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