Skip to content
...@@ -2,36 +2,37 @@ ...@@ -2,36 +2,37 @@
/** /**
* Class QuestionNotReachable * Class QuestionNotReachable
* @package * @package
* *
* Date: 25.03.13 * Date: 25.03.13
* Time: 15:15 * Time: 15:15
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class QuestionNotReachable extends \RuntimeException{ class QuestionNotReachable extends \RuntimeException
{
/** /**
* @var int * @var int
*/ */
protected $question_index; protected $question_index;
/** /**
* @param int $question_index * @param int $question_index
*/ */
public function __construct($question_index) public function __construct($question_index)
{ {
$this->question_index = $question_index; $this->question_index = $question_index;
parent::__construct( parent::__construct(
sprintf('The Question with index "Q%s" is not reachable from this node "', $this->question_index) sprintf('The Question with index "Q%s" is not reachable from this node "', $this->question_index)
); );
} }
/** /**
* @return int * @return int
*/ */
public function getQuestionIndex() public function getQuestionIndex()
{ {
return $this->question_index; return $this->question_index;
} }
} }
\ No newline at end of file
...@@ -2,38 +2,39 @@ ...@@ -2,38 +2,39 @@
/** /**
* Class UnableToParseCondition * Class UnableToParseCondition
* @package * @package
* *
* Date: 25.03.13 * Date: 25.03.13
* Time: 15:15 * Time: 15:15
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class UnableToParseCondition extends \RuntimeException{ class UnableToParseCondition extends \RuntimeException
{
/** /**
* @var string * @var string
*/ */
protected $condition; protected $condition;
/** /**
* @param string $expression * @param string $expression
* @param int $question_index * @param int $question_index
*/ */
public function __construct($condition) public function __construct($condition)
{ {
$this->condition = $condition; $this->condition = $condition;
parent::__construct( parent::__construct(
sprintf('The parser is unable to parse the condition "%s"', $this->condition) sprintf('The parser is unable to parse the condition "%s"', $this->condition)
); );
} }
/** /**
* @return string * @return string
*/ */
public function getCondition() public function getCondition()
{ {
return $this->condition; return $this->condition;
} }
} }
\ No newline at end of file
...@@ -2,35 +2,36 @@ ...@@ -2,35 +2,36 @@
/** /**
* Class UnsupportedExpression * Class UnsupportedExpression
* @package * @package
* *
* Date: 25.03.13 * Date: 25.03.13
* Time: 15:15 * Time: 15:15
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class UnsupportedExpression extends \RuntimeException{ class UnsupportedExpression extends \RuntimeException
{
/** /**
* @var string * @var string
*/ */
protected $expression; protected $expression;
/** /**
* @param string $expression * @param string $expression
*/ */
public function __construct($expression) public function __construct($expression)
{ {
$this->expression = $expression; $this->expression = $expression;
parent::__construct( parent::__construct(
sprintf('The expression "%s" is not supported', $this->expression) sprintf('The expression "%s" is not supported', $this->expression)
); );
} }
/** /**
* @return string * @return string
*/ */
public function getExpression() public function getExpression()
{ {
return $this->expression; return $this->expression;
} }
} }
\ No newline at end of file
...@@ -2,36 +2,37 @@ ...@@ -2,36 +2,37 @@
/** /**
* Class UnsupportedOperation * Class UnsupportedOperation
* @package * @package
* *
* Date: 25.03.13 * Date: 25.03.13
* Time: 15:15 * Time: 15:15
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class UnsupportedOperation extends \RuntimeException{ class UnsupportedOperation extends \RuntimeException
{
/** /**
* @var string * @var string
*/ */
protected $operator; protected $operator;
/** /**
* @param string $operator * @param string $operator
*/ */
public function __construct($operator) public function __construct($operator)
{ {
$this->operator = $operator; $this->operator = $operator;
parent::__construct( parent::__construct(
sprintf('The operator "%s" is not supported', $this->operator) sprintf('The operator "%s" is not supported', $this->operator)
); );
} }
/** /**
* @return string * @return string
*/ */
public function getOperator() public function getOperator()
{ {
return $this->operator; return $this->operator;
} }
} }
\ No newline at end of file
<?php <?php
include_once __DIR__. '/../AbstractComposite.php'; include_once __DIR__ . '/../AbstractComposite.php';
include_once 'ExpressionInterface.php'; include_once 'ExpressionInterface.php';
/** /**
...@@ -9,37 +9,38 @@ include_once 'ExpressionInterface.php'; ...@@ -9,37 +9,38 @@ include_once 'ExpressionInterface.php';
* Date: 25.03.13 * Date: 25.03.13
* Time: 15:42 * Time: 15:42
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
abstract class AbstractExpression extends AbstractComposite implements ExpressionInterface { abstract class AbstractExpression extends AbstractComposite implements ExpressionInterface
{
/** /**
* Get the Pattern to match relevant informations for an Expression * Get the Pattern to match relevant informations for an Expression
* @return string * @return string
*/ */
protected function getPattern() protected function getPattern()
{ {
return '/-?[0-9\.]+/'; return '/-?[0-9\.]+/';
} }
/** /**
* Parses the delivered Value and sets the relevant information for an Expression as attributes * Parses the delivered Value and sets the relevant information for an Expression as attributes
* *
* @param string $value * @param string $value
*/ */
public function parseValue($value) public function parseValue($value)
{ {
$result = array(); $result = array();
preg_match_all($this->getPattern(), $value, $result); preg_match_all($this->getPattern(), $value, $result);
$this->setMatches($result); $this->setMatches($result);
} }
/** /**
* Sets the result of the parsed value by a specific expression pattern * Sets the result of the parsed value by a specific expression pattern
* @see ExpressionInterface::parseValue() * @see ExpressionInterface::parseValue()
* @see ExpressionInterface::getPattern() * @see ExpressionInterface::getPattern()
* *
* @param array $matches * @param array $matches
*/ */
abstract protected function setMatches($matches); abstract protected function setMatches($matches);
} }
...@@ -9,84 +9,84 @@ require_once "QuestionExpressionInterface.php"; ...@@ -9,84 +9,84 @@ require_once "QuestionExpressionInterface.php";
* Date: 25.03.13 * Date: 25.03.13
* Time: 16:39 * Time: 16:39
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class AnswerOfQuestionExpression extends AbstractExpression implements QuestionExpressionInterface class AnswerOfQuestionExpression extends AbstractExpression implements QuestionExpressionInterface
{ {
/** /**
* The pattern <b>'/Q[0-9]+([^\[|0-9]|$)/'</b> should match the following expression in a condition <br /> * The pattern <b>'/Q[0-9]+([^\[|0-9]|$)/'</b> should match the following expression in a condition <br />
* <br /> * <br />
* <pre> * <pre>
* <b>Qn</b> "n" is a Placeholder for a numeric question index * <b>Qn</b> "n" is a Placeholder for a numeric question index
* </pre> * </pre>
* It is used to create a AnswerOfQuestionExpression * It is used to create a AnswerOfQuestionExpression
* @see AnswerOfQuestionExpression * @see AnswerOfQuestionExpression
* @var string * @var string
*/ */
// public static $pattern = '/Q[0-9]+([^\[|0-9]|$)/'; // public static $pattern = '/Q[0-9]+([^\[|0-9]|$)/';
public static $pattern = '/(Q\d+)(?=\=|<|>|\s|$)/'; public static $pattern = '/(Q\d+)(?=\=|<|>|\s|$)/';
/** /**
* @var string * @var string
*/ */
public static $identifier = "Qn"; public static $identifier = "Qn";
/** /**
* The Index of the a question * The Index of the a question
* *
* @var int * @var int
*/ */
protected $question_index; protected $question_index;
/** /**
* Sets the result of the parsed value by a specific expression pattern * Sets the result of the parsed value by a specific expression pattern
* @see ExpressionInterface::parseValue() * @see ExpressionInterface::parseValue()
* @see ExpressionInterface::getPattern() * @see ExpressionInterface::getPattern()
* *
* @param array $matches * @param array $matches
*/ */
protected function setMatches($matches) protected function setMatches($matches)
{ {
$this->question_index = $matches[0][0]; $this->question_index = $matches[0][0];
} }
/** /**
* Get the question index * Get the question index
* *
* @return int * @return int
*/ */
public function getQuestionIndex() public function getQuestionIndex()
{ {
return $this->question_index; return $this->question_index;
} }
/** /**
* Get the value of this Expression * Get the value of this Expression
* @return string * @return string
*/ */
public function getValue() public function getValue()
{ {
return "Q" . $this->question_index; return "Q" . $this->question_index;
} }
/** /**
* Get a human readable description of the Composite element * Get a human readable description of the Composite element
* @return string * @return string
*/ */
public function getDescription() public function getDescription()
{ {
return "Frage " . $this->question_index . " "; return "Frage " . $this->question_index . " ";
} }
/** /**
* Get the Pattern to match relevant informations for an Expression * Get the Pattern to match relevant informations for an Expression
* @return string * @return string
*/ */
protected function getPattern() protected function getPattern()
{ {
return '/-?[0-9]+/'; return '/-?[0-9]+/';
} }
} }
...@@ -9,93 +9,85 @@ include_once "SolutionExpressionInterface.php"; ...@@ -9,93 +9,85 @@ include_once "SolutionExpressionInterface.php";
* Date: 15.05.14 * Date: 15.05.14
* Time: 08:51 * Time: 08:51
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class EmptyAnswerExpression extends AbstractExpression implements SolutionExpressionInterface class EmptyAnswerExpression extends AbstractExpression implements SolutionExpressionInterface
{ {
public static $pattern = '/(\?)/';
public static $pattern = '/(\?)/'; public static $identifier = "?";
public static $identifier = "?"; /**
* @var boolean
*/
protected $matched;
/** protected function getPattern()
* @var boolean {
*/ return '/(\?)/';
protected $matched; }
protected function getPattern() /**
{ * Get the value of this Expression
return '/(\?)/'; * @return string
} */
public function getValue()
{
return "?";
}
/** /**
* Get the value of this Expression * Get a human readable description of the Composite element
* @return string * @return string
*/ */
public function getValue() public function getDescription()
{ {
return "?"; return " nicht beantwortet";
} }
/** /**
* Get a human readable description of the Composite element * @param ilUserQuestionResult $result
* @return string * @param string $comperator
*/ * @param null|int $index
public function getDescription() *
{ * @return bool
return " nicht beantwortet"; */
} public function checkResult($result, $comperator, $index = null)
{
if ($index == null) {
switch ($comperator) {
case "=":
return !$result->hasSolutions();
break;
case "<>":
return $result->hasSolutions();
break;
default:
return false;
}
} else {
$solution = $result->getSolutionForKey($index);
switch ($comperator) {
case "=":
return $solution == null;
break;
case "<>":
return $solution != null;
break;
default:
return false;
}
}
}
/** /**
* @param ilUserQuestionResult $result * Sets the result of the parsed value by a specific expression pattern
* @param string $comperator * @see ExpressionInterface::parseValue()
* @param null|int $index * @see ExpressionInterface::getPattern()
* *
* @return bool * @param array $matches
*/ */
public function checkResult($result, $comperator, $index = null) protected function setMatches($matches)
{ {
if($index == null) $this->matched = true;
{ }
switch($comperator)
{
case "=":
return !$result->hasSolutions();
break;
case "<>":
return $result->hasSolutions();
break;
default:
return false;
}
}
else
{
$solution = $result->getSolutionForKey($index);
switch($comperator)
{
case "=":
return $solution == null;
break;
case "<>":
return $solution != null;
break;
default:
return false;
}
}
}
/**
* Sets the result of the parsed value by a specific expression pattern
* @see ExpressionInterface::parseValue()
* @see ExpressionInterface::getPattern()
*
* @param array $matches
*/
protected function setMatches($matches)
{
$this->matched = true;
}
} }
\ No newline at end of file
...@@ -9,106 +9,104 @@ include_once "SolutionExpressionInterface.php"; ...@@ -9,106 +9,104 @@ include_once "SolutionExpressionInterface.php";
* Date: 25.03.13 * Date: 25.03.13
* Time: 16:41 * Time: 16:41
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class ExclusiveResultExpression extends AbstractExpression implements SolutionExpressionInterface class ExclusiveResultExpression extends AbstractExpression implements SolutionExpressionInterface
{ {
/** /**
* The pattern <b>"/\*[0-9]+(?:,[0-9]+)*\* /"</b> should match the following expression in a condition <br /> * The pattern <b>"/\*[0-9]+(?:,[0-9]+)*\* /"</b> should match the following expression in a condition <br />
* <br /> * <br />
* <pre> * <pre>
* <b>#n#</b> "n" is a Placeholder for a numeric value * <b>#n#</b> "n" is a Placeholder for a numeric value
* * </pre> * * </pre>
* It is used to create a NumericResultExpression * It is used to create a NumericResultExpression
* @see NumericResultExpression * @see NumericResultExpression
* @var string * @var string
*/ */
public static $pattern = '/\*[0-9]+(?:,[0-9]+)*\*/'; public static $pattern = '/\*[0-9]+(?:,[0-9]+)*\*/';
/** /**
* @var string * @var string
*/ */
public static $identifier = "*n,m,o,p*"; public static $identifier = "*n,m,o,p*";
/** /**
* An ordered array with numeric indices of elements * An ordered array with numeric indices of elements
* *
* @var int[] * @var int[]
*/ */
protected $exclusive; protected $exclusive;
protected function getPattern() protected function getPattern()
{ {
return '/(\d+)/'; return '/(\d+)/';
} }
/** /**
* Sets the result of the parsed value by a specific expression pattern * Sets the result of the parsed value by a specific expression pattern
* @see ExpressionInterface::parseValue() * @see ExpressionInterface::parseValue()
* @see ExpressionInterface::getPattern() * @see ExpressionInterface::getPattern()
* *
* @param array $matches * @param array $matches
*/ */
protected function setMatches($matches) protected function setMatches($matches)
{ {
$this->exclusive = array(); $this->exclusive = array();
foreach($matches[0] as $match) foreach ($matches[0] as $match) {
{ $this->exclusive[] = $match;
$this->exclusive[] = $match; }
} }
}
/** /**
* @return \int[] * @return \int[]
*/ */
public function getExclusive() public function getExclusive()
{ {
return $this->exclusive; return $this->exclusive;
} }
/** /**
* Get the value of this Expression * Get the value of this Expression
* @return string * @return string
*/ */
public function getValue() public function getValue()
{ {
return "*" . join(",", $this->exclusive) . "*"; return "*" . join(",", $this->exclusive) . "*";
} }
/** /**
* Get a human readable description of the Composite element * Get a human readable description of the Composite element
* @return string * @return string
*/ */
public function getDescription() public function getDescription()
{ {
return join(",", $this->exclusive) . " beantwortet "; return join(",", $this->exclusive) . " beantwortet ";
} }
/** /**
* @param ilUserQuestionResult $result * @param ilUserQuestionResult $result
* @param string $comperator * @param string $comperator
* @param null|int $index * @param null|int $index
* *
* @return bool * @return bool
*/ */
public function checkResult($result, $comperator, $index = null) public function checkResult($result, $comperator, $index = null)
{ {
$values = $result->getUserSolutionsByIdentifier("value"); $values = $result->getUserSolutionsByIdentifier("value");
$exclusive = $this->getExclusive(); $exclusive = $this->getExclusive();
sort($values); sort($values);
sort($exclusive); sort($exclusive);
switch($comperator) switch ($comperator) {
{ case "=":
case "=": return $values == $exclusive;
return $values == $exclusive; break;
break; case "<>":
case "<>": return $values != $exclusive;
return $values != $exclusive; break;
break; default:
default: return false;
return false; }
} }
}
} }
...@@ -7,19 +7,20 @@ ...@@ -7,19 +7,20 @@
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
interface ExpressionInterface { interface ExpressionInterface
{
/** /**
* Get the value of this Expression * Get the value of this Expression
* *
* @return string * @return string
*/ */
public function getValue(); public function getValue();
/** /**
* Parses the delivered Value and sets the relevant information for an Expression as attributes * Parses the delivered Value and sets the relevant information for an Expression as attributes
* *
* @param string $value * @param string $value
*/ */
public function parseValue($value); public function parseValue($value);
} }
\ No newline at end of file
...@@ -9,131 +9,129 @@ include_once "SolutionExpressionInterface.php"; ...@@ -9,131 +9,129 @@ include_once "SolutionExpressionInterface.php";
* Date: 25.03.13 * Date: 25.03.13
* Time: 16:41 * Time: 16:41
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class MatchingResultExpression extends AbstractExpression implements SolutionExpressionInterface class MatchingResultExpression extends AbstractExpression implements SolutionExpressionInterface
{ {
/** /**
* The pattern <b>"/;[0-9]+:[0-9]+;/"</b> should match the following expression in a condition <br /> * The pattern <b>"/;[0-9]+:[0-9]+;/"</b> should match the following expression in a condition <br />
* <br /> * <br />
* <pre> * <pre>
* <b>;n:m;</b> "n" is a Placeholder for a left numeric index * <b>;n:m;</b> "n" is a Placeholder for a left numeric index
* "m" is a Placeholder for a right numeric index * "m" is a Placeholder for a right numeric index
* </pre> * </pre>
* It is used to create a NumericResultExpression * It is used to create a NumericResultExpression
* @see MatchingResultExpression * @see MatchingResultExpression
* @var string * @var string
*/ */
public static $pattern = "/;[0-9]+:[0-9]+;/"; public static $pattern = "/;[0-9]+:[0-9]+;/";
/** /**
* @var string * @var string
*/ */
public static $identifier = ";n:m;"; public static $identifier = ";n:m;";
/** /**
* A numeric value which should be the left index of an element * A numeric value which should be the left index of an element
* *
* @var float * @var float
*/ */
protected $left_numeric_value; protected $left_numeric_value;
/** /**
* A numeric value which should be the right index of an element * A numeric value which should be the right index of an element
* *
* @var float * @var float
*/ */
protected $right_numeric_value; protected $right_numeric_value;
protected function getPattern() protected function getPattern()
{ {
return '/;(\d+):(\d+);/'; return '/;(\d+):(\d+);/';
} }
/** /**
* Sets the result of the parsed value by a specific expression pattern * Sets the result of the parsed value by a specific expression pattern
* @see ExpressionInterface::parseValue() * @see ExpressionInterface::parseValue()
* @see ExpressionInterface::getPattern() * @see ExpressionInterface::getPattern()
* *
* @param array $matches * @param array $matches
*/ */
protected function setMatches($matches) protected function setMatches($matches)
{ {
$this->left_numeric_value = $matches[1][0]; $this->left_numeric_value = $matches[1][0];
$this->right_numeric_value = $matches[2][0]; $this->right_numeric_value = $matches[2][0];
} }
/** /**
* @return float * @return float
*/ */
public function getRightNumericValue() public function getRightNumericValue()
{ {
return $this->right_numeric_value; return $this->right_numeric_value;
} }
/** /**
* @return float * @return float
*/ */
public function getLeftNumericValue() public function getLeftNumericValue()
{ {
return $this->left_numeric_value; return $this->left_numeric_value;
} }
/** /**
* Get the value of this Expression * Get the value of this Expression
* @return string * @return string
*/ */
public function getValue() public function getValue()
{ {
return ";" . $this->left_numeric_value. ":" . $this->right_numeric_value . ";"; return ";" . $this->left_numeric_value . ":" . $this->right_numeric_value . ";";
} }
/** /**
* Get a human readable description of the Composite element * Get a human readable description of the Composite element
* @return string * @return string
*/ */
public function getDescription() public function getDescription()
{ {
return $this->numeric_value . " beantwortet "; return $this->numeric_value . " beantwortet ";
} }
/** /**
* @param ilUserQuestionResult $result * @param ilUserQuestionResult $result
* @param string $comperator * @param string $comperator
* @param null|int $index * @param null|int $index
* *
* @return bool * @return bool
*/ */
public function checkResult($result, $comperator, $index = null) public function checkResult($result, $comperator, $index = null)
{ {
$solutions = $result->getSolutions(); $solutions = $result->getSolutions();
$isTrue = false; $isTrue = false;
foreach($solutions as $solution) foreach ($solutions as $solution) {
{ $isTrue = $isTrue || $this->compare($comperator, $solution["key"], $solution["value"]);
$isTrue = $isTrue || $this->compare($comperator, $solution["key"], $solution["value"]); }
} return $isTrue;
return $isTrue; }
}
/** /**
* @param string $comperator * @param string $comperator
* @param int $left * @param int $left
* @param int $right * @param int $right
* *
* @return bool * @return bool
*/ */
private function compare($comperator, $left, $right) private function compare($comperator, $left, $right)
{ {
switch($comperator) switch ($comperator) {
{ case "=":
case "=": return $this->getLeftNumericValue() == $left && $this->getRightNumericValue() == $right;
return $this->getLeftNumericValue() == $left && $this->getRightNumericValue() == $right; break;
break; case "<>":
case "<>": return $this->getLeftNumericValue() != $left || $this->getRightNumericValue() != $right;
return $this->getLeftNumericValue() != $left || $this->getRightNumericValue() != $right; break;
break; default:
default: return false;
return false; }
} }
}
} }
...@@ -9,112 +9,107 @@ include_once "SolutionExpressionInterface.php"; ...@@ -9,112 +9,107 @@ include_once "SolutionExpressionInterface.php";
* Date: 25.03.13 * Date: 25.03.13
* Time: 16:41 * Time: 16:41
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class NumberOfResultExpression extends AbstractExpression implements SolutionExpressionInterface class NumberOfResultExpression extends AbstractExpression implements SolutionExpressionInterface
{ {
/** /**
* The pattern <b>"/\\+[0-9]+\\+/"</b> should match the following expression in a condition <br /> * The pattern <b>"/\\+[0-9]+\\+/"</b> should match the following expression in a condition <br />
* <br /> * <br />
* <pre> * <pre>
* <b>+n+</b> "n" is a Placeholder for a numeric value * <b>+n+</b> "n" is a Placeholder for a numeric value
* </pre> * </pre>
* It is used to create a NumberOfResultExpression * It is used to create a NumberOfResultExpression
* @see NumberOfResultExpression * @see NumberOfResultExpression
* @var string * @var string
*/ */
public static $pattern = "/\\+[0-9]+\\+/"; public static $pattern = "/\\+[0-9]+\\+/";
/** /**
* @var string * @var string
*/ */
public static $identifier = "+n+"; public static $identifier = "+n+";
/** /**
* A numeric value to identify a specific answer which should be compared * A numeric value to identify a specific answer which should be compared
* *
* @var int * @var int
*/ */
protected $numeric_value; protected $numeric_value;
/** /**
* Sets the result of the parsed value by a specific expression pattern * Sets the result of the parsed value by a specific expression pattern
* @see ExpressionInterface::parseValue() * @see ExpressionInterface::parseValue()
* @see ExpressionInterface::getPattern() * @see ExpressionInterface::getPattern()
* *
* @param array $matches * @param array $matches
*/ */
protected function setMatches($matches) protected function setMatches($matches)
{ {
$this->numeric_value = $matches[0][0]; $this->numeric_value = $matches[0][0];
} }
/** /**
* @return int * @return int
*/ */
public function getNumericValue() public function getNumericValue()
{ {
return $this->numeric_value; return $this->numeric_value;
} }
/** /**
* Get the value of this Expression * Get the value of this Expression
* @return string * @return string
*/ */
public function getValue() public function getValue()
{ {
return '+' . $this->numeric_value . "+"; return '+' . $this->numeric_value . "+";
} }
/** /**
* Get a human readable description of the Composite element * Get a human readable description of the Composite element
* @return string * @return string
*/ */
public function getDescription() public function getDescription()
{ {
return "Anwort " . $this->numeric_value . " beantwortet "; return "Anwort " . $this->numeric_value . " beantwortet ";
} }
/** /**
* @param ilUserQuestionResult $result * @param ilUserQuestionResult $result
* @param string $comperator * @param string $comperator
* @param null|int $index * @param null|int $index
* *
* @return bool * @return bool
*/ */
public function checkResult($result, $comperator, $index = null) public function checkResult($result, $comperator, $index = null)
{ {
$isTrue = false; $isTrue = false;
if($index == null) if ($index == null) {
{ $values = $result->getUserSolutionsByIdentifier("key");
$values = $result->getUserSolutionsByIdentifier("key");
foreach($values as $value) foreach ($values as $value) {
{ $isTrue = $isTrue || $this->compare($comperator, $value);
$isTrue = $isTrue || $this->compare($comperator, $value); }
} } else {
} $solution = $result->getSolutionForKey($index);
else $isTrue = $this->compare($comperator, $solution["value"]);
{ }
$solution = $result->getSolutionForKey($index);
$isTrue = $this->compare($comperator, $solution["value"]);
}
return $isTrue; return $isTrue;
} }
private function compare($comperator, $value) private function compare($comperator, $value)
{ {
switch($comperator) switch ($comperator) {
{ case "=":
case "=": return $value == $this->getNumericValue();
return $value == $this->getNumericValue(); break;
break; case "<>":
case "<>": return $value != $this->getNumericValue();
return $value != $this->getNumericValue(); break;
break; default:
default: return false;
return false; }
} }
}
} }
...@@ -9,124 +9,119 @@ include_once "SolutionExpressionInterface.php"; ...@@ -9,124 +9,119 @@ include_once "SolutionExpressionInterface.php";
* Date: 25.03.13 * Date: 25.03.13
* Time: 16:41 * Time: 16:41
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
class NumericResultExpression extends AbstractExpression implements SolutionExpressionInterface class NumericResultExpression extends AbstractExpression implements SolutionExpressionInterface
{ {
/** /**
* The pattern <b>"/#[0-9]+#/"</b> should match the following expression in a condition <br /> * The pattern <b>"/#[0-9]+#/"</b> should match the following expression in a condition <br />
* <br /> * <br />
* <pre> * <pre>
* <b>#n#</b> "n" is a Placeholder for a numeric value * <b>#n#</b> "n" is a Placeholder for a numeric value
* * </pre> * * </pre>
* It is used to create a NumericResultExpression * It is used to create a NumericResultExpression
* @see NumericResultExpression * @see NumericResultExpression
* @var string * @var string
*/ */
public static $pattern = '/#-?[0-9\.]+#/'; public static $pattern = '/#-?[0-9\.]+#/';
/** /**
* @var string * @var string
*/ */
public static $identifier = "#n#"; public static $identifier = "#n#";
/** /**
* A numeric value which should be compared * A numeric value which should be compared
* *
* @var float * @var float
*/ */
protected $numeric_value; protected $numeric_value;
/** /**
* Sets the result of the parsed value by a specific expression pattern * Sets the result of the parsed value by a specific expression pattern
* @see ExpressionInterface::parseValue() * @see ExpressionInterface::parseValue()
* @see ExpressionInterface::getPattern() * @see ExpressionInterface::getPattern()
* *
* @param array $matches * @param array $matches
*/ */
protected function setMatches($matches) protected function setMatches($matches)
{ {
$this->numeric_value = $matches[0][0]; $this->numeric_value = $matches[0][0];
} }
/** /**
* @return float * @return float
*/ */
public function getNumericValue() public function getNumericValue()
{ {
return $this->numeric_value; return $this->numeric_value;
} }
/** /**
* Get the value of this Expression * Get the value of this Expression
* @return string * @return string
*/ */
public function getValue() public function getValue()
{ {
return "#" . $this->numeric_value . "#"; return "#" . $this->numeric_value . "#";
} }
/** /**
* Get a human readable description of the Composite element * Get a human readable description of the Composite element
* @return string * @return string
*/ */
public function getDescription() public function getDescription()
{ {
return $this->numeric_value . " beantwortet "; return $this->numeric_value . " beantwortet ";
} }
/** /**
* @param ilUserQuestionResult $result * @param ilUserQuestionResult $result
* @param string $comperator * @param string $comperator
* @param null|int $index * @param null|int $index
* *
* @return bool * @return bool
*/ */
public function checkResult($result, $comperator, $index = null) public function checkResult($result, $comperator, $index = null)
{ {
$isTrue = false; $isTrue = false;
if($index == null) if ($index == null) {
{ $values = $result->getUserSolutionsByIdentifier("value");
$values = $result->getUserSolutionsByIdentifier("value");
foreach($values as $value) foreach ($values as $value) {
{ $isTrue = $isTrue || $this->compare($comperator, $value);
$isTrue = $isTrue || $this->compare($comperator, $value); }
} } else {
} $solution = $result->getSolutionForKey($index);
else $isTrue = $this->compare($comperator, $solution["value"]);
{ }
$solution = $result->getSolutionForKey($index);
$isTrue = $this->compare($comperator, $solution["value"]);
}
return $isTrue; return $isTrue;
} }
private function compare($comperator, $value) private function compare($comperator, $value)
{ {
switch($comperator) switch ($comperator) {
{ case "<":
case "<": return $value < $this->getNumericValue();
return $value < $this->getNumericValue(); break;
break; case "<=":
case "<=": return $value <= $this->getNumericValue();
return $value <= $this->getNumericValue(); break;
break; case "=":
case "=": return $value == $this->getNumericValue();
return $value == $this->getNumericValue(); break;
break; case ">=":
case ">=": return $value >= $this->getNumericValue();
return $value >= $this->getNumericValue(); break;
break; case ">":
case ">": return $value > $this->getNumericValue();
return $value > $this->getNumericValue(); break;
break; case "<>":
case "<>": return $value != $this->getNumericValue();
return $value != $this->getNumericValue(); break;
break; default:
default: return false;
return false; }
} }
}
} }
...@@ -7,8 +7,7 @@ ...@@ -7,8 +7,7 @@
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
interface QuestionExpressionInterface { interface QuestionExpressionInterface
{
public function getQuestionIndex();
public function getQuestionIndex(); }
}
\ No newline at end of file
...@@ -9,12 +9,12 @@ ...@@ -9,12 +9,12 @@
interface SolutionExpressionInterface interface SolutionExpressionInterface
{ {
/** /**
* @param ilUserQuestionResult $result * @param ilUserQuestionResult $result
* @param string $comperator * @param string $comperator
* @param null|int $index * @param null|int $index
* *
* @return bool * @return bool
*/ */
public function checkResult($result, $comperator, $index = null); public function checkResult($result, $comperator, $index = null);
} }
\ No newline at end of file
...@@ -8,33 +8,33 @@ include_once "ManufacturerInterface.php"; ...@@ -8,33 +8,33 @@ include_once "ManufacturerInterface.php";
* Date: 26.03.13 * Date: 26.03.13
* Time: 15:13 * Time: 15:13
* @author Thomas Joußen <tjoussen@databay.de> * @author Thomas Joußen <tjoussen@databay.de>
*/ */
abstract class AbstractManufacturer implements ManufacturerInterface{ abstract class AbstractManufacturer implements ManufacturerInterface
{
/** /**
* Matches a delivered string with a the pattern returned by getPattern implemented in the explicit Manufacturer * Matches a delivered string with a the pattern returned by getPattern implemented in the explicit Manufacturer
* *
* @param string $subject * @param string $subject
* @throws UnableToParseCondition * @throws UnableToParseCondition
* *
* @see ManufacturerInterface::getPattern() * @see ManufacturerInterface::getPattern()
* @return array * @return array
*/ */
public function match($subject) public function match($subject)
{ {
$matches = array(); $matches = array();
$num_matches = preg_match_all($this->getPattern(), $subject, $matches); $num_matches = preg_match_all($this->getPattern(), $subject, $matches);
if($num_matches == 0) if ($num_matches == 0) {
{ require_once __DIR__ . '/../Exception/UnableToParseCondition.php';
require_once __DIR__ . '/../Exception/UnableToParseCondition.php'; throw new UnableToParseCondition($subject);
throw new UnableToParseCondition($subject); }
} // Trims each element in the matches array
// Trims each element in the matches array $matches = array_map(function ($element) {
$matches = array_map(function($element){ return trim($element);
return trim($element); }, $matches[0]);
}, $matches[0]);
return $matches; return $matches;
} }
} }