diff --git a/Services/Skill/Profile/class.ilSkillProfileGUI.php b/Services/Skill/Profile/class.ilSkillProfileGUI.php index b15d81090a51..f01e640029b5 100644 --- a/Services/Skill/Profile/class.ilSkillProfileGUI.php +++ b/Services/Skill/Profile/class.ilSkillProfileGUI.php @@ -98,12 +98,7 @@ class ilSkillProfileGUI * @var string[] */ protected array $requested_table_profile_ids = []; - protected string $requested_table_profile_level_assignment_action = ""; - - /** - * @var string[] - */ - protected array $requested_table_profile_level_assignment_ids = []; + protected int $requested_level_id = 0; protected bool $local_context = false; public function __construct(SkillTreeAccess $skill_tree_access_manager, int $skill_tree_id = 0) @@ -145,8 +140,7 @@ public function __construct(SkillTreeAccess $skill_tree_access_manager, int $ski $this->requested_user_ids = $this->admin_gui_request->getUserIds(); $this->requested_table_profile_action = $this->admin_gui_request->getTableProfileAction(); $this->requested_table_profile_ids = $this->admin_gui_request->getTableProfileIds(); - $this->requested_table_profile_level_assignment_action = $this->admin_gui_request->getTableProfileLevelAssignmentAction(); - $this->requested_table_profile_level_assignment_ids = $this->admin_gui_request->getTableProfileLevelAssignmentIds(); + $this->requested_level_id = $this->admin_gui_request->getLevelId(); if ($this->requested_sprof_id > 0) { $this->id = $this->requested_sprof_id; @@ -663,9 +657,31 @@ public function assignLevelSelectSkill(bool $update = false): void ); } - $table = $this->table_manager->getProfileLevelAssignmentTable($this->requested_cskill_id, $update) - ->getComponent(); - $tpl->setContent($this->ui_ren->render($table)); + $id_parts = explode(":", $this->requested_cskill_id); + $skill_id = (int) $id_parts[0]; + $skill = new ilBasicSkill($skill_id); + $level_data = $skill->getLevelData(); + + $items = []; + foreach ($level_data as $levels) { + $ilCtrl->setParameterByClass(self::class, "level_id", $levels["id"]); + $items[] = $this->ui_fac->item()->standard($levels["title"])->withMainAction( + $this->ui_fac->link()->standard( + $lng->txt("skmg_assign_level"), + $ilCtrl->getLinkTarget($this, $update ? "updateLevelOfProfile" : "assignLevelToProfile") + ) + ); + $ilCtrl->clearParameterByClass(self::class, "level_id"); + } + + $list = $this->ui_fac->panel()->listing()->standard( + $skill->getTitle() . ", " . $lng->txt("skmg_skill_levels"), + [ + $this->ui_fac->item()->group("", $items) + ] + ); + + $tpl->setContent($this->ui_ren->render($list)); } public function updateLevelOfSelectedSkill(): void @@ -685,15 +701,13 @@ public function assignLevelToProfile(Profile\SkillProfileLevel $level = null): v if ($level) { $this->profile_manager->updateSkillLevel($level); - } elseif ($this->requested_table_profile_level_assignment_action === "assignLevel" - && !empty($this->requested_table_profile_level_assignment_ids) - ) { + } else { $parts = explode(":", $this->requested_cskill_id); $level = $this->skill_factory->profile()->profileLevel( $this->profile->getId(), (int) $parts[0], (int) $parts[1], - (int) $this->requested_table_profile_level_assignment_ids[0], + $this->requested_level_id, $this->profile_manager->getMaxLevelOrderNr($this->profile->getId()) + 10 ); $this->profile_manager->addSkillLevel($level); @@ -711,20 +725,16 @@ public function assignLevelToProfile(Profile\SkillProfileLevel $level = null): v public function updateLevelOfProfile(): void { - if ($this->requested_table_profile_level_assignment_action === "assignLevel" - && !empty($this->requested_table_profile_level_assignment_ids) - ) { - $parts = explode(":", $this->requested_cskill_id); - $level = $this->profile_manager->getSkillLevel($this->profile->getId(), (int) $parts[0], (int) $parts[1]); - $level_updated = $this->skill_factory->profile()->profileLevel( - $level->getProfileId(), - $level->getBaseSkillId(), - $level->getTrefId(), - (int) $this->requested_table_profile_level_assignment_ids[0], - $level->getOrderNr() - ); - $this->assignLevelToProfile($level_updated); - } + $parts = explode(":", $this->requested_cskill_id); + $level = $this->profile_manager->getSkillLevel($this->profile->getId(), (int) $parts[0], (int) $parts[1]); + $level_updated = $this->skill_factory->profile()->profileLevel( + $level->getProfileId(), + $level->getBaseSkillId(), + $level->getTrefId(), + $this->requested_level_id, + $level->getOrderNr() + ); + $this->assignLevelToProfile($level_updated); } public function confirmLevelAssignmentRemoval(): void diff --git a/Services/Skill/Service/classes/class.SkillAdminGUIRequest.php b/Services/Skill/Service/classes/class.SkillAdminGUIRequest.php index 185174eda2cd..b47d45a94389 100644 --- a/Services/Skill/Service/classes/class.SkillAdminGUIRequest.php +++ b/Services/Skill/Service/classes/class.SkillAdminGUIRequest.php @@ -227,19 +227,6 @@ public function getTableProfileIds(): array return $this->getTableIds("skl_profile_table_profile_ids"); } - public function getTableProfileLevelAssignmentAction(): string - { - return $this->getTableAction("skl_profile_level_assignment_table_action"); - } - - /** - * @return string[] - */ - public function getTableProfileLevelAssignmentIds(): array - { - return $this->getTableIds("skl_profile_level_assignment_table_level_ids"); - } - public function getTableProfileUserAssignmentAction(): string { return $this->getTableAction("skl_profile_user_assignment_table_action"); diff --git a/Services/Skill/Table/classes/class.ProfileLevelAssignmentTable.php b/Services/Skill/Table/classes/class.ProfileLevelAssignmentTable.php deleted file mode 100644 index 97b18769977e..000000000000 --- a/Services/Skill/Table/classes/class.ProfileLevelAssignmentTable.php +++ /dev/null @@ -1,176 +0,0 @@ - - */ -class ProfileLevelAssignmentTable -{ - protected \ilCtrl $ctrl; - protected \ilLanguage $lng; - protected UI\Factory $ui_fac; - protected ServerRequestInterface $request; - protected Data\Factory $df; - protected string $cskill_id = ""; - protected int $skill_id = 0; - protected bool $update = false; - protected \ilBasicSkill $skill; - - public function __construct(string $cskill_id, bool $update = false) - { - global $DIC; - - $this->ctrl = $DIC->ctrl(); - $this->lng = $DIC->language(); - $this->ui_fac = $DIC->ui()->factory(); - $this->request = $DIC->http()->request(); - $this->df = new Data\Factory(); - - $this->cskill_id = $cskill_id; - $id_parts = explode(":", $this->cskill_id); - $this->skill_id = (int) $id_parts[0]; - $this->skill = new \ilBasicSkill($this->skill_id); - $this->update = $update; - } - - public function getComponent(): UI\Component\Table\Data - { - $columns = $this->getColumns(); - $actions = $this->getActions(); - $data_retrieval = $this->getDataRetrieval(); - - $title = $this->skill->getTitle() . ", " . $this->lng->txt("skmg_skill_levels"); - $table = $this->ui_fac->table() - ->data($title, $columns, $data_retrieval) - ->withId( - self::class . "_" . - $this->cskill_id - ) - ->withActions($actions) - ->withRequest($this->request); - - return $table; - } - - protected function getColumns(): array - { - $columns = [ - "title" => $this->ui_fac->table()->column()->text($this->lng->txt("title")) - ->withIsSortable(false) - ]; - - return $columns; - } - - protected function getActions(): array - { - $query_params_namespace = ["skl_profile_level_assignment_table"]; - - $uri_assign = $this->df->uri( - ILIAS_HTTP_PATH . "/" . $this->ctrl->getLinkTargetByClass( - "ilskillprofilegui", - $this->update ? "updateLevelOfProfile" : "assignLevelToProfile" - ) - ); - $url_builder_assign = new UI\URLBuilder($uri_assign); - list($url_builder_assign, $action_parameter_token_assign, $row_id_token_assign) = - $url_builder_assign->acquireParameters( - $query_params_namespace, - "action", - "level_ids" - ); - - $actions = [ - "assign" => $this->ui_fac->table()->action()->single( - $this->lng->txt("skmg_assign_level"), - $url_builder_assign->withParameter($action_parameter_token_assign, "assignLevel"), - $row_id_token_assign - ) - ]; - - return $actions; - } - - protected function getDataRetrieval(): UI\Component\Table\DataRetrieval - { - $data_retrieval = new class ( - $this->skill - ) implements UI\Component\Table\DataRetrieval { - use TableRecords; - - public function __construct( - protected \ilBasicSkill $skill - ) { - } - - public function getRows( - UI\Component\Table\DataRowBuilder $row_builder, - array $visible_column_ids, - Data\Range $range, - Data\Order $order, - ?array $filter_data, - ?array $additional_parameters - ): \Generator { - $records = $this->getRecords($range); - foreach ($records as $idx => $record) { - $row_id = $record["id"]; - - yield $row_builder->buildDataRow((string) $row_id, $record); - } - } - - public function getTotalRowCount( - ?array $filter_data, - ?array $additional_parameters - ): ?int { - return count($this->getRecords()); - } - - protected function getRecords(Data\Range $range = null): array - { - $level_data = $this->skill->getLevelData(); - - $records = []; - $i = 0; - foreach ($level_data as $levels) { - $records[$i]["id"] = $levels["id"]; - $records[$i]["title"] = $levels["title"]; - - $i++; - } - - if ($range) { - $records = $this->limitRecords($records, $range); - } - - return $records; - } - }; - - return $data_retrieval; - } -} diff --git a/Services/Skill/Table/classes/class.TableManager.php b/Services/Skill/Table/classes/class.TableManager.php index 55c4e5806723..1f6094691348 100644 --- a/Services/Skill/Table/classes/class.TableManager.php +++ b/Services/Skill/Table/classes/class.TableManager.php @@ -65,13 +65,6 @@ public function getProfileTable( return new ProfileTable($ref_id, $skill_tree_id); } - public function getProfileLevelAssignmentTable( - string $cskill_id, - bool $update = false - ): ProfileLevelAssignmentTable { - return new ProfileLevelAssignmentTable($cskill_id, $update); - } - public function getProfileUserAssignmentTable( Profile\SkillProfile $profile, Access\SkillTreeAccess $tree_access_manager