/** * 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 = VideoPost::find(); $postTable = VideoPost::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, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'is_pin' => $this->is_pin]); $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'slug', $this->slug])->andFilterWhere(['like', 'content', $this->content])->andFilterWhere(['like', 'cached_tag_list', $this->cached_tag_list])->andFilterWhere(['like', 'user.username', $this->getAttribute('user.username')]); return $dataProvider; }
/** * Finds the VideoPost model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return VideoPost the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = VideoPost::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * Get block with video reviews * @return array Data */ public static function getVideoNews() { $postTable = Post::tableName(); $assetTable = Asset::tableName(); // Video review $videoReviewNews = VideoPost::find()->where(['is_public' => 1])->orderBy(['created_at' => SORT_DESC])->limit(3)->all(); if (count($videoReviewNews) == 0) { return false; } $block = ['view' => '@frontend/views/blocks/review_news_block', 'data' => compact('videoReviewNews')]; return $block; }
/** * Url: /video/{$id}-{$slug} * @param int $id Album id * @param string $slug Album slug * @return mixed * @throws NotFoundHttpException */ public function actionVideoPost($id, $slug) { $videoPost = VideoPost::find()->where(['id' => $id, 'is_public' => 1])->one(); if (!isset($videoPost)) { throw new NotFoundHttpException('Страница не найдена.'); } $image = $videoPost->getAsset(); $video = $videoPost->getVideoAsset(); $options = ['templateType' => 'col2', 'title' => 'Dynamomania.com | Видео: ' . $videoPost->title, 'columnFirst' => ['content' => ['view' => '@frontend/views/site/video_post', 'data' => compact('videoPost', 'image', 'video')]], 'columnSecond' => ['short_news' => SiteBlock::getShortNews()]]; $banner = SiteBlock::getBanner(Banner::REGION_UNDER_NEWS); $count = 0; while ($banner) { $count++; $options['columnFirst']['banner-' . $count] = $banner; $options['columnFirst']['banner-' . $count]['weight'] = 2; $banner = SiteBlock::getBanner(Banner::REGION_UNDER_NEWS); } $options['columnFirst']['comments'] = Comment::getCommentsBlock($videoPost->id, Comment::COMMENTABLE_VIDEO); $options['columnFirst']['comments']['weight'] = 5; usort($options['columnFirst'], 'self::cmp'); return $this->render('@frontend/views/site/index', $options); }