示例#1
0
 /**
  * Process datatables ajax request.
  *
  * @return \Illuminate\Http\JsonResponse
  */
 public function search()
 {
     //$tickets = Ticket::all();
     $tickets = Ticket::select("tickets.*", DB::raw("count(distinct events.id) as event_count"), DB::raw("count(distinct notes.id) as notes_count"))->leftJoin('events', 'events.ticket_id', '=', 'tickets.id')->leftJoin('notes', function ($join) {
         // We need a LEFT JOIN .. ON .. AND ..).
         // This doesn't exist within Illuminate's JoinClause class
         // So we use some nesting foo here
         $join->on('notes.ticket_id', '=', 'tickets.id')->nest(function ($join) {
             $join->on('notes.viewed', '=', DB::raw("'false'"));
         });
     })->groupBy('tickets.id');
     return Datatables::of($tickets)->addColumn('actions', function ($ticket) {
         $actions = ' <a href="tickets/' . $ticket->id . '" class="btn btn-xs btn-primary"><span class="glyphicon glyphicon-eye-open"></span> ' . trans('misc.button.show') . '</a> ';
         return $actions;
     })->editColumn('type_id', function ($ticket) {
         return trans('types.type.' . $ticket->type_id . '.name');
     })->editColumn('class_id', function ($ticket) {
         return trans('classifications.' . $ticket->class_id . '.name');
     })->editColumn('status_id', function ($ticket) {
         return trans('types.status.' . $ticket->status_id . '.name');
     })->make(true);
 }
 /**
  * Export tickets to CSV format.
  *
  * @param string $format
  *
  * @return \Illuminate\Http\Response
  */
 public function export($format)
 {
     // TODO #AIO-?? ExportProvider - (mark) Move this into an ExportProvider or something?
     // only export all tickets when we are in the systemaccount
     $auth_account = $this->auth_user->account;
     if ($auth_account->isSystemAccount()) {
         $tickets = Ticket::all();
     } else {
         $tickets = Ticket::select('tickets.*')->where('ip_contact_account_id', $auth_account->id)->orWhere('domain_contact_account_id', $auth_account);
     }
     if ($format === 'csv') {
         $columns = ['id' => 'Ticket ID', 'ip' => 'IP address', 'class_id' => 'Classification', 'type_id' => 'Type', 'first_seen' => 'First seen', 'last_seen' => 'Last seen', 'event_count' => 'Events', 'status_id' => 'Ticket Status'];
         $output = '"' . implode('", "', $columns) . '"' . PHP_EOL;
         foreach ($tickets as $ticket) {
             $row = [$ticket->id, $ticket->ip, trans("classifications.{$ticket->class_id}.name"), trans("types.type.{$ticket->type_id}.name"), $ticket->firstEvent[0]->seen, $ticket->lastEvent[0]->seen, $ticket->events->count(), trans("types.status.abusedesk.{$ticket->status_id}.name")];
             $output .= '"' . implode('", "', $row) . '"' . PHP_EOL;
         }
         return response(substr($output, 0, -1), 200)->header('Content-Type', 'text/csv')->header('Content-Disposition', 'attachment; filename="Tickets.csv"');
     }
     return Redirect::route('admin.contacts.index')->with('message', "The requested format {$format} is not available for exports");
 }