diff --git a/classes/Interface/Settings/interface.xdhtSettingsInterface.php b/classes/Interface/Settings/interface.xdhtSettingsInterface.php index c538793..f6ca609 100644 --- a/classes/Interface/Settings/interface.xdhtSettingsInterface.php +++ b/classes/Interface/Settings/interface.xdhtSettingsInterface.php @@ -121,6 +121,17 @@ public function getRecommenderSystemServer() : int; public function setRecommenderSystemServer(int $recommender_system_server)/*:void*/ ; + /** + * @return array + */ + public function getRecommenderSystemServerBuiltInDebugCompetences() : array; + + + /** + * @param array $recommender_system_server_built_in_debug_competences + */ + public function setRecommenderSystemServerBuiltInDebugCompetences(array $recommender_system_server_built_in_debug_competences)/*:void*/ ; + /** * @return int */ diff --git a/classes/Recommender/debug/api/v1/_helper/_init.php b/classes/Recommender/debug/api/v1/_helper/_init.php index 9dcc468..73f9ca2 100644 --- a/classes/Recommender/debug/api/v1/_helper/_init.php +++ b/classes/Recommender/debug/api/v1/_helper/_init.php @@ -24,6 +24,22 @@ $random_recomander_id = $all_questions[rand(0, (count($all_questions) - 1))]; +$random_competences = $facade->settings()->getRecommenderSystemServerBuiltInDebugCompetences(); +if (!empty($random_competences)) { + $random_competences = array_map(function (array $skill_ids) : int { + return $skill_ids[rand(0, (count($skill_ids) - 1))]; + }, array_reduce($random_competences, function (array $random_competences, array $competence) : array { + if (!isset($random_competences[$competence["competence_id"]])) { + $random_competences[$competence["competence_id"]] = []; + } + $random_competences[$competence["competence_id"]][] = $competence["skill_id"]; + + return $random_competences; + }, [])); +} else { + $random_competences = null; +} + try { $post = json_decode(file_get_contents("php://input"), true); } catch (Throwable $ex) { diff --git a/classes/Recommender/debug/api/v1/answer.php b/classes/Recommender/debug/api/v1/answer.php index 6cf062b..6932c42 100644 --- a/classes/Recommender/debug/api/v1/answer.php +++ b/classes/Recommender/debug/api/v1/answer.php @@ -13,11 +13,7 @@ "progress" => 0.5, "progress_type" => RecommenderResponse::MESSAGE_TYPE_QUESTION, "learning_progress_status" => RecommenderResponse::LEARNING_PROGRESS_STATUS_IN_PROGRESS, - "competences" => [ - 11 => 12, - 12 => 15, - 13 => 18 - ] + "competences" => $random_competences ]; require_once __DIR__ . "/_helper/_output.php"; diff --git a/classes/Recommender/debug/api/v1/rating.php b/classes/Recommender/debug/api/v1/rating.php index 7b831e5..ec3c030 100644 --- a/classes/Recommender/debug/api/v1/rating.php +++ b/classes/Recommender/debug/api/v1/rating.php @@ -13,11 +13,7 @@ "progress" => 1, "progress_type" => RecommenderResponse::MESSAGE_TYPE_SUCCESS, "learning_progress_status" => RecommenderResponse::LEARNING_PROGRESS_STATUS_COMPLETED, - "competences" => [ - 11 => 13, - 12 => 16, - 13 => 19 - ] + "competences" => $random_competences ]; require_once __DIR__ . "/_helper/_output.php"; diff --git a/classes/Recommender/debug/api/v1/start.php b/classes/Recommender/debug/api/v1/start.php index a431ed9..16539da 100644 --- a/classes/Recommender/debug/api/v1/start.php +++ b/classes/Recommender/debug/api/v1/start.php @@ -13,11 +13,7 @@ "progress" => 0, "progress_type" => RecommenderResponse::MESSAGE_TYPE_INFO, "learning_progress_status" => RecommenderResponse::LEARNING_PROGRESS_STATUS_NOT_ATTEMPTED, - "competences" => [ - 11 => 11, - 12 => 14, - 13 => 17 - ] + "competences" => $random_competences ]; require_once __DIR__ . "/_helper/_output.php"; diff --git a/classes/Settings/class.xdhtSettings.php b/classes/Settings/class.xdhtSettings.php index f5ef961..e7c0fe4 100644 --- a/classes/Settings/class.xdhtSettings.php +++ b/classes/Settings/class.xdhtSettings.php @@ -88,6 +88,14 @@ class xdhtSettings extends ActiveRecord implements xdhtSettingsInterface * @db_is_notnull true */ protected $recommender_system_server = self::RECOMMENDER_SYSTEM_SERVER_EXTERNAL; + /** + * @var array + * + * @db_has_field true + * @db_fieldtype text + * @db_is_notnull true + */ + protected $rec_sys_ser_bui_in_deb_comp = []; /** * @var int * @@ -117,6 +125,38 @@ public function getConnectorContainerName() } + /** + * @inheritDoc + */ + public function sleep(/*string*/ $field_name) + { + $field_value = $this->{$field_name}; + + switch ($field_name) { + case "rec_sys_ser_bui_in_deb_comp": + return json_encode($field_value); + + default: + return null; + } + } + + + /** + * @inheritDoc + */ + public function wakeUp(/*string*/ $field_name, $field_value) + { + switch ($field_name) { + case "rec_sys_ser_bui_in_deb_comp": + return json_decode($field_value, true) ?? []; + + default: + return null; + } + } + + /** * @return int */ @@ -283,6 +323,24 @@ public function setRecommenderSystemServer(int $recommender_system_server)/*:voi } + /** + * @inheritDoc + */ + public function getRecommenderSystemServerBuiltInDebugCompetences() : array + { + return $this->rec_sys_ser_bui_in_deb_comp; + } + + + /** + * @inheritDoc + */ + public function setRecommenderSystemServerBuiltInDebugCompetences(array $recommender_system_server_built_in_debug_competences)/*:void*/ + { + $this->rec_sys_ser_bui_in_deb_comp = $recommender_system_server_built_in_debug_competences; + } + + /** * @inheritDoc */ diff --git a/classes/Settings/class.xdhtSettingsFormGUI.php b/classes/Settings/class.xdhtSettingsFormGUI.php index daffe87..b42595c 100644 --- a/classes/Settings/class.xdhtSettingsFormGUI.php +++ b/classes/Settings/class.xdhtSettingsFormGUI.php @@ -1,5 +1,6 @@ setInfo(nl2br(str_replace("\\n", "\n", self::plugin() ->translate("recommender_system_server_built_in_debug_info", "", ["[[question_id]]", "recomander_id", self::plugin()->directory() . "/classes/Recommender/debug/api/v1"])), false)); $recommender_system_server->addOption($recommender_system_server_built_in_debug); + $recommender_system_server_built_in_debug_competences = new MultiLineNewInputGUI("competences", "recommender_system_server_built_in_debug_competences"); + $recommender_system_server_built_in_debug_competences->setShowSort(false); + $recommender_system_server_built_in_debug_competences->setInfo(self::plugin()->translate("recommender_system_server_built_in_debug_competences_info", "", ["competence_id", "skill_id"])); + $recommender_system_server_built_in_debug_competences_competence_id = new ilNumberInputGUI("competence_id", "competence_id"); + $recommender_system_server_built_in_debug_competences_competence_id->setRequired(true); + $recommender_system_server_built_in_debug_competences->addInput($recommender_system_server_built_in_debug_competences_competence_id); + $recommender_system_server_built_in_debug_competences_skill_id = new ilNumberInputGUI("skill_id", "skill_id"); + $recommender_system_server_built_in_debug_competences_skill_id->setRequired(true); + $recommender_system_server_built_in_debug_competences->addInput($recommender_system_server_built_in_debug_competences_skill_id); + $recommender_system_server_built_in_debug->addSubItem($recommender_system_server_built_in_debug_competences); } $ti = new ilTextInputGUI(self::plugin()->translate("url"), 'url'); @@ -155,6 +166,7 @@ public function fillForm() $values['url'] = $this->facade->settings()->getUrl(); $values['log'] = $this->facade->settings()->getLog(); $values['recommender_system'] = $this->facade->settings()->getRecommenderSystemServer(); + $values['recommender_system_server_built_in_debug_competences'] = $this->facade->settings()->getRecommenderSystemServerBuiltInDebugCompetences(); if (Config::getField(Config::KEY_LEARNING_PROGRESS)) { $values['learning_progress'] = $this->facade->settings()->getLearningProgress(); } @@ -193,6 +205,7 @@ public function fillObject() $this->facade->settings()->setUrl($this->getInput('url')); $this->facade->settings()->setLog($this->getInput('log')); $this->facade->settings()->setRecommenderSystemServer(intval($this->getInput('recommender_system'))); + $this->facade->settings()->setRecommenderSystemServerBuiltInDebugCompetences((array) $this->getInput('recommender_system_server_built_in_debug_competences')); if (Config::getField(Config::KEY_LEARNING_PROGRESS)) { $this->facade->settings()->setLearningProgress(intval($this->getInput('learning_progress'))); } diff --git a/lang/ilias_de.lang b/lang/ilias_de.lang index 68f1abc..5708f87 100644 --- a/lang/ilias_de.lang +++ b/lang/ilias_de.lang @@ -78,4 +78,5 @@ config_configuration#:#Konfiguration config_configuration_saved#:#Konfiguration gespeichert config_save#:#Speichern config_salt#:#Salt -config_salt_info#:#Wird für die Anonymisierung des Benutzers mit dem Recommender System verwendet \ No newline at end of file +config_salt_info#:#Wird für die Anonymisierung des Benutzers mit dem Recommender System verwendet +recommender_system_server_built_in_debug_competences_info#:#Wenn mehrere gleiche %1$s, wird eine zufällige %2$s genommen \ No newline at end of file diff --git a/lang/ilias_en.lang b/lang/ilias_en.lang index 039e34a..629ef06 100644 --- a/lang/ilias_en.lang +++ b/lang/ilias_en.lang @@ -78,4 +78,5 @@ config_configuration#:#Configuration config_configuration_saved#:#Configuration saved config_save#:#Save config_salt#:#Salt -config_salt_info#:#Used to anonymize the user with the recommender system \ No newline at end of file +config_salt_info#:#Used to anonymize the user with the recommender system +recommender_system_server_built_in_debug_competences_info#:#If multiple same %1$s, a random %2$s will be taken \ No newline at end of file diff --git a/sql/dbupdate.php b/sql/dbupdate.php index 0183037..aa83af0 100644 --- a/sql/dbupdate.php +++ b/sql/dbupdate.php @@ -29,3 +29,7 @@ \srag\Plugins\DhbwTraining\Config\Config::updateDB(); \srag\Plugins\DhbwTraining\Config\Config::initDefaultSalt(); ?> +<#8> +