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
216,700
moodle/moodle
backup/util/ui/base_moodleform.class.php
base_moodleform.get_element
public function get_element($elementname) { if ($this->_form->elementExists($elementname)) { return $this->_form->getElement($elementname); } else { return false; } }
php
public function get_element($elementname) { if ($this->_form->elementExists($elementname)) { return $this->_form->getElement($elementname); } else { return false; } }
[ "public", "function", "get_element", "(", "$", "elementname", ")", "{", "if", "(", "$", "this", "->", "_form", "->", "elementExists", "(", "$", "elementname", ")", ")", "{", "return", "$", "this", "->", "_form", "->", "getElement", "(", "$", "elementname", ")", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Gets an element from the form if it exists @param string $elementname @return HTML_QuickForm_input|MoodleQuickForm_group
[ "Gets", "an", "element", "from", "the", "form", "if", "it", "exists" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/base_moodleform.class.php#L369-L375
216,701
moodle/moodle
mod/book/classes/external.php
mod_book_external.get_books_by_courses
public static function get_books_by_courses($courseids = array()) { global $CFG; $returnedbooks = array(); $warnings = array(); $params = self::validate_parameters(self::get_books_by_courses_parameters(), array('courseids' => $courseids)); $courses = array(); if (empty($params['courseids'])) { $courses = enrol_get_my_courses(); $params['courseids'] = array_keys($courses); } // Ensure there are courseids to loop through. if (!empty($params['courseids'])) { list($courses, $warnings) = external_util::validate_courses($params['courseids'], $courses); // Get the books in this course, this function checks users visibility permissions. // We can avoid then additional validate_context calls. $books = get_all_instances_in_courses("book", $courses); foreach ($books as $book) { $context = context_module::instance($book->coursemodule); // Entry to return. $bookdetails = array(); // First, we return information that any user can see in the web interface. $bookdetails['id'] = $book->id; $bookdetails['coursemodule'] = $book->coursemodule; $bookdetails['course'] = $book->course; $bookdetails['name'] = external_format_string($book->name, $context->id); // Format intro. list($bookdetails['intro'], $bookdetails['introformat']) = external_format_text($book->intro, $book->introformat, $context->id, 'mod_book', 'intro', null); $bookdetails['introfiles'] = external_util::get_area_files($context->id, 'mod_book', 'intro', false, false); $bookdetails['numbering'] = $book->numbering; $bookdetails['navstyle'] = $book->navstyle; $bookdetails['customtitles'] = $book->customtitles; if (has_capability('moodle/course:manageactivities', $context)) { $bookdetails['revision'] = $book->revision; $bookdetails['timecreated'] = $book->timecreated; $bookdetails['timemodified'] = $book->timemodified; $bookdetails['section'] = $book->section; $bookdetails['visible'] = $book->visible; $bookdetails['groupmode'] = $book->groupmode; $bookdetails['groupingid'] = $book->groupingid; } $returnedbooks[] = $bookdetails; } } $result = array(); $result['books'] = $returnedbooks; $result['warnings'] = $warnings; return $result; }
php
public static function get_books_by_courses($courseids = array()) { global $CFG; $returnedbooks = array(); $warnings = array(); $params = self::validate_parameters(self::get_books_by_courses_parameters(), array('courseids' => $courseids)); $courses = array(); if (empty($params['courseids'])) { $courses = enrol_get_my_courses(); $params['courseids'] = array_keys($courses); } // Ensure there are courseids to loop through. if (!empty($params['courseids'])) { list($courses, $warnings) = external_util::validate_courses($params['courseids'], $courses); // Get the books in this course, this function checks users visibility permissions. // We can avoid then additional validate_context calls. $books = get_all_instances_in_courses("book", $courses); foreach ($books as $book) { $context = context_module::instance($book->coursemodule); // Entry to return. $bookdetails = array(); // First, we return information that any user can see in the web interface. $bookdetails['id'] = $book->id; $bookdetails['coursemodule'] = $book->coursemodule; $bookdetails['course'] = $book->course; $bookdetails['name'] = external_format_string($book->name, $context->id); // Format intro. list($bookdetails['intro'], $bookdetails['introformat']) = external_format_text($book->intro, $book->introformat, $context->id, 'mod_book', 'intro', null); $bookdetails['introfiles'] = external_util::get_area_files($context->id, 'mod_book', 'intro', false, false); $bookdetails['numbering'] = $book->numbering; $bookdetails['navstyle'] = $book->navstyle; $bookdetails['customtitles'] = $book->customtitles; if (has_capability('moodle/course:manageactivities', $context)) { $bookdetails['revision'] = $book->revision; $bookdetails['timecreated'] = $book->timecreated; $bookdetails['timemodified'] = $book->timemodified; $bookdetails['section'] = $book->section; $bookdetails['visible'] = $book->visible; $bookdetails['groupmode'] = $book->groupmode; $bookdetails['groupingid'] = $book->groupingid; } $returnedbooks[] = $bookdetails; } } $result = array(); $result['books'] = $returnedbooks; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "get_books_by_courses", "(", "$", "courseids", "=", "array", "(", ")", ")", "{", "global", "$", "CFG", ";", "$", "returnedbooks", "=", "array", "(", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_books_by_courses_parameters", "(", ")", ",", "array", "(", "'courseids'", "=>", "$", "courseids", ")", ")", ";", "$", "courses", "=", "array", "(", ")", ";", "if", "(", "empty", "(", "$", "params", "[", "'courseids'", "]", ")", ")", "{", "$", "courses", "=", "enrol_get_my_courses", "(", ")", ";", "$", "params", "[", "'courseids'", "]", "=", "array_keys", "(", "$", "courses", ")", ";", "}", "// Ensure there are courseids to loop through.", "if", "(", "!", "empty", "(", "$", "params", "[", "'courseids'", "]", ")", ")", "{", "list", "(", "$", "courses", ",", "$", "warnings", ")", "=", "external_util", "::", "validate_courses", "(", "$", "params", "[", "'courseids'", "]", ",", "$", "courses", ")", ";", "// Get the books in this course, this function checks users visibility permissions.", "// We can avoid then additional validate_context calls.", "$", "books", "=", "get_all_instances_in_courses", "(", "\"book\"", ",", "$", "courses", ")", ";", "foreach", "(", "$", "books", "as", "$", "book", ")", "{", "$", "context", "=", "context_module", "::", "instance", "(", "$", "book", "->", "coursemodule", ")", ";", "// Entry to return.", "$", "bookdetails", "=", "array", "(", ")", ";", "// First, we return information that any user can see in the web interface.", "$", "bookdetails", "[", "'id'", "]", "=", "$", "book", "->", "id", ";", "$", "bookdetails", "[", "'coursemodule'", "]", "=", "$", "book", "->", "coursemodule", ";", "$", "bookdetails", "[", "'course'", "]", "=", "$", "book", "->", "course", ";", "$", "bookdetails", "[", "'name'", "]", "=", "external_format_string", "(", "$", "book", "->", "name", ",", "$", "context", "->", "id", ")", ";", "// Format intro.", "list", "(", "$", "bookdetails", "[", "'intro'", "]", ",", "$", "bookdetails", "[", "'introformat'", "]", ")", "=", "external_format_text", "(", "$", "book", "->", "intro", ",", "$", "book", "->", "introformat", ",", "$", "context", "->", "id", ",", "'mod_book'", ",", "'intro'", ",", "null", ")", ";", "$", "bookdetails", "[", "'introfiles'", "]", "=", "external_util", "::", "get_area_files", "(", "$", "context", "->", "id", ",", "'mod_book'", ",", "'intro'", ",", "false", ",", "false", ")", ";", "$", "bookdetails", "[", "'numbering'", "]", "=", "$", "book", "->", "numbering", ";", "$", "bookdetails", "[", "'navstyle'", "]", "=", "$", "book", "->", "navstyle", ";", "$", "bookdetails", "[", "'customtitles'", "]", "=", "$", "book", "->", "customtitles", ";", "if", "(", "has_capability", "(", "'moodle/course:manageactivities'", ",", "$", "context", ")", ")", "{", "$", "bookdetails", "[", "'revision'", "]", "=", "$", "book", "->", "revision", ";", "$", "bookdetails", "[", "'timecreated'", "]", "=", "$", "book", "->", "timecreated", ";", "$", "bookdetails", "[", "'timemodified'", "]", "=", "$", "book", "->", "timemodified", ";", "$", "bookdetails", "[", "'section'", "]", "=", "$", "book", "->", "section", ";", "$", "bookdetails", "[", "'visible'", "]", "=", "$", "book", "->", "visible", ";", "$", "bookdetails", "[", "'groupmode'", "]", "=", "$", "book", "->", "groupmode", ";", "$", "bookdetails", "[", "'groupingid'", "]", "=", "$", "book", "->", "groupingid", ";", "}", "$", "returnedbooks", "[", "]", "=", "$", "bookdetails", ";", "}", "}", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'books'", "]", "=", "$", "returnedbooks", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Returns a list of books in a provided list of courses, if no list is provided all books that the user can view will be returned. @param array $courseids the course ids @return array of books details @since Moodle 3.0
[ "Returns", "a", "list", "of", "books", "in", "a", "provided", "list", "of", "courses", "if", "no", "list", "is", "provided", "all", "books", "that", "the", "user", "can", "view", "will", "be", "returned", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/book/classes/external.php#L176-L231
216,702
moodle/moodle
lib/horde/framework/Horde/Support/Randomid.php
Horde_Support_Randomid.generate
public function generate() { $elts = array( uniqid(), mt_rand(), getmypid(), spl_object_hash($this) ); if (function_exists('zend_thread_id')) { $elts[] = zend_thread_id(); } if (function_exists('sys_getloadavg') && ($loadavg = sys_getloadavg())) { $elts = array_merge($elts, $loadavg); } if (function_exists('memory_get_usage')) { $elts[] = memory_get_usage(); $elts[] = memory_get_peak_usage(); } shuffle($elts); /* Base64 can have /, +, and = characters. Restrict to URL-safe * characters. */ return substr(str_replace( array('/', '+', '='), array('-', '_', ''), base64_encode(hash('sha1', serialize($elts), true)) ), 0, 23); }
php
public function generate() { $elts = array( uniqid(), mt_rand(), getmypid(), spl_object_hash($this) ); if (function_exists('zend_thread_id')) { $elts[] = zend_thread_id(); } if (function_exists('sys_getloadavg') && ($loadavg = sys_getloadavg())) { $elts = array_merge($elts, $loadavg); } if (function_exists('memory_get_usage')) { $elts[] = memory_get_usage(); $elts[] = memory_get_peak_usage(); } shuffle($elts); /* Base64 can have /, +, and = characters. Restrict to URL-safe * characters. */ return substr(str_replace( array('/', '+', '='), array('-', '_', ''), base64_encode(hash('sha1', serialize($elts), true)) ), 0, 23); }
[ "public", "function", "generate", "(", ")", "{", "$", "elts", "=", "array", "(", "uniqid", "(", ")", ",", "mt_rand", "(", ")", ",", "getmypid", "(", ")", ",", "spl_object_hash", "(", "$", "this", ")", ")", ";", "if", "(", "function_exists", "(", "'zend_thread_id'", ")", ")", "{", "$", "elts", "[", "]", "=", "zend_thread_id", "(", ")", ";", "}", "if", "(", "function_exists", "(", "'sys_getloadavg'", ")", "&&", "(", "$", "loadavg", "=", "sys_getloadavg", "(", ")", ")", ")", "{", "$", "elts", "=", "array_merge", "(", "$", "elts", ",", "$", "loadavg", ")", ";", "}", "if", "(", "function_exists", "(", "'memory_get_usage'", ")", ")", "{", "$", "elts", "[", "]", "=", "memory_get_usage", "(", ")", ";", "$", "elts", "[", "]", "=", "memory_get_peak_usage", "(", ")", ";", "}", "shuffle", "(", "$", "elts", ")", ";", "/* Base64 can have /, +, and = characters. Restrict to URL-safe\n * characters. */", "return", "substr", "(", "str_replace", "(", "array", "(", "'/'", ",", "'+'", ",", "'='", ")", ",", "array", "(", "'-'", ",", "'_'", ",", "''", ")", ",", "base64_encode", "(", "hash", "(", "'sha1'", ",", "serialize", "(", "$", "elts", ")", ",", "true", ")", ")", ")", ",", "0", ",", "23", ")", ";", "}" ]
Generate a random ID.
[ "Generate", "a", "random", "ID", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Support/Randomid.php#L37-L66
216,703
moodle/moodle
backup/moodle2/backup_section_task.class.php
backup_section_task.execute
public function execute() { // Find section_included_setting if (!$this->get_setting_value('included')) { $this->log('section skipped by _included setting', backup::LOG_DEBUG, $this->name); } else { // Setting tells us it's ok to execute parent::execute(); } }
php
public function execute() { // Find section_included_setting if (!$this->get_setting_value('included')) { $this->log('section skipped by _included setting', backup::LOG_DEBUG, $this->name); } else { // Setting tells us it's ok to execute parent::execute(); } }
[ "public", "function", "execute", "(", ")", "{", "// Find section_included_setting", "if", "(", "!", "$", "this", "->", "get_setting_value", "(", "'included'", ")", ")", "{", "$", "this", "->", "log", "(", "'section skipped by _included setting'", ",", "backup", "::", "LOG_DEBUG", ",", "$", "this", "->", "name", ")", ";", "}", "else", "{", "// Setting tells us it's ok to execute", "parent", "::", "execute", "(", ")", ";", "}", "}" ]
Exceptionally override the execute method, so, based in the section_included setting, we are able to skip the execution of one task completely
[ "Exceptionally", "override", "the", "execute", "method", "so", "based", "in", "the", "section_included", "setting", "we", "are", "able", "to", "skip", "the", "execution", "of", "one", "task", "completely" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/moodle2/backup_section_task.class.php#L101-L110
216,704
moodle/moodle
backup/moodle2/backup_section_task.class.php
backup_section_task.get_setting
public function get_setting($name) { $namewithprefix = 'section_' . $this->sectionid . '_' . $name; $result = null; foreach ($this->settings as $key => $setting) { if ($setting->get_name() == $namewithprefix) { if ($result != null) { throw new base_task_exception('multiple_settings_by_name_found', $namewithprefix); } else { $result = $setting; } } } if ($result) { return $result; } else { // Fallback to parent return parent::get_setting($name); } }
php
public function get_setting($name) { $namewithprefix = 'section_' . $this->sectionid . '_' . $name; $result = null; foreach ($this->settings as $key => $setting) { if ($setting->get_name() == $namewithprefix) { if ($result != null) { throw new base_task_exception('multiple_settings_by_name_found', $namewithprefix); } else { $result = $setting; } } } if ($result) { return $result; } else { // Fallback to parent return parent::get_setting($name); } }
[ "public", "function", "get_setting", "(", "$", "name", ")", "{", "$", "namewithprefix", "=", "'section_'", ".", "$", "this", "->", "sectionid", ".", "'_'", ".", "$", "name", ";", "$", "result", "=", "null", ";", "foreach", "(", "$", "this", "->", "settings", "as", "$", "key", "=>", "$", "setting", ")", "{", "if", "(", "$", "setting", "->", "get_name", "(", ")", "==", "$", "namewithprefix", ")", "{", "if", "(", "$", "result", "!=", "null", ")", "{", "throw", "new", "base_task_exception", "(", "'multiple_settings_by_name_found'", ",", "$", "namewithprefix", ")", ";", "}", "else", "{", "$", "result", "=", "$", "setting", ";", "}", "}", "}", "if", "(", "$", "result", ")", "{", "return", "$", "result", ";", "}", "else", "{", "// Fallback to parent", "return", "parent", "::", "get_setting", "(", "$", "name", ")", ";", "}", "}" ]
Specialisation that, first of all, looks for the setting within the task with the the prefix added and later, delegates to parent without adding anything
[ "Specialisation", "that", "first", "of", "all", "looks", "for", "the", "setting", "within", "the", "task", "with", "the", "the", "prefix", "added", "and", "later", "delegates", "to", "parent", "without", "adding", "anything" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/moodle2/backup_section_task.class.php#L117-L135
216,705
moodle/moodle
backup/moodle2/backup_section_task.class.php
backup_section_task.define_settings
protected function define_settings() { global $DB; // All the settings related to this activity will include this prefix $settingprefix = 'section_' . $this->sectionid . '_'; // All these are common settings to be shared by all sections $section = $DB->get_record('course_sections', array('id' => $this->sectionid), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $section->course), '*', MUST_EXIST); // Define section_included (to decide if the whole task must be really executed) $settingname = $settingprefix . 'included'; $section_included = new backup_section_included_setting($settingname, base_setting::IS_BOOLEAN, true); $section_included->get_ui()->set_label(get_section_name($course, $section)); $this->add_setting($section_included); // Define section_userinfo. Dependent of: // - users root setting // - section_included setting $settingname = $settingprefix . 'userinfo'; $section_userinfo = new backup_section_userinfo_setting($settingname, base_setting::IS_BOOLEAN, true); $section_userinfo->get_ui()->set_label(get_string('includeuserinfo','backup')); $this->add_setting($section_userinfo); // Look for "users" root setting $users = $this->plan->get_setting('users'); $users->add_dependency($section_userinfo); // Look for "section_included" section setting $section_included->add_dependency($section_userinfo); }
php
protected function define_settings() { global $DB; // All the settings related to this activity will include this prefix $settingprefix = 'section_' . $this->sectionid . '_'; // All these are common settings to be shared by all sections $section = $DB->get_record('course_sections', array('id' => $this->sectionid), '*', MUST_EXIST); $course = $DB->get_record('course', array('id' => $section->course), '*', MUST_EXIST); // Define section_included (to decide if the whole task must be really executed) $settingname = $settingprefix . 'included'; $section_included = new backup_section_included_setting($settingname, base_setting::IS_BOOLEAN, true); $section_included->get_ui()->set_label(get_section_name($course, $section)); $this->add_setting($section_included); // Define section_userinfo. Dependent of: // - users root setting // - section_included setting $settingname = $settingprefix . 'userinfo'; $section_userinfo = new backup_section_userinfo_setting($settingname, base_setting::IS_BOOLEAN, true); $section_userinfo->get_ui()->set_label(get_string('includeuserinfo','backup')); $this->add_setting($section_userinfo); // Look for "users" root setting $users = $this->plan->get_setting('users'); $users->add_dependency($section_userinfo); // Look for "section_included" section setting $section_included->add_dependency($section_userinfo); }
[ "protected", "function", "define_settings", "(", ")", "{", "global", "$", "DB", ";", "// All the settings related to this activity will include this prefix", "$", "settingprefix", "=", "'section_'", ".", "$", "this", "->", "sectionid", ".", "'_'", ";", "// All these are common settings to be shared by all sections", "$", "section", "=", "$", "DB", "->", "get_record", "(", "'course_sections'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "sectionid", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "$", "course", "=", "$", "DB", "->", "get_record", "(", "'course'", ",", "array", "(", "'id'", "=>", "$", "section", "->", "course", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "// Define section_included (to decide if the whole task must be really executed)", "$", "settingname", "=", "$", "settingprefix", ".", "'included'", ";", "$", "section_included", "=", "new", "backup_section_included_setting", "(", "$", "settingname", ",", "base_setting", "::", "IS_BOOLEAN", ",", "true", ")", ";", "$", "section_included", "->", "get_ui", "(", ")", "->", "set_label", "(", "get_section_name", "(", "$", "course", ",", "$", "section", ")", ")", ";", "$", "this", "->", "add_setting", "(", "$", "section_included", ")", ";", "// Define section_userinfo. Dependent of:", "// - users root setting", "// - section_included setting", "$", "settingname", "=", "$", "settingprefix", ".", "'userinfo'", ";", "$", "section_userinfo", "=", "new", "backup_section_userinfo_setting", "(", "$", "settingname", ",", "base_setting", "::", "IS_BOOLEAN", ",", "true", ")", ";", "$", "section_userinfo", "->", "get_ui", "(", ")", "->", "set_label", "(", "get_string", "(", "'includeuserinfo'", ",", "'backup'", ")", ")", ";", "$", "this", "->", "add_setting", "(", "$", "section_userinfo", ")", ";", "// Look for \"users\" root setting", "$", "users", "=", "$", "this", "->", "plan", "->", "get_setting", "(", "'users'", ")", ";", "$", "users", "->", "add_dependency", "(", "$", "section_userinfo", ")", ";", "// Look for \"section_included\" section setting", "$", "section_included", "->", "add_dependency", "(", "$", "section_userinfo", ")", ";", "}" ]
Define the common setting that any backup section will have
[ "Define", "the", "common", "setting", "that", "any", "backup", "section", "will", "have" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/moodle2/backup_section_task.class.php#L142-L171
216,706
moodle/moodle
lib/dml/pgsql_native_moodle_recordset.php
pgsql_native_moodle_recordset.fetch_cursor_block
protected function fetch_cursor_block() { if ($this->result) { throw new coding_exception('Unexpected non-empty result when fetching from cursor'); } list($this->result, $this->lastbatch) = $this->db->fetch_from_cursor($this->cursorname); if (!$this->result) { throw new coding_exception('Unexpected failure when fetching from cursor'); } }
php
protected function fetch_cursor_block() { if ($this->result) { throw new coding_exception('Unexpected non-empty result when fetching from cursor'); } list($this->result, $this->lastbatch) = $this->db->fetch_from_cursor($this->cursorname); if (!$this->result) { throw new coding_exception('Unexpected failure when fetching from cursor'); } }
[ "protected", "function", "fetch_cursor_block", "(", ")", "{", "if", "(", "$", "this", "->", "result", ")", "{", "throw", "new", "coding_exception", "(", "'Unexpected non-empty result when fetching from cursor'", ")", ";", "}", "list", "(", "$", "this", "->", "result", ",", "$", "this", "->", "lastbatch", ")", "=", "$", "this", "->", "db", "->", "fetch_from_cursor", "(", "$", "this", "->", "cursorname", ")", ";", "if", "(", "!", "$", "this", "->", "result", ")", "{", "throw", "new", "coding_exception", "(", "'Unexpected failure when fetching from cursor'", ")", ";", "}", "}" ]
Fetches the next block of data when using cursors. @throws coding_exception If you call this when the fetch buffer wasn't freed yet
[ "Fetches", "the", "next", "block", "of", "data", "when", "using", "cursors", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/pgsql_native_moodle_recordset.php#L91-L99
216,707
moodle/moodle
course/format/renderer.php
format_section_renderer_base.section_title
public function section_title($section, $course) { $title = get_section_name($course, $section); $url = course_get_url($course, $section->section, array('navigation' => true)); if ($url) { $title = html_writer::link($url, $title); } return $title; }
php
public function section_title($section, $course) { $title = get_section_name($course, $section); $url = course_get_url($course, $section->section, array('navigation' => true)); if ($url) { $title = html_writer::link($url, $title); } return $title; }
[ "public", "function", "section_title", "(", "$", "section", ",", "$", "course", ")", "{", "$", "title", "=", "get_section_name", "(", "$", "course", ",", "$", "section", ")", ";", "$", "url", "=", "course_get_url", "(", "$", "course", ",", "$", "section", "->", "section", ",", "array", "(", "'navigation'", "=>", "true", ")", ")", ";", "if", "(", "$", "url", ")", "{", "$", "title", "=", "html_writer", "::", "link", "(", "$", "url", ",", "$", "title", ")", ";", "}", "return", "$", "title", ";", "}" ]
Generate the section title, wraps it in a link to the section page if page is to be displayed on a separate page @param stdClass $section The course_section entry from DB @param stdClass $course The course entry from DB @return string HTML to output.
[ "Generate", "the", "section", "title", "wraps", "it", "in", "a", "link", "to", "the", "section", "page", "if", "page", "is", "to", "be", "displayed", "on", "a", "separate", "page" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/renderer.php#L80-L87
216,708
moodle/moodle
course/format/renderer.php
format_section_renderer_base.section_edit_control_menu
protected function section_edit_control_menu($controls, $course, $section) { $o = ""; if (!empty($controls)) { $menu = new action_menu(); $menu->set_menu_trigger(get_string('edit')); $menu->attributes['class'] .= ' section-actions'; foreach ($controls as $value) { $url = empty($value['url']) ? '' : $value['url']; $icon = empty($value['icon']) ? '' : $value['icon']; $name = empty($value['name']) ? '' : $value['name']; $attr = empty($value['attr']) ? array() : $value['attr']; $class = empty($value['pixattr']['class']) ? '' : $value['pixattr']['class']; $al = new action_menu_link_secondary( new moodle_url($url), new pix_icon($icon, '', null, array('class' => "smallicon " . $class)), $name, $attr ); $menu->add($al); } $o .= html_writer::div($this->render($menu), 'section_action_menu', array('data-sectionid' => $section->id)); } return $o; }
php
protected function section_edit_control_menu($controls, $course, $section) { $o = ""; if (!empty($controls)) { $menu = new action_menu(); $menu->set_menu_trigger(get_string('edit')); $menu->attributes['class'] .= ' section-actions'; foreach ($controls as $value) { $url = empty($value['url']) ? '' : $value['url']; $icon = empty($value['icon']) ? '' : $value['icon']; $name = empty($value['name']) ? '' : $value['name']; $attr = empty($value['attr']) ? array() : $value['attr']; $class = empty($value['pixattr']['class']) ? '' : $value['pixattr']['class']; $al = new action_menu_link_secondary( new moodle_url($url), new pix_icon($icon, '', null, array('class' => "smallicon " . $class)), $name, $attr ); $menu->add($al); } $o .= html_writer::div($this->render($menu), 'section_action_menu', array('data-sectionid' => $section->id)); } return $o; }
[ "protected", "function", "section_edit_control_menu", "(", "$", "controls", ",", "$", "course", ",", "$", "section", ")", "{", "$", "o", "=", "\"\"", ";", "if", "(", "!", "empty", "(", "$", "controls", ")", ")", "{", "$", "menu", "=", "new", "action_menu", "(", ")", ";", "$", "menu", "->", "set_menu_trigger", "(", "get_string", "(", "'edit'", ")", ")", ";", "$", "menu", "->", "attributes", "[", "'class'", "]", ".=", "' section-actions'", ";", "foreach", "(", "$", "controls", "as", "$", "value", ")", "{", "$", "url", "=", "empty", "(", "$", "value", "[", "'url'", "]", ")", "?", "''", ":", "$", "value", "[", "'url'", "]", ";", "$", "icon", "=", "empty", "(", "$", "value", "[", "'icon'", "]", ")", "?", "''", ":", "$", "value", "[", "'icon'", "]", ";", "$", "name", "=", "empty", "(", "$", "value", "[", "'name'", "]", ")", "?", "''", ":", "$", "value", "[", "'name'", "]", ";", "$", "attr", "=", "empty", "(", "$", "value", "[", "'attr'", "]", ")", "?", "array", "(", ")", ":", "$", "value", "[", "'attr'", "]", ";", "$", "class", "=", "empty", "(", "$", "value", "[", "'pixattr'", "]", "[", "'class'", "]", ")", "?", "''", ":", "$", "value", "[", "'pixattr'", "]", "[", "'class'", "]", ";", "$", "al", "=", "new", "action_menu_link_secondary", "(", "new", "moodle_url", "(", "$", "url", ")", ",", "new", "pix_icon", "(", "$", "icon", ",", "''", ",", "null", ",", "array", "(", "'class'", "=>", "\"smallicon \"", ".", "$", "class", ")", ")", ",", "$", "name", ",", "$", "attr", ")", ";", "$", "menu", "->", "add", "(", "$", "al", ")", ";", "}", "$", "o", ".=", "html_writer", "::", "div", "(", "$", "this", "->", "render", "(", "$", "menu", ")", ",", "'section_action_menu'", ",", "array", "(", "'data-sectionid'", "=>", "$", "section", "->", "id", ")", ")", ";", "}", "return", "$", "o", ";", "}" ]
Generate the edit control action menu @param array $controls The edit control items from section_edit_control_items @param stdClass $course The course entry from DB @param stdClass $section The course_section entry from DB @return string HTML to output.
[ "Generate", "the", "edit", "control", "action", "menu" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/renderer.php#L108-L134
216,709
moodle/moodle
course/format/renderer.php
format_section_renderer_base.section_right_content
protected function section_right_content($section, $course, $onsectionpage) { $o = $this->output->spacer(); $controls = $this->section_edit_control_items($course, $section, $onsectionpage); $o .= $this->section_edit_control_menu($controls, $course, $section); return $o; }
php
protected function section_right_content($section, $course, $onsectionpage) { $o = $this->output->spacer(); $controls = $this->section_edit_control_items($course, $section, $onsectionpage); $o .= $this->section_edit_control_menu($controls, $course, $section); return $o; }
[ "protected", "function", "section_right_content", "(", "$", "section", ",", "$", "course", ",", "$", "onsectionpage", ")", "{", "$", "o", "=", "$", "this", "->", "output", "->", "spacer", "(", ")", ";", "$", "controls", "=", "$", "this", "->", "section_edit_control_items", "(", "$", "course", ",", "$", "section", ",", "$", "onsectionpage", ")", ";", "$", "o", ".=", "$", "this", "->", "section_edit_control_menu", "(", "$", "controls", ",", "$", "course", ",", "$", "section", ")", ";", "return", "$", "o", ";", "}" ]
Generate the content to displayed on the right part of a section before course modules are included @param stdClass $section The course_section entry from DB @param stdClass $course The course entry from DB @param bool $onsectionpage true if being printed on a section page @return string HTML to output.
[ "Generate", "the", "content", "to", "displayed", "on", "the", "right", "part", "of", "a", "section", "before", "course", "modules", "are", "included" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/renderer.php#L145-L152
216,710
moodle/moodle
course/format/renderer.php
format_section_renderer_base.section_left_content
protected function section_left_content($section, $course, $onsectionpage) { $o = ''; if ($section->section != 0) { // Only in the non-general sections. if (course_get_format($course)->is_section_current($section)) { $o = get_accesshide(get_string('currentsection', 'format_'.$course->format)); } } return $o; }
php
protected function section_left_content($section, $course, $onsectionpage) { $o = ''; if ($section->section != 0) { // Only in the non-general sections. if (course_get_format($course)->is_section_current($section)) { $o = get_accesshide(get_string('currentsection', 'format_'.$course->format)); } } return $o; }
[ "protected", "function", "section_left_content", "(", "$", "section", ",", "$", "course", ",", "$", "onsectionpage", ")", "{", "$", "o", "=", "''", ";", "if", "(", "$", "section", "->", "section", "!=", "0", ")", "{", "// Only in the non-general sections.", "if", "(", "course_get_format", "(", "$", "course", ")", "->", "is_section_current", "(", "$", "section", ")", ")", "{", "$", "o", "=", "get_accesshide", "(", "get_string", "(", "'currentsection'", ",", "'format_'", ".", "$", "course", "->", "format", ")", ")", ";", "}", "}", "return", "$", "o", ";", "}" ]
Generate the content to displayed on the left part of a section before course modules are included @param stdClass $section The course_section entry from DB @param stdClass $course The course entry from DB @param bool $onsectionpage true if being printed on a section page @return string HTML to output.
[ "Generate", "the", "content", "to", "displayed", "on", "the", "left", "part", "of", "a", "section", "before", "course", "modules", "are", "included" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/renderer.php#L163-L174
216,711
moodle/moodle
course/format/renderer.php
format_section_renderer_base.section_header
protected function section_header($section, $course, $onsectionpage, $sectionreturn=null) { global $PAGE; $o = ''; $currenttext = ''; $sectionstyle = ''; if ($section->section != 0) { // Only in the non-general sections. if (!$section->visible) { $sectionstyle = ' hidden'; } if (course_get_format($course)->is_section_current($section)) { $sectionstyle = ' current'; } } $o.= html_writer::start_tag('li', array('id' => 'section-'.$section->section, 'class' => 'section main clearfix'.$sectionstyle, 'role'=>'region', 'aria-label'=> get_section_name($course, $section))); // Create a span that contains the section title to be used to create the keyboard section move menu. $o .= html_writer::tag('span', get_section_name($course, $section), array('class' => 'hidden sectionname')); $leftcontent = $this->section_left_content($section, $course, $onsectionpage); $o.= html_writer::tag('div', $leftcontent, array('class' => 'left side')); $rightcontent = $this->section_right_content($section, $course, $onsectionpage); $o.= html_writer::tag('div', $rightcontent, array('class' => 'right side')); $o.= html_writer::start_tag('div', array('class' => 'content')); // When not on a section page, we display the section titles except the general section if null $hasnamenotsecpg = (!$onsectionpage && ($section->section != 0 || !is_null($section->name))); // When on a section page, we only display the general section title, if title is not the default one $hasnamesecpg = ($onsectionpage && ($section->section == 0 && !is_null($section->name))); $classes = ' accesshide'; if ($hasnamenotsecpg || $hasnamesecpg) { $classes = ''; } $sectionname = html_writer::tag('span', $this->section_title($section, $course)); $o.= $this->output->heading($sectionname, 3, 'sectionname' . $classes); $o .= $this->section_availability($section); $o .= html_writer::start_tag('div', array('class' => 'summary')); if ($section->uservisible || $section->visible) { // Show summary if section is available or has availability restriction information. // Do not show summary if section is hidden but we still display it because of course setting // "Hidden sections are shown in collapsed form". $o .= $this->format_summary_text($section); } $o .= html_writer::end_tag('div'); return $o; }
php
protected function section_header($section, $course, $onsectionpage, $sectionreturn=null) { global $PAGE; $o = ''; $currenttext = ''; $sectionstyle = ''; if ($section->section != 0) { // Only in the non-general sections. if (!$section->visible) { $sectionstyle = ' hidden'; } if (course_get_format($course)->is_section_current($section)) { $sectionstyle = ' current'; } } $o.= html_writer::start_tag('li', array('id' => 'section-'.$section->section, 'class' => 'section main clearfix'.$sectionstyle, 'role'=>'region', 'aria-label'=> get_section_name($course, $section))); // Create a span that contains the section title to be used to create the keyboard section move menu. $o .= html_writer::tag('span', get_section_name($course, $section), array('class' => 'hidden sectionname')); $leftcontent = $this->section_left_content($section, $course, $onsectionpage); $o.= html_writer::tag('div', $leftcontent, array('class' => 'left side')); $rightcontent = $this->section_right_content($section, $course, $onsectionpage); $o.= html_writer::tag('div', $rightcontent, array('class' => 'right side')); $o.= html_writer::start_tag('div', array('class' => 'content')); // When not on a section page, we display the section titles except the general section if null $hasnamenotsecpg = (!$onsectionpage && ($section->section != 0 || !is_null($section->name))); // When on a section page, we only display the general section title, if title is not the default one $hasnamesecpg = ($onsectionpage && ($section->section == 0 && !is_null($section->name))); $classes = ' accesshide'; if ($hasnamenotsecpg || $hasnamesecpg) { $classes = ''; } $sectionname = html_writer::tag('span', $this->section_title($section, $course)); $o.= $this->output->heading($sectionname, 3, 'sectionname' . $classes); $o .= $this->section_availability($section); $o .= html_writer::start_tag('div', array('class' => 'summary')); if ($section->uservisible || $section->visible) { // Show summary if section is available or has availability restriction information. // Do not show summary if section is hidden but we still display it because of course setting // "Hidden sections are shown in collapsed form". $o .= $this->format_summary_text($section); } $o .= html_writer::end_tag('div'); return $o; }
[ "protected", "function", "section_header", "(", "$", "section", ",", "$", "course", ",", "$", "onsectionpage", ",", "$", "sectionreturn", "=", "null", ")", "{", "global", "$", "PAGE", ";", "$", "o", "=", "''", ";", "$", "currenttext", "=", "''", ";", "$", "sectionstyle", "=", "''", ";", "if", "(", "$", "section", "->", "section", "!=", "0", ")", "{", "// Only in the non-general sections.", "if", "(", "!", "$", "section", "->", "visible", ")", "{", "$", "sectionstyle", "=", "' hidden'", ";", "}", "if", "(", "course_get_format", "(", "$", "course", ")", "->", "is_section_current", "(", "$", "section", ")", ")", "{", "$", "sectionstyle", "=", "' current'", ";", "}", "}", "$", "o", ".=", "html_writer", "::", "start_tag", "(", "'li'", ",", "array", "(", "'id'", "=>", "'section-'", ".", "$", "section", "->", "section", ",", "'class'", "=>", "'section main clearfix'", ".", "$", "sectionstyle", ",", "'role'", "=>", "'region'", ",", "'aria-label'", "=>", "get_section_name", "(", "$", "course", ",", "$", "section", ")", ")", ")", ";", "// Create a span that contains the section title to be used to create the keyboard section move menu.", "$", "o", ".=", "html_writer", "::", "tag", "(", "'span'", ",", "get_section_name", "(", "$", "course", ",", "$", "section", ")", ",", "array", "(", "'class'", "=>", "'hidden sectionname'", ")", ")", ";", "$", "leftcontent", "=", "$", "this", "->", "section_left_content", "(", "$", "section", ",", "$", "course", ",", "$", "onsectionpage", ")", ";", "$", "o", ".=", "html_writer", "::", "tag", "(", "'div'", ",", "$", "leftcontent", ",", "array", "(", "'class'", "=>", "'left side'", ")", ")", ";", "$", "rightcontent", "=", "$", "this", "->", "section_right_content", "(", "$", "section", ",", "$", "course", ",", "$", "onsectionpage", ")", ";", "$", "o", ".=", "html_writer", "::", "tag", "(", "'div'", ",", "$", "rightcontent", ",", "array", "(", "'class'", "=>", "'right side'", ")", ")", ";", "$", "o", ".=", "html_writer", "::", "start_tag", "(", "'div'", ",", "array", "(", "'class'", "=>", "'content'", ")", ")", ";", "// When not on a section page, we display the section titles except the general section if null", "$", "hasnamenotsecpg", "=", "(", "!", "$", "onsectionpage", "&&", "(", "$", "section", "->", "section", "!=", "0", "||", "!", "is_null", "(", "$", "section", "->", "name", ")", ")", ")", ";", "// When on a section page, we only display the general section title, if title is not the default one", "$", "hasnamesecpg", "=", "(", "$", "onsectionpage", "&&", "(", "$", "section", "->", "section", "==", "0", "&&", "!", "is_null", "(", "$", "section", "->", "name", ")", ")", ")", ";", "$", "classes", "=", "' accesshide'", ";", "if", "(", "$", "hasnamenotsecpg", "||", "$", "hasnamesecpg", ")", "{", "$", "classes", "=", "''", ";", "}", "$", "sectionname", "=", "html_writer", "::", "tag", "(", "'span'", ",", "$", "this", "->", "section_title", "(", "$", "section", ",", "$", "course", ")", ")", ";", "$", "o", ".=", "$", "this", "->", "output", "->", "heading", "(", "$", "sectionname", ",", "3", ",", "'sectionname'", ".", "$", "classes", ")", ";", "$", "o", ".=", "$", "this", "->", "section_availability", "(", "$", "section", ")", ";", "$", "o", ".=", "html_writer", "::", "start_tag", "(", "'div'", ",", "array", "(", "'class'", "=>", "'summary'", ")", ")", ";", "if", "(", "$", "section", "->", "uservisible", "||", "$", "section", "->", "visible", ")", "{", "// Show summary if section is available or has availability restriction information.", "// Do not show summary if section is hidden but we still display it because of course setting", "// \"Hidden sections are shown in collapsed form\".", "$", "o", ".=", "$", "this", "->", "format_summary_text", "(", "$", "section", ")", ";", "}", "$", "o", ".=", "html_writer", "::", "end_tag", "(", "'div'", ")", ";", "return", "$", "o", ";", "}" ]
Generate the display of the header part of a section before course modules are included @param stdClass $section The course_section entry from DB @param stdClass $course The course entry from DB @param bool $onsectionpage true if being printed on a single-section page @param int $sectionreturn The section to return to after an action @return string HTML to output.
[ "Generate", "the", "display", "of", "the", "header", "part", "of", "a", "section", "before", "course", "modules", "are", "included" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/renderer.php#L186-L242
216,712
moodle/moodle
course/format/renderer.php
format_section_renderer_base.section_edit_controls
protected function section_edit_controls($course, $section, $onsectionpage = false) { global $PAGE; if (!$PAGE->user_is_editing()) { return array(); } $controls = array(); $items = $this->section_edit_control_items($course, $section, $onsectionpage); foreach ($items as $key => $item) { $url = empty($item['url']) ? '' : $item['url']; $icon = empty($item['icon']) ? '' : $item['icon']; $name = empty($item['name']) ? '' : $item['name']; $attr = empty($item['attr']) ? '' : $item['attr']; $class = empty($item['pixattr']['class']) ? '' : $item['pixattr']['class']; $alt = empty($item['pixattr']['alt']) ? '' : $item['pixattr']['alt']; $controls[$key] = html_writer::link( new moodle_url($url), $this->output->pix_icon($icon, $alt), $attr); } debugging('section_edit_controls() is deprecated, please use section_edit_control_items() instead.', DEBUG_DEVELOPER); return $controls; }
php
protected function section_edit_controls($course, $section, $onsectionpage = false) { global $PAGE; if (!$PAGE->user_is_editing()) { return array(); } $controls = array(); $items = $this->section_edit_control_items($course, $section, $onsectionpage); foreach ($items as $key => $item) { $url = empty($item['url']) ? '' : $item['url']; $icon = empty($item['icon']) ? '' : $item['icon']; $name = empty($item['name']) ? '' : $item['name']; $attr = empty($item['attr']) ? '' : $item['attr']; $class = empty($item['pixattr']['class']) ? '' : $item['pixattr']['class']; $alt = empty($item['pixattr']['alt']) ? '' : $item['pixattr']['alt']; $controls[$key] = html_writer::link( new moodle_url($url), $this->output->pix_icon($icon, $alt), $attr); } debugging('section_edit_controls() is deprecated, please use section_edit_control_items() instead.', DEBUG_DEVELOPER); return $controls; }
[ "protected", "function", "section_edit_controls", "(", "$", "course", ",", "$", "section", ",", "$", "onsectionpage", "=", "false", ")", "{", "global", "$", "PAGE", ";", "if", "(", "!", "$", "PAGE", "->", "user_is_editing", "(", ")", ")", "{", "return", "array", "(", ")", ";", "}", "$", "controls", "=", "array", "(", ")", ";", "$", "items", "=", "$", "this", "->", "section_edit_control_items", "(", "$", "course", ",", "$", "section", ",", "$", "onsectionpage", ")", ";", "foreach", "(", "$", "items", "as", "$", "key", "=>", "$", "item", ")", "{", "$", "url", "=", "empty", "(", "$", "item", "[", "'url'", "]", ")", "?", "''", ":", "$", "item", "[", "'url'", "]", ";", "$", "icon", "=", "empty", "(", "$", "item", "[", "'icon'", "]", ")", "?", "''", ":", "$", "item", "[", "'icon'", "]", ";", "$", "name", "=", "empty", "(", "$", "item", "[", "'name'", "]", ")", "?", "''", ":", "$", "item", "[", "'name'", "]", ";", "$", "attr", "=", "empty", "(", "$", "item", "[", "'attr'", "]", ")", "?", "''", ":", "$", "item", "[", "'attr'", "]", ";", "$", "class", "=", "empty", "(", "$", "item", "[", "'pixattr'", "]", "[", "'class'", "]", ")", "?", "''", ":", "$", "item", "[", "'pixattr'", "]", "[", "'class'", "]", ";", "$", "alt", "=", "empty", "(", "$", "item", "[", "'pixattr'", "]", "[", "'alt'", "]", ")", "?", "''", ":", "$", "item", "[", "'pixattr'", "]", "[", "'alt'", "]", ";", "$", "controls", "[", "$", "key", "]", "=", "html_writer", "::", "link", "(", "new", "moodle_url", "(", "$", "url", ")", ",", "$", "this", "->", "output", "->", "pix_icon", "(", "$", "icon", ",", "$", "alt", ")", ",", "$", "attr", ")", ";", "}", "debugging", "(", "'section_edit_controls() is deprecated, please use section_edit_control_items() instead.'", ",", "DEBUG_DEVELOPER", ")", ";", "return", "$", "controls", ";", "}" ]
Generate the edit controls of a section @param stdClass $course The course entry from DB @param stdClass $section The course_section entry from DB @param bool $onsectionpage true if being printed on a section page @return array of links with edit controls @deprecated since Moodle 3.0 MDL-48947 - please do not use this function any more. @see format_section_renderer_base::section_edit_control_items()
[ "Generate", "the", "edit", "controls", "of", "a", "section" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/renderer.php#L266-L290
216,713
moodle/moodle
course/format/renderer.php
format_section_renderer_base.section_summary
protected function section_summary($section, $course, $mods) { $classattr = 'section main section-summary clearfix'; $linkclasses = ''; // If section is hidden then display grey section link if (!$section->visible) { $classattr .= ' hidden'; $linkclasses .= ' dimmed_text'; } else if (course_get_format($course)->is_section_current($section)) { $classattr .= ' current'; } $title = get_section_name($course, $section); $o = ''; $o .= html_writer::start_tag('li', array('id' => 'section-'.$section->section, 'class' => $classattr, 'role'=>'region', 'aria-label'=> $title)); $o .= html_writer::tag('div', '', array('class' => 'left side')); $o .= html_writer::tag('div', '', array('class' => 'right side')); $o .= html_writer::start_tag('div', array('class' => 'content')); if ($section->uservisible) { $title = html_writer::tag('a', $title, array('href' => course_get_url($course, $section->section), 'class' => $linkclasses)); } $o .= $this->output->heading($title, 3, 'section-title'); $o .= $this->section_availability($section); $o.= html_writer::start_tag('div', array('class' => 'summarytext')); if ($section->uservisible || $section->visible) { // Show summary if section is available or has availability restriction information. // Do not show summary if section is hidden but we still display it because of course setting // "Hidden sections are shown in collapsed form". $o .= $this->format_summary_text($section); } $o.= html_writer::end_tag('div'); $o.= $this->section_activity_summary($section, $course, null); $o .= html_writer::end_tag('div'); $o .= html_writer::end_tag('li'); return $o; }
php
protected function section_summary($section, $course, $mods) { $classattr = 'section main section-summary clearfix'; $linkclasses = ''; // If section is hidden then display grey section link if (!$section->visible) { $classattr .= ' hidden'; $linkclasses .= ' dimmed_text'; } else if (course_get_format($course)->is_section_current($section)) { $classattr .= ' current'; } $title = get_section_name($course, $section); $o = ''; $o .= html_writer::start_tag('li', array('id' => 'section-'.$section->section, 'class' => $classattr, 'role'=>'region', 'aria-label'=> $title)); $o .= html_writer::tag('div', '', array('class' => 'left side')); $o .= html_writer::tag('div', '', array('class' => 'right side')); $o .= html_writer::start_tag('div', array('class' => 'content')); if ($section->uservisible) { $title = html_writer::tag('a', $title, array('href' => course_get_url($course, $section->section), 'class' => $linkclasses)); } $o .= $this->output->heading($title, 3, 'section-title'); $o .= $this->section_availability($section); $o.= html_writer::start_tag('div', array('class' => 'summarytext')); if ($section->uservisible || $section->visible) { // Show summary if section is available or has availability restriction information. // Do not show summary if section is hidden but we still display it because of course setting // "Hidden sections are shown in collapsed form". $o .= $this->format_summary_text($section); } $o.= html_writer::end_tag('div'); $o.= $this->section_activity_summary($section, $course, null); $o .= html_writer::end_tag('div'); $o .= html_writer::end_tag('li'); return $o; }
[ "protected", "function", "section_summary", "(", "$", "section", ",", "$", "course", ",", "$", "mods", ")", "{", "$", "classattr", "=", "'section main section-summary clearfix'", ";", "$", "linkclasses", "=", "''", ";", "// If section is hidden then display grey section link", "if", "(", "!", "$", "section", "->", "visible", ")", "{", "$", "classattr", ".=", "' hidden'", ";", "$", "linkclasses", ".=", "' dimmed_text'", ";", "}", "else", "if", "(", "course_get_format", "(", "$", "course", ")", "->", "is_section_current", "(", "$", "section", ")", ")", "{", "$", "classattr", ".=", "' current'", ";", "}", "$", "title", "=", "get_section_name", "(", "$", "course", ",", "$", "section", ")", ";", "$", "o", "=", "''", ";", "$", "o", ".=", "html_writer", "::", "start_tag", "(", "'li'", ",", "array", "(", "'id'", "=>", "'section-'", ".", "$", "section", "->", "section", ",", "'class'", "=>", "$", "classattr", ",", "'role'", "=>", "'region'", ",", "'aria-label'", "=>", "$", "title", ")", ")", ";", "$", "o", ".=", "html_writer", "::", "tag", "(", "'div'", ",", "''", ",", "array", "(", "'class'", "=>", "'left side'", ")", ")", ";", "$", "o", ".=", "html_writer", "::", "tag", "(", "'div'", ",", "''", ",", "array", "(", "'class'", "=>", "'right side'", ")", ")", ";", "$", "o", ".=", "html_writer", "::", "start_tag", "(", "'div'", ",", "array", "(", "'class'", "=>", "'content'", ")", ")", ";", "if", "(", "$", "section", "->", "uservisible", ")", "{", "$", "title", "=", "html_writer", "::", "tag", "(", "'a'", ",", "$", "title", ",", "array", "(", "'href'", "=>", "course_get_url", "(", "$", "course", ",", "$", "section", "->", "section", ")", ",", "'class'", "=>", "$", "linkclasses", ")", ")", ";", "}", "$", "o", ".=", "$", "this", "->", "output", "->", "heading", "(", "$", "title", ",", "3", ",", "'section-title'", ")", ";", "$", "o", ".=", "$", "this", "->", "section_availability", "(", "$", "section", ")", ";", "$", "o", ".=", "html_writer", "::", "start_tag", "(", "'div'", ",", "array", "(", "'class'", "=>", "'summarytext'", ")", ")", ";", "if", "(", "$", "section", "->", "uservisible", "||", "$", "section", "->", "visible", ")", "{", "// Show summary if section is available or has availability restriction information.", "// Do not show summary if section is hidden but we still display it because of course setting", "// \"Hidden sections are shown in collapsed form\".", "$", "o", ".=", "$", "this", "->", "format_summary_text", "(", "$", "section", ")", ";", "}", "$", "o", ".=", "html_writer", "::", "end_tag", "(", "'div'", ")", ";", "$", "o", ".=", "$", "this", "->", "section_activity_summary", "(", "$", "section", ",", "$", "course", ",", "null", ")", ";", "$", "o", ".=", "html_writer", "::", "end_tag", "(", "'div'", ")", ";", "$", "o", ".=", "html_writer", "::", "end_tag", "(", "'li'", ")", ";", "return", "$", "o", ";", "}" ]
Generate a summary of a section for display on the 'course index page' @param stdClass $section The course_section entry from DB @param stdClass $course The course entry from DB @param array $mods (argument not used) @return string HTML to output.
[ "Generate", "a", "summary", "of", "a", "section", "for", "display", "on", "the", "course", "index", "page" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/renderer.php#L423-L466
216,714
moodle/moodle
course/format/renderer.php
format_section_renderer_base.section_activity_summary
protected function section_activity_summary($section, $course, $mods) { $modinfo = get_fast_modinfo($course); if (empty($modinfo->sections[$section->section])) { return ''; } // Generate array with count of activities in this section: $sectionmods = array(); $total = 0; $complete = 0; $cancomplete = isloggedin() && !isguestuser(); $completioninfo = new completion_info($course); foreach ($modinfo->sections[$section->section] as $cmid) { $thismod = $modinfo->cms[$cmid]; if ($thismod->modname == 'label') { // Labels are special (not interesting for students)! continue; } if ($thismod->uservisible) { if (isset($sectionmods[$thismod->modname])) { $sectionmods[$thismod->modname]['name'] = $thismod->modplural; $sectionmods[$thismod->modname]['count']++; } else { $sectionmods[$thismod->modname]['name'] = $thismod->modfullname; $sectionmods[$thismod->modname]['count'] = 1; } if ($cancomplete && $completioninfo->is_enabled($thismod) != COMPLETION_TRACKING_NONE) { $total++; $completiondata = $completioninfo->get_data($thismod, true); if ($completiondata->completionstate == COMPLETION_COMPLETE || $completiondata->completionstate == COMPLETION_COMPLETE_PASS) { $complete++; } } } } if (empty($sectionmods)) { // No sections return ''; } // Output section activities summary: $o = ''; $o.= html_writer::start_tag('div', array('class' => 'section-summary-activities mdl-right')); foreach ($sectionmods as $mod) { $o.= html_writer::start_tag('span', array('class' => 'activity-count')); $o.= $mod['name'].': '.$mod['count']; $o.= html_writer::end_tag('span'); } $o.= html_writer::end_tag('div'); // Output section completion data if ($total > 0) { $a = new stdClass; $a->complete = $complete; $a->total = $total; $o.= html_writer::start_tag('div', array('class' => 'section-summary-activities mdl-right')); $o.= html_writer::tag('span', get_string('progresstotal', 'completion', $a), array('class' => 'activity-count')); $o.= html_writer::end_tag('div'); } return $o; }
php
protected function section_activity_summary($section, $course, $mods) { $modinfo = get_fast_modinfo($course); if (empty($modinfo->sections[$section->section])) { return ''; } // Generate array with count of activities in this section: $sectionmods = array(); $total = 0; $complete = 0; $cancomplete = isloggedin() && !isguestuser(); $completioninfo = new completion_info($course); foreach ($modinfo->sections[$section->section] as $cmid) { $thismod = $modinfo->cms[$cmid]; if ($thismod->modname == 'label') { // Labels are special (not interesting for students)! continue; } if ($thismod->uservisible) { if (isset($sectionmods[$thismod->modname])) { $sectionmods[$thismod->modname]['name'] = $thismod->modplural; $sectionmods[$thismod->modname]['count']++; } else { $sectionmods[$thismod->modname]['name'] = $thismod->modfullname; $sectionmods[$thismod->modname]['count'] = 1; } if ($cancomplete && $completioninfo->is_enabled($thismod) != COMPLETION_TRACKING_NONE) { $total++; $completiondata = $completioninfo->get_data($thismod, true); if ($completiondata->completionstate == COMPLETION_COMPLETE || $completiondata->completionstate == COMPLETION_COMPLETE_PASS) { $complete++; } } } } if (empty($sectionmods)) { // No sections return ''; } // Output section activities summary: $o = ''; $o.= html_writer::start_tag('div', array('class' => 'section-summary-activities mdl-right')); foreach ($sectionmods as $mod) { $o.= html_writer::start_tag('span', array('class' => 'activity-count')); $o.= $mod['name'].': '.$mod['count']; $o.= html_writer::end_tag('span'); } $o.= html_writer::end_tag('div'); // Output section completion data if ($total > 0) { $a = new stdClass; $a->complete = $complete; $a->total = $total; $o.= html_writer::start_tag('div', array('class' => 'section-summary-activities mdl-right')); $o.= html_writer::tag('span', get_string('progresstotal', 'completion', $a), array('class' => 'activity-count')); $o.= html_writer::end_tag('div'); } return $o; }
[ "protected", "function", "section_activity_summary", "(", "$", "section", ",", "$", "course", ",", "$", "mods", ")", "{", "$", "modinfo", "=", "get_fast_modinfo", "(", "$", "course", ")", ";", "if", "(", "empty", "(", "$", "modinfo", "->", "sections", "[", "$", "section", "->", "section", "]", ")", ")", "{", "return", "''", ";", "}", "// Generate array with count of activities in this section:", "$", "sectionmods", "=", "array", "(", ")", ";", "$", "total", "=", "0", ";", "$", "complete", "=", "0", ";", "$", "cancomplete", "=", "isloggedin", "(", ")", "&&", "!", "isguestuser", "(", ")", ";", "$", "completioninfo", "=", "new", "completion_info", "(", "$", "course", ")", ";", "foreach", "(", "$", "modinfo", "->", "sections", "[", "$", "section", "->", "section", "]", "as", "$", "cmid", ")", "{", "$", "thismod", "=", "$", "modinfo", "->", "cms", "[", "$", "cmid", "]", ";", "if", "(", "$", "thismod", "->", "modname", "==", "'label'", ")", "{", "// Labels are special (not interesting for students)!", "continue", ";", "}", "if", "(", "$", "thismod", "->", "uservisible", ")", "{", "if", "(", "isset", "(", "$", "sectionmods", "[", "$", "thismod", "->", "modname", "]", ")", ")", "{", "$", "sectionmods", "[", "$", "thismod", "->", "modname", "]", "[", "'name'", "]", "=", "$", "thismod", "->", "modplural", ";", "$", "sectionmods", "[", "$", "thismod", "->", "modname", "]", "[", "'count'", "]", "++", ";", "}", "else", "{", "$", "sectionmods", "[", "$", "thismod", "->", "modname", "]", "[", "'name'", "]", "=", "$", "thismod", "->", "modfullname", ";", "$", "sectionmods", "[", "$", "thismod", "->", "modname", "]", "[", "'count'", "]", "=", "1", ";", "}", "if", "(", "$", "cancomplete", "&&", "$", "completioninfo", "->", "is_enabled", "(", "$", "thismod", ")", "!=", "COMPLETION_TRACKING_NONE", ")", "{", "$", "total", "++", ";", "$", "completiondata", "=", "$", "completioninfo", "->", "get_data", "(", "$", "thismod", ",", "true", ")", ";", "if", "(", "$", "completiondata", "->", "completionstate", "==", "COMPLETION_COMPLETE", "||", "$", "completiondata", "->", "completionstate", "==", "COMPLETION_COMPLETE_PASS", ")", "{", "$", "complete", "++", ";", "}", "}", "}", "}", "if", "(", "empty", "(", "$", "sectionmods", ")", ")", "{", "// No sections", "return", "''", ";", "}", "// Output section activities summary:", "$", "o", "=", "''", ";", "$", "o", ".=", "html_writer", "::", "start_tag", "(", "'div'", ",", "array", "(", "'class'", "=>", "'section-summary-activities mdl-right'", ")", ")", ";", "foreach", "(", "$", "sectionmods", "as", "$", "mod", ")", "{", "$", "o", ".=", "html_writer", "::", "start_tag", "(", "'span'", ",", "array", "(", "'class'", "=>", "'activity-count'", ")", ")", ";", "$", "o", ".=", "$", "mod", "[", "'name'", "]", ".", "': '", ".", "$", "mod", "[", "'count'", "]", ";", "$", "o", ".=", "html_writer", "::", "end_tag", "(", "'span'", ")", ";", "}", "$", "o", ".=", "html_writer", "::", "end_tag", "(", "'div'", ")", ";", "// Output section completion data", "if", "(", "$", "total", ">", "0", ")", "{", "$", "a", "=", "new", "stdClass", ";", "$", "a", "->", "complete", "=", "$", "complete", ";", "$", "a", "->", "total", "=", "$", "total", ";", "$", "o", ".=", "html_writer", "::", "start_tag", "(", "'div'", ",", "array", "(", "'class'", "=>", "'section-summary-activities mdl-right'", ")", ")", ";", "$", "o", ".=", "html_writer", "::", "tag", "(", "'span'", ",", "get_string", "(", "'progresstotal'", ",", "'completion'", ",", "$", "a", ")", ",", "array", "(", "'class'", "=>", "'activity-count'", ")", ")", ";", "$", "o", ".=", "html_writer", "::", "end_tag", "(", "'div'", ")", ";", "}", "return", "$", "o", ";", "}" ]
Generate a summary of the activites in a section @param stdClass $section The course_section entry from DB @param stdClass $course the course record from DB @param array $mods (argument not used) @return string HTML to output.
[ "Generate", "a", "summary", "of", "the", "activites", "in", "a", "section" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/renderer.php#L476-L542
216,715
moodle/moodle
course/format/renderer.php
format_section_renderer_base.stealth_section_header
protected function stealth_section_header($sectionno) { $o = ''; $o.= html_writer::start_tag('li', array('id' => 'section-'.$sectionno, 'class' => 'section main clearfix orphaned hidden')); $o.= html_writer::tag('div', '', array('class' => 'left side')); $course = course_get_format($this->page->course)->get_course(); $section = course_get_format($this->page->course)->get_section($sectionno); $rightcontent = $this->section_right_content($section, $course, false); $o.= html_writer::tag('div', $rightcontent, array('class' => 'right side')); $o.= html_writer::start_tag('div', array('class' => 'content')); $o.= $this->output->heading(get_string('orphanedactivitiesinsectionno', '', $sectionno), 3, 'sectionname'); return $o; }
php
protected function stealth_section_header($sectionno) { $o = ''; $o.= html_writer::start_tag('li', array('id' => 'section-'.$sectionno, 'class' => 'section main clearfix orphaned hidden')); $o.= html_writer::tag('div', '', array('class' => 'left side')); $course = course_get_format($this->page->course)->get_course(); $section = course_get_format($this->page->course)->get_section($sectionno); $rightcontent = $this->section_right_content($section, $course, false); $o.= html_writer::tag('div', $rightcontent, array('class' => 'right side')); $o.= html_writer::start_tag('div', array('class' => 'content')); $o.= $this->output->heading(get_string('orphanedactivitiesinsectionno', '', $sectionno), 3, 'sectionname'); return $o; }
[ "protected", "function", "stealth_section_header", "(", "$", "sectionno", ")", "{", "$", "o", "=", "''", ";", "$", "o", ".=", "html_writer", "::", "start_tag", "(", "'li'", ",", "array", "(", "'id'", "=>", "'section-'", ".", "$", "sectionno", ",", "'class'", "=>", "'section main clearfix orphaned hidden'", ")", ")", ";", "$", "o", ".=", "html_writer", "::", "tag", "(", "'div'", ",", "''", ",", "array", "(", "'class'", "=>", "'left side'", ")", ")", ";", "$", "course", "=", "course_get_format", "(", "$", "this", "->", "page", "->", "course", ")", "->", "get_course", "(", ")", ";", "$", "section", "=", "course_get_format", "(", "$", "this", "->", "page", "->", "course", ")", "->", "get_section", "(", "$", "sectionno", ")", ";", "$", "rightcontent", "=", "$", "this", "->", "section_right_content", "(", "$", "section", ",", "$", "course", ",", "false", ")", ";", "$", "o", ".=", "html_writer", "::", "tag", "(", "'div'", ",", "$", "rightcontent", ",", "array", "(", "'class'", "=>", "'right side'", ")", ")", ";", "$", "o", ".=", "html_writer", "::", "start_tag", "(", "'div'", ",", "array", "(", "'class'", "=>", "'content'", ")", ")", ";", "$", "o", ".=", "$", "this", "->", "output", "->", "heading", "(", "get_string", "(", "'orphanedactivitiesinsectionno'", ",", "''", ",", "$", "sectionno", ")", ",", "3", ",", "'sectionname'", ")", ";", "return", "$", "o", ";", "}" ]
Generate the header html of a stealth section @param int $sectionno The section number in the course which is being displayed @return string HTML to output.
[ "Generate", "the", "header", "html", "of", "a", "stealth", "section" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/renderer.php#L684-L695
216,716
moodle/moodle
course/format/renderer.php
format_section_renderer_base.section_hidden
protected function section_hidden($sectionno, $courseorid = null) { if ($courseorid) { $sectionname = get_section_name($courseorid, $sectionno); $strnotavailable = get_string('notavailablecourse', '', $sectionname); } else { $strnotavailable = get_string('notavailable'); } $o = ''; $o.= html_writer::start_tag('li', array('id' => 'section-'.$sectionno, 'class' => 'section main clearfix hidden')); $o.= html_writer::tag('div', '', array('class' => 'left side')); $o.= html_writer::tag('div', '', array('class' => 'right side')); $o.= html_writer::start_tag('div', array('class' => 'content')); $o.= html_writer::tag('div', $strnotavailable); $o.= html_writer::end_tag('div'); $o.= html_writer::end_tag('li'); return $o; }
php
protected function section_hidden($sectionno, $courseorid = null) { if ($courseorid) { $sectionname = get_section_name($courseorid, $sectionno); $strnotavailable = get_string('notavailablecourse', '', $sectionname); } else { $strnotavailable = get_string('notavailable'); } $o = ''; $o.= html_writer::start_tag('li', array('id' => 'section-'.$sectionno, 'class' => 'section main clearfix hidden')); $o.= html_writer::tag('div', '', array('class' => 'left side')); $o.= html_writer::tag('div', '', array('class' => 'right side')); $o.= html_writer::start_tag('div', array('class' => 'content')); $o.= html_writer::tag('div', $strnotavailable); $o.= html_writer::end_tag('div'); $o.= html_writer::end_tag('li'); return $o; }
[ "protected", "function", "section_hidden", "(", "$", "sectionno", ",", "$", "courseorid", "=", "null", ")", "{", "if", "(", "$", "courseorid", ")", "{", "$", "sectionname", "=", "get_section_name", "(", "$", "courseorid", ",", "$", "sectionno", ")", ";", "$", "strnotavailable", "=", "get_string", "(", "'notavailablecourse'", ",", "''", ",", "$", "sectionname", ")", ";", "}", "else", "{", "$", "strnotavailable", "=", "get_string", "(", "'notavailable'", ")", ";", "}", "$", "o", "=", "''", ";", "$", "o", ".=", "html_writer", "::", "start_tag", "(", "'li'", ",", "array", "(", "'id'", "=>", "'section-'", ".", "$", "sectionno", ",", "'class'", "=>", "'section main clearfix hidden'", ")", ")", ";", "$", "o", ".=", "html_writer", "::", "tag", "(", "'div'", ",", "''", ",", "array", "(", "'class'", "=>", "'left side'", ")", ")", ";", "$", "o", ".=", "html_writer", "::", "tag", "(", "'div'", ",", "''", ",", "array", "(", "'class'", "=>", "'right side'", ")", ")", ";", "$", "o", ".=", "html_writer", "::", "start_tag", "(", "'div'", ",", "array", "(", "'class'", "=>", "'content'", ")", ")", ";", "$", "o", ".=", "html_writer", "::", "tag", "(", "'div'", ",", "$", "strnotavailable", ")", ";", "$", "o", ".=", "html_writer", "::", "end_tag", "(", "'div'", ")", ";", "$", "o", ".=", "html_writer", "::", "end_tag", "(", "'li'", ")", ";", "return", "$", "o", ";", "}" ]
Generate the html for a hidden section @param int $sectionno The section number in the course which is being displayed @param int|stdClass $courseorid The course to get the section name for (object or just course id) @return string HTML to output.
[ "Generate", "the", "html", "for", "a", "hidden", "section" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/renderer.php#L715-L732
216,717
moodle/moodle
course/format/renderer.php
format_section_renderer_base.section_nav_selection
protected function section_nav_selection($course, $sections, $displaysection) { global $CFG; $o = ''; $sectionmenu = array(); $sectionmenu[course_get_url($course)->out(false)] = get_string('maincoursepage'); $modinfo = get_fast_modinfo($course); $section = 1; $numsections = course_get_format($course)->get_last_section_number(); while ($section <= $numsections) { $thissection = $modinfo->get_section_info($section); $showsection = $thissection->uservisible or !$course->hiddensections; if (($showsection) && ($section != $displaysection) && ($url = course_get_url($course, $section))) { $sectionmenu[$url->out(false)] = get_section_name($course, $section); } $section++; } $select = new url_select($sectionmenu, '', array('' => get_string('jumpto'))); $select->class = 'jumpmenu'; $select->formid = 'sectionmenu'; $o .= $this->output->render($select); return $o; }
php
protected function section_nav_selection($course, $sections, $displaysection) { global $CFG; $o = ''; $sectionmenu = array(); $sectionmenu[course_get_url($course)->out(false)] = get_string('maincoursepage'); $modinfo = get_fast_modinfo($course); $section = 1; $numsections = course_get_format($course)->get_last_section_number(); while ($section <= $numsections) { $thissection = $modinfo->get_section_info($section); $showsection = $thissection->uservisible or !$course->hiddensections; if (($showsection) && ($section != $displaysection) && ($url = course_get_url($course, $section))) { $sectionmenu[$url->out(false)] = get_section_name($course, $section); } $section++; } $select = new url_select($sectionmenu, '', array('' => get_string('jumpto'))); $select->class = 'jumpmenu'; $select->formid = 'sectionmenu'; $o .= $this->output->render($select); return $o; }
[ "protected", "function", "section_nav_selection", "(", "$", "course", ",", "$", "sections", ",", "$", "displaysection", ")", "{", "global", "$", "CFG", ";", "$", "o", "=", "''", ";", "$", "sectionmenu", "=", "array", "(", ")", ";", "$", "sectionmenu", "[", "course_get_url", "(", "$", "course", ")", "->", "out", "(", "false", ")", "]", "=", "get_string", "(", "'maincoursepage'", ")", ";", "$", "modinfo", "=", "get_fast_modinfo", "(", "$", "course", ")", ";", "$", "section", "=", "1", ";", "$", "numsections", "=", "course_get_format", "(", "$", "course", ")", "->", "get_last_section_number", "(", ")", ";", "while", "(", "$", "section", "<=", "$", "numsections", ")", "{", "$", "thissection", "=", "$", "modinfo", "->", "get_section_info", "(", "$", "section", ")", ";", "$", "showsection", "=", "$", "thissection", "->", "uservisible", "or", "!", "$", "course", "->", "hiddensections", ";", "if", "(", "(", "$", "showsection", ")", "&&", "(", "$", "section", "!=", "$", "displaysection", ")", "&&", "(", "$", "url", "=", "course_get_url", "(", "$", "course", ",", "$", "section", ")", ")", ")", "{", "$", "sectionmenu", "[", "$", "url", "->", "out", "(", "false", ")", "]", "=", "get_section_name", "(", "$", "course", ",", "$", "section", ")", ";", "}", "$", "section", "++", ";", "}", "$", "select", "=", "new", "url_select", "(", "$", "sectionmenu", ",", "''", ",", "array", "(", "''", "=>", "get_string", "(", "'jumpto'", ")", ")", ")", ";", "$", "select", "->", "class", "=", "'jumpmenu'", ";", "$", "select", "->", "formid", "=", "'sectionmenu'", ";", "$", "o", ".=", "$", "this", "->", "output", "->", "render", "(", "$", "select", ")", ";", "return", "$", "o", ";", "}" ]
Generate the html for the 'Jump to' menu on a single section page. @param stdClass $course The course entry from DB @param array $sections The course_sections entries from the DB @param $displaysection the current displayed section number. @return string HTML to output.
[ "Generate", "the", "html", "for", "the", "Jump", "to", "menu", "on", "a", "single", "section", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/renderer.php#L743-L766
216,718
moodle/moodle
course/format/renderer.php
format_section_renderer_base.format_summary_text
protected function format_summary_text($section) { $context = context_course::instance($section->course); $summarytext = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php', $context->id, 'course', 'section', $section->id); $options = new stdClass(); $options->noclean = true; $options->overflowdiv = true; return format_text($summarytext, $section->summaryformat, $options); }
php
protected function format_summary_text($section) { $context = context_course::instance($section->course); $summarytext = file_rewrite_pluginfile_urls($section->summary, 'pluginfile.php', $context->id, 'course', 'section', $section->id); $options = new stdClass(); $options->noclean = true; $options->overflowdiv = true; return format_text($summarytext, $section->summaryformat, $options); }
[ "protected", "function", "format_summary_text", "(", "$", "section", ")", "{", "$", "context", "=", "context_course", "::", "instance", "(", "$", "section", "->", "course", ")", ";", "$", "summarytext", "=", "file_rewrite_pluginfile_urls", "(", "$", "section", "->", "summary", ",", "'pluginfile.php'", ",", "$", "context", "->", "id", ",", "'course'", ",", "'section'", ",", "$", "section", "->", "id", ")", ";", "$", "options", "=", "new", "stdClass", "(", ")", ";", "$", "options", "->", "noclean", "=", "true", ";", "$", "options", "->", "overflowdiv", "=", "true", ";", "return", "format_text", "(", "$", "summarytext", ",", "$", "section", "->", "summaryformat", ",", "$", "options", ")", ";", "}" ]
Generate html for a section summary text @param stdClass $section The course_section entry from DB @return string HTML to output.
[ "Generate", "html", "for", "a", "section", "summary", "text" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/renderer.php#L1025-L1034
216,719
moodle/moodle
lib/google/src/Google/Logger/Abstract.php
Google_Logger_Abstract.reverseJsonInContext
protected function reverseJsonInContext(array &$context) { if (!$context) { return; } foreach ($context as $key => $val) { if (!$val || !is_string($val) || !($val[0] == '{' || $val[0] == '[')) { continue; } $json = @json_decode($val); if (is_object($json) || is_array($json)) { $context[$key] = $json; } } }
php
protected function reverseJsonInContext(array &$context) { if (!$context) { return; } foreach ($context as $key => $val) { if (!$val || !is_string($val) || !($val[0] == '{' || $val[0] == '[')) { continue; } $json = @json_decode($val); if (is_object($json) || is_array($json)) { $context[$key] = $json; } } }
[ "protected", "function", "reverseJsonInContext", "(", "array", "&", "$", "context", ")", "{", "if", "(", "!", "$", "context", ")", "{", "return", ";", "}", "foreach", "(", "$", "context", "as", "$", "key", "=>", "$", "val", ")", "{", "if", "(", "!", "$", "val", "||", "!", "is_string", "(", "$", "val", ")", "||", "!", "(", "$", "val", "[", "0", "]", "==", "'{'", "||", "$", "val", "[", "0", "]", "==", "'['", ")", ")", "{", "continue", ";", "}", "$", "json", "=", "@", "json_decode", "(", "$", "val", ")", ";", "if", "(", "is_object", "(", "$", "json", ")", "||", "is_array", "(", "$", "json", ")", ")", "{", "$", "context", "[", "$", "key", "]", "=", "$", "json", ";", "}", "}", "}" ]
Reverses JSON encoded PHP arrays and objects so that they log better. @param array $context The log context
[ "Reverses", "JSON", "encoded", "PHP", "arrays", "and", "objects", "so", "that", "they", "log", "better", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/google/src/Google/Logger/Abstract.php#L322-L338
216,720
moodle/moodle
lib/enrollib.php
enrol_plugin.load_config
protected function load_config() { if (!isset($this->config)) { $name = $this->get_name(); $this->config = get_config("enrol_$name"); } }
php
protected function load_config() { if (!isset($this->config)) { $name = $this->get_name(); $this->config = get_config("enrol_$name"); } }
[ "protected", "function", "load_config", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "config", ")", ")", "{", "$", "name", "=", "$", "this", "->", "get_name", "(", ")", ";", "$", "this", "->", "config", "=", "get_config", "(", "\"enrol_$name\"", ")", ";", "}", "}" ]
Makes sure config is loaded and cached. @return void
[ "Makes", "sure", "config", "is", "loaded", "and", "cached", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/enrollib.php#L1775-L1780
216,721
moodle/moodle
lib/enrollib.php
enrol_plugin.get_config
public function get_config($name, $default = NULL) { $this->load_config(); return isset($this->config->$name) ? $this->config->$name : $default; }
php
public function get_config($name, $default = NULL) { $this->load_config(); return isset($this->config->$name) ? $this->config->$name : $default; }
[ "public", "function", "get_config", "(", "$", "name", ",", "$", "default", "=", "NULL", ")", "{", "$", "this", "->", "load_config", "(", ")", ";", "return", "isset", "(", "$", "this", "->", "config", "->", "$", "name", ")", "?", "$", "this", "->", "config", "->", "$", "name", ":", "$", "default", ";", "}" ]
Returns plugin config value @param string $name @param string $default value if config does not exist yet @return string value or default
[ "Returns", "plugin", "config", "value" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/enrollib.php#L1788-L1791
216,722
moodle/moodle
lib/enrollib.php
enrol_plugin.set_config
public function set_config($name, $value) { $pluginname = $this->get_name(); $this->load_config(); if ($value === NULL) { unset($this->config->$name); } else { $this->config->$name = $value; } set_config($name, $value, "enrol_$pluginname"); }
php
public function set_config($name, $value) { $pluginname = $this->get_name(); $this->load_config(); if ($value === NULL) { unset($this->config->$name); } else { $this->config->$name = $value; } set_config($name, $value, "enrol_$pluginname"); }
[ "public", "function", "set_config", "(", "$", "name", ",", "$", "value", ")", "{", "$", "pluginname", "=", "$", "this", "->", "get_name", "(", ")", ";", "$", "this", "->", "load_config", "(", ")", ";", "if", "(", "$", "value", "===", "NULL", ")", "{", "unset", "(", "$", "this", "->", "config", "->", "$", "name", ")", ";", "}", "else", "{", "$", "this", "->", "config", "->", "$", "name", "=", "$", "value", ";", "}", "set_config", "(", "$", "name", ",", "$", "value", ",", "\"enrol_$pluginname\"", ")", ";", "}" ]
Sets plugin config value @param string $name name of config @param string $value string config value, null means delete @return string value
[ "Sets", "plugin", "config", "value" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/enrollib.php#L1799-L1808
216,723
moodle/moodle
lib/enrollib.php
enrol_plugin.update_user_enrol
public function update_user_enrol(stdClass $instance, $userid, $status = NULL, $timestart = NULL, $timeend = NULL) { global $DB, $USER, $CFG; $name = $this->get_name(); if ($instance->enrol !== $name) { throw new coding_exception('invalid enrol instance!'); } if (!$ue = $DB->get_record('user_enrolments', array('enrolid'=>$instance->id, 'userid'=>$userid))) { // weird, user not enrolled return; } $modified = false; if (isset($status) and $ue->status != $status) { $ue->status = $status; $modified = true; } if (isset($timestart) and $ue->timestart != $timestart) { $ue->timestart = $timestart; $modified = true; } if (isset($timeend) and $ue->timeend != $timeend) { $ue->timeend = $timeend; $modified = true; } if (!$modified) { // no change return; } $ue->modifierid = $USER->id; $ue->timemodified = time(); $DB->update_record('user_enrolments', $ue); // User enrolments have changed, so mark user as dirty. mark_user_dirty($userid); // Invalidate core_access cache for get_suspended_userids. cache_helper::invalidate_by_definition('core', 'suspended_userids', array(), array($instance->courseid)); // Trigger event. $event = \core\event\user_enrolment_updated::create( array( 'objectid' => $ue->id, 'courseid' => $instance->courseid, 'context' => context_course::instance($instance->courseid), 'relateduserid' => $ue->userid, 'other' => array('enrol' => $name) ) ); $event->trigger(); core_course_category::user_enrolment_changed($instance->courseid, $ue->userid, $ue->status, $ue->timestart, $ue->timeend); }
php
public function update_user_enrol(stdClass $instance, $userid, $status = NULL, $timestart = NULL, $timeend = NULL) { global $DB, $USER, $CFG; $name = $this->get_name(); if ($instance->enrol !== $name) { throw new coding_exception('invalid enrol instance!'); } if (!$ue = $DB->get_record('user_enrolments', array('enrolid'=>$instance->id, 'userid'=>$userid))) { // weird, user not enrolled return; } $modified = false; if (isset($status) and $ue->status != $status) { $ue->status = $status; $modified = true; } if (isset($timestart) and $ue->timestart != $timestart) { $ue->timestart = $timestart; $modified = true; } if (isset($timeend) and $ue->timeend != $timeend) { $ue->timeend = $timeend; $modified = true; } if (!$modified) { // no change return; } $ue->modifierid = $USER->id; $ue->timemodified = time(); $DB->update_record('user_enrolments', $ue); // User enrolments have changed, so mark user as dirty. mark_user_dirty($userid); // Invalidate core_access cache for get_suspended_userids. cache_helper::invalidate_by_definition('core', 'suspended_userids', array(), array($instance->courseid)); // Trigger event. $event = \core\event\user_enrolment_updated::create( array( 'objectid' => $ue->id, 'courseid' => $instance->courseid, 'context' => context_course::instance($instance->courseid), 'relateduserid' => $ue->userid, 'other' => array('enrol' => $name) ) ); $event->trigger(); core_course_category::user_enrolment_changed($instance->courseid, $ue->userid, $ue->status, $ue->timestart, $ue->timeend); }
[ "public", "function", "update_user_enrol", "(", "stdClass", "$", "instance", ",", "$", "userid", ",", "$", "status", "=", "NULL", ",", "$", "timestart", "=", "NULL", ",", "$", "timeend", "=", "NULL", ")", "{", "global", "$", "DB", ",", "$", "USER", ",", "$", "CFG", ";", "$", "name", "=", "$", "this", "->", "get_name", "(", ")", ";", "if", "(", "$", "instance", "->", "enrol", "!==", "$", "name", ")", "{", "throw", "new", "coding_exception", "(", "'invalid enrol instance!'", ")", ";", "}", "if", "(", "!", "$", "ue", "=", "$", "DB", "->", "get_record", "(", "'user_enrolments'", ",", "array", "(", "'enrolid'", "=>", "$", "instance", "->", "id", ",", "'userid'", "=>", "$", "userid", ")", ")", ")", "{", "// weird, user not enrolled", "return", ";", "}", "$", "modified", "=", "false", ";", "if", "(", "isset", "(", "$", "status", ")", "and", "$", "ue", "->", "status", "!=", "$", "status", ")", "{", "$", "ue", "->", "status", "=", "$", "status", ";", "$", "modified", "=", "true", ";", "}", "if", "(", "isset", "(", "$", "timestart", ")", "and", "$", "ue", "->", "timestart", "!=", "$", "timestart", ")", "{", "$", "ue", "->", "timestart", "=", "$", "timestart", ";", "$", "modified", "=", "true", ";", "}", "if", "(", "isset", "(", "$", "timeend", ")", "and", "$", "ue", "->", "timeend", "!=", "$", "timeend", ")", "{", "$", "ue", "->", "timeend", "=", "$", "timeend", ";", "$", "modified", "=", "true", ";", "}", "if", "(", "!", "$", "modified", ")", "{", "// no change", "return", ";", "}", "$", "ue", "->", "modifierid", "=", "$", "USER", "->", "id", ";", "$", "ue", "->", "timemodified", "=", "time", "(", ")", ";", "$", "DB", "->", "update_record", "(", "'user_enrolments'", ",", "$", "ue", ")", ";", "// User enrolments have changed, so mark user as dirty.", "mark_user_dirty", "(", "$", "userid", ")", ";", "// Invalidate core_access cache for get_suspended_userids.", "cache_helper", "::", "invalidate_by_definition", "(", "'core'", ",", "'suspended_userids'", ",", "array", "(", ")", ",", "array", "(", "$", "instance", "->", "courseid", ")", ")", ";", "// Trigger event.", "$", "event", "=", "\\", "core", "\\", "event", "\\", "user_enrolment_updated", "::", "create", "(", "array", "(", "'objectid'", "=>", "$", "ue", "->", "id", ",", "'courseid'", "=>", "$", "instance", "->", "courseid", ",", "'context'", "=>", "context_course", "::", "instance", "(", "$", "instance", "->", "courseid", ")", ",", "'relateduserid'", "=>", "$", "ue", "->", "userid", ",", "'other'", "=>", "array", "(", "'enrol'", "=>", "$", "name", ")", ")", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "core_course_category", "::", "user_enrolment_changed", "(", "$", "instance", "->", "courseid", ",", "$", "ue", "->", "userid", ",", "$", "ue", "->", "status", ",", "$", "ue", "->", "timestart", ",", "$", "ue", "->", "timeend", ")", ";", "}" ]
Store user_enrolments changes and trigger event. @param stdClass $instance @param int $userid @param int $status @param int $timestart @param int $timeend @return void
[ "Store", "user_enrolments", "changes", "and", "trigger", "event", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/enrollib.php#L2016-L2073
216,724
moodle/moodle
lib/enrollib.php
enrol_plugin.can_edit_instance
public function can_edit_instance($instance) { $context = context_course::instance($instance->courseid); return has_capability('enrol/' . $instance->enrol . ':config', $context); }
php
public function can_edit_instance($instance) { $context = context_course::instance($instance->courseid); return has_capability('enrol/' . $instance->enrol . ':config', $context); }
[ "public", "function", "can_edit_instance", "(", "$", "instance", ")", "{", "$", "context", "=", "context_course", "::", "instance", "(", "$", "instance", "->", "courseid", ")", ";", "return", "has_capability", "(", "'enrol/'", ".", "$", "instance", "->", "enrol", ".", "':config'", ",", "$", "context", ")", ";", "}" ]
Return whether or not, given the current state, it is possible to edit an instance of this enrolment plugin in the course. Used by the standard editing UI to generate a link to the edit instance form if editing is allowed. @param stdClass $instance @return boolean
[ "Return", "whether", "or", "not", "given", "the", "current", "state", "it", "is", "possible", "to", "edit", "an", "instance", "of", "this", "enrolment", "plugin", "in", "the", "course", ".", "Used", "by", "the", "standard", "editing", "UI", "to", "generate", "a", "link", "to", "the", "edit", "instance", "form", "if", "editing", "is", "allowed", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/enrollib.php#L2216-L2220
216,725
moodle/moodle
lib/enrollib.php
enrol_plugin.get_unenrolself_link
public function get_unenrolself_link($instance) { global $USER, $CFG, $DB; $name = $this->get_name(); if ($instance->enrol !== $name) { throw new coding_exception('invalid enrol instance!'); } if ($instance->courseid == SITEID) { return NULL; } if (!enrol_is_enabled($name)) { return NULL; } if ($instance->status != ENROL_INSTANCE_ENABLED) { return NULL; } if (!file_exists("$CFG->dirroot/enrol/$name/unenrolself.php")) { return NULL; } $context = context_course::instance($instance->courseid, MUST_EXIST); if (!has_capability("enrol/$name:unenrolself", $context)) { return NULL; } if (!$DB->record_exists('user_enrolments', array('enrolid'=>$instance->id, 'userid'=>$USER->id, 'status'=>ENROL_USER_ACTIVE))) { return NULL; } return new moodle_url("/enrol/$name/unenrolself.php", array('enrolid'=>$instance->id)); }
php
public function get_unenrolself_link($instance) { global $USER, $CFG, $DB; $name = $this->get_name(); if ($instance->enrol !== $name) { throw new coding_exception('invalid enrol instance!'); } if ($instance->courseid == SITEID) { return NULL; } if (!enrol_is_enabled($name)) { return NULL; } if ($instance->status != ENROL_INSTANCE_ENABLED) { return NULL; } if (!file_exists("$CFG->dirroot/enrol/$name/unenrolself.php")) { return NULL; } $context = context_course::instance($instance->courseid, MUST_EXIST); if (!has_capability("enrol/$name:unenrolself", $context)) { return NULL; } if (!$DB->record_exists('user_enrolments', array('enrolid'=>$instance->id, 'userid'=>$USER->id, 'status'=>ENROL_USER_ACTIVE))) { return NULL; } return new moodle_url("/enrol/$name/unenrolself.php", array('enrolid'=>$instance->id)); }
[ "public", "function", "get_unenrolself_link", "(", "$", "instance", ")", "{", "global", "$", "USER", ",", "$", "CFG", ",", "$", "DB", ";", "$", "name", "=", "$", "this", "->", "get_name", "(", ")", ";", "if", "(", "$", "instance", "->", "enrol", "!==", "$", "name", ")", "{", "throw", "new", "coding_exception", "(", "'invalid enrol instance!'", ")", ";", "}", "if", "(", "$", "instance", "->", "courseid", "==", "SITEID", ")", "{", "return", "NULL", ";", "}", "if", "(", "!", "enrol_is_enabled", "(", "$", "name", ")", ")", "{", "return", "NULL", ";", "}", "if", "(", "$", "instance", "->", "status", "!=", "ENROL_INSTANCE_ENABLED", ")", "{", "return", "NULL", ";", "}", "if", "(", "!", "file_exists", "(", "\"$CFG->dirroot/enrol/$name/unenrolself.php\"", ")", ")", "{", "return", "NULL", ";", "}", "$", "context", "=", "context_course", "::", "instance", "(", "$", "instance", "->", "courseid", ",", "MUST_EXIST", ")", ";", "if", "(", "!", "has_capability", "(", "\"enrol/$name:unenrolself\"", ",", "$", "context", ")", ")", "{", "return", "NULL", ";", "}", "if", "(", "!", "$", "DB", "->", "record_exists", "(", "'user_enrolments'", ",", "array", "(", "'enrolid'", "=>", "$", "instance", "->", "id", ",", "'userid'", "=>", "$", "USER", "->", "id", ",", "'status'", "=>", "ENROL_USER_ACTIVE", ")", ")", ")", "{", "return", "NULL", ";", "}", "return", "new", "moodle_url", "(", "\"/enrol/$name/unenrolself.php\"", ",", "array", "(", "'enrolid'", "=>", "$", "instance", "->", "id", ")", ")", ";", "}" ]
Returns list of unenrol links for all enrol instances in course. @param int $instance @return moodle_url or NULL if self unenrolment not supported
[ "Returns", "list", "of", "unenrol", "links", "for", "all", "enrol", "instances", "in", "course", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/enrollib.php#L2278-L2313
216,726
moodle/moodle
lib/enrollib.php
enrol_plugin.delete_instance
public function delete_instance($instance) { global $DB; $name = $this->get_name(); if ($instance->enrol !== $name) { throw new coding_exception('invalid enrol instance!'); } //first unenrol all users $participants = $DB->get_recordset('user_enrolments', array('enrolid'=>$instance->id)); foreach ($participants as $participant) { $this->unenrol_user($instance, $participant->userid); } $participants->close(); // now clean up all remainders that were not removed correctly if ($gms = $DB->get_records('groups_members', array('itemid' => $instance->id, 'component' => 'enrol_' . $name))) { foreach ($gms as $gm) { groups_remove_member($gm->groupid, $gm->userid); } } $DB->delete_records('role_assignments', array('itemid'=>$instance->id, 'component'=>'enrol_'.$name)); $DB->delete_records('user_enrolments', array('enrolid'=>$instance->id)); // finally drop the enrol row $DB->delete_records('enrol', array('id'=>$instance->id)); $context = context_course::instance($instance->courseid); \core\event\enrol_instance_deleted::create_from_record($instance)->trigger(); // Invalidate all enrol caches. $context->mark_dirty(); }
php
public function delete_instance($instance) { global $DB; $name = $this->get_name(); if ($instance->enrol !== $name) { throw new coding_exception('invalid enrol instance!'); } //first unenrol all users $participants = $DB->get_recordset('user_enrolments', array('enrolid'=>$instance->id)); foreach ($participants as $participant) { $this->unenrol_user($instance, $participant->userid); } $participants->close(); // now clean up all remainders that were not removed correctly if ($gms = $DB->get_records('groups_members', array('itemid' => $instance->id, 'component' => 'enrol_' . $name))) { foreach ($gms as $gm) { groups_remove_member($gm->groupid, $gm->userid); } } $DB->delete_records('role_assignments', array('itemid'=>$instance->id, 'component'=>'enrol_'.$name)); $DB->delete_records('user_enrolments', array('enrolid'=>$instance->id)); // finally drop the enrol row $DB->delete_records('enrol', array('id'=>$instance->id)); $context = context_course::instance($instance->courseid); \core\event\enrol_instance_deleted::create_from_record($instance)->trigger(); // Invalidate all enrol caches. $context->mark_dirty(); }
[ "public", "function", "delete_instance", "(", "$", "instance", ")", "{", "global", "$", "DB", ";", "$", "name", "=", "$", "this", "->", "get_name", "(", ")", ";", "if", "(", "$", "instance", "->", "enrol", "!==", "$", "name", ")", "{", "throw", "new", "coding_exception", "(", "'invalid enrol instance!'", ")", ";", "}", "//first unenrol all users", "$", "participants", "=", "$", "DB", "->", "get_recordset", "(", "'user_enrolments'", ",", "array", "(", "'enrolid'", "=>", "$", "instance", "->", "id", ")", ")", ";", "foreach", "(", "$", "participants", "as", "$", "participant", ")", "{", "$", "this", "->", "unenrol_user", "(", "$", "instance", ",", "$", "participant", "->", "userid", ")", ";", "}", "$", "participants", "->", "close", "(", ")", ";", "// now clean up all remainders that were not removed correctly", "if", "(", "$", "gms", "=", "$", "DB", "->", "get_records", "(", "'groups_members'", ",", "array", "(", "'itemid'", "=>", "$", "instance", "->", "id", ",", "'component'", "=>", "'enrol_'", ".", "$", "name", ")", ")", ")", "{", "foreach", "(", "$", "gms", "as", "$", "gm", ")", "{", "groups_remove_member", "(", "$", "gm", "->", "groupid", ",", "$", "gm", "->", "userid", ")", ";", "}", "}", "$", "DB", "->", "delete_records", "(", "'role_assignments'", ",", "array", "(", "'itemid'", "=>", "$", "instance", "->", "id", ",", "'component'", "=>", "'enrol_'", ".", "$", "name", ")", ")", ";", "$", "DB", "->", "delete_records", "(", "'user_enrolments'", ",", "array", "(", "'enrolid'", "=>", "$", "instance", "->", "id", ")", ")", ";", "// finally drop the enrol row", "$", "DB", "->", "delete_records", "(", "'enrol'", ",", "array", "(", "'id'", "=>", "$", "instance", "->", "id", ")", ")", ";", "$", "context", "=", "context_course", "::", "instance", "(", "$", "instance", "->", "courseid", ")", ";", "\\", "core", "\\", "event", "\\", "enrol_instance_deleted", "::", "create_from_record", "(", "$", "instance", ")", "->", "trigger", "(", ")", ";", "// Invalidate all enrol caches.", "$", "context", "->", "mark_dirty", "(", ")", ";", "}" ]
Delete course enrol plugin instance, unenrol all users. @param object $instance @return void
[ "Delete", "course", "enrol", "plugin", "instance", "unenrol", "all", "users", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/enrollib.php#L2495-L2527
216,727
moodle/moodle
lib/enrollib.php
enrol_plugin.add_course_navigation
public function add_course_navigation($instancesnode, stdClass $instance) { if ($this->use_standard_editing_ui()) { $context = context_course::instance($instance->courseid); $cap = 'enrol/' . $instance->enrol . ':config'; if (has_capability($cap, $context)) { $linkparams = array('courseid' => $instance->courseid, 'id' => $instance->id, 'type' => $instance->enrol); $managelink = new moodle_url('/enrol/editinstance.php', $linkparams); $instancesnode->add($this->get_instance_name($instance), $managelink, navigation_node::TYPE_SETTING); } } }
php
public function add_course_navigation($instancesnode, stdClass $instance) { if ($this->use_standard_editing_ui()) { $context = context_course::instance($instance->courseid); $cap = 'enrol/' . $instance->enrol . ':config'; if (has_capability($cap, $context)) { $linkparams = array('courseid' => $instance->courseid, 'id' => $instance->id, 'type' => $instance->enrol); $managelink = new moodle_url('/enrol/editinstance.php', $linkparams); $instancesnode->add($this->get_instance_name($instance), $managelink, navigation_node::TYPE_SETTING); } } }
[ "public", "function", "add_course_navigation", "(", "$", "instancesnode", ",", "stdClass", "$", "instance", ")", "{", "if", "(", "$", "this", "->", "use_standard_editing_ui", "(", ")", ")", "{", "$", "context", "=", "context_course", "::", "instance", "(", "$", "instance", "->", "courseid", ")", ";", "$", "cap", "=", "'enrol/'", ".", "$", "instance", "->", "enrol", ".", "':config'", ";", "if", "(", "has_capability", "(", "$", "cap", ",", "$", "context", ")", ")", "{", "$", "linkparams", "=", "array", "(", "'courseid'", "=>", "$", "instance", "->", "courseid", ",", "'id'", "=>", "$", "instance", "->", "id", ",", "'type'", "=>", "$", "instance", "->", "enrol", ")", ";", "$", "managelink", "=", "new", "moodle_url", "(", "'/enrol/editinstance.php'", ",", "$", "linkparams", ")", ";", "$", "instancesnode", "->", "add", "(", "$", "this", "->", "get_instance_name", "(", "$", "instance", ")", ",", "$", "managelink", ",", "navigation_node", "::", "TYPE_SETTING", ")", ";", "}", "}", "}" ]
Adds navigation links into course admin block. By defaults looks for manage links only. @param navigation_node $instancesnode @param stdClass $instance @return void
[ "Adds", "navigation", "links", "into", "course", "admin", "block", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/enrollib.php#L2572-L2582
216,728
moodle/moodle
lib/enrollib.php
enrol_plugin.get_action_icons
public function get_action_icons(stdClass $instance) { global $OUTPUT; $icons = array(); if ($this->use_standard_editing_ui()) { $linkparams = array('courseid' => $instance->courseid, 'id' => $instance->id, 'type' => $instance->enrol); $editlink = new moodle_url("/enrol/editinstance.php", $linkparams); $icons[] = $OUTPUT->action_icon($editlink, new pix_icon('t/edit', get_string('edit'), 'core', array('class' => 'iconsmall'))); } return $icons; }
php
public function get_action_icons(stdClass $instance) { global $OUTPUT; $icons = array(); if ($this->use_standard_editing_ui()) { $linkparams = array('courseid' => $instance->courseid, 'id' => $instance->id, 'type' => $instance->enrol); $editlink = new moodle_url("/enrol/editinstance.php", $linkparams); $icons[] = $OUTPUT->action_icon($editlink, new pix_icon('t/edit', get_string('edit'), 'core', array('class' => 'iconsmall'))); } return $icons; }
[ "public", "function", "get_action_icons", "(", "stdClass", "$", "instance", ")", "{", "global", "$", "OUTPUT", ";", "$", "icons", "=", "array", "(", ")", ";", "if", "(", "$", "this", "->", "use_standard_editing_ui", "(", ")", ")", "{", "$", "linkparams", "=", "array", "(", "'courseid'", "=>", "$", "instance", "->", "courseid", ",", "'id'", "=>", "$", "instance", "->", "id", ",", "'type'", "=>", "$", "instance", "->", "enrol", ")", ";", "$", "editlink", "=", "new", "moodle_url", "(", "\"/enrol/editinstance.php\"", ",", "$", "linkparams", ")", ";", "$", "icons", "[", "]", "=", "$", "OUTPUT", "->", "action_icon", "(", "$", "editlink", ",", "new", "pix_icon", "(", "'t/edit'", ",", "get_string", "(", "'edit'", ")", ",", "'core'", ",", "array", "(", "'class'", "=>", "'iconsmall'", ")", ")", ")", ";", "}", "return", "$", "icons", ";", "}" ]
Returns edit icons for the page with list of instances @param stdClass $instance @return array
[ "Returns", "edit", "icons", "for", "the", "page", "with", "list", "of", "instances" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/enrollib.php#L2589-L2600
216,729
moodle/moodle
lib/enrollib.php
enrol_plugin.is_cron_required
public function is_cron_required() { global $CFG; $name = $this->get_name(); $versionfile = "$CFG->dirroot/enrol/$name/version.php"; $plugin = new stdClass(); include($versionfile); if (empty($plugin->cron)) { return false; } $lastexecuted = $this->get_config('lastcron', 0); if ($lastexecuted + $plugin->cron < time()) { return true; } else { return false; } }
php
public function is_cron_required() { global $CFG; $name = $this->get_name(); $versionfile = "$CFG->dirroot/enrol/$name/version.php"; $plugin = new stdClass(); include($versionfile); if (empty($plugin->cron)) { return false; } $lastexecuted = $this->get_config('lastcron', 0); if ($lastexecuted + $plugin->cron < time()) { return true; } else { return false; } }
[ "public", "function", "is_cron_required", "(", ")", "{", "global", "$", "CFG", ";", "$", "name", "=", "$", "this", "->", "get_name", "(", ")", ";", "$", "versionfile", "=", "\"$CFG->dirroot/enrol/$name/version.php\"", ";", "$", "plugin", "=", "new", "stdClass", "(", ")", ";", "include", "(", "$", "versionfile", ")", ";", "if", "(", "empty", "(", "$", "plugin", "->", "cron", ")", ")", "{", "return", "false", ";", "}", "$", "lastexecuted", "=", "$", "this", "->", "get_config", "(", "'lastcron'", ",", "0", ")", ";", "if", "(", "$", "lastexecuted", "+", "$", "plugin", "->", "cron", "<", "time", "(", ")", ")", "{", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Reads version.php and determines if it is necessary to execute the cron job now. @return bool
[ "Reads", "version", ".", "php", "and", "determines", "if", "it", "is", "necessary", "to", "execute", "the", "cron", "job", "now", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/enrollib.php#L2607-L2623
216,730
moodle/moodle
lib/enrollib.php
enrol_plugin.user_delete
public function user_delete($user) { global $DB; $sql = "SELECT e.* FROM {enrol} e JOIN {user_enrolments} ue ON (ue.enrolid = e.id) WHERE e.enrol = :name AND ue.userid = :userid"; $params = array('name'=>$this->get_name(), 'userid'=>$user->id); $rs = $DB->get_recordset_sql($sql, $params); foreach($rs as $instance) { $this->unenrol_user($instance, $user->id); } $rs->close(); }
php
public function user_delete($user) { global $DB; $sql = "SELECT e.* FROM {enrol} e JOIN {user_enrolments} ue ON (ue.enrolid = e.id) WHERE e.enrol = :name AND ue.userid = :userid"; $params = array('name'=>$this->get_name(), 'userid'=>$user->id); $rs = $DB->get_recordset_sql($sql, $params); foreach($rs as $instance) { $this->unenrol_user($instance, $user->id); } $rs->close(); }
[ "public", "function", "user_delete", "(", "$", "user", ")", "{", "global", "$", "DB", ";", "$", "sql", "=", "\"SELECT e.*\n FROM {enrol} e\n JOIN {user_enrolments} ue ON (ue.enrolid = e.id)\n WHERE e.enrol = :name AND ue.userid = :userid\"", ";", "$", "params", "=", "array", "(", "'name'", "=>", "$", "this", "->", "get_name", "(", ")", ",", "'userid'", "=>", "$", "user", "->", "id", ")", ";", "$", "rs", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "foreach", "(", "$", "rs", "as", "$", "instance", ")", "{", "$", "this", "->", "unenrol_user", "(", "$", "instance", ",", "$", "user", "->", "id", ")", ";", "}", "$", "rs", "->", "close", "(", ")", ";", "}" ]
Called when user is about to be deleted @param object $user @return void
[ "Called", "when", "user", "is", "about", "to", "be", "deleted" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/enrollib.php#L2637-L2651
216,731
moodle/moodle
lib/enrollib.php
enrol_plugin.get_user_enrolment_actions
public function get_user_enrolment_actions(course_enrolment_manager $manager, $ue) { $actions = []; $context = $manager->get_context(); $instance = $ue->enrolmentinstance; $params = $manager->get_moodlepage()->url->params(); $params['ue'] = $ue->id; // Edit enrolment action. if ($this->allow_manage($instance) && has_capability("enrol/{$instance->enrol}:manage", $context)) { $title = get_string('editenrolment', 'enrol'); $icon = new pix_icon('t/edit', $title); $url = new moodle_url('/enrol/editenrolment.php', $params); $actionparams = [ 'class' => 'editenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_EDIT ]; $actions[] = new user_enrolment_action($icon, $title, $url, $actionparams); } // Unenrol action. if ($this->allow_unenrol_user($instance, $ue) && has_capability("enrol/{$instance->enrol}:unenrol", $context)) { $title = get_string('unenrol', 'enrol'); $icon = new pix_icon('t/delete', $title); $url = new moodle_url('/enrol/unenroluser.php', $params); $actionparams = [ 'class' => 'unenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_UNENROL ]; $actions[] = new user_enrolment_action($icon, $title, $url, $actionparams); } return $actions; }
php
public function get_user_enrolment_actions(course_enrolment_manager $manager, $ue) { $actions = []; $context = $manager->get_context(); $instance = $ue->enrolmentinstance; $params = $manager->get_moodlepage()->url->params(); $params['ue'] = $ue->id; // Edit enrolment action. if ($this->allow_manage($instance) && has_capability("enrol/{$instance->enrol}:manage", $context)) { $title = get_string('editenrolment', 'enrol'); $icon = new pix_icon('t/edit', $title); $url = new moodle_url('/enrol/editenrolment.php', $params); $actionparams = [ 'class' => 'editenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_EDIT ]; $actions[] = new user_enrolment_action($icon, $title, $url, $actionparams); } // Unenrol action. if ($this->allow_unenrol_user($instance, $ue) && has_capability("enrol/{$instance->enrol}:unenrol", $context)) { $title = get_string('unenrol', 'enrol'); $icon = new pix_icon('t/delete', $title); $url = new moodle_url('/enrol/unenroluser.php', $params); $actionparams = [ 'class' => 'unenrollink', 'rel' => $ue->id, 'data-action' => ENROL_ACTION_UNENROL ]; $actions[] = new user_enrolment_action($icon, $title, $url, $actionparams); } return $actions; }
[ "public", "function", "get_user_enrolment_actions", "(", "course_enrolment_manager", "$", "manager", ",", "$", "ue", ")", "{", "$", "actions", "=", "[", "]", ";", "$", "context", "=", "$", "manager", "->", "get_context", "(", ")", ";", "$", "instance", "=", "$", "ue", "->", "enrolmentinstance", ";", "$", "params", "=", "$", "manager", "->", "get_moodlepage", "(", ")", "->", "url", "->", "params", "(", ")", ";", "$", "params", "[", "'ue'", "]", "=", "$", "ue", "->", "id", ";", "// Edit enrolment action.", "if", "(", "$", "this", "->", "allow_manage", "(", "$", "instance", ")", "&&", "has_capability", "(", "\"enrol/{$instance->enrol}:manage\"", ",", "$", "context", ")", ")", "{", "$", "title", "=", "get_string", "(", "'editenrolment'", ",", "'enrol'", ")", ";", "$", "icon", "=", "new", "pix_icon", "(", "'t/edit'", ",", "$", "title", ")", ";", "$", "url", "=", "new", "moodle_url", "(", "'/enrol/editenrolment.php'", ",", "$", "params", ")", ";", "$", "actionparams", "=", "[", "'class'", "=>", "'editenrollink'", ",", "'rel'", "=>", "$", "ue", "->", "id", ",", "'data-action'", "=>", "ENROL_ACTION_EDIT", "]", ";", "$", "actions", "[", "]", "=", "new", "user_enrolment_action", "(", "$", "icon", ",", "$", "title", ",", "$", "url", ",", "$", "actionparams", ")", ";", "}", "// Unenrol action.", "if", "(", "$", "this", "->", "allow_unenrol_user", "(", "$", "instance", ",", "$", "ue", ")", "&&", "has_capability", "(", "\"enrol/{$instance->enrol}:unenrol\"", ",", "$", "context", ")", ")", "{", "$", "title", "=", "get_string", "(", "'unenrol'", ",", "'enrol'", ")", ";", "$", "icon", "=", "new", "pix_icon", "(", "'t/delete'", ",", "$", "title", ")", ";", "$", "url", "=", "new", "moodle_url", "(", "'/enrol/unenroluser.php'", ",", "$", "params", ")", ";", "$", "actionparams", "=", "[", "'class'", "=>", "'unenrollink'", ",", "'rel'", "=>", "$", "ue", "->", "id", ",", "'data-action'", "=>", "ENROL_ACTION_UNENROL", "]", ";", "$", "actions", "[", "]", "=", "new", "user_enrolment_action", "(", "$", "icon", ",", "$", "title", ",", "$", "url", ",", "$", "actionparams", ")", ";", "}", "return", "$", "actions", ";", "}" ]
Gets an array of the user enrolment actions @param course_enrolment_manager $manager @param stdClass $ue @return array An array of user_enrolment_actions
[ "Gets", "an", "array", "of", "the", "user", "enrolment", "actions" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/enrollib.php#L2674-L2707
216,732
moodle/moodle
mod/chat/classes/privacy/provider.php
provider.get_chat_ids_to_cmids_from_cmids
protected static function get_chat_ids_to_cmids_from_cmids(array $cmids) { global $DB; list($insql, $inparams) = $DB->get_in_or_equal($cmids, SQL_PARAMS_NAMED); $sql = " SELECT c.id, cm.id AS cmid FROM {chat} c JOIN {modules} m ON m.name = :chat JOIN {course_modules} cm ON cm.instance = c.id AND cm.module = m.id WHERE cm.id $insql"; $params = array_merge($inparams, ['chat' => 'chat']); return $DB->get_records_sql_menu($sql, $params); }
php
protected static function get_chat_ids_to_cmids_from_cmids(array $cmids) { global $DB; list($insql, $inparams) = $DB->get_in_or_equal($cmids, SQL_PARAMS_NAMED); $sql = " SELECT c.id, cm.id AS cmid FROM {chat} c JOIN {modules} m ON m.name = :chat JOIN {course_modules} cm ON cm.instance = c.id AND cm.module = m.id WHERE cm.id $insql"; $params = array_merge($inparams, ['chat' => 'chat']); return $DB->get_records_sql_menu($sql, $params); }
[ "protected", "static", "function", "get_chat_ids_to_cmids_from_cmids", "(", "array", "$", "cmids", ")", "{", "global", "$", "DB", ";", "list", "(", "$", "insql", ",", "$", "inparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "cmids", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "sql", "=", "\"\n SELECT c.id, cm.id AS cmid\n FROM {chat} c\n JOIN {modules} m\n ON m.name = :chat\n JOIN {course_modules} cm\n ON cm.instance = c.id\n AND cm.module = m.id\n WHERE cm.id $insql\"", ";", "$", "params", "=", "array_merge", "(", "$", "inparams", ",", "[", "'chat'", "=>", "'chat'", "]", ")", ";", "return", "$", "DB", "->", "get_records_sql_menu", "(", "$", "sql", ",", "$", "params", ")", ";", "}" ]
Return a dict of chat IDs mapped to their course module ID. @param array $cmids The course module IDs. @return array In the form of [$chatid => $cmid].
[ "Return", "a", "dict", "of", "chat", "IDs", "mapped", "to", "their", "course", "module", "ID", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/chat/classes/privacy/provider.php#L286-L300
216,733
moodle/moodle
lib/htmlpurifier/HTMLPurifier/IDAccumulator.php
HTMLPurifier_IDAccumulator.build
public static function build($config, $context) { $id_accumulator = new HTMLPurifier_IDAccumulator(); $id_accumulator->load($config->get('Attr.IDBlacklist')); return $id_accumulator; }
php
public static function build($config, $context) { $id_accumulator = new HTMLPurifier_IDAccumulator(); $id_accumulator->load($config->get('Attr.IDBlacklist')); return $id_accumulator; }
[ "public", "static", "function", "build", "(", "$", "config", ",", "$", "context", ")", "{", "$", "id_accumulator", "=", "new", "HTMLPurifier_IDAccumulator", "(", ")", ";", "$", "id_accumulator", "->", "load", "(", "$", "config", "->", "get", "(", "'Attr.IDBlacklist'", ")", ")", ";", "return", "$", "id_accumulator", ";", "}" ]
Builds an IDAccumulator, also initializing the default blacklist @param HTMLPurifier_Config $config Instance of HTMLPurifier_Config @param HTMLPurifier_Context $context Instance of HTMLPurifier_Context @return HTMLPurifier_IDAccumulator Fully initialized HTMLPurifier_IDAccumulator
[ "Builds", "an", "IDAccumulator", "also", "initializing", "the", "default", "blacklist" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/IDAccumulator.php#L24-L29
216,734
moodle/moodle
lib/htmlpurifier/HTMLPurifier/IDAccumulator.php
HTMLPurifier_IDAccumulator.add
public function add($id) { if (isset($this->ids[$id])) { return false; } return $this->ids[$id] = true; }
php
public function add($id) { if (isset($this->ids[$id])) { return false; } return $this->ids[$id] = true; }
[ "public", "function", "add", "(", "$", "id", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "ids", "[", "$", "id", "]", ")", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "ids", "[", "$", "id", "]", "=", "true", ";", "}" ]
Add an ID to the lookup table. @param string $id ID to be added. @return bool status, true if success, false if there's a dupe
[ "Add", "an", "ID", "to", "the", "lookup", "table", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/IDAccumulator.php#L36-L42
216,735
moodle/moodle
question/type/ddimageortext/rendererbase.php
qtype_ddtoimage_renderer_base.get_url_for_image
protected static function get_url_for_image(question_attempt $qa, $filearea, $itemid = 0) { $question = $qa->get_question(); $qubaid = $qa->get_usage_id(); $slot = $qa->get_slot(); $fs = get_file_storage(); if ($filearea == 'bgimage') { $itemid = $question->id; } $componentname = $question->qtype->plugin_name(); $draftfiles = $fs->get_area_files($question->contextid, $componentname, $filearea, $itemid, 'id'); if ($draftfiles) { foreach ($draftfiles as $file) { if ($file->is_directory()) { continue; } $url = moodle_url::make_pluginfile_url($question->contextid, $componentname, $filearea, "$qubaid/$slot/{$itemid}", '/', $file->get_filename()); return $url->out(); } } return null; }
php
protected static function get_url_for_image(question_attempt $qa, $filearea, $itemid = 0) { $question = $qa->get_question(); $qubaid = $qa->get_usage_id(); $slot = $qa->get_slot(); $fs = get_file_storage(); if ($filearea == 'bgimage') { $itemid = $question->id; } $componentname = $question->qtype->plugin_name(); $draftfiles = $fs->get_area_files($question->contextid, $componentname, $filearea, $itemid, 'id'); if ($draftfiles) { foreach ($draftfiles as $file) { if ($file->is_directory()) { continue; } $url = moodle_url::make_pluginfile_url($question->contextid, $componentname, $filearea, "$qubaid/$slot/{$itemid}", '/', $file->get_filename()); return $url->out(); } } return null; }
[ "protected", "static", "function", "get_url_for_image", "(", "question_attempt", "$", "qa", ",", "$", "filearea", ",", "$", "itemid", "=", "0", ")", "{", "$", "question", "=", "$", "qa", "->", "get_question", "(", ")", ";", "$", "qubaid", "=", "$", "qa", "->", "get_usage_id", "(", ")", ";", "$", "slot", "=", "$", "qa", "->", "get_slot", "(", ")", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "if", "(", "$", "filearea", "==", "'bgimage'", ")", "{", "$", "itemid", "=", "$", "question", "->", "id", ";", "}", "$", "componentname", "=", "$", "question", "->", "qtype", "->", "plugin_name", "(", ")", ";", "$", "draftfiles", "=", "$", "fs", "->", "get_area_files", "(", "$", "question", "->", "contextid", ",", "$", "componentname", ",", "$", "filearea", ",", "$", "itemid", ",", "'id'", ")", ";", "if", "(", "$", "draftfiles", ")", "{", "foreach", "(", "$", "draftfiles", "as", "$", "file", ")", "{", "if", "(", "$", "file", "->", "is_directory", "(", ")", ")", "{", "continue", ";", "}", "$", "url", "=", "moodle_url", "::", "make_pluginfile_url", "(", "$", "question", "->", "contextid", ",", "$", "componentname", ",", "$", "filearea", ",", "\"$qubaid/$slot/{$itemid}\"", ",", "'/'", ",", "$", "file", "->", "get_filename", "(", ")", ")", ";", "return", "$", "url", "->", "out", "(", ")", ";", "}", "}", "return", "null", ";", "}" ]
Returns the URL for an image @param object $qa Question attempt object @param string $filearea File area descriptor @param int $itemid Item id to get @return string Output url, or null if not found
[ "Returns", "the", "URL", "for", "an", "image" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/ddimageortext/rendererbase.php#L136-L159
216,736
moodle/moodle
question/type/ddimageortext/rendererbase.php
qtype_ddtoimage_renderer_base.hidden_field_for_qt_var
protected function hidden_field_for_qt_var(question_attempt $qa, $varname, $value = null, $classes = null) { if ($value === null) { $value = $qa->get_last_qt_var($varname); } $fieldname = $qa->get_qt_field_name($varname); $attributes = array('type' => 'hidden', 'id' => str_replace(':', '_', $fieldname), 'name' => $fieldname, 'value' => $value); if ($classes !== null) { $attributes['class'] = join(' ', $classes); } return array($fieldname, html_writer::empty_tag('input', $attributes)."\n"); }
php
protected function hidden_field_for_qt_var(question_attempt $qa, $varname, $value = null, $classes = null) { if ($value === null) { $value = $qa->get_last_qt_var($varname); } $fieldname = $qa->get_qt_field_name($varname); $attributes = array('type' => 'hidden', 'id' => str_replace(':', '_', $fieldname), 'name' => $fieldname, 'value' => $value); if ($classes !== null) { $attributes['class'] = join(' ', $classes); } return array($fieldname, html_writer::empty_tag('input', $attributes)."\n"); }
[ "protected", "function", "hidden_field_for_qt_var", "(", "question_attempt", "$", "qa", ",", "$", "varname", ",", "$", "value", "=", "null", ",", "$", "classes", "=", "null", ")", "{", "if", "(", "$", "value", "===", "null", ")", "{", "$", "value", "=", "$", "qa", "->", "get_last_qt_var", "(", "$", "varname", ")", ";", "}", "$", "fieldname", "=", "$", "qa", "->", "get_qt_field_name", "(", "$", "varname", ")", ";", "$", "attributes", "=", "array", "(", "'type'", "=>", "'hidden'", ",", "'id'", "=>", "str_replace", "(", "':'", ",", "'_'", ",", "$", "fieldname", ")", ",", "'name'", "=>", "$", "fieldname", ",", "'value'", "=>", "$", "value", ")", ";", "if", "(", "$", "classes", "!==", "null", ")", "{", "$", "attributes", "[", "'class'", "]", "=", "join", "(", "' '", ",", "$", "classes", ")", ";", "}", "return", "array", "(", "$", "fieldname", ",", "html_writer", "::", "empty_tag", "(", "'input'", ",", "$", "attributes", ")", ".", "\"\\n\"", ")", ";", "}" ]
Returns a hidden field for a qt variable @param object $qa Question attempt object @param string $varname The hidden var name @param string $value The hidden value @param array $classes Any additional css classes to apply @return array Array with field name and the html of the tag
[ "Returns", "a", "hidden", "field", "for", "a", "qt", "variable" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/ddimageortext/rendererbase.php#L170-L184
216,737
moodle/moodle
lib/mlbackend/php/phpml/src/Phpml/Math/LinearAlgebra/EigenvalueDecomposition.php
EigenvalueDecomposition.getEigenvectors
public function getEigenvectors() { $vectors = $this->V; // Always return the eigenvectors of length 1.0 $vectors = new Matrix($vectors); $vectors = array_map(function ($vect) { $sum = 0; for ($i = 0; $i < count($vect); ++$i) { $sum += $vect[$i] ** 2; } $sum = sqrt($sum); for ($i = 0; $i < count($vect); ++$i) { $vect[$i] /= $sum; } return $vect; }, $vectors->transpose()->toArray()); return $vectors; }
php
public function getEigenvectors() { $vectors = $this->V; // Always return the eigenvectors of length 1.0 $vectors = new Matrix($vectors); $vectors = array_map(function ($vect) { $sum = 0; for ($i = 0; $i < count($vect); ++$i) { $sum += $vect[$i] ** 2; } $sum = sqrt($sum); for ($i = 0; $i < count($vect); ++$i) { $vect[$i] /= $sum; } return $vect; }, $vectors->transpose()->toArray()); return $vectors; }
[ "public", "function", "getEigenvectors", "(", ")", "{", "$", "vectors", "=", "$", "this", "->", "V", ";", "// Always return the eigenvectors of length 1.0", "$", "vectors", "=", "new", "Matrix", "(", "$", "vectors", ")", ";", "$", "vectors", "=", "array_map", "(", "function", "(", "$", "vect", ")", "{", "$", "sum", "=", "0", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "vect", ")", ";", "++", "$", "i", ")", "{", "$", "sum", "+=", "$", "vect", "[", "$", "i", "]", "**", "2", ";", "}", "$", "sum", "=", "sqrt", "(", "$", "sum", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "vect", ")", ";", "++", "$", "i", ")", "{", "$", "vect", "[", "$", "i", "]", "/=", "$", "sum", ";", "}", "return", "$", "vect", ";", "}", ",", "$", "vectors", "->", "transpose", "(", ")", "->", "toArray", "(", ")", ")", ";", "return", "$", "vectors", ";", "}" ]
Return the eigenvector matrix @access public @return array
[ "Return", "the", "eigenvector", "matrix" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mlbackend/php/phpml/src/Phpml/Math/LinearAlgebra/EigenvalueDecomposition.php#L835-L856
216,738
moodle/moodle
admin/roles/classes/capability_table_with_risks.php
core_role_capability_table_with_risks.save_changes
public function save_changes() { // Set the permissions. foreach ($this->changed as $changedcap) { assign_capability($changedcap, $this->permissions[$changedcap], $this->roleid, $this->context->id, true); } }
php
public function save_changes() { // Set the permissions. foreach ($this->changed as $changedcap) { assign_capability($changedcap, $this->permissions[$changedcap], $this->roleid, $this->context->id, true); } }
[ "public", "function", "save_changes", "(", ")", "{", "// Set the permissions.", "foreach", "(", "$", "this", "->", "changed", "as", "$", "changedcap", ")", "{", "assign_capability", "(", "$", "changedcap", ",", "$", "this", "->", "permissions", "[", "$", "changedcap", "]", ",", "$", "this", "->", "roleid", ",", "$", "this", "->", "context", "->", "id", ",", "true", ")", ";", "}", "}" ]
Save the new values of any permissions that have been changed.
[ "Save", "the", "new", "values", "of", "any", "permissions", "that", "have", "been", "changed", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/roles/classes/capability_table_with_risks.php#L120-L126
216,739
moodle/moodle
admin/roles/classes/capability_table_with_risks.php
core_role_capability_table_with_risks.get_risk_icon
public function get_risk_icon($type) { global $OUTPUT; $alt = get_string("{$type}short", "admin"); $title = get_string($type, "admin"); $text = $OUTPUT->pix_icon('i/' . str_replace('risk', 'risk_', $type), $alt, 'moodle', [ 'title' => $title, ]); $action = new popup_action('click', $this->risksurl, 'docspopup'); $riskicon = $OUTPUT->action_link($this->risksurl, $text, $action); return $riskicon; }
php
public function get_risk_icon($type) { global $OUTPUT; $alt = get_string("{$type}short", "admin"); $title = get_string($type, "admin"); $text = $OUTPUT->pix_icon('i/' . str_replace('risk', 'risk_', $type), $alt, 'moodle', [ 'title' => $title, ]); $action = new popup_action('click', $this->risksurl, 'docspopup'); $riskicon = $OUTPUT->action_link($this->risksurl, $text, $action); return $riskicon; }
[ "public", "function", "get_risk_icon", "(", "$", "type", ")", "{", "global", "$", "OUTPUT", ";", "$", "alt", "=", "get_string", "(", "\"{$type}short\"", ",", "\"admin\"", ")", ";", "$", "title", "=", "get_string", "(", "$", "type", ",", "\"admin\"", ")", ";", "$", "text", "=", "$", "OUTPUT", "->", "pix_icon", "(", "'i/'", ".", "str_replace", "(", "'risk'", ",", "'risk_'", ",", "$", "type", ")", ",", "$", "alt", ",", "'moodle'", ",", "[", "'title'", "=>", "$", "title", ",", "]", ")", ";", "$", "action", "=", "new", "popup_action", "(", "'click'", ",", "$", "this", "->", "risksurl", ",", "'docspopup'", ")", ";", "$", "riskicon", "=", "$", "OUTPUT", "->", "action_link", "(", "$", "this", "->", "risksurl", ",", "$", "text", ",", "$", "action", ")", ";", "return", "$", "riskicon", ";", "}" ]
Print a risk icon, as a link to the Risks page on Moodle Docs. @param string $type the type of risk, will be one of the keys from the get_all_risks array. Must start with 'risk'.
[ "Print", "a", "risk", "icon", "as", "a", "link", "to", "the", "Risks", "page", "on", "Moodle", "Docs", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/roles/classes/capability_table_with_risks.php#L180-L193
216,740
moodle/moodle
mod/forum/classes/local/factories/vault.php
vault.get_forum_vault
public function get_forum_vault() : forum_vault { return new forum_vault( $this->db, $this->entityfactory, $this->legacymapper->get_legacy_data_mapper_for_vault('forum') ); }
php
public function get_forum_vault() : forum_vault { return new forum_vault( $this->db, $this->entityfactory, $this->legacymapper->get_legacy_data_mapper_for_vault('forum') ); }
[ "public", "function", "get_forum_vault", "(", ")", ":", "forum_vault", "{", "return", "new", "forum_vault", "(", "$", "this", "->", "db", ",", "$", "this", "->", "entityfactory", ",", "$", "this", "->", "legacymapper", "->", "get_legacy_data_mapper_for_vault", "(", "'forum'", ")", ")", ";", "}" ]
Create a forum vault. @return forum_vault
[ "Create", "a", "forum", "vault", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/vault.php#L80-L86
216,741
moodle/moodle
mod/forum/classes/local/factories/vault.php
vault.get_discussion_vault
public function get_discussion_vault() : discussion_vault { return new discussion_vault( $this->db, $this->entityfactory, $this->legacymapper->get_legacy_data_mapper_for_vault('discussion') ); }
php
public function get_discussion_vault() : discussion_vault { return new discussion_vault( $this->db, $this->entityfactory, $this->legacymapper->get_legacy_data_mapper_for_vault('discussion') ); }
[ "public", "function", "get_discussion_vault", "(", ")", ":", "discussion_vault", "{", "return", "new", "discussion_vault", "(", "$", "this", "->", "db", ",", "$", "this", "->", "entityfactory", ",", "$", "this", "->", "legacymapper", "->", "get_legacy_data_mapper_for_vault", "(", "'discussion'", ")", ")", ";", "}" ]
Create a discussion vault. @return discussion_vault
[ "Create", "a", "discussion", "vault", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/vault.php#L93-L99
216,742
moodle/moodle
mod/forum/classes/local/factories/vault.php
vault.get_discussions_in_forum_vault
public function get_discussions_in_forum_vault() : discussion_list_vault { return new discussion_list_vault( $this->db, $this->entityfactory, $this->legacymapper->get_legacy_data_mapper_for_vault('discussion') ); }
php
public function get_discussions_in_forum_vault() : discussion_list_vault { return new discussion_list_vault( $this->db, $this->entityfactory, $this->legacymapper->get_legacy_data_mapper_for_vault('discussion') ); }
[ "public", "function", "get_discussions_in_forum_vault", "(", ")", ":", "discussion_list_vault", "{", "return", "new", "discussion_list_vault", "(", "$", "this", "->", "db", ",", "$", "this", "->", "entityfactory", ",", "$", "this", "->", "legacymapper", "->", "get_legacy_data_mapper_for_vault", "(", "'discussion'", ")", ")", ";", "}" ]
Create a discussion list vault. @return discussion_list_vault
[ "Create", "a", "discussion", "list", "vault", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/vault.php#L106-L112
216,743
moodle/moodle
mod/forum/classes/local/factories/vault.php
vault.get_post_vault
public function get_post_vault() : post_vault { return new post_vault( $this->db, $this->entityfactory, $this->legacymapper->get_legacy_data_mapper_for_vault('post') ); }
php
public function get_post_vault() : post_vault { return new post_vault( $this->db, $this->entityfactory, $this->legacymapper->get_legacy_data_mapper_for_vault('post') ); }
[ "public", "function", "get_post_vault", "(", ")", ":", "post_vault", "{", "return", "new", "post_vault", "(", "$", "this", "->", "db", ",", "$", "this", "->", "entityfactory", ",", "$", "this", "->", "legacymapper", "->", "get_legacy_data_mapper_for_vault", "(", "'post'", ")", ")", ";", "}" ]
Create a post vault. @return post_vault
[ "Create", "a", "post", "vault", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/vault.php#L119-L125
216,744
moodle/moodle
mod/forum/classes/local/factories/vault.php
vault.get_author_vault
public function get_author_vault() : author_vault { return new author_vault( $this->db, $this->entityfactory, $this->legacymapper->get_legacy_data_mapper_for_vault('author') ); }
php
public function get_author_vault() : author_vault { return new author_vault( $this->db, $this->entityfactory, $this->legacymapper->get_legacy_data_mapper_for_vault('author') ); }
[ "public", "function", "get_author_vault", "(", ")", ":", "author_vault", "{", "return", "new", "author_vault", "(", "$", "this", "->", "db", ",", "$", "this", "->", "entityfactory", ",", "$", "this", "->", "legacymapper", "->", "get_legacy_data_mapper_for_vault", "(", "'author'", ")", ")", ";", "}" ]
Create an author vault. @return author_vault
[ "Create", "an", "author", "vault", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/vault.php#L132-L138
216,745
moodle/moodle
mod/forum/classes/local/factories/vault.php
vault.get_post_read_receipt_collection_vault
public function get_post_read_receipt_collection_vault() : post_read_receipt_collection_vault { return new post_read_receipt_collection_vault( $this->db, $this->entityfactory, $this->legacymapper->get_legacy_data_mapper_for_vault('post') ); }
php
public function get_post_read_receipt_collection_vault() : post_read_receipt_collection_vault { return new post_read_receipt_collection_vault( $this->db, $this->entityfactory, $this->legacymapper->get_legacy_data_mapper_for_vault('post') ); }
[ "public", "function", "get_post_read_receipt_collection_vault", "(", ")", ":", "post_read_receipt_collection_vault", "{", "return", "new", "post_read_receipt_collection_vault", "(", "$", "this", "->", "db", ",", "$", "this", "->", "entityfactory", ",", "$", "this", "->", "legacymapper", "->", "get_legacy_data_mapper_for_vault", "(", "'post'", ")", ")", ";", "}" ]
Create a post read receipt collection vault. @return post_read_receipt_collection_vault
[ "Create", "a", "post", "read", "receipt", "collection", "vault", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/vault.php#L145-L151
216,746
moodle/moodle
mod/assign/feedback/offline/locallib.php
assign_feedback_offline.download_grades
public function download_grades() { global $CFG; require_capability('mod/assign:grade', $this->assignment->get_context()); require_once($CFG->dirroot . '/mod/assign/gradingtable.php'); $groupmode = groups_get_activity_groupmode($this->assignment->get_course_module()); // All users. $groupid = 0; $groupname = ''; if ($groupmode) { $groupid = groups_get_activity_group($this->assignment->get_course_module(), true); $groupname = groups_get_group_name($groupid) . '-'; } $filename = clean_filename(get_string('offlinegradingworksheet', 'assignfeedback_offline') . '-' . $this->assignment->get_course()->shortname . '-' . $this->assignment->get_instance()->name . '-' . $groupname . $this->assignment->get_course_module()->id); $table = new assign_grading_table($this->assignment, 0, '', 0, false, $filename); $table->out(0, false); return; }
php
public function download_grades() { global $CFG; require_capability('mod/assign:grade', $this->assignment->get_context()); require_once($CFG->dirroot . '/mod/assign/gradingtable.php'); $groupmode = groups_get_activity_groupmode($this->assignment->get_course_module()); // All users. $groupid = 0; $groupname = ''; if ($groupmode) { $groupid = groups_get_activity_group($this->assignment->get_course_module(), true); $groupname = groups_get_group_name($groupid) . '-'; } $filename = clean_filename(get_string('offlinegradingworksheet', 'assignfeedback_offline') . '-' . $this->assignment->get_course()->shortname . '-' . $this->assignment->get_instance()->name . '-' . $groupname . $this->assignment->get_course_module()->id); $table = new assign_grading_table($this->assignment, 0, '', 0, false, $filename); $table->out(0, false); return; }
[ "public", "function", "download_grades", "(", ")", "{", "global", "$", "CFG", ";", "require_capability", "(", "'mod/assign:grade'", ",", "$", "this", "->", "assignment", "->", "get_context", "(", ")", ")", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/mod/assign/gradingtable.php'", ")", ";", "$", "groupmode", "=", "groups_get_activity_groupmode", "(", "$", "this", "->", "assignment", "->", "get_course_module", "(", ")", ")", ";", "// All users.", "$", "groupid", "=", "0", ";", "$", "groupname", "=", "''", ";", "if", "(", "$", "groupmode", ")", "{", "$", "groupid", "=", "groups_get_activity_group", "(", "$", "this", "->", "assignment", "->", "get_course_module", "(", ")", ",", "true", ")", ";", "$", "groupname", "=", "groups_get_group_name", "(", "$", "groupid", ")", ".", "'-'", ";", "}", "$", "filename", "=", "clean_filename", "(", "get_string", "(", "'offlinegradingworksheet'", ",", "'assignfeedback_offline'", ")", ".", "'-'", ".", "$", "this", "->", "assignment", "->", "get_course", "(", ")", "->", "shortname", ".", "'-'", ".", "$", "this", "->", "assignment", "->", "get_instance", "(", ")", "->", "name", ".", "'-'", ".", "$", "groupname", ".", "$", "this", "->", "assignment", "->", "get_course_module", "(", ")", "->", "id", ")", ";", "$", "table", "=", "new", "assign_grading_table", "(", "$", "this", "->", "assignment", ",", "0", ",", "''", ",", "0", ",", "false", ",", "$", "filename", ")", ";", "$", "table", "->", "out", "(", "0", ",", "false", ")", ";", "return", ";", "}" ]
Download a marking worksheet @return string The response html
[ "Download", "a", "marking", "worksheet" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/offline/locallib.php#L327-L351
216,747
moodle/moodle
mod/assign/feedback/offline/locallib.php
assign_feedback_offline.is_enabled
public function is_enabled() { if ($this->enabledcache === null) { $gradingmanager = get_grading_manager($this->assignment->get_context(), 'mod_assign', 'submissions'); $controller = $gradingmanager->get_active_controller(); $active = !empty($controller); if ($active) { $this->enabledcache = false; } else { $this->enabledcache = parent::is_enabled(); } } return $this->enabledcache; }
php
public function is_enabled() { if ($this->enabledcache === null) { $gradingmanager = get_grading_manager($this->assignment->get_context(), 'mod_assign', 'submissions'); $controller = $gradingmanager->get_active_controller(); $active = !empty($controller); if ($active) { $this->enabledcache = false; } else { $this->enabledcache = parent::is_enabled(); } } return $this->enabledcache; }
[ "public", "function", "is_enabled", "(", ")", "{", "if", "(", "$", "this", "->", "enabledcache", "===", "null", ")", "{", "$", "gradingmanager", "=", "get_grading_manager", "(", "$", "this", "->", "assignment", "->", "get_context", "(", ")", ",", "'mod_assign'", ",", "'submissions'", ")", ";", "$", "controller", "=", "$", "gradingmanager", "->", "get_active_controller", "(", ")", ";", "$", "active", "=", "!", "empty", "(", "$", "controller", ")", ";", "if", "(", "$", "active", ")", "{", "$", "this", "->", "enabledcache", "=", "false", ";", "}", "else", "{", "$", "this", "->", "enabledcache", "=", "parent", "::", "is_enabled", "(", ")", ";", "}", "}", "return", "$", "this", "->", "enabledcache", ";", "}" ]
Override the default is_enabled to disable this plugin if advanced grading is active @return bool
[ "Override", "the", "default", "is_enabled", "to", "disable", "this", "plugin", "if", "advanced", "grading", "is", "active" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/offline/locallib.php#L385-L398
216,748
moodle/moodle
lib/classes/ip_utils.php
ip_utils.is_domain_name
public static function is_domain_name($domainname) { if (!is_string($domainname)) { return false; } // Usually the trailing dot (null label) is omitted, but is valid if supplied. We'll just remove it and validate as normal. $domainname = rtrim($domainname, '.'); // The entire name cannot exceed 253 ascii characters (255 octets, less the leading label-length byte and null label byte). if (strlen($domainname) > 253) { return false; } // Tertiary domain labels can have 63 octets max, and must not have begin or end with a hyphen. // The TLD label cannot begin with a number, but otherwise, is only loosely restricted here (TLD list is not checked). $domaintertiary = '([a-zA-Z0-9](([a-zA-Z0-9-]{0,61})[a-zA-Z0-9])?\.)*'; $domaintoplevel = '([a-zA-Z](([a-zA-Z0-9-]*)[a-zA-Z0-9])?)'; $address = '(' . $domaintertiary . $domaintoplevel . ')'; $regexp = '#^' . $address . '$#i'; // Case insensitive matching. return preg_match($regexp, $domainname, $match) == true; // False for error, 0 for no match - we treat the same. }
php
public static function is_domain_name($domainname) { if (!is_string($domainname)) { return false; } // Usually the trailing dot (null label) is omitted, but is valid if supplied. We'll just remove it and validate as normal. $domainname = rtrim($domainname, '.'); // The entire name cannot exceed 253 ascii characters (255 octets, less the leading label-length byte and null label byte). if (strlen($domainname) > 253) { return false; } // Tertiary domain labels can have 63 octets max, and must not have begin or end with a hyphen. // The TLD label cannot begin with a number, but otherwise, is only loosely restricted here (TLD list is not checked). $domaintertiary = '([a-zA-Z0-9](([a-zA-Z0-9-]{0,61})[a-zA-Z0-9])?\.)*'; $domaintoplevel = '([a-zA-Z](([a-zA-Z0-9-]*)[a-zA-Z0-9])?)'; $address = '(' . $domaintertiary . $domaintoplevel . ')'; $regexp = '#^' . $address . '$#i'; // Case insensitive matching. return preg_match($regexp, $domainname, $match) == true; // False for error, 0 for no match - we treat the same. }
[ "public", "static", "function", "is_domain_name", "(", "$", "domainname", ")", "{", "if", "(", "!", "is_string", "(", "$", "domainname", ")", ")", "{", "return", "false", ";", "}", "// Usually the trailing dot (null label) is omitted, but is valid if supplied. We'll just remove it and validate as normal.", "$", "domainname", "=", "rtrim", "(", "$", "domainname", ",", "'.'", ")", ";", "// The entire name cannot exceed 253 ascii characters (255 octets, less the leading label-length byte and null label byte).", "if", "(", "strlen", "(", "$", "domainname", ")", ">", "253", ")", "{", "return", "false", ";", "}", "// Tertiary domain labels can have 63 octets max, and must not have begin or end with a hyphen.", "// The TLD label cannot begin with a number, but otherwise, is only loosely restricted here (TLD list is not checked).", "$", "domaintertiary", "=", "'([a-zA-Z0-9](([a-zA-Z0-9-]{0,61})[a-zA-Z0-9])?\\.)*'", ";", "$", "domaintoplevel", "=", "'([a-zA-Z](([a-zA-Z0-9-]*)[a-zA-Z0-9])?)'", ";", "$", "address", "=", "'('", ".", "$", "domaintertiary", ".", "$", "domaintoplevel", ".", "')'", ";", "$", "regexp", "=", "'#^'", ".", "$", "address", ".", "'$#i'", ";", "// Case insensitive matching.", "return", "preg_match", "(", "$", "regexp", ",", "$", "domainname", ",", "$", "match", ")", "==", "true", ";", "// False for error, 0 for no match - we treat the same.", "}" ]
Syntax checking for domain names, including fully qualified domain names. This function does not verify the existence of the domain name. It only verifies syntactic correctness. This is based on RFC1034/1035 and does not provide support for validation of internationalised domain names (IDNs). All IDNs must be prior-converted to their ascii-compatible encoding before being passed to this function. @param string $domainname the input string to check. @return bool true if the string has valid syntax, false otherwise.
[ "Syntax", "checking", "for", "domain", "names", "including", "fully", "qualified", "domain", "names", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/ip_utils.php#L49-L67
216,749
moodle/moodle
lib/classes/ip_utils.php
ip_utils.is_domain_matching_pattern
public static function is_domain_matching_pattern($pattern) { if (!is_string($pattern)) { return false; } // Usually the trailing dot (null label) is omitted, but is valid if supplied. We'll just remove it and validate as normal. $pattern = rtrim($pattern, '.'); // The entire name cannot exceed 253 ascii characters (255 octets, less the leading label-length byte and null label byte). if (strlen($pattern) > 253) { return false; } // A valid pattern must left-positioned wildcard symbol (*). // Tertiary domain labels can have 63 octets max, and must not have begin or end with a hyphen. // The TLD label cannot begin with a number, but otherwise, is only loosely restricted here (TLD list is not checked). $wildcard = '((\*)\.){1}'; $domaintertiary = '([a-zA-Z0-9](([a-zA-Z0-9-]{0,61})[a-zA-Z0-9])?\.)*'; $domaintoplevel = '([a-zA-Z](([a-zA-Z0-9-]*)[a-zA-Z0-9])?)'; $address = '(' . $wildcard . $domaintertiary . $domaintoplevel . ')'; $regexp = '#^' . $address . '$#i'; // Case insensitive matching. return preg_match($regexp, $pattern, $match) == true; // False for error, 0 for no match - we treat the same. }
php
public static function is_domain_matching_pattern($pattern) { if (!is_string($pattern)) { return false; } // Usually the trailing dot (null label) is omitted, but is valid if supplied. We'll just remove it and validate as normal. $pattern = rtrim($pattern, '.'); // The entire name cannot exceed 253 ascii characters (255 octets, less the leading label-length byte and null label byte). if (strlen($pattern) > 253) { return false; } // A valid pattern must left-positioned wildcard symbol (*). // Tertiary domain labels can have 63 octets max, and must not have begin or end with a hyphen. // The TLD label cannot begin with a number, but otherwise, is only loosely restricted here (TLD list is not checked). $wildcard = '((\*)\.){1}'; $domaintertiary = '([a-zA-Z0-9](([a-zA-Z0-9-]{0,61})[a-zA-Z0-9])?\.)*'; $domaintoplevel = '([a-zA-Z](([a-zA-Z0-9-]*)[a-zA-Z0-9])?)'; $address = '(' . $wildcard . $domaintertiary . $domaintoplevel . ')'; $regexp = '#^' . $address . '$#i'; // Case insensitive matching. return preg_match($regexp, $pattern, $match) == true; // False for error, 0 for no match - we treat the same. }
[ "public", "static", "function", "is_domain_matching_pattern", "(", "$", "pattern", ")", "{", "if", "(", "!", "is_string", "(", "$", "pattern", ")", ")", "{", "return", "false", ";", "}", "// Usually the trailing dot (null label) is omitted, but is valid if supplied. We'll just remove it and validate as normal.", "$", "pattern", "=", "rtrim", "(", "$", "pattern", ",", "'.'", ")", ";", "// The entire name cannot exceed 253 ascii characters (255 octets, less the leading label-length byte and null label byte).", "if", "(", "strlen", "(", "$", "pattern", ")", ">", "253", ")", "{", "return", "false", ";", "}", "// A valid pattern must left-positioned wildcard symbol (*).", "// Tertiary domain labels can have 63 octets max, and must not have begin or end with a hyphen.", "// The TLD label cannot begin with a number, but otherwise, is only loosely restricted here (TLD list is not checked).", "$", "wildcard", "=", "'((\\*)\\.){1}'", ";", "$", "domaintertiary", "=", "'([a-zA-Z0-9](([a-zA-Z0-9-]{0,61})[a-zA-Z0-9])?\\.)*'", ";", "$", "domaintoplevel", "=", "'([a-zA-Z](([a-zA-Z0-9-]*)[a-zA-Z0-9])?)'", ";", "$", "address", "=", "'('", ".", "$", "wildcard", ".", "$", "domaintertiary", ".", "$", "domaintoplevel", ".", "')'", ";", "$", "regexp", "=", "'#^'", ".", "$", "address", ".", "'$#i'", ";", "// Case insensitive matching.", "return", "preg_match", "(", "$", "regexp", ",", "$", "pattern", ",", "$", "match", ")", "==", "true", ";", "// False for error, 0 for no match - we treat the same.", "}" ]
Checks whether the input string is a valid wildcard domain matching pattern. A domain matching pattern is essentially a domain name with a single, leading wildcard (*) label, and at least one other label. The wildcard label is considered to match at least one label at or above (to the left of) its position in the string, but will not match the trailing domain (everything to its right). The string must be dot-separated, and the whole pattern must follow the domain name syntax rules defined in RFC1034/1035. Namely, the character type (ascii), total-length (253) and label-length (63) restrictions. This function only confirms syntactic correctness. It does not check for the existence of the domain/subdomains. For example, the string '*.example.com' is a pattern deemed to match any direct subdomain of example.com (such as test.example.com), any higher level subdomains (e.g. another.test.example.com) but will not match the 'example.com' domain itself. @param string $pattern the string to check. @return bool true if the input string is a valid domain wildcard matching pattern, false otherwise.
[ "Checks", "whether", "the", "input", "string", "is", "a", "valid", "wildcard", "domain", "matching", "pattern", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/ip_utils.php#L87-L107
216,750
moodle/moodle
mod/assignment/backup/moodle2/restore_assignment_stepslib.php
restore_assignment_activity_structure_step.upgrade_mod_assign
private function upgrade_mod_assign() { global $DB, $CFG; // The current module must exist. $pluginmanager = core_plugin_manager::instance(); $plugininfo = $pluginmanager->get_plugin_info('mod_assign'); // Check that the assignment module is installed. if ($plugininfo && $plugininfo->is_installed_and_upgraded()) { // Include the required mod assign upgrade code. require_once($CFG->dirroot . '/mod/assign/upgradelib.php'); require_once($CFG->dirroot . '/mod/assign/locallib.php'); // Get the id and type of this assignment. $newinstance = $this->task->get_activityid(); $record = $DB->get_record('assignment', array('id'=>$newinstance), 'assignmenttype', MUST_EXIST); $type = $record->assignmenttype; $subplugininfo = $pluginmanager->get_plugin_info('assignment_' . $type); // See if it is possible to upgrade. if (assign::can_upgrade_assignment($type, $subplugininfo->versiondb)) { $assignment_upgrader = new assign_upgrade_manager(); $log = ''; $success = $assignment_upgrader->upgrade_assignment($newinstance, $log); if (!$success) { throw new restore_step_exception('mod_assign_upgrade_failed', $log); } } } }
php
private function upgrade_mod_assign() { global $DB, $CFG; // The current module must exist. $pluginmanager = core_plugin_manager::instance(); $plugininfo = $pluginmanager->get_plugin_info('mod_assign'); // Check that the assignment module is installed. if ($plugininfo && $plugininfo->is_installed_and_upgraded()) { // Include the required mod assign upgrade code. require_once($CFG->dirroot . '/mod/assign/upgradelib.php'); require_once($CFG->dirroot . '/mod/assign/locallib.php'); // Get the id and type of this assignment. $newinstance = $this->task->get_activityid(); $record = $DB->get_record('assignment', array('id'=>$newinstance), 'assignmenttype', MUST_EXIST); $type = $record->assignmenttype; $subplugininfo = $pluginmanager->get_plugin_info('assignment_' . $type); // See if it is possible to upgrade. if (assign::can_upgrade_assignment($type, $subplugininfo->versiondb)) { $assignment_upgrader = new assign_upgrade_manager(); $log = ''; $success = $assignment_upgrader->upgrade_assignment($newinstance, $log); if (!$success) { throw new restore_step_exception('mod_assign_upgrade_failed', $log); } } } }
[ "private", "function", "upgrade_mod_assign", "(", ")", "{", "global", "$", "DB", ",", "$", "CFG", ";", "// The current module must exist.", "$", "pluginmanager", "=", "core_plugin_manager", "::", "instance", "(", ")", ";", "$", "plugininfo", "=", "$", "pluginmanager", "->", "get_plugin_info", "(", "'mod_assign'", ")", ";", "// Check that the assignment module is installed.", "if", "(", "$", "plugininfo", "&&", "$", "plugininfo", "->", "is_installed_and_upgraded", "(", ")", ")", "{", "// Include the required mod assign upgrade code.", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/mod/assign/upgradelib.php'", ")", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/mod/assign/locallib.php'", ")", ";", "// Get the id and type of this assignment.", "$", "newinstance", "=", "$", "this", "->", "task", "->", "get_activityid", "(", ")", ";", "$", "record", "=", "$", "DB", "->", "get_record", "(", "'assignment'", ",", "array", "(", "'id'", "=>", "$", "newinstance", ")", ",", "'assignmenttype'", ",", "MUST_EXIST", ")", ";", "$", "type", "=", "$", "record", "->", "assignmenttype", ";", "$", "subplugininfo", "=", "$", "pluginmanager", "->", "get_plugin_info", "(", "'assignment_'", ".", "$", "type", ")", ";", "// See if it is possible to upgrade.", "if", "(", "assign", "::", "can_upgrade_assignment", "(", "$", "type", ",", "$", "subplugininfo", "->", "versiondb", ")", ")", "{", "$", "assignment_upgrader", "=", "new", "assign_upgrade_manager", "(", ")", ";", "$", "log", "=", "''", ";", "$", "success", "=", "$", "assignment_upgrader", "->", "upgrade_assignment", "(", "$", "newinstance", ",", "$", "log", ")", ";", "if", "(", "!", "$", "success", ")", "{", "throw", "new", "restore_step_exception", "(", "'mod_assign_upgrade_failed'", ",", "$", "log", ")", ";", "}", "}", "}", "}" ]
This function will attempt to upgrade the newly restored assignment to an instance of mod_assign if mod_assignment is currently disabled and mod_assign is enabled and mod_assign says it can upgrade this assignment. @return none
[ "This", "function", "will", "attempt", "to", "upgrade", "the", "newly", "restored", "assignment", "to", "an", "instance", "of", "mod_assign", "if", "mod_assignment", "is", "currently", "disabled", "and", "mod_assign", "is", "enabled", "and", "mod_assign", "says", "it", "can", "upgrade", "this", "assignment", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assignment/backup/moodle2/restore_assignment_stepslib.php#L107-L139
216,751
moodle/moodle
mod/assignment/backup/moodle2/restore_assignment_stepslib.php
restore_assignment_activity_structure_step.is_valid_assignment_subplugin
protected function is_valid_assignment_subplugin($type) { static $subplugins = null; if (is_null($subplugins)) { $subplugins = get_plugin_list('assignment'); } return array_key_exists($type, $subplugins); }
php
protected function is_valid_assignment_subplugin($type) { static $subplugins = null; if (is_null($subplugins)) { $subplugins = get_plugin_list('assignment'); } return array_key_exists($type, $subplugins); }
[ "protected", "function", "is_valid_assignment_subplugin", "(", "$", "type", ")", "{", "static", "$", "subplugins", "=", "null", ";", "if", "(", "is_null", "(", "$", "subplugins", ")", ")", "{", "$", "subplugins", "=", "get_plugin_list", "(", "'assignment'", ")", ";", "}", "return", "array_key_exists", "(", "$", "type", ",", "$", "subplugins", ")", ";", "}" ]
Determine if a sub-plugin is supported or not @param string $type @return bool
[ "Determine", "if", "a", "sub", "-", "plugin", "is", "supported", "or", "not" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assignment/backup/moodle2/restore_assignment_stepslib.php#L166-L173
216,752
moodle/moodle
analytics/classes/model_config.php
model_config.export
public function export(string $zipfilename, bool $includeweights = true) : string { if (!$this->model) { throw new \coding_exception('No model object provided.'); } if (!$this->model->can_export_configuration()) { throw new \moodle_exception('errornoexportconfigrequirements', 'analytics'); } $zip = new \zip_packer(); $zipfiles = []; // Model config in JSON. $modeldata = $this->export_model_data(); $exporttmpdir = make_request_directory('analyticsexport'); $jsonfilepath = $exporttmpdir . DIRECTORY_SEPARATOR . 'model-config.json'; if (!file_put_contents($jsonfilepath, json_encode($modeldata))) { print_error('errornoexportconfig', 'analytics'); } $zipfiles[self::CONFIG_FILE_NAME] = $jsonfilepath; // ML backend. if ($includeweights && $this->model->is_trained()) { $processor = $this->model->get_predictions_processor(true); $outputdir = $this->model->get_output_dir(array('execution')); $mlbackenddir = $processor->export($this->model->get_unique_id(), $outputdir); $mlbackendfiles = get_directory_list($mlbackenddir); foreach ($mlbackendfiles as $mlbackendfile) { $fullpath = $mlbackenddir . DIRECTORY_SEPARATOR . $mlbackendfile; // Place the ML backend files inside a mlbackend/ dir. $zipfiles['mlbackend/' . $mlbackendfile] = $fullpath; } } $zipfilepath = $exporttmpdir . DIRECTORY_SEPARATOR . $zipfilename; $zip->archive_to_pathname($zipfiles, $zipfilepath); return $zipfilepath; }
php
public function export(string $zipfilename, bool $includeweights = true) : string { if (!$this->model) { throw new \coding_exception('No model object provided.'); } if (!$this->model->can_export_configuration()) { throw new \moodle_exception('errornoexportconfigrequirements', 'analytics'); } $zip = new \zip_packer(); $zipfiles = []; // Model config in JSON. $modeldata = $this->export_model_data(); $exporttmpdir = make_request_directory('analyticsexport'); $jsonfilepath = $exporttmpdir . DIRECTORY_SEPARATOR . 'model-config.json'; if (!file_put_contents($jsonfilepath, json_encode($modeldata))) { print_error('errornoexportconfig', 'analytics'); } $zipfiles[self::CONFIG_FILE_NAME] = $jsonfilepath; // ML backend. if ($includeweights && $this->model->is_trained()) { $processor = $this->model->get_predictions_processor(true); $outputdir = $this->model->get_output_dir(array('execution')); $mlbackenddir = $processor->export($this->model->get_unique_id(), $outputdir); $mlbackendfiles = get_directory_list($mlbackenddir); foreach ($mlbackendfiles as $mlbackendfile) { $fullpath = $mlbackenddir . DIRECTORY_SEPARATOR . $mlbackendfile; // Place the ML backend files inside a mlbackend/ dir. $zipfiles['mlbackend/' . $mlbackendfile] = $fullpath; } } $zipfilepath = $exporttmpdir . DIRECTORY_SEPARATOR . $zipfilename; $zip->archive_to_pathname($zipfiles, $zipfilepath); return $zipfilepath; }
[ "public", "function", "export", "(", "string", "$", "zipfilename", ",", "bool", "$", "includeweights", "=", "true", ")", ":", "string", "{", "if", "(", "!", "$", "this", "->", "model", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'No model object provided.'", ")", ";", "}", "if", "(", "!", "$", "this", "->", "model", "->", "can_export_configuration", "(", ")", ")", "{", "throw", "new", "\\", "moodle_exception", "(", "'errornoexportconfigrequirements'", ",", "'analytics'", ")", ";", "}", "$", "zip", "=", "new", "\\", "zip_packer", "(", ")", ";", "$", "zipfiles", "=", "[", "]", ";", "// Model config in JSON.", "$", "modeldata", "=", "$", "this", "->", "export_model_data", "(", ")", ";", "$", "exporttmpdir", "=", "make_request_directory", "(", "'analyticsexport'", ")", ";", "$", "jsonfilepath", "=", "$", "exporttmpdir", ".", "DIRECTORY_SEPARATOR", ".", "'model-config.json'", ";", "if", "(", "!", "file_put_contents", "(", "$", "jsonfilepath", ",", "json_encode", "(", "$", "modeldata", ")", ")", ")", "{", "print_error", "(", "'errornoexportconfig'", ",", "'analytics'", ")", ";", "}", "$", "zipfiles", "[", "self", "::", "CONFIG_FILE_NAME", "]", "=", "$", "jsonfilepath", ";", "// ML backend.", "if", "(", "$", "includeweights", "&&", "$", "this", "->", "model", "->", "is_trained", "(", ")", ")", "{", "$", "processor", "=", "$", "this", "->", "model", "->", "get_predictions_processor", "(", "true", ")", ";", "$", "outputdir", "=", "$", "this", "->", "model", "->", "get_output_dir", "(", "array", "(", "'execution'", ")", ")", ";", "$", "mlbackenddir", "=", "$", "processor", "->", "export", "(", "$", "this", "->", "model", "->", "get_unique_id", "(", ")", ",", "$", "outputdir", ")", ";", "$", "mlbackendfiles", "=", "get_directory_list", "(", "$", "mlbackenddir", ")", ";", "foreach", "(", "$", "mlbackendfiles", "as", "$", "mlbackendfile", ")", "{", "$", "fullpath", "=", "$", "mlbackenddir", ".", "DIRECTORY_SEPARATOR", ".", "$", "mlbackendfile", ";", "// Place the ML backend files inside a mlbackend/ dir.", "$", "zipfiles", "[", "'mlbackend/'", ".", "$", "mlbackendfile", "]", "=", "$", "fullpath", ";", "}", "}", "$", "zipfilepath", "=", "$", "exporttmpdir", ".", "DIRECTORY_SEPARATOR", ".", "$", "zipfilename", ";", "$", "zip", "->", "archive_to_pathname", "(", "$", "zipfiles", ",", "$", "zipfilepath", ")", ";", "return", "$", "zipfilepath", ";", "}" ]
Exports a model to a zip using the provided file name. @param string $zipfilename @param bool $includeweights Include the model weights if available @return string
[ "Exports", "a", "model", "to", "a", "zip", "using", "the", "provided", "file", "name", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model_config.php#L64-L104
216,753
moodle/moodle
analytics/classes/model_config.php
model_config.import
public function import(string $zipfilepath) : \core_analytics\model { list($modeldata, $mlbackenddir) = $this->extract_import_contents($zipfilepath); $target = \core_analytics\manager::get_target($modeldata->target); $indicators = []; foreach ($modeldata->indicators as $indicatorclass) { $indicator = \core_analytics\manager::get_indicator($indicatorclass); $indicators[$indicator->get_id()] = $indicator; } $model = \core_analytics\model::create($target, $indicators, $modeldata->timesplitting, $modeldata->processor); // Import them disabled. $model->update(false, false, false, false); if ($mlbackenddir) { $modeldir = $model->get_output_dir(['execution']); if (!$model->get_predictions_processor(true)->import($model->get_unique_id(), $modeldir, $mlbackenddir)) { throw new \moodle_exception('errorimport', 'analytics'); } $model->mark_as_trained(); } return $model; }
php
public function import(string $zipfilepath) : \core_analytics\model { list($modeldata, $mlbackenddir) = $this->extract_import_contents($zipfilepath); $target = \core_analytics\manager::get_target($modeldata->target); $indicators = []; foreach ($modeldata->indicators as $indicatorclass) { $indicator = \core_analytics\manager::get_indicator($indicatorclass); $indicators[$indicator->get_id()] = $indicator; } $model = \core_analytics\model::create($target, $indicators, $modeldata->timesplitting, $modeldata->processor); // Import them disabled. $model->update(false, false, false, false); if ($mlbackenddir) { $modeldir = $model->get_output_dir(['execution']); if (!$model->get_predictions_processor(true)->import($model->get_unique_id(), $modeldir, $mlbackenddir)) { throw new \moodle_exception('errorimport', 'analytics'); } $model->mark_as_trained(); } return $model; }
[ "public", "function", "import", "(", "string", "$", "zipfilepath", ")", ":", "\\", "core_analytics", "\\", "model", "{", "list", "(", "$", "modeldata", ",", "$", "mlbackenddir", ")", "=", "$", "this", "->", "extract_import_contents", "(", "$", "zipfilepath", ")", ";", "$", "target", "=", "\\", "core_analytics", "\\", "manager", "::", "get_target", "(", "$", "modeldata", "->", "target", ")", ";", "$", "indicators", "=", "[", "]", ";", "foreach", "(", "$", "modeldata", "->", "indicators", "as", "$", "indicatorclass", ")", "{", "$", "indicator", "=", "\\", "core_analytics", "\\", "manager", "::", "get_indicator", "(", "$", "indicatorclass", ")", ";", "$", "indicators", "[", "$", "indicator", "->", "get_id", "(", ")", "]", "=", "$", "indicator", ";", "}", "$", "model", "=", "\\", "core_analytics", "\\", "model", "::", "create", "(", "$", "target", ",", "$", "indicators", ",", "$", "modeldata", "->", "timesplitting", ",", "$", "modeldata", "->", "processor", ")", ";", "// Import them disabled.", "$", "model", "->", "update", "(", "false", ",", "false", ",", "false", ",", "false", ")", ";", "if", "(", "$", "mlbackenddir", ")", "{", "$", "modeldir", "=", "$", "model", "->", "get_output_dir", "(", "[", "'execution'", "]", ")", ";", "if", "(", "!", "$", "model", "->", "get_predictions_processor", "(", "true", ")", "->", "import", "(", "$", "model", "->", "get_unique_id", "(", ")", ",", "$", "modeldir", ",", "$", "mlbackenddir", ")", ")", "{", "throw", "new", "\\", "moodle_exception", "(", "'errorimport'", ",", "'analytics'", ")", ";", "}", "$", "model", "->", "mark_as_trained", "(", ")", ";", "}", "return", "$", "model", ";", "}" ]
Imports the provided model configuration into a new model. Note that this method assumes that self::check_dependencies has already been called. @param string $zipfilepath Path to the zip file to import @return \core_analytics\model
[ "Imports", "the", "provided", "model", "configuration", "into", "a", "new", "model", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model_config.php#L114-L138
216,754
moodle/moodle
analytics/classes/model_config.php
model_config.check_dependencies
public function check_dependencies(\stdClass $modeldata, bool $ignoreversionmismatches) : ?string { $siteversions = \core_component::get_all_versions(); // Possible issues. $missingcomponents = []; $versionmismatches = []; $missingclasses = []; // We first check that this site has the required dependencies and the required versions. foreach ($modeldata->dependencies as $component => $importversion) { if (empty($siteversions[$component])) { if ($component === 'core') { $component = 'Moodle'; } $missingcomponents[$component] = $component . ' (' . $importversion . ')'; continue; } if ($siteversions[$component] == $importversion) { // All good here. continue; } if (!$ignoreversionmismatches) { if ($component === 'core') { $component = 'Moodle'; } $versionmismatches[$component] = $component . ' (' . $importversion . ')'; } } // Checking that each of the components is available. if (!$target = manager::get_target($modeldata->target)) { $missingclasses[] = $modeldata->target; } if (!$timesplitting = manager::get_time_splitting($modeldata->timesplitting)) { $missingclasses[] = $modeldata->timesplitting; } // Indicators. foreach ($modeldata->indicators as $indicatorclass) { if (!$indicator = manager::get_indicator($indicatorclass)) { $missingclasses[] = $indicatorclass; } } // ML backend. if (!empty($modeldata->processor)) { if (!$processor = \core_analytics\manager::get_predictions_processor($modeldata->processor, false)) { $missingclasses[] = $indicatorclass; } } if (!empty($missingcomponents)) { return get_string('errorimportmissingcomponents', 'analytics', join(', ', $missingcomponents)); } if (!empty($versionmismatches)) { return get_string('errorimportversionmismatches', 'analytics', implode(', ', $versionmismatches)); } if (!empty($missingclasses)) { $a = (object)[ 'missingclasses' => implode(', ', $missingclasses), ]; return get_string('errorimportmissingclasses', 'analytics', $a); } // No issues found. return null; }
php
public function check_dependencies(\stdClass $modeldata, bool $ignoreversionmismatches) : ?string { $siteversions = \core_component::get_all_versions(); // Possible issues. $missingcomponents = []; $versionmismatches = []; $missingclasses = []; // We first check that this site has the required dependencies and the required versions. foreach ($modeldata->dependencies as $component => $importversion) { if (empty($siteversions[$component])) { if ($component === 'core') { $component = 'Moodle'; } $missingcomponents[$component] = $component . ' (' . $importversion . ')'; continue; } if ($siteversions[$component] == $importversion) { // All good here. continue; } if (!$ignoreversionmismatches) { if ($component === 'core') { $component = 'Moodle'; } $versionmismatches[$component] = $component . ' (' . $importversion . ')'; } } // Checking that each of the components is available. if (!$target = manager::get_target($modeldata->target)) { $missingclasses[] = $modeldata->target; } if (!$timesplitting = manager::get_time_splitting($modeldata->timesplitting)) { $missingclasses[] = $modeldata->timesplitting; } // Indicators. foreach ($modeldata->indicators as $indicatorclass) { if (!$indicator = manager::get_indicator($indicatorclass)) { $missingclasses[] = $indicatorclass; } } // ML backend. if (!empty($modeldata->processor)) { if (!$processor = \core_analytics\manager::get_predictions_processor($modeldata->processor, false)) { $missingclasses[] = $indicatorclass; } } if (!empty($missingcomponents)) { return get_string('errorimportmissingcomponents', 'analytics', join(', ', $missingcomponents)); } if (!empty($versionmismatches)) { return get_string('errorimportversionmismatches', 'analytics', implode(', ', $versionmismatches)); } if (!empty($missingclasses)) { $a = (object)[ 'missingclasses' => implode(', ', $missingclasses), ]; return get_string('errorimportmissingclasses', 'analytics', $a); } // No issues found. return null; }
[ "public", "function", "check_dependencies", "(", "\\", "stdClass", "$", "modeldata", ",", "bool", "$", "ignoreversionmismatches", ")", ":", "?", "string", "{", "$", "siteversions", "=", "\\", "core_component", "::", "get_all_versions", "(", ")", ";", "// Possible issues.", "$", "missingcomponents", "=", "[", "]", ";", "$", "versionmismatches", "=", "[", "]", ";", "$", "missingclasses", "=", "[", "]", ";", "// We first check that this site has the required dependencies and the required versions.", "foreach", "(", "$", "modeldata", "->", "dependencies", "as", "$", "component", "=>", "$", "importversion", ")", "{", "if", "(", "empty", "(", "$", "siteversions", "[", "$", "component", "]", ")", ")", "{", "if", "(", "$", "component", "===", "'core'", ")", "{", "$", "component", "=", "'Moodle'", ";", "}", "$", "missingcomponents", "[", "$", "component", "]", "=", "$", "component", ".", "' ('", ".", "$", "importversion", ".", "')'", ";", "continue", ";", "}", "if", "(", "$", "siteversions", "[", "$", "component", "]", "==", "$", "importversion", ")", "{", "// All good here.", "continue", ";", "}", "if", "(", "!", "$", "ignoreversionmismatches", ")", "{", "if", "(", "$", "component", "===", "'core'", ")", "{", "$", "component", "=", "'Moodle'", ";", "}", "$", "versionmismatches", "[", "$", "component", "]", "=", "$", "component", ".", "' ('", ".", "$", "importversion", ".", "')'", ";", "}", "}", "// Checking that each of the components is available.", "if", "(", "!", "$", "target", "=", "manager", "::", "get_target", "(", "$", "modeldata", "->", "target", ")", ")", "{", "$", "missingclasses", "[", "]", "=", "$", "modeldata", "->", "target", ";", "}", "if", "(", "!", "$", "timesplitting", "=", "manager", "::", "get_time_splitting", "(", "$", "modeldata", "->", "timesplitting", ")", ")", "{", "$", "missingclasses", "[", "]", "=", "$", "modeldata", "->", "timesplitting", ";", "}", "// Indicators.", "foreach", "(", "$", "modeldata", "->", "indicators", "as", "$", "indicatorclass", ")", "{", "if", "(", "!", "$", "indicator", "=", "manager", "::", "get_indicator", "(", "$", "indicatorclass", ")", ")", "{", "$", "missingclasses", "[", "]", "=", "$", "indicatorclass", ";", "}", "}", "// ML backend.", "if", "(", "!", "empty", "(", "$", "modeldata", "->", "processor", ")", ")", "{", "if", "(", "!", "$", "processor", "=", "\\", "core_analytics", "\\", "manager", "::", "get_predictions_processor", "(", "$", "modeldata", "->", "processor", ",", "false", ")", ")", "{", "$", "missingclasses", "[", "]", "=", "$", "indicatorclass", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "missingcomponents", ")", ")", "{", "return", "get_string", "(", "'errorimportmissingcomponents'", ",", "'analytics'", ",", "join", "(", "', '", ",", "$", "missingcomponents", ")", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "versionmismatches", ")", ")", "{", "return", "get_string", "(", "'errorimportversionmismatches'", ",", "'analytics'", ",", "implode", "(", "', '", ",", "$", "versionmismatches", ")", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "missingclasses", ")", ")", "{", "$", "a", "=", "(", "object", ")", "[", "'missingclasses'", "=>", "implode", "(", "', '", ",", "$", "missingclasses", ")", ",", "]", ";", "return", "get_string", "(", "'errorimportmissingclasses'", ",", "'analytics'", ",", "$", "a", ")", ";", "}", "// No issues found.", "return", "null", ";", "}" ]
Check that the provided model configuration can be deployed in this site. @param \stdClass $modeldata @param bool $ignoreversionmismatches @return string|null Error string or null if all good.
[ "Check", "that", "the", "provided", "model", "configuration", "can", "be", "deployed", "in", "this", "site", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model_config.php#L147-L221
216,755
moodle/moodle
analytics/classes/model_config.php
model_config.get_class_component
public static function get_class_component(string $fullclassname) : ?string { // Strip out leading backslash. $fullclassname = ltrim($fullclassname, '\\'); $nextbackslash = strpos($fullclassname, '\\'); if ($nextbackslash === false) { // Global space. return 'core'; } $component = substr($fullclassname, 0, $nextbackslash); // All core subsystems use core's version.php. if (strpos($component, 'core_') === 0) { $component = 'core'; } return $component; }
php
public static function get_class_component(string $fullclassname) : ?string { // Strip out leading backslash. $fullclassname = ltrim($fullclassname, '\\'); $nextbackslash = strpos($fullclassname, '\\'); if ($nextbackslash === false) { // Global space. return 'core'; } $component = substr($fullclassname, 0, $nextbackslash); // All core subsystems use core's version.php. if (strpos($component, 'core_') === 0) { $component = 'core'; } return $component; }
[ "public", "static", "function", "get_class_component", "(", "string", "$", "fullclassname", ")", ":", "?", "string", "{", "// Strip out leading backslash.", "$", "fullclassname", "=", "ltrim", "(", "$", "fullclassname", ",", "'\\\\'", ")", ";", "$", "nextbackslash", "=", "strpos", "(", "$", "fullclassname", ",", "'\\\\'", ")", ";", "if", "(", "$", "nextbackslash", "===", "false", ")", "{", "// Global space.", "return", "'core'", ";", "}", "$", "component", "=", "substr", "(", "$", "fullclassname", ",", "0", ",", "$", "nextbackslash", ")", ";", "// All core subsystems use core's version.php.", "if", "(", "strpos", "(", "$", "component", ",", "'core_'", ")", "===", "0", ")", "{", "$", "component", "=", "'core'", ";", "}", "return", "$", "component", ";", "}" ]
Returns the component the class belongs to. Note that this method does not work for global space classes. @param string $fullclassname Qualified name including the namespace. @return string|null Frankenstyle component
[ "Returns", "the", "component", "the", "class", "belongs", "to", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model_config.php#L231-L249
216,756
moodle/moodle
analytics/classes/model_config.php
model_config.extract_import_contents
public function extract_import_contents(string $zipfilepath) : array { $importtempdir = make_request_directory('analyticsimport' . microtime(false)); $zip = new \zip_packer(); $filelist = $zip->extract_to_pathname($zipfilepath, $importtempdir); if (empty($filelist[self::CONFIG_FILE_NAME])) { // Missing required file. throw new \moodle_exception('errorimport', 'analytics'); } $jsonmodeldata = file_get_contents($importtempdir . DIRECTORY_SEPARATOR . self::CONFIG_FILE_NAME); if (!$modeldata = json_decode($jsonmodeldata)) { throw new \moodle_exception('errorimport', 'analytics'); } if (empty($modeldata->target) || empty($modeldata->timesplitting) || empty($modeldata->indicators)) { throw new \moodle_exception('errorimport', 'analytics'); } $mlbackenddir = $importtempdir . DIRECTORY_SEPARATOR . 'mlbackend'; if (!is_dir($mlbackenddir)) { $mlbackenddir = false; } return [$modeldata, $mlbackenddir]; }
php
public function extract_import_contents(string $zipfilepath) : array { $importtempdir = make_request_directory('analyticsimport' . microtime(false)); $zip = new \zip_packer(); $filelist = $zip->extract_to_pathname($zipfilepath, $importtempdir); if (empty($filelist[self::CONFIG_FILE_NAME])) { // Missing required file. throw new \moodle_exception('errorimport', 'analytics'); } $jsonmodeldata = file_get_contents($importtempdir . DIRECTORY_SEPARATOR . self::CONFIG_FILE_NAME); if (!$modeldata = json_decode($jsonmodeldata)) { throw new \moodle_exception('errorimport', 'analytics'); } if (empty($modeldata->target) || empty($modeldata->timesplitting) || empty($modeldata->indicators)) { throw new \moodle_exception('errorimport', 'analytics'); } $mlbackenddir = $importtempdir . DIRECTORY_SEPARATOR . 'mlbackend'; if (!is_dir($mlbackenddir)) { $mlbackenddir = false; } return [$modeldata, $mlbackenddir]; }
[ "public", "function", "extract_import_contents", "(", "string", "$", "zipfilepath", ")", ":", "array", "{", "$", "importtempdir", "=", "make_request_directory", "(", "'analyticsimport'", ".", "microtime", "(", "false", ")", ")", ";", "$", "zip", "=", "new", "\\", "zip_packer", "(", ")", ";", "$", "filelist", "=", "$", "zip", "->", "extract_to_pathname", "(", "$", "zipfilepath", ",", "$", "importtempdir", ")", ";", "if", "(", "empty", "(", "$", "filelist", "[", "self", "::", "CONFIG_FILE_NAME", "]", ")", ")", "{", "// Missing required file.", "throw", "new", "\\", "moodle_exception", "(", "'errorimport'", ",", "'analytics'", ")", ";", "}", "$", "jsonmodeldata", "=", "file_get_contents", "(", "$", "importtempdir", ".", "DIRECTORY_SEPARATOR", ".", "self", "::", "CONFIG_FILE_NAME", ")", ";", "if", "(", "!", "$", "modeldata", "=", "json_decode", "(", "$", "jsonmodeldata", ")", ")", "{", "throw", "new", "\\", "moodle_exception", "(", "'errorimport'", ",", "'analytics'", ")", ";", "}", "if", "(", "empty", "(", "$", "modeldata", "->", "target", ")", "||", "empty", "(", "$", "modeldata", "->", "timesplitting", ")", "||", "empty", "(", "$", "modeldata", "->", "indicators", ")", ")", "{", "throw", "new", "\\", "moodle_exception", "(", "'errorimport'", ",", "'analytics'", ")", ";", "}", "$", "mlbackenddir", "=", "$", "importtempdir", ".", "DIRECTORY_SEPARATOR", ".", "'mlbackend'", ";", "if", "(", "!", "is_dir", "(", "$", "mlbackenddir", ")", ")", "{", "$", "mlbackenddir", "=", "false", ";", "}", "return", "[", "$", "modeldata", ",", "$", "mlbackenddir", "]", ";", "}" ]
Extracts the import zip contents. @param string $zipfilepath Zip file path @return array [0] => \stdClass, [1] => string
[ "Extracts", "the", "import", "zip", "contents", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model_config.php#L257-L285
216,757
moodle/moodle
analytics/classes/model_config.php
model_config.export_model_data
protected function export_model_data() : \stdClass { $versions = \core_component::get_all_versions(); $data = new \stdClass(); // Target. $data->target = $this->model->get_target()->get_id(); $requiredclasses[] = $data->target; // Time splitting method. $data->timesplitting = $this->model->get_time_splitting()->get_id(); $requiredclasses[] = $data->timesplitting; // Model indicators. $data->indicators = []; foreach ($this->model->get_indicators() as $indicator) { $indicatorid = $indicator->get_id(); $data->indicators[] = $indicatorid; $requiredclasses[] = $indicatorid; } // Return the predictions processor this model is using, even if no predictions processor // was explicitly selected. $predictionsprocessor = $this->model->get_predictions_processor(); $data->processor = '\\' . get_class($predictionsprocessor); $requiredclasses[] = $data->processor; // Add information for versioning. $data->dependencies = []; foreach ($requiredclasses as $fullclassname) { $component = $this->get_class_component($fullclassname); $data->dependencies[$component] = $versions[$component]; } return $data; }
php
protected function export_model_data() : \stdClass { $versions = \core_component::get_all_versions(); $data = new \stdClass(); // Target. $data->target = $this->model->get_target()->get_id(); $requiredclasses[] = $data->target; // Time splitting method. $data->timesplitting = $this->model->get_time_splitting()->get_id(); $requiredclasses[] = $data->timesplitting; // Model indicators. $data->indicators = []; foreach ($this->model->get_indicators() as $indicator) { $indicatorid = $indicator->get_id(); $data->indicators[] = $indicatorid; $requiredclasses[] = $indicatorid; } // Return the predictions processor this model is using, even if no predictions processor // was explicitly selected. $predictionsprocessor = $this->model->get_predictions_processor(); $data->processor = '\\' . get_class($predictionsprocessor); $requiredclasses[] = $data->processor; // Add information for versioning. $data->dependencies = []; foreach ($requiredclasses as $fullclassname) { $component = $this->get_class_component($fullclassname); $data->dependencies[$component] = $versions[$component]; } return $data; }
[ "protected", "function", "export_model_data", "(", ")", ":", "\\", "stdClass", "{", "$", "versions", "=", "\\", "core_component", "::", "get_all_versions", "(", ")", ";", "$", "data", "=", "new", "\\", "stdClass", "(", ")", ";", "// Target.", "$", "data", "->", "target", "=", "$", "this", "->", "model", "->", "get_target", "(", ")", "->", "get_id", "(", ")", ";", "$", "requiredclasses", "[", "]", "=", "$", "data", "->", "target", ";", "// Time splitting method.", "$", "data", "->", "timesplitting", "=", "$", "this", "->", "model", "->", "get_time_splitting", "(", ")", "->", "get_id", "(", ")", ";", "$", "requiredclasses", "[", "]", "=", "$", "data", "->", "timesplitting", ";", "// Model indicators.", "$", "data", "->", "indicators", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "model", "->", "get_indicators", "(", ")", "as", "$", "indicator", ")", "{", "$", "indicatorid", "=", "$", "indicator", "->", "get_id", "(", ")", ";", "$", "data", "->", "indicators", "[", "]", "=", "$", "indicatorid", ";", "$", "requiredclasses", "[", "]", "=", "$", "indicatorid", ";", "}", "// Return the predictions processor this model is using, even if no predictions processor", "// was explicitly selected.", "$", "predictionsprocessor", "=", "$", "this", "->", "model", "->", "get_predictions_processor", "(", ")", ";", "$", "data", "->", "processor", "=", "'\\\\'", ".", "get_class", "(", "$", "predictionsprocessor", ")", ";", "$", "requiredclasses", "[", "]", "=", "$", "data", "->", "processor", ";", "// Add information for versioning.", "$", "data", "->", "dependencies", "=", "[", "]", ";", "foreach", "(", "$", "requiredclasses", "as", "$", "fullclassname", ")", "{", "$", "component", "=", "$", "this", "->", "get_class_component", "(", "$", "fullclassname", ")", ";", "$", "data", "->", "dependencies", "[", "$", "component", "]", "=", "$", "versions", "[", "$", "component", "]", ";", "}", "return", "$", "data", ";", "}" ]
Exports the configuration of the model. @return \stdClass
[ "Exports", "the", "configuration", "of", "the", "model", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model_config.php#L290-L326
216,758
moodle/moodle
availability/renderer.php
core_availability_renderer.render_core_availability_multiple_messages
public function render_core_availability_multiple_messages( core_availability_multiple_messages $renderable) { // Get initial message. $out = get_string('list_' . ($renderable->root ? 'root_' : '') . ($renderable->andoperator ? 'and' : 'or') . ($renderable->treehidden ? '_hidden' : ''), 'availability'); // Make the list. $out .= html_writer::start_tag('ul'); foreach ($renderable->items as $item) { if (is_string($item)) { $str = $item; } else { $str = $this->render($item); } $out .= html_writer::tag('li', $str); } $out .= html_writer::end_tag('ul'); return $out; }
php
public function render_core_availability_multiple_messages( core_availability_multiple_messages $renderable) { // Get initial message. $out = get_string('list_' . ($renderable->root ? 'root_' : '') . ($renderable->andoperator ? 'and' : 'or') . ($renderable->treehidden ? '_hidden' : ''), 'availability'); // Make the list. $out .= html_writer::start_tag('ul'); foreach ($renderable->items as $item) { if (is_string($item)) { $str = $item; } else { $str = $this->render($item); } $out .= html_writer::tag('li', $str); } $out .= html_writer::end_tag('ul'); return $out; }
[ "public", "function", "render_core_availability_multiple_messages", "(", "core_availability_multiple_messages", "$", "renderable", ")", "{", "// Get initial message.", "$", "out", "=", "get_string", "(", "'list_'", ".", "(", "$", "renderable", "->", "root", "?", "'root_'", ":", "''", ")", ".", "(", "$", "renderable", "->", "andoperator", "?", "'and'", ":", "'or'", ")", ".", "(", "$", "renderable", "->", "treehidden", "?", "'_hidden'", ":", "''", ")", ",", "'availability'", ")", ";", "// Make the list.", "$", "out", ".=", "html_writer", "::", "start_tag", "(", "'ul'", ")", ";", "foreach", "(", "$", "renderable", "->", "items", "as", "$", "item", ")", "{", "if", "(", "is_string", "(", "$", "item", ")", ")", "{", "$", "str", "=", "$", "item", ";", "}", "else", "{", "$", "str", "=", "$", "this", "->", "render", "(", "$", "item", ")", ";", "}", "$", "out", ".=", "html_writer", "::", "tag", "(", "'li'", ",", "$", "str", ")", ";", "}", "$", "out", ".=", "html_writer", "::", "end_tag", "(", "'ul'", ")", ";", "return", "$", "out", ";", "}" ]
Renders HTML for the result of two or more availability restriction messages being combined in a list. The supplied messages should already take account of the 'not' option, e.g. an example message could be 'User profile field Department must not be set to Maths'. This function will not be called unless there are at least two messages. @param core_availability_multiple_messages $renderable Multiple messages @return string Combined HTML
[ "Renders", "HTML", "for", "the", "result", "of", "two", "or", "more", "availability", "restriction", "messages", "being", "combined", "in", "a", "list", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/availability/renderer.php#L46-L65
216,759
moodle/moodle
lib/classes/notification.php
notification.add
public static function add($message, $level = null) { global $PAGE, $SESSION; if ($PAGE && $PAGE->state === \moodle_page::STATE_IN_BODY) { // Currently in the page body - just render and exit immediately. // We insert some code to immediately insert this into the user-notifications created by the header. $id = uniqid(); echo \html_writer::span( $PAGE->get_renderer('core')->render(new \core\output\notification($message, $level)), '', array('id' => $id)); // Insert this JS here using a script directly rather than waiting for the page footer to load to avoid // ensure that the message is added to the user-notifications section as soon as possible after it is created. echo \html_writer::script( "(function() {" . "var notificationHolder = document.getElementById('user-notifications');" . "if (!notificationHolder) { return; }" . "var thisNotification = document.getElementById('{$id}');" . "if (!thisNotification) { return; }" . "notificationHolder.appendChild(thisNotification.firstChild);" . "thisNotification.remove();" . "})();" ); return; } // Add the notification directly to the session. // This will either be fetched in the header, or by JS in the footer. if (!isset($SESSION->notifications) || !array($SESSION->notifications)) { // Initialise $SESSION if necessary. if (!is_object($SESSION)) { $SESSION = new stdClass(); } $SESSION->notifications = []; } $SESSION->notifications[] = (object) array( 'message' => $message, 'type' => $level, ); }
php
public static function add($message, $level = null) { global $PAGE, $SESSION; if ($PAGE && $PAGE->state === \moodle_page::STATE_IN_BODY) { // Currently in the page body - just render and exit immediately. // We insert some code to immediately insert this into the user-notifications created by the header. $id = uniqid(); echo \html_writer::span( $PAGE->get_renderer('core')->render(new \core\output\notification($message, $level)), '', array('id' => $id)); // Insert this JS here using a script directly rather than waiting for the page footer to load to avoid // ensure that the message is added to the user-notifications section as soon as possible after it is created. echo \html_writer::script( "(function() {" . "var notificationHolder = document.getElementById('user-notifications');" . "if (!notificationHolder) { return; }" . "var thisNotification = document.getElementById('{$id}');" . "if (!thisNotification) { return; }" . "notificationHolder.appendChild(thisNotification.firstChild);" . "thisNotification.remove();" . "})();" ); return; } // Add the notification directly to the session. // This will either be fetched in the header, or by JS in the footer. if (!isset($SESSION->notifications) || !array($SESSION->notifications)) { // Initialise $SESSION if necessary. if (!is_object($SESSION)) { $SESSION = new stdClass(); } $SESSION->notifications = []; } $SESSION->notifications[] = (object) array( 'message' => $message, 'type' => $level, ); }
[ "public", "static", "function", "add", "(", "$", "message", ",", "$", "level", "=", "null", ")", "{", "global", "$", "PAGE", ",", "$", "SESSION", ";", "if", "(", "$", "PAGE", "&&", "$", "PAGE", "->", "state", "===", "\\", "moodle_page", "::", "STATE_IN_BODY", ")", "{", "// Currently in the page body - just render and exit immediately.", "// We insert some code to immediately insert this into the user-notifications created by the header.", "$", "id", "=", "uniqid", "(", ")", ";", "echo", "\\", "html_writer", "::", "span", "(", "$", "PAGE", "->", "get_renderer", "(", "'core'", ")", "->", "render", "(", "new", "\\", "core", "\\", "output", "\\", "notification", "(", "$", "message", ",", "$", "level", ")", ")", ",", "''", ",", "array", "(", "'id'", "=>", "$", "id", ")", ")", ";", "// Insert this JS here using a script directly rather than waiting for the page footer to load to avoid", "// ensure that the message is added to the user-notifications section as soon as possible after it is created.", "echo", "\\", "html_writer", "::", "script", "(", "\"(function() {\"", ".", "\"var notificationHolder = document.getElementById('user-notifications');\"", ".", "\"if (!notificationHolder) { return; }\"", ".", "\"var thisNotification = document.getElementById('{$id}');\"", ".", "\"if (!thisNotification) { return; }\"", ".", "\"notificationHolder.appendChild(thisNotification.firstChild);\"", ".", "\"thisNotification.remove();\"", ".", "\"})();\"", ")", ";", "return", ";", "}", "// Add the notification directly to the session.", "// This will either be fetched in the header, or by JS in the footer.", "if", "(", "!", "isset", "(", "$", "SESSION", "->", "notifications", ")", "||", "!", "array", "(", "$", "SESSION", "->", "notifications", ")", ")", "{", "// Initialise $SESSION if necessary.", "if", "(", "!", "is_object", "(", "$", "SESSION", ")", ")", "{", "$", "SESSION", "=", "new", "stdClass", "(", ")", ";", "}", "$", "SESSION", "->", "notifications", "=", "[", "]", ";", "}", "$", "SESSION", "->", "notifications", "[", "]", "=", "(", "object", ")", "array", "(", "'message'", "=>", "$", "message", ",", "'type'", "=>", "$", "level", ",", ")", ";", "}" ]
Add a message to the session notification stack. @param string $message The message to add to the stack @param string $level The type of message to add to the stack
[ "Add", "a", "message", "to", "the", "session", "notification", "stack", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/notification.php#L58-L97
216,760
moodle/moodle
calendar/type/gregorian/classes/structure.php
structure.get_months
public function get_months() { $months = array(); $date = new \DateTime('@1263556800'); $date->setTimezone(new \DateTimeZone('UTC')); for ($i = 1; $i <= 12; $i++) { $date->setDate(2000, $i, 15); $months[$i] = userdate($date->getTimestamp(), '%B', 'UTC'); } return $months; }
php
public function get_months() { $months = array(); $date = new \DateTime('@1263556800'); $date->setTimezone(new \DateTimeZone('UTC')); for ($i = 1; $i <= 12; $i++) { $date->setDate(2000, $i, 15); $months[$i] = userdate($date->getTimestamp(), '%B', 'UTC'); } return $months; }
[ "public", "function", "get_months", "(", ")", "{", "$", "months", "=", "array", "(", ")", ";", "$", "date", "=", "new", "\\", "DateTime", "(", "'@1263556800'", ")", ";", "$", "date", "->", "setTimezone", "(", "new", "\\", "DateTimeZone", "(", "'UTC'", ")", ")", ";", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<=", "12", ";", "$", "i", "++", ")", "{", "$", "date", "->", "setDate", "(", "2000", ",", "$", "i", ",", "15", ")", ";", "$", "months", "[", "$", "i", "]", "=", "userdate", "(", "$", "date", "->", "getTimestamp", "(", ")", ",", "'%B'", ",", "'UTC'", ")", ";", "}", "return", "$", "months", ";", "}" ]
Returns a list of all the names of the months. @return array the month names
[ "Returns", "a", "list", "of", "all", "the", "names", "of", "the", "months", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/type/gregorian/classes/structure.php#L68-L79
216,761
moodle/moodle
calendar/type/gregorian/classes/structure.php
structure.get_years
public function get_years($minyear = null, $maxyear = null) { if (is_null($minyear)) { $minyear = $this->get_min_year(); } if (is_null($maxyear)) { $maxyear = $this->get_max_year(); } $years = array(); for ($i = $minyear; $i <= $maxyear; $i++) { $years[$i] = $i; } return $years; }
php
public function get_years($minyear = null, $maxyear = null) { if (is_null($minyear)) { $minyear = $this->get_min_year(); } if (is_null($maxyear)) { $maxyear = $this->get_max_year(); } $years = array(); for ($i = $minyear; $i <= $maxyear; $i++) { $years[$i] = $i; } return $years; }
[ "public", "function", "get_years", "(", "$", "minyear", "=", "null", ",", "$", "maxyear", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "minyear", ")", ")", "{", "$", "minyear", "=", "$", "this", "->", "get_min_year", "(", ")", ";", "}", "if", "(", "is_null", "(", "$", "maxyear", ")", ")", "{", "$", "maxyear", "=", "$", "this", "->", "get_max_year", "(", ")", ";", "}", "$", "years", "=", "array", "(", ")", ";", "for", "(", "$", "i", "=", "$", "minyear", ";", "$", "i", "<=", "$", "maxyear", ";", "$", "i", "++", ")", "{", "$", "years", "[", "$", "i", "]", "=", "$", "i", ";", "}", "return", "$", "years", ";", "}" ]
Returns an array of years. @param int $minyear @param int $maxyear @return array the years
[ "Returns", "an", "array", "of", "years", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/type/gregorian/classes/structure.php#L106-L121
216,762
moodle/moodle
calendar/type/gregorian/classes/structure.php
structure.get_date_order
public function get_date_order($minyear = null, $maxyear = null) { $dateinfo = array(); $dateinfo['day'] = $this->get_days(); $dateinfo['month'] = $this->get_months(); $dateinfo['year'] = $this->get_years($minyear, $maxyear); return $dateinfo; }
php
public function get_date_order($minyear = null, $maxyear = null) { $dateinfo = array(); $dateinfo['day'] = $this->get_days(); $dateinfo['month'] = $this->get_months(); $dateinfo['year'] = $this->get_years($minyear, $maxyear); return $dateinfo; }
[ "public", "function", "get_date_order", "(", "$", "minyear", "=", "null", ",", "$", "maxyear", "=", "null", ")", "{", "$", "dateinfo", "=", "array", "(", ")", ";", "$", "dateinfo", "[", "'day'", "]", "=", "$", "this", "->", "get_days", "(", ")", ";", "$", "dateinfo", "[", "'month'", "]", "=", "$", "this", "->", "get_months", "(", ")", ";", "$", "dateinfo", "[", "'year'", "]", "=", "$", "this", "->", "get_years", "(", "$", "minyear", ",", "$", "maxyear", ")", ";", "return", "$", "dateinfo", ";", "}" ]
Returns a multidimensional array with information for day, month, year and the order they are displayed when selecting a date. The order in the array will be the order displayed when selecting a date. Override this function to change the date selector order. @param int $minyear The year to start with @param int $maxyear The year to finish with @return array Full date information
[ "Returns", "a", "multidimensional", "array", "with", "information", "for", "day", "month", "year", "and", "the", "order", "they", "are", "displayed", "when", "selecting", "a", "date", ".", "The", "order", "in", "the", "array", "will", "be", "the", "order", "displayed", "when", "selecting", "a", "date", ".", "Override", "this", "function", "to", "change", "the", "date", "selector", "order", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/type/gregorian/classes/structure.php#L133-L140
216,763
moodle/moodle
calendar/type/gregorian/classes/structure.php
structure.get_weekdays
public function get_weekdays() { return array( 0 => array( 'shortname' => get_string('sun', 'calendar'), 'fullname' => get_string('sunday', 'calendar') ), 1 => array( 'shortname' => get_string('mon', 'calendar'), 'fullname' => get_string('monday', 'calendar') ), 2 => array( 'shortname' => get_string('tue', 'calendar'), 'fullname' => get_string('tuesday', 'calendar') ), 3 => array( 'shortname' => get_string('wed', 'calendar'), 'fullname' => get_string('wednesday', 'calendar') ), 4 => array( 'shortname' => get_string('thu', 'calendar'), 'fullname' => get_string('thursday', 'calendar') ), 5 => array( 'shortname' => get_string('fri', 'calendar'), 'fullname' => get_string('friday', 'calendar') ), 6 => array( 'shortname' => get_string('sat', 'calendar'), 'fullname' => get_string('saturday', 'calendar') ), ); }
php
public function get_weekdays() { return array( 0 => array( 'shortname' => get_string('sun', 'calendar'), 'fullname' => get_string('sunday', 'calendar') ), 1 => array( 'shortname' => get_string('mon', 'calendar'), 'fullname' => get_string('monday', 'calendar') ), 2 => array( 'shortname' => get_string('tue', 'calendar'), 'fullname' => get_string('tuesday', 'calendar') ), 3 => array( 'shortname' => get_string('wed', 'calendar'), 'fullname' => get_string('wednesday', 'calendar') ), 4 => array( 'shortname' => get_string('thu', 'calendar'), 'fullname' => get_string('thursday', 'calendar') ), 5 => array( 'shortname' => get_string('fri', 'calendar'), 'fullname' => get_string('friday', 'calendar') ), 6 => array( 'shortname' => get_string('sat', 'calendar'), 'fullname' => get_string('saturday', 'calendar') ), ); }
[ "public", "function", "get_weekdays", "(", ")", "{", "return", "array", "(", "0", "=>", "array", "(", "'shortname'", "=>", "get_string", "(", "'sun'", ",", "'calendar'", ")", ",", "'fullname'", "=>", "get_string", "(", "'sunday'", ",", "'calendar'", ")", ")", ",", "1", "=>", "array", "(", "'shortname'", "=>", "get_string", "(", "'mon'", ",", "'calendar'", ")", ",", "'fullname'", "=>", "get_string", "(", "'monday'", ",", "'calendar'", ")", ")", ",", "2", "=>", "array", "(", "'shortname'", "=>", "get_string", "(", "'tue'", ",", "'calendar'", ")", ",", "'fullname'", "=>", "get_string", "(", "'tuesday'", ",", "'calendar'", ")", ")", ",", "3", "=>", "array", "(", "'shortname'", "=>", "get_string", "(", "'wed'", ",", "'calendar'", ")", ",", "'fullname'", "=>", "get_string", "(", "'wednesday'", ",", "'calendar'", ")", ")", ",", "4", "=>", "array", "(", "'shortname'", "=>", "get_string", "(", "'thu'", ",", "'calendar'", ")", ",", "'fullname'", "=>", "get_string", "(", "'thursday'", ",", "'calendar'", ")", ")", ",", "5", "=>", "array", "(", "'shortname'", "=>", "get_string", "(", "'fri'", ",", "'calendar'", ")", ",", "'fullname'", "=>", "get_string", "(", "'friday'", ",", "'calendar'", ")", ")", ",", "6", "=>", "array", "(", "'shortname'", "=>", "get_string", "(", "'sat'", ",", "'calendar'", ")", ",", "'fullname'", "=>", "get_string", "(", "'saturday'", ",", "'calendar'", ")", ")", ",", ")", ";", "}" ]
Returns an indexed list of all the names of the weekdays. The list starts with the index 0. Each index, representing a day, must be an array that contains the indexes 'shortname' and 'fullname'. @return array array of days
[ "Returns", "an", "indexed", "list", "of", "all", "the", "names", "of", "the", "weekdays", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/type/gregorian/classes/structure.php#L160-L191
216,764
moodle/moodle
calendar/type/gregorian/classes/structure.php
structure.get_starting_weekday
public function get_starting_weekday() { global $CFG; if (isset($CFG->calendar_startwday)) { $firstday = $CFG->calendar_startwday; } else { $firstday = get_string('firstdayofweek', 'langconfig'); } if (!is_numeric($firstday)) { $startingweekday = CALENDAR_DEFAULT_STARTING_WEEKDAY; } else { $startingweekday = intval($firstday) % 7; } return get_user_preferences('calendar_startwday', $startingweekday); }
php
public function get_starting_weekday() { global $CFG; if (isset($CFG->calendar_startwday)) { $firstday = $CFG->calendar_startwday; } else { $firstday = get_string('firstdayofweek', 'langconfig'); } if (!is_numeric($firstday)) { $startingweekday = CALENDAR_DEFAULT_STARTING_WEEKDAY; } else { $startingweekday = intval($firstday) % 7; } return get_user_preferences('calendar_startwday', $startingweekday); }
[ "public", "function", "get_starting_weekday", "(", ")", "{", "global", "$", "CFG", ";", "if", "(", "isset", "(", "$", "CFG", "->", "calendar_startwday", ")", ")", "{", "$", "firstday", "=", "$", "CFG", "->", "calendar_startwday", ";", "}", "else", "{", "$", "firstday", "=", "get_string", "(", "'firstdayofweek'", ",", "'langconfig'", ")", ";", "}", "if", "(", "!", "is_numeric", "(", "$", "firstday", ")", ")", "{", "$", "startingweekday", "=", "CALENDAR_DEFAULT_STARTING_WEEKDAY", ";", "}", "else", "{", "$", "startingweekday", "=", "intval", "(", "$", "firstday", ")", "%", "7", ";", "}", "return", "get_user_preferences", "(", "'calendar_startwday'", ",", "$", "startingweekday", ")", ";", "}" ]
Returns the index of the starting week day. This may vary, for example some may consider Monday as the start of the week, where as others may consider Sunday the start. @return int
[ "Returns", "the", "index", "of", "the", "starting", "week", "day", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/type/gregorian/classes/structure.php#L201-L217
216,765
moodle/moodle
calendar/type/gregorian/classes/structure.php
structure.get_weekday
public function get_weekday($year, $month, $day) { return intval(date('w', mktime(12, 0, 0, $month, $day, $year))); }
php
public function get_weekday($year, $month, $day) { return intval(date('w', mktime(12, 0, 0, $month, $day, $year))); }
[ "public", "function", "get_weekday", "(", "$", "year", ",", "$", "month", ",", "$", "day", ")", "{", "return", "intval", "(", "date", "(", "'w'", ",", "mktime", "(", "12", ",", "0", ",", "0", ",", "$", "month", ",", "$", "day", ",", "$", "year", ")", ")", ")", ";", "}" ]
Returns the index of the weekday for a specific calendar date. @param int $year @param int $month @param int $day @return int
[ "Returns", "the", "index", "of", "the", "weekday", "for", "a", "specific", "calendar", "date", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/type/gregorian/classes/structure.php#L227-L229
216,766
moodle/moodle
calendar/type/gregorian/classes/structure.php
structure.timestamp_to_date_string
public function timestamp_to_date_string($time, $format, $timezone, $fixday, $fixhour) { global $CFG; if (empty($format)) { $format = get_string('strftimedaydatetime', 'langconfig'); } if (!empty($CFG->nofixday)) { // Config.php can force %d not to be fixed. $fixday = false; } else if ($fixday) { $formatnoday = str_replace('%d', 'DD', $format); $fixday = ($formatnoday != $format); $format = $formatnoday; } // Note: This logic about fixing 12-hour time to remove unnecessary leading // zero is required because on Windows, PHP strftime function does not // support the correct 'hour without leading zero' parameter (%l). if (!empty($CFG->nofixhour)) { // Config.php can force %I not to be fixed. $fixhour = false; } else if ($fixhour) { $formatnohour = str_replace('%I', 'HH', $format); $fixhour = ($formatnohour != $format); $format = $formatnohour; } $time = (int)$time; // Moodle allows rubbish in input... $datestring = date_format_string($time, $format, $timezone); date_default_timezone_set(\core_date::get_user_timezone($timezone)); if ($fixday) { $daystring = ltrim(str_replace(array(' 0', ' '), '', strftime(' %d', $time))); $datestring = str_replace('DD', $daystring, $datestring); } if ($fixhour) { $hourstring = ltrim(str_replace(array(' 0', ' '), '', strftime(' %I', $time))); $datestring = str_replace('HH', $hourstring, $datestring); } \core_date::set_default_server_timezone(); return $datestring; }
php
public function timestamp_to_date_string($time, $format, $timezone, $fixday, $fixhour) { global $CFG; if (empty($format)) { $format = get_string('strftimedaydatetime', 'langconfig'); } if (!empty($CFG->nofixday)) { // Config.php can force %d not to be fixed. $fixday = false; } else if ($fixday) { $formatnoday = str_replace('%d', 'DD', $format); $fixday = ($formatnoday != $format); $format = $formatnoday; } // Note: This logic about fixing 12-hour time to remove unnecessary leading // zero is required because on Windows, PHP strftime function does not // support the correct 'hour without leading zero' parameter (%l). if (!empty($CFG->nofixhour)) { // Config.php can force %I not to be fixed. $fixhour = false; } else if ($fixhour) { $formatnohour = str_replace('%I', 'HH', $format); $fixhour = ($formatnohour != $format); $format = $formatnohour; } $time = (int)$time; // Moodle allows rubbish in input... $datestring = date_format_string($time, $format, $timezone); date_default_timezone_set(\core_date::get_user_timezone($timezone)); if ($fixday) { $daystring = ltrim(str_replace(array(' 0', ' '), '', strftime(' %d', $time))); $datestring = str_replace('DD', $daystring, $datestring); } if ($fixhour) { $hourstring = ltrim(str_replace(array(' 0', ' '), '', strftime(' %I', $time))); $datestring = str_replace('HH', $hourstring, $datestring); } \core_date::set_default_server_timezone(); return $datestring; }
[ "public", "function", "timestamp_to_date_string", "(", "$", "time", ",", "$", "format", ",", "$", "timezone", ",", "$", "fixday", ",", "$", "fixhour", ")", "{", "global", "$", "CFG", ";", "if", "(", "empty", "(", "$", "format", ")", ")", "{", "$", "format", "=", "get_string", "(", "'strftimedaydatetime'", ",", "'langconfig'", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "CFG", "->", "nofixday", ")", ")", "{", "// Config.php can force %d not to be fixed.", "$", "fixday", "=", "false", ";", "}", "else", "if", "(", "$", "fixday", ")", "{", "$", "formatnoday", "=", "str_replace", "(", "'%d'", ",", "'DD'", ",", "$", "format", ")", ";", "$", "fixday", "=", "(", "$", "formatnoday", "!=", "$", "format", ")", ";", "$", "format", "=", "$", "formatnoday", ";", "}", "// Note: This logic about fixing 12-hour time to remove unnecessary leading", "// zero is required because on Windows, PHP strftime function does not", "// support the correct 'hour without leading zero' parameter (%l).", "if", "(", "!", "empty", "(", "$", "CFG", "->", "nofixhour", ")", ")", "{", "// Config.php can force %I not to be fixed.", "$", "fixhour", "=", "false", ";", "}", "else", "if", "(", "$", "fixhour", ")", "{", "$", "formatnohour", "=", "str_replace", "(", "'%I'", ",", "'HH'", ",", "$", "format", ")", ";", "$", "fixhour", "=", "(", "$", "formatnohour", "!=", "$", "format", ")", ";", "$", "format", "=", "$", "formatnohour", ";", "}", "$", "time", "=", "(", "int", ")", "$", "time", ";", "// Moodle allows rubbish in input...", "$", "datestring", "=", "date_format_string", "(", "$", "time", ",", "$", "format", ",", "$", "timezone", ")", ";", "date_default_timezone_set", "(", "\\", "core_date", "::", "get_user_timezone", "(", "$", "timezone", ")", ")", ";", "if", "(", "$", "fixday", ")", "{", "$", "daystring", "=", "ltrim", "(", "str_replace", "(", "array", "(", "' 0'", ",", "' '", ")", ",", "''", ",", "strftime", "(", "' %d'", ",", "$", "time", ")", ")", ")", ";", "$", "datestring", "=", "str_replace", "(", "'DD'", ",", "$", "daystring", ",", "$", "datestring", ")", ";", "}", "if", "(", "$", "fixhour", ")", "{", "$", "hourstring", "=", "ltrim", "(", "str_replace", "(", "array", "(", "' 0'", ",", "' '", ")", ",", "''", ",", "strftime", "(", "' %I'", ",", "$", "time", ")", ")", ")", ";", "$", "datestring", "=", "str_replace", "(", "'HH'", ",", "$", "hourstring", ",", "$", "datestring", ")", ";", "}", "\\", "core_date", "::", "set_default_server_timezone", "(", ")", ";", "return", "$", "datestring", ";", "}" ]
Returns a formatted string that represents a date in user time. Returns a formatted string that represents a date in user time <b>WARNING: note that the format is for strftime(), not date().</b> Because of a bug in most Windows time libraries, we can't use the nicer %e, so we have to use %d which has leading zeroes. A lot of the fuss in the function is just getting rid of these leading zeroes as efficiently as possible. If parameter fixday = true (default), then take off leading zero from %d, else maintain it. @param int $time the timestamp in UTC, as obtained from the database @param string $format strftime format @param int|float|string $timezone the timezone to use {@link http://docs.moodle.org/dev/Time_API#Timezone} @param bool $fixday if true then the leading zero from %d is removed, if false then the leading zero is maintained @param bool $fixhour if true then the leading zero from %I is removed, if false then the leading zero is maintained @return string the formatted date/time
[ "Returns", "a", "formatted", "string", "that", "represents", "a", "date", "in", "user", "time", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/type/gregorian/classes/structure.php#L299-L343
216,767
moodle/moodle
lib/horde/framework/Horde/Exception.php
Horde_Exception.setLogLevel
public function setLogLevel($level = 0) { if (is_string($level)) { $level = defined('Horde_Log::' . $level) ? constant('Horde_Log::' . $level) : 0; } $this->_logLevel = $level; }
php
public function setLogLevel($level = 0) { if (is_string($level)) { $level = defined('Horde_Log::' . $level) ? constant('Horde_Log::' . $level) : 0; } $this->_logLevel = $level; }
[ "public", "function", "setLogLevel", "(", "$", "level", "=", "0", ")", "{", "if", "(", "is_string", "(", "$", "level", ")", ")", "{", "$", "level", "=", "defined", "(", "'Horde_Log::'", ".", "$", "level", ")", "?", "constant", "(", "'Horde_Log::'", ".", "$", "level", ")", ":", "0", ";", "}", "$", "this", "->", "_logLevel", "=", "$", "level", ";", "}" ]
Sets the log level. @param mixed $level The log level.
[ "Sets", "the", "log", "level", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Exception.php#L62-L71
216,768
moodle/moodle
mod/lti/TrivialStore.php
TrivialOAuthDataStore.lookup_consumer
public function lookup_consumer($consumerkey) { if (strpos($consumerkey, "http://" ) === 0) { $consumer = new OAuthConsumer($consumerkey, "secret", null); return $consumer; } if ( $this->consumers[$consumerkey] ) { $consumer = new OAuthConsumer($consumerkey, $this->consumers[$consumerkey], null); return $consumer; } return null; }
php
public function lookup_consumer($consumerkey) { if (strpos($consumerkey, "http://" ) === 0) { $consumer = new OAuthConsumer($consumerkey, "secret", null); return $consumer; } if ( $this->consumers[$consumerkey] ) { $consumer = new OAuthConsumer($consumerkey, $this->consumers[$consumerkey], null); return $consumer; } return null; }
[ "public", "function", "lookup_consumer", "(", "$", "consumerkey", ")", "{", "if", "(", "strpos", "(", "$", "consumerkey", ",", "\"http://\"", ")", "===", "0", ")", "{", "$", "consumer", "=", "new", "OAuthConsumer", "(", "$", "consumerkey", ",", "\"secret\"", ",", "null", ")", ";", "return", "$", "consumer", ";", "}", "if", "(", "$", "this", "->", "consumers", "[", "$", "consumerkey", "]", ")", "{", "$", "consumer", "=", "new", "OAuthConsumer", "(", "$", "consumerkey", ",", "$", "this", "->", "consumers", "[", "$", "consumerkey", "]", ",", "null", ")", ";", "return", "$", "consumer", ";", "}", "return", "null", ";", "}" ]
Get OAuth consumer given its key @param string $consumerkey Consumer key @return moodle\mod\lti\OAuthConsumer OAuthConsumer object
[ "Get", "OAuth", "consumer", "given", "its", "key" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lti/TrivialStore.php#L75-L85
216,769
moodle/moodle
lib/pear/HTML/QuickForm/RuleRegistry.php
HTML_QuickForm_RuleRegistry.&
function &getRule($ruleName) { list($class, $path) = $GLOBALS['_HTML_QuickForm_registered_rules'][$ruleName]; if (!isset($this->_rules[$class])) { if (!empty($path)) { include_once($path); } $this->_rules[$class] = new $class(); } $this->_rules[$class]->setName($ruleName); return $this->_rules[$class]; }
php
function &getRule($ruleName) { list($class, $path) = $GLOBALS['_HTML_QuickForm_registered_rules'][$ruleName]; if (!isset($this->_rules[$class])) { if (!empty($path)) { include_once($path); } $this->_rules[$class] = new $class(); } $this->_rules[$class]->setName($ruleName); return $this->_rules[$class]; }
[ "function", "&", "getRule", "(", "$", "ruleName", ")", "{", "list", "(", "$", "class", ",", "$", "path", ")", "=", "$", "GLOBALS", "[", "'_HTML_QuickForm_registered_rules'", "]", "[", "$", "ruleName", "]", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "_rules", "[", "$", "class", "]", ")", ")", "{", "if", "(", "!", "empty", "(", "$", "path", ")", ")", "{", "include_once", "(", "$", "path", ")", ";", "}", "$", "this", "->", "_rules", "[", "$", "class", "]", "=", "new", "$", "class", "(", ")", ";", "}", "$", "this", "->", "_rules", "[", "$", "class", "]", "->", "setName", "(", "$", "ruleName", ")", ";", "return", "$", "this", "->", "_rules", "[", "$", "class", "]", ";", "}" ]
Returns a reference to the requested rule object @param string $ruleName Name of the requested rule @access public @return object
[ "Returns", "a", "reference", "to", "the", "requested", "rule", "object" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/RuleRegistry.php#L110-L122
216,770
moodle/moodle
lib/pear/HTML/QuickForm/RuleRegistry.php
HTML_QuickForm_RuleRegistry.validate
function validate($ruleName, $values, $options = null, $multiple = false) { $rule =& $this->getRule($ruleName); if (is_array($values) && !$multiple) { $result = 0; foreach ($values as $value) { if ($rule->validate($value, $options) === true) { $result++; } } return ($result == 0) ? false : $result; } else { return $rule->validate($values, $options); } }
php
function validate($ruleName, $values, $options = null, $multiple = false) { $rule =& $this->getRule($ruleName); if (is_array($values) && !$multiple) { $result = 0; foreach ($values as $value) { if ($rule->validate($value, $options) === true) { $result++; } } return ($result == 0) ? false : $result; } else { return $rule->validate($values, $options); } }
[ "function", "validate", "(", "$", "ruleName", ",", "$", "values", ",", "$", "options", "=", "null", ",", "$", "multiple", "=", "false", ")", "{", "$", "rule", "=", "&", "$", "this", "->", "getRule", "(", "$", "ruleName", ")", ";", "if", "(", "is_array", "(", "$", "values", ")", "&&", "!", "$", "multiple", ")", "{", "$", "result", "=", "0", ";", "foreach", "(", "$", "values", "as", "$", "value", ")", "{", "if", "(", "$", "rule", "->", "validate", "(", "$", "value", ",", "$", "options", ")", "===", "true", ")", "{", "$", "result", "++", ";", "}", "}", "return", "(", "$", "result", "==", "0", ")", "?", "false", ":", "$", "result", ";", "}", "else", "{", "return", "$", "rule", "->", "validate", "(", "$", "values", ",", "$", "options", ")", ";", "}", "}" ]
Performs validation on the given values @param string $ruleName Name of the rule to be used @param mixed $values Can be a scalar or an array of values to be validated @param mixed $options Options used by the rule @param mixed $multiple Whether to validate an array of values altogether @access public @return mixed true if no error found, int of valid values (when an array of values is given) or false if error
[ "Performs", "validation", "on", "the", "given", "values" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/RuleRegistry.php#L135-L150
216,771
moodle/moodle
lib/pear/HTML/QuickForm/RuleRegistry.php
HTML_QuickForm_RuleRegistry.getValidationScript
function getValidationScript(&$element, $elementName, $ruleData) { $reset = (isset($ruleData['reset'])) ? $ruleData['reset'] : false; $rule =& $this->getRule($ruleData['type']); if (!is_array($element)) { list($jsValue, $jsReset) = $this->_getJsValue($element, $elementName, $reset, null); } else { $jsValue = " value = new Array();\n"; $jsReset = ''; for ($i = 0; $i < count($element); $i++) { list($tmp_value, $tmp_reset) = $this->_getJsValue($element[$i], $element[$i]->getName(), $reset, $i); $jsValue .= "\n" . $tmp_value; $jsReset .= $tmp_reset; } } $jsField = isset($ruleData['group'])? $ruleData['group']: $elementName; list ($jsPrefix, $jsCheck) = $rule->getValidationScript($ruleData['format']); if (!isset($ruleData['howmany'])) { $js = $jsValue . "\n" . $jsPrefix . " if (" . str_replace('{jsVar}', 'value', $jsCheck) . " && !errFlag['{$jsField}']) {\n" . " errFlag['{$jsField}'] = true;\n" . " _qfMsg = _qfMsg + '\\n - {$ruleData['message']}';\n" . $jsReset . " }\n"; } else { $js = $jsValue . "\n" . $jsPrefix . " var res = 0;\n" . " for (var i = 0; i < value.length; i++) {\n" . " if (!(" . str_replace('{jsVar}', 'value[i]', $jsCheck) . ")) {\n" . " res++;\n" . " }\n" . " }\n" . " if (res < {$ruleData['howmany']} && !errFlag['{$jsField}']) {\n" . " errFlag['{$jsField}'] = true;\n" . " _qfMsg = _qfMsg + '\\n - {$ruleData['message']}';\n" . $jsReset . " }\n"; } return $js; }
php
function getValidationScript(&$element, $elementName, $ruleData) { $reset = (isset($ruleData['reset'])) ? $ruleData['reset'] : false; $rule =& $this->getRule($ruleData['type']); if (!is_array($element)) { list($jsValue, $jsReset) = $this->_getJsValue($element, $elementName, $reset, null); } else { $jsValue = " value = new Array();\n"; $jsReset = ''; for ($i = 0; $i < count($element); $i++) { list($tmp_value, $tmp_reset) = $this->_getJsValue($element[$i], $element[$i]->getName(), $reset, $i); $jsValue .= "\n" . $tmp_value; $jsReset .= $tmp_reset; } } $jsField = isset($ruleData['group'])? $ruleData['group']: $elementName; list ($jsPrefix, $jsCheck) = $rule->getValidationScript($ruleData['format']); if (!isset($ruleData['howmany'])) { $js = $jsValue . "\n" . $jsPrefix . " if (" . str_replace('{jsVar}', 'value', $jsCheck) . " && !errFlag['{$jsField}']) {\n" . " errFlag['{$jsField}'] = true;\n" . " _qfMsg = _qfMsg + '\\n - {$ruleData['message']}';\n" . $jsReset . " }\n"; } else { $js = $jsValue . "\n" . $jsPrefix . " var res = 0;\n" . " for (var i = 0; i < value.length; i++) {\n" . " if (!(" . str_replace('{jsVar}', 'value[i]', $jsCheck) . ")) {\n" . " res++;\n" . " }\n" . " }\n" . " if (res < {$ruleData['howmany']} && !errFlag['{$jsField}']) {\n" . " errFlag['{$jsField}'] = true;\n" . " _qfMsg = _qfMsg + '\\n - {$ruleData['message']}';\n" . $jsReset . " }\n"; } return $js; }
[ "function", "getValidationScript", "(", "&", "$", "element", ",", "$", "elementName", ",", "$", "ruleData", ")", "{", "$", "reset", "=", "(", "isset", "(", "$", "ruleData", "[", "'reset'", "]", ")", ")", "?", "$", "ruleData", "[", "'reset'", "]", ":", "false", ";", "$", "rule", "=", "&", "$", "this", "->", "getRule", "(", "$", "ruleData", "[", "'type'", "]", ")", ";", "if", "(", "!", "is_array", "(", "$", "element", ")", ")", "{", "list", "(", "$", "jsValue", ",", "$", "jsReset", ")", "=", "$", "this", "->", "_getJsValue", "(", "$", "element", ",", "$", "elementName", ",", "$", "reset", ",", "null", ")", ";", "}", "else", "{", "$", "jsValue", "=", "\" value = new Array();\\n\"", ";", "$", "jsReset", "=", "''", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "element", ")", ";", "$", "i", "++", ")", "{", "list", "(", "$", "tmp_value", ",", "$", "tmp_reset", ")", "=", "$", "this", "->", "_getJsValue", "(", "$", "element", "[", "$", "i", "]", ",", "$", "element", "[", "$", "i", "]", "->", "getName", "(", ")", ",", "$", "reset", ",", "$", "i", ")", ";", "$", "jsValue", ".=", "\"\\n\"", ".", "$", "tmp_value", ";", "$", "jsReset", ".=", "$", "tmp_reset", ";", "}", "}", "$", "jsField", "=", "isset", "(", "$", "ruleData", "[", "'group'", "]", ")", "?", "$", "ruleData", "[", "'group'", "]", ":", "$", "elementName", ";", "list", "(", "$", "jsPrefix", ",", "$", "jsCheck", ")", "=", "$", "rule", "->", "getValidationScript", "(", "$", "ruleData", "[", "'format'", "]", ")", ";", "if", "(", "!", "isset", "(", "$", "ruleData", "[", "'howmany'", "]", ")", ")", "{", "$", "js", "=", "$", "jsValue", ".", "\"\\n\"", ".", "$", "jsPrefix", ".", "\" if (\"", ".", "str_replace", "(", "'{jsVar}'", ",", "'value'", ",", "$", "jsCheck", ")", ".", "\" && !errFlag['{$jsField}']) {\\n\"", ".", "\" errFlag['{$jsField}'] = true;\\n\"", ".", "\" _qfMsg = _qfMsg + '\\\\n - {$ruleData['message']}';\\n\"", ".", "$", "jsReset", ".", "\" }\\n\"", ";", "}", "else", "{", "$", "js", "=", "$", "jsValue", ".", "\"\\n\"", ".", "$", "jsPrefix", ".", "\" var res = 0;\\n\"", ".", "\" for (var i = 0; i < value.length; i++) {\\n\"", ".", "\" if (!(\"", ".", "str_replace", "(", "'{jsVar}'", ",", "'value[i]'", ",", "$", "jsCheck", ")", ".", "\")) {\\n\"", ".", "\" res++;\\n\"", ".", "\" }\\n\"", ".", "\" }\\n\"", ".", "\" if (res < {$ruleData['howmany']} && !errFlag['{$jsField}']) {\\n\"", ".", "\" errFlag['{$jsField}'] = true;\\n\"", ".", "\" _qfMsg = _qfMsg + '\\\\n - {$ruleData['message']}';\\n\"", ".", "$", "jsReset", ".", "\" }\\n\"", ";", "}", "return", "$", "js", ";", "}" ]
Returns the validation test in javascript code @param mixed Element(s) the rule applies to @param string Element name, in case $element is not array @param array Rule data @access public @return string JavaScript for the rule
[ "Returns", "the", "validation", "test", "in", "javascript", "code" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/RuleRegistry.php#L161-L200
216,772
moodle/moodle
auth/oauth2/classes/linked_login.php
linked_login.has_existing_issuer_match
public static function has_existing_issuer_match(\core\oauth2\issuer $issuer, $username) { global $DB; $where = "issuerid = :issuerid AND username = :username AND (confirmtokenexpires = 0 OR confirmtokenexpires > :maxexpiry)"; $count = $DB->count_records_select(static::TABLE, $where, [ 'issuerid' => $issuer->get('id'), 'username' => $username, 'maxexpiry' => (new \DateTime('NOW'))->getTimestamp(), ]); return $count > 0; }
php
public static function has_existing_issuer_match(\core\oauth2\issuer $issuer, $username) { global $DB; $where = "issuerid = :issuerid AND username = :username AND (confirmtokenexpires = 0 OR confirmtokenexpires > :maxexpiry)"; $count = $DB->count_records_select(static::TABLE, $where, [ 'issuerid' => $issuer->get('id'), 'username' => $username, 'maxexpiry' => (new \DateTime('NOW'))->getTimestamp(), ]); return $count > 0; }
[ "public", "static", "function", "has_existing_issuer_match", "(", "\\", "core", "\\", "oauth2", "\\", "issuer", "$", "issuer", ",", "$", "username", ")", "{", "global", "$", "DB", ";", "$", "where", "=", "\"issuerid = :issuerid\n AND username = :username\n AND (confirmtokenexpires = 0 OR confirmtokenexpires > :maxexpiry)\"", ";", "$", "count", "=", "$", "DB", "->", "count_records_select", "(", "static", "::", "TABLE", ",", "$", "where", ",", "[", "'issuerid'", "=>", "$", "issuer", "->", "get", "(", "'id'", ")", ",", "'username'", "=>", "$", "username", ",", "'maxexpiry'", "=>", "(", "new", "\\", "DateTime", "(", "'NOW'", ")", ")", "->", "getTimestamp", "(", ")", ",", "]", ")", ";", "return", "$", "count", ">", "0", ";", "}" ]
Check whether there are any valid linked accounts for this issuer and username combination. @param \core\oauth2\issuer $issuer The issuer @param string $username The username to check
[ "Check", "whether", "there", "are", "any", "valid", "linked", "accounts", "for", "this", "issuer", "and", "username", "combination", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/oauth2/classes/linked_login.php#L75-L89
216,773
moodle/moodle
auth/oauth2/classes/linked_login.php
linked_login.delete_orphaned
public static function delete_orphaned($issuerid = false) { global $DB; // Delete any linked_login entries with a issuerid // which does not exist in the issuer table. // In the left join, the issuer id will be null // where a match linked_login.issuerid is not found. $sql = "DELETE FROM {" . self::TABLE . "} WHERE issuerid NOT IN (SELECT id FROM {" . \core\oauth2\issuer::TABLE . "})"; $params = []; if (!empty($issuerid)) { $sql .= ' AND issuerid = ?'; $params['issuerid'] = $issuerid; } return $DB->execute($sql, $params); }
php
public static function delete_orphaned($issuerid = false) { global $DB; // Delete any linked_login entries with a issuerid // which does not exist in the issuer table. // In the left join, the issuer id will be null // where a match linked_login.issuerid is not found. $sql = "DELETE FROM {" . self::TABLE . "} WHERE issuerid NOT IN (SELECT id FROM {" . \core\oauth2\issuer::TABLE . "})"; $params = []; if (!empty($issuerid)) { $sql .= ' AND issuerid = ?'; $params['issuerid'] = $issuerid; } return $DB->execute($sql, $params); }
[ "public", "static", "function", "delete_orphaned", "(", "$", "issuerid", "=", "false", ")", "{", "global", "$", "DB", ";", "// Delete any linked_login entries with a issuerid", "// which does not exist in the issuer table.", "// In the left join, the issuer id will be null", "// where a match linked_login.issuerid is not found.", "$", "sql", "=", "\"DELETE FROM {\"", ".", "self", "::", "TABLE", ".", "\"}\n WHERE issuerid NOT IN (SELECT id FROM {\"", ".", "\\", "core", "\\", "oauth2", "\\", "issuer", "::", "TABLE", ".", "\"})\"", ";", "$", "params", "=", "[", "]", ";", "if", "(", "!", "empty", "(", "$", "issuerid", ")", ")", "{", "$", "sql", ".=", "' AND issuerid = ?'", ";", "$", "params", "[", "'issuerid'", "]", "=", "$", "issuerid", ";", "}", "return", "$", "DB", "->", "execute", "(", "$", "sql", ",", "$", "params", ")", ";", "}" ]
Remove all linked logins that are using issuers that have been deleted. @param int $issuerid The issuer id of the issuer to check, or false to check all (defaults to all) @return boolean
[ "Remove", "all", "linked", "logins", "that", "are", "using", "issuers", "that", "have", "been", "deleted", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/oauth2/classes/linked_login.php#L97-L111
216,774
moodle/moodle
mod/data/field/date/field.class.php
data_field_date.display_search_field
function display_search_field($value=0) { $selectors = html_writer::select_time('days', 'f_'.$this->field->id.'_d', $value['timestamp']) . html_writer::select_time('months', 'f_'.$this->field->id.'_m', $value['timestamp']) . html_writer::select_time('years', 'f_'.$this->field->id.'_y', $value['timestamp']); $datecheck = html_writer::checkbox('f_'.$this->field->id.'_z', 1, $value['usedate']); $str = '<div class="form-inline">' . $selectors . ' ' . $datecheck . ' ' . get_string('usedate', 'data') . '</div>'; return $str; }
php
function display_search_field($value=0) { $selectors = html_writer::select_time('days', 'f_'.$this->field->id.'_d', $value['timestamp']) . html_writer::select_time('months', 'f_'.$this->field->id.'_m', $value['timestamp']) . html_writer::select_time('years', 'f_'.$this->field->id.'_y', $value['timestamp']); $datecheck = html_writer::checkbox('f_'.$this->field->id.'_z', 1, $value['usedate']); $str = '<div class="form-inline">' . $selectors . ' ' . $datecheck . ' ' . get_string('usedate', 'data') . '</div>'; return $str; }
[ "function", "display_search_field", "(", "$", "value", "=", "0", ")", "{", "$", "selectors", "=", "html_writer", "::", "select_time", "(", "'days'", ",", "'f_'", ".", "$", "this", "->", "field", "->", "id", ".", "'_d'", ",", "$", "value", "[", "'timestamp'", "]", ")", ".", "html_writer", "::", "select_time", "(", "'months'", ",", "'f_'", ".", "$", "this", "->", "field", "->", "id", ".", "'_m'", ",", "$", "value", "[", "'timestamp'", "]", ")", ".", "html_writer", "::", "select_time", "(", "'years'", ",", "'f_'", ".", "$", "this", "->", "field", "->", "id", ".", "'_y'", ",", "$", "value", "[", "'timestamp'", "]", ")", ";", "$", "datecheck", "=", "html_writer", "::", "checkbox", "(", "'f_'", ".", "$", "this", "->", "field", "->", "id", ".", "'_z'", ",", "1", ",", "$", "value", "[", "'usedate'", "]", ")", ";", "$", "str", "=", "'<div class=\"form-inline\">'", ".", "$", "selectors", ".", "' '", ".", "$", "datecheck", ".", "' '", ".", "get_string", "(", "'usedate'", ",", "'data'", ")", ".", "'</div>'", ";", "return", "$", "str", ";", "}" ]
Enable the following three functions once core API issues have been addressed.
[ "Enable", "the", "following", "three", "functions", "once", "core", "API", "issues", "have", "been", "addressed", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/field/date/field.class.php#L76-L84
216,775
moodle/moodle
mod/workshop/backup/moodle1/lib.php
moodle1_mod_workshop_handler.get_strategy_handler
protected function get_strategy_handler($strategy) { global $CFG; // we include other files here if (is_null($this->strategyhandlers)) { $this->strategyhandlers = array(); $subplugins = core_component::get_plugin_list('workshopform'); foreach ($subplugins as $name => $dir) { $handlerfile = $dir.'/backup/moodle1/lib.php'; $handlerclass = "moodle1_workshopform_{$name}_handler"; if (!file_exists($handlerfile)) { continue; } require_once($handlerfile); if (!class_exists($handlerclass)) { throw new moodle1_convert_exception('missing_handler_class', $handlerclass); } $this->log('preparing workshop grading strategy handler', backup::LOG_DEBUG, $handlerclass); $this->strategyhandlers[$name] = new $handlerclass($this, $name); if (!$this->strategyhandlers[$name] instanceof moodle1_workshopform_handler) { throw new moodle1_convert_exception('wrong_handler_class', get_class($this->strategyhandlers[$name])); } } } if (!isset($this->strategyhandlers[$strategy])) { throw new moodle1_convert_exception('usupported_subplugin', 'workshopform_'.$strategy); } return $this->strategyhandlers[$strategy]; }
php
protected function get_strategy_handler($strategy) { global $CFG; // we include other files here if (is_null($this->strategyhandlers)) { $this->strategyhandlers = array(); $subplugins = core_component::get_plugin_list('workshopform'); foreach ($subplugins as $name => $dir) { $handlerfile = $dir.'/backup/moodle1/lib.php'; $handlerclass = "moodle1_workshopform_{$name}_handler"; if (!file_exists($handlerfile)) { continue; } require_once($handlerfile); if (!class_exists($handlerclass)) { throw new moodle1_convert_exception('missing_handler_class', $handlerclass); } $this->log('preparing workshop grading strategy handler', backup::LOG_DEBUG, $handlerclass); $this->strategyhandlers[$name] = new $handlerclass($this, $name); if (!$this->strategyhandlers[$name] instanceof moodle1_workshopform_handler) { throw new moodle1_convert_exception('wrong_handler_class', get_class($this->strategyhandlers[$name])); } } } if (!isset($this->strategyhandlers[$strategy])) { throw new moodle1_convert_exception('usupported_subplugin', 'workshopform_'.$strategy); } return $this->strategyhandlers[$strategy]; }
[ "protected", "function", "get_strategy_handler", "(", "$", "strategy", ")", "{", "global", "$", "CFG", ";", "// we include other files here", "if", "(", "is_null", "(", "$", "this", "->", "strategyhandlers", ")", ")", "{", "$", "this", "->", "strategyhandlers", "=", "array", "(", ")", ";", "$", "subplugins", "=", "core_component", "::", "get_plugin_list", "(", "'workshopform'", ")", ";", "foreach", "(", "$", "subplugins", "as", "$", "name", "=>", "$", "dir", ")", "{", "$", "handlerfile", "=", "$", "dir", ".", "'/backup/moodle1/lib.php'", ";", "$", "handlerclass", "=", "\"moodle1_workshopform_{$name}_handler\"", ";", "if", "(", "!", "file_exists", "(", "$", "handlerfile", ")", ")", "{", "continue", ";", "}", "require_once", "(", "$", "handlerfile", ")", ";", "if", "(", "!", "class_exists", "(", "$", "handlerclass", ")", ")", "{", "throw", "new", "moodle1_convert_exception", "(", "'missing_handler_class'", ",", "$", "handlerclass", ")", ";", "}", "$", "this", "->", "log", "(", "'preparing workshop grading strategy handler'", ",", "backup", "::", "LOG_DEBUG", ",", "$", "handlerclass", ")", ";", "$", "this", "->", "strategyhandlers", "[", "$", "name", "]", "=", "new", "$", "handlerclass", "(", "$", "this", ",", "$", "name", ")", ";", "if", "(", "!", "$", "this", "->", "strategyhandlers", "[", "$", "name", "]", "instanceof", "moodle1_workshopform_handler", ")", "{", "throw", "new", "moodle1_convert_exception", "(", "'wrong_handler_class'", ",", "get_class", "(", "$", "this", "->", "strategyhandlers", "[", "$", "name", "]", ")", ")", ";", "}", "}", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "strategyhandlers", "[", "$", "strategy", "]", ")", ")", "{", "throw", "new", "moodle1_convert_exception", "(", "'usupported_subplugin'", ",", "'workshopform_'", ".", "$", "strategy", ")", ";", "}", "return", "$", "this", "->", "strategyhandlers", "[", "$", "strategy", "]", ";", "}" ]
Factory method returning the handler of the given grading strategy subplugin @param string $strategy the name of the grading strategy @throws moodle1_convert_exception @return moodle1_workshopform_handler the instance of the handler
[ "Factory", "method", "returning", "the", "handler", "of", "the", "given", "grading", "strategy", "subplugin" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/backup/moodle1/lib.php#L265-L295
216,776
moodle/moodle
backup/util/plan/base_plan.class.php
base_plan.add_result
public function add_result($result) { if (!is_array($result)) { throw new coding_exception('Associative array is expected as a parameter of add_result()'); } $this->results = array_merge($this->results, $result); }
php
public function add_result($result) { if (!is_array($result)) { throw new coding_exception('Associative array is expected as a parameter of add_result()'); } $this->results = array_merge($this->results, $result); }
[ "public", "function", "add_result", "(", "$", "result", ")", "{", "if", "(", "!", "is_array", "(", "$", "result", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Associative array is expected as a parameter of add_result()'", ")", ";", "}", "$", "this", "->", "results", "=", "array_merge", "(", "$", "this", "->", "results", ",", "$", "result", ")", ";", "}" ]
Add the passed info to the plan results At the moment we expect an associative array structure to be merged into the current results. In the future, some sort of base_result class may be introduced. @param array $result associative array describing a result of a task/step
[ "Add", "the", "passed", "info", "to", "the", "plan", "results" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/plan/base_plan.class.php#L91-L96
216,777
moodle/moodle
files/classes/converter.php
converter.get_enabled_plugins
protected function get_enabled_plugins() { $plugins = \core\plugininfo\fileconverter::get_enabled_plugins(); $pluginclasses = []; foreach ($plugins as $plugin) { $pluginclasses[$plugin] = \core\plugininfo\fileconverter::get_classname($plugin); } return $pluginclasses; }
php
protected function get_enabled_plugins() { $plugins = \core\plugininfo\fileconverter::get_enabled_plugins(); $pluginclasses = []; foreach ($plugins as $plugin) { $pluginclasses[$plugin] = \core\plugininfo\fileconverter::get_classname($plugin); } return $pluginclasses; }
[ "protected", "function", "get_enabled_plugins", "(", ")", "{", "$", "plugins", "=", "\\", "core", "\\", "plugininfo", "\\", "fileconverter", "::", "get_enabled_plugins", "(", ")", ";", "$", "pluginclasses", "=", "[", "]", ";", "foreach", "(", "$", "plugins", "as", "$", "plugin", ")", "{", "$", "pluginclasses", "[", "$", "plugin", "]", "=", "\\", "core", "\\", "plugininfo", "\\", "fileconverter", "::", "get_classname", "(", "$", "plugin", ")", ";", "}", "return", "$", "pluginclasses", ";", "}" ]
Get a list of enabled plugins and classes. @return array List of enabled plugins
[ "Get", "a", "list", "of", "enabled", "plugins", "and", "classes", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/files/classes/converter.php#L44-L53
216,778
moodle/moodle
files/classes/converter.php
converter.start_conversion
public function start_conversion(stored_file $file, $format, $forcerefresh = false) { $conversions = conversion::get_conversions_for_file($file, $format); if ($forcerefresh || count($conversions) > 1) { while ($conversion = array_shift($conversions)) { if ($conversion->get('id')) { $conversion->delete(); } } } if (empty($conversions)) { $conversion = new conversion(0, (object) [ 'sourcefileid' => $file->get_id(), 'targetformat' => $format, ]); $conversion->create(); } else { $conversion = array_shift($conversions); } if ($conversion->get('status') !== conversion::STATUS_COMPLETE) { $this->poll_conversion($conversion); } return $conversion; }
php
public function start_conversion(stored_file $file, $format, $forcerefresh = false) { $conversions = conversion::get_conversions_for_file($file, $format); if ($forcerefresh || count($conversions) > 1) { while ($conversion = array_shift($conversions)) { if ($conversion->get('id')) { $conversion->delete(); } } } if (empty($conversions)) { $conversion = new conversion(0, (object) [ 'sourcefileid' => $file->get_id(), 'targetformat' => $format, ]); $conversion->create(); } else { $conversion = array_shift($conversions); } if ($conversion->get('status') !== conversion::STATUS_COMPLETE) { $this->poll_conversion($conversion); } return $conversion; }
[ "public", "function", "start_conversion", "(", "stored_file", "$", "file", ",", "$", "format", ",", "$", "forcerefresh", "=", "false", ")", "{", "$", "conversions", "=", "conversion", "::", "get_conversions_for_file", "(", "$", "file", ",", "$", "format", ")", ";", "if", "(", "$", "forcerefresh", "||", "count", "(", "$", "conversions", ")", ">", "1", ")", "{", "while", "(", "$", "conversion", "=", "array_shift", "(", "$", "conversions", ")", ")", "{", "if", "(", "$", "conversion", "->", "get", "(", "'id'", ")", ")", "{", "$", "conversion", "->", "delete", "(", ")", ";", "}", "}", "}", "if", "(", "empty", "(", "$", "conversions", ")", ")", "{", "$", "conversion", "=", "new", "conversion", "(", "0", ",", "(", "object", ")", "[", "'sourcefileid'", "=>", "$", "file", "->", "get_id", "(", ")", ",", "'targetformat'", "=>", "$", "format", ",", "]", ")", ";", "$", "conversion", "->", "create", "(", ")", ";", "}", "else", "{", "$", "conversion", "=", "array_shift", "(", "$", "conversions", ")", ";", "}", "if", "(", "$", "conversion", "->", "get", "(", "'status'", ")", "!==", "conversion", "::", "STATUS_COMPLETE", ")", "{", "$", "this", "->", "poll_conversion", "(", "$", "conversion", ")", ";", "}", "return", "$", "conversion", ";", "}" ]
Start the conversion for a stored_file into a new format. @param stored_file $file The file to convert @param string $format The desired target file format (file extension) @param boolean $forcerefresh If true, the file will be converted every time (not cached). @return conversion conversion object
[ "Start", "the", "conversion", "for", "a", "stored_file", "into", "a", "new", "format", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/files/classes/converter.php#L74-L100
216,779
moodle/moodle
files/classes/converter.php
converter.poll_conversion
public function poll_conversion(conversion $conversion) { $format = $conversion->get('targetformat'); $file = $conversion->get_sourcefile(); if ($conversion->get('status') == conversion::STATUS_IN_PROGRESS) { // The current conversion is in progress. // Check for updates. if ($instance = $conversion->get_converter_instance()) { $instance->poll_conversion_status($conversion); } else { // Unable to fetch the converter instance. // Reset the status back to PENDING so that it may be picked up again. $conversion->set('status', conversion::STATUS_PENDING); } $conversion->update(); } // Refresh the status. $status = $conversion->get('status'); if ($status === conversion::STATUS_PENDING || $status === conversion::STATUS_FAILED) { // The current status is either pending or failed. // Attempt to pick up a new converter and convert the document. $from = pathinfo($file->get_filename(), PATHINFO_EXTENSION); $converters = $this->get_document_converter_classes($from, $format); $currentconverter = $this->get_next_converter($converters, $conversion->get('converter')); if (!$currentconverter) { // No more converters available. $conversion->set('status', conversion::STATUS_FAILED); $conversion->update(); return $this; } do { $conversion ->set('converter', $currentconverter) ->set('status', conversion::STATUS_IN_PROGRESS) ->update(); $instance = $conversion->get_converter_instance(); $instance->start_document_conversion($conversion); $failed = $conversion->get('status') === conversion::STATUS_FAILED; $currentconverter = $this->get_next_converter($converters, $currentconverter); } while ($failed && $currentconverter); $conversion->update(); } return $this; }
php
public function poll_conversion(conversion $conversion) { $format = $conversion->get('targetformat'); $file = $conversion->get_sourcefile(); if ($conversion->get('status') == conversion::STATUS_IN_PROGRESS) { // The current conversion is in progress. // Check for updates. if ($instance = $conversion->get_converter_instance()) { $instance->poll_conversion_status($conversion); } else { // Unable to fetch the converter instance. // Reset the status back to PENDING so that it may be picked up again. $conversion->set('status', conversion::STATUS_PENDING); } $conversion->update(); } // Refresh the status. $status = $conversion->get('status'); if ($status === conversion::STATUS_PENDING || $status === conversion::STATUS_FAILED) { // The current status is either pending or failed. // Attempt to pick up a new converter and convert the document. $from = pathinfo($file->get_filename(), PATHINFO_EXTENSION); $converters = $this->get_document_converter_classes($from, $format); $currentconverter = $this->get_next_converter($converters, $conversion->get('converter')); if (!$currentconverter) { // No more converters available. $conversion->set('status', conversion::STATUS_FAILED); $conversion->update(); return $this; } do { $conversion ->set('converter', $currentconverter) ->set('status', conversion::STATUS_IN_PROGRESS) ->update(); $instance = $conversion->get_converter_instance(); $instance->start_document_conversion($conversion); $failed = $conversion->get('status') === conversion::STATUS_FAILED; $currentconverter = $this->get_next_converter($converters, $currentconverter); } while ($failed && $currentconverter); $conversion->update(); } return $this; }
[ "public", "function", "poll_conversion", "(", "conversion", "$", "conversion", ")", "{", "$", "format", "=", "$", "conversion", "->", "get", "(", "'targetformat'", ")", ";", "$", "file", "=", "$", "conversion", "->", "get_sourcefile", "(", ")", ";", "if", "(", "$", "conversion", "->", "get", "(", "'status'", ")", "==", "conversion", "::", "STATUS_IN_PROGRESS", ")", "{", "// The current conversion is in progress.", "// Check for updates.", "if", "(", "$", "instance", "=", "$", "conversion", "->", "get_converter_instance", "(", ")", ")", "{", "$", "instance", "->", "poll_conversion_status", "(", "$", "conversion", ")", ";", "}", "else", "{", "// Unable to fetch the converter instance.", "// Reset the status back to PENDING so that it may be picked up again.", "$", "conversion", "->", "set", "(", "'status'", ",", "conversion", "::", "STATUS_PENDING", ")", ";", "}", "$", "conversion", "->", "update", "(", ")", ";", "}", "// Refresh the status.", "$", "status", "=", "$", "conversion", "->", "get", "(", "'status'", ")", ";", "if", "(", "$", "status", "===", "conversion", "::", "STATUS_PENDING", "||", "$", "status", "===", "conversion", "::", "STATUS_FAILED", ")", "{", "// The current status is either pending or failed.", "// Attempt to pick up a new converter and convert the document.", "$", "from", "=", "pathinfo", "(", "$", "file", "->", "get_filename", "(", ")", ",", "PATHINFO_EXTENSION", ")", ";", "$", "converters", "=", "$", "this", "->", "get_document_converter_classes", "(", "$", "from", ",", "$", "format", ")", ";", "$", "currentconverter", "=", "$", "this", "->", "get_next_converter", "(", "$", "converters", ",", "$", "conversion", "->", "get", "(", "'converter'", ")", ")", ";", "if", "(", "!", "$", "currentconverter", ")", "{", "// No more converters available.", "$", "conversion", "->", "set", "(", "'status'", ",", "conversion", "::", "STATUS_FAILED", ")", ";", "$", "conversion", "->", "update", "(", ")", ";", "return", "$", "this", ";", "}", "do", "{", "$", "conversion", "->", "set", "(", "'converter'", ",", "$", "currentconverter", ")", "->", "set", "(", "'status'", ",", "conversion", "::", "STATUS_IN_PROGRESS", ")", "->", "update", "(", ")", ";", "$", "instance", "=", "$", "conversion", "->", "get_converter_instance", "(", ")", ";", "$", "instance", "->", "start_document_conversion", "(", "$", "conversion", ")", ";", "$", "failed", "=", "$", "conversion", "->", "get", "(", "'status'", ")", "===", "conversion", "::", "STATUS_FAILED", ";", "$", "currentconverter", "=", "$", "this", "->", "get_next_converter", "(", "$", "converters", ",", "$", "currentconverter", ")", ";", "}", "while", "(", "$", "failed", "&&", "$", "currentconverter", ")", ";", "$", "conversion", "->", "update", "(", ")", ";", "}", "return", "$", "this", ";", "}" ]
Poll for updates to the supplied conversion. @param conversion $conversion The conversion in progress @return $this
[ "Poll", "for", "updates", "to", "the", "supplied", "conversion", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/files/classes/converter.php#L108-L157
216,780
moodle/moodle
files/classes/converter.php
converter.get_next_converter
protected function get_next_converter($converters, $currentconverter = null) { if ($currentconverter) { $keys = array_keys($converters, $currentconverter); $key = $keys[0]; if (isset($converters[$key + 1])) { return $converters[$key + 1]; } else { return false; } } else if (!empty($converters)) { return $converters[0]; } else { return false; } }
php
protected function get_next_converter($converters, $currentconverter = null) { if ($currentconverter) { $keys = array_keys($converters, $currentconverter); $key = $keys[0]; if (isset($converters[$key + 1])) { return $converters[$key + 1]; } else { return false; } } else if (!empty($converters)) { return $converters[0]; } else { return false; } }
[ "protected", "function", "get_next_converter", "(", "$", "converters", ",", "$", "currentconverter", "=", "null", ")", "{", "if", "(", "$", "currentconverter", ")", "{", "$", "keys", "=", "array_keys", "(", "$", "converters", ",", "$", "currentconverter", ")", ";", "$", "key", "=", "$", "keys", "[", "0", "]", ";", "if", "(", "isset", "(", "$", "converters", "[", "$", "key", "+", "1", "]", ")", ")", "{", "return", "$", "converters", "[", "$", "key", "+", "1", "]", ";", "}", "else", "{", "return", "false", ";", "}", "}", "else", "if", "(", "!", "empty", "(", "$", "converters", ")", ")", "{", "return", "$", "converters", "[", "0", "]", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Fetch the next converter to try. @param array $converters The list of converters to try @param string|null $currentconverter The converter currently in use @return string|false Name of next converter if present
[ "Fetch", "the", "next", "converter", "to", "try", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/files/classes/converter.php#L166-L180
216,781
moodle/moodle
files/classes/converter.php
converter.get_document_converter_classes
protected function get_document_converter_classes($from, $to) { $classes = []; $converters = $this->get_enabled_plugins(); foreach ($converters as $plugin => $classname) { if (!class_exists($classname)) { continue; } if (!$classname::are_requirements_met()) { continue; } if ($classname::supports($from, $to)) { $classes[] = $classname; } } return $classes; }
php
protected function get_document_converter_classes($from, $to) { $classes = []; $converters = $this->get_enabled_plugins(); foreach ($converters as $plugin => $classname) { if (!class_exists($classname)) { continue; } if (!$classname::are_requirements_met()) { continue; } if ($classname::supports($from, $to)) { $classes[] = $classname; } } return $classes; }
[ "protected", "function", "get_document_converter_classes", "(", "$", "from", ",", "$", "to", ")", "{", "$", "classes", "=", "[", "]", ";", "$", "converters", "=", "$", "this", "->", "get_enabled_plugins", "(", ")", ";", "foreach", "(", "$", "converters", "as", "$", "plugin", "=>", "$", "classname", ")", "{", "if", "(", "!", "class_exists", "(", "$", "classname", ")", ")", "{", "continue", ";", "}", "if", "(", "!", "$", "classname", "::", "are_requirements_met", "(", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "classname", "::", "supports", "(", "$", "from", ",", "$", "to", ")", ")", "{", "$", "classes", "[", "]", "=", "$", "classname", ";", "}", "}", "return", "$", "classes", ";", "}" ]
Fetch the class for the preferred document converter. @param string $from The source target file (file extension) @param string $to The desired target file format (file extension) @return string The class for document conversion
[ "Fetch", "the", "class", "for", "the", "preferred", "document", "converter", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/files/classes/converter.php#L189-L208
216,782
moodle/moodle
files/classes/converter.php
converter.can_convert_storedfile_to
public function can_convert_storedfile_to(stored_file $file, $to) { if ($file->is_directory()) { // Directories cannot be converted. return false; } if (!$file->get_filesize()) { // Empty files cannot be converted. return false; } $from = pathinfo($file->get_filename(), PATHINFO_EXTENSION); if (!$from) { // No file extension could be found. Unable to determine converter. return false; } return $this->can_convert_format_to($from, $to); }
php
public function can_convert_storedfile_to(stored_file $file, $to) { if ($file->is_directory()) { // Directories cannot be converted. return false; } if (!$file->get_filesize()) { // Empty files cannot be converted. return false; } $from = pathinfo($file->get_filename(), PATHINFO_EXTENSION); if (!$from) { // No file extension could be found. Unable to determine converter. return false; } return $this->can_convert_format_to($from, $to); }
[ "public", "function", "can_convert_storedfile_to", "(", "stored_file", "$", "file", ",", "$", "to", ")", "{", "if", "(", "$", "file", "->", "is_directory", "(", ")", ")", "{", "// Directories cannot be converted.", "return", "false", ";", "}", "if", "(", "!", "$", "file", "->", "get_filesize", "(", ")", ")", "{", "// Empty files cannot be converted.", "return", "false", ";", "}", "$", "from", "=", "pathinfo", "(", "$", "file", "->", "get_filename", "(", ")", ",", "PATHINFO_EXTENSION", ")", ";", "if", "(", "!", "$", "from", ")", "{", "// No file extension could be found. Unable to determine converter.", "return", "false", ";", "}", "return", "$", "this", "->", "can_convert_format_to", "(", "$", "from", ",", "$", "to", ")", ";", "}" ]
Check whether document conversion is supported for this file and target format. @param stored_file $file The file to convert @param string $to The desired target file format (file extension) @return bool Whether the target type can be converted
[ "Check", "whether", "document", "conversion", "is", "supported", "for", "this", "file", "and", "target", "format", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/files/classes/converter.php#L217-L235
216,783
moodle/moodle
lib/htmlpurifier/HTMLPurifier/Printer.php
HTMLPurifier_Printer.prepareGenerator
public function prepareGenerator($config) { $all = $config->getAll(); $context = new HTMLPurifier_Context(); $this->generator = new HTMLPurifier_Generator($config, $context); }
php
public function prepareGenerator($config) { $all = $config->getAll(); $context = new HTMLPurifier_Context(); $this->generator = new HTMLPurifier_Generator($config, $context); }
[ "public", "function", "prepareGenerator", "(", "$", "config", ")", "{", "$", "all", "=", "$", "config", "->", "getAll", "(", ")", ";", "$", "context", "=", "new", "HTMLPurifier_Context", "(", ")", ";", "$", "this", "->", "generator", "=", "new", "HTMLPurifier_Generator", "(", "$", "config", ",", "$", "context", ")", ";", "}" ]
Give generator necessary configuration if possible @param HTMLPurifier_Config $config
[ "Give", "generator", "necessary", "configuration", "if", "possible" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Printer.php#L32-L37
216,784
moodle/moodle
lib/htmlpurifier/HTMLPurifier/Printer.php
HTMLPurifier_Printer.start
protected function start($tag, $attr = array()) { return $this->generator->generateFromToken( new HTMLPurifier_Token_Start($tag, $attr ? $attr : array()) ); }
php
protected function start($tag, $attr = array()) { return $this->generator->generateFromToken( new HTMLPurifier_Token_Start($tag, $attr ? $attr : array()) ); }
[ "protected", "function", "start", "(", "$", "tag", ",", "$", "attr", "=", "array", "(", ")", ")", "{", "return", "$", "this", "->", "generator", "->", "generateFromToken", "(", "new", "HTMLPurifier_Token_Start", "(", "$", "tag", ",", "$", "attr", "?", "$", "attr", ":", "array", "(", ")", ")", ")", ";", "}" ]
Returns a start tag @param string $tag Tag name @param array $attr Attribute array @return string
[ "Returns", "a", "start", "tag" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Printer.php#L51-L56
216,785
moodle/moodle
lib/htmlpurifier/HTMLPurifier/Printer.php
HTMLPurifier_Printer.element
protected function element($tag, $contents, $attr = array(), $escape = true) { return $this->start($tag, $attr) . ($escape ? $this->escape($contents) : $contents) . $this->end($tag); }
php
protected function element($tag, $contents, $attr = array(), $escape = true) { return $this->start($tag, $attr) . ($escape ? $this->escape($contents) : $contents) . $this->end($tag); }
[ "protected", "function", "element", "(", "$", "tag", ",", "$", "contents", ",", "$", "attr", "=", "array", "(", ")", ",", "$", "escape", "=", "true", ")", "{", "return", "$", "this", "->", "start", "(", "$", "tag", ",", "$", "attr", ")", ".", "(", "$", "escape", "?", "$", "this", "->", "escape", "(", "$", "contents", ")", ":", "$", "contents", ")", ".", "$", "this", "->", "end", "(", "$", "tag", ")", ";", "}" ]
Prints a complete element with content inside @param string $tag Tag name @param string $contents Element contents @param array $attr Tag attributes @param bool $escape whether or not to escape contents @return string
[ "Prints", "a", "complete", "element", "with", "content", "inside" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Printer.php#L78-L83
216,786
moodle/moodle
lib/htmlpurifier/HTMLPurifier/Printer.php
HTMLPurifier_Printer.escape
protected function escape($string) { $string = HTMLPurifier_Encoder::cleanUTF8($string); $string = htmlspecialchars($string, ENT_COMPAT, 'UTF-8'); return $string; }
php
protected function escape($string) { $string = HTMLPurifier_Encoder::cleanUTF8($string); $string = htmlspecialchars($string, ENT_COMPAT, 'UTF-8'); return $string; }
[ "protected", "function", "escape", "(", "$", "string", ")", "{", "$", "string", "=", "HTMLPurifier_Encoder", "::", "cleanUTF8", "(", "$", "string", ")", ";", "$", "string", "=", "htmlspecialchars", "(", "$", "string", ",", "ENT_COMPAT", ",", "'UTF-8'", ")", ";", "return", "$", "string", ";", "}" ]
Escapes a string for HTML output. @param string $string String to escape @return string
[ "Escapes", "a", "string", "for", "HTML", "output", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Printer.php#L131-L136
216,787
moodle/moodle
lib/htmlpurifier/HTMLPurifier/Printer.php
HTMLPurifier_Printer.listify
protected function listify($array, $polite = false) { if (empty($array)) { return 'None'; } $ret = ''; $i = count($array); foreach ($array as $value) { $i--; $ret .= $value; if ($i > 0 && !($polite && $i == 1)) { $ret .= ', '; } if ($polite && $i == 1) { $ret .= 'and '; } } return $ret; }
php
protected function listify($array, $polite = false) { if (empty($array)) { return 'None'; } $ret = ''; $i = count($array); foreach ($array as $value) { $i--; $ret .= $value; if ($i > 0 && !($polite && $i == 1)) { $ret .= ', '; } if ($polite && $i == 1) { $ret .= 'and '; } } return $ret; }
[ "protected", "function", "listify", "(", "$", "array", ",", "$", "polite", "=", "false", ")", "{", "if", "(", "empty", "(", "$", "array", ")", ")", "{", "return", "'None'", ";", "}", "$", "ret", "=", "''", ";", "$", "i", "=", "count", "(", "$", "array", ")", ";", "foreach", "(", "$", "array", "as", "$", "value", ")", "{", "$", "i", "--", ";", "$", "ret", ".=", "$", "value", ";", "if", "(", "$", "i", ">", "0", "&&", "!", "(", "$", "polite", "&&", "$", "i", "==", "1", ")", ")", "{", "$", "ret", ".=", "', '", ";", "}", "if", "(", "$", "polite", "&&", "$", "i", "==", "1", ")", "{", "$", "ret", ".=", "'and '", ";", "}", "}", "return", "$", "ret", ";", "}" ]
Takes a list of strings and turns them into a single list @param string[] $array List of strings @param bool $polite Bool whether or not to add an end before the last @return string
[ "Takes", "a", "list", "of", "strings", "and", "turns", "them", "into", "a", "single", "list" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Printer.php#L144-L162
216,788
moodle/moodle
lib/htmlpurifier/HTMLPurifier/Printer.php
HTMLPurifier_Printer.getClass
protected function getClass($obj, $sec_prefix = '') { static $five = null; if ($five === null) { $five = version_compare(PHP_VERSION, '5', '>='); } $prefix = 'HTMLPurifier_' . $sec_prefix; if (!$five) { $prefix = strtolower($prefix); } $class = str_replace($prefix, '', get_class($obj)); $lclass = strtolower($class); $class .= '('; switch ($lclass) { case 'enum': $values = array(); foreach ($obj->valid_values as $value => $bool) { $values[] = $value; } $class .= implode(', ', $values); break; case 'css_composite': $values = array(); foreach ($obj->defs as $def) { $values[] = $this->getClass($def, $sec_prefix); } $class .= implode(', ', $values); break; case 'css_multiple': $class .= $this->getClass($obj->single, $sec_prefix) . ', '; $class .= $obj->max; break; case 'css_denyelementdecorator': $class .= $this->getClass($obj->def, $sec_prefix) . ', '; $class .= $obj->element; break; case 'css_importantdecorator': $class .= $this->getClass($obj->def, $sec_prefix); if ($obj->allow) { $class .= ', !important'; } break; } $class .= ')'; return $class; }
php
protected function getClass($obj, $sec_prefix = '') { static $five = null; if ($five === null) { $five = version_compare(PHP_VERSION, '5', '>='); } $prefix = 'HTMLPurifier_' . $sec_prefix; if (!$five) { $prefix = strtolower($prefix); } $class = str_replace($prefix, '', get_class($obj)); $lclass = strtolower($class); $class .= '('; switch ($lclass) { case 'enum': $values = array(); foreach ($obj->valid_values as $value => $bool) { $values[] = $value; } $class .= implode(', ', $values); break; case 'css_composite': $values = array(); foreach ($obj->defs as $def) { $values[] = $this->getClass($def, $sec_prefix); } $class .= implode(', ', $values); break; case 'css_multiple': $class .= $this->getClass($obj->single, $sec_prefix) . ', '; $class .= $obj->max; break; case 'css_denyelementdecorator': $class .= $this->getClass($obj->def, $sec_prefix) . ', '; $class .= $obj->element; break; case 'css_importantdecorator': $class .= $this->getClass($obj->def, $sec_prefix); if ($obj->allow) { $class .= ', !important'; } break; } $class .= ')'; return $class; }
[ "protected", "function", "getClass", "(", "$", "obj", ",", "$", "sec_prefix", "=", "''", ")", "{", "static", "$", "five", "=", "null", ";", "if", "(", "$", "five", "===", "null", ")", "{", "$", "five", "=", "version_compare", "(", "PHP_VERSION", ",", "'5'", ",", "'>='", ")", ";", "}", "$", "prefix", "=", "'HTMLPurifier_'", ".", "$", "sec_prefix", ";", "if", "(", "!", "$", "five", ")", "{", "$", "prefix", "=", "strtolower", "(", "$", "prefix", ")", ";", "}", "$", "class", "=", "str_replace", "(", "$", "prefix", ",", "''", ",", "get_class", "(", "$", "obj", ")", ")", ";", "$", "lclass", "=", "strtolower", "(", "$", "class", ")", ";", "$", "class", ".=", "'('", ";", "switch", "(", "$", "lclass", ")", "{", "case", "'enum'", ":", "$", "values", "=", "array", "(", ")", ";", "foreach", "(", "$", "obj", "->", "valid_values", "as", "$", "value", "=>", "$", "bool", ")", "{", "$", "values", "[", "]", "=", "$", "value", ";", "}", "$", "class", ".=", "implode", "(", "', '", ",", "$", "values", ")", ";", "break", ";", "case", "'css_composite'", ":", "$", "values", "=", "array", "(", ")", ";", "foreach", "(", "$", "obj", "->", "defs", "as", "$", "def", ")", "{", "$", "values", "[", "]", "=", "$", "this", "->", "getClass", "(", "$", "def", ",", "$", "sec_prefix", ")", ";", "}", "$", "class", ".=", "implode", "(", "', '", ",", "$", "values", ")", ";", "break", ";", "case", "'css_multiple'", ":", "$", "class", ".=", "$", "this", "->", "getClass", "(", "$", "obj", "->", "single", ",", "$", "sec_prefix", ")", ".", "', '", ";", "$", "class", ".=", "$", "obj", "->", "max", ";", "break", ";", "case", "'css_denyelementdecorator'", ":", "$", "class", ".=", "$", "this", "->", "getClass", "(", "$", "obj", "->", "def", ",", "$", "sec_prefix", ")", ".", "', '", ";", "$", "class", ".=", "$", "obj", "->", "element", ";", "break", ";", "case", "'css_importantdecorator'", ":", "$", "class", ".=", "$", "this", "->", "getClass", "(", "$", "obj", "->", "def", ",", "$", "sec_prefix", ")", ";", "if", "(", "$", "obj", "->", "allow", ")", "{", "$", "class", ".=", "', !important'", ";", "}", "break", ";", "}", "$", "class", ".=", "')'", ";", "return", "$", "class", ";", "}" ]
Retrieves the class of an object without prefixes, as well as metadata @param object $obj Object to determine class of @param string $sec_prefix Further prefix to remove @return string
[ "Retrieves", "the", "class", "of", "an", "object", "without", "prefixes", "as", "well", "as", "metadata" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Printer.php#L170-L215
216,789
moodle/moodle
backup/util/ui/restore_ui_components.php
restore_search_base.get_url
final public function get_url() { global $PAGE; $params = array( $this->get_varsearch() => $this->get_search() ); return ($this->url !== null) ? new moodle_url($this->url, $params) : new moodle_url($PAGE->url, $params); }
php
final public function get_url() { global $PAGE; $params = array( $this->get_varsearch() => $this->get_search() ); return ($this->url !== null) ? new moodle_url($this->url, $params) : new moodle_url($PAGE->url, $params); }
[ "final", "public", "function", "get_url", "(", ")", "{", "global", "$", "PAGE", ";", "$", "params", "=", "array", "(", "$", "this", "->", "get_varsearch", "(", ")", "=>", "$", "this", "->", "get_search", "(", ")", ")", ";", "return", "(", "$", "this", "->", "url", "!==", "null", ")", "?", "new", "moodle_url", "(", "$", "this", "->", "url", ",", "$", "params", ")", ":", "new", "moodle_url", "(", "$", "PAGE", "->", "url", ",", "$", "params", ")", ";", "}" ]
The URL for this search @global moodle_page $PAGE @return moodle_url The URL for this page
[ "The", "URL", "for", "this", "search" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/restore_ui_components.php#L103-L109
216,790
moodle/moodle
backup/util/ui/restore_ui_components.php
restore_search_base.require_capability
final public function require_capability($capability, $user = null) { if (!is_int($user)) { $user = null; } $this->requiredcapabilities[] = array( 'capability' => $capability, 'user' => $user ); }
php
final public function require_capability($capability, $user = null) { if (!is_int($user)) { $user = null; } $this->requiredcapabilities[] = array( 'capability' => $capability, 'user' => $user ); }
[ "final", "public", "function", "require_capability", "(", "$", "capability", ",", "$", "user", "=", "null", ")", "{", "if", "(", "!", "is_int", "(", "$", "user", ")", ")", "{", "$", "user", "=", "null", ";", "}", "$", "this", "->", "requiredcapabilities", "[", "]", "=", "array", "(", "'capability'", "=>", "$", "capability", ",", "'user'", "=>", "$", "user", ")", ";", "}" ]
Adds a required capability which all results will be checked against @param string $capability @param int|null $user
[ "Adds", "a", "required", "capability", "which", "all", "results", "will", "be", "checked", "against" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/restore_ui_components.php#L162-L170
216,791
moodle/moodle
backup/util/ui/restore_ui_components.php
restore_course_search.get_searchsql
protected function get_searchsql() { global $DB; $ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx'); $ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)"; $params = array( 'contextlevel' => CONTEXT_COURSE, 'fullnamesearch' => '%'.$this->get_search().'%', 'shortnamesearch' => '%'.$this->get_search().'%' ); $select = " SELECT c.id, c.fullname, c.shortname, c.visible, c.sortorder "; $from = " FROM {course} c "; $where = " WHERE (".$DB->sql_like('c.fullname', ':fullnamesearch', false)." OR ". $DB->sql_like('c.shortname', ':shortnamesearch', false).")"; $orderby = " ORDER BY c.sortorder"; if ($this->currentcourseid !== null && !$this->includecurrentcourse) { $where .= " AND c.id <> :currentcourseid"; $params['currentcourseid'] = $this->currentcourseid; } return array($select.$ctxselect.$from.$ctxjoin.$where.$orderby, $params); }
php
protected function get_searchsql() { global $DB; $ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx'); $ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)"; $params = array( 'contextlevel' => CONTEXT_COURSE, 'fullnamesearch' => '%'.$this->get_search().'%', 'shortnamesearch' => '%'.$this->get_search().'%' ); $select = " SELECT c.id, c.fullname, c.shortname, c.visible, c.sortorder "; $from = " FROM {course} c "; $where = " WHERE (".$DB->sql_like('c.fullname', ':fullnamesearch', false)." OR ". $DB->sql_like('c.shortname', ':shortnamesearch', false).")"; $orderby = " ORDER BY c.sortorder"; if ($this->currentcourseid !== null && !$this->includecurrentcourse) { $where .= " AND c.id <> :currentcourseid"; $params['currentcourseid'] = $this->currentcourseid; } return array($select.$ctxselect.$from.$ctxjoin.$where.$orderby, $params); }
[ "protected", "function", "get_searchsql", "(", ")", "{", "global", "$", "DB", ";", "$", "ctxselect", "=", "', '", ".", "context_helper", "::", "get_preload_record_columns_sql", "(", "'ctx'", ")", ";", "$", "ctxjoin", "=", "\"LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)\"", ";", "$", "params", "=", "array", "(", "'contextlevel'", "=>", "CONTEXT_COURSE", ",", "'fullnamesearch'", "=>", "'%'", ".", "$", "this", "->", "get_search", "(", ")", ".", "'%'", ",", "'shortnamesearch'", "=>", "'%'", ".", "$", "this", "->", "get_search", "(", ")", ".", "'%'", ")", ";", "$", "select", "=", "\" SELECT c.id, c.fullname, c.shortname, c.visible, c.sortorder \"", ";", "$", "from", "=", "\" FROM {course} c \"", ";", "$", "where", "=", "\" WHERE (\"", ".", "$", "DB", "->", "sql_like", "(", "'c.fullname'", ",", "':fullnamesearch'", ",", "false", ")", ".", "\" OR \"", ".", "$", "DB", "->", "sql_like", "(", "'c.shortname'", ",", "':shortnamesearch'", ",", "false", ")", ".", "\")\"", ";", "$", "orderby", "=", "\" ORDER BY c.sortorder\"", ";", "if", "(", "$", "this", "->", "currentcourseid", "!==", "null", "&&", "!", "$", "this", "->", "includecurrentcourse", ")", "{", "$", "where", ".=", "\" AND c.id <> :currentcourseid\"", ";", "$", "params", "[", "'currentcourseid'", "]", "=", "$", "this", "->", "currentcourseid", ";", "}", "return", "array", "(", "$", "select", ".", "$", "ctxselect", ".", "$", "from", ".", "$", "ctxjoin", ".", "$", "where", ".", "$", "orderby", ",", "$", "params", ")", ";", "}" ]
Get the search SQL. @global moodle_database $DB @return array
[ "Get", "the", "search", "SQL", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/restore_ui_components.php#L313-L336
216,792
moodle/moodle
backup/util/ui/restore_ui_components.php
restore_category_search.get_searchsql
protected function get_searchsql() { global $DB; $ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx'); $ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)"; $params = array( 'contextlevel' => CONTEXT_COURSECAT, 'namesearch' => '%'.$this->get_search().'%', ); $select = " SELECT c.id, c.name, c.visible, c.sortorder, c.description, c.descriptionformat "; $from = " FROM {course_categories} c "; $where = " WHERE ".$DB->sql_like('c.name', ':namesearch', false); $orderby = " ORDER BY c.sortorder"; return array($select.$ctxselect.$from.$ctxjoin.$where.$orderby, $params); }
php
protected function get_searchsql() { global $DB; $ctxselect = ', ' . context_helper::get_preload_record_columns_sql('ctx'); $ctxjoin = "LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)"; $params = array( 'contextlevel' => CONTEXT_COURSECAT, 'namesearch' => '%'.$this->get_search().'%', ); $select = " SELECT c.id, c.name, c.visible, c.sortorder, c.description, c.descriptionformat "; $from = " FROM {course_categories} c "; $where = " WHERE ".$DB->sql_like('c.name', ':namesearch', false); $orderby = " ORDER BY c.sortorder"; return array($select.$ctxselect.$from.$ctxjoin.$where.$orderby, $params); }
[ "protected", "function", "get_searchsql", "(", ")", "{", "global", "$", "DB", ";", "$", "ctxselect", "=", "', '", ".", "context_helper", "::", "get_preload_record_columns_sql", "(", "'ctx'", ")", ";", "$", "ctxjoin", "=", "\"LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)\"", ";", "$", "params", "=", "array", "(", "'contextlevel'", "=>", "CONTEXT_COURSECAT", ",", "'namesearch'", "=>", "'%'", ".", "$", "this", "->", "get_search", "(", ")", ".", "'%'", ",", ")", ";", "$", "select", "=", "\" SELECT c.id, c.name, c.visible, c.sortorder, c.description, c.descriptionformat \"", ";", "$", "from", "=", "\" FROM {course_categories} c \"", ";", "$", "where", "=", "\" WHERE \"", ".", "$", "DB", "->", "sql_like", "(", "'c.name'", ",", "':namesearch'", ",", "false", ")", ";", "$", "orderby", "=", "\" ORDER BY c.sortorder\"", ";", "return", "array", "(", "$", "select", ".", "$", "ctxselect", ".", "$", "from", ".", "$", "ctxjoin", ".", "$", "where", ".", "$", "orderby", ",", "$", "params", ")", ";", "}" ]
Returns the search SQL. @global moodle_database $DB @return array
[ "Returns", "the", "search", "SQL", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/restore_ui_components.php#L395-L411
216,793
moodle/moodle
mod/assign/adminlib.php
assign_admin_page_manage_assign_plugins.search
public function search($query) { if ($result = parent::search($query)) { return $result; } $found = false; foreach (core_component::get_plugin_list($this->subtype) as $name => $notused) { if (strpos(core_text::strtolower(get_string('pluginname', $this->subtype . '_' . $name)), $query) !== false) { $found = true; break; } } if ($found) { $result = new stdClass(); $result->page = $this; $result->settings = array(); return array($this->name => $result); } else { return array(); } }
php
public function search($query) { if ($result = parent::search($query)) { return $result; } $found = false; foreach (core_component::get_plugin_list($this->subtype) as $name => $notused) { if (strpos(core_text::strtolower(get_string('pluginname', $this->subtype . '_' . $name)), $query) !== false) { $found = true; break; } } if ($found) { $result = new stdClass(); $result->page = $this; $result->settings = array(); return array($this->name => $result); } else { return array(); } }
[ "public", "function", "search", "(", "$", "query", ")", "{", "if", "(", "$", "result", "=", "parent", "::", "search", "(", "$", "query", ")", ")", "{", "return", "$", "result", ";", "}", "$", "found", "=", "false", ";", "foreach", "(", "core_component", "::", "get_plugin_list", "(", "$", "this", "->", "subtype", ")", "as", "$", "name", "=>", "$", "notused", ")", "{", "if", "(", "strpos", "(", "core_text", "::", "strtolower", "(", "get_string", "(", "'pluginname'", ",", "$", "this", "->", "subtype", ".", "'_'", ".", "$", "name", ")", ")", ",", "$", "query", ")", "!==", "false", ")", "{", "$", "found", "=", "true", ";", "break", ";", "}", "}", "if", "(", "$", "found", ")", "{", "$", "result", "=", "new", "stdClass", "(", ")", ";", "$", "result", "->", "page", "=", "$", "this", ";", "$", "result", "->", "settings", "=", "array", "(", ")", ";", "return", "array", "(", "$", "this", "->", "name", "=>", "$", "result", ")", ";", "}", "else", "{", "return", "array", "(", ")", ";", "}", "}" ]
Search plugins for the specified string @param string $query The string to search for @return array
[ "Search", "plugins", "for", "the", "specified", "string" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/adminlib.php#L60-L82
216,794
moodle/moodle
mod/assign/adminlib.php
assign_plugin_manager.get_sorted_plugins_list
public function get_sorted_plugins_list() { $names = core_component::get_plugin_list($this->subtype); $result = array(); foreach ($names as $name => $path) { $idx = get_config($this->subtype . '_' . $name, 'sortorder'); if (!$idx) { $idx = 0; } while (array_key_exists($idx, $result)) { $idx +=1; } $result[$idx] = $name; } ksort($result); return $result; }
php
public function get_sorted_plugins_list() { $names = core_component::get_plugin_list($this->subtype); $result = array(); foreach ($names as $name => $path) { $idx = get_config($this->subtype . '_' . $name, 'sortorder'); if (!$idx) { $idx = 0; } while (array_key_exists($idx, $result)) { $idx +=1; } $result[$idx] = $name; } ksort($result); return $result; }
[ "public", "function", "get_sorted_plugins_list", "(", ")", "{", "$", "names", "=", "core_component", "::", "get_plugin_list", "(", "$", "this", "->", "subtype", ")", ";", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "names", "as", "$", "name", "=>", "$", "path", ")", "{", "$", "idx", "=", "get_config", "(", "$", "this", "->", "subtype", ".", "'_'", ".", "$", "name", ",", "'sortorder'", ")", ";", "if", "(", "!", "$", "idx", ")", "{", "$", "idx", "=", "0", ";", "}", "while", "(", "array_key_exists", "(", "$", "idx", ",", "$", "result", ")", ")", "{", "$", "idx", "+=", "1", ";", "}", "$", "result", "[", "$", "idx", "]", "=", "$", "name", ";", "}", "ksort", "(", "$", "result", ")", ";", "return", "$", "result", ";", "}" ]
Return a list of plugins sorted by the order defined in the admin interface @return array The list of plugins
[ "Return", "a", "list", "of", "plugins", "sorted", "by", "the", "order", "defined", "in", "the", "admin", "interface" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/adminlib.php#L117-L135
216,795
moodle/moodle
mod/assign/adminlib.php
assign_plugin_manager.format_icon_link
private function format_icon_link($action, $plugin, $icon, $alt) { global $OUTPUT; $url = $this->pageurl; if ($action === 'delete') { $url = core_plugin_manager::instance()->get_uninstall_url($this->subtype.'_'.$plugin, 'manage'); if (!$url) { return '&nbsp;'; } return html_writer::link($url, get_string('uninstallplugin', 'core_admin')); } return $OUTPUT->action_icon(new moodle_url($url, array('action' => $action, 'plugin'=> $plugin, 'sesskey' => sesskey())), new pix_icon($icon, $alt, 'moodle', array('title' => $alt)), null, array('title' => $alt)) . ' '; }
php
private function format_icon_link($action, $plugin, $icon, $alt) { global $OUTPUT; $url = $this->pageurl; if ($action === 'delete') { $url = core_plugin_manager::instance()->get_uninstall_url($this->subtype.'_'.$plugin, 'manage'); if (!$url) { return '&nbsp;'; } return html_writer::link($url, get_string('uninstallplugin', 'core_admin')); } return $OUTPUT->action_icon(new moodle_url($url, array('action' => $action, 'plugin'=> $plugin, 'sesskey' => sesskey())), new pix_icon($icon, $alt, 'moodle', array('title' => $alt)), null, array('title' => $alt)) . ' '; }
[ "private", "function", "format_icon_link", "(", "$", "action", ",", "$", "plugin", ",", "$", "icon", ",", "$", "alt", ")", "{", "global", "$", "OUTPUT", ";", "$", "url", "=", "$", "this", "->", "pageurl", ";", "if", "(", "$", "action", "===", "'delete'", ")", "{", "$", "url", "=", "core_plugin_manager", "::", "instance", "(", ")", "->", "get_uninstall_url", "(", "$", "this", "->", "subtype", ".", "'_'", ".", "$", "plugin", ",", "'manage'", ")", ";", "if", "(", "!", "$", "url", ")", "{", "return", "'&nbsp;'", ";", "}", "return", "html_writer", "::", "link", "(", "$", "url", ",", "get_string", "(", "'uninstallplugin'", ",", "'core_admin'", ")", ")", ";", "}", "return", "$", "OUTPUT", "->", "action_icon", "(", "new", "moodle_url", "(", "$", "url", ",", "array", "(", "'action'", "=>", "$", "action", ",", "'plugin'", "=>", "$", "plugin", ",", "'sesskey'", "=>", "sesskey", "(", ")", ")", ")", ",", "new", "pix_icon", "(", "$", "icon", ",", "$", "alt", ",", "'moodle'", ",", "array", "(", "'title'", "=>", "$", "alt", ")", ")", ",", "null", ",", "array", "(", "'title'", "=>", "$", "alt", ")", ")", ".", "' '", ";", "}" ]
Util function for writing an action icon link @param string $action URL parameter to include in the link @param string $plugin URL parameter to include in the link @param string $icon The key to the icon to use (e.g. 't/up') @param string $alt The string description of the link used as the title and alt text @return string The icon/link
[ "Util", "function", "for", "writing", "an", "action", "icon", "link" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/adminlib.php#L147-L164
216,796
moodle/moodle
mod/assign/adminlib.php
assign_plugin_manager.view_header
private function view_header() { global $OUTPUT; admin_externalpage_setup('manage' . $this->subtype . 'plugins'); // Print the page heading. echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('manage' . $this->subtype . 'plugins', 'assign')); }
php
private function view_header() { global $OUTPUT; admin_externalpage_setup('manage' . $this->subtype . 'plugins'); // Print the page heading. echo $OUTPUT->header(); echo $OUTPUT->heading(get_string('manage' . $this->subtype . 'plugins', 'assign')); }
[ "private", "function", "view_header", "(", ")", "{", "global", "$", "OUTPUT", ";", "admin_externalpage_setup", "(", "'manage'", ".", "$", "this", "->", "subtype", ".", "'plugins'", ")", ";", "// Print the page heading.", "echo", "$", "OUTPUT", "->", "header", "(", ")", ";", "echo", "$", "OUTPUT", "->", "heading", "(", "get_string", "(", "'manage'", ".", "$", "this", "->", "subtype", ".", "'plugins'", ",", "'assign'", ")", ")", ";", "}" ]
Write the page header @return None
[ "Write", "the", "page", "header" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/adminlib.php#L240-L246
216,797
moodle/moodle
mod/assign/adminlib.php
assign_plugin_manager.move_plugin
public function move_plugin($plugintomove, $dir) { // Get a list of the current plugins. $plugins = $this->get_sorted_plugins_list(); $currentindex = 0; // Throw away the keys. $plugins = array_values($plugins); // Find this plugin in the list. foreach ($plugins as $key => $plugin) { if ($plugin == $plugintomove) { $currentindex = $key; break; } } // Make the switch. if ($dir == 'up') { if ($currentindex > 0) { $tempplugin = $plugins[$currentindex - 1]; $plugins[$currentindex - 1] = $plugins[$currentindex]; $plugins[$currentindex] = $tempplugin; } } else if ($dir == 'down') { if ($currentindex < (count($plugins) - 1)) { $tempplugin = $plugins[$currentindex + 1]; $plugins[$currentindex + 1] = $plugins[$currentindex]; $plugins[$currentindex] = $tempplugin; } } // Save the new normal order. foreach ($plugins as $key => $plugin) { set_config('sortorder', $key, $this->subtype . '_' . $plugin); } return 'view'; }
php
public function move_plugin($plugintomove, $dir) { // Get a list of the current plugins. $plugins = $this->get_sorted_plugins_list(); $currentindex = 0; // Throw away the keys. $plugins = array_values($plugins); // Find this plugin in the list. foreach ($plugins as $key => $plugin) { if ($plugin == $plugintomove) { $currentindex = $key; break; } } // Make the switch. if ($dir == 'up') { if ($currentindex > 0) { $tempplugin = $plugins[$currentindex - 1]; $plugins[$currentindex - 1] = $plugins[$currentindex]; $plugins[$currentindex] = $tempplugin; } } else if ($dir == 'down') { if ($currentindex < (count($plugins) - 1)) { $tempplugin = $plugins[$currentindex + 1]; $plugins[$currentindex + 1] = $plugins[$currentindex]; $plugins[$currentindex] = $tempplugin; } } // Save the new normal order. foreach ($plugins as $key => $plugin) { set_config('sortorder', $key, $this->subtype . '_' . $plugin); } return 'view'; }
[ "public", "function", "move_plugin", "(", "$", "plugintomove", ",", "$", "dir", ")", "{", "// Get a list of the current plugins.", "$", "plugins", "=", "$", "this", "->", "get_sorted_plugins_list", "(", ")", ";", "$", "currentindex", "=", "0", ";", "// Throw away the keys.", "$", "plugins", "=", "array_values", "(", "$", "plugins", ")", ";", "// Find this plugin in the list.", "foreach", "(", "$", "plugins", "as", "$", "key", "=>", "$", "plugin", ")", "{", "if", "(", "$", "plugin", "==", "$", "plugintomove", ")", "{", "$", "currentindex", "=", "$", "key", ";", "break", ";", "}", "}", "// Make the switch.", "if", "(", "$", "dir", "==", "'up'", ")", "{", "if", "(", "$", "currentindex", ">", "0", ")", "{", "$", "tempplugin", "=", "$", "plugins", "[", "$", "currentindex", "-", "1", "]", ";", "$", "plugins", "[", "$", "currentindex", "-", "1", "]", "=", "$", "plugins", "[", "$", "currentindex", "]", ";", "$", "plugins", "[", "$", "currentindex", "]", "=", "$", "tempplugin", ";", "}", "}", "else", "if", "(", "$", "dir", "==", "'down'", ")", "{", "if", "(", "$", "currentindex", "<", "(", "count", "(", "$", "plugins", ")", "-", "1", ")", ")", "{", "$", "tempplugin", "=", "$", "plugins", "[", "$", "currentindex", "+", "1", "]", ";", "$", "plugins", "[", "$", "currentindex", "+", "1", "]", "=", "$", "plugins", "[", "$", "currentindex", "]", ";", "$", "plugins", "[", "$", "currentindex", "]", "=", "$", "tempplugin", ";", "}", "}", "// Save the new normal order.", "foreach", "(", "$", "plugins", "as", "$", "key", "=>", "$", "plugin", ")", "{", "set_config", "(", "'sortorder'", ",", "$", "key", ",", "$", "this", "->", "subtype", ".", "'_'", ".", "$", "plugin", ")", ";", "}", "return", "'view'", ";", "}" ]
Change the order of this plugin. @param string $plugintomove - The plugin to move @param string $dir - up or down @return string The next page to display
[ "Change", "the", "order", "of", "this", "plugin", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/adminlib.php#L289-L326
216,798
moodle/moodle
analytics/classes/local/target/linear.php
linear.get_calculation_outcome
public function get_calculation_outcome($value, $ignoredsubtype = false) { // This is very generic, targets will probably be interested in overwriting this. $diff = static::get_max_value() - static::get_min_value(); if (($value - static::get_min_value()) / $diff >= 0.5) { return self::OUTCOME_VERY_POSITIVE; } return self::OUTCOME_VERY_NEGATIVE; }
php
public function get_calculation_outcome($value, $ignoredsubtype = false) { // This is very generic, targets will probably be interested in overwriting this. $diff = static::get_max_value() - static::get_min_value(); if (($value - static::get_min_value()) / $diff >= 0.5) { return self::OUTCOME_VERY_POSITIVE; } return self::OUTCOME_VERY_NEGATIVE; }
[ "public", "function", "get_calculation_outcome", "(", "$", "value", ",", "$", "ignoredsubtype", "=", "false", ")", "{", "// This is very generic, targets will probably be interested in overwriting this.", "$", "diff", "=", "static", "::", "get_max_value", "(", ")", "-", "static", "::", "get_min_value", "(", ")", ";", "if", "(", "(", "$", "value", "-", "static", "::", "get_min_value", "(", ")", ")", "/", "$", "diff", ">=", "0.5", ")", "{", "return", "self", "::", "OUTCOME_VERY_POSITIVE", ";", "}", "return", "self", "::", "OUTCOME_VERY_NEGATIVE", ";", "}" ]
How positive is this calculated value? @param float $value @param string $ignoredsubtype @return int
[ "How", "positive", "is", "this", "calculated", "value?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/target/linear.php#L56-L64
216,799
moodle/moodle
repository/dropbox/classes/task/cron_task.php
cron_task.execute
public function execute() { global $CFG; require_once($CFG->dirroot . '/repository/lib.php'); $instances = \repository::get_instances(['type' => 'dropbox']); foreach ($instances as $instance) { $instance->cron(); } }
php
public function execute() { global $CFG; require_once($CFG->dirroot . '/repository/lib.php'); $instances = \repository::get_instances(['type' => 'dropbox']); foreach ($instances as $instance) { $instance->cron(); } }
[ "public", "function", "execute", "(", ")", "{", "global", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/repository/lib.php'", ")", ";", "$", "instances", "=", "\\", "repository", "::", "get_instances", "(", "[", "'type'", "=>", "'dropbox'", "]", ")", ";", "foreach", "(", "$", "instances", "as", "$", "instance", ")", "{", "$", "instance", "->", "cron", "(", ")", ";", "}", "}" ]
Run dropbox repository cron.
[ "Run", "dropbox", "repository", "cron", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/dropbox/classes/task/cron_task.php#L40-L48