示例#1
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;
         }
     }
 }