/** * 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 EventSearch(); $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; } 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(['Id' => $searchClass->Id, 'sourceId' => $searchClass->sourceId, 'cityId' => $searchClass->cityId, 'zoneId' => $searchClass->zoneId, 'localityId' => $searchClass->localityId, 'gpsLat' => $searchClass->gpsLat, 'gpsLong' => $searchClass->gpsLong, 'startDate' => $searchClass->startDate, 'endDate' => $searchClass->endDate, 'startTime' => $searchClass->startTime, 'endTime' => $searchClass->endTime, 'status' => $searchClass->status, 'isRecursive' => $searchClass->isRecursive, 'healthStatus' => $searchClass->healthStatus, 'createdOn' => $searchClass->createdOn, 'createdBy' => $searchClass->createdBy, 'updatedOn' => $searchClass->updatedOn, 'updatedBy' => $searchClass->updatedBy]); $query->andFilterWhere(['like', 'categoryId', $searchClass->categoryId])->andFilterWhere(['like', 'name', $searchClass->name])->andFilterWhere(['like', 'description', $searchClass->description])->andFilterWhere(['like', 'address', $searchClass->address])->andFilterWhere(['like', 'landmark', $searchClass->landmark])->andFilterWhere(['like', 'pincode', $searchClass->pincode])->andFilterWhere(['like', 'tollfree', $searchClass->tollfree])->andFilterWhere(['like', 'contactName', $searchClass->contactName])->andFilterWhere(['like', 'email', $searchClass->email])->andFilterWhere(['like', 'url', $searchClass->url])->andFilterWhere(['like', 'shopurl', $searchClass->shopurl])->andFilterWhere(['like', 'price', $searchClass->price])->andFilterWhere(['like', 'ip', $searchClass->ip])->andFilterWhere(['like', 'recursionData', $searchClass->recursionData])->andFilterWhere(['like', 'oldGuid', $searchClass->oldGuid])->andFilterWhere(['like', 'guid', $searchClass->guid])->andFilterWhere(['like', 'multipleTimings', $searchClass->multipleTimings])->andFilterWhere(['like', 'weekdaysChecklist', $searchClass->weekdaysChecklist]); /*$query->joinWith('eventMap')->andFilterWhere(['like', 'phone', $this->phone]) ->andFilterWhere(['like', 'mobile', $this->mobile]);//*/ return $dataProvider; }
/** * Lists all Event models. * @return mixed */ public function actionIndex() { if (Yii::$app->user->isGuest) { $this->redirect(Yii::$app->urlManager->createUrl('site/login')); } $searchModel = new EventSearch(); $dataProvider = $searchModel->search(Yii::$app->request->queryParams); return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]); }
/** * Lists all Event models. * @return mixed */ public function actionIndex() { $searchModel = new EventSearch(); $dataProvider = $searchModel->search(Yii::$app->request->getQueryParams()); return $this->render('index', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel, 'state' => new Event()]); }