/** * In rare cases the system may want to change all references to one ID * (e.g. one course-module ID) to another one, within a course. This * function does that for the conditional availability data for all * modules and sections on the course. * * @param int|\stdClass $courseorid Course id or object * @param string $table Table name e.g. 'course_modules' * @param int $oldid Previous ID * @param int $newid New ID * @return bool True if anything changed, otherwise false */ public static function update_dependency_id_across_course($courseorid, $table, $oldid, $newid) { global $DB; $transaction = $DB->start_delegated_transaction(); $modinfo = get_fast_modinfo($courseorid); $anychanged = false; foreach ($modinfo->get_cms() as $cm) { $info = new info_module($cm); $changed = $info->update_dependency_id($table, $oldid, $newid); $anychanged = $anychanged || $changed; } foreach ($modinfo->get_section_info_all() as $section) { $info = new info_section($section); $changed = $info->update_dependency_id($table, $oldid, $newid); $anychanged = $anychanged || $changed; } $transaction->allow_commit(); if ($anychanged) { get_fast_modinfo($courseorid, 0, true); } return $anychanged; }
public function get_user_list_sql($onlyactive = true) { global $CFG, $DB; if (!$CFG->enableavailability) { return array('', array()); } // Get query for section (if any) and module. $section = $this->cm->get_modinfo()->get_section_info($this->cm->sectionnum, MUST_EXIST); $sectioninfo = new info_section($section); $sectionresult = $sectioninfo->get_user_list_sql($onlyactive); $moduleresult = parent::get_user_list_sql($onlyactive); if (!$sectionresult[0]) { return $moduleresult; } if (!$moduleresult[0]) { return $sectionresult; } return array($DB->sql_intersect(array($sectionresult[0], $moduleresult[0]), 'id'), array_merge($sectionresult[1], $moduleresult[1])); }
/** * Tests against a user list. Users who cannot access the activity due to * availability restrictions will be removed from the list. * * Note this only includes availability restrictions (those handled within * this API) and not other ways of restricting access. * * This test ONLY includes conditions which are marked as being applied to * user lists. For example, group conditions are included but date * conditions are not included. * * When called on a module, this test DOES also include restrictions on the * section (if any). * * The function operates reasonably efficiently i.e. should not do per-user * database queries. It is however likely to be fairly slow. * * @param array $users Array of userid => object * @return array Filtered version of input array */ public function filter_user_list(array $users) { global $CFG; if (!$CFG->enableavailability) { return $users; } // Apply section filtering first. $section = $this->cm->get_modinfo()->get_section_info($this->cm->sectionnum, MUST_EXIST); $sectioninfo = new info_section($section); $filtered = $sectioninfo->filter_user_list($users); // Now do base class (module) filtering on top. return parent::filter_user_list($filtered); }