Search moodle.org's
Developer Documentation

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
  • Differences Between: [Versions 311 and 400] [Versions 37 and 311] [Versions 38 and 311]

    Course and category management helper class.

    Copyright: 2013 Sam Hemelryk
    License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
    File Size: 1027 lines (42 kb)
    Included or required:0 times
    Referenced: 0 times
    Includes or requires: 0 files

    Defines 1 class


    Class: helper  - X-Ref

    Course and category management interface helper class.

    This class provides methods useful to the course and category management interfaces.
    Many of the methods on this class are static and serve one of two purposes.
    1.  encapsulate functionality in an effort to ensure minimal changes between the different
    methods of interaction. Specifically browser, AJAX and webservice.
    2.  abstract logic for acquiring actions away from output so that renderers may use them without
    having to include any logic or capability checks.

    get_course_detail_array(\core_course_list_element $course)   X-Ref
    Returns course details in an array ready to be printed.

    param: \core_course_list_element $course
    return: array

    get_category_listitem_actions(\core_course_category $category)   X-Ref
    Returns an array of actions that can be performed upon a category being shown in a list.

    param: \core_course_category $category
    return: array

    get_course_listitem_actions(\core_course_category $category, \core_course_list_element $course)   X-Ref
    Returns an array of actions for a course listitem.

    param: \core_course_category $category
    param: \core_course_list_element $course
    return: array

    get_course_detail_actions(\core_course_list_element $course)   X-Ref
    Returns an array of actions that can be performed on the course being displayed.

    param: \core_course_list_element $course
    return: array

    action_course_change_sortorder_up_one(\core_course_list_element $course,\core_course_category $category)   X-Ref
    Resorts the courses within a category moving the given course up by one.

    param: \core_course_list_element $course
    param: \core_course_category $category
    return: bool

    action_course_change_sortorder_down_one(\core_course_list_element $course,\core_course_category $category)   X-Ref
    Resorts the courses within a category moving the given course down by one.

    param: \core_course_list_element $course
    param: \core_course_category $category
    return: bool

    action_course_change_sortorder_up_one_by_record($courserecordorid)   X-Ref
    Resorts the courses within a category moving the given course up by one.

    param: int|\stdClass $courserecordorid
    return: bool

    action_course_change_sortorder_down_one_by_record($courserecordorid)   X-Ref
    Resorts the courses within a category moving the given course down by one.

    param: int|\stdClass $courserecordorid
    return: bool

    action_course_change_sortorder_after_course($courserecordorid, $moveaftercourseid)   X-Ref
    Changes the sort order so that the first course appears after the second course.

    param: int|\stdClass $courserecordorid
    param: int $moveaftercourseid
    return: bool

    action_course_show(\core_course_list_element $course)   X-Ref
    Makes a course visible given a \core_course_list_element object.

    param: \core_course_list_element $course
    return: bool

    action_course_hide(\core_course_list_element $course)   X-Ref
    Makes a course hidden given a \core_course_list_element object.

    param: \core_course_list_element $course
    return: bool

    action_course_show_by_record($courserecordorid)   X-Ref
    Makes a course visible given a course id or a database record.

    param: int|\stdClass $courserecordorid
    return: bool

    action_course_hide_by_record($courserecordorid)   X-Ref
    Makes a course hidden given a course id or a database record.

    param: int|\stdClass $courserecordorid
    return: bool

    action_category_change_sortorder_up_one(\core_course_category $category)   X-Ref
    Resort a categories subcategories shifting the given category up one.

    param: \core_course_category $category
    return: bool

    action_category_change_sortorder_down_one(\core_course_category $category)   X-Ref
    Resort a categories subcategories shifting the given category down one.

    param: \core_course_category $category
    return: bool

    action_category_change_sortorder_up_one_by_id($categoryid)   X-Ref
    Resort a categories subcategories shifting the given category up one.

    param: int $categoryid
    return: bool

    action_category_change_sortorder_down_one_by_id($categoryid)   X-Ref
    Resort a categories subcategories shifting the given category down one.

    param: int $categoryid
    return: bool

    action_category_hide(\core_course_category $category)   X-Ref
    Makes a category hidden given a core_course_category object.

    param: \core_course_category $category
    return: bool

    action_category_show(\core_course_category $category)   X-Ref
    Makes a category visible given a core_course_category object.

    param: \core_course_category $category
    return: bool

    action_category_show_by_id($categoryid)   X-Ref
    Makes a category visible given a course category id or database record.

    param: int|\stdClass $categoryid
    return: bool

    action_category_hide_by_id($categoryid)   X-Ref
    Makes a category hidden given a course category id or database record.

    param: int|\stdClass $categoryid
    return: bool

    action_category_resort_subcategories(\core_course_category $category, $sort, $cleanup = true)   X-Ref
    Resorts the sub categories of the given 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

    action_category_resort_courses(\core_course_category $category, $sort, $cleanup = true)   X-Ref
    Resorts the courses within the given 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

    action_category_move_courses_into(\core_course_category $oldcategory,\core_course_category $newcategory, array $courseids)   X-Ref
    Moves courses out of one category and into a new category.

    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.

    get_management_viewmodes()   X-Ref
    Returns the view modes for the management interface.

    return: array

    search_courses($search, $blocklist, $modulelist, $page = 0, $perpage = null)   X-Ref
    Search for courses with matching params.

    Please note that only one of search, blocklist, or modulelist can be specified at a time.
    Specifying more than one will result in only the first being used.

    param: string $search Words to search for. We search fullname, shortname, idnumber and summary.
    param: int $blocklist The ID of a block, courses will only be returned if they use this block.
    param: string $modulelist The name of a module (relates to database table name). Only courses containing this module
    param: int $page The page number to display, starting at 0.
    param: int $perpage The number of courses to display per page.
    return: array

    move_courses_into_category($categoryorid, $courseids = array()   X-Ref
    Moves one or more courses out of the category they are currently in and into a new category.

    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|\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.

    get_category_courses_visibility($categoryid)   X-Ref
    Returns an array of courseids and visiblity for all courses within the given category.

    param: int $categoryid
    return: array

    get_category_children_visibility($categoryid)   X-Ref
    Returns an array of all categoryids that have the given category as a parent and their visible value.

    param: int $categoryid
    return: array

    record_expanded_category(\core_course_category $coursecat, $expanded = true)   X-Ref
    Records when a category is expanded or collapsed so that when the user

    param: \core_course_category $coursecat The category we're working with.
    param: bool $expanded True if the category is expanded now.

    get_expanded_categories($withpath = null)   X-Ref
    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: \core_course_category[] An array of Category ID's to expand.

    get_course_copy_capabilities()   X-Ref
    Get an array of the capabilities required to copy a course.

    return: array

    can_copy_course(int $courseid)   X-Ref
    Returns true if the current user can copy this course.

    param: int $courseid
    return: bool