예제 #1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $user = Yii::$app->getModule("user")->model("User");
     $query = Album::find();
     $postTable = Album::tableName();
     // set up query with relation to `user.username`
     $userTable = $user::tableName();
     $query->joinWith(['user' => function ($query) use($userTable) {
         $query->from(['user' => $userTable]);
     }]);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10], 'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]]]);
     // enable sorting for the related columns
     $addSortAttributes = ["user.username"];
     foreach ($addSortAttributes as $addSortAttribute) {
         $dataProvider->sort->attributes[$addSortAttribute] = ['asc' => [$addSortAttribute => SORT_ASC], 'desc' => [$addSortAttribute => SORT_DESC]];
     }
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(["{$postTable}.id" => $this->id, 'user_id' => $this->user_id, 'is_public' => $this->is_public]);
     if ($this->created_at) {
         $createdTime = strtotime($this->created_at);
         $startDay = date("Y-m-d 00:00:00", $createdTime);
         $endDay = date("Y-m-d 00:00:00", $createdTime + 60 * 60 * 24);
         $query->andFilterWhere(['between', 'created_at', $startDay, $endDay]);
     }
     if ($this->updated_at) {
         $updatedTime = strtotime($this->updated_at);
         $startDay = date("Y-m-d 00:00:00", $updatedTime);
         $endDay = date("Y-m-d 00:00:00", $updatedTime + 60 * 60 * 24);
         $query->andFilterWhere(['between', 'updated_at', $startDay, $endDay]);
     }
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'cached_tag_list', $this->cached_tag_list])->andFilterWhere(['like', 'user.username', $this->getAttribute('user.username')]);
     return $dataProvider;
 }
예제 #2
0
 protected function findModel($id)
 {
     if (($model = Album::find()->where(['and', 'id=' . $id])->One()) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #3
0
 public function actionIndex()
 {
     //页面左侧分类
     $bigCate = Category::find()->where(['is_nav' => \common\models\YesNo::YES])->orderBy(['sort_order' => SORT_ASC])->all();
     //首页轮播图
     $slider = Slider::find()->where(['place' => 0])->orderBy(['ord' => SORT_ASC])->all();
     //师生风采
     $teachers = \common\models\Album::find()->orderBy(['id' => SORT_DESC])->limit(5)->all();
     //友情链接
     $friendLink = \common\models\Friendlink::find()->where(['isshow' => \common\models\YesNo::YES])->orderBy(['ord' => SORT_ASC])->all();
     return $this->render('index', ['bigCate' => $bigCate, 'slider' => $slider, 'teachers' => $teachers, 'friendlink' => $friendLink]);
 }
예제 #4
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Album::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'views' => $this->views, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'intro', $this->intro])->andFilterWhere(['like', 'author', $this->author]);
     return $dataProvider;
 }
예제 #5
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.');
     }
 }
예제 #6
0
 public function afterSave($insert, $changedAttributes)
 {
     switch ($this->commentable_type) {
         case self::COMMENTABLE_POST:
         case self::COMMENTABLE_TRANSFER:
         case self::COMMENTABLE_MATCH:
         case self::COMMENTABLE_VIDEO:
         case self::COMMENTABLE_INQUIRER:
             $commentCount = CommentCount::find()->where(['commentable_id' => $this->commentable_id, 'commentable_type' => $this->commentable_type])->one();
             if (empty($commentCount->id)) {
                 $commentCount = new CommentCount();
                 $commentCount->commentable_id = $this->commentable_id;
                 $commentCount->commentable_type = $this->commentable_type;
             }
             $count = Comment::find()->where(['commentable_type' => $this->commentable_type, 'commentable_id' => $this->commentable_id])->count();
             $commentCount->count = $count;
             $commentCount->save(false);
             break;
         case self::COMMENTABLE_PHOTO:
         case self::COMMENTABLE_ALBUM:
             if ($this->commentable_type == self::COMMENTABLE_ALBUM) {
                 $albumID = $this->commentable_id;
             } else {
                 $albumTable = Album::tableName();
                 $assetTable = Asset::tableName();
                 $album = (new \yii\db\Query())->select("{$albumTable}.id")->from($albumTable)->innerJoin($assetTable, "{$assetTable}.assetable_id = {$albumTable}.id")->where(["{$assetTable}.id" => $this->commentable_id, "{$assetTable}.assetable_type" => Asset::ASSETABLE_ALBUM])->one();
                 if (isset($album['id'])) {
                     $albumID = $album['id'];
                 }
             }
             if (isset($albumID)) {
                 $commentCount = CommentCount::find()->where(['commentable_id' => $albumID, 'commentable_type' => self::COMMENTABLE_ALBUM])->one();
                 if (empty($commentCount->id)) {
                     $commentCount = new CommentCount();
                     $commentCount->commentable_id = $albumID;
                     $commentCount->commentable_type = self::COMMENTABLE_ALBUM;
                     $commentCount->count = 0;
                 }
                 // $commentCount->count++;
                 $albumCount = Comment::find()->where(['commentable_type' => $this->commentable_type, 'commentable_id' => $this->commentable_id])->count();
                 $assetTable = Asset::tableName();
                 $albumTable = self::tableName();
                 $ids = (new \yii\db\Query())->select("{$assetTable}.id")->from($assetTable)->innerJoin($albumTable, "{$albumTable}.id = {$assetTable}.assetable_id")->where(["{$albumTable}.id" => $albumID, "{$assetTable}.assetable_type" => Asset::ASSETABLE_ALBUM])->all();
                 $assetIDs = [];
                 foreach ($ids as $id) {
                     $assetIDs[] = (int) $id['id'];
                 }
                 $assetsCount = Comment::find()->where(['commentable_type' => self::COMMENTABLE_PHOTO, 'commentable_id' => $assetIDs])->count();
                 $commentCount->count = $albumCount + $assetsCount;
                 $commentCount->save(false);
             }
             break;
         default:
             break;
     }
     parent::afterSave($insert, $changedAttributes);
 }
예제 #7
0
 /**
  * Get block with photo reviews
  * @return array Data
  */
 public static function getPhotoNews()
 {
     // Photo review
     $photoReviewNews = Album::find()->where(['is_public' => 1])->orderBy(['created_at' => SORT_DESC])->limit(3)->all();
     if (count($photoReviewNews) == 0) {
         return false;
     }
     $block = ['view' => '@frontend/views/blocks/review_news_block', 'data' => compact('photoReviewNews')];
     return $block;
 }
예제 #8
0
 /**
  * Url: /album/{$album_id}-{$slug}/{$photo_id}
  * @param int $album_id Album id
  * @param string $slug Album slug
  * @param $photo_id
  * @return mixed Content
  * @throws NotFoundHttpException
  */
 public function actionPhoto($album_id, $slug, $photo_id)
 {
     $album = Album::find()->where(['id' => $album_id, 'is_public' => 1])->one();
     if (!isset($album)) {
         throw new NotFoundHttpException('Страница не найдена.');
     }
     $photo = Asset::find()->where(['id' => $photo_id, 'thumbnail' => Asset::THUMBNAIL_CONTENT])->one();
     if (!isset($photo)) {
         $photo = Asset::find()->where(['id' => $photo_id])->one();
     }
     if (!isset($photo)) {
         throw new NotFoundHttpException('Страница не найдена.');
     }
     return $this->render('@frontend/views/site/index', ['templateType' => 'col2', 'title' => 'Dynamomania.com | Фотоальбом: ' . $album->title, 'columnFirst' => ['content' => ['view' => '@frontend/views/site/photo_single', 'data' => compact('album', 'photo')], 'comments' => Comment::getCommentsBlock($photo->id, Comment::COMMENTABLE_PHOTO)], 'columnSecond' => ['short_news' => SiteBlock::getshortNews(50)]]);
 }