30c67b7cb770f52eb616b2c6d8a2641435a98dc1
[moodle.git] / group / classes / output / group_details.php
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/>.
17 /**
18  * Group details page.
19  *
20  * @package    core_group
21  * @copyright  2017 Adrian Greeve <adrian@moodle.com>
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();
27 use renderable;
28 use renderer_base;
29 use stdClass;
30 use templatable;
31 use context_course;
32 use moodle_url;
34 /**
35  * Group details page class.
36  *
37  * @package    core_group
38  * @copyright  2017 Adrian Greeve <adrian@moodle.com>
39  * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40  */
41 class group_details implements renderable, templatable {
43     /** @var stdClass $group An object with the group information. */
44     protected $group;
46     /**
47      * group_details constructor.
48      *
49      * @param  int $groupid Group ID to show details of.
50      */
51     public function __construct($groupid) {
52         $this->group = groups_get_group($groupid, '*', MUST_EXIST);
53     }
55     /**
56      * Export the data.
57      *
58      * @param renderer_base $output
59      * @return stdClass
60      */
61     public function export_for_template(renderer_base $output) {
63         if (!empty($this->group->description) || (!empty($this->group->picture) && empty($this->group->hidepicture))) {
64             $context = context_course::instance($this->group->courseid);
65             $description = file_rewrite_pluginfile_urls($this->group->description,
66                                                         'pluginfile.php',
67                                                         $context->id,
68                                                         'group',
69                                                         'description',
70                                                         $this->group->id);
72             $descriptionformat = $this->group->descriptionformat ?? FORMAT_MOODLE;
73             $options = [
74                 'overflowdiv' => true,
75                 'context'     => $context
76             ];
78             $data = new stdClass();
79             $data->picture = print_group_picture($this->group, $this->group->courseid, true, true, false);
80             $data->name = format_string($this->group->name, true, ['context' => $context]);
81             $data->description = format_text($description, $descriptionformat, $options);
83             if (has_capability('moodle/course:managegroups', $context)) {
84                 $url = new moodle_url('/group/group.php', ['id' => $this->group->id, 'courseid' => $this->group->courseid]);
85                 $data->editurl = $url->out(false);
86             }
88             return $data;
89         } else {
90             return;
91         }
92     }
93 }