Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 66 |
|
0.00% |
0 / 16 |
CRAP | |
0.00% |
0 / 1 |
| tao_helpers_grid_Column | |
0.00% |
0 / 66 |
|
0.00% |
0 / 16 |
870 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| setType | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| getType | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| setTitle | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| getTitle | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getId | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| setAdapter | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
6 | |||
| hasAdapter | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
20 | |||
| getAdaptersData | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
72 | |||
| getAdapter | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 | |||
| getOptions | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| setOptions | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getOption | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| setOption | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| removeAdapter | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getAdapters | |
0.00% |
0 / 3 |
|
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_Column |
| 27 | * |
| 28 | * @access public |
| 29 | * @author Somsack Sipasseuth, <somsack.sipasseuth@tudor.lu> |
| 30 | * @package tao |
| 31 | |
| 32 | */ |
| 33 | class tao_helpers_grid_Column |
| 34 | { |
| 35 | // --- ASSOCIATIONS --- |
| 36 | |
| 37 | |
| 38 | // --- ATTRIBUTES --- |
| 39 | |
| 40 | /** |
| 41 | * Short description of attribute id |
| 42 | * |
| 43 | * @access protected |
| 44 | * @var string |
| 45 | */ |
| 46 | protected $id = ''; |
| 47 | |
| 48 | /** |
| 49 | * Short description of attribute title |
| 50 | * |
| 51 | * @access protected |
| 52 | * @var string |
| 53 | */ |
| 54 | protected $title = ''; |
| 55 | |
| 56 | /** |
| 57 | * Short description of attribute type |
| 58 | * |
| 59 | * @access protected |
| 60 | * @var string |
| 61 | */ |
| 62 | protected $type = ''; |
| 63 | |
| 64 | /** |
| 65 | * Short description of attribute order |
| 66 | * |
| 67 | * @access protected |
| 68 | * @var int |
| 69 | */ |
| 70 | protected $order = 0; |
| 71 | |
| 72 | /** |
| 73 | * Short description of attribute adapters |
| 74 | * |
| 75 | * @access protected |
| 76 | * @var array |
| 77 | */ |
| 78 | protected $adapters = []; |
| 79 | |
| 80 | /** |
| 81 | * Short description of attribute options |
| 82 | * |
| 83 | * @access public |
| 84 | * @var array |
| 85 | */ |
| 86 | public $options = []; |
| 87 | |
| 88 | // --- OPERATIONS --- |
| 89 | |
| 90 | /** |
| 91 | * Short description of method __construct |
| 92 | * |
| 93 | * @access public |
| 94 | * @author Somsack Sipasseuth, <somsack.sipasseuth@tudor.lu> |
| 95 | * @param string id |
| 96 | * @param string title |
| 97 | * @param array options |
| 98 | * @return mixed |
| 99 | */ |
| 100 | public function __construct($id, $title, $options = []) |
| 101 | { |
| 102 | |
| 103 | $this->id = $id; |
| 104 | $this->title = $title; |
| 105 | $this->options = $options; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Short description of method setType |
| 110 | * |
| 111 | * @access public |
| 112 | * @author Somsack Sipasseuth, <somsack.sipasseuth@tudor.lu> |
| 113 | * @param string type |
| 114 | * @return boolean |
| 115 | */ |
| 116 | public function setType($type) |
| 117 | { |
| 118 | $returnValue = (bool) false; |
| 119 | |
| 120 | |
| 121 | $this->type = $type; |
| 122 | $returnValue = true; |
| 123 | |
| 124 | |
| 125 | return (bool) $returnValue; |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * Short description of method getType |
| 130 | * |
| 131 | * @access public |
| 132 | * @author Somsack Sipasseuth, <somsack.sipasseuth@tudor.lu> |
| 133 | * @return string |
| 134 | */ |
| 135 | public function getType() |
| 136 | { |
| 137 | $returnValue = (string) ''; |
| 138 | |
| 139 | |
| 140 | $returnValue = $this->type; |
| 141 | |
| 142 | |
| 143 | return (string) $returnValue; |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Short description of method setTitle |
| 148 | * |
| 149 | * @access public |
| 150 | * @author Somsack Sipasseuth, <somsack.sipasseuth@tudor.lu> |
| 151 | * @param string title |
| 152 | * @return boolean |
| 153 | */ |
| 154 | public function setTitle($title) |
| 155 | { |
| 156 | $returnValue = (bool) false; |
| 157 | |
| 158 | |
| 159 | $this->title = $title; |
| 160 | $returnValue = true; |
| 161 | |
| 162 | |
| 163 | return (bool) $returnValue; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Short description of method getTitle |
| 168 | * |
| 169 | * @access public |
| 170 | * @author Somsack Sipasseuth, <somsack.sipasseuth@tudor.lu> |
| 171 | * @return string |
| 172 | */ |
| 173 | public function getTitle() |
| 174 | { |
| 175 | $returnValue = (string) ''; |
| 176 | |
| 177 | |
| 178 | $returnValue = $this->title; |
| 179 | |
| 180 | |
| 181 | return (string) $returnValue; |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Short description of method getId |
| 186 | * |
| 187 | * @access public |
| 188 | * @author Somsack Sipasseuth, <somsack.sipasseuth@tudor.lu> |
| 189 | * @return string |
| 190 | */ |
| 191 | public function getId() |
| 192 | { |
| 193 | $returnValue = (string) ''; |
| 194 | |
| 195 | |
| 196 | $returnValue = $this->id; |
| 197 | |
| 198 | |
| 199 | return (string) $returnValue; |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * Short description of method setAdapter |
| 204 | * |
| 205 | * @access public |
| 206 | * @author Somsack Sipasseuth, <somsack.sipasseuth@tudor.lu> |
| 207 | * @param Adapter adapter |
| 208 | * @return boolean |
| 209 | */ |
| 210 | public function setAdapter(tao_helpers_grid_Cell_Adapter $adapter) |
| 211 | { |
| 212 | $returnValue = (bool) false; |
| 213 | |
| 214 | |
| 215 | if (!is_null($adapter)) { |
| 216 | $this->adapters[] = $adapter; |
| 217 | $returnValue = true; |
| 218 | } |
| 219 | |
| 220 | |
| 221 | return (bool) $returnValue; |
| 222 | } |
| 223 | |
| 224 | /** |
| 225 | * Short description of method hasAdapter |
| 226 | * |
| 227 | * @access public |
| 228 | * @author Somsack Sipasseuth, <somsack.sipasseuth@tudor.lu> |
| 229 | * @param string type (to check if the adaptor is of a certain type) |
| 230 | * @return boolean |
| 231 | */ |
| 232 | public function hasAdapter($type = '') |
| 233 | { |
| 234 | $returnValue = (bool) false; |
| 235 | |
| 236 | |
| 237 | $adapterClass = empty($type) ? 'tao_helpers_grid_Cell_Adapter' : $type; |
| 238 | foreach ($this->adapters as $adapter) { |
| 239 | if ($adapter instanceof $adapterClass) { |
| 240 | $returnValue = true; |
| 241 | break; |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | |
| 246 | |
| 247 | return (bool) $returnValue; |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * Short description of method getAdaptersData |
| 252 | * |
| 253 | * @access public |
| 254 | * @author Somsack Sipasseuth, <somsack.sipasseuth@tudor.lu> |
| 255 | * @param string rowId |
| 256 | * @param string cellValue (tao_helpers_grid_Grid, tao_helpers_grid_GridContainer or string) |
| 257 | * @param bool evaluateData |
| 258 | * @return mixed |
| 259 | */ |
| 260 | public function getAdaptersData($rowId, $cellValue = null, $evaluateData = true) |
| 261 | { |
| 262 | $returnValue = null; |
| 263 | |
| 264 | |
| 265 | |
| 266 | if ($this->hasAdapter()) { |
| 267 | foreach ($this->adapters as $adapter) { |
| 268 | if ($adapter instanceof tao_helpers_grid_Cell_Adapter) { |
| 269 | $cellValue = $adapter->getValue($rowId, $this->id, $cellValue); |
| 270 | } |
| 271 | } |
| 272 | $returnValue = $cellValue; |
| 273 | } |
| 274 | |
| 275 | if ($evaluateData) { |
| 276 | //allow returning to type "string" or "Grid" only |
| 277 | if ($returnValue instanceof tao_helpers_grid_Grid) { |
| 278 | $returnValue = $returnValue->toArray(); |
| 279 | } elseif ($returnValue instanceof tao_helpers_grid_GridContainer) { |
| 280 | $returnValue = $returnValue->toArray(); |
| 281 | } elseif (is_array($returnValue)) { |
| 282 | //ok; authorize array type |
| 283 | } else { |
| 284 | $returnValue = (string) $returnValue; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | |
| 289 | |
| 290 | return $returnValue; |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * Short description of method getAdapter |
| 295 | * |
| 296 | * @access public |
| 297 | * @author Somsack Sipasseuth, <somsack.sipasseuth@tudor.lu> |
| 298 | * @param type |
| 299 | * @return tao_helpers_transfert_Adapter |
| 300 | */ |
| 301 | public function getAdapter($type) |
| 302 | { |
| 303 | $returnValue = null; |
| 304 | |
| 305 | |
| 306 | foreach ($this->adapters as $adapter) { |
| 307 | if ($adapter instanceof $type) { |
| 308 | $returnValue = $adapter; |
| 309 | break; |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | |
| 314 | return $returnValue; |
| 315 | } |
| 316 | |
| 317 | /** |
| 318 | * Short description of method getOptions |
| 319 | * |
| 320 | * @access public |
| 321 | * @author Somsack Sipasseuth, <somsack.sipasseuth@tudor.lu> |
| 322 | * @return array |
| 323 | */ |
| 324 | public function getOptions() |
| 325 | { |
| 326 | $returnValue = []; |
| 327 | |
| 328 | |
| 329 | $returnValue = $this->options; |
| 330 | |
| 331 | |
| 332 | return (array) $returnValue; |
| 333 | } |
| 334 | |
| 335 | /** |
| 336 | * Short description of method setOptions |
| 337 | * |
| 338 | * @access public |
| 339 | * @author Somsack Sipasseuth, <somsack.sipasseuth@tudor.lu> |
| 340 | * @param array options |
| 341 | */ |
| 342 | public function setOptions($options) |
| 343 | { |
| 344 | |
| 345 | $this->options = array_merge($this->options, $options); |
| 346 | } |
| 347 | |
| 348 | /** |
| 349 | * Short description of method getOption |
| 350 | * |
| 351 | * @access public |
| 352 | * @author Somsack Sipasseuth, <somsack.sipasseuth@tudor.lu> |
| 353 | * @param name |
| 354 | * @return core_kernel_classes_object |
| 355 | */ |
| 356 | public function getOption($name) |
| 357 | { |
| 358 | $returnValue = null; |
| 359 | |
| 360 | |
| 361 | $returnValue = $this->options[$name]; |
| 362 | |
| 363 | |
| 364 | return $returnValue; |
| 365 | } |
| 366 | |
| 367 | /** |
| 368 | * Short description of method setOption |
| 369 | * |
| 370 | * @access public |
| 371 | * @author Somsack Sipasseuth, <somsack.sipasseuth@tudor.lu> |
| 372 | * @param name |
| 373 | * @param value |
| 374 | */ |
| 375 | public function setOption($name, $value) |
| 376 | { |
| 377 | |
| 378 | $this->options[$name] = $value; |
| 379 | } |
| 380 | |
| 381 | /** |
| 382 | * Short description of method removeAdapter |
| 383 | * |
| 384 | * @access public |
| 385 | * @author Somsack Sipasseuth, <somsack.sipasseuth@tudor.lu> |
| 386 | * @param string type |
| 387 | * @return boolean |
| 388 | */ |
| 389 | public function removeAdapter($type = '') |
| 390 | { |
| 391 | $returnValue = (bool) false; |
| 392 | |
| 393 | |
| 394 | |
| 395 | |
| 396 | return (bool) $returnValue; |
| 397 | } |
| 398 | |
| 399 | /** |
| 400 | * Short description of method getAdapters |
| 401 | * |
| 402 | * @access public |
| 403 | * @author Somsack Sipasseuth, <somsack.sipasseuth@tudor.lu> |
| 404 | * @return array |
| 405 | */ |
| 406 | public function getAdapters() |
| 407 | { |
| 408 | $returnValue = []; |
| 409 | |
| 410 | |
| 411 | $returnValue = $this->adapters; |
| 412 | |
| 413 | |
| 414 | return (array) $returnValue; |
| 415 | } |
| 416 | } |