/** * Handle domain logic for an action. * * @param array $input * @return PayloadInterface * @throws UserNotAuthorized */ public function __invoke(array $input) { //Check that the auth user matches the requested user //todo: determine if manager's should have access if ($input[AuthHandler::TOKEN_ATTRIBUTE]->getMetadata('id') != $input['id']) { throw new UserNotAuthorized(); } $employee = $this->userRepository->getOneByIdOrFail($input['id']); $shifts = $this->shiftRepository->getByEmployee($employee); //Loop over shifts getting employees that work at the same time for each shift foreach ($shifts as $shift) { $coworkers = $this->userRepository->getEmployeesWorkingBetween($shift->getStartTime(), $shift->getEndTime(), [$employee]); $shift->setCoworkers($coworkers); } $this->collection->setData($shifts)->setTransformer($this->shiftTransformer); return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->parseIncludes('coworkers')->createData($this->collection)->toArray()); }
/** * @param User $user * @param Request $request * @param UserRepository $userRepository * @return mixed */ public function listCoworkers(User $user, Request $request, UserRepository $userRepository) { //Check that the auth user matches the requested user //todo: determine if manager's should have access // if ($input[AuthHandler::TOKEN_ATTRIBUTE]->getMetadata('id') != $input['id']) { // throw new UserNotAuthorized; // } $shifts = $this->shiftRepository->getByEmployee($user); //Loop over shifts getting employees that work at the same time for each shift foreach ($shifts as $shift) { $coworkers = $userRepository->getEmployeesWorkingBetween($shift->getStartTime(), $shift->getEndTime(), [$user]); $shift->setCoworkers($coworkers); } return $this->respondWithCollection($shifts, $this->shiftTransformer, 'coworkers'); }