Skip to content

Commit

Permalink
Merge branch 'release-46.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions committed May 10, 2023
2 parents 2b19bd8 + a2cbbae commit a78281a
Show file tree
Hide file tree
Showing 281 changed files with 5,763 additions and 1,717 deletions.
81 changes: 55 additions & 26 deletions actions/class.Creator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
* Copyright (c) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT);
*/

use function GuzzleHttp\Psr7\stream_for;

use oat\taoQtiTest\models\TestCategoryPresetProvider;
use oat\taoQtiTest\models\TestModelService;
use oat\generis\model\data\event\ResourceUpdated;
use oat\oatbox\event\EventManager;

use function GuzzleHttp\Psr7\stream_for;

/**
* QTI test Creator Controller.
*
Expand All @@ -35,43 +35,60 @@
*/
class taoQtiTest_actions_Creator extends tao_actions_CommonModule
{

/**
* Render the creator base view
*/
/**
* Render the creator base view
*/
public function index()
{

$labels = [];
$testUri = $this->getRequestParameter('uri');
$testModel = $this->getServiceManager()->get(TestModelService::SERVICE_ID);
$labels = [];
$testUri = $this->getRequestParameter('uri');
$testModel = $this->getServiceManager()->get(TestModelService::SERVICE_ID);

$items = $testModel->getItems(new core_kernel_classes_Resource(tao_helpers_Uri::decode($testUri)));
$items = $testModel->getItems(new core_kernel_classes_Resource(tao_helpers_Uri::decode($testUri)));
foreach ($items as $item) {
$labels[$item->getUri()] = $item->getLabel();
}
$this->setData('labels', json_encode(tao_helpers_Uri::encodeArray($labels, tao_helpers_Uri::ENCODE_ARRAY_KEYS)));
$this->setData(
'labels',
json_encode(tao_helpers_Uri::encodeArray($labels, tao_helpers_Uri::ENCODE_ARRAY_KEYS))
);

$runtimeConfig = $this->getRuntimeConfig();
$categoriesPresetService = $this->getServiceManager()->get(TestCategoryPresetProvider::SERVICE_ID);
$this->setData('categoriesPresets', json_encode($categoriesPresetService->getAvailablePresets($runtimeConfig)));
$runtimeConfig = $this->getRuntimeConfig();
$categoriesPresetService = $this->getServiceManager()->get(TestCategoryPresetProvider::SERVICE_ID);
$this->setData('categoriesPresets', json_encode($categoriesPresetService->getAvailablePresets($runtimeConfig)));

$this->setData('loadUrl', _url('getTest', null, null, ['uri' => $testUri]));
$this->setData('saveUrl', _url('saveTest', null, null, ['uri' => $testUri]));
$this->setData('loadUrl', _url('getTest', null, null, ['uri' => $testUri]));
$this->setData('saveUrl', _url('saveTest', null, null, ['uri' => $testUri]));

if (common_ext_ExtensionsManager::singleton()->isInstalled('taoBlueprints')) {
$this->setData('blueprintsByIdUrl', _url('getBlueprintsByIdentifier', 'Blueprints', 'taoBlueprints'));
$this->setData('blueprintsByTestSectionUrl', _url('getBlueprintsByTestSection', 'Blueprints', 'taoBlueprints', ['test' => $testUri]));
$this->setData(
'blueprintsByIdUrl',
_url(
'getBlueprintsByIdentifier',
'Blueprints',
'taoBlueprints'
)
);
$this->setData(
'blueprintsByTestSectionUrl',
_url(
'getBlueprintsByTestSection',
'Blueprints',
'taoBlueprints',
['test' => $testUri]
)
);
}
$this->setData('identifierUrl', _url('getIdentifier', null, null, ['uri' => $testUri]));
$this->setData('identifierUrl', _url('getIdentifier', null, null, ['uri' => $testUri]));

$guidedNavigation = false;
$guidedNavigation = false;
if (is_array($runtimeConfig) && isset($runtimeConfig['guidedNavigation'])) {
$guidedNavigation = $runtimeConfig['guidedNavigation'];
}
$this->setData('guidedNavigation', json_encode($guidedNavigation == true));
$this->setData('guidedNavigation', json_encode($guidedNavigation == true));

$this->setView('creator.tpl');
$this->setView('creator.tpl');
}

/**
Expand Down Expand Up @@ -109,17 +126,26 @@ public function saveTest()

//save the blueprint if the extension is installed
if (common_ext_ExtensionsManager::singleton()->isInstalled('taoBlueprints')) {
$testSectionLinkService = $this->getServiceManager()->get(\oat\taoBlueprints\model\TestSectionLinkService::SERVICE_ID);
$testSectionLinkService = $this->getServiceManager()->get(
\oat\taoBlueprints\model\TestSectionLinkService::SERVICE_ID
);
$model = json_decode($parameters['model'], true);
if (isset($model['testParts'])) {
foreach ($model['testParts'] as $testPart) {
if (isset($testPart['assessmentSections'])) {
foreach ($testPart['assessmentSections'] as $section) {
if (isset($section['blueprint'])) {
if (!empty($section['blueprint'])) {
$testSectionLinkService->setBlueprintForTestSection($test, $section['identifier'], $section['blueprint']);
$testSectionLinkService->setBlueprintForTestSection(
$test,
$section['identifier'],
$section['blueprint']
);
} else {
$testSectionLinkService->removeBlueprintForTestSection($test, $section['identifier']);
$testSectionLinkService->removeBlueprintForTestSection(
$test,
$section['identifier']
);
}
}
}
Expand Down Expand Up @@ -177,7 +203,10 @@ protected function getCurrentTest()
*/
protected function getRuntimeConfig()
{
$extension = $this->getServiceLocator()->get(\common_ext_ExtensionsManager::SERVICE_ID)->getExtensionById('taoQtiTest');
$extension = $this
->getServiceLocator()
->get(\common_ext_ExtensionsManager::SERVICE_ID)
->getExtensionById('taoQtiTest');
return $extension->getConfig('testRunner');
}
}
5 changes: 2 additions & 3 deletions actions/class.ItemRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

class taoQtiTest_actions_ItemRunner extends AbstractQtiItemRunner
{

/**
* The endpoint specific to QTI Items in a QTI Test runner context
* @return string
Expand All @@ -13,7 +12,7 @@ protected function getResultServerEndpoint()
{
return _url('', 'TestRunner', 'taoQtiTest');
}

/**
* Define additional parameters for the result server
* @return array
Expand All @@ -26,7 +25,7 @@ protected function getResultServerParams()
'itemDataPath' => $this->getRequestParameter('itemDataPath')
];
}

protected function selectView()
{
$this->setInitialVariableElements();
Expand Down
11 changes: 9 additions & 2 deletions actions/class.Items.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ class taoQtiTest_actions_Items extends tao_actions_CommonModule
public function get()
{
$items = [];
$propertyFilters = [taoItems_models_classes_ItemsService::PROPERTY_ITEM_MODEL => taoItems_models_classes_itemModel::CLASS_URI_QTI];
$propertyFilters = [
// phpcs:disable Generic.Files.LineLength
taoItems_models_classes_ItemsService::PROPERTY_ITEM_MODEL => taoItems_models_classes_itemModel::CLASS_URI_QTI
// phpcs:enable Generic.Files.LineLength
];
$options = ['recursive' => true, 'like' => true, 'limit' => 50];
$notEmpty = filter_var($this->getRequestParameter('notempty'), FILTER_VALIDATE_BOOLEAN);

Expand Down Expand Up @@ -136,7 +140,10 @@ public function getItems()
public function getCategories()
{
if (!$this->hasRequestParameter('uris')) {
$this->returnJson(__("At least one mandatory parameter was required but found missing in your request"), 412);
$this->returnJson(
__("At least one mandatory parameter was required but found missing in your request"),
412
);
return;
}

Expand Down
4 changes: 3 additions & 1 deletion actions/class.OfflineRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ public function init()
*/
private function attachBranchingRulesToResponse(array $testMap, QtiRunnerServiceContext $serviceContext)
{
$serializedTestDefinition = $this->getTestDefinitionSerializerService()->getSerializedTestDefinition($serviceContext);
$serializedTestDefinition = $this->getTestDefinitionSerializerService()->getSerializedTestDefinition(
$serviceContext
);
$branchRuleExtender = new TestMapBranchRuleExtender();

return $branchRuleExtender->getTestMapWithBranchRules($testMap, $serializedTestDefinition);
Expand Down
37 changes: 29 additions & 8 deletions actions/class.Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,17 @@ protected function getServiceContext()
$delivery = $execution->getDelivery();
$container = $this->getRuntimeService()->getDeliveryContainer($delivery->getUri());
if (!$container instanceof QtiTestDeliveryContainer) {
throw new common_Exception('Non QTI test container ' . get_class($container) . ' in qti test runner');
throw new common_Exception(
'Non QTI test container ' . get_class($container) . ' in qti test runner'
);
}
$testDefinition = $container->getSourceTest($execution);
$testCompilation = $container->getPrivateDirId($execution) . '|' . $container->getPublicDirId($execution);
$this->serviceContext = $this->getRunnerService()->getServiceContext($testDefinition, $testCompilation, $testExecution);
$this->serviceContext = $this->getRunnerService()->getServiceContext(
$testDefinition,
$testCompilation,
$testExecution
);
}

return $this->serviceContext;
Expand Down Expand Up @@ -234,7 +240,9 @@ protected function getErrorResponse($e = null, $prevResponse = [])
/** @var QtiRunnerMessageService $messageService */
$messageService = $this->getServiceManager()->get(QtiRunnerMessageService::SERVICE_ID);
try {
// phpcs:disable Generic.Files.LineLength
$response['message'] = __($messageService->getStateMessage($this->serviceContext->getTestSession()));
// phpcs:enable Generic.Files.LineLength
} catch (common_exception_Error $e) {
$response['message'] = null;
}
Expand Down Expand Up @@ -392,14 +400,18 @@ public function getItem()
$response['success'] = false;

$userIdentifier = common_session_SessionManager::getSession()->getUser()->getIdentifier();
common_Logger::e("Unable to retrieve item with identifier '${itemIdentifier}' for user '${userIdentifier}'.");
common_Logger::e(
"Unable to retrieve item with identifier '${itemIdentifier}' for user '${userIdentifier}'."
);
}

$this->getRunnerService()->startTimer($serviceContext);
} catch (common_Exception $e) {
$userIdentifier = common_session_SessionManager::getSession()->getUser()->getIdentifier();
$msg = __CLASS__ . "::getItem(): Unable to retrieve item with identifier '${itemIdentifier}' for user '${userIdentifier}'.\n";
$msg .= "Exception of type '" . get_class($e) . "' was thrown in '" . $e->getFile() . "' l." . $e->getLine() . " with message '" . $e->getMessage() . "'.";
$msg = __CLASS__ . "::getItem(): Unable to retrieve item with identifier '${itemIdentifier}' for "
. "user '${userIdentifier}'.\n";
$msg .= "Exception of type '" . get_class($e) . "' was thrown in '" . $e->getFile() . "' l." . $e->getLine()
. " with message '" . $e->getMessage() . "'.";

if ($e instanceof common_exception_Unauthorized) {
// Log as debug as not being authorized is not a "real" system error.
Expand Down Expand Up @@ -528,11 +540,17 @@ protected function saveItemResponses($emptyAllowed = true)
$itemResponse = $this->getItemResponse();

if ($serviceContext->getCurrentAssessmentItemRef()->getIdentifier() !== $itemIdentifier) {
throw new QtiRunnerItemResponseException(__('Item response identifier does not match current item'));
throw new QtiRunnerItemResponseException(
__('Item response identifier does not match current item')
);
}

if (!is_null($itemResponse) && !empty($itemDefinition)) {
$responses = $this->getRunnerService()->parsesItemResponse($serviceContext, $itemDefinition, $itemResponse);
$responses = $this->getRunnerService()->parsesItemResponse(
$serviceContext,
$itemDefinition,
$itemResponse
);

//still verify allowSkipping & empty responses
if (
Expand Down Expand Up @@ -564,7 +582,10 @@ public function submitItem()
// as we need to store the item state whatever the test state is
$this->validateSecurityToken();
$serviceContext = $this->getServiceContext();
$itemRef = $this->getRunnerService()->getItemHref($serviceContext, $this->getRequestParameter('itemDefinition'));
$itemRef = $this->getRunnerService()->getItemHref(
$serviceContext,
$this->getRequestParameter('itemDefinition')
);

if (!$this->getRunnerService()->isTerminated($serviceContext)) {
$this->endItemTimer();
Expand Down
33 changes: 18 additions & 15 deletions actions/class.TestContent.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
Expand All @@ -18,7 +19,7 @@
*
*
*/

/**
* Tests Content Controller provide access to the files of an test
*
Expand All @@ -39,31 +40,33 @@ public function files()
}
$testUri = $this->getRequestParameter('uri');
$test = new core_kernel_classes_Resource($testUri);

if (!$this->hasRequestParameter('lang')) {
throw new common_exception_MissingParameter('lang', __METHOD__);
}
$testLang = $this->getRequestParameter('lang');

$subPath = $this->hasRequestParameter('path') ? $this->getRequestParameter('path') : '/';
$depth = $this->hasRequestParameter('depth') ? $this->getRequestParameter('depth') : 1;

//build filters
$filters = [];
if ($this->hasRequestParameter('filters')) {
$filterParameter = $this->getRequestParameter('filters');
if (!empty($filterParameter)) {
if (preg_match('/\/\*/', $filterParameter)) {
common_Logger::w('Stars mime type are not yet supported, filter "' . $filterParameter . '" will fail');
common_Logger::w(
'Stars mime type are not yet supported, filter "' . $filterParameter . '" will fail'
);
}
$filters = array_map('trim', explode(',', $filterParameter));
}
}

$data = taoQtiTest_helpers_ResourceManager::buildDirectory($test, $testLang, $subPath, $depth, $filters);
echo json_encode($data);
}

/**
* Upload a file to the item directory
*
Expand All @@ -76,28 +79,28 @@ public function upload()
}
$testUri = $this->getRequestParameter('uri');
$test = new core_kernel_classes_Resource($testUri);

if (!$this->hasRequestParameter('lang')) {
throw new common_exception_MissingParameter('lang', __METHOD__);
}
$testLang = $this->getRequestParameter('lang');

if (!$this->hasRequestParameter('path')) {
throw new common_exception_MissingParameter('path', __METHOD__);
}

//TODO path traversal and null byte poison check ?
$baseDir = taoQtiTest_helpers_ResourceManager::getBaseDir($test);
$relPath = trim($this->getRequestParameter('path'), '/');
$relPath = empty($relPath) ? '' : $relPath . '/';

$file = tao_helpers_Http::getUploadedFile('content');
$fileName = $file['name'];

if (!move_uploaded_file($file["tmp_name"], $baseDir . $relPath . $fileName)) {
throw new common_exception_Error('Unable to move uploaded file');
}

$fileData = taoQtiTest_helpers_ResourceManager::buildFile($test, $testLang, $relPath . $fileName);
echo json_encode($fileData);
}
Expand All @@ -113,14 +116,14 @@ public function download()
}
$testUri = $this->getRequestParameter('uri');
$test = new core_kernel_classes_Resource($testUri);

if (!$this->hasRequestParameter('path')) {
throw new common_exception_MissingParameter('path', __METHOD__);
}

$baseDir = taoQtiTest_helpers_ResourceManager::getBaseDir($test);
$path = $baseDir . ltrim($this->getRequestParameter('path'), '/');

tao_helpers_Http::returnFile($path);
}
}
Loading

0 comments on commit a78281a

Please sign in to comment.