/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Videos::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'type_id' => $this->type_id, 'user_id' => $this->user_id, 'status' => $this->status, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'url', $this->url])->andFilterWhere(['like', 'images', $this->images])->andFilterWhere(['like', 'description', $this->description])->andFilterWhere(['like', 'seo_keywords', $this->seo_keywords])->andFilterWhere(['like', 'seo_title', $this->seo_title]); return $dataProvider; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Videos::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 8], 'sort' => ['defaultOrder' => ['id' => SORT_DESC]]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } foreach (explode(" ", trim($this->description)) as $qs) { $query->orWhere(['like', 'description', $qs]); } $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'updated_at' => $this->updated_at, 'created_at' => $this->created_at]); if (isset($params['video'])) { $query->join("join", "video_categories_bind", "video_categories_bind.video_id=videos.id"); $query->where("video_categories_bind.category_id = " . $params['video']); } $query->andFilterWhere(['like', 'link', $this->link]); return $dataProvider; }
public function actionTest($catId = 0) { //$request = Yii::$app->request; //$post = $request->post; //var_dump($post); //$redis = Yii::$app->redis; //var_dump($redis); $query = videos::find(); if ($catId != 0) { $query = Videos::find()->where(['catId' => $catId]); } $countQuery = clone $query; $pages = new Pagination(['totalCount' => $countQuery->count(), 'pageSize' => 16]); if ($pages->page >= ($pages->totalCount + 15) / 16) { return array(); } $videos = $query->offset($pages->offset)->select(['id', 'title', 'youtubeChannelId', 'streamUrl', 'youtubeId', 'catId', 'thumbnails_json'])->limit($pages->limit)->asArray()->all(); $result = array(); $result['totalCount'] = $pages->totalCount; $result['PageCount'] = $pages->pageCount; $result['videos'] = $videos; return $result; }