Skip to content

Commit

Permalink
MDL-62742 core: rename coursecat->core_course_category
Browse files Browse the repository at this point in the history
Also rename course_in_list -> core_course_list_element
Deprecate class coursecat_sortable_records
  • Loading branch information
marinaglancy committed Aug 28, 2018
1 parent 8df868e commit 442f12f
Show file tree
Hide file tree
Showing 64 changed files with 3,890 additions and 3,837 deletions.
5 changes: 2 additions & 3 deletions admin/roles/classes/define_role_table_advanced.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ protected function load_parent_permissions() {
}

public function save_changes() {
global $DB, $CFG;
global $DB;

if (!$this->roleid) {
// Creating role.
Expand All @@ -448,8 +448,7 @@ public function save_changes() {
// 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.
Expand Down
10 changes: 4 additions & 6 deletions admin/tool/dataprivacy/classes/data_registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@

defined('MOODLE_INTERNAL') || die();

require_once($CFG->libdir . '/coursecatlib.php');

/**
* Data registry business logic methods. Mostly internal stuff.
*
Expand Down Expand Up @@ -113,17 +111,17 @@ public static function defaults_set() {
/**
* 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) {
Expand Down
3 changes: 1 addition & 2 deletions admin/tool/dataprivacy/classes/output/data_registry_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
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');

Expand Down Expand Up @@ -226,7 +225,7 @@ public static function get_courses_branch(\context $catcontext) {
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 = [];
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/recyclebin/tests/category_bin_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function test_pre_course_category_delete_hook() {
$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.
Expand Down
3 changes: 1 addition & 2 deletions admin/tool/uploadcourse/classes/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -379,7 +378,7 @@ public static function resolve_category($data, &$errors = array()) {
$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 {
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/uploadcourse/classes/step2_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function definition () {
$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');

Expand Down
3 changes: 1 addition & 2 deletions admin/tool/uploadcourse/cli/uploadcourse.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

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');
Expand All @@ -46,7 +45,7 @@
'allowrenames' => false,
'allowresets' => false,
'reset' => false,
'category' => coursecat::get_default()->id,
'category' => core_course_category::get_default()->id,
),
array(
'h' => 'help',
Expand Down
1 change: 0 additions & 1 deletion admin/tool/uploadcourse/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/usertours/classes/local/filter/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static function get_filter_name() {
* 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;
}

Expand Down
3 changes: 1 addition & 2 deletions badges/criteria/award_criteria_courseset.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ public function get_courses(&$mform) {
// 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();
Expand Down
3 changes: 1 addition & 2 deletions blocks/course_list/block_course_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -76,7 +75,7 @@ function get_content() {
}
}

$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) {
Expand Down
3 changes: 1 addition & 2 deletions blocks/myoverview/classes/output/courses_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ public function __construct($courses, $coursesprogress) {
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 = [
Expand All @@ -84,7 +83,7 @@ public function export_for_template(renderer_base $output) {
// 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) {
Expand Down
2 changes: 1 addition & 1 deletion calendar/classes/local/event/container.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ function ($dbrow) {

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;
Expand Down
2 changes: 0 additions & 2 deletions calendar/classes/local/event/data_access/event_vault.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
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.
*
Expand Down
2 changes: 1 addition & 1 deletion calendar/classes/local/event/forms/eventtype.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ protected function add_event_type_elements($mform, $eventtypes) {

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;
}

Expand Down
10 changes: 4 additions & 6 deletions calendar/classes/local/event/proxies/coursecat_proxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

defined('MOODLE_INTERNAL') || die();

require_once($CFG->libdir . '/coursecatlib.php');

/**
* Course category proxy.
*
Expand All @@ -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;

Expand Down Expand Up @@ -81,11 +79,11 @@ public function get($member) {
/**
* 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;
}
Expand Down
5 changes: 3 additions & 2 deletions calendar/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ public static function get_calendar_events($events = array(), $options = array()
$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())) {
Expand All @@ -267,7 +268,7 @@ public static function get_calendar_events($events = array(), $options = array()
$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,
Expand Down
20 changes: 9 additions & 11 deletions calendar/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
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
*/
Expand Down Expand Up @@ -805,7 +803,7 @@ public function properties($prepareeditor = false) {
$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 {
Expand Down Expand Up @@ -1067,14 +1065,14 @@ public static function create($time, int $courseid, int $categoryid = null) : ca
}

$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;
Expand Down Expand Up @@ -1158,15 +1156,15 @@ public function set_sources(stdClass $course, array $courses, stdClass $category
// 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();
$this->categories[] = $category->id;
} 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.
Expand All @@ -1188,7 +1186,7 @@ public function set_sources(stdClass $course, array $courses, stdClass $category
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,
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion calendar/managesubscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@

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;
}
Expand Down
Loading

0 comments on commit 442f12f

Please sign in to comment.