mirrored from git://git.moodle.org/moodle.git
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-75513 gradereport_user: Create tertiary navigation actions
- Loading branch information
Mihail Geshoski
committed
Nov 2, 2022
1 parent
be366c5
commit 42c5109
Showing
2 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
<?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/>. | ||
|
||
namespace gradereport_user\output; | ||
|
||
use moodle_url; | ||
use core_grades\output\general_action_bar; | ||
|
||
/** | ||
* Renderable class for the action bar elements in the user report page. | ||
* | ||
* @package gradereport_user | ||
* @copyright 2022 Mihail Geshoski <mihail@moodle.com> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class action_bar extends \core_grades\output\action_bar { | ||
|
||
/** @var int|null $userid The user ID. */ | ||
protected $userid; | ||
|
||
/** @var int $userview The user report view mode. */ | ||
protected $userview; | ||
|
||
/** @var int|null $currentgroupid The user report view mode. */ | ||
protected $currentgroupid; | ||
|
||
/** | ||
* The class constructor. | ||
* | ||
* @param \context $context The context object. | ||
* @param int $userview The user report view mode. | ||
* @param int|null $userid The user ID or 0 if displaying all users. | ||
* @param int|null $currentgroupid The ID of the current group. | ||
*/ | ||
public function __construct(\context $context, int $userview, ?int $userid = null, ?int $currentgroupid = null) { | ||
parent::__construct($context); | ||
$this->userview = $userview; | ||
$this->userid = $userid; | ||
$this->currentgroupid = $currentgroupid; | ||
} | ||
|
||
/** | ||
* Returns the template for the action bar. | ||
* | ||
* @return string | ||
*/ | ||
public function get_template(): string { | ||
return 'gradereport_user/action_bar'; | ||
} | ||
|
||
/** | ||
* Export the data for the mustache template. | ||
* | ||
* @param \renderer_base $output renderer to be used to render the action bar elements. | ||
* @return array | ||
*/ | ||
public function export_for_template(\renderer_base $output): array { | ||
global $PAGE, $USER; | ||
|
||
// If in the course context, we should display the general navigation selector in gradebook. | ||
$courseid = $this->context->instanceid; | ||
// Get the data used to output the general navigation selector. | ||
$generalnavselector = new general_action_bar($this->context, | ||
new moodle_url('/grade/report/user/index.php', ['id' => $courseid]), 'gradereport', 'user'); | ||
$data = $generalnavselector->export_for_template($output); | ||
|
||
// If the user has the capability to view all grades, display the group selector (if applicable), the user selector | ||
// and the view mode selector (if applicable). | ||
if (has_capability('moodle/grade:viewall', $this->context)) { | ||
$course = get_course($courseid); | ||
$gradesrenderer = $PAGE->get_renderer('core_grades'); | ||
$userreportrenderer = $PAGE->get_renderer('gradereport_user'); | ||
|
||
$data['groupselector'] = $gradesrenderer->group_selector($course); | ||
$data['userselector'] = $userreportrenderer->users_selector($course, $this->userid, $this->currentgroupid); | ||
|
||
// Do not output the 'view mode' selector when in zero state or when the current user is viewing its own report. | ||
if (!is_null($this->userid) && $USER->id != $this->userid) { | ||
$data['viewasselector'] = $userreportrenderer->view_mode_selector($this->userid, $this->userview, $courseid); | ||
} | ||
} | ||
|
||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
{{! | ||
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 gradereport_user/action_bar | ||
Actions bar for the grade user report. | ||
Context variables required for this template: | ||
* generalnavselector - The data object containing the required properties to render the general navigation selector. | ||
* groupselector - (optional) HTML that outputs the group selector | ||
* userselector - (optional) HTML that outputs the user selector | ||
* viewasselector - (optional) HTML that outputs the 'view report as' selector | ||
Example context (json): | ||
{ | ||
"generalnavselector": { | ||
"name": "Gradebook tertiary navigation selector", | ||
"value": "opt2", | ||
"baseid": "select-menu56789", | ||
"selectedoption": "Gradebook setup", | ||
"options": [ | ||
{ | ||
"selected": false, | ||
"isgroup": { | ||
"name": "View", | ||
"id": "select-menu-group1", | ||
"options": [ | ||
{ | ||
"name": "Grader report", | ||
"value": "opt1", | ||
"id": "select-menu-option1", | ||
"selected": false | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"selected": false, | ||
"isgroup": { | ||
"name": "Setup", | ||
"id": "select-menu-group2", | ||
"options": [ | ||
{ | ||
"name": "Gradebook setup", | ||
"value": "opt2", | ||
"id": "select-menu-option2", | ||
"selected": true | ||
} | ||
] | ||
} | ||
} | ||
] | ||
}, | ||
"groupselector": "<div class='group-selector'></div>", | ||
"userselector": "<div class='user-selector'></div>", | ||
"viewasselector": "<div class='view-user-selector'></div>" | ||
} | ||
}} | ||
<div class="container-fluid tertiary-navigation full-width-bottom-border"> | ||
<div class="row"> | ||
{{#generalnavselector}} | ||
<div class="navitem"> | ||
{{>core/tertiary_navigation_selector}} | ||
</div> | ||
<div class="navitem-divider"></div> | ||
{{/generalnavselector}} | ||
{{#groupselector}} | ||
<div class="navitem"> | ||
{{{groupselector}}} | ||
</div> | ||
<div class="navitem-divider"></div> | ||
{{/groupselector}} | ||
{{#userselector}} | ||
<div class="navitem"> | ||
{{{userselector}}} | ||
</div> | ||
<div class="navitem-divider"></div> | ||
{{/userselector}} | ||
<div class="d-flex ml-sm-auto"> | ||
{{#viewasselector}} | ||
<div class="navitem-divider"></div> | ||
<div class="navitem"> | ||
{{{viewasselector}}} | ||
</div> | ||
<div class="navitem-divider"></div> | ||
{{/viewasselector}} | ||
</div> | ||
</div> | ||
</div> |