Skip to content

Commit

Permalink
MDL-77632 core_grades: Move select checkboxes to name column.
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyatregubov committed Jun 30, 2023
1 parent 8dbb618 commit 65cafd3
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 18 deletions.
114 changes: 106 additions & 8 deletions grade/edit/tree/lib.php
Expand Up @@ -69,10 +69,6 @@ public function __construct($gtree, $moving, $gpr) {
$this->columns[] = grade_edit_tree_column::factory('status');
$this->columns[] = grade_edit_tree_column::factory('actions');

if ($this->deepest_level > 1) {
$this->columns[] = grade_edit_tree_column::factory('select');
}

$this->table = new html_table();
$this->table->id = "grade_edit_tree_table";
$this->table->attributes['class'] = 'generaltable simple setup-grades';
Expand Down Expand Up @@ -818,16 +814,41 @@ public function get_category_cell($category, $levelclass, $params) {
'category' => $params['eid']
]);

$mastercheckbox = '';
if ($this->deepest_level > 1) {
if (empty($params['eid'])) {
throw new Exception('Array key (eid) missing from 3rd param of ' .
'grade_edit_tree_column_select::get_category_cell($category, $levelclass, $params)');
}

// Get toggle group for this master checkbox.
$togglegroup = $this->get_checkbox_togglegroup($category);
// Set label for this master checkbox.
$masterlabel = $params['level'] === 1 ? get_string('all') : $params['name'];
// Build the master checkbox.
$mastercheckbox = new \core\output\checkbox_toggleall($togglegroup, true, [
'id' => $togglegroup,
'name' => $togglegroup,
'value' => 1,
'classes' => 'itemselect ignoredirty mr-2',
'label' => $masterlabel,
// Consistent label to prevent the select column from resizing.
'selectall' => $masterlabel,
'deselectall' => $masterlabel,
'labelclasses' => 'accesshide m-0',
]);

$mastercheckbox = $OUTPUT->render($mastercheckbox);
}

$moveaction = isset($params['moveaction']) ? $params['moveaction'] : '';
$categorycell = parent::get_category_cell($category, $levelclass, $params);
$categorycell->colspan = ($this->deepest_level + 2) - $params['level'];
$categorycell->text = html_writer::div($visibilitytoggle . $moveaction . $params['name'], 'font-weight-bold');
$categorycell->text = html_writer::div($mastercheckbox . $visibilitytoggle . $moveaction . $params['name'], 'font-weight-bold');
return $categorycell;
}

public function get_item_cell($item, $params) {
global $CFG;

if (empty($params['element']) || empty($params['name']) || empty($params['level'])) {
throw new Exception('Array key (name, level or element) missing from 2nd param of grade_edit_tree_column_name::get_item_cell($item, $params)');
}
Expand All @@ -849,9 +870,56 @@ public function get_item_cell($item, $params) {

$itemcell = parent::get_item_cell($item, $params);
$itemcell->colspan = ($this->deepest_level + 1) - $params['level'];
$itemcell->text = \html_writer::div($moveaction . $itemicon . $content, "{$params['itemtype']} d-flex align-items-center");

$checkbox = '';
if (($this->deepest_level > 1) && ($params['itemtype'] != 'course') && ($params['itemtype'] != 'category')) {
global $OUTPUT;

$label = get_string('select', 'grades', $params['name']);

if (empty($params['itemtype']) || empty($params['eid'])) {
throw new \moodle_exception('missingitemtypeoreid', 'core_grades');
}

// Fetch the grade item's category.
$category = $item->get_parent_category();
$togglegroup = $this->get_checkbox_togglegroup($category);

$checkboxid = 'select_' . $params['eid'];
$checkbox = new \core\output\checkbox_toggleall($togglegroup, false, [
'id' => $checkboxid,
'name' => $checkboxid,
'label' => $label,
'labelclasses' => 'accesshide',
'classes' => 'itemselect ignoredirty mr-2',
]);
$checkbox = $OUTPUT->render($checkbox);
}

$itemcell->text = \html_writer::div($checkbox . $moveaction . $itemicon . $content,
"{$params['itemtype']} d-flex align-items-center");
return $itemcell;
}

/**
* Generates a toggle group name for a bulk-action checkbox based on the given grade category.
*
* @param grade_category $category The grade category.
* @return string
*/
protected function get_checkbox_togglegroup(grade_category $category): string {
$levels = [];
$categories = explode('/', $category->path);
foreach ($categories as $categoryid) {
$level = 'category' . $categoryid;
if (!in_array($level, $levels)) {
$levels[] = 'category' . $categoryid;
}
}
$togglegroup = implode(' ', $levels);

return $togglegroup;
}
}

/**
Expand Down Expand Up @@ -1089,20 +1157,37 @@ public function get_item_cell($item, $params) {
/**
* Class grade_edit_tree_column_select
*
* @deprecated Since Moodle 4.3.
* @todo Final deprecation on Moodle 4.7 MDL-77668
*
* @package core_grades
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class grade_edit_tree_column_select extends grade_edit_tree_column {

/**
* @deprecated Since Moodle 4.3.
* @todo Final deprecation on Moodle 4.7 MDL-77668
*/
public function get_header_cell() {
debugging('Method grade_edit_tree_column_select::get_header_cell() is deprecated, ' .
'please do not use it anymore.', DEBUG_DEVELOPER);

$headercell = clone($this->headercell);
$headercell->text = get_string('select');
return $headercell;
}

/**
* @deprecated Since Moodle 4.3.
* @todo Final deprecation on Moodle 4.7 MDL-77668
*/
public function get_category_cell($category, $levelclass, $params) {
global $OUTPUT;

debugging('Method grade_edit_tree_column_select::get_category_cell() is deprecated, ' .
'please do not use it anymore.', DEBUG_DEVELOPER);

if (empty($params['eid'])) {
throw new Exception('Array key (eid) missing from 3rd param of grade_edit_tree_column_select::get_category_cell($category, $levelclass, $params)');
}
Expand Down Expand Up @@ -1137,7 +1222,14 @@ public function get_category_cell($category, $levelclass, $params) {
return $categorycell;
}

/**
* @deprecated Since Moodle 4.3.
* @todo Final deprecation on Moodle 4.7 MDL-77668
*/
public function get_item_cell($item, $params) {
debugging('Method grade_edit_tree_column_select::get_item_cell() is deprecated, ' .
'please do not use it anymore.', DEBUG_DEVELOPER);

if (empty($params['itemtype']) || empty($params['eid'])) {
throw new \moodle_exception('missingitemtypeoreid', 'core_grades');
}
Expand Down Expand Up @@ -1166,10 +1258,16 @@ public function get_item_cell($item, $params) {
/**
* Generates a toggle group name for a bulk-action checkbox based on the given grade category.
*
* @deprecated Since Moodle 4.3.
* @todo Final deprecation on Moodle 4.7 MDL-77668
*
* @param grade_category $category The grade category.
* @return string
*/
protected function get_checkbox_togglegroup(grade_category $category): string {
debugging('Method grade_edit_tree_column_select::get_checkbox_togglegroup() is deprecated, ' .
'please do not use it anymore.', DEBUG_DEVELOPER);

$levels = [];
$categories = explode('/', $category->path);
foreach ($categories as $categoryid) {
Expand Down
2 changes: 1 addition & 1 deletion grade/upgrade.txt
Expand Up @@ -2,10 +2,10 @@ This file describes API changes in /grade/* ;
Information provided here is intended especially for developers.

=== 4.3 ===

* The $showtitle parameter in the print_grade_page_head function located inside grade/lib.php has been deprecated and is not used anymore.
* The deprecated `core_grades_create_gradecategory` external method has been removed, in addition to the accompanying
`core_grades_external::create_gradecategory` methods
* The grade_edit_tree_column_select class has been deprecated.

=== 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.
Expand Down
2 changes: 1 addition & 1 deletion lang/en/grades.php
Expand Up @@ -507,7 +507,7 @@
$string['minmaxupgradewarning'] = 'Note: An inconsistency has been detected with some grades due to a change in the minimum and maximum grades used when calculating the grade displayed in the gradebook. It is recommended that the inconsistency is resolved by clicking the button below, though this will result in some grades being changed.';
$string['minimum_show'] = 'Show minimum grade';
$string['minimum_show_help'] = 'Minimum grade is used in calculating grades and weights. If not shown, minimum grade will default to zero and cannot be edited.';
$string['missingitemtypeoreid'] = 'Array key (itemtype or eid) missing from 2nd param of grade_edit_tree_column_select::get_item_cell($item, $params)';
$string['missingitemtypeoreid'] = 'Array key (itemtype or eid) missing';
$string['missingscale'] = 'Scale must be selected';
$string['mode'] = 'Mode';
$string['modgrade'] = 'Grade';
Expand Down
2 changes: 0 additions & 2 deletions theme/boost/scss/moodle/grade.scss
Expand Up @@ -355,8 +355,6 @@
vertical-align: middle;

&.column-name {
padding-left: 38px;

.small {
font-size: 70%;
}
Expand Down
3 changes: 0 additions & 3 deletions theme/boost/style/moodle.css
Expand Up @@ -34951,9 +34951,6 @@ p.arrow_button {
border: none;
vertical-align: middle;
}
.path-grade-edit-tree .gradetree-wrapper .setup-grades.generaltable tr td.column-name {
padding-left: 38px;
}
.path-grade-edit-tree .gradetree-wrapper .setup-grades.generaltable tr td.column-name .small {
font-size: 70%;
}
Expand Down
3 changes: 0 additions & 3 deletions theme/classic/style/moodle.css
Expand Up @@ -34951,9 +34951,6 @@ p.arrow_button {
border: none;
vertical-align: middle;
}
.path-grade-edit-tree .gradetree-wrapper .setup-grades.generaltable tr td.column-name {
padding-left: 38px;
}
.path-grade-edit-tree .gradetree-wrapper .setup-grades.generaltable tr td.column-name .small {
font-size: 70%;
}
Expand Down

0 comments on commit 65cafd3

Please sign in to comment.