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'); }
/** * @return array * @throws \Stjornvisi\Service\Exception */ private function getUsers() { $userService = new User(); $userService->setDataSource($this->getDataSourceDriver())->setEventManager($this->getEventManager()); return $userService->getUserMessage(); }
/** * @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"); } }
/** * 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; }
/** * 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'); }
public function testTrue() { $service = new User(); $service->setDataSource(self::$pdo); $service->attendance(1); }
/** * @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"); } }
/** * 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); }
/** * @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; } } }
/** * 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; }