/** * 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; }
/** * Url: /match/{$id}/videos * @param $id Match id * @return mixed * @throws NotFoundHttpException */ public function actionMatchVideos($id) { $match = Match::findOne($id); if (!isset($match)) { throw new NotFoundHttpException('The requested page does not exist.'); } $title = "Видео матча " . $match->name; $videoPostTable = VideoPost::tableName(); $relationTable = Relation::tableName(); $query = VideoPost::find()->innerJoin($relationTable, "{$videoPostTable}.id = {$relationTable}.relationable_id")->where(['is_public' => 1, "{$relationTable}.relationable_type" => Relation::RELATIONABLE_VIDEO, "{$relationTable}.parent_id" => $match->id])->orderBy(['created_at' => SORT_DESC]); $videosDataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 10]]); $emptyText = 'Видеозаписей к матчу не найдено'; return $this->render('@frontend/views/site/index', ['templateType' => 'col2', 'title' => 'Dynamomania.com | ' . $title, 'columnFirst' => ['menu' => ['view' => '@frontend/views/translation/menu', 'data' => compact('match')], 'content' => ['view' => '@frontend/views/site/videos', 'data' => compact('videosDataProvider', 'emptyText')]], 'columnSecond' => ['short_news' => SiteBlock::getshortNews(50)]]); }