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; }
/** * 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; }
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; }
/** * Retrieve a model object from post data. An object will be created * and initialized with attribute values in $_POST. Attributes not in * $_POST are retrieved from DB. * * @param string $class name of the model class * @param mixed $filter * @param string $key if specified then $_POST[key] is used instead of $_POST[class] */ public function postModel($class, $filter = array(), $key = null) { if ($key == null) { $key = $class; } if (!isset($_POST[$key])) { return null; } $input = new XInputFilter($_POST[$key]); return $input->getModel($class, $filter); }
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; }
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; }
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; }
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(); } } } }