/** * Finds whether this section is available at the moment for the current user. * * The value can be accessed publicly as $sectioninfo->available * * @return bool */ private function get_available() { global $CFG; $userid = $this->modinfo->get_user_id(); if ($this->_available !== null || $userid == -1) { // Has already been calculated or does not need calculation. return $this->_available; } if (!empty($CFG->enableavailability)) { require_once $CFG->libdir . '/conditionlib.php'; // Get availability information. $ci = new \core_availability\info_section($this); $this->_available = $ci->is_available($this->_availableinfo, true, $userid, $this->modinfo); } else { $this->_available = true; $this->_availableinfo = ''; } return $this->_available; }
/** * Return conditionally unavailable elements. * @param $course * @return array * @throws \coding_exception */ public static function conditionally_unavailable_elements($course) { $cancomplete = isloggedin() && !isguestuser(); $unavailablesections = []; $unavailablemods = []; $information = ''; if ($cancomplete) { $completioninfo = new \completion_info($course); if ($completioninfo->is_enabled()) { $modinfo = get_fast_modinfo($course); $sections = $modinfo->get_section_info_all(); foreach ($sections as $number => $section) { $ci = new \core_availability\info_section($section); if (!$ci->is_available($information, true)) { $unavailablesections[] = $number; } } foreach ($modinfo->get_cms() as $mod) { $ci = new \core_availability\info_module($mod); if (!$ci->is_available($information, true)) { $unavailablemods[] = $mod->id; } } } } return [$unavailablesections, $unavailablemods]; }
/** * Finds whether this section is available at the moment for the current user. * * The value can be accessed publicly as $sectioninfo->available * * @return bool */ private function get_available() { global $CFG; $userid = $this->modinfo->get_user_id(); if ($this->_available !== null || $userid == -1) { // Has already been calculated or does not need calculation. return $this->_available; } $this->_available = true; $this->_availableinfo = ''; if (!empty($CFG->enableavailability)) { // Get availability information. $ci = new \core_availability\info_section($this); $this->_available = $ci->is_available($this->_availableinfo, true, $userid, $this->modinfo); } // Execute the hook from the course format that may override the available/availableinfo properties. $currentavailable = $this->_available; course_get_format($this->modinfo->get_course())->section_get_available_hook($this, $this->_available, $this->_availableinfo); if (!$currentavailable && $this->_available) { debugging('section_get_available_hook() can not make unavailable section available', DEBUG_DEVELOPER); $this->_available = $currentavailable; } return $this->_available; }
/** * Javascript required by both standard header layout and flexpage layout * * @return void */ public static function page_requires_js() { global $CFG, $PAGE, $COURSE, $USER; $PAGE->requires->jquery(); $PAGE->requires->strings_for_js(array('close', 'debugerrors', 'problemsfound', 'error:coverimageexceedsmaxbytes', 'error:coverimageresolutionlow', 'forumtopic', 'forumauthor', 'forumpicturegroup', 'forumreplies', 'forumlastpost', 'hiddencoursestoggle', 'loading', 'more', 'moving', 'movingcount', 'movehere', 'movefailed', 'movingdropsectionhelp', 'movingstartedhelp'), 'theme_snap'); $PAGE->requires->strings_for_js(['ok', 'cancel'], 'moodle'); $PAGE->requires->strings_for_js(['printbook'], 'booktool_print'); // Are we viewing /course/view.php - note, this is different from just checking the page type. // We only ever want to load course.js when on site page or view.php - no point in loading it when on // course settings page, etc. $courseviewpage = local::current_url_path() === '/course/view.php'; $pagehascoursecontent = $PAGE->pagetype === 'site-index' || $courseviewpage; $cancomplete = isloggedin() && !isguestuser(); $unavailablesections = []; $unavailablemods = []; if ($cancomplete) { $completioninfo = new \completion_info($COURSE); if ($completioninfo->is_enabled()) { $modinfo = get_fast_modinfo($COURSE); $sections = $modinfo->get_section_info_all(); foreach ($sections as $number => $section) { $ci = new \core_availability\info_section($section); $information = ''; if (!$ci->is_available($information, true)) { $unavailablesections[] = $number; } } foreach ($modinfo as $mod) { $ci = new \core_availability\info_module($mod); if (!$ci->is_available($information, true)) { $unavailablemods[] = $mod->id; } } } } list($unavailablesections, $unavailablemods) = local::conditionally_unavailable_elements($COURSE); $coursevars = (object) ['id' => $COURSE->id, 'shortname' => $COURSE->shortname, 'contextid' => $PAGE->context->id, 'ajaxurl' => '/course/rest.php', 'unavailablesections' => $unavailablesections, 'unavailablemods' => $unavailablemods, 'enablecompletion' => $COURSE->enablecompletion]; $initvars = [$coursevars, $pagehascoursecontent, get_max_upload_file_size($CFG->maxbytes)]; $PAGE->requires->js_call_amd('theme_snap/snap', 'snapInit', $initvars); // Does the page have editable course content? if ($pagehascoursecontent && $PAGE->user_allowed_editing()) { $canmanageacts = has_capability('moodle/course:manageactivities', context_course::instance($COURSE->id)); if ($canmanageacts && empty($USER->editing)) { $modinfo = get_fast_modinfo($COURSE); $modnamesused = $modinfo->get_used_module_names(); // Temporarily change edit mode to on for course ajax to be included. $USER->editing = true; self::include_course_ajax($COURSE, $modnamesused); $USER->editing = false; } } }