MDL-66074 mod_forum: Relocate the grader button
authorMathew May <mathewm@hotmail.co.nz>
Sat, 5 Oct 2019 11:32:30 +0000 (19:32 +0800)
committerMathew May <mathewm@hotmail.co.nz>
Wed, 30 Oct 2019 02:23:41 +0000 (10:23 +0800)
Also adding capability checks to the button.

mod/forum/templates/discussion_list.mustache
mod/forum/templates/grades/grade_button.mustache [new file with mode: 0644]
mod/forum/view.php

index 135cf73..2140770 100644 (file)
@@ -72,9 +72,6 @@
         {{/forum.capabilities.selfenrol}}
     {{/forum.capabilities.create}}
 
-    {{!TODO Add capability check}}
-    <a class="btn btn-primary" href="" data-grade-action="launch">{{#str}}gradeusers, forum{{/str}}</a>
-
     {{#state.hasdiscussions}}
         {{$discussion_top_pagination}}
             {{{ pagination }}}
diff --git a/mod/forum/templates/grades/grade_button.mustache b/mod/forum/templates/grades/grade_button.mustache
new file mode 100644 (file)
index 0000000..d03c3c2
--- /dev/null
@@ -0,0 +1,41 @@
+{{!
+    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 mod_forum/grades/grade_button
+
+    Template which defines a forum post for sending in a single-post HTML email.
+
+    Classes required for JS:
+    * none
+
+    Data attributes required for JS:
+    * none
+
+    Example context (json):
+    {
+    }
+}}
+<a class="btn btn-primary" href="" data-grade-action="launch" {{!
+    }}data-contextid="{{contextid}}" {{!
+    }}data-cmid="{{cmid}}" {{!
+    }}data-name="{{name}}" {{!
+    }}data-group="{{groupid}}" {{!
+    }}data-grading-component="{{gradingcomponent}}" {{!
+    }}data-grading-component-subtype="{{gradingcomponentsubtype}}" {{!
+    }}data-gradable-itemtype="forum" {{!
+    }}{{#firstgradeduserid}}data-initialuserid="{{firstgradeduserid}}" {{/firstgradeduserid}}{{!
+    }}>{{#str}}gradeusers, forum{{/str}}</a>
index 30d640a..c564295 100644 (file)
@@ -22,6 +22,8 @@
  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  */
 
+use mod_forum\grades\forum_gradeitem;
+
 require_once('../../config.php');
 
 $managerfactory = mod_forum\local\container::get_manager_factory();
@@ -88,9 +90,27 @@ $PAGE->set_context($forum->get_context());
 $PAGE->set_title($forum->get_name());
 $PAGE->add_body_class('forumtype-' . $forum->get_type() . ' reset-style');
 $PAGE->set_heading($course->fullname);
-$PAGE->set_button(forum_search_form($course, $search));
 $PAGE->set_include_region_main_settings_in_header_actions(true);
 
+$buttons = [];
+if ($capabilitymanager->can_grade($USER)) {
+    $forumgradeitem = forum_gradeitem::load_from_forum_entity($forum);
+    if ($forumgradeitem->is_grading_enabled()) {
+        $groupid = groups_get_activity_group($cm, true) ?: null;
+        $gradeobj = (object) [
+            'contextid' => $forum->get_context()->id,
+            'cmid' => $cmid,
+            'name' => $forum->get_name(),
+            'groupid' => $groupid,
+            'gradingcomponent' => $forumgradeitem->get_grading_component_name(),
+            'gradingcomponentsubtype' => $forumgradeitem->get_grading_component_subtype(),
+        ];
+        $buttons[] = $OUTPUT->render_from_template('mod_forum/grades/grade_button', $gradeobj);
+    }
+}
+$buttons[] = forum_search_form($course, $search);
+$PAGE->set_button(implode('', $buttons));
+
 if ($istypesingle && $displaymode == FORUM_MODE_MODERN) {
     $PAGE->add_body_class('modern-display-mode reset-style');
 }