Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| ResponseCondition | |
0.00% |
0 / 11 |
|
0.00% |
0 / 3 |
56 | |
0.00% |
0 / 1 |
| getRule | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
30 | |||
| addResponseIf | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setResponseElse | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 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\ResponseCondition; |
| 26 | use oat\taoQtiItem\model\qti\response\ResponseRule; |
| 27 | use oat\taoQtiItem\model\qti\response\Rule; |
| 28 | use oat\taoQtiItem\model\qti\expression\Expression; |
| 29 | use oat\taoQtiItem\model\qti\response\ConditionalExpression; |
| 30 | |
| 31 | /** |
| 32 | * Short description of class |
| 33 | * |
| 34 | * @access public |
| 35 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 36 | * @package taoQTI |
| 37 | |
| 38 | */ |
| 39 | class ResponseCondition extends ResponseRule implements Rule |
| 40 | { |
| 41 | // --- ATTRIBUTES --- |
| 42 | |
| 43 | /** |
| 44 | * Short description of attribute responseIfs |
| 45 | * |
| 46 | * @access protected |
| 47 | * @var array |
| 48 | */ |
| 49 | protected $responseIfs = []; |
| 50 | |
| 51 | /** |
| 52 | * Short description of attribute responseElse |
| 53 | * |
| 54 | * @access public |
| 55 | * @var ResponseRule |
| 56 | */ |
| 57 | public $responseElse = null; |
| 58 | |
| 59 | // --- OPERATIONS --- |
| 60 | |
| 61 | /** |
| 62 | * Short description of method getRule |
| 63 | * |
| 64 | * @access public |
| 65 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 66 | * @return string |
| 67 | */ |
| 68 | public function getRule() |
| 69 | { |
| 70 | $returnValue = (string) ''; |
| 71 | |
| 72 | |
| 73 | |
| 74 | // Get the if / elseif conditions and the associated actions |
| 75 | foreach ($this->responseIfs as $responseElseIf) { |
| 76 | $returnValue .= (empty($returnValue) ? '' : ' else ') . $responseElseIf->getRule(); |
| 77 | } |
| 78 | |
| 79 | // Get the else actions |
| 80 | if (!empty($this->responseElse)) { |
| 81 | $returnValue .= 'else {'; |
| 82 | foreach ($this->responseElse as $actions) { |
| 83 | $returnValue .= $actions->getRule(); |
| 84 | } |
| 85 | $returnValue .= '}'; |
| 86 | } |
| 87 | |
| 88 | |
| 89 | |
| 90 | return (string) $returnValue; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * Short description of method addResponseIf |
| 95 | * |
| 96 | * @access public |
| 97 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 98 | * @param Expression condition |
| 99 | * @param array actions |
| 100 | * @return mixed |
| 101 | */ |
| 102 | public function addResponseIf(Expression $condition, $actions) |
| 103 | { |
| 104 | |
| 105 | $this->responseIfs[] = new ConditionalExpression($condition, $actions); |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Short description of method setResponseElse |
| 110 | * |
| 111 | * @access public |
| 112 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 113 | * @param array actions |
| 114 | * @return mixed |
| 115 | */ |
| 116 | public function setResponseElse($actions) |
| 117 | { |
| 118 | |
| 119 | $this->responseElse = $actions; |
| 120 | } |
| 121 | } |