diff --git a/grade/report/singleview/classes/output/gradeitem_action_bar.php b/grade/report/singleview/classes/output/action_bar.php similarity index 51% rename from grade/report/singleview/classes/output/gradeitem_action_bar.php rename to grade/report/singleview/classes/output/action_bar.php index 203cb24a572..59c0012e034 100644 --- a/grade/report/singleview/classes/output/gradeitem_action_bar.php +++ b/grade/report/singleview/classes/output/action_bar.php @@ -20,27 +20,51 @@ namespace gradereport_singleview\output; use moodle_url; use renderer_base; +use gradereport_singleview\report\singleview; /** - * Class gradeitem_action_bar + * Renderable class for the action bar elements in the single view report page. * * @package gradereport_singleview * @copyright 2022 Shamim Rezaie * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -class gradeitem_action_bar extends \core_grades\output\action_bar { +class action_bar extends \core_grades\output\action_bar { - protected \gradereport_singleview\report\singleview $report; + /** @var singleview $report The single view report class. */ + protected singleview $report; - public function __construct(\context $context, \gradereport_singleview\report\singleview $report) { + /** @var string $itemtype The single view item type. */ + protected string $itemtype; + + /** + * The class constructor. + * + * @param \context $context The context object. + * @param singleview $report The single view report class. + * @param string $itemtype The single view item type. + */ + public function __construct(\context $context, singleview $report, string $itemtype) { parent::__construct($context); $this->report = $report; + $this->itemtype = $itemtype; } + /** + * Returns the template for the action bar. + * + * @return string + */ public function get_template(): string { - return 'gradereport_singleview/gradeitem_action_bar'; + return 'gradereport_singleview/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) { $courseid = $this->context->instanceid; // Get the data used to output the general navigation selector. @@ -52,24 +76,19 @@ class gradeitem_action_bar extends \core_grades\output\action_bar { ); $data = $generalnavselector->export_for_template($output); - $data['gradeselectactive'] = true; - $data['gradezerolink'] = new moodle_url( - '/grade/report/singleview/index.php', - ['id' => $courseid, 'item' => 'grade_select'] - ); - $data['userzerolink'] = new moodle_url( - '/grade/report/singleview/index.php', - ['id' => $courseid, 'item' => 'user_select'] - ); + // The data required to output the page toggle element. + $data['pagetoggler'] = [ + 'displaylabel' => true, + 'userselectactive' => $this->itemtype === 'user', + 'gradeselectactive' => $this->itemtype === 'grade', + 'gradezerolink' => new moodle_url('/grade/report/singleview/index.php', + ['id' => $courseid, 'item' => 'grade_select']), + 'userzerolink' => new moodle_url('/grade/report/singleview/index.php', + ['id' => $courseid, 'item' => 'user_select']) + ]; $data['groupselector'] = $this->report->group_selector; - - // Grade item selector. - $screen = new \gradereport_singleview\local\screen\user($this->report->courseid, null, $this->report->currentgroup); - $options = $screen->options(); - $gradeitemselector = new \core\output\select_menu('itemid', $options, $this->report->screen->item->id); - $gradeitemselector->set_label(get_string('assessmentname', 'gradereport_singleview')); - $data['gradeitemselector'] = $gradeitemselector->export_for_template($output); + $data['itemselector'] = $this->report->itemselector; $data['pbarurl'] = $this->report->pbarurl->out(false); diff --git a/grade/report/singleview/classes/output/user_action_bar.php b/grade/report/singleview/classes/output/user_action_bar.php deleted file mode 100644 index 75987c88647..00000000000 --- a/grade/report/singleview/classes/output/user_action_bar.php +++ /dev/null @@ -1,78 +0,0 @@ -. - -declare(strict_types=1); - -namespace gradereport_singleview\output; - -use moodle_url; -use renderer_base; - -/** - * Class user_action_bar - * - * @package gradereport_singleview - * @copyright 2022 Shamim Rezaie - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class user_action_bar extends \core_grades\output\action_bar { - - protected \gradereport_singleview\report\singleview $report; - - public function __construct(\context $context, \gradereport_singleview\report\singleview $report) { - parent::__construct($context); - $this->report = $report; - } - - public function get_template(): string { - return 'gradereport_singleview/user_action_bar'; - } - - public function export_for_template(renderer_base $output) { - $courseid = $this->context->instanceid; - // Get the data used to output the general navigation selector. - $generalnavselector = new \core_grades\output\general_action_bar( - $this->context, - new moodle_url('/grade/report/singleview/index.php', ['id' => $courseid]), - 'report', - 'singleview' - ); - $data = $generalnavselector->export_for_template($output); - - $data['userselectactive'] = true; - $data['gradezerolink'] = new moodle_url( - '/grade/report/singleview/index.php', - ['id' => $courseid, 'item' => 'grade_select'] - ); - $data['userzerolink'] = new moodle_url( - '/grade/report/singleview/index.php', - ['id' => $courseid, 'item' => 'user_select'] - ); - - $data['groupselector'] = $this->report->group_selector; - - // User selector. - $screen = new \gradereport_singleview\local\screen\grade($this->report->courseid, null, $this->report->currentgroup); - $options = $screen->options(); - $userselector = new \core\output\select_menu('itemid', $options, $this->report->screen->item->id); - $userselector->set_label(get_string('user')); - $data['userselector'] = $userselector->export_for_template($output); - - $data['pbarurl'] = $this->report->pbarurl->out(false); - - return $data; - } -} diff --git a/grade/report/singleview/classes/report/singleview.php b/grade/report/singleview/classes/report/singleview.php index 70dafa80efc..6e32756c2bc 100644 --- a/grade/report/singleview/classes/report/singleview.php +++ b/grade/report/singleview/classes/report/singleview.php @@ -34,6 +34,9 @@ require_once($CFG->dirroot . '/grade/report/lib.php'); */ class singleview extends grade_report { + /** @var string|null $itemselector The raw HTML of the item selector based on the selected single view item type. */ + public ?string $itemselector = null; + /** * Return the list of valid screens, used to validate the input. * @@ -99,6 +102,8 @@ class singleview extends grade_report { // The setup_group method is used to validate group mode and permissions and define the currentgroup value. $this->setup_groups(); + $this->setup_item_selector($itemtype, $itemid); + $screenclass = "\\gradereport_singleview\\local\\screen\\${itemtype}"; $this->screen = new $screenclass($courseid, $itemid, $this->currentgroup); @@ -135,4 +140,22 @@ class singleview extends grade_report { $renderer = $PAGE->get_renderer('core_grades'); return $renderer->group_selector($course, $urlroot->out()); } + + /** + * Function used to set the the appropriate item selector (raw HTML) based on the selected single view item type. + * + * @param string $itemtype The single view item type. + * @param int|null $itemid The item ID. + */ + protected function setup_item_selector(string $itemtype, ?int $itemid) { + global $PAGE; + + $renderer = $PAGE->get_renderer('gradereport_singleview'); + + if ($itemtype === 'user' || $itemtype === 'user_select' ) { + $this->itemselector = $renderer->users_selector($this->course, $itemid, $this->currentgroup); + } else if ($itemtype === 'grade' || $itemtype === 'grade_select' ) { + $this->itemselector = $renderer->grade_items_selector($this->course, $itemid); + } + } } diff --git a/grade/report/singleview/index.php b/grade/report/singleview/index.php index 806402d8e6d..23decbe15a2 100644 --- a/grade/report/singleview/index.php +++ b/grade/report/singleview/index.php @@ -93,17 +93,18 @@ $report = new gradereport_singleview\report\singleview($courseid, $gpr, $context $reportname = $report->screen->heading(); -$actionbar = new \core_grades\output\general_action_bar($context, - new moodle_url('/grade/report/singleview/index.php', ['id' => $courseid]), 'report', 'singleview'); +if ($itemtype == 'user' || $itemtype == 'user_select') { + $actionbar = new \gradereport_singleview\output\action_bar($context, $report, 'user'); +} else if ($itemtype == 'grade' || $itemtype == 'grade_select') { + $actionbar = new \gradereport_singleview\output\action_bar($context, $report, 'grade'); +} else { + $actionbar = new \core_grades\output\general_action_bar($context, new moodle_url('/grade/report/singleview/index.php', + ['id' => $courseid]), 'report', 'singleview'); +} if ($itemtype == 'user') { - $actionbar = new \gradereport_singleview\output\user_action_bar($context, $report); print_grade_page_head($course->id, 'report', 'singleview', $reportname, false, false, true, null, null, $report->screen->item, $actionbar); -} else if ($itemtype == 'grade') { - $actionbar = new \gradereport_singleview\output\gradeitem_action_bar($context, $report); - print_grade_page_head($course->id, 'report', 'singleview', $reportname, false, false, - true, null, null, null, $actionbar); } else { print_grade_page_head($course->id, 'report', 'singleview', $reportname, false, false, true, null, null, null, $actionbar); diff --git a/grade/report/singleview/templates/user_action_bar.mustache b/grade/report/singleview/templates/action_bar.mustache similarity index 65% rename from grade/report/singleview/templates/user_action_bar.mustache rename to grade/report/singleview/templates/action_bar.mustache index dd18fb49961..ded93d0c8d8 100644 --- a/grade/report/singleview/templates/user_action_bar.mustache +++ b/grade/report/singleview/templates/action_bar.mustache @@ -15,7 +15,7 @@ along with Moodle. If not, see . }} {{! - @template gradereport_singleview/user_action_bar + @template gradereport_singleview/action_bar }}
@@ -29,20 +29,15 @@ {{{.}}}
{{/groupselector}} - {{#userselector}} + {{#itemselector}} - {{#js}} - document.querySelector('.tertiary-navigation [name="itemid"]').addEventListener('change', function(e) { - var url = new URL("{{{pbarurl}}}"); - url.searchParams.set('itemid', e.target.value); - window.location.href = url; - }); - {{/js}} - {{/userselector}} - + {{/itemselector}} + {{#pagetoggler}} + + {{/pagetoggler}}
diff --git a/grade/report/singleview/templates/gradeitem_action_bar.mustache b/grade/report/singleview/templates/gradeitem_action_bar.mustache deleted file mode 100644 index 011b163faec..00000000000 --- a/grade/report/singleview/templates/gradeitem_action_bar.mustache +++ /dev/null @@ -1,48 +0,0 @@ -{{! - 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 . -}} -{{! - @template gradereport_singleview/gradeitem_action_bar -}} -
-
- {{#generalnavselector}} - - {{/generalnavselector}} - {{#groupselector}} - - {{/groupselector}} - {{#gradeitemselector}} - - {{#js}} - document.querySelector('.tertiary-navigation [name="itemid"]').addEventListener('change', function(e) { - var url = new URL("{{{pbarurl}}}"); - url.searchParams.set('itemid', e.target.value); - window.location.href = url; - }); - {{/js}} - {{/gradeitemselector}} - -
-