Ejemplo n.º 1
0
 public function actionBulk(Request $request)
 {
     $input = $request->all();
     $action = $input['submit'];
     $ids = $input['table_records'];
     if ($action == 'update') {
         $data = [];
         if (!empty($input['ticket_category_id'])) {
             $data['ticket_category_id'] = $input['ticket_category_id'];
         }
         if (!empty($input['department_id'])) {
             $data['department_id'] = $input['department_id'];
         }
         if (!empty($input['open'])) {
             $data['open'] = 0;
         }
         if (!empty($input['priority'])) {
             $data['priority'] = $input['priority'];
         }
         if (!empty($data)) {
             foreach ($ids as $id) {
                 $descriptions = [];
                 $ticket = Ticket::with('department')->find($id);
                 if (isset($data['department_id']) and $data['department_id'] == $ticket->department_id) {
                     unset($data['department_id']);
                 }
                 if (isset($data['ticket_category_id']) and $data['ticket_category_id'] == $ticket->ticket_category_id) {
                     unset($data['ticket_category_id']);
                 }
                 if (isset($data['open']) and $data['open'] == $ticket->open) {
                     unset($data['open']);
                 }
                 if (isset($data['department_id']) && !empty($data['department_id'])) {
                     $descriptions[] = trans('tickets::tickets.histories.department_changed', ['user' => user()->name, 'old' => $ticket->department->name, 'new' => TicketDepartment::find($data['department_id'])->name]);
                 }
                 if (isset($data['open'])) {
                     $descriptions[] = trans('tickets::tickets.histories.ticket_closed', ['user' => user()->name]);
                 }
                 if (isset($data['priority']) && !empty($data['priority'])) {
                     $descriptions[] = trans('tickets::tickets.histories.priority_changed', ['user' => user()->name, 'old' => trans('tickets.tickets.priorities.' . $ticket->priority), 'new' => trans('tickets.tickets.priorities.' . $data['priority'])]);
                 }
                 if (!empty($data)) {
                     event(new TicketUpdated($ticket, $descriptions));
                     if (!$ticket->fill($data)->save()) {
                         return $ticket->errors();
                     }
                 }
             }
             return redirect()->back()->with('success', trans('tickets::tickets.bulk_update_success'));
         } else {
             return redirect()->back()->with('warning', trans('tickets::tickets.bulk_update_no_data'));
         }
     }
 }