public function __invoke(array $input) { $payload = new Payload(); $payload->setStatus(Payload::FOUND); $shifts = new Collection($this->shifts->findAll(), new Shift()); $payload->setOutput(['shifts' => (new Manager())->createData($shifts)->toArray()]); return $payload; }
public function __invoke(array $input) { $output['shift'] = []; $payload = new Payload(); $payload->setStatus(Payload::FOUND); if (empty($input['token']) || !Authenticator::validateManager($input['token'])) { $output['error']['num'] = '101'; $output['error']['msg'] = 'Invalid Token'; $payload->setOutput($output); return $payload; } $required_fields = ['manager_id', 'employee_id', 'start_time', 'end_time']; foreach ($required_fields as $field) { if (empty($input[$field])) { $output['error']['num'] = '801'; $output['error']['msg'] = $field . ' must be specified'; $payload->setOutput($output); return $payload; } } $start_datetime = new \DateTime($input['start_time']); $end_datetime = new \DateTime($input['end_time']); $mapper = spot()->mapper('Spark\\Project\\Domain\\Entity\\Shift'); //first check to see if any of employees current shifts overlap with requested start/end $conflicting_shifts = $mapper->getConflictingShifts($input['employee_id'], $start_datetime->date, $end_datetime->date); //return overlapping shift if it exists with error code, else add the shift if ($conflicting_shifts && count($conflicting_shifts) > 0) { $output['error']['num'] = '201'; $output['error']['msg'] = 'Conflicting Shift'; $shift = $conflicting_shifts[0]; } else { $shift_to_add = ['manager_id' => $input['manager_id'], 'employee_id' => $input['employee_id'], 'start_time' => $start_datetime, 'end_time' => $end_datetime]; if (!empty($input['break'])) { $shift_to_add['break'] = $input['break']; } try { $shift = $mapper->create($shift_to_add); } catch (\Exception $e) { $output['error']['num'] = '999'; $output['error']['msg'] = $e->getMessage(); $payload->setOutput($output); return $payload; } } $output['shift'] = $shift->getAPIOutput(); if (empty($output['error']['num'])) { $output['error']['num'] = '000'; $output['error']['msg'] = 'SUCCESS'; } $payload->setOutput($output); return $payload; }
public function __invoke(array $input) { $input += ['user_id' => false] + Paginate::$defaultOptions; $payload = new Payload(); $payload->setStatus(Payload::FOUND); $output = []; $options = array_filter(['user_id' => $input['user_id'], 'limit' => $input['limit'], 'page' => $input['page']]); list($shifts, $paginate) = $this->mapper->getShifts($options); $output['meta']['paginate'] = $paginate->getMeta(); $output['shifts'] = $shifts; $payload->setOutput($output); return $payload; }
public function __invoke(array $input) { $output['coworkers_shifts'] = []; $payload = new Payload(); $payload->setStatus(Payload::FOUND); if (empty($input['token']) || !Authenticator::validateEmployee($input['token'])) { $output['error']['num'] = '101'; $output['error']['msg'] = 'Invalid Token'; $payload->setOutput($output); return $payload; } $mapper = spot()->mapper('Spark\\Project\\Domain\\Entity\\Shift'); $shift = $mapper->first(['id' => $input['shift_id']]); if (!$shift) { $output['error']['num'] = '811'; $output['error']['msg'] = 'Invalid shift_id'; $payload->setOutput($output); return $payload; } $coworkers_shifts = $mapper->getCoworkerShifts($shift->id); $return_attrs = ['user_id', 'name', 'start_time', 'end_time']; foreach ($coworkers_shifts as $shift) { $output['coworkers_shifts'][] = $shift->getAPIOutput($return_attrs); } if (empty($output['error']['num'])) { $output['error']['num'] = '000'; $output['error']['msg'] = 'SUCCESS'; } $payload->setOutput($output); return $payload; }
public function __invoke(array $input) { $output['weekly_hours'] = []; $payload = new Payload(); $payload->setStatus(Payload::FOUND); if (empty($input['token']) || !Authenticator::validateEmployee($input['token'])) { $output['error']['num'] = '101'; $output['error']['msg'] = 'Invalid Token'; $payload->setOutput($output); return $payload; } $user_mapper = spot()->mapper('Spark\\Project\\Domain\\Entity\\User'); $employee = $user_mapper->first(['id' => $input['employee_id']]); if (!$employee) { $output['error']['num'] = '811'; $output['error']['msg'] = 'Invalid employee_id'; $payload->setOutput($output); return $payload; } $weeks_back = 5; if (!empty($input['weeks_back']) && $input['weeks_back'] > 0) { $weeks_back = $input['weeks_back']; } $mapper = spot()->mapper('Spark\\Project\\Domain\\Entity\\Shift'); $output['weekly_hours'] = $mapper->getWeeklyHours($input['employee_id'], $weeks_back); $payload->setOutput($output); return $payload; }
public function __invoke(array $input) { $payload = new Payload(); if (!$this->isOkay($input)) { return $payload->setExtras(['template' => 'error'])->setStatus(Payload::NOT_AUTHENTICATED)->setInput($input); } if (!$this->isValidState($input)) { return $payload->setExtras(['template' => 'error'])->setStatus(Payload::NOT_VALID)->setInput($input)->setMessages(['error' => 'Invalid state detected']); } $provider = $input['provider']; $code = $input['code']; $token = $this->provider->getAccessToken('authorization_code', compact('code')); // Store the token to later actions $this->session->merge('tokens', [$provider => $token]); return $payload->setStatus(Payload::AUTHENTICATED)->setOutput(compact('provider')); }
public function __invoke(array $input) { $output['shifts'] = []; $payload = new Payload(); $payload->setStatus(Payload::FOUND); if (empty($input['token']) || !Authenticator::validateManager($input['token'])) { $output['error']['num'] = '101'; $output['error']['msg'] = 'Invalid Token'; $payload->setOutput($output); return $payload; } $required_fields = ['start_time', 'end_time']; foreach ($required_fields as $field) { if (empty($input[$field])) { $output['error']['num'] = '801'; $output['error']['msg'] = $field . ' must be specified'; $payload->setOutput($output); return $payload; } } $mapper = spot()->mapper('Spark\\Project\\Domain\\Entity\\Shift'); try { $shifts = $mapper->getShiftsBetween($input['start_time'], $input['end_time']); } catch (\Exception $e) { $output['error']['num'] = '999'; $output['error']['msg'] = $e->getMessage(); $payload->setOutput($output); return $payload; } $return_attrs = ['manager_id', 'break', 'start_time', 'end_time']; foreach ($shifts as $shift) { $output['shifts'][] = $shift->getAPIOutput($return_attrs); } if (empty($output['error']['num'])) { $output['error']['num'] = '000'; $output['error']['msg'] = 'SUCCESS'; } $payload->setOutput($output); return $payload; }
public function __invoke(array $input) { $payload = new Payload(); if (!$this->isAuthenticated($input)) { return $payload->setExtras(['template' => 'error'])->setStatus(Payload::NOT_VALID)->setInput($input)->setMessages(['token' => 'No token found for this provider']); } $provider = $input['provider']; $token = $this->session->get('tokens')[$provider]; try { $owner = $this->provider->getResourceOwner($token); } catch (IdentityProviderException $e) { if ($e->getCode() === 401) { $this->session->merge('tokens', [$provider => null]); return $payload->setExtras(['template' => 'error'])->setStatus(Payload::NOT_AUTHENTICATED)->setInput($input)->setMessages(['token' => 'Token for this provider is invalid, token removed']); } return $payload->setExtras(['template' => 'error'])->setStatus(Payload::ERROR)->setOutput($e->getResponseBody()); } // Collect output $id = $owner->getId(); $details = $owner->toArray(); return $payload->setExtras(['template' => 'user'])->setStatus(Payload::SUCCESS)->setOutput(compact('provider', 'id', 'details')); }
public function __invoke(array $input) { $output['shifts'] = []; $payload = new Payload(); $payload->setStatus(Payload::FOUND); if (empty($input['token']) || !Authenticator::validateEmployee($input['token'])) { $output['error']['num'] = '101'; $output['error']['msg'] = 'Invalid Token'; $payload->setOutput($output); return $payload; } if (empty($input['employee_id'])) { $output['error']['num'] = '801'; $output['error']['msg'] = 'employee_id must be specified'; $payload->setOutput($output); return $payload; } $user_mapper = spot()->mapper('Spark\\Project\\Domain\\Entity\\User'); $user = $user_mapper->first(['id' => $input['employee_id']]); if (!$user) { $output['error']['num'] = '811'; $output['error']['msg'] = 'Invalid employee_id'; $payload->setOutput($output); return $payload; } $mapper = spot()->mapper('Spark\\Project\\Domain\\Entity\\Shift'); $shifts = $mapper->where(['employee_id' => $input['employee_id']])->order(['start_time' => 'ASC']); $return_attrs = ['manager_id', 'break', 'start_time', 'end_time']; foreach ($shifts as $shift) { $output['shifts'][] = $shift->getAPIOutput($return_attrs); } if (empty($output['error']['num'])) { $output['error']['num'] = '000'; $output['error']['msg'] = 'SUCCESS'; } $payload->setOutput($output); return $payload; }
public function __invoke(array $input) { $output['manager'] = []; $payload = new Payload(); $payload->setStatus(Payload::FOUND); if (empty($input['token']) || !Authenticator::validateEmployee($input['token'])) { $output['error']['num'] = '101'; $output['error']['msg'] = 'Invalid Token'; $payload->setOutput($output); return $payload; } if (empty($input['manager_id'])) { $output['error']['num'] = '801'; $output['error']['msg'] = 'manager_id must be specified'; $payload->setOutput($output); return $payload; } $user_mapper = spot()->mapper('Spark\\Project\\Domain\\Entity\\User'); $user = $user_mapper->where(['id' => $input['manager_id']])->first(); if (!$user) { $output['error']['num'] = '811'; $output['error']['msg'] = 'Invalid manager_id'; $payload->setOutput($output); return $payload; } $return_attrs = ['id', 'name', 'email', 'phone']; foreach ($return_attrs as $attr) { $manager[$attr] = $user->{$attr}; } $output['manager'] = $manager; if (empty($output['error']['num'])) { $output['error']['num'] = '000'; $output['error']['msg'] = 'SUCCESS'; } $payload->setOutput($output); return $payload; }
public function __invoke(array $input) { $output['shift'] = []; $payload = new Payload(); $payload->setStatus(Payload::FOUND); if (empty($input['token']) || !Authenticator::validateManager($input['token'])) { $output['error']['num'] = '101'; $output['error']['msg'] = 'Invalid Token'; $payload->setOutput($output); return $payload; } $required_fields = ['shift_id', 'employee_id']; foreach ($required_fields as $field) { if (empty($input[$field])) { $output['error']['num'] = '801'; $output['error']['msg'] = $field . ' must be specified'; $payload->setOutput($output); return $payload; } } $mapper = spot()->mapper('Spark\\Project\\Domain\\Entity\\Shift'); $shift = $mapper->first(['id' => $input['shift_id']]); if (!$shift) { $output['error']['num'] = '811'; $output['error']['msg'] = 'Invalid shift_id'; $payload->setOutput($output); return $payload; } $user_mapper = spot()->mapper('Spark\\Project\\Domain\\Entity\\User'); $user = $user_mapper->first(['id' => $input['employee_id']]); if (!$user) { $output['error']['num'] = '812'; $output['error']['msg'] = 'Invalid employee_id'; $payload->setOutput($output); return $payload; } try { $shift->employee_id = $input['employee_id']; $mapper->update($shift); } catch (\Exception $e) { $output['error']['num'] = '999'; $output['error']['msg'] = $e->getMessage(); $payload->setOutput($output); return $payload; } $output['shift'] = $shift->getAPIOutput(); if (empty($output['error']['num'])) { $output['error']['num'] = '000'; $output['error']['msg'] = 'SUCCESS'; } $payload->setOutput($output); return $payload; }
/** * @param array $input * @return Payload */ public function __invoke(array $input) { $payload = new Payload(); return $payload->setStatus(PayloadStatus::SUCCESS)->setOutput(['message' => 'input is a : ' . $input['page']]); }
public function _invoke($input) { $payload = new Payload(); return $payload->setStatus(PayloadStatus::SUCCESS)->setOutput(['phrase' => 'Hello ' . $input['name']]); // ->defaults(['name' => 'world']); }