/** * @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; } } }
/** * Get all users when there is no * storage connection * @expectedException Exception */ public function testFetchAllException() { $service = new User(); $service->setDataSource(new PDOMock()); $service->fetchAll(); }
/** * 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; }