Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
ItemUpdateInlineFeedback | |
0.00% |
0 / 26 |
|
0.00% |
0 / 1 |
90 | |
0.00% |
0 / 1 |
updateItem | |
0.00% |
0 / 26 |
|
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 InlineModalFeedbackItemUpdate |
26 | * |
27 | * @author sam |
28 | */ |
29 | class ItemUpdateInlineFeedback extends ItemUpdater |
30 | { |
31 | /** |
32 | * Update the item content by wrapping the modalfeedback body into a new wrapper |
33 | * |
34 | * @param oat\taoQtiItem\modal\Item $item |
35 | * @param string $itemFile |
36 | * @return boolean |
37 | */ |
38 | protected function updateItem(\oat\taoQtiItem\model\qti\Item $item, $itemFile) |
39 | { |
40 | $changed = false; |
41 | $responses = $item->getResponses(); |
42 | |
43 | foreach ($responses as $response) { |
44 | $responseIdentifier = $response->attr('identifier'); |
45 | $rules = $response->getFeedbackRules(); |
46 | |
47 | foreach ($rules as $rule) { |
48 | $modalFeedbacks = []; |
49 | if ($rule->getFeedbackThen()) { |
50 | $modalFeedbacks[] = $rule->getFeedbackThen(); |
51 | } |
52 | if ($rule->getFeedbackElse()) { |
53 | $modalFeedbacks[] = $rule->getFeedbackElse(); |
54 | } |
55 | foreach ($modalFeedbacks as $modalFeedback) { |
56 | $feedbackXml = simplexml_load_string($modalFeedback->toQti()); |
57 | if ( |
58 | $feedbackXml->div[0] && $feedbackXml->div[0]['class'] && preg_match( |
59 | '/^x-tao-wrapper/', |
60 | $feedbackXml->div[0]['class'] |
61 | ) |
62 | ) { |
63 | // the item body has not already been wrapped by the new wrapper |
64 | // <div class="x-tao-wrapper w-tao-relatedOutcome-{{response.identifier}}"> |
65 | continue; |
66 | } |
67 | $message = $modalFeedback->getBody()->getBody(); |
68 | $modalFeedback->getBody()->edit( |
69 | '<div class="x-tao-wrapper x-tao-relatedOutcome-' . $responseIdentifier . '">' . $message |
70 | . '</div>', |
71 | true |
72 | ); |
73 | $changed = true; |
74 | } |
75 | } |
76 | } |
77 | |
78 | return $changed; |
79 | } |
80 | } |