Moodle PHP Documentation 4.3
Moodle 4.3.5 (Build: 20240610) (7dcfaa79f78)
core_cohort

Namespaces

namespace  core_cohort\customfield
  
 
namespace  core_cohort\external
  
 
namespace  core_cohort\output
  
 
namespace  core_cohort\privacy
  
 
namespace  core_cohort\reportbuilder\datasource
  
 
namespace  core_cohort\reportbuilder\local\entities
  
 
namespace  core_cohort\reportbuilder\local\systemreports
  
 

Classes

class  behat_cohort
 Steps definitions for cohort actions. More...
 
class  cohort_candidate_selector
 Cohort assignment candidates. More...
 
class  cohort_edit_form
 
class  cohort_existing_selector
 Cohort assignment candidates. More...
 
class  cohort_upload_form
 Cohort upload form class. More...
 
class  core_cohort\customfield\cohort_handler
 
class  core_cohort\external\cohort_summary_exporter
 Class for exporting a cohort summary from an stdClass. More...
 
class  core_cohort\output\cohortidnumber
 Class to prepare a cohort idnumber for display. More...
 
class  core_cohort\output\cohortname
 Class to prepare a cohort name for display. More...
 
class  core_cohort\privacy\provider
 Privacy class for requesting user data. More...
 
class  core_cohort\reportbuilder\datasource\cohorts
 
class  core_cohort\reportbuilder\local\entities\cohort
 
class  core_cohort\reportbuilder\local\entities\cohort_member
 
class  core_cohort\reportbuilder\local\systemreports\cohorts
 

Functions

 cohort_add_cohort ($cohort)
 Add new cohort.
 
 cohort_add_member ($cohortid, $userid)
 Add cohort member.
 
 cohort_can_view_cohort ($cohortorid, $currentcontext)
 Check if cohort exists and user is allowed to access it from the given context.
 
 cohort_delete_category ($category)
 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.
 
 cohort_delete_cohort ($cohort)
 Delete cohort.
 
 cohort_edit_controls (context $context, moodle_url $currenturl)
 Returns navigation controls (tabtree) to be displayed on cohort management pages.
 
 cohort_get_all_cohorts ($page=0, $perpage=25, $search='', $withcustomfields=false)
 Get all the cohorts defined anywhere in system.
 
 cohort_get_available_cohorts ($currentcontext, $withmembers=0, $offset=0, $limit=25, $search='', $withcustomfields=false)
 Returns the list of cohorts visible to the current user in the given course.
 
 cohort_get_cohort ($cohortorid, $currentcontext, $withcustomfields=false)
 Get a cohort by id.
 
 cohort_get_cohorts ($contextid, $page=0, $perpage=25, $search='', $withcustomfields=false)
 Get all the cohorts defined in given context.
 
 cohort_get_custom_fields_data (array $cohortids)
 Returns custom fields data for provided cohorts.
 
 cohort_get_list_of_themes ()
 Returns a list of valid themes which can be displayed in a selector.
 
 cohort_get_user_cohort_theme ($userid)
 Get the user cohort theme.
 
 cohort_get_user_cohorts ($userid, $withcustomfields=false)
 Get all the cohorts where the given user is member of.
 
 cohort_is_member ($cohortid, $userid)
 Is this user a cohort member?
 
 cohort_remove_member ($cohortid, $userid)
 Remove cohort member.
 
 cohort_update_cohort ($cohort)
 Update existing cohort.
 
 core_cohort_inplace_editable ($itemtype, $itemid, $newvalue)
 Implements callback inplace_editable() allowing to edit values in-place.
 

Variables

const COHORT_ALL 0
 
const COHORT_COUNT_ENROLLED_MEMBERS 3
 
const COHORT_COUNT_MEMBERS 1
 
const COHORT_WITH_ENROLLED_MEMBERS_ONLY 17
 
const COHORT_WITH_MEMBERS_ONLY 5
 
const COHORT_WITH_NOTENROLLED_MEMBERS_ONLY 23
 

Detailed Description

Function Documentation

◆ cohort_add_cohort()

cohort_add_cohort ( $cohort)

Add new cohort.

Parameters
stdClass$cohort
Return values
intnew cohort id

◆ cohort_add_member()

cohort_add_member ( $cohortid,
$userid )

Add cohort member.

Parameters
int$cohortid
int$userid
Return values
void

◆ cohort_can_view_cohort()

cohort_can_view_cohort ( $cohortorid,
$currentcontext )

Check if cohort exists and user is allowed to access it from the given context.

Parameters
stdClass | int$cohortoridcohort object or id
context$currentcontextcurrent context (course) where visibility is checked
Return values
boolean

◆ cohort_delete_category()

cohort_delete_category ( $category)

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.

Parameters
stdClass | core_course_category$category
Return values
void

◆ cohort_delete_cohort()

cohort_delete_cohort ( $cohort)

Delete cohort.

Parameters
stdClass$cohort
Return values
void

◆ cohort_edit_controls()

cohort_edit_controls ( context $context,
moodle_url $currenturl )

Returns navigation controls (tabtree) to be displayed on cohort management pages.

Parameters
context$contextsystem or category context where cohorts controls are about to be displayed
moodle_url$currenturl
Return values
null|renderable

◆ cohort_get_all_cohorts()

cohort_get_all_cohorts ( $page = 0,
$perpage = 25,
$search = '',
$withcustomfields = false )

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.

Parameters
int$pagenumber of the current page
int$perpageitems per page
string$searchsearch string
bool$withcustomfieldsif set to yes, then cohort custom fields will be included in the results.
Return values
arrayArray(totalcohorts => int, cohorts => array, allcohorts => int)

◆ cohort_get_available_cohorts()

cohort_get_available_cohorts ( $currentcontext,
$withmembers = 0,
$offset = 0,
$limit = 25,
$search = '',
$withcustomfields = false )

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

Parameters
context$currentcontext
int$withmembersone of the COHORT_XXX constants that allows to return non empty cohorts only or cohorts with enroled/not enroled users, or just return members count
int$offset
int$limit
string$search
bool$withcustomfieldsif set to yes, then cohort custom fields will be included in the results.
Return values
array

◆ cohort_get_cohort()

cohort_get_cohort ( $cohortorid,
$currentcontext,
$withcustomfields = false )

Get a cohort by id.

Also does a visibility check and returns false if the user cannot see this cohort.

Parameters
stdClass | int$cohortoridcohort object or id
context$currentcontextcurrent context (course) where visibility is checked
bool$withcustomfieldsif set to yes, then cohort custom fields will be included in the results.
Return values
stdClass|boolean

◆ cohort_get_cohorts()

cohort_get_cohorts ( $contextid,
$page = 0,
$perpage = 25,
$search = '',
$withcustomfields = false )

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.

Parameters
int$contextid
int$pagenumber of the current page
int$perpageitems per page
string$searchsearch string
bool$withcustomfieldsif set to yes, then cohort custom fields will be included in the results.
Return values
arrayArray(totalcohorts => int, cohorts => array, allcohorts => int)

◆ cohort_get_custom_fields_data()

cohort_get_custom_fields_data ( array $cohortids)

Returns custom fields data for provided cohorts.

Parameters
array$cohortidsa list of cohort IDs to provide data for.
Return values
core_customfield\data_controller[]

◆ cohort_get_list_of_themes()

cohort_get_list_of_themes ( )

Returns a list of valid themes which can be displayed in a selector.

Return values
arrayas (string)themename => (string)get_string_theme

◆ cohort_get_user_cohort_theme()

cohort_get_user_cohort_theme ( $userid)

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

Parameters
int$userid
Return values
string|null

◆ cohort_get_user_cohorts()

cohort_get_user_cohorts ( $userid,
$withcustomfields = false )

Get all the cohorts where the given user is member of.

Parameters
int$userid
bool$withcustomfieldsif set to yes, then cohort custom fields will be included in the results.
Return values
arrayArray

◆ cohort_is_member()

cohort_is_member ( $cohortid,
$userid )

Is this user a cohort member?

Parameters
int$cohortid
int$userid
Return values
bool

◆ cohort_remove_member()

cohort_remove_member ( $cohortid,
$userid )

Remove cohort member.

Parameters
int$cohortid
int$userid
Return values
void

◆ cohort_update_cohort()

cohort_update_cohort ( $cohort)

Update existing cohort.

Parameters
stdClass$cohort
Return values
void

◆ core_cohort_inplace_editable()

core_cohort_inplace_editable ( $itemtype,
$itemid,
$newvalue )

Implements callback inplace_editable() allowing to edit values in-place.

Parameters
string$itemtype
int$itemid
mixed$newvalue
Return values
core\output\inplace_editable