Skip to content

Commit

Permalink
MDL-63764 core_competency: Support bulk user delete course competencies
Browse files Browse the repository at this point in the history
This issue is a part of the MDL-62560 Epic.
Also made user IDs optional, so user course competencies can be deleted by course ID only.
  • Loading branch information
mickhawkins committed Oct 29, 2018
1 parent daf0b4f commit b03e932
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions competency/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -478,8 +478,7 @@ public static function delete_data_for_all_users_in_context(context $context) {
break;

case CONTEXT_COURSE:
$courseid = $context->instanceid;
$DB->delete_records(user_competency_course::TABLE, ['courseid' => $courseid]);
static::delete_user_competencies_in_course($context->instanceid);
break;
}
}
Expand Down Expand Up @@ -511,7 +510,7 @@ public static function delete_data_for_user(approved_contextlist $contextlist) {
break;

case CONTEXT_COURSE:
static::delete_user_competencies_in_course($userid, $context->instanceid);
static::delete_user_competencies_in_course($context->instanceid, [$userid]);
break;
}
}
Expand Down Expand Up @@ -602,15 +601,26 @@ protected static function delete_user_competencies($userid) {
}

/**
* Delete the record of competencies for a user in a course.
* Delete the record of competencies for user(s) in a course.
*
* @param int $userid The user ID.
* @param int $courseid The course ID.
* @param int[] $userids The user IDs, if deleting for specific user(s).
* @return void
*/
protected static function delete_user_competencies_in_course($userid, $courseid) {
protected static function delete_user_competencies_in_course($courseid, $userids = []) {
global $DB;
$DB->delete_records(user_competency_course::TABLE, ['userid' => $userid, 'courseid' => $courseid]);

$params = ['courseid' => $courseid];
$where = "courseid = :courseid";

if (!empty($userids)) {
list($insql, $inparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
$params = $params + $inparams;

$where .= " AND userid {$insql}";
}

$DB->delete_records_select(user_competency_course::TABLE, $where, $params);
}

/**
Expand Down

0 comments on commit b03e932

Please sign in to comment.