/**
  * Display the specified resource.
  * GET /models/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     try {
         $model = Model::findOrFail($id);
     } catch (ModelNotFoundException $e) {
         return $this->respondNotFound('Model does not exist');
     }
     return $this->respondOk(['model' => $this->modelTransformer->transform($model)]);
 }
 /**
  * Get's an item from the repository.
  *
  * @param  int   $model_id
  * @return model
  */
 public function getById($model_id)
 {
     return $this->model->findOrFail($model_id);
 }
Example #3
0
 public function getEmployeesCan($start, $end, $reseller_id)
 {
     if (!is_integer($start) || !is_integer($end) || !is_integer($reseller_id)) {
         throw new Exception('All arguments of this method must be of type integer');
     }
     if ($end < $start) {
         throw new Exception('End must be greater than start.');
     }
     $collection = [];
     $date = lib('time')->createFromTimestamp((int) $start);
     $midnight = (int) $date->startOfDay()->getTimestamp();
     $day = (string) $date->frenchDay();
     $row = Model::Schedule()->where(['day', '=', (string) $day])->where(['reseller_id', '=', (int) $reseller_id])->first(true);
     $reseller = Model::findOrFail((int) $reseller_id);
     if ($row) {
         $amStart = lib('agenda')->transform((string) $row->am_start, (int) $midnight);
         $amEnd = lib('agenda')->transform((string) $row->am_end, (int) $midnight);
         $pmStart = lib('agenda')->transform((string) $row->pm_start, (int) $midnight);
         $pmEnd = lib('agenda')->transform((string) $row->pm_end, (int) $midnight);
         $continue = true;
         if ($start > $pmEnd) {
             $continue = false;
         } elseif ($start > $amEnd && $start < $pmStart) {
             $continue = false;
         } elseif ($start < $amStart) {
             $continue = false;
         }
         if (true === $continue) {
             if ($end > $pmEnd) {
                 $continue = false;
             } elseif ($end > $amEnd && $end < $pmStart) {
                 $continue = false;
             }
         }
         if (true === $continue) {
             $employees = Model::Reselleremployee()->where(['reseller_id', '=', (int) $reseller_id])->cursor();
             foreach ($employees as $employee) {
                 $hasAppointment = lib('agenda')->hasAppointments((int) $start, (int) $end, (int) $employee['id']);
                 $hasVacations = lib('agenda')->hasVacations((int) $start, (int) $end, (int) $employee['id']);
                 if (false === $hasAppointment && false === $hasVacations) {
                     $collection[] = (int) $employee['id'];
                 }
             }
         }
     }
     return $collection;
 }
Example #4
0
 /**
  * @param       $id
  * @param array $data
  *
  * @return array
  */
 public function update($id, array $data)
 {
     $model = $this->model->findOrFail($id);
     return $model->update($data);
 }