Widget.php
3 months ago
WidgetConfig.php
1 month ago
WidgetContainerConfig.php
3 months ago
WidgetsList.php
1 month ago
WidgetContainerConfig.php
128 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Matomo - free/libre analytics platform |
| 5 | * |
| 6 | * @link https://matomo.org |
| 7 | * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 8 | */ |
| 9 | namespace Piwik\Widget; |
| 10 | |
| 11 | /** |
| 12 | * Defines a new widget container. Widget containers are useful when you want to combine several widgets |
| 13 | * into one unique widgets. For example you could combine an evolution graph widget with a sparklines widget |
| 14 | * and combine them to a single "overview widget". It also allows you to specify layouts meaning you can |
| 15 | * define a layout that will group multiple widgets into one widget displaying a menu on the left side for each |
| 16 | * widget and the actual widget on the right side. By default widgets within a container are displayed vertically |
| 17 | * one after another. |
| 18 | * |
| 19 | * To define a widget container just place a subclass within the `Widgets` folder of your plugin. |
| 20 | * |
| 21 | * @api since Piwik 3.0.0 |
| 22 | */ |
| 23 | class WidgetContainerConfig extends \Piwik\Widget\WidgetConfig |
| 24 | { |
| 25 | /** |
| 26 | * @var WidgetConfig[] |
| 27 | */ |
| 28 | protected $widgets = array(); |
| 29 | protected $layout = ''; |
| 30 | protected $id = ''; |
| 31 | protected $module = 'CoreHome'; |
| 32 | protected $action = 'renderWidgetContainer'; |
| 33 | protected $isWidgetizable = \false; |
| 34 | /** |
| 35 | * Sets (overwrites) the id of the widget container. |
| 36 | * |
| 37 | * The id can be used by any plugins to add more widgets to this container and it will be also used for the unique |
| 38 | * widget id and in the URL to render this widget. |
| 39 | * |
| 40 | * @param string $id eg 'Products' or 'Contents' |
| 41 | * @return static |
| 42 | */ |
| 43 | public function setId($id) |
| 44 | { |
| 45 | $this->id = $id; |
| 46 | return $this; |
| 47 | } |
| 48 | /** |
| 49 | * Get the id of the widget. |
| 50 | * @return string |
| 51 | */ |
| 52 | public function getId() |
| 53 | { |
| 54 | return $this->id; |
| 55 | } |
| 56 | /** |
| 57 | * Sets the layout of the container widget. |
| 58 | * |
| 59 | * By default widgets within a container are displayed one after another. In case you want to change this |
| 60 | * behaviour you can specify a layout that will be recognized by the UI. It is not yet possible to define |
| 61 | * custom layouts. |
| 62 | * |
| 63 | * @param string $layout eg 'ByDimension' see {@link Piwik\Plugins\CoreHome\CoreHome::WIDGET_CONTAINER_LAYOUT_BY_DIMENSION} |
| 64 | * @return static |
| 65 | */ |
| 66 | public function setLayout($layout) |
| 67 | { |
| 68 | $this->layout = $layout; |
| 69 | return $this; |
| 70 | } |
| 71 | /** |
| 72 | * Gets the currently set layout. |
| 73 | * @return string |
| 74 | */ |
| 75 | public function getLayout() |
| 76 | { |
| 77 | return $this->layout; |
| 78 | } |
| 79 | /** |
| 80 | * Adds a new widget to the container widget. |
| 81 | * |
| 82 | * @return static |
| 83 | */ |
| 84 | public function addWidgetConfig(\Piwik\Widget\WidgetConfig $widget) |
| 85 | { |
| 86 | $this->widgets[] = $widget; |
| 87 | return $this; |
| 88 | } |
| 89 | /** |
| 90 | * Set (overwrite) widget configs. |
| 91 | * |
| 92 | * @param WidgetConfig[] $configs |
| 93 | */ |
| 94 | public function setWidgetConfigs($configs) |
| 95 | { |
| 96 | $this->widgets = $configs; |
| 97 | } |
| 98 | /** |
| 99 | * Get all added widget configs. |
| 100 | * |
| 101 | * @return WidgetConfig[] |
| 102 | */ |
| 103 | public function getWidgetConfigs() |
| 104 | { |
| 105 | return $this->widgets; |
| 106 | } |
| 107 | /** |
| 108 | * @inheritdoc |
| 109 | */ |
| 110 | public function getUniqueId() |
| 111 | { |
| 112 | $parameters = $this->getParameters(); |
| 113 | unset($parameters['module']); |
| 114 | unset($parameters['action']); |
| 115 | unset($parameters['containerId']); |
| 116 | return \Piwik\Widget\WidgetsList::getWidgetUniqueId($this->id, '', $parameters); |
| 117 | } |
| 118 | /** |
| 119 | * @inheritdoc |
| 120 | */ |
| 121 | public function getParameters() |
| 122 | { |
| 123 | $params = parent::getParameters(); |
| 124 | $params['containerId'] = $this->getId(); |
| 125 | return $params; |
| 126 | } |
| 127 | } |
| 128 |