/** * Creates a new Location model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Location(); $model->loadDefaultValues(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } elseif (!Yii::$app->request->isPost) { $model->load(Yii::$app->request->get()); } if (Yii::$app->request->isAjax) { return $this->renderAjax('_form', ['model' => $model]); } return $this->render('create', ['model' => $model]); }
public function saveLocations($locations) { $user = User::thisUser(); Location::deleteAll(['entity' => self::THIS_ENTITY, 'entity_id' => $this->id]); if (is_array($locations)) { $locations = array_slice($locations, 0, self::MAX_LOCATION_SCHOOL); foreach ($locations as $location) { $newLocation = new Location(); $newLocation->user_id = $user->id; $newLocation->entity = self::THIS_ENTITY; $newLocation->entity_id = $this->id; $newLocation->title = $location['title']; $newLocation->description = $location['description']; $newLocation->lat = $location['lat']; $newLocation->lng = $location['lng']; $newLocation->zoom = $location['zoom']; $newLocation->type = $location['type']; $newLocation->save(); } } }