Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ItemFixGhostResponse | |
0.00% |
0 / 21 |
|
0.00% |
0 / 1 |
90 | |
0.00% |
0 / 1 |
| updateItem | |
0.00% |
0 / 21 |
|
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\taoQtiItem\model\update; |
| 23 | |
| 24 | /** |
| 25 | * Description of ItemFixGhostResponse |
| 26 | * |
| 27 | * @author sam |
| 28 | */ |
| 29 | class ItemFixGhostResponse extends ItemUpdater |
| 30 | { |
| 31 | private $templates = [ |
| 32 | 'http://www.imsglobal.org/question/qti_v2p1/rptemplates/match_correct', |
| 33 | 'http://www.imsglobal.org/question/qti_v2p1/rptemplates/map_response', |
| 34 | 'http://www.imsglobal.org/question/qti_v2p1/rptemplates/map_response_point' |
| 35 | ]; |
| 36 | |
| 37 | /** |
| 38 | * Remove unused response declaration from the items and rp template misuse |
| 39 | * |
| 40 | * @param oat\taoQtiItem\modal\Item $item |
| 41 | * @param string $itemFile |
| 42 | * @return boolean |
| 43 | */ |
| 44 | protected function updateItem(\oat\taoQtiItem\model\qti\Item $item, $itemFile) |
| 45 | { |
| 46 | $changed = false; |
| 47 | $responses = $item->getResponses(); |
| 48 | $interactions = $item->getInteractions(); |
| 49 | $usedResponses = []; |
| 50 | foreach ($interactions as $interaction) { |
| 51 | $usedResponses[] = $interaction->attr('responseIdentifier'); |
| 52 | } |
| 53 | foreach ($responses as $response) { |
| 54 | $responseIdentifier = $response->attr('identifier'); |
| 55 | if (!in_array($responseIdentifier, $usedResponses)) { |
| 56 | $changed = true; |
| 57 | $item->removeResponse($response); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | $xml = simplexml_load_file($itemFile); |
| 62 | $rpTemplate = (string) $xml->responseProcessing['template']; |
| 63 | |
| 64 | //detect wrong usage for standard standard response declaration |
| 65 | $rp = $item->getResponseProcessing(); |
| 66 | if ($rp instanceof \oat\taoQtiItem\model\qti\response\TemplatesDriven && $rpTemplate) { |
| 67 | if (count($interactions) > 1) { |
| 68 | $changed = true; |
| 69 | } else { |
| 70 | $interaction = reset($interactions); |
| 71 | if ($interaction && $interaction->attr('responseIdentifier') != 'RESPONSE') { |
| 72 | $changed = true; |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | return $changed; |
| 78 | } |
| 79 | } |