enrol_renderer.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. <?php
  2. // This file is part of The Bootstrap 3 Moodle theme
  3. //
  4. // Moodle is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // Moodle is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Renderers to align Moodle's HTML with that expected by Bootstrap
  18. *
  19. * @package theme_bootstrap
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21. */
  22. defined('MOODLE_INTERNAL') || die();
  23. require_once($CFG->dirroot . "/enrol/renderer.php");
  24. class theme_bootstrap_core_enrol_renderer extends core_enrol_renderer {
  25. public function render_course_enrolment_users_table(course_enrolment_users_table $table,
  26. moodleform $mform) {
  27. $table->initialise_javascript();
  28. // Added for the Bootstrap theme. Make this table responsive
  29. $table->attributes['class'] .= ' table table-responsive';
  30. $buttons = $table->get_manual_enrol_buttons();
  31. $buttonhtml = '';
  32. if (count($buttons) > 0) {
  33. $buttonhtml .= html_writer::start_tag('div', array('class' => 'enrol_user_buttons'));
  34. foreach ($buttons as $button) {
  35. $buttonhtml .= $this->render($button);
  36. }
  37. $buttonhtml .= html_writer::end_tag('div');
  38. }
  39. $content = '';
  40. if (!empty($buttonhtml)) {
  41. $content .= $buttonhtml;
  42. }
  43. $content .= $mform->render();
  44. $content .= $this->output->render($table->get_paging_bar());
  45. // Check if the table has any bulk operations. If it does we want to wrap the table in a
  46. // form so that we can capture and perform any required bulk operations.
  47. if ($table->has_bulk_user_enrolment_operations()) {
  48. $content .= html_writer::start_tag('form', array('action' => new moodle_url('/enrol/bulkchange.php'), 'method' => 'post'));
  49. foreach ($table->get_combined_url_params() as $key => $value) {
  50. if ($key == 'action') {
  51. continue;
  52. }
  53. $content .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $key, 'value' => $value));
  54. }
  55. $content .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'action', 'value' => 'bulkchange'));
  56. $content .= html_writer::table($table);
  57. $content .= html_writer::start_tag('div', array('class' => 'singleselect bulkuserop'));
  58. $content .= html_writer::start_tag('select', array('name' => 'bulkuserop'));
  59. $content .= html_writer::tag('option', get_string('withselectedusers', 'enrol'), array('value' => ''));
  60. $options = array('' => get_string('withselectedusers', 'enrol'));
  61. foreach ($table->get_bulk_user_enrolment_operations() as $operation) {
  62. $content .= html_writer::tag('option', $operation->get_title(), array('value' => $operation->get_identifier()));
  63. }
  64. $content .= html_writer::end_tag('select');
  65. $content .= html_writer::empty_tag('input', array('type' => 'submit', 'value' => get_string('go')));
  66. $content .= html_writer::end_tag('div');
  67. $content .= html_writer::end_tag('form');
  68. } else {
  69. // Added for the Bootstrap theme, a no-overflow wrapper
  70. $content .= html_writer::start_tag('div', array('class' => 'no-overflow'));
  71. $content .= html_writer::table($table);
  72. $content .= html_writer::end_tag('div');
  73. }
  74. $content .= $this->output->render($table->get_paging_bar());
  75. if (!empty($buttonhtml)) {
  76. $content .= $buttonhtml;
  77. }
  78. return $content;
  79. }
  80. public function user_roles_and_actions($userid, $roles, $assignableroles, $canassign, $pageurl) {
  81. $iconenroladd = $this->output->pix_url('t/enroladd');
  82. $iconenrolremove = $this->output->pix_url('t/delete');
  83. // get list of roles
  84. $rolesoutput = '';
  85. foreach ($roles as $roleid=>$role) {
  86. if ($canassign and (is_siteadmin() or isset($assignableroles[$roleid])) and !$role['unchangeable']) {
  87. $strunassign = get_string('unassignarole', 'role', $role['text']);
  88. $icon = html_writer::empty_tag('img', array('alt'=>$strunassign, 'src'=>$iconenrolremove));
  89. $url = new moodle_url($pageurl, array('action'=>'unassign', 'roleid'=>$roleid, 'user'=>$userid));
  90. $rolesoutput .= html_writer::tag('div', $role['text'] . html_writer::link($url, $icon, array('class'=>'unassignrolelink', 'rel'=>$roleid, 'title'=>$strunassign)), array('class'=>'role role_'.$roleid));
  91. } else {
  92. $rolesoutput .= html_writer::tag('div', $role['text'], array('class'=>'role unchangeable', 'rel'=>$roleid));
  93. }
  94. }
  95. $output = '';
  96. if (!empty($assignableroles) && $canassign) {
  97. $roleids = array_keys($roles);
  98. $hasallroles = true;
  99. foreach (array_keys($assignableroles) as $key) {
  100. if (!in_array($key, $roleids)) {
  101. $hasallroles = false;
  102. break;
  103. }
  104. }
  105. if (!$hasallroles) {
  106. $url = new moodle_url($pageurl, array('action'=>'assign', 'user'=>$userid));
  107. $icon = html_writer::tag('label', get_string('assignroles', 'role'), array('alt'=>get_string('assignroles', 'role'), 'class' => 'label label-primary'));
  108. $output = html_writer::tag('div', html_writer::link($url, $icon, array('class'=>'assignrolelink', 'title'=>get_string('assignroles', 'role'))), array('class'=>'addrole'));
  109. }
  110. }
  111. $output .= html_writer::tag('div', $rolesoutput, array('class'=>'roles'));
  112. return $output;
  113. }
  114. public function user_groups_and_actions($userid, $groups, $allgroups, $canmanagegroups, $pageurl) {
  115. $iconenroladd = $this->output->pix_url('t/enroladd');
  116. $iconenrolremove = $this->output->pix_url('t/delete');
  117. $straddgroup = get_string('addgroup', 'group');
  118. $groupoutput = '';
  119. foreach($groups as $groupid=>$name) {
  120. if ($canmanagegroups and groups_remove_member_allowed($groupid, $userid)) {
  121. $icon = html_writer::tag('label', get_string('add'), array('alt'=>$straddgroup, 'class' => 'label label-primary'));
  122. $url = new moodle_url($pageurl, array('action'=>'addmember', 'user'=>$userid));
  123. $groupoutput .= html_writer::tag('div', html_writer::link($url, $icon), array('class'=>'addgroup'));
  124. $icon = html_writer::empty_tag('img', array('alt'=>get_string('removefromgroup', 'group', $name), 'src'=>$iconenrolremove));
  125. $url = new moodle_url($pageurl, array('action'=>'removemember', 'group'=>$groupid, 'user'=>$userid));
  126. $groupoutput .= html_writer::tag('div', $name . html_writer::link($url, $icon), array('class'=>'group', 'rel'=>$groupid));
  127. } else {
  128. $groupoutput .= html_writer::tag('div', $name, array('class'=>'group', 'rel'=>$groupid));
  129. }
  130. }
  131. $groupoutput = html_writer::tag('div', $groupoutput, array('class'=>'groups'));
  132. if ($canmanagegroups && (count($groups) < count($allgroups))) {
  133. $icon = html_writer::tag('label', get_string('add'), array('alt'=>$straddgroup, 'class' => 'label label-primary'));
  134. $url = new moodle_url($pageurl, array('action'=>'addmember', 'user'=>$userid));
  135. $groupoutput .= html_writer::tag('div', html_writer::link($url, $icon), array('class'=>'addgroup'));
  136. }
  137. return $groupoutput;
  138. }
  139. }