HtmlEmailFooterView.php
2 years ago
HtmlReportEmailHeaderView.php
1 month ago
MethodCallExpression.php
1 year ago
OneClickDone.php
6 months ago
RenderTokenParser.php
1 year ago
SecurityPolicy.php
1 month ago
UIControl.php
1 month ago
ViewInterface.php
1 year ago
UIControl.php
155 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\View; |
| 10 | |
| 11 | use Exception; |
| 12 | use Piwik\View; |
| 13 | /** |
| 14 | * Base type of UI controls. |
| 15 | * |
| 16 | * The JavaScript companion class can be found in plugins/CoreHome/javascripts/uiControl.js. |
| 17 | * |
| 18 | * @api |
| 19 | */ |
| 20 | class UIControl extends \Piwik\View |
| 21 | { |
| 22 | /** |
| 23 | * The Twig template file that generates the control's HTML. |
| 24 | * |
| 25 | * Derived classes must set this constant. |
| 26 | */ |
| 27 | public const TEMPLATE = ''; |
| 28 | /** |
| 29 | * The CSS class that is used to map the root element of this control with the JavaScript class. |
| 30 | * |
| 31 | * This field must be set prior to rendering. |
| 32 | * |
| 33 | * @var string |
| 34 | */ |
| 35 | public $cssIdentifier = null; |
| 36 | /** |
| 37 | * The name of the JavaScript class that handles the behavior of this control. |
| 38 | * |
| 39 | * This field must be set prior to rendering. |
| 40 | * |
| 41 | * @var string |
| 42 | */ |
| 43 | public $jsClass = null; |
| 44 | /** |
| 45 | * The JavaScript module that contains the JavaScript class. |
| 46 | * |
| 47 | * @var string |
| 48 | */ |
| 49 | public $jsNamespace = 'piwik/UI'; |
| 50 | /** |
| 51 | * Extra CSS class(es) for the root element. |
| 52 | * |
| 53 | * @var string |
| 54 | */ |
| 55 | public $cssClass = ""; |
| 56 | /** |
| 57 | * HTML Attributes for the root element |
| 58 | * |
| 59 | * @var string |
| 60 | */ |
| 61 | public $htmlAttributes = array(); |
| 62 | /** |
| 63 | * The inner view that renders the actual control content. |
| 64 | * |
| 65 | * @var View |
| 66 | */ |
| 67 | private $innerView = null; |
| 68 | public function __construct() |
| 69 | { |
| 70 | $this->innerView = new View(static::TEMPLATE); |
| 71 | parent::__construct("@CoreHome\\_uiControl"); |
| 72 | } |
| 73 | /** |
| 74 | * Sets a variable. See {@link View::__set()}. |
| 75 | */ |
| 76 | public function __set($key, $val) |
| 77 | { |
| 78 | $this->innerView->__set($key, $val); |
| 79 | } |
| 80 | /** |
| 81 | * Gets a view variable. See {@link View::__get()}. |
| 82 | */ |
| 83 | public function &__get($key) |
| 84 | { |
| 85 | return $this->innerView->__get($key); |
| 86 | } |
| 87 | public function __isset($key) |
| 88 | { |
| 89 | return isset($this->innerView->templateVars[$key]); |
| 90 | } |
| 91 | /** |
| 92 | * Renders the control view within a containing <div> that is used by the UIControl JavaScript |
| 93 | * class. |
| 94 | * |
| 95 | * @return string |
| 96 | */ |
| 97 | public function render() |
| 98 | { |
| 99 | if ($this->cssIdentifier === null) { |
| 100 | throw new Exception("All UIControls must set a cssIdentifier property"); |
| 101 | } |
| 102 | if ($this->jsClass === null) { |
| 103 | throw new Exception("All UIControls must set a jsClass property"); |
| 104 | } |
| 105 | return parent::render(); |
| 106 | } |
| 107 | /** |
| 108 | * See {@link View::getTemplateVars()}. |
| 109 | */ |
| 110 | public function getTemplateVars($override = array()) |
| 111 | { |
| 112 | $this->templateVars['implView'] = $this->innerView; |
| 113 | $this->templateVars['cssIdentifier'] = $this->cssIdentifier; |
| 114 | $this->templateVars['cssClass'] = $this->cssClass; |
| 115 | $this->templateVars['jsClass'] = $this->jsClass; |
| 116 | $this->templateVars['htmlAttributes'] = $this->htmlAttributes; |
| 117 | $this->templateVars['jsNamespace'] = $this->jsNamespace; |
| 118 | $this->templateVars['implOverride'] = $override; |
| 119 | $innerTemplateVars = $this->innerView->getTemplateVars($override); |
| 120 | $this->templateVars['clientSideProperties'] = array(); |
| 121 | foreach ($this->getClientSideProperties() as $name) { |
| 122 | $this->templateVars['clientSideProperties'][$name] = $innerTemplateVars[$name]; |
| 123 | } |
| 124 | $this->templateVars['clientSideParameters'] = array(); |
| 125 | foreach ($this->getClientSideParameters() as $name) { |
| 126 | $this->templateVars['clientSideParameters'][$name] = $innerTemplateVars[$name]; |
| 127 | } |
| 128 | return parent::getTemplateVars($override); |
| 129 | } |
| 130 | /** |
| 131 | * Returns the array of property names whose values are passed to the UIControl JavaScript class. |
| 132 | * |
| 133 | * Should be overridden by descendants. |
| 134 | * |
| 135 | * @return array |
| 136 | */ |
| 137 | public function getClientSideProperties() |
| 138 | { |
| 139 | return array(); |
| 140 | } |
| 141 | /** |
| 142 | * Returns an array of property names whose values are passed to the UIControl JavaScript class. |
| 143 | * These values differ from those in {@link $clientSideProperties} in that they are meant to passed as |
| 144 | * request parameters when the JavaScript code makes an AJAX request. |
| 145 | * |
| 146 | * Should be overridden by descendants. |
| 147 | * |
| 148 | * @return array |
| 149 | */ |
| 150 | public function getClientSideParameters() |
| 151 | { |
| 152 | return array(); |
| 153 | } |
| 154 | } |
| 155 |