Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ItemFixTextReaderDefaultValue | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
90 | |
0.00% |
0 / 1 |
| updateItem | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
90 | |||
| 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) 2016 (original work) Open Assessment Technologies SA ; |
| 19 | * |
| 20 | */ |
| 21 | |
| 22 | namespace oat\pciSamples\model\update; |
| 23 | |
| 24 | use oat\taoQtiItem\model\update\ItemUpdater; |
| 25 | use oat\taoQtiItem\model\qti\Item; |
| 26 | use oat\taoQtiItem\model\qti\Value; |
| 27 | use oat\taoQtiItem\model\qti\interaction\PortableCustomInteraction; |
| 28 | |
| 29 | /** |
| 30 | * Description of ItemFixTextReaderDefaultValue |
| 31 | * |
| 32 | * @author sam |
| 33 | */ |
| 34 | class ItemFixTextReaderDefaultValue extends ItemUpdater |
| 35 | { |
| 36 | /** |
| 37 | * Remove unused response declaration from the items and rp template misuse |
| 38 | * |
| 39 | * @param oat\taoQtiItem\modal\Item $item |
| 40 | * @param string $itemFile |
| 41 | * @return boolean |
| 42 | */ |
| 43 | protected function updateItem(Item $item, $itemFile) |
| 44 | { |
| 45 | $changed = false; |
| 46 | $requireFix = false; |
| 47 | $interactions = $item->getInteractions(); |
| 48 | foreach ($interactions as $interaction) { |
| 49 | if ( |
| 50 | $interaction instanceof PortableCustomInteraction |
| 51 | && $interaction->getTypeIdentifier() === 'textReaderInteraction' |
| 52 | ) { |
| 53 | $response = $interaction->getResponse(); |
| 54 | $currentDefaultVal = $response->getDefaultValue(); |
| 55 | |
| 56 | if (!is_array($currentDefaultVal) || empty($currentDefaultVal) || count($currentDefaultVal) !== 1) { |
| 57 | $requireFix = true; |
| 58 | } else { |
| 59 | $val = $currentDefaultVal[0]; |
| 60 | $requireFix = !($val instanceof Value && $val->getValue() === 'true'); |
| 61 | } |
| 62 | |
| 63 | if ($requireFix) { |
| 64 | $defaultValue = new Value(); |
| 65 | $defaultValue->setValue('true'); |
| 66 | $response->setDefaultValue([$defaultValue]); |
| 67 | $changed = true; |
| 68 | } |
| 69 | } |
| 70 | } |
| 71 | return $changed; |
| 72 | } |
| 73 | } |