コード例 #1
0
 /**
  * @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;
 }
コード例 #2
0
ファイル: Adapter.php プロジェクト: sctape/rest-scheduler-api
 /**
  * Validates a specified authentication token.
  *
  * - If the specified token is invalid, an InvalidException instance is
  *   thrown.
  * - If a valid token is present, a corresponding Token instance is
  *   returned.
  * - If for some reason the token cannot be validated, an AuthException
  *   instance is thrown.
  *
  * @param string $token
  * @return \Spark\Auth\Token
  * @throws \Spark\Auth\Exception\InvalidException if an invalid auth token
  *         is specified
  * @throws \Spark\Auth\Exception\AuthException if another error occurs
  *         during authentication
  */
 public function validateToken($token)
 {
     if ($user = $this->userRepository->getOneByToken($token)) {
         return new Token($token, ['id' => $user->getId(), 'entity' => $user]);
     }
     throw new AuthException();
 }
コード例 #3
0
 /**
  * @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());
 }
コード例 #4
0
 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;
 }
コード例 #5
0
 /**
  * Handle domain logic for an action.
  *
  * @param  array $input
  * @return PayloadInterface
  */
 public function __invoke(array $input)
 {
     //Check that user is authorized to view this resource
     $this->authorizeUser($input[AuthHandler::TOKEN_ATTRIBUTE]->getMetadata('entity'), 'view', 'users');
     //Validate input
     $inputValidator = v::key('id', v::intVal());
     $inputValidator->assert($input);
     //Get user from repository and transform into resource
     $user = $this->userRepository->getOneByIdOrFail($input['id']);
     $this->item->setData($user)->setTransformer($this->userTransformer);
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->createData($this->item)->toArray());
 }
コード例 #6
0
 /**
  * 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());
 }
コード例 #7
0
 /**
  * @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());
 }
コード例 #8
0
ファイル: CreateShift.php プロジェクト: sctape/scheduler
 /**
  * @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;
 }
コード例 #9
0
 /**
  * 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());
 }
コード例 #10
0
 /**
  * Handle domain logic for an action.
  *
  * @param  array $input
  * @return PayloadInterface
  */
 public function __invoke(array $input)
 {
     $user = $this->userRepository->getOneById($input['id']);
     $resource = new Item($user, $this->userTransformer);
     return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->createData($resource)->toArray());
 }
コード例 #11
0
ファイル: UsersController.php プロジェクト: sctape/scheduler
 /**
  * @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');
 }