Beispiel #1
0
 public function actionSave(array $attributes, $validateOnly = false)
 {
     $input = new XInputFilter($attributes);
     $model = $input->getModel('Language');
     if (!$model->save()) {
         errorHandler()->log(new XException($model, 0));
     }
     $this->result = $model;
 }
Beispiel #2
0
 /**
  * Save a Module model
  *
  * @param array $attributes Model attributes
  * @return Module    */
 public function actionSave(array $attributes)
 {
     $input = new XInputFilter($attributes);
     $model = $input->getModel('Module');
     if (!$model->save()) {
         return $this->result = errorHandler()->commonException()->modelIsNotSaved($model);
     }
     return $this->result = $model;
 }
Beispiel #3
0
 public function actionSave(array $attributes)
 {
     $input = new XInputFilter($attributes);
     $model = $input->getModel('AdminUserGroup');
     if (!$model->save()) {
         errorHandler()->log(new XException($model, 0));
     }
     $this->result = $model;
 }
Beispiel #4
0
 public function actionSave(array $attributes)
 {
     if (isset($attributes['password']) && empty($attributes['password'])) {
         unset($attributes['password']);
     }
     if (isset($attributes['confirmPassword']) && empty($attributes['confirmPassword'])) {
         unset($attributes['confirmPassword']);
     }
     $input = new XInputFilter($attributes);
     $model = $input->getModel('AdminUser');
     /*if (!$model->validate())
       {
           errorHandler()->log(new XException($model,0));
       }
       else
       {
           if (!empty($model->password))
           {
               if ($model->isNewRecord)
                   $model->password = md5($model->password);
           }
           if (! $model->save(false))
               errorHandler()->log(new XException($model,0));
       }*/
     if (isset($attributes['password'])) {
         if (!empty($model->password)) {
             $model->password = md5($model->password);
         }
         if (isset($attributes['confirmPassword']) && !empty($model->confirmPassword)) {
             $model->confirmPassword = md5($model->confirmPassword);
         }
     } else {
         // case upate, the case password can be empty
         $model->confirmPassword = $model->password;
     }
     if (!$model->save()) {
         return $this->result = errorHandler()->logException($model, -1, 'XUSER_ERR_SAVE_ADMIN_USER_FAILED', array('message' => 'Saving Admin User has been failed'));
     }
     return $this->result = $model;
 }
Beispiel #5
0
 public function actionSave(array $attributes, $validateOnly = false)
 {
     $input = new XInputFilter($attributes);
     $model = $input->getModel('Term');
     $model->setScenario('single_save');
     if ($model->save()) {
         if ($model->parentId) {
             $relation = TermHierarchy::model()->findByAttributes(array('term_id' => $model->id));
             if (!is_object($relation)) {
                 $relation = new TermHierarchy();
                 $relation->term_id = $model->id;
             }
             $relation->parent_id = $model->parentId;
             if (!$relation->save()) {
                 Yii::log(CVarDumper::dumpAsString($relation->getErrors()), CLogger::LEVEL_ERROR);
             }
         }
     } else {
         errorHandler()->log(new XException($model, 0));
     }
     $this->result = $model;
 }
Beispiel #6
0
 public function actionSignUp(array $attributes)
 {
     $input = new XInputFilter($attributes);
     $model = $input->getModel('User');
     $attributes['password'] = randomString();
     $model->password = md5($attributes['password']);
     $model->validation_code = md5(randomString());
     $model->validation_type = User::VALIDATION_TYPE_ACTIVATE;
     defined('XUSER_VALIDATION_TIMESPAN') or define('XUSER_VALIDATION_TIMESPAN', 24 * 3600);
     $model->validation_expired = date('Y-m-d h:i:s', time() + XUSER_VALIDATION_TIMESPAN);
     $model->status = User::STATUS_INACTIVE;
     $model->setScenario('signup');
     if (!$model->save()) {
         errorHandler()->log(new XException(Yii::t('XUser.Api', CHtml::errorSummary($model))));
         return;
     }
     $this->result = true;
 }
Beispiel #7
0
 public function actionUpdate(array $attributes, $oldName = null, $oldModule = null, $oldOrdering = null)
 {
     $input = new XInputFilter($attributes);
     $param = $input->getModel('Setting');
     if ($param->module == 'System') {
         $param->module = '';
     }
     // Get old Name & Module
     if ($oldModule == 'System') {
         $oldModule = '';
     }
     if ($oldName == $param->name && $oldModule == $param->module) {
         // User didn't change primary key -> update as usual
         foreach ($param->attributes as $key => $attr) {
             if ($key !== 'name' && $key !== 'module') {
                 $updatedFields[$key] = $param->{$key};
             }
         }
         Setting::model()->updateByPk(array('name' => $oldName, 'module' => $oldModule), $updatedFields);
         $this->actionDb2php();
     } else {
         // Check if this new primary key exists or not
         $temp = Setting::model()->findByPk(array('name' => $param->name, 'module' => $param->module));
         if (!empty($temp)) {
             errorHandler()->log(Yii::t('Settings.Api', 'PARAMETER_EXISTS'));
         } else {
             Setting::model()->deleteByPk(array('name' => $oldName, 'module' => $oldModule));
             $param->ordering = $oldOrdering;
             if (!$param->save()) {
                 errorHandler()->log($this->normalizeModelErrors($param->Errors));
             } else {
                 $this->actionDb2php();
             }
         }
     }
 }
Beispiel #8
0
 public function cookie($name, $default = null, $filter = '')
 {
     $input = new XInputFilter($_COOKIE);
     return $input->getInput($name, $default, $filter);
 }