| 1 | <?php namespace Modules\Dashboard\Foundation\Widgets; |
||
| 3 | abstract class BaseWidget |
||
| 4 | { |
||
| 5 | /** |
||
| 6 | * Boot the widget and add the data to the dashboard view composer |
||
| 7 | */ |
||
| 8 | public function boot() |
||
| 9 | { |
||
| 10 | $widgetViewComposer = app('Modules\Dashboard\Composers\WidgetViewComposer'); |
||
| 11 | /** @var \Illuminate\Contracts\View\Factory $view */ |
||
| 12 | $view = app('Illuminate\Contracts\View\Factory'); |
||
| 13 | |||
| 14 | if ($view->exists($this->view())) { |
||
| 15 | $html = $view->make($this->view()) |
||
| 16 | ->with($this->data()) |
||
| 17 | ->render(); |
||
| 18 | |||
| 19 | $sluggedName = str_slug($this->name()); |
||
| 20 | |||
| 21 | $widgetViewComposer |
||
| 22 | ->setWidgetName($sluggedName) |
||
| 23 | ->addSubView($sluggedName, $html) |
||
| 24 | ->addWidgetOptions($sluggedName, $this->options()); |
||
| 25 | } |
||
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Get the widget name |
||
| 30 | * @return string |
||
| 31 | */ |
||
| 32 | abstract protected function name(); |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Return an array of widget options |
||
| 36 | * Possible options: |
||
| 37 | * x, y, width, height |
||
| 38 | * @return array |
||
| 39 | */ |
||
| 40 | abstract protected function options(); |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Get the widget view |
||
| 44 | * @return string |
||
| 45 | */ |
||
| 46 | abstract protected function view(); |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Get the widget data to send to the view |
||
| 50 | * @return array |
||
| 51 | */ |
||
| 52 | abstract protected function data(); |
||
| 53 | } |
||
| 54 |