Example #1
0
 public function __invoke(Request $request, Response $response, PayloadInterface $payload = null) : Response
 {
     $file = $this->getTemplateFile();
     $html = $this->render($file, $payload->getOutput());
     $response->getBody()->write($html);
     return $response;
 }
Example #2
0
 /**
  * @param array $input
  * @return mixed
  */
 public function __invoke(array $input)
 {
     $user = $this->user->find($input['id']);
     if (!$user) {
         return $this->payload->setStatus(PayloadStatus::NOT_FOUND);
     }
     return $this->payload->setStatus(PayloadStatus::SUCCESS)->setOutput($this->user->find($input['id'])->shifts);
 }
Example #3
0
 /**
  * @param array $input
  * @return mixed
  */
 public function __invoke(array $input)
 {
     if (!isset($input['month'])) {
         return $this->payload->setStatus(PayloadStatus::ERROR)->setInput($input)->setOutput("Month cannot be blank e.g. '?month=2016-02'");
     }
     if (!\Datetime::createFromFormat('Y-m', $input['month'])) {
         return $this->payload->setStatus(PayloadStatus::ERROR)->setInput($input)->setOutput("Month is incorrect format e.g. '?month=2016-02'");
     }
     $month_start = Carbon::createFromFormat('Y-m', $input['month'])->startOfMonth();
     $month_end = Carbon::createFromFormat('Y-m', $input['month'])->endOfMonth();
     $shifts = $this->shift->where('employee_id', '=', $input['id'])->where('start_time', '>=', $month_start)->where('start_time', '<=', $month_end)->get();
     $hours = ['total_shifts' => $shifts->count(), 'total_hours' => 0];
     foreach ($shifts as $shift) {
         $hours['total_hours'] += $shift->start_time->diffInHours($shift->end_time);
     }
     return $this->payload->setStatus(PayloadStatus::SUCCESS)->setOutput($hours);
 }
Example #4
0
 /**
  * @param array $input
  * @return mixed
  */
 public function __invoke(array $input)
 {
     return $this->payload->setStatus(PayloadStatus::SUCCESS)->setOutput($this->user->all());
 }
 /**
  * Builds a Response for PayloadStatus::SUCCESS.
  */
 protected function success()
 {
     $this->response = $this->response->withStatus(200);
     $this->htmlBody($this->payload->getOutput());
 }
Example #6
0
 /**
  * @param array $input
  * @return mixed
  */
 public function __invoke(array $input)
 {
     $users = ['data' => [['id' => 1, 'name' => 'Bob Smith', 'role' => 'employee', 'email' => '*****@*****.**', 'phone' => '555-555-5555', 'created_at' => '2016-01-30', 'updated_at' => '2016-01-31'], ['id' => 2, 'name' => 'Jon Jones', 'role' => 'employee', 'email' => '*****@*****.**', 'phone' => '555-555-5555', 'created_at' => '2016-01-30', 'updated_at' => '2016-01-31'], ['id' => 3, 'name' => 'Sally Black', 'role' => 'employee', 'email' => '*****@*****.**', 'phone' => '555-555-5555', 'created_at' => '2016-01-30', 'updated_at' => '2016-01-31'], ['id' => 4, 'name' => 'Tony Stark', 'role' => 'manager', 'email' => '*****@*****.**', 'phone' => '555-555-5555', 'created_at' => '2016-01-30', 'updated_at' => '2016-01-31']]];
     return $this->payload->setStatus(PayloadStatus::SUCCESS)->setOutput($users);
 }
Example #7
0
 /**
  * @param array $input
  * @return mixed
  */
 public function __invoke(array $input)
 {
     return $this->payload->setStatus(PayloadStatus::UPDATED)->setOutput($input);
 }
 /**
  *
  * Builds a Response for PayloadStatus::UPDATED.
  *
  */
 protected function updated()
 {
     $this->response = $this->response->withStatus(303);
     $this->jsonBody($this->payload->getOutput());
 }
Example #9
0
 /**
  * Error
  *
  * @return mixed
  *
  * @access protected
  */
 protected function error()
 {
     $this->response = $this->response->withStatus(500);
     $this->render($this->errorViewScript, ['error' => $this->payload->getOutput()]);
 }
 /**
  * Returns the Responder
  * @return string
  */
 protected function htmlBody($data)
 {
     //
     // $slug = 'error';
     if (isset($data)) {
         // $slug = $this->request->getAttribute('page');
         $slugFromPayload = $this->payload->getOutput();
         //             $slug = $slugFromPayload['slug'];
         if (isset($slugFromPayload['slug'])) {
             $slug = $slugFromPayload['slug'];
         } else {
             $slug = 'index';
         }
         // $this->request = $this->request->withAttribute('page', 'error.php');
         //setup views
         //            $this->loadTemplate();
         //            $template = $this->twig->loadTemplate($view);
         //            $body = $template->render($data);
         //            $this->response = $this->response->withHeader('Content-Type', 'text/html');
         //            $this->response->getBody()->write($body);
     }
     // set thir probaly fro config file
     // Aura.view setup
     $view_factory = new ViewFactory();
     // a
     $view = $view_factory->newInstance();
     //
     // layout
     $layout_registry = $view->getLayoutRegistry();
     $layout_registry->set('layout', $this->layout);
     // views
     $view_registry = $view->getViewRegistry();
     $slug = $this->request->getAttribute('page');
     $partial_view = $this->staticpages . $slug . '.php';
     // check if the partial file exists, if not set status 404
     if (!file_exists($partial_view)) {
         $this->response = $this->response->withStatus(404);
         $partial_view = $this->staticpages . 'error' . '.php';
     }
     // set the registy
     $view_registry->set('_content', $partial_view);
     // demo data
     $dataset = ['data' => $data, 'partial' => 'partial', 'debug' => $this->payload->getStatus()];
     // assign data to the view
     $view->setData($dataset);
     /*
      * check for ajax request and set views accordingly
      */
     if ($this->is_pjax()) {
         // pjax request, set the view only
         // $this->renderView();
         $view->setView('_content');
     } else {
         // regular http request, set view and layout
         $view->setLayout('layout');
         $view->setView('_content');
     }
     $output = $view->__invoke();
     // retun response
     $this->response = $this->response->withHeader('Content-Type', 'text/html');
     $this->response->getBody()->write($output);
 }