Example #1
0
 /**
  * Returns true if and only if $value meets the validation requirements
  *
  * If $value fails validation, then this method returns false, and
  * getMessages() will return an array of messages that explain why the
  * validation failed.
  *
  * @param  mixed $value
  * @return bool
  * @throws Exception\RuntimeException If validation of $value is impossible
  */
 public function isValid($value)
 {
     $user = $this->userService->get($value);
     if ($user) {
         $this->error(self::EMAIL_IN_USE);
         return false;
     }
     return true;
 }
Example #2
0
 public function testActiveUserActiveCompanyUserConnected2()
 {
     $service = new User();
     $service->setDataSource(self::$pdo);
     $result = $service->getTypeByCompany(3, 1);
     $this->assertInstanceOf('stdClass', $result);
     $this->assertEquals(0, $result->is_admin, 'is not admin');
     $this->assertEquals(0, $result->type, 'access is of type 1');
 }
Example #3
0
 /**
  * @return array
  * @throws \Stjornvisi\Service\Exception
  */
 private function getUsers()
 {
     $userService = new User();
     $userService->setDataSource($this->getDataSourceDriver())->setEventManager($this->getEventManager());
     return $userService->getUserMessage();
 }
Example #4
0
 /**
  * Get the recipient.
  *
  * @param $recipient
  * @return bool|null|object|\stdClass
  * @throws NotifyException
  * @throws \Stjornvisi\Service\Exception
  */
 private function getUser($recipient)
 {
     if (!$recipient) {
         throw new NotifyException('No recipient provided');
     }
     $user = new User();
     $user->setDataSource($this->getDataSourceDriver())->setEventManager($this->getEventManager());
     $userObject = null;
     //USER
     //	user can be in the system or he can be
     //	a guest, we have to prepare for both.
     if (is_numeric($recipient)) {
         $userObject = $user->get($recipient);
         if (!$userObject) {
             throw new NotifyException("User [{$recipient}] not found");
         }
     } else {
         $userObject = (object) array('name' => $recipient->name, 'email' => $recipient->email);
     }
     return $userObject;
 }
Example #5
0
 /**
  * @param int $id
  * @return \Stjornvisi\Service\User
  * @throws NotifyException
  * @throws \Stjornvisi\Service\Exception
  */
 public function getUser($id)
 {
     $pdo = new \PDO($this->dataStore['dns'], $this->dataStore['user'], $this->dataStore['password'], $this->dataStore['options']);
     $userService = new User();
     $userService->setDataSource($pdo)->setEventManager($this->getEventManager());
     if (($user = $userService->get($id)) != false) {
         return $user;
     } else {
         throw new NotifyException("User [{$id}] not found");
     }
 }
Example #6
0
 public function testTrue()
 {
     $service = new User();
     $service->setDataSource(self::$pdo);
     $service->attendance(1);
 }
Example #7
0
 /**
  * Set password for user then there is no
  * connection to storage.
  * @expectedException Exception
  */
 public function testSetPasswordException()
 {
     $service = new User();
     $service->setDataSource(new PDOMock());
     $service->setPassword(1, 'hundur');
 }
Example #8
0
 /**
  * @param $id
  * @return \Stjornvisi\Service\User
  * @throws \Stjornvisi\Service\Exception
  * @throws \Stjornvisi\Notify\NotifyException
  */
 private function getUser($id)
 {
     $userService = new User();
     $userService->setDataSource($this->getDataSourceDriver())->setEventManager($this->getEventManager());
     if (($user = $userService->get($id)) != false) {
         return $user;
     } else {
         throw new NotifyException("User [{$id}] not found");
     }
 }
Example #9
0
 /**
  * Try to change type of user
  * when there is no connection to
  * storage.
  * @expectedException Exception
  */
 public function testSetTypeException()
 {
     $service = new User();
     $service->setDataSource(new PDOMock());
     $service->setType(2, 1);
 }
Example #10
0
 /**
  * @param string $recipients
  * @param bool $test
  * @param int $sender_id
  * @param int $group_id
  * @return \Stjornvisi\Service\User[] array
  * @throws \Stjornvisi\Service\Exception
  */
 private function getUsers($recipients, $test, $sender_id, $group_id)
 {
     $userService = new User();
     $userService->setDataSource($this->getDataSourceDriver())->setEventManager($this->getEventManager());
     //ALL OR FORMEN
     //	send to all members of group or forman
     $exclude = $recipients == 'allir' ? [-1] : [0];
     //forman
     //TEST OR REAL
     //	if test, send ony to sender, else to all
     return $test ? array($userService->get($sender_id)) : $userService->getUserMessageByGroup([$group_id], $exclude);
 }
Example #11
0
 /**
  * @param array $groups
  * @param $eventId
  * @param $userId
  * @param $recipients
  * @param $test
  * @return \Stjornvisi\Service\User[]
  * @throws NotifyException
  * @throws \Stjornvisi\Service\Exception
  */
 private function getUser(array $groups, $eventId, $userId, $recipients, $test)
 {
     $user = new User();
     $user->setDataSource($this->getDataSourceDriver())->setEventManager($this->getEventManager());
     //TEST
     //	this is just a test message so we send it just to the user in question
     if ($test) {
         if (($result = $user->get($userId)) != false) {
             return [$result];
         } else {
             throw new NotifyException("Sender not found");
         }
         //REAL
         //	this is the real thing.
         //	If $groupIds is NULL/empty, this this is a Stjornvisi Event and then
         //	we just fetch all valid users in the system.
     } else {
         $users = $recipients == 'allir' ? empty($groupIds) ? $user->fetchAll(true) : $user->getUserMessageByGroup($groups) : $user->getUserMessageByEvent($eventId);
         if (empty($users)) {
             throw new NotifyException("No users found for event notification");
         } else {
             return $users;
         }
     }
 }
Example #12
0
 /**
  * Find out who is actually getting this
  * e-mail.
  *
  * @param int $sender
  * @param string $recipients
  * @param bool $test
  * @return array
  * @throws \Stjornvisi\Service\Exception
  */
 private function getUsers($sender, $recipients, $test)
 {
     $user = new User();
     $user->setDataSource($this->getDataSourceDriver())->setEventManager($this->getEventManager());
     $recipientAddresses = [];
     if ($test) {
         return [$user->get($sender)];
     } else {
         switch ($recipients) {
             case "formenn":
                 $recipientAddresses = $user->fetchAllManagers(true);
                 break;
             case "stjornendur":
                 $recipientAddresses = $user->fetchAllLeaders(true);
                 break;
             case "allir":
                 $user->fetchAll(true);
                 break;
             default:
                 $recipientAddresses = [];
         }
     }
     return $recipientAddresses;
 }