예제 #1
0
 /**
  * User profile action
  *
  * @return void
  */
 public function profileAction()
 {
     $request = $this->getRequest();
     $user = $this->_user;
     $form = new \Application_Form_UserUpdate($user);
     if ($request->isPost()) {
         if ($form->isValid($request->getPost())) {
             $data = $form->getValues();
             try {
                 $changed = $this->_updateUser($user, $data);
                 $this->view->success = 1;
                 if ($changed) {
                     $message = 'Profile updated successfully.';
                     $msgPriority = 'success';
                     $form = new \Application_Form_UserUpdate($user);
                 } else {
                     $message = 'No changes were made.';
                     $msgPriority = 'notice';
                 }
                 $this->view->messages()->addMessage($message, $msgPriority);
             } catch (Exception $e) {
                 $this->getResponse()->setHttpResponseCode(500);
                 $this->view->success = 0;
                 #$message = ('development' == APPLICATION_ENV ? $e->getMessage() : 'Application error: UCPA001');
                 $message = 'Application error: UCPA001 - ' . $e->getMessage();
                 $this->view->messages()->addMessage($message, 'error');
                 Logger::err($e->getMessage());
             }
         } else {
             // Submitted form data is invalid
             $this->getResponse()->setHttpResponseCode(500);
             $this->view->success = 0;
         }
     } else {
         // Not a POST request
     }
     $this->view->form = $form;
     JqueryViewHelper::assignData(array('userId' => $user->getId()));
 }
예제 #2
0
 /**
  * Edit action
  *
  * @return void
  */
 public function editAction()
 {
     $request = $this->getRequest();
     $timeZone = new DateTimeZone($this->_user->getProfile()->getTimeZone()->getName());
     $params = $request->getParams();
     // Get the user that is being updated
     $userId = $request->getParam('userId', null);
     if (null === ($user = UserService::findOneById($userId))) {
         throw new \Admin_UsersControllerException('No user found.');
     }
     $form = new \Admin_Form_UserEdit();
     $form->setDefaultsFromUser($user);
     // Pre-validate form; set conditional requirements
     $form->preValidate($request->getParams());
     if ($request->isPost()) {
         // AJAX request with partial form submission? (probably an AJAX request to update a single property)
         if ($request->isXmlHttpRequest() && $form->isValidPartial($params)) {
             #Logger::debug(__METHOD__.':: params-pre = '.var_export($params, true));
             $params = array_merge($params, $this->_prepFormData($form->getValues(), $user));
             #Logger::debug(__METHOD__.':: params-post = '.var_export($params, true));
         }
         if ($form->isValid($params)) {
             $data = $form->getValues();
             #Logger::debug(__METHOD__.':: data = '.var_export($data, true));
             try {
                 $changed = $this->_updateUser($user, $data);
                 $this->view->success = 1;
                 $this->view->userId = $userId;
                 if ($changed) {
                     $message = 'User modified successfully.';
                     $msgPriority = 'success';
                 } else {
                     $message = 'No changes were made.';
                     $msgPriority = 'notice';
                 }
                 if (!$request->isXmlHttpRequest()) {
                     $this->_helper->sessionMessenger($message, $msgPriority);
                     return $this->_helper->getHelper('Redirector')->gotoRoute(array(), 'adminUsers');
                 }
                 $this->view->messages()->addMessage($message, $msgPriority);
             } catch (Exception $e) {
                 $this->getResponse()->setHttpResponseCode(500);
                 $this->view->success = 0;
                 $message = 'development' == APPLICATION_ENV ? $e->getMessage() : 'Application error: AUCEA001';
                 $this->view->messages()->addMessage($message, 'error');
                 Logger::err(__METHOD__ . '::' . $e->getMessage());
             }
         } else {
             // Submitted form data is invalid
             $this->getResponse()->setHttpResponseCode(500);
             $this->view->success = 0;
             Logger::debug(__METHOD__ . ':: formErrors = ' . var_export($form->getMessages(), true));
             if ($request->isXmlHttpRequest()) {
                 $this->view->messages()->addMessage('Application error: AUCEA000', 'error');
                 #$this->view->messages()->addMessage($form->getMessages(), 'error');
             }
         }
     } else {
         // Not a POST request
         $form->setDefaultsFromUser($user);
     }
     $this->view->assign(array('editHistory' => UserEditEventService::findByUser($user->getId()), 'timeZone' => $timeZone, 'form' => $form, 'userId' => $userId));
     JqueryViewHelper::assignData(array('userId' => $userId));
 }