Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 29 |
|
0.00% |
0 / 6 |
CRAP | |
0.00% |
0 / 1 |
| Feedback | |
0.00% |
0 / 29 |
|
0.00% |
0 / 6 |
182 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getBody | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getUsedAttributes | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| isIdentifierAvailable | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
56 | |||
| toArray | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
| toFilteredArray | |
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) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | */ |
| 20 | |
| 21 | namespace oat\taoQtiItem\model\qti\feedback; |
| 22 | |
| 23 | use InvalidArgumentException; |
| 24 | use oat\taoQtiItem\model\qti\IdentifiedElement; |
| 25 | use oat\taoQtiItem\model\qti\container\FlowContainer; |
| 26 | use oat\taoQtiItem\model\qti\Item; |
| 27 | use oat\taoQtiItem\model\qti\container\ContainerStatic; |
| 28 | use oat\taoQtiItem\model\qti\exception\QtiModelException; |
| 29 | use oat\taoQtiItem\model\qti\ContentVariable; |
| 30 | use oat\taoQtiItem\model\qti\attribute\OutcomeIdentifier; |
| 31 | use oat\taoQtiItem\model\qti\attribute\ShowHideTemplateElement; |
| 32 | |
| 33 | /** |
| 34 | * The QTI_Feedback object represent one of the three available feedbackElements |
| 35 | * (feedbackInline, feedbackBlock, feedbackModal |
| 36 | * |
| 37 | * @access public |
| 38 | * @author Sam Sipasseuth, <sam.sipasseuth@taotesting.com> |
| 39 | * @package taoQTI |
| 40 | * @see http://www.imsglobal.org/question/qtiv2p1/imsqti_infov2p1.html#element10243 |
| 41 | */ |
| 42 | abstract class Feedback extends IdentifiedElement implements FlowContainer, ContentVariable |
| 43 | { |
| 44 | protected $body; |
| 45 | |
| 46 | /** |
| 47 | * Feedback constructor. |
| 48 | * |
| 49 | * @param array $attributes |
| 50 | * @param Item|null $relatedItem |
| 51 | * @param string $serial |
| 52 | * |
| 53 | * @throws QtiModelException |
| 54 | */ |
| 55 | public function __construct($attributes = [], Item $relatedItem = null, $serial = '') |
| 56 | { |
| 57 | parent::__construct($attributes, $relatedItem, $serial); |
| 58 | $this->body = new ContainerStatic('', $relatedItem); //@todo: implement interactive container |
| 59 | } |
| 60 | |
| 61 | public function getBody() |
| 62 | { |
| 63 | return $this->body; |
| 64 | } |
| 65 | |
| 66 | protected function getUsedAttributes() |
| 67 | { |
| 68 | return [ |
| 69 | OutcomeIdentifier::class, |
| 70 | ShowHideTemplateElement::class |
| 71 | ]; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Check if the given new identifier is valid in the current state of the qti element |
| 76 | * |
| 77 | * @param string $newIdentifier |
| 78 | * @return bool |
| 79 | * @throws InvalidArgumentException |
| 80 | */ |
| 81 | public function isIdentifierAvailable($newIdentifier) |
| 82 | { |
| 83 | if (empty($newIdentifier) || is_null($newIdentifier)) { |
| 84 | throw new InvalidArgumentException("newIdentifier must be set"); |
| 85 | } |
| 86 | |
| 87 | if (!empty($this->identifier) && $newIdentifier === $this->identifier) { |
| 88 | return true; |
| 89 | } |
| 90 | |
| 91 | $relatedItem = $this->getRelatedItem(); |
| 92 | |
| 93 | if (is_null($relatedItem)) { |
| 94 | return true; // no restriction on identifier since not attached to any qti item |
| 95 | } |
| 96 | |
| 97 | $collection = $relatedItem->getIdentifiedElements(); |
| 98 | |
| 99 | try { |
| 100 | return null === $collection->getUnique($newIdentifier, self::class); |
| 101 | } catch (QtiModelException $e) { |
| 102 | } |
| 103 | |
| 104 | return false; |
| 105 | } |
| 106 | |
| 107 | public function toArray($filterVariableContent = false, &$filtered = []) |
| 108 | { |
| 109 | $data = parent::toArray($filterVariableContent, $filtered); |
| 110 | |
| 111 | if ($filterVariableContent) { |
| 112 | $filtered[$this->getSerial()] = $data; |
| 113 | $data = [ |
| 114 | 'serial' => $data['serial'], |
| 115 | 'qtiClass' => $data['qtiClass'] |
| 116 | ]; |
| 117 | } |
| 118 | |
| 119 | return $data; |
| 120 | } |
| 121 | |
| 122 | public function toFilteredArray() |
| 123 | { |
| 124 | return $this->toArray(true); |
| 125 | } |
| 126 | } |