1 | <?php |
||
30 | class ActiveImageBehavior extends SBehavior |
||
31 | { |
||
32 | public $imageClass; |
||
33 | |||
34 | private $images; |
||
35 | |||
36 | 38 | public function init() |
|
37 | { |
||
38 | 38 | if( !isset($this->imageClass) ) |
|
39 | 38 | { |
|
40 | throw new CException('Can not attach ActiveImageBehavior without imageClass property'); |
||
41 | } |
||
42 | 38 | } |
|
43 | |||
44 | /** |
||
45 | * @param string $type |
||
46 | * |
||
47 | * @return FActiveImage |
||
48 | */ |
||
49 | public function getImage($type = 'main') |
||
50 | { |
||
51 | if( $image = Arr::reset($this->getImages($type)) ) |
||
52 | return $image; |
||
53 | |||
54 | return Yii::createComponent(['class' => $this->imageClass]); |
||
55 | } |
||
56 | |||
57 | /** |
||
58 | * @param string $type |
||
59 | * |
||
60 | * @return FActiveImage[] |
||
61 | */ |
||
62 | public function getImages($type = 'main') |
||
63 | { |
||
64 | if( !isset($this->images) ) |
||
65 | { |
||
66 | $criteria = $this->getColorCriteria(); |
||
67 | $criteria->compare('parent', $this->owner->getPrimaryKey()); |
||
68 | /** |
||
69 | * @var FActiveRecord $model |
||
70 | */ |
||
71 | $model = new $this->imageClass; |
||
72 | $images = $model->findAll($criteria); |
||
73 | |||
74 | $this->setImages($images, $type); |
||
75 | } |
||
76 | |||
77 | return isset($this->images[$type]) ? $this->images[$type] : array(); |
||
78 | } |
||
79 | |||
80 | /** |
||
81 | * @param array $images |
||
82 | * @param string $type |
||
83 | * |
||
84 | * @return void |
||
85 | */ |
||
86 | 2 | public function setImages($images, $type) |
|
97 | |||
98 | /** |
||
99 | * ��������� ������ ����������� |
||
100 | * |
||
101 | * @param FActiveImage|null $excludeImage - ������ ����������� |
||
102 | * @param array $types - �������� ��� |
||
103 | * |
||
104 | * @return FActiveImage[] |
||
105 | */ |
||
106 | public function getImagesGallery(FActiveImage $excludeImage = null, $types = array('main', 'gallery')) |
||
121 | |||
122 | 2 | public function getColorCriteria() |
|
150 | } |