Skip to content

Commit

Permalink
MDL-66074 mod_forum: Relocate the grader button
Browse files Browse the repository at this point in the history
Also adding capability checks to the button.
  • Loading branch information
Chocolate-lightning committed Oct 30, 2019
1 parent aa04b72 commit 1d709d7
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
3 changes: 0 additions & 3 deletions mod/forum/templates/discussion_list.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}}
Expand Down
41 changes: 41 additions & 0 deletions mod/forum/templates/grades/grade_button.mustache
Original file line number Diff line number Diff line change
@@ -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>
22 changes: 21 additions & 1 deletion mod/forum/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -88,9 +90,27 @@
$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');
}
Expand Down

0 comments on commit 1d709d7

Please sign in to comment.