resource_sequence.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Entity\Sequence;
  4. $cidReset = true;
  5. require_once __DIR__.'/../inc/global.inc.php';
  6. api_protect_global_admin_script();
  7. // setting breadcrumbs
  8. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
  9. $tpl = new Template(get_lang('ResourcesSequencing'));
  10. $sessionListFromDatabase = SessionManager::get_sessions_list();
  11. $sessionList = [];
  12. if (!empty($sessionListFromDatabase)) {
  13. foreach ($sessionListFromDatabase as $sessionItem) {
  14. $sessionList[$sessionItem['id']] = $sessionItem['name'].' ('.$sessionItem['id'].')';
  15. }
  16. }
  17. $formSequence = new FormValidator('sequence_form', 'post', api_get_self(), null, null, 'inline');
  18. $formSequence->addText('name', get_lang('Sequence'), true, ['cols-size' => [3, 8, 1]]);
  19. $formSequence->addButtonCreate(get_lang('AddSequence'), 'submit_sequence', false, ['cols-size' => [3, 8, 1]]);
  20. $em = Database::getManager();
  21. // Add sequence
  22. if ($formSequence->validate()) {
  23. $values = $formSequence->exportValues();
  24. $sequence = new Sequence();
  25. $sequence->setName($values['name']);
  26. $em->persist($sequence);
  27. $em->flush();
  28. header('Location: '.api_get_self());
  29. exit;
  30. }
  31. $selectSequence = new FormValidator('frm_select_delete');
  32. $selectSequence->addHidden('sequence_type', 'session');
  33. $em = Database::getManager();
  34. $sequenceList = $em->getRepository('ChamiloCoreBundle:Sequence')->findAll();
  35. $slcSequences = $selectSequence->addSelect(
  36. 'sequence',
  37. get_lang('Sequence'),
  38. $sequenceList,
  39. ['id' => 'sequence_id', 'cols-size' => [3, 7, 2], 'disabled' => 'disabled']
  40. );
  41. if (!empty($sequenceList)) {
  42. $selectSequence->addButtonDelete(get_lang('Delete'));
  43. $slcSequences->removeAttribute('disabled');
  44. }
  45. if ($selectSequence->validate()) {
  46. $values = $selectSequence->exportValues();
  47. $sequence = $em->find('ChamiloCoreBundle:Sequence', $values['sequence']);
  48. $em
  49. ->createQuery('DELETE FROM ChamiloCoreBundle:SequenceResource sr WHERE sr.sequence = :seq')
  50. ->execute(['seq' => $sequence]);
  51. $em->remove($sequence);
  52. $em->flush();
  53. Display::addFlash(
  54. Display::return_message(get_lang('Deleted'), 'success')
  55. );
  56. header('Location: '.api_get_self());
  57. exit;
  58. }
  59. $form = new FormValidator('');
  60. $form->addHtml("<div class='col-md-6'>");
  61. $form->addHidden('sequence_type', 'session');
  62. $form->addSelect(
  63. 'sessions',
  64. get_lang('Sessions'),
  65. $sessionList,
  66. ['id' => 'item', 'cols-size' => [4, 7, 1], 'disabled' => 'disabled']
  67. );
  68. $form->addButtonNext(get_lang('UseAsReference'), 'use_as_reference', ['cols-size' => [4, 7, 1], 'disabled' => 'disabled']);
  69. $form->addHtml("</div>");
  70. $form->addHtml("<div class='col-md-6'>");
  71. $form->addSelect(
  72. 'requirements',
  73. get_lang('Requirements'),
  74. $sessionList,
  75. ['id' => 'requirements', 'cols-size' => [3, 7, 2], 'disabled' => 'disabled']
  76. );
  77. $form->addButtonCreate(get_lang('SetAsRequirement'), 'set_requirement', false, ['cols-size' => [3, 7, 2], 'disabled' => 'disabled']);
  78. $form->addHtml("</div>");
  79. $formSave = new FormValidator('');
  80. $formSave->addHidden('sequence_type', 'session');
  81. $formSave->addButton(
  82. 'save_resource',
  83. get_lang('SaveSettings'),
  84. 'floppy-o',
  85. 'success',
  86. null,
  87. null,
  88. ['cols-size' => [1, 10, 1], 'disabled' => 'disabled']
  89. );
  90. $tpl->assign('create_sequence', $formSequence->returnForm());
  91. $tpl->assign('select_sequence', $selectSequence->returnForm());
  92. $tpl->assign('configure_sequence', $form->returnForm());
  93. $tpl->assign('save_sequence', $formSave->returnForm());
  94. $layout = $tpl->get_template('admin/resource_sequence.tpl');
  95. $tpl->display($layout);