Exemplo n.º 1
0
 private function isManager($serverParams)
 {
     $data = Utilities::getInstance()->extractData($serverParams);
     if (!isset($data->role) || $data->role != Constants::MANAGER) {
         return false;
     }
     return true;
 }
Exemplo n.º 2
0
 /**
  * @inheritDoc
  */
 public function __invoke(array $input)
 {
     $status = PayloadInterface::INVALID;
     $serverParams = $this->server->getServerParams();
     $hasAuthorization = self::hasAuthorization($serverParams, $this->payload, Constants::MANAGER_ACCESS);
     if (!$hasAuthorization) {
         return self::getErrorStatus($this->payload);
     }
     $employeeDetail = array(self::setDefaultMessage(Constants::EMPLOYEE_ID . Constants::ERROR_REQUIRED));
     if (!empty($input[Constants::EMPLOYEE_ID])) {
         $employeeId = $input[Constants::EMPLOYEE_ID];
         $employeeDetail = Utilities::getInstance()->findEmployeeById($employeeId);
         $status = PayloadInterface::OK;
     }
     return $this->payload->withStatus($status)->withOutput($employeeDetail);
 }
 /**
  * @inheritDoc
  */
 public function __invoke(array $input)
 {
     $status = PayloadInterface::INVALID;
     $serverParams = $this->server->getServerParams();
     $hasAuthorization = self::hasAuthorization($serverParams, $this->payload, Constants::MANAGER_ACCESS);
     if (!$hasAuthorization) {
         return self::getErrorStatus($this->payload);
     }
     $updateStatus = array(self::setDefaultMessage(Constants::SHIFT_ID . Constants::ANDSTR . Constants::EMPLOYEE_ID . Constants::ERROR_REQUIRED));
     if (!empty($input[Constants::SHIFT_ID]) && !empty($input[Constants::EMPLOYEE_ID])) {
         $shiftId = $input[Constants::SHIFT_ID];
         $employeeId = $input[Constants::EMPLOYEE_ID];
         $updateStatus = Utilities::getInstance()->updateEmployeeShift($shiftId, $employeeId);
         // dummy function: Results from DB implementation
         $status = PayloadInterface::OK;
     }
     return $this->payload->withStatus($status)->withOutput($updateStatus);
 }
Exemplo n.º 4
0
 /**
  * @inheritDoc
  */
 public function __invoke(array $input)
 {
     $status = PayloadInterface::INVALID;
     $serverParams = $this->server->getServerParams();
     $hasAuthorization = self::hasAuthorization($serverParams, $this->payload, Constants::MANAGER_ACCESS);
     if (!$hasAuthorization) {
         return self::getErrorStatus($this->payload);
     }
     $shiftRange = array(self::setDefaultMessage(Constants::FROM_DATE . " AND " . Constants::TO_DATE . Constants::ERROR_REQUIRED));
     if (!empty($input[Constants::FROM_DATE]) && !empty($input[Constants::TO_DATE])) {
         $startTime = $input[Constants::FROM_DATE];
         $endTime = $input[Constants::TO_DATE];
         $shiftRange = Utilities::getInstance()->findShiftsByRange($startTime, $endTime);
         // dummy function: Results from DB implementation
         $status = PayloadInterface::OK;
     }
     return $this->payload->withStatus($status)->withOutput($shiftRange);
 }
Exemplo n.º 5
0
 /**
  * @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);
 }
Exemplo n.º 6
0
 /**
  * @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);
 }
Exemplo n.º 7
0
 /**
  * @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);
 }
Exemplo n.º 8
0
 /**
  * @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);
 }
Exemplo n.º 9
0
 /**
  * @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);
 }
Exemplo n.º 10
0
 /**
  *
  * @param ServerInterface $server            
  * @param PayloadInterface $payload            
  */
 public function __construct(ServerRequestInterface $server, PayloadInterface $payload)
 {
     $this->payload = $payload;
     $this->token = Utilities::getInstance()->generateToken($server, Constants::SAMPLE_EMPLOYEE_ID, Constants::EMPLOYEE);
 }
Exemplo n.º 11
0
 public function extractData($serverParams)
 {
     $token = Utilities::getInstance()->parseToken($serverParams);
     if ($token->getMetadata(Constants::DATA) != Constants::EMPTYSTR) {
         return $token->getMetadata(Constants::DATA);
     }
     return array();
 }