groupings.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. // This file is part of Moodle - http://moodle.org/
  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. * Allows a creator to edit groupings
  18. *
  19. * @copyright 1999 Martin Dougiamas http://dougiamas.com
  20. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  21. * @package core_group
  22. */
  23. require_once '../config.php';
  24. require_once $CFG->dirroot.'/group/lib.php';
  25. $courseid = required_param('id', PARAM_INT);
  26. $PAGE->set_url('/group/groupings.php', array('id'=>$courseid));
  27. if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
  28. print_error('nocourseid');
  29. }
  30. require_login($course);
  31. $context = context_course::instance($course->id);
  32. require_capability('moodle/course:managegroups', $context);
  33. $strgrouping = get_string('grouping', 'group');
  34. $strgroups = get_string('groups');
  35. $strname = get_string('name');
  36. $strdelete = get_string('delete');
  37. $stredit = get_string('edit');
  38. $srtnewgrouping = get_string('creategrouping', 'group');
  39. $strgroups = get_string('groups');
  40. $strgroupings = get_string('groupings', 'group');
  41. $struses = get_string('activities');
  42. $strparticipants = get_string('participants');
  43. $strmanagegrping = get_string('showgroupsingrouping', 'group');
  44. navigation_node::override_active_url(new moodle_url('/group/index.php', array('id'=>$courseid)));
  45. $PAGE->navbar->add($strgroupings);
  46. /// Print header
  47. $PAGE->set_title($strgroupings);
  48. $PAGE->set_heading($course->fullname);
  49. $PAGE->set_pagelayout('standard');
  50. echo $OUTPUT->header();
  51. // Add tabs
  52. $currenttab = 'groupings';
  53. require('tabs.php');
  54. echo $OUTPUT->heading($strgroupings);
  55. $data = array();
  56. if ($groupings = $DB->get_records('groupings', array('courseid'=>$course->id), 'name')) {
  57. $canchangeidnumber = has_capability('moodle/course:changeidnumber', $context);
  58. foreach ($groupings as $gid => $grouping) {
  59. $groupings[$gid]->formattedname = format_string($grouping->name, true, array('context' => $context));
  60. }
  61. core_collator::asort_objects_by_property($groupings, 'formattedname');
  62. foreach($groupings as $grouping) {
  63. $line = array();
  64. $line[0] = $grouping->formattedname;
  65. if ($groups = groups_get_all_groups($courseid, 0, $grouping->id)) {
  66. $groupnames = array();
  67. foreach ($groups as $group) {
  68. $groupnames[] = format_string($group->name);
  69. }
  70. $line[1] = implode(', ', $groupnames);
  71. } else {
  72. $line[1] = get_string('none');
  73. }
  74. $line[2] = $DB->count_records('course_modules', array('course'=>$course->id, 'groupingid'=>$grouping->id));
  75. $url = new moodle_url('/group/grouping.php', array('id' => $grouping->id));
  76. $buttons = html_writer::link($url, $OUTPUT->pix_icon('t/edit', $stredit, 'core',
  77. array('class' => 'iconsmall')), array('title' => $stredit));
  78. if (empty($grouping->idnumber) || $canchangeidnumber) {
  79. // It's only possible to delete groups without an idnumber unless the user has the changeidnumber capability.
  80. $url = new moodle_url('/group/grouping.php', array('id' => $grouping->id, 'delete' => 1));
  81. $buttons .= html_writer::link($url, $OUTPUT->pix_icon('t/delete', $strdelete, 'core',
  82. array('class' => 'iconsmall')), array('title' => $strdelete));
  83. } else {
  84. $buttons .= $OUTPUT->spacer();
  85. }
  86. $url = new moodle_url('/group/assign.php', array('id' => $grouping->id));
  87. $buttons .= html_writer::link($url, $OUTPUT->pix_icon('t/groups', $strmanagegrping, 'core',
  88. array('class' => 'iconsmall')), array('title' => $strmanagegrping));
  89. $line[3] = $buttons;
  90. $data[] = $line;
  91. }
  92. }
  93. $table = new html_table();
  94. $table->head = array($strgrouping, $strgroups, $struses, $stredit);
  95. $table->size = array('30%', '50%', '10%', '10%');
  96. $table->align = array('left', 'left', 'center', 'center');
  97. $table->width = '90%';
  98. $table->data = $data;
  99. echo html_writer::table($table);
  100. echo $OUTPUT->container_start('buttons');
  101. echo $OUTPUT->single_button(new moodle_url('grouping.php', array('courseid'=>$courseid)), $srtnewgrouping);
  102. echo $OUTPUT->container_end();
  103. echo $OUTPUT->footer();