/** * @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); }
/** * @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; } } }