Skip to content
Open
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: 3 additions & 7 deletions Modules/Test/classes/class.ilObjTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4667,10 +4667,7 @@ public function createQuestionGUI($question_type, $question_id = -1): ?assQuesti
return null;
}

assQuestion::_includeClass($question_type, 1);

$question_type_gui = $question_type . 'GUI';
$question = new $question_type_gui();
$question = ilTestQuestions::instance()->getQuestionGUI($question_type);

if ($question_id > 0) {
$question->object->loadFromDb($question_id);
Expand Down Expand Up @@ -10075,9 +10072,8 @@ public function areObligationsEnabled(): bool
*/
public static function isQuestionObligationPossible($questionId): bool
{
$classConcreteQuestion = assQuestion::_getQuestionType($questionId);

assQuestion::_includeClass($classConcreteQuestion, 0);
$question_type = assQuestion::_getQuestionType($questionId);
$classConcreteQuestion = ilTestQuestions::instance()->getQuestionClass($question_type);

// static binder is not at work yet (in PHP < 5.3)
//$obligationPossible = $classConcreteQuestion::isObligationPossible();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public function fillRow(array $a_set): void
);

if ($this->isQuestionManagingEnabled()) {
$editHref = $this->getQuestionEditLink($a_set, $a_set['type_tag'] . 'GUI', 'editQuestion');
$editHref = $this->getQuestionEditLink($a_set, ilTestQuestions::instance()->getQuestionGUIClass($a_set['type_tag']), 'editQuestion');
$actions->addItem($this->lng->txt('edit_question'), '', $editHref);

$editPageHref = $this->getQuestionEditLink($a_set, 'ilAssQuestionPageGUI', 'edit');
Expand Down
31 changes: 10 additions & 21 deletions Modules/TestQuestionPool/classes/class.assQuestion.php
Original file line number Diff line number Diff line change
Expand Up @@ -2617,8 +2617,7 @@ public static function instantiateQuestion(int $question_id): assQuestion
throw new InvalidArgumentException('No question with ID ' . $question_id . ' exists');
}

assQuestion::_includeClass($question_type);
$question = new $question_type();
$question = ilTestQuestions::instance()->getQuestion($question_type);
$question->loadFromDb($question_id);

$feedbackObjectClassname = self::getFeedbackClassNameByQuestionType($question_type);
Expand Down Expand Up @@ -3162,6 +3161,9 @@ public function getActiveUserData(int $active_id): array
return array();
}

/**
* @deprecated this class does nothing
*/
public static function _includeClass(string $question_type, int $gui = 0): void
{
if (self::isCoreQuestionType($question_type)) {
Expand All @@ -3171,14 +3173,17 @@ public static function _includeClass(string $question_type, int $gui = 0): void

public static function getFeedbackClassNameByQuestionType(string $questionType): string
{
return str_replace('ass', 'ilAss', $questionType) . 'Feedback';
return ilTestQuestions::instance()->getFeedbackClass($questionType);
}

public static function isCoreQuestionType(string $questionType): bool
{
return file_exists("Modules/TestQuestionPool/classes/class.{$questionType}GUI.php");
}

/**
* @deprecated this class does nothing
*/
public static function includeCoreClass($questionType, $withGuiClass): void
{
if ($withGuiClass) {
Expand All @@ -3191,19 +3196,7 @@ public static function includeCoreClass($questionType, $withGuiClass): void

public static function _getQuestionTypeName($type_tag): string
{
global $DIC;
if (file_exists("./Modules/TestQuestionPool/classes/class." . $type_tag . ".php")) {
$lng = $DIC['lng'];
return $lng->txt($type_tag);
}
$component_factory = $DIC['component.factory'];

foreach ($component_factory->getActivePluginsInSlot("qst") as $pl) {
if ($pl->getQuestionType() === $type_tag) {
return $pl->getQuestionTypeTranslation();
}
}
return "";
return ilTestQuestions::instance()->getTypeTranslation($type_tag);
}

/**
Expand All @@ -3228,12 +3221,8 @@ public static function instantiateQuestionGUI(int $a_question_id): assQuestionGU
if (strcmp($a_question_id, "") != 0) {
$question_type = assQuestion::_getQuestionType($a_question_id);

assQuestion::_includeClass($question_type, 1);

$question_type_gui = $question_type . 'GUI';
$question_gui = new $question_type_gui();
$question_gui = ilTestQuestions::instance()->getQuestionGUI($question_type);
$question_gui->object->loadFromDb($a_question_id);

$feedbackObjectClassname = self::getFeedbackClassNameByQuestionType($question_type);
$question_gui->object->feedbackOBJ = new $feedbackObjectClassname($question_gui->object, $ilCtrl, $ilDB, $lng);

Expand Down
9 changes: 3 additions & 6 deletions Modules/TestQuestionPool/classes/class.assQuestionGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,7 @@ public static function _getQuestionGUI(string $question_type = '', int $question
return null;
}

assQuestion::_includeClass($question_type, 1);

$question_type_gui = $question_type . 'GUI';
$question = new $question_type_gui();
$question = ilTestQuestions::instance()->getQuestionGUI($question_type);

$feedbackObjectClassname = assQuestion::getFeedbackClassNameByQuestionType($question_type);
$question->object->feedbackOBJ = new $feedbackObjectClassname($question->object, $ilCtrl, $ilDB, $lng);
Expand All @@ -462,7 +459,7 @@ public static function _getGUIClassNameForId($a_q_id): string
*/
public static function _getClassNameForQType($q_type): string
{
return $q_type . "GUI";
return ilTestQuestions::instance()->getQuestionGUIClass($q_type);
}

public function populateJavascriptFilesRequiredForWorkForm(ilGlobalTemplateInterface $tpl): void
Expand Down Expand Up @@ -1711,7 +1708,7 @@ protected function setDefaultTabs(ilTabsGUI $ilTabs): void
$q_type = $this->object->getQuestionType();

if (strlen($q_type)) {
$classname = $q_type . "GUI";
$classname = ilTestQuestions::instance()->getQuestionGUIClass($q_type);
$this->ctrl->setParameterByClass(strtolower($classname), "sel_question_types", $q_type);
$this->ctrl->setParameterByClass(strtolower($classname), "q_id", $this->request->getQuestionId());
}
Expand Down
27 changes: 1 addition & 26 deletions Modules/TestQuestionPool/classes/class.ilAssQuestionList.php
Original file line number Diff line number Diff line change
Expand Up @@ -678,32 +678,7 @@ private function loadTaxonomyAssignmentData($parentObjId, $questionId): array

private function isActiveQuestionType(array $questionData): bool
{
if (!isset($questionData['plugin'])) {
return false;
}

if (!$questionData['plugin']) {
return true;
}

if (!$this->component_repository->getComponentByTypeAndName(
ilComponentInfo::TYPE_MODULES,
'TestQuestionPool'
)->getPluginSlotById('qst')->hasPluginName($questionData['plugin_name'])) {
return false;
}

return $this->component_repository
->getComponentByTypeAndName(
ilComponentInfo::TYPE_MODULES,
'TestQuestionPool'
)
->getPluginSlotById(
'qst'
)
->getPluginByName(
$questionData['plugin_name']
)->isActive();
return ilTestQuestions::instance()->isActive($questionData['type_tag']);
}

public function getDataArrayForQuestionId($questionId)
Expand Down
29 changes: 8 additions & 21 deletions Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -1380,18 +1380,8 @@ public static function _getQuestionTypes($all_tags = false, $fixOrder = false, $
$types = array();
while ($row = $ilDB->fetchAssoc($result)) {
if ($all_tags || (!in_array($row["question_type_id"], $forbidden_types))) {
$ilLog = $DIC['ilLog'];

if ($row["plugin"] == 0) {
$types[$lng->txt($row["type_tag"])] = $row;
} else {
$component_factory = $DIC['component.factory'];
//$plugins = $component_repository->getPluginSlotById("qst")->getActivePlugins();
foreach ($component_factory->getActivePluginsInSlot("qst") as $pl) {
if (strcmp($pl->getQuestionType(), $row["type_tag"]) == 0) {
$types[$pl->getQuestionTypeTranslation()] = $row;
}
}
if (ilTestQuestions::instance()->isActive($row["type_tag"])) {
$types[ilTestQuestions::instance()->getTypeTranslation($row["type_tag"])] = $row;
}
}
}
Expand Down Expand Up @@ -1432,15 +1422,7 @@ public static function getQuestionTypeTranslations(): array
$result = $ilDB->query("SELECT * FROM qpl_qst_type");
$types = array();
while ($row = $ilDB->fetchAssoc($result)) {
if ($row["plugin"] == 0) {
$types[$row['type_tag']] = $lng->txt($row["type_tag"]);
} else {
foreach ($component_factory->getActivePluginsInSlot("qst") as $pl) {
if (strcmp($pl->getQuestionType(), $row["type_tag"]) == 0) {
$types[$row['type_tag']] = $pl->getQuestionTypeTranslation();
}
}
}
$types[$row['type_tag']] = ilTestQuestions::instance()->getTypeTranslation($row['type_tag']);
}
ksort($types);
return $types;
Expand Down Expand Up @@ -1478,6 +1460,7 @@ public static function &_getSelfAssessmentQuestionTypes($all_tags = false): arra
"assErrorText" => 10,
"assLongMenu" => 11
);
$next = 12;
$satypes = array();
$qtypes = ilObjQuestionPool::_getQuestionTypes($all_tags);
foreach ($qtypes as $k => $t) {
Expand All @@ -1486,6 +1469,10 @@ public static function &_getSelfAssessmentQuestionTypes($all_tags = false): arra
$t["order"] = $allowed_types[$t["type_tag"]];
$satypes[$k] = $t;
}
elseif (ilTestQuestions::instance()->supportsOffline($t["type_tag"])) {
$t["order"] = $next++;
$satypes[$k] = $t;
}
}
return $satypes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,29 +124,7 @@ public function setPluginName($pluginName): void
*/
public function isImportable(): bool
{
if (!$this->isPlugin()) {
return true;
}

// Plugins MAY overwrite this method an report back their activation status
if (!$this->component_repository->getComponentByTypeAndName(
ilComponentInfo::TYPE_MODULES,
'TestQuestionPool'
)->getPluginSlotById('qst')->hasPluginName($this->getPluginName())) {
return false;
}

return $this->component_repository
->getComponentByTypeAndName(
ilComponentInfo::TYPE_MODULES,
'TestQuestionPool'
)
->getPluginSlotById(
'qst'
)
->getPluginByName(
$this->getPluginName()
)->isActive();
return ilTestQuestions::instance()->isImportable($this->getTag());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ public function fillRow(array $a_set): void
$this->ctrl->getLinkTargetByClass('ilAssQuestionPreviewGUI', ilAssQuestionPreviewGUI::CMD_STATISTICS)
);
if ($this->getEditable()) {
$editHref = $this->ctrl->getLinkTargetByClass($a_set['type_tag'] . 'GUI', 'editQuestion');
$editHref = $this->ctrl->getLinkTargetByClass($class, 'editQuestion');
$actions->addItem($this->lng->txt('edit_question'), '', $editHref);

$editPageHref = $this->ctrl->getLinkTargetByClass('ilAssQuestionPageGUI', 'edit');
Expand Down
7 changes: 6 additions & 1 deletion Services/Init/classes/Dependencies/InitUIFramework.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public function init(\ILIAS\DI\Container $c): void
$c["ui.factory.menu"],
$c["ui.factory.symbol"],
$c["ui.factory.toast"],
$c["ui.factory.legacy"]
$c["ui.factory.legacy"],
$c["ui.factory.question"],
);
};
$c["ui.upload_limit_resolver"] = function ($c) {
Expand Down Expand Up @@ -285,5 +286,9 @@ public function init(\ILIAS\DI\Container $c): void
$c["ui.pathresolver"] = function ($c): ILIAS\UI\Implementation\Render\ImagePathResolver {
return new ilImagePathResolver();
};
$c["ui.factory.question"] = function ($c) {
return new ILIAS\UI\Implementation\Component\Question\Factory();
};

}
}
52 changes: 52 additions & 0 deletions Services/Question/classes/Core/class.ilQuestionBaseRepo.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

class ilQuestionBaseRepo
{
private ilDBInterface $db;

public function __Construct(ilDBInterface $db) {
$this->db = $db;
}


public function getBaseSettingsForId(int $question_id): ?ilQuestionBaseSettings
{
$query = "SELECT qpl_questions.* FROM qpl_questions WHERE question_id = "
. $this->db->quote($question_id, 'integer');

$result = $this->db->query($query);

if ($row = $this->db->fetchAssoc($result)) {

return new ilQuestionBaseSettings(
(int) $row['question_id'],
(int) $row['question_type_fi'],
(int) $row['obj_fi'],
(string) $row['title'],
(string) $row['description'],
(string) $row['question_text'],
(string) $row['author'],
(int) $row['owner'],
(int) substr($row['working_time'], 0, 2) * 3600
+ (int) substr($row['working_time'], 3, 2) * 60
+ (int) substr($row['working_time'], 6, 2),
(int) $row['points'],
(int) $row['nr_of_tries'],
(bool) $row['complete'],
(int) $row['created'],
(int) $row['tstamp'],
$row['original_id'] ? (int) $row['original_id'] : null,
(string) $row['external_id'],
(string) $row['add_cont_edit_mode'],
(string) $row['lifecycle']
);
}
return null;
}

public function saveBaseSettings(ilQuestionBaseSettings $settings) : void
{
// todo
}

}
Loading