コード例 #1
0
 /**
  * Method to update images name/description via AJAX.
  * On success returns JSON array od objects with new image info.
  * @throws CHttpException
  */
 public function actionChangeData()
 {
     if (!isset($_POST['photo'])) {
         throw new CHttpException(400, 'Nothing, to save');
     }
     $data = $_POST['photo'];
     $criteria = new CDbCriteria();
     $criteria->index = 'id';
     $criteria->addInCondition('id', array_keys($data));
     /** @var $models GalleryPhoto[] */
     $models = GalleryPhoto::model()->findAll($criteria);
     foreach ($data as $id => $attributes) {
         if (isset($attributes['name'])) {
             $models[$id]->name = $attributes['name'];
         }
         if (isset($attributes['description'])) {
             $models[$id]->description = $attributes['description'];
         }
         $models[$id]->save();
     }
     $resp = array();
     foreach ($models as $model) {
         $resp[] = array('id' => $model->id, 'rank' => $model->rank, 'name' => (string) $model->name, 'description' => (string) $model->description, 'preview' => $model->getPreview());
     }
     echo CJSON::encode($resp);
 }
コード例 #2
0
ファイル: GalleryBehavior.php プロジェクト: lidijakralj/bober
 /** @return GalleryPhoto[] Photos from associated gallery */
 public function getGalleryPhotos()
 {
     $criteria = new CDbCriteria();
     $criteria->condition = 'gallery_id = :gallery_id';
     $criteria->params[':gallery_id'] = $this->getOwner()->{$this->idAttribute};
     $criteria->order = '`rank` asc';
     return GalleryPhoto::model()->findAll($criteria);
 }
コード例 #3
0
ファイル: DefaultController.php プロジェクト: xPashaNx/diet
 public function actionSortPhoto($galleryId)
 {
     if (isset($_POST['sortArr'])) {
         $sortData = $_POST['sortArr'];
         $photos = GalleryPhoto::model()->findAllByAttributes(array('gallery_id' => $galleryId), array('order' => 'sort_order'));
         foreach ($photos as $key => $photo) {
             $photo->sort_order = $sortData[$key];
             $photo->save('sort_order');
         }
     }
 }
コード例 #4
0
ファイル: Gallery.php プロジェクト: xPashaNx/diet
 public function getCover()
 {
     // Если в галерее есть фото
     if (isset($this->photos)) {
         // Если указана обложка - возвращаем ее
         if ($this->cover_photo_id) {
             $coverPhoto = GalleryPhoto::model()->findByPk($this->cover_photo_id);
             if ($coverPhoto) {
                 $result = $coverPhoto;
             } else {
                 $result = false;
             }
         } else {
             // Если не указана обложка - берем первую фотку
             $criteria = new CDbCriteria();
             $criteria->order = 'sort_order';
             $criteria->condition = 'gallery_id=:gallery_id';
             $criteria->params = array(':gallery_id' => $this->id);
             $coverPhoto = GalleryPhoto::model()->find($criteria);
             $result = $coverPhoto;
         }
     } else {
         $result = false;
     }
     return $result;
 }
コード例 #5
0
ファイル: GalleryPhoto.php プロジェクト: xPashaNx/diet
 public static function getRandomPhoto()
 {
     $criteria = new CDbCriteria();
     $criteria->limit = 1;
     $criteria->select = "*, rand() as rand";
     $criteria->order = "rand";
     return GalleryPhoto::model()->find($criteria);
 }