/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = LocationProvider::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'latitude' => $this->latitude, 'longitude' => $this->longitude, 'provided_at' => $this->provided_at, 'created_at' => $this->created_at]); $query->andFilterWhere(['like', 'identity_kind', $this->identity_kind])->andFilterWhere(['like', 'identity_info', $this->identity_info]); return $dataProvider; }
/** * Finds the LocationProvider model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return LocationProvider the loaded model * @throws HttpException if the model cannot be found */ protected function findModel($id) { if (($model = LocationProvider::findOne($id)) !== null) { return $model; } else { throw new HttpException(404, 'The requested page does not exist.'); } }
public function createProvider() { $provider = new LocationProvider(); if ($this->identity_kind == LocationProvider::IDENTITY_KIND_PEOPLE) { $provider_exist = LocationProvider::findOne(['identity_info' => $this->identity_info]); if ($provider_exist) { $provider = $provider_exist; } else { $provider->identity_info = $this->identity_info; } $location = Yii::$app->telecoms->locateWithNumber($this->identity_info); if ($location) { $provider->latitude = $location['latitude']; $provider->longitude = $location['longitude']; } else { throw new TelecomsLocateFailException('fail to locate the provider with number : ' . $this->identity_info); } } elseif ($this->identity_kind == LocationProvider::IDENTITY_KIND_POLICE) { $provider->identity_info = LocationProvider::IDENTITY_KIND_POLICE . time(); } else { $provider->identity_info = LocationProvider::IDENTITY_KIND_MONITOR_SYSTEM . time(); } $provider->identity_kind = $this->identity_kind; $provider->provided_at = $this->provided_at; $provider->save(); $this->_provider = $provider; }
/** * @return \yii\db\ActiveQuery */ public function getProvider() { return $this->hasOne(\common\models\location\LocationProvider::className(), ['id' => 'provider_id']); }
public function createProvider() { $provider = new LocationProvider(); $provider->identity_info = LocationProvider::IDENTITY_KIND_POLICE . time(); $provider->save(); $this->_provider = $provider; }