skill_create.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. use Chamilo\CoreBundle\Framework\Container;
  5. /**
  6. * Create skill form
  7. * @author Angel Fernando Quiroz Campos <angel.quiroz@beeznest.com>
  8. * @package chamilo.admin
  9. */
  10. $cidReset = true;
  11. //require_once '../inc/global.inc.php';
  12. $this_section = SECTION_PLATFORM_ADMIN;
  13. api_protect_admin_script();
  14. if (api_get_setting('skill.allow_skills_tool') != 'true') {
  15. api_not_allowed();
  16. }
  17. $interbreadcrumb[] = array('url' => Container::getRouter()->generate('administration') , "name" => get_lang('PlatformAdmin'));
  18. $interbreadcrumb[] = array('url' => 'skill_list.php', 'name' => get_lang('ManageSkills'));
  19. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('CreateSkill'));
  20. /* Process data */
  21. $skillParentId = isset($_GET['parent']) ? intval($_GET['parent']) : 0;
  22. $formDefaultValues = [];
  23. $objSkill = new Skill();
  24. $objGradebook = new Gradebook();
  25. if ($skillParentId > 0) {
  26. $skillParentInfo = $objSkill->get_skill_info($skillParentId);
  27. $formDefaultValues = [
  28. 'parent_id' => $skillParentInfo['id'],
  29. 'gradebook_id' => []
  30. ];
  31. foreach ($skillParentInfo['gradebooks'] as $gradebook) {
  32. $formDefaultValues['gradebook_id'][] = intval($gradebook['id']);
  33. }
  34. }
  35. $allSkills = $objSkill->get_all();
  36. $allGradebooks = $objGradebook->find('all');
  37. $isAlreadyRootSkill = false;
  38. foreach ($allSkills as $checkedSkill) {
  39. if (intval($checkedSkill['parent_id']) > 0) {
  40. $isAlreadyRootSkill = true;
  41. break;
  42. }
  43. }
  44. $skillList = $isAlreadyRootSkill ? [] : [0 => get_lang('None')];
  45. $gradebookList = [];
  46. foreach ($allSkills as $skill) {
  47. $skillList[$skill['id']] = $skill['name'];
  48. }
  49. foreach ($allGradebooks as $gradebook) {
  50. $gradebookList[$gradebook['id']] = $gradebook['name'];
  51. }
  52. /* Form */
  53. $createForm = new FormValidator('skill_create');
  54. $createForm->addHeader(get_lang('CreateSkill'));
  55. $createForm->addText('name', get_lang('Name'), true, ['id' => 'name']);
  56. $createForm->addText('short_code', get_lang('ShortCode'), false, ['id' => 'short_code']);
  57. $createForm->addSelect('parent_id', get_lang('Parent'), $skillList, ['id' => 'parent_id']);
  58. $createForm->addSelect(
  59. 'gradebook_id',
  60. [get_lang('Gradebook'), get_lang('WithCertificate')],
  61. $gradebookList,
  62. ['id' => 'gradebook_id', 'multiple' => 'multiple', 'size' => 10]
  63. );
  64. $createForm->addTextarea('description', get_lang('Description'), ['id' => 'description', 'rows' => 7]);
  65. $extraField = new ExtraField('skill');
  66. $returnParams = $extraField->addElements($createForm);
  67. $jquery_ready_content = $returnParams['jquery_ready_content'];
  68. // the $jquery_ready_content variable collects all functions that will be load in the $(document).ready javascript function
  69. if (!empty($jquery_ready_content)) {
  70. $htmlHeadXtra[] = '<script>
  71. $(document).ready(function(){
  72. ' . $jquery_ready_content . '
  73. });
  74. </script>';
  75. }
  76. $createForm->addButtonSave(get_lang('Save'));
  77. $createForm->addHidden('id', null);
  78. $createForm->setDefaults($formDefaultValues);
  79. if ($createForm->validate()) {
  80. $skillValues = $createForm->getSubmitValues();
  81. $created = $objSkill->add($skillValues);
  82. $skillValues['item_id'] = $created;
  83. $extraFieldValue = new ExtraFieldValue('skill');
  84. $extraFieldValue->saveFieldValues($skillValues);
  85. if ($created) {
  86. Display::return_message(get_lang('TheSkillHasBeenCreated'), 'success');
  87. } else {
  88. Display::return_message(get_lang('CannotCreateSkill'), 'error');
  89. }
  90. header('Location: '.api_get_path(WEB_CODE_PATH) . 'admin/skill_list.php');
  91. exit;
  92. }
  93. //$tpl = new Template(get_lang('CreateSkill'));
  94. echo $createForm->returnForm();