Skip to content
GitLab
Explore
Sign in
formatest
FormATest_QuestionSetPool
Compare revisions
dac62171f9f4b208778bdbb4996d236af1fe3adc to 381d5850e2bde24749dbdf4affb7ff3984e296ea
Expand all
Hide whitespace changes
Inline
Side-by-side
Parser/classes/Exception/QuestionNotReachable.php
View file @
381d5850
...
...
@@ -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
;
}
}
Parser/classes/Exception/UnableToParseCondition.php
View file @
381d5850
...
...
@@ -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
;
}
}
Parser/classes/Exception/UnsupportedExpression.php
View file @
381d5850
...
...
@@ -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
;
}
}
Parser/classes/Exception/UnsupportedOperation.php
View file @
381d5850
...
...
@@ -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
;
}
}
Parser/classes/Expressions/AbstractExpression.php
View file @
381d5850
<?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
);
}
Parser/classes/Expressions/AnswerOfQuestionExpression.php
View file @
381d5850
...
...
@@ -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]+/'
;
}
}
Parser/classes/Expressions/EmptyAnswerExpression.php
View file @
381d5850
...
...
@@ -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
$
patt
er
n
=
'/(\?)/'
;
public
static
$
identifi
er
=
"?"
;
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
get
Value
()
{
return
"?
"
;
}
/**
* Get
a human readable description of the Composite element
* @return string
*/
public
function
get
Description
()
{
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
Parser/classes/Expressions/ExclusiveResultExpression.php
View file @
381d5850
...
...
@@ -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
;
}
}
}
Parser/classes/Expressions/ExpressionInterface.php
View file @
381d5850
...
...
@@ -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
);
}
Parser/classes/Expressions/MatchingResultExpression.php
View file @
381d5850
...
...
@@ -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
;
}
}
}
Parser/classes/Expressions/NumberOfResultExpression.php
View file @
381d5850
...
...
@@ -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
;
}
}
}
Parser/classes/Expressions/NumericResultExpression.php
View file @
381d5850
...
...
@@ -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
;
}
}
}
Parser/classes/Expressions/OrderingResultExpression.php
View file @
381d5850
This diff is collapsed.
Click to expand it.
Parser/classes/Expressions/PercentageResultExpression.php
View file @
381d5850
This diff is collapsed.
Click to expand it.
Parser/classes/Expressions/QuestionExpressionInterface.php
View file @
381d5850
...
...
@@ -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
();
}
Parser/classes/Expressions/ResultOfAnswerOfQuestionExpression.php
View file @
381d5850
This diff is collapsed.
Click to expand it.
Parser/classes/Expressions/SolutionExpressionInterface.php
View file @
381d5850
...
...
@@ -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
);
}
Parser/classes/Expressions/StringResultExpression.php
View file @
381d5850
This diff is collapsed.
Click to expand it.
Parser/classes/Factory/AbstractManufacturer.php
View file @
381d5850
...
...
@@ -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
;
}
}
Parser/classes/Factory/ExpressionManufacturer.php
View file @
381d5850
This diff is collapsed.
Click to expand it.
Prev
1
2
3
4
5
6
7
Next