Exemplo n.º 1
0
 /**
  * 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.');
     }
 }
Exemplo n.º 2
0
 /**
  * @param int $id Album id
  * @param int $count Exist amount of images
  * @return mixed Images to bxSlider
  */
 public function actionAlbumLoadImages($id, $count)
 {
     $album = Album::findOne($id);
     $contentImagesCount = Asset::find()->where(['assetable_id' => $id, 'assetable_type' => Asset::ASSETABLE_ALBUM, 'thumbnail' => Asset::THUMBNAIL_CONTENT])->count();
     $query = Asset::find()->where(['assetable_id' => $id, 'assetable_type' => Asset::ASSETABLE_ALBUM]);
     if ($contentImagesCount > 0) {
         $query->andWhere(['thumbnail' => Asset::THUMBNAIL_CONTENT]);
     }
     $images = $query->limit(12)->offset($count)->orderBy(['id' => SORT_ASC])->all();
     $thumbnailImages = [];
     $contentImagesHtml = '';
     $thumbnailImagesHtml = '';
     foreach ($images as $image) {
         if (isset($image->parent_id)) {
             $thumbnailImage = Asset::find()->where(['parent_id' => $image->parent_id, 'thumbnail' => Asset::THUMBNAIL_SMALL])->one();
             $thumbnailImages[] = isset($thumbnailImage->id) ? $thumbnailImage : $image;
         } else {
             $thumbnailImages[] = $image;
         }
         $contentImagesHtml .= '<div><a href="' . $album->getPhotoUrl($image->id) . '">' . '<img src="' . $image->getFileUrl() . '" alt="slide">' . '</a></div>';
     }
     foreach ($thumbnailImages as $image) {
         $thumbnailImagesHtml .= '<a class="pager-item" data-slide-index="' . $count . '" href="javascript:void(0)"><img src="' . $image->getFileUrl() . '" alt="slide"></a>';
         $count++;
     }
     return Json::encode(compact('contentImagesHtml', 'thumbnailImagesHtml'));
 }