/** **显示一个事件详情,包括涉事儿童信息和当前节点简要信息. * @param $id * @return string * @throws HttpException */ public function actionEvent($id) { /** @var LocationNew $location_new */ $location_new = LocationNew::find()->where('event_id=:event_id and is_reliable=1', [':event_id' => $id])->with('provider')->orderBy('occur_at DESC')->one(); /** @var Event $event */ $event = Event::find()->where('id=:id', [':id' => $id])->with(['user', 'profiles'])->one(); if (!$location_new || !$event) { throw new HttpException(404, 'The resource you request does not exist'); } return $this->render('event', ['event' => $event, 'profile' => $event->profiles[0], 'location_new' => $location_new, 'provider' => $location_new->provider]); }
/** * Finds the LocationNew model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return LocationNew the loaded model * @throws HttpException if the model cannot be found */ protected function findModel($id) { if (($model = LocationNew::findOne($id)) !== null) { return $model; } else { throw new HttpException(404, 'The requested page does not exist.'); } }
public function createLocationNew() { $location_new = new LocationNew(); $location_new->attributes = ['user_id' => Yii::$app->user->id, 'event_id' => $this->event_id, 'provider_id' => $this->getProvider()->id, 'city' => $this->city, 'title_from_provider' => $this->title_from_provider, 'occur_at' => $this->occur_at]; $details = Yii::$app->map->searchWithTitle($this->city, $this->title_from_provider); if (!$details) { throw new MapWithTitleException('无法获取该位置准确经纬度,请修改位置信息重试'); } $location_new->title_from_API = $details['title']; $location_new->latitude = $details['latitude']; $location_new->longitude = $details['longitude']; if ($this->identity_kind == LocationProvider::IDENTITY_KIND_PEOPLE) { $location_new->is_reliable = $this->isSpaceReliable(); } $location_new->save(); $this->_location_new = $location_new; }
/** * @return \yii\db\ActiveQuery */ public function getLocationNews() { return $this->hasMany(\common\models\location\LocationNew::className(), ['event_id' => 'id']); }