id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
217,800
moodle/moodle
lib/modinfolib.php
course_modinfo.instance
public static function instance($courseorid, $userid = 0) { global $USER; if (is_object($courseorid)) { $course = $courseorid; } else { $course = (object)array('id' => $courseorid); } if (empty($userid)) { $userid = $USER->id; } if (!empty(self::$instancecache[$course->id])) { if (self::$instancecache[$course->id]->userid == $userid && (!isset($course->cacherev) || $course->cacherev == self::$instancecache[$course->id]->get_course()->cacherev)) { // This course's modinfo for the same user was recently retrieved, return cached. self::$cacheaccessed[$course->id] = microtime(true); return self::$instancecache[$course->id]; } else { // Prevent potential reference problems when switching users. self::clear_instance_cache($course->id); } } $modinfo = new course_modinfo($course, $userid); // We have a limit of MAX_MODINFO_CACHE_SIZE entries to store in static variable. if (count(self::$instancecache) >= MAX_MODINFO_CACHE_SIZE) { // Find the course that was the least recently accessed. asort(self::$cacheaccessed, SORT_NUMERIC); $courseidtoremove = key(array_reverse(self::$cacheaccessed, true)); self::clear_instance_cache($courseidtoremove); } // Add modinfo to the static cache. self::$instancecache[$course->id] = $modinfo; self::$cacheaccessed[$course->id] = microtime(true); return $modinfo; }
php
public static function instance($courseorid, $userid = 0) { global $USER; if (is_object($courseorid)) { $course = $courseorid; } else { $course = (object)array('id' => $courseorid); } if (empty($userid)) { $userid = $USER->id; } if (!empty(self::$instancecache[$course->id])) { if (self::$instancecache[$course->id]->userid == $userid && (!isset($course->cacherev) || $course->cacherev == self::$instancecache[$course->id]->get_course()->cacherev)) { // This course's modinfo for the same user was recently retrieved, return cached. self::$cacheaccessed[$course->id] = microtime(true); return self::$instancecache[$course->id]; } else { // Prevent potential reference problems when switching users. self::clear_instance_cache($course->id); } } $modinfo = new course_modinfo($course, $userid); // We have a limit of MAX_MODINFO_CACHE_SIZE entries to store in static variable. if (count(self::$instancecache) >= MAX_MODINFO_CACHE_SIZE) { // Find the course that was the least recently accessed. asort(self::$cacheaccessed, SORT_NUMERIC); $courseidtoremove = key(array_reverse(self::$cacheaccessed, true)); self::clear_instance_cache($courseidtoremove); } // Add modinfo to the static cache. self::$instancecache[$course->id] = $modinfo; self::$cacheaccessed[$course->id] = microtime(true); return $modinfo; }
[ "public", "static", "function", "instance", "(", "$", "courseorid", ",", "$", "userid", "=", "0", ")", "{", "global", "$", "USER", ";", "if", "(", "is_object", "(", "$", "courseorid", ")", ")", "{", "$", "course", "=", "$", "courseorid", ";", "}", "else", "{", "$", "course", "=", "(", "object", ")", "array", "(", "'id'", "=>", "$", "courseorid", ")", ";", "}", "if", "(", "empty", "(", "$", "userid", ")", ")", "{", "$", "userid", "=", "$", "USER", "->", "id", ";", "}", "if", "(", "!", "empty", "(", "self", "::", "$", "instancecache", "[", "$", "course", "->", "id", "]", ")", ")", "{", "if", "(", "self", "::", "$", "instancecache", "[", "$", "course", "->", "id", "]", "->", "userid", "==", "$", "userid", "&&", "(", "!", "isset", "(", "$", "course", "->", "cacherev", ")", "||", "$", "course", "->", "cacherev", "==", "self", "::", "$", "instancecache", "[", "$", "course", "->", "id", "]", "->", "get_course", "(", ")", "->", "cacherev", ")", ")", "{", "// This course's modinfo for the same user was recently retrieved, return cached.", "self", "::", "$", "cacheaccessed", "[", "$", "course", "->", "id", "]", "=", "microtime", "(", "true", ")", ";", "return", "self", "::", "$", "instancecache", "[", "$", "course", "->", "id", "]", ";", "}", "else", "{", "// Prevent potential reference problems when switching users.", "self", "::", "clear_instance_cache", "(", "$", "course", "->", "id", ")", ";", "}", "}", "$", "modinfo", "=", "new", "course_modinfo", "(", "$", "course", ",", "$", "userid", ")", ";", "// We have a limit of MAX_MODINFO_CACHE_SIZE entries to store in static variable.", "if", "(", "count", "(", "self", "::", "$", "instancecache", ")", ">=", "MAX_MODINFO_CACHE_SIZE", ")", "{", "// Find the course that was the least recently accessed.", "asort", "(", "self", "::", "$", "cacheaccessed", ",", "SORT_NUMERIC", ")", ";", "$", "courseidtoremove", "=", "key", "(", "array_reverse", "(", "self", "::", "$", "cacheaccessed", ",", "true", ")", ")", ";", "self", "::", "clear_instance_cache", "(", "$", "courseidtoremove", ")", ";", "}", "// Add modinfo to the static cache.", "self", "::", "$", "instancecache", "[", "$", "course", "->", "id", "]", "=", "$", "modinfo", ";", "self", "::", "$", "cacheaccessed", "[", "$", "course", "->", "id", "]", "=", "microtime", "(", "true", ")", ";", "return", "$", "modinfo", ";", "}" ]
Returns the instance of course_modinfo for the specified course and specified user This function uses static cache for the retrieved instances. The cache size is limited by MAX_MODINFO_CACHE_SIZE. If instance is not found in the static cache or it was created for another user or the cacherev validation failed - a new instance is constructed and returned. Used in {@link get_fast_modinfo()} @param int|stdClass $courseorid object from DB table 'course' (must have field 'id' and recommended to have field 'cacherev') or just a course id @param int $userid User id to populate 'availble' and 'uservisible' attributes of modules and sections. Set to 0 for current user (default). Set to -1 to avoid calculation of dynamic user-depended data. @return course_modinfo
[ "Returns", "the", "instance", "of", "course_modinfo", "for", "the", "specified", "course", "and", "specified", "user" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/modinfolib.php#L395-L433
217,801
moodle/moodle
lib/modinfolib.php
course_modinfo.get_course_cache_lock
protected static function get_course_cache_lock($courseid) { // Get database lock to ensure this doesn't happen multiple times in parallel. Wait a // reasonable time for the lock to be released, so we can give a suitable error message. // In case the system crashes while building the course cache, the lock will automatically // expire after a (slightly longer) period. $lockfactory = \core\lock\lock_config::get_lock_factory('core_modinfo'); $lock = $lockfactory->get_lock('build_course_cache_' . $courseid, self::COURSE_CACHE_LOCK_WAIT, self::COURSE_CACHE_LOCK_EXPIRY); if (!$lock) { throw new moodle_exception('locktimeout', '', '', null, 'core_modinfo/build_course_cache_' . $courseid); } return $lock; }
php
protected static function get_course_cache_lock($courseid) { // Get database lock to ensure this doesn't happen multiple times in parallel. Wait a // reasonable time for the lock to be released, so we can give a suitable error message. // In case the system crashes while building the course cache, the lock will automatically // expire after a (slightly longer) period. $lockfactory = \core\lock\lock_config::get_lock_factory('core_modinfo'); $lock = $lockfactory->get_lock('build_course_cache_' . $courseid, self::COURSE_CACHE_LOCK_WAIT, self::COURSE_CACHE_LOCK_EXPIRY); if (!$lock) { throw new moodle_exception('locktimeout', '', '', null, 'core_modinfo/build_course_cache_' . $courseid); } return $lock; }
[ "protected", "static", "function", "get_course_cache_lock", "(", "$", "courseid", ")", "{", "// Get database lock to ensure this doesn't happen multiple times in parallel. Wait a", "// reasonable time for the lock to be released, so we can give a suitable error message.", "// In case the system crashes while building the course cache, the lock will automatically", "// expire after a (slightly longer) period.", "$", "lockfactory", "=", "\\", "core", "\\", "lock", "\\", "lock_config", "::", "get_lock_factory", "(", "'core_modinfo'", ")", ";", "$", "lock", "=", "$", "lockfactory", "->", "get_lock", "(", "'build_course_cache_'", ".", "$", "courseid", ",", "self", "::", "COURSE_CACHE_LOCK_WAIT", ",", "self", "::", "COURSE_CACHE_LOCK_EXPIRY", ")", ";", "if", "(", "!", "$", "lock", ")", "{", "throw", "new", "moodle_exception", "(", "'locktimeout'", ",", "''", ",", "''", ",", "null", ",", "'core_modinfo/build_course_cache_'", ".", "$", "courseid", ")", ";", "}", "return", "$", "lock", ";", "}" ]
Gets a lock for rebuilding the cache of a single course. Caller must release the returned lock. This is used to ensure that the cache rebuild doesn't happen multiple times in parallel. This function will wait up to 1 minute for the lock to be obtained. If the lock cannot be obtained, it throws an exception. @param int $courseid Course id @return \core\lock\lock Lock (must be released!) @throws moodle_exception If the lock cannot be obtained
[ "Gets", "a", "lock", "for", "rebuilding", "the", "cache", "of", "a", "single", "course", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/modinfolib.php#L609-L622
217,802
moodle/moodle
lib/modinfolib.php
course_modinfo.build_course_cache
public static function build_course_cache($course) { if (empty($course->id)) { throw new coding_exception('Object $course is missing required property \id\''); } $lock = self::get_course_cache_lock($course->id); try { return self::inner_build_course_cache($course, $lock); } finally { $lock->release(); } }
php
public static function build_course_cache($course) { if (empty($course->id)) { throw new coding_exception('Object $course is missing required property \id\''); } $lock = self::get_course_cache_lock($course->id); try { return self::inner_build_course_cache($course, $lock); } finally { $lock->release(); } }
[ "public", "static", "function", "build_course_cache", "(", "$", "course", ")", "{", "if", "(", "empty", "(", "$", "course", "->", "id", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Object $course is missing required property \\id\\''", ")", ";", "}", "$", "lock", "=", "self", "::", "get_course_cache_lock", "(", "$", "course", "->", "id", ")", ";", "try", "{", "return", "self", "::", "inner_build_course_cache", "(", "$", "course", ",", "$", "lock", ")", ";", "}", "finally", "{", "$", "lock", "->", "release", "(", ")", ";", "}", "}" ]
Builds and stores in MUC object containing information about course modules and sections together with cached fields from table course. @param stdClass $course object from DB table course. Must have property 'id' but preferably should have all cached fields. @return stdClass object with all cached keys of the course plus fields modinfo and sectioncache. The same object is stored in MUC @throws moodle_exception if course is not found (if $course object misses some of the necessary fields it is re-requested from database)
[ "Builds", "and", "stores", "in", "MUC", "object", "containing", "information", "about", "course", "modules", "and", "sections", "together", "with", "cached", "fields", "from", "table", "course", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/modinfolib.php#L635-L646
217,803
moodle/moodle
lib/modinfolib.php
course_modinfo.inner_build_course_cache
protected static function inner_build_course_cache($course, \core\lock\lock $lock) { global $DB, $CFG; require_once("{$CFG->dirroot}/course/lib.php"); // Ensure object has all necessary fields. foreach (self::$cachedfields as $key) { if (!isset($course->$key)) { $course = $DB->get_record('course', array('id' => $course->id), implode(',', array_merge(array('id'), self::$cachedfields)), MUST_EXIST); break; } } // Retrieve all information about activities and sections. // This may take time on large courses and it is possible that another user modifies the same course during this process. // Field cacherev stored in both DB and cache will ensure that cached data matches the current course state. $coursemodinfo = new stdClass(); $coursemodinfo->modinfo = get_array_of_activities($course->id); $coursemodinfo->sectioncache = self::build_course_section_cache($course); foreach (self::$cachedfields as $key) { $coursemodinfo->$key = $course->$key; } // Set the accumulated activities and sections information in cache, together with cacherev. $cachecoursemodinfo = cache::make('core', 'coursemodinfo'); $cachecoursemodinfo->set($course->id, $coursemodinfo); return $coursemodinfo; }
php
protected static function inner_build_course_cache($course, \core\lock\lock $lock) { global $DB, $CFG; require_once("{$CFG->dirroot}/course/lib.php"); // Ensure object has all necessary fields. foreach (self::$cachedfields as $key) { if (!isset($course->$key)) { $course = $DB->get_record('course', array('id' => $course->id), implode(',', array_merge(array('id'), self::$cachedfields)), MUST_EXIST); break; } } // Retrieve all information about activities and sections. // This may take time on large courses and it is possible that another user modifies the same course during this process. // Field cacherev stored in both DB and cache will ensure that cached data matches the current course state. $coursemodinfo = new stdClass(); $coursemodinfo->modinfo = get_array_of_activities($course->id); $coursemodinfo->sectioncache = self::build_course_section_cache($course); foreach (self::$cachedfields as $key) { $coursemodinfo->$key = $course->$key; } // Set the accumulated activities and sections information in cache, together with cacherev. $cachecoursemodinfo = cache::make('core', 'coursemodinfo'); $cachecoursemodinfo->set($course->id, $coursemodinfo); return $coursemodinfo; }
[ "protected", "static", "function", "inner_build_course_cache", "(", "$", "course", ",", "\\", "core", "\\", "lock", "\\", "lock", "$", "lock", ")", "{", "global", "$", "DB", ",", "$", "CFG", ";", "require_once", "(", "\"{$CFG->dirroot}/course/lib.php\"", ")", ";", "// Ensure object has all necessary fields.", "foreach", "(", "self", "::", "$", "cachedfields", "as", "$", "key", ")", "{", "if", "(", "!", "isset", "(", "$", "course", "->", "$", "key", ")", ")", "{", "$", "course", "=", "$", "DB", "->", "get_record", "(", "'course'", ",", "array", "(", "'id'", "=>", "$", "course", "->", "id", ")", ",", "implode", "(", "','", ",", "array_merge", "(", "array", "(", "'id'", ")", ",", "self", "::", "$", "cachedfields", ")", ")", ",", "MUST_EXIST", ")", ";", "break", ";", "}", "}", "// Retrieve all information about activities and sections.", "// This may take time on large courses and it is possible that another user modifies the same course during this process.", "// Field cacherev stored in both DB and cache will ensure that cached data matches the current course state.", "$", "coursemodinfo", "=", "new", "stdClass", "(", ")", ";", "$", "coursemodinfo", "->", "modinfo", "=", "get_array_of_activities", "(", "$", "course", "->", "id", ")", ";", "$", "coursemodinfo", "->", "sectioncache", "=", "self", "::", "build_course_section_cache", "(", "$", "course", ")", ";", "foreach", "(", "self", "::", "$", "cachedfields", "as", "$", "key", ")", "{", "$", "coursemodinfo", "->", "$", "key", "=", "$", "course", "->", "$", "key", ";", "}", "// Set the accumulated activities and sections information in cache, together with cacherev.", "$", "cachecoursemodinfo", "=", "cache", "::", "make", "(", "'core'", ",", "'coursemodinfo'", ")", ";", "$", "cachecoursemodinfo", "->", "set", "(", "$", "course", "->", "id", ",", "$", "coursemodinfo", ")", ";", "return", "$", "coursemodinfo", ";", "}" ]
Called to build course cache when there is already a lock obtained. @param stdClass $course object from DB table course @param \core\lock\lock $lock Lock object - not actually used, just there to indicate you have a lock @return stdClass Course object that has been stored in MUC
[ "Called", "to", "build", "course", "cache", "when", "there", "is", "already", "a", "lock", "obtained", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/modinfolib.php#L655-L680
217,804
moodle/moodle
lib/modinfolib.php
cm_info.get_module_type_name
public function get_module_type_name($plural = false) { $modnames = get_module_types_names($plural); if (isset($modnames[$this->modname])) { return $modnames[$this->modname]; } else { return null; } }
php
public function get_module_type_name($plural = false) { $modnames = get_module_types_names($plural); if (isset($modnames[$this->modname])) { return $modnames[$this->modname]; } else { return null; } }
[ "public", "function", "get_module_type_name", "(", "$", "plural", "=", "false", ")", "{", "$", "modnames", "=", "get_module_types_names", "(", "$", "plural", ")", ";", "if", "(", "isset", "(", "$", "modnames", "[", "$", "this", "->", "modname", "]", ")", ")", "{", "return", "$", "modnames", "[", "$", "this", "->", "modname", "]", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
Returns a localised human-readable name of the module type @param bool $plural return plural form @return string
[ "Returns", "a", "localised", "human", "-", "readable", "name", "of", "the", "module", "type" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/modinfolib.php#L1492-L1499
217,805
moodle/moodle
lib/modinfolib.php
cm_info.get_effective_groupmode
private function get_effective_groupmode() { $groupmode = $this->groupmode; if ($this->modinfo->get_course()->groupmodeforce) { $groupmode = $this->modinfo->get_course()->groupmode; if ($groupmode != NOGROUPS && !plugin_supports('mod', $this->modname, FEATURE_GROUPS, false)) { $groupmode = NOGROUPS; } } return $groupmode; }
php
private function get_effective_groupmode() { $groupmode = $this->groupmode; if ($this->modinfo->get_course()->groupmodeforce) { $groupmode = $this->modinfo->get_course()->groupmode; if ($groupmode != NOGROUPS && !plugin_supports('mod', $this->modname, FEATURE_GROUPS, false)) { $groupmode = NOGROUPS; } } return $groupmode; }
[ "private", "function", "get_effective_groupmode", "(", ")", "{", "$", "groupmode", "=", "$", "this", "->", "groupmode", ";", "if", "(", "$", "this", "->", "modinfo", "->", "get_course", "(", ")", "->", "groupmodeforce", ")", "{", "$", "groupmode", "=", "$", "this", "->", "modinfo", "->", "get_course", "(", ")", "->", "groupmode", ";", "if", "(", "$", "groupmode", "!=", "NOGROUPS", "&&", "!", "plugin_supports", "(", "'mod'", ",", "$", "this", "->", "modname", ",", "FEATURE_GROUPS", ",", "false", ")", ")", "{", "$", "groupmode", "=", "NOGROUPS", ";", "}", "}", "return", "$", "groupmode", ";", "}" ]
Returns effective groupmode of the module that may be overwritten by forced course groupmode. @return int one of constants NOGROUPS, SEPARATEGROUPS, VISIBLEGROUPS
[ "Returns", "effective", "groupmode", "of", "the", "module", "that", "may", "be", "overwritten", "by", "forced", "course", "groupmode", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/modinfolib.php#L1574-L1583
217,806
moodle/moodle
lib/modinfolib.php
cm_info.get_course_module_record
public function get_course_module_record($additionalfields = false) { $cmrecord = new stdClass(); // Standard fields from table course_modules. static $cmfields = array('id', 'course', 'module', 'instance', 'section', 'idnumber', 'added', 'score', 'indent', 'visible', 'visibleoncoursepage', 'visibleold', 'groupmode', 'groupingid', 'completion', 'completiongradeitemnumber', 'completionview', 'completionexpected', 'showdescription', 'availability', 'deletioninprogress'); foreach ($cmfields as $key) { $cmrecord->$key = $this->$key; } // Additional fields that function get_coursemodule_from_id() adds. if ($additionalfields) { $cmrecord->name = $this->name; $cmrecord->modname = $this->modname; $cmrecord->sectionnum = $this->sectionnum; } return $cmrecord; }
php
public function get_course_module_record($additionalfields = false) { $cmrecord = new stdClass(); // Standard fields from table course_modules. static $cmfields = array('id', 'course', 'module', 'instance', 'section', 'idnumber', 'added', 'score', 'indent', 'visible', 'visibleoncoursepage', 'visibleold', 'groupmode', 'groupingid', 'completion', 'completiongradeitemnumber', 'completionview', 'completionexpected', 'showdescription', 'availability', 'deletioninprogress'); foreach ($cmfields as $key) { $cmrecord->$key = $this->$key; } // Additional fields that function get_coursemodule_from_id() adds. if ($additionalfields) { $cmrecord->name = $this->name; $cmrecord->modname = $this->modname; $cmrecord->sectionnum = $this->sectionnum; } return $cmrecord; }
[ "public", "function", "get_course_module_record", "(", "$", "additionalfields", "=", "false", ")", "{", "$", "cmrecord", "=", "new", "stdClass", "(", ")", ";", "// Standard fields from table course_modules.", "static", "$", "cmfields", "=", "array", "(", "'id'", ",", "'course'", ",", "'module'", ",", "'instance'", ",", "'section'", ",", "'idnumber'", ",", "'added'", ",", "'score'", ",", "'indent'", ",", "'visible'", ",", "'visibleoncoursepage'", ",", "'visibleold'", ",", "'groupmode'", ",", "'groupingid'", ",", "'completion'", ",", "'completiongradeitemnumber'", ",", "'completionview'", ",", "'completionexpected'", ",", "'showdescription'", ",", "'availability'", ",", "'deletioninprogress'", ")", ";", "foreach", "(", "$", "cmfields", "as", "$", "key", ")", "{", "$", "cmrecord", "->", "$", "key", "=", "$", "this", "->", "$", "key", ";", "}", "// Additional fields that function get_coursemodule_from_id() adds.", "if", "(", "$", "additionalfields", ")", "{", "$", "cmrecord", "->", "name", "=", "$", "this", "->", "name", ";", "$", "cmrecord", "->", "modname", "=", "$", "this", "->", "modname", ";", "$", "cmrecord", "->", "sectionnum", "=", "$", "this", "->", "sectionnum", ";", "}", "return", "$", "cmrecord", ";", "}" ]
Returns itself in the form of stdClass. The object includes all fields that table course_modules has and additionally fields 'name', 'modname', 'sectionnum' (if requested). This can be used as a faster alternative to {@link get_coursemodule_from_id()} @param bool $additionalfields include additional fields 'name', 'modname', 'sectionnum' @return stdClass
[ "Returns", "itself", "in", "the", "form", "of", "stdClass", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/modinfolib.php#L1603-L1623
217,807
moodle/moodle
lib/modinfolib.php
cm_info.obtain_dynamic_data
private function obtain_dynamic_data() { global $CFG; $userid = $this->modinfo->get_user_id(); if ($this->state >= self::STATE_BUILDING_DYNAMIC || $userid == -1) { return; } $this->state = self::STATE_BUILDING_DYNAMIC; if (!empty($CFG->enableavailability)) { // Get availability information. $ci = new \core_availability\info_module($this); // Note that the modinfo currently available only includes minimal details (basic data) // but we know that this function does not need anything more than basic data. $this->available = $ci->is_available($this->availableinfo, true, $userid, $this->modinfo); } else { $this->available = true; } // Check parent section. if ($this->available) { $parentsection = $this->modinfo->get_section_info($this->sectionnum); if (!$parentsection->available) { // Do not store info from section here, as that is already // presented from the section (if appropriate) - just change // the flag $this->available = false; } } // Update visible state for current user. $this->update_user_visible(); // Let module make dynamic changes at this point $this->call_mod_function('cm_info_dynamic'); $this->state = self::STATE_DYNAMIC; }
php
private function obtain_dynamic_data() { global $CFG; $userid = $this->modinfo->get_user_id(); if ($this->state >= self::STATE_BUILDING_DYNAMIC || $userid == -1) { return; } $this->state = self::STATE_BUILDING_DYNAMIC; if (!empty($CFG->enableavailability)) { // Get availability information. $ci = new \core_availability\info_module($this); // Note that the modinfo currently available only includes minimal details (basic data) // but we know that this function does not need anything more than basic data. $this->available = $ci->is_available($this->availableinfo, true, $userid, $this->modinfo); } else { $this->available = true; } // Check parent section. if ($this->available) { $parentsection = $this->modinfo->get_section_info($this->sectionnum); if (!$parentsection->available) { // Do not store info from section here, as that is already // presented from the section (if appropriate) - just change // the flag $this->available = false; } } // Update visible state for current user. $this->update_user_visible(); // Let module make dynamic changes at this point $this->call_mod_function('cm_info_dynamic'); $this->state = self::STATE_DYNAMIC; }
[ "private", "function", "obtain_dynamic_data", "(", ")", "{", "global", "$", "CFG", ";", "$", "userid", "=", "$", "this", "->", "modinfo", "->", "get_user_id", "(", ")", ";", "if", "(", "$", "this", "->", "state", ">=", "self", "::", "STATE_BUILDING_DYNAMIC", "||", "$", "userid", "==", "-", "1", ")", "{", "return", ";", "}", "$", "this", "->", "state", "=", "self", "::", "STATE_BUILDING_DYNAMIC", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "enableavailability", ")", ")", "{", "// Get availability information.", "$", "ci", "=", "new", "\\", "core_availability", "\\", "info_module", "(", "$", "this", ")", ";", "// Note that the modinfo currently available only includes minimal details (basic data)", "// but we know that this function does not need anything more than basic data.", "$", "this", "->", "available", "=", "$", "ci", "->", "is_available", "(", "$", "this", "->", "availableinfo", ",", "true", ",", "$", "userid", ",", "$", "this", "->", "modinfo", ")", ";", "}", "else", "{", "$", "this", "->", "available", "=", "true", ";", "}", "// Check parent section.", "if", "(", "$", "this", "->", "available", ")", "{", "$", "parentsection", "=", "$", "this", "->", "modinfo", "->", "get_section_info", "(", "$", "this", "->", "sectionnum", ")", ";", "if", "(", "!", "$", "parentsection", "->", "available", ")", "{", "// Do not store info from section here, as that is already", "// presented from the section (if appropriate) - just change", "// the flag", "$", "this", "->", "available", "=", "false", ";", "}", "}", "// Update visible state for current user.", "$", "this", "->", "update_user_visible", "(", ")", ";", "// Let module make dynamic changes at this point", "$", "this", "->", "call_mod_function", "(", "'cm_info_dynamic'", ")", ";", "$", "this", "->", "state", "=", "self", "::", "STATE_DYNAMIC", ";", "}" ]
If dynamic data for this course-module is not yet available, gets it. This function is automatically called when requesting any course_modinfo property that can be modified by modules (have a set_xxx method). Dynamic data is data which does not come directly from the cache but is calculated at runtime based on the current user. Primarily this concerns whether the user can access the module or not. As part of this function, the module's _cm_info_dynamic function from its lib.php will be called (if it exists). @return void
[ "If", "dynamic", "data", "for", "this", "course", "-", "module", "is", "not", "yet", "available", "gets", "it", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/modinfolib.php#L1878-L1915
217,808
moodle/moodle
lib/modinfolib.php
cm_info.is_stealth
public function is_stealth() { return !$this->visibleoncoursepage || ($this->visible && ($section = $this->get_section_info()) && !$section->visible); }
php
public function is_stealth() { return !$this->visibleoncoursepage || ($this->visible && ($section = $this->get_section_info()) && !$section->visible); }
[ "public", "function", "is_stealth", "(", ")", "{", "return", "!", "$", "this", "->", "visibleoncoursepage", "||", "(", "$", "this", "->", "visible", "&&", "(", "$", "section", "=", "$", "this", "->", "get_section_info", "(", ")", ")", "&&", "!", "$", "section", "->", "visible", ")", ";", "}" ]
Whether this module is available but hidden from course page "Stealth" modules are the ones that are not shown on course page but available by following url. They are normally also displayed in grade reports and other reports. Module will be stealth either if visibleoncoursepage=0 or it is a visible module inside the hidden section. @return bool
[ "Whether", "this", "module", "is", "available", "but", "hidden", "from", "course", "page" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/modinfolib.php#L1949-L1952
217,809
moodle/moodle
lib/modinfolib.php
cm_info.update_user_visible
private function update_user_visible() { $userid = $this->modinfo->get_user_id(); if ($userid == -1) { return null; } $this->uservisible = true; // If the module is being deleted, set the uservisible state to false and return. if ($this->deletioninprogress) { $this->uservisible = false; return null; } // If the user cannot access the activity set the uservisible flag to false. // Additional checks are required to determine whether the activity is entirely hidden or just greyed out. if ((!$this->visible && !has_capability('moodle/course:viewhiddenactivities', $this->get_context(), $userid)) || (!$this->get_available() && !has_capability('moodle/course:ignoreavailabilityrestrictions', $this->get_context(), $userid))) { $this->uservisible = false; } // Check group membership. if ($this->is_user_access_restricted_by_capability()) { $this->uservisible = false; // Ensure activity is completely hidden from the user. $this->availableinfo = ''; } $this->uservisibleoncoursepage = $this->uservisible && ($this->visibleoncoursepage || has_capability('moodle/course:manageactivities', $this->get_context(), $userid) || has_capability('moodle/course:activityvisibility', $this->get_context(), $userid)); // Activity that is not available, not hidden from course page and has availability // info is actually visible on the course page (with availability info and without a link). if (!$this->uservisible && $this->visibleoncoursepage && $this->availableinfo) { $this->uservisibleoncoursepage = true; } }
php
private function update_user_visible() { $userid = $this->modinfo->get_user_id(); if ($userid == -1) { return null; } $this->uservisible = true; // If the module is being deleted, set the uservisible state to false and return. if ($this->deletioninprogress) { $this->uservisible = false; return null; } // If the user cannot access the activity set the uservisible flag to false. // Additional checks are required to determine whether the activity is entirely hidden or just greyed out. if ((!$this->visible && !has_capability('moodle/course:viewhiddenactivities', $this->get_context(), $userid)) || (!$this->get_available() && !has_capability('moodle/course:ignoreavailabilityrestrictions', $this->get_context(), $userid))) { $this->uservisible = false; } // Check group membership. if ($this->is_user_access_restricted_by_capability()) { $this->uservisible = false; // Ensure activity is completely hidden from the user. $this->availableinfo = ''; } $this->uservisibleoncoursepage = $this->uservisible && ($this->visibleoncoursepage || has_capability('moodle/course:manageactivities', $this->get_context(), $userid) || has_capability('moodle/course:activityvisibility', $this->get_context(), $userid)); // Activity that is not available, not hidden from course page and has availability // info is actually visible on the course page (with availability info and without a link). if (!$this->uservisible && $this->visibleoncoursepage && $this->availableinfo) { $this->uservisibleoncoursepage = true; } }
[ "private", "function", "update_user_visible", "(", ")", "{", "$", "userid", "=", "$", "this", "->", "modinfo", "->", "get_user_id", "(", ")", ";", "if", "(", "$", "userid", "==", "-", "1", ")", "{", "return", "null", ";", "}", "$", "this", "->", "uservisible", "=", "true", ";", "// If the module is being deleted, set the uservisible state to false and return.", "if", "(", "$", "this", "->", "deletioninprogress", ")", "{", "$", "this", "->", "uservisible", "=", "false", ";", "return", "null", ";", "}", "// If the user cannot access the activity set the uservisible flag to false.", "// Additional checks are required to determine whether the activity is entirely hidden or just greyed out.", "if", "(", "(", "!", "$", "this", "->", "visible", "&&", "!", "has_capability", "(", "'moodle/course:viewhiddenactivities'", ",", "$", "this", "->", "get_context", "(", ")", ",", "$", "userid", ")", ")", "||", "(", "!", "$", "this", "->", "get_available", "(", ")", "&&", "!", "has_capability", "(", "'moodle/course:ignoreavailabilityrestrictions'", ",", "$", "this", "->", "get_context", "(", ")", ",", "$", "userid", ")", ")", ")", "{", "$", "this", "->", "uservisible", "=", "false", ";", "}", "// Check group membership.", "if", "(", "$", "this", "->", "is_user_access_restricted_by_capability", "(", ")", ")", "{", "$", "this", "->", "uservisible", "=", "false", ";", "// Ensure activity is completely hidden from the user.", "$", "this", "->", "availableinfo", "=", "''", ";", "}", "$", "this", "->", "uservisibleoncoursepage", "=", "$", "this", "->", "uservisible", "&&", "(", "$", "this", "->", "visibleoncoursepage", "||", "has_capability", "(", "'moodle/course:manageactivities'", ",", "$", "this", "->", "get_context", "(", ")", ",", "$", "userid", ")", "||", "has_capability", "(", "'moodle/course:activityvisibility'", ",", "$", "this", "->", "get_context", "(", ")", ",", "$", "userid", ")", ")", ";", "// Activity that is not available, not hidden from course page and has availability", "// info is actually visible on the course page (with availability info and without a link).", "if", "(", "!", "$", "this", "->", "uservisible", "&&", "$", "this", "->", "visibleoncoursepage", "&&", "$", "this", "->", "availableinfo", ")", "{", "$", "this", "->", "uservisibleoncoursepage", "=", "true", ";", "}", "}" ]
Works out whether activity is available to the current user If the activity is unavailable, additional checks are required to determine if its hidden or greyed out @return void
[ "Works", "out", "whether", "activity", "is", "available", "to", "the", "current", "user" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/modinfolib.php#L1992-L2031
217,810
moodle/moodle
lib/modinfolib.php
cm_info.obtain_view_data
private function obtain_view_data() { if ($this->state >= self::STATE_BUILDING_VIEW || $this->modinfo->get_user_id() == -1) { return; } $this->obtain_dynamic_data(); $this->state = self::STATE_BUILDING_VIEW; // Let module make changes at this point $this->call_mod_function('cm_info_view'); $this->state = self::STATE_VIEW; }
php
private function obtain_view_data() { if ($this->state >= self::STATE_BUILDING_VIEW || $this->modinfo->get_user_id() == -1) { return; } $this->obtain_dynamic_data(); $this->state = self::STATE_BUILDING_VIEW; // Let module make changes at this point $this->call_mod_function('cm_info_view'); $this->state = self::STATE_VIEW; }
[ "private", "function", "obtain_view_data", "(", ")", "{", "if", "(", "$", "this", "->", "state", ">=", "self", "::", "STATE_BUILDING_VIEW", "||", "$", "this", "->", "modinfo", "->", "get_user_id", "(", ")", "==", "-", "1", ")", "{", "return", ";", "}", "$", "this", "->", "obtain_dynamic_data", "(", ")", ";", "$", "this", "->", "state", "=", "self", "::", "STATE_BUILDING_VIEW", ";", "// Let module make changes at this point", "$", "this", "->", "call_mod_function", "(", "'cm_info_view'", ")", ";", "$", "this", "->", "state", "=", "self", "::", "STATE_VIEW", ";", "}" ]
If view data for this course-module is not yet available, obtains it. This function is automatically called if any of the functions (marked) which require view data are called. View data is data which is needed only for displaying the course main page (& any similar functionality on other pages) but is not needed in general. Obtaining view data may have a performance cost. As part of this function, the module's _cm_info_view function from its lib.php will be called (if it exists). @return void
[ "If", "view", "data", "for", "this", "course", "-", "module", "is", "not", "yet", "available", "obtains", "it", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/modinfolib.php#L2115-L2125
217,811
moodle/moodle
lib/modinfolib.php
section_info.__isset
public function __isset($name) { if (method_exists($this, 'get_'.$name) || property_exists($this, '_'.$name) || array_key_exists($name, self::$sectionformatoptions[$this->modinfo->get_course()->format])) { $value = $this->__get($name); return isset($value); } return false; }
php
public function __isset($name) { if (method_exists($this, 'get_'.$name) || property_exists($this, '_'.$name) || array_key_exists($name, self::$sectionformatoptions[$this->modinfo->get_course()->format])) { $value = $this->__get($name); return isset($value); } return false; }
[ "public", "function", "__isset", "(", "$", "name", ")", "{", "if", "(", "method_exists", "(", "$", "this", ",", "'get_'", ".", "$", "name", ")", "||", "property_exists", "(", "$", "this", ",", "'_'", ".", "$", "name", ")", "||", "array_key_exists", "(", "$", "name", ",", "self", "::", "$", "sectionformatoptions", "[", "$", "this", "->", "modinfo", "->", "get_course", "(", ")", "->", "format", "]", ")", ")", "{", "$", "value", "=", "$", "this", "->", "__get", "(", "$", "name", ")", ";", "return", "isset", "(", "$", "value", ")", ";", "}", "return", "false", ";", "}" ]
Magic method to check if the property is set @param string $name name of the property @return bool
[ "Magic", "method", "to", "check", "if", "the", "property", "is", "set" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/modinfolib.php#L2703-L2711
217,812
moodle/moodle
lib/modinfolib.php
section_info.__empty
public function __empty($name) { if (method_exists($this, 'get_'.$name) || property_exists($this, '_'.$name) || array_key_exists($name, self::$sectionformatoptions[$this->modinfo->get_course()->format])) { $value = $this->__get($name); return empty($value); } return true; }
php
public function __empty($name) { if (method_exists($this, 'get_'.$name) || property_exists($this, '_'.$name) || array_key_exists($name, self::$sectionformatoptions[$this->modinfo->get_course()->format])) { $value = $this->__get($name); return empty($value); } return true; }
[ "public", "function", "__empty", "(", "$", "name", ")", "{", "if", "(", "method_exists", "(", "$", "this", ",", "'get_'", ".", "$", "name", ")", "||", "property_exists", "(", "$", "this", ",", "'_'", ".", "$", "name", ")", "||", "array_key_exists", "(", "$", "name", ",", "self", "::", "$", "sectionformatoptions", "[", "$", "this", "->", "modinfo", "->", "get_course", "(", ")", "->", "format", "]", ")", ")", "{", "$", "value", "=", "$", "this", "->", "__get", "(", "$", "name", ")", ";", "return", "empty", "(", "$", "value", ")", ";", "}", "return", "true", ";", "}" ]
Magic method to check if the property is empty @param string $name name of the property @return bool
[ "Magic", "method", "to", "check", "if", "the", "property", "is", "empty" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/modinfolib.php#L2719-L2727
217,813
moodle/moodle
lib/modinfolib.php
section_info.get_available
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; }
php
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; }
[ "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", ";", "}" ]
Finds whether this section is available at the moment for the current user. The value can be accessed publicly as $sectioninfo->available @return bool
[ "Finds", "whether", "this", "section", "is", "available", "at", "the", "moment", "for", "the", "current", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/modinfolib.php#L2762-L2786
217,814
moodle/moodle
lib/modinfolib.php
section_info.get_sequence
private function get_sequence() { if (!empty($this->modinfo->sections[$this->_section])) { return implode(',', $this->modinfo->sections[$this->_section]); } else { return ''; } }
php
private function get_sequence() { if (!empty($this->modinfo->sections[$this->_section])) { return implode(',', $this->modinfo->sections[$this->_section]); } else { return ''; } }
[ "private", "function", "get_sequence", "(", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "modinfo", "->", "sections", "[", "$", "this", "->", "_section", "]", ")", ")", "{", "return", "implode", "(", "','", ",", "$", "this", "->", "modinfo", "->", "sections", "[", "$", "this", "->", "_section", "]", ")", ";", "}", "else", "{", "return", "''", ";", "}", "}" ]
Restores the course_sections.sequence value @return string
[ "Restores", "the", "course_sections", ".", "sequence", "value" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/modinfolib.php#L2853-L2859
217,815
moodle/moodle
lib/modinfolib.php
section_info.convert_for_section_cache
public static function convert_for_section_cache($section) { global $CFG; // Course id stored in course table unset($section->course); // Section number stored in array key unset($section->section); // Sequence stored implicity in modinfo $sections array unset($section->sequence); // Remove default data foreach (self::$sectioncachedefaults as $field => $value) { // Exact compare as strings to avoid problems if some strings are set // to "0" etc. if (isset($section->{$field}) && $section->{$field} === $value) { unset($section->{$field}); } } }
php
public static function convert_for_section_cache($section) { global $CFG; // Course id stored in course table unset($section->course); // Section number stored in array key unset($section->section); // Sequence stored implicity in modinfo $sections array unset($section->sequence); // Remove default data foreach (self::$sectioncachedefaults as $field => $value) { // Exact compare as strings to avoid problems if some strings are set // to "0" etc. if (isset($section->{$field}) && $section->{$field} === $value) { unset($section->{$field}); } } }
[ "public", "static", "function", "convert_for_section_cache", "(", "$", "section", ")", "{", "global", "$", "CFG", ";", "// Course id stored in course table", "unset", "(", "$", "section", "->", "course", ")", ";", "// Section number stored in array key", "unset", "(", "$", "section", "->", "section", ")", ";", "// Sequence stored implicity in modinfo $sections array", "unset", "(", "$", "section", "->", "sequence", ")", ";", "// Remove default data", "foreach", "(", "self", "::", "$", "sectioncachedefaults", "as", "$", "field", "=>", "$", "value", ")", "{", "// Exact compare as strings to avoid problems if some strings are set", "// to \"0\" etc.", "if", "(", "isset", "(", "$", "section", "->", "{", "$", "field", "}", ")", "&&", "$", "section", "->", "{", "$", "field", "}", "===", "$", "value", ")", "{", "unset", "(", "$", "section", "->", "{", "$", "field", "}", ")", ";", "}", "}", "}" ]
Prepares section data for inclusion in sectioncache cache, removing items that are set to defaults, and adding availability data if required. Called by build_section_cache in course_modinfo only; do not use otherwise. @param object $section Raw section data object
[ "Prepares", "section", "data", "for", "inclusion", "in", "sectioncache", "cache", "removing", "items", "that", "are", "set", "to", "defaults", "and", "adding", "availability", "data", "if", "required", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/modinfolib.php#L2886-L2904
217,816
moodle/moodle
backup/moodle2/backup_block_task.class.php
backup_block_task.get_taskbasepath
public function get_taskbasepath() { $basepath = $this->get_basepath(); // Module blocks are under module dir if (!empty($this->moduleid)) { $basepath .= '/activities/' . $this->modulename . '_' . $this->moduleid . '/blocks/' . $this->blockname . '_' . $this->blockid; // Course blocks are under course dir } else { $basepath .= '/course/blocks/' . $this->blockname . '_' . $this->blockid; } return $basepath; }
php
public function get_taskbasepath() { $basepath = $this->get_basepath(); // Module blocks are under module dir if (!empty($this->moduleid)) { $basepath .= '/activities/' . $this->modulename . '_' . $this->moduleid . '/blocks/' . $this->blockname . '_' . $this->blockid; // Course blocks are under course dir } else { $basepath .= '/course/blocks/' . $this->blockname . '_' . $this->blockid; } return $basepath; }
[ "public", "function", "get_taskbasepath", "(", ")", "{", "$", "basepath", "=", "$", "this", "->", "get_basepath", "(", ")", ";", "// Module blocks are under module dir", "if", "(", "!", "empty", "(", "$", "this", "->", "moduleid", ")", ")", "{", "$", "basepath", ".=", "'/activities/'", ".", "$", "this", "->", "modulename", ".", "'_'", ".", "$", "this", "->", "moduleid", ".", "'/blocks/'", ".", "$", "this", "->", "blockname", ".", "'_'", ".", "$", "this", "->", "blockid", ";", "// Course blocks are under course dir", "}", "else", "{", "$", "basepath", ".=", "'/course/blocks/'", ".", "$", "this", "->", "blockname", ".", "'_'", ".", "$", "this", "->", "blockid", ";", "}", "return", "$", "basepath", ";", "}" ]
Block tasks have their own directory to write files
[ "Block", "tasks", "have", "their", "own", "directory", "to", "write", "files" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/moodle2/backup_block_task.class.php#L107-L120
217,817
moodle/moodle
admin/tool/usertours/classes/tour.php
tour.load_from_record
public static function load_from_record($record, $clean = false) { $tour = new self(); return $tour->reload_from_record($record, $clean); }
php
public static function load_from_record($record, $clean = false) { $tour = new self(); return $tour->reload_from_record($record, $clean); }
[ "public", "static", "function", "load_from_record", "(", "$", "record", ",", "$", "clean", "=", "false", ")", "{", "$", "tour", "=", "new", "self", "(", ")", ";", "return", "$", "tour", "->", "reload_from_record", "(", "$", "record", ",", "$", "clean", ")", ";", "}" ]
Create an instance of tour from its provided DB record. @param stdClass $record The record of the tour to load. @param boolean $clean Clean the values. @return tour
[ "Create", "an", "instance", "of", "tour", "from", "its", "provided", "DB", "record", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/tour.php#L133-L136
217,818
moodle/moodle
admin/tool/usertours/classes/tour.php
tour.reload_from_record
protected function reload_from_record($record, $clean = false) { $this->id = $record->id; if (!property_exists($record, 'description')) { if (property_exists($record, 'comment')) { $record->description = $record->comment; unset($record->comment); } } if ($clean) { $this->name = clean_param($record->name, PARAM_TEXT); $this->description = clean_text($record->description); } else { $this->name = $record->name; $this->description = $record->description; } $this->pathmatch = $record->pathmatch; $this->enabled = $record->enabled; if (isset($record->sortorder)) { $this->sortorder = $record->sortorder; } $this->config = json_decode($record->configdata); $this->dirty = false; $this->steps = []; return $this; }
php
protected function reload_from_record($record, $clean = false) { $this->id = $record->id; if (!property_exists($record, 'description')) { if (property_exists($record, 'comment')) { $record->description = $record->comment; unset($record->comment); } } if ($clean) { $this->name = clean_param($record->name, PARAM_TEXT); $this->description = clean_text($record->description); } else { $this->name = $record->name; $this->description = $record->description; } $this->pathmatch = $record->pathmatch; $this->enabled = $record->enabled; if (isset($record->sortorder)) { $this->sortorder = $record->sortorder; } $this->config = json_decode($record->configdata); $this->dirty = false; $this->steps = []; return $this; }
[ "protected", "function", "reload_from_record", "(", "$", "record", ",", "$", "clean", "=", "false", ")", "{", "$", "this", "->", "id", "=", "$", "record", "->", "id", ";", "if", "(", "!", "property_exists", "(", "$", "record", ",", "'description'", ")", ")", "{", "if", "(", "property_exists", "(", "$", "record", ",", "'comment'", ")", ")", "{", "$", "record", "->", "description", "=", "$", "record", "->", "comment", ";", "unset", "(", "$", "record", "->", "comment", ")", ";", "}", "}", "if", "(", "$", "clean", ")", "{", "$", "this", "->", "name", "=", "clean_param", "(", "$", "record", "->", "name", ",", "PARAM_TEXT", ")", ";", "$", "this", "->", "description", "=", "clean_text", "(", "$", "record", "->", "description", ")", ";", "}", "else", "{", "$", "this", "->", "name", "=", "$", "record", "->", "name", ";", "$", "this", "->", "description", "=", "$", "record", "->", "description", ";", "}", "$", "this", "->", "pathmatch", "=", "$", "record", "->", "pathmatch", ";", "$", "this", "->", "enabled", "=", "$", "record", "->", "enabled", ";", "if", "(", "isset", "(", "$", "record", "->", "sortorder", ")", ")", "{", "$", "this", "->", "sortorder", "=", "$", "record", "->", "sortorder", ";", "}", "$", "this", "->", "config", "=", "json_decode", "(", "$", "record", "->", "configdata", ")", ";", "$", "this", "->", "dirty", "=", "false", ";", "$", "this", "->", "steps", "=", "[", "]", ";", "return", "$", "this", ";", "}" ]
Reload the tour into the current object. @param stdClass $record The record to reload. @param boolean $clean Clean the values. @return tour
[ "Reload", "the", "tour", "into", "the", "current", "object", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/tour.php#L168-L193
217,819
moodle/moodle
admin/tool/usertours/classes/tour.php
tour.get_steps
public function get_steps() { if (empty($this->steps)) { $this->steps = helper::get_steps($this->id); } return $this->steps; }
php
public function get_steps() { if (empty($this->steps)) { $this->steps = helper::get_steps($this->id); } return $this->steps; }
[ "public", "function", "get_steps", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "steps", ")", ")", "{", "$", "this", "->", "steps", "=", "helper", "::", "get_steps", "(", "$", "this", "->", "id", ")", ";", "}", "return", "$", "this", "->", "steps", ";", "}" ]
Fetch all steps in the tour. @return stdClass[]
[ "Fetch", "all", "steps", "in", "the", "tour", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/tour.php#L200-L206
217,820
moodle/moodle
admin/tool/usertours/classes/tour.php
tour.set_name
public function set_name($value) { $this->name = clean_param($value, PARAM_TEXT); $this->dirty = true; return $this; }
php
public function set_name($value) { $this->name = clean_param($value, PARAM_TEXT); $this->dirty = true; return $this; }
[ "public", "function", "set_name", "(", "$", "value", ")", "{", "$", "this", "->", "name", "=", "clean_param", "(", "$", "value", ",", "PARAM_TEXT", ")", ";", "$", "this", "->", "dirty", "=", "true", ";", "return", "$", "this", ";", "}" ]
Set the name of the tour to the specified value. @param string $value The new name. @return $this
[ "Set", "the", "name", "of", "the", "tour", "to", "the", "specified", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/tour.php#L241-L246
217,821
moodle/moodle
admin/tool/usertours/classes/tour.php
tour.set_description
public function set_description($value) { $this->description = clean_text($value); $this->dirty = true; return $this; }
php
public function set_description($value) { $this->description = clean_text($value); $this->dirty = true; return $this; }
[ "public", "function", "set_description", "(", "$", "value", ")", "{", "$", "this", "->", "description", "=", "clean_text", "(", "$", "value", ")", ";", "$", "this", "->", "dirty", "=", "true", ";", "return", "$", "this", ";", "}" ]
Set the description of the tour to the specified value. @param string $value The new description. @return $this
[ "Set", "the", "description", "of", "the", "tour", "to", "the", "specified", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/tour.php#L263-L268
217,822
moodle/moodle
admin/tool/usertours/classes/tour.php
tour.to_record
public function to_record() { return (object) array( 'id' => $this->id, 'name' => $this->name, 'description' => $this->description, 'pathmatch' => $this->pathmatch, 'enabled' => $this->enabled, 'sortorder' => $this->sortorder, 'configdata' => json_encode($this->config), ); }
php
public function to_record() { return (object) array( 'id' => $this->id, 'name' => $this->name, 'description' => $this->description, 'pathmatch' => $this->pathmatch, 'enabled' => $this->enabled, 'sortorder' => $this->sortorder, 'configdata' => json_encode($this->config), ); }
[ "public", "function", "to_record", "(", ")", "{", "return", "(", "object", ")", "array", "(", "'id'", "=>", "$", "this", "->", "id", ",", "'name'", "=>", "$", "this", "->", "name", ",", "'description'", "=>", "$", "this", "->", "description", ",", "'pathmatch'", "=>", "$", "this", "->", "pathmatch", ",", "'enabled'", "=>", "$", "this", "->", "enabled", ",", "'sortorder'", "=>", "$", "this", "->", "sortorder", ",", "'configdata'", "=>", "json_encode", "(", "$", "this", "->", "config", ")", ",", ")", ";", "}" ]
Prepare this tour for saving to the database. @return object
[ "Prepare", "this", "tour", "for", "saving", "to", "the", "database", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/tour.php#L373-L383
217,823
moodle/moodle
admin/tool/usertours/classes/tour.php
tour.is_last_tour
public function is_last_tour($tourcount = null) { if ($tourcount === null) { $tourcount = helper::count_tours(); } return ($this->get_sortorder() === ($tourcount - 1)); }
php
public function is_last_tour($tourcount = null) { if ($tourcount === null) { $tourcount = helper::count_tours(); } return ($this->get_sortorder() === ($tourcount - 1)); }
[ "public", "function", "is_last_tour", "(", "$", "tourcount", "=", "null", ")", "{", "if", "(", "$", "tourcount", "===", "null", ")", "{", "$", "tourcount", "=", "helper", "::", "count_tours", "(", ")", ";", "}", "return", "(", "$", "this", "->", "get_sortorder", "(", ")", "===", "(", "$", "tourcount", "-", "1", ")", ")", ";", "}" ]
Whether this tour is the last tour. @param int $tourcount The pre-fetched count of tours @return boolean
[ "Whether", "this", "tour", "is", "the", "last", "tour", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/tour.php#L409-L414
217,824
moodle/moodle
admin/tool/usertours/classes/tour.php
tour.set_config
public function set_config($key, $value) { if ($this->config === null) { $this->config = (object) array(); } $this->config->$key = $value; $this->dirty = true; return $this; }
php
public function set_config($key, $value) { if ($this->config === null) { $this->config = (object) array(); } $this->config->$key = $value; $this->dirty = true; return $this; }
[ "public", "function", "set_config", "(", "$", "key", ",", "$", "value", ")", "{", "if", "(", "$", "this", "->", "config", "===", "null", ")", "{", "$", "this", "->", "config", "=", "(", "object", ")", "array", "(", ")", ";", "}", "$", "this", "->", "config", "->", "$", "key", "=", "$", "value", ";", "$", "this", "->", "dirty", "=", "true", ";", "return", "$", "this", ";", "}" ]
Set the configuration item as specified. @param string $key The configuration key to set. @param mixed $value The new value for the configuration item. @return $this
[ "Set", "the", "configuration", "item", "as", "specified", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/tour.php#L491-L499
217,825
moodle/moodle
admin/tool/usertours/classes/tour.php
tour.reset_step_sortorder
public function reset_step_sortorder() { global $DB; $steps = $DB->get_records('tool_usertours_steps', array('tourid' => $this->id), 'sortorder ASC', 'id'); $index = 0; foreach ($steps as $step) { $DB->set_field('tool_usertours_steps', 'sortorder', $index, array('id' => $step->id)); $index++; } // Notify of a change to the step configuration. // Note: Do not notify of a tour change here. This is only a step change for a tour. cache::notify_step_change($this->get_id()); return $this; }
php
public function reset_step_sortorder() { global $DB; $steps = $DB->get_records('tool_usertours_steps', array('tourid' => $this->id), 'sortorder ASC', 'id'); $index = 0; foreach ($steps as $step) { $DB->set_field('tool_usertours_steps', 'sortorder', $index, array('id' => $step->id)); $index++; } // Notify of a change to the step configuration. // Note: Do not notify of a tour change here. This is only a step change for a tour. cache::notify_step_change($this->get_id()); return $this; }
[ "public", "function", "reset_step_sortorder", "(", ")", "{", "global", "$", "DB", ";", "$", "steps", "=", "$", "DB", "->", "get_records", "(", "'tool_usertours_steps'", ",", "array", "(", "'tourid'", "=>", "$", "this", "->", "id", ")", ",", "'sortorder ASC'", ",", "'id'", ")", ";", "$", "index", "=", "0", ";", "foreach", "(", "$", "steps", "as", "$", "step", ")", "{", "$", "DB", "->", "set_field", "(", "'tool_usertours_steps'", ",", "'sortorder'", ",", "$", "index", ",", "array", "(", "'id'", "=>", "$", "step", "->", "id", ")", ")", ";", "$", "index", "++", ";", "}", "// Notify of a change to the step configuration.", "// Note: Do not notify of a tour change here. This is only a step change for a tour.", "cache", "::", "notify_step_change", "(", "$", "this", "->", "get_id", "(", ")", ")", ";", "return", "$", "this", ";", "}" ]
Reset the sortorder for all steps in the tour. @return $this
[ "Reset", "the", "sortorder", "for", "all", "steps", "in", "the", "tour", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/tour.php#L562-L577
217,826
moodle/moodle
admin/tool/usertours/classes/tour.php
tour.should_show_for_user
public function should_show_for_user() { if (!$this->is_enabled()) { // The tour is disabled - it should not be shown. return false; } if ($tourcompletiondate = get_user_preferences(self::TOUR_LAST_COMPLETED_BY_USER . $this->get_id(), null)) { if ($tourresetdate = get_user_preferences(self::TOUR_REQUESTED_BY_USER . $this->get_id(), null)) { if ($tourresetdate >= $tourcompletiondate) { return true; } } $lastmajorupdate = $this->get_config('majorupdatetime', time()); if ($tourcompletiondate > $lastmajorupdate) { // The user has completed the tour since the last major update. return false; } } return true; }
php
public function should_show_for_user() { if (!$this->is_enabled()) { // The tour is disabled - it should not be shown. return false; } if ($tourcompletiondate = get_user_preferences(self::TOUR_LAST_COMPLETED_BY_USER . $this->get_id(), null)) { if ($tourresetdate = get_user_preferences(self::TOUR_REQUESTED_BY_USER . $this->get_id(), null)) { if ($tourresetdate >= $tourcompletiondate) { return true; } } $lastmajorupdate = $this->get_config('majorupdatetime', time()); if ($tourcompletiondate > $lastmajorupdate) { // The user has completed the tour since the last major update. return false; } } return true; }
[ "public", "function", "should_show_for_user", "(", ")", "{", "if", "(", "!", "$", "this", "->", "is_enabled", "(", ")", ")", "{", "// The tour is disabled - it should not be shown.", "return", "false", ";", "}", "if", "(", "$", "tourcompletiondate", "=", "get_user_preferences", "(", "self", "::", "TOUR_LAST_COMPLETED_BY_USER", ".", "$", "this", "->", "get_id", "(", ")", ",", "null", ")", ")", "{", "if", "(", "$", "tourresetdate", "=", "get_user_preferences", "(", "self", "::", "TOUR_REQUESTED_BY_USER", ".", "$", "this", "->", "get_id", "(", ")", ",", "null", ")", ")", "{", "if", "(", "$", "tourresetdate", ">=", "$", "tourcompletiondate", ")", "{", "return", "true", ";", "}", "}", "$", "lastmajorupdate", "=", "$", "this", "->", "get_config", "(", "'majorupdatetime'", ",", "time", "(", ")", ")", ";", "if", "(", "$", "tourcompletiondate", ">", "$", "lastmajorupdate", ")", "{", "// The user has completed the tour since the last major update.", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Whether this tour should be displayed to the user. @return boolean
[ "Whether", "this", "tour", "should", "be", "displayed", "to", "the", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/tour.php#L584-L604
217,827
moodle/moodle
admin/tool/usertours/classes/tour.php
tour.get_tour_key
public function get_tour_key() { global $USER; $tourtime = $this->get_config('majorupdatetime', null); if ($tourtime === null) { // This tour has no majorupdate time. // Set one now to prevent repeated displays to the user. $this->set_config('majorupdatetime', time()); $this->persist(); $tourtime = $this->get_config('majorupdatetime', null); } if ($userresetdate = get_user_preferences(self::TOUR_REQUESTED_BY_USER . $this->get_id(), null)) { $tourtime = max($tourtime, $userresetdate); } return sprintf('tool_usertours_%d_%d_%s', $USER->id, $this->get_id(), $tourtime); }
php
public function get_tour_key() { global $USER; $tourtime = $this->get_config('majorupdatetime', null); if ($tourtime === null) { // This tour has no majorupdate time. // Set one now to prevent repeated displays to the user. $this->set_config('majorupdatetime', time()); $this->persist(); $tourtime = $this->get_config('majorupdatetime', null); } if ($userresetdate = get_user_preferences(self::TOUR_REQUESTED_BY_USER . $this->get_id(), null)) { $tourtime = max($tourtime, $userresetdate); } return sprintf('tool_usertours_%d_%d_%s', $USER->id, $this->get_id(), $tourtime); }
[ "public", "function", "get_tour_key", "(", ")", "{", "global", "$", "USER", ";", "$", "tourtime", "=", "$", "this", "->", "get_config", "(", "'majorupdatetime'", ",", "null", ")", ";", "if", "(", "$", "tourtime", "===", "null", ")", "{", "// This tour has no majorupdate time.", "// Set one now to prevent repeated displays to the user.", "$", "this", "->", "set_config", "(", "'majorupdatetime'", ",", "time", "(", ")", ")", ";", "$", "this", "->", "persist", "(", ")", ";", "$", "tourtime", "=", "$", "this", "->", "get_config", "(", "'majorupdatetime'", ",", "null", ")", ";", "}", "if", "(", "$", "userresetdate", "=", "get_user_preferences", "(", "self", "::", "TOUR_REQUESTED_BY_USER", ".", "$", "this", "->", "get_id", "(", ")", ",", "null", ")", ")", "{", "$", "tourtime", "=", "max", "(", "$", "tourtime", ",", "$", "userresetdate", ")", ";", "}", "return", "sprintf", "(", "'tool_usertours_%d_%d_%s'", ",", "$", "USER", "->", "id", ",", "$", "this", "->", "get_id", "(", ")", ",", "$", "tourtime", ")", ";", "}" ]
Get the key for this tour. This is used in the session cookie to determine whether the user has seen this tour before.
[ "Get", "the", "key", "for", "this", "tour", ".", "This", "is", "used", "in", "the", "session", "cookie", "to", "determine", "whether", "the", "user", "has", "seen", "this", "tour", "before", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/tour.php#L610-L628
217,828
moodle/moodle
admin/tool/usertours/classes/tour.php
tour.mark_major_change
public function mark_major_change() { global $DB; // Clear old reset and completion notes. $DB->delete_records('user_preferences', ['name' => self::TOUR_LAST_COMPLETED_BY_USER . $this->get_id()]); $DB->delete_records('user_preferences', ['name' => self::TOUR_REQUESTED_BY_USER . $this->get_id()]); $this->set_config('majorupdatetime', time()); $this->persist(); return $this; }
php
public function mark_major_change() { global $DB; // Clear old reset and completion notes. $DB->delete_records('user_preferences', ['name' => self::TOUR_LAST_COMPLETED_BY_USER . $this->get_id()]); $DB->delete_records('user_preferences', ['name' => self::TOUR_REQUESTED_BY_USER . $this->get_id()]); $this->set_config('majorupdatetime', time()); $this->persist(); return $this; }
[ "public", "function", "mark_major_change", "(", ")", "{", "global", "$", "DB", ";", "// Clear old reset and completion notes.", "$", "DB", "->", "delete_records", "(", "'user_preferences'", ",", "[", "'name'", "=>", "self", "::", "TOUR_LAST_COMPLETED_BY_USER", ".", "$", "this", "->", "get_id", "(", ")", "]", ")", ";", "$", "DB", "->", "delete_records", "(", "'user_preferences'", ",", "[", "'name'", "=>", "self", "::", "TOUR_REQUESTED_BY_USER", ".", "$", "this", "->", "get_id", "(", ")", "]", ")", ";", "$", "this", "->", "set_config", "(", "'majorupdatetime'", ",", "time", "(", ")", ")", ";", "$", "this", "->", "persist", "(", ")", ";", "return", "$", "this", ";", "}" ]
Update a tour giving it a new major update time. This will ensure that it is displayed to all users, even those who have already seen it. @return $this
[ "Update", "a", "tour", "giving", "it", "a", "new", "major", "update", "time", ".", "This", "will", "ensure", "that", "it", "is", "displayed", "to", "all", "users", "even", "those", "who", "have", "already", "seen", "it", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/tour.php#L658-L668
217,829
moodle/moodle
admin/tool/usertours/classes/tour.php
tour.get_filter_values
public function get_filter_values($filter) { if ($allvalues = (array) $this->get_config('filtervalues')) { if (isset($allvalues[$filter])) { return $allvalues[$filter]; } } return []; }
php
public function get_filter_values($filter) { if ($allvalues = (array) $this->get_config('filtervalues')) { if (isset($allvalues[$filter])) { return $allvalues[$filter]; } } return []; }
[ "public", "function", "get_filter_values", "(", "$", "filter", ")", "{", "if", "(", "$", "allvalues", "=", "(", "array", ")", "$", "this", "->", "get_config", "(", "'filtervalues'", ")", ")", "{", "if", "(", "isset", "(", "$", "allvalues", "[", "$", "filter", "]", ")", ")", "{", "return", "$", "allvalues", "[", "$", "filter", "]", ";", "}", "}", "return", "[", "]", ";", "}" ]
Get the configured filter values. @param string $filter The filter to retrieve values for. @return array
[ "Get", "the", "configured", "filter", "values", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/tour.php#L727-L735
217,830
moodle/moodle
admin/tool/usertours/classes/tour.php
tour.set_filter_values
public function set_filter_values($filter, array $values = []) { $allvalues = (array) $this->get_config('filtervalues', []); $allvalues[$filter] = $values; return $this->set_config('filtervalues', $allvalues); }
php
public function set_filter_values($filter, array $values = []) { $allvalues = (array) $this->get_config('filtervalues', []); $allvalues[$filter] = $values; return $this->set_config('filtervalues', $allvalues); }
[ "public", "function", "set_filter_values", "(", "$", "filter", ",", "array", "$", "values", "=", "[", "]", ")", "{", "$", "allvalues", "=", "(", "array", ")", "$", "this", "->", "get_config", "(", "'filtervalues'", ",", "[", "]", ")", ";", "$", "allvalues", "[", "$", "filter", "]", "=", "$", "values", ";", "return", "$", "this", "->", "set_config", "(", "'filtervalues'", ",", "$", "allvalues", ")", ";", "}" ]
Set the values for the specified filter. @param string $filter The filter to set. @param array $values The values to set. @return $this
[ "Set", "the", "values", "for", "the", "specified", "filter", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/tour.php#L744-L749
217,831
moodle/moodle
admin/tool/usertours/classes/tour.php
tour.matches_all_filters
public function matches_all_filters(\context $context) { $filters = helper::get_all_filters(); // All filters must match. // If any one filter fails to match, we return false. foreach ($filters as $filterclass) { if (!$filterclass::filter_matches($this, $context)) { return false; } } return true; }
php
public function matches_all_filters(\context $context) { $filters = helper::get_all_filters(); // All filters must match. // If any one filter fails to match, we return false. foreach ($filters as $filterclass) { if (!$filterclass::filter_matches($this, $context)) { return false; } } return true; }
[ "public", "function", "matches_all_filters", "(", "\\", "context", "$", "context", ")", "{", "$", "filters", "=", "helper", "::", "get_all_filters", "(", ")", ";", "// All filters must match.", "// If any one filter fails to match, we return false.", "foreach", "(", "$", "filters", "as", "$", "filterclass", ")", "{", "if", "(", "!", "$", "filterclass", "::", "filter_matches", "(", "$", "this", ",", "$", "context", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Check whether this tour matches all filters. @param context $context The context to check @return bool
[ "Check", "whether", "this", "tour", "matches", "all", "filters", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/tour.php#L757-L769
217,832
moodle/moodle
admin/tool/generator/classes/course_backend.php
tool_generator_course_backend.create_course
private function create_course() { $this->log('createcourse', $this->shortname); $courserecord = array( 'shortname' => $this->shortname, 'fullname' => $this->fullname, 'numsections' => self::$paramsections[$this->size], 'startdate' => usergetmidnight(time()) ); if (strlen($this->summary) > 0) { $courserecord['summary'] = $this->summary; $courserecord['summary_format'] = $this->summaryformat; } return $this->generator->create_course($courserecord, array('createsections' => true)); }
php
private function create_course() { $this->log('createcourse', $this->shortname); $courserecord = array( 'shortname' => $this->shortname, 'fullname' => $this->fullname, 'numsections' => self::$paramsections[$this->size], 'startdate' => usergetmidnight(time()) ); if (strlen($this->summary) > 0) { $courserecord['summary'] = $this->summary; $courserecord['summary_format'] = $this->summaryformat; } return $this->generator->create_course($courserecord, array('createsections' => true)); }
[ "private", "function", "create_course", "(", ")", "{", "$", "this", "->", "log", "(", "'createcourse'", ",", "$", "this", "->", "shortname", ")", ";", "$", "courserecord", "=", "array", "(", "'shortname'", "=>", "$", "this", "->", "shortname", ",", "'fullname'", "=>", "$", "this", "->", "fullname", ",", "'numsections'", "=>", "self", "::", "$", "paramsections", "[", "$", "this", "->", "size", "]", ",", "'startdate'", "=>", "usergetmidnight", "(", "time", "(", ")", ")", ")", ";", "if", "(", "strlen", "(", "$", "this", "->", "summary", ")", ">", "0", ")", "{", "$", "courserecord", "[", "'summary'", "]", "=", "$", "this", "->", "summary", ";", "$", "courserecord", "[", "'summary_format'", "]", "=", "$", "this", "->", "summaryformat", ";", "}", "return", "$", "this", "->", "generator", "->", "create_course", "(", "$", "courserecord", ",", "array", "(", "'createsections'", "=>", "true", ")", ")", ";", "}" ]
Creates the actual course. @return stdClass Course record
[ "Creates", "the", "actual", "course", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/generator/classes/course_backend.php#L249-L263
217,833
moodle/moodle
admin/tool/generator/classes/course_backend.php
tool_generator_course_backend.create_user_accounts
private function create_user_accounts($first, $last) { global $CFG; $this->log('createaccounts', (object)array('from' => $first, 'to' => $last), true); $count = $last - $first + 1; $done = 0; for ($number = $first; $number <= $last; $number++, $done++) { // Work out username with 6-digit number. $textnumber = (string)$number; while (strlen($textnumber) < 6) { $textnumber = '0' . $textnumber; } $username = 'tool_generator_' . $textnumber; // Create user account. $record = array('username' => $username, 'idnumber' => $number); // We add a user password if it has been specified. if (!empty($CFG->tool_generator_users_password)) { $record['password'] = $CFG->tool_generator_users_password; } $user = $this->generator->create_user($record); $this->userids[$number] = (int)$user->id; $this->dot($done, $count); } $this->end_log(); }
php
private function create_user_accounts($first, $last) { global $CFG; $this->log('createaccounts', (object)array('from' => $first, 'to' => $last), true); $count = $last - $first + 1; $done = 0; for ($number = $first; $number <= $last; $number++, $done++) { // Work out username with 6-digit number. $textnumber = (string)$number; while (strlen($textnumber) < 6) { $textnumber = '0' . $textnumber; } $username = 'tool_generator_' . $textnumber; // Create user account. $record = array('username' => $username, 'idnumber' => $number); // We add a user password if it has been specified. if (!empty($CFG->tool_generator_users_password)) { $record['password'] = $CFG->tool_generator_users_password; } $user = $this->generator->create_user($record); $this->userids[$number] = (int)$user->id; $this->dot($done, $count); } $this->end_log(); }
[ "private", "function", "create_user_accounts", "(", "$", "first", ",", "$", "last", ")", "{", "global", "$", "CFG", ";", "$", "this", "->", "log", "(", "'createaccounts'", ",", "(", "object", ")", "array", "(", "'from'", "=>", "$", "first", ",", "'to'", "=>", "$", "last", ")", ",", "true", ")", ";", "$", "count", "=", "$", "last", "-", "$", "first", "+", "1", ";", "$", "done", "=", "0", ";", "for", "(", "$", "number", "=", "$", "first", ";", "$", "number", "<=", "$", "last", ";", "$", "number", "++", ",", "$", "done", "++", ")", "{", "// Work out username with 6-digit number.", "$", "textnumber", "=", "(", "string", ")", "$", "number", ";", "while", "(", "strlen", "(", "$", "textnumber", ")", "<", "6", ")", "{", "$", "textnumber", "=", "'0'", ".", "$", "textnumber", ";", "}", "$", "username", "=", "'tool_generator_'", ".", "$", "textnumber", ";", "// Create user account.", "$", "record", "=", "array", "(", "'username'", "=>", "$", "username", ",", "'idnumber'", "=>", "$", "number", ")", ";", "// We add a user password if it has been specified.", "if", "(", "!", "empty", "(", "$", "CFG", "->", "tool_generator_users_password", ")", ")", "{", "$", "record", "[", "'password'", "]", "=", "$", "CFG", "->", "tool_generator_users_password", ";", "}", "$", "user", "=", "$", "this", "->", "generator", "->", "create_user", "(", "$", "record", ")", ";", "$", "this", "->", "userids", "[", "$", "number", "]", "=", "(", "int", ")", "$", "user", "->", "id", ";", "$", "this", "->", "dot", "(", "$", "done", ",", "$", "count", ")", ";", "}", "$", "this", "->", "end_log", "(", ")", ";", "}" ]
Creates user accounts with a numeric range. @param int $first Number of first user @param int $last Number of last user
[ "Creates", "user", "accounts", "with", "a", "numeric", "range", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/generator/classes/course_backend.php#L343-L370
217,834
moodle/moodle
admin/tool/generator/classes/course_backend.php
tool_generator_course_backend.create_assignments
private function create_assignments() { // Set up generator. $assigngenerator = $this->generator->get_plugin_generator('mod_assign'); // Create assignments. $number = self::$paramassignments[$this->size]; $this->log('createassignments', $number, true); for ($i = 0; $i < $number; $i++) { $record = array('course' => $this->course); $options = array('section' => $this->get_target_section()); $assigngenerator->create_instance($record, $options); $this->dot($i, $number); } $this->end_log(); }
php
private function create_assignments() { // Set up generator. $assigngenerator = $this->generator->get_plugin_generator('mod_assign'); // Create assignments. $number = self::$paramassignments[$this->size]; $this->log('createassignments', $number, true); for ($i = 0; $i < $number; $i++) { $record = array('course' => $this->course); $options = array('section' => $this->get_target_section()); $assigngenerator->create_instance($record, $options); $this->dot($i, $number); } $this->end_log(); }
[ "private", "function", "create_assignments", "(", ")", "{", "// Set up generator.", "$", "assigngenerator", "=", "$", "this", "->", "generator", "->", "get_plugin_generator", "(", "'mod_assign'", ")", ";", "// Create assignments.", "$", "number", "=", "self", "::", "$", "paramassignments", "[", "$", "this", "->", "size", "]", ";", "$", "this", "->", "log", "(", "'createassignments'", ",", "$", "number", ",", "true", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "number", ";", "$", "i", "++", ")", "{", "$", "record", "=", "array", "(", "'course'", "=>", "$", "this", "->", "course", ")", ";", "$", "options", "=", "array", "(", "'section'", "=>", "$", "this", "->", "get_target_section", "(", ")", ")", ";", "$", "assigngenerator", "->", "create_instance", "(", "$", "record", ",", "$", "options", ")", ";", "$", "this", "->", "dot", "(", "$", "i", ",", "$", "number", ")", ";", "}", "$", "this", "->", "end_log", "(", ")", ";", "}" ]
Creates a number of Assignment activities.
[ "Creates", "a", "number", "of", "Assignment", "activities", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/generator/classes/course_backend.php#L375-L390
217,835
moodle/moodle
admin/tool/generator/classes/course_backend.php
tool_generator_course_backend.create_pages
private function create_pages() { // Set up generator. $pagegenerator = $this->generator->get_plugin_generator('mod_page'); // Create pages. $number = self::$parampages[$this->size]; $this->log('createpages', $number, true); for ($i = 0; $i < $number; $i++) { $record = array('course' => $this->course); $options = array('section' => $this->get_target_section()); $pagegenerator->create_instance($record, $options); $this->dot($i, $number); } $this->end_log(); }
php
private function create_pages() { // Set up generator. $pagegenerator = $this->generator->get_plugin_generator('mod_page'); // Create pages. $number = self::$parampages[$this->size]; $this->log('createpages', $number, true); for ($i = 0; $i < $number; $i++) { $record = array('course' => $this->course); $options = array('section' => $this->get_target_section()); $pagegenerator->create_instance($record, $options); $this->dot($i, $number); } $this->end_log(); }
[ "private", "function", "create_pages", "(", ")", "{", "// Set up generator.", "$", "pagegenerator", "=", "$", "this", "->", "generator", "->", "get_plugin_generator", "(", "'mod_page'", ")", ";", "// Create pages.", "$", "number", "=", "self", "::", "$", "parampages", "[", "$", "this", "->", "size", "]", ";", "$", "this", "->", "log", "(", "'createpages'", ",", "$", "number", ",", "true", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "number", ";", "$", "i", "++", ")", "{", "$", "record", "=", "array", "(", "'course'", "=>", "$", "this", "->", "course", ")", ";", "$", "options", "=", "array", "(", "'section'", "=>", "$", "this", "->", "get_target_section", "(", ")", ")", ";", "$", "pagegenerator", "->", "create_instance", "(", "$", "record", ",", "$", "options", ")", ";", "$", "this", "->", "dot", "(", "$", "i", ",", "$", "number", ")", ";", "}", "$", "this", "->", "end_log", "(", ")", ";", "}" ]
Creates a number of Page activities.
[ "Creates", "a", "number", "of", "Page", "activities", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/generator/classes/course_backend.php#L395-L410
217,836
moodle/moodle
admin/tool/generator/classes/course_backend.php
tool_generator_course_backend.create_small_files
private function create_small_files() { $count = self::$paramsmallfilecount[$this->size]; $this->log('createsmallfiles', $count, true); // Create resource with default textfile only. $resourcegenerator = $this->generator->get_plugin_generator('mod_resource'); $record = array('course' => $this->course, 'name' => get_string('smallfiles', 'tool_generator')); $options = array('section' => 0); $resource = $resourcegenerator->create_instance($record, $options); // Add files. $fs = get_file_storage(); $context = context_module::instance($resource->cmid); $filerecord = array('component' => 'mod_resource', 'filearea' => 'content', 'contextid' => $context->id, 'itemid' => 0, 'filepath' => '/'); for ($i = 0; $i < $count; $i++) { $filerecord['filename'] = 'smallfile' . $i . '.dat'; // Generate random binary data (different for each file so it // doesn't compress unrealistically). $data = random_bytes_emulate($this->limit_filesize(self::$paramsmallfilesize[$this->size])); $fs->create_file_from_string($filerecord, $data); $this->dot($i, $count); } $this->end_log(); }
php
private function create_small_files() { $count = self::$paramsmallfilecount[$this->size]; $this->log('createsmallfiles', $count, true); // Create resource with default textfile only. $resourcegenerator = $this->generator->get_plugin_generator('mod_resource'); $record = array('course' => $this->course, 'name' => get_string('smallfiles', 'tool_generator')); $options = array('section' => 0); $resource = $resourcegenerator->create_instance($record, $options); // Add files. $fs = get_file_storage(); $context = context_module::instance($resource->cmid); $filerecord = array('component' => 'mod_resource', 'filearea' => 'content', 'contextid' => $context->id, 'itemid' => 0, 'filepath' => '/'); for ($i = 0; $i < $count; $i++) { $filerecord['filename'] = 'smallfile' . $i . '.dat'; // Generate random binary data (different for each file so it // doesn't compress unrealistically). $data = random_bytes_emulate($this->limit_filesize(self::$paramsmallfilesize[$this->size])); $fs->create_file_from_string($filerecord, $data); $this->dot($i, $count); } $this->end_log(); }
[ "private", "function", "create_small_files", "(", ")", "{", "$", "count", "=", "self", "::", "$", "paramsmallfilecount", "[", "$", "this", "->", "size", "]", ";", "$", "this", "->", "log", "(", "'createsmallfiles'", ",", "$", "count", ",", "true", ")", ";", "// Create resource with default textfile only.", "$", "resourcegenerator", "=", "$", "this", "->", "generator", "->", "get_plugin_generator", "(", "'mod_resource'", ")", ";", "$", "record", "=", "array", "(", "'course'", "=>", "$", "this", "->", "course", ",", "'name'", "=>", "get_string", "(", "'smallfiles'", ",", "'tool_generator'", ")", ")", ";", "$", "options", "=", "array", "(", "'section'", "=>", "0", ")", ";", "$", "resource", "=", "$", "resourcegenerator", "->", "create_instance", "(", "$", "record", ",", "$", "options", ")", ";", "// Add files.", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "context", "=", "context_module", "::", "instance", "(", "$", "resource", "->", "cmid", ")", ";", "$", "filerecord", "=", "array", "(", "'component'", "=>", "'mod_resource'", ",", "'filearea'", "=>", "'content'", ",", "'contextid'", "=>", "$", "context", "->", "id", ",", "'itemid'", "=>", "0", ",", "'filepath'", "=>", "'/'", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", ";", "$", "i", "++", ")", "{", "$", "filerecord", "[", "'filename'", "]", "=", "'smallfile'", ".", "$", "i", ".", "'.dat'", ";", "// Generate random binary data (different for each file so it", "// doesn't compress unrealistically).", "$", "data", "=", "random_bytes_emulate", "(", "$", "this", "->", "limit_filesize", "(", "self", "::", "$", "paramsmallfilesize", "[", "$", "this", "->", "size", "]", ")", ")", ";", "$", "fs", "->", "create_file_from_string", "(", "$", "filerecord", ",", "$", "data", ")", ";", "$", "this", "->", "dot", "(", "$", "i", ",", "$", "count", ")", ";", "}", "$", "this", "->", "end_log", "(", ")", ";", "}" ]
Creates one resource activity with a lot of small files.
[ "Creates", "one", "resource", "activity", "with", "a", "lot", "of", "small", "files", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/generator/classes/course_backend.php#L415-L443
217,837
moodle/moodle
admin/tool/generator/classes/course_backend.php
tool_generator_course_backend.create_big_files
private function create_big_files() { // Work out how many files and how many blocks to use (up to 64KB). $count = self::$parambigfilecount[$this->size]; $filesize = $this->limit_filesize(self::$parambigfilesize[$this->size]); $blocks = ceil($filesize / 65536); $blocksize = floor($filesize / $blocks); $this->log('createbigfiles', $count, true); // Prepare temp area. $tempfolder = make_temp_directory('tool_generator'); $tempfile = $tempfolder . '/' . rand(); // Create resources and files. $fs = get_file_storage(); $resourcegenerator = $this->generator->get_plugin_generator('mod_resource'); for ($i = 0; $i < $count; $i++) { // Create resource. $record = array('course' => $this->course, 'name' => get_string('bigfile', 'tool_generator', $i)); $options = array('section' => $this->get_target_section()); $resource = $resourcegenerator->create_instance($record, $options); // Write file. $handle = fopen($tempfile, 'w'); if (!$handle) { throw new coding_exception('Failed to open temporary file'); } for ($j = 0; $j < $blocks; $j++) { $data = random_bytes_emulate($blocksize); fwrite($handle, $data); $this->dot($i * $blocks + $j, $count * $blocks); } fclose($handle); // Add file. $context = context_module::instance($resource->cmid); $filerecord = array('component' => 'mod_resource', 'filearea' => 'content', 'contextid' => $context->id, 'itemid' => 0, 'filepath' => '/', 'filename' => 'bigfile' . $i . '.dat'); $fs->create_file_from_pathname($filerecord, $tempfile); } unlink($tempfile); $this->end_log(); }
php
private function create_big_files() { // Work out how many files and how many blocks to use (up to 64KB). $count = self::$parambigfilecount[$this->size]; $filesize = $this->limit_filesize(self::$parambigfilesize[$this->size]); $blocks = ceil($filesize / 65536); $blocksize = floor($filesize / $blocks); $this->log('createbigfiles', $count, true); // Prepare temp area. $tempfolder = make_temp_directory('tool_generator'); $tempfile = $tempfolder . '/' . rand(); // Create resources and files. $fs = get_file_storage(); $resourcegenerator = $this->generator->get_plugin_generator('mod_resource'); for ($i = 0; $i < $count; $i++) { // Create resource. $record = array('course' => $this->course, 'name' => get_string('bigfile', 'tool_generator', $i)); $options = array('section' => $this->get_target_section()); $resource = $resourcegenerator->create_instance($record, $options); // Write file. $handle = fopen($tempfile, 'w'); if (!$handle) { throw new coding_exception('Failed to open temporary file'); } for ($j = 0; $j < $blocks; $j++) { $data = random_bytes_emulate($blocksize); fwrite($handle, $data); $this->dot($i * $blocks + $j, $count * $blocks); } fclose($handle); // Add file. $context = context_module::instance($resource->cmid); $filerecord = array('component' => 'mod_resource', 'filearea' => 'content', 'contextid' => $context->id, 'itemid' => 0, 'filepath' => '/', 'filename' => 'bigfile' . $i . '.dat'); $fs->create_file_from_pathname($filerecord, $tempfile); } unlink($tempfile); $this->end_log(); }
[ "private", "function", "create_big_files", "(", ")", "{", "// Work out how many files and how many blocks to use (up to 64KB).", "$", "count", "=", "self", "::", "$", "parambigfilecount", "[", "$", "this", "->", "size", "]", ";", "$", "filesize", "=", "$", "this", "->", "limit_filesize", "(", "self", "::", "$", "parambigfilesize", "[", "$", "this", "->", "size", "]", ")", ";", "$", "blocks", "=", "ceil", "(", "$", "filesize", "/", "65536", ")", ";", "$", "blocksize", "=", "floor", "(", "$", "filesize", "/", "$", "blocks", ")", ";", "$", "this", "->", "log", "(", "'createbigfiles'", ",", "$", "count", ",", "true", ")", ";", "// Prepare temp area.", "$", "tempfolder", "=", "make_temp_directory", "(", "'tool_generator'", ")", ";", "$", "tempfile", "=", "$", "tempfolder", ".", "'/'", ".", "rand", "(", ")", ";", "// Create resources and files.", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "resourcegenerator", "=", "$", "this", "->", "generator", "->", "get_plugin_generator", "(", "'mod_resource'", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "count", ";", "$", "i", "++", ")", "{", "// Create resource.", "$", "record", "=", "array", "(", "'course'", "=>", "$", "this", "->", "course", ",", "'name'", "=>", "get_string", "(", "'bigfile'", ",", "'tool_generator'", ",", "$", "i", ")", ")", ";", "$", "options", "=", "array", "(", "'section'", "=>", "$", "this", "->", "get_target_section", "(", ")", ")", ";", "$", "resource", "=", "$", "resourcegenerator", "->", "create_instance", "(", "$", "record", ",", "$", "options", ")", ";", "// Write file.", "$", "handle", "=", "fopen", "(", "$", "tempfile", ",", "'w'", ")", ";", "if", "(", "!", "$", "handle", ")", "{", "throw", "new", "coding_exception", "(", "'Failed to open temporary file'", ")", ";", "}", "for", "(", "$", "j", "=", "0", ";", "$", "j", "<", "$", "blocks", ";", "$", "j", "++", ")", "{", "$", "data", "=", "random_bytes_emulate", "(", "$", "blocksize", ")", ";", "fwrite", "(", "$", "handle", ",", "$", "data", ")", ";", "$", "this", "->", "dot", "(", "$", "i", "*", "$", "blocks", "+", "$", "j", ",", "$", "count", "*", "$", "blocks", ")", ";", "}", "fclose", "(", "$", "handle", ")", ";", "// Add file.", "$", "context", "=", "context_module", "::", "instance", "(", "$", "resource", "->", "cmid", ")", ";", "$", "filerecord", "=", "array", "(", "'component'", "=>", "'mod_resource'", ",", "'filearea'", "=>", "'content'", ",", "'contextid'", "=>", "$", "context", "->", "id", ",", "'itemid'", "=>", "0", ",", "'filepath'", "=>", "'/'", ",", "'filename'", "=>", "'bigfile'", ".", "$", "i", ".", "'.dat'", ")", ";", "$", "fs", "->", "create_file_from_pathname", "(", "$", "filerecord", ",", "$", "tempfile", ")", ";", "}", "unlink", "(", "$", "tempfile", ")", ";", "$", "this", "->", "end_log", "(", ")", ";", "}" ]
Creates a number of resource activities with one big file each.
[ "Creates", "a", "number", "of", "resource", "activities", "with", "one", "big", "file", "each", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/generator/classes/course_backend.php#L448-L493
217,838
moodle/moodle
admin/tool/generator/classes/course_backend.php
tool_generator_course_backend.create_forum
private function create_forum() { global $DB; $discussions = self::$paramforumdiscussions[$this->size]; $posts = self::$paramforumposts[$this->size]; $totalposts = $discussions * $posts; $this->log('createforum', $totalposts, true); // Create empty forum. $forumgenerator = $this->generator->get_plugin_generator('mod_forum'); $record = array('course' => $this->course, 'name' => get_string('pluginname', 'forum')); $options = array('section' => 0); $forum = $forumgenerator->create_instance($record, $options); // Add discussions and posts. $sofar = 0; for ($i = 0; $i < $discussions; $i++) { $record = array('forum' => $forum->id, 'course' => $this->course->id, 'userid' => $this->get_target_user()); $discussion = $forumgenerator->create_discussion($record); $parentid = $DB->get_field('forum_posts', 'id', array('discussion' => $discussion->id), MUST_EXIST); $sofar++; for ($j = 0; $j < $posts - 1; $j++, $sofar++) { $record = array('discussion' => $discussion->id, 'userid' => $this->get_target_user(), 'parent' => $parentid); $forumgenerator->create_post($record); $this->dot($sofar, $totalposts); } } $this->end_log(); }
php
private function create_forum() { global $DB; $discussions = self::$paramforumdiscussions[$this->size]; $posts = self::$paramforumposts[$this->size]; $totalposts = $discussions * $posts; $this->log('createforum', $totalposts, true); // Create empty forum. $forumgenerator = $this->generator->get_plugin_generator('mod_forum'); $record = array('course' => $this->course, 'name' => get_string('pluginname', 'forum')); $options = array('section' => 0); $forum = $forumgenerator->create_instance($record, $options); // Add discussions and posts. $sofar = 0; for ($i = 0; $i < $discussions; $i++) { $record = array('forum' => $forum->id, 'course' => $this->course->id, 'userid' => $this->get_target_user()); $discussion = $forumgenerator->create_discussion($record); $parentid = $DB->get_field('forum_posts', 'id', array('discussion' => $discussion->id), MUST_EXIST); $sofar++; for ($j = 0; $j < $posts - 1; $j++, $sofar++) { $record = array('discussion' => $discussion->id, 'userid' => $this->get_target_user(), 'parent' => $parentid); $forumgenerator->create_post($record); $this->dot($sofar, $totalposts); } } $this->end_log(); }
[ "private", "function", "create_forum", "(", ")", "{", "global", "$", "DB", ";", "$", "discussions", "=", "self", "::", "$", "paramforumdiscussions", "[", "$", "this", "->", "size", "]", ";", "$", "posts", "=", "self", "::", "$", "paramforumposts", "[", "$", "this", "->", "size", "]", ";", "$", "totalposts", "=", "$", "discussions", "*", "$", "posts", ";", "$", "this", "->", "log", "(", "'createforum'", ",", "$", "totalposts", ",", "true", ")", ";", "// Create empty forum.", "$", "forumgenerator", "=", "$", "this", "->", "generator", "->", "get_plugin_generator", "(", "'mod_forum'", ")", ";", "$", "record", "=", "array", "(", "'course'", "=>", "$", "this", "->", "course", ",", "'name'", "=>", "get_string", "(", "'pluginname'", ",", "'forum'", ")", ")", ";", "$", "options", "=", "array", "(", "'section'", "=>", "0", ")", ";", "$", "forum", "=", "$", "forumgenerator", "->", "create_instance", "(", "$", "record", ",", "$", "options", ")", ";", "// Add discussions and posts.", "$", "sofar", "=", "0", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "discussions", ";", "$", "i", "++", ")", "{", "$", "record", "=", "array", "(", "'forum'", "=>", "$", "forum", "->", "id", ",", "'course'", "=>", "$", "this", "->", "course", "->", "id", ",", "'userid'", "=>", "$", "this", "->", "get_target_user", "(", ")", ")", ";", "$", "discussion", "=", "$", "forumgenerator", "->", "create_discussion", "(", "$", "record", ")", ";", "$", "parentid", "=", "$", "DB", "->", "get_field", "(", "'forum_posts'", ",", "'id'", ",", "array", "(", "'discussion'", "=>", "$", "discussion", "->", "id", ")", ",", "MUST_EXIST", ")", ";", "$", "sofar", "++", ";", "for", "(", "$", "j", "=", "0", ";", "$", "j", "<", "$", "posts", "-", "1", ";", "$", "j", "++", ",", "$", "sofar", "++", ")", "{", "$", "record", "=", "array", "(", "'discussion'", "=>", "$", "discussion", "->", "id", ",", "'userid'", "=>", "$", "this", "->", "get_target_user", "(", ")", ",", "'parent'", "=>", "$", "parentid", ")", ";", "$", "forumgenerator", "->", "create_post", "(", "$", "record", ")", ";", "$", "this", "->", "dot", "(", "$", "sofar", ",", "$", "totalposts", ")", ";", "}", "}", "$", "this", "->", "end_log", "(", ")", ";", "}" ]
Creates one forum activity with a bunch of posts.
[ "Creates", "one", "forum", "activity", "with", "a", "bunch", "of", "posts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/generator/classes/course_backend.php#L498-L531
217,839
moodle/moodle
admin/tool/generator/classes/course_backend.php
tool_generator_course_backend.get_target_section
private function get_target_section() { if (!$this->fixeddataset) { $key = rand(1, self::$paramsections[$this->size]); } else { // Using section 1. $key = 1; } return $key; }
php
private function get_target_section() { if (!$this->fixeddataset) { $key = rand(1, self::$paramsections[$this->size]); } else { // Using section 1. $key = 1; } return $key; }
[ "private", "function", "get_target_section", "(", ")", "{", "if", "(", "!", "$", "this", "->", "fixeddataset", ")", "{", "$", "key", "=", "rand", "(", "1", ",", "self", "::", "$", "paramsections", "[", "$", "this", "->", "size", "]", ")", ";", "}", "else", "{", "// Using section 1.", "$", "key", "=", "1", ";", "}", "return", "$", "key", ";", "}" ]
Gets a section number. Depends on $this->fixeddataset. @return int A section number from 1 to the number of sections
[ "Gets", "a", "section", "number", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/generator/classes/course_backend.php#L540-L550
217,840
moodle/moodle
admin/tool/generator/classes/course_backend.php
tool_generator_course_backend.get_target_user
private function get_target_user() { if (!$this->fixeddataset) { $userid = $this->userids[rand(1, self::$paramusers[$this->size])]; } else if ($userid = current($this->userids)) { // Moving pointer to the next user. next($this->userids); } else { // Returning to the beginning if we reached the end. $userid = reset($this->userids); } return $userid; }
php
private function get_target_user() { if (!$this->fixeddataset) { $userid = $this->userids[rand(1, self::$paramusers[$this->size])]; } else if ($userid = current($this->userids)) { // Moving pointer to the next user. next($this->userids); } else { // Returning to the beginning if we reached the end. $userid = reset($this->userids); } return $userid; }
[ "private", "function", "get_target_user", "(", ")", "{", "if", "(", "!", "$", "this", "->", "fixeddataset", ")", "{", "$", "userid", "=", "$", "this", "->", "userids", "[", "rand", "(", "1", ",", "self", "::", "$", "paramusers", "[", "$", "this", "->", "size", "]", ")", "]", ";", "}", "else", "if", "(", "$", "userid", "=", "current", "(", "$", "this", "->", "userids", ")", ")", "{", "// Moving pointer to the next user.", "next", "(", "$", "this", "->", "userids", ")", ";", "}", "else", "{", "// Returning to the beginning if we reached the end.", "$", "userid", "=", "reset", "(", "$", "this", "->", "userids", ")", ";", "}", "return", "$", "userid", ";", "}" ]
Gets a user id. Depends on $this->fixeddataset. @return int A user id for a random created user
[ "Gets", "a", "user", "id", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/generator/classes/course_backend.php#L559-L572
217,841
moodle/moodle
admin/tool/generator/classes/course_backend.php
tool_generator_course_backend.limit_filesize
private function limit_filesize($length) { // Limit to $this->filesizelimit. if (is_numeric($this->filesizelimit) && $length > $this->filesizelimit) { $length = floor($this->filesizelimit); } return $length; }
php
private function limit_filesize($length) { // Limit to $this->filesizelimit. if (is_numeric($this->filesizelimit) && $length > $this->filesizelimit) { $length = floor($this->filesizelimit); } return $length; }
[ "private", "function", "limit_filesize", "(", "$", "length", ")", "{", "// Limit to $this->filesizelimit.", "if", "(", "is_numeric", "(", "$", "this", "->", "filesizelimit", ")", "&&", "$", "length", ">", "$", "this", "->", "filesizelimit", ")", "{", "$", "length", "=", "floor", "(", "$", "this", "->", "filesizelimit", ")", ";", "}", "return", "$", "length", ";", "}" ]
Restricts the binary file size if necessary @param int $length The total length @return int The limited length if a limit was specified.
[ "Restricts", "the", "binary", "file", "size", "if", "necessary" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/generator/classes/course_backend.php#L580-L588
217,842
moodle/moodle
lib/horde/framework/Horde/Text/Flowed.php
Horde_Text_Flowed.toFlowed
public function toFlowed($quote = false, array $opts = array()) { $txt = ''; $this->_reformat(true, $quote, empty($opts['nowrap'])); foreach ($this->_output as $line) { $txt .= $line['text'] . "\n"; } return $txt; }
php
public function toFlowed($quote = false, array $opts = array()) { $txt = ''; $this->_reformat(true, $quote, empty($opts['nowrap'])); foreach ($this->_output as $line) { $txt .= $line['text'] . "\n"; } return $txt; }
[ "public", "function", "toFlowed", "(", "$", "quote", "=", "false", ",", "array", "$", "opts", "=", "array", "(", ")", ")", "{", "$", "txt", "=", "''", ";", "$", "this", "->", "_reformat", "(", "true", ",", "$", "quote", ",", "empty", "(", "$", "opts", "[", "'nowrap'", "]", ")", ")", ";", "foreach", "(", "$", "this", "->", "_output", "as", "$", "line", ")", "{", "$", "txt", ".=", "$", "line", "[", "'text'", "]", ".", "\"\\n\"", ";", "}", "return", "$", "txt", ";", "}" ]
Reformats the input string, where the string is 'format=fixed' plain text as described in RFC 2646. @param boolean $quote Add level of quoting to each line? @param array $opts Additional options: <pre> 'nowrap' - (boolean) If true, does not wrap unquoted lines. DEFAULT: false </pre> @return string The text converted to RFC 2646 'flowed' format.
[ "Reformats", "the", "input", "string", "where", "the", "string", "is", "format", "=", "fixed", "plain", "text", "as", "described", "in", "RFC", "2646", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Text/Flowed.php#L169-L179
217,843
moodle/moodle
lib/classes/plugininfo/local.php
local.load_settings
public function load_settings(\part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) { global $CFG, $USER, $DB, $OUTPUT, $PAGE; // In case settings.php wants to refer to them. $ADMIN = $adminroot; // May be used in settings.php. $plugininfo = $this; // Also can be used inside settings.php. if (!$this->is_installed_and_upgraded()) { return; } if (file_exists($this->full_path('settings.php'))) { include($this->full_path('settings.php')); } }
php
public function load_settings(\part_of_admin_tree $adminroot, $parentnodename, $hassiteconfig) { global $CFG, $USER, $DB, $OUTPUT, $PAGE; // In case settings.php wants to refer to them. $ADMIN = $adminroot; // May be used in settings.php. $plugininfo = $this; // Also can be used inside settings.php. if (!$this->is_installed_and_upgraded()) { return; } if (file_exists($this->full_path('settings.php'))) { include($this->full_path('settings.php')); } }
[ "public", "function", "load_settings", "(", "\\", "part_of_admin_tree", "$", "adminroot", ",", "$", "parentnodename", ",", "$", "hassiteconfig", ")", "{", "global", "$", "CFG", ",", "$", "USER", ",", "$", "DB", ",", "$", "OUTPUT", ",", "$", "PAGE", ";", "// In case settings.php wants to refer to them.", "$", "ADMIN", "=", "$", "adminroot", ";", "// May be used in settings.php.", "$", "plugininfo", "=", "$", "this", ";", "// Also can be used inside settings.php.", "if", "(", "!", "$", "this", "->", "is_installed_and_upgraded", "(", ")", ")", "{", "return", ";", "}", "if", "(", "file_exists", "(", "$", "this", "->", "full_path", "(", "'settings.php'", ")", ")", ")", "{", "include", "(", "$", "this", "->", "full_path", "(", "'settings.php'", ")", ")", ";", "}", "}" ]
Loads plugin settings to the settings tree This function usually includes settings.php file in plugins folder. Alternatively it can create a link to some settings page (instance of admin_externalpage) @param \part_of_admin_tree $adminroot @param string $parentnodename @param bool $hassiteconfig whether the current user has moodle/site:config capability
[ "Loads", "plugin", "settings", "to", "the", "settings", "tree" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/plugininfo/local.php#L57-L69
217,844
moodle/moodle
mod/workshop/allocation/scheduled/classes/task/cron_task.php
cron_task.execute
public function execute() { global $CFG, $DB; $sql = "SELECT w.* FROM {workshopallocation_scheduled} a JOIN {workshop} w ON a.workshopid = w.id WHERE a.enabled = 1 AND w.phase = 20 AND w.submissionend > 0 AND w.submissionend < ? AND (a.timeallocated IS NULL OR a.timeallocated < w.submissionend)"; $workshops = $DB->get_records_sql($sql, array(time())); if (empty($workshops)) { mtrace('... no workshops awaiting scheduled allocation. ', ''); return; } mtrace('... executing scheduled allocation in ' . count($workshops) . ' workshop(s) ... ', ''); require_once($CFG->dirroot . '/mod/workshop/locallib.php'); foreach ($workshops as $workshop) { $cm = get_coursemodule_from_instance('workshop', $workshop->id, $workshop->course, false, MUST_EXIST); $course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST); $workshop = new \workshop($workshop, $cm, $course); $allocator = $workshop->allocator_instance('scheduled'); $allocator->execute(); } }
php
public function execute() { global $CFG, $DB; $sql = "SELECT w.* FROM {workshopallocation_scheduled} a JOIN {workshop} w ON a.workshopid = w.id WHERE a.enabled = 1 AND w.phase = 20 AND w.submissionend > 0 AND w.submissionend < ? AND (a.timeallocated IS NULL OR a.timeallocated < w.submissionend)"; $workshops = $DB->get_records_sql($sql, array(time())); if (empty($workshops)) { mtrace('... no workshops awaiting scheduled allocation. ', ''); return; } mtrace('... executing scheduled allocation in ' . count($workshops) . ' workshop(s) ... ', ''); require_once($CFG->dirroot . '/mod/workshop/locallib.php'); foreach ($workshops as $workshop) { $cm = get_coursemodule_from_instance('workshop', $workshop->id, $workshop->course, false, MUST_EXIST); $course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST); $workshop = new \workshop($workshop, $cm, $course); $allocator = $workshop->allocator_instance('scheduled'); $allocator->execute(); } }
[ "public", "function", "execute", "(", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "$", "sql", "=", "\"SELECT w.*\n FROM {workshopallocation_scheduled} a\n JOIN {workshop} w ON a.workshopid = w.id\n WHERE a.enabled = 1\n AND w.phase = 20\n AND w.submissionend > 0\n AND w.submissionend < ?\n AND (a.timeallocated IS NULL OR a.timeallocated < w.submissionend)\"", ";", "$", "workshops", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "array", "(", "time", "(", ")", ")", ")", ";", "if", "(", "empty", "(", "$", "workshops", ")", ")", "{", "mtrace", "(", "'... no workshops awaiting scheduled allocation. '", ",", "''", ")", ";", "return", ";", "}", "mtrace", "(", "'... executing scheduled allocation in '", ".", "count", "(", "$", "workshops", ")", ".", "' workshop(s) ... '", ",", "''", ")", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/mod/workshop/locallib.php'", ")", ";", "foreach", "(", "$", "workshops", "as", "$", "workshop", ")", "{", "$", "cm", "=", "get_coursemodule_from_instance", "(", "'workshop'", ",", "$", "workshop", "->", "id", ",", "$", "workshop", "->", "course", ",", "false", ",", "MUST_EXIST", ")", ";", "$", "course", "=", "$", "DB", "->", "get_record", "(", "'course'", ",", "[", "'id'", "=>", "$", "cm", "->", "course", "]", ",", "'*'", ",", "MUST_EXIST", ")", ";", "$", "workshop", "=", "new", "\\", "workshop", "(", "$", "workshop", ",", "$", "cm", ",", "$", "course", ")", ";", "$", "allocator", "=", "$", "workshop", "->", "allocator_instance", "(", "'scheduled'", ")", ";", "$", "allocator", "->", "execute", "(", ")", ";", "}", "}" ]
Run scheduled allocation cron.
[ "Run", "scheduled", "allocation", "cron", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/allocation/scheduled/classes/task/cron_task.php#L48-L77
217,845
moodle/moodle
lib/horde/framework/Horde/String.php
Horde_String.convertCharset
public static function convertCharset($input, $from, $to, $force = false) { /* Don't bother converting numbers. */ if (is_numeric($input)) { return $input; } /* If the from and to character sets are identical, return now. */ if (!$force && $from == $to) { return $input; } $from = self::lower($from); $to = self::lower($to); if (!$force && $from == $to) { return $input; } if (is_array($input)) { $tmp = array(); foreach ($input as $key => $val) { $tmp[self::_convertCharset($key, $from, $to)] = self::convertCharset($val, $from, $to, $force); } return $tmp; } if (is_object($input)) { // PEAR_Error/Exception objects are almost guaranteed to contain // recursion, which will cause a segfault in PHP. We should never // reach this line, but add a check. if (($input instanceof Exception) || ($input instanceof PEAR_Error)) { return ''; } $input = clone $input; $vars = get_object_vars($input); foreach ($vars as $key => $val) { $input->$key = self::convertCharset($val, $from, $to, $force); } return $input; } if (!is_string($input)) { return $input; } return self::_convertCharset($input, $from, $to); }
php
public static function convertCharset($input, $from, $to, $force = false) { /* Don't bother converting numbers. */ if (is_numeric($input)) { return $input; } /* If the from and to character sets are identical, return now. */ if (!$force && $from == $to) { return $input; } $from = self::lower($from); $to = self::lower($to); if (!$force && $from == $to) { return $input; } if (is_array($input)) { $tmp = array(); foreach ($input as $key => $val) { $tmp[self::_convertCharset($key, $from, $to)] = self::convertCharset($val, $from, $to, $force); } return $tmp; } if (is_object($input)) { // PEAR_Error/Exception objects are almost guaranteed to contain // recursion, which will cause a segfault in PHP. We should never // reach this line, but add a check. if (($input instanceof Exception) || ($input instanceof PEAR_Error)) { return ''; } $input = clone $input; $vars = get_object_vars($input); foreach ($vars as $key => $val) { $input->$key = self::convertCharset($val, $from, $to, $force); } return $input; } if (!is_string($input)) { return $input; } return self::_convertCharset($input, $from, $to); }
[ "public", "static", "function", "convertCharset", "(", "$", "input", ",", "$", "from", ",", "$", "to", ",", "$", "force", "=", "false", ")", "{", "/* Don't bother converting numbers. */", "if", "(", "is_numeric", "(", "$", "input", ")", ")", "{", "return", "$", "input", ";", "}", "/* If the from and to character sets are identical, return now. */", "if", "(", "!", "$", "force", "&&", "$", "from", "==", "$", "to", ")", "{", "return", "$", "input", ";", "}", "$", "from", "=", "self", "::", "lower", "(", "$", "from", ")", ";", "$", "to", "=", "self", "::", "lower", "(", "$", "to", ")", ";", "if", "(", "!", "$", "force", "&&", "$", "from", "==", "$", "to", ")", "{", "return", "$", "input", ";", "}", "if", "(", "is_array", "(", "$", "input", ")", ")", "{", "$", "tmp", "=", "array", "(", ")", ";", "foreach", "(", "$", "input", "as", "$", "key", "=>", "$", "val", ")", "{", "$", "tmp", "[", "self", "::", "_convertCharset", "(", "$", "key", ",", "$", "from", ",", "$", "to", ")", "]", "=", "self", "::", "convertCharset", "(", "$", "val", ",", "$", "from", ",", "$", "to", ",", "$", "force", ")", ";", "}", "return", "$", "tmp", ";", "}", "if", "(", "is_object", "(", "$", "input", ")", ")", "{", "// PEAR_Error/Exception objects are almost guaranteed to contain", "// recursion, which will cause a segfault in PHP. We should never", "// reach this line, but add a check.", "if", "(", "(", "$", "input", "instanceof", "Exception", ")", "||", "(", "$", "input", "instanceof", "PEAR_Error", ")", ")", "{", "return", "''", ";", "}", "$", "input", "=", "clone", "$", "input", ";", "$", "vars", "=", "get_object_vars", "(", "$", "input", ")", ";", "foreach", "(", "$", "vars", "as", "$", "key", "=>", "$", "val", ")", "{", "$", "input", "->", "$", "key", "=", "self", "::", "convertCharset", "(", "$", "val", ",", "$", "from", ",", "$", "to", ",", "$", "force", ")", ";", "}", "return", "$", "input", ";", "}", "if", "(", "!", "is_string", "(", "$", "input", ")", ")", "{", "return", "$", "input", ";", "}", "return", "self", "::", "_convertCharset", "(", "$", "input", ",", "$", "from", ",", "$", "to", ")", ";", "}" ]
Converts a string from one charset to another. Uses the iconv or the mbstring extensions. The original string is returned if conversion failed or none of the extensions were available. @param mixed $input The data to be converted. If $input is an an array, the array's values get converted recursively. @param string $from The string's current charset. @param string $to The charset to convert the string to. @param boolean $force Force conversion? @return mixed The converted input data.
[ "Converts", "a", "string", "from", "one", "charset", "to", "another", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/String.php#L50-L97
217,846
moodle/moodle
lib/horde/framework/Horde/String.php
Horde_String._convertCharset
protected static function _convertCharset($input, $from, $to) { /* Use utf8_[en|de]code() if possible and if the string isn't too * large (less than 16 MB = 16 * 1024 * 1024 = 16777216 bytes) - these * functions use more memory. */ if (Horde_Util::extensionExists('xml') && ((strlen($input) < 16777216) || !Horde_Util::extensionExists('iconv') || !Horde_Util::extensionExists('mbstring'))) { if (($to == 'utf-8') && in_array($from, array('iso-8859-1', 'us-ascii', 'utf-8'))) { return utf8_encode($input); } if (($from == 'utf-8') && in_array($to, array('iso-8859-1', 'us-ascii', 'utf-8'))) { return utf8_decode($input); } } /* Try UTF7-IMAP conversions. */ if (($from == 'utf7-imap') || ($to == 'utf7-imap')) { try { if ($from == 'utf7-imap') { return self::convertCharset(Horde_Imap_Client_Utf7imap::Utf7ImapToUtf8($input), 'UTF-8', $to); } else { if ($from == 'utf-8') { $conv = $input; } else { $conv = self::convertCharset($input, $from, 'UTF-8'); } return Horde_Imap_Client_Utf7imap::Utf8ToUtf7Imap($conv); } } catch (Horde_Imap_Client_Exception $e) { return $input; } } /* Try iconv with transliteration. */ if (Horde_Util::extensionExists('iconv')) { unset($php_errormsg); ini_set('track_errors', 1); $out = @iconv($from, $to . '//TRANSLIT', $input); $errmsg = isset($php_errormsg); ini_restore('track_errors'); if (!$errmsg && $out !== false) { return $out; } } /* Try mbstring. */ if (Horde_Util::extensionExists('mbstring')) { $out = @mb_convert_encoding($input, $to, self::_mbstringCharset($from)); if (!empty($out)) { return $out; } } return $input; }
php
protected static function _convertCharset($input, $from, $to) { /* Use utf8_[en|de]code() if possible and if the string isn't too * large (less than 16 MB = 16 * 1024 * 1024 = 16777216 bytes) - these * functions use more memory. */ if (Horde_Util::extensionExists('xml') && ((strlen($input) < 16777216) || !Horde_Util::extensionExists('iconv') || !Horde_Util::extensionExists('mbstring'))) { if (($to == 'utf-8') && in_array($from, array('iso-8859-1', 'us-ascii', 'utf-8'))) { return utf8_encode($input); } if (($from == 'utf-8') && in_array($to, array('iso-8859-1', 'us-ascii', 'utf-8'))) { return utf8_decode($input); } } /* Try UTF7-IMAP conversions. */ if (($from == 'utf7-imap') || ($to == 'utf7-imap')) { try { if ($from == 'utf7-imap') { return self::convertCharset(Horde_Imap_Client_Utf7imap::Utf7ImapToUtf8($input), 'UTF-8', $to); } else { if ($from == 'utf-8') { $conv = $input; } else { $conv = self::convertCharset($input, $from, 'UTF-8'); } return Horde_Imap_Client_Utf7imap::Utf8ToUtf7Imap($conv); } } catch (Horde_Imap_Client_Exception $e) { return $input; } } /* Try iconv with transliteration. */ if (Horde_Util::extensionExists('iconv')) { unset($php_errormsg); ini_set('track_errors', 1); $out = @iconv($from, $to . '//TRANSLIT', $input); $errmsg = isset($php_errormsg); ini_restore('track_errors'); if (!$errmsg && $out !== false) { return $out; } } /* Try mbstring. */ if (Horde_Util::extensionExists('mbstring')) { $out = @mb_convert_encoding($input, $to, self::_mbstringCharset($from)); if (!empty($out)) { return $out; } } return $input; }
[ "protected", "static", "function", "_convertCharset", "(", "$", "input", ",", "$", "from", ",", "$", "to", ")", "{", "/* Use utf8_[en|de]code() if possible and if the string isn't too\n * large (less than 16 MB = 16 * 1024 * 1024 = 16777216 bytes) - these\n * functions use more memory. */", "if", "(", "Horde_Util", "::", "extensionExists", "(", "'xml'", ")", "&&", "(", "(", "strlen", "(", "$", "input", ")", "<", "16777216", ")", "||", "!", "Horde_Util", "::", "extensionExists", "(", "'iconv'", ")", "||", "!", "Horde_Util", "::", "extensionExists", "(", "'mbstring'", ")", ")", ")", "{", "if", "(", "(", "$", "to", "==", "'utf-8'", ")", "&&", "in_array", "(", "$", "from", ",", "array", "(", "'iso-8859-1'", ",", "'us-ascii'", ",", "'utf-8'", ")", ")", ")", "{", "return", "utf8_encode", "(", "$", "input", ")", ";", "}", "if", "(", "(", "$", "from", "==", "'utf-8'", ")", "&&", "in_array", "(", "$", "to", ",", "array", "(", "'iso-8859-1'", ",", "'us-ascii'", ",", "'utf-8'", ")", ")", ")", "{", "return", "utf8_decode", "(", "$", "input", ")", ";", "}", "}", "/* Try UTF7-IMAP conversions. */", "if", "(", "(", "$", "from", "==", "'utf7-imap'", ")", "||", "(", "$", "to", "==", "'utf7-imap'", ")", ")", "{", "try", "{", "if", "(", "$", "from", "==", "'utf7-imap'", ")", "{", "return", "self", "::", "convertCharset", "(", "Horde_Imap_Client_Utf7imap", "::", "Utf7ImapToUtf8", "(", "$", "input", ")", ",", "'UTF-8'", ",", "$", "to", ")", ";", "}", "else", "{", "if", "(", "$", "from", "==", "'utf-8'", ")", "{", "$", "conv", "=", "$", "input", ";", "}", "else", "{", "$", "conv", "=", "self", "::", "convertCharset", "(", "$", "input", ",", "$", "from", ",", "'UTF-8'", ")", ";", "}", "return", "Horde_Imap_Client_Utf7imap", "::", "Utf8ToUtf7Imap", "(", "$", "conv", ")", ";", "}", "}", "catch", "(", "Horde_Imap_Client_Exception", "$", "e", ")", "{", "return", "$", "input", ";", "}", "}", "/* Try iconv with transliteration. */", "if", "(", "Horde_Util", "::", "extensionExists", "(", "'iconv'", ")", ")", "{", "unset", "(", "$", "php_errormsg", ")", ";", "ini_set", "(", "'track_errors'", ",", "1", ")", ";", "$", "out", "=", "@", "iconv", "(", "$", "from", ",", "$", "to", ".", "'//TRANSLIT'", ",", "$", "input", ")", ";", "$", "errmsg", "=", "isset", "(", "$", "php_errormsg", ")", ";", "ini_restore", "(", "'track_errors'", ")", ";", "if", "(", "!", "$", "errmsg", "&&", "$", "out", "!==", "false", ")", "{", "return", "$", "out", ";", "}", "}", "/* Try mbstring. */", "if", "(", "Horde_Util", "::", "extensionExists", "(", "'mbstring'", ")", ")", "{", "$", "out", "=", "@", "mb_convert_encoding", "(", "$", "input", ",", "$", "to", ",", "self", "::", "_mbstringCharset", "(", "$", "from", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "out", ")", ")", "{", "return", "$", "out", ";", "}", "}", "return", "$", "input", ";", "}" ]
Internal function used to do charset conversion. @param string $input See self::convertCharset(). @param string $from See self::convertCharset(). @param string $to See self::convertCharset(). @return string The converted string.
[ "Internal", "function", "used", "to", "do", "charset", "conversion", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/String.php#L108-L167
217,847
moodle/moodle
lib/horde/framework/Horde/String.php
Horde_String.lower
public static function lower($string, $locale = false, $charset = null) { if ($locale) { if (Horde_Util::extensionExists('mbstring')) { if (is_null($charset)) { throw new InvalidArgumentException('$charset argument must not be null'); } $ret = @mb_strtolower($string, self::_mbstringCharset($charset)); if (!empty($ret)) { return $ret; } } return strtolower($string); } if (!isset(self::$_lowers[$string])) { $language = setlocale(LC_CTYPE, 0); setlocale(LC_CTYPE, 'C'); self::$_lowers[$string] = strtolower($string); setlocale(LC_CTYPE, $language); } return self::$_lowers[$string]; }
php
public static function lower($string, $locale = false, $charset = null) { if ($locale) { if (Horde_Util::extensionExists('mbstring')) { if (is_null($charset)) { throw new InvalidArgumentException('$charset argument must not be null'); } $ret = @mb_strtolower($string, self::_mbstringCharset($charset)); if (!empty($ret)) { return $ret; } } return strtolower($string); } if (!isset(self::$_lowers[$string])) { $language = setlocale(LC_CTYPE, 0); setlocale(LC_CTYPE, 'C'); self::$_lowers[$string] = strtolower($string); setlocale(LC_CTYPE, $language); } return self::$_lowers[$string]; }
[ "public", "static", "function", "lower", "(", "$", "string", ",", "$", "locale", "=", "false", ",", "$", "charset", "=", "null", ")", "{", "if", "(", "$", "locale", ")", "{", "if", "(", "Horde_Util", "::", "extensionExists", "(", "'mbstring'", ")", ")", "{", "if", "(", "is_null", "(", "$", "charset", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'$charset argument must not be null'", ")", ";", "}", "$", "ret", "=", "@", "mb_strtolower", "(", "$", "string", ",", "self", "::", "_mbstringCharset", "(", "$", "charset", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "ret", ")", ")", "{", "return", "$", "ret", ";", "}", "}", "return", "strtolower", "(", "$", "string", ")", ";", "}", "if", "(", "!", "isset", "(", "self", "::", "$", "_lowers", "[", "$", "string", "]", ")", ")", "{", "$", "language", "=", "setlocale", "(", "LC_CTYPE", ",", "0", ")", ";", "setlocale", "(", "LC_CTYPE", ",", "'C'", ")", ";", "self", "::", "$", "_lowers", "[", "$", "string", "]", "=", "strtolower", "(", "$", "string", ")", ";", "setlocale", "(", "LC_CTYPE", ",", "$", "language", ")", ";", "}", "return", "self", "::", "$", "_lowers", "[", "$", "string", "]", ";", "}" ]
Makes a string lowercase. @param string $string The string to be converted. @param boolean $locale If true the string will be converted based on a given charset, locale independent else. @param string $charset If $locale is true, the charset to use when converting. @return string The string with lowercase characters.
[ "Makes", "a", "string", "lowercase", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/String.php#L180-L203
217,848
moodle/moodle
lib/horde/framework/Horde/String.php
Horde_String.upper
public static function upper($string, $locale = false, $charset = null) { if ($locale) { if (Horde_Util::extensionExists('mbstring')) { if (is_null($charset)) { throw new InvalidArgumentException('$charset argument must not be null'); } $ret = @mb_strtoupper($string, self::_mbstringCharset($charset)); if (!empty($ret)) { return $ret; } } return strtoupper($string); } if (!isset(self::$_uppers[$string])) { $language = setlocale(LC_CTYPE, 0); setlocale(LC_CTYPE, 'C'); self::$_uppers[$string] = strtoupper($string); setlocale(LC_CTYPE, $language); } return self::$_uppers[$string]; }
php
public static function upper($string, $locale = false, $charset = null) { if ($locale) { if (Horde_Util::extensionExists('mbstring')) { if (is_null($charset)) { throw new InvalidArgumentException('$charset argument must not be null'); } $ret = @mb_strtoupper($string, self::_mbstringCharset($charset)); if (!empty($ret)) { return $ret; } } return strtoupper($string); } if (!isset(self::$_uppers[$string])) { $language = setlocale(LC_CTYPE, 0); setlocale(LC_CTYPE, 'C'); self::$_uppers[$string] = strtoupper($string); setlocale(LC_CTYPE, $language); } return self::$_uppers[$string]; }
[ "public", "static", "function", "upper", "(", "$", "string", ",", "$", "locale", "=", "false", ",", "$", "charset", "=", "null", ")", "{", "if", "(", "$", "locale", ")", "{", "if", "(", "Horde_Util", "::", "extensionExists", "(", "'mbstring'", ")", ")", "{", "if", "(", "is_null", "(", "$", "charset", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'$charset argument must not be null'", ")", ";", "}", "$", "ret", "=", "@", "mb_strtoupper", "(", "$", "string", ",", "self", "::", "_mbstringCharset", "(", "$", "charset", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "ret", ")", ")", "{", "return", "$", "ret", ";", "}", "}", "return", "strtoupper", "(", "$", "string", ")", ";", "}", "if", "(", "!", "isset", "(", "self", "::", "$", "_uppers", "[", "$", "string", "]", ")", ")", "{", "$", "language", "=", "setlocale", "(", "LC_CTYPE", ",", "0", ")", ";", "setlocale", "(", "LC_CTYPE", ",", "'C'", ")", ";", "self", "::", "$", "_uppers", "[", "$", "string", "]", "=", "strtoupper", "(", "$", "string", ")", ";", "setlocale", "(", "LC_CTYPE", ",", "$", "language", ")", ";", "}", "return", "self", "::", "$", "_uppers", "[", "$", "string", "]", ";", "}" ]
Makes a string uppercase. @param string $string The string to be converted. @param boolean $locale If true the string will be converted based on a given charset, locale independent else. @param string $charset If $locale is true, the charset to use when converting. If not provided the current charset. @return string The string with uppercase characters.
[ "Makes", "a", "string", "uppercase", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/String.php#L216-L239
217,849
moodle/moodle
lib/horde/framework/Horde/String.php
Horde_String.ucfirst
public static function ucfirst($string, $locale = false, $charset = null) { if ($locale) { if (is_null($charset)) { throw new InvalidArgumentException('$charset argument must not be null'); } $first = self::substr($string, 0, 1, $charset); if (self::isAlpha($first, $charset)) { $string = self::upper($first, true, $charset) . self::substr($string, 1, null, $charset); } } else { $string = self::upper(substr($string, 0, 1), false) . substr($string, 1); } return $string; }
php
public static function ucfirst($string, $locale = false, $charset = null) { if ($locale) { if (is_null($charset)) { throw new InvalidArgumentException('$charset argument must not be null'); } $first = self::substr($string, 0, 1, $charset); if (self::isAlpha($first, $charset)) { $string = self::upper($first, true, $charset) . self::substr($string, 1, null, $charset); } } else { $string = self::upper(substr($string, 0, 1), false) . substr($string, 1); } return $string; }
[ "public", "static", "function", "ucfirst", "(", "$", "string", ",", "$", "locale", "=", "false", ",", "$", "charset", "=", "null", ")", "{", "if", "(", "$", "locale", ")", "{", "if", "(", "is_null", "(", "$", "charset", ")", ")", "{", "throw", "new", "InvalidArgumentException", "(", "'$charset argument must not be null'", ")", ";", "}", "$", "first", "=", "self", "::", "substr", "(", "$", "string", ",", "0", ",", "1", ",", "$", "charset", ")", ";", "if", "(", "self", "::", "isAlpha", "(", "$", "first", ",", "$", "charset", ")", ")", "{", "$", "string", "=", "self", "::", "upper", "(", "$", "first", ",", "true", ",", "$", "charset", ")", ".", "self", "::", "substr", "(", "$", "string", ",", "1", ",", "null", ",", "$", "charset", ")", ";", "}", "}", "else", "{", "$", "string", "=", "self", "::", "upper", "(", "substr", "(", "$", "string", ",", "0", ",", "1", ")", ",", "false", ")", ".", "substr", "(", "$", "string", ",", "1", ")", ";", "}", "return", "$", "string", ";", "}" ]
Returns a string with the first letter capitalized if it is alphabetic. @param string $string The string to be capitalized. @param boolean $locale If true the string will be converted based on a given charset, locale independent else. @param string $charset The charset to use, defaults to current charset. @return string The capitalized string.
[ "Returns", "a", "string", "with", "the", "first", "letter", "capitalized", "if", "it", "is", "alphabetic", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/String.php#L252-L267
217,850
moodle/moodle
lib/horde/framework/Horde/String.php
Horde_String.ucwords
public static function ucwords($string, $locale = false, $charset = null) { $words = preg_split('/(\s+)/', $string, -1, PREG_SPLIT_DELIM_CAPTURE); for ($i = 0, $c = count($words); $i < $c; $i += 2) { $words[$i] = self::ucfirst($words[$i], $locale, $charset); } return implode('', $words); }
php
public static function ucwords($string, $locale = false, $charset = null) { $words = preg_split('/(\s+)/', $string, -1, PREG_SPLIT_DELIM_CAPTURE); for ($i = 0, $c = count($words); $i < $c; $i += 2) { $words[$i] = self::ucfirst($words[$i], $locale, $charset); } return implode('', $words); }
[ "public", "static", "function", "ucwords", "(", "$", "string", ",", "$", "locale", "=", "false", ",", "$", "charset", "=", "null", ")", "{", "$", "words", "=", "preg_split", "(", "'/(\\s+)/'", ",", "$", "string", ",", "-", "1", ",", "PREG_SPLIT_DELIM_CAPTURE", ")", ";", "for", "(", "$", "i", "=", "0", ",", "$", "c", "=", "count", "(", "$", "words", ")", ";", "$", "i", "<", "$", "c", ";", "$", "i", "+=", "2", ")", "{", "$", "words", "[", "$", "i", "]", "=", "self", "::", "ucfirst", "(", "$", "words", "[", "$", "i", "]", ",", "$", "locale", ",", "$", "charset", ")", ";", "}", "return", "implode", "(", "''", ",", "$", "words", ")", ";", "}" ]
Returns a string with the first letter of each word capitalized if it is alphabetic. Sentences are splitted into words at whitestrings. @param string $string The string to be capitalized. @param boolean $locale If true the string will be converted based on a given charset, locale independent else. @param string $charset The charset to use, defaults to current charset. @return string The capitalized string.
[ "Returns", "a", "string", "with", "the", "first", "letter", "of", "each", "word", "capitalized", "if", "it", "is", "alphabetic", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/String.php#L282-L289
217,851
moodle/moodle
lib/horde/framework/Horde/String.php
Horde_String._pos
protected static function _pos( $haystack, $needle, $offset, $charset, $func ) { if (Horde_Util::extensionExists('mbstring')) { unset($php_errormsg); $track_errors = ini_set('track_errors', 1); $ret = @call_user_func('mb_' . $func, $haystack, $needle, $offset, self::_mbstringCharset($charset)); ini_set('track_errors', $track_errors); if (!isset($php_errormsg)) { return $ret; } } if (Horde_Util::extensionExists('intl')) { unset($php_errormsg); $track_errors = ini_set('track_errors', 1); $ret = self::convertCharset( @call_user_func( 'grapheme_' . $func, self::convertCharset($haystack, $charset, 'UTF-8'), self::convertCharset($needle, $charset, 'UTF-8'), $offset ), 'UTF-8', $charset ); ini_set('track_errors', $track_errors); if (!isset($php_errormsg)) { return $ret; } } return $func($haystack, $needle, $offset); }
php
protected static function _pos( $haystack, $needle, $offset, $charset, $func ) { if (Horde_Util::extensionExists('mbstring')) { unset($php_errormsg); $track_errors = ini_set('track_errors', 1); $ret = @call_user_func('mb_' . $func, $haystack, $needle, $offset, self::_mbstringCharset($charset)); ini_set('track_errors', $track_errors); if (!isset($php_errormsg)) { return $ret; } } if (Horde_Util::extensionExists('intl')) { unset($php_errormsg); $track_errors = ini_set('track_errors', 1); $ret = self::convertCharset( @call_user_func( 'grapheme_' . $func, self::convertCharset($haystack, $charset, 'UTF-8'), self::convertCharset($needle, $charset, 'UTF-8'), $offset ), 'UTF-8', $charset ); ini_set('track_errors', $track_errors); if (!isset($php_errormsg)) { return $ret; } } return $func($haystack, $needle, $offset); }
[ "protected", "static", "function", "_pos", "(", "$", "haystack", ",", "$", "needle", ",", "$", "offset", ",", "$", "charset", ",", "$", "func", ")", "{", "if", "(", "Horde_Util", "::", "extensionExists", "(", "'mbstring'", ")", ")", "{", "unset", "(", "$", "php_errormsg", ")", ";", "$", "track_errors", "=", "ini_set", "(", "'track_errors'", ",", "1", ")", ";", "$", "ret", "=", "@", "call_user_func", "(", "'mb_'", ".", "$", "func", ",", "$", "haystack", ",", "$", "needle", ",", "$", "offset", ",", "self", "::", "_mbstringCharset", "(", "$", "charset", ")", ")", ";", "ini_set", "(", "'track_errors'", ",", "$", "track_errors", ")", ";", "if", "(", "!", "isset", "(", "$", "php_errormsg", ")", ")", "{", "return", "$", "ret", ";", "}", "}", "if", "(", "Horde_Util", "::", "extensionExists", "(", "'intl'", ")", ")", "{", "unset", "(", "$", "php_errormsg", ")", ";", "$", "track_errors", "=", "ini_set", "(", "'track_errors'", ",", "1", ")", ";", "$", "ret", "=", "self", "::", "convertCharset", "(", "@", "call_user_func", "(", "'grapheme_'", ".", "$", "func", ",", "self", "::", "convertCharset", "(", "$", "haystack", ",", "$", "charset", ",", "'UTF-8'", ")", ",", "self", "::", "convertCharset", "(", "$", "needle", ",", "$", "charset", ",", "'UTF-8'", ")", ",", "$", "offset", ")", ",", "'UTF-8'", ",", "$", "charset", ")", ";", "ini_set", "(", "'track_errors'", ",", "$", "track_errors", ")", ";", "if", "(", "!", "isset", "(", "$", "php_errormsg", ")", ")", "{", "return", "$", "ret", ";", "}", "}", "return", "$", "func", "(", "$", "haystack", ",", "$", "needle", ",", "$", "offset", ")", ";", "}" ]
Perform string position searches. @param string $haystack The string to search through. @param string $needle The string to search for. @param integer $offset Character in $haystack to start searching at. @param string $charset Charset of $needle. @param string $func Function to use. @return integer The position of occurrence.
[ "Perform", "string", "position", "searches", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/String.php#L482-L516
217,852
moodle/moodle
lib/horde/framework/Horde/String.php
Horde_String.truncate
public static function truncate($text, $length = 100) { return (self::length($text) > $length) ? rtrim(self::substr($text, 0, $length - 3)) . '...' : $text; }
php
public static function truncate($text, $length = 100) { return (self::length($text) > $length) ? rtrim(self::substr($text, 0, $length - 3)) . '...' : $text; }
[ "public", "static", "function", "truncate", "(", "$", "text", ",", "$", "length", "=", "100", ")", "{", "return", "(", "self", "::", "length", "(", "$", "text", ")", ">", "$", "length", ")", "?", "rtrim", "(", "self", "::", "substr", "(", "$", "text", ",", "0", ",", "$", "length", "-", "3", ")", ")", ".", "'...'", ":", "$", "text", ";", "}" ]
Return a truncated string, suitable for notifications. @param string $text The original string. @param integer $length The maximum length. @return string The truncated string, if longer than $length.
[ "Return", "a", "truncated", "string", "suitable", "for", "notifications", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/String.php#L689-L694
217,853
moodle/moodle
lib/horde/framework/Horde/String.php
Horde_String.abbreviate
public static function abbreviate($text, $length = 20) { return (self::length($text) > $length) ? rtrim(self::substr($text, 0, round(($length - 3) / 2))) . '...' . ltrim(self::substr($text, (($length - 3) / 2) * -1)) : $text; }
php
public static function abbreviate($text, $length = 20) { return (self::length($text) > $length) ? rtrim(self::substr($text, 0, round(($length - 3) / 2))) . '...' . ltrim(self::substr($text, (($length - 3) / 2) * -1)) : $text; }
[ "public", "static", "function", "abbreviate", "(", "$", "text", ",", "$", "length", "=", "20", ")", "{", "return", "(", "self", "::", "length", "(", "$", "text", ")", ">", "$", "length", ")", "?", "rtrim", "(", "self", "::", "substr", "(", "$", "text", ",", "0", ",", "round", "(", "(", "$", "length", "-", "3", ")", "/", "2", ")", ")", ")", ".", "'...'", ".", "ltrim", "(", "self", "::", "substr", "(", "$", "text", ",", "(", "(", "$", "length", "-", "3", ")", "/", "2", ")", "*", "-", "1", ")", ")", ":", "$", "text", ";", "}" ]
Return an abbreviated string, with characters in the middle of the excessively long string replaced by '...'. @param string $text The original string. @param integer $length The length at which to abbreviate. @return string The abbreviated string, if longer than $length.
[ "Return", "an", "abbreviated", "string", "with", "characters", "in", "the", "middle", "of", "the", "excessively", "long", "string", "replaced", "by", "...", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/String.php#L705-L710
217,854
moodle/moodle
lib/horde/framework/Horde/String.php
Horde_String.common
public static function common($str1, $str2) { for ($result = '', $i = 0; isset($str1[$i]) && isset($str2[$i]) && $str1[$i] == $str2[$i]; $i++) { $result .= $str1[$i]; } return $result; }
php
public static function common($str1, $str2) { for ($result = '', $i = 0; isset($str1[$i]) && isset($str2[$i]) && $str1[$i] == $str2[$i]; $i++) { $result .= $str1[$i]; } return $result; }
[ "public", "static", "function", "common", "(", "$", "str1", ",", "$", "str2", ")", "{", "for", "(", "$", "result", "=", "''", ",", "$", "i", "=", "0", ";", "isset", "(", "$", "str1", "[", "$", "i", "]", ")", "&&", "isset", "(", "$", "str2", "[", "$", "i", "]", ")", "&&", "$", "str1", "[", "$", "i", "]", "==", "$", "str2", "[", "$", "i", "]", ";", "$", "i", "++", ")", "{", "$", "result", ".=", "$", "str1", "[", "$", "i", "]", ";", "}", "return", "$", "result", ";", "}" ]
Returns the common leading part of two strings. @param string $str1 A string. @param string $str2 Another string. @return string The start of $str1 and $str2 that is identical in both.
[ "Returns", "the", "common", "leading", "part", "of", "two", "strings", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/String.php#L720-L728
217,855
moodle/moodle
lib/horde/framework/Horde/String.php
Horde_String.isAlpha
public static function isAlpha($string, $charset) { if (!Horde_Util::extensionExists('mbstring')) { return ctype_alpha($string); } $charset = self::_mbstringCharset($charset); $old_charset = mb_regex_encoding(); if ($charset != $old_charset) { @mb_regex_encoding($charset); } $alpha = !@mb_ereg_match('[^[:alpha:]]', $string); if ($charset != $old_charset) { @mb_regex_encoding($old_charset); } return $alpha; }
php
public static function isAlpha($string, $charset) { if (!Horde_Util::extensionExists('mbstring')) { return ctype_alpha($string); } $charset = self::_mbstringCharset($charset); $old_charset = mb_regex_encoding(); if ($charset != $old_charset) { @mb_regex_encoding($charset); } $alpha = !@mb_ereg_match('[^[:alpha:]]', $string); if ($charset != $old_charset) { @mb_regex_encoding($old_charset); } return $alpha; }
[ "public", "static", "function", "isAlpha", "(", "$", "string", ",", "$", "charset", ")", "{", "if", "(", "!", "Horde_Util", "::", "extensionExists", "(", "'mbstring'", ")", ")", "{", "return", "ctype_alpha", "(", "$", "string", ")", ";", "}", "$", "charset", "=", "self", "::", "_mbstringCharset", "(", "$", "charset", ")", ";", "$", "old_charset", "=", "mb_regex_encoding", "(", ")", ";", "if", "(", "$", "charset", "!=", "$", "old_charset", ")", "{", "@", "mb_regex_encoding", "(", "$", "charset", ")", ";", "}", "$", "alpha", "=", "!", "@", "mb_ereg_match", "(", "'[^[:alpha:]]'", ",", "$", "string", ")", ";", "if", "(", "$", "charset", "!=", "$", "old_charset", ")", "{", "@", "mb_regex_encoding", "(", "$", "old_charset", ")", ";", "}", "return", "$", "alpha", ";", "}" ]
Returns true if the every character in the parameter is an alphabetic character. @param string $string The string to test. @param string $charset The charset to use when testing the string. @return boolean True if the parameter was alphabetic only.
[ "Returns", "true", "if", "the", "every", "character", "in", "the", "parameter", "is", "an", "alphabetic", "character", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/String.php#L739-L757
217,856
moodle/moodle
lib/horde/framework/Horde/String.php
Horde_String.isLower
public static function isLower($string, $charset) { return ((self::lower($string, true, $charset) === $string) && self::isAlpha($string, $charset)); }
php
public static function isLower($string, $charset) { return ((self::lower($string, true, $charset) === $string) && self::isAlpha($string, $charset)); }
[ "public", "static", "function", "isLower", "(", "$", "string", ",", "$", "charset", ")", "{", "return", "(", "(", "self", "::", "lower", "(", "$", "string", ",", "true", ",", "$", "charset", ")", "===", "$", "string", ")", "&&", "self", "::", "isAlpha", "(", "$", "string", ",", "$", "charset", ")", ")", ";", "}" ]
Returns true if ever character in the parameter is a lowercase letter in the current locale. @param string $string The string to test. @param string $charset The charset to use when testing the string. @return boolean True if the parameter was lowercase.
[ "Returns", "true", "if", "ever", "character", "in", "the", "parameter", "is", "a", "lowercase", "letter", "in", "the", "current", "locale", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/String.php#L768-L772
217,857
moodle/moodle
lib/horde/framework/Horde/String.php
Horde_String.isUpper
public static function isUpper($string, $charset) { return ((self::upper($string, true, $charset) === $string) && self::isAlpha($string, $charset)); }
php
public static function isUpper($string, $charset) { return ((self::upper($string, true, $charset) === $string) && self::isAlpha($string, $charset)); }
[ "public", "static", "function", "isUpper", "(", "$", "string", ",", "$", "charset", ")", "{", "return", "(", "(", "self", "::", "upper", "(", "$", "string", ",", "true", ",", "$", "charset", ")", "===", "$", "string", ")", "&&", "self", "::", "isAlpha", "(", "$", "string", ",", "$", "charset", ")", ")", ";", "}" ]
Returns true if every character in the parameter is an uppercase letter in the current locale. @param string $string The string to test. @param string $charset The charset to use when testing the string. @return boolean True if the parameter was uppercase.
[ "Returns", "true", "if", "every", "character", "in", "the", "parameter", "is", "an", "uppercase", "letter", "in", "the", "current", "locale", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/String.php#L783-L787
217,858
moodle/moodle
lib/horde/framework/Horde/String.php
Horde_String.regexMatch
public static function regexMatch($text, $regex, $charset = null) { if (!empty($charset)) { $regex = self::convertCharset($regex, $charset, 'utf-8'); $text = self::convertCharset($text, $charset, 'utf-8'); } $matches = array(); foreach ($regex as $val) { if (preg_match('/' . $val . '/u', $text, $matches)) { break; } } if (!empty($charset)) { $matches = self::convertCharset($matches, 'utf-8', $charset); } return $matches; }
php
public static function regexMatch($text, $regex, $charset = null) { if (!empty($charset)) { $regex = self::convertCharset($regex, $charset, 'utf-8'); $text = self::convertCharset($text, $charset, 'utf-8'); } $matches = array(); foreach ($regex as $val) { if (preg_match('/' . $val . '/u', $text, $matches)) { break; } } if (!empty($charset)) { $matches = self::convertCharset($matches, 'utf-8', $charset); } return $matches; }
[ "public", "static", "function", "regexMatch", "(", "$", "text", ",", "$", "regex", ",", "$", "charset", "=", "null", ")", "{", "if", "(", "!", "empty", "(", "$", "charset", ")", ")", "{", "$", "regex", "=", "self", "::", "convertCharset", "(", "$", "regex", ",", "$", "charset", ",", "'utf-8'", ")", ";", "$", "text", "=", "self", "::", "convertCharset", "(", "$", "text", ",", "$", "charset", ",", "'utf-8'", ")", ";", "}", "$", "matches", "=", "array", "(", ")", ";", "foreach", "(", "$", "regex", "as", "$", "val", ")", "{", "if", "(", "preg_match", "(", "'/'", ".", "$", "val", ".", "'/u'", ",", "$", "text", ",", "$", "matches", ")", ")", "{", "break", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "charset", ")", ")", "{", "$", "matches", "=", "self", "::", "convertCharset", "(", "$", "matches", ",", "'utf-8'", ",", "$", "charset", ")", ";", "}", "return", "$", "matches", ";", "}" ]
Performs a multibyte safe regex match search on the text provided. @param string $text The text to search. @param array $regex The regular expressions to use, without perl regex delimiters (e.g. '/' or '|'). @param string $charset The character set of the text. @return array The matches array from the first regex that matches.
[ "Performs", "a", "multibyte", "safe", "regex", "match", "search", "on", "the", "text", "provided", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/String.php#L799-L818
217,859
moodle/moodle
lib/horde/framework/Horde/String.php
Horde_String.validUtf8
public static function validUtf8($text) { $text = strval($text); // First check for illegal surrogate pair sequences. See RFC 3629. if (preg_match('/\xE0[\x80-\x9F][\x80-\xBF]|\xED[\xA0-\xBF][\x80-\xBF]/S', $text)) { return false; } for ($i = 0, $len = strlen($text); $i < $len; ++$i) { $c = ord($text[$i]); if ($c > 128) { if ($c > 247) { // STD 63 (RFC 3629) eliminates 5 & 6-byte characters. return false; } elseif ($c > 239) { $j = 3; } elseif ($c > 223) { $j = 2; } elseif ($c > 191) { $j = 1; } else { return false; } if (($i + $j) > $len) { return false; } do { $c = ord($text[++$i]); if (($c < 128) || ($c > 191)) { return false; } } while (--$j); } } return true; }
php
public static function validUtf8($text) { $text = strval($text); // First check for illegal surrogate pair sequences. See RFC 3629. if (preg_match('/\xE0[\x80-\x9F][\x80-\xBF]|\xED[\xA0-\xBF][\x80-\xBF]/S', $text)) { return false; } for ($i = 0, $len = strlen($text); $i < $len; ++$i) { $c = ord($text[$i]); if ($c > 128) { if ($c > 247) { // STD 63 (RFC 3629) eliminates 5 & 6-byte characters. return false; } elseif ($c > 239) { $j = 3; } elseif ($c > 223) { $j = 2; } elseif ($c > 191) { $j = 1; } else { return false; } if (($i + $j) > $len) { return false; } do { $c = ord($text[++$i]); if (($c < 128) || ($c > 191)) { return false; } } while (--$j); } } return true; }
[ "public", "static", "function", "validUtf8", "(", "$", "text", ")", "{", "$", "text", "=", "strval", "(", "$", "text", ")", ";", "// First check for illegal surrogate pair sequences. See RFC 3629.", "if", "(", "preg_match", "(", "'/\\xE0[\\x80-\\x9F][\\x80-\\xBF]|\\xED[\\xA0-\\xBF][\\x80-\\xBF]/S'", ",", "$", "text", ")", ")", "{", "return", "false", ";", "}", "for", "(", "$", "i", "=", "0", ",", "$", "len", "=", "strlen", "(", "$", "text", ")", ";", "$", "i", "<", "$", "len", ";", "++", "$", "i", ")", "{", "$", "c", "=", "ord", "(", "$", "text", "[", "$", "i", "]", ")", ";", "if", "(", "$", "c", ">", "128", ")", "{", "if", "(", "$", "c", ">", "247", ")", "{", "// STD 63 (RFC 3629) eliminates 5 & 6-byte characters.", "return", "false", ";", "}", "elseif", "(", "$", "c", ">", "239", ")", "{", "$", "j", "=", "3", ";", "}", "elseif", "(", "$", "c", ">", "223", ")", "{", "$", "j", "=", "2", ";", "}", "elseif", "(", "$", "c", ">", "191", ")", "{", "$", "j", "=", "1", ";", "}", "else", "{", "return", "false", ";", "}", "if", "(", "(", "$", "i", "+", "$", "j", ")", ">", "$", "len", ")", "{", "return", "false", ";", "}", "do", "{", "$", "c", "=", "ord", "(", "$", "text", "[", "++", "$", "i", "]", ")", ";", "if", "(", "(", "$", "c", "<", "128", ")", "||", "(", "$", "c", ">", "191", ")", ")", "{", "return", "false", ";", "}", "}", "while", "(", "--", "$", "j", ")", ";", "}", "}", "return", "true", ";", "}" ]
Check to see if a string is valid UTF-8. @param string $text The text to check. @return boolean True if valid UTF-8.
[ "Check", "to", "see", "if", "a", "string", "is", "valid", "UTF", "-", "8", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/String.php#L827-L866
217,860
moodle/moodle
enrol/self/externallib.php
enrol_self_external.get_instance_info
public static function get_instance_info($instanceid) { global $DB, $CFG; require_once($CFG->libdir . '/enrollib.php'); $params = self::validate_parameters(self::get_instance_info_parameters(), array('instanceid' => $instanceid)); // Retrieve self enrolment plugin. $enrolplugin = enrol_get_plugin('self'); if (empty($enrolplugin)) { throw new moodle_exception('invaliddata', 'error'); } self::validate_context(context_system::instance()); $enrolinstance = $DB->get_record('enrol', array('id' => $params['instanceid']), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $enrolinstance->courseid), '*', MUST_EXIST); if (!core_course_category::can_view_course_info($course) && !can_access_course($course)) { throw new moodle_exception('coursehidden'); } $instanceinfo = (array) $enrolplugin->get_enrol_info($enrolinstance); if (isset($instanceinfo['requiredparam']->enrolpassword)) { $instanceinfo['enrolpassword'] = $instanceinfo['requiredparam']->enrolpassword; } unset($instanceinfo->requiredparam); return $instanceinfo; }
php
public static function get_instance_info($instanceid) { global $DB, $CFG; require_once($CFG->libdir . '/enrollib.php'); $params = self::validate_parameters(self::get_instance_info_parameters(), array('instanceid' => $instanceid)); // Retrieve self enrolment plugin. $enrolplugin = enrol_get_plugin('self'); if (empty($enrolplugin)) { throw new moodle_exception('invaliddata', 'error'); } self::validate_context(context_system::instance()); $enrolinstance = $DB->get_record('enrol', array('id' => $params['instanceid']), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $enrolinstance->courseid), '*', MUST_EXIST); if (!core_course_category::can_view_course_info($course) && !can_access_course($course)) { throw new moodle_exception('coursehidden'); } $instanceinfo = (array) $enrolplugin->get_enrol_info($enrolinstance); if (isset($instanceinfo['requiredparam']->enrolpassword)) { $instanceinfo['enrolpassword'] = $instanceinfo['requiredparam']->enrolpassword; } unset($instanceinfo->requiredparam); return $instanceinfo; }
[ "public", "static", "function", "get_instance_info", "(", "$", "instanceid", ")", "{", "global", "$", "DB", ",", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/enrollib.php'", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_instance_info_parameters", "(", ")", ",", "array", "(", "'instanceid'", "=>", "$", "instanceid", ")", ")", ";", "// Retrieve self enrolment plugin.", "$", "enrolplugin", "=", "enrol_get_plugin", "(", "'self'", ")", ";", "if", "(", "empty", "(", "$", "enrolplugin", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'invaliddata'", ",", "'error'", ")", ";", "}", "self", "::", "validate_context", "(", "context_system", "::", "instance", "(", ")", ")", ";", "$", "enrolinstance", "=", "$", "DB", "->", "get_record", "(", "'enrol'", ",", "array", "(", "'id'", "=>", "$", "params", "[", "'instanceid'", "]", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "$", "course", "=", "$", "DB", "->", "get_record", "(", "'course'", ",", "array", "(", "'id'", "=>", "$", "enrolinstance", "->", "courseid", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "if", "(", "!", "core_course_category", "::", "can_view_course_info", "(", "$", "course", ")", "&&", "!", "can_access_course", "(", "$", "course", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'coursehidden'", ")", ";", "}", "$", "instanceinfo", "=", "(", "array", ")", "$", "enrolplugin", "->", "get_enrol_info", "(", "$", "enrolinstance", ")", ";", "if", "(", "isset", "(", "$", "instanceinfo", "[", "'requiredparam'", "]", "->", "enrolpassword", ")", ")", "{", "$", "instanceinfo", "[", "'enrolpassword'", "]", "=", "$", "instanceinfo", "[", "'requiredparam'", "]", "->", "enrolpassword", ";", "}", "unset", "(", "$", "instanceinfo", "->", "requiredparam", ")", ";", "return", "$", "instanceinfo", ";", "}" ]
Return self-enrolment instance information. @param int $instanceid instance id of self enrolment plugin. @return array instance information. @throws moodle_exception
[ "Return", "self", "-", "enrolment", "instance", "information", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/self/externallib.php#L57-L85
217,861
moodle/moodle
mod/lti/classes/service_exception_handler.php
service_exception_handler.handle
public function handle($exception) { $message = $exception->getMessage(); // Add the exception backtrace for developers. if (debugging('', DEBUG_DEVELOPER)) { $message .= "\n".format_backtrace(get_exception_info($exception)->backtrace, true); } // Switch to response. $type = str_replace('Request', 'Response', $this->type); // Build the appropriate xml. $response = lti_get_response_xml('failure', $message, $this->id, $type); $xml = $response->asXML(); // Log the request if necessary. if ($this->log) { lti_log_response($xml, $exception); } echo $xml; }
php
public function handle($exception) { $message = $exception->getMessage(); // Add the exception backtrace for developers. if (debugging('', DEBUG_DEVELOPER)) { $message .= "\n".format_backtrace(get_exception_info($exception)->backtrace, true); } // Switch to response. $type = str_replace('Request', 'Response', $this->type); // Build the appropriate xml. $response = lti_get_response_xml('failure', $message, $this->id, $type); $xml = $response->asXML(); // Log the request if necessary. if ($this->log) { lti_log_response($xml, $exception); } echo $xml; }
[ "public", "function", "handle", "(", "$", "exception", ")", "{", "$", "message", "=", "$", "exception", "->", "getMessage", "(", ")", ";", "// Add the exception backtrace for developers.", "if", "(", "debugging", "(", "''", ",", "DEBUG_DEVELOPER", ")", ")", "{", "$", "message", ".=", "\"\\n\"", ".", "format_backtrace", "(", "get_exception_info", "(", "$", "exception", ")", "->", "backtrace", ",", "true", ")", ";", "}", "// Switch to response.", "$", "type", "=", "str_replace", "(", "'Request'", ",", "'Response'", ",", "$", "this", "->", "type", ")", ";", "// Build the appropriate xml.", "$", "response", "=", "lti_get_response_xml", "(", "'failure'", ",", "$", "message", ",", "$", "this", "->", "id", ",", "$", "type", ")", ";", "$", "xml", "=", "$", "response", "->", "asXML", "(", ")", ";", "// Log the request if necessary.", "if", "(", "$", "this", "->", "log", ")", "{", "lti_log_response", "(", "$", "xml", ",", "$", "exception", ")", ";", "}", "echo", "$", "xml", ";", "}" ]
Echo an exception message encapsulated in XML. @param \Exception|\Throwable $exception The exception that was thrown
[ "Echo", "an", "exception", "message", "encapsulated", "in", "XML", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lti/classes/service_exception_handler.php#L99-L121
217,862
moodle/moodle
backup/util/helper/backup_helper.class.php
backup_helper.clear_backup_dir
static public function clear_backup_dir($backupid, \core\progress\base $progress = null) { $backupiddir = make_backup_temp_directory($backupid, false); if (!self::delete_dir_contents($backupiddir, '', $progress)) { throw new backup_helper_exception('cannot_empty_backup_temp_dir'); } return true; }
php
static public function clear_backup_dir($backupid, \core\progress\base $progress = null) { $backupiddir = make_backup_temp_directory($backupid, false); if (!self::delete_dir_contents($backupiddir, '', $progress)) { throw new backup_helper_exception('cannot_empty_backup_temp_dir'); } return true; }
[ "static", "public", "function", "clear_backup_dir", "(", "$", "backupid", ",", "\\", "core", "\\", "progress", "\\", "base", "$", "progress", "=", "null", ")", "{", "$", "backupiddir", "=", "make_backup_temp_directory", "(", "$", "backupid", ",", "false", ")", ";", "if", "(", "!", "self", "::", "delete_dir_contents", "(", "$", "backupiddir", ",", "''", ",", "$", "progress", ")", ")", "{", "throw", "new", "backup_helper_exception", "(", "'cannot_empty_backup_temp_dir'", ")", ";", "}", "return", "true", ";", "}" ]
Given one backupid, ensure its temp dir is completely empty If supplied, progress object should be ready to receive indeterminate progress reports. @param string $backupid Backup id @param \core\progress\base $progress Optional progress reporting object
[ "Given", "one", "backupid", "ensure", "its", "temp", "dir", "is", "completely", "empty" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/helper/backup_helper.class.php#L51-L57
217,863
moodle/moodle
backup/util/helper/backup_helper.class.php
backup_helper.delete_backup_dir
static public function delete_backup_dir($backupid, \core\progress\base $progress = null) { $backupiddir = make_backup_temp_directory($backupid, false); self::clear_backup_dir($backupid, $progress); return rmdir($backupiddir); }
php
static public function delete_backup_dir($backupid, \core\progress\base $progress = null) { $backupiddir = make_backup_temp_directory($backupid, false); self::clear_backup_dir($backupid, $progress); return rmdir($backupiddir); }
[ "static", "public", "function", "delete_backup_dir", "(", "$", "backupid", ",", "\\", "core", "\\", "progress", "\\", "base", "$", "progress", "=", "null", ")", "{", "$", "backupiddir", "=", "make_backup_temp_directory", "(", "$", "backupid", ",", "false", ")", ";", "self", "::", "clear_backup_dir", "(", "$", "backupid", ",", "$", "progress", ")", ";", "return", "rmdir", "(", "$", "backupiddir", ")", ";", "}" ]
Given one backupid, delete completely its temp dir If supplied, progress object should be ready to receive indeterminate progress reports. @param string $backupid Backup id @param \core\progress\base $progress Optional progress reporting object
[ "Given", "one", "backupid", "delete", "completely", "its", "temp", "dir" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/helper/backup_helper.class.php#L68-L72
217,864
moodle/moodle
backup/util/helper/backup_helper.class.php
backup_helper.delete_old_backup_dirs
static public function delete_old_backup_dirs($deletefrom, \core\progress\base $progress = null) { $status = true; // Get files and directories in the backup temp dir without descend. $backuptempdir = make_backup_temp_directory(''); $list = get_directory_list($backuptempdir, '', false, true, true); foreach ($list as $file) { $file_path = $backuptempdir . '/' . $file; $moddate = filemtime($file_path); if ($status && $moddate < $deletefrom) { //If directory, recurse if (is_dir($file_path)) { // $file is really the backupid $status = self::delete_backup_dir($file, $progress); //If file } else { unlink($file_path); } } } if (!$status) { throw new backup_helper_exception('problem_deleting_old_backup_temp_dirs'); } }
php
static public function delete_old_backup_dirs($deletefrom, \core\progress\base $progress = null) { $status = true; // Get files and directories in the backup temp dir without descend. $backuptempdir = make_backup_temp_directory(''); $list = get_directory_list($backuptempdir, '', false, true, true); foreach ($list as $file) { $file_path = $backuptempdir . '/' . $file; $moddate = filemtime($file_path); if ($status && $moddate < $deletefrom) { //If directory, recurse if (is_dir($file_path)) { // $file is really the backupid $status = self::delete_backup_dir($file, $progress); //If file } else { unlink($file_path); } } } if (!$status) { throw new backup_helper_exception('problem_deleting_old_backup_temp_dirs'); } }
[ "static", "public", "function", "delete_old_backup_dirs", "(", "$", "deletefrom", ",", "\\", "core", "\\", "progress", "\\", "base", "$", "progress", "=", "null", ")", "{", "$", "status", "=", "true", ";", "// Get files and directories in the backup temp dir without descend.", "$", "backuptempdir", "=", "make_backup_temp_directory", "(", "''", ")", ";", "$", "list", "=", "get_directory_list", "(", "$", "backuptempdir", ",", "''", ",", "false", ",", "true", ",", "true", ")", ";", "foreach", "(", "$", "list", "as", "$", "file", ")", "{", "$", "file_path", "=", "$", "backuptempdir", ".", "'/'", ".", "$", "file", ";", "$", "moddate", "=", "filemtime", "(", "$", "file_path", ")", ";", "if", "(", "$", "status", "&&", "$", "moddate", "<", "$", "deletefrom", ")", "{", "//If directory, recurse", "if", "(", "is_dir", "(", "$", "file_path", ")", ")", "{", "// $file is really the backupid", "$", "status", "=", "self", "::", "delete_backup_dir", "(", "$", "file", ",", "$", "progress", ")", ";", "//If file", "}", "else", "{", "unlink", "(", "$", "file_path", ")", ";", "}", "}", "}", "if", "(", "!", "$", "status", ")", "{", "throw", "new", "backup_helper_exception", "(", "'problem_deleting_old_backup_temp_dirs'", ")", ";", "}", "}" ]
Delete all the temp dirs older than the time specified. If supplied, progress object should be ready to receive indeterminate progress reports. @param int $deletefrom Time to delete from @param \core\progress\base $progress Optional progress reporting object
[ "Delete", "all", "the", "temp", "dirs", "older", "than", "the", "time", "specified", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/helper/backup_helper.class.php#L159-L181
217,865
moodle/moodle
lib/htmlpurifier/HTMLPurifier/Context.php
HTMLPurifier_Context.destroy
public function destroy($name) { if (!array_key_exists($name, $this->_storage)) { trigger_error( "Attempted to destroy non-existent variable $name", E_USER_ERROR ); return; } unset($this->_storage[$name]); }
php
public function destroy($name) { if (!array_key_exists($name, $this->_storage)) { trigger_error( "Attempted to destroy non-existent variable $name", E_USER_ERROR ); return; } unset($this->_storage[$name]); }
[ "public", "function", "destroy", "(", "$", "name", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "name", ",", "$", "this", "->", "_storage", ")", ")", "{", "trigger_error", "(", "\"Attempted to destroy non-existent variable $name\"", ",", "E_USER_ERROR", ")", ";", "return", ";", "}", "unset", "(", "$", "this", "->", "_storage", "[", "$", "name", "]", ")", ";", "}" ]
Destroys a variable in the context. @param string $name String name
[ "Destroys", "a", "variable", "in", "the", "context", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Context.php#L61-L71
217,866
moodle/moodle
lib/htmlpurifier/HTMLPurifier/Context.php
HTMLPurifier_Context.loadArray
public function loadArray($context_array) { foreach ($context_array as $key => $discard) { $this->register($key, $context_array[$key]); } }
php
public function loadArray($context_array) { foreach ($context_array as $key => $discard) { $this->register($key, $context_array[$key]); } }
[ "public", "function", "loadArray", "(", "$", "context_array", ")", "{", "foreach", "(", "$", "context_array", "as", "$", "key", "=>", "$", "discard", ")", "{", "$", "this", "->", "register", "(", "$", "key", ",", "$", "context_array", "[", "$", "key", "]", ")", ";", "}", "}" ]
Loads a series of variables from an associative array @param array $context_array Assoc array of variables to load
[ "Loads", "a", "series", "of", "variables", "from", "an", "associative", "array" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Context.php#L87-L92
217,867
moodle/moodle
backup/controller/base_controller.class.php
base_controller.add_logger
public function add_logger(base_logger $logger) { $existing = $this->logger; while ($existing->get_next()) { $existing = $existing->get_next(); } $existing->set_next($logger); }
php
public function add_logger(base_logger $logger) { $existing = $this->logger; while ($existing->get_next()) { $existing = $existing->get_next(); } $existing->set_next($logger); }
[ "public", "function", "add_logger", "(", "base_logger", "$", "logger", ")", "{", "$", "existing", "=", "$", "this", "->", "logger", ";", "while", "(", "$", "existing", "->", "get_next", "(", ")", ")", "{", "$", "existing", "=", "$", "existing", "->", "get_next", "(", ")", ";", "}", "$", "existing", "->", "set_next", "(", "$", "logger", ")", ";", "}" ]
Inserts a new logger at end of logging chain. @param base_logger $logger New logger to add
[ "Inserts", "a", "new", "logger", "at", "end", "of", "logging", "chain", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/controller/base_controller.class.php#L69-L75
217,868
moodle/moodle
backup/moodle2/backup_xml_transformer.class.php
backup_xml_transformer.register_link_encoders
private function register_link_encoders() { global $LINKS_ENCODERS_CACHE; // If encoder is linked, then return cached encoder. if (!empty($LINKS_ENCODERS_CACHE)) { return $LINKS_ENCODERS_CACHE; } $encoders = array(); // Add the course encoder $encoders['backup_course_task'] = 'encode_content_links'; // Add the module ones. Each module supporting moodle2 backups MUST have it $mods = core_component::get_plugin_list('mod'); foreach ($mods as $mod => $moddir) { if (plugin_supports('mod', $mod, FEATURE_BACKUP_MOODLE2) && class_exists('backup_' . $mod . '_activity_task')) { $encoders['backup_' . $mod . '_activity_task'] = 'encode_content_links'; } } // Add the block encoders $blocks = core_component::get_plugin_list('block'); foreach ($blocks as $block => $blockdir) { if (class_exists('backup_' . $block . '_block_task')) { $encoders['backup_' . $block . '_block_task'] = 'encode_content_links'; } } // Add the course format encodes // TODO: Same than blocks, need to know how courseformats are going to handle backup // (1.9 was based in backuplib function, see code) // Add local encodes // TODO: Any interest? 1.9 never had that. $LINKS_ENCODERS_CACHE = $encoders; return $encoders; }
php
private function register_link_encoders() { global $LINKS_ENCODERS_CACHE; // If encoder is linked, then return cached encoder. if (!empty($LINKS_ENCODERS_CACHE)) { return $LINKS_ENCODERS_CACHE; } $encoders = array(); // Add the course encoder $encoders['backup_course_task'] = 'encode_content_links'; // Add the module ones. Each module supporting moodle2 backups MUST have it $mods = core_component::get_plugin_list('mod'); foreach ($mods as $mod => $moddir) { if (plugin_supports('mod', $mod, FEATURE_BACKUP_MOODLE2) && class_exists('backup_' . $mod . '_activity_task')) { $encoders['backup_' . $mod . '_activity_task'] = 'encode_content_links'; } } // Add the block encoders $blocks = core_component::get_plugin_list('block'); foreach ($blocks as $block => $blockdir) { if (class_exists('backup_' . $block . '_block_task')) { $encoders['backup_' . $block . '_block_task'] = 'encode_content_links'; } } // Add the course format encodes // TODO: Same than blocks, need to know how courseformats are going to handle backup // (1.9 was based in backuplib function, see code) // Add local encodes // TODO: Any interest? 1.9 never had that. $LINKS_ENCODERS_CACHE = $encoders; return $encoders; }
[ "private", "function", "register_link_encoders", "(", ")", "{", "global", "$", "LINKS_ENCODERS_CACHE", ";", "// If encoder is linked, then return cached encoder.", "if", "(", "!", "empty", "(", "$", "LINKS_ENCODERS_CACHE", ")", ")", "{", "return", "$", "LINKS_ENCODERS_CACHE", ";", "}", "$", "encoders", "=", "array", "(", ")", ";", "// Add the course encoder", "$", "encoders", "[", "'backup_course_task'", "]", "=", "'encode_content_links'", ";", "// Add the module ones. Each module supporting moodle2 backups MUST have it", "$", "mods", "=", "core_component", "::", "get_plugin_list", "(", "'mod'", ")", ";", "foreach", "(", "$", "mods", "as", "$", "mod", "=>", "$", "moddir", ")", "{", "if", "(", "plugin_supports", "(", "'mod'", ",", "$", "mod", ",", "FEATURE_BACKUP_MOODLE2", ")", "&&", "class_exists", "(", "'backup_'", ".", "$", "mod", ".", "'_activity_task'", ")", ")", "{", "$", "encoders", "[", "'backup_'", ".", "$", "mod", ".", "'_activity_task'", "]", "=", "'encode_content_links'", ";", "}", "}", "// Add the block encoders", "$", "blocks", "=", "core_component", "::", "get_plugin_list", "(", "'block'", ")", ";", "foreach", "(", "$", "blocks", "as", "$", "block", "=>", "$", "blockdir", ")", "{", "if", "(", "class_exists", "(", "'backup_'", ".", "$", "block", ".", "'_block_task'", ")", ")", "{", "$", "encoders", "[", "'backup_'", ".", "$", "block", ".", "'_block_task'", "]", "=", "'encode_content_links'", ";", "}", "}", "// Add the course format encodes", "// TODO: Same than blocks, need to know how courseformats are going to handle backup", "// (1.9 was based in backuplib function, see code)", "// Add local encodes", "// TODO: Any interest? 1.9 never had that.", "$", "LINKS_ENCODERS_CACHE", "=", "$", "encoders", ";", "return", "$", "encoders", ";", "}" ]
Register all available content link encoders @return array encoder @todo MDL-25290 replace LINKS_ENCODERS_CACHE global with MUC code
[ "Register", "all", "available", "content", "link", "encoders" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/moodle2/backup_xml_transformer.class.php#L147-L184
217,869
moodle/moodle
user/classes/search/user.php
user.get_document_recordset
public function get_document_recordset($modifiedfrom = 0, \context $context = null) { global $DB; // Prepare query conditions. $where = 'timemodified >= ? AND deleted = ? AND confirmed = ?'; $params = [$modifiedfrom, 0, 1]; // Handle context types. if (!$context) { $context = \context_system::instance(); } switch ($context->contextlevel) { case CONTEXT_MODULE: case CONTEXT_BLOCK: case CONTEXT_COURSE: case CONTEXT_COURSECAT: // These contexts cannot contain any users. return null; case CONTEXT_USER: // Restrict to specific user. $where .= ' AND id = ?'; $params[] = $context->instanceid; break; case CONTEXT_SYSTEM: break; default: throw new \coding_exception('Unexpected contextlevel: ' . $context->contextlevel); } return $DB->get_recordset_select('user', $where, $params); }
php
public function get_document_recordset($modifiedfrom = 0, \context $context = null) { global $DB; // Prepare query conditions. $where = 'timemodified >= ? AND deleted = ? AND confirmed = ?'; $params = [$modifiedfrom, 0, 1]; // Handle context types. if (!$context) { $context = \context_system::instance(); } switch ($context->contextlevel) { case CONTEXT_MODULE: case CONTEXT_BLOCK: case CONTEXT_COURSE: case CONTEXT_COURSECAT: // These contexts cannot contain any users. return null; case CONTEXT_USER: // Restrict to specific user. $where .= ' AND id = ?'; $params[] = $context->instanceid; break; case CONTEXT_SYSTEM: break; default: throw new \coding_exception('Unexpected contextlevel: ' . $context->contextlevel); } return $DB->get_recordset_select('user', $where, $params); }
[ "public", "function", "get_document_recordset", "(", "$", "modifiedfrom", "=", "0", ",", "\\", "context", "$", "context", "=", "null", ")", "{", "global", "$", "DB", ";", "// Prepare query conditions.", "$", "where", "=", "'timemodified >= ? AND deleted = ? AND confirmed = ?'", ";", "$", "params", "=", "[", "$", "modifiedfrom", ",", "0", ",", "1", "]", ";", "// Handle context types.", "if", "(", "!", "$", "context", ")", "{", "$", "context", "=", "\\", "context_system", "::", "instance", "(", ")", ";", "}", "switch", "(", "$", "context", "->", "contextlevel", ")", "{", "case", "CONTEXT_MODULE", ":", "case", "CONTEXT_BLOCK", ":", "case", "CONTEXT_COURSE", ":", "case", "CONTEXT_COURSECAT", ":", "// These contexts cannot contain any users.", "return", "null", ";", "case", "CONTEXT_USER", ":", "// Restrict to specific user.", "$", "where", ".=", "' AND id = ?'", ";", "$", "params", "[", "]", "=", "$", "context", "->", "instanceid", ";", "break", ";", "case", "CONTEXT_SYSTEM", ":", "break", ";", "default", ":", "throw", "new", "\\", "coding_exception", "(", "'Unexpected contextlevel: '", ".", "$", "context", "->", "contextlevel", ")", ";", "}", "return", "$", "DB", "->", "get_recordset_select", "(", "'user'", ",", "$", "where", ",", "$", "params", ")", ";", "}" ]
Returns recordset containing required data attributes for indexing. @param number $modifiedfrom @param \context|null $context Optional context to restrict scope of returned results @return \moodle_recordset|null Recordset (or null if no results)
[ "Returns", "recordset", "containing", "required", "data", "attributes", "for", "indexing", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/classes/search/user.php#L47-L80
217,870
moodle/moodle
user/classes/search/user.php
user.get_document
public function get_document($record, $options = array()) { $context = \context_system::instance(); // Prepare associative array with data from DB. $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname); // Include all alternate names in title. $array = []; foreach (get_all_user_name_fields(false, null, null, null, true) as $field) { $array[$field] = $record->$field; } $fullusername = join(' ', $array); // Assigning properties to our document. $doc->set('title', content_to_text($fullusername, false)); $doc->set('contextid', $context->id); $doc->set('courseid', SITEID); $doc->set('itemid', $record->id); $doc->set('modified', $record->timemodified); $doc->set('owneruserid', \core_search\manager::NO_OWNER_ID); $doc->set('content', content_to_text($record->description, $record->descriptionformat)); // Check if this document should be considered new. if (isset($options['lastindexedtime']) && $options['lastindexedtime'] < $record->timecreated) { // If the document was created after the last index time, it must be new. $doc->set_is_new(true); } return $doc; }
php
public function get_document($record, $options = array()) { $context = \context_system::instance(); // Prepare associative array with data from DB. $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname); // Include all alternate names in title. $array = []; foreach (get_all_user_name_fields(false, null, null, null, true) as $field) { $array[$field] = $record->$field; } $fullusername = join(' ', $array); // Assigning properties to our document. $doc->set('title', content_to_text($fullusername, false)); $doc->set('contextid', $context->id); $doc->set('courseid', SITEID); $doc->set('itemid', $record->id); $doc->set('modified', $record->timemodified); $doc->set('owneruserid', \core_search\manager::NO_OWNER_ID); $doc->set('content', content_to_text($record->description, $record->descriptionformat)); // Check if this document should be considered new. if (isset($options['lastindexedtime']) && $options['lastindexedtime'] < $record->timecreated) { // If the document was created after the last index time, it must be new. $doc->set_is_new(true); } return $doc; }
[ "public", "function", "get_document", "(", "$", "record", ",", "$", "options", "=", "array", "(", ")", ")", "{", "$", "context", "=", "\\", "context_system", "::", "instance", "(", ")", ";", "// Prepare associative array with data from DB.", "$", "doc", "=", "\\", "core_search", "\\", "document_factory", "::", "instance", "(", "$", "record", "->", "id", ",", "$", "this", "->", "componentname", ",", "$", "this", "->", "areaname", ")", ";", "// Include all alternate names in title.", "$", "array", "=", "[", "]", ";", "foreach", "(", "get_all_user_name_fields", "(", "false", ",", "null", ",", "null", ",", "null", ",", "true", ")", "as", "$", "field", ")", "{", "$", "array", "[", "$", "field", "]", "=", "$", "record", "->", "$", "field", ";", "}", "$", "fullusername", "=", "join", "(", "' '", ",", "$", "array", ")", ";", "// Assigning properties to our document.", "$", "doc", "->", "set", "(", "'title'", ",", "content_to_text", "(", "$", "fullusername", ",", "false", ")", ")", ";", "$", "doc", "->", "set", "(", "'contextid'", ",", "$", "context", "->", "id", ")", ";", "$", "doc", "->", "set", "(", "'courseid'", ",", "SITEID", ")", ";", "$", "doc", "->", "set", "(", "'itemid'", ",", "$", "record", "->", "id", ")", ";", "$", "doc", "->", "set", "(", "'modified'", ",", "$", "record", "->", "timemodified", ")", ";", "$", "doc", "->", "set", "(", "'owneruserid'", ",", "\\", "core_search", "\\", "manager", "::", "NO_OWNER_ID", ")", ";", "$", "doc", "->", "set", "(", "'content'", ",", "content_to_text", "(", "$", "record", "->", "description", ",", "$", "record", "->", "descriptionformat", ")", ")", ";", "// Check if this document should be considered new.", "if", "(", "isset", "(", "$", "options", "[", "'lastindexedtime'", "]", ")", "&&", "$", "options", "[", "'lastindexedtime'", "]", "<", "$", "record", "->", "timecreated", ")", "{", "// If the document was created after the last index time, it must be new.", "$", "doc", "->", "set_is_new", "(", "true", ")", ";", "}", "return", "$", "doc", ";", "}" ]
Returns document instances for each record in the recordset. @param \stdClass $record @param array $options @return \core_search\document
[ "Returns", "document", "instances", "for", "each", "record", "in", "the", "recordset", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/classes/search/user.php#L89-L117
217,871
moodle/moodle
user/classes/search/user.php
user.get_document_display_title
public function get_document_display_title(\core_search\document $doc) { $user = \core_user::get_user($doc->get('itemid')); return fullname($user); }
php
public function get_document_display_title(\core_search\document $doc) { $user = \core_user::get_user($doc->get('itemid')); return fullname($user); }
[ "public", "function", "get_document_display_title", "(", "\\", "core_search", "\\", "document", "$", "doc", ")", "{", "$", "user", "=", "\\", "core_user", "::", "get_user", "(", "$", "doc", "->", "get", "(", "'itemid'", ")", ")", ";", "return", "fullname", "(", "$", "user", ")", ";", "}" ]
Returns the user fullname to display as document title @param \core_search\document $doc @return string User fullname
[ "Returns", "the", "user", "fullname", "to", "display", "as", "document", "title" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/classes/search/user.php#L125-L129
217,872
moodle/moodle
user/classes/search/user.php
user.check_access
public function check_access($id) { global $DB, $USER; $user = $DB->get_record('user', array('id' => $id)); if (!$user || $user->deleted) { return \core_search\manager::ACCESS_DELETED; } if (user_can_view_profile($user)) { return \core_search\manager::ACCESS_GRANTED; } return \core_search\manager::ACCESS_DENIED; }
php
public function check_access($id) { global $DB, $USER; $user = $DB->get_record('user', array('id' => $id)); if (!$user || $user->deleted) { return \core_search\manager::ACCESS_DELETED; } if (user_can_view_profile($user)) { return \core_search\manager::ACCESS_GRANTED; } return \core_search\manager::ACCESS_DENIED; }
[ "public", "function", "check_access", "(", "$", "id", ")", "{", "global", "$", "DB", ",", "$", "USER", ";", "$", "user", "=", "$", "DB", "->", "get_record", "(", "'user'", ",", "array", "(", "'id'", "=>", "$", "id", ")", ")", ";", "if", "(", "!", "$", "user", "||", "$", "user", "->", "deleted", ")", "{", "return", "\\", "core_search", "\\", "manager", "::", "ACCESS_DELETED", ";", "}", "if", "(", "user_can_view_profile", "(", "$", "user", ")", ")", "{", "return", "\\", "core_search", "\\", "manager", "::", "ACCESS_GRANTED", ";", "}", "return", "\\", "core_search", "\\", "manager", "::", "ACCESS_DENIED", ";", "}" ]
Checking whether I can access a document @param int $id user id @return int
[ "Checking", "whether", "I", "can", "access", "a", "document" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/classes/search/user.php#L137-L150
217,873
moodle/moodle
lib/dml/pgsql_native_moodle_database.php
pgsql_native_moodle_database.fetch_from_cursor
public function fetch_from_cursor($cursorname) { $count = $this->get_fetch_buffer_size(); $sql = 'FETCH ' . $count . ' FROM ' . $cursorname; $this->query_start($sql, [], SQL_QUERY_AUX); $result = pg_query($this->pgsql, $sql); $last = pg_num_rows($result) !== $count; $this->query_end($result); return [$result, $last]; }
php
public function fetch_from_cursor($cursorname) { $count = $this->get_fetch_buffer_size(); $sql = 'FETCH ' . $count . ' FROM ' . $cursorname; $this->query_start($sql, [], SQL_QUERY_AUX); $result = pg_query($this->pgsql, $sql); $last = pg_num_rows($result) !== $count; $this->query_end($result); return [$result, $last]; }
[ "public", "function", "fetch_from_cursor", "(", "$", "cursorname", ")", "{", "$", "count", "=", "$", "this", "->", "get_fetch_buffer_size", "(", ")", ";", "$", "sql", "=", "'FETCH '", ".", "$", "count", ".", "' FROM '", ".", "$", "cursorname", ";", "$", "this", "->", "query_start", "(", "$", "sql", ",", "[", "]", ",", "SQL_QUERY_AUX", ")", ";", "$", "result", "=", "pg_query", "(", "$", "this", "->", "pgsql", ",", "$", "sql", ")", ";", "$", "last", "=", "pg_num_rows", "(", "$", "result", ")", "!==", "$", "count", ";", "$", "this", "->", "query_end", "(", "$", "result", ")", ";", "return", "[", "$", "result", ",", "$", "last", "]", ";", "}" ]
Retrieves data from cursor. For use by recordset only; do not call directly. Return value contains the next batch of Postgres data, and a boolean indicating if this is definitely the last batch (if false, there may be more) @param string $cursorname Name of cursor to read from @return array Array with 2 elements (next data batch and boolean indicating last batch)
[ "Retrieves", "data", "from", "cursor", ".", "For", "use", "by", "recordset", "only", ";", "do", "not", "call", "directly", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/pgsql_native_moodle_database.php#L798-L810
217,874
moodle/moodle
lib/dml/pgsql_native_moodle_database.php
pgsql_native_moodle_database.close_cursor
public function close_cursor($cursorname) { // If the transaction got cancelled, then ignore this request. $sql = 'CLOSE ' . $cursorname; $this->query_start($sql, [], SQL_QUERY_AUX); $result = pg_query($this->pgsql, $sql); $this->query_end($result); if ($result) { pg_free_result($result); } return true; }
php
public function close_cursor($cursorname) { // If the transaction got cancelled, then ignore this request. $sql = 'CLOSE ' . $cursorname; $this->query_start($sql, [], SQL_QUERY_AUX); $result = pg_query($this->pgsql, $sql); $this->query_end($result); if ($result) { pg_free_result($result); } return true; }
[ "public", "function", "close_cursor", "(", "$", "cursorname", ")", "{", "// If the transaction got cancelled, then ignore this request.", "$", "sql", "=", "'CLOSE '", ".", "$", "cursorname", ";", "$", "this", "->", "query_start", "(", "$", "sql", ",", "[", "]", ",", "SQL_QUERY_AUX", ")", ";", "$", "result", "=", "pg_query", "(", "$", "this", "->", "pgsql", ",", "$", "sql", ")", ";", "$", "this", "->", "query_end", "(", "$", "result", ")", ";", "if", "(", "$", "result", ")", "{", "pg_free_result", "(", "$", "result", ")", ";", "}", "return", "true", ";", "}" ]
Closes a cursor. For use by recordset only; do not call directly. @param string $cursorname Name of cursor to close @return bool True if we actually closed one, false if the transaction was cancelled
[ "Closes", "a", "cursor", ".", "For", "use", "by", "recordset", "only", ";", "do", "not", "call", "directly", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/pgsql_native_moodle_database.php#L818-L828
217,875
moodle/moodle
lib/dml/pgsql_native_moodle_database.php
pgsql_native_moodle_database.insert_chunk
protected function insert_chunk($table, array $chunk, array $columns) { $i = 1; $params = array(); $values = array(); foreach ($chunk as $dataobject) { $vals = array(); foreach ($columns as $field => $column) { $params[] = $this->normalise_value($column, $dataobject[$field]); $vals[] = "\$".$i++; } $values[] = '('.implode(',', $vals).')'; } $fieldssql = '('.implode(',', array_keys($columns)).')'; $valuessql = implode(',', $values); $sql = "INSERT INTO {$this->prefix}$table $fieldssql VALUES $valuessql"; $this->query_start($sql, $params, SQL_QUERY_INSERT); $result = pg_query_params($this->pgsql, $sql, $params); $this->query_end($result); pg_free_result($result); }
php
protected function insert_chunk($table, array $chunk, array $columns) { $i = 1; $params = array(); $values = array(); foreach ($chunk as $dataobject) { $vals = array(); foreach ($columns as $field => $column) { $params[] = $this->normalise_value($column, $dataobject[$field]); $vals[] = "\$".$i++; } $values[] = '('.implode(',', $vals).')'; } $fieldssql = '('.implode(',', array_keys($columns)).')'; $valuessql = implode(',', $values); $sql = "INSERT INTO {$this->prefix}$table $fieldssql VALUES $valuessql"; $this->query_start($sql, $params, SQL_QUERY_INSERT); $result = pg_query_params($this->pgsql, $sql, $params); $this->query_end($result); pg_free_result($result); }
[ "protected", "function", "insert_chunk", "(", "$", "table", ",", "array", "$", "chunk", ",", "array", "$", "columns", ")", "{", "$", "i", "=", "1", ";", "$", "params", "=", "array", "(", ")", ";", "$", "values", "=", "array", "(", ")", ";", "foreach", "(", "$", "chunk", "as", "$", "dataobject", ")", "{", "$", "vals", "=", "array", "(", ")", ";", "foreach", "(", "$", "columns", "as", "$", "field", "=>", "$", "column", ")", "{", "$", "params", "[", "]", "=", "$", "this", "->", "normalise_value", "(", "$", "column", ",", "$", "dataobject", "[", "$", "field", "]", ")", ";", "$", "vals", "[", "]", "=", "\"\\$\"", ".", "$", "i", "++", ";", "}", "$", "values", "[", "]", "=", "'('", ".", "implode", "(", "','", ",", "$", "vals", ")", ".", "')'", ";", "}", "$", "fieldssql", "=", "'('", ".", "implode", "(", "','", ",", "array_keys", "(", "$", "columns", ")", ")", ".", "')'", ";", "$", "valuessql", "=", "implode", "(", "','", ",", "$", "values", ")", ";", "$", "sql", "=", "\"INSERT INTO {$this->prefix}$table $fieldssql VALUES $valuessql\"", ";", "$", "this", "->", "query_start", "(", "$", "sql", ",", "$", "params", ",", "SQL_QUERY_INSERT", ")", ";", "$", "result", "=", "pg_query_params", "(", "$", "this", "->", "pgsql", ",", "$", "sql", ",", "$", "params", ")", ";", "$", "this", "->", "query_end", "(", "$", "result", ")", ";", "pg_free_result", "(", "$", "result", ")", ";", "}" ]
Insert records in chunks, strict param types... Note: can be used only from insert_records(). @param string $table @param array $chunk @param database_column_info[] $columns
[ "Insert", "records", "in", "chunks", "strict", "param", "types", "..." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/pgsql_native_moodle_database.php#L1092-L1113
217,876
moodle/moodle
lib/dml/pgsql_native_moodle_database.php
pgsql_native_moodle_database.delete_records_select
public function delete_records_select($table, $select, array $params=null) { if ($select) { $select = "WHERE $select"; } $sql = "DELETE FROM {$this->prefix}$table $select"; list($sql, $params, $type) = $this->fix_sql_params($sql, $params); $this->query_start($sql, $params, SQL_QUERY_UPDATE); $result = pg_query_params($this->pgsql, $sql, $params); $this->query_end($result); pg_free_result($result); return true; }
php
public function delete_records_select($table, $select, array $params=null) { if ($select) { $select = "WHERE $select"; } $sql = "DELETE FROM {$this->prefix}$table $select"; list($sql, $params, $type) = $this->fix_sql_params($sql, $params); $this->query_start($sql, $params, SQL_QUERY_UPDATE); $result = pg_query_params($this->pgsql, $sql, $params); $this->query_end($result); pg_free_result($result); return true; }
[ "public", "function", "delete_records_select", "(", "$", "table", ",", "$", "select", ",", "array", "$", "params", "=", "null", ")", "{", "if", "(", "$", "select", ")", "{", "$", "select", "=", "\"WHERE $select\"", ";", "}", "$", "sql", "=", "\"DELETE FROM {$this->prefix}$table $select\"", ";", "list", "(", "$", "sql", ",", "$", "params", ",", "$", "type", ")", "=", "$", "this", "->", "fix_sql_params", "(", "$", "sql", ",", "$", "params", ")", ";", "$", "this", "->", "query_start", "(", "$", "sql", ",", "$", "params", ",", "SQL_QUERY_UPDATE", ")", ";", "$", "result", "=", "pg_query_params", "(", "$", "this", "->", "pgsql", ",", "$", "sql", ",", "$", "params", ")", ";", "$", "this", "->", "query_end", "(", "$", "result", ")", ";", "pg_free_result", "(", "$", "result", ")", ";", "return", "true", ";", "}" ]
Delete one or more records from a table which match a particular WHERE clause, lobs not supported. @param string $table The database table to be checked against. @param string $select A fragment of SQL to be used in a where clause in the SQL call (used to define the selection criteria). @param array $params array of sql parameters @return bool true @throws dml_exception A DML specific exception is thrown for any errors.
[ "Delete", "one", "or", "more", "records", "from", "a", "table", "which", "match", "a", "particular", "WHERE", "clause", "lobs", "not", "supported", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/pgsql_native_moodle_database.php#L1266-L1281
217,877
moodle/moodle
mod/assign/feedback/editpdf/fpdi/pdf_context.php
pdf_context.getPos
public function getPos() { if ($this->_mode == 0) { if (feof($this->file)) { $stat = fstat($this->file); fseek($this->file, $stat['size']); } $pos = ftell($this->file); return $pos; } else { return 0; } }
php
public function getPos() { if ($this->_mode == 0) { if (feof($this->file)) { $stat = fstat($this->file); fseek($this->file, $stat['size']); } $pos = ftell($this->file); return $pos; } else { return 0; } }
[ "public", "function", "getPos", "(", ")", "{", "if", "(", "$", "this", "->", "_mode", "==", "0", ")", "{", "if", "(", "feof", "(", "$", "this", "->", "file", ")", ")", "{", "$", "stat", "=", "fstat", "(", "$", "this", "->", "file", ")", ";", "fseek", "(", "$", "this", "->", "file", ",", "$", "stat", "[", "'size'", "]", ")", ";", "}", "$", "pos", "=", "ftell", "(", "$", "this", "->", "file", ")", ";", "return", "$", "pos", ";", "}", "else", "{", "return", "0", ";", "}", "}" ]
Get the position in the file stream @return int
[ "Get", "the", "position", "in", "the", "file", "stream" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/fpdi/pdf_context.php#L67-L81
217,878
moodle/moodle
mod/assign/feedback/editpdf/fpdi/pdf_context.php
pdf_context.reset
public function reset($pos = null, $l = 100) { if ($this->_mode == 0) { if (!is_null($pos)) { fseek($this->file, $pos); } $this->buffer = $l > 0 ? fread($this->file, $l) : ''; $this->length = strlen($this->buffer); if ($this->length < $l) $this->increaseLength($l - $this->length); } else { $this->buffer = $this->file; $this->length = strlen($this->buffer); } $this->offset = 0; $this->stack = array(); }
php
public function reset($pos = null, $l = 100) { if ($this->_mode == 0) { if (!is_null($pos)) { fseek($this->file, $pos); } $this->buffer = $l > 0 ? fread($this->file, $l) : ''; $this->length = strlen($this->buffer); if ($this->length < $l) $this->increaseLength($l - $this->length); } else { $this->buffer = $this->file; $this->length = strlen($this->buffer); } $this->offset = 0; $this->stack = array(); }
[ "public", "function", "reset", "(", "$", "pos", "=", "null", ",", "$", "l", "=", "100", ")", "{", "if", "(", "$", "this", "->", "_mode", "==", "0", ")", "{", "if", "(", "!", "is_null", "(", "$", "pos", ")", ")", "{", "fseek", "(", "$", "this", "->", "file", ",", "$", "pos", ")", ";", "}", "$", "this", "->", "buffer", "=", "$", "l", ">", "0", "?", "fread", "(", "$", "this", "->", "file", ",", "$", "l", ")", ":", "''", ";", "$", "this", "->", "length", "=", "strlen", "(", "$", "this", "->", "buffer", ")", ";", "if", "(", "$", "this", "->", "length", "<", "$", "l", ")", "$", "this", "->", "increaseLength", "(", "$", "l", "-", "$", "this", "->", "length", ")", ";", "}", "else", "{", "$", "this", "->", "buffer", "=", "$", "this", "->", "file", ";", "$", "this", "->", "length", "=", "strlen", "(", "$", "this", "->", "buffer", ")", ";", "}", "$", "this", "->", "offset", "=", "0", ";", "$", "this", "->", "stack", "=", "array", "(", ")", ";", "}" ]
Reset the position in the file stream. Optionally move the file pointer to a new location and reset the buffered data. @param null $pos @param int $l
[ "Reset", "the", "position", "in", "the", "file", "stream", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/fpdi/pdf_context.php#L91-L108
217,879
moodle/moodle
mod/forum/classes/potential_subscriber_selector.php
mod_forum_potential_subscriber_selector.find_users
public function find_users($search) { global $DB; $whereconditions = array(); list($wherecondition, $params) = $this->search_sql($search, 'u'); if ($wherecondition) { $whereconditions[] = $wherecondition; } if (!$this->forcesubscribed) { $existingids = array(); foreach ($this->existingsubscribers as $group) { foreach ($group as $user) { $existingids[$user->id] = 1; } } if ($existingids) { list($usertest, $userparams) = $DB->get_in_or_equal( array_keys($existingids), SQL_PARAMS_NAMED, 'existing', false); $whereconditions[] = 'u.id ' . $usertest; $params = array_merge($params, $userparams); } } if ($whereconditions) { $wherecondition = 'WHERE ' . implode(' AND ', $whereconditions); } list($esql, $eparams) = get_enrolled_sql($this->context, '', $this->currentgroup, true); $params = array_merge($params, $eparams); $fields = 'SELECT ' . $this->required_fields_sql('u'); $sql = " FROM {user} u JOIN ($esql) je ON je.id = u.id $wherecondition"; list($sort, $sortparams) = users_order_by_sql('u', $search, $this->accesscontext); $order = ' ORDER BY ' . $sort; $availableusers = $DB->get_records_sql($fields . $sql . $order, array_merge($params, $sortparams)); $cm = get_coursemodule_from_instance('forum', $this->forumid); $modinfo = get_fast_modinfo($cm->course); $info = new \core_availability\info_module($modinfo->get_cm($cm->id)); $availableusers = $info->filter_user_list($availableusers); if (empty($availableusers)) { return array(); } // Check to see if there are too many to show sensibly. if (!$this->is_validating()) { $potentialmemberscount = count($availableusers); if ($potentialmemberscount > $this->maxusersperpage) { return $this->too_many_results($search, $potentialmemberscount); } } if ($this->forcesubscribed) { return array(get_string("existingsubscribers", 'forum') => $availableusers); } else { return array(get_string("potentialsubscribers", 'forum') => $availableusers); } }
php
public function find_users($search) { global $DB; $whereconditions = array(); list($wherecondition, $params) = $this->search_sql($search, 'u'); if ($wherecondition) { $whereconditions[] = $wherecondition; } if (!$this->forcesubscribed) { $existingids = array(); foreach ($this->existingsubscribers as $group) { foreach ($group as $user) { $existingids[$user->id] = 1; } } if ($existingids) { list($usertest, $userparams) = $DB->get_in_or_equal( array_keys($existingids), SQL_PARAMS_NAMED, 'existing', false); $whereconditions[] = 'u.id ' . $usertest; $params = array_merge($params, $userparams); } } if ($whereconditions) { $wherecondition = 'WHERE ' . implode(' AND ', $whereconditions); } list($esql, $eparams) = get_enrolled_sql($this->context, '', $this->currentgroup, true); $params = array_merge($params, $eparams); $fields = 'SELECT ' . $this->required_fields_sql('u'); $sql = " FROM {user} u JOIN ($esql) je ON je.id = u.id $wherecondition"; list($sort, $sortparams) = users_order_by_sql('u', $search, $this->accesscontext); $order = ' ORDER BY ' . $sort; $availableusers = $DB->get_records_sql($fields . $sql . $order, array_merge($params, $sortparams)); $cm = get_coursemodule_from_instance('forum', $this->forumid); $modinfo = get_fast_modinfo($cm->course); $info = new \core_availability\info_module($modinfo->get_cm($cm->id)); $availableusers = $info->filter_user_list($availableusers); if (empty($availableusers)) { return array(); } // Check to see if there are too many to show sensibly. if (!$this->is_validating()) { $potentialmemberscount = count($availableusers); if ($potentialmemberscount > $this->maxusersperpage) { return $this->too_many_results($search, $potentialmemberscount); } } if ($this->forcesubscribed) { return array(get_string("existingsubscribers", 'forum') => $availableusers); } else { return array(get_string("potentialsubscribers", 'forum') => $availableusers); } }
[ "public", "function", "find_users", "(", "$", "search", ")", "{", "global", "$", "DB", ";", "$", "whereconditions", "=", "array", "(", ")", ";", "list", "(", "$", "wherecondition", ",", "$", "params", ")", "=", "$", "this", "->", "search_sql", "(", "$", "search", ",", "'u'", ")", ";", "if", "(", "$", "wherecondition", ")", "{", "$", "whereconditions", "[", "]", "=", "$", "wherecondition", ";", "}", "if", "(", "!", "$", "this", "->", "forcesubscribed", ")", "{", "$", "existingids", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "existingsubscribers", "as", "$", "group", ")", "{", "foreach", "(", "$", "group", "as", "$", "user", ")", "{", "$", "existingids", "[", "$", "user", "->", "id", "]", "=", "1", ";", "}", "}", "if", "(", "$", "existingids", ")", "{", "list", "(", "$", "usertest", ",", "$", "userparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "array_keys", "(", "$", "existingids", ")", ",", "SQL_PARAMS_NAMED", ",", "'existing'", ",", "false", ")", ";", "$", "whereconditions", "[", "]", "=", "'u.id '", ".", "$", "usertest", ";", "$", "params", "=", "array_merge", "(", "$", "params", ",", "$", "userparams", ")", ";", "}", "}", "if", "(", "$", "whereconditions", ")", "{", "$", "wherecondition", "=", "'WHERE '", ".", "implode", "(", "' AND '", ",", "$", "whereconditions", ")", ";", "}", "list", "(", "$", "esql", ",", "$", "eparams", ")", "=", "get_enrolled_sql", "(", "$", "this", "->", "context", ",", "''", ",", "$", "this", "->", "currentgroup", ",", "true", ")", ";", "$", "params", "=", "array_merge", "(", "$", "params", ",", "$", "eparams", ")", ";", "$", "fields", "=", "'SELECT '", ".", "$", "this", "->", "required_fields_sql", "(", "'u'", ")", ";", "$", "sql", "=", "\" FROM {user} u\n JOIN ($esql) je ON je.id = u.id\n $wherecondition\"", ";", "list", "(", "$", "sort", ",", "$", "sortparams", ")", "=", "users_order_by_sql", "(", "'u'", ",", "$", "search", ",", "$", "this", "->", "accesscontext", ")", ";", "$", "order", "=", "' ORDER BY '", ".", "$", "sort", ";", "$", "availableusers", "=", "$", "DB", "->", "get_records_sql", "(", "$", "fields", ".", "$", "sql", ".", "$", "order", ",", "array_merge", "(", "$", "params", ",", "$", "sortparams", ")", ")", ";", "$", "cm", "=", "get_coursemodule_from_instance", "(", "'forum'", ",", "$", "this", "->", "forumid", ")", ";", "$", "modinfo", "=", "get_fast_modinfo", "(", "$", "cm", "->", "course", ")", ";", "$", "info", "=", "new", "\\", "core_availability", "\\", "info_module", "(", "$", "modinfo", "->", "get_cm", "(", "$", "cm", "->", "id", ")", ")", ";", "$", "availableusers", "=", "$", "info", "->", "filter_user_list", "(", "$", "availableusers", ")", ";", "if", "(", "empty", "(", "$", "availableusers", ")", ")", "{", "return", "array", "(", ")", ";", "}", "// Check to see if there are too many to show sensibly.", "if", "(", "!", "$", "this", "->", "is_validating", "(", ")", ")", "{", "$", "potentialmemberscount", "=", "count", "(", "$", "availableusers", ")", ";", "if", "(", "$", "potentialmemberscount", ">", "$", "this", "->", "maxusersperpage", ")", "{", "return", "$", "this", "->", "too_many_results", "(", "$", "search", ",", "$", "potentialmemberscount", ")", ";", "}", "}", "if", "(", "$", "this", "->", "forcesubscribed", ")", "{", "return", "array", "(", "get_string", "(", "\"existingsubscribers\"", ",", "'forum'", ")", "=>", "$", "availableusers", ")", ";", "}", "else", "{", "return", "array", "(", "get_string", "(", "\"potentialsubscribers\"", ",", "'forum'", ")", "=>", "$", "availableusers", ")", ";", "}", "}" ]
Finds all potential users Potential subscribers are all enroled users who are not already subscribed. @param string $search @return array
[ "Finds", "all", "potential", "users" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/potential_subscriber_selector.php#L79-L143
217,880
moodle/moodle
lib/classes/grades_external.php
core_grades_external.get_grade_item
private static function get_grade_item($courseid, $itemtype, $itemmodule = null, $iteminstance = null, $itemnumber = null) { $gradeiteminstance = null; if ($itemtype == 'course') { $gradeiteminstance = grade_item::fetch(array('courseid' => $courseid, 'itemtype' => $itemtype)); } else { $gradeiteminstance = grade_item::fetch( array('courseid' => $courseid, 'itemtype' => $itemtype, 'itemmodule' => $itemmodule, 'iteminstance' => $iteminstance, 'itemnumber' => $itemnumber)); } return $gradeiteminstance; }
php
private static function get_grade_item($courseid, $itemtype, $itemmodule = null, $iteminstance = null, $itemnumber = null) { $gradeiteminstance = null; if ($itemtype == 'course') { $gradeiteminstance = grade_item::fetch(array('courseid' => $courseid, 'itemtype' => $itemtype)); } else { $gradeiteminstance = grade_item::fetch( array('courseid' => $courseid, 'itemtype' => $itemtype, 'itemmodule' => $itemmodule, 'iteminstance' => $iteminstance, 'itemnumber' => $itemnumber)); } return $gradeiteminstance; }
[ "private", "static", "function", "get_grade_item", "(", "$", "courseid", ",", "$", "itemtype", ",", "$", "itemmodule", "=", "null", ",", "$", "iteminstance", "=", "null", ",", "$", "itemnumber", "=", "null", ")", "{", "$", "gradeiteminstance", "=", "null", ";", "if", "(", "$", "itemtype", "==", "'course'", ")", "{", "$", "gradeiteminstance", "=", "grade_item", "::", "fetch", "(", "array", "(", "'courseid'", "=>", "$", "courseid", ",", "'itemtype'", "=>", "$", "itemtype", ")", ")", ";", "}", "else", "{", "$", "gradeiteminstance", "=", "grade_item", "::", "fetch", "(", "array", "(", "'courseid'", "=>", "$", "courseid", ",", "'itemtype'", "=>", "$", "itemtype", ",", "'itemmodule'", "=>", "$", "itemmodule", ",", "'iteminstance'", "=>", "$", "iteminstance", ",", "'itemnumber'", "=>", "$", "itemnumber", ")", ")", ";", "}", "return", "$", "gradeiteminstance", ";", "}" ]
Get a grade item @param int $courseid Course id @param string $itemtype Item type @param string $itemmodule Item module @param int $iteminstance Item instance @param int $itemnumber Item number @return grade_item A grade_item instance @deprecated Moodle 3.2 MDL-51373 - Please do not call this function any more. @see gradereport_user_external::get_grade_items for a similar function
[ "Get", "a", "grade", "item" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/grades_external.php#L303-L313
217,881
moodle/moodle
lib/classes/grades_external.php
core_grades_external.update_grades
public static function update_grades($source, $courseid, $component, $activityid, $itemnumber, $grades = array(), $itemdetails = array()) { global $CFG; $params = self::validate_parameters( self::update_grades_parameters(), array( 'source' => $source, 'courseid' => $courseid, 'component' => $component, 'activityid' => $activityid, 'itemnumber' => $itemnumber, 'grades' => $grades, 'itemdetails' => $itemdetails ) ); list($itemtype, $itemmodule) = normalize_component($params['component']); if (! $cm = get_coursemodule_from_id($itemmodule, $activityid)) { throw new moodle_exception('invalidcoursemodule'); } $iteminstance = $cm->instance; $coursecontext = context_course::instance($params['courseid']); try { self::validate_context($coursecontext); } catch (Exception $e) { $exceptionparam = new stdClass(); $exceptionparam->message = $e->getMessage(); $exceptionparam->courseid = $params['courseid']; throw new moodle_exception('errorcoursecontextnotvalid' , 'webservice', '', $exceptionparam); } $hidinggrades = false; $editinggradeitem = false; $editinggrades = false; $gradestructure = array(); foreach ($grades as $grade) { $editinggrades = true; $gradestructure[ $grade['studentid'] ] = array('userid' => $grade['studentid'], 'rawgrade' => $grade['grade']); } if (!empty($params['itemdetails'])) { if (isset($params['itemdetails']['hidden'])) { $hidinggrades = true; } else { $editinggradeitem = true; } } if ($editinggradeitem && !has_capability('moodle/grade:manage', $coursecontext)) { throw new moodle_exception('nopermissiontoviewgrades', 'error', '', null, 'moodle/grade:manage required to edit grade information'); } if ($hidinggrades && !has_capability('moodle/grade:hide', $coursecontext) && !has_capability('moodle/grade:hide', $coursecontext)) { throw new moodle_exception('nopermissiontoviewgrades', 'error', '', null, 'moodle/grade:hide required to hide grade items'); } if ($editinggrades && !has_capability('moodle/grade:edit', $coursecontext)) { throw new moodle_exception('nopermissiontoviewgrades', 'error', '', null, 'moodle/grade:edit required to edit grades'); } return grade_update($params['source'], $params['courseid'], $itemtype, $itemmodule, $iteminstance, $itemnumber, $gradestructure, $params['itemdetails']); }
php
public static function update_grades($source, $courseid, $component, $activityid, $itemnumber, $grades = array(), $itemdetails = array()) { global $CFG; $params = self::validate_parameters( self::update_grades_parameters(), array( 'source' => $source, 'courseid' => $courseid, 'component' => $component, 'activityid' => $activityid, 'itemnumber' => $itemnumber, 'grades' => $grades, 'itemdetails' => $itemdetails ) ); list($itemtype, $itemmodule) = normalize_component($params['component']); if (! $cm = get_coursemodule_from_id($itemmodule, $activityid)) { throw new moodle_exception('invalidcoursemodule'); } $iteminstance = $cm->instance; $coursecontext = context_course::instance($params['courseid']); try { self::validate_context($coursecontext); } catch (Exception $e) { $exceptionparam = new stdClass(); $exceptionparam->message = $e->getMessage(); $exceptionparam->courseid = $params['courseid']; throw new moodle_exception('errorcoursecontextnotvalid' , 'webservice', '', $exceptionparam); } $hidinggrades = false; $editinggradeitem = false; $editinggrades = false; $gradestructure = array(); foreach ($grades as $grade) { $editinggrades = true; $gradestructure[ $grade['studentid'] ] = array('userid' => $grade['studentid'], 'rawgrade' => $grade['grade']); } if (!empty($params['itemdetails'])) { if (isset($params['itemdetails']['hidden'])) { $hidinggrades = true; } else { $editinggradeitem = true; } } if ($editinggradeitem && !has_capability('moodle/grade:manage', $coursecontext)) { throw new moodle_exception('nopermissiontoviewgrades', 'error', '', null, 'moodle/grade:manage required to edit grade information'); } if ($hidinggrades && !has_capability('moodle/grade:hide', $coursecontext) && !has_capability('moodle/grade:hide', $coursecontext)) { throw new moodle_exception('nopermissiontoviewgrades', 'error', '', null, 'moodle/grade:hide required to hide grade items'); } if ($editinggrades && !has_capability('moodle/grade:edit', $coursecontext)) { throw new moodle_exception('nopermissiontoviewgrades', 'error', '', null, 'moodle/grade:edit required to edit grades'); } return grade_update($params['source'], $params['courseid'], $itemtype, $itemmodule, $iteminstance, $itemnumber, $gradestructure, $params['itemdetails']); }
[ "public", "static", "function", "update_grades", "(", "$", "source", ",", "$", "courseid", ",", "$", "component", ",", "$", "activityid", ",", "$", "itemnumber", ",", "$", "grades", "=", "array", "(", ")", ",", "$", "itemdetails", "=", "array", "(", ")", ")", "{", "global", "$", "CFG", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "update_grades_parameters", "(", ")", ",", "array", "(", "'source'", "=>", "$", "source", ",", "'courseid'", "=>", "$", "courseid", ",", "'component'", "=>", "$", "component", ",", "'activityid'", "=>", "$", "activityid", ",", "'itemnumber'", "=>", "$", "itemnumber", ",", "'grades'", "=>", "$", "grades", ",", "'itemdetails'", "=>", "$", "itemdetails", ")", ")", ";", "list", "(", "$", "itemtype", ",", "$", "itemmodule", ")", "=", "normalize_component", "(", "$", "params", "[", "'component'", "]", ")", ";", "if", "(", "!", "$", "cm", "=", "get_coursemodule_from_id", "(", "$", "itemmodule", ",", "$", "activityid", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'invalidcoursemodule'", ")", ";", "}", "$", "iteminstance", "=", "$", "cm", "->", "instance", ";", "$", "coursecontext", "=", "context_course", "::", "instance", "(", "$", "params", "[", "'courseid'", "]", ")", ";", "try", "{", "self", "::", "validate_context", "(", "$", "coursecontext", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "$", "exceptionparam", "=", "new", "stdClass", "(", ")", ";", "$", "exceptionparam", "->", "message", "=", "$", "e", "->", "getMessage", "(", ")", ";", "$", "exceptionparam", "->", "courseid", "=", "$", "params", "[", "'courseid'", "]", ";", "throw", "new", "moodle_exception", "(", "'errorcoursecontextnotvalid'", ",", "'webservice'", ",", "''", ",", "$", "exceptionparam", ")", ";", "}", "$", "hidinggrades", "=", "false", ";", "$", "editinggradeitem", "=", "false", ";", "$", "editinggrades", "=", "false", ";", "$", "gradestructure", "=", "array", "(", ")", ";", "foreach", "(", "$", "grades", "as", "$", "grade", ")", "{", "$", "editinggrades", "=", "true", ";", "$", "gradestructure", "[", "$", "grade", "[", "'studentid'", "]", "]", "=", "array", "(", "'userid'", "=>", "$", "grade", "[", "'studentid'", "]", ",", "'rawgrade'", "=>", "$", "grade", "[", "'grade'", "]", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "params", "[", "'itemdetails'", "]", ")", ")", "{", "if", "(", "isset", "(", "$", "params", "[", "'itemdetails'", "]", "[", "'hidden'", "]", ")", ")", "{", "$", "hidinggrades", "=", "true", ";", "}", "else", "{", "$", "editinggradeitem", "=", "true", ";", "}", "}", "if", "(", "$", "editinggradeitem", "&&", "!", "has_capability", "(", "'moodle/grade:manage'", ",", "$", "coursecontext", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'nopermissiontoviewgrades'", ",", "'error'", ",", "''", ",", "null", ",", "'moodle/grade:manage required to edit grade information'", ")", ";", "}", "if", "(", "$", "hidinggrades", "&&", "!", "has_capability", "(", "'moodle/grade:hide'", ",", "$", "coursecontext", ")", "&&", "!", "has_capability", "(", "'moodle/grade:hide'", ",", "$", "coursecontext", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'nopermissiontoviewgrades'", ",", "'error'", ",", "''", ",", "null", ",", "'moodle/grade:hide required to hide grade items'", ")", ";", "}", "if", "(", "$", "editinggrades", "&&", "!", "has_capability", "(", "'moodle/grade:edit'", ",", "$", "coursecontext", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'nopermissiontoviewgrades'", ",", "'error'", ",", "''", ",", "null", ",", "'moodle/grade:edit required to edit grades'", ")", ";", "}", "return", "grade_update", "(", "$", "params", "[", "'source'", "]", ",", "$", "params", "[", "'courseid'", "]", ",", "$", "itemtype", ",", "$", "itemmodule", ",", "$", "iteminstance", ",", "$", "itemnumber", ",", "$", "gradestructure", ",", "$", "params", "[", "'itemdetails'", "]", ")", ";", "}" ]
Update a grade item and, optionally, student grades @param string $source The source of the grade update @param int $courseid The course id @param string $component Component name @param int $activityid The activity id @param int $itemnumber The item number @param array $grades Array of grades @param array $itemdetails Array of item details @return int A status flag @since Moodle 2.7
[ "Update", "a", "grade", "item", "and", "optionally", "student", "grades" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/grades_external.php#L490-L558
217,882
moodle/moodle
lib/pear/HTML/QuickForm/Rule/Compare.php
HTML_QuickForm_Rule_Compare._findOperator
function _findOperator($name) { if (empty($name)) { return '=='; } elseif (isset($this->_operators[$name])) { return $this->_operators[$name]; } elseif (in_array($name, $this->_operators)) { return $name; } else { return '=='; } }
php
function _findOperator($name) { if (empty($name)) { return '=='; } elseif (isset($this->_operators[$name])) { return $this->_operators[$name]; } elseif (in_array($name, $this->_operators)) { return $name; } else { return '=='; } }
[ "function", "_findOperator", "(", "$", "name", ")", "{", "if", "(", "empty", "(", "$", "name", ")", ")", "{", "return", "'=='", ";", "}", "elseif", "(", "isset", "(", "$", "this", "->", "_operators", "[", "$", "name", "]", ")", ")", "{", "return", "$", "this", "->", "_operators", "[", "$", "name", "]", ";", "}", "elseif", "(", "in_array", "(", "$", "name", ",", "$", "this", "->", "_operators", ")", ")", "{", "return", "$", "name", ";", "}", "else", "{", "return", "'=='", ";", "}", "}" ]
Returns the operator to use for comparing the values @access private @param string operator name @return string operator to use for validation
[ "Returns", "the", "operator", "to", "use", "for", "comparing", "the", "values" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/Rule/Compare.php#L57-L68
217,883
moodle/moodle
repository/nextcloud/classes/issuer_management.php
issuer_management.is_valid_issuer
public static function is_valid_issuer(\core\oauth2\issuer $issuer) { $endpointwebdav = false; $endpointocs = false; $endpointtoken = false; $endpointauth = false; $endpointuserinfo = false; $endpoints = \core\oauth2\api::get_endpoints($issuer); foreach ($endpoints as $endpoint) { $name = $endpoint->get('name'); switch ($name) { case 'webdav_endpoint': $endpointwebdav = true; break; case 'ocs_endpoint': $endpointocs = true; break; case 'token_endpoint': $endpointtoken = true; break; case 'authorization_endpoint': $endpointauth = true; break; case 'userinfo_endpoint': $endpointuserinfo = true; break; } } return $endpointwebdav && $endpointocs && $endpointtoken && $endpointauth && $endpointuserinfo; }
php
public static function is_valid_issuer(\core\oauth2\issuer $issuer) { $endpointwebdav = false; $endpointocs = false; $endpointtoken = false; $endpointauth = false; $endpointuserinfo = false; $endpoints = \core\oauth2\api::get_endpoints($issuer); foreach ($endpoints as $endpoint) { $name = $endpoint->get('name'); switch ($name) { case 'webdav_endpoint': $endpointwebdav = true; break; case 'ocs_endpoint': $endpointocs = true; break; case 'token_endpoint': $endpointtoken = true; break; case 'authorization_endpoint': $endpointauth = true; break; case 'userinfo_endpoint': $endpointuserinfo = true; break; } } return $endpointwebdav && $endpointocs && $endpointtoken && $endpointauth && $endpointuserinfo; }
[ "public", "static", "function", "is_valid_issuer", "(", "\\", "core", "\\", "oauth2", "\\", "issuer", "$", "issuer", ")", "{", "$", "endpointwebdav", "=", "false", ";", "$", "endpointocs", "=", "false", ";", "$", "endpointtoken", "=", "false", ";", "$", "endpointauth", "=", "false", ";", "$", "endpointuserinfo", "=", "false", ";", "$", "endpoints", "=", "\\", "core", "\\", "oauth2", "\\", "api", "::", "get_endpoints", "(", "$", "issuer", ")", ";", "foreach", "(", "$", "endpoints", "as", "$", "endpoint", ")", "{", "$", "name", "=", "$", "endpoint", "->", "get", "(", "'name'", ")", ";", "switch", "(", "$", "name", ")", "{", "case", "'webdav_endpoint'", ":", "$", "endpointwebdav", "=", "true", ";", "break", ";", "case", "'ocs_endpoint'", ":", "$", "endpointocs", "=", "true", ";", "break", ";", "case", "'token_endpoint'", ":", "$", "endpointtoken", "=", "true", ";", "break", ";", "case", "'authorization_endpoint'", ":", "$", "endpointauth", "=", "true", ";", "break", ";", "case", "'userinfo_endpoint'", ":", "$", "endpointuserinfo", "=", "true", ";", "break", ";", "}", "}", "return", "$", "endpointwebdav", "&&", "$", "endpointocs", "&&", "$", "endpointtoken", "&&", "$", "endpointauth", "&&", "$", "endpointuserinfo", ";", "}" ]
Check if an issuer provides all endpoints that are required by repository_nextcloud. @param \core\oauth2\issuer $issuer An issuer. @return bool True, if all endpoints exist; false otherwise.
[ "Check", "if", "an", "issuer", "provides", "all", "endpoints", "that", "are", "required", "by", "repository_nextcloud", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/nextcloud/classes/issuer_management.php#L43-L71
217,884
moodle/moodle
repository/nextcloud/classes/issuer_management.php
issuer_management.parse_endpoint_url
public static function parse_endpoint_url(string $endpointname, \core\oauth2\issuer $issuer) : array { $url = $issuer->get_endpoint_url($endpointname); if (empty($url)) { throw new configuration_exception(get_string('endpointnotdefined', 'repository_nextcloud', $endpointname)); } return parse_url($url); }
php
public static function parse_endpoint_url(string $endpointname, \core\oauth2\issuer $issuer) : array { $url = $issuer->get_endpoint_url($endpointname); if (empty($url)) { throw new configuration_exception(get_string('endpointnotdefined', 'repository_nextcloud', $endpointname)); } return parse_url($url); }
[ "public", "static", "function", "parse_endpoint_url", "(", "string", "$", "endpointname", ",", "\\", "core", "\\", "oauth2", "\\", "issuer", "$", "issuer", ")", ":", "array", "{", "$", "url", "=", "$", "issuer", "->", "get_endpoint_url", "(", "$", "endpointname", ")", ";", "if", "(", "empty", "(", "$", "url", ")", ")", "{", "throw", "new", "configuration_exception", "(", "get_string", "(", "'endpointnotdefined'", ",", "'repository_nextcloud'", ",", "$", "endpointname", ")", ")", ";", "}", "return", "parse_url", "(", "$", "url", ")", ";", "}" ]
Returns the parsed url parts of an endpoint of an issuer. @param string $endpointname @param \core\oauth2\issuer $issuer @return array parseurl [scheme => https/http, host=>'hostname', port=>443, path=>'path'] @throws configuration_exception if an endpoint is undefined
[ "Returns", "the", "parsed", "url", "parts", "of", "an", "endpoint", "of", "an", "issuer", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/nextcloud/classes/issuer_management.php#L80-L86
217,885
moodle/moodle
lib/htmlpurifier/HTMLPurifier/Injector.php
HTMLPurifier_Injector.allowsElement
public function allowsElement($name) { if (!empty($this->currentNesting)) { $parent_token = array_pop($this->currentNesting); $this->currentNesting[] = $parent_token; $parent = $this->htmlDefinition->info[$parent_token->name]; } else { $parent = $this->htmlDefinition->info_parent_def; } if (!isset($parent->child->elements[$name]) || isset($parent->excludes[$name])) { return false; } // check for exclusion for ($i = count($this->currentNesting) - 2; $i >= 0; $i--) { $node = $this->currentNesting[$i]; $def = $this->htmlDefinition->info[$node->name]; if (isset($def->excludes[$name])) { return false; } } return true; }
php
public function allowsElement($name) { if (!empty($this->currentNesting)) { $parent_token = array_pop($this->currentNesting); $this->currentNesting[] = $parent_token; $parent = $this->htmlDefinition->info[$parent_token->name]; } else { $parent = $this->htmlDefinition->info_parent_def; } if (!isset($parent->child->elements[$name]) || isset($parent->excludes[$name])) { return false; } // check for exclusion for ($i = count($this->currentNesting) - 2; $i >= 0; $i--) { $node = $this->currentNesting[$i]; $def = $this->htmlDefinition->info[$node->name]; if (isset($def->excludes[$name])) { return false; } } return true; }
[ "public", "function", "allowsElement", "(", "$", "name", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "currentNesting", ")", ")", "{", "$", "parent_token", "=", "array_pop", "(", "$", "this", "->", "currentNesting", ")", ";", "$", "this", "->", "currentNesting", "[", "]", "=", "$", "parent_token", ";", "$", "parent", "=", "$", "this", "->", "htmlDefinition", "->", "info", "[", "$", "parent_token", "->", "name", "]", ";", "}", "else", "{", "$", "parent", "=", "$", "this", "->", "htmlDefinition", "->", "info_parent_def", ";", "}", "if", "(", "!", "isset", "(", "$", "parent", "->", "child", "->", "elements", "[", "$", "name", "]", ")", "||", "isset", "(", "$", "parent", "->", "excludes", "[", "$", "name", "]", ")", ")", "{", "return", "false", ";", "}", "// check for exclusion", "for", "(", "$", "i", "=", "count", "(", "$", "this", "->", "currentNesting", ")", "-", "2", ";", "$", "i", ">=", "0", ";", "$", "i", "--", ")", "{", "$", "node", "=", "$", "this", "->", "currentNesting", "[", "$", "i", "]", ";", "$", "def", "=", "$", "this", "->", "htmlDefinition", "->", "info", "[", "$", "node", "->", "name", "]", ";", "if", "(", "isset", "(", "$", "def", "->", "excludes", "[", "$", "name", "]", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Tests if the context node allows a certain element @param string $name Name of element to test for @return bool True if element is allowed, false if it is not
[ "Tests", "if", "the", "context", "node", "allows", "a", "certain", "element" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Injector.php#L147-L168
217,886
moodle/moodle
lib/lessphp/Cache.php
Less_Cache.Regen
public static function Regen( $less_files, $parser_options = array(), $modify_vars = array() ){ $parser_options['use_cache'] = false; return self::Get( $less_files, $parser_options, $modify_vars ); }
php
public static function Regen( $less_files, $parser_options = array(), $modify_vars = array() ){ $parser_options['use_cache'] = false; return self::Get( $less_files, $parser_options, $modify_vars ); }
[ "public", "static", "function", "Regen", "(", "$", "less_files", ",", "$", "parser_options", "=", "array", "(", ")", ",", "$", "modify_vars", "=", "array", "(", ")", ")", "{", "$", "parser_options", "[", "'use_cache'", "]", "=", "false", ";", "return", "self", "::", "Get", "(", "$", "less_files", ",", "$", "parser_options", ",", "$", "modify_vars", ")", ";", "}" ]
Force the compiler to regenerate the cached css file @param array $less_files Array of .less files to compile @param array $parser_options Array of compiler options @param array $modify_vars Array of variables @return string Name of the css file
[ "Force", "the", "compiler", "to", "regenerate", "the", "cached", "css", "file" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Cache.php#L140-L143
217,887
moodle/moodle
lib/lessphp/Cache.php
Less_Cache.ListFiles
static function ListFiles($list_file, &$list, &$css_file_name ){ $list = explode("\n",file_get_contents($list_file)); //pop the cached name that should match $compiled_name $css_file_name = array_pop($list); if( !preg_match('/^' . Less_Cache::$prefix . '[a-f0-9]+\.css$/',$css_file_name) ){ $list[] = $css_file_name; $css_file_name = false; } }
php
static function ListFiles($list_file, &$list, &$css_file_name ){ $list = explode("\n",file_get_contents($list_file)); //pop the cached name that should match $compiled_name $css_file_name = array_pop($list); if( !preg_match('/^' . Less_Cache::$prefix . '[a-f0-9]+\.css$/',$css_file_name) ){ $list[] = $css_file_name; $css_file_name = false; } }
[ "static", "function", "ListFiles", "(", "$", "list_file", ",", "&", "$", "list", ",", "&", "$", "css_file_name", ")", "{", "$", "list", "=", "explode", "(", "\"\\n\"", ",", "file_get_contents", "(", "$", "list_file", ")", ")", ";", "//pop the cached name that should match $compiled_name", "$", "css_file_name", "=", "array_pop", "(", "$", "list", ")", ";", "if", "(", "!", "preg_match", "(", "'/^'", ".", "Less_Cache", "::", "$", "prefix", ".", "'[a-f0-9]+\\.css$/'", ",", "$", "css_file_name", ")", ")", "{", "$", "list", "[", "]", "=", "$", "css_file_name", ";", "$", "css_file_name", "=", "false", ";", "}", "}" ]
Get the list of less files and generated css file from a list file
[ "Get", "the", "list", "of", "less", "files", "and", "generated", "css", "file", "from", "a", "list", "file" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Cache.php#L301-L313
217,888
moodle/moodle
privacy/classes/local/request/contextlist_base.php
contextlist_base.get_contexts
public function get_contexts() : array { $contexts = []; foreach ($this->contextids as $contextid) { // It is possible that this context has been deleted and we now have subsequent calls being made with this // contextlist. Exceptions here will stop the further processing of this component and that is why we are // doing a try catch. try { $contexts[] = \context::instance_by_id($contextid); } catch (\Exception $e) { // Remove this context. unset($this->contextids[$this->iteratorposition]); } } return $contexts; }
php
public function get_contexts() : array { $contexts = []; foreach ($this->contextids as $contextid) { // It is possible that this context has been deleted and we now have subsequent calls being made with this // contextlist. Exceptions here will stop the further processing of this component and that is why we are // doing a try catch. try { $contexts[] = \context::instance_by_id($contextid); } catch (\Exception $e) { // Remove this context. unset($this->contextids[$this->iteratorposition]); } } return $contexts; }
[ "public", "function", "get_contexts", "(", ")", ":", "array", "{", "$", "contexts", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "contextids", "as", "$", "contextid", ")", "{", "// It is possible that this context has been deleted and we now have subsequent calls being made with this", "// contextlist. Exceptions here will stop the further processing of this component and that is why we are", "// doing a try catch.", "try", "{", "$", "contexts", "[", "]", "=", "\\", "context", "::", "instance_by_id", "(", "$", "contextid", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "// Remove this context.", "unset", "(", "$", "this", "->", "contextids", "[", "$", "this", "->", "iteratorposition", "]", ")", ";", "}", "}", "return", "$", "contexts", ";", "}" ]
Get the complete list of context objects that relate to this request. @return \context[]
[ "Get", "the", "complete", "list", "of", "context", "objects", "that", "relate", "to", "this", "request", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/contextlist_base.php#L84-L99
217,889
moodle/moodle
privacy/classes/local/request/contextlist_base.php
contextlist_base.current
public function current() { // It is possible that this context has been deleted and we now have subsequent calls being made with this // contextlist. Exceptions here will stop the further processing of this component and that is why we are // doing a try catch. try { $context = \context::instance_by_id($this->contextids[$this->iteratorposition]); } catch (\Exception $e) { // Remove this context. unset($this->contextids[$this->iteratorposition]); // Check to see if there are any more contexts left. if ($this->count()) { // Move the pointer to the next record and try again. $this->next(); $context = $this->current(); } else { // There are no more context ids left. return; } } return $context; }
php
public function current() { // It is possible that this context has been deleted and we now have subsequent calls being made with this // contextlist. Exceptions here will stop the further processing of this component and that is why we are // doing a try catch. try { $context = \context::instance_by_id($this->contextids[$this->iteratorposition]); } catch (\Exception $e) { // Remove this context. unset($this->contextids[$this->iteratorposition]); // Check to see if there are any more contexts left. if ($this->count()) { // Move the pointer to the next record and try again. $this->next(); $context = $this->current(); } else { // There are no more context ids left. return; } } return $context; }
[ "public", "function", "current", "(", ")", "{", "// It is possible that this context has been deleted and we now have subsequent calls being made with this", "// contextlist. Exceptions here will stop the further processing of this component and that is why we are", "// doing a try catch.", "try", "{", "$", "context", "=", "\\", "context", "::", "instance_by_id", "(", "$", "this", "->", "contextids", "[", "$", "this", "->", "iteratorposition", "]", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "// Remove this context.", "unset", "(", "$", "this", "->", "contextids", "[", "$", "this", "->", "iteratorposition", "]", ")", ";", "// Check to see if there are any more contexts left.", "if", "(", "$", "this", "->", "count", "(", ")", ")", "{", "// Move the pointer to the next record and try again.", "$", "this", "->", "next", "(", ")", ";", "$", "context", "=", "$", "this", "->", "current", "(", ")", ";", "}", "else", "{", "// There are no more context ids left.", "return", ";", "}", "}", "return", "$", "context", ";", "}" ]
Return the current context. @return \context
[ "Return", "the", "current", "context", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/contextlist_base.php#L124-L144
217,890
moodle/moodle
mod/quiz/classes/repaginate.php
repaginate.get_this_slot
protected function get_this_slot($slots, $slotnumber) { foreach ($slots as $key => $slot) { if ($slot->slot == $slotnumber) { return $slot; } } return null; }
php
protected function get_this_slot($slots, $slotnumber) { foreach ($slots as $key => $slot) { if ($slot->slot == $slotnumber) { return $slot; } } return null; }
[ "protected", "function", "get_this_slot", "(", "$", "slots", ",", "$", "slotnumber", ")", "{", "foreach", "(", "$", "slots", "as", "$", "key", "=>", "$", "slot", ")", "{", "if", "(", "$", "slot", "->", "slot", "==", "$", "slotnumber", ")", "{", "return", "$", "slot", ";", "}", "}", "return", "null", ";", "}" ]
Return current slot object. @param array $slots @param int $slotnumber @return stdClass $slot
[ "Return", "current", "slot", "object", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/repaginate.php#L85-L92
217,891
moodle/moodle
mod/quiz/classes/repaginate.php
repaginate.get_slots_by_slot_number
protected function get_slots_by_slot_number($slots) { if (!$slots) { return array(); } $newslots = array(); foreach ($slots as $slot) { $newslots[$slot->slot] = $slot; } return $newslots; }
php
protected function get_slots_by_slot_number($slots) { if (!$slots) { return array(); } $newslots = array(); foreach ($slots as $slot) { $newslots[$slot->slot] = $slot; } return $newslots; }
[ "protected", "function", "get_slots_by_slot_number", "(", "$", "slots", ")", "{", "if", "(", "!", "$", "slots", ")", "{", "return", "array", "(", ")", ";", "}", "$", "newslots", "=", "array", "(", ")", ";", "foreach", "(", "$", "slots", "as", "$", "slot", ")", "{", "$", "newslots", "[", "$", "slot", "->", "slot", "]", "=", "$", "slot", ";", "}", "return", "$", "newslots", ";", "}" ]
Return array of slots with slot number as key @param stdClass[] $slots @return stdClass[]
[ "Return", "array", "of", "slots", "with", "slot", "number", "as", "key" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/repaginate.php#L99-L108
217,892
moodle/moodle
mod/quiz/classes/repaginate.php
repaginate.get_slots_by_slotid
protected function get_slots_by_slotid($slots) { if (!$slots) { return array(); } $newslots = array(); foreach ($slots as $slot) { $newslots[$slot->id] = $slot; } return $newslots; }
php
protected function get_slots_by_slotid($slots) { if (!$slots) { return array(); } $newslots = array(); foreach ($slots as $slot) { $newslots[$slot->id] = $slot; } return $newslots; }
[ "protected", "function", "get_slots_by_slotid", "(", "$", "slots", ")", "{", "if", "(", "!", "$", "slots", ")", "{", "return", "array", "(", ")", ";", "}", "$", "newslots", "=", "array", "(", ")", ";", "foreach", "(", "$", "slots", "as", "$", "slot", ")", "{", "$", "newslots", "[", "$", "slot", "->", "id", "]", "=", "$", "slot", ";", "}", "return", "$", "newslots", ";", "}" ]
Return array of slots with slot id as key @param stdClass[] $slots @return stdClass[]
[ "Return", "array", "of", "slots", "with", "slot", "id", "as", "key" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/repaginate.php#L115-L124
217,893
moodle/moodle
mod/quiz/classes/repaginate.php
repaginate.repaginate_slots
public function repaginate_slots($nextslotnumber, $type) { global $DB; $this->slots = $DB->get_records('quiz_slots', array('quizid' => $this->quizid), 'slot'); $nextslot = null; $newslots = array(); foreach ($this->slots as $slot) { if ($slot->slot < $nextslotnumber) { $newslots[$slot->id] = $slot; } else if ($slot->slot == $nextslotnumber) { $nextslot = $this->repaginate_next_slot($nextslotnumber, $type); // Update DB. $DB->update_record('quiz_slots', $nextslot, true); // Update returning object. $newslots[$slot->id] = $nextslot; } } if ($nextslot) { $newslots = array_merge($newslots, $this->repaginate_the_rest($this->slots, $nextslotnumber, $type)); $this->slots = $this->get_slots_by_slotid($newslots); } }
php
public function repaginate_slots($nextslotnumber, $type) { global $DB; $this->slots = $DB->get_records('quiz_slots', array('quizid' => $this->quizid), 'slot'); $nextslot = null; $newslots = array(); foreach ($this->slots as $slot) { if ($slot->slot < $nextslotnumber) { $newslots[$slot->id] = $slot; } else if ($slot->slot == $nextslotnumber) { $nextslot = $this->repaginate_next_slot($nextslotnumber, $type); // Update DB. $DB->update_record('quiz_slots', $nextslot, true); // Update returning object. $newslots[$slot->id] = $nextslot; } } if ($nextslot) { $newslots = array_merge($newslots, $this->repaginate_the_rest($this->slots, $nextslotnumber, $type)); $this->slots = $this->get_slots_by_slotid($newslots); } }
[ "public", "function", "repaginate_slots", "(", "$", "nextslotnumber", ",", "$", "type", ")", "{", "global", "$", "DB", ";", "$", "this", "->", "slots", "=", "$", "DB", "->", "get_records", "(", "'quiz_slots'", ",", "array", "(", "'quizid'", "=>", "$", "this", "->", "quizid", ")", ",", "'slot'", ")", ";", "$", "nextslot", "=", "null", ";", "$", "newslots", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "slots", "as", "$", "slot", ")", "{", "if", "(", "$", "slot", "->", "slot", "<", "$", "nextslotnumber", ")", "{", "$", "newslots", "[", "$", "slot", "->", "id", "]", "=", "$", "slot", ";", "}", "else", "if", "(", "$", "slot", "->", "slot", "==", "$", "nextslotnumber", ")", "{", "$", "nextslot", "=", "$", "this", "->", "repaginate_next_slot", "(", "$", "nextslotnumber", ",", "$", "type", ")", ";", "// Update DB.", "$", "DB", "->", "update_record", "(", "'quiz_slots'", ",", "$", "nextslot", ",", "true", ")", ";", "// Update returning object.", "$", "newslots", "[", "$", "slot", "->", "id", "]", "=", "$", "nextslot", ";", "}", "}", "if", "(", "$", "nextslot", ")", "{", "$", "newslots", "=", "array_merge", "(", "$", "newslots", ",", "$", "this", "->", "repaginate_the_rest", "(", "$", "this", "->", "slots", ",", "$", "nextslotnumber", ",", "$", "type", ")", ")", ";", "$", "this", "->", "slots", "=", "$", "this", "->", "get_slots_by_slotid", "(", "$", "newslots", ")", ";", "}", "}" ]
Repaginate, update DB and slots object @param int $nextslotnumber @param int $type repaginate::LINK or repaginate::UNLINK.
[ "Repaginate", "update", "DB", "and", "slots", "object" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/repaginate.php#L131-L153
217,894
moodle/moodle
mod/quiz/classes/repaginate.php
repaginate.repaginate_next_slot
public function repaginate_next_slot($nextslotnumber, $type) { $currentslotnumber = $nextslotnumber - 1; if (!($currentslotnumber && $nextslotnumber)) { return null; } $currentslot = $this->get_this_slot($this->slots, $currentslotnumber); $nextslot = $this->get_this_slot($this->slots, $nextslotnumber); if ($type === self::LINK) { return $this->repaginate_this_slot($nextslot, $currentslot->page); } else if ($type === self::UNLINK) { return $this->repaginate_this_slot($nextslot, $nextslot->page + 1); } return null; }
php
public function repaginate_next_slot($nextslotnumber, $type) { $currentslotnumber = $nextslotnumber - 1; if (!($currentslotnumber && $nextslotnumber)) { return null; } $currentslot = $this->get_this_slot($this->slots, $currentslotnumber); $nextslot = $this->get_this_slot($this->slots, $nextslotnumber); if ($type === self::LINK) { return $this->repaginate_this_slot($nextslot, $currentslot->page); } else if ($type === self::UNLINK) { return $this->repaginate_this_slot($nextslot, $nextslot->page + 1); } return null; }
[ "public", "function", "repaginate_next_slot", "(", "$", "nextslotnumber", ",", "$", "type", ")", "{", "$", "currentslotnumber", "=", "$", "nextslotnumber", "-", "1", ";", "if", "(", "!", "(", "$", "currentslotnumber", "&&", "$", "nextslotnumber", ")", ")", "{", "return", "null", ";", "}", "$", "currentslot", "=", "$", "this", "->", "get_this_slot", "(", "$", "this", "->", "slots", ",", "$", "currentslotnumber", ")", ";", "$", "nextslot", "=", "$", "this", "->", "get_this_slot", "(", "$", "this", "->", "slots", ",", "$", "nextslotnumber", ")", ";", "if", "(", "$", "type", "===", "self", "::", "LINK", ")", "{", "return", "$", "this", "->", "repaginate_this_slot", "(", "$", "nextslot", ",", "$", "currentslot", "->", "page", ")", ";", "}", "else", "if", "(", "$", "type", "===", "self", "::", "UNLINK", ")", "{", "return", "$", "this", "->", "repaginate_this_slot", "(", "$", "nextslot", ",", "$", "nextslot", "->", "page", "+", "1", ")", ";", "}", "return", "null", ";", "}" ]
Repaginate next slot and return the modified slot object @param int $nextslotnumber @param int $type repaginate::LINK or repaginate::UNLINK. @return stdClass|null
[ "Repaginate", "next", "slot", "and", "return", "the", "modified", "slot", "object" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/repaginate.php#L161-L175
217,895
moodle/moodle
mod/quiz/classes/repaginate.php
repaginate.repaginate_n_question_per_page
public function repaginate_n_question_per_page($slots, $number) { $slots = $this->get_slots_by_slot_number($slots); $newslots = array(); $count = 0; $page = 1; foreach ($slots as $key => $slot) { for ($page + $count; $page < ($number + $count + 1); $page++) { if ($slot->slot >= $page) { $slot->page = $page; $count++; } } $newslots[$slot->id] = $slot; } return $newslots; }
php
public function repaginate_n_question_per_page($slots, $number) { $slots = $this->get_slots_by_slot_number($slots); $newslots = array(); $count = 0; $page = 1; foreach ($slots as $key => $slot) { for ($page + $count; $page < ($number + $count + 1); $page++) { if ($slot->slot >= $page) { $slot->page = $page; $count++; } } $newslots[$slot->id] = $slot; } return $newslots; }
[ "public", "function", "repaginate_n_question_per_page", "(", "$", "slots", ",", "$", "number", ")", "{", "$", "slots", "=", "$", "this", "->", "get_slots_by_slot_number", "(", "$", "slots", ")", ";", "$", "newslots", "=", "array", "(", ")", ";", "$", "count", "=", "0", ";", "$", "page", "=", "1", ";", "foreach", "(", "$", "slots", "as", "$", "key", "=>", "$", "slot", ")", "{", "for", "(", "$", "page", "+", "$", "count", ";", "$", "page", "<", "(", "$", "number", "+", "$", "count", "+", "1", ")", ";", "$", "page", "++", ")", "{", "if", "(", "$", "slot", "->", "slot", ">=", "$", "page", ")", "{", "$", "slot", "->", "page", "=", "$", "page", ";", "$", "count", "++", ";", "}", "}", "$", "newslots", "[", "$", "slot", "->", "id", "]", "=", "$", "slot", ";", "}", "return", "$", "newslots", ";", "}" ]
Return the slots with the new pagination, regardless of current pagination. @param stdClass[] $slots the slots to repaginate. @param int $number number of question per page @return stdClass[] the updated slots.
[ "Return", "the", "slots", "with", "the", "new", "pagination", "regardless", "of", "current", "pagination", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/repaginate.php#L183-L198
217,896
moodle/moodle
mod/quiz/classes/repaginate.php
repaginate.repaginate_the_rest
public function repaginate_the_rest($quizslots, $slotfrom, $type, $dbupdate = true) { global $DB; if (!$quizslots) { return null; } $newslots = array(); foreach ($quizslots as $slot) { if ($type == self::LINK) { if ($slot->slot <= $slotfrom) { continue; } $slot->page = $slot->page - 1; } else if ($type == self::UNLINK) { if ($slot->slot <= $slotfrom - 1) { continue; } $slot->page = $slot->page + 1; } // Update DB. if ($dbupdate) { $DB->update_record('quiz_slots', $slot); } $newslots[$slot->id] = $slot; } return $newslots; }
php
public function repaginate_the_rest($quizslots, $slotfrom, $type, $dbupdate = true) { global $DB; if (!$quizslots) { return null; } $newslots = array(); foreach ($quizslots as $slot) { if ($type == self::LINK) { if ($slot->slot <= $slotfrom) { continue; } $slot->page = $slot->page - 1; } else if ($type == self::UNLINK) { if ($slot->slot <= $slotfrom - 1) { continue; } $slot->page = $slot->page + 1; } // Update DB. if ($dbupdate) { $DB->update_record('quiz_slots', $slot); } $newslots[$slot->id] = $slot; } return $newslots; }
[ "public", "function", "repaginate_the_rest", "(", "$", "quizslots", ",", "$", "slotfrom", ",", "$", "type", ",", "$", "dbupdate", "=", "true", ")", "{", "global", "$", "DB", ";", "if", "(", "!", "$", "quizslots", ")", "{", "return", "null", ";", "}", "$", "newslots", "=", "array", "(", ")", ";", "foreach", "(", "$", "quizslots", "as", "$", "slot", ")", "{", "if", "(", "$", "type", "==", "self", "::", "LINK", ")", "{", "if", "(", "$", "slot", "->", "slot", "<=", "$", "slotfrom", ")", "{", "continue", ";", "}", "$", "slot", "->", "page", "=", "$", "slot", "->", "page", "-", "1", ";", "}", "else", "if", "(", "$", "type", "==", "self", "::", "UNLINK", ")", "{", "if", "(", "$", "slot", "->", "slot", "<=", "$", "slotfrom", "-", "1", ")", "{", "continue", ";", "}", "$", "slot", "->", "page", "=", "$", "slot", "->", "page", "+", "1", ";", "}", "// Update DB.", "if", "(", "$", "dbupdate", ")", "{", "$", "DB", "->", "update_record", "(", "'quiz_slots'", ",", "$", "slot", ")", ";", "}", "$", "newslots", "[", "$", "slot", "->", "id", "]", "=", "$", "slot", ";", "}", "return", "$", "newslots", ";", "}" ]
Repaginate the rest. @param stdClass[] $quizslots @param int $slotfrom @param int $type @param bool $dbupdate @return stdClass[]
[ "Repaginate", "the", "rest", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/repaginate.php#L208-L233
217,897
moodle/moodle
mod/assign/feedback/comments/classes/privacy/provider.php
provider.delete_feedback_for_grade
public static function delete_feedback_for_grade(assign_plugin_request_data $requestdata) { global $DB; $fs = new \file_storage(); $fs->delete_area_files($requestdata->get_context()->id, ASSIGNFEEDBACK_COMMENTS_COMPONENT, ASSIGNFEEDBACK_COMMENTS_FILEAREA, $requestdata->get_pluginobject()->id); $DB->delete_records('assignfeedback_comments', ['assignment' => $requestdata->get_assignid(), 'grade' => $requestdata->get_pluginobject()->id]); }
php
public static function delete_feedback_for_grade(assign_plugin_request_data $requestdata) { global $DB; $fs = new \file_storage(); $fs->delete_area_files($requestdata->get_context()->id, ASSIGNFEEDBACK_COMMENTS_COMPONENT, ASSIGNFEEDBACK_COMMENTS_FILEAREA, $requestdata->get_pluginobject()->id); $DB->delete_records('assignfeedback_comments', ['assignment' => $requestdata->get_assignid(), 'grade' => $requestdata->get_pluginobject()->id]); }
[ "public", "static", "function", "delete_feedback_for_grade", "(", "assign_plugin_request_data", "$", "requestdata", ")", "{", "global", "$", "DB", ";", "$", "fs", "=", "new", "\\", "file_storage", "(", ")", ";", "$", "fs", "->", "delete_area_files", "(", "$", "requestdata", "->", "get_context", "(", ")", "->", "id", ",", "ASSIGNFEEDBACK_COMMENTS_COMPONENT", ",", "ASSIGNFEEDBACK_COMMENTS_FILEAREA", ",", "$", "requestdata", "->", "get_pluginobject", "(", ")", "->", "id", ")", ";", "$", "DB", "->", "delete_records", "(", "'assignfeedback_comments'", ",", "[", "'assignment'", "=>", "$", "requestdata", "->", "get_assignid", "(", ")", ",", "'grade'", "=>", "$", "requestdata", "->", "get_pluginobject", "(", ")", "->", "id", "]", ")", ";", "}" ]
Calling this function should delete all user data associated with this grade entry. @param assign_plugin_request_data $requestdata Data useful for deleting user data.
[ "Calling", "this", "function", "should", "delete", "all", "user", "data", "associated", "with", "this", "grade", "entry", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/comments/classes/privacy/provider.php#L153-L162
217,898
moodle/moodle
lib/portfolio/forms.php
portfolio_export_form.validation
public function validation($data, $files) { $errors = array(); if (array_key_exists('plugin', $this->_customdata) && is_object($this->_customdata['plugin'])) { $pluginerrors = $this->_customdata['plugin']->export_config_validation($data); if (is_array($pluginerrors)) { $errors = $pluginerrors; } } if (array_key_exists('caller', $this->_customdata) && is_object($this->_customdata['caller'])) { $callererrors = $this->_customdata['caller']->export_config_validation($data); if (is_array($callererrors)) { $errors = array_merge($errors, $callererrors); } } return $errors; }
php
public function validation($data, $files) { $errors = array(); if (array_key_exists('plugin', $this->_customdata) && is_object($this->_customdata['plugin'])) { $pluginerrors = $this->_customdata['plugin']->export_config_validation($data); if (is_array($pluginerrors)) { $errors = $pluginerrors; } } if (array_key_exists('caller', $this->_customdata) && is_object($this->_customdata['caller'])) { $callererrors = $this->_customdata['caller']->export_config_validation($data); if (is_array($callererrors)) { $errors = array_merge($errors, $callererrors); } } return $errors; }
[ "public", "function", "validation", "(", "$", "data", ",", "$", "files", ")", "{", "$", "errors", "=", "array", "(", ")", ";", "if", "(", "array_key_exists", "(", "'plugin'", ",", "$", "this", "->", "_customdata", ")", "&&", "is_object", "(", "$", "this", "->", "_customdata", "[", "'plugin'", "]", ")", ")", "{", "$", "pluginerrors", "=", "$", "this", "->", "_customdata", "[", "'plugin'", "]", "->", "export_config_validation", "(", "$", "data", ")", ";", "if", "(", "is_array", "(", "$", "pluginerrors", ")", ")", "{", "$", "errors", "=", "$", "pluginerrors", ";", "}", "}", "if", "(", "array_key_exists", "(", "'caller'", ",", "$", "this", "->", "_customdata", ")", "&&", "is_object", "(", "$", "this", "->", "_customdata", "[", "'caller'", "]", ")", ")", "{", "$", "callererrors", "=", "$", "this", "->", "_customdata", "[", "'caller'", "]", "->", "export_config_validation", "(", "$", "data", ")", ";", "if", "(", "is_array", "(", "$", "callererrors", ")", ")", "{", "$", "errors", "=", "array_merge", "(", "$", "errors", ",", "$", "callererrors", ")", ";", "}", "}", "return", "$", "errors", ";", "}" ]
Validate portfolio export form @param stdClass $data portfolio information from form data @return array
[ "Validate", "portfolio", "export", "form" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/forms.php#L110-L127
217,899
moodle/moodle
lib/portfolio/forms.php
portfolio_admin_form.validation
public function validation($data, $files) { global $DB; $errors = array(); if ($DB->count_records('portfolio_instance', array('name' => $data['name'], 'plugin' => $data['plugin'])) > 1) { $errors = array('name' => get_string('err_uniquename', 'portfolio')); } $pluginerrors = array(); $pluginerrors = portfolio_static_function($this->plugin, 'admin_config_validation', $data); if (is_array($pluginerrors)) { $errors = array_merge($errors, $pluginerrors); } return $errors; }
php
public function validation($data, $files) { global $DB; $errors = array(); if ($DB->count_records('portfolio_instance', array('name' => $data['name'], 'plugin' => $data['plugin'])) > 1) { $errors = array('name' => get_string('err_uniquename', 'portfolio')); } $pluginerrors = array(); $pluginerrors = portfolio_static_function($this->plugin, 'admin_config_validation', $data); if (is_array($pluginerrors)) { $errors = array_merge($errors, $pluginerrors); } return $errors; }
[ "public", "function", "validation", "(", "$", "data", ",", "$", "files", ")", "{", "global", "$", "DB", ";", "$", "errors", "=", "array", "(", ")", ";", "if", "(", "$", "DB", "->", "count_records", "(", "'portfolio_instance'", ",", "array", "(", "'name'", "=>", "$", "data", "[", "'name'", "]", ",", "'plugin'", "=>", "$", "data", "[", "'plugin'", "]", ")", ")", ">", "1", ")", "{", "$", "errors", "=", "array", "(", "'name'", "=>", "get_string", "(", "'err_uniquename'", ",", "'portfolio'", ")", ")", ";", "}", "$", "pluginerrors", "=", "array", "(", ")", ";", "$", "pluginerrors", "=", "portfolio_static_function", "(", "$", "this", "->", "plugin", ",", "'admin_config_validation'", ",", "$", "data", ")", ";", "if", "(", "is_array", "(", "$", "pluginerrors", ")", ")", "{", "$", "errors", "=", "array_merge", "(", "$", "errors", ",", "$", "pluginerrors", ")", ";", "}", "return", "$", "errors", ";", "}" ]
Validate admin config form @param stdObject $data form data @return array
[ "Validate", "admin", "config", "form" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/forms.php#L229-L243