Commit 442f12f8 authored by Marina Glancy's avatar Marina Glancy
Browse files

MDL-62742 core: rename coursecat->core_course_category

Also rename course_in_list -> core_course_list_element
Deprecate class coursecat_sortable_records
parent 8df868e9
......@@ -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,
......
......@@ -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;
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment