public function init() { parent::init(); if (is_null($this->attribute)) { throw new Exception("Module \"attribute\" attribute must be set"); } if (is_null($this->latitudeAttribute)) { throw new Exception("Module \"latitudeAttribute\" attribute must be set"); } if (is_null($this->longitudeAttribute)) { throw new Exception("Module \"longitudeAttribute\" attribute must be set"); } if (is_null($this->jsonAttribute)) { throw new Exception("Module \"jsonAttribute\" attribute must be set"); } if (is_null($this->class)) { $this->class = __NAMESPACE__ . '\\models\\Locations'; } $location = new $this->class(); $location->setAttributes(['destinationAttribute' => $this->attribute, 'latitudeAttribute' => $this->latitudeAttribute, 'longitudeAttribute' => $this->longitudeAttribute, 'jsonAttribute' => $this->jsonAttribute]); $this->location = $location; Event::on(Locations::className(), Locations::EVENT_ADD_LOCATION, [Locations::className(), 'addLocation']); Event::on(Locations::className(), Locations::EVENT_GET_LOCATION, [Locations::className(), 'getLocation']); return true; }
protected function createNewLocation($models) { $googleResponse = self::requestGoogleInfo($models); $googleJson = Json::decode($googleResponse); if ($googleJson['status'] != 'OK') { return null; } $location = new Locations(); $latLng = self::getDestinationLatLng($models); $location->setAttributes(['latitude' => $latLng[0], 'longitude' => $latLng[1], 'google_response' => $googleResponse]); if ($location->save()) { return $location; } return null; }