Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
    /** @var bool Whether to show/hide the messaging setting buttons. */
63
    public $messagingsettingsvisible;
64
 
65
    /**
66
     * index_page constructor.
67
     *
68
     * @param int $courseid The course ID.
69
     * @param array $groups The array of groups to be rendered.
70
     * @param string $selectedgroupname The name of the currently selected group.
71
     * @param array $selectedgroupmembers The array of group members to be rendered, if a group is selected.
72
     * @param bool $disableaddedit Whether to disable the add members/edit group buttons.
73
     * @param bool $disabledelete Whether to disable the delete group button.
74
     * @param array $undeletablegroups Groups that can't be deleted by the user.
75
     * @param bool $messagingsettingsvisible If the messaging settings buttons should be visible.
76
     */
77
    public function __construct($courseid, $groups, $selectedgroupname, $selectedgroupmembers, $disableaddedit, $disabledelete,
78
                                $undeletablegroups, $messagingsettingsvisible) {
79
        $this->courseid = $courseid;
80
        $this->groups = $groups;
81
        $this->selectedgroupname = $selectedgroupname;
82
        $this->selectedgroupmembers = $selectedgroupmembers;
83
        $this->disableaddedit = $disableaddedit;
84
        $this->disabledelete = $disabledelete;
85
        $this->undeletablegroups = $undeletablegroups;
86
        $this->messagingsettingsvisible = $messagingsettingsvisible;
87
    }
88
 
89
    /**
90
     * Export the data.
91
     *
92
     * @param renderer_base $output
93
     * @return stdClass
94
     */
95
    public function export_for_template(renderer_base $output) {
96
        global $CFG;
97
 
98
        $data = new stdClass();
99
 
100
        // Variables that will be passed to the JS helper.
101
        $data->courseid = $this->courseid;
102
        $data->wwwroot = $CFG->wwwroot;
103
        // To be passed to the JS init script in the template. Encode as a JSON string.
104
        $data->undeletablegroups = json_encode($this->undeletablegroups);
105
 
106
        // Some buttons are enabled if single group selected.
107
        $data->addmembersdisabled = $this->disableaddedit;
108
        $data->editgroupsettingsdisabled = $this->disableaddedit;
109
        $data->deletegroupdisabled = $this->disabledelete;
110
        $data->groups = $this->groups;
111
        $data->members = $this->selectedgroupmembers;
112
        $data->selectedgroup = $this->selectedgroupname;
113
        $data->messagingsettingsvisible = $this->messagingsettingsvisible;
114
 
115
        return $data;
116
    }
117
}