class cohort_support

internal  
 

Utility functions for Moodle cohorts.

Methods

static array
get_cohorts(int $contextid, int $page = 0, int $perpage = 25, string $search = '')

Retrieves cohorts for a given context with pagination and optional search.

static array
get_cohorts_with_total(int $contextid, int $page = 0, int $perpage = 25, string $search = '')

Retrieves cohorts with normalization and total count.

static array
get_all()

Retrieves all visible cohorts as an options list [id => name].

static void
create_cohort(string $name, string $idnumber)

Creates a new cohort if a cohort with the given idnumber does not exist.

Details

at line 48
static array get_cohorts(int $contextid, int $page = 0, int $perpage = 25, string $search = '')

Retrieves cohorts for a given context with pagination and optional search.

Parameters

int $contextid

Context ID

int $page

page number (0-based)

int $perpage

items per page

string $search

optional search term

Return Value

array

list of cohort objects (as returned by cohort_get_cohorts)

at line 66
static array get_cohorts_with_total(int $contextid, int $page = 0, int $perpage = 25, string $search = '')

Retrieves cohorts with normalization and total count.

Some Moodle versions return an associative array with keys like 'cohorts' and 'totalcohorts'. This method abstracts that variation and always returns a normalized structure.

Parameters

int $contextid

Context ID

int $page

page number (0-based)

int $perpage

items per page

string $search

optional search term

Return Value

array

at line 103
static array get_all()

Retrieves all visible cohorts as an options list [id => name].

Return Value

array

Map of cohort ID to cohort name

at line 127
static void create_cohort(string $name, string $idnumber)

Creates a new cohort if a cohort with the given idnumber does not exist.

Parameters

string $name

The name of the cohort to create

string $idnumber

The unique identifier for the cohort

Return Value

void