Skip to content

Commit

Permalink
Merge pull request #409 from oat-sa/fix/AUT-3994/ResponseValidityCons…
Browse files Browse the repository at this point in the history
…traint

Fix/aut 3994/response validity constraint
  • Loading branch information
bartlomiejmarszal authored Dec 19, 2024
2 parents 0aad73f + 343df8a commit 3a90acd
Show file tree
Hide file tree
Showing 40 changed files with 2,092 additions and 8 deletions.
29 changes: 29 additions & 0 deletions qtism/data/AssessmentItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
use qtism\data\processing\TemplateProcessing;
use qtism\data\state\OutcomeDeclarationCollection;
use qtism\data\state\ResponseDeclarationCollection;
use qtism\data\state\ResponseValidityConstraintCollection;
use qtism\data\state\TemplateDeclarationCollection;
use SplObjectStorage;

Expand All @@ -43,6 +44,24 @@ class AssessmentItem extends QtiComponent implements QtiIdentifiable, IAssessmen
{
use QtiIdentifiableTrait;

private const INTERACTION_CLASS_NAMES = [
'choiceInteraction',
'orderInteraction',
'associateInteraction',
'matchInteraction',
'inlineChoiceInteraction',
'textEntryInteraction',
'extendedTextInteraction',
'hottextInteraction',
'hotspotInteraction',
'selectPointInteraction',
'graphicOrderInteraction',
'graphicAssociateInteraction',
'positionObjectInteraction',
'gapMatchInteraction',
'graphicGapMatchInteraction',
];

/**
* From IMS QTI:
*
Expand Down Expand Up @@ -658,6 +677,16 @@ public function getModalFeedbacks()
return $this->modalFeedbacks;
}

public function getResponseValidityConstraints(): ResponseValidityConstraintCollection
{
$responseValidityConstraints = new ResponseValidityConstraintCollection();
foreach ($this->getComponentsByClassName(self::INTERACTION_CLASS_NAMES) as $component) {
$responseValidityConstraints[] = $component->getResponseValidityConstraint();
}

return $responseValidityConstraints;
}

/**
* @return string
*/
Expand Down
45 changes: 44 additions & 1 deletion qtism/data/ExtendedAssessmentItemRef.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2013-2020 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
* Copyright (c) 2013-2024 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
*
* @author Jérôme Bogaerts <[email protected]>
* @license GPLv2
Expand All @@ -30,6 +30,8 @@
use qtism\data\state\OutcomeDeclarationCollection;
use qtism\data\state\ResponseDeclaration;
use qtism\data\state\ResponseDeclarationCollection;
use qtism\data\state\ResponseValidityConstraint;
use qtism\data\state\ResponseValidityConstraintCollection;

/**
* The ExtendedAssessmentItemRef class is an extended representation of the QTI assessmentItemRef class.
Expand Down Expand Up @@ -79,6 +81,12 @@ class ExtendedAssessmentItemRef extends AssessmentItemRef implements IAssessment
*/
private $timeDependent = false;

/**
* @var ResponseValidityConstraintCollection
* @qtism-bean-property
*/
private $responseValidityConstraints;

/**
* Create a new instance of CompactAssessmentItem
*
Expand All @@ -93,6 +101,7 @@ public function __construct($identifier, $href, IdentifierCollection $categories

$this->setOutcomeDeclarations(new OutcomeDeclarationCollection());
$this->setResponseDeclarations(new ResponseDeclarationCollection());
$this->setResponseValidityConstraints(new ResponseValidityConstraintCollection());
}

/**
Expand Down Expand Up @@ -298,4 +307,38 @@ public function getComponents()

return new QtiComponentCollection($components);
}

/**
* Get the response validity constraints related to the item content.
*/
public function getResponseValidityConstraints()
{
return $this->responseValidityConstraints;
}

/**
* Add a response validity constraint related to item content.
*/
public function addResponseValidityConstraint(ResponseValidityConstraint $responseValidityConstraint): void
{
$this->getResponseValidityConstraints()->attach($responseValidityConstraint);
}

/**
* Remove a response validity constraint related to item content.
*/
public function removeResponseValidityConstraint(ResponseValidityConstraint $responseValidityConstraint): void
{
$this->getResponseValidityConstraints()->detach($responseValidityConstraint);
}

/**
* Set the response validity constraints related to the item content.
*/
public function setResponseValidityConstraints(ResponseValidityConstraintCollection $responseValidityConstraints): void
{
$this->responseValidityConstraints = $responseValidityConstraints;
}


}
130 changes: 130 additions & 0 deletions qtism/data/ExtendedAssessmentTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2013-2024 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
*
* @author Jérôme Bogaerts <[email protected]>
* @license GPLv2
*/

namespace qtism\data;

/**
* The ExtendedAssessmentTest class is an extended representation of the QTI
* AssessmentTest class. It gathers together the AssessmentTest + additional references
* to testFeedback components.
*/
class ExtendedAssessmentTest extends AssessmentTest
{
/**
* A collection of TestFeedbackRef objects.
*
* @var TestFeedbackRefCollection
* @qtism-bean-property
*/
private $testFeedbackRefs;

/**
* Create a new ExtendedAssessmentTest object.
*
* @param string $identifier A QTI identifier.
* @param string $title A title.
* @param TestPartCollection $testParts A collection of ExtendedTestPart objects.
*/
public function __construct($identifier, $title, TestPartCollection $testParts = null)
{
parent::__construct($identifier, $title, $testParts);
$this->setTestFeedbackRefs(new TestFeedbackRefCollection());
}

/**
* Set the collection of TestFeedbackRef objects.
*
* @param TestFeedbackRefCollection $testFeedbackRefs
*/
public function setTestFeedbackRefs(TestFeedbackRefCollection $testFeedbackRefs): void
{
$this->testFeedbackRefs = $testFeedbackRefs;
}

/**
* Get the collection of TestFeedbackRef objects.
*
* @return TestFeedbackRefCollection
*/
public function getTestFeedbackRefs(): TestFeedbackRefCollection
{
return $this->testFeedbackRefs;
}

/**
* Add a TestFeedbackRef object.
*
* @param TestFeedbackRef $testFeedbackRef
*/
public function addTestFeedbackRef(TestFeedbackRef $testFeedbackRef): void
{
$this->getTestFeedbackRefs()->attach($testFeedbackRef);
}

/**
* Remove a TestFeedbackRef object.
*
* @param TestFeedbackRef $testFeedbackRef
*/
public function removeTestFeedbackRef(TestFeedbackRef $testFeedbackRef): void
{
$this->getTestFeedbackRefs()->detach($testFeedbackRef);
}

/**
* Create an ExtendedAssessmentTest object from an AssessmentTest object.
*
* @param AssessmentTest $assessmentTest
* @return ExtendedAssessmentTest
*/
public static function createFromAssessmentTest(AssessmentTest $assessmentTest): ExtendedAssessmentTest
{
$ref = new ExtendedAssessmentTest(
$assessmentTest->getIdentifier(),
$assessmentTest->getTitle(),
$assessmentTest->getTestParts()
);

$ref->setTimeLimits($assessmentTest->getTimeLimits());
$ref->setOutcomeDeclarations($assessmentTest->getOutcomeDeclarations());
$ref->setOutcomeProcessing($assessmentTest->getOutcomeProcessing());
$ref->setTestFeedbacks($assessmentTest->getTestFeedbacks());
$ref->setToolName($assessmentTest->getToolName());
$ref->setToolVersion($assessmentTest->getToolVersion());

return $ref;
}

/**
* @return QtiComponentCollection
*/
public function getComponents(): QtiComponentCollection
{
$components = array_merge(
parent::getComponents()->getArrayCopy(),
$this->getTestFeedbackRefs()->getArrayCopy()
);

return new QtiComponentCollection($components);
}
}
135 changes: 135 additions & 0 deletions qtism/data/ExtendedTestPart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; under version 2
* of the License (non-upgradable).
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* Copyright (c) 2013-2024 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
*
* @author Jérôme Bogaerts <[email protected]>
* @license GPLv2
*/

namespace qtism\data;

use InvalidArgumentException;

/**
* The ExtendedTestPart class is an extended representation of the QTI
* testPart class. It gathers together the testPart + additional references
* to testFeedback components.
*/
class ExtendedTestPart extends TestPart
{
/**
* Create a new ExtendedTestPart object.
*
* @param string $identifier An identifier.
* @param SectionPartCollection $assessmentSections A collection of AssessmentSection and/or AssessmentSectionRef objects.
* @param int $navigationMode A value from the NavigationMode enumeration.
* @param int $submissionMode A value from the SubmissionMode enumeration.
* @throws InvalidArgumentException If any of the arguments is invalid.
*/
public function __construct($identifier, SectionPartCollection $assessmentSections, $navigationMode = NavigationMode::LINEAR, $submissionMode = SubmissionMode::INDIVIDUAL)
{
parent::__construct($identifier, $assessmentSections, $navigationMode, $submissionMode);
$this->setTestFeedbackRefs(new TestFeedbackRefCollection());
}

/**
* A collection of TestFeedbackRef objects.
*
* @var TestFeedbackRefCollection
* @qtism-bean-property
*/
private $testFeedbackRefs;

/**
* Set the collection of TestFeedbackRef objects.
*
* @param TestFeedbackRefCollection $testFeedbackRefs
*/
public function setTestFeedbackRefs(TestFeedbackRefCollection $testFeedbackRefs): void
{
$this->testFeedbackRefs = $testFeedbackRefs;
}

/**
* Get the collection of TestFeedbackRef objects.
*
* @return TestFeedbackRefCollection
*/
public function getTestFeedbackRefs(): TestFeedbackRefCollection
{
return $this->testFeedbackRefs;
}

/**
* Add a TestFeedbackRef to the ExtendedTestPart.
*
* @param TestFeedbackRef $testFeedbackRef
*/
public function addTestFeedbackRef(TestFeedbackRef $testFeedbackRef): void
{
$this->getTestFeedbackRefs()->attach($testFeedbackRef);
}

/**
* Remove a TestFeedbackRef from the ExtendedTestPart.
*
* @param TestFeedbackRef $testFeedbackRef
*/
public function removeTestFeedbackRef(TestFeedbackRef $testFeedbackRef): void
{
$this->getTestFeedbackRefs()->detach($testFeedbackRef);
}

/**
* Create a new ExtendedTestPart object from another TestPart object.
*
* @param TestPart $testPart
* @return ExtendedTestPart
*/
public static function createFromTestPart(TestPart $testPart): ExtendedTestPart
{
$ref = new self(
$testPart->getIdentifier(),
$testPart->getAssessmentSections(),
$testPart->getNavigationMode(),
$testPart->getSubmissionMode()
);

$ref->setAssessmentSections($testPart->getAssessmentSections());
$ref->setTimeLimits($testPart->getTimeLimits());
$ref->setPreConditions($testPart->getPreConditions());
$ref->setBranchRules($testPart->getBranchRules());
$ref->setItemSessionControl($testPart->getItemSessionControl());
$ref->setTestFeedbacks($testPart->getTestFeedbacks());

return $ref;
}

/**
* @return QtiComponentCollection
*/
public function getComponents(): QtiComponentCollection
{
$components = array_merge(
parent::getComponents()->getArrayCopy(),
$this->getTestFeedbackRefs()->getArrayCopy()
);

return new QtiComponentCollection($components);
}
}
Loading

0 comments on commit 3a90acd

Please sign in to comment.