### Eclipse Workspace Patch 1.0
#P ou-moodle
Index: course/courselib.php
===================================================================
RCS file: course/courselib.php
diff -N course/courselib.php
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ course/courselib.php 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,254 @@
+parent));
+ if ($cattomove->parent != $move_cat_id) {
+ $newparent = get_record('course_categories', 'id', $move_cat_id);
+ require_capability('moodle/category:manage', get_category_or_system_context($move_cat_id));
+ if (!move_category($cattomove, $newparent)) {
+ notify('Could not update that category!');
+ }
+ }
+ }
+}
+
+/**
+ * Changes the visibility of the given category as long as the user has
+ * moodle/category:manage on the given categories parent category or system
+ * @param int $cat_id category id for category to move
+ * @param int $visible the new visibility
+ */
+function category_change_visibility($cat_id, $visible=0) {
+ if ($category = get_record('course_categories', 'id', $cat_id)) {
+ require_capability('moodle/category:manage', get_category_or_system_context($category->parent));
+ if (! set_field('course_categories', 'visible', $visible, 'id', $category->id)) {
+ notify('Could not update that category!');
+ }
+// ou-specific begins
+ else {
+ set_field("course_categories", "timemodified", time(), "id", $category->id);
+ }
+// ou-specific ends
+ if (! set_field('course', 'visible', $visible, 'category', $category->id)) {
+ notify('Could not hide/show any courses in this category !');
+ }
+ }
+}
+
+/*
+ * Helper function for category_change_visibility, just looks cleaner in code
+ * @param int $cat_id category id for category to move
+ */
+function category_hide($cat_id) {
+ category_change_visibility($cat_id, 0);
+}
+
+/*
+ * Helper function for category_change_visibility, just looks cleaner in code
+ * @param int $cat_id category id for category to move
+ */
+function category_show($cat_id) {
+ category_change_visibility($cat_id, 1);
+}
+
+/**
+ * Move the category up or down within it's parent category as long as the user
+ * has moodle/category:manage on the given category
+ * @param int $cat_id category id for category to move
+ * @param string $type only allows 'up' or 'down'.
+ */
+function category_move($cat_id, $type) {
+ switch($type) {
+ 'up':
+ 'down':
+ break;
+ default:
+ print_error('Unknown category move type.');
+ break;
+ }
+
+ $swapcategory = NULL;
+ $movecategory = NULL;
+
+ require_capability('moodle/category:manage', get_context_instance(CONTEXT_COURSECAT, $cat_id));
+ if ($movecategory = get_record('course_categories', 'id', $cat_id)) {
+ $categories = get_categories($movecategory->parent);
+
+ $choosenext = false;
+
+ foreach ($categories as $category) {
+ if($choosenext) {
+ $swapcategory = $category;
+ break;
+ }
+ if ($category->id == $movecategory->id) {
+ if($type == 'down') {
+ $choosenext = true;
+ } else {
+ break;
+ }
+ }
+ if($type == 'up') {
+ $swapcategory = $category;
+ }
+ }
+ unset($category);
+ }
+ // Renumber everything for robustness
+ if ($swapcategory && $movecategory) {
+ $count = 0;
+ foreach ($categories as $category) {
+ $count++;
+ if ($category->id == $swapcategory->id) {
+ $category = $movecategory;
+ } else if ($category->id == $movecategory->id) {
+ $category = $swapcategory;
+ }
+ if (! set_field('course_categories', 'sortorder', $count, 'id', $category->id)) {
+ notify('Could not update that category!');
+ }
+ }
+ unset($category);
+ }
+}
+
+/*
+ * Helper function for category_move, just looks cleaner in code
+ * @param int $cat_id category id for category to move up
+ */
+function category_move_up($cat_id) {
+ category_move($cat_id, 'up');
+}
+
+/*
+ * Helper function for category_move, just looks cleaner in code
+ * @param int $cat_id category id for category to move down
+ */
+function category_move_down($cat_id) {
+ category_move($cat_id, 'down');
+}
+
+/*
+ * Recursive function to print all the categories ready for editing
+ */
+function print_category_edit($category, $displaylist, $parentslist, $depth=-1, $up=false, $down=false) {
+ global $CFG, $USER;
+
+ static $str = NULL;
+
+ if (is_null($str)) {
+ $str = new stdClass;
+ $str->edit = get_string('edit');
+ $str->delete = get_string('delete');
+ $str->moveup = get_string('moveup');
+ $str->movedown = get_string('movedown');
+ $str->edit = get_string('editthiscategory');
+ $str->hide = get_string('hide');
+ $str->show = get_string('show');
+ $str->spacer = '
';
+ }
+
+ if (!empty($category)) {
+
+ if (!isset($category->context)) {
+ $category->context = get_context_instance(CONTEXT_COURSECAT, $category->id);
+ }
+
+ echo '
';
+
+ echo '
';
+
+ if (!empty($category->visible)) {
+ echo '
';
+ } else {
+ echo '
';
+ }
+
+ if ($up) {
+ echo '
';
+ } else {
+ echo $str->spacer;
+ }
+ if ($down) {
+ echo '
';
+ } else {
+ echo $str->spacer;
+ }
+ }
+ echo '
';
- }
-
- if (!empty($category)) {
-
- if (!isset($category->context)) {
- $category->context = get_context_instance(CONTEXT_COURSECAT, $category->id);
- }
-
- echo '
';
-
- echo '
';
-
- if (!empty($category->visible)) {
- echo '
';
- } else {
- echo '
';
- }
-
- if ($up) {
- echo '
';
- } else {
- echo $str->spacer;
- }
- if ($down) {
- echo '
';
- } else {
- echo $str->spacer;
- }
- }
- echo '