Search moodle.org's
Developer Documentation

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
  • /cohort/ -> lib.php (source)

    Differences Between: [Versions 310 and 34] [Versions 310 and 35] [Versions 34 and 310] [Versions 35 and 310]

    Cohort related management functions, this file needs to be included manually.

    Copyright: 2010 Petr Skoda {@link http://skodak.org}
    License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
    File Size: 637 lines (23 kb)
    Included or required:0 times
    Referenced: 14 times
    Includes or requires: 0 files

    Defines 19 functions


    Functions that are not part of a class:

    cohort_add_cohort($cohort)   X-Ref
    Add new cohort.

    return: int new cohort id
    param: stdClass $cohort

    cohort_update_cohort($cohort)   X-Ref
    Update existing cohort.

    return: void
    param: stdClass $cohort

    cohort_delete_cohort($cohort)   X-Ref
    Delete cohort.

    return: void
    param: stdClass $cohort

    cohort_delete_category($category)   X-Ref
    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.

    return: void
    param: stdClass|core_course_category $category

    cohort_add_member($cohortid, $userid)   X-Ref
    Add cohort member

    return: void
    param: int $cohortid
    param: int $userid

    cohort_remove_member($cohortid, $userid)   X-Ref
    Remove cohort member

    return: void
    param: int $cohortid
    param: int $userid

    cohort_is_member($cohortid, $userid)   X-Ref
    Is this user a cohort member?

    return: bool
    param: int $cohortid
    param: int $userid

    cohort_get_available_cohorts($currentcontext, $withmembers = 0, $offset = 0, $limit = 25, $search = '')   X-Ref
    Returns the list of cohorts visible to the current user in the given course.

    The following fields are returned in each record: id, name, contextid, idnumber, visible
    Fields memberscnt and enrolledcnt will be also returned if requested

    return: array
    param: context $currentcontext
    param: int $withmembers one of the COHORT_XXX constants that allows to return non empty cohorts only
    param: int $offset
    param: int $limit
    param: string $search

    cohort_can_view_cohort($cohortorid, $currentcontext)   X-Ref
    No description

    cohort_get_cohort($cohortorid, $currentcontext)   X-Ref
    Get a cohort by id. Also does a visibility check and returns false if the user cannot see this cohort.

    return: stdClass|boolean
    param: stdClass|int $cohortorid cohort object or id
    param: context $currentcontext current context (course) where visibility is checked

    cohort_get_search_query($search, $tablealias = '')   X-Ref
    Produces a part of SQL query to filter cohorts by the search string

    Called from {@link cohort_get_cohorts()}, {@link cohort_get_all_cohorts()} and {@link cohort_get_available_cohorts()}

    return: array of two elements - SQL condition and array of named parameters
    param: string $search search string
    param: string $tablealias alias of cohort table in the SQL query (highly recommended if other tables are used in query)

    cohort_get_cohorts($contextid, $page = 0, $perpage = 25, $search = '')   X-Ref
    Get all the cohorts defined in given context.

    The function does not check user capability to view/manage cohorts in the given context
    assuming that it has been already verified.

    return: array    Array(totalcohorts => int, cohorts => array, allcohorts => int)
    param: int $contextid
    param: int $page number of the current page
    param: int $perpage items per page
    param: string $search search string

    cohort_get_all_cohorts($page = 0, $perpage = 25, $search = '')   X-Ref
    Get all the cohorts defined anywhere in system.

    The function assumes that user capability to view/manage cohorts on system level
    has already been verified. This function only checks if such capabilities have been
    revoked in child (categories) contexts.

    return: array    Array(totalcohorts => int, cohorts => array, allcohorts => int)
    param: int $page number of the current page
    param: int $perpage items per page
    param: string $search search string

    cohort_get_user_cohorts($userid)   X-Ref
    Get all the cohorts where the given user is member of.

    return: array Array
    param: int $userid

    cohort_get_user_cohort_theme($userid)   X-Ref
    Get the user cohort theme.

    If the user is member of one cohort, will return this cohort theme (if defined).
    If the user is member of 2 or more cohorts, will return the theme if all them have the same
    theme (null themes are ignored).

    return: string|null
    param: int $userid

    cohort_get_invisible_contexts()   X-Ref
    Returns list of contexts where cohorts are present but current user does not have capability to view/manage them.

    This function is called from {@link cohort_get_all_cohorts()} to ensure correct pagination in rare cases when user
    is revoked capability in child contexts. It assumes that user's capability to view/manage cohorts on system
    level has already been verified.

    return: array array of context ids

    cohort_edit_controls(context $context, moodle_url $currenturl)   X-Ref
    Returns navigation controls (tabtree) to be displayed on cohort management pages

    return: null|renderable
    param: context $context system or category context where cohorts controls are about to be displayed
    param: moodle_url $currenturl

    core_cohort_inplace_editable($itemtype, $itemid, $newvalue)   X-Ref
    Implements callback inplace_editable() allowing to edit values in-place

    return: \core\output\inplace_editable
    param: string $itemtype
    param: int $itemid
    param: mixed $newvalue

    cohort_get_list_of_themes()   X-Ref
    Returns a list of valid themes which can be displayed in a selector.

    return: array as (string)themename => (string)get_string_theme