예제 #1
0
 /**
  * Execute the console command.
  *
  * @return boolean
  */
 public function handle()
 {
     if (empty($this->option('list')) && empty($this->option('send'))) {
         $this->error('Invalid or incomplete option(s) used, try --help');
         return false;
     }
     $notification = new Notification();
     $searchTicket = false;
     $searchReference = false;
     $searchForce = false;
     if ($this->option('ticket') !== null) {
         $searchTicket = $this->option('ticket');
     }
     if ($this->option('reference') !== null) {
         $searchReference = $this->option('reference');
     }
     if ($this->option('force') !== null) {
         $searchForce = $this->option('force');
     }
     $notifications = $notification->buildList($searchTicket, $searchReference, $searchForce);
     if (!empty($this->option('list')) && $this->option('list') === true) {
         if (empty($notifications)) {
             return true;
         }
         if (!is_array($notifications)) {
             $this->error('Error(s) received while building notifications list:' . PHP_EOL . $notifications);
             return false;
         }
         /*
          * Apply field filtering for output
          */
         $list = [];
         foreach ($notifications as $customerReference => $notificationTypes) {
             foreach ($notificationTypes as $notificationType => $tickets) {
                 foreach ($tickets as $ticket) {
                     $list[$notificationType][] = array_intersect_key($ticket->toArray(), $this->fields);
                 }
             }
         }
         foreach ($list as $notificationType => $table) {
             $this->info("Notifications for {$notificationType} contacts:");
             $this->table($this->headers, $table);
             $this->info('');
         }
     }
     if (!empty($this->option('send')) && $this->option('send') === true) {
         $errors = $notification->walkList($notifications);
         if ($errors !== true) {
             $this->error("Errors ({$errors}) while sending notifications. Details logged under JOB " . getmypid());
         } else {
             $this->info("Successfully send out notifications. Details logged under JOB " . getmypid());
         }
     }
     return true;
 }
예제 #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @param NoteFormRequest $noteForm
  *
  * @return \Illuminate\Http\RedirectResponse
  */
 public function store(NoteFormRequest $noteForm)
 {
     Note::create($noteForm->all());
     /*
      * send notication if a new note is added
      */
     if ($noteForm->hidden != true) {
         $notification = new Notification();
         $notifications = $notification->buildList($noteForm->ticket_id, false, true);
         $notification->walkList($notifications);
     }
     return Redirect::route('admin.tickets.show', $noteForm->ticket_id)->with('message', 'A new note for this ticket has been created');
 }
예제 #3
0
 /**
  * Send a notification for this ticket to the IP contact.
  *
  * @param Ticket $ticket    Ticket Model
  * @param string $only      Only send to ('ip', 'domain' or null (both))
  * @return \Illuminate\Http\RedirectResponse
  */
 public function notify(Ticket $ticket, $only = null)
 {
     $notification = new Notification();
     $notification->walkList($notification->buildList($ticket->id, false, true, $only));
     return Redirect::route('admin.tickets.show', $ticket->id)->with('message', 'Contact has been notified.');
 }