Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| RendererTrait | |
100.00% |
8 / 8 |
|
100.00% |
4 / 4 |
6 | |
100.00% |
1 / 1 |
| getRenderer | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| setView | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| setData | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| hasView | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| 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) 2019 (original work) Open Assessment Technologies SA; |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\tao\model\mvc; |
| 23 | |
| 24 | use Renderer; |
| 25 | |
| 26 | trait RendererTrait |
| 27 | { |
| 28 | /** |
| 29 | * @var Renderer The renderer engine to display view |
| 30 | */ |
| 31 | protected $renderer; |
| 32 | |
| 33 | public function getRenderer() |
| 34 | { |
| 35 | if (!isset($this->renderer)) { |
| 36 | $this->renderer = new Renderer(); |
| 37 | } |
| 38 | return $this->renderer; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Helper to set renderer view |
| 43 | * |
| 44 | * @param $identifier |
| 45 | * @return $this |
| 46 | */ |
| 47 | public function setView($identifier) |
| 48 | { |
| 49 | $this->getRenderer()->setTemplate($identifier); |
| 50 | return $this; |
| 51 | } |
| 52 | |
| 53 | |
| 54 | /** |
| 55 | * Helper to set renderer data |
| 56 | * |
| 57 | * @param $key |
| 58 | * @param $value |
| 59 | * @return $this |
| 60 | */ |
| 61 | public function setData($key, $value) |
| 62 | { |
| 63 | $this->getRenderer()->setData($key, $value); |
| 64 | return $this; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Check if the renderer has a view |
| 69 | * |
| 70 | * @return bool |
| 71 | */ |
| 72 | public function hasView() |
| 73 | { |
| 74 | return isset($this->renderer) && $this->renderer->hasTemplate(); |
| 75 | } |
| 76 | } |