/** * Obtains a string describing this restriction (whether or not * it actually applies). Used to obtain information that is displayed to * students if the activity is not available to them, and for staff to see * what conditions are. * * The $full parameter can be used to distinguish between 'staff' cases * (when displaying all information about the activity) and 'student' cases * (when displaying only conditions they don't meet). * * If implementations require a course or modinfo, they should use * the get methods in $info. * * The special string <AVAILABILITY_CMNAME_123/> can be returned, where * 123 is any number. It will be replaced with the correctly-formatted * name for that activity. * * @param bool $full Set true if this is the 'full information' view * @param bool $not Set true if we are inverting the condition * @param info $info Item we're checking * @return string Information string (for admin) about all restrictions on * this item */ public function get_description($full, $not, info $info) { global $USER, $PAGE; static $jsadded = false; if (!$info instanceof info_module) { return ''; // Should only be possible against activities, not sections. } $cm = $info->get_course_module(); if ($not) { $str = get_string('requires_nopassword', 'availability_password'); } else { $str = get_string('requires_password', 'availability_password'); } if (!$full || !$this->is_available($not, $info, false, $USER->id)) { $url = new \moodle_url('/availability/condition/password/index.php', array('id' => $cm->id)); $str = \html_writer::link($url, $str, array('class' => 'availability_password-popup')); if (!$jsadded) { $PAGE->requires->strings_for_js(['enterpassword', 'wrongpassword', 'passwordintro'], 'availability_password'); $PAGE->requires->strings_for_js(['submit', 'cancel'], 'core'); $jsadded = true; $PAGE->requires->yui_module('moodle-availability_password-popup', 'M.availability_password.popup.init'); } } return $str; }
/** * Gets the actual grouping id for the condition. This is either a specified * id, or a special flag indicating that we use the one for the current cm. * * @param \core_availability\info $info Info about context cm * @return int Grouping id * @throws \coding_exception If it's set to use a cm but there isn't grouping */ protected function get_grouping_id(\core_availability\info $info) { if ($this->activitygrouping) { $groupingid = $info->get_course_module()->groupingid; if (!$groupingid) { throw new \coding_exception('Not supposed to be able to turn on activitygrouping when no grouping'); } return $groupingid; } else { return $this->groupingid; } }