/** * @param AssignShift $command * @return Shift */ public function handle(AssignShift $command) { $shift = $this->shiftRepository->getOneByIdOrFail($command->shift_id); $employee = $this->userRepository->getOneByIdOrFail($command->employee_id); $shift->setEmployee($employee); return $shift; }
/** * @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 UpdateShift $command * @return Shift */ public function handle(UpdateShift $command) { $shift = $this->shiftRepository->getOneById($command->shift_id); $shift->setBreak($command->break); $shift->setStartTime($command->start_time); $shift->setEndTime($command->end_time); return $shift; }
/** * @param ShiftRepository $shiftRepository * @return Shift */ public function handle(ShiftRepository $shiftRepository) { $this->shift->setBreak($this->break); $this->shift->setStartTime($this->start_time); $this->shift->setEndTime($this->end_time); $shiftRepository->update($this->shift); return $this->shift; }
public function handle(CreateShift $command) { $this->shift->setBreak($command->break); $this->shift->setEmployee($this->userRepository->getOneById($command->employee_id)); $this->shift->setManager($this->userRepository->getOneById($command->manager_id)); $this->shift->setStartTime($command->start_time); $this->shift->setEndTime($command->end_time); $this->shiftRepository->store($this->shift); return $this->shift; }
/** * 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()); }
/** * @param UserRepository $userRepository * @param ShiftRepository $shiftRepository * @param Shift $shift * @param Guard $auth * @return Shift */ public function handle(UserRepository $userRepository, ShiftRepository $shiftRepository, Shift $shift, Guard $auth) { $shift->setBreak($this->break); $shift->setStartTime($this->start_time); $shift->setEndTime($this->end_time); if ($this->employee_id) { $shift->setEmployee($userRepository->getOneById($this->employee_id)); } if ($this->manager_id) { $shift->setManager($userRepository->getOneById($this->manager_id)); } else { $shift->setManager($auth->getUser()); } $shiftRepository->store($shift); $shiftRepository->update($shift); return $shift; }
/** * 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'); }
/** * @param ListShiftsRequest $request * @return mixed */ public function index(ListShiftsRequest $request) { //Retrieve shifts between in time period $shifts = $this->shiftRepository->getShiftsBetween(Carbon::parse($request->get('startDateTime')), Carbon::parse($request->get('endDateTime'))); return $this->respondWithCollection($shifts, $this->shiftTransformer, ['manager', 'employee']); }
/** * @param ShiftRepository $shiftRepository * @return Shift */ public function handle(ShiftRepository $shiftRepository) { $this->shift->setEmployee($this->user); $shiftRepository->update($this->shift); return $this->shift; }