Skip to content

Commit

Permalink
Merge branch 'wip-MDL-42318-master' of https://github.com/marinaglanc…
Browse files Browse the repository at this point in the history
  • Loading branch information
Damyon Wiese committed Nov 5, 2013
2 parents 82d305f + d3bd747 commit 1ddbe78
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions course/classes/management_renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public function category_listitem(coursecat $category, array $subcategories, $to
}
$countid = 'course-count-'.$category->id;
$html .= html_writer::span(get_string('courses'), 'accesshide', array('id' => $countid));
$html .= html_writer::span($category->coursecount.$courseicon, 'course-count dimmed', array('aria-labelledby' => $countid));
$html .= html_writer::span($category->get_courses_count().$courseicon, 'course-count dimmed', array('aria-labelledby' => $countid));
$html .= html_writer::end_div();
$html .= html_writer::end_div();
if ($isexpanded) {
Expand Down Expand Up @@ -477,7 +477,7 @@ public function course_listing(coursecat $category = null, course_in_list $cours
*/
protected function listing_pagination(coursecat $category, $page, $perpage, $showtotals = false) {
$html = '';
$totalcourses = $category->coursecount;
$totalcourses = $category->get_courses_count();
$totalpages = ceil($totalcourses / $perpage);
if ($showtotals) {
if ($totalpages == 0) {
Expand Down
6 changes: 6 additions & 0 deletions course/tests/management_helper_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,9 @@ public function test_action_category_resort_courses() {
'shortname' => 'Advanced algebra', 'idnumber' => '10002'));
$syscontext = context_system::instance();

// Update category object from DB so the course count is correct.
$category = coursecat::get($category->id);

list($user, $roleid) = $this->get_user_objects($generator, $syscontext->id);
$caps = course_capability_assignment::allow(self::CATEGORY_MANAGE, $roleid, $syscontext->id);

Expand Down Expand Up @@ -991,6 +994,9 @@ public function test_action_course_movedown_and_moveup() {
$course1 = $generator->create_course(array('category' => $category->id));
$context = $category->get_context();

// Update category object from DB so the course count is correct.
$category = coursecat::get($category->id);

list($user, $roleid) = $this->get_user_objects($generator, $context->id);
$caps = course_capability_assignment::allow(self::CATEGORY_MANAGE, $roleid, $context->id);

Expand Down
10 changes: 6 additions & 4 deletions lib/coursecatlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2293,26 +2293,28 @@ public function can_create_subcategory() {

/**
* Returns true if the user can resort this categories sub categories and courses.
* Must have manage capability and be able to see all subcategories.
* @return bool
*/
public function can_resort_subcategories() {
return $this->has_manage_capability();
return $this->has_manage_capability() && !$this->get_not_visible_children_ids();
}

/**
* Returns true if the user can resort the courses within this category.
* Must have manage capability and be able to see all courses.
* @return bool
*/
public function can_resort_courses() {
return $this->has_manage_capability();
return $this->has_manage_capability() && $this->coursecount == $this->get_courses_count();
}

/**
* Returns true of the user can change the sortorder of this category (resort the parent category)
* Returns true of the user can change the sortorder of this category (resort in the parent category)
* @return bool
*/
public function can_change_sortorder() {
return $this->parent_has_manage_capability();
return $this->id && $this->get_parent_coursecat()->can_resort_subcategories();
}

/**
Expand Down

0 comments on commit 1ddbe78

Please sign in to comment.