Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 43 |
|
0.00% |
0 / 7 |
CRAP | |
0.00% |
0 / 1 |
| tao_helpers_grid_GridContainer | |
0.00% |
0 / 43 |
|
0.00% |
0 / 7 |
342 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
12 | |||
| __destruct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| getGrid | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| initGrid | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| initColumns | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| toArray | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| initOptions | |
0.00% |
0 / 22 |
|
0.00% |
0 / 1 |
90 | |||
| __clone | |
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 | /** |
| 26 | * Short description of class tao_helpers_grid_GridContainer |
| 27 | * |
| 28 | * @abstract |
| 29 | * @access public |
| 30 | * @author Somsack Sipasseuth, <somsack.sipasseuth@tudor.lu> |
| 31 | * @package tao |
| 32 | |
| 33 | */ |
| 34 | abstract class tao_helpers_grid_GridContainer |
| 35 | { |
| 36 | // --- ASSOCIATIONS --- |
| 37 | |
| 38 | |
| 39 | // --- ATTRIBUTES --- |
| 40 | |
| 41 | /** |
| 42 | * Short description of attribute grid |
| 43 | * |
| 44 | * @access protected |
| 45 | * @var Grid |
| 46 | */ |
| 47 | protected $grid = null; |
| 48 | |
| 49 | /** |
| 50 | * Short description of attribute grids |
| 51 | * |
| 52 | * @access protected |
| 53 | * @var array |
| 54 | */ |
| 55 | protected static $grids = []; |
| 56 | |
| 57 | /** |
| 58 | * Short description of attribute options |
| 59 | * |
| 60 | * @access protected |
| 61 | * @var array |
| 62 | */ |
| 63 | protected $options = []; |
| 64 | |
| 65 | /** |
| 66 | * Short description of attribute data |
| 67 | * |
| 68 | * @access protected |
| 69 | * @var array |
| 70 | */ |
| 71 | protected $data = []; |
| 72 | |
| 73 | /** |
| 74 | * Short description of attribute excludedProperties |
| 75 | * |
| 76 | * @access protected |
| 77 | * @var array |
| 78 | */ |
| 79 | protected $excludedProperties = []; |
| 80 | |
| 81 | // --- OPERATIONS --- |
| 82 | |
| 83 | /** |
| 84 | * Short description of method __construct |
| 85 | * |
| 86 | * @access public |
| 87 | * @author Somsack Sipasseuth, <somsack.sipasseuth@tudor.lu> |
| 88 | * @param array data |
| 89 | * @param array options |
| 90 | * @return mixed |
| 91 | */ |
| 92 | public function __construct($data = [], $options = []) |
| 93 | { |
| 94 | |
| 95 | |
| 96 | $this->data = $data; |
| 97 | $this->options = $options; |
| 98 | $this->excludedProperties = (is_array($this->options) && isset($this->options['excludedProperties'])) |
| 99 | ? $this->options['excludedProperties'] |
| 100 | : []; |
| 101 | $this->grid = new tao_helpers_grid_Grid($options); |
| 102 | |
| 103 | //init columns ... |
| 104 | $this->initGrid(); |
| 105 | $this->initColumns(); |
| 106 | $this->initOptions($options); |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Short description of method __destruct |
| 111 | * |
| 112 | * @access public |
| 113 | * @author Somsack Sipasseuth, <somsack.sipasseuth@tudor.lu> |
| 114 | * @return mixed |
| 115 | */ |
| 116 | public function __destruct() |
| 117 | { |
| 118 | |
| 119 | if (!is_null($this->grid)) { |
| 120 | //remove the refs of the contained grid |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | /** |
| 125 | * Short description of method getGrid |
| 126 | * |
| 127 | * @access public |
| 128 | * @author Somsack Sipasseuth, <somsack.sipasseuth@tudor.lu> |
| 129 | * @return tao_helpers_grid_Grid |
| 130 | */ |
| 131 | public function getGrid() |
| 132 | { |
| 133 | $returnValue = null; |
| 134 | |
| 135 | |
| 136 | $returnValue = $this->grid; |
| 137 | |
| 138 | |
| 139 | return $returnValue; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Short description of method initGrid |
| 144 | * |
| 145 | * @access protected |
| 146 | * @author Somsack Sipasseuth, <somsack.sipasseuth@tudor.lu> |
| 147 | * @return boolean |
| 148 | */ |
| 149 | protected function initGrid() |
| 150 | { |
| 151 | $returnValue = (bool) false; |
| 152 | |
| 153 | |
| 154 | |
| 155 | //set data if data given |
| 156 | $returnValue = $this->grid->setData($this->data); |
| 157 | |
| 158 | |
| 159 | |
| 160 | return (bool) $returnValue; |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Short description of method initColumns |
| 165 | * |
| 166 | * @abstract |
| 167 | * @access protected |
| 168 | * @author Somsack Sipasseuth, <somsack.sipasseuth@tudor.lu> |
| 169 | * @return boolean |
| 170 | */ |
| 171 | abstract protected function initColumns(); |
| 172 | |
| 173 | /** |
| 174 | * Short description of method toArray |
| 175 | * |
| 176 | * @access public |
| 177 | * @author Somsack Sipasseuth, <somsack.sipasseuth@tudor.lu> |
| 178 | * @return array |
| 179 | */ |
| 180 | public function toArray() |
| 181 | { |
| 182 | $returnValue = []; |
| 183 | |
| 184 | |
| 185 | $returnValue = $this->grid->toArray(); |
| 186 | |
| 187 | |
| 188 | return (array) $returnValue; |
| 189 | } |
| 190 | |
| 191 | /** |
| 192 | * Short description of method initOptions |
| 193 | * |
| 194 | * @access public |
| 195 | * @author Somsack Sipasseuth, <somsack.sipasseuth@tudor.lu> |
| 196 | * @return boolean |
| 197 | */ |
| 198 | public function initOptions($options = []) |
| 199 | { |
| 200 | $returnValue = (bool) false; |
| 201 | |
| 202 | |
| 203 | |
| 204 | $columns = $this->grid->getColumns(); |
| 205 | if (isset($options['columns'])) { |
| 206 | foreach ($options['columns'] as $columnId => $columnOptions) { |
| 207 | if (isset($columns[$columnId])) { |
| 208 | foreach ($columnOptions as $optionsName => $optionsValue) { |
| 209 | if ($optionsName == 'columns') { |
| 210 | //if the options is columns, the options will be used to augment the subgrid model |
| 211 | $columns = $this->grid->getColumns(); |
| 212 | $subGridAdapter = null; |
| 213 | //get the last subgrid adapter which defines the column |
| 214 | $adapters = $columns[$columnId]->getAdapters(); |
| 215 | $adaptersLength = count($adapters); |
| 216 | for ($i = $adaptersLength - 1; $i >= 0; $i--) { |
| 217 | if ($adapters[$i] instanceof tao_helpers_grid_Cell_SubgridAdapter) { |
| 218 | $subGridAdapter = $adapters[$i]; |
| 219 | break; |
| 220 | } |
| 221 | } |
| 222 | if (is_null($subGridAdapter)) { |
| 223 | throw new Exception(__('The column ') . $columnId . __(' requires a subgrid adapter')); |
| 224 | } |
| 225 | //init options of the subgrid |
| 226 | $subGridAdapter->getGridContainer()->initOptions($columnOptions); |
| 227 | |
| 228 | continue; |
| 229 | } |
| 230 | $columns[$columnId]->setOption($optionsName, $optionsValue); |
| 231 | } |
| 232 | } |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | |
| 237 | return (bool) $returnValue; |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * Short description of method __clone |
| 242 | * |
| 243 | * @access public |
| 244 | * @author Somsack Sipasseuth, <somsack.sipasseuth@tudor.lu> |
| 245 | * @return mixed |
| 246 | */ |
| 247 | public function __clone() |
| 248 | { |
| 249 | |
| 250 | $this->grid = clone $this->grid; |
| 251 | } |
| 252 | } |