public static function store() { $p = $_POST; $group = new Group($p); if (count($group->validate()) > 0) { die("errors"); $errors = $group->validate(); View::make("group/new.html", array("errors" => $errors, 'name' => $_POST['name'])); } else { $group->store(); Redirect::to("/group", array('message' => "New Group has been saved.")); } }
/** * This function performs the validation work for complex object models. * * In addition to checking the current object, all related objects will * also be validated. If all pass then <code>true</code> is returned; otherwise * an aggreagated array of ValidationFailed objects will be returned. * * @param array $columns Array of column names to validate. * @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise. */ protected function doValidate($columns = null) { if (!$this->alreadyInValidation) { $this->alreadyInValidation = true; $retval = null; $failureMap = array(); // We call the validate method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aGroup !== null) { if (!$this->aGroup->validate($columns)) { $failureMap = array_merge($failureMap, $this->aGroup->getValidationFailures()); } } if ($this->aUser !== null) { if (!$this->aUser->validate($columns)) { $failureMap = array_merge($failureMap, $this->aUser->getValidationFailures()); } } if (($retval = DirectoryPermissionPeer::doValidate($this, $columns)) !== true) { $failureMap = array_merge($failureMap, $retval); } $this->alreadyInValidation = false; } return !empty($failureMap) ? $failureMap : true; }
public function postGroup($id = null) { if (Input::has('id')) { $group = Group::find(Input::get('id')); if (!$group->isGroupOwner(Auth::user()->id)) { return Response::json($this->growlMessage('You cannot modify a group you do not own.', 'error')); } $message = "Your group has been updated!"; } else { $group = new Group(); $group->status = Group::STATUS_PENDING; $message = "Your group has been created! It must be approved before you can invite others to join or create documents."; } $postData = array('name', 'display_name', 'address1', 'address2', 'city', 'state', 'postal_code', 'phone_number'); foreach ($postData as $field) { $group->{$field} = Input::get($field); } if ($group->validate()) { $group->save(); $group->addMember(Auth::user()->id, Group::ROLE_OWNER); if ($group->status === Group::STATUS_PENDING) { Event::fire(MadisonEvent::VERIFY_REQUEST_GROUP, $group); } return Response::json($this->growlMessage($message, 'success')); } else { return Response::json($this->growlMessage($group->getErrors()->all(), 'error'), 400); } }
/** * Edits or Creates a user group */ public function actionEdit() { // Create Group Edit Form $group = Group::model()->findByPk(Yii::app()->request->getQuery('id')); if ($group === null) { $group = new Group(); } $group->scenario = 'edit'; $group->populateDefaultSpaceGuid(); $group->populateAdminGuids(); // uncomment the following code to enable ajax-based validation if (isset($_POST['ajax']) && $_POST['ajax'] === 'admin-group-form') { echo CActiveForm::validate($model); Yii::app()->end(); } if (isset($_POST['Group'])) { $_POST = Yii::app()->input->stripClean($_POST); $group->attributes = $_POST['Group']; if ($group->validate()) { $group->save(); // Redirect to admin groups overview $this->redirect(Yii::app()->createUrl('//admin/group')); } } $this->render('edit', array('group' => $group)); }
public function edit($name) { $group = Group::where('group_name', $name)->firstOrFail(); self::checkOwner(self::userFp(), $name); if (Request::isMethod('GET')) { return View::make('group.edit', ['group' => $group]); } else { $input = Input::only('group_name', 'group_title', 'description', 'submit_text', 'is_private'); Group::validate($input); Group::editGroup($group, $input); return Redirect::to("group/edit/{$name}"); } }
public function actionCreateGroup() { /* validate all query string param */ $model = new Group('create'); $fileModel = new FileUploadFormModel(); $fileModel->setScenario(FileUploadFormModel::FILE_UPLOAD_MODE_SINGLE); /*define the required variable for the controller base on the query string param */ if (isset($_POST['Group'])) { $model->setAttributes($_POST['Group']); //$fileHandler->LoadUploadedeImageToModel(); //$model->photos = $fileHandler->photos; //$model->photos = CUploadedFile::getInstancesByName(BSMultiFileUploadWidget::fieldName); if ($model->validate()) { $fileModel->LoadUploadedeImage(); if ($fileModel->isUploadedFile()) { if ($fileModel->validate()) { $SavedFileRelativePaths = $fileModel->processImage(get_class($model), $model->group_name, md5(DateTimeHelper::now())); $model->apply_img = ArrayHelper::array2string($SavedFileRelativePaths); if ($model->save()) { $model->addOwnerUser(Yii::app()->user->id); Yii::app()->user->setFlash(FlashMsg::SUCCESS, "已提交組織申請"); $this->redirect(array('index')); } else { Yii::app()->user->setFlash(FlashMsg::ERROR, "提交組織申請失敗"); } } } else { if ($model->save()) { $model->addOwnerUser(Yii::app()->user->id); Yii::app()->user->setFlash(FlashMsg::SUCCESS, "已提交組織申請"); $this->redirect(array('index')); } else { Yii::app()->user->setFlash(FlashMsg::ERROR, "提交組織申請失敗"); } } } } $this->render('createGroup', array('model' => $model, 'fileModel' => $fileModel)); }
protected function _createGroup($opts = array()) { $group = new Group(array("name" => $opts["name"], "users" => $opts["users"])); if ($group->validate()) { $group->save(); return $group; } return false; }
/** * 创建小组 */ public function actionCreate() { $uid = Yii::app()->user->id; $model = new Group(); $model->scenario = 'create'; $category_list = $model->getGroupCategory(); $category_list = CHtml::listData($category_list, 'id', 'title'); if (!empty($_POST['Group'])) { $attributes = $_POST['Group']; $model->attributes = $attributes; $model->validate(); } $data = array('owner' => $owner, 'is_me' => $is_me, 'group' => $group, 'category_list' => $category_list); $this->render('create', $data); }