Skip to content

Commit

Permalink
MDL-35465 move duplicate check to cohort_add_member()
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Sep 16, 2012
1 parent aad6e65 commit 2f8c69e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 1 addition & 5 deletions cohort/assign.php
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -80,10 +79,7 @@
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();
Expand Down
4 changes: 4 additions & 0 deletions cohort/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2f8c69e

Please sign in to comment.