Add create skill form - refs BT#9583 #7385

1.10.x
Angel Fernando Quiroz Campos 11 years ago
parent ed88e33274
commit 4991e1ea67
  1. 79
      main/admin/skill_create.php
  2. 9
      main/admin/skill_list.php
  3. 20
      main/inc/lib/display.lib.php

@ -0,0 +1,79 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Create skill form
* @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
* @package chamilo.admin
*/
use ChamiloSession as Session;
$cidReset = true;
require_once '../inc/global.inc.php';
$this_section = SECTION_PLATFORM_ADMIN;
api_protect_admin_script();
if (api_get_setting('allow_skills_tool') != 'true') {
api_not_allowed();
}
$interbreadcrumb[] = array("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
/* Process data */
$objSkill = new Skill();
$objGradebook = new Gradebook();
$allSkills = $objSkill->get_all();
$allGradebooks = $objGradebook->find('all');
$skillList = [0 => get_lang('None')];
$gradebookList = [];
foreach ($allSkills as $skill) {
$skillList[$skill['id']] = $skill['name'];
}
foreach ($allGradebooks as $gradebook) {
$gradebookList[$gradebook['id']] = $gradebook['name'];
}
/* Form */
$createForm = new FormValidator('skill_create');
$createForm->addHeader(get_lang('CreateSkill'));
$createForm->addText('name', get_lang('Name'), true, ['id' => 'name']);
$createForm->addText('short_code', get_lang('ShortCode'), false, ['id' => 'short_code']);
$createForm->addSelect('parent_id', get_lang('Parent'), $skillList, ['id' => 'parent_id']);
$createForm->addSelect(
'gradebook_id',
[get_lang('Gradebook'), get_lang('WithCertificate')],
$gradebookList,
['id' => 'gradebook_id', 'multiple' => 'multiple', 'size' => 10]
);
$createForm->addTextarea('description', get_lang('Description'), ['id' => 'description', 'rows' => 7]);
$createForm->addButtonSave(get_lang('Save'));
$createForm->addHidden('id', null);
if ($createForm->validate()) {
$created = $objSkill->add($createForm->getSubmitValues());
if ($created) {
Session::write(
'message',
Display::return_message(get_lang('TheSkillHasBeenCreated'), 'success')
);
} else {
Session::write(
'message',
Display::return_message(get_lang('CannotCreateSkill'), 'error')
);
}
Header::location(api_get_path(WEB_CODE_PATH) . 'admin/skill_list.php');
}
/* view */
$tpl = new Template(get_lang('CreateSkill'));
$tpl->assign('content', $createForm->returnForm());
$tpl->display_one_col_template();

@ -23,6 +23,14 @@ $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAd
$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')]
);
/* View */
$skill = new Skill();
$skillList = $skill->get_all();
@ -33,6 +41,7 @@ $tpl->assign('skills', $skillList);
$content = $tpl->fetch('default/skill/list.tpl');
$tpl->assign('actions', $toolbar);
$tpl->assign('content', $content);
$tpl->display_one_col_template();

@ -2106,4 +2106,24 @@ class Display
</div>';
}
/**
* Get the button HTML with an Awesome Font icon
* @param string $text The button content
* @param string $url The url to button
* @param string $icon The Awesome Font class for icon
* @param string $type Ooptional. The button Bootstrap class. Default 'default' class
* @param array $attributes The additional attributes
* @return string The button HTML
*/
public static function toolbarButton($text, $url, $icon = 'check', $type = 'default', array $attributes = [])
{
$buttonClass = "btn btn-$type";
$icon = self::tag('i', null, ['class' => "fa fa-$icon"]);
$attributes['class'] = isset($attributes['class']) ? "$buttonClass {$attributes['class']}" : $buttonClass;
return self::url("$icon $text", $url, $attributes);
}
}

Loading…
Cancel
Save