예제 #1
0
파일: Photo.php 프로젝트: xidiao/gxfenxi
 /**
  * 保存后进行处理
  * 写入照片的上一页,下一页
  *
  * @param bool $insert
  * @param array $changedAttributes
  */
 public static function updatePrevNextAndCover($album_id)
 {
     if (!empty($album_id)) {
         $photos = Photo::find()->andWhere(['album_id' => $album_id])->all();
         $albumCoverPhoto = null;
         if (!empty($photos)) {
             foreach ($photos as $key => $val) {
                 if ($val->is_album_cover == 1) {
                     $albumCoverPhoto = $val;
                 }
                 $prev_photo = Photo::getPhotoHasPrev($key, $photos);
                 $next_photo = Photo::getPhotoHasNext($key, $photos);
                 if ($prev_photo == $val->prev_photo && $next_photo == $val->next_photo) {
                     continue;
                 } else {
                     $Photo = Photo::findOne($val->id);
                     $Photo->prev_photo = $prev_photo;
                     $Photo->next_photo = $next_photo;
                     $Photo->save();
                 }
             }
         }
         if (empty($albumCoverPhoto)) {
             $albumCoverPhoto = array_shift($photos);
         }
         $Album = Album::findOne($album_id);
         $Album->image = $albumCoverPhoto->image;
         $Album->cover = $albumCoverPhoto->cover;
         $Album->thumb = $albumCoverPhoto->thumb;
         $Album->icon = $albumCoverPhoto->icon;
         $Album->save();
     }
 }
예제 #2
0
파일: Album.php 프로젝트: xidiao/gxfenxi
 public function updatePhotoCount($id)
 {
     $quuery = Photo::find()->select('count(1) as photo_count')->andWhere(['album_id' => $id])->asArray()->one();
     $model = Album::findOne($id);
     $model->photo_count = $quuery['photo_count'];
     $model->save();
 }
예제 #3
0
 /**
  * Displays a single Photo model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $model = $this->findModel($id);
     $albumModel = Album::findOne($model->album_id);
     $photoCount = Photo::find()->andWhere(['album_id' => $model->album_id])->count('*');
     $currentPage = Photo::find()->andWhere(['album_id' => $model->album_id])->andWhere('id >= ' . $id)->count('*');
     return $this->render('photoView', ['model' => $model, 'photoCount' => $photoCount, 'currentPage' => $currentPage, 'albumModel' => $albumModel, 'userCreadedBy' => User::find()->andWhere(['id' => $model->created_by])->asArray()->one(), 'userExtendCreadedBy' => UserExtend::find()->andWhere(['user_id' => $model->created_by])->asArray()->one(), 'user' => User::find()->andWhere(['id' => Yii::$app->getUser()->getId()])->asArray()->one(), 'userExtend' => UserExtend::find()->andWhere(['user_id' => Yii::$app->getUser()->getId()])->asArray()->one()]);
 }
예제 #4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search1($params)
 {
     $query = Photo::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'album_id' => $this->album_id, 'recs_count' => $this->recs_count, 'liked_count' => $this->liked_count, 'prev_photo' => $this->prev_photo, 'next_photo' => $this->next_photo, 'created_by' => $this->created_by, 'created_at' => $this->created_at, 'updated_by' => $this->updated_by, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'alt', $this->alt])->andFilterWhere(['like', 'author', $this->author])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'icon', $this->icon])->andFilterWhere(['like', 'cover', $this->cover])->andFilterWhere(['like', 'thumb', $this->thumb])->andFilterWhere(['like', 'image', $this->image])->andFilterWhere(['like', 'privacy', $this->privacy])->andFilterWhere(['like', 'can_reply', $this->can_reply])->andFilterWhere(['like', 'desc', $this->desc])->andFilterWhere(['like', 'is_album_cover', $this->is_album_cover]);
     return $dataProvider;
 }