Merge branch 'wip-MDL-47542-master' of git://github.com/marinaglancy/moodle

This commit is contained in:
Damyon Wiese
2014-10-24 11:49:19 +02:00
committed by Eloy Lafuente (stronk7)
6 changed files with 142 additions and 78 deletions
+22 -9
View File
@@ -109,7 +109,7 @@ class grade_edit_tree {
* @return string HTML
*/
public function build_html_tree($element, $totals, $parents, $level, &$row_count) {
global $CFG, $COURSE, $USER, $OUTPUT;
global $CFG, $COURSE, $PAGE, $OUTPUT;
$object = $element['object'];
$eid = $element['eid'];
@@ -126,30 +126,41 @@ class grade_edit_tree {
$rowclasses[] = $parent_eid;
}
$actions = '';
$moveaction = '';
$actionsmenu = new action_menu();
$actionsmenu->initialise_js($PAGE);
$actionsmenu->set_menu_trigger(get_string('edit'));
$actionsmenu->set_owner_selector('grade-item-' . $eid);
$actionsmenu->set_alignment(action_menu::TL, action_menu::BL);
if (!$is_category_item) {
$actions .= $this->gtree->get_edit_icon($element, $this->gpr);
if (!$is_category_item && ($icon = $this->gtree->get_edit_icon($element, $this->gpr, true))) {
$actionsmenu->add($icon);
}
if ($this->show_calculations) {
$actions .= $this->gtree->get_calculation_icon($element, $this->gpr);
if ($this->show_calculations && ($icon = $this->gtree->get_calculation_icon($element, $this->gpr, true))) {
$actionsmenu->add($icon);
}
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()));
$actions .= $OUTPUT->action_icon($aurl, new pix_icon('t/delete', get_string('delete')));
$icon = new action_menu_link_secondary($aurl, new pix_icon('t/delete', get_string('delete')), get_string('delete'));
$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')));
}
$actions .= $this->gtree->get_hiding_icon($element, $this->gpr);
if ($icon = $this->gtree->get_hiding_icon($element, $this->gpr, true)) {
$actionsmenu->add($icon);
}
$actions .= $this->gtree->get_reset_icon($element, $this->gpr);
if ($icon = $this->gtree->get_reset_icon($element, $this->gpr, true)) {
$actionsmenu->add($icon);
}
$actions = $OUTPUT->render($actionsmenu);
$returnrows = array();
$root = false;
@@ -279,6 +290,7 @@ class grade_edit_tree {
}
$row = new html_table_row();
$row->id = 'grade-item-' . $eid;
$row->attributes['class'] = $courseclass . ' category ' . $dimmed;
foreach ($rowclasses as $class) {
$row->attributes['class'] .= ' ' . $class;
@@ -327,6 +339,7 @@ class grade_edit_tree {
$dimmed = ($item->is_hidden()) ? "dimmed_text" : "";
$gradeitemrow = new html_table_row();
$gradeitemrow->id = 'grade-item-' . $eid;
$gradeitemrow->attributes['class'] = $categoryitemclass . ' item ' . $dimmed;
foreach ($rowclasses as $class) {
$gradeitemrow->attributes['class'] .= ' ' . $class;
+49 -23
View File
@@ -1564,16 +1564,17 @@ class grade_structure {
*
* @param array $element An array representing an element in the grade_tree
* @param object $gpr A grade_plugin_return object
* @return string
* @param bool $returnactionmenulink return the instance of action_menu_link instead of string
* @return string|action_menu_link
*/
public function get_reset_icon($element, $gpr) {
public function get_reset_icon($element, $gpr, $returnactionmenulink = false) {
global $CFG, $OUTPUT;
// Limit to category items set to use the natural weights aggregation method, and users
// with the capability to manage grades.
if ($element['type'] != 'category' || $element['object']->aggregation != GRADE_AGGREGATE_SUM ||
!has_capability('moodle/grade:manage', $this->context)) {
return '';
return $returnactionmenulink ? null : '';
}
$str = get_string('resetweights', 'grades', $this->get_params_for_iconstr($element));
@@ -1584,7 +1585,12 @@ class grade_structure {
'sesskey' => sesskey(),
));
return $OUTPUT->action_icon($gpr->add_url_params($url), new pix_icon('t/reset', $str));
if ($returnactionmenulink) {
return new action_menu_link_secondary($gpr->add_url_params($url), new pix_icon('t/reset', $str),
get_string('resetweightsshort', 'grades'));
} else {
return $OUTPUT->action_icon($gpr->add_url_params($url), new pix_icon('t/reset', $str));
}
}
/**
@@ -1592,17 +1598,17 @@ class grade_structure {
*
* @param array $element An array representing an element in the grade_tree
* @param object $gpr A grade_plugin_return object
*
* @return string
* @param bool $returnactionmenulink return the instance of action_menu_link instead of string
* @return string|action_menu_link
*/
public function get_edit_icon($element, $gpr) {
public function get_edit_icon($element, $gpr, $returnactionmenulink = false) {
global $CFG, $OUTPUT;
if (!has_capability('moodle/grade:manage', $this->context)) {
if ($element['type'] == 'grade' and has_capability('moodle/grade:edit', $this->context)) {
// oki - let them override grade
} else {
return '';
return $returnactionmenulink ? null : '';
}
}
@@ -1656,10 +1662,16 @@ class grade_structure {
}
if ($url) {
return $OUTPUT->action_icon($gpr->add_url_params($url), new pix_icon('t/edit', $stredit));
if ($returnactionmenulink) {
return new action_menu_link_secondary($gpr->add_url_params($url),
new pix_icon('t/edit', $stredit),
get_string('editsettings'));
} else {
return $OUTPUT->action_icon($gpr->add_url_params($url), new pix_icon('t/edit', $stredit));
}
} else {
return '';
return $returnactionmenulink ? null : '';
}
}
@@ -1668,19 +1680,19 @@ class grade_structure {
*
* @param array $element An array representing an element in the grade_tree
* @param object $gpr A grade_plugin_return object
*
* @return string
* @param bool $returnactionmenulink return the instance of action_menu_link instead of string
* @return string|action_menu_link
*/
public function get_hiding_icon($element, $gpr) {
public function get_hiding_icon($element, $gpr, $returnactionmenulink = false) {
global $CFG, $OUTPUT;
if (!$element['object']->can_control_visibility()) {
return '';
return $returnactionmenulink ? null : '';
}
if (!has_capability('moodle/grade:manage', $this->context) and
!has_capability('moodle/grade:hide', $this->context)) {
return '';
return $returnactionmenulink ? null : '';
}
$strparams = $this->get_params_for_iconstr($element);
@@ -1703,11 +1715,19 @@ class grade_structure {
$url->param('action', 'show');
$hideicon = $OUTPUT->action_icon($url, new pix_icon('t/'.$type, $tooltip, 'moodle', array('alt'=>$strshow, 'class'=>'smallicon')));
if ($returnactionmenulink) {
$hideicon = new action_menu_link_secondary($url, new pix_icon('t/'.$type, $tooltip), get_string('show'));
} else {
$hideicon = $OUTPUT->action_icon($url, new pix_icon('t/'.$type, $tooltip, 'moodle', array('alt'=>$strshow, 'class'=>'smallicon')));
}
} else {
$url->param('action', 'hide');
$hideicon = $OUTPUT->action_icon($url, new pix_icon('t/hide', $strhide));
if ($returnactionmenulink) {
$hideicon = new action_menu_link_secondary($url, new pix_icon('t/hide', $strhide), get_string('hide'));
} else {
$hideicon = $OUTPUT->action_icon($url, new pix_icon('t/hide', $strhide));
}
}
return $hideicon;
@@ -1775,13 +1795,13 @@ class grade_structure {
*
* @param array $element An array representing an element in the grade_tree
* @param object $gpr A grade_plugin_return object
*
* @return string
* @param bool $returnactionmenulink return the instance of action_menu_link instead of string
* @return string|action_menu_link
*/
public function get_calculation_icon($element, $gpr) {
public function get_calculation_icon($element, $gpr, $returnactionmenulink = false) {
global $CFG, $OUTPUT;
if (!has_capability('moodle/grade:manage', $this->context)) {
return '';
return $returnactionmenulink ? null : '';
}
$type = $element['type'];
@@ -1804,11 +1824,17 @@ class grade_structure {
$url = new moodle_url('/grade/edit/tree/calculation.php', array('courseid' => $this->courseid, 'id' => $object->id));
$url = $gpr->add_url_params($url);
return $OUTPUT->action_icon($url, new pix_icon($icon, $streditcalculation));
if ($returnactionmenulink) {
return new action_menu_link_secondary($url,
new pix_icon($icon, $streditcalculation),
get_string('editcalculation', 'grades'));
} else {
return $OUTPUT->action_icon($url, new pix_icon($icon, $streditcalculation));
}
}
}
return '';
return $returnactionmenulink ? null : '';
}
}
+41 -6
View File
@@ -59,14 +59,49 @@ class behat_grade extends behat_base {
* @return Given[]
*/
public function i_set_the_following_settings_for_grade_item($gradeitem, TableNode $data) {
$steps = array();
$gradeitem = $this->getSession()->getSelectorsHandler()->xpathLiteral($gradeitem);
if ($this->running_javascript()) {
$xpath = "//tr[contains(.,$gradeitem)]//*[contains(@class,'moodle-actionmenu')]//a[contains(@class,'toggle-display')]";
if ($this->getSession()->getPage()->findAll('xpath', $xpath)) {
$steps[] = new Given('I click on "' . $this->escape($xpath) . '" "xpath_element"');
}
}
$savechanges = get_string('savechanges', 'grades');
$edit = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('edit') . ' ');
$gradeitem = $this->getSession()->getSelectorsHandler()->xpathLiteral($gradeitem);
$linkxpath = "//a[./img[starts-with(@title,$edit) and contains(@title,$gradeitem)]]";
return array(
new Given('I click on "' . $this->escape($linkxpath) . '" "xpath_element"'),
new Given('I set the following fields to these values:', $data),
new Given('I press "' . $this->escape($savechanges) . '"'),
);
$steps[] = new Given('I click on "' . $this->escape($linkxpath) . '" "xpath_element"');
$steps[] = new Given('I set the following fields to these values:', $data);
$steps[] = new Given('I press "' . $this->escape($savechanges) . '"');
return $steps;
}
/**
* Resets the weights for the grade category
*
* Teacher must be on the grade setup page.
*
* @Given /^I reset weights for grade category "(?P<grade_item_string>(?:[^"]|\\")*)"$/
* @param $gradeitem
* @return array
*/
public function i_reset_weights_for_grade_category($gradeitem) {
$steps = array();
if ($this->running_javascript()) {
$gradeitemliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($gradeitem);
$xpath = "//tr[contains(.,$gradeitemliteral)]//*[contains(@class,'moodle-actionmenu')]//a[contains(@class,'toggle-display')]";
if ($this->getSession()->getPage()->findAll('xpath', $xpath)) {
$steps[] = new Given('I click on "' . $this->escape($xpath) . '" "xpath_element"');
}
}
$linktext = get_string('resetweights', 'grades', (object)array('itemname' => $gradeitem));
$steps[] = new Given('I click on "' . $this->escape($linktext) . '" "link"');
return $steps;
}
}
+7 -10
View File
@@ -502,15 +502,12 @@ Feature: We can use calculated grade totals
@javascript
Scenario: Natural aggregation from the setup screen
And I set the field "Grade report" to "Categories and items"
And I follow "Edit Course 1"
And I set the field "Aggregation" to "Natural"
And I press "Save changes"
And I follow "Edit Sub category 1"
And I set the field "Aggregation" to "Natural"
And I press "Save changes"
And I follow "Edit Sub category 2"
And I set the field "Aggregation" to "Natural"
And I press "Save changes"
And I set the following settings for grade item "Course 1":
| Aggregation | Natural |
And I set the following settings for grade item "Sub category 1":
| Aggregation | Natural |
And I set the following settings for grade item "Sub category 2":
| Aggregation | Natural |
And I set the field "Override weight of Test assignment one" to "1"
And the field "Weight of Test assignment one" matches value "37.975"
@@ -551,7 +548,7 @@ Feature: We can use calculated grade totals
And I set the field "Override weight of Sub category 1" to "1"
And the field "Weight of Test assignment one" matches value "37.975"
And the field "Weight of Sub category 1" matches value "5.696"
And I click on "Reset weights of Sub category 2" "link"
And I reset weights for grade category "Sub category 2"
And the field "Weight of Test assignment ten" matches value "33.333"
@javascript
@@ -99,9 +99,8 @@ Feature: We can use natural aggregation and weights will be normalised to a tota
@javascript
Scenario: Grade items weights are normalised when all grade item weights are overridden (sum exactly 100). Extra credit is set to zero.
When I follow "Edit assign Test assignment seven"
And I set the field "Extra credit" to "1"
And I press "Save changes"
When I set the following settings for grade item "Test assignment seven":
| Extra credit | 1 |
And the field "Weight of Test assignment five" matches value "66.667"
And the field "Weight of Test assignment six" matches value "33.333"
And the field "Weight of Test assignment seven" matches value "50.0"
@@ -115,7 +114,7 @@ Feature: We can use natural aggregation and weights will be normalised to a tota
And the field "Weight of Test assignment five" matches value "60.000"
And the field "Weight of Test assignment six" matches value "40.000"
And the field "Weight of Test assignment seven" matches value "0.0"
And I follow "Reset weights of Sub category 1"
And I reset weights for grade category "Sub category 1"
And the field "Weight of Test assignment five" matches value "66.667"
And the field "Weight of Test assignment six" matches value "33.333"
And the field "Weight of Test assignment seven" matches value "50.0"
@@ -123,9 +122,8 @@ Feature: We can use natural aggregation and weights will be normalised to a tota
@javascript
Scenario: Grade items weights are normalised when all grade item weights are overridden (sum over 100). Extra credit is set to zero.
When I follow "Edit assign Test assignment seven"
And I set the field "Extra credit" to "1"
And I press "Save changes"
When I set the following settings for grade item "Test assignment seven":
| Extra credit | 1 |
And I set the field "Override weight of Test assignment five" to "1"
And I set the field "Override weight of Test assignment six" to "1"
And I set the field "Weight of Test assignment five" to "60"
@@ -136,7 +134,7 @@ Feature: We can use natural aggregation and weights will be normalised to a tota
And the field "Weight of Test assignment five" matches value "54.545"
And the field "Weight of Test assignment six" matches value "45.455"
And the field "Weight of Test assignment seven" matches value "0.0"
And I follow "Reset weights of Sub category 1"
And I reset weights for grade category "Sub category 1"
And the field "Weight of Test assignment five" matches value "66.667"
And the field "Weight of Test assignment six" matches value "33.333"
And the field "Weight of Test assignment seven" matches value "50.0"
@@ -144,9 +142,8 @@ Feature: We can use natural aggregation and weights will be normalised to a tota
@javascript
Scenario: Grade items weights are normalised when all grade item weights are overridden (sum under 100). Extra credit is set to zero.
When I follow "Edit assign Test assignment seven"
And I set the field "Extra credit" to "1"
And I press "Save changes"
When I set the following settings for grade item "Test assignment seven":
| Extra credit | 1 |
And I set the field "Override weight of Test assignment five" to "1"
And I set the field "Override weight of Test assignment six" to "1"
And I set the field "Weight of Test assignment five" to "40"
@@ -157,7 +154,7 @@ Feature: We can use natural aggregation and weights will be normalised to a tota
And the field "Weight of Test assignment five" matches value "57.143"
And the field "Weight of Test assignment six" matches value "42.857"
And the field "Weight of Test assignment seven" matches value "0.0"
And I follow "Reset weights of Sub category 1"
And I reset weights for grade category "Sub category 1"
And the field "Weight of Test assignment five" matches value "66.667"
And the field "Weight of Test assignment six" matches value "33.333"
And the field "Weight of Test assignment seven" matches value "50.0"
@@ -165,9 +162,8 @@ Feature: We can use natural aggregation and weights will be normalised to a tota
@javascript
Scenario: Grade items weights are normalised when not all grade item weights are overridden. Extra credit is set respectful to non-overridden items.
When I follow "Edit assign Test assignment seven"
And I set the field "Extra credit" to "1"
And I press "Save changes"
When I set the following settings for grade item "Test assignment seven":
| Extra credit | 1 |
And I set the field "Override weight of Test assignment five" to "1"
And I set the field "Weight of Test assignment five" to "40"
And I press "Save changes"
@@ -176,7 +172,7 @@ Feature: We can use natural aggregation and weights will be normalised to a tota
And the field "Weight of Test assignment five" matches value "40.00"
And the field "Weight of Test assignment six" matches value "60.000"
And the field "Weight of Test assignment seven" matches value "90.0"
And I follow "Reset weights of Sub category 1"
And I reset weights for grade category "Sub category 1"
And the field "Weight of Test assignment five" matches value "66.667"
And the field "Weight of Test assignment six" matches value "33.333"
And the field "Weight of Test assignment seven" matches value "50.0"
@@ -185,9 +181,8 @@ Feature: We can use natural aggregation and weights will be normalised to a tota
Scenario: The extra credit grade item weight is overridden to a figure over one hundred and then
the grade item is set to normal.
When I follow "Edit assign Test assignment seven"
And I set the field "Extra credit" to "1"
And I press "Save changes"
When I set the following settings for grade item "Test assignment seven":
| Extra credit | 1 |
And I set the field "Override weight of Test assignment seven" to "1"
And I set the field "Weight of Test assignment seven" to "105"
And I press "Save changes"
@@ -195,9 +190,8 @@ Feature: We can use natural aggregation and weights will be normalised to a tota
And the field "Weight of Test assignment five" matches value "66.667"
And the field "Weight of Test assignment six" matches value "33.333"
And the field "Weight of Test assignment seven" matches value "105.0"
And I follow "Edit assign Test assignment seven"
And I set the field "Extra credit" to "0"
And I press "Save changes"
When I set the following settings for grade item "Test assignment seven":
| Extra credit | 0 |
And I should see "Your weights have been adjusted to total 100."
And the field "Weight of Test assignment five" matches value "0.0"
@@ -208,14 +202,13 @@ Feature: We can use natural aggregation and weights will be normalised to a tota
Scenario: The extra credit grade item weight is overridden to a figure over one hundred and then
the grade category is reset.
When I follow "Edit assign Test assignment seven"
And I set the field "Extra credit" to "1"
And I press "Save changes"
When I set the following settings for grade item "Test assignment seven":
| Extra credit | 1 |
And I set the field "Override weight of Test assignment seven" to "1"
And I set the field "Weight of Test assignment seven" to "105"
And I press "Save changes"
And I follow "Reset weights of Sub category 1"
And I reset weights for grade category "Sub category 1"
And the field "Weight of Test assignment five" matches value "66.667"
And the field "Weight of Test assignment six" matches value "33.333"
And the field "Weight of Test assignment seven" matches value "50.0"
@@ -238,15 +231,14 @@ Feature: We can use natural aggregation and weights will be normalised to a tota
@javascript
Scenario: With one grade item set as extra credit, when I reset the weights for a category they return to the natural weights.
When I follow "Edit assign Test assignment five"
And I set the field "Extra credit" to "1"
And I press "Save changes"
When I set the following settings for grade item "Test assignment five":
| Extra credit | 1 |
And I set the field "Override weight of Test assignment six" to "1"
And I set the field "Override weight of Test assignment seven" to "1"
And I set the field "Weight of Test assignment six" to "55"
And I set the field "Weight of Test assignment seven" to "40"
And I press "Save changes"
And I follow "Reset weights of Sub category 1"
And I reset weights for grade category "Sub category 1"
Then the field "Weight of Test assignment five" matches value "80.0"
And the field "Weight of Test assignment six" matches value "40.0"
And the field "Weight of Test assignment seven" matches value "60.0"
+1
View File
@@ -576,6 +576,7 @@ $string['reportdefault'] = 'Report default ({$a})';
$string['reportplugins'] = 'Report plugins';
$string['reportsettings'] = 'Report settings';
$string['reprintheaders'] = 'Reprint headers';
$string['resetweightsshort'] = 'Reset weights';
$string['resetweights'] = 'Reset weights of {$a->itemname}';
$string['respectingcurrentdata'] = 'leaving current configuration unmodified';
$string['rowpreviewnum'] = 'Preview rows';