/** * Check if the module has any update that affects the current user since a given time. * * @param cm_info $cm course module data * @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 */ function forum_check_updates_since(cm_info $cm, $from, $filter = array()) { $context = $cm->context; $updates = new stdClass(); if (!has_capability('mod/forum:viewdiscussion', $context)) { return $updates; } $updates = course_check_module_updates_since($cm, $from, array(), $filter); // Check if there are new discussions in the forum. $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; }
/** * Check if the module has any update that affects the current user since a given time. * * @param cm_info $cm course module data * @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 */ function wiki_check_updates_since(cm_info $cm, $from, $filter = array()) { global $DB, $CFG; require_once $CFG->dirroot . '/mod/wiki/locallib.php'; $updates = new stdClass(); if (!has_capability('mod/wiki:viewpage', $cm->context)) { return $updates; } $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(); foreach ($subwikis as $subwiki) { $subwikisids[] = $subwiki->id; } list($subwikissql, $params) = $DB->get_in_or_equal($subwikisids, SQL_PARAMS_NAMED); $select = 'subwikiid ' . $subwikissql . ' AND (timemodified > :since1 OR timecreated > :since2)'; $params['since1'] = $from; $params['since2'] = $from; $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; }
/** * Check if the module has any update that affects the current user since a given time. * * @param cm_info $cm course module data * @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 */ function assign_check_updates_since(cm_info $cm, $from, $filter = array()) { global $DB, $USER, $CFG; require_once $CFG->dirroot . '/mod/assign/locallib.php'; $updates = new stdClass(); $updates = course_check_module_updates_since($cm, $from, array(ASSIGN_INTROATTACHMENT_FILEAREA), $filter); // 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 = (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; }
/** * Check if the module has any update that affects the current user since a given time. * * @param cm_info $cm course module data * @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 */ function imscp_check_updates_since(cm_info $cm, $from, $filter = array()) { $updates = course_check_module_updates_since($cm, $from, array('content'), $filter); return $updates; }
/** * Check if the module has any update that affects the current user since a given time. * * @param cm_info $cm course module data * @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 */ function survey_check_updates_since(cm_info $cm, $from, $filter = array()) { global $DB, $USER; $updates = new stdClass(); if (!has_capability('mod/survey:participate', $cm->context)) { return $updates; } $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); $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; }
/** * Check if the module has any update that affects the current user since a given time. * * @param cm_info $cm course module data * @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 */ function scorm_check_updates_since(cm_info $cm, $from, $filter = array()) { global $DB, $USER, $CFG; require_once $CFG->dirroot . '/mod/scorm/locallib.php'; $scorm = $DB->get_record($cm->modname, array('id' => $cm->instance), '*', MUST_EXIST); $updates = new stdClass(); list($available, $warnings) = scorm_get_availability_status($scorm, true, $cm->context); if (!$available) { return $updates; } $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); $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; }
/** * Check if the module has any update that affects the current user since a given time. * * @param cm_info $cm course module data * @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 */ function quiz_check_updates_since(cm_info $cm, $from, $filter = array()) { global $DB, $USER, $CFG; require_once $CFG->dirroot . '/mod/quiz/locallib.php'; $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(); $questionids = array_keys($quizobj->get_questions()); if (!empty($questionids)) { list($questionsql, $params) = $DB->get_in_or_equal($questionids, SQL_PARAMS_NAMED); $select = 'id ' . $questionsql . ' AND (timemodified > :time1 OR timecreated > :time2)'; $params['time1'] = $from; $params['time2'] = $from; $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); $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; }
/** * Check if the module has any update that affects the current user since a given time. * * @param cm_info $cm course module data * @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 */ function glossary_check_updates_since(cm_info $cm, $from, $filter = array()) { global $DB; $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'; } $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; }
public function test_course_check_module_updates_since() { global $CFG, $DB, $USER; require_once $CFG->dirroot . '/mod/glossary/lib.php'; require_once $CFG->dirroot . '/rating/lib.php'; require_once $CFG->dirroot . '/comment/lib.php'; $this->resetAfterTest(true); $CFG->enablecompletion = true; $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1)); $glossary = $this->getDataGenerator()->create_module('glossary', array('course' => $course->id, 'completion' => COMPLETION_TRACKING_AUTOMATIC, 'completionview' => 1, 'allowcomments' => 1, 'assessed' => RATING_AGGREGATE_AVERAGE, 'scale' => 100)); $glossarygenerator = $this->getDataGenerator()->get_plugin_generator('mod_glossary'); $context = context_module::instance($glossary->cmid); $modinfo = get_fast_modinfo($course); $cm = $modinfo->get_cm($glossary->cmid); $user = $this->getDataGenerator()->create_user(); $studentrole = $DB->get_record('role', array('shortname' => 'student')); $this->getDataGenerator()->enrol_user($user->id, $course->id, $studentrole->id); $from = time(); $teacher = $this->getDataGenerator()->create_user(); $teacherrole = $DB->get_record('role', array('shortname' => 'teacher')); $this->getDataGenerator()->enrol_user($teacher->id, $course->id, $teacherrole->id); assign_capability('mod/glossary:viewanyrating', CAP_ALLOW, $studentrole->id, $context->id, true); // Check nothing changed right now. $updates = course_check_module_updates_since($cm, $from); $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(); // Do some changes. $this->setUser($user); $entry = $glossarygenerator->create_content($glossary); $this->setUser($teacher); // Name. set_coursemodule_name($glossary->cmid, 'New name'); // Add some ratings. $rm = new rating_manager(); $result = $rm->add_rating($cm, $context, 'mod_glossary', 'entry', $entry->id, 100, 50, $user->id, RATING_AGGREGATE_AVERAGE); // Change grades. $glossary->cmidnumber = $glossary->cmid; glossary_update_grades($glossary, $user->id); $this->setUser($user); // Completion status. glossary_view($glossary, $course, $cm, $context, 'letter'); // Add one comment. $args = new stdClass(); $args->context = $context; $args->course = $course; $args->cm = $cm; $args->area = 'glossary_entry'; $args->itemid = $entry->id; $args->client_id = 1; $args->component = 'mod_glossary'; $manager = new comment($args); $manager->add('blah blah blah'); // Check upgrade status. $updates = course_check_module_updates_since($cm, $from); $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); }
/** * Check if the module has any update that affects the current user since a given time. * * @param cm_info $cm course module data * @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 */ function label_check_updates_since(cm_info $cm, $from, $filter = array()) { $updates = course_check_module_updates_since($cm, $from, array(), $filter); return $updates; }
/** * Check if the module has any update that affects the current user since a given time. * * @param cm_info $cm course module data * @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 */ function book_check_updates_since(cm_info $cm, $from, $filter = array()) { global $DB; $context = $cm->context; $updates = new stdClass(); if (!has_capability('mod/book:read', $context)) { return $updates; } $updates = course_check_module_updates_since($cm, $from, array('content'), $filter); $select = 'bookid = :id AND (timecreated > :since1 OR timemodified > :since2)'; $params = array('id' => $cm->instance, 'since1' => $from, 'since2' => $from); if (!has_capability('mod/book:viewhiddenchapters', $context)) { $select .= ' AND hidden = 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; }
/** * Check if the module has any update that affects the current user since a given time. * * @param cm_info $cm course module data * @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 */ function lti_check_updates_since(cm_info $cm, $from, $filter = array()) { global $DB, $USER; $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); $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; }
/** * Check if the module has any update that affects the current user since a given time. * * @param cm_info $cm course module data * @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 */ function choice_check_updates_since(cm_info $cm, $from, $filter = array()) { global $DB; $updates = new stdClass(); $choice = $DB->get_record($cm->modname, array('id' => $cm->instance), '*', MUST_EXIST); list($available, $warnings) = choice_get_availability_status($choice); if (!$available) { return $updates; } $updates = course_check_module_updates_since($cm, $from, array(), $filter); if (!choice_can_view_results($choice)) { 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); $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; }