public function actionAdduser() { $project = $this->loadModel(); if (!Yii::app()->user->checkAccess('createUser', array('project' => $project))) { throw new CHttpException(403, 'You are not authorized to per-form this action.'); } $form = new ProjectUserForm(); // collect user input data if (isset($_POST['ProjectUserForm'])) { $form->attributes = $_POST['ProjectUserForm']; $form->project = $project; // validate user input and set a sucessfull flassh message if valid if ($form->validate()) { Yii::app()->user->setFlash('success', $form->username . " has been added to the project."); $form = new ProjectUserForm(); } } // display the add user form $users = User::model()->findAll(); $usernames = array(); foreach ($users as $user) { $usernames[] = $user->username; } $form->project = $project; $this->render('adduser', array('model' => $form, 'usernames' => $usernames)); }
/** * Add User to project */ public function actionAddUser($id) { $form = new ProjectUserForm(); $project = $this->loadModel($id); //Get form data if (isset($_POST['ProjectUserForm'])) { $form->attributes = $_POST['ProjectUserForm']; $form->project = $project; //Validate and display success message if ($form->validate()) { Yii::app()->user->setFlash('success', $form->username . "has been added to the project!"); $form = new ProjectUserForm(); } } //display form $users = User::model()->findAll(); $usernames = array(); foreach ($users as $user) { $usernames[] = $user->username; } $form->project = $project; $this->render('adduser', array('model' => $form, 'usernames' => $usernames)); }
/** * Provides a form so that project administrators can * associate other users to the project */ public function actionAdduser($id) { $project = $this->loadModel($id); if (!Yii::app()->user->checkAccess('createUser', array('project' => $project))) { throw new CHttpException(403, 'You are not authorized to perform this action.'); } $form = new ProjectUserForm(); // collect user input data if (isset($_POST['ProjectUserForm'])) { $form->attributes = $_POST['ProjectUserForm']; $form->project = $project; // validate user input if ($form->validate()) { if ($form->assign()) { Yii::app()->user->setFlash('success', $form->username . " has been added to the project."); //reset the form for another user to be associated if desired $form->unsetAttributes(); $form->clearErrors(); } } } $form->project = $project; $this->render('adduser', array('model' => $form)); }
public function actionAddUser($id) { $model = $this->loadModel($id); $model->checkAccess('createUser', true); $form = new ProjectUserForm(); // collect user input data if (isset($_POST['ProjectUserForm'])) { $form->attributes = $_POST['ProjectUserForm']; $form->project = $model; // validate user input and set a successful flash message if ($form->validate()) { Yii::app()->user->setFlash('success', $form->username . ' has been added to the project.'); $form = new ProjectUserForm(); } } // display the add user form $users = User::model()->findAll(); $usernames = array(); foreach ($users as $user) { $usernames[] = $user->username; } $form->project = $model; $this->render('adduser', array('model' => $form, 'usernames' => $usernames)); }