Beispiel #1
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'show' page.
  */
 public function actionUpdate()
 {
     $model = $this->loadModel();
     // explicitly set model scenario to be current action
     //$model->setScenario($this->action->id);
     // whether data is passed
     if (isset($_POST['Location'])) {
         // collect user input data
         $model->attributes = $_POST['Location'];
         // validate with the current action as scenario and save without validation
         if (($validated = $model->validate()) !== false && ($saved = $model->save(false)) !== false) {
             // set success message
             MUserFlash::setTopSuccess(Yii::t('hint', 'The "{title}" location record has been updated.', array('{title}' => MHtml::wrapInTag($model->title, 'strong'))));
             // go to the 'show' page
             $this->redirect(array('show', 'id' => $model->id));
         }
     }
     $this->render($this->action->id, array('model' => $model));
 }
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'show' page.
  */
 public function actionUpdate()
 {
     if (($model = $this->loadModel()) === null) {
         // model not found
         MUserFlash::setTopError(Yii::t('modelNotFound', $this->id));
         $this->redirect($this->getGotoUrl());
     }
     // explicitly set model scenario to be current action
     //$model->setScenario($this->action->id);
     // whether data is passed
     if (isset($_POST['CompanyPayment'])) {
         // collect user input data
         $model->attributes = $_POST['CompanyPayment'];
         // validate with the current action as scenario and save without validation
         if (($validated = $model->validate()) !== false && ($saved = $model->save(false)) !== false) {
             // set success message
             MUserFlash::setTopSuccess(Yii::t('hint', 'The company payment record number "{paymentNumber}" has been updated.', array('{paymentNumber}' => MHtml::wrapInTag(empty($model->paymentNumber) ? $model->id : $model->paymentNumber, 'strong'))));
             // go to the 'show' page
             $this->redirect(array('show', 'id' => $model->id));
         }
     }
     $this->render($this->action->id, array('model' => $model));
 }
Beispiel #3
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'show' page.
  */
 public function actionUpdate()
 {
     $model = $this->loadModel(array('with' => array('allCompany2Project', 'allManager2Project')));
     if ($model === null) {
         // model not found
         MUserFlash::setTopError(Yii::t('modelNotFound', $this->id));
         $this->redirect($this->getGotoUrl());
     }
     // explicitly set model scenario to be current action
     //$model->setScenario($this->action->id);
     // whether data is passed
     if (isset($_POST['Project'])) {
         // collect user input data
         $model->attributes = $_POST['Project'];
         // validate with the current action as scenario and save without validation
         if (($validated = $model->validate()) !== false && ($saved = $model->save(false)) !== false) {
             if (isset($_POST['Company2Project'])) {
                 // assigned companies
                 $hasCompany = isset($model->allCompany2Project[0]->id);
                 if (!$hasCompany) {
                     $model->allCompany2Project = array(0 => new Company2Project('create'));
                     $model->allCompany2Project[0]->projectId = $model->id;
                 }
                 foreach ($model->allCompany2Project as $company2Project) {
                     // collect user input data
                     $company2Project->attributes = $_POST['Company2Project'];
                     // at the crossroads: which action is expected to be performed
                     if ($hasCompany && empty($company2Project->companyId)) {
                         // un-assigned associated record
                         $company2Project->delete();
                     } else {
                         // validate and create/update record
                         $company2Project->save();
                     }
                 }
             }
             if (isset($_POST['User2Project'])) {
                 // assigned managers
                 $hasManager = isset($model->allManager2Project[0]->id);
                 if (!$hasManager) {
                     $model->allManager2Project = array(0 => new User2Project('create'));
                     $model->allManager2Project[0]->projectId = $model->id;
                 }
                 foreach ($model->allManager2Project as $manager2Project) {
                     // collect user input data
                     $manager2Project->attributes = $_POST['User2Project'];
                     // at the crossroads: which action is expected to be performed
                     if ($hasManager && empty($manager2Project->userId)) {
                         // un-assigned associated record
                         $manager2Project->delete();
                     } else {
                         // validate and create/update record
                         $manager2Project->save();
                     }
                 }
             }
             // set success message
             MUserFlash::setTopSuccess(Yii::t('hint', 'The "{title}" project record has been updated.', array('{title}' => MHtml::wrapInTag($model->title, 'strong'))));
             // go to the 'show' page
             $this->redirect(array('show', 'id' => $model->id));
         }
     }
     if (!isset($model->allCompany2Project[0])) {
         // new associated company
         $model->allCompany2Project = array(0 => new Company2Project('create'));
         $model->allCompany2Project[0]->projectId = $model->id;
     }
     if (!isset($model->allManager2Project[0])) {
         // new associated manager
         $model->allManager2Project = array(0 => new User2Project('create'));
         $model->allManager2Project[0]->projectId = $model->id;
         $model->allManager2Project[0]->role = User2Project::MANAGER;
     }
     $this->render($this->action->id, array('model' => $model));
 }
Beispiel #4
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'show' page.
  */
 public function actionUpdate()
 {
     $model = $this->loadModel(array('with' => array('allUser2Company', 'allLocation')));
     if ($model === null) {
         // model not found
         MUserFlash::setTopError(Yii::t('modelNotFound', $this->id));
         $this->redirect($this->getGotoUrl());
     }
     // explicitly set model scenario to be current action
     //$model->setScenario($this->action->id);
     // whether data is passed
     if (isset($_POST['Company'])) {
         // collect user input data
         $model->attributes = $_POST['Company'];
         // validate with the current action as scenario and save without validation
         if (($validated = $model->validate()) !== false && ($saved = $model->save(false)) !== false) {
             if (isset($_POST['User2Company'])) {
                 // assigned users
                 $hasUser = isset($model->allUser2Company[0]->id);
                 if (!$hasUser) {
                     $model->allUser2Company = array(0 => new User2Company('create'));
                     $model->allUser2Company[0]->companyId = $model->id;
                 }
                 foreach ($model->allUser2Company as $user2Company) {
                     // collect user input data
                     $user2Company->attributes = $_POST['User2Company'];
                     $user2Company->position = 'owner';
                     // at the crossroads: which action is expected to be performed
                     if ($hasUser && empty($user2Company->userId)) {
                         // un-assigned associated record
                         $user2Company->delete();
                     } else {
                         // validate and create/update record
                         $user2Company->save();
                     }
                 }
             }
             if (isset($_POST['Location'])) {
                 // assigned locations
                 if (!isset($model->allLocation[0]->id)) {
                     $model->allLocation = array(0 => new Location('create'));
                 }
                 foreach ($model->allLocation as $location) {
                     // collect user input data
                     $location->attributes = $_POST['Location'];
                     // validate and create/update record
                     if ($location->save()) {
                         $location2Record = new Location2Record('create');
                         $location2Record->locationId = $location->id;
                         $location2Record->record = get_class($model);
                         $location2Record->recordId = $model->id;
                         $location2Record->save();
                     }
                 }
             }
             // set success message
             MUserFlash::setTopSuccess(Yii::t('hint', 'The "{title}" company record has been updated.', array('{title}' => MHtml::wrapInTag($model->title, 'strong'))));
             // go to the 'show' page
             $this->redirect(array('show', 'id' => $model->id));
         }
     }
     if (!isset($model->allUser2Company[0])) {
         // new associated user
         $model->allUser2Company = array(0 => new User2Company('create'));
         $model->allUser2Company[0]->companyId = $model->id;
     }
     if (!isset($model->allLocation[0])) {
         // new associated location
         $model->allLocation = array(0 => new Location('create'));
     }
     // display the update form
     $this->render($this->action->id, array('model' => $model));
 }
Beispiel #5
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'show' page.
  */
 public function actionUpdate()
 {
     if (($model = $this->loadModel(array('with' => array('allConsultant2Task')))) === null) {
         // model not found
         MUserFlash::setTopError(Yii::t('modelNotFound', $this->id));
         $this->redirect($this->getGotoUrl());
     }
     // explicitly set model scenario to be current action
     //$model->setScenario($this->action->id);
     // whether data is passed
     if (isset($_POST['Task'])) {
         // collect user input data
         $model->attributes = $_POST['Task'];
         if (!isset($_POST['Task']['companyId'])) {
             // set company based on the project
             if ($model->projectId >= 1) {
                 $criteria = new CDbCriteria();
                 $criteria->order = "`t`.`companyPriority` ASC, `t`.`id` ASC";
                 if (($company2Project = Company2Project::model()->findByAttributes(array('projectId' => $model->projectId), $criteria)) !== null) {
                     $model->companyId = $company2Project->companyId;
                 } else {
                     $model->companyId = 0;
                 }
             } else {
                 $model->companyId = 0;
             }
         }
         if ($model->projectId >= 1 && empty($model->hourlyRate)) {
             // set project's hourly rate
             if (($project = Project::model()->findByPk($model->projectId)) !== null) {
                 $model->hourlyRate = $project->hourlyRate;
             }
         }
         // validate with the current action as scenario and save without validation
         if (($validated = $model->validate()) !== false && ($saved = $model->save(false)) !== false) {
             if (isset($_POST['User2Task'])) {
                 // assigned consultants
                 $hasConsultant = isset($model->allConsultant2Task[0]->id);
                 if (!$hasConsultant) {
                     $model->allConsultant2Task = array(0 => new User2Task('create'));
                     $model->allConsultant2Task[0]->taskId = $model->id;
                 }
                 foreach ($model->allConsultant2Task as $consultant2Task) {
                     // collect user input data
                     $consultant2Task->attributes = $_POST['User2Task'];
                     // at the crossroads: which action is expected to be performed
                     if ($hasConsultant && empty($consultant2Task->userId)) {
                         // un-assigned associated record
                         $consultant2Task->delete();
                     } else {
                         // validate and create/update record
                         $consultant2Task->save();
                     }
                 }
             }
             if (($managers2Task = User2Task::model()->findAllByAttributes(array('taskId' => $model->id, 'role' => User2Task::MANAGER))) !== array()) {
                 // delete existing relation(s) between task and manager
                 foreach ($managers2Task as $manager2Task) {
                     $manager2Task->delete();
                 }
             }
             if ($model->projectId >= 1) {
                 // new relation between task and manager
                 $criteria = new CDbCriteria();
                 $criteria->order = "`t`.`userPriority` ASC, `t`.`id` ASC";
                 if (($user2Project = User2Project::model()->findByAttributes(array('projectId' => $model->projectId, 'role' => User2Project::MANAGER), $criteria)) !== null) {
                     $user2Task = new User2Task('create');
                     $user2Task->userId = $user2Project->userId;
                     $user2Task->taskId = $model->id;
                     $user2Task->role = User2Task::MANAGER;
                     $user2Task->save();
                 }
             }
             // set success message
             MUserFlash::setTopSuccess(Yii::t('hint', 'The "{title}" task record has been updated.', array('{title}' => MHtml::wrapInTag($model->title, 'strong'))));
             // go to the 'show' page
             $this->redirect(array('show', 'id' => $model->id));
         }
     }
     if (!isset($model->allConsultant2Task[0])) {
         // new associated consultant
         $model->allConsultant2Task = array(0 => new User2Task('create'));
         $model->allConsultant2Task[0]->taskId = $model->id;
         $model->allConsultant2Task[0]->role = User2Task::CONSULTANT;
     }
     // prepare model data for the form
     $model->estimateH = floor($model->estimateMinute / 60);
     $model->estimateM = fmod($model->estimateMinute, 60);
     // render the view file
     $this->render($this->action->id, array('model' => $model));
 }
Beispiel #6
0
 /**
  * Update user interface.
  * Accessible only to authenticated users and admin.
  * If update is successful, the browser will be redirected to the 'show' page.
  */
 public function actionUpdateInterface()
 {
     if (!Yii::app()->user->checkAccess($this->route, array('model' => $this->loadModel()))) {
         // access denied
         MUserFlash::setTopError(Yii::t('accessDenied', $this->route));
         $this->redirect($this->getGotoUrl());
     }
     $pkIsPassed = isset($_GET['id']);
     if (($model = $this->loadModel()) === null) {
         // model not found
         MUserFlash::setTopError(Yii::t('modelNotFound', $this->id));
         $this->redirect($this->getGotoUrl());
     }
     // explicitly set model scenario to be current action
     $model->setScenario($this->action->id);
     if (is_object($model->details)) {
         $model->details->setScenario($this->action->id);
     }
     // whether data is passed
     if (isset($_POST['User'])) {
         // collect user input data
         $model->attributes = $_POST['User'];
         // validate with the current action as scenario and save without validation
         if (($validated = $model->validate()) !== false && ($saved = $model->save(false)) !== false) {
             // take care of updateTime (this is not critical)
             $model->details->saveAttributes(array('updateTime' => time()));
             // update variables first defined in {@link _CUserIdentity} class
             if ($model->isMe) {
                 // update user states in the session for {@link _CController::init}
                 Yii::app()->user->setState('interface', $model->interface);
                 // set user preferred interface
                 if (!empty($model->interface)) {
                     W3::setInterface($model->interface);
                 }
                 // we do not need to update user cookie any more because
                 // we overrode auto-login with {@link _CWebUser::restoreFromCookie}
             }
             // set success message
             MUserFlash::setTopSuccess(Yii::t('hint', $model->isMe ? '{screenName}, new user interface has been applied.' : 'The user interface for member account "{screenName}" has been updated.', array('{screenName}' => MHtml::wrapInTag($model->screenName, 'strong'))));
             // go to 'show' page
             $this->redirect($model->isMe ? array('show') : array('show', 'id' => $model->id));
         } else {
             if ($validated && !$saved) {
                 // set error message
                 MUserFlash::setTopError(Yii::t('hint', $model->isMe ? 'Error! {screenName}, new user interface could not be applied.' : 'Error! The user interface for member account "{screenName}" could not be updated.', array('{screenName}' => MHtml::wrapInTag($model->screenName, 'strong'))));
                 Yii::log(W3::t('system', 'Could not save attributes of the {model} model. Model ID: {modelId}. Method called: {method}.', array('{model}' => get_class($model), '{modelId}' => $model->id, '{method}' => __METHOD__ . '()')), 'error', 'w3');
             }
         }
     }
     // display the update form
     $this->render($this->action->id, array('model' => $model, 'pkIsPassed' => $pkIsPassed));
 }
Beispiel #7
0
 /**
  * Deletes a particular model via ajax request.
  * The report is printed out in the json format,
  * and is displayed in a dialog.
  */
 public function actionAjaxDelete()
 {
     if (!Yii::app()->request->isAjaxRequest) {
         throw new CHttpException(400, Yii::t('http', 'Invalid request. Please do not repeat this request again.'));
         exit;
     }
     if (!isset($_POST['id'])) {
         // data not passed
         $this->printJsonExit(array('status' => 'error', 'message' => Yii::t('hint', 'Error! Necessary data was not passed.')));
     }
     if (($model = $this->loadModel()) === null) {
         // model not found
         $this->printJsonExit(array('status' => 'error', 'message' => Yii::t('modelNotFoundById', $this->id, array('{id}' => MHtml::wrapInTag($_POST['id'], 'strong')))));
     }
     if ($model->delete()) {
         // success
         $this->printJson(array('status' => 'success', 'message' => Yii::t('hint', 'The time record number {id} has been successfully deleted.', array('{id}' => MHtml::wrapInTag($model->id, 'strong')))));
     } else {
         // error
         $this->printJson(array('status' => 'error', 'message' => Yii::t('hint', 'Error! The time record number {id} could not be deleted.', array('{id}' => MHtml::wrapInTag($model->id, 'strong')))));
         // save the error in the logs
         Yii::log(W3::t('system', 'Could not delete the {model} model. Model ID: {modelId}. Method called: {method}.', array('{model}' => get_class($model), '{modelId}' => $model->id, '{method}' => __METHOD__ . '()')), 'error', 'w3');
     }
 }
Beispiel #8
0
 /**
  * Logout the current user and redirect to homepage.
  */
 public function actionLogout()
 {
     $isLoggedIn = !Yii::app()->user->isGuest;
     $screenName = $isLoggedIn ? Yii::app()->user->screenName : '';
     // log user out and destroy all session data
     // if you want to keep the session alive, then use Yii::app()->user->logout(false) instead
     Yii::app()->user->logout();
     // if user was logged in, we should notify about logout
     if ($isLoggedIn) {
         if (!Yii::app()->getSession()->getIsStarted()) {
             // if session is destroyed, we need to re-open it. this is necessary for user flash
             Yii::app()->getSession()->open();
         }
         // set the goodbye message
         MUserFlash::setTopInfo(Yii::t('hint', '{screenName}, you have been successfully logged out.', array('{screenName}' => MHtml::wrapInTag($screenName, 'strong'))));
     }
     // go to home page
     $this->redirect(Yii::app()->homeUrl);
 }