Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Modules/Test/classes/class.ilObjTestGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -1303,8 +1303,14 @@ public function uploadTst()
$this->ctrl->redirect($this, 'create');
return false;
}
$qtiParser = new ilQTIParser($qti_file, ilQTIParser::IL_MO_VERIFY_QTI, 0, "");
$qtiParser->startParsing();
$qtiParser = new ilQTIParser($qti_file, ilQTIParser::IL_MO_VERIFY_QTI, 0, "", [], true);
try {
$qtiParser->startParsing();
} catch (ilSaxParserException) {
$this->tpl->setOnScreenMessage('failure', $this->lng->txt('import_file_not_valid'), true);
$this->ctrl->redirect($this, 'create');
return false;
}
$founditems = $qtiParser->getFoundItems();

$complete = 0;
Expand Down
13 changes: 7 additions & 6 deletions Modules/TestQuestionPool/classes/class.assFormulaQuestion.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ public function addResultUnit($result, $unit): void
}
}

/**
* @return assFormulaQuestionUnit[]
*/
public function getResultUnits(assFormulaQuestionResult $result): array
{
if (!isset($this->resultunits[$result->getResult()])) {
Expand Down Expand Up @@ -368,13 +371,11 @@ public function substituteVariables(array $userdata, bool $graphicalOutput = fal
if (is_array($userdata)) {
foreach ($result_units as $unit) {
if (isset($userdata[$result]["unit"]) && $userdata[$result]["unit"] == $unit->getId()) {
$units = $unit->getUnit();
$units = $unit->getSanitizedUnit();
}
}
} else {
if ($resObj->getUnit()) {
$units = $resObj->getUnit()->getUnit();
}
} elseif ($resObj->getUnit()) {
$units = $resObj->getUnit()->getSanitizedUnit();
}
} else {
$units = '<select name="result_' . $result . '_unit">';
Expand All @@ -388,7 +389,7 @@ public function substituteVariables(array $userdata, bool $graphicalOutput = fal
$units .= ' selected="selected"';
}
}
$units .= '>' . $unit->getUnit() . '</option>';
$units .= '>' . $unit->getSanitizedUnit() . '</option>';
}
$units .= '</select>';
}
Expand Down
32 changes: 22 additions & 10 deletions Modules/TestQuestionPool/classes/class.assFormulaQuestionUnit.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -18,6 +16,8 @@
*
*********************************************************************/

declare(strict_types=1);

/**
* Formula Question Unit
* @author Helmut Schottmüller <helmut.schottmueller@mac.com>
Expand All @@ -40,7 +40,7 @@ public function initFormArray(array $data): void
$this->factor = (float) $data['factor'];
$this->baseunit = (int) $data['baseunit_fi'];
$this->baseunit_title = $data['baseunit_title'] ?? null;
$this->category = (int) $data['category'];
$this->category = (int) $data['category_fi'];
$this->sequence = (int) $data['sequence'];
}

Expand All @@ -64,6 +64,11 @@ public function getUnit(): string
return $this->unit;
}

public function getSanitizedUnit(): string
{
return htmlspecialchars($this->getUnit(), ENT_QUOTES | ENT_SUBSTITUTE, 'utf-8');
}

public function setSequence(int $sequence): void
{
$this->sequence = $sequence;
Expand Down Expand Up @@ -108,6 +113,11 @@ public function getBaseunitTitle(): ?string
return $this->baseunit_title;
}

public function getSanitizedBaseunitTitle(): ?string
{
return $this->sanitizeString($this->getBaseunitTitle() ?? '');
}

public function setCategory(int $category): void
{
$this->category = $category;
Expand All @@ -122,14 +132,11 @@ public function getDisplayString(): string
{
global $DIC;

$lng = $DIC->language();

$unit = $this->getUnit();
if (strcmp('-qpl_qst_formulaquestion_' . $unit . '-', $lng->txt('qpl_qst_formulaquestion_' . $unit)) !== 0) {
$unit = $lng->txt('qpl_qst_formulaquestion_' . $unit);
}

return $unit;
$txt = $DIC->language()->txt("qpl_qst_formulaquestion_{$unit}");
return strcmp("-qpl_qst_formulaquestion_{$unit}-", $txt) !== 0
? $this->sanitizeString($txt)
: $this->getSanitizedUnit();
}

public static function lookupUnitFactor(int $a_unit_id): float
Expand All @@ -147,4 +154,9 @@ public static function lookupUnitFactor(int $a_unit_id): float

return (float) $row['factor'];
}

private function sanitizeString(string $string): string
{
return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, 'utf-8');
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -18,6 +16,8 @@
*
*********************************************************************/

declare(strict_types=1);

/**
* Formula Question Unit Category
* @author Helmut Schottmüller <helmut.schottmueller@mac.com>
Expand Down Expand Up @@ -56,6 +56,11 @@ public function getCategory(): string
return $this->category;
}

public function getSanitizedCategory(): string
{
return $this->sanitizeString($this->getCategory());
}

public function setQuestionFi(int $question_fi): void
{
$this->question_fi = $question_fi;
Expand All @@ -70,13 +75,15 @@ public function getDisplayString(): string
{
global $DIC;

$lng = $DIC->language();

$category = $this->getCategory();
if (strcmp('-qpl_qst_formulaquestion_' . $category . '-', $lng->txt('qpl_qst_formulaquestion_' . $category)) !== 0) {
$category = $lng->txt('qpl_qst_formulaquestion_' . $category);
}
$txt = $DIC->language()->txt("qpl_qst_formulaquestion_{$category}");
return strcmp("-qpl_qst_formulaquestion_{$category}-", $txt) !== 0
? $this->sanitizeString($txt)
: $this->getSanitizedCategory();
}

return $category;
private function sanitizeString(string $string): string
{
return htmlspecialchars($string, ENT_QUOTES | ENT_SUBSTITUTE, 'utf-8');
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -18,6 +16,8 @@
*
*********************************************************************/

declare(strict_types=1);

/**
* Class ilLocalUnitConfigurationGUI
*/
Expand Down Expand Up @@ -143,7 +143,9 @@ protected function confirmImportGlobalCategory(): void
protected function confirmImportGlobalCategories(array $category_ids): void
{
// @todo: Confirmation Currently not implemented, so forward to import
$this->importGlobalCategories($category_ids);
$category_ids === []
? $this->showGlobalUnitCategories()
: $this->importGlobalCategories($category_ids);
}

protected function importGlobalCategories(array $category_ids): void
Expand Down Expand Up @@ -171,9 +173,9 @@ protected function importGlobalCategories(array $category_ids): void

if ($i) {
$this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
$this->ctrl->setParameter($this, 'question_fi', $this->request->getQuestionId());
}

$this->ctrl->setParameter($this, 'question_fi', 0);
$this->ctrl->redirect($this, 'showLocalUnitCategories');
}
}
21 changes: 8 additions & 13 deletions Modules/TestQuestionPool/classes/class.ilUnitConfigurationGUI.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php

declare(strict_types=1);

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand All @@ -18,6 +16,8 @@
*
*********************************************************************/

declare(strict_types=1);

/**
* Class ilUnitConfigurationGUI
*/
Expand Down Expand Up @@ -81,15 +81,10 @@ public function executeCommand(): void
{
$cmd = $this->ctrl->getCmd($this->getDefaultCommand());
$this->checkPermissions($cmd);
switch ($cmd) {
case 'confirmImportGlobalCategories':
$category_ids = $this->request->raw('category_ids');
$this->$cmd($category_ids);
break;
default:
$this->$cmd();
break;
}
match ($cmd) {
'confirmImportGlobalCategories' => $this->$cmd($this->request->getUnitCategoryIds()),
default => $this->$cmd(),
};

$this->handleSubtabs();
}
Expand Down Expand Up @@ -483,8 +478,8 @@ protected function showUnitsOfCategory(): void
/** @var assFormulaQuestionUnit $unit */
$data[] = [
'unit_id' => $unit->getId(),
'unit' => $unit->getUnit(),
'baseunit' => $unit->getBaseunitTitle(),
'unit' => $unit->getSanitizedUnit(),
'baseunit' => $unit->getSanitizedBaseunitTitle(),
'baseunit_id' => $unit->getBaseUnit(),
'factor' => $unit->getFactor(),
'sequence' => $unit->getSequence(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* This file is part of ILIAS, a powerful learning management system
* published by ILIAS open source e-Learning e.V.
Expand Down Expand Up @@ -65,6 +66,53 @@ public function toXML($a_include_header = true, $a_include_binary = true, $a_shu
$a_xml_writer->xmlElement("fieldlabel", null, "points");
$a_xml_writer->xmlElement("fieldentry", null, $this->object->getPoints());
$a_xml_writer->xmlEndTag("qtimetadatafield");

/** @var assFormulaQuestion $object */
$object = $this->object;
$unit_repository = $object->getUnitRepository();

$question_id = $this->object->getId();
$unit_categories = array_filter(
$unit_repository->getAllUnitCategories(),
static fn(object $object): bool => $object->getQuestionFi() === $question_id,
);

$a_xml_writer->xmlStartTag("qtimetadatafield");
$a_xml_writer->xmlElement("fieldlabel", null, "unit_categories");
/** @var assFormulaQuestionUnitCategory $unit_category */
foreach ($unit_categories as $unit_category) {
$a_xml_writer->xmlElement(
"fieldentry",
["id" => $unit_category->getId(), "question_fi" => $unit_category->getQuestionFi()],
$unit_category->getCategory()
);
}
$a_xml_writer->xmlEndTag("qtimetadatafield");

$categorized_units = array_filter(
$unit_repository->getCategorizedUnits(),
static fn(object $object): bool => $object instanceof assFormulaQuestionUnit,
);

$a_xml_writer->xmlStartTag("qtimetadatafield");
$a_xml_writer->xmlElement("fieldlabel", null, "units");
/** @var assFormulaQuestionUnit $categorized_unit */
foreach ($categorized_units as $categorized_unit) {
$a_xml_writer->xmlElement(
"fieldentry",
[
"id" => $categorized_unit->getId(),
"sequence" => $categorized_unit->getSequence(),
"factor" => $categorized_unit->getFactor(),
"base_unit" => $categorized_unit->getBaseUnit(),
"base_unit_title" => $categorized_unit->getBaseunitTitle(),
"category" => $categorized_unit->getCategory()
],
$categorized_unit->getUnit()
);
}
$a_xml_writer->xmlEndTag("qtimetadatafield");

foreach ($this->object->getVariables() as $variable) {
$var = [
"precision" => $variable->getPrecision(),
Expand Down
Loading