skill_rel_course.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\SkillBundle\Entity\SkillRelCourse;
  4. $cidReset = true;
  5. require_once __DIR__.'/../inc/global.inc.php';
  6. if (api_get_configuration_value('allow_skill_rel_items') == false) {
  7. api_not_allowed(true);
  8. }
  9. $courseId = isset($_GET['course_id']) ? (int) $_GET['course_id'] : 0;
  10. $course = api_get_course_entity($courseId);
  11. if (empty($course)) {
  12. api_not_allowed(true);
  13. }
  14. $sessionId = isset($_GET['session_id']) ? (int) $_GET['session_id'] : null;
  15. $url = api_get_self().'?course_id='.$courseId.'&session_id='.$sessionId;
  16. $form = new FormValidator('skills', 'post', $url);
  17. $sessionName = $course->getTitleAndCode();
  18. if (!empty($sessionId)) {
  19. $session = api_get_session_entity($sessionId);
  20. $courseExistsInSession = SessionManager::sessionHasCourse($sessionId, $course->getCode());
  21. if (!$courseExistsInSession) {
  22. api_not_allowed(true);
  23. }
  24. $sessionName = ' '.$session->getName().' - '.$course->getTitleAndCode();
  25. }
  26. $form->addHeader(get_lang('AddSkills').$sessionName);
  27. $skillList = [];
  28. $em = Database::getManager();
  29. $items = $em->getRepository('ChamiloSkillBundle:SkillRelCourse')->findBy(
  30. ['course' => $courseId, 'session' => $sessionId]
  31. );
  32. /** @var SkillRelCourse $skillRelCourse */
  33. foreach ($items as $skillRelCourse) {
  34. $skillList[$skillRelCourse->getSkill()->getId()] = $skillRelCourse->getSkill()->getName();
  35. }
  36. $form->addHidden('course_id', $courseId);
  37. $form->addHidden('session_id', $sessionId);
  38. $form->addSelectAjax(
  39. 'skills',
  40. get_lang('Skills'),
  41. $skillList,
  42. [
  43. 'url' => api_get_path(WEB_AJAX_PATH).'skill.ajax.php?a=search_skills',
  44. 'multiple' => 'multiple',
  45. ]
  46. );
  47. $form->addButtonSave(get_lang('Save'));
  48. $form->setDefaults(['skills' => array_keys($skillList)]);
  49. if ($form->validate()) {
  50. $result = Skill::saveSkillsToCourseFromForm($form);
  51. if ($result) {
  52. Display::addFlash(Display::return_message(get_lang('Updated')));
  53. }
  54. header('Location: '.$url);
  55. exit;
  56. }
  57. $content = $form->returnForm();
  58. $interbreadcrumb[] = [
  59. 'url' => api_get_path(WEB_CODE_PATH).'session/session_list.php',
  60. 'name' => get_lang('SessionList'),
  61. ];
  62. $interbreadcrumb[] = [
  63. 'url' => api_get_path(WEB_CODE_PATH).'session/resume_session.php?id_session='.$sessionId,
  64. 'name' => get_lang('SessionOverview'),
  65. ];
  66. $template = new Template(get_lang('SkillRelCourses'));
  67. $template->assign('content', $content);
  68. $template->display_one_col_template();