MDL-35465 move duplicate check to cohort_add_member()

This commit is contained in:
Petr Škoda 2012-09-16 21:32:27 +02:00
parent aad6e655f6
commit 2f8c69e199
2 changed files with 5 additions and 5 deletions

View File

@ -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();

View File

@ -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;