/**
  * Display a listing of tickets related to user.
  *
  * @return Response
  */
 public function index()
 {
     $items = config('ticketit.paginate_items');
     if (Models\Agent::isAdmin()) {
         $tickets = Models\Ticket::orderBy('updated_at', 'desc')->paginate($items);
     } elseif (Models\Agent::isAgent()) {
         $agent = Models\Agent::find(\Auth::user()->id);
         $tickets = $agent->agentTickets()->orderBy('updated_at', 'desc')->paginate($items);
     } else {
         $user = Models\Agent::find(\Auth::user()->id);
         $tickets = $user->userTickets()->orderBy('updated_at', 'desc')->paginate($items);
     }
     return view('ticketit::index', compact('tickets'));
 }
 /**
  * Bootstrap the application services.
  *
  * @return void
  */
 public function boot()
 {
     $installer = new InstallController();
     // if a migration is missing scape to the installation
     if (empty($installer->inactiveMigrations()) && DB::table('ticketit_settings')->count() != 0) {
         // Send the Agent User model to the view under $u
         view()->composer('*', function ($view) {
             if (auth()->check()) {
                 $u = Agent::find(auth()->user()->id);
                 $view->with('u', $u);
             }
             $setting = new Setting();
             $view->with('setting', $setting);
         });
         // Adding HTML5 color picker to form elements
         CollectiveForm::macro('custom', function ($type, $name, $value = "#000000", $options = []) {
             $field = $this->input($type, $name, $value, $options);
             return $field;
         });
         // Passing to views the master view value from the setting file
         view()->composer('ticketit::*', function ($view) {
             $tools = new ToolsController();
             $master = Setting::grab('master_template');
             $email = Setting::grab('email.template');
             $view->with(compact('master', 'email', 'tools'));
         });
         // Send notification when new comment is added
         Comment::creating(function ($comment) {
             if (Setting::grab('comment_notification')) {
                 $notification = new NotificationsController();
                 $notification->newComment($comment);
             }
         });
         // Send notification when ticket status is modified
         Ticket::updating(function ($modified_ticket) {
             if (Setting::grab('status_notification')) {
                 $original_ticket = Ticket::find($modified_ticket->id);
                 if ($original_ticket->status_id != $modified_ticket->status_id || $original_ticket->completed_at != $modified_ticket->completed_at) {
                     $notification = new NotificationsController();
                     $notification->ticketStatusUpdated($modified_ticket, $original_ticket);
                 }
             }
             if (Setting::grab('assigned_notification')) {
                 $original_ticket = Ticket::find($modified_ticket->id);
                 if ($original_ticket->agent->id != $modified_ticket->agent->id) {
                     $notification = new NotificationsController();
                     $notification->ticketAgentUpdated($modified_ticket, $original_ticket);
                 }
             }
             return true;
         });
         // Send notification when ticket status is modified
         Ticket::created(function ($ticket) {
             if (Setting::grab('assigned_notification')) {
                 $notification = new NotificationsController();
                 $notification->newTicketNotifyAgent($ticket);
             }
             return true;
         });
         $this->loadTranslationsFrom(__DIR__ . '/Translations', 'ticketit');
         $this->loadViewsFrom(__DIR__ . '/Views', 'ticketit');
         $this->publishes([__DIR__ . '/Views' => base_path('resources/views/vendor/ticketit')], 'views');
         $this->publishes([__DIR__ . '/Translations' => base_path('resources/lang/vendor/ticketit')], 'lang');
         $this->publishes([__DIR__ . '/Public' => public_path('vendor/ticketit')], 'public');
         $this->publishes([__DIR__ . '/Migrations' => base_path('database/migrations')], 'db');
         // Check public assets are present, publish them if not
         //            $installer->publicAssets();
         $main_route = Setting::grab('main_route');
         $admin_route = Setting::grab('admin_route');
         include __DIR__ . '/routes.php';
     } elseif (Request::path() == 'tickets-install') {
         $this->loadTranslationsFrom(__DIR__ . '/Translations', 'ticketit');
         $this->loadViewsFrom(__DIR__ . '/Views', 'ticketit');
         $this->publishes([__DIR__ . '/Migrations' => base_path('database/migrations')], 'db');
         Route::get('/tickets-install', ['middleware' => 'auth', 'uses' => 'Kordy\\Ticketit\\Controllers\\InstallController@index']);
         Route::post('/tickets-install', ['middleware' => 'auth', 'uses' => 'Kordy\\Ticketit\\Controllers\\InstallController@setup']);
     }
 }
 /**
  * Sync Administrator categories with the selected categories got from update form
  * @param $id
  * @param Request $request
  */
 public function syncAdministratorCategories($id, Request $request)
 {
     $form_cats = $request->input('administrator_cats') == null ? [] : $request->input('administrator_cats');
     $administrator = Agent::find($id);
     $administrator->categories()->sync($form_cats);
 }
 /**
  * Sync Agent categories with the selected categories got from update form
  * @param $id
  * @param Request $request
  */
 public function syncAgentCategories($id, Request $request)
 {
     $form_cats = $request->input('agent_cats') == null ? [] : $request->input('agent_cats');
     $agent = Agent::find($id);
     $agent->categories()->sync($form_cats);
 }
Exemple #5
0
 public function getTickets($complete = false)
 {
     $user = Agent::find(auth()->user()->id);
     if ($user->isAdmin()) {
         $tickets = $user->allTickets($complete);
     } elseif ($user->isAgent()) {
         $tickets = $user->agentTickets($complete);
     } else {
         $tickets = $user->userTickets($complete);
     }
     return $tickets;
 }