Skip to content

Commit

Permalink
Merge branch 'MDL-77033-master-3' of https://github.com/ilyatregubov/…
Browse files Browse the repository at this point in the history
  • Loading branch information
snake committed Mar 31, 2023
2 parents e541732 + 51182b6 commit aeb7763
Show file tree
Hide file tree
Showing 54 changed files with 1,265 additions and 1,208 deletions.
16 changes: 8 additions & 8 deletions admin/tool/behat/tests/behat/data_generators.feature
Expand Up @@ -330,22 +330,22 @@ Feature: Set up contextual data for tests
And I am on "Course 1" course homepage
And I navigate to "Setup > Gradebook setup" in the course gradebook
Then I should see "Test Grade Item 1"
And I open the action menu in "Test Grade Item 1" "table_row"
And I choose "Edit" in the open action menu
And I click on grade item menu "Test Grade Item 1" of type "gradeitem" on "setup" page
And I choose "Edit grade item" in the open action menu
And I expand all fieldsets
And I should see "Course 1"
And I press "Cancel"
And I should see "Grade category 1"
And I should see "Test Grade Item 2"
And I open the action menu in "Test Grade Item 2" "table_row"
And I choose "Edit" in the open action menu
And I click on grade item menu "Test Grade Item 2" of type "gradeitem" on "setup" page
And I choose "Edit grade item" in the open action menu
And I expand all fieldsets
And I should see "Grade category 1"
And I press "Cancel"
And I should see "Grade sub category 2"
And I should see "Test Grade Item 3"
And I open the action menu in "Test Grade Item 3" "table_row"
And I choose "Edit" in the open action menu
And I click on grade item menu "Test Grade Item 3" of type "gradeitem" on "setup" page
And I choose "Edit grade item" in the open action menu
And I expand all fieldsets
And I should see "Grade sub category 2"
And I press "Cancel"
Expand Down Expand Up @@ -410,8 +410,8 @@ Feature: Set up contextual data for tests
And I am on "Course 1" course homepage
And I navigate to "Setup > Gradebook setup" in the course gradebook
Then I should see "Test Outcome Grade Item 1"
And I open the action menu in "Test Outcome Grade Item 1" "table_row"
And I choose "Edit" in the open action menu
And I click on grade item menu "Test Outcome Grade Item 1" of type "gradeitem" on "setup" page
And I choose "Edit grade item" in the open action menu
And the field "Outcome" matches value "Grade outcome 1"
And I expand all fieldsets
And I should see "Grade category 1" in the "Grade category" "form_row"
Expand Down
Expand Up @@ -59,7 +59,7 @@ Feature: Students will be shown relevant completion state based on grade item vi
Scenario: Passing grade and receive a grade completions for hidden grade item (passgrade completion enabled)
Given I am on the "Course 1" course page logged in as teacher1
And I navigate to "Setup > Gradebook setup" in the course gradebook
And I hide the grade item "Test assignment name"
And I hide the grade item "Test assignment name" of type "gradeitem" on "setup" page
And I navigate to "View > Grader report" in the course gradebook
And I turn editing mode on
And I give the grade "21" to the user "Student First" for the grade item "Test assignment name"
Expand Down Expand Up @@ -119,7 +119,7 @@ Feature: Students will be shown relevant completion state based on grade item vi
And I log out
And I am on the "Course 1" course page logged in as teacher1
And I navigate to "Setup > Gradebook setup" in the course gradebook
And I hide the grade item "Test assignment name"
And I hide the grade item "Test assignment name" of type "gradeitem" on "setup" page
And I navigate to "View > Grader report" in the course gradebook
And I turn editing mode on
And I give the grade "21" to the user "Student First" for the grade item "Test assignment name"
Expand Down
4 changes: 1 addition & 3 deletions grade/edit/tree/index.php
Expand Up @@ -247,7 +247,7 @@

$actionbar = new \core_grades\output\gradebook_setup_action_bar($context);
print_grade_page_head($courseid, 'settings', 'setup', get_string('gradebooksetup', 'grades'),
false, false, true, null, null, null, $actionbar);
false, false, true, null, null, null, $actionbar, false);

// Print Table of categories and items
echo $OUTPUT->box_start('gradetreebox generalbox');
Expand Down Expand Up @@ -292,5 +292,3 @@

echo $OUTPUT->footer();
die;


137 changes: 87 additions & 50 deletions grade/edit/tree/lib.php
Expand Up @@ -66,6 +66,7 @@ public function __construct($gtree, $moving, $gpr) {
}

$this->columns[] = grade_edit_tree_column::factory('range'); // This is not a setting... How do we deal with it?
$this->columns[] = grade_edit_tree_column::factory('status');
$this->columns[] = grade_edit_tree_column::factory('actions');

if ($this->deepest_level > 1) {
Expand Down Expand Up @@ -104,7 +105,7 @@ public function build_html_tree($element, $totals, $parents, $level, &$row_count

$object = $element['object'];
$eid = $element['eid'];
$object->name = $this->gtree->get_element_header($element, true, false, true, true, true);
$object->name = $this->gtree->get_element_header($element, true, false, true, false, true);
$object->icon = $this->gtree->get_element_icon($element);
$object->type = $this->gtree->get_element_type_string($element);
$object->stripped_name = $this->gtree->get_element_header($element, false, false, false);
Expand All @@ -119,54 +120,13 @@ public function build_html_tree($element, $totals, $parents, $level, &$row_count
}

$moveaction = '';
$actionsmenu = new action_menu();
$actionsmenu->set_menu_trigger($OUTPUT->pix_icon('i/moremenu', get_string('actions')), 'actions');
$actionsmenu->set_owner_selector('grade-item-' . $eid);

if (!$is_category_item && ($icon = $this->gtree->get_edit_icon($element, $this->gpr, true))) {
$actionsmenu->add($icon);
}
// MDL-49281 if grade_item already has calculation, it should be editable even if global setting is off.
$type = $element['type'];
$iscalculated = ($type == 'item' or $type == 'courseitem' or $type == 'categoryitem') && $object->is_calculated();
$icon = $this->gtree->get_calculation_icon($element, $this->gpr, true);
if ($iscalculated || $icon) {
$actionsmenu->add($icon);
}
$actions = $this->gtree->get_cell_action_menu($element, 'setup', $this->gpr);

if ($element['type'] == 'item' or ($element['type'] == 'category' and $element['depth'] > 1)) {
if ($this->element_deletable($element)) {
$aurl = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'delete', 'eid' => $eid, 'sesskey' => sesskey()));
$icon = new action_menu_link_secondary($aurl, new pix_icon('t/delete', get_string('delete')), get_string('delete'));
$actionsmenu->add($icon);
}

if ($this->element_duplicatable($element)) {
$duplicateparams = array();
$duplicateparams['id'] = $COURSE->id;
$duplicateparams['action'] = 'duplicate';
$duplicateparams['eid'] = $eid;
$duplicateparams['sesskey'] = sesskey();
$aurl = new moodle_url('index.php', $duplicateparams);
$duplicateicon = new pix_icon('t/copy', get_string('duplicate'));
$icon = new action_menu_link_secondary($aurl, $duplicateicon, get_string('duplicate'));
$actionsmenu->add($icon);
}

$aurl = new moodle_url('index.php', array('id' => $COURSE->id, 'action' => 'moveselect', 'eid' => $eid, 'sesskey' => sesskey()));
$moveaction .= $OUTPUT->action_icon($aurl, new pix_icon('t/move', get_string('move')));
}

if ($icon = $this->gtree->get_hiding_icon($element, $this->gpr, true)) {
$actionsmenu->add($icon);
}

if ($icon = $this->gtree->get_reset_icon($element, $this->gpr, true)) {
$actionsmenu->add($icon);
}

$actions = $OUTPUT->render($actionsmenu);

$returnrows = array();
$root = false;

Expand Down Expand Up @@ -205,8 +165,6 @@ public function build_html_tree($element, $totals, $parents, $level, &$row_count
$item = $category->get_grade_item();

// Add aggregation coef input if not a course item and if parent category has correct aggregation type
$dimmed = ($item->is_hidden()) ? 'dimmed_text' : '';

// Before we print the category's row, we must find out how many rows will appear below it (for the filler cell's rowspan)
$aggregation_position = grade_get_setting($COURSE->id, 'aggregationposition', $CFG->grade_aggregationposition);
$category_total_data = null; // Used if aggregationposition is set to "last", so we can print it last
Expand Down Expand Up @@ -315,7 +273,7 @@ public function build_html_tree($element, $totals, $parents, $level, &$row_count

$categoryrow = new html_table_row();
$categoryrow->id = 'grade-item-' . $eid;
$categoryrow->attributes['class'] = $courseclass . ' category ' . $dimmed;
$categoryrow->attributes['class'] = $courseclass . ' category ';
$categoryrow->attributes['data-category'] = $eid;
$categoryrow->attributes['data-itemid'] = $category->get_grade_item()->id;
$categoryrow->attributes['data-hidden'] = 'false';
Expand Down Expand Up @@ -373,10 +331,9 @@ public function build_html_tree($element, $totals, $parents, $level, &$row_count
$categoryitemclass = 'courseitem';
}

$dimmed = ($item->is_hidden()) ? "dimmed_text" : "";
$gradeitemrow = new html_table_row();
$gradeitemrow->id = 'grade-item-' . $eid;
$gradeitemrow->attributes['class'] = $categoryitemclass . ' item ' . $dimmed;
$gradeitemrow->attributes['class'] = $categoryitemclass . ' item ';
$gradeitemrow->attributes['data-itemid'] = $object->id;
$gradeitemrow->attributes['data-hidden'] = 'false';
// If this item is a course or category aggregation, add a data attribute that stores the identifier of
Expand Down Expand Up @@ -486,7 +443,7 @@ static function format_number($number) {
* @param array $element
* @return bool
*/
function element_deletable($element) {
public static function element_deletable($element) {
global $COURSE;

if ($element['type'] != 'item') {
Expand Down Expand Up @@ -514,7 +471,7 @@ function element_deletable($element) {
* @param array $element
* @return bool
*/
public function element_duplicatable($element) {
public static function element_duplicatable($element) {
if ($element['type'] != 'item') {
return false;
}
Expand Down Expand Up @@ -1010,6 +967,86 @@ public function get_item_cell($item, $params) {
}
}

/**
* Class grade_edit_tree_column_status
*
* @package core_grades
* @copyright 2023 Ilya Tregubov <ilya@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class grade_edit_tree_column_status extends grade_edit_tree_column {

/**
* Get status column header cell
* @return html_table_cell status column header cell
*/
public function get_header_cell() {
$headercell = clone($this->headercell);
$headercell->text = get_string('status');
return $headercell;
}

/**
* Get category cell in status column
*
* @param grade_category $category grade category
* @param string $levelclass Category level info
* @param array $params Params (category id, action performed etc)
* @return html_table_cell category cell in status columns
*/
public function get_category_cell($category, $levelclass, $params) {
global $OUTPUT, $gtree;
$categorycell = parent::get_category_cell($category, $levelclass, $params);
$element = [];
$element['object'] = $category;
$categorycell->text = $gtree->set_grade_status_icons($element);

// Aggregation type.
$aggrstrings = grade_helper::get_aggregation_strings();
$context = new stdClass();
$context->aggregation = $aggrstrings[$category->aggregation];

// Include/exclude empty grades.
if ($category->aggregateonlygraded) {
$context->aggregateonlygraded = $category->aggregateonlygraded;
}

// Aggregate outcomes.
if ($category->aggregateoutcomes) {
$context->aggregateoutcomes = $category->aggregateoutcomes;
}

// Drop the lowest.
if ($category->droplow) {
$context->droplow = $category->droplow;
}

// Keep the highest.
if ($category->keephigh) {
$context->keephigh = $category->keephigh;
}
$categorycell->text .= $OUTPUT->render_from_template('core_grades/category_settings', $context);
return $categorycell;
}

/**
* Get category cell in status column
*
* @param grade_item $item grade item
* @param array $params Params
* @return html_table_cell item cell in status columns
*/
public function get_item_cell($item, $params) {
global $gtree;

$element = [];
$element['object'] = $item;
$itemcell = parent::get_item_cell($item, $params);
$itemcell->text = $gtree->set_grade_status_icons($element);
return $itemcell;
}
}

/**
* Class grade_edit_tree_column_actions
*
Expand Down

0 comments on commit aeb7763

Please sign in to comment.