From 887644a1d5c5e9ea749fb0e8a1d5f51417190410 Mon Sep 17 00:00:00 2001 From: cescobedo Date: Wed, 20 May 2020 18:50:21 +0200 Subject: [PATCH] MDL-68451 mod_h5pactivity: Add info attempts in check_updates_since Add updates information related to attempts in check_updates_since because they may affect the user or the information displayed in the app. --- mod/h5pactivity/lib.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/mod/h5pactivity/lib.php b/mod/h5pactivity/lib.php index b3cb285dc37..36d051528df 100644 --- a/mod/h5pactivity/lib.php +++ b/mod/h5pactivity/lib.php @@ -334,7 +334,41 @@ function h5pactivity_page_type_list(string $pagetype, stdClass $parentcontext, s * @return stdClass an object with the different type of areas indicating if they were updated or not */ function h5pactivity_check_updates_since(cm_info $cm, int $from, array $filter = []): stdClass { + global $DB, $USER; + $updates = course_check_module_updates_since($cm, $from, ['package'], $filter); + + $updates->tracks = (object) ['updated' => false]; + $select = 'h5pactivityid = ? AND userid = ? AND timemodified > ?'; + $params = [$cm->instance, $USER->id, $from]; + $tracks = $DB->get_records_select('h5pactivity_attempts', $select, $params, '', 'id'); + if (!empty($tracks)) { + $updates->tracks->updated = true; + $updates->tracks->itemids = array_keys($tracks); + } + + // Now, teachers should see other students updates. + if (has_capability('mod/h5pactivity:reviewattempts', $cm->context)) { + $select = 'h5pactivityid = ? AND timemodified > ?'; + $params = [$cm->instance, $from]; + + if (groups_get_activity_groupmode($cm) == SEPARATEGROUPS) { + $groupusers = array_keys(groups_get_activity_shared_group_members($cm)); + if (empty($groupusers)) { + return $updates; + } + list($insql, $inparams) = $DB->get_in_or_equal($groupusers); + $select .= ' AND userid ' . $insql; + $params = array_merge($params, $inparams); + } + + $updates->usertracks = (object) ['updated' => false]; + $tracks = $DB->get_records_select('h5pactivity_attempts', $select, $params, '', 'id'); + if (!empty($tracks)) { + $updates->usertracks->updated = true; + $updates->usertracks->itemids = array_keys($tracks); + } + } return $updates; }