Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 401 and 403]

   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  /**
  18   * Group index page.
  19   *
  20   * @package    core_group
  21   * @copyright  2017 Jun Pataleta
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  namespace core_group\output;
  25  defined('MOODLE_INTERNAL') || die();
  26  
  27  use renderable;
  28  use renderer_base;
  29  use stdClass;
  30  use templatable;
  31  
  32  /**
  33   * Group index page class.
  34   *
  35   * @package    core_group
  36   * @copyright  2017 Jun Pataleta
  37   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  38   */
  39  class index_page implements renderable, templatable {
  40  
  41      /** @var int $courseid The course ID. */
  42      public $courseid;
  43  
  44      /** @var array The array of groups to be rendered. */
  45      public $groups;
  46  
  47      /** @var string The name of the currently selected group. */
  48      public $selectedgroupname;
  49  
  50      /** @var array The array of group members to be rendered, if a group is selected. */
  51      public $selectedgroupmembers;
  52  
  53      /** @var bool Whether to disable the add members/edit group buttons. */
  54      public $disableaddedit;
  55  
  56      /** @var bool Whether to disable the delete group button. */
  57      public $disabledelete;
  58  
  59      /** @var array Groups that can't be deleted by the user. */
  60      public $undeletablegroups;
  61  
  62      /**
  63       * index_page constructor.
  64       *
  65       * @param int $courseid The course ID.
  66       * @param array $groups The array of groups to be rendered.
  67       * @param string $selectedgroupname The name of the currently selected group.
  68       * @param array $selectedgroupmembers The array of group members to be rendered, if a group is selected.
  69       * @param bool $disableaddedit Whether to disable the add members/edit group buttons.
  70       * @param bool $disabledelete Whether to disable the delete group button.
  71       * @param array $undeletablegroups Groups that can't be deleted by the user.
  72       */
  73      public function __construct($courseid, $groups, $selectedgroupname, $selectedgroupmembers, $disableaddedit, $disabledelete,
  74                                  $undeletablegroups) {
  75          $this->courseid = $courseid;
  76          $this->groups = $groups;
  77          $this->selectedgroupname = $selectedgroupname;
  78          $this->selectedgroupmembers = $selectedgroupmembers;
  79          $this->disableaddedit = $disableaddedit;
  80          $this->disabledelete = $disabledelete;
  81          $this->undeletablegroups = $undeletablegroups;
  82      }
  83  
  84      /**
  85       * Export the data.
  86       *
  87       * @param renderer_base $output
  88       * @return stdClass
  89       */
  90      public function export_for_template(renderer_base $output) {
  91          global $CFG;
  92  
  93          $data = new stdClass();
  94  
  95          // Variables that will be passed to the JS helper.
  96          $data->courseid = $this->courseid;
  97          $data->wwwroot = $CFG->wwwroot;
  98          // To be passed to the JS init script in the template. Encode as a JSON string.
  99          $data->undeletablegroups = json_encode($this->undeletablegroups);
 100  
 101          // Some buttons are enabled if single group selected.
 102          $data->addmembersdisabled = $this->disableaddedit;
 103          $data->editgroupsettingsdisabled = $this->disableaddedit;
 104          $data->deletegroupdisabled = $this->disabledelete;
 105          $data->groups = $this->groups;
 106          $data->members = $this->selectedgroupmembers;
 107          $data->selectedgroup = $this->selectedgroupname;
 108  
 109          return $data;
 110      }
 111  }