MDL-75155 grades: Removed $exportactiveurl and $importactiveurl

The parameters $exportactiveurl and $importactiveurl are removed from
export_action_bar and import_action_bar classes. Not only passing them
were redundant and it was possible to generate them by having
$activeplugin (also passed to the mentioned class constructors), but
also we had a bug there. The value of $PAGE->url was passed as those
parameters, but $PAGE->url can sometimes include additional parameters
and as a result, its value may not match any of the available
export/import plugins.
This commit is contained in:
Shamim Rezaie 2022-08-20 15:40:26 +10:00
parent fa59f35ca4
commit 3505cb0fd2
12 changed files with 33 additions and 25 deletions

View File

@ -27,9 +27,6 @@ use moodle_url;
*/
class export_action_bar extends action_bar {
/** @var moodle_url $exportactiveurl The URL that should be set as active in the exports URL selector element. */
protected $exportactiveurl;
/** @var string $activeplugin The plugin of the current export grades page (xml, ods, ...). */
protected $activeplugin;
@ -37,12 +34,14 @@ class export_action_bar extends action_bar {
* The class constructor.
*
* @param \context $context The context object.
* @param moodle_url $exportactiveurl The URL that should be set as active in the exports URL selector element.
* @param null $unused This parameter has been deprecated since 4.1 and should not be used anymore.
* @param string $activeplugin The plugin of the current export grades page (xml, ods, ...).
*/
public function __construct(\context $context, moodle_url $exportactiveurl, string $activeplugin) {
public function __construct(\context $context, $unused, string $activeplugin) {
if ($unused !== null) {
debugging('Deprecated argument passed to ' . __FUNCTION__, DEBUG_DEVELOPER);
}
parent::__construct($context);
$this->exportactiveurl = $exportactiveurl;
$this->activeplugin = $activeplugin;
}
@ -85,13 +84,17 @@ class export_action_bar extends action_bar {
}
$exportsmenu = [];
$exportactiveurl = null;
// Generate the data for the exports navigation selector menu.
foreach ($exports as $export) {
$exportsmenu[$export->link->out()] = $export->string;
if ($export->id == $this->activeplugin) {
$exportactiveurl = $export->link->out();
}
}
// This navigation selector menu will contain the links to all available grade export plugin pages.
$exportsurlselect = new \core\output\select_menu('exportas', $exportsmenu, $this->exportactiveurl->out());
$exportsurlselect = new \core\output\select_menu('exportas', $exportsmenu, $exportactiveurl);
$exportsurlselect->set_label(get_string('exportas', 'grades'));
$data['exportselector'] = $exportsurlselect->export_for_template($output);

View File

@ -48,8 +48,7 @@ class export_key_manager_action_bar extends action_bar {
}
$courseid = $this->context->instanceid;
// Get the data used to output the general navigation selector and exports navigation selector.
$exportnavselectors = new export_action_bar($this->context,
new moodle_url('/grade/export/keymanager.php', ['id' => $courseid]), 'keymanager');
$exportnavselectors = new export_action_bar($this->context, null, 'keymanager');
$data = $exportnavselectors->export_for_template($output);
// Add a button to the action bar with a link to the 'add user key' page.

View File

@ -27,9 +27,6 @@ use moodle_url;
*/
class import_action_bar extends action_bar {
/** @var moodle_url $importactiveurl The URL that should be set as active in the imports URL selector element. */
protected $importactiveurl;
/** @var string $activeplugin The plugin of the current import grades page (xml, csv, ...). */
protected $activeplugin;
@ -37,12 +34,14 @@ class import_action_bar extends action_bar {
* The class constructor.
*
* @param \context $context The context object.
* @param moodle_url $importactiveurl The URL that should be set as active in the imports URL selector element.
* @param null $unused This parameter has been deprecated since 4.1 and should not be used anymore.
* @param string $activeplugin The plugin of the current import grades page (xml, csv, ...).
*/
public function __construct(\context $context, moodle_url $importactiveurl, string $activeplugin) {
public function __construct(\context $context, $unused, string $activeplugin) {
if ($unused !== null) {
debugging('Deprecated argument passed to ' . __FUNCTION__, DEBUG_DEVELOPER);
}
parent::__construct($context);
$this->importactiveurl = $importactiveurl;
$this->activeplugin = $activeplugin;
}
@ -85,13 +84,17 @@ class import_action_bar extends action_bar {
}
$importsmenu = [];
$importactiveurl = null;
// Generate the data for the imports navigation selector menu.
foreach ($imports as $import) {
$importsmenu[$import->link->out()] = $import->string;
if ($import->id == $this->activeplugin) {
$importactiveurl = $import->link->out();
}
}
// This navigation selector menu will contain the links to all available grade export plugin pages.
$importsurlselect = new \core\output\select_menu('importas', $importsmenu, $this->importactiveurl->out());
$importsurlselect = new \core\output\select_menu('importas', $importsmenu, $importactiveurl);
$importsurlselect->set_label(get_string('importas', 'grades'));
$data['importselector'] = $importsurlselect->export_for_template($output);

View File

@ -48,8 +48,7 @@ class import_key_manager_action_bar extends action_bar {
}
$courseid = $this->context->instanceid;
// Get the data used to output the general navigation selector and imports navigation selector.
$importnavselectors = new import_action_bar($this->context,
new moodle_url('/grade/import/keymanager.php', ['id' => $courseid]), 'keymanager');
$importnavselectors = new import_action_bar($this->context, null, 'keymanager');
$data = $importnavselectors->export_for_template($output);
// Add a button to the action bar with a link to the 'add user key' page.

View File

@ -33,7 +33,7 @@ $context = context_course::instance($id);
require_capability('moodle/grade:export', $context);
require_capability('gradeexport/ods:view', $context);
$actionbar = new \core_grades\output\export_action_bar($context, $PAGE->url, 'ods');
$actionbar = new \core_grades\output\export_action_bar($context, null, 'ods');
print_grade_page_head($COURSE->id, 'export', 'ods',
get_string('exportto', 'grades') . ' ' . get_string('pluginname', 'gradeexport_ods'),
false, false, true, null, null, null, $actionbar);

View File

@ -33,7 +33,7 @@ $context = context_course::instance($id);
require_capability('moodle/grade:export', $context);
require_capability('gradeexport/txt:view', $context);
$actionbar = new \core_grades\output\export_action_bar($context, $PAGE->url, 'txt');
$actionbar = new \core_grades\output\export_action_bar($context, null, 'txt');
print_grade_page_head($COURSE->id, 'export', 'txt',
get_string('exportto', 'grades') . ' ' . get_string('pluginname', 'gradeexport_txt'),
false, false, true, null, null, null, $actionbar);

View File

@ -33,7 +33,7 @@ $context = context_course::instance($id);
require_capability('moodle/grade:export', $context);
require_capability('gradeexport/xls:view', $context);
$actionbar = new \core_grades\output\export_action_bar($context, $PAGE->url, 'xls');
$actionbar = new \core_grades\output\export_action_bar($context, null, 'xls');
print_grade_page_head($COURSE->id, 'export', 'xls',
get_string('exportto', 'grades') . ' ' . get_string('pluginname', 'gradeexport_xls'),
false, false, true, null, null, null, $actionbar);

View File

@ -33,7 +33,7 @@ $context = context_course::instance($id);
require_capability('moodle/grade:export', $context);
require_capability('gradeexport/xml:view', $context);
$actionbar = new \core_grades\output\export_action_bar($context, $PAGE->url, 'xml');
$actionbar = new \core_grades\output\export_action_bar($context, null, 'xml');
print_grade_page_head($COURSE->id, 'export', 'xml',
get_string('exportto', 'grades') . ' ' . get_string('pluginname', 'gradeexport_xml'),
false, false, true, null, null, null, $actionbar);

View File

@ -51,7 +51,7 @@ $separatemode = (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and
!has_capability('moodle/site:accessallgroups', $context));
$currentgroup = groups_get_course_group($course);
$actionbar = new \core_grades\output\import_action_bar($context, $PAGE->url, 'csv');
$actionbar = new \core_grades\output\import_action_bar($context, null, 'csv');
print_grade_page_head($course->id, 'import', 'csv', get_string('importcsv', 'grades'), false, false, true,
'importcsv', 'grades', null, $actionbar);

View File

@ -47,7 +47,7 @@ $separatemode = (groups_get_course_groupmode($COURSE) == SEPARATEGROUPS and
!has_capability('moodle/site:accessallgroups', $context));
$currentgroup = groups_get_course_group($course);
$actionbar = new \core_grades\output\import_action_bar($context, $PAGE->url, 'direct');
$actionbar = new \core_grades\output\import_action_bar($context, null, 'direct');
print_grade_page_head($course->id, 'import', 'direct', get_string('pluginname', 'gradeimport_direct'), false, false, true,
'userdata', 'gradeimport_direct', null, $actionbar);

View File

@ -87,7 +87,7 @@ if ($data = $mform->get_data()) {
}
}
$actionbar = new \core_grades\output\import_action_bar($context, $PAGE->url, 'xml');
$actionbar = new \core_grades\output\import_action_bar($context, null, 'xml');
print_grade_page_head($COURSE->id, 'import', 'xml', get_string('importxml', 'grades'),
false, false, true, 'importxml', 'gradeimport_xml', null, $actionbar);

View File

@ -1,6 +1,10 @@
This file describes API changes in /grade/* ;
Information provided here is intended especially for developers.
=== 4.1 ===
* The $importactiveurl parameter in the constructor of the core_grades\output\import_action_bar class has been deprecated and is not used anymore.
* The $exportactiveurl parameter in the constructor of the core_grades\output\export_action_bar class has been deprecated and is not used anymore.
=== 4.0 ===
* The select_in_gradebook_tabs() function in behat_grade.php has been deprecated. Please use the function