private function completeLogin($code) { $token = $this->rdio->getAccessToken('authorization_code', compact('code')); $this->session->del('rdio.state'); $this->session->set('rdio.token', $token); return $this->payload->withStatus(Payload::OK)->withMessages(['redirect' => '/login']); }
/** * @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()); }
/** * @inheritDoc */ public function __invoke(array $input) { $start = urldecode($input['startTime']); $end = urldecode($input['endTime']); $shifts = $this->shiftMapper->getShiftsBetween($start, $end); $output = []; if ($shifts) { foreach ($shifts as $shift) { $employee = $this->userMapper->find($shift->getEmployeeId()); $manager = $this->userMapper->find($shift->getManagerId()); if (!$employee) { $employee = '[No employee scheduled]'; } else { $employee = $employee->getName(); } if (!$manager) { $manager = '[No manager assigned]'; } else { $manager = $manager->getName(); } $output[] = ['employee' => $employee, 'manager' => $manager, 'start_time' => $shift->getStartTime(), 'end_time' => $shift->getEndTime()]; } } return $this->payload->withStatus(PayloadInterface::OK)->withOutput([$output]); }
/** * @inheritDoc */ public function __invoke(array $input) { $date = urldecode($input['date']); $shifts = $this->shiftMapper->getWeeklySummary($this->userId, $date); $output = []; $hoursWorked = 0; $minutesWorked = 0; // todo: not error if they haven't worked foreach ($shifts as $shift) { $output['shifts'][] = ['id' => $shift->getid(), 'start_time' => $shift->getStartTime(), 'end_time' => $shift->getEndTime()]; // I'm just going to care about hours and minutes // your seconds mean nothing to me. Maybe later. $start = new \DateTime($shift->getStartTime()); $end = new \DateTime($shift->getEndTime()); $interval = $start->diff($end); $hoursWorked += $interval->h; $minutesWorked += $interval->i; } if ($minutesWorked) { $output['hours_worked'] = $hoursWorked + $minutesWorked / 60; } else { $output['hours_worked'] = $hoursWorked; } return $this->payload->withStatus(PayloadInterface::OK)->withOutput([$output]); }
/** * @inheritDoc */ public function __invoke(array $input) { // this method assumes that when you're modifying a shift, // all of the data is being reposted. if (empty($input['shift_id'])) { $shift = $this->shiftMapper->create(); } else { $shift = $this->shiftMapper->find($input['shift_id']); } // if manager id has been provided, let's use it. if (!empty($input['manager_id'])) { $shift->setManagerId($input['manager_id']); } else { $shift->setManagerId($this->userId); } if (!empty($input['employee_id'])) { $shift->setEmployeeId($input['employee_id']); } $shift->setBreak($input['break']); $shift->setStartTime($input['start_time']); $shift->setEndTime($input['end_time']); if ($this->shiftMapper->save($shift)) { $status = PayloadInterface::OK; $output = ['status' => 'Successfully saved']; } else { $status = PayloadInterface::ERROR; $output = ['status' => 'Failed to save']; } return $this->payload->withStatus($status)->withOutput([$output]); }
/** * @inheritDoc */ public function __invoke(array $input) { if (empty($input['name'])) { return (new Payload())->withStatus(Payload::ERROR)->withOutput(['template' => 'partials::404', 'name' => $name]); // ->withOutput([ // 'error' => 'Missing name argument', // ]); } $name = 'world'; if (!empty($input['name'])) { $name = $input['name']; } if (!empty($input['name'])) { $name = $input['name']; } // if ($this->payload->engine->exists('articles::beginners_guide')) { // It exists! // } // Check static page or partial exists // if ($this->engine->exists('static/' . $name)) { // } else { // header("HTTP/1.0 404 Not Found"); // echo "PHP continues.\n"; // echo "Not after a die, however.\n"; // die(); // } return $this->payload->withStatus(PayloadInterface::OK)->withOutput(['template' => 'templates::staticpage', 'name' => $name]); }
/** * @inheritDoc */ public function __invoke(array $input) { $output = []; $shift = $this->shiftMapper->find($input['shiftId']); // I was going to add a check here to make sure the employee // requesting the shift was the employee on the shift but wasn't // sure if that was supposed to be allowed or not. if (!$shift) { return $this->payload->withStatus(PayloadInterface::ERROR)->withOutput(['error' => 'Requested shift does not exist']); } $manager = $this->userMapper->find($shift->getManagerId()); $output['manager_info'] = ['id' => $manager->getId(), 'name' => $manager->getName(), 'phone' => $manager->getPhone(), 'email' => $manager->getEmail()]; $overlappingShifts = $this->shiftMapper->getShiftsBetween($shift->getStartTime(), $shift->getEndTime()); if ($overlappingShifts) { foreach ($overlappingShifts as $overlappingShift) { if ($overlappingShift->getId() != $shift->getId()) { $coworker = $this->userMapper->find($overlappingShift->getEmployeeId()); if (!$coworker) { $coworker = '[No employee scheduled]'; } else { $coworker = $coworker->getName(); } $output['overlapping_shifts'][] = ['name' => $coworker, 'start_time' => $overlappingShift->getStartTime(), 'end_time' => $overlappingShift->getEndTime()]; } } } return $this->payload->withStatus(PayloadInterface::OK)->withOutput([$output]); }
/** * @inheritDoc */ public function __invoke(array $input) { $name = 'world'; if (!empty($input['name'])) { $name = $input['name']; } return $this->payload->withStatus(PayloadInterface::OK)->withOutput(['hello' => $name]); }
/** * @inheritDoc */ public function __invoke(array $input) { $employee = $this->userMapper->find($input['employeeId']); $output = []; if ($employee) { $output = ['id' => $employee->getId(), 'name' => $employee->getName(), 'phone' => $employee->getPhone(), 'email' => $employee->getEmail()]; } return $this->payload->withStatus(PayloadInterface::OK)->withOutput([$output]); }
public function __invoke(array $input) { if (!empty($input['username']) && !empty($input['password'])) { if (!$this->isValidEmail($input['username'])) { return $this->invalidLogin($input['username']); } return $this->completeLogin($input['username'], $input['password']); } return $this->payload->withStatus(Payload::OK)->withOutput(['template' => 'login/tidal']); }
/** * @inheritDoc */ public function __invoke(array $input) { $shifts = $this->shiftMapper->getFutureShiftsByEmployee($this->userId); $output = []; if (is_array($shifts) && !empty($shifts)) { foreach ($shifts as $shift) { $output[] = ['id' => $shift->getId(), 'start_time' => $shift->getStartTime(), 'end_time' => $shift->getEndTime()]; } } return $this->payload->withStatus(PayloadInterface::OK)->withOutput([$output]); }
/** * Handle domain logic for an action. * * @param array $input * @return PayloadInterface */ public function __invoke(array $input) { //Check that user has permission to edit this resource $this->authorizeUser($input[AuthHandler::TOKEN_ATTRIBUTE]->getMetaData('entity'), 'edit', 'shifts'); //Validate input $inputValidator = v::key('id', v::intVal())->key('employee_id', v::intVal()); $inputValidator->assert($input); //Execute command to update employee on shift $shift = $this->commandBus->handle(new AssignShiftCommand($input['id'], $input['employee_id'])); $shiftItem = new Item($shift, new ShiftTransformer()); return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->parseIncludes(['manager', 'employee'])->createData($shiftItem)->toArray()); }
/** * 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()); }
/** * 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 */ public function __invoke(array $input) { //Check that user is authorized to edit this resource $this->authorizeUser($input[AuthHandler::TOKEN_ATTRIBUTE]->getMetadata('entity'), 'edit', 'shifts'); //Validate input $inputValidator = v::key('break', v::floatVal())->key('start_time', v::stringType())->key('end_time', v::stringType())->key('id', v::intVal()); $inputValidator->assert($input); //Update shift data $shift = $this->commandBus->handle(new UpdateShiftCommand($input['id'], $input['break'], $input['start_time'], $input['end_time'])); $shiftItem = new Item($shift, new ShiftTransformer()); return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->createData($shiftItem)->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()); }
/** * Get the response status from the payload. * * @param PayloadInterface $payload * @return integer */ public function status(PayloadInterface $payload) { $status = $payload->getStatus(); if ($status >= PayloadInterface::OK && $status < PayloadInterface::ERROR) { return 200; } if ($status >= PayloadInterface::ERROR && $status < PayloadInterface::INVALID) { return 500; } if ($status >= PayloadInterface::INVALID && $status < PayloadInterface::UNKNOWN) { return 400; } return 520; }
/** * 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()); }
/** * Handle domain logic for an action. * * @param array $input * @return PayloadInterface */ public function __invoke(array $input) { //Ensure that the use has permission to create shifts $user = $input[AuthHandler::TOKEN_ATTRIBUTE]->getMetadata('entity'); $this->authorizeUser($user, 'create', 'shifts'); //If no manager_id is specified in request, default to user creating shift if (!array_key_exists('manager_id', $input)) { $input['manager_id'] = $user->getId(); } //Validate input $inputValidator = v::key('break', v::floatVal())->key('start_time', v::date())->key('end_time', v::date()->min($input['start_time']))->key('manager_id', v::intVal()); $inputValidator->assert($input); //Execute command to create shift $shift = $this->commandBus->handle(new CreateShift($input['manager_id'], $input['employee_id'], $input['break'], $input['start_time'], $input['end_time'])); $this->item->setData($shift)->setTransformer($this->shiftTransformer); return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->parseIncludes(['manager', 'employee'])->createData($this->item)->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()); }
/** * @inheritDoc */ public function __invoke(array $input) { $serverParams = $this->server->getServerParams(); if (!self::hasAuthorization($serverParams, $this->payload)) { return self::getErrorStatus($this->payload); } $weekDate = date(Constants::DEFAULT_DATEFORMAT); if (isset($input[Constants::WEEK_DATE])) { $weekDate = $input[Constants::WEEK_DATE]; } $token = Utilities::getInstance()->parseToken($serverParams); $data = Utilities::getInstance()->extractData($token); $employeeId = $data->user_id; $hours = array(); if (!empty($employeeId)) { $hours = Utilities::getInstance()->findWeekHours($employeeId, $weekDate); // dummy function: Results from DB implementation } return $this->payload->withStatus(PayloadInterface::OK)->withOutput($hours); }
/** * @inheritDoc */ public function __invoke(array $input) { $status = PayloadInterface::INVALID; $serverParams = $this->server->getServerParams(); $shiftId = 0; if (isset($input[Constants::SHIFT_ID])) { $shiftId = $input[Constants::SHIFT_ID]; } if (!self::hasAuthorization($serverParams, $this->payload)) { return self::getErrorStatus($this->payload); } $data = Utilities::getInstance()->extractData($serverParams); $employeeId = $data->user_id; $buddies = array(self::setDefaultMessage(Constants::EMPLOYEE_ID . Constants::ERROR_REQUIRED)); if (!empty($employeeId)) { $buddies = Utilities::getInstance()->findShiftBuddy($employeeId, $shiftId); // dummy function: Results from DB implementation $status = PayloadInterface::OK; } return $this->payload->withStatus($status)->withOutput($buddies); }
/** * @inheritDoc */ public function __invoke(array $input) { $status = PayloadInterface::INVALID; $serverParams = $this->server->getServerParams(); if (!self::hasAuthorization($serverParams, $this->payload)) { return self::getErrorStatus($this->payload); } $data = Utilities::getInstance()->extractData($serverParams); $employeeId = $data->user_id; //defaults to own id if (isset($input[Constants::EMPLOYEE_ID]) && self::hasAuthorization($serverParams, $this->payload, Constants::MANAGER_ACCESS)) { $employeeId = $input[Constants::EMPLOYEE_ID]; //only Managers can query employee IDs } $shifts = array(self::setDefaultMessage(Constants::EMPLOYEE_ID . Constants::ERROR_REQUIRED)); if (!empty($employeeId)) { $shifts = Utilities::getInstance()->findShiftsByEmployeeId($employeeId); //Results from DB implementation, sample provided here with random generated data $status = PayloadInterface::OK; } return $this->payload->withStatus($status)->withOutput($shifts); }
/** * @inheritDoc */ public function __invoke(array $input) { $status = PayloadInterface::INVALID; $serverParams = $this->server->getServerParams(); if (!self::hasAuthorization($serverParams, $this->payload)) { return self::getErrorStatus($this->payload); } $token = Utilities::getInstance()->parseToken($serverParams); $data = Utilities::getInstance()->extractData($token); $employeeId = $data->user_id; $shiftId = 0; if (isset($input[Constants::SHIFT_ID])) { $shiftId = $input[Constants::SHIFT_ID]; } $shifts = array(self::setDefaultMessage(Constants::ERROR_SHIFTID_REQUIRED)); if (!empty($shiftId)) { $shifts = Utilities::getInstance()->findEmployeeManager($shiftId); // Results from DB implementation, sample provided here with random generated data $status = PayloadInterface::OK; } return $this->payload->withStatus($status)->withOutput($shifts); }
/** * @inheritDoc */ public function __invoke(array $input) { $status = PayloadInterface::INVALID; $serverParams = $this->server->getServerParams(); if (!self::hasAuthorization($serverParams, $this->payload, Constants::MANAGER_ACCESS)) { return self::getErrorStatus($this->payload); } $data = Utilities::getInstance()->extractData($serverParams); $managerId = $data->user_id; $insertStatus = array(self::setDefaultMessage(Constants::EMPLOYEE_ID . Constants::ANDSTR . Constants::BREAKS . Constants::ANDSTR . Constants::FROM_DATE . Constants::ANDSTR . Constants::TO_DATE . Constants::ANDSTR)); if (self::hasRequiredParams($input)) { $employeeId = $input[Constants::EMPLOYEE_ID]; $breaks = $input[Constants::BREAKS]; $startTime = $input[Constants::FROM_DATE]; $endTime = $input[Constants::TO_DATE]; $now = date(Constants::DEFAULT_DATEFORMAT); $newShift = new Shift([Constants::MANAGER_ID => $managerId, Constants::EMPLOYEE_ID => $employeeId, Constants::BREAKS => $breaks, Constants::START_TIME => $startTime, Constants::END_TIME => $endTime, Constants::CREATED_AT => $now, Constants::UPDATED_AT => $now]); $insertStatus = Utilities::getInstance()->addShift($newShift); // dummy function: Results from DB implementation $status = PayloadInterface::OK; } return $this->payload->withStatus($status)->withOutput($insertStatus); }
public function __invoke(array $input) { $types = ['collection' => 'importRdioCollection', 'favorites' => 'importRdioFavorites']; if (!empty($input['types'])) { $wants = $input['types']; if (!is_array($wants)) { $wants = preg_split('/,\\s*/', $wants); } $types = array_intersect_key($types, array_flip($wants)); } $missing = 0; $imported = 0; $failed = []; foreach ($types as $type => $method) { list($i, $m) = call_user_func([$this, $method]); $failed[$type] = $m; $imported += $i; $missing += count($m); } $output = compact('imported', 'missing', 'failed'); return $this->payload->withStatus(Payload::OK)->withOutput($output + ['template' => 'imported']); }
/** * 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()); }
/** * Determine if the payload has usable output * * @param PayloadInterface $payload * * @return boolean */ protected function hasOutput(PayloadInterface $payload) { return (bool) $payload->getOutput(); }
public function __invoke(array $input) { $this->session->del('rdio.token'); $this->session->del('tidal.session'); return $this->payload->withStatus(Payload::OK)->withMessages(['redirect' => 'login']); }
public function __invoke(array $input) { return $this->payload->withStatus(Payload::OK)->withOutput(['rdio_ready' => $this->session->has('rdio.token'), 'tidal_ready' => $this->session->has('tidal.session'), 'template' => 'login']); }