Exemplo n.º 1
0
 /**
  * Returns a new grid instance of all available events.
  *
  * @return \Cartalyst\DataGrid\DataGrid
  */
 public function grid()
 {
     $columns = ['id', 'user_id', 'api_id', 'location_id', 'created_at'];
     $settings = ['sort' => 'created_at', 'direction' => 'desc', 'threshold' => 10, 'throttle' => 11];
     $transformer = function (Event $event) {
         $apiObject = $this->event->findApiObject($event->api_id);
         if ($apiObject) {
             $startDate = new \DateTime($apiObject->start);
             $endDate = new \DateTime($apiObject->end);
             // If the event is all day, we'll format the dates differently.
             if ($apiObject->all_day) {
                 $start = $startDate->format('Y-m-d');
                 $end = $endDate->format('Y-m-d');
             } else {
                 $start = $startDate->format('Y-m-d h:i:s');
                 $end = $endDate->format('Y-m-d h:i:s');
             }
             return ['title' => $apiObject->title, 'location' => $event->location ? $event->location->trail : null, 'start' => $start, 'end' => $end, 'view_url' => route('maintenance.events.show', [$event->id])];
         }
         return null;
     };
     return $this->event->grid($columns, $settings, $transformer);
 }