Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 42 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ResponseRuleParserFactory | |
0.00% |
0 / 42 |
|
0.00% |
0 / 2 |
240 | |
0.00% |
0 / 1 |
| buildResponseRule | |
0.00% |
0 / 18 |
|
0.00% |
0 / 1 |
42 | |||
| buildResponseCondition | |
0.00% |
0 / 24 |
|
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) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | * |
| 20 | * |
| 21 | */ |
| 22 | |
| 23 | namespace oat\taoQtiItem\model\qti\response; |
| 24 | |
| 25 | use oat\taoQtiItem\model\qti\response\ResponseRuleParserFactory; |
| 26 | use oat\taoQtiItem\model\qti\response\ExitResponse; |
| 27 | use oat\taoQtiItem\model\qti\expression\ExpressionParserFactory; |
| 28 | use oat\taoQtiItem\model\qti\response\SetOutcomeVariable; |
| 29 | use oat\taoQtiItem\model\qti\exception\ParsingException; |
| 30 | use oat\taoQtiItem\model\qti\response\ResponseCondition; |
| 31 | use SimpleXMLElement; |
| 32 | |
| 33 | /** |
| 34 | * Short description of class |
| 35 | * |
| 36 | * @access public |
| 37 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 38 | * @package taoQTI |
| 39 | |
| 40 | */ |
| 41 | class ResponseRuleParserFactory |
| 42 | { |
| 43 | /** |
| 44 | * Short description of method buildResponseRule |
| 45 | * |
| 46 | * @access public |
| 47 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 48 | * @param SimpleXMLElement data |
| 49 | * @return oat\taoQtiItem\model\qti\response\ResponseRule |
| 50 | */ |
| 51 | public static function buildResponseRule(SimpleXMLElement $data) |
| 52 | { |
| 53 | $returnValue = null; |
| 54 | |
| 55 | switch ($data->getName()) { |
| 56 | case 'exitResponse': |
| 57 | $returnValue = new ExitResponse(); |
| 58 | break; |
| 59 | case 'setOutcomeValue': |
| 60 | $identifier = (string)$data['identifier']; |
| 61 | $children = []; |
| 62 | foreach ($data->children() as $child) { |
| 63 | $children[] = $child; |
| 64 | } |
| 65 | $expression = ExpressionParserFactory::build(array_shift($children)); |
| 66 | $returnValue = new SetOutcomeVariable($identifier, $expression); |
| 67 | break; |
| 68 | case 'responseCondition': |
| 69 | $returnValue = self::buildResponseCondition($data); |
| 70 | break; |
| 71 | default: |
| 72 | throw new ParsingException('unknwown element ' . $data->getName() . ' in ResponseProcessing'); |
| 73 | } |
| 74 | |
| 75 | return $returnValue; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Short description of method buildResponseCondition |
| 80 | * |
| 81 | * @access private |
| 82 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 83 | * @param SimpleXMLElement data |
| 84 | * @return oat\taoQtiItem\model\qti\response\ResponseCondition |
| 85 | */ |
| 86 | private static function buildResponseCondition(SimpleXMLElement $data) |
| 87 | { |
| 88 | $responseCondition = new ResponseCondition(); |
| 89 | |
| 90 | foreach ($data->children() as $child) { |
| 91 | switch ($child->getName()) { |
| 92 | case 'responseIf': |
| 93 | case 'responseElseIf': |
| 94 | $subchildren = null; |
| 95 | foreach ($child->children() as $subchild) { |
| 96 | $subchildren[] = $subchild; |
| 97 | } |
| 98 | |
| 99 | // first node is condition |
| 100 | $conditionNode = array_shift($subchildren); |
| 101 | $condition = ExpressionParserFactory::build($conditionNode); |
| 102 | |
| 103 | // all the other nodes are action |
| 104 | $responseRules = []; |
| 105 | foreach ($subchildren as $responseRule) { |
| 106 | $responseRules[] = self::buildResponseRule($responseRule); |
| 107 | } |
| 108 | $responseCondition->addResponseIf($condition, $responseRules); |
| 109 | |
| 110 | break; |
| 111 | |
| 112 | case 'responseElse': |
| 113 | $responseRules = []; |
| 114 | foreach ($child->children() as $responseRule) { |
| 115 | $responseRules[] = self::buildResponseRule($responseRule); |
| 116 | } |
| 117 | $responseCondition->setResponseElse($responseRules); |
| 118 | break; |
| 119 | |
| 120 | default: |
| 121 | throw new ParsingException('unknown node in ResponseCondition'); |
| 122 | } |
| 123 | } |
| 124 | |
| 125 | $returnValue = $responseCondition; |
| 126 | |
| 127 | return $returnValue; |
| 128 | } |
| 129 | } |