Example #1
0
 /**
  * @module User
  * @action Update
  * @return array
  */
 public function updateAction()
 {
     if ($this->getRequest()->isPost()) {
         $params = $this->getRequest()->getParams();
         $idEmail = $params['id_email'];
         $id = $this->getRequest()->getParam('id_user');
         $user = UserQuery::create()->findByPKOrThrow($id, $this->i18n->_("It does not exist the User with id {$id}"));
         if (isset($idEmail)) {
             $emailQuery = EmailQuery::create()->findByPK($idEmail);
         }
         if (count($emailQuery) > 0) {
             $email = $emailQuery;
         } else {
             $email = EmailFactory::createFromArray($params);
             $this->getEmailCatalog()->create($email);
             $this->getUserCatalog()->linkToEmail($user->getIdPerson(), $email->getIdEmail());
         }
         $emailPerson = UserQuery::create()->innerJoinEmail()->whereAdd('Person.' . User::ID_PERSON, $user->getIdPerson())->whereAdd('Email.' . Email::ID_EMAIL, $email->getIdEmail(), UserQuery::NOT_EQUAL)->addColumn('Person2Email.id_email')->fetchCol();
         foreach ($emailPerson as $unlinkableMail) {
             $this->getUserCatalog()->unlinkFromEmail($user->getIdPerson(), $unlinkableMail);
         }
         try {
             $this->getUserCatalog()->beginTransaction();
             $accessRole = $this->getRequest()->getParam('id_access_role');
             $username = $this->getRequest()->getParam('username');
             $pass = $this->getRequest()->getParam('password');
             $name = $this->getRequest()->getParam('name');
             $lastName = $this->getRequest()->getParam('last_name');
             $secondName = $this->getRequest()->getParam('second_name');
             $notifications = $this->getRequest()->getParam('notifications') == User::$ReceiveNotifications['Yes'] ? User::$ReceiveNotifications['Yes'] : User::$ReceiveNotifications['No'];
             $userParams = array('id_access_role' => $accessRole, 'username' => $username, 'name' => $name, 'last_name' => $lastName, 'second_name' => $secondName, 'notifications' => $notifications);
             if ($pass) {
                 $userParams['password'] = new Zend_Db_Expr("PASSWORD('{$pass}')");
             }
             UserFactory::populate($user, $userParams);
             $this->getUserCatalog()->update($user);
             EmailFactory::populate($email, $params);
             $this->getEmailCatalog()->update($email);
             $this->newLogForUpdate($user);
             $this->getUserCatalog()->commit();
             $this->setFlash('ok', $this->i18n->_("Se actualizo correctamente el User"));
         } catch (Exception $e) {
             $this->getUserCatalog()->rollBack();
             $this->setFlash('error', $this->i18n->_($e->getMessage()));
         }
     }
     $this->_redirect('user/list');
 }
Example #2
0
 /**
  *
  * @param NotificationType $notificationType
  * @return array
  */
 private function getEmails(NotificationType $notificationType)
 {
     $emails = new EmailCollection();
     $regexp = self::EMAIL_REGEXP;
     $notificationTypeCatalog = $this->getCatalog('NotificationTypeCatalog');
     $accessRoles = AccessRoleQuery::create()->whereAdd(AccessRole::ID_ACCESS_ROLE, $notificationTypeCatalog->getAllAccessRoles($notificationType->getIdNotificationType()), AccessRoleQuery::IN)->find();
     while ($accessRoles->valid()) {
         $accessRole = $accessRoles->read();
         $users = UserQuery::create()->whereAdd(User::ID_ACCESS_ROLE, $accessRole->getIdAccessRole())->whereAdd(User::NOTIFICATIONS, User::$ReceiveNotifications['Yes'])->actives()->find();
         while ($users->valid()) {
             $user = $users->read();
             $email = EmailQuery::create()->innerJoinPerson()->whereAdd('Person.id_person', $user->getIdPerson())->findOne();
             if (!$email instanceof Email) {
                 $eventDispatcher = $this->getEventDispatcherService();
                 $eventDispatcher->createUserMissingEmailNotification($user, ErrorEvent::MISSING_USER_EMAIL, $notificationType);
                 continue;
             } elseif (!preg_match($regexp, $email->getEmail())) {
                 // 					$eventDispatcher->createIncorectUserEmailNotification($user, ErrorEvent::INCORRECT_USER_EMAIL, $notificationType);
             } else {
                 $emails->append($email);
             }
         }
     }
     $emailsArray = array_values($emails->filter(function (Email $email) use($regexp) {
         return preg_match($regexp, $email->getEmail());
     })->toCombo());
     return array_unique($emailsArray);
 }