Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ExpressionParserFactory | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
30 | |
0.00% |
0 / 1 |
| build | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
30 | |||
| 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\expression; |
| 24 | |
| 25 | use oat\taoQtiItem\model\qti\expression\ExpressionParserFactory; |
| 26 | use oat\taoQtiItem\model\qti\expression\CommonExpression; |
| 27 | use SimpleXMLElement; |
| 28 | |
| 29 | /** |
| 30 | * Short description of class |
| 31 | * |
| 32 | * @access public |
| 33 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 34 | * @package taoQTI |
| 35 | |
| 36 | */ |
| 37 | class ExpressionParserFactory |
| 38 | { |
| 39 | // --- ASSOCIATIONS --- |
| 40 | |
| 41 | |
| 42 | // --- ATTRIBUTES --- |
| 43 | |
| 44 | // --- OPERATIONS --- |
| 45 | |
| 46 | /** |
| 47 | * Short description of method build |
| 48 | * |
| 49 | * @access public |
| 50 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 51 | * @param SimpleXMLElement data |
| 52 | * @return oat\taoQtiItem\model\qti\expression\Expression |
| 53 | */ |
| 54 | public static function build(SimpleXMLElement $data) |
| 55 | { |
| 56 | $returnValue = null; |
| 57 | |
| 58 | |
| 59 | $expression = null; |
| 60 | $expressionName = $data->getName(); |
| 61 | |
| 62 | //retrieve the expression attributes |
| 63 | $attributes = []; |
| 64 | foreach ($data->attributes() as $key => $value) { |
| 65 | $attributes[$key] = (string)$value; |
| 66 | } |
| 67 | |
| 68 | // Create expression function of its type (If specialization has been done for the expression type) |
| 69 | $expressionClass = 'oat\\taoQtiItem\\model\\qti\\expression\\' . ucfirst($expressionName); |
| 70 | |
| 71 | if (class_exists($expressionClass)) { |
| 72 | $expression = new $expressionClass($expressionName, $attributes); |
| 73 | } else { |
| 74 | $expression = new CommonExpression($expressionName, $attributes); |
| 75 | } |
| 76 | |
| 77 | // If the expression has a value |
| 78 | $expressionValue = (string) trim($data); |
| 79 | if ($expressionValue != '') { |
| 80 | $expression->setValue($expressionValue); |
| 81 | } |
| 82 | |
| 83 | // All sub-expressions of an expression are embedded by this expression |
| 84 | $subExpressions = []; |
| 85 | foreach ($data->children() as $subExpressionNode) { |
| 86 | $subExpressions[] = self::build($subExpressionNode); |
| 87 | } |
| 88 | $expression->setSubExpressions($subExpressions); |
| 89 | |
| 90 | $returnValue = $expression; |
| 91 | |
| 92 | |
| 93 | |
| 94 | return $returnValue; |
| 95 | } |
| 96 | } |