2 // This file is part of Moodle - http://moodle.org/
4 // Moodle is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // Moodle is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 * Performs course category management ajax actions.
20 * Please note functions may throw exceptions, please ensure your JS handles them as well as the outcome objects.
22 * @package core_course
23 * @copyright 2013 Sam Hemelryk
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27 define('AJAX_SCRIPT', true);
29 require_once('../../config.php');
30 require_once($CFG->dirroot
.'/lib/coursecatlib.php');
31 require_once($CFG->dirroot
.'/course/lib.php');
33 $action = required_param('action', PARAM_ALPHA
);
34 require_sesskey(); // Gotta have the sesskey.
35 require_login(); // Gotta be logged in (of course).
36 $PAGE->set_context(context_system
::instance());
38 // Prepare an outcome object. We always use this.
39 $outcome = new stdClass
;
40 $outcome->error
= false;
41 $outcome->outcome
= false;
43 echo $OUTPUT->header();
47 $courseid = required_param('courseid', PARAM_INT
);
48 $outcome->outcome
= \core_course\management\helper
::action_course_change_sortorder_up_one_by_record($courseid);
50 case 'movecoursedown' :
51 $courseid = required_param('courseid', PARAM_INT
);
52 $outcome->outcome
= \core_course\management\helper
::action_course_change_sortorder_down_one_by_record($courseid);
54 case 'movecourseintocategory':
55 $courseid = required_param('courseid', PARAM_INT
);
56 $categoryid = required_param('categoryid', PARAM_INT
);
57 $outcome->outcome
= \core_course\management\helper
::move_courses_into_category($categoryid, $courseid);
59 case 'movecourseafter' :
60 $courseid = required_param('courseid', PARAM_INT
);
61 $moveaftercourseid = required_param('moveafter', PARAM_INT
);
62 $outcome->outcome
= \core_course\management\helper
::action_course_change_sortorder_after_course(
63 $courseid, $moveaftercourseid);
66 $courseid = required_param('courseid', PARAM_INT
);
67 $outcome->outcome
= \core_course\management\helper
::action_course_hide_by_record($courseid);
70 $courseid = required_param('courseid', PARAM_INT
);
71 $outcome->outcome
= \core_course\management\helper
::action_course_show_by_record($courseid);
73 case 'movecategoryup' :
74 $categoryid = required_param('categoryid', PARAM_INT
);
75 $outcome->outcome
= \core_course\management\helper
::action_category_change_sortorder_up_one_by_id($categoryid);
77 case 'movecategorydown' :
78 $categoryid = required_param('categoryid', PARAM_INT
);
79 $outcome->outcome
= \core_course\management\helper
::action_category_change_sortorder_down_one_by_id($categoryid);
82 $categoryid = required_param('categoryid', PARAM_INT
);
83 $selectedcategoryid = optional_param('selectedcategory', null, PARAM_INT
);
84 $outcome->outcome
= \core_course\management\helper
::action_category_hide_by_id($categoryid);
85 $outcome->categoryvisibility
= \core_course\management\helper
::get_category_children_visibility($categoryid);
86 $outcome->coursevisibility
= \core_course\management\helper
::get_category_courses_visibility($categoryid);
87 if ($selectedcategoryid !== null) {
88 $outcome->coursevisibility
= array_merge(
89 $outcome->coursevisibility
,
90 \core_course\management\helper
::get_category_courses_visibility($selectedcategoryid)
95 $categoryid = required_param('categoryid', PARAM_INT
);
96 $selectedcategoryid = optional_param('selectedcategory', null, PARAM_INT
);
97 $outcome->outcome
= \core_course\management\helper
::action_category_show_by_id($categoryid);
98 $outcome->categoryvisibility
= \core_course\management\helper
::get_category_children_visibility($categoryid);
99 $outcome->coursevisibility
= \core_course\management\helper
::get_category_courses_visibility($categoryid);
100 if ($selectedcategoryid !== null) {
101 $outcome->coursevisibility
= array_merge(
102 $outcome->coursevisibility
,
103 \core_course\management\helper
::get_category_courses_visibility($selectedcategoryid)
107 case 'getsubcategorieshtml' :
108 $categoryid = required_param('categoryid', PARAM_INT
);
109 /* @var core_course_management_renderer $renderer */
110 $renderer = $PAGE->get_renderer('core_course', 'management');
111 $outcome->html
= html_writer
::start_tag('ul', array('class' => 'ml'));
112 $coursecat = coursecat
::get($categoryid);
113 foreach ($coursecat->get_children() as $subcat) {
114 $outcome->html
.= $renderer->category_listitem($subcat, array(), $subcat->get_children_count());
116 $outcome->html
.= html_writer
::end_tag('ul');
117 $outcome->outcome
= true;
121 echo json_encode($outcome);
122 echo $OUTPUT->footer();
124 // Don't ever even consider putting anything after this. It just wouldn't make sense.
125 // But you already knew that, you smart developer you.