Add option to enable/disable skills - refs BT#10181

1.10.x
Angel Fernando Quiroz Campos 10 years ago
parent d2f674b463
commit da5c70c191
  1. 159
      main/admin/skill_list.php
  2. 3
      main/inc/lib/skill.lib.php
  3. 16
      main/template/default/skill/list.tpl

@ -19,44 +19,121 @@ if (api_get_setting('allow_skills_tool') != 'true') {
api_not_allowed();
}
$interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
$message = Session::has('message') ? Session::read('message') : null;
$toolbar = Display::toolbarButton(
get_lang('CreateSkill'),
api_get_path(WEB_CODE_PATH) . 'admin/skill_create.php',
'plus',
'success',
['title' => get_lang('CreateSkill')]
);
$toolbar .= Display::toolbarButton(
get_lang('SkillsWheel'),
api_get_path(WEB_CODE_PATH) . 'admin/skills_wheel.php',
'bullseye',
'primary',
['title' => get_lang('CreateSkill')]
);
$toolbar .= Display::toolbarButton(
get_lang('BadgesManagement'),
api_get_path(WEB_CODE_PATH) . 'admin/skill_badge_list.php',
'certificate',
'warning',
['title' => get_lang('BadgesManagement')]
);
/* View */
$skill = new Skill();
$skillList = $skill->get_all();
$tpl = new Template(get_lang('ManageSkills'));
$tpl->assign('message', $message);
$tpl->assign('skills', $skillList);
$content = $tpl->fetch('default/skill/list.tpl');
$tpl->assign('actions', $toolbar);
$tpl->assign('content', $content);
$tpl->display_one_col_template();
Session::erase('message');
$action = isset($_GET['action']) ? $_GET['action'] : 'list';
$skillId = isset($_GET['id']) ? intval($_GET['id']): 0;
$entityManager = Database::getManager();
switch ($action) {
case 'enable':
$skill = $entityManager->find('ChamiloCoreBundle:Skill', $skillId);
if (is_null($skill)) {
Display::addFlash(
Display::return_message(
get_lang('SkillNotFound'),
'error'
)
);
} else {
$updatedAt = new DateTime(
api_get_utc_datetime(),
new DateTimeZone(_api_get_timezone())
);
$skill->setStatus(1);
$skill->setUpdatedAt($updatedAt);
$entityManager->persist($skill);
$entityManager->flush();
Display::addFlash(
Display::return_message(
sprintf(get_lang('SkillXEnabled'), $skill->getName()),
'success'
)
);
}
header('Location: ' . api_get_self());
exit;
break;
case 'disable':
$skill = $entityManager->find('ChamiloCoreBundle:Skill', $skillId);
if (is_null($skill)) {
Display::addFlash(
Display::return_message(
get_lang('SkillNotFound'),
'error'
)
);
} else {
$updatedAt = new DateTime(
api_get_utc_datetime(),
new DateTimeZone(_api_get_timezone())
);
$skill->setStatus(0);
$skill->setUpdatedAt($updatedAt);
$entityManager->persist($skill);
$entityManager->flush();
Display::addFlash(
Display::return_message(
sprintf(get_lang('SkillXDisabled'), $skill->getName()),
'success'
)
);
}
header('Location: ' . api_get_self());
exit;
break;
case 'list':
//no break
default:
$interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
$message = Session::has('message') ? Session::read('message') : null;
$toolbar = Display::toolbarButton(
get_lang('CreateSkill'),
api_get_path(WEB_CODE_PATH) . 'admin/skill_create.php',
'plus',
'success',
['title' => get_lang('CreateSkill')]
);
$toolbar .= Display::toolbarButton(
get_lang('SkillsWheel'),
api_get_path(WEB_CODE_PATH) . 'admin/skills_wheel.php',
'bullseye',
'primary',
['title' => get_lang('CreateSkill')]
);
$toolbar .= Display::toolbarButton(
get_lang('BadgesManagement'),
api_get_path(WEB_CODE_PATH) . 'admin/skill_badge_list.php',
'certificate',
'warning',
['title' => get_lang('BadgesManagement')]
);
/* View */
$skill = new Skill();
$skillList = $skill->get_all();
$tpl = new Template(get_lang('ManageSkills'));
$tpl->assign('message', $message);
$tpl->assign('skills', $skillList);
$content = $tpl->fetch('default/skill/list.tpl');
$tpl->assign('actions', $toolbar);
$tpl->assign('content', $content);
$tpl->display_one_col_template();
Session::erase('message');
break;
}

@ -612,7 +612,8 @@ class Skill extends Model
ss.parent_id,
ss.relation_type,
s.icon,
s.short_code
s.short_code,
s.status
FROM {$this->table} s
INNER JOIN {$this->table_skill_rel_skill} ss
ON (s.id = ss.skill_id) $id_condition

@ -27,15 +27,25 @@
<td class="text-center">{{ skill.short_code }}</td>
<td width="300">{{ skill.description }}</td>
<td class="text-right">
<a href="{{ _p.web_main }}admin/skill_edit.php?id={{ skill.id }}" class="btn btn-default btn-sm">
<a href="{{ _p.web_main }}admin/skill_edit.php?id={{ skill.id }}" class="btn btn-primary btn-sm">
<i class="fa fa-edit"></i> {{ "Edit" | get_lang }}
</a>
<a href="{{ _p.web_main }}admin/skill_create.php?parent={{ skill.id }}" class="btn btn-default btn-sm">
<a href="{{ _p.web_main }}admin/skill_create.php?parent={{ skill.id }}" class="btn btn-primary btn-sm">
<i class="fa fa-plus"></i> {{ "CreateChildSkill" | get_lang }}
</a>
<a href="{{ _p.web_main }}admin/skill_badge_create.php?id={{ skill.id }}" class="btn btn-default btn-sm">
<a href="{{ _p.web_main }}admin/skill_badge_create.php?id={{ skill.id }}" class="btn btn-primary btn-sm">
<i class="fa fa-shield"></i> {{ "CreateBadge" | get_lang }}
</a>
{% if skill.status == 0 %}
<a href="{{ _p.web_self ~ '?' ~ {"action": "enable", "id": skill.id}|url_encode() }}" class="btn btn-success btn-sm">
<i class="fa fa-shield"></i> {{ 'Enable' }}
</a>
{% else %}
<a href="{{ _p.web_self ~ '?' ~ {"action": "disable", "id": skill.id}|url_encode() }}" class="btn btn-danger btn-sm">
<i class="fa fa-shield"></i> {{ 'Disable' }}
</a>
{% endif %}
</td>
</tr>
{% endfor %}

Loading…
Cancel
Save