Skip to content

Commit

Permalink
Merge branch 'MDL-64782-master' of git://github.com/rezaies/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
David Monllaó committed Apr 24, 2019
2 parents 439af89 + 55fec31 commit 45c8b22
Show file tree
Hide file tree
Showing 11 changed files with 199 additions and 287 deletions.
21 changes: 4 additions & 17 deletions admin/tool/monitor/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,29 +114,16 @@ public static function get_contexts_for_userid(int $userid) : contextlist {
public static function get_users_in_context(userlist $userlist) {
$context = $userlist->get_context();

if (!is_a($context, \context_user::class)) {
if (!$context instanceof \context_user) {
return;
}

$params = [
'contextid' => $context->id,
'contextuser' => CONTEXT_USER,
];

$sql = "SELECT mr.userid
FROM {context} ctx
JOIN {tool_monitor_rules} mr ON ctx.instanceid = mr.userid
AND ctx.contextlevel = :contextuser
WHERE ctx.id = :contextid";
$params = ['userid' => $context->instanceid];

$sql = "SELECT userid FROM {tool_monitor_rules} WHERE userid = :userid";
$userlist->add_from_sql('userid', $sql, $params);

$sql = "SELECT ms.userid
FROM {context} ctx
LEFT JOIN {tool_monitor_subscriptions} ms ON ctx.instanceid = ms.userid
AND ctx.contextlevel = :contextuser
WHERE ctx.id = :contextid";

$sql = "SELECT userid FROM {tool_monitor_subscriptions} WHERE userid = :userid";
$userlist->add_from_sql('userid', $sql, $params);
}

Expand Down
24 changes: 5 additions & 19 deletions backup/util/ui/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,18 +142,11 @@ public static function get_users_in_context(userlist $userlist) {
$context = $userlist->get_context();

if ($context instanceof \context_course) {
$params = [
'contextcourse' => CONTEXT_COURSE,
'contextid' => $context->id,

];
$params = ['courseid' => $context->instanceid];

$sql = "SELECT bc.userid
FROM {backup_controllers} bc
JOIN {context} ctx
ON ctx.instanceid = bc.itemid
AND ctx.contextlevel = :contextcourse
WHERE ctx.id = :contextid
WHERE bc.itemid = :courseid
AND bc.type = :typecourse";

$courseparams = ['typecourse' => 'course'] + $params;
Expand All @@ -164,10 +157,7 @@ public static function get_users_in_context(userlist $userlist) {
FROM {backup_controllers} bc
JOIN {course_sections} c
ON bc.itemid = c.id
JOIN {context} ctx
ON ctx.instanceid = c.course
AND ctx.contextlevel = :contextcourse
WHERE ctx.id = :contextid
WHERE c.course = :courseid
AND bc.type = :typesection";

$sectionparams = ['typesection' => 'section'] + $params;
Expand All @@ -177,17 +167,13 @@ public static function get_users_in_context(userlist $userlist) {

if ($context instanceof \context_module) {
$params = [
'contextmodule' => CONTEXT_MODULE,
'contextid' => $context->id,
'cmid' => $context->instanceid,
'typeactivity' => 'activity'
];

$sql = "SELECT bc.userid
FROM {backup_controllers} bc
JOIN {context} ctx
ON ctx.instanceid = bc.itemid
AND ctx.contextlevel = :contextmodule
WHERE ctx.id = :contextid
WHERE bc.itemid = :cmid
AND bc.type = :typeactivity";

$userlist->add_from_sql('userid', $sql, $params);
Expand Down
23 changes: 12 additions & 11 deletions badges/classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,20 +197,21 @@ public static function get_users_in_context(userlist $userlist) {

if ($context->contextlevel == CONTEXT_COURSE || $context->contextlevel == CONTEXT_SYSTEM) {
// Find the modifications we made on badges (course & system).
$params = [
'courselevel' => CONTEXT_COURSE,
'syscontextid' => SYSCONTEXTID,
'typecourse' => BADGE_TYPE_COURSE,
'typesite' => BADGE_TYPE_SITE,
'contextid' => $context->id,
];
if ($context->contextlevel == CONTEXT_COURSE) {
$extrawhere = 'AND b.courseid = :courseid';
$params = [
'badgetype' => BADGE_TYPE_COURSE,
'courseid' => $context->instanceid
];
} else {
$extrawhere = '';
$params = ['badgetype' => BADGE_TYPE_SITE];
}

$sql = "SELECT b.usermodified, b.usercreated
FROM {badge} b
JOIN {context} ctx
ON (b.type = :typecourse AND b.courseid = ctx.instanceid AND ctx.contextlevel = :courselevel)
OR (b.type = :typesite AND ctx.id = :syscontextid)
WHERE ctx.id = :contextid";
WHERE b.type = :badgetype
$extrawhere";

$userlist->add_from_sql('usermodified', $sql, $params);
$userlist->add_from_sql('usercreated', $sql, $params);
Expand Down
Loading

0 comments on commit 45c8b22

Please sign in to comment.