/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Characteristic();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Characteristic'])) {
         $model->attributes = $_POST['Characteristic'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Esempio n. 2
0
		public static function add($characteristic)
		{
			$char = Characteristic::getByCharacteristic($characteristic);
			if( !$char )
			{
				$char = new Characteristic(null, $characteristic);
				return $char->save();
			}
			else
			{
				return $char;
			}
		}
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     try {
         $model = new Characteristic();
         // Uncomment the following line if AJAX validation is needed
         // $this->performAjaxValidation($model);
         if (isset($_POST['Characteristic'])) {
             $model->attributes = $_POST['Characteristic'];
             if ($model->save()) {
                 Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, '<strong>Well!</strong> Characteristic created with sucess!');
                 Yii::app()->controller->refresh();
             }
         }
     } catch (Exception $e) {
         Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, '<strong>Ops!</strong> ERROR!');
         Yii::app()->controller->refresh();
     }
     $this->render('create', array('model' => $model));
 }
 protected function saveChar($model)
 {
     if (!($brand = Brand::model()->find('alias=:alias', array(':alias' => $model->brand_alias)))) {
         $brand = new Brand();
     }
     $brand->title = $model->brand;
     $brand->alias = $model->brand_alias;
     $brand->save();
     if (!empty($brand->errors)) {
         d('brand ' . $brand->title);
         d($brand->errors);
     }
     if (!($car = Car::model()->find('alias=:alias', array(':alias' => $model->model_alias)))) {
         $car = new Car();
     }
     $car->brand_id = $brand->id;
     $car->title = $model->model;
     $car->alias = $model->model_alias;
     $car->manufacture_start = $model->modificationManufactureStart . '0101';
     $car->manufacture_end = $model->modificationManufactureEnd ? $model->modificationManufactureEnd . '0101' : null;
     $car->save();
     if (!empty($car->errors)) {
         d('model ' . $car->title);
         d($car->errors);
     }
     if (!($mod = Modification::model()->find('alias=:alias', array(':alias' => $model->mod_alias)))) {
         $mod = new Modification();
     }
     $mod->model_id = $car->id;
     $mod->title = $model->mod;
     $mod->alias = $model->mod_alias;
     $mod->manufacture_start = $model->modificationManufactureStart . '0101';
     $mod->manufacture_end = $model->modificationManufactureEnd ? $model->modificationManufactureEnd . '0101' : null;
     $mod->save();
     if (!empty($mod->errors)) {
         d('mod ' . $mod->title);
         d($mod->errors);
     }
     if (!($char = Characteristic::model()->find('modification_id=:mod_id', array(':mod_id' => $mod->id)))) {
         $char = new Characteristic();
     }
     $char->attributes = $model->char->attributes;
     $char->modification_id = $mod->id;
     $char->save();
     if (!empty($char->errors)) {
         d('char ' . $mod->title);
         d($char->errors);
         d($model->url);
     }
 }