/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params, $poisk1, $poisk2) { $query = Trip::find()->innerJoin('userdata', 'userdata.id=trip.iduserdata'); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['numbertrip' => 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; } $query->andFilterWhere(['id' => $this->id, 'iduserdata' => $this->iduserdata, 'idclient' => $this->idclient, 'idproject' => $this->idproject, 'idusers' => $this->idusers, 'date_kup_bilet' => $this->date_kup_bilet, 'date_otpr' => $this->date_otpr, 'date_pr' => $this->date_pr, 'date_otpr1' => $this->date_otpr1, 'date_pr1' => $this->date_pr1, 'status_trip' => $this->status_trip, 'numbertrip' => $this->numbertrip, 'daily' => $this->daily, 'cena_pr' => $this->cena_pr, 'event' => $this->event, 'taxi' => $this->taxi, 'stoimost_pr' => $this->stoimost_pr, 'predstav' => $this->predstav, 'budzhet' => $this->budzhet, 'date_zvit' => $this->date_zvit, 'date_zvit_us' => $this->date_zvit_us, 'key' => $this->key, 'zhurnal' => $this->zhurnal, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'userdata.id_depart' => $this->depart]); if (!$poisk1 and !$poisk2) { $query->andFilterWhere(['like', 'target', $this->target])->andFilterWhere(['like', 'vidtransport', $this->vidtransport])->andFilterWhere(['like', 'note', $this->note]); } else { $poisk1 = \DateTime::createFromFormat('d.m.Y', $poisk1); $poisk1 = $poisk1->format('U'); $poisk2 = \DateTime::createFromFormat('d.m.Y', $poisk2); $poisk2 = $poisk2->format('U'); $query->andFilterWhere(['like', 'target', $this->target])->andFilterWhere(['like', 'vidtransport', $this->vidtransport])->andFilterWhere(['like', 'note', $this->note])->andFilterWhere(['>=', 'date_otpr', $poisk1])->andFilterWhere(['<=', 'date_otpr', $poisk2]); // ->addFilterWhere(['<','date_otpr', $poisk2]); } return $dataProvider; }
/** * Gets all the available trips * * @return \App\Models\Trip[] */ public function getAll() { return \App\Models\Trip::get(array('*')); }
/** * @return \yii\db\ActiveQuery */ public function getTrips() { return $this->hasMany(Trip::className(), ['idpr' => 'id']); }
/** * Finds the Trip model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Trip the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Trip::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }