Skip to content

Commit

Permalink
Merge branch 'wip-MDL-41127-m25' of git://github.com/marinaglancy/moo…
Browse files Browse the repository at this point in the history
…dle into MOODLE_25_STABLE
  • Loading branch information
Damyon Wiese committed Aug 27, 2013
2 parents 0d376b0 + b471509 commit 01209ab
Showing 1 changed file with 29 additions and 9 deletions.
38 changes: 29 additions & 9 deletions course/manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@
require_once($CFG->dirroot.'/course/lib.php');
require_once($CFG->libdir.'/coursecatlib.php');

/**
* Limit the total number of categories where user has 'moodle/course:manage'
* permission in order for "Move categories" dropdown to be displayed on this page.
* If number of categories exceeds this limit, user can always use edit category
* form to change the parent. Otherwise the page size becomes too big.
*/
if (!defined('COURSECAT_QUICKMOVE_LIMIT')) {
define('COURSECAT_QUICKMOVE_LIMIT', 200);
}

// Category id.
$id = optional_param('categoryid', 0, PARAM_INT);
// Which page to show.
Expand Down Expand Up @@ -322,24 +332,30 @@
echo $OUTPUT->heading(new lang_string('searchresults'));
} else if (!$coursecat->id) {
// Print out the categories with all the knobs.
$manageablecategories = coursecat::make_categories_list('moodle/category:manage');
$displaymovecategoryto = !empty($manageablecategories) && (count($manageablecategories) <= COURSECAT_QUICKMOVE_LIMIT);
$table = new html_table;
$table->id = 'coursecategories';
$table->attributes['class'] = 'admintable generaltable editcourse';
$table->head = array(
get_string('categories'),
get_string('courses'),
get_string('edit'),
get_string('movecategoryto'),
);
if ($displaymovecategoryto) {
$table->head[] = get_string('movecategoryto');
}
$table->colclasses = array(
'leftalign name',
'centeralign count',
'centeralign icons',
'leftalign actions'
);
if ($displaymovecategoryto) {
$table->colclasses[] = 'leftalign actions';
}
$table->data = array();

print_category_edit($table, $coursecat);
print_category_edit($table, $coursecat, -1, false, false, $displaymovecategoryto);

echo html_writer::table($table);
} else {
Expand Down Expand Up @@ -627,8 +643,9 @@
* @param int $depth The depth of the category.
* @param bool $up True if this category can be moved up.
* @param bool $down True if this category can be moved down.
* @param bool $displaymovecategoryto whether to display a dropdown for quick category move.
*/
function print_category_edit(html_table $table, coursecat $category, $depth = -1, $up = false, $down = false) {
function print_category_edit(html_table $table, coursecat $category, $depth = -1, $up = false, $down = false, $displaymovecategoryto = true) {
global $OUTPUT;

static $str = null;
Expand Down Expand Up @@ -716,24 +733,27 @@ function print_category_edit(html_table $table, coursecat $category, $depth = -1
}

$actions = '';
if (has_capability('moodle/category:manage', $categorycontext)) {
if ($displaymovecategoryto && has_capability('moodle/category:manage', $categorycontext)) {
$popupurl = new moodle_url('/course/manage.php', array('movecat' => $category->id, 'sesskey' => sesskey()));
$tempdisplaylist = array(0 => get_string('top')) + coursecat::make_categories_list('moodle/category:manage', $category->id);
$select = new single_select($popupurl, 'movetocat', $tempdisplaylist, $category->parent, null, "moveform$category->id");
$select->set_label(get_string('frontpagecategorynames'), array('class' => 'accesshide'));
$actions = $OUTPUT->render($select);
}

$table->data[] = new html_table_row(array(
$thisrowdata = array(
// Category name.
new html_table_cell($categoryname),
// Course count.
new html_table_cell($category->coursecount),
// Icons.
new html_table_cell(join(' ', $icons)),
);
if ($displaymovecategoryto) {
// Actions.
new html_table_cell($actions)
));
$thisrowdata[] = new html_table_cell($actions);
}
$table->data[] = new html_table_row($thisrowdata);
}

if ($categories = $category->get_children()) {
Expand All @@ -751,7 +771,7 @@ function print_category_edit(html_table $table, coursecat $category, $depth = -1
$down = $last ? false : true;
$first = false;

print_category_edit($table, $cat, $depth+1, $up, $down);
print_category_edit($table, $cat, $depth+1, $up, $down, $displaymovecategoryto);
}
}
}

0 comments on commit 01209ab

Please sign in to comment.