weekly release 3.5dev
[moodle.git] / cohort / lib.php
CommitLineData
b980c56e 1<?php
b980c56e
PS
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * Cohort related management functions, this file needs to be included manually.
19 *
607fdf63 20 * @package core_cohort
707f4136 21 * @copyright 2010 Petr Skoda {@link http://skodak.org}
b980c56e
PS
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
607fdf63 25defined('MOODLE_INTERNAL') || die();
b980c56e 26
80f98467
MG
27define('COHORT_ALL', 0);
28define('COHORT_COUNT_MEMBERS', 1);
29define('COHORT_COUNT_ENROLLED_MEMBERS', 3);
30define('COHORT_WITH_MEMBERS_ONLY', 5);
31define('COHORT_WITH_ENROLLED_MEMBERS_ONLY', 17);
32define('COHORT_WITH_NOTENROLLED_MEMBERS_ONLY', 23);
33
b980c56e
PS
34/**
35 * Add new cohort.
df997f84 36 *
6eb8bf7f
PS
37 * @param stdClass $cohort
38 * @return int new cohort id
b980c56e 39 */
df997f84 40function cohort_add_cohort($cohort) {
b980c56e 41 global $DB;
df997f84
PS
42
43 if (!isset($cohort->name)) {
13f66945 44 throw new coding_exception('Missing cohort name in cohort_add_cohort().');
df997f84
PS
45 }
46 if (!isset($cohort->idnumber)) {
47 $cohort->idnumber = NULL;
48 }
49 if (!isset($cohort->description)) {
88a119bb 50 $cohort->description = '';
df997f84
PS
51 }
52 if (!isset($cohort->descriptionformat)) {
53 $cohort->descriptionformat = FORMAT_HTML;
54 }
80f98467
MG
55 if (!isset($cohort->visible)) {
56 $cohort->visible = 1;
57 }
df997f84
PS
58 if (empty($cohort->component)) {
59 $cohort->component = '';
60 }
61 if (!isset($cohort->timecreated)) {
62 $cohort->timecreated = time();
63 }
64 if (!isset($cohort->timemodified)) {
65 $cohort->timemodified = $cohort->timecreated;
66 }
67
68 $cohort->id = $DB->insert_record('cohort', $cohort);
69
04aee04a
DP
70 $event = \core\event\cohort_created::create(array(
71 'context' => context::instance_by_id($cohort->contextid),
72 'objectid' => $cohort->id,
73 ));
74 $event->add_record_snapshot('cohort', $cohort);
75 $event->trigger();
df997f84
PS
76
77 return $cohort->id;
b980c56e
PS
78}
79
80/**
81 * Update existing cohort.
6eb8bf7f 82 * @param stdClass $cohort
b980c56e
PS
83 * @return void
84 */
df997f84 85function cohort_update_cohort($cohort) {
b980c56e 86 global $DB;
081003b6
PS
87 if (property_exists($cohort, 'component') and empty($cohort->component)) {
88 // prevent NULLs
89 $cohort->component = '';
df997f84
PS
90 }
91 $cohort->timemodified = time();
92 $DB->update_record('cohort', $cohort);
93
04aee04a
DP
94 $event = \core\event\cohort_updated::create(array(
95 'context' => context::instance_by_id($cohort->contextid),
96 'objectid' => $cohort->id,
97 ));
98 $event->trigger();
b980c56e
PS
99}
100
101/**
102 * Delete cohort.
6eb8bf7f 103 * @param stdClass $cohort
b980c56e
PS
104 * @return void
105 */
106function cohort_delete_cohort($cohort) {
107 global $DB;
108
109 if ($cohort->component) {
110 // TODO: add component delete callback
111 }
112
113 $DB->delete_records('cohort_members', array('cohortid'=>$cohort->id));
114 $DB->delete_records('cohort', array('id'=>$cohort->id));
df997f84 115
02113beb
MN
116 // Notify the competency subsystem.
117 \core_competency\api::hook_cohort_deleted($cohort);
118
04aee04a
DP
119 $event = \core\event\cohort_deleted::create(array(
120 'context' => context::instance_by_id($cohort->contextid),
121 'objectid' => $cohort->id,
122 ));
123 $event->add_record_snapshot('cohort', $cohort);
124 $event->trigger();
b980c56e
PS
125}
126
e60ff536
PS
127/**
128 * Somehow deal with cohorts when deleting course category,
129 * we can not just delete them because they might be used in enrol
130 * plugins or referenced in external systems.
b33389d2 131 * @param stdClass|coursecat $category
e60ff536
PS
132 * @return void
133 */
134function cohort_delete_category($category) {
135 global $DB;
136 // TODO: make sure that cohorts are really, really not used anywhere and delete, for now just move to parent or system context
137
abdf2b67 138 $oldcontext = context_coursecat::instance($category->id);
e60ff536
PS
139
140 if ($category->parent and $parent = $DB->get_record('course_categories', array('id'=>$category->parent))) {
abdf2b67 141 $parentcontext = context_coursecat::instance($parent->id);
e60ff536
PS
142 $sql = "UPDATE {cohort} SET contextid = :newcontext WHERE contextid = :oldcontext";
143 $params = array('oldcontext'=>$oldcontext->id, 'newcontext'=>$parentcontext->id);
144 } else {
6ca657a7 145 $syscontext = context_system::instance();
e60ff536
PS
146 $sql = "UPDATE {cohort} SET contextid = :newcontext WHERE contextid = :oldcontext";
147 $params = array('oldcontext'=>$oldcontext->id, 'newcontext'=>$syscontext->id);
148 }
149
150 $DB->execute($sql, $params);
151}
152
b980c56e 153/**
e0db105b 154 * Add cohort member
b980c56e
PS
155 * @param int $cohortid
156 * @param int $userid
157 * @return void
158 */
159function cohort_add_member($cohortid, $userid) {
160 global $DB;
2f8c69e1
PS
161 if ($DB->record_exists('cohort_members', array('cohortid'=>$cohortid, 'userid'=>$userid))) {
162 // No duplicates!
163 return;
164 }
fbaea88f 165 $record = new stdClass();
b980c56e
PS
166 $record->cohortid = $cohortid;
167 $record->userid = $userid;
168 $record->timeadded = time();
169 $DB->insert_record('cohort_members', $record);
df997f84 170
04aee04a
DP
171 $cohort = $DB->get_record('cohort', array('id' => $cohortid), '*', MUST_EXIST);
172
173 $event = \core\event\cohort_member_added::create(array(
174 'context' => context::instance_by_id($cohort->contextid),
175 'objectid' => $cohortid,
176 'relateduserid' => $userid,
177 ));
178 $event->add_record_snapshot('cohort', $cohort);
179 $event->trigger();
b980c56e
PS
180}
181
182/**
e0db105b 183 * Remove cohort member
b980c56e
PS
184 * @param int $cohortid
185 * @param int $userid
186 * @return void
187 */
188function cohort_remove_member($cohortid, $userid) {
189 global $DB;
190 $DB->delete_records('cohort_members', array('cohortid'=>$cohortid, 'userid'=>$userid));
df997f84 191
04aee04a
DP
192 $cohort = $DB->get_record('cohort', array('id' => $cohortid), '*', MUST_EXIST);
193
194 $event = \core\event\cohort_member_removed::create(array(
195 'context' => context::instance_by_id($cohort->contextid),
196 'objectid' => $cohortid,
197 'relateduserid' => $userid,
198 ));
199 $event->add_record_snapshot('cohort', $cohort);
200 $event->trigger();
b980c56e
PS
201}
202
dd6b1f15
PS
203/**
204 * Is this user a cohort member?
205 * @param int $cohortid
206 * @param int $userid
207 * @return bool
208 */
209function cohort_is_member($cohortid, $userid) {
210 global $DB;
211
212 return $DB->record_exists('cohort_members', array('cohortid'=>$cohortid, 'userid'=>$userid));
213}
214
92343cd2 215/**
80f98467 216 * Returns the list of cohorts visible to the current user in the given course.
92343cd2 217 *
80f98467
MG
218 * The following fields are returned in each record: id, name, contextid, idnumber, visible
219 * Fields memberscnt and enrolledcnt will be also returned if requested
a09ae434 220 *
80f98467
MG
221 * @param context $currentcontext
222 * @param int $withmembers one of the COHORT_XXX constants that allows to return non empty cohorts only
223 * or cohorts with enroled/not enroled users, or just return members count
224 * @param int $offset
225 * @param int $limit
226 * @param string $search
227 * @return array
92343cd2 228 */
80f98467 229function cohort_get_available_cohorts($currentcontext, $withmembers = 0, $offset = 0, $limit = 25, $search = '') {
a09ae434 230 global $DB;
92343cd2 231
80f98467 232 $params = array();
a09ae434 233
80f98467
MG
234 // Build context subquery. Find the list of parent context where user is able to see any or visible-only cohorts.
235 // Since this method is normally called for the current course all parent contexts are already preloaded.
236 $contextsany = array_filter($currentcontext->get_parent_context_ids(),
484b43f4
MG
237 function($a) {
238 return has_capability("moodle/cohort:view", context::instance_by_id($a));
239 });
80f98467
MG
240 $contextsvisible = array_diff($currentcontext->get_parent_context_ids(), $contextsany);
241 if (empty($contextsany) && empty($contextsvisible)) {
242 // User does not have any permissions to view cohorts.
243 return array();
244 }
245 $subqueries = array();
246 if (!empty($contextsany)) {
247 list($parentsql, $params1) = $DB->get_in_or_equal($contextsany, SQL_PARAMS_NAMED, 'ctxa');
248 $subqueries[] = 'c.contextid ' . $parentsql;
249 $params = array_merge($params, $params1);
250 }
251 if (!empty($contextsvisible)) {
252 list($parentsql, $params1) = $DB->get_in_or_equal($contextsvisible, SQL_PARAMS_NAMED, 'ctxv');
253 $subqueries[] = '(c.visible = 1 AND c.contextid ' . $parentsql. ')';
254 $params = array_merge($params, $params1);
255 }
256 $wheresql = '(' . implode(' OR ', $subqueries) . ')';
257
258 // Build the rest of the query.
259 $fromsql = "";
260 $fieldssql = 'c.id, c.name, c.contextid, c.idnumber, c.visible';
261 $groupbysql = '';
262 $havingsql = '';
263 if ($withmembers) {
de66ddea
AG
264 $fieldssql .= ', s.memberscnt';
265 $subfields = "c.id, COUNT(DISTINCT cm.userid) AS memberscnt";
266 $groupbysql = " GROUP BY c.id";
80f98467 267 $fromsql = " LEFT JOIN {cohort_members} cm ON cm.cohortid = c.id ";
80f98467
MG
268 if (in_array($withmembers,
269 array(COHORT_COUNT_ENROLLED_MEMBERS, COHORT_WITH_ENROLLED_MEMBERS_ONLY, COHORT_WITH_NOTENROLLED_MEMBERS_ONLY))) {
270 list($esql, $params2) = get_enrolled_sql($currentcontext);
271 $fromsql .= " LEFT JOIN ($esql) u ON u.id = cm.userid ";
272 $params = array_merge($params2, $params);
de66ddea
AG
273 $fieldssql .= ', s.enrolledcnt';
274 $subfields .= ', COUNT(DISTINCT u.id) AS enrolledcnt';
80f98467
MG
275 }
276 if ($withmembers == COHORT_WITH_MEMBERS_ONLY) {
277 $havingsql = " HAVING COUNT(DISTINCT cm.userid) > 0";
278 } else if ($withmembers == COHORT_WITH_ENROLLED_MEMBERS_ONLY) {
279 $havingsql = " HAVING COUNT(DISTINCT u.id) > 0";
280 } else if ($withmembers == COHORT_WITH_NOTENROLLED_MEMBERS_ONLY) {
281 $havingsql = " HAVING COUNT(DISTINCT cm.userid) > COUNT(DISTINCT u.id)";
282 }
283 }
284 if ($search) {
285 list($searchsql, $searchparams) = cohort_get_search_query($search);
286 $wheresql .= ' AND ' . $searchsql;
287 $params = array_merge($params, $searchparams);
a09ae434 288 }
92343cd2 289
de66ddea
AG
290 if ($withmembers) {
291 $sql = "SELECT " . str_replace('c.', 'cohort.', $fieldssql) . "
292 FROM {cohort} cohort
293 JOIN (SELECT $subfields
294 FROM {cohort} c $fromsql
295 WHERE $wheresql $groupbysql $havingsql
296 ) s ON cohort.id = s.id
297 ORDER BY cohort.name, cohort.idnumber";
298 } else {
299 $sql = "SELECT $fieldssql
300 FROM {cohort} c $fromsql
301 WHERE $wheresql
302 ORDER BY c.name, c.idnumber";
303 }
92343cd2 304
80f98467
MG
305 return $DB->get_records_sql($sql, $params, $offset, $limit);
306}
307
308/**
309 * Check if cohort exists and user is allowed to access it from the given context.
310 *
311 * @param stdClass|int $cohortorid cohort object or id
312 * @param context $currentcontext current context (course) where visibility is checked
313 * @return boolean
314 */
315function cohort_can_view_cohort($cohortorid, $currentcontext) {
316 global $DB;
317 if (is_numeric($cohortorid)) {
318 $cohort = $DB->get_record('cohort', array('id' => $cohortorid), 'id, contextid, visible');
319 } else {
320 $cohort = $cohortorid;
321 }
92343cd2 322
80f98467
MG
323 if ($cohort && in_array($cohort->contextid, $currentcontext->get_parent_context_ids())) {
324 if ($cohort->visible) {
325 return true;
326 }
327 $cohortcontext = context::instance_by_id($cohort->contextid);
328 if (has_capability('moodle/cohort:view', $cohortcontext)) {
329 return true;
92343cd2
PS
330 }
331 }
80f98467 332 return false;
92343cd2
PS
333}
334
a60e8ba5
DW
335/**
336 * Get a cohort by id. Also does a visibility check and returns false if the user cannot see this cohort.
337 *
338 * @param stdClass|int $cohortorid cohort object or id
339 * @param context $currentcontext current context (course) where visibility is checked
340 * @return stdClass|boolean
341 */
342function cohort_get_cohort($cohortorid, $currentcontext) {
343 global $DB;
344 if (is_numeric($cohortorid)) {
345 $cohort = $DB->get_record('cohort', array('id' => $cohortorid), 'id, contextid, visible');
346 } else {
347 $cohort = $cohortorid;
348 }
349
350 if ($cohort && in_array($cohort->contextid, $currentcontext->get_parent_context_ids())) {
351 if ($cohort->visible) {
352 return $cohort;
353 }
354 $cohortcontext = context::instance_by_id($cohort->contextid);
355 if (has_capability('moodle/cohort:view', $cohortcontext)) {
356 return $cohort;
357 }
358 }
359 return false;
360}
361
274dc068
MG
362/**
363 * Produces a part of SQL query to filter cohorts by the search string
364 *
80f98467 365 * Called from {@link cohort_get_cohorts()}, {@link cohort_get_all_cohorts()} and {@link cohort_get_available_cohorts()}
274dc068
MG
366 *
367 * @access private
368 *
80f98467
MG
369 * @param string $search search string
370 * @param string $tablealias alias of cohort table in the SQL query (highly recommended if other tables are used in query)
371 * @return array of two elements - SQL condition and array of named parameters
274dc068 372 */
80f98467 373function cohort_get_search_query($search, $tablealias = '') {
274dc068
MG
374 global $DB;
375 $params = array();
376 if (empty($search)) {
377 // This function should not be called if there is no search string, just in case return dummy query.
378 return array('1=1', $params);
379 }
80f98467
MG
380 if ($tablealias && substr($tablealias, -1) !== '.') {
381 $tablealias .= '.';
382 }
274dc068
MG
383 $searchparam = '%' . $DB->sql_like_escape($search) . '%';
384 $conditions = array();
385 $fields = array('name', 'idnumber', 'description');
80f98467 386 $cnt = 0;
274dc068 387 foreach ($fields as $field) {
80f98467
MG
388 $conditions[] = $DB->sql_like($tablealias . $field, ':csearch' . $cnt, false);
389 $params['csearch' . $cnt] = $searchparam;
390 $cnt++;
274dc068
MG
391 }
392 $sql = '(' . implode(' OR ', $conditions) . ')';
393 return array($sql, $params);
394}
395
543009cb 396/**
aad6e655 397 * Get all the cohorts defined in given context.
543009cb 398 *
274dc068
MG
399 * The function does not check user capability to view/manage cohorts in the given context
400 * assuming that it has been already verified.
401 *
543009cb
RK
402 * @param int $contextid
403 * @param int $page number of the current page
404 * @param int $perpage items per page
405 * @param string $search search string
9a2f6770 406 * @return array Array(totalcohorts => int, cohorts => array, allcohorts => int)
543009cb
RK
407 */
408function cohort_get_cohorts($contextid, $page = 0, $perpage = 25, $search = '') {
409 global $DB;
410
274dc068
MG
411 $fields = "SELECT *";
412 $countfields = "SELECT COUNT(1)";
413 $sql = " FROM {cohort}
80f98467
MG
414 WHERE contextid = :contextid";
415 $params = array('contextid' => $contextid);
274dc068 416 $order = " ORDER BY name ASC, idnumber ASC";
543009cb
RK
417
418 if (!empty($search)) {
274dc068
MG
419 list($searchcondition, $searchparams) = cohort_get_search_query($search);
420 $sql .= ' AND ' . $searchcondition;
421 $params = array_merge($params, $searchparams);
543009cb 422 }
543009cb 423
274dc068
MG
424 $totalcohorts = $allcohorts = $DB->count_records('cohort', array('contextid' => $contextid));
425 if (!empty($search)) {
426 $totalcohorts = $DB->count_records_sql($countfields . $sql, $params);
427 }
543009cb
RK
428 $cohorts = $DB->get_records_sql($fields . $sql . $order, $params, $page*$perpage, $perpage);
429
274dc068 430 return array('totalcohorts' => $totalcohorts, 'cohorts' => $cohorts, 'allcohorts' => $allcohorts);
543009cb 431}
274dc068
MG
432
433/**
434 * Get all the cohorts defined anywhere in system.
435 *
436 * The function assumes that user capability to view/manage cohorts on system level
437 * has already been verified. This function only checks if such capabilities have been
438 * revoked in child (categories) contexts.
439 *
440 * @param int $page number of the current page
441 * @param int $perpage items per page
442 * @param string $search search string
443 * @return array Array(totalcohorts => int, cohorts => array, allcohorts => int)
444 */
445function cohort_get_all_cohorts($page = 0, $perpage = 25, $search = '') {
446 global $DB;
447
448 $fields = "SELECT c.*, ".context_helper::get_preload_record_columns_sql('ctx');
449 $countfields = "SELECT COUNT(*)";
450 $sql = " FROM {cohort} c
451 JOIN {context} ctx ON ctx.id = c.contextid ";
452 $params = array();
453 $wheresql = '';
454
455 if ($excludedcontexts = cohort_get_invisible_contexts()) {
80f98467 456 list($excludedsql, $excludedparams) = $DB->get_in_or_equal($excludedcontexts, SQL_PARAMS_NAMED, 'excl', false);
274dc068
MG
457 $wheresql = ' WHERE c.contextid '.$excludedsql;
458 $params = array_merge($params, $excludedparams);
459 }
460
461 $totalcohorts = $allcohorts = $DB->count_records_sql($countfields . $sql . $wheresql, $params);
462
463 if (!empty($search)) {
80f98467 464 list($searchcondition, $searchparams) = cohort_get_search_query($search, 'c');
274dc068
MG
465 $wheresql .= ($wheresql ? ' AND ' : ' WHERE ') . $searchcondition;
466 $params = array_merge($params, $searchparams);
467 $totalcohorts = $DB->count_records_sql($countfields . $sql . $wheresql, $params);
468 }
469
470 $order = " ORDER BY c.name ASC, c.idnumber ASC";
471 $cohorts = $DB->get_records_sql($fields . $sql . $wheresql . $order, $params, $page*$perpage, $perpage);
472
473 // Preload used contexts, they will be used to check view/manage/assign capabilities and display categories names.
474 foreach (array_keys($cohorts) as $key) {
475 context_helper::preload_from_record($cohorts[$key]);
476 }
477
478 return array('totalcohorts' => $totalcohorts, 'cohorts' => $cohorts, 'allcohorts' => $allcohorts);
479}
480
481/**
482 * Returns list of contexts where cohorts are present but current user does not have capability to view/manage them.
483 *
484 * This function is called from {@link cohort_get_all_cohorts()} to ensure correct pagination in rare cases when user
485 * is revoked capability in child contexts. It assumes that user's capability to view/manage cohorts on system
486 * level has already been verified.
487 *
488 * @access private
489 *
490 * @return array array of context ids
491 */
492function cohort_get_invisible_contexts() {
493 global $DB;
494 if (is_siteadmin()) {
495 // Shortcut, admin can do anything and can not be prohibited from any context.
496 return array();
497 }
498 $records = $DB->get_recordset_sql("SELECT DISTINCT ctx.id, ".context_helper::get_preload_record_columns_sql('ctx')." ".
499 "FROM {context} ctx JOIN {cohort} c ON ctx.id = c.contextid ");
500 $excludedcontexts = array();
501 foreach ($records as $ctx) {
502 context_helper::preload_from_record($ctx);
d406ddca
DM
503 if (context::instance_by_id($ctx->id) == context_system::instance()) {
504 continue; // System context cohorts should be available and permissions already checked.
505 }
274dc068
MG
506 if (!has_any_capability(array('moodle/cohort:manage', 'moodle/cohort:view'), context::instance_by_id($ctx->id))) {
507 $excludedcontexts[] = $ctx->id;
508 }
509 }
a938e409 510 $records->close();
274dc068
MG
511 return $excludedcontexts;
512}
513
514/**
515 * Returns navigation controls (tabtree) to be displayed on cohort management pages
516 *
517 * @param context $context system or category context where cohorts controls are about to be displayed
518 * @param moodle_url $currenturl
519 * @return null|renderable
520 */
521function cohort_edit_controls(context $context, moodle_url $currenturl) {
522 $tabs = array();
523 $currenttab = 'view';
524 $viewurl = new moodle_url('/cohort/index.php', array('contextid' => $context->id));
525 if (($searchquery = $currenturl->get_param('search'))) {
526 $viewurl->param('search', $searchquery);
527 }
528 if ($context->contextlevel == CONTEXT_SYSTEM) {
529 $tabs[] = new tabobject('view', new moodle_url($viewurl, array('showall' => 0)), get_string('systemcohorts', 'cohort'));
530 $tabs[] = new tabobject('viewall', new moodle_url($viewurl, array('showall' => 1)), get_string('allcohorts', 'cohort'));
531 if ($currenturl->get_param('showall')) {
532 $currenttab = 'viewall';
533 }
534 } else {
535 $tabs[] = new tabobject('view', $viewurl, get_string('cohorts', 'cohort'));
536 }
537 if (has_capability('moodle/cohort:manage', $context)) {
538 $addurl = new moodle_url('/cohort/edit.php', array('contextid' => $context->id));
539 $tabs[] = new tabobject('addcohort', $addurl, get_string('addcohort', 'cohort'));
540 if ($currenturl->get_path() === $addurl->get_path() && !$currenturl->param('id')) {
541 $currenttab = 'addcohort';
542 }
5076b961
MG
543
544 $uploadurl = new moodle_url('/cohort/upload.php', array('contextid' => $context->id));
545 $tabs[] = new tabobject('uploadcohorts', $uploadurl, get_string('uploadcohorts', 'cohort'));
546 if ($currenturl->get_path() === $uploadurl->get_path()) {
547 $currenttab = 'uploadcohorts';
548 }
274dc068
MG
549 }
550 if (count($tabs) > 1) {
551 return new tabtree($tabs, $currenttab);
552 }
553 return null;
80f98467 554}
48983fb9
MG
555
556/**
557 * Implements callback inplace_editable() allowing to edit values in-place
558 *
559 * @param string $itemtype
560 * @param int $itemid
561 * @param mixed $newvalue
562 * @return \core\output\inplace_editable
563 */
564function core_cohort_inplace_editable($itemtype, $itemid, $newvalue) {
565 if ($itemtype === 'cohortname') {
566 return \core_cohort\output\cohortname::update($itemid, $newvalue);
567 } else if ($itemtype === 'cohortidnumber') {
568 return \core_cohort\output\cohortidnumber::update($itemid, $newvalue);
569 }
570}