Skip to content

Skill: Make sub-skill auto-loading optional in manual skill assignment - refs #6158 #6160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 31 additions & 26 deletions public/main/skills/assign.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
$skillUserRepo = $entityManager->getRepository(\Chamilo\CoreBundle\Entity\SkillRelUser::class);

$skillLevels = api_get_setting('skill.skill_levels_names', true);
$autoloadSubskills = api_get_setting('skill.manual_assignment_subskill_autoload');

$skillsOptions = ['' => get_lang('Select')];
$acquiredLevel = ['' => get_lang('none')];
Expand Down Expand Up @@ -63,26 +64,28 @@
$subSkillList = array_unique($subSkillList);

if (empty($subSkillList) && $skillId) {
$skillRelSkill = new SkillRelSkillModel();
$parents = $skillRelSkill->getSkillParents($skillId);
ksort($parents);

$subSkillList = [];
foreach ($parents as $parent) {
if ($parent['skill_id'] != 1) {
$subSkillList[] = $parent['skill_id'];
if ('true' === $autoloadSubskills) {
$skillRelSkill = new SkillRelSkillModel();
$parents = $skillRelSkill->getSkillParents($skillId);
ksort($parents);

$subSkillList = [];
foreach ($parents as $parent) {
if ($parent['skill_id'] != 1) {
$subSkillList[] = $parent['skill_id'];
}
}
}
$subSkillList[] = $skillId;
$subSkillList = array_unique($subSkillList);
$subSkillList[] = $skillId;
$subSkillList = array_unique($subSkillList);

$firstParentId = $subSkillList[0];
$subSkillListToString = implode(',', array_slice($subSkillList, 0, -1)) . ',' . $skillId;
$currentLevel = 'sub_skill_id_' . count($subSkillList) - 1;
$firstParentId = $subSkillList[0];
$subSkillListToString = implode(',', array_slice($subSkillList, 0, -1)) . ',' . $skillId;
$currentLevel = 'sub_skill_id_' . count($subSkillList) - 1;

$currentUrl = api_get_path(WEB_CODE_PATH).'skills/assign.php?user='.$userId.'&id='.$firstParentId.'&current_value='.$skillId.'&current='.$currentLevel.'&sub_skill_list='.$subSkillListToString;
header('Location: '.$currentUrl);
exit;
$currentUrl = api_get_path(WEB_CODE_PATH).'skills/assign.php?user='.$userId.'&id='.$firstParentId.'&current_value='.$skillId.'&current='.$currentLevel.'&sub_skill_list='.$subSkillListToString;
header('Location: '.$currentUrl);
exit;
}
}

if (!empty($subSkillList)) {
Expand Down Expand Up @@ -221,15 +224,17 @@
}
}

$form->addSelect(
'sub_skill_id_'.($counter + 1),
$levelName,
$skillsOptions,
[
'id' => 'sub_skill_id_'.($counter + 1),
'class' => 'sub_skill ',
]
);
if ('true' === $autoloadSubskills) {
$form->addSelect(
'sub_skill_id_'.($counter + 1),
$levelName,
$skillsOptions,
[
'id' => 'sub_skill_id_'.($counter + 1),
'class' => 'sub_skill ',
]
);
}

if (isset($subSkillList[$counter + 1])) {
$nextSkill = $skillRepo->find($subSkillList[$counter + 1]);
Expand Down
5 changes: 5 additions & 0 deletions src/CoreBundle/DataFixtures/SettingsCurrentFixtures.php
Original file line number Diff line number Diff line change
Expand Up @@ -3427,6 +3427,11 @@ public static function getNewConfigurationSettings(): array
'title' => 'Allow teachers to set which skills are acquired through their courses',
'comment' => 'By default, only admins can decide which skills can be acquired through which course.',
],
[
'name' => 'manual_assignment_subskill_autoload',
'title' => 'Assigning skills to user: sub-skills auto-loading',
'comment' => 'When manually assigning skills to a user, the form can be set to automatically offer you to assign a sub-skill instead of the skill you selected.',
],
],
'survey' => [
[
Expand Down
2 changes: 2 additions & 0 deletions src/CoreBundle/Settings/SkillSettingsSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function buildSettings(AbstractSettingsBuilder $builder): void
'skills_hierarchical_view_in_user_tracking' => 'false',
'skill_levels_names' => '',
'allow_skill_rel_items' => 'false',
'manual_assignment_subskill_autoload' => 'false',
]
)
;
Expand Down Expand Up @@ -59,6 +60,7 @@ public function buildForm(FormBuilderInterface $builder): void
]
)
->add('allow_skill_rel_items', YesNoType::class)
->add('manual_assignment_subskill_autoload', YesNoType::class)
;

$this->updateFormFieldsFromSettingsInfo($builder);
Expand Down
Loading