Skip to content

Commit

Permalink
minor fixes, ready for 4.1
Browse files Browse the repository at this point in the history
  • Loading branch information
Flottertotte committed Dec 22, 2022
1 parent 0e788e7 commit 4952fed
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 43 deletions.
76 changes: 36 additions & 40 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace enrol_waitlist\privacy;

defined('MOODLE_INTERNAL') || die();
Expand All @@ -12,39 +11,36 @@
use core_privacy\local\request\approved_userlist;

class provider implements \core_privacy\local\metadata\provider, \core_privacy\local\request\plugin\provider, \core_privacy\local\request\core_userlist_provider {

public static function get_metadata(collection $collection) : collection {

$collection->add_database_table(
'user_enrol_waitlist',
[
'userid' => 'privacy:metadata:user_enrol_waitlist:userid'
],
'privacy:metadata:user_enrol_waitlist'
);

return $collection;
}

public static function get_contexts_for_userid(int $userid) : contextlist {
$sql = "SELECT c.id
FROM {user_enrol_waitlist} ew
JOIN {context} c ON c.contextlevel = ? AND c.instanceid = ew.id
WHERE ew.userid = ?";
$params = [CONTEXT_COURSE, $userid];

$contextlist = new contextlist();
$contextlist->set_component('enrol_waitlists');
return $contextlist->add_from_sql($sql, $params);
}

public static function get_users_in_context(userlist $userlist) {
$context = $userlist->get_context();

if (!$context instanceof \context_course) {
return;
}

// Values of ep.receiver_email and ep.business are already normalised to lowercase characters by PayPal,
// therefore there is no need to use LOWER() on them in the following query.
$sql = "SELECT u.id
Expand All @@ -53,95 +49,95 @@ public static function get_users_in_context(userlist $userlist) {
JOIN {user} u ON ew.userid = u.id
WHERE e.courseid = :courseid";
$params = ['courseid' => $context->instanceid];

$userlist->add_from_sql('id', $sql, $params);
}

public static function export_user_data(approved_contextlist $contextlist) {

global $DB;

if (empty($contextlist->count())) {
return;
}

$user = $contextlist->get_user();

list($contextsql, $contextparams) = $DB->get_in_or_equal($contextlist->get_contextids(), SQL_PARAMS_NAMED);

$sql = "SELECT ew.*
FROM {user_enrol_waitlist} ew
JOIN {enrol} e ON ew.instanceid = e.id
JOIN {context} ctx ON e.courseid = ctx.instanceid AND ctx.contextlevel = :contextcourse
JOIN {user} u ON u.id = ep.userid
WHERE ctx.id {$contextsql} AND u.id = :userid
ORDER BY e.courseid";

$params = [
'contextcourse' => CONTEXT_COURSE,
'userid' => $user->id,
'emailuserid' => $user->id,
];
$params += $contextparams;
}

public static function delete_data_for_all_users_in_context(\context $context) {

global $DB;

if (!$context instanceof \context_course) {
return;
}

$DB->delete_records('enrol_waitlist', array('instanceid' => $context->instanceid));

}

public static function delete_data_for_user(approved_contextlist $contextlist) {

global $DB;

if (empty($contextlist->count())) {
return;
}

$user = $contextlist->get_user();

$contexts = $contextlist->get_contexts();
$courseids = [];

foreach ($contexts as $context) {
if ($context instanceof \context_course) {
$courseids[] = $context->instanceid;
}
}

list($insql, $inparams) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED);

$select = "userid = :userid AND instanceid $insql";
$params = $inparams + ['userid' => $user->id];
$DB->delete_records_select('enrol_waitlist', $select, $params);

}

public static function delete_data_for_users(approved_userlist $userlist) {

global $DB;

$context = $userlist->get_context();

if ($context->contextlevel != CONTEXT_COURSE) {
return;
}

$userids = $userlist->get_userids();

list($usersql, $userparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);

$params = ['instanceid' => $context->instanceid] + $userparams;

$select = "instanceid = :instanceid AND userid $usersql";
$DB->delete_records_select('enrol_waitlist', $select, $params);

}
}
1 change: 0 additions & 1 deletion library.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ class course_enrolment_manager {
/**#@+
* These variables are used to cache the information this class uses
* please never use these directly instead use their get_ counterparts.
* @access private
* @var array
*/
private $_instancessql = null;
Expand Down
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
*/
defined('MOODLE_INTERNAL') || die();

$plugin->version = 2022032500; // The current module version (Date: YYYYMMDDXX)
$plugin->version = 2022122000; // The current module version (Date: YYYYMMDDXX)
$plugin->requires = 2011033005; // Requires at least this Moodle version
$plugin->maturity = MATURITY_STABLE;
$plugin->release = 'Course Enrol Waitlist Plugin Version 3.9-b';
$plugin->release = 'Course Enrol Waitlist Plugin Version 4.1-a';
$plugin->component = 'enrol_waitlist'; // Full name of the plugin (used for diagnostics)
$plugin->cron = 180;

0 comments on commit 4952fed

Please sign in to comment.