Exemplo n.º 1
0
 /**
  * function to load data
  * @param type $id 
  * @return type file
  */
 public function get_data($id)
 {
     $attachments = App\Model\helpdesk\Ticket\Ticket_attachments::where('id', '=', $id)->get();
     foreach ($attachments as $attachment) {
         header('Content-type: application/' . $attachment->type . '');
         header('Content-Disposition: inline; filename=' . $attachment->name . '');
         header('Content-Transfer-Encoding: binary');
         echo $attachment->file;
     }
 }
Exemplo n.º 2
0
 /**
  * Function to delete ticket
  * @param type $id
  * @param type Tickets $ticket
  * @return type string
  */
 public function delete($id, Tickets $ticket)
 {
     $ticket_delete = $ticket->where('id', '=', $id)->first();
     if ($ticket_delete->status == 5) {
         $ticket_delete->delete();
         $ticket_threads = Ticket_Thread::where('ticket_id', '=', $id)->get();
         foreach ($ticket_threads as $ticket_thread) {
             $ticket_thread->delete();
         }
         $ticket_attachments = Ticket_attachments::where('ticket_id', '=', $id)->get();
         foreach ($ticket_attachments as $ticket_attachment) {
             $ticket_attachment->delete();
         }
         return "your ticket has been delete";
     } else {
         $ticket_delete->is_deleted = 0;
         $ticket_delete->status = 5;
         $ticket_delete->save();
         $ticket_status_message = Ticket_Status::where('id', '=', $ticket_delete->status)->first();
         $thread = new Ticket_Thread();
         $thread->ticket_id = $ticket_delete->id;
         $thread->user_id = Auth::user()->id;
         $thread->is_internal = 1;
         $thread->body = $ticket_status_message->message . " " . Auth::user()->first_name . " " . Auth::user()->last_name;
         $thread->save();
         return "your ticket" . $ticket_delete->ticket_number . " has been delete";
     }
 }
 public function get_unassigned()
 {
     if (Auth::user()->role == "admin") {
         // $tickets = Tickets::where('status', '=', 1)->where('assigned_to', '=', Auth::user()->id)->get();
         $tickets = Tickets::where('assigned_to', '=', null)->where('status', '1')->get();
     } else {
         $dept = Department::where('id', '=', Auth::user()->primary_dpt)->first();
         $tickets = Tickets::where('assigned_to', '=', null)->where('dept_id', '=', $dept->id)->get();
         // $dept = Department::where('name','=',Auth::user()->primary_dpt)->first();
         // $tickets = Tickets::where('status', '=', 1)->where('assigned_to', '=', Auth::user()->id)->get();
     }
     return \Datatable::collection(new Collection($tickets))->addColumn('id', function ($ticket) {
         return "<input type='checkbox' name='select_all[]' class='icheckbox_flat-blue' value='" . $ticket->id . "'></input>";
     })->addColumn('subject', function ($ticket) {
         $subject = DB::table('ticket_thread')->select('title')->where('ticket_id', "=", $ticket->id)->first();
         $string = $subject->title;
         if (strlen($string) > 20) {
             $stringCut = substr($string, 0, 30);
             $string = substr($stringCut, 0, strrpos($stringCut, ' ')) . ' ...';
         }
         //collabrations
         $collaborators = DB::table('ticket_collaborator')->where('ticket_id', '=', $ticket->id)->get();
         $collab = count($collaborators);
         if ($collab > 0) {
             $collabString = '&nbsp;<i class="fa fa-users"></i>';
         } else {
             $collabString = null;
         }
         $threads = Ticket_Thread::where('ticket_id', '=', $ticket->id)->first();
         //Ticket_Thread::where('ticket_id', '=', $ticket->id)->get();
         $count = count($threads);
         $attachment = Ticket_attachments::where('thread_id', '=', $threads->id)->get();
         $attachCount = count($attachment);
         if ($attachCount > 0) {
             $attachString = '&nbsp;<i class="fa fa-paperclip"></i>';
         } else {
             $attachString = "";
         }
         //return $threads->id;
         return "<a href='" . route('ticket.thread', [$ticket->id]) . "' title='" . $subject->title . "'>" . $string . "&nbsp;<span style='color:green'>(" . $count . ")<i class='fa fa-comment'></i></span></a>" . $collabString . $attachString;
     })->addColumn('ticket_number', function ($ticket) {
         return "<a href='" . route('ticket.thread', [$ticket->id]) . "' title='" . $ticket->ticket_number . "'>#" . $ticket->ticket_number . "</a>";
     })->addColumn('priority', function ($ticket) {
         $priority = DB::table('ticket_priority')->select('priority', 'priority_color')->where('priority_id', "=", $ticket->priority_id)->first();
         return '<span class="btn btn-' . $priority->priority_color . ' btn-xs">' . $priority->priority . '</span>';
         //return "loda";
     })->addColumn('from', function ($ticket) {
         $from = DB::table('users')->select('user_name')->where('id', "=", $ticket->user_id)->first();
         return "<span style='color:#508983'>" . $from->user_name . "</span>";
     })->addColumn('Last Replier', function ($ticket) {
         $TicketData = Ticket_Thread::where('ticket_id', '=', $ticket->id)->where('is_internal', '!=', 1)->max('id');
         $TicketDatarow = Ticket_Thread::where('id', '=', $TicketData)->first();
         $LastResponse = User::where('id', '=', $TicketDatarow->user_id)->first();
         if ($LastResponse->role == "user") {
             $rep = "#F39C12";
             $username = $LastResponse->user_name;
         } else {
             $rep = "#000";
             $username = $LastResponse->first_name . " " . $LastResponse->last_name;
             if ($LastResponse->first_name == null || $LastResponse->last_name == null) {
                 $username = $LastResponse->user_name;
             }
         }
         return "<span style='color:" . $rep . "'>" . $username . "</span>";
     })->addColumn('assigned_to', function ($ticket) {
         if ($ticket->assigned_to == null) {
             return "<span style='color:red'>Unassigned</span>";
         } else {
             $assign = DB::table("users")->where('id', "=", $ticket->assigned_to)->first();
             return "<span style='color:green'>" . $assign->first_name . " " . $assign->last_name . "</span>";
         }
     })->addColumn('Last', function ($ticket) {
         $TicketData = Ticket_Thread::where('ticket_id', '=', $ticket->id)->max('id');
         $TicketDatarow = Ticket_Thread::select('updated_at')->where('id', '=', $TicketData)->first();
         return date('d F Y, H:i:s', strtotime($TicketDatarow->updated_at));
     })->searchColumns('subject', 'from', 'assigned_to', 'ticket_number', 'priority')->orderColumns('subject', 'from', 'assigned_to', 'Last Replier', 'ticket_number', 'priority', 'Last')->make();
 }
 /**
  * Create Attachment
  * @param type $thread
  * @param type $attach
  * @return int
  */
 public function attach($thread, $attach)
 {
     try {
         $ta = new Ticket_attachments();
         foreach ($attach as $file) {
             $ta->create(['thread_id' => $thread, 'name' => $file['name'], 'size' => $file['size'], 'type' => $file['type'], 'file' => $file['file'], 'poster' => 'ATTACHMENT']);
         }
         $ta->create(['thread_id' => $thread, 'name' => $name, 'size' => $size, 'type' => $type, 'file' => $file, 'poster' => 'ATTACHMENT']);
         return 1;
     } catch (\Exception $e) {
         return $e->getMessage();
     }
 }