From 0e3d2a2e94ff700a14f48b88953378a21befbce6 Mon Sep 17 00:00:00 2001 From: Lukas Scharmer Date: Mon, 25 Apr 2022 15:41:05 +0200 Subject: [PATCH] Finish review for Services/Skill --- .../classes/class.ilTestPersonalSkillsGUI.php | 2 +- .../classes/class.ilSkillGSToolProvider.php | 26 ++------ .../Skill/Profile/class.ilSkillProfile.php | 50 +++++++++----- .../class.ilSkillProfileCompletionManager.php | 6 ++ ...ass.ilSkillProfileCompletionRepository.php | 7 +- .../Skill/Profile/class.ilSkillProfileGUI.php | 24 ++++++- .../Resources/class.ilSkillResources.php | 44 +++++++++---- .../class.ilSkillResourcesManager.php | 5 +- .../classes/class.SkillAdminGUIRequest.php | 36 ++++++++++ .../Service/classes/class.SkillGUIRequest.php | 64 ++++++------------ .../classes/class.SkillPersonalGUIRequest.php | 6 ++ .../classes/class.SkillTreeService.php | 6 ++ .../Service/classes/class.SkillUIService.php | 2 +- .../Skill/Tree/class.SkillTreeTableGUI.php | 15 +++-- .../Skill/Tree/class.ilGlobalSkillTree.php | 9 +++ .../Tree/class.ilGlobalVirtualSkillTree.php | 25 +++---- .../Skill/Tree/class.ilObjSkillTreeGUI.php | 10 ++- .../class.ilSkillTemplateTreeExplorerGUI.php | 6 ++ Services/Skill/Tree/class.ilSkillTree.php | 10 ++- Services/Skill/Tree/class.ilSkillTreeNode.php | 46 +++++++++---- .../Skill/Tree/class.ilSkillTreeNodeGUI.php | 9 +++ .../Skill/Tree/class.ilVirtualSkillTree.php | 48 ++++++++++---- .../class.ilVirtualSkillTreeExplorerGUI.php | 7 +- .../classes/Provider/SkillMainBarProvider.php | 4 +- .../Setup/class.ilSkillDBUpdateSteps.php | 22 +++---- Services/Skill/classes/class.ilBasicSkill.php | 5 +- .../Skill/classes/class.ilBasicSkillGUI.php | 23 ++++++- .../class.ilBasicSkillLevelDBRepository.php | 14 ++-- .../classes/class.ilBasicSkillTemplateGUI.php | 2 +- .../class.ilBasicSkillTreeDBRepository.php | 6 +- ...lass.ilBasicSkillUserLevelDBRepository.php | 23 +++++-- .../classes/class.ilObjSkillManagementGUI.php | 25 ++++--- .../Skill/classes/class.ilPersonalSkill.php | 28 ++++++-- .../class.ilPersonalSkillExplorerGUI.php | 27 ++++++-- .../classes/class.ilPersonalSkillsGUI.php | 66 ++++++++++++++++--- .../Skill/classes/class.ilSkillDataSet.php | 14 +++- .../classes/class.ilSkillExportConfig.php | 8 +++ .../classes/class.ilSkillSelectorGUI.php | 9 +-- .../class.ilSkillTemplateReferenceGUI.php | 2 +- Services/Skill/classes/class.ilSkillUsage.php | 58 ++++++++++------ ...erface.ilBasicSkillUserLevelRepository.php | 3 +- .../interfaces/interface.ilSkillUsageInfo.php | 7 +- 42 files changed, 570 insertions(+), 239 deletions(-) diff --git a/Modules/Test/classes/class.ilTestPersonalSkillsGUI.php b/Modules/Test/classes/class.ilTestPersonalSkillsGUI.php index 747cc2753d44..5bd5dd4fad18 100644 --- a/Modules/Test/classes/class.ilTestPersonalSkillsGUI.php +++ b/Modules/Test/classes/class.ilTestPersonalSkillsGUI.php @@ -53,7 +53,7 @@ public function getHTML() : string $gui->setProfileId($this->getSelectedSkillProfile()); - $html = $gui->getGapAnalysisHTML($this->getUsrId(), $this->getAvailableSkills()); + $html = $gui->getGapAnalysisHTML((int) $this->getUsrId(), $this->getAvailableSkills()); return $html; } diff --git a/Services/Skill/GlobalScreen/classes/class.ilSkillGSToolProvider.php b/Services/Skill/GlobalScreen/classes/class.ilSkillGSToolProvider.php index 5fbf859db539..3e384bc8231c 100644 --- a/Services/Skill/GlobalScreen/classes/class.ilSkillGSToolProvider.php +++ b/Services/Skill/GlobalScreen/classes/class.ilSkillGSToolProvider.php @@ -20,6 +20,7 @@ use ILIAS\GlobalScreen\Scope\Tool\Provider\AbstractDynamicToolProvider; use ILIAS\GlobalScreen\ScreenContext\Stack\CalledContexts; use ILIAS\GlobalScreen\ScreenContext\Stack\ContextCollection; +use ILIAS\UI\Component\Legacy\Legacy; /** * Workspace GS tool provider @@ -57,21 +58,14 @@ public function getToolsForContextStack(CalledContexts $called_contexts) : array $icon = $this->dic->ui()->factory()->symbol()->icon()->custom(\ilUtil::getImagePath("outlined/icon_skmg.svg"), $title); - $additional_data = $called_contexts->current()->getAdditionalData(); if ($additional_data->is(self::SHOW_SKILL_TREE, true)) { $tree_id = $additional_data->get(self::SKILL_TREE_ID); - $iff = function ($id) { - return $this->identification_provider->contextAwareIdentifier($id); - }; - $l = function (string $content) { - return $this->dic->ui()->factory()->legacy($content); - }; - $tools[] = $this->factory->tool($iff("tree")) + $tools[] = $this->factory->tool($this->identification_provider->contextAwareIdentifier("tree")) ->withTitle($title) ->withSymbol($icon) - ->withContentWrapper(function () use ($l, $tree_id) { - return $l($this->getSkillTree($tree_id)); + ->withContentWrapper(function () use ($tree_id) : Legacy { + return $this->dic->ui()->factory()->legacy($this->getSkillTree($tree_id)); }); } @@ -80,17 +74,11 @@ public function getToolsForContextStack(CalledContexts $called_contexts) : array if ($additional_data->is(self::SHOW_TEMPLATE_TREE, true)) { $tree_id = $additional_data->get(self::SKILL_TREE_ID); - $iff = function ($id) { - return $this->identification_provider->contextAwareIdentifier($id); - }; - $l = function (string $content) { - return $this->dic->ui()->factory()->legacy($content); - }; - $tools[] = $this->factory->tool($iff("tree")) + $tools[] = $this->factory->tool($this->identification_provider->contextAwareIdentifier("tree")) ->withTitle("Templates") ->withSymbol($icon) - ->withContentWrapper(function () use ($l, $tree_id) { - return $l($this->getTemplateTree($tree_id)); + ->withContentWrapper(function () use ($tree_id) : Legacy { + return $this->dic->ui()->factory()->legacy($this->getTemplateTree($tree_id)); }); } return $tools; diff --git a/Services/Skill/Profile/class.ilSkillProfile.php b/Services/Skill/Profile/class.ilSkillProfile.php index 0440f82feb02..920ad46b7f05 100644 --- a/Services/Skill/Profile/class.ilSkillProfile.php +++ b/Services/Skill/Profile/class.ilSkillProfile.php @@ -34,6 +34,10 @@ class ilSkillProfile implements ilSkillUsageInfo protected int $ref_id = 0; protected string $image_id = ""; protected int $skill_tree_id = 0; + + /** + * @var array{base_skill_id: int, tref_id: int, level_id: int, order_nr: int}[] + */ protected array $skill_level = []; public function __construct(int $a_id = 0) @@ -89,7 +93,7 @@ public function getRefId() : int return $this->ref_id; } - public function setImageId(string $a_val) + public function setImageId(string $a_val) : void { $this->image_id = $a_val; } @@ -99,7 +103,7 @@ public function getImageId() : string return $this->image_id; } - public function setSkillTreeId(int $a_val) + public function setSkillTreeId(int $a_val) : void { $this->skill_tree_id = $a_val; } @@ -131,9 +135,12 @@ public function removeSkillLevel(int $a_base_skill_id, int $a_tref_id, int $a_le } } + /** + * @return array{base_skill_id: int, tref_id: int, level_id: int, order_nr: int}[] + */ public function getSkillLevels() : array { - usort($this->skill_level, function ($level_a, $level_b) { + usort($this->skill_level, static function (array $level_a, array $level_b) : int { return $level_a['order_nr'] <=> $level_b['order_nr']; }); @@ -415,11 +422,8 @@ public static function getLocalProfilesForObject(int $a_ref_id) : array return $profiles; } - - /** - * @return mixed - */ - protected static function lookup(int $a_id, string $a_field) + + protected static function lookup(int $a_id, string $a_field) : ?string { global $DIC; @@ -430,7 +434,8 @@ protected static function lookup(int $a_id, string $a_field) " WHERE id = " . $ilDB->quote($a_id, "integer") ); $rec = $ilDB->fetchAssoc($set); - return $rec[$a_field]; + + return isset($rec[$a_field]) ? (string) $rec[$a_field] : null; } public static function lookupTitle(int $a_id) : string @@ -440,7 +445,7 @@ public static function lookupTitle(int $a_id) : string public static function lookupRefId(int $a_id) : int { - return self::lookup($a_id, "ref_id"); + return (int) self::lookup($a_id, "ref_id"); } /** @@ -536,6 +541,9 @@ public static function removeUserFromAllProfiles(int $a_user_id) : void ); } + /** + * @return array{id: int, title: string, description: string, image_id: string}[] + */ public static function getProfilesOfUser(int $a_user_id) : array { global $DIC; @@ -554,6 +562,7 @@ public static function getProfilesOfUser(int $a_user_id) : array " ORDER BY p.title ASC" ); while ($rec = $ilDB->fetchAssoc($set)) { + $rec['id'] = (int) $rec['id']; $user_profiles[] = $rec; } @@ -570,9 +579,9 @@ public static function getProfilesOfUser(int $a_user_id) : array // merge competence profiles and remove multiple occurrences $all_profiles = array_merge($user_profiles, $role_profiles); $temp_profiles = []; - foreach ($all_profiles as &$v) { + foreach ($all_profiles as $v) { if (!isset($temp_profiles[$v["id"]])) { - $temp_profiles[$v["id"]] = &$v; + $temp_profiles[$v["id"]] = $v; } } $all_profiles = array_values($temp_profiles); @@ -667,6 +676,7 @@ public static function removeRoleFromAllProfiles(int $a_role_id) : void /** * Get global and local profiles of a role + * @return array{id: int, title: string, description: string, image_id: string}[] */ public static function getAllProfilesOfRole(int $a_role_id) : array { @@ -682,11 +692,15 @@ public static function getAllProfilesOfRole(int $a_role_id) : array " ORDER BY p.title ASC" ); while ($rec = $ilDB->fetchAssoc($set)) { + $rec['id'] = (int) $rec['id']; $profiles[] = $rec; } return $profiles; } + /** + * @return array{id: int, title: string, description: string, image_id: string}[] + */ public static function getGlobalProfilesOfRole(int $a_role_id) : array { global $DIC; @@ -702,8 +716,10 @@ public static function getGlobalProfilesOfRole(int $a_role_id) : array " ORDER BY p.title ASC" ); while ($rec = $ilDB->fetchAssoc($set)) { + $rec['id'] = (int) $rec['id']; $profiles[] = $rec; } + return $profiles; } @@ -741,11 +757,15 @@ public static function countRoles(int $a_profile_id) : int return (int) $rec["rcnt"]; } - public static function getUsageInfo(array $a_cskill_ids, array &$a_usages) : void + /** + * @param array{skill_id: int, tref_id: int}[] $a_cskill_ids + * + * @return array> + */ + public static function getUsageInfo(array $a_cskill_ids) : array { - ilSkillUsage::getUsageInfoGeneric( + return ilSkillUsage::getUsageInfoGeneric( $a_cskill_ids, - $a_usages, ilSkillUsage::PROFILE, "skl_profile_level", "profile_id", diff --git a/Services/Skill/Profile/class.ilSkillProfileCompletionManager.php b/Services/Skill/Profile/class.ilSkillProfileCompletionManager.php index 31bd082b59db..df5b77aa98ee 100644 --- a/Services/Skill/Profile/class.ilSkillProfileCompletionManager.php +++ b/Services/Skill/Profile/class.ilSkillProfileCompletionManager.php @@ -43,6 +43,10 @@ public function getUserId() : int return $this->user_id; } + /** + * @param array{base_skill_id: int, tref_id: int, level_id: int} $a_skills + * @return array> + */ public function getActualMaxLevels( array $a_skills = null, string $a_gap_mode = "", @@ -73,6 +77,7 @@ public function getActualLastLevels( int $a_gap_mode_obj_id = 0 ) : array { // todo for coming feature + return []; } /** @@ -121,6 +126,7 @@ public function isProfileFulfilled(int $a_profile_id) : bool /** * Get all profiles of user which are fulfilled or non-fulfilled + * @return array */ public function getAllProfileCompletionsForUser() : array { diff --git a/Services/Skill/Profile/class.ilSkillProfileCompletionRepository.php b/Services/Skill/Profile/class.ilSkillProfileCompletionRepository.php index 64a9058abec2..0cd6aaa41098 100644 --- a/Services/Skill/Profile/class.ilSkillProfileCompletionRepository.php +++ b/Services/Skill/Profile/class.ilSkillProfileCompletionRepository.php @@ -172,6 +172,7 @@ public function removeAllEntries() : void /** * Get all profile completion entries for a user + * @return array{profile_id: int, user_id: int, date: string, fulfilled: int}[] */ public static function getFulfilledEntriesForUser(int $a_user_id) : array { @@ -187,10 +188,10 @@ public static function getFulfilledEntriesForUser(int $a_user_id) : array $entries = []; while ($rec = $ilDB->fetchAssoc($set)) { $entries[] = array( - "profile_id" => $rec["profile_id"], - "user_id" => $rec["user_id"], + "profile_id" => (int) $rec["profile_id"], + "user_id" => (int) $rec["user_id"], "date" => $rec["date"], - "fulfilled" => $rec["fulfilled"] + "fulfilled" => (int) $rec["fulfilled"] ); } diff --git a/Services/Skill/Profile/class.ilSkillProfileGUI.php b/Services/Skill/Profile/class.ilSkillProfileGUI.php index add0199cfa75..78f3561a428a 100644 --- a/Services/Skill/Profile/class.ilSkillProfileGUI.php +++ b/Services/Skill/Profile/class.ilSkillProfileGUI.php @@ -51,14 +51,34 @@ class ilSkillProfileGUI protected SkillAdminGUIRequest $admin_gui_request; protected int $requested_ref_id = 0; protected int $requested_sprof_id = 0; + + /** + * @var int[] + */ protected array $requested_profile_ids = []; protected bool $requested_local_context = false; protected string $requested_cskill_id = ""; protected int $requested_level_id = 0; + + /** + * @var string[] + */ protected array $requested_level_ass_ids = []; + + /** + * @var int[] + */ protected array $requested_level_order = []; protected string $requested_user_login = ""; + + /** + * @var int[] + */ protected array $requested_users = []; + + /** + * @var int[] + */ protected array $requested_user_ids = []; protected bool $local_context = false; @@ -901,11 +921,11 @@ public function removeUsers() : void $type = ilObject::_lookupType($i); switch ($type) { case 'usr': - $this->profile->removeUserFromProfile((int) $i); + $this->profile->removeUserFromProfile($i); break; case 'role': - $this->profile->removeRoleFromProfile((int) $i); + $this->profile->removeRoleFromProfile($i); break; default: diff --git a/Services/Skill/Resources/class.ilSkillResources.php b/Services/Skill/Resources/class.ilSkillResources.php index a7c076ec1a2a..fa6259e4858d 100644 --- a/Services/Skill/Resources/class.ilSkillResources.php +++ b/Services/Skill/Resources/class.ilSkillResources.php @@ -45,6 +45,9 @@ class ilSkillResources implements ilSkillUsageInfo // rep_ref_id (int): the ref id of the repository resource // trigger: 1, if the resource triggers the skill level (0 otherwise) // imparting: 1, if the resource imparts knowledge of the skill level (0 otherwise) + /** + * @var array> + */ protected array $resources = []; public function __construct(int $a_skill_id = 0, int $a_tref_id = 0) @@ -93,12 +96,12 @@ public function readResources() : void ); while ($rec = $ilDB->fetchAssoc($set)) { if ($tree->isInTree($rec["rep_ref_id"])) { - $this->resources[$rec["level_id"]][$rec["rep_ref_id"]] = array( - "level_id" => $rec["level_id"], - "rep_ref_id" => $rec["rep_ref_id"], - "trigger" => $rec["ltrigger"], - "imparting" => $rec["imparting"] - ); + $this->resources[(int) $rec["level_id"]][(int) $rec["rep_ref_id"]] = array( + "level_id" => (int) $rec["level_id"], + "rep_ref_id" => (int) $rec["rep_ref_id"], + "trigger" => (int) $rec["ltrigger"], + "imparting" => (int) $rec["imparting"] + ); } } } @@ -119,8 +122,8 @@ public function save() : void "(base_skill_id, tref_id, level_id, rep_ref_id, imparting, ltrigger) VALUES (" . $ilDB->quote($this->getBaseSkillId(), "integer") . "," . $ilDB->quote($this->getTemplateRefId(), "integer") . "," . - $ilDB->quote((int) $level_id, "integer") . "," . - $ilDB->quote((int) $ref_id, "integer") . "," . + $ilDB->quote($level_id, "integer") . "," . + $ilDB->quote($ref_id, "integer") . "," . $ilDB->quote((int) $r["imparting"], "integer") . "," . $ilDB->quote((int) $r["trigger"], "integer") . ")"); @@ -129,11 +132,17 @@ public function save() : void } } + /** + * @return array> + */ public function getResources() : array { return $this->resources; } + /** + * @return array + */ public function getResourcesOfLevel(int $a_level_id) : array { $ret = (isset($this->resources[$a_level_id]) && is_array($this->resources[$a_level_id])) @@ -167,11 +176,15 @@ public function setResourceAsImparting(int $a_level_id, int $a_rep_ref_id, bool $this->resources[$a_level_id][$a_rep_ref_id]["imparting"] = $a_imparting; } - public static function getUsageInfo(array $a_cskill_ids, array &$a_usages) + /** + * @param array{skill_id: int, tref_id: int}[] $a_cskill_ids array of common skill ids + * + * @return array> + */ + public static function getUsageInfo(array $a_cskill_ids) : array { - ilSkillUsage::getUsageInfoGeneric( + return ilSkillUsage::getUsageInfoGeneric( $a_cskill_ids, - $a_usages, ilSkillUsage::RESOURCE, "skl_skill_resource", "rep_ref_id", @@ -179,6 +192,9 @@ public static function getUsageInfo(array $a_cskill_ids, array &$a_usages) ); } + /** + * @return array{base_skill_id: int, tref_id: int, level_id: int}[] + */ public static function getTriggerLevelsForRefId(int $a_ref_id) : array { global $DIC; @@ -192,9 +208,9 @@ public static function getTriggerLevelsForRefId(int $a_ref_id) : array $skill_levels = []; while ($rec = $db->fetchAssoc($set)) { $skill_levels[] = array( - "base_skill_id" => $rec["base_skill_id"], - "tref_id" => $rec["tref_id"], - "level_id" => $rec["level_id"] + "base_skill_id" => (int) $rec["base_skill_id"], + "tref_id" => (int) $rec["tref_id"], + "level_id" => (int) $rec["level_id"] ); } return $skill_levels; diff --git a/Services/Skill/Resources/class.ilSkillResourcesManager.php b/Services/Skill/Resources/class.ilSkillResourcesManager.php index 0a5c211acd14..6e0761cf41d3 100644 --- a/Services/Skill/Resources/class.ilSkillResourcesManager.php +++ b/Services/Skill/Resources/class.ilSkillResourcesManager.php @@ -55,13 +55,16 @@ public function isLevelTooLow(array $a_levels, array $profile_levels, array $act return $too_low; } + /** + * @return array{level_id: int, rep_ref_id: int, trigger: int, imparting: int}[] + */ public function getSuggestedResources() : array { $resources = $this->res->getResources(); $imp_resources = []; foreach ($resources as $level) { foreach ($level as $r) { - if ($r["imparting"] == true && + if ($r["imparting"] && $this->current_target_level == $r["level_id"]) { $imp_resources[] = $r; } diff --git a/Services/Skill/Service/classes/class.SkillAdminGUIRequest.php b/Services/Skill/Service/classes/class.SkillAdminGUIRequest.php index bd67b0f6c41d..6f6b9682567c 100644 --- a/Services/Skill/Service/classes/class.SkillAdminGUIRequest.php +++ b/Services/Skill/Service/classes/class.SkillAdminGUIRequest.php @@ -93,6 +93,9 @@ public function getLocalContext() : bool return $this->bool("local_context"); } + /** + * @return int[] + */ public function getOrder() : array { return $this->intArray("order"); @@ -103,41 +106,65 @@ public function getLevelId() : int return $this->int("level_id"); } + /** + * @return int[] + */ public function getLevelIds() : array { return $this->getIds(); } + /** + * @return string[] + */ public function getAssignedLevelIds() : array { return $this->strArray("ass_id"); } + /** + * @return int[] + */ public function getResourceIds() : array { return $this->getIds(); } + /** + * @return bool[] + */ public function getSuggested() : array { return $this->boolArray("suggested"); } + /** + * @return bool[] + */ public function getTrigger() : array { return $this->boolArray("trigger"); } + /** + * @return string[] + */ public function getTitles() : array { return $this->strArray("title"); } + /** + * @return int[] + */ public function getNodeIds() : array { return $this->getIds(); } + /** + * @return int[] + */ public function getProfileIds() : array { return $this->getIds(); @@ -148,16 +175,25 @@ public function getUserLogin() : string return $this->str("user_login"); } + /** + * @return int[] + */ public function getUsers() : array { return $this->intArray("user"); } + /** + * @return int[] + */ public function getUserIds() : array { return $this->getIds(); } + /** + * @return string[] + */ public function getSelectedIds(string $post_var) : array { return $this->strArray($post_var); diff --git a/Services/Skill/Service/classes/class.SkillGUIRequest.php b/Services/Skill/Service/classes/class.SkillGUIRequest.php index 489f7f6f4651..06243f80ae5f 100644 --- a/Services/Skill/Service/classes/class.SkillGUIRequest.php +++ b/Services/Skill/Service/classes/class.SkillGUIRequest.php @@ -54,7 +54,7 @@ public function __construct( /** * get integer parameter kindly */ - protected function int($key) : int + protected function int(string $key) : int { $t = $this->refinery->kindlyTo()->int(); return (int) ($this->get($key, $t) ?? 0); @@ -62,26 +62,17 @@ protected function int($key) : int /** * get integer array kindly + * @return int[]|array */ - protected function intArray($key) : array + protected function intArray(string $key) : array { if (!$this->isArray($key)) { return []; } $t = $this->refinery->custom()->transformation( - function ($arr) { + static function (array $arr) : array { // keep keys(!), transform all values to int - return array_column( - array_map( - function ($k, $v) { - return [$k, (int) $v]; - }, - array_keys($arr), - $arr - ), - 1, - 0 - ); + return array_map('intval', $arr); } ); return (array) ($this->get($key, $t) ?? []); @@ -90,7 +81,7 @@ function ($k, $v) { /** * get string parameter kindly */ - protected function str($key) : string + protected function str(string $key) : string { $t = $this->refinery->kindlyTo()->string(); return \ilUtil::stripSlashes((string) ($this->get($key, $t) ?? "")); @@ -98,25 +89,21 @@ protected function str($key) : string /** * get string array kindly + * @return string[]|array */ - protected function strArray($key) : array + protected function strArray(string $key) : array { if (!$this->isArray($key)) { return []; } $t = $this->refinery->custom()->transformation( - function ($arr) { + static function (array $arr) : array { // keep keys(!), transform all values to string - return array_column( - array_map( - function ($k, $v) { - return [$k, \ilUtil::stripSlashes((string) $v)]; - }, - array_keys($arr), - $arr - ), - 1, - 0 + return array_map( + static function ($v) : string { + return \ilUtil::stripSlashes((string) $v); + }, + $arr ); } ); @@ -126,7 +113,7 @@ function ($k, $v) { /** * get bool parameter kindly */ - protected function bool($key) : bool + protected function bool(string $key) : bool { $t = $this->refinery->kindlyTo()->bool(); return (bool) ($this->get($key, $t) ?? false); @@ -134,26 +121,17 @@ protected function bool($key) : bool /** * get bool array kindly + * @return bool[]|array */ - protected function boolArray($key) : array + protected function boolArray(string $key) : array { if (!$this->isArray($key)) { return []; } $t = $this->refinery->custom()->transformation( - function ($arr) { + static function (array $arr) : array { // keep keys(!), transform all values to bool - return array_column( - array_map( - function ($k, $v) { - return [$k, (bool) $v]; - }, - array_keys($arr), - $arr - ), - 1, - 0 - ); + return array_map('boolval', $arr); } ); return (array) ($this->get($key, $t) ?? []); @@ -165,9 +143,7 @@ function ($k, $v) { protected function isArray(string $key) : bool { if ($this->passed_query_params === null && $this->passed_post_data === null) { - $no_transform = $this->refinery->custom()->transformation(function ($v) { - return $v; - }); + $no_transform = $this->refinery->identity(); $w = $this->http->wrapper(); if ($w->post()->has($key)) { return is_array($w->post()->retrieve($key, $no_transform)); diff --git a/Services/Skill/Service/classes/class.SkillPersonalGUIRequest.php b/Services/Skill/Service/classes/class.SkillPersonalGUIRequest.php index 2c52ac8af52a..fced77b113b7 100644 --- a/Services/Skill/Service/classes/class.SkillPersonalGUIRequest.php +++ b/Services/Skill/Service/classes/class.SkillPersonalGUIRequest.php @@ -53,6 +53,9 @@ public function getSkillId() : int return $this->int("skill_id"); } + /** + * @return int[] + */ public function getSkillIds() : array { return $this->getIds(); @@ -83,6 +86,9 @@ public function getWorkspaceId() : int return $this->int("wsp_id"); } + /** + * @return int[] + */ public function getWorkspaceIds() : array { return $this->intArray("wsp_id"); diff --git a/Services/Skill/Service/classes/class.SkillTreeService.php b/Services/Skill/Service/classes/class.SkillTreeService.php index dc67f9971637..0e5c720e0c99 100644 --- a/Services/Skill/Service/classes/class.SkillTreeService.php +++ b/Services/Skill/Service/classes/class.SkillTreeService.php @@ -82,6 +82,9 @@ public function getVirtualSkillTreeForNodeId(int $node_id) : \ilVirtualSkillTree return $vtree; } + /** + * @return array{skill_id: int, child: int, tref_id: int, parent: int}[] + */ public function getSkillTreePath(int $base_skill_id, int $tref_id = 0) : array { $tree = $this->tree_repo->getTreeForNodeId($base_skill_id); @@ -97,6 +100,9 @@ public function getObjSkillTreeById(int $tree_id) : \ilObjSkillTree return $obj_tree; } + /** + * @return \ilObjSkillTree[] + */ public function getObjSkillTrees() : array { $obj_trees = iterator_to_array($this->tree_manager->getTrees()); diff --git a/Services/Skill/Service/classes/class.SkillUIService.php b/Services/Skill/Service/classes/class.SkillUIService.php index 155f3bcfe9b5..3c6094fa356c 100644 --- a/Services/Skill/Service/classes/class.SkillUIService.php +++ b/Services/Skill/Service/classes/class.SkillUIService.php @@ -29,7 +29,7 @@ public function __construct() { } - public function getGapUI() //int $user_id, int $profile_id,... + public function getGapUI() : void //int $user_id, int $profile_id,... { } } diff --git a/Services/Skill/Tree/class.SkillTreeTableGUI.php b/Services/Skill/Tree/class.SkillTreeTableGUI.php index 391d2842ddac..e38c90b85cb0 100644 --- a/Services/Skill/Tree/class.SkillTreeTableGUI.php +++ b/Services/Skill/Tree/class.SkillTreeTableGUI.php @@ -76,18 +76,18 @@ public function __construct(object $a_parent_obj, string $a_parent_cmd, SkillInt } /** - * @return array[] + * @return array({title: string, tree: \ilObjSkillTree}|array{})[] */ protected function getItems() : array { return array_filter(array_map( - function ($i) { - $tree_access_manager = $this->internal_manager->getTreeAccessManager($i->getRefId()); + function (\ilObjSkillTree $skillTree) : array { + $tree_access_manager = $this->internal_manager->getTreeAccessManager($skillTree->getRefId()); if ($tree_access_manager->hasVisibleTreePermission()) { return [ - "title" => $i->getTitle(), - "tree" => $i - ]; + "title" => $skillTree->getTitle(), + "tree" => $skillTree + ]; } return []; }, @@ -95,6 +95,9 @@ function ($i) { )); } + /** + * @param array{tree: \ilObjSkillTree} + */ protected function fillRow(array $a_set) : void { $tpl = $this->tpl; diff --git a/Services/Skill/Tree/class.ilGlobalSkillTree.php b/Services/Skill/Tree/class.ilGlobalSkillTree.php index ee7be02fbf6b..6fb2ec672c52 100644 --- a/Services/Skill/Tree/class.ilGlobalSkillTree.php +++ b/Services/Skill/Tree/class.ilGlobalSkillTree.php @@ -40,6 +40,9 @@ public function __construct() $this->tree_repo = $DIC->skills()->internal()->repo()->getTreeRepo(); } + /** + * @return array{child: int, parent: int} + */ public function getNodeData(int $a_node_id, ?int $a_tree_pk = null) : array { if ($a_node_id == 0) { @@ -48,6 +51,9 @@ public function getNodeData(int $a_node_id, ?int $a_tree_pk = null) : array return parent::getNodeData($a_node_id, $a_tree_pk); } + /** + * @return array{parent: int, depth: int, obj_id: int, child: int} + */ public function getRootNode() : array { $root_node = []; @@ -65,6 +71,9 @@ public function readRootId() : int return 0; } + /** + * @return array{child: int, parent: int}[] + */ public function getChilds(int $a_node_id, string $a_order = "", string $a_direction = "ASC") : array { if ($a_node_id == 0) { diff --git a/Services/Skill/Tree/class.ilGlobalVirtualSkillTree.php b/Services/Skill/Tree/class.ilGlobalVirtualSkillTree.php index d7393057f0e6..1413de7725e9 100644 --- a/Services/Skill/Tree/class.ilGlobalVirtualSkillTree.php +++ b/Services/Skill/Tree/class.ilGlobalVirtualSkillTree.php @@ -26,12 +26,6 @@ */ class ilGlobalVirtualSkillTree extends ilVirtualSkillTree { - protected ilLanguage $lng; - protected static ?array $order_node_data = null; - protected bool $include_drafts = false; - protected array $drafts = []; - protected bool $include_outdated = false; - protected array $outdated = []; protected bool $root_node_processed = false; protected SkillTreeManager $skill_tree_manager; protected SkillTreeFactory $skill_tree_factory; @@ -47,6 +41,9 @@ public function __construct() $this->tree_repo = $DIC->skills()->internal()->repo()->getTreeRepo(); } + /** + * @return array{id: int, parent: int, depth: int, obj_id: int} + */ public function getRootNode() : array { $root_id = 0; @@ -60,6 +57,9 @@ public function getRootNode() : array return $root_node; } + /** + * @return array{id: int, child: int, parent: int}[] + */ public function getChildsOfNode(string $a_parent_id) : array { if ($a_parent_id === "0") { @@ -79,13 +79,14 @@ public function getChildsOfNode(string $a_parent_id) : array } } + /** + * @return {cskill_id: string, id: string, skill_id: string, tref_id: string, parent: string, type: string}[] + */ public function getSubTreeForTreeId(string $a_tree_id) : array { - $result = []; - $node = $this->getNode($a_tree_id); - $result[] = $node; - $this->__getSubTreeRec($a_tree_id, $result, false); - - return $result; + return array_merge( + [$this->getNode($a_tree_id)], + $this->__getSubTreeRec($a_tree_id, false) + ); } } diff --git a/Services/Skill/Tree/class.ilObjSkillTreeGUI.php b/Services/Skill/Tree/class.ilObjSkillTreeGUI.php index eb8d3d3cbb28..c44a3f44988d 100644 --- a/Services/Skill/Tree/class.ilObjSkillTreeGUI.php +++ b/Services/Skill/Tree/class.ilObjSkillTreeGUI.php @@ -53,7 +53,15 @@ class ilObjSkillTreeGUI extends ilObjectGUI protected int $requested_templates_tree = 0; protected string $requested_skexpand = ""; protected int $requested_tmpmode = 0; + + /** + * @var string[] + */ protected array $requested_titles = []; + + /** + * @var int[] + */ protected array $requested_node_ids = []; /** @@ -769,7 +777,7 @@ public function editSkillTemplates() : void // Tree // - public function showTree($a_templates, $a_gui = "", $a_gui_cmd = "") : void + public function showTree(bool $a_templates, $a_gui = "", $a_gui_cmd = "") : void { $ilUser = $this->user; $tpl = $this->tpl; diff --git a/Services/Skill/Tree/class.ilSkillTemplateTreeExplorerGUI.php b/Services/Skill/Tree/class.ilSkillTemplateTreeExplorerGUI.php index 4cc53ad93173..53de1affd61d 100644 --- a/Services/Skill/Tree/class.ilSkillTemplateTreeExplorerGUI.php +++ b/Services/Skill/Tree/class.ilSkillTemplateTreeExplorerGUI.php @@ -28,7 +28,13 @@ class ilSkillTemplateTreeExplorerGUI extends ilTreeExplorerGUI { protected SkillAdminGUIRequest $admin_gui_request; protected int $requested_skill_node_id = 0; + /** + * @var array + */ protected array $parent = []; + /** + * @var array + */ protected array $draft = []; /** diff --git a/Services/Skill/Tree/class.ilSkillTree.php b/Services/Skill/Tree/class.ilSkillTree.php index 7c474873fcde..74fca9bb5c6d 100644 --- a/Services/Skill/Tree/class.ilSkillTree.php +++ b/Services/Skill/Tree/class.ilSkillTree.php @@ -31,6 +31,9 @@ public function __construct(int $a_tree_id = 1) $this->setTableNames('skl_tree', 'skl_tree_node'); } + /** + * @return array{skill_id: int, child: int, tref_id: int, parent: int}[] + */ public function getSkillTreePath(int $a_base_skill_id, int $a_tref_id = 0) : array { if ($a_tref_id > 0) { @@ -112,11 +115,6 @@ public function getMaxOrderNr(int $a_par_id, bool $a_templates = false) : int ); } - $max = 0; - foreach ($childs as $k => $c) { - $max = max(array($c["order_nr"], $max)); - } - - return $max; + return max(0, ...array_column($childs, 'order_nr')); } } diff --git a/Services/Skill/Tree/class.ilSkillTreeNode.php b/Services/Skill/Tree/class.ilSkillTreeNode.php index c3713c7ee3a6..64ded06309a2 100644 --- a/Services/Skill/Tree/class.ilSkillTreeNode.php +++ b/Services/Skill/Tree/class.ilSkillTreeNode.php @@ -35,6 +35,19 @@ class ilSkillTreeNode protected string $import_id = ""; protected string $creation_date = ""; protected int $status = 0; + + /** + * @var array{ + * type: string, + * title: string, + * description: string, + * order_nr: int, + * self_eval: bool, + * status: int, + * import_id: string, + * creation_date: string + * } + */ protected array $data_record = []; public const STATUS_PUBLISH = 0; @@ -181,11 +194,14 @@ public function read() : void $obj_set = $ilDB->query($query); $this->data_record = $ilDB->fetchAssoc($obj_set); } + $this->data_record["order_nr"] = (int) $this->data_record["order_nr"]; + $this->data_record["self_eval"] = (bool) $this->data_record["self_eval"]; + $this->data_record["status"] = (int) $this->data_record["status"]; $this->setType($this->data_record["type"]); $this->setTitle($this->data_record["title"]); $this->setDescription($this->data_record["description"] ?? ""); $this->setOrderNr($this->data_record["order_nr"]); - $this->setSelfEvaluation((bool) $this->data_record["self_eval"]); + $this->setSelfEvaluation($this->data_record["self_eval"]); $this->setStatus($this->data_record["status"]); $this->setImportId($this->data_record["import_id"] ?? ""); $this->setCreationDate($this->data_record["creation_date"] ?? ""); @@ -199,7 +215,7 @@ public function setDataRecord(array $a_record) : void $this->data_record = $a_record; } - protected static function _lookup(int $a_obj_id, string $a_field) + protected static function _lookup(int $a_obj_id, string $a_field) : ?string { global $DIC; @@ -210,7 +226,7 @@ protected static function _lookup(int $a_obj_id, string $a_field) $obj_set = $ilDB->query($query); $obj_rec = $ilDB->fetchAssoc($obj_set); - return $obj_rec[$a_field]; + return isset($obj_rec[$a_field]) ? (string) $obj_rec[$a_field] : null; } public static function _lookupTitle(int $a_obj_id, int $a_tref_id = 0) : string @@ -355,10 +371,7 @@ public function update() $ilDB->manipulate($query); } - /** - * Delete Node - */ - public function delete() + public function delete() : void { $ilDB = $this->db; @@ -373,11 +386,9 @@ public function delete() public static function uniqueTypesCheck(array $a_items) : bool { $types = []; - if (is_array($a_items)) { - foreach ($a_items as $item) { - $type = ilSkillTreeNode::_lookupType($item); - $types[$type] = $type; - } + foreach ($a_items as $item) { + $type = ilSkillTreeNode::_lookupType($item); + $types[$type] = $type; } if (count($types) > 1) { @@ -386,6 +397,9 @@ public static function uniqueTypesCheck(array $a_items) : bool return true; } + /** + * @return array + */ public static function getAllSelfEvaluationNodes() : array { global $DIC; @@ -398,11 +412,15 @@ public static function getAllSelfEvaluationNodes() : array ); $nodes = []; while ($rec = $ilDB->fetchAssoc($set)) { + $rec["obj_id"] = (int) $rec["obj_id"]; $nodes[$rec["obj_id"]] = $rec["title"]; } return $nodes; } + /** + * @return array{obj_id: int, order_nr: int, status: int, self_eval: bool, title: string, type: string, create_date: string, description: string}[] + */ public static function getSelectableSkills() : array { global $DIC; @@ -416,6 +434,10 @@ public static function getSelectableSkills() : array $sel_skills = []; while ($rec = $ilDB->fetchAssoc($set)) { + $rec['obj_id'] = (int) $rec['obj_id']; + $rec['order_nr'] = (int) $rec['order_nr']; + $rec['status'] = (int) $rec['status']; + $rec['self_eval'] = (bool) $rec['self_eval']; $sel_skills[] = $rec; } diff --git a/Services/Skill/Tree/class.ilSkillTreeNodeGUI.php b/Services/Skill/Tree/class.ilSkillTreeNodeGUI.php index c40588a1f29c..3e7d8dcc9294 100644 --- a/Services/Skill/Tree/class.ilSkillTreeNodeGUI.php +++ b/Services/Skill/Tree/class.ilSkillTreeNodeGUI.php @@ -51,7 +51,16 @@ class ilSkillTreeNodeGUI protected int $requested_node_id = 0; protected string $requested_backcmd = ""; protected int $requested_tmpmode = 0; + protected int $base_skill_id = 0; + + /** + * @var int[] + */ protected array $requested_node_ids = []; + + /** + * @var int[] + */ protected array $requested_node_order = []; public function __construct(Tree\SkillTreeNodeManager $node_manager, int $a_node_id = 0) diff --git a/Services/Skill/Tree/class.ilVirtualSkillTree.php b/Services/Skill/Tree/class.ilVirtualSkillTree.php index c1b84b69c9ab..50069b5bcbd4 100644 --- a/Services/Skill/Tree/class.ilVirtualSkillTree.php +++ b/Services/Skill/Tree/class.ilVirtualSkillTree.php @@ -30,10 +30,21 @@ class ilVirtualSkillTree protected ilLanguage $lng; protected ilSkillTree $tree; + /** + * @var ?array + */ protected static ?array $order_node_data = null; protected bool $include_drafts = false; + + /** + * @var string[] + */ protected array $drafts = []; protected bool $include_outdated = false; + + /** + * @var string[] + */ protected array $outdated = []; public function __construct(int $tree_id) @@ -44,6 +55,9 @@ public function __construct(int $tree_id) $this->tree = $DIC->skills()->internal()->factory()->tree()->getTreeById($tree_id); } + /** + * @return array{id: string, cskill_id: string} + */ public function getRootNode() : array { $root_id = $this->tree->readRootId(); @@ -108,6 +122,9 @@ public function getNode(string $a_vtree_id) : array return $node_data; } + /** + * @return array{cskill_id: string, id: string, skill_id: string, tref_id: string, parent: string, type: string}[] + */ public function getChildsOfNode(string $a_parent_id) : array { $a_parent_id_parts = explode(":", $a_parent_id); @@ -230,6 +247,9 @@ public function getNodeTitle(array $a_node) : string return $title; } + /** + * @return {cskill_id: string, id: string, skill_id: string, tref_id: string, parent: string, type: string}[] + */ public function getSubTreeForCSkillId(string $a_cskill_id, bool $a_only_basic = false) : array { $id_parts = explode(":", $a_cskill_id); @@ -246,21 +266,25 @@ public function getSubTreeForCSkillId(string $a_cskill_id, bool $a_only_basic = ($node["type"] == "sktr" && ilSkillTreeNode::_lookupType($node["skill_id"]) == "sktp")) { $result[] = $node; } - $this->__getSubTreeRec($id, $result, $a_only_basic); - - return $result; + return array_merge($result, $this->__getSubTreeRec($id, $a_only_basic)); } - protected function __getSubTreeRec(string $id, array &$result, bool $a_only_basic) : void + /** + * @return {cskill_id: string, id: string, skill_id: string, tref_id: string, parent: string, type: string}[] + */ + protected function __getSubTreeRec(string $id, bool $a_only_basic) : array { + $result = []; $childs = $this->getChildsOfNode($id); foreach ($childs as $c) { if (!$a_only_basic || in_array($c["type"], array("skll", "sktp")) || ($c["type"] == "sktr" && ilSkillTreeNode::_lookupType($c["skill_id"]) == "sktp")) { $result[] = $c; } - $this->__getSubTreeRec($c["id"], $result, $a_only_basic); + $result = array_merge($result, $this->__getSubTreeRec((int) $c["id"], $a_only_basic)); } + + return $result; } public function isDraft(string $a_node_id) : bool @@ -281,7 +305,7 @@ public function isOutdated(string $a_node_id) : bool * @param string $a_tref_id_key if first parameter is array[], this string identifies the key of the tref id * @return string[]|array[] */ - public function getOrderedNodeset(array $c_skill_ids, string $a_skill_id_key = "", string $a_tref_id_key = "") + public function getOrderedNodeset(array $c_skill_ids, string $a_skill_id_key = "", string $a_tref_id_key = "") : array { global $DIC; @@ -291,10 +315,10 @@ public function getOrderedNodeset(array $c_skill_ids, string $a_skill_id_key = " $node_data = []; $set = $db->query("SELECT t.child, t.parent, t.lft, n.order_nr FROM skl_tree t JOIN skl_tree_node n ON (t.child = n.obj_id)"); while ($rec = $db->fetchAssoc($set)) { - $node_data[$rec["child"]] = array( - "parent" => $rec["parent"], - "lft" => $rec["lft"], - "order_nr" => $rec["order_nr"], + $node_data[(int) $rec["child"]] = array( + "parent" => null === $rec["parent"] ? null : (int) $rec["parent"], + "lft" => (int) $rec["lft"], + "order_nr" => (int) $rec["order_nr"], ); } self::$order_node_data = $node_data; @@ -302,7 +326,7 @@ public function getOrderedNodeset(array $c_skill_ids, string $a_skill_id_key = " $node_data = self::$order_node_data; } - uasort($c_skill_ids, function ($a, $b) use ($node_data, $a_skill_id_key, $a_tref_id_key) { + uasort($c_skill_ids, function ($a, $b) use ($node_data, $a_skill_id_key, $a_tref_id_key) : int { // normalize to cskill strings if (is_array($a)) { @@ -352,7 +376,7 @@ protected function getPath(string $a, array $node_data) : array /** * get first uncommon ancestors of $a and $b in $node_data * - * @return array|false + * @return array{0: mixed, 1: mixed}|false */ protected function getFirstUncommonAncestors(string $a, string $b, array $node_data) { diff --git a/Services/Skill/Tree/class.ilVirtualSkillTreeExplorerGUI.php b/Services/Skill/Tree/class.ilVirtualSkillTreeExplorerGUI.php index 71b85183bac3..1dee46501bc3 100644 --- a/Services/Skill/Tree/class.ilVirtualSkillTreeExplorerGUI.php +++ b/Services/Skill/Tree/class.ilVirtualSkillTreeExplorerGUI.php @@ -78,6 +78,9 @@ public function getShowOutdatedNodes() : bool return $this->show_outdated_nodes; } + /** + * @return array{id: string, cskill_id: string} + */ public function getRootNode() : array { return $this->vtree->getRootNode(); @@ -103,7 +106,7 @@ public function getDomNodeIdForNodeId($a_node_id) : string /** * @inheritdoc */ - public function getNodeIdForDomNodeId($a_dom_node_id) : string + public function getNodeIdForDomNodeId(string $a_dom_node_id) : string { $id = parent::getNodeIdForDomNodeId($a_dom_node_id); return str_replace("_", ":", $id); @@ -111,7 +114,7 @@ public function getNodeIdForDomNodeId($a_dom_node_id) : string /** * @param string $a_parent_node_id - * @return array + * @return array{cskill_id: string, id: string, skill_id: string, tref_id: string, parent: string}[] */ public function getChildsOfNode($a_parent_node_id) : array { diff --git a/Services/Skill/classes/Provider/SkillMainBarProvider.php b/Services/Skill/classes/Provider/SkillMainBarProvider.php index 263bda8c2c90..0ae69a9b9c6a 100644 --- a/Services/Skill/classes/Provider/SkillMainBarProvider.php +++ b/Services/Skill/classes/Provider/SkillMainBarProvider.php @@ -65,9 +65,9 @@ public function getStaticSubItems() : array ->withParent(StandardTopItemsProvider::getInstance()->getAchievementsIdentification()) ->withPosition(20) ->withSymbol($icon) - ->withNonAvailableReason($this->dic->ui()->factory()->legacy("{$this->dic->language()->txt('component_not_active')}")) + ->withNonAvailableReason($this->dic->ui()->factory()->legacy($this->dic->language()->txt('component_not_active'))) ->withAvailableCallable( - function () { + static function () : bool { $skmg_set = new ilSetting("skmg"); return (bool) ($skmg_set->get("enable_skmg")); diff --git a/Services/Skill/classes/Setup/class.ilSkillDBUpdateSteps.php b/Services/Skill/classes/Setup/class.ilSkillDBUpdateSteps.php index 300c572e3fec..56b6087d1c0a 100644 --- a/Services/Skill/classes/Setup/class.ilSkillDBUpdateSteps.php +++ b/Services/Skill/classes/Setup/class.ilSkillDBUpdateSteps.php @@ -26,7 +26,7 @@ public function prepare(\ilDBInterface $db) : void $this->db = $db; } - public function step_1() + public function step_1() : void { if ($this->db->sequenceExists('skl_self_eval')) { $this->db->dropSequence('skl_self_eval'); @@ -41,7 +41,7 @@ public function step_1() } } - public function step_2() + public function step_2() : void { if (!$this->db->tableColumnExists('skl_user_skill_level', 'trigger_user_id')) { $this->db->addTableColumn( @@ -57,7 +57,7 @@ public function step_2() } } - public function step_3() + public function step_3() : void { if (!$this->db->tableColumnExists('skl_user_has_level', 'trigger_user_id')) { $this->db->addTableColumn( @@ -73,7 +73,7 @@ public function step_3() } } - public function step_4() + public function step_4() : void { include_once 'Services/Migration/DBUpdate_3560/classes/class.ilDBUpdateNewObjectType.php'; @@ -140,7 +140,7 @@ public function step_4() } } - public function step_5() + public function step_5() : void { include_once 'Services/Migration/DBUpdate_3560/classes/class.ilDBUpdateNewObjectType.php'; $skill_tree_type_id = ilDBUpdateNewObjectType::getObjectTypeId('skee'); @@ -157,7 +157,7 @@ public function step_5() ilDBUpdateNewObjectType::addRBACOperation($skill_tree_type_id, $ops_id); } - public function step_6() + public function step_6() : void { // get skill managemenet object id $set = $this->db->queryF( @@ -205,7 +205,7 @@ public function step_6() $tree->insertNode($ref_id, (int) $skmg_ref_id); } - public function step_7() + public function step_7() : void { $set = $this->db->queryF( "SELECT * FROM object_data " . @@ -226,7 +226,7 @@ public function step_7() ); } - public function step_8() + public function step_8() : void { if (!$this->db->tableColumnExists("skl_profile", "skill_tree_id")) { $this->db->addTableColumn("skl_profile", "skill_tree_id", array( @@ -238,7 +238,7 @@ public function step_8() } } - public function step_9() + public function step_9() : void { $set = $this->db->queryF( "SELECT * FROM object_data " . @@ -259,7 +259,7 @@ public function step_9() ); } - public function step_10() + public function step_10() : void { if (!$this->db->tableColumnExists("skl_profile", "image_id")) { $this->db->addTableColumn("skl_profile", "image_id", array( @@ -270,7 +270,7 @@ public function step_10() } } - public function step_11() + public function step_11() : void { if (!$this->db->tableExists("skl_profile_completion")) { $fields = [ diff --git a/Services/Skill/classes/class.ilBasicSkill.php b/Services/Skill/classes/class.ilBasicSkill.php index 513b7406d16f..b75ddc6fab8b 100644 --- a/Services/Skill/classes/class.ilBasicSkill.php +++ b/Services/Skill/classes/class.ilBasicSkill.php @@ -543,11 +543,10 @@ public function getShortTitleForCertificate() : string return "Skill"; } - public static function getUsageInfo(array $a_cskill_ids, array &$a_usages) // return type? + public static function getUsageInfo(array $a_cskill_ids) : array { - ilSkillUsage::getUsageInfoGeneric( + return ilSkillUsage::getUsageInfoGeneric( $a_cskill_ids, - $a_usages, ilSkillUsage::USER_ASSIGNED, "skl_user_skill_level", "user_id" diff --git a/Services/Skill/classes/class.ilBasicSkillGUI.php b/Services/Skill/classes/class.ilBasicSkillGUI.php index ed007a45d834..32fbd7361952 100644 --- a/Services/Skill/classes/class.ilBasicSkillGUI.php +++ b/Services/Skill/classes/class.ilBasicSkillGUI.php @@ -42,13 +42,32 @@ class ilBasicSkillGUI extends ilSkillTreeNodeGUI protected ServerRequestInterface $request; protected int $tref_id = 0; - protected int $base_skill_id = 0; protected int $requested_level_id = 0; protected int $requested_root_id = 0; + + /** + * @var int[] + */ protected array $requested_level_order = []; + + /** + * @var int[] + */ protected array $requested_level_ids = []; + + /** + * @var int[] + */ protected array $requested_resource_ids = []; + + /** + * @var array + */ protected array $requested_suggested = []; + + /** + * @var array + */ protected array $requested_trigger = []; public function __construct(Tree\SkillTreeNodeManager $node_manager, int $a_node_id = 0) @@ -449,7 +468,7 @@ public function deleteLevel() : void if (!empty($this->requested_level_ids)) { foreach ($this->requested_level_ids as $id) { - $this->node_object->deleteLevel((int) $id); + $this->node_object->deleteLevel($id); } $this->node_object->fixLevelNumbering(); } diff --git a/Services/Skill/classes/class.ilBasicSkillLevelDBRepository.php b/Services/Skill/classes/class.ilBasicSkillLevelDBRepository.php index f3779fdf9da6..9b136524df8c 100644 --- a/Services/Skill/classes/class.ilBasicSkillLevelDBRepository.php +++ b/Services/Skill/classes/class.ilBasicSkillLevelDBRepository.php @@ -73,6 +73,9 @@ protected function getMaxLevelNr(int $skill_id) : int return (int) $rec["mnr"] ?? 0; } + /** + * Returns multiple rows when $a_id is 0 else one or []. + */ public function getLevelData(int $skill_id, int $a_id = 0) : array { $ilDB = $this->db; @@ -98,7 +101,7 @@ public function getLevelData(int $skill_id, int $a_id = 0) : array return $levels; } - protected function lookupLevelProperty(int $a_id, string $a_prop) + protected function lookupLevelProperty(int $a_id, string $a_prop) : ?string { $ilDB = $this->db; @@ -107,7 +110,8 @@ protected function lookupLevelProperty(int $a_id, string $a_prop) " id = " . $ilDB->quote($a_id, "integer") ); $rec = $ilDB->fetchAssoc($set); - return $rec[$a_prop]; + + return isset($rec[$a_prop]) ? (string) $rec[$a_prop] : null; } public function lookupLevelTitle(int $a_id) : string @@ -125,7 +129,7 @@ public function lookupLevelSkillId(int $a_id) : int return $this->lookupLevelProperty($a_id, "skill_id") ?? 0; } - protected function writeLevelProperty(int $a_id, string $a_prop, $a_value, string $a_type) : void + protected function writeLevelProperty(int $a_id, string $a_prop, ?string $a_value, string $a_type) : void { $ilDB = $this->db; @@ -201,8 +205,8 @@ public function getSkillForLevelId(int $a_level_id) : ?ilBasicSkill ); $skill = null; if ($rec = $ilDB->fetchAssoc($set)) { - if ($this->tree_repo->isInAnyTree($rec["skill_id"])) { - $skill = new ilBasicSkill($rec["skill_id"]); + if ($this->tree_repo->isInAnyTree((int) $rec["skill_id"])) { + $skill = new ilBasicSkill((int) $rec["skill_id"]); } } return $skill; diff --git a/Services/Skill/classes/class.ilBasicSkillTemplateGUI.php b/Services/Skill/classes/class.ilBasicSkillTemplateGUI.php index d0b501d6d16f..71c34a9aa30e 100644 --- a/Services/Skill/classes/class.ilBasicSkillTemplateGUI.php +++ b/Services/Skill/classes/class.ilBasicSkillTemplateGUI.php @@ -150,7 +150,7 @@ public function setLevelHead() : void ); } - public function setTabs(string $a_tab = "") : void + public function setTabs(string $a_tab = "levels") : void { $ilTabs = $this->tabs; $ilCtrl = $this->ctrl; diff --git a/Services/Skill/classes/class.ilBasicSkillTreeDBRepository.php b/Services/Skill/classes/class.ilBasicSkillTreeDBRepository.php index 63b1c9aee247..a45a3270c2e5 100644 --- a/Services/Skill/classes/class.ilBasicSkillTreeDBRepository.php +++ b/Services/Skill/classes/class.ilBasicSkillTreeDBRepository.php @@ -56,7 +56,7 @@ public function getCommonSkillIdForImportId( " ORDER BY n.creation_date DESC "); while ($rec = $ilDB->fetchAssoc($set)) { if (($t = ilSkillTemplateReference::_lookupTemplateId($rec["obj_id"])) > 0) { - $template_ids[$t] = $rec["obj_id"]; + $template_ids[$t] = (int) $rec["obj_id"]; } } } else { @@ -86,7 +86,7 @@ public function getCommonSkillIdForImportId( } foreach ($matching_trefs as $t) { - $results[] = array("skill_id" => $rec["obj_id"], + $results[] = array("skill_id" => (int) $rec["obj_id"], "tref_id" => $t, "creation_date" => $rec["creation_date"] ); @@ -110,7 +110,7 @@ public function getLevelIdForImportId(int $a_source_inst_id, int $a_level_import " ORDER BY l.creation_date DESC "); $results = []; while ($rec = $ilDB->fetchAssoc($set)) { - $results[] = array("level_id" => $rec["id"], "creation_date" => $rec["creation_date"]); + $results[] = array("level_id" => (int) $rec["id"], "creation_date" => $rec["creation_date"]); } return $results; } diff --git a/Services/Skill/classes/class.ilBasicSkillUserLevelDBRepository.php b/Services/Skill/classes/class.ilBasicSkillUserLevelDBRepository.php index 27cf9371e919..61a4b597dcfc 100644 --- a/Services/Skill/classes/class.ilBasicSkillUserLevelDBRepository.php +++ b/Services/Skill/classes/class.ilBasicSkillUserLevelDBRepository.php @@ -136,6 +136,9 @@ public function hasRecentSelfEvaluation( return $recent; } + /** + * @return array + */ public function getNewAchievementsPerUser( string $a_timestamp, string $a_timestamp_to = null, @@ -162,6 +165,16 @@ public function getNewAchievementsPerUser( " ORDER BY user_id, status_date ASC "); $achievements = []; while ($rec = $ilDB->fetchAssoc($set)) { + $rec['user_id'] = (int) $rec['user_id']; + $rec['level_id'] = (int) $rec['level_id']; + $rec['skill_id'] = (int) $rec['skill_id']; + $rec['status'] = (int) $rec['status']; + $rec['valid'] = (int) $rec['valid']; + $rec['trigger_ref_id'] = (int) $rec['trigger_ref_id']; + $rec['trigger_obj_id'] = (int) $rec['trigger_obj_id']; + $rec['tref_id'] = (int) $rec['tref_id']; + $rec['self_eval'] = (int) $rec['self_eval']; + $rec['next_level_fullfilment'] = (float) $rec['next_level_fullfilment']; $achievements[$rec["user_id"]][] = $rec; } @@ -408,6 +421,9 @@ public function getAllHistoricLevelEntriesOfUser( ); $levels = []; while ($rec = $ilDB->fetchAssoc($set)) { + $rec['tref_id'] = (int) $rec['tref_id']; + $rec['skill_id'] = (int) $rec['skill_id']; + $rec['user_id'] = (int) $rec['user_id']; $levels[] = $rec; } return $levels; @@ -487,10 +503,7 @@ public function hasSelfEvaluated(int $a_user_id, int $a_skill_id, int $a_tref_id " AND self_eval = " . $ilDB->quote(1, "integer") ); - if ($rec = $ilDB->fetchAssoc($set)) { - return true; - } - return false; + return !!$ilDB->fetchAssoc($set); } public function getLastLevelPerObject( @@ -514,7 +527,7 @@ public function getLastLevelPerObject( ); if ($rec = $ilDB->fetchAssoc($set)) { - return $rec["level_id"]; + return (int) $rec["level_id"]; } return 0; diff --git a/Services/Skill/classes/class.ilObjSkillManagementGUI.php b/Services/Skill/classes/class.ilObjSkillManagementGUI.php index a5bd876d601e..030372802cf9 100644 --- a/Services/Skill/classes/class.ilObjSkillManagementGUI.php +++ b/Services/Skill/classes/class.ilObjSkillManagementGUI.php @@ -34,10 +34,7 @@ */ class ilObjSkillManagementGUI extends ilObjectGUI { - /** - * @var ilRbacSystem - */ - protected $rbacsystem; + protected ilRbacSystem $rbacsystem; protected ilErrorHandling $error; protected ilTabsGUI $tabs; protected Factory $ui_fac; @@ -54,7 +51,15 @@ class ilObjSkillManagementGUI extends ilObjectGUI protected int $requested_templates_tree = 0; protected string $requested_skexpand = ""; protected int $requested_tmpmode = 0; + + /** + * @var string[] + */ protected array $requested_titles = []; + + /** + * @var int[] + */ protected array $requested_node_ids = []; /** @@ -354,7 +359,7 @@ public function listTrees() : void $this->ctrl->redirectByClass("skilltreeadmingui", "listTrees"); } - public function saveAllTitles(bool $a_succ_mess = true) + public function saveAllTitles(bool $a_succ_mess = true) : void { $ilCtrl = $this->ctrl; $lng = $this->lng; @@ -374,7 +379,7 @@ public function saveAllTitles(bool $a_succ_mess = true) $ilCtrl->redirect($this, "editSkills"); } - public function saveAllTemplateTitles(bool $a_succ_mess = true) + public function saveAllTemplateTitles(bool $a_succ_mess = true) : void { $ilCtrl = $this->ctrl; $lng = $this->lng; @@ -394,7 +399,7 @@ public function saveAllTemplateTitles(bool $a_succ_mess = true) $ilCtrl->redirect($this, "editSkillTemplates"); } - public function expandAll(bool $a_redirect = true) + public function expandAll(bool $a_redirect = true) : void { $this->requested_skexpand = ""; $n_id = ($this->requested_node_id > 0) @@ -409,7 +414,7 @@ public function expandAll(bool $a_redirect = true) $this->saveAllTitles(false); } - public function collapseAll(bool $a_redirect = true) + public function collapseAll(bool $a_redirect = true) : void { $this->requested_skexpand = ""; $n_id = ($this->requested_node_id > 0) @@ -554,7 +559,7 @@ public function confirmedDelete() : void // Skill Templates // - public function editSkillTemplates() + public function editSkillTemplates() : void { $tpl = $this->tpl; $ilTabs = $this->tabs; @@ -570,7 +575,7 @@ public function editSkillTemplates() // Tree // - public function showTree(bool $a_templates, $a_gui = null, string $a_gui_cmd = "") + public function showTree(bool $a_templates, $a_gui = null, string $a_gui_cmd = "") : void { $ilUser = $this->user; $tpl = $this->tpl; diff --git a/Services/Skill/classes/class.ilPersonalSkill.php b/Services/Skill/classes/class.ilPersonalSkill.php index d8cea7953e6e..97cf116c7e46 100644 --- a/Services/Skill/classes/class.ilPersonalSkill.php +++ b/Services/Skill/classes/class.ilPersonalSkill.php @@ -24,6 +24,9 @@ */ class ilPersonalSkill implements ilSkillUsageInfo { + /** + * @return array + */ public static function getSelectedUserSkills(int $a_user_id) : array { global $DIC; @@ -39,8 +42,10 @@ public static function getSelectedUserSkills(int $a_user_id) : array $pskills = []; while ($rec = $ilDB->fetchAssoc($set)) { if ($repo->isInAnyTree($rec["skill_node_id"])) { - $pskills[$rec["skill_node_id"]] = array("skill_node_id" => $rec["skill_node_id"], - "title" => ilSkillTreeNode::_lookupTitle($rec["skill_node_id"])); + $pskills[(int) $rec["skill_node_id"]] = array( + "skill_node_id" => (int) $rec["skill_node_id"], + "title" => ilSkillTreeNode::_lookupTitle($rec["skill_node_id"]) + ); } } return $pskills; @@ -142,6 +147,7 @@ public static function assignMaterial( /** * Get assigned material (for a skill level and user) + * @return array{user_id: int, top_skill_id: int, skill_id: int, level_id: int, wsp_id: int, tref_id: int}[] */ public static function getAssignedMaterial(int $a_user_id, int $a_tref_id, int $a_level) : array { @@ -157,6 +163,12 @@ public static function getAssignedMaterial(int $a_user_id, int $a_tref_id, int $ ); $mat = []; while ($rec = $ilDB->fetchAssoc($set)) { + $rec['user_id'] = (int) $rec['user_id']; + $rec['top_skill_id'] = (int) $rec['top_skill_id']; + $rec['skill_id'] = (int) $rec['skill_id']; + $rec['level_id'] = (int) $rec['level_id']; + $rec['wsp_id'] = (int) $rec['wsp_id']; + $rec['tref_id'] = (int) $rec['tref_id']; $mat[] = $rec; } return $mat; @@ -274,16 +286,20 @@ public static function getSelfEvaluationDate( return $bs->getLastUpdatePerObject($a_tref_id, 0, $a_user_id, 1); } - public static function getUsageInfo(array $a_cskill_ids, array &$a_usages) : void + /** + * @param array{skill_id: int tref_id: int}[] $a_cskill_ids + * + * @return array> + */ + public static function getUsageInfo(array $a_cskill_ids) : array { global $DIC; $ilDB = $DIC->database(); // material - ilSkillUsage::getUsageInfoGeneric( + $a_usages = ilSkillUsage::getUsageInfoGeneric( $a_cskill_ids, - $a_usages, ilSkillUsage::USER_MATERIAL, "skl_assigned_material", "user_id" @@ -316,5 +332,7 @@ public static function getUsageInfo(array $a_cskill_ids, array &$a_usages) : voi array("key" => $rec["user_id"]); } } + + return $a_usages; } } diff --git a/Services/Skill/classes/class.ilPersonalSkillExplorerGUI.php b/Services/Skill/classes/class.ilPersonalSkillExplorerGUI.php index 3670d97929aa..6b6c24b4a5d0 100644 --- a/Services/Skill/classes/class.ilPersonalSkillExplorerGUI.php +++ b/Services/Skill/classes/class.ilPersonalSkillExplorerGUI.php @@ -27,19 +27,38 @@ */ class ilPersonalSkillExplorerGUI extends ilTreeExplorerGUI { + protected string $select_gui = ""; + protected string $select_cmd = ""; + protected string $select_par = ""; /** - * @var object|string + * @var array{child: int, parent: int}[] */ - protected $select_gui = ""; - protected string $select_cmd = ""; - protected string $select_par = ""; protected array $all_nodes = []; + + /** + * @var array + */ protected array $node = []; + + /** + * @var array + */ protected array $child_nodes = []; + + /** + * @var array + */ protected array $parent = []; + /** + * @var array + */ protected array $selectable = []; + + /** + * @var array + */ protected array $selectable_child_nodes = []; protected bool $has_selectable_nodes = false; diff --git a/Services/Skill/classes/class.ilPersonalSkillsGUI.php b/Services/Skill/classes/class.ilPersonalSkillsGUI.php index 04cd7ed16adf..5d7f247cabba 100644 --- a/Services/Skill/classes/class.ilPersonalSkillsGUI.php +++ b/Services/Skill/classes/class.ilPersonalSkillsGUI.php @@ -36,11 +36,27 @@ class ilPersonalSkillsGUI public const LIST_PROFILES = ""; protected string $offline_mode = ""; + + /** + * @var array> + */ protected array $actual_levels = []; + + /** + * @var array> + */ protected array $gap_self_eval_levels = []; protected bool $history_view = false; + + /** + * @var int[] + */ protected array $trigger_objects_filter = []; protected string $intro_text = ""; + + /** + * @var string[] + */ protected array $hidden_skills = []; protected string $mode = ""; protected string $gap_mode = ""; @@ -63,10 +79,26 @@ class ilPersonalSkillsGUI protected ResourceStorage $storage; protected int $obj_id = 0; + + /** + * @var array + */ protected array $obj_skills = []; protected int $profile_id = 0; + + /** + * @var array{base_skill_id: int, tref_id: int, level_id: int, order_nr: int}[] + */ protected array $profile_levels = []; + + /** + * @var array{id: int, title: string, description: string, image_id: string}[] + */ protected array $user_profiles = []; + + /** + * @var array + */ protected array $cont_profiles = []; protected bool $use_materials = false; protected ilSkillManagementSettings $skmg_settings; @@ -78,13 +110,25 @@ class ilPersonalSkillsGUI protected int $requested_node_id = 0; protected int $requested_profile_id = 0; protected int $requested_skill_id = 0; + + /** + * @var int[] + */ protected array $requested_skill_ids = []; protected int $requested_basic_skill_id = 0; protected int $requested_tref_id = 0; protected int $requested_level_id = 0; protected int $requested_self_eval_level_id = 0; protected int $requested_wsp_id = 0; + + /** + * @var int[] + */ protected array $requested_wsp_ids = []; + + /** + * @var string[] + */ protected array $trigger_user_filter = []; public function __construct() @@ -161,7 +205,7 @@ public function getProfileId() : int } /** - * @param array $a_val self evaluation values key1: base_skill_id, key2: tref_id: value: level id + * @param array> $a_val self evaluation values key1: base_skill_id, key2: tref_id: value: level id */ public function setGapAnalysisSelfEvalLevels(array $a_val) : void { @@ -207,17 +251,17 @@ public function getIntroText() : string } /** - * @return array + * @return string[] */ - public function getTriggerUserFilter() + public function getTriggerUserFilter() : array { return $this->trigger_user_filter; } /** - * @param array $trigger_user_filter + * @param string[] $trigger_user_filter */ - public function setTriggerUserFilter($trigger_user_filter) + public function setTriggerUserFilter(array $trigger_user_filter) : void { $this->trigger_user_filter = $trigger_user_filter; } @@ -263,12 +307,18 @@ public function getObjectId() : int return $this->obj_id; } + /** + * @return array + */ public function getObjectSkills() : array { return $this->obj_skills; } - public function setObjectSkills(int $a_obj_id, ?array $a_skills = null) : void + /** + * @param array $a_skills + */ + public function setObjectSkills(int $a_obj_id, array $a_skills) : void { $this->obj_id = $a_obj_id; $this->obj_skills = $a_skills; @@ -902,7 +952,7 @@ public function selectMaterial() : void $this->requested_tref_id, $this->requested_basic_skill_id, $this->requested_level_id, - (int) $w + $w ); } $this->tpl->setOnScreenMessage('success', $lng->txt("msg_obj_modified"), true); @@ -1124,7 +1174,7 @@ public function setGapAnalysisActualStatusModePerObject(int $a_obj_id, string $a $this->mode = "gap"; } - public function getGapAnalysisHTML($a_user_id = 0, array $a_skills = null) : string + public function getGapAnalysisHTML(int $a_user_id = 0, array $a_skills = null) : string { $ilUser = $this->user; $lng = $this->lng; diff --git a/Services/Skill/classes/class.ilSkillDataSet.php b/Services/Skill/classes/class.ilSkillDataSet.php index 0e645b41cc9f..071d445e63fd 100644 --- a/Services/Skill/classes/class.ilSkillDataSet.php +++ b/Services/Skill/classes/class.ilSkillDataSet.php @@ -44,7 +44,14 @@ class ilSkillDataSet extends ilDataSet protected int $init_top_order_nr = 0; protected int $init_templ_top_order_nr = 0; + /** + * @var int[] + */ protected array $selected_nodes = []; + + /** + * @var int[] + */ protected array $selected_profiles = []; protected string $mode = ""; @@ -494,6 +501,11 @@ public function readData(string $a_entity, string $a_version, array $a_ids) : vo } } + /** + * @param array{Id: int, Child: int Type: string} $a_rec + * + * @return array + */ protected function getDependencies( string $a_entity, string $a_version, @@ -551,7 +563,7 @@ protected function getDependencies( $set = $ilDB->query("SELECT DISTINCT(templ_id) FROM skl_templ_ref " . " WHERE " . $ilDB->in("skl_node_id", $ref_nodes, false, "integer")); while ($rec = $ilDB->fetchAssoc($set)) { - $deps["skl_templ_subtree"]["ids"][] = $rec["templ_id"]; + $deps["skl_templ_subtree"]["ids"][] = (int) $rec["templ_id"]; } // export subtree after templates diff --git a/Services/Skill/classes/class.ilSkillExportConfig.php b/Services/Skill/classes/class.ilSkillExportConfig.php index 01339e6ed27a..025afaa1712b 100644 --- a/Services/Skill/classes/class.ilSkillExportConfig.php +++ b/Services/Skill/classes/class.ilSkillExportConfig.php @@ -27,7 +27,15 @@ class ilSkillExportConfig extends ilExportConfig { public const MODE_SKILLS = ""; public const MODE_PROFILES = "prof"; + + /** + * @var int[] + */ protected array $selected_nodes = []; + + /** + * @var int[] + */ protected array $selected_profiles = []; protected string $mode = ""; protected int $skill_tree_id = 0; diff --git a/Services/Skill/classes/class.ilSkillSelectorGUI.php b/Services/Skill/classes/class.ilSkillSelectorGUI.php index c20f833e0c14..caa5eac639da 100644 --- a/Services/Skill/classes/class.ilSkillSelectorGUI.php +++ b/Services/Skill/classes/class.ilSkillSelectorGUI.php @@ -26,13 +26,14 @@ */ class ilSkillSelectorGUI extends ilVirtualSkillTreeExplorerGUI { - /** - * @var object|string - */ - protected $select_gui = ""; + protected string $select_gui = ""; protected string $select_cmd = ""; protected string $select_par = ""; protected SkillAdminGUIRequest $admin_gui_request; + + /** + * @var string[] + */ protected array $requested_selected_ids = []; public function __construct( diff --git a/Services/Skill/classes/class.ilSkillTemplateReferenceGUI.php b/Services/Skill/classes/class.ilSkillTemplateReferenceGUI.php index d3f0e900995d..06c70fd5aef1 100644 --- a/Services/Skill/classes/class.ilSkillTemplateReferenceGUI.php +++ b/Services/Skill/classes/class.ilSkillTemplateReferenceGUI.php @@ -73,7 +73,7 @@ public function executeCommand() : void } } - public function setTabs($a_tab = "") : void + public function setTabs($a_tab = "levels") : void { $ilTabs = $this->tabs; $ilCtrl = $this->ctrl; diff --git a/Services/Skill/classes/class.ilSkillUsage.php b/Services/Skill/classes/class.ilSkillUsage.php index d66710e1b928..5818089a47ac 100644 --- a/Services/Skill/classes/class.ilSkillUsage.php +++ b/Services/Skill/classes/class.ilSkillUsage.php @@ -49,7 +49,7 @@ class ilSkillUsage implements ilSkillUsageInfo /** * @var ilSkillUsageInfo[] */ - protected $classes = [ilBasicSkill::class, ilPersonalSkill::class, ilSkillProfile::class, + protected array $classes = [ilBasicSkill::class, ilPersonalSkill::class, ilSkillProfile::class, ilSkillResources::class, ilSkillUsage::class]; protected ilBasicSkillTreeRepository $tree_repo; @@ -90,7 +90,7 @@ public static function setUsage(int $a_obj_id, int $a_skill_id, int $a_tref_id, } /** - * @return array|int[] + * @return int[] */ public static function getUsages(int $a_skill_id, int $a_tref_id) : array { @@ -111,11 +111,15 @@ public static function getUsages(int $a_skill_id, int $a_tref_id) : array return $obj_ids; } - public static function getUsageInfo(array $a_cskill_ids, array &$a_usages) : void + /** + * @param array{skill_id: int tref_id: int}[] $a_cskill_ids + * + * @return array> + */ + public static function getUsageInfo(array $a_cskill_ids) : array { - self::getUsageInfoGeneric( + return self::getUsageInfoGeneric( $a_cskill_ids, - $a_usages, ilSkillUsage::TYPE_GENERAL, "skl_usage", "obj_id" @@ -124,22 +128,26 @@ public static function getUsageInfo(array $a_cskill_ids, array &$a_usages) : voi /** * Get standard usage query + * @param array{skill_id: int tref_id: int}[] $a_cskill_ids + * + * @return array> */ public static function getUsageInfoGeneric( array $a_cskill_ids, - array &$a_usages, string $a_usage_type, string $a_table, string $a_key_field, string $a_skill_field = "skill_id", string $a_tref_field = "tref_id" - ) : void { + ) : array { global $DIC; + $a_usages = []; + $ilDB = $DIC->database(); if (count($a_cskill_ids) == 0) { - return; + return []; } $w = "WHERE"; @@ -156,11 +164,13 @@ public static function getUsageInfoGeneric( $a_usages[$rec[$a_skill_field] . ":" . $rec[$a_tref_field]][$a_usage_type][] = array("key" => $rec[$a_key_field]); } + + return $a_usages; } /** - * @param array $a_cskill_ids array of common skill ids ("skill_id" => skill_id, "tref_id" => tref_id) - * @return array + * @param array{skill_id: int, tref_id: int}[] $a_cskill_ids array of common skill ids ("skill_id" => skill_id, "tref_id" => tref_id) + * @return array> */ public function getAllUsagesInfo(array $a_cskill_ids) : array { @@ -168,14 +178,14 @@ public function getAllUsagesInfo(array $a_cskill_ids) : array $usages = []; foreach ($classes as $class) { - $class::getUsageInfo($a_cskill_ids, $usages); + $usages = array_merge_recursive($usages, $class::getUsageInfo($a_cskill_ids)); } return $usages; } /** * @param array $a_tree_ids array of common skill ids ("skill_id" => skill_id, "tref_id" => tref_id) - * @return array + * @return array> */ public function getAllUsagesInfoOfTrees(array $a_tree_ids) : array { @@ -193,6 +203,9 @@ public function getAllUsagesInfoOfTrees(array $a_tree_ids) : array return $this->getAllUsagesInfo($allnodes); } + /** + * @return array> + */ public function getAllUsagesInfoOfSubtree(int $a_skill_id, int $a_tref_id = 0) : array { // get nodes @@ -204,7 +217,7 @@ public function getAllUsagesInfoOfSubtree(int $a_skill_id, int $a_tref_id = 0) : /** * @param array $a_cskill_ids array of common skill ids ("skill_id" => skill_id, "tref_id" => tref_id) - * @return array + * @return array> */ public function getAllUsagesInfoOfSubtrees(array $a_cskill_ids) : array { @@ -221,6 +234,9 @@ public function getAllUsagesInfoOfSubtrees(array $a_cskill_ids) : array return $this->getAllUsagesInfo($allnodes); } + /** + * @return array> + */ public function getAllUsagesOfTemplate(int $a_template_id) : array { $skill_logger = ilLoggerFactory::getLogger('skll'); @@ -275,6 +291,9 @@ public static function getObjTypeString(string $a_type) : string } } + /** + * @return int[] + */ public function getAssignedObjectsForSkill(int $a_skill_id, int $a_tref_id) : array { //$objects = $this->getAllUsagesInfoOfSubtree($a_skill_id, $a_tref_id); @@ -283,19 +302,20 @@ public function getAssignedObjectsForSkill(int $a_skill_id, int $a_tref_id) : ar return $objects; } + /** + * @return string[] + */ public function getAssignedObjectsForSkillTemplate(int $a_template_id) : array { $usages = $this->getAllUsagesOfTemplate($a_template_id); $obj_usages = array_column($usages, "gen"); - $objects = []; - $objects["objects"] = []; - foreach ($obj_usages as $obj) { - $objects["objects"] = array_column($obj, "key"); - } - return $objects["objects"]; + return array_column(current(array_reverse($obj_usages)) ?: [], 'key'); } + /** + * @return int[] + */ public function getAssignedObjectsForSkillProfile(int $a_profile_id) : array { $profile = new ilSkillProfile($a_profile_id); diff --git a/Services/Skill/interfaces/interface.ilBasicSkillUserLevelRepository.php b/Services/Skill/interfaces/interface.ilBasicSkillUserLevelRepository.php index e1f69b41b9d2..7cdc323b4667 100644 --- a/Services/Skill/interfaces/interface.ilBasicSkillUserLevelRepository.php +++ b/Services/Skill/interfaces/interface.ilBasicSkillUserLevelRepository.php @@ -102,7 +102,8 @@ public function writeUserSkillLevelStatus( int $a_tref_id = 0, bool $a_self_eval = false, string $a_unique_identifier = "", - float $a_next_level_fulfilment = 0.0 + float $a_next_level_fulfilment = 0.0, + string $trigger_user_id = "" ) : void; /** diff --git a/Services/Skill/interfaces/interface.ilSkillUsageInfo.php b/Services/Skill/interfaces/interface.ilSkillUsageInfo.php index 0fe0560a85cb..449b333bafe8 100644 --- a/Services/Skill/interfaces/interface.ilSkillUsageInfo.php +++ b/Services/Skill/interfaces/interface.ilSkillUsageInfo.php @@ -28,8 +28,9 @@ interface ilSkillUsageInfo /** * Get title of an assigned item * - * @param array $a_cskill_ids array of common skill ids ("skill_id" => skill_id, "tref_id" => tref_id) - * @param array $a_usages + * @param array{skill_id: int, tref_id: int}[] $a_cskill_ids array of common skill ids + * + * @return array> */ - public static function getUsageInfo(array $a_cskill_ids, array &$a_usages); + public static function getUsageInfo(array $a_cskill_ids) : array; }