/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Screen(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Screen'])) { $attributes = $_POST['Screen']; $attributes['user_id'] = Yii::app()->user->getId(); $model->attributes = $attributes; if ($model->save()) { $this->redirect(array('update', 'id' => $model->id)); } } $this->render('create', array('model' => $model)); }
public function testCreateScreen() { $newScreenName = "Screen test 1"; $this->object->setAttributes(array('name' => $newScreenName, 'description' => "New screen description.")); $this->assertTrue($this->object->save(FALSE)); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Screen(); $weather = new Weather(); $commercial = new Commercial(); $theme = new Theme(); $geocode = new Geocode(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Screen'])) { $model->attributes = $_POST['Screen']; if ($model->save()) { if (isset($_POST['Weather'])) { $weather->attributes = $_POST['Weather']; $screenWeather = new ScreenWeather(); $screenWeather->code = $weather->code; $screenWeather->screen_id = $model->id; if ($screenWeather->save()) { Yii::app()->user->setFlash('success', Yii::t('screen', 'Weather code assigned successfully.')); } else { Yii::app()->user->setFlash('error', Yii::t('screen', 'Could not assign the Weather Code to the Screen.')); } } if (isset($_POST['Commercial'])) { $commercial->attributes = $_POST['Commercial']; $screenCommercial = new ScreenCommercialAssignment(); $screenCommercial->commercial_id = $commercial->id; $screenCommercial->screen_id = $model->id; if ($screenCommercial->save()) { Yii::app()->user->setFlash('success', Yii::t('screen', 'Commercial Area assigned successfully.')); } else { Yii::app()->user->setFlash('error', Yii::t('screen', 'Could not assign the Commercial Area to the Screen.')); } } if (isset($_POST['Theme'])) { $theme->attributes = $_POST['Theme']; $screenTheme = new ScreenThemeAssignment(); $screenTheme->theme_id = $theme->id; $screenTheme->screen_id = $model->id; if ($screenTheme->save()) { Yii::app()->user->setFlash('success', Yii::t('screen', 'Theme assigned successfully.')); } else { Yii::app()->user->setFlash('error', Yii::t('screen', 'Could not assign the theme to the Screen.')); } } // Create geocode and insert the lng and lat and assign it to the screen $location = $model->geocodeLookup($model->name . ',' . $model->yeshuv->name_heb); $geocode->lat = $location['lat']; $geocode->lng = $location['lng']; if ($geocode->save()) { $screenGeocode = new ScreenGeocodeAssignment(); $screenGeocode->screen_id = $model->id; $screenGeocode->geocode_id = $geocode->id; if ($screenGeocode->save()) { Yii::app()->user->setFlash('success', Yii::t('screen', 'Geocode assigned successfully.')); } } else { Yii::app()->user->setFlash('error', Yii::t('screen', 'Could not assign the Geocode to the Screen.')); } Yii::app()->user->setFlash('success', Yii::t('screen', 'Screen created successfully.')); $this->redirect(array('view', 'id' => $model->id)); } } $this->render('create', array('model' => $model, 'weather' => $weather, 'commercial' => $commercial, 'theme' => $theme)); }