Skip to content

Commit

Permalink
Merge branch 'MDL-45847_master' of https://github.com/Syxton/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Jul 21, 2014
2 parents 724d7ab + 9a4231e commit 65f00f0
Show file tree
Hide file tree
Showing 10 changed files with 192 additions and 83 deletions.
14 changes: 12 additions & 2 deletions course/classes/management/helper.php
Expand Up @@ -221,12 +221,22 @@ public static function get_category_listitem_actions(\coursecat $category) {
$actions['resortbyname'] = array(
'url' => new \moodle_url($baseurl, array('action' => 'resortcategories', 'resort' => 'name')),
'icon' => new \pix_icon('t/sort', new \lang_string('sort')),
'string' => new \lang_string('resortsubcategoriesbyname', 'moodle')
'string' => new \lang_string('resortsubcategoriesby', 'moodle' , get_string('categoryname'))
);
$actions['resortbynamedesc'] = array(
'url' => new \moodle_url($baseurl, array('action' => 'resortcategories', 'resort' => 'namedesc')),
'icon' => new \pix_icon('t/sort', new \lang_string('sort')),
'string' => new \lang_string('resortsubcategoriesbyreverse', 'moodle', get_string('categoryname'))
);
$actions['resortbyidnumber'] = array(
'url' => new \moodle_url($baseurl, array('action' => 'resortcategories', 'resort' => 'idnumber')),
'icon' => new \pix_icon('t/sort', new \lang_string('sort')),
'string' => new \lang_string('resortsubcategoriesbyidnumber', 'moodle')
'string' => new \lang_string('resortsubcategoriesby', 'moodle', get_string('idnumbercoursecategory'))
);
$actions['resortbyidnumberdesc'] = array(
'url' => new \moodle_url($baseurl, array('action' => 'resortcategories', 'resort' => 'idnumberdesc')),
'icon' => new \pix_icon('t/sort', new \lang_string('sort')),
'string' => new \lang_string('resortsubcategoriesbyreverse', 'moodle', get_string('idnumbercoursecategory'))
);
}

Expand Down
49 changes: 41 additions & 8 deletions course/classes/management_renderer.php
Expand Up @@ -407,8 +407,10 @@ public function category_bulk_actions(coursecat $category = null) {
$form .= html_writer::div(
html_writer::select(
array(
'name' => get_string('sortcategoriesbyname'),
'idnumber' => get_string('sortcategoriesbyidnumber'),
'name' => get_string('sortbyx', 'moodle', get_string('categoryname')),
'namedesc' => get_string('sortbyxreverse', 'moodle', get_string('categoryname')),
'idnumber' => get_string('sortbyx', 'moodle', get_string('idnumbercoursecategory')),
'idnumberdesc' => get_string('sortbyxreverse' , 'moodle' , get_string('idnumbercoursecategory')),
'none' => get_string('dontsortcategories')
),
'resortcategoriesby',
Expand All @@ -420,9 +422,14 @@ public function category_bulk_actions(coursecat $category = null) {
$form .= html_writer::div(
html_writer::select(
array(
'fullname' => get_string('sortcoursesbyfullname'),
'shortname' => get_string('sortcoursesbyshortname'),
'idnumber' => get_string('sortcoursesbyidnumber'),
'fullname' => get_string('sortbyx', 'moodle', get_string('fullnamecourse')),
'fullnamedesc' => get_string('sortbyxreverse', 'moodle', get_string('fullnamecourse')),
'shortname' => get_string('sortbyx', 'moodle', get_string('shortnamecourse')),
'shortnamedesc' => get_string('sortbyxreverse', 'moodle', get_string('shortnamecourse')),
'idnumber' => get_string('sortbyx', 'moodle', get_string('idnumbercourse')),
'idnumberdesc' => get_string('sortbyxreverse', 'moodle', get_string('idnumbercourse')),
'timecreated' => get_string('sortbyx', 'moodle', get_string('timecreatedcourse')),
'timecreateddesc' => get_string('sortbyxreverse', 'moodle', get_string('timecreatedcourse')),
'none' => get_string('dontsortcourses')
),
'resortcoursesby',
Expand Down Expand Up @@ -676,12 +683,38 @@ public function course_listing_actions(coursecat $category, course_in_list $cour
$params['sesskey'] = sesskey();
$baseurl = new moodle_url('/course/management.php', $params);
$fullnameurl = new moodle_url($baseurl, array('resort' => 'fullname'));
$fullnameurldesc = new moodle_url($baseurl, array('resort' => 'fullnamedesc'));
$shortnameurl = new moodle_url($baseurl, array('resort' => 'shortname'));
$shortnameurldesc = new moodle_url($baseurl, array('resort' => 'shortnamedesc'));
$idnumberurl = new moodle_url($baseurl, array('resort' => 'idnumber'));
$idnumberdescurl = new moodle_url($baseurl, array('resort' => 'idnumberdesc'));
$timecreatedurl = new moodle_url($baseurl, array('resort' => 'timecreated'));
$timecreateddescurl = new moodle_url($baseurl, array('resort' => 'timecreateddesc'));
$menu = new action_menu(array(
new action_menu_link_secondary($fullnameurl, null, get_string('resortbyfullname')),
new action_menu_link_secondary($shortnameurl, null, get_string('resortbyshortname')),
new action_menu_link_secondary($idnumberurl, null, get_string('resortbyidnumber'))
new action_menu_link_secondary($fullnameurl,
null,
get_string('sortbyx', 'moodle', get_string('fullnamecourse'))),
new action_menu_link_secondary($fullnameurldesc,
null,
get_string('sortbyxreverse', 'moodle', get_string('fullnamecourse'))),
new action_menu_link_secondary($shortnameurl,
null,
get_string('sortbyx', 'moodle', get_string('shortnamecourse'))),
new action_menu_link_secondary($shortnameurldesc,
null,
get_string('sortbyxreverse', 'moodle', get_string('shortnamecourse'))),
new action_menu_link_secondary($idnumberurl,
null,
get_string('sortbyx', 'moodle', get_string('idnumbercourse'))),
new action_menu_link_secondary($idnumberdescurl,
null,
get_string('sortbyxreverse', 'moodle', get_string('idnumbercourse'))),
new action_menu_link_secondary($timecreatedurl,
null,
get_string('sortbyx', 'moodle', get_string('timecreatedcourse'))),
new action_menu_link_secondary($timecreateddescurl,
null,
get_string('sortbyxreverse', 'moodle', get_string('timecreatedcourse')))
));
$menu->set_menu_trigger(get_string('resortcourses'));
$actions[] = $this->render($menu);
Expand Down
3 changes: 2 additions & 1 deletion course/lib.php
Expand Up @@ -2517,7 +2517,8 @@ function create_course($data, $editoroptions = NULL) {
}
}

$data->timecreated = time();
// Check if timecreated is given.
$data->timecreated = !empty($data->timecreated) ? $data->timecreated : time();
$data->timemodified = $data->timecreated;

// place at beginning of any category
Expand Down
8 changes: 6 additions & 2 deletions course/management.php
Expand Up @@ -354,10 +354,14 @@
// They're not sorting anything.
break;
}
if (!in_array($sortcategoriesby, array('idnumber', 'name'))) {
if (!in_array($sortcategoriesby, array('idnumber', 'idnumberdesc',
'name', 'namedesc'))) {
$sortcategoriesby = false;
}
if (!in_array($sortcoursesby, array('idnumber', 'fullname', 'shortname'))) {
if (!in_array($sortcoursesby, array('timecreated', 'timecreateddesc',
'idnumber', 'idnumberdesc',
'fullname', 'fullnamedesc',
'shortname', 'shortnamedesc'))) {
$sortcoursesby = false;
}

Expand Down
24 changes: 16 additions & 8 deletions course/tests/behat/category_resort.feature
Expand Up @@ -25,8 +25,10 @@ Feature: Test we can resort categories in the management interface.

Examples:
| sortby | cat1 | cat2 | cat3 |
| "Sort categories by name" | "Applied sciences" | "Extended social studies" | "Social studies" |
| "Sort categories by ID number" | "Extended social studies" | "Social studies" | "Applied sciences" |
| "Sort by Category name ascending" | "Applied sciences" | "Extended social studies" | "Social studies" |
| "Sort by Category name descending" | "Social studies" | "Extended social studies" | "Applied sciences" |
| "Sort by Category ID number ascending" | "Extended social studies" | "Social studies" | "Applied sciences" |
| "Sort by Category ID number descending" | "Applied sciences" | "Social studies" | "Extended social studies" |

Scenario Outline: Test bulk sorting current category.
Given the following "categories" exist:
Expand All @@ -52,8 +54,10 @@ Feature: Test we can resort categories in the management interface.

Examples:
| sortby | cat1 | cat2 | cat3 |
| "Sort categories by name" | "Applied sciences" | "Extended social studies" | "Social studies" |
| "Sort categories by ID number" | "Extended social studies" | "Social studies" | "Applied sciences" |
| "Sort by Category name ascending" | "Applied sciences" | "Extended social studies" | "Social studies" |
| "Sort by Category name descending" | "Social studies" | "Extended social studies" | "Applied sciences" |
| "Sort by Category ID number ascending" | "Extended social studies" | "Social studies" | "Applied sciences" |
| "Sort by Category ID number descending" | "Applied sciences" | "Social studies" | "Extended social studies" |

Scenario Outline: Test resorting subcategories.
Given the following "categories" exist:
Expand All @@ -77,8 +81,10 @@ Feature: Test we can resort categories in the management interface.

Examples:
| sortby | cat1 | cat2 | cat3 |
| "resortbyname" | "Applied sciences" | "Extended social studies" | "Social studies" |
| "resortbyidnumber" | "Extended social studies" | "Social studies" | "Applied sciences" |
| "resortbyname" | "Applied sciences" | "Extended social studies" | "Social studies" |
| "resortbynamedesc" | "Social studies" | "Extended social studies" | "Applied sciences" |
| "resortbyidnumber" | "Extended social studies" | "Social studies" | "Applied sciences" |
| "resortbyidnumberdesc" | "Applied sciences" | "Social studies" | "Extended social studies" |

@javascript
Scenario Outline: Test resorting subcategories with JS enabled.
Expand All @@ -103,8 +109,10 @@ Feature: Test we can resort categories in the management interface.

Examples:
| sortby | cat1 | cat2 | cat3 |
| "resortbyname" | "Applied sciences" | "Extended social studies" | "Social studies" |
| "resortbyidnumber" | "Extended social studies" | "Social studies" | "Applied sciences" |
| "resortbyname" | "Applied sciences" | "Extended social studies" | "Social studies" |
| "resortbynamedesc" | "Social studies" | "Extended social studies" | "Applied sciences" |
| "resortbyidnumber" | "Extended social studies" | "Social studies" | "Applied sciences" |
| "resortbyidnumberdesc" | "Applied sciences" | "Social studies" | "Extended social studies" |

# The scenario below this is the same but with JS enabled.
Scenario: Test moving categories up and down by one.
Expand Down
48 changes: 31 additions & 17 deletions course/tests/behat/course_category_management_listing.feature
Expand Up @@ -255,8 +255,10 @@ Feature: Course category management interface performs as expected

Examples:
| sortby | cat1 | cat2 | cat3 |
| "Sort categories by name" | "Applied sciences" | "Extended social studies" | "Social studies" |
| "Sort categories by ID number" | "Extended social studies" | "Social studies" | "Applied sciences" |
| "Sort by Category name ascending" | "Applied sciences" | "Extended social studies" | "Social studies" |
| "Sort by Category name descending" | "Social studies" | "Extended social studies" | "Applied sciences" |
| "Sort by Category ID number ascending" | "Extended social studies" | "Social studies" | "Applied sciences" |
| "Sort by Category ID number descending" | "Applied sciences" | "Social studies" | "Extended social studies" |

@javascript
Scenario Outline: Sub categories are displayed correctly when resorted
Expand All @@ -281,19 +283,21 @@ Feature: Course category management interface performs as expected

Examples:
| sortby | cat1 | cat2 | cat3 |
| "resortbyname" | "Applied sciences" | "Extended social studies" | "Social studies" |
| "resortbyidnumber" | "Extended social studies" | "Social studies" | "Applied sciences" |
| "resortbyname" | "Applied sciences" | "Extended social studies" | "Social studies" |
| "resortbynamedesc" | "Social studies" | "Extended social studies" | "Applied sciences" |
| "resortbyidnumber" | "Extended social studies" | "Social studies" | "Applied sciences" |
| "resortbyidnumberdesc" | "Applied sciences" | "Social studies" | "Extended social studies" |

@javascript
Scenario Outline: Test courses are displayed correctly after being resorted.
Given the following "categories" exist:
| name | category 0| idnumber |
| Cat 1 | 0 | CAT1 |
And the following "courses" exist:
| category | fullname | shortname | idnumber | sortorder |
| CAT1 | Social studies | Senior school | Ext003 | 1 |
| CAT1 | Applied sciences | Middle school | Sci001 | 2 |
| CAT1 | Extended social studies | Junior school | Ext002 | 3 |
| category | fullname | shortname | idnumber | sortorder | timecreated |
| CAT1 | Social studies | Senior school | Ext003 | 1 | 10000000001 |
| CAT1 | Applied sciences | Middle school | Sci001 | 2 | 10000000002 |
| CAT1 | Extended social studies | Junior school | Ext002 | 3 | 10000000003 |

And I log in as "admin"
And I go to the courses management page
Expand All @@ -302,9 +306,14 @@ Feature: Course category management interface performs as expected
# Redirect.
And I should see the "Course categories and courses" management page
And I click on "Sort courses" "link"
And I should see "By fullname" in the ".course-listing-actions" "css_element"
And I should see "By shortname" in the ".course-listing-actions" "css_element"
And I should see "By idnumber" in the ".course-listing-actions" "css_element"
And I should see "Sort by Course full name ascending" in the ".course-listing-actions" "css_element"
And I should see "Sort by Course full name descending" in the ".course-listing-actions" "css_element"
And I should see "Sort by Course short name ascending" in the ".course-listing-actions" "css_element"
And I should see "Sort by Course short name descending" in the ".course-listing-actions" "css_element"
And I should see "Sort by Course ID number ascending" in the ".course-listing-actions" "css_element"
And I should see "Sort by Course ID number descending" in the ".course-listing-actions" "css_element"
And I should see "Sort by Course time created ascending" in the ".course-listing-actions" "css_element"
And I should see "Sort by Course time created descending" in the ".course-listing-actions" "css_element"
And I click on <sortby> "link" in the ".course-listing-actions" "css_element"
# Redirect.
And I should see the "Course categories and courses" management page
Expand All @@ -313,9 +322,14 @@ Feature: Course category management interface performs as expected

Examples:
| sortby | course1 | course2 | course3 |
| "By fullname" | "Applied sciences" | "Extended social studies" | "Social studies" |
| "By shortname" | "Extended social studies" | "Applied sciences" | "Social studies" |
| "By idnumber" | "Extended social studies" | "Social studies" | "Applied sciences" |
| "Sort by Course full name ascending" | "Applied sciences" | "Extended social studies" | "Social studies" |
| "Sort by Course full name descending" | "Social studies" | "Extended social studies" | "Applied sciences" |
| "Sort by Course short name ascending" | "Extended social studies" | "Applied sciences" | "Social studies" |
| "Sort by Course short name descending" | "Social studies" | "Applied sciences" | "Extended social studies" |
| "Sort by Course ID number ascending" | "Extended social studies" | "Social studies" | "Applied sciences" |
| "Sort by Course ID number descending" | "Applied sciences" | "Social studies" | "Extended social studies" |
| "Sort by Course time created ascending" | "Social studies" | "Applied sciences" | "Extended social studies" |
| "Sort by Course time created descending" | "Extended social studies" | "Applied sciences" | "Social studies" |

@javascript
Scenario: Test course pagination
Expand Down Expand Up @@ -344,7 +358,7 @@ Feature: Course category management interface performs as expected
# Redirect.
And I should see the "Course categories and courses" management page
And I click on "Sort courses" "link"
And I click on "By idnumber" "link" in the ".course-listing-actions" "css_element"
And I click on "Sort by Course ID number ascending" "link" in the ".course-listing-actions" "css_element"
# Redirect.
And I should see "Per page: 20" in the ".course-listing-actions" "css_element"
And I should see course listing "Course 1" before "Course 2"
Expand Down Expand Up @@ -527,7 +541,7 @@ Feature: Course category management interface performs as expected
# Redirect.
And I should see the "Course categories and courses" management page
And I click on "Sort courses" "link"
And I click on "By idnumber" "link" in the ".course-listing-actions" "css_element"
And I click on "Sort by Course ID number ascending" "link" in the ".course-listing-actions" "css_element"
# Redirect.
And I should see "Per page: 20" in the ".course-listing-actions" "css_element"
And I should see course listing "Course 1" before "Course 2"
Expand Down Expand Up @@ -592,7 +606,7 @@ Feature: Course category management interface performs as expected
# Redirect.
And I should see the "Course categories and courses" management page
And I click on "Sort courses" "link"
And I click on "By idnumber" "link" in the ".course-listing-actions" "css_element"
And I click on "Sort by Course ID number ascending" "link" in the ".course-listing-actions" "css_element"
# Redirect.
And I should see the "Course categories and courses" management page
And I should see "Per page: 20" in the ".course-listing-actions" "css_element"
Expand Down

0 comments on commit 65f00f0

Please sign in to comment.