Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 31 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Hotspot | |
0.00% |
0 / 31 |
|
0.00% |
0 / 3 |
210 | |
0.00% |
0 / 1 |
| setContent | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getContent | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| validateCoords | |
0.00% |
0 / 29 |
|
0.00% |
0 / 1 |
156 | |||
| 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\choice; |
| 24 | |
| 25 | use oat\taoQtiItem\model\qti\choice\Hotspot; |
| 26 | use oat\taoQtiItem\model\qti\choice\Choice; |
| 27 | |
| 28 | /** |
| 29 | * QTI Hotspot definition |
| 30 | * |
| 31 | * @access public |
| 32 | * @author Sam, <sam@taotesting.com> |
| 33 | * @package taoQTI |
| 34 | |
| 35 | */ |
| 36 | abstract class Hotspot extends Choice |
| 37 | { |
| 38 | public function setContent($content) |
| 39 | { |
| 40 | $this->setAttribute('shape', $content); |
| 41 | } |
| 42 | |
| 43 | public function getContent() |
| 44 | { |
| 45 | return $this->getAttibute('shape'); |
| 46 | } |
| 47 | |
| 48 | public function validateCoords($newAttributes = []) |
| 49 | { |
| 50 | |
| 51 | $returnValue = true; |
| 52 | |
| 53 | $shape = ''; |
| 54 | if (isset($newAttributes['shape'])) { |
| 55 | $shape = $newAttributes['shape']; |
| 56 | } else { |
| 57 | $s = $this->getAttibute('shape'); |
| 58 | if (!empty($s)) { |
| 59 | $shape = $s; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | if (isset($newAttributes['coords'])) { |
| 64 | $coords = $newAttributes['coords']; |
| 65 | if (is_array($coords)) { |
| 66 | //ok |
| 67 | } elseif (is_string($coords)) { |
| 68 | $coords = explode($coords, ','); |
| 69 | } else { |
| 70 | throw new InvalidArgumentException('the attribute "coords" is not in the right format'); |
| 71 | } |
| 72 | |
| 73 | if (empty($shape)) { |
| 74 | //validate coord format against shape type: |
| 75 | switch ($shape) { |
| 76 | case 'rect': |
| 77 | $returnValue = (count($coords) === 4); |
| 78 | break; |
| 79 | case 'circle': |
| 80 | $returnValue = (count($coords) === 3); |
| 81 | break; |
| 82 | case 'ellipse': |
| 83 | $returnValue = (count($coords) === 4); |
| 84 | break; |
| 85 | case 'poly': |
| 86 | $returnValue = (count($coords) % 2 === 0); |
| 87 | break; |
| 88 | default: |
| 89 | break; |
| 90 | } |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | return $returnValue; |
| 95 | } |
| 96 | } |