/** * 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; }