mirror of
https://github.com/moodle/moodle.git
synced 2025-04-15 05:25:08 +02:00
MDL-35465 move duplicate check to cohort_add_member()
This commit is contained in:
parent
aad6e655f6
commit
2f8c69e199
@ -1,5 +1,4 @@
|
||||
<?php
|
||||
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
@ -80,10 +79,7 @@ if (optional_param('add', false, PARAM_BOOL) && confirm_sesskey()) {
|
||||
if (!empty($userstoassign)) {
|
||||
|
||||
foreach ($userstoassign as $adduser) {
|
||||
// no duplicates please
|
||||
if (!$DB->record_exists('cohort_members', array('cohortid'=>$cohort->id, 'userid'=>$adduser->id))) {
|
||||
cohort_add_member($cohort->id, $adduser->id);
|
||||
}
|
||||
cohort_add_member($cohort->id, $adduser->id);
|
||||
}
|
||||
|
||||
$potentialuserselector->invalidate_selected_users();
|
||||
|
@ -132,6 +132,10 @@ function cohort_delete_category($category) {
|
||||
*/
|
||||
function cohort_add_member($cohortid, $userid) {
|
||||
global $DB;
|
||||
if ($DB->record_exists('cohort_members', array('cohortid'=>$cohortid, 'userid'=>$userid))) {
|
||||
// No duplicates!
|
||||
return;
|
||||
}
|
||||
$record = new stdClass();
|
||||
$record->cohortid = $cohortid;
|
||||
$record->userid = $userid;
|
||||
|
Loading…
x
Reference in New Issue
Block a user