Skip to content
......@@ -2,36 +2,37 @@
/**
* Class QuestionNotReachable
* @package
* @package
*
* Date: 25.03.13
* Time: 15:15
* @author Thomas Joußen <tjoussen@databay.de>
*/
class QuestionNotReachable extends \RuntimeException{
*/
class QuestionNotReachable extends \RuntimeException
{
/**
* @var int
*/
protected $question_index;
/**
* @var int
*/
protected $question_index;
/**
* @param int $question_index
*/
public function __construct($question_index)
{
$this->question_index = $question_index;
/**
* @param int $question_index
*/
public function __construct($question_index)
{
$this->question_index = $question_index;
parent::__construct(
sprintf('The Question with index "Q%s" is not reachable from this node "', $this->question_index)
);
}
parent::__construct(
sprintf('The Question with index "Q%s" is not reachable from this node "', $this->question_index)
);
}
/**
* @return int
*/
public function getQuestionIndex()
{
return $this->question_index;
}
}
\ No newline at end of file
/**
* @return int
*/
public function getQuestionIndex()
{
return $this->question_index;
}
}
......@@ -2,38 +2,39 @@
/**
* Class UnableToParseCondition
* @package
* @package
*
* Date: 25.03.13
* Time: 15:15
* @author Thomas Joußen <tjoussen@databay.de>
*/
class UnableToParseCondition extends \RuntimeException{
*/
class UnableToParseCondition extends \RuntimeException
{
/**
* @var string
*/
protected $condition;
/**
* @var string
*/
protected $condition;
/**
* @param string $expression
* @param int $question_index
*/
public function __construct($condition)
{
$this->condition = $condition;
/**
* @param string $expression
* @param int $question_index
*/
public function __construct($condition)
{
$this->condition = $condition;
parent::__construct(
sprintf('The parser is unable to parse the condition "%s"', $this->condition)
);
}
parent::__construct(
sprintf('The parser is unable to parse the condition "%s"', $this->condition)
);
}
/**
* @return string
*/
public function getCondition()
{
return $this->condition;
}
}
\ No newline at end of file
/**
* @return string
*/
public function getCondition()
{
return $this->condition;
}
}
......@@ -2,35 +2,36 @@
/**
* Class UnsupportedExpression
* @package
* @package
*
* Date: 25.03.13
* Time: 15:15
* @author Thomas Joußen <tjoussen@databay.de>
*/
class UnsupportedExpression extends \RuntimeException{
*/
class UnsupportedExpression extends \RuntimeException
{
/**
* @var string
*/
protected $expression;
/**
* @var string
*/
protected $expression;
/**
* @param string $expression
*/
public function __construct($expression)
{
$this->expression = $expression;
parent::__construct(
sprintf('The expression "%s" is not supported', $this->expression)
);
}
/**
* @param string $expression
*/
public function __construct($expression)
{
$this->expression = $expression;
parent::__construct(
sprintf('The expression "%s" is not supported', $this->expression)
);
}
/**
* @return string
*/
public function getExpression()
{
return $this->expression;
}
}
\ No newline at end of file
/**
* @return string
*/
public function getExpression()
{
return $this->expression;
}
}
......@@ -2,36 +2,37 @@
/**
* Class UnsupportedOperation
* @package
* @package
*
* Date: 25.03.13
* Time: 15:15
* @author Thomas Joußen <tjoussen@databay.de>
*/
class UnsupportedOperation extends \RuntimeException{
*/
class UnsupportedOperation extends \RuntimeException
{
/**
* @var string
*/
protected $operator;
/**
* @var string
*/
protected $operator;
/**
* @param string $operator
*/
public function __construct($operator)
{
$this->operator = $operator;
/**
* @param string $operator
*/
public function __construct($operator)
{
$this->operator = $operator;
parent::__construct(
sprintf('The operator "%s" is not supported', $this->operator)
);
}
parent::__construct(
sprintf('The operator "%s" is not supported', $this->operator)
);
}
/**
* @return string
*/
public function getOperator()
{
return $this->operator;
}
}
\ No newline at end of file
/**
* @return string
*/
public function getOperator()
{
return $this->operator;
}
}
<?php
include_once __DIR__. '/../AbstractComposite.php';
include_once __DIR__ . '/../AbstractComposite.php';
include_once 'ExpressionInterface.php';
/**
......@@ -9,37 +9,38 @@ include_once 'ExpressionInterface.php';
* Date: 25.03.13
* Time: 15:42
* @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
* @return string
*/
protected function getPattern()
{
return '/-?[0-9\.]+/';
}
/**
* Get the Pattern to match relevant informations for an Expression
* @return string
*/
protected function getPattern()
{
return '/-?[0-9\.]+/';
}
/**
* Parses the delivered Value and sets the relevant information for an Expression as attributes
*
* @param string $value
*/
public function parseValue($value)
{
$result = array();
preg_match_all($this->getPattern(), $value, $result);
$this->setMatches($result);
}
/**
* Parses the delivered Value and sets the relevant information for an Expression as attributes
*
* @param string $value
*/
public function parseValue($value)
{
$result = array();
preg_match_all($this->getPattern(), $value, $result);
$this->setMatches($result);
}
/**
* Sets the result of the parsed value by a specific expression pattern
* @see ExpressionInterface::parseValue()
* @see ExpressionInterface::getPattern()
*
* @param array $matches
*/
abstract protected function setMatches($matches);
/**
* Sets the result of the parsed value by a specific expression pattern
* @see ExpressionInterface::parseValue()
* @see ExpressionInterface::getPattern()
*
* @param array $matches
*/
abstract protected function setMatches($matches);
}
......@@ -9,84 +9,84 @@ require_once "QuestionExpressionInterface.php";
* Date: 25.03.13
* Time: 16:39
* @author Thomas Joußen <tjoussen@databay.de>
*/
*/
class AnswerOfQuestionExpression extends AbstractExpression implements QuestionExpressionInterface
{
/**
* The pattern <b>'/Q[0-9]+([^\[|0-9]|$)/'</b> should match the following expression in a condition <br />
* <br />
* <pre>
* <b>Qn</b> "n" is a Placeholder for a numeric question index
* </pre>
* It is used to create a AnswerOfQuestionExpression
/**
* The pattern <b>'/Q[0-9]+([^\[|0-9]|$)/'</b> should match the following expression in a condition <br />
* <br />
* <pre>
* <b>Qn</b> "n" is a Placeholder for a numeric question index
* </pre>
* It is used to create a AnswerOfQuestionExpression
* @see AnswerOfQuestionExpression
* @var string
*/
* @see AnswerOfQuestionExpression
* @var string
*/
// public static $pattern = '/Q[0-9]+([^\[|0-9]|$)/';
public static $pattern = '/(Q\d+)(?=\=|<|>|\s|$)/';
// public static $pattern = '/Q[0-9]+([^\[|0-9]|$)/';
public static $pattern = '/(Q\d+)(?=\=|<|>|\s|$)/';
/**
* @var string
*/
public static $identifier = "Qn";
/**
* @var string
*/
public static $identifier = "Qn";
/**
* The Index of the a question
*
* @var int
*/
protected $question_index;
/**
* The Index of the a question
*
* @var int
*/
protected $question_index;
/**
* 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->question_index = $matches[0][0];
}
/**
* 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->question_index = $matches[0][0];
}
/**
* Get the question index
*
* @return int
*/
public function getQuestionIndex()
{
return $this->question_index;
}
/**
* Get the question index
*
* @return int
*/
public function getQuestionIndex()
{
return $this->question_index;
}
/**
* Get the value of this Expression
* @return string
*/
public function getValue()
{
return "Q" . $this->question_index;
}
/**
* Get the value of this Expression
* @return string
*/
public function getValue()
{
return "Q" . $this->question_index;
}
/**
* Get a human readable description of the Composite element
* @return string
*/
public function getDescription()
{
return "Frage " . $this->question_index . " ";
}
/**
* Get a human readable description of the Composite element
* @return string
*/
public function getDescription()
{
return "Frage " . $this->question_index . " ";
}
/**
* Get the Pattern to match relevant informations for an Expression
* @return string
*/
protected function getPattern()
{
return '/-?[0-9]+/';
}
/**
* Get the Pattern to match relevant informations for an Expression
* @return string
*/
protected function getPattern()
{
return '/-?[0-9]+/';
}
}
......@@ -9,93 +9,85 @@ include_once "SolutionExpressionInterface.php";
* Date: 15.05.14
* Time: 08:51
* @author Thomas Joußen <tjoussen@databay.de>
*/
*/
class EmptyAnswerExpression extends AbstractExpression implements SolutionExpressionInterface
{
public static $pattern = '/(\?)/';
public static $pattern = '/(\?)/';
public static $identifier = "?";
public static $identifier = "?";
/**
* @var boolean
*/
protected $matched;
/**
* @var boolean
*/
protected $matched;
protected function getPattern()
{
return '/(\?)/';
}
protected function getPattern()
{
return '/(\?)/';
}
/**
* Get the value of this Expression
* @return string
*/
public function getValue()
{
return "?";
}
/**
* Get the value of this Expression
* @return string
*/
public function getValue()
{
return "?";
}
/**
* Get a human readable description of the Composite element
* @return string
*/
public function getDescription()
{
return " nicht beantwortet";
}
/**
* Get a human readable description of the Composite element
* @return string
*/
public function getDescription()
{
return " nicht beantwortet";
}
/**
* @param ilUserQuestionResult $result
* @param string $comperator
* @param null|int $index
*
* @return bool
*/
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
* @param string $comperator
* @param null|int $index
*
* @return bool
*/
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;
}
}
}
/**
* 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;
}
/**
* 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";
* Date: 25.03.13
* Time: 16:41
* @author Thomas Joußen <tjoussen@databay.de>
*/
*/
class ExclusiveResultExpression extends AbstractExpression implements SolutionExpressionInterface
{
/**
* The pattern <b>"/\*[0-9]+(?:,[0-9]+)*\* /"</b> should match the following expression in a condition <br />
* <br />
* <pre>
* <b>#n#</b> "n" is a Placeholder for a numeric value
* * </pre>
* It is used to create a NumericResultExpression
/**
* The pattern <b>"/\*[0-9]+(?:,[0-9]+)*\* /"</b> should match the following expression in a condition <br />
* <br />
* <pre>
* <b>#n#</b> "n" is a Placeholder for a numeric value
* * </pre>
* It is used to create a NumericResultExpression
* @see NumericResultExpression
* @var string
*/
public static $pattern = '/\*[0-9]+(?:,[0-9]+)*\*/';
* @see NumericResultExpression
* @var string
*/
public static $pattern = '/\*[0-9]+(?:,[0-9]+)*\*/';
/**
* @var string
*/
public static $identifier = "*n,m,o,p*";
/**
* @var string
*/
public static $identifier = "*n,m,o,p*";
/**
* An ordered array with numeric indices of elements
*
* @var int[]
*/
protected $exclusive;
/**
* An ordered array with numeric indices of elements
*
* @var int[]
*/
protected $exclusive;
protected function getPattern()
{
return '/(\d+)/';
}
protected function getPattern()
{
return '/(\d+)/';
}
/**
* 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->exclusive = array();
/**
* 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->exclusive = array();
foreach($matches[0] as $match)
{
$this->exclusive[] = $match;
}
}
foreach ($matches[0] as $match) {
$this->exclusive[] = $match;
}
}
/**
* @return \int[]
*/
public function getExclusive()
{
return $this->exclusive;
}
/**
* @return \int[]
*/
public function getExclusive()
{
return $this->exclusive;
}
/**
* Get the value of this Expression
* @return string
*/
public function getValue()
{
return "*" . join(",", $this->exclusive) . "*";
}
/**
* Get the value of this Expression
* @return string
*/
public function getValue()
{
return "*" . join(",", $this->exclusive) . "*";
}
/**
* Get a human readable description of the Composite element
* @return string
*/
public function getDescription()
{
return join(",", $this->exclusive) . " beantwortet ";
}
/**
* Get a human readable description of the Composite element
* @return string
*/
public function getDescription()
{
return join(",", $this->exclusive) . " beantwortet ";
}
/**
* @param ilUserQuestionResult $result
* @param string $comperator
* @param null|int $index
*
* @return bool
*/
public function checkResult($result, $comperator, $index = null)
{
$values = $result->getUserSolutionsByIdentifier("value");
$exclusive = $this->getExclusive();
sort($values);
sort($exclusive);
/**
* @param ilUserQuestionResult $result
* @param string $comperator
* @param null|int $index
*
* @return bool
*/
public function checkResult($result, $comperator, $index = null)
{
$values = $result->getUserSolutionsByIdentifier("value");
$exclusive = $this->getExclusive();
sort($values);
sort($exclusive);
switch($comperator)
{
case "=":
return $values == $exclusive;
break;
case "<>":
return $values != $exclusive;
break;
default:
return false;
}
}
switch ($comperator) {
case "=":
return $values == $exclusive;
break;
case "<>":
return $values != $exclusive;
break;
default:
return false;
}
}
}
......@@ -7,19 +7,20 @@
* @author Thomas Joußen <tjoussen@databay.de>
*/
interface ExpressionInterface {
interface ExpressionInterface
{
/**
* Get the value of this Expression
*
* @return string
*/
public function getValue();
/**
* Get the value of this Expression
*
* @return string
*/
public function getValue();
/**
* Parses the delivered Value and sets the relevant information for an Expression as attributes
*
* @param string $value
*/
public function parseValue($value);
}
\ No newline at end of file
/**
* Parses the delivered Value and sets the relevant information for an Expression as attributes
*
* @param string $value
*/
public function parseValue($value);
}
......@@ -9,131 +9,129 @@ include_once "SolutionExpressionInterface.php";
* Date: 25.03.13
* Time: 16:41
* @author Thomas Joußen <tjoussen@databay.de>
*/
*/
class MatchingResultExpression extends AbstractExpression implements SolutionExpressionInterface
{
/**
* The pattern <b>"/;[0-9]+:[0-9]+;/"</b> should match the following expression in a condition <br />
* <br />
* <pre>
* <b>;n:m;</b> "n" is a Placeholder for a left numeric index
* "m" is a Placeholder for a right numeric index
* </pre>
* It is used to create a NumericResultExpression
/**
* The pattern <b>"/;[0-9]+:[0-9]+;/"</b> should match the following expression in a condition <br />
* <br />
* <pre>
* <b>;n:m;</b> "n" is a Placeholder for a left numeric index
* "m" is a Placeholder for a right numeric index
* </pre>
* It is used to create a NumericResultExpression
* @see MatchingResultExpression
* @var string
*/
public static $pattern = "/;[0-9]+:[0-9]+;/";
* @see MatchingResultExpression
* @var string
*/
public static $pattern = "/;[0-9]+:[0-9]+;/";
/**
* @var string
*/
public static $identifier = ";n:m;";
/**
* @var string
*/
public static $identifier = ";n:m;";
/**
* A numeric value which should be the left index of an element
*
* @var float
*/
protected $left_numeric_value;
/**
* A numeric value which should be the left index of an element
*
* @var float
*/
protected $left_numeric_value;
/**
* A numeric value which should be the right index of an element
*
* @var float
*/
protected $right_numeric_value;
/**
* A numeric value which should be the right index of an element
*
* @var float
*/
protected $right_numeric_value;
protected function getPattern()
{
return '/;(\d+):(\d+);/';
}
protected function getPattern()
{
return '/;(\d+):(\d+);/';
}
/**
* 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->left_numeric_value = $matches[1][0];
$this->right_numeric_value = $matches[2][0];
}
/**
* 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->left_numeric_value = $matches[1][0];
$this->right_numeric_value = $matches[2][0];
}
/**
* @return float
*/
public function getRightNumericValue()
{
return $this->right_numeric_value;
}
/**
* @return float
*/
public function getRightNumericValue()
{
return $this->right_numeric_value;
}
/**
* @return float
*/
public function getLeftNumericValue()
{
return $this->left_numeric_value;
}
/**
* @return float
*/
public function getLeftNumericValue()
{
return $this->left_numeric_value;
}
/**
* Get the value of this Expression
* @return string
*/
public function getValue()
{
return ";" . $this->left_numeric_value. ":" . $this->right_numeric_value . ";";
}
/**
* Get the value of this Expression
* @return string
*/
public function getValue()
{
return ";" . $this->left_numeric_value . ":" . $this->right_numeric_value . ";";
}
/**
* Get a human readable description of the Composite element
* @return string
*/
public function getDescription()
{
return $this->numeric_value . " beantwortet ";
}
/**
* Get a human readable description of the Composite element
* @return string
*/
public function getDescription()
{
return $this->numeric_value . " beantwortet ";
}
/**
* @param ilUserQuestionResult $result
* @param string $comperator
* @param null|int $index
*
* @return bool
*/
public function checkResult($result, $comperator, $index = null)
{
$solutions = $result->getSolutions();
$isTrue = false;
foreach($solutions as $solution)
{
$isTrue = $isTrue || $this->compare($comperator, $solution["key"], $solution["value"]);
}
return $isTrue;
}
/**
* @param ilUserQuestionResult $result
* @param string $comperator
* @param null|int $index
*
* @return bool
*/
public function checkResult($result, $comperator, $index = null)
{
$solutions = $result->getSolutions();
$isTrue = false;
foreach ($solutions as $solution) {
$isTrue = $isTrue || $this->compare($comperator, $solution["key"], $solution["value"]);
}
return $isTrue;
}
/**
* @param string $comperator
* @param int $left
* @param int $right
*
* @return bool
*/
private function compare($comperator, $left, $right)
{
switch($comperator)
{
case "=":
return $this->getLeftNumericValue() == $left && $this->getRightNumericValue() == $right;
break;
case "<>":
return $this->getLeftNumericValue() != $left || $this->getRightNumericValue() != $right;
break;
default:
return false;
}
}
/**
* @param string $comperator
* @param int $left
* @param int $right
*
* @return bool
*/
private function compare($comperator, $left, $right)
{
switch ($comperator) {
case "=":
return $this->getLeftNumericValue() == $left && $this->getRightNumericValue() == $right;
break;
case "<>":
return $this->getLeftNumericValue() != $left || $this->getRightNumericValue() != $right;
break;
default:
return false;
}
}
}
......@@ -9,112 +9,107 @@ include_once "SolutionExpressionInterface.php";
* Date: 25.03.13
* Time: 16:41
* @author Thomas Joußen <tjoussen@databay.de>
*/
*/
class NumberOfResultExpression extends AbstractExpression implements SolutionExpressionInterface
{
/**
* The pattern <b>"/\\+[0-9]+\\+/"</b> should match the following expression in a condition <br />
* <br />
* <pre>
* <b>+n+</b> "n" is a Placeholder for a numeric value
* </pre>
* It is used to create a NumberOfResultExpression
/**
* The pattern <b>"/\\+[0-9]+\\+/"</b> should match the following expression in a condition <br />
* <br />
* <pre>
* <b>+n+</b> "n" is a Placeholder for a numeric value
* </pre>
* It is used to create a NumberOfResultExpression
* @see NumberOfResultExpression
* @var string
*/
public static $pattern = "/\\+[0-9]+\\+/";
* @see NumberOfResultExpression
* @var string
*/
public static $pattern = "/\\+[0-9]+\\+/";
/**
* @var string
*/
public static $identifier = "+n+";
/**
* @var string
*/
public static $identifier = "+n+";
/**
* A numeric value to identify a specific answer which should be compared
*
* @var int
*/
protected $numeric_value;
/**
* A numeric value to identify a specific answer which should be compared
*
* @var int
*/
protected $numeric_value;
/**
* 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->numeric_value = $matches[0][0];
}
/**
* 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->numeric_value = $matches[0][0];
}
/**
* @return int
*/
public function getNumericValue()
{
return $this->numeric_value;
}
/**
* @return int
*/
public function getNumericValue()
{
return $this->numeric_value;
}
/**
* Get the value of this Expression
* @return string
*/
public function getValue()
{
return '+' . $this->numeric_value . "+";
}
/**
* Get the value of this Expression
* @return string
*/
public function getValue()
{
return '+' . $this->numeric_value . "+";
}
/**
* Get a human readable description of the Composite element
* @return string
*/
public function getDescription()
{
return "Anwort " . $this->numeric_value . " beantwortet ";
}
/**
* Get a human readable description of the Composite element
* @return string
*/
public function getDescription()
{
return "Anwort " . $this->numeric_value . " beantwortet ";
}
/**
* @param ilUserQuestionResult $result
* @param string $comperator
* @param null|int $index
*
* @return bool
*/
public function checkResult($result, $comperator, $index = null)
{
$isTrue = false;
if($index == null)
{
$values = $result->getUserSolutionsByIdentifier("key");
/**
* @param ilUserQuestionResult $result
* @param string $comperator
* @param null|int $index
*
* @return bool
*/
public function checkResult($result, $comperator, $index = null)
{
$isTrue = false;
if ($index == null) {
$values = $result->getUserSolutionsByIdentifier("key");
foreach($values as $value)
{
$isTrue = $isTrue || $this->compare($comperator, $value);
}
}
else
{
$solution = $result->getSolutionForKey($index);
$isTrue = $this->compare($comperator, $solution["value"]);
}
foreach ($values as $value) {
$isTrue = $isTrue || $this->compare($comperator, $value);
}
} else {
$solution = $result->getSolutionForKey($index);
$isTrue = $this->compare($comperator, $solution["value"]);
}
return $isTrue;
}
return $isTrue;
}
private function compare($comperator, $value)
{
switch($comperator)
{
case "=":
return $value == $this->getNumericValue();
break;
case "<>":
return $value != $this->getNumericValue();
break;
default:
return false;
}
}
private function compare($comperator, $value)
{
switch ($comperator) {
case "=":
return $value == $this->getNumericValue();
break;
case "<>":
return $value != $this->getNumericValue();
break;
default:
return false;
}
}
}
......@@ -9,124 +9,119 @@ include_once "SolutionExpressionInterface.php";
* Date: 25.03.13
* Time: 16:41
* @author Thomas Joußen <tjoussen@databay.de>
*/
*/
class NumericResultExpression extends AbstractExpression implements SolutionExpressionInterface
{
/**
* The pattern <b>"/#[0-9]+#/"</b> should match the following expression in a condition <br />
* <br />
* <pre>
* <b>#n#</b> "n" is a Placeholder for a numeric value
* * </pre>
* It is used to create a NumericResultExpression
/**
* The pattern <b>"/#[0-9]+#/"</b> should match the following expression in a condition <br />
* <br />
* <pre>
* <b>#n#</b> "n" is a Placeholder for a numeric value
* * </pre>
* It is used to create a NumericResultExpression
* @see NumericResultExpression
* @var string
*/
public static $pattern = '/#-?[0-9\.]+#/';
* @see NumericResultExpression
* @var string
*/
public static $pattern = '/#-?[0-9\.]+#/';
/**
* @var string
*/
public static $identifier = "#n#";
/**
* @var string
*/
public static $identifier = "#n#";
/**
* A numeric value which should be compared
*
* @var float
*/
protected $numeric_value;
/**
* A numeric value which should be compared
*
* @var float
*/
protected $numeric_value;
/**
* 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->numeric_value = $matches[0][0];
}
/**
* 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->numeric_value = $matches[0][0];
}
/**
* @return float
*/
public function getNumericValue()
{
return $this->numeric_value;
}
/**
* @return float
*/
public function getNumericValue()
{
return $this->numeric_value;
}
/**
* Get the value of this Expression
* @return string
*/
public function getValue()
{
return "#" . $this->numeric_value . "#";
}
/**
* Get the value of this Expression
* @return string
*/
public function getValue()
{
return "#" . $this->numeric_value . "#";
}
/**
* Get a human readable description of the Composite element
* @return string
*/
public function getDescription()
{
return $this->numeric_value . " beantwortet ";
}
/**
* Get a human readable description of the Composite element
* @return string
*/
public function getDescription()
{
return $this->numeric_value . " beantwortet ";
}
/**
* @param ilUserQuestionResult $result
* @param string $comperator
* @param null|int $index
*
* @return bool
*/
public function checkResult($result, $comperator, $index = null)
{
$isTrue = false;
if($index == null)
{
$values = $result->getUserSolutionsByIdentifier("value");
/**
* @param ilUserQuestionResult $result
* @param string $comperator
* @param null|int $index
*
* @return bool
*/
public function checkResult($result, $comperator, $index = null)
{
$isTrue = false;
if ($index == null) {
$values = $result->getUserSolutionsByIdentifier("value");
foreach($values as $value)
{
$isTrue = $isTrue || $this->compare($comperator, $value);
}
}
else
{
$solution = $result->getSolutionForKey($index);
$isTrue = $this->compare($comperator, $solution["value"]);
}
foreach ($values as $value) {
$isTrue = $isTrue || $this->compare($comperator, $value);
}
} else {
$solution = $result->getSolutionForKey($index);
$isTrue = $this->compare($comperator, $solution["value"]);
}
return $isTrue;
}
return $isTrue;
}
private function compare($comperator, $value)
{
switch($comperator)
{
case "<":
return $value < $this->getNumericValue();
break;
case "<=":
return $value <= $this->getNumericValue();
break;
case "=":
return $value == $this->getNumericValue();
break;
case ">=":
return $value >= $this->getNumericValue();
break;
case ">":
return $value > $this->getNumericValue();
break;
case "<>":
return $value != $this->getNumericValue();
break;
default:
return false;
}
}
private function compare($comperator, $value)
{
switch ($comperator) {
case "<":
return $value < $this->getNumericValue();
break;
case "<=":
return $value <= $this->getNumericValue();
break;
case "=":
return $value == $this->getNumericValue();
break;
case ">=":
return $value >= $this->getNumericValue();
break;
case ">":
return $value > $this->getNumericValue();
break;
case "<>":
return $value != $this->getNumericValue();
break;
default:
return false;
}
}
}
......@@ -9,105 +9,103 @@ include_once "SolutionExpressionInterface.php";
* Date: 25.03.13
* Time: 16:41
* @author Thomas Joußen <tjoussen@databay.de>
*/
*/
class OrderingResultExpression extends AbstractExpression implements SolutionExpressionInterface
{
/**
* The pattern <b>"/\$[0-9]+(?:,[0-9]+)*\$/"</b> should match the following expression in a condition <br />
* <br />
* <pre>
* <b>$a,..,n,m$</b> all characters are placeholders for numeric indices
* </pre>
* It is used to create a OrderingResultExpression
*
* @var string
*/
public static $pattern = '/\$[0-9]+(?:,[0-9]+)*\$/';
/**
* The pattern <b>"/\$[0-9]+(?:,[0-9]+)*\$/"</b> should match the following expression in a condition <br />
* <br />
* <pre>
* <b>$a,..,n,m$</b> all characters are placeholders for numeric indices
* </pre>
* It is used to create a OrderingResultExpression
*
* @var string
*/
public static $pattern = '/\$[0-9]+(?:,[0-9]+)*\$/';
/**
* @var string
*/
public static $identifier = '$n,m,o,p$';
/**
* @var string
*/
public static $identifier = '$n,m,o,p$';
/**
* An ordered array with numeric indices of elements
*
* @var int[]
*/
protected $ordering;
/**
* An ordered array with numeric indices of elements
*
* @var int[]
*/
protected $ordering;
protected function getPattern()
{
return '/(\d+)/';
}
protected function getPattern()
{
return '/(\d+)/';
}
/**
* 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->ordering = array();
/**
* 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->ordering = array();
foreach($matches[0] as $match)
{
$this->ordering[] = $match;
}
}
foreach ($matches[0] as $match) {
$this->ordering[] = $match;
}
}
/**
* @return \int[]
*/
public function getOrdering()
{
return $this->ordering;
}
/**
* @return \int[]
*/
public function getOrdering()
{
return $this->ordering;
}
/**
* Get the value of this Expression
* @return string
*/
public function getValue()
{
return "$" . join(",", $this->ordering) . "$";
}
/**
* Get the value of this Expression
* @return string
*/
public function getValue()
{
return "$" . join(",", $this->ordering) . "$";
}
/**
* Get a human readable description of the Composite element
* @return string
*/
public function getDescription()
{
return join(",", $this->ordering) . " beantwortet ";
}
/**
* Get a human readable description of the Composite element
* @return string
*/
public function getDescription()
{
return join(",", $this->ordering) . " beantwortet ";
}
/**
* @param ilUserQuestionResult $result
* @param string $comperator
* @param null|int $index
*
* @return bool
*/
public function checkResult($result, $comperator, $index = null)
{
$keys = $result->getUserSolutionsByIdentifier("key");
$keys = array_filter($keys,function($element) {
return $element != null;
});
/**
* @param ilUserQuestionResult $result
* @param string $comperator
* @param null|int $index
*
* @return bool
*/
public function checkResult($result, $comperator, $index = null)
{
$keys = $result->getUserSolutionsByIdentifier("key");
$keys = array_filter($keys, function ($element) {
return $element != null;
});
switch($comperator)
{
case "=":
return $keys == $this->getOrdering();
break;
case "<>":
return $keys != $this->getOrdering();
break;
default:
return false;
}
}
switch ($comperator) {
case "=":
return $keys == $this->getOrdering();
break;
case "<>":
return $keys != $this->getOrdering();
break;
default:
return false;
}
}
}
......@@ -9,104 +9,103 @@ include_once "SolutionExpressionInterface.php";
* Date: 25.03.13
* Time: 16:40
* @author Thomas Joußen <tjoussen@databay.de>
*/
*/
class PercentageResultExpression extends AbstractExpression implements SolutionExpressionInterface
{
/**
* The pattern <b>"/%[0-9]+%/"</b> should match the following expression in a condition <br />
* <br />
* <pre>
* <b>%n%</b> "n" is a Placeholder for a numeric value
* </pre>
* It is used to create a PercentageResultExpression
/**
* The pattern <b>"/%[0-9]+%/"</b> should match the following expression in a condition <br />
* <br />
* <pre>
* <b>%n%</b> "n" is a Placeholder for a numeric value
* </pre>
* It is used to create a PercentageResultExpression
* @see PercentageResultExpression
* @var string
*/
public static $pattern = '/%[0-9\.]+%/';
* @see PercentageResultExpression
* @var string
*/
public static $pattern = '/%[0-9\.]+%/';
/**
* @var string
*/
public static $identifier = "%n%";
/**
* @var string
*/
public static $identifier = "%n%";
/**
* An numeric value whicht should be compared as percentage
*
* @var float
*/
protected $numeric_value;
/**
* An numeric value whicht should be compared as percentage
*
* @var float
*/
protected $numeric_value;
/**
* 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->numeric_value = $matches[0][0];
}
/**
* 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->numeric_value = $matches[0][0];
}
/**
* @return float
*/
public function getNumericValue()
{
return $this->numeric_value;
}
/**
* @return float
*/
public function getNumericValue()
{
return $this->numeric_value;
}
/**
* Get the value of this Expression
* @return string
*/
public function getValue()
{
return "%" . $this->numeric_value . "%";
}
/**
* Get the value of this Expression
* @return string
*/
public function getValue()
{
return "%" . $this->numeric_value . "%";
}
/**
* Get a human readable description of the Composite element
* @return string
*/
public function getDescription()
{
return $this->numeric_value . "% beantwortet ";
}
/**
* Get a human readable description of the Composite element
* @return string
*/
public function getDescription()
{
return $this->numeric_value . "% beantwortet ";
}
/**
* @param ilUserQuestionResult $result
* @param string $comperator
* @param null $index
*
* @return bool
*/
public function checkResult($result, $comperator, $index = null)
{
$percentage = $result->getReachedPercentage();
switch($comperator)
{
case "<":
return $percentage < $this->getNumericValue();
break;
case "<=":
return $percentage <= $this->getNumericValue();
break;
case "=":
return $percentage == $this->getNumericValue();
break;
case ">=":
return $percentage >= $this->getNumericValue();
break;
case ">":
return $percentage > $this->getNumericValue();
break;
case "<>":
return $percentage != $this->getNumericValue();
break;
default:
return false;
}
}
/**
* @param ilUserQuestionResult $result
* @param string $comperator
* @param null $index
*
* @return bool
*/
public function checkResult($result, $comperator, $index = null)
{
$percentage = $result->getReachedPercentage();
switch ($comperator) {
case "<":
return $percentage < $this->getNumericValue();
break;
case "<=":
return $percentage <= $this->getNumericValue();
break;
case "=":
return $percentage == $this->getNumericValue();
break;
case ">=":
return $percentage >= $this->getNumericValue();
break;
case ">":
return $percentage > $this->getNumericValue();
break;
case "<>":
return $percentage != $this->getNumericValue();
break;
default:
return false;
}
}
}
......@@ -7,8 +7,7 @@
* @author Thomas Joußen <tjoussen@databay.de>
*/
interface QuestionExpressionInterface {
public function getQuestionIndex();
}
\ No newline at end of file
interface QuestionExpressionInterface
{
public function getQuestionIndex();
}
......@@ -9,94 +9,95 @@ require_once "QuestionExpressionInterface.php";
* Date: 25.03.13
* Time: 16:40
* @author Thomas Joußen <tjoussen@databay.de>
*/
class ResultOfAnswerOfQuestionExpression extends AbstractExpression implements QuestionExpressionInterface{
/**
* The pattern <b>"/Q[0-9]+\\[[0-9]+\\]/"</b> should match the following expression in a condition <br />
* <br />
* <pre>
* <b>Qn[m]</b> "n" is a Placeholder for a numeric question index
* "m" is a Placeholde for a numeric answer index of a question
* </pre>
* It is used to create a ResultOfAnswerOfQuestioExpression
*/
class ResultOfAnswerOfQuestionExpression extends AbstractExpression implements QuestionExpressionInterface
{
/**
* The pattern <b>"/Q[0-9]+\\[[0-9]+\\]/"</b> should match the following expression in a condition <br />
* <br />
* <pre>
* <b>Qn[m]</b> "n" is a Placeholder for a numeric question index
* "m" is a Placeholde for a numeric answer index of a question
* </pre>
* It is used to create a ResultOfAnswerOfQuestioExpression
* @see ResultOfAnswerOfQuestionExpression
* @var string
*/
public static $pattern = "/Q[0-9]+\\[[0-9]+\\]/";
* @see ResultOfAnswerOfQuestionExpression
* @var string
*/
public static $pattern = "/Q[0-9]+\\[[0-9]+\\]/";
/**
* @var string
*/
public static $identifier = "Qn[m]";
/**
* @var string
*/
public static $identifier = "Qn[m]";
/**
* The index of a question
*
* @var int
*/
protected $question_index;
/**
* The index of a question
*
* @var int
*/
protected $question_index;
/**
* The indes of an answer of a question
*
* @var int
*/
protected $answer_index;
/**
* The indes of an answer of a question
*
* @var int
*/
protected $answer_index;
/**
* Get the Pattern to match relevant informations for an Expression
* @return string
*/
public function getPattern()
{
return '/(\d+)\[(\d+)\]/';
}
/**
* Get the Pattern to match relevant informations for an Expression
* @return string
*/
public function getPattern()
{
return '/(\d+)\[(\d+)\]/';
}
/**
* 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->question_index = $matches[1][0];
$this->answer_index = $matches[2][0];
}
/**
* 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->question_index = $matches[1][0];
$this->answer_index = $matches[2][0];
}
/**
* @return int
*/
public function getQuestionIndex()
{
return $this->question_index;
}
/**
* @return int
*/
public function getQuestionIndex()
{
return $this->question_index;
}
/**
* @return int
*/
public function getAnswerIndex()
{
return $this->answer_index;
}
/**
* @return int
*/
public function getAnswerIndex()
{
return $this->answer_index;
}
/**
* Get the value of this Expression
* @return string
*/
public function getValue()
{
return "Q" . $this->question_index . '[' . $this->answer_index . ']';
}
/**
* Get the value of this Expression
* @return string
*/
public function getValue()
{
return "Q" . $this->question_index . '[' . $this->answer_index . ']';
}
/**
* Get a human readable description of the Composite element
* @return string
*/
public function getDescription()
{
return "Frage " . $this->question_index . " mit Anwort " . $this->answer_index . " beantwortet ";
}
/**
* Get a human readable description of the Composite element
* @return string
*/
public function getDescription()
{
return "Frage " . $this->question_index . " mit Anwort " . $this->answer_index . " beantwortet ";
}
}
......@@ -9,12 +9,12 @@
interface SolutionExpressionInterface
{
/**
* @param ilUserQuestionResult $result
* @param string $comperator
* @param null|int $index
*
* @return bool
*/
public function checkResult($result, $comperator, $index = null);
}
\ No newline at end of file
/**
* @param ilUserQuestionResult $result
* @param string $comperator
* @param null|int $index
*
* @return bool
*/
public function checkResult($result, $comperator, $index = null);
}
......@@ -10,127 +10,122 @@ include_once "SolutionExpressionInterface.php";
* Date: 25.03.13
* Time: 16:41
* @author Thomas Joußen <tjoussen@databay.de>
*/
*/
class StringResultExpression extends AbstractExpression implements SolutionExpressionInterface
{
/**
* The pattern <b>"/~.*?~/"</b> should match the following expression in a condition <br />
* <br />
* <pre>
* <b>~TEXT~</b> "TEXT" is a Placeholder for string value
* </pre>
* It is used to create a StringResultExpression
/**
* The pattern <b>"/~.*?~/"</b> should match the following expression in a condition <br />
* <br />
* <pre>
* <b>~TEXT~</b> "TEXT" is a Placeholder for string value
* </pre>
* It is used to create a StringResultExpression
* @see StringResultExpression
* @var string
*/
public static $pattern = "/~.*?~/";
* @see StringResultExpression
* @var string
*/
public static $pattern = "/~.*?~/";
/**
* @var string
*/
public static $identifier = "~TEXT~";
/**
* @var string
*/
public static $identifier = "~TEXT~";
/**
* A text value which should be compared
*
* @var string
*/
protected $text;
/**
* A text value which should be compared
*
* @var string
*/
protected $text;
/**
* Get the Pattern to match relevant informations for an Expression
* @return string
*/
public function getPattern()
{
return '/~(.*)~/';
}
/**
* Get the Pattern to match relevant informations for an Expression
* @return string
*/
public function getPattern()
{
return '/~(.*)~/';
}
/**
* 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->text = $matches[1][0];
}
/**
* 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->text = $matches[1][0];
}
/**
* @return string
*/
public function getText()
{
return $this->text;
}
/**
* @return string
*/
public function getText()
{
return $this->text;
}
/**
* Get the value of this Expression
* @return string
*/
public function getValue()
{
return "~" . $this->text . '~';
}
/**
* Get the value of this Expression
* @return string
*/
public function getValue()
{
return "~" . $this->text . '~';
}
/**
* Get a human readable description of the Composite element
* @return string
*/
public function getDescription()
{
return $this->text . " beantwortet ";
}
/**
* Get a human readable description of the Composite element
* @return string
*/
public function getDescription()
{
return $this->text . " beantwortet ";
}
/**
* @param ilUserQuestionResult $result
* @param string $comperator
* @param int $index
*
* @return bool
*/
public function checkResult($result, $comperator, $index = null)
{
$isTrue = false;
if($index == null)
{
$values = $result->getUserSolutionsByIdentifier("value");
/**
* @param ilUserQuestionResult $result
* @param string $comperator
* @param int $index
*
* @return bool
*/
public function checkResult($result, $comperator, $index = null)
{
$isTrue = false;
if ($index == null) {
$values = $result->getUserSolutionsByIdentifier("value");
foreach($values as $value)
{
$isTrue = $isTrue || $this->compare($comperator, $value);
}
}
else
{
$solution = $result->getSolutionForKey($index);
$isTrue = $this->compare($comperator, $solution["value"]);
}
foreach ($values as $value) {
$isTrue = $isTrue || $this->compare($comperator, $value);
}
} else {
$solution = $result->getSolutionForKey($index);
$isTrue = $this->compare($comperator, $solution["value"]);
}
return $isTrue;
}
return $isTrue;
}
/**
* @param string $comperator
* @param mixed $value
*
* @return bool
*/
private function compare($comperator, $value)
{
switch($comperator)
{
case "=":
return $this->getText() == $value;
break;
case "<>":
return $this->getText() != $value;
break;
default:
return false;
}
}
/**
* @param string $comperator
* @param mixed $value
*
* @return bool
*/
private function compare($comperator, $value)
{
switch ($comperator) {
case "=":
return $this->getText() == $value;
break;
case "<>":
return $this->getText() != $value;
break;
default:
return false;
}
}
}
......@@ -8,33 +8,33 @@ include_once "ManufacturerInterface.php";
* Date: 26.03.13
* Time: 15:13
* @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
*
* @param string $subject
* @throws UnableToParseCondition
*
* @see ManufacturerInterface::getPattern()
* @return array
*/
public function match($subject)
{
$matches = array();
$num_matches = preg_match_all($this->getPattern(), $subject, $matches);
/**
* Matches a delivered string with a the pattern returned by getPattern implemented in the explicit Manufacturer
*
* @param string $subject
* @throws UnableToParseCondition
*
* @see ManufacturerInterface::getPattern()
* @return array
*/
public function match($subject)
{
$matches = array();
$num_matches = preg_match_all($this->getPattern(), $subject, $matches);
if($num_matches == 0)
{
require_once __DIR__ . '/../Exception/UnableToParseCondition.php';
throw new UnableToParseCondition($subject);
}
// Trims each element in the matches array
$matches = array_map(function($element){
return trim($element);
}, $matches[0]);
if ($num_matches == 0) {
require_once __DIR__ . '/../Exception/UnableToParseCondition.php';
throw new UnableToParseCondition($subject);
}
// Trims each element in the matches array
$matches = array_map(function ($element) {
return trim($element);
}, $matches[0]);
return $matches;
}
return $matches;
}
}
......@@ -8,137 +8,141 @@ include_once "AbstractManufacturer.php";
* Date: 25.03.13
* Time: 15:12
* @author Thomas Joußen <tjoussen@databay.de>
*/
class ExpressionManufacturer extends AbstractManufacturer{
*/
class ExpressionManufacturer extends AbstractManufacturer
{
/**
* A Singleton Instance of the ExpressionManufacturer
*
* @see ExpressionManufacturer::_getInstance()
* @see ExpressionManufacturer::__construct()
*
* @var null|ExpressionManufacturer
*/
protected static $instance = null;
/**
* A Singleton Instance of the ExpressionManufacturer
*
* @see ExpressionManufacturer::_getInstance()
* @see ExpressionManufacturer::__construct()
*
* @var null|ExpressionManufacturer
*/
protected static $instance = null;
/**
* Get an Instance of ExpressionManufacturer
*
* @return ExpressionManufacturer
*/
public static function _getInstance()
{
if(self::$instance == null){
self::$instance = new ExpressionManufacturer();
}
return self::$instance;
}
/**
* Get an Instance of ExpressionManufacturer
*
* @return ExpressionManufacturer
*/
public static function _getInstance()
{
if (self::$instance == null) {
self::$instance = new ExpressionManufacturer();
}
return self::$instance;
}
/**
* /**
* Create a new specific Composite object which is representing the delivered Attribute
*
* @param string $attribute
*
* @return AbstractComposite|AnswerOfQuestionExpression|NumberOfResultExpression|NumericResultExpression|PercentageResultExpression|ResultOfAnswerOfQuestionExpression|StringResultExpression
* @throws UnsupportedExpression
*/
public function manufacture($attribute)
{
$expression = null;
/**
* /**
* Create a new specific Composite object which is representing the delivered Attribute
*
* @param string $attribute
*
* @return AbstractComposite|AnswerOfQuestionExpression|NumberOfResultExpression|NumericResultExpression|PercentageResultExpression|ResultOfAnswerOfQuestionExpression|StringResultExpression
* @throws UnsupportedExpression
*/
public function manufacture($attribute)
{
$expression = null;
switch(true)
{
case preg_match(ResultOfAnswerOfQuestionExpression::$pattern, $attribute):
$expression = new ResultOfAnswerOfQuestionExpression();
break;
case preg_match(AnswerOfQuestionExpression::$pattern, $attribute):
$expression = new AnswerOfQuestionExpression();
break;
case preg_match(PercentageResultExpression::$pattern, $attribute):
$expression = new PercentageResultExpression();
break;
case preg_match(NumberOfResultExpression::$pattern, $attribute):
$expression = new NumberOfResultExpression();
break;
case preg_match(NumericResultExpression::$pattern, $attribute):
$expression = new NumericResultExpression();
break;
case preg_match(StringResultExpression::$pattern, $attribute):
$expression = new StringResultExpression();
break;
case preg_match(MatchingResultExpression::$pattern, $attribute):
$expression = new MatchingResultExpression();
break;
case preg_match(OrderingResultExpression::$pattern, $attribute):
$expression = new OrderingResultExpression();
break;
case preg_match(ExclusiveResultExpression::$pattern, $attribute):
$expression = new ExclusiveResultExpression();
break;
case preg_match(EmptyAnswerExpression::$pattern, $attribute):
$expression = new EmptyAnswerExpression();
break;
default:
throw new UnsupportedExpression($attribute);
break;
}
switch (true) {
case preg_match(ResultOfAnswerOfQuestionExpression::$pattern, $attribute):
$expression = new ResultOfAnswerOfQuestionExpression();
break;
case preg_match(AnswerOfQuestionExpression::$pattern, $attribute):
$expression = new AnswerOfQuestionExpression();
break;
case preg_match(PercentageResultExpression::$pattern, $attribute):
$expression = new PercentageResultExpression();
break;
case preg_match(NumberOfResultExpression::$pattern, $attribute):
$expression = new NumberOfResultExpression();
break;
case preg_match(NumericResultExpression::$pattern, $attribute):
$expression = new NumericResultExpression();
break;
case preg_match(StringResultExpression::$pattern, $attribute):
$expression = new StringResultExpression();
break;
case preg_match(MatchingResultExpression::$pattern, $attribute):
$expression = new MatchingResultExpression();
break;
case preg_match(OrderingResultExpression::$pattern, $attribute):
$expression = new OrderingResultExpression();
break;
case preg_match(ExclusiveResultExpression::$pattern, $attribute):
$expression = new ExclusiveResultExpression();
break;
case preg_match(EmptyAnswerExpression::$pattern, $attribute):
$expression = new EmptyAnswerExpression();
break;
default:
throw new UnsupportedExpression($attribute);
break;
}
$expression->parseValue($attribute);
return $expression;
}
$expression->parseValue($attribute);
return $expression;
}
/**
* This function create a regular expression to match all expression in a condition. <br />
* The following string is created by this function <b>'/%[0-9]+%|#[0-9]+#|\+[0-9]+\+|Q[0-9]+([^\[|0-9]|$)|Q[0-9]+\[[0-9]+\]|~.*?~'</b><br />
* It matches all expression in a condition and is divided into the following parts:
*
* <pre>
* Qn /Q[0-9]+(?!\\[)/
* Qn[m] /Q[0-9]+\\[[0-9]+\\]/
* %n% /%[0-9]+%/
* +n+ /\\+[0-9]+\\+/
* #n# /#[0-9]+#/
* ~TEXT~ /~.*?~/ Hier gibt es noch Probleme, wenn im Text ein ~ enthalten ist
* </pre>
*
* @return string
*/
public function getPattern(){
return
"/" .
substr(PercentageResultExpression::$pattern, 1, strlen(PercentageResultExpression::$pattern) - 2) . "|" .
substr(NumericResultExpression::$pattern, 1, strlen(NumericResultExpression::$pattern) - 2) . "|" .
substr(NumberOfResultExpression::$pattern, 1, strlen(NumberOfResultExpression::$pattern) - 2) . "|" .
substr(AnswerOfQuestionExpression::$pattern, 1, strlen(AnswerOfQuestionExpression::$pattern) - 2) . "|" .
substr(ResultOfAnswerOfQuestionExpression::$pattern, 1, strlen(ResultOfAnswerOfQuestionExpression::$pattern) - 2) . "|" .
substr(StringResultExpression::$pattern, 1, strlen(StringResultExpression::$pattern) - 2) . "|" .
substr(MatchingResultExpression::$pattern, 1, strlen(MatchingResultExpression::$pattern) - 2) . "|" .
substr(OrderingResultExpression::$pattern, 1, strlen(OrderingResultExpression::$pattern) - 2) . "|" .
substr(ExclusiveResultExpression::$pattern, 1, strlen(ExclusiveResultExpression::$pattern) - 2) . "|" .
substr(EmptyAnswerExpression::$pattern, 1, strlen(EmptyAnswerExpression::$pattern) - 2) .
"/";
}
/**
* This function create a regular expression to match all expression in a condition. <br />
* The following string is created by this function <b>'/%[0-9]+%|#[0-9]+#|\+[0-9]+\+|Q[0-9]+([^\[|0-9]|$)|Q[0-9]+\[[0-9]+\]|~.*?~'</b><br />
* It matches all expression in a condition and is divided into the following parts:
*
* <pre>
* Qn /Q[0-9]+(?!\\[)/
* Qn[m] /Q[0-9]+\\[[0-9]+\\]/
* %n% /%[0-9]+%/
* +n+ /\\+[0-9]+\\+/
* #n# /#[0-9]+#/
* ~TEXT~ /~.*?~/ Hier gibt es noch Probleme, wenn im Text ein ~ enthalten ist
* </pre>
*
* @return string
*/
public function getPattern()
{
return
"/" .
substr(PercentageResultExpression::$pattern, 1, strlen(PercentageResultExpression::$pattern) - 2) . "|" .
substr(NumericResultExpression::$pattern, 1, strlen(NumericResultExpression::$pattern) - 2) . "|" .
substr(NumberOfResultExpression::$pattern, 1, strlen(NumberOfResultExpression::$pattern) - 2) . "|" .
substr(AnswerOfQuestionExpression::$pattern, 1, strlen(AnswerOfQuestionExpression::$pattern) - 2) . "|" .
substr(ResultOfAnswerOfQuestionExpression::$pattern, 1, strlen(ResultOfAnswerOfQuestionExpression::$pattern) - 2) . "|" .
substr(StringResultExpression::$pattern, 1, strlen(StringResultExpression::$pattern) - 2) . "|" .
substr(MatchingResultExpression::$pattern, 1, strlen(MatchingResultExpression::$pattern) - 2) . "|" .
substr(OrderingResultExpression::$pattern, 1, strlen(OrderingResultExpression::$pattern) - 2) . "|" .
substr(ExclusiveResultExpression::$pattern, 1, strlen(ExclusiveResultExpression::$pattern) - 2) . "|" .
substr(EmptyAnswerExpression::$pattern, 1, strlen(EmptyAnswerExpression::$pattern) - 2) .
"/";
}
/**
* Private constructor to prevent creating of an object of ExpressionManufacturer
*/
private function __construct(){
require_once __DIR__ . "/../Expressions/AnswerOfQuestionExpression.php";
require_once __DIR__ . "/../Expressions/ResultOfAnswerOfQuestionExpression.php";
require_once __DIR__ . "/../Expressions/PercentageResultExpression.php";
require_once __DIR__ . "/../Expressions/NumberOfResultExpression.php";
require_once __DIR__ . "/../Expressions/NumericResultExpression.php";
require_once __DIR__ . "/../Expressions/StringResultExpression.php";
require_once __DIR__ . "/../Expressions/MatchingResultExpression.php";
require_once __DIR__ . "/../Expressions/OrderingResultExpression.php";
require_once __DIR__ . "/../Expressions/ExclusiveResultExpression.php";
require_once __DIR__ . "/../Expressions/EmptyAnswerExpression.php";
require_once __DIR__ . '/../Exception/UnsupportedExpression.php';
}
/**
* Private constructor to prevent creating of an object of ExpressionManufacturer
*/
private function __construct()
{
require_once __DIR__ . "/../Expressions/AnswerOfQuestionExpression.php";
require_once __DIR__ . "/../Expressions/ResultOfAnswerOfQuestionExpression.php";
require_once __DIR__ . "/../Expressions/PercentageResultExpression.php";
require_once __DIR__ . "/../Expressions/NumberOfResultExpression.php";
require_once __DIR__ . "/../Expressions/NumericResultExpression.php";
require_once __DIR__ . "/../Expressions/StringResultExpression.php";
require_once __DIR__ . "/../Expressions/MatchingResultExpression.php";
require_once __DIR__ . "/../Expressions/OrderingResultExpression.php";
require_once __DIR__ . "/../Expressions/ExclusiveResultExpression.php";
require_once __DIR__ . "/../Expressions/EmptyAnswerExpression.php";
require_once __DIR__ . '/../Exception/UnsupportedExpression.php';
}
/**
* Private clone to prevent cloning an object of ExpressionManufacturer
*/
private function __clone() { }
/**
* Private clone to prevent cloning an object of ExpressionManufacturer
*/
private function __clone()
{
}
}