Merge branch 'wip-MDL-62742-master' of git://github.com/marinaglancy/moodle
This commit is contained in:
@@ -434,7 +434,7 @@ class core_role_define_role_table_advanced extends core_role_capability_table_wi
|
||||
}
|
||||
|
||||
public function save_changes() {
|
||||
global $DB, $CFG;
|
||||
global $DB;
|
||||
|
||||
if (!$this->roleid) {
|
||||
// Creating role.
|
||||
@@ -448,8 +448,7 @@ class core_role_define_role_table_advanced extends core_role_capability_table_wi
|
||||
// the UI. It would be better to do this only when we know that fields affected are
|
||||
// updated. But thats getting into the weeds of the coursecat cache and role edits
|
||||
// should not be that frequent, so here is the ugly brutal approach.
|
||||
require_once($CFG->libdir . '/coursecatlib.php');
|
||||
coursecat::role_assignment_changed($this->role->id, context_system::instance());
|
||||
core_course_category::role_assignment_changed($this->role->id, context_system::instance());
|
||||
}
|
||||
|
||||
// Assignable contexts.
|
||||
|
||||
@@ -35,8 +35,6 @@ use tool_dataprivacy\context_instance;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->libdir . '/coursecatlib.php');
|
||||
|
||||
/**
|
||||
* Data registry business logic methods. Mostly internal stuff.
|
||||
*
|
||||
@@ -113,17 +111,17 @@ class data_registry {
|
||||
/**
|
||||
* Returns all site categories that are visible to the current user.
|
||||
*
|
||||
* @return \coursecat[]
|
||||
* @return \core_course_category[]
|
||||
*/
|
||||
public static function get_site_categories() {
|
||||
global $DB;
|
||||
|
||||
if (method_exists('\coursecat', 'get_all')) {
|
||||
$categories = \coursecat::get_all(['returnhidden' => true]);
|
||||
if (method_exists('\core_course_category', 'get_all')) {
|
||||
$categories = \core_course_category::get_all(['returnhidden' => true]);
|
||||
} else {
|
||||
// Fallback (to be removed once this gets integrated into master).
|
||||
$ids = $DB->get_fieldset_select('course_categories', 'id', '');
|
||||
$categories = \coursecat::get_many($ids);
|
||||
$categories = \core_course_category::get_many($ids);
|
||||
}
|
||||
|
||||
foreach ($categories as $key => $category) {
|
||||
|
||||
@@ -30,7 +30,6 @@ use stdClass;
|
||||
use templatable;
|
||||
use tool_dataprivacy\data_registry;
|
||||
|
||||
require_once($CFG->libdir . '/coursecatlib.php');
|
||||
require_once($CFG->dirroot . '/' . $CFG->admin . '/tool/dataprivacy/lib.php');
|
||||
require_once($CFG->libdir . '/blocklib.php');
|
||||
|
||||
@@ -226,7 +225,7 @@ class data_registry_page implements renderable, templatable {
|
||||
throw new \coding_exception('A course category context should be provided');
|
||||
}
|
||||
|
||||
$coursecat = \coursecat::get($catcontext->instanceid);
|
||||
$coursecat = \core_course_category::get($catcontext->instanceid);
|
||||
$courses = $coursecat->get_courses();
|
||||
|
||||
$branches = [];
|
||||
|
||||
@@ -96,7 +96,7 @@ class tool_recyclebin_category_bin_tests extends advanced_testcase {
|
||||
$this->assertEquals(1, $DB->count_records('tool_recyclebin_category'));
|
||||
|
||||
// Now let's delete the course category.
|
||||
$category = coursecat::get($this->course->category);
|
||||
$category = core_course_category::get($this->course->category);
|
||||
$category->delete_full(false);
|
||||
|
||||
// Check that the course was deleted from the category recycle bin.
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
require_once($CFG->libdir . '/coursecatlib.php');
|
||||
require_once($CFG->dirroot . '/cache/lib.php');
|
||||
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
|
||||
require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
|
||||
@@ -379,7 +378,7 @@ class tool_uploadcourse_helper {
|
||||
$catid = null;
|
||||
|
||||
if (!empty($data['category'])) {
|
||||
$category = coursecat::get((int) $data['category'], IGNORE_MISSING);
|
||||
$category = core_course_category::get((int) $data['category'], IGNORE_MISSING);
|
||||
if (!empty($category) && !empty($category->id)) {
|
||||
$catid = $category->id;
|
||||
} else {
|
||||
|
||||
@@ -82,7 +82,7 @@ class tool_uploadcourse_step2_form extends tool_uploadcourse_base_form {
|
||||
$mform->addElement('header', 'defaultheader', get_string('defaultvalues', 'tool_uploadcourse'));
|
||||
$mform->setExpanded('defaultheader', true);
|
||||
|
||||
$displaylist = coursecat::make_categories_list('moodle/course:create');
|
||||
$displaylist = core_course_category::make_categories_list('moodle/course:create');
|
||||
$mform->addElement('select', 'defaults[category]', get_string('coursecategory'), $displaylist);
|
||||
$mform->addHelpButton('defaults[category]', 'coursecategory');
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ define('CLI_SCRIPT', true);
|
||||
|
||||
require(__DIR__ . '/../../../../config.php');
|
||||
require_once($CFG->libdir . '/clilib.php');
|
||||
require_once($CFG->libdir . '/coursecatlib.php');
|
||||
require_once($CFG->libdir . '/csvlib.class.php');
|
||||
|
||||
$courseconfig = get_config('moodlecourse');
|
||||
@@ -46,7 +45,7 @@ list($options, $unrecognized) = cli_get_params(array(
|
||||
'allowrenames' => false,
|
||||
'allowresets' => false,
|
||||
'reset' => false,
|
||||
'category' => coursecat::get_default()->id,
|
||||
'category' => core_course_category::get_default()->id,
|
||||
),
|
||||
array(
|
||||
'h' => 'help',
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
|
||||
require(__DIR__ . '/../../../config.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
require_once($CFG->libdir . '/coursecatlib.php');
|
||||
require_once($CFG->libdir . '/csvlib.class.php');
|
||||
|
||||
admin_externalpage_setup('tooluploadcourse');
|
||||
|
||||
@@ -52,7 +52,7 @@ class category extends base {
|
||||
* And whose values are the values to display
|
||||
*/
|
||||
public static function get_filter_options() {
|
||||
$options = \coursecat::make_categories_list();
|
||||
$options = \core_course_category::make_categories_list();
|
||||
return $options;
|
||||
}
|
||||
|
||||
|
||||
@@ -81,8 +81,7 @@ class award_criteria_courseset extends award_criteria {
|
||||
// Get courses with enabled completion.
|
||||
$courses = $DB->get_records('course', array('enablecompletion' => COMPLETION_ENABLED));
|
||||
if (!empty($courses)) {
|
||||
require_once($CFG->libdir . '/coursecatlib.php');
|
||||
$list = coursecat::make_categories_list();
|
||||
$list = core_course_category::make_categories_list();
|
||||
|
||||
$select = array();
|
||||
$selected = array();
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
*/
|
||||
|
||||
include_once($CFG->dirroot . '/course/lib.php');
|
||||
include_once($CFG->libdir . '/coursecatlib.php');
|
||||
|
||||
class block_course_list extends block_list {
|
||||
function init() {
|
||||
@@ -76,7 +75,7 @@ class block_course_list extends block_list {
|
||||
}
|
||||
}
|
||||
|
||||
$categories = coursecat::get(0)->get_children(); // Parent = 0 ie top-level categories only
|
||||
$categories = core_course_category::get(0)->get_children(); // Parent = 0 ie top-level categories only
|
||||
if ($categories) { //Check we have categories
|
||||
if (count($categories) > 1 || (count($categories) == 1 && $DB->count_records('course') > 200)) { // Just print top level category links
|
||||
foreach ($categories as $category) {
|
||||
|
||||
@@ -65,7 +65,6 @@ class courses_view implements renderable, templatable {
|
||||
public function export_for_template(renderer_base $output) {
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot.'/course/lib.php');
|
||||
require_once($CFG->dirroot.'/lib/coursecatlib.php');
|
||||
|
||||
// Build courses view data structure.
|
||||
$coursesview = [
|
||||
@@ -84,7 +83,7 @@ class courses_view implements renderable, templatable {
|
||||
// Convert summary to plain text.
|
||||
$exportedcourse->summary = content_to_text($exportedcourse->summary, $exportedcourse->summaryformat);
|
||||
|
||||
$course = new \course_in_list($course);
|
||||
$course = new \core_course_list_element($course);
|
||||
foreach ($course->get_course_overviewfiles() as $file) {
|
||||
$isimage = $file->is_valid_image();
|
||||
if ($isimage) {
|
||||
|
||||
@@ -126,7 +126,7 @@ class container {
|
||||
|
||||
if (!empty($dbrow->categoryid)) {
|
||||
// This is a category event. Check that the category is visible to this user.
|
||||
$category = \coursecat::get($dbrow->categoryid, IGNORE_MISSING, true, $requestinguserid);
|
||||
$category = \core_course_category::get($dbrow->categoryid, IGNORE_MISSING, true, $requestinguserid);
|
||||
|
||||
if (empty($category) || !$category->is_uservisible($requestinguserid)) {
|
||||
return true;
|
||||
|
||||
@@ -33,8 +33,6 @@ use core_calendar\local\event\factories\action_factory_interface;
|
||||
use core_calendar\local\event\factories\event_factory_interface;
|
||||
use core_calendar\local\event\strategies\raw_event_retrieval_strategy_interface;
|
||||
|
||||
require_once($CFG->libdir . '/coursecatlib.php');
|
||||
|
||||
/**
|
||||
* Event vault class.
|
||||
*
|
||||
|
||||
@@ -36,8 +36,6 @@ use core_calendar\local\event\value_objects\event_description;
|
||||
use core_calendar\local\event\value_objects\event_times;
|
||||
use core_calendar\local\event\entities\event_interface;
|
||||
|
||||
require_once($CFG->libdir . '/coursecatlib.php');
|
||||
|
||||
/**
|
||||
* Abstract factory for creating calendar events.
|
||||
*
|
||||
|
||||
@@ -90,7 +90,7 @@ trait eventtype {
|
||||
|
||||
if (!empty($eventtypes['category'])) {
|
||||
$categoryoptions = [];
|
||||
foreach (\coursecat::make_categories_list('moodle/category:manage') as $id => $category) {
|
||||
foreach (\core_course_category::make_categories_list('moodle/category:manage') as $id => $category) {
|
||||
$categoryoptions[$id] = $category;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,8 +26,6 @@ namespace core_calendar\local\event\proxies;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->libdir . '/coursecatlib.php');
|
||||
|
||||
/**
|
||||
* Course category proxy.
|
||||
*
|
||||
@@ -48,7 +46,7 @@ class coursecat_proxy implements proxy_interface {
|
||||
protected $base;
|
||||
|
||||
/**
|
||||
* @var \coursecat $category The proxied instance.
|
||||
* @var \core_course_category $category The proxied instance.
|
||||
*/
|
||||
protected $category;
|
||||
|
||||
@@ -81,11 +79,11 @@ class coursecat_proxy implements proxy_interface {
|
||||
/**
|
||||
* Get the full instance of the proxied class.
|
||||
*
|
||||
* @return \coursecat
|
||||
* @return \core_course_category
|
||||
*/
|
||||
public function get_proxied_instance() : \coursecat {
|
||||
public function get_proxied_instance() : \core_course_category {
|
||||
if (!$this->category) {
|
||||
$this->category = \coursecat::get($this->id, IGNORE_MISSING, true);
|
||||
$this->category = \core_course_category::get($this->id, IGNORE_MISSING, true);
|
||||
}
|
||||
return $this->category;
|
||||
}
|
||||
|
||||
@@ -242,7 +242,8 @@ class core_calendar_external extends external_api {
|
||||
$categories = [];
|
||||
|
||||
if (!empty($params['events']['categoryids'])) {
|
||||
$catobjs = \coursecat::get_many(array_merge($params['events']['categoryids'], array_keys($coursecategories)));
|
||||
$catobjs = \core_course_category::get_many(
|
||||
array_merge($params['events']['categoryids'], array_keys($coursecategories)));
|
||||
foreach ($catobjs as $catobj) {
|
||||
if (isset($coursecategories[$catobj->id]) ||
|
||||
has_capability('moodle/category:manage', $catobj->get_context())) {
|
||||
@@ -267,7 +268,7 @@ class core_calendar_external extends external_api {
|
||||
$categories = array_flip($categories);
|
||||
} else {
|
||||
$categories = [];
|
||||
foreach (\coursecat::get_all() as $category) {
|
||||
foreach (\core_course_category::get_all() as $category) {
|
||||
if (isset($coursecategories[$category->id]) ||
|
||||
has_capability('moodle/category:manage', $category->get_context(), $USER, false)) {
|
||||
// If the user has access to a course in this category or can manage the category,
|
||||
|
||||
+9
-11
@@ -27,8 +27,6 @@ if (!defined('MOODLE_INTERNAL')) {
|
||||
die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
|
||||
}
|
||||
|
||||
require_once($CFG->libdir . '/coursecatlib.php');
|
||||
|
||||
/**
|
||||
* These are read by the administration component to provide default values
|
||||
*/
|
||||
@@ -805,7 +803,7 @@ class calendar_event {
|
||||
$this->editoroptions['maxbytes'] = $course->maxbytes;
|
||||
} else if ($properties->eventtype === 'category') {
|
||||
// First check the course is valid.
|
||||
\coursecat::get($properties->categoryid, MUST_EXIST, true);
|
||||
\core_course_category::get($properties->categoryid, MUST_EXIST, true);
|
||||
// Course context.
|
||||
$this->editorcontext = $this->get_context();
|
||||
} else {
|
||||
@@ -1067,14 +1065,14 @@ class calendar_information {
|
||||
}
|
||||
|
||||
$courses = [$course->id => $course];
|
||||
$category = (\coursecat::get($course->category, MUST_EXIST, true))->get_db_record();
|
||||
$category = (\core_course_category::get($course->category, MUST_EXIST, true))->get_db_record();
|
||||
} else if (!empty($categoryid)) {
|
||||
$course = get_site();
|
||||
$courses = calendar_get_default_courses(null, 'id, category, groupmode, groupmodeforce');
|
||||
|
||||
// Filter available courses to those within this category or it's children.
|
||||
$ids = [$categoryid];
|
||||
$category = \coursecat::get($categoryid);
|
||||
$category = \core_course_category::get($categoryid);
|
||||
$ids = array_merge($ids, array_keys($category->get_children()));
|
||||
$courses = array_filter($courses, function($course) use ($ids) {
|
||||
return array_search($course->category, $ids) !== false;
|
||||
@@ -1158,7 +1156,7 @@ class calendar_information {
|
||||
// A specific course was requested.
|
||||
// Fetch the category that this course is in, along with all parents.
|
||||
// Do not include child categories of this category, as the user many not have enrolments in those siblings or children.
|
||||
$category = \coursecat::get($course->category, MUST_EXIST, true);
|
||||
$category = \core_course_category::get($course->category, MUST_EXIST, true);
|
||||
$this->categoryid = $category->id;
|
||||
|
||||
$this->categories = $category->get_parents();
|
||||
@@ -1166,7 +1164,7 @@ class calendar_information {
|
||||
} else if (null !== $category && $category->id > 0) {
|
||||
// A specific category was requested.
|
||||
// Fetch all parents of this category, along with all children too.
|
||||
$category = \coursecat::get($category->id);
|
||||
$category = \core_course_category::get($category->id);
|
||||
$this->categoryid = $category->id;
|
||||
|
||||
// Build the category list.
|
||||
@@ -1188,7 +1186,7 @@ class calendar_information {
|
||||
if ($this->categories === false) {
|
||||
// Use the category id as the key in the following array. That way we do not have to remove duplicates.
|
||||
$categories = [];
|
||||
foreach (\coursecat::get_all() as $category) {
|
||||
foreach (\core_course_category::get_all() as $category) {
|
||||
if (isset($coursecategories[$category->id]) ||
|
||||
has_capability('moodle/category:manage', $category->get_context(), $USER, false)) {
|
||||
// If the user has access to a course in this category or can manage the category,
|
||||
@@ -2177,7 +2175,7 @@ function calendar_view_event_allowed(calendar_event $event) {
|
||||
return isset($mycourses[$courseid]);
|
||||
} else if ($event->categoryid) {
|
||||
// If this is a category we need to be able to see the category.
|
||||
$cat = \coursecat::get($event->categoryid, IGNORE_MISSING);
|
||||
$cat = \core_course_category::get($event->categoryid, IGNORE_MISSING);
|
||||
if (!$cat) {
|
||||
return false;
|
||||
}
|
||||
@@ -3147,7 +3145,7 @@ function calendar_can_edit_subscription($subscriptionorid) {
|
||||
$category = null;
|
||||
|
||||
if (!empty($categoryid)) {
|
||||
$category = \coursecat::get($categoryid);
|
||||
$category = \core_course_category::get($categoryid);
|
||||
}
|
||||
calendar_get_allowed_types($allowed, $courseid, null, $category);
|
||||
switch ($subscription->eventtype) {
|
||||
@@ -3693,7 +3691,7 @@ function calendar_get_allowed_event_types(int $courseid = null) {
|
||||
if (has_capability('moodle/calendar:manageownentries', \context_system::instance())) {
|
||||
$types['user'] = true;
|
||||
}
|
||||
if (coursecat::has_manage_capability_on_any()) {
|
||||
if (core_course_category::has_manage_capability_on_any()) {
|
||||
$types['category'] = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -154,7 +154,7 @@ if ($usedefaultfilters) {
|
||||
|
||||
if (!empty($types['category'])) {
|
||||
list($categoryinsql, $categoryparams) = $DB->get_in_or_equal(
|
||||
array_keys(\coursecat::make_categories_list('moodle/category:manage')), SQL_PARAMS_NAMED, 'category');
|
||||
array_keys(\core_course_category::make_categories_list('moodle/category:manage')), SQL_PARAMS_NAMED, 'category');
|
||||
$searches[] = "(eventtype = 'category' AND categoryid {$categoryinsql})";
|
||||
$params += $categoryparams;
|
||||
}
|
||||
|
||||
@@ -293,7 +293,7 @@ class calendar_information_testcase extends advanced_testcase {
|
||||
$generator = $this->getDataGenerator();
|
||||
$user = $generator->create_user();
|
||||
$course = $courses['A1.1'];
|
||||
$category = \coursecat::get($course->category);
|
||||
$category = \core_course_category::get($course->category);
|
||||
$wrongcategory = $categories['B1'];
|
||||
$generator->enrol_user($user->id, $course->id);
|
||||
|
||||
@@ -329,7 +329,7 @@ class calendar_information_testcase extends advanced_testcase {
|
||||
$generator = $this->getDataGenerator();
|
||||
$user = $generator->create_user();
|
||||
$course = $courses['A1.1'];
|
||||
$category = \coursecat::get($course->category);
|
||||
$category = \core_course_category::get($course->category);
|
||||
$wrongcategory = $categories['B1'];
|
||||
$generator->enrol_user($user->id, $course->id);
|
||||
|
||||
@@ -378,7 +378,7 @@ class calendar_information_testcase extends advanced_testcase {
|
||||
$generator = $this->getDataGenerator();
|
||||
$user = $generator->create_user();
|
||||
$course = $courses['A1.1'];
|
||||
$category = \coursecat::get($course->category);
|
||||
$category = \core_course_category::get($course->category);
|
||||
$generator->enrol_user($user->id, $course->id);
|
||||
|
||||
$this->setUser($user);
|
||||
@@ -419,7 +419,7 @@ class calendar_information_testcase extends advanced_testcase {
|
||||
$generator = $this->getDataGenerator();
|
||||
$user = $generator->create_user();
|
||||
$course = $courses['A1.1'];
|
||||
$category = \coursecat::get($course->category);
|
||||
$category = \core_course_category::get($course->category);
|
||||
$generator->enrol_user($user->id, $course->id);
|
||||
|
||||
$this->setUser($user);
|
||||
@@ -503,7 +503,7 @@ class calendar_information_testcase extends advanced_testcase {
|
||||
$generator = $this->getDataGenerator();
|
||||
$user = $generator->create_user();
|
||||
$course = $courses['A1.1'];
|
||||
$category = \coursecat::get($course->category);
|
||||
$category = \core_course_category::get($course->category);
|
||||
$wrongcategory = $categories['B1'];
|
||||
$generator->enrol_user($user->id, $course->id);
|
||||
|
||||
@@ -540,7 +540,7 @@ class calendar_information_testcase extends advanced_testcase {
|
||||
$user = $generator->create_user();
|
||||
$coursea = $courses['A.1'];
|
||||
$courseb = $courses['A.2'];
|
||||
$category = \coursecat::get($coursea->category);
|
||||
$category = \core_course_category::get($coursea->category);
|
||||
$wrongcategory = $categories['B1'];
|
||||
$generator->enrol_user($user->id, $coursea->id);
|
||||
$generator->enrol_user($user->id, $courseb->id);
|
||||
@@ -576,7 +576,7 @@ class calendar_information_testcase extends advanced_testcase {
|
||||
$user = $generator->create_user();
|
||||
$coursea = $courses['A.1'];
|
||||
$courseb = $courses['A.2'];
|
||||
$category = \coursecat::get($coursea->category);
|
||||
$category = \core_course_category::get($coursea->category);
|
||||
$wrongcategory = $categories['B1'];
|
||||
$generator->enrol_user($user->id, $coursea->id);
|
||||
$generator->enrol_user($user->id, $courseb->id);
|
||||
@@ -622,7 +622,7 @@ class calendar_information_testcase extends advanced_testcase {
|
||||
$user = $generator->create_user();
|
||||
$coursea = $courses['A.1'];
|
||||
$courseb = $courses['A.2'];
|
||||
$category = \coursecat::get($coursea->category);
|
||||
$category = \core_course_category::get($coursea->category);
|
||||
$wrongcategory = $categories['B1'];
|
||||
$generator->enrol_user($user->id, $coursea->id);
|
||||
$generator->enrol_user($user->id, $courseb->id);
|
||||
@@ -669,7 +669,7 @@ class calendar_information_testcase extends advanced_testcase {
|
||||
$user = $generator->create_user();
|
||||
$coursea = $courses['A.1'];
|
||||
$courseb = $courses['A.2'];
|
||||
$category = \coursecat::get($coursea->category);
|
||||
$category = \core_course_category::get($coursea->category);
|
||||
$wrongcategory = $categories['B1'];
|
||||
$generator->enrol_user($user->id, $coursea->id);
|
||||
$generator->enrol_user($user->id, $courseb->id);
|
||||
@@ -705,7 +705,7 @@ class calendar_information_testcase extends advanced_testcase {
|
||||
$user = $generator->create_user();
|
||||
$coursea = $courses['A.1'];
|
||||
$courseb = $courses['A.2'];
|
||||
$category = \coursecat::get($coursea->category);
|
||||
$category = \core_course_category::get($coursea->category);
|
||||
$wrongcategory = $categories['B1'];
|
||||
$generator->enrol_user($user->id, $coursea->id);
|
||||
$generator->enrol_user($user->id, $courseb->id);
|
||||
@@ -739,8 +739,8 @@ class calendar_information_testcase extends advanced_testcase {
|
||||
$user = $generator->create_user();
|
||||
$coursea = $courses['A.1'];
|
||||
$courseb = $courses['B.1'];
|
||||
$categorya = \coursecat::get($coursea->category);
|
||||
$categoryb = \coursecat::get($courseb->category);
|
||||
$categorya = \core_course_category::get($coursea->category);
|
||||
$categoryb = \core_course_category::get($courseb->category);
|
||||
$wrongcategory = $categories['C'];
|
||||
$generator->enrol_user($user->id, $coursea->id);
|
||||
$generator->enrol_user($user->id, $courseb->id);
|
||||
@@ -776,8 +776,8 @@ class calendar_information_testcase extends advanced_testcase {
|
||||
$user = $generator->create_user();
|
||||
$coursea = $courses['A.1'];
|
||||
$courseb = $courses['B.1'];
|
||||
$categorya = \coursecat::get($coursea->category);
|
||||
$categoryb = \coursecat::get($courseb->category);
|
||||
$categorya = \core_course_category::get($coursea->category);
|
||||
$categoryb = \core_course_category::get($courseb->category);
|
||||
$wrongcategory = $categories['C'];
|
||||
$generator->enrol_user($user->id, $coursea->id);
|
||||
$generator->enrol_user($user->id, $courseb->id);
|
||||
@@ -823,8 +823,8 @@ class calendar_information_testcase extends advanced_testcase {
|
||||
$user = $generator->create_user();
|
||||
$coursea = $courses['A.1'];
|
||||
$courseb = $courses['B.1'];
|
||||
$categorya = \coursecat::get($coursea->category);
|
||||
$categoryb = \coursecat::get($courseb->category);
|
||||
$categorya = \core_course_category::get($coursea->category);
|
||||
$categoryb = \core_course_category::get($courseb->category);
|
||||
$wrongcategory = $categories['C'];
|
||||
$generator->enrol_user($user->id, $coursea->id);
|
||||
$generator->enrol_user($user->id, $courseb->id);
|
||||
@@ -871,8 +871,8 @@ class calendar_information_testcase extends advanced_testcase {
|
||||
$user = $generator->create_user();
|
||||
$coursea = $courses['A.1'];
|
||||
$courseb = $courses['B.1'];
|
||||
$categorya = \coursecat::get($coursea->category);
|
||||
$categoryb = \coursecat::get($courseb->category);
|
||||
$categorya = \core_course_category::get($coursea->category);
|
||||
$categoryb = \core_course_category::get($courseb->category);
|
||||
$wrongcategory = $categories['C'];
|
||||
$generator->enrol_user($user->id, $coursea->id);
|
||||
$generator->enrol_user($user->id, $courseb->id);
|
||||
@@ -912,8 +912,8 @@ class calendar_information_testcase extends advanced_testcase {
|
||||
$user = $generator->create_user();
|
||||
$coursea = $courses['A.1'];
|
||||
$courseb = $courses['B.1'];
|
||||
$categorya = \coursecat::get($coursea->category);
|
||||
$categoryb = \coursecat::get($courseb->category);
|
||||
$categorya = \core_course_category::get($coursea->category);
|
||||
$categoryb = \core_course_category::get($courseb->category);
|
||||
$wrongcategory = $categories['C'];
|
||||
$generator->enrol_user($user->id, $coursea->id);
|
||||
$generator->enrol_user($user->id, $courseb->id);
|
||||
@@ -971,7 +971,7 @@ class calendar_information_testcase extends advanced_testcase {
|
||||
|
||||
$generator = $this->getDataGenerator();
|
||||
$course = $courses['A1.1'];
|
||||
$category = \coursecat::get($course->category);
|
||||
$category = \core_course_category::get($course->category);
|
||||
$this->setAdminUser();
|
||||
$generator->enrol_user($USER->id, $course->id);
|
||||
|
||||
@@ -1002,7 +1002,7 @@ class calendar_information_testcase extends advanced_testcase {
|
||||
|
||||
$generator = $this->getDataGenerator();
|
||||
$course = $courses['A1.1'];
|
||||
$category = \coursecat::get($course->category);
|
||||
$category = \core_course_category::get($course->category);
|
||||
$wrongcategory = $categories['B1'];
|
||||
$this->setAdminUser();
|
||||
$generator->enrol_user($USER->id, $course->id);
|
||||
@@ -1049,7 +1049,7 @@ class calendar_information_testcase extends advanced_testcase {
|
||||
|
||||
$generator = $this->getDataGenerator();
|
||||
$course = $courses['A1.1'];
|
||||
$category = \coursecat::get($course->category);
|
||||
$category = \core_course_category::get($course->category);
|
||||
$wrongcategory = $categories['B1'];
|
||||
$this->setAdminUser();
|
||||
$generator->enrol_user($USER->id, $course->id);
|
||||
|
||||
@@ -59,6 +59,6 @@ class core_calendar_coursecat_proxy_testcase extends advanced_testcase {
|
||||
$this->assertEquals($name, $proxy->get('name'));
|
||||
$this->assertEquals(1, $DB->perf_get_reads() - $startreads);
|
||||
|
||||
$this->assertInstanceOf('coursecat', $proxy->get_proxied_instance());
|
||||
$this->assertInstanceOf('core_course_category', $proxy->get_proxied_instance());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,9 +100,7 @@ class cohort_edit_form extends moodleform {
|
||||
}
|
||||
|
||||
protected function get_category_options($currentcontextid) {
|
||||
global $CFG;
|
||||
require_once($CFG->libdir. '/coursecatlib.php');
|
||||
$displaylist = coursecat::make_categories_list('moodle/cohort:manage');
|
||||
$displaylist = core_course_category::make_categories_list('moodle/cohort:manage');
|
||||
$options = array();
|
||||
$syscontext = context_system::instance();
|
||||
if (has_capability('moodle/cohort:manage', $syscontext)) {
|
||||
|
||||
+1
-1
@@ -138,7 +138,7 @@ function cohort_delete_cohort($cohort) {
|
||||
* Somehow deal with cohorts when deleting course category,
|
||||
* we can not just delete them because they might be used in enrol
|
||||
* plugins or referenced in external systems.
|
||||
* @param stdClass|coursecat $category
|
||||
* @param stdClass|core_course_category $category
|
||||
* @return void
|
||||
*/
|
||||
function cohort_delete_category($category) {
|
||||
|
||||
@@ -138,11 +138,9 @@ class cohort_upload_form extends moodleform {
|
||||
* @return array
|
||||
*/
|
||||
protected function get_context_options() {
|
||||
global $CFG;
|
||||
require_once($CFG->libdir. '/coursecatlib.php');
|
||||
if ($this->contextoptions === null) {
|
||||
$this->contextoptions = array();
|
||||
$displaylist = coursecat::make_categories_list('moodle/cohort:manage');
|
||||
$displaylist = core_course_category::make_categories_list('moodle/cohort:manage');
|
||||
// We need to index the options array by context id instead of category id and add option for system context.
|
||||
$syscontext = context_system::instance();
|
||||
if (has_capability('moodle/cohort:manage', $syscontext)) {
|
||||
|
||||
@@ -27,7 +27,6 @@
|
||||
define('AJAX_SCRIPT', true);
|
||||
|
||||
require_once('../../config.php');
|
||||
require_once($CFG->dirroot.'/lib/coursecatlib.php');
|
||||
require_once($CFG->dirroot.'/course/lib.php');
|
||||
|
||||
$action = required_param('action', PARAM_ALPHA);
|
||||
@@ -55,8 +54,8 @@ switch ($action) {
|
||||
$courseid = required_param('courseid', PARAM_INT);
|
||||
$categoryid = required_param('categoryid', PARAM_INT);
|
||||
$course = get_course($courseid);
|
||||
$oldcategory = coursecat::get($course->category);
|
||||
$category = coursecat::get($categoryid);
|
||||
$oldcategory = core_course_category::get($course->category);
|
||||
$category = core_course_category::get($categoryid);
|
||||
$outcome->outcome = \core_course\management\helper::move_courses_into_category($category, $courseid);
|
||||
$perpage = (int)get_user_preferences('coursecat_management_perpage', $CFG->coursesperpage);
|
||||
$totalcourses = $oldcategory->get_courses_count();
|
||||
@@ -126,13 +125,13 @@ switch ($action) {
|
||||
break;
|
||||
case 'expandcategory':
|
||||
$categoryid = required_param('categoryid', PARAM_INT);
|
||||
$coursecat = coursecat::get($categoryid);
|
||||
$coursecat = core_course_category::get($categoryid);
|
||||
\core_course\management\helper::record_expanded_category($coursecat);
|
||||
$outcome->outcome = true;
|
||||
break;
|
||||
case 'collapsecategory':
|
||||
$categoryid = required_param('categoryid', PARAM_INT);
|
||||
$coursecat = coursecat::get($categoryid);
|
||||
$coursecat = core_course_category::get($categoryid);
|
||||
\core_course\management\helper::record_expanded_category($coursecat, false);
|
||||
$outcome->outcome = true;
|
||||
break;
|
||||
@@ -142,7 +141,7 @@ switch ($action) {
|
||||
$renderer = $PAGE->get_renderer('core_course', 'management');
|
||||
$outcome->html = html_writer::start_tag('ul',
|
||||
array('class' => 'ml', 'role' => 'group', 'id' => 'subcategoriesof'.$categoryid));
|
||||
$coursecat = coursecat::get($categoryid);
|
||||
$coursecat = core_course_category::get($categoryid);
|
||||
foreach ($coursecat->get_children() as $subcat) {
|
||||
$outcome->html .= $renderer->category_listitem($subcat, array(), $subcat->get_children_count());
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -26,7 +26,6 @@ defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
require_once($CFG->libdir . '/formslib.php');
|
||||
require_once($CFG->libdir . '/questionlib.php');
|
||||
require_once($CFG->libdir . '/coursecatlib.php');
|
||||
|
||||
/**
|
||||
* Delete category moodleform.
|
||||
@@ -37,8 +36,8 @@ require_once($CFG->libdir . '/coursecatlib.php');
|
||||
class core_course_deletecategory_form extends moodleform {
|
||||
|
||||
/**
|
||||
* The coursecat object for that category being deleted.
|
||||
* @var coursecat
|
||||
* The core_course_category object for that category being deleted.
|
||||
* @var core_course_category
|
||||
*/
|
||||
protected $coursecat;
|
||||
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
require_once($CFG->libdir.'/formslib.php');
|
||||
require_once($CFG->libdir.'/coursecatlib.php');
|
||||
|
||||
/**
|
||||
* Edit category form.
|
||||
@@ -52,7 +51,7 @@ class core_course_editcategory_form extends moodleform {
|
||||
}
|
||||
if ($categoryid) {
|
||||
// Editing an existing category.
|
||||
$options += coursecat::make_categories_list('moodle/category:manage', $categoryid);
|
||||
$options += core_course_category::make_categories_list('moodle/category:manage', $categoryid);
|
||||
if (empty($options[$parent])) {
|
||||
// Ensure the the category parent has been included in the options.
|
||||
$options[$parent] = $DB->get_field('course_categories', 'name', array('id'=>$parent));
|
||||
@@ -60,7 +59,7 @@ class core_course_editcategory_form extends moodleform {
|
||||
$strsubmit = get_string('savechanges');
|
||||
} else {
|
||||
// Making a new category.
|
||||
$options += coursecat::make_categories_list('moodle/category:manage');
|
||||
$options += core_course_category::make_categories_list('moodle/category:manage');
|
||||
$strsubmit = get_string('createcategory');
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,442 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Contains class core_course_list_element
|
||||
*
|
||||
* @package core
|
||||
* @subpackage course
|
||||
* @copyright 2018 Marina Glancy
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Class to store information about one course in a list of courses
|
||||
*
|
||||
* Not all information may be retrieved when object is created but
|
||||
* it will be retrieved on demand when appropriate property or method is
|
||||
* called.
|
||||
*
|
||||
* Instances of this class are usually returned by functions
|
||||
* {@link core_course_category::search_courses()}
|
||||
* and
|
||||
* {@link core_course_category::get_courses()}
|
||||
*
|
||||
* @property-read int $id
|
||||
* @property-read int $category Category ID
|
||||
* @property-read int $sortorder
|
||||
* @property-read string $fullname
|
||||
* @property-read string $shortname
|
||||
* @property-read string $idnumber
|
||||
* @property-read string $summary Course summary. Field is present if core_course_category::get_courses()
|
||||
* was called with option 'summary'. Otherwise will be retrieved from DB on first request
|
||||
* @property-read int $summaryformat Summary format. Field is present if core_course_category::get_courses()
|
||||
* was called with option 'summary'. Otherwise will be retrieved from DB on first request
|
||||
* @property-read string $format Course format. Retrieved from DB on first request
|
||||
* @property-read int $showgrades Retrieved from DB on first request
|
||||
* @property-read int $newsitems Retrieved from DB on first request
|
||||
* @property-read int $startdate
|
||||
* @property-read int $enddate
|
||||
* @property-read int $marker Retrieved from DB on first request
|
||||
* @property-read int $maxbytes Retrieved from DB on first request
|
||||
* @property-read int $legacyfiles Retrieved from DB on first request
|
||||
* @property-read int $showreports Retrieved from DB on first request
|
||||
* @property-read int $visible
|
||||
* @property-read int $visibleold Retrieved from DB on first request
|
||||
* @property-read int $groupmode Retrieved from DB on first request
|
||||
* @property-read int $groupmodeforce Retrieved from DB on first request
|
||||
* @property-read int $defaultgroupingid Retrieved from DB on first request
|
||||
* @property-read string $lang Retrieved from DB on first request
|
||||
* @property-read string $theme Retrieved from DB on first request
|
||||
* @property-read int $timecreated Retrieved from DB on first request
|
||||
* @property-read int $timemodified Retrieved from DB on first request
|
||||
* @property-read int $requested Retrieved from DB on first request
|
||||
* @property-read int $enablecompletion Retrieved from DB on first request
|
||||
* @property-read int $completionnotify Retrieved from DB on first request
|
||||
* @property-read int $cacherev
|
||||
*
|
||||
* @package core
|
||||
* @subpackage course
|
||||
* @copyright 2013 Marina Glancy
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class core_course_list_element implements IteratorAggregate {
|
||||
|
||||
/** @var stdClass record retrieved from DB, may have additional calculated property such as managers and hassummary */
|
||||
protected $record;
|
||||
|
||||
/** @var array array of course contacts - stores result of call to get_course_contacts() */
|
||||
protected $coursecontacts;
|
||||
|
||||
/** @var bool true if the current user can access the course, false otherwise. */
|
||||
protected $canaccess = null;
|
||||
|
||||
/**
|
||||
* Creates an instance of the class from record
|
||||
*
|
||||
* @param stdClass $record except fields from course table it may contain
|
||||
* field hassummary indicating that summary field is not empty.
|
||||
* Also it is recommended to have context fields here ready for
|
||||
* context preloading
|
||||
*/
|
||||
public function __construct(stdClass $record) {
|
||||
context_helper::preload_from_record($record);
|
||||
$this->record = new stdClass();
|
||||
foreach ($record as $key => $value) {
|
||||
$this->record->$key = $value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the course has non-empty summary field
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function has_summary() {
|
||||
if (isset($this->record->hassummary)) {
|
||||
return !empty($this->record->hassummary);
|
||||
}
|
||||
if (!isset($this->record->summary)) {
|
||||
// We need to retrieve summary.
|
||||
$this->__get('summary');
|
||||
}
|
||||
return !empty($this->record->summary);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates if the course have course contacts to display
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function has_course_contacts() {
|
||||
if (!isset($this->record->managers)) {
|
||||
$courses = array($this->id => &$this->record);
|
||||
core_course_category::preload_course_contacts($courses);
|
||||
}
|
||||
return !empty($this->record->managers);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns list of course contacts (usually teachers) to display in course link
|
||||
*
|
||||
* Roles to display are set up in $CFG->coursecontact
|
||||
*
|
||||
* The result is the list of users where user id is the key and the value
|
||||
* is an array with elements:
|
||||
* - 'user' - object containing basic user information
|
||||
* - 'role' - object containing basic role information (id, name, shortname, coursealias)
|
||||
* - 'rolename' => role_get_name($role, $context, ROLENAME_ALIAS)
|
||||
* - 'username' => fullname($user, $canviewfullnames)
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function get_course_contacts() {
|
||||
global $CFG;
|
||||
if (empty($CFG->coursecontact)) {
|
||||
// No roles are configured to be displayed as course contacts.
|
||||
return array();
|
||||
}
|
||||
if ($this->coursecontacts === null) {
|
||||
$this->coursecontacts = array();
|
||||
$context = context_course::instance($this->id);
|
||||
|
||||
if (!isset($this->record->managers)) {
|
||||
// Preload course contacts from DB.
|
||||
$courses = array($this->id => &$this->record);
|
||||
core_course_category::preload_course_contacts($courses);
|
||||
}
|
||||
|
||||
// Build return array with full roles names (for this course context) and users names.
|
||||
$canviewfullnames = has_capability('moodle/site:viewfullnames', $context);
|
||||
foreach ($this->record->managers as $ruser) {
|
||||
if (isset($this->coursecontacts[$ruser->id])) {
|
||||
// Only display a user once with the highest sortorder role.
|
||||
continue;
|
||||
}
|
||||
$user = new stdClass();
|
||||
$user = username_load_fields_from_object($user, $ruser, null, array('id', 'username'));
|
||||
$role = new stdClass();
|
||||
$role->id = $ruser->roleid;
|
||||
$role->name = $ruser->rolename;
|
||||
$role->shortname = $ruser->roleshortname;
|
||||
$role->coursealias = $ruser->rolecoursealias;
|
||||
|
||||
$this->coursecontacts[$user->id] = array(
|
||||
'user' => $user,
|
||||
'role' => $role,
|
||||
'rolename' => role_get_name($role, $context, ROLENAME_ALIAS),
|
||||
'username' => fullname($user, $canviewfullnames)
|
||||
);
|
||||
}
|
||||
}
|
||||
return $this->coursecontacts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if course has any associated overview files
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function has_course_overviewfiles() {
|
||||
global $CFG;
|
||||
if (empty($CFG->courseoverviewfileslimit)) {
|
||||
return false;
|
||||
}
|
||||
$fs = get_file_storage();
|
||||
$context = context_course::instance($this->id);
|
||||
return !$fs->is_area_empty($context->id, 'course', 'overviewfiles');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all course overview files
|
||||
*
|
||||
* @return array array of stored_file objects
|
||||
*/
|
||||
public function get_course_overviewfiles() {
|
||||
global $CFG;
|
||||
if (empty($CFG->courseoverviewfileslimit)) {
|
||||
return array();
|
||||
}
|
||||
require_once($CFG->libdir. '/filestorage/file_storage.php');
|
||||
require_once($CFG->dirroot. '/course/lib.php');
|
||||
$fs = get_file_storage();
|
||||
$context = context_course::instance($this->id);
|
||||
$files = $fs->get_area_files($context->id, 'course', 'overviewfiles', false, 'filename', false);
|
||||
if (count($files)) {
|
||||
$overviewfilesoptions = course_overviewfiles_options($this->id);
|
||||
$acceptedtypes = $overviewfilesoptions['accepted_types'];
|
||||
if ($acceptedtypes !== '*') {
|
||||
// Filter only files with allowed extensions.
|
||||
require_once($CFG->libdir. '/filelib.php');
|
||||
foreach ($files as $key => $file) {
|
||||
if (!file_extension_in_typegroup($file->get_filename(), $acceptedtypes)) {
|
||||
unset($files[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (count($files) > $CFG->courseoverviewfileslimit) {
|
||||
// Return no more than $CFG->courseoverviewfileslimit files.
|
||||
$files = array_slice($files, 0, $CFG->courseoverviewfileslimit, true);
|
||||
}
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method to check if property is set
|
||||
*
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
public function __isset($name) {
|
||||
return isset($this->record->$name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic method to get a course property
|
||||
*
|
||||
* Returns any field from table course (retrieves it from DB if it was not retrieved before)
|
||||
*
|
||||
* @param string $name
|
||||
* @return mixed
|
||||
*/
|
||||
public function __get($name) {
|
||||
global $DB;
|
||||
if (property_exists($this->record, $name)) {
|
||||
return $this->record->$name;
|
||||
} else if ($name === 'summary' || $name === 'summaryformat') {
|
||||
// Retrieve fields summary and summaryformat together because they are most likely to be used together.
|
||||
$record = $DB->get_record('course', array('id' => $this->record->id), 'summary, summaryformat', MUST_EXIST);
|
||||
$this->record->summary = $record->summary;
|
||||
$this->record->summaryformat = $record->summaryformat;
|
||||
return $this->record->$name;
|
||||
} else if (array_key_exists($name, $DB->get_columns('course'))) {
|
||||
// Another field from table 'course' that was not retrieved.
|
||||
$this->record->$name = $DB->get_field('course', $name, array('id' => $this->record->id), MUST_EXIST);
|
||||
return $this->record->$name;
|
||||
}
|
||||
debugging('Invalid course property accessed! '.$name);
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* All properties are read only, sorry.
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
public function __unset($name) {
|
||||
debugging('Can not unset '.get_class($this).' instance properties!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Magic setter method, we do not want anybody to modify properties from the outside
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function __set($name, $value) {
|
||||
debugging('Can not change '.get_class($this).' instance properties!');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an iterator because magic vars can't be seen by 'foreach'.
|
||||
* Exclude context fields
|
||||
*
|
||||
* Implementing method from interface IteratorAggregate
|
||||
*
|
||||
* @return ArrayIterator
|
||||
*/
|
||||
public function getIterator() {
|
||||
$ret = array('id' => $this->record->id);
|
||||
foreach ($this->record as $property => $value) {
|
||||
$ret[$property] = $value;
|
||||
}
|
||||
return new ArrayIterator($ret);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of this course as it should be displayed within a list.
|
||||
* @return string
|
||||
*/
|
||||
public function get_formatted_name() {
|
||||
return format_string(get_course_display_name_for_list($this), true, $this->get_context());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the formatted fullname for this course.
|
||||
* @return string
|
||||
*/
|
||||
public function get_formatted_fullname() {
|
||||
return format_string($this->__get('fullname'), true, $this->get_context());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the formatted shortname for this course.
|
||||
* @return string
|
||||
*/
|
||||
public function get_formatted_shortname() {
|
||||
return format_string($this->__get('shortname'), true, $this->get_context());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the current user can access this course.
|
||||
* @return bool
|
||||
*/
|
||||
public function can_access() {
|
||||
if ($this->canaccess === null) {
|
||||
$this->canaccess = can_access_course($this->record);
|
||||
}
|
||||
return $this->canaccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the user can edit this courses settings.
|
||||
*
|
||||
* Note: this function does not check that the current user can access the course.
|
||||
* To do that please call require_login with the course, or if not possible call
|
||||
* {@link core_course_list_element::can_access()}
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function can_edit() {
|
||||
return has_capability('moodle/course:update', $this->get_context());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the user can change the visibility of this course.
|
||||
*
|
||||
* Note: this function does not check that the current user can access the course.
|
||||
* To do that please call require_login with the course, or if not possible call
|
||||
* {@link core_course_list_element::can_access()}
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function can_change_visibility() {
|
||||
// You must be able to both hide a course and view the hidden course.
|
||||
return has_all_capabilities(array('moodle/course:visibility', 'moodle/course:viewhiddencourses'),
|
||||
$this->get_context());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the context for this course.
|
||||
* @return context_course
|
||||
*/
|
||||
public function get_context() {
|
||||
return context_course::instance($this->__get('id'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this course is visible to the current user.
|
||||
* @return bool
|
||||
*/
|
||||
public function is_uservisible() {
|
||||
return $this->visible || has_capability('moodle/course:viewhiddencourses', $this->get_context());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the current user can review enrolments for this course.
|
||||
*
|
||||
* Note: this function does not check that the current user can access the course.
|
||||
* To do that please call require_login with the course, or if not possible call
|
||||
* {@link core_course_list_element::can_access()}
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function can_review_enrolments() {
|
||||
return has_capability('moodle/course:enrolreview', $this->get_context());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the current user can delete this course.
|
||||
*
|
||||
* Note: this function does not check that the current user can access the course.
|
||||
* To do that please call require_login with the course, or if not possible call
|
||||
* {@link core_course_list_element::can_access()}
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function can_delete() {
|
||||
return can_delete_course($this->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the current user can backup this course.
|
||||
*
|
||||
* Note: this function does not check that the current user can access the course.
|
||||
* To do that please call require_login with the course, or if not possible call
|
||||
* {@link core_course_list_element::can_access()}
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function can_backup() {
|
||||
return has_capability('moodle/backup:backupcourse', $this->get_context());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the current user can restore this course.
|
||||
*
|
||||
* Note: this function does not check that the current user can access the course.
|
||||
* To do that please call require_login with the course, or if not possible call
|
||||
* {@link core_course_list_element::can_access()}
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function can_restore() {
|
||||
return has_capability('moodle/restore:restorecourse', $this->get_context());
|
||||
}
|
||||
}
|
||||
@@ -52,10 +52,10 @@ class helper {
|
||||
* Returns course details in an array ready to be printed.
|
||||
*
|
||||
* @global \moodle_database $DB
|
||||
* @param \course_in_list $course
|
||||
* @param \core_course_list_element $course
|
||||
* @return array
|
||||
*/
|
||||
public static function get_course_detail_array(\course_in_list $course) {
|
||||
public static function get_course_detail_array(\core_course_list_element $course) {
|
||||
global $DB;
|
||||
|
||||
$canaccess = $course->can_access();
|
||||
@@ -72,7 +72,7 @@ class helper {
|
||||
}
|
||||
}
|
||||
|
||||
$category = \coursecat::get($course->category);
|
||||
$category = \core_course_category::get($course->category);
|
||||
$categoryurl = new \moodle_url('/course/management.php', array('categoryid' => $course->category));
|
||||
$categoryname = $category->get_formatted_name();
|
||||
|
||||
@@ -164,10 +164,10 @@ class helper {
|
||||
/**
|
||||
* Returns an array of actions that can be performed upon a category being shown in a list.
|
||||
*
|
||||
* @param \coursecat $category
|
||||
* @param \core_course_category $category
|
||||
* @return array
|
||||
*/
|
||||
public static function get_category_listitem_actions(\coursecat $category) {
|
||||
public static function get_category_listitem_actions(\core_course_category $category) {
|
||||
$manageurl = new \moodle_url('/course/management.php', array('categoryid' => $category->id));
|
||||
$baseurl = new \moodle_url($manageurl, array('sesskey' => \sesskey()));
|
||||
$actions = array();
|
||||
@@ -313,11 +313,11 @@ class helper {
|
||||
/**
|
||||
* Returns an array of actions for a course listitem.
|
||||
*
|
||||
* @param \coursecat $category
|
||||
* @param \course_in_list $course
|
||||
* @param \core_course_category $category
|
||||
* @param \core_course_list_element $course
|
||||
* @return string
|
||||
*/
|
||||
public static function get_course_listitem_actions(\coursecat $category, \course_in_list $course) {
|
||||
public static function get_course_listitem_actions(\core_course_category $category, \core_course_list_element $course) {
|
||||
$baseurl = new \moodle_url(
|
||||
'/course/management.php',
|
||||
array('courseid' => $course->id, 'categoryid' => $course->category, 'sesskey' => \sesskey())
|
||||
@@ -371,10 +371,10 @@ class helper {
|
||||
/**
|
||||
* Returns an array of actions that can be performed on the course being displayed.
|
||||
*
|
||||
* @param \course_in_list $course
|
||||
* @param \core_course_list_element $course
|
||||
* @return array
|
||||
*/
|
||||
public static function get_course_detail_actions(\course_in_list $course) {
|
||||
public static function get_course_detail_actions(\core_course_list_element $course) {
|
||||
$params = array('courseid' => $course->id, 'categoryid' => $course->category, 'sesskey' => \sesskey());
|
||||
$baseurl = new \moodle_url('/course/management.php', $params);
|
||||
$actions = array();
|
||||
@@ -440,14 +440,15 @@ class helper {
|
||||
/**
|
||||
* Resorts the courses within a category moving the given course up by one.
|
||||
*
|
||||
* @param \course_in_list $course
|
||||
* @param \coursecat $category
|
||||
* @param \core_course_list_element $course
|
||||
* @param \core_course_category $category
|
||||
* @return bool
|
||||
* @throws \moodle_exception
|
||||
*/
|
||||
public static function action_course_change_sortorder_up_one(\course_in_list $course, \coursecat $category) {
|
||||
public static function action_course_change_sortorder_up_one(\core_course_list_element $course,
|
||||
\core_course_category $category) {
|
||||
if (!$category->can_resort_courses()) {
|
||||
throw new \moodle_exception('permissiondenied', 'error', '', null, 'coursecat::can_resort');
|
||||
throw new \moodle_exception('permissiondenied', 'error', '', null, 'core_course_category::can_resort');
|
||||
}
|
||||
return \course_change_sortorder_by_one($course, true);
|
||||
}
|
||||
@@ -455,14 +456,15 @@ class helper {
|
||||
/**
|
||||
* Resorts the courses within a category moving the given course down by one.
|
||||
*
|
||||
* @param \course_in_list $course
|
||||
* @param \coursecat $category
|
||||
* @param \core_course_list_element $course
|
||||
* @param \core_course_category $category
|
||||
* @return bool
|
||||
* @throws \moodle_exception
|
||||
*/
|
||||
public static function action_course_change_sortorder_down_one(\course_in_list $course, \coursecat $category) {
|
||||
public static function action_course_change_sortorder_down_one(\core_course_list_element $course,
|
||||
\core_course_category $category) {
|
||||
if (!$category->can_resort_courses()) {
|
||||
throw new \moodle_exception('permissiondenied', 'error', '', null, 'coursecat::can_resort');
|
||||
throw new \moodle_exception('permissiondenied', 'error', '', null, 'core_course_category::can_resort');
|
||||
}
|
||||
return \course_change_sortorder_by_one($course, false);
|
||||
}
|
||||
@@ -478,8 +480,8 @@ class helper {
|
||||
if (is_int($courserecordorid)) {
|
||||
$courserecordorid = get_course($courserecordorid);
|
||||
}
|
||||
$course = new \course_in_list($courserecordorid);
|
||||
$category = \coursecat::get($course->category);
|
||||
$course = new \core_course_list_element($courserecordorid);
|
||||
$category = \core_course_category::get($course->category);
|
||||
return self::action_course_change_sortorder_up_one($course, $category);
|
||||
}
|
||||
|
||||
@@ -494,8 +496,8 @@ class helper {
|
||||
if (is_int($courserecordorid)) {
|
||||
$courserecordorid = get_course($courserecordorid);
|
||||
}
|
||||
$course = new \course_in_list($courserecordorid);
|
||||
$category = \coursecat::get($course->category);
|
||||
$course = new \core_course_list_element($courserecordorid);
|
||||
$category = \core_course_category::get($course->category);
|
||||
return self::action_course_change_sortorder_down_one($course, $category);
|
||||
}
|
||||
|
||||
@@ -509,7 +511,7 @@ class helper {
|
||||
*/
|
||||
public static function action_course_change_sortorder_after_course($courserecordorid, $moveaftercourseid) {
|
||||
$course = \get_course($courserecordorid);
|
||||
$category = \coursecat::get($course->category);
|
||||
$category = \core_course_category::get($course->category);
|
||||
if (!$category->can_resort_courses()) {
|
||||
$url = '/course/management.php?categoryid='.$course->category;
|
||||
throw new \moodle_exception('nopermissions', 'error', $url, \get_string('resortcourses', 'moodle'));
|
||||
@@ -518,29 +520,31 @@ class helper {
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a course visible given a \course_in_list object.
|
||||
* Makes a course visible given a \core_course_list_element object.
|
||||
*
|
||||
* @param \course_in_list $course
|
||||
* @param \core_course_list_element $course
|
||||
* @return bool
|
||||
* @throws \moodle_exception
|
||||
*/
|
||||
public static function action_course_show(\course_in_list $course) {
|
||||
public static function action_course_show(\core_course_list_element $course) {
|
||||
if (!$course->can_change_visibility()) {
|
||||
throw new \moodle_exception('permissiondenied', 'error', '', null, 'course_in_list::can_change_visbility');
|
||||
throw new \moodle_exception('permissiondenied', 'error', '', null,
|
||||
'core_course_list_element::can_change_visbility');
|
||||
}
|
||||
return course_change_visibility($course->id, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a course hidden given a \course_in_list object.
|
||||
* Makes a course hidden given a \core_course_list_element object.
|
||||
*
|
||||
* @param \course_in_list $course
|
||||
* @param \core_course_list_element $course
|
||||
* @return bool
|
||||
* @throws \moodle_exception
|
||||
*/
|
||||
public static function action_course_hide(\course_in_list $course) {
|
||||
public static function action_course_hide(\core_course_list_element $course) {
|
||||
if (!$course->can_change_visibility()) {
|
||||
throw new \moodle_exception('permissiondenied', 'error', '', null, 'course_in_list::can_change_visbility');
|
||||
throw new \moodle_exception('permissiondenied', 'error', '', null,
|
||||
'core_course_list_element::can_change_visbility');
|
||||
}
|
||||
return course_change_visibility($course->id, false);
|
||||
}
|
||||
@@ -556,7 +560,7 @@ class helper {
|
||||
if (is_int($courserecordorid)) {
|
||||
$courserecordorid = get_course($courserecordorid);
|
||||
}
|
||||
$course = new \course_in_list($courserecordorid);
|
||||
$course = new \core_course_list_element($courserecordorid);
|
||||
return self::action_course_show($course);
|
||||
}
|
||||
|
||||
@@ -571,20 +575,20 @@ class helper {
|
||||
if (is_int($courserecordorid)) {
|
||||
$courserecordorid = get_course($courserecordorid);
|
||||
}
|
||||
$course = new \course_in_list($courserecordorid);
|
||||
$course = new \core_course_list_element($courserecordorid);
|
||||
return self::action_course_hide($course);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resort a categories subcategories shifting the given category up one.
|
||||
*
|
||||
* @param \coursecat $category
|
||||
* @param \core_course_category $category
|
||||
* @return bool
|
||||
* @throws \moodle_exception
|
||||
*/
|
||||
public static function action_category_change_sortorder_up_one(\coursecat $category) {
|
||||
public static function action_category_change_sortorder_up_one(\core_course_category $category) {
|
||||
if (!$category->can_change_sortorder()) {
|
||||
throw new \moodle_exception('permissiondenied', 'error', '', null, 'coursecat::can_change_sortorder');
|
||||
throw new \moodle_exception('permissiondenied', 'error', '', null, 'core_course_category::can_change_sortorder');
|
||||
}
|
||||
return $category->change_sortorder_by_one(true);
|
||||
}
|
||||
@@ -592,13 +596,13 @@ class helper {
|
||||
/**
|
||||
* Resort a categories subcategories shifting the given category down one.
|
||||
*
|
||||
* @param \coursecat $category
|
||||
* @param \core_course_category $category
|
||||
* @return bool
|
||||
* @throws \moodle_exception
|
||||
*/
|
||||
public static function action_category_change_sortorder_down_one(\coursecat $category) {
|
||||
public static function action_category_change_sortorder_down_one(\core_course_category $category) {
|
||||
if (!$category->can_change_sortorder()) {
|
||||
throw new \moodle_exception('permissiondenied', 'error', '', null, 'coursecat::can_change_sortorder');
|
||||
throw new \moodle_exception('permissiondenied', 'error', '', null, 'core_course_category::can_change_sortorder');
|
||||
}
|
||||
return $category->change_sortorder_by_one(false);
|
||||
}
|
||||
@@ -610,7 +614,7 @@ class helper {
|
||||
* @return bool
|
||||
*/
|
||||
public static function action_category_change_sortorder_up_one_by_id($categoryid) {
|
||||
$category = \coursecat::get($categoryid);
|
||||
$category = \core_course_category::get($categoryid);
|
||||
return self::action_category_change_sortorder_up_one($category);
|
||||
}
|
||||
|
||||
@@ -621,72 +625,72 @@ class helper {
|
||||
* @return bool
|
||||
*/
|
||||
public static function action_category_change_sortorder_down_one_by_id($categoryid) {
|
||||
$category = \coursecat::get($categoryid);
|
||||
$category = \core_course_category::get($categoryid);
|
||||
return self::action_category_change_sortorder_down_one($category);
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a category hidden given a \coursecat record.
|
||||
* Makes a category hidden given a core_course_category object.
|
||||
*
|
||||
* @param \coursecat $category
|
||||
* @param \core_course_category $category
|
||||
* @return bool
|
||||
* @throws \moodle_exception
|
||||
*/
|
||||
public static function action_category_hide(\coursecat $category) {
|
||||
public static function action_category_hide(\core_course_category $category) {
|
||||
if (!$category->can_change_visibility()) {
|
||||
throw new \moodle_exception('permissiondenied', 'error', '', null, 'coursecat::can_change_visbility');
|
||||
throw new \moodle_exception('permissiondenied', 'error', '', null, 'core_course_category::can_change_visbility');
|
||||
}
|
||||
$category->hide();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a category visible given a \coursecat record.
|
||||
* Makes a category visible given a core_course_category object.
|
||||
*
|
||||
* @param \coursecat $category
|
||||
* @param \core_course_category $category
|
||||
* @return bool
|
||||
* @throws \moodle_exception
|
||||
*/
|
||||
public static function action_category_show(\coursecat $category) {
|
||||
public static function action_category_show(\core_course_category $category) {
|
||||
if (!$category->can_change_visibility()) {
|
||||
throw new \moodle_exception('permissiondenied', 'error', '', null, 'coursecat::can_change_visbility');
|
||||
throw new \moodle_exception('permissiondenied', 'error', '', null, 'core_course_category::can_change_visbility');
|
||||
}
|
||||
$category->show();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a category visible given a \coursecat id or database record.
|
||||
* Makes a category visible given a course category id or database record.
|
||||
*
|
||||
* @param int|\stdClass $categoryid
|
||||
* @return bool
|
||||
*/
|
||||
public static function action_category_show_by_id($categoryid) {
|
||||
return self::action_category_show(\coursecat::get($categoryid));
|
||||
return self::action_category_show(\core_course_category::get($categoryid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a category hidden given a \coursecat id or database record.
|
||||
* Makes a category hidden given a course category id or database record.
|
||||
*
|
||||
* @param int|\stdClass $categoryid
|
||||
* @return bool
|
||||
*/
|
||||
public static function action_category_hide_by_id($categoryid) {
|
||||
return self::action_category_hide(\coursecat::get($categoryid));
|
||||
return self::action_category_hide(\core_course_category::get($categoryid));
|
||||
}
|
||||
|
||||
/**
|
||||
* Resorts the sub categories of the given category.
|
||||
*
|
||||
* @param \coursecat $category
|
||||
* @param \core_course_category $category
|
||||
* @param string $sort One of idnumber or name.
|
||||
* @param bool $cleanup If true cleanup will be done, if false you will need to do it manually later.
|
||||
* @return bool
|
||||
* @throws \moodle_exception
|
||||
*/
|
||||
public static function action_category_resort_subcategories(\coursecat $category, $sort, $cleanup = true) {
|
||||
public static function action_category_resort_subcategories(\core_course_category $category, $sort, $cleanup = true) {
|
||||
if (!$category->can_resort_subcategories()) {
|
||||
throw new \moodle_exception('permissiondenied', 'error', '', null, 'coursecat::can_resort');
|
||||
throw new \moodle_exception('permissiondenied', 'error', '', null, 'core_course_category::can_resort');
|
||||
}
|
||||
return $category->resort_subcategories($sort, $cleanup);
|
||||
}
|
||||
@@ -694,15 +698,15 @@ class helper {
|
||||
/**
|
||||
* Resorts the courses within the given category.
|
||||
*
|
||||
* @param \coursecat $category
|
||||
* @param \core_course_category $category
|
||||
* @param string $sort One of fullname, shortname or idnumber
|
||||
* @param bool $cleanup If true cleanup will be done, if false you will need to do it manually later.
|
||||
* @return bool
|
||||
* @throws \moodle_exception
|
||||
*/
|
||||
public static function action_category_resort_courses(\coursecat $category, $sort, $cleanup = true) {
|
||||
public static function action_category_resort_courses(\core_course_category $category, $sort, $cleanup = true) {
|
||||
if (!$category->can_resort_courses()) {
|
||||
throw new \moodle_exception('permissiondenied', 'error', '', null, 'coursecat::can_resort');
|
||||
throw new \moodle_exception('permissiondenied', 'error', '', null, 'core_course_category::can_resort');
|
||||
}
|
||||
return $category->resort_courses($sort, $cleanup);
|
||||
}
|
||||
@@ -710,13 +714,14 @@ class helper {
|
||||
/**
|
||||
* Moves courses out of one category and into a new category.
|
||||
*
|
||||
* @param \coursecat $oldcategory The category we are moving courses out of.
|
||||
* @param \coursecat $newcategory The category we are moving courses into.
|
||||
* @param \core_course_category $oldcategory The category we are moving courses out of.
|
||||
* @param \core_course_category $newcategory The category we are moving courses into.
|
||||
* @param array $courseids The ID's of the courses we want to move.
|
||||
* @return bool True on success.
|
||||
* @throws \moodle_exception
|
||||
*/
|
||||
public static function action_category_move_courses_into(\coursecat $oldcategory, \coursecat $newcategory, array $courseids) {
|
||||
public static function action_category_move_courses_into(\core_course_category $oldcategory,
|
||||
\core_course_category $newcategory, array $courseids) {
|
||||
global $DB;
|
||||
|
||||
list($where, $params) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED);
|
||||
@@ -773,13 +778,13 @@ class helper {
|
||||
$searchcriteria = array('modulelist' => $modulelist);
|
||||
}
|
||||
|
||||
$courses = \coursecat::get(0)->search_courses($searchcriteria, array(
|
||||
$courses = \core_course_category::get(0)->search_courses($searchcriteria, array(
|
||||
'recursive' => true,
|
||||
'offset' => $page * $perpage,
|
||||
'limit' => $perpage,
|
||||
'sort' => array('fullname' => 1)
|
||||
));
|
||||
$totalcount = \coursecat::get(0)->search_courses_count($searchcriteria, array('recursive' => true));
|
||||
$totalcount = \core_course_category::get(0)->search_courses_count($searchcriteria, array('recursive' => true));
|
||||
|
||||
return array($courses, \count($courses), $totalcount);
|
||||
}
|
||||
@@ -790,7 +795,7 @@ class helper {
|
||||
* This function works much the same way as action_category_move_courses_into however it allows courses from multiple
|
||||
* categories to be moved into a single category.
|
||||
*
|
||||
* @param int|\coursecat $categoryorid The category to move them into.
|
||||
* @param int|\core_course_category $categoryorid The category to move them into.
|
||||
* @param array|int $courseids An array of course id's or optionally just a single course id.
|
||||
* @return bool True on success or false on failure.
|
||||
* @throws \moodle_exception
|
||||
@@ -805,10 +810,10 @@ class helper {
|
||||
if (count($courseids) === 0) {
|
||||
return false;
|
||||
}
|
||||
if ($categoryorid instanceof \coursecat) {
|
||||
if ($categoryorid instanceof \core_course_category) {
|
||||
$moveto = $categoryorid;
|
||||
} else {
|
||||
$moveto = \coursecat::get($categoryorid);
|
||||
$moveto = \core_course_category::get($categoryorid);
|
||||
}
|
||||
if (!$moveto->can_move_courses_out_of() || !$moveto->can_move_courses_into()) {
|
||||
throw new \moodle_exception('cannotmovecourses');
|
||||
@@ -824,7 +829,7 @@ class helper {
|
||||
}
|
||||
$catid = $courses[$id]->category;
|
||||
if (!isset($checks[$catid])) {
|
||||
$coursecat = \coursecat::get($catid);
|
||||
$coursecat = \core_course_category::get($catid);
|
||||
$checks[$catid] = $coursecat->can_move_courses_out_of() && $coursecat->can_move_courses_into();
|
||||
}
|
||||
if (!$checks[$catid]) {
|
||||
@@ -855,7 +860,7 @@ class helper {
|
||||
*/
|
||||
public static function get_category_children_visibility($categoryid) {
|
||||
global $DB;
|
||||
$category = \coursecat::get($categoryid);
|
||||
$category = \core_course_category::get($categoryid);
|
||||
$select = $DB->sql_like('path', ':path');
|
||||
$path = $category->path . '/%';
|
||||
|
||||
@@ -869,10 +874,10 @@ class helper {
|
||||
/**
|
||||
* Records when a category is expanded or collapsed so that when the user
|
||||
*
|
||||
* @param \coursecat $coursecat The category we're working with.
|
||||
* @param \core_course_category $coursecat The category we're working with.
|
||||
* @param bool $expanded True if the category is expanded now.
|
||||
*/
|
||||
public static function record_expanded_category(\coursecat $coursecat, $expanded = true) {
|
||||
public static function record_expanded_category(\core_course_category $coursecat, $expanded = true) {
|
||||
// If this ever changes we are going to reset it and reload the categories as required.
|
||||
self::$expandedcategories = null;
|
||||
$categoryid = $coursecat->id;
|
||||
@@ -920,7 +925,7 @@ class helper {
|
||||
* Returns the categories that should be expanded when displaying the interface.
|
||||
*
|
||||
* @param int|null $withpath If specified a path to require as the parent.
|
||||
* @return \coursecat[] An array of Category ID's to expand.
|
||||
* @return \core_course_category[] An array of Category ID's to expand.
|
||||
*/
|
||||
public static function get_expanded_categories($withpath = null) {
|
||||
if (self::$expandedcategories === null) {
|
||||
|
||||
@@ -78,7 +78,7 @@ class core_course_management_renderer extends plugin_renderer_base {
|
||||
$html .= html_writer::start_div();
|
||||
$html .= $this->view_mode_selector(\core_course\management\helper::get_management_viewmodes(), $viewmode);
|
||||
if ($viewmode === 'courses') {
|
||||
$categories = coursecat::make_categories_list(array('moodle/category:manage', 'moodle/course:create'));
|
||||
$categories = core_course_category::make_categories_list(array('moodle/category:manage', 'moodle/course:create'));
|
||||
$nothing = false;
|
||||
if ($categoryid === null) {
|
||||
$nothing = array('' => get_string('selectacategory'));
|
||||
@@ -119,10 +119,10 @@ class core_course_management_renderer extends plugin_renderer_base {
|
||||
/**
|
||||
* Presents a course category listing.
|
||||
*
|
||||
* @param coursecat $category The currently selected category. Also the category to highlight in the listing.
|
||||
* @param core_course_category $category The currently selected category. Also the category to highlight in the listing.
|
||||
* @return string
|
||||
*/
|
||||
public function category_listing(coursecat $category = null) {
|
||||
public function category_listing(core_course_category $category = null) {
|
||||
|
||||
if ($category === null) {
|
||||
$selectedparents = array();
|
||||
@@ -136,7 +136,7 @@ class core_course_management_renderer extends plugin_renderer_base {
|
||||
$catatlevel[] = array_shift($selectedparents);
|
||||
$catatlevel = array_unique($catatlevel);
|
||||
|
||||
$listing = coursecat::get(0)->get_children();
|
||||
$listing = core_course_category::get(0)->get_children();
|
||||
|
||||
$attributes = array(
|
||||
'class' => 'ml',
|
||||
@@ -173,14 +173,14 @@ class core_course_management_renderer extends plugin_renderer_base {
|
||||
*
|
||||
* This function gets called recursively to render sub categories.
|
||||
*
|
||||
* @param coursecat $category The category to render as listitem.
|
||||
* @param coursecat[] $subcategories The subcategories belonging to the category being rented.
|
||||
* @param core_course_category $category The category to render as listitem.
|
||||
* @param core_course_category[] $subcategories The subcategories belonging to the category being rented.
|
||||
* @param int $totalsubcategories The total number of sub categories.
|
||||
* @param int $selectedcategory The currently selected category
|
||||
* @param int[] $selectedcategories The path to the selected category and its ID.
|
||||
* @return string
|
||||
*/
|
||||
public function category_listitem(coursecat $category, array $subcategories, $totalsubcategories,
|
||||
public function category_listitem(core_course_category $category, array $subcategories, $totalsubcategories,
|
||||
$selectedcategory = null, $selectedcategories = array()) {
|
||||
|
||||
$isexpandable = ($totalsubcategories > 0);
|
||||
@@ -313,23 +313,23 @@ class core_course_management_renderer extends plugin_renderer_base {
|
||||
* These are not the actions associated with an individual category listing.
|
||||
* That happens through category_listitem_actions.
|
||||
*
|
||||
* @param coursecat $category
|
||||
* @param core_course_category $category
|
||||
* @return string
|
||||
*/
|
||||
public function category_listing_actions(coursecat $category = null) {
|
||||
public function category_listing_actions(core_course_category $category = null) {
|
||||
$actions = array();
|
||||
|
||||
$cancreatecategory = $category && $category->can_create_subcategory();
|
||||
$cancreatecategory = $cancreatecategory || coursecat::can_create_top_level_category();
|
||||
$cancreatecategory = $cancreatecategory || core_course_category::can_create_top_level_category();
|
||||
if ($category === null) {
|
||||
$category = coursecat::get(0);
|
||||
$category = core_course_category::get(0);
|
||||
}
|
||||
|
||||
if ($cancreatecategory) {
|
||||
$url = new moodle_url('/course/editcategory.php', array('parent' => $category->id));
|
||||
$actions[] = html_writer::link($url, get_string('createnewcategory'));
|
||||
}
|
||||
if (coursecat::can_approve_course_requests()) {
|
||||
if (core_course_category::can_approve_course_requests()) {
|
||||
$actions[] = html_writer::link(new moodle_url('/course/pending.php'), get_string('coursespending'));
|
||||
}
|
||||
if (count($actions) === 0) {
|
||||
@@ -341,11 +341,11 @@ class core_course_management_renderer extends plugin_renderer_base {
|
||||
/**
|
||||
* Renderers the actions for individual category list items.
|
||||
*
|
||||
* @param coursecat $category
|
||||
* @param core_course_category $category
|
||||
* @param array $actions
|
||||
* @return string
|
||||
*/
|
||||
public function category_listitem_actions(coursecat $category, array $actions = null) {
|
||||
public function category_listitem_actions(core_course_category $category, array $actions = null) {
|
||||
if ($actions === null) {
|
||||
$actions = \core_course\management\helper::get_category_listitem_actions($category);
|
||||
}
|
||||
@@ -377,20 +377,20 @@ class core_course_management_renderer extends plugin_renderer_base {
|
||||
/**
|
||||
* Renders bulk actions for categories.
|
||||
*
|
||||
* @param coursecat $category The currently selected category if there is one.
|
||||
* @param core_course_category $category The currently selected category if there is one.
|
||||
* @return string
|
||||
*/
|
||||
public function category_bulk_actions(coursecat $category = null) {
|
||||
public function category_bulk_actions(core_course_category $category = null) {
|
||||
// Resort courses.
|
||||
// Change parent.
|
||||
if (!coursecat::can_resort_any() && !coursecat::can_change_parent_any()) {
|
||||
if (!core_course_category::can_resort_any() && !core_course_category::can_change_parent_any()) {
|
||||
return '';
|
||||
}
|
||||
$strgo = new lang_string('go');
|
||||
|
||||
$html = html_writer::start_div('category-bulk-actions bulk-actions');
|
||||
$html .= html_writer::div(get_string('categorybulkaction'), 'accesshide', array('tabindex' => '0'));
|
||||
if (coursecat::can_resort_any()) {
|
||||
if (core_course_category::can_resort_any()) {
|
||||
$selectoptions = array(
|
||||
'selectedcategories' => get_string('selectedcategories'),
|
||||
'allcategories' => get_string('allcategories')
|
||||
@@ -452,12 +452,12 @@ class core_course_management_renderer extends plugin_renderer_base {
|
||||
$html .= html_writer::div($form, 'pair-value span9 col-md-9 yui3-u-3-4');
|
||||
$html .= html_writer::end_div();
|
||||
}
|
||||
if (coursecat::can_change_parent_any()) {
|
||||
if (core_course_category::can_change_parent_any()) {
|
||||
$options = array();
|
||||
if (has_capability('moodle/category:manage', context_system::instance())) {
|
||||
$options[0] = coursecat::get(0)->get_formatted_name();
|
||||
$options[0] = core_course_category::get(0)->get_formatted_name();
|
||||
}
|
||||
$options += coursecat::make_categories_list('moodle/category:manage');
|
||||
$options += core_course_category::make_categories_list('moodle/category:manage');
|
||||
$select = html_writer::select(
|
||||
$options,
|
||||
'movecategoriesto',
|
||||
@@ -479,14 +479,15 @@ class core_course_management_renderer extends plugin_renderer_base {
|
||||
/**
|
||||
* Renders a course listing.
|
||||
*
|
||||
* @param coursecat $category The currently selected category. This is what the listing is focused on.
|
||||
* @param course_in_list $course The currently selected course.
|
||||
* @param core_course_category $category The currently selected category. This is what the listing is focused on.
|
||||
* @param core_course_list_element $course The currently selected course.
|
||||
* @param int $page The page being displayed.
|
||||
* @param int $perpage The number of courses to display per page.
|
||||
* @param string|null $viewmode The view mode the page is in, one out of 'default', 'combined', 'courses' or 'categories'.
|
||||
* @return string
|
||||
*/
|
||||
public function course_listing(coursecat $category = null, course_in_list $course = null, $page = 0, $perpage = 20,
|
||||
public function course_listing(core_course_category $category = null, core_course_list_element $course = null,
|
||||
$page = 0, $perpage = 20,
|
||||
$viewmode = 'default') {
|
||||
|
||||
if ($category === null) {
|
||||
@@ -543,14 +544,15 @@ class core_course_management_renderer extends plugin_renderer_base {
|
||||
/**
|
||||
* Renders pagination for a course listing.
|
||||
*
|
||||
* @param coursecat $category The category to produce pagination for.
|
||||
* @param core_course_category $category The category to produce pagination for.
|
||||
* @param int $page The current page.
|
||||
* @param int $perpage The number of courses to display per page.
|
||||
* @param bool $showtotals Set to true to show the total number of courses and what is being displayed.
|
||||
* @param string|null $viewmode The view mode the page is in, one out of 'default', 'combined', 'courses' or 'categories'.
|
||||
* @return string
|
||||
*/
|
||||
protected function listing_pagination(coursecat $category, $page, $perpage, $showtotals = false, $viewmode = 'default') {
|
||||
protected function listing_pagination(core_course_category $category, $page, $perpage, $showtotals = false,
|
||||
$viewmode = 'default') {
|
||||
$html = '';
|
||||
$totalcourses = $category->get_courses_count();
|
||||
$totalpages = ceil($totalcourses / $perpage);
|
||||
@@ -618,12 +620,12 @@ class core_course_management_renderer extends plugin_renderer_base {
|
||||
*
|
||||
* This function will be called for every course being displayed by course_listing.
|
||||
*
|
||||
* @param coursecat $category The currently selected category and the category the course belongs to.
|
||||
* @param course_in_list $course The course to produce HTML for.
|
||||
* @param core_course_category $category The currently selected category and the category the course belongs to.
|
||||
* @param core_course_list_element $course The course to produce HTML for.
|
||||
* @param int $selectedcourse The id of the currently selected course.
|
||||
* @return string
|
||||
*/
|
||||
public function course_listitem(coursecat $category, course_in_list $course, $selectedcourse) {
|
||||
public function course_listitem(core_course_category $category, core_course_list_element $course, $selectedcourse) {
|
||||
|
||||
$text = $course->get_formatted_name();
|
||||
$attributes = array(
|
||||
@@ -676,12 +678,12 @@ class core_course_management_renderer extends plugin_renderer_base {
|
||||
*
|
||||
* Not to be confused with course_listitem_actions which renderers the actions for individual courses.
|
||||
*
|
||||
* @param coursecat $category
|
||||
* @param course_in_list $course The currently selected course.
|
||||
* @param core_course_category $category
|
||||
* @param core_course_list_element $course The currently selected course.
|
||||
* @param int $perpage
|
||||
* @return string
|
||||
*/
|
||||
public function course_listing_actions(coursecat $category, course_in_list $course = null, $perpage = 20) {
|
||||
public function course_listing_actions(core_course_category $category, core_course_list_element $course = null, $perpage = 20) {
|
||||
$actions = array();
|
||||
if ($category->can_create_course()) {
|
||||
$url = new moodle_url('/course/edit.php', array('category' => $category->id, 'returnto' => 'catmanage'));
|
||||
@@ -755,11 +757,11 @@ class core_course_management_renderer extends plugin_renderer_base {
|
||||
/**
|
||||
* Renderers actions for individual course actions.
|
||||
*
|
||||
* @param coursecat $category The currently selected category.
|
||||
* @param course_in_list $course The course to renderer actions for.
|
||||
* @param core_course_category $category The currently selected category.
|
||||
* @param core_course_list_element $course The course to renderer actions for.
|
||||
* @return string
|
||||
*/
|
||||
public function course_listitem_actions(coursecat $category, course_in_list $course) {
|
||||
public function course_listitem_actions(core_course_category $category, core_course_list_element $course) {
|
||||
$actions = \core_course\management\helper::get_course_listitem_actions($category, $course);
|
||||
if (empty($actions)) {
|
||||
return '';
|
||||
@@ -775,15 +777,15 @@ class core_course_management_renderer extends plugin_renderer_base {
|
||||
/**
|
||||
* Renderers bulk actions that can be performed on courses.
|
||||
*
|
||||
* @param coursecat $category The currently selected category and the category in which courses that
|
||||
* @param core_course_category $category The currently selected category and the category in which courses that
|
||||
* are selectable belong.
|
||||
* @return string
|
||||
*/
|
||||
public function course_bulk_actions(coursecat $category) {
|
||||
public function course_bulk_actions(core_course_category $category) {
|
||||
$html = html_writer::start_div('course-bulk-actions bulk-actions');
|
||||
if ($category->can_move_courses_out_of()) {
|
||||
$html .= html_writer::div(get_string('coursebulkaction'), 'accesshide', array('tabindex' => '0'));
|
||||
$options = coursecat::make_categories_list('moodle/category:manage');
|
||||
$options = core_course_category::make_categories_list('moodle/category:manage');
|
||||
$select = html_writer::select(
|
||||
$options,
|
||||
'movecoursesto',
|
||||
@@ -810,7 +812,7 @@ class core_course_management_renderer extends plugin_renderer_base {
|
||||
public function course_search_bulk_actions() {
|
||||
$html = html_writer::start_div('course-bulk-actions bulk-actions');
|
||||
$html .= html_writer::div(get_string('coursebulkaction'), 'accesshide', array('tabindex' => '0'));
|
||||
$options = coursecat::make_categories_list('moodle/category:manage');
|
||||
$options = core_course_category::make_categories_list('moodle/category:manage');
|
||||
$select = html_writer::select(
|
||||
$options,
|
||||
'movecoursesto',
|
||||
@@ -831,10 +833,10 @@ class core_course_management_renderer extends plugin_renderer_base {
|
||||
/**
|
||||
* Renderers detailed course information.
|
||||
*
|
||||
* @param course_in_list $course The course to display details for.
|
||||
* @param core_course_list_element $course The course to display details for.
|
||||
* @return string
|
||||
*/
|
||||
public function course_detail(course_in_list $course) {
|
||||
public function course_detail(core_course_list_element $course) {
|
||||
$details = \core_course\management\helper::get_course_detail_array($course);
|
||||
$fullname = $details['fullname']['value'];
|
||||
|
||||
@@ -867,10 +869,10 @@ class core_course_management_renderer extends plugin_renderer_base {
|
||||
/**
|
||||
* A collection of actions for a course.
|
||||
*
|
||||
* @param course_in_list $course The course to display actions for.
|
||||
* @param core_course_list_element $course The course to display actions for.
|
||||
* @return string
|
||||
*/
|
||||
public function course_detail_actions(course_in_list $course) {
|
||||
public function course_detail_actions(core_course_list_element $course) {
|
||||
$actions = \core_course\management\helper::get_course_detail_actions($course);
|
||||
if (empty($actions)) {
|
||||
return '';
|
||||
@@ -1089,13 +1091,13 @@ class core_course_management_renderer extends plugin_renderer_base {
|
||||
*
|
||||
* @param array $courses The courses to display.
|
||||
* @param int $totalcourses The total number of courses to display.
|
||||
* @param course_in_list $course The currently selected course if there is one.
|
||||
* @param core_course_list_element $course The currently selected course if there is one.
|
||||
* @param int $page The current page, starting at 0.
|
||||
* @param int $perpage The number of courses to display per page.
|
||||
* @param string $search The string we are searching for.
|
||||
* @return string
|
||||
*/
|
||||
public function search_listing(array $courses, $totalcourses, course_in_list $course = null, $page = 0, $perpage = 20,
|
||||
public function search_listing(array $courses, $totalcourses, core_course_list_element $course = null, $page = 0, $perpage = 20,
|
||||
$search = '') {
|
||||
$page = max($page, 0);
|
||||
$perpage = max($perpage, 2);
|
||||
@@ -1203,11 +1205,11 @@ class core_course_management_renderer extends plugin_renderer_base {
|
||||
*
|
||||
* This function will be called for every course being displayed by course_listing.
|
||||
*
|
||||
* @param course_in_list $course The course to produce HTML for.
|
||||
* @param core_course_list_element $course The course to produce HTML for.
|
||||
* @param int $selectedcourse The id of the currently selected course.
|
||||
* @return string
|
||||
*/
|
||||
public function search_listitem(course_in_list $course, $selectedcourse) {
|
||||
public function search_listitem(core_course_list_element $course, $selectedcourse) {
|
||||
|
||||
$text = $course->get_formatted_name();
|
||||
$attributes = array(
|
||||
@@ -1217,7 +1219,7 @@ class core_course_management_renderer extends plugin_renderer_base {
|
||||
'data-visible' => $course->visible ? '1' : '0'
|
||||
);
|
||||
$bulkcourseinput = '';
|
||||
if (coursecat::get($course->category)->can_move_courses_out_of()) {
|
||||
if (core_course_category::get($course->category)->can_move_courses_out_of()) {
|
||||
$bulkcourseinput = array(
|
||||
'type' => 'checkbox',
|
||||
'name' => 'bc[]',
|
||||
@@ -1228,7 +1230,7 @@ class core_course_management_renderer extends plugin_renderer_base {
|
||||
);
|
||||
}
|
||||
$viewcourseurl = new moodle_url($this->page->url, array('courseid' => $course->id));
|
||||
$categoryname = coursecat::get($course->category)->get_formatted_name();
|
||||
$categoryname = core_course_category::get($course->category)->get_formatted_name();
|
||||
|
||||
$html = html_writer::start_tag('li', $attributes);
|
||||
$html .= html_writer::start_div('clearfix');
|
||||
@@ -1251,10 +1253,10 @@ class core_course_management_renderer extends plugin_renderer_base {
|
||||
/**
|
||||
* Renderers actions for individual course actions.
|
||||
*
|
||||
* @param course_in_list $course The course to renderer actions for.
|
||||
* @param core_course_list_element $course The course to renderer actions for.
|
||||
* @return string
|
||||
*/
|
||||
public function search_listitem_actions(course_in_list $course) {
|
||||
public function search_listitem_actions(core_course_list_element $course) {
|
||||
$baseurl = new moodle_url(
|
||||
'/course/managementsearch.php',
|
||||
array('courseid' => $course->id, 'categoryid' => $course->category, 'sesskey' => sesskey())
|
||||
|
||||
@@ -138,8 +138,7 @@ class course_completion_form extends moodleform {
|
||||
|
||||
if (!empty($courses)) {
|
||||
// Get category list.
|
||||
require_once($CFG->libdir. '/coursecatlib.php');
|
||||
$list = coursecat::make_categories_list();
|
||||
$list = core_course_category::make_categories_list();
|
||||
|
||||
// Get course list for select box.
|
||||
$selectbox = array();
|
||||
|
||||
@@ -4,7 +4,6 @@ defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
require_once($CFG->libdir.'/formslib.php');
|
||||
require_once($CFG->libdir.'/completionlib.php');
|
||||
require_once($CFG->libdir. '/coursecatlib.php');
|
||||
|
||||
/**
|
||||
* The form for handling editing a course.
|
||||
@@ -77,7 +76,7 @@ class course_edit_form extends moodleform {
|
||||
// Verify permissions to change course category or keep current.
|
||||
if (empty($course->id)) {
|
||||
if (has_capability('moodle/course:create', $categorycontext)) {
|
||||
$displaylist = coursecat::make_categories_list('moodle/course:create');
|
||||
$displaylist = core_course_category::make_categories_list('moodle/course:create');
|
||||
$mform->addElement('select', 'category', get_string('coursecategory'), $displaylist);
|
||||
$mform->addHelpButton('category', 'coursecategory');
|
||||
$mform->setDefault('category', $category->id);
|
||||
@@ -88,10 +87,11 @@ class course_edit_form extends moodleform {
|
||||
}
|
||||
} else {
|
||||
if (has_capability('moodle/course:changecategory', $coursecontext)) {
|
||||
$displaylist = coursecat::make_categories_list('moodle/course:changecategory');
|
||||
$displaylist = core_course_category::make_categories_list('moodle/course:changecategory');
|
||||
if (!isset($displaylist[$course->category])) {
|
||||
//always keep current
|
||||
$displaylist[$course->category] = coursecat::get($course->category, MUST_EXIST, true)->get_formatted_name();
|
||||
$displaylist[$course->category] = core_course_category::get($course->category, MUST_EXIST, true)
|
||||
->get_formatted_name();
|
||||
}
|
||||
$mform->addElement('select', 'category', get_string('coursecategory'), $displaylist);
|
||||
$mform->addHelpButton('category', 'coursecategory');
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->dirroot.'/course/lib.php');
|
||||
require_once($CFG->libdir.'/coursecatlib.php');
|
||||
|
||||
require_login();
|
||||
|
||||
@@ -36,7 +35,7 @@ $id = optional_param('id', 0, PARAM_INT);
|
||||
|
||||
$url = new moodle_url('/course/editcategory.php');
|
||||
if ($id) {
|
||||
$coursecat = coursecat::get($id, MUST_EXIST, true);
|
||||
$coursecat = core_course_category::get($id, MUST_EXIST, true);
|
||||
$category = $coursecat->get_db_record();
|
||||
$context = context_coursecat::instance($id);
|
||||
|
||||
@@ -105,7 +104,7 @@ if ($mform->is_cancelled()) {
|
||||
}
|
||||
$coursecat->update($data, $mform->get_description_editor_options());
|
||||
} else {
|
||||
$category = coursecat::create($data, $mform->get_description_editor_options());
|
||||
$category = core_course_category::create($data, $mform->get_description_editor_options());
|
||||
}
|
||||
$manageurl->param('categoryid', $category->id);
|
||||
redirect($manageurl);
|
||||
|
||||
+13
-18
@@ -1845,8 +1845,7 @@ class core_course_external extends external_api {
|
||||
* @since Moodle 2.3
|
||||
*/
|
||||
public static function create_categories($categories) {
|
||||
global $CFG, $DB;
|
||||
require_once($CFG->libdir . "/coursecatlib.php");
|
||||
global $DB;
|
||||
|
||||
$params = self::validate_parameters(self::create_categories_parameters(),
|
||||
array('categories' => $categories));
|
||||
@@ -1869,7 +1868,7 @@ class core_course_external extends external_api {
|
||||
// this will validate format and throw an exception if there are errors
|
||||
external_validate_format($category['descriptionformat']);
|
||||
|
||||
$newcategory = coursecat::create($category);
|
||||
$newcategory = core_course_category::create($category);
|
||||
$context = context_coursecat::instance($newcategory->id);
|
||||
|
||||
$createdcategories[] = array(
|
||||
@@ -1935,8 +1934,7 @@ class core_course_external extends external_api {
|
||||
* @since Moodle 2.3
|
||||
*/
|
||||
public static function update_categories($categories) {
|
||||
global $CFG, $DB;
|
||||
require_once($CFG->libdir . "/coursecatlib.php");
|
||||
global $DB;
|
||||
|
||||
// Validate parameters.
|
||||
$params = self::validate_parameters(self::update_categories_parameters(), array('categories' => $categories));
|
||||
@@ -1944,7 +1942,7 @@ class core_course_external extends external_api {
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
|
||||
foreach ($params['categories'] as $cat) {
|
||||
$category = coursecat::get($cat['id']);
|
||||
$category = core_course_category::get($cat['id']);
|
||||
|
||||
$categorycontext = context_coursecat::instance($cat['id']);
|
||||
self::validate_context($categorycontext);
|
||||
@@ -2003,7 +2001,6 @@ class core_course_external extends external_api {
|
||||
public static function delete_categories($categories) {
|
||||
global $CFG, $DB;
|
||||
require_once($CFG->dirroot . "/course/lib.php");
|
||||
require_once($CFG->libdir . "/coursecatlib.php");
|
||||
|
||||
// Validate parameters.
|
||||
$params = self::validate_parameters(self::delete_categories_parameters(), array('categories' => $categories));
|
||||
@@ -2011,7 +2008,7 @@ class core_course_external extends external_api {
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
|
||||
foreach ($params['categories'] as $category) {
|
||||
$deletecat = coursecat::get($category['id'], MUST_EXIST);
|
||||
$deletecat = core_course_category::get($category['id'], MUST_EXIST);
|
||||
$context = context_coursecat::instance($deletecat->id);
|
||||
require_capability('moodle/category:manage', $context);
|
||||
self::validate_context($context);
|
||||
@@ -2029,9 +2026,9 @@ class core_course_external extends external_api {
|
||||
// If the parent is the root, moving is not supported (because a course must always be inside a category).
|
||||
// We must move to an existing category.
|
||||
if (!empty($category['newparent'])) {
|
||||
$newparentcat = coursecat::get($category['newparent']);
|
||||
$newparentcat = core_course_category::get($category['newparent']);
|
||||
} else {
|
||||
$newparentcat = coursecat::get($deletecat->parent);
|
||||
$newparentcat = core_course_category::get($deletecat->parent);
|
||||
}
|
||||
|
||||
// This operation is not allowed. We must move contents to an existing category.
|
||||
@@ -2227,18 +2224,18 @@ class core_course_external extends external_api {
|
||||
/**
|
||||
* Return the course information that is public (visible by every one)
|
||||
*
|
||||
* @param course_in_list $course course in list object
|
||||
* @param core_course_list_element $course course in list object
|
||||
* @param stdClass $coursecontext course context object
|
||||
* @return array the course information
|
||||
* @since Moodle 3.2
|
||||
*/
|
||||
protected static function get_course_public_information(course_in_list $course, $coursecontext) {
|
||||
protected static function get_course_public_information(core_course_list_element $course, $coursecontext) {
|
||||
|
||||
static $categoriescache = array();
|
||||
|
||||
// Category information.
|
||||
if (!array_key_exists($course->category, $categoriescache)) {
|
||||
$categoriescache[$course->category] = coursecat::get($course->category, IGNORE_MISSING);
|
||||
$categoriescache[$course->category] = core_course_category::get($course->category, IGNORE_MISSING);
|
||||
}
|
||||
$category = $categoriescache[$course->category];
|
||||
|
||||
@@ -2322,7 +2319,6 @@ class core_course_external extends external_api {
|
||||
$requiredcapabilities=array(),
|
||||
$limittoenrolled=0) {
|
||||
global $CFG;
|
||||
require_once($CFG->libdir . '/coursecatlib.php');
|
||||
|
||||
$warnings = array();
|
||||
|
||||
@@ -2365,8 +2361,8 @@ class core_course_external extends external_api {
|
||||
}
|
||||
|
||||
// Search the courses.
|
||||
$courses = coursecat::search_courses($searchcriteria, $options, $params['requiredcapabilities']);
|
||||
$totalcount = coursecat::search_courses_count($searchcriteria, $options, $params['requiredcapabilities']);
|
||||
$courses = core_course_category::search_courses($searchcriteria, $options, $params['requiredcapabilities']);
|
||||
$totalcount = core_course_category::search_courses_count($searchcriteria, $options, $params['requiredcapabilities']);
|
||||
|
||||
if (!empty($limittoenrolled)) {
|
||||
// Get the courses where the current user has access.
|
||||
@@ -3016,7 +3012,6 @@ class core_course_external extends external_api {
|
||||
*/
|
||||
public static function get_courses_by_field($field = '', $value = '') {
|
||||
global $DB, $CFG;
|
||||
require_once($CFG->libdir . '/coursecatlib.php');
|
||||
require_once($CFG->libdir . '/filterlib.php');
|
||||
|
||||
$params = self::validate_parameters(self::get_courses_by_field_parameters(),
|
||||
@@ -3066,7 +3061,7 @@ class core_course_external extends external_api {
|
||||
continue;
|
||||
}
|
||||
// Get the public course information, even if we are not enrolled.
|
||||
$courseinlist = new course_in_list($course);
|
||||
$courseinlist = new core_course_list_element($course);
|
||||
$coursesdata[$course->id] = self::get_course_public_information($courseinlist, $context);
|
||||
|
||||
// Now, check if we have access to the course.
|
||||
|
||||
+2
-3
@@ -25,7 +25,6 @@
|
||||
|
||||
require_once("../config.php");
|
||||
require_once($CFG->dirroot. '/course/lib.php');
|
||||
require_once($CFG->libdir. '/coursecatlib.php');
|
||||
|
||||
$categoryid = optional_param('categoryid', 0, PARAM_INT); // Category id
|
||||
$site = get_site();
|
||||
@@ -38,8 +37,8 @@ if ($categoryid) {
|
||||
$category = $PAGE->category;
|
||||
} else {
|
||||
// Check if there is only one category, if so use that.
|
||||
if (coursecat::count_all() == 1) {
|
||||
$category = coursecat::get_default();
|
||||
if (core_course_category::count_all() == 1) {
|
||||
$category = core_course_category::get_default();
|
||||
|
||||
$categoryid = $category->id;
|
||||
$PAGE->set_category_by_id($categoryid);
|
||||
|
||||
+11
-15
@@ -728,15 +728,13 @@ function get_category_or_system_context($categoryid) {
|
||||
/**
|
||||
* Returns full course categories trees to be used in html_writer::select()
|
||||
*
|
||||
* Calls {@link coursecat::make_categories_list()} to build the tree and
|
||||
* Calls {@link core_course_category::make_categories_list()} to build the tree and
|
||||
* adds whitespace to denote nesting
|
||||
*
|
||||
* @return array array mapping coursecat id to the display name
|
||||
* @return array array mapping course category id to the display name
|
||||
*/
|
||||
function make_categories_options() {
|
||||
global $CFG;
|
||||
require_once($CFG->libdir. '/coursecatlib.php');
|
||||
$cats = coursecat::make_categories_list('', 0, ' / ');
|
||||
$cats = core_course_category::make_categories_list('', 0, ' / ');
|
||||
foreach ($cats as $key => $value) {
|
||||
// Prefix the value with the number of spaces equal to category depth (number of separators in the value).
|
||||
$cats[$key] = str_repeat(' ', substr_count($value, ' / ')). $value;
|
||||
@@ -2322,14 +2320,14 @@ function save_local_role_names($courseid, $data) {
|
||||
$DB->insert_record('role_names', $rolename);
|
||||
}
|
||||
// This will ensure the course contacts cache is purged..
|
||||
coursecat::role_assignment_changed($roleid, $context);
|
||||
core_course_category::role_assignment_changed($roleid, $context);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns options to use in course overviewfiles filemanager
|
||||
*
|
||||
* @param null|stdClass|course_in_list|int $course either object that has 'id' property or just the course id;
|
||||
* @param null|stdClass|core_course_list_element|int $course either object that has 'id' property or just the course id;
|
||||
* may be empty if course does not exist yet (course create form)
|
||||
* @return array|null array of options such as maxfiles, maxbytes, accepted_types, etc.
|
||||
* or null if overviewfiles are disabled
|
||||
@@ -2911,20 +2909,19 @@ class course_request {
|
||||
* hidden categories if he has capabilities 'moodle/site:approvecourse' and
|
||||
* 'moodle/course:changecategory'
|
||||
*
|
||||
* @return coursecat
|
||||
* @return core_course_category
|
||||
*/
|
||||
public function get_category() {
|
||||
global $CFG;
|
||||
require_once($CFG->libdir.'/coursecatlib.php');
|
||||
// If the category is not set, if the current user does not have the rights to change the category, or if the
|
||||
// category does not exist, we set the default category to the course to be approved.
|
||||
// The system level is used because the capability moodle/site:approvecourse is based on a system level.
|
||||
if (empty($this->properties->category) || !has_capability('moodle/course:changecategory', context_system::instance()) ||
|
||||
(!$category = coursecat::get($this->properties->category, IGNORE_MISSING, true))) {
|
||||
$category = coursecat::get($CFG->defaultrequestcategory, IGNORE_MISSING, true);
|
||||
(!$category = core_course_category::get($this->properties->category, IGNORE_MISSING, true))) {
|
||||
$category = core_course_category::get($CFG->defaultrequestcategory, IGNORE_MISSING, true);
|
||||
}
|
||||
if (!$category) {
|
||||
$category = coursecat::get_default();
|
||||
$category = core_course_category::get_default();
|
||||
}
|
||||
return $category;
|
||||
}
|
||||
@@ -3545,7 +3542,7 @@ function course_change_visibility($courseid, $show = true) {
|
||||
/**
|
||||
* Changes the course sortorder by one, moving it up or down one in respect to sort order.
|
||||
*
|
||||
* @param stdClass|course_in_list $course
|
||||
* @param stdClass|core_course_list_element $course
|
||||
* @param bool $up If set to true the course will be moved up one. Otherwise down one.
|
||||
* @return bool
|
||||
*/
|
||||
@@ -3674,7 +3671,6 @@ function course_view($context, $sectionnumber = 0) {
|
||||
*/
|
||||
function course_get_tagged_courses($tag, $exclusivemode = false, $fromctx = 0, $ctx = 0, $rec = 1, $page = 0) {
|
||||
global $CFG, $PAGE;
|
||||
require_once($CFG->libdir . '/coursecatlib.php');
|
||||
|
||||
$perpage = $exclusivemode ? $CFG->coursesperpage : 5;
|
||||
$displayoptions = array(
|
||||
@@ -3684,7 +3680,7 @@ function course_get_tagged_courses($tag, $exclusivemode = false, $fromctx = 0, $
|
||||
);
|
||||
|
||||
$courserenderer = $PAGE->get_renderer('core', 'course');
|
||||
$totalcount = coursecat::search_courses_count(array('tagid' => $tag->id, 'ctx' => $ctx, 'rec' => $rec));
|
||||
$totalcount = core_course_category::search_courses_count(array('tagid' => $tag->id, 'ctx' => $ctx, 'rec' => $rec));
|
||||
$content = $courserenderer->tagged_courses($tag->id, $exclusivemode, $ctx, $rec, $displayoptions);
|
||||
$totalpages = ceil($totalcount / $perpage);
|
||||
|
||||
|
||||
+20
-20
@@ -23,7 +23,6 @@
|
||||
*/
|
||||
|
||||
require_once('../config.php');
|
||||
require_once($CFG->dirroot.'/lib/coursecatlib.php');
|
||||
require_once($CFG->dirroot.'/course/lib.php');
|
||||
|
||||
$categoryid = optional_param('categoryid', null, PARAM_INT);
|
||||
@@ -52,8 +51,8 @@ $url = new moodle_url('/course/management.php');
|
||||
$systemcontext = $context = context_system::instance();
|
||||
if ($courseid) {
|
||||
$record = get_course($courseid);
|
||||
$course = new course_in_list($record);
|
||||
$category = coursecat::get($course->category);
|
||||
$course = new core_course_list_element($record);
|
||||
$category = core_course_category::get($course->category);
|
||||
$categoryid = $category->id;
|
||||
$context = context_coursecat::instance($category->id);
|
||||
$url->param('categoryid', $categoryid);
|
||||
@@ -62,14 +61,14 @@ if ($courseid) {
|
||||
} else if ($categoryid) {
|
||||
$courseid = null;
|
||||
$course = null;
|
||||
$category = coursecat::get($categoryid);
|
||||
$category = core_course_category::get($categoryid);
|
||||
$context = context_coursecat::instance($category->id);
|
||||
$url->param('categoryid', $category->id);
|
||||
|
||||
} else {
|
||||
$course = null;
|
||||
$courseid = null;
|
||||
$category = coursecat::get_default();
|
||||
$category = core_course_category::get_default();
|
||||
$categoryid = $category->id;
|
||||
$context = context_coursecat::instance($category->id);
|
||||
$url->param('categoryid', $category->id);
|
||||
@@ -108,7 +107,7 @@ $PAGE->set_heading($pageheading);
|
||||
// This is a system level page that operates on other contexts.
|
||||
require_login();
|
||||
|
||||
if (!coursecat::has_capability_on_any(array('moodle/category:manage', 'moodle/course:create'))) {
|
||||
if (!core_course_category::has_capability_on_any(array('moodle/category:manage', 'moodle/course:create'))) {
|
||||
// The user isn't able to manage any categories. Lets redirect them to the relevant course/index.php page.
|
||||
$url = new moodle_url('/course/index.php');
|
||||
if ($categoryid) {
|
||||
@@ -141,7 +140,7 @@ if ($category && !has_any_capability($capabilities, $systemcontext)) {
|
||||
navigation_node::override_active_url(new moodle_url('/course/management.php'));
|
||||
}
|
||||
if (!$issearching && $category !== null) {
|
||||
$parents = coursecat::get_many($category->get_parents());
|
||||
$parents = core_course_category::get_many($category->get_parents());
|
||||
$parents[] = $category;
|
||||
foreach ($parents as $parent) {
|
||||
$PAGE->navbar->add(
|
||||
@@ -149,7 +148,7 @@ if (!$issearching && $category !== null) {
|
||||
new moodle_url('/course/management.php', array('categoryid' => $parent->id))
|
||||
);
|
||||
}
|
||||
if ($course instanceof course_in_list) {
|
||||
if ($course instanceof core_course_list_element) {
|
||||
// Use the list name so that it matches whats being displayed below.
|
||||
$PAGE->navbar->add($course->get_formatted_name());
|
||||
}
|
||||
@@ -180,7 +179,7 @@ if ($action !== false && confirm_sesskey()) {
|
||||
switch ($action) {
|
||||
case 'resortcategories' :
|
||||
$sort = required_param('resort', PARAM_ALPHA);
|
||||
$cattosort = coursecat::get((int)optional_param('categoryid', 0, PARAM_INT));
|
||||
$cattosort = core_course_category::get((int)optional_param('categoryid', 0, PARAM_INT));
|
||||
$redirectback = \core_course\management\helper::action_category_resort_subcategories($cattosort, $sort);
|
||||
break;
|
||||
case 'resortcourses' :
|
||||
@@ -231,7 +230,7 @@ if ($action !== false && confirm_sesskey()) {
|
||||
// They must have specified a category.
|
||||
required_param('categoryid', PARAM_INT);
|
||||
if (!$category->can_delete()) {
|
||||
throw new moodle_exception('permissiondenied', 'error', '', null, 'coursecat::can_resort');
|
||||
throw new moodle_exception('permissiondenied', 'error', '', null, 'core_course_category::can_resort');
|
||||
}
|
||||
$mform = new core_course_deletecategory_form(null, $category);
|
||||
if ($mform->is_cancelled()) {
|
||||
@@ -287,7 +286,7 @@ if ($action !== false && confirm_sesskey()) {
|
||||
if ($courseids === false) {
|
||||
break;
|
||||
}
|
||||
$moveto = coursecat::get($movetoid);
|
||||
$moveto = core_course_category::get($movetoid);
|
||||
try {
|
||||
// If this fails we want to catch the exception and report it.
|
||||
$redirectback = \core_course\management\helper::move_courses_into_category($moveto,
|
||||
@@ -305,10 +304,10 @@ if ($action !== false && confirm_sesskey()) {
|
||||
} else if ($bulkmovecategories) {
|
||||
$categoryids = optional_param_array('bcat', array(), PARAM_INT);
|
||||
$movetocatid = required_param('movecategoriesto', PARAM_INT);
|
||||
$movetocat = coursecat::get($movetocatid);
|
||||
$movetocat = core_course_category::get($movetocatid);
|
||||
$movecount = 0;
|
||||
foreach ($categoryids as $id) {
|
||||
$cattomove = coursecat::get($id);
|
||||
$cattomove = core_course_category::get($id);
|
||||
if ($id == $movetocatid) {
|
||||
$notificationsfail[] = get_string('movecategoryownparent', 'error', $cattomove->get_formatted_name());
|
||||
continue;
|
||||
@@ -369,7 +368,7 @@ if ($action !== false && confirm_sesskey()) {
|
||||
$categoryids = array(
|
||||
required_param('currentcategoryid', PARAM_INT)
|
||||
);
|
||||
$categories = coursecat::get_many($categoryids);
|
||||
$categories = core_course_category::get_many($categoryids);
|
||||
} else if ($for === 'selectedcategories') {
|
||||
// Bulk resort selected categories.
|
||||
$categoryids = optional_param_array('bcat', false, PARAM_INT);
|
||||
@@ -377,14 +376,15 @@ if ($action !== false && confirm_sesskey()) {
|
||||
if ($categoryids === false) {
|
||||
break;
|
||||
}
|
||||
$categories = coursecat::get_many($categoryids);
|
||||
$categories = core_course_category::get_many($categoryids);
|
||||
} else if ($for === 'allcategories') {
|
||||
if ($sortcategoriesby && coursecat::get(0)->can_resort_subcategories()) {
|
||||
\core_course\management\helper::action_category_resort_subcategories(coursecat::get(0), $sortcategoriesby);
|
||||
if ($sortcategoriesby && core_course_category::get(0)->can_resort_subcategories()) {
|
||||
\core_course\management\helper::action_category_resort_subcategories(
|
||||
core_course_category::get(0), $sortcategoriesby);
|
||||
}
|
||||
$categorieslist = coursecat::make_categories_list('moodle/category:manage');
|
||||
$categorieslist = core_course_category::make_categories_list('moodle/category:manage');
|
||||
$categoryids = array_keys($categorieslist);
|
||||
$categories = coursecat::get_many($categoryids);
|
||||
$categories = core_course_category::get_many($categoryids);
|
||||
unset($categorieslist);
|
||||
} else {
|
||||
break;
|
||||
@@ -398,7 +398,7 @@ if ($action !== false && confirm_sesskey()) {
|
||||
\core_course\management\helper::action_category_resort_courses($cat, $sortcoursesby, false);
|
||||
}
|
||||
}
|
||||
coursecat::resort_categories_cleanup($sortcoursesby !== false);
|
||||
core_course_category::resort_categories_cleanup($sortcoursesby !== false);
|
||||
if ($category === null && count($categoryids) === 1) {
|
||||
// They're bulk sorting just a single category and they've not selected a category.
|
||||
// Lets for convenience sake auto-select the category that has been resorted for them.
|
||||
|
||||
+45
-54
@@ -78,7 +78,7 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
/**
|
||||
* Renders course info box.
|
||||
*
|
||||
* @param stdClass|course_in_list $course
|
||||
* @param stdClass $course
|
||||
* @return string
|
||||
*/
|
||||
public function course_info_box(stdClass $course) {
|
||||
@@ -1030,7 +1030,7 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
* bigger than count($courses), a paging bar is displayed above and under the
|
||||
* courses list.
|
||||
*
|
||||
* @param array $courses array of course records (or instances of course_in_list) to show on this page
|
||||
* @param array $courses array of course records (or instances of core_course_list_element) to show on this page
|
||||
* @param bool $showcategoryname whether to add category name to the course description
|
||||
* @param string $additionalclasses additional CSS classes to add to the div.courses
|
||||
* @param moodle_url $paginationurl url to view more or url to form links to the other pages in paging bar
|
||||
@@ -1075,13 +1075,12 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
* please use {@link core_course_renderer::course_info_box()}
|
||||
*
|
||||
* @param coursecat_helper $chelper various display options
|
||||
* @param course_in_list|stdClass $course
|
||||
* @param core_course_list_element|stdClass $course
|
||||
* @param string $additionalclasses additional classes to add to the main <div> tag (usually
|
||||
* depend on the course position in list - first/last/even/odd)
|
||||
* @return string
|
||||
*/
|
||||
protected function coursecat_coursebox(coursecat_helper $chelper, $course, $additionalclasses = '') {
|
||||
global $CFG;
|
||||
if (!isset($this->strings->summary)) {
|
||||
$this->strings->summary = get_string('summary');
|
||||
}
|
||||
@@ -1089,8 +1088,7 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
return '';
|
||||
}
|
||||
if ($course instanceof stdClass) {
|
||||
require_once($CFG->libdir. '/coursecatlib.php');
|
||||
$course = new course_in_list($course);
|
||||
$course = new core_course_list_element($course);
|
||||
}
|
||||
$content = '';
|
||||
$classes = trim('coursebox clearfix '. $additionalclasses);
|
||||
@@ -1153,7 +1151,7 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
* This method is called from coursecat_coursebox() and may be re-used in AJAX
|
||||
*
|
||||
* @param coursecat_helper $chelper various display options
|
||||
* @param stdClass|course_in_list $course
|
||||
* @param stdClass|core_course_list_element $course
|
||||
* @return string
|
||||
*/
|
||||
protected function coursecat_coursebox_content(coursecat_helper $chelper, $course) {
|
||||
@@ -1162,8 +1160,7 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
return '';
|
||||
}
|
||||
if ($course instanceof stdClass) {
|
||||
require_once($CFG->libdir. '/coursecatlib.php');
|
||||
$course = new course_in_list($course);
|
||||
$course = new core_course_list_element($course);
|
||||
}
|
||||
$content = '';
|
||||
|
||||
@@ -1197,7 +1194,7 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
}
|
||||
$content .= $contentimages. $contentfiles;
|
||||
|
||||
// display course contacts. See course_in_list::get_course_contacts()
|
||||
// Display course contacts. See core_course_list_element::get_course_contacts().
|
||||
if ($course->has_course_contacts()) {
|
||||
$content .= html_writer::start_tag('ul', array('class' => 'teachers'));
|
||||
foreach ($course->get_course_contacts() as $userid => $coursecontact) {
|
||||
@@ -1212,8 +1209,7 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
|
||||
// display course category if necessary (for example in search results)
|
||||
if ($chelper->get_show_courses() == self::COURSECAT_SHOW_COURSES_EXPANDED_WITH_CAT) {
|
||||
require_once($CFG->libdir. '/coursecatlib.php');
|
||||
if ($cat = coursecat::get($course->category, IGNORE_MISSING)) {
|
||||
if ($cat = core_course_category::get($course->category, IGNORE_MISSING)) {
|
||||
$content .= html_writer::start_tag('div', array('class' => 'coursecat'));
|
||||
$content .= get_string('category').': '.
|
||||
html_writer::link(new moodle_url('/course/index.php', array('categoryid' => $cat->id)),
|
||||
@@ -1323,7 +1319,7 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
* Renders the list of subcategories in a category
|
||||
*
|
||||
* @param coursecat_helper $chelper various display options
|
||||
* @param coursecat $coursecat
|
||||
* @param core_course_category $coursecat
|
||||
* @param int $depth depth of the category in the current tree
|
||||
* @return string
|
||||
*/
|
||||
@@ -1335,7 +1331,8 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
}
|
||||
$totalcount = $coursecat->get_children_count();
|
||||
if (!$totalcount) {
|
||||
// Note that we call coursecat::get_children_count() AFTER coursecat::get_children() to avoid extra DB requests.
|
||||
// Note that we call core_course_category::get_children_count() AFTER core_course_category::get_children()
|
||||
// to avoid extra DB requests.
|
||||
// Categories count is cached during children categories retrieval.
|
||||
return '';
|
||||
}
|
||||
@@ -1410,7 +1407,7 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
* This method is re-used by AJAX to expand content of not loaded category
|
||||
*
|
||||
* @param coursecat_helper $chelper various display options
|
||||
* @param coursecat $coursecat
|
||||
* @param core_course_category $coursecat
|
||||
* @param int $depth depth of the category in the current tree
|
||||
* @return string
|
||||
*/
|
||||
@@ -1457,7 +1454,7 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
* use {@link core_course_renderer::course_category()}
|
||||
*
|
||||
* @param coursecat_helper $chelper various display options
|
||||
* @param coursecat $coursecat
|
||||
* @param core_course_category $coursecat
|
||||
* @param int $depth depth of this category in the current tree
|
||||
* @return string
|
||||
*/
|
||||
@@ -1526,7 +1523,7 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
* Returns HTML to display a tree of subcategories and courses in the given category
|
||||
*
|
||||
* @param coursecat_helper $chelper various display options
|
||||
* @param coursecat $coursecat top category (this category's name and description will NOT be added to the tree)
|
||||
* @param core_course_category $coursecat top category (this category's name and description will NOT be added to the tree)
|
||||
* @return string
|
||||
*/
|
||||
protected function coursecat_tree(coursecat_helper $chelper, $coursecat) {
|
||||
@@ -1574,12 +1571,11 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
*
|
||||
* Invoked from /course/index.php
|
||||
*
|
||||
* @param int|stdClass|coursecat $category
|
||||
* @param int|stdClass|core_course_category $category
|
||||
*/
|
||||
public function course_category($category) {
|
||||
global $CFG;
|
||||
require_once($CFG->libdir. '/coursecatlib.php');
|
||||
$coursecat = coursecat::get(is_object($category) ? $category->id : $category);
|
||||
$coursecat = core_course_category::get(is_object($category) ? $category->id : $category);
|
||||
$site = get_site();
|
||||
$output = '';
|
||||
|
||||
@@ -1590,9 +1586,9 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
$this->page->set_button($managebutton);
|
||||
}
|
||||
if (!$coursecat->id) {
|
||||
if (coursecat::count_all() == 1) {
|
||||
if (core_course_category::count_all() == 1) {
|
||||
// There exists only one category in the system, do not display link to it
|
||||
$coursecat = coursecat::get_default();
|
||||
$coursecat = core_course_category::get_default();
|
||||
$strfulllistofcourses = get_string('fulllistofcourses');
|
||||
$this->page->set_title("$site->shortname: $strfulllistofcourses");
|
||||
} else {
|
||||
@@ -1601,16 +1597,16 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
}
|
||||
} else {
|
||||
$title = $site->shortname;
|
||||
if (coursecat::count_all() > 1) {
|
||||
if (core_course_category::count_all() > 1) {
|
||||
$title .= ": ". $coursecat->get_formatted_name();
|
||||
}
|
||||
$this->page->set_title($title);
|
||||
|
||||
// Print the category selector
|
||||
if (coursecat::count_all() > 1) {
|
||||
if (core_course_category::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');
|
||||
core_course_category::make_categories_list(), $coursecat->id, null, 'switchcategory');
|
||||
$select->set_label(get_string('categories').':');
|
||||
$output .= $this->render($select);
|
||||
$output .= html_writer::end_tag('div'); // .categorypicker
|
||||
@@ -1678,7 +1674,7 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
$output .= $this->single_button($url, get_string('addnewcourse'), 'get');
|
||||
}
|
||||
ob_start();
|
||||
if (coursecat::count_all() == 1) {
|
||||
if (core_course_category::count_all() == 1) {
|
||||
print_course_request_buttons(context_system::instance());
|
||||
} else {
|
||||
print_course_request_buttons($context);
|
||||
@@ -1701,7 +1697,6 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
*/
|
||||
public function coursecat_ajax() {
|
||||
global $DB, $CFG;
|
||||
require_once($CFG->libdir. '/coursecatlib.php');
|
||||
|
||||
$type = required_param('type', PARAM_INT);
|
||||
|
||||
@@ -1711,7 +1706,7 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
$showcourses = required_param('showcourses', PARAM_INT);
|
||||
$depth = required_param('depth', PARAM_INT);
|
||||
|
||||
$category = coursecat::get($categoryid);
|
||||
$category = core_course_category::get($categoryid);
|
||||
|
||||
$chelper = new coursecat_helper();
|
||||
$baseurl = new moodle_url('/course/index.php', array('categoryid' => $categoryid));
|
||||
@@ -1753,7 +1748,6 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
$content = '';
|
||||
if (!empty($searchcriteria)) {
|
||||
// print search results
|
||||
require_once($CFG->libdir. '/coursecatlib.php');
|
||||
|
||||
$displayoptions = array('sort' => array('displayname' => 1));
|
||||
// take the current page and number of results per page from query
|
||||
@@ -1779,8 +1773,8 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
set_search_criteria($searchcriteria)->
|
||||
set_attributes(array('class' => $class));
|
||||
|
||||
$courses = coursecat::search_courses($searchcriteria, $chelper->get_courses_display_options());
|
||||
$totalcount = coursecat::search_courses_count($searchcriteria);
|
||||
$courses = core_course_category::search_courses($searchcriteria, $chelper->get_courses_display_options());
|
||||
$totalcount = core_course_category::search_courses_count($searchcriteria);
|
||||
$courseslist = $this->coursecat_courses($chelper, $courses, $totalcount);
|
||||
|
||||
if (!$totalcount) {
|
||||
@@ -1824,11 +1818,10 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
*/
|
||||
public function tagged_courses($tagid, $exclusivemode = true, $ctx = 0, $rec = true, $displayoptions = null) {
|
||||
global $CFG;
|
||||
require_once($CFG->libdir . '/coursecatlib.php');
|
||||
if (empty($displayoptions)) {
|
||||
$displayoptions = array();
|
||||
}
|
||||
$showcategories = coursecat::count_all() > 1;
|
||||
$showcategories = core_course_category::count_all() > 1;
|
||||
$displayoptions += array('limit' => $CFG->coursesperpage, 'offset' => 0);
|
||||
$chelper = new coursecat_helper();
|
||||
$searchcriteria = array('tagid' => $tagid, 'ctx' => $ctx, 'rec' => $rec);
|
||||
@@ -1838,8 +1831,8 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
set_courses_display_options($displayoptions)->
|
||||
set_attributes(array('class' => 'course-search-result course-search-result-tagid'));
|
||||
// (we set the same css class as in search results by tagid)
|
||||
if ($totalcount = coursecat::search_courses_count($searchcriteria)) {
|
||||
$courses = coursecat::search_courses($searchcriteria, $chelper->get_courses_display_options());
|
||||
if ($totalcount = core_course_category::search_courses_count($searchcriteria)) {
|
||||
$courses = core_course_category::search_courses($searchcriteria, $chelper->get_courses_display_options());
|
||||
if ($exclusivemode) {
|
||||
return $this->coursecat_courses($chelper, $courses, $totalcount);
|
||||
} else {
|
||||
@@ -1850,7 +1843,7 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
$imgwithlink = html_writer::link($url, $img);
|
||||
$coursename = html_writer::link($url, $course->get_formatted_name());
|
||||
$details = '';
|
||||
if ($showcategories && ($cat = coursecat::get($course->category, IGNORE_MISSING))) {
|
||||
if ($showcategories && ($cat = core_course_category::get($course->category, IGNORE_MISSING))) {
|
||||
$details = get_string('category').': '.
|
||||
html_writer::link(new moodle_url('/course/index.php', array('categoryid' => $cat->id)),
|
||||
$cat->get_formatted_name(), array('class' => $cat->visible ? '' : 'dimmed'));
|
||||
@@ -1997,7 +1990,6 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
*/
|
||||
public function frontpage_available_courses() {
|
||||
global $CFG;
|
||||
require_once($CFG->libdir. '/coursecatlib.php');
|
||||
|
||||
$chelper = new coursecat_helper();
|
||||
$chelper->set_show_courses(self::COURSECAT_SHOW_COURSES_EXPANDED)->
|
||||
@@ -2008,8 +2000,8 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
'viewmoretext' => new lang_string('fulllistofcourses')));
|
||||
|
||||
$chelper->set_attributes(array('class' => 'frontpage-course-list-all'));
|
||||
$courses = coursecat::get(0)->get_courses($chelper->get_courses_display_options());
|
||||
$totalcount = coursecat::get(0)->get_courses_count($chelper->get_courses_display_options());
|
||||
$courses = core_course_category::get(0)->get_courses($chelper->get_courses_display_options());
|
||||
$totalcount = core_course_category::get(0)->get_courses_count($chelper->get_courses_display_options());
|
||||
if (!$totalcount && !$this->page->user_is_editing() && has_capability('moodle/course:create', context_system::instance())) {
|
||||
// Print link to create a new course, for the 1st available category.
|
||||
return $this->add_new_course_button();
|
||||
@@ -2039,7 +2031,6 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
*/
|
||||
public function frontpage_combo_list() {
|
||||
global $CFG;
|
||||
require_once($CFG->libdir. '/coursecatlib.php');
|
||||
$chelper = new coursecat_helper();
|
||||
$chelper->set_subcat_depth($CFG->maxcategorydepth)->
|
||||
set_categories_display_options(array(
|
||||
@@ -2053,7 +2044,7 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
array('browse' => 'courses', 'page' => 1))
|
||||
))->
|
||||
set_attributes(array('class' => 'frontpage-category-combo'));
|
||||
return $this->coursecat_tree($chelper, coursecat::get(0));
|
||||
return $this->coursecat_tree($chelper, core_course_category::get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2063,7 +2054,6 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
*/
|
||||
public function frontpage_categories_list() {
|
||||
global $CFG;
|
||||
require_once($CFG->libdir. '/coursecatlib.php');
|
||||
$chelper = new coursecat_helper();
|
||||
$chelper->set_subcat_depth($CFG->maxcategorydepth)->
|
||||
set_show_courses(self::COURSECAT_SHOW_COURSES_COUNT)->
|
||||
@@ -2073,7 +2063,7 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
array('browse' => 'categories', 'page' => 1))
|
||||
))->
|
||||
set_attributes(array('class' => 'frontpage-category-names'));
|
||||
return $this->coursecat_tree($chelper, coursecat::get(0));
|
||||
return $this->coursecat_tree($chelper, core_course_category::get(0));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2469,7 +2459,7 @@ class core_course_renderer extends plugin_renderer_base {
|
||||
/**
|
||||
* Class storing display options and functions to help display course category and/or courses lists
|
||||
*
|
||||
* This is a wrapper for coursecat objects that also stores display options
|
||||
* This is a wrapper for core_course_category objects that also stores display options
|
||||
* and functions to retrieve sorted and paginated lists of categories/courses.
|
||||
*
|
||||
* If theme overrides methods in core_course_renderers that access this class
|
||||
@@ -2501,7 +2491,8 @@ class coursecat_helper {
|
||||
*/
|
||||
public function set_show_courses($showcourses) {
|
||||
$this->showcourses = $showcourses;
|
||||
// Automatically set the options to preload summary and coursecontacts for coursecat::get_courses() and coursecat::search_courses()
|
||||
// Automatically set the options to preload summary and coursecontacts for core_course_category::get_courses()
|
||||
// and core_course_category::search_courses().
|
||||
$this->coursesdisplayoptions['summary'] = $showcourses >= core_course_renderer::COURSECAT_SHOW_COURSES_AUTO;
|
||||
$this->coursesdisplayoptions['coursecontacts'] = $showcourses >= core_course_renderer::COURSECAT_SHOW_COURSES_EXPANDED;
|
||||
return $this;
|
||||
@@ -2543,9 +2534,9 @@ class coursecat_helper {
|
||||
/**
|
||||
* Sets options to display list of courses
|
||||
*
|
||||
* Options are later submitted as argument to coursecat::get_courses() and/or coursecat::search_courses()
|
||||
* Options are later submitted as argument to core_course_category::get_courses() and/or core_course_category::search_courses()
|
||||
*
|
||||
* Options that coursecat::get_courses() accept:
|
||||
* Options that core_course_category::get_courses() accept:
|
||||
* - recursive - return courses from subcategories as well. Use with care,
|
||||
* this may be a huge list!
|
||||
* - summary - preloads fields 'summary' and 'summaryformat'
|
||||
@@ -2604,8 +2595,8 @@ class coursecat_helper {
|
||||
/**
|
||||
* Returns all options to display the courses
|
||||
*
|
||||
* This array is usually passed to {@link coursecat::get_courses()} or
|
||||
* {@link coursecat::search_courses()}
|
||||
* This array is usually passed to {@link core_course_category::get_courses()} or
|
||||
* {@link core_course_category::search_courses()}
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -2616,7 +2607,7 @@ class coursecat_helper {
|
||||
/**
|
||||
* Sets options to display list of subcategories
|
||||
*
|
||||
* Options 'sort', 'offset' and 'limit' are passed to coursecat::get_children().
|
||||
* Options 'sort', 'offset' and 'limit' are passed to core_course_category::get_children().
|
||||
* Any other options may be used by renderer functions
|
||||
*
|
||||
* @param array $options
|
||||
@@ -2645,7 +2636,7 @@ class coursecat_helper {
|
||||
/**
|
||||
* Returns all options to display list of subcategories
|
||||
*
|
||||
* This array is usually passed to {@link coursecat::get_children()}
|
||||
* This array is usually passed to {@link core_course_category::get_children()}
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -2696,7 +2687,7 @@ class coursecat_helper {
|
||||
/**
|
||||
* Returns formatted and filtered description of the given category
|
||||
*
|
||||
* @param coursecat $coursecat category
|
||||
* @param core_course_category $coursecat category
|
||||
* @param stdClass|array $options format options, by default [noclean,overflowdiv],
|
||||
* if context is not specified it will be added automatically
|
||||
* @return string|null
|
||||
@@ -2727,7 +2718,7 @@ class coursecat_helper {
|
||||
/**
|
||||
* Returns given course's summary with proper embedded files urls and formatted
|
||||
*
|
||||
* @param course_in_list $course
|
||||
* @param core_course_list_element $course
|
||||
* @param array|stdClass $options additional formatting options
|
||||
* @return string
|
||||
*/
|
||||
@@ -2760,7 +2751,7 @@ class coursecat_helper {
|
||||
/**
|
||||
* Returns course name as it is configured to appear in courses lists formatted to course context
|
||||
*
|
||||
* @param course_in_list $course
|
||||
* @param core_course_list_element $course
|
||||
* @param array|stdClass $options additional formatting options
|
||||
* @return string
|
||||
*/
|
||||
|
||||
@@ -36,7 +36,6 @@ if (!defined('MOODLE_INTERNAL')) {
|
||||
}
|
||||
|
||||
require_once($CFG->libdir.'/formslib.php');
|
||||
require_once($CFG->libdir.'/coursecatlib.php');
|
||||
|
||||
/**
|
||||
* A form for a user to request a course.
|
||||
@@ -70,7 +69,7 @@ class course_request_form extends moodleform {
|
||||
$mform->setType('shortname', PARAM_TEXT);
|
||||
|
||||
if (!empty($CFG->requestcategoryselection)) {
|
||||
$displaylist = coursecat::make_categories_list();
|
||||
$displaylist = core_course_category::make_categories_list();
|
||||
$mform->addElement('select', 'category', get_string('coursecategory'), $displaylist);
|
||||
$mform->setDefault('category', $CFG->defaultrequestcategory);
|
||||
$mform->addHelpButton('category', 'coursecategory');
|
||||
|
||||
+1
-2
@@ -23,7 +23,6 @@
|
||||
|
||||
require_once("../config.php");
|
||||
require_once($CFG->dirroot.'/course/lib.php');
|
||||
require_once($CFG->libdir.'/coursecatlib.php');
|
||||
|
||||
$search = optional_param('search', '', PARAM_RAW); // search words
|
||||
$page = optional_param('page', 0, PARAM_INT); // which page to show
|
||||
@@ -36,7 +35,7 @@ $tagid = optional_param('tagid', '', PARAM_INT); // searches for courses t
|
||||
$capabilities = array('moodle/course:create', 'moodle/category:manage');
|
||||
|
||||
// Populate usercatlist with list of category id's with course:create and category:manage capabilities.
|
||||
$usercatlist = coursecat::make_categories_list($capabilities);
|
||||
$usercatlist = core_course_category::make_categories_list($capabilities);
|
||||
|
||||
$search = trim(strip_tags($search)); // trim & clean raw searched string
|
||||
|
||||
|
||||
@@ -1476,7 +1476,7 @@ class behat_course extends behat_base {
|
||||
$this->i_select_category_in_the_management_interface($name);
|
||||
|
||||
$this->execute('behat_forms::i_set_the_field_to',
|
||||
array('menumovecategoriesto', coursecat::get(0)->get_formatted_name())
|
||||
array('menumovecategoriesto', core_course_category::get(0)->get_formatted_name())
|
||||
);
|
||||
|
||||
// Save event.
|
||||
|
||||
@@ -15,9 +15,9 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Tests for class coursecat from lib/coursecatlib.php
|
||||
* Tests for class core_course_category
|
||||
*
|
||||
* @package core
|
||||
* @package core_course
|
||||
* @category phpunit
|
||||
* @copyright 2013 Marina Glancy
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
@@ -25,13 +25,10 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->libdir . '/coursecatlib.php');
|
||||
|
||||
/**
|
||||
* Functional test for coursecatlib.php
|
||||
* Functional test for class core_course_category
|
||||
*/
|
||||
class core_coursecatlib_testcase extends advanced_testcase {
|
||||
class core_course_category_testcase extends advanced_testcase {
|
||||
|
||||
protected $roles;
|
||||
|
||||
@@ -81,7 +78,7 @@ class core_coursecatlib_testcase extends advanced_testcase {
|
||||
$data->description = 'aaa';
|
||||
$data->idnumber = '';
|
||||
|
||||
$category1 = coursecat::create($data);
|
||||
$category1 = core_course_category::create($data);
|
||||
|
||||
// Initially confirm that base data was inserted correctly.
|
||||
$this->assertSame($data->name, $category1->name);
|
||||
@@ -92,10 +89,10 @@ class core_coursecatlib_testcase extends advanced_testcase {
|
||||
|
||||
// Create two more categories and test the sortorder worked correctly.
|
||||
$data->name = 'ccc';
|
||||
$category2 = coursecat::create($data);
|
||||
$category2 = core_course_category::create($data);
|
||||
|
||||
$data->name = 'bbb';
|
||||
$category3 = coursecat::create($data);
|
||||
$category3 = core_course_category::create($data);
|
||||
|
||||
$this->assertGreaterThan($category1->sortorder, $category2->sortorder);
|
||||
$this->assertGreaterThan($category2->sortorder, $category3->sortorder);
|
||||
@@ -103,43 +100,43 @@ class core_coursecatlib_testcase extends advanced_testcase {
|
||||
|
||||
public function test_name_idnumber_exceptions() {
|
||||
try {
|
||||
coursecat::create(array('name' => ''));
|
||||
$this->fail('Missing category name exception expected in coursecat::create');
|
||||
core_course_category::create(array('name' => ''));
|
||||
$this->fail('Missing category name exception expected in core_course_category::create');
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertInstanceOf('moodle_exception', $e);
|
||||
}
|
||||
$cat1 = coursecat::create(array('name' => 'Cat1', 'idnumber' => '1'));
|
||||
$cat1 = core_course_category::create(array('name' => 'Cat1', 'idnumber' => '1'));
|
||||
try {
|
||||
$cat1->update(array('name' => ''));
|
||||
$this->fail('Missing category name exception expected in coursecat::update');
|
||||
$this->fail('Missing category name exception expected in core_course_category::update');
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertInstanceOf('moodle_exception', $e);
|
||||
}
|
||||
try {
|
||||
coursecat::create(array('name' => 'Cat2', 'idnumber' => '1'));
|
||||
$this->fail('Duplicate idnumber exception expected in coursecat::create');
|
||||
core_course_category::create(array('name' => 'Cat2', 'idnumber' => '1'));
|
||||
$this->fail('Duplicate idnumber exception expected in core_course_category::create');
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertInstanceOf('moodle_exception', $e);
|
||||
}
|
||||
$cat2 = coursecat::create(array('name' => 'Cat2', 'idnumber' => '2'));
|
||||
$cat2 = core_course_category::create(array('name' => 'Cat2', 'idnumber' => '2'));
|
||||
try {
|
||||
$cat2->update(array('idnumber' => '1'));
|
||||
$this->fail('Duplicate idnumber exception expected in coursecat::update');
|
||||
$this->fail('Duplicate idnumber exception expected in core_course_category::update');
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertInstanceOf('moodle_exception', $e);
|
||||
}
|
||||
// Test that duplicates with an idnumber of 0 cannot be created.
|
||||
coursecat::create(array('name' => 'Cat3', 'idnumber' => '0'));
|
||||
core_course_category::create(array('name' => 'Cat3', 'idnumber' => '0'));
|
||||
try {
|
||||
coursecat::create(array('name' => 'Cat4', 'idnumber' => '0'));
|
||||
$this->fail('Duplicate idnumber "0" exception expected in coursecat::create');
|
||||
core_course_category::create(array('name' => 'Cat4', 'idnumber' => '0'));
|
||||
$this->fail('Duplicate idnumber "0" exception expected in core_course_category::create');
|
||||
} catch (moodle_exception $e) {
|
||||
$this->assertInstanceOf('moodle_exception', $e);
|
||||
}
|
||||
// Test an update cannot make a duplicate idnumber of 0.
|
||||
try {
|
||||
$cat2->update(array('idnumber' => '0'));
|
||||
$this->fail('Duplicate idnumber "0" exception expected in coursecat::update');
|
||||
$this->fail('Duplicate idnumber "0" exception expected in core_course_category::update');
|
||||
} catch (Exception $e) {
|
||||
$this->assertInstanceOf('moodle_exception', $e);
|
||||
}
|
||||
@@ -150,33 +147,33 @@ class core_coursecatlib_testcase extends advanced_testcase {
|
||||
$this->assign_capability('moodle/category:manage');
|
||||
|
||||
// Create category 1 initially hidden.
|
||||
$category1 = coursecat::create(array('name' => 'Cat1', 'visible' => 0));
|
||||
$category1 = core_course_category::create(array('name' => 'Cat1', 'visible' => 0));
|
||||
$this->assertEquals(0, $category1->visible);
|
||||
$this->assertEquals(0, $category1->visibleold);
|
||||
|
||||
// Create category 2 initially hidden as a child of hidden category 1.
|
||||
$category2 = coursecat::create(array('name' => 'Cat2', 'visible' => 0, 'parent' => $category1->id));
|
||||
$category2 = core_course_category::create(array('name' => 'Cat2', 'visible' => 0, 'parent' => $category1->id));
|
||||
$this->assertEquals(0, $category2->visible);
|
||||
$this->assertEquals(0, $category2->visibleold);
|
||||
|
||||
// Create category 3 initially visible as a child of hidden category 1.
|
||||
$category3 = coursecat::create(array('name' => 'Cat3', 'visible' => 1, 'parent' => $category1->id));
|
||||
$category3 = core_course_category::create(array('name' => 'Cat3', 'visible' => 1, 'parent' => $category1->id));
|
||||
$this->assertEquals(0, $category3->visible);
|
||||
$this->assertEquals(1, $category3->visibleold);
|
||||
|
||||
// Show category 1 and make sure that category 2 is hidden and category 3 is visible.
|
||||
$category1->show();
|
||||
$this->assertEquals(1, coursecat::get($category1->id)->visible);
|
||||
$this->assertEquals(0, coursecat::get($category2->id)->visible);
|
||||
$this->assertEquals(1, coursecat::get($category3->id)->visible);
|
||||
$this->assertEquals(1, core_course_category::get($category1->id)->visible);
|
||||
$this->assertEquals(0, core_course_category::get($category2->id)->visible);
|
||||
$this->assertEquals(1, core_course_category::get($category3->id)->visible);
|
||||
|
||||
// Create visible category 4.
|
||||
$category4 = coursecat::create(array('name' => 'Cat4'));
|
||||
$category4 = core_course_category::create(array('name' => 'Cat4'));
|
||||
$this->assertEquals(1, $category4->visible);
|
||||
$this->assertEquals(1, $category4->visibleold);
|
||||
|
||||
// Create visible category 5 as a child of visible category 4.
|
||||
$category5 = coursecat::create(array('name' => 'Cat5', 'parent' => $category4->id));
|
||||
$category5 = core_course_category::create(array('name' => 'Cat5', 'parent' => $category4->id));
|
||||
$this->assertEquals(1, $category5->visible);
|
||||
$this->assertEquals(1, $category5->visibleold);
|
||||
|
||||
@@ -184,7 +181,7 @@ class core_coursecatlib_testcase extends advanced_testcase {
|
||||
$category4->hide();
|
||||
$this->assertEquals(0, $category4->visible);
|
||||
$this->assertEquals(0, $category4->visibleold);
|
||||
$category5 = coursecat::get($category5->id); // We have to re-read from DB.
|
||||
$category5 = core_course_category::get($category5->id); // We have to re-read from DB.
|
||||
$this->assertEquals(0, $category5->visible);
|
||||
$this->assertEquals(1, $category5->visibleold);
|
||||
|
||||
@@ -192,7 +189,7 @@ class core_coursecatlib_testcase extends advanced_testcase {
|
||||
$category4->show();
|
||||
$this->assertEquals(1, $category4->visible);
|
||||
$this->assertEquals(1, $category4->visibleold);
|
||||
$category5 = coursecat::get($category5->id); // We have to re-read from DB.
|
||||
$category5 = core_course_category::get($category5->id); // We have to re-read from DB.
|
||||
$this->assertEquals(1, $category5->visible);
|
||||
$this->assertEquals(1, $category5->visibleold);
|
||||
|
||||
@@ -202,7 +199,7 @@ class core_coursecatlib_testcase extends advanced_testcase {
|
||||
$this->assertEquals(1, $category5->visibleold);
|
||||
|
||||
// Re-read object for category 5 from DB and check again.
|
||||
$category5 = coursecat::get($category5->id);
|
||||
$category5 = core_course_category::get($category5->id);
|
||||
$this->assertEquals(0, $category5->visible);
|
||||
$this->assertEquals(1, $category5->visibleold);
|
||||
|
||||
@@ -217,10 +214,10 @@ class core_coursecatlib_testcase extends advanced_testcase {
|
||||
$this->assign_capability('moodle/category:viewhiddencategories');
|
||||
$this->assign_capability('moodle/category:manage');
|
||||
|
||||
$category1 = coursecat::create(array('name' => 'Cat1'));
|
||||
$category2 = coursecat::create(array('name' => 'Cat2', 'parent' => $category1->id));
|
||||
$category3 = coursecat::create(array('name' => 'Cat3', 'parent' => $category1->id));
|
||||
$category4 = coursecat::create(array('name' => 'Cat4', 'parent' => $category2->id));
|
||||
$category1 = core_course_category::create(array('name' => 'Cat1'));
|
||||
$category2 = core_course_category::create(array('name' => 'Cat2', 'parent' => $category1->id));
|
||||
$category3 = core_course_category::create(array('name' => 'Cat3', 'parent' => $category1->id));
|
||||
$category4 = core_course_category::create(array('name' => 'Cat4', 'parent' => $category2->id));
|
||||
|
||||
// Check function get_children().
|
||||
$this->assertEquals(array($category2->id, $category3->id), array_keys($category1->get_children()));
|
||||
@@ -247,7 +244,7 @@ class core_coursecatlib_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
public function test_update() {
|
||||
$category1 = coursecat::create(array('name' => 'Cat1'));
|
||||
$category1 = core_course_category::create(array('name' => 'Cat1'));
|
||||
$timecreated = $category1->timemodified;
|
||||
$this->assertSame('Cat1', $category1->name);
|
||||
$this->assertTrue(empty($category1->description));
|
||||
@@ -255,10 +252,10 @@ class core_coursecatlib_testcase extends advanced_testcase {
|
||||
$testdescription = 'This is cat 1 а также русский текст';
|
||||
$category1->update(array('description' => $testdescription));
|
||||
$this->assertSame($testdescription, $category1->description);
|
||||
$category1 = coursecat::get($category1->id);
|
||||
$category1 = core_course_category::get($category1->id);
|
||||
$this->assertSame($testdescription, $category1->description);
|
||||
cache_helper::purge_by_event('changesincoursecat');
|
||||
$category1 = coursecat::get($category1->id);
|
||||
$category1 = core_course_category::get($category1->id);
|
||||
$this->assertSame($testdescription, $category1->description);
|
||||
|
||||
$this->assertGreaterThan($timecreated, $category1->timemodified);
|
||||
@@ -272,10 +269,10 @@ class core_coursecatlib_testcase extends advanced_testcase {
|
||||
|
||||
$initialcatid = $DB->get_field_sql('SELECT max(id) from {course_categories}');
|
||||
|
||||
$category1 = coursecat::create(array('name' => 'Cat1'));
|
||||
$category2 = coursecat::create(array('name' => 'Cat2', 'parent' => $category1->id));
|
||||
$category3 = coursecat::create(array('name' => 'Cat3'));
|
||||
$category4 = coursecat::create(array('name' => 'Cat4', 'parent' => $category2->id));
|
||||
$category1 = core_course_category::create(array('name' => 'Cat1'));
|
||||
$category2 = core_course_category::create(array('name' => 'Cat2', 'parent' => $category1->id));
|
||||
$category3 = core_course_category::create(array('name' => 'Cat3'));
|
||||
$category4 = core_course_category::create(array('name' => 'Cat4', 'parent' => $category2->id));
|
||||
|
||||
$course1 = $this->getDataGenerator()->create_course(array('category' => $category2->id));
|
||||
$course2 = $this->getDataGenerator()->create_course(array('category' => $category4->id));
|
||||
@@ -314,7 +311,7 @@ class core_coursecatlib_testcase extends advanced_testcase {
|
||||
// $course1
|
||||
// structure.
|
||||
|
||||
$this->assertNull(coursecat::get($category2->id, IGNORE_MISSING, true));
|
||||
$this->assertNull(core_course_category::get($category2->id, IGNORE_MISSING, true));
|
||||
$this->assertEquals(array(), $category1->get_children());
|
||||
$this->assertEquals(array($category4->id), array_keys($category3->get_children()));
|
||||
$this->assertEquals($category4->id, $DB->get_field('course', 'category', array('id' => $course2->id)));
|
||||
@@ -342,13 +339,14 @@ class core_coursecatlib_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
public function test_get_children() {
|
||||
$category1 = coursecat::create(array('name' => 'Cat1'));
|
||||
$category2 = coursecat::create(array('name' => 'Cat2', 'parent' => $category1->id));
|
||||
$category3 = coursecat::create(array('name' => 'Cat3', 'parent' => $category1->id, 'visible' => 0));
|
||||
$category4 = coursecat::create(array('name' => 'Cat4', 'idnumber' => '12', 'parent' => $category1->id));
|
||||
$category5 = coursecat::create(array('name' => 'Cat5', 'idnumber' => '11', 'parent' => $category1->id, 'visible' => 0));
|
||||
$category6 = coursecat::create(array('name' => 'Cat6', 'idnumber' => '10', 'parent' => $category1->id));
|
||||
$category7 = coursecat::create(array('name' => 'Cat0', 'parent' => $category1->id));
|
||||
$category1 = core_course_category::create(array('name' => 'Cat1'));
|
||||
$category2 = core_course_category::create(array('name' => 'Cat2', 'parent' => $category1->id));
|
||||
$category3 = core_course_category::create(array('name' => 'Cat3', 'parent' => $category1->id, 'visible' => 0));
|
||||
$category4 = core_course_category::create(array('name' => 'Cat4', 'idnumber' => '12', 'parent' => $category1->id));
|
||||
$category5 = core_course_category::create(array('name' => 'Cat5', 'idnumber' => '11',
|
||||
'parent' => $category1->id, 'visible' => 0));
|
||||
$category6 = core_course_category::create(array('name' => 'Cat6', 'idnumber' => '10', 'parent' => $category1->id));
|
||||
$category7 = core_course_category::create(array('name' => 'Cat0', 'parent' => $category1->id));
|
||||
|
||||
$children = $category1->get_children();
|
||||
// User does not have the capability to view hidden categories, so the list should be
|
||||
@@ -385,14 +383,14 @@ class core_coursecatlib_testcase extends advanced_testcase {
|
||||
* Test the get_all_children_ids function.
|
||||
*/
|
||||
public function test_get_all_children_ids() {
|
||||
$category1 = coursecat::create(array('name' => 'Cat1'));
|
||||
$category2 = coursecat::create(array('name' => 'Cat2'));
|
||||
$category11 = coursecat::create(array('name' => 'Cat11', 'parent' => $category1->id));
|
||||
$category12 = coursecat::create(array('name' => 'Cat12', 'parent' => $category1->id));
|
||||
$category13 = coursecat::create(array('name' => 'Cat13', 'parent' => $category1->id));
|
||||
$category111 = coursecat::create(array('name' => 'Cat111', 'parent' => $category11->id));
|
||||
$category112 = coursecat::create(array('name' => 'Cat112', 'parent' => $category11->id));
|
||||
$category1121 = coursecat::create(array('name' => 'Cat1121', 'parent' => $category112->id));
|
||||
$category1 = core_course_category::create(array('name' => 'Cat1'));
|
||||
$category2 = core_course_category::create(array('name' => 'Cat2'));
|
||||
$category11 = core_course_category::create(array('name' => 'Cat11', 'parent' => $category1->id));
|
||||
$category12 = core_course_category::create(array('name' => 'Cat12', 'parent' => $category1->id));
|
||||
$category13 = core_course_category::create(array('name' => 'Cat13', 'parent' => $category1->id));
|
||||
$category111 = core_course_category::create(array('name' => 'Cat111', 'parent' => $category11->id));
|
||||
$category112 = core_course_category::create(array('name' => 'Cat112', 'parent' => $category11->id));
|
||||
$category1121 = core_course_category::create(array('name' => 'Cat1121', 'parent' => $category112->id));
|
||||
|
||||
$this->assertCount(0, $category2->get_all_children_ids());
|
||||
$this->assertCount(6, $category1->get_all_children_ids());
|
||||
@@ -419,15 +417,15 @@ class core_coursecatlib_testcase extends advanced_testcase {
|
||||
global $DB;
|
||||
// Dont assume there is just one. An add-on might create a category as part of the install.
|
||||
$numcategories = $DB->count_records('course_categories');
|
||||
$this->assertEquals($numcategories, coursecat::count_all());
|
||||
$category1 = coursecat::create(array('name' => 'Cat1'));
|
||||
$category2 = coursecat::create(array('name' => 'Cat2', 'parent' => $category1->id));
|
||||
$category3 = coursecat::create(array('name' => 'Cat3', 'parent' => $category2->id, 'visible' => 0));
|
||||
$this->assertEquals($numcategories, core_course_category::count_all());
|
||||
$category1 = core_course_category::create(array('name' => 'Cat1'));
|
||||
$category2 = core_course_category::create(array('name' => 'Cat2', 'parent' => $category1->id));
|
||||
$category3 = core_course_category::create(array('name' => 'Cat3', 'parent' => $category2->id, 'visible' => 0));
|
||||
// Now we've got three more.
|
||||
$this->assertEquals($numcategories + 3, coursecat::count_all());
|
||||
$this->assertEquals($numcategories + 3, core_course_category::count_all());
|
||||
cache_helper::purge_by_event('changesincoursecat');
|
||||
// We should still have 4.
|
||||
$this->assertEquals($numcategories + 3, coursecat::count_all());
|
||||
$this->assertEquals($numcategories + 3, core_course_category::count_all());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -470,7 +468,7 @@ class core_coursecatlib_testcase extends advanced_testcase {
|
||||
$c3 = (int)$course3->id;
|
||||
$c4 = (int)$course4->id;
|
||||
|
||||
$coursecat = coursecat::get($category->id);
|
||||
$coursecat = core_course_category::get($category->id);
|
||||
$this->assertTrue($coursecat->resort_courses('idnumber'));
|
||||
$this->assertSame(array($c1, $c4, $c2, $c3), array_keys($coursecat->get_courses()));
|
||||
|
||||
@@ -494,8 +492,8 @@ class core_coursecatlib_testcase extends advanced_testcase {
|
||||
}
|
||||
|
||||
public function test_get_search_courses() {
|
||||
$cat1 = coursecat::create(array('name' => 'Cat1'));
|
||||
$cat2 = coursecat::create(array('name' => 'Cat2', 'parent' => $cat1->id));
|
||||
$cat1 = core_course_category::create(array('name' => 'Cat1'));
|
||||
$cat2 = core_course_category::create(array('name' => 'Cat2', 'parent' => $cat1->id));
|
||||
$c1 = $this->getDataGenerator()->create_course(array('category' => $cat1->id, 'fullname' => 'Test 3', 'summary' => ' ', 'idnumber' => 'ID3'));
|
||||
$c2 = $this->getDataGenerator()->create_course(array('category' => $cat1->id, 'fullname' => 'Test 1', 'summary' => ' ', 'visible' => 0));
|
||||
$c3 = $this->getDataGenerator()->create_course(array('category' => $cat1->id, 'fullname' => 'Математика', 'summary' => ' Test '));
|
||||
@@ -538,26 +536,26 @@ class core_coursecatlib_testcase extends advanced_testcase {
|
||||
// Search courses.
|
||||
|
||||
// Search by text.
|
||||
$res = coursecat::search_courses(array('search' => 'Test'));
|
||||
$res = core_course_category::search_courses(array('search' => 'Test'));
|
||||
$this->assertEquals(array($c4->id, $c3->id, $c1->id, $c8->id, $c5->id), array_keys($res));
|
||||
$this->assertEquals(5, coursecat::search_courses_count(array('search' => 'Test')));
|
||||
$this->assertEquals(5, core_course_category::search_courses_count(array('search' => 'Test')));
|
||||
|
||||
// Search by text with specified offset and limit.
|
||||
$options = array('sort' => array('fullname' => 1), 'offset' => 1, 'limit' => 2);
|
||||
$res = coursecat::search_courses(array('search' => 'Test'), $options);
|
||||
$res = core_course_category::search_courses(array('search' => 'Test'), $options);
|
||||
$this->assertEquals(array($c4->id, $c5->id), array_keys($res));
|
||||
$this->assertEquals(5, coursecat::search_courses_count(array('search' => 'Test'), $options));
|
||||
$this->assertEquals(5, core_course_category::search_courses_count(array('search' => 'Test'), $options));
|
||||
|
||||
// IMPORTANT: the tests below may fail on some databases
|
||||
// case-insensitive search.
|
||||
$res = coursecat::search_courses(array('search' => 'test'));
|
||||
$res = core_course_category::search_courses(array('search' => 'test'));
|
||||
$this->assertEquals(array($c4->id, $c3->id, $c1->id, $c8->id, $c5->id), array_keys($res));
|
||||
$this->assertEquals(5, coursecat::search_courses_count(array('search' => 'test')));
|
||||
$this->assertEquals(5, core_course_category::search_courses_count(array('search' => 'test')));
|
||||
|
||||
// Non-latin language search.
|
||||
$res = coursecat::search_courses(array('search' => 'Математика'));
|
||||
$res = core_course_category::search_courses(array('search' => 'Математика'));
|
||||
$this->assertEquals(array($c3->id, $c6->id), array_keys($res));
|
||||
$this->assertEquals(2, coursecat::search_courses_count(array('search' => 'Математика'), array()));
|
||||
$this->assertEquals(2, core_course_category::search_courses_count(array('search' => 'Математика'), array()));
|
||||
|
||||
$this->setUser($this->getDataGenerator()->create_user());
|
||||
|
||||
@@ -565,9 +563,9 @@ class core_coursecatlib_testcase extends advanced_testcase {
|
||||
$this->assign_capability('moodle/course:create', CAP_ALLOW, context_coursecat::instance($cat2->id));
|
||||
// Do another search with restricted capabilities.
|
||||
$reqcaps = array('moodle/course:create');
|
||||
$res = coursecat::search_courses(array('search' => 'test'), array(), $reqcaps);
|
||||
$res = core_course_category::search_courses(array('search' => 'test'), array(), $reqcaps);
|
||||
$this->assertEquals(array($c8->id, $c5->id), array_keys($res));
|
||||
$this->assertEquals(2, coursecat::search_courses_count(array('search' => 'test'), array(), $reqcaps));
|
||||
$this->assertEquals(2, core_course_category::search_courses_count(array('search' => 'test'), array(), $reqcaps));
|
||||
}
|
||||
|
||||
public function test_course_contacts() {
|
||||
@@ -601,10 +599,10 @@ class core_coursecatlib_testcase extends advanced_testcase {
|
||||
// -- course12 (user1 has teacher role) | [Expected]
|
||||
// also user4 is enrolled as teacher but enrolment is not active
|
||||
$category = $course = $enrol = $user = array();
|
||||
$category[1] = coursecat::create(array('name' => 'Cat1'))->id;
|
||||
$category[2] = coursecat::create(array('name' => 'Cat2', 'parent' => $category[1]))->id;
|
||||
$category[3] = coursecat::create(array('name' => 'Cat3', 'parent' => $category[1]))->id;
|
||||
$category[4] = coursecat::create(array('name' => 'Cat4', 'parent' => $category[2]))->id;
|
||||
$category[1] = core_course_category::create(array('name' => 'Cat1'))->id;
|
||||
$category[2] = core_course_category::create(array('name' => 'Cat2', 'parent' => $category[1]))->id;
|
||||
$category[3] = core_course_category::create(array('name' => 'Cat3', 'parent' => $category[1]))->id;
|
||||
$category[4] = core_course_category::create(array('name' => 'Cat4', 'parent' => $category[2]))->id;
|
||||
foreach (array(1, 2, 3, 4) as $catid) {
|
||||
foreach (array(1, 2) as $courseid) {
|
||||
$course[$catid][$courseid] = $this->getDataGenerator()->create_course(array('idnumber' => 'id'.$catid.$courseid,
|
||||
@@ -619,7 +617,8 @@ class core_coursecatlib_testcase extends advanced_testcase {
|
||||
$manual = enrol_get_plugin('manual');
|
||||
|
||||
// Nobody is enrolled now and course contacts are empty.
|
||||
$allcourses = coursecat::get(0)->get_courses(array('recursive' => true, 'coursecontacts' => true, 'sort' => array('idnumber' => 1)));
|
||||
$allcourses = core_course_category::get(0)->get_courses(
|
||||
array('recursive' => true, 'coursecontacts' => true, 'sort' => array('idnumber' => 1)));
|
||||
foreach ($allcourses as $onecourse) {
|
||||
$this->assertEmpty($onecourse->get_course_contacts());
|
||||
}
|
||||
@@ -648,7 +647,8 @@ class core_coursecatlib_testcase extends advanced_testcase {
|
||||
role_assign($teacherrole->id, $user[1], context_course::instance($course[1][2]));
|
||||
$manual->enrol_user($enrol[1][2], $user[4], $teacherrole->id, 0, 0, ENROL_USER_SUSPENDED);
|
||||
|
||||
$allcourses = coursecat::get(0)->get_courses(array('recursive' => true, 'coursecontacts' => true, 'sort' => array('idnumber' => 1)));
|
||||
$allcourses = core_course_category::get(0)->get_courses(
|
||||
array('recursive' => true, 'coursecontacts' => true, 'sort' => array('idnumber' => 1)));
|
||||
// Simplify the list of contacts for each course (similar as renderer would do).
|
||||
$contacts = array();
|
||||
foreach (array(1, 2, 3, 4) as $catid) {
|
||||
@@ -681,7 +681,8 @@ class core_coursecatlib_testcase extends advanced_testcase {
|
||||
|
||||
// Suspend user 4 and make sure he is no longer in contacts of course 1 in category 4.
|
||||
$manual->enrol_user($enrol[4][1], $user[4], $teacherrole->id, 0, 0, ENROL_USER_SUSPENDED);
|
||||
$allcourses = coursecat::get(0)->get_courses(array('recursive' => true, 'coursecontacts' => true, 'sort' => array('idnumber' => 1)));
|
||||
$allcourses = core_course_category::get(0)->get_courses(
|
||||
array('recursive' => true, 'coursecontacts' => true, 'sort' => array('idnumber' => 1)));
|
||||
$contacts = $allcourses[$course[4][1]]->get_course_contacts();
|
||||
$this->assertCount(1, $contacts);
|
||||
$contact = reset($contacts);
|
||||
@@ -693,7 +694,7 @@ class core_coursecatlib_testcase extends advanced_testcase {
|
||||
public function test_overview_files() {
|
||||
global $CFG;
|
||||
$this->setAdminUser();
|
||||
$cat1 = coursecat::create(array('name' => 'Cat1'));
|
||||
$cat1 = core_course_category::create(array('name' => 'Cat1'));
|
||||
|
||||
// Create course c1 with one image file.
|
||||
$dratid1 = $this->fill_draft_area(array('filename.jpg' => 'Test file contents1'));
|
||||
@@ -786,10 +787,10 @@ class core_coursecatlib_testcase extends advanced_testcase {
|
||||
$cat2name = 'Cat2';
|
||||
$cat3name = 'Cat3';
|
||||
$cat4name = 'Cat4';
|
||||
$category1 = coursecat::create(array('name' => $cat1name));
|
||||
$category2 = coursecat::create(array('name' => $cat2name, 'parent' => $category1->id));
|
||||
$category3 = coursecat::create(array('name' => $cat3name, 'parent' => $category2->id));
|
||||
$category4 = coursecat::create(array('name' => $cat4name, 'parent' => $category2->id));
|
||||
$category1 = core_course_category::create(array('name' => $cat1name));
|
||||
$category2 = core_course_category::create(array('name' => $cat2name, 'parent' => $category1->id));
|
||||
$category3 = core_course_category::create(array('name' => $cat3name, 'parent' => $category2->id));
|
||||
$category4 = core_course_category::create(array('name' => $cat4name, 'parent' => $category2->id));
|
||||
|
||||
$this->assertEquals($cat1name, $category1->get_nested_name(false));
|
||||
$this->assertEquals("{$cat1name} / {$cat2name}", $category2->get_nested_name(false));
|
||||
@@ -801,9 +802,9 @@ class core_coursecatlib_testcase extends advanced_testcase {
|
||||
global $USER;
|
||||
|
||||
// Create category 1 as visible.
|
||||
$category1 = coursecat::create(array('name' => 'Cat1', 'visible' => 1));
|
||||
$category1 = core_course_category::create(array('name' => 'Cat1', 'visible' => 1));
|
||||
// Create category 2 as hidden.
|
||||
$category2 = coursecat::create(array('name' => 'Cat2', 'visible' => 0));
|
||||
$category2 = core_course_category::create(array('name' => 'Cat2', 'visible' => 0));
|
||||
|
||||
$this->assertTrue($category1->is_uservisible());
|
||||
$this->assertFalse($category2->is_uservisible());
|
||||
@@ -831,21 +832,21 @@ class core_coursecatlib_testcase extends advanced_testcase {
|
||||
$this->assign_capability('moodle/category:viewhiddencategories');
|
||||
|
||||
// Create category 1 as visible.
|
||||
$category1 = coursecat::create(array('name' => 'Cat1', 'visible' => 1));
|
||||
$category1 = core_course_category::create(array('name' => 'Cat1', 'visible' => 1));
|
||||
// Create category 2 as hidden.
|
||||
$category2 = coursecat::create(array('name' => 'Cat2', 'visible' => 0));
|
||||
$category2 = core_course_category::create(array('name' => 'Cat2', 'visible' => 0));
|
||||
|
||||
$this->assertEquals($category1->id, coursecat::get($category1->id)->id);
|
||||
$this->assertEquals($category2->id, coursecat::get($category2->id)->id);
|
||||
$this->assertEquals($category1->id, core_course_category::get($category1->id)->id);
|
||||
$this->assertEquals($category2->id, core_course_category::get($category2->id)->id);
|
||||
|
||||
// Login as another user to test coursecat::get.
|
||||
// Login as another user to test core_course_category::get.
|
||||
$this->setUser($this->getDataGenerator()->create_user());
|
||||
$this->assertEquals($category1->id, coursecat::get($category1->id)->id);
|
||||
$this->assertEquals($category1->id, core_course_category::get($category1->id)->id);
|
||||
|
||||
// Expecting to get an exception as this new user does not have the moodle/category:viewhiddencategories capability.
|
||||
$this->expectException('moodle_exception');
|
||||
$this->expectExceptionMessage('unknowncategory');
|
||||
coursecat::get($category2->id);
|
||||
core_course_category::get($category2->id);
|
||||
}
|
||||
|
||||
public function test_another_user_coursecat_get() {
|
||||
@@ -854,24 +855,24 @@ class core_coursecatlib_testcase extends advanced_testcase {
|
||||
$this->assign_capability('moodle/category:viewhiddencategories');
|
||||
|
||||
// Create category 1 as visible.
|
||||
$category1 = coursecat::create(array('name' => 'Cat1', 'visible' => 1));
|
||||
$category1 = core_course_category::create(array('name' => 'Cat1', 'visible' => 1));
|
||||
// Create category 2 as hidden.
|
||||
$category2 = coursecat::create(array('name' => 'Cat2', 'visible' => 0));
|
||||
$category2 = core_course_category::create(array('name' => 'Cat2', 'visible' => 0));
|
||||
|
||||
// First, store current user's object, then login as another user.
|
||||
$user1 = $USER;
|
||||
$user2 = $this->getDataGenerator()->create_user();
|
||||
$this->setUser($user2);
|
||||
|
||||
$this->assertEquals($category1->id, coursecat::get($category1->id, MUST_EXIST, false, $user1)->id);
|
||||
$this->assertEquals($category2->id, coursecat::get($category2->id, MUST_EXIST, false, $user1)->id);
|
||||
$this->assertEquals($category1->id, core_course_category::get($category1->id, MUST_EXIST, false, $user1)->id);
|
||||
$this->assertEquals($category2->id, core_course_category::get($category2->id, MUST_EXIST, false, $user1)->id);
|
||||
|
||||
$this->setUser($user1);
|
||||
|
||||
$this->assertEquals($category1->id, coursecat::get($category1->id, MUST_EXIST, false, $user2)->id);
|
||||
$this->assertEquals($category1->id, core_course_category::get($category1->id, MUST_EXIST, false, $user2)->id);
|
||||
$this->expectException('moodle_exception');
|
||||
$this->expectExceptionMessage('unknowncategory');
|
||||
coursecat::get($category2->id, MUST_EXIST, false, $user2);
|
||||
core_course_category::get($category2->id, MUST_EXIST, false, $user2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,8 +97,8 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
course_capability_assignment::allow(array(self::COURSE_VIEW, self::COURSE_VIEWHIDDEN), $roleid, $subcontext->id);
|
||||
|
||||
$this->assertTrue(\core_course\management\helper::action_category_hide($category));
|
||||
$cat = coursecat::get($category->id);
|
||||
$subcat = coursecat::get($subcategory->id);
|
||||
$cat = core_course_category::get($category->id);
|
||||
$subcat = core_course_category::get($subcategory->id);
|
||||
$course = $DB->get_record('course', array('id' => $course->id), 'id, visible, visibleold', MUST_EXIST);
|
||||
$this->assertEquals(0, $cat->visible);
|
||||
$this->assertEquals(0, $cat->visibleold);
|
||||
@@ -108,8 +108,8 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
$this->assertEquals(1, $course->visibleold);
|
||||
// This doesn't change anything but should succeed still.
|
||||
$this->assertTrue(\core_course\management\helper::action_category_hide($category));
|
||||
$cat = coursecat::get($category->id);
|
||||
$subcat = coursecat::get($subcategory->id);
|
||||
$cat = core_course_category::get($category->id);
|
||||
$subcat = core_course_category::get($subcategory->id);
|
||||
$course = $DB->get_record('course', array('id' => $course->id), 'id, visible, visibleold', MUST_EXIST);
|
||||
$this->assertEquals(0, $cat->visible);
|
||||
$this->assertEquals(0, $cat->visibleold);
|
||||
@@ -119,8 +119,8 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
$this->assertEquals(1, $course->visibleold);
|
||||
|
||||
$this->assertTrue(\core_course\management\helper::action_category_show($category));
|
||||
$cat = coursecat::get($category->id);
|
||||
$subcat = coursecat::get($subcategory->id);
|
||||
$cat = core_course_category::get($category->id);
|
||||
$subcat = core_course_category::get($subcategory->id);
|
||||
$course = $DB->get_record('course', array('id' => $course->id), 'id, visible, visibleold', MUST_EXIST);
|
||||
$this->assertEquals(1, $cat->visible);
|
||||
$this->assertEquals(1, $cat->visibleold);
|
||||
@@ -130,8 +130,8 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
$this->assertEquals(1, $course->visibleold);
|
||||
// This doesn't change anything but should succeed still.
|
||||
$this->assertTrue(\core_course\management\helper::action_category_show($category));
|
||||
$cat = coursecat::get($category->id);
|
||||
$subcat = coursecat::get($subcategory->id);
|
||||
$cat = core_course_category::get($category->id);
|
||||
$subcat = core_course_category::get($subcategory->id);
|
||||
$course = $DB->get_record('course', array('id' => $course->id), 'id, visible, visibleold', MUST_EXIST);
|
||||
$this->assertEquals(1, $cat->visible);
|
||||
$this->assertEquals(1, $cat->visibleold);
|
||||
@@ -147,8 +147,8 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
$this->fail('Expected exception did not occur when trying to hide a category without permission.');
|
||||
} catch (moodle_exception $ex) {
|
||||
// The category must still be visible.
|
||||
$cat = coursecat::get($category->id);
|
||||
$subcat = coursecat::get($subcategory->id);
|
||||
$cat = core_course_category::get($category->id);
|
||||
$subcat = core_course_category::get($subcategory->id);
|
||||
$course = $DB->get_record('course', array('id' => $course->id), 'id, visible, visibleold', MUST_EXIST);
|
||||
$this->assertEquals(1, $cat->visible);
|
||||
$this->assertEquals(1, $cat->visibleold);
|
||||
@@ -161,8 +161,8 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
// Hide the category so that we can test helper::show.
|
||||
$parentassignment->assign(CAP_ALLOW);
|
||||
\core_course\management\helper::action_category_hide($category);
|
||||
$cat = coursecat::get($category->id);
|
||||
$subcat = coursecat::get($subcategory->id);
|
||||
$cat = core_course_category::get($category->id);
|
||||
$subcat = core_course_category::get($subcategory->id);
|
||||
$course = $DB->get_record('course', array('id' => $course->id), 'id, visible, visibleold', MUST_EXIST);
|
||||
$this->assertEquals(0, $cat->visible);
|
||||
$this->assertEquals(0, $cat->visibleold);
|
||||
@@ -178,8 +178,8 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
$this->fail('Expected exception did not occur when trying to show a category without permission.');
|
||||
} catch (moodle_exception $ex) {
|
||||
// The category must still be hidden.
|
||||
$cat = coursecat::get($category->id);
|
||||
$subcat = coursecat::get($subcategory->id);
|
||||
$cat = core_course_category::get($category->id);
|
||||
$subcat = core_course_category::get($subcategory->id);
|
||||
$course = $DB->get_record('course', array('id' => $course->id), 'id, visible, visibleold', MUST_EXIST);
|
||||
$this->assertEquals(0, $cat->visible);
|
||||
$this->assertEquals(0, $cat->visibleold);
|
||||
@@ -193,8 +193,8 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
// Now we have capability on the category and subcategory but not the parent.
|
||||
// Try to mark the subcategory as visible. This should be possible although its parent is set to hidden.
|
||||
$this->assertTrue(\core_course\management\helper::action_category_show($subcategory));
|
||||
$cat = coursecat::get($category->id);
|
||||
$subcat = coursecat::get($subcategory->id);
|
||||
$cat = core_course_category::get($category->id);
|
||||
$subcat = core_course_category::get($subcategory->id);
|
||||
$course = $DB->get_record('course', array('id' => $course->id), 'id, visible, visibleold', MUST_EXIST);
|
||||
$this->assertEquals(0, $cat->visible);
|
||||
$this->assertEquals(0, $cat->visibleold);
|
||||
@@ -206,8 +206,8 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
// Now make the parent visible for the next test.
|
||||
$parentassignment->assign(CAP_ALLOW);
|
||||
$this->assertTrue(\core_course\management\helper::action_category_show($category));
|
||||
$cat = coursecat::get($category->id);
|
||||
$subcat = coursecat::get($subcategory->id);
|
||||
$cat = core_course_category::get($category->id);
|
||||
$subcat = core_course_category::get($subcategory->id);
|
||||
$course = $DB->get_record('course', array('id' => $course->id), 'id, visible, visibleold', MUST_EXIST);
|
||||
$this->assertEquals(1, $cat->visible);
|
||||
$this->assertEquals(1, $cat->visibleold);
|
||||
@@ -225,7 +225,7 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
$this->fail('Expected exception did not occur when trying to hide a category without permission.');
|
||||
} catch (moodle_exception $ex) {
|
||||
// The category must still be visible.
|
||||
$this->assertEquals(1, coursecat::get($category->id)->visible);
|
||||
$this->assertEquals(1, core_course_category::get($category->id)->visible);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -255,8 +255,8 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
course_capability_assignment::allow(array(self::COURSE_VIEW, self::COURSE_VIEWHIDDEN), $roleid, $subcontext->id);
|
||||
|
||||
$this->assertTrue(\core_course\management\helper::action_category_hide_by_id($category->id));
|
||||
$cat = coursecat::get($category->id);
|
||||
$subcat = coursecat::get($subcategory->id);
|
||||
$cat = core_course_category::get($category->id);
|
||||
$subcat = core_course_category::get($subcategory->id);
|
||||
$course = $DB->get_record('course', array('id' => $course->id), 'id, visible, visibleold', MUST_EXIST);
|
||||
$this->assertEquals(0, $cat->visible);
|
||||
$this->assertEquals(0, $cat->visibleold);
|
||||
@@ -266,8 +266,8 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
$this->assertEquals(1, $course->visibleold);
|
||||
// This doesn't change anything but should succeed still.
|
||||
$this->assertTrue(\core_course\management\helper::action_category_hide_by_id($category->id));
|
||||
$cat = coursecat::get($category->id);
|
||||
$subcat = coursecat::get($subcategory->id);
|
||||
$cat = core_course_category::get($category->id);
|
||||
$subcat = core_course_category::get($subcategory->id);
|
||||
$course = $DB->get_record('course', array('id' => $course->id), 'id, visible, visibleold', MUST_EXIST);
|
||||
$this->assertEquals(0, $cat->visible);
|
||||
$this->assertEquals(0, $cat->visibleold);
|
||||
@@ -277,8 +277,8 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
$this->assertEquals(1, $course->visibleold);
|
||||
|
||||
$this->assertTrue(\core_course\management\helper::action_category_show_by_id($category->id));
|
||||
$cat = coursecat::get($category->id);
|
||||
$subcat = coursecat::get($subcategory->id);
|
||||
$cat = core_course_category::get($category->id);
|
||||
$subcat = core_course_category::get($subcategory->id);
|
||||
$course = $DB->get_record('course', array('id' => $course->id), 'id, visible, visibleold', MUST_EXIST);
|
||||
$this->assertEquals(1, $cat->visible);
|
||||
$this->assertEquals(1, $cat->visibleold);
|
||||
@@ -288,8 +288,8 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
$this->assertEquals(1, $course->visibleold);
|
||||
// This doesn't change anything but should succeed still.
|
||||
$this->assertTrue(\core_course\management\helper::action_category_show_by_id($category->id));
|
||||
$cat = coursecat::get($category->id);
|
||||
$subcat = coursecat::get($subcategory->id);
|
||||
$cat = core_course_category::get($category->id);
|
||||
$subcat = core_course_category::get($subcategory->id);
|
||||
$course = $DB->get_record('course', array('id' => $course->id), 'id, visible, visibleold', MUST_EXIST);
|
||||
$this->assertEquals(1, $cat->visible);
|
||||
$this->assertEquals(1, $cat->visibleold);
|
||||
@@ -305,8 +305,8 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
$this->fail('Expected exception did not occur when trying to hide a category without permission.');
|
||||
} catch (moodle_exception $ex) {
|
||||
// The category must still be visible.
|
||||
$cat = coursecat::get($category->id);
|
||||
$subcat = coursecat::get($subcategory->id);
|
||||
$cat = core_course_category::get($category->id);
|
||||
$subcat = core_course_category::get($subcategory->id);
|
||||
$this->assertEquals(1, $cat->visible);
|
||||
$this->assertEquals(1, $cat->visibleold);
|
||||
$this->assertEquals(1, $subcat->visible);
|
||||
@@ -318,8 +318,8 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
// Hide the category so that we can test helper::show.
|
||||
$parentassignment->assign(CAP_ALLOW);
|
||||
\core_course\management\helper::action_category_hide_by_id($category->id);
|
||||
$cat = coursecat::get($category->id);
|
||||
$subcat = coursecat::get($subcategory->id);
|
||||
$cat = core_course_category::get($category->id);
|
||||
$subcat = core_course_category::get($subcategory->id);
|
||||
$course = $DB->get_record('course', array('id' => $course->id), 'id, visible, visibleold', MUST_EXIST);
|
||||
$this->assertEquals(0, $cat->visible);
|
||||
$this->assertEquals(0, $cat->visibleold);
|
||||
@@ -335,8 +335,8 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
$this->fail('Expected exception did not occur when trying to show a category without permission.');
|
||||
} catch (moodle_exception $ex) {
|
||||
// The category must still be hidden.
|
||||
$cat = coursecat::get($category->id);
|
||||
$subcat = coursecat::get($subcategory->id);
|
||||
$cat = core_course_category::get($category->id);
|
||||
$subcat = core_course_category::get($subcategory->id);
|
||||
$course = $DB->get_record('course', array('id' => $course->id), 'id, visible, visibleold', MUST_EXIST);
|
||||
$this->assertEquals(0, $cat->visible);
|
||||
$this->assertEquals(0, $cat->visibleold);
|
||||
@@ -350,8 +350,8 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
// Now we have capability on the category and subcategory but not the parent.
|
||||
// Try to mark the subcategory as visible. This should be possible although its parent is set to hidden.
|
||||
$this->assertTrue(\core_course\management\helper::action_category_show($subcategory));
|
||||
$cat = coursecat::get($category->id);
|
||||
$subcat = coursecat::get($subcategory->id);
|
||||
$cat = core_course_category::get($category->id);
|
||||
$subcat = core_course_category::get($subcategory->id);
|
||||
$course = $DB->get_record('course', array('id' => $course->id), 'id, visible, visibleold', MUST_EXIST);
|
||||
$this->assertEquals(0, $cat->visible);
|
||||
$this->assertEquals(0, $cat->visibleold);
|
||||
@@ -363,8 +363,8 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
// Now make the parent visible for the next test.
|
||||
$parentassignment->assign(CAP_ALLOW);
|
||||
$this->assertTrue(\core_course\management\helper::action_category_show_by_id($category->id));
|
||||
$cat = coursecat::get($category->id);
|
||||
$subcat = coursecat::get($subcategory->id);
|
||||
$cat = core_course_category::get($category->id);
|
||||
$subcat = core_course_category::get($subcategory->id);
|
||||
$course = $DB->get_record('course', array('id' => $course->id), 'id, visible, visibleold', MUST_EXIST);
|
||||
$this->assertEquals(1, $cat->visible);
|
||||
$this->assertEquals(1, $cat->visibleold);
|
||||
@@ -382,7 +382,7 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
$this->fail('Expected exception did not occur when trying to hide a category without permission.');
|
||||
} catch (moodle_exception $ex) {
|
||||
// The category must still be visible.
|
||||
$this->assertEquals(1, coursecat::get($category->id)->visible);
|
||||
$this->assertEquals(1, core_course_category::get($category->id)->visible);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -484,7 +484,7 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
|
||||
// Prevent the user from being able to move into $sub2.
|
||||
$sub2cap = course_capability_assignment::prohibit(self::CATEGORY_MANAGE, $roleid, $sub2->get_context()->id);
|
||||
$sub2 = coursecat::get($sub2->id);
|
||||
$sub2 = core_course_category::get($sub2->id);
|
||||
// Suppress debugging messages for a moment.
|
||||
$olddebug = $CFG->debug;
|
||||
$CFG->debug = 0;
|
||||
@@ -547,9 +547,9 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
// Move the top category down one.
|
||||
$this->assertTrue(\core_course\management\helper::action_category_change_sortorder_down_one($cat1));
|
||||
// Reload out objects.
|
||||
$cat1 = coursecat::get($cat1->id);
|
||||
$cat2 = coursecat::get($cat2->id);
|
||||
$cat3 = coursecat::get($cat3->id);
|
||||
$cat1 = core_course_category::get($cat1->id);
|
||||
$cat2 = core_course_category::get($cat2->id);
|
||||
$cat3 = core_course_category::get($cat3->id);
|
||||
// Verify that caches were cleared.
|
||||
$this->assertEquals($DB->get_field('course_categories', 'sortorder', array('id' => $cat1->id)), $cat1->sortorder);
|
||||
$this->assertEquals($DB->get_field('course_categories', 'sortorder', array('id' => $cat2->id)), $cat2->sortorder);
|
||||
@@ -563,9 +563,9 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
// Move the bottom category up one.
|
||||
$this->assertTrue(\core_course\management\helper::action_category_change_sortorder_up_one($cat3));
|
||||
// Reload out objects.
|
||||
$cat1 = coursecat::get($cat1->id);
|
||||
$cat2 = coursecat::get($cat2->id);
|
||||
$cat3 = coursecat::get($cat3->id);
|
||||
$cat1 = core_course_category::get($cat1->id);
|
||||
$cat2 = core_course_category::get($cat2->id);
|
||||
$cat3 = core_course_category::get($cat3->id);
|
||||
// Verify that caches were cleared.
|
||||
$this->assertEquals($DB->get_field('course_categories', 'sortorder', array('id' => $cat1->id)), $cat1->sortorder);
|
||||
$this->assertEquals($DB->get_field('course_categories', 'sortorder', array('id' => $cat2->id)), $cat2->sortorder);
|
||||
@@ -591,9 +591,9 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
);
|
||||
|
||||
// Reload out objects the above actions will have caused the objects to become stale.
|
||||
$cat1 = coursecat::get($cat1->id);
|
||||
$cat2 = coursecat::get($cat2->id);
|
||||
$cat3 = coursecat::get($cat3->id);
|
||||
$cat1 = core_course_category::get($cat1->id);
|
||||
$cat2 = core_course_category::get($cat2->id);
|
||||
$cat3 = core_course_category::get($cat3->id);
|
||||
// Verify that caches were cleared.
|
||||
$this->assertEquals($DB->get_field('course_categories', 'sortorder', array('id' => $cat1->id)), $cat1->sortorder);
|
||||
$this->assertEquals($DB->get_field('course_categories', 'sortorder', array('id' => $cat2->id)), $cat2->sortorder);
|
||||
@@ -603,9 +603,9 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
// Test moving the top category up one. Nothing should change but it should return false.
|
||||
$this->assertFalse(\core_course\management\helper::action_category_change_sortorder_up_one($cat3));
|
||||
// Reload out objects.
|
||||
$cat1 = coursecat::get($cat1->id);
|
||||
$cat2 = coursecat::get($cat2->id);
|
||||
$cat3 = coursecat::get($cat3->id);
|
||||
$cat1 = core_course_category::get($cat1->id);
|
||||
$cat2 = core_course_category::get($cat2->id);
|
||||
$cat3 = core_course_category::get($cat3->id);
|
||||
// Verify that caches were cleared.
|
||||
$this->assertEquals($DB->get_field('course_categories', 'sortorder', array('id' => $cat1->id)), $cat1->sortorder);
|
||||
$this->assertEquals($DB->get_field('course_categories', 'sortorder', array('id' => $cat2->id)), $cat2->sortorder);
|
||||
@@ -619,9 +619,9 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
// Test moving the bottom category down one. Nothing should change but it should return false.
|
||||
$this->assertFalse(\core_course\management\helper::action_category_change_sortorder_down_one($cat2));
|
||||
// Reload out objects.
|
||||
$cat1 = coursecat::get($cat1->id);
|
||||
$cat2 = coursecat::get($cat2->id);
|
||||
$cat3 = coursecat::get($cat3->id);
|
||||
$cat1 = core_course_category::get($cat1->id);
|
||||
$cat2 = core_course_category::get($cat2->id);
|
||||
$cat3 = core_course_category::get($cat3->id);
|
||||
// Verify that caches were cleared.
|
||||
$this->assertEquals($DB->get_field('course_categories', 'sortorder', array('id' => $cat1->id)), $cat1->sortorder);
|
||||
$this->assertEquals($DB->get_field('course_categories', 'sortorder', array('id' => $cat2->id)), $cat2->sortorder);
|
||||
@@ -674,7 +674,7 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
$syscontext = context_system::instance();
|
||||
|
||||
// Update category object from DB so the course count is correct.
|
||||
$category = coursecat::get($category->id);
|
||||
$category = core_course_category::get($category->id);
|
||||
|
||||
list($user, $roleid) = $this->get_user_objects($generator, $syscontext->id);
|
||||
$caps = course_capability_assignment::allow(self::CATEGORY_MANAGE, $roleid, $syscontext->id);
|
||||
@@ -738,7 +738,7 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
// Prohibit resorting.
|
||||
$caps->assign(CAP_PROHIBIT);
|
||||
// Refresh our coursecat object.
|
||||
$category = coursecat::get($category->id);
|
||||
$category = core_course_category::get($category->id);
|
||||
|
||||
// We should no longer have permission to do this. Test it out!
|
||||
try {
|
||||
@@ -746,7 +746,7 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
$this->fail('Courses sorted without having the required permission.');
|
||||
} catch (moodle_exception $exception) {
|
||||
// Check its the right exception.
|
||||
$this->assertEquals('coursecat::can_resort', $exception->debuginfo);
|
||||
$this->assertEquals('core_course_category::can_resort', $exception->debuginfo);
|
||||
// Test things are as they were before.
|
||||
$courses = $category->get_courses();
|
||||
$this->assertInternalType('array', $courses);
|
||||
@@ -823,7 +823,7 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
}
|
||||
|
||||
// Test resorting the top level category (puke).
|
||||
$topcat = coursecat::get(0);
|
||||
$topcat = core_course_category::get(0);
|
||||
\core_course\management\helper::action_category_resort_subcategories($topcat, 'name');
|
||||
$categories = $topcat->get_children();
|
||||
$this->assertInternalType('array', $categories);
|
||||
@@ -833,7 +833,7 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
// Prohibit resorting.
|
||||
$caps->assign(CAP_PROHIBIT);
|
||||
// Refresh our coursecat object.
|
||||
$parent = coursecat::get($parent->id);
|
||||
$parent = core_course_category::get($parent->id);
|
||||
|
||||
// We should no longer have permission to do this. Test it out!
|
||||
try {
|
||||
@@ -841,7 +841,7 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
$this->fail('Categories sorted without having the required permission.');
|
||||
} catch (moodle_exception $exception) {
|
||||
// Check its the right exception.
|
||||
$this->assertEquals('coursecat::can_resort', $exception->debuginfo);
|
||||
$this->assertEquals('core_course_category::can_resort', $exception->debuginfo);
|
||||
// Test things are as they were before.
|
||||
$categories = $parent->get_children();
|
||||
$this->assertInternalType('array', $categories);
|
||||
@@ -870,7 +870,7 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
$caps = array(self::COURSE_VIEW, self::COURSE_VIEWHIDDEN);
|
||||
$assignment = course_capability_assignment::allow($caps, $roleid, $coursecontext->id);
|
||||
|
||||
$course = new course_in_list(get_course($course->id));
|
||||
$course = new core_course_list_element(get_course($course->id));
|
||||
|
||||
// Check it is set to what we think it is.
|
||||
$this->assertEquals('1', $course->visible);
|
||||
@@ -879,39 +879,39 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
// Test hiding the course.
|
||||
$this->assertTrue(\core_course\management\helper::action_course_hide($course));
|
||||
// Refresh the course.
|
||||
$course = new course_in_list(get_course($course->id));
|
||||
$course = new core_course_list_element(get_course($course->id));
|
||||
$this->assertEquals('0', $course->visible);
|
||||
$this->assertEquals('0', $course->visibleold);
|
||||
|
||||
// Test hiding the course again.
|
||||
$this->assertTrue(\core_course\management\helper::action_course_hide($course));
|
||||
// Refresh the course.
|
||||
$course = new course_in_list(get_course($course->id));
|
||||
$course = new core_course_list_element(get_course($course->id));
|
||||
$this->assertEquals('0', $course->visible);
|
||||
$this->assertEquals('0', $course->visibleold);
|
||||
|
||||
// Test showing the course.
|
||||
$this->assertTrue(\core_course\management\helper::action_course_show($course));
|
||||
// Refresh the course.
|
||||
$course = new course_in_list(get_course($course->id));
|
||||
$course = new core_course_list_element(get_course($course->id));
|
||||
$this->assertEquals('1', $course->visible);
|
||||
$this->assertEquals('1', $course->visibleold);
|
||||
|
||||
// Test showing the course again. Shouldn't change anything.
|
||||
$this->assertTrue(\core_course\management\helper::action_course_show($course));
|
||||
// Refresh the course.
|
||||
$course = new course_in_list(get_course($course->id));
|
||||
$course = new core_course_list_element(get_course($course->id));
|
||||
$this->assertEquals('1', $course->visible);
|
||||
$this->assertEquals('1', $course->visibleold);
|
||||
|
||||
// Revoke the permissions.
|
||||
$assignment->revoke();
|
||||
$course = new course_in_list(get_course($course->id));
|
||||
$course = new core_course_list_element(get_course($course->id));
|
||||
|
||||
try {
|
||||
\core_course\management\helper::action_course_show($course);
|
||||
} catch (moodle_exception $exception) {
|
||||
$this->assertEquals('course_in_list::can_change_visbility', $exception->debuginfo);
|
||||
$this->assertEquals('core_course_list_element::can_change_visbility', $exception->debuginfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -975,7 +975,7 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
try {
|
||||
\core_course\management\helper::action_course_show_by_record($course);
|
||||
} catch (moodle_exception $exception) {
|
||||
$this->assertEquals('course_in_list::can_change_visbility', $exception->debuginfo);
|
||||
$this->assertEquals('core_course_list_element::can_change_visbility', $exception->debuginfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -995,7 +995,7 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
$context = $category->get_context();
|
||||
|
||||
// Update category object from DB so the course count is correct.
|
||||
$category = coursecat::get($category->id);
|
||||
$category = core_course_category::get($category->id);
|
||||
|
||||
list($user, $roleid) = $this->get_user_objects($generator, $context->id);
|
||||
$caps = course_capability_assignment::allow(self::CATEGORY_MANAGE, $roleid, $context->id);
|
||||
@@ -1008,7 +1008,8 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
|
||||
// Move a course down.
|
||||
$this->assertTrue(
|
||||
\core_course\management\helper::action_course_change_sortorder_down_one(new course_in_list(get_course($course1->id)), $category)
|
||||
\core_course\management\helper::action_course_change_sortorder_down_one(
|
||||
new core_course_list_element(get_course($course1->id)), $category)
|
||||
);
|
||||
$courses = $category->get_courses();
|
||||
$this->assertInternalType('array', $courses);
|
||||
@@ -1018,7 +1019,8 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
|
||||
// Move a course up.
|
||||
$this->assertTrue(
|
||||
\core_course\management\helper::action_course_change_sortorder_up_one(new course_in_list(get_course($course3->id)), $category)
|
||||
\core_course\management\helper::action_course_change_sortorder_up_one(
|
||||
new core_course_list_element(get_course($course3->id)), $category)
|
||||
);
|
||||
$courses = $category->get_courses();
|
||||
$this->assertInternalType('array', $courses);
|
||||
@@ -1048,7 +1050,8 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
|
||||
// Try move the bottom course down. This should return false and nothing changes.
|
||||
$this->assertFalse(
|
||||
\core_course\management\helper::action_course_change_sortorder_down_one(new course_in_list(get_course($course1->id)), $category)
|
||||
\core_course\management\helper::action_course_change_sortorder_down_one(
|
||||
new core_course_list_element(get_course($course1->id)), $category)
|
||||
);
|
||||
$courses = $category->get_courses();
|
||||
$this->assertInternalType('array', $courses);
|
||||
@@ -1058,7 +1061,8 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
|
||||
// Try move the top course up. This should return false and nothing changes.
|
||||
$this->assertFalse(
|
||||
\core_course\management\helper::action_course_change_sortorder_up_one(new course_in_list(get_course($course2->id)), $category)
|
||||
\core_course\management\helper::action_course_change_sortorder_up_one(
|
||||
new core_course_list_element(get_course($course2->id)), $category)
|
||||
);
|
||||
$courses = $category->get_courses();
|
||||
$this->assertInternalType('array', $courses);
|
||||
@@ -1069,10 +1073,11 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
// Prohibit the ability to move.
|
||||
$caps->assign(CAP_PROHIBIT);
|
||||
// Reload the category.
|
||||
$category = coursecat::get($category->id);
|
||||
$category = core_course_category::get($category->id);
|
||||
|
||||
try {
|
||||
\core_course\management\helper::action_course_change_sortorder_down_one(new course_in_list(get_course($course2->id)), $category);
|
||||
\core_course\management\helper::action_course_change_sortorder_down_one(
|
||||
new core_course_list_element(get_course($course2->id)), $category);
|
||||
$this->fail('Course moved without having the required permissions.');
|
||||
} catch (moodle_exception $exception) {
|
||||
// Check nothing has changed.
|
||||
@@ -1141,7 +1146,7 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
'moodle/restore:restorecourse'
|
||||
), $roleid, $context->id);
|
||||
|
||||
$actions = \core_course\management\helper::get_course_detail_actions(new course_in_list($course));
|
||||
$actions = \core_course\management\helper::get_course_detail_actions(new core_course_list_element($course));
|
||||
$this->assertInternalType('array', $actions);
|
||||
$this->assertArrayHasKey('view', $actions);
|
||||
$this->assertArrayHasKey('edit', $actions);
|
||||
@@ -1175,7 +1180,7 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
'moodle/site:accessallgroups'
|
||||
), $roleid, $context->id);
|
||||
|
||||
$details = \core_course\management\helper::get_course_detail_array(new course_in_list($course));
|
||||
$details = \core_course\management\helper::get_course_detail_array(new core_course_list_element($course));
|
||||
$this->assertInternalType('array', $details);
|
||||
$this->assertArrayHasKey('format', $details);
|
||||
$this->assertArrayHasKey('fullname', $details);
|
||||
@@ -1261,7 +1266,7 @@ class core_course_management_helper_test extends advanced_testcase {
|
||||
|
||||
// Prevent the user from being able to move into $sub2.
|
||||
$sub2cap = course_capability_assignment::prohibit(self::CATEGORY_MANAGE, $roleid, $sub2->get_context()->id);
|
||||
$sub2 = coursecat::get($sub2->id);
|
||||
$sub2 = core_course_category::get($sub2->id);
|
||||
// Suppress debugging messages for a moment.
|
||||
$olddebug = $CFG->debug;
|
||||
$CFG->debug = 0;
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->dirroot.'/group/lib.php');
|
||||
require_once($CFG->dirroot.'/lib/coursecatlib.php');
|
||||
|
||||
/**
|
||||
* IMS Enterprise file enrolment plugin.
|
||||
@@ -873,10 +872,9 @@ class enrol_imsenterprise_plugin extends enrol_plugin {
|
||||
*/
|
||||
private function get_default_category_id() {
|
||||
global $CFG;
|
||||
require_once($CFG->libdir.'/coursecatlib.php');
|
||||
|
||||
if ($this->defaultcategoryid === null) {
|
||||
$category = coursecat::get_default();
|
||||
$category = core_course_category::get_default();
|
||||
$this->defaultcategoryid = $category->id;
|
||||
}
|
||||
|
||||
@@ -957,7 +955,7 @@ class enrol_imsenterprise_plugin extends enrol_plugin {
|
||||
$newcat->visible = 0;
|
||||
$newcat->parent = $parentid;
|
||||
$newcat->idnumber = $categoryidnumber;
|
||||
$newcat = coursecat::create($newcat);
|
||||
$newcat = core_course_category::create($newcat);
|
||||
$catid = $newcat->id;
|
||||
$this->log_line("Created new (hidden) category '$fullnestedcatname'");
|
||||
} else {
|
||||
|
||||
@@ -372,13 +372,12 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
|
||||
* Add new course without a category.
|
||||
*/
|
||||
public function test_course_add_default_category() {
|
||||
global $DB, $CFG;
|
||||
require_once($CFG->libdir.'/coursecatlib.php');
|
||||
global $DB;
|
||||
|
||||
$this->imsplugin->set_config('createnewcategories', false);
|
||||
|
||||
// Delete the default category, to ensure the plugin handles this gracefully.
|
||||
$defaultcat = coursecat::get_default();
|
||||
$defaultcat = core_course_category::get_default();
|
||||
$defaultcat->delete_full(false);
|
||||
|
||||
// Create an course with the IMS plugin without a category.
|
||||
@@ -781,7 +780,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
|
||||
$this->assertFalse((boolean)$subcatid);
|
||||
|
||||
// Check course was put in default category.
|
||||
$defaultcat = coursecat::get_default();
|
||||
$defaultcat = core_course_category::get_default();
|
||||
$dbcourse = $DB->get_record('course', array('idnumber' => $course1->idnumber), '*', MUST_EXIST);
|
||||
$this->assertEquals($dbcourse->category, $defaultcat->id);
|
||||
|
||||
@@ -949,7 +948,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
|
||||
$this->assertFalse($catid);
|
||||
|
||||
// Check course was put in default category.
|
||||
$defaultcat = coursecat::get_default();
|
||||
$defaultcat = core_course_category::get_default();
|
||||
$dbcourse = $DB->get_record('course', array('idnumber' => $course->idnumber), '*', MUST_EXIST);
|
||||
$this->assertEquals($dbcourse->category, $defaultcat->id);
|
||||
|
||||
|
||||
+4
-6
@@ -1420,7 +1420,7 @@ function get_roles_with_capability($capability, $permission = null, $context = n
|
||||
* @return int new/existing id of the assignment
|
||||
*/
|
||||
function role_assign($roleid, $userid, $contextid, $component = '', $itemid = 0, $timemodified = '') {
|
||||
global $USER, $DB, $CFG;
|
||||
global $USER, $DB;
|
||||
|
||||
// first of all detect if somebody is using old style parameters
|
||||
if ($contextid === 0 or is_numeric($component)) {
|
||||
@@ -1501,8 +1501,7 @@ function role_assign($roleid, $userid, $contextid, $component = '', $itemid = 0,
|
||||
reload_all_capabilities();
|
||||
}
|
||||
|
||||
require_once($CFG->libdir . '/coursecatlib.php');
|
||||
coursecat::role_assignment_changed($roleid, $context);
|
||||
core_course_category::role_assignment_changed($roleid, $context);
|
||||
|
||||
$event = \core\event\role_assigned::create(array(
|
||||
'context' => $context,
|
||||
@@ -1561,7 +1560,6 @@ function role_unassign($roleid, $userid, $contextid, $component = '', $itemid =
|
||||
*/
|
||||
function role_unassign_all(array $params, $subcontexts = false, $includemanual = false) {
|
||||
global $USER, $CFG, $DB;
|
||||
require_once($CFG->libdir . '/coursecatlib.php');
|
||||
|
||||
if (!$params) {
|
||||
throw new coding_exception('Missing parameters in role_unsassign_all() call');
|
||||
@@ -1612,7 +1610,7 @@ function role_unassign_all(array $params, $subcontexts = false, $includemanual =
|
||||
));
|
||||
$event->add_record_snapshot('role_assignments', $ra);
|
||||
$event->trigger();
|
||||
coursecat::role_assignment_changed($ra->roleid, $context);
|
||||
core_course_category::role_assignment_changed($ra->roleid, $context);
|
||||
}
|
||||
}
|
||||
unset($ras);
|
||||
@@ -1644,7 +1642,7 @@ function role_unassign_all(array $params, $subcontexts = false, $includemanual =
|
||||
'other'=>array('id'=>$ra->id, 'component'=>$ra->component, 'itemid'=>$ra->itemid)));
|
||||
$event->add_record_snapshot('role_assignments', $ra);
|
||||
$event->trigger();
|
||||
coursecat::role_assignment_changed($ra->roleid, $context);
|
||||
core_course_category::role_assignment_changed($ra->roleid, $context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,7 +86,7 @@ class course_category_deleted extends base {
|
||||
/**
|
||||
* Returns the legacy event data.
|
||||
*
|
||||
* @return \coursecat the category that was deleted
|
||||
* @return \core_course_category the category that was deleted
|
||||
*/
|
||||
protected function get_legacy_eventdata() {
|
||||
return $this->coursecat;
|
||||
@@ -95,9 +95,9 @@ class course_category_deleted extends base {
|
||||
/**
|
||||
* Set custom data of the event - deleted coursecat.
|
||||
*
|
||||
* @param \coursecat $coursecat
|
||||
* @param \core_course_category $coursecat
|
||||
*/
|
||||
public function set_coursecat(\coursecat $coursecat) {
|
||||
public function set_coursecat(\core_course_category $coursecat) {
|
||||
$this->coursecat = $coursecat;
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ class course_category_deleted extends base {
|
||||
* Returns deleted coursecat for event observers.
|
||||
*
|
||||
* @throws \coding_exception
|
||||
* @return \coursecat
|
||||
* @return \core_course_category
|
||||
*/
|
||||
public function get_coursecat() {
|
||||
if ($this->is_restored()) {
|
||||
|
||||
+2
-2
@@ -36,11 +36,11 @@ use moodle_url;
|
||||
class coursecat_summary_exporter extends \core\external\exporter {
|
||||
|
||||
/**
|
||||
* @var \coursecat $category
|
||||
* @var \core_course_category $category
|
||||
*/
|
||||
protected $category;
|
||||
|
||||
public function __construct(\coursecat $category, $related) {
|
||||
public function __construct(\core_course_category $category, $related) {
|
||||
$this->category = $category;
|
||||
|
||||
$data = [];
|
||||
|
||||
+5
-3208
File diff suppressed because it is too large
Load Diff
@@ -36,4 +36,6 @@ defined('MOODLE_INTERNAL') || die();
|
||||
// The old class name is the key, the new class name is the value.
|
||||
// The array must be called $renamedclasses.
|
||||
$renamedclasses = array(
|
||||
'course_in_list' => 'core_course_list_element',
|
||||
'coursecat' => 'core_course_category',
|
||||
);
|
||||
|
||||
+30
-21
@@ -1090,71 +1090,77 @@ function update_category_button() {
|
||||
*/
|
||||
function make_categories_list() {
|
||||
throw new coding_exception('Global function make_categories_list() is removed. Please use '.
|
||||
'coursecat::make_categories_list() and coursecat::get_parents()');
|
||||
'core_course_category::make_categories_list() and core_course_category::get_parents()');
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since 2.5
|
||||
*/
|
||||
function category_delete_move() {
|
||||
throw new coding_exception('Function category_delete_move() is removed. Please use coursecat::delete_move() instead.');
|
||||
throw new coding_exception('Function category_delete_move() is removed. Please use ' .
|
||||
'core_course_category::delete_move() instead.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since 2.5
|
||||
*/
|
||||
function category_delete_full() {
|
||||
throw new coding_exception('Function category_delete_full() is removed. Please use coursecat::delete_full() instead.');
|
||||
throw new coding_exception('Function category_delete_full() is removed. Please use ' .
|
||||
'core_course_category::delete_full() instead.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since 2.5
|
||||
*/
|
||||
function move_category() {
|
||||
throw new coding_exception('Function move_category() is removed. Please use coursecat::change_parent() instead.');
|
||||
throw new coding_exception('Function move_category() is removed. Please use core_course_category::change_parent() instead.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since 2.5
|
||||
*/
|
||||
function course_category_hide() {
|
||||
throw new coding_exception('Function course_category_hide() is removed. Please use coursecat::hide() instead.');
|
||||
throw new coding_exception('Function course_category_hide() is removed. Please use core_course_category::hide() instead.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since 2.5
|
||||
*/
|
||||
function course_category_show() {
|
||||
throw new coding_exception('Function course_category_show() is removed. Please use coursecat::show() instead.');
|
||||
throw new coding_exception('Function course_category_show() is removed. Please use core_course_category::show() instead.');
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since 2.5. Please use coursecat::get($catid, IGNORE_MISSING) or coursecat::get($catid, MUST_EXIST).
|
||||
* @deprecated since 2.5. Please use core_course_category::get($catid, IGNORE_MISSING) or
|
||||
* core_course_category::get($catid, MUST_EXIST).
|
||||
*/
|
||||
function get_course_category() {
|
||||
throw new coding_exception('Function get_course_category() is removed. Please use coursecat::get(), see phpdocs for more details');
|
||||
throw new coding_exception('Function get_course_category() is removed. Please use core_course_category::get(), ' .
|
||||
'see phpdocs for more details');
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since 2.5
|
||||
*/
|
||||
function create_course_category() {
|
||||
throw new coding_exception('Function create_course_category() is removed. Please use coursecat::create()');
|
||||
throw new coding_exception('Function create_course_category() is removed. Please use core_course_category::create(), ' .
|
||||
'see phpdocs for more details');
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since 2.5. Please use coursecat::get() and coursecat::get_children()
|
||||
* @deprecated since 2.5. Please use core_course_category::get() and core_course_category::get_children()
|
||||
*/
|
||||
function get_all_subcategories() {
|
||||
throw new coding_exception('Function get_all_subcategories() is removed. Please use appropriate methods() ' .
|
||||
'of coursecat class.');
|
||||
throw new coding_exception('Function get_all_subcategories() is removed. Please use appropriate methods() '.
|
||||
'of core_course_category class. See phpdocs for more details');
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since 2.5. Please use coursecat::get($parentid)->get_children().
|
||||
* @deprecated since 2.5. Please use core_course_category::get($parentid)->get_children().
|
||||
*/
|
||||
function get_child_categories() {
|
||||
throw new coding_exception('Function get_child_categories() is removed. Use coursecat::get_children().');
|
||||
throw new coding_exception('Function get_child_categories() is removed. Use core_course_category::get_children() or see ' .
|
||||
'phpdocs for more details.');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1162,7 +1168,7 @@ function get_child_categories() {
|
||||
*/
|
||||
function get_categories() {
|
||||
throw new coding_exception('Function get_categories() is removed. Please use ' .
|
||||
'appropriate functions from class coursecat');
|
||||
'appropriate functions from class core_course_category');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1213,7 +1219,7 @@ function print_category_info() {
|
||||
*/
|
||||
function get_course_category_tree() {
|
||||
throw new coding_exception('Function get_course_category_tree() is removed, please use course ' .
|
||||
'renderer or coursecat class, see function phpdocs for more info');
|
||||
'renderer or core_course_category class, see function phpdocs for more info');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1234,14 +1240,16 @@ function print_course() {
|
||||
* @deprecated since 2.5
|
||||
*/
|
||||
function get_category_courses_array() {
|
||||
throw new coding_exception('Function get_category_courses_array() is removed, please use methods of coursecat class');
|
||||
throw new coding_exception('Function get_category_courses_array() is removed, please use methods of ' .
|
||||
'core_course_category class');
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated since 2.5
|
||||
*/
|
||||
function get_category_courses_array_recursively() {
|
||||
throw new coding_exception('Function get_category_courses_array_recursively() is removed, please use methods of coursecat class', DEBUG_DEVELOPER);
|
||||
throw new coding_exception('Function get_category_courses_array_recursively() is removed, please use ' .
|
||||
'methods of core_course_category class', DEBUG_DEVELOPER);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1255,7 +1263,8 @@ function blog_get_context_url() {
|
||||
* @deprecated since 2.5
|
||||
*/
|
||||
function get_courses_wmanagers() {
|
||||
throw new coding_exception('Function get_courses_wmanagers() is removed, please use coursecat::get_courses()');
|
||||
throw new coding_exception('Function get_courses_wmanagers() is removed, please use ' .
|
||||
'core_course_category::get_courses()');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3101,8 +3110,8 @@ function calendar_get_all_allowed_types() {
|
||||
$types['site'] = true;
|
||||
}
|
||||
|
||||
if (coursecat::has_manage_capability_on_any()) {
|
||||
$types['category'] = coursecat::make_categories_list('moodle/category:manage');
|
||||
if (core_course_category::has_manage_capability_on_any()) {
|
||||
$types['category'] = core_course_category::make_categories_list('moodle/category:manage');
|
||||
}
|
||||
|
||||
// This function warms the context cache for the course so the calls
|
||||
|
||||
+3
-6
@@ -1909,8 +1909,7 @@ abstract class enrol_plugin {
|
||||
);
|
||||
$event->trigger();
|
||||
// Check if course contacts cache needs to be cleared.
|
||||
require_once($CFG->libdir . '/coursecatlib.php');
|
||||
coursecat::user_enrolment_changed($courseid, $ue->userid,
|
||||
core_course_category::user_enrolment_changed($courseid, $ue->userid,
|
||||
$ue->status, $ue->timestart, $ue->timeend);
|
||||
}
|
||||
|
||||
@@ -2004,8 +2003,7 @@ abstract class enrol_plugin {
|
||||
);
|
||||
$event->trigger();
|
||||
|
||||
require_once($CFG->libdir . '/coursecatlib.php');
|
||||
coursecat::user_enrolment_changed($instance->courseid, $ue->userid,
|
||||
core_course_category::user_enrolment_changed($instance->courseid, $ue->userid,
|
||||
$ue->status, $ue->timestart, $ue->timeend);
|
||||
}
|
||||
|
||||
@@ -2089,8 +2087,7 @@ abstract class enrol_plugin {
|
||||
$context->mark_dirty();
|
||||
|
||||
// Check if courrse contacts cache needs to be cleared.
|
||||
require_once($CFG->libdir . '/coursecatlib.php');
|
||||
coursecat::user_enrolment_changed($courseid, $ue->userid, ENROL_USER_SUSPENDED);
|
||||
core_course_category::user_enrolment_changed($courseid, $ue->userid, ENROL_USER_SUSPENDED);
|
||||
|
||||
// reset current user enrolment caching
|
||||
if ($userid == $USER->id) {
|
||||
|
||||
@@ -131,7 +131,7 @@ class file_browser_testcase extends advanced_testcase {
|
||||
public function test_file_info_context_system_hidden() {
|
||||
|
||||
// Hide the course category that contains our two courses. Teacher does not have cap to view hidden categories.
|
||||
coursecat::get($this->course1->category)->update(['visible' => 0]);
|
||||
core_course_category::get($this->course1->category)->update(['visible' => 0]);
|
||||
|
||||
// We should have two non-empty children in system context (courses).
|
||||
$browser = get_file_browser();
|
||||
|
||||
+1
-1
@@ -9841,7 +9841,7 @@ function get_home_page() {
|
||||
* Gets the name of a course to be displayed when showing a list of courses.
|
||||
* By default this is just $course->fullname but user can configure it. The
|
||||
* result of this function should be passed through print_string.
|
||||
* @param stdClass|course_in_list $course Moodle course object
|
||||
* @param stdClass|core_course_list_element $course Moodle course object
|
||||
* @return string Display name of course (either fullname or short + fullname)
|
||||
*/
|
||||
function get_course_display_name_for_list($course) {
|
||||
|
||||
@@ -1497,8 +1497,7 @@ class global_navigation extends navigation_node {
|
||||
protected function show_my_categories() {
|
||||
global $CFG;
|
||||
if ($this->showmycategories === null) {
|
||||
require_once('coursecatlib.php');
|
||||
$this->showmycategories = !empty($CFG->navshowmycoursecategories) && coursecat::count_all() > 1;
|
||||
$this->showmycategories = !empty($CFG->navshowmycoursecategories) && core_course_category::count_all() > 1;
|
||||
}
|
||||
return $this->showmycategories;
|
||||
}
|
||||
@@ -2969,8 +2968,7 @@ class global_navigation extends navigation_node {
|
||||
// Array of category IDs that include the categories of the user's courses and the related course categories.
|
||||
$fullpathcategoryids = [];
|
||||
// Get the course categories for the enrolled courses' category IDs.
|
||||
require_once('coursecatlib.php');
|
||||
$mycoursecategories = coursecat::get_many($categoryids);
|
||||
$mycoursecategories = core_course_category::get_many($categoryids);
|
||||
// Loop over each of these categories and build the category tree using each category's path.
|
||||
foreach ($mycoursecategories as $mycoursecat) {
|
||||
$pathcategoryids = explode('/', $mycoursecat->path);
|
||||
@@ -2981,7 +2979,7 @@ class global_navigation extends navigation_node {
|
||||
}
|
||||
|
||||
// Fetch all of the categories related to the user's courses.
|
||||
$pathcategories = coursecat::get_many($fullpathcategoryids);
|
||||
$pathcategories = core_course_category::get_many($fullpathcategoryids);
|
||||
// Loop over each of these categories and build the category tree.
|
||||
foreach ($pathcategories as $coursecat) {
|
||||
// No need to process categories that have already been added.
|
||||
@@ -3525,11 +3523,10 @@ class navbar extends navigation_node {
|
||||
private function get_course_categories() {
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot.'/course/lib.php');
|
||||
require_once($CFG->libdir.'/coursecatlib.php');
|
||||
|
||||
$categories = array();
|
||||
$cap = 'moodle/category:viewhiddencategories';
|
||||
$showcategories = coursecat::count_all() > 1;
|
||||
$showcategories = core_course_category::count_all() > 1;
|
||||
|
||||
if ($showcategories) {
|
||||
foreach ($this->page->categories as $category) {
|
||||
|
||||
+3
-3
@@ -257,7 +257,7 @@ function question_remove_stale_questions_from_category($categoryid) {
|
||||
* 2/ Any questions that can't be deleted are moved to a new category
|
||||
* NOTE: this function is called from lib/db/upgrade.php
|
||||
*
|
||||
* @param object|coursecat $category course category object
|
||||
* @param object|core_course_category $category course category object
|
||||
*/
|
||||
function question_category_delete_safe($category) {
|
||||
global $DB;
|
||||
@@ -438,8 +438,8 @@ function question_delete_course($course, $feedback=true) {
|
||||
* 1/ All question categories and their questions are deleted for this course category.
|
||||
* 2/ All questions are moved to new category
|
||||
*
|
||||
* @param object|coursecat $category course category object
|
||||
* @param object|coursecat $newcategory empty means everything deleted, otherwise id of
|
||||
* @param object|core_course_category $category course category object
|
||||
* @param object|core_course_category $newcategory empty means everything deleted, otherwise id of
|
||||
* category where content moved
|
||||
* @param boolean $feedback to specify if the process must output a summary of its work
|
||||
* @return boolean
|
||||
|
||||
@@ -289,12 +289,9 @@ EOD;
|
||||
* Create a test course category
|
||||
* @param array|stdClass $record
|
||||
* @param array $options
|
||||
* @return coursecat course category record
|
||||
* @return core_course_category course category record
|
||||
*/
|
||||
public function create_category($record=null, array $options=null) {
|
||||
global $DB, $CFG;
|
||||
require_once("$CFG->libdir/coursecatlib.php");
|
||||
|
||||
$this->categorycount++;
|
||||
$i = $this->categorycount;
|
||||
|
||||
@@ -312,7 +309,7 @@ EOD;
|
||||
$record['idnumber'] = '';
|
||||
}
|
||||
|
||||
return coursecat::create($record);
|
||||
return core_course_category::create($record);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -90,7 +90,7 @@ class core_gradelib_testcase extends advanced_testcase {
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
$category = coursecat::create(array('name' => 'Cat1'));
|
||||
$category = core_course_category::create(array('name' => 'Cat1'));
|
||||
|
||||
// Add a grade letter to the category.
|
||||
$letter = new stdClass();
|
||||
|
||||
@@ -101,6 +101,8 @@ information provided here is intended especially for developers.
|
||||
- file_merge_draft_areas()
|
||||
- file_replace_file_area_in_text()
|
||||
- extract_draft_file_urls_from_text()
|
||||
* Class coursecat is now alias to autoloaded class core_course_category, course_in_list is an alias to
|
||||
core_course_list_element, class coursecat_sortable_records is deprecated without replacement.
|
||||
|
||||
=== 3.5 ===
|
||||
|
||||
|
||||
@@ -162,8 +162,6 @@ class api {
|
||||
public static function search_users($userid, $search, $limitnum = 0) {
|
||||
global $CFG, $DB;
|
||||
|
||||
require_once($CFG->dirroot . '/lib/coursecatlib.php');
|
||||
|
||||
// Used to search for contacts.
|
||||
$fullname = $DB->sql_fullname();
|
||||
$ufields = \user_picture::fields('u', array('lastaccess'));
|
||||
@@ -199,7 +197,7 @@ class api {
|
||||
// 'moodle/course:viewparticipants' or 'moodle/course:enrolreview', but since the search_courses function
|
||||
// only takes required parameters we can't. However, the chance of a user having 'moodle/course:enrolreview' but
|
||||
// *not* 'moodle/course:viewparticipants' are pretty much zero, so it is not worth addressing.
|
||||
if ($arrcourses = \coursecat::search_courses(array('search' => $search), array('limit' => $limitnum),
|
||||
if ($arrcourses = \core_course_category::search_courses(array('search' => $search), array('limit' => $limitnum),
|
||||
array('moodle/course:viewparticipants'))) {
|
||||
foreach ($arrcourses as $course) {
|
||||
if (isset($enrolledcourses[$course->id])) {
|
||||
|
||||
@@ -28,9 +28,9 @@ defined('MOODLE_INTERNAL') || die();
|
||||
require_once($CFG->dirroot . "/course/classes/management_renderer.php");
|
||||
|
||||
use html_writer;
|
||||
use coursecat;
|
||||
use core_course_category;
|
||||
use moodle_url;
|
||||
use course_in_list;
|
||||
use core_course_list_element;
|
||||
use lang_string;
|
||||
use context_system;
|
||||
use stdClass;
|
||||
@@ -103,10 +103,10 @@ class renderer extends \core_course_management_renderer {
|
||||
/**
|
||||
* Renderers detailed course information.
|
||||
*
|
||||
* @param course_in_list $course The course to display details for.
|
||||
* @param core_course_list_element $course The course to display details for.
|
||||
* @return string
|
||||
*/
|
||||
public function course_detail(course_in_list $course) {
|
||||
public function course_detail(core_course_list_element $course) {
|
||||
$details = \core_course\management\helper::get_course_detail_array($course);
|
||||
$fullname = $details['fullname']['value'];
|
||||
|
||||
@@ -184,10 +184,10 @@ class renderer extends \core_course_management_renderer {
|
||||
/**
|
||||
* Presents a course category listing.
|
||||
*
|
||||
* @param coursecat $category The currently selected category. Also the category to highlight in the listing.
|
||||
* @param core_course_category $category The currently selected category. Also the category to highlight in the listing.
|
||||
* @return string
|
||||
*/
|
||||
public function category_listing(coursecat $category = null) {
|
||||
public function category_listing(core_course_category $category = null) {
|
||||
|
||||
if ($category === null) {
|
||||
$selectedparents = array();
|
||||
@@ -201,7 +201,7 @@ class renderer extends \core_course_management_renderer {
|
||||
$catatlevel[] = array_shift($selectedparents);
|
||||
$catatlevel = array_unique($catatlevel);
|
||||
|
||||
$listing = coursecat::get(0)->get_children();
|
||||
$listing = core_course_category::get(0)->get_children();
|
||||
|
||||
$attributes = array(
|
||||
'class' => 'ml-1 list-unstyled',
|
||||
@@ -241,14 +241,14 @@ class renderer extends \core_course_management_renderer {
|
||||
*
|
||||
* This function gets called recursively to render sub categories.
|
||||
*
|
||||
* @param coursecat $category The category to render as listitem.
|
||||
* @param coursecat[] $subcategories The subcategories belonging to the category being rented.
|
||||
* @param core_course_category $category The category to render as listitem.
|
||||
* @param core_course_category[] $subcategories The subcategories belonging to the category being rented.
|
||||
* @param int $totalsubcategories The total number of sub categories.
|
||||
* @param int $selectedcategory The currently selected category
|
||||
* @param int[] $selectedcategories The path to the selected category and its ID.
|
||||
* @return string
|
||||
*/
|
||||
public function category_listitem(coursecat $category, array $subcategories, $totalsubcategories,
|
||||
public function category_listitem(core_course_category $category, array $subcategories, $totalsubcategories,
|
||||
$selectedcategory = null, $selectedcategories = array()) {
|
||||
|
||||
$isexpandable = ($totalsubcategories > 0);
|
||||
@@ -383,23 +383,23 @@ class renderer extends \core_course_management_renderer {
|
||||
* These are not the actions associated with an individual category listing.
|
||||
* That happens through category_listitem_actions.
|
||||
*
|
||||
* @param coursecat $category
|
||||
* @param core_course_category $category
|
||||
* @return string
|
||||
*/
|
||||
public function category_listing_actions(coursecat $category = null) {
|
||||
public function category_listing_actions(core_course_category $category = null) {
|
||||
$actions = array();
|
||||
|
||||
$cancreatecategory = $category && $category->can_create_subcategory();
|
||||
$cancreatecategory = $cancreatecategory || coursecat::can_create_top_level_category();
|
||||
$cancreatecategory = $cancreatecategory || core_course_category::can_create_top_level_category();
|
||||
if ($category === null) {
|
||||
$category = coursecat::get(0);
|
||||
$category = core_course_category::get(0);
|
||||
}
|
||||
|
||||
if ($cancreatecategory) {
|
||||
$url = new moodle_url('/course/editcategory.php', array('parent' => $category->id));
|
||||
$actions[] = html_writer::link($url, get_string('createnewcategory'), array('class' => 'btn btn-default'));
|
||||
}
|
||||
if (coursecat::can_approve_course_requests()) {
|
||||
if (core_course_category::can_approve_course_requests()) {
|
||||
$actions[] = html_writer::link(new moodle_url('/course/pending.php'), get_string('coursespending'));
|
||||
}
|
||||
if (count($actions) === 0) {
|
||||
@@ -411,14 +411,14 @@ class renderer extends \core_course_management_renderer {
|
||||
/**
|
||||
* Renders a course listing.
|
||||
*
|
||||
* @param coursecat $category The currently selected category. This is what the listing is focused on.
|
||||
* @param course_in_list $course The currently selected course.
|
||||
* @param core_course_category $category The currently selected category. This is what the listing is focused on.
|
||||
* @param core_course_list_element $course The currently selected course.
|
||||
* @param int $page The page being displayed.
|
||||
* @param int $perpage The number of courses to display per page.
|
||||
* @param string|null $viewmode The view mode the page is in, one out of 'default', 'combined', 'courses' or 'categories'.
|
||||
* @return string
|
||||
*/
|
||||
public function course_listing(coursecat $category = null, course_in_list $course = null,
|
||||
public function course_listing(core_course_category $category = null, core_course_list_element $course = null,
|
||||
$page = 0, $perpage = 20, $viewmode = 'default') {
|
||||
|
||||
if ($category === null) {
|
||||
@@ -479,12 +479,12 @@ class renderer extends \core_course_management_renderer {
|
||||
*
|
||||
* This function will be called for every course being displayed by course_listing.
|
||||
*
|
||||
* @param coursecat $category The currently selected category and the category the course belongs to.
|
||||
* @param course_in_list $course The course to produce HTML for.
|
||||
* @param core_course_category $category The currently selected category and the category the course belongs to.
|
||||
* @param core_course_list_element $course The course to produce HTML for.
|
||||
* @param int $selectedcourse The id of the currently selected course.
|
||||
* @return string
|
||||
*/
|
||||
public function course_listitem(coursecat $category, course_in_list $course, $selectedcourse) {
|
||||
public function course_listitem(core_course_category $category, core_course_list_element $course, $selectedcourse) {
|
||||
|
||||
$text = $course->get_formatted_name();
|
||||
$attributes = array(
|
||||
@@ -537,12 +537,12 @@ class renderer extends \core_course_management_renderer {
|
||||
*
|
||||
* Not to be confused with course_listitem_actions which renderers the actions for individual courses.
|
||||
*
|
||||
* @param coursecat $category
|
||||
* @param course_in_list $course The currently selected course.
|
||||
* @param core_course_category $category
|
||||
* @param core_course_list_element $course The currently selected course.
|
||||
* @param int $perpage
|
||||
* @return string
|
||||
*/
|
||||
public function course_listing_actions(coursecat $category, course_in_list $course = null, $perpage = 20) {
|
||||
public function course_listing_actions(core_course_category $category, core_course_list_element $course = null, $perpage = 20) {
|
||||
$actions = array();
|
||||
if ($category->can_create_course()) {
|
||||
$url = new moodle_url('/course/edit.php', array('category' => $category->id, 'returnto' => 'catmanage'));
|
||||
@@ -618,13 +618,13 @@ class renderer extends \core_course_management_renderer {
|
||||
*
|
||||
* @param array $courses The courses to display.
|
||||
* @param int $totalcourses The total number of courses to display.
|
||||
* @param course_in_list $course The currently selected course if there is one.
|
||||
* @param core_course_list_element $course The currently selected course if there is one.
|
||||
* @param int $page The current page, starting at 0.
|
||||
* @param int $perpage The number of courses to display per page.
|
||||
* @param string $search The string we are searching for.
|
||||
* @return string
|
||||
*/
|
||||
public function search_listing(array $courses, $totalcourses, course_in_list $course = null, $page = 0, $perpage = 20,
|
||||
public function search_listing(array $courses, $totalcourses, core_course_list_element $course = null, $page = 0, $perpage = 20,
|
||||
$search = '') {
|
||||
$page = max($page, 0);
|
||||
$perpage = max($perpage, 2);
|
||||
@@ -666,11 +666,11 @@ class renderer extends \core_course_management_renderer {
|
||||
*
|
||||
* This function will be called for every course being displayed by course_listing.
|
||||
*
|
||||
* @param course_in_list $course The course to produce HTML for.
|
||||
* @param core_course_list_element $course The course to produce HTML for.
|
||||
* @param int $selectedcourse The id of the currently selected course.
|
||||
* @return string
|
||||
*/
|
||||
public function search_listitem(course_in_list $course, $selectedcourse) {
|
||||
public function search_listitem(core_course_list_element $course, $selectedcourse) {
|
||||
|
||||
$text = $course->get_formatted_name();
|
||||
$attributes = array(
|
||||
@@ -680,7 +680,7 @@ class renderer extends \core_course_management_renderer {
|
||||
'data-visible' => $course->visible ? '1' : '0'
|
||||
);
|
||||
$bulkcourseinput = '';
|
||||
if (coursecat::get($course->category)->can_move_courses_out_of()) {
|
||||
if (core_course_category::get($course->category)->can_move_courses_out_of()) {
|
||||
$bulkcourseinput = array(
|
||||
'type' => 'checkbox',
|
||||
'name' => 'bc[]',
|
||||
@@ -691,7 +691,7 @@ class renderer extends \core_course_management_renderer {
|
||||
);
|
||||
}
|
||||
$viewcourseurl = new moodle_url($this->page->url, array('courseid' => $course->id));
|
||||
$categoryname = coursecat::get($course->category)->get_formatted_name();
|
||||
$categoryname = core_course_category::get($course->category)->get_formatted_name();
|
||||
|
||||
$html = html_writer::start_tag('li', $attributes);
|
||||
$html .= html_writer::start_div('clearfix');
|
||||
@@ -730,10 +730,10 @@ class renderer extends \core_course_management_renderer {
|
||||
/**
|
||||
* A collection of actions for a course.
|
||||
*
|
||||
* @param course_in_list $course The course to display actions for.
|
||||
* @param core_course_list_element $course The course to display actions for.
|
||||
* @return string
|
||||
*/
|
||||
public function course_detail_actions(course_in_list $course) {
|
||||
public function course_detail_actions(core_course_list_element $course) {
|
||||
$actions = \core_course\management\helper::get_course_detail_actions($course);
|
||||
if (empty($actions)) {
|
||||
return '';
|
||||
|
||||
@@ -66,9 +66,7 @@ class user_filter_courserole extends user_filter_type {
|
||||
* @return array of course categories
|
||||
*/
|
||||
public function get_course_categories() {
|
||||
global $CFG;
|
||||
require_once($CFG->libdir.'/coursecatlib.php');
|
||||
return array(0 => get_string('anycategory', 'filters')) + coursecat::make_categories_list();
|
||||
return array(0 => get_string('anycategory', 'filters')) + core_course_category::make_categories_list();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user