Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
67.86% |
19 / 28 |
|
60.00% |
3 / 5 |
CRAP | |
0.00% |
0 / 1 |
| tao_helpers_form_xhtml_TagWrapper | |
67.86% |
19 / 28 |
|
60.00% |
3 / 5 |
20.51 | |
0.00% |
0 / 1 |
| preRender | |
100.00% |
11 / 11 |
|
100.00% |
1 / 1 |
5 | |||
| postRender | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
| getOption | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
12 | |||
| setOption | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| __construct | |
100.00% |
4 / 4 |
|
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) 2008-2010 (original work) Deutsche Institut für Internationale Pädagogische Forschung |
| 19 | * (under the project TAO-TRANSFER); |
| 20 | * 2009-2012 (update and modification) Public Research Centre Henri Tudor |
| 21 | * (under the project TAO-SUSTAIN & TAO-DEV); |
| 22 | * |
| 23 | */ |
| 24 | |
| 25 | /** |
| 26 | * This decorator wrap the decorated element inside a tag. |
| 27 | * Usually an xhtml tag. |
| 28 | * |
| 29 | * @access public |
| 30 | * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu> |
| 31 | * @package tao |
| 32 | |
| 33 | */ |
| 34 | class tao_helpers_form_xhtml_TagWrapper implements tao_helpers_form_Decorator |
| 35 | { |
| 36 | // --- ATTRIBUTES --- |
| 37 | |
| 38 | /** |
| 39 | * Short description of attribute tag |
| 40 | * |
| 41 | * @access protected |
| 42 | * @var string |
| 43 | */ |
| 44 | protected $tag = 'div'; |
| 45 | |
| 46 | protected $attributes = []; |
| 47 | |
| 48 | // --- OPERATIONS --- |
| 49 | |
| 50 | /** |
| 51 | * Short description of method preRender |
| 52 | * |
| 53 | * @access public |
| 54 | * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu> |
| 55 | * @return string |
| 56 | */ |
| 57 | public function preRender() |
| 58 | { |
| 59 | $returnValue = (string) ''; |
| 60 | |
| 61 | |
| 62 | if (!empty($this->tag)) { |
| 63 | $returnValue .= "<{$this->tag}"; |
| 64 | if (isset($this->attributes['cssClass'])) { |
| 65 | // legacy |
| 66 | $this->attributes['class'] = $this->attributes['cssClass'] . |
| 67 | (isset($this->attributes['class']) ? ' ' . $this->attributes['class'] : ''); |
| 68 | unset($this->attributes['cssClass']); |
| 69 | } |
| 70 | foreach ($this->attributes as $key => $value) { |
| 71 | $returnValue .= ' ' . $key . '=\'' . $value . '\' '; |
| 72 | } |
| 73 | $returnValue .= ">"; |
| 74 | } |
| 75 | return (string) $returnValue; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Short description of method postRender |
| 80 | * |
| 81 | * @access public |
| 82 | * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu> |
| 83 | * @return string |
| 84 | */ |
| 85 | public function postRender() |
| 86 | { |
| 87 | $returnValue = (string) ''; |
| 88 | |
| 89 | |
| 90 | if (!empty($this->tag)) { |
| 91 | $returnValue .= "</{$this->tag}>"; |
| 92 | } |
| 93 | |
| 94 | |
| 95 | return (string) $returnValue; |
| 96 | } |
| 97 | |
| 98 | /** |
| 99 | * Short description of method getOption |
| 100 | * |
| 101 | * @access public |
| 102 | * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu> |
| 103 | * @param string key |
| 104 | * @return string |
| 105 | */ |
| 106 | public function getOption($key) |
| 107 | { |
| 108 | if ($key == 'tag') { |
| 109 | return $this->tag; |
| 110 | } elseif (isset($this->attributes[$key])) { |
| 111 | return $this->attributes[$key]; |
| 112 | } else { |
| 113 | return ''; |
| 114 | } |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * Short description of method setOption |
| 119 | * |
| 120 | * @access public |
| 121 | * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu> |
| 122 | * @param string key |
| 123 | * @param string value |
| 124 | * @return boolean |
| 125 | */ |
| 126 | public function setOption($key, $value) |
| 127 | { |
| 128 | if ($key == 'tag') { |
| 129 | $this->tag = $value; |
| 130 | } else { |
| 131 | $this->attributes[$key] = $value; |
| 132 | } |
| 133 | return true; |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Short description of method __construct |
| 138 | * |
| 139 | * @access public |
| 140 | * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu> |
| 141 | * @param array options |
| 142 | * @return mixed |
| 143 | */ |
| 144 | public function __construct($options = []) |
| 145 | { |
| 146 | |
| 147 | if (isset($options['tag'])) { |
| 148 | $this->tag = $options['tag']; |
| 149 | unset($options['tag']); |
| 150 | } |
| 151 | $this->attributes = $options; |
| 152 | } |
| 153 | } |