-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
649 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<?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) 2024 (original work) Open Assessment Technologies SA; | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace oat\taoQtiTest\model\Infrastructure; | ||
|
||
use common_exception_Error; | ||
use oat\taoQtiTest\models\runner\QtiRunnerEmptyResponsesException; | ||
use oat\taoQtiTest\models\runner\RunnerServiceContext; | ||
use qtism\runtime\common\State; | ||
use qtism\runtime\tests\AssessmentItemSessionException; | ||
use qtism\runtime\tests\AssessmentTestSession; | ||
|
||
class QtiItemResponseValidator | ||
{ | ||
/** | ||
* @throws AssessmentItemSessionException | ||
* @throws common_exception_Error | ||
* @throws QtiRunnerEmptyResponsesException | ||
*/ | ||
public function validate(AssessmentTestSession $testSession, State $responses): void | ||
{ | ||
if ($this->getAllowSkip($testSession) && $responses->containsNullOnly()) { | ||
return; | ||
} | ||
|
||
if (!$this->getAllowSkip($testSession) && $responses->containsNullOnly()) { | ||
throw new QtiRunnerEmptyResponsesException(); | ||
} | ||
|
||
if ($this->getResponseValidation($testSession)) { | ||
$testSession->getCurrentAssessmentItemSession() | ||
->checkResponseValidityConstraints($responses); | ||
} | ||
} | ||
|
||
private function getResponseValidation(AssessmentTestSession $testSession): bool | ||
{ | ||
return $testSession->getRoute() | ||
->current() | ||
->getItemSessionControl() | ||
->getItemSessionControl() | ||
->mustValidateResponses(); | ||
} | ||
|
||
private function getAllowSkip(AssessmentTestSession $testSession): bool | ||
{ | ||
return $testSession->getRoute() | ||
->current() | ||
->getItemSessionControl() | ||
->getItemSessionControl() | ||
->doesAllowSkipping(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?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) 2024 (original work) Open Assessment Technologies SA; | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace oat\taoQtiTest\model\Service; | ||
|
||
use common_ext_Extension; | ||
use common_ext_ExtensionsManager as ExtensionsManager; | ||
use oat\generis\model\data\Ontology; | ||
use oat\oatbox\reporting\Report; | ||
|
||
class PluginManagerService | ||
{ | ||
private const PLUGIN_MAP = [ | ||
'allowSkipping' => 'enable-allow-skipping', | ||
'validateResponses' => 'enable-validate-responses', | ||
]; | ||
private Ontology $ontology; | ||
private ExtensionsManager $extensionsManager; | ||
private common_ext_Extension $extension; | ||
private array $config; | ||
|
||
public function __construct(Ontology $ontology, ExtensionsManager $extensionsManager) | ||
{ | ||
$this->ontology = $ontology; | ||
$this->extensionsManager = $extensionsManager; | ||
$this->extension = $this->extensionsManager->getExtensionById('taoQtiTest'); | ||
$this->config = $this->extension->getConfig('testRunner') ?? []; | ||
} | ||
|
||
/** | ||
* @param string[] $disablePlugins | ||
* @param Report $report | ||
* @throws \common_exception_Error | ||
*/ | ||
public function disablePlugin(array $disablePlugins, Report $report): void | ||
{ | ||
foreach ($disablePlugins as $plugin) { | ||
if (array_key_exists($plugin, self::PLUGIN_MAP)) { | ||
$report->add(new Report(Report::TYPE_INFO, 'Plugin ' . $plugin . ' has been disabled')); | ||
$this->config[self::PLUGIN_MAP[$plugin]] = false; | ||
} | ||
|
||
if (array_key_exists($plugin, $this->config)) { | ||
$report->add(new Report(Report::TYPE_INFO, 'Plugin ' . $plugin . ' has been disabled')); | ||
$this->config[$plugin] = false; | ||
} | ||
} | ||
$this->extension->setConfig('testRunner', $this->config); | ||
} | ||
|
||
public function enablePlugin(array $enablePlugins, Report $report): void | ||
{ | ||
$config = $this->getConfig(); | ||
|
||
foreach ($enablePlugins as $plugin) { | ||
if (array_key_exists($plugin, self::PLUGIN_MAP)) { | ||
$report->add(new Report(Report::TYPE_INFO, 'Plugin ' . $plugin . ' has been enabled')); | ||
$config[self::PLUGIN_MAP[$plugin]] = true; | ||
} | ||
|
||
if (array_key_exists($plugin, $config)) { | ||
$report->add(new Report(Report::TYPE_INFO, 'Plugin ' . $plugin . ' has been disabled')); | ||
$config[$plugin] = true; | ||
} | ||
} | ||
$this->extension->setConfig('testRunner', $config); | ||
} | ||
|
||
private function getConfig(): array | ||
{ | ||
return $this->extensionsManager->getExtensionById('taoQtiTest')->getConfig('testRunner'); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
models/classes/runner/QtiRunnerInvalidResponsesException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?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) 2024 (original work) Open Assessment Technologies SA ; | ||
*/ | ||
|
||
namespace oat\taoQtiTest\models\classes\runner; | ||
|
||
use common_Exception; | ||
use common_exception_UserReadableException; | ||
|
||
class QtiRunnerInvalidResponsesException extends common_Exception implements common_exception_UserReadableException | ||
{ | ||
public function __construct($message = 'A response to this item is invalid', $code = 200) | ||
{ | ||
parent::__construct($message, $code); | ||
} | ||
|
||
public function getUserMessage() | ||
{ | ||
return __('A response to this item is invalid.'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.