private function getManager($shift_id) { $shift = Shift::load($shift_id); $manager_id = $shift->manager_id; $manager = User::load($manager_id); return [$manager->jsonSerialize()]; }
private function getEmployees() { $dbc = DatabaseConnection::getConnection(); $statement = $dbc->prepare("SELECT * FROM users" . " WHERE role='employee'" . " ORDER BY name"); $statement->execute(); $employees = []; while ($row = $statement->fetch(PDO::FETCH_ASSOC)) { $employees[] = [User::load($row['id'])->jsonSerialize()]; } return $employees; }
/** * @inheritDoc */ public function validateToken($token) { session_start(); session_regenerate_id(true); try { $user = User::load($token); return new Token($token, ['id' => $user->id, 'role' => $user->role]); } catch (Exception $e) { throw new AuthException($e); } throw new InvalidException(); }
/** * @inheritDoc */ public function __invoke(array $input) { $token = $input['spark/auth:token']; $role = $token->getMetadata('role'); $isEmployee = strcmp($role, 'employee') === 0; if ($isEmployee) { throw new AuthException('This action is not available to employees.'); } else { $employee = User::load($input['employee'])->jsonSerialize(); } return $this->payload->withStatus(PayloadInterface::OK)->withOutput(["employee", $employee]); }
private function getCoworkers($shift_id) { $shift = Shift::load($shift_id); $start_time = $shift->start_time; $end_time = $shift->end_time; $dbc = DatabaseConnection::getConnection(); $statement = $dbc->prepare("SELECT * FROM shifts" . " WHERE (start_time >= :start_time AND start_time < :end_time)" . " OR (end_time >= :start_time AND end_time < :end_time)" . " ORDER BY start_time"); $statement->execute(['start_time' => $start_time, 'end_time' => $end_time]); $coworker_ids = []; while ($row = $statement->fetch(PDO::FETCH_ASSOC)) { if (strcmp($row['employee_id'], $shift->employee_id) !== 0 && strcmp($row['employee_id'], '') !== 0) { $coworker_ids[] = $row['employee_id']; } } $coworkers = []; foreach ($coworker_ids as $coworker_id) { $coworkers[] = User::load($coworker_id)->name; } return $coworkers; }