mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 20:42:22 +02:00
MDL-56307 course: Return time updated and times updated
This commit is contained in:
parent
cebce76f61
commit
65b2669d98
@ -3625,14 +3625,19 @@ function course_check_updates($course, $tocheck, $filter = array()) {
|
||||
foreach ($tocheck as $instance) {
|
||||
if ($instance['contextlevel'] == 'module') {
|
||||
// Check module visibility.
|
||||
$modinfoexception = false;
|
||||
try {
|
||||
$cm = $modinfo->get_cm($instance['id']);
|
||||
} catch (Exception $e) {
|
||||
$modinfoexception = true;
|
||||
$warnings[] = array(
|
||||
'item' => 'module',
|
||||
'itemid' => $instance['id'],
|
||||
'warningcode' => 'cmidnotincourse',
|
||||
'message' => 'This module id does not belong to this course.'
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($modinfoexception or !$cm->uservisible) {
|
||||
if (!$cm->uservisible) {
|
||||
$warnings[] = array(
|
||||
'item' => 'module',
|
||||
'itemid' => $instance['id'],
|
||||
@ -3692,7 +3697,10 @@ function course_check_module_updates_since($cm, $from, $fileareas = array(), $fi
|
||||
|
||||
// Check changes in the module configuration.
|
||||
if (isset($mod->timemodified) and (empty($filter) or in_array('configuration', $filter))) {
|
||||
$updates->configuration = $mod->timemodified > $from;
|
||||
$updates->configuration = (object) array('updated' => false);
|
||||
if ($updates->configuration->updated = $mod->timemodified > $from) {
|
||||
$updates->configuration->timeupdated = $mod->timemodified;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for updates in files.
|
||||
@ -3703,50 +3711,53 @@ function course_check_module_updates_since($cm, $from, $fileareas = array(), $fi
|
||||
$fs = get_file_storage();
|
||||
$files = $fs->get_area_files($context->id, $component, $fileareas, false, "filearea, timemodified DESC", true, $from);
|
||||
foreach ($fileareas as $filearea) {
|
||||
$updates->{$filearea . 'files'} = false;
|
||||
$updates->{$filearea . 'files'} = (object) array('updated' => false);
|
||||
}
|
||||
foreach ($files as $file) {
|
||||
$updates->{$file->get_filearea() . 'files'} = true;
|
||||
$updates->{$file->get_filearea() . 'files'}->updated = true;
|
||||
$updates->{$file->get_filearea() . 'files'}->itemids[] = $file->get_id();
|
||||
}
|
||||
}
|
||||
|
||||
// Check completion.
|
||||
$updates->completion = false;
|
||||
$supportcompletion = plugin_supports('mod', $cm->modname, FEATURE_COMPLETION_HAS_RULES);
|
||||
$supportcompletion = $supportcompletion or plugin_supports('mod', $cm->modname, FEATURE_COMPLETION_TRACKS_VIEWS);
|
||||
if ($supportcompletion and (empty($filter) or in_array('completion', $filter))) {
|
||||
$updates->completion = (object) array('updated' => false);
|
||||
$completion = new completion_info($course);
|
||||
// Use wholecourse to cache all the modules the first time.
|
||||
$completiondata = $completion->get_data($cm, true);
|
||||
$updates->completion = !empty($completiondata->timemodified) && $completiondata->timemodified > $from;
|
||||
if ($updates->completion->updated = !empty($completiondata->timemodified) && $completiondata->timemodified > $from) {
|
||||
$updates->completion->timemodified = $completiondata->timemodified;
|
||||
}
|
||||
}
|
||||
|
||||
// Check grades.
|
||||
$updates->gradeitems = false;
|
||||
$updates->outcomes = false;
|
||||
$supportgrades = plugin_supports('mod', $cm->modname, FEATURE_GRADE_HAS_GRADE);
|
||||
$supportgrades = $supportgrades or plugin_supports('mod', $cm->modname, FEATURE_GRADE_OUTCOMES);
|
||||
if ($supportgrades and (empty($filter) or (in_array('gradeitems', $filter) or in_array('outcomes', $filter)))) {
|
||||
require_once($CFG->libdir . '/gradelib.php');
|
||||
$grades = grade_get_grades($course->id, 'mod', $cm->modname, $mod->id, $USER->id);
|
||||
|
||||
|
||||
if (empty($filter) or in_array('gradeitems', $filter)) {
|
||||
$updates->gradeitems = (object) array('updated' => false);
|
||||
foreach ($grades->items as $gradeitem) {
|
||||
foreach ($gradeitem->grades as $grade) {
|
||||
if ($grade->datesubmitted > $from or $grade->dategraded > $from) {
|
||||
$updates->gradeitems = true;
|
||||
break 2;
|
||||
$updates->gradeitems->updated = true;
|
||||
$updates->gradeitems->itemids[] = $gradeitem->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (empty($filter) or in_array('outcomes', $filter)) {
|
||||
$updates->outcomes = (object) array('updated' => false);
|
||||
foreach ($grades->outcomes as $outcome) {
|
||||
foreach ($outcome->grades as $grade) {
|
||||
if ($grade->datesubmitted > $from or $grade->dategraded > $from) {
|
||||
$updates->outcomes = true;
|
||||
break 2;
|
||||
$updates->outcomes->updated = true;
|
||||
$updates->outcomes->itemids[] = $outcome->id;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -3754,19 +3765,27 @@ function course_check_module_updates_since($cm, $from, $fileareas = array(), $fi
|
||||
}
|
||||
|
||||
// Check comments.
|
||||
$updates->comments = false;
|
||||
if (plugin_supports('mod', $cm->modname, FEATURE_COMMENT) and (empty($filter) or in_array('comments', $filter))) {
|
||||
$updates->comments = (object) array('updated' => false);
|
||||
require_once($CFG->dirroot . '/comment/locallib.php');
|
||||
$manager = new comment_manager();
|
||||
$updates->comments = count($manager->get_component_comments_since($course, $cm, $context, $component, $from)) > 0;
|
||||
$comments = $manager->get_component_comments_since($course, $context, $component, $from, $cm);
|
||||
if (!empty($comments)) {
|
||||
$updates->comments->updated = true;
|
||||
$updates->comments->itemids = array_keys($comments);
|
||||
}
|
||||
}
|
||||
|
||||
// Check ratings.
|
||||
$updates->ratings = false;
|
||||
if (plugin_supports('mod', $cm->modname, FEATURE_RATE) and (empty($filter) or in_array('ratings', $filter))) {
|
||||
$updates->ratings = (object) array('updated' => false);
|
||||
require_once($CFG->dirroot . '/rating/lib.php');
|
||||
$manager = new rating_manager();
|
||||
$updates->ratings = count($manager->get_component_ratings_since($course, $cm, $context, $component, $from)) > 0;
|
||||
$ratings = $manager->get_component_ratings_since($context, $component, $from);
|
||||
if (!empty($ratings)) {
|
||||
$updates->ratings->updated = true;
|
||||
$updates->ratings->itemids = array_keys($ratings);
|
||||
}
|
||||
}
|
||||
|
||||
return $updates;
|
||||
|
@ -3333,13 +3333,13 @@ class core_course_courselib_testcase extends advanced_testcase {
|
||||
|
||||
// Check nothing changed right now.
|
||||
$updates = course_check_module_updates_since($cm, $from);
|
||||
$this->assertFalse($updates->configuration);
|
||||
$this->assertFalse($updates->completion);
|
||||
$this->assertFalse($updates->gradeitems);
|
||||
$this->assertFalse($updates->comments);
|
||||
$this->assertFalse($updates->ratings);
|
||||
$this->assertFalse($updates->introfiles);
|
||||
$this->assertFalse($updates->outcomes);
|
||||
$this->assertFalse($updates->configuration->updated);
|
||||
$this->assertFalse($updates->completion->updated);
|
||||
$this->assertFalse($updates->gradeitems->updated);
|
||||
$this->assertFalse($updates->comments->updated);
|
||||
$this->assertFalse($updates->ratings->updated);
|
||||
$this->assertFalse($updates->introfiles->updated);
|
||||
$this->assertFalse($updates->outcomes->updated);
|
||||
|
||||
$this->waitForSecond();
|
||||
|
||||
@ -3377,12 +3377,12 @@ class core_course_courselib_testcase extends advanced_testcase {
|
||||
|
||||
// Check upgrade status.
|
||||
$updates = course_check_module_updates_since($cm, $from);
|
||||
$this->assertTrue($updates->configuration);
|
||||
$this->assertTrue($updates->completion);
|
||||
$this->assertTrue($updates->gradeitems);
|
||||
$this->assertTrue($updates->comments);
|
||||
$this->assertTrue($updates->ratings);
|
||||
$this->assertFalse($updates->introfiles);
|
||||
$this->assertFalse($updates->outcomes);
|
||||
$this->assertTrue($updates->configuration->updated);
|
||||
$this->assertTrue($updates->completion->updated);
|
||||
$this->assertTrue($updates->gradeitems->updated);
|
||||
$this->assertTrue($updates->comments->updated);
|
||||
$this->assertTrue($updates->ratings->updated);
|
||||
$this->assertFalse($updates->introfiles->updated);
|
||||
$this->assertFalse($updates->outcomes->updated);
|
||||
}
|
||||
}
|
||||
|
@ -1537,8 +1537,19 @@ function assign_check_updates_since(cm_info $cm, $from, $filter = array()) {
|
||||
// Check if there is a new submission by the user or new grades.
|
||||
$select = 'assignment = :id AND userid = :userid AND (timecreated > :since1 OR timemodified > :since2)';
|
||||
$params = array('id' => $cm->instance, 'userid' => $USER->id, 'since1' => $from, 'since2' => $from);
|
||||
$updates->submissions = $DB->count_records_select('assign_submission', $select, $params) > 0;
|
||||
$updates->grades = $DB->count_records_select('assign_grades', $select, $params) > 0;
|
||||
$updates->submissions = (object) array('updated' => false);
|
||||
$submissions = $DB->get_records_select('assign_submission', $select, $params, '', 'id');
|
||||
if (!empty($submissions)) {
|
||||
$updates->submissions->updated = true;
|
||||
$updates->submissions->itemids = array_keys($submissions);
|
||||
}
|
||||
|
||||
$updates->grades = (object) array('updated' => false);
|
||||
$grades = $DB->get_records_select('assign_grades', $select, $params, '', 'id');
|
||||
if (!empty($grades)) {
|
||||
$updates->grades->updated = true;
|
||||
$updates->grades->itemids = array_keys($grades);
|
||||
}
|
||||
|
||||
return $updates;
|
||||
}
|
||||
|
@ -661,7 +661,12 @@ function book_check_updates_since(cm_info $cm, $from, $filter = array()) {
|
||||
if (!has_capability('mod/book:viewhiddenchapters', $context)) {
|
||||
$select .= ' AND hidden = 0';
|
||||
}
|
||||
$updates->entries = $DB->count_records_select('book_chapters', $select, $params) > 0;
|
||||
$updates->entries = (object) array('updated' => false);
|
||||
$entries = $DB->get_records_select('book_chapters', $select, $params, '', 'id');
|
||||
if (!empty($entries)) {
|
||||
$updates->entries->updated = true;
|
||||
$updates->entries->itemids = array_keys($entries);
|
||||
}
|
||||
|
||||
return $updates;
|
||||
}
|
||||
|
@ -1156,9 +1156,14 @@ function choice_check_updates_since(cm_info $cm, $from, $filter = array()) {
|
||||
return $updates;
|
||||
}
|
||||
// Check if there are new responses in the choice.
|
||||
$updates->answers = (object) array('updated' => false);
|
||||
$select = 'choiceid = :id AND timemodified > :since';
|
||||
$params = array('id' => $choice->id, 'since' => $from);
|
||||
$updates->answers = $DB->count_records_select('choice_answers', $select, $params) > 0;
|
||||
$answers = $DB->get_records_select('choice_answers', $select, $params, '', 'id');
|
||||
if (!empty($answers)) {
|
||||
$updates->answers->updated = true;
|
||||
$updates->answers->itemids = array_keys($answers);
|
||||
}
|
||||
|
||||
return $updates;
|
||||
}
|
||||
|
@ -747,7 +747,7 @@ function folder_print_recent_activity($course, $viewfullnames, $timestart) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Check if the module has any update that affects the current user since a given time.
|
||||
*
|
||||
* @param cm_info $cm course module data
|
||||
|
@ -2521,13 +2521,12 @@ function forum_count_discussions($forum, $cm, $course) {
|
||||
* @param int $perpage
|
||||
* @param int $groupid if groups enabled, get discussions for this group overriding the current group.
|
||||
* Use FORUM_POSTS_ALL_USER_GROUPS for all the user groups
|
||||
* @param string $extrasql additional SQL code for the query
|
||||
* @param array $extraparams additional params for the $extrasql
|
||||
* @param int $updatedsince retrieve only discussions updated since the given time
|
||||
* @return array
|
||||
*/
|
||||
function forum_get_discussions($cm, $forumsort="", $fullpost=true, $unused=-1, $limit=-1,
|
||||
$userlastmodified=false, $page=-1, $perpage=0, $groupid = -1,
|
||||
$extrasql = '', $extraparams = array()) {
|
||||
$updatedsince = 0) {
|
||||
global $CFG, $DB, $USER;
|
||||
|
||||
$timelimit = '';
|
||||
@ -2638,6 +2637,12 @@ function forum_get_discussions($cm, $forumsort="", $fullpost=true, $unused=-1, $
|
||||
$umtable = " LEFT JOIN {user} um ON (d.usermodified = um.id)";
|
||||
}
|
||||
|
||||
$updatedsincesql = '';
|
||||
if (!empty($updatedsince)) {
|
||||
$updatedsincesql = 'AND d.timemodified > ?';
|
||||
$params[] = $updatedsince;
|
||||
}
|
||||
|
||||
$allnames = get_all_user_name_fields(true, 'u');
|
||||
$sql = "SELECT $postdata, d.name, d.timemodified, d.usermodified, d.groupid, d.timestart, d.timeend, d.pinned, $allnames,
|
||||
u.email, u.picture, u.imagealt $umfields
|
||||
@ -2646,11 +2651,9 @@ function forum_get_discussions($cm, $forumsort="", $fullpost=true, $unused=-1, $
|
||||
JOIN {user} u ON p.userid = u.id
|
||||
$umtable
|
||||
WHERE d.forum = ? AND p.parent = 0
|
||||
$timelimit $groupselect $extrasql
|
||||
$timelimit $groupselect $updatedsincesql
|
||||
ORDER BY $forumsort, d.id DESC";
|
||||
if (!empty($extrasql)) {
|
||||
$params = array_merge($params, $extraparams);
|
||||
}
|
||||
|
||||
return $DB->get_records_sql($sql, $params, $limitfrom, $limitnum);
|
||||
}
|
||||
|
||||
@ -8049,7 +8052,7 @@ function forum_discussion_is_locked($forum, $discussion) {
|
||||
* Check if the module has any update that affects the current user since a given time.
|
||||
*
|
||||
* @param cm_info $cm course module data
|
||||
* @param stdClass $context context object
|
||||
* @param int $from the time to check updates from
|
||||
* @param array $filter if we need to check only specific updates
|
||||
* @return stdClass an object with the different type of areas indicating if they were updated or not
|
||||
* @since Moodle 3.2
|
||||
@ -8065,10 +8068,12 @@ function forum_check_updates_since(cm_info $cm, $from, $filter = array()) {
|
||||
$updates = course_check_module_updates_since($cm, $from, array(), $filter);
|
||||
|
||||
// Check if there are new discussions in the forum.
|
||||
$sql = 'AND (d.timemodified > ? OR p.created > ? OR p.modified > ?)';
|
||||
$params = array($from, $from, $from);
|
||||
$discussions = forum_get_discussions($cm, '', false, -1, -1, true, -1, 0, FORUM_POSTS_ALL_USER_GROUPS, $sql, $params);
|
||||
$updates->discussions = count($discussions) > 0;
|
||||
$updates->discussions = (object) array('updated' => false);
|
||||
$discussions = forum_get_discussions($cm, '', false, -1, -1, true, -1, 0, FORUM_POSTS_ALL_USER_GROUPS, $from);
|
||||
if (!empty($discussions)) {
|
||||
$updates->discussions->updated = true;
|
||||
$updates->discussions->itemids = array_keys($discussions);
|
||||
}
|
||||
|
||||
return $updates;
|
||||
}
|
||||
|
@ -4116,12 +4116,18 @@ function glossary_check_updates_since(cm_info $cm, $from, $filter = array()) {
|
||||
|
||||
$updates = course_check_module_updates_since($cm, $from, array('attachment', 'entry'), $filter);
|
||||
|
||||
$updates->entries = (object) array('updated' => false);
|
||||
$select = 'glossaryid = :id AND (timecreated > :since1 OR timemodified > :since2)';
|
||||
$params = array('id' => $cm->instance, 'since1' => $from, 'since2' => $from);
|
||||
if (!has_capability('mod/glossary:approve', $cm->context)) {
|
||||
$select .= ' AND approved = 1';
|
||||
}
|
||||
$updates->entries = $DB->count_records_select('glossary_entries', $select, $params) > 0;
|
||||
|
||||
$entries = $DB->get_records_select('glossary_entries', $select, $params, '', 'id');
|
||||
if (!empty($entries)) {
|
||||
$updates->entries->updated = true;
|
||||
$updates->entries->itemids = array_keys($entries);
|
||||
}
|
||||
|
||||
return $updates;
|
||||
}
|
||||
|
@ -576,9 +576,14 @@ function lti_check_updates_since(cm_info $cm, $from, $filter = array()) {
|
||||
$updates = course_check_module_updates_since($cm, $from, array(), $filter);
|
||||
|
||||
// Check if there is a new submission.
|
||||
$updates->submissions = (object) array('updated' => false);
|
||||
$select = 'ltiid = :id AND userid = :userid AND (datesubmitted > :since1 OR dateupdated > :since2)';
|
||||
$params = array('id' => $cm->instance, 'userid' => $USER->id, 'since1' => $from, 'since2' => $from);
|
||||
$updates->submissions = $DB->count_records_select('lti_submission', $select, $params) > 0;
|
||||
$submissions = $DB->get_records_select('lti_submission', $select, $params, '', 'id');
|
||||
if (!empty($submissions)) {
|
||||
$updates->submissions->updated = true;
|
||||
$updates->submissions->itemids = array_keys($submissions);
|
||||
}
|
||||
|
||||
return $updates;
|
||||
}
|
||||
|
@ -1925,6 +1925,7 @@ function quiz_check_updates_since(cm_info $cm, $from, $filter = array()) {
|
||||
$updates = course_check_module_updates_since($cm, $from, array(), $filter);
|
||||
|
||||
// Check if questions were updated.
|
||||
$updates->questions = (object) array('updated' => false);
|
||||
$quizobj = quiz::create($cm->instance, $USER->id);
|
||||
$quizobj->preload_questions();
|
||||
$quizobj->load_questions();
|
||||
@ -1934,16 +1935,29 @@ function quiz_check_updates_since(cm_info $cm, $from, $filter = array()) {
|
||||
$select = 'id ' . $questionsql . ' AND (timemodified > :time1 OR timecreated > :time2)';
|
||||
$params['time1'] = $from;
|
||||
$params['time2'] = $from;
|
||||
$updates->questions = $DB->count_records_select('question', $select, $params) > 0;
|
||||
} else {
|
||||
$updates->questions = false;
|
||||
$questions = $DB->count_records_select('question', $select, $params) > 0;
|
||||
if (!empty($questions)) {
|
||||
$updates->questions->updated = true;
|
||||
$updates->questions->itemids = array_keys($questions);
|
||||
}
|
||||
}
|
||||
|
||||
// Check for new attempts or grades.
|
||||
$updates->attempts = (object) array('updated' => false);
|
||||
$updates->grades = (object) array('updated' => false);
|
||||
$select = 'quiz = ? AND userid = ? AND timemodified > ?';
|
||||
$params = array($cm->instance, $USER->id, $from);
|
||||
$updates->attempts = $DB->count_records_select('quiz_attempts', $select, $params) > 0;
|
||||
$updates->grades = $DB->count_records_select('quiz_grades', $select, $params) > 0;
|
||||
|
||||
$attempts = $DB->get_records_select('quiz_attempts', $select, $params, '', 'id');
|
||||
if (!empty($attempts)) {
|
||||
$updates->attempts->updated = true;
|
||||
$updates->attempts->itemids = array_keys($attempts);
|
||||
}
|
||||
$grades = $DB->get_records_select('quiz_grades', $select, $params, '', 'id');
|
||||
if (!empty($grades)) {
|
||||
$updates->grades->updated = true;
|
||||
$updates->grades->itemids = array_keys($grades);
|
||||
}
|
||||
|
||||
return $updates;
|
||||
}
|
||||
|
@ -1516,8 +1516,13 @@ function scorm_check_updates_since(cm_info $cm, $from, $filter = array()) {
|
||||
}
|
||||
$updates = course_check_module_updates_since($cm, $from, array('package'), $filter);
|
||||
|
||||
$updates->tracks = (object) array('updated' => false);
|
||||
$select = 'scormid = ? AND userid = ? AND timemodified > ?';
|
||||
$params = array($scorm->id, $USER->id, $from);
|
||||
$updates->tracks = $DB->count_records_select('scorm_scoes_track', $select, $params) > 0;
|
||||
$tracks = $DB->get_records_select('scorm_scoes_track', $select, $params, '', 'id');
|
||||
if (!empty($tracks)) {
|
||||
$updates->tracks->updated = true;
|
||||
$updates->tracks->itemids = array_keys($tracks);
|
||||
}
|
||||
return $updates;
|
||||
}
|
||||
|
@ -1069,8 +1069,13 @@ function survey_check_updates_since(cm_info $cm, $from, $filter = array()) {
|
||||
}
|
||||
$updates = course_check_module_updates_since($cm, $from, array(), $filter);
|
||||
|
||||
$updates->answers = (object) array('updated' => false);
|
||||
$select = 'survey = ? AND userid = ? AND time > ?';
|
||||
$params = array($cm->instance, $USER->id, $from);
|
||||
$updates->tracks = $DB->count_records_select('survey_answers', $select, $params) > 0;
|
||||
$answers = $DB->get_records_select('survey_answers', $select, $params, '', 'id');
|
||||
if (!empty($answers)) {
|
||||
$updates->answers->updated = true;
|
||||
$updates->answers->itemids = array_keys($answers);
|
||||
}
|
||||
return $updates;
|
||||
}
|
||||
|
@ -760,6 +760,7 @@ function wiki_check_updates_since(cm_info $cm, $from, $filter = array()) {
|
||||
$updates = course_check_module_updates_since($cm, $from, array('attachments'), $filter);
|
||||
|
||||
// Check only pages updated in subwikis the user can access.
|
||||
$updates->pages = (object) array('updated' => false);
|
||||
$wiki = $DB->get_record($cm->modname, array('id' => $cm->instance), '*', MUST_EXIST);
|
||||
if ($subwikis = wiki_get_visible_subwikis($wiki, $cm, $cm->context)) {
|
||||
$subwikisids = array();
|
||||
@ -770,9 +771,11 @@ function wiki_check_updates_since(cm_info $cm, $from, $filter = array()) {
|
||||
$select = 'subwikiid ' . $subwikissql . ' AND (timemodified > :since1 OR timecreated > :since2)';
|
||||
$params['since1'] = $from;
|
||||
$params['since2'] = $from;
|
||||
$updates->pages = $DB->count_records_select('wiki_pages', $select, $params) > 0;
|
||||
} else {
|
||||
$updates->pages = false;
|
||||
$pages = $DB->get_records_select('wiki_pages', $select, $params, '', 'id');
|
||||
if (!empty($pages)) {
|
||||
$updates->pages->updated = true;
|
||||
$updates->pages->itemids = array_keys($pages);
|
||||
}
|
||||
}
|
||||
return $updates;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user