Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 34 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Choice | |
0.00% |
0 / 34 |
|
0.00% |
0 / 3 |
156 | |
0.00% |
0 / 1 |
| getUsedAttributes | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| getContent | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| setContent | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| isIdentifierAvailable | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
90 | |||
| toForm | |
0.00% |
0 / 8 |
|
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\choice; |
| 24 | |
| 25 | use oat\taoQtiItem\model\qti\IdentifiedElement; |
| 26 | use oat\taoQtiItem\model\qti\exception\QtiModelException; |
| 27 | |
| 28 | /** |
| 29 | * A choice is a kind of interaction's proposition. |
| 30 | * |
| 31 | * @access public |
| 32 | * @author Sam, <sam@taotesting.com> |
| 33 | * @package taoQTI |
| 34 | * @see http://www.imsglobal.org/question/qtiv2p1/imsqti_infov2p1.html#element10271 |
| 35 | |
| 36 | */ |
| 37 | abstract class Choice extends IdentifiedElement |
| 38 | { |
| 39 | protected function getUsedAttributes() |
| 40 | { |
| 41 | return [ |
| 42 | 'oat\\taoQtiItem\\model\\qti\\attribute\\Fixed', |
| 43 | 'oat\\taoQtiItem\\model\\qti\\attribute\\TemplateIdentifier', |
| 44 | 'oat\\taoQtiItem\\model\\qti\\attribute\\ShowHideChoice', |
| 45 | ]; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Common method to get the content of a choice. |
| 50 | * The return value is mostly a string, but could also be a oat\taoQtiItem\model\qti\QtiObject |
| 51 | * |
| 52 | * @return mixed |
| 53 | */ |
| 54 | abstract public function getContent(); |
| 55 | |
| 56 | /** |
| 57 | * Common method to se the content of a choice. |
| 58 | * The content type is mostly a String, but could also be a oat\taoQtiItem\model\qti\QtiObject |
| 59 | * or oat\taoQtiItem\model\qti\OutcomeDeclaration |
| 60 | * |
| 61 | * @param mixed content |
| 62 | */ |
| 63 | abstract public function setContent($content); |
| 64 | |
| 65 | /** |
| 66 | * Check if the given new identifier is valid in the current state of the qti element |
| 67 | * |
| 68 | * @param string $newIdentifier |
| 69 | * @return booean |
| 70 | * @throws InvalidArgumentException |
| 71 | */ |
| 72 | public function isIdentifierAvailable($newIdentifier) |
| 73 | { |
| 74 | |
| 75 | $returnValue = false; |
| 76 | |
| 77 | if (empty($newIdentifier) || is_null($newIdentifier)) { |
| 78 | throw new InvalidArgumentException("newIdentifier must be set"); |
| 79 | } |
| 80 | |
| 81 | if (!empty($this->identifier) && $newIdentifier == $this->identifier) { |
| 82 | $returnValue = true; |
| 83 | } else { |
| 84 | $relatedItem = $this->getRelatedItem(); |
| 85 | if (is_null($relatedItem)) { |
| 86 | $returnValue = true; //no restriction on identifier since not attached to any qti item |
| 87 | } else { |
| 88 | $collection = $relatedItem->getIdentifiedElements(); |
| 89 | |
| 90 | try { |
| 91 | $uniqueChoice = $collection->getUnique( |
| 92 | $newIdentifier, |
| 93 | 'oat\\taoQtiItem\\model\\qti\\choice\\Choice' |
| 94 | ); |
| 95 | $uniqueOutcome = $collection->getUnique( |
| 96 | $newIdentifier, |
| 97 | 'oat\\taoQtiItem\\model\\qti\\OutcomeDeclaration' |
| 98 | ); |
| 99 | |
| 100 | if (is_null($uniqueChoice) && is_null($uniqueOutcome)) { |
| 101 | $returnValue = true; |
| 102 | } |
| 103 | } catch (QtiModelException $e) { |
| 104 | //return false |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | return $returnValue; |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Return the form to edit the current instance |
| 114 | * |
| 115 | * @access public |
| 116 | * @author Bertrand Chevrier, <bertrand.chevrier@tudor.lu> |
| 117 | * @return tao_helpers_form_Form |
| 118 | */ |
| 119 | public function toForm() |
| 120 | { |
| 121 | $returnValue = null; |
| 122 | |
| 123 | $choiceFormClass = '\\oat\\taoQtiItem\\controller\\QTIform\\choice\\' . ucfirst(static::$qtiTagName); |
| 124 | if (!class_exists($choiceFormClass)) { |
| 125 | throw new QtiModelException("the class {$choiceFormClass} does not exist"); |
| 126 | } else { |
| 127 | $formContainer = new $choiceFormClass($this); |
| 128 | $myForm = $formContainer->getForm(); |
| 129 | $returnValue = $myForm; |
| 130 | } |
| 131 | |
| 132 | return $returnValue; |
| 133 | } |
| 134 | } |