Skip to content

Commit

Permalink
MDL-76146 gradereport_grader: Move action icons to action menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyatregubov committed Feb 17, 2023
1 parent 149805b commit 29c2205
Show file tree
Hide file tree
Showing 16 changed files with 547 additions and 55 deletions.
143 changes: 143 additions & 0 deletions grade/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1710,6 +1710,23 @@ public function get_grade_analysis_icon(grade_grade $grade) {
['title' => $title, 'aria-label' => $title]);
}

/**
* Returns a link leading to the grade analysis page
*
* @param grade_grade $grade
* @param string $gradeanalysisstring Language string
* @return string|null
*/
public function get_grade_analysis_link(grade_grade $grade, string $gradeanalysisstring): ?string {
$url = $this->get_grade_analysis_url($grade);
if (is_null($url)) {
return null;
}

return html_writer::link($url, $gradeanalysisstring,
['class' => 'dropdown-item', 'aria-label' => $gradeanalysisstring, 'role' => 'menuitem']);
}

/**
* Returns an action menu for the grade.
*
Expand Down Expand Up @@ -1915,6 +1932,40 @@ public function get_edit_icon($element, $gpr, $returnactionmenulink = false) {
}
}

/**
* Returns a link leading to the edit grade/grade item/category page
*
* @param array $element An array representing an element in the grade_tree
* @param object $gpr A grade_plugin_return object
* @param array $langstrings Language strings
* @return string|null
*/
public function get_edit_link(array $element, object $gpr, array $langstrings): ?string {
$url = null;
$title = '';
if (!has_capability('moodle/grade:manage', $this->context)) {
if (!($element['type'] == 'grade') || !has_capability('moodle/grade:edit', $this->context)) {
return null;
}
}

$object = $element['object'];

if ($element['type'] == 'grade') {
if (empty($object->id)) {
$url = new moodle_url('/grade/edit/tree/grade.php',
['courseid' => $this->courseid, 'itemid' => $object->itemid, 'userid' => $object->userid]);
} else {
$url = new moodle_url('/grade/edit/tree/grade.php',
['courseid' => $this->courseid, 'id' => $object->id]);
}
$title = $langstrings[0];
}
$gpr->add_url_params($url);
return html_writer::link($url, $title,
['class' => 'dropdown-item', 'aria-label' => $title, 'role' => 'menuitem']);
}

/**
* Return hiding icon for give element
*
Expand Down Expand Up @@ -1973,6 +2024,50 @@ public function get_hiding_icon($element, $gpr, $returnactionmenulink = false) {
return $hideicon;
}

/**
* Returns a link with url to hide/unhide grade/grade item/grade category
*
* @param array $element An array representing an element in the grade_tree
* @param object $gpr A grade_plugin_return object
* @param array $langstrings Language strings
* @return string|null
*/
public function get_hiding_link(array $element, object $gpr, array $langstrings): ?string {
if (!$element['object']->can_control_visibility() ||
(!has_capability('moodle/grade:manage', $this->context) &&
!has_capability('moodle/grade:hide', $this->context))) {
return null;
}

$url = new moodle_url('/grade/edit/tree/action.php',
['id' => $this->courseid, 'sesskey' => sesskey(), 'eid' => $element['eid']]);
$url = $gpr->add_url_params($url);

if ($element['object']->is_hidden()) {
$url->param('action', 'show');
$title = $langstrings[0];
} else {
$url->param('action', 'hide');
$title = $langstrings[1];
}

$url = html_writer::link($url, $title,
['class' => 'dropdown-item', 'aria-label' => $title, 'role' => 'menuitem']);

if ($element['type'] == 'grade') {
$item = $element['object']->grade_item;
if ($item->hidden) {
$strparamobj = new stdClass();
$strparamobj->itemname = $item->get_name(true, true);
$strnonunhideable = get_string('nonunhideableverbose', 'grades', $strparamobj);
$url = html_writer::span($title, 'text-muted dropdown-item',
['title' => $strnonunhideable, 'aria-label' => $title, 'role' => 'menuitem']);
}
}

return $url;
}

/**
* Return locking icon for given element
*
Expand Down Expand Up @@ -2030,6 +2125,54 @@ public function get_locking_icon($element, $gpr) {
return $action;
}

/**
* Returns link to lock/unlock grade/grade item/grade category
*
* @param array $element An array representing an element in the grade_tree
* @param object $gpr A grade_plugin_return object
* @param array $langstrings Language strings
*
* @return string|null
*/
public function get_locking_link(array $element, object $gpr, array $langstrings): ?string {

$title = '';
$url = new moodle_url('/grade/edit/tree/action.php',
['id' => $this->courseid, 'sesskey' => sesskey(), 'eid' => $element['eid']]);
$url = $gpr->add_url_params($url);

if (($element['type'] == 'grade') && ($element['object']->grade_item->is_locked())) {
// Don't allow an unlocking action for a grade whose grade item is locked: just print a state icon.
$strparamobj = new stdClass();
$strparamobj->itemname = $element['object']->grade_item->get_name(true, true);
$strnonunlockable = get_string('nonunlockableverbose', 'grades', $strparamobj);
$title = $langstrings[0];
return html_writer::span($title, 'text-muted dropdown-item', ['title' => $strnonunlockable,
'aria-label' => $title, 'role' => 'menuitem']);
} else if ($element['object']->is_locked()) {
$title = $langstrings[0];
if (!has_capability('moodle/grade:manage', $this->context) &&
!has_capability('moodle/grade:unlock', $this->context)) {
return html_writer::span($title, 'text-muted dropdown-item',
['aria-label' => $title, 'role' => 'menuitem']);
} else {
$url->param('action', 'unlock');
}
} else {
$title = $langstrings[1];
if (!has_capability('moodle/grade:manage', $this->context) &&
!has_capability('moodle/grade:lock', $this->context)) {
return html_writer::span($title, 'text-muted dropdown-item',
['aria-label' => $title, 'role' => 'menuitem']);
} else {
$url->param('action', 'lock');
}
}

return html_writer::link($url, $title,
['class' => 'dropdown-item', 'aria-label' => $title, 'role' => 'menuitem']);
}

/**
* Return calculation icon for given element
*
Expand Down
2 changes: 1 addition & 1 deletion grade/report/grader/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@

$actionbar = new \gradereport_grader\output\action_bar($context, $report, $numusers);
print_grade_page_head($COURSE->id, 'report', 'grader', $reportname, false, $buttons, true,
null, null, null, $actionbar);
null, null, null, $actionbar, false);

// make sure separate group does not prevent view
if ($report->currentgroup == -2) {
Expand Down
1 change: 1 addition & 0 deletions grade/report/grader/lang/en/gradereport_grader.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
$string['summarygrader'] = 'A table with the names of students in the first column, with assessable activities grouped by course and category across the top.';
$string['useractivitygrade'] = '{$a} grade';
$string['overriddengrade'] = 'Overridden grade';
$string['cellactions'] = 'Cell actions';

// Deprecated since Moodle 4.2.
$string['privacy:metadata:preference:grade_report_showquickfeedback'] = 'Whether to display a feedback text input box with a dotted border for each grade, allowing the feedback for many grades to be edited at the same time';
Expand Down
Loading

0 comments on commit 29c2205

Please sign in to comment.