Skip to content
Permalink
Browse files
Merge branch 'MDL-64782-master' of git://github.com/rezaies/moodle
  • Loading branch information
David Monllaó committed Apr 24, 2019
2 parents 439af89 + 55fec31 commit 45c8b226be6d0095888e88c3c4dba015c124f4d4
@@ -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);
}

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

0 comments on commit 45c8b22

Please sign in to comment.