1 <?php
2 3 4 5 6 7
8 namespace foundation\widgets;
9
10 use foundation\helpers\ArrayHelper;
11 use foundation\helpers\Html;
12 use foundation\enum\Enum;
13
14 15 16 17 18 19 20 21
22 class Clearing extends base\Widget
23 {
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
39 public $items;
40
41
42 43 44
45 public function init()
46 {
47 $this->assets = array(
48 'js' => YII_DEBUG ? 'foundation/foundation.clearing.js' : 'foundation.min.js'
49 );
50 Html::addCssClass($this->htmlOptions, Enum::CLEARING_THUMBS);
51 ArrayHelper::addValue('data-clearing', 'data-clearing', $this->htmlOptions);
52 parent::init();
53 }
54
55 56 57
58 public function run()
59 {
60 echo $this->renderClearing();
61 }
62
63 64 65 66
67 public function renderClearing()
68 {
69 if (empty($this->items)) {
70 return true;
71 }
72 $list = array();
73 foreach ($this->items as $item) {
74 $list[] = $this->renderItem($item);
75 }
76 return \CHtml::tag('ul', $this->htmlOptions, implode("\n", $list));
77 }
78
79 80 81 82 83
84 public function renderItem($item)
85 {
86 $options = ArrayHelper::getValue($item, 'options', array());
87 if (isset($item['featured'])) {
88 Html::addCssClass($this->htmlOptions, Enum::ClEARING_FEATURE);
89 Html::addCssClass($options, Enum::CLEARING_FEATURE_IMG);
90 }
91 $imgOptions = array();
92 $imgOptions['src'] = ArrayHelper::getValue($item, 'th', '#');
93 $imgOptions['data-caption'] = ArrayHelper::getValue($item, 'caption', null);
94 $url = ArrayHelper::getValue($item, 'img', '#');
95
96 return \CHtml::tag('li', $options, \CHtml::link(\CHtml::tag('img', $imgOptions), $url));
97
98 }
99 }