| Code Coverage | ||||||||||
| Lines | Functions and Methods | Classes and Traits | ||||||||
| Total |  | 0.00% | 0 / 50 |  | 0.00% | 0 / 4 | CRAP |  | 0.00% | 0 / 1 | 
| tao_helpers_form_elements_xhtml_Checkbox |  | 0.00% | 0 / 50 |  | 0.00% | 0 / 4 | 240 |  | 0.00% | 0 / 1 | 
| feed |  | 0.00% | 0 / 5 |  | 0.00% | 0 / 1 | 12 | |||
| render |  | 0.00% | 0 / 43 |  | 0.00% | 0 / 1 | 110 | |||
| setValue |  | 0.00% | 0 / 1 |  | 0.00% | 0 / 1 | 2 | |||
| getEvaluatedValue |  | 0.00% | 0 / 1 |  | 0.00% | 0 / 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 | use oat\tao\helpers\form\elements\xhtml\XhtmlRenderingTrait; | 
| 26 | |
| 27 | /** | 
| 28 | * Short description of class tao_helpers_form_elements_xhtml_Checkbox | 
| 29 | * | 
| 30 | * @access public | 
| 31 | * @author Joel Bout, <joel.bout@tudor.lu> | 
| 32 | * @package tao | 
| 33 | */ | 
| 34 | class tao_helpers_form_elements_xhtml_Checkbox extends tao_helpers_form_elements_Checkbox | 
| 35 | { | 
| 36 | use XhtmlRenderingTrait; | 
| 37 | |
| 38 | /** | 
| 39 | * Short description of method feed | 
| 40 | * | 
| 41 | * @access public | 
| 42 | * @author Joel Bout, <joel.bout@tudor.lu> | 
| 43 | */ | 
| 44 | public function feed() | 
| 45 | { | 
| 46 | $expression = "/^" . preg_quote($this->name, "/") . "(.)*[0-9]+$/"; | 
| 47 | $this->setValues([]); | 
| 48 | foreach ($_POST as $key => $value) { | 
| 49 | if (preg_match($expression, $key)) { | 
| 50 | $this->addValue(tao_helpers_Uri::decode($value)); | 
| 51 | } | 
| 52 | } | 
| 53 | } | 
| 54 | |
| 55 | /** | 
| 56 | * Short description of method render | 
| 57 | * | 
| 58 | * @access public | 
| 59 | * @author Joel Bout, <joel.bout@tudor.lu> | 
| 60 | * @return string | 
| 61 | */ | 
| 62 | public function render() | 
| 63 | { | 
| 64 | $returnValue = $this->renderLabel(); | 
| 65 | |
| 66 | $checkAll = false; | 
| 67 | if (isset($this->attributes['checkAll'])) { | 
| 68 | $checkAll = (bool) $this->attributes['checkAll']; | 
| 69 | unset($this->attributes['checkAll']); | 
| 70 | } | 
| 71 | $i = 0; | 
| 72 | $checked = 0; | 
| 73 | $returnValue .= '<div class="form_radlst form_checklst plain">'; | 
| 74 | $readOnlyOptions = $this->getReadOnly(); | 
| 75 | foreach ($this->options as $optionId => $optionLabel) { | 
| 76 | $readOnly = isset($readOnlyOptions[$optionId]); | 
| 77 | if ($readOnly) { | 
| 78 | $returnValue .= '<div class="grid-row readonly">'; | 
| 79 | } else { | 
| 80 | $returnValue .= '<div class="grid-row">'; | 
| 81 | } | 
| 82 | |
| 83 | $returnValue .= '<div class="col-1">'; | 
| 84 | $returnValue .= "<input type='checkbox' value='{$optionId}' name='{$this->name}_{$i}' " | 
| 85 | . "id='{$this->name}_{$i}' data-testid='{$this->getDescription()}_{$i}' "; | 
| 86 | $returnValue .= $this->renderAttributes(); | 
| 87 | |
| 88 | if ($readOnly) { | 
| 89 | $returnValue .= "disabled='disabled' readonly='readonly' "; | 
| 90 | } | 
| 91 | |
| 92 | if (in_array($optionId, $this->values)) { | 
| 93 | $returnValue .= " checked='checked' "; | 
| 94 | $checked++; | 
| 95 | } | 
| 96 | $returnValue .= ' />'; | 
| 97 | $returnValue .= '</div><div class="col-10">'; | 
| 98 | $returnValue .= "<label class='elt_desc' for='{$this->name}_{$i}'>" . _dh($optionLabel) . "</label>"; | 
| 99 | $returnValue .= '</div><div class="col-1">'; | 
| 100 | if ($readOnly) { | 
| 101 | $readOnlyReason = $readOnlyOptions[$optionId]; | 
| 102 | if (!empty($readOnlyReason)) { | 
| 103 | $returnValue .= '<span class="tooltip-trigger icon-warning" data-tooltip="~ .tooltip-content" ' | 
| 104 | . 'data-tooltip-theme="info"></span><div class="tooltip-content">' . _dh($readOnlyReason) | 
| 105 | . '</div>'; | 
| 106 | } | 
| 107 | } | 
| 108 | $returnValue .= '</div></div>'; | 
| 109 | $i++; | 
| 110 | } | 
| 111 | $returnValue .= "</div>"; | 
| 112 | |
| 113 | // add a small link | 
| 114 | if ($checkAll) { | 
| 115 | if ($checked == (count($this->options) - count($readOnlyOptions))) { | 
| 116 | $returnValue .= "<span class='checker-container'><a id='{$this->name}_checker' " | 
| 117 | . "class='box-checker box-checker-uncheck' href='#'>" . __('Uncheck All') . "</a></span>"; | 
| 118 | } else { | 
| 119 | $returnValue .= "<span class='checker-container'><a id='{$this->name}_checker' class='box-checker' " | 
| 120 | . "href='#'>" . __('Check All') . "</a></span>"; | 
| 121 | } | 
| 122 | } | 
| 123 | |
| 124 | return (string) $returnValue; | 
| 125 | } | 
| 126 | |
| 127 | /** | 
| 128 | * Short description of method setValue | 
| 129 | * | 
| 130 | * @access public | 
| 131 | * @author Joel Bout, <joel.bout@tudor.lu> | 
| 132 | * @param string $value | 
| 133 | * @return mixed | 
| 134 | */ | 
| 135 | public function setValue($value) | 
| 136 | { | 
| 137 | $this->addValue($value); | 
| 138 | } | 
| 139 | |
| 140 | /** | 
| 141 | * Short description of method getEvaluatedValue | 
| 142 | * | 
| 143 | * @access public | 
| 144 | * @author Joel Bout, <joel.bout@tudor.lu> | 
| 145 | * @return array | 
| 146 | */ | 
| 147 | public function getEvaluatedValue() | 
| 148 | { | 
| 149 | return array_map("tao_helpers_Uri::decode", $this->getValues()); | 
| 150 | // return array_map("tao_helpers_Uri::decode", $this->getRawValue()); | 
| 151 | } | 
| 152 | } |