MDL-60515 groups: Display group information on the participants page.
authorAdrian Greeve <adrian@moodle.com>
Mon, 23 Oct 2017 00:04:09 +0000 (08:04 +0800)
committerAdrian Greeve <adrian@moodle.com>
Mon, 30 Oct 2017 08:43:18 +0000 (16:43 +0800)
group/classes/output/group_details.php [new file with mode: 0644]
group/classes/output/renderer.php
group/members.php
group/templates/group_details.mustache [new file with mode: 0644]
theme/boost/scss/moodle/user.scss
theme/bootstrapbase/less/moodle/user.less
theme/bootstrapbase/style/moodle.css
user/index.php

diff --git a/group/classes/output/group_details.php b/group/classes/output/group_details.php
new file mode 100644 (file)
index 0000000..30c67b7
--- /dev/null
@@ -0,0 +1,93 @@
+<?php
+// This file is part of Moodle - http://moodle.org/
+//
+// Moodle is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Moodle is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+
+/**
+ * Group details page.
+ *
+ * @package    core_group
+ * @copyright  2017 Adrian Greeve <adrian@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+namespace core_group\output;
+defined('MOODLE_INTERNAL') || die();
+
+use renderable;
+use renderer_base;
+use stdClass;
+use templatable;
+use context_course;
+use moodle_url;
+
+/**
+ * Group details page class.
+ *
+ * @package    core_group
+ * @copyright  2017 Adrian Greeve <adrian@moodle.com>
+ * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+class group_details implements renderable, templatable {
+
+    /** @var stdClass $group An object with the group information. */
+    protected $group;
+
+    /**
+     * group_details constructor.
+     *
+     * @param  int $groupid Group ID to show details of.
+     */
+    public function __construct($groupid) {
+        $this->group = groups_get_group($groupid, '*', MUST_EXIST);
+    }
+
+    /**
+     * Export the data.
+     *
+     * @param renderer_base $output
+     * @return stdClass
+     */
+    public function export_for_template(renderer_base $output) {
+
+        if (!empty($this->group->description) || (!empty($this->group->picture) && empty($this->group->hidepicture))) {
+            $context = context_course::instance($this->group->courseid);
+            $description = file_rewrite_pluginfile_urls($this->group->description,
+                                                        'pluginfile.php',
+                                                        $context->id,
+                                                        'group',
+                                                        'description',
+                                                        $this->group->id);
+
+            $descriptionformat = $this->group->descriptionformat ?? FORMAT_MOODLE;
+            $options = [
+                'overflowdiv' => true,
+                'context'     => $context
+            ];
+
+            $data = new stdClass();
+            $data->picture = print_group_picture($this->group, $this->group->courseid, true, true, false);
+            $data->name = format_string($this->group->name, true, ['context' => $context]);
+            $data->description = format_text($description, $descriptionformat, $options);
+
+            if (has_capability('moodle/course:managegroups', $context)) {
+                $url = new moodle_url('/group/group.php', ['id' => $this->group->id, 'courseid' => $this->group->courseid]);
+                $data->editurl = $url->out(false);
+            }
+
+            return $data;
+        } else {
+            return;
+        }
+    }
+}
index 14443cf..c3285fa 100644 (file)
@@ -47,4 +47,15 @@ class renderer extends plugin_renderer_base {
         $data = $page->export_for_template($this);
         return parent::render_from_template('core_group/index', $data);
     }
+
+    /**
+     * Defer to template.
+     *
+     * @param group_details $page Group details page object.
+     * @return string HTML to render the group details.
+     */
+    public function group_details(group_details $page) {
+        $data = $page->export_for_template($this);
+        return parent::render_from_template('core_group/group_details', $data);
+    }
 }
index 3f4e352..f089e32 100644 (file)
@@ -102,36 +102,11 @@ echo $OUTPUT->heading(get_string('adduserstogroup', 'group').": $groupname", 3);
 // Store the rows we want to display in the group info.
 $groupinforow = array();
 
-// Check if there is a picture to display.
-if (!empty($group->picture)) {
-    $picturecell = new html_table_cell();
-    $picturecell->attributes['class'] = 'left side picture';
-    $picturecell->text = print_group_picture($group, $course->id, true, true, false);
-    $groupinforow[] = $picturecell;
-}
-
 // Check if there is a description to display.
-$group->description = file_rewrite_pluginfile_urls($group->description, 'pluginfile.php', $context->id, 'group', 'description', $group->id);
 if (!empty($group->description)) {
-    if (!isset($group->descriptionformat)) {
-        $group->descriptionformat = FORMAT_MOODLE;
-    }
-
-    $options = new stdClass;
-    $options->overflowdiv = true;
-
-    $contentcell = new html_table_cell();
-    $contentcell->attributes['class'] = 'content';
-    $contentcell->text = format_text($group->description, $group->descriptionformat, $options);
-    $groupinforow[] = $contentcell;
-}
-
-// Check if we have something to show.
-if (!empty($groupinforow)) {
-    $groupinfotable = new html_table();
-    $groupinfotable->attributes['class'] = 'groupinfobox';
-    $groupinfotable->data[] = new html_table_row($groupinforow);
-    echo html_writer::table($groupinfotable);
+    $grouprenderer = $PAGE->get_renderer('core_group');
+    $groupdetailpage = new \core_group\output\group_details($groupid);
+    echo $grouprenderer->group_details($groupdetailpage);
 }
 
 /// Print the editing form
diff --git a/group/templates/group_details.mustache b/group/templates/group_details.mustache
new file mode 100644 (file)
index 0000000..05ac405
--- /dev/null
@@ -0,0 +1,65 @@
+{{!
+    This file is part of Moodle - http://moodle.org/
+
+    Moodle is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    Moodle is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
+}}
+{{!
+    @template core_group/group_details
+
+    Template for the Groups page.
+
+    Classes required for JS:
+    * none
+
+    Data attributes required for JS:
+    * none
+
+    Context variables required for this template:
+    * name string Group Name
+    * picture string Group image HTML
+    * description string Group description
+    * edit string edit link to edit the group
+
+    Example context (json):
+    {
+        "name": "Group Name",
+        "picture": "",
+        "description": "This is the description for Group Name",
+        "editurl": ""
+    }
+}}
+{{#name}}
+<div class="groupinfobox container-fluid p-y-1">
+    <div class="row-fluid">
+        {{#picture}}
+        <div class="group-image col-sm-1 span1">{{{picture}}}</div>
+        {{/picture}}
+        <div {{#picture}}class="col-sm-11 span11"{{/picture}}{{^picture}}class="col"{{/picture}}>
+            <div class="container-fluid">
+                <div class="row-fluid">
+                    <div class="col">
+                        <h3 class="d-inline-block">{{name}}</h3>
+                        {{#editurl}}
+                        <span class="group-edit"><a href="{{editurl}}">{{#pix}}t/edit, core, {{#str}}editgroupprofile{{/str}}{{/pix}}</a></span>
+                        {{/editurl}}
+                    </div>
+                </div>
+                <div class="row-fluid">
+                    <div class="group-description col">{{{description}}}</div>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+{{/name}}
index aa7f3a6..3561900 100644 (file)
     font-weight: bold;
 }
 
+.group-image {
+    min-width: 93px;
+}
+
 .groupinfobox {
     @extend .card;
 }
index 265d53e..4e7ee1f 100644 (file)
     width: 100px;
     vertical-align: top;
 }
+
+.group-image {
+    min-width: 60px;
+}
+
 .course-participation #showall {
     text-align: center;
     margin: 10px 0;
index 3789070..dc577b3 100644 (file)
@@ -9895,6 +9895,9 @@ body.path-question-type .mform fieldset.hidden {
   width: 100px;
   vertical-align: top;
 }
+.group-image {
+  min-width: 60px;
+}
 .course-participation #showall {
   text-align: center;
   margin: 10px 0;
index ef2de01..e458477 100644 (file)
@@ -196,6 +196,12 @@ if ($groupid !== false) {
     }
 }
 
+if ($groupid && ($course->groupmode != SEPARATEGROUPS || $canaccessallgroups)) {
+    $grouprenderer = $PAGE->get_renderer('core_group');
+    $groupdetailpage = new \core_group\output\group_details($groupid);
+    echo $grouprenderer->group_details($groupdetailpage);
+}
+
 // Manage enrolments.
 $manager = new course_enrolment_manager($PAGE, $course);
 $enrolbuttons = $manager->get_manual_enrol_buttons();