Example #1
0
 /**
  * Handle domain logic for an action.
  *
  * @param  array $input
  * @return PayloadInterface
  */
 public function __invoke(array $input)
 {
     //Authorize user to be able to view shifts
     $this->authorizeUser($input[AuthHandler::TOKEN_ATTRIBUTE]->getMetaData('entity'), 'view', 'shifts');
     //Validate input
     $inputValidator = v::key('startDateTime', v::stringType())->key('endDateTime', v::stringType());
     $inputValidator->assert($input);
     //Retrieve shifts between in time period
     $shifts = $this->shiftRepository->getShiftsBetween(Carbon::parse($input['startDateTime']), Carbon::parse($input['endDateTime']));
     $this->collection->setData($shifts)->setTransformer($this->shiftTransformer);
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->parseIncludes(['manager', 'employee'])->createData($this->collection)->toArray());
 }
 /**
  * Handle domain logic for an action.
  *
  * @param  array $input
  * @return PayloadInterface
  * @throws UserNotAuthorized
  */
 public function __invoke(array $input)
 {
     //Make sure requested user matches auth user
     //todo: figure out if managers can access all employees' hours
     if ($input['id'] != $input[AuthHandler::TOKEN_ATTRIBUTE]->getMetaData('id')) {
         throw new UserNotAuthorized();
     }
     //Get hours and transform to more readable collection
     $employee = $this->userRepository->getOneByIdOrFail($input['id']);
     $hours = $this->shiftRepository->getHoursCountGroupedByWeekFor($employee);
     $this->collection->setData($hours)->setTransformer($this->hoursTransformer);
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->createData($this->collection)->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());
 }