true), array('dateRu, link', 'safe'), // The following rule is used by search(). // Please remove those attributes that should not be searched. array('id, date, photo_gallery_id, video_gallery_id', 'safe', 'on' => 'search'), array('hidden, code', 'safe'), ); } /** * @return array relational rules. */ public function relations() { // NOTE: you may need to adjust the relation name and the related // class name for the relations automatically generated below. return array( 'i18ns' => array(self::HAS_MANY, 'AlbumI18n', 'id', 'index' => 'lang'), 'i18n' => array(self::HAS_ONE, 'AlbumI18n', 'id', 'condition' => 'lang=\'' . Yii::app()->language . '\''), ); } /** * @return array customized attribute labels (name=>label) */ public function attributeLabels() { return array( 'id' => 'ID', 'link' => 'Псевдоним в адресной строке', 'date' => 'Дата', 'dateRu' => 'Дата', 'image' => 'Обложка альбома', 'photo_gallery_id' => 'Фото галерея', 'video_gallery_id' => 'Видео галерея', 'hidden' => 'Страница скрыта', ); } /** * Retrieves a list of models based on the current search/filter conditions. * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. */ public function search() { // Warning: Please modify the following code to remove attributes that // should not be searched. $criteria = new CDbCriteria; //// $criteria->compare('id', $this->id); $criteria->compare('albums_section_id', $this->albums_section_id); $criteria->compare('date', $this->date, true); $criteria->compare('photo_gallery_id', $this->photo_gallery_id); $criteria->compare('video_gallery_id', $this->video_gallery_id); $sort = new CSort(); $sort->defaultOrder = array( 'date' => true, ); return new CActiveDataProvider($this, array( 'criteria' => $criteria, 'sort' => $sort, )); } public function save($runValidation = true, $attributes = null) { $r = parent::save($runValidation, $attributes); if (empty($this->link)) { $this->link = $this->id; $this->saveAttributes($this->attributes); } return $r; } public function getDateRu() { return ($this->date !== null) ? date('d.m.Y', CDateTimeParser::parse($this->date, 'yyyy-MM-dd')) : date('d.m.Y'); } public function setDateRu($value) { $this->date = date('Y-m-d', CDateTimeParser::parse($value, 'dd.MM.yyyy')); } public $image; public function behaviors() { return array( 'imageBehavior' => array( 'class' => 'ImageARBehavior', 'attribute' => 'image', // this must exist 'extension' => 'png, gif, jpg, jpeg', // possible extensions, comma separated 'prefix' => 'img_', 'relativeWebRootFolder' => 'images/albums', // this folder must exist // 'forceExt' => 'png', 'formats' => array( 'preview' => array( 'suffix' => '_medium', 'process' => array( 'centeredpreview' => array(168, 126), ), ), 'normal' => array(), ), 'defaultName' => 'default', ), 'photoGalleryBehavior' => array( 'class' => 'GalleryBehavior', 'idAttribute' => 'photo_gallery_id', 'versions' => array( 'small' => array( 'centeredpreview' => array(168, 126), ), 'medium' => array( 'cresize' => array(800, null), 'watermark' => array('images/watermark.png', 0, 0), ) ), 'name' => true, 'description' => true, ), 'videoGalleryBehavior' => array( 'class' => 'GalleryBehavior', 'idAttribute' => 'video_gallery_id', 'versions' => array( 'small' => array( 'centeredpreview' => array(168, 126), ), 'medium' => array( 'cresize' => array(800, null), ) ), 'name' => true, 'description' => false, 'link' => true, ), ); } /** * @param Node $node * @return void */ public function setNode($node) { $this->albums_section_id = $node->data_id; } }