| 1 |  |  | <?php namespace Arcanesoft\Foundation\Http\Controllers\System; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | use Arcanedev\LogViewer\Contracts\LogViewer as LogViewerContract; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | use Arcanedev\LogViewer\Entities\Log; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use Arcanedev\LogViewer\Exceptions\LogNotFoundException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use Arcanesoft\Core\Traits\Notifyable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Arcanesoft\Foundation\Http\Controllers\Controller; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Arcanesoft\Foundation\Policies\LogViewerPolicy; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Arcanesoft\Foundation\Presenters\PaginationPresenter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Illuminate\Http\Request; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Illuminate\Pagination\LengthAwarePaginator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Illuminate\Support\Arr; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * Class     LogViewerController | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * @package  Arcanesoft\Foundation\Http\Controllers\System | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * @author   ARCANEDEV <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | class LogViewerController extends Controller | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     /* ------------------------------------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      |  Traits | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      | ------------------------------------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     use Notifyable; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |     /* ------------------------------------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      |  Properties | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |      | ------------------------------------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * The LogViewer instance. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |      * @var \Arcanedev\LogViewer\Contracts\LogViewer | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     protected $logViewer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |      * Logs per page. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |      * @var int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |     protected $perPage = 30; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     /* ------------------------------------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      |  Constructor | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      | ------------------------------------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * LogViewerController constructor. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * @param  \Arcanedev\LogViewer\Contracts\LogViewer  $logViewer | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     public function __construct(LogViewerContract $logViewer) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         parent::__construct(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         $this->logViewer = $logViewer; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |         $this->perPage   = config('arcanesoft.foundation.log-viewer.per-page', $this->perPage); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         $this->setCurrentPage('foundation-system-logviewer'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $this->addBreadcrumbRoute('LogViewer', 'foundation::system.log-viewer.index'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     /* ------------------------------------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |      |  Main Functions | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |      | ------------------------------------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |      * Show the LogViewer Dashboard. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |      * @return \Illuminate\View\View | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |     public function index() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         $this->authorize(LogViewerPolicy::PERMISSION_DASHBOARD); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $stats    = $this->logViewer->statsTable(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |         $percents = $this->calcPercentages($stats->footer(), $stats->header()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |         $this->setTitle('LogViewer Dashboard'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |         $this->addBreadcrumb('Dashboard'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |         return $this->view('system.log-viewer.dashboard', compact('percents')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |      * List all logs. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |      * @param  \Illuminate\Http\Request  $request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |      * @return \Illuminate\View\View | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |     public function listLogs(Request $request) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |         $this->authorize(LogViewerPolicy::PERMISSION_LIST); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |         $stats   = $this->logViewer->statsTable(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |         $headers = $stats->header(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |         // $footer   = $stats->footer(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 101 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |         $page    = $request->get('page', 1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         $offset  = ($page * $this->perPage) - $this->perPage; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         $rows    = new LengthAwarePaginator( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |             array_slice($stats->rows(), $offset, $this->perPage, true), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |             count($stats->rows()), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |             $this->perPage, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |             $page | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |         $rows->setPath($request->url()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |         $title = 'Logs List'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |         $this->setTitle($title); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |         $this->addBreadcrumb($title); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |         return $this->view('system.log-viewer.list', compact('headers', 'rows', 'footer')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |      * Show the log entries by date. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |      * @param  string  $date | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |      * @return \Illuminate\View\View | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |     public function show($date) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 128 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 129 |  |  |         $this->authorize(LogViewerPolicy::PERMISSION_SHOW); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 130 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 131 |  |  |         $log       = $this->getLogOrFail($date); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 132 |  |  |         $levels    = $this->logViewer->levelsNames(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 133 |  |  |         $entries   = $log->entries()->paginate($this->perPage); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 134 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 135 |  |  |         $title = 'Log : ' . $date; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 136 |  |  |         $this->setTitle($title); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 137 |  |  |         $this->addBreadcrumbRoute('Logs List', 'foundation::system.log-viewer.logs.list'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 138 |  |  |         $this->addBreadcrumb($title); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 139 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 140 |  |  |         return $this->view('system.log-viewer.show', compact('log', 'levels', 'entries')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 141 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 142 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 143 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 144 |  |  |      * Filter the log entries by date and level. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 145 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 146 |  |  |      * @param  string  $date | 
            
                                                                                                            
                            
            
                                    
            
            
                | 147 |  |  |      * @param  string  $level | 
            
                                                                                                            
                            
            
                                    
            
            
                | 148 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 149 |  |  |      * @return \Illuminate\View\View|\Illuminate\Http\RedirectResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 150 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 151 |  |  |     public function showByLevel($date, $level) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 152 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 153 |  |  |         $this->authorize(LogViewerPolicy::PERMISSION_SHOW); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 154 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 155 |  |  |         $log = $this->getLogOrFail($date); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 156 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 157 |  |  |         if ($level == 'all') { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 158 |  |  |             return redirect()->route('foundation::system.log-viewer.logs.show', [$date]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 159 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 160 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 161 |  |  |         $levels    = $this->logViewer->levelsNames(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 162 |  |  |         $entries   = $this->logViewer->entries($date, $level)->paginate($this->perPage); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 163 |  |  |         $presenter = new PaginationPresenter($entries); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 164 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 165 |  |  |         $this->addBreadcrumbRoute('Logs List', 'foundation::system.log-viewer.logs.list'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 166 |  |  |         $this->addBreadcrumbRoute($date, 'foundation::system.log-viewer.logs.show', [$date]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 167 |  |  |         $this->addBreadcrumb(ucfirst($level)); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 168 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 169 |  |  |         return $this->view('system.log-viewer.show', compact('log', 'levels', 'entries', 'presenter')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 170 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 171 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 172 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 173 |  |  |      * Download the log. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 174 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 175 |  |  |      * @param  string  $date | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |      * @return \Symfony\Component\HttpFoundation\BinaryFileResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |     public function download($date) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |         $this->authorize(LogViewerPolicy::PERMISSION_DOWNLOAD); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |         return $this->logViewer->download($date); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |      * Delete a log. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |      * @param  \Illuminate\Http\Request  $request | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |      * @return \Illuminate\Http\JsonResponse | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |     public function delete(Request $request) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |         self::onlyAjax(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |         $this->authorize(LogViewerPolicy::PERMISSION_DELETE); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |         $date = $request->get('date'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |         $ajax = ['status' => 'error']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |         if ($this->logViewer->delete($date)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |             $ajax = ['status' => 'success']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |             $this->notifySuccess( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |                 "The log [$date] was deleted successfully !", | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |                 "Log [$date] deleted !" | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |             ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |         return response()->json($ajax); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |     /* ------------------------------------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |      |  Other Functions | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |      | ------------------------------------------------------------------------------------------------ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |      * Get a log or fail. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |      * @param  string  $date | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |      * @return Log|null | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |     private function getLogOrFail($date) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |         $log = null; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |         try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |             $log = $this->logViewer->get($date); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |         catch(LogNotFoundException $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |             abort(404, $e->getMessage()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |         return $log; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |      * Calculate the percentage. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |      * @param  array  $total | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |      * @param  array  $names | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |      * @return array | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 246 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 247 |  |  |     private function calcPercentages(array $total, array $names) | 
            
                                                        
            
                                    
            
            
                | 248 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 249 |  |  |         $percents = []; | 
            
                                                        
            
                                    
            
            
                | 250 |  |  |         $all      = Arr::get($total, 'all'); | 
            
                                                        
            
                                    
            
            
                | 251 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 252 |  |  |         foreach ($total as $level => $count) { | 
            
                                                        
            
                                    
            
            
                | 253 |  |  |             $percents[$level] = [ | 
            
                                                        
            
                                    
            
            
                | 254 |  |  |                 'name'    => $names[$level], | 
            
                                                        
            
                                    
            
            
                | 255 |  |  |                 'count'   => $count, | 
            
                                                        
            
                                    
            
            
                | 256 |  |  |                 'percent' => round(($count / $all) * 100, 2), | 
            
                                                        
            
                                    
            
            
                | 257 |  |  |             ]; | 
            
                                                        
            
                                    
            
            
                | 258 |  |  |         } | 
            
                                                        
            
                                    
            
            
                | 259 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 260 |  |  |         return $percents; | 
            
                                                        
            
                                    
            
            
                | 261 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 262 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 263 |  |  |  |