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