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(); }
/** * 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()]); }
/** * Finds the Album model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Album the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Album::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * 保存后进行处理 * 写入照片的上一页,下一页 * * @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(); } }
/** * Updates an existing Photo model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $albumModel = Album::findOne($model->album_id); return $this->render('update', ['model' => $model, 'albumModel' => $albumModel]); }