Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| Enumeration | |
0.00% |
0 / 11 |
|
0.00% |
0 / 4 |
56 | |
0.00% |
0 / 1 |
| validate | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| fix | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
| getEnumeration | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setValue | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| 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) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | namespace oat\taoQtiItem\model\qti\datatype; |
| 24 | |
| 25 | use oat\taoQtiItem\model\qti\datatype\Enumeration; |
| 26 | use oat\taoQtiItem\model\qti\datatype\Datatype; |
| 27 | use oat\taoQtiItem\model\qti\exception\QtiModelException; |
| 28 | |
| 29 | /** |
| 30 | * Enumeration is a data type that contains a precise list of values |
| 31 | * |
| 32 | * @access public |
| 33 | * @author Sam, <sam@taotesting.com> |
| 34 | * @package taoQTI |
| 35 | |
| 36 | */ |
| 37 | abstract class Enumeration extends Datatype |
| 38 | { |
| 39 | public static function validate($value) |
| 40 | { |
| 41 | return (bool)in_array($value, static::getEnumeration()); |
| 42 | } |
| 43 | |
| 44 | public static function fix($value) |
| 45 | { |
| 46 | |
| 47 | $returnValue = null; |
| 48 | |
| 49 | $enum = static::getEnumeration(); |
| 50 | foreach ($enum as $element) { |
| 51 | if (strcasecmp($value, $element) == 0) { |
| 52 | $returnValue = $element; |
| 53 | break; |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | return $returnValue; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Returns the array enumeration all available elements |
| 62 | * |
| 63 | * @return array |
| 64 | */ |
| 65 | public static function getEnumeration() |
| 66 | { |
| 67 | throw new QtiModelException('Method to be implemented by and called from inherited classes'); |
| 68 | } |
| 69 | |
| 70 | public function setValue($value) |
| 71 | { |
| 72 | if (!empty($value)) { |
| 73 | parent::setValue($value); |
| 74 | } |
| 75 | } |
| 76 | } |