| 1 | 
           efrain | 
           1 | 
           <?php
  | 
        
        
            | 
            | 
           2 | 
              | 
        
        
            | 
            | 
           3 | 
           // This file is part of Moodle - http://moodle.org/
  | 
        
        
            | 
            | 
           4 | 
           //
  | 
        
        
            | 
            | 
           5 | 
           // Moodle is free software: you can redistribute it and/or modify
  | 
        
        
            | 
            | 
           6 | 
           // it under the terms of the GNU General Public License as published by
  | 
        
        
            | 
            | 
           7 | 
           // the Free Software Foundation, either version 3 of the License, or
  | 
        
        
            | 
            | 
           8 | 
           // (at your option) any later version.
  | 
        
        
            | 
            | 
           9 | 
           //
  | 
        
        
            | 
            | 
           10 | 
           // Moodle is distributed in the hope that it will be useful,
  | 
        
        
            | 
            | 
           11 | 
           // but WITHOUT ANY WARRANTY; without even the implied warranty of
  | 
        
        
            | 
            | 
           12 | 
           // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  | 
        
        
            | 
            | 
           13 | 
           // GNU General Public License for more details.
  | 
        
        
            | 
            | 
           14 | 
           //
  | 
        
        
            | 
            | 
           15 | 
           // You should have received a copy of the GNU General Public License
  | 
        
        
            | 
            | 
           16 | 
           // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  | 
        
        
            | 
            | 
           17 | 
              | 
        
        
            | 
            | 
           18 | 
           /**
  | 
        
        
            | 
            | 
           19 | 
            * Allows a creator to edit groupings
  | 
        
        
            | 
            | 
           20 | 
            *
  | 
        
        
            | 
            | 
           21 | 
            * @copyright 1999 Martin Dougiamas  http://dougiamas.com
  | 
        
        
            | 
            | 
           22 | 
            * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  | 
        
        
            | 
            | 
           23 | 
            * @package core_group
  | 
        
        
            | 
            | 
           24 | 
            */
  | 
        
        
            | 
            | 
           25 | 
              | 
        
        
            | 
            | 
           26 | 
           require_once '../config.php';
  | 
        
        
            | 
            | 
           27 | 
           require_once $CFG->dirroot.'/group/lib.php';
  | 
        
        
            | 
            | 
           28 | 
              | 
        
        
            | 
            | 
           29 | 
           $courseid = required_param('id', PARAM_INT);
  | 
        
        
            | 
            | 
           30 | 
              | 
        
        
            | 
            | 
           31 | 
           $PAGE->set_url('/group/groupings.php', array('id'=>$courseid));
  | 
        
        
            | 
            | 
           32 | 
              | 
        
        
            | 
            | 
           33 | 
           if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
  | 
        
        
            | 
            | 
           34 | 
               throw new \moodle_exception('invalidcourseid');
  | 
        
        
            | 
            | 
           35 | 
           }
  | 
        
        
            | 
            | 
           36 | 
              | 
        
        
            | 
            | 
           37 | 
           require_login($course);
  | 
        
        
            | 
            | 
           38 | 
           $context = context_course::instance($course->id);
  | 
        
        
            | 
            | 
           39 | 
           require_capability('moodle/course:managegroups', $context);
  | 
        
        
            | 
            | 
           40 | 
              | 
        
        
            | 
            | 
           41 | 
           $strgrouping     = get_string('grouping', 'group');
  | 
        
        
            | 
            | 
           42 | 
           $strgroups       = get_string('groups');
  | 
        
        
            | 
            | 
           43 | 
           $strname         = get_string('name');
  | 
        
        
            | 
            | 
           44 | 
           $strdelete       = get_string('delete');
  | 
        
        
            | 
            | 
           45 | 
           $stredit         = get_string('edit');
  | 
        
        
            | 
            | 
           46 | 
           $srtnewgrouping  = get_string('creategrouping', 'group');
  | 
        
        
            | 
            | 
           47 | 
           $strgroups       = get_string('groups');
  | 
        
        
            | 
            | 
           48 | 
           $strgroupings    = get_string('groupings', 'group');
  | 
        
        
            | 
            | 
           49 | 
           $struses         = get_string('activities');
  | 
        
        
            | 
            | 
           50 | 
           $strparticipants = get_string('participants');
  | 
        
        
            | 
            | 
           51 | 
           $strmanagegrping = get_string('showgroupsingrouping', 'group');
  | 
        
        
            | 
            | 
           52 | 
              | 
        
        
            | 
            | 
           53 | 
           navigation_node::override_active_url(new moodle_url('/group/index.php', array('id'=>$courseid)));
  | 
        
        
            | 
            | 
           54 | 
           $PAGE->navbar->add($strgroupings);
  | 
        
        
            | 
            | 
           55 | 
              | 
        
        
            | 
            | 
           56 | 
           /// Print header
  | 
        
        
            | 
            | 
           57 | 
           $PAGE->set_title($strgroupings);
  | 
        
        
            | 
            | 
           58 | 
           $PAGE->set_heading($course->fullname);
  | 
        
        
            | 
            | 
           59 | 
           $PAGE->set_pagelayout('standard');
  | 
        
        
            | 
            | 
           60 | 
              | 
        
        
            | 
            | 
           61 | 
           echo $OUTPUT->header();
  | 
        
        
            | 
            | 
           62 | 
           echo $OUTPUT->render_participants_tertiary_nav($course);
  | 
        
        
            | 
            | 
           63 | 
              | 
        
        
            | 
            | 
           64 | 
           $data = array();
  | 
        
        
            | 
            | 
           65 | 
           if ($groupings = $DB->get_records('groupings', array('courseid'=>$course->id), 'name')) {
  | 
        
        
            | 
            | 
           66 | 
               $canchangeidnumber = has_capability('moodle/course:changeidnumber', $context);
  | 
        
        
            | 
            | 
           67 | 
               foreach ($groupings as $gid => $grouping) {
  | 
        
        
            | 
            | 
           68 | 
                   $groupings[$gid]->formattedname = format_string($grouping->name, true, array('context' => $context));
  | 
        
        
            | 
            | 
           69 | 
               }
  | 
        
        
            | 
            | 
           70 | 
               core_collator::asort_objects_by_property($groupings, 'formattedname');
  | 
        
        
            | 
            | 
           71 | 
               foreach($groupings as $grouping) {
  | 
        
        
            | 
            | 
           72 | 
                   $line = array();
  | 
        
        
            | 
            | 
           73 | 
                   $line[0] = $grouping->formattedname;
  | 
        
        
            | 
            | 
           74 | 
              | 
        
        
            | 
            | 
           75 | 
                   if ($groups = groups_get_all_groups($courseid, 0, $grouping->id)) {
  | 
        
        
            | 
            | 
           76 | 
                       $groupnames = array();
  | 
        
        
            | 
            | 
           77 | 
                       foreach ($groups as $group) {
  | 
        
        
            | 
            | 
           78 | 
                           $groupnames[] = format_string($group->name);
  | 
        
        
            | 
            | 
           79 | 
                       }
  | 
        
        
            | 
            | 
           80 | 
                       $line[1] = implode(', ', $groupnames);
  | 
        
        
            | 
            | 
           81 | 
                   } else {
  | 
        
        
            | 
            | 
           82 | 
                       $line[1] = get_string('none');
  | 
        
        
            | 
            | 
           83 | 
                   }
  | 
        
        
            | 
            | 
           84 | 
                   $line[2] = $DB->count_records('course_modules', array('course'=>$course->id, 'groupingid'=>$grouping->id));
  | 
        
        
            | 
            | 
           85 | 
              | 
        
        
            | 
            | 
           86 | 
                   $url = new moodle_url('/group/grouping.php', array('id' => $grouping->id));
  | 
        
        
            | 
            | 
           87 | 
                   $buttons  = html_writer::link($url, $OUTPUT->pix_icon('t/edit', $stredit, 'core',
  | 
        
        
            | 
            | 
           88 | 
                           array('class' => 'iconsmall')), array('title' => $stredit));
  | 
        
        
            | 
            | 
           89 | 
                   if (empty($grouping->idnumber) || $canchangeidnumber) {
  | 
        
        
            | 
            | 
           90 | 
                       // It's only possible to delete groups without an idnumber unless the user has the changeidnumber capability.
  | 
        
        
            | 
            | 
           91 | 
                       $url = new moodle_url('/group/grouping.php', array('id' => $grouping->id, 'delete' => 1));
  | 
        
        
            | 
            | 
           92 | 
                       $buttons .= html_writer::link($url, $OUTPUT->pix_icon('t/delete', $strdelete, 'core',
  | 
        
        
            | 
            | 
           93 | 
                               array('class' => 'iconsmall')), array('title' => $strdelete));
  | 
        
        
            | 
            | 
           94 | 
                   } else {
  | 
        
        
            | 
            | 
           95 | 
                       $buttons .= $OUTPUT->spacer();
  | 
        
        
            | 
            | 
           96 | 
                   }
  | 
        
        
            | 
            | 
           97 | 
                   $url = new moodle_url('/group/assign.php', array('id' => $grouping->id));
  | 
        
        
            | 
            | 
           98 | 
                   $buttons .= html_writer::link($url, $OUTPUT->pix_icon('t/groups', $strmanagegrping, 'core',
  | 
        
        
            | 
            | 
           99 | 
                           array('class' => 'iconsmall')), array('title' => $strmanagegrping));
  | 
        
        
            | 
            | 
           100 | 
              | 
        
        
            | 
            | 
           101 | 
                   $line[3] = $buttons;
  | 
        
        
            | 
            | 
           102 | 
                   $data[] = $line;
  | 
        
        
            | 
            | 
           103 | 
               }
  | 
        
        
            | 
            | 
           104 | 
           }
  | 
        
        
            | 
            | 
           105 | 
           $table = new html_table();
  | 
        
        
            | 
            | 
           106 | 
           $table->head  = array($strgrouping, $strgroups, $struses, $stredit);
  | 
        
        
            | 
            | 
           107 | 
           $table->size  = array('30%', '50%', '10%', '10%');
  | 
        
        
            | 
            | 
           108 | 
           $table->align = array('left', 'left', 'center', 'center');
  | 
        
        
            | 
            | 
           109 | 
           $table->width = '90%';
  | 
        
        
            | 
            | 
           110 | 
           $table->data  = $data;
  | 
        
        
            | 
            | 
           111 | 
           echo html_writer::table($table);
  | 
        
        
            | 
            | 
           112 | 
              | 
        
        
            | 
            | 
           113 | 
           echo $OUTPUT->container_start('buttons');
  | 
        
        
            | 
            | 
           114 | 
           echo $OUTPUT->single_button(new moodle_url('grouping.php', array('courseid'=>$courseid)), $srtnewgrouping);
  | 
        
        
            | 
            | 
           115 | 
           echo $OUTPUT->container_end();
  | 
        
        
            | 
            | 
           116 | 
              | 
        
        
            | 
            | 
           117 | 
           echo $OUTPUT->footer();
  |