Moodle APIs 3.9
Moodle 3.9.13+ (Build: 20220325)
Files | Namespaces | Classes | Functions | Variables
core_cohort

Files

file  behat_cohort.php
 Cohorts steps definitions.
 
file  cohort_summary_exporter.php
 Class for exporting a cohort summary from an stdClass.
 
file  cohortidnumber.php
 Contains class core_cohort::output::cohortidnumber.
 
file  cohortname.php
 Contains class core_cohort::output::cohortname.
 
file  edit_form.php
 Cohort related management functions, this file needs to be included manually.
 
file  externallib.php
 External cohort API.
 
file  upload_form.php
 A form for cohort upload.
 

Namespaces

namespace  core_cohort\external
  
 
namespace  core_cohort\output
  
 
namespace  core_cohort\privacy
  
 

Classes

class  behat_cohort
 
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\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_external
 

Functions

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

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 = '' 
)

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
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 = '' 
)

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
Return values
array

◆ cohort_get_cohort()

cohort_get_cohort (   $cohortorid,
  $currentcontext 
)

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
Return values
stdClass|boolean

◆ cohort_get_cohorts()

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

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
Return values
arrayArray(totalcohorts => int, cohorts => array, allcohorts => int)

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

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

Parameters
int$userid
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