diff --git a/Parser/Tests/CompositeBuilderTest.php b/Parser/Tests/CompositeBuilderTest.php index f5579b1f01899f95c541f140602dda1456d0e723..0951a67d8f104405e4829d78b21d50a9fff4c793 100644 --- a/Parser/Tests/CompositeBuilderTest.php +++ b/Parser/Tests/CompositeBuilderTest.php @@ -7,23 +7,25 @@ * Time: 13:51 * @author Thomas Joußen */ -class CompositeBuilderTest extends PHPUnit_Framework_TestCase { +class CompositeBuilderTest extends PHPUnit_Framework_TestCase +{ - /** - * @var CompositeBuilder - */ - protected $builder; + /** + * @var CompositeBuilder + */ + protected $builder; - public function setUp(){ - include_once __DIR__ . '/../classes/CompositeBuilder.php'; - $this->builder = new CompositeBuilder; - } + public function setUp() + { + include_once __DIR__ . '/../classes/CompositeBuilder.php'; + $this->builder = new CompositeBuilder; + } - public function test_OperatorsWeight() - { - $weight = array('<=','<','=','>=','>','<>','&','|'); - $operators = $this->readAttribute($this->builder, "operators"); + public function test_OperatorsWeight() + { + $weight = array('<=','<','=','>=','>','<>','&','|'); + $operators = $this->readAttribute($this->builder, "operators"); - $this->assertEmpty(array_diff($weight, $operators)); - } + $this->assertEmpty(array_diff($weight, $operators)); + } } diff --git a/Parser/Tests/ConditionParserProxy.php b/Parser/Tests/ConditionParserProxy.php index f4c253224d9b56385fdef3b68b684cf553b4d610..3c87c563cea03fcddb148413840567908ca3f6c6 100644 --- a/Parser/Tests/ConditionParserProxy.php +++ b/Parser/Tests/ConditionParserProxy.php @@ -8,56 +8,55 @@ include_once __DIR__ . '/../classes/ConditionParser.php'; * Date: 25.03.13 * Time: 11:05 * @author Thomas Joußen - */ -class ConditionParserProxy extends ConditionParser{ - - public function fetchExpressions() - { - parent::fetchExpressions(); // TODO: Change the autogenerated stub - } - - public function fetchOperators() - { - parent::fetchOperators(); // TODO: Change the autogenerated stub - } - - public function cannonicalizeCondition() - { - parent::cannonicalizeCondition(); // TODO: Change the autogenerated stub - } - - public function createNodeArray() - { - return parent::createNodeArray(); // TODO: Change the autogenerated stub - } - - public function setCondition($condition) - { - $this->condition = $condition; - } - - /** - * @return string - */ - public function getCondition() - { - return $this->condition; - } - - /** - * @return array - */ - public function getExpressions() - { - return $this->expressions; - } - - /** - * @return array - */ - public function getOperators() - { - return $this->operators; - } - + */ +class ConditionParserProxy extends ConditionParser +{ + public function fetchExpressions() + { + parent::fetchExpressions(); // TODO: Change the autogenerated stub + } + + public function fetchOperators() + { + parent::fetchOperators(); // TODO: Change the autogenerated stub + } + + public function cannonicalizeCondition() + { + parent::cannonicalizeCondition(); // TODO: Change the autogenerated stub + } + + public function createNodeArray() + { + return parent::createNodeArray(); // TODO: Change the autogenerated stub + } + + public function setCondition($condition) + { + $this->condition = $condition; + } + + /** + * @return string + */ + public function getCondition() + { + return $this->condition; + } + + /** + * @return array + */ + public function getExpressions() + { + return $this->expressions; + } + + /** + * @return array + */ + public function getOperators() + { + return $this->operators; + } } diff --git a/Parser/Tests/ConditionParserTest.php b/Parser/Tests/ConditionParserTest.php index d9627b90edbeec453606c0696ee3f1413201c485..f873ad0d212e27c963caef6369fdea85037aed3c 100644 --- a/Parser/Tests/ConditionParserTest.php +++ b/Parser/Tests/ConditionParserTest.php @@ -8,159 +8,156 @@ * Time: 16:08 * @author Thomas Joußen */ -class ConditionParserTest extends \PHPUnit_Framework_TestCase { - - protected $key_constraint; - protected $type_constraint; - protected $array_constraint; - - /** - * @var null|ConditionParserProxy - */ - protected $parser = null; - - protected static $CONDITION = "Q5 = +32+ & (Q74 <= %9879% | Q5 >= #5#)"; - protected static $EXPECTED_EXPRESSIONS = array("Q5","+32+","Q74","%9879%","Q5","#5#"); - protected static $EXPECTED_OPERATORS = array("=","&","<=","|",">="); - protected static $CANNONICALIZED_CONDITION = "n o n o (n o n o n o n)"; - - public function setUp(){ - include_once 'ConditionParserProxy.php'; - include_once __DIR__ . '/../classes/AbstractComposite.php'; - $this->parser = new ConditionParserProxy(); - - - $this->key_constraint = $this->logicalOr( - $this->equalTo("type"), - $this->equalTo("value"), - $this->equalTo("negated") - ); - $this->type_constraint = $this->logicalOr( - $this->equalTo("group"), - $this->equalTo("expression"), - $this->equalTo("operator") - ); - $this->array_constraint = $this->logicalOr( - $this->equalTo("nodes"), - $this->isType("integer") - ); - } - - public function test_construction() - { - $this->assertInstanceOf('ConditionParser', $this->parser); - } - - public function test_FetchExpressions() - { - $this->parser->setCondition(self::$CONDITION); - $this->parser->fetchExpressions(); - - foreach(self::$EXPECTED_EXPRESSIONS as $expression){ - $this->assertContains($expression, $this->parser->getExpressions()); - } - } - - public function test_FetchOperators() - { - $this->parser->setCondition(self::$CONDITION); - $this->parser->fetchOperators(); - - foreach(self::$EXPECTED_OPERATORS as $operator){ - $this->assertContains($operator, $this->parser->getOperators()); - } - } - - public function test_CannonicalizeCondition() - { - $this->parser->setCondition(self::$CONDITION); - $this->parser->fetchExpressions(); - $this->parser->fetchOperators(); - $this->parser->cannonicalizeCondition(); - $this->assertEquals(self::$CANNONICALIZED_CONDITION, $this->parser->getCondition()); - } - - public function test_CreateNodeArray() - { - $this->parser->setCondition(self::$CONDITION); - $this->parser->fetchExpressions(); - $this->parser->fetchOperators(); - $this->parser->cannonicalizeCondition(); - $node_array = $this->parser->createNodeArray(); - - $this->recursiveNodeTest($node_array); - } - - public function test_Parse() - { - $composite = $this->parser->parse(self::$CONDITION); - $this->assertInstanceOf("AbstractComposite", $composite); - } - - /** - * @expectedException UnableToParseCondition - */ - public function test_Nonsense() - { - $composite = $this->parser->parse("1 = 1"); - } - - public function test_DescribeComposite() - { - $composite = $this->parser->parse("Q1[2] & (Q2[1] | Q2[2])"); - $this->assertInstanceOf("AbstractComposite", $composite); - $description = $composite->describe(); - $expected = "(Frage 1 mit Anwort 2 beantwortet und (Frage 2 mit Anwort 1 beantwortet oder Frage 2 mit Anwort 2 beantwortet ) ) "; - $this->assertEquals($expected, $description); - } - - /** - * @expectedException ConditionParserException - */ - public function test_Issue1338() - { - $condition = "Q85[1]=~nach oben geöffnete Parabel~ &|Q85[2]=#0# | Q85[8]=+2+ !Q85[9]=+2+"; - $this->parser->setCondition($condition); - $this->parser->fetchExpressions(); - $this->parser->getOperators(); - $this->parser->cannonicalizeCondition(); - $this->parser->parse($condition); - } - - public function test_Replacing() - { - $condition = "Q5 = +2+ & !Q2 < #3# | !Q5 <= %100%"; - $this->parser->setCondition($condition); - $this->parser->fetchExpressions(); - $this->parser->getOperators(); - $this->parser->cannonicalizeCondition(); - - $this->assertEquals("n o n o !(n o n) o !(n o n)", $this->parser->getCondition()); - } - - private function recursiveNodeTest($nodes){ - foreach($nodes as $key => $node) - { - if(!is_array($node)) - { - $this->assertThat($key, $this->key_constraint); - if($key == "type") - { - $this->assertThat($node, $this->type_constraint); - } - } - else - { - $this->assertThat($key, $this->array_constraint); - $this->recursiveNodeTest($node); - } - } - } - - public function test_missingSpaces() - { - $condition = "Q1=%100%"; - $composite = $this->parser->parse($condition); - $this->assertInstanceOf("AbstractComposite", $composite); - } +class ConditionParserTest extends \PHPUnit_Framework_TestCase +{ + protected $key_constraint; + protected $type_constraint; + protected $array_constraint; + + /** + * @var null|ConditionParserProxy + */ + protected $parser = null; + + protected static $CONDITION = "Q5 = +32+ & (Q74 <= %9879% | Q5 >= #5#)"; + protected static $EXPECTED_EXPRESSIONS = array("Q5","+32+","Q74","%9879%","Q5","#5#"); + protected static $EXPECTED_OPERATORS = array("=","&","<=","|",">="); + protected static $CANNONICALIZED_CONDITION = "n o n o (n o n o n o n)"; + + public function setUp() + { + include_once 'ConditionParserProxy.php'; + include_once __DIR__ . '/../classes/AbstractComposite.php'; + $this->parser = new ConditionParserProxy(); + + + $this->key_constraint = $this->logicalOr( + $this->equalTo("type"), + $this->equalTo("value"), + $this->equalTo("negated") + ); + $this->type_constraint = $this->logicalOr( + $this->equalTo("group"), + $this->equalTo("expression"), + $this->equalTo("operator") + ); + $this->array_constraint = $this->logicalOr( + $this->equalTo("nodes"), + $this->isType("integer") + ); + } + + public function test_construction() + { + $this->assertInstanceOf('ConditionParser', $this->parser); + } + + public function test_FetchExpressions() + { + $this->parser->setCondition(self::$CONDITION); + $this->parser->fetchExpressions(); + + foreach (self::$EXPECTED_EXPRESSIONS as $expression) { + $this->assertContains($expression, $this->parser->getExpressions()); + } + } + + public function test_FetchOperators() + { + $this->parser->setCondition(self::$CONDITION); + $this->parser->fetchOperators(); + + foreach (self::$EXPECTED_OPERATORS as $operator) { + $this->assertContains($operator, $this->parser->getOperators()); + } + } + + public function test_CannonicalizeCondition() + { + $this->parser->setCondition(self::$CONDITION); + $this->parser->fetchExpressions(); + $this->parser->fetchOperators(); + $this->parser->cannonicalizeCondition(); + $this->assertEquals(self::$CANNONICALIZED_CONDITION, $this->parser->getCondition()); + } + + public function test_CreateNodeArray() + { + $this->parser->setCondition(self::$CONDITION); + $this->parser->fetchExpressions(); + $this->parser->fetchOperators(); + $this->parser->cannonicalizeCondition(); + $node_array = $this->parser->createNodeArray(); + + $this->recursiveNodeTest($node_array); + } + + public function test_Parse() + { + $composite = $this->parser->parse(self::$CONDITION); + $this->assertInstanceOf("AbstractComposite", $composite); + } + + /** + * @expectedException UnableToParseCondition + */ + public function test_Nonsense() + { + $composite = $this->parser->parse("1 = 1"); + } + + public function test_DescribeComposite() + { + $composite = $this->parser->parse("Q1[2] & (Q2[1] | Q2[2])"); + $this->assertInstanceOf("AbstractComposite", $composite); + $description = $composite->describe(); + $expected = "(Frage 1 mit Anwort 2 beantwortet und (Frage 2 mit Anwort 1 beantwortet oder Frage 2 mit Anwort 2 beantwortet ) ) "; + $this->assertEquals($expected, $description); + } + + /** + * @expectedException ConditionParserException + */ + public function test_Issue1338() + { + $condition = "Q85[1]=~nach oben geöffnete Parabel~ &|Q85[2]=#0# | Q85[8]=+2+ !Q85[9]=+2+"; + $this->parser->setCondition($condition); + $this->parser->fetchExpressions(); + $this->parser->getOperators(); + $this->parser->cannonicalizeCondition(); + $this->parser->parse($condition); + } + + public function test_Replacing() + { + $condition = "Q5 = +2+ & !Q2 < #3# | !Q5 <= %100%"; + $this->parser->setCondition($condition); + $this->parser->fetchExpressions(); + $this->parser->getOperators(); + $this->parser->cannonicalizeCondition(); + + $this->assertEquals("n o n o !(n o n) o !(n o n)", $this->parser->getCondition()); + } + + private function recursiveNodeTest($nodes) + { + foreach ($nodes as $key => $node) { + if (!is_array($node)) { + $this->assertThat($key, $this->key_constraint); + if ($key == "type") { + $this->assertThat($node, $this->type_constraint); + } + } else { + $this->assertThat($key, $this->array_constraint); + $this->recursiveNodeTest($node); + } + } + } + + public function test_missingSpaces() + { + $condition = "Q1=%100%"; + $composite = $this->parser->parse($condition); + $this->assertInstanceOf("AbstractComposite", $composite); + } } diff --git a/Parser/Tests/Expressions/ExpressionTest.php b/Parser/Tests/Expressions/ExpressionTest.php index 6207942651bab831a3557e466a1c30aaf50ea05f..d21908731ef14eef783f4202ff9d1a982490de97 100644 --- a/Parser/Tests/Expressions/ExpressionTest.php +++ b/Parser/Tests/Expressions/ExpressionTest.php @@ -7,96 +7,95 @@ * Time: 15:51 * @author Thomas Joußen */ -class ExpressionTest extends PHPUnit_Framework_TestCase { - - - public function test_AnswerOfQuestionExpression() - { - include_once __DIR__ . '/../../classes/Expressions/AnswerOfQuestionExpression.php'; - $expression = new AnswerOfQuestionExpression(); - $expression->parseValue("Q3672"); - - $this->assertEquals("Q3672", $expression->getValue()); - $this->assertEquals(3672, $expression->getQuestionIndex()); - } - - public function test_NumberOfResultExpression() - { - include_once __DIR__ . '/../../classes/Expressions/NumberOfResultExpression.php'; - $expression = new NumberOfResultExpression(); - $expression->parseValue("+34+"); - - $this->assertEquals("+34+", $expression->getValue()); - $this->assertEquals(34, $expression->getNumericValue()); - } - - public function test_NumericResultExpression() - { - include_once __DIR__ . '/../../classes/Expressions/NumericResultExpression.php'; - $expression = new NumericResultExpression(); - $expression->parseValue("#-4.5#"); - - $this->assertEquals("#-4.5#", $expression->getValue()); - $this->assertEquals(-4.5, $expression->getNumericValue()); - } - - public function test_PercentageResultExpression() - { - include_once __DIR__ . '/../../classes/Expressions/PercentageResultExpression.php'; - $expression = new PercentageResultExpression(); - $expression->parseValue("%99.9%"); - - $this->assertEquals("%99.9%", $expression->getValue()); - $this->assertEquals(99.9, $expression->getNumericValue()); - } - - public function test_ResultOfAnswerOfQuestionExpression() - { - include_once __DIR__ . '/../../classes/Expressions/ResultOfAnswerOfQuestionExpression.php'; - $expression = new ResultOfAnswerOfQuestionExpression(); - $expression->parseValue("Q36[49]"); - - $this->assertEquals("Q36[49]", $expression->getValue()); - $this->assertEquals(36, $expression->getQuestionIndex()); - $this->assertEquals(49, $expression->getAnswerIndex()); - } - - public function test_StringResultExpression() - { - include_once __DIR__ . '/../../classes/Expressions/StringResultExpression.php'; - $expression = new StringResultExpression(); - $expression->parseValue("~Hallo Welt~"); - - $this->assertEquals("~Hallo Welt~", $expression->getValue()); - $this->assertEquals("Hallo Welt", $expression->getText()); - } - - public function test_MatchingResultExpression() - { - include_once __DIR__ . '/../../classes/Expressions/MatchingResultExpression.php'; - $expression = new MatchingResultExpression(); - $expression->parseValue(";14:15;"); - - $this->assertEquals(";14:15;", $expression->getValue()); - $this->assertEquals(14, $expression->getLeftNumericValue()); - $this->assertEquals(15, $expression->getRightNumericValue()); - } - - public function test_OrderingResultExpression() - { - include_once __DIR__ . '/../../classes/Expressions/OrderingResultExpression.php'; - $expression = new OrderingResultExpression(); - - $expression->parseValue("$14$"); - $this->assertEquals("$14$", $expression->getValue()); - $this->assertEquals(array(14), $expression->getOrdering()); - - $expression->parseValue("$14,15$"); - $this->assertEquals("$14,15$", $expression->getValue()); - $this->assertEquals(array(14,15), $expression->getOrdering()); - - $expression->parseValue("$14,15,17,18,29,30,30$"); - $this->assertEquals("$14,15,17,18,29,30,30$", $expression->getValue()); - $this->assertEquals(array(14,15,17,18,29,30,30), $expression->getOrdering()); - } +class ExpressionTest extends PHPUnit_Framework_TestCase +{ + public function test_AnswerOfQuestionExpression() + { + include_once __DIR__ . '/../../classes/Expressions/AnswerOfQuestionExpression.php'; + $expression = new AnswerOfQuestionExpression(); + $expression->parseValue("Q3672"); + + $this->assertEquals("Q3672", $expression->getValue()); + $this->assertEquals(3672, $expression->getQuestionIndex()); + } + + public function test_NumberOfResultExpression() + { + include_once __DIR__ . '/../../classes/Expressions/NumberOfResultExpression.php'; + $expression = new NumberOfResultExpression(); + $expression->parseValue("+34+"); + + $this->assertEquals("+34+", $expression->getValue()); + $this->assertEquals(34, $expression->getNumericValue()); + } + + public function test_NumericResultExpression() + { + include_once __DIR__ . '/../../classes/Expressions/NumericResultExpression.php'; + $expression = new NumericResultExpression(); + $expression->parseValue("#-4.5#"); + + $this->assertEquals("#-4.5#", $expression->getValue()); + $this->assertEquals(-4.5, $expression->getNumericValue()); + } + + public function test_PercentageResultExpression() + { + include_once __DIR__ . '/../../classes/Expressions/PercentageResultExpression.php'; + $expression = new PercentageResultExpression(); + $expression->parseValue("%99.9%"); + + $this->assertEquals("%99.9%", $expression->getValue()); + $this->assertEquals(99.9, $expression->getNumericValue()); + } + + public function test_ResultOfAnswerOfQuestionExpression() + { + include_once __DIR__ . '/../../classes/Expressions/ResultOfAnswerOfQuestionExpression.php'; + $expression = new ResultOfAnswerOfQuestionExpression(); + $expression->parseValue("Q36[49]"); + + $this->assertEquals("Q36[49]", $expression->getValue()); + $this->assertEquals(36, $expression->getQuestionIndex()); + $this->assertEquals(49, $expression->getAnswerIndex()); + } + + public function test_StringResultExpression() + { + include_once __DIR__ . '/../../classes/Expressions/StringResultExpression.php'; + $expression = new StringResultExpression(); + $expression->parseValue("~Hallo Welt~"); + + $this->assertEquals("~Hallo Welt~", $expression->getValue()); + $this->assertEquals("Hallo Welt", $expression->getText()); + } + + public function test_MatchingResultExpression() + { + include_once __DIR__ . '/../../classes/Expressions/MatchingResultExpression.php'; + $expression = new MatchingResultExpression(); + $expression->parseValue(";14:15;"); + + $this->assertEquals(";14:15;", $expression->getValue()); + $this->assertEquals(14, $expression->getLeftNumericValue()); + $this->assertEquals(15, $expression->getRightNumericValue()); + } + + public function test_OrderingResultExpression() + { + include_once __DIR__ . '/../../classes/Expressions/OrderingResultExpression.php'; + $expression = new OrderingResultExpression(); + + $expression->parseValue("$14$"); + $this->assertEquals("$14$", $expression->getValue()); + $this->assertEquals(array(14), $expression->getOrdering()); + + $expression->parseValue("$14,15$"); + $this->assertEquals("$14,15$", $expression->getValue()); + $this->assertEquals(array(14,15), $expression->getOrdering()); + + $expression->parseValue("$14,15,17,18,29,30,30$"); + $this->assertEquals("$14,15,17,18,29,30,30$", $expression->getValue()); + $this->assertEquals(array(14,15,17,18,29,30,30), $expression->getOrdering()); + } } diff --git a/Parser/Tests/Factory/ExpressionManufacturerTest.php b/Parser/Tests/Factory/ExpressionManufacturerTest.php index dd486134c0322b3a974d7eb7563cbee76ca26c7d..31657adcfe7d599095a31a3f8c9cda1d9e51dc87 100644 --- a/Parser/Tests/Factory/ExpressionManufacturerTest.php +++ b/Parser/Tests/Factory/ExpressionManufacturerTest.php @@ -7,92 +7,92 @@ * Time: 12:30 * @author Thomas Joußen */ -class ExpressionManufacturerTest extends PHPUnit_Framework_TestCase { +class ExpressionManufacturerTest extends PHPUnit_Framework_TestCase +{ - /** - * @var ReflectionClass - */ - protected $reflection; + /** + * @var ReflectionClass + */ + protected $reflection; - /** - * @var ExpressionManufacturer - */ - protected $manufacturer; + /** + * @var ExpressionManufacturer + */ + protected $manufacturer; - /** - * @var string - */ - protected $expected_pattern = '/%[0-9\.]+%|#-?[0-9\.]+#|\+[0-9]+\+|(Q\d+)(?=\=|<|>|\s|$)|Q[0-9]+\[[0-9]+\]|~.*?~|;[0-9]+:[0-9]+;|\$[0-9]+(?:,[0-9]+)*\$|\*[0-9]+(?:,[0-9]+)*\*/'; + /** + * @var string + */ + protected $expected_pattern = '/%[0-9\.]+%|#-?[0-9\.]+#|\+[0-9]+\+|(Q\d+)(?=\=|<|>|\s|$)|Q[0-9]+\[[0-9]+\]|~.*?~|;[0-9]+:[0-9]+;|\$[0-9]+(?:,[0-9]+)*\$|\*[0-9]+(?:,[0-9]+)*\*/'; - public function setUp(){ - include_once __DIR__ . '/../../classes/Factory/ExpressionManufacturer.php'; + public function setUp() + { + include_once __DIR__ . '/../../classes/Factory/ExpressionManufacturer.php'; - $this->reflection = new ReflectionClass("ExpressionManufacturer"); - $this->manufacturer = ExpressionManufacturer::_getInstance(); - } + $this->reflection = new ReflectionClass("ExpressionManufacturer"); + $this->manufacturer = ExpressionManufacturer::_getInstance(); + } - public function test_NotConstructable() - { - $this->assertFalse($this->reflection->isInstantiable()); - $method = $this->reflection->getMethod("__construct"); - $this->assertTrue($method->isPrivate()); - } + public function test_NotConstructable() + { + $this->assertFalse($this->reflection->isInstantiable()); + $method = $this->reflection->getMethod("__construct"); + $this->assertTrue($method->isPrivate()); + } - public function test_NotCloneable() - { - $this->assertFalse($this->reflection->isCloneable()); - $method = $this->reflection->getMethod("__clone"); - $this->assertTrue($method->isPrivate()); - } + public function test_NotCloneable() + { + $this->assertFalse($this->reflection->isCloneable()); + $method = $this->reflection->getMethod("__clone"); + $this->assertTrue($method->isPrivate()); + } - public function test_Singleton() - { - $this->assertNotNull($this->manufacturer); - $this->assertEquals($this->manufacturer, ExpressionManufacturer::_getInstance()); - } + public function test_Singleton() + { + $this->assertNotNull($this->manufacturer); + $this->assertEquals($this->manufacturer, ExpressionManufacturer::_getInstance()); + } - public function test_GetPattern() - { - $this->assertEquals($this->expected_pattern, $this->manufacturer->getPattern()); - } + public function test_GetPattern() + { + $this->assertEquals($this->expected_pattern, $this->manufacturer->getPattern()); + } - public function test_MatchPattern() - { - $subject = 'Q5 Q66 Q52[92] ~Hallo_Welt~ #5# +32+ %098% $3,4,5$ ;2:6;'; - $matches = $this->manufacturer->match($subject); - $tokens = \explode(" ", $subject); - foreach($tokens as $token) - { - $this->assertContains($token, $matches); - } - } + public function test_MatchPattern() + { + $subject = 'Q5 Q66 Q52[92] ~Hallo_Welt~ #5# +32+ %098% $3,4,5$ ;2:6;'; + $matches = $this->manufacturer->match($subject); + $tokens = \explode(" ", $subject); + foreach ($tokens as $token) { + $this->assertContains($token, $matches); + } + } - public function test_SupportedExpressions() - { - $expressions = array( - "Q736" => 'AnswerOfQuestionExpression', - "Q52[90]" => "ResultOfAnswerOfQuestionExpression", - "%9%" => "PercentageResultExpression", - "+14+" => "NumberOfResultExpression", - "#2#" => "NumericResultExpression", - "~Hello World~" => "StringResultExpression", - ";2:5;" => "MatchingResultExpression", - "$2,3,4,5$" => "OrderingResultExpression" - ); + public function test_SupportedExpressions() + { + $expressions = array( + "Q736" => 'AnswerOfQuestionExpression', + "Q52[90]" => "ResultOfAnswerOfQuestionExpression", + "%9%" => "PercentageResultExpression", + "+14+" => "NumberOfResultExpression", + "#2#" => "NumericResultExpression", + "~Hello World~" => "StringResultExpression", + ";2:5;" => "MatchingResultExpression", + "$2,3,4,5$" => "OrderingResultExpression" + ); - foreach($expressions as $key => $expression) - { - include_once __DIR__ . "/../../classes/Expressions/" . $expression . ".php"; - $expression_object = $this->manufacturer->manufacture($key); - $this->assertInstanceOf($expression, $expression_object); - } - } + foreach ($expressions as $key => $expression) { + include_once __DIR__ . "/../../classes/Expressions/" . $expression . ".php"; + $expression_object = $this->manufacturer->manufacture($key); + $this->assertInstanceOf($expression, $expression_object); + } + } - /** - * @expectedException UnsupportedExpression - */ - public function test_UnsupportedExpression() - { - $this->manufacturer->manufacture("%23#"); - } + /** + * @expectedException UnsupportedExpression + */ + public function test_UnsupportedExpression() + { + $this->manufacturer->manufacture("%23#"); + } } diff --git a/Parser/Tests/Factory/OperationManufacturerTest.php b/Parser/Tests/Factory/OperationManufacturerTest.php index 3930ed46be599b88c6917d21551cacb516baef46..108ab8604d65e661e68fbbd3db6821b010ddced8 100644 --- a/Parser/Tests/Factory/OperationManufacturerTest.php +++ b/Parser/Tests/Factory/OperationManufacturerTest.php @@ -7,92 +7,92 @@ * Time: 12:30 * @author Thomas Joußen */ -class OperationManufacturerTest extends PHPUnit_Framework_TestCase { +class OperationManufacturerTest extends PHPUnit_Framework_TestCase +{ - /** - * @var ReflectionClass - */ - protected $reflection; + /** + * @var ReflectionClass + */ + protected $reflection; - /** - * @var OperationManufacturer - */ - protected $manufacturer; + /** + * @var OperationManufacturer + */ + protected $manufacturer; - /** - * @var string - */ - protected $expected_pattern = '/[&\|<>=]+/'; + /** + * @var string + */ + protected $expected_pattern = '/[&\|<>=]+/'; - public function setUp(){ - include_once __DIR__ . '/../../classes/Factory/OperationManufacturer.php'; + public function setUp() + { + include_once __DIR__ . '/../../classes/Factory/OperationManufacturer.php'; - $this->reflection = new ReflectionClass("OperationManufacturer"); - $this->manufacturer = OperationManufacturer::_getInstance(); - } + $this->reflection = new ReflectionClass("OperationManufacturer"); + $this->manufacturer = OperationManufacturer::_getInstance(); + } - public function test_NotConstructable() - { - $this->assertFalse($this->reflection->isInstantiable()); - $method = $this->reflection->getMethod("__construct"); - $this->assertTrue($method->isPrivate()); - } + public function test_NotConstructable() + { + $this->assertFalse($this->reflection->isInstantiable()); + $method = $this->reflection->getMethod("__construct"); + $this->assertTrue($method->isPrivate()); + } - public function test_NotCloneable() - { - $this->assertFalse($this->reflection->isCloneable()); - $method = $this->reflection->getMethod("__clone"); - $this->assertTrue($method->isPrivate()); - } + public function test_NotCloneable() + { + $this->assertFalse($this->reflection->isCloneable()); + $method = $this->reflection->getMethod("__clone"); + $this->assertTrue($method->isPrivate()); + } - public function test_Singleton() - { - $this->assertNotNull($this->manufacturer); - $this->assertEquals($this->manufacturer, OperationManufacturer::_getInstance()); - } + public function test_Singleton() + { + $this->assertNotNull($this->manufacturer); + $this->assertEquals($this->manufacturer, OperationManufacturer::_getInstance()); + } - public function test_GetPattern() - { - $this->assertEquals($this->expected_pattern,$this->manufacturer->getPattern()); - } + public function test_GetPattern() + { + $this->assertEquals($this->expected_pattern, $this->manufacturer->getPattern()); + } - public function test_MatchPattern() - { - $subject = '< = > & | <> <= >='; - $matches = $this->manufacturer->match($subject); - $tokens = \explode(" ", $subject); - foreach($tokens as $token) - { - $this->assertContains($token, $matches); - } - } + public function test_MatchPattern() + { + $subject = '< = > & | <> <= >='; + $matches = $this->manufacturer->match($subject); + $tokens = \explode(" ", $subject); + foreach ($tokens as $token) { + $this->assertContains($token, $matches); + } + } - public function test_SupportedOperations() - { - $operations = array( - "<" => 'LesserOperation', - "<=" => "LesserOrEqualsOperation", - "=" => "EqualsOperation", - ">=" => "GreaterOrEqualsOperation", - ">" => "GreaterOperation", - "<>" => "NotEqualsOperation", - "&" => "AndOperation", - "|" => "OrOperation" - ); + public function test_SupportedOperations() + { + $operations = array( + "<" => 'LesserOperation', + "<=" => "LesserOrEqualsOperation", + "=" => "EqualsOperation", + ">=" => "GreaterOrEqualsOperation", + ">" => "GreaterOperation", + "<>" => "NotEqualsOperation", + "&" => "AndOperation", + "|" => "OrOperation" + ); - foreach($operations as $key => $operation) - { - include_once __DIR__ . "/../../classes/Operations/" . $operation . ".php"; - $operation_object = $this->manufacturer->manufacture($key); - $this->assertInstanceOf($operation, $operation_object); - } - } + foreach ($operations as $key => $operation) { + include_once __DIR__ . "/../../classes/Operations/" . $operation . ".php"; + $operation_object = $this->manufacturer->manufacture($key); + $this->assertInstanceOf($operation, $operation_object); + } + } - /** - * @expectedException UnsupportedOperation - */ - public function test_UnsupportedOperation() - { - $this->manufacturer->manufacture("=="); - } + /** + * @expectedException UnsupportedOperation + */ + public function test_UnsupportedOperation() + { + $this->manufacturer->manufacture("=="); + } } diff --git a/Parser/classes/AbstractComposite.php b/Parser/classes/AbstractComposite.php index 3151b4fbda4bd23ee15566fc06a89c0a9529139c..3e79ddc4bad8c8ec638dc9012f39dbcfb1d69a4f 100644 --- a/Parser/classes/AbstractComposite.php +++ b/Parser/classes/AbstractComposite.php @@ -8,37 +8,41 @@ include_once 'CompositeInterface.php'; * Date: 25.03.13 * Time: 10:05 * @author Thomas Joußen - */ -abstract class AbstractComposite implements CompositeInterface { + */ +abstract class AbstractComposite implements CompositeInterface +{ - /** - * @var AbstractComposite[] - */ - public $nodes = array(); + /** + * @var AbstractComposite[] + */ + public $nodes = array(); - /** - * Adds an CompositeInterface object to the node array which represents the condition tree structure - * - * @param CompositeInterface $node - */ - public function addNode(CompositeInterface $node) - { - $this->nodes[] = $node; - } + /** + * Adds an CompositeInterface object to the node array which represents the condition tree structure + * + * @param CompositeInterface $node + */ + public function addNode(CompositeInterface $node) + { + $this->nodes[] = $node; + } - /** - * Describes a Composite tree Structure as human readable string - * @return string - */ - public function describe() - { - $description = ""; - if(is_array($this->nodes)) - { - if(\count($this->nodes) > 0) $description .= "(" . $this->nodes[0]->describe(); - $description .= $this->getDescription(); - if(\count($this->nodes) > 0) $description .= $this->nodes[1]->describe() . ") "; - } - return $description; - } + /** + * Describes a Composite tree Structure as human readable string + * @return string + */ + public function describe() + { + $description = ""; + if (is_array($this->nodes)) { + if (\count($this->nodes) > 0) { + $description .= "(" . $this->nodes[0]->describe(); + } + $description .= $this->getDescription(); + if (\count($this->nodes) > 0) { + $description .= $this->nodes[1]->describe() . ") "; + } + } + return $description; + } } diff --git a/Parser/classes/CompositeBuilder.php b/Parser/classes/CompositeBuilder.php index 16fd7f0e9a5a6a7925bc2262ad454f46993e0da7..7958d8722ce228ff972b34b34aece91b169a171a 100644 --- a/Parser/classes/CompositeBuilder.php +++ b/Parser/classes/CompositeBuilder.php @@ -6,96 +6,89 @@ * Date: 27.03.13 * Time: 12:18 * @author Thomas Joußen - */ -class CompositeBuilder { + */ +class CompositeBuilder +{ - /** - * This array defines the weights and direction of operators.
- * It is required to build the composite tree with the correct depth structure - * - * @var array - */ - protected $operators = array('<=','<','=','>=','>','<>','&','|'); + /** + * This array defines the weights and direction of operators.
+ * It is required to build the composite tree with the correct depth structure + * + * @var array + */ + protected $operators = array('<=','<','=','>=','>','<>','&','|'); - /** - * Construct requirements - */ - public function __construct() - { - include_once 'Factory/OperationManufacturer.php'; - include_once 'Factory/ExpressionManufacturer.php'; - } + /** + * Construct requirements + */ + public function __construct() + { + include_once 'Factory/OperationManufacturer.php'; + include_once 'Factory/ExpressionManufacturer.php'; + } - /** - * @param array $nodes - * - * @return array - */ - public function create($nodes) - { - if($nodes['type'] == 'group') - { - foreach($nodes['nodes'] as $key => $child) - { - $nodes['nodes'][$key] = $this->create($child); - } - - $counted_nodes = 0; - if(is_array($nodes['nodes'])) - { - $counted_nodes = count($nodes['nodes']); - } - - foreach($this->operators as $next_operator) - { - do{ - $index = -1; - for($i = 0; $i < $counted_nodes; $i++) - { - if(!is_object($nodes['nodes'][$i]) && $nodes['nodes'][$i]['type'] == 'operator' && $nodes['nodes'][$i]['value'] == $next_operator) - { - $index = $i; - break; - } - } - if($index >= 0) - { - $operation_manufacture = OperationManufacturer::_getInstance(); - $operator = $operation_manufacture->manufacture($nodes['nodes'][$index]['value']); + /** + * @param array $nodes + * + * @return array + */ + public function create($nodes) + { + if ($nodes['type'] == 'group') { + foreach ($nodes['nodes'] as $key => $child) { + $nodes['nodes'][$key] = $this->create($child); + } + + $counted_nodes = 0; + if (is_array($nodes['nodes'])) { + $counted_nodes = count($nodes['nodes']); + } + + foreach ($this->operators as $next_operator) { + do { + $index = -1; + for ($i = 0; $i < $counted_nodes; $i++) { + if (!is_object($nodes['nodes'][$i]) && $nodes['nodes'][$i]['type'] == 'operator' && $nodes['nodes'][$i]['value'] == $next_operator) { + $index = $i; + break; + } + } + if ($index >= 0) { + $operation_manufacture = OperationManufacturer::_getInstance(); + $operator = $operation_manufacture->manufacture($nodes['nodes'][$index]['value']); - $operator->setNegated($nodes["negated"]); - $operator->addNode($this->getExpression($nodes, $index-1)); - $operator->addNode($this->getExpression($nodes, $index+1)); + $operator->setNegated($nodes["negated"]); + $operator->addNode($this->getExpression($nodes, $index - 1)); + $operator->addNode($this->getExpression($nodes, $index + 1)); - $new_nodes = array_slice($nodes['nodes'], 0, $index - 1); - $new_nodes[] = $operator; - $nodes['nodes'] = array_merge($new_nodes, array_slice($nodes['nodes'], $index + 2)); - } - }while($index >= 0); - } - return $nodes['nodes'][0]; - } - return $nodes; - } + $new_nodes = array_slice($nodes['nodes'], 0, $index - 1); + $new_nodes[] = $operator; + $nodes['nodes'] = array_merge($new_nodes, array_slice($nodes['nodes'], $index + 2)); + } + } while ($index >= 0); + } + return $nodes['nodes'][0]; + } + return $nodes; + } - /** - * Manufacure an expression from the delivered node and the index. If an expression already exist in the node for
- * for the delivered index, this function will return the existing expression - * - * @param array $node - * @param int $index - * - * @return CompositeInterface - */ - private function getExpression(array $node, $index) - { - $manufacturer = ExpressionManufacturer::_getInstance(); + /** + * Manufacure an expression from the delivered node and the index. If an expression already exist in the node for
+ * for the delivered index, this function will return the existing expression + * + * @param array $node + * @param int $index + * + * @return CompositeInterface + */ + private function getExpression(array $node, $index) + { + $manufacturer = ExpressionManufacturer::_getInstance(); - $expression = $node['nodes'][$index]; - if(!($expression instanceof AbstractComposite)) - { - $expression = $manufacturer->manufacture($node['nodes'][$index]['value']); - } - return $expression; - } + $expression = $node['nodes'][$index]; + if (!($expression instanceof AbstractComposite)) { + $expression = $manufacturer->manufacture($node['nodes'][$index]['value']); + } + return $expression; + } } diff --git a/Parser/classes/CompositeEvaluator.php b/Parser/classes/CompositeEvaluator.php index 4b3e8af283c908093074063d1c5ec451bfc7432d..5f22ce27f749c20fff9175ee1ab68283f5858da6 100644 --- a/Parser/classes/CompositeEvaluator.php +++ b/Parser/classes/CompositeEvaluator.php @@ -6,191 +6,174 @@ * Date: 07.01.14 * Time: 13:27 * @author Thomas Joußen - */ -class CompositeEvaluator { - - /** - * @var ilParserQuestionProvider - */ - protected $object_loader; - - /** - * @var ilFormATestSession - */ - protected $session; - - /** - * @param ilParserQuestionProvider $object_loader - * @param ilFormATestSession $session - */ - public function __construct($object_loader, $session) - { - $this->object_loader = $object_loader; - $this->session = $session; - } - - /** - * @param AbstractComposite $composite - * - * @return bool - */ - public function evaluate(AbstractComposite $composite) - { - if(is_array($composite->nodes) && count($composite->nodes) > 0) - { - $composite->nodes[0] = $this->evaluate($composite->nodes[0]); - $composite->nodes[1] = $this->evaluate($composite->nodes[1]); - $composite = $this->evaluateSubTree($composite); - } - return $composite; - } - - /** - * @param AbstractComposite $composite - * - * @return bool - */ - private function evaluateSubTree(AbstractComposite $composite) - { - $result = false; - if($composite->nodes[0] instanceof ExpressionInterface && - $composite->nodes[1] instanceof ExpressionInterface - ){ - $question = $this->object_loader->getQuestion($composite->nodes[0]->getQuestionIndex()); - $rightNode = $composite->nodes[1]; - - $index = ($composite->nodes[0] instanceof ResultOfAnswerOfQuestionExpression)? $composite->nodes[0]->getAnswerIndex(): null; - - $solutions = $question->getUserQuestionResult($this->session->getActiveId(),$this->session->getPass()); - - if($question instanceof assClozeTest) - { - // @todo for Thomas J.: Move to interface / implement in concrete class (req. for future releases) - /** - * @var $gap assClozeGap - * @var $answer assAnswerCloze - */ - $result = $solutions->getSolutionForKey($index); - $gap = $question->getAvailableAnswerOptions($index-1); - - if($rightNode instanceof StringResultExpression) - { - if($gap->getType() == 1) - { - $answer = $gap->getItem($result['value'] - 1); - $solutions->removeByKey($index); - $solutions->addKeyValue($index, $answer->getAnswertext()); - } - } - else if( - $rightNode instanceof PercentageResultExpression && - $composite->nodes[0] instanceof ResultOfAnswerOfQuestionExpression) - { - require_once './Services/Randomization/classes/class.ilArrayElementShuffler.php'; - /** - * @var $answers assAnswerCloze[] - */ - $answers = $gap->getItems(new ilArrayElementShuffler()); - $max_points = 0; - foreach($answers as $answer) - { - if($max_points < $answer->getPoints()) - { - $max_points = $answer->getPoints(); - } - } - - $item = null; - $reached_points = null; - // @todo for Thomas J.: Maybe handle identical scoring for every type - switch($gap->getType()) - { - case CLOZE_TEXT: - for($order = 0; $order < $gap->getItemCount(); $order++) - { - $answer = $gap->getItem($order); - $item_points = $question->getTextgapPoints($answer->getAnswertext(), $result['value'], $answer->getPoints()); - if($item_points > $reached_points) $reached_points = $item_points; - } - break; - - case CLOZE_NUMERIC: - for($order = 0; $order < $gap->getItemCount(); $order++) - { - $answer = $gap->getItem($order); - $item_points = $question->getNumericgapPoints($answer->getAnswertext(), $result["value"], $answer->getPoints(), $answer->getLowerBound(), $answer->getUpperBound()); - if($item_points > $reached_points) $reached_points = $item_points; - } - break; - - case CLOZE_SELECT: - if($result['value'] != null) - { - $answer = $gap->getItem($result['value'] - 1); - $reached_points = $answer->getPoints(); - } - break; - } - - $percentage = 0; - if($max_points != 0 && $reached_points !== null) - { - $percentage = (int)(($reached_points / $max_points) * 100); - } - $solutions->setReachedPercentage($percentage); - } - } - - if( - $question instanceof assFormulaQuestion && - $rightNode instanceof PercentageResultExpression && - $composite->nodes[0] instanceof ResultOfAnswerOfQuestionExpression - ) - { - // @todo for Thomas J.: Move to interface / implement in concrete class (req. for future releases) - $result = $solutions->getSolutionForKey($index); - $answer = $question->getAvailableAnswerOptions($index-1); - - $unit = $solutions->getSolutionForKey($index . "_unit"); - $key = null; - if(is_array($unit)) - { - $key = $unit['value']; - } - - $max_points = $answer->getPoints(); - $points = $answer->getReachedPoints($question->getVariables(), $question->getResults(), $result["value"], $key, $question->getUnitrepository()->getUnits()); - - $percentage = 0; - if($max_points != 0) - { - $percentage = (int)(($points/$max_points)*100); - } - $solutions->setReachedPercentage($percentage); - } - - $result = $rightNode->checkResult($solutions,$composite->getPattern(),$index); - } - else - { - switch($composite->getPattern()) - { - case "&": - $result = $composite->nodes[0] && $composite->nodes[1]; - break; - case "|": - $result = $composite->nodes[0] || $composite->nodes[1]; - break; - default: - $result = false; - } - } - - if($composite->isNegated()) - { - return !$result; - } - return $result; - } + */ +class CompositeEvaluator +{ + + /** + * @var ilParserQuestionProvider + */ + protected $object_loader; + + /** + * @var ilFormATestSession + */ + protected $session; + + /** + * @param ilParserQuestionProvider $object_loader + * @param ilFormATestSession $session + */ + public function __construct($object_loader, $session) + { + $this->object_loader = $object_loader; + $this->session = $session; + } + + /** + * @param AbstractComposite $composite + * + * @return bool + */ + public function evaluate(AbstractComposite $composite) + { + if (is_array($composite->nodes) && count($composite->nodes) > 0) { + $composite->nodes[0] = $this->evaluate($composite->nodes[0]); + $composite->nodes[1] = $this->evaluate($composite->nodes[1]); + $composite = $this->evaluateSubTree($composite); + } + return $composite; + } + + /** + * @param AbstractComposite $composite + * + * @return bool + */ + private function evaluateSubTree(AbstractComposite $composite) + { + $result = false; + if ($composite->nodes[0] instanceof ExpressionInterface && + $composite->nodes[1] instanceof ExpressionInterface + ) { + $question = $this->object_loader->getQuestion($composite->nodes[0]->getQuestionIndex()); + $rightNode = $composite->nodes[1]; + + $index = ($composite->nodes[0] instanceof ResultOfAnswerOfQuestionExpression)? $composite->nodes[0]->getAnswerIndex(): null; + + $solutions = $question->getUserQuestionResult($this->session->getActiveId(), $this->session->getPass()); + + if ($question instanceof assClozeTest) { + // @todo for Thomas J.: Move to interface / implement in concrete class (req. for future releases) + /** + * @var $gap assClozeGap + * @var $answer assAnswerCloze + */ + $result = $solutions->getSolutionForKey($index); + $gap = $question->getAvailableAnswerOptions($index - 1); + + if ($rightNode instanceof StringResultExpression) { + if ($gap->getType() == 1) { + $answer = $gap->getItem($result['value'] - 1); + $solutions->removeByKey($index); + $solutions->addKeyValue($index, $answer->getAnswertext()); + } + } elseif ( + $rightNode instanceof PercentageResultExpression && + $composite->nodes[0] instanceof ResultOfAnswerOfQuestionExpression) { + /** + * @var $answers assAnswerCloze[] + */ + $answers = $gap->getItems(new ilArrayElementShuffler()); + $max_points = 0; + foreach ($answers as $answer) { + if ($max_points < $answer->getPoints()) { + $max_points = $answer->getPoints(); + } + } + + $item = null; + $reached_points = null; + // @todo for Thomas J.: Maybe handle identical scoring for every type + switch ($gap->getType()) { + case CLOZE_TEXT: + for ($order = 0; $order < $gap->getItemCount(); $order++) { + $answer = $gap->getItem($order); + $item_points = $question->getTextgapPoints($answer->getAnswertext(), $result['value'], $answer->getPoints()); + if ($item_points > $reached_points) { + $reached_points = $item_points; + } + } + break; + + case CLOZE_NUMERIC: + for ($order = 0; $order < $gap->getItemCount(); $order++) { + $answer = $gap->getItem($order); + $item_points = $question->getNumericgapPoints($answer->getAnswertext(), $result["value"], $answer->getPoints(), $answer->getLowerBound(), $answer->getUpperBound()); + if ($item_points > $reached_points) { + $reached_points = $item_points; + } + } + break; + + case CLOZE_SELECT: + if ($result['value'] != null) { + $answer = $gap->getItem($result['value'] - 1); + $reached_points = $answer->getPoints(); + } + break; + } + + $percentage = 0; + if ($max_points != 0 && $reached_points !== null) { + $percentage = (int) (($reached_points / $max_points) * 100); + } + $solutions->setReachedPercentage($percentage); + } + } + + if ( + $question instanceof assFormulaQuestion && + $rightNode instanceof PercentageResultExpression && + $composite->nodes[0] instanceof ResultOfAnswerOfQuestionExpression + ) { + // @todo for Thomas J.: Move to interface / implement in concrete class (req. for future releases) + $result = $solutions->getSolutionForKey($index); + $answer = $question->getAvailableAnswerOptions($index - 1); + + $unit = $solutions->getSolutionForKey($index . "_unit"); + $key = null; + if (is_array($unit)) { + $key = $unit['value']; + } + + $max_points = $answer->getPoints(); + $points = $answer->getReachedPoints($question->getVariables(), $question->getResults(), $result["value"], $key, $question->getUnitrepository()->getUnits()); + + $percentage = 0; + if ($max_points != 0) { + $percentage = (int) (($points / $max_points) * 100); + } + $solutions->setReachedPercentage($percentage); + } + + $result = $rightNode->checkResult($solutions, $composite->getPattern(), $index); + } else { + switch ($composite->getPattern()) { + case "&": + $result = $composite->nodes[0] && $composite->nodes[1]; + break; + case "|": + $result = $composite->nodes[0] || $composite->nodes[1]; + break; + default: + $result = false; + } + } + + if ($composite->isNegated()) { + return !$result; + } + return $result; + } } - diff --git a/Parser/classes/CompositeInterface.php b/Parser/classes/CompositeInterface.php index 1dfb503d4068b62fe176ddc16a499fb33b1b68cc..ea5bc75a4f871f59f77344c09f308f03497aa4f2 100644 --- a/Parser/classes/CompositeInterface.php +++ b/Parser/classes/CompositeInterface.php @@ -7,26 +7,27 @@ * @author Thomas Joußen */ -interface CompositeInterface { +interface CompositeInterface +{ - /** - * Adds an CompositeInterface object to the node array which represents the condition tree structure - * - * @param CompositeInterface $node - */ - public function addNode(CompositeInterface $node); + /** + * Adds an CompositeInterface object to the node array which represents the condition tree structure + * + * @param CompositeInterface $node + */ + public function addNode(CompositeInterface $node); - /** - * Describes a Composite tree Structure as human readable string - * - * @return string - */ - public function describe(); + /** + * Describes a Composite tree Structure as human readable string + * + * @return string + */ + public function describe(); - /** - * Get a human readable description of the Composite element - * - * @return string - */ - public function getDescription(); -} \ No newline at end of file + /** + * Get a human readable description of the Composite element + * + * @return string + */ + public function getDescription(); +} diff --git a/Parser/classes/CompositeValidator.php b/Parser/classes/CompositeValidator.php index 349d6690dedfbf1c34f613107ab9e79e98456f96..755bae552fa58b8e45ad5ba5b07b4dd55f5e08a5 100644 --- a/Parser/classes/CompositeValidator.php +++ b/Parser/classes/CompositeValidator.php @@ -18,292 +18,254 @@ require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/ * Date: 04.12.13 * Time: 14:19 * @author Thomas Joußen - */ + */ class CompositeValidator { - /** - * @var ilParserQuestionProvider - * - * @todo Needs to be abstract or interface - */ - protected $object_loader; + /** + * @var ilParserQuestionProvider + * + * @todo Needs to be abstract or interface + */ + protected $object_loader; - /** - * @var ilQuestionSetPoolNode - */ - protected $node; + /** + * @var ilQuestionSetPoolNode + */ + protected $node; - /** - * @var array - */ - protected $data; + /** + * @var array + */ + protected $data; - /** - * @param ilParserQuestionProvider $object_loader - * @oaram ilQuestionSetPoolNode $node - * @param array $data - */ - public function __construct($object_loader, $node, $data) - { - $this->object_loader = $object_loader; - $this->node = $node; - $this->data = $data; - } + /** + * @param ilParserQuestionProvider $object_loader + * @oaram ilQuestionSetPoolNode $node + * @param array $data + */ + public function __construct($object_loader, $node, $data) + { + $this->object_loader = $object_loader; + $this->node = $node; + $this->data = $data; + } - public function validate(AbstractComposite $composite) - { - if(is_array($composite->nodes) && count($composite->nodes) > 0) - { - $this->validate($composite->nodes[0]); - $this->validate($composite->nodes[1]); - $this->validateSubTree($composite); - } + public function validate(AbstractComposite $composite) + { + if (is_array($composite->nodes) && count($composite->nodes) > 0) { + $this->validate($composite->nodes[0]); + $this->validate($composite->nodes[1]); + $this->validateSubTree($composite); + } - return; - } + return; + } - private function validateSubTree(AbstractComposite $composite) - { - if($composite->nodes[0] instanceof QuestionExpressionInterface && - $composite->nodes[1] instanceof SolutionExpressionInterface - ){ - $question_expression = $composite->nodes[0]; - $answer_expression = $composite->nodes[1]; - $question_index = $composite->nodes[0]->getQuestionIndex(); - $answer_index = null; - $question = $this->object_loader->getQuestion($question_index); + private function validateSubTree(AbstractComposite $composite) + { + if ($composite->nodes[0] instanceof QuestionExpressionInterface && + $composite->nodes[1] instanceof SolutionExpressionInterface + ) { + $question_expression = $composite->nodes[0]; + $answer_expression = $composite->nodes[1]; + $question_index = $composite->nodes[0]->getQuestionIndex(); + $answer_index = null; + $question = $this->object_loader->getQuestion($question_index); - $this->checkQuestionExists($question, $question_index); - $this->checkQuestionIsReachable($question, $question_index); + $this->checkQuestionExists($question, $question_index); + $this->checkQuestionIsReachable($question, $question_index); - if($this->isResultOfAnswerExpression($question_expression)) - { - $answer_index = $question_expression->getAnswerIndex()-1; - $this->checkIfAnswerIndexOfQuestionExists($question, $question_index, $answer_index); - } - if($answer_expression instanceof NumberOfResultExpression && !($question instanceof assClozeTest)) - { - $this->checkIfAnswerIndexOfQuestionExists($question, $question_index, $answer_expression->getNumericValue()-1); - } + if ($this->isResultOfAnswerExpression($question_expression)) { + $answer_index = $question_expression->getAnswerIndex() - 1; + $this->checkIfAnswerIndexOfQuestionExists($question, $question_index, $answer_index); + } + if ($answer_expression instanceof NumberOfResultExpression && !($question instanceof assClozeTest)) { + $this->checkIfAnswerIndexOfQuestionExists($question, $question_index, $answer_expression->getNumericValue() - 1); + } - $this->checkAnswerExpressionExist($question->getExpressionTypes(), $answer_expression, $question_index); - $this->checkOperatorExistForExpression($question->getOperators($answer_expression::$identifier), $answer_expression, $composite::$pattern); + $this->checkAnswerExpressionExist($question->getExpressionTypes(), $answer_expression, $question_index); + $this->checkOperatorExistForExpression($question->getOperators($answer_expression::$identifier), $answer_expression, $composite::$pattern); - if($answer_expression instanceof OrderingResultExpression && - ($question instanceof assOrderingHorizontal || $question instanceof assOrderingQuestion ) - ) - { - foreach($answer_expression->getOrdering() as $order) - { - $count = 0; - foreach($answer_expression->getOrdering() as $element) - { - if($element == $order) - { - $count++; - } - } - if($count > 1) - { - throw new DuplicateElement($order); - } + if ($answer_expression instanceof OrderingResultExpression && + ($question instanceof assOrderingHorizontal || $question instanceof assOrderingQuestion) + ) { + foreach ($answer_expression->getOrdering() as $order) { + $count = 0; + foreach ($answer_expression->getOrdering() as $element) { + if ($element == $order) { + $count++; + } + } + if ($count > 1) { + throw new DuplicateElement($order); + } - $this->checkIfAnswerIndexOfQuestionExists($question, $question_index, $order-1); - } - } - if($question instanceof assClozeTest) - { - $this->validateClozeTest($answer_index, $question, $answer_expression, $question_index); - } - elseif( - $answer_expression instanceof PercentageResultExpression && - $this->isResultOfAnswerExpression($question_expression) && - !($question instanceof assFormulaQuestion) - ) - { - throw new ExpressionNotSupportedByQuestion($answer_expression->getValue(), $question_index . "[". ($answer_index+1) . "]"); - } - } - elseif( - ($composite->nodes[0] instanceof AbstractOperation && - $composite->nodes[1] instanceof ExpressionInterface) || - ($composite->nodes[0] instanceof ExpressionInterface && - $composite->nodes[1] instanceof AbstractOperation) || - ($composite->nodes[0] instanceof SolutionExpressionInterface) - ) - { - throw new UnableToParseCondition(""); - } - } + $this->checkIfAnswerIndexOfQuestionExists($question, $question_index, $order - 1); + } + } + if ($question instanceof assClozeTest) { + $this->validateClozeTest($answer_index, $question, $answer_expression, $question_index); + } elseif ( + $answer_expression instanceof PercentageResultExpression && + $this->isResultOfAnswerExpression($question_expression) && + !($question instanceof assFormulaQuestion) + ) { + throw new ExpressionNotSupportedByQuestion($answer_expression->getValue(), $question_index . "[" . ($answer_index + 1) . "]"); + } + } elseif ( + ($composite->nodes[0] instanceof AbstractOperation && + $composite->nodes[1] instanceof ExpressionInterface) || + ($composite->nodes[0] instanceof ExpressionInterface && + $composite->nodes[1] instanceof AbstractOperation) || + ($composite->nodes[0] instanceof SolutionExpressionInterface) + ) { + throw new UnableToParseCondition(""); + } + } - /** - * @param int $answer_index - * @param assQuestion|iQuestionCondition $question - * @param ExpressionInterface $answer_expression - * @param int $question_index - * - * @throws AnswerValueNotExist - */ - private function validateClozeTest($answer_index, $question, $answer_expression, $question_index) - { - if($answer_index !== null) - { - $options = $question->getAvailableAnswerOptions($answer_index); - $found = false; - switch($options->getType()) - { - case 0: // text - if( - $answer_expression instanceof StringResultExpression - ) - { - $found = true; - } + /** + * @param int $answer_index + * @param assQuestion|iQuestionCondition $question + * @param ExpressionInterface $answer_expression + * @param int $question_index + * + * @throws AnswerValueNotExist + */ + private function validateClozeTest($answer_index, $question, $answer_expression, $question_index) + { + if ($answer_index !== null) { + $options = $question->getAvailableAnswerOptions($answer_index); + $found = false; + switch ($options->getType()) { + case 0: // text + if ( + $answer_expression instanceof StringResultExpression + ) { + $found = true; + } - break; - case 1: // select + break; + case 1: // select - if($answer_expression instanceof StringResultExpression) - { - require_once './Services/Randomization/classes/class.ilArrayElementShuffler.php'; - foreach($options->getItems(new ilArrayElementShuffler()) as $item) - { - if($item->getAnswertext() == $answer_expression->getText()) - { - $found = true; - } - } - } - elseif($answer_expression instanceof NumberOfResultExpression) - { - require_once './Services/Randomization/classes/class.ilArrayElementShuffler.php'; - foreach($options->getItems(new ilArrayElementShuffler()) as $item) - { - if($item->getOrder() == $answer_expression->getNumericValue()-1) - { - $found = true; - } - } - } - break; - case 2: // numeric - if($answer_expression instanceof NumericResultExpression) - { - $found = true; - } - break; - } + if ($answer_expression instanceof StringResultExpression) { + foreach ($options->getItems(new ilArrayElementShuffler()) as $item) { + if ($item->getAnswertext() == $answer_expression->getText()) { + $found = true; + } + } + } elseif ($answer_expression instanceof NumberOfResultExpression) { + foreach ($options->getItems(new ilArrayElementShuffler()) as $item) { + if ($item->getOrder() == $answer_expression->getNumericValue() - 1) { + $found = true; + } + } + } + break; + case 2: // numeric + if ($answer_expression instanceof NumericResultExpression) { + $found = true; + } + break; + } - if($answer_expression instanceof EmptyAnswerExpression) - { - $found = true; - } - if(!$found && !($answer_expression instanceof PercentageResultExpression)) - { - throw new AnswerValueNotExist($question_index, $answer_expression->getValue(), $answer_index+1); - } + if ($answer_expression instanceof EmptyAnswerExpression) { + $found = true; + } + if (!$found && !($answer_expression instanceof PercentageResultExpression)) { + throw new AnswerValueNotExist($question_index, $answer_expression->getValue(), $answer_index + 1); + } + } + } - } - } + /** + * @param iQuestionCondition $question + * @param int $question_index + * @param int $answer_index + * + * @throws AnswerIndexNotExist + */ + private function checkIfAnswerIndexOfQuestionExists($question, $question_index, $answer_index) + { + $answer_options = $question->getAvailableAnswerOptions($answer_index); + if ($answer_options == null) { + throw new AnswerIndexNotExist($question_index, $answer_index + 1); + } + } - /** - * @param iQuestionCondition $question - * @param int $question_index - * @param int $answer_index - * - * @throws AnswerIndexNotExist - */ - private function checkIfAnswerIndexOfQuestionExists($question, $question_index, $answer_index) - { - $answer_options = $question->getAvailableAnswerOptions($answer_index); - if($answer_options == null) - { - throw new AnswerIndexNotExist($question_index, $answer_index+1); - } - } + /** + * @param assQuestion|null $question + * @param int $index + * + * @throws QuestionNotExist + */ + private function checkQuestionExists($question, $index) + { + if ($question == null) { + throw new QuestionNotExist($index); + } + } - /** - * @param assQuestion|null $question - * @param int $index - * - * @throws QuestionNotExist - */ - private function checkQuestionExists($question, $index) - { - if($question == null) - { - throw new QuestionNotExist($index); - } - } + /** + * @param ExpressionInterface $expression + * + * @return bool + */ + private function isResultOfAnswerExpression($expression) + { + return $expression instanceof ResultOfAnswerOfQuestionExpression; + } - /** - * @param ExpressionInterface $expression - * - * @return bool - */ - private function isResultOfAnswerExpression($expression) - { - return $expression instanceof ResultOfAnswerOfQuestionExpression; - } + /** + * @param array $expressions + * @param ExpressionInterface $answer_expression + * @param int $question_index + * + * @throws ExpressionNotSupportedByQuestion + */ + private function checkAnswerExpressionExist($expressions, $answer_expression, $question_index) + { + if (!in_array($answer_expression::$identifier, $expressions)) { + throw new ExpressionNotSupportedByQuestion($answer_expression->getValue(), $question_index); + } + } - /** - * @param array $expressions - * @param ExpressionInterface $answer_expression - * @param int $question_index - * - * @throws ExpressionNotSupportedByQuestion - */ - private function checkAnswerExpressionExist($expressions, $answer_expression, $question_index) - { - if(!in_array($answer_expression::$identifier, $expressions)) - { - throw new ExpressionNotSupportedByQuestion($answer_expression->getValue(), $question_index); - } - } + /** + * @param array $operators + * @param ExpressionInterface $answer_expression + * @param string $pattern + * + * @throws OperatorNotSupportedByExpression + */ + private function checkOperatorExistForExpression($operators, $answer_expression, $pattern) + { + if (!in_array($pattern, $operators)) { + throw new OperatorNotSupportedByExpression($answer_expression->getValue(), $pattern); + } + } - /** - * @param array $operators - * @param ExpressionInterface $answer_expression - * @param string $pattern - * - * @throws OperatorNotSupportedByExpression - */ - private function checkOperatorExistForExpression($operators, $answer_expression, $pattern) - { - if(!in_array($pattern, $operators)) - { - throw new OperatorNotSupportedByExpression($answer_expression->getValue(),$pattern); - } - } + /** + * @param $question + * @param $index + * + * @throws QuestionNotReachable + */ + private function checkQuestionIsReachable($question, $index) + { + $reachable = false; + foreach ($this->data as $node) { + if ($node["node_index"] > $this->node->getIndex()) { + break; + } - /** - * @param $question - * @param $index - * - * @throws QuestionNotReachable - */ - private function checkQuestionIsReachable($question, $index) - { - $reachable = false; - foreach($this->data as $node) - { - if($node["node_index"] > $this->node->getIndex()) - { - break; - } + if ($node["question_fi"] == $question->getId()) { + $reachable = true; + break; + } + } - if($node["question_fi"] == $question->getId()) - { - $reachable = true; - break; - } - } - - if(!$reachable) - { - throw new QuestionNotReachable($index); - } - } + if (!$reachable) { + throw new QuestionNotReachable($index); + } + } } - \ No newline at end of file diff --git a/Parser/classes/ConditionParser.php b/Parser/classes/ConditionParser.php index 3c9303117399c89ab6adea58f0cd76af92cff4f6..6f23468c5e360e40d23a9bf96a544c066572f84d 100644 --- a/Parser/classes/ConditionParser.php +++ b/Parser/classes/ConditionParser.php @@ -10,249 +10,234 @@ require_once "Exception/ConditionParserException.php"; * Date: 22.03.13 * Time: 13:54 * @author Thomas Joußen - */ -class ConditionParser { - - /** - * The condition which should be parsed into a ParserComposite to match a branch condition - * - * @var string - */ - protected $condition; - - /** - * The expressions which are be matched by the regular expression ConditionParser::$regex_expression in the condition - * - * @see Parser::$regex_expression - * @var array - */ - protected $expressions; - - /** - * The operators which are be matched by the regular expression ConditionParser::$regex_operator in the condition - * - * @see Parser::$regex_operator - * @var array - */ - protected $operators; - - /** - * The parser index to save the current position in the condition parser - * - * @var int - */ - protected $index; - - /** - * Counts the number of spaces in a condition - * - * @var int - */ - protected $spaces; - - /** - * Construct requirements - */ - public function __construct(){ - include_once __DIR__ . '/Factory/ExpressionManufacturer.php'; - include_once __DIR__ . '/Factory/OperationManufacturer.php'; - include_once "CompositeBuilder.php"; - } - - /** - * Parses the delivered condition and creates a composite tree Structure - * - * @param $condition - * - * @see CompositeBuilder::create() - * @return array - */ - public function parse($condition){ - $this->condition = $condition; - // $this->checkBrackets(); - $this->fetchExpressions(); - $this->fetchOperators(); - $this->cannonicalizeCondition(); - $this->checkBrackets(); - $nodes = $this->createNodeArray(); - $compositeBuilder = new CompositeBuilder(); - return $compositeBuilder->create($nodes); - } - - /** - * Matches all expressions in the current condition and assign these to the class attribute ConditionParser::$expressions - * - * @see AbstractManufacturer::match() - * @see ExpressionManufacturer::getPattern() - * @see Parser::$expressions - */ - protected function fetchExpressions(){ - $manufacturer = ExpressionManufacturer::_getInstance(); - $this->expressions = $manufacturer->match($this->condition); - } - - /** - * Matches all operators in the current condition and assign these to the class attribute ConditionParser::$operators - * - * @see AbstractManufacturer::match() - * @see OperationManufacturer::getPattern() - * @see Parser::$operators - */ - protected function fetchOperators(){ - $manufacturer = OperationManufacturer::_getInstance(); - $this->operators = $manufacturer->match($this->condition); - } - - /** - * Cannonicalize the condition into a more general form.
- * It replaces all expression with "n" and all orperators with "o"
- * so that the result of an condition after cannonicalization could be:
- *
- * (n o n) o (n o n) o n - */ - protected function cannonicalizeCondition(){ - $manufacturer = ExpressionManufacturer::_getInstance(); - $this->condition = preg_replace($manufacturer->getPattern(), 'n', $this->condition); - $manufacturer = OperationManufacturer::_getInstance(); - $this->condition = preg_replace($manufacturer->getPattern(), 'o', $this->condition); - $this->condition = preg_replace("/no/", "n o", $this->condition); - $this->condition = preg_replace("/on/", "o n", $this->condition); - - for($i = 0; $i < strlen($this->condition); $i++) - { - if($this->condition[$i] == "!" && !$this->isNegationSurroundedByBrackets($i)) - { - $this->surroundNegationExpression($i); - } - } - } - - public function checkBrackets() - { - $num_brackets_open = substr_count($this->condition, "("); - $num_brackets_close = substr_count($this->condition, ")"); - - if($num_brackets_open > $num_brackets_close) - { - throw new MissingBracket(")"); - } - if($num_brackets_open < $num_brackets_close) - { - throw new MissingBracket("("); - } - } - - /** - * Creates an array representing all Nodes in a condition based on the fetched expressions and operators.
- * The array has a tree representation which depth is dependent to the bracketing in the condition
- * The array contains of four main keys to identify the elements:
- *
- * - * - * - * - * - * - * - * - * - * - * - * - * - *
KeyValuesDescription
type"group", "expression", "operator"The type of the node - Group is used to introduce the next tree depth
valuemixedContains an extracted expression or operation from a condition
nodesarrayContains an node array
- * - * @return array - */ - protected function createNodeArray() - { - $expected = array("n", "(", "!"); - $group = array(); - $negation = false; - - while($this->index < strlen($this->condition)) - { - $a = $this->condition[$this->index]; - if(trim($this->condition[$this->index]) != "" && in_array($this->condition[$this->index], $expected)) - { - if ($this->condition[$this->index] == ')') - { - return $group; - } - else if ($this->condition[$this->index] == 'n') - { - $group[] = array('type' => 'expression', 'value' => array_shift($this->expressions)); - $expected = array("o", ")"); - } - else if ($this->condition[$this->index] == 'o') - { - $group[] = array('type' => 'operator', 'value' => array_shift($this->operators)); - $expected = array("n", "(", "!"); - } - else if ($this->condition[$this->index] == '(') - { - $this->index++; - $elements = $this->createNodeArray(); - $group[] = array('type' => "group", "negated" => $negation, 'nodes' => $elements); - $negation = false; - $expected = array("o",")"); - } - else if($this->condition[$this->index] == "!") - { - $negation = true; - } - } - elseif(trim($this->condition[$this->index]) != "") - { - throw new ConditionParserException($this->index-$this->spaces+1); - } - else - { - $this->spaces++; - } - - $this->index++; - } - return array('type' => 'group', "negated" => $negation, 'nodes' => $group); - } - - /** - * @return array - */ - public function getExpressions() - { - return $this->expressions; - } - - /** - * @param int $index - */ - protected function surroundNegationExpression($index) - { - $start = strpos($this->condition, "n", $index + 1); - $end = false; - - if($start !== false) - { - $end = strpos($this->condition, "n", $start + 1); - } - - if($start !== false && $end !== false) - { - $this->condition = substr_replace($this->condition, "(n o n)", $start, $end - $start + 1); - } - } - - /** - * @param int $index - * - * @return boolean - */ - protected function isNegationSurroundedByBrackets($index) - { - $next_bracket = strpos($this->condition, "(", $index+1); - $next_expression = strpos($this->condition, "n", $index+1); - - return $next_bracket !== false & $next_bracket < $next_expression; - } + */ +class ConditionParser +{ + + /** + * The condition which should be parsed into a ParserComposite to match a branch condition + * + * @var string + */ + protected $condition; + + /** + * The expressions which are be matched by the regular expression ConditionParser::$regex_expression in the condition + * + * @see Parser::$regex_expression + * @var array + */ + protected $expressions; + + /** + * The operators which are be matched by the regular expression ConditionParser::$regex_operator in the condition + * + * @see Parser::$regex_operator + * @var array + */ + protected $operators; + + /** + * The parser index to save the current position in the condition parser + * + * @var int + */ + protected $index; + + /** + * Counts the number of spaces in a condition + * + * @var int + */ + protected $spaces; + + /** + * Construct requirements + */ + public function __construct() + { + include_once __DIR__ . '/Factory/ExpressionManufacturer.php'; + include_once __DIR__ . '/Factory/OperationManufacturer.php'; + include_once "CompositeBuilder.php"; + } + + /** + * Parses the delivered condition and creates a composite tree Structure + * + * @param $condition + * + * @see CompositeBuilder::create() + * @return array + */ + public function parse($condition) + { + $this->condition = $condition; + // $this->checkBrackets(); + $this->fetchExpressions(); + $this->fetchOperators(); + $this->cannonicalizeCondition(); + $this->checkBrackets(); + $nodes = $this->createNodeArray(); + $compositeBuilder = new CompositeBuilder(); + return $compositeBuilder->create($nodes); + } + + /** + * Matches all expressions in the current condition and assign these to the class attribute ConditionParser::$expressions + * + * @see AbstractManufacturer::match() + * @see ExpressionManufacturer::getPattern() + * @see Parser::$expressions + */ + protected function fetchExpressions() + { + $manufacturer = ExpressionManufacturer::_getInstance(); + $this->expressions = $manufacturer->match($this->condition); + } + + /** + * Matches all operators in the current condition and assign these to the class attribute ConditionParser::$operators + * + * @see AbstractManufacturer::match() + * @see OperationManufacturer::getPattern() + * @see Parser::$operators + */ + protected function fetchOperators() + { + $manufacturer = OperationManufacturer::_getInstance(); + $this->operators = $manufacturer->match($this->condition); + } + + /** + * Cannonicalize the condition into a more general form.
+ * It replaces all expression with "n" and all orperators with "o"
+ * so that the result of an condition after cannonicalization could be:
+ *
+ * (n o n) o (n o n) o n + */ + protected function cannonicalizeCondition() + { + $manufacturer = ExpressionManufacturer::_getInstance(); + $this->condition = preg_replace($manufacturer->getPattern(), 'n', $this->condition); + $manufacturer = OperationManufacturer::_getInstance(); + $this->condition = preg_replace($manufacturer->getPattern(), 'o', $this->condition); + $this->condition = preg_replace("/no/", "n o", $this->condition); + $this->condition = preg_replace("/on/", "o n", $this->condition); + + for ($i = 0; $i < strlen($this->condition); $i++) { + if ($this->condition[$i] == "!" && !$this->isNegationSurroundedByBrackets($i)) { + $this->surroundNegationExpression($i); + } + } + } + + public function checkBrackets() + { + $num_brackets_open = substr_count($this->condition, "("); + $num_brackets_close = substr_count($this->condition, ")"); + + if ($num_brackets_open > $num_brackets_close) { + throw new MissingBracket(")"); + } + if ($num_brackets_open < $num_brackets_close) { + throw new MissingBracket("("); + } + } + + /** + * Creates an array representing all Nodes in a condition based on the fetched expressions and operators.
+ * The array has a tree representation which depth is dependent to the bracketing in the condition
+ * The array contains of four main keys to identify the elements:
+ *
+ * + * + * + * + * + * + * + * + * + * + * + * + * + *
KeyValuesDescription
type"group", "expression", "operator"The type of the node - Group is used to introduce the next tree depth
valuemixedContains an extracted expression or operation from a condition
nodesarrayContains an node array
+ * + * @return array + */ + protected function createNodeArray() + { + $expected = array("n", "(", "!"); + $group = array(); + $negation = false; + + while ($this->index < strlen($this->condition)) { + $a = $this->condition[$this->index]; + if (trim($this->condition[$this->index]) != "" && in_array($this->condition[$this->index], $expected)) { + if ($this->condition[$this->index] == ')') { + return $group; + } elseif ($this->condition[$this->index] == 'n') { + $group[] = array('type' => 'expression', 'value' => array_shift($this->expressions)); + $expected = array("o", ")"); + } elseif ($this->condition[$this->index] == 'o') { + $group[] = array('type' => 'operator', 'value' => array_shift($this->operators)); + $expected = array("n", "(", "!"); + } elseif ($this->condition[$this->index] == '(') { + $this->index++; + $elements = $this->createNodeArray(); + $group[] = array('type' => "group", "negated" => $negation, 'nodes' => $elements); + $negation = false; + $expected = array("o",")"); + } elseif ($this->condition[$this->index] == "!") { + $negation = true; + } + } elseif (trim($this->condition[$this->index]) != "") { + throw new ConditionParserException($this->index - $this->spaces + 1); + } else { + $this->spaces++; + } + + $this->index++; + } + return array('type' => 'group', "negated" => $negation, 'nodes' => $group); + } + + /** + * @return array + */ + public function getExpressions() + { + return $this->expressions; + } + + /** + * @param int $index + */ + protected function surroundNegationExpression($index) + { + $start = strpos($this->condition, "n", $index + 1); + $end = false; + + if ($start !== false) { + $end = strpos($this->condition, "n", $start + 1); + } + + if ($start !== false && $end !== false) { + $this->condition = substr_replace($this->condition, "(n o n)", $start, $end - $start + 1); + } + } + + /** + * @param int $index + * + * @return boolean + */ + protected function isNegationSurroundedByBrackets($index) + { + $next_bracket = strpos($this->condition, "(", $index + 1); + $next_expression = strpos($this->condition, "n", $index + 1); + + return $next_bracket !== false & $next_bracket < $next_expression; + } } diff --git a/Parser/classes/Exception/AnswerIndexNotExist.php b/Parser/classes/Exception/AnswerIndexNotExist.php index 97bd80e4b2a854cc2f2847424235e625c219f0ff..06de093bb5df08f70eb4e42b97a582c1c3da76e8 100644 --- a/Parser/classes/Exception/AnswerIndexNotExist.php +++ b/Parser/classes/Exception/AnswerIndexNotExist.php @@ -2,51 +2,52 @@ /** * Class AnswerIndexNotExist - * @package + * @package * * Date: 25.03.13 * Time: 15:15 * @author Thomas Joußen - */ -class AnswerIndexNotExist extends \RuntimeException{ + */ +class AnswerIndexNotExist extends \RuntimeException +{ - /** - * @var int - */ - protected $question_index; + /** + * @var int + */ + protected $question_index; - /** - * @var int - */ - protected $answer_index; + /** + * @var int + */ + protected $answer_index; - /** - * @param int $question_index - * @param int $answer_index - */ - public function __construct($question_index, $answer_index) - { - $this->question_index = $question_index; - $this->answer_index = $answer_index; + /** + * @param int $question_index + * @param int $answer_index + */ + public function __construct($question_index, $answer_index) + { + $this->question_index = $question_index; + $this->answer_index = $answer_index; - parent::__construct( - sprintf('The Question with index "Q%s" does not have an answer with the index "%s" ', $this->question_index, $this->answer_index) - ); - } + parent::__construct( + sprintf('The Question with index "Q%s" does not have an answer with the index "%s" ', $this->question_index, $this->answer_index) + ); + } - /** - * @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; - } -} \ No newline at end of file + /** + * @return int + */ + public function getAnswerIndex() + { + return $this->answer_index; + } +} diff --git a/Parser/classes/Exception/AnswerValueNotExist.php b/Parser/classes/Exception/AnswerValueNotExist.php index f80e9b0a1f0411c6eaaa9d24f48468883bace053..0f39e516b493f0661ff56dc08c34b66212e7e282 100644 --- a/Parser/classes/Exception/AnswerValueNotExist.php +++ b/Parser/classes/Exception/AnswerValueNotExist.php @@ -2,72 +2,72 @@ /** * Class QuestionNotReachable - * @package + * @package * * Date: 25.03.13 * Time: 15:15 * @author Thomas Joußen - */ -class AnswerValueNotExist extends \RuntimeException{ + */ +class AnswerValueNotExist extends \RuntimeException +{ - /** - * @var int - */ - protected $question_index; + /** + * @var int + */ + protected $question_index; - /** - * @var string - */ - protected $value; + /** + * @var string + */ + protected $value; - /** - * @var int - */ - protected $answer_index; + /** + * @var int + */ + protected $answer_index; - /** - * @param int $question_index - * @param string $value - * @param int $answer_index - */ - public function __construct($question_index, $value, $answer_index = null) - { - $this->question_index = $question_index; - $this->answer_index = $answer_index; - $this->value = $value; + /** + * @param int $question_index + * @param string $value + * @param int $answer_index + */ + public function __construct($question_index, $value, $answer_index = null) + { + $this->question_index = $question_index; + $this->answer_index = $answer_index; + $this->value = $value; - $message = 'The value "%s" does not exist for the question Q%s[%s]'; - if($this->answer_index === null) - { - $message = 'The value "%s" does not exist for the question Q%s'; - } + $message = 'The value "%s" does not exist for the question Q%s[%s]'; + if ($this->answer_index === null) { + $message = 'The value "%s" does not exist for the question Q%s'; + } - parent::__construct( - sprintf($message, $this->question_index, $value, $this->answer_index) - ); - } + parent::__construct( + sprintf($message, $this->question_index, $value, $this->answer_index) + ); + } - /** - * @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; + } - /** - * @return string - */ - public function getValue() - { - return $this->value; - } -} \ No newline at end of file + /** + * @return string + */ + public function getValue() + { + return $this->value; + } +} diff --git a/Parser/classes/Exception/ConditionParserException.php b/Parser/classes/Exception/ConditionParserException.php index f8dad52ac293d80ddb93809475a0d0bee8e64b46..9f8f6c424c159cdda7dc21b9ea1ada63acb5fff3 100644 --- a/Parser/classes/Exception/ConditionParserException.php +++ b/Parser/classes/Exception/ConditionParserException.php @@ -6,33 +6,32 @@ * Date: 02.04.14 * Time: 15:40 * @author Thomas Joußen - */ + */ class ConditionParserException extends \RuntimeException { - /** - * @var int - */ - protected $column; + /** + * @var int + */ + protected $column; - /** - * @param int $column - */ - public function __construct($column) - { - $this->column = $column; + /** + * @param int $column + */ + public function __construct($column) + { + $this->column = $column; - parent::__construct( - sprintf('The expression at position "%s" is not valid', $this->column) - ); - } + parent::__construct( + sprintf('The expression at position "%s" is not valid', $this->column) + ); + } - /** - * @return int - */ - public function getColumn() - { - return $this->column; - } + /** + * @return int + */ + public function getColumn() + { + return $this->column; + } } - \ No newline at end of file diff --git a/Parser/classes/Exception/DuplicateElement.php b/Parser/classes/Exception/DuplicateElement.php index 557e667b01e7c22a995bdc823105f421826c24da..32f62c74053500e035f6ebd677a77256537cc2ba 100755 --- a/Parser/classes/Exception/DuplicateElement.php +++ b/Parser/classes/Exception/DuplicateElement.php @@ -2,36 +2,37 @@ /** * Class DuplicateElement - * @package + * @package * * Date: 25.03.13 * Time: 15:15 * @author Thomas Joußen - */ -class DuplicateElement extends \RuntimeException{ + */ +class DuplicateElement extends \RuntimeException +{ - /** - * @var string - */ - protected $element; + /** + * @var string + */ + protected $element; - /** - * @param string $bracket - */ - public function __construct($element) - { - $this->element = $element; + /** + * @param string $bracket + */ + public function __construct($element) + { + $this->element = $element; - parent::__construct( - sprintf('Duplicate key "%s" in condition', $this->element) - ); - } + parent::__construct( + sprintf('Duplicate key "%s" in condition', $this->element) + ); + } - /** - * @return string - */ - public function getElement() - { - return $this->element; - } -} \ No newline at end of file + /** + * @return string + */ + public function getElement() + { + return $this->element; + } +} diff --git a/Parser/classes/Exception/ExpressionNotSupportedByQuestion.php b/Parser/classes/Exception/ExpressionNotSupportedByQuestion.php index 32090feb401a90da4c5264874af3e1034b60e865..8fcdb4256513137caedd8308c44f7525bd1cc718 100644 --- a/Parser/classes/Exception/ExpressionNotSupportedByQuestion.php +++ b/Parser/classes/Exception/ExpressionNotSupportedByQuestion.php @@ -2,51 +2,52 @@ /** * Class ExpressionNotSupportedByQuestion - * @package + * @package * * Date: 25.03.13 * Time: 15:15 * @author Thomas Joußen - */ -class ExpressionNotSupportedByQuestion extends \RuntimeException{ + */ +class ExpressionNotSupportedByQuestion extends \RuntimeException +{ - /** - * @var string - */ - protected $expression; + /** + * @var string + */ + protected $expression; - /** - * @var int - */ - protected $question_index; + /** + * @var int + */ + protected $question_index; - /** - * @param string $expression - * @param int $question_index - */ - public function __construct($expression, $question_index) - { - $this->expression = $expression; - $this->question_index = $question_index; + /** + * @param string $expression + * @param int $question_index + */ + public function __construct($expression, $question_index) + { + $this->expression = $expression; + $this->question_index = $question_index; - parent::__construct( - sprintf('The expression "%s" is not supported by the question with index "Q%s"', $this->expression, $this->question_index) - ); - } + parent::__construct( + sprintf('The expression "%s" is not supported by the question with index "Q%s"', $this->expression, $this->question_index) + ); + } - /** - * @return int - */ - public function getQuestionIndex() - { - return $this->question_index; - } + /** + * @return int + */ + public function getQuestionIndex() + { + return $this->question_index; + } - /** - * @return string - */ - public function getExpression() - { - return $this->expression; - } -} \ No newline at end of file + /** + * @return string + */ + public function getExpression() + { + return $this->expression; + } +} diff --git a/Parser/classes/Exception/MissingBracket.php b/Parser/classes/Exception/MissingBracket.php index 6777d4ed2ab30a5eaef14a5701035e501eac35be..5d81cca1ffc5fea07e753f640a016e7aaa9353a9 100644 --- a/Parser/classes/Exception/MissingBracket.php +++ b/Parser/classes/Exception/MissingBracket.php @@ -2,36 +2,37 @@ /** * Class AnswerIndexNotExist - * @package + * @package * * Date: 25.03.13 * Time: 15:15 * @author Thomas Joußen - */ -class MissingBracket extends \RuntimeException{ + */ +class MissingBracket extends \RuntimeException +{ - /** - * @var string - */ - protected $bracket; + /** + * @var string + */ + protected $bracket; - /** - * @param string $bracket - */ - public function __construct($bracket) - { - $this->bracket = $bracket; + /** + * @param string $bracket + */ + public function __construct($bracket) + { + $this->bracket = $bracket; - parent::__construct( - sprintf('There is a bracket "%s" missing in the condition', $this->bracket) - ); - } + parent::__construct( + sprintf('There is a bracket "%s" missing in the condition', $this->bracket) + ); + } - /** - * @return string - */ - public function getBracket() - { - return $this->bracket; - } -} \ No newline at end of file + /** + * @return string + */ + public function getBracket() + { + return $this->bracket; + } +} diff --git a/Parser/classes/Exception/OperatorNotSupportedByExpression.php b/Parser/classes/Exception/OperatorNotSupportedByExpression.php index 9bad51b55494bfd4de723a0595451ed88cf3b12d..7c1934be913aa0d65590e6328cf7db46e6a7ab0c 100644 --- a/Parser/classes/Exception/OperatorNotSupportedByExpression.php +++ b/Parser/classes/Exception/OperatorNotSupportedByExpression.php @@ -2,51 +2,52 @@ /** * Class OperatorNotSupportedByExpression - * @package + * @package * * Date: 25.03.13 * Time: 15:15 * @author Thomas Joußen - */ -class OperatorNotSupportedByExpression extends \RuntimeException{ + */ +class OperatorNotSupportedByExpression extends \RuntimeException +{ - /** - * @var string - */ - protected $operator; + /** + * @var string + */ + protected $operator; - /** - * @var string - */ - protected $expression; + /** + * @var string + */ + protected $expression; - /** - * @param string $expression - * @param string $operator - */ - public function __construct($expression, $operator) - { - $this->expression = $expression; - $this->operator = $operator; + /** + * @param string $expression + * @param string $operator + */ + public function __construct($expression, $operator) + { + $this->expression = $expression; + $this->operator = $operator; - parent::__construct( - sprintf('The expression "%s" is not supported by the operator "%s"', $this->expression, $this->operator) - ); - } + parent::__construct( + sprintf('The expression "%s" is not supported by the operator "%s"', $this->expression, $this->operator) + ); + } - /** - * @return string - */ - public function getExpression() - { - return $this->expression; - } + /** + * @return string + */ + public function getExpression() + { + return $this->expression; + } - /** - * @return string - */ - public function getOperator() - { - return $this->operator; - } -} \ No newline at end of file + /** + * @return string + */ + public function getOperator() + { + return $this->operator; + } +} diff --git a/Parser/classes/Exception/QuestionNotExist.php b/Parser/classes/Exception/QuestionNotExist.php index e6046da714e40097fb1e2a1de66a1bb4d4641f99..83b418d97e526534dad046d8baa662bda2009fee 100644 --- a/Parser/classes/Exception/QuestionNotExist.php +++ b/Parser/classes/Exception/QuestionNotExist.php @@ -2,36 +2,37 @@ /** * Class QuestionNotExist - * @package + * @package * * Date: 25.03.13 * Time: 15:15 * @author Thomas Joußen - */ -class QuestionNotExist extends \RuntimeException{ + */ +class QuestionNotExist 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" does not exist "', $this->question_index) - ); - } + parent::__construct( + sprintf('The Question with index "Q%s" does not exist "', $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; + } +} diff --git a/Parser/classes/Exception/QuestionNotReachable.php b/Parser/classes/Exception/QuestionNotReachable.php index 216fe0335c04011bc51a602a7ba60627d5f4fc1f..13c8aef2ab95223e2ee3e866a0e25d6b48cd44fb 100644 --- a/Parser/classes/Exception/QuestionNotReachable.php +++ b/Parser/classes/Exception/QuestionNotReachable.php @@ -2,36 +2,37 @@ /** * Class QuestionNotReachable - * @package + * @package * * Date: 25.03.13 * Time: 15:15 * @author Thomas Joußen - */ -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; + } +} diff --git a/Parser/classes/Exception/UnableToParseCondition.php b/Parser/classes/Exception/UnableToParseCondition.php index 4c99d31b8df66a6aaeff22b3872e111d9774f500..3dd40ab081975fb469af966fa79c243d3e739f45 100644 --- a/Parser/classes/Exception/UnableToParseCondition.php +++ b/Parser/classes/Exception/UnableToParseCondition.php @@ -2,38 +2,39 @@ /** * Class UnableToParseCondition - * @package + * @package * * Date: 25.03.13 * Time: 15:15 * @author Thomas Joußen - */ -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; + } +} diff --git a/Parser/classes/Exception/UnsupportedExpression.php b/Parser/classes/Exception/UnsupportedExpression.php index 8e21c53e8b15803e18e0a25c8e0fd06e15dede31..31fa7e69be9f9bf561ae081ee21e7afe1e9f5512 100644 --- a/Parser/classes/Exception/UnsupportedExpression.php +++ b/Parser/classes/Exception/UnsupportedExpression.php @@ -2,35 +2,36 @@ /** * Class UnsupportedExpression - * @package + * @package * * Date: 25.03.13 * Time: 15:15 * @author Thomas Joußen - */ -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; + } +} diff --git a/Parser/classes/Exception/UnsupportedOperation.php b/Parser/classes/Exception/UnsupportedOperation.php index 0966060db2ef73c4bb1ae62152e8c90ef6ffed59..a8da9fd9a657bcbfdd8613aaf32a20fc04b57bf2 100644 --- a/Parser/classes/Exception/UnsupportedOperation.php +++ b/Parser/classes/Exception/UnsupportedOperation.php @@ -2,36 +2,37 @@ /** * Class UnsupportedOperation - * @package + * @package * * Date: 25.03.13 * Time: 15:15 * @author Thomas Joußen - */ -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; + } +} diff --git a/Parser/classes/Expressions/AbstractExpression.php b/Parser/classes/Expressions/AbstractExpression.php index 161a2f2af8cc41df269fc4bd04598f1065b297b9..7d904c83d79987f4c7f6e37bb741a1c42c5da0d3 100644 --- a/Parser/classes/Expressions/AbstractExpression.php +++ b/Parser/classes/Expressions/AbstractExpression.php @@ -1,6 +1,6 @@ - */ -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); } diff --git a/Parser/classes/Expressions/AnswerOfQuestionExpression.php b/Parser/classes/Expressions/AnswerOfQuestionExpression.php index c8c530ec039f1c3f820acbc9cd9abcbf721ff318..294766f093a1d4b2e1815ee60ee74ccb77861ed7 100644 --- a/Parser/classes/Expressions/AnswerOfQuestionExpression.php +++ b/Parser/classes/Expressions/AnswerOfQuestionExpression.php @@ -9,84 +9,84 @@ require_once "QuestionExpressionInterface.php"; * Date: 25.03.13 * Time: 16:39 * @author Thomas Joußen - */ + */ class AnswerOfQuestionExpression extends AbstractExpression implements QuestionExpressionInterface { - /** - * The pattern '/Q[0-9]+([^\[|0-9]|$)/' should match the following expression in a condition
- *
- *
-	 * Qn	"n" is a Placeholder for a numeric question index
-	 * 
- * It is used to create a AnswerOfQuestionExpression + /** + * The pattern '/Q[0-9]+([^\[|0-9]|$)/' should match the following expression in a condition
+ *
+ *
+     * Qn	"n" is a Placeholder for a numeric question index
+     * 
+ * 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]+/'; + } } diff --git a/Parser/classes/Expressions/EmptyAnswerExpression.php b/Parser/classes/Expressions/EmptyAnswerExpression.php index b8e0857ea9cabe7fc728ed689b5490fc4e1ff474..6b12da9e95162fa8ee5399aacc1b93a08c58c79c 100644 --- a/Parser/classes/Expressions/EmptyAnswerExpression.php +++ b/Parser/classes/Expressions/EmptyAnswerExpression.php @@ -9,93 +9,85 @@ include_once "SolutionExpressionInterface.php"; * Date: 15.05.14 * Time: 08:51 * @author Thomas Joußen - */ + */ 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 diff --git a/Parser/classes/Expressions/ExclusiveResultExpression.php b/Parser/classes/Expressions/ExclusiveResultExpression.php index 78c0bfa63a07adae9fada9e27242e2d3c3dbb299..73834bd28dd7b881bc0366fa90228681bcacb61b 100644 --- a/Parser/classes/Expressions/ExclusiveResultExpression.php +++ b/Parser/classes/Expressions/ExclusiveResultExpression.php @@ -9,106 +9,104 @@ include_once "SolutionExpressionInterface.php"; * Date: 25.03.13 * Time: 16:41 * @author Thomas Joußen - */ + */ class ExclusiveResultExpression extends AbstractExpression implements SolutionExpressionInterface { - /** - * The pattern "/\*[0-9]+(?:,[0-9]+)*\* /" should match the following expression in a condition
- *
- *
-	 * #n#	"n" is a Placeholder for a numeric value
-	 * * 
- * It is used to create a NumericResultExpression + /** + * The pattern "/\*[0-9]+(?:,[0-9]+)*\* /" should match the following expression in a condition
+ *
+ *
+     * #n#	"n" is a Placeholder for a numeric value
+     * * 
+ * 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; + } + } } diff --git a/Parser/classes/Expressions/ExpressionInterface.php b/Parser/classes/Expressions/ExpressionInterface.php index 4357c7a623566c1265c515fe4b365145de231c49..51cbdeeb28f3d4e509d7847f98c43b7ccf63727f 100644 --- a/Parser/classes/Expressions/ExpressionInterface.php +++ b/Parser/classes/Expressions/ExpressionInterface.php @@ -7,19 +7,20 @@ * @author Thomas Joußen */ -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); +} diff --git a/Parser/classes/Expressions/MatchingResultExpression.php b/Parser/classes/Expressions/MatchingResultExpression.php index d815c101eab1d711fc9e54e30923e4c9afa28bc3..6f6b18c021ee7e0b145a61107b2e9aea41fb6a38 100644 --- a/Parser/classes/Expressions/MatchingResultExpression.php +++ b/Parser/classes/Expressions/MatchingResultExpression.php @@ -9,131 +9,129 @@ include_once "SolutionExpressionInterface.php"; * Date: 25.03.13 * Time: 16:41 * @author Thomas Joußen - */ + */ class MatchingResultExpression extends AbstractExpression implements SolutionExpressionInterface { - /** - * The pattern "/;[0-9]+:[0-9]+;/" should match the following expression in a condition
- *
- *
-	 * ;n:m;	"n" is a Placeholder for a left numeric index
-	 * 				"m" is a Placeholder for a right numeric index
-	 * 
- * It is used to create a NumericResultExpression + /** + * The pattern "/;[0-9]+:[0-9]+;/" should match the following expression in a condition
+ *
+ *
+     * ;n:m;	"n" is a Placeholder for a left numeric index
+     * 				"m" is a Placeholder for a right numeric index
+     * 
+ * 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; + } + } } diff --git a/Parser/classes/Expressions/NumberOfResultExpression.php b/Parser/classes/Expressions/NumberOfResultExpression.php index cdc11080652b66d22df6dde114834e3e7ae1099e..c19398623350b57af8c6f031588c1ff2a1eca8fa 100644 --- a/Parser/classes/Expressions/NumberOfResultExpression.php +++ b/Parser/classes/Expressions/NumberOfResultExpression.php @@ -9,112 +9,107 @@ include_once "SolutionExpressionInterface.php"; * Date: 25.03.13 * Time: 16:41 * @author Thomas Joußen - */ + */ class NumberOfResultExpression extends AbstractExpression implements SolutionExpressionInterface { - /** - * The pattern "/\\+[0-9]+\\+/" should match the following expression in a condition
- *
- *
-	 * +n+	"n" is a Placeholder for a numeric value
-	 * 
- * It is used to create a NumberOfResultExpression + /** + * The pattern "/\\+[0-9]+\\+/" should match the following expression in a condition
+ *
+ *
+     * +n+	"n" is a Placeholder for a numeric value
+     * 
+ * 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; + } + } } diff --git a/Parser/classes/Expressions/NumericResultExpression.php b/Parser/classes/Expressions/NumericResultExpression.php index d46d770d82178a6d48c594a6dbc531e45a2003ec..4ef86dbd23010395edb88fc2eea868bd72bf5ce8 100644 --- a/Parser/classes/Expressions/NumericResultExpression.php +++ b/Parser/classes/Expressions/NumericResultExpression.php @@ -9,124 +9,119 @@ include_once "SolutionExpressionInterface.php"; * Date: 25.03.13 * Time: 16:41 * @author Thomas Joußen - */ + */ class NumericResultExpression extends AbstractExpression implements SolutionExpressionInterface { - /** - * The pattern "/#[0-9]+#/" should match the following expression in a condition
- *
- *
-	 * #n#	"n" is a Placeholder for a numeric value
-	 * * 
- * It is used to create a NumericResultExpression + /** + * The pattern "/#[0-9]+#/" should match the following expression in a condition
+ *
+ *
+     * #n#	"n" is a Placeholder for a numeric value
+     * * 
+ * 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; + } + } } diff --git a/Parser/classes/Expressions/OrderingResultExpression.php b/Parser/classes/Expressions/OrderingResultExpression.php index 0fb6adfcc7d92939845c0ebb26bb7a52992e8bd2..69fc8983afeba6b2c926d3baa1297e0565ad28ad 100644 --- a/Parser/classes/Expressions/OrderingResultExpression.php +++ b/Parser/classes/Expressions/OrderingResultExpression.php @@ -9,105 +9,103 @@ include_once "SolutionExpressionInterface.php"; * Date: 25.03.13 * Time: 16:41 * @author Thomas Joußen - */ + */ class OrderingResultExpression extends AbstractExpression implements SolutionExpressionInterface { - /** - * The pattern "/\$[0-9]+(?:,[0-9]+)*\$/" should match the following expression in a condition
- *
- *
-	 * $a,..,n,m$	all characters are placeholders for numeric indices
-	 * 
- * It is used to create a OrderingResultExpression - * - * @var string - */ - public static $pattern = '/\$[0-9]+(?:,[0-9]+)*\$/'; + /** + * The pattern "/\$[0-9]+(?:,[0-9]+)*\$/" should match the following expression in a condition
+ *
+ *
+     * $a,..,n,m$	all characters are placeholders for numeric indices
+     * 
+ * 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; + } + } } diff --git a/Parser/classes/Expressions/PercentageResultExpression.php b/Parser/classes/Expressions/PercentageResultExpression.php index c325cada1e921045c5b412a5ec91caf852665d47..0cfbe73f53d16be8edd989d23ca1c0ac019d629f 100644 --- a/Parser/classes/Expressions/PercentageResultExpression.php +++ b/Parser/classes/Expressions/PercentageResultExpression.php @@ -9,104 +9,103 @@ include_once "SolutionExpressionInterface.php"; * Date: 25.03.13 * Time: 16:40 * @author Thomas Joußen - */ + */ class PercentageResultExpression extends AbstractExpression implements SolutionExpressionInterface { - /** - * The pattern "/%[0-9]+%/" should match the following expression in a condition
- *
- *
-	 * %n%	"n" is a Placeholder for a numeric value
-	 * 
- * It is used to create a PercentageResultExpression + /** + * The pattern "/%[0-9]+%/" should match the following expression in a condition
+ *
+ *
+     * %n%	"n" is a Placeholder for a numeric value
+     * 
+ * 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; + } + } } diff --git a/Parser/classes/Expressions/QuestionExpressionInterface.php b/Parser/classes/Expressions/QuestionExpressionInterface.php index bc01d5c072fe5ce1fe43dadb2169ebbef298b934..8e55e01e30521e3a2d3473590a27794df2677eaf 100644 --- a/Parser/classes/Expressions/QuestionExpressionInterface.php +++ b/Parser/classes/Expressions/QuestionExpressionInterface.php @@ -7,8 +7,7 @@ * @author Thomas Joußen */ -interface QuestionExpressionInterface { - - - public function getQuestionIndex(); -} \ No newline at end of file +interface QuestionExpressionInterface +{ + public function getQuestionIndex(); +} diff --git a/Parser/classes/Expressions/ResultOfAnswerOfQuestionExpression.php b/Parser/classes/Expressions/ResultOfAnswerOfQuestionExpression.php index 92bbdf585024cf1e87eb451820bcd110cb75514f..03c5b610ee43c07045accb5246e52bcd04afd561 100644 --- a/Parser/classes/Expressions/ResultOfAnswerOfQuestionExpression.php +++ b/Parser/classes/Expressions/ResultOfAnswerOfQuestionExpression.php @@ -9,94 +9,95 @@ require_once "QuestionExpressionInterface.php"; * Date: 25.03.13 * Time: 16:40 * @author Thomas Joußen - */ -class ResultOfAnswerOfQuestionExpression extends AbstractExpression implements QuestionExpressionInterface{ - /** - * The pattern "/Q[0-9]+\\[[0-9]+\\]/" should match the following expression in a condition
- *
- *
-	 * Qn[m]	"n" is a Placeholder for a numeric question index
-	 * 				"m" is a Placeholde for a numeric answer index of a question
-	 * 
- * It is used to create a ResultOfAnswerOfQuestioExpression + */ +class ResultOfAnswerOfQuestionExpression extends AbstractExpression implements QuestionExpressionInterface +{ + /** + * The pattern "/Q[0-9]+\\[[0-9]+\\]/" should match the following expression in a condition
+ *
+ *
+     * Qn[m]	"n" is a Placeholder for a numeric question index
+     * 				"m" is a Placeholde for a numeric answer index of a question
+     * 
+ * 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 "; + } } diff --git a/Parser/classes/Expressions/SolutionExpressionInterface.php b/Parser/classes/Expressions/SolutionExpressionInterface.php index e1ececb49261f1860bbe87573c4c25bb470684d3..0287defc714e527939e9c931ec7063bc1b5f869b 100644 --- a/Parser/classes/Expressions/SolutionExpressionInterface.php +++ b/Parser/classes/Expressions/SolutionExpressionInterface.php @@ -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); +} diff --git a/Parser/classes/Expressions/StringResultExpression.php b/Parser/classes/Expressions/StringResultExpression.php index e100c04fc9c6861d8ca9fb18936972794c685148..cfda43f439b3981ab218efd03730cdc370de9400 100644 --- a/Parser/classes/Expressions/StringResultExpression.php +++ b/Parser/classes/Expressions/StringResultExpression.php @@ -10,127 +10,122 @@ include_once "SolutionExpressionInterface.php"; * Date: 25.03.13 * Time: 16:41 * @author Thomas Joußen - */ + */ class StringResultExpression extends AbstractExpression implements SolutionExpressionInterface { - /** - * The pattern "/~.*?~/" should match the following expression in a condition
- *
- *
-	 * ~TEXT~	"TEXT" is a Placeholder for string value
-	 * 
- * It is used to create a StringResultExpression + /** + * The pattern "/~.*?~/" should match the following expression in a condition
+ *
+ *
+     * ~TEXT~	"TEXT" is a Placeholder for string value
+     * 
+ * 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; + } + } } diff --git a/Parser/classes/Factory/AbstractManufacturer.php b/Parser/classes/Factory/AbstractManufacturer.php index fcf56959657c99ce558ebed7181f82dc4bd98a7c..ee4fabcd6a110a06d2d986285c443b1142683b4a 100644 --- a/Parser/classes/Factory/AbstractManufacturer.php +++ b/Parser/classes/Factory/AbstractManufacturer.php @@ -8,33 +8,33 @@ include_once "ManufacturerInterface.php"; * Date: 26.03.13 * Time: 15:13 * @author Thomas Joußen - */ -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; + } } diff --git a/Parser/classes/Factory/ExpressionManufacturer.php b/Parser/classes/Factory/ExpressionManufacturer.php index 86df7d9f85be4e673c251a5a07c1d40ce79ebdda..63cca51e661c114605fd7fcd5ac557751b13488d 100644 --- a/Parser/classes/Factory/ExpressionManufacturer.php +++ b/Parser/classes/Factory/ExpressionManufacturer.php @@ -8,137 +8,141 @@ include_once "AbstractManufacturer.php"; * Date: 25.03.13 * Time: 15:12 * @author Thomas Joußen - */ -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.
- * The following string is created by this function '/%[0-9]+%|#[0-9]+#|\+[0-9]+\+|Q[0-9]+([^\[|0-9]|$)|Q[0-9]+\[[0-9]+\]|~.*?~'
- * It matches all expression in a condition and is divided into the following parts: - * - *
-	 * 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
-	 * 
- * - * @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.
+ * The following string is created by this function '/%[0-9]+%|#[0-9]+#|\+[0-9]+\+|Q[0-9]+([^\[|0-9]|$)|Q[0-9]+\[[0-9]+\]|~.*?~'
+ * It matches all expression in a condition and is divided into the following parts: + * + *
+     * 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
+     * 
+ * + * @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() + { + } } diff --git a/Parser/classes/Factory/ManufacturerInterface.php b/Parser/classes/Factory/ManufacturerInterface.php index 20d49e25d9e30fc86d98adb4d1cfdf85ee161105..bc9f1283e9de8d9e36d2f3c232f21c2a49d9e743 100644 --- a/Parser/classes/Factory/ManufacturerInterface.php +++ b/Parser/classes/Factory/ManufacturerInterface.php @@ -7,36 +7,37 @@ * @author Thomas Joußen */ -interface ManufacturerInterface { +interface ManufacturerInterface +{ - /** - * Get an singleton of the manufacturer - * - * @return ManufacturerInterface - */ - public static function _getInstance(); + /** + * Get an singleton of the manufacturer + * + * @return ManufacturerInterface + */ + public static function _getInstance(); - /** - * Create a new specific Composite object which is representing the delivered Attribute - * - * @param string $attribute - * - * @return AbstractComposite - */ - public function manufacture($attribute); + /** + * Create a new specific Composite object which is representing the delivered Attribute + * + * @param string $attribute + * + * @return AbstractComposite + */ + public function manufacture($attribute); - /** - * @return string - */ - public function getPattern(); + /** + * @return string + */ + public function getPattern(); - /** - * Matches a delivered string with a the pattern returned by getPattern implemented in the explicit Manufacturer - * - * @param string $subject - * - * @see ManufacturerInterface::getPattern() - * @return array - */ - public function match($subject); -} \ No newline at end of file + /** + * Matches a delivered string with a the pattern returned by getPattern implemented in the explicit Manufacturer + * + * @param string $subject + * + * @see ManufacturerInterface::getPattern() + * @return array + */ + public function match($subject); +} diff --git a/Parser/classes/Factory/OperationManufacturer.php b/Parser/classes/Factory/OperationManufacturer.php index ee8afc3e8ea40fbd9ba0f951fb4fe843b546d792..608711985d7f7f146114bdc5c2c259653abf6176 100644 --- a/Parser/classes/Factory/OperationManufacturer.php +++ b/Parser/classes/Factory/OperationManufacturer.php @@ -8,118 +8,121 @@ require_once "AbstractManufacturer.php"; * Date: 25.03.13 * Time: 15:12 * @author Thomas Joußen - */ -class OperationManufacturer extends AbstractManufacturer{ + */ +class OperationManufacturer extends AbstractManufacturer +{ - /** - * A Singleton Instance of the OperationManufacturer - * - * @see OperatoinManufacturer::_getInstance() - * @see OperationManufacturer::__construct() - * - * @var null|OperationManufacturer - */ - protected static $instance = null; + /** + * A Singleton Instance of the OperationManufacturer + * + * @see OperatoinManufacturer::_getInstance() + * @see OperationManufacturer::__construct() + * + * @var null|OperationManufacturer + */ + protected static $instance = null; - /** - * Get an Instance of OperationManufacturer - * - * @return OperationManufacturer - */ - public static function _getInstance(){ - if(self::$instance == null){ - self::$instance = new OperationManufacturer(); - } - return self::$instance; - } + /** + * Get an Instance of OperationManufacturer + * + * @return OperationManufacturer + */ + public static function _getInstance() + { + if (self::$instance == null) { + self::$instance = new OperationManufacturer(); + } + return self::$instance; + } - /** - * Create a new specific Composite object which is representing the delivered Attribute - * - * @param string $attribute - * - * @return AbstractComposite|AndOperation|EqualsOperation|GreaterOperation|GreaterOrEqualsOperation|LesserOperation|LesserOrEqualsOperation|NotEqualsOperation|OrOperation - * @throws UnsupportedOperation - */ - public function manufacture($attribute) - { - $operation = ""; - switch($attribute) - { - case LesserOperation::$pattern: - $operation = new LesserOperation(); - break; - case LesserOrEqualsOperation::$pattern: - $operation = new LesserOrEqualsOperation(); - break; - case EqualsOperation::$pattern: - $operation = new EqualsOperation(); - break; - case GreaterOrEqualsOperation::$pattern: - $operation = new GreaterOrEqualsOperation(); - break; - case GreaterOperation::$pattern: - $operation = new GreaterOperation(); - break; - case NotEqualsOperation::$pattern: - $operation = new NotEqualsOperation(); - break; - case AndOperation::$pattern: - $operation = new AndOperation(); - break; - case OrOperation::$pattern: - $operation = new OrOperation(); - break; - default: - throw new UnsupportedOperation($attribute); - break; - } - return $operation; - } + /** + * Create a new specific Composite object which is representing the delivered Attribute + * + * @param string $attribute + * + * @return AbstractComposite|AndOperation|EqualsOperation|GreaterOperation|GreaterOrEqualsOperation|LesserOperation|LesserOrEqualsOperation|NotEqualsOperation|OrOperation + * @throws UnsupportedOperation + */ + public function manufacture($attribute) + { + $operation = ""; + switch ($attribute) { + case LesserOperation::$pattern: + $operation = new LesserOperation(); + break; + case LesserOrEqualsOperation::$pattern: + $operation = new LesserOrEqualsOperation(); + break; + case EqualsOperation::$pattern: + $operation = new EqualsOperation(); + break; + case GreaterOrEqualsOperation::$pattern: + $operation = new GreaterOrEqualsOperation(); + break; + case GreaterOperation::$pattern: + $operation = new GreaterOperation(); + break; + case NotEqualsOperation::$pattern: + $operation = new NotEqualsOperation(); + break; + case AndOperation::$pattern: + $operation = new AndOperation(); + break; + case OrOperation::$pattern: + $operation = new OrOperation(); + break; + default: + throw new UnsupportedOperation($attribute); + break; + } + return $operation; + } - /** - * This function create a regular expression to match all operators in a condition.
- * The following string is created by this function '/[\!&\|<>=]+/'
- * It matches all operators in a condition and is divided into the following parts: - * - *
-	 * NEGATION:           !
-	 * AND:                &
-	 * OR:                 |
-	 * LESSER:             <
-	 * LESSER OR EQUALS:   <=
-	 * EQUALS              =
-	 * GREATER OR EQUALS   >=
-	 * GREATER             >
-	 * NOT EQUALS          <>
-	 * 
- * - * @return string - */ - public function getPattern() - { -// return '/[&\|<>=]+/'; - return '/&|\||(?)=|<(?!=|>)|>(?!=)|<=|>=|<>/'; - } + /** + * This function create a regular expression to match all operators in a condition.
+ * The following string is created by this function '/[\!&\|<>=]+/'
+ * It matches all operators in a condition and is divided into the following parts: + * + *
+     * NEGATION:           !
+     * AND:                &
+     * OR:                 |
+     * LESSER:             <
+     * LESSER OR EQUALS:   <=
+     * EQUALS              =
+     * GREATER OR EQUALS   >=
+     * GREATER             >
+     * NOT EQUALS          <>
+     * 
+ * + * @return string + */ + public function getPattern() + { + // return '/[&\|<>=]+/'; + return '/&|\||(?)=|<(?!=|>)|>(?!=)|<=|>=|<>/'; + } - /** - * Private construtor to prevent creating an object of OperationManufacturer - */ - private function __construct() - { - require_once __DIR__ . '/../Operations/LesserOperation.php'; - require_once __DIR__ . '/../Operations/LesserOrEqualsOperation.php'; - require_once __DIR__ . '/../Operations/EqualsOperation.php'; - require_once __DIR__ . '/../Operations/GreaterOrEqualsOperation.php'; - require_once __DIR__ . '/../Operations/GreaterOperation.php'; - require_once __DIR__ . '/../Operations/NotEqualsOperation.php'; - require_once __DIR__ . '/../Operations/AndOperation.php'; - require_once __DIR__ . '/../Operations/OrOperation.php'; - require_once __DIR__ . '/../Exception/UnsupportedOperation.php'; - } + /** + * Private construtor to prevent creating an object of OperationManufacturer + */ + private function __construct() + { + require_once __DIR__ . '/../Operations/LesserOperation.php'; + require_once __DIR__ . '/../Operations/LesserOrEqualsOperation.php'; + require_once __DIR__ . '/../Operations/EqualsOperation.php'; + require_once __DIR__ . '/../Operations/GreaterOrEqualsOperation.php'; + require_once __DIR__ . '/../Operations/GreaterOperation.php'; + require_once __DIR__ . '/../Operations/NotEqualsOperation.php'; + require_once __DIR__ . '/../Operations/AndOperation.php'; + require_once __DIR__ . '/../Operations/OrOperation.php'; + require_once __DIR__ . '/../Exception/UnsupportedOperation.php'; + } - /** - * Private clone to prevent cloning an object of OperationManufacturer - */ - private function __clone() {} + /** + * Private clone to prevent cloning an object of OperationManufacturer + */ + private function __clone() + { + } } diff --git a/Parser/classes/Operations/AbstractOperation.php b/Parser/classes/Operations/AbstractOperation.php index 849720c4d7756383fa010cb65083709f6f17a98f..2860c9fb0eedd38c576a7799bda878cdee55a521 100644 --- a/Parser/classes/Operations/AbstractOperation.php +++ b/Parser/classes/Operations/AbstractOperation.php @@ -8,32 +8,33 @@ include_once __DIR__ . "/../AbstractComposite.php"; * Date: 25.03.13 * Time: 15:37 * @author Thomas Joußen - */ -abstract class AbstractOperation extends AbstractComposite { + */ +abstract class AbstractOperation extends AbstractComposite +{ - /** - * @var bool - */ - protected $negated = false; + /** + * @var bool + */ + protected $negated = false; - /** - * @return string - */ - abstract public function getPattern(); + /** + * @return string + */ + abstract public function getPattern(); - /** - * @param boolean $negated - */ - public function setNegated($negated) - { - $this->negated = $negated; - } + /** + * @param boolean $negated + */ + public function setNegated($negated) + { + $this->negated = $negated; + } - /** - * @return boolean - */ - public function isNegated() - { - return $this->negated; - } + /** + * @return boolean + */ + public function isNegated() + { + return $this->negated; + } } diff --git a/Parser/classes/Operations/AndOperation.php b/Parser/classes/Operations/AndOperation.php index dcb1279bb1b752e0a069f9aff275d8b66720271f..cfe6c4dc7e2392dd1832b895763fe33507996cff 100644 --- a/Parser/classes/Operations/AndOperation.php +++ b/Parser/classes/Operations/AndOperation.php @@ -8,28 +8,29 @@ include_once 'AbstractOperation.php'; * Date: 25.03.13 * Time: 14:58 * @author Thomas Joußen - */ -class AndOperation extends AbstractOperation{ + */ +class AndOperation extends AbstractOperation +{ - /** - * @var string - */ - public static $pattern = "&"; + /** + * @var string + */ + public static $pattern = "&"; - /** - * Get a human readable description of the Composite element - * @return string - */ - public function getDescription() - { - return "und "; - } + /** + * Get a human readable description of the Composite element + * @return string + */ + public function getDescription() + { + return "und "; + } - /** - * @return string - */ - public function getPattern() - { - return self::$pattern; - } + /** + * @return string + */ + public function getPattern() + { + return self::$pattern; + } } diff --git a/Parser/classes/Operations/EqualsOperation.php b/Parser/classes/Operations/EqualsOperation.php index 4accf799db0248dcb4f48cd8d786fa1b199c250b..3258a258815d7eb641d807c4ca97b38f535aca71 100644 --- a/Parser/classes/Operations/EqualsOperation.php +++ b/Parser/classes/Operations/EqualsOperation.php @@ -8,25 +8,26 @@ include_once 'AbstractOperation.php'; * Date: 25.03.13 * Time: 14:57 * @author Thomas Joußen - */ -class EqualsOperation extends AbstractOperation { + */ +class EqualsOperation extends AbstractOperation +{ - /** - * @var string - */ - public static $pattern = "="; + /** + * @var string + */ + public static $pattern = "="; - /** - * Get a human readable description of the Composite element - * @return string - */ - public function getDescription() - { - return 'mit genau '; - } + /** + * Get a human readable description of the Composite element + * @return string + */ + public function getDescription() + { + return 'mit genau '; + } - public function getPattern() - { - return self::$pattern; - } + public function getPattern() + { + return self::$pattern; + } } diff --git a/Parser/classes/Operations/GreaterOperation.php b/Parser/classes/Operations/GreaterOperation.php index fce2880714e94be465bc41fc4fde2c7932e67d75..1e0f85ed33bd3350c51307f04e30f340b4157eb7 100644 --- a/Parser/classes/Operations/GreaterOperation.php +++ b/Parser/classes/Operations/GreaterOperation.php @@ -8,24 +8,25 @@ include_once 'AbstractOperation.php'; * Date: 25.03.13 * Time: 14:57 * @author Thomas Joußen - */ -class GreaterOperation extends AbstractOperation{ + */ +class GreaterOperation extends AbstractOperation +{ - /** - * @var string - */ - public static $pattern = ">"; + /** + * @var string + */ + public static $pattern = ">"; - function getDescription() - { - return "mit mehr als "; - } + public function getDescription() + { + return "mit mehr als "; + } - /** - * @return string - */ - public function getPattern() - { - return self::$pattern; - } + /** + * @return string + */ + public function getPattern() + { + return self::$pattern; + } } diff --git a/Parser/classes/Operations/GreaterOrEqualsOperation.php b/Parser/classes/Operations/GreaterOrEqualsOperation.php index 7304c522ff3bed63f4a0b652dec5f8db64a32be7..f83204fc2d45a3bc495b8ff222bd6ee21020e8d1 100644 --- a/Parser/classes/Operations/GreaterOrEqualsOperation.php +++ b/Parser/classes/Operations/GreaterOrEqualsOperation.php @@ -8,24 +8,25 @@ include_once 'AbstractOperation.php'; * Date: 25.03.13 * Time: 14:58 * @author Thomas Joußen - */ -class GreaterOrEqualsOperation extends AbstractOperation{ + */ +class GreaterOrEqualsOperation extends AbstractOperation +{ - /** - * @var string - */ - public static $pattern = ">="; + /** + * @var string + */ + public static $pattern = ">="; - function getDescription() - { - return "mit mehr oder genau "; - } + public function getDescription() + { + return "mit mehr oder genau "; + } - /** - * @return string - */ - public function getPattern() - { - return self::$pattern; - } + /** + * @return string + */ + public function getPattern() + { + return self::$pattern; + } } diff --git a/Parser/classes/Operations/LesserOperation.php b/Parser/classes/Operations/LesserOperation.php index cbb97eded51bd3a0ea6b4b52f7ae24cf0cc1afbe..b1ae1d615194686dc625460afb6f5f0850503bde 100644 --- a/Parser/classes/Operations/LesserOperation.php +++ b/Parser/classes/Operations/LesserOperation.php @@ -8,24 +8,25 @@ include_once 'AbstractOperation.php'; * Date: 25.03.13 * Time: 14:57 * @author Thomas Joußen - */ -class LesserOperation extends AbstractOperation{ + */ +class LesserOperation extends AbstractOperation +{ - /** - * @var string - */ - public static $pattern = "<"; + /** + * @var string + */ + public static $pattern = "<"; - function getDescription() - { - return "mit weniger als "; - } + public function getDescription() + { + return "mit weniger als "; + } - /** - * @return string - */ - public function getPattern() - { - return self::$pattern; - } + /** + * @return string + */ + public function getPattern() + { + return self::$pattern; + } } diff --git a/Parser/classes/Operations/LesserOrEqualsOperation.php b/Parser/classes/Operations/LesserOrEqualsOperation.php index 490c7b9632a106844fcd10ae6e9cac7390aabc90..794d2327e79a55b1ca5fa75a27177c441781bf12 100644 --- a/Parser/classes/Operations/LesserOrEqualsOperation.php +++ b/Parser/classes/Operations/LesserOrEqualsOperation.php @@ -8,24 +8,25 @@ include_once 'AbstractOperation.php'; * Date: 25.03.13 * Time: 14:58 * @author Thomas Joußen - */ -class LesserOrEqualsOperation extends AbstractOperation{ + */ +class LesserOrEqualsOperation extends AbstractOperation +{ - /** - * @var string - */ - public static $pattern = "<="; + /** + * @var string + */ + public static $pattern = "<="; - function getDescription() - { - return "mit weniger oder gleich "; - } + public function getDescription() + { + return "mit weniger oder gleich "; + } - /** - * @return string - */ - public function getPattern() - { - return self::$pattern; - } + /** + * @return string + */ + public function getPattern() + { + return self::$pattern; + } } diff --git a/Parser/classes/Operations/NotEqualsOperation.php b/Parser/classes/Operations/NotEqualsOperation.php index 57b302d479d0eac5826e2b937848d9ecf9403d55..df03711a0b0e830f5969d126da4ac06247a19826 100644 --- a/Parser/classes/Operations/NotEqualsOperation.php +++ b/Parser/classes/Operations/NotEqualsOperation.php @@ -8,24 +8,25 @@ include_once 'AbstractOperation.php'; * Date: 25.03.13 * Time: 14:57 * @author Thomas Joußen - */ -class NotEqualsOperation extends AbstractOperation{ + */ +class NotEqualsOperation extends AbstractOperation +{ - /** - * @var string - */ - public static $pattern = "<>"; + /** + * @var string + */ + public static $pattern = "<>"; - function getDescription() - { - return "nicht mit "; - } + public function getDescription() + { + return "nicht mit "; + } - /** - * @return string - */ - public function getPattern() - { - return self::$pattern; - } + /** + * @return string + */ + public function getPattern() + { + return self::$pattern; + } } diff --git a/Parser/classes/Operations/OrOperation.php b/Parser/classes/Operations/OrOperation.php index 1fa3a35e1721f65ebbccdb0a5c0f76c641905e58..d163965a83651fc9d8506a46b624170d4c01b273 100644 --- a/Parser/classes/Operations/OrOperation.php +++ b/Parser/classes/Operations/OrOperation.php @@ -8,24 +8,25 @@ include_once 'AbstractOperation.php'; * Date: 25.03.13 * Time: 14:58 * @author Thomas Joußen - */ -class OrOperation extends AbstractOperation{ + */ +class OrOperation extends AbstractOperation +{ - /** - * @var string - */ - public static $pattern = "|"; + /** + * @var string + */ + public static $pattern = "|"; - function getDescription() - { - return "oder "; - } + public function getDescription() + { + return "oder "; + } - /** - * @return string - */ - public function getPattern() - { - return self::$pattern; - } + /** + * @return string + */ + public function getPattern() + { + return self::$pattern; + } } diff --git a/README.md b/README.md index 9242bd510f62bf711c89e84682ea58d2c570d968..ccf1891cc2a719910b1bb2ab8bf96809c61e9c64 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ # ILIAS QuestionSetPool -* For ILIAS versions: 5.3.0 - 5.4.999 +* For ILIAS versions: 6.0 - 6.999 ## Installation Instructions 1. Create the plugin path: @@ -20,3 +20,10 @@ 3. Select **Plugins** from the **Administration** main menu drop down. 4. Search the **QuestionSetPool** plugin in the list of plugin and choose **Activate** from the **Actions** drop down. 5. Choose **Configure** from the **Actions** drop down and enter the required data. + +## Dependencies + +### Graphviz + +Please install [`Graphviz`](https://graphviz.org/). Graphviz is required for +the graph visualization of the question paths. \ No newline at end of file diff --git a/classes/class.ilObjQuestionSetPool.php b/classes/class.ilObjQuestionSetPool.php index 176bca72a9107d11e55ea48e90e8e81a4c64bdbf..66c16a3e8882e3e9e72d5e9233be79faa301108c 100644 --- a/classes/class.ilObjQuestionSetPool.php +++ b/classes/class.ilObjQuestionSetPool.php @@ -1,9 +1,7 @@ - */ + */ class ilObjQuestionSetPool extends ilObjectPlugin implements ilPluginModelInterface, ilQuestionEditingFormConsumer { - /** - * @var ilQuestionSetPoolPlugin - */ - public $plugin; - - /** - * Boolean to check weather the object is online - * - * @var boolean - */ - protected $online; - - /** - * @var ilQuestionSetPoolSetList - */ - protected $set_list; - - /** - * @var array - */ - protected static $online_status_map = array(); - - /** - * @var bool - */ - private $skillServiceEnabled = false; - - /** - * @var null|bool - */ - private static $isSkillManagementGloballyActivated = null; - - /** - * @param int $a_ref_id - */ - public function __construct($a_ref_id = 0) - { - global $DIC; - - require_once 'models/class.ilQuestionSetPoolSetList.php'; - parent::__construct($a_ref_id); - - $DIC->language()->loadLanguageModule('assessment'); - } + /** + * @var ilQuestionSetPoolPlugin + */ + public $plugin; + + /** + * Boolean to check weather the object is online + * + * @var boolean + */ + protected $online; + + /** + * @var ilQuestionSetPoolSetList + */ + protected $set_list; + + /** + * @var array + */ + protected static $online_status_map = array(); + + /** + * @var bool + */ + private $skillServiceEnabled = false; + + /** + * @var null|bool + */ + private static $isSkillManagementGloballyActivated = null; + + /** + * @param int $a_ref_id + */ + public function __construct($a_ref_id = 0) + { + global $DIC; + + require_once 'models/class.ilQuestionSetPoolSetList.php'; + parent::__construct($a_ref_id); + + $DIC->language()->loadLanguageModule('assessment'); + } public function checkQuestionParent($questionId) { @@ -72,484 +70,455 @@ class ilObjQuestionSetPool extends ilObjectPlugin implements ilPluginModelInterf return (bool) $row['cnt']; } - /** - * @return string - */ - public function getQuestionEditingFormBackTargetLabel() - { - return ilQuestionSetPoolPlugin::getInstance()->txt('back_to_qsp'); - } - - /** - * @param $context - * @return string - */ - public function getQuestionEditingFormBackTarget($context) - { - global $DIC; - $ilCtrl = $DIC->ctrl(); - $params = @json_decode(base64_decode($context), true); - - $ilCtrl->setParameterByClass('ilObjPluginDispatchGUI', 'ref_id', $this->getRefId()); - $url = $ilCtrl->getLinkTargetByClass(array('ilObjPluginDispatchGUI', 'ilObjQuestionSetPoolGUI'), '', '', false, false); - foreach((array)$params as $key => $value) - { - $url = ilUtil::appendUrlParameterString($url, $key . '='. $value); - } - - return $url; - } - - /** - * - */ - protected function initType() - { - require_once 'class.ilQuestionSetPoolPlugin.php'; - $this->setType(ilQuestionSetPoolPlugin::getPluginId()); - } - - protected function doRead() - { - global $DIC; - $ilDB = $DIC->database(); - - $this->set_list = new ilQuestionSetPoolSetList($this); - - $result = $ilDB->queryF( - "SELECT * FROM rep_robj_xqsp_data WHERE id = %s", - array("integer"), - array($this->id) - ); - - $data = $ilDB->fetchAssoc($result); - - $this->setOnline($data["is_online"]); - $this->setSkillServiceEnabled($data['skill_service']); - } - - /** - * - */ - public function doCreate() - { - global $DIC; - $ilDB = $DIC->database(); - - $this->set_list = new ilQuestionSetPoolSetList($this); - - $ilDB->insert( - $this->plugin->getAdditionalDataTable(), - array( - "id" => array("integer", $this->id), - "is_online" => array("integer", $this->isOnline()) - ) - ); - - $this->createMetaData(); - } - - /** - * - */ - public function doUpdate() - { - global $DIC; - $ilDB = $DIC->database(); - - $ilDB->update( - $this->plugin->getAdditionalDataTable(), - array( - "is_online" => array("integer", $this->isOnline()), - 'skill_service' => array('integer', $this->isSkillServiceEnabled()) - ), - array( - "id" => array("integer", $this->id) - ) - ); - - $this->updateMetaData(); - } - - /** - * Cascade delete children - */ - protected function beforeDelete() - { - $sets = $this->set_list->getData(); - foreach($sets as $set) - { - /** - * @var $set ilQuestionSetPoolSet - */ - $set->remove(); - } - - return true; - } - - protected function doDelete() - { - global $DIC; - $ilDB = $DIC->database(); - - $query = 'DELETE FROM '.$this->plugin->getAdditionalDataTable().' WHERE id = ' . $ilDB->quote($this->getId(), 'integer'); - $ilDB->manipulate($query); - - $this->deleteMetaData(); - } - - - - /** - * @param ilObjQuestionSetPool $new_obj - * @param int $a_target_id - * @param int $a_copy_id - */ - public function doCloneObject($new_obj, $a_target_id, $a_copy_id = NULL) - { - $this->cloneMetaData($new_obj); - $this->cloneQuestionSets($new_obj); - } - - /** - * @param ilObjQuestionSetPool| ilObjFormATest $new_obj - */ - public function cloneQuestionSets($new_obj) - { - $this->plugin->includeClass('models/class.ilQuestionSetPoolSet.php'); - $this->plugin->includeClass('models/class.ilQuestionSetPoolPath.php'); - $this->plugin->includeClass('models/class.ilQuestionSetPoolNode.php'); - $this->plugin->includeClass('models/class.ilQuestionSetPoolJumpCondition.php'); - - $setlist = $this->getSetList(); - $sets = $setlist->loadData(); - foreach((array)$sets as $set_index => $set_data) - { - $set = new ilQuestionSetPoolSet((int)$set_data['id']); - $set->read(); - - $new_set = new ilQuestionSetPoolSet(); - $new_set->setContainerObjId($new_obj->getId()); - $new_set->setTitle((string)$set->getTitle()); - $new_set->setDescription((string)$set->getDescription()); - $new_set->update(); - - // Export QuestionList - $question_mapping = $this->cloneQuestionList($set, $new_set); - - // Export Paths - $this->clonePathList($set->getPathList(), $new_set, $question_mapping); - } - } - - /** - * @param ilQuestionSetPoolSet $source_set - * @param ilQuestionSetPoolSet $new_set - * @return array - */ - protected function cloneQuestionList(ilQuestionSetPoolSet $source_set, ilQuestionSetPoolSet $new_set) - { - $questionList = $source_set->getQuestionList(); - $questions = $questionList->loadData(); - - $mapping = array(); - - foreach((array)$questions as $question_index => $question) - { - $mapping = $questionList->cloneQuestionList(array($question['question_id']), $source_set, $new_set) + $mapping; - } - - return $mapping; - } - - /** - * @param ilQuestionSetPoolPathList $pathList - * @param ilQuestionSetPoolSet $new_set - * @param array $question_mapping A map of integer values, old_question_fi -> new_question_fi - */ - protected function clonePathList(ilQuestionSetPoolPathList $pathList, ilQuestionSetPoolSet $new_set, array $question_mapping) - { - $paths = $pathList->loadData(); - foreach((array)$paths as $path_index => $path_data) - { - $path = new ilQuestionSetPoolPath(); - $path->setId($path_data['id']); - $path->read(); - - $new_path = new ilQuestionSetPoolPath(); - $new_path->setSet($new_set); - $new_path->setTitle($path->getTitle()); - $new_path->setIndex($path->getIndex()); - $new_path->import(); - - // Nodes - $this->cloneNodeList($path->getNodes(), $new_path, $question_mapping); - } - } - - /** - * @param ilQuestionSetPoolNodeList $nodeList - * @param ilQuestionSetPoolPath $new_path - * @param array $question_mapping A map of integer values, old_question_fi -> new_question_fi - * $question_mapping A map of integer values, old_question_fi -> new_question_fi - */ - protected function cloneNodeList(ilQuestionSetPoolNodeList $nodeList, ilQuestionSetPoolPath $new_path, array $question_mapping) - { - $nodes = $nodeList->loadData(); - foreach((array)$nodes as $node_index => $node_data) - { - $node = new ilQuestionSetPoolNode((int)$node_data['id']); - $node->read(); - - $new_node = new ilQuestionSetPoolNode(); - if(isset($question_mapping[$node->getQuestion()->getId()])) - { - $new_node->setQuestion(assQuestion::_instantiateQuestion($question_mapping[$node->getQuestion()->getId()])); - } - else - { - $new_node->setQuestion(assQuestion::_instantiateQuestion($node->getQuestion()->getId())); - } - $new_node->setPath($new_path); - $new_node->setInitialCondition($node->getInitialCondition()); - $new_node->setDominantScoring($node->getDominantScoring()); - $new_node->setTrueFeedback($node->getTrueFeedback()); - $new_node->setFalseFeedback($node->getFalseFeedback()); - $new_node->import(); - - // Jump Conditions - $this->cloneJumpConditions($node->getJumpConditionList(), $new_node); - } - } - - /** - * @param ilQuestionSetPoolJumpConditionList $jumpConditionList - * @param ilQuestionSetPoolNode $new_node - */ - protected function cloneJumpConditions(ilQuestionSetPoolJumpConditionList $jumpConditionList, ilQuestionSetPoolNode $new_node) - { - $jumpConditions = $jumpConditionList->getData(); - foreach((array)$jumpConditions as $jmp_con_index => $jumpCondition_data) - { - $jumpCondition = new ilQuestionSetPoolJumpCondition(); - $jumpCondition->setId($jumpCondition_data['id']); - $jumpCondition->read(); - - $new_jump_con = new ilQuestionSetPoolJumpCondition(); - $new_jump_con->setNode($new_node); - $new_jump_con->setQuestion($new_node->getQuestion()); - $new_jump_con->setJumpCondition($jumpCondition->getJumpCondition()); - $new_jump_con->setRepititions($jumpCondition->getRepititions()); - $new_jump_con->setTrueFeedback($jumpCondition->getTrueFeedback()); - $new_jump_con->setTrueJumpFeedback($jumpCondition->getTrueJumpFeedback()); - $new_jump_con->setFalseFeedback($jumpCondition->getFalseFeedback()); - - $new_jump_con->import(); - } - } - - /** - * @param boolean $online - */ - public function setOnline($online) - { - $this->online = $online; - } - - /** - * @return boolean - */ - public function isOnline() - { - return $this->online; - } - - /** - * @return ilQuestionSetPoolSetList - */ - public function getSetList() - { - return $this->set_list; - } - - /** - * @return array - */ - public function toArray() - { - return array( - 'title' => $this->getTitle(), - 'description' => $this->getDescription(), - 'online' => $this->isOnline(), - 'skill_service' => $this->isSkillServiceEnabled() - ); - } - - /** - * @param ilPropertyFormGUI $form - */ - public function bindForm(ilPropertyFormGUI $form) - { - $this->setTitle($form->getInput('title')); - $this->setDescription($form->getInput('description')); - $this->setOnline($form->getInput('online')); - $this->setSkillServiceEnabled((bool)$form->getInput('skill_service')); - } - - /** - * @param int $obj_id - * @return bool - */ - public static function getOnlineStatusByObjId($obj_id) - { - if(isset(self::$online_status_map[$obj_id])) - { - return (bool)self::$online_status_map[$obj_id]; - } - - self::preloadDataForLists(array($obj_id)); - } - - /** - * @param array $obj_ids - * @param array $ref_ids - */ - public static function preloadDataForLists(array $obj_ids, array $ref_ids = array()) - { - global $DIC; - $ilDB = $DIC->database(); - - if(is_array($obj_ids) && count($obj_ids) == 1) - { - $in = ' id = ' . $ilDB->quote(current($obj_ids), 'integer') . ' '; - } - else - { - $in = $ilDB->in('id', $obj_ids, false, 'integer'); - } - - $query = " + /** + * @return string + */ + public function getQuestionEditingFormBackTargetLabel() + { + return ilQuestionSetPoolPlugin::getInstance()->txt('back_to_qsp'); + } + + /** + * @param $context + * @return string + */ + public function getQuestionEditingFormBackTarget($context) + { + global $DIC; + $ilCtrl = $DIC->ctrl(); + $params = @json_decode(base64_decode($context), true); + + $ilCtrl->setParameterByClass('ilObjPluginDispatchGUI', 'ref_id', $this->getRefId()); + $url = $ilCtrl->getLinkTargetByClass(array('ilObjPluginDispatchGUI', 'ilObjQuestionSetPoolGUI'), '', '', false, false); + foreach ((array) $params as $key => $value) { + $url = ilUtil::appendUrlParameterString($url, $key . '=' . $value); + } + + return $url; + } + + /** + * + */ + protected function initType() + { + require_once 'class.ilQuestionSetPoolPlugin.php'; + $this->setType(ilQuestionSetPoolPlugin::getPluginId()); + } + + protected function doRead() + { + global $DIC; + $ilDB = $DIC->database(); + + $this->set_list = new ilQuestionSetPoolSetList($this); + + $result = $ilDB->queryF( + "SELECT * FROM rep_robj_xqsp_data WHERE id = %s", + array("integer"), + array($this->id) + ); + + $data = $ilDB->fetchAssoc($result); + + $this->setOnline($data["is_online"]); + $this->setSkillServiceEnabled($data['skill_service']); + } + + /** + * + */ + public function doCreate() + { + global $DIC; + $ilDB = $DIC->database(); + + $this->set_list = new ilQuestionSetPoolSetList($this); + + $ilDB->insert( + $this->plugin->getAdditionalDataTable(), + array( + "id" => array("integer", $this->id), + "is_online" => array("integer", $this->isOnline()) + ) + ); + + $this->createMetaData(); + } + + /** + * + */ + public function doUpdate() + { + global $DIC; + $ilDB = $DIC->database(); + + $ilDB->update( + $this->plugin->getAdditionalDataTable(), + array( + "is_online" => array("integer", $this->isOnline()), + 'skill_service' => array('integer', $this->isSkillServiceEnabled()) + ), + array( + "id" => array("integer", $this->id) + ) + ); + + $this->updateMetaData(); + } + + /** + * Cascade delete children + */ + protected function beforeDelete() + { + $sets = $this->set_list->getData(); + foreach ($sets as $set) { + /** + * @var $set ilQuestionSetPoolSet + */ + $set->remove(); + } + + return true; + } + + protected function doDelete() + { + global $DIC; + $ilDB = $DIC->database(); + + $query = 'DELETE FROM ' . $this->plugin->getAdditionalDataTable() . ' WHERE id = ' . $ilDB->quote($this->getId(), 'integer'); + $ilDB->manipulate($query); + + $this->deleteMetaData(); + } + + + + /** + * @param ilObjQuestionSetPool $new_obj + * @param int $a_target_id + * @param int $a_copy_id + */ + public function doCloneObject($new_obj, $a_target_id, $a_copy_id = null) + { + $this->cloneMetaData($new_obj); + $this->cloneQuestionSets($new_obj); + } + + /** + * @param ilObjQuestionSetPool| ilObjFormATest $new_obj + */ + public function cloneQuestionSets($new_obj) + { + $this->plugin->includeClass('models/class.ilQuestionSetPoolSet.php'); + $this->plugin->includeClass('models/class.ilQuestionSetPoolPath.php'); + $this->plugin->includeClass('models/class.ilQuestionSetPoolNode.php'); + $this->plugin->includeClass('models/class.ilQuestionSetPoolJumpCondition.php'); + + $setlist = $this->getSetList(); + $sets = $setlist->loadData(); + foreach ((array) $sets as $set_index => $set_data) { + $set = new ilQuestionSetPoolSet((int) $set_data['id']); + $set->read(); + + $new_set = new ilQuestionSetPoolSet(); + $new_set->setContainerObjId($new_obj->getId()); + $new_set->setTitle((string) $set->getTitle()); + $new_set->setDescription((string) $set->getDescription()); + $new_set->update(); + + // Export QuestionList + $question_mapping = $this->cloneQuestionList($set, $new_set); + + // Export Paths + $this->clonePathList($set->getPathList(), $new_set, $question_mapping); + } + } + + /** + * @param ilQuestionSetPoolSet $source_set + * @param ilQuestionSetPoolSet $new_set + * @return array + */ + protected function cloneQuestionList(ilQuestionSetPoolSet $source_set, ilQuestionSetPoolSet $new_set) + { + $questionList = $source_set->getQuestionList(); + $questions = $questionList->loadData(); + + $mapping = array(); + + foreach ((array) $questions as $question_index => $question) { + $mapping = $questionList->cloneQuestionList(array($question['question_id']), $source_set, $new_set) + $mapping; + } + + return $mapping; + } + + /** + * @param ilQuestionSetPoolPathList $pathList + * @param ilQuestionSetPoolSet $new_set + * @param array $question_mapping A map of integer values, old_question_fi -> new_question_fi + */ + protected function clonePathList(ilQuestionSetPoolPathList $pathList, ilQuestionSetPoolSet $new_set, array $question_mapping) + { + $paths = $pathList->loadData(); + foreach ((array) $paths as $path_index => $path_data) { + $path = new ilQuestionSetPoolPath(); + $path->setId($path_data['id']); + $path->read(); + + $new_path = new ilQuestionSetPoolPath(); + $new_path->setSet($new_set); + $new_path->setTitle($path->getTitle()); + $new_path->setIndex($path->getIndex()); + $new_path->import(); + + // Nodes + $this->cloneNodeList($path->getNodes(), $new_path, $question_mapping); + } + } + + /** + * @param ilQuestionSetPoolNodeList $nodeList + * @param ilQuestionSetPoolPath $new_path + * @param array $question_mapping A map of integer values, old_question_fi -> new_question_fi + * $question_mapping A map of integer values, old_question_fi -> new_question_fi + */ + protected function cloneNodeList(ilQuestionSetPoolNodeList $nodeList, ilQuestionSetPoolPath $new_path, array $question_mapping) + { + $nodes = $nodeList->loadData(); + foreach ((array) $nodes as $node_index => $node_data) { + $node = new ilQuestionSetPoolNode((int) $node_data['id']); + $node->read(); + + $new_node = new ilQuestionSetPoolNode(); + if (isset($question_mapping[$node->getQuestion()->getId()])) { + $new_node->setQuestion(assQuestion::_instantiateQuestion($question_mapping[$node->getQuestion()->getId()])); + } else { + $new_node->setQuestion(assQuestion::_instantiateQuestion($node->getQuestion()->getId())); + } + $new_node->setPath($new_path); + $new_node->setInitialCondition($node->getInitialCondition()); + $new_node->setDominantScoring($node->getDominantScoring()); + $new_node->setTrueFeedback($node->getTrueFeedback()); + $new_node->setFalseFeedback($node->getFalseFeedback()); + $new_node->import(); + + // Jump Conditions + $this->cloneJumpConditions($node->getJumpConditionList(), $new_node); + } + } + + /** + * @param ilQuestionSetPoolJumpConditionList $jumpConditionList + * @param ilQuestionSetPoolNode $new_node + */ + protected function cloneJumpConditions(ilQuestionSetPoolJumpConditionList $jumpConditionList, ilQuestionSetPoolNode $new_node) + { + $jumpConditions = $jumpConditionList->getData(); + foreach ((array) $jumpConditions as $jmp_con_index => $jumpCondition_data) { + $jumpCondition = new ilQuestionSetPoolJumpCondition(); + $jumpCondition->setId($jumpCondition_data['id']); + $jumpCondition->read(); + + $new_jump_con = new ilQuestionSetPoolJumpCondition(); + $new_jump_con->setNode($new_node); + $new_jump_con->setQuestion($new_node->getQuestion()); + $new_jump_con->setJumpCondition($jumpCondition->getJumpCondition()); + $new_jump_con->setRepititions($jumpCondition->getRepititions()); + $new_jump_con->setTrueFeedback($jumpCondition->getTrueFeedback()); + $new_jump_con->setTrueJumpFeedback($jumpCondition->getTrueJumpFeedback()); + $new_jump_con->setFalseFeedback($jumpCondition->getFalseFeedback()); + + $new_jump_con->import(); + } + } + + /** + * @param boolean $online + */ + public function setOnline($online) + { + $this->online = $online; + } + + /** + * @return boolean + */ + public function isOnline() + { + return $this->online; + } + + /** + * @return ilQuestionSetPoolSetList + */ + public function getSetList() + { + return $this->set_list; + } + + /** + * @return array + */ + public function toArray() + { + return array( + 'title' => $this->getTitle(), + 'description' => $this->getDescription(), + 'online' => $this->isOnline(), + 'skill_service' => $this->isSkillServiceEnabled() + ); + } + + /** + * @param ilPropertyFormGUI $form + */ + public function bindForm(ilPropertyFormGUI $form) + { + $this->setTitle($form->getInput('title')); + $this->setDescription($form->getInput('description')); + $this->setOnline($form->getInput('online')); + $this->setSkillServiceEnabled((bool) $form->getInput('skill_service')); + } + + /** + * @param int $obj_id + * @return bool + */ + public static function getOnlineStatusByObjId($obj_id) + { + if (isset(self::$online_status_map[$obj_id])) { + return (bool) self::$online_status_map[$obj_id]; + } + + self::preloadDataForLists(array($obj_id)); + } + + /** + * @param array $obj_ids + * @param array $ref_ids + */ + public static function preloadDataForLists(array $obj_ids, array $ref_ids = array()) + { + global $DIC; + $ilDB = $DIC->database(); + + if (is_array($obj_ids) && count($obj_ids) == 1) { + $in = ' id = ' . $ilDB->quote(current($obj_ids), 'integer') . ' '; + } else { + $in = $ilDB->in('id', $obj_ids, false, 'integer'); + } + + $query = " SELECT id, is_online FROM rep_robj_xqsp_data WHERE $in "; - $res = $ilDB->query($query); - - while($row = $ilDB->fetchAssoc($res)) - { - self::$online_status_map[$row['id']] = $row['is_online']; - } - } - - public static function getAvailableQuestionSetPools($could_be_offline = FALSE) - { - global $DIC; - $ilDB = $DIC->database(); - $ilUser = $DIC->user(); - - $result_array = array(); - - $pools = ilUtil::_getObjectsByOperations("xqsp", "read", $ilUser->getId(), -1); - $obj_ids = array(); - $ref_ids = array(); - foreach($pools as $ref_id) - { - $obj_ids[$ref_id] = ilObject::_lookupObjId($ref_id); - $ref_ids[ilObject::_lookupObjId($ref_id)] = $ref_id; - } - - if($could_be_offline) - { - $result = $ilDB->query("SELECT id FROM rep_robj_xqsp_data WHERE " . $ilDB->in("id", $obj_ids, false, "integer")); - } - else - { - $result = $ilDB->queryF( - "SELECT id FROM rep_robj_xqsp_data WHERE is_online = %s AND " . $ilDB->in("id", $obj_ids, false, "integer"), - array("integer"), - array(1) - ); - } - - while(($row = $ilDB->fetchAssoc($result)) != null) - { - $pool = new ilObjQuestionSetPool(); - $pool->setRefId($ref_ids[$row["id"]]); - $pool->read(); - $result_array[$row["id"]] = $pool; - } - - return $result_array; - } - - public static function canSynchronizeSet($set_id) - { - global $DIC; - $rbacsystem = $DIC->rbac()->system(); - - if($set_id == null) - { - return false; - } - - $set = new ilQuestionSetPoolSet($set_id); - $set->read(); - if($set->getContainerObjId() != null) - { - $available = array_keys(self::getAvailableQuestionSetPools()); - - if(in_array($set->getContainerObjId(), $available)) - { - $refs = ilObject::_getAllReferences($set->getContainerObjId()); - foreach($refs as $ref) - { - if($rbacsystem->checkAccess("write", $ref) && ilObject::_hasUntrashedReference($set->getContainerObjId())) - { - return true; - } - } - } - } - - return false; - } - - /** - * @param boolean $skillServiceEnabled - */ - public function setSkillServiceEnabled($skillServiceEnabled) - { - $this->skillServiceEnabled = $skillServiceEnabled; - } - - /** - * @return bool - */ - public function isSkillServiceEnabled() - { - if(!self::isSkillManagementGloballyActivated()) - { - return false; - } - - return $this->skillServiceEnabled; - } - - /** - * @return bool - */ - public static function isSkillManagementGloballyActivated() - { - - if( self::$isSkillManagementGloballyActivated === null ) - { - include_once './Services/Skill/classes/class.ilSkillManagementSettings.php'; - $skmgSet = new ilSkillManagementSettings(); - - self::$isSkillManagementGloballyActivated = $skmgSet->isActivated(); - } - - return self::$isSkillManagementGloballyActivated; - } + $res = $ilDB->query($query); + + while ($row = $ilDB->fetchAssoc($res)) { + self::$online_status_map[$row['id']] = $row['is_online']; + } + } + + public static function getAvailableQuestionSetPools($could_be_offline = false) + { + global $DIC; + $ilDB = $DIC->database(); + $ilUser = $DIC->user(); + + $result_array = array(); + + $pools = ilUtil::_getObjectsByOperations("xqsp", "read", $ilUser->getId(), -1); + $obj_ids = array(); + $ref_ids = array(); + foreach ($pools as $ref_id) { + $obj_ids[$ref_id] = ilObject::_lookupObjId($ref_id); + $ref_ids[ilObject::_lookupObjId($ref_id)] = $ref_id; + } + + if ($could_be_offline) { + $result = $ilDB->query("SELECT id FROM rep_robj_xqsp_data WHERE " . $ilDB->in("id", $obj_ids, false, "integer")); + } else { + $result = $ilDB->queryF( + "SELECT id FROM rep_robj_xqsp_data WHERE is_online = %s AND " . $ilDB->in("id", $obj_ids, false, "integer"), + array("integer"), + array(1) + ); + } + + while (($row = $ilDB->fetchAssoc($result)) != null) { + $pool = new ilObjQuestionSetPool(); + $pool->setRefId($ref_ids[$row["id"]]); + $pool->read(); + $result_array[$row["id"]] = $pool; + } + + return $result_array; + } + + public static function canSynchronizeSet($set_id) + { + global $DIC; + $rbacsystem = $DIC->rbac()->system(); + + if ($set_id == null) { + return false; + } + + $set = new ilQuestionSetPoolSet($set_id); + $set->read(); + if ($set->getContainerObjId() != null) { + $available = array_keys(self::getAvailableQuestionSetPools()); + + if (in_array($set->getContainerObjId(), $available)) { + $refs = ilObject::_getAllReferences($set->getContainerObjId()); + foreach ($refs as $ref) { + if ($rbacsystem->checkAccess("write", $ref) && ilObject::_hasUntrashedReference($set->getContainerObjId())) { + return true; + } + } + } + } + + return false; + } + + /** + * @param boolean $skillServiceEnabled + */ + public function setSkillServiceEnabled($skillServiceEnabled) + { + $this->skillServiceEnabled = $skillServiceEnabled; + } + + /** + * @return bool + */ + public function isSkillServiceEnabled() + { + if (!self::isSkillManagementGloballyActivated()) { + return false; + } + + return $this->skillServiceEnabled; + } + + /** + * @return bool + */ + public static function isSkillManagementGloballyActivated() + { + if (self::$isSkillManagementGloballyActivated === null) { + $skmgSet = new ilSkillManagementSettings(); + + self::$isSkillManagementGloballyActivated = $skmgSet->isActivated(); + } + + return self::$isSkillManagementGloballyActivated; + } } diff --git a/classes/class.ilObjQuestionSetPoolAccess.php b/classes/class.ilObjQuestionSetPoolAccess.php index 52f6c8ed176206a3d646ff098d9870d16ba45ebf..f58347ef7355b61df13df9a1d92854dea2907399 100644 --- a/classes/class.ilObjQuestionSetPoolAccess.php +++ b/classes/class.ilObjQuestionSetPoolAccess.php @@ -1,7 +1,6 @@ - */ + */ class ilObjQuestionSetPoolAccess extends ilObjectPluginAccess { - /** - * @param string $a_cmd - * @param string $a_permission - * @param int $a_ref_id - * @param int $a_obj_id - * @param string $a_user_id - * @return bool - */ - public function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = '') - { - /** - * @var $ilUser ilObjUser - * @var $ilAccess ilAccessHandler - */ - global $ilUser, $ilAccess; + /** + * @param string $a_cmd + * @param string $a_permission + * @param int $a_ref_id + * @param int $a_obj_id + * @param string $a_user_id + * @return bool + */ + public function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = '') + { + /** + * @var $ilUser ilObjUser + * @var $ilAccess ilAccessHandler + */ + global $ilUser, $ilAccess; - if(!$a_user_id) - { - $a_user_id = $ilUser->getId(); - } + if (!$a_user_id) { + $a_user_id = $ilUser->getId(); + } - switch($a_permission) - { - case 'read': - if( - !ilObjQuestionSetPoolAccess::checkOnline($a_obj_id) && - !$ilAccess->checkAccessOfUser($a_user_id, 'write', '', $a_ref_id) - ) - { - return false; - } - return true; - } + switch ($a_permission) { + case 'read': + if ( + !ilObjQuestionSetPoolAccess::checkOnline($a_obj_id) && + !$ilAccess->checkAccessOfUser($a_user_id, 'write', '', $a_ref_id) + ) { + return false; + } + return true; + } - return true; - } + return true; + } - /** - * @param int $a_obj_id - */ - public static function checkOnline($a_obj_id) - { - return ilObjQuestionSetPool::getOnlineStatusByObjId($a_obj_id); - } + /** + * @param int $a_obj_id + */ + public static function checkOnline($a_obj_id) + { + return ilObjQuestionSetPool::getOnlineStatusByObjId($a_obj_id); + } - /** - * @param array $a_obj_ids - * @param array $a_ref_ids - */ - static function _preloadData($a_obj_ids, $a_ref_ids) - { - ilObjQuestionSetPool::preloadDataForLists($a_obj_ids, $a_ref_ids); - } + /** + * @param array $a_obj_ids + * @param array $a_ref_ids + */ + public static function _preloadData($a_obj_ids, $a_ref_ids) + { + ilObjQuestionSetPool::preloadDataForLists($a_obj_ids, $a_ref_ids); + } } diff --git a/classes/class.ilObjQuestionSetPoolGUI.php b/classes/class.ilObjQuestionSetPoolGUI.php index 76abbb24208c34617c3b601a854c547c3aebf12b..265281a000460d3edbf408a038c83921b86793bc 100755 --- a/classes/class.ilObjQuestionSetPoolGUI.php +++ b/classes/class.ilObjQuestionSetPoolGUI.php @@ -1,9 +1,6 @@ setDescription($this->object->getDescription()); - - $this->lng->loadLanguageModule('assessment'); - $tpl->addCss('./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/templates/default/xqsp.css'); - - $next_class = $this->ctrl->getNextClass($this); - switch($next_class) - { - case 'ilquestionsetpoolskilladministrationgui': - require_once 'controllers/class.ilQuestionSetPoolSkillAdministrationGUI.php'; - $this->prepareOutput(); - $this->addHeaderAction(); - - $gui = new ilQuestionSetPoolSkillAdministrationGUI($this); - $this->ctrl->forwardCommand($gui); - break; - - case 'ilmdeditorgui': - $this->checkPermission('write'); - require_once 'Services/MetaData/classes/class.ilMDEditorGUI.php'; - $md_gui = new ilMDEditorGUI($this->object->getId(), 0, $this->object->getType()); - $md_gui->addObserver($this->object, 'MDUpdateListener', 'General'); - $ilTabs->setTabActive('meta_data'); - return $this->ctrl->forwardCommand($md_gui); - break; - - case 'ilpublicuserprofilegui': - require_once 'Services/User/classes/class.ilPublicUserProfileGUI.php'; - $profile_gui = new ilPublicUserProfileGUI($_GET['user']); - $profile_gui->setBackUrl($this->ctrl->getLinkTarget($this, 'showContent')); - $this->tpl->setContent($this->ctrl->forwardCommand($profile_gui)); - break; - - case 'ilcommonactiondispatchergui': - require_once 'Services/Object/classes/class.ilCommonActionDispatcherGUI.php'; - $gui = ilCommonActionDispatcherGUI::getInstanceFromAjaxCall(); - $this->ctrl->forwardCommand($gui); - break; - case "ilquestionsetpoolexportgui": - $this->checkPermission('write'); - $ilTabs->setTabActive('export'); - $this->getPlugin()->includeClass('class.ilQuestionSetPoolExportGUI.php'); - $exp_gui = new ilQuestionSetPoolExportGUI($this); - $exp_gui->addFormat('xml', $this->lng->txt('qpl_export_xml')); - $this->ctrl->forwardCommand($exp_gui); - break; - default: - switch($cmd) - { - case 'redrawHeaderAction': - case 'addToDesk': - case 'removeFromDesk': - if(in_array($cmd, array('addToDesk', 'removeFromDesk'))) - { - $cmd .= 'Object'; - } - $this->checkPermission('read'); - $this->$cmd(); - break; - - default: - $this->ensureEntityExistance(); - $dispatcher = ilPluginDispatcher::getInstance($this); - $dispatcher->dispatch($cmd); - break; - } - break; - } - - $this->addHeaderAction(); - } - - protected function redirectToDefaultPage() - { - $this->ctrl->redirect($this); - } - - protected function ensureEntityExistance() - { - if(isset($_GET['set_id']) && (int)$_GET['set_id']) - { - $set_id = (int)$_GET['set_id']; - $this->getPlugin()->includeClass('models/class.ilQuestionSetPoolSet.php'); - if(!ilQuestionSetPoolSet::exists($set_id)) - { - ilUtil::sendFailure($this->txt('poss_sync_err_set'), true); - $this->redirectToDefaultPage(); - } - } - - if(isset($_GET['path_id']) && (int)$_GET['path_id']) - { - $path_id = (int)$_GET['path_id']; - $this->getPlugin()->includeClass('models/class.ilQuestionSetPoolPath.php'); - if(!ilQuestionSetPoolPath::exists($path_id)) - { - ilUtil::sendFailure($this->txt('poss_sync_err_path'), true); - $this->redirectToDefaultPage(); - } - } - - if(isset($_GET['node_id']) && (int)$_GET['node_id']) - { - $node_id = (int)$_GET['node_id']; - $this->getPlugin()->includeClass('models/class.ilQuestionSetPoolNode.php'); - if(!ilQuestionSetPoolNode::exists($node_id)) - { - ilUtil::sendFailure($this->txt('poss_sync_err_node'), true); - $this->redirectToDefaultPage(); - } - } - } - - /** - * Public wrapper for permission checks - * @param string $permission - * @return bool - */ - public function hasPermission($permission) - { - return $this->checkPermissionBool($permission); - } - - /** - * Public wrapper for permission assumption - * @param string $permission - * @return bool - */ - public function ensurePermission($permission) - { - return $this->checkPermission($permission); - } - - /** - * - */ - public function populateContentStyleBlock() - { - include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php"); - $this->tpl->setCurrentBlock( "ContentStyle" ); - $this->tpl->setVariable( "LOCATION_CONTENT_STYLESHEET",ilObjStyleSheet::getContentStylePath(0)); - $this->tpl->parseCurrentBlock(); - - $this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "test_print.css", "Modules/Test"), "print"); - $this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "ta.css", "Modules/Test"), "screen"); - } - - /** - * - */ - public function populateSyntaxStyleBlock() - { - $this->tpl->setCurrentBlock( "SyntaxStyle" ); - $this->tpl->setVariable( "LOCATION_SYNTAX_STYLESHEET",ilObjStyleSheet::getSyntaxStylePath()); - $this->tpl->parseCurrentBlock(); - } - - /** - * Functions that must be overwritten - */ - public function getType() - { - require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/classes/class.ilQuestionSetPoolPlugin.php"; - return ilQuestionSetPoolPlugin::getPluginId(); - } - - /** - * Cmd that will be redirected to after creation of a new object. - */ - public function getAfterCreationCmd() - { - return "ilQuestionSetPoolPropertiesGUI.edit"; - } - - public function getStandardCmd() - { - return "ilQuestionSetPoolSetsGUI.show"; - } - - /** - * @param string $type - * @return array - */ - protected function initCreationForms($type) - { - return array( - self::CFORM_NEW => $this->initCreateForm($type), - self::CFORM_IMPORT => $this->initImportForm($type) - ); - } - - /** - * @param string $type - * @return ilPropertyFormGUI - */ - public function initCreateForm($type) - { - $form = parent::initCreateForm($type); - // Add additional form elements for creation form here - return $form; - } - - /** - * @param $a_new_type - * @return ilPropertyFormGUI - */ - public function initImportForm($a_new_type) - { - $form = parent::initImportForm($a_new_type); - - // select question pool - include_once("./Modules/Test/classes/class.ilObjTest.php"); - $tst = new ilObjTest(); - $questionpools = $tst->getAvailableQuestionpools(TRUE, FALSE, TRUE, TRUE); - $this->getPlugin()->includeClass('class.ilQuestionSetPoolImporter.php'); - $options = array( - ilQuestionSetPoolImporter::SINGLE_IMPORT_NEW_POOL => $this->lng->txt("assessment_new_pool"), - ilQuestionSetPoolImporter::SINGLE_IMPORT_NO_POOL => $this->lng->txt('assessment_no_pool') - ); - - if (is_array($questionpools) && count($questionpools)) - { - foreach ($questionpools as $key => $value) - { - $options[$key] = $value["title"]; - } - } - $pool = new ilSelectInputGUI($this->lng->txt("select_questionpool"), "qpl"); - $pool->setOptions($options); - $form->addItem($pool); - - return $form; - } - - /** - * - */ - public function setTabs() - { - $this->tabs_gui->clearTargets(); - - if($this->checkPermissionBool('read')) - { - $this->tabs_gui->addTab('content', $this->txt('question_sets'), $this->ctrl->getLinkTarget($this, 'ilQuestionSetPoolSetsGUI.show')); - } - - $this->addInfoTab(); - - if($this->checkPermissionBool('read') && $this->object->isSkillServiceEnabled() && ilObjQuestionSetPool::isSkillManagementGloballyActivated()) - { - require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionSkillAssignmentsGUI.php'; - - $link = $this->ctrl->getLinkTargetByClass( - array('ilQuestionSetPoolSkillAdministrationGUI', 'ilAssQuestionSkillAssignmentsGUI'), - ilAssQuestionSkillAssignmentsGUI::CMD_SHOW_SKILL_QUEST_ASSIGNS - ); - - $this->tabs_gui->addTarget('tst_tab_competences', $link); - } - - if($this->checkPermissionBool('write')) - { - $this->tabs_gui->addTab('properties', $this->lng->txt('properties'), $this->ctrl->getLinkTarget($this, 'ilQuestionSetPoolPropertiesGUI.edit')); - $this->tabs_gui->addTarget('meta_data', $this->ctrl->getLinkTargetByClass('ilmdeditorgui', ''), '', 'ilmdeditorgui'); - $this->tabs_gui->addTarget("export", $this->ctrl->getLinkTargetByClass("ilquestionsetpoolexportgui", ""), "", "ilquestionsetpoolexportgui"); - } - - $this->addPermissionTab(); - } - - /** - * @param string $a_sub_type - * @param int $a_sub_id - * @return ilObjectListGUI|ilObjQuestionSetPoolListGUI - */ - protected function initHeaderAction($a_sub_type = null, $a_sub_id = null) - { - /** - * @var $ilUser ilObjUser - */ - global $ilUser; - - $lg = parent::initHeaderAction(); - if($lg instanceof ilObjQuestionSetPoolListGUI) - { - if($ilUser->getId() != ANONYMOUS_USER_ID) - { - // Maybe handle notifications in future ... - } - } - - return $lg; - } - - /** - * @see ilDesktopItemHandling::addToDesk() - */ - public function addToDeskObject() - { - /** - * @var $ilSetting ilSetting - * @var $lng ilLanguage - */ - global $ilSetting, $lng; - - if((int)$ilSetting->get('disable_my_offers')) - { - $this->ctrl->redirect($this); - return; - } - - include_once './Services/PersonalDesktop/classes/class.ilDesktopItemGUI.php'; - ilDesktopItemGUI::addToDesktop(); - ilUtil::sendSuccess($lng->txt('added_to_desktop'), true); - $this->ctrl->redirect($this); - } - - /** - * @see ilDesktopItemHandling::removeFromDesk() - */ - public function removeFromDeskObject() - { - global $ilSetting, $lng; - - if((int)$ilSetting->get('disable_my_offers')) - { - $this->ctrl->redirect($this); - return; - } - - include_once './Services/PersonalDesktop/classes/class.ilDesktopItemGUI.php'; - ilDesktopItemGUI::removeFromDesktop(); - ilUtil::sendSuccess($lng->txt('removed_from_desktop'), true); - $this->ctrl->redirect($this); - } + /** + * @var ilObjQuestionSetPool + */ + public $object; + + public $plugin; + + /** + * @param string $cmd + * @return mixed + */ + public function performCommand($cmd) + { + /** + * @var $ilTabs ilTabsGUI + * @var $tpl ilTemplate + */ + global $ilTabs, $tpl; + + $tpl->setDescription($this->object->getDescription()); + + $this->lng->loadLanguageModule('assessment'); + $tpl->addCss('./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/templates/default/xqsp.css'); + + $next_class = $this->ctrl->getNextClass($this); + switch ($next_class) { + case 'ilquestionsetpoolskilladministrationgui': + require_once 'controllers/class.ilQuestionSetPoolSkillAdministrationGUI.php'; + $this->prepareOutput(); + $this->addHeaderAction(); + + $gui = new ilQuestionSetPoolSkillAdministrationGUI($this); + $this->ctrl->forwardCommand($gui); + break; + + case 'ilmdeditorgui': + $this->checkPermission('write'); + $md_gui = new ilMDEditorGUI($this->object->getId(), 0, $this->object->getType()); + $md_gui->addObserver($this->object, 'MDUpdateListener', 'General'); + $ilTabs->setTabActive('meta_data'); + return $this->ctrl->forwardCommand($md_gui); + break; + + case 'ilpublicuserprofilegui': + $profile_gui = new ilPublicUserProfileGUI($_GET['user']); + $profile_gui->setBackUrl($this->ctrl->getLinkTarget($this, 'showContent')); + $this->tpl->setContent($this->ctrl->forwardCommand($profile_gui)); + break; + + case 'ilcommonactiondispatchergui': + $gui = ilCommonActionDispatcherGUI::getInstanceFromAjaxCall(); + $this->ctrl->forwardCommand($gui); + break; + case "ilquestionsetpoolexportgui": + $this->checkPermission('write'); + $ilTabs->setTabActive('export'); + $this->getPlugin()->includeClass('class.ilQuestionSetPoolExportGUI.php'); + $exp_gui = new ilQuestionSetPoolExportGUI($this); + $exp_gui->addFormat('xml', $this->lng->txt('qpl_export_xml')); + $this->ctrl->forwardCommand($exp_gui); + break; + default: + switch ($cmd) { + case 'redrawHeaderAction': + case 'addToDesk': + case 'removeFromDesk': + if (in_array($cmd, array('addToDesk', 'removeFromDesk'))) { + $cmd .= 'Object'; + } + $this->checkPermission('read'); + $this->$cmd(); + break; + + default: + $this->ensureEntityExistance(); + require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/classes/dispatcher/class.ilPluginDispatcher.php"; + $dispatcher = ilPluginDispatcher::getInstance($this); + $dispatcher->dispatch($cmd); + break; + } + break; + } + + $this->addHeaderAction(); + } + + protected function redirectToDefaultPage() + { + $this->ctrl->redirect($this); + } + + protected function ensureEntityExistance() + { + if (isset($_GET['set_id']) && (int) $_GET['set_id']) { + $set_id = (int) $_GET['set_id']; + $this->getPlugin()->includeClass('models/class.ilQuestionSetPoolSet.php'); + if (!ilQuestionSetPoolSet::exists($set_id)) { + ilUtil::sendFailure($this->txt('poss_sync_err_set'), true); + $this->redirectToDefaultPage(); + } + } + + if (isset($_GET['path_id']) && (int) $_GET['path_id']) { + $path_id = (int) $_GET['path_id']; + $this->getPlugin()->includeClass('models/class.ilQuestionSetPoolPath.php'); + if (!ilQuestionSetPoolPath::exists($path_id)) { + ilUtil::sendFailure($this->txt('poss_sync_err_path'), true); + $this->redirectToDefaultPage(); + } + } + + if (isset($_GET['node_id']) && (int) $_GET['node_id']) { + $node_id = (int) $_GET['node_id']; + $this->getPlugin()->includeClass('models/class.ilQuestionSetPoolNode.php'); + if (!ilQuestionSetPoolNode::exists($node_id)) { + ilUtil::sendFailure($this->txt('poss_sync_err_node'), true); + $this->redirectToDefaultPage(); + } + } + } + + /** + * Public wrapper for permission checks + * @param string $permission + * @return bool + */ + public function hasPermission($permission) + { + return $this->checkPermissionBool($permission); + } + + /** + * Public wrapper for permission assumption + * @param string $permission + * @return bool + */ + public function ensurePermission($permission) + { + return $this->checkPermission($permission); + } + + /** + * + */ + public function populateContentStyleBlock() + { + $this->tpl->setCurrentBlock("ContentStyle"); + $this->tpl->setVariable("LOCATION_CONTENT_STYLESHEET", ilObjStyleSheet::getContentStylePath(0)); + $this->tpl->parseCurrentBlock(); + + $this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "test_print.css", "Modules/Test"), "print"); + $this->tpl->addCss(ilUtil::getStyleSheetLocation("output", "ta.css", "Modules/Test"), "screen"); + } + + /** + * + */ + public function populateSyntaxStyleBlock() + { + $this->tpl->setCurrentBlock("SyntaxStyle"); + $this->tpl->setVariable("LOCATION_SYNTAX_STYLESHEET", ilObjStyleSheet::getSyntaxStylePath()); + $this->tpl->parseCurrentBlock(); + } + + /** + * Functions that must be overwritten + */ + public function getType() + { + require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/classes/class.ilQuestionSetPoolPlugin.php"; + return ilQuestionSetPoolPlugin::getPluginId(); + } + + /** + * Cmd that will be redirected to after creation of a new object. + */ + public function getAfterCreationCmd() + { + return "ilQuestionSetPoolPropertiesGUI.edit"; + } + + public function getStandardCmd() + { + return "ilQuestionSetPoolSetsGUI.show"; + } + + /** + * @param string $type + * @return array + */ + protected function initCreationForms($type) + { + return array( + self::CFORM_NEW => $this->initCreateForm($type), + self::CFORM_IMPORT => $this->initImportForm($type) + ); + } + + /** + * @param string $type + * @return ilPropertyFormGUI + */ + public function initCreateForm($type) + { + $form = parent::initCreateForm($type); + // Add additional form elements for creation form here + return $form; + } + + /** + * @param $a_new_type + * @return ilPropertyFormGUI + */ + public function initImportForm($a_new_type) + { + $form = parent::initImportForm($a_new_type); + + // select question pool + include_once("./Modules/Test/classes/class.ilObjTest.php"); + $tst = new ilObjTest(); + $questionpools = $tst->getAvailableQuestionpools(true, false, true, true); + $this->getPlugin()->includeClass('class.ilQuestionSetPoolImporter.php'); + $options = array( + ilQuestionSetPoolImporter::SINGLE_IMPORT_NEW_POOL => $this->lng->txt("assessment_new_pool"), + ilQuestionSetPoolImporter::SINGLE_IMPORT_NO_POOL => $this->lng->txt('assessment_no_pool') + ); + + if (is_array($questionpools) && count($questionpools)) { + foreach ($questionpools as $key => $value) { + $options[$key] = $value["title"]; + } + } + $pool = new ilSelectInputGUI($this->lng->txt("select_questionpool"), "qpl"); + $pool->setOptions($options); + $form->addItem($pool); + + return $form; + } + + /** + * + */ + public function setTabs() + { + $this->tabs_gui->clearTargets(); + + if ($this->checkPermissionBool('read')) { + $this->tabs_gui->addTab('content', $this->txt('question_sets'), $this->ctrl->getLinkTarget($this, 'ilQuestionSetPoolSetsGUI.show')); + } + + $this->addInfoTab(); + + if ($this->checkPermissionBool('read') && $this->object->isSkillServiceEnabled() && ilObjQuestionSetPool::isSkillManagementGloballyActivated()) { + $link = $this->ctrl->getLinkTargetByClass( + array('ilQuestionSetPoolSkillAdministrationGUI', 'ilAssQuestionSkillAssignmentsGUI'), + ilAssQuestionSkillAssignmentsGUI::CMD_SHOW_SKILL_QUEST_ASSIGNS + ); + + $this->tabs_gui->addTarget('tst_tab_competences', $link); + } + + if ($this->checkPermissionBool('write')) { + $this->tabs_gui->addTab('properties', $this->lng->txt('properties'), $this->ctrl->getLinkTarget($this, 'ilQuestionSetPoolPropertiesGUI.edit')); + $this->tabs_gui->addTarget('meta_data', $this->ctrl->getLinkTargetByClass('ilmdeditorgui', ''), '', 'ilmdeditorgui'); + $this->tabs_gui->addTarget("export", $this->ctrl->getLinkTargetByClass("ilquestionsetpoolexportgui", ""), "", "ilquestionsetpoolexportgui"); + } + + $this->addPermissionTab(); + } + + /** + * @param string $a_sub_type + * @param int $a_sub_id + * @return ilObjectListGUI|ilObjQuestionSetPoolListGUI + */ + protected function initHeaderAction($a_sub_type = null, $a_sub_id = null) + { + /** + * @var $ilUser ilObjUser + */ + global $ilUser; + + $lg = parent::initHeaderAction(); + if ($lg instanceof ilObjQuestionSetPoolListGUI) { + if ($ilUser->getId() != ANONYMOUS_USER_ID) { + // Maybe handle notifications in future ... + } + } + + return $lg; + } } diff --git a/classes/class.ilObjQuestionSetPoolListGUI.php b/classes/class.ilObjQuestionSetPoolListGUI.php index b99e5854548408cf215f2f6d8badd3e9ea2b4d98..4f9c4649623eac82df051772d36346811485b1e2 100644 --- a/classes/class.ilObjQuestionSetPoolListGUI.php +++ b/classes/class.ilObjQuestionSetPoolListGUI.php @@ -1,66 +1,62 @@ - */ + */ class ilObjQuestionSetPoolListGUI extends ilObjectPluginListGUI { - - public function getGuiClass() - { - return 'ilObj'. ilQuestionSetPoolPlugin::getName() . 'GUI'; - } - - public function initCommands() - { - $this->copy_enabled = true; - - return array( - array( - 'permission' => 'read', - 'cmd' => 'infoScreen', - 'default' => true - ), - array( - 'permission' => 'write', - 'cmd' => 'ilQuestionSetPoolPropertiesGUI.edit', - 'default' => false - ) - ); - } - - public function initType() - { - require_once 'class.ilQuestionSetPoolPlugin.php'; - $this->setType(ilQuestionSetPoolPlugin::getPluginId()); - } - - /** - * @return array - */ - public function getProperties() - { - /** - * @var $lng ilLanguage - */ - global $lng; - - $props = array(); - include_once "class.ilObjQuestionSetPoolAccess.php"; - - if (!ilObjQuestionSetPoolAccess::checkOnline($this->obj_id)) - { - $props[] = array("alert" => true, "property" => $lng->txt("status"), - "value" => $lng->txt("offline")); - } - - return $props; - } + public function getGuiClass() + { + return 'ilObj' . ilQuestionSetPoolPlugin::getName() . 'GUI'; + } + + public function initCommands() + { + $this->copy_enabled = true; + + return array( + array( + 'permission' => 'read', + 'cmd' => 'infoScreen', + 'default' => true + ), + array( + 'permission' => 'write', + 'cmd' => 'ilQuestionSetPoolPropertiesGUI.edit', + 'default' => false + ) + ); + } + + public function initType() + { + require_once 'class.ilQuestionSetPoolPlugin.php'; + $this->setType(ilQuestionSetPoolPlugin::getPluginId()); + } + + /** + * @return array + */ + public function getProperties() + { + /** + * @var $lng ilLanguage + */ + global $lng; + + $props = array(); + include_once "class.ilObjQuestionSetPoolAccess.php"; + + if (!ilObjQuestionSetPoolAccess::checkOnline($this->obj_id)) { + $props[] = array("alert" => true, "property" => $lng->txt("status"), + "value" => $lng->txt("offline")); + } + + return $props; + } } diff --git a/classes/class.ilObjQuestionSetPoolXMLParser.php b/classes/class.ilObjQuestionSetPoolXMLParser.php index 95de12a314a0b31e5b7b941c04f861357681940a..9a8473bcd36f6fe1d123ddba11c8cf00d520fc73 100644 --- a/classes/class.ilObjQuestionSetPoolXMLParser.php +++ b/classes/class.ilObjQuestionSetPoolXMLParser.php @@ -1,274 +1,263 @@ */ class ilObjQuestionSetPoolXMLParser extends ilSaxParser { - /** - * @var ilObjQuestionSetPool - */ - private $xqsp_obj; - - private $inSettingsTag; - - private $inMetaDataTag; - private $inMdGeneralTag; - - public $sets = array(); - - private $questions = array(); - private $paths = array(); - private $nodes = array(); - private $jump_conditions = array(); - protected $importDirectory = ''; - - /** - * @param ilObjQuestionSetPool $xqsp_obj - * @param $xmlFile - */ - public function __construct(ilObjQuestionSetPool $xqsp_obj, $xmlFile) - { - $this->xqsp_obj = $xqsp_obj; - - $this->inSettingsTag = false; - $this->inMetaDataTag = false; - $this->inMdGeneralTag = false; - - parent::__construct($xmlFile); - } - - /** - * Set import directory - * - * @param string import directory - */ - public function setImportDirectory($a_val) - { - $this->importDirectory = $a_val; - } - - /** - * Get import directory - * - * @return string import directory - */ - public function getImportDirectory() - { - return $this->importDirectory; - } - - /** - * @param $xmlParser - */ - public function setHandlers($xmlParser) - { - xml_set_object($xmlParser, $this); - xml_set_element_handler($xmlParser, 'handlerBeginTag', 'handlerEndTag'); - xml_set_character_data_handler($xmlParser, 'handlerCharacterData'); - } - - /** - * @param $xmlParser - * @param $tagName - * @param $tagAttributes - */ - public function handlerBeginTag($xmlParser, $tagName, $tagAttributes) - { - switch($tagName) - { - case 'MetaData': - $this->inMetaDataTag = true; - break; - - case 'General': - if($this->inMetaDataTag) - { - $this->inMdGeneralTag = true; - } - break; - - case 'Description': - if($this->inMetaDataTag && $this->inMdGeneralTag) - { - $this->cdata = ''; - } - break; - - case 'Settings': - $this->inSettingsTag = true; - break; - - case 'Online': - case 'SkillService': - if($this->inSettingsTag) - { - $this->cdata = ''; - } - break; - case 'SetId': - case 'SetTitle': - case 'SetDescription': - case 'OriginalId': - $this->cdata = ''; - break; - } - } - - /** - * @param $xmlParser - * @param $tagName - */ - public function handlerEndTag($xmlParser, $tagName) - { - switch($tagName) - { - case 'MetaData': - $this->inMetaDataTag = false; - break; - - case 'General': - if($this->inMetaDataTag) - { - $this->inMdGeneralTag = false; - } - break; - - case 'Title': - if($this->inMetaDataTag && $this->inMdGeneralTag) - { - $this->xqsp_obj->setTitle(trim($this->cdata)); - $this->cdata = ''; - } - break; - - case 'Description': - if($this->inMetaDataTag && $this->inMdGeneralTag) - { - $this->xqsp_obj->setDescription(trim($this->cdata)); - $this->cdata = ''; - } - break; - - case 'Settings': - $this->inSettingsTag = false; - break; - - case 'Online': - $this->xqsp_obj->setOnline((bool)trim($this->cdata)); - $this->cdata = ''; - break; - - case 'SkillService': - $this->xqsp_obj->setSkillServiceEnabled((bool)trim($this->cdata)); - $this->cdata = ''; - break; - // sets - case 'SetId': - case 'SetTitle': - case 'SetDescription': - case 'OriginalId': - $this->import_set[$tagName] = trim($this->cdata); - $this->cdata = ''; - break; - // question - case 'QuestionId': - case 'QuestionIndex': - case 'QuestionOriginalId': - $this->import_question[$tagName] = trim($this->cdata); - $this->cdata = ''; - break; - // paths - case 'PathId': - case 'PathTitle': - case 'PathQuestionSetId': - case 'PathIndex': - $this->import_path[$tagName] = trim($this->cdata); - $this->cdata = ''; - break; - //nodes - case 'NodeId': - case 'NodeQuestionId': - case 'NodePathId': - case 'NodeIndex': - case 'NodeInitialCondition': - case 'NodeDominantScoring': - case 'NodeTrueFeedback': - case 'NodeFalseFeedback': - $this->import_node[$tagName] = trim($this->cdata); - $this->cdata = ''; - break; - // jump conditions - case 'JumpConditionId': - case 'JumpConditionText': - case 'JumpConditionNodeId': - case 'JumpConditionQuestionId': - case 'JumpConditionRepetitions': - case 'JumpConditionSorting': - case 'JumpConditionTrueFeedback': - case 'JumpConditionTrueJumpFeedback': - case 'JumpConditionFalseFeedback': - $this->import_jump_condition[$tagName] = trim($this->cdata); - $this->cdata = ''; - break; - case 'Set': - //'addSet'; - $this->sets[] = array($this->import_set, 'questions' => $this->questions, 'paths' => $this->paths); - $this->questions = array(); - $this->paths = array(); - $this->import_set = array(); - break; - - case 'Question': - // addQuesion - $this->questions[] = $this->import_question; - $this->import_question = array(); - break; - - case 'Path': - // addPath - $this->paths[] = array($this->import_path, 'nodes' => $this->nodes); - $this->nodes = array(); - $this->import_path = array(); - break; - - case 'Node': - // addNode - $this->nodes[] = array($this->import_node, 'jump_conditions' => $this->jump_conditions); - $this->jump_conditions = array(); - $this->import_node = array(); - break; - - case 'JumpCondition': - // addJumpConditition - $this->jump_conditions[] = $this->import_jump_condition; - $this->import_jump_condition = array(); - break; - } - } - - public function handlerCharacterData($xmlParser, $charData) - { - if($charData != "\n") - { - // Replace multiple tabs with one space - $charData = preg_replace("/\t+/", " ", $charData); - - $this->cdata .= $charData; - } - } - - public function getQuestionSetPoolObject() - { - return $this->xqsp_obj; - } - - public function getSetsArray() - { - return $this->sets; - } -} \ No newline at end of file + /** + * @var ilObjQuestionSetPool + */ + private $xqsp_obj; + + private $inSettingsTag; + + private $inMetaDataTag; + private $inMdGeneralTag; + + public $sets = array(); + + private $questions = array(); + private $paths = array(); + private $nodes = array(); + private $jump_conditions = array(); + protected $importDirectory = ''; + + /** + * @param ilObjQuestionSetPool $xqsp_obj + * @param $xmlFile + */ + public function __construct(ilObjQuestionSetPool $xqsp_obj, $xmlFile) + { + $this->xqsp_obj = $xqsp_obj; + + $this->inSettingsTag = false; + $this->inMetaDataTag = false; + $this->inMdGeneralTag = false; + + parent::__construct($xmlFile); + } + + /** + * Set import directory + * + * @param string import directory + */ + public function setImportDirectory($a_val) + { + $this->importDirectory = $a_val; + } + + /** + * Get import directory + * + * @return string import directory + */ + public function getImportDirectory() + { + return $this->importDirectory; + } + + /** + * @param $xmlParser + */ + public function setHandlers($xmlParser) + { + xml_set_object($xmlParser, $this); + xml_set_element_handler($xmlParser, 'handlerBeginTag', 'handlerEndTag'); + xml_set_character_data_handler($xmlParser, 'handlerCharacterData'); + } + + /** + * @param $xmlParser + * @param $tagName + * @param $tagAttributes + */ + public function handlerBeginTag($xmlParser, $tagName, $tagAttributes) + { + switch ($tagName) { + case 'MetaData': + $this->inMetaDataTag = true; + break; + + case 'General': + if ($this->inMetaDataTag) { + $this->inMdGeneralTag = true; + } + break; + + case 'Description': + if ($this->inMetaDataTag && $this->inMdGeneralTag) { + $this->cdata = ''; + } + break; + + case 'Settings': + $this->inSettingsTag = true; + break; + + case 'Online': + case 'SkillService': + if ($this->inSettingsTag) { + $this->cdata = ''; + } + break; + case 'SetId': + case 'SetTitle': + case 'SetDescription': + case 'OriginalId': + $this->cdata = ''; + break; + } + } + + /** + * @param $xmlParser + * @param $tagName + */ + public function handlerEndTag($xmlParser, $tagName) + { + switch ($tagName) { + case 'MetaData': + $this->inMetaDataTag = false; + break; + + case 'General': + if ($this->inMetaDataTag) { + $this->inMdGeneralTag = false; + } + break; + + case 'Title': + if ($this->inMetaDataTag && $this->inMdGeneralTag) { + $this->xqsp_obj->setTitle(trim($this->cdata)); + $this->cdata = ''; + } + break; + + case 'Description': + if ($this->inMetaDataTag && $this->inMdGeneralTag) { + $this->xqsp_obj->setDescription(trim($this->cdata)); + $this->cdata = ''; + } + break; + + case 'Settings': + $this->inSettingsTag = false; + break; + + case 'Online': + $this->xqsp_obj->setOnline((bool) trim($this->cdata)); + $this->cdata = ''; + break; + + case 'SkillService': + $this->xqsp_obj->setSkillServiceEnabled((bool) trim($this->cdata)); + $this->cdata = ''; + break; + // sets + case 'SetId': + case 'SetTitle': + case 'SetDescription': + case 'OriginalId': + $this->import_set[$tagName] = trim($this->cdata); + $this->cdata = ''; + break; + // question + case 'QuestionId': + case 'QuestionIndex': + case 'QuestionOriginalId': + $this->import_question[$tagName] = trim($this->cdata); + $this->cdata = ''; + break; + // paths + case 'PathId': + case 'PathTitle': + case 'PathQuestionSetId': + case 'PathIndex': + $this->import_path[$tagName] = trim($this->cdata); + $this->cdata = ''; + break; + //nodes + case 'NodeId': + case 'NodeQuestionId': + case 'NodePathId': + case 'NodeIndex': + case 'NodeInitialCondition': + case 'NodeDominantScoring': + case 'NodeTrueFeedback': + case 'NodeFalseFeedback': + $this->import_node[$tagName] = trim($this->cdata); + $this->cdata = ''; + break; + // jump conditions + case 'JumpConditionId': + case 'JumpConditionText': + case 'JumpConditionNodeId': + case 'JumpConditionQuestionId': + case 'JumpConditionRepetitions': + case 'JumpConditionSorting': + case 'JumpConditionTrueFeedback': + case 'JumpConditionTrueJumpFeedback': + case 'JumpConditionFalseFeedback': + $this->import_jump_condition[$tagName] = trim($this->cdata); + $this->cdata = ''; + break; + case 'Set': + //'addSet'; + $this->sets[] = array($this->import_set, 'questions' => $this->questions, 'paths' => $this->paths); + $this->questions = array(); + $this->paths = array(); + $this->import_set = array(); + break; + + case 'Question': + // addQuesion + $this->questions[] = $this->import_question; + $this->import_question = array(); + break; + + case 'Path': + // addPath + $this->paths[] = array($this->import_path, 'nodes' => $this->nodes); + $this->nodes = array(); + $this->import_path = array(); + break; + + case 'Node': + // addNode + $this->nodes[] = array($this->import_node, 'jump_conditions' => $this->jump_conditions); + $this->jump_conditions = array(); + $this->import_node = array(); + break; + + case 'JumpCondition': + // addJumpConditition + $this->jump_conditions[] = $this->import_jump_condition; + $this->import_jump_condition = array(); + break; + } + } + + public function handlerCharacterData($xmlParser, $charData) + { + if ($charData != "\n") { + // Replace multiple tabs with one space + $charData = preg_replace("/\t+/", " ", $charData); + + $this->cdata .= $charData; + } + } + + public function getQuestionSetPoolObject() + { + return $this->xqsp_obj; + } + + public function getSetsArray() + { + return $this->sets; + } +} diff --git a/classes/class.ilQuestionSetPoolExportGUI.php b/classes/class.ilQuestionSetPoolExportGUI.php index 934609274f833b67ad2752dfaa77a13dfbc4c746..7c0230d1ff0b50d03a17a550e2d5f1d713fe51e4 100755 --- a/classes/class.ilQuestionSetPoolExportGUI.php +++ b/classes/class.ilQuestionSetPoolExportGUI.php @@ -1,33 +1,30 @@ */ class ilQuestionSetPoolExportGUI extends ilExportGUI { - /** - * {@inheritdoc} - */ - protected function buildExportTableGUI() - { - require_once 'tables/class.ilQuestionSetPoolExportTableGUI.php'; - $table = new ilQuestionSetPoolExportTableGUI($this, 'listExportFiles', $this->obj); - return $table; - } - - /** - * Download file - */ - public function download() - { - if(isset($_GET['file']) && $_GET['file']) - { - $_POST['file'] = array($_GET['file']); - } - parent::download(); - } -} \ No newline at end of file + /** + * {@inheritdoc} + */ + protected function buildExportTableGUI() + { + require_once 'tables/class.ilQuestionSetPoolExportTableGUI.php'; + $table = new ilQuestionSetPoolExportTableGUI($this, 'listExportFiles', $this->obj); + return $table; + } + + /** + * Download file + */ + public function download() + { + if (isset($_GET['file']) && $_GET['file']) { + $_POST['file'] = array($_GET['file']); + } + parent::download(); + } +} diff --git a/classes/class.ilQuestionSetPoolExporter.php b/classes/class.ilQuestionSetPoolExporter.php index 96b8313249742891b1b2899e9ed2fd2eafe7a6d5..979931ccc780fc4753776957b771f0ecdf7fd1fe 100755 --- a/classes/class.ilQuestionSetPoolExporter.php +++ b/classes/class.ilQuestionSetPoolExporter.php @@ -1,524 +1,491 @@ */ class ilQuestionSetPoolExporter extends ilXmlExporter { - /** - * @var ilXmlWriter - */ - protected $xml_writer = NULL; - - /** - * @var string - */ - protected $export_dir = ''; - - /** - * @var string - */ - protected $subdir = ''; - - /** - * @var string - */ - protected $filename = ''; - - /** - * @var string - */ - protected $qti_filename = ''; - - /** - * @var string - */ - protected $zipfilename = ''; - - /** - * @var array with question ids to export - */ - protected $questions = array(); - - /** - * @var ilLog - */ - protected $expLog = NULL; - - /** - * Initialisation - */ - function init() - { - } - - /** - * ilQuestionSetPoolExporter constructor. - */ - public function __construct() - { - $this->plugin_object = ilPlugin::getPluginObject('Services', 'Repository', 'robj', 'QuestionSetPool'); - } - - /** - * - */ - public function initLogFile() - { - include_once "./Services/Logging/classes/class.ilLog.php"; - $this->expLog = new ilLog($this->getExportDirectory(), "export.log"); - $this->expLog->delete(); - $this->expLog->setLogFormat(""); - $this->expLog->write(date("[y-m-d H:i:s] ") . "Start Export"); - } - - /** - * creates data directory for export files - * (data_dir/qpl_data/qpl_/export, depending on data - * directory that is set in ILIAS setup/ini) - */ - function createExportDirectory() - { - global $ilErr; - - include_once "./Services/Utilities/classes/class.ilUtil.php"; - $xqsp_data_dir = ilUtil::getDataDir() . "/xqsp_data"; - ilUtil::makeDir($xqsp_data_dir); - if(!is_writable($xqsp_data_dir)) - { - $ilErr->raiseError("Questionpool Data Directory (" . $xqsp_data_dir . ") not writeable.", $ilErr->FATAL); - } - - // create learning module directory (data_dir/lm_data/lm_) - $xqsp_dir = $xqsp_data_dir . "/xqsp_" . $this->object->getId(); - ilUtil::makeDir($xqsp_dir); - if(!@is_dir($xqsp_dir)) - { - $ilErr->raiseError("Creation of QuestionSetPool Directory failed. xqsp_", $ilErr->FATAL); - } - // // create Export subdirectory (data_dir/lm_data/lm_/Export) - // ilUtil::makeDir($this->getExportDirectory('xls')); - // if(!@is_dir($this->getExportDirectory('xls'))) - // { - // $ilErr->raiseError("Creation of Export Directory failed. xls", $ilErr->FATAL); - // } - ilUtil::makeDir($this->getExportDirectory('zip')); - if(!@is_dir($this->getExportDirectory('zip'))) - { - $ilErr->raiseError("Creation of Export Directory failed. zip", $ilErr->FATAL); - } - - } - - /** - * get export directory of questionsetpool - * @param string $type - * @return string - */ - function getExportDirectory($type = "") - { - include_once "./Services/Utilities/classes/class.ilUtil.php"; - switch($type) - { - case 'xml': - include_once("./Services/Export/classes/class.ilExport.php"); - $export_dir = ilExport::_getExportDirectory($this->object->getId(), $type, $this->object->getType()); - break; + /** + * @var ilXmlWriter + */ + protected $xml_writer = null; + + /** + * @var string + */ + protected $export_dir = ''; + + /** + * @var string + */ + protected $subdir = ''; + + /** + * @var string + */ + protected $filename = ''; + + /** + * @var string + */ + protected $qti_filename = ''; + + /** + * @var string + */ + protected $zipfilename = ''; + + /** + * @var array with question ids to export + */ + protected $questions = array(); + + /** + * @var ilLog + */ + protected $expLog = null; + + /** + * Initialisation + */ + public function init() + { + } + + /** + * ilQuestionSetPoolExporter constructor. + */ + public function __construct() + { + $this->plugin_object = ilPlugin::getPluginObject('Services', 'Repository', 'robj', 'QuestionSetPool'); + } + + /** + * + */ + public function initLogFile() + { + $this->expLog = new ilLog($this->getExportDirectory(), "export.log"); + $this->expLog->delete(); + $this->expLog->setLogFormat(""); + $this->expLog->write(date("[y-m-d H:i:s] ") . "Start Export"); + } + + /** + * creates data directory for export files + * (data_dir/qpl_data/qpl_/export, depending on data + * directory that is set in ILIAS setup/ini) + */ + public function createExportDirectory() + { + global $ilErr; + + $xqsp_data_dir = ilUtil::getDataDir() . "/xqsp_data"; + ilUtil::makeDir($xqsp_data_dir); + if (!is_writable($xqsp_data_dir)) { + $ilErr->raiseError("Questionpool Data Directory (" . $xqsp_data_dir . ") not writeable.", $ilErr->FATAL); + } + + // create learning module directory (data_dir/lm_data/lm_) + $xqsp_dir = $xqsp_data_dir . "/xqsp_" . $this->object->getId(); + ilUtil::makeDir($xqsp_dir); + if (!@is_dir($xqsp_dir)) { + $ilErr->raiseError("Creation of QuestionSetPool Directory failed. xqsp_", $ilErr->FATAL); + } + // // create Export subdirectory (data_dir/lm_data/lm_/Export) + // ilUtil::makeDir($this->getExportDirectory('xls')); + // if(!@is_dir($this->getExportDirectory('xls'))) + // { + // $ilErr->raiseError("Creation of Export Directory failed. xls", $ilErr->FATAL); + // } + ilUtil::makeDir($this->getExportDirectory('zip')); + if (!@is_dir($this->getExportDirectory('zip'))) { + $ilErr->raiseError("Creation of Export Directory failed. zip", $ilErr->FATAL); + } + } + + /** + * get export directory of questionsetpool + * @param string $type + * @return string + */ + public function getExportDirectory($type = "") + { + switch ($type) { + case 'xml': + $export_dir = ilExport::_getExportDirectory($this->object->getId(), $type, $this->object->getType()); + break; // case 'xls': - case 'zip': - $export_dir = ilUtil::getDataDir()."/xqsp_data"."/xqsp_".$this->object->getId()."/export_$type"; - break; - - default: - $export_dir = ilUtil::getDataDir()."/xqsp_data"."/xqsp_".$this->object->getId()."/export"; - break; - } - return $export_dir; - } + case 'zip': + $export_dir = ilUtil::getDataDir() . "/xqsp_data" . "/xqsp_" . $this->object->getId() . "/export_$type"; + break; + + default: + $export_dir = ilUtil::getDataDir() . "/xqsp_data" . "/xqsp_" . $this->object->getId() . "/export"; + break; + } + return $export_dir; + } - /** - * - */ - public function exportPagesXML() - { - global $ilBench; - - $this->mob_ids = array(); - $this->file_ids = array(); - - $attrs = array(); - $attrs["Type"] = "QuestionSetPool_FormATest"; - $this->xml_writer->xmlStartTag("ContentObject", $attrs); - - // MetaData - $this->exportXMLMetaData(); - - // Settings - $this->exportXMLSettings(); - - // Question Sets - $this->exportQuestionSets(); - - // PageObjects - $this->expLog->write(date("[y-m-d H:i:s] ") . "Start Export Page Objects"); - $ilBench->start("ContentObjectExport", "exportPageObjects"); - $this->qpl_obj->exportXMLPageObjects($this->xml_writer, IL_INST_ID, $this->expLog, $this->questions); - $ilBench->stop("ContentObjectExport", "exportPageObjects"); - $this->expLog->write(date("[y-m-d H:i:s] ") . "Finished Export Page Objects"); - - // add media objects which were added with tiny mce - $this->expLog->write(date("[y-m-d H:i:s] ") . "Start Export Media Objects"); - $export_dir = $this->exp->export_run_dir; - $ilBench->start("ContentObjectExport", "exportMediaObjects"); - - $this->exportXHTMLMediaObjects($export_dir); - $ilBench->stop("ContentObjectExport", "exportMediaObjects"); - $this->expLog->write(date("[y-m-d H:i:s] ") . "Finished Export Media Objects"); - - if(is_array($this->qpl_obj->file_ids) && count($this->qpl_obj->file_ids) > 0) - { - // FileItems - $this->expLog->write(date("[y-m-d H:i:s] ") . "Start Export File Items"); - $ilBench->start("ContentObjectExport", "exportFileItems"); - $this->exportFileItems($this->export_dir . "/" . $this->subdir, $this->expLog); - $ilBench->stop("ContentObjectExport", "exportFileItems"); - $this->expLog->write(date("[y-m-d H:i:s] ") . "Finished Export File Items"); - } - $this->xml_writer->xmlEndTag("ContentObject"); - } - - /** - * export content objects meta data to xml (see ilias_co.dtd) - */ - function exportXMLMetaData() - { - include_once("Services/MetaData/classes/class.ilMD2XML.php"); - $md2xml = new ilMD2XML($this->object->getId(), 0, $this->object->getType()); - $md2xml->setExportMode(true); - $md2xml->startExport(); - $this->xml_writer->appendXML($md2xml->getXML()); - } - - /** - * - */ - private function exportXMLSettings() - { - $this->xml_writer->xmlStartTag('Settings'); - - $this->xml_writer->xmlElement('Title', null, (string)$this->object->getTitle()); - $this->xml_writer->xmlElement('Description', null, (string)$this->object->getDescription()); - $this->xml_writer->xmlElement('Online', null, (int)$this->object->isOnline()); - $this->xml_writer->xmlElement('SkillService', null, (int)$this->object->isSkillServiceEnabled()); - - $this->xml_writer->xmlEndTag('Settings'); - } - - /** - * - */ - protected function exportQuestionSets() - { - $this->plugin_object = ilQuestionSetPoolPlugin::getInstance(); - $this->plugin_object->includeClass('models/class.ilQuestionSetPoolSet.php'); - $this->plugin_object->includeClass('models/class.ilQuestionSetPoolPath.php'); - $this->plugin_object->includeClass('models/class.ilQuestionSetPoolNode.php'); - $this->plugin_object->includeClass('models/class.ilQuestionSetPoolJumpCondition.php'); - - $setlist = $this->object->getSetList(); - $sets = array(); - $sets = $setlist->loadData(); - - $this->xml_writer->xmlStartTag('QuestionSets'); - foreach($sets as $set_index => $set_data) - { - $set = new ilQuestionSetPoolSet((int)$set_data['id']); - $set->read(); - - $this->xml_writer->xmlStartTag('Set'); - $this->xml_writer->xmlElement('SetId', null, (int)$set->getId()); - $this->xml_writer->xmlElement('SetTitle', null, (string)$set->getTitle()); - $this->xml_writer->xmlElement('SetDescription', null, (string)$set->getDescription()); - - $this->xml_writer->xmlElement('OriginalId', null, (int)$set->getOriginalId()); - - // Export QuestionList - $this->exportQuestionList($set->getQuestionList()); - - // Export Paths - $this->exportPathList($set->getPathList()); - - $this->xml_writer->xmlEndTag('Set'); - } - - $this->xml_writer->xmlEndTag('QuestionSets'); - } - - /** - * @param ilQuestionSetPoolSetQuestionList $questionList - */ - protected function exportQuestionList(ilQuestionSetPoolSetQuestionList $questionList) - { - $questions = array(); - $questions = $questionList->loadData(); - $this->xml_writer->xmlStartTag('Questions'); - foreach($questions as $question_index => $question) - { - $this->xml_writer->xmlStartTag('Question'); - $this->xml_writer->xmlElement('QuestionId', null, $question['question_id']); - $this->xml_writer->xmlElement('QuestionIndex', null, $question['question_index']); - $this->xml_writer->xmlElement('QuestionOriginalId', null, $question['original_id']); - $this->xml_writer->xmlEndTag('Question'); - $this->questions[$question['question_id']] = $question['question_id']; - } - $this->xml_writer->xmlEndTag('Questions'); - if(is_array($this->questions) && count($this->questions) > 0) - { - $this->exportQuestions(); - } - } - - /** - * @param ilQuestionSetPoolPathList $pathlist - */ - protected function exportPathList(ilQuestionSetPoolPathList $pathList) - { - $paths = array(); - $paths = $pathList->loadData(); - - $this->xml_writer->xmlStartTag('Paths'); - foreach($paths as $path_index => $path_data) - { - $path = new ilQuestionSetPoolPath(); - $path->setId($path_data['id']); - $path->read(); - $this->xml_writer->xmlStartTag('Path'); - $this->xml_writer->xmlElement('PathId', null, (int)$path->getId()); - $this->xml_writer->xmlElement('PathTitle', null, (string)$path->getTitle()); - $this->xml_writer->xmlElement('PathQuestionSetId', null, (int)$path_data['questionset_fi']); - $this->xml_writer->xmlElement('PathIndex', null, $path->getIndex()); - - // Nodes - $this->exportNodeList($path->getNodes()); - - $this->xml_writer->xmlEndTag('Path'); - } - $this->xml_writer->xmlEndTag('Paths'); - } - - /** - * @param ilQuestionSetPoolNodeList $nodelist - */ - protected function exportNodeList(ilQuestionSetPoolNodeList $nodeList) - { - $nodes = array(); - $nodes = $nodeList->loadData(); - - $this->xml_writer->xmlStartTag('Nodes'); - foreach($nodes as $node_index => $node_data) - { - $node = new ilQuestionSetPoolNode((int)$node_data['id']); - $node->read(); - $this->xml_writer->xmlStartTag('Node'); - - $this->xml_writer->xmlElement('NodeId', null, (int)$node->getId()); - $this->xml_writer->xmlElement('NodeQuestionId', null, (int)$node_data['question_fi']); - $this->xml_writer->xmlElement('NodePathId', null, (int)$node_data['path_fi']); - $this->xml_writer->xmlElement('NodeIndex', null, (int)$node->getIndex()); - - $this->xml_writer->xmlElement('NodeInitialCondition', null, $node->getInitialCondition()); - $this->xml_writer->xmlElement('NodeDominantScoring', null, $node->getDominantScoring()); - - $this->xml_writer->xmlElement('NodeTrueFeedback', null, $node->getTrueFeedback()); - $this->xml_writer->xmlElement('NodeFalseFeedback', null, $node->getFalseFeedback()); - - // Jump Conditions - $this->exportJumpConditions($node->getJumpConditionList()); - - $this->xml_writer->xmlEndTag('Node'); - } - $this->xml_writer->xmlEndTag('Nodes'); - } - - /** - * @param ilQuestionSetPoolJumpConditionList $jumpConditionList - */ - protected function exportJumpConditions(ilQuestionSetPoolJumpConditionList $jumpConditionList) - { - $jumpConditions = array(); - $jumpConditions = $jumpConditionList->getData(); - - $this->xml_writer->xmlStartTag('JumpConditions'); - - foreach($jumpConditions as $jmp_con_index => $jumpCondition_data) - { - $jumpCondition = new ilQuestionSetPoolJumpCondition(); - $jumpCondition->setId($jumpCondition_data['id']); - $jumpCondition->read(); - - $this->xml_writer->xmlStartTag('JumpCondition'); - $this->xml_writer->xmlElement('JumpConditionId', null, (int)$jumpCondition->getId()); - $this->xml_writer->xmlElement('JumpConditionText', null, (string)$jumpCondition->getJumpCondition()); - - $this->xml_writer->xmlElement('JumpConditionNodeId', null, (int)$jumpCondition_data['node_fi']); - $this->xml_writer->xmlElement('JumpConditionQuestionId', null, $jumpCondition_data['question_fi']); - - $this->xml_writer->xmlElement('JumpConditionRepetitions', null, $jumpCondition->getRepititions()); - $this->xml_writer->xmlElement('JumpConditionSorting', null, $jumpCondition->getSorting()); - $this->xml_writer->xmlElement('JumpConditionTrueFeedback', null, $jumpCondition->getTrueFeedback()); - $this->xml_writer->xmlElement('JumpConditionTrueJumpFeedback', null, $jumpCondition->getTrueJumpFeedback()); - $this->xml_writer->xmlElement('JumpConditionFalseFeedback', null, $jumpCondition->getFalseFeedback()); - - $this->xml_writer->xmlEndTag('JumpCondition'); - } - - $this->xml_writer->xmlEndTag('JumpConditions'); - } - - /** - * Default ilias questionpool export - */ - protected function exportQuestions() - { - // write qti file - ilUtil::makeDirParents($this->export_dir); - $qti_file = fopen($this->export_dir . "/" . $this->qti_filename, "w"); - fwrite($qti_file, $this->qpl_obj->questionsToXML($this->questions)); - fclose($qti_file); - } - - /** - * @param $a_export_dir - */ - function exportXHTMLMediaObjects($a_export_dir) - { - include_once("./Services/MediaObjects/classes/class.ilObjMediaObject.php"); - ilUtil::makeDirParents($a_export_dir."/objects/"); - - foreach($this->questions as $question_id) - { - $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $question_id); - foreach($mobs as $mob) - { - if(ilObjMediaObject::_exists($mob)) - { - $mob_obj = new ilObjMediaObject($mob); - $mob_obj->exportFiles($a_export_dir); - unset($mob_obj); - } - } - } - } - - /** - * Main export method for single object export AND export within an container (crs, cat, ...) - * @param $a_entity - * @param $a_schema_version - * @param $a_id - * @return string - */ - public function getXmlRepresentation($a_entity, $a_schema_version, $a_id) - { - $ref_id = current(ilObject::_getAllReferences($a_id)); - - $date = time(); - $this->export_dir = $this->getAbsoluteExportDirectory(); - $this->subdir = $date . "__" . IL_INST_ID . "__" . "xqsp" . "_" . $a_id; - $this->filename = $this->subdir . ".xml"; - $this->qti_filename ="xqsp_qti.xml"; - - $this->plugin_object->includeClass('class.ilObjQuestionSetPool.php'); - - $this->object = new ilObjQuestionSetPool($ref_id); - $this->xml_writer = new ilXmlWriter(); - - $this->qpl_obj = new ilObjQuestionPool(); - // get Log File - ilUtil::makeDirParents($this->getExportDirectory()); - $this->initLogFile(); - $this->exportPagesXML(); - - return $this->xml_writer->xmlDumpMem(); - } - - /** - * @param $a_entity - * @return array - */ - public function getValidSchemaVersions($a_entity) - { - return array( - '5.1.0' => array( - 'namespace' => 'http://www.ilias.de/', - 'xsd_file' => 'xqsp_5_1.xsd', - 'uses_dataset' => false, - 'min' => '5.1.0', - 'max' => '5.1.999' - ) - ); - } - - /** - * @param $a_entity - * @param $a_target_release - * @param array $a_ids - * @return array - */ - public function getXmlExportHeadDependencies($a_entity, $a_target_release, $a_ids) - { - if("xqsp" == $a_entity) - { - // Array von QSP obj_ids - $qpl_obj_ids = array(); - - global $ilDB, $ilObjDataCache; - //qs.id, qs.questionsetpool_fi, qst.question_fi, qpl_qst.obj_fi, - $res = $ilDB->query(' + /** + * + */ + public function exportPagesXML() + { + global $ilBench; + + $this->mob_ids = array(); + $this->file_ids = array(); + + $attrs = array(); + $attrs["Type"] = "QuestionSetPool_FormATest"; + $this->xml_writer->xmlStartTag("ContentObject", $attrs); + + // MetaData + $this->exportXMLMetaData(); + + // Settings + $this->exportXMLSettings(); + + // Question Sets + $this->exportQuestionSets(); + + // PageObjects + $this->expLog->write(date("[y-m-d H:i:s] ") . "Start Export Page Objects"); + $ilBench->start("ContentObjectExport", "exportPageObjects"); + $this->qpl_obj->exportXMLPageObjects($this->xml_writer, IL_INST_ID, $this->expLog, $this->questions); + $ilBench->stop("ContentObjectExport", "exportPageObjects"); + $this->expLog->write(date("[y-m-d H:i:s] ") . "Finished Export Page Objects"); + + // add media objects which were added with tiny mce + $this->expLog->write(date("[y-m-d H:i:s] ") . "Start Export Media Objects"); + $export_dir = $this->exp->export_run_dir; + $ilBench->start("ContentObjectExport", "exportMediaObjects"); + + $this->exportXHTMLMediaObjects($export_dir); + $ilBench->stop("ContentObjectExport", "exportMediaObjects"); + $this->expLog->write(date("[y-m-d H:i:s] ") . "Finished Export Media Objects"); + + if (is_array($this->qpl_obj->file_ids) && count($this->qpl_obj->file_ids) > 0) { + // FileItems + $this->expLog->write(date("[y-m-d H:i:s] ") . "Start Export File Items"); + $ilBench->start("ContentObjectExport", "exportFileItems"); + $this->exportFileItems($this->export_dir . "/" . $this->subdir, $this->expLog); + $ilBench->stop("ContentObjectExport", "exportFileItems"); + $this->expLog->write(date("[y-m-d H:i:s] ") . "Finished Export File Items"); + } + $this->xml_writer->xmlEndTag("ContentObject"); + } + + /** + * export content objects meta data to xml (see ilias_co.dtd) + */ + public function exportXMLMetaData() + { + $md2xml = new ilMD2XML($this->object->getId(), 0, $this->object->getType()); + $md2xml->setExportMode(true); + $md2xml->startExport(); + $this->xml_writer->appendXML($md2xml->getXML()); + } + + /** + * + */ + private function exportXMLSettings() + { + $this->xml_writer->xmlStartTag('Settings'); + + $this->xml_writer->xmlElement('Title', null, (string) $this->object->getTitle()); + $this->xml_writer->xmlElement('Description', null, (string) $this->object->getDescription()); + $this->xml_writer->xmlElement('Online', null, (int) $this->object->isOnline()); + $this->xml_writer->xmlElement('SkillService', null, (int) $this->object->isSkillServiceEnabled()); + + $this->xml_writer->xmlEndTag('Settings'); + } + + /** + * + */ + protected function exportQuestionSets() + { + $this->plugin_object = ilQuestionSetPoolPlugin::getInstance(); + $this->plugin_object->includeClass('models/class.ilQuestionSetPoolSet.php'); + $this->plugin_object->includeClass('models/class.ilQuestionSetPoolPath.php'); + $this->plugin_object->includeClass('models/class.ilQuestionSetPoolNode.php'); + $this->plugin_object->includeClass('models/class.ilQuestionSetPoolJumpCondition.php'); + + $setlist = $this->object->getSetList(); + $sets = array(); + $sets = $setlist->loadData(); + + $this->xml_writer->xmlStartTag('QuestionSets'); + foreach ($sets as $set_index => $set_data) { + $set = new ilQuestionSetPoolSet((int) $set_data['id']); + $set->read(); + + $this->xml_writer->xmlStartTag('Set'); + $this->xml_writer->xmlElement('SetId', null, (int) $set->getId()); + $this->xml_writer->xmlElement('SetTitle', null, (string) $set->getTitle()); + $this->xml_writer->xmlElement('SetDescription', null, (string) $set->getDescription()); + + $this->xml_writer->xmlElement('OriginalId', null, (int) $set->getOriginalId()); + + // Export QuestionList + $this->exportQuestionList($set->getQuestionList()); + + // Export Paths + $this->exportPathList($set->getPathList()); + + $this->xml_writer->xmlEndTag('Set'); + } + + $this->xml_writer->xmlEndTag('QuestionSets'); + } + + /** + * @param ilQuestionSetPoolSetQuestionList $questionList + */ + protected function exportQuestionList(ilQuestionSetPoolSetQuestionList $questionList) + { + $questions = array(); + $questions = $questionList->loadData(); + $this->xml_writer->xmlStartTag('Questions'); + foreach ($questions as $question_index => $question) { + $this->xml_writer->xmlStartTag('Question'); + $this->xml_writer->xmlElement('QuestionId', null, $question['question_id']); + $this->xml_writer->xmlElement('QuestionIndex', null, $question['question_index']); + $this->xml_writer->xmlElement('QuestionOriginalId', null, $question['original_id']); + $this->xml_writer->xmlEndTag('Question'); + $this->questions[$question['question_id']] = $question['question_id']; + } + $this->xml_writer->xmlEndTag('Questions'); + if (is_array($this->questions) && count($this->questions) > 0) { + $this->exportQuestions(); + } + } + + /** + * @param ilQuestionSetPoolPathList $pathlist + */ + protected function exportPathList(ilQuestionSetPoolPathList $pathList) + { + $paths = array(); + $paths = $pathList->loadData(); + + $this->xml_writer->xmlStartTag('Paths'); + foreach ($paths as $path_index => $path_data) { + $path = new ilQuestionSetPoolPath(); + $path->setId($path_data['id']); + $path->read(); + $this->xml_writer->xmlStartTag('Path'); + $this->xml_writer->xmlElement('PathId', null, (int) $path->getId()); + $this->xml_writer->xmlElement('PathTitle', null, (string) $path->getTitle()); + $this->xml_writer->xmlElement('PathQuestionSetId', null, (int) $path_data['questionset_fi']); + $this->xml_writer->xmlElement('PathIndex', null, $path->getIndex()); + + // Nodes + $this->exportNodeList($path->getNodes()); + + $this->xml_writer->xmlEndTag('Path'); + } + $this->xml_writer->xmlEndTag('Paths'); + } + + /** + * @param ilQuestionSetPoolNodeList $nodelist + */ + protected function exportNodeList(ilQuestionSetPoolNodeList $nodeList) + { + $nodes = array(); + $nodes = $nodeList->loadData(); + + $this->xml_writer->xmlStartTag('Nodes'); + foreach ($nodes as $node_index => $node_data) { + $node = new ilQuestionSetPoolNode((int) $node_data['id']); + $node->read(); + $this->xml_writer->xmlStartTag('Node'); + + $this->xml_writer->xmlElement('NodeId', null, (int) $node->getId()); + $this->xml_writer->xmlElement('NodeQuestionId', null, (int) $node_data['question_fi']); + $this->xml_writer->xmlElement('NodePathId', null, (int) $node_data['path_fi']); + $this->xml_writer->xmlElement('NodeIndex', null, (int) $node->getIndex()); + + $this->xml_writer->xmlElement('NodeInitialCondition', null, $node->getInitialCondition()); + $this->xml_writer->xmlElement('NodeDominantScoring', null, $node->getDominantScoring()); + + $this->xml_writer->xmlElement('NodeTrueFeedback', null, $node->getTrueFeedback()); + $this->xml_writer->xmlElement('NodeFalseFeedback', null, $node->getFalseFeedback()); + + // Jump Conditions + $this->exportJumpConditions($node->getJumpConditionList()); + + $this->xml_writer->xmlEndTag('Node'); + } + $this->xml_writer->xmlEndTag('Nodes'); + } + + /** + * @param ilQuestionSetPoolJumpConditionList $jumpConditionList + */ + protected function exportJumpConditions(ilQuestionSetPoolJumpConditionList $jumpConditionList) + { + $jumpConditions = array(); + $jumpConditions = $jumpConditionList->getData(); + + $this->xml_writer->xmlStartTag('JumpConditions'); + + foreach ($jumpConditions as $jmp_con_index => $jumpCondition_data) { + $jumpCondition = new ilQuestionSetPoolJumpCondition(); + $jumpCondition->setId($jumpCondition_data['id']); + $jumpCondition->read(); + + $this->xml_writer->xmlStartTag('JumpCondition'); + $this->xml_writer->xmlElement('JumpConditionId', null, (int) $jumpCondition->getId()); + $this->xml_writer->xmlElement('JumpConditionText', null, (string) $jumpCondition->getJumpCondition()); + + $this->xml_writer->xmlElement('JumpConditionNodeId', null, (int) $jumpCondition_data['node_fi']); + $this->xml_writer->xmlElement('JumpConditionQuestionId', null, $jumpCondition_data['question_fi']); + + $this->xml_writer->xmlElement('JumpConditionRepetitions', null, $jumpCondition->getRepititions()); + $this->xml_writer->xmlElement('JumpConditionSorting', null, $jumpCondition->getSorting()); + $this->xml_writer->xmlElement('JumpConditionTrueFeedback', null, $jumpCondition->getTrueFeedback()); + $this->xml_writer->xmlElement('JumpConditionTrueJumpFeedback', null, $jumpCondition->getTrueJumpFeedback()); + $this->xml_writer->xmlElement('JumpConditionFalseFeedback', null, $jumpCondition->getFalseFeedback()); + + $this->xml_writer->xmlEndTag('JumpCondition'); + } + + $this->xml_writer->xmlEndTag('JumpConditions'); + } + + /** + * Default ilias questionpool export + */ + protected function exportQuestions() + { + // write qti file + ilUtil::makeDirParents($this->export_dir); + $qti_file = fopen($this->export_dir . "/" . $this->qti_filename, "w"); + fwrite($qti_file, $this->qpl_obj->questionsToXML($this->questions)); + fclose($qti_file); + } + + /** + * @param $a_export_dir + */ + public function exportXHTMLMediaObjects($a_export_dir) + { + ilUtil::makeDirParents($a_export_dir . "/objects/"); + + foreach ($this->questions as $question_id) { + $mobs = ilObjMediaObject::_getMobsOfObject("qpl:html", $question_id); + foreach ($mobs as $mob) { + if (ilObjMediaObject::_exists($mob)) { + $mob_obj = new ilObjMediaObject($mob); + $mob_obj->exportFiles($a_export_dir); + unset($mob_obj); + } + } + } + } + + /** + * Main export method for single object export AND export within an container (crs, cat, ...) + * @param $a_entity + * @param $a_schema_version + * @param $a_id + * @return string + */ + public function getXmlRepresentation($a_entity, $a_schema_version, $a_id) + { + $ref_id = current(ilObject::_getAllReferences($a_id)); + + $date = time(); + $this->export_dir = $this->getAbsoluteExportDirectory(); + $this->subdir = $date . "__" . IL_INST_ID . "__" . "xqsp" . "_" . $a_id; + $this->filename = $this->subdir . ".xml"; + $this->qti_filename = "xqsp_qti.xml"; + + $this->plugin_object->includeClass('class.ilObjQuestionSetPool.php'); + + $this->object = new ilObjQuestionSetPool($ref_id); + $this->xml_writer = new ilXmlWriter(); + + $this->qpl_obj = new ilObjQuestionPool(); + // get Log File + ilUtil::makeDirParents($this->getExportDirectory()); + $this->initLogFile(); + $this->exportPagesXML(); + + return $this->xml_writer->xmlDumpMem(); + } + + /** + * @param $a_entity + * @return array + */ + public function getValidSchemaVersions($a_entity) + { + return array( + '5.1.0' => array( + 'namespace' => 'http://www.ilias.de/', + 'xsd_file' => 'xqsp_5_1.xsd', + 'uses_dataset' => false, + 'min' => '5.1.0', + 'max' => '5.1.999' + ) + ); + } + + /** + * @param $a_entity + * @param $a_target_release + * @param array $a_ids + * @return array + */ + public function getXmlExportHeadDependencies($a_entity, $a_target_release, $a_ids) + { + if ("xqsp" == $a_entity) { + // Array von QSP obj_ids + $qpl_obj_ids = array(); + + global $ilDB, $ilObjDataCache; + //qs.id, qs.questionsetpool_fi, qst.question_fi, qpl_qst.obj_fi, + $res = $ilDB->query(' SELECT qpl_qst.question_id, qpl_qst.original_id FROM rep_robj_xqsp_qs qs INNER JOIN rep_robj_xqsp_qs_qst qst ON qs.id = qst.questionset_fi INNER JOIN qpl_questions qpl_qst ON qst.question_fi = qpl_qst.question_id WHERE ' . $ilDB->in('qs.questionsetpool_fi', $a_ids, false, 'integer')); - - $org_qst_ids = array(); - while($row = $ilDB->fetchAssoc($res)) - { - $ids[] = $row; - if($row['original_id'] !== NULL) - { - $org_qst_ids[] = $row['original_id']; - } - else - { - $org_qst_ids[] = $row['question_id']; - } - } - - if(is_array($org_qst_ids) && count($org_qst_ids) > 0) - { - $res_2 = $ilDB->query('SELECT obj_fi FROM qpl_questions WHERE '. $ilDB->in('question_id',$org_qst_ids, false, 'integer')); - - while($row = $ilDB->fetchAssoc($res_2)) - { - if($ilObjDataCache->lookupType($row['obj_fi']) == 'qpl') - { - $qpl_obj_ids[$row['obj_fi']] = $row['obj_fi']; - } - } - } - - return array (array( - "component" => "Modules/TestQuestionPool", - "entity" => "qpl", - "ids" => array_unique($qpl_obj_ids))); - } - - return parent::getXmlExportHeadDependencies(); - } + + $org_qst_ids = array(); + while ($row = $ilDB->fetchAssoc($res)) { + $ids[] = $row; + if ($row['original_id'] !== null) { + $org_qst_ids[] = $row['original_id']; + } else { + $org_qst_ids[] = $row['question_id']; + } + } + + if (is_array($org_qst_ids) && count($org_qst_ids) > 0) { + $res_2 = $ilDB->query('SELECT obj_fi FROM qpl_questions WHERE ' . $ilDB->in('question_id', $org_qst_ids, false, 'integer')); + + while ($row = $ilDB->fetchAssoc($res_2)) { + if ($ilObjDataCache->lookupType($row['obj_fi']) == 'qpl') { + $qpl_obj_ids[$row['obj_fi']] = $row['obj_fi']; + } + } + } + + return array(array( + "component" => "Modules/TestQuestionPool", + "entity" => "qpl", + "ids" => array_unique($qpl_obj_ids))); + } + + return parent::getXmlExportHeadDependencies(); + } } diff --git a/classes/class.ilQuestionSetPoolImporter.php b/classes/class.ilQuestionSetPoolImporter.php index 3d94e665515ad8563c7d360978f6d40f98cec8ed..abf5542ed9c76d36ed756b4f4ecd7592dc8d9a7a 100755 --- a/classes/class.ilQuestionSetPoolImporter.php +++ b/classes/class.ilQuestionSetPoolImporter.php @@ -1,518 +1,478 @@ */ class ilQuestionSetPoolImporter extends ilXmlImporter { - const SINGLE_IMPORT_NEW_POOL = -1; - const SINGLE_IMPORT_NO_POOL = -2; + const SINGLE_IMPORT_NEW_POOL = -1; + const SINGLE_IMPORT_NO_POOL = -2; - /** - * @var ilObjQuestionPool - */ - protected $qpl_obj = NULL; - - protected $is_single_import = true; - - /** - * @var int[] - */ - protected static $pool_by_parent_id = array(); - - protected $current_parent_ref_id = 0; - - /** - * @var null - */ - protected $xml_file = NULL; - /** - * @var null - */ - protected $qti_file = NULL; - - /** - * @var array - */ - protected $qpl_qst_mapping = array(); - - /** - * @param $xml_file - */ - private function setXmlFile($xml_file) - { - $this->xml_file = $xml_file; - } - - public function getXmlFile() - { - return $this->xml_file; - } - - /** - * @param $qti_file - */ - public function setQtiFile($qti_file) - { - $this->qti_file = $qti_file; - } - - public function getQtiFile() - { - return $this->qti_file; - } - - /** - * ilQuestionSetPoolImporter constructor. - */ - public function __construct() - { - $this->plugin_object = ilQuestionSetPoolPlugin::getInstance(); - $this->plugin_object->includeClass('models/class.ilQuestionSetPoolSet.php'); - $this->plugin_object->includeClass('models/class.ilQuestionSetPoolPath.php'); - $this->plugin_object->includeClass('models/class.ilQuestionSetPoolNode.php'); - $this->plugin_object->includeClass('models/class.ilQuestionSetPoolJumpCondition.php'); - } - - public function init() - { - $qti_path = $this->getImportDirectory().'/Plugins/xqsp/set_1/expDir_1'; - $qti_file = $qti_path.'/xqsp_qti.xml'; - $xml_file = $this->getImportDirectory().'/Plugins/xqsp/set_1/export.xml'; + /** + * @var ilObjQuestionPool + */ + protected $qpl_obj = null; + + protected $is_single_import = true; + + /** + * @var int[] + */ + protected static $pool_by_parent_id = array(); + + protected $current_parent_ref_id = 0; + + /** + * @var null + */ + protected $xml_file = null; + /** + * @var null + */ + protected $qti_file = null; + + /** + * @var array + */ + protected $qpl_qst_mapping = array(); + + /** + * @param $xml_file + */ + private function setXmlFile($xml_file) + { + $this->xml_file = $xml_file; + } + + public function getXmlFile() + { + return $this->xml_file; + } + + /** + * @param $qti_file + */ + public function setQtiFile($qti_file) + { + $this->qti_file = $qti_file; + } + + public function getQtiFile() + { + return $this->qti_file; + } + + /** + * ilQuestionSetPoolImporter constructor. + */ + public function __construct() + { + $this->plugin_object = ilQuestionSetPoolPlugin::getInstance(); + $this->plugin_object->includeClass('models/class.ilQuestionSetPoolSet.php'); + $this->plugin_object->includeClass('models/class.ilQuestionSetPoolPath.php'); + $this->plugin_object->includeClass('models/class.ilQuestionSetPoolNode.php'); + $this->plugin_object->includeClass('models/class.ilQuestionSetPoolJumpCondition.php'); + } + + public function init() + { + $qti_path = $this->getImportDirectory() . '/Plugins/xqsp/set_1/expDir_1'; + $qti_file = $qti_path . '/xqsp_qti.xml'; + $xml_file = $this->getImportDirectory() . '/Plugins/xqsp/set_1/export.xml'; - $this->validateXmlFile($xml_file); - $this->setQtiFile($qti_file); - } - - - /** - * @param $xml_file - */ - public function validateXmlFile($xml_file) - { - $this->plugin_object->includeClass('class.ilQuestionSetPoolXmlValidator.php'); - $validator = new ilQuestionSetPoolXmlValidator(); - $validator->setXsdFile('/xml/xqsp_5_1.xsd'); - $validator->setXmlFile($xml_file); - $validator->validate(); - $this->setXmlFile($xml_file); - return true; - } - - /** - * - */ - public function createImportDirectory() - { - global $ilErr; - - include_once "./Services/Utilities/classes/class.ilUtil.php"; - $xqsp_data_dir = ilUtil::getDataDir()."/xqsp_data"; - ilUtil::makeDir($xqsp_data_dir); - - if(!is_writable($xqsp_data_dir)) - { - $ilErr->raiseError("QuestionSetPool Data Directory (".$xqsp_data_dir.") not writeable.", $ilErr->error_obj->FATAL); - } - - // create QuestionSetPool directory (data_dir/xqsp_data/xqsp_import) - $import_dir = $xqsp_data_dir."/xqsp_import"; - ilUtil::makeDir($import_dir); - if(!@is_dir($import_dir)) - { - $ilErr->raiseError("Creation of QuestionSetPool import directory failed.", $ilErr->error_obj->FATAL); - } - - $this->setImportDirectory($import_dir); - } - - public function initializeQplObject($id) - { - if($id <= 0) - { - $this->qpl_obj = $this->createQplObject(); - } - else - { - $this->qpl_obj = new ilObjQuestionPool($id, false); - $this->qpl_obj->read(true); - } - } - - /** - * Creates a new questionpool object - * - * copied from ilObjQuestionPoolGUI->importVerifiedFileObject() - */ - public function createQplObject() - { - // create new questionpool object - $qpl_obj = new ilObjQuestionPool(0, true); - // set type of questionpool object - $qpl_obj->setType('qpl'); - // set title of questionpool object to "dummy" - $qpl_obj->setTitle("dummy"); - // set description of questionpool object - $qpl_obj->setDescription("questionpool creation"); - // set online - $qpl_obj->setOnline(true); - // create the questionpool class in the ILIAS database (object_data table) - $qpl_obj->create(true); - // create a reference for the questionpool object in the ILIAS database (object_reference table) - $qpl_obj->createReference(); - - $qpl_obj->update(); - $qpl_obj->saveToDb(); - return $qpl_obj; - } - - /** - * Import questions to QPL questionpool - */ - protected function parseQtiFile() - { - //@important do not delete this $_SESSION handling!! - include_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php"; - $tmp_dir = ilObjQuestionPool::_getImportDirectory(); - ilObjQuestionPool::_setImportDirectory($this->getImportDirectoryBase()); + $this->validateXmlFile($xml_file); + $this->setQtiFile($qti_file); + } + + + /** + * @param $xml_file + */ + public function validateXmlFile($xml_file) + { + $this->plugin_object->includeClass('class.ilQuestionSetPoolXmlValidator.php'); + $validator = new ilQuestionSetPoolXmlValidator(); + $validator->setXsdFile('/xml/xqsp_5_1.xsd'); + $validator->setXmlFile($xml_file); + $validator->validate(); + $this->setXmlFile($xml_file); + return true; + } + + /** + * + */ + public function createImportDirectory() + { + global $ilErr; + + $xqsp_data_dir = ilUtil::getDataDir() . "/xqsp_data"; + ilUtil::makeDir($xqsp_data_dir); + + if (!is_writable($xqsp_data_dir)) { + $ilErr->raiseError("QuestionSetPool Data Directory (" . $xqsp_data_dir . ") not writeable.", $ilErr->error_obj->FATAL); + } + + // create QuestionSetPool directory (data_dir/xqsp_data/xqsp_import) + $import_dir = $xqsp_data_dir . "/xqsp_import"; + ilUtil::makeDir($import_dir); + if (!@is_dir($import_dir)) { + $ilErr->raiseError("Creation of QuestionSetPool import directory failed.", $ilErr->error_obj->FATAL); + } + + $this->setImportDirectory($import_dir); + } + + public function initializeQplObject($id) + { + if ($id <= 0) { + $this->qpl_obj = $this->createQplObject(); + } else { + $this->qpl_obj = new ilObjQuestionPool($id, false); + $this->qpl_obj->read(true); + } + } + + /** + * Creates a new questionpool object + * + * copied from ilObjQuestionPoolGUI->importVerifiedFileObject() + */ + public function createQplObject() + { + // create new questionpool object + $qpl_obj = new ilObjQuestionPool(0, true); + // set type of questionpool object + $qpl_obj->setType('qpl'); + // set title of questionpool object to "dummy" + $qpl_obj->setTitle("dummy"); + // set description of questionpool object + $qpl_obj->setDescription("questionpool creation"); + // set online + $qpl_obj->setOnline(true); + // create the questionpool class in the ILIAS database (object_data table) + $qpl_obj->create(true); + // create a reference for the questionpool object in the ILIAS database (object_reference table) + $qpl_obj->createReference(); + + $qpl_obj->update(); + $qpl_obj->saveToDb(); + return $qpl_obj; + } + + /** + * Import questions to QPL questionpool + */ + protected function parseQtiFile() + { + //@important do not delete this $_SESSION handling!! + $tmp_dir = ilObjQuestionPool::_getImportDirectory(); + ilObjQuestionPool::_setImportDirectory($this->getImportDirectoryBase()); - $tmp_subdir = $_SESSION["qpl_import_subdir"]; - $_SESSION["qpl_import_subdir"] = basename($this->getImportDirectory()); + $tmp_subdir = $_SESSION["qpl_import_subdir"]; + $_SESSION["qpl_import_subdir"] = basename($this->getImportDirectory()); - // start parsing of QTI files - include_once "./Services/QTI/classes/class.ilQTIParser.php"; - $qtiParser = new ilQTIParser($this->getQtiFile(), IL_MO_PARSE_QTI, $this->xqsp_obj->getId()); - $result = $qtiParser->startParsing(); - $this->addQuestionMapping($qtiParser->getImportMapping()); + // start parsing of QTI files + $qtiParser = new ilQTIParser($this->getQtiFile(), IL_MO_PARSE_QTI, $this->xqsp_obj->getId()); + $result = $qtiParser->startParsing(); + $this->addQuestionMapping($qtiParser->getImportMapping()); - ilObjQuestionPool::_setImportDirectory($tmp_dir); - $_SESSION["qpl_import_subdir"] = $tmp_subdir; - } - - protected function addQuestionMapping($qtiParser_import_mapping) - { - foreach($qtiParser_import_mapping as $question_ident => $pool_qst_ident) - { - $exp_ident = explode('_qst_', $question_ident); - $old_qst_id = end($exp_ident); - $new_qst_id = $pool_qst_ident['pool']; - $this->qpl_qst_mapping[$old_qst_id] = $new_qst_id; - } - } + ilObjQuestionPool::_setImportDirectory($tmp_dir); + $_SESSION["qpl_import_subdir"] = $tmp_subdir; + } + + protected function addQuestionMapping($qtiParser_import_mapping) + { + foreach ($qtiParser_import_mapping as $question_ident => $pool_qst_ident) { + $exp_ident = explode('_qst_', $question_ident); + $old_qst_id = end($exp_ident); + $new_qst_id = $pool_qst_ident['pool']; + $this->qpl_qst_mapping[$old_qst_id] = $new_qst_id; + } + } - /** - * @param array $set_data - * @param array $set_questions - * @param array $set_paths - */ - public function importQuestionSet($set_data, $set_questions, $set_paths, $a_mapping) - { - $set = new ilQuestionSetPoolSet(); - $set->setContainerObjId($this->xqsp_obj->getId()); - $set->setTitle($set_data['SetTitle']); - $set->setDescription($set_data['SetDescription']); - $set->setOriginalId($set_data['OriginialId']); + /** + * @param array $set_data + * @param array $set_questions + * @param array $set_paths + */ + public function importQuestionSet($set_data, $set_questions, $set_paths, $a_mapping) + { + $set = new ilQuestionSetPoolSet(); + $set->setContainerObjId($this->xqsp_obj->getId()); + $set->setTitle($set_data['SetTitle']); + $set->setDescription($set_data['SetDescription']); + $set->setOriginalId($set_data['OriginialId']); - $set->update(); + $set->update(); - $this->addSetMapping($set_data['SetId'], $set->getId()); + $this->addSetMapping($set_data['SetId'], $set->getId()); - foreach($set_questions as $set_question) - { - $original_question_id = $a_mapping->getMapping('Modules/TestQuestionPool', 'quest', $set_question['QuestionOriginalId']); - if($original_question_id) - { - if(!assQuestion::_questionExistsInPool($original_question_id)) - { - $original_question_id = NULL; - } - } + foreach ($set_questions as $set_question) { + $original_question_id = $a_mapping->getMapping('Modules/TestQuestionPool', 'quest', $set_question['QuestionOriginalId']); + if ($original_question_id) { + if (!assQuestion::_questionExistsInPool($original_question_id)) { + $original_question_id = null; + } + } - $copy_id = $set->getQuestionList()->import($this->qpl_qst_mapping[$set_question['QuestionId']], $original_question_id); - $this->qpl_qst_mapping[$set_question['QuestionId']] = $copy_id; + $copy_id = $set->getQuestionList()->import($this->qpl_qst_mapping[$set_question['QuestionId']], $original_question_id); + $this->qpl_qst_mapping[$set_question['QuestionId']] = $copy_id; - if($original_question_id == 0 || $this->is_single_import) - { - $this->qpl_qst_mapping['new_qpl'][$set_question['QuestionId']] = $copy_id; - if($set_question['QuestionOriginalId']) - { - $a_mapping->addMapping('Plugins/xqsp', 'org_qst_id', $set_question['QuestionOriginalId'], $copy_id); - } - } - else - { - $this->qpl_qst_mapping['new_qpl'][$set_question['QuestionId']] = $original_question_id; - } - } + if ($original_question_id == 0 || $this->is_single_import) { + $this->qpl_qst_mapping['new_qpl'][$set_question['QuestionId']] = $copy_id; + if ($set_question['QuestionOriginalId']) { + $a_mapping->addMapping('Plugins/xqsp', 'org_qst_id', $set_question['QuestionOriginalId'], $copy_id); + } + } else { + $this->qpl_qst_mapping['new_qpl'][$set_question['QuestionId']] = $original_question_id; + } + } - foreach($set_paths as $set_path) - { - $path = new ilQuestionSetPoolPath(); - $path->setSet($set); - $path->setTitle($set_path[0]['PathTitle']); - $path->import(); + foreach ($set_paths as $set_path) { + $path = new ilQuestionSetPoolPath(); + $path->setSet($set); + $path->setTitle($set_path[0]['PathTitle']); + $path->import(); - $this->addPathMapping($set_data[0]['PathId'], $path->getId()); + $this->addPathMapping($set_data[0]['PathId'], $path->getId()); - $nodes = $set_path['nodes']; - $this->importNodes($nodes, $path); - } - } - - /** - * @param array $nodes - * @param ilQuestionSetPoolPath $path - */ - protected function importNodes($nodes, ilQuestionSetPoolPath $path) - { - foreach($nodes as $node_data) - { - $node = new ilQuestionSetPoolNode(); - $node->setQuestion(assQuestion::_instantiateQuestion($this->qpl_qst_mapping[$node_data[0]['NodeQuestionId']])); - $node->setPath($path); - $node->setInitialCondition($node_data[0]['NodeInitialCondition']); - if(strlen($node_data[0]['NodeDominantScoring'])) - { - $node->setDominantScoring($node_data[0]['NodeDominantScoring']); - } - $node->setTrueFeedback($node_data[0]['NodeTrueFeedback']); - $node->setFalseFeedback($node_data[0]['NodeFalseFeedback']); - - $node->import(); - - $this->addNodeMapping($node_data[0]['NodeId'], $node->getId()); - - $jump_conditions = $node_data['jump_conditions']; - if(is_array($jump_conditions) && count($jump_conditions) == 0) - { - continue 1; - } - $this->importJumpConditions($jump_conditions, $node); - } - } - - /** - * @param array $jump_conditions - * @param ilQuestionSetPoolNode $node - */ - protected function importJumpConditions($jump_conditions, ilQuestionSetPoolNode $node) - { - foreach($jump_conditions as $jump_condition_data) - { - $jump_con = new ilQuestionSetPoolJumpCondition(); - $jump_con->setNode($node); - $jump_con->setQuestion( - $this->qpl_qst_mapping[$jump_condition_data['JumpConditionQuestionId']] ? - assQuestion::_instantiateQuestion($this->qpl_qst_mapping[$jump_condition_data['JumpConditionQuestionId']]): - NULL - ); - $jump_con->setJumpCondition($jump_condition_data['JumpConditionText']); - if(strlen($jump_condition_data['JumpConditionRepetitions'])) - { - $jump_con->setRepititions($jump_condition_data['JumpConditionRepetitions']); - } + $nodes = $set_path['nodes']; + $this->importNodes($nodes, $path); + } + } + + /** + * @param array $nodes + * @param ilQuestionSetPoolPath $path + */ + protected function importNodes($nodes, ilQuestionSetPoolPath $path) + { + foreach ($nodes as $node_data) { + $node = new ilQuestionSetPoolNode(); + $node->setQuestion(assQuestion::_instantiateQuestion($this->qpl_qst_mapping[$node_data[0]['NodeQuestionId']])); + $node->setPath($path); + $node->setInitialCondition($node_data[0]['NodeInitialCondition']); + if (strlen($node_data[0]['NodeDominantScoring'])) { + $node->setDominantScoring($node_data[0]['NodeDominantScoring']); + } + $node->setTrueFeedback($node_data[0]['NodeTrueFeedback']); + $node->setFalseFeedback($node_data[0]['NodeFalseFeedback']); + + $node->import(); + + $this->addNodeMapping($node_data[0]['NodeId'], $node->getId()); + + $jump_conditions = $node_data['jump_conditions']; + if (is_array($jump_conditions) && count($jump_conditions) == 0) { + continue 1; + } + $this->importJumpConditions($jump_conditions, $node); + } + } + + /** + * @param array $jump_conditions + * @param ilQuestionSetPoolNode $node + */ + protected function importJumpConditions($jump_conditions, ilQuestionSetPoolNode $node) + { + foreach ($jump_conditions as $jump_condition_data) { + $jump_con = new ilQuestionSetPoolJumpCondition(); + $jump_con->setNode($node); + $jump_con->setQuestion( + $this->qpl_qst_mapping[$jump_condition_data['JumpConditionQuestionId']] ? + assQuestion::_instantiateQuestion($this->qpl_qst_mapping[$jump_condition_data['JumpConditionQuestionId']]): + null + ); + $jump_con->setJumpCondition($jump_condition_data['JumpConditionText']); + if (strlen($jump_condition_data['JumpConditionRepetitions'])) { + $jump_con->setRepititions($jump_condition_data['JumpConditionRepetitions']); + } - $jump_con->setTrueFeedback($jump_condition_data['JumpConditionTrueFeedback']); - $jump_con->setTrueJumpFeedback($jump_condition_data['JumpConditionTrueJumpFeedback']); - $jump_con->setFalseFeedback($jump_condition_data['JumpConditionFalseFeedback']); - - $jump_con->import(); - } - } - - /** - * @param $old_set_id - * @param $new_set_id - */ - protected function addSetMapping($old_set_id, $new_set_id) - { - $this->set_mapping[$old_set_id] = $new_set_id; - } - - /** - * @param $old_path_id - * @param $new_path_id - */ - protected function addPathMapping($old_path_id, $new_path_id) - { - $this->path_mapping[$old_path_id] = $new_path_id; - } - - /** - * @param $old_node_id - * @param $new_node_id - */ - protected function addNodeMapping($old_node_id, $new_node_id) - { - $this->node_mapping[$old_node_id] = $new_node_id; - } - - /** - * Import XML - * @param $a_entity - * @param $a_id - * @param $a_xml - * @param $a_mapping - * @return bool - */ - function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping) - { - /** - * @var $tree ilTree - */ - global $tree; + $jump_con->setTrueFeedback($jump_condition_data['JumpConditionTrueFeedback']); + $jump_con->setTrueJumpFeedback($jump_condition_data['JumpConditionTrueJumpFeedback']); + $jump_con->setFalseFeedback($jump_condition_data['JumpConditionFalseFeedback']); + + $jump_con->import(); + } + } + + /** + * @param $old_set_id + * @param $new_set_id + */ + protected function addSetMapping($old_set_id, $new_set_id) + { + $this->set_mapping[$old_set_id] = $new_set_id; + } + + /** + * @param $old_path_id + * @param $new_path_id + */ + protected function addPathMapping($old_path_id, $new_path_id) + { + $this->path_mapping[$old_path_id] = $new_path_id; + } + + /** + * @param $old_node_id + * @param $new_node_id + */ + protected function addNodeMapping($old_node_id, $new_node_id) + { + $this->node_mapping[$old_node_id] = $new_node_id; + } + + /** + * Import XML + * @param $a_entity + * @param $a_id + * @param $a_xml + * @param $a_mapping + * @return bool + */ + public function importXmlRepresentation($a_entity, $a_id, $a_xml, $a_mapping) + { + /** + * @var $tree ilTree + */ + global $tree; - $this->plugin_object->includeClass('class.ilObjQuestionSetPool.php'); - $this->plugin_object->includeClass('class.ilObjQuestionSetPoolXMLParser.php'); - - $parent_ref_id = 0; - - if($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_id)) - { - $ref_ids = ilObject::_getAllReferences($new_id); - $ref_id = current($ref_ids); - - $parent_ref_id = $tree->getParentId($ref_id); - - $this->xqsp_obj = ilObjectFactory::getInstanceByObjId($new_id, false); - $this->xqsp_obj->setRefId($ref_id); - $this->is_single_import = false; - } - else - { - $this->xqsp_obj = new ilObjQuestionSetPool(); - $this->xqsp_obj->create(true); - $this->is_single_import = true; - } - - $this->current_parent_ref_id = $parent_ref_id; - - // import questions to QPL questionpool - $this->parseQtiFile(); + $this->plugin_object->includeClass('class.ilObjQuestionSetPool.php'); + $this->plugin_object->includeClass('class.ilObjQuestionSetPoolXMLParser.php'); + + $parent_ref_id = 0; + + if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_id)) { + $ref_ids = ilObject::_getAllReferences($new_id); + $ref_id = current($ref_ids); + + $parent_ref_id = $tree->getParentId($ref_id); + + $this->xqsp_obj = ilObjectFactory::getInstanceByObjId($new_id, false); + $this->xqsp_obj->setRefId($ref_id); + $this->is_single_import = false; + } else { + $this->xqsp_obj = new ilObjQuestionSetPool(); + $this->xqsp_obj->create(true); + $this->is_single_import = true; + } + + $this->current_parent_ref_id = $parent_ref_id; + + // import questions to QPL questionpool + $this->parseQtiFile(); - $parser = new ilObjQuestionSetPoolXMLParser($this->xqsp_obj, $this->getXmlFile()); - $parser->setImportDirectory($this->getImportDirectory()); - $parser->startParsing(); - $this->xqsp_obj = $parser->getQuestionSetPoolObject(); - $this->xqsp_obj->update(); - - // create sets - $sets = $parser->getSetsArray(); - - foreach($sets as $set_data) - { - $this->importQuestionSet($set_data[0], $set_data['questions'], $set_data['paths'], $a_mapping); - } - - $a_mapping->addMapping('Plugins/xqsp', 'xqsp', $a_id, $this->xqsp_obj->getId()); - } - - function finalProcessing($a_mapping) - { - - // Container import - // Prüfen, ob in einer statischen Variable (z.B. self::$pool_by_parent[$this->current_parent_ref_id] schon eine Pool ID existiert - // Wenn ja, diesen Pool nehmen (sofern Bedarf für neue Originale) - // Wenn nein, neuen Pool auf dieser Ebene -> mit putInTree($this->current_parent_ref_id) einhängen, - // und dann dessen ID hier merken: self::$pool_by_parent[$this->current_parent_ref_id] - - // Einzel-Import mit (ggf. erfolgter Wahl eines bestehenden Fragenpools als Ziel für Originale unserer Fragen) - $new_qpl_id = (int)$_POST['qpl']; - if($_POST['qpl'] == self::SINGLE_IMPORT_NO_POOL) - { - //Die neuen Fragen 'ohne pool' liegen schon im XQSP. - } - else - { - if ($new_qpl_id > 0) - { - $this->initializeQplObject($new_qpl_id); - } - // Containter-Import (Plugin liegt im Kurs, die Originale unserer Fragen liegen ggf.(!!) in ebenfalls importierten Fragenpools) - else if ($this->is_single_import || (is_array($this->qpl_qst_mapping['new_qpl']) && count($this->qpl_qst_mapping['new_qpl']) > 0)) - { - $parent_ref_id = $a_mapping->getTargetId(); - if (!$this->is_single_import && $this->current_parent_ref_id > 0) - { - $parent_ref_id = $this->current_parent_ref_id; - } + $parser = new ilObjQuestionSetPoolXMLParser($this->xqsp_obj, $this->getXmlFile()); + $parser->setImportDirectory($this->getImportDirectory()); + $parser->startParsing(); + $this->xqsp_obj = $parser->getQuestionSetPoolObject(); + $this->xqsp_obj->update(); + + // create sets + $sets = $parser->getSetsArray(); + + foreach ($sets as $set_data) { + $this->importQuestionSet($set_data[0], $set_data['questions'], $set_data['paths'], $a_mapping); + } + + $a_mapping->addMapping('Plugins/xqsp', 'xqsp', $a_id, $this->xqsp_obj->getId()); + } + + public function finalProcessing($a_mapping) + { + + // Container import + // Prüfen, ob in einer statischen Variable (z.B. self::$pool_by_parent[$this->current_parent_ref_id] schon eine Pool ID existiert + // Wenn ja, diesen Pool nehmen (sofern Bedarf für neue Originale) + // Wenn nein, neuen Pool auf dieser Ebene -> mit putInTree($this->current_parent_ref_id) einhängen, + // und dann dessen ID hier merken: self::$pool_by_parent[$this->current_parent_ref_id] + + // Einzel-Import mit (ggf. erfolgter Wahl eines bestehenden Fragenpools als Ziel für Originale unserer Fragen) + $new_qpl_id = (int) $_POST['qpl']; + if ($_POST['qpl'] == self::SINGLE_IMPORT_NO_POOL) { + //Die neuen Fragen 'ohne pool' liegen schon im XQSP. + } else { + if ($new_qpl_id > 0) { + $this->initializeQplObject($new_qpl_id); + } + // Containter-Import (Plugin liegt im Kurs, die Originale unserer Fragen liegen ggf.(!!) in ebenfalls importierten Fragenpools) + elseif ($this->is_single_import || (is_array($this->qpl_qst_mapping['new_qpl']) && count($this->qpl_qst_mapping['new_qpl']) > 0)) { + $parent_ref_id = $a_mapping->getTargetId(); + if (!$this->is_single_import && $this->current_parent_ref_id > 0) { + $parent_ref_id = $this->current_parent_ref_id; + } - if (isset(self::$pool_by_parent_id[$parent_ref_id])) - { - $pool_obj_id = self::$pool_by_parent_id[$parent_ref_id]; - $this->initializeQplObject($pool_obj_id); - } - else - { - // es handelt sich um einen dummy pool - $this->initializeQplObject(0); - // put the questionpool object in the administration tree - $this->qpl_obj->putInTree($parent_ref_id); - // get default permissions and set the permissions for the questionpool object - $this->qpl_obj->setPermissions($parent_ref_id); + if (isset(self::$pool_by_parent_id[$parent_ref_id])) { + $pool_obj_id = self::$pool_by_parent_id[$parent_ref_id]; + $this->initializeQplObject($pool_obj_id); + } else { + // es handelt sich um einen dummy pool + $this->initializeQplObject(0); + // put the questionpool object in the administration tree + $this->qpl_obj->putInTree($parent_ref_id); + // get default permissions and set the permissions for the questionpool object + $this->qpl_obj->setPermissions($parent_ref_id); - self::$pool_by_parent_id[$parent_ref_id] = $this->qpl_obj->getId(); - } - } + self::$pool_by_parent_id[$parent_ref_id] = $this->qpl_obj->getId(); + } + } - foreach ($this->qpl_qst_mapping['new_qpl'] as $new_id) - { - //Die neuen Fragen 'ohne pool' liegen schon im XQSP. - // jetzt müssen sie in den neu angelegten dummy pool (QPL) kopiert werden und die org_id im xqsp-pool angepasst werden. - $source_qst = assQuestion::_instantiateQuestion($new_id); - $is_xqsp_pool = (ilObject::_lookupType($source_qst->getObjId()) == 'xqsp' ? true : false); - // This is the intended behaviour, see http://www.ilias.de/mantis/view.php?id=18325 - if(($source_qst->getOriginalId() == NULL || $this->is_single_import) && $is_xqsp_pool) - { - // Dies ist nur für Fragen "ohne pool" relevant!!!! - $clone_id = $source_qst->copyObject($this->qpl_obj->getId()); - $source_qst = assQuestion::_instantiateQuestion($new_id); - $source_qst->setNewOriginalId($clone_id); - $source_qst->saveToDb(); - } - } - } - return parent::finalProcessing($a_mapping); - } - - /** - * Create qti and xml file name - * @return array - */ - protected function parseXmlFileNames() - { - $GLOBALS['ilLog']->write(__METHOD__.': '.$this->getImportDirectory()); - - $basename = basename($this->getImportDirectory()); + foreach ($this->qpl_qst_mapping['new_qpl'] as $new_id) { + //Die neuen Fragen 'ohne pool' liegen schon im XQSP. + // jetzt müssen sie in den neu angelegten dummy pool (QPL) kopiert werden und die org_id im xqsp-pool angepasst werden. + $source_qst = assQuestion::_instantiateQuestion($new_id); + $is_xqsp_pool = (ilObject::_lookupType($source_qst->getObjId()) == 'xqsp' ? true : false); + // This is the intended behaviour, see http://www.ilias.de/mantis/view.php?id=18325 + if (($source_qst->getOriginalId() == null || $this->is_single_import) && $is_xqsp_pool) { + // Dies ist nur für Fragen "ohne pool" relevant!!!! + $clone_id = $source_qst->copyObject($this->qpl_obj->getId()); + $source_qst = assQuestion::_instantiateQuestion($new_id); + $source_qst->setNewOriginalId($clone_id); + $source_qst->saveToDb(); + } + } + } + return parent::finalProcessing($a_mapping); + } + + /** + * Create qti and xml file name + * @return array + */ + protected function parseXmlFileNames() + { + $GLOBALS['ilLog']->write(__METHOD__ . ': ' . $this->getImportDirectory()); + + $basename = basename($this->getImportDirectory()); - $xml = $this->getImportDirectory().'/'.$basename.'.xml'; - $qti = $this->getImportDirectory().'/'.preg_replace('/xqsp/', 'qti', $basename).'.xml'; - - return array($xml,$qti); - } + $xml = $this->getImportDirectory() . '/' . $basename . '.xml'; + $qti = $this->getImportDirectory() . '/' . preg_replace('/xqsp/', 'qti', $basename) . '.xml'; + + return array($xml,$qti); + } - private function getImportDirectoryBase() - { - $dir = $this->getImportDirectory(); - $dir = dirname($dir); - return $dir; - } - - /** - * @param array $mapping - */ - public function setExternalQplQuestionMapping(array $mapping) - { - $this->qpl_qst_mapping = $mapping; - } - - public function getExternalQplQuestionMapping() - { - return $this->qpl_qst_mapping; - } + private function getImportDirectoryBase() + { + $dir = $this->getImportDirectory(); + $dir = dirname($dir); + return $dir; + } + + /** + * @param array $mapping + */ + public function setExternalQplQuestionMapping(array $mapping) + { + $this->qpl_qst_mapping = $mapping; + } + + public function getExternalQplQuestionMapping() + { + return $this->qpl_qst_mapping; + } } diff --git a/classes/class.ilQuestionSetPoolPlugin.php b/classes/class.ilQuestionSetPoolPlugin.php index 28977da794085d5d0ae4cf7073b3d4e89f959dcc..17a5876c1b4ea59cfff99cc04e78899c12a7244c 100644 --- a/classes/class.ilQuestionSetPoolPlugin.php +++ b/classes/class.ilQuestionSetPoolPlugin.php @@ -1,172 +1,161 @@ - */ + */ class ilQuestionSetPoolPlugin extends ilRepositoryObjectPlugin { - /** - * @var self|null - */ - private static $instance; - - /** - * @var string - */ - private static $PLUGIN_CTYPE = 'Services'; - - /** - * @var string - */ - private static $PLUGIN_CNAME = 'Repository'; - - /** - * @var string - */ - private static $PLUGIN_SLOT_ID = "robj"; - - /** - * @var string - */ - private static $PLUGIN_ID = "xqsp"; - - /** - * @var string - */ - private static $PLUGIN_NAME = "QuestionSetPool"; - - /** - * Get the ID of the of the Plugin - * - * @return string - */ - public static function getPluginId() - { - return self::$PLUGIN_ID; - } - - /** - * Get Plugin Name. Must be same as in class name ilPlugin - * and must correspond to plugins subdirectory name. - * Must be overwritten in plugin class of plugin - * (and should be made final) - * @return string Plugin Name - */ - public function getPluginName() - { - return self::$PLUGIN_NAME; - } - - public static function getName() - { - return self::$PLUGIN_NAME; - } - - /** - * @return self|ilPlugin|ilRepositoryObjectPlugin - */ - public static function getInstance() - { - if(null !== self::$instance) - { - return self::$instance; - } - - return (self::$instance = ilPluginAdmin::getPluginObject( - self::$PLUGIN_CTYPE, - self::$PLUGIN_CNAME, - self::$PLUGIN_SLOT_ID, - self::$PLUGIN_NAME - )); - } - - /** - * @return string - */ - public function getAdditionalDataTable() - { - return "rep_robj_xqsp_data"; - } - - /** - * @return string - */ - public function getQuestionSetTable() - { - return "rep_robj_xqsp_qs"; - } - - /** - * @param string $a_type - * @param string $a_size - * @return string - */ - public static function _getIcon($a_type, $a_size) - { - return ilPlugin::_getImagePath( - IL_COMP_SERVICE, 'Repository', 'robj', - ilPlugin::lookupNameForId(IL_COMP_SERVICE, 'Repository', 'robj', $a_type), - 'icon_' . $a_type . '.svg' - ); - } - - protected function uninstallCustom() - { - /** - * @var $ilDB ilDB - */ - global $ilDB; - - if($ilDB->tableExists('rep_robj_xqsp_data')) - { - $ilDB->dropTable('rep_robj_xqsp_data'); - } - - if($ilDB->tableExists('rep_robj_xqsp_jmp_con')) - { - $ilDB->dropTable('rep_robj_xqsp_jmp_con'); - } - if($ilDB->sequenceExists('rep_robj_xqsp_jmp_con')) - { - $ilDB->dropSequence('rep_robj_xqsp_jmp_con'); - } - - if($ilDB->tableExists('rep_robj_xqsp_node')) - { - $ilDB->dropTable('rep_robj_xqsp_node'); - } - if($ilDB->sequenceExists('rep_robj_xqsp_node')) - { - $ilDB->dropSequence('rep_robj_xqsp_node'); - } - - if($ilDB->tableExists('rep_robj_xqsp_path')) - { - $ilDB->dropTable('rep_robj_xqsp_path'); - } - if($ilDB->sequenceExists('rep_robj_xqsp_path')) - { - $ilDB->dropSequence('rep_robj_xqsp_path'); - } - - if($ilDB->tableExists('rep_robj_xqsp_qs')) - { - $ilDB->dropTable('rep_robj_xqsp_qs'); - } - if($ilDB->sequenceExists('rep_robj_xqsp_qs')) - { - $ilDB->dropSequence('rep_robj_xqsp_qs'); - } - - if($ilDB->tableExists('rep_robj_xqsp_qs_qst')) - { - $ilDB->dropTable('rep_robj_xqsp_qs_qst'); - } - } + /** + * @var self|null + */ + private static $instance; + + /** + * @var string + */ + private static $PLUGIN_CTYPE = 'Services'; + + /** + * @var string + */ + private static $PLUGIN_CNAME = 'Repository'; + + /** + * @var string + */ + private static $PLUGIN_SLOT_ID = "robj"; + + /** + * @var string + */ + private static $PLUGIN_ID = "xqsp"; + + /** + * @var string + */ + private static $PLUGIN_NAME = "QuestionSetPool"; + + /** + * Get the ID of the of the Plugin + * + * @return string + */ + public static function getPluginId() + { + return self::$PLUGIN_ID; + } + + /** + * Get Plugin Name. Must be same as in class name ilPlugin + * and must correspond to plugins subdirectory name. + * Must be overwritten in plugin class of plugin + * (and should be made final) + * @return string Plugin Name + */ + public function getPluginName() + { + return self::$PLUGIN_NAME; + } + + public static function getName() + { + return self::$PLUGIN_NAME; + } + + /** + * @return self|ilPlugin|ilRepositoryObjectPlugin + */ + public static function getInstance() + { + if (null !== self::$instance) { + return self::$instance; + } + + return (self::$instance = ilPluginAdmin::getPluginObject( + self::$PLUGIN_CTYPE, + self::$PLUGIN_CNAME, + self::$PLUGIN_SLOT_ID, + self::$PLUGIN_NAME + )); + } + + /** + * @return string + */ + public function getAdditionalDataTable() + { + return "rep_robj_xqsp_data"; + } + + /** + * @return string + */ + public function getQuestionSetTable() + { + return "rep_robj_xqsp_qs"; + } + + /** + * @param string $a_type + * @param string $a_size + * @return string + */ + public static function _getIcon($a_type, $a_size) + { + return ilPlugin::_getImagePath( + IL_COMP_SERVICE, + 'Repository', + 'robj', + ilPlugin::lookupNameForId(IL_COMP_SERVICE, 'Repository', 'robj', $a_type), + 'icon_' . $a_type . '.svg' + ); + } + + protected function uninstallCustom() + { + /** + * @var $ilDB ilDB + */ + global $ilDB; + + if ($ilDB->tableExists('rep_robj_xqsp_data')) { + $ilDB->dropTable('rep_robj_xqsp_data'); + } + + if ($ilDB->tableExists('rep_robj_xqsp_jmp_con')) { + $ilDB->dropTable('rep_robj_xqsp_jmp_con'); + } + if ($ilDB->sequenceExists('rep_robj_xqsp_jmp_con')) { + $ilDB->dropSequence('rep_robj_xqsp_jmp_con'); + } + + if ($ilDB->tableExists('rep_robj_xqsp_node')) { + $ilDB->dropTable('rep_robj_xqsp_node'); + } + if ($ilDB->sequenceExists('rep_robj_xqsp_node')) { + $ilDB->dropSequence('rep_robj_xqsp_node'); + } + + if ($ilDB->tableExists('rep_robj_xqsp_path')) { + $ilDB->dropTable('rep_robj_xqsp_path'); + } + if ($ilDB->sequenceExists('rep_robj_xqsp_path')) { + $ilDB->dropSequence('rep_robj_xqsp_path'); + } + + if ($ilDB->tableExists('rep_robj_xqsp_qs')) { + $ilDB->dropTable('rep_robj_xqsp_qs'); + } + if ($ilDB->sequenceExists('rep_robj_xqsp_qs')) { + $ilDB->dropSequence('rep_robj_xqsp_qs'); + } + + if ($ilDB->tableExists('rep_robj_xqsp_qs_qst')) { + $ilDB->dropTable('rep_robj_xqsp_qs_qst'); + } + } } diff --git a/classes/class.ilQuestionSetPoolXmlValidator.php b/classes/class.ilQuestionSetPoolXmlValidator.php index c819dd6a6cd38f6a711726ffbfcf939e5ea3651b..15ffbaeeed2286de3bbf16542aaa115d35c51d2b 100644 --- a/classes/class.ilQuestionSetPoolXmlValidator.php +++ b/classes/class.ilQuestionSetPoolXmlValidator.php @@ -6,280 +6,271 @@ */ class ilQuestionSetPoolXmlValidator { - /** - * - */ - const MODE_VALIDATION = 1; - /** - * - */ - const XSD_FILE = './Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/xml/xqsp_5_1.xsd'; - /** - * - */ - const NAME_SPACE_URI = 'http://www.ilias.de/Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool'; - /** - * - */ - const DOM_MISSING_NS_CODE = 1845; - - /** - * @var - */ - private $mode; - /** - * @var string - */ - private $schema; - /** - * @var - */ - private $xml; - - /** - * @var array - */ - private $assignments = array(); - /** - * @var array - */ - private $errors = array(); - /** - * @var bool - */ - private $has_errors = false; - - /** - * @var null - */ - protected $xml_file = NULL; - - /** - * @var null - */ - protected $xsd_file = NULL; - - /** - * @var string - */ - protected $error_message = ''; - - /** - * ilQuestionSetPoolXmlValidator constructor. - */ - public function __construct() - { - $this->schema = self::XSD_FILE; - } - - /** - * @return mixed - */ - public function getMode() - { - return $this->mode; - } - - /** - * @param mixed $mode - */ - public function setMode($mode) - { - $this->mode = $mode; - } - - /** - * @return string - */ - public function getSchema() - { - return $this->schema; - } - - /** - * @param string $schema - */ - public function setSchema($schema) - { - $this->schema = $schema; - } - - /** - * @return mixed - */ - public function getXml() - { - return $this->xml; - } - - /** - * @param mixed $xml - */ - public function setXml($xml) - { - $this->xml = $xml; - } - - /** - * @return array - */ - public function getAssignments() - { - return $this->assignments; - } - - /** - * @param array $assignments - */ - public function setAssignments($assignments) - { - $this->assignments = $assignments; - } - - /** - * @return array - */ - public function getErrors() - { - return $this->errors; - } - - /** - * @param array $errors - */ - public function setErrors($errors) - { - $this->errors = $errors; - } - - /** - * @return boolean - */ - public function isHasErrors() - { - return $this->has_errors; - } - - /** - * @param boolean $has_errors - */ - public function setHasErrors($has_errors) - { - $this->has_errors = $has_errors; - } - - /** - * @return null - */ - public function getXmlFile() - { - return $this->xml_file; - } - - /** - * @param null $xml_file - */ - public function setXmlFile($xml_file) - { - $this->xml_file = $xml_file; - } - - /** - * @return null - */ - public function getXsdFile() - { - return $this->xsd_file; - } - - /** - * @param null $xsd_file - */ - public function setXsdFile($xsd_file) - { - $this->xsd_file = $xsd_file; - } - - /** - * @return string - */ - public function getErrorMessage() - { - return $this->error_message; - } - - /** - * @param string $error_message - */ - public function setErrorMessage($error_message) - { - $this->error_message = $error_message; - } - - /** - * @return bool - */ - public function validate() - { - // validate against schema - $this->setXml(@file_get_contents($this->getXmlFile())); - - if(!$this->validateXml($this->getXml(), false)) - { - return true; - } - - if(is_array($this->errors) && count($this->errors)) - { - return false; - } - return true; - } - - /** - * validate xml string - * @param string $a_xml - * @param bool|false $a_add_default_namespace - * @return bool - */ - protected function validateXml($a_xml, $a_add_default_namespace = false) - { - ilLoggerFactory::getLogger('xqsp')->debug($a_xml); - - libxml_use_internal_errors(true); - $dom = new DOMDocument(); - $dom->loadXML($a_xml); - $dom->schemaValidate($this->getSchema()); - - foreach(libxml_get_errors() as $error) - { - ilLoggerFactory::getLogger('xqsp')->warning('XML schema validation failed: ' . $error->line.': '. $error->message); - - /* @var $error LibXMLError */ - if($error->code == self::DOM_MISSING_NS_CODE) - { - if(!$a_add_default_namespace) - { - // add default namespace to xml - $xml = simplexml_load_string($a_xml); - $xml->addAttribute('xmlns', self::NAME_SPACE_URI); - $xml->saveXml(); - ilLoggerFactory::getLogger('xqsp')->debug('Starting second validation with default namespace'); - libxml_clear_errors(); - return $this->validateXml($xml->asXML(), true); - } - } - else - { - $this->errors[] = $error->line.': '.$error->message; - } - } - libxml_clear_errors(); - if(is_array($this->errors) && count($this->errors)) - { - return false; - } - return true; - - } -} \ No newline at end of file + /** + * + */ + const MODE_VALIDATION = 1; + /** + * + */ + const XSD_FILE = './Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/xml/xqsp_5_1.xsd'; + /** + * + */ + const NAME_SPACE_URI = 'http://www.ilias.de/Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool'; + /** + * + */ + const DOM_MISSING_NS_CODE = 1845; + + /** + * @var + */ + private $mode; + /** + * @var string + */ + private $schema; + /** + * @var + */ + private $xml; + + /** + * @var array + */ + private $assignments = array(); + /** + * @var array + */ + private $errors = array(); + /** + * @var bool + */ + private $has_errors = false; + + /** + * @var null + */ + protected $xml_file = null; + + /** + * @var null + */ + protected $xsd_file = null; + + /** + * @var string + */ + protected $error_message = ''; + + /** + * ilQuestionSetPoolXmlValidator constructor. + */ + public function __construct() + { + $this->schema = self::XSD_FILE; + } + + /** + * @return mixed + */ + public function getMode() + { + return $this->mode; + } + + /** + * @param mixed $mode + */ + public function setMode($mode) + { + $this->mode = $mode; + } + + /** + * @return string + */ + public function getSchema() + { + return $this->schema; + } + + /** + * @param string $schema + */ + public function setSchema($schema) + { + $this->schema = $schema; + } + + /** + * @return mixed + */ + public function getXml() + { + return $this->xml; + } + + /** + * @param mixed $xml + */ + public function setXml($xml) + { + $this->xml = $xml; + } + + /** + * @return array + */ + public function getAssignments() + { + return $this->assignments; + } + + /** + * @param array $assignments + */ + public function setAssignments($assignments) + { + $this->assignments = $assignments; + } + + /** + * @return array + */ + public function getErrors() + { + return $this->errors; + } + + /** + * @param array $errors + */ + public function setErrors($errors) + { + $this->errors = $errors; + } + + /** + * @return boolean + */ + public function isHasErrors() + { + return $this->has_errors; + } + + /** + * @param boolean $has_errors + */ + public function setHasErrors($has_errors) + { + $this->has_errors = $has_errors; + } + + /** + * @return null + */ + public function getXmlFile() + { + return $this->xml_file; + } + + /** + * @param null $xml_file + */ + public function setXmlFile($xml_file) + { + $this->xml_file = $xml_file; + } + + /** + * @return null + */ + public function getXsdFile() + { + return $this->xsd_file; + } + + /** + * @param null $xsd_file + */ + public function setXsdFile($xsd_file) + { + $this->xsd_file = $xsd_file; + } + + /** + * @return string + */ + public function getErrorMessage() + { + return $this->error_message; + } + + /** + * @param string $error_message + */ + public function setErrorMessage($error_message) + { + $this->error_message = $error_message; + } + + /** + * @return bool + */ + public function validate() + { + // validate against schema + $this->setXml(@file_get_contents($this->getXmlFile())); + + if (!$this->validateXml($this->getXml(), false)) { + return true; + } + + if (is_array($this->errors) && count($this->errors)) { + return false; + } + return true; + } + + /** + * validate xml string + * @param string $a_xml + * @param bool|false $a_add_default_namespace + * @return bool + */ + protected function validateXml($a_xml, $a_add_default_namespace = false) + { + ilLoggerFactory::getLogger('xqsp')->debug($a_xml); + + libxml_use_internal_errors(true); + $dom = new DOMDocument(); + $dom->loadXML($a_xml); + $dom->schemaValidate($this->getSchema()); + + foreach (libxml_get_errors() as $error) { + ilLoggerFactory::getLogger('xqsp')->warning('XML schema validation failed: ' . $error->line . ': ' . $error->message); + + /* @var $error LibXMLError */ + if ($error->code == self::DOM_MISSING_NS_CODE) { + if (!$a_add_default_namespace) { + // add default namespace to xml + $xml = simplexml_load_string($a_xml); + $xml->addAttribute('xmlns', self::NAME_SPACE_URI); + $xml->saveXml(); + ilLoggerFactory::getLogger('xqsp')->debug('Starting second validation with default namespace'); + libxml_clear_errors(); + return $this->validateXml($xml->asXML(), true); + } + } else { + $this->errors[] = $error->line . ': ' . $error->message; + } + } + libxml_clear_errors(); + if (is_array($this->errors) && count($this->errors)) { + return false; + } + return true; + } +} diff --git a/classes/controllers/abstract.ilPluginControllerFormGUI.php b/classes/controllers/abstract.ilPluginControllerFormGUI.php index 9900018696b162c3437d9fbcbddbec706a6c5bb6..0da19614788cbff574ef893945d6d53ba10c868d 100644 --- a/classes/controllers/abstract.ilPluginControllerFormGUI.php +++ b/classes/controllers/abstract.ilPluginControllerFormGUI.php @@ -8,77 +8,76 @@ require_once "abstract.ilPluginControllerGUI.php"; * Date: 02.10.13 * Time: 15:10 * @author Thomas Joußen - */ + */ abstract class ilPluginControllerFormGUI extends ilPluginControllerGUI { - /** - * @var ilPropertyFormGUI - */ - protected $form; + /** + * @var ilPropertyFormGUI + */ + protected $form; - public function edit() - { - $model = $this->loadModel(); - $this->initForm($model); - $this->bindModelToForm($model); - $this->tpl->setContent($this->form->getHTML()); - } + public function edit() + { + $model = $this->loadModel(); + $this->initForm($model); + $this->bindModelToForm($model); + $this->tpl->setContent($this->form->getHTML()); + } - public function update() - { - $model = $this->loadModel(); - $this->initForm($model); - if($this->form->checkInput()) - { - $model->bindForm($this->form); - $model->update(); - ilUtil::sendSuccess($this->plugin->txt("msg_obj_modified"), true); - $this->redirect( - $this->getAfterUpdateRedirectCmd(), - $this->getAfterUpdateRedirectParams($model) - ); - } + public function update() + { + $model = $this->loadModel(); + $this->initForm($model); + if ($this->form->checkInput()) { + $model->bindForm($this->form); + $model->update(); + ilUtil::sendSuccess($this->plugin->txt("msg_obj_modified"), true); + $this->redirect( + $this->getAfterUpdateRedirectCmd(), + $this->getAfterUpdateRedirectParams($model) + ); + } - $this->form->setValuesByPost(); - $this->tpl->setContent($this->form->getHTML()); - } + $this->form->setValuesByPost(); + $this->tpl->setContent($this->form->getHTML()); + } - /** - * @param ilPluginModelInterface $model - */ - protected function bindModelToForm(ilPluginModelInterface $model) - { - $this->form->setValuesByArray($model->toArray()); - } + /** + * @param ilPluginModelInterface $model + */ + protected function bindModelToForm(ilPluginModelInterface $model) + { + $this->form->setValuesByArray($model->toArray()); + } - /** - * Loads and returns the Model for the controller gui - * - * @return ilPluginModelInterface - */ - abstract protected function loadModel(); + /** + * Loads and returns the Model for the controller gui + * + * @return ilPluginModelInterface + */ + abstract protected function loadModel(); - /** - * Initialize the PropertyFormGUI for this controller - * - * @param ilPluginModel $model - * - * @return mixed - */ - abstract protected function initForm($model); + /** + * Initialize the PropertyFormGUI for this controller + * + * @param ilPluginModel $model + * + * @return mixed + */ + abstract protected function initForm($model); - /** - * Get the redirect action after an update was successful - * - * @return string - */ - abstract protected function getAfterUpdateRedirectCmd(); + /** + * Get the redirect action after an update was successful + * + * @return string + */ + abstract protected function getAfterUpdateRedirectCmd(); - /** - * @param $model - * - * @return array - */ - abstract protected function getAfterUpdateRedirectParams($model); + /** + * @param $model + * + * @return array + */ + abstract protected function getAfterUpdateRedirectParams($model); } diff --git a/classes/controllers/abstract.ilPluginControllerGUI.php b/classes/controllers/abstract.ilPluginControllerGUI.php index a832906fd694215884f52c924355a51e45f74e9d..47558ebc7b08359f822ebfe4952b6a385983ec75 100644 --- a/classes/controllers/abstract.ilPluginControllerGUI.php +++ b/classes/controllers/abstract.ilPluginControllerGUI.php @@ -8,137 +8,140 @@ require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/ * Date: 23.09.13 * Time: 14:10 * @author Thomas Joußen - */ -abstract class ilPluginControllerGUI { - - /** - * The main Controller of the Plugin - * - * @var ilObjQuestionSetPoolGUI - */ - public $controller; - - /** - * @var ilCtrl - */ - public $ctrl; - - /** - * @var ilToolbarGUI; - */ - protected $toolbar; - - /** - * @var ilTemplate - */ - protected $tpl; - - /** - * @var iPlugin - */ - protected $plugin; - - /** - * @var ilLanguage - */ - protected $lng; - - /** - * @var ilTabsGUI - */ - protected $tabs; - - /** - * @var ilObjUser - */ - protected $user; - - /** - * @param ilObjQuestionSetPoolGUI $controller - */ - public function __construct(ilObjQuestionSetPoolGUI $controller) - { - global $DIC; - - $this->controller = $controller; - $this->ctrl = $DIC->ctrl(); - $this->tpl = $DIC->ui()->mainTemplate(); - $this->plugin = $this->controller->plugin; - $this->lng = $DIC->language(); - $this->toolbar = $DIC->toolbar(); - $this->tabs = $DIC->tabs(); - $this->user = $DIC->user(); - $this->activateTab(); - $this->includeRequirements(); - } - - protected function initToolbar() - { - $this->toolbar->setFormAction($this->ctrl->getFormAction($this->controller)); - } - - protected function addToolbarButton($text, $command, array $params = array()) - { - if($this->toolbar == null) - { - $this->initToolbar(); - } - - foreach($params as $key => $param) - { - $this->ctrl->setParameter($this->controller, $key, $param); - } - - $link = $this->ctrl->getLinkTarget($this->controller, $command); - - foreach($params as $key => $param) - { - $this->ctrl->setParameter($this->controller, $key, ""); - } - - $this->toolbar->addButton($this->plugin->txt($text),$link); - } - - /** - * Activates the tab for the current GUI - */ - private function activateTab() - { - $this->tabs->activateTab($this->getCurrentTab()); - } - - private function includeRequirements() - { - $requirements = $this->getRequirements(); - - if(!empty($requirements)) - { - foreach($requirements as $requirement) - { - require_once $this->controller->plugin->getDirectory().DIRECTORY_SEPARATOR."classes".DIRECTORY_SEPARATOR.$requirement; - } - } - } - - protected function redirect($command, $params = array()) - { - foreach($params as $key => $param) - { - $this->ctrl->setParameter($this->controller, $key, $param); - } - - $this->ctrl->redirect($this->controller, $command); - } - - /** - * Returns the current tab name - * - * return string - */ - abstract protected function getCurrentTab(); - - /** - * @return array - */ - abstract protected function getRequirements(); + */ +abstract class ilPluginControllerGUI +{ + + /** + * The main Controller of the Plugin + * + * @var ilObjQuestionSetPoolGUI + */ + public $controller; + + /** + * @var ilCtrl + */ + public $ctrl; + + /** + * @var ilToolbarGUI; + */ + protected $toolbar; + + /** + * @var ilTemplate + */ + protected $tpl; + + /** + * @var ilPlugin + */ + protected $plugin; + + /** + * @var ilLanguage + */ + protected $lng; + + /** + * @var ilTabsGUI + */ + protected $tabs; + + /** + * @var ilObjUser + */ + protected $user; + + /** @var \ILIAS\UI\Factory */ + protected $uiFactory; + /** @var \ILIAS\UI\Renderer */ + protected $uiRenderer; + + /** + * @param ilObjQuestionSetPoolGUI $controller + */ + public function __construct(ilObjQuestionSetPoolGUI $controller) + { + global $DIC; + + $this->controller = $controller; + $this->ctrl = $DIC->ctrl(); + $this->tpl = $DIC->ui()->mainTemplate(); + $this->plugin = $this->controller->plugin; + $this->lng = $DIC->language(); + $this->toolbar = $DIC->toolbar(); + $this->tabs = $DIC->tabs(); + $this->user = $DIC->user(); + $this->uiFactory = $DIC->ui()->factory(); + $this->uiRenderer = $DIC->ui()->renderer(); + + $this->activateTab(); + $this->includeRequirements(); + } + + protected function initToolbar() + { + $this->toolbar->setFormAction($this->ctrl->getFormAction($this->controller)); + } + + protected function addToolbarButton($text, $command, array $params = array()) + { + if ($this->toolbar == null) { + $this->initToolbar(); + } + + foreach ($params as $key => $param) { + $this->ctrl->setParameter($this->controller, $key, $param); + } + + $link = $this->ctrl->getLinkTarget($this->controller, $command); + + foreach ($params as $key => $param) { + $this->ctrl->setParameter($this->controller, $key, ""); + } + + $this->toolbar->addButton($this->plugin->txt($text), $link); + } + + /** + * Activates the tab for the current GUI + */ + private function activateTab() + { + $this->tabs->activateTab($this->getCurrentTab()); + } + + private function includeRequirements() + { + $requirements = $this->getRequirements(); + + if (!empty($requirements)) { + foreach ($requirements as $requirement) { + require_once $this->controller->plugin->getDirectory() . DIRECTORY_SEPARATOR . "classes" . DIRECTORY_SEPARATOR . $requirement; + } + } + } + + protected function redirect($command, $params = array()) + { + foreach ($params as $key => $param) { + $this->ctrl->setParameter($this->controller, $key, $param); + } + + $this->ctrl->redirect($this->controller, $command); + } + + /** + * Returns the current tab name + * + * return string + */ + abstract protected function getCurrentTab(); + + /** + * @return array + */ + abstract protected function getRequirements(); } diff --git a/classes/controllers/abstract.ilPluginControllerTableGUI.php b/classes/controllers/abstract.ilPluginControllerTableGUI.php index bbadb40356f796cbce173f31b2a0af320aac94bd..9ecdef38364866e4254a77c391ef9b0908599012 100644 --- a/classes/controllers/abstract.ilPluginControllerTableGUI.php +++ b/classes/controllers/abstract.ilPluginControllerTableGUI.php @@ -8,17 +8,17 @@ require_once "abstract.ilPluginControllerGUI.php"; * Date: 02.10.13 * Time: 15:11 * @author Thomas Joußen - */ + */ abstract class ilPluginControllerTableGUI extends ilPluginControllerGUI { - /** - * @param string $key - * - * @return bool - */ - protected function dataSelected($key) - { - return (isset($_POST[$key]) && (is_array($_POST[$key]) && count($_POST[$key]) > 0)); - } + /** + * @param string $key + * + * @return bool + */ + protected function dataSelected($key) + { + return (isset($_POST[$key]) && (is_array($_POST[$key]) && count($_POST[$key]) > 0)); + } } diff --git a/classes/controllers/abstract.ilQuestionSetPoolConditionGUI.php b/classes/controllers/abstract.ilQuestionSetPoolConditionGUI.php index 8887ffda9863583ecbecda262e0d00dd6e9a03d1..cbfdfacaa0ce9efb16080dc1448758459e1ebad0 100644 --- a/classes/controllers/abstract.ilQuestionSetPoolConditionGUI.php +++ b/classes/controllers/abstract.ilQuestionSetPoolConditionGUI.php @@ -10,71 +10,65 @@ require_once "Customizing/global/plugins/Services/Repository/RepositoryObject/Qu * Date: 11.02.14 * Time: 10:39 * @author Thomas Joußen - */ + */ abstract class ilQuestionSetPoolConditionGUI extends ilPluginControllerFormGUI { + public function showPreview() + { + $gui = assQuestion::instantiateQuestionGUI((int) $_GET["question_id"]); + $gui->setTargetGuiClass("ilObjQuestionSetPoolGUI"); + $gui->setQuestionHeaderBlockBuilder(new ilQuestionSetPoolQuestionHeaderBuilder($gui->object->getTitle)); + echo $gui->getPreview(); + exit; + } - public function showPreview() - { - $gui = assQuestion::instantiateQuestionGUI((int)$_GET["question_id"]); - $gui->setTargetGuiClass("ilObjQuestionSetPoolGUI"); - $gui->setQuestionHeaderBlockBuilder(new ilQuestionSetPoolQuestionHeaderBuilder($gui->object->getTitle)); - echo $gui->getPreview(); - exit; - } + /** + * + */ + public function afterQuestionChanged() + { + $template = new ilTemplate('tpl.il_xqsp_after_question_changed.html', false, false, 'Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool'); + $this->tpl->setContent($template->get()); + } - /** - * - */ - public function afterQuestionChanged() - { - $template = new ilTemplate('tpl.il_xqsp_after_question_changed.html', FALSE, FALSE, 'Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool'); - $this->tpl->setContent($template->get()); - } + /** + * @param ilQuestionSetPoolNode $model + * @param ilTemplate $template + */ + protected function renderQuestionInfo($model, $template) + { + $questions = $model->getPath()->getQuestionsLowerAndEqualsIndex($model->getIndex()); - /** - * @param ilQuestionSetPoolNode $model - * @param ilTemplate $template - */ - protected function renderQuestionInfo($model, $template) - { - $questions = $model->getPath()->getQuestionsLowerAndEqualsIndex($model->getIndex()); + $this->controller->populateContentStyleBlock(); + $this->controller->populateSyntaxStyleBlock(); - $this->controller->populateContentStyleBlock(); - $this->controller->populateSyntaxStyleBlock(); + $mathJaxSetting = new ilSetting("MathJax"); + if ($mathJaxSetting->get("enable")) { + $this->controller->tpl->addJavaScript($mathJaxSetting->get("path_to_mathjax")); + } - include_once "./Services/Administration/classes/class.ilSetting.php"; - $mathJaxSetting = new ilSetting("MathJax"); - if($mathJaxSetting->get("enable")) - { - $this->controller->tpl->addJavaScript($mathJaxSetting->get("path_to_mathjax")); - } + foreach ($questions as $key => $question_data) { + $params = array( + 'node_id' => (int) $_GET['node_id'], + 'cmd' => get_class($this) . '.afterQuestionChanged' + ); + $edit = 'ilias.php?consumer_context=' . base64_encode(json_encode($params)) . '&baseClass=ilObjQuestionPoolGUI&ref_id=' . $this->controller->object->getRefId() . '&cmd=editQuestionForTest&calling_consumer=' . $this->controller->object->getRefId() . '&q_id=' . $question_data["question_id"]; - foreach ($questions as $key => $question_data) - { - $params = array( - 'node_id' => (int)$_GET['node_id'], - 'cmd' => get_class($this) . '.afterQuestionChanged' - ); - $edit = 'ilias.php?consumer_context=' . base64_encode(json_encode($params)) . '&baseClass=ilObjQuestionPoolGUI&ref_id=' . $this->controller->object->getRefId().'&cmd=editQuestionForTest&calling_consumer=' . $this->controller->object->getRefId() . '&q_id=' . $question_data["question_id"]; + $template->setCurrentBlock("question_row"); + $template->setVariable("CSS_ROW", "tblrow" . $key % 2); + $template->setVariable("QUESTION_INDEX", "Q" . $question_data["question_index"]); + $template->setVariable("QUESTION_ID", $question_data["question_id"]); + $template->setVariable("PREVIEW", $this->lng->txt("preview")); + $template->setVariable("EDIT_LINK", $edit); + $template->setVariable("EDIT", $this->lng->txt("edit")); + $template->setVariable("QUESTION_TITLE", $question_data["title"]); + $template->parseCurrentBlock(); + } - $template->setCurrentBlock("question_row"); - $template->setVariable("CSS_ROW", "tblrow" . $key % 2); - $template->setVariable("QUESTION_INDEX", "Q" . $question_data["question_index"]); - $template->setVariable("QUESTION_ID", $question_data["question_id"]); - $template->setVariable("PREVIEW", $this->lng->txt("preview")); - $template->setVariable("EDIT_LINK", $edit); - $template->setVariable("EDIT", $this->lng->txt("edit")); - $template->setVariable("QUESTION_TITLE", $question_data["title"]); - $template->parseCurrentBlock(); - } - - $template->setVariable("TXT_QUESTION", $this->controller->lng->txt('question')); - $template->setVariable("TXT_ACTIONS", $this->controller->lng->txt('actions')); - $template->setVariable("PREVIEW_LINK", $this->ctrl->getLinkTarget($this->controller, get_class($this) . ".showPreview", "", true)); - include_once "Services/UIComponent/Glyph/classes/class.ilGlyphGUI.php"; - $template->setVariable('CLOSE_IMG_SRC', ilGlyphGUI::get(ilGlyphGUI::CLOSE)); - $template->setVariable('CLOSE_IMG_ALT', $this->controller->lng->txt('close')); - } + $template->setVariable("TXT_QUESTION", $this->controller->lng->txt('question')); + $template->setVariable("TXT_ACTIONS", $this->controller->lng->txt('actions')); + $template->setVariable("PREVIEW_LINK", $this->ctrl->getLinkTarget($this->controller, get_class($this) . ".showPreview", "", true)); + $template->setVariable('CLOSE_IMG_SRC', ilGlyphGUI::get(ilGlyphGUI::CLOSE)); + $template->setVariable('CLOSE_IMG_ALT', $this->controller->lng->txt('close')); + } } - diff --git a/classes/controllers/class.ilQuestionSetPoolInitialConditionGUI.php b/classes/controllers/class.ilQuestionSetPoolInitialConditionGUI.php index a371b8cecca1fed22a45e3cecedaead86ad9da03..b23e709385d8ddc3e8563dfc281306ceb4c050dd 100644 --- a/classes/controllers/class.ilQuestionSetPoolInitialConditionGUI.php +++ b/classes/controllers/class.ilQuestionSetPoolInitialConditionGUI.php @@ -8,273 +8,254 @@ require_once "abstract.ilQuestionSetPoolConditionGUI.php"; * Date: 21.11.13 * Time: 14:15 * @author Thomas Joußen - */ + */ class ilQuestionSetPoolInitialConditionGUI extends ilQuestionSetPoolConditionGUI { - /** - * @var array $feedback_types needed for tiny-mce - */ - protected $feedback_types = array( - 0 => array('post_var' => 'true_feedback', 'obj_type' => 'itf'), - 2 => array('post_var' => 'false_feedback', 'obj_type' => 'iff')); - - public function edit() - { - include_once 'Services/jQuery/classes/class.iljQueryUtil.php'; - iljQueryUtil::initjQuery(); - include_once 'Services/YUI/classes/class.ilYuiUtil.php'; - ilYuiUtil::initPanel(); - ilYuiUtil::initOverlay(); - $this->tpl->addJavascript('./Services/UIComponent/Overlay/js/ilOverlay.js'); - $this->tpl->addJavaScript("./Services/JavaScript/js/Basic.js"); - - $model = $this->loadModel(); - $this->initForm($model); - $this->bindModelToForm($model); - - $template = new ilTemplate("tpl.il_xqsp_condition.html", true, true, "Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool"); - - $this->renderQuestionInfo($model, $template); - - $template->setVariable("FORM", $this->form->getHTML()); - $template->setVariable("INFO", ilQuestionSetPoolInfoBox::render($this->plugin)); - - require_once 'Services/UIComponent/Button/classes/class.ilLinkButton.php'; - $button = ilLinkButton::getInstance(); - $button->addCSSClass('toggle_feedback'); - $button->setCaption($this->plugin->txt('hide_feedback_form_parts'), false); - $this->toolbar->addButtonInstance($button); - $template->setVariable("TXT_SHOW_FEEDBACK", $this->plugin->txt('show_feedback_form_parts')); - $template->setVariable("TXT_HIDE_FEEDBACK", $this->plugin->txt('hide_feedback_form_parts')); - - $this->tpl->setContent($template->get()); - } - - public function update() - { - $model = $this->loadModel(); - $this->initForm($model); - if($this->form->checkInput()) - { - $model->bindForm($this->form); - - $isValid = ilQuestionSetPoolConditionValidator::isValid( - $model->getInitialCondition(), - $model, - $model->getPath()->getNodes()->getData(), - $this->plugin - ); - - if($isValid) - { - $model->update(); - - $this->copyTemporaryMobs($model); - $this->deleteUnusedMobs($model); - - ilUtil::sendSuccess($this->plugin->txt("msg_obj_modified"), true); - $this->redirect( - $this->getAfterUpdateRedirectCmd(), - $this->getAfterUpdateRedirectParams($model) - ); - } - } - - $this->form->setValuesByPost(); - - $template = new ilTemplate("tpl.il_xqsp_condition.html", true, true, "Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool"); - - $this->renderQuestionInfo($model, $template); - - $template->setVariable("FORM", $this->form->getHTML()); - $template->setVariable("INFO", ilQuestionSetPoolInfoBox::render($this->plugin)); - - $this->tpl->setContent($template->get()); - } - - public function remove() - { - $model = $this->loadModel(); - $model->read(); - $model->setInitialCondition(null); - $model->update(); - - ilUtil::sendSuccess($this->plugin->txt("msg_obj_modified"), true); - $this->redirect( - $this->getAfterUpdateRedirectCmd(), - $this->getAfterUpdateRedirectParams($model) - ); - } - - - /** - * Loads and returns the Model for the controller gui - * @return ilQuestionSetPoolNode - */ - protected function loadModel() - { - $id = (isset($_GET['node_id']))? (int)$_GET['node_id'] : (int)$_POST['id']; - $model = new ilQuestionSetPoolNode($id); - $model->read(); - - return $model; - } - - /** - * Initialize the PropertyFormGUI for this controller - * - * @param $model ilQuestionSetPoolNode - */ - protected function initForm($model) - { - require_once "./Services/Form/classes/class.ilPropertyFormGUI.php"; - - $this->form = new ilPropertyFormGUI(); - $this->form->setName('condition_form'); - $this->form->setTableWidth("100%"); - $this->form->setTitle(sprintf( - $this->plugin->txt("edit_initial_condition_title"), - $model->getPath()->getSet()->getTitle(), - $model->getPath()->getTitle(), - $model->getIndex() - )); - - $node_id = new ilHiddenInputGUI("id"); - $node_id->setRequired(true); - - $initial_condition = new ilConditionInputGUI($this->plugin->txt("initial_condition"), "initial_condition"); - $initial_condition->setInlineStyle('width:95%'); - $initial_condition->setRequired(false); - - $this->form->addItem($node_id); - $this->form->addItem($initial_condition); - - $true_feedback = new ilTextAreaInputGUI($this->plugin->txt('true_feedback'), 'true_feedback'); - $true_feedback->setUseRte(TRUE); - $true_feedback->addPlugin("latex"); - $true_feedback->addButton("latex"); - $true_feedback->setRTESupport($model->getId(), 'x_itf:html', 'assessment'); - $true_feedback->setRteTagSet('full'); - $this->form->addItem($true_feedback); - - $false_feedback = new ilTextAreaInputGUI($this->plugin->txt('false_feedback'), 'false_feedback'); - $false_feedback->setUseRte(TRUE); - $false_feedback->addPlugin("latex"); - $false_feedback->addButton("latex"); - $false_feedback->setRTESupport($model->getId(), 'x_iff:html', 'assessment'); - $false_feedback->setInfo($this->plugin->txt('false_feedback_info')); - - $false_feedback->setRteTagSet('full'); - $this->form->addItem($false_feedback); - - $this->ctrl->setParameter($this->controller, "path_id", $model->getPath()->getId()); - $this->ctrl->setParameter($this->controller, "set_id", $model->getPath()->getSet()->getId()); - $this->form->setFormAction($this->ctrl->getFormAction($this->controller)); - $this->ctrl->setParameter($this->controller, "path_id", ""); - $this->ctrl->setParameter($this->controller, "set_id", ""); - $this->form->addCommandButton("ilQuestionSetPoolInitialConditionGUI.update", $this->plugin->txt("save")); - $this->form->addCommandButton("ilQuestionSetPoolNodesGUI.listNodes", $this->plugin->txt("cancel")); - } - - /** - * Get the redirect action after an update was successful - * @return string - */ - protected function getAfterUpdateRedirectCmd() - { - return "ilQuestionSetPoolNodesGUI.listNodes"; - } - - /** - * @param $model - * - * @return array - */ - protected function getAfterUpdateRedirectParams($model) - { - return array( - "set_id" => $model->getPath()->getSet()->getId(), - "path_id" => $model->getPath()->getId() - ); - } - - /** - * Returns the current tab name - * return string - */ - protected function getCurrentTab() - { - return "content"; - } - - /** - * @return array - */ - protected function getRequirements() - { - return array( - "models/class.ilQuestionSetPoolNode.php", - "providers/class.ilParserQuestionProvider.php", - "utils/abstract.ilQuestionSetPoolInfoBox.php", - "utils/abstract.ilQuestionSetPoolConditionValidator.php", - "utils/class.ilConditionInputGUI.php" - ); - } - - protected function copyTemporaryMobs($model) - { - global $DIC; - $ilUser = $DIC->user(); - - foreach($this->feedback_types as $type) - { - $mediaObjects = ilRTE::_getMediaObjects($this->form->getInput($type['post_var']), 0); - $myMediaObjects = ilObjMediaObject::_getMobsOfObject('x_'.$type['obj_type'].':html', $ilUser->getId()); - foreach($mediaObjects as $mob) - { - foreach($myMediaObjects as $myMob) - { - if($mob == $myMob) - { - // change usage - ilObjMediaObject::_removeUsage($mob, 'x_'.$type['obj_type'].':html', $ilUser->getId()); - break; - } - } - ilObjMediaObject::_saveUsage($mob, 'x_'.$type['obj_type'].':html', $model->getId()); - } - } - } - - protected function deleteUnusedMobs($model) - { - foreach($this->feedback_types as $type) - { - // remove usage of deleted media objects - include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php'; - $oldMediaObjects = ilObjMediaObject::_getMobsOfObject('x_'.$type['obj_type'].':html', $model->getId()); - $curMediaObjects = ilRTE::_getMediaObjects($this->form->getInput($type['post_var']), 0); - foreach($oldMediaObjects as $oldMob) - { - $found = false; - foreach($curMediaObjects as $curMob) - { - if($oldMob == $curMob) - { - $found = true; - break; - } - } - if(!$found) - { - if(ilObjMediaObject::_exists($oldMob)) - { - ilObjMediaObject::_removeUsage($oldMob, 'x_'.$type['obj_type'].':html', $model->getId()); - $mob_obj = new ilObjMediaObject($oldMob); - $mob_obj->delete(); - } - } - } - } - } + /** + * @var array $feedback_types needed for tiny-mce + */ + protected $feedback_types = array( + 0 => array('post_var' => 'true_feedback', 'obj_type' => 'itf'), + 2 => array('post_var' => 'false_feedback', 'obj_type' => 'iff')); + + public function edit() + { + iljQueryUtil::initjQuery(); + ilYuiUtil::initPanel(); + ilYuiUtil::initOverlay(); + $this->tpl->addJavascript('./Services/UIComponent/Overlay/js/ilOverlay.js'); + $this->tpl->addJavaScript("./Services/JavaScript/js/Basic.js"); + + $model = $this->loadModel(); + $this->initForm($model); + $this->bindModelToForm($model); + + $template = new ilTemplate("tpl.il_xqsp_condition.html", true, true, "Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool"); + + $this->renderQuestionInfo($model, $template); + + $template->setVariable("FORM", $this->form->getHTML()); + $template->setVariable("INFO", ilQuestionSetPoolInfoBox::render($this->plugin)); + + $button = ilLinkButton::getInstance(); + $button->addCSSClass('toggle_feedback'); + $button->setCaption($this->plugin->txt('hide_feedback_form_parts'), false); + $this->toolbar->addButtonInstance($button); + $template->setVariable("TXT_SHOW_FEEDBACK", $this->plugin->txt('show_feedback_form_parts')); + $template->setVariable("TXT_HIDE_FEEDBACK", $this->plugin->txt('hide_feedback_form_parts')); + + $this->tpl->setContent($template->get()); + } + + public function update() + { + $model = $this->loadModel(); + $this->initForm($model); + if ($this->form->checkInput()) { + $model->bindForm($this->form); + + $isValid = ilQuestionSetPoolConditionValidator::isValid( + $model->getInitialCondition(), + $model, + $model->getPath()->getNodes()->getData(), + $this->plugin + ); + + if ($isValid) { + $model->update(); + + $this->copyTemporaryMobs($model); + $this->deleteUnusedMobs($model); + + ilUtil::sendSuccess($this->plugin->txt("msg_obj_modified"), true); + $this->redirect( + $this->getAfterUpdateRedirectCmd(), + $this->getAfterUpdateRedirectParams($model) + ); + } + } + + $this->form->setValuesByPost(); + + $template = new ilTemplate("tpl.il_xqsp_condition.html", true, true, "Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool"); + + $this->renderQuestionInfo($model, $template); + + $template->setVariable("FORM", $this->form->getHTML()); + $template->setVariable("INFO", ilQuestionSetPoolInfoBox::render($this->plugin)); + + $this->tpl->setContent($template->get()); + } + + public function remove() + { + $model = $this->loadModel(); + $model->read(); + $model->setInitialCondition(null); + $model->update(); + + ilUtil::sendSuccess($this->plugin->txt("msg_obj_modified"), true); + $this->redirect( + $this->getAfterUpdateRedirectCmd(), + $this->getAfterUpdateRedirectParams($model) + ); + } + + + /** + * Loads and returns the Model for the controller gui + * @return ilQuestionSetPoolNode + */ + protected function loadModel() + { + $id = (isset($_GET['node_id']))? (int) $_GET['node_id'] : (int) $_POST['id']; + $model = new ilQuestionSetPoolNode($id); + $model->read(); + + return $model; + } + + /** + * Initialize the PropertyFormGUI for this controller + * + * @param $model ilQuestionSetPoolNode + */ + protected function initForm($model) + { + $this->form = new ilPropertyFormGUI(); + $this->form->setName('condition_form'); + $this->form->setTableWidth("100%"); + $this->form->setTitle(sprintf( + $this->plugin->txt("edit_initial_condition_title"), + $model->getPath()->getSet()->getTitle(), + $model->getPath()->getTitle(), + $model->getIndex() + )); + + $node_id = new ilHiddenInputGUI("id"); + $node_id->setRequired(true); + + $initial_condition = new ilConditionInputGUI($this->plugin->txt("initial_condition"), "initial_condition"); + $initial_condition->setInlineStyle('width:95%'); + $initial_condition->setRequired(false); + + $this->form->addItem($node_id); + $this->form->addItem($initial_condition); + + $true_feedback = new ilTextAreaInputGUI($this->plugin->txt('true_feedback'), 'true_feedback'); + $true_feedback->setUseRte(true); + $true_feedback->addPlugin("latex"); + $true_feedback->addButton("latex"); + $true_feedback->setRTESupport($model->getId(), 'x_itf:html', 'assessment'); + $true_feedback->setRteTagSet('full'); + $this->form->addItem($true_feedback); + + $false_feedback = new ilTextAreaInputGUI($this->plugin->txt('false_feedback'), 'false_feedback'); + $false_feedback->setUseRte(true); + $false_feedback->addPlugin("latex"); + $false_feedback->addButton("latex"); + $false_feedback->setRTESupport($model->getId(), 'x_iff:html', 'assessment'); + $false_feedback->setInfo($this->plugin->txt('false_feedback_info')); + + $false_feedback->setRteTagSet('full'); + $this->form->addItem($false_feedback); + + $this->ctrl->setParameter($this->controller, "path_id", $model->getPath()->getId()); + $this->ctrl->setParameter($this->controller, "set_id", $model->getPath()->getSet()->getId()); + $this->form->setFormAction($this->ctrl->getFormAction($this->controller)); + $this->ctrl->setParameter($this->controller, "path_id", ""); + $this->ctrl->setParameter($this->controller, "set_id", ""); + $this->form->addCommandButton("ilQuestionSetPoolInitialConditionGUI.update", $this->plugin->txt("save")); + $this->form->addCommandButton("ilQuestionSetPoolNodesGUI.listNodes", $this->plugin->txt("cancel")); + } + + /** + * Get the redirect action after an update was successful + * @return string + */ + protected function getAfterUpdateRedirectCmd() + { + return "ilQuestionSetPoolNodesGUI.listNodes"; + } + + /** + * @param $model + * + * @return array + */ + protected function getAfterUpdateRedirectParams($model) + { + return array( + "set_id" => $model->getPath()->getSet()->getId(), + "path_id" => $model->getPath()->getId() + ); + } + + /** + * Returns the current tab name + * return string + */ + protected function getCurrentTab() + { + return "content"; + } + + /** + * @return array + */ + protected function getRequirements() + { + return array( + "models/class.ilQuestionSetPoolNode.php", + "providers/class.ilParserQuestionProvider.php", + "utils/abstract.ilQuestionSetPoolInfoBox.php", + "utils/abstract.ilQuestionSetPoolConditionValidator.php", + "utils/class.ilConditionInputGUI.php" + ); + } + + protected function copyTemporaryMobs($model) + { + global $DIC; + $ilUser = $DIC->user(); + + foreach ($this->feedback_types as $type) { + $mediaObjects = ilRTE::_getMediaObjects($this->form->getInput($type['post_var']), 0); + $myMediaObjects = ilObjMediaObject::_getMobsOfObject('x_' . $type['obj_type'] . ':html', $ilUser->getId()); + foreach ($mediaObjects as $mob) { + foreach ($myMediaObjects as $myMob) { + if ($mob == $myMob) { + // change usage + ilObjMediaObject::_removeUsage($mob, 'x_' . $type['obj_type'] . ':html', $ilUser->getId()); + break; + } + } + ilObjMediaObject::_saveUsage($mob, 'x_' . $type['obj_type'] . ':html', $model->getId()); + } + } + } + + protected function deleteUnusedMobs($model) + { + foreach ($this->feedback_types as $type) { + $oldMediaObjects = ilObjMediaObject::_getMobsOfObject('x_' . $type['obj_type'] . ':html', $model->getId()); + $curMediaObjects = ilRTE::_getMediaObjects($this->form->getInput($type['post_var']), 0); + foreach ($oldMediaObjects as $oldMob) { + $found = false; + foreach ($curMediaObjects as $curMob) { + if ($oldMob == $curMob) { + $found = true; + break; + } + } + if (!$found) { + if (ilObjMediaObject::_exists($oldMob)) { + ilObjMediaObject::_removeUsage($oldMob, 'x_' . $type['obj_type'] . ':html', $model->getId()); + $mob_obj = new ilObjMediaObject($oldMob); + $mob_obj->delete(); + } + } + } + } + } } diff --git a/classes/controllers/class.ilQuestionSetPoolJumpConditionGUI.php b/classes/controllers/class.ilQuestionSetPoolJumpConditionGUI.php index 4fdd706466349ebe375fae576b93d40bbe95e918..e23ccf382a51b9c8e1c47e5fb5d904087125f9f0 100644 --- a/classes/controllers/class.ilQuestionSetPoolJumpConditionGUI.php +++ b/classes/controllers/class.ilQuestionSetPoolJumpConditionGUI.php @@ -8,463 +8,420 @@ require_once "abstract.ilQuestionSetPoolConditionGUI.php"; * Date: 05.12.13 * Time: 09:20 * @author Thomas Joußen - */ + */ class ilQuestionSetPoolJumpConditionGUI extends ilQuestionSetPoolConditionGUI { - /** - * @var array $feedback_types needed for tiny-mce - */ - protected $feedback_types = array( - 0 => array('post_var' => 'true_feedback', 'obj_type' => 'tf'), - 1 => array('post_var' => 'true_jump_feedback', 'obj_type' => 'tjf'), - 2 => array('post_var' => 'false_feedback', 'obj_type' => 'ff')); - - /** - * @var ilQuestionSetPoolJumpCondition - */ - protected $model; - - public function edit() - { - include_once 'Services/jQuery/classes/class.iljQueryUtil.php'; - iljQueryUtil::initjQuery(); - include_once 'Services/YUI/classes/class.ilYuiUtil.php'; - ilYuiUtil::initPanel(); - ilYuiUtil::initOverlay(); - $this->tpl->addJavascript('./Services/UIComponent/Overlay/js/ilOverlay.js'); - $this->tpl->addJavaScript("./Services/JavaScript/js/Basic.js"); - - $this->model = $this->loadModel(); - $this->initForm($this->model); - $this->bindModelToForm($this->model); - - ilUtil::sendInfo($this->plugin->txt("jump_condition_target_question"), true); - - $template = new ilTemplate("tpl.il_xqsp_condition.html", true, true, "Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool"); - - $this->renderQuestionInfo($this->model->getNode(), $template); - - $template->setVariable("FORM", $this->form->getHTML()); - $template->setVariable("INFO", ilQuestionSetPoolInfoBox::render($this->plugin)); - - require_once 'Services/UIComponent/Button/classes/class.ilLinkButton.php'; - $button = ilLinkButton::getInstance(); - $button->addCSSClass('toggle_feedback'); - $button->setCaption($this->plugin->txt('hide_feedback_form_parts'), false); - $this->toolbar->addButtonInstance($button); - $template->setVariable("TXT_SHOW_FEEDBACK", $this->plugin->txt('show_feedback_form_parts')); - $template->setVariable("TXT_HIDE_FEEDBACK", $this->plugin->txt('hide_feedback_form_parts')); - - $this->tpl->setContent($template->get()); - } - - public function update() - { - include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php'; - $this->model = $this->loadModel(); - - $this->initForm($this->model); - if($this->form->checkInput()) - { - $this->model->bindForm($this->form); - - $isValid = ilQuestionSetPoolConditionValidator::isValid( - $this->model->getJumpCondition(), - $this->model->getNode(), - $this->model->getNode()->getPath()->getNodes()->getData(), - $this->plugin - ); - if($isValid) - { - $this->model->update(); - - $this->copyTemporaryMobs(); - $this->deleteUnusedMobs(); - $this->deleteTemporaryMobs(); - - ilUtil::sendSuccess($this->plugin->txt("msg_obj_modified"), true); - $this->redirect( - $this->getAfterUpdateRedirectCmd(), - $this->getAfterUpdateRedirectParams($this->model) - ); - } - } - $this->form->setValuesByPost(); - - $template = new ilTemplate("tpl.il_xqsp_condition.html", true, true, "Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool"); - - $this->renderQuestionInfo($this->model->getNode(), $template); - - $template->setVariable("FORM", $this->form->getHTML()); - $template->setVariable("INFO", ilQuestionSetPoolInfoBox::render($this->plugin)); - - $this->tpl->setContent($template->get()); - } - - public function up() - { - $condition = $this->loadModel(); - $data = $condition->getNode()->getJumpConditionList()->getData(); - foreach($data as $key => $element) - { - if($element["id"] == $condition->getId()) - { - $this->swap($condition, $data[$key-1]["id"]); - break; - } - } - - $this->redirect("ilQuestionSetPoolNodesGUI.listNodes", array( - "path_id" => $condition->getNode()->getPath()->getId(), - "set_id" => $condition->getNode()->getPath()->getSet()->getId() - )); - } - - public function down() - { - $condition = $this->loadModel(); - $data = $condition->getNode()->getJumpConditionList()->getData(); - foreach($data as $key => $element) - { - if($element["id"] == $condition->getId()) - { - $this->swap($condition, $data[$key+1]["id"]); - break; - } - } - $this->redirect("ilQuestionSetPoolNodesGUI.listNodes", array( - "path_id" => $condition->getNode()->getPath()->getId(), - "set_id" => $condition->getNode()->getPath()->getSet()->getId() - )); - } - - /** - * @param ilQuestionSetPoolJumpCondition $condition - * @param $swap_condition_id - */ - protected function swap($condition, $swap_condition_id) - { - $swap_condition = new ilQuestionSetPoolJumpCondition(); - $swap_condition->setId($swap_condition_id); - $swap_condition->read(); - - $sorting = $condition->getSorting(); - $condition->setSorting($swap_condition->getSorting()); - $swap_condition->setSorting($sorting); - - $swap_condition->update(); - $condition->update(); - } - - - public function remove() - { - $model = $this->loadModel(); - $model->remove(); - - ilUtil::sendSuccess($this->plugin->txt("msg_obj_modified"), true); - $this->redirect( - $this->getAfterUpdateRedirectCmd(), - $this->getAfterUpdateRedirectParams($model) - ); - } - - /** - * Loads and returns the Model for the controller gui - * @return ilQuestionSetPoolJumpCondition - */ - protected function loadModel() - { - $id = (isset($_GET['condition_id']))? (int)$_GET['condition_id'] : (int)$_POST['id']; - $model = new ilQuestionSetPoolJumpCondition($id); - $model->read(); - - return $model; - } - - /** - * Initialize the PropertyFormGUI for this controller - * - * @param $model - */ - protected function initForm($model) - { - global $DIC; - $ilUser = $DIC->user(); - - require_once "./Services/Form/classes/class.ilPropertyFormGUI.php"; - - $this->form = new ilPropertyFormGUI(); - $this->form->setName('condition_form'); - $this->form->setTableWidth("100%"); - $this->form->setTitle(sprintf($this->plugin->txt("jump_condition_title"), - $model->getNode()->getPath()->getSet()->getTitle(), - $model->getNode()->getPath()->getTitle(), - $model->getNode()->getIndex() - )); - - $node_id = new ilHiddenInputGUI("node_fi"); - $condition_id = new ilHiddenInputGUI("id"); - - $condition = new ilConditionInputGUI($this->plugin->txt("condition"), "jump_condition"); - $condition->setInlineStyle('width:95%'); - $condition->setRequired(false); - - $questions = new ilSelectInputGUI($this->plugin->txt("target_question"), "question"); - $questions->setRequired(true); - $questions->setOptions($this->getQuestions()); - - $repititions = new ilNumberInputGUI($this->plugin->txt("repititions"), "repititions"); - $repititions->setSize(5); - $repititions->allowDecimals(false); - $repititions->setRequired(false); - - $this->form->addItem($node_id); - $this->form->addItem($condition_id); - $this->form->addItem($condition); - $this->form->addItem($questions); - $this->form->addItem($repititions); - - $true_feedback = new ilTextAreaInputGUI($this->plugin->txt('true_feedback'), 'true_feedback'); - $true_feedback->setUseRte(TRUE); - $true_feedback->addPlugin("latex"); - $true_feedback->addButton("latex"); - if($_GET["condition_id"]) - { - $true_feedback->setRTESupport($_GET["condition_id"], 'x_tf', 'assessment'); - } - else - { - $true_feedback->setRTESupport($ilUser->getId(), 'x_tf~', 'assessment'); - } - $true_feedback->setRteTagSet('full'); - $this->form->addItem($true_feedback); - - $true_jump_feedback = new ilTextAreaInputGUI($this->plugin->txt('true_jump_feedback'), 'true_jump_feedback'); - $true_jump_feedback->setUseRte(TRUE); - $true_jump_feedback->addPlugin("latex"); - $true_jump_feedback->addButton("latex"); - if($_GET["condition_id"]) - { - $true_jump_feedback->setRTESupport($_GET["condition_id"], 'x_tjf', 'assessment'); - } - else - { - $true_jump_feedback->setRTESupport($ilUser->getId(), 'x_tjf~:html', 'assessment'); - } - $true_jump_feedback->setRteTagSet('full'); - $this->form->addItem($true_jump_feedback); - - $false_feedback = new ilTextAreaInputGUI($this->plugin->txt('false_feedback'), 'false_feedback'); - $false_feedback->setUseRte(TRUE); - $false_feedback->addPlugin("latex"); - $false_feedback->addButton("latex"); - if($_GET["condition_id"]) - { - $false_feedback->setRTESupport($_GET["condition_id"], 'x_ff:html', 'assessment'); - } - else - { - $false_feedback->setRTESupport($ilUser->getId(), 'x_ff~:html', 'assessment'); - } - $false_feedback->setRteTagSet('full'); - $this->form->addItem($false_feedback); - - $this->ctrl->setParameter($this->controller, "condition_id", $_GET["condition_id"]); - $this->ctrl->setParameter($this->controller, "path_id", $model->getNode()->getPath()->getId()); - $this->ctrl->setParameter($this->controller, "set_id", $model->getNode()->getPath()->getSet()->getId()); - $this->form->setFormAction($this->ctrl->getFormAction($this->controller)); - $this->ctrl->setParameter($this->controller, "path_id", ""); - $this->ctrl->setParameter($this->controller, "set_id", ""); - $this->ctrl->setParameter($this->controller, "condition_id", ""); - $this->form->addCommandButton("ilQuestionSetPoolJumpConditionGUI.update", $this->plugin->txt("save")); - $this->form->addCommandButton("ilQuestionSetPoolNodesGUI.listNodes", $this->plugin->txt("cancel")); - - } - - protected function bindModelToForm(ilPluginModelInterface $model) - { - parent::bindModelToForm($model); - $item = $this->form->getItemByPostVar("node_fi"); - $item->setValue($model->getNode()->getId()); - - $question_id = "-"; - if($model->getQuestion() != null) - { - $question_id = $model->getQuestion()->getId(); - } - $item = $this->form->getItemByPostVar("question"); - $item->setValue($question_id); - } - - - /** - * @return array - */ - protected function getQuestions() - { - global $DIC; - $ilDB = $DIC->database(); - - $questions = array(); - - $result = $ilDB->queryF( - "SELECT qs_qst.question_index, q.title, q.question_id + /** + * @var array $feedback_types needed for tiny-mce + */ + protected $feedback_types = array( + 0 => array('post_var' => 'true_feedback', 'obj_type' => 'tf'), + 1 => array('post_var' => 'true_jump_feedback', 'obj_type' => 'tjf'), + 2 => array('post_var' => 'false_feedback', 'obj_type' => 'ff')); + + /** + * @var ilQuestionSetPoolJumpCondition + */ + protected $model; + + public function edit() + { + iljQueryUtil::initjQuery(); + ilYuiUtil::initPanel(); + ilYuiUtil::initOverlay(); + $this->tpl->addJavascript('./Services/UIComponent/Overlay/js/ilOverlay.js'); + $this->tpl->addJavaScript("./Services/JavaScript/js/Basic.js"); + + $this->model = $this->loadModel(); + $this->initForm($this->model); + $this->bindModelToForm($this->model); + + ilUtil::sendInfo($this->plugin->txt("jump_condition_target_question"), true); + + $template = new ilTemplate("tpl.il_xqsp_condition.html", true, true, "Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool"); + + $this->renderQuestionInfo($this->model->getNode(), $template); + + $template->setVariable("FORM", $this->form->getHTML()); + $template->setVariable("INFO", ilQuestionSetPoolInfoBox::render($this->plugin)); + + $button = ilLinkButton::getInstance(); + $button->addCSSClass('toggle_feedback'); + $button->setCaption($this->plugin->txt('hide_feedback_form_parts'), false); + $this->toolbar->addButtonInstance($button); + $template->setVariable("TXT_SHOW_FEEDBACK", $this->plugin->txt('show_feedback_form_parts')); + $template->setVariable("TXT_HIDE_FEEDBACK", $this->plugin->txt('hide_feedback_form_parts')); + + $this->tpl->setContent($template->get()); + } + + public function update() + { + $this->model = $this->loadModel(); + + $this->initForm($this->model); + if ($this->form->checkInput()) { + $this->model->bindForm($this->form); + + $isValid = ilQuestionSetPoolConditionValidator::isValid( + $this->model->getJumpCondition(), + $this->model->getNode(), + $this->model->getNode()->getPath()->getNodes()->getData(), + $this->plugin + ); + if ($isValid) { + $this->model->update(); + + $this->copyTemporaryMobs(); + $this->deleteUnusedMobs(); + $this->deleteTemporaryMobs(); + + ilUtil::sendSuccess($this->plugin->txt("msg_obj_modified"), true); + $this->redirect( + $this->getAfterUpdateRedirectCmd(), + $this->getAfterUpdateRedirectParams($this->model) + ); + } + } + $this->form->setValuesByPost(); + + $template = new ilTemplate("tpl.il_xqsp_condition.html", true, true, "Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool"); + + $this->renderQuestionInfo($this->model->getNode(), $template); + + $template->setVariable("FORM", $this->form->getHTML()); + $template->setVariable("INFO", ilQuestionSetPoolInfoBox::render($this->plugin)); + + $this->tpl->setContent($template->get()); + } + + public function up() + { + $condition = $this->loadModel(); + $data = $condition->getNode()->getJumpConditionList()->getData(); + foreach ($data as $key => $element) { + if ($element["id"] == $condition->getId()) { + $this->swap($condition, $data[$key - 1]["id"]); + break; + } + } + + $this->redirect("ilQuestionSetPoolNodesGUI.listNodes", array( + "path_id" => $condition->getNode()->getPath()->getId(), + "set_id" => $condition->getNode()->getPath()->getSet()->getId() + )); + } + + public function down() + { + $condition = $this->loadModel(); + $data = $condition->getNode()->getJumpConditionList()->getData(); + foreach ($data as $key => $element) { + if ($element["id"] == $condition->getId()) { + $this->swap($condition, $data[$key + 1]["id"]); + break; + } + } + $this->redirect("ilQuestionSetPoolNodesGUI.listNodes", array( + "path_id" => $condition->getNode()->getPath()->getId(), + "set_id" => $condition->getNode()->getPath()->getSet()->getId() + )); + } + + /** + * @param ilQuestionSetPoolJumpCondition $condition + * @param $swap_condition_id + */ + protected function swap($condition, $swap_condition_id) + { + $swap_condition = new ilQuestionSetPoolJumpCondition(); + $swap_condition->setId($swap_condition_id); + $swap_condition->read(); + + $sorting = $condition->getSorting(); + $condition->setSorting($swap_condition->getSorting()); + $swap_condition->setSorting($sorting); + + $swap_condition->update(); + $condition->update(); + } + + + public function remove() + { + $model = $this->loadModel(); + $model->remove(); + + ilUtil::sendSuccess($this->plugin->txt("msg_obj_modified"), true); + $this->redirect( + $this->getAfterUpdateRedirectCmd(), + $this->getAfterUpdateRedirectParams($model) + ); + } + + /** + * Loads and returns the Model for the controller gui + * @return ilQuestionSetPoolJumpCondition + */ + protected function loadModel() + { + $id = (isset($_GET['condition_id']))? (int) $_GET['condition_id'] : (int) $_POST['id']; + $model = new ilQuestionSetPoolJumpCondition($id); + $model->read(); + + return $model; + } + + /** + * Initialize the PropertyFormGUI for this controller + * + * @param $model + */ + protected function initForm($model) + { + global $DIC; + $ilUser = $DIC->user(); + + $this->form = new ilPropertyFormGUI(); + $this->form->setName('condition_form'); + $this->form->setTableWidth("100%"); + $this->form->setTitle(sprintf( + $this->plugin->txt("jump_condition_title"), + $model->getNode()->getPath()->getSet()->getTitle(), + $model->getNode()->getPath()->getTitle(), + $model->getNode()->getIndex() + )); + + $node_id = new ilHiddenInputGUI("node_fi"); + $condition_id = new ilHiddenInputGUI("id"); + + $condition = new ilConditionInputGUI($this->plugin->txt("condition"), "jump_condition"); + $condition->setInlineStyle('width:95%'); + $condition->setRequired(false); + + $questions = new ilSelectInputGUI($this->plugin->txt("target_question"), "question"); + $questions->setRequired(true); + $questions->setOptions($this->getQuestions()); + + $repititions = new ilNumberInputGUI($this->plugin->txt("repititions"), "repititions"); + $repititions->setSize(5); + $repititions->allowDecimals(false); + $repititions->setRequired(false); + + $this->form->addItem($node_id); + $this->form->addItem($condition_id); + $this->form->addItem($condition); + $this->form->addItem($questions); + $this->form->addItem($repititions); + + $true_feedback = new ilTextAreaInputGUI($this->plugin->txt('true_feedback'), 'true_feedback'); + $true_feedback->setUseRte(true); + $true_feedback->addPlugin("latex"); + $true_feedback->addButton("latex"); + if ($_GET["condition_id"]) { + $true_feedback->setRTESupport($_GET["condition_id"], 'x_tf', 'assessment'); + } else { + $true_feedback->setRTESupport($ilUser->getId(), 'x_tf~', 'assessment'); + } + $true_feedback->setRteTagSet('full'); + $this->form->addItem($true_feedback); + + $true_jump_feedback = new ilTextAreaInputGUI($this->plugin->txt('true_jump_feedback'), 'true_jump_feedback'); + $true_jump_feedback->setUseRte(true); + $true_jump_feedback->addPlugin("latex"); + $true_jump_feedback->addButton("latex"); + if ($_GET["condition_id"]) { + $true_jump_feedback->setRTESupport($_GET["condition_id"], 'x_tjf', 'assessment'); + } else { + $true_jump_feedback->setRTESupport($ilUser->getId(), 'x_tjf~:html', 'assessment'); + } + $true_jump_feedback->setRteTagSet('full'); + $this->form->addItem($true_jump_feedback); + + $false_feedback = new ilTextAreaInputGUI($this->plugin->txt('false_feedback'), 'false_feedback'); + $false_feedback->setUseRte(true); + $false_feedback->addPlugin("latex"); + $false_feedback->addButton("latex"); + if ($_GET["condition_id"]) { + $false_feedback->setRTESupport($_GET["condition_id"], 'x_ff:html', 'assessment'); + } else { + $false_feedback->setRTESupport($ilUser->getId(), 'x_ff~:html', 'assessment'); + } + $false_feedback->setRteTagSet('full'); + $this->form->addItem($false_feedback); + + $this->ctrl->setParameter($this->controller, "condition_id", $_GET["condition_id"]); + $this->ctrl->setParameter($this->controller, "path_id", $model->getNode()->getPath()->getId()); + $this->ctrl->setParameter($this->controller, "set_id", $model->getNode()->getPath()->getSet()->getId()); + $this->form->setFormAction($this->ctrl->getFormAction($this->controller)); + $this->ctrl->setParameter($this->controller, "path_id", ""); + $this->ctrl->setParameter($this->controller, "set_id", ""); + $this->ctrl->setParameter($this->controller, "condition_id", ""); + $this->form->addCommandButton("ilQuestionSetPoolJumpConditionGUI.update", $this->plugin->txt("save")); + $this->form->addCommandButton("ilQuestionSetPoolNodesGUI.listNodes", $this->plugin->txt("cancel")); + } + + protected function bindModelToForm(ilPluginModelInterface $model) + { + parent::bindModelToForm($model); + $item = $this->form->getItemByPostVar("node_fi"); + $item->setValue($model->getNode()->getId()); + + $question_id = "-"; + if ($model->getQuestion() != null) { + $question_id = $model->getQuestion()->getId(); + } + $item = $this->form->getItemByPostVar("question"); + $item->setValue($question_id); + } + + + /** + * @return array + */ + protected function getQuestions() + { + global $DIC; + $ilDB = $DIC->database(); + + $questions = array(); + + $result = $ilDB->queryF( + "SELECT qs_qst.question_index, q.title, q.question_id FROM rep_robj_xqsp_qs_qst qs_qst INNER JOIN rep_robj_xqsp_node n ON n.question_fi = qs_qst.question_fi INNER JOIN qpl_questions q ON q.question_id = qs_qst.question_fi WHERE n.path_fi = %s AND n.node_index <= %s", - array("integer", "integer"), - array($this->model->getNode()->getPath()->getId(), $this->model->getNode()->getIndex()) - ); - - while(($row = $ilDB->fetchAssoc($result)) != null) - { - $questions[$row["question_id"]] = "Q" . $row['question_index'] . " - " . $row["title"]; - } - - $questions["-"] = $this->plugin->txt("tst_termination"); - - return $questions; - } - - /** - * Get the redirect action after an update was successful - * @return string - */ - protected function getAfterUpdateRedirectCmd() - { - return "ilQuestionSetPoolNodesGUI.listNodes"; - } - - /** - * @param $model - * - * @return array - */ - protected function getAfterUpdateRedirectParams($model) - { - return array( - "set_id" => $model->getNode()->getPath()->getSet()->getId(), - "path_id" => $model->getNode()->getPath()->getId() - ); - } - - /** - * Returns the current tab name - * return string - */ - protected function getCurrentTab() - { - return "content"; - } - - /** - * @return array - */ - protected function getRequirements() - { - return array( - "models/class.ilQuestionSetPoolJumpCondition.php", - "providers/class.ilParserQuestionProvider.php", - "utils/abstract.ilQuestionSetPoolInfoBox.php", - "utils/abstract.ilQuestionSetPoolConditionValidator.php", - "utils/class.ilConditionInputGUI.php" - ); - } - - /** - * - */ - protected function copyTemporaryMobs() - { - global $DIC; - $ilUser = $DIC->user(); - - foreach($this->feedback_types as $type) - { - $mediaObjects = ilRTE::_getMediaObjects($this->form->getInput($type['post_var']), 0); - $myMediaObjects = ilObjMediaObject::_getMobsOfObject('x_'.$type['obj_type'].'~:html', $ilUser->getId()); - foreach($mediaObjects as $mob) - { - foreach($myMediaObjects as $myMob) - { - if($mob == $myMob) - { - // change usage - ilObjMediaObject::_removeUsage($mob, 'x_'.$type['obj_type'].'~:html', $ilUser->getId()); - break; - } - } - ilObjMediaObject::_saveUsage($mob, 'x_'.$type['obj_type'].':html', $this->model->getId()); - } - } - } - - /** - * - */ - protected function deleteUnusedMobs() - { - foreach($this->feedback_types as $type) - { - // remove usage of deleted media objects - include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php'; - $oldMediaObjects = ilObjMediaObject::_getMobsOfObject('x_'.$type['obj_type'].':html', $this->model->getId()); - $curMediaObjects = ilRTE::_getMediaObjects($this->form->getInput($type['post_var']), 0); - foreach($oldMediaObjects as $oldMob) - { - $found = false; - foreach($curMediaObjects as $curMob) - { - if($oldMob == $curMob) - { - $found = true; - break; - } - } - if(!$found) - { - if(ilObjMediaObject::_exists($oldMob)) - { - ilObjMediaObject::_removeUsage($oldMob, 'x_' . $type['obj_type'].':html', $this->model->getId()); - $mob_obj = new ilObjMediaObject($oldMob); - $mob_obj->delete(); - } - } - } - } - } - - /** - * - */ - protected function deleteTemporaryMobs() - { - global $DIC; - $ilUser = $DIC->user(); - - try - { - include_once 'Services/MediaObjects/classes/class.ilObjMediaObject.php'; - - foreach($this->feedback_types as $type) - { - $mobs = ilObjMediaObject::_getMobsOfObject('x_'.$type['obj_type'].'~:html', $ilUser->getId()); - foreach($mobs as $mob) - { - if(ilObjMediaObject::_exists($mob)) - { - ilObjMediaObject::_removeUsage($mob, 'x_'.$type['obj_type'].'~:html', $ilUser->getId()); - $mob_obj = new ilObjMediaObject($mob); - $mob_obj->delete(); - } - } - } - } - catch(Exception $e) - { - } - } + array("integer", "integer"), + array($this->model->getNode()->getPath()->getId(), $this->model->getNode()->getIndex()) + ); + + while (($row = $ilDB->fetchAssoc($result)) != null) { + $questions[$row["question_id"]] = "Q" . $row['question_index'] . " - " . $row["title"]; + } + + $questions["-"] = $this->plugin->txt("tst_termination"); + + return $questions; + } + + /** + * Get the redirect action after an update was successful + * @return string + */ + protected function getAfterUpdateRedirectCmd() + { + return "ilQuestionSetPoolNodesGUI.listNodes"; + } + + /** + * @param $model + * + * @return array + */ + protected function getAfterUpdateRedirectParams($model) + { + return array( + "set_id" => $model->getNode()->getPath()->getSet()->getId(), + "path_id" => $model->getNode()->getPath()->getId() + ); + } + + /** + * Returns the current tab name + * return string + */ + protected function getCurrentTab() + { + return "content"; + } + + /** + * @return array + */ + protected function getRequirements() + { + return array( + "models/class.ilQuestionSetPoolJumpCondition.php", + "providers/class.ilParserQuestionProvider.php", + "utils/abstract.ilQuestionSetPoolInfoBox.php", + "utils/abstract.ilQuestionSetPoolConditionValidator.php", + "utils/class.ilConditionInputGUI.php" + ); + } + + /** + * + */ + protected function copyTemporaryMobs() + { + global $DIC; + $ilUser = $DIC->user(); + + foreach ($this->feedback_types as $type) { + $mediaObjects = ilRTE::_getMediaObjects($this->form->getInput($type['post_var']), 0); + $myMediaObjects = ilObjMediaObject::_getMobsOfObject('x_' . $type['obj_type'] . '~:html', $ilUser->getId()); + foreach ($mediaObjects as $mob) { + foreach ($myMediaObjects as $myMob) { + if ($mob == $myMob) { + // change usage + ilObjMediaObject::_removeUsage($mob, 'x_' . $type['obj_type'] . '~:html', $ilUser->getId()); + break; + } + } + ilObjMediaObject::_saveUsage($mob, 'x_' . $type['obj_type'] . ':html', $this->model->getId()); + } + } + } + + /** + * + */ + protected function deleteUnusedMobs() + { + foreach ($this->feedback_types as $type) { + $oldMediaObjects = ilObjMediaObject::_getMobsOfObject('x_' . $type['obj_type'] . ':html', $this->model->getId()); + $curMediaObjects = ilRTE::_getMediaObjects($this->form->getInput($type['post_var']), 0); + foreach ($oldMediaObjects as $oldMob) { + $found = false; + foreach ($curMediaObjects as $curMob) { + if ($oldMob == $curMob) { + $found = true; + break; + } + } + if (!$found) { + if (ilObjMediaObject::_exists($oldMob)) { + ilObjMediaObject::_removeUsage($oldMob, 'x_' . $type['obj_type'] . ':html', $this->model->getId()); + $mob_obj = new ilObjMediaObject($oldMob); + $mob_obj->delete(); + } + } + } + } + } + + /** + * + */ + protected function deleteTemporaryMobs() + { + global $DIC; + $ilUser = $DIC->user(); + + try { + foreach ($this->feedback_types as $type) { + $mobs = ilObjMediaObject::_getMobsOfObject('x_' . $type['obj_type'] . '~:html', $ilUser->getId()); + foreach ($mobs as $mob) { + if (ilObjMediaObject::_exists($mob)) { + ilObjMediaObject::_removeUsage($mob, 'x_' . $type['obj_type'] . '~:html', $ilUser->getId()); + $mob_obj = new ilObjMediaObject($mob); + $mob_obj->delete(); + } + } + } + } catch (Exception $e) { + } + } } diff --git a/classes/controllers/class.ilQuestionSetPoolNodeGUI.php b/classes/controllers/class.ilQuestionSetPoolNodeGUI.php index 34ba51a18fd479fa13f3d4fd1173a69b128724d8..0c8dcb38dfeb1d11a36cd5bdaf11cbe1d1e4d18d 100644 --- a/classes/controllers/class.ilQuestionSetPoolNodeGUI.php +++ b/classes/controllers/class.ilQuestionSetPoolNodeGUI.php @@ -8,271 +8,253 @@ require_once "abstract.ilPluginControllerFormGUI.php"; * Date: 21.11.13 * Time: 14:15 * @author Thomas Joußen - */ + */ class ilQuestionSetPoolNodeGUI extends ilPluginControllerFormGUI { - - protected $redirectCmd = "ilQuestionSetPoolNodesGUI.listNodes"; - - public function edit() - { - $model = $this->loadModel(); - - $this->redirectIfUnableToAddNewNode($model); - $this->initForm($model); - $this->bindModelToForm($model); - $this->tpl->setContent($this->form->getHTML()); - } - - public function updateAndNew() - { - $this->redirectCmd = "ilQuestionSetPoolNodeGUI.edit"; - $this->update(); - } - - public function removeConfirmation() - { - require_once "./Services/Utilities/classes/class.ilConfirmationGUI.php"; - $model = $this->loadModel(); - $model->read(); - - if(!$model->getId() || $model->getPath()->getSet()->getContainerObjId() != $this->controller->object->getId()) - { - if($model->getId()) - { - ilUtil::sendFailure(sprintf($this->plugin->txt('nodes_del_perm_err_s'), implode(', ', array($model->getIndex()))), true); - } - $this->controller->ctrl->setParameter($this->controller, 'set_id', (int)$_GET['set_id']); - $this->controller->ctrl->setParameter($this->controller, 'path_id', (int)$_GET['path_id']); - $this->controller->ctrl->redirect($this->controller, 'ilQuestionSetPoolNodesGUI.listNodes'); - return; - } - - $confirmation = new ilConfirmationGUI(); - $this->ctrl->setParameter($this->controller, "node_id", $model->getId()); - $this->ctrl->setParameter($this->controller, "set_id", $model->getPath()->getSet()->getId()); - $this->ctrl->setParameter($this->controller, "path_id", $model->getPath()->getId()); - $confirmation->setFormAction($this->ctrl->getFormAction($this->controller, "ilQuestionSetPoolNodesGUI.listNodes")); - $this->ctrl->setParameter($this->controller, "node_id", ""); - $this->ctrl->setParameter($this->controller, "set_id", ""); - $this->ctrl->setParameter($this->controller, "path_id", ""); - $confirmation->setHeaderText($this->plugin->txt("confirm_delete_node")); - $confirmation->setCancel($this->plugin->txt("cancel"), "ilQuestionSetPoolNodesGUI.listNodes"); - $confirmation->setConfirm($this->plugin->txt("confirm"), "ilQuestionSetPoolNodeGUI.remove"); - - $confirmation->addItem("id", $model->getId(), "(Q" . $model->getQuestionIndex() . ") ".$model->getQuestion()->getTitle()); - $this->tpl->setContent($confirmation->getHTML()); - } - - public function remove() - { - $model = $this->loadModel(); - $model->read(); - - if(!$model->getId() || $model->getPath()->getSet()->getContainerObjId() != $this->controller->object->getId()) - { - if($model->getId()) - { - ilUtil::sendFailure(sprintf($this->plugin->txt('nodes_del_perm_err_s'), implode(', ', array($model->getIndex()))), true); - } - $this->controller->ctrl->setParameter($this->controller, 'set_id', (int)$_GET['set_id']); - $this->controller->ctrl->setParameter($this->controller, 'path_id', (int)$_GET['path_id']); - $this->controller->ctrl->redirect($this->controller, 'ilQuestionSetPoolNodesGUI.listNodes'); - return; - } - - $data = $model->getPath()->getNodes()->getData(); - foreach($data as $key => $element) - { - if($element["id"] == $model->getId()) - { - unset($data[$key]); - } - } - - if($model->getIndex() == 1) - { - ilUtil::sendFailure($this->plugin->txt("cant_delete_first_node"), true); - - $this->redirect( - "ilQuestionSetPoolNodesGUI.listNodes", - $this->getAfterUpdateRedirectParams($model) - ); - } - - $canBeDeleted = true; - foreach($data as $node) - { - $node = new ilQuestionSetPoolNode($node["id"]); - $node->read(); - - if(!ilQuestionSetPoolConditionValidator::isValid($node->getInitialCondition(),$node,$data,$this->plugin)) - { - $canBeDeleted = false; - ilUtil::sendFailure($this->plugin->txt("node_used_in_initial_condition"), true); - } - - $conditions = $node->getJumpConditionList()->getData(); - foreach($conditions as $condition) - { - if(!ilQuestionSetPoolConditionValidator::isValid($condition["jump_condition"],$node,$data,$this->plugin)) - { - $canBeDeleted = false; - ilUtil::sendFailure($this->plugin->txt("node_used_in_jump_condition"), true); - } - - if($condition["question_fi"] == $model->getQuestion()->getId() && - $condition["node_fi"] != $model->getId() - ) - { - $canBeDeleted = false; - ilUtil::sendFailure($this->plugin->txt("node_is_used_as_target"), true); - } - } - } - - if($canBeDeleted) - { - $model->remove(); - ilUtil::sendSuccess($this->plugin->txt("node_deleted"), true); - } - - $this->redirect( - "ilQuestionSetPoolNodesGUI.listNodes", - $this->getAfterUpdateRedirectParams($model) - ); - } - - /** - * Loads and returns the Model for the controller gui - * @return ilQuestionSetPoolNode - */ - protected function loadModel() - { - $id = (isset($_GET['node_id']))? (int)$_GET['node_id'] : (int)$_POST['id']; - $model = new ilQuestionSetPoolNode($id); - $model->read(); - - return $model; - } - - /** - * Initialize the PropertyFormGUI for this controller - * - * @param $model - */ - protected function initForm($model) - { - require_once "./Services/Form/classes/class.ilPropertyFormGUI.php"; - - $this->form = new ilPropertyFormGUI(); - $this->form->setTitle(sprintf($this->plugin->txt("set_node_title"), - $model->getPath()->getSet()->getTitle(), - $model->getPath()->getTitle() - )); - - $question = new ilSelectInputGUI($this->plugin->txt('question'), "question_fi"); - $question->setRequired(true); - $question->setOptions($this->getQuestionOptions($model)); - - $this->form->addItem($question); - - $this->ctrl->setParameter($this->controller, "path_id", (int)$_GET['path_id']); - $this->ctrl->setParameter($this->controller, "set_id", (int)$_GET['set_id']); - $this->form->setFormAction($this->ctrl->getFormAction($this->controller)); - $this->ctrl->setParameter($this->controller, "path_id", ""); - $this->ctrl->setParameter($this->controller, "set_id", ""); - $this->form->addCommandButton("ilQuestionSetPoolNodeGUI.updateAndNew", $this->plugin->txt("save_and_new")); - $this->form->addCommandButton("ilQuestionSetPoolNodeGUI.update", $this->plugin->txt("save")); - $this->form->addCommandButton("ilQuestionSetPoolNodesGUI.listNodes", $this->plugin->txt("cancel")); - } - - /** - * Get the redirect action after an update was successful - * @return string - */ - protected function getAfterUpdateRedirectCmd() - { - ilUtil::sendSuccess($this->plugin->txt("msg_node_created"), true); - return $this->redirectCmd; - } - - /** - * @param $model - * - * @return array - */ - protected function getAfterUpdateRedirectParams($model) - { - return array( - "path_id" => $model->getPath()->getId(), - "set_id" => $model->getPath()->getSet()->getId() - ); - } - - /** - * Returns the current tab name - * return string - */ - protected function getCurrentTab() - { - return "content"; - } - - /** - * @return array - */ - protected function getRequirements() - { - return array( - "models/class.ilQuestionSetPoolNode.php", - "models/class.ilQuestionSetPoolPath.php", - "utils/abstract.ilQuestionSetPoolConditionValidator.php" - ); - } - - /** - * @param ilQuestionSetPoolNode $model - * - * @return array - */ - protected function getQuestionOptions($model) - { - $path = new ilQuestionSetPoolPath((int)$_GET['path_id']); - $path->read(); - $nodes = $path->getNodes()->getData(); - $questions = $model->getPath()->getSet()->getQuestionList()->getData(); - $options = array(); - - foreach ($questions as $question) - { - $options[$question['question_id']] = $question['title']; - } - - foreach($nodes as $node) - { - if(array_key_exists($node["question_fi"], $options)){ - unset($options[$node["question_fi"]]); - } - } - - return $options; - } - - /** - * @param $model - */ - protected function redirectIfUnableToAddNewNode($model) - { - if (is_array($this->getQuestionOptions($model)) && count($this->getQuestionOptions($model)) == 0) - { - ilUtil::sendFailure($this->plugin->txt("unable_to_add_new_node"), true); - $this->redirect( - "ilQuestionSetPoolNodesGUI.listNodes", array( - "path_id" => (int)$_GET["path_id"], - "set_id" => (int)$_GET["set_id"] - ) - ); - } - } + protected $redirectCmd = "ilQuestionSetPoolNodesGUI.listNodes"; + + public function edit() + { + $model = $this->loadModel(); + + $this->redirectIfUnableToAddNewNode($model); + $this->initForm($model); + $this->bindModelToForm($model); + $this->tpl->setContent($this->form->getHTML()); + } + + public function updateAndNew() + { + $this->redirectCmd = "ilQuestionSetPoolNodeGUI.edit"; + $this->update(); + } + + public function removeConfirmation() + { + $model = $this->loadModel(); + $model->read(); + + if (!$model->getId() || $model->getPath()->getSet()->getContainerObjId() != $this->controller->object->getId()) { + if ($model->getId()) { + ilUtil::sendFailure(sprintf($this->plugin->txt('nodes_del_perm_err_s'), implode(', ', array($model->getIndex()))), true); + } + $this->ctrl->setParameter($this->controller, 'set_id', (int) $_GET['set_id']); + $this->ctrl->setParameter($this->controller, 'path_id', (int) $_GET['path_id']); + $this->ctrl->redirect($this->controller, 'ilQuestionSetPoolNodesGUI.listNodes'); + return; + } + + $confirmation = new ilConfirmationGUI(); + $this->ctrl->setParameter($this->controller, "node_id", $model->getId()); + $this->ctrl->setParameter($this->controller, "set_id", $model->getPath()->getSet()->getId()); + $this->ctrl->setParameter($this->controller, "path_id", $model->getPath()->getId()); + $confirmation->setFormAction($this->ctrl->getFormAction($this->controller, "ilQuestionSetPoolNodesGUI.listNodes")); + $this->ctrl->setParameter($this->controller, "node_id", ""); + $this->ctrl->setParameter($this->controller, "set_id", ""); + $this->ctrl->setParameter($this->controller, "path_id", ""); + $confirmation->setHeaderText($this->plugin->txt("confirm_delete_node")); + $confirmation->setCancel($this->plugin->txt("cancel"), "ilQuestionSetPoolNodesGUI.listNodes"); + $confirmation->setConfirm($this->plugin->txt("confirm"), "ilQuestionSetPoolNodeGUI.remove"); + + $confirmation->addItem("id", $model->getId(), "(Q" . $model->getQuestionIndex() . ") " . $model->getQuestion()->getTitle()); + $this->tpl->setContent($confirmation->getHTML()); + } + + public function remove() + { + $model = $this->loadModel(); + $model->read(); + + if (!$model->getId() || $model->getPath()->getSet()->getContainerObjId() != $this->controller->object->getId()) { + if ($model->getId()) { + ilUtil::sendFailure(sprintf($this->plugin->txt('nodes_del_perm_err_s'), implode(', ', array($model->getIndex()))), true); + } + $this->ctrl->setParameter($this->controller, 'set_id', (int) $_GET['set_id']); + $this->ctrl->setParameter($this->controller, 'path_id', (int) $_GET['path_id']); + $this->ctrl->redirect($this->controller, 'ilQuestionSetPoolNodesGUI.listNodes'); + return; + } + + $data = $model->getPath()->getNodes()->getData(); + foreach ($data as $key => $element) { + if ($element["id"] == $model->getId()) { + unset($data[$key]); + } + } + + if ($model->getIndex() == 1) { + ilUtil::sendFailure($this->plugin->txt("cant_delete_first_node"), true); + + $this->redirect( + "ilQuestionSetPoolNodesGUI.listNodes", + $this->getAfterUpdateRedirectParams($model) + ); + } + + $canBeDeleted = true; + foreach ($data as $node) { + $node = new ilQuestionSetPoolNode($node["id"]); + $node->read(); + + if (!ilQuestionSetPoolConditionValidator::isValid($node->getInitialCondition(), $node, $data, $this->plugin)) { + $canBeDeleted = false; + ilUtil::sendFailure($this->plugin->txt("node_used_in_initial_condition"), true); + } + + $conditions = $node->getJumpConditionList()->getData(); + foreach ($conditions as $condition) { + if (!ilQuestionSetPoolConditionValidator::isValid($condition["jump_condition"], $node, $data, $this->plugin)) { + $canBeDeleted = false; + ilUtil::sendFailure($this->plugin->txt("node_used_in_jump_condition"), true); + } + + if ($condition["question_fi"] == $model->getQuestion()->getId() && + $condition["node_fi"] != $model->getId() + ) { + $canBeDeleted = false; + ilUtil::sendFailure($this->plugin->txt("node_is_used_as_target"), true); + } + } + } + + if ($canBeDeleted) { + $model->remove(); + ilUtil::sendSuccess($this->plugin->txt("node_deleted"), true); + } + + $this->redirect( + "ilQuestionSetPoolNodesGUI.listNodes", + $this->getAfterUpdateRedirectParams($model) + ); + } + + /** + * Loads and returns the Model for the controller gui + * @return ilQuestionSetPoolNode + */ + protected function loadModel() + { + $id = (isset($_GET['node_id']))? (int) $_GET['node_id'] : (int) $_POST['id']; + $model = new ilQuestionSetPoolNode($id); + $model->read(); + + return $model; + } + + /** + * Initialize the PropertyFormGUI for this controller + * + * @param $model + */ + protected function initForm($model) + { + $this->form = new ilPropertyFormGUI(); + $this->form->setTitle(sprintf( + $this->plugin->txt("set_node_title"), + $model->getPath()->getSet()->getTitle(), + $model->getPath()->getTitle() + )); + + $question = new ilSelectInputGUI($this->plugin->txt('question'), "question_fi"); + $question->setRequired(true); + $question->setOptions($this->getQuestionOptions($model)); + + $this->form->addItem($question); + + $this->ctrl->setParameter($this->controller, "path_id", (int) $_GET['path_id']); + $this->ctrl->setParameter($this->controller, "set_id", (int) $_GET['set_id']); + $this->form->setFormAction($this->ctrl->getFormAction($this->controller)); + $this->ctrl->setParameter($this->controller, "path_id", ""); + $this->ctrl->setParameter($this->controller, "set_id", ""); + $this->form->addCommandButton("ilQuestionSetPoolNodeGUI.updateAndNew", $this->plugin->txt("save_and_new")); + $this->form->addCommandButton("ilQuestionSetPoolNodeGUI.update", $this->plugin->txt("save")); + $this->form->addCommandButton("ilQuestionSetPoolNodesGUI.listNodes", $this->plugin->txt("cancel")); + } + + /** + * Get the redirect action after an update was successful + * @return string + */ + protected function getAfterUpdateRedirectCmd() + { + ilUtil::sendSuccess($this->plugin->txt("msg_node_created"), true); + return $this->redirectCmd; + } + + /** + * @param $model + * + * @return array + */ + protected function getAfterUpdateRedirectParams($model) + { + return array( + "path_id" => $model->getPath()->getId(), + "set_id" => $model->getPath()->getSet()->getId() + ); + } + + /** + * Returns the current tab name + * return string + */ + protected function getCurrentTab() + { + return "content"; + } + + /** + * @return array + */ + protected function getRequirements() + { + return array( + "models/class.ilQuestionSetPoolNode.php", + "models/class.ilQuestionSetPoolPath.php", + "utils/abstract.ilQuestionSetPoolConditionValidator.php" + ); + } + + /** + * @param ilQuestionSetPoolNode $model + * + * @return array + */ + protected function getQuestionOptions($model) + { + $path = new ilQuestionSetPoolPath((int) $_GET['path_id']); + $path->read(); + $nodes = $path->getNodes()->getData(); + $questions = $model->getPath()->getSet()->getQuestionList()->getData(); + $options = array(); + + foreach ($questions as $question) { + $options[$question['question_id']] = $question['title']; + } + + foreach ($nodes as $node) { + if (array_key_exists($node["question_fi"], $options)) { + unset($options[$node["question_fi"]]); + } + } + + return $options; + } + + /** + * @param $model + */ + protected function redirectIfUnableToAddNewNode($model) + { + if (is_array($this->getQuestionOptions($model)) && count($this->getQuestionOptions($model)) == 0) { + ilUtil::sendFailure($this->plugin->txt("unable_to_add_new_node"), true); + $this->redirect( + "ilQuestionSetPoolNodesGUI.listNodes", + array( + "path_id" => (int) $_GET["path_id"], + "set_id" => (int) $_GET["set_id"] + ) + ); + } + } } diff --git a/classes/controllers/class.ilQuestionSetPoolNodesGUI.php b/classes/controllers/class.ilQuestionSetPoolNodesGUI.php index d5a662f3c5ae2901e70287fb22e8075d6bdf02c8..ca687d023a4a4766777bfc6bd006d900dc8911a9 100644 --- a/classes/controllers/class.ilQuestionSetPoolNodesGUI.php +++ b/classes/controllers/class.ilQuestionSetPoolNodesGUI.php @@ -8,235 +8,223 @@ require_once "abstract.ilPluginControllerTableGUI.php"; * Date: 21.11.13 * Time: 11:52 * @author Thomas Joußen - */ + */ class ilQuestionSetPoolNodesGUI extends ilPluginControllerTableGUI { - - public function __construct(ilObjQuestionSetPoolGUI $controller) - { - parent::__construct($controller); - $this->addSubTabs(); - } - - /** - * - */ - public function editQuestion() - { - $this->controller->ensurePermission('write'); - - if(!isset($_GET['q_id']) || !(int)$_GET['q_id']) - { - $this->listNodes(); - return; - } - - $params = array( - 'set_id' => (int)$_GET['set_id'], - 'path_id' => (int)$_GET['path_id'], - 'cmd' => __CLASS__ . '.listNodes' - ); - - $question_id = (int)$_GET['q_id']; - ilUtil::redirect('ilias.php?consumer_context=' . base64_encode(json_encode($params)) . '&baseClass=ilObjQuestionPoolGUI&ref_id=' . $this->controller->object->getRefId().'&cmd=editQuestionForTest&calling_consumer=' . $this->controller->object->getRefId() . '&q_id=' . $question_id); - } - - public function listNodes() - { - $this->addToolbarButton("back_to_path_list", "ilQuestionSetPoolPathsGUI.listPaths",array( - "set_id" => (int)$_GET["set_id"] - )); - $this->addToolbarButton("add_node", "ilQuestionSetPoolNodeGUI.edit", array( - "path_id" => (int)$_GET['path_id'], - "set_id" =>(int) $_GET['set_id'], - )); - - $model = new ilQuestionSetPoolPath((int)$_GET['path_id']); - $model->read(); - - $this->ctrl->setParameter($this->controller, "set_id", (int)$_GET["set_id"]); - $table = new ilQuestionSetPoolNodeTableGUI($this->controller, $this->plugin, (int)$_GET['path_id']); - $table->setModelList($model->getNodes()); - $table->setTitle( - $model->getSet()->getTitle() . " - " . - $model->getTitle() . " - " . - $this->plugin->txt('nodes')); - - $table->addCommandButton("ilQuestionSetPoolNodesGUI.saveSorting", $this->plugin->txt("save_sorting")); - $table->addCommandButton("ilQuestionSetPoolNodesGUI.saveDominantScoring", $this->plugin->txt("save_dominant_scoring")); - - $table->populate(); - - $this->tpl->setContent($table->getHTML()); - } - - public function saveSorting() - { - $this->sortdata(); - ilUtil::sendSuccess($this->plugin->txt("saved_sorting"), true); - $this->redirect("ilQuestionSetPoolNodesGUI.listNodes", array( - "set_id" => (int)$_GET["set_id"], - "path_id" => (int)$_GET["path_id"] - )); - } - - public function saveDominantScoring() - { - $model = new ilQuestionSetPoolPath((int)$_GET["path_id"]); - $model->read(); - $data = $model->getNodes()->getData(); - - foreach($data as $element) - { - $node = new ilQuestionSetPoolNode($element["id"]); - $node->read(); - if($_POST["dominant_scoring"][$node->getId()] === "") - { - $node->setDominantScoring(null); - } - else - { - $node->setDominantScoring((int)$_POST["dominant_scoring"][$node->getId()]); - } - $node->update(); - } - - ilUtil::sendSuccess($this->plugin->txt("saved_dominant_scoring"), true); - $this->redirect("ilQuestionSetPoolNodesGUI.listNodes", array( - "set_id" => $model->getSet()->getId(), - "path_id" => $model->getId() - )); - } - - protected function sortdata() - { - $model = new ilQuestionSetPoolPath((int)$_GET['path_id']); - $model->read(); - $data = $model->getNodes()->getData(); - - foreach($data as $key => $element) - { - if($element["node_index"] != 1) - { - $minimumTwo = (int)$_POST["sorting"][$element["id"]]; - $data[$key]["node_index"] = $minimumTwo > 1 ? $minimumTwo : 2; - } - } - - usort($data, function($a,$b){ - return $a["node_index"] - $b["node_index"]; - }); - - if(!$this->conditionsAreValid($data)) - { - ilUtil::sendFailure($this->plugin->txt("sorting_error_jmp_conditions"), true); - $this->redirect("ilQuestionSetPoolNodesGUI.listNodes", array( - "set_id" => (int)$_GET["set_id"], - "path_id" => (int)$_GET["path_id"] - )); - } - - if(is_array($data)) - { - for($i = 0; $i < count($data); $i++) - { - $data[$i]["node_index"] = ($i + 1); - $model->getNodes()->update($data[$i]); - } - } - return $data; - } - - /** - * Returns the current tab name - * return string - */ - protected function getCurrentTab() - { - return "content"; - } - - /** - * @return array - */ - protected function getRequirements() - { - return array( - "models/class.ilQuestionSetPoolPath.php", - "tables/class.ilQuestionSetPoolNodeTableGUI.php", - "utils/abstract.ilQuestionSetPoolConditionValidator.php" - ); - } - - private function addSubTabs() - { - global $DIC; - $ilTabs = $DIC->tabs(); - - $this->ctrl->setParameter($this->controller, "set_id", (int)$_GET['set_id']); - - $ilTabs->addSubTab("set_questions", $this->plugin->txt("questions"), - $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolSetQuestionsGUI.listQuestions")); - - $ilTabs->addSubTab("paths", $this->plugin->txt("paths"), - $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolPathsGUI.listPaths")); - - $ilTabs->addSubTab("path_overview", $this->plugin->txt("path_overview"), - $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolPathGraphGUI.showPathOverview")); - - $ilTabs->activateSubTab("paths"); - - $this->ctrl->setParameter($this->controller, "set_id", ""); - } - - /** - * @param $data - * - * @return bool - */ - protected function conditionsAreValid($data) - { - if(is_array($data)) - { - for($index = 1; $index < count($data); $index++) - { - $node = new ilQuestionSetPoolNode($data[$index]["id"]); - $node->read(); - $node->setIndex($data[$index]["node_index"]); - - if(!ilQuestionSetPoolConditionValidator::isValid($node->getInitialCondition(), $node, $data, $this->plugin)) - { - return false; - } - - foreach($data[$index]["jump_conditions"] as $jump_condition) - { - if(!ilQuestionSetPoolConditionValidator::isValid($jump_condition["jump_condition"], $node, $data, $this->plugin)) - { - return false; - } - - $error = false; - for($inner_index = 0; $inner_index <= $index; $inner_index++) - { - if($data[$inner_index]["question_fi"] == $jump_condition["question_fi"] || $jump_condition["question_fi"] == null) - { - $error = false; - break; - } - else - { - $error = true; - } - } - if($error) - { - return false; - } - } - } - } - return true; - } + public function __construct(ilObjQuestionSetPoolGUI $controller) + { + parent::__construct($controller); + $this->addSubTabs(); + } + + /** + * + */ + public function editQuestion() + { + $this->controller->ensurePermission('write'); + + if (!isset($_GET['q_id']) || !(int) $_GET['q_id']) { + $this->listNodes(); + return; + } + + $params = array( + 'set_id' => (int) $_GET['set_id'], + 'path_id' => (int) $_GET['path_id'], + 'cmd' => __CLASS__ . '.listNodes' + ); + + $question_id = (int) $_GET['q_id']; + ilUtil::redirect('ilias.php?consumer_context=' . base64_encode(json_encode($params)) . '&baseClass=ilObjQuestionPoolGUI&ref_id=' . $this->controller->object->getRefId() . '&cmd=editQuestionForTest&calling_consumer=' . $this->controller->object->getRefId() . '&q_id=' . $question_id); + } + + public function listNodes() + { + $this->addToolbarButton("back_to_path_list", "ilQuestionSetPoolPathsGUI.listPaths", array( + "set_id" => (int) $_GET["set_id"] + )); + $this->addToolbarButton("add_node", "ilQuestionSetPoolNodeGUI.edit", array( + "path_id" => (int) $_GET['path_id'], + "set_id" => (int) $_GET['set_id'], + )); + + $model = new ilQuestionSetPoolPath((int) $_GET['path_id']); + $model->read(); + + $this->ctrl->setParameter($this->controller, "set_id", (int) $_GET["set_id"]); + $table = new ilQuestionSetPoolNodeTableGUI($this->controller, $this->plugin, (int) $_GET['path_id']); + $table->setModelList($model->getNodes()); + $table->setTitle( + $model->getSet()->getTitle() . " - " . + $model->getTitle() . " - " . + $this->plugin->txt('nodes') + ); + + $table->addCommandButton("ilQuestionSetPoolNodesGUI.saveSorting", $this->plugin->txt("save_sorting")); + $table->addCommandButton("ilQuestionSetPoolNodesGUI.saveDominantScoring", $this->plugin->txt("save_dominant_scoring")); + + $table->populate(); + + $this->tpl->setContent($table->getHTML()); + } + + public function saveSorting() + { + $this->sortdata(); + ilUtil::sendSuccess($this->plugin->txt("saved_sorting"), true); + $this->redirect("ilQuestionSetPoolNodesGUI.listNodes", array( + "set_id" => (int) $_GET["set_id"], + "path_id" => (int) $_GET["path_id"] + )); + } + + public function saveDominantScoring() + { + $model = new ilQuestionSetPoolPath((int) $_GET["path_id"]); + $model->read(); + $data = $model->getNodes()->getData(); + + foreach ($data as $element) { + $node = new ilQuestionSetPoolNode($element["id"]); + $node->read(); + if ($_POST["dominant_scoring"][$node->getId()] === "") { + $node->setDominantScoring(null); + } else { + $node->setDominantScoring((int) $_POST["dominant_scoring"][$node->getId()]); + } + $node->update(); + } + + ilUtil::sendSuccess($this->plugin->txt("saved_dominant_scoring"), true); + $this->redirect("ilQuestionSetPoolNodesGUI.listNodes", array( + "set_id" => $model->getSet()->getId(), + "path_id" => $model->getId() + )); + } + + protected function sortdata() + { + $model = new ilQuestionSetPoolPath((int) $_GET['path_id']); + $model->read(); + $data = $model->getNodes()->getData(); + + foreach ($data as $key => $element) { + if ($element["node_index"] != 1) { + $minimumTwo = (int) $_POST["sorting"][$element["id"]]; + $data[$key]["node_index"] = $minimumTwo > 1 ? $minimumTwo : 2; + } + } + + usort($data, function ($a, $b) { + return $a["node_index"] - $b["node_index"]; + }); + + if (!$this->conditionsAreValid($data)) { + ilUtil::sendFailure($this->plugin->txt("sorting_error_jmp_conditions"), true); + $this->redirect("ilQuestionSetPoolNodesGUI.listNodes", array( + "set_id" => (int) $_GET["set_id"], + "path_id" => (int) $_GET["path_id"] + )); + } + + if (is_array($data)) { + for ($i = 0; $i < count($data); $i++) { + $data[$i]["node_index"] = ($i + 1); + $model->getNodes()->update($data[$i]); + } + } + return $data; + } + + /** + * Returns the current tab name + * return string + */ + protected function getCurrentTab() + { + return "content"; + } + + /** + * @return array + */ + protected function getRequirements() + { + return array( + "models/class.ilQuestionSetPoolPath.php", + "tables/class.ilQuestionSetPoolNodeTableGUI.php", + "utils/abstract.ilQuestionSetPoolConditionValidator.php" + ); + } + + private function addSubTabs() + { + global $DIC; + $ilTabs = $DIC->tabs(); + + $this->ctrl->setParameter($this->controller, "set_id", (int) $_GET['set_id']); + + $ilTabs->addSubTab( + "set_questions", + $this->plugin->txt("questions"), + $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolSetQuestionsGUI.listQuestions") + ); + + $ilTabs->addSubTab( + "paths", + $this->plugin->txt("paths"), + $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolPathsGUI.listPaths") + ); + + $ilTabs->addSubTab( + "path_overview", + $this->plugin->txt("path_overview"), + $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolPathGraphGUI.showPathOverview") + ); + + $ilTabs->activateSubTab("paths"); + + $this->ctrl->setParameter($this->controller, "set_id", ""); + } + + /** + * @param $data + * + * @return bool + */ + protected function conditionsAreValid($data) + { + if (is_array($data)) { + for ($index = 1; $index < count($data); $index++) { + $node = new ilQuestionSetPoolNode($data[$index]["id"]); + $node->read(); + $node->setIndex($data[$index]["node_index"]); + + if (!ilQuestionSetPoolConditionValidator::isValid($node->getInitialCondition(), $node, $data, $this->plugin)) { + return false; + } + + foreach ($data[$index]["jump_conditions"] as $jump_condition) { + if (!ilQuestionSetPoolConditionValidator::isValid($jump_condition["jump_condition"], $node, $data, $this->plugin)) { + return false; + } + + $error = false; + for ($inner_index = 0; $inner_index <= $index; $inner_index++) { + if ($data[$inner_index]["question_fi"] == $jump_condition["question_fi"] || $jump_condition["question_fi"] == null) { + $error = false; + break; + } else { + $error = true; + } + } + if ($error) { + return false; + } + } + } + } + return true; + } } - \ No newline at end of file diff --git a/classes/controllers/class.ilQuestionSetPoolPathGUI.php b/classes/controllers/class.ilQuestionSetPoolPathGUI.php index aa11d492b7a6e99d8be93c5646dc666588a00a74..872040cda1d19351b4821ba38dcc33525a765de7 100644 --- a/classes/controllers/class.ilQuestionSetPoolPathGUI.php +++ b/classes/controllers/class.ilQuestionSetPoolPathGUI.php @@ -8,223 +8,214 @@ require_once "abstract.ilPluginControllerFormGUI.php"; * Date: 21.11.13 * Time: 10:22 * @author Thomas Joußen - */ + */ class ilQuestionSetPoolPathGUI extends ilPluginControllerFormGUI { - - protected $redirectCmd = "ilQuestionSetPoolNodesGUI.listNodes"; - - public function edit() - { - $this->redirectIfNoQuestionsInSet(); - - $model = $this->loadModel(); - $this->initForm($model); - $this->bindModelToForm($model); - $this->tpl->setContent($this->form->getHTML()); - } - - public function update() - { - $this->redirectIfNoQuestionsInSet(); - - $model = $this->loadModel(); - $this->initForm($model); - if($this->form->checkInput()) - { - $model->bindForm($this->form); - $model->update(); - ilUtil::sendSuccess($this->plugin->txt("msg_path_modified"), true); - - $this->redirect( - $this->getAfterUpdateRedirectCmd(), - $this->getAfterUpdateRedirectParams($model) - ); - } - - $this->form->setValuesByPost(); - $this->tpl->setContent($this->form->getHTML()); - } - - public function updateAndNewNode() - { - $this->redirectCmd = "ilQuestionSetPoolNodeGUI.edit"; - $this->update(); - } - - - /** - * Loads and returns the Model for the controller gui - * @return ilPluginModel - */ - protected function loadModel() - { - $model = new ilQuestionSetPoolPath((int)$_GET["path_id"]); - $model->read(); - - return $model; - } - - /** - * Initialize the PropertyFormGUI for this controller - * - * @param ilQuestionSetPoolPath $model - */ - protected function initForm($model) - { - require_once "./Services/Form/classes/class.ilPropertyFormGUI.php"; - $this->form = new ilPropertyFormGUI(); - $this->form->setTitle( - sprintf( - $this->plugin->txt("path_title"), - $model->getSet()->getTitle() - ) - ); - - $title = new ilTextInputGUI($this->plugin->txt("title"), "title"); - $title->setRequired(true); - $this->form->addItem($title); - - if($model->getId() <= 0) - { - $start_question = new ilSelectInputGUI($this->plugin->txt('start_question'), "start_question"); - $start_question->setRequired(true); - $start_question->setOptions($this->getStartQuestionOptions($model)); - $this->form->addItem($start_question); - } - - $this->ctrl->setParameter($this->controller, "path_id", (int)$model->getId()); - $this->ctrl->setParameter($this->controller, "set_id", (int)$_GET['set_id']); - $this->form->setFormAction($this->ctrl->getFormAction($this->controller)); - $this->ctrl->setParameter($this->controller, "set_id", ""); - $this->ctrl->setParameter($this->controller, "path_id", ""); - $this->form->addCommandButton("ilQuestionSetPoolPathGUI.updateAndNewNode", $this->plugin->txt("save_and_node")); - $this->form->addCommandButton("ilQuestionSetPoolPathGUI.update", $this->plugin->txt("save")); - $this->form->addCommandButton("ilQuestionSetPoolPathsGUI.listPaths", $this->plugin->txt("cancel")); - } - - /** - * @param ilQuestionSetPoolPath $model - * - * @return array - */ - protected function getStartQuestionOptions($model) - { - $options = array(); - $questions = $this->getExistingStartQuestion($model); - - if($questions == null) - { - $set = new ilQuestionSetPoolSet((int)$_GET["set_id"]); - $set->read(); - $questions = $set->getQuestionList()->getData(); - }else{ - ilUtil::sendInfo($this->plugin->txt("start_question_defined"), false); - } - - foreach ($questions as $question) - { - $options[$question['question_id']] = $question['title']; - } - - return $options; - } - - /** - * @param ilQuestionSetPoolPath $model - * - * @return array|null - */ - public function getExistingStartQuestion($model) - { - global $DIC; - $ilDB = $DIC->database(); - - $ilDB->setLimit(1, 0); - $result = $ilDB->queryF( - "SELECT q.question_id, q.title + protected $redirectCmd = "ilQuestionSetPoolNodesGUI.listNodes"; + + public function edit() + { + $this->redirectIfNoQuestionsInSet(); + + $model = $this->loadModel(); + $this->initForm($model); + $this->bindModelToForm($model); + $this->tpl->setContent($this->form->getHTML()); + } + + public function update() + { + $this->redirectIfNoQuestionsInSet(); + + $model = $this->loadModel(); + $this->initForm($model); + if ($this->form->checkInput()) { + $model->bindForm($this->form); + $model->update(); + ilUtil::sendSuccess($this->plugin->txt("msg_path_modified"), true); + + $this->redirect( + $this->getAfterUpdateRedirectCmd(), + $this->getAfterUpdateRedirectParams($model) + ); + } + + $this->form->setValuesByPost(); + $this->tpl->setContent($this->form->getHTML()); + } + + public function updateAndNewNode() + { + $this->redirectCmd = "ilQuestionSetPoolNodeGUI.edit"; + $this->update(); + } + + + /** + * Loads and returns the Model for the controller gui + * @return ilPluginModel + */ + protected function loadModel() + { + $model = new ilQuestionSetPoolPath((int) $_GET["path_id"]); + $model->read(); + + return $model; + } + + /** + * Initialize the PropertyFormGUI for this controller + * + * @param ilQuestionSetPoolPath $model + */ + protected function initForm($model) + { + $this->form = new ilPropertyFormGUI(); + $this->form->setTitle( + sprintf( + $this->plugin->txt("path_title"), + $model->getSet()->getTitle() + ) + ); + + $title = new ilTextInputGUI($this->plugin->txt("title"), "title"); + $title->setRequired(true); + $this->form->addItem($title); + + if ($model->getId() <= 0) { + $start_question = new ilSelectInputGUI($this->plugin->txt('start_question'), "start_question"); + $start_question->setRequired(true); + $start_question->setOptions($this->getStartQuestionOptions($model)); + $this->form->addItem($start_question); + } + + $this->ctrl->setParameter($this->controller, "path_id", (int) $model->getId()); + $this->ctrl->setParameter($this->controller, "set_id", (int) $_GET['set_id']); + $this->form->setFormAction($this->ctrl->getFormAction($this->controller)); + $this->ctrl->setParameter($this->controller, "set_id", ""); + $this->ctrl->setParameter($this->controller, "path_id", ""); + $this->form->addCommandButton("ilQuestionSetPoolPathGUI.updateAndNewNode", $this->plugin->txt("save_and_node")); + $this->form->addCommandButton("ilQuestionSetPoolPathGUI.update", $this->plugin->txt("save")); + $this->form->addCommandButton("ilQuestionSetPoolPathsGUI.listPaths", $this->plugin->txt("cancel")); + } + + /** + * @param ilQuestionSetPoolPath $model + * + * @return array + */ + protected function getStartQuestionOptions($model) + { + $options = array(); + $questions = $this->getExistingStartQuestion($model); + + if ($questions == null) { + $set = new ilQuestionSetPoolSet((int) $_GET["set_id"]); + $set->read(); + $questions = $set->getQuestionList()->getData(); + } else { + ilUtil::sendInfo($this->plugin->txt("start_question_defined"), false); + } + + foreach ($questions as $question) { + $options[$question['question_id']] = $question['title']; + } + + return $options; + } + + /** + * @param ilQuestionSetPoolPath $model + * + * @return array|null + */ + public function getExistingStartQuestion($model) + { + global $DIC; + $ilDB = $DIC->database(); + + $ilDB->setLimit(1, 0); + $result = $ilDB->queryF( + "SELECT q.question_id, q.title FROM qpl_questions q INNER JOIN rep_robj_xqsp_node n ON n.question_fi = q.question_id INNER JOIN rep_robj_xqsp_qs_qst qst ON qst.question_fi = q.question_id WHERE n.node_index = %s AND qst.questionset_fi = %s", - array("integer", "integer"), - array(1, $model->getSet()->getId()) - ); - - $data = $ilDB->fetchAssoc($result); - - if($data != null) - { - $data = array($data); - } - - return $data; - } - - /** - * @param ilQuestionSetPoolSet $set - * @return bool - */ - protected function doesSetHaveQuestions($set) - { - return is_array($set->getQuestionList()->getData()) ? count($set->getQuestionList()->getData()) > 0 : 0; - } - - /** - * Returns the current tab name - * return string - */ - protected function getCurrentTab() - { - return "content"; - } - - /** - * @return array - */ - protected function getRequirements() - { - return array( - 'models/class.ilQuestionSetPoolPath.php', - "models/class.ilQuestionSetPoolSet.php" - ); - } - - /** - * Get the redirect action after an update was successful - * @return string - */ - protected function getAfterUpdateRedirectCmd() - { - return $this->redirectCmd; - } - - /** - * @param ilQuestionSetPoolPath $model - * - * @return array - */ - protected function getAfterUpdateRedirectParams($model = NULL) - { - return array( - "set_id" => (int)$_GET['set_id'], - "path_id" => ($model == NULL ? NULL : (int)$model->getId()) - ); - } - - protected function redirectIfNoQuestionsInSet() - { - $set = new ilQuestionSetPoolSet((int)$_GET["set_id"]); - $set->read(); - - if (!$this->doesSetHaveQuestions($set)) - { - ilUtil::sendFailure($this->plugin->txt("no_questions_in_set"), true); - $this->redirect( - $this->getAfterUpdateRedirectCmd(), - $this->getAfterUpdateRedirectParams(null) - ); - } - } + array("integer", "integer"), + array(1, $model->getSet()->getId()) + ); + + $data = $ilDB->fetchAssoc($result); + + if ($data != null) { + $data = array($data); + } + + return $data; + } + + /** + * @param ilQuestionSetPoolSet $set + * @return bool + */ + protected function doesSetHaveQuestions($set) + { + return is_array($set->getQuestionList()->getData()) ? count($set->getQuestionList()->getData()) > 0 : 0; + } + + /** + * Returns the current tab name + * return string + */ + protected function getCurrentTab() + { + return "content"; + } + + /** + * @return array + */ + protected function getRequirements() + { + return array( + 'models/class.ilQuestionSetPoolPath.php', + "models/class.ilQuestionSetPoolSet.php" + ); + } + + /** + * Get the redirect action after an update was successful + * @return string + */ + protected function getAfterUpdateRedirectCmd() + { + return $this->redirectCmd; + } + + /** + * @param ilQuestionSetPoolPath $model + * + * @return array + */ + protected function getAfterUpdateRedirectParams($model = null) + { + return array( + "set_id" => (int) $_GET['set_id'], + "path_id" => ($model == null ? null : (int) $model->getId()) + ); + } + + protected function redirectIfNoQuestionsInSet() + { + $set = new ilQuestionSetPoolSet((int) $_GET["set_id"]); + $set->read(); + + if (!$this->doesSetHaveQuestions($set)) { + ilUtil::sendFailure($this->plugin->txt("no_questions_in_set"), true); + $this->redirect( + $this->getAfterUpdateRedirectCmd(), + $this->getAfterUpdateRedirectParams(null) + ); + } + } } - \ No newline at end of file diff --git a/classes/controllers/class.ilQuestionSetPoolPathGraphGUI.php b/classes/controllers/class.ilQuestionSetPoolPathGraphGUI.php index ff1b8d1cec4c1c30b62123e4048d9477a79f4145..b01ab8893a15c2f604ac635f02fd709d8727c7c8 100644 --- a/classes/controllers/class.ilQuestionSetPoolPathGraphGUI.php +++ b/classes/controllers/class.ilQuestionSetPoolPathGraphGUI.php @@ -4,243 +4,234 @@ require_once dirname(__FILE__) . '/../../vendor/autoload.php'; /** * Class ilQuestionSetPoolPathGraphGUI */ -class ilQuestionSetPoolPathGraphGUI extends ilPluginControllerGUI +class ilQuestionSetPoolPathGraphGUI extends ilPluginControllerGUI { - /** - * @param ilObjQuestionSetPoolGUI $controller - */ - public function __construct(ilObjQuestionSetPoolGUI $controller) - { - parent::__construct($controller); - $this->addSubTabs(); - } - - /** - * - */ - public function showPathOverview() - { - $set = new ilQuestionSetPoolSet((int)$_GET['set_id']); - $set->read(); - - $template = new ilTemplate('tpl.il_xqsp_path_overview.html', true, true, 'Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool'); - - $this->renderPathTable($set, $template); - $this->ctrl->setParameter($this->controller, 'set_id', (int)$_GET['set_id']); - - $template->setVariable('SET_TITLE', $set->getTitle()); - $template->setVariable('GRAPH_TITLE', $this->plugin->txt("graph_viz_title")); - $template->setVariable('PATH_GRAPH_SRC', $this->renderPathGraph()); - - $this->tpl->setContent($template->get()); - } - - /** - * - */ - public function renderPathGraph() - { - $set = new ilQuestionSetPoolSet((int)$_GET['set_id']); - $set->read(); - - $graph = new Fhaculty\Graph\Graph(); - - $pathes = $set->getPathList()->getData(); - foreach($pathes as $path) - { - $model = new ilQuestionSetPoolPath($path['id']); - $model->read(); - $nodes = $model->getNodes()->getData(); - - $num_nodes = is_array($nodes) ? count($nodes): 0; - for($i = 0; $i < $num_nodes; $i++) - { - $nodeId = 'Q' . $nodes[$i]['question_index']; - try { - $graph->getVertex($nodeId); - } catch (Exception $exception) { - $vertex = $graph->createVertex($nodeId); - $vertex->setAttribute('graphviz.shape', 'box'); - } - } - } - $vertex = $graph->createVertex($this->controller->plugin->txt('end_of_set')); - $vertex->setAttribute('graphviz.shape', 'box'); - - $edges = array(); - - foreach($pathes as $path) - { - $model = new ilQuestionSetPoolPath($path['id']); - $model->read(); - $nodes = $model->getNodes()->getData(); - $num_nodes = is_array($nodes) ? count($nodes): 0; - for($i = 0; $i < $num_nodes; $i++) - { - if(isset($nodes[$i + 1])) - { - $edges["Q".$nodes[$i]['question_index']]["Q".$nodes[$i + 1]['question_index']]['initial'][trim($nodes[$i]['initial_condition'])] = $nodes[$i]['initial_condition']; - } - else - { - $edges["Q".$nodes[$i]['question_index']][$this->controller->plugin->txt('end_of_set')]['initial'][trim($nodes[$i]['initial_condition'])] = $nodes[$i]['initial_condition']; - } - - foreach((array)$nodes[$i]['jump_conditions'] as $condition) - { - if($condition['question_index']) - { - $edges["Q".$nodes[$i]['question_index']]["Q".$condition['question_index']]['jump'][trim($condition['jump_condition'])] = $condition['jump_condition']; - } - else - { - $edges["Q".$nodes[$i]['question_index']][$this->controller->plugin->txt('end_of_set')]['end'][trim($condition['jump_condition'])] = $condition['jump_condition']; - } - } - } - } - - foreach($edges as $node_source => $data_target) - { - foreach($data_target as $node_target => $data_conditions) - { - if(is_array($data_conditions['initial']) && count($data_conditions['initial']) > 0) - { - $initial = join("\n", array_filter($data_conditions['initial'])); - $edge = new Fhaculty\Graph\Edge\Directed($graph->getVertex($node_source), $graph->getVertex($node_target)); - $edge->setAttribute('graphviz.color', 'darkgreen'); - $edge->setAttribute('graphviz.label', $initial); - } - if(is_array($data_conditions['jump']) && count($data_conditions['jump']) > 0) - { - $jump = join("\n", array_filter($data_conditions['jump'])); - $edge = new Fhaculty\Graph\Edge\Directed($graph->getVertex($node_source), $graph->getVertex($node_target)); - $edge->setAttribute('graphviz.color', 'blue'); - $edge->setAttribute('graphviz.label', $jump); - } - if(is_array($data_conditions['end']) && count($data_conditions['end']) > 0) - { - $end = join("\n", array_filter($data_conditions['end'])); - $edge = new Fhaculty\Graph\Edge\Directed($graph->getVertex($node_source), $graph->getVertex($node_target)); - $edge->setAttribute('graphviz.color', 'red'); - $edge->setAttribute('graphviz.label', $end); - } - } - } - - $graphviz = new Graphp\GraphViz\GraphViz(); - $imageSrc = $graphviz->createImageSrc($graph); - return $imageSrc; - } - - /** - * Returns the current tab name - * return string - */ - protected function getCurrentTab() - { - return 'content'; - } - - /** - * @return array - */ - protected function getRequirements() - { - return array( - 'models/class.ilQuestionSetPoolSet.php', - 'models/class.ilQuestionSetPoolPath.php' - ); - } - - private function addSubTabs() - { - global $DIC; - $ilTabs = $DIC->tabs(); - - $this->ctrl->setParameter($this->controller, "set_id", (int)$_GET['set_id']); - - $ilTabs->addSubTab("set_questions", $this->plugin->txt("questions"), - $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolSetQuestionsGUI.listQuestions")); - - $ilTabs->addSubTab("paths", $this->plugin->txt("paths"), - $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolPathsGUI.listPaths")); - - $ilTabs->addSubTab("path_overview", $this->plugin->txt("path_overview"), - $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolPathGraphGUI.showPathOverview")); - - $ilTabs->activateSubTab("path_overview"); - - $this->ctrl->setParameter($this->controller, "set_id", ""); - } - - /** - * @param $set - * @param $template - */ - protected function renderPathTable($set, $template) - { - $pathes = $set->getPathList()->getData(); - foreach ($pathes as $path_data) - { - $path = new ilQuestionSetPoolPath($path_data['id']); - $path->read(); - $nodes = $path->getNodes()->getData(); - - foreach ($nodes as $node) - { - $template->setCurrentBlock("initial_condition"); - $condition = $node["initial_condition"]; - if ($condition == "") - { - $condition = $this->plugin->txt("empty_condition"); - } - $template->setVariable("INITIAL_CONDITION", $condition); - $template->parseCurrentBlock(); - - $template->setCurrentBlock("question"); - $template->setVariable("QUESTION_INDEX", $node["question_index"]); - $template->parseCurrentBlock(); - - if (is_array($node["jump_conditions"]) && count($node["jump_conditions"]) > 0) - { - foreach ($node["jump_conditions"] as $jump_condition) - { - $condition = ""; - - if ($jump_condition["question_index"] != null) - { - $condition .= $this->plugin->txt("target_question") . ": "; - $condition .= "Q" . $jump_condition["question_index"]; - } - else - { - $condition .= $this->plugin->txt("tst_termination"); - } - $template->setCurrentBlock("jump_condition"); - $template->setVariable("JUMP_CONDITION", $jump_condition["jump_condition"]); - $template->setVariable("TARGET", $condition . "
". $this->plugin->txt("repititions") . ": " . $jump_condition["repititions"]); - $template->parseCurrentBlock(); - } - } - else - { - $template->setCurrentBlock("jump_condition"); - $template->setVariable("JUMP_CONDITION", " "); - $template->setVariable("TARGET", " "); - $template->parseCurrentBlock(); - } - $template->setCurrentBlock("jump_conditions"); - $template->parseCurrentBlock(); - } - - $template->setCurrentBlock("test_end"); - $template->setVariable("END_TEST", $this->plugin->txt('end_of_test')); - $template->parseCurrentBlock(); - - $template->setCurrentBlock("path"); - $template->setVariable("PATH_TITLE", $path->getTitle()); - $template->parseCurrentBlock(); - } - } + /** + * @param ilObjQuestionSetPoolGUI $controller + */ + public function __construct(ilObjQuestionSetPoolGUI $controller) + { + parent::__construct($controller); + $this->addSubTabs(); + } + + /** + * + */ + public function showPathOverview() + { + $set = new ilQuestionSetPoolSet((int) $_GET['set_id']); + $set->read(); + + $template = new ilTemplate('tpl.il_xqsp_path_overview.html', true, true, 'Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool'); + + $this->renderPathTable($set, $template); + $this->ctrl->setParameter($this->controller, 'set_id', (int) $_GET['set_id']); + + $template->setVariable('SET_TITLE', $set->getTitle()); + $template->setVariable('GRAPH_TITLE', $this->plugin->txt("graph_viz_title")); + + $components = []; + try { + $template->setVariable('PATH_GRAPH_SRC', $this->renderPathGraph()); + $components[] = $this->uiFactory->legacy($template->get()); + } catch (Exception $e) { + $components[] = $this->uiFactory->legacy($template->get()); + $components[] = $this->uiFactory->messageBox()->failure('Could not display graph: ' . $e->getMessage()); + } + + $this->tpl->setContent($this->uiRenderer->render($components)); + } + + /** + * + */ + public function renderPathGraph() + { + $set = new ilQuestionSetPoolSet((int) $_GET['set_id']); + $set->read(); + + $graph = new Fhaculty\Graph\Graph(); + + $pathes = $set->getPathList()->getData(); + foreach ($pathes as $path) { + $model = new ilQuestionSetPoolPath($path['id']); + $model->read(); + $nodes = $model->getNodes()->getData(); + + $num_nodes = is_array($nodes) ? count($nodes): 0; + for ($i = 0; $i < $num_nodes; $i++) { + $nodeId = 'Q' . $nodes[$i]['question_index']; + try { + $graph->getVertex($nodeId); + } catch (Exception $exception) { + $vertex = $graph->createVertex($nodeId); + $vertex->setAttribute('graphviz.shape', 'box'); + } + } + } + $vertex = $graph->createVertex($this->controller->plugin->txt('end_of_set')); + $vertex->setAttribute('graphviz.shape', 'box'); + + $edges = array(); + + foreach ($pathes as $path) { + $model = new ilQuestionSetPoolPath($path['id']); + $model->read(); + $nodes = $model->getNodes()->getData(); + $num_nodes = is_array($nodes) ? count($nodes): 0; + for ($i = 0; $i < $num_nodes; $i++) { + if (isset($nodes[$i + 1])) { + $edges["Q" . $nodes[$i]['question_index']]["Q" . $nodes[$i + 1]['question_index']]['initial'][trim($nodes[$i]['initial_condition'])] = $nodes[$i]['initial_condition']; + } else { + $edges["Q" . $nodes[$i]['question_index']][$this->controller->plugin->txt('end_of_set')]['initial'][trim($nodes[$i]['initial_condition'])] = $nodes[$i]['initial_condition']; + } + + foreach ((array) $nodes[$i]['jump_conditions'] as $condition) { + if ($condition['question_index']) { + $edges["Q" . $nodes[$i]['question_index']]["Q" . $condition['question_index']]['jump'][trim($condition['jump_condition'])] = $condition['jump_condition']; + } else { + $edges["Q" . $nodes[$i]['question_index']][$this->controller->plugin->txt('end_of_set')]['end'][trim($condition['jump_condition'])] = $condition['jump_condition']; + } + } + } + } + + foreach ($edges as $node_source => $data_target) { + foreach ($data_target as $node_target => $data_conditions) { + if (is_array($data_conditions['initial']) && count($data_conditions['initial']) > 0) { + $initial = join("\n", array_filter($data_conditions['initial'])); + $edge = new Fhaculty\Graph\Edge\Directed($graph->getVertex($node_source), $graph->getVertex($node_target)); + $edge->setAttribute('graphviz.color', 'darkgreen'); + $edge->setAttribute('graphviz.label', $initial); + } + if (is_array($data_conditions['jump']) && count($data_conditions['jump']) > 0) { + $jump = join("\n", array_filter($data_conditions['jump'])); + $edge = new Fhaculty\Graph\Edge\Directed($graph->getVertex($node_source), $graph->getVertex($node_target)); + $edge->setAttribute('graphviz.color', 'blue'); + $edge->setAttribute('graphviz.label', $jump); + } + if (is_array($data_conditions['end']) && count($data_conditions['end']) > 0) { + $end = join("\n", array_filter($data_conditions['end'])); + $edge = new Fhaculty\Graph\Edge\Directed($graph->getVertex($node_source), $graph->getVertex($node_target)); + $edge->setAttribute('graphviz.color', 'red'); + $edge->setAttribute('graphviz.label', $end); + } + } + } + + $graphviz = new Graphp\GraphViz\GraphViz(); + $imageSrc = $graphviz->createImageSrc($graph); + return $imageSrc; + } + + /** + * Returns the current tab name + * return string + */ + protected function getCurrentTab() + { + return 'content'; + } + + /** + * @return array + */ + protected function getRequirements() + { + return array( + 'models/class.ilQuestionSetPoolSet.php', + 'models/class.ilQuestionSetPoolPath.php' + ); + } + + private function addSubTabs() + { + global $DIC; + $ilTabs = $DIC->tabs(); + + $this->ctrl->setParameter($this->controller, "set_id", (int) $_GET['set_id']); + + $ilTabs->addSubTab( + "set_questions", + $this->plugin->txt("questions"), + $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolSetQuestionsGUI.listQuestions") + ); + + $ilTabs->addSubTab( + "paths", + $this->plugin->txt("paths"), + $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolPathsGUI.listPaths") + ); + + $ilTabs->addSubTab( + "path_overview", + $this->plugin->txt("path_overview"), + $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolPathGraphGUI.showPathOverview") + ); + + $ilTabs->activateSubTab("path_overview"); + + $this->ctrl->setParameter($this->controller, "set_id", ""); + } + + /** + * @param $set + * @param $template + */ + protected function renderPathTable($set, $template) + { + $pathes = $set->getPathList()->getData(); + foreach ($pathes as $path_data) { + $path = new ilQuestionSetPoolPath($path_data['id']); + $path->read(); + $nodes = $path->getNodes()->getData(); + + foreach ($nodes as $node) { + $template->setCurrentBlock("initial_condition"); + $condition = $node["initial_condition"]; + if ($condition == "") { + $condition = $this->plugin->txt("empty_condition"); + } + $template->setVariable("INITIAL_CONDITION", $condition); + $template->parseCurrentBlock(); + + $template->setCurrentBlock("question"); + $template->setVariable("QUESTION_INDEX", $node["question_index"]); + $template->parseCurrentBlock(); + + if (is_array($node["jump_conditions"]) && count($node["jump_conditions"]) > 0) { + foreach ($node["jump_conditions"] as $jump_condition) { + $condition = ""; + + if ($jump_condition["question_index"] != null) { + $condition .= $this->plugin->txt("target_question") . ": "; + $condition .= "Q" . $jump_condition["question_index"]; + } else { + $condition .= $this->plugin->txt("tst_termination"); + } + $template->setCurrentBlock("jump_condition"); + $template->setVariable("JUMP_CONDITION", $jump_condition["jump_condition"]); + $template->setVariable("TARGET", $condition . "
" . $this->plugin->txt("repititions") . ": " . $jump_condition["repititions"]); + $template->parseCurrentBlock(); + } + } else { + $template->setCurrentBlock("jump_condition"); + $template->setVariable("JUMP_CONDITION", " "); + $template->setVariable("TARGET", " "); + $template->parseCurrentBlock(); + } + $template->setCurrentBlock("jump_conditions"); + $template->parseCurrentBlock(); + } + + $template->setCurrentBlock("test_end"); + $template->setVariable("END_TEST", $this->plugin->txt('end_of_test')); + $template->parseCurrentBlock(); + + $template->setCurrentBlock("path"); + $template->setVariable("PATH_TITLE", $path->getTitle()); + $template->parseCurrentBlock(); + } + } } diff --git a/classes/controllers/class.ilQuestionSetPoolPathsGUI.php b/classes/controllers/class.ilQuestionSetPoolPathsGUI.php index 194c28da93ba4ceec4e369df77b004c8bfc03de7..f18b98fb5a9631afad6b4ade9cc607124bc77ba4 100644 --- a/classes/controllers/class.ilQuestionSetPoolPathsGUI.php +++ b/classes/controllers/class.ilQuestionSetPoolPathsGUI.php @@ -8,309 +8,281 @@ require_once "abstract.ilPluginControllerTableGUI.php"; * Date: 08.10.13 * Time: 11:11 * @author Thomas Joußen - */ + */ class ilQuestionSetPoolPathsGUI extends ilPluginControllerTableGUI { - - public function __construct(ilObjQuestionSetPoolGUI $controller) - { - parent::__construct($controller); - $this->addSubTabs(); - } - - public function listPaths() - { - if($this->controller->object instanceof ilObjQuestionSetPool) - { - $this->addToolbarButton("back_to_set_list", "ilQuestionSetPoolSetsGUI.show"); - } - - $this->addToolbarButton("add_path", "ilQuestionSetPoolPathGUI.edit", array( - "set_id" => (int)$_GET['set_id'] - )); - - $this->ctrl->setParameter($this->controller, 'set_id', (int)$_GET['set_id']); - $table = new ilQuestionSetPoolPathTableGUI($this->controller, $this->plugin, (int)$_GET['set_id']); - - $set = new ilQuestionSetPoolSet((int)$_GET['set_id']); - $set->read(); - - $table->setModelList($set->getPathList()); - $table->setTitle($set->getTitle() . " - " . $this->plugin->txt('paths')); - $table->addCommandButton("ilQuestionSetPoolPathsGUI.saveSorting", $this->plugin->txt("save_sorting")); - $table->populate(); - - $this->tpl->setContent($table->getHTML()); - } - - public function saveSorting() - { - $this->doSorting(); - - ilUtil::sendSuccess($this->plugin->txt("saved_sorting"), true); - $this->redirect("ilQuestionSetPoolPathsGUI.listPaths", array( - "set_id" => (int)$_GET["set_id"] - )); - } - - public function copy() - { - if($this->dataSelected("path_id")) - { - $set = new ilQuestionSetPoolSet((int)$_GET['set_id']); - $set->read(); - $path_titles = $set->getPathTitles(); - foreach($_POST["path_id"] as $path_id) - { - $path = new ilQuestionSetPoolPath($path_id); - $path->read(); - - $data = $path->getSet()->getQuestionList()->getData(); - $question_ids = array(); - foreach($data as $element) - { - $question_ids[$element["question_id"]] = $element["question_id"]; - } - - $title = $path->getTitle(); - $i = 2; - while(in_array($title . ' (' . $i . ')', $path_titles)) - { - $i++; - } - - $title .= ' (' . $i . ')'; - - $path_titles[] = $title; - - $path->duplicate($question_ids, $title); - } - - //$this->doSorting(); - - ilUtil::sendInfo($this->plugin->txt('success_path_copy')); - $this->redirect("ilQuestionSetPoolPathsGUI.listPaths", array( - "set_id" => $_GET["set_id"] - )); - } - else - { - ilUtil::sendInfo($this->plugin->txt('no_path_selected')); - $this->listPaths(); - return; - }; - } - - /** - * Called if a single path should be deleted, calls \ilQuestionSetPoolPathsGUI::removeMultipleConfirmation do show the confirmation screen - */ - public function removeConfirmation() - { - if(!isset($_GET['path_id'])) - { - ilUtil::sendInfo($this->plugin->txt('no_path_selected')); - $this->listPaths(); - return; - } - - $_POST['path_id'] = array((int)$_GET['path_id']); - $this->removeMultipleConfirmation(); - } - - /** - * Shows an confirmation screen for the selected paths - */ - public function removeMultipleConfirmation() - { - if(!isset($_POST['path_id']) || !is_array($_POST['path_id'])) - { - ilUtil::sendInfo($this->plugin->txt('no_path_selected')); - $this->listPaths(); - return; - } - - $this->tabs->activateSubTab('paths'); - - $set = new ilQuestionSetPoolSet((int)$_GET["set_id"]); - $set->read(); - - require_once 'Services/Utilities/classes/class.ilConfirmationGUI.php'; - $confirmation = new ilConfirmationGUI(); - - $num_items = 0; - $missing_perm_path_titles = array(); - foreach($_POST['path_id'] as $path_id) - { - $path = new ilQuestionSetPoolPath((int)$path_id); - $path->read(); - if($path->getSet()->getContainerObjId() == $this->controller->object->getId()) - { - $confirmation->addItem('path_id[]', $path->getId(), $path->getTitle()); - ++$num_items; - } - else - { - $missing_perm_path_titles[] = $path->getTitle(); - } - } - - if(1 == $num_items) - { - $confirmation->setHeaderText($this->plugin->txt('confirm_delete_paths_s')); - } - else if($num_items > 1) - { - $confirmation->setHeaderText($this->plugin->txt('confirm_delete_paths_p')); - } - - $missing_perm_path_titles = array_filter($missing_perm_path_titles); - if(is_array($missing_perm_path_titles)) - { - if(1 == count($missing_perm_path_titles)) - { - ilUtil::sendFailure(sprintf($this->plugin->txt('paths_del_perm_err_s'), implode(', ', $missing_perm_path_titles))); - } - else if(count($missing_perm_path_titles) > 1) - { - ilUtil::sendFailure(sprintf($this->plugin->txt('paths_del_perm_err_p'), implode(', ', $missing_perm_path_titles))); - } - } - if(!$num_items) - { - $this->listPaths(); - return; - } - - $this->ctrl->setParameter($this->controller, 'set_id', $set->getId()); - $confirmation->setFormAction($this->ctrl->getFormAction($this->controller, __CLASS__ . '.listPaths')); - $this->ctrl->setParameter($this->controller, 'set_id', ''); - $confirmation->setCancel($this->plugin->txt('cancel'), __CLASS__ . '.listPaths'); - $confirmation->setConfirm($this->plugin->txt('confirm'), __CLASS__ . '.remove'); - $this->tpl->setContent($confirmation->getHTML()); - } - - /** - * Finally deletes (cascading) the selected paths - */ - public function remove() - { - if(!isset($_POST['path_id']) || !is_array($_POST['path_id'])) - { - ilUtil::sendInfo($this->plugin->txt('no_path_selected')); - $this->listPaths(); - return; - } - - $set = new ilQuestionSetPoolSet((int)$_GET["set_id"]); - $set->read(); - - $num_items = 0; - $missing_perm_path_titles = array(); - foreach($_POST['path_id'] as $path_id) - { - $path = new ilQuestionSetPoolPath((int)$path_id); - $path->read(); - if($path->getSet()->getContainerObjId() == $this->controller->object->getId()) - { - ++$num_items; - $path->remove(); - } - else - { - $missing_perm_path_titles[] = $path->getTitle(); - } - } - - if(1 == $num_items) - { - ilUtil::sendSuccess($this->plugin->txt('deleted_paths_s'), true); - } - else if($num_items > 1) - { - ilUtil::sendSuccess($this->plugin->txt('deleted_paths_p'), true); - } - - $missing_perm_path_titles = array_filter($missing_perm_path_titles); - if(is_array($missing_perm_path_titles)) - { - if(1 == count($missing_perm_path_titles)) - { - ilUtil::sendFailure(sprintf($this->plugin->txt('paths_del_perm_err_s'), implode(', ', $missing_perm_path_titles))); - } - else if(count($missing_perm_path_titles) > 1) - { - ilUtil::sendFailure(sprintf($this->plugin->txt('paths_del_perm_err_p'), implode(', ', $missing_perm_path_titles))); - } - } - $this->ctrl->setParameter($this->controller, 'set_id', $set->getId()); - $this->redirect(__CLASS__ . '.listPaths'); - } - - /** - * Returns the current tab name - * return string - */ - protected function getCurrentTab() - { - return "content"; - } - - /** - * @return array - */ - protected function getRequirements() - { - return array( - "tables/class.ilQuestionSetPoolPathTableGUI.php", - "models/class.ilQuestionSetPoolPath.php", - "models/class.ilQuestionSetPoolSet.php" - ); - } - - private function addSubTabs() - { - global $DIC; - $ilTabs = $DIC->tabs(); - - $this->ctrl->setParameter($this->controller, "set_id", (int)$_GET['set_id']); - - $ilTabs->addSubTab("set_questions", $this->plugin->txt("questions"), - $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolSetQuestionsGUI.listQuestions")); - - $ilTabs->addSubTab("paths", $this->plugin->txt("paths"), - $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolPathsGUI.listPaths")); - - $ilTabs->addSubTab("path_overview", $this->plugin->txt("path_overview"), - $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolPathGraphGUI.showPathOverview")); - - $ilTabs->activateSubTab("paths"); - - $this->ctrl->setParameter($this->controller, "set_id", ""); - } - - protected function doSorting() - { - $model = new ilQuestionSetPoolSet((int)$_GET['set_id']); - $model->read(); - $data = $model->getPathList()->getData(); - - foreach($data as $key => $element) - { - $data[$key]["path_index"] = (int)$_POST["sorting"][$element["id"]]; - } - - usort( - $data, function ($a, $b) { - return $a["path_index"] - $b["path_index"]; - } - ); - if(is_array($data)) - { - for($i = 0; $i < count($data); $i++) - { - $data[$i]["path_index"] = ($i + 1); - $model->getPathList()->update($data[$i]); - } - } - } -} \ No newline at end of file + public function __construct(ilObjQuestionSetPoolGUI $controller) + { + parent::__construct($controller); + $this->addSubTabs(); + } + + public function listPaths() + { + if ($this->controller->object instanceof ilObjQuestionSetPool) { + $this->addToolbarButton("back_to_set_list", "ilQuestionSetPoolSetsGUI.show"); + } + + $this->addToolbarButton("add_path", "ilQuestionSetPoolPathGUI.edit", array( + "set_id" => (int) $_GET['set_id'] + )); + + $this->ctrl->setParameter($this->controller, 'set_id', (int) $_GET['set_id']); + $table = new ilQuestionSetPoolPathTableGUI($this->controller, $this->plugin, (int) $_GET['set_id']); + + $set = new ilQuestionSetPoolSet((int) $_GET['set_id']); + $set->read(); + + $table->setModelList($set->getPathList()); + $table->setTitle($set->getTitle() . " - " . $this->plugin->txt('paths')); + $table->addCommandButton("ilQuestionSetPoolPathsGUI.saveSorting", $this->plugin->txt("save_sorting")); + $table->populate(); + + $this->tpl->setContent($table->getHTML()); + } + + public function saveSorting() + { + $this->doSorting(); + + ilUtil::sendSuccess($this->plugin->txt("saved_sorting"), true); + $this->redirect("ilQuestionSetPoolPathsGUI.listPaths", array( + "set_id" => (int) $_GET["set_id"] + )); + } + + public function copy() + { + if ($this->dataSelected("path_id")) { + $set = new ilQuestionSetPoolSet((int) $_GET['set_id']); + $set->read(); + $path_titles = $set->getPathTitles(); + foreach ($_POST["path_id"] as $path_id) { + $path = new ilQuestionSetPoolPath($path_id); + $path->read(); + + $data = $path->getSet()->getQuestionList()->getData(); + $question_ids = array(); + foreach ($data as $element) { + $question_ids[$element["question_id"]] = $element["question_id"]; + } + + $title = $path->getTitle(); + $i = 2; + while (in_array($title . ' (' . $i . ')', $path_titles)) { + $i++; + } + + $title .= ' (' . $i . ')'; + + $path_titles[] = $title; + + $path->duplicate($question_ids, $title); + } + + //$this->doSorting(); + + ilUtil::sendInfo($this->plugin->txt('success_path_copy')); + $this->redirect("ilQuestionSetPoolPathsGUI.listPaths", array( + "set_id" => $_GET["set_id"] + )); + } else { + ilUtil::sendInfo($this->plugin->txt('no_path_selected')); + $this->listPaths(); + return; + }; + } + + /** + * Called if a single path should be deleted, calls \ilQuestionSetPoolPathsGUI::removeMultipleConfirmation do show the confirmation screen + */ + public function removeConfirmation() + { + if (!isset($_GET['path_id'])) { + ilUtil::sendInfo($this->plugin->txt('no_path_selected')); + $this->listPaths(); + return; + } + + $_POST['path_id'] = array((int) $_GET['path_id']); + $this->removeMultipleConfirmation(); + } + + /** + * Shows an confirmation screen for the selected paths + */ + public function removeMultipleConfirmation() + { + if (!isset($_POST['path_id']) || !is_array($_POST['path_id'])) { + ilUtil::sendInfo($this->plugin->txt('no_path_selected')); + $this->listPaths(); + return; + } + + $this->tabs->activateSubTab('paths'); + + $set = new ilQuestionSetPoolSet((int) $_GET["set_id"]); + $set->read(); + + $confirmation = new ilConfirmationGUI(); + + $num_items = 0; + $missing_perm_path_titles = array(); + foreach ($_POST['path_id'] as $path_id) { + $path = new ilQuestionSetPoolPath((int) $path_id); + $path->read(); + if ($path->getSet()->getContainerObjId() == $this->controller->object->getId()) { + $confirmation->addItem('path_id[]', $path->getId(), $path->getTitle()); + ++$num_items; + } else { + $missing_perm_path_titles[] = $path->getTitle(); + } + } + + if (1 == $num_items) { + $confirmation->setHeaderText($this->plugin->txt('confirm_delete_paths_s')); + } elseif ($num_items > 1) { + $confirmation->setHeaderText($this->plugin->txt('confirm_delete_paths_p')); + } + + $missing_perm_path_titles = array_filter($missing_perm_path_titles); + if (is_array($missing_perm_path_titles)) { + if (1 == count($missing_perm_path_titles)) { + ilUtil::sendFailure(sprintf($this->plugin->txt('paths_del_perm_err_s'), implode(', ', $missing_perm_path_titles))); + } elseif (count($missing_perm_path_titles) > 1) { + ilUtil::sendFailure(sprintf($this->plugin->txt('paths_del_perm_err_p'), implode(', ', $missing_perm_path_titles))); + } + } + if (!$num_items) { + $this->listPaths(); + return; + } + + $this->ctrl->setParameter($this->controller, 'set_id', $set->getId()); + $confirmation->setFormAction($this->ctrl->getFormAction($this->controller, __CLASS__ . '.listPaths')); + $this->ctrl->setParameter($this->controller, 'set_id', ''); + $confirmation->setCancel($this->plugin->txt('cancel'), __CLASS__ . '.listPaths'); + $confirmation->setConfirm($this->plugin->txt('confirm'), __CLASS__ . '.remove'); + $this->tpl->setContent($confirmation->getHTML()); + } + + /** + * Finally deletes (cascading) the selected paths + */ + public function remove() + { + if (!isset($_POST['path_id']) || !is_array($_POST['path_id'])) { + ilUtil::sendInfo($this->plugin->txt('no_path_selected')); + $this->listPaths(); + return; + } + + $set = new ilQuestionSetPoolSet((int) $_GET["set_id"]); + $set->read(); + + $num_items = 0; + $missing_perm_path_titles = array(); + foreach ($_POST['path_id'] as $path_id) { + $path = new ilQuestionSetPoolPath((int) $path_id); + $path->read(); + if ($path->getSet()->getContainerObjId() == $this->controller->object->getId()) { + ++$num_items; + $path->remove(); + } else { + $missing_perm_path_titles[] = $path->getTitle(); + } + } + + if (1 == $num_items) { + ilUtil::sendSuccess($this->plugin->txt('deleted_paths_s'), true); + } elseif ($num_items > 1) { + ilUtil::sendSuccess($this->plugin->txt('deleted_paths_p'), true); + } + + $missing_perm_path_titles = array_filter($missing_perm_path_titles); + if (is_array($missing_perm_path_titles)) { + if (1 == count($missing_perm_path_titles)) { + ilUtil::sendFailure(sprintf($this->plugin->txt('paths_del_perm_err_s'), implode(', ', $missing_perm_path_titles))); + } elseif (count($missing_perm_path_titles) > 1) { + ilUtil::sendFailure(sprintf($this->plugin->txt('paths_del_perm_err_p'), implode(', ', $missing_perm_path_titles))); + } + } + $this->ctrl->setParameter($this->controller, 'set_id', $set->getId()); + $this->redirect(__CLASS__ . '.listPaths'); + } + + /** + * Returns the current tab name + * return string + */ + protected function getCurrentTab() + { + return "content"; + } + + /** + * @return array + */ + protected function getRequirements() + { + return array( + "tables/class.ilQuestionSetPoolPathTableGUI.php", + "models/class.ilQuestionSetPoolPath.php", + "models/class.ilQuestionSetPoolSet.php" + ); + } + + private function addSubTabs() + { + global $DIC; + $ilTabs = $DIC->tabs(); + + $this->ctrl->setParameter($this->controller, "set_id", (int) $_GET['set_id']); + + $ilTabs->addSubTab( + "set_questions", + $this->plugin->txt("questions"), + $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolSetQuestionsGUI.listQuestions") + ); + + $ilTabs->addSubTab( + "paths", + $this->plugin->txt("paths"), + $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolPathsGUI.listPaths") + ); + + $ilTabs->addSubTab( + "path_overview", + $this->plugin->txt("path_overview"), + $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolPathGraphGUI.showPathOverview") + ); + + $ilTabs->activateSubTab("paths"); + + $this->ctrl->setParameter($this->controller, "set_id", ""); + } + + protected function doSorting() + { + $model = new ilQuestionSetPoolSet((int) $_GET['set_id']); + $model->read(); + $data = $model->getPathList()->getData(); + + foreach ($data as $key => $element) { + $data[$key]["path_index"] = (int) $_POST["sorting"][$element["id"]]; + } + + usort( + $data, + function ($a, $b) { + return $a["path_index"] - $b["path_index"]; + } + ); + if (is_array($data)) { + for ($i = 0; $i < count($data); $i++) { + $data[$i]["path_index"] = ($i + 1); + $model->getPathList()->update($data[$i]); + } + } + } +} diff --git a/classes/controllers/class.ilQuestionSetPoolPropertiesGUI.php b/classes/controllers/class.ilQuestionSetPoolPropertiesGUI.php index db6089f57ba5be15ba1a738e3eaa1408c3bd4ea0..a13c6fea825926fd8fb9b09d182b5cac11c9d455 100644 --- a/classes/controllers/class.ilQuestionSetPoolPropertiesGUI.php +++ b/classes/controllers/class.ilQuestionSetPoolPropertiesGUI.php @@ -8,101 +8,95 @@ require_once "abstract.ilPluginControllerFormGUI.php"; * Date: 01.10.13 * Time: 09:56 * @author Thomas Joußen - */ + */ class ilQuestionSetPoolPropertiesGUI extends ilPluginControllerFormGUI { + protected function initForm($model) + { + $this->form = new ilPropertyFormGUI(); - protected function initForm($model) - { - require_once "./Services/Form/classes/class.ilPropertyFormGUI.php"; - $this->form = new ilPropertyFormGUI(); + $title = new ilTextInputGUI($this->plugin->txt("title"), "title"); + $title->setRequired(true); - $title = new ilTextInputGUI($this->plugin->txt("title"), "title"); - $title->setRequired(true); + $description = new ilTextAreaInputGUI($this->plugin->txt("description"), "description"); + $description->setRequired(false); - $description = new ilTextAreaInputGUI($this->plugin->txt("description"), "description"); - $description->setRequired(false); + $online = new ilCheckboxInputGUI($this->plugin->txt("online"), "online"); - $online = new ilCheckboxInputGUI($this->plugin->txt("online"), "online"); + $skill_service = new ilCheckboxInputGUI($this->plugin->txt("skill_service_setting"), "skill_service"); + $skill_service->setRequired(false); + $skill_service->setInfo($this->plugin->txt('adm_enable_skmg_first')); + global $DIC; + $ilSetting = $DIC->settings(); + + $skill_setting_enabled = $ilSetting->_lookupValue('skmg', 'enable_skmg'); + if ($skill_setting_enabled == false) { + $skill_service->setChecked($skill_setting_enabled); + $skill_service->setValue(0); + $skill_service->setDisabled(true); + } else { + $skill_service->setValue(1); + } - $skill_service = new ilCheckboxInputGUI($this->plugin->txt("skill_service_setting"), "skill_service"); - $skill_service->setRequired(false); - $skill_service->setInfo($this->plugin->txt('adm_enable_skmg_first')); - global $DIC; - $ilSetting = $DIC->settings(); - - $skill_setting_enabled = $ilSetting->_lookupValue('skmg','enable_skmg'); - if($skill_setting_enabled == false) - { - $skill_service->setChecked($skill_setting_enabled); - $skill_service->setValue(0); - $skill_service->setDisabled(true); - } - else - { - $skill_service->setValue(1); - } + $this->form->addItem($title); + $this->form->addItem($description); + $this->form->addItem($online); + $this->form->addItem($skill_service); + $this->form->setTitle($this->plugin->txt("edit_properties")); + $this->form->setFormAction($this->ctrl->getFormAction($this->controller)); + $this->form->addCommandButton("ilQuestionSetPoolPropertiesGUI.update", $this->plugin->txt("save")); + } - $this->form->addItem($title); - $this->form->addItem($description); - $this->form->addItem($online); - $this->form->addItem($skill_service); - $this->form->setTitle($this->plugin->txt("edit_properties")); - $this->form->setFormAction($this->ctrl->getFormAction($this->controller)); - $this->form->addCommandButton("ilQuestionSetPoolPropertiesGUI.update", $this->plugin->txt("save")); - } + /** + * Returns the current tab name + * return string + */ + protected function getCurrentTab() + { + return "properties"; + } - /** - * Returns the current tab name - * return string - */ - protected function getCurrentTab() - { - return "properties"; - } + /** + * @return array + */ + protected function getRequirements() + { + array(); + } - /** - * @return array - */ - protected function getRequirements() - { - array(); - } + /** + * Loads and returns the Model for the controller gui + * @return ilPluginModelInterface + */ + protected function loadModel() + { + return $this->controller->object; + } - /** - * Loads and returns the Model for the controller gui - * @return ilPluginModelInterface - */ - protected function loadModel() - { - return $this->controller->object; - } + /** + * Get the redirect action after an update was successful + * @return string + */ + protected function getRedirectAfterUpdate() + { + } - /** - * Get the redirect action after an update was successful - * @return string - */ - protected function getRedirectAfterUpdate() - { + /** + * Get the redirect action after an update was successful + * @return string + */ + protected function getAfterUpdateRedirectCmd() + { + return "ilQuestionSetPoolPropertiesGUI.edit"; + } - } - - /** - * Get the redirect action after an update was successful - * @return string - */ - protected function getAfterUpdateRedirectCmd() - { - return "ilQuestionSetPoolPropertiesGUI.edit"; - } - - /** - * @param $model - * - * @return array - */ - protected function getAfterUpdateRedirectParams($model) - { - return array(); - } + /** + * @param $model + * + * @return array + */ + protected function getAfterUpdateRedirectParams($model) + { + return array(); + } } diff --git a/classes/controllers/class.ilQuestionSetPoolSetGUI.php b/classes/controllers/class.ilQuestionSetPoolSetGUI.php index fd9a36a04dd8e6408fb1cae8d590760fa5d1c25e..7e04bdf42320c32a6f773236d8787ad9fd66cf9f 100644 --- a/classes/controllers/class.ilQuestionSetPoolSetGUI.php +++ b/classes/controllers/class.ilQuestionSetPoolSetGUI.php @@ -8,116 +8,109 @@ require_once "abstract.ilPluginControllerFormGUI.php"; * Date: 02.10.13 * Time: 10:01 * @author Thomas Joußen - */ + */ class ilQuestionSetPoolSetGUI extends ilPluginControllerFormGUI { - - public function update() - { - $model = $this->loadModel(); - $this->initForm($model); - if($this->form->checkInput()) - { - $model->bindForm($this->form); - - if($model->isTitleUnique()) - { - $model->update(); - ilUtil::sendSuccess($this->plugin->txt("msg_obj_modified"), true); - $this->redirect( - $this->getAfterUpdateRedirectCmd(), - $this->getAfterUpdateRedirectParams($model) - ); - } - else - { - ilUtil::sendFailure($this->plugin->txt("set_title_not_unique"), true); - } - } - - $this->form->setValuesByPost(); - $this->tpl->setContent($this->form->getHTML()); - } - - /** - * Returns the current tab name - * return string - */ - protected function getCurrentTab() - { - return "content"; - } - - /** - * @return array - */ - protected function getRequirements() - { - return array( - "models/class.ilQuestionSetPoolSet.php" - ); - } - - protected function initForm($model) - { - require_once "./Services/Form/classes/class.ilPropertyFormGUI.php"; - - $this->form = new ilPropertyFormGUI(); - $this->form->setTitle(sprintf( - $this->plugin->txt("question_set_title"), - $this->controller->object->getTitle() - )); - - $id = new ilHiddenInputGUI("id"); - - $title = new ilTextInputGUI($this->plugin->txt("title"), "title"); - $title->setRequired(true); - - $description = new ilTextAreaInputGUI($this->plugin->txt("description"), "description"); - $description->setRequired(false); - - $this->form->addItem($id); - $this->form->addItem($title); - $this->form->addItem($description); - - - $this->form->setFormAction($this->ctrl->getFormAction($this->controller)); - - $this->form->addCommandButton("ilQuestionSetPoolSetGUI.update", $this->plugin->txt("save")); - $this->form->addCommandButton("ilQuestionSetPoolSetsGUI.show", $this->plugin->txt("cancel")); - } - - /** - * Loads and returns the Model for the controller gui - * - * @return ilPluginModelInterface - */ - protected function loadModel() - { - $id = isset($_GET["set_id"])? (int)$_GET['set_id']: (int)$_POST["id"]; - $model = new ilQuestionSetPoolSet($id); - $model->setContainerObjId($this->controller->object->getId()); - $model->read(); - - return $model; - } - - /** - * Get the redirect action after an update was successful - * @return string - */ - protected function getAfterUpdateRedirectCmd() - { - return "ilQuestionSetPoolSetsGUI.show"; - } - - /** - * @param $model - * - * @return array - */ - protected function getAfterUpdateRedirectParams($model) - { - return array(); - } + public function update() + { + $model = $this->loadModel(); + $this->initForm($model); + if ($this->form->checkInput()) { + $model->bindForm($this->form); + + if ($model->isTitleUnique()) { + $model->update(); + ilUtil::sendSuccess($this->plugin->txt("msg_obj_modified"), true); + $this->redirect( + $this->getAfterUpdateRedirectCmd(), + $this->getAfterUpdateRedirectParams($model) + ); + } else { + ilUtil::sendFailure($this->plugin->txt("set_title_not_unique"), true); + } + } + + $this->form->setValuesByPost(); + $this->tpl->setContent($this->form->getHTML()); + } + + /** + * Returns the current tab name + * return string + */ + protected function getCurrentTab() + { + return "content"; + } + + /** + * @return array + */ + protected function getRequirements() + { + return array( + "models/class.ilQuestionSetPoolSet.php" + ); + } + + protected function initForm($model) + { + $this->form = new ilPropertyFormGUI(); + $this->form->setTitle(sprintf( + $this->plugin->txt("question_set_title"), + $this->controller->object->getTitle() + )); + + $id = new ilHiddenInputGUI("id"); + + $title = new ilTextInputGUI($this->plugin->txt("title"), "title"); + $title->setRequired(true); + + $description = new ilTextAreaInputGUI($this->plugin->txt("description"), "description"); + $description->setRequired(false); + + $this->form->addItem($id); + $this->form->addItem($title); + $this->form->addItem($description); + + + $this->form->setFormAction($this->ctrl->getFormAction($this->controller)); + + $this->form->addCommandButton("ilQuestionSetPoolSetGUI.update", $this->plugin->txt("save")); + $this->form->addCommandButton("ilQuestionSetPoolSetsGUI.show", $this->plugin->txt("cancel")); + } + + /** + * Loads and returns the Model for the controller gui + * + * @return ilPluginModelInterface + */ + protected function loadModel() + { + $id = isset($_GET["set_id"])? (int) $_GET['set_id']: (int) $_POST["id"]; + $model = new ilQuestionSetPoolSet($id); + $model->setContainerObjId($this->controller->object->getId()); + $model->read(); + + return $model; + } + + /** + * Get the redirect action after an update was successful + * @return string + */ + protected function getAfterUpdateRedirectCmd() + { + return "ilQuestionSetPoolSetsGUI.show"; + } + + /** + * @param $model + * + * @return array + */ + protected function getAfterUpdateRedirectParams($model) + { + return array(); + } } diff --git a/classes/controllers/class.ilQuestionSetPoolSetQuestionsGUI.php b/classes/controllers/class.ilQuestionSetPoolSetQuestionsGUI.php index 925179286fa5b8f623964ac10e04510908f4e0b2..cc5e07c432ff23b1539bec0cfb46f765e71f041e 100644 --- a/classes/controllers/class.ilQuestionSetPoolSetQuestionsGUI.php +++ b/classes/controllers/class.ilQuestionSetPoolSetQuestionsGUI.php @@ -8,374 +8,354 @@ require_once "abstract.ilPluginControllerTableGUI.php"; * Date: 08.10.13 * Time: 11:11 * @author Thomas Joußen - */ + */ class ilQuestionSetPoolSetQuestionsGUI extends ilPluginControllerTableGUI { - public function __construct(ilObjQuestionSetPoolGUI $controller) - { - parent::__construct($controller); - $this->addSubTabs(); - } - - /** - * - */ - public function listQuestions() - { - $this->controller->ensurePermission('write'); - - if($this->controller->object instanceof ilObjQuestionSetPool) - { - $this->addToolbarButton("back_to_set_list", "ilQuestionSetPoolSetsGUI.show"); - } - $this->addToolbarButton("browse_for_questions", "ilQuestionSetPoolSetQuestionsGUI.browseForQuestions", array( - "set_id" => (int)$_GET['set_id'] - )); - - $set = new ilQuestionSetPoolSet((int)$_GET['set_id']); - $set->read(); - - $this->ctrl->setParameter($this->controller, "set_id", (int)$_GET["set_id"]); - $table = new ilQuestionSetPoolSetQuestionsTableGUI($this->controller, $this->plugin, "ilQuestionSetPoolSetQuestionsGUI.listQuestions", ilQuestionSetPoolSetQuestionsTableGUI::CONTEXT_LIST_SET_QST, (int)$_GET['set_id']); - $table->setModelList($set->getQuestionList()); - - $table->setTitle( - $set->getTitle() . " - ". - $this->plugin->txt("questions") - ); - $table->addMultiCommand("ilQuestionSetPoolSetQuestionsGUI.removeMultipleConfirmation", $this->controller->lng->txt("remove")); - $table->addMultiCommand("ilQuestionSetPoolSetQuestionsGUI.copyQuestion", $this->controller->lng->txt("duplicate")); - $table->populate(); - - $this->tpl->setContent($table->getHTML()); - } - - /** - * - */ - public function browseForQuestions() - { - $this->controller->ensurePermission('write'); - - $this->ctrl->setParameter($this->controller, "set_id", (int)$_GET['set_id']); - - $this->addToolbarButton("back_to_qst_list", __CLASS__ . ".listQuestions"); - - $table = new ilQuestionSetPoolQuestionsTableGUI($this->controller, $this->plugin, "ilQuestionSetPoolSetQuestionsGUI.browseForQuestions", ilQuestionSetPoolQuestionsTableGUI::CONTEXT_LIST_LINKED_QST_IN_SET, (int)$_GET['set_id']); - $table->setGuiClassName("ilQuestionSetPoolSetQuestionsGUI"); - $table->initFilter(); - $modellist = new ilQuestionPoolQuestionList(); - $modellist->setQuestionSetPool($this->controller->object); - $table->setModelList($modellist); - $table->addMultiCommand("ilQuestionSetPoolSetQuestionsGUI.insertQuestions", $this->controller->lng->txt("insert")); - $table->populate(); - - ilUtil::sendInfo($this->plugin->txt("qs_question_info"), true); - - $this->tpl->setContent($table->getHTML()); - } - - /** - * - */ - public function insertQuestions() - { - $this->controller->ensurePermission('write'); - - if(!$this->dataSelected("q_id")) - { - ilUtil::sendInfo($this->plugin->txt("no_questions_selected"), true); - $this->redirect("ilQuestionSetPoolSetQuestionsGUI.browseForQuestions", array( - 'set_id' => (int)$_GET['set_id'] - )); - } - - $set = new ilQuestionSetPoolSet((int)$_GET["set_id"]); - $set->read(); - $success = $set->getQuestionList()->insert($_POST['q_id'], $this->controller->object); - - if(!$success) - { - ilUtil::sendFailure($this->plugin->txt("questions_added_error"), true); - $this->redirect("ilQuestionSetPoolSetQuestionsGUI.browseForQuestions", array( - 'set_id' => (int)$_GET['set_id'] - )); - } - - ilUtil::sendSuccess($this->plugin->txt("questions_added"), true); - $this->redirect("ilQuestionSetPoolSetQuestionsGUI.listQuestions", array( - 'set_id' => (int)$_GET['set_id'] - )); - } - - /** - * Called if a single set should be deleted, calls \\ilQuestionSetPoolSetQuestionsGUI::removeMultipleConfirmation do show the confirmation screen - */ - public function removeConfirmation() - { - if(!isset($_GET['q_id'])) - { - ilUtil::sendInfo($this->plugin->txt('no_questions_selected_to_delete')); - $this->listQuestions(); - return; - } - - $_POST['q_id'] = array((int)$_GET['q_id']); - $this->removeMultipleConfirmation(); - } - - /** - * - */ - public function copyQuestion() - { - $this->controller->ensurePermission('write'); - - if(!isset($_POST['q_id']) || !is_array($_POST['q_id']) || !count($_POST['q_id'])) - { - ilUtil::sendFailure($this->lng->txt('copy_no_questions_selected')); - $this->listQuestions(); - } - - $question_ids = array_filter((array)$_POST['q_id']); - - $set = new ilQuestionSetPoolSet((int)$_GET["set_id"]); - $set->read(); - $set->getQuestionList()->insert($question_ids, $this->controller->object); - if(is_array($question_ids)) - { - if(1 == count($question_ids)) - { - ilUtil::sendSuccess($this->plugin->txt('copy_questions_success_s'), true); - } - else - { - ilUtil::sendSuccess($this->plugin->txt('copy_questions_success_p'), true); - } - $this->redirect("ilQuestionSetPoolSetQuestionsGUI.listQuestions", array( - 'set_id' => (int)$_GET['set_id'] - )); - } - } - - /** - * - */ - public function removeMultipleConfirmation() - { - $this->controller->ensurePermission('write'); - - if(!$this->dataSelected('q_id')) - { - ilUtil::sendInfo($this->plugin->txt('no_questions_selected_to_delete')); - $this->listQuestions(); - return; - } - - $this->redirectIfQuestionIsUsedInPath(); - - $confirmation = new ilConfirmationGUI(); - $this->ctrl->setParameter($this->controller, 'set_id', (int)$_GET['set_id']); - $confirmation->setFormAction($this->ctrl->getFormAction($this->controller, __CLASS__ . '.listQuestions')); - $this->ctrl->setParameter($this->controller, 'set_id', ''); - $confirmation->setCancel($this->lng->txt('cancel'), __CLASS__ . '.listQuestions'); - $confirmation->setConfirm($this->lng->txt('confirm'), __CLASS__ . '.removeQuestions'); - - $num_items = 0; - require_once 'Modules/TestQuestionPool/classes/class.assQuestion.php'; - foreach($_POST['q_id'] as $question_id) - { - $question = assQuestion::_instanciateQuestion($question_id); - $confirmation->addItem('q_id[]', $question_id, $question->getTitle()); - ++$num_items; - } - - if(1 == $num_items) - { - $confirmation->setHeaderText($this->plugin->txt('remove_selected_questions_s')); - } - else - { - $confirmation->setHeaderText($this->plugin->txt('remove_selected_questions_p')); - } - - $this->tpl->setContent($confirmation->getHTML()); - } - - public function removeQuestions() - { - $this->controller->ensurePermission('write'); - - if(!$this->dataSelected('q_id')) - { - ilUtil::sendInfo($this->plugin->txt('no_questions_selected_to_delete'), true); - $this->redirect('ilQuestionSetPoolSetQuestionsGUI.listQuestions', array( - 'set_id' => (int)$_GET['set_id'] - )); - } - - $this->redirectIfQuestionIsUsedInPath(); - - $questions_to_delete = (array)$_POST['q_id']; - - $model = new ilQuestionSetPoolSet((int)$_GET['set_id']); - $model->read(); - $model->getQuestionList()->remove($questions_to_delete); - - if(is_array($questions_to_delete) && count($questions_to_delete) == 1) - { - ilUtil::sendSuccess($this->plugin->txt('deleted_selected_questions_s'), true); - } - else - { - ilUtil::sendSuccess($this->plugin->txt('deleted_selected_questions_p'), true); - } - $this->redirect('ilQuestionSetPoolSetQuestionsGUI.listQuestions', array( - 'set_id' => (int)$_GET['set_id'] - )); - } - - /** - * - */ - public function showQuestionPreview() - { - $this->ctrl->setParameter($this->controller, "set_id", (int)$_GET['set_id']); - if(isset($_GET['referer']) && 'browse' == $_GET['referer']) - { - $this->toolbar->addButton($this->plugin->txt('back_to_qst_list'), $this->ctrl->getLinkTarget($this->controller, __CLASS__ . '.browseForQuestions')); - } - else - { - $this->toolbar->addButton($this->plugin->txt('back_to_qst_list'), $this->ctrl->getLinkTarget($this->controller, __CLASS__ . '.listQuestions')); - } - $this->ctrl->setParameter($this->controller, "set_id", ""); - - $this->controller->populateContentStyleBlock(); - $this->controller->populateSyntaxStyleBlock(); - - require_once 'Modules/TestQuestionPool/classes/class.assQuestion.php'; - $gui = assQuestion::instantiateQuestionGUI((int)$_GET['q_id']); - $gui->setTargetGuiClass('ilObjQuestionSetPoolGUI'); - $preview = $gui->getPreview(); - $this->tpl->setContent($preview); - } - - public function applyAvailableFilter() - { - $table = new ilQuestionSetPoolQuestionsTableGUI($this->controller, $this->plugin, "ilQuestionSetPoolSetQuestionsGUI.browseForQuestions", ilQuestionSetPoolQuestionsTableGUI::CONTEXT_LIST_LINKED_QST_IN_SET, (int)$_GET['set_id']); - $table->setGuiClassName("ilQuestionSetPoolSetQuestionsGUI"); - $table->initFilter(); - $table->resetOffset(); - $table->writeFilterToSession(); - - $this->browseForQuestions(); - } - - public function resetAvailableFilter() - { - $table = new ilQuestionSetPoolQuestionsTableGUI($this->controller, $this->plugin, "ilQuestionSetPoolSetQuestionsGUI.browseForQuestions", ilQuestionSetPoolQuestionsTableGUI::CONTEXT_LIST_LINKED_QST_IN_SET, (int)$_GET['set_id']); - $table->setGuiClassName("ilQuestionSetPoolSetQuestionsGUI"); - $table->initFilter(); - $table->resetOffset(); - $table->resetFilter(); - - $this->browseForQuestions(); - } - - /** - * Returns the current tab name - * return string - */ - protected function getCurrentTab() - { - return "content"; - } - - /** - * @return array - */ - protected function getRequirements() - { - require_once "Services/Utilities/classes/class.ilConfirmationGUI.php"; - require_once "Modules/Test/classes/class.ilObjAssessmentFolder.php"; - - return array( - "tables/class.ilQuestionSetPoolQuestionsTableGUI.php", - "tables/class.ilQuestionSetPoolSetQuestionsTableGUI.php", - "models/class.ilQuestionSetPoolSet.php", - "models/class.ilQuestionSetPoolPath.php", - "models/class.ilQuestionPoolQuestionList.php", - - ); - } - - /** - * - */ - public function editQuestion() - { - $this->controller->ensurePermission('write'); - - if(!isset($_GET['q_id']) || !(int)$_GET['q_id']) - { - $this->listQuestions(); - return; - } - - $params = array( - 'set_id' => (int)$_GET['set_id'], - 'cmd' => __CLASS__ . '.listQuestions' - ); - - $question_id = (int)$_GET['q_id']; - ilUtil::redirect('ilias.php?consumer_context=' . base64_encode(json_encode($params)) . '&baseClass=ilObjQuestionPoolGUI&ref_id=' . $this->controller->object->getRefId().'&cmd=editQuestionForTest&calling_consumer=' . $this->controller->object->getRefId() . '&q_id=' . $question_id); - } - - private function addSubTabs() - { - $this->ctrl->setParameter($this->controller, "set_id", (int)$_GET['set_id']); - - $this->tabs->addSubTab("set_questions", $this->plugin->txt("questions"), - $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolSetQuestionsGUI.listQuestions")); - - $this->tabs->addSubTab("paths", $this->plugin->txt("paths"), - $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolPathsGUI.listPaths")); - - $this->tabs->addSubTab("path_overview", $this->plugin->txt("path_overview"), - $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolPathGraphGUI.showPathOverview")); - - $this->tabs->activateSubTab("set_questions"); - - $this->ctrl->setParameter($this->controller, "set_id", ""); - } - - /** - * - */ - protected function redirectIfQuestionIsUsedInPath() - { - $model = new ilQuestionSetPoolSet((int)$_GET['set_id']); - $model->read(); - $paths = $model->getPathList()->getData(); - - foreach((array)$_POST['q_id'] as $question_id) - { - foreach($paths as $path_data) - { - $path = new ilQuestionSetPoolPath($path_data['id']); - $path->read(); - - if($path->isQuestionInPath($question_id)) - { - ilUtil::sendFailure($this->plugin->txt('questions_used_in_path'), true); - $this->redirect( - 'ilQuestionSetPoolSetQuestionsGUI.listQuestions', array( - 'set_id' => (int)$_GET['set_id'] - ) - ); - } - } - } - } + public function __construct(ilObjQuestionSetPoolGUI $controller) + { + parent::__construct($controller); + $this->addSubTabs(); + } + + /** + * + */ + public function listQuestions() + { + $this->controller->ensurePermission('write'); + + if ($this->controller->object instanceof ilObjQuestionSetPool) { + $this->addToolbarButton("back_to_set_list", "ilQuestionSetPoolSetsGUI.show"); + } + $this->addToolbarButton("browse_for_questions", "ilQuestionSetPoolSetQuestionsGUI.browseForQuestions", array( + "set_id" => (int) $_GET['set_id'] + )); + + $set = new ilQuestionSetPoolSet((int) $_GET['set_id']); + $set->read(); + + $this->ctrl->setParameter($this->controller, "set_id", (int) $_GET["set_id"]); + $table = new ilQuestionSetPoolSetQuestionsTableGUI($this->controller, $this->plugin, "ilQuestionSetPoolSetQuestionsGUI.listQuestions", ilQuestionSetPoolSetQuestionsTableGUI::CONTEXT_LIST_SET_QST, (int) $_GET['set_id']); + $table->setModelList($set->getQuestionList()); + + $table->setTitle( + $set->getTitle() . " - " . + $this->plugin->txt("questions") + ); + $table->addMultiCommand("ilQuestionSetPoolSetQuestionsGUI.removeMultipleConfirmation", $this->controller->lng->txt("remove")); + $table->addMultiCommand("ilQuestionSetPoolSetQuestionsGUI.copyQuestion", $this->controller->lng->txt("duplicate")); + $table->populate(); + + $this->tpl->setContent($table->getHTML()); + } + + /** + * + */ + public function browseForQuestions() + { + $this->controller->ensurePermission('write'); + + $this->ctrl->setParameter($this->controller, "set_id", (int) $_GET['set_id']); + + $this->addToolbarButton("back_to_qst_list", __CLASS__ . ".listQuestions"); + + $table = new ilQuestionSetPoolQuestionsTableGUI($this->controller, $this->plugin, "ilQuestionSetPoolSetQuestionsGUI.browseForQuestions", ilQuestionSetPoolQuestionsTableGUI::CONTEXT_LIST_LINKED_QST_IN_SET, (int) $_GET['set_id']); + $table->setGuiClassName("ilQuestionSetPoolSetQuestionsGUI"); + $table->initFilter(); + $modellist = new ilQuestionPoolQuestionList(); + $modellist->setQuestionSetPool($this->controller->object); + $table->setModelList($modellist); + $table->addMultiCommand("ilQuestionSetPoolSetQuestionsGUI.insertQuestions", $this->controller->lng->txt("insert")); + $table->populate(); + + ilUtil::sendInfo($this->plugin->txt("qs_question_info"), true); + + $this->tpl->setContent($table->getHTML()); + } + + /** + * + */ + public function insertQuestions() + { + $this->controller->ensurePermission('write'); + + if (!$this->dataSelected("q_id")) { + ilUtil::sendInfo($this->plugin->txt("no_questions_selected"), true); + $this->redirect("ilQuestionSetPoolSetQuestionsGUI.browseForQuestions", array( + 'set_id' => (int) $_GET['set_id'] + )); + } + + $set = new ilQuestionSetPoolSet((int) $_GET["set_id"]); + $set->read(); + $success = $set->getQuestionList()->insert($_POST['q_id'], $this->controller->object); + + if (!$success) { + ilUtil::sendFailure($this->plugin->txt("questions_added_error"), true); + $this->redirect("ilQuestionSetPoolSetQuestionsGUI.browseForQuestions", array( + 'set_id' => (int) $_GET['set_id'] + )); + } + + ilUtil::sendSuccess($this->plugin->txt("questions_added"), true); + $this->redirect("ilQuestionSetPoolSetQuestionsGUI.listQuestions", array( + 'set_id' => (int) $_GET['set_id'] + )); + } + + /** + * Called if a single set should be deleted, calls \\ilQuestionSetPoolSetQuestionsGUI::removeMultipleConfirmation do show the confirmation screen + */ + public function removeConfirmation() + { + if (!isset($_GET['q_id'])) { + ilUtil::sendInfo($this->plugin->txt('no_questions_selected_to_delete')); + $this->listQuestions(); + return; + } + + $_POST['q_id'] = array((int) $_GET['q_id']); + $this->removeMultipleConfirmation(); + } + + /** + * + */ + public function copyQuestion() + { + $this->controller->ensurePermission('write'); + + if (!isset($_POST['q_id']) || !is_array($_POST['q_id']) || !count($_POST['q_id'])) { + ilUtil::sendFailure($this->lng->txt('copy_no_questions_selected')); + $this->listQuestions(); + } + + $question_ids = array_filter((array) $_POST['q_id']); + + $set = new ilQuestionSetPoolSet((int) $_GET["set_id"]); + $set->read(); + $set->getQuestionList()->insert($question_ids, $this->controller->object); + if (is_array($question_ids)) { + if (1 == count($question_ids)) { + ilUtil::sendSuccess($this->plugin->txt('copy_questions_success_s'), true); + } else { + ilUtil::sendSuccess($this->plugin->txt('copy_questions_success_p'), true); + } + $this->redirect("ilQuestionSetPoolSetQuestionsGUI.listQuestions", array( + 'set_id' => (int) $_GET['set_id'] + )); + } + } + + /** + * + */ + public function removeMultipleConfirmation() + { + $this->controller->ensurePermission('write'); + + if (!$this->dataSelected('q_id')) { + ilUtil::sendInfo($this->plugin->txt('no_questions_selected_to_delete')); + $this->listQuestions(); + return; + } + + $this->redirectIfQuestionIsUsedInPath(); + + $confirmation = new ilConfirmationGUI(); + $this->ctrl->setParameter($this->controller, 'set_id', (int) $_GET['set_id']); + $confirmation->setFormAction($this->ctrl->getFormAction($this->controller, __CLASS__ . '.listQuestions')); + $this->ctrl->setParameter($this->controller, 'set_id', ''); + $confirmation->setCancel($this->lng->txt('cancel'), __CLASS__ . '.listQuestions'); + $confirmation->setConfirm($this->lng->txt('confirm'), __CLASS__ . '.removeQuestions'); + + $num_items = 0; + foreach ($_POST['q_id'] as $question_id) { + $question = assQuestion::_instanciateQuestion($question_id); + $confirmation->addItem('q_id[]', $question_id, $question->getTitle()); + ++$num_items; + } + + if (1 == $num_items) { + $confirmation->setHeaderText($this->plugin->txt('remove_selected_questions_s')); + } else { + $confirmation->setHeaderText($this->plugin->txt('remove_selected_questions_p')); + } + + $this->tpl->setContent($confirmation->getHTML()); + } + + public function removeQuestions() + { + $this->controller->ensurePermission('write'); + + if (!$this->dataSelected('q_id')) { + ilUtil::sendInfo($this->plugin->txt('no_questions_selected_to_delete'), true); + $this->redirect('ilQuestionSetPoolSetQuestionsGUI.listQuestions', array( + 'set_id' => (int) $_GET['set_id'] + )); + } + + $this->redirectIfQuestionIsUsedInPath(); + + $questions_to_delete = (array) $_POST['q_id']; + + $model = new ilQuestionSetPoolSet((int) $_GET['set_id']); + $model->read(); + $model->getQuestionList()->remove($questions_to_delete); + + if (is_array($questions_to_delete) && count($questions_to_delete) == 1) { + ilUtil::sendSuccess($this->plugin->txt('deleted_selected_questions_s'), true); + } else { + ilUtil::sendSuccess($this->plugin->txt('deleted_selected_questions_p'), true); + } + $this->redirect('ilQuestionSetPoolSetQuestionsGUI.listQuestions', array( + 'set_id' => (int) $_GET['set_id'] + )); + } + + /** + * + */ + public function showQuestionPreview() + { + $this->ctrl->setParameter($this->controller, "set_id", (int) $_GET['set_id']); + if (isset($_GET['referer']) && 'browse' == $_GET['referer']) { + $this->toolbar->addButton($this->plugin->txt('back_to_qst_list'), $this->ctrl->getLinkTarget($this->controller, __CLASS__ . '.browseForQuestions')); + } else { + $this->toolbar->addButton($this->plugin->txt('back_to_qst_list'), $this->ctrl->getLinkTarget($this->controller, __CLASS__ . '.listQuestions')); + } + $this->ctrl->setParameter($this->controller, "set_id", ""); + + $this->controller->populateContentStyleBlock(); + $this->controller->populateSyntaxStyleBlock(); + + $gui = assQuestion::instantiateQuestionGUI((int) $_GET['q_id']); + $gui->setTargetGuiClass('ilObjQuestionSetPoolGUI'); + $preview = $gui->getPreview(); + $this->tpl->setContent($preview); + } + + public function applyAvailableFilter() + { + $table = new ilQuestionSetPoolQuestionsTableGUI($this->controller, $this->plugin, "ilQuestionSetPoolSetQuestionsGUI.browseForQuestions", ilQuestionSetPoolQuestionsTableGUI::CONTEXT_LIST_LINKED_QST_IN_SET, (int) $_GET['set_id']); + $table->setGuiClassName("ilQuestionSetPoolSetQuestionsGUI"); + $table->initFilter(); + $table->resetOffset(); + $table->writeFilterToSession(); + + $this->browseForQuestions(); + } + + public function resetAvailableFilter() + { + $table = new ilQuestionSetPoolQuestionsTableGUI($this->controller, $this->plugin, "ilQuestionSetPoolSetQuestionsGUI.browseForQuestions", ilQuestionSetPoolQuestionsTableGUI::CONTEXT_LIST_LINKED_QST_IN_SET, (int) $_GET['set_id']); + $table->setGuiClassName("ilQuestionSetPoolSetQuestionsGUI"); + $table->initFilter(); + $table->resetOffset(); + $table->resetFilter(); + + $this->browseForQuestions(); + } + + /** + * Returns the current tab name + * return string + */ + protected function getCurrentTab() + { + return "content"; + } + + /** + * @return array + */ + protected function getRequirements() + { + return array( + "tables/class.ilQuestionSetPoolQuestionsTableGUI.php", + "tables/class.ilQuestionSetPoolSetQuestionsTableGUI.php", + "models/class.ilQuestionSetPoolSet.php", + "models/class.ilQuestionSetPoolPath.php", + "models/class.ilQuestionPoolQuestionList.php", + + ); + } + + /** + * + */ + public function editQuestion() + { + $this->controller->ensurePermission('write'); + + if (!isset($_GET['q_id']) || !(int) $_GET['q_id']) { + $this->listQuestions(); + return; + } + + $params = array( + 'set_id' => (int) $_GET['set_id'], + 'cmd' => __CLASS__ . '.listQuestions' + ); + + $question_id = (int) $_GET['q_id']; + ilUtil::redirect('ilias.php?consumer_context=' . base64_encode(json_encode($params)) . '&baseClass=ilObjQuestionPoolGUI&ref_id=' . $this->controller->object->getRefId() . '&cmd=editQuestionForTest&calling_consumer=' . $this->controller->object->getRefId() . '&q_id=' . $question_id); + } + + private function addSubTabs() + { + $this->ctrl->setParameter($this->controller, "set_id", (int) $_GET['set_id']); + + $this->tabs->addSubTab( + "set_questions", + $this->plugin->txt("questions"), + $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolSetQuestionsGUI.listQuestions") + ); + + $this->tabs->addSubTab( + "paths", + $this->plugin->txt("paths"), + $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolPathsGUI.listPaths") + ); + + $this->tabs->addSubTab( + "path_overview", + $this->plugin->txt("path_overview"), + $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolPathGraphGUI.showPathOverview") + ); + + $this->tabs->activateSubTab("set_questions"); + + $this->ctrl->setParameter($this->controller, "set_id", ""); + } + + /** + * + */ + protected function redirectIfQuestionIsUsedInPath() + { + $model = new ilQuestionSetPoolSet((int) $_GET['set_id']); + $model->read(); + $paths = $model->getPathList()->getData(); + + foreach ((array) $_POST['q_id'] as $question_id) { + foreach ($paths as $path_data) { + $path = new ilQuestionSetPoolPath($path_data['id']); + $path->read(); + + if ($path->isQuestionInPath($question_id)) { + ilUtil::sendFailure($this->plugin->txt('questions_used_in_path'), true); + $this->redirect( + 'ilQuestionSetPoolSetQuestionsGUI.listQuestions', + array( + 'set_id' => (int) $_GET['set_id'] + ) + ); + } + } + } + } } diff --git a/classes/controllers/class.ilQuestionSetPoolSetsGUI.php b/classes/controllers/class.ilQuestionSetPoolSetsGUI.php index 7e6510a340a166c8e086fbf0639a297e32d1674d..bf52c05804a29fade8594109d9a1716216bb4b0d 100644 --- a/classes/controllers/class.ilQuestionSetPoolSetsGUI.php +++ b/classes/controllers/class.ilQuestionSetPoolSetsGUI.php @@ -8,222 +8,191 @@ require_once "abstract.ilPluginControllerTableGUI.php"; * Date: 02.10.13 * Time: 09:33 * @author Thomas Joußen - */ + */ class ilQuestionSetPoolSetsGUI extends ilPluginControllerTableGUI { - - public function show() - { - $this->addToolbarButton("add_set", "ilQuestionSetPoolSetGUI.edit"); - - $table = new ilQuestionSetPoolSetsTableGUI($this->controller, $this->plugin); - $tmp = $this->controller->object->getSetList(); - $table->setModelList($this->controller->object->getSetList()); - $table->addMultiCommand("ilQuestionSetPoolSetsGUI.duplicate", $this->lng->txt("copy")); - $table->populate(); - - $this->tpl->setContent($table->getHTML()); - } - - /** - * Called if a single set should be deleted, calls \ilQuestionSetPoolSetsGUI::removeMultipleConfirmation do show the confirmation screen - */ - public function removeConfirmation() - { - if(!isset($_GET['set_id'])) - { - ilUtil::sendInfo($this->plugin->txt('no_set_selected')); - $this->show(); - return; - } - - $_POST['set_id'] = array((int)$_GET['set_id']); - $this->removeMultipleConfirmation(); - } - - /** - * Shows an confirmation screen for the selected sets - */ - public function removeMultipleConfirmation() - { - if(!isset($_POST['set_id']) || !is_array($_POST['set_id'])) - { - ilUtil::sendInfo($this->plugin->txt('no_set_selected')); - $this->show(); - return; - } - - $this->tabs->activateSubTab('paths'); - - require_once 'Services/Utilities/classes/class.ilConfirmationGUI.php'; - $confirmation = new ilConfirmationGUI(); - - $num_items = 0; - $missing_perm_nodes_titles = array(); - foreach($_POST['set_id'] as $set_id) - { - $set = new ilQuestionSetPoolSet((int)$set_id); - $set->read(); - if($set->getContainerObjId() == $this->controller->object->getId()) - { - $confirmation->addItem('set_id[]', $set->getId(), $set->getTitle()); - ++$num_items; - } - else - { - $missing_perm_nodes_titles[] = $set->getTitle(); - } - } - - if(1 == $num_items) - { - $confirmation->setHeaderText($this->plugin->txt('confirm_delete_sets_s')); - } - else - { - $confirmation->setHeaderText($this->plugin->txt('confirm_delete_sets_p')); - } - - $missing_perm_nodes_titles = array_filter($missing_perm_nodes_titles); - if(is_array($missing_perm_nodes_titles)) - { - if(1 == count($missing_perm_nodes_titles)) - { - ilUtil::sendFailure(sprintf($this->plugin->txt('sets_del_perm_err_s'), implode(', ', $missing_perm_nodes_titles))); - } - else if(count($missing_perm_nodes_titles) > 1) - { - ilUtil::sendFailure(sprintf($this->plugin->txt('sets_del_perm_err_p'), implode(', ', $missing_perm_nodes_titles))); - } - } - if(!$num_items) - { - $this->show(); - return; - } - - $confirmation->setFormAction($this->ctrl->getFormAction($this->controller, __CLASS__ . '.show')); - $confirmation->setCancel($this->plugin->txt('cancel'), __CLASS__ . '.show'); - $confirmation->setConfirm($this->plugin->txt('confirm'), __CLASS__ . '.remove'); - - $this->tpl->setContent($confirmation->getHTML()); - } - - /** - * Finally deletes (cascading) the selected sets - */ - public function remove() - { - if(!isset($_POST['set_id']) || !is_array($_POST['set_id'])) - { - ilUtil::sendInfo($this->plugin->txt('no_set_selected')); - $this->show(); - return; - } - - $num_items = 0; - $missing_perm_nodes_titles = array(); - foreach($_POST['set_id'] as $set_id) - { - $set = new ilQuestionSetPoolSet((int)$set_id); - $set->read(); - if($set->getContainerObjId() == $this->controller->object->getId()) - { - $set->remove(); - ++$num_items; - } - else - { - $missing_perm_nodes_titles[] = $set->getTitle(); - } - } - - if(1 == $num_items) - { - ilUtil::sendSuccess($this->plugin->txt('deleted_sets_s'), true); - } - else if($num_items > 1) - { - ilUtil::sendSuccess($this->plugin->txt('deleted_sets_p'), true); - } - - $missing_perm_nodes_titles = array_filter($missing_perm_nodes_titles); - if(is_array($missing_perm_nodes_titles)) - { - if(1 == count($missing_perm_nodes_titles)) - { - ilUtil::sendFailure(sprintf($this->plugin->txt('sets_del_perm_err_s'), implode(', ', $missing_perm_nodes_titles))); - } - else if(count($missing_perm_nodes_titles) > 1) - { - ilUtil::sendFailure(sprintf($this->plugin->txt('sets_del_perm_err_p'), implode(', ', $missing_perm_nodes_titles))); - } - } - $this->redirect(__CLASS__ . '.show'); - } - - public function duplicate() - { - if(!$this->dataSelected("set_id")) - { - ilUtil::sendInfo($this->plugin->txt('no_set_selected')); - $this->redirect("ilQuestionSetPoolSetsGUI.show"); - } - - foreach($_POST["set_id"] as $set_id) - { - $set = new ilQuestionSetPoolSet((int)$set_id); - $set->read(); - $set->duplicate($this->controller->object->getId()); - } - - ilUtil::sendSuccess($this->plugin->txt("sets_duplicated"), true); - $this->redirect("ilQuestionSetPoolSetsGUI.show"); - } - - - public function synchronize() - { - $set = new ilQuestionSetPoolSet((int)$_GET["set_id"]); - $set->read(); - - if(ilObjQuestionSetPool::canSynchronizeSet($set->getOriginalId())) - { - $original = new ilQuestionSetPoolSet($set->getOriginalId()); - $original->read(); - $old_questions = $original->getQuestionList()->getData(); - $original->remove(); - - $clone = $set->synchronize($original->getContainerObjId(), $old_questions); - //$clone = $set->duplicate($original->getContainerObjId()); - $clone->setOriginalId(null); - $clone->update(); - - ilQuestionSetPoolSet::updateOriginalId($set->getOriginalId(), $clone->getId()); - - ilUtil::sendSuccess($this->plugin->txt("sets_synchronize_success"), true); - } - $this->redirect("ilQuestionSetPoolPathsGUI.listPaths", array("set_id" => $_GET["set_id"])); - } - - /** - * Returns the current tab name - * return string - */ - protected function getCurrentTab() - { - return "content"; - } - - /** - * @return array - */ - protected function getRequirements() - { - return array( - "tables/class.ilQuestionSetPoolSetsTableGUI.php", - "providers/class.ilQuestionSetPoolSetsProvider.php", - "models/class.ilQuestionSetPoolSet.php" - ); - } + public function show() + { + $this->addToolbarButton("add_set", "ilQuestionSetPoolSetGUI.edit"); + + $table = new ilQuestionSetPoolSetsTableGUI($this->controller, $this->plugin); + $tmp = $this->controller->object->getSetList(); + $table->setModelList($this->controller->object->getSetList()); + $table->addMultiCommand("ilQuestionSetPoolSetsGUI.duplicate", $this->lng->txt("copy")); + $table->populate(); + + $this->tpl->setContent($table->getHTML()); + } + + /** + * Called if a single set should be deleted, calls \ilQuestionSetPoolSetsGUI::removeMultipleConfirmation do show the confirmation screen + */ + public function removeConfirmation() + { + if (!isset($_GET['set_id'])) { + ilUtil::sendInfo($this->plugin->txt('no_set_selected')); + $this->show(); + return; + } + + $_POST['set_id'] = array((int) $_GET['set_id']); + $this->removeMultipleConfirmation(); + } + + /** + * Shows an confirmation screen for the selected sets + */ + public function removeMultipleConfirmation() + { + if (!isset($_POST['set_id']) || !is_array($_POST['set_id'])) { + ilUtil::sendInfo($this->plugin->txt('no_set_selected')); + $this->show(); + return; + } + + $this->tabs->activateSubTab('paths'); + + $confirmation = new ilConfirmationGUI(); + + $num_items = 0; + $missing_perm_nodes_titles = array(); + foreach ($_POST['set_id'] as $set_id) { + $set = new ilQuestionSetPoolSet((int) $set_id); + $set->read(); + if ($set->getContainerObjId() == $this->controller->object->getId()) { + $confirmation->addItem('set_id[]', $set->getId(), $set->getTitle()); + ++$num_items; + } else { + $missing_perm_nodes_titles[] = $set->getTitle(); + } + } + + if (1 == $num_items) { + $confirmation->setHeaderText($this->plugin->txt('confirm_delete_sets_s')); + } else { + $confirmation->setHeaderText($this->plugin->txt('confirm_delete_sets_p')); + } + + $missing_perm_nodes_titles = array_filter($missing_perm_nodes_titles); + if (is_array($missing_perm_nodes_titles)) { + if (1 == count($missing_perm_nodes_titles)) { + ilUtil::sendFailure(sprintf($this->plugin->txt('sets_del_perm_err_s'), implode(', ', $missing_perm_nodes_titles))); + } elseif (count($missing_perm_nodes_titles) > 1) { + ilUtil::sendFailure(sprintf($this->plugin->txt('sets_del_perm_err_p'), implode(', ', $missing_perm_nodes_titles))); + } + } + if (!$num_items) { + $this->show(); + return; + } + + $confirmation->setFormAction($this->ctrl->getFormAction($this->controller, __CLASS__ . '.show')); + $confirmation->setCancel($this->plugin->txt('cancel'), __CLASS__ . '.show'); + $confirmation->setConfirm($this->plugin->txt('confirm'), __CLASS__ . '.remove'); + + $this->tpl->setContent($confirmation->getHTML()); + } + + /** + * Finally deletes (cascading) the selected sets + */ + public function remove() + { + if (!isset($_POST['set_id']) || !is_array($_POST['set_id'])) { + ilUtil::sendInfo($this->plugin->txt('no_set_selected')); + $this->show(); + return; + } + + $num_items = 0; + $missing_perm_nodes_titles = array(); + foreach ($_POST['set_id'] as $set_id) { + $set = new ilQuestionSetPoolSet((int) $set_id); + $set->read(); + if ($set->getContainerObjId() == $this->controller->object->getId()) { + $set->remove(); + ++$num_items; + } else { + $missing_perm_nodes_titles[] = $set->getTitle(); + } + } + + if (1 == $num_items) { + ilUtil::sendSuccess($this->plugin->txt('deleted_sets_s'), true); + } elseif ($num_items > 1) { + ilUtil::sendSuccess($this->plugin->txt('deleted_sets_p'), true); + } + + $missing_perm_nodes_titles = array_filter($missing_perm_nodes_titles); + if (is_array($missing_perm_nodes_titles)) { + if (1 == count($missing_perm_nodes_titles)) { + ilUtil::sendFailure(sprintf($this->plugin->txt('sets_del_perm_err_s'), implode(', ', $missing_perm_nodes_titles))); + } elseif (count($missing_perm_nodes_titles) > 1) { + ilUtil::sendFailure(sprintf($this->plugin->txt('sets_del_perm_err_p'), implode(', ', $missing_perm_nodes_titles))); + } + } + $this->redirect(__CLASS__ . '.show'); + } + + public function duplicate() + { + if (!$this->dataSelected("set_id")) { + ilUtil::sendInfo($this->plugin->txt('no_set_selected')); + $this->redirect("ilQuestionSetPoolSetsGUI.show"); + } + + foreach ($_POST["set_id"] as $set_id) { + $set = new ilQuestionSetPoolSet((int) $set_id); + $set->read(); + $set->duplicate($this->controller->object->getId()); + } + + ilUtil::sendSuccess($this->plugin->txt("sets_duplicated"), true); + $this->redirect("ilQuestionSetPoolSetsGUI.show"); + } + + + public function synchronize() + { + $set = new ilQuestionSetPoolSet((int) $_GET["set_id"]); + $set->read(); + + if (ilObjQuestionSetPool::canSynchronizeSet($set->getOriginalId())) { + $original = new ilQuestionSetPoolSet($set->getOriginalId()); + $original->read(); + $old_questions = $original->getQuestionList()->getData(); + $original->remove(); + + $clone = $set->synchronize($original->getContainerObjId(), $old_questions); + //$clone = $set->duplicate($original->getContainerObjId()); + $clone->setOriginalId(null); + $clone->update(); + + ilQuestionSetPoolSet::updateOriginalId($set->getOriginalId(), $clone->getId()); + + ilUtil::sendSuccess($this->plugin->txt("sets_synchronize_success"), true); + } + $this->redirect("ilQuestionSetPoolPathsGUI.listPaths", array("set_id" => $_GET["set_id"])); + } + + /** + * Returns the current tab name + * return string + */ + protected function getCurrentTab() + { + return "content"; + } + + /** + * @return array + */ + protected function getRequirements() + { + return array( + "tables/class.ilQuestionSetPoolSetsTableGUI.php", + "providers/class.ilQuestionSetPoolSetsProvider.php", + "models/class.ilQuestionSetPoolSet.php" + ); + } } diff --git a/classes/controllers/class.ilQuestionSetPoolSkillAdministrationGUI.php b/classes/controllers/class.ilQuestionSetPoolSkillAdministrationGUI.php index 627bbd31f9a91c52bee3a58cbe87e0869f1a5ec4..5ed35f7b8be9881fe6b7470debe67b10dcb375b1 100644 --- a/classes/controllers/class.ilQuestionSetPoolSkillAdministrationGUI.php +++ b/classes/controllers/class.ilQuestionSetPoolSkillAdministrationGUI.php @@ -1,9 +1,6 @@ object = $controller->object; - - parent::__construct($controller); - } - - public function executeCommand() - { - global $DIC; - $ilDB = $DIC->database(); - $ilPluginAdmin = $DIC['ilPluginAdmin']; - $ilAccess = $DIC->access(); - - if( $this->isAccessDenied() ) - { - $this->ilias->raiseError($this->lng->txt("permission_denied"), $this->ilias->error_obj->MESSAGE); - } - - $nextClass = $this->ctrl->getNextClass(); - $this->setSubTabs($nextClass); - $questionContainerId = $this->object->getId(); - - switch($nextClass) - { - case 'ilassquestionskillassignmentsgui': - $provider = new ilQuestionSetPoolSkillQuestionListProvider(); - - $questionList = new ilQuestionSetPoolSkillAssQuestionList($ilDB, $this->lng, $ilPluginAdmin); - $questionList->setQuestionInstanceTypeFilter($this->getRequiredQuestionInstanceTypeFilter()); - $questionList->setParentObjId($questionContainerId); - $questionList->setProvider($provider); - $questionList->load(); - - $gui = new ilAssQuestionSkillAssignmentsGUI($this->ctrl, $ilAccess, $this->tpl, $this->lng, $ilDB); - $gui->setAssignmentEditingEnabled($this->isAssignmentEditingRequired()); - $gui->setQuestionContainerId($questionContainerId); - $gui->setQuestionList($questionList); - $gui->setQuestionOrderSequence($questionList->getOrderSequence()); - $this->ctrl->forwardCommand($gui); - - break; - case 'ilassquestionskillusagestablegui': - $gui = new ilAssQuestionSkillUsagesTableGUI($this->ctrl, $this->tpl, $this->lng, $ilDB, $this->object->getId()); - - $this->ctrl->forwardCommand($gui); - - break; - } - } - - private function getRequiredQuestionInstanceTypeFilter() - { - return ilAssQuestionList::QUESTION_INSTANCE_TYPE_DUPLICATES; - } - - protected function isAssignmentEditingRequired() - { - return true; - } - - protected function isAccessDenied() - { - if(!$this->object->isSkillServiceEnabled()) - { - return true; - } - - if(!ilObjQuestionSetPool::isSkillManagementGloballyActivated()) - { - return true; - } - - return false; - } - - /** - * Returns the current tab name - * return string - */ - protected function getCurrentTab() - { - return 'tst_tab_competences'; - } - - private function setSubTabs($controllerClass) - { - $link = $this->ctrl->getLinkTargetByClass( - 'ilAssQuestionSkillAssignmentsGUI', ilAssQuestionSkillAssignmentsGUI::CMD_SHOW_SKILL_QUEST_ASSIGNS - ); - $this->tabs->addSubTab( - 'ilassquestionskillassignmentsgui', $this->lng->txt('qpl_skl_sub_tab_quest_assign'), $link - - ); - $link = $this->ctrl->getLinkTargetByClass( - 'ilAssQuestionSkillUsagesTableGUI', ilAssQuestionSkillUsagesTableGUI::CMD_SHOW - ); - $this->tabs->addSubTab( - 'ilassquestionskillusagestablegui', $this->lng->txt('qpl_skl_sub_tab_usages'), $link - - ); - - $this->tabs->activateSubTab($controllerClass); - } - - /** - * @return array - */ - protected function getRequirements() - { - return array( - 'utils/class.ilQuestionSetPoolSkillAssQuestionList.php', - 'providers/class.ilQuestionSetPoolSkillQuestionListProvider.php' - ); - } + /** + * @var ilObjQuestionSetPool + */ + protected $object; + + public function __construct(ilObjQuestionSetPoolGUI $controller) + { + $this->object = $controller->object; + + parent::__construct($controller); + } + + public function executeCommand() + { + global $DIC; + $ilDB = $DIC->database(); + $ilPluginAdmin = $DIC['ilPluginAdmin']; + $ilAccess = $DIC->access(); + + if ($this->isAccessDenied()) { + $this->ilias->raiseError($this->lng->txt("permission_denied"), $this->ilias->error_obj->MESSAGE); + } + + $nextClass = $this->ctrl->getNextClass(); + $this->setSubTabs($nextClass); + $questionContainerId = $this->object->getId(); + + switch ($nextClass) { + case 'ilassquestionskillassignmentsgui': + $provider = new ilQuestionSetPoolSkillQuestionListProvider(); + + $questionList = new ilQuestionSetPoolSkillAssQuestionList($ilDB, $this->lng, $ilPluginAdmin); + $questionList->setQuestionInstanceTypeFilter($this->getRequiredQuestionInstanceTypeFilter()); + $questionList->setParentObjId($questionContainerId); + $questionList->setProvider($provider); + $questionList->load(); + + $gui = new ilAssQuestionSkillAssignmentsGUI($this->ctrl, $ilAccess, $this->tpl, $this->lng, $ilDB); + $gui->setAssignmentEditingEnabled($this->isAssignmentEditingRequired()); + $gui->setQuestionContainerId($questionContainerId); + $gui->setQuestionList($questionList); + $gui->setQuestionOrderSequence($questionList->getOrderSequence()); + $this->ctrl->forwardCommand($gui); + + break; + case 'ilassquestionskillusagestablegui': + $gui = new ilAssQuestionSkillUsagesTableGUI($this->ctrl, $this->tpl, $this->lng, $ilDB, $this->object->getId()); + + $this->ctrl->forwardCommand($gui); + + break; + } + } + + private function getRequiredQuestionInstanceTypeFilter() + { + return ilAssQuestionList::QUESTION_INSTANCE_TYPE_DUPLICATES; + } + + protected function isAssignmentEditingRequired() + { + return true; + } + + protected function isAccessDenied() + { + if (!$this->object->isSkillServiceEnabled()) { + return true; + } + + if (!ilObjQuestionSetPool::isSkillManagementGloballyActivated()) { + return true; + } + + return false; + } + + /** + * Returns the current tab name + * return string + */ + protected function getCurrentTab() + { + return 'tst_tab_competences'; + } + + private function setSubTabs($controllerClass) + { + $link = $this->ctrl->getLinkTargetByClass( + 'ilAssQuestionSkillAssignmentsGUI', + ilAssQuestionSkillAssignmentsGUI::CMD_SHOW_SKILL_QUEST_ASSIGNS + ); + $this->tabs->addSubTab( + 'ilassquestionskillassignmentsgui', + $this->lng->txt('qpl_skl_sub_tab_quest_assign'), + $link + + ); + $link = $this->ctrl->getLinkTargetByClass( + 'ilAssQuestionSkillUsagesTableGUI', + ilAssQuestionSkillUsagesTableGUI::CMD_SHOW + ); + $this->tabs->addSubTab( + 'ilassquestionskillusagestablegui', + $this->lng->txt('qpl_skl_sub_tab_usages'), + $link + + ); + + $this->tabs->activateSubTab($controllerClass); + } + + /** + * @return array + */ + protected function getRequirements() + { + return array( + 'utils/class.ilQuestionSetPoolSkillAssQuestionList.php', + 'providers/class.ilQuestionSetPoolSkillQuestionListProvider.php' + ); + } } - \ No newline at end of file diff --git a/classes/dispatcher/class.ilPluginDispatcher.php b/classes/dispatcher/class.ilPluginDispatcher.php index 2ab584f6007361209e096ef92d4f1b3240a77fa3..fa217f1aabeaddf2a358a75c1cf9f5d9fbeca781 100644 --- a/classes/dispatcher/class.ilPluginDispatcher.php +++ b/classes/dispatcher/class.ilPluginDispatcher.php @@ -6,116 +6,118 @@ * Date: 23.09.13 * Time: 14:32 * @author Thomas Joußen - */ -class ilPluginDispatcher { - - /** - * @var ilPluginDispatcher - */ - private static $_instance = null; - - /** - * @param ilObjectPluginGUI $baseController - * - * @return ilPluginDispatcher - */ - public static function getInstance($baseController) - { - if(self::$_instance == null) - { - self::$_instance = new ilPluginDispatcher($baseController); - } - - return self::$_instance; - } - - /** - * @param string $cmd - * - * @return mixed - */ - public function dispatch($cmd) - { - $controller = $this->getController($cmd); - $command = $this->getCommand($cmd); - - if(!is_object($controller)) - { - $controller = $this->instantiateController($controller); - } - - $controller->$command(); - } - - /** - * @param string $cmd - * - * @return string|ilPluginControllerGUI - */ - protected function getController($cmd) - { - $controller = substr($cmd, 0, strpos($cmd, ".")); - - if($controller == "") - { - $controller = $this->baseController; - } - - return $controller; - } - - /** - * @param string $cmd - * - * @return string - */ - protected function getCommand($cmd) - { - $pos = strpos($cmd, "."); - - if($pos > 0) - { - $cmd = substr($cmd, $pos + 1); - } - - return $cmd; - } - - /** - * @param string $controller - * - * @return ilPluginControllerGUI - */ - protected function instantiateController($controller) - { - $this->requireController($controller); - - return new $controller($this->baseController); - } - - /** - * @return string - */ - protected function getControllerPath() - { - $path = $this->baseController->plugin->getDirectory() . - DIRECTORY_SEPARATOR . - "classes" . - DIRECTORY_SEPARATOR . - "controllers" . - DIRECTORY_SEPARATOR; - - return $path; - } - - /** - * @param $controller - */ - protected function requireController($controller) - { - require_once $this->getControllerPath() . "class.$controller.php"; - } - - private function __construct($baseController){$this->baseController = $baseController;} - private function __clone(){} + */ +class ilPluginDispatcher +{ + + /** + * @var ilPluginDispatcher + */ + private static $_instance = null; + + /** + * @param ilObjectPluginGUI $baseController + * + * @return ilPluginDispatcher + */ + public static function getInstance($baseController) + { + if (self::$_instance == null) { + self::$_instance = new ilPluginDispatcher($baseController); + } + + return self::$_instance; + } + + /** + * @param string $cmd + * + * @return mixed + */ + public function dispatch($cmd) + { + $controller = $this->getController($cmd); + $command = $this->getCommand($cmd); + + if (!is_object($controller)) { + $controller = $this->instantiateController($controller); + } + + $controller->$command(); + } + + /** + * @param string $cmd + * + * @return string|ilPluginControllerGUI + */ + protected function getController($cmd) + { + $controller = substr($cmd, 0, strpos($cmd, ".")); + + if ($controller == "") { + $controller = $this->baseController; + } + + return $controller; + } + + /** + * @param string $cmd + * + * @return string + */ + protected function getCommand($cmd) + { + $pos = strpos($cmd, "."); + + if ($pos > 0) { + $cmd = substr($cmd, $pos + 1); + } + + return $cmd; + } + + /** + * @param string $controller + * + * @return ilPluginControllerGUI + */ + protected function instantiateController($controller) + { + $this->requireController($controller); + + return new $controller($this->baseController); + } + + /** + * @return string + */ + protected function getControllerPath() + { + $path = $this->baseController->plugin->getDirectory() . + DIRECTORY_SEPARATOR . + "classes" . + DIRECTORY_SEPARATOR . + "controllers" . + DIRECTORY_SEPARATOR; + + return $path; + } + + /** + * @param $controller + */ + protected function requireController($controller) + { + require_once $this->getControllerPath() . "class.$controller.php"; + } + + private function __construct($baseController) + { + $this->baseController = $baseController; + } + private function __clone() + { + } } diff --git a/classes/models/abstract.ilPluginModel.php b/classes/models/abstract.ilPluginModel.php index 684fbc1f3030973dc68f665fa1fb820eadc619a2..ec973a769de787cb4ac08f07e2b3f95e93a15a97 100644 --- a/classes/models/abstract.ilPluginModel.php +++ b/classes/models/abstract.ilPluginModel.php @@ -8,52 +8,49 @@ require_once "interface.ilPluginModelInterface.php"; * Date: 21.11.13 * Time: 11:17 * @author Thomas Joußen - */ + */ abstract class ilPluginModel implements ilPluginModelInterface { - /** - * @var int - */ - protected $id; - - public function __construct($id = 0) - { - $this->id = $id; - } - - //abstract protected function create(); - //abstract protected function update(); - - /** - * @param int $id - */ - public function setId($id) - { - $this->id = $id; - } - - /** - * @return int - */ - public function getId() - { - return $this->id; - } - - /** - * @return array - */ - public function toArray() - { - $result = array(); - foreach($this as $key => $value) - { - $result[$key] = $value; - } - - return $result; - } - + /** + * @var int + */ + protected $id; + + public function __construct($id = 0) + { + $this->id = $id; + } + + //abstract protected function create(); + //abstract protected function update(); + + /** + * @param int $id + */ + public function setId($id) + { + $this->id = $id; + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @return array + */ + public function toArray() + { + $result = array(); + foreach ($this as $key => $value) { + $result[$key] = $value; + } + + return $result; + } } - \ No newline at end of file diff --git a/classes/models/abstract.ilPluginModelList.php b/classes/models/abstract.ilPluginModelList.php index ec1780b97d11fea9a897198570656d34c2060e1c..46624bdccf5eb9f587cdc62fd07a3f00a3488d70 100644 --- a/classes/models/abstract.ilPluginModelList.php +++ b/classes/models/abstract.ilPluginModelList.php @@ -6,77 +6,75 @@ * Date: 06.11.13 * Time: 11:24 * @author Thomas Joußen - */ + */ abstract class ilPluginModelList { - /** - * @var ilDB - */ - protected $db; + /** + * @var ilDB + */ + protected $db; - /** - * @var array - */ - private $data; + /** + * @var array + */ + private $data; - /** - * @var boolean - */ - protected $loaded; + /** + * @var boolean + */ + protected $loaded; - public function __construct() - { - global $DIC; + public function __construct() + { + global $DIC; - $this->db = $DIC->database(); - } + $this->db = $DIC->database(); + } - /** - * @return array - */ - public function getData() - { - if(!$this->isLoaded()) - { - $data = $this->loadData(); - $this->data = $this->createObjectsFromData($data); - $this->setLoaded(true); - } + /** + * @return array + */ + public function getData() + { + if (!$this->isLoaded()) { + $data = $this->loadData(); + $this->data = $this->createObjectsFromData($data); + $this->setLoaded(true); + } - return $this->data; - } + return $this->data; + } - /** - * @param boolean $loaded - */ - public function setLoaded($loaded) - { - $this->loaded = $loaded; - } + /** + * @param boolean $loaded + */ + public function setLoaded($loaded) + { + $this->loaded = $loaded; + } - /** - * @return boolean - */ - public function isLoaded() - { - return $this->loaded; - } + /** + * @return boolean + */ + public function isLoaded() + { + return $this->loaded; + } - /** - * @param array $params - * @param array $filter - * - * @return array - */ - abstract public function loadData($params = array(), $filter = array()); + /** + * @param array $params + * @param array $filter + * + * @return array + */ + abstract public function loadData($params = array(), $filter = array()); - /** - * @param array $data - * - * @return array - */ - abstract public function createObjectsFromData($data); + /** + * @param array $data + * + * @return array + */ + abstract public function createObjectsFromData($data); } - \ No newline at end of file diff --git a/classes/models/class.ilQuestionPoolQuestionList.php b/classes/models/class.ilQuestionPoolQuestionList.php index 7cb1992934c4aab7523e2af8179cf3f1f73cedf0..b86ceaa332229ec2d2e0d74bd09c76322c51f227 100644 --- a/classes/models/class.ilQuestionPoolQuestionList.php +++ b/classes/models/class.ilQuestionPoolQuestionList.php @@ -8,58 +8,55 @@ require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/ * Date: 06.11.13 * Time: 14:56 * @author Thomas Joußen - */ + */ class ilQuestionPoolQuestionList extends ilPluginModelList { - /** - * @var ilObjQuestionSetPool - */ - protected $question_set_pool; - - /** - * @param \ilObjQuestionSetPool $question_set_pool - */ - public function setQuestionSetPool($question_set_pool) - { - $this->question_set_pool = $question_set_pool; - } - - /** - * @param array $params - * @param array $filter - * - * @return array - */ - public function loadData($params = array(), $filter = array()) - { - require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/classes/providers/class.ilQuestionSetPoolQuestionsBrowserProvider.php"; - require_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php"; - - $available_pools = array_keys(ilObjQuestionPool::_getAvailableQuestionpools(true,false, false, false, false)); - - if(is_array($available_pools) && count($available_pools) == 0) - { - return null; - } - - $filter["question_pools"] = $available_pools; - $filter["xqsp_id"] = $this->question_set_pool->getId(); - - $provider = new ilQuestionSetPoolQuestionsBrowserProvider(); - $data = $provider->loadData($filter, $params); - - return $data; - } - - /** - * @param array $data - * - * @return array - */ - public function createObjectsFromData($data) - { - return $data; - } + /** + * @var ilObjQuestionSetPool + */ + protected $question_set_pool; + + /** + * @param \ilObjQuestionSetPool $question_set_pool + */ + public function setQuestionSetPool($question_set_pool) + { + $this->question_set_pool = $question_set_pool; + } + + /** + * @param array $params + * @param array $filter + * + * @return array + */ + public function loadData($params = array(), $filter = array()) + { + require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/classes/providers/class.ilQuestionSetPoolQuestionsBrowserProvider.php"; + + $available_pools = array_keys(ilObjQuestionPool::_getAvailableQuestionpools(true, false, false, false, false)); + + if (is_array($available_pools) && count($available_pools) == 0) { + return null; + } + + $filter["question_pools"] = $available_pools; + $filter["xqsp_id"] = $this->question_set_pool->getId(); + + $provider = new ilQuestionSetPoolQuestionsBrowserProvider(); + $data = $provider->loadData($filter, $params); + + return $data; + } + + /** + * @param array $data + * + * @return array + */ + public function createObjectsFromData($data) + { + return $data; + } } - \ No newline at end of file diff --git a/classes/models/class.ilQuestionSetPoolJumpCondition.php b/classes/models/class.ilQuestionSetPoolJumpCondition.php index fdbcb821b645a3b3693394b7c93a6351d20b003f..bd15104e26ed68fcb2a1aec06181e2fdd9e5a4e3 100644 --- a/classes/models/class.ilQuestionSetPoolJumpCondition.php +++ b/classes/models/class.ilQuestionSetPoolJumpCondition.php @@ -1,7 +1,6 @@ - */ + */ class ilQuestionSetPoolJumpCondition extends ilPluginModel { - /** - * @var string - */ - protected $jump_condition; - - /** - * @var assQuestion - */ - private $question; - - /** - * @var ilQuestionSetPoolNode - */ - protected $node; - - /** - * @var int - */ - protected $repititions = NULL; - - /** - * @var int - */ - protected $sorting; - - /** - * @var string null - */ - protected $true_feedback = NULL; - - /** - * @var string null - */ - protected $true_jump_feedback = NULL; - - /** - * @var string null - */ - protected $false_feedback = NULL; - - /** - * @param string $jump_condition - */ - public function setJumpCondition($jump_condition) - { - $this->jump_condition = $jump_condition; - } - - /** - * @return string - */ - public function getJumpCondition() - { - return $this->jump_condition; - } - - /** - * @param \ilQuestionSetPoolNode $node - */ - public function setNode($node) - { - $this->node = $node; - } - - /** - * @return \ilQuestionSetPoolNode - */ - public function getNode() - { - return $this->node; - } - - /** - * @param \assQuestion $question - */ - public function setQuestion($question) - { - $this->question = $question; - } - - /** - * @return \assQuestion - */ - public function getQuestion() - { - return $this->question; - } - - /** - * @param int $repititions - */ - public function setRepititions($repititions) - { - $this->repititions = $repititions; - } - - /** - * @return int - */ - public function getRepititions() - { - return $this->repititions; - } - - /** - * @param int $sorting - */ - public function setSorting($sorting) - { - $this->sorting = $sorting; - } - - /** - * @return int - */ - public function getSorting() - { - return $this->sorting; - } - - public function update() - { - global $DIC; - $ilDB = $DIC->database(); - - $question_id = null; - if($this->getQuestion() != null) - { - $question_id = $this->getQuestion()->getId(); - } - - if($this->id > 0) - { - return (bool)$ilDB->update( - "rep_robj_xqsp_jmp_con", - array( - "question_fi" => array("integer", $question_id), - "jump_condition" => array("text", $this->getJumpCondition()), - "repititions" => array("integer", $this->getRepititions()), - "sorting" => array("integer", $this->getSorting()), - 'true_feedback' => array('clob', $this->getTrueFeedback()), - 'true_jmp_feedback' => array('clob', $this->getTrueJumpFeedback()), - 'false_feedback' => array('clob', $this->getFalseFeedback()), - ), - array( - "id" => array("integer", $this->getId()) - ) - ); - } - else - { - $this->setId($ilDB->nextId("rep_robj_xqsp_jmp_con")); - - $this->setSorting(time()); - return $ilDB->insert( - "rep_robj_xqsp_jmp_con", - array( - "id" => array("integer", $this->getId()), - "jump_condition" => array("text", $this->getJumpCondition()), - "node_fi" => array("integer", $this->getNode()->getId()), - "question_fi" => array("integer", $question_id), - "repititions" => array("integer", $this->getRepititions()), - "sorting" => array("integer", $this->getSorting()), - 'true_feedback' => array('clob', $this->getTrueFeedback()), - 'true_jmp_feedback' => array('clob', $this->getTrueJumpFeedback()), - 'false_feedback' => array('clob', $this->getFalseFeedback()), - ) - ); - } - } - - public function read() - { - global $DIC; - $ilDB = $DIC->database(); - - $result = $ilDB->queryF( - "SELECT * FROM rep_robj_xqsp_jmp_con WHERE id = %s", - array("integer"), - array($this->id) - ); - $data = $ilDB->fetchAssoc($result); - - $id = (isset($data['node_fi']))? $data['node_fi'] : $_REQUEST['node_fi']; - $node = new ilQuestionSetPoolNode($id); - $node->read(); - - $question = assQuestion::_instanciateQuestion($data["question_fi"]); - - $this->setId($data['id']); - $this->setJumpCondition($data['jump_condition']); - $this->setQuestion($question); - $this->setNode($node); - $this->setRepititions($data["repititions"]); - $this->setSorting($data["sorting"]); - - require_once 'Services/RTE/classes/class.ilRTE.php'; - - $this->setTrueFeedback(ilRTE::_replaceMediaObjectImageSrc($data['true_feedback'], 1)); - $this->setTrueJumpFeedback(ilRTE::_replaceMediaObjectImageSrc($data['true_jmp_feedback'], 1)); - $this->setFalseFeedback(ilRTE::_replaceMediaObjectImageSrc($data['false_feedback'], 1)); - } - - /** - * @param ilQuestionSetPoolNode $node - * @param array $question_ids - * - * @return bool - */ - public function duplicate($node, $question_ids) - { - global $DIC; - $ilDB = $DIC->database(); - $clone = clone $this; - $clone->setId($ilDB->nextId("rep_robj_xqsp_jmp_con")); - $clone->setNode($node); - $clone->setSorting($this->getSorting()); - - $question_id = null; - if($this->getQuestion() != null) - { - $question_id = $this->getQuestion()->getId(); - } - - return $ilDB->insert( - "rep_robj_xqsp_jmp_con", - array( - "id" => array("integer", $clone->getId()), - "jump_condition" => array("text", $clone->getJumpCondition()), - "question_fi" => array("integer", $question_ids[$question_id]), - "node_fi" => array("integer", $clone->getNode()->getId()), - "repititions" => array("integer", $this->getRepititions()), - "sorting" => array("integer", $this->getSorting()), - 'true_feedback' => array('clob', $this->getTrueFeedback()), - 'true_jmp_feedback' => array('clob', $this->getTrueJumpFeedback()), - 'false_feedback' => array('clob', $this->getFalseFeedback()), - ) - ); - } - - public function remove() - { - global $DIC; - $ilDB = $DIC->database(); - - return $ilDB->manipulateF( - "DELETE FROM rep_robj_xqsp_jmp_con WHERE id = %s", - array("integer"), - array($this->getId()) - ); - } - - /** - * @param ilPropertyFormGUI $form - */ - public function bindForm(ilPropertyFormGUI $form) - { - $this->setJumpCondition($form->getInput("jump_condition")); - $this->setQuestion(assQuestion::_instanciateQuestion($form->getInput("question"))); - if($form->getInput("repititions") != "") - { - $this->setRepititions($form->getInput("repititions")); - } - else - { - $this->setRepititions(null); - } - - require_once 'Services/RTE/classes/class.ilRTE.php'; - - $this->setTrueFeedback(ilRTE::_replaceMediaObjectImageSrc($form->getInput('true_feedback'), 0)); - $this->setTrueJumpFeedback(ilRTE::_replaceMediaObjectImageSrc($form->getInput('true_jump_feedback'), 0)); - $this->setFalseFeedback(ilRTE::_replaceMediaObjectImageSrc($form->getInput('false_feedback'), 0)); - } - /** - * @return string - */ - public function getFalseFeedback() - { - return $this->false_feedback; - } - - /** - * @param string $false_feedback - */ - public function setFalseFeedback($false_feedback) - { - $this->false_feedback = $false_feedback; - } - - /** - * @return string - */ - public function getTrueFeedback() - { - return $this->true_feedback; - } - - /** - * @param string $true_feedback - */ - public function setTrueFeedback($true_feedback) - { - $this->true_feedback = $true_feedback; - } - - /** - * @return string - */ - public function getTrueJumpFeedback() - { - return $this->true_jump_feedback; - } - - /** - * @param string $true_jump_feedback - */ - public function setTrueJumpFeedback($true_jump_feedback) - { - $this->true_jump_feedback = $true_jump_feedback; - } - - public function import() - { - global $DIC; - $ilDB = $DIC->database();B; - - $this->setId($ilDB->nextId("rep_robj_xqsp_jmp_con")); - - $question_id = null; - if($this->getQuestion() != null) - { - $question_id = $this->getQuestion()->getId(); - } - - $this->setSorting(time()); - $ilDB->insert( - "rep_robj_xqsp_jmp_con", - array( - "id" => array("integer", $this->getId()), - "jump_condition" => array("text", $this->getJumpCondition()), - "node_fi" => array("integer", $this->getNode()->getId()), - "question_fi" => array("integer", $question_id), - "repititions" => array("integer", $this->getRepititions()), - "sorting" => array("integer", $this->getSorting()), - 'true_feedback' => array('clob', $this->getTrueFeedback()), - 'true_jmp_feedback' => array('clob', $this->getTrueJumpFeedback()), - 'false_feedback' => array('clob', $this->getFalseFeedback()) - ) - ); - } - + /** + * @var string + */ + protected $jump_condition; + + /** + * @var assQuestion + */ + private $question; + + /** + * @var ilQuestionSetPoolNode + */ + protected $node; + + /** + * @var int + */ + protected $repititions = null; + + /** + * @var int + */ + protected $sorting; + + /** + * @var string null + */ + protected $true_feedback = null; + + /** + * @var string null + */ + protected $true_jump_feedback = null; + + /** + * @var string null + */ + protected $false_feedback = null; + + /** + * @param string $jump_condition + */ + public function setJumpCondition($jump_condition) + { + $this->jump_condition = $jump_condition; + } + + /** + * @return string + */ + public function getJumpCondition() + { + return $this->jump_condition; + } + + /** + * @param \ilQuestionSetPoolNode $node + */ + public function setNode($node) + { + $this->node = $node; + } + + /** + * @return \ilQuestionSetPoolNode + */ + public function getNode() + { + return $this->node; + } + + /** + * @param \assQuestion $question + */ + public function setQuestion($question) + { + $this->question = $question; + } + + /** + * @return \assQuestion + */ + public function getQuestion() + { + return $this->question; + } + + /** + * @param int $repititions + */ + public function setRepititions($repititions) + { + $this->repititions = $repititions; + } + + /** + * @return int + */ + public function getRepititions() + { + return $this->repititions; + } + + /** + * @param int $sorting + */ + public function setSorting($sorting) + { + $this->sorting = $sorting; + } + + /** + * @return int + */ + public function getSorting() + { + return $this->sorting; + } + + public function update() + { + global $DIC; + $ilDB = $DIC->database(); + + $question_id = null; + if ($this->getQuestion() != null) { + $question_id = $this->getQuestion()->getId(); + } + + if ($this->id > 0) { + return (bool) $ilDB->update( + "rep_robj_xqsp_jmp_con", + array( + "question_fi" => array("integer", $question_id), + "jump_condition" => array("text", $this->getJumpCondition()), + "repititions" => array("integer", $this->getRepititions()), + "sorting" => array("integer", $this->getSorting()), + 'true_feedback' => array('clob', $this->getTrueFeedback()), + 'true_jmp_feedback' => array('clob', $this->getTrueJumpFeedback()), + 'false_feedback' => array('clob', $this->getFalseFeedback()), + ), + array( + "id" => array("integer", $this->getId()) + ) + ); + } else { + $this->setId($ilDB->nextId("rep_robj_xqsp_jmp_con")); + + $this->setSorting(time()); + return $ilDB->insert( + "rep_robj_xqsp_jmp_con", + array( + "id" => array("integer", $this->getId()), + "jump_condition" => array("text", $this->getJumpCondition()), + "node_fi" => array("integer", $this->getNode()->getId()), + "question_fi" => array("integer", $question_id), + "repititions" => array("integer", $this->getRepititions()), + "sorting" => array("integer", $this->getSorting()), + 'true_feedback' => array('clob', $this->getTrueFeedback()), + 'true_jmp_feedback' => array('clob', $this->getTrueJumpFeedback()), + 'false_feedback' => array('clob', $this->getFalseFeedback()), + ) + ); + } + } + + public function read() + { + global $DIC; + $ilDB = $DIC->database(); + + $result = $ilDB->queryF( + "SELECT * FROM rep_robj_xqsp_jmp_con WHERE id = %s", + array("integer"), + array($this->id) + ); + $data = $ilDB->fetchAssoc($result); + + $id = (isset($data['node_fi']))? $data['node_fi'] : $_REQUEST['node_fi']; + $node = new ilQuestionSetPoolNode($id); + $node->read(); + + $question = assQuestion::_instanciateQuestion($data["question_fi"]); + + $this->setId($data['id']); + $this->setJumpCondition($data['jump_condition']); + $this->setQuestion($question); + $this->setNode($node); + $this->setRepititions($data["repititions"]); + $this->setSorting($data["sorting"]); + + $this->setTrueFeedback(ilRTE::_replaceMediaObjectImageSrc($data['true_feedback'], 1)); + $this->setTrueJumpFeedback(ilRTE::_replaceMediaObjectImageSrc($data['true_jmp_feedback'], 1)); + $this->setFalseFeedback(ilRTE::_replaceMediaObjectImageSrc($data['false_feedback'], 1)); + } + + /** + * @param ilQuestionSetPoolNode $node + * @param array $question_ids + * + * @return bool + */ + public function duplicate($node, $question_ids) + { + global $DIC; + $ilDB = $DIC->database(); + $clone = clone $this; + $clone->setId($ilDB->nextId("rep_robj_xqsp_jmp_con")); + $clone->setNode($node); + $clone->setSorting($this->getSorting()); + + $question_id = null; + if ($this->getQuestion() != null) { + $question_id = $this->getQuestion()->getId(); + } + + return $ilDB->insert( + "rep_robj_xqsp_jmp_con", + array( + "id" => array("integer", $clone->getId()), + "jump_condition" => array("text", $clone->getJumpCondition()), + "question_fi" => array("integer", $question_ids[$question_id]), + "node_fi" => array("integer", $clone->getNode()->getId()), + "repititions" => array("integer", $this->getRepititions()), + "sorting" => array("integer", $this->getSorting()), + 'true_feedback' => array('clob', $this->getTrueFeedback()), + 'true_jmp_feedback' => array('clob', $this->getTrueJumpFeedback()), + 'false_feedback' => array('clob', $this->getFalseFeedback()), + ) + ); + } + + public function remove() + { + global $DIC; + $ilDB = $DIC->database(); + + return $ilDB->manipulateF( + "DELETE FROM rep_robj_xqsp_jmp_con WHERE id = %s", + array("integer"), + array($this->getId()) + ); + } + + /** + * @param ilPropertyFormGUI $form + */ + public function bindForm(ilPropertyFormGUI $form) + { + $this->setJumpCondition($form->getInput("jump_condition")); + $this->setQuestion(assQuestion::_instanciateQuestion($form->getInput("question"))); + if ($form->getInput("repititions") != "") { + $this->setRepititions($form->getInput("repititions")); + } else { + $this->setRepititions(null); + } + + $this->setTrueFeedback(ilRTE::_replaceMediaObjectImageSrc($form->getInput('true_feedback'), 0)); + $this->setTrueJumpFeedback(ilRTE::_replaceMediaObjectImageSrc($form->getInput('true_jump_feedback'), 0)); + $this->setFalseFeedback(ilRTE::_replaceMediaObjectImageSrc($form->getInput('false_feedback'), 0)); + } + /** + * @return string + */ + public function getFalseFeedback() + { + return $this->false_feedback; + } + + /** + * @param string $false_feedback + */ + public function setFalseFeedback($false_feedback) + { + $this->false_feedback = $false_feedback; + } + + /** + * @return string + */ + public function getTrueFeedback() + { + return $this->true_feedback; + } + + /** + * @param string $true_feedback + */ + public function setTrueFeedback($true_feedback) + { + $this->true_feedback = $true_feedback; + } + + /** + * @return string + */ + public function getTrueJumpFeedback() + { + return $this->true_jump_feedback; + } + + /** + * @param string $true_jump_feedback + */ + public function setTrueJumpFeedback($true_jump_feedback) + { + $this->true_jump_feedback = $true_jump_feedback; + } + + public function import() + { + global $DIC; + $ilDB = $DIC->database(); + B; + + $this->setId($ilDB->nextId("rep_robj_xqsp_jmp_con")); + + $question_id = null; + if ($this->getQuestion() != null) { + $question_id = $this->getQuestion()->getId(); + } + + $this->setSorting(time()); + $ilDB->insert( + "rep_robj_xqsp_jmp_con", + array( + "id" => array("integer", $this->getId()), + "jump_condition" => array("text", $this->getJumpCondition()), + "node_fi" => array("integer", $this->getNode()->getId()), + "question_fi" => array("integer", $question_id), + "repititions" => array("integer", $this->getRepititions()), + "sorting" => array("integer", $this->getSorting()), + 'true_feedback' => array('clob', $this->getTrueFeedback()), + 'true_jmp_feedback' => array('clob', $this->getTrueJumpFeedback()), + 'false_feedback' => array('clob', $this->getFalseFeedback()) + ) + ); + } } - \ No newline at end of file diff --git a/classes/models/class.ilQuestionSetPoolJumpConditionList.php b/classes/models/class.ilQuestionSetPoolJumpConditionList.php index 9db29fd735bcd346633c3a0e63ba0510b9990425..c2b308a6ab83910d2f107c440c9706b776b4df0f 100644 --- a/classes/models/class.ilQuestionSetPoolJumpConditionList.php +++ b/classes/models/class.ilQuestionSetPoolJumpConditionList.php @@ -8,47 +8,46 @@ require_once "abstract.ilPluginModelList.php"; * Date: 05.12.13 * Time: 10:16 * @author Thomas Joußen - */ + */ class ilQuestionSetPoolJumpConditionList extends ilPluginModelList { - /** - * @var ilQuestionSetPoolNode - */ - protected $node; - - public function __construct($node) - { - $this->node = $node; - - parent::__construct(); - } - - - /** - * @param array $params - * @param array $filter - * - * @return array - */ - public function loadData($params = array(), $filter = array()) - { - require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/classes/providers/class.ilQuestionSetPoolJumpConditionsProvider.php"; - - $provider = new ilQuestionSetPoolJumpConditionsProvider(); - $filter["node_fi"] = $this->node->getId(); - $data = $provider->loadData($filter, $params); - - return $data; - } - - /** - * @param array $data - * - * @return array - */ - public function createObjectsFromData($data) - { - return $data; - } + /** + * @var ilQuestionSetPoolNode + */ + protected $node; + + public function __construct($node) + { + $this->node = $node; + + parent::__construct(); + } + + + /** + * @param array $params + * @param array $filter + * + * @return array + */ + public function loadData($params = array(), $filter = array()) + { + require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/classes/providers/class.ilQuestionSetPoolJumpConditionsProvider.php"; + + $provider = new ilQuestionSetPoolJumpConditionsProvider(); + $filter["node_fi"] = $this->node->getId(); + $data = $provider->loadData($filter, $params); + + return $data; + } + + /** + * @param array $data + * + * @return array + */ + public function createObjectsFromData($data) + { + return $data; + } } - \ No newline at end of file diff --git a/classes/models/class.ilQuestionSetPoolNode.php b/classes/models/class.ilQuestionSetPoolNode.php index 4790d0cb8804115261c4185d7da415ead88fd4ad..2778cae7de19a7b23dfcde4b3b96a97a12b0e8fc 100644 --- a/classes/models/class.ilQuestionSetPoolNode.php +++ b/classes/models/class.ilQuestionSetPoolNode.php @@ -1,7 +1,6 @@ - */ + */ class ilQuestionSetPoolNode extends ilPluginModel { - /** - * @var integer - */ - protected $id; - - /** - * @var integer - */ - protected $index; - - /** - * @var assQuestion - */ - protected $question; - - /** - * @var int - */ - protected $question_index; - - /** - * @var string|null - */ - protected $initial_condition; - - /** - * @var ilQuestionSetPoolPath - */ - protected $path; - - /** - * @var ilQuestionSetPoolJumpConditionList - */ - protected $jump_condition_list; - - /** - * @var int - */ - protected $dominant_scoring = NULL; - - /** - * @var string null - */ - protected $true_feedback = NULL; - - /** - * @var string null - */ - protected $false_feedback = NULL; - - public function __construct($id = 0) - { - require_once "class.ilQuestionSetPoolJumpConditionList.php"; - $this->jump_condition_list = new ilQuestionSetPoolJumpConditionList($this); - - parent::__construct($id); - } - - /** - * @param int $id - */ - public function setId($id) - { - $this->id = $id; - } - - /** - * @return int - */ - public function getId() - { - return $this->id; - } - - /** - * @param int $index - */ - public function setIndex($index) - { - $this->index = $index; - } - - /** - * @return int - */ - public function getIndex() - { - return $this->index; - } - - /** - * @param null|string $initial_condition - */ - public function setInitialCondition($initial_condition) - { - $this->initial_condition = $initial_condition; - } - - /** - * @return null|string - */ - public function getInitialCondition() - { - return $this->initial_condition; - } - - /** - * @param \assQuestion $question - */ - public function setQuestion($question) - { - $this->question = $question; - } - - /** - * @return \assQuestion - */ - public function getQuestion() - { - return $this->question; - } - - /** - * @param \ilQuestionSetPoolPath $path - */ - public function setPath(ilQuestionSetPoolPath $path) - { - $this->path = $path; - } - - /** - * @return \ilQuestionSetPoolPath - */ - public function getPath() - { - return $this->path; - } - - /** - * @param \ilQuestionSetPoolJumpConditionList $jump_condition_list - */ - public function setJumpConditionList($jump_condition_list) - { - $this->jump_condition_list = $jump_condition_list; - } - - /** - * @return \ilQuestionSetPoolJumpConditionList - */ - public function getJumpConditionList() - { - return $this->jump_condition_list; - } - - /** - * @return int - */ - public function getQuestionIndex() - { - return $this->question_index; - } - - /** - * @param int $dominant_scoring - */ - public function setDominantScoring($dominant_scoring) - { - $this->dominant_scoring = $dominant_scoring; - } - - /** - * @return int - */ - public function getDominantScoring() - { - return $this->dominant_scoring; - } - - /** - * @param integer $id - * @return bool - */ - public static function exists($id) - { - global $DIC; - $ilDB = $DIC->database(); - - $result = $ilDB->queryF( - "SELECT COUNT(*) cnt FROM rep_robj_xqsp_node WHERE id = %s", - array("integer"), - array($id) - ); - $data = $ilDB->fetchAssoc($result); - - return (int)$data['cnt'] == 1 ? true : false; - } - - public function update() - { - global $DIC; - $ilDB = $DIC->database(); - - if($this->id > 0) - { - return (bool)$ilDB->update( - "rep_robj_xqsp_node", - array( - "question_fi" => array('integer', $this->getQuestion()->getId()), - "initial_condition" => array('text', $this->getInitialCondition()), - "dominant_scoring" => array("integer", $this->getDominantScoring()), - "true_feedback" => array('clob', $this->getTrueFeedback()), - "false_feedback" => array('clob', $this->getFalseFeedback()), - ), - array( - 'id' => array("integer", $this->getId()) - ) - ); - } - else - { - $this->setId($ilDB->nextId("rep_robj_xqsp_node")); - - return $ilDB->queryF( - "INSERT INTO rep_robj_xqsp_node (id, path_fi, question_fi, node_index) + /** + * @var integer + */ + protected $id; + + /** + * @var integer + */ + protected $index; + + /** + * @var assQuestion + */ + protected $question; + + /** + * @var int + */ + protected $question_index; + + /** + * @var string|null + */ + protected $initial_condition; + + /** + * @var ilQuestionSetPoolPath + */ + protected $path; + + /** + * @var ilQuestionSetPoolJumpConditionList + */ + protected $jump_condition_list; + + /** + * @var int + */ + protected $dominant_scoring = null; + + /** + * @var string null + */ + protected $true_feedback = null; + + /** + * @var string null + */ + protected $false_feedback = null; + + public function __construct($id = 0) + { + require_once "class.ilQuestionSetPoolJumpConditionList.php"; + $this->jump_condition_list = new ilQuestionSetPoolJumpConditionList($this); + + parent::__construct($id); + } + + /** + * @param int $id + */ + public function setId($id) + { + $this->id = $id; + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param int $index + */ + public function setIndex($index) + { + $this->index = $index; + } + + /** + * @return int + */ + public function getIndex() + { + return $this->index; + } + + /** + * @param null|string $initial_condition + */ + public function setInitialCondition($initial_condition) + { + $this->initial_condition = $initial_condition; + } + + /** + * @return null|string + */ + public function getInitialCondition() + { + return $this->initial_condition; + } + + /** + * @param \assQuestion $question + */ + public function setQuestion($question) + { + $this->question = $question; + } + + /** + * @return \assQuestion + */ + public function getQuestion() + { + return $this->question; + } + + /** + * @param \ilQuestionSetPoolPath $path + */ + public function setPath(ilQuestionSetPoolPath $path) + { + $this->path = $path; + } + + /** + * @return \ilQuestionSetPoolPath + */ + public function getPath() + { + return $this->path; + } + + /** + * @param \ilQuestionSetPoolJumpConditionList $jump_condition_list + */ + public function setJumpConditionList($jump_condition_list) + { + $this->jump_condition_list = $jump_condition_list; + } + + /** + * @return \ilQuestionSetPoolJumpConditionList + */ + public function getJumpConditionList() + { + return $this->jump_condition_list; + } + + /** + * @return int + */ + public function getQuestionIndex() + { + return $this->question_index; + } + + /** + * @param int $dominant_scoring + */ + public function setDominantScoring($dominant_scoring) + { + $this->dominant_scoring = $dominant_scoring; + } + + /** + * @return int + */ + public function getDominantScoring() + { + return $this->dominant_scoring; + } + + /** + * @param integer $id + * @return bool + */ + public static function exists($id) + { + global $DIC; + $ilDB = $DIC->database(); + + $result = $ilDB->queryF( + "SELECT COUNT(*) cnt FROM rep_robj_xqsp_node WHERE id = %s", + array("integer"), + array($id) + ); + $data = $ilDB->fetchAssoc($result); + + return (int) $data['cnt'] == 1 ? true : false; + } + + public function update() + { + global $DIC; + $ilDB = $DIC->database(); + + if ($this->id > 0) { + return (bool) $ilDB->update( + "rep_robj_xqsp_node", + array( + "question_fi" => array('integer', $this->getQuestion()->getId()), + "initial_condition" => array('text', $this->getInitialCondition()), + "dominant_scoring" => array("integer", $this->getDominantScoring()), + "true_feedback" => array('clob', $this->getTrueFeedback()), + "false_feedback" => array('clob', $this->getFalseFeedback()), + ), + array( + 'id' => array("integer", $this->getId()) + ) + ); + } else { + $this->setId($ilDB->nextId("rep_robj_xqsp_node")); + + return $ilDB->queryF( + "INSERT INTO rep_robj_xqsp_node (id, path_fi, question_fi, node_index) (SELECT %s,%s, %s, CASE WHEN MAX(node_index) IS NULL THEN 1 ELSE MAX(node_index) + 1 END FROM rep_robj_xqsp_node WHERE path_fi = %s)", - array("integer", "integer", "integer","integer"), - array($this->getId(), $this->getPath()->getId(), $this->getQuestion()->getId(), $this->getPath()->getId()) - ); - } - } - - public function read() - { - require_once "class.ilQuestionSetPoolPath.php"; - - global $DIC; - $ilDB = $DIC->database(); - - $result = $ilDB->queryF( - "SELECT node.*, qst.question_index FROM rep_robj_xqsp_node node + array("integer", "integer", "integer","integer"), + array($this->getId(), $this->getPath()->getId(), $this->getQuestion()->getId(), $this->getPath()->getId()) + ); + } + } + + public function read() + { + require_once "class.ilQuestionSetPoolPath.php"; + + global $DIC; + $ilDB = $DIC->database(); + + $result = $ilDB->queryF( + "SELECT node.*, qst.question_index FROM rep_robj_xqsp_node node INNER JOIN rep_robj_xqsp_qs_qst qst ON qst.question_fi = node.question_fi WHERE id = %s", - array("integer"), - array($this->id) - ); - - $data = $ilDB->fetchAssoc($result); - - $this->setId($data['id']); - $this->setIndex($data['node_index']); - $this->setInitialCondition($data['initial_condition']); - $this->setDominantScoring($data["dominant_scoring"]); - $this->setQuestion(assQuestion::_instantiateQuestion($data['question_fi'])); - $this->question_index = $data["question_index"]; - - require_once 'Services/RTE/classes/class.ilRTE.php'; - $this->setTrueFeedback(ilRTE::_replaceMediaObjectImageSrc($data['true_feedback'], 1)); - $this->setFalseFeedback(ilRTE::_replaceMediaObjectImageSrc($data['false_feedback'], 1)); - - $path_fi = (isset($_GET['path_id']))? $_GET['path_id'] : $data['path_fi']; - $path = new ilQuestionSetPoolPath($path_fi); - $path->read(); - $this->setPath($path); - } - - /** - * @param ilQuestionSetPoolPath $path - * @param array $question_ids - */ - public function duplicate($path, $question_ids) - { - global $DIC; - $ilDB = $DIC->database(); - - $clone = clone $this; - $clone->setId($ilDB->nextId("rep_robj_xqsp_node")); - $clone->setPath($path); - - $ilDB->insert( - "rep_robj_xqsp_node", - array( - "id" => array("integer", $clone->getId()), - "path_fi" => array("integer", $clone->getPath()->getId()), - "question_fi" => array("integer", $question_ids[$this->getQuestion()->getId()]), - "node_index" => array("integer", $clone->getIndex()), - "initial_condition" => array("text", $clone->getInitialCondition()), - "dominant_scoring" => array("integer", $this->getDominantScoring()), - "true_feedback" => array("clob", $clone->getTrueFeedback()), - "false_feedback" => array("clob", $clone->getFalseFeedback()), - ) - ); - - require_once "class.ilQuestionSetPoolJumpCondition.php"; - $data = $this->getJumpConditionList()->getData(); - foreach($data as $element) - { - $condition = new ilQuestionSetPoolJumpCondition($element["id"]); - $condition->read(); - $condition->duplicate($clone, $question_ids); - } - - return true; - } - - public function remove() - { - global $DIC; - $ilDB = $DIC->database(); - - $this->removeJumpConditions(); - - return $ilDB->manipulateF( - "DELETE FROM rep_robj_xqsp_node WHERE id = %s", - array("integer"), - array($this->getId()) - ); - } - - /** - * @param ilPropertyFormGUI $form - */ - public function bindForm(ilPropertyFormGUI $form) - { - require_once 'Services/RTE/classes/class.ilRTE.php'; - - if(($input = $form->getInput("initial_condition")) !== null) - { - $this->setInitialCondition($input); - } - - if(($input = $form->getInput("question_fi")) != null) - { - $this->setQuestion(assQuestion::_instanciateQuestion($input)); - } - - if(($input = $form->getInput("true_feedback"))!= NULL) - { - $this->setTrueFeedback(ilRTE::_replaceMediaObjectImageSrc($input, 0)); - } - - if(($input = $form->getInput("false_feedback"))!= NULL) - { - $this->setFalseFeedback(ilRTE::_replaceMediaObjectImageSrc($input, 0)); - } - } - - private function removeJumpConditions() - { - require_once "class.ilQuestionSetPoolJumpCondition.php"; - $data = $this->getJumpConditionList()->getData(); - foreach ($data as $element) - { - $condition = new ilQuestionSetPoolJumpCondition($element["id"]); - $condition->read(); - $condition->remove(); - } - } - - /** - * @return string - */ - public function getFalseFeedback() - { - return $this->false_feedback; - } - - /** - * @param string $false_feedback - */ - public function setFalseFeedback($false_feedback) - { - $this->false_feedback = $false_feedback; - } - - /** - * @return string - */ - public function getTrueFeedback() - { - return $this->true_feedback; - } - - /** - * @param string $true_feedback - */ - public function setTrueFeedback($true_feedback) - { - $this->true_feedback = $true_feedback; - } - - public function import() - { - global $DIC; - $ilDB = $DIC->database(); - - $this->setId($ilDB->nextId("rep_robj_xqsp_node")); - - $ilDB->queryF( - "INSERT INTO rep_robj_xqsp_node (id, path_fi, question_fi, node_index) + array("integer"), + array($this->id) + ); + + $data = $ilDB->fetchAssoc($result); + + $this->setId($data['id']); + $this->setIndex($data['node_index']); + $this->setInitialCondition($data['initial_condition']); + $this->setDominantScoring($data["dominant_scoring"]); + $this->setQuestion(assQuestion::_instantiateQuestion($data['question_fi'])); + $this->question_index = $data["question_index"]; + + $this->setTrueFeedback(ilRTE::_replaceMediaObjectImageSrc($data['true_feedback'], 1)); + $this->setFalseFeedback(ilRTE::_replaceMediaObjectImageSrc($data['false_feedback'], 1)); + + $path_fi = (isset($_GET['path_id']))? $_GET['path_id'] : $data['path_fi']; + $path = new ilQuestionSetPoolPath($path_fi); + $path->read(); + $this->setPath($path); + } + + /** + * @param ilQuestionSetPoolPath $path + * @param array $question_ids + */ + public function duplicate($path, $question_ids) + { + global $DIC; + $ilDB = $DIC->database(); + + $clone = clone $this; + $clone->setId($ilDB->nextId("rep_robj_xqsp_node")); + $clone->setPath($path); + + $ilDB->insert( + "rep_robj_xqsp_node", + array( + "id" => array("integer", $clone->getId()), + "path_fi" => array("integer", $clone->getPath()->getId()), + "question_fi" => array("integer", $question_ids[$this->getQuestion()->getId()]), + "node_index" => array("integer", $clone->getIndex()), + "initial_condition" => array("text", $clone->getInitialCondition()), + "dominant_scoring" => array("integer", $this->getDominantScoring()), + "true_feedback" => array("clob", $clone->getTrueFeedback()), + "false_feedback" => array("clob", $clone->getFalseFeedback()), + ) + ); + + require_once "class.ilQuestionSetPoolJumpCondition.php"; + $data = $this->getJumpConditionList()->getData(); + foreach ($data as $element) { + $condition = new ilQuestionSetPoolJumpCondition($element["id"]); + $condition->read(); + $condition->duplicate($clone, $question_ids); + } + + return true; + } + + public function remove() + { + global $DIC; + $ilDB = $DIC->database(); + + $this->removeJumpConditions(); + + return $ilDB->manipulateF( + "DELETE FROM rep_robj_xqsp_node WHERE id = %s", + array("integer"), + array($this->getId()) + ); + } + + /** + * @param ilPropertyFormGUI $form + */ + public function bindForm(ilPropertyFormGUI $form) + { + if (($input = $form->getInput("initial_condition")) !== null) { + $this->setInitialCondition($input); + } + + if (($input = $form->getInput("question_fi")) != null) { + $this->setQuestion(assQuestion::_instanciateQuestion($input)); + } + + if (($input = $form->getInput("true_feedback")) != null) { + $this->setTrueFeedback(ilRTE::_replaceMediaObjectImageSrc($input, 0)); + } + + if (($input = $form->getInput("false_feedback")) != null) { + $this->setFalseFeedback(ilRTE::_replaceMediaObjectImageSrc($input, 0)); + } + } + + private function removeJumpConditions() + { + require_once "class.ilQuestionSetPoolJumpCondition.php"; + $data = $this->getJumpConditionList()->getData(); + foreach ($data as $element) { + $condition = new ilQuestionSetPoolJumpCondition($element["id"]); + $condition->read(); + $condition->remove(); + } + } + + /** + * @return string + */ + public function getFalseFeedback() + { + return $this->false_feedback; + } + + /** + * @param string $false_feedback + */ + public function setFalseFeedback($false_feedback) + { + $this->false_feedback = $false_feedback; + } + + /** + * @return string + */ + public function getTrueFeedback() + { + return $this->true_feedback; + } + + /** + * @param string $true_feedback + */ + public function setTrueFeedback($true_feedback) + { + $this->true_feedback = $true_feedback; + } + + public function import() + { + global $DIC; + $ilDB = $DIC->database(); + + $this->setId($ilDB->nextId("rep_robj_xqsp_node")); + + $ilDB->queryF( + "INSERT INTO rep_robj_xqsp_node (id, path_fi, question_fi, node_index) (SELECT %s,%s, %s, CASE WHEN MAX(node_index) IS NULL THEN 1 ELSE MAX(node_index) + 1 END FROM rep_robj_xqsp_node WHERE path_fi = %s)", - array("integer", "integer", "integer","integer"), - array($this->getId(), $this->getPath()->getId(), $this->getQuestion()->getId(), $this->getPath()->getId()) - ); - - $ilDB->update( - "rep_robj_xqsp_node", - array( - "initial_condition" => array('text', $this->getInitialCondition()), - "dominant_scoring" => array("integer", $this->getDominantScoring()), - "true_feedback" => array('clob', $this->getTrueFeedback()), - "false_feedback" => array('clob', $this->getFalseFeedback()) - ), - array('id' => array("integer", $this->getId()) - ) - ); - } + array("integer", "integer", "integer","integer"), + array($this->getId(), $this->getPath()->getId(), $this->getQuestion()->getId(), $this->getPath()->getId()) + ); + + $ilDB->update( + "rep_robj_xqsp_node", + array( + "initial_condition" => array('text', $this->getInitialCondition()), + "dominant_scoring" => array("integer", $this->getDominantScoring()), + "true_feedback" => array('clob', $this->getTrueFeedback()), + "false_feedback" => array('clob', $this->getFalseFeedback()) + ), + array('id' => array("integer", $this->getId()) + ) + ); + } } diff --git a/classes/models/class.ilQuestionSetPoolNodeList.php b/classes/models/class.ilQuestionSetPoolNodeList.php index 8d5b2f9dfc7324647cc26ab0bbaabeba4ba87c9a..0d9f498529ab5d4e51394963faf285263345a6af 100644 --- a/classes/models/class.ilQuestionSetPoolNodeList.php +++ b/classes/models/class.ilQuestionSetPoolNodeList.php @@ -8,140 +8,131 @@ require_once "abstract.ilPluginModelList.php"; * Date: 21.11.13 * Time: 12:21 * @author Thomas Joußen - */ + */ class ilQuestionSetPoolNodeList extends ilPluginModelList { - /** - * @var ilQuestionSetPoolPath - */ - protected $path; - - public function __construct($path) - { - $this->path = $path; - - parent::__construct(); - } - - /** - * @param array $params - * @param array $filter - * - * @return array - */ - public function loadData($params = array(), $filter = array()) - { - require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/classes/providers/class.ilQuestionSetPoolNodeProvider.php"; - - $provider = new ilQuestionSetPoolNodeProvider(); - $filter["path_fi"] = $this->path->getId(); - return $provider->loadData($filter, $params); - } - - public function update($data) - { - return $this->db->update( - "rep_robj_xqsp_node", - array( - "node_index" => array("integer", $data["node_index"]) - ), - array( - "id" => array("integer", $data["id"]) - ) - ); - } - - public function getQuestionIds() - { - - } - - /** - * @param ilQuestionSetPoolNode $current_node - * - * @return ilQuestionSetPoolNode - */ - public function getNextNode($current_node) - { - $data = $this->getData(); - - foreach($data as $item) - { - if($item["node_index"] > $current_node->getIndex()) - { - $node = new ilQuestionSetPoolNode($item["id"]); - $node->read(); - return $node; - } - } - - return null; - } - - /** - * @param ilQuestionSetPoolNode $current_node - * - * @return IlQuestionSetPoolNode|null - */ - public function getPreviousNode($current_node) - { - $data = $this->getData(); - - $prev = null; - foreach($data as $item) - { - if($item["node_index"] == $current_node->getIndex() && $prev != null) - { - $prev = new ilQuestionSetPoolNode($prev["id"]); - $prev->read(); - return $prev; - } - $prev = $item; - } - return null; - } - - /** - * @param int $question_id - * - * @return ilQuestionSetPoolNode|null - */ - public function getNodeByQuestionId($question_id) - { - $data = $this->getData(); - - foreach($data as $item) - { - if($item["question_fi"] == $question_id) - { - $node = new ilQuestionSetPoolNode($item["id"]); - $node->read(); - return $node; - } - } - return null; - } - - /** - * @param array $data - * - * @return array - */ - public function createObjectsFromData($data) - { - require_once "class.ilQuestionSetPoolJumpConditionList.php"; - require_once "class.ilQuestionSetPoolNode.php"; - foreach($data as $key => $element) - { - $node = new ilQuestionSetPoolNode($element["id"]); - $node->read(); - - $list = new ilQuestionSetPoolJumpConditionList($node); - $data[$key]["jump_conditions"] = $list->getData(); - } - - return $data; - } + /** + * @var ilQuestionSetPoolPath + */ + protected $path; + + public function __construct($path) + { + $this->path = $path; + + parent::__construct(); + } + + /** + * @param array $params + * @param array $filter + * + * @return array + */ + public function loadData($params = array(), $filter = array()) + { + require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/classes/providers/class.ilQuestionSetPoolNodeProvider.php"; + + $provider = new ilQuestionSetPoolNodeProvider(); + $filter["path_fi"] = $this->path->getId(); + return $provider->loadData($filter, $params); + } + + public function update($data) + { + return $this->db->update( + "rep_robj_xqsp_node", + array( + "node_index" => array("integer", $data["node_index"]) + ), + array( + "id" => array("integer", $data["id"]) + ) + ); + } + + public function getQuestionIds() + { + } + + /** + * @param ilQuestionSetPoolNode $current_node + * + * @return ilQuestionSetPoolNode + */ + public function getNextNode($current_node) + { + $data = $this->getData(); + + foreach ($data as $item) { + if ($item["node_index"] > $current_node->getIndex()) { + $node = new ilQuestionSetPoolNode($item["id"]); + $node->read(); + return $node; + } + } + + return null; + } + + /** + * @param ilQuestionSetPoolNode $current_node + * + * @return IlQuestionSetPoolNode|null + */ + public function getPreviousNode($current_node) + { + $data = $this->getData(); + + $prev = null; + foreach ($data as $item) { + if ($item["node_index"] == $current_node->getIndex() && $prev != null) { + $prev = new ilQuestionSetPoolNode($prev["id"]); + $prev->read(); + return $prev; + } + $prev = $item; + } + return null; + } + + /** + * @param int $question_id + * + * @return ilQuestionSetPoolNode|null + */ + public function getNodeByQuestionId($question_id) + { + $data = $this->getData(); + + foreach ($data as $item) { + if ($item["question_fi"] == $question_id) { + $node = new ilQuestionSetPoolNode($item["id"]); + $node->read(); + return $node; + } + } + return null; + } + + /** + * @param array $data + * + * @return array + */ + public function createObjectsFromData($data) + { + require_once "class.ilQuestionSetPoolJumpConditionList.php"; + require_once "class.ilQuestionSetPoolNode.php"; + foreach ($data as $key => $element) { + $node = new ilQuestionSetPoolNode($element["id"]); + $node->read(); + + $list = new ilQuestionSetPoolJumpConditionList($node); + $data[$key]["jump_conditions"] = $list->getData(); + } + + return $data; + } } - \ No newline at end of file diff --git a/classes/models/class.ilQuestionSetPoolPath.php b/classes/models/class.ilQuestionSetPoolPath.php index 74a4ba9b0c3f33e169b9789652405664d0765b80..fe703018b4f096821809cea21c6a31891f8a5cae 100644 --- a/classes/models/class.ilQuestionSetPoolPath.php +++ b/classes/models/class.ilQuestionSetPoolPath.php @@ -8,368 +8,356 @@ require_once "abstract.ilPluginModel.php"; * Date: 21.11.13 * Time: 11:02 * @author Thomas Joußen - */ + */ class ilQuestionSetPoolPath extends ilPluginModel { - /** - * @var integer - */ - protected $id; - - /** - * @var string - */ - protected $title; - - /** - * @var ilQuestionSetPoolNodeList - */ - protected $nodes; - - /** - * @var ilQuestionSetPoolSet - */ - protected $set; - - /** - * @var integer - */ - private $start_question_id; - - /** - * @var int - */ - private $index; - - /** - * @param int $id - */ - public function setId($id) - { - $this->id = $id; - } - - /** - * @return int - */ - public function getId() - { - return $this->id; - } - - /** - * @param \ilQuestionSetPoolNodeList $nodes - */ - public function setNodes($nodes) - { - $this->nodes = $nodes; - } - - /** - * @return \ilQuestionSetPoolNodeList - */ - public function getNodes() - { - return $this->nodes; - } - - /** - * @param string $title - */ - public function setTitle($title) - { - $this->title = $title; - } - - /** - * @return string - */ - public function getTitle() - { - return $this->title; - } - - /** - * @param \ilQuestionSetPoolSet $set - */ - public function setSet($set) - { - $this->set = $set; - } - - /** - * @return \ilQuestionSetPoolSet - */ - public function getSet() - { - return $this->set; - } - - /** - * @param int $index - */ - public function setIndex($index) - { - $this->index = $index; - } - - /** - * @return int - */ - public function getIndex() - { - return $this->index; - } - - /** - * @param int $question_id - * - * @return bool - */ - public function isQuestionInPath($question_id) - { - $data = $this->getNodes()->getData(); - foreach($data as $item) - { - if($item["question_fi"] == $question_id) - { - return true; - } - } - return false; - } - - /** - * @param integer $id - * @return bool - */ - public static function exists($id) - { - global $DIC; - $ilDB = $DIC->database(); - - $result = $ilDB->queryF( - "SELECT COUNT(*) cnt FROM rep_robj_xqsp_path WHERE id = %s", - array("integer"), - array($id) - ); - $data = $ilDB->fetchAssoc($result); - - return (int)$data['cnt'] == 1 ? true : false; - } - - public function update() - { - global $DIC; - $ilDB = $DIC->database(); - - if($this->id > 0) - { - $ilDB->update( - "rep_robj_xqsp_path", - array("title" => array("text", $this->getTitle())), - array("id" => array("integer", $this->getId())) - ); - } - else - { - $this->setId($ilDB->nextId("rep_robj_xqsp_path")); - $success = $ilDB->queryF( - "INSERT INTO rep_robj_xqsp_path (id, title, questionset_fi, path_index) + /** + * @var integer + */ + protected $id; + + /** + * @var string + */ + protected $title; + + /** + * @var ilQuestionSetPoolNodeList + */ + protected $nodes; + + /** + * @var ilQuestionSetPoolSet + */ + protected $set; + + /** + * @var integer + */ + private $start_question_id; + + /** + * @var int + */ + private $index; + + /** + * @param int $id + */ + public function setId($id) + { + $this->id = $id; + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param \ilQuestionSetPoolNodeList $nodes + */ + public function setNodes($nodes) + { + $this->nodes = $nodes; + } + + /** + * @return \ilQuestionSetPoolNodeList + */ + public function getNodes() + { + return $this->nodes; + } + + /** + * @param string $title + */ + public function setTitle($title) + { + $this->title = $title; + } + + /** + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * @param \ilQuestionSetPoolSet $set + */ + public function setSet($set) + { + $this->set = $set; + } + + /** + * @return \ilQuestionSetPoolSet + */ + public function getSet() + { + return $this->set; + } + + /** + * @param int $index + */ + public function setIndex($index) + { + $this->index = $index; + } + + /** + * @return int + */ + public function getIndex() + { + return $this->index; + } + + /** + * @param int $question_id + * + * @return bool + */ + public function isQuestionInPath($question_id) + { + $data = $this->getNodes()->getData(); + foreach ($data as $item) { + if ($item["question_fi"] == $question_id) { + return true; + } + } + return false; + } + + /** + * @param integer $id + * @return bool + */ + public static function exists($id) + { + global $DIC; + $ilDB = $DIC->database(); + + $result = $ilDB->queryF( + "SELECT COUNT(*) cnt FROM rep_robj_xqsp_path WHERE id = %s", + array("integer"), + array($id) + ); + $data = $ilDB->fetchAssoc($result); + + return (int) $data['cnt'] == 1 ? true : false; + } + + public function update() + { + global $DIC; + $ilDB = $DIC->database(); + + if ($this->id > 0) { + $ilDB->update( + "rep_robj_xqsp_path", + array("title" => array("text", $this->getTitle())), + array("id" => array("integer", $this->getId())) + ); + } else { + $this->setId($ilDB->nextId("rep_robj_xqsp_path")); + $success = $ilDB->queryF( + "INSERT INTO rep_robj_xqsp_path (id, title, questionset_fi, path_index) (SELECT %s,%s, %s, CASE WHEN MAX(path_index) IS NULL THEN 1 ELSE MAX(path_index) + 1 END FROM rep_robj_xqsp_path WHERE questionset_fi = %s)", - array("integer", "text", "integer", "integer"), - array($this->getId(), $this->getTitle(), (int)$_GET['set_id'],(int)$_GET['set_id']) - ); - - $node_id = $ilDB->nextId("rep_robj_xqsp_node"); - return $success && $ilDB->insert( - "rep_robj_xqsp_node", - array( - "id" => array("integer", $node_id), - "question_fi" => array("integer", $this->start_question_id), - "path_fi" => array("integer", $this->getId()), - "node_index" => array("integer", 1), - "initial_condition" => array("text", "") - ) - ); - } - } - - /** - * Extracted from update method for XML-Import procedure - * - * @return bool - */ - public function import() - { - global $DIC; - $ilDB = $DIC->database(); - - $this->setId($ilDB->nextId("rep_robj_xqsp_path")); - $success = $ilDB->queryF( - "INSERT INTO rep_robj_xqsp_path (id, title, questionset_fi, path_index) + array("integer", "text", "integer", "integer"), + array($this->getId(), $this->getTitle(), (int) $_GET['set_id'],(int) $_GET['set_id']) + ); + + $node_id = $ilDB->nextId("rep_robj_xqsp_node"); + return $success && $ilDB->insert( + "rep_robj_xqsp_node", + array( + "id" => array("integer", $node_id), + "question_fi" => array("integer", $this->start_question_id), + "path_fi" => array("integer", $this->getId()), + "node_index" => array("integer", 1), + "initial_condition" => array("text", "") + ) + ); + } + } + + /** + * Extracted from update method for XML-Import procedure + * + * @return bool + */ + public function import() + { + global $DIC; + $ilDB = $DIC->database(); + + $this->setId($ilDB->nextId("rep_robj_xqsp_path")); + $success = $ilDB->queryF( + "INSERT INTO rep_robj_xqsp_path (id, title, questionset_fi, path_index) (SELECT %s,%s, %s, CASE WHEN MAX(path_index) IS NULL THEN 1 ELSE MAX(path_index) + 1 END FROM rep_robj_xqsp_path WHERE questionset_fi = %s)", - array("integer", "text", "integer", "integer"), - array($this->getId(), $this->getTitle(), (int)$this->getSet()->getId(),(int)$this->getSet()->getId()) - ); - return $success; - } - - public function read() - { - require_once "class.ilQuestionSetPoolNodeList.php"; - require_once "class.ilQuestionSetPoolSet.php"; - global $DIC; - $ilDB = $DIC->database(); - $result = $ilDB->queryF( - "SELECT * FROM rep_robj_xqsp_path WHERE id = %s", - array("integer"), - array($this->id) - ); - - $data = $ilDB->fetchAssoc($result); - - $this->setId($data['id']); - $this->setTitle($data['title']); - $this->setIndex($data["path_index"]); - $this->setNodes(new ilQuestionSetPoolNodeList($this)); - - $id = isset($data["questionset_fi"])? $data["questionset_fi"] : $_GET['set_id']; - $set = new ilQuestionSetPoolSet($id); - $set->read(); - $this->setSet($set); - } - - /** - * @param array $question_ids - */ - public function duplicate($question_ids, $title = "") - { - global $DIC; - $ilDB = $DIC->database(); - - $clone = clone $this; - $clone->setId($ilDB->nextId("rep_robj_xqsp_path")); - - if($title != "") - { - $clone->setTitle($title); - } - - $ilDB->queryF( - "INSERT INTO rep_robj_xqsp_path (id, title, questionset_fi, path_index) + array("integer", "text", "integer", "integer"), + array($this->getId(), $this->getTitle(), (int) $this->getSet()->getId(),(int) $this->getSet()->getId()) + ); + return $success; + } + + public function read() + { + require_once "class.ilQuestionSetPoolNodeList.php"; + require_once "class.ilQuestionSetPoolSet.php"; + global $DIC; + $ilDB = $DIC->database(); + $result = $ilDB->queryF( + "SELECT * FROM rep_robj_xqsp_path WHERE id = %s", + array("integer"), + array($this->id) + ); + + $data = $ilDB->fetchAssoc($result); + + $this->setId($data['id']); + $this->setTitle($data['title']); + $this->setIndex($data["path_index"]); + $this->setNodes(new ilQuestionSetPoolNodeList($this)); + + $id = isset($data["questionset_fi"])? $data["questionset_fi"] : $_GET['set_id']; + $set = new ilQuestionSetPoolSet($id); + $set->read(); + $this->setSet($set); + } + + /** + * @param array $question_ids + */ + public function duplicate($question_ids, $title = "") + { + global $DIC; + $ilDB = $DIC->database(); + + $clone = clone $this; + $clone->setId($ilDB->nextId("rep_robj_xqsp_path")); + + if ($title != "") { + $clone->setTitle($title); + } + + $ilDB->queryF( + "INSERT INTO rep_robj_xqsp_path (id, title, questionset_fi, path_index) (SELECT %s,%s, %s, CASE WHEN MAX(path_index) IS NULL THEN 1 ELSE MAX(path_index) + 1 END FROM rep_robj_xqsp_path WHERE questionset_fi = %s)", - array("integer", "text", "integer", "integer"), - array($clone->getId(), $clone->getTitle(),$clone->getSet()->getId(),$clone->getSet()->getId()) - ); - - require_once "class.ilQuestionSetPoolNode.php"; - $data = $this->getNodes()->getData(); - foreach($data as $element) - { - $node = new ilQuestionSetPoolNode($element["id"]); - $node->read(); - $node->duplicate($clone, $question_ids); - } - } - - public function remove() - { - global $DIC; - $ilDB = $DIC->database(); - - $this->removeNodes(); - - return $ilDB->manipulateF( - "DELETE FROM rep_robj_xqsp_path WHERE id = %s", - array("integer"), - array($this->getId()) - ); - } - - public function getQuestionsLowerAndEqualsIndex($index) - { - global $DIC; - $ilDB = $DIC->database(); - - $result = $ilDB->queryF( - "SELECT qs_qst.question_index, q.title, q.question_id + array("integer", "text", "integer", "integer"), + array($clone->getId(), $clone->getTitle(),$clone->getSet()->getId(),$clone->getSet()->getId()) + ); + + require_once "class.ilQuestionSetPoolNode.php"; + $data = $this->getNodes()->getData(); + foreach ($data as $element) { + $node = new ilQuestionSetPoolNode($element["id"]); + $node->read(); + $node->duplicate($clone, $question_ids); + } + } + + public function remove() + { + global $DIC; + $ilDB = $DIC->database(); + + $this->removeNodes(); + + return $ilDB->manipulateF( + "DELETE FROM rep_robj_xqsp_path WHERE id = %s", + array("integer"), + array($this->getId()) + ); + } + + public function getQuestionsLowerAndEqualsIndex($index) + { + global $DIC; + $ilDB = $DIC->database(); + + $result = $ilDB->queryF( + "SELECT qs_qst.question_index, q.title, q.question_id FROM rep_robj_xqsp_qs_qst qs_qst INNER JOIN rep_robj_xqsp_node n ON n.question_fi = qs_qst.question_fi INNER JOIN qpl_questions q ON q.question_id = qs_qst.question_fi WHERE n.path_fi = %s AND n.node_index <= %s ORDER BY n.node_index", - array("integer", "integer"), - array($this->getId(), $index) - ); - - $data = array(); - while(($row = $ilDB->fetchAssoc($result)) != null) - { - $data[] = $row; - } - return $data; - } - - /** - * @param ilQuestionSetPoolPath $path - * @param int $index - * - * @return bool - */ - public function isEqualsUntilIndex($path, $index) - { - $current_nodes = $this->getNodes()->getData(); - $compate_nodes = $path->getNodes()->getData(); - - for($i = 0; $i < $index; $i++) - { - if( - $current_nodes[$i]["question_index"] != $compate_nodes[$i]["question_index"] - ) - { - return false; - } - } - return true; - } - - /** - * @param ilPropertyFormGUI $form - */ - public function bindForm(ilPropertyFormGUI $form) - { - $this->setTitle($form->getInput("title")); - $this->start_question_id = $form->getInput("start_question"); - } - - private function removeNodes() - { - require_once "class.ilQuestionSetPoolNode.php"; - - $data = $this->getNodes()->getData(); - foreach ($data as $element) - { - $node = new ilQuestionSetPoolNode($element["id"]); - $node->read(); - $node->remove(); - } - } + array("integer", "integer"), + array($this->getId(), $index) + ); + + $data = array(); + while (($row = $ilDB->fetchAssoc($result)) != null) { + $data[] = $row; + } + return $data; + } + + /** + * @param ilQuestionSetPoolPath $path + * @param int $index + * + * @return bool + */ + public function isEqualsUntilIndex($path, $index) + { + $current_nodes = $this->getNodes()->getData(); + $compate_nodes = $path->getNodes()->getData(); + + for ($i = 0; $i < $index; $i++) { + if ( + $current_nodes[$i]["question_index"] != $compate_nodes[$i]["question_index"] + ) { + return false; + } + } + return true; + } + + /** + * @param ilPropertyFormGUI $form + */ + public function bindForm(ilPropertyFormGUI $form) + { + $this->setTitle($form->getInput("title")); + $this->start_question_id = $form->getInput("start_question"); + } + + private function removeNodes() + { + require_once "class.ilQuestionSetPoolNode.php"; + + $data = $this->getNodes()->getData(); + foreach ($data as $element) { + $node = new ilQuestionSetPoolNode($element["id"]); + $node->read(); + $node->remove(); + } + } } - \ No newline at end of file diff --git a/classes/models/class.ilQuestionSetPoolPathList.php b/classes/models/class.ilQuestionSetPoolPathList.php index b061b7e4d5ccc423831ec64722d7dfcdbfd49650..413ae465212f4a9e521fff86f1c4160e3fcea08a 100644 --- a/classes/models/class.ilQuestionSetPoolPathList.php +++ b/classes/models/class.ilQuestionSetPoolPathList.php @@ -8,94 +8,92 @@ require_once "abstract.ilPluginModelList.php"; * Date: 10.10.13 * Time: 10:49 * @author Thomas Joußen - */ + */ class ilQuestionSetPoolPathList extends ilPluginModelList { - /** - * @var ilQuestionSetPoolSet - */ - protected $set; + /** + * @var ilQuestionSetPoolSet + */ + protected $set; - public function __construct($set) - { - $this->set = $set; + public function __construct($set) + { + $this->set = $set; - parent::__construct(); - } + parent::__construct(); + } - /** - * @param array $params - * @param array $filter - * - * @return array - */ - public function loadData($params = array(), $filter = array()) - { - require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/classes/providers/class.ilQuestionSetPoolPathProvider.php"; + /** + * @param array $params + * @param array $filter + * + * @return array + */ + public function loadData($params = array(), $filter = array()) + { + require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/classes/providers/class.ilQuestionSetPoolPathProvider.php"; - $provider = new ilQuestionSetPoolPathProvider(); - $filter["questionset_fi"] = $this->set->getId(); - return $provider->loadData($filter, $params); - } + $provider = new ilQuestionSetPoolPathProvider(); + $filter["questionset_fi"] = $this->set->getId(); + return $provider->loadData($filter, $params); + } - public function update($data) - { - return $this->db->update( - "rep_robj_xqsp_path", - array( - "path_index" => array("integer", $data["path_index"]) - ), - array( - "id" => array("integer", $data["id"]) - ) - ); - } + public function update($data) + { + return $this->db->update( + "rep_robj_xqsp_path", + array( + "path_index" => array("integer", $data["path_index"]) + ), + array( + "id" => array("integer", $data["id"]) + ) + ); + } - public function getPath($id) - { - $data = $this->getData(); + public function getPath($id) + { + $data = $this->getData(); - foreach($data as $item) - { - if($item->getId() == $id) - { - return $item; - } - } + foreach ($data as $item) { + if ($item->getId() == $id) { + return $item; + } + } - return null; - } + return null; + } - public function insert($question_ids) - { - return true; - } + public function insert($question_ids) + { + return true; + } - public function remove($question_ids) - { - return true; - } + public function remove($question_ids) + { + return true; + } - /** - * @param array $data - * - * @return array - */ - public function createObjectsFromData($data) - { - return $data; - /*$objects = array(); - foreach($data as $item) - { - require_once 'class.ilQuestionSetPoolSet.php'; - $set = new ilQuestionSetPoolSet($this->question_set_pool); - $set->setId($item['id']); - $set->setTitle($item['title']); - $set->setDescription($item['description']); + /** + * @param array $data + * + * @return array + */ + public function createObjectsFromData($data) + { + return $data; + /*$objects = array(); + foreach($data as $item) + { + require_once 'class.ilQuestionSetPoolSet.php'; + $set = new ilQuestionSetPoolSet($this->question_set_pool); + $set->setId($item['id']); + $set->setTitle($item['title']); + $set->setDescription($item['description']); - $objects[] = $set; - } + $objects[] = $set; + } - return $objects;*/ - } + return $objects;*/ + } } diff --git a/classes/models/class.ilQuestionSetPoolSet.php b/classes/models/class.ilQuestionSetPoolSet.php index 6326638f28832e7ed28053b08386884f99d49372..557791b783220c4f5f2c2bf2b5628d44c2e3856a 100644 --- a/classes/models/class.ilQuestionSetPoolSet.php +++ b/classes/models/class.ilQuestionSetPoolSet.php @@ -8,480 +8,467 @@ require_once "abstract.ilPluginModel.php"; * Date: 02.10.13 * Time: 12:18 * @author Thomas Joußen - */ -class ilQuestionSetPoolSet extends ilPluginModel{ - - /** - * @var integer - */ - protected $id; - - /** - * @var string - */ - protected $title; - - /** - * @var string - */ - protected $description; - - /** - * @var ilQuestionSetPoolSetQuestionList - */ - protected $question_list; - - /** - * @var ilQuestionSetPoolPathList - */ - protected $path_list; - - /** - * @var int|null - */ - protected $original_id; - - /** - * @var int - */ - protected $container_obj_id; - /** - * needed for formatest-importer - * @var array - */ - public $xqsp_qst_mapping = array(); - - - /** - * ilQuestionSetPoolSet constructor. - * @param int $id question_set_id - */ - public function __construct($id = 0) - { - require_once 'class.ilQuestionSetPoolSetQuestionList.php'; - require_once 'class.ilQuestionSetPoolPathList.php'; - $this->question_list = new ilQuestionSetPoolSetQuestionList($this); - $this->path_list = new ilQuestionSetPoolPathList($this); - - parent::__construct($id); - } - - /** - * @param integer $id - * @return bool - */ - public static function exists($id) - { - global $DIC; - $ilDB = $DIC->database(); - - $result = $ilDB->queryF( - "SELECT COUNT(*) cnt FROM rep_robj_xqsp_qs WHERE id = %s", - array("integer"), - array($id) - ); - $data = $ilDB->fetchAssoc($result); - - return (int)$data['cnt'] == 1 ? true : false; - } - - /** - * @param string $description - */ - public function setDescription($description) - { - $this->description = $description; - } - - /** - * @return string - */ - public function getDescription() - { - return $this->description; - } - - /** - * @param int $id - */ - public function setId($id) - { - $this->id = $id; - } - - /** - * @return int - */ - public function getId() - { - return $this->id; - } - - /** - * @param string $title - */ - public function setTitle($title) - { - $this->title = $title; - } - - /** - * @return string - */ - public function getTitle() - { - return $this->title; - } - - /** - * @return ilQuestionSetPoolSetQuestionList - */ - public function getQuestionList() - { - return $this->question_list; - } - - /** - * @return ilQuestionSetPoolPathList - */ - public function getPathList() - { - return $this->path_list; - } - - /** - * @param int|null $original_id - */ - public function setOriginalId($original_id) - { - $this->original_id = $original_id; - } - - /** - * @return int|null - */ - public function getOriginalId() - { - return $this->original_id; - } - - /** - * @param int $container_obj_id - */ - public function setContainerObjId($container_obj_id) - { - $this->container_obj_id = $container_obj_id; - } - - /** - * @return int - */ - public function getContainerObjId() - { - return $this->container_obj_id; - } - - public function update() - { - global $DIC; - $ilDB = $DIC->database(); - - if($this->id > 0) - { - return (bool)$ilDB->update( - "rep_robj_xqsp_qs", - array( - "title" => array("text", $this->getTitle()), - "description" => array("text", $this->getDescription()), - "original_id" => array("integer", $this->getOriginalId()) - ), - array( - "id" => array("integer", $this->getId()) - ) - ); - } - else - { - $this->setId($ilDB->nextId("rep_robj_xqsp_qs")); - return $ilDB->insert( - "rep_robj_xqsp_qs", - array( - "id" => array("integer", $this->getId()), - "title" => array("text", $this->getTitle()), - "description" => array("text", $this->getDescription()), - "questionsetpool_fi" => array("integer", $this->getContainerObjId()), - "original_id" => array("integer", $this->getOriginalId()) - ) - ); - } - } - - public function read() - { - global $DIC; - $ilDB = $DIC->database(); - - $result = $ilDB->queryF( - "SELECT * FROM rep_robj_xqsp_qs WHERE id = %s", - array("integer"), - array($this->id) - ); - - $data = $ilDB->fetchAssoc($result); - - if($data != null) - { - $this->setContainerObjId($data["questionsetpool_fi"]); - $this->setDescription($data['description']); - $this->setTitle($data['title']); - $this->setOriginalId($data["original_id"]); - } - } - - /** - * @return bool - */ - public function remove() - { - global $DIC; - $ilDB = $DIC->database(); - - $this->removePaths(); - $this->removeQuestions(); - - return $ilDB->manipulateF( - "DELETE FROM rep_robj_xqsp_qs WHERE id = %s", - array("integer"), - array($this->getId()) - ); - } - - public function isTitleUnique() - { - global $DIC; - $ilDB = $DIC->database(); - - $result = $ilDB->queryF( - "SELECT COUNT(id) num FROM rep_robj_xqsp_qs WHERE title = %s AND id != %s AND questionsetpool_fi = %s", - array("text", "integer", "integer"), - array($this->getTitle(), $this->getId(), $this->getContainerObjId()) - ); - - $row = $ilDB->fetchAssoc($result); - - return $row["num"] == 0; - } - - /** - * @return array - */ - public function getPathTitles() - { - global $DIC; - $ilDB = $DIC->database(); - - $titles = array(); - $result = $ilDB->queryF( - "SELECT DISTINCT(title) FROM rep_robj_xqsp_path WHERE questionset_fi = %s", - array("integer"), - array($this->getId()) - ); - - while($row = $ilDB->fetchAssoc($result)) - { - $titles[] = $row['title']; - } - - return $titles; - } - - /** - * @param string$original_title - * @param integer $container_obj_id - */ - protected function getUniqueTitleForContainer($original_title, $container_obj_id) - { - global $DIC; - $ilDB = $DIC->database(); - - $title = $original_title; - $i = 1; - if($this->getContainerObjId() == $container_obj_id) - { - ++$i; - $title .= ' (' . $i . ')'; - } - - do - { - $result = $ilDB->queryF( - "SELECT id FROM rep_robj_xqsp_qs WHERE title = %s AND questionsetpool_fi = %s", - array("text", "integer"), - array($title, $container_obj_id) - ); - if(!$ilDB->numRows($result)) - { - return $title; - } - $title = $original_title . ' (' . ++$i . ')'; - } - while(true); - } - - /** - * @param int $container_obj_id - * - * @return self - */ - public function duplicate($container_obj_id) - { - $clone = $this->duplicateSet($container_obj_id); - $question_ids = $this->duplicateQuestions($container_obj_id, $clone); - $this->duplicatePaths($clone, $question_ids); - - return $clone; - } - - public function synchronize($container_obj_id, $old_questions) - { - $clone = $this->duplicateSet($container_obj_id); - - $question_ids = $this->synchronizeQuestions($container_obj_id, $clone, $old_questions); - $this->duplicatePaths($clone, $question_ids); - - return $clone; - } - - /** - * @param ilPropertyFormGUI $form - */ - public function bindForm(ilPropertyFormGUI $form) - { - $this->setTitle($form->getInput('title')); - $this->setDescription($form->getInput('description')); - } - - /** - * @param int $old_id - * @param int $new_id - */ - public static function updateOriginalId($old_id, $new_id) - { - global $DIC; - $ilDB = $DIC->database(); - - $ilDB->update( - "rep_robj_xqsp_qs", - array("original_id" => array("integer", $new_id)), - array("original_id" => array("integer", $old_id)) - ); - } - - /** - * @return array - */ - private function removeQuestions() - { - $data = $this->getQuestionList()->getData(); - $question_ids = array(); - foreach ($data as $element) - { - $question_ids[] = $element["question_id"]; - } - return $this->getQuestionList()->remove($question_ids); - } - - private function removePaths() - { - require_once "class.ilQuestionSetPoolPath.php"; - - $data = $this->getPathList()->getData(); - foreach ($data as $element) - { - $path = new ilQuestionSetPoolPath($element["id"]); - $path->read(); - $path->remove(); - } - } - - /** - * @param $container_obj_id - * - * @return ilQuestionSetPoolSet - */ - private function duplicateSet($container_obj_id) - { - $clone = new ilQuestionSetPoolSet(); - $clone->setTitle($this->getUniqueTitleForContainer($this->getTitle(), $container_obj_id)); - $clone->setDescription($this->getDescription()); - //$clone->setOriginalId($this->getOriginalId()); - $clone->setOriginalId($this->getId()); - $clone->setContainerObjId($container_obj_id); - $clone->update(); - - return $clone; -} - - /** - * @param $clone - * @param $question_ids - */ - private function duplicatePaths($clone, $question_ids) - { - require_once "class.ilQuestionSetPoolPath.php"; - - $data = $this->getPathList()->getData(); - foreach($data as $element) - { - $path = new ilQuestionSetPoolPath($element["id"]); - $path->read(); - $path->setSet($clone); - $path->duplicate($question_ids); - } - } - - /** - * @param int $container_obj_id - * @param ilQuestionSetPoolSet $clone - * - * @return array - */ - private function duplicateQuestions($container_obj_id, $clone) - { - $data = $this->getQuestionList()->getData(); - $question_ids = array(); - foreach($data as $element) - { - $question_ids[] = $element["question_id"]; - } - $question_ids = $clone->getQuestionList()->duplicate($question_ids, $this, $container_obj_id); - - $this->xqsp_qst_mapping = $question_ids; - return $question_ids; - } - - public function getQuestionMapping() - { - return $this->xqsp_qst_mapping; - } - - /** - * @param int $container_obj_id - * @param ilQuestionSetPoolSet $clone - * @param array $old_questions - * - * @return array - */ - private function synchronizeQuestions($container_obj_id, $clone, $old_questions) - { - $data = $this->getQuestionList()->getData(); - $question_ids = array(); - foreach($data as $element) - { - $question_ids[] = $element["question_id"]; - } - $question_ids = $clone->getQuestionList()->synchronize($question_ids, $this, $container_obj_id, $old_questions); - - return $question_ids; - } + */ +class ilQuestionSetPoolSet extends ilPluginModel +{ + + /** + * @var integer + */ + protected $id; + + /** + * @var string + */ + protected $title; + + /** + * @var string + */ + protected $description; + + /** + * @var ilQuestionSetPoolSetQuestionList + */ + protected $question_list; + + /** + * @var ilQuestionSetPoolPathList + */ + protected $path_list; + + /** + * @var int|null + */ + protected $original_id; + + /** + * @var int + */ + protected $container_obj_id; + /** + * needed for formatest-importer + * @var array + */ + public $xqsp_qst_mapping = array(); + + + /** + * ilQuestionSetPoolSet constructor. + * @param int $id question_set_id + */ + public function __construct($id = 0) + { + require_once 'class.ilQuestionSetPoolSetQuestionList.php'; + require_once 'class.ilQuestionSetPoolPathList.php'; + $this->question_list = new ilQuestionSetPoolSetQuestionList($this); + $this->path_list = new ilQuestionSetPoolPathList($this); + + parent::__construct($id); + } + + /** + * @param integer $id + * @return bool + */ + public static function exists($id) + { + global $DIC; + $ilDB = $DIC->database(); + + $result = $ilDB->queryF( + "SELECT COUNT(*) cnt FROM rep_robj_xqsp_qs WHERE id = %s", + array("integer"), + array($id) + ); + $data = $ilDB->fetchAssoc($result); + + return (int) $data['cnt'] == 1 ? true : false; + } + + /** + * @param string $description + */ + public function setDescription($description) + { + $this->description = $description; + } + + /** + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * @param int $id + */ + public function setId($id) + { + $this->id = $id; + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param string $title + */ + public function setTitle($title) + { + $this->title = $title; + } + + /** + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * @return ilQuestionSetPoolSetQuestionList + */ + public function getQuestionList() + { + return $this->question_list; + } + + /** + * @return ilQuestionSetPoolPathList + */ + public function getPathList() + { + return $this->path_list; + } + + /** + * @param int|null $original_id + */ + public function setOriginalId($original_id) + { + $this->original_id = $original_id; + } + + /** + * @return int|null + */ + public function getOriginalId() + { + return $this->original_id; + } + + /** + * @param int $container_obj_id + */ + public function setContainerObjId($container_obj_id) + { + $this->container_obj_id = $container_obj_id; + } + + /** + * @return int + */ + public function getContainerObjId() + { + return $this->container_obj_id; + } + + public function update() + { + global $DIC; + $ilDB = $DIC->database(); + + if ($this->id > 0) { + return (bool) $ilDB->update( + "rep_robj_xqsp_qs", + array( + "title" => array("text", $this->getTitle()), + "description" => array("text", $this->getDescription()), + "original_id" => array("integer", $this->getOriginalId()) + ), + array( + "id" => array("integer", $this->getId()) + ) + ); + } else { + $this->setId($ilDB->nextId("rep_robj_xqsp_qs")); + return $ilDB->insert( + "rep_robj_xqsp_qs", + array( + "id" => array("integer", $this->getId()), + "title" => array("text", $this->getTitle()), + "description" => array("text", $this->getDescription()), + "questionsetpool_fi" => array("integer", $this->getContainerObjId()), + "original_id" => array("integer", $this->getOriginalId()) + ) + ); + } + } + + public function read() + { + global $DIC; + $ilDB = $DIC->database(); + + $result = $ilDB->queryF( + "SELECT * FROM rep_robj_xqsp_qs WHERE id = %s", + array("integer"), + array($this->id) + ); + + $data = $ilDB->fetchAssoc($result); + + if ($data != null) { + $this->setContainerObjId($data["questionsetpool_fi"]); + $this->setDescription($data['description']); + $this->setTitle($data['title']); + $this->setOriginalId($data["original_id"]); + } + } + + /** + * @return bool + */ + public function remove() + { + global $DIC; + $ilDB = $DIC->database(); + + $this->removePaths(); + $this->removeQuestions(); + + return $ilDB->manipulateF( + "DELETE FROM rep_robj_xqsp_qs WHERE id = %s", + array("integer"), + array($this->getId()) + ); + } + + public function isTitleUnique() + { + global $DIC; + $ilDB = $DIC->database(); + + $result = $ilDB->queryF( + "SELECT COUNT(id) num FROM rep_robj_xqsp_qs WHERE title = %s AND id != %s AND questionsetpool_fi = %s", + array("text", "integer", "integer"), + array($this->getTitle(), $this->getId(), $this->getContainerObjId()) + ); + + $row = $ilDB->fetchAssoc($result); + + return $row["num"] == 0; + } + + /** + * @return array + */ + public function getPathTitles() + { + global $DIC; + $ilDB = $DIC->database(); + + $titles = array(); + $result = $ilDB->queryF( + "SELECT DISTINCT(title) FROM rep_robj_xqsp_path WHERE questionset_fi = %s", + array("integer"), + array($this->getId()) + ); + + while ($row = $ilDB->fetchAssoc($result)) { + $titles[] = $row['title']; + } + + return $titles; + } + + /** + * @param string$original_title + * @param integer $container_obj_id + */ + protected function getUniqueTitleForContainer($original_title, $container_obj_id) + { + global $DIC; + $ilDB = $DIC->database(); + + $title = $original_title; + $i = 1; + if ($this->getContainerObjId() == $container_obj_id) { + ++$i; + $title .= ' (' . $i . ')'; + } + + do { + $result = $ilDB->queryF( + "SELECT id FROM rep_robj_xqsp_qs WHERE title = %s AND questionsetpool_fi = %s", + array("text", "integer"), + array($title, $container_obj_id) + ); + if (!$ilDB->numRows($result)) { + return $title; + } + $title = $original_title . ' (' . ++$i . ')'; + } while (true); + } + + /** + * @param int $container_obj_id + * + * @return self + */ + public function duplicate($container_obj_id) + { + $clone = $this->duplicateSet($container_obj_id); + $question_ids = $this->duplicateQuestions($container_obj_id, $clone); + $this->duplicatePaths($clone, $question_ids); + + return $clone; + } + + public function synchronize($container_obj_id, $old_questions) + { + $clone = $this->duplicateSet($container_obj_id); + + $question_ids = $this->synchronizeQuestions($container_obj_id, $clone, $old_questions); + $this->duplicatePaths($clone, $question_ids); + + return $clone; + } + + /** + * @param ilPropertyFormGUI $form + */ + public function bindForm(ilPropertyFormGUI $form) + { + $this->setTitle($form->getInput('title')); + $this->setDescription($form->getInput('description')); + } + + /** + * @param int $old_id + * @param int $new_id + */ + public static function updateOriginalId($old_id, $new_id) + { + global $DIC; + $ilDB = $DIC->database(); + + $ilDB->update( + "rep_robj_xqsp_qs", + array("original_id" => array("integer", $new_id)), + array("original_id" => array("integer", $old_id)) + ); + } + + /** + * @return array + */ + private function removeQuestions() + { + $data = $this->getQuestionList()->getData(); + $question_ids = array(); + foreach ($data as $element) { + $question_ids[] = $element["question_id"]; + } + return $this->getQuestionList()->remove($question_ids); + } + + private function removePaths() + { + require_once "class.ilQuestionSetPoolPath.php"; + + $data = $this->getPathList()->getData(); + foreach ($data as $element) { + $path = new ilQuestionSetPoolPath($element["id"]); + $path->read(); + $path->remove(); + } + } + + /** + * @param $container_obj_id + * + * @return ilQuestionSetPoolSet + */ + private function duplicateSet($container_obj_id) + { + $clone = new ilQuestionSetPoolSet(); + $clone->setTitle($this->getUniqueTitleForContainer($this->getTitle(), $container_obj_id)); + $clone->setDescription($this->getDescription()); + //$clone->setOriginalId($this->getOriginalId()); + $clone->setOriginalId($this->getId()); + $clone->setContainerObjId($container_obj_id); + $clone->update(); + + return $clone; + } + + /** + * @param $clone + * @param $question_ids + */ + private function duplicatePaths($clone, $question_ids) + { + require_once "class.ilQuestionSetPoolPath.php"; + + $data = $this->getPathList()->getData(); + foreach ($data as $element) { + $path = new ilQuestionSetPoolPath($element["id"]); + $path->read(); + $path->setSet($clone); + $path->duplicate($question_ids); + } + } + + /** + * @param int $container_obj_id + * @param ilQuestionSetPoolSet $clone + * + * @return array + */ + private function duplicateQuestions($container_obj_id, $clone) + { + $data = $this->getQuestionList()->getData(); + $question_ids = array(); + foreach ($data as $element) { + $question_ids[] = $element["question_id"]; + } + $question_ids = $clone->getQuestionList()->duplicate($question_ids, $this, $container_obj_id); + + $this->xqsp_qst_mapping = $question_ids; + return $question_ids; + } + + public function getQuestionMapping() + { + return $this->xqsp_qst_mapping; + } + + /** + * @param int $container_obj_id + * @param ilQuestionSetPoolSet $clone + * @param array $old_questions + * + * @return array + */ + private function synchronizeQuestions($container_obj_id, $clone, $old_questions) + { + $data = $this->getQuestionList()->getData(); + $question_ids = array(); + foreach ($data as $element) { + $question_ids[] = $element["question_id"]; + } + $question_ids = $clone->getQuestionList()->synchronize($question_ids, $this, $container_obj_id, $old_questions); + + return $question_ids; + } } diff --git a/classes/models/class.ilQuestionSetPoolSetList.php b/classes/models/class.ilQuestionSetPoolSetList.php index 897cd39df1e33be70ab2729f3c266c9b5582ea87..021db3471410eb12982d2cb12f3efc84d33d7d5f 100644 --- a/classes/models/class.ilQuestionSetPoolSetList.php +++ b/classes/models/class.ilQuestionSetPoolSetList.php @@ -8,152 +8,143 @@ require_once "abstract.ilPluginModelList.php"; * Date: 10.10.13 * Time: 10:49 * @author Thomas Joußen - */ + */ class ilQuestionSetPoolSetList extends ilPluginModelList { - /** - * @var ilObjQuestionSetPool - */ - protected $question_set_pool; - - /** - * needed for formatest-importer - * @var array - */ - public $xqsp_qst_mapping = array(); - - /** - * needed for formatest-importer - * @var array - */ - public $set_mapping = array(); + /** + * @var ilObjQuestionSetPool + */ + protected $question_set_pool; + + /** + * needed for formatest-importer + * @var array + */ + public $xqsp_qst_mapping = array(); + + /** + * needed for formatest-importer + * @var array + */ + public $set_mapping = array(); - public function __construct($question_set_pool) - { - $this->question_set_pool = $question_set_pool; + public function __construct($question_set_pool) + { + $this->question_set_pool = $question_set_pool; - parent::__construct(); - } + parent::__construct(); + } - /** - * @param array $params - * @param array $filter - * - * @return array - */ - public function loadData($params = array(), $filter = array()) - { - require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/classes/providers/class.ilQuestionSetPoolSetsProvider.php"; + /** + * @param array $params + * @param array $filter + * + * @return array + */ + public function loadData($params = array(), $filter = array()) + { + require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/classes/providers/class.ilQuestionSetPoolSetsProvider.php"; - $provider = new ilQuestionSetPoolSetsProvider(); - $filter["questionsetpool_fi"] = $this->question_set_pool->getId(); - return $provider->loadData($filter, $params); - } + $provider = new ilQuestionSetPoolSetsProvider(); + $filter["questionsetpool_fi"] = $this->question_set_pool->getId(); + return $provider->loadData($filter, $params); + } - public function getSet($id) - { - $data = $this->getData(); + public function getSet($id) + { + $data = $this->getData(); - foreach($data as $item) - { - if($item->getId() == $id) - { - return $item; - } - } + foreach ($data as $item) { + if ($item->getId() == $id) { + return $item; + } + } - return null; - } - - /** - * @param $set_ids - * @param bool $do_clone - * @return bool - */ - public function insert($set_ids, $do_clone = true) - { - require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/classes/class.ilObjQuestionSetPool.php"; - - foreach($set_ids as $set_id) - { - $set = new ilQuestionSetPoolSet($set_id); - $set->read(); - - if($set != null ) - { - if($do_clone) - { - $clone = $set->duplicate($this->question_set_pool->getId()); - $container_id = $clone->getId(); - $this->set_mapping[$set_id] = $clone->getId(); - $this->xqsp_qst_mapping = $set->getQuestionMapping(); - } - else - { - $container_id = $set->getId(); - $this->xqsp_qst_mapping = $set->getQuestionMapping(); - } - $success = $this->db->queryF( - "INSERT INTO rep_robj_xtsf_qs (obj_fi, questionset_fi, sorting) + return null; + } + + /** + * @param $set_ids + * @param bool $do_clone + * @return bool + */ + public function insert($set_ids, $do_clone = true) + { + require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/classes/class.ilObjQuestionSetPool.php"; + + foreach ($set_ids as $set_id) { + $set = new ilQuestionSetPoolSet($set_id); + $set->read(); + + if ($set != null) { + if ($do_clone) { + $clone = $set->duplicate($this->question_set_pool->getId()); + $container_id = $clone->getId(); + $this->set_mapping[$set_id] = $clone->getId(); + $this->xqsp_qst_mapping = $set->getQuestionMapping(); + } else { + $container_id = $set->getId(); + $this->xqsp_qst_mapping = $set->getQuestionMapping(); + } + $success = $this->db->queryF( + "INSERT INTO rep_robj_xtsf_qs (obj_fi, questionset_fi, sorting) (SELECT %s,%s, CASE WHEN MAX(sorting) IS NULL THEN 10 ELSE MAX(sorting) + 10 END FROM rep_robj_xtsf_qs WHERE obj_fi = %s)", - array("integer", "integer", "integer"), - array($this->question_set_pool->getId(), $container_id, $this->question_set_pool->getId()) - ); - - if(!$success) - { - return false; - } - } - } - return true; - } + array("integer", "integer", "integer"), + array($this->question_set_pool->getId(), $container_id, $this->question_set_pool->getId()) + ); + + if (!$success) { + return false; + } + } + } + return true; + } - public function remove($question_ids) - { - return true; - } + public function remove($question_ids) + { + return true; + } - /** - * @param array $data - * - * @return array - */ - public function createObjectsFromData($data) - { - $objects = array(); - foreach($data as $item) - { - require_once 'class.ilQuestionSetPoolSet.php'; - $set = new ilQuestionSetPoolSet($this->question_set_pool); - $set->setId($item['id']); - $set->setTitle($item['title']); - $set->setDescription($item['description']); + /** + * @param array $data + * + * @return array + */ + public function createObjectsFromData($data) + { + $objects = array(); + foreach ($data as $item) { + require_once 'class.ilQuestionSetPoolSet.php'; + $set = new ilQuestionSetPoolSet($this->question_set_pool); + $set->setId($item['id']); + $set->setTitle($item['title']); + $set->setDescription($item['description']); - $objects[] = $set; - } + $objects[] = $set; + } - return $objects; - } - - /** - * @return array - */ - public function getQuestionMapping() - { - return $this->xqsp_qst_mapping; - } - - /** - * @return array - */ - public function getSetMapping() - { - return $this->set_mapping; - } + return $objects; + } + + /** + * @return array + */ + public function getQuestionMapping() + { + return $this->xqsp_qst_mapping; + } + + /** + * @return array + */ + public function getSetMapping() + { + return $this->set_mapping; + } } diff --git a/classes/models/class.ilQuestionSetPoolSetQuestionList.php b/classes/models/class.ilQuestionSetPoolSetQuestionList.php index 3d415e1304637d263b1231fbab19093f276ef267..434fe118999cd8e826096eb85d23aa340f3ea381 100644 --- a/classes/models/class.ilQuestionSetPoolSetQuestionList.php +++ b/classes/models/class.ilQuestionSetPoolSetQuestionList.php @@ -8,376 +8,344 @@ require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/ * Date: 26.09.13 * Time: 12:21 * @author Thomas Joußen - */ + */ class ilQuestionSetPoolSetQuestionList extends ilPluginModelList { - /** - * @var ilQuestionSetPoolSet - */ - protected $set; - - public function __construct($set) - { - $this->set = $set; - - parent::__construct(); - } - - /** - * @param array $params - * @param array $filter - * - * @return array - */ - public function loadData($params = array(), $filter = array()) - { - require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/classes/providers/class.ilQuestionSetPoolSetQuestionsProvider.php"; - - $provider = new ilQuestionSetPoolSetQuestionsProvider(); - $filter["questionset_fi"] = $this->set->getId(); - return $provider->loadData($filter, $params); - } - - /** - * @param array $question_ids - * @param ilObjQuestionSetPool $question_set_pool - * - * @return bool - */ - public function insert($question_ids, $question_set_pool) - { - - require_once "./Modules/TestQuestionPool/classes/class.assQuestion.php"; - - $question_titles = $this->getQuestionTitles(); - - foreach($question_ids as $question_id) - { - $question = assQuestion::_instantiateQuestion($question_id); - $obj_id = $question->getObjId(); - - $title = $question->getTitle(); - if(in_array($title, $question_titles)) - { - $i = 2; - while(in_array($title . ' (' . $i . ')', $question_titles)) - { - $i++; - } - $title .= ' (' . $i . ')'; - } - $question_titles[] = $title; - - //$copy_id = $question->copyObject($this->question_set_pool->getId()); - $copy_id = $question->duplicate(true, $title,"","",$question_set_pool->getId()); - - if($question->getObjId() == $obj_id) - { - $this->db->update( - "qpl_questions", - array( - "original_id" => array("integer", null) - ), - array( - "question_id" => array("integer", $copy_id) - ) - ); - } - - - $success = $this->db->queryF( - "INSERT INTO rep_robj_xqsp_qs_qst (questionset_fi, question_fi, question_index) + /** + * @var ilQuestionSetPoolSet + */ + protected $set; + + public function __construct($set) + { + $this->set = $set; + + parent::__construct(); + } + + /** + * @param array $params + * @param array $filter + * + * @return array + */ + public function loadData($params = array(), $filter = array()) + { + require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/classes/providers/class.ilQuestionSetPoolSetQuestionsProvider.php"; + + $provider = new ilQuestionSetPoolSetQuestionsProvider(); + $filter["questionset_fi"] = $this->set->getId(); + return $provider->loadData($filter, $params); + } + + /** + * @param array $question_ids + * @param ilObjQuestionSetPool $question_set_pool + * + * @return bool + */ + public function insert($question_ids, $question_set_pool) + { + $question_titles = $this->getQuestionTitles(); + + foreach ($question_ids as $question_id) { + $question = assQuestion::_instantiateQuestion($question_id); + $obj_id = $question->getObjId(); + + $title = $question->getTitle(); + if (in_array($title, $question_titles)) { + $i = 2; + while (in_array($title . ' (' . $i . ')', $question_titles)) { + $i++; + } + $title .= ' (' . $i . ')'; + } + $question_titles[] = $title; + + //$copy_id = $question->copyObject($this->question_set_pool->getId()); + $copy_id = $question->duplicate(true, $title, "", "", $question_set_pool->getId()); + + if ($question->getObjId() == $obj_id) { + $this->db->update( + "qpl_questions", + array( + "original_id" => array("integer", null) + ), + array( + "question_id" => array("integer", $copy_id) + ) + ); + } + + + $success = $this->db->queryF( + "INSERT INTO rep_robj_xqsp_qs_qst (questionset_fi, question_fi, question_index) (SELECT %s,%s, CASE WHEN MAX(question_index) IS NULL THEN 1 ELSE MAX(question_index) + 1 END FROM rep_robj_xqsp_qs_qst WHERE questionset_fi = %s)", - array("integer", "integer", "integer"), - array($this->set->getId(), $copy_id, $this->set->getId()) - ); - - if(!$success) - { - return false; - } - } - - return true; - } - - /** - * @return array - */ - public function getQuestionTitles() - { - global $DIC; - $ilDB = $DIC->database(); - - $titles = array(); - $result = $ilDB->queryF("SELECT DISTINCT(qpl_questions.title) FROM rep_robj_xqsp_qs_qst, qpl_questions WHERE rep_robj_xqsp_qs_qst.questionset_fi = %s AND rep_robj_xqsp_qs_qst.question_fi = qpl_questions.question_id ORDER BY rep_robj_xqsp_qs_qst.question_index", - array('integer'), - array($this->set->getId()) - ); - - while ($row = $ilDB->fetchAssoc($result)) - { - $titles[] = $row['title']; - } - - return $titles; - } - - /** - * @param array $question_ids - * @param ilQuestionSetPoolSet $old_set - * @param integer $container_obj_id Container id (e.g. question set pool obj_id or forma test obj_id) - * - * @return array - */ - public function duplicate($question_ids, $old_set, $container_obj_id) - { - require_once "./Modules/TestQuestionPool/classes/class.assQuestion.php"; - $new_question_ids = array(); - foreach($question_ids as $question_id) - { - $question = assQuestion::_instantiateQuestion($question_id); - $original_obj_fi = $question->getObjId(); - $copy_id = $question->duplicate(true, "","","", $container_obj_id); - - $new_question_ids[$question_id] = $copy_id; - - if($original_obj_fi != $container_obj_id) - { - $this->db->manipulateF( - 'UPDATE qpl_questions SET original_id = %s WHERE question_id = %s', - array('integer', 'integer'), - array($question_id, $copy_id) - ); - } - - $success = $this->db->queryF( - "INSERT INTO rep_robj_xqsp_qs_qst (questionset_fi, question_fi, question_index) + array("integer", "integer", "integer"), + array($this->set->getId(), $copy_id, $this->set->getId()) + ); + + if (!$success) { + return false; + } + } + + return true; + } + + /** + * @return array + */ + public function getQuestionTitles() + { + global $DIC; + $ilDB = $DIC->database(); + + $titles = array(); + $result = $ilDB->queryF( + "SELECT DISTINCT(qpl_questions.title) FROM rep_robj_xqsp_qs_qst, qpl_questions WHERE rep_robj_xqsp_qs_qst.questionset_fi = %s AND rep_robj_xqsp_qs_qst.question_fi = qpl_questions.question_id ORDER BY rep_robj_xqsp_qs_qst.question_index", + array('integer'), + array($this->set->getId()) + ); + + while ($row = $ilDB->fetchAssoc($result)) { + $titles[] = $row['title']; + } + + return $titles; + } + + /** + * @param array $question_ids + * @param ilQuestionSetPoolSet $old_set + * @param integer $container_obj_id Container id (e.g. question set pool obj_id or forma test obj_id) + * + * @return array + */ + public function duplicate($question_ids, $old_set, $container_obj_id) + { + $new_question_ids = array(); + foreach ($question_ids as $question_id) { + $question = assQuestion::_instantiateQuestion($question_id); + $original_obj_fi = $question->getObjId(); + $copy_id = $question->duplicate(true, "", "", "", $container_obj_id); + + $new_question_ids[$question_id] = $copy_id; + + if ($original_obj_fi != $container_obj_id) { + $this->db->manipulateF( + 'UPDATE qpl_questions SET original_id = %s WHERE question_id = %s', + array('integer', 'integer'), + array($question_id, $copy_id) + ); + } + + $success = $this->db->queryF( + "INSERT INTO rep_robj_xqsp_qs_qst (questionset_fi, question_fi, question_index) (SELECT %s, %s, question_index FROM rep_robj_xqsp_qs_qst WHERE questionset_fi = %s AND question_fi = %s )", - array("integer", "integer", "integer", "integer"), - array($this->set->getId(), $copy_id, $old_set->getId(), $question_id) - ); - if(!$success) - { - return array(); - } - } - return $new_question_ids; - } - - /** - * @param array $question_ids - * @param ilQuestionSetPoolSet $old_set - * @param int $container_obj_id - * @param array $old_questions - */ - public function synchronize($question_ids, $old_set, $container_obj_id, $old_questions) - { - require_once "./Modules/TestQuestionPool/classes/class.assQuestion.php"; - $new_question_ids = array(); - foreach($question_ids as $question_id) - { - $question = assQuestion::_instantiateQuestion($question_id); - $old_original_id = $question->getOriginalId(); - $copy_id = $question->duplicate(true, "","","", $container_obj_id); - - $new_question_ids[$question_id] = $copy_id; - - // Change original id of base question (Testquestion) - $this->db->manipulateF( - "UPDATE qpl_questions SET original_id = %s WHERE original_id = %s", - array("integer", "integer"), - array($copy_id, $old_original_id) - ); - - foreach($old_questions as $old_question) - { - if($old_question["question_id"] == $old_original_id) - { - $old_original_id = $old_question["original_id"]; - } - } - - $this->db->manipulateF( - "UPDATE qpl_questions SET original_id = %s WHERE question_id = %s", - array("integer", "integer"), - array($old_original_id, $copy_id) - ); - - $success = $this->db->queryF( - "INSERT INTO rep_robj_xqsp_qs_qst (questionset_fi, question_fi, question_index) + array("integer", "integer", "integer", "integer"), + array($this->set->getId(), $copy_id, $old_set->getId(), $question_id) + ); + if (!$success) { + return array(); + } + } + return $new_question_ids; + } + + /** + * @param array $question_ids + * @param ilQuestionSetPoolSet $old_set + * @param int $container_obj_id + * @param array $old_questions + */ + public function synchronize($question_ids, $old_set, $container_obj_id, $old_questions) + { + $new_question_ids = array(); + foreach ($question_ids as $question_id) { + $question = assQuestion::_instantiateQuestion($question_id); + $old_original_id = $question->getOriginalId(); + $copy_id = $question->duplicate(true, "", "", "", $container_obj_id); + + $new_question_ids[$question_id] = $copy_id; + + // Change original id of base question (Testquestion) + $this->db->manipulateF( + "UPDATE qpl_questions SET original_id = %s WHERE original_id = %s", + array("integer", "integer"), + array($copy_id, $old_original_id) + ); + + foreach ($old_questions as $old_question) { + if ($old_question["question_id"] == $old_original_id) { + $old_original_id = $old_question["original_id"]; + } + } + + $this->db->manipulateF( + "UPDATE qpl_questions SET original_id = %s WHERE question_id = %s", + array("integer", "integer"), + array($old_original_id, $copy_id) + ); + + $success = $this->db->queryF( + "INSERT INTO rep_robj_xqsp_qs_qst (questionset_fi, question_fi, question_index) (SELECT %s, %s, question_index FROM rep_robj_xqsp_qs_qst WHERE questionset_fi = %s AND question_fi = %s )", - array("integer", "integer", "integer", "integer"), - array($this->set->getId(), $copy_id, $old_set->getId(), $question_id) - ); - if(!$success) - { - return array(); - } - } - - return $new_question_ids; - } - - /** - * @param array $question_ids - * - * @return bool - */ - public function remove($question_ids) - { - foreach($question_ids as $question_id) - { - $success = $this->db->manipulateF( - "DELETE FROM rep_robj_xqsp_qs_qst WHERE question_fi = %s", - array("integer"), - array($question_id) - ); - - require_once 'Modules/TestQuestionPool/classes/class.assQuestion.php'; - /** - * @var $gui assQuestionGUI - */ - $question = assQuestion::_instantiateQuestion($question_id); - if($question instanceof assQuestion) - { - /** - * @var $object assQuestion - */ - $question->delete($question_id); - //@todo überprüfen ob Löschen von Verzeichnissen bei Fragen mit Dateiupload (zB: Imagemap + vertikale Anordnungsfrage) funktioniert - - } - - if(!$success) - { - return false; - } - } - - return true; - } - - /** - * @param array $data - * - * @return array - */ - public function createObjectsFromData($data) - { - return $data; - } - - /** - * @param nt $question_id - * @param null $original_question_id - * @return bool||int $copy_id - */ - public function import($question_id, $original_question_id = NULL) - { - require_once "./Modules/TestQuestionPool/classes/class.assQuestion.php"; - - $question_titles = $this->getQuestionTitles(); - - $question = assQuestion::_instantiateQuestion($question_id); - $obj_id = $question->getObjId(); - - $title = $question->getTitle(); - if(in_array($title, $question_titles)) - { - $i = 2; - while(in_array($title . ' (' . $i . ')', $question_titles)) - { - $i++; - } - $title .= ' (' . $i . ')'; - } - $question_titles[] = $title; - - if($question->getObjId() == $obj_id) - { - if($original_question_id == 0) - { - $original_question_id = NULL; - } - - $this->db->update( - "qpl_questions", - array( - "original_id" => array("integer", $original_question_id) - ), - array( - "question_id" => array("integer", $question_id) - ) - ); - } - - $success = $this->db->queryF( - "INSERT INTO rep_robj_xqsp_qs_qst (questionset_fi, question_fi, question_index) + array("integer", "integer", "integer", "integer"), + array($this->set->getId(), $copy_id, $old_set->getId(), $question_id) + ); + if (!$success) { + return array(); + } + } + + return $new_question_ids; + } + + /** + * @param array $question_ids + * + * @return bool + */ + public function remove($question_ids) + { + foreach ($question_ids as $question_id) { + $success = $this->db->manipulateF( + "DELETE FROM rep_robj_xqsp_qs_qst WHERE question_fi = %s", + array("integer"), + array($question_id) + ); + + /** + * @var $gui assQuestionGUI + */ + $question = assQuestion::_instantiateQuestion($question_id); + if ($question instanceof assQuestion) { + /** + * @var $object assQuestion + */ + $question->delete($question_id); + //@todo überprüfen ob Löschen von Verzeichnissen bei Fragen mit Dateiupload (zB: Imagemap + vertikale Anordnungsfrage) funktioniert + } + + if (!$success) { + return false; + } + } + + return true; + } + + /** + * @param array $data + * + * @return array + */ + public function createObjectsFromData($data) + { + return $data; + } + + /** + * @param nt $question_id + * @param null $original_question_id + * @return bool||int $copy_id + */ + public function import($question_id, $original_question_id = null) + { + $question_titles = $this->getQuestionTitles(); + + $question = assQuestion::_instantiateQuestion($question_id); + $obj_id = $question->getObjId(); + + $title = $question->getTitle(); + if (in_array($title, $question_titles)) { + $i = 2; + while (in_array($title . ' (' . $i . ')', $question_titles)) { + $i++; + } + $title .= ' (' . $i . ')'; + } + $question_titles[] = $title; + + if ($question->getObjId() == $obj_id) { + if ($original_question_id == 0) { + $original_question_id = null; + } + + $this->db->update( + "qpl_questions", + array( + "original_id" => array("integer", $original_question_id) + ), + array( + "question_id" => array("integer", $question_id) + ) + ); + } + + $success = $this->db->queryF( + "INSERT INTO rep_robj_xqsp_qs_qst (questionset_fi, question_fi, question_index) (SELECT %s,%s, CASE WHEN MAX(question_index) IS NULL THEN 1 ELSE MAX(question_index) + 1 END FROM rep_robj_xqsp_qs_qst WHERE questionset_fi = %s)", - array("integer", "integer", "integer"), - array($this->set->getId(), $question_id, $this->set->getId()) - ); - - if(!$success) - { - return false; - } - return $question_id; - } - - /** - * @param array $question_ids - * @param ilQuestionSetPoolSet $source_set - * @param ilQuestionSetPoolSet $target_set - * @return array - */ - public function cloneQuestionList($question_ids, ilQuestionSetPoolSet $source_set, ilQuestionSetPoolSet $target_set) - { - require_once "./Modules/TestQuestionPool/classes/class.assQuestion.php"; - $new_question_ids = array(); - foreach($question_ids as $question_id) - { - $question = assQuestion::_instantiateQuestion($question_id); - $copy_id = $question->duplicate(true, "","","", $target_set->getContainerObjId()); - - $original_obj_fi = $question->getObjId(); - - $new_question_ids[$question_id] = $copy_id; - - if($original_obj_fi != $target_set->getContainerObjId()) - { - $this->db->manipulateF( - 'UPDATE qpl_questions SET original_id = %s WHERE question_id = %s', - array('integer', 'integer'), - array($question_id, $copy_id) - ); - } - - $this->db->queryF( - "INSERT INTO rep_robj_xqsp_qs_qst (questionset_fi, question_fi, question_index) + array("integer", "integer", "integer"), + array($this->set->getId(), $question_id, $this->set->getId()) + ); + + if (!$success) { + return false; + } + return $question_id; + } + + /** + * @param array $question_ids + * @param ilQuestionSetPoolSet $source_set + * @param ilQuestionSetPoolSet $target_set + * @return array + */ + public function cloneQuestionList($question_ids, ilQuestionSetPoolSet $source_set, ilQuestionSetPoolSet $target_set) + { + $new_question_ids = array(); + foreach ($question_ids as $question_id) { + $question = assQuestion::_instantiateQuestion($question_id); + $copy_id = $question->duplicate(true, "", "", "", $target_set->getContainerObjId()); + + $original_obj_fi = $question->getObjId(); + + $new_question_ids[$question_id] = $copy_id; + + if ($original_obj_fi != $target_set->getContainerObjId()) { + $this->db->manipulateF( + 'UPDATE qpl_questions SET original_id = %s WHERE question_id = %s', + array('integer', 'integer'), + array($question_id, $copy_id) + ); + } + + $this->db->queryF( + "INSERT INTO rep_robj_xqsp_qs_qst (questionset_fi, question_fi, question_index) (SELECT %s, %s, question_index FROM rep_robj_xqsp_qs_qst WHERE questionset_fi = %s AND question_fi = %s )", - array("integer", "integer", "integer", "integer"), - array($target_set->getId(), $copy_id, $source_set->getId(), $question_id) - ); - } - return $new_question_ids; - } + array("integer", "integer", "integer", "integer"), + array($target_set->getId(), $copy_id, $source_set->getId(), $question_id) + ); + } + return $new_question_ids; + } } diff --git a/classes/models/interface.ilPluginModelInterface.php b/classes/models/interface.ilPluginModelInterface.php index e84e05343e838bc0acc0dc2a493072480d7ae409..4ae5b3222644c0b705af7faaf222c4830d98145e 100644 --- a/classes/models/interface.ilPluginModelInterface.php +++ b/classes/models/interface.ilPluginModelInterface.php @@ -7,19 +7,19 @@ * @author Thomas Joußen */ -interface ilPluginModelInterface { +interface ilPluginModelInterface +{ + public function update(); - public function update(); + public function read(); - public function read(); + /** + * @return array + */ + public function toArray(); - /** - * @return array - */ - public function toArray(); - - /** - * @param ilPropertyFormGUI $form - */ - public function bindForm(ilPropertyFormGUI $form); -} \ No newline at end of file + /** + * @param ilPropertyFormGUI $form + */ + public function bindForm(ilPropertyFormGUI $form); +} diff --git a/classes/providers/abstract.ilPluginTableDatabaseDataProvider.php b/classes/providers/abstract.ilPluginTableDatabaseDataProvider.php index b7f3aaa3d1e1d7be6a74b15bb2d08d7428af5d4d..792242eb696c1cb8ee55d0d671de901eb25f8544 100644 --- a/classes/providers/abstract.ilPluginTableDatabaseDataProvider.php +++ b/classes/providers/abstract.ilPluginTableDatabaseDataProvider.php @@ -8,186 +8,181 @@ require_once "interface.ilPluginTableDataProvider.php"; * Date: 24.09.13 * Time: 09:00 * @author Thomas Joußen - */ -abstract class ilPluginTableDatabaseDataProvider implements ilPluginTableDataProvider{ - - /** - * @var ilDB - */ - protected $db; - - /** - * @var int - */ - protected $limit = 0; - - /** - * @var int - */ - protected $offset = 0; - - /** - * @var string - */ - protected $query = ""; - - /** - * - */ - public function __construct() - { - global $DIC; - $this->db = $DIC->database(); - } - - /** - * @param $limit - * - * @throws InvalidArgumentException - */ - public function setLimit($limit) - { - if (!is_numeric($limit)) - { - throw new InvalidArgumentException('Please provide a valid numerical limit.'); - } - $this->limit = $limit; - } - - /** - * @return int - */ - public function getLimit() - { - return $this->limit; - } - - - /** - * @param $offset - * - * @throws InvalidArgumentException - */ - public function setOffset($offset) - { - if (!is_numeric($offset)) - { - throw new InvalidArgumentException('Please provide a valid numerical offset.'); - } - - $this->offset = $offset; - } - - /** - * @return int - */ - public function getOffset() - { - return $this->offset; - } - - /** - * @param array $filter - * @param array $orderBy - * - * @return array - */ - public function loadData(array $filter, array $orderBy = array()) - { - $data = array(); - -// $this->db->setLimit($this->limit, $this->offset); - $this->buildQuery($filter, $orderBy); - - $res = $this->db->query($this->query); - - while ($row = $this->db->fetchAssoc($res)) - { - $data[] = $row; - } - - return $data; - } - - /** - * @param array $filter - * @param array $orderBy - * - * @return string - */ - protected function buildQuery(array $filter, array $orderBy) - { - $select = $this->getSelectPart(); - $where = $this->getWherePart($filter); - $from = $this->getFromPart(); - $join = $this->getJoinPart(); - $order = $this->getOrderByPart($orderBy); - $group = $this->getGroupByPart(); - $having = $this->getHavingPart($filter); - - $where = strlen($where)? 'WHERE ' . $where : ''; - $query = "SELECT {$select} FROM {$from} {$join} {$where}"; - - if (strlen($group)) - { - $query .= " GROUP BY {$group}"; - } - - if (strlen($having)) - { - $query .= " HAVING {$having}"; - } - - if (strlen($order)) - { - $query .= " ORDER BY {$order}"; - } - - $this->query = $query; - } - - /** - * @return string - * @abstract - */ - abstract protected function getSelectPart(); - - /** - * @return string - * @abstract - */ - abstract protected function getFromPart(); - - /** - * @return string - * @abstract - */ - abstract protected function getJoinPart(); - - /** - * @param array $filter - * @return string - * @abstract - */ - abstract protected function getWherePart(array $filter); - - /** - * @return string - * @abstract - */ - abstract protected function getGroupByPart(); - - /** - * @param array $filter - * @return string - * @abstract - */ - abstract protected function getHavingPart(array $filter); - - /** - * @param array $params - * @return string - * @abstract - */ - abstract protected function getOrderByPart(array $params); + */ +abstract class ilPluginTableDatabaseDataProvider implements ilPluginTableDataProvider +{ + + /** + * @var ilDB + */ + protected $db; + + /** + * @var int + */ + protected $limit = 0; + + /** + * @var int + */ + protected $offset = 0; + + /** + * @var string + */ + protected $query = ""; + + /** + * + */ + public function __construct() + { + global $DIC; + $this->db = $DIC->database(); + } + + /** + * @param $limit + * + * @throws InvalidArgumentException + */ + public function setLimit($limit) + { + if (!is_numeric($limit)) { + throw new InvalidArgumentException('Please provide a valid numerical limit.'); + } + $this->limit = $limit; + } + + /** + * @return int + */ + public function getLimit() + { + return $this->limit; + } + + + /** + * @param $offset + * + * @throws InvalidArgumentException + */ + public function setOffset($offset) + { + if (!is_numeric($offset)) { + throw new InvalidArgumentException('Please provide a valid numerical offset.'); + } + + $this->offset = $offset; + } + + /** + * @return int + */ + public function getOffset() + { + return $this->offset; + } + + /** + * @param array $filter + * @param array $orderBy + * + * @return array + */ + public function loadData(array $filter, array $orderBy = array()) + { + $data = array(); + + // $this->db->setLimit($this->limit, $this->offset); + $this->buildQuery($filter, $orderBy); + + $res = $this->db->query($this->query); + + while ($row = $this->db->fetchAssoc($res)) { + $data[] = $row; + } + + return $data; + } + + /** + * @param array $filter + * @param array $orderBy + * + * @return string + */ + protected function buildQuery(array $filter, array $orderBy) + { + $select = $this->getSelectPart(); + $where = $this->getWherePart($filter); + $from = $this->getFromPart(); + $join = $this->getJoinPart(); + $order = $this->getOrderByPart($orderBy); + $group = $this->getGroupByPart(); + $having = $this->getHavingPart($filter); + + $where = strlen($where)? 'WHERE ' . $where : ''; + $query = "SELECT {$select} FROM {$from} {$join} {$where}"; + + if (strlen($group)) { + $query .= " GROUP BY {$group}"; + } + + if (strlen($having)) { + $query .= " HAVING {$having}"; + } + + if (strlen($order)) { + $query .= " ORDER BY {$order}"; + } + + $this->query = $query; + } + + /** + * @return string + * @abstract + */ + abstract protected function getSelectPart(); + + /** + * @return string + * @abstract + */ + abstract protected function getFromPart(); + + /** + * @return string + * @abstract + */ + abstract protected function getJoinPart(); + + /** + * @param array $filter + * @return string + * @abstract + */ + abstract protected function getWherePart(array $filter); + + /** + * @return string + * @abstract + */ + abstract protected function getGroupByPart(); + + /** + * @param array $filter + * @return string + * @abstract + */ + abstract protected function getHavingPart(array $filter); + + /** + * @param array $params + * @return string + * @abstract + */ + abstract protected function getOrderByPart(array $params); } diff --git a/classes/providers/class.ilParserQuestionProvider.php b/classes/providers/class.ilParserQuestionProvider.php index 7f31a1fc7a778d970802b5e648014d048735e694..4533c915e1a9731b4ad6c4c570ac989c989eb84f 100644 --- a/classes/providers/class.ilParserQuestionProvider.php +++ b/classes/providers/class.ilParserQuestionProvider.php @@ -8,37 +8,34 @@ * @author Thomas Joußen * * @todo MAYBE CHANGE THE LOCATION OF THIS CLASS - */ -class ilParserQuestionProvider { - - protected $set_id; - - public function __construct($set_id) - { - $this->set_id = $set_id; - } - - /** - * @param int $index - * - * @return iQuestionCondition - */ - public function getQuestion($index) - { - global $DIC; - $ilDB = $DIC->database(); - - $result = $ilDB->queryF( - "SELECT question_fi FROM rep_robj_xqsp_qs_qst WHERE question_index = %s AND questionset_fi = %s", - array("integer", "integer"), - array($index, $this->set_id) - ); - - $data = $ilDB->fetchAssoc($result); - - require_once "./Modules/TestQuestionPool/classes/class.assQuestion.php"; - - return assQuestion::_instanciateQuestion($data['question_fi']); - } + */ +class ilParserQuestionProvider +{ + protected $set_id; + + public function __construct($set_id) + { + $this->set_id = $set_id; + } + + /** + * @param int $index + * + * @return iQuestionCondition + */ + public function getQuestion($index) + { + global $DIC; + $ilDB = $DIC->database(); + + $result = $ilDB->queryF( + "SELECT question_fi FROM rep_robj_xqsp_qs_qst WHERE question_index = %s AND questionset_fi = %s", + array("integer", "integer"), + array($index, $this->set_id) + ); + + $data = $ilDB->fetchAssoc($result); + + return assQuestion::_instanciateQuestion($data['question_fi']); + } } - \ No newline at end of file diff --git a/classes/providers/class.ilQuestionSetPoolJumpConditionsProvider.php b/classes/providers/class.ilQuestionSetPoolJumpConditionsProvider.php index df9a274e23972067a50097f916e060c3dbfa6b2d..9c6de5e3b77eab5f2427ef81a56e12d11ef889df 100644 --- a/classes/providers/class.ilQuestionSetPoolJumpConditionsProvider.php +++ b/classes/providers/class.ilQuestionSetPoolJumpConditionsProvider.php @@ -8,74 +8,73 @@ require_once "abstract.ilPluginTableDatabaseDataProvider.php"; * Date: 05.12.13 * Time: 12:30 * @author Thomas Joußen - */ + */ class ilQuestionSetPoolJumpConditionsProvider extends ilPluginTableDatabaseDataProvider { - /** - * @return string - */ - protected function getSelectPart() - { - return "con.*, qst.question_index"; - } + /** + * @return string + */ + protected function getSelectPart() + { + return "con.*, qst.question_index"; + } - /** - * @return string - */ - protected function getFromPart() - { - return "rep_robj_xqsp_jmp_con con"; - } + /** + * @return string + */ + protected function getFromPart() + { + return "rep_robj_xqsp_jmp_con con"; + } - /** - * @return string - */ - protected function getJoinPart() - { - return join(" ", array( - "INNER JOIN rep_robj_xqsp_node n ON n.id = con.node_fi", - "INNER JOIN rep_robj_xqsp_path p ON p.id = n.path_fi", - "LEFT JOIN rep_robj_xqsp_qs_qst qst ON qst.questionset_fi = p.questionset_fi AND qst.question_fi = con.question_fi" - )); - } + /** + * @return string + */ + protected function getJoinPart() + { + return join(" ", array( + "INNER JOIN rep_robj_xqsp_node n ON n.id = con.node_fi", + "INNER JOIN rep_robj_xqsp_path p ON p.id = n.path_fi", + "LEFT JOIN rep_robj_xqsp_qs_qst qst ON qst.questionset_fi = p.questionset_fi AND qst.question_fi = con.question_fi" + )); + } - /** - * @param array $filter - * - * @return string - */ - protected function getWherePart(array $filter) - { - return "con.node_fi = " . $this->db->quote($filter['node_fi']); - } + /** + * @param array $filter + * + * @return string + */ + protected function getWherePart(array $filter) + { + return "con.node_fi = " . $this->db->quote($filter['node_fi']); + } - /** - * @return string - */ - protected function getGroupByPart() - { - return ""; - } + /** + * @return string + */ + protected function getGroupByPart() + { + return ""; + } - /** - * @param array $filter - * - * @return string - */ - protected function getHavingPart(array $filter) - { - return ""; - } + /** + * @param array $filter + * + * @return string + */ + protected function getHavingPart(array $filter) + { + return ""; + } - /** - * @param array $params - * - * @return string - */ - protected function getOrderByPart(array $params) - { - return "con.sorting ASC"; - } + /** + * @param array $params + * + * @return string + */ + protected function getOrderByPart(array $params) + { + return "con.sorting ASC"; + } } - \ No newline at end of file diff --git a/classes/providers/class.ilQuestionSetPoolNodeProvider.php b/classes/providers/class.ilQuestionSetPoolNodeProvider.php index 1d801187ed2ce4c2279eed9ae6396fa1f30b9751..244e200eda6728f6bcc529e8b6d7494a0d8f7a70 100644 --- a/classes/providers/class.ilQuestionSetPoolNodeProvider.php +++ b/classes/providers/class.ilQuestionSetPoolNodeProvider.php @@ -8,85 +8,84 @@ require_once "abstract.ilPluginTableDatabaseDataProvider.php"; * Date: 21.11.13 * Time: 12:23 * @author Thomas Joußen - */ + */ class ilQuestionSetPoolNodeProvider extends ilPluginTableDatabaseDataProvider { - /** - * @return string - */ - protected function getSelectPart() - { - $select = array( - "rep_robj_xqsp_node.*", - "rep_robj_xqsp_qs.id as set_fi", - "qpl_questions.title as question_title", - "rep_robj_xqsp_qs_qst.question_index", - // "rep_robj_xqsp_jmp_con.*" - ); + /** + * @return string + */ + protected function getSelectPart() + { + $select = array( + "rep_robj_xqsp_node.*", + "rep_robj_xqsp_qs.id as set_fi", + "qpl_questions.title as question_title", + "rep_robj_xqsp_qs_qst.question_index", + // "rep_robj_xqsp_jmp_con.*" + ); - return join(", ", $select); - } + return join(", ", $select); + } - /** - * @return string - */ - protected function getFromPart() - { - return "rep_robj_xqsp_node"; - } + /** + * @return string + */ + protected function getFromPart() + { + return "rep_robj_xqsp_node"; + } - /** - * @return string - */ - protected function getJoinPart() - { - $join = array( - "INNER JOIN qpl_questions ON qpl_questions.question_id = rep_robj_xqsp_node.question_fi", - "INNER JOIN rep_robj_xqsp_path ON rep_robj_xqsp_path.id = rep_robj_xqsp_node.path_fi", - "INNER JOIN rep_robj_xqsp_qs ON rep_robj_xqsp_qs.id = rep_robj_xqsp_path.questionset_fi", - "INNER JOIN rep_robj_xqsp_qs_qst ON rep_robj_xqsp_qs_qst.question_fi = qpl_questions.question_id", - // "INNER JOIN rep_robj_xqsp_jmp_con ON rep_robj_xqsp_jmp_con.node_fi = rep_robj_xqsp_node.id" - ); - return implode(" ", $join); - } + /** + * @return string + */ + protected function getJoinPart() + { + $join = array( + "INNER JOIN qpl_questions ON qpl_questions.question_id = rep_robj_xqsp_node.question_fi", + "INNER JOIN rep_robj_xqsp_path ON rep_robj_xqsp_path.id = rep_robj_xqsp_node.path_fi", + "INNER JOIN rep_robj_xqsp_qs ON rep_robj_xqsp_qs.id = rep_robj_xqsp_path.questionset_fi", + "INNER JOIN rep_robj_xqsp_qs_qst ON rep_robj_xqsp_qs_qst.question_fi = qpl_questions.question_id", + // "INNER JOIN rep_robj_xqsp_jmp_con ON rep_robj_xqsp_jmp_con.node_fi = rep_robj_xqsp_node.id" + ); + return implode(" ", $join); + } - /** - * @param array $filter - * - * @return string - */ - protected function getWherePart(array $filter) - { - return "rep_robj_xqsp_node.path_fi =" . $this->db->quote($filter['path_fi']); - } + /** + * @param array $filter + * + * @return string + */ + protected function getWherePart(array $filter) + { + return "rep_robj_xqsp_node.path_fi =" . $this->db->quote($filter['path_fi']); + } - /** - * @return string - */ - protected function getGroupByPart() - { - return ""; - } + /** + * @return string + */ + protected function getGroupByPart() + { + return ""; + } - /** - * @param array $filter - * - * @return string - */ - protected function getHavingPart(array $filter) - { - return ""; - } + /** + * @param array $filter + * + * @return string + */ + protected function getHavingPart(array $filter) + { + return ""; + } - /** - * @param array $params - * - * @return string - */ - protected function getOrderByPart(array $params) - { - return "rep_robj_xqsp_node.node_index ASC"; - } + /** + * @param array $params + * + * @return string + */ + protected function getOrderByPart(array $params) + { + return "rep_robj_xqsp_node.node_index ASC"; + } } - \ No newline at end of file diff --git a/classes/providers/class.ilQuestionSetPoolPathProvider.php b/classes/providers/class.ilQuestionSetPoolPathProvider.php index bd23b37bc7afa47c27e95a342cd8e968fa6571c6..84f238f2cdc4818066ca14952f5b5b996dae6321 100644 --- a/classes/providers/class.ilQuestionSetPoolPathProvider.php +++ b/classes/providers/class.ilQuestionSetPoolPathProvider.php @@ -8,70 +8,69 @@ require_once "abstract.ilPluginTableDatabaseDataProvider.php"; * Date: 19.11.13 * Time: 12:15 * @author Thomas Joußen - */ + */ class ilQuestionSetPoolPathProvider extends ilPluginTableDatabaseDataProvider { - /** - * @return string - */ - protected function getSelectPart() - { - return "*"; - } + /** + * @return string + */ + protected function getSelectPart() + { + return "*"; + } - /** - * @return string - */ - protected function getFromPart() - { - return "rep_robj_xqsp_path"; - } + /** + * @return string + */ + protected function getFromPart() + { + return "rep_robj_xqsp_path"; + } - /** - * @return string - */ - protected function getJoinPart() - { - return ""; - } + /** + * @return string + */ + protected function getJoinPart() + { + return ""; + } - /** - * @param array $filter - * - * @return string - */ - protected function getWherePart(array $filter) - { - return "rep_robj_xqsp_path.questionset_fi = " . $this->db->quote($filter['questionset_fi']); - } + /** + * @param array $filter + * + * @return string + */ + protected function getWherePart(array $filter) + { + return "rep_robj_xqsp_path.questionset_fi = " . $this->db->quote($filter['questionset_fi']); + } - /** - * @return string - */ - protected function getGroupByPart() - { - return ""; - } + /** + * @return string + */ + protected function getGroupByPart() + { + return ""; + } - /** - * @param array $filter - * - * @return string - */ - protected function getHavingPart(array $filter) - { - return ""; - } + /** + * @param array $filter + * + * @return string + */ + protected function getHavingPart(array $filter) + { + return ""; + } - /** - * @param array $params - * - * @return string - */ - protected function getOrderByPart(array $params) - { - return "rep_robj_xqsp_path.path_index ASC"; - } + /** + * @param array $params + * + * @return string + */ + protected function getOrderByPart(array $params) + { + return "rep_robj_xqsp_path.path_index ASC"; + } } - \ No newline at end of file diff --git a/classes/providers/class.ilQuestionSetPoolQuestionsBrowserProvider.php b/classes/providers/class.ilQuestionSetPoolQuestionsBrowserProvider.php index 07bd866a263a142907c5aa7a8ea26b3f7c5ca7ec..c30f045bb82e1041901615c4937f1ee2a280e9ed 100644 --- a/classes/providers/class.ilQuestionSetPoolQuestionsBrowserProvider.php +++ b/classes/providers/class.ilQuestionSetPoolQuestionsBrowserProvider.php @@ -8,138 +8,133 @@ require_once "abstract.ilPluginTableDatabaseDataProvider.php"; * Date: 16.04.13 * Time: 16:12 * @author Thomas Joußen - */ + */ class ilQuestionSetPoolQuestionsBrowserProvider extends ilPluginTableDatabaseDataProvider { - /** - * @return string - */ - protected function getSelectPart() - { - $fields = array( - "qpl_questions.*", - "qpl_qst_type.type_tag", - "qpl_qst_type.plugin", - "object_data.title pool_title", - "object_reference.ref_id pool_ref_id" - ); - - return implode(", ", $fields); - } - - /** - * @return string - */ - protected function getFromPart() - { - $from = array( - "qpl_questions", - - ); - - return implode(", ", $from); - } - - /** - * @return string - */ - protected function getJoinPart() - { - $joins = array( - "INNER JOIN qpl_qst_type ON qpl_questions.question_type_fi = qpl_qst_type.question_type_id", - "INNER JOIN object_data ON object_data.obj_id = qpl_questions.obj_fi", - "INNER JOIN object_reference ON object_reference.obj_id = qpl_questions.obj_fi", - //"LEFT JOIN rep_robj_xqsp_question ON qpl_questions.question_id = rep_robj_xqsp_question.question_fi" - ); - - return implode(" ", $joins); - } - - - /** - * @param array $filter - * - * @return string - */ - protected function getWherePart(array $filter) - { - $excludes = array( - 14, - 8 - ); - $types = array_merge($excludes, ilObjAssessmentFolder::_getManualScoring()); - - $where = array( - "qpl_questions.original_id IS NULL", - "qpl_questions.tstamp > 0", + /** + * @return string + */ + protected function getSelectPart() + { + $fields = array( + "qpl_questions.*", + "qpl_qst_type.type_tag", + "qpl_qst_type.plugin", + "object_data.title pool_title", + "object_reference.ref_id pool_ref_id" + ); + + return implode(", ", $fields); + } + + /** + * @return string + */ + protected function getFromPart() + { + $from = array( + "qpl_questions", + + ); + + return implode(", ", $from); + } + + /** + * @return string + */ + protected function getJoinPart() + { + $joins = array( + "INNER JOIN qpl_qst_type ON qpl_questions.question_type_fi = qpl_qst_type.question_type_id", + "INNER JOIN object_data ON object_data.obj_id = qpl_questions.obj_fi", + "INNER JOIN object_reference ON object_reference.obj_id = qpl_questions.obj_fi", + //"LEFT JOIN rep_robj_xqsp_question ON qpl_questions.question_id = rep_robj_xqsp_question.question_fi" + ); + + return implode(" ", $joins); + } + + + /** + * @param array $filter + * + * @return string + */ + protected function getWherePart(array $filter) + { + $excludes = array( + 14, + 8 + ); + $types = array_merge($excludes, ilObjAssessmentFolder::_getManualScoring()); + + $where = array( + "qpl_questions.original_id IS NULL", + "qpl_questions.tstamp > 0", // "(rep_robj_xqsp_question.questionsetpool_fi IS NULL OR rep_robj_xqsp_question.questionsetpool_fi != " . $this->db->quote($filter['xqsp_id'], 'integer') . ")", // "rep_robj_xqsp_question.questionsetpool_fi != " . $this->db->quote($filter['xqsp_id'], 'integer'), - $this->db->in("qpl_qst_type.question_type_id", $types, true, "integer"), - $this->db->in('qpl_questions.obj_fi', $filter["question_pools"], false, 'integer'), - "qpl_questions.complete = " . $this->db->quote("1", "text") - ); - - $where = $this->addOptionalFilterElements($filter, $where); - - return implode(" AND ", $where); - } - - /** - * @return string - */ - protected function getGroupByPart() - { - return ""; - } - - /** - * @param array $filter - * @return string - */ - protected function getHavingPart(array $filter) - { - return ""; - } - - /** - * @param array $params - * @return string - */ - protected function getOrderByPart(array $params) - { - return ""; - } - - /** - * @param array $filter - * @param $where - * - * @return array - */ - protected function addOptionalFilterElements(array $filter, $where) - { - if ($filter["question_type"]) - { - $where[] = "qpl_qst_type.type_tag = " . $this->db->quote($filter["question_type"], "text"); - } - if ($filter["title"]) - { - $where[] = $this->db->like("qpl_questions.title", "text", "%".$filter["title"]."%"); - } - if ($filter["description"]) - { - $where[] = $this->db->like("qpl_questions.description", "text", "%".$filter["description"]."%"); - } - if ($filter["author"]) - { - $where[] = $this->db->like("qpl_questions.author", "text", "%".$filter["author"]."%"); - } - if ($filter["qpl"]) - { - $where[] = $this->db->like("object_data.title", "text", "%".$filter["qpl"]."%"); - } - - return $where; - } + $this->db->in("qpl_qst_type.question_type_id", $types, true, "integer"), + $this->db->in('qpl_questions.obj_fi', $filter["question_pools"], false, 'integer'), + "qpl_questions.complete = " . $this->db->quote("1", "text") + ); + + $where = $this->addOptionalFilterElements($filter, $where); + + return implode(" AND ", $where); + } + + /** + * @return string + */ + protected function getGroupByPart() + { + return ""; + } + + /** + * @param array $filter + * @return string + */ + protected function getHavingPart(array $filter) + { + return ""; + } + + /** + * @param array $params + * @return string + */ + protected function getOrderByPart(array $params) + { + return ""; + } + + /** + * @param array $filter + * @param $where + * + * @return array + */ + protected function addOptionalFilterElements(array $filter, $where) + { + if ($filter["question_type"]) { + $where[] = "qpl_qst_type.type_tag = " . $this->db->quote($filter["question_type"], "text"); + } + if ($filter["title"]) { + $where[] = $this->db->like("qpl_questions.title", "text", "%" . $filter["title"] . "%"); + } + if ($filter["description"]) { + $where[] = $this->db->like("qpl_questions.description", "text", "%" . $filter["description"] . "%"); + } + if ($filter["author"]) { + $where[] = $this->db->like("qpl_questions.author", "text", "%" . $filter["author"] . "%"); + } + if ($filter["qpl"]) { + $where[] = $this->db->like("object_data.title", "text", "%" . $filter["qpl"] . "%"); + } + + return $where; + } } diff --git a/classes/providers/class.ilQuestionSetPoolSetQuestionsProvider.php b/classes/providers/class.ilQuestionSetPoolSetQuestionsProvider.php index 845f73b375fdc67c1bbef77f7daa98af67a10c6e..e42aea1dba9c383d7b320972968848560c24accf 100644 --- a/classes/providers/class.ilQuestionSetPoolSetQuestionsProvider.php +++ b/classes/providers/class.ilQuestionSetPoolSetQuestionsProvider.php @@ -8,93 +8,92 @@ require_once "abstract.ilPluginTableDatabaseDataProvider.php"; * Date: 15.11.13 * Time: 10:01 * @author Thomas Joußen - */ + */ class ilQuestionSetPoolSetQuestionsProvider extends ilPluginTableDatabaseDataProvider { - /** - * @return string - */ - protected function getSelectPart() - { - $fields = array( - "qpl_questions.*", - "qpl_qst_type.type_tag", - "qpl_qst_type.plugin", - "object_data.title as pool_title", - "rep_robj_xqsp_qs_qst.question_index" - ); + /** + * @return string + */ + protected function getSelectPart() + { + $fields = array( + "qpl_questions.*", + "qpl_qst_type.type_tag", + "qpl_qst_type.plugin", + "object_data.title as pool_title", + "rep_robj_xqsp_qs_qst.question_index" + ); - return implode(", ", $fields); - } + return implode(", ", $fields); + } - /** - * @return string - */ - protected function getFromPart() - { - $from = array( - "qpl_questions", - ); + /** + * @return string + */ + protected function getFromPart() + { + $from = array( + "qpl_questions", + ); - return implode(", ", $from); - } + return implode(", ", $from); + } - /** - * @return string - */ - protected function getJoinPart() - { - $joins = array( - "INNER JOIN qpl_qst_type ON qpl_questions.question_type_fi = qpl_qst_type.question_type_id", - "INNER JOIN object_data ON object_data.obj_id = qpl_questions.obj_fi", - "LEFT JOIN rep_robj_xqsp_qs_qst ON rep_robj_xqsp_qs_qst.question_fi = qpl_questions.question_id" - ); + /** + * @return string + */ + protected function getJoinPart() + { + $joins = array( + "INNER JOIN qpl_qst_type ON qpl_questions.question_type_fi = qpl_qst_type.question_type_id", + "INNER JOIN object_data ON object_data.obj_id = qpl_questions.obj_fi", + "LEFT JOIN rep_robj_xqsp_qs_qst ON rep_robj_xqsp_qs_qst.question_fi = qpl_questions.question_id" + ); - return implode(" ", $joins); - } + return implode(" ", $joins); + } - /** - * @param array $filter - * - * @return string - */ - protected function getWherePart(array $filter) - { - $where = array( - "qpl_questions.tstamp > 0", - "rep_robj_xqsp_qs_qst.questionset_fi = " . $this->db->quote($filter["questionset_fi"], 'integer') - ); + /** + * @param array $filter + * + * @return string + */ + protected function getWherePart(array $filter) + { + $where = array( + "qpl_questions.tstamp > 0", + "rep_robj_xqsp_qs_qst.questionset_fi = " . $this->db->quote($filter["questionset_fi"], 'integer') + ); - // ADD FILTER ELEMENTS + // ADD FILTER ELEMENTS - return implode(" AND ", $where); - } + return implode(" AND ", $where); + } - /** - * @return string - */ - protected function getGroupByPart() - { - return ""; - } + /** + * @return string + */ + protected function getGroupByPart() + { + return ""; + } - /** - * @param array $filter - * @return string - */ - protected function getHavingPart(array $filter) - { - return ""; - } + /** + * @param array $filter + * @return string + */ + protected function getHavingPart(array $filter) + { + return ""; + } - /** - * @param array $params - * @return string - */ - protected function getOrderByPart(array $params) - { - return ""; - } + /** + * @param array $params + * @return string + */ + protected function getOrderByPart(array $params) + { + return ""; + } } - \ No newline at end of file diff --git a/classes/providers/class.ilQuestionSetPoolSetsProvider.php b/classes/providers/class.ilQuestionSetPoolSetsProvider.php index 3edffe75dd37e6c1536140942c9d16aebcdc765d..d0203a073e57f5cefce7011d2cb5ec3f44e74132 100644 --- a/classes/providers/class.ilQuestionSetPoolSetsProvider.php +++ b/classes/providers/class.ilQuestionSetPoolSetsProvider.php @@ -8,74 +8,74 @@ require_once "abstract.ilPluginTableDatabaseDataProvider.php"; * Date: 07.10.13 * Time: 14:34 * @author Thomas Joußen - */ + */ class ilQuestionSetPoolSetsProvider extends ilPluginTableDatabaseDataProvider { - /** - * @return string - */ - protected function getSelectPart() - { - $select = array( - "id", - "title", - "description" - ); + /** + * @return string + */ + protected function getSelectPart() + { + $select = array( + "id", + "title", + "description" + ); - $select[] = "(SELECT COUNT(qst.question_fi) FROM rep_robj_xqsp_qs_qst qst WHERE qst.questionset_fi = qs.id) has_questions"; + $select[] = "(SELECT COUNT(qst.question_fi) FROM rep_robj_xqsp_qs_qst qst WHERE qst.questionset_fi = qs.id) has_questions"; - return implode(", ", $select); - } + return implode(", ", $select); + } - /** - * @return string - */ - protected function getFromPart() - { - return "rep_robj_xqsp_qs qs"; - } + /** + * @return string + */ + protected function getFromPart() + { + return "rep_robj_xqsp_qs qs"; + } - /** - * @return string - */ - protected function getJoinPart() - { - return ""; - } + /** + * @return string + */ + protected function getJoinPart() + { + return ""; + } - /** - * @param array $filter - * - * @return string - */ - protected function getWherePart(array $filter) - { - return "questionsetpool_fi = " . $this->db->quote($filter["questionsetpool_fi"], "integer"); - } + /** + * @param array $filter + * + * @return string + */ + protected function getWherePart(array $filter) + { + return "questionsetpool_fi = " . $this->db->quote($filter["questionsetpool_fi"], "integer"); + } - /** - * @return string - */ - protected function getGroupByPart() - { - return ""; - } + /** + * @return string + */ + protected function getGroupByPart() + { + return ""; + } - /** - * @param array $filter - * @return string - */ - protected function getHavingPart(array $filter) - { - return ""; - } + /** + * @param array $filter + * @return string + */ + protected function getHavingPart(array $filter) + { + return ""; + } - /** - * @param array $params - * @return string - */ - protected function getOrderByPart(array $params) - { - return ""; - } + /** + * @param array $params + * @return string + */ + protected function getOrderByPart(array $params) + { + return ""; + } } diff --git a/classes/providers/class.ilQuestionSetPoolSkillQuestionListProvider.php b/classes/providers/class.ilQuestionSetPoolSkillQuestionListProvider.php index ab94cbb3f82048ad3167800c345657ff32b4f602..0bbe4a7ad574376cf86722c05dac2c3d6543c431 100644 --- a/classes/providers/class.ilQuestionSetPoolSkillQuestionListProvider.php +++ b/classes/providers/class.ilQuestionSetPoolSkillQuestionListProvider.php @@ -11,70 +11,69 @@ require_once 'abstract.ilPluginTableDatabaseDataProvider.php'; class ilQuestionSetPoolSkillQuestionListProvider extends ilPluginTableDatabaseDataProvider { - /** - * @return string - */ - protected function getSelectPart() - { - return join(',', array('title','question_index','question_fi')); - } + /** + * @return string + */ + protected function getSelectPart() + { + return join(',', array('title','question_index','question_fi')); + } - /** - * @return string - */ - protected function getFromPart() - { - return 'rep_robj_xqsp_qs_qst'; - } + /** + * @return string + */ + protected function getFromPart() + { + return 'rep_robj_xqsp_qs_qst'; + } - /** - * @param array $filter - * - * @return string - */ - protected function getJoinPart() - { - return join(' ', array( - 'INNER JOIN rep_robj_xqsp_qs ON rep_robj_xqsp_qs.id = rep_robj_xqsp_qs_qst.questionset_fi', - )); - } + /** + * @param array $filter + * + * @return string + */ + protected function getJoinPart() + { + return join(' ', array( + 'INNER JOIN rep_robj_xqsp_qs ON rep_robj_xqsp_qs.id = rep_robj_xqsp_qs_qst.questionset_fi', + )); + } - /** - * @param array $filter - * - * @return string - */ - protected function getWherePart(array $filter) - { - return $this->db->equals('rep_robj_xqsp_qs.questionsetpool_fi', $filter['questionsetpool_fi'], 'integer'); - } + /** + * @param array $filter + * + * @return string + */ + protected function getWherePart(array $filter) + { + return $this->db->equals('rep_robj_xqsp_qs.questionsetpool_fi', $filter['questionsetpool_fi'], 'integer'); + } - /** - * @return string - */ - protected function getGroupByPart() - { - return ''; - } + /** + * @return string + */ + protected function getGroupByPart() + { + return ''; + } - /** - * @param array $filter - * - * @return string - */ - protected function getHavingPart(array $filter) - { - return ''; - } + /** + * @param array $filter + * + * @return string + */ + protected function getHavingPart(array $filter) + { + return ''; + } - /** - * @param array $params - * - * @return string - */ - protected function getOrderByPart(array $params) - { - return 'rep_robj_xqsp_qs.title, question_index ASC'; - } + /** + * @param array $params + * + * @return string + */ + protected function getOrderByPart(array $params) + { + return 'rep_robj_xqsp_qs.title, question_index ASC'; + } } - \ No newline at end of file diff --git a/classes/providers/interface.ilPluginTableDataProvider.php b/classes/providers/interface.ilPluginTableDataProvider.php index 0a845e2f1392271f6e7607edc347bfb662b83a79..f3e547250f8da8e42ab71a280211f4706c7c6f18 100644 --- a/classes/providers/interface.ilPluginTableDataProvider.php +++ b/classes/providers/interface.ilPluginTableDataProvider.php @@ -7,6 +7,6 @@ * @author Thomas Joußen */ -interface ilPluginTableDataProvider { - -} \ No newline at end of file +interface ilPluginTableDataProvider +{ +} diff --git a/classes/tables/class.ilPluginTableGUI.php b/classes/tables/class.ilPluginTableGUI.php index 67f9e9682408b2b50a5f5484245fd9dbcbf46599..f443d18e12341b203c56ca441a14a13f064dc34e 100644 --- a/classes/tables/class.ilPluginTableGUI.php +++ b/classes/tables/class.ilPluginTableGUI.php @@ -1,6 +1,5 @@ - */ + */ abstract class ilPluginTableGUI extends ilTable2GUI { - /** - * @var ilPluginModelList - */ - protected $model_list; - - /** - * @var ilCtrl - */ - protected $ctrl; - - /** - * @var array - */ - protected $visibleOptionalColumns = array(); - - /** - * @var array - */ - protected $optionalColumns = array(); - - /** - * @var array - */ - protected $filter = array(); - - /** - * @var array - */ - protected $optional_filter = array(); - - /** - * @var - */ - protected $plugin; - - public function __construct($a_parent_obj, $a_parent_cmd = "", $plugin) - { - $this->plugin = $plugin; - parent::__construct($a_parent_obj, $a_parent_cmd); - - $this->lng->loadLanguageModule("assessment"); - } - - - /** - * @param ilPluginModelList $model_list - */ - public function setModelList($model_list) - { - $this->model_list = $model_list; - } - - /** - * @return ilPluginModelList - */ - public function getModelList() - { - return $this->model_list; - } - - /** - * @param string $column - * @return bool - */ - protected function isColumnVisible($column) - { - if(array_key_exists($column, $this->optionalColumns) && !isset($this->visibleOptionalColumns[$column])) - { - return false; - } - - return true; - } - - /** - * This method can be used to prepare values for sorting (e.g. translations), to filter items etc. - * It is called before sorting and segmentation. - * @param array $data - * @return array - */ - protected function prepareData(array &$data) - { - foreach($data as $key => $item) - { - if(!is_array($item)) - { - $data[$key] = $item->toArray(); - } - } - } - - /** - * This method can be used to manipulate the data of a row after sorting and segmentation - * @param array $data - * @return array - */ - protected function prepareRow(array &$row) - { - } - - /** - * Define a final formatting for a cell value - * @param mixed $column - * @param array $row - * @return mixed - */ - protected function formatCellValue($column, array $row) - { - return $row[$column]; - } - - /** - * @param array $row - */ - final protected function fillRow($row) - { - $this->prepareRow($row); - - foreach($this->getStaticData() as $column) - { - $value = $this->formatCellValue($column, $row); - $this->tpl->setVariable('VAL_' . strtoupper($column), $value); - } - - foreach($this->optionalColumns as $index => $definition) - { - if(!$this->isColumnVisible($index)) - { - continue; - } - - $this->tpl->setCurrentBlock('optional_column'); - $value = $this->formatCellValue($index, $row); - if((string)$value === '') - { - $this->tpl->touchBlock('optional_column'); - } - else - { - $this->tpl->setVariable('OPTIONAL_COLUMN_VAL_' . strtoupper($index), $value); - } - - $this->tpl->parseCurrentBlock(); - } - } - - /** - * Return an array of all static (always visible) data fields in a row. - * For each key there has to be a variable name VAL_ in your defined row template. - * Example: - * return array('title', 'checkbox'); - * There have to be two template variables: VAL_TITLE and VAL_CHECKBOX - * @return array - * @abstract - */ - abstract protected function getStaticData(); - - /** - * @throws ilException - */ - public function populate() - { - /*$data = $this->getModelList()->getData(); - if($data != null) - { - $this->prepareData($data); - } - - $this->setData($data);*/ - /** - * @TODO MOVE TO A PROVIDER! - */ - if(!$this->getExternalSegmentation() && $this->getExternalSorting()) - { - $this->determineOffsetAndOrder(true); - } - else if($this->getExternalSegmentation() || $this->getExternalSorting()) - { - $this->determineOffsetAndOrder(); - } - $params = array(); - if($this->getExternalSegmentation()) - { - $params['limit'] = $this->getLimit(); - $params['offset'] = $this->getOffset(); - } - if($this->getExternalSorting()) - { - $params['order_field'] = $this->getOrderField(); - $params['order_direction'] = $this->getOrderDirection(); - } - - $this->determineSelectedFilters(); - $filter = $this->filter; - - foreach($this->optional_filter as $key => $value) - { - if($this->isFilterSelected($key)) - { - $filter[$key] = $value; - } - } - - $data = $this->getModelList()->loadData($params, $filter); - - if(is_array($data['items'])) - { - if(!count($data['items']) && $this->getOffset() > 0 && $this->getExternalSegmentation()) - { - $this->resetOffset(); - $params['limit'] = $this->getLimit(); - $params['offset'] = $this->getOffset(); - $data = $this->getModelList()->loadData($params, $filter); - } - } - - if($data != null) - { - $this->prepareData($data); - } - - $this->setData($data); - if($this->getExternalSegmentation()) - { - if(is_array($data)) - { - $this->setMaxCount(count($data)); - } - } - } + /** + * @var ilPluginModelList + */ + protected $model_list; + + /** + * @var ilCtrl + */ + protected $ctrl; + + /** + * @var array + */ + protected $visibleOptionalColumns = array(); + + /** + * @var array + */ + protected $optionalColumns = array(); + + /** + * @var array + */ + protected $filter = array(); + + /** + * @var array + */ + protected $optional_filter = array(); + + /** + * @var + */ + protected $plugin; + + public function __construct($a_parent_obj, $a_parent_cmd = "", $plugin) + { + $this->plugin = $plugin; + parent::__construct($a_parent_obj, $a_parent_cmd); + + $this->lng->loadLanguageModule("assessment"); + } + + + /** + * @param ilPluginModelList $model_list + */ + public function setModelList($model_list) + { + $this->model_list = $model_list; + } + + /** + * @return ilPluginModelList + */ + public function getModelList() + { + return $this->model_list; + } + + /** + * @param string $column + * @return bool + */ + protected function isColumnVisible($column) + { + if (array_key_exists($column, $this->optionalColumns) && !isset($this->visibleOptionalColumns[$column])) { + return false; + } + + return true; + } + + /** + * This method can be used to prepare values for sorting (e.g. translations), to filter items etc. + * It is called before sorting and segmentation. + * @param array $data + * @return array + */ + protected function prepareData(array &$data) + { + foreach ($data as $key => $item) { + if (!is_array($item)) { + $data[$key] = $item->toArray(); + } + } + } + + /** + * This method can be used to manipulate the data of a row after sorting and segmentation + * @param array $data + * @return array + */ + protected function prepareRow(array &$row) + { + } + + /** + * Define a final formatting for a cell value + * @param mixed $column + * @param array $row + * @return mixed + */ + protected function formatCellValue($column, array $row) + { + return $row[$column]; + } + + /** + * @param array $row + */ + final protected function fillRow($row) + { + $this->prepareRow($row); + + foreach ($this->getStaticData() as $column) { + $value = $this->formatCellValue($column, $row); + $this->tpl->setVariable('VAL_' . strtoupper($column), $value); + } + + foreach ($this->optionalColumns as $index => $definition) { + if (!$this->isColumnVisible($index)) { + continue; + } + + $this->tpl->setCurrentBlock('optional_column'); + $value = $this->formatCellValue($index, $row); + if ((string) $value === '') { + $this->tpl->touchBlock('optional_column'); + } else { + $this->tpl->setVariable('OPTIONAL_COLUMN_VAL_' . strtoupper($index), $value); + } + + $this->tpl->parseCurrentBlock(); + } + } + + /** + * Return an array of all static (always visible) data fields in a row. + * For each key there has to be a variable name VAL_ in your defined row template. + * Example: + * return array('title', 'checkbox'); + * There have to be two template variables: VAL_TITLE and VAL_CHECKBOX + * @return array + * @abstract + */ + abstract protected function getStaticData(); + + /** + * @throws ilException + */ + public function populate() + { + /*$data = $this->getModelList()->getData(); + if($data != null) + { + $this->prepareData($data); + } + + $this->setData($data);*/ + /** + * @TODO MOVE TO A PROVIDER! + */ + if (!$this->getExternalSegmentation() && $this->getExternalSorting()) { + $this->determineOffsetAndOrder(true); + } elseif ($this->getExternalSegmentation() || $this->getExternalSorting()) { + $this->determineOffsetAndOrder(); + } + $params = array(); + if ($this->getExternalSegmentation()) { + $params['limit'] = $this->getLimit(); + $params['offset'] = $this->getOffset(); + } + if ($this->getExternalSorting()) { + $params['order_field'] = $this->getOrderField(); + $params['order_direction'] = $this->getOrderDirection(); + } + + $this->determineSelectedFilters(); + $filter = $this->filter; + + foreach ($this->optional_filter as $key => $value) { + if ($this->isFilterSelected($key)) { + $filter[$key] = $value; + } + } + + $data = $this->getModelList()->loadData($params, $filter); + + if (is_array($data['items'])) { + if (!count($data['items']) && $this->getOffset() > 0 && $this->getExternalSegmentation()) { + $this->resetOffset(); + $params['limit'] = $this->getLimit(); + $params['offset'] = $this->getOffset(); + $data = $this->getModelList()->loadData($params, $filter); + } + } + + if ($data != null) { + $this->prepareData($data); + } + + $this->setData($data); + if ($this->getExternalSegmentation()) { + if (is_array($data)) { + $this->setMaxCount(count($data)); + } + } + } } diff --git a/classes/tables/class.ilQuestionSetPoolExportTableGUI.php b/classes/tables/class.ilQuestionSetPoolExportTableGUI.php index e27abf4b2b3b0e7b5ad3a7eb744ce0be657efcbd..14d93f6ff98ad6f99a27835704c47f9fa791bedb 100755 --- a/classes/tables/class.ilQuestionSetPoolExportTableGUI.php +++ b/classes/tables/class.ilQuestionSetPoolExportTableGUI.php @@ -1,53 +1,50 @@ */ class ilQuestionSetPoolExportTableGUI extends ilExportTableGUI { - /** - * Constructor - * - * @access public - * @param - * @return - */ - public function __construct($a_parent_obj, $a_parent_cmd, $a_exp_obj) - { - parent::__construct($a_parent_obj, $a_parent_cmd, $a_exp_obj); + /** + * Constructor + * + * @access public + * @param + * @return + */ + public function __construct($a_parent_obj, $a_parent_cmd, $a_exp_obj) + { + parent::__construct($a_parent_obj, $a_parent_cmd, $a_exp_obj); - // NOT REQUIRED ANYMORE, PROBLEM NOW FIXED IN THE ROOT - // KEEP CODE, JF OPINIONS / ROOT FIXINGS CAN CHANGE - //$this->addCustomColumn($this->lng->txt('actions'), $this, 'formatActionsList'); - } + // NOT REQUIRED ANYMORE, PROBLEM NOW FIXED IN THE ROOT + // KEEP CODE, JF OPINIONS / ROOT FIXINGS CAN CHANGE + //$this->addCustomColumn($this->lng->txt('actions'), $this, 'formatActionsList'); + } - /** - * @param string $type - * @param string $filename - */ - protected function formatActionsList($type, $filename) - { - global $DIC; - $ilCtrl = $DIC->ctrl(); + /** + * @param string $type + * @param string $filename + */ + protected function formatActionsList($type, $filename) + { + global $DIC; + $ilCtrl = $DIC->ctrl(); - $list = new ilAdvancedSelectionListGUI(); - $list->setListTitle($this->lng->txt('actions')); - $ilCtrl->setParameter($this->getParentObject(), 'file', $type.':'.$filename); - $list->addItem($this->lng->txt('download'), '', $ilCtrl->getLinkTarget($this->getParentObject(), 'download')); - $ilCtrl->setParameter($this->getParentObject(), 'file', ''); - return $list->getHTML(); - } + $list = new ilAdvancedSelectionListGUI(); + $list->setListTitle($this->lng->txt('actions')); + $ilCtrl->setParameter($this->getParentObject(), 'file', $type . ':' . $filename); + $list->addItem($this->lng->txt('download'), '', $ilCtrl->getLinkTarget($this->getParentObject(), 'download')); + $ilCtrl->setParameter($this->getParentObject(), 'file', ''); + return $list->getHTML(); + } - /*** - * - */ - protected function initMultiCommands() - { - $this->addMultiCommand('confirmDeletion', $this->lng->txt('delete')); - } -} \ No newline at end of file + /*** + * + */ + protected function initMultiCommands() + { + $this->addMultiCommand('confirmDeletion', $this->lng->txt('delete')); + } +} diff --git a/classes/tables/class.ilQuestionSetPoolNodeTableGUI.php b/classes/tables/class.ilQuestionSetPoolNodeTableGUI.php index a2037d29fbfc89ae7bedbf300258fcd18423fa88..b1b408c0f8903504ec81430158e47271329f061f 100644 --- a/classes/tables/class.ilQuestionSetPoolNodeTableGUI.php +++ b/classes/tables/class.ilQuestionSetPoolNodeTableGUI.php @@ -1,8 +1,6 @@ - */ + */ class ilQuestionSetPoolNodeTableGUI extends ilPluginTableGUI { - - private $controller; - - public function __construct($controller, $plugin, $path_id) - { - global $DIC; - $ilCtrl = $DIC->ctrl(); - - $this->ctrl = $ilCtrl; - $this->controller = $controller; - $this->setId("xqsp_nodes_".$plugin->getId() . '_' . $path_id); - - parent::__construct($controller, "ilQuestionSetPoolNodesGUI.listNodes", $plugin); - - $this->createTable(); - } - - private function createTable() - { - $this->setTitle($this->plugin->txt('nodes')); - - $this->setFormName("paths"); - $this->setStyle('table', 'fullwidth'); - - $this->addColumn($this->plugin->txt('index'), '', true, '1%'); - $this->addColumn($this->lng->txt('question'), '', '400px'); - $this->addColumn($this->plugin->txt('initial_condition')); - $this->addColumn($this->plugin->txt('jump_conditions')); - $this->addColumn($this->plugin->txt('dominant_scoring')); - $this->addColumn($this->plugin->txt('actions'), '', '1%'); - - /*$this->setSelectAllCheckbox('n_id');*/ - - $this->setRowTemplate('tpl.il_xqsp_node_row.html', $this->controller->plugin->getDirectory()); - $this->ctrl->setParameter($this->controller, "path_id", $_GET['path_id']); - $this->ctrl->setParameter($this->controller, "set_id", $_GET['set_id']); - $this->setFormAction($this->ctrl->getFormAction($this->controller)); - $this->ctrl->setParameter($this->controller, "path_id", ""); - $this->ctrl->setParameter($this->controller, "set_id", ""); - $this->setDefaultOrderField("title"); - $this->setDefaultOrderDirection("asc"); - - $this->enable("sort"); - $this->enable("header"); - /*$this->enable("select_all");*/ - } - - - /** - * Return an array of all static (always visible) data fields in a row. - * For each key there has to be a variable name VAL_ in your defined row template. - * Example: - * return array('title', 'checkbox'); - * There have to be two template variables: VAL_TITLE and VAL_CHECKBOX - * @return array - */ - protected function getStaticData() - { - return array( - "node_index", - "question_title", - "question_index", - "initial_condition", - "jump_conditions", - "dominant_scoring", - "actions" - ); - } - - protected function formatCellValue($column, array $row) - { - switch($column) - { - case "question_title": - $this->ctrl->setParameter($this->parent_obj, "q_id", $row["question_fi"]); - $this->ctrl->setParameter($this->parent_obj, "set_id", $row["set_fi"]); - $this->ctrl->setParameter($this->parent_obj, "path_id", $row["path_fi"]); - $row['question_title'] = '' . $row['question_title'] . ''; - $this->ctrl->setParameter($this->parent_obj, "q_id", ""); - $this->ctrl->setParameter($this->parent_obj, "set_id", ""); - $this->ctrl->setParameter($this->parent_obj, "path_id", ""); - break; - case "node_index": - $sort = new ilNumberInputGUI('', 'sorting[' . $row['id'] . ']'); - $sort->allowDecimals(false); - $sort->setSize(3); - $sort->setValue($row[$column]); - if($row[$column] == 1) - { - $sort->setDisabled(true); - } - $row[$column] = $sort->render(); - break; - case "dominant_scoring": - $number = new ilNumberInputGUI("", $column."[".$row['id']. "]"); - $number->allowDecimals(false); - $number->setSize(3); - $number->setValue($row[$column]); - $row[$column] = $number->render(); - break; - case "initial_condition": - $row = $this->renderInitialCondition($row); - break; - case "actions": - $action = new ilAdvancedSelectionListGUI(); - $action->setId('asl_'.$row["id"]); - $action->setListTitle($this->lng->txt('actions')); - - $this->ctrl->setParameter($this->controller, "set_id", $row["set_fi"]); - $this->ctrl->setParameter($this->controller, "path_id", $row["path_fi"]); - - $this->ctrl->setParameter($this->controller, "node_id", $row['id']); - if(!$row["initial_condition"]) - { - - $action->addItem($this->plugin->txt("add_initial_condition"), '', $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolInitialConditionGUI.edit")); - } - else - { - $action->addItem($this->plugin->txt("edit_initial_condition"), '', $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolInitialConditionGUI.edit")); - } - $this->ctrl->setParameter($this->controller, "node_id", ""); - - $this->ctrl->setParameter($this->controller, "node_fi", $row['id']); - $this->ctrl->setParameter($this->controller, "condition_id", $row['condition_id']); - $action->addItem($this->plugin->txt("jump_condition_add"), '', $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolJumpConditionGUI.edit")); - $this->ctrl->setParameter($this->controller, "condition_id", ""); - $this->ctrl->setParameter($this->controller, "node_fi", ""); - - $this->ctrl->setParameter($this->controller, 'node_id', $row['id']); - $action->addItem($this->lng->txt("delete"), '',$this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolNodeGUI.removeConfirmation")); - $this->ctrl->setParameter($this->controller, "node_id", ""); - - $this->ctrl->setParameter($this->controller, "set_id", ''); - $this->ctrl->setParameter($this->controller, "path_id", ''); - - $row["actions"] = $action->getHtml(); - break; - case "jump_conditions": - $row = $this->renderJumpConditions($row); - break; - } - return parent::formatCellValue($column, $row); - } - - /** - * @param array $row - * - * @return array - */ - protected function renderJumpConditions(array $row) - { - require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/classes/models/class.ilQuestionSetPoolNode.php"; - - $model = new ilQuestionSetPoolNode($row["id"]); - $model->read(); - $row["jump_conditions"] = $model->getJumpConditionList()->getData(); - - $this->ctrl->setParameter($this->controller, "set_id", $row["set_fi"]); - $this->ctrl->setParameter($this->controller, "path_id", $row["path_fi"]); - - $conditions = '
    '; - foreach ($row['jump_conditions'] as $key => $condition) - { - $this->ctrl->setParameter($this->controller, "condition_id", $condition['id']); - $edit = $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolJumpConditionGUI.edit"); - $remove = $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolJumpConditionGUI.remove"); - $up = $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolJumpConditionGUI.up"); - $down = $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolJumpConditionGUI.down"); - $this->ctrl->setParameter($this->controller, "condition_id", ""); - - $conditions .= "
  • "; - if($key != 0) - { - $conditions .= ' '; - } - else - { - $conditions .= ' '; - } - - $conditions .= $condition['jump_condition'] . " - "; - if ($condition["question_index"] != null) - { - $conditions .= $this->plugin->txt("target_question") . ": "; - $conditions .= "Q" . $condition["question_index"]; - } - else - { - $conditions .= $this->plugin->txt("tst_termination"); - } - - $action = new ilAdvancedSelectionListGUI(); - $action->setId('asl_jump_'.$condition["id"]); - $action->setListTitle(''); - $action->addItem($this->plugin->txt("jump_condition_edit"), '', $edit); - $action->addItem($this->plugin->txt("jump_condition_delete"), '', $remove); - - $conditions .= $action->getHTML(); - $conditions .= "
    "; - - if(is_array($row['jump_conditions'])) - { - if($key != count($row["jump_conditions"]) - 1) - { - $conditions .= ' '; - } - else - { - $conditions .= ' '; - } - } - - if($condition["repititions"] == null) - { - $condition["repititions"] = $this->plugin->txt("endless_repititions"); - } - - $conditions .= $this->plugin->txt("repititions") . ": " . $condition["repititions"]; - $conditions .= "
  • "; - } - if (is_array($row['jump_conditions']) && count($row['jump_conditions'])) - { - $row['jump_conditions'] = $conditions; - } - else - { - $row['jump_conditions'] = ""; - } - - $this->ctrl->setParameter($this->controller, "set_id", ''); - $this->ctrl->setParameter($this->controller, "path_id", ''); - - return $row; -} - - /** - * @param array $row - * @return array - */ - protected function renderInitialCondition(array $row) - { - if($row["initial_condition"] != null) - { - $this->ctrl->setParameter($this->controller, "set_id", $row["set_fi"]); - $this->ctrl->setParameter($this->controller, "path_id", $row["path_fi"]); - - $this->ctrl->setParameter($this->controller, "node_id", $row['id']); - $edit = $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolInitialConditionGUI.edit"); - $this->ctrl->setParameter($this->controller, "node_id", ""); - - $this->ctrl->setParameter($this->controller, "node_id", $row['id']); - $remove = $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolInitialConditionGUI.remove"); - $this->ctrl->setParameter($this->controller, "node_id", ""); - - $action = new ilAdvancedSelectionListGUI(); - $action->setId('asl_init_'.$row["id"]); - $action->setListTitle(''); - - $action->addItem($this->plugin->txt("edit_initial_condition"), '', $edit); - $action->addItem($this->plugin->txt("remove_initial_condition"), '', $remove); - - $row["initial_condition"] = '
    • ' . $row["initial_condition"] . $action->getHTML().'
    '; - - $this->ctrl->setParameter($this->controller, "set_id", ''); - $this->ctrl->setParameter($this->controller, "path_id", ''); - - return $row; - } - - return $row; -} + private $controller; + + public function __construct($controller, $plugin, $path_id) + { + global $DIC; + $ilCtrl = $DIC->ctrl(); + + $this->ctrl = $ilCtrl; + $this->controller = $controller; + $this->setId("xqsp_nodes_" . $plugin->getId() . '_' . $path_id); + + parent::__construct($controller, "ilQuestionSetPoolNodesGUI.listNodes", $plugin); + + $this->createTable(); + } + + private function createTable() + { + $this->setTitle($this->plugin->txt('nodes')); + + $this->setFormName("paths"); + $this->setStyle('table', 'fullwidth'); + + $this->addColumn($this->plugin->txt('index'), '', true, '1%'); + $this->addColumn($this->lng->txt('question'), '', '400px'); + $this->addColumn($this->plugin->txt('initial_condition')); + $this->addColumn($this->plugin->txt('jump_conditions')); + $this->addColumn($this->plugin->txt('dominant_scoring')); + $this->addColumn($this->plugin->txt('actions'), '', '1%'); + + /*$this->setSelectAllCheckbox('n_id');*/ + + $this->setRowTemplate('tpl.il_xqsp_node_row.html', $this->controller->plugin->getDirectory()); + $this->ctrl->setParameter($this->controller, "path_id", $_GET['path_id']); + $this->ctrl->setParameter($this->controller, "set_id", $_GET['set_id']); + $this->setFormAction($this->ctrl->getFormAction($this->controller)); + $this->ctrl->setParameter($this->controller, "path_id", ""); + $this->ctrl->setParameter($this->controller, "set_id", ""); + $this->setDefaultOrderField("title"); + $this->setDefaultOrderDirection("asc"); + + $this->enable("sort"); + $this->enable("header"); + /*$this->enable("select_all");*/ + } + + + /** + * Return an array of all static (always visible) data fields in a row. + * For each key there has to be a variable name VAL_ in your defined row template. + * Example: + * return array('title', 'checkbox'); + * There have to be two template variables: VAL_TITLE and VAL_CHECKBOX + * @return array + */ + protected function getStaticData() + { + return array( + "node_index", + "question_title", + "question_index", + "initial_condition", + "jump_conditions", + "dominant_scoring", + "actions" + ); + } + + protected function formatCellValue($column, array $row) + { + switch ($column) { + case "question_title": + $this->ctrl->setParameter($this->parent_obj, "q_id", $row["question_fi"]); + $this->ctrl->setParameter($this->parent_obj, "set_id", $row["set_fi"]); + $this->ctrl->setParameter($this->parent_obj, "path_id", $row["path_fi"]); + $row['question_title'] = '' . $row['question_title'] . ''; + $this->ctrl->setParameter($this->parent_obj, "q_id", ""); + $this->ctrl->setParameter($this->parent_obj, "set_id", ""); + $this->ctrl->setParameter($this->parent_obj, "path_id", ""); + break; + case "node_index": + $sort = new ilNumberInputGUI('', 'sorting[' . $row['id'] . ']'); + $sort->allowDecimals(false); + $sort->setSize(3); + $sort->setValue($row[$column]); + if ($row[$column] == 1) { + $sort->setDisabled(true); + } + $row[$column] = $sort->render(); + break; + case "dominant_scoring": + $number = new ilNumberInputGUI("", $column . "[" . $row['id'] . "]"); + $number->allowDecimals(false); + $number->setSize(3); + $number->setValue($row[$column]); + $row[$column] = $number->render(); + break; + case "initial_condition": + $row = $this->renderInitialCondition($row); + break; + case "actions": + $action = new ilAdvancedSelectionListGUI(); + $action->setId('asl_' . $row["id"]); + $action->setListTitle($this->lng->txt('actions')); + + $this->ctrl->setParameter($this->controller, "set_id", $row["set_fi"]); + $this->ctrl->setParameter($this->controller, "path_id", $row["path_fi"]); + + $this->ctrl->setParameter($this->controller, "node_id", $row['id']); + if (!$row["initial_condition"]) { + $action->addItem($this->plugin->txt("add_initial_condition"), '', $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolInitialConditionGUI.edit")); + } else { + $action->addItem($this->plugin->txt("edit_initial_condition"), '', $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolInitialConditionGUI.edit")); + } + $this->ctrl->setParameter($this->controller, "node_id", ""); + + $this->ctrl->setParameter($this->controller, "node_fi", $row['id']); + $this->ctrl->setParameter($this->controller, "condition_id", $row['condition_id']); + $action->addItem($this->plugin->txt("jump_condition_add"), '', $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolJumpConditionGUI.edit")); + $this->ctrl->setParameter($this->controller, "condition_id", ""); + $this->ctrl->setParameter($this->controller, "node_fi", ""); + + $this->ctrl->setParameter($this->controller, 'node_id', $row['id']); + $action->addItem($this->lng->txt("delete"), '', $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolNodeGUI.removeConfirmation")); + $this->ctrl->setParameter($this->controller, "node_id", ""); + + $this->ctrl->setParameter($this->controller, "set_id", ''); + $this->ctrl->setParameter($this->controller, "path_id", ''); + + $row["actions"] = $action->getHtml(); + break; + case "jump_conditions": + $row = $this->renderJumpConditions($row); + break; + } + return parent::formatCellValue($column, $row); + } + + /** + * @param array $row + * + * @return array + */ + protected function renderJumpConditions(array $row) + { + require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/classes/models/class.ilQuestionSetPoolNode.php"; + $model = new ilQuestionSetPoolNode($row["id"]); + $model->read(); + $row["jump_conditions"] = $model->getJumpConditionList()->getData(); + + $this->ctrl->setParameter($this->controller, "set_id", $row["set_fi"]); + $this->ctrl->setParameter($this->controller, "path_id", $row["path_fi"]); + + $conditions = '
      '; + foreach ($row['jump_conditions'] as $key => $condition) { + $this->ctrl->setParameter($this->controller, "condition_id", $condition['id']); + $edit = $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolJumpConditionGUI.edit"); + $remove = $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolJumpConditionGUI.remove"); + $up = $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolJumpConditionGUI.up"); + $down = $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolJumpConditionGUI.down"); + $this->ctrl->setParameter($this->controller, "condition_id", ""); + + $conditions .= "
    • "; + if ($key != 0) { + $conditions .= ' '; + } else { + $conditions .= ' '; + } + + $conditions .= $condition['jump_condition'] . " - "; + if ($condition["question_index"] != null) { + $conditions .= $this->plugin->txt("target_question") . ": "; + $conditions .= "Q" . $condition["question_index"]; + } else { + $conditions .= $this->plugin->txt("tst_termination"); + } + + $action = new ilAdvancedSelectionListGUI(); + $action->setId('asl_jump_' . $condition["id"]); + $action->setListTitle(''); + $action->addItem($this->plugin->txt("jump_condition_edit"), '', $edit); + $action->addItem($this->plugin->txt("jump_condition_delete"), '', $remove); + + $conditions .= $action->getHTML(); + $conditions .= "
      "; + + if (is_array($row['jump_conditions'])) { + if ($key != count($row["jump_conditions"]) - 1) { + $conditions .= ' '; + } else { + $conditions .= ' '; + } + } + + if ($condition["repititions"] == null) { + $condition["repititions"] = $this->plugin->txt("endless_repititions"); + } + + $conditions .= $this->plugin->txt("repititions") . ": " . $condition["repititions"]; + $conditions .= "
    • "; + } + if (is_array($row['jump_conditions']) && count($row['jump_conditions'])) { + $row['jump_conditions'] = $conditions; + } else { + $row['jump_conditions'] = ""; + } + + $this->ctrl->setParameter($this->controller, "set_id", ''); + $this->ctrl->setParameter($this->controller, "path_id", ''); + + return $row; + } + + /** + * @param array $row + * @return array + */ + protected function renderInitialCondition(array $row) + { + if ($row["initial_condition"] != null) { + $this->ctrl->setParameter($this->controller, "set_id", $row["set_fi"]); + $this->ctrl->setParameter($this->controller, "path_id", $row["path_fi"]); + + $this->ctrl->setParameter($this->controller, "node_id", $row['id']); + $edit = $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolInitialConditionGUI.edit"); + $this->ctrl->setParameter($this->controller, "node_id", ""); + + $this->ctrl->setParameter($this->controller, "node_id", $row['id']); + $remove = $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolInitialConditionGUI.remove"); + $this->ctrl->setParameter($this->controller, "node_id", ""); + + $action = new ilAdvancedSelectionListGUI(); + $action->setId('asl_init_' . $row["id"]); + $action->setListTitle(''); + + $action->addItem($this->plugin->txt("edit_initial_condition"), '', $edit); + $action->addItem($this->plugin->txt("remove_initial_condition"), '', $remove); + + $row["initial_condition"] = '
      • ' . $row["initial_condition"] . $action->getHTML() . '
      '; + + $this->ctrl->setParameter($this->controller, "set_id", ''); + $this->ctrl->setParameter($this->controller, "path_id", ''); + + return $row; + } + + return $row; + } } - \ No newline at end of file diff --git a/classes/tables/class.ilQuestionSetPoolPathTableGUI.php b/classes/tables/class.ilQuestionSetPoolPathTableGUI.php index 9dd1a36e06ae8962635eca5506791022fe9d950a..88630aebd69fc769eb8a8e87e3b50febaac28928 100644 --- a/classes/tables/class.ilQuestionSetPoolPathTableGUI.php +++ b/classes/tables/class.ilQuestionSetPoolPathTableGUI.php @@ -1,8 +1,6 @@ - */ + */ class ilQuestionSetPoolPathTableGUI extends ilPluginTableGUI { - - private $controller; - - public function __construct($controller, $plugin, $set_id) - { - global $DIC; - - $this->ctrl = $DIC->ctrl(); - $this->controller = $controller; - $this->setId("xqsp_paths_".$plugin->getId().'_'.$set_id); - - parent::__construct($controller, "", $plugin); - - $this->createTable(); - } - - private function createTable() - { - $this->setTitle($this->plugin->txt('paths')); - - $this->setFormName("paths"); - $this->setStyle('table', 'fullwidth'); - $this->addColumn('', '', '1%', true); - $this->addColumn($this->plugin->txt('index'), '', true, '1%'); - $this->addColumn($this->lng->txt('title')); - $this->addColumn($this->lng->txt('actions'), '', '1%'); - - $this->setSelectAllCheckbox('path_id'); - - $this->setRowTemplate('tpl.il_xqsp_path_row.html', $this->controller->plugin->getDirectory()); - $this->setFormAction($this->ctrl->getFormAction($this->parent_obj)); - $this->setDefaultOrderField("path_index"); - $this->setDefaultOrderDirection("asc"); - - $this->addMultiCommand('ilQuestionSetPoolPathsGUI.removeMultipleConfirmation', $this->lng->txt('delete')); - $this->addMultiCommand('ilQuestionSetPoolPathsGUI.copy', $this->lng->txt('copy')); - - //$this->enable('sort'); - $this->disable("sort"); - $this->enable('header'); - $this->enable('select_all'); - } - - - /** - * Return an array of all static (always visible) data fields in a row. - * For each key there has to be a variable name VAL_ in your defined row template. - * Example: - * return array('title', 'checkbox'); - * There have to be two template variables: VAL_TITLE and VAL_CHECKBOX - * @return array - */ - protected function getStaticData() - { - return array( - 'path_index', - 'checkbox', - 'title_link', - 'title', - 'actions' - ); - } - - protected function formatCellValue($column, array $row) - { - - if($column == "path_index") - { - $sort = new ilNumberInputGUI('', 'sorting[' . $row['id'] . ']'); - $sort->allowDecimals(false); - $sort->setSize(3); - $sort->setValue($row[$column]); - $row[$column] = $sort->render(); - } - if($column == "checkbox") - { - $row[$column] = ilUtil::formCheckbox(false, 'path_id[]', $row['id']); - } - if($column == "title_link") - { - $this->ctrl->setParameter($this->controller, "path_id", $row['id']); - $this->ctrl->setParameter($this->controller, "set_id", $row['questionset_fi']); - $href = $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolNodesGUI.listNodes"); - $this->ctrl->setParameter($this->controller, "path_id", ""); - $this->ctrl->setParameter($this->controller, "set_id", $row['questionset_fi']); - $row[$column] = $href; - } - else if('actions' == $column) - { - $action = new ilAdvancedSelectionListGUI(); - $action->setId('asl_'.$row["id"]); - $action->setListTitle($this->lng->txt('actions')); - - $this->ctrl->setParameter($this->controller, "path_id", $row['id']); - $this->ctrl->setParameter($this->controller, "set_id", $row['questionset_fi']); - $action->addItem($this->lng->txt("edit"), '', $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolPathGUI.edit")); - $action->addItem($this->plugin->txt("show_nodes"), '', $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolNodesGUI.listNodes")); - $action->addItem($this->lng->txt("delete"), '', $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolPathsGUI.removeConfirmation")); - $this->ctrl->setParameter($this->controller, "path_id", ""); - $this->ctrl->setParameter($this->controller, "set_id", $row['questionset_fi']); - - $row["actions"] = $action->getHtml(); - } - - return parent::formatCellValue($column, $row); - } + private $controller; + + public function __construct($controller, $plugin, $set_id) + { + global $DIC; + + $this->ctrl = $DIC->ctrl(); + $this->controller = $controller; + $this->setId("xqsp_paths_" . $plugin->getId() . '_' . $set_id); + + parent::__construct($controller, "", $plugin); + + $this->createTable(); + } + + private function createTable() + { + $this->setTitle($this->plugin->txt('paths')); + + $this->setFormName("paths"); + $this->setStyle('table', 'fullwidth'); + $this->addColumn('', '', '1%', true); + $this->addColumn($this->plugin->txt('index'), '', true, '1%'); + $this->addColumn($this->lng->txt('title')); + $this->addColumn($this->lng->txt('actions'), '', '1%'); + + $this->setSelectAllCheckbox('path_id'); + + $this->setRowTemplate('tpl.il_xqsp_path_row.html', $this->controller->plugin->getDirectory()); + $this->setFormAction($this->ctrl->getFormAction($this->parent_obj)); + $this->setDefaultOrderField("path_index"); + $this->setDefaultOrderDirection("asc"); + + $this->addMultiCommand('ilQuestionSetPoolPathsGUI.removeMultipleConfirmation', $this->lng->txt('delete')); + $this->addMultiCommand('ilQuestionSetPoolPathsGUI.copy', $this->lng->txt('copy')); + + //$this->enable('sort'); + $this->disable("sort"); + $this->enable('header'); + $this->enable('select_all'); + } + + + /** + * Return an array of all static (always visible) data fields in a row. + * For each key there has to be a variable name VAL_ in your defined row template. + * Example: + * return array('title', 'checkbox'); + * There have to be two template variables: VAL_TITLE and VAL_CHECKBOX + * @return array + */ + protected function getStaticData() + { + return array( + 'path_index', + 'checkbox', + 'title_link', + 'title', + 'actions' + ); + } + + protected function formatCellValue($column, array $row) + { + if ($column == "path_index") { + $sort = new ilNumberInputGUI('', 'sorting[' . $row['id'] . ']'); + $sort->allowDecimals(false); + $sort->setSize(3); + $sort->setValue($row[$column]); + $row[$column] = $sort->render(); + } + if ($column == "checkbox") { + $row[$column] = ilUtil::formCheckbox(false, 'path_id[]', $row['id']); + } + if ($column == "title_link") { + $this->ctrl->setParameter($this->controller, "path_id", $row['id']); + $this->ctrl->setParameter($this->controller, "set_id", $row['questionset_fi']); + $href = $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolNodesGUI.listNodes"); + $this->ctrl->setParameter($this->controller, "path_id", ""); + $this->ctrl->setParameter($this->controller, "set_id", $row['questionset_fi']); + $row[$column] = $href; + } elseif ('actions' == $column) { + $action = new ilAdvancedSelectionListGUI(); + $action->setId('asl_' . $row["id"]); + $action->setListTitle($this->lng->txt('actions')); + + $this->ctrl->setParameter($this->controller, "path_id", $row['id']); + $this->ctrl->setParameter($this->controller, "set_id", $row['questionset_fi']); + $action->addItem($this->lng->txt("edit"), '', $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolPathGUI.edit")); + $action->addItem($this->plugin->txt("show_nodes"), '', $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolNodesGUI.listNodes")); + $action->addItem($this->lng->txt("delete"), '', $this->ctrl->getLinkTarget($this->controller, "ilQuestionSetPoolPathsGUI.removeConfirmation")); + $this->ctrl->setParameter($this->controller, "path_id", ""); + $this->ctrl->setParameter($this->controller, "set_id", $row['questionset_fi']); + + $row["actions"] = $action->getHtml(); + } + + return parent::formatCellValue($column, $row); + } } - \ No newline at end of file diff --git a/classes/tables/class.ilQuestionSetPoolQuestionsTableGUI.php b/classes/tables/class.ilQuestionSetPoolQuestionsTableGUI.php index 8cdd25803fd3dc42563c60b61505be6fe600b3da..fef56a2194c771f4cbc153a1940d1a8daf57c32a 100644 --- a/classes/tables/class.ilQuestionSetPoolQuestionsTableGUI.php +++ b/classes/tables/class.ilQuestionSetPoolQuestionsTableGUI.php @@ -1,9 +1,6 @@ - */ + */ class ilQuestionSetPoolQuestionsTableGUI extends ilPluginTableGUI { - const CONTEXT_BROWSE_QST_TO_LINK = 2; - const CONTEXT_LIST_LINKED_QST_IN_SET = 3; - const CONTEXT_LIST_SET_QST = 4; - - /** - * @var array - */ - protected static $checked_qst_types = array(); - - /** - * @var ilObjQuestionSetPoolGUI - */ - private $controller; - - /** - * @var string - */ - public $gui_class_name = ""; - - /** - * @var int - */ - protected $table_context = self::CONTEXT_BROWSE_QST_TO_LINK; - - /** - * @param ilObjQuestionSetPoolGUI $controller - * @param ilQuestionSetPoolPlugin $plugin - * @param string $action - * @param int $context - * @param int|null $set_id - */ - public function __construct(ilObjQuestionSetPoolGUI $controller, ilQuestionSetPoolPlugin $plugin, $action, $context = self::CONTEXT_BROWSE_QST_TO_LINK, $set_id = null) - { - global $DIC; - - $this->ctrl = $DIC->ctrl(); - $this->controller = $controller; - $this->setTableContext($context); - $this->setId("xqsp_qst_" . $plugin->getId() . ($set_id ? '_' . $set_id : '')); - - parent::__construct($controller, $action, $plugin); - - $this->createTable(); - } - - /** - * @param int $context - */ - public function setTableContext($context) - { - $this->table_context = $context; - } - - /** - * @return int - */ - public function getTableContext() - { - return $this->table_context; - } - - /** - * - */ - private function createTable() - { - $this->setTitle($this->plugin->txt("questionbrowser")); - - $this->setFormName('questionbrowser'); - $this->setStyle('table', 'fullwidth'); - $this->addColumn('', '', '1%', true); - - if($this->getTableContext() == self::CONTEXT_LIST_SET_QST) - { - $this->optionalColumns = array( - "question_index" => "question_index" - ); - $this->visibleOptionalColumns = array( - "question_index" => true - ); - - $this->addColumn($this->plugin->txt("index"), 'index', ''); - $this->setDefaultOrderField("index"); - } - else - { - $this->setDefaultOrderField("title"); - } - $this->addColumn($this->lng->txt("title"), 'title', ''); - $this->addColumn($this->lng->txt("description"), 'description', ''); - $this->addColumn($this->plugin->txt("question_type"), 'type_tag', ''); - $this->addColumn($this->plugin->txt("points"), 'points', ''); - $this->addColumn($this->lng->txt("author"), 'author', ''); - $this->addColumn($this->lng->txt("create_date"), 'created', ''); - $this->addColumn($this->lng->txt("last_update"), 'tstamp', ''); - $this->addColumn($this->plugin->txt("original_question_pool"), 'qpl', ''); - $this->addColumn($this->lng->txt("actions"), '', ''); - - $this->setSelectAllCheckbox('q_id'); - - $this->setRowTemplate("tpl.il_xqsp_questions_row.html", $this->controller->plugin->getDirectory()); - - $this->setFormAction($this->ctrl->getFormAction($this->controller)); - $this->setDefaultOrderDirection("asc"); - - $this->enable('sort'); - $this->enable('header'); - $this->enable('select_all'); - } - - public function setGuiClassName($gui_class_name) - { - $this->gui_class_name = $gui_class_name; - } - /** - * @param string $gui_class_name - */ - public function initFilter() - { - $this->createFilterTextInput("title"); - $this->createFilterTextInput("description"); - $this->createFilterTextInput("author"); - $this->createFilterTextInput("qpl"); - $this->createFilterSelectInput("question_type", $this->pullQuestionTypes()); - - $this->setFilterCommand($this->gui_class_name.'.applyAvailableFilter'); - $this->setResetCommand($this->gui_class_name.'.resetAvailableFilter'); - } - - /** - * @param $caption - */ - private function createFilterTextInput($caption) - { - require_once "./Services/Form/classes/class.ilTextInputGUI.php"; - $input = new ilTextInputGUI($this->lng->txt($caption), $caption); - $input->setMaxLength(64); - $input->setSize(20); - $input->setValidationRegexp('/^[^%]+$/is'); - $this->addFilterItem($input); - $input->readFromSession(); - $this->filter[$caption] = $input->getValue(); - } - - /** - * @param string $caption - * @param array $options - */ - private function createFilterSelectInput($caption, $options) - { - require_once "./Services/Form/classes/class.ilSelectInputGUI.php"; - $si = new ilSelectInputGUI($this->lng->txt($caption), $caption); - $si->setOptions($options); - $this->addFilterItem($si); - $si->readFromSession(); - $this->filter[$caption] = $si->getValue(); - } - - /** - * @return array - */ - private function pullQuestionTypes() - { - require_once "./Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php"; - $types = ilObjQuestionPool::_getQuestionTypes(); - $options = array( - "" => $this->lng->txt('filter_all_question_types') - ); - foreach ($types as $translation => $row) - { - $options[$row['type_tag']] = $translation; - } - - return $options; - } - - /** - * Return an array of all static (always visible) data fields in a row. - * For each key there has to be a variable name VAL_ in your defined row template. - * Example: - * return array('title', 'checkbox'); - * There have to be two template variables: VAL_TITLE and VAL_CHECKBOX - * @return array - */ - protected function getStaticData() - { - return array( - 'title', - "description", - "author", - "type_tag", - "points", - "question_id", - "tstamp", - "created", - "pool_title", - "actions" - ); - } - - function numericOrdering($a_field) - { - return in_array($a_field, array( - "points", "tstamp", "created" - )); - } - - - /** - * Define a final formatting for a cell value - * - * @param mixed $column - * @param array $row - * - * @return mixed - */ - protected function formatCellValue($column, array $row) - { - if ($column == "tstamp" || $column == "created") - { - return ilDatePresentation::formatDate(new ilDateTime($row[$column], IL_CAL_UNIX)); - } - else if ($column == "type_tag") - { - require_once "./Modules/TestQuestionPool/classes/class.assQuestion.php"; - - return assQuestion::_getQuestionTypeName($row[$column]); - } - else if($column == "actions") - { - $action = new ilAdvancedSelectionListGUI(); - $action->setId('asl_'.$row["question_id"]); - $action->setListTitle($this->lng->txt('actions')); - - $this->ctrl->setParameter($this->parent_obj, "q_id", $row["question_id"]); - if(in_array($this->getTableContext(), array(self::CONTEXT_LIST_LINKED_QST_IN_SET, self::CONTEXT_BROWSE_QST_TO_LINK))) - { - $this->ctrl->setParameter($this->parent_obj, "referer", 'browse'); - } - - if($this->getTableContext() == self::CONTEXT_LIST_LINKED_QST_IN_SET) - { - $action->addItem($this->lng->txt("preview"), '', $this->ctrl->getLinkTarget($this->parent_obj, "ilQuestionSetPoolSetQuestionsGUI.showQuestionPreview")); - } - $this->ctrl->setParameter($this->parent_obj, "q_id", ""); - - $this->ctrl->setParameterByClass('ilObjQuestionPoolGUI', 'ref_id', $row["pool_ref_id"]); - $this->ctrl->setParameterByClass('ilObjQuestionPoolGUI', 'q_id', $row["question_id"]); - $action->addItem( - $this->plugin->txt("edit_original_question"), - '', - $this->ctrl->getLinkTargetByClass('ilObjQuestionPoolGUI', "editQuestionForTest"), - '', - '', - '_blank' - ); - $this->ctrl->setParameterByClass('ilObjQuestionPoolGUI', 'ref_id', ''); - $this->ctrl->setParameterByClass('ilObjQuestionPoolGUI', 'q_id', ''); - - $action->addItem( - $this->plugin->txt("to_original_question_pool"), - '', - 'goto.php?target=qpl_'.$row["pool_ref_id"].'&client_id='.CLIENT_ID, - '', - '', - '_blank' - ); - - $row["actions"] = $action->getHTML(); - } - - return parent::formatCellValue($column, $row); - } - - /** - * @param array $data - */ - protected function prepareData(array &$data) - { - $t0 = microtime(true); - foreach($data as $key => $item) - { - if(!is_array($item)) - { - $data[$key] = $item->toArray(); - } - - $tag = $data[$key]['type_tag']; - $is_plugin = $data[$key]['plugin']; - - if( - isset(self::$checked_qst_types[$tag]) && - self::$checked_qst_types[$tag] === false - ) - { - unset($data[$key]); - continue; - } - else - { - $is_supported = false; - - if( - $is_plugin && - !$this->isPluginActive($tag) - ) - { - self::$checked_qst_types[$tag] = $is_supported; - unset($data[$key]); - continue; - } - - assQuestion::_includeClass($tag); - $reflection = new ReflectionClass($tag); - if($reflection->implementsInterface('iQuestionCondition')) - { - $is_supported = true; - } - - if(!$is_supported) - { - unset($data[$key]); - } - - self::$checked_qst_types[$tag] = $is_supported; - } - } - } - - /** - * Checks wheather or not a question plugin with a given name is active - * - * @param string $a_pname The plugin name - * @access public - */ - private function isPluginActive($a_pname) - { - global $DIC; - $ilPluginAdmin = $DIC['ilPluginAdmin']; - - if($ilPluginAdmin->isActive(IL_COMP_MODULE, "TestQuestionPool", "qst", $a_pname)) - { - return true; - } - else - { - return false; - } - } + const CONTEXT_BROWSE_QST_TO_LINK = 2; + const CONTEXT_LIST_LINKED_QST_IN_SET = 3; + const CONTEXT_LIST_SET_QST = 4; + + /** + * @var array + */ + protected static $checked_qst_types = array(); + + /** + * @var ilObjQuestionSetPoolGUI + */ + private $controller; + + /** + * @var string + */ + public $gui_class_name = ""; + + /** + * @var int + */ + protected $table_context = self::CONTEXT_BROWSE_QST_TO_LINK; + + /** + * @param ilObjQuestionSetPoolGUI $controller + * @param ilQuestionSetPoolPlugin $plugin + * @param string $action + * @param int $context + * @param int|null $set_id + */ + public function __construct(ilObjQuestionSetPoolGUI $controller, ilQuestionSetPoolPlugin $plugin, $action, $context = self::CONTEXT_BROWSE_QST_TO_LINK, $set_id = null) + { + global $DIC; + + $this->ctrl = $DIC->ctrl(); + $this->controller = $controller; + $this->setTableContext($context); + $this->setId("xqsp_qst_" . $plugin->getId() . ($set_id ? '_' . $set_id : '')); + + parent::__construct($controller, $action, $plugin); + + $this->createTable(); + } + + /** + * @param int $context + */ + public function setTableContext($context) + { + $this->table_context = $context; + } + + /** + * @return int + */ + public function getTableContext() + { + return $this->table_context; + } + + /** + * + */ + private function createTable() + { + $this->setTitle($this->plugin->txt("questionbrowser")); + + $this->setFormName('questionbrowser'); + $this->setStyle('table', 'fullwidth'); + $this->addColumn('', '', '1%', true); + + if ($this->getTableContext() == self::CONTEXT_LIST_SET_QST) { + $this->optionalColumns = array( + "question_index" => "question_index" + ); + $this->visibleOptionalColumns = array( + "question_index" => true + ); + + $this->addColumn($this->plugin->txt("index"), 'index', ''); + $this->setDefaultOrderField("index"); + } else { + $this->setDefaultOrderField("title"); + } + $this->addColumn($this->lng->txt("title"), 'title', ''); + $this->addColumn($this->lng->txt("description"), 'description', ''); + $this->addColumn($this->plugin->txt("question_type"), 'type_tag', ''); + $this->addColumn($this->plugin->txt("points"), 'points', ''); + $this->addColumn($this->lng->txt("author"), 'author', ''); + $this->addColumn($this->lng->txt("create_date"), 'created', ''); + $this->addColumn($this->lng->txt("last_update"), 'tstamp', ''); + $this->addColumn($this->plugin->txt("original_question_pool"), 'qpl', ''); + $this->addColumn($this->lng->txt("actions"), '', ''); + + $this->setSelectAllCheckbox('q_id'); + + $this->setRowTemplate("tpl.il_xqsp_questions_row.html", $this->controller->plugin->getDirectory()); + + $this->setFormAction($this->ctrl->getFormAction($this->controller)); + $this->setDefaultOrderDirection("asc"); + + $this->enable('sort'); + $this->enable('header'); + $this->enable('select_all'); + } + + public function setGuiClassName($gui_class_name) + { + $this->gui_class_name = $gui_class_name; + } + /** + * @param string $gui_class_name + */ + public function initFilter() + { + $this->createFilterTextInput("title"); + $this->createFilterTextInput("description"); + $this->createFilterTextInput("author"); + $this->createFilterTextInput("qpl"); + $this->createFilterSelectInput("question_type", $this->pullQuestionTypes()); + + $this->setFilterCommand($this->gui_class_name . '.applyAvailableFilter'); + $this->setResetCommand($this->gui_class_name . '.resetAvailableFilter'); + } + + /** + * @param $caption + */ + private function createFilterTextInput($caption) + { + $input = new ilTextInputGUI($this->lng->txt($caption), $caption); + $input->setMaxLength(64); + $input->setSize(20); + $input->setValidationRegexp('/^[^%]+$/is'); + $this->addFilterItem($input); + $input->readFromSession(); + $this->filter[$caption] = $input->getValue(); + } + + /** + * @param string $caption + * @param array $options + */ + private function createFilterSelectInput($caption, $options) + { + $si = new ilSelectInputGUI($this->lng->txt($caption), $caption); + $si->setOptions($options); + $this->addFilterItem($si); + $si->readFromSession(); + $this->filter[$caption] = $si->getValue(); + } + + /** + * @return array + */ + private function pullQuestionTypes() + { + $types = ilObjQuestionPool::_getQuestionTypes(); + $options = array( + "" => $this->lng->txt('filter_all_question_types') + ); + foreach ($types as $translation => $row) { + $options[$row['type_tag']] = $translation; + } + + return $options; + } + + /** + * Return an array of all static (always visible) data fields in a row. + * For each key there has to be a variable name VAL_ in your defined row template. + * Example: + * return array('title', 'checkbox'); + * There have to be two template variables: VAL_TITLE and VAL_CHECKBOX + * @return array + */ + protected function getStaticData() + { + return array( + 'title', + "description", + "author", + "type_tag", + "points", + "question_id", + "tstamp", + "created", + "pool_title", + "actions" + ); + } + + public function numericOrdering($a_field) + { + return in_array($a_field, array( + "points", "tstamp", "created" + )); + } + + + /** + * Define a final formatting for a cell value + * + * @param mixed $column + * @param array $row + * + * @return mixed + */ + protected function formatCellValue($column, array $row) + { + if ($column == "tstamp" || $column == "created") { + return ilDatePresentation::formatDate(new ilDateTime($row[$column], IL_CAL_UNIX)); + } elseif ($column == "type_tag") { + return assQuestion::_getQuestionTypeName($row[$column]); + } elseif ($column == "actions") { + $action = new ilAdvancedSelectionListGUI(); + $action->setId('asl_' . $row["question_id"]); + $action->setListTitle($this->lng->txt('actions')); + + $this->ctrl->setParameter($this->parent_obj, "q_id", $row["question_id"]); + if (in_array($this->getTableContext(), array(self::CONTEXT_LIST_LINKED_QST_IN_SET, self::CONTEXT_BROWSE_QST_TO_LINK))) { + $this->ctrl->setParameter($this->parent_obj, "referer", 'browse'); + } + + if ($this->getTableContext() == self::CONTEXT_LIST_LINKED_QST_IN_SET) { + $action->addItem($this->lng->txt("preview"), '', $this->ctrl->getLinkTarget($this->parent_obj, "ilQuestionSetPoolSetQuestionsGUI.showQuestionPreview")); + } + $this->ctrl->setParameter($this->parent_obj, "q_id", ""); + + $this->ctrl->setParameterByClass('ilObjQuestionPoolGUI', 'ref_id', $row["pool_ref_id"]); + $this->ctrl->setParameterByClass('ilObjQuestionPoolGUI', 'q_id', $row["question_id"]); + $action->addItem( + $this->plugin->txt("edit_original_question"), + '', + $this->ctrl->getLinkTargetByClass('ilObjQuestionPoolGUI', "editQuestionForTest"), + '', + '', + '_blank' + ); + $this->ctrl->setParameterByClass('ilObjQuestionPoolGUI', 'ref_id', ''); + $this->ctrl->setParameterByClass('ilObjQuestionPoolGUI', 'q_id', ''); + + $action->addItem( + $this->plugin->txt("to_original_question_pool"), + '', + 'goto.php?target=qpl_' . $row["pool_ref_id"] . '&client_id=' . CLIENT_ID, + '', + '', + '_blank' + ); + + $row["actions"] = $action->getHTML(); + } + + return parent::formatCellValue($column, $row); + } + + /** + * @param array $data + */ + protected function prepareData(array &$data) + { + $t0 = microtime(true); + foreach ($data as $key => $item) { + if (!is_array($item)) { + $data[$key] = $item->toArray(); + } + + $tag = $data[$key]['type_tag']; + $is_plugin = $data[$key]['plugin']; + + if ( + isset(self::$checked_qst_types[$tag]) && + self::$checked_qst_types[$tag] === false + ) { + unset($data[$key]); + continue; + } else { + $is_supported = false; + + if ( + $is_plugin && + !$this->isPluginActive($tag) + ) { + self::$checked_qst_types[$tag] = $is_supported; + unset($data[$key]); + continue; + } + + assQuestion::_includeClass($tag); + $reflection = new ReflectionClass($tag); + if ($reflection->implementsInterface('iQuestionCondition')) { + $is_supported = true; + } + + if (!$is_supported) { + unset($data[$key]); + } + + self::$checked_qst_types[$tag] = $is_supported; + } + } + } + + /** + * Checks wheather or not a question plugin with a given name is active + * + * @param string $a_pname The plugin name + * @access public + */ + private function isPluginActive($a_pname) + { + global $DIC; + $ilPluginAdmin = $DIC['ilPluginAdmin']; + + if ($ilPluginAdmin->isActive(IL_COMP_MODULE, "TestQuestionPool", "qst", $a_pname)) { + return true; + } else { + return false; + } + } } diff --git a/classes/tables/class.ilQuestionSetPoolSetQuestionsTableGUI.php b/classes/tables/class.ilQuestionSetPoolSetQuestionsTableGUI.php index 3530e1b9dd87850a7e5ccb28b12a1a5038859bcb..95b28456381db713712e3593e71f39d0193940b3 100644 --- a/classes/tables/class.ilQuestionSetPoolSetQuestionsTableGUI.php +++ b/classes/tables/class.ilQuestionSetPoolSetQuestionsTableGUI.php @@ -1,7 +1,6 @@ - */ + */ class ilQuestionSetPoolSetQuestionsTableGUI extends ilQuestionSetPoolQuestionsTableGUI { - /** - * Define a final formatting for a cell value - * - * @param mixed $column - * @param array $row - * - * @return mixed - */ - protected function formatCellValue($column, array $row) - { - if ($column == "tstamp" || $column == "created") - { - return ilDatePresentation::formatDate(new ilDateTime($row[$column], IL_CAL_UNIX)); - } - else if ($column == "type_tag") - { - require_once "./Modules/TestQuestionPool/classes/class.assQuestion.php"; + /** + * Define a final formatting for a cell value + * + * @param mixed $column + * @param array $row + * + * @return mixed + */ + protected function formatCellValue($column, array $row) + { + if ($column == "tstamp" || $column == "created") { + return ilDatePresentation::formatDate(new ilDateTime($row[$column], IL_CAL_UNIX)); + } elseif ($column == "type_tag") { + return assQuestion::_getQuestionTypeName($row[$column]); + } elseif ($column == "title") { + $this->ctrl->setParameter($this->parent_obj, "q_id", $row["question_id"]); + $row['title'] = '' . $row['title'] . ''; + $this->ctrl->setParameter($this->parent_obj, "q_id", ""); + } elseif ($column == "actions" && !strlen($row[$column])) { + $action = new ilAdvancedSelectionListGUI(); + $action->setId('asl_' . (int) $row["question_id"]); + $action->setListTitle($this->lng->txt('actions')); - return assQuestion::_getQuestionTypeName($row[$column]); - } - else if ($column == "title") - { - $this->ctrl->setParameter($this->parent_obj, "q_id", $row["question_id"]); - $row['title'] = '' . $row['title'] . ''; - $this->ctrl->setParameter($this->parent_obj, "q_id", ""); - } - else if($column == "actions" && !strlen($row[$column])) - { - $action = new ilAdvancedSelectionListGUI(); - $action->setId('asl_'.(int)$row["question_id"]); - $action->setListTitle($this->lng->txt('actions')); + $this->ctrl->setParameter($this->parent_obj, "q_id", $row["question_id"]); + $action->addItem($this->plugin->txt('edit_question'), '', $this->ctrl->getLinkTarget($this->parent_obj, "ilQuestionSetPoolSetQuestionsGUI.editQuestion")); + $action->addItem($this->lng->txt("preview"), '', $this->ctrl->getLinkTarget($this->parent_obj, "ilQuestionSetPoolSetQuestionsGUI.showQuestionPreview")); + $action->addItem($this->lng->txt("delete"), '', $this->ctrl->getLinkTarget($this->parent_obj, "ilQuestionSetPoolSetQuestionsGUI.removeConfirmation")); + $this->ctrl->setParameter($this->parent_obj, "q_id", ""); - $this->ctrl->setParameter($this->parent_obj, "q_id", $row["question_id"]); - $action->addItem($this->plugin->txt('edit_question'), '', $this->ctrl->getLinkTarget($this->parent_obj, "ilQuestionSetPoolSetQuestionsGUI.editQuestion")); - $action->addItem($this->lng->txt("preview"), '', $this->ctrl->getLinkTarget($this->parent_obj, "ilQuestionSetPoolSetQuestionsGUI.showQuestionPreview")); - $action->addItem($this->lng->txt("delete"), '', $this->ctrl->getLinkTarget($this->parent_obj, "ilQuestionSetPoolSetQuestionsGUI.removeConfirmation")); - $this->ctrl->setParameter($this->parent_obj, "q_id", ""); + $row["actions"] = $action->getHTML(); + } - $row["actions"] = $action->getHTML(); - } - - return $row[$column]; - } + return $row[$column]; + } } - \ No newline at end of file diff --git a/classes/tables/class.ilQuestionSetPoolSetsTableGUI.php b/classes/tables/class.ilQuestionSetPoolSetsTableGUI.php index c0ee9262dde675ae58d66644676f2b0082f9d011..b7d348c1d46191a66ef4cb17c9ce14c38910fd94 100644 --- a/classes/tables/class.ilQuestionSetPoolSetsTableGUI.php +++ b/classes/tables/class.ilQuestionSetPoolSetsTableGUI.php @@ -1,7 +1,6 @@ - */ + */ class ilQuestionSetPoolSetsTableGUI extends ilPluginTableGUI { - - public function __construct($controller, $plugin) - { - global $DIC; - - $this->ctrl = $DIC->ctrl(); - $this->setId("xqsp_sets_".$plugin->getId()); - - parent::__construct($controller, "", $plugin); - - $this->createTable(); - } - - private function createTable() - { - $this->setTitle($this->plugin->txt("setsbrowser")); - - $this->setFormName('setsbrowser'); - $this->setStyle('table', 'fullwidth'); - $this->addColumn('', '', '1%', true); - - $this->addColumn($this->lng->txt("title"), 'title', ''); - $this->addColumn($this->lng->txt("description"), 'description', ''); - $this->addColumn($this->lng->txt("actions"), '', '1%'); - - $this->setSelectAllCheckbox('set_id'); - - $this->setRowTemplate("tpl.il_xqsp_qs_row.html", $this->parent_obj->plugin->getDirectory()); - - $this->setFormAction($this->ctrl->getFormAction($this->parent_obj)); - $this->setDefaultOrderField("title"); - $this->setDefaultOrderDirection("asc"); - - $this->addMultiCommand('ilQuestionSetPoolSetsGUI.removeMultipleConfirmation', $this->lng->txt('delete')); - - $this->enable('sort'); - $this->enable('header'); - $this->enable('select_all'); - } - - /** - * Return an array of all static (always visible) data fields in a row. - * For each key there has to be a variable name VAL_ in your defined row template. - * Example: - * return array('title', 'checkbox'); - * There have to be two template variables: VAL_TITLE and VAL_CHECKBOX - * @return array - */ - protected function getStaticData() - { - return array( - 'checkbox', - 'title', - 'title_link', - "description", - "author", - "points", - "tstamp", - "created", - "actions" - ); - } - - /** - * Define a final formatting for a cell value - * - * @param mixed $column - * @param array $row - * - * @return mixed - */ - protected function formatCellValue($column, array $row) - { - if($column == "checkbox") - { - $row[$column] = ilUtil::formCheckbox(false, 'set_id[]', $row['id']); - } - if ($column == "tstamp" || $column == "created") - { - return ilDatePresentation::formatDate(new ilDateTime($row[$column], IL_CAL_UNIX)); - } - if($column == "title_link") - { - $this->ctrl->setParameter($this->parent_obj, "set_id", $row['id']); - if($row["has_questions"]) - { - $href = $this->ctrl->getLinkTarget($this->parent_obj, "ilQuestionSetPoolPathsGUI.listPaths"); - } - else - { - $href = $this->ctrl->getLinkTarget($this->parent_obj, "ilQuestionSetPoolSetQuestionsGUI.listQuestions"); - } - - $this->ctrl->setParameter($this->parent_obj, "set_id", ""); - $row[$column] = $href; - } - if($column == 'actions') - { - $action = new ilAdvancedSelectionListGUI(); - $action->setId('asl_'.$row["id"]); - $action->setListTitle($this->lng->txt('actions')); - - $this->ctrl->setParameter($this->parent_obj, "set_id", $row['id']); - $action->addItem($this->plugin->txt("edit"), '', $this->ctrl->getLinkTarget($this->parent_obj, "ilQuestionSetPoolSetGUI.edit")); - if($row["has_questions"]) - { - $action->addItem($this->plugin->txt("show_added_questions"), '', $this->ctrl->getLinkTarget($this->parent_obj, "ilQuestionSetPoolSetQuestionsGUI.listQuestions")); - $action->addItem($this->plugin->txt("path_overview"), '', $this->ctrl->getLinkTarget($this->parent_obj, "ilQuestionSetPoolPathGraphGUI.showPathOverview")); - } - else - { - $action->addItem($this->plugin->txt("add_questions"), '', $this->ctrl->getLinkTarget($this->parent_obj, "ilQuestionSetPoolSetQuestionsGUI.browseForQuestions")); - } - $action->addItem($this->lng->txt("delete"), '', $this->ctrl->getLinkTarget($this->parent_obj, "ilQuestionSetPoolSetsGUI.removeConfirmation")); - $this->ctrl->setParameter($this->parent_obj, "set_id", ""); - - $row["actions"] = $action->getHTML(); - } - - return parent::formatCellValue($column, $row); - } + public function __construct($controller, $plugin) + { + global $DIC; + + $this->ctrl = $DIC->ctrl(); + $this->setId("xqsp_sets_" . $plugin->getId()); + + parent::__construct($controller, "", $plugin); + + $this->createTable(); + } + + private function createTable() + { + $this->setTitle($this->plugin->txt("setsbrowser")); + + $this->setFormName('setsbrowser'); + $this->setStyle('table', 'fullwidth'); + $this->addColumn('', '', '1%', true); + + $this->addColumn($this->lng->txt("title"), 'title', ''); + $this->addColumn($this->lng->txt("description"), 'description', ''); + $this->addColumn($this->lng->txt("actions"), '', '1%'); + + $this->setSelectAllCheckbox('set_id'); + + $this->setRowTemplate("tpl.il_xqsp_qs_row.html", $this->parent_obj->plugin->getDirectory()); + + $this->setFormAction($this->ctrl->getFormAction($this->parent_obj)); + $this->setDefaultOrderField("title"); + $this->setDefaultOrderDirection("asc"); + + $this->addMultiCommand('ilQuestionSetPoolSetsGUI.removeMultipleConfirmation', $this->lng->txt('delete')); + + $this->enable('sort'); + $this->enable('header'); + $this->enable('select_all'); + } + + /** + * Return an array of all static (always visible) data fields in a row. + * For each key there has to be a variable name VAL_ in your defined row template. + * Example: + * return array('title', 'checkbox'); + * There have to be two template variables: VAL_TITLE and VAL_CHECKBOX + * @return array + */ + protected function getStaticData() + { + return array( + 'checkbox', + 'title', + 'title_link', + "description", + "author", + "points", + "tstamp", + "created", + "actions" + ); + } + + /** + * Define a final formatting for a cell value + * + * @param mixed $column + * @param array $row + * + * @return mixed + */ + protected function formatCellValue($column, array $row) + { + if ($column == "checkbox") { + $row[$column] = ilUtil::formCheckbox(false, 'set_id[]', $row['id']); + } + if ($column == "tstamp" || $column == "created") { + return ilDatePresentation::formatDate(new ilDateTime($row[$column], IL_CAL_UNIX)); + } + if ($column == "title_link") { + $this->ctrl->setParameter($this->parent_obj, "set_id", $row['id']); + if ($row["has_questions"]) { + $href = $this->ctrl->getLinkTarget($this->parent_obj, "ilQuestionSetPoolPathsGUI.listPaths"); + } else { + $href = $this->ctrl->getLinkTarget($this->parent_obj, "ilQuestionSetPoolSetQuestionsGUI.listQuestions"); + } + + $this->ctrl->setParameter($this->parent_obj, "set_id", ""); + $row[$column] = $href; + } + if ($column == 'actions') { + $action = new ilAdvancedSelectionListGUI(); + $action->setId('asl_' . $row["id"]); + $action->setListTitle($this->lng->txt('actions')); + + $this->ctrl->setParameter($this->parent_obj, "set_id", $row['id']); + $action->addItem($this->plugin->txt("edit"), '', $this->ctrl->getLinkTarget($this->parent_obj, "ilQuestionSetPoolSetGUI.edit")); + if ($row["has_questions"]) { + $action->addItem($this->plugin->txt("show_added_questions"), '', $this->ctrl->getLinkTarget($this->parent_obj, "ilQuestionSetPoolSetQuestionsGUI.listQuestions")); + $action->addItem($this->plugin->txt("path_overview"), '', $this->ctrl->getLinkTarget($this->parent_obj, "ilQuestionSetPoolPathGraphGUI.showPathOverview")); + } else { + $action->addItem($this->plugin->txt("add_questions"), '', $this->ctrl->getLinkTarget($this->parent_obj, "ilQuestionSetPoolSetQuestionsGUI.browseForQuestions")); + } + $action->addItem($this->lng->txt("delete"), '', $this->ctrl->getLinkTarget($this->parent_obj, "ilQuestionSetPoolSetsGUI.removeConfirmation")); + $this->ctrl->setParameter($this->parent_obj, "set_id", ""); + + $row["actions"] = $action->getHTML(); + } + + return parent::formatCellValue($column, $row); + } } diff --git a/classes/utils/abstract.ilQuestionSetPoolConditionValidator.php b/classes/utils/abstract.ilQuestionSetPoolConditionValidator.php index ddda67b0370d416a4c0ccd894c9f1555567dc0d8..78c966d8372bbe5f6706ce64d3f49bd60d9cf342 100644 --- a/classes/utils/abstract.ilQuestionSetPoolConditionValidator.php +++ b/classes/utils/abstract.ilQuestionSetPoolConditionValidator.php @@ -21,152 +21,125 @@ require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/ * Date: 05.12.13 * Time: 11:45 * @author Thomas Joußen - */ -abstract class ilQuestionSetPoolConditionValidator { + */ +abstract class ilQuestionSetPoolConditionValidator +{ - /** - * @param string $condition - * @param ilQuestionSetPoolNode $node - * @param array $data - * @param ilPlugin $plugin - * - * @return bool - */ - public static function isValid($condition, $node,$data, $plugin) - { - if($condition == "") - { - return true; - } + /** + * @param string $condition + * @param ilQuestionSetPoolNode $node + * @param array $data + * @param ilPlugin $plugin + * + * @return bool + */ + public static function isValid($condition, $node, $data, $plugin) + { + if ($condition == "") { + return true; + } - try - { - $parser = new ConditionParser(); - $composite = $parser->parse($condition); - $validator = ilQuestionSetPoolConditionValidator::initializeValidator($node, $data); - $validator->validate($composite); - } - catch (QuestionNotExist $e) - { - ilUtil::sendFailure( - sprintf($plugin->txt("question_not_exist"), $e->getQuestionIndex()), - true - ); + try { + $parser = new ConditionParser(); + $composite = $parser->parse($condition); + $validator = ilQuestionSetPoolConditionValidator::initializeValidator($node, $data); + $validator->validate($composite); + } catch (QuestionNotExist $e) { + ilUtil::sendFailure( + sprintf($plugin->txt("question_not_exist"), $e->getQuestionIndex()), + true + ); - return false; - } - catch (QuestionNotReachable $e) - { - ilUtil::sendFailure( - sprintf($plugin->txt("question_not_reachable"), $e->getQuestionIndex()), - true - ); + return false; + } catch (QuestionNotReachable $e) { + ilUtil::sendFailure( + sprintf($plugin->txt("question_not_reachable"), $e->getQuestionIndex()), + true + ); - return false; - } - catch (AnswerIndexNotExist $e) - { - ilUtil::sendFailure( - sprintf($plugin->txt("answer_index_not_exist"), $e->getQuestionIndex(), $e->getAnswerIndex()), - true - ); + return false; + } catch (AnswerIndexNotExist $e) { + ilUtil::sendFailure( + sprintf($plugin->txt("answer_index_not_exist"), $e->getQuestionIndex(), $e->getAnswerIndex()), + true + ); - return false; - } - catch (ExpressionNotSupportedByQuestion $e) - { - ilUtil::sendFailure( - sprintf($plugin->txt("expression_not_supported_by_question"), $e->getQuestionIndex(), $e->getExpression()), - true - ); + return false; + } catch (ExpressionNotSupportedByQuestion $e) { + ilUtil::sendFailure( + sprintf($plugin->txt("expression_not_supported_by_question"), $e->getQuestionIndex(), $e->getExpression()), + true + ); - return false; - } - catch (OperatorNotSupportedByExpression $e) - { - ilUtil::sendFailure( - sprintf($plugin->txt("operator_not_supported_by_expression"), $e->getOperator(), $e->getExpression()), - true - ); + return false; + } catch (OperatorNotSupportedByExpression $e) { + ilUtil::sendFailure( + sprintf($plugin->txt("operator_not_supported_by_expression"), $e->getOperator(), $e->getExpression()), + true + ); - return false; - } - catch (UnsupportedExpression $e) - { - ilUtil::sendFailure( - sprintf($plugin->txt("expression_not_supported"), $e->getExpression()), - true - ); + return false; + } catch (UnsupportedExpression $e) { + ilUtil::sendFailure( + sprintf($plugin->txt("expression_not_supported"), $e->getExpression()), + true + ); - return false; - } - catch (UnsupportedOperation $e) - { - ilUtil::sendFailure( - sprintf($plugin->txt("operator_not_supported"), $e->getOperator()), - true - ); - return false; - } - catch (UnableToParseCondition $e) - { - if($e->getCondition() != "") - { - $condition = $e->getCondition(); - } - ilUtil::sendFailure( - sprintf($plugin->txt("unable_to_parse_condition"), $condition), - true - ); - return false; - } - catch (MissingBracket $e) - { - ilUtil::sendFailure( - sprintf($plugin->txt("missing_bracket"), $e->getBracket()), - true - ); - return false; - } - catch (AnswerValueNotExist $e) - { - ilUtil::sendFailure( - sprintf($plugin->txt("answer_value_not_exists"), $e->getValue(), $e->getQuestionIndex(), $e->getAnswerIndex()), - true - ); - return false; - } - catch (ConditionParserException $e) - { - ilUtil::sendFailure( - sprintf($plugin->txt("invalid_statement"), $e->getColumn()), - true - ); - return false; - } - catch(DuplicateElement $e) - { - ilUtil::sendFailure( - sprintf($plugin->txt("duplicate_element"), $e->getElement()), - true - ); - return false; - } - return true; - } + return false; + } catch (UnsupportedOperation $e) { + ilUtil::sendFailure( + sprintf($plugin->txt("operator_not_supported"), $e->getOperator()), + true + ); + return false; + } catch (UnableToParseCondition $e) { + if ($e->getCondition() != "") { + $condition = $e->getCondition(); + } + ilUtil::sendFailure( + sprintf($plugin->txt("unable_to_parse_condition"), $condition), + true + ); + return false; + } catch (MissingBracket $e) { + ilUtil::sendFailure( + sprintf($plugin->txt("missing_bracket"), $e->getBracket()), + true + ); + return false; + } catch (AnswerValueNotExist $e) { + ilUtil::sendFailure( + sprintf($plugin->txt("answer_value_not_exists"), $e->getValue(), $e->getQuestionIndex(), $e->getAnswerIndex()), + true + ); + return false; + } catch (ConditionParserException $e) { + ilUtil::sendFailure( + sprintf($plugin->txt("invalid_statement"), $e->getColumn()), + true + ); + return false; + } catch (DuplicateElement $e) { + ilUtil::sendFailure( + sprintf($plugin->txt("duplicate_element"), $e->getElement()), + true + ); + return false; + } + return true; + } - /** - * @param ilQuestionSetPoolNode $node - * @oaram array $data - * - * @return CompositeValidator - */ - public static function initializeValidator($node, $data) - { - $provider = new ilParserQuestionProvider($node->getPath()->getSet()->getId()); - $validator = new CompositeValidator($provider, $node, $data); + /** + * @param ilQuestionSetPoolNode $node + * @oaram array $data + * + * @return CompositeValidator + */ + public static function initializeValidator($node, $data) + { + $provider = new ilParserQuestionProvider($node->getPath()->getSet()->getId()); + $validator = new CompositeValidator($provider, $node, $data); - return $validator; - } + return $validator; + } } - \ No newline at end of file diff --git a/classes/utils/abstract.ilQuestionSetPoolInfoBox.php b/classes/utils/abstract.ilQuestionSetPoolInfoBox.php index 927bd6e37d46ea1cc14c8067e936d3d043dd7ff8..2dc70bb86c578bba89496e55b296267c972ced2e 100644 --- a/classes/utils/abstract.ilQuestionSetPoolInfoBox.php +++ b/classes/utils/abstract.ilQuestionSetPoolInfoBox.php @@ -6,42 +6,39 @@ * Date: 05.12.13 * Time: 11:40 * @author Thomas Joußen - */ -abstract class ilQuestionSetPoolInfoBox { + */ +abstract class ilQuestionSetPoolInfoBox +{ - /** - * @param $plugin - * - * @return string - * @internal param \ilQuestionSetPoolNode $model - */ - public static function render($plugin) - { - $template = new ilTemplate("tpl.il_xqsp_sentential_logic.html", true, true, "Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool"); + /** + * @param $plugin + * + * @return string + * @internal param \ilQuestionSetPoolNode $model + */ + public static function render($plugin) + { + $template = new ilTemplate("tpl.il_xqsp_sentential_logic.html", true, true, "Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool"); - $template->setVariable("HEADER", $plugin->txt("info_sentential_logic")); - $template->setVariable("GENERAL_EXPRESSIONS", $plugin->txt("general_expressions")); - $template->setVariable("QUESTION_SPECIFIC_EXPRESSIONS", $plugin->txt("question_specific_expressions")); + $template->setVariable("HEADER", $plugin->txt("info_sentential_logic")); + $template->setVariable("GENERAL_EXPRESSIONS", $plugin->txt("general_expressions")); + $template->setVariable("QUESTION_SPECIFIC_EXPRESSIONS", $plugin->txt("question_specific_expressions")); - $template->setVariable("LOGICAL_AND", $plugin->txt("logical_and")); - $template->setVariable("LOGICAL_OR", $plugin->txt("logical_or")); - $template->setVariable("NEGATION", $plugin->txt("negation")); - $template->setVariable("BRACKETS", $plugin->txt("brackets")); - $template->setVariable("QUESTION_INDEX", $plugin->txt("question_index")); - $template->setVariable("ANSWER_INDEX_OF_QUESTION_INDEX", $plugin->txt("answer_index_of_question_index")); + $template->setVariable("LOGICAL_AND", $plugin->txt("logical_and")); + $template->setVariable("LOGICAL_OR", $plugin->txt("logical_or")); + $template->setVariable("NEGATION", $plugin->txt("negation")); + $template->setVariable("BRACKETS", $plugin->txt("brackets")); + $template->setVariable("QUESTION_INDEX", $plugin->txt("question_index")); + $template->setVariable("ANSWER_INDEX_OF_QUESTION_INDEX", $plugin->txt("answer_index_of_question_index")); - require_once "./Modules/TestQuestionPool/classes/class.ilOperatorsExpressionMapping.php"; + foreach (ilOperatorsExpressionMapping::getAll() as $expression => $operators) { + $template->setCurrentBlock("expression_type"); + $template->setVariable("EXPRESSION", $expression); + $template->setVariable("EXPRESSION_DESCRIPTION", $plugin->txt("expression_type_" . $expression)); + $template->setVariable("OPERATORS", join(", ", $operators)); + $template->parseCurrentBlock(); + } - foreach (ilOperatorsExpressionMapping::getAll() as $expression => $operators) - { - $template->setCurrentBlock("expression_type"); - $template->setVariable("EXPRESSION", $expression); - $template->setVariable("EXPRESSION_DESCRIPTION", $plugin->txt("expression_type_" . $expression)); - $template->setVariable("OPERATORS", join(", ", $operators)); - $template->parseCurrentBlock(); - } - - return $template->get(); - } + return $template->get(); + } } - \ No newline at end of file diff --git a/classes/utils/class.ilConditionInputGUI.php b/classes/utils/class.ilConditionInputGUI.php index ddae32ca02d5388ce71550b39170c7b2d2641e9d..dd7ee66c10c6c13166a54cca1af762e6cccc39fa 100644 --- a/classes/utils/class.ilConditionInputGUI.php +++ b/classes/utils/class.ilConditionInputGUI.php @@ -1,43 +1,35 @@ - */ + */ class ilConditionInputGUI extends ilTextInputGUI { + public function checkInput() + { + global $DIC; + $lng = $DIC->language(); - function checkInput() - { - global $DIC; - $lng = $DIC->language(); - - $_POST[$this->getPostVar()] = ilUtil::stripOnlySlashes($_POST[$this->getPostVar()]); - if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "") - { - $this->setAlert($lng->txt("msg_input_is_required")); + $_POST[$this->getPostVar()] = ilUtil::stripOnlySlashes($_POST[$this->getPostVar()]); + if ($this->getRequired() && trim($_POST[$this->getPostVar()]) == "") { + $this->setAlert($lng->txt("msg_input_is_required")); - return false; - } - else if (strlen($this->getValidationRegexp())) - { - if (!preg_match($this->getValidationRegexp(), $_POST[$this->getPostVar()])) - { - $this->setAlert( - $this->getValidationFailureMessage() ? - $this->getValidationFailureMessage() : - $lng->txt('msg_wrong_format') - ); - return FALSE; - } - } + return false; + } elseif (strlen($this->getValidationRegexp())) { + if (!preg_match($this->getValidationRegexp(), $_POST[$this->getPostVar()])) { + $this->setAlert( + $this->getValidationFailureMessage() ? + $this->getValidationFailureMessage() : + $lng->txt('msg_wrong_format') + ); + return false; + } + } - return $this->checkSubItemsInput(); - } + return $this->checkSubItemsInput(); + } } - \ No newline at end of file diff --git a/classes/utils/class.ilQuestionSetPoolQuestionHeaderBuilder.php b/classes/utils/class.ilQuestionSetPoolQuestionHeaderBuilder.php index c7b41ef2a3f600ed6433f995302dd696403b5bfe..2588aa097d242c01d3cfc4d2b5482bee62ac2c5f 100644 --- a/classes/utils/class.ilQuestionSetPoolQuestionHeaderBuilder.php +++ b/classes/utils/class.ilQuestionSetPoolQuestionHeaderBuilder.php @@ -1,36 +1,33 @@ - */ + */ class ilQuestionSetPoolQuestionHeaderBuilder implements ilQuestionHeaderBlockBuilder { - /** - * @var string - */ - protected $title; + /** + * @var string + */ + protected $title; - /** - * @param string $title - */ - public function __construct($title) - { - $this->title = $title; - } - /** - * Get the HTML representation of the header block - * @return string - */ - public function getHTML() - { - return $this->title; - } + /** + * @param string $title + */ + public function __construct($title) + { + $this->title = $title; + } + /** + * Get the HTML representation of the header block + * @return string + */ + public function getHTML() + { + return $this->title; + } } - \ No newline at end of file diff --git a/classes/utils/class.ilQuestionSetPoolSkillAssQuestionList.php b/classes/utils/class.ilQuestionSetPoolSkillAssQuestionList.php index e89b5f6ad724c2a9baf6f4579e0ace417b37b226..282b32aaf364b5a8db03b6d7f6f4553863cb8646 100644 --- a/classes/utils/class.ilQuestionSetPoolSkillAssQuestionList.php +++ b/classes/utils/class.ilQuestionSetPoolSkillAssQuestionList.php @@ -1,7 +1,5 @@ orderSequence = array(); + /** + * @param ilDBInterface $db + * @param ilLanguage $lng + * @param ilPluginAdmin $pluginAdmin + */ + public function __construct(ilDBInterface $db, ilLanguage $lng, ilPluginAdmin $pluginAdmin) + { + $this->orderSequence = array(); - parent::__construct($db, $lng, $pluginAdmin); - } + parent::__construct($db, $lng, $pluginAdmin); + } - /** - * @param ilPluginTableDatabaseDataProvider $provider - */ - public function setProvider(ilPluginTableDatabaseDataProvider $provider) - { - $this->provider = $provider; - } + /** + * @param ilPluginTableDatabaseDataProvider $provider + */ + public function setProvider(ilPluginTableDatabaseDataProvider $provider) + { + $this->provider = $provider; + } - public function load() - { - parent::load(); + public function load() + { + parent::load(); - $data = $this->provider->loadData(array('questionsetpool_fi' => $this->getParentObjId())); + $data = $this->provider->loadData(array('questionsetpool_fi' => $this->getParentObjId())); - foreach($data as $row) - { - $this->orderSequence[] = $row['question_fi']; - $questionId = $row['question_fi']; - if(array_key_exists($questionId, $this->questions)) - { - $title = $this->questions[$questionId]['title']; - $this->questions[$questionId]['title'] = '(Q'. $row['question_index']. ') '. $title . ' - ' . $row['title']; - } - } - } + foreach ($data as $row) { + $this->orderSequence[] = $row['question_fi']; + $questionId = $row['question_fi']; + if (array_key_exists($questionId, $this->questions)) { + $title = $this->questions[$questionId]['title']; + $this->questions[$questionId]['title'] = '(Q' . $row['question_index'] . ') ' . $title . ' - ' . $row['title']; + } + } + } - /** - * @return array - */ - public function getOrderSequence() - { - return $this->orderSequence; - } -} \ No newline at end of file + /** + * @return array + */ + public function getOrderSequence() + { + return $this->orderSequence; + } +} diff --git a/plugin.php b/plugin.php index 3aa3b7627a886406f5ccd93f06a7eb9d5d28f1fa..006c10b551cd2af4b969a7c62d6810e11e192f90 100755 --- a/plugin.php +++ b/plugin.php @@ -7,10 +7,10 @@ * @author Thomas Joußen */ $id = "xqsp"; -$version = "6.0.0"; +$version = "7.0.0"; -$ilias_min_version = "5.3.0"; -$ilias_max_version = "5.4.999"; +$ilias_min_version = "6.0"; +$ilias_max_version = "6.999"; $responsible = "Thomas Joußen"; $responsible_mail = "tjoussen@databay.de"; diff --git a/sql/dbupdate.php b/sql/dbupdate.php index ce3e3ab78a6383c9d7245e4a8d852b75a7a58678..a6abab58e4747d0fa36ed93082c0f2deae574c10 100755 --- a/sql/dbupdate.php +++ b/sql/dbupdate.php @@ -1,383 +1,370 @@ <#1> tableExists("rep_robj_xqsp_data")) -{ - $fields = array( - 'id' => array( - 'type' => 'integer', - 'length' => '4', - 'notnull' => true - ), - 'is_online' => array( - 'type' => 'integer', - 'length' => '1', - 'notnull' => false - ) - ); - $ilDB->createTable("rep_robj_xqsp_data", $fields); - $ilDB->addPrimaryKey("rep_robj_xqsp_data", array("id")); +if (!$ilDB->tableExists("rep_robj_xqsp_data")) { + $fields = array( + 'id' => array( + 'type' => 'integer', + 'length' => '4', + 'notnull' => true + ), + 'is_online' => array( + 'type' => 'integer', + 'length' => '1', + 'notnull' => false + ) + ); + $ilDB->createTable("rep_robj_xqsp_data", $fields); + $ilDB->addPrimaryKey("rep_robj_xqsp_data", array("id")); } ?> <#2> tableExists("rep_robj_xqsp_question")) -{ - $fields = array( - 'questionsetpool_fi' => array( - 'type' => 'integer', - 'length' => '4', - 'notnull' => true - ), - 'question_fi' => array( - 'type' => 'integer', - 'length' => '4', - 'notnull' => true - ) - ); - $ilDB->createTable("rep_robj_xqsp_question", $fields); - $ilDB->addPrimaryKey("rep_robj_xqsp_question", array("questionsetpool_fi", "question_fi")); +if (!$ilDB->tableExists("rep_robj_xqsp_question")) { + $fields = array( + 'questionsetpool_fi' => array( + 'type' => 'integer', + 'length' => '4', + 'notnull' => true + ), + 'question_fi' => array( + 'type' => 'integer', + 'length' => '4', + 'notnull' => true + ) + ); + $ilDB->createTable("rep_robj_xqsp_question", $fields); + $ilDB->addPrimaryKey("rep_robj_xqsp_question", array("questionsetpool_fi", "question_fi")); } ?> <#3> tableExists("rep_robj_xqsp_qs")) -{ - $fields = array( - 'id' => array( - 'type' => 'integer', - 'length' => 4, - 'notnull' => true - ), - 'questionsetpool_fi' => array( - 'type' => 'integer', - 'length' => 4, - 'notnull' => true - ), - 'title' => array( - 'type' => 'text', - 'length' => 255 - ), - 'description' => array( - 'type' => 'text', - 'length' => 4000 - ) - ); - $ilDB->createTable("rep_robj_xqsp_qs", $fields); - $ilDB->addPrimaryKey("rep_robj_xqsp_qs", array("id")); - $ilDB->createSequence("rep_robj_xqsp_qs"); +if (!$ilDB->tableExists("rep_robj_xqsp_qs")) { + $fields = array( + 'id' => array( + 'type' => 'integer', + 'length' => 4, + 'notnull' => true + ), + 'questionsetpool_fi' => array( + 'type' => 'integer', + 'length' => 4, + 'notnull' => true + ), + 'title' => array( + 'type' => 'text', + 'length' => 255 + ), + 'description' => array( + 'type' => 'text', + 'length' => 4000 + ) + ); + $ilDB->createTable("rep_robj_xqsp_qs", $fields); + $ilDB->addPrimaryKey("rep_robj_xqsp_qs", array("id")); + $ilDB->createSequence("rep_robj_xqsp_qs"); } ?> <#4> tableExists("rep_robj_xqsp_qs_qst")) -{ - $fields = array( - 'questionset_fi' => array( - 'type' => 'integer', - 'length' => '4', - 'notnull' => true - ), - 'question_fi' => array( - 'type' => 'integer', - 'length' => '4', - 'notnull' => true - ) - ); - $ilDB->createTable("rep_robj_xqsp_qs_qst", $fields); - $ilDB->addPrimaryKey("rep_robj_xqsp_qs_qst", array("questionset_fi", "question_fi")); +if (!$ilDB->tableExists("rep_robj_xqsp_qs_qst")) { + $fields = array( + 'questionset_fi' => array( + 'type' => 'integer', + 'length' => '4', + 'notnull' => true + ), + 'question_fi' => array( + 'type' => 'integer', + 'length' => '4', + 'notnull' => true + ) + ); + $ilDB->createTable("rep_robj_xqsp_qs_qst", $fields); + $ilDB->addPrimaryKey("rep_robj_xqsp_qs_qst", array("questionset_fi", "question_fi")); } ?> <#5> tableColumnExists("rep_robj_xqsp_qs_qst", "question_index")) -{ - $ilDB->addTableColumn("rep_robj_xqsp_qs_qst", "question_index", array( - 'type' => 'integer', - 'length' => '4', - 'notnull' => true - )); +if (!$ilDB->tableColumnExists("rep_robj_xqsp_qs_qst", "question_index")) { + $ilDB->addTableColumn("rep_robj_xqsp_qs_qst", "question_index", array( + 'type' => 'integer', + 'length' => '4', + 'notnull' => true + )); } ?> <#6> tableExists("rep_robj_xqsp_path")) -{ - $fields = array( - 'id' => array( - 'type' => 'integer', - 'length' => '4', - 'notnull' => true - ), - 'title' => array( - 'type' => 'text', - 'length' => 255 - ), - 'questionset_fi' => array( - 'type' => 'integer', - 'length' => '4', - 'notnull' => true - ), - ); - $ilDB->createTable("rep_robj_xqsp_path", $fields); - $ilDB->addPrimaryKey("rep_robj_xqsp_path", array("id")); - $ilDB->createSequence("rep_robj_xqsp_path"); +if (!$ilDB->tableExists("rep_robj_xqsp_path")) { + $fields = array( + 'id' => array( + 'type' => 'integer', + 'length' => '4', + 'notnull' => true + ), + 'title' => array( + 'type' => 'text', + 'length' => 255 + ), + 'questionset_fi' => array( + 'type' => 'integer', + 'length' => '4', + 'notnull' => true + ), + ); + $ilDB->createTable("rep_robj_xqsp_path", $fields); + $ilDB->addPrimaryKey("rep_robj_xqsp_path", array("id")); + $ilDB->createSequence("rep_robj_xqsp_path"); } ?> <#7> tableExists("rep_robj_xqsp_node")) -{ - $fields = array( - 'id' => array( - 'type' => 'integer', - 'length' => '4', - 'notnull' => true - ), - 'question_fi' => array( - 'type' => 'integer', - 'length' => '4', - 'notnull' => true - ), - 'path_fi' => array( - 'type' => 'integer', - 'length' => '4', - 'notnull' => true - ), - 'node_index' => array( - 'type' => 'integer', - 'length' => '4', - 'notnull' => true - ), - 'initial_condition' => array( - 'type' => 'text', - 'length' => '4000', - ), - ); - $ilDB->createTable("rep_robj_xqsp_node", $fields); - $ilDB->addPrimaryKey("rep_robj_xqsp_node", array("id")); - $ilDB->createSequence("rep_robj_xqsp_node"); +if (!$ilDB->tableExists("rep_robj_xqsp_node")) { + $fields = array( + 'id' => array( + 'type' => 'integer', + 'length' => '4', + 'notnull' => true + ), + 'question_fi' => array( + 'type' => 'integer', + 'length' => '4', + 'notnull' => true + ), + 'path_fi' => array( + 'type' => 'integer', + 'length' => '4', + 'notnull' => true + ), + 'node_index' => array( + 'type' => 'integer', + 'length' => '4', + 'notnull' => true + ), + 'initial_condition' => array( + 'type' => 'text', + 'length' => '4000', + ), + ); + $ilDB->createTable("rep_robj_xqsp_node", $fields); + $ilDB->addPrimaryKey("rep_robj_xqsp_node", array("id")); + $ilDB->createSequence("rep_robj_xqsp_node"); } ?> <#8> tableExists("rep_robj_xqsp_jmp_con")) -{ - $fields = array( - 'id' => array( - 'type' => 'integer', - 'length' => '4', - 'notnull' => true - ), - 'jump_condition' => array( - 'type' => 'text', - 'length' => 4000 - ), - 'node_fi' => array( - 'type' => 'integer', - 'length' => '4', - 'notnull' => true - ), - 'question_fi' => array( - 'type' => 'integer', - 'length' => '4', - 'notnull' => true - ), - ); - $ilDB->createTable("rep_robj_xqsp_jmp_con", $fields); - $ilDB->addPrimaryKey("rep_robj_xqsp_jmp_con", array("id")); - $ilDB->createSequence("rep_robj_xqsp_jmp_con"); +if (!$ilDB->tableExists("rep_robj_xqsp_jmp_con")) { + $fields = array( + 'id' => array( + 'type' => 'integer', + 'length' => '4', + 'notnull' => true + ), + 'jump_condition' => array( + 'type' => 'text', + 'length' => 4000 + ), + 'node_fi' => array( + 'type' => 'integer', + 'length' => '4', + 'notnull' => true + ), + 'question_fi' => array( + 'type' => 'integer', + 'length' => '4', + 'notnull' => true + ), + ); + $ilDB->createTable("rep_robj_xqsp_jmp_con", $fields); + $ilDB->addPrimaryKey("rep_robj_xqsp_jmp_con", array("id")); + $ilDB->createSequence("rep_robj_xqsp_jmp_con"); } ?> <#9> tableColumnExists("rep_robj_xqsp_qs", "is_online")) -{ - $ilDB->addTableColumn("rep_robj_xqsp_qs", "is_online", array( - 'type' => 'integer', - 'length' => '1', - 'notnull' => false - )); +if (!$ilDB->tableColumnExists("rep_robj_xqsp_qs", "is_online")) { + $ilDB->addTableColumn("rep_robj_xqsp_qs", "is_online", array( + 'type' => 'integer', + 'length' => '1', + 'notnull' => false + )); } ?> <#10> tableColumnExists("rep_robj_xqsp_qs", "original_id")) -{ - $ilDB->addTableColumn("rep_robj_xqsp_qs", "original_id", array( - 'type' => 'integer', - 'length' => '4', - 'notnull' => false - )); +if (!$ilDB->tableColumnExists("rep_robj_xqsp_qs", "original_id")) { + $ilDB->addTableColumn("rep_robj_xqsp_qs", "original_id", array( + 'type' => 'integer', + 'length' => '4', + 'notnull' => false + )); } ?> <#11> tableExists("rep_robj_xqsp_jmp_con")) -{ - $ilDB->modifyTableColumn("rep_robj_xqsp_jmp_con", "question_fi", array( - "type" => "integer", - "length" => 4, - "notnull" => false - )); +if ($ilDB->tableExists("rep_robj_xqsp_jmp_con")) { + $ilDB->modifyTableColumn("rep_robj_xqsp_jmp_con", "question_fi", array( + "type" => "integer", + "length" => 4, + "notnull" => false + )); } ?> <#12> quote('xqsp', 'text'); $res = $ilDB->query($query); -while($row = $ilDB->fetchAssoc($res)) -{ - $ilDB->manipulateF( - 'INSERT INTO rep_robj_xqsp_data (id) VALUES (%s)', - array('integer'), - array($row['obj_id']) - ); +while ($row = $ilDB->fetchAssoc($res)) { + $ilDB->manipulateF( + 'INSERT INTO rep_robj_xqsp_data (id) VALUES (%s)', + array('integer'), + array($row['obj_id']) + ); } ?> <#13> tableExists('rep_robj_xqsp_question')) -{ - $ilDB->dropTable('rep_robj_xqsp_question'); +if ($ilDB->tableExists('rep_robj_xqsp_question')) { + $ilDB->dropTable('rep_robj_xqsp_question'); } ?> <#14> tableColumnExists("rep_robj_xqsp_path", "path_index")) -{ - $ilDB->addTableColumn("rep_robj_xqsp_path", "path_index", array( - 'type' => 'integer', - 'length' => '4', - 'notnull' => false - )); +if (!$ilDB->tableColumnExists("rep_robj_xqsp_path", "path_index")) { + $ilDB->addTableColumn("rep_robj_xqsp_path", "path_index", array( + 'type' => 'integer', + 'length' => '4', + 'notnull' => false + )); } ?> <#15> tableColumnExists("rep_robj_xqsp_node", "dominant_scoring")) -{ - $ilDB->addTableColumn("rep_robj_xqsp_node", "dominant_scoring", array( - 'type' => 'integer', - 'length' => '4', - 'notnull' => true - )); +if (!$ilDB->tableColumnExists("rep_robj_xqsp_node", "dominant_scoring")) { + $ilDB->addTableColumn("rep_robj_xqsp_node", "dominant_scoring", array( + 'type' => 'integer', + 'length' => '4', + 'notnull' => true + )); } ?> <#16> tableColumnExists("rep_robj_xqsp_jmp_con", "repititions")) -{ - $ilDB->addTableColumn("rep_robj_xqsp_jmp_con", "repititions", array( - 'type' => 'integer', - 'length' => '4', - 'notnull' => true - )); +if (!$ilDB->tableColumnExists("rep_robj_xqsp_jmp_con", "repititions")) { + $ilDB->addTableColumn("rep_robj_xqsp_jmp_con", "repititions", array( + 'type' => 'integer', + 'length' => '4', + 'notnull' => true + )); } ?> <#17> tableColumnExists("rep_robj_xqsp_qs", "is_online")) -{ - $ilDB->dropTableColumn("rep_robj_xqsp_qs", "is_online"); +if ($ilDB->tableColumnExists("rep_robj_xqsp_qs", "is_online")) { + $ilDB->dropTableColumn("rep_robj_xqsp_qs", "is_online"); } ?> <#18> tableColumnExists("rep_robj_xqsp_node", "dominant_scoring")) -{ - $ilDB->modifyTableColumn("rep_robj_xqsp_node", "dominant_scoring", array( - "type" => "integer", - "length" => 4, - "notnull" => false - )); +if ($ilDB->tableColumnExists("rep_robj_xqsp_node", "dominant_scoring")) { + $ilDB->modifyTableColumn("rep_robj_xqsp_node", "dominant_scoring", array( + "type" => "integer", + "length" => 4, + "notnull" => false + )); } ?> <#19> tableColumnExists("rep_robj_xqsp_jmp_con", "sorting")) -{ - $ilDB->addTableColumn("rep_robj_xqsp_jmp_con", "sorting", array( - "type" => "integer", - "length" => 4, - "notnull" => false - )); +if (!$ilDB->tableColumnExists("rep_robj_xqsp_jmp_con", "sorting")) { + $ilDB->addTableColumn("rep_robj_xqsp_jmp_con", "sorting", array( + "type" => "integer", + "length" => 4, + "notnull" => false + )); - $ilDB->query("UPDATE rep_robj_xqsp_jmp_con SET sorting = id"); + $ilDB->query("UPDATE rep_robj_xqsp_jmp_con SET sorting = id"); } ?> <#20> tableColumnExists("rep_robj_xqsp_jmp_con", "repititions")) -{ - $ilDB->modifyTableColumn("rep_robj_xqsp_jmp_con", "repititions", array( - "type" => "integer", - "length" => 4, - "notnull" => false - )); +if ($ilDB->tableColumnExists("rep_robj_xqsp_jmp_con", "repititions")) { + $ilDB->modifyTableColumn("rep_robj_xqsp_jmp_con", "repititions", array( + "type" => "integer", + "length" => 4, + "notnull" => false + )); - $ilDB->query("UPDATE rep_robj_xqsp_jmp_con SET repititions = NULL WHERE repititions = 0"); + $ilDB->query("UPDATE rep_robj_xqsp_jmp_con SET repititions = NULL WHERE repititions = 0"); } ?> <#21> tableExists('rep_robj_xqsp_node')) -{ - if(!$ilDB->tableColumnExists("rep_robj_xqsp_node", "true_feedback")) - { - $ilDB->addTableColumn('rep_robj_xqsp_node', 'true_feedback', - array("type" => "clob", - "notnull" => false, - "default" => null)); - } +if ($ilDB->tableExists('rep_robj_xqsp_node')) { + if (!$ilDB->tableColumnExists("rep_robj_xqsp_node", "true_feedback")) { + $ilDB->addTableColumn( + 'rep_robj_xqsp_node', + 'true_feedback', + array("type" => "clob", + "notnull" => false, + "default" => null) + ); + } - if(!$ilDB->tableColumnExists("rep_robj_xqsp_node", "false_feedback")) - { - $ilDB->addTableColumn('rep_robj_xqsp_node', 'false_feedback', - array("type" => "clob", - "notnull" => false, - "default" => null)); - } + if (!$ilDB->tableColumnExists("rep_robj_xqsp_node", "false_feedback")) { + $ilDB->addTableColumn( + 'rep_robj_xqsp_node', + 'false_feedback', + array("type" => "clob", + "notnull" => false, + "default" => null) + ); + } } ?> <#22> tableExists('rep_robj_xqsp_jmp_con')) -{ - if(!$ilDB->tableColumnExists("rep_robj_xqsp_jmp_con", "true_feedback")) - { - $ilDB->addTableColumn('rep_robj_xqsp_jmp_con', 'true_feedback', - array("type" => "clob", - "notnull" => false, - "default" => null)); - } +if ($ilDB->tableExists('rep_robj_xqsp_jmp_con')) { + if (!$ilDB->tableColumnExists("rep_robj_xqsp_jmp_con", "true_feedback")) { + $ilDB->addTableColumn( + 'rep_robj_xqsp_jmp_con', + 'true_feedback', + array("type" => "clob", + "notnull" => false, + "default" => null) + ); + } - if(!$ilDB->tableColumnExists("rep_robj_xqsp_jmp_con", "true_jmp_feedback")) - { - $ilDB->addTableColumn('rep_robj_xqsp_jmp_con', 'true_jmp_feedback', - array("type" => "clob", - "notnull" => false, - "default" => null)); - } - - if(!$ilDB->tableColumnExists("rep_robj_xqsp_jmp_con", "false_feedback")) - { - $ilDB->addTableColumn('rep_robj_xqsp_jmp_con', 'false_feedback', - array("type" => "clob", - "notnull" => false, - "default" => null)); - } + if (!$ilDB->tableColumnExists("rep_robj_xqsp_jmp_con", "true_jmp_feedback")) { + $ilDB->addTableColumn( + 'rep_robj_xqsp_jmp_con', + 'true_jmp_feedback', + array("type" => "clob", + "notnull" => false, + "default" => null) + ); + } + + if (!$ilDB->tableColumnExists("rep_robj_xqsp_jmp_con", "false_feedback")) { + $ilDB->addTableColumn( + 'rep_robj_xqsp_jmp_con', + 'false_feedback', + array("type" => "clob", + "notnull" => false, + "default" => null) + ); + } } ?> <#23> tableColumnExists("rep_robj_xqsp_data", "skill_service")) -{ - $ilDB->addTableColumn("rep_robj_xqsp_data", "skill_service", array( - 'type' => 'integer', - 'length' => '1', - 'notnull' => false - )); +if (!$ilDB->tableColumnExists("rep_robj_xqsp_data", "skill_service")) { + $ilDB->addTableColumn("rep_robj_xqsp_data", "skill_service", array( + 'type' => 'integer', + 'length' => '1', + 'notnull' => false + )); } ?> <#24> diff --git a/templates/default/tpl.il_xqsp_condition.html b/templates/default/tpl.il_xqsp_condition.html index 70b7d91f18deb8f2c36dbf3f0b2ec9d65784415f..71252282419b323264b0f979cad474cebc3c6368 100644 --- a/templates/default/tpl.il_xqsp_condition.html +++ b/templates/default/tpl.il_xqsp_condition.html @@ -36,30 +36,31 @@ //$("#ilQuestionSetPoolConditionInputContainer form input[type=submit]").first().click(); }; - var $fbd_toggle = $('#il_center_col a.toggle_feedback'); - + const $fbd_toggle = $('#il_center_col a.toggle_feedback'); + $(function() { - var $topbar = $(".ilTopBar"); - var $main_menu = $(".ilMainHeader"); - var $condition_container = $("#ilConditionFormContainer"); - var $condition_add_on_container = $("#ilQuestionSetPoolConditionAddOnContainer"); - var $panelcontainer = $(".ilQuestionSetPoolConditionInputQuestionPreviewContainer"); - var $table = $(".ilQuestionSetPoolConditionQuestionTable"); - - var showFeedback = function() { + const $metabar = $(".il-layout-page header"); + const $breadcrumbs = $(".il-layout-page .breadcrumbs"); + const $condition_container = $("#ilConditionFormContainer"); + const $condition_add_on_container = $("#ilQuestionSetPoolConditionAddOnContainer"); + const $panelcontainer = $(".ilQuestionSetPoolConditionInputQuestionPreviewContainer"); + const $table = $(".ilQuestionSetPoolConditionQuestionTable"); + const $toolbar = $(".ilToolbar"); + + const showFeedback = function() { $fbd_toggle.removeClass('ilFormATestFeedbackHidden'); $('form[name="condition_form"] textarea[name*="feedback"]').closest("div.form-group").show(); $fbd_toggle.text("{TXT_HIDE_FEEDBACK} "); }; - - var hideFeedback = function() { + + const hideFeedback = function() { $('form[name="condition_form"] textarea[name*="feedback"]').closest("div.form-group").hide(); $fbd_toggle.addClass('ilFormATestFeedbackHidden'); $fbd_toggle.text("{TXT_SHOW_FEEDBACK}"); }; - if ($fbd_toggle.size() == 1) { - $fbd_toggle.on('click', function(e) { + if ($fbd_toggle.length === 1) { + $fbd_toggle.on("click", function(e) { e.preventDefault(); e.stopPropagation(); @@ -73,11 +74,11 @@ var onScrollHandler = function() { if ($panelcontainer.hasClass('ilPartialContainer')) { - var static_height = parseFloat($topbar.height()) + parseFloat($main_menu.height()); - var threshold_height = parseFloat($(document).scrollTop()) + static_height; + const static_height = parseFloat($metabar.height()) + parseFloat($breadcrumbs.height()); + const threshold_height = parseFloat($(document).scrollTop()) + static_height; - var stcc = $condition_container.offset().top; - var stcaoc = $condition_add_on_container.offset().top; + const stcc = $condition_container.offset().top; + const stcaoc = $condition_add_on_container.offset().top; if (threshold_height >= stcc && !$condition_container.hasClass('ilFixedMode')) { $condition_container.css('width', $condition_container.width()); @@ -102,7 +103,7 @@ } } - var $closeBtn = $panelcontainer.find(".ilClose"); + const $closeBtn = $panelcontainer.find(".ilClose"); $closeBtn.click(function(e) { $condition_add_on_container.removeClass("ilPartialContainer"); $panelcontainer.removeClass("ilPartialContainer"); @@ -123,8 +124,7 @@ }); $(".preview").click(function(e) { - var $this = $(this); - var $panel; + const $this = $(this); hideFeedback(); @@ -134,7 +134,7 @@ $panelcontainer.find(".ilPreviewPanel").remove(); - $panel = $('
      '); + const $panel = $('
      '); $.ajax({ url: '{PREVIEW_LINK}&question_id=' + $this.attr('id').replace("preview_", ""), dataType: 'html', @@ -143,10 +143,10 @@ $panel.html(data); $panel.appendTo($panelcontainer); } catch(e) { - console.log(e); + console.error(e); } - if(typeof MathJax != "undefined") { + if (typeof MathJax != "undefined") { MathJax.Hub.Queue(["Typeset", MathJax.Hub]); } @@ -157,7 +157,7 @@ e.preventDefault(); }); - $(document).on('scroll', onScrollHandler); + $(".il-layout-page-content").on('scroll', onScrollHandler); }); }(jQuery, document, window)); \ No newline at end of file diff --git a/templates/default/tpl.il_xqsp_path_overview.html b/templates/default/tpl.il_xqsp_path_overview.html index 812dabd880c7c6a7af0662f3bba3b09bf1b82f48..a55a92d92267d883f0a3df47943b70a4c7bc39ab 100644 --- a/templates/default/tpl.il_xqsp_path_overview.html +++ b/templates/default/tpl.il_xqsp_path_overview.html @@ -33,5 +33,5 @@ -

      {GRAPH_TITLE}

      - \ No newline at end of file +

      {GRAPH_TITLE}

      + \ No newline at end of file diff --git a/test/Mocks/classes/controllers/class.ilPluginSubControllerMock.php b/test/Mocks/classes/controllers/class.ilPluginSubControllerMock.php index 8ccc124670fed0f8a154319ab298e5c0c6d08e78..60ab9d69ed761c95620063fdaeec5fa049431a0c 100644 --- a/test/Mocks/classes/controllers/class.ilPluginSubControllerMock.php +++ b/test/Mocks/classes/controllers/class.ilPluginSubControllerMock.php @@ -6,12 +6,11 @@ * Date: 24.09.13 * Time: 11:45 * @author Thomas Joußen - */ -class ilPluginSubControllerMock { - - public function testMethod() - { - echo "It work's"; - } - + */ +class ilPluginSubControllerMock +{ + public function testMethod() + { + echo "It work's"; + } } diff --git a/test/Mocks/ilPluginTableDatabaseDataProviderMock.php b/test/Mocks/ilPluginTableDatabaseDataProviderMock.php index 827015f513859b7659dca3edb4f712b261000cd4..548f4f479af990fad33eb39eab0cc64782076440 100644 --- a/test/Mocks/ilPluginTableDatabaseDataProviderMock.php +++ b/test/Mocks/ilPluginTableDatabaseDataProviderMock.php @@ -8,65 +8,67 @@ require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/ * Date: 27.09.13 * Time: 16:24 * @author Thomas Joußen - */ -class ilPluginTableDatabaseDataProviderMock extends ilPluginTableDatabaseDataProvider{ + */ +class ilPluginTableDatabaseDataProviderMock extends ilPluginTableDatabaseDataProvider +{ - /** - * @return string - */ - protected function getSelectPart() - { - // TODO: Implement getSelectPart() method. - } + /** + * @return string + */ + protected function getSelectPart() + { + // TODO: Implement getSelectPart() method. + } - /** - * @return string - */ - protected function getFromPart() - { - // TODO: Implement getFromPart() method. - } + /** + * @return string + */ + protected function getFromPart() + { + // TODO: Implement getFromPart() method. + } - /** - * @return string - */ - protected function getJoinPart() - { - // TODO: Implement getJoinPart() method. - } + /** + * @return string + */ + protected function getJoinPart() + { + // TODO: Implement getJoinPart() method. + } - /** - * @param array $filter - * - * @return string - */ - protected function getWherePart(array $filter) - { - // TODO: Implement getWherePart() method. - } + /** + * @param array $filter + * + * @return string + */ + protected function getWherePart(array $filter) + { + // TODO: Implement getWherePart() method. + } - /** - * @return string - */ - protected function getGroupByPart() - { - // TODO: Implement getGroupByPart() method. - } + /** + * @return string + */ + protected function getGroupByPart() + { + // TODO: Implement getGroupByPart() method. + } - /** - * @param array $filter - * @return string - */ - protected function getHavingPart(array $filter) - { - // TODO: Implement getHavingPart() method. - } + /** + * @param array $filter + * @return string + */ + protected function getHavingPart(array $filter) + { + // TODO: Implement getHavingPart() method. + } - /** - * @param array $params - * @return string - */ - protected function getOrderByPart(array $params) - { - // TODO: Implement getOrderByPart() method. - }} + /** + * @param array $params + * @return string + */ + protected function getOrderByPart(array $params) + { + // TODO: Implement getOrderByPart() method. + } +} diff --git a/test/Mocks/ilQuestionSetPoolPluginMock.php b/test/Mocks/ilQuestionSetPoolPluginMock.php index d3d5d3b695e99f403667b39e4830e96e2018754d..066c676315797926c6d2fe08547c1595a731c9b2 100644 --- a/test/Mocks/ilQuestionSetPoolPluginMock.php +++ b/test/Mocks/ilQuestionSetPoolPluginMock.php @@ -6,18 +6,18 @@ * Date: 24.09.13 * Time: 11:16 * @author Thomas Joußen - */ -class ilQuestionSetPoolPluginMock{ + */ +class ilQuestionSetPoolPluginMock +{ + protected $directory = "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/test/Mocks"; - protected $directory = "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/test/Mocks"; + public function getDirectory() + { + return $this->directory; + } - public function getDirectory() - { - return $this->directory; - } - - public function setDirectory($dir) - { - $this->directory = $dir; - } + public function setDirectory($dir) + { + $this->directory = $dir; + } } diff --git a/test/dispatcher/ilPluginDispatcherTest.php b/test/dispatcher/ilPluginDispatcherTest.php index d31c767a91bc59284ebaf05c5529b4219e4227a9..5e4abf7aa20a511f57e8ed7ea86c3967e7046c23 100644 --- a/test/dispatcher/ilPluginDispatcherTest.php +++ b/test/dispatcher/ilPluginDispatcherTest.php @@ -9,124 +9,125 @@ require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/ * Time: 09:53 * @author Thomas Joußen */ -class ilPluginDispatcherTest extends PHPUnit_Framework_TestCase { +class ilPluginDispatcherTest extends PHPUnit_Framework_TestCase +{ - /** - * @var ilPluginDispatcher - */ - protected $dispatcher; + /** + * @var ilPluginDispatcher + */ + protected $dispatcher; - /** - * @var PHPUnit_Framework_MockObject_MockObject - */ - protected $baseController_mock; + /** + * @var PHPUnit_Framework_MockObject_MockObject + */ + protected $baseController_mock; - public function setUp() - { - // Include original Object for mock, because an Error accures, if it is included in subfiles in a test - require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/classes/class.ilObjQuestionSetPoolGUI.php"; - require_once "./Services/UIComponent/Tabs/classes/class.ilTabsGUI.php"; - require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/test/Mocks/ilQuestionSetPoolPluginMock.php"; + public function setUp() + { + // Include original Object for mock, because an Error accures, if it is included in subfiles in a test + require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/classes/class.ilObjQuestionSetPoolGUI.php"; + require_once "./Services/UIComponent/Tabs/classes/class.ilTabsGUI.php"; + require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/test/Mocks/ilQuestionSetPoolPluginMock.php"; - global $DIC; - $ilTabs = $DIC->tabs(); + global $DIC; + $ilTabs = $DIC->tabs(); - $this->baseController_mock = $this->getMockBuilder("ilObjQuestionSetPoolGUI")->disableOriginalConstructor()->getMock(); - $this->baseController_mock->plugin = new ilQuestionSetPoolPluginMock(); + $this->baseController_mock = $this->getMockBuilder("ilObjQuestionSetPoolGUI")->disableOriginalConstructor()->getMock(); + $this->baseController_mock->plugin = new ilQuestionSetPoolPluginMock(); - $ilTabs_mock = $this->getMockBuilder("ilTabsGUI")->disableOriginalConstructor()->getMock(); - $ilTabs_mock - ->expects($this->any()) - ->method("activateTab"); + $ilTabs_mock = $this->getMockBuilder("ilTabsGUI")->disableOriginalConstructor()->getMock(); + $ilTabs_mock + ->expects($this->any()) + ->method("activateTab"); - $ilTabs = $ilTabs_mock; + $ilTabs = $ilTabs_mock; - $this->dispatcher = ilPluginDispatcher::getInstance($this->baseController_mock); - } + $this->dispatcher = ilPluginDispatcher::getInstance($this->baseController_mock); + } - public function testGetInstance() - { - $dispatcher2 = ilPluginDispatcher::getInstance($this->baseController_mock); + public function testGetInstance() + { + $dispatcher2 = ilPluginDispatcher::getInstance($this->baseController_mock); - $this->assertNotNull($this->dispatcher); - $this->assertEquals($this->dispatcher, $dispatcher2); - } + $this->assertNotNull($this->dispatcher); + $this->assertEquals($this->dispatcher, $dispatcher2); + } - public function testGetController() - { - $getController = $this->getMethod("getController"); + public function testGetController() + { + $getController = $this->getMethod("getController"); - $controller = $getController->invokeArgs($this->dispatcher, array("testController.testMethod")); + $controller = $getController->invokeArgs($this->dispatcher, array("testController.testMethod")); - $this->assertEquals("testController", $controller); - } + $this->assertEquals("testController", $controller); + } - public function testGetCommand() - { - $getCommand = $this->getMethod("getCommand"); + public function testGetCommand() + { + $getCommand = $this->getMethod("getCommand"); - $command = $getCommand->invokeArgs($this->dispatcher, array("testController.testMethod")); + $command = $getCommand->invokeArgs($this->dispatcher, array("testController.testMethod")); - $this->assertEquals("testMethod", $command); - } + $this->assertEquals("testMethod", $command); + } - public function testGetCommandWithoutPassedController() - { - $getCommand = $this->getMethod("getCommand"); + public function testGetCommandWithoutPassedController() + { + $getCommand = $this->getMethod("getCommand"); - $command = $getCommand->invokeArgs($this->dispatcher, array("testMethod")); + $command = $getCommand->invokeArgs($this->dispatcher, array("testMethod")); - $this->assertEquals("testMethod", $command); - } + $this->assertEquals("testMethod", $command); + } - public function testGetControllerWithoutPassedController() - { - $getController = $this->getMethod("getController"); + public function testGetControllerWithoutPassedController() + { + $getController = $this->getMethod("getController"); - $controller = $getController->invokeArgs($this->dispatcher, array("testMethod")); + $controller = $getController->invokeArgs($this->dispatcher, array("testMethod")); - $this->assertEquals($this->baseController_mock, $controller); - } + $this->assertEquals($this->baseController_mock, $controller); + } - public function testInstantiateController() - { - $getController = $this->getMethod("getController"); - $instantiateController = $this->getMethod("instantiateController"); + public function testInstantiateController() + { + $getController = $this->getMethod("getController"); + $instantiateController = $this->getMethod("instantiateController"); - $controllerName = $getController->invokeArgs($this->dispatcher, array("ilPluginSubControllerMock.testMethod")); - $controller = $instantiateController->invokeArgs($this->dispatcher, array($controllerName)); + $controllerName = $getController->invokeArgs($this->dispatcher, array("ilPluginSubControllerMock.testMethod")); + $controller = $instantiateController->invokeArgs($this->dispatcher, array($controllerName)); - $this->assertInstanceOf("ilPluginSubControllerMock", $controller); - } + $this->assertInstanceOf("ilPluginSubControllerMock", $controller); + } - public function testGetControllerPath() - { - $getControllerPath = $this->getMethod("getControllerPath"); + public function testGetControllerPath() + { + $getControllerPath = $this->getMethod("getControllerPath"); - $actual = $getControllerPath->invokeArgs($this->dispatcher, array()); + $actual = $getControllerPath->invokeArgs($this->dispatcher, array()); - $this->assertStringEndsWith("/classes/controllers/", $actual); - } + $this->assertStringEndsWith("/classes/controllers/", $actual); + } - public function testDispatch() - { - $this->expectOutputString("It work's"); - $this->dispatcher->dispatch("ilPluginSubControllerMock.testMethod"); - } + public function testDispatch() + { + $this->expectOutputString("It work's"); + $this->dispatcher->dispatch("ilPluginSubControllerMock.testMethod"); + } - /** - * Get an ReflectionMethod to test private or protected functions - * - * @param string $method - * - * @return ReflectionMethod - */ - private function getMethod($method) - { - $class = new ReflectionClass("ilPluginDispatcher"); - $method = $class->getMethod($method); - $method->setAccessible(true); + /** + * Get an ReflectionMethod to test private or protected functions + * + * @param string $method + * + * @return ReflectionMethod + */ + private function getMethod($method) + { + $class = new ReflectionClass("ilPluginDispatcher"); + $method = $class->getMethod($method); + $method->setAccessible(true); - return $method; - } + return $method; + } } diff --git a/test/ilQuestionSetPoolTestSuite.php b/test/ilQuestionSetPoolTestSuite.php index 3778cf546a24ace53d0efb7f5048c4243be9458c..62276a5fec0d091c1c406b9dbab0176128fd3cc5 100644 --- a/test/ilQuestionSetPoolTestSuite.php +++ b/test/ilQuestionSetPoolTestSuite.php @@ -8,23 +8,22 @@ require_once "./Services/Repository/classes/class.ilObjectPluginGUI.php"; * Date: 24.09.13 * Time: 12:16 * @author Thomas Joußen - */ + */ class ilQuestionSetPoolTestSuite extends PHPUnit_Framework_TestSuite { + public static function suite() + { + $suite = new self(); - public static function suite() - { - $suite = new self(); + require_once './Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/test/dispatcher/ilPluginDispatcherTest.php'; + $suite->addTestSuite('ilPluginDispatcherTest'); - require_once './Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/test/dispatcher/ilPluginDispatcherTest.php'; - $suite->addTestSuite('ilPluginDispatcherTest'); + require_once './Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/test/providers/ilQuestionSetPoolQuestionsProviderTest.php'; + $suite->addTestSuite('ilQuestionSetPoolQuestionsProviderTest'); - require_once './Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/test/providers/ilQuestionSetPoolQuestionsProviderTest.php'; - $suite->addTestSuite('ilQuestionSetPoolQuestionsProviderTest'); + require_once './Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/test/providers/ilPluginTableDatabaseDataProviderTest.php'; + $suite->addTestSuite('ilPluginTableDatabaseDataProviderTest'); - require_once './Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/test/providers/ilPluginTableDatabaseDataProviderTest.php'; - $suite->addTestSuite('ilPluginTableDatabaseDataProviderTest'); - - return $suite; - } + return $suite; + } } diff --git a/test/providers/ilPluginTableDatabaseDataProviderTest.php b/test/providers/ilPluginTableDatabaseDataProviderTest.php index e274a78155cdfbfc6c8e737ce222ae644de4916a..508ca7b2d458a766d51a8ac41a540d8f555b8f1b 100644 --- a/test/providers/ilPluginTableDatabaseDataProviderTest.php +++ b/test/providers/ilPluginTableDatabaseDataProviderTest.php @@ -9,36 +9,35 @@ require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/ * Time: 13:33 * @author Thomas Joußen */ -class ilPluginTableDatabaseDataProviderTest extends PHPUnit_Framework_TestCase { - - /** - * @var ilQuestionSetPoolQuestionsBrowserProvider - */ - protected $provider; - - public function setUp() - { - global $DIC; - $ilDB = $DIC->database(); - - $ilDB_mock = $this->getMockBuilder("ilDB")->getMock(); - $ilDB_mock - ->expects($this->any()) - ->method("quote") - ->with(2) - ->will($this->returnValue(2)); - - $ilDB = $ilDB_mock; - - $this->provider = new ilPluginTableDatabaseDataProviderMock(); - } - - public function testIsLoaded() - { - $this->assertFalse($this->provider->isLoaded(), "The Provider isn't loaded"); - $this->provider->setLoaded(true); - $this->assertTrue($this->provider->isLoaded(), "The Provider is loaded"); - } - - +class ilPluginTableDatabaseDataProviderTest extends PHPUnit_Framework_TestCase +{ + + /** + * @var ilQuestionSetPoolQuestionsBrowserProvider + */ + protected $provider; + + public function setUp() + { + global $DIC; + $ilDB = $DIC->database(); + + $ilDB_mock = $this->getMockBuilder("ilDB")->getMock(); + $ilDB_mock + ->expects($this->any()) + ->method("quote") + ->with(2) + ->will($this->returnValue(2)); + + $ilDB = $ilDB_mock; + + $this->provider = new ilPluginTableDatabaseDataProviderMock(); + } + + public function testIsLoaded() + { + $this->assertFalse($this->provider->isLoaded(), "The Provider isn't loaded"); + $this->provider->setLoaded(true); + $this->assertTrue($this->provider->isLoaded(), "The Provider is loaded"); + } } diff --git a/test/providers/ilQuestionSetPoolQuestionsProviderTest.php b/test/providers/ilQuestionSetPoolQuestionsProviderTest.php index 1256011ea123a6aa537595a6b4b0440ecdc5421a..7f871a792404b4459c6f0956b919308aab49eaaa 100644 --- a/test/providers/ilQuestionSetPoolQuestionsProviderTest.php +++ b/test/providers/ilQuestionSetPoolQuestionsProviderTest.php @@ -7,121 +7,123 @@ * Time: 12:33 * @author Thomas Joußen */ -class ilQuestionSetPoolQuestionsProviderTest extends PHPUnit_Framework_TestCase { +class ilQuestionSetPoolQuestionsProviderTest extends PHPUnit_Framework_TestCase +{ - /** - * @var ilQuestionSetPoolQuestionsProvider; - */ - protected $provider; + /** + * @var ilQuestionSetPoolQuestionsProvider; + */ + protected $provider; - public function setUp(){ - require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/classes/providers/class.ilQuestionSetPoolQuestionsProvider.php"; - - global $DIC; - $ilDB = $DIC->database(); + public function setUp() + { + require_once "./Customizing/global/plugins/Services/Repository/RepositoryObject/QuestionSetPool/classes/providers/class.ilQuestionSetPoolQuestionsProvider.php"; + + global $DIC; + $ilDB = $DIC->database(); - $ilDB_mock = $this->getMockBuilder("ilDB")->getMock(); - $ilDB_mock - ->expects($this->any()) - ->method("quote") - ->with(2) - ->will($this->returnValue(2)); + $ilDB_mock = $this->getMockBuilder("ilDB")->getMock(); + $ilDB_mock + ->expects($this->any()) + ->method("quote") + ->with(2) + ->will($this->returnValue(2)); - $ilDB = $ilDB_mock; + $ilDB = $ilDB_mock; - $this->provider = new ilQuestionSetPoolQuestionsProvider(); - } + $this->provider = new ilQuestionSetPoolQuestionsProvider(); + } - public function testGetSelectPart() - { - $method = $this->getMethod("getSelectPart"); + public function testGetSelectPart() + { + $method = $this->getMethod("getSelectPart"); - $expected = "qpl_questions.*, qpl_qst_type.type_tag, qpl_qst_type.plugin, object_data.title as pool_title"; - $actual = $method->invokeArgs($this->provider, array()); + $expected = "qpl_questions.*, qpl_qst_type.type_tag, qpl_qst_type.plugin, object_data.title as pool_title"; + $actual = $method->invokeArgs($this->provider, array()); - $this->assertEquals($expected, $actual); - } + $this->assertEquals($expected, $actual); + } - public function testGetFromPart() - { - $method = $this->getMethod("getFromPart"); + public function testGetFromPart() + { + $method = $this->getMethod("getFromPart"); - $expected = "qpl_questions"; - $actual = $method->invokeArgs($this->provider, array()); + $expected = "qpl_questions"; + $actual = $method->invokeArgs($this->provider, array()); - $this->assertEquals($expected, $actual); - } + $this->assertEquals($expected, $actual); + } - public function testGetJoinPart() - { - $method = $this->getMethod("getJoinPart"); + public function testGetJoinPart() + { + $method = $this->getMethod("getJoinPart"); - $expected = - "INNER JOIN qpl_qst_type ON qpl_questions.question_type_fi = qpl_qst_type.question_type_id ". - "INNER JOIN object_data ON object_data.obj_id = qpl_questions.obj_fi ". - "LEFT JOIN rep_robj_xqsp_question ON qpl_questions.question_id = rep_robj_xqsp_question.question_fi"; + $expected = + "INNER JOIN qpl_qst_type ON qpl_questions.question_type_fi = qpl_qst_type.question_type_id " . + "INNER JOIN object_data ON object_data.obj_id = qpl_questions.obj_fi " . + "LEFT JOIN rep_robj_xqsp_question ON qpl_questions.question_id = rep_robj_xqsp_question.question_fi"; - $actual = $method->invokeArgs($this->provider, array()); + $actual = $method->invokeArgs($this->provider, array()); - $this->assertEquals($expected, $actual); - } + $this->assertEquals($expected, $actual); + } - public function testWherePart() - { - $method = $this->getMethod("getWherePart"); - $filter = array( - "xqsp_id" => 2 - ); + public function testWherePart() + { + $method = $this->getMethod("getWherePart"); + $filter = array( + "xqsp_id" => 2 + ); - $expected = "qpl_questions.original_id IS NULL AND qpl_questions.tstamp > 0 AND rep_robj_xqsp_question.questionsetpool_fi = 2"; + $expected = "qpl_questions.original_id IS NULL AND qpl_questions.tstamp > 0 AND rep_robj_xqsp_question.questionsetpool_fi = 2"; - $actual = $method->invokeArgs($this->provider, array($filter)); + $actual = $method->invokeArgs($this->provider, array($filter)); - $this->assertEquals($expected, $actual); - } + $this->assertEquals($expected, $actual); + } - public function testGroupByPart() - { - $method = $this->getMethod("getGroupByPart"); + public function testGroupByPart() + { + $method = $this->getMethod("getGroupByPart"); - $actual = $method->invokeArgs($this->provider, array()); + $actual = $method->invokeArgs($this->provider, array()); - $this->assertEquals("", $actual); - } + $this->assertEquals("", $actual); + } - public function testHavingPart() - { - $method = $this->getMethod("getHavingPart"); - $filter = array(); + public function testHavingPart() + { + $method = $this->getMethod("getHavingPart"); + $filter = array(); - $actual = $method->invokeArgs($this->provider, array($filter)); + $actual = $method->invokeArgs($this->provider, array($filter)); - $this->assertEquals("", $actual); - } + $this->assertEquals("", $actual); + } - public function testOrderByPart() - { - $method = $this->getMethod("getOrderByPart"); - $filter = array(); + public function testOrderByPart() + { + $method = $this->getMethod("getOrderByPart"); + $filter = array(); - $actual = $method->invokeArgs($this->provider, array($filter)); + $actual = $method->invokeArgs($this->provider, array($filter)); - $this->assertEquals("", $actual); - } + $this->assertEquals("", $actual); + } - /** - * Get an ReflectionMethod to test private or protected functions - * - * @param string $method - * - * @return ReflectionMethod - */ - private function getMethod($method) - { - $class = new ReflectionClass("ilQuestionSetPoolQuestionsProvider"); - $method = $class->getMethod($method); - $method->setAccessible(true); + /** + * Get an ReflectionMethod to test private or protected functions + * + * @param string $method + * + * @return ReflectionMethod + */ + private function getMethod($method) + { + $class = new ReflectionClass("ilQuestionSetPoolQuestionsProvider"); + $method = $class->getMethod($method); + $method->setAccessible(true); - return $method; - } + return $method; + } }