Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 61 |
|
0.00% |
0 / 12 |
CRAP | |
0.00% |
0 / 1 |
| ConfigurableTheme | |
0.00% |
0 / 61 |
|
0.00% |
0 / 12 |
1122 | |
0.00% |
0 / 1 |
| initializeTexts | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getText | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| getTextFromArray | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
20 | |||
| getAllTexts | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| getTemplate | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
72 | |||
| getThemeData | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
| getStylesheet | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| getLogoUrl | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| getLink | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| getMessage | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| getLabel | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| getId | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2015 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\tao\model\theme; |
| 23 | |
| 24 | use oat\oatbox\Configurable; |
| 25 | use oat\tao\helpers\Template; |
| 26 | |
| 27 | /** |
| 28 | * Class UrlSourceTheme |
| 29 | * |
| 30 | * Class to easily configure a theme |
| 31 | * To use it, declare into tao/theming.conf themes: |
| 32 | * |
| 33 | * return new oat\tao\model\theme\ThemeService(array( |
| 34 | * 'available' => array( |
| 35 | * [...], |
| 36 | * 'test' => new \oat\tao\model\theme\ConfigurableTheme(), |
| 37 | * 'testConfigured' => new \oat\tao\model\theme\ConfigurableTheme(array( |
| 38 | * 'data' => array( |
| 39 | * 'logo-url' => 'http://lorempixel.com/400/200, |
| 40 | * 'link' => 'http://taotesting.com', |
| 41 | * 'message' => 'Tao Platform', |
| 42 | * 'label' => 'Default Theme', |
| 43 | * 'id' => 'defaultTheme' |
| 44 | * ), |
| 45 | * 'stylesheet' => 'http://tao.dev/tao/views/css/tao-3.css' |
| 46 | * ) |
| 47 | * ) |
| 48 | * [...] |
| 49 | * |
| 50 | * @package oat\tao\model\theme |
| 51 | * @deprecated use oat\tao\model\theme\ConfigurablePlatformTheme instead |
| 52 | */ |
| 53 | class ConfigurableTheme extends Configurable implements Theme, SolarDesignCheckerInterface |
| 54 | { |
| 55 | use SolarDesignCheckerTrait; |
| 56 | |
| 57 | /** Theme id offset in the options. */ |
| 58 | public const THEME_ID = 'id'; |
| 59 | |
| 60 | /** Theme label offset in the options. */ |
| 61 | public const THEME_LABEL = 'label'; |
| 62 | |
| 63 | /** Theme data offset in the options. */ |
| 64 | public const THEME_DATA = 'data'; |
| 65 | |
| 66 | /** Theme css offset in the options. */ |
| 67 | public const THEME_CSS = 'stylesheet'; |
| 68 | |
| 69 | /** Theme data logo url offset in the options under the data offset. */ |
| 70 | public const THEME_DATA_LOGO_URL = 'logo-url'; |
| 71 | /** Theme data logo link offset in the options under the data offset. */ |
| 72 | public const THEME_DATA_LINK = 'link'; |
| 73 | /** Theme data logo title offset in the options under the data offset. */ |
| 74 | public const THEME_DATA_MESSAGE = 'message'; |
| 75 | |
| 76 | /** |
| 77 | * Defined custom texts |
| 78 | * @var array |
| 79 | */ |
| 80 | private $allTexts; |
| 81 | |
| 82 | /** |
| 83 | * Define all custom text |
| 84 | * return [ |
| 85 | * 'myCustomTextId' => __('My custom text translation'); |
| 86 | * ]; |
| 87 | * @return array |
| 88 | */ |
| 89 | protected function initializeTexts() |
| 90 | { |
| 91 | return []; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * Allow to set a custom translatable string for a given key |
| 96 | * @param String $key |
| 97 | * @return string |
| 98 | */ |
| 99 | public function getText($key) |
| 100 | { |
| 101 | if (empty($this->allTexts)) { |
| 102 | $this->allTexts = $this->initializeTexts(); |
| 103 | } |
| 104 | return (array_key_exists($key, $this->allTexts)) |
| 105 | ? $this->allTexts[$key] |
| 106 | : ''; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Retrieve all custom strings for the given keys |
| 111 | * @param String[] $allKeys |
| 112 | * @return array |
| 113 | */ |
| 114 | public function getTextFromArray($allKeys) |
| 115 | { |
| 116 | $allValues = []; |
| 117 | if (is_array($allKeys) && ! empty($allKeys)) { |
| 118 | foreach ($allKeys as $key) { |
| 119 | $allValues[$key] = $this->getText($key); |
| 120 | } |
| 121 | } |
| 122 | return $allValues; |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Retrieve all existing strings |
| 127 | * @return array |
| 128 | */ |
| 129 | public function getAllTexts() |
| 130 | { |
| 131 | if (empty($this->allTexts)) { |
| 132 | $this->allTexts = $this->initializeTexts(); |
| 133 | } |
| 134 | return $this->allTexts; |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Get a template associated to given $id |
| 139 | * |
| 140 | * @param string $id |
| 141 | * @param string $context |
| 142 | * @return null|string |
| 143 | */ |
| 144 | public function getTemplate($id, $context = Theme::CONTEXT_BACKOFFICE) |
| 145 | { |
| 146 | switch ($id) { |
| 147 | case 'head': |
| 148 | $template = Template::getTemplate('blocks/head.tpl', 'tao'); |
| 149 | break; |
| 150 | case 'header-logo': |
| 151 | $template = Template::getTemplate('blocks/header-logo.tpl', 'tao'); |
| 152 | break; |
| 153 | case 'footer': |
| 154 | $template = Template::getTemplate('blocks/footer.tpl', 'tao'); |
| 155 | break; |
| 156 | case 'login-message': |
| 157 | $template = Template::getTemplate('blocks/login-message.tpl', 'tao'); |
| 158 | break; |
| 159 | case 'login': |
| 160 | $template = Template::getTemplate('blocks/login.tpl', 'tao'); |
| 161 | break; |
| 162 | case 'logout': |
| 163 | $template = Template::getTemplate('blocks/logout.tpl', 'tao'); |
| 164 | break; |
| 165 | default: |
| 166 | \common_Logger::d('Unknown template ' . $id); |
| 167 | $template = null; |
| 168 | } |
| 169 | return $template; |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Get options under data key |
| 174 | * Options to configure header & footer template |
| 175 | * |
| 176 | * @return array |
| 177 | */ |
| 178 | public function getThemeData() |
| 179 | { |
| 180 | if ($this->hasOption(static::THEME_DATA) && is_array($this->getOption(static::THEME_DATA))) { |
| 181 | return $this->getOption(static::THEME_DATA); |
| 182 | } |
| 183 | |
| 184 | return []; |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Get the url of stylesheet associated to current theme configuration |
| 189 | * |
| 190 | * @param string $context |
| 191 | * @return string |
| 192 | */ |
| 193 | public function getStylesheet($context = Theme::CONTEXT_BACKOFFICE) |
| 194 | { |
| 195 | if ($this->hasOption(static::THEME_CSS)) { |
| 196 | return $this->getOption(static::THEME_CSS); |
| 197 | } |
| 198 | |
| 199 | return Template::css('tao-3.css', 'tao'); |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * Get the logo url of current theme |
| 204 | * Logo url is used into header |
| 205 | * |
| 206 | * @return string |
| 207 | */ |
| 208 | public function getLogoUrl() |
| 209 | { |
| 210 | $data = $this->getThemeData(); |
| 211 | if (isset($data[static::THEME_DATA_LOGO_URL])) { |
| 212 | return $data[static::THEME_DATA_LOGO_URL]; |
| 213 | } |
| 214 | |
| 215 | return Template::img('tao-logo.png', 'tao'); |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * Get the url link of current theme |
| 220 | * Url is used into header, to provide link to logo |
| 221 | * Url is used into footer, to provide link to footer message |
| 222 | * |
| 223 | * @return string |
| 224 | */ |
| 225 | public function getLink() |
| 226 | { |
| 227 | $data = $this->getThemeData(); |
| 228 | if (isset($data[static::THEME_DATA_LINK])) { |
| 229 | return $data[static::THEME_DATA_LINK]; |
| 230 | } |
| 231 | |
| 232 | return 'http://taotesting.com'; |
| 233 | } |
| 234 | |
| 235 | /** |
| 236 | * Get the message of current theme |
| 237 | * Message is used in the header as title of the logo |
| 238 | * Message is used in the footer as footer message |
| 239 | * |
| 240 | * @return string |
| 241 | */ |
| 242 | public function getMessage() |
| 243 | { |
| 244 | $data = $this->getThemeData(); |
| 245 | if (isset($data[static::THEME_DATA_MESSAGE])) { |
| 246 | return $data[static::THEME_DATA_MESSAGE]; |
| 247 | } |
| 248 | |
| 249 | return ''; |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * Get the label of current theme |
| 254 | * Labels are useful in situations where you can choose between multiple themes |
| 255 | * |
| 256 | * @return string |
| 257 | */ |
| 258 | public function getLabel() |
| 259 | { |
| 260 | if ($this->hasOption(static::THEME_LABEL)) { |
| 261 | return $this->getOption(static::THEME_LABEL); |
| 262 | } |
| 263 | |
| 264 | return ''; |
| 265 | } |
| 266 | |
| 267 | /** |
| 268 | * Get the id of current theme |
| 269 | * IDs are used to register the theme |
| 270 | * |
| 271 | * @return string |
| 272 | */ |
| 273 | public function getId() |
| 274 | { |
| 275 | if ($this->hasOption(static::THEME_ID)) { |
| 276 | return $this->getOption(static::THEME_ID); |
| 277 | } |
| 278 | |
| 279 | return ''; |
| 280 | } |
| 281 | } |