/** * @param array $input * @return PayloadInterface */ public function __invoke(array $input) { $employee = $this->userRepository->getOneById($input['id']); $shifts = $this->shiftRepository->getByEmployee($employee); $shiftsCollection = new Collection($shifts, new ShiftTransformer()); return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->createData($shiftsCollection)->toArray()); }
/** * @param array $input * @return PayloadInterface * @throws UserNotAuthorized */ public function __invoke(array $input) { //Don't allow employees to view other employee's shifts //todo: figure out if managers can access all employees' shifts if ($input['id'] != $input[AuthHandler::TOKEN_ATTRIBUTE]->getMetaData('id')) { throw new UserNotAuthorized(); } //Validate input $inputValidator = v::key('id', v::intVal()); $inputValidator->assert($input); //Get shifts and transform $employee = $this->userRepository->getOneByIdOrFail($input['id']); $shifts = $this->shiftRepository->getByEmployee($employee); $this->collection->setData($shifts)->setTransformer($this->shiftTransformer); $include = array_key_exists('include', $input) ? $input['include'] : ''; return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->parseIncludes($include)->createData($this->collection)->toArray()); }
/** * 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'); }