Ejemplo n.º 1
0
 /**
  * Create Ticket
  * @param type $user_id
  * @param type $subject
  * @param type $body
  * @param type $helptopic
  * @param type $sla
  * @param type $priority
  * @return type string
  */
 public function create_ticket($user_id, $subject, $body, $helptopic, $sla, $priority, $source, $headers, $dept, $assignto, $form_data, $attach = '')
 {
     try {
         $max_number = Tickets::whereRaw('id = (select max(`id`) from tickets)')->first();
         if ($max_number == null) {
             $ticket_number = "AAAA-9999-9999999";
         } else {
             foreach ($max_number as $number) {
                 $ticket_number = $max_number->ticket_number;
             }
         }
         $ticket = new Tickets();
         $ticket->ticket_number = $this->ticket_number($ticket_number);
         $ticket->user_id = $user_id;
         $ticket->dept_id = $dept;
         $ticket->help_topic_id = $helptopic;
         $ticket->sla = $sla;
         $ticket->assigned_to = $assignto;
         $ticket->status = '1';
         $ticket->priority_id = $priority;
         $ticket->source = $source;
         $ticket->save();
         $ticket_number = $ticket->ticket_number;
         $id = $ticket->id;
         if ($form_data != null) {
             $help_topic = Help_topic::where('id', '=', $helptopic)->first();
             $forms = Fields::where('forms_id', '=', $help_topic->custom_form)->get();
             foreach ($form_data as $key => $form_details) {
                 foreach ($forms as $from) {
                     if ($from->name == $key) {
                         $form_value = new Ticket_Form_Data();
                         $form_value->ticket_id = $id;
                         $form_value->title = $from->label;
                         $form_value->content = $form_details;
                         $form_value->save();
                     }
                 }
             }
         }
         $this->store_collaborators($headers, $id);
         $thread = $this->ticket_thread($subject, $body, $id, $user_id);
         if (!empty($attach)) {
             $this->attach($thread, $attach);
         }
         return $thread;
     } catch (\Exception $e) {
         return $e->getMessage();
     }
 }