/** * Prepares the data provider that should return the requested collection of the models. * @return ActiveDataProvider */ protected function prepareDataProvider() { if ($this->prepareDataProvider !== null) { return call_user_func($this->prepareDataProvider, $this); } /** * @var \yii\db\BaseActiveRecord $modelClass */ $modelClass = $this->modelClass; $searchClass = new TheatreSearch(); $query = $modelClass::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->setSort(['defaultOrder' => ['updatedOn' => SORT_DESC]]); $query->andWhere("not ((`state`=" . AppActiveRecord::STATUS_DRAFT . ") AND (`createdBy`!=" . \yii::$app->user->id . "))"); if (!($searchClass->load(Yii::$app->request->queryParams, '') && $searchClass->validate())) { $query->andFilterWhere(['NOT', ['state' => AppActiveRecord::STATUS_DELETE]]); return $dataProvider; } $query->andFilterWhere(['Id' => $searchClass->Id, 'cityId' => $searchClass->cityId, 'gpsLat' => $searchClass->gpsLat, 'gpsLong' => $searchClass->gpsLong, 'status' => $searchClass->status, 'hotelId' => $searchClass->hotelId, 'noofscreens' => $searchClass->noofscreens, 'zoneId' => $searchClass->zoneId, 'localityId' => $searchClass->localityId, 'createdOn' => $searchClass->createdOn, 'updatedOn' => $searchClass->updatedOn, 'createdBy' => $searchClass->createdBy, 'updatedBy' => $searchClass->updatedBy, 'entityType' => $searchClass->entityType, 'state' => $searchClass->state]); if ($searchClass->state !== null) { if ($searchClass->state == AppActiveRecord::STATUS_DRAFT) { $query->andFilterWhere(['state' => $this->state, 'createdBy' => \yii::$app->user->id]); } else { $query->andFilterWhere(['state' => $searchClass->state]); } } else { $query->andFilterWhere(['NOT', ['state' => AppActiveRecord::STATUS_DELETE]]); } $query->andFilterWhere(['like', 'name', $searchClass->name])->andFilterWhere(['like', 'address', $searchClass->address])->andFilterWhere(['like', 'facility', $searchClass->facility])->andFilterWhere(['like', 'email', $searchClass->email])->andFilterWhere(['like', 'tollfree', $searchClass->tollfree])->andFilterWhere(['like', 'website', $searchClass->website])->andFilterWhere(['like', 'facebookUrl', $searchClass->facebookUrl])->andFilterWhere(['like', 'pincode', $searchClass->pincode])->andFilterWhere(['like', 'landmark', $searchClass->landmark])->andFilterWhere(['like', 'bookingNumber', $searchClass->bookingNumber])->andFilterWhere(['like', 'guid', $searchClass->guid])->andFilterWhere(['like', 'ip', $searchClass->ip]); return $dataProvider; }
/** * Lists all Theatre models. * @return mixed */ public function actionIndex() { $searchModel = new TheatreSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider, 'state' => new Theatre()]); }