Skip to content

Commit

Permalink
MDL-57250 core: show admin settings when only one category exists
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjnelson authored and danpoltawski committed Dec 13, 2016
1 parent d314123 commit 75efa08
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
Expand Up @@ -42,10 +42,6 @@ Feature: Basic recycle bin functionality
And I should see "Test assign" in the "Topic 1" "section"

Scenario: Restore a deleted course
# TODO MDL-57250 remove extra category.
Given the following "categories" exist:
| name | idnumber |
| There is a bug with navigation and we need an extra category | CAT1 |
Given I log in as "admin"
And I go to the courses management page
And I click on "delete" action for "Course 2" in management course listing
Expand All @@ -54,7 +50,7 @@ Feature: Basic recycle bin functionality
And I should see "C2 has been completely deleted"
And I press "Continue"
And I am on course index
And I follow "Miscellaneous"
And I should see "Course 1"
And I should not see "Course 2"
When I navigate to "Recycle bin" in current page administration
Then I should see "Course 2"
Expand Down
13 changes: 11 additions & 2 deletions course/index.php
Expand Up @@ -37,9 +37,18 @@
// And the object has been loaded for us no need for another DB call
$category = $PAGE->category;
} else {
$categoryid = 0;
// Check if there is only one category, if so use that.
if (coursecat::count_all() == 1) {
$category = coursecat::get_default();

$categoryid = $category->id;
$PAGE->set_category_by_id($categoryid);
$PAGE->set_pagetype('course-index-category');
} else {
$PAGE->set_context(context_system::instance());
}

$PAGE->set_url('/course/index.php');
$PAGE->set_context(context_system::instance());
}

$PAGE->set_pagelayout('coursecategory');
Expand Down
20 changes: 13 additions & 7 deletions course/renderer.php
Expand Up @@ -1554,15 +1554,21 @@ public function course_category($category) {
$this->page->set_title("$site->shortname: $strcategories");
}
} else {
$this->page->set_title("$site->shortname: ". $coursecat->get_formatted_name());
$title = $site->shortname;
if (coursecat::count_all() > 1) {
$title .= ": ". $coursecat->get_formatted_name();
}
$this->page->set_title($title);

// Print the category selector
$output .= html_writer::start_tag('div', array('class' => 'categorypicker'));
$select = new single_select(new moodle_url('/course/index.php'), 'categoryid',
coursecat::make_categories_list(), $coursecat->id, null, 'switchcategory');
$select->set_label(get_string('categories').':');
$output .= $this->render($select);
$output .= html_writer::end_tag('div'); // .categorypicker
if (coursecat::count_all() > 1) {
$output .= html_writer::start_tag('div', array('class' => 'categorypicker'));
$select = new single_select(new moodle_url('/course/index.php'), 'categoryid',
coursecat::make_categories_list(), $coursecat->id, null, 'switchcategory');
$select->set_label(get_string('categories').':');
$output .= $this->render($select);
$output .= html_writer::end_tag('div'); // .categorypicker
}
}

// Print current category description
Expand Down

0 comments on commit 75efa08

Please sign in to comment.