id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
217,100
moodle/moodle
lib/outputlib.php
theme_config.get_css_cache_key
public function get_css_cache_key() { $nosvg = (!$this->use_svg_icons()) ? 'nosvg_' : ''; $rtlmode = ($this->rtlmode == true) ? 'rtl' : 'ltr'; return $nosvg . $this->name . '_' . $rtlmode; }
php
public function get_css_cache_key() { $nosvg = (!$this->use_svg_icons()) ? 'nosvg_' : ''; $rtlmode = ($this->rtlmode == true) ? 'rtl' : 'ltr'; return $nosvg . $this->name . '_' . $rtlmode; }
[ "public", "function", "get_css_cache_key", "(", ")", "{", "$", "nosvg", "=", "(", "!", "$", "this", "->", "use_svg_icons", "(", ")", ")", "?", "'nosvg_'", ":", "''", ";", "$", "rtlmode", "=", "(", "$", "this", "->", "rtlmode", "==", "true", ")", "?", "'rtl'", ":", "'ltr'", ";", "return", "$", "nosvg", ".", "$", "this", "->", "name", ".", "'_'", ".", "$", "rtlmode", ";", "}" ]
Generate the css content cache key. @return string The post processed css cache key.
[ "Generate", "the", "css", "content", "cache", "key", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L1194-L1199
217,101
moodle/moodle
lib/outputlib.php
theme_config.get_css_content_editor
public function get_css_content_editor() { $css = ''; $cssfiles = $this->editor_css_files(); // If editor has static CSS, include it. foreach ($cssfiles as $file) { $css .= file_get_contents($file)."\n"; } // If editor has SCSS, compile and include it. if (($convertedscss = $this->editor_scss_to_css())) { $css .= $convertedscss; } $output = $this->post_process($css); return $output; }
php
public function get_css_content_editor() { $css = ''; $cssfiles = $this->editor_css_files(); // If editor has static CSS, include it. foreach ($cssfiles as $file) { $css .= file_get_contents($file)."\n"; } // If editor has SCSS, compile and include it. if (($convertedscss = $this->editor_scss_to_css())) { $css .= $convertedscss; } $output = $this->post_process($css); return $output; }
[ "public", "function", "get_css_content_editor", "(", ")", "{", "$", "css", "=", "''", ";", "$", "cssfiles", "=", "$", "this", "->", "editor_css_files", "(", ")", ";", "// If editor has static CSS, include it.", "foreach", "(", "$", "cssfiles", "as", "$", "file", ")", "{", "$", "css", ".=", "file_get_contents", "(", "$", "file", ")", ".", "\"\\n\"", ";", "}", "// If editor has SCSS, compile and include it.", "if", "(", "(", "$", "convertedscss", "=", "$", "this", "->", "editor_scss_to_css", "(", ")", ")", ")", "{", "$", "css", ".=", "$", "convertedscss", ";", "}", "$", "output", "=", "$", "this", "->", "post_process", "(", "$", "css", ")", ";", "return", "$", "output", ";", "}" ]
Get the whole css stylesheet for editor iframe. NOTE: this method is not expected to be used from any addons. @return string CSS markup
[ "Get", "the", "whole", "css", "stylesheet", "for", "editor", "iframe", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L1293-L1310
217,102
moodle/moodle
lib/outputlib.php
theme_config.get_css_content_from_less
protected function get_css_content_from_less($themedesigner) { global $CFG; $lessfile = $this->lessfile; if (!$lessfile || !is_readable($this->dir . '/less/' . $lessfile . '.less')) { throw new coding_exception('The theme did not define a LESS file, or it is not readable.'); } // We might need more memory/time to do this, so let's play safe. raise_memory_limit(MEMORY_EXTRA); core_php_time_limit::raise(300); // Files list. $files = $this->get_css_files($themedesigner); // Get the LESS file path. $themelessfile = $files['theme'][$lessfile]; // Setup compiler options. $options = array( // We need to set the import directory to where $lessfile is. 'import_dirs' => array(dirname($themelessfile) => '/'), // Always disable default caching. 'cache_method' => false, // Disable the relative URLs, we have post_process() to handle that. 'relativeUrls' => false, ); if ($themedesigner) { // Add the sourceMap inline to ensure that it is atomically generated. $options['sourceMap'] = true; $options['sourceMapBasepath'] = $CFG->dirroot; $options['sourceMapRootpath'] = $CFG->wwwroot; } // Instantiate the compiler. $compiler = new core_lessc($options); try { $compiler->parse_file_content($themelessfile); // Get the callbacks. $compiler->parse($this->get_extra_less_code()); $compiler->ModifyVars($this->get_less_variables()); // Compile the CSS. $compiled = $compiler->getCss(); } catch (Less_Exception_Parser $e) { $compiled = false; debugging('Error while compiling LESS ' . $lessfile . ' file: ' . $e->getMessage(), DEBUG_DEVELOPER); } // Try to save memory. $compiler = null; unset($compiler); return $compiled; }
php
protected function get_css_content_from_less($themedesigner) { global $CFG; $lessfile = $this->lessfile; if (!$lessfile || !is_readable($this->dir . '/less/' . $lessfile . '.less')) { throw new coding_exception('The theme did not define a LESS file, or it is not readable.'); } // We might need more memory/time to do this, so let's play safe. raise_memory_limit(MEMORY_EXTRA); core_php_time_limit::raise(300); // Files list. $files = $this->get_css_files($themedesigner); // Get the LESS file path. $themelessfile = $files['theme'][$lessfile]; // Setup compiler options. $options = array( // We need to set the import directory to where $lessfile is. 'import_dirs' => array(dirname($themelessfile) => '/'), // Always disable default caching. 'cache_method' => false, // Disable the relative URLs, we have post_process() to handle that. 'relativeUrls' => false, ); if ($themedesigner) { // Add the sourceMap inline to ensure that it is atomically generated. $options['sourceMap'] = true; $options['sourceMapBasepath'] = $CFG->dirroot; $options['sourceMapRootpath'] = $CFG->wwwroot; } // Instantiate the compiler. $compiler = new core_lessc($options); try { $compiler->parse_file_content($themelessfile); // Get the callbacks. $compiler->parse($this->get_extra_less_code()); $compiler->ModifyVars($this->get_less_variables()); // Compile the CSS. $compiled = $compiler->getCss(); } catch (Less_Exception_Parser $e) { $compiled = false; debugging('Error while compiling LESS ' . $lessfile . ' file: ' . $e->getMessage(), DEBUG_DEVELOPER); } // Try to save memory. $compiler = null; unset($compiler); return $compiled; }
[ "protected", "function", "get_css_content_from_less", "(", "$", "themedesigner", ")", "{", "global", "$", "CFG", ";", "$", "lessfile", "=", "$", "this", "->", "lessfile", ";", "if", "(", "!", "$", "lessfile", "||", "!", "is_readable", "(", "$", "this", "->", "dir", ".", "'/less/'", ".", "$", "lessfile", ".", "'.less'", ")", ")", "{", "throw", "new", "coding_exception", "(", "'The theme did not define a LESS file, or it is not readable.'", ")", ";", "}", "// We might need more memory/time to do this, so let's play safe.", "raise_memory_limit", "(", "MEMORY_EXTRA", ")", ";", "core_php_time_limit", "::", "raise", "(", "300", ")", ";", "// Files list.", "$", "files", "=", "$", "this", "->", "get_css_files", "(", "$", "themedesigner", ")", ";", "// Get the LESS file path.", "$", "themelessfile", "=", "$", "files", "[", "'theme'", "]", "[", "$", "lessfile", "]", ";", "// Setup compiler options.", "$", "options", "=", "array", "(", "// We need to set the import directory to where $lessfile is.", "'import_dirs'", "=>", "array", "(", "dirname", "(", "$", "themelessfile", ")", "=>", "'/'", ")", ",", "// Always disable default caching.", "'cache_method'", "=>", "false", ",", "// Disable the relative URLs, we have post_process() to handle that.", "'relativeUrls'", "=>", "false", ",", ")", ";", "if", "(", "$", "themedesigner", ")", "{", "// Add the sourceMap inline to ensure that it is atomically generated.", "$", "options", "[", "'sourceMap'", "]", "=", "true", ";", "$", "options", "[", "'sourceMapBasepath'", "]", "=", "$", "CFG", "->", "dirroot", ";", "$", "options", "[", "'sourceMapRootpath'", "]", "=", "$", "CFG", "->", "wwwroot", ";", "}", "// Instantiate the compiler.", "$", "compiler", "=", "new", "core_lessc", "(", "$", "options", ")", ";", "try", "{", "$", "compiler", "->", "parse_file_content", "(", "$", "themelessfile", ")", ";", "// Get the callbacks.", "$", "compiler", "->", "parse", "(", "$", "this", "->", "get_extra_less_code", "(", ")", ")", ";", "$", "compiler", "->", "ModifyVars", "(", "$", "this", "->", "get_less_variables", "(", ")", ")", ";", "// Compile the CSS.", "$", "compiled", "=", "$", "compiler", "->", "getCss", "(", ")", ";", "}", "catch", "(", "Less_Exception_Parser", "$", "e", ")", "{", "$", "compiled", "=", "false", ";", "debugging", "(", "'Error while compiling LESS '", ".", "$", "lessfile", ".", "' file: '", ".", "$", "e", "->", "getMessage", "(", ")", ",", "DEBUG_DEVELOPER", ")", ";", "}", "// Try to save memory.", "$", "compiler", "=", "null", ";", "unset", "(", "$", "compiler", ")", ";", "return", "$", "compiled", ";", "}" ]
Return the CSS content generated from LESS the file. @param bool $themedesigner True if theme designer is enabled. @return bool|string Return false when the compilation failed. Else the compiled string.
[ "Return", "the", "CSS", "content", "generated", "from", "LESS", "the", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L1435-L1493
217,103
moodle/moodle
lib/outputlib.php
theme_config.get_css_content_from_scss
protected function get_css_content_from_scss($themedesigner) { global $CFG; list($paths, $scss) = $this->get_scss_property(); if (!$scss) { throw new coding_exception('The theme did not define a SCSS file, or it is not readable.'); } // We might need more memory/time to do this, so let's play safe. raise_memory_limit(MEMORY_EXTRA); core_php_time_limit::raise(300); // Set-up the compiler. $compiler = new core_scss(); $compiler->prepend_raw_scss($this->get_pre_scss_code()); if (is_string($scss)) { $compiler->set_file($scss); } else { $compiler->append_raw_scss($scss($this)); $compiler->setImportPaths($paths); } $compiler->append_raw_scss($this->get_extra_scss_code()); try { // Compile! $compiled = $compiler->to_css(); } catch (\Exception $e) { $compiled = false; debugging('Error while compiling SCSS: ' . $e->getMessage(), DEBUG_DEVELOPER); } // Try to save memory. $compiler = null; unset($compiler); return $compiled; }
php
protected function get_css_content_from_scss($themedesigner) { global $CFG; list($paths, $scss) = $this->get_scss_property(); if (!$scss) { throw new coding_exception('The theme did not define a SCSS file, or it is not readable.'); } // We might need more memory/time to do this, so let's play safe. raise_memory_limit(MEMORY_EXTRA); core_php_time_limit::raise(300); // Set-up the compiler. $compiler = new core_scss(); $compiler->prepend_raw_scss($this->get_pre_scss_code()); if (is_string($scss)) { $compiler->set_file($scss); } else { $compiler->append_raw_scss($scss($this)); $compiler->setImportPaths($paths); } $compiler->append_raw_scss($this->get_extra_scss_code()); try { // Compile! $compiled = $compiler->to_css(); } catch (\Exception $e) { $compiled = false; debugging('Error while compiling SCSS: ' . $e->getMessage(), DEBUG_DEVELOPER); } // Try to save memory. $compiler = null; unset($compiler); return $compiled; }
[ "protected", "function", "get_css_content_from_scss", "(", "$", "themedesigner", ")", "{", "global", "$", "CFG", ";", "list", "(", "$", "paths", ",", "$", "scss", ")", "=", "$", "this", "->", "get_scss_property", "(", ")", ";", "if", "(", "!", "$", "scss", ")", "{", "throw", "new", "coding_exception", "(", "'The theme did not define a SCSS file, or it is not readable.'", ")", ";", "}", "// We might need more memory/time to do this, so let's play safe.", "raise_memory_limit", "(", "MEMORY_EXTRA", ")", ";", "core_php_time_limit", "::", "raise", "(", "300", ")", ";", "// Set-up the compiler.", "$", "compiler", "=", "new", "core_scss", "(", ")", ";", "$", "compiler", "->", "prepend_raw_scss", "(", "$", "this", "->", "get_pre_scss_code", "(", ")", ")", ";", "if", "(", "is_string", "(", "$", "scss", ")", ")", "{", "$", "compiler", "->", "set_file", "(", "$", "scss", ")", ";", "}", "else", "{", "$", "compiler", "->", "append_raw_scss", "(", "$", "scss", "(", "$", "this", ")", ")", ";", "$", "compiler", "->", "setImportPaths", "(", "$", "paths", ")", ";", "}", "$", "compiler", "->", "append_raw_scss", "(", "$", "this", "->", "get_extra_scss_code", "(", ")", ")", ";", "try", "{", "// Compile!", "$", "compiled", "=", "$", "compiler", "->", "to_css", "(", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "$", "compiled", "=", "false", ";", "debugging", "(", "'Error while compiling SCSS: '", ".", "$", "e", "->", "getMessage", "(", ")", ",", "DEBUG_DEVELOPER", ")", ";", "}", "// Try to save memory.", "$", "compiler", "=", "null", ";", "unset", "(", "$", "compiler", ")", ";", "return", "$", "compiled", ";", "}" ]
Return the CSS content generated from the SCSS file. @param bool $themedesigner True if theme designer is enabled. @return bool|string Return false when the compilation failed. Else the compiled string.
[ "Return", "the", "CSS", "content", "generated", "from", "the", "SCSS", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L1501-L1538
217,104
moodle/moodle
lib/outputlib.php
theme_config.get_precompiled_css_content
public function get_precompiled_css_content() { $configs = [$this] + $this->parent_configs; $css = ''; foreach ($configs as $config) { if (isset($config->precompiledcsscallback)) { $function = $config->precompiledcsscallback; if (function_exists($function)) { $css .= $function($this); } } } return $css; }
php
public function get_precompiled_css_content() { $configs = [$this] + $this->parent_configs; $css = ''; foreach ($configs as $config) { if (isset($config->precompiledcsscallback)) { $function = $config->precompiledcsscallback; if (function_exists($function)) { $css .= $function($this); } } } return $css; }
[ "public", "function", "get_precompiled_css_content", "(", ")", "{", "$", "configs", "=", "[", "$", "this", "]", "+", "$", "this", "->", "parent_configs", ";", "$", "css", "=", "''", ";", "foreach", "(", "$", "configs", "as", "$", "config", ")", "{", "if", "(", "isset", "(", "$", "config", "->", "precompiledcsscallback", ")", ")", "{", "$", "function", "=", "$", "config", "->", "precompiledcsscallback", ";", "if", "(", "function_exists", "(", "$", "function", ")", ")", "{", "$", "css", ".=", "$", "function", "(", "$", "this", ")", ";", "}", "}", "}", "return", "$", "css", ";", "}" ]
Return the precompiled CSS if the precompiledcsscallback exists. @return string Return compiled css.
[ "Return", "the", "precompiled", "CSS", "if", "the", "precompiledcsscallback", "exists", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L1545-L1558
217,105
moodle/moodle
lib/outputlib.php
theme_config.get_icon_system
public function get_icon_system() { // Getting all the candidate functions. $system = false; if (isset($this->iconsystem) && \core\output\icon_system::is_valid_system($this->iconsystem)) { return $this->iconsystem; } foreach ($this->parent_configs as $parent_config) { if (isset($parent_config->iconsystem) && \core\output\icon_system::is_valid_system($parent_config->iconsystem)) { return $parent_config->iconsystem; } } return \core\output\icon_system::STANDARD; }
php
public function get_icon_system() { // Getting all the candidate functions. $system = false; if (isset($this->iconsystem) && \core\output\icon_system::is_valid_system($this->iconsystem)) { return $this->iconsystem; } foreach ($this->parent_configs as $parent_config) { if (isset($parent_config->iconsystem) && \core\output\icon_system::is_valid_system($parent_config->iconsystem)) { return $parent_config->iconsystem; } } return \core\output\icon_system::STANDARD; }
[ "public", "function", "get_icon_system", "(", ")", "{", "// Getting all the candidate functions.", "$", "system", "=", "false", ";", "if", "(", "isset", "(", "$", "this", "->", "iconsystem", ")", "&&", "\\", "core", "\\", "output", "\\", "icon_system", "::", "is_valid_system", "(", "$", "this", "->", "iconsystem", ")", ")", "{", "return", "$", "this", "->", "iconsystem", ";", "}", "foreach", "(", "$", "this", "->", "parent_configs", "as", "$", "parent_config", ")", "{", "if", "(", "isset", "(", "$", "parent_config", "->", "iconsystem", ")", "&&", "\\", "core", "\\", "output", "\\", "icon_system", "::", "is_valid_system", "(", "$", "parent_config", "->", "iconsystem", ")", ")", "{", "return", "$", "parent_config", "->", "iconsystem", ";", "}", "}", "return", "\\", "core", "\\", "output", "\\", "icon_system", "::", "STANDARD", ";", "}" ]
Get the icon system to use. @return string
[ "Get", "the", "icon", "system", "to", "use", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L1565-L1578
217,106
moodle/moodle
lib/outputlib.php
theme_config.get_less_variables
protected function get_less_variables() { $variables = array(); // Getting all the candidate functions. $candidates = array(); foreach ($this->parent_configs as $parent_config) { if (!isset($parent_config->lessvariablescallback)) { continue; } $candidates[] = $parent_config->lessvariablescallback; } $candidates[] = $this->lessvariablescallback; // Calling the functions. foreach ($candidates as $function) { if (function_exists($function)) { $vars = $function($this); if (!is_array($vars)) { debugging('Callback ' . $function . ' did not return an array() as expected', DEBUG_DEVELOPER); continue; } $variables = array_merge($variables, $vars); } } return $variables; }
php
protected function get_less_variables() { $variables = array(); // Getting all the candidate functions. $candidates = array(); foreach ($this->parent_configs as $parent_config) { if (!isset($parent_config->lessvariablescallback)) { continue; } $candidates[] = $parent_config->lessvariablescallback; } $candidates[] = $this->lessvariablescallback; // Calling the functions. foreach ($candidates as $function) { if (function_exists($function)) { $vars = $function($this); if (!is_array($vars)) { debugging('Callback ' . $function . ' did not return an array() as expected', DEBUG_DEVELOPER); continue; } $variables = array_merge($variables, $vars); } } return $variables; }
[ "protected", "function", "get_less_variables", "(", ")", "{", "$", "variables", "=", "array", "(", ")", ";", "// Getting all the candidate functions.", "$", "candidates", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "parent_configs", "as", "$", "parent_config", ")", "{", "if", "(", "!", "isset", "(", "$", "parent_config", "->", "lessvariablescallback", ")", ")", "{", "continue", ";", "}", "$", "candidates", "[", "]", "=", "$", "parent_config", "->", "lessvariablescallback", ";", "}", "$", "candidates", "[", "]", "=", "$", "this", "->", "lessvariablescallback", ";", "// Calling the functions.", "foreach", "(", "$", "candidates", "as", "$", "function", ")", "{", "if", "(", "function_exists", "(", "$", "function", ")", ")", "{", "$", "vars", "=", "$", "function", "(", "$", "this", ")", ";", "if", "(", "!", "is_array", "(", "$", "vars", ")", ")", "{", "debugging", "(", "'Callback '", ".", "$", "function", ".", "' did not return an array() as expected'", ",", "DEBUG_DEVELOPER", ")", ";", "continue", ";", "}", "$", "variables", "=", "array_merge", "(", "$", "variables", ",", "$", "vars", ")", ";", "}", "}", "return", "$", "variables", ";", "}" ]
Return extra LESS variables to use when compiling. @return array Where keys are the variable names (omitting the @), and the values are the value.
[ "Return", "extra", "LESS", "variables", "to", "use", "when", "compiling", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L1585-L1611
217,107
moodle/moodle
lib/outputlib.php
theme_config.get_extra_less_code
protected function get_extra_less_code() { $content = ''; // Getting all the candidate functions. $candidates = array(); foreach ($this->parent_configs as $parent_config) { if (!isset($parent_config->extralesscallback)) { continue; } $candidates[] = $parent_config->extralesscallback; } $candidates[] = $this->extralesscallback; // Calling the functions. foreach ($candidates as $function) { if (function_exists($function)) { $content .= "\n/** Extra LESS from $function **/\n" . $function($this) . "\n"; } } return $content; }
php
protected function get_extra_less_code() { $content = ''; // Getting all the candidate functions. $candidates = array(); foreach ($this->parent_configs as $parent_config) { if (!isset($parent_config->extralesscallback)) { continue; } $candidates[] = $parent_config->extralesscallback; } $candidates[] = $this->extralesscallback; // Calling the functions. foreach ($candidates as $function) { if (function_exists($function)) { $content .= "\n/** Extra LESS from $function **/\n" . $function($this) . "\n"; } } return $content; }
[ "protected", "function", "get_extra_less_code", "(", ")", "{", "$", "content", "=", "''", ";", "// Getting all the candidate functions.", "$", "candidates", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "parent_configs", "as", "$", "parent_config", ")", "{", "if", "(", "!", "isset", "(", "$", "parent_config", "->", "extralesscallback", ")", ")", "{", "continue", ";", "}", "$", "candidates", "[", "]", "=", "$", "parent_config", "->", "extralesscallback", ";", "}", "$", "candidates", "[", "]", "=", "$", "this", "->", "extralesscallback", ";", "// Calling the functions.", "foreach", "(", "$", "candidates", "as", "$", "function", ")", "{", "if", "(", "function_exists", "(", "$", "function", ")", ")", "{", "$", "content", ".=", "\"\\n/** Extra LESS from $function **/\\n\"", ".", "$", "function", "(", "$", "this", ")", ".", "\"\\n\"", ";", "}", "}", "return", "$", "content", ";", "}" ]
Return extra LESS code to add when compiling. This is intended to be used by themes to inject some LESS code before it gets compiled. If you want to inject variables you should use {@link self::get_less_variables()}. @return string The LESS code to inject.
[ "Return", "extra", "LESS", "code", "to", "add", "when", "compiling", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L1622-L1643
217,108
moodle/moodle
lib/outputlib.php
theme_config.get_extra_scss_code
protected function get_extra_scss_code() { $content = ''; // Getting all the candidate functions. $candidates = array(); foreach ($this->parent_configs as $parent_config) { if (!isset($parent_config->extrascsscallback)) { continue; } $candidates[] = $parent_config->extrascsscallback; } $candidates[] = $this->extrascsscallback; // Calling the functions. foreach ($candidates as $function) { if (function_exists($function)) { $content .= "\n/** Extra SCSS from $function **/\n" . $function($this) . "\n"; } } return $content; }
php
protected function get_extra_scss_code() { $content = ''; // Getting all the candidate functions. $candidates = array(); foreach ($this->parent_configs as $parent_config) { if (!isset($parent_config->extrascsscallback)) { continue; } $candidates[] = $parent_config->extrascsscallback; } $candidates[] = $this->extrascsscallback; // Calling the functions. foreach ($candidates as $function) { if (function_exists($function)) { $content .= "\n/** Extra SCSS from $function **/\n" . $function($this) . "\n"; } } return $content; }
[ "protected", "function", "get_extra_scss_code", "(", ")", "{", "$", "content", "=", "''", ";", "// Getting all the candidate functions.", "$", "candidates", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "parent_configs", "as", "$", "parent_config", ")", "{", "if", "(", "!", "isset", "(", "$", "parent_config", "->", "extrascsscallback", ")", ")", "{", "continue", ";", "}", "$", "candidates", "[", "]", "=", "$", "parent_config", "->", "extrascsscallback", ";", "}", "$", "candidates", "[", "]", "=", "$", "this", "->", "extrascsscallback", ";", "// Calling the functions.", "foreach", "(", "$", "candidates", "as", "$", "function", ")", "{", "if", "(", "function_exists", "(", "$", "function", ")", ")", "{", "$", "content", ".=", "\"\\n/** Extra SCSS from $function **/\\n\"", ".", "$", "function", "(", "$", "this", ")", ".", "\"\\n\"", ";", "}", "}", "return", "$", "content", ";", "}" ]
Return extra SCSS code to add when compiling. This is intended to be used by themes to inject some SCSS code before it gets compiled. If you want to inject variables you should use {@link self::get_scss_variables()}. @return string The SCSS code to inject.
[ "Return", "extra", "SCSS", "code", "to", "add", "when", "compiling", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L1654-L1675
217,109
moodle/moodle
lib/outputlib.php
theme_config.get_pre_scss_code
protected function get_pre_scss_code() { $content = ''; // Getting all the candidate functions. $candidates = array(); foreach ($this->parent_configs as $parent_config) { if (!isset($parent_config->prescsscallback)) { continue; } $candidates[] = $parent_config->prescsscallback; } $candidates[] = $this->prescsscallback; // Calling the functions. foreach ($candidates as $function) { if (function_exists($function)) { $content .= "\n/** Pre-SCSS from $function **/\n" . $function($this) . "\n"; } } return $content; }
php
protected function get_pre_scss_code() { $content = ''; // Getting all the candidate functions. $candidates = array(); foreach ($this->parent_configs as $parent_config) { if (!isset($parent_config->prescsscallback)) { continue; } $candidates[] = $parent_config->prescsscallback; } $candidates[] = $this->prescsscallback; // Calling the functions. foreach ($candidates as $function) { if (function_exists($function)) { $content .= "\n/** Pre-SCSS from $function **/\n" . $function($this) . "\n"; } } return $content; }
[ "protected", "function", "get_pre_scss_code", "(", ")", "{", "$", "content", "=", "''", ";", "// Getting all the candidate functions.", "$", "candidates", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "parent_configs", "as", "$", "parent_config", ")", "{", "if", "(", "!", "isset", "(", "$", "parent_config", "->", "prescsscallback", ")", ")", "{", "continue", ";", "}", "$", "candidates", "[", "]", "=", "$", "parent_config", "->", "prescsscallback", ";", "}", "$", "candidates", "[", "]", "=", "$", "this", "->", "prescsscallback", ";", "// Calling the functions.", "foreach", "(", "$", "candidates", "as", "$", "function", ")", "{", "if", "(", "function_exists", "(", "$", "function", ")", ")", "{", "$", "content", ".=", "\"\\n/** Pre-SCSS from $function **/\\n\"", ".", "$", "function", "(", "$", "this", ")", ".", "\"\\n\"", ";", "}", "}", "return", "$", "content", ";", "}" ]
SCSS code to prepend when compiling. This is intended to be used by themes to inject SCSS code before it gets compiled. @return string The SCSS code to inject.
[ "SCSS", "code", "to", "prepend", "when", "compiling", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L1684-L1705
217,110
moodle/moodle
lib/outputlib.php
theme_config.get_scss_property
public function get_scss_property() { if ($this->scsscache === null) { $configs = [$this] + $this->parent_configs; $scss = null; foreach ($configs as $config) { $path = "{$config->dir}/scss"; // We collect the SCSS property until we've found one. if (empty($scss) && !empty($config->scss)) { $candidate = is_string($config->scss) ? "{$path}/{$config->scss}.scss" : $config->scss; if ($candidate instanceof Closure) { $scss = $candidate; } else if (is_string($candidate) && is_readable($candidate)) { $scss = $candidate; } } // We collect the import paths once we've found a SCSS property. if ($scss && is_dir($path)) { $paths[] = $path; } } $this->scsscache = $scss !== null ? [$paths, $scss] : false; } return $this->scsscache; }
php
public function get_scss_property() { if ($this->scsscache === null) { $configs = [$this] + $this->parent_configs; $scss = null; foreach ($configs as $config) { $path = "{$config->dir}/scss"; // We collect the SCSS property until we've found one. if (empty($scss) && !empty($config->scss)) { $candidate = is_string($config->scss) ? "{$path}/{$config->scss}.scss" : $config->scss; if ($candidate instanceof Closure) { $scss = $candidate; } else if (is_string($candidate) && is_readable($candidate)) { $scss = $candidate; } } // We collect the import paths once we've found a SCSS property. if ($scss && is_dir($path)) { $paths[] = $path; } } $this->scsscache = $scss !== null ? [$paths, $scss] : false; } return $this->scsscache; }
[ "public", "function", "get_scss_property", "(", ")", "{", "if", "(", "$", "this", "->", "scsscache", "===", "null", ")", "{", "$", "configs", "=", "[", "$", "this", "]", "+", "$", "this", "->", "parent_configs", ";", "$", "scss", "=", "null", ";", "foreach", "(", "$", "configs", "as", "$", "config", ")", "{", "$", "path", "=", "\"{$config->dir}/scss\"", ";", "// We collect the SCSS property until we've found one.", "if", "(", "empty", "(", "$", "scss", ")", "&&", "!", "empty", "(", "$", "config", "->", "scss", ")", ")", "{", "$", "candidate", "=", "is_string", "(", "$", "config", "->", "scss", ")", "?", "\"{$path}/{$config->scss}.scss\"", ":", "$", "config", "->", "scss", ";", "if", "(", "$", "candidate", "instanceof", "Closure", ")", "{", "$", "scss", "=", "$", "candidate", ";", "}", "else", "if", "(", "is_string", "(", "$", "candidate", ")", "&&", "is_readable", "(", "$", "candidate", ")", ")", "{", "$", "scss", "=", "$", "candidate", ";", "}", "}", "// We collect the import paths once we've found a SCSS property.", "if", "(", "$", "scss", "&&", "is_dir", "(", "$", "path", ")", ")", "{", "$", "paths", "[", "]", "=", "$", "path", ";", "}", "}", "$", "this", "->", "scsscache", "=", "$", "scss", "!==", "null", "?", "[", "$", "paths", ",", "$", "scss", "]", ":", "false", ";", "}", "return", "$", "this", "->", "scsscache", ";", "}" ]
Get the SCSS property. This resolves whether a SCSS file (or content) has to be used when generating the stylesheet for the theme. It will look at parents themes and check the SCSS properties there. @return False when SCSS is not used. An array with the import paths, and the path to the SCSS file or Closure as second.
[ "Get", "the", "SCSS", "property", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L1717-L1746
217,111
moodle/moodle
lib/outputlib.php
theme_config.javascript_url
public function javascript_url($inhead) { global $CFG; $rev = theme_get_revision(); $params = array('theme'=>$this->name,'rev'=>$rev); $params['type'] = $inhead ? 'head' : 'footer'; // Return early if there are no files to serve if (count($this->javascript_files($params['type'])) === 0) { return null; } if (!empty($CFG->slasharguments) and $rev > 0) { $url = new moodle_url("/theme/javascript.php"); $url->set_slashargument('/'.$this->name.'/'.$rev.'/'.$params['type'], 'noparam', true); return $url; } else { return new moodle_url('/theme/javascript.php', $params); } }
php
public function javascript_url($inhead) { global $CFG; $rev = theme_get_revision(); $params = array('theme'=>$this->name,'rev'=>$rev); $params['type'] = $inhead ? 'head' : 'footer'; // Return early if there are no files to serve if (count($this->javascript_files($params['type'])) === 0) { return null; } if (!empty($CFG->slasharguments) and $rev > 0) { $url = new moodle_url("/theme/javascript.php"); $url->set_slashargument('/'.$this->name.'/'.$rev.'/'.$params['type'], 'noparam', true); return $url; } else { return new moodle_url('/theme/javascript.php', $params); } }
[ "public", "function", "javascript_url", "(", "$", "inhead", ")", "{", "global", "$", "CFG", ";", "$", "rev", "=", "theme_get_revision", "(", ")", ";", "$", "params", "=", "array", "(", "'theme'", "=>", "$", "this", "->", "name", ",", "'rev'", "=>", "$", "rev", ")", ";", "$", "params", "[", "'type'", "]", "=", "$", "inhead", "?", "'head'", ":", "'footer'", ";", "// Return early if there are no files to serve", "if", "(", "count", "(", "$", "this", "->", "javascript_files", "(", "$", "params", "[", "'type'", "]", ")", ")", "===", "0", ")", "{", "return", "null", ";", "}", "if", "(", "!", "empty", "(", "$", "CFG", "->", "slasharguments", ")", "and", "$", "rev", ">", "0", ")", "{", "$", "url", "=", "new", "moodle_url", "(", "\"/theme/javascript.php\"", ")", ";", "$", "url", "->", "set_slashargument", "(", "'/'", ".", "$", "this", "->", "name", ".", "'/'", ".", "$", "rev", ".", "'/'", ".", "$", "params", "[", "'type'", "]", ",", "'noparam'", ",", "true", ")", ";", "return", "$", "url", ";", "}", "else", "{", "return", "new", "moodle_url", "(", "'/theme/javascript.php'", ",", "$", "params", ")", ";", "}", "}" ]
Generate a URL to the file that serves theme JavaScript files. If we determine that the theme has no relevant files, then we return early with a null value. @param bool $inhead true means head url, false means footer @return moodle_url|null
[ "Generate", "a", "URL", "to", "the", "file", "that", "serves", "theme", "JavaScript", "files", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L1757-L1776
217,112
moodle/moodle
lib/outputlib.php
theme_config.resolve_excludes
protected function resolve_excludes($variable, $default = null) { $setting = $default; if (is_array($this->{$variable}) or $this->{$variable} === true) { $setting = $this->{$variable}; } else { foreach ($this->parent_configs as $parent_config) { // the immediate parent first, base last if (!isset($parent_config->{$variable})) { continue; } if (is_array($parent_config->{$variable}) or $parent_config->{$variable} === true) { $setting = $parent_config->{$variable}; break; } } } return $setting; }
php
protected function resolve_excludes($variable, $default = null) { $setting = $default; if (is_array($this->{$variable}) or $this->{$variable} === true) { $setting = $this->{$variable}; } else { foreach ($this->parent_configs as $parent_config) { // the immediate parent first, base last if (!isset($parent_config->{$variable})) { continue; } if (is_array($parent_config->{$variable}) or $parent_config->{$variable} === true) { $setting = $parent_config->{$variable}; break; } } } return $setting; }
[ "protected", "function", "resolve_excludes", "(", "$", "variable", ",", "$", "default", "=", "null", ")", "{", "$", "setting", "=", "$", "default", ";", "if", "(", "is_array", "(", "$", "this", "->", "{", "$", "variable", "}", ")", "or", "$", "this", "->", "{", "$", "variable", "}", "===", "true", ")", "{", "$", "setting", "=", "$", "this", "->", "{", "$", "variable", "}", ";", "}", "else", "{", "foreach", "(", "$", "this", "->", "parent_configs", "as", "$", "parent_config", ")", "{", "// the immediate parent first, base last", "if", "(", "!", "isset", "(", "$", "parent_config", "->", "{", "$", "variable", "}", ")", ")", "{", "continue", ";", "}", "if", "(", "is_array", "(", "$", "parent_config", "->", "{", "$", "variable", "}", ")", "or", "$", "parent_config", "->", "{", "$", "variable", "}", "===", "true", ")", "{", "$", "setting", "=", "$", "parent_config", "->", "{", "$", "variable", "}", ";", "break", ";", "}", "}", "}", "return", "$", "setting", ";", "}" ]
Resolves an exclude setting to the themes setting is applicable or the setting of its closest parent. @param string $variable The name of the setting the exclude setting to resolve @param string $default @return mixed
[ "Resolves", "an", "exclude", "setting", "to", "the", "themes", "setting", "is", "applicable", "or", "the", "setting", "of", "its", "closest", "parent", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L1838-L1854
217,113
moodle/moodle
lib/outputlib.php
theme_config.javascript_content
public function javascript_content($type) { $jsfiles = $this->javascript_files($type); $js = ''; foreach ($jsfiles as $jsfile) { $js .= file_get_contents($jsfile)."\n"; } return $js; }
php
public function javascript_content($type) { $jsfiles = $this->javascript_files($type); $js = ''; foreach ($jsfiles as $jsfile) { $js .= file_get_contents($jsfile)."\n"; } return $js; }
[ "public", "function", "javascript_content", "(", "$", "type", ")", "{", "$", "jsfiles", "=", "$", "this", "->", "javascript_files", "(", "$", "type", ")", ";", "$", "js", "=", "''", ";", "foreach", "(", "$", "jsfiles", "as", "$", "jsfile", ")", "{", "$", "js", ".=", "file_get_contents", "(", "$", "jsfile", ")", ".", "\"\\n\"", ";", "}", "return", "$", "js", ";", "}" ]
Returns the content of the one huge javascript file merged from all theme javascript files. @param bool $type @return string
[ "Returns", "the", "content", "of", "the", "one", "huge", "javascript", "file", "merged", "from", "all", "theme", "javascript", "files", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L1862-L1869
217,114
moodle/moodle
lib/outputlib.php
theme_config.post_process
public function post_process($css) { // now resolve all image locations if (preg_match_all('/\[\[pix:([a-z0-9_]+\|)?([^\]]+)\]\]/', $css, $matches, PREG_SET_ORDER)) { $replaced = array(); foreach ($matches as $match) { if (isset($replaced[$match[0]])) { continue; } $replaced[$match[0]] = true; $imagename = $match[2]; $component = rtrim($match[1], '|'); $imageurl = $this->image_url($imagename, $component)->out(false); // we do not need full url because the image.php is always in the same dir $imageurl = preg_replace('|^http.?://[^/]+|', '', $imageurl); $css = str_replace($match[0], $imageurl, $css); } } // Now resolve all font locations. if (preg_match_all('/\[\[font:([a-z0-9_]+\|)?([^\]]+)\]\]/', $css, $matches, PREG_SET_ORDER)) { $replaced = array(); foreach ($matches as $match) { if (isset($replaced[$match[0]])) { continue; } $replaced[$match[0]] = true; $fontname = $match[2]; $component = rtrim($match[1], '|'); $fonturl = $this->font_url($fontname, $component)->out(false); // We do not need full url because the font.php is always in the same dir. $fonturl = preg_replace('|^http.?://[^/]+|', '', $fonturl); $css = str_replace($match[0], $fonturl, $css); } } // Now resolve all theme settings or do any other postprocessing. // This needs to be done before calling core parser, since the parser strips [[settings]] tags. $csspostprocess = $this->csspostprocess; if (function_exists($csspostprocess)) { $css = $csspostprocess($css, $this); } // Post processing using an object representation of CSS. $treeprocessor = $this->get_css_tree_post_processor(); $needsparsing = !empty($treeprocessor) || !empty($this->rtlmode); if ($needsparsing) { // We might need more memory/time to do this, so let's play safe. raise_memory_limit(MEMORY_EXTRA); core_php_time_limit::raise(300); $parser = new core_cssparser($css); $csstree = $parser->parse(); unset($parser); if ($this->rtlmode) { $this->rtlize($csstree); } if ($treeprocessor) { $treeprocessor($csstree, $this); } $css = $csstree->render(); unset($csstree); } return $css; }
php
public function post_process($css) { // now resolve all image locations if (preg_match_all('/\[\[pix:([a-z0-9_]+\|)?([^\]]+)\]\]/', $css, $matches, PREG_SET_ORDER)) { $replaced = array(); foreach ($matches as $match) { if (isset($replaced[$match[0]])) { continue; } $replaced[$match[0]] = true; $imagename = $match[2]; $component = rtrim($match[1], '|'); $imageurl = $this->image_url($imagename, $component)->out(false); // we do not need full url because the image.php is always in the same dir $imageurl = preg_replace('|^http.?://[^/]+|', '', $imageurl); $css = str_replace($match[0], $imageurl, $css); } } // Now resolve all font locations. if (preg_match_all('/\[\[font:([a-z0-9_]+\|)?([^\]]+)\]\]/', $css, $matches, PREG_SET_ORDER)) { $replaced = array(); foreach ($matches as $match) { if (isset($replaced[$match[0]])) { continue; } $replaced[$match[0]] = true; $fontname = $match[2]; $component = rtrim($match[1], '|'); $fonturl = $this->font_url($fontname, $component)->out(false); // We do not need full url because the font.php is always in the same dir. $fonturl = preg_replace('|^http.?://[^/]+|', '', $fonturl); $css = str_replace($match[0], $fonturl, $css); } } // Now resolve all theme settings or do any other postprocessing. // This needs to be done before calling core parser, since the parser strips [[settings]] tags. $csspostprocess = $this->csspostprocess; if (function_exists($csspostprocess)) { $css = $csspostprocess($css, $this); } // Post processing using an object representation of CSS. $treeprocessor = $this->get_css_tree_post_processor(); $needsparsing = !empty($treeprocessor) || !empty($this->rtlmode); if ($needsparsing) { // We might need more memory/time to do this, so let's play safe. raise_memory_limit(MEMORY_EXTRA); core_php_time_limit::raise(300); $parser = new core_cssparser($css); $csstree = $parser->parse(); unset($parser); if ($this->rtlmode) { $this->rtlize($csstree); } if ($treeprocessor) { $treeprocessor($csstree, $this); } $css = $csstree->render(); unset($csstree); } return $css; }
[ "public", "function", "post_process", "(", "$", "css", ")", "{", "// now resolve all image locations", "if", "(", "preg_match_all", "(", "'/\\[\\[pix:([a-z0-9_]+\\|)?([^\\]]+)\\]\\]/'", ",", "$", "css", ",", "$", "matches", ",", "PREG_SET_ORDER", ")", ")", "{", "$", "replaced", "=", "array", "(", ")", ";", "foreach", "(", "$", "matches", "as", "$", "match", ")", "{", "if", "(", "isset", "(", "$", "replaced", "[", "$", "match", "[", "0", "]", "]", ")", ")", "{", "continue", ";", "}", "$", "replaced", "[", "$", "match", "[", "0", "]", "]", "=", "true", ";", "$", "imagename", "=", "$", "match", "[", "2", "]", ";", "$", "component", "=", "rtrim", "(", "$", "match", "[", "1", "]", ",", "'|'", ")", ";", "$", "imageurl", "=", "$", "this", "->", "image_url", "(", "$", "imagename", ",", "$", "component", ")", "->", "out", "(", "false", ")", ";", "// we do not need full url because the image.php is always in the same dir", "$", "imageurl", "=", "preg_replace", "(", "'|^http.?://[^/]+|'", ",", "''", ",", "$", "imageurl", ")", ";", "$", "css", "=", "str_replace", "(", "$", "match", "[", "0", "]", ",", "$", "imageurl", ",", "$", "css", ")", ";", "}", "}", "// Now resolve all font locations.", "if", "(", "preg_match_all", "(", "'/\\[\\[font:([a-z0-9_]+\\|)?([^\\]]+)\\]\\]/'", ",", "$", "css", ",", "$", "matches", ",", "PREG_SET_ORDER", ")", ")", "{", "$", "replaced", "=", "array", "(", ")", ";", "foreach", "(", "$", "matches", "as", "$", "match", ")", "{", "if", "(", "isset", "(", "$", "replaced", "[", "$", "match", "[", "0", "]", "]", ")", ")", "{", "continue", ";", "}", "$", "replaced", "[", "$", "match", "[", "0", "]", "]", "=", "true", ";", "$", "fontname", "=", "$", "match", "[", "2", "]", ";", "$", "component", "=", "rtrim", "(", "$", "match", "[", "1", "]", ",", "'|'", ")", ";", "$", "fonturl", "=", "$", "this", "->", "font_url", "(", "$", "fontname", ",", "$", "component", ")", "->", "out", "(", "false", ")", ";", "// We do not need full url because the font.php is always in the same dir.", "$", "fonturl", "=", "preg_replace", "(", "'|^http.?://[^/]+|'", ",", "''", ",", "$", "fonturl", ")", ";", "$", "css", "=", "str_replace", "(", "$", "match", "[", "0", "]", ",", "$", "fonturl", ",", "$", "css", ")", ";", "}", "}", "// Now resolve all theme settings or do any other postprocessing.", "// This needs to be done before calling core parser, since the parser strips [[settings]] tags.", "$", "csspostprocess", "=", "$", "this", "->", "csspostprocess", ";", "if", "(", "function_exists", "(", "$", "csspostprocess", ")", ")", "{", "$", "css", "=", "$", "csspostprocess", "(", "$", "css", ",", "$", "this", ")", ";", "}", "// Post processing using an object representation of CSS.", "$", "treeprocessor", "=", "$", "this", "->", "get_css_tree_post_processor", "(", ")", ";", "$", "needsparsing", "=", "!", "empty", "(", "$", "treeprocessor", ")", "||", "!", "empty", "(", "$", "this", "->", "rtlmode", ")", ";", "if", "(", "$", "needsparsing", ")", "{", "// We might need more memory/time to do this, so let's play safe.", "raise_memory_limit", "(", "MEMORY_EXTRA", ")", ";", "core_php_time_limit", "::", "raise", "(", "300", ")", ";", "$", "parser", "=", "new", "core_cssparser", "(", "$", "css", ")", ";", "$", "csstree", "=", "$", "parser", "->", "parse", "(", ")", ";", "unset", "(", "$", "parser", ")", ";", "if", "(", "$", "this", "->", "rtlmode", ")", "{", "$", "this", "->", "rtlize", "(", "$", "csstree", ")", ";", "}", "if", "(", "$", "treeprocessor", ")", "{", "$", "treeprocessor", "(", "$", "csstree", ",", "$", "this", ")", ";", "}", "$", "css", "=", "$", "csstree", "->", "render", "(", ")", ";", "unset", "(", "$", "csstree", ")", ";", "}", "return", "$", "css", ";", "}" ]
Post processes CSS. This method post processes all of the CSS before it is served for this theme. This is done so that things such as image URL's can be swapped in and to run any specific CSS post process method the theme has requested. This allows themes to use CSS settings. @param string $css The CSS to process. @return string The processed CSS.
[ "Post", "processes", "CSS", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L1882-L1950
217,115
moodle/moodle
lib/outputlib.php
theme_config.font_url
public function font_url($font, $component) { global $CFG; $params = array('theme'=>$this->name); if (empty($component) or $component === 'moodle' or $component === 'core') { $params['component'] = 'core'; } else { $params['component'] = $component; } $rev = theme_get_revision(); if ($rev != -1) { $params['rev'] = $rev; } $params['font'] = $font; $url = new moodle_url("/theme/font.php"); if (!empty($CFG->slasharguments) and $rev > 0) { $path = '/'.$params['theme'].'/'.$params['component'].'/'.$params['rev'].'/'.$params['font']; $url->set_slashargument($path, 'noparam', true); } else { $url->params($params); } return $url; }
php
public function font_url($font, $component) { global $CFG; $params = array('theme'=>$this->name); if (empty($component) or $component === 'moodle' or $component === 'core') { $params['component'] = 'core'; } else { $params['component'] = $component; } $rev = theme_get_revision(); if ($rev != -1) { $params['rev'] = $rev; } $params['font'] = $font; $url = new moodle_url("/theme/font.php"); if (!empty($CFG->slasharguments) and $rev > 0) { $path = '/'.$params['theme'].'/'.$params['component'].'/'.$params['rev'].'/'.$params['font']; $url->set_slashargument($path, 'noparam', true); } else { $url->params($params); } return $url; }
[ "public", "function", "font_url", "(", "$", "font", ",", "$", "component", ")", "{", "global", "$", "CFG", ";", "$", "params", "=", "array", "(", "'theme'", "=>", "$", "this", "->", "name", ")", ";", "if", "(", "empty", "(", "$", "component", ")", "or", "$", "component", "===", "'moodle'", "or", "$", "component", "===", "'core'", ")", "{", "$", "params", "[", "'component'", "]", "=", "'core'", ";", "}", "else", "{", "$", "params", "[", "'component'", "]", "=", "$", "component", ";", "}", "$", "rev", "=", "theme_get_revision", "(", ")", ";", "if", "(", "$", "rev", "!=", "-", "1", ")", "{", "$", "params", "[", "'rev'", "]", "=", "$", "rev", ";", "}", "$", "params", "[", "'font'", "]", "=", "$", "font", ";", "$", "url", "=", "new", "moodle_url", "(", "\"/theme/font.php\"", ")", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "slasharguments", ")", "and", "$", "rev", ">", "0", ")", "{", "$", "path", "=", "'/'", ".", "$", "params", "[", "'theme'", "]", ".", "'/'", ".", "$", "params", "[", "'component'", "]", ".", "'/'", ".", "$", "params", "[", "'rev'", "]", ".", "'/'", ".", "$", "params", "[", "'font'", "]", ";", "$", "url", "->", "set_slashargument", "(", "$", "path", ",", "'noparam'", ",", "true", ")", ";", "}", "else", "{", "$", "url", "->", "params", "(", "$", "params", ")", ";", "}", "return", "$", "url", ";", "}" ]
Return the URL for a font @param string $font the name of the font (including extension). @param string $component specification of one plugin like in get_string() @return moodle_url
[ "Return", "the", "URL", "for", "a", "font" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L2034-L2061
217,116
moodle/moodle
lib/outputlib.php
theme_config.setting_file_url
public function setting_file_url($setting, $filearea) { global $CFG; if (empty($this->settings->$setting)) { return null; } $component = 'theme_'.$this->name; $itemid = theme_get_revision(); $filepath = $this->settings->$setting; $syscontext = context_system::instance(); $url = moodle_url::make_file_url("$CFG->wwwroot/pluginfile.php", "/$syscontext->id/$component/$filearea/$itemid".$filepath); // Now this is tricky because the we can not hardcode http or https here, lets use the relative link. // Note: unfortunately moodle_url does not support //urls yet. $url = preg_replace('|^https?://|i', '//', $url->out(false)); return $url; }
php
public function setting_file_url($setting, $filearea) { global $CFG; if (empty($this->settings->$setting)) { return null; } $component = 'theme_'.$this->name; $itemid = theme_get_revision(); $filepath = $this->settings->$setting; $syscontext = context_system::instance(); $url = moodle_url::make_file_url("$CFG->wwwroot/pluginfile.php", "/$syscontext->id/$component/$filearea/$itemid".$filepath); // Now this is tricky because the we can not hardcode http or https here, lets use the relative link. // Note: unfortunately moodle_url does not support //urls yet. $url = preg_replace('|^https?://|i', '//', $url->out(false)); return $url; }
[ "public", "function", "setting_file_url", "(", "$", "setting", ",", "$", "filearea", ")", "{", "global", "$", "CFG", ";", "if", "(", "empty", "(", "$", "this", "->", "settings", "->", "$", "setting", ")", ")", "{", "return", "null", ";", "}", "$", "component", "=", "'theme_'", ".", "$", "this", "->", "name", ";", "$", "itemid", "=", "theme_get_revision", "(", ")", ";", "$", "filepath", "=", "$", "this", "->", "settings", "->", "$", "setting", ";", "$", "syscontext", "=", "context_system", "::", "instance", "(", ")", ";", "$", "url", "=", "moodle_url", "::", "make_file_url", "(", "\"$CFG->wwwroot/pluginfile.php\"", ",", "\"/$syscontext->id/$component/$filearea/$itemid\"", ".", "$", "filepath", ")", ";", "// Now this is tricky because the we can not hardcode http or https here, lets use the relative link.", "// Note: unfortunately moodle_url does not support //urls yet.", "$", "url", "=", "preg_replace", "(", "'|^https?://|i'", ",", "'//'", ",", "$", "url", "->", "out", "(", "false", ")", ")", ";", "return", "$", "url", ";", "}" ]
Returns URL to the stored file via pluginfile.php. Note the theme must also implement pluginfile.php handler, theme revision is used instead of the itemid. @param string $setting @param string $filearea @return string protocol relative URL or null if not present
[ "Returns", "URL", "to", "the", "stored", "file", "via", "pluginfile", ".", "php", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L2073-L2093
217,117
moodle/moodle
lib/outputlib.php
theme_config.setting_file_serve
public function setting_file_serve($filearea, $args, $forcedownload, $options) { global $CFG; require_once("$CFG->libdir/filelib.php"); $syscontext = context_system::instance(); $component = 'theme_'.$this->name; $revision = array_shift($args); if ($revision < 0) { $lifetime = 0; } else { $lifetime = 60*60*24*60; // By default, theme files must be cache-able by both browsers and proxies. if (!array_key_exists('cacheability', $options)) { $options['cacheability'] = 'public'; } } $fs = get_file_storage(); $relativepath = implode('/', $args); $fullpath = "/{$syscontext->id}/{$component}/{$filearea}/0/{$relativepath}"; $fullpath = rtrim($fullpath, '/'); if ($file = $fs->get_file_by_hash(sha1($fullpath))) { send_stored_file($file, $lifetime, 0, $forcedownload, $options); return true; } else { send_file_not_found(); } }
php
public function setting_file_serve($filearea, $args, $forcedownload, $options) { global $CFG; require_once("$CFG->libdir/filelib.php"); $syscontext = context_system::instance(); $component = 'theme_'.$this->name; $revision = array_shift($args); if ($revision < 0) { $lifetime = 0; } else { $lifetime = 60*60*24*60; // By default, theme files must be cache-able by both browsers and proxies. if (!array_key_exists('cacheability', $options)) { $options['cacheability'] = 'public'; } } $fs = get_file_storage(); $relativepath = implode('/', $args); $fullpath = "/{$syscontext->id}/{$component}/{$filearea}/0/{$relativepath}"; $fullpath = rtrim($fullpath, '/'); if ($file = $fs->get_file_by_hash(sha1($fullpath))) { send_stored_file($file, $lifetime, 0, $forcedownload, $options); return true; } else { send_file_not_found(); } }
[ "public", "function", "setting_file_serve", "(", "$", "filearea", ",", "$", "args", ",", "$", "forcedownload", ",", "$", "options", ")", "{", "global", "$", "CFG", ";", "require_once", "(", "\"$CFG->libdir/filelib.php\"", ")", ";", "$", "syscontext", "=", "context_system", "::", "instance", "(", ")", ";", "$", "component", "=", "'theme_'", ".", "$", "this", "->", "name", ";", "$", "revision", "=", "array_shift", "(", "$", "args", ")", ";", "if", "(", "$", "revision", "<", "0", ")", "{", "$", "lifetime", "=", "0", ";", "}", "else", "{", "$", "lifetime", "=", "60", "*", "60", "*", "24", "*", "60", ";", "// By default, theme files must be cache-able by both browsers and proxies.", "if", "(", "!", "array_key_exists", "(", "'cacheability'", ",", "$", "options", ")", ")", "{", "$", "options", "[", "'cacheability'", "]", "=", "'public'", ";", "}", "}", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "relativepath", "=", "implode", "(", "'/'", ",", "$", "args", ")", ";", "$", "fullpath", "=", "\"/{$syscontext->id}/{$component}/{$filearea}/0/{$relativepath}\"", ";", "$", "fullpath", "=", "rtrim", "(", "$", "fullpath", ",", "'/'", ")", ";", "if", "(", "$", "file", "=", "$", "fs", "->", "get_file_by_hash", "(", "sha1", "(", "$", "fullpath", ")", ")", ")", "{", "send_stored_file", "(", "$", "file", ",", "$", "lifetime", ",", "0", ",", "$", "forcedownload", ",", "$", "options", ")", ";", "return", "true", ";", "}", "else", "{", "send_file_not_found", "(", ")", ";", "}", "}" ]
Serve the theme setting file. @param string $filearea @param array $args @param bool $forcedownload @param array $options @return bool may terminate if file not found or donotdie not specified
[ "Serve", "the", "theme", "setting", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L2104-L2133
217,118
moodle/moodle
lib/outputlib.php
theme_config.resolve_image_location
public function resolve_image_location($image, $component, $svg = false) { global $CFG; if (!is_bool($svg)) { // If $svg isn't a bool then we need to decide for ourselves. $svg = $this->use_svg_icons(); } if ($component === 'moodle' or $component === 'core' or empty($component)) { if ($imagefile = $this->image_exists("$this->dir/pix_core/$image", $svg)) { return $imagefile; } foreach (array_reverse($this->parent_configs) as $parent_config) { // base first, the immediate parent last if ($imagefile = $this->image_exists("$parent_config->dir/pix_core/$image", $svg)) { return $imagefile; } } if ($imagefile = $this->image_exists("$CFG->dataroot/pix/$image", $svg)) { return $imagefile; } if ($imagefile = $this->image_exists("$CFG->dirroot/pix/$image", $svg)) { return $imagefile; } return null; } else if ($component === 'theme') { //exception if ($image === 'favicon') { return "$this->dir/pix/favicon.ico"; } if ($imagefile = $this->image_exists("$this->dir/pix/$image", $svg)) { return $imagefile; } foreach (array_reverse($this->parent_configs) as $parent_config) { // base first, the immediate parent last if ($imagefile = $this->image_exists("$parent_config->dir/pix/$image", $svg)) { return $imagefile; } } return null; } else { if (strpos($component, '_') === false) { $component = 'mod_'.$component; } list($type, $plugin) = explode('_', $component, 2); if ($imagefile = $this->image_exists("$this->dir/pix_plugins/$type/$plugin/$image", $svg)) { return $imagefile; } foreach (array_reverse($this->parent_configs) as $parent_config) { // base first, the immediate parent last if ($imagefile = $this->image_exists("$parent_config->dir/pix_plugins/$type/$plugin/$image", $svg)) { return $imagefile; } } if ($imagefile = $this->image_exists("$CFG->dataroot/pix_plugins/$type/$plugin/$image", $svg)) { return $imagefile; } $dir = core_component::get_plugin_directory($type, $plugin); if ($imagefile = $this->image_exists("$dir/pix/$image", $svg)) { return $imagefile; } return null; } }
php
public function resolve_image_location($image, $component, $svg = false) { global $CFG; if (!is_bool($svg)) { // If $svg isn't a bool then we need to decide for ourselves. $svg = $this->use_svg_icons(); } if ($component === 'moodle' or $component === 'core' or empty($component)) { if ($imagefile = $this->image_exists("$this->dir/pix_core/$image", $svg)) { return $imagefile; } foreach (array_reverse($this->parent_configs) as $parent_config) { // base first, the immediate parent last if ($imagefile = $this->image_exists("$parent_config->dir/pix_core/$image", $svg)) { return $imagefile; } } if ($imagefile = $this->image_exists("$CFG->dataroot/pix/$image", $svg)) { return $imagefile; } if ($imagefile = $this->image_exists("$CFG->dirroot/pix/$image", $svg)) { return $imagefile; } return null; } else if ($component === 'theme') { //exception if ($image === 'favicon') { return "$this->dir/pix/favicon.ico"; } if ($imagefile = $this->image_exists("$this->dir/pix/$image", $svg)) { return $imagefile; } foreach (array_reverse($this->parent_configs) as $parent_config) { // base first, the immediate parent last if ($imagefile = $this->image_exists("$parent_config->dir/pix/$image", $svg)) { return $imagefile; } } return null; } else { if (strpos($component, '_') === false) { $component = 'mod_'.$component; } list($type, $plugin) = explode('_', $component, 2); if ($imagefile = $this->image_exists("$this->dir/pix_plugins/$type/$plugin/$image", $svg)) { return $imagefile; } foreach (array_reverse($this->parent_configs) as $parent_config) { // base first, the immediate parent last if ($imagefile = $this->image_exists("$parent_config->dir/pix_plugins/$type/$plugin/$image", $svg)) { return $imagefile; } } if ($imagefile = $this->image_exists("$CFG->dataroot/pix_plugins/$type/$plugin/$image", $svg)) { return $imagefile; } $dir = core_component::get_plugin_directory($type, $plugin); if ($imagefile = $this->image_exists("$dir/pix/$image", $svg)) { return $imagefile; } return null; } }
[ "public", "function", "resolve_image_location", "(", "$", "image", ",", "$", "component", ",", "$", "svg", "=", "false", ")", "{", "global", "$", "CFG", ";", "if", "(", "!", "is_bool", "(", "$", "svg", ")", ")", "{", "// If $svg isn't a bool then we need to decide for ourselves.", "$", "svg", "=", "$", "this", "->", "use_svg_icons", "(", ")", ";", "}", "if", "(", "$", "component", "===", "'moodle'", "or", "$", "component", "===", "'core'", "or", "empty", "(", "$", "component", ")", ")", "{", "if", "(", "$", "imagefile", "=", "$", "this", "->", "image_exists", "(", "\"$this->dir/pix_core/$image\"", ",", "$", "svg", ")", ")", "{", "return", "$", "imagefile", ";", "}", "foreach", "(", "array_reverse", "(", "$", "this", "->", "parent_configs", ")", "as", "$", "parent_config", ")", "{", "// base first, the immediate parent last", "if", "(", "$", "imagefile", "=", "$", "this", "->", "image_exists", "(", "\"$parent_config->dir/pix_core/$image\"", ",", "$", "svg", ")", ")", "{", "return", "$", "imagefile", ";", "}", "}", "if", "(", "$", "imagefile", "=", "$", "this", "->", "image_exists", "(", "\"$CFG->dataroot/pix/$image\"", ",", "$", "svg", ")", ")", "{", "return", "$", "imagefile", ";", "}", "if", "(", "$", "imagefile", "=", "$", "this", "->", "image_exists", "(", "\"$CFG->dirroot/pix/$image\"", ",", "$", "svg", ")", ")", "{", "return", "$", "imagefile", ";", "}", "return", "null", ";", "}", "else", "if", "(", "$", "component", "===", "'theme'", ")", "{", "//exception", "if", "(", "$", "image", "===", "'favicon'", ")", "{", "return", "\"$this->dir/pix/favicon.ico\"", ";", "}", "if", "(", "$", "imagefile", "=", "$", "this", "->", "image_exists", "(", "\"$this->dir/pix/$image\"", ",", "$", "svg", ")", ")", "{", "return", "$", "imagefile", ";", "}", "foreach", "(", "array_reverse", "(", "$", "this", "->", "parent_configs", ")", "as", "$", "parent_config", ")", "{", "// base first, the immediate parent last", "if", "(", "$", "imagefile", "=", "$", "this", "->", "image_exists", "(", "\"$parent_config->dir/pix/$image\"", ",", "$", "svg", ")", ")", "{", "return", "$", "imagefile", ";", "}", "}", "return", "null", ";", "}", "else", "{", "if", "(", "strpos", "(", "$", "component", ",", "'_'", ")", "===", "false", ")", "{", "$", "component", "=", "'mod_'", ".", "$", "component", ";", "}", "list", "(", "$", "type", ",", "$", "plugin", ")", "=", "explode", "(", "'_'", ",", "$", "component", ",", "2", ")", ";", "if", "(", "$", "imagefile", "=", "$", "this", "->", "image_exists", "(", "\"$this->dir/pix_plugins/$type/$plugin/$image\"", ",", "$", "svg", ")", ")", "{", "return", "$", "imagefile", ";", "}", "foreach", "(", "array_reverse", "(", "$", "this", "->", "parent_configs", ")", "as", "$", "parent_config", ")", "{", "// base first, the immediate parent last", "if", "(", "$", "imagefile", "=", "$", "this", "->", "image_exists", "(", "\"$parent_config->dir/pix_plugins/$type/$plugin/$image\"", ",", "$", "svg", ")", ")", "{", "return", "$", "imagefile", ";", "}", "}", "if", "(", "$", "imagefile", "=", "$", "this", "->", "image_exists", "(", "\"$CFG->dataroot/pix_plugins/$type/$plugin/$image\"", ",", "$", "svg", ")", ")", "{", "return", "$", "imagefile", ";", "}", "$", "dir", "=", "core_component", "::", "get_plugin_directory", "(", "$", "type", ",", "$", "plugin", ")", ";", "if", "(", "$", "imagefile", "=", "$", "this", "->", "image_exists", "(", "\"$dir/pix/$image\"", ",", "$", "svg", ")", ")", "{", "return", "$", "imagefile", ";", "}", "return", "null", ";", "}", "}" ]
Resolves the real image location. $svg was introduced as an arg in 2.4. It is important because not all supported browsers support the use of SVG and we need a way in which to turn it off. By default SVG won't be used unless asked for. This is done for two reasons: 1. It ensures that we don't serve svg images unless we really want to. The admin has selected to force them, of the users browser supports SVG. 2. We only serve SVG images from locations we trust. This must NOT include any areas where the image may have been uploaded by the user due to security concerns. @param string $image name of image, may contain relative path @param string $component @param bool $svg|null Should SVG images also be looked for? If null, resorts to $CFG->svgicons if that is set; falls back to auto-detection of browser support otherwise @return string full file path
[ "Resolves", "the", "real", "image", "location", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L2152-L2214
217,119
moodle/moodle
lib/outputlib.php
theme_config.resolve_font_location
public function resolve_font_location($font, $component) { global $CFG; if ($component === 'moodle' or $component === 'core' or empty($component)) { if (file_exists("$this->dir/fonts_core/$font")) { return "$this->dir/fonts_core/$font"; } foreach (array_reverse($this->parent_configs) as $parent_config) { // Base first, the immediate parent last. if (file_exists("$parent_config->dir/fonts_core/$font")) { return "$parent_config->dir/fonts_core/$font"; } } if (file_exists("$CFG->dataroot/fonts/$font")) { return "$CFG->dataroot/fonts/$font"; } if (file_exists("$CFG->dirroot/lib/fonts/$font")) { return "$CFG->dirroot/lib/fonts/$font"; } return null; } else if ($component === 'theme') { // Exception. if (file_exists("$this->dir/fonts/$font")) { return "$this->dir/fonts/$font"; } foreach (array_reverse($this->parent_configs) as $parent_config) { // Base first, the immediate parent last. if (file_exists("$parent_config->dir/fonts/$font")) { return "$parent_config->dir/fonts/$font"; } } return null; } else { if (strpos($component, '_') === false) { $component = 'mod_'.$component; } list($type, $plugin) = explode('_', $component, 2); if (file_exists("$this->dir/fonts_plugins/$type/$plugin/$font")) { return "$this->dir/fonts_plugins/$type/$plugin/$font"; } foreach (array_reverse($this->parent_configs) as $parent_config) { // Base first, the immediate parent last. if (file_exists("$parent_config->dir/fonts_plugins/$type/$plugin/$font")) { return "$parent_config->dir/fonts_plugins/$type/$plugin/$font"; } } if (file_exists("$CFG->dataroot/fonts_plugins/$type/$plugin/$font")) { return "$CFG->dataroot/fonts_plugins/$type/$plugin/$font"; } $dir = core_component::get_plugin_directory($type, $plugin); if (file_exists("$dir/fonts/$font")) { return "$dir/fonts/$font"; } return null; } }
php
public function resolve_font_location($font, $component) { global $CFG; if ($component === 'moodle' or $component === 'core' or empty($component)) { if (file_exists("$this->dir/fonts_core/$font")) { return "$this->dir/fonts_core/$font"; } foreach (array_reverse($this->parent_configs) as $parent_config) { // Base first, the immediate parent last. if (file_exists("$parent_config->dir/fonts_core/$font")) { return "$parent_config->dir/fonts_core/$font"; } } if (file_exists("$CFG->dataroot/fonts/$font")) { return "$CFG->dataroot/fonts/$font"; } if (file_exists("$CFG->dirroot/lib/fonts/$font")) { return "$CFG->dirroot/lib/fonts/$font"; } return null; } else if ($component === 'theme') { // Exception. if (file_exists("$this->dir/fonts/$font")) { return "$this->dir/fonts/$font"; } foreach (array_reverse($this->parent_configs) as $parent_config) { // Base first, the immediate parent last. if (file_exists("$parent_config->dir/fonts/$font")) { return "$parent_config->dir/fonts/$font"; } } return null; } else { if (strpos($component, '_') === false) { $component = 'mod_'.$component; } list($type, $plugin) = explode('_', $component, 2); if (file_exists("$this->dir/fonts_plugins/$type/$plugin/$font")) { return "$this->dir/fonts_plugins/$type/$plugin/$font"; } foreach (array_reverse($this->parent_configs) as $parent_config) { // Base first, the immediate parent last. if (file_exists("$parent_config->dir/fonts_plugins/$type/$plugin/$font")) { return "$parent_config->dir/fonts_plugins/$type/$plugin/$font"; } } if (file_exists("$CFG->dataroot/fonts_plugins/$type/$plugin/$font")) { return "$CFG->dataroot/fonts_plugins/$type/$plugin/$font"; } $dir = core_component::get_plugin_directory($type, $plugin); if (file_exists("$dir/fonts/$font")) { return "$dir/fonts/$font"; } return null; } }
[ "public", "function", "resolve_font_location", "(", "$", "font", ",", "$", "component", ")", "{", "global", "$", "CFG", ";", "if", "(", "$", "component", "===", "'moodle'", "or", "$", "component", "===", "'core'", "or", "empty", "(", "$", "component", ")", ")", "{", "if", "(", "file_exists", "(", "\"$this->dir/fonts_core/$font\"", ")", ")", "{", "return", "\"$this->dir/fonts_core/$font\"", ";", "}", "foreach", "(", "array_reverse", "(", "$", "this", "->", "parent_configs", ")", "as", "$", "parent_config", ")", "{", "// Base first, the immediate parent last.", "if", "(", "file_exists", "(", "\"$parent_config->dir/fonts_core/$font\"", ")", ")", "{", "return", "\"$parent_config->dir/fonts_core/$font\"", ";", "}", "}", "if", "(", "file_exists", "(", "\"$CFG->dataroot/fonts/$font\"", ")", ")", "{", "return", "\"$CFG->dataroot/fonts/$font\"", ";", "}", "if", "(", "file_exists", "(", "\"$CFG->dirroot/lib/fonts/$font\"", ")", ")", "{", "return", "\"$CFG->dirroot/lib/fonts/$font\"", ";", "}", "return", "null", ";", "}", "else", "if", "(", "$", "component", "===", "'theme'", ")", "{", "// Exception.", "if", "(", "file_exists", "(", "\"$this->dir/fonts/$font\"", ")", ")", "{", "return", "\"$this->dir/fonts/$font\"", ";", "}", "foreach", "(", "array_reverse", "(", "$", "this", "->", "parent_configs", ")", "as", "$", "parent_config", ")", "{", "// Base first, the immediate parent last.", "if", "(", "file_exists", "(", "\"$parent_config->dir/fonts/$font\"", ")", ")", "{", "return", "\"$parent_config->dir/fonts/$font\"", ";", "}", "}", "return", "null", ";", "}", "else", "{", "if", "(", "strpos", "(", "$", "component", ",", "'_'", ")", "===", "false", ")", "{", "$", "component", "=", "'mod_'", ".", "$", "component", ";", "}", "list", "(", "$", "type", ",", "$", "plugin", ")", "=", "explode", "(", "'_'", ",", "$", "component", ",", "2", ")", ";", "if", "(", "file_exists", "(", "\"$this->dir/fonts_plugins/$type/$plugin/$font\"", ")", ")", "{", "return", "\"$this->dir/fonts_plugins/$type/$plugin/$font\"", ";", "}", "foreach", "(", "array_reverse", "(", "$", "this", "->", "parent_configs", ")", "as", "$", "parent_config", ")", "{", "// Base first, the immediate parent last.", "if", "(", "file_exists", "(", "\"$parent_config->dir/fonts_plugins/$type/$plugin/$font\"", ")", ")", "{", "return", "\"$parent_config->dir/fonts_plugins/$type/$plugin/$font\"", ";", "}", "}", "if", "(", "file_exists", "(", "\"$CFG->dataroot/fonts_plugins/$type/$plugin/$font\"", ")", ")", "{", "return", "\"$CFG->dataroot/fonts_plugins/$type/$plugin/$font\"", ";", "}", "$", "dir", "=", "core_component", "::", "get_plugin_directory", "(", "$", "type", ",", "$", "plugin", ")", ";", "if", "(", "file_exists", "(", "\"$dir/fonts/$font\"", ")", ")", "{", "return", "\"$dir/fonts/$font\"", ";", "}", "return", "null", ";", "}", "}" ]
Resolves the real font location. @param string $font name of font file @param string $component @return string full file path
[ "Resolves", "the", "real", "font", "location", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L2223-L2277
217,120
moodle/moodle
lib/outputlib.php
theme_config.use_svg_icons
public function use_svg_icons() { global $CFG; if ($this->usesvg === null) { if (!isset($CFG->svgicons)) { $this->usesvg = core_useragent::supports_svg(); } else { // Force them on/off depending upon the setting. $this->usesvg = (bool)$CFG->svgicons; } } return $this->usesvg; }
php
public function use_svg_icons() { global $CFG; if ($this->usesvg === null) { if (!isset($CFG->svgicons)) { $this->usesvg = core_useragent::supports_svg(); } else { // Force them on/off depending upon the setting. $this->usesvg = (bool)$CFG->svgicons; } } return $this->usesvg; }
[ "public", "function", "use_svg_icons", "(", ")", "{", "global", "$", "CFG", ";", "if", "(", "$", "this", "->", "usesvg", "===", "null", ")", "{", "if", "(", "!", "isset", "(", "$", "CFG", "->", "svgicons", ")", ")", "{", "$", "this", "->", "usesvg", "=", "core_useragent", "::", "supports_svg", "(", ")", ";", "}", "else", "{", "// Force them on/off depending upon the setting.", "$", "this", "->", "usesvg", "=", "(", "bool", ")", "$", "CFG", "->", "svgicons", ";", "}", "}", "return", "$", "this", "->", "usesvg", ";", "}" ]
Return true if we should look for SVG images as well. @return bool
[ "Return", "true", "if", "we", "should", "look", "for", "SVG", "images", "as", "well", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L2284-L2296
217,121
moodle/moodle
lib/outputlib.php
theme_config.image_exists
private static function image_exists($filepath, $svg = false) { if ($svg && file_exists("$filepath.svg")) { return "$filepath.svg"; } else if (file_exists("$filepath.png")) { return "$filepath.png"; } else if (file_exists("$filepath.gif")) { return "$filepath.gif"; } else if (file_exists("$filepath.jpg")) { return "$filepath.jpg"; } else if (file_exists("$filepath.jpeg")) { return "$filepath.jpeg"; } else { return false; } }
php
private static function image_exists($filepath, $svg = false) { if ($svg && file_exists("$filepath.svg")) { return "$filepath.svg"; } else if (file_exists("$filepath.png")) { return "$filepath.png"; } else if (file_exists("$filepath.gif")) { return "$filepath.gif"; } else if (file_exists("$filepath.jpg")) { return "$filepath.jpg"; } else if (file_exists("$filepath.jpeg")) { return "$filepath.jpeg"; } else { return false; } }
[ "private", "static", "function", "image_exists", "(", "$", "filepath", ",", "$", "svg", "=", "false", ")", "{", "if", "(", "$", "svg", "&&", "file_exists", "(", "\"$filepath.svg\"", ")", ")", "{", "return", "\"$filepath.svg\"", ";", "}", "else", "if", "(", "file_exists", "(", "\"$filepath.png\"", ")", ")", "{", "return", "\"$filepath.png\"", ";", "}", "else", "if", "(", "file_exists", "(", "\"$filepath.gif\"", ")", ")", "{", "return", "\"$filepath.gif\"", ";", "}", "else", "if", "(", "file_exists", "(", "\"$filepath.jpg\"", ")", ")", "{", "return", "\"$filepath.jpg\"", ";", "}", "else", "if", "(", "file_exists", "(", "\"$filepath.jpeg\"", ")", ")", "{", "return", "\"$filepath.jpeg\"", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Checks if file with any image extension exists. The order to these images was adjusted prior to the release of 2.4 At that point the were the following image counts in Moodle core: - png = 667 in pix dirs (1499 total) - gif = 385 in pix dirs (606 total) - jpg = 62 in pix dirs (74 total) - jpeg = 0 in pix dirs (1 total) There is work in progress to move towards SVG presently hence that has been prioritiesed. @param string $filepath @param bool $svg If set to true SVG images will also be looked for. @return string image name with extension
[ "Checks", "if", "file", "with", "any", "image", "extension", "exists", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L2347-L2361
217,122
moodle/moodle
lib/outputlib.php
theme_config.find_theme_config
private static function find_theme_config($themename, $settings, $parentscheck = true) { // We have to use the variable name $THEME (upper case) because that // is what is used in theme config.php files. if (!$dir = theme_config::find_theme_location($themename)) { return null; } $THEME = new stdClass(); $THEME->name = $themename; $THEME->dir = $dir; $THEME->settings = $settings; global $CFG; // just in case somebody tries to use $CFG in theme config include("$THEME->dir/config.php"); // verify the theme configuration is OK if (!is_array($THEME->parents)) { // parents option is mandatory now return null; } else { // We use $parentscheck to only check the direct parents (avoid infinite loop). if ($parentscheck) { // Find all parent theme configs. foreach ($THEME->parents as $parent) { $parentconfig = theme_config::find_theme_config($parent, $settings, false); if (empty($parentconfig)) { return null; } } } } return $THEME; }
php
private static function find_theme_config($themename, $settings, $parentscheck = true) { // We have to use the variable name $THEME (upper case) because that // is what is used in theme config.php files. if (!$dir = theme_config::find_theme_location($themename)) { return null; } $THEME = new stdClass(); $THEME->name = $themename; $THEME->dir = $dir; $THEME->settings = $settings; global $CFG; // just in case somebody tries to use $CFG in theme config include("$THEME->dir/config.php"); // verify the theme configuration is OK if (!is_array($THEME->parents)) { // parents option is mandatory now return null; } else { // We use $parentscheck to only check the direct parents (avoid infinite loop). if ($parentscheck) { // Find all parent theme configs. foreach ($THEME->parents as $parent) { $parentconfig = theme_config::find_theme_config($parent, $settings, false); if (empty($parentconfig)) { return null; } } } } return $THEME; }
[ "private", "static", "function", "find_theme_config", "(", "$", "themename", ",", "$", "settings", ",", "$", "parentscheck", "=", "true", ")", "{", "// We have to use the variable name $THEME (upper case) because that", "// is what is used in theme config.php files.", "if", "(", "!", "$", "dir", "=", "theme_config", "::", "find_theme_location", "(", "$", "themename", ")", ")", "{", "return", "null", ";", "}", "$", "THEME", "=", "new", "stdClass", "(", ")", ";", "$", "THEME", "->", "name", "=", "$", "themename", ";", "$", "THEME", "->", "dir", "=", "$", "dir", ";", "$", "THEME", "->", "settings", "=", "$", "settings", ";", "global", "$", "CFG", ";", "// just in case somebody tries to use $CFG in theme config", "include", "(", "\"$THEME->dir/config.php\"", ")", ";", "// verify the theme configuration is OK", "if", "(", "!", "is_array", "(", "$", "THEME", "->", "parents", ")", ")", "{", "// parents option is mandatory now", "return", "null", ";", "}", "else", "{", "// We use $parentscheck to only check the direct parents (avoid infinite loop).", "if", "(", "$", "parentscheck", ")", "{", "// Find all parent theme configs.", "foreach", "(", "$", "THEME", "->", "parents", "as", "$", "parent", ")", "{", "$", "parentconfig", "=", "theme_config", "::", "find_theme_config", "(", "$", "parent", ",", "$", "settings", ",", "false", ")", ";", "if", "(", "empty", "(", "$", "parentconfig", ")", ")", "{", "return", "null", ";", "}", "}", "}", "}", "return", "$", "THEME", ";", "}" ]
Loads the theme config from config.php file. @param string $themename @param stdClass $settings from config_plugins table @param boolean $parentscheck true to also check the parents. . @return stdClass The theme configuration
[ "Loads", "the", "theme", "config", "from", "config", ".", "php", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L2371-L2405
217,123
moodle/moodle
lib/outputlib.php
theme_config.find_theme_location
private static function find_theme_location($themename) { global $CFG; if (file_exists("$CFG->dirroot/theme/$themename/config.php")) { $dir = "$CFG->dirroot/theme/$themename"; } else if (!empty($CFG->themedir) and file_exists("$CFG->themedir/$themename/config.php")) { $dir = "$CFG->themedir/$themename"; } else { return null; } if (file_exists("$dir/styles.php")) { //legacy theme - needs to be upgraded - upgrade info is displayed on the admin settings page return null; } return $dir; }
php
private static function find_theme_location($themename) { global $CFG; if (file_exists("$CFG->dirroot/theme/$themename/config.php")) { $dir = "$CFG->dirroot/theme/$themename"; } else if (!empty($CFG->themedir) and file_exists("$CFG->themedir/$themename/config.php")) { $dir = "$CFG->themedir/$themename"; } else { return null; } if (file_exists("$dir/styles.php")) { //legacy theme - needs to be upgraded - upgrade info is displayed on the admin settings page return null; } return $dir; }
[ "private", "static", "function", "find_theme_location", "(", "$", "themename", ")", "{", "global", "$", "CFG", ";", "if", "(", "file_exists", "(", "\"$CFG->dirroot/theme/$themename/config.php\"", ")", ")", "{", "$", "dir", "=", "\"$CFG->dirroot/theme/$themename\"", ";", "}", "else", "if", "(", "!", "empty", "(", "$", "CFG", "->", "themedir", ")", "and", "file_exists", "(", "\"$CFG->themedir/$themename/config.php\"", ")", ")", "{", "$", "dir", "=", "\"$CFG->themedir/$themename\"", ";", "}", "else", "{", "return", "null", ";", "}", "if", "(", "file_exists", "(", "\"$dir/styles.php\"", ")", ")", "{", "//legacy theme - needs to be upgraded - upgrade info is displayed on the admin settings page", "return", "null", ";", "}", "return", "$", "dir", ";", "}" ]
Finds the theme location and verifies the theme has all needed files and is not obsoleted. @param string $themename @return string full dir path or null if not found
[ "Finds", "the", "theme", "location", "and", "verifies", "the", "theme", "has", "all", "needed", "files", "and", "is", "not", "obsoleted", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L2414-L2433
217,124
moodle/moodle
lib/outputlib.php
theme_config.get_renderer
public function get_renderer(moodle_page $page, $component, $subtype = null, $target = null) { if (is_null($this->rf)) { $classname = $this->rendererfactory; $this->rf = new $classname($this); } return $this->rf->get_renderer($page, $component, $subtype, $target); }
php
public function get_renderer(moodle_page $page, $component, $subtype = null, $target = null) { if (is_null($this->rf)) { $classname = $this->rendererfactory; $this->rf = new $classname($this); } return $this->rf->get_renderer($page, $component, $subtype, $target); }
[ "public", "function", "get_renderer", "(", "moodle_page", "$", "page", ",", "$", "component", ",", "$", "subtype", "=", "null", ",", "$", "target", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "rf", ")", ")", "{", "$", "classname", "=", "$", "this", "->", "rendererfactory", ";", "$", "this", "->", "rf", "=", "new", "$", "classname", "(", "$", "this", ")", ";", "}", "return", "$", "this", "->", "rf", "->", "get_renderer", "(", "$", "page", ",", "$", "component", ",", "$", "subtype", ",", "$", "target", ")", ";", "}" ]
Get the renderer for a part of Moodle for this theme. @param moodle_page $page the page we are rendering @param string $component the name of part of moodle. E.g. 'core', 'quiz', 'qtype_multichoice'. @param string $subtype optional subtype such as 'news' resulting to 'mod_forum_news' @param string $target one of rendering target constants @return renderer_base the requested renderer.
[ "Get", "the", "renderer", "for", "a", "part", "of", "Moodle", "for", "this", "theme", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L2444-L2451
217,125
moodle/moodle
lib/outputlib.php
theme_config.layout_file
public function layout_file($pagelayout) { global $CFG; $layoutinfo = $this->layout_info_for_page($pagelayout); $layoutfile = $layoutinfo['file']; if (array_key_exists('theme', $layoutinfo)) { $themes = array($layoutinfo['theme']); } else { $themes = array_merge(array($this->name),$this->parents); } foreach ($themes as $theme) { if ($dir = $this->find_theme_location($theme)) { $path = "$dir/layout/$layoutfile"; // Check the template exists, return general base theme template if not. if (is_readable($path)) { return $path; } } } debugging('Can not find layout file for: ' . $pagelayout); // fallback to standard normal layout return "$CFG->dirroot/theme/base/layout/general.php"; }
php
public function layout_file($pagelayout) { global $CFG; $layoutinfo = $this->layout_info_for_page($pagelayout); $layoutfile = $layoutinfo['file']; if (array_key_exists('theme', $layoutinfo)) { $themes = array($layoutinfo['theme']); } else { $themes = array_merge(array($this->name),$this->parents); } foreach ($themes as $theme) { if ($dir = $this->find_theme_location($theme)) { $path = "$dir/layout/$layoutfile"; // Check the template exists, return general base theme template if not. if (is_readable($path)) { return $path; } } } debugging('Can not find layout file for: ' . $pagelayout); // fallback to standard normal layout return "$CFG->dirroot/theme/base/layout/general.php"; }
[ "public", "function", "layout_file", "(", "$", "pagelayout", ")", "{", "global", "$", "CFG", ";", "$", "layoutinfo", "=", "$", "this", "->", "layout_info_for_page", "(", "$", "pagelayout", ")", ";", "$", "layoutfile", "=", "$", "layoutinfo", "[", "'file'", "]", ";", "if", "(", "array_key_exists", "(", "'theme'", ",", "$", "layoutinfo", ")", ")", "{", "$", "themes", "=", "array", "(", "$", "layoutinfo", "[", "'theme'", "]", ")", ";", "}", "else", "{", "$", "themes", "=", "array_merge", "(", "array", "(", "$", "this", "->", "name", ")", ",", "$", "this", "->", "parents", ")", ";", "}", "foreach", "(", "$", "themes", "as", "$", "theme", ")", "{", "if", "(", "$", "dir", "=", "$", "this", "->", "find_theme_location", "(", "$", "theme", ")", ")", "{", "$", "path", "=", "\"$dir/layout/$layoutfile\"", ";", "// Check the template exists, return general base theme template if not.", "if", "(", "is_readable", "(", "$", "path", ")", ")", "{", "return", "$", "path", ";", "}", "}", "}", "debugging", "(", "'Can not find layout file for: '", ".", "$", "pagelayout", ")", ";", "// fallback to standard normal layout", "return", "\"$CFG->dirroot/theme/base/layout/general.php\"", ";", "}" ]
Given the settings of this theme, and the page pagelayout, return the full path of the page layout file to use. Used by {@link core_renderer::header()}. @param string $pagelayout the the page layout name. @return string Full path to the lyout file to use
[ "Given", "the", "settings", "of", "this", "theme", "and", "the", "page", "pagelayout", "return", "the", "full", "path", "of", "the", "page", "layout", "file", "to", "use", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L2477-L2503
217,126
moodle/moodle
lib/outputlib.php
theme_config.setup_blocks
public function setup_blocks($pagelayout, $blockmanager) { $layoutinfo = $this->layout_info_for_page($pagelayout); if (!empty($layoutinfo['regions'])) { $blockmanager->add_regions($layoutinfo['regions'], false); $blockmanager->set_default_region($layoutinfo['defaultregion']); } }
php
public function setup_blocks($pagelayout, $blockmanager) { $layoutinfo = $this->layout_info_for_page($pagelayout); if (!empty($layoutinfo['regions'])) { $blockmanager->add_regions($layoutinfo['regions'], false); $blockmanager->set_default_region($layoutinfo['defaultregion']); } }
[ "public", "function", "setup_blocks", "(", "$", "pagelayout", ",", "$", "blockmanager", ")", "{", "$", "layoutinfo", "=", "$", "this", "->", "layout_info_for_page", "(", "$", "pagelayout", ")", ";", "if", "(", "!", "empty", "(", "$", "layoutinfo", "[", "'regions'", "]", ")", ")", "{", "$", "blockmanager", "->", "add_regions", "(", "$", "layoutinfo", "[", "'regions'", "]", ",", "false", ")", ";", "$", "blockmanager", "->", "set_default_region", "(", "$", "layoutinfo", "[", "'defaultregion'", "]", ")", ";", "}", "}" ]
Inform a block_manager about the block regions this theme wants on this page layout. @param string $pagelayout the general type of the page. @param block_manager $blockmanager the block_manger to set up.
[ "Inform", "a", "block_manager", "about", "the", "block", "regions", "this", "theme", "wants", "on", "this", "page", "layout", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L2526-L2532
217,127
moodle/moodle
lib/outputlib.php
theme_config.get_region_name
protected function get_region_name($region, $theme) { $regionstring = get_string('region-' . $region, 'theme_' . $theme); // A name exists in this theme, so use it if (substr($regionstring, 0, 1) != '[') { return $regionstring; } // Otherwise, try to find one elsewhere // Check parents, if any foreach ($this->parents as $parentthemename) { $regionstring = get_string('region-' . $region, 'theme_' . $parentthemename); if (substr($regionstring, 0, 1) != '[') { return $regionstring; } } // Last resort, try the boost theme for names return get_string('region-' . $region, 'theme_boost'); }
php
protected function get_region_name($region, $theme) { $regionstring = get_string('region-' . $region, 'theme_' . $theme); // A name exists in this theme, so use it if (substr($regionstring, 0, 1) != '[') { return $regionstring; } // Otherwise, try to find one elsewhere // Check parents, if any foreach ($this->parents as $parentthemename) { $regionstring = get_string('region-' . $region, 'theme_' . $parentthemename); if (substr($regionstring, 0, 1) != '[') { return $regionstring; } } // Last resort, try the boost theme for names return get_string('region-' . $region, 'theme_boost'); }
[ "protected", "function", "get_region_name", "(", "$", "region", ",", "$", "theme", ")", "{", "$", "regionstring", "=", "get_string", "(", "'region-'", ".", "$", "region", ",", "'theme_'", ".", "$", "theme", ")", ";", "// A name exists in this theme, so use it", "if", "(", "substr", "(", "$", "regionstring", ",", "0", ",", "1", ")", "!=", "'['", ")", "{", "return", "$", "regionstring", ";", "}", "// Otherwise, try to find one elsewhere", "// Check parents, if any", "foreach", "(", "$", "this", "->", "parents", "as", "$", "parentthemename", ")", "{", "$", "regionstring", "=", "get_string", "(", "'region-'", ".", "$", "region", ",", "'theme_'", ".", "$", "parentthemename", ")", ";", "if", "(", "substr", "(", "$", "regionstring", ",", "0", ",", "1", ")", "!=", "'['", ")", "{", "return", "$", "regionstring", ";", "}", "}", "// Last resort, try the boost theme for names", "return", "get_string", "(", "'region-'", ".", "$", "region", ",", "'theme_boost'", ")", ";", "}" ]
Gets the visible name for the requested block region. @param string $region The region name to get @param string $theme The theme the region belongs to (may come from the parent theme) @return string
[ "Gets", "the", "visible", "name", "for", "the", "requested", "block", "region", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L2541-L2559
217,128
moodle/moodle
lib/outputlib.php
theme_config.get_all_block_regions
public function get_all_block_regions() { $regions = array(); foreach ($this->layouts as $layoutinfo) { foreach ($layoutinfo['regions'] as $region) { $regions[$region] = $this->get_region_name($region, $this->name); } } return $regions; }
php
public function get_all_block_regions() { $regions = array(); foreach ($this->layouts as $layoutinfo) { foreach ($layoutinfo['regions'] as $region) { $regions[$region] = $this->get_region_name($region, $this->name); } } return $regions; }
[ "public", "function", "get_all_block_regions", "(", ")", "{", "$", "regions", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "layouts", "as", "$", "layoutinfo", ")", "{", "foreach", "(", "$", "layoutinfo", "[", "'regions'", "]", "as", "$", "region", ")", "{", "$", "regions", "[", "$", "region", "]", "=", "$", "this", "->", "get_region_name", "(", "$", "region", ",", "$", "this", "->", "name", ")", ";", "}", "}", "return", "$", "regions", ";", "}" ]
Get the list of all block regions known to this theme in all templates. @return array internal region name => human readable name.
[ "Get", "the", "list", "of", "all", "block", "regions", "known", "to", "this", "theme", "in", "all", "templates", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L2566-L2574
217,129
moodle/moodle
lib/outputlib.php
theme_config.get_block_render_method
public function get_block_render_method() { if ($this->blockrendermethod) { // Return the specified block render method. return $this->blockrendermethod; } // Its not explicitly set, check the parent theme configs. foreach ($this->parent_configs as $config) { if (isset($config->blockrendermethod)) { return $config->blockrendermethod; } } // Default it to blocks. return 'blocks'; }
php
public function get_block_render_method() { if ($this->blockrendermethod) { // Return the specified block render method. return $this->blockrendermethod; } // Its not explicitly set, check the parent theme configs. foreach ($this->parent_configs as $config) { if (isset($config->blockrendermethod)) { return $config->blockrendermethod; } } // Default it to blocks. return 'blocks'; }
[ "public", "function", "get_block_render_method", "(", ")", "{", "if", "(", "$", "this", "->", "blockrendermethod", ")", "{", "// Return the specified block render method.", "return", "$", "this", "->", "blockrendermethod", ";", "}", "// Its not explicitly set, check the parent theme configs.", "foreach", "(", "$", "this", "->", "parent_configs", "as", "$", "config", ")", "{", "if", "(", "isset", "(", "$", "config", "->", "blockrendermethod", ")", ")", "{", "return", "$", "config", "->", "blockrendermethod", ";", "}", "}", "// Default it to blocks.", "return", "'blocks'", ";", "}" ]
Returns the block render method. It is set by the theme via: $THEME->blockrendermethod = '...'; It can be one of two values, blocks or blocks_for_region. It should be set to the method being used by the theme layouts. @return string
[ "Returns", "the", "block", "render", "method", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L2596-L2609
217,130
moodle/moodle
lib/outputlib.php
theme_config.get_css_tree_post_processor
public function get_css_tree_post_processor() { $configs = [$this] + $this->parent_configs; foreach ($configs as $config) { if (!empty($config->csstreepostprocessor) && is_callable($config->csstreepostprocessor)) { return $config->csstreepostprocessor; } } return null; }
php
public function get_css_tree_post_processor() { $configs = [$this] + $this->parent_configs; foreach ($configs as $config) { if (!empty($config->csstreepostprocessor) && is_callable($config->csstreepostprocessor)) { return $config->csstreepostprocessor; } } return null; }
[ "public", "function", "get_css_tree_post_processor", "(", ")", "{", "$", "configs", "=", "[", "$", "this", "]", "+", "$", "this", "->", "parent_configs", ";", "foreach", "(", "$", "configs", "as", "$", "config", ")", "{", "if", "(", "!", "empty", "(", "$", "config", "->", "csstreepostprocessor", ")", "&&", "is_callable", "(", "$", "config", "->", "csstreepostprocessor", ")", ")", "{", "return", "$", "config", "->", "csstreepostprocessor", ";", "}", "}", "return", "null", ";", "}" ]
Get the callable for CSS tree post processing. @return string|null
[ "Get", "the", "callable", "for", "CSS", "tree", "post", "processing", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L2616-L2624
217,131
moodle/moodle
lib/outputlib.php
xhtml_container_stack.push
public function push($type, $closehtml) { $container = new stdClass; $container->type = $type; $container->closehtml = $closehtml; if ($this->isdebugging) { $this->log('Open', $type); } array_push($this->opencontainers, $container); }
php
public function push($type, $closehtml) { $container = new stdClass; $container->type = $type; $container->closehtml = $closehtml; if ($this->isdebugging) { $this->log('Open', $type); } array_push($this->opencontainers, $container); }
[ "public", "function", "push", "(", "$", "type", ",", "$", "closehtml", ")", "{", "$", "container", "=", "new", "stdClass", ";", "$", "container", "->", "type", "=", "$", "type", ";", "$", "container", "->", "closehtml", "=", "$", "closehtml", ";", "if", "(", "$", "this", "->", "isdebugging", ")", "{", "$", "this", "->", "log", "(", "'Open'", ",", "$", "type", ")", ";", "}", "array_push", "(", "$", "this", "->", "opencontainers", ",", "$", "container", ")", ";", "}" ]
Push the close HTML for a recently opened container onto the stack. @param string $type The type of container. This is checked when {@link pop()} is called and must match, otherwise a developer debug warning is output. @param string $closehtml The HTML required to close the container.
[ "Push", "the", "close", "HTML", "for", "a", "recently", "opened", "container", "onto", "the", "stack", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputlib.php#L2676-L2684
217,132
moodle/moodle
backup/util/helper/convert_helper.class.php
convert_helper.available_converters
public static function available_converters($restore=true) { global $CFG; $converters = array(); $plugins = get_list_of_plugins('backup/converter'); foreach ($plugins as $name) { $filename = $restore ? 'lib.php' : 'backuplib.php'; $classuf = $restore ? '_converter' : '_export_converter'; $classfile = "{$CFG->dirroot}/backup/converter/{$name}/{$filename}"; $classname = "{$name}{$classuf}"; $zip_contents = "{$name}_zip_contents"; $store_backup_file = "{$name}_store_backup_file"; $convert = "{$name}_backup_convert"; if (!file_exists($classfile)) { throw new convert_helper_exception('converter_classfile_not_found', $classfile); } require_once($classfile); if (!class_exists($classname)) { throw new convert_helper_exception('converter_classname_not_found', $classname); } if (call_user_func($classname .'::is_available')) { if (!$restore) { if (!class_exists($zip_contents)) { throw new convert_helper_exception('converter_classname_not_found', $zip_contents); } if (!class_exists($store_backup_file)) { throw new convert_helper_exception('converter_classname_not_found', $store_backup_file); } if (!class_exists($convert)) { throw new convert_helper_exception('converter_classname_not_found', $convert); } } $converters[] = $name; } } return $converters; }
php
public static function available_converters($restore=true) { global $CFG; $converters = array(); $plugins = get_list_of_plugins('backup/converter'); foreach ($plugins as $name) { $filename = $restore ? 'lib.php' : 'backuplib.php'; $classuf = $restore ? '_converter' : '_export_converter'; $classfile = "{$CFG->dirroot}/backup/converter/{$name}/{$filename}"; $classname = "{$name}{$classuf}"; $zip_contents = "{$name}_zip_contents"; $store_backup_file = "{$name}_store_backup_file"; $convert = "{$name}_backup_convert"; if (!file_exists($classfile)) { throw new convert_helper_exception('converter_classfile_not_found', $classfile); } require_once($classfile); if (!class_exists($classname)) { throw new convert_helper_exception('converter_classname_not_found', $classname); } if (call_user_func($classname .'::is_available')) { if (!$restore) { if (!class_exists($zip_contents)) { throw new convert_helper_exception('converter_classname_not_found', $zip_contents); } if (!class_exists($store_backup_file)) { throw new convert_helper_exception('converter_classname_not_found', $store_backup_file); } if (!class_exists($convert)) { throw new convert_helper_exception('converter_classname_not_found', $convert); } } $converters[] = $name; } } return $converters; }
[ "public", "static", "function", "available_converters", "(", "$", "restore", "=", "true", ")", "{", "global", "$", "CFG", ";", "$", "converters", "=", "array", "(", ")", ";", "$", "plugins", "=", "get_list_of_plugins", "(", "'backup/converter'", ")", ";", "foreach", "(", "$", "plugins", "as", "$", "name", ")", "{", "$", "filename", "=", "$", "restore", "?", "'lib.php'", ":", "'backuplib.php'", ";", "$", "classuf", "=", "$", "restore", "?", "'_converter'", ":", "'_export_converter'", ";", "$", "classfile", "=", "\"{$CFG->dirroot}/backup/converter/{$name}/{$filename}\"", ";", "$", "classname", "=", "\"{$name}{$classuf}\"", ";", "$", "zip_contents", "=", "\"{$name}_zip_contents\"", ";", "$", "store_backup_file", "=", "\"{$name}_store_backup_file\"", ";", "$", "convert", "=", "\"{$name}_backup_convert\"", ";", "if", "(", "!", "file_exists", "(", "$", "classfile", ")", ")", "{", "throw", "new", "convert_helper_exception", "(", "'converter_classfile_not_found'", ",", "$", "classfile", ")", ";", "}", "require_once", "(", "$", "classfile", ")", ";", "if", "(", "!", "class_exists", "(", "$", "classname", ")", ")", "{", "throw", "new", "convert_helper_exception", "(", "'converter_classname_not_found'", ",", "$", "classname", ")", ";", "}", "if", "(", "call_user_func", "(", "$", "classname", ".", "'::is_available'", ")", ")", "{", "if", "(", "!", "$", "restore", ")", "{", "if", "(", "!", "class_exists", "(", "$", "zip_contents", ")", ")", "{", "throw", "new", "convert_helper_exception", "(", "'converter_classname_not_found'", ",", "$", "zip_contents", ")", ";", "}", "if", "(", "!", "class_exists", "(", "$", "store_backup_file", ")", ")", "{", "throw", "new", "convert_helper_exception", "(", "'converter_classname_not_found'", ",", "$", "store_backup_file", ")", ";", "}", "if", "(", "!", "class_exists", "(", "$", "convert", ")", ")", "{", "throw", "new", "convert_helper_exception", "(", "'converter_classname_not_found'", ",", "$", "convert", ")", ";", "}", "}", "$", "converters", "[", "]", "=", "$", "name", ";", "}", "}", "return", "$", "converters", ";", "}" ]
Returns the list of all available converters and loads their classes Converter must be installed as a directory in backup/converter/ and its method is_available() must return true to get to the list. @see base_converter::is_available() @return array of strings
[ "Returns", "the", "list", "of", "all", "available", "converters", "and", "loads", "their", "classes" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/helper/convert_helper.class.php#L53-L97
217,133
moodle/moodle
backup/util/helper/convert_helper.class.php
convert_helper.detect_moodle2_format
public static function detect_moodle2_format($tempdir) { $dirpath = make_backup_temp_directory($tempdir, false); if (!is_dir($dirpath)) { throw new convert_helper_exception('tmp_backup_directory_not_found', $dirpath); } $filepath = $dirpath . '/moodle_backup.xml'; if (!file_exists($filepath)) { return false; } $handle = fopen($filepath, 'r'); $firstchars = fread($handle, 200); $status = fclose($handle); if (strpos($firstchars,'<?xml version="1.0" encoding="UTF-8"?>') !== false and strpos($firstchars,'<moodle_backup>') !== false and strpos($firstchars,'<information>') !== false) { return true; } return false; }
php
public static function detect_moodle2_format($tempdir) { $dirpath = make_backup_temp_directory($tempdir, false); if (!is_dir($dirpath)) { throw new convert_helper_exception('tmp_backup_directory_not_found', $dirpath); } $filepath = $dirpath . '/moodle_backup.xml'; if (!file_exists($filepath)) { return false; } $handle = fopen($filepath, 'r'); $firstchars = fread($handle, 200); $status = fclose($handle); if (strpos($firstchars,'<?xml version="1.0" encoding="UTF-8"?>') !== false and strpos($firstchars,'<moodle_backup>') !== false and strpos($firstchars,'<information>') !== false) { return true; } return false; }
[ "public", "static", "function", "detect_moodle2_format", "(", "$", "tempdir", ")", "{", "$", "dirpath", "=", "make_backup_temp_directory", "(", "$", "tempdir", ",", "false", ")", ";", "if", "(", "!", "is_dir", "(", "$", "dirpath", ")", ")", "{", "throw", "new", "convert_helper_exception", "(", "'tmp_backup_directory_not_found'", ",", "$", "dirpath", ")", ";", "}", "$", "filepath", "=", "$", "dirpath", ".", "'/moodle_backup.xml'", ";", "if", "(", "!", "file_exists", "(", "$", "filepath", ")", ")", "{", "return", "false", ";", "}", "$", "handle", "=", "fopen", "(", "$", "filepath", ",", "'r'", ")", ";", "$", "firstchars", "=", "fread", "(", "$", "handle", ",", "200", ")", ";", "$", "status", "=", "fclose", "(", "$", "handle", ")", ";", "if", "(", "strpos", "(", "$", "firstchars", ",", "'<?xml version=\"1.0\" encoding=\"UTF-8\"?>'", ")", "!==", "false", "and", "strpos", "(", "$", "firstchars", ",", "'<moodle_backup>'", ")", "!==", "false", "and", "strpos", "(", "$", "firstchars", ",", "'<information>'", ")", "!==", "false", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Detects if the given folder contains an unpacked moodle2 backup @param string $tempdir the name of the backup directory @return boolean true if moodle2 format detected, false otherwise
[ "Detects", "if", "the", "given", "folder", "contains", "an", "unpacked", "moodle2", "backup" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/helper/convert_helper.class.php#L133-L155
217,134
moodle/moodle
backup/util/helper/convert_helper.class.php
convert_helper.to_moodle2_format
public static function to_moodle2_format($tempdir, $format = null, $logger = null) { if (is_null($format)) { $format = backup_general_helper::detect_backup_format($tempdir); } // get the supported conversion paths from all available converters $converters = self::available_converters(); $descriptions = array(); foreach ($converters as $name) { $classname = "{$name}_converter"; if (!class_exists($classname)) { throw new convert_helper_exception('class_not_loaded', $classname); } if ($logger instanceof base_logger) { backup_helper::log('available converter', backup::LOG_DEBUG, $classname, 1, false, $logger); } $descriptions[$name] = call_user_func($classname .'::description'); } // choose the best conversion path for the given format $path = self::choose_conversion_path($format, $descriptions); if (empty($path)) { if ($logger instanceof base_logger) { backup_helper::log('unable to find the conversion path', backup::LOG_ERROR, null, 0, false, $logger); } return false; } if ($logger instanceof base_logger) { backup_helper::log('conversion path established', backup::LOG_INFO, implode(' => ', array_merge($path, array('moodle2'))), 0, false, $logger); } foreach ($path as $name) { if ($logger instanceof base_logger) { backup_helper::log('running converter', backup::LOG_INFO, $name, 0, false, $logger); } $converter = convert_factory::get_converter($name, $tempdir, $logger); $converter->convert(); } // make sure we ended with moodle2 format if (!self::detect_moodle2_format($tempdir)) { throw new convert_helper_exception('conversion_failed'); } return true; }
php
public static function to_moodle2_format($tempdir, $format = null, $logger = null) { if (is_null($format)) { $format = backup_general_helper::detect_backup_format($tempdir); } // get the supported conversion paths from all available converters $converters = self::available_converters(); $descriptions = array(); foreach ($converters as $name) { $classname = "{$name}_converter"; if (!class_exists($classname)) { throw new convert_helper_exception('class_not_loaded', $classname); } if ($logger instanceof base_logger) { backup_helper::log('available converter', backup::LOG_DEBUG, $classname, 1, false, $logger); } $descriptions[$name] = call_user_func($classname .'::description'); } // choose the best conversion path for the given format $path = self::choose_conversion_path($format, $descriptions); if (empty($path)) { if ($logger instanceof base_logger) { backup_helper::log('unable to find the conversion path', backup::LOG_ERROR, null, 0, false, $logger); } return false; } if ($logger instanceof base_logger) { backup_helper::log('conversion path established', backup::LOG_INFO, implode(' => ', array_merge($path, array('moodle2'))), 0, false, $logger); } foreach ($path as $name) { if ($logger instanceof base_logger) { backup_helper::log('running converter', backup::LOG_INFO, $name, 0, false, $logger); } $converter = convert_factory::get_converter($name, $tempdir, $logger); $converter->convert(); } // make sure we ended with moodle2 format if (!self::detect_moodle2_format($tempdir)) { throw new convert_helper_exception('conversion_failed'); } return true; }
[ "public", "static", "function", "to_moodle2_format", "(", "$", "tempdir", ",", "$", "format", "=", "null", ",", "$", "logger", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "format", ")", ")", "{", "$", "format", "=", "backup_general_helper", "::", "detect_backup_format", "(", "$", "tempdir", ")", ";", "}", "// get the supported conversion paths from all available converters", "$", "converters", "=", "self", "::", "available_converters", "(", ")", ";", "$", "descriptions", "=", "array", "(", ")", ";", "foreach", "(", "$", "converters", "as", "$", "name", ")", "{", "$", "classname", "=", "\"{$name}_converter\"", ";", "if", "(", "!", "class_exists", "(", "$", "classname", ")", ")", "{", "throw", "new", "convert_helper_exception", "(", "'class_not_loaded'", ",", "$", "classname", ")", ";", "}", "if", "(", "$", "logger", "instanceof", "base_logger", ")", "{", "backup_helper", "::", "log", "(", "'available converter'", ",", "backup", "::", "LOG_DEBUG", ",", "$", "classname", ",", "1", ",", "false", ",", "$", "logger", ")", ";", "}", "$", "descriptions", "[", "$", "name", "]", "=", "call_user_func", "(", "$", "classname", ".", "'::description'", ")", ";", "}", "// choose the best conversion path for the given format", "$", "path", "=", "self", "::", "choose_conversion_path", "(", "$", "format", ",", "$", "descriptions", ")", ";", "if", "(", "empty", "(", "$", "path", ")", ")", "{", "if", "(", "$", "logger", "instanceof", "base_logger", ")", "{", "backup_helper", "::", "log", "(", "'unable to find the conversion path'", ",", "backup", "::", "LOG_ERROR", ",", "null", ",", "0", ",", "false", ",", "$", "logger", ")", ";", "}", "return", "false", ";", "}", "if", "(", "$", "logger", "instanceof", "base_logger", ")", "{", "backup_helper", "::", "log", "(", "'conversion path established'", ",", "backup", "::", "LOG_INFO", ",", "implode", "(", "' => '", ",", "array_merge", "(", "$", "path", ",", "array", "(", "'moodle2'", ")", ")", ")", ",", "0", ",", "false", ",", "$", "logger", ")", ";", "}", "foreach", "(", "$", "path", "as", "$", "name", ")", "{", "if", "(", "$", "logger", "instanceof", "base_logger", ")", "{", "backup_helper", "::", "log", "(", "'running converter'", ",", "backup", "::", "LOG_INFO", ",", "$", "name", ",", "0", ",", "false", ",", "$", "logger", ")", ";", "}", "$", "converter", "=", "convert_factory", "::", "get_converter", "(", "$", "name", ",", "$", "tempdir", ",", "$", "logger", ")", ";", "$", "converter", "->", "convert", "(", ")", ";", "}", "// make sure we ended with moodle2 format", "if", "(", "!", "self", "::", "detect_moodle2_format", "(", "$", "tempdir", ")", ")", "{", "throw", "new", "convert_helper_exception", "(", "'conversion_failed'", ")", ";", "}", "return", "true", ";", "}" ]
Converts the given directory with the backup into moodle2 format @param string $tempdir The directory to convert @param string $format The current format, if already detected @param base_logger|null if the conversion should be logged, use this logger @throws convert_helper_exception @return bool false if unable to find the conversion path, true otherwise
[ "Converts", "the", "given", "directory", "with", "the", "backup", "into", "moodle2", "format" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/helper/convert_helper.class.php#L166-L215
217,135
moodle/moodle
question/format/gift/format.php
qformat_gift.write_general_feedback
public function write_general_feedback($question, $indent = "\t") { $generalfeedback = $this->write_questiontext($question->generalfeedback, $question->generalfeedbackformat, $question->questiontextformat); if ($generalfeedback) { $generalfeedback = '####' . $generalfeedback; if ($indent) { $generalfeedback = $indent . $generalfeedback . "\n"; } } return $generalfeedback; }
php
public function write_general_feedback($question, $indent = "\t") { $generalfeedback = $this->write_questiontext($question->generalfeedback, $question->generalfeedbackformat, $question->questiontextformat); if ($generalfeedback) { $generalfeedback = '####' . $generalfeedback; if ($indent) { $generalfeedback = $indent . $generalfeedback . "\n"; } } return $generalfeedback; }
[ "public", "function", "write_general_feedback", "(", "$", "question", ",", "$", "indent", "=", "\"\\t\"", ")", "{", "$", "generalfeedback", "=", "$", "this", "->", "write_questiontext", "(", "$", "question", "->", "generalfeedback", ",", "$", "question", "->", "generalfeedbackformat", ",", "$", "question", "->", "questiontextformat", ")", ";", "if", "(", "$", "generalfeedback", ")", "{", "$", "generalfeedback", "=", "'####'", ".", "$", "generalfeedback", ";", "if", "(", "$", "indent", ")", "{", "$", "generalfeedback", "=", "$", "indent", ".", "$", "generalfeedback", ".", "\"\\n\"", ";", "}", "}", "return", "$", "generalfeedback", ";", "}" ]
Outputs the general feedback for the question, if any. This needs to be the last thing before the }. @param object $question the question data. @param string $indent to put before the general feedback. Defaults to a tab. If this is not blank, a newline is added after the line.
[ "Outputs", "the", "general", "feedback", "for", "the", "question", "if", "any", ".", "This", "needs", "to", "be", "the", "last", "thing", "before", "the", "}", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/format/gift/format.php#L623-L635
217,136
moodle/moodle
comment/classes/external.php
core_comment_external.get_comments
public static function get_comments($contextlevel, $instanceid, $component, $itemid, $area = '', $page = 0) { $warnings = array(); $arrayparams = array( 'contextlevel' => $contextlevel, 'instanceid' => $instanceid, 'component' => $component, 'itemid' => $itemid, 'area' => $area, 'page' => $page ); $params = self::validate_parameters(self::get_comments_parameters(), $arrayparams); $context = self::get_context_from_params($params); self::validate_context($context); require_capability('moodle/comment:view', $context); $args = new stdClass; $args->context = $context; $args->area = $params['area']; $args->itemid = $params['itemid']; $args->component = $params['component']; $commentobject = new comment($args); $comments = $commentobject->get_comments($params['page']); // False means no permissions to see comments. if ($comments === false) { throw new moodle_exception('nopermissions', 'error', '', 'view comments'); } $options = array('blanktarget' => true); foreach ($comments as $key => $comment) { list($comments[$key]->content, $comments[$key]->format) = external_format_text($comment->content, $comment->format, $context->id, $params['component'], '', 0, $options); } $results = array( 'comments' => $comments, 'warnings' => $warnings ); return $results; }
php
public static function get_comments($contextlevel, $instanceid, $component, $itemid, $area = '', $page = 0) { $warnings = array(); $arrayparams = array( 'contextlevel' => $contextlevel, 'instanceid' => $instanceid, 'component' => $component, 'itemid' => $itemid, 'area' => $area, 'page' => $page ); $params = self::validate_parameters(self::get_comments_parameters(), $arrayparams); $context = self::get_context_from_params($params); self::validate_context($context); require_capability('moodle/comment:view', $context); $args = new stdClass; $args->context = $context; $args->area = $params['area']; $args->itemid = $params['itemid']; $args->component = $params['component']; $commentobject = new comment($args); $comments = $commentobject->get_comments($params['page']); // False means no permissions to see comments. if ($comments === false) { throw new moodle_exception('nopermissions', 'error', '', 'view comments'); } $options = array('blanktarget' => true); foreach ($comments as $key => $comment) { list($comments[$key]->content, $comments[$key]->format) = external_format_text($comment->content, $comment->format, $context->id, $params['component'], '', 0, $options); } $results = array( 'comments' => $comments, 'warnings' => $warnings ); return $results; }
[ "public", "static", "function", "get_comments", "(", "$", "contextlevel", ",", "$", "instanceid", ",", "$", "component", ",", "$", "itemid", ",", "$", "area", "=", "''", ",", "$", "page", "=", "0", ")", "{", "$", "warnings", "=", "array", "(", ")", ";", "$", "arrayparams", "=", "array", "(", "'contextlevel'", "=>", "$", "contextlevel", ",", "'instanceid'", "=>", "$", "instanceid", ",", "'component'", "=>", "$", "component", ",", "'itemid'", "=>", "$", "itemid", ",", "'area'", "=>", "$", "area", ",", "'page'", "=>", "$", "page", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_comments_parameters", "(", ")", ",", "$", "arrayparams", ")", ";", "$", "context", "=", "self", "::", "get_context_from_params", "(", "$", "params", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "require_capability", "(", "'moodle/comment:view'", ",", "$", "context", ")", ";", "$", "args", "=", "new", "stdClass", ";", "$", "args", "->", "context", "=", "$", "context", ";", "$", "args", "->", "area", "=", "$", "params", "[", "'area'", "]", ";", "$", "args", "->", "itemid", "=", "$", "params", "[", "'itemid'", "]", ";", "$", "args", "->", "component", "=", "$", "params", "[", "'component'", "]", ";", "$", "commentobject", "=", "new", "comment", "(", "$", "args", ")", ";", "$", "comments", "=", "$", "commentobject", "->", "get_comments", "(", "$", "params", "[", "'page'", "]", ")", ";", "// False means no permissions to see comments.", "if", "(", "$", "comments", "===", "false", ")", "{", "throw", "new", "moodle_exception", "(", "'nopermissions'", ",", "'error'", ",", "''", ",", "'view comments'", ")", ";", "}", "$", "options", "=", "array", "(", "'blanktarget'", "=>", "true", ")", ";", "foreach", "(", "$", "comments", "as", "$", "key", "=>", "$", "comment", ")", "{", "list", "(", "$", "comments", "[", "$", "key", "]", "->", "content", ",", "$", "comments", "[", "$", "key", "]", "->", "format", ")", "=", "external_format_text", "(", "$", "comment", "->", "content", ",", "$", "comment", "->", "format", ",", "$", "context", "->", "id", ",", "$", "params", "[", "'component'", "]", ",", "''", ",", "0", ",", "$", "options", ")", ";", "}", "$", "results", "=", "array", "(", "'comments'", "=>", "$", "comments", ",", "'warnings'", "=>", "$", "warnings", ")", ";", "return", "$", "results", ";", "}" ]
Return a list of comments @param string $contextlevel ('system, course, user', etc..) @param int $instanceid @param string $component the name of the component @param int $itemid the item id @param string $area comment area @param int $page page number @return array of comments and warnings @since Moodle 2.9
[ "Return", "a", "list", "of", "comments" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/comment/classes/external.php#L74-L123
217,137
moodle/moodle
mod/assign/submission/comments/locallib.php
assign_submission_comments.view_summary
public function view_summary(stdClass $submission, & $showviewlink) { // Never show a link to view full submission. $showviewlink = false; // Need to used this init() otherwise it does not have the javascript includes. comment::init(); $options = new stdClass(); $options->area = 'submission_comments'; $options->course = $this->assignment->get_course(); $options->context = $this->assignment->get_context(); $options->itemid = $submission->id; $options->component = 'assignsubmission_comments'; $options->showcount = true; $options->displaycancel = true; $comment = new comment($options); $o = $this->assignment->get_renderer()->container($comment->output(true), 'commentscontainer'); return $o; }
php
public function view_summary(stdClass $submission, & $showviewlink) { // Never show a link to view full submission. $showviewlink = false; // Need to used this init() otherwise it does not have the javascript includes. comment::init(); $options = new stdClass(); $options->area = 'submission_comments'; $options->course = $this->assignment->get_course(); $options->context = $this->assignment->get_context(); $options->itemid = $submission->id; $options->component = 'assignsubmission_comments'; $options->showcount = true; $options->displaycancel = true; $comment = new comment($options); $o = $this->assignment->get_renderer()->container($comment->output(true), 'commentscontainer'); return $o; }
[ "public", "function", "view_summary", "(", "stdClass", "$", "submission", ",", "&", "$", "showviewlink", ")", "{", "// Never show a link to view full submission.", "$", "showviewlink", "=", "false", ";", "// Need to used this init() otherwise it does not have the javascript includes.", "comment", "::", "init", "(", ")", ";", "$", "options", "=", "new", "stdClass", "(", ")", ";", "$", "options", "->", "area", "=", "'submission_comments'", ";", "$", "options", "->", "course", "=", "$", "this", "->", "assignment", "->", "get_course", "(", ")", ";", "$", "options", "->", "context", "=", "$", "this", "->", "assignment", "->", "get_context", "(", ")", ";", "$", "options", "->", "itemid", "=", "$", "submission", "->", "id", ";", "$", "options", "->", "component", "=", "'assignsubmission_comments'", ";", "$", "options", "->", "showcount", "=", "true", ";", "$", "options", "->", "displaycancel", "=", "true", ";", "$", "comment", "=", "new", "comment", "(", "$", "options", ")", ";", "$", "o", "=", "$", "this", "->", "assignment", "->", "get_renderer", "(", ")", "->", "container", "(", "$", "comment", "->", "output", "(", "true", ")", ",", "'commentscontainer'", ")", ";", "return", "$", "o", ";", "}" ]
Display AJAX based comment in the submission status table @param stdClass $submission @param bool $showviewlink - If the comments are long this is set to true so they can be shown in a separate page @return string
[ "Display", "AJAX", "based", "comment", "in", "the", "submission", "status", "table" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/submission/comments/locallib.php#L55-L75
217,138
moodle/moodle
question/behaviour/behaviourbase.php
question_behaviour.adjust_display_options
public function adjust_display_options(question_display_options $options) { if (!$this->qa->has_marks()) { $options->correctness = false; $options->numpartscorrect = false; } if ($this->qa->get_state()->is_finished()) { $options->readonly = true; $options->numpartscorrect = $options->numpartscorrect && $this->qa->get_state()->is_partially_correct() && !empty($this->question->shownumcorrect); } else { $options->hide_all_feedback(); } }
php
public function adjust_display_options(question_display_options $options) { if (!$this->qa->has_marks()) { $options->correctness = false; $options->numpartscorrect = false; } if ($this->qa->get_state()->is_finished()) { $options->readonly = true; $options->numpartscorrect = $options->numpartscorrect && $this->qa->get_state()->is_partially_correct() && !empty($this->question->shownumcorrect); } else { $options->hide_all_feedback(); } }
[ "public", "function", "adjust_display_options", "(", "question_display_options", "$", "options", ")", "{", "if", "(", "!", "$", "this", "->", "qa", "->", "has_marks", "(", ")", ")", "{", "$", "options", "->", "correctness", "=", "false", ";", "$", "options", "->", "numpartscorrect", "=", "false", ";", "}", "if", "(", "$", "this", "->", "qa", "->", "get_state", "(", ")", "->", "is_finished", "(", ")", ")", "{", "$", "options", "->", "readonly", "=", "true", ";", "$", "options", "->", "numpartscorrect", "=", "$", "options", "->", "numpartscorrect", "&&", "$", "this", "->", "qa", "->", "get_state", "(", ")", "->", "is_partially_correct", "(", ")", "&&", "!", "empty", "(", "$", "this", "->", "question", "->", "shownumcorrect", ")", ";", "}", "else", "{", "$", "options", "->", "hide_all_feedback", "(", ")", ";", "}", "}" ]
Make any changes to the display options before a question is rendered, so that it can be displayed in a way that is appropriate for the statue it is currently in. For example, by default, if the question is finished, we ensure that it is only ever displayed read-only. @param question_display_options $options the options to adjust. Just change the properties of this object - objects are passed by referece.
[ "Make", "any", "changes", "to", "the", "display", "options", "before", "a", "question", "is", "rendered", "so", "that", "it", "can", "be", "displayed", "in", "a", "way", "that", "is", "appropriate", "for", "the", "statue", "it", "is", "currently", "in", ".", "For", "example", "by", "default", "if", "the", "question", "is", "finished", "we", "ensure", "that", "it", "is", "only", "ever", "displayed", "read", "-", "only", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/behaviour/behaviourbase.php#L158-L171
217,139
moodle/moodle
question/behaviour/behaviourbase.php
question_behaviour.get_expected_data
public function get_expected_data() { if (!$this->qa->get_state()->is_finished()) { return array(); } $vars = array('comment' => question_attempt::PARAM_RAW_FILES, 'commentformat' => PARAM_INT); if ($this->qa->get_max_mark()) { $vars['mark'] = PARAM_RAW_TRIMMED; $vars['maxmark'] = PARAM_FLOAT; } return $vars; }
php
public function get_expected_data() { if (!$this->qa->get_state()->is_finished()) { return array(); } $vars = array('comment' => question_attempt::PARAM_RAW_FILES, 'commentformat' => PARAM_INT); if ($this->qa->get_max_mark()) { $vars['mark'] = PARAM_RAW_TRIMMED; $vars['maxmark'] = PARAM_FLOAT; } return $vars; }
[ "public", "function", "get_expected_data", "(", ")", "{", "if", "(", "!", "$", "this", "->", "qa", "->", "get_state", "(", ")", "->", "is_finished", "(", ")", ")", "{", "return", "array", "(", ")", ";", "}", "$", "vars", "=", "array", "(", "'comment'", "=>", "question_attempt", "::", "PARAM_RAW_FILES", ",", "'commentformat'", "=>", "PARAM_INT", ")", ";", "if", "(", "$", "this", "->", "qa", "->", "get_max_mark", "(", ")", ")", "{", "$", "vars", "[", "'mark'", "]", "=", "PARAM_RAW_TRIMMED", ";", "$", "vars", "[", "'maxmark'", "]", "=", "PARAM_FLOAT", ";", "}", "return", "$", "vars", ";", "}" ]
Return an array of the behaviour variables that could be submitted as part of a question of this type, with their types, so they can be properly cleaned. @return array variable name => PARAM_... constant.
[ "Return", "an", "array", "of", "the", "behaviour", "variables", "that", "could", "be", "submitted", "as", "part", "of", "a", "question", "of", "this", "type", "with", "their", "types", "so", "they", "can", "be", "properly", "cleaned", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/behaviour/behaviourbase.php#L211-L222
217,140
moodle/moodle
question/behaviour/behaviourbase.php
question_behaviour_with_save.process_save
public function process_save(question_attempt_pending_step $pendingstep) { if ($this->qa->get_state()->is_finished()) { return question_attempt::DISCARD; } else if (!$this->qa->get_state()->is_active()) { throw new coding_exception('Question is not active, cannot process_actions.'); } if ($this->is_same_response($pendingstep)) { return question_attempt::DISCARD; } if ($this->is_complete_response($pendingstep)) { $pendingstep->set_state(question_state::$complete); } else { $pendingstep->set_state(question_state::$todo); } return question_attempt::KEEP; }
php
public function process_save(question_attempt_pending_step $pendingstep) { if ($this->qa->get_state()->is_finished()) { return question_attempt::DISCARD; } else if (!$this->qa->get_state()->is_active()) { throw new coding_exception('Question is not active, cannot process_actions.'); } if ($this->is_same_response($pendingstep)) { return question_attempt::DISCARD; } if ($this->is_complete_response($pendingstep)) { $pendingstep->set_state(question_state::$complete); } else { $pendingstep->set_state(question_state::$todo); } return question_attempt::KEEP; }
[ "public", "function", "process_save", "(", "question_attempt_pending_step", "$", "pendingstep", ")", "{", "if", "(", "$", "this", "->", "qa", "->", "get_state", "(", ")", "->", "is_finished", "(", ")", ")", "{", "return", "question_attempt", "::", "DISCARD", ";", "}", "else", "if", "(", "!", "$", "this", "->", "qa", "->", "get_state", "(", ")", "->", "is_active", "(", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Question is not active, cannot process_actions.'", ")", ";", "}", "if", "(", "$", "this", "->", "is_same_response", "(", "$", "pendingstep", ")", ")", "{", "return", "question_attempt", "::", "DISCARD", ";", "}", "if", "(", "$", "this", "->", "is_complete_response", "(", "$", "pendingstep", ")", ")", "{", "$", "pendingstep", "->", "set_state", "(", "question_state", "::", "$", "complete", ")", ";", "}", "else", "{", "$", "pendingstep", "->", "set_state", "(", "question_state", "::", "$", "todo", ")", ";", "}", "return", "question_attempt", "::", "KEEP", ";", "}" ]
Implementation of processing a save action that should be suitable for most subclasses. @param question_attempt_pending_step $pendingstep a partially initialised step containing all the information about the action that is being peformed. @return bool either {@link question_attempt::KEEP} or {@link question_attempt::DISCARD}
[ "Implementation", "of", "processing", "a", "save", "action", "that", "should", "be", "suitable", "for", "most", "subclasses", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/behaviour/behaviourbase.php#L672-L689
217,141
moodle/moodle
question/behaviour/behaviourbase.php
question_cbm.adjust_fraction
public static function adjust_fraction($fraction, $certainty) { if ($certainty == -1) { // Certainty -1 has never been used in standard Moodle, but is // used in Tony-Gardiner Medwin's patches to mean 'No idea' which // we intend to implement: MDL-42077. In the mean time, avoid // errors for people who have used TGM's patches. return 0; } if ($fraction <= 0.00000005) { return self::$wrongscore[$certainty]; } else { return self::$rightscore[$certainty] * $fraction; } }
php
public static function adjust_fraction($fraction, $certainty) { if ($certainty == -1) { // Certainty -1 has never been used in standard Moodle, but is // used in Tony-Gardiner Medwin's patches to mean 'No idea' which // we intend to implement: MDL-42077. In the mean time, avoid // errors for people who have used TGM's patches. return 0; } if ($fraction <= 0.00000005) { return self::$wrongscore[$certainty]; } else { return self::$rightscore[$certainty] * $fraction; } }
[ "public", "static", "function", "adjust_fraction", "(", "$", "fraction", ",", "$", "certainty", ")", "{", "if", "(", "$", "certainty", "==", "-", "1", ")", "{", "// Certainty -1 has never been used in standard Moodle, but is", "// used in Tony-Gardiner Medwin's patches to mean 'No idea' which", "// we intend to implement: MDL-42077. In the mean time, avoid", "// errors for people who have used TGM's patches.", "return", "0", ";", "}", "if", "(", "$", "fraction", "<=", "0.00000005", ")", "{", "return", "self", "::", "$", "wrongscore", "[", "$", "certainty", "]", ";", "}", "else", "{", "return", "self", "::", "$", "rightscore", "[", "$", "certainty", "]", "*", "$", "fraction", ";", "}", "}" ]
Given a fraction, and a certainty, compute the adjusted fraction. @param number $fraction the raw fraction for this question. @param int $certainty one of the certainty level constants. @return number the adjusted fraction taking the certainty into account.
[ "Given", "a", "fraction", "and", "a", "certainty", "compute", "the", "adjusted", "fraction", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/behaviour/behaviourbase.php#L779-L792
217,142
moodle/moodle
question/behaviour/behaviourbase.php
question_cbm.summary_with_certainty
public static function summary_with_certainty($summary, $certainty) { if (is_null($certainty)) { return $summary; } return $summary . ' [' . self::get_short_string($certainty) . ']'; }
php
public static function summary_with_certainty($summary, $certainty) { if (is_null($certainty)) { return $summary; } return $summary . ' [' . self::get_short_string($certainty) . ']'; }
[ "public", "static", "function", "summary_with_certainty", "(", "$", "summary", ",", "$", "certainty", ")", "{", "if", "(", "is_null", "(", "$", "certainty", ")", ")", "{", "return", "$", "summary", ";", "}", "return", "$", "summary", ".", "' ['", ".", "self", "::", "get_short_string", "(", "$", "certainty", ")", ".", "']'", ";", "}" ]
Add information about certainty to a response summary. @param string $summary the response summary. @param int $certainty the level of certainty to add. @return string the summary with information about the certainty added.
[ "Add", "information", "about", "certainty", "to", "a", "response", "summary", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/behaviour/behaviourbase.php#L816-L821
217,143
moodle/moodle
lib/filebrowser/file_info_context_system.php
file_info_context_system.get_file_info
public function get_file_info($component, $filearea, $itemid, $filepath, $filename) { if (empty($component)) { return $this; } $methodname = "get_area_{$component}_{$filearea}"; if (method_exists($this, $methodname)) { return $this->$methodname($itemid, $filepath, $filename); } return null; }
php
public function get_file_info($component, $filearea, $itemid, $filepath, $filename) { if (empty($component)) { return $this; } $methodname = "get_area_{$component}_{$filearea}"; if (method_exists($this, $methodname)) { return $this->$methodname($itemid, $filepath, $filename); } return null; }
[ "public", "function", "get_file_info", "(", "$", "component", ",", "$", "filearea", ",", "$", "itemid", ",", "$", "filepath", ",", "$", "filename", ")", "{", "if", "(", "empty", "(", "$", "component", ")", ")", "{", "return", "$", "this", ";", "}", "$", "methodname", "=", "\"get_area_{$component}_{$filearea}\"", ";", "if", "(", "method_exists", "(", "$", "this", ",", "$", "methodname", ")", ")", "{", "return", "$", "this", "->", "$", "methodname", "(", "$", "itemid", ",", "$", "filepath", ",", "$", "filename", ")", ";", "}", "return", "null", ";", "}" ]
Return information about this specific part of context level @param string $component component @param string $filearea file area @param int $itemid item ID @param string $filepath file path @param string $filename file name @return file_info|null file_info instance or null if not found or access not allowed
[ "Return", "information", "about", "this", "specific", "part", "of", "context", "level" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filebrowser/file_info_context_system.php#L59-L71
217,144
moodle/moodle
completion/completion_completion.php
completion_completion.fetch
public static function fetch($params) { $cache = cache::make('core', 'coursecompletion'); $key = $params['userid'] . '_' . $params['course']; if ($hit = $cache->get($key)) { return $hit['value']; } $tocache = self::fetch_helper('course_completions', __CLASS__, $params); $cache->set($key, ['value' => $tocache]); return $tocache; }
php
public static function fetch($params) { $cache = cache::make('core', 'coursecompletion'); $key = $params['userid'] . '_' . $params['course']; if ($hit = $cache->get($key)) { return $hit['value']; } $tocache = self::fetch_helper('course_completions', __CLASS__, $params); $cache->set($key, ['value' => $tocache]); return $tocache; }
[ "public", "static", "function", "fetch", "(", "$", "params", ")", "{", "$", "cache", "=", "cache", "::", "make", "(", "'core'", ",", "'coursecompletion'", ")", ";", "$", "key", "=", "$", "params", "[", "'userid'", "]", ".", "'_'", ".", "$", "params", "[", "'course'", "]", ";", "if", "(", "$", "hit", "=", "$", "cache", "->", "get", "(", "$", "key", ")", ")", "{", "return", "$", "hit", "[", "'value'", "]", ";", "}", "$", "tocache", "=", "self", "::", "fetch_helper", "(", "'course_completions'", ",", "__CLASS__", ",", "$", "params", ")", ";", "$", "cache", "->", "set", "(", "$", "key", ",", "[", "'value'", "=>", "$", "tocache", "]", ")", ";", "return", "$", "tocache", ";", "}" ]
Finds and returns a data_object instance based on params. @param array $params associative arrays varname = >value @return data_object instance of data_object or false if none found.
[ "Finds", "and", "returns", "a", "data_object", "instance", "based", "on", "params", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/completion_completion.php#L76-L87
217,145
moodle/moodle
completion/completion_completion.php
completion_completion.mark_inprogress
public function mark_inprogress($timestarted = null) { $timenow = time(); // Set reaggregate flag $this->reaggregate = $timenow; if (!$this->timestarted) { if (!$timestarted) { $timestarted = $timenow; } $this->timestarted = $timestarted; } return $this->_save(); }
php
public function mark_inprogress($timestarted = null) { $timenow = time(); // Set reaggregate flag $this->reaggregate = $timenow; if (!$this->timestarted) { if (!$timestarted) { $timestarted = $timenow; } $this->timestarted = $timestarted; } return $this->_save(); }
[ "public", "function", "mark_inprogress", "(", "$", "timestarted", "=", "null", ")", "{", "$", "timenow", "=", "time", "(", ")", ";", "// Set reaggregate flag", "$", "this", "->", "reaggregate", "=", "$", "timenow", ";", "if", "(", "!", "$", "this", "->", "timestarted", ")", "{", "if", "(", "!", "$", "timestarted", ")", "{", "$", "timestarted", "=", "$", "timenow", ";", "}", "$", "this", "->", "timestarted", "=", "$", "timestarted", ";", "}", "return", "$", "this", "->", "_save", "(", ")", ";", "}" ]
Mark this user as inprogress in this course If the user is already marked as inprogress, the time will not be changed @param integer $timestarted Time started (optional)
[ "Mark", "this", "user", "as", "inprogress", "in", "this", "course" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/completion_completion.php#L126-L143
217,146
moodle/moodle
completion/completion_completion.php
completion_completion.mark_complete
public function mark_complete($timecomplete = null) { global $USER; // Never change a completion time. if ($this->timecompleted) { return; } // Use current time if nothing supplied. if (!$timecomplete) { $timecomplete = time(); } // Set time complete. $this->timecompleted = $timecomplete; // Save record. if ($result = $this->_save()) { $data = $this->get_record_data(); \core\event\course_completed::create_from_completion($data)->trigger(); } return $result; }
php
public function mark_complete($timecomplete = null) { global $USER; // Never change a completion time. if ($this->timecompleted) { return; } // Use current time if nothing supplied. if (!$timecomplete) { $timecomplete = time(); } // Set time complete. $this->timecompleted = $timecomplete; // Save record. if ($result = $this->_save()) { $data = $this->get_record_data(); \core\event\course_completed::create_from_completion($data)->trigger(); } return $result; }
[ "public", "function", "mark_complete", "(", "$", "timecomplete", "=", "null", ")", "{", "global", "$", "USER", ";", "// Never change a completion time.", "if", "(", "$", "this", "->", "timecompleted", ")", "{", "return", ";", "}", "// Use current time if nothing supplied.", "if", "(", "!", "$", "timecomplete", ")", "{", "$", "timecomplete", "=", "time", "(", ")", ";", "}", "// Set time complete.", "$", "this", "->", "timecompleted", "=", "$", "timecomplete", ";", "// Save record.", "if", "(", "$", "result", "=", "$", "this", "->", "_save", "(", ")", ")", "{", "$", "data", "=", "$", "this", "->", "get_record_data", "(", ")", ";", "\\", "core", "\\", "event", "\\", "course_completed", "::", "create_from_completion", "(", "$", "data", ")", "->", "trigger", "(", ")", ";", "}", "return", "$", "result", ";", "}" ]
Mark this user complete in this course This generally happens when the required completion criteria in the course are complete. @param integer $timecomplete Time completed (optional) @return void
[ "Mark", "this", "user", "complete", "in", "this", "course" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/completion_completion.php#L154-L177
217,147
moodle/moodle
completion/completion_completion.php
completion_completion._save
private function _save() { if ($this->timeenrolled === null) { $this->timeenrolled = 0; } $result = false; // Save record if ($this->id) { $result = $this->update(); } else { // Make sure reaggregate field is not null if (!$this->reaggregate) { $this->reaggregate = 0; } // Make sure timestarted is not null if (!$this->timestarted) { $this->timestarted = 0; } $result = $this->insert(); } if ($result) { // Update the cached record. $cache = cache::make('core', 'coursecompletion'); $data = $this->get_record_data(); $key = $data->userid . '_' . $data->course; $cache->set($key, ['value' => $data]); } return $result; }
php
private function _save() { if ($this->timeenrolled === null) { $this->timeenrolled = 0; } $result = false; // Save record if ($this->id) { $result = $this->update(); } else { // Make sure reaggregate field is not null if (!$this->reaggregate) { $this->reaggregate = 0; } // Make sure timestarted is not null if (!$this->timestarted) { $this->timestarted = 0; } $result = $this->insert(); } if ($result) { // Update the cached record. $cache = cache::make('core', 'coursecompletion'); $data = $this->get_record_data(); $key = $data->userid . '_' . $data->course; $cache->set($key, ['value' => $data]); } return $result; }
[ "private", "function", "_save", "(", ")", "{", "if", "(", "$", "this", "->", "timeenrolled", "===", "null", ")", "{", "$", "this", "->", "timeenrolled", "=", "0", ";", "}", "$", "result", "=", "false", ";", "// Save record", "if", "(", "$", "this", "->", "id", ")", "{", "$", "result", "=", "$", "this", "->", "update", "(", ")", ";", "}", "else", "{", "// Make sure reaggregate field is not null", "if", "(", "!", "$", "this", "->", "reaggregate", ")", "{", "$", "this", "->", "reaggregate", "=", "0", ";", "}", "// Make sure timestarted is not null", "if", "(", "!", "$", "this", "->", "timestarted", ")", "{", "$", "this", "->", "timestarted", "=", "0", ";", "}", "$", "result", "=", "$", "this", "->", "insert", "(", ")", ";", "}", "if", "(", "$", "result", ")", "{", "// Update the cached record.", "$", "cache", "=", "cache", "::", "make", "(", "'core'", ",", "'coursecompletion'", ")", ";", "$", "data", "=", "$", "this", "->", "get_record_data", "(", ")", ";", "$", "key", "=", "$", "data", "->", "userid", ".", "'_'", ".", "$", "data", "->", "course", ";", "$", "cache", "->", "set", "(", "$", "key", ",", "[", "'value'", "=>", "$", "data", "]", ")", ";", "}", "return", "$", "result", ";", "}" ]
Save course completion status This method creates a course_completions record if none exists @access private @return bool
[ "Save", "course", "completion", "status" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/completion_completion.php#L186-L218
217,148
moodle/moodle
blocks/community/renderer.php
block_community_renderer.remove_success
public function remove_success(moodle_url $url) { $html = $this->output->notification(get_string('communityremoved', 'hub'), 'notifysuccess'); $continuebutton = new single_button($url, get_string('continue', 'block_community')); $html .= html_writer::tag('div', $this->output->render($continuebutton), array('class' => 'continuebutton')); return $html; }
php
public function remove_success(moodle_url $url) { $html = $this->output->notification(get_string('communityremoved', 'hub'), 'notifysuccess'); $continuebutton = new single_button($url, get_string('continue', 'block_community')); $html .= html_writer::tag('div', $this->output->render($continuebutton), array('class' => 'continuebutton')); return $html; }
[ "public", "function", "remove_success", "(", "moodle_url", "$", "url", ")", "{", "$", "html", "=", "$", "this", "->", "output", "->", "notification", "(", "get_string", "(", "'communityremoved'", ",", "'hub'", ")", ",", "'notifysuccess'", ")", ";", "$", "continuebutton", "=", "new", "single_button", "(", "$", "url", ",", "get_string", "(", "'continue'", ",", "'block_community'", ")", ")", ";", "$", "html", ".=", "html_writer", "::", "tag", "(", "'div'", ",", "$", "this", "->", "output", "->", "render", "(", "$", "continuebutton", ")", ",", "array", "(", "'class'", "=>", "'continuebutton'", ")", ")", ";", "return", "$", "html", ";", "}" ]
Display remove community success message and a button to be redirected to te referer page @param moodle_url $url the page to be redirected to @return string html
[ "Display", "remove", "community", "success", "message", "and", "a", "button", "to", "be", "redirected", "to", "te", "referer", "page" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/community/renderer.php#L52-L60
217,149
moodle/moodle
blocks/community/renderer.php
block_community_renderer.moodlenet_info
public function moodlenet_info() { if (!$info = \core\hub\registration::get_moodlenet_info()) { return ''; } $image = html_writer::div(html_writer::img($info['imgurl'], $info['name']), 'hubimage'); $namelink = html_writer::link($info['url'], html_writer::tag('h2', $info['name']), array('class' => 'hubtitlelink')); $description = clean_param($info['description'], PARAM_TEXT); $descriptiontext = html_writer::div(format_text($description, FORMAT_PLAIN), 'hubdescription'); $additionaldesc = get_string('enrollablecourses', 'block_community') . ': ' . $info['enrollablecourses'] . ' - ' . get_string('downloadablecourses', 'block_community') . ': ' . $info['downloadablecourses']; $stats = html_writer::div(html_writer::tag('div', $additionaldesc), 'hubstats'); $text = html_writer::div($descriptiontext . $stats, 'hubtext'); $imgandtext = html_writer::div($image . $text, 'hubimgandtext'); $fulldesc = html_writer::div($namelink . $imgandtext, 'hubmainhmtl clearfix'); return html_writer::div($fulldesc, 'formlisting'); }
php
public function moodlenet_info() { if (!$info = \core\hub\registration::get_moodlenet_info()) { return ''; } $image = html_writer::div(html_writer::img($info['imgurl'], $info['name']), 'hubimage'); $namelink = html_writer::link($info['url'], html_writer::tag('h2', $info['name']), array('class' => 'hubtitlelink')); $description = clean_param($info['description'], PARAM_TEXT); $descriptiontext = html_writer::div(format_text($description, FORMAT_PLAIN), 'hubdescription'); $additionaldesc = get_string('enrollablecourses', 'block_community') . ': ' . $info['enrollablecourses'] . ' - ' . get_string('downloadablecourses', 'block_community') . ': ' . $info['downloadablecourses']; $stats = html_writer::div(html_writer::tag('div', $additionaldesc), 'hubstats'); $text = html_writer::div($descriptiontext . $stats, 'hubtext'); $imgandtext = html_writer::div($image . $text, 'hubimgandtext'); $fulldesc = html_writer::div($namelink . $imgandtext, 'hubmainhmtl clearfix'); return html_writer::div($fulldesc, 'formlisting'); }
[ "public", "function", "moodlenet_info", "(", ")", "{", "if", "(", "!", "$", "info", "=", "\\", "core", "\\", "hub", "\\", "registration", "::", "get_moodlenet_info", "(", ")", ")", "{", "return", "''", ";", "}", "$", "image", "=", "html_writer", "::", "div", "(", "html_writer", "::", "img", "(", "$", "info", "[", "'imgurl'", "]", ",", "$", "info", "[", "'name'", "]", ")", ",", "'hubimage'", ")", ";", "$", "namelink", "=", "html_writer", "::", "link", "(", "$", "info", "[", "'url'", "]", ",", "html_writer", "::", "tag", "(", "'h2'", ",", "$", "info", "[", "'name'", "]", ")", ",", "array", "(", "'class'", "=>", "'hubtitlelink'", ")", ")", ";", "$", "description", "=", "clean_param", "(", "$", "info", "[", "'description'", "]", ",", "PARAM_TEXT", ")", ";", "$", "descriptiontext", "=", "html_writer", "::", "div", "(", "format_text", "(", "$", "description", ",", "FORMAT_PLAIN", ")", ",", "'hubdescription'", ")", ";", "$", "additionaldesc", "=", "get_string", "(", "'enrollablecourses'", ",", "'block_community'", ")", ".", "': '", ".", "$", "info", "[", "'enrollablecourses'", "]", ".", "' - '", ".", "get_string", "(", "'downloadablecourses'", ",", "'block_community'", ")", ".", "': '", ".", "$", "info", "[", "'downloadablecourses'", "]", ";", "$", "stats", "=", "html_writer", "::", "div", "(", "html_writer", "::", "tag", "(", "'div'", ",", "$", "additionaldesc", ")", ",", "'hubstats'", ")", ";", "$", "text", "=", "html_writer", "::", "div", "(", "$", "descriptiontext", ".", "$", "stats", ",", "'hubtext'", ")", ";", "$", "imgandtext", "=", "html_writer", "::", "div", "(", "$", "image", ".", "$", "text", ",", "'hubimgandtext'", ")", ";", "$", "fulldesc", "=", "html_writer", "::", "div", "(", "$", "namelink", ".", "$", "imgandtext", ",", "'hubmainhmtl clearfix'", ")", ";", "return", "html_writer", "::", "div", "(", "$", "fulldesc", ",", "'formlisting'", ")", ";", "}" ]
Displays information about moodle.net above course search form @return string
[ "Displays", "information", "about", "moodle", ".", "net", "above", "course", "search", "form" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/community/renderer.php#L93-L115
217,150
moodle/moodle
repository/coursefiles/lib.php
repository_coursefiles.get_name
public function get_name() { $context = $this->context->get_course_context(false); if ($context) { return get_string('courselegacyfilesofcourse', 'moodle', $context->get_context_name(false, true)); } else { return get_string('courselegacyfiles'); } }
php
public function get_name() { $context = $this->context->get_course_context(false); if ($context) { return get_string('courselegacyfilesofcourse', 'moodle', $context->get_context_name(false, true)); } else { return get_string('courselegacyfiles'); } }
[ "public", "function", "get_name", "(", ")", "{", "$", "context", "=", "$", "this", "->", "context", "->", "get_course_context", "(", "false", ")", ";", "if", "(", "$", "context", ")", "{", "return", "get_string", "(", "'courselegacyfilesofcourse'", ",", "'moodle'", ",", "$", "context", "->", "get_context_name", "(", "false", ",", "true", ")", ")", ";", "}", "else", "{", "return", "get_string", "(", "'courselegacyfiles'", ")", ";", "}", "}" ]
Return the repository name. @return string
[ "Return", "the", "repository", "name", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/coursefiles/lib.php#L188-L195
217,151
moodle/moodle
media/player/videojs/classes/plugin.php
media_videojs_plugin.find_language
protected function find_language() { global $CFG; $this->language = current_language(); $basedir = $CFG->dirroot . '/media/player/videojs/videojs/lang/'; $langfiles = get_directory_list($basedir); $candidates = []; foreach ($langfiles as $langfile) { if (strtolower(pathinfo($langfile, PATHINFO_EXTENSION)) !== 'js') { continue; } $lang = basename($langfile, '.js'); if (strtolower($langfile) === $this->language . '.js') { // Found an exact match for the language. $js = file_get_contents($basedir . $langfile); break; } if (substr($this->language, 0, 2) === strtolower(substr($langfile, 0, 2))) { // Not an exact match but similar, for example "pt_br" is similar to "pt". $candidates[$lang] = $langfile; } } if (empty($js) && $candidates) { // Exact match was not found, take the first candidate. $this->language = key($candidates); $js = file_get_contents($basedir . $candidates[$this->language]); } // Add it as a language for Video.JS. if (!empty($js)) { return "$js\n"; } // Could not match, use default language of video player (English). $this->language = null; return ""; }
php
protected function find_language() { global $CFG; $this->language = current_language(); $basedir = $CFG->dirroot . '/media/player/videojs/videojs/lang/'; $langfiles = get_directory_list($basedir); $candidates = []; foreach ($langfiles as $langfile) { if (strtolower(pathinfo($langfile, PATHINFO_EXTENSION)) !== 'js') { continue; } $lang = basename($langfile, '.js'); if (strtolower($langfile) === $this->language . '.js') { // Found an exact match for the language. $js = file_get_contents($basedir . $langfile); break; } if (substr($this->language, 0, 2) === strtolower(substr($langfile, 0, 2))) { // Not an exact match but similar, for example "pt_br" is similar to "pt". $candidates[$lang] = $langfile; } } if (empty($js) && $candidates) { // Exact match was not found, take the first candidate. $this->language = key($candidates); $js = file_get_contents($basedir . $candidates[$this->language]); } // Add it as a language for Video.JS. if (!empty($js)) { return "$js\n"; } // Could not match, use default language of video player (English). $this->language = null; return ""; }
[ "protected", "function", "find_language", "(", ")", "{", "global", "$", "CFG", ";", "$", "this", "->", "language", "=", "current_language", "(", ")", ";", "$", "basedir", "=", "$", "CFG", "->", "dirroot", ".", "'/media/player/videojs/videojs/lang/'", ";", "$", "langfiles", "=", "get_directory_list", "(", "$", "basedir", ")", ";", "$", "candidates", "=", "[", "]", ";", "foreach", "(", "$", "langfiles", "as", "$", "langfile", ")", "{", "if", "(", "strtolower", "(", "pathinfo", "(", "$", "langfile", ",", "PATHINFO_EXTENSION", ")", ")", "!==", "'js'", ")", "{", "continue", ";", "}", "$", "lang", "=", "basename", "(", "$", "langfile", ",", "'.js'", ")", ";", "if", "(", "strtolower", "(", "$", "langfile", ")", "===", "$", "this", "->", "language", ".", "'.js'", ")", "{", "// Found an exact match for the language.", "$", "js", "=", "file_get_contents", "(", "$", "basedir", ".", "$", "langfile", ")", ";", "break", ";", "}", "if", "(", "substr", "(", "$", "this", "->", "language", ",", "0", ",", "2", ")", "===", "strtolower", "(", "substr", "(", "$", "langfile", ",", "0", ",", "2", ")", ")", ")", "{", "// Not an exact match but similar, for example \"pt_br\" is similar to \"pt\".", "$", "candidates", "[", "$", "lang", "]", "=", "$", "langfile", ";", "}", "}", "if", "(", "empty", "(", "$", "js", ")", "&&", "$", "candidates", ")", "{", "// Exact match was not found, take the first candidate.", "$", "this", "->", "language", "=", "key", "(", "$", "candidates", ")", ";", "$", "js", "=", "file_get_contents", "(", "$", "basedir", ".", "$", "candidates", "[", "$", "this", "->", "language", "]", ")", ";", "}", "// Add it as a language for Video.JS.", "if", "(", "!", "empty", "(", "$", "js", ")", ")", "{", "return", "\"$js\\n\"", ";", "}", "// Could not match, use default language of video player (English).", "$", "this", "->", "language", "=", "null", ";", "return", "\"\"", ";", "}" ]
Tries to match the current language to existing language files Matched language is stored in $this->language @return string JS code with a setting
[ "Tries", "to", "match", "the", "current", "language", "to", "existing", "language", "files" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/media/player/videojs/classes/plugin.php#L295-L329
217,152
moodle/moodle
media/player/videojs/classes/plugin.php
media_videojs_plugin.setup
public function setup($page) { // Load dynamic loader. It will scan page for videojs media and load necessary modules. // Loader will be loaded on absolutely every page, however the videojs will only be loaded // when video is present on the page or added later to it in AJAX. $path = new moodle_url('/media/player/videojs/videojs/video-js.swf'); $contents = 'videojs.options.flash.swf = "' . $path . '";' . "\n"; $contents .= $this->find_language(current_language()); $page->requires->js_amd_inline(<<<EOT require(["media_videojs/loader"], function(loader) { loader.setUp(function(videojs) { $contents }); }); EOT ); }
php
public function setup($page) { // Load dynamic loader. It will scan page for videojs media and load necessary modules. // Loader will be loaded on absolutely every page, however the videojs will only be loaded // when video is present on the page or added later to it in AJAX. $path = new moodle_url('/media/player/videojs/videojs/video-js.swf'); $contents = 'videojs.options.flash.swf = "' . $path . '";' . "\n"; $contents .= $this->find_language(current_language()); $page->requires->js_amd_inline(<<<EOT require(["media_videojs/loader"], function(loader) { loader.setUp(function(videojs) { $contents }); }); EOT ); }
[ "public", "function", "setup", "(", "$", "page", ")", "{", "// Load dynamic loader. It will scan page for videojs media and load necessary modules.", "// Loader will be loaded on absolutely every page, however the videojs will only be loaded", "// when video is present on the page or added later to it in AJAX.", "$", "path", "=", "new", "moodle_url", "(", "'/media/player/videojs/videojs/video-js.swf'", ")", ";", "$", "contents", "=", "'videojs.options.flash.swf = \"'", ".", "$", "path", ".", "'\";'", ".", "\"\\n\"", ";", "$", "contents", ".=", "$", "this", "->", "find_language", "(", "current_language", "(", ")", ")", ";", "$", "page", "->", "requires", "->", "js_amd_inline", "(", "<<<EOT\nrequire([\"media_videojs/loader\"], function(loader) {\n loader.setUp(function(videojs) {\n $contents\n });\n});\nEOT", ")", ";", "}" ]
Setup page requirements. @param moodle_page $page The page we are going to add requirements to.
[ "Setup", "page", "requirements", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/media/player/videojs/classes/plugin.php#L378-L394
217,153
moodle/moodle
course/classes/analytics/indicator/potential_social_breadth.php
potential_social_breadth.get_social_indicator
protected function get_social_indicator($modname) { $indicators = \core_analytics\manager::get_all_indicators(); foreach ($indicators as $indicator) { if ($indicator instanceof community_of_inquiry_activity && $indicator->get_indicator_type() === community_of_inquiry_activity::INDICATOR_SOCIAL && $indicator->get_activity_type() === $modname) { return $indicator; } } return false; }
php
protected function get_social_indicator($modname) { $indicators = \core_analytics\manager::get_all_indicators(); foreach ($indicators as $indicator) { if ($indicator instanceof community_of_inquiry_activity && $indicator->get_indicator_type() === community_of_inquiry_activity::INDICATOR_SOCIAL && $indicator->get_activity_type() === $modname) { return $indicator; } } return false; }
[ "protected", "function", "get_social_indicator", "(", "$", "modname", ")", "{", "$", "indicators", "=", "\\", "core_analytics", "\\", "manager", "::", "get_all_indicators", "(", ")", ";", "foreach", "(", "$", "indicators", "as", "$", "indicator", ")", "{", "if", "(", "$", "indicator", "instanceof", "community_of_inquiry_activity", "&&", "$", "indicator", "->", "get_indicator_type", "(", ")", "===", "community_of_inquiry_activity", "::", "INDICATOR_SOCIAL", "&&", "$", "indicator", "->", "get_activity_type", "(", ")", "===", "$", "modname", ")", "{", "return", "$", "indicator", ";", "}", "}", "return", "false", ";", "}" ]
Returns the social breadth class of this indicator. @param string $modname @return \core_analytics\local\indicator\base|false
[ "Returns", "the", "social", "breadth", "class", "of", "this", "indicator", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/analytics/indicator/potential_social_breadth.php#L127-L137
217,154
moodle/moodle
mod/forum/classes/local/vaults/post.php
post.from_db_records
protected function from_db_records(array $results) { $entityfactory = $this->get_entity_factory(); return array_map(function(array $result) use ($entityfactory) { ['record' => $record] = $result; return $entityfactory->get_post_from_stdclass($record); }, $results); }
php
protected function from_db_records(array $results) { $entityfactory = $this->get_entity_factory(); return array_map(function(array $result) use ($entityfactory) { ['record' => $record] = $result; return $entityfactory->get_post_from_stdclass($record); }, $results); }
[ "protected", "function", "from_db_records", "(", "array", "$", "results", ")", "{", "$", "entityfactory", "=", "$", "this", "->", "get_entity_factory", "(", ")", ";", "return", "array_map", "(", "function", "(", "array", "$", "result", ")", "use", "(", "$", "entityfactory", ")", "{", "[", "'record'", "=>", "$", "record", "]", "=", "$", "result", ";", "return", "$", "entityfactory", "->", "get_post_from_stdclass", "(", "$", "record", ")", ";", "}", ",", "$", "results", ")", ";", "}" ]
Convert the DB records into post entities. @param array $results The DB records @return post_entity[]
[ "Convert", "the", "DB", "records", "into", "post", "entities", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/post.php#L88-L95
217,155
moodle/moodle
mod/forum/classes/local/vaults/post.php
post.get_from_discussion_id
public function get_from_discussion_id( stdClass $user, int $discussionid, bool $canseeprivatereplies, string $orderby = 'created ASC' ) : array { $alias = $this->get_table_alias(); [ 'where' => $privatewhere, 'params' => $privateparams, ] = $this->get_private_reply_sql($user, $canseeprivatereplies); $wheresql = "{$alias}.discussion = :discussionid {$privatewhere}"; $orderbysql = $alias . '.' . $orderby; $sql = $this->generate_get_records_sql($wheresql, $orderbysql); $records = $this->get_db()->get_records_sql($sql, array_merge([ 'discussionid' => $discussionid, ], $privateparams)); return $this->transform_db_records_to_entities($records); }
php
public function get_from_discussion_id( stdClass $user, int $discussionid, bool $canseeprivatereplies, string $orderby = 'created ASC' ) : array { $alias = $this->get_table_alias(); [ 'where' => $privatewhere, 'params' => $privateparams, ] = $this->get_private_reply_sql($user, $canseeprivatereplies); $wheresql = "{$alias}.discussion = :discussionid {$privatewhere}"; $orderbysql = $alias . '.' . $orderby; $sql = $this->generate_get_records_sql($wheresql, $orderbysql); $records = $this->get_db()->get_records_sql($sql, array_merge([ 'discussionid' => $discussionid, ], $privateparams)); return $this->transform_db_records_to_entities($records); }
[ "public", "function", "get_from_discussion_id", "(", "stdClass", "$", "user", ",", "int", "$", "discussionid", ",", "bool", "$", "canseeprivatereplies", ",", "string", "$", "orderby", "=", "'created ASC'", ")", ":", "array", "{", "$", "alias", "=", "$", "this", "->", "get_table_alias", "(", ")", ";", "[", "'where'", "=>", "$", "privatewhere", ",", "'params'", "=>", "$", "privateparams", ",", "]", "=", "$", "this", "->", "get_private_reply_sql", "(", "$", "user", ",", "$", "canseeprivatereplies", ")", ";", "$", "wheresql", "=", "\"{$alias}.discussion = :discussionid {$privatewhere}\"", ";", "$", "orderbysql", "=", "$", "alias", ".", "'.'", ".", "$", "orderby", ";", "$", "sql", "=", "$", "this", "->", "generate_get_records_sql", "(", "$", "wheresql", ",", "$", "orderbysql", ")", ";", "$", "records", "=", "$", "this", "->", "get_db", "(", ")", "->", "get_records_sql", "(", "$", "sql", ",", "array_merge", "(", "[", "'discussionid'", "=>", "$", "discussionid", ",", "]", ",", "$", "privateparams", ")", ")", ";", "return", "$", "this", "->", "transform_db_records_to_entities", "(", "$", "records", ")", ";", "}" ]
Get the post ids for the given discussion. @param stdClass $user The user to check the unread count for @param int $discussionid The discussion to load posts for @param bool $canseeprivatereplies Whether this user can see all private replies or not @param string $orderby Order the results @return post_entity[]
[ "Get", "the", "post", "ids", "for", "the", "given", "discussion", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/post.php#L106-L128
217,156
moodle/moodle
mod/forum/classes/local/vaults/post.php
post.get_from_discussion_ids
public function get_from_discussion_ids(stdClass $user, array $discussionids, bool $canseeprivatereplies) : array { if (empty($discussionids)) { return []; } $alias = $this->get_table_alias(); list($insql, $params) = $this->get_db()->get_in_or_equal($discussionids, SQL_PARAMS_NAMED); [ 'where' => $privatewhere, 'params' => $privateparams, ] = $this->get_private_reply_sql($user, $canseeprivatereplies); $wheresql = "{$alias}.discussion {$insql} {$privatewhere}"; $sql = $this->generate_get_records_sql($wheresql, ''); $records = $this->get_db()->get_records_sql($sql, array_merge($params, $privateparams)); return $this->transform_db_records_to_entities($records); }
php
public function get_from_discussion_ids(stdClass $user, array $discussionids, bool $canseeprivatereplies) : array { if (empty($discussionids)) { return []; } $alias = $this->get_table_alias(); list($insql, $params) = $this->get_db()->get_in_or_equal($discussionids, SQL_PARAMS_NAMED); [ 'where' => $privatewhere, 'params' => $privateparams, ] = $this->get_private_reply_sql($user, $canseeprivatereplies); $wheresql = "{$alias}.discussion {$insql} {$privatewhere}"; $sql = $this->generate_get_records_sql($wheresql, ''); $records = $this->get_db()->get_records_sql($sql, array_merge($params, $privateparams)); return $this->transform_db_records_to_entities($records); }
[ "public", "function", "get_from_discussion_ids", "(", "stdClass", "$", "user", ",", "array", "$", "discussionids", ",", "bool", "$", "canseeprivatereplies", ")", ":", "array", "{", "if", "(", "empty", "(", "$", "discussionids", ")", ")", "{", "return", "[", "]", ";", "}", "$", "alias", "=", "$", "this", "->", "get_table_alias", "(", ")", ";", "list", "(", "$", "insql", ",", "$", "params", ")", "=", "$", "this", "->", "get_db", "(", ")", "->", "get_in_or_equal", "(", "$", "discussionids", ",", "SQL_PARAMS_NAMED", ")", ";", "[", "'where'", "=>", "$", "privatewhere", ",", "'params'", "=>", "$", "privateparams", ",", "]", "=", "$", "this", "->", "get_private_reply_sql", "(", "$", "user", ",", "$", "canseeprivatereplies", ")", ";", "$", "wheresql", "=", "\"{$alias}.discussion {$insql} {$privatewhere}\"", ";", "$", "sql", "=", "$", "this", "->", "generate_get_records_sql", "(", "$", "wheresql", ",", "''", ")", ";", "$", "records", "=", "$", "this", "->", "get_db", "(", ")", "->", "get_records_sql", "(", "$", "sql", ",", "array_merge", "(", "$", "params", ",", "$", "privateparams", ")", ")", ";", "return", "$", "this", "->", "transform_db_records_to_entities", "(", "$", "records", ")", ";", "}" ]
Get the list of posts for the given discussions. @param stdClass $user The user to check the unread count for @param int[] $discussionids The list of discussion ids to load posts for @param bool $canseeprivatereplies Whether this user can see all private replies or not @return post_entity[]
[ "Get", "the", "list", "of", "posts", "for", "the", "given", "discussions", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/post.php#L138-L157
217,157
moodle/moodle
mod/forum/classes/local/vaults/post.php
post.get_replies_to_post
public function get_replies_to_post( stdClass $user, post_entity $post, bool $canseeprivatereplies, string $orderby = 'created ASC' ) : array { $alias = $this->get_table_alias(); [ 'where' => $privatewhere, 'params' => $privateparams, ] = $this->get_private_reply_sql($user, $canseeprivatereplies); $params = array_merge([ 'discussionid' => $post->get_discussion_id(), 'created' => $post->get_time_created(), 'excludepostid' => $post->get_id(), ], $privateparams); // Unfortunately the best we can do to filter down the query is ignore all posts // that were created before the given post (since they can't be replies). // We also filter to remove private replies if the user cannot vie them. $wheresql = "{$alias}.discussion = :discussionid AND {$alias}.created >= :created {$privatewhere} AND {$alias}.id != :excludepostid"; $orderbysql = $alias . '.' . $orderby; $sql = $this->generate_get_records_sql($wheresql, $orderbysql); $records = $this->get_db()->get_records_sql($sql, $params); $posts = $this->transform_db_records_to_entities($records); $sorter = $this->get_entity_factory()->get_posts_sorter(); // We need to sort all of the values into the replies tree in order to capture // the full list of descendants. $sortedposts = $sorter->sort_into_children($posts); $replies = []; // From the sorted list we can grab the first elements and check if they are replies // to the post we care about. If so we keep them. foreach ($sortedposts as $candidate) { [$candidatepost, $candidatereplies] = $candidate; if ($candidatepost->has_parent() && $candidatepost->get_parent_id() == $post->get_id()) { $replies[] = $candidate; } } if (empty($replies)) { return $replies; } $getreplypostids = function($candidates) use (&$getreplypostids) { $ids = []; foreach ($candidates as $candidate) { [$reply, $replies] = $candidate; $ids = array_merge($ids, [$reply->get_id()], $getreplypostids($replies)); } return $ids; }; // Recursively build a list of the ids of all posts in the full reply tree. $replypostids = $getreplypostids($replies); // Now go back and filter the original result set down to just the posts that // we've flagged as in the reply tree. We need to filter the original set of values // so that we can maintain the requested sort order. return array_values(array_filter($posts, function($post) use ($replypostids) { return in_array($post->get_id(), $replypostids); })); }
php
public function get_replies_to_post( stdClass $user, post_entity $post, bool $canseeprivatereplies, string $orderby = 'created ASC' ) : array { $alias = $this->get_table_alias(); [ 'where' => $privatewhere, 'params' => $privateparams, ] = $this->get_private_reply_sql($user, $canseeprivatereplies); $params = array_merge([ 'discussionid' => $post->get_discussion_id(), 'created' => $post->get_time_created(), 'excludepostid' => $post->get_id(), ], $privateparams); // Unfortunately the best we can do to filter down the query is ignore all posts // that were created before the given post (since they can't be replies). // We also filter to remove private replies if the user cannot vie them. $wheresql = "{$alias}.discussion = :discussionid AND {$alias}.created >= :created {$privatewhere} AND {$alias}.id != :excludepostid"; $orderbysql = $alias . '.' . $orderby; $sql = $this->generate_get_records_sql($wheresql, $orderbysql); $records = $this->get_db()->get_records_sql($sql, $params); $posts = $this->transform_db_records_to_entities($records); $sorter = $this->get_entity_factory()->get_posts_sorter(); // We need to sort all of the values into the replies tree in order to capture // the full list of descendants. $sortedposts = $sorter->sort_into_children($posts); $replies = []; // From the sorted list we can grab the first elements and check if they are replies // to the post we care about. If so we keep them. foreach ($sortedposts as $candidate) { [$candidatepost, $candidatereplies] = $candidate; if ($candidatepost->has_parent() && $candidatepost->get_parent_id() == $post->get_id()) { $replies[] = $candidate; } } if (empty($replies)) { return $replies; } $getreplypostids = function($candidates) use (&$getreplypostids) { $ids = []; foreach ($candidates as $candidate) { [$reply, $replies] = $candidate; $ids = array_merge($ids, [$reply->get_id()], $getreplypostids($replies)); } return $ids; }; // Recursively build a list of the ids of all posts in the full reply tree. $replypostids = $getreplypostids($replies); // Now go back and filter the original result set down to just the posts that // we've flagged as in the reply tree. We need to filter the original set of values // so that we can maintain the requested sort order. return array_values(array_filter($posts, function($post) use ($replypostids) { return in_array($post->get_id(), $replypostids); })); }
[ "public", "function", "get_replies_to_post", "(", "stdClass", "$", "user", ",", "post_entity", "$", "post", ",", "bool", "$", "canseeprivatereplies", ",", "string", "$", "orderby", "=", "'created ASC'", ")", ":", "array", "{", "$", "alias", "=", "$", "this", "->", "get_table_alias", "(", ")", ";", "[", "'where'", "=>", "$", "privatewhere", ",", "'params'", "=>", "$", "privateparams", ",", "]", "=", "$", "this", "->", "get_private_reply_sql", "(", "$", "user", ",", "$", "canseeprivatereplies", ")", ";", "$", "params", "=", "array_merge", "(", "[", "'discussionid'", "=>", "$", "post", "->", "get_discussion_id", "(", ")", ",", "'created'", "=>", "$", "post", "->", "get_time_created", "(", ")", ",", "'excludepostid'", "=>", "$", "post", "->", "get_id", "(", ")", ",", "]", ",", "$", "privateparams", ")", ";", "// Unfortunately the best we can do to filter down the query is ignore all posts", "// that were created before the given post (since they can't be replies).", "// We also filter to remove private replies if the user cannot vie them.", "$", "wheresql", "=", "\"{$alias}.discussion = :discussionid\n AND {$alias}.created >= :created {$privatewhere}\n AND {$alias}.id != :excludepostid\"", ";", "$", "orderbysql", "=", "$", "alias", ".", "'.'", ".", "$", "orderby", ";", "$", "sql", "=", "$", "this", "->", "generate_get_records_sql", "(", "$", "wheresql", ",", "$", "orderbysql", ")", ";", "$", "records", "=", "$", "this", "->", "get_db", "(", ")", "->", "get_records_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "$", "posts", "=", "$", "this", "->", "transform_db_records_to_entities", "(", "$", "records", ")", ";", "$", "sorter", "=", "$", "this", "->", "get_entity_factory", "(", ")", "->", "get_posts_sorter", "(", ")", ";", "// We need to sort all of the values into the replies tree in order to capture", "// the full list of descendants.", "$", "sortedposts", "=", "$", "sorter", "->", "sort_into_children", "(", "$", "posts", ")", ";", "$", "replies", "=", "[", "]", ";", "// From the sorted list we can grab the first elements and check if they are replies", "// to the post we care about. If so we keep them.", "foreach", "(", "$", "sortedposts", "as", "$", "candidate", ")", "{", "[", "$", "candidatepost", ",", "$", "candidatereplies", "]", "=", "$", "candidate", ";", "if", "(", "$", "candidatepost", "->", "has_parent", "(", ")", "&&", "$", "candidatepost", "->", "get_parent_id", "(", ")", "==", "$", "post", "->", "get_id", "(", ")", ")", "{", "$", "replies", "[", "]", "=", "$", "candidate", ";", "}", "}", "if", "(", "empty", "(", "$", "replies", ")", ")", "{", "return", "$", "replies", ";", "}", "$", "getreplypostids", "=", "function", "(", "$", "candidates", ")", "use", "(", "&", "$", "getreplypostids", ")", "{", "$", "ids", "=", "[", "]", ";", "foreach", "(", "$", "candidates", "as", "$", "candidate", ")", "{", "[", "$", "reply", ",", "$", "replies", "]", "=", "$", "candidate", ";", "$", "ids", "=", "array_merge", "(", "$", "ids", ",", "[", "$", "reply", "->", "get_id", "(", ")", "]", ",", "$", "getreplypostids", "(", "$", "replies", ")", ")", ";", "}", "return", "$", "ids", ";", "}", ";", "// Recursively build a list of the ids of all posts in the full reply tree.", "$", "replypostids", "=", "$", "getreplypostids", "(", "$", "replies", ")", ";", "// Now go back and filter the original result set down to just the posts that", "// we've flagged as in the reply tree. We need to filter the original set of values", "// so that we can maintain the requested sort order.", "return", "array_values", "(", "array_filter", "(", "$", "posts", ",", "function", "(", "$", "post", ")", "use", "(", "$", "replypostids", ")", "{", "return", "in_array", "(", "$", "post", "->", "get_id", "(", ")", ",", "$", "replypostids", ")", ";", "}", ")", ")", ";", "}" ]
Load a list of replies to the given post. This will load all descendants of the post. That is, all direct replies and replies to those replies etc. The return value will be a flat array of posts in the requested order. @param stdClass $user The user to check the unread count for @param post_entity $post The post to load replies for @param bool $canseeprivatereplies Whether this user can see all private replies or not @param string $orderby How to order the replies @return post_entity[]
[ "Load", "a", "list", "of", "replies", "to", "the", "given", "post", ".", "This", "will", "load", "all", "descendants", "of", "the", "post", ".", "That", "is", "all", "direct", "replies", "and", "replies", "to", "those", "replies", "etc", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/post.php#L171-L239
217,158
moodle/moodle
mod/forum/classes/local/vaults/post.php
post.get_reply_count_for_post_id_in_discussion_id
public function get_reply_count_for_post_id_in_discussion_id( stdClass $user, int $postid, int $discussionid, bool $canseeprivatereplies) : int { [ 'where' => $privatewhere, 'params' => $privateparams, ] = $this->get_private_reply_sql($user, $canseeprivatereplies); $alias = $this->get_table_alias(); $table = self::TABLE; $sql = "SELECT {$alias}.id, {$alias}.parent FROM {{$table}} {$alias} WHERE p.discussion = :discussionid {$privatewhere}"; $postparents = $this->get_db()->get_records_sql_menu($sql, array_merge([ 'discussionid' => $discussionid, ], $privateparams)); return $this->count_children_from_parent_recursively($postparents, $postid); }
php
public function get_reply_count_for_post_id_in_discussion_id( stdClass $user, int $postid, int $discussionid, bool $canseeprivatereplies) : int { [ 'where' => $privatewhere, 'params' => $privateparams, ] = $this->get_private_reply_sql($user, $canseeprivatereplies); $alias = $this->get_table_alias(); $table = self::TABLE; $sql = "SELECT {$alias}.id, {$alias}.parent FROM {{$table}} {$alias} WHERE p.discussion = :discussionid {$privatewhere}"; $postparents = $this->get_db()->get_records_sql_menu($sql, array_merge([ 'discussionid' => $discussionid, ], $privateparams)); return $this->count_children_from_parent_recursively($postparents, $postid); }
[ "public", "function", "get_reply_count_for_post_id_in_discussion_id", "(", "stdClass", "$", "user", ",", "int", "$", "postid", ",", "int", "$", "discussionid", ",", "bool", "$", "canseeprivatereplies", ")", ":", "int", "{", "[", "'where'", "=>", "$", "privatewhere", ",", "'params'", "=>", "$", "privateparams", ",", "]", "=", "$", "this", "->", "get_private_reply_sql", "(", "$", "user", ",", "$", "canseeprivatereplies", ")", ";", "$", "alias", "=", "$", "this", "->", "get_table_alias", "(", ")", ";", "$", "table", "=", "self", "::", "TABLE", ";", "$", "sql", "=", "\"SELECT {$alias}.id, {$alias}.parent\n FROM {{$table}} {$alias}\n WHERE p.discussion = :discussionid {$privatewhere}\"", ";", "$", "postparents", "=", "$", "this", "->", "get_db", "(", ")", "->", "get_records_sql_menu", "(", "$", "sql", ",", "array_merge", "(", "[", "'discussionid'", "=>", "$", "discussionid", ",", "]", ",", "$", "privateparams", ")", ")", ";", "return", "$", "this", "->", "count_children_from_parent_recursively", "(", "$", "postparents", ",", "$", "postid", ")", ";", "}" ]
Get a mapping of replies to the specified discussions. @param stdClass $user The user to check the unread count for @param int $postid The post to collect replies to @param int $discussionid The list of discussions to fetch counts for @param bool $canseeprivatereplies Whether this user can see all private replies or not @return int The number of replies for each discussion returned in an associative array
[ "Get", "a", "mapping", "of", "replies", "to", "the", "specified", "discussions", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/post.php#L278-L297
217,159
moodle/moodle
mod/forum/classes/local/vaults/post.php
post.count_children_from_parent_recursively
private function count_children_from_parent_recursively(array $postparents, int $postid) : int { if (!isset($postparents[$postid])) { // Post not found at all. return 0; } $count = 0; foreach ($postparents as $pid => $parentid) { if ($postid == $parentid) { $count += $this->count_children_from_parent_recursively($postparents, $pid) + 1; } } return $count; }
php
private function count_children_from_parent_recursively(array $postparents, int $postid) : int { if (!isset($postparents[$postid])) { // Post not found at all. return 0; } $count = 0; foreach ($postparents as $pid => $parentid) { if ($postid == $parentid) { $count += $this->count_children_from_parent_recursively($postparents, $pid) + 1; } } return $count; }
[ "private", "function", "count_children_from_parent_recursively", "(", "array", "$", "postparents", ",", "int", "$", "postid", ")", ":", "int", "{", "if", "(", "!", "isset", "(", "$", "postparents", "[", "$", "postid", "]", ")", ")", "{", "// Post not found at all.", "return", "0", ";", "}", "$", "count", "=", "0", ";", "foreach", "(", "$", "postparents", "as", "$", "pid", "=>", "$", "parentid", ")", "{", "if", "(", "$", "postid", "==", "$", "parentid", ")", "{", "$", "count", "+=", "$", "this", "->", "count_children_from_parent_recursively", "(", "$", "postparents", ",", "$", "pid", ")", "+", "1", ";", "}", "}", "return", "$", "count", ";", "}" ]
Count the children whose parent matches the current record recursively. @param array $postparents The full mapping of posts. @param int $postid The ID to check for @return int $count
[ "Count", "the", "children", "whose", "parent", "matches", "the", "current", "record", "recursively", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/post.php#L306-L320
217,160
moodle/moodle
mod/forum/classes/local/vaults/post.php
post.get_unread_count_for_discussion_ids
public function get_unread_count_for_discussion_ids(stdClass $user, array $discussionids, bool $canseeprivatereplies) : array { global $CFG; if (empty($discussionids)) { return []; } [ 'where' => $privatewhere, 'params' => $privateparams, ] = $this->get_private_reply_sql($user, $canseeprivatereplies); $alias = $this->get_table_alias(); list($insql, $params) = $this->get_db()->get_in_or_equal($discussionids, SQL_PARAMS_NAMED); $sql = "SELECT p.discussion, COUNT(p.id) FROM {" . self::TABLE . "} p LEFT JOIN {forum_read} r ON r.postid = p.id AND r.userid = :userid WHERE p.discussion {$insql} AND p.modified > :cutofftime AND r.id IS NULL {$privatewhere} GROUP BY p.discussion"; $params['userid'] = $user->id; $params['cutofftime'] = floor((new \DateTime()) ->sub(new \DateInterval("P{$CFG->forum_oldpostdays}D")) ->format('U') / 60) * 60; return $this->get_db()->get_records_sql_menu($sql, array_merge($params, $privateparams)); }
php
public function get_unread_count_for_discussion_ids(stdClass $user, array $discussionids, bool $canseeprivatereplies) : array { global $CFG; if (empty($discussionids)) { return []; } [ 'where' => $privatewhere, 'params' => $privateparams, ] = $this->get_private_reply_sql($user, $canseeprivatereplies); $alias = $this->get_table_alias(); list($insql, $params) = $this->get_db()->get_in_or_equal($discussionids, SQL_PARAMS_NAMED); $sql = "SELECT p.discussion, COUNT(p.id) FROM {" . self::TABLE . "} p LEFT JOIN {forum_read} r ON r.postid = p.id AND r.userid = :userid WHERE p.discussion {$insql} AND p.modified > :cutofftime AND r.id IS NULL {$privatewhere} GROUP BY p.discussion"; $params['userid'] = $user->id; $params['cutofftime'] = floor((new \DateTime()) ->sub(new \DateInterval("P{$CFG->forum_oldpostdays}D")) ->format('U') / 60) * 60; return $this->get_db()->get_records_sql_menu($sql, array_merge($params, $privateparams)); }
[ "public", "function", "get_unread_count_for_discussion_ids", "(", "stdClass", "$", "user", ",", "array", "$", "discussionids", ",", "bool", "$", "canseeprivatereplies", ")", ":", "array", "{", "global", "$", "CFG", ";", "if", "(", "empty", "(", "$", "discussionids", ")", ")", "{", "return", "[", "]", ";", "}", "[", "'where'", "=>", "$", "privatewhere", ",", "'params'", "=>", "$", "privateparams", ",", "]", "=", "$", "this", "->", "get_private_reply_sql", "(", "$", "user", ",", "$", "canseeprivatereplies", ")", ";", "$", "alias", "=", "$", "this", "->", "get_table_alias", "(", ")", ";", "list", "(", "$", "insql", ",", "$", "params", ")", "=", "$", "this", "->", "get_db", "(", ")", "->", "get_in_or_equal", "(", "$", "discussionids", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "sql", "=", "\"SELECT p.discussion, COUNT(p.id) FROM {\"", ".", "self", "::", "TABLE", ".", "\"} p\n LEFT JOIN {forum_read} r ON r.postid = p.id AND r.userid = :userid\n WHERE p.discussion {$insql} AND p.modified > :cutofftime AND r.id IS NULL {$privatewhere}\n GROUP BY p.discussion\"", ";", "$", "params", "[", "'userid'", "]", "=", "$", "user", "->", "id", ";", "$", "params", "[", "'cutofftime'", "]", "=", "floor", "(", "(", "new", "\\", "DateTime", "(", ")", ")", "->", "sub", "(", "new", "\\", "DateInterval", "(", "\"P{$CFG->forum_oldpostdays}D\"", ")", ")", "->", "format", "(", "'U'", ")", "/", "60", ")", "*", "60", ";", "return", "$", "this", "->", "get_db", "(", ")", "->", "get_records_sql_menu", "(", "$", "sql", ",", "array_merge", "(", "$", "params", ",", "$", "privateparams", ")", ")", ";", "}" ]
Get a mapping of unread post counts for the specified discussions. @param stdClass $user The user to fetch counts for @param int[] $discussionids The list of discussions to fetch counts for @param bool $canseeprivatereplies Whether this user can see all private replies or not @return int[] The count of unread posts for each discussion returned in an associative array
[ "Get", "a", "mapping", "of", "unread", "post", "counts", "for", "the", "specified", "discussions", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/post.php#L330-L355
217,161
moodle/moodle
mod/forum/classes/local/vaults/post.php
post.get_private_reply_sql
private function get_private_reply_sql(stdClass $user, bool $canseeprivatereplies) { $params = []; $privatewhere = ''; if (!$canseeprivatereplies) { $privatewhere = ' AND (p.privatereplyto = :privatereplyto OR p.userid = :privatereplyfrom OR p.privatereplyto = 0)'; $params['privatereplyto'] = $user->id; $params['privatereplyfrom'] = $user->id; } return [ 'where' => $privatewhere, 'params' => $params, ]; }
php
private function get_private_reply_sql(stdClass $user, bool $canseeprivatereplies) { $params = []; $privatewhere = ''; if (!$canseeprivatereplies) { $privatewhere = ' AND (p.privatereplyto = :privatereplyto OR p.userid = :privatereplyfrom OR p.privatereplyto = 0)'; $params['privatereplyto'] = $user->id; $params['privatereplyfrom'] = $user->id; } return [ 'where' => $privatewhere, 'params' => $params, ]; }
[ "private", "function", "get_private_reply_sql", "(", "stdClass", "$", "user", ",", "bool", "$", "canseeprivatereplies", ")", "{", "$", "params", "=", "[", "]", ";", "$", "privatewhere", "=", "''", ";", "if", "(", "!", "$", "canseeprivatereplies", ")", "{", "$", "privatewhere", "=", "' AND (p.privatereplyto = :privatereplyto OR p.userid = :privatereplyfrom OR p.privatereplyto = 0)'", ";", "$", "params", "[", "'privatereplyto'", "]", "=", "$", "user", "->", "id", ";", "$", "params", "[", "'privatereplyfrom'", "]", "=", "$", "user", "->", "id", ";", "}", "return", "[", "'where'", "=>", "$", "privatewhere", ",", "'params'", "=>", "$", "params", ",", "]", ";", "}" ]
Get the SQL where and additional parameters to use to restrict posts to private reply posts. @param stdClass $user The user to fetch counts for @param bool $canseeprivatereplies Whether this user can see all private replies or not @return array The SQL WHERE clause, and parameters to use in the SQL.
[ "Get", "the", "SQL", "where", "and", "additional", "parameters", "to", "use", "to", "restrict", "posts", "to", "private", "reply", "posts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/post.php#L403-L416
217,162
moodle/moodle
mod/forum/classes/local/vaults/post.php
post.get_first_post_for_discussion_ids
public function get_first_post_for_discussion_ids(array $discussionids) : array { if (empty($discussionids)) { return []; } list($insql, $params) = $this->get_db()->get_in_or_equal($discussionids, SQL_PARAMS_NAMED); $sql = " SELECT p.* FROM {" . self::TABLE . "} p JOIN ( SELECT mp.discussion, MIN(mp.created) AS created FROM {" . self::TABLE . "} mp WHERE mp.discussion {$insql} GROUP BY mp.discussion ) lp ON lp.discussion = p.discussion AND lp.created = p.created"; return $this->get_db()->get_records_sql($sql, $params); }
php
public function get_first_post_for_discussion_ids(array $discussionids) : array { if (empty($discussionids)) { return []; } list($insql, $params) = $this->get_db()->get_in_or_equal($discussionids, SQL_PARAMS_NAMED); $sql = " SELECT p.* FROM {" . self::TABLE . "} p JOIN ( SELECT mp.discussion, MIN(mp.created) AS created FROM {" . self::TABLE . "} mp WHERE mp.discussion {$insql} GROUP BY mp.discussion ) lp ON lp.discussion = p.discussion AND lp.created = p.created"; return $this->get_db()->get_records_sql($sql, $params); }
[ "public", "function", "get_first_post_for_discussion_ids", "(", "array", "$", "discussionids", ")", ":", "array", "{", "if", "(", "empty", "(", "$", "discussionids", ")", ")", "{", "return", "[", "]", ";", "}", "list", "(", "$", "insql", ",", "$", "params", ")", "=", "$", "this", "->", "get_db", "(", ")", "->", "get_in_or_equal", "(", "$", "discussionids", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "sql", "=", "\"\n SELECT p.*\n FROM {\"", ".", "self", "::", "TABLE", ".", "\"} p\n JOIN (\n SELECT mp.discussion, MIN(mp.created) AS created\n FROM {\"", ".", "self", "::", "TABLE", ".", "\"} mp\n WHERE mp.discussion {$insql}\n GROUP BY mp.discussion\n ) lp ON lp.discussion = p.discussion AND lp.created = p.created\"", ";", "return", "$", "this", "->", "get_db", "(", ")", "->", "get_records_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "}" ]
Get a mapping of the first post in each discussion based on post creation time. @param int[] $discussionids The list of discussions to fetch counts for @return stdClass[] The post object of the first post for each discussions returned in an associative array
[ "Get", "a", "mapping", "of", "the", "first", "post", "in", "each", "discussion", "based", "on", "post", "creation", "time", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/post.php#L424-L443
217,163
moodle/moodle
lib/php-css-parser/CSSList/Document.php
Document.getAllValues
public function getAllValues($mElement = null, $bSearchInFunctionArguments = false) { $sSearchString = null; if ($mElement === null) { $mElement = $this; } else if (is_string($mElement)) { $sSearchString = $mElement; $mElement = $this; } $aResult = array(); $this->allValues($mElement, $aResult, $sSearchString, $bSearchInFunctionArguments); return $aResult; }
php
public function getAllValues($mElement = null, $bSearchInFunctionArguments = false) { $sSearchString = null; if ($mElement === null) { $mElement = $this; } else if (is_string($mElement)) { $sSearchString = $mElement; $mElement = $this; } $aResult = array(); $this->allValues($mElement, $aResult, $sSearchString, $bSearchInFunctionArguments); return $aResult; }
[ "public", "function", "getAllValues", "(", "$", "mElement", "=", "null", ",", "$", "bSearchInFunctionArguments", "=", "false", ")", "{", "$", "sSearchString", "=", "null", ";", "if", "(", "$", "mElement", "===", "null", ")", "{", "$", "mElement", "=", "$", "this", ";", "}", "else", "if", "(", "is_string", "(", "$", "mElement", ")", ")", "{", "$", "sSearchString", "=", "$", "mElement", ";", "$", "mElement", "=", "$", "this", ";", "}", "$", "aResult", "=", "array", "(", ")", ";", "$", "this", "->", "allValues", "(", "$", "mElement", ",", "$", "aResult", ",", "$", "sSearchString", ",", "$", "bSearchInFunctionArguments", ")", ";", "return", "$", "aResult", ";", "}" ]
Returns all Value objects found recursively in the tree. @param (object|string) $mElement the CSSList or RuleSet to start the search from (defaults to the whole document). If a string is given, it is used as rule name filter (@see{RuleSet->getRules()}). @param (bool) $bSearchInFunctionArguments whether to also return Value objects used as Function arguments.
[ "Returns", "all", "Value", "objects", "found", "recursively", "in", "the", "tree", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/php-css-parser/CSSList/Document.php#L47-L58
217,164
moodle/moodle
lib/behat/form_field/behat_form_editor.php
behat_form_editor.select_text
public function select_text() { // NodeElement.keyPress simply doesn't work. if (!$this->running_javascript()) { throw new coding_exception('Selecting text requires javascript.'); } $editorid = $this->field->getAttribute('id'); $js = ' (function() { var e = document.getElementById("'.$editorid.'editable"), r = rangy.createRange(), s = rangy.getSelection(); while ((e.firstChild !== null) && (e.firstChild.nodeType != document.TEXT_NODE)) { e = e.firstChild; } e.focus(); r.selectNodeContents(e); s.setSingleRange(r); }()); '; $this->session->executeScript($js); }
php
public function select_text() { // NodeElement.keyPress simply doesn't work. if (!$this->running_javascript()) { throw new coding_exception('Selecting text requires javascript.'); } $editorid = $this->field->getAttribute('id'); $js = ' (function() { var e = document.getElementById("'.$editorid.'editable"), r = rangy.createRange(), s = rangy.getSelection(); while ((e.firstChild !== null) && (e.firstChild.nodeType != document.TEXT_NODE)) { e = e.firstChild; } e.focus(); r.selectNodeContents(e); s.setSingleRange(r); }()); '; $this->session->executeScript($js); }
[ "public", "function", "select_text", "(", ")", "{", "// NodeElement.keyPress simply doesn't work.", "if", "(", "!", "$", "this", "->", "running_javascript", "(", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Selecting text requires javascript.'", ")", ";", "}", "$", "editorid", "=", "$", "this", "->", "field", "->", "getAttribute", "(", "'id'", ")", ";", "$", "js", "=", "' (function() {\n var e = document.getElementById(\"'", ".", "$", "editorid", ".", "'editable\"),\n r = rangy.createRange(),\n s = rangy.getSelection();\n\n while ((e.firstChild !== null) && (e.firstChild.nodeType != document.TEXT_NODE)) {\n e = e.firstChild;\n }\n e.focus();\n r.selectNodeContents(e);\n s.setSingleRange(r);\n}()); '", ";", "$", "this", "->", "session", "->", "executeScript", "(", "$", "js", ")", ";", "}" ]
Select all the text in the form field.
[ "Select", "all", "the", "text", "in", "the", "form", "field", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/form_field/behat_form_editor.php#L72-L92
217,165
moodle/moodle
mod/forum/classes/local/entities/post_read_receipt_collection.php
post_read_receipt_collection.has_user_read_post
public function has_user_read_post(stdClass $user, post_entity $post) : bool { global $CFG; $isoldpost = ($post->get_time_modified() < (time() - ($CFG->forum_oldpostdays * 24 * 3600))); if ($isoldpost) { return true; } $receipts = isset($this->receiptsbypostid[$post->get_id()]) ? $this->receiptsbypostid[$post->get_id()] : []; foreach ($receipts as $receipt) { if ($receipt->userid == $user->id) { return true; } } return false; }
php
public function has_user_read_post(stdClass $user, post_entity $post) : bool { global $CFG; $isoldpost = ($post->get_time_modified() < (time() - ($CFG->forum_oldpostdays * 24 * 3600))); if ($isoldpost) { return true; } $receipts = isset($this->receiptsbypostid[$post->get_id()]) ? $this->receiptsbypostid[$post->get_id()] : []; foreach ($receipts as $receipt) { if ($receipt->userid == $user->id) { return true; } } return false; }
[ "public", "function", "has_user_read_post", "(", "stdClass", "$", "user", ",", "post_entity", "$", "post", ")", ":", "bool", "{", "global", "$", "CFG", ";", "$", "isoldpost", "=", "(", "$", "post", "->", "get_time_modified", "(", ")", "<", "(", "time", "(", ")", "-", "(", "$", "CFG", "->", "forum_oldpostdays", "*", "24", "*", "3600", ")", ")", ")", ";", "if", "(", "$", "isoldpost", ")", "{", "return", "true", ";", "}", "$", "receipts", "=", "isset", "(", "$", "this", "->", "receiptsbypostid", "[", "$", "post", "->", "get_id", "(", ")", "]", ")", "?", "$", "this", "->", "receiptsbypostid", "[", "$", "post", "->", "get_id", "(", ")", "]", ":", "[", "]", ";", "foreach", "(", "$", "receipts", "as", "$", "receipt", ")", "{", "if", "(", "$", "receipt", "->", "userid", "==", "$", "user", "->", "id", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Check whether a user has read a post. @param stdClass $user The user to check @param post_entity $post The post to check @return bool
[ "Check", "whether", "a", "user", "has", "read", "a", "post", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/entities/post_read_receipt_collection.php#L68-L85
217,166
moodle/moodle
calendar/classes/external/calendar_event_exporter.php
calendar_event_exporter.define_related
protected static function define_related() { $related = parent::define_related(); $related['daylink'] = \moodle_url::class; $related['type'] = '\core_calendar\type_base'; $related['today'] = 'int'; $related['moduleinstance'] = 'stdClass?'; return $related; }
php
protected static function define_related() { $related = parent::define_related(); $related['daylink'] = \moodle_url::class; $related['type'] = '\core_calendar\type_base'; $related['today'] = 'int'; $related['moduleinstance'] = 'stdClass?'; return $related; }
[ "protected", "static", "function", "define_related", "(", ")", "{", "$", "related", "=", "parent", "::", "define_related", "(", ")", ";", "$", "related", "[", "'daylink'", "]", "=", "\\", "moodle_url", "::", "class", ";", "$", "related", "[", "'type'", "]", "=", "'\\core_calendar\\type_base'", ";", "$", "related", "[", "'today'", "]", "=", "'int'", ";", "$", "related", "[", "'moduleinstance'", "]", "=", "'stdClass?'", ";", "return", "$", "related", ";", "}" ]
Returns a list of objects that are related. @return array
[ "Returns", "a", "list", "of", "objects", "that", "are", "related", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/external/calendar_event_exporter.php#L187-L195
217,167
moodle/moodle
calendar/classes/external/calendar_event_exporter.php
calendar_event_exporter.get_timestamp_min_limit
protected function get_timestamp_min_limit(\DateTimeInterface $starttime, $min) { // We need to check that the minimum valid time is earlier in the // day than the current event time so that if the user drags and drops // the event to this day (which changes the date but not the time) it // will result in a valid time start for the event. // // For example: // An event that starts on 2017-01-10 08:00 with a minimum cutoff // of 2017-01-05 09:00 means that 2017-01-05 is not a valid start day // for the drag and drop because it would result in the event start time // being set to 2017-01-05 08:00, which is invalid. Instead the minimum // valid start day would be 2017-01-06. $values = []; $timestamp = $min[0]; $errorstring = $min[1]; $mindate = (new \DateTimeImmutable())->setTimestamp($timestamp); $minstart = $mindate->setTime( $starttime->format('H'), $starttime->format('i'), $starttime->format('s') ); $midnight = usergetmidnight($timestamp); if ($mindate <= $minstart) { $values['mindaytimestamp'] = $midnight; } else { $tomorrow = (new \DateTime())->setTimestamp($midnight)->modify('+1 day'); $values['mindaytimestamp'] = $tomorrow->getTimestamp(); } // Get the human readable error message to display if the min day // timestamp is violated. $values['mindayerror'] = $errorstring; return $values; }
php
protected function get_timestamp_min_limit(\DateTimeInterface $starttime, $min) { // We need to check that the minimum valid time is earlier in the // day than the current event time so that if the user drags and drops // the event to this day (which changes the date but not the time) it // will result in a valid time start for the event. // // For example: // An event that starts on 2017-01-10 08:00 with a minimum cutoff // of 2017-01-05 09:00 means that 2017-01-05 is not a valid start day // for the drag and drop because it would result in the event start time // being set to 2017-01-05 08:00, which is invalid. Instead the minimum // valid start day would be 2017-01-06. $values = []; $timestamp = $min[0]; $errorstring = $min[1]; $mindate = (new \DateTimeImmutable())->setTimestamp($timestamp); $minstart = $mindate->setTime( $starttime->format('H'), $starttime->format('i'), $starttime->format('s') ); $midnight = usergetmidnight($timestamp); if ($mindate <= $minstart) { $values['mindaytimestamp'] = $midnight; } else { $tomorrow = (new \DateTime())->setTimestamp($midnight)->modify('+1 day'); $values['mindaytimestamp'] = $tomorrow->getTimestamp(); } // Get the human readable error message to display if the min day // timestamp is violated. $values['mindayerror'] = $errorstring; return $values; }
[ "protected", "function", "get_timestamp_min_limit", "(", "\\", "DateTimeInterface", "$", "starttime", ",", "$", "min", ")", "{", "// We need to check that the minimum valid time is earlier in the", "// day than the current event time so that if the user drags and drops", "// the event to this day (which changes the date but not the time) it", "// will result in a valid time start for the event.", "//", "// For example:", "// An event that starts on 2017-01-10 08:00 with a minimum cutoff", "// of 2017-01-05 09:00 means that 2017-01-05 is not a valid start day", "// for the drag and drop because it would result in the event start time", "// being set to 2017-01-05 08:00, which is invalid. Instead the minimum", "// valid start day would be 2017-01-06.", "$", "values", "=", "[", "]", ";", "$", "timestamp", "=", "$", "min", "[", "0", "]", ";", "$", "errorstring", "=", "$", "min", "[", "1", "]", ";", "$", "mindate", "=", "(", "new", "\\", "DateTimeImmutable", "(", ")", ")", "->", "setTimestamp", "(", "$", "timestamp", ")", ";", "$", "minstart", "=", "$", "mindate", "->", "setTime", "(", "$", "starttime", "->", "format", "(", "'H'", ")", ",", "$", "starttime", "->", "format", "(", "'i'", ")", ",", "$", "starttime", "->", "format", "(", "'s'", ")", ")", ";", "$", "midnight", "=", "usergetmidnight", "(", "$", "timestamp", ")", ";", "if", "(", "$", "mindate", "<=", "$", "minstart", ")", "{", "$", "values", "[", "'mindaytimestamp'", "]", "=", "$", "midnight", ";", "}", "else", "{", "$", "tomorrow", "=", "(", "new", "\\", "DateTime", "(", ")", ")", "->", "setTimestamp", "(", "$", "midnight", ")", "->", "modify", "(", "'+1 day'", ")", ";", "$", "values", "[", "'mindaytimestamp'", "]", "=", "$", "tomorrow", "->", "getTimestamp", "(", ")", ";", "}", "// Get the human readable error message to display if the min day", "// timestamp is violated.", "$", "values", "[", "'mindayerror'", "]", "=", "$", "errorstring", ";", "return", "$", "values", ";", "}" ]
Get the correct minimum midnight day limit based on the event start time and the minimum timestamp limit of what the event belongs to. @param DateTimeInterface $starttime The event start time @param array $min The module's minimum limit for the event @return array Returns an array with mindaytimestamp and mindayerror keys.
[ "Get", "the", "correct", "minimum", "midnight", "day", "limit", "based", "on", "the", "event", "start", "time", "and", "the", "minimum", "timestamp", "limit", "of", "what", "the", "event", "belongs", "to", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/external/calendar_event_exporter.php#L297-L331
217,168
moodle/moodle
calendar/classes/external/calendar_event_exporter.php
calendar_event_exporter.get_timestamp_max_limit
protected function get_timestamp_max_limit(\DateTimeInterface $starttime, $max) { // We're doing a similar calculation here as we are for the minimum // day timestamp. See the explanation above. $values = []; $timestamp = $max[0]; $errorstring = $max[1]; $maxdate = (new \DateTimeImmutable())->setTimestamp($timestamp); $maxstart = $maxdate->setTime( $starttime->format('H'), $starttime->format('i'), $starttime->format('s') ); $midnight = usergetmidnight($timestamp); if ($maxdate >= $maxstart) { $values['maxdaytimestamp'] = $midnight; } else { $yesterday = (new \DateTime())->setTimestamp($midnight)->modify('-1 day'); $values['maxdaytimestamp'] = $yesterday->getTimestamp(); } // Get the human readable error message to display if the max day // timestamp is violated. $values['maxdayerror'] = $errorstring; return $values; }
php
protected function get_timestamp_max_limit(\DateTimeInterface $starttime, $max) { // We're doing a similar calculation here as we are for the minimum // day timestamp. See the explanation above. $values = []; $timestamp = $max[0]; $errorstring = $max[1]; $maxdate = (new \DateTimeImmutable())->setTimestamp($timestamp); $maxstart = $maxdate->setTime( $starttime->format('H'), $starttime->format('i'), $starttime->format('s') ); $midnight = usergetmidnight($timestamp); if ($maxdate >= $maxstart) { $values['maxdaytimestamp'] = $midnight; } else { $yesterday = (new \DateTime())->setTimestamp($midnight)->modify('-1 day'); $values['maxdaytimestamp'] = $yesterday->getTimestamp(); } // Get the human readable error message to display if the max day // timestamp is violated. $values['maxdayerror'] = $errorstring; return $values; }
[ "protected", "function", "get_timestamp_max_limit", "(", "\\", "DateTimeInterface", "$", "starttime", ",", "$", "max", ")", "{", "// We're doing a similar calculation here as we are for the minimum", "// day timestamp. See the explanation above.", "$", "values", "=", "[", "]", ";", "$", "timestamp", "=", "$", "max", "[", "0", "]", ";", "$", "errorstring", "=", "$", "max", "[", "1", "]", ";", "$", "maxdate", "=", "(", "new", "\\", "DateTimeImmutable", "(", ")", ")", "->", "setTimestamp", "(", "$", "timestamp", ")", ";", "$", "maxstart", "=", "$", "maxdate", "->", "setTime", "(", "$", "starttime", "->", "format", "(", "'H'", ")", ",", "$", "starttime", "->", "format", "(", "'i'", ")", ",", "$", "starttime", "->", "format", "(", "'s'", ")", ")", ";", "$", "midnight", "=", "usergetmidnight", "(", "$", "timestamp", ")", ";", "if", "(", "$", "maxdate", ">=", "$", "maxstart", ")", "{", "$", "values", "[", "'maxdaytimestamp'", "]", "=", "$", "midnight", ";", "}", "else", "{", "$", "yesterday", "=", "(", "new", "\\", "DateTime", "(", ")", ")", "->", "setTimestamp", "(", "$", "midnight", ")", "->", "modify", "(", "'-1 day'", ")", ";", "$", "values", "[", "'maxdaytimestamp'", "]", "=", "$", "yesterday", "->", "getTimestamp", "(", ")", ";", "}", "// Get the human readable error message to display if the max day", "// timestamp is violated.", "$", "values", "[", "'maxdayerror'", "]", "=", "$", "errorstring", ";", "return", "$", "values", ";", "}" ]
Get the correct maximum midnight day limit based on the event start time and the maximum timestamp limit of what the event belongs to. @param DateTimeInterface $starttime The event start time @param array $max The module's maximum limit for the event @return array Returns an array with maxdaytimestamp and maxdayerror keys.
[ "Get", "the", "correct", "maximum", "midnight", "day", "limit", "based", "on", "the", "event", "start", "time", "and", "the", "maximum", "timestamp", "limit", "of", "what", "the", "event", "belongs", "to", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/external/calendar_event_exporter.php#L341-L366
217,169
moodle/moodle
calendar/classes/external/calendar_event_exporter.php
calendar_event_exporter.get_module_timestamp_min_limit
protected function get_module_timestamp_min_limit(\DateTimeInterface $starttime, $min) { debugging('get_module_timestamp_min_limit() has been deprecated. Please call get_timestamp_min_limit() instead.', DEBUG_DEVELOPER); return $this->get_timestamp_min_limit($starttime, $min); }
php
protected function get_module_timestamp_min_limit(\DateTimeInterface $starttime, $min) { debugging('get_module_timestamp_min_limit() has been deprecated. Please call get_timestamp_min_limit() instead.', DEBUG_DEVELOPER); return $this->get_timestamp_min_limit($starttime, $min); }
[ "protected", "function", "get_module_timestamp_min_limit", "(", "\\", "DateTimeInterface", "$", "starttime", ",", "$", "min", ")", "{", "debugging", "(", "'get_module_timestamp_min_limit() has been deprecated. Please call get_timestamp_min_limit() instead.'", ",", "DEBUG_DEVELOPER", ")", ";", "return", "$", "this", "->", "get_timestamp_min_limit", "(", "$", "starttime", ",", "$", "min", ")", ";", "}" ]
Get the correct minimum midnight day limit based on the event start time and the module's minimum timestamp limit. @deprecated since Moodle 3.6. Please use get_timestamp_min_limit(). @todo final deprecation. To be removed in Moodle 4.0 @param DateTimeInterface $starttime The event start time @param array $min The module's minimum limit for the event @return array Returns an array with mindaytimestamp and mindayerror keys.
[ "Get", "the", "correct", "minimum", "midnight", "day", "limit", "based", "on", "the", "event", "start", "time", "and", "the", "module", "s", "minimum", "timestamp", "limit", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/external/calendar_event_exporter.php#L378-L382
217,170
moodle/moodle
calendar/classes/external/calendar_event_exporter.php
calendar_event_exporter.get_module_timestamp_max_limit
protected function get_module_timestamp_max_limit(\DateTimeInterface $starttime, $max) { debugging('get_module_timestamp_max_limit() has been deprecated. Please call get_timestamp_max_limit() instead.', DEBUG_DEVELOPER); return $this->get_timestamp_max_limit($starttime, $max); }
php
protected function get_module_timestamp_max_limit(\DateTimeInterface $starttime, $max) { debugging('get_module_timestamp_max_limit() has been deprecated. Please call get_timestamp_max_limit() instead.', DEBUG_DEVELOPER); return $this->get_timestamp_max_limit($starttime, $max); }
[ "protected", "function", "get_module_timestamp_max_limit", "(", "\\", "DateTimeInterface", "$", "starttime", ",", "$", "max", ")", "{", "debugging", "(", "'get_module_timestamp_max_limit() has been deprecated. Please call get_timestamp_max_limit() instead.'", ",", "DEBUG_DEVELOPER", ")", ";", "return", "$", "this", "->", "get_timestamp_max_limit", "(", "$", "starttime", ",", "$", "max", ")", ";", "}" ]
Get the correct maximum midnight day limit based on the event start time and the module's maximum timestamp limit. @deprecated since Moodle 3.6. Please use get_timestamp_max_limit(). @todo final deprecation. To be removed in Moodle 4.0 @param DateTimeInterface $starttime The event start time @param array $max The module's maximum limit for the event @return array Returns an array with maxdaytimestamp and maxdayerror keys.
[ "Get", "the", "correct", "maximum", "midnight", "day", "limit", "based", "on", "the", "event", "start", "time", "and", "the", "module", "s", "maximum", "timestamp", "limit", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/external/calendar_event_exporter.php#L394-L398
217,171
moodle/moodle
backup/converter/convertlib.php
base_converter.convert
public function convert() { try { $this->log('creating the target directory', backup::LOG_DEBUG); $this->create_workdir(); $this->log('executing the conversion', backup::LOG_DEBUG); $this->execute(); $this->log('replacing the source directory with the converted version', backup::LOG_DEBUG); $this->replace_tempdir(); } catch (Exception $e) { } // clean-up stuff if needed $this->destroy(); // eventually re-throw the execution exception if (isset($e) and ($e instanceof Exception)) { throw $e; } }
php
public function convert() { try { $this->log('creating the target directory', backup::LOG_DEBUG); $this->create_workdir(); $this->log('executing the conversion', backup::LOG_DEBUG); $this->execute(); $this->log('replacing the source directory with the converted version', backup::LOG_DEBUG); $this->replace_tempdir(); } catch (Exception $e) { } // clean-up stuff if needed $this->destroy(); // eventually re-throw the execution exception if (isset($e) and ($e instanceof Exception)) { throw $e; } }
[ "public", "function", "convert", "(", ")", "{", "try", "{", "$", "this", "->", "log", "(", "'creating the target directory'", ",", "backup", "::", "LOG_DEBUG", ")", ";", "$", "this", "->", "create_workdir", "(", ")", ";", "$", "this", "->", "log", "(", "'executing the conversion'", ",", "backup", "::", "LOG_DEBUG", ")", ";", "$", "this", "->", "execute", "(", ")", ";", "$", "this", "->", "log", "(", "'replacing the source directory with the converted version'", ",", "backup", "::", "LOG_DEBUG", ")", ";", "$", "this", "->", "replace_tempdir", "(", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "}", "// clean-up stuff if needed", "$", "this", "->", "destroy", "(", ")", ";", "// eventually re-throw the execution exception", "if", "(", "isset", "(", "$", "e", ")", "and", "(", "$", "e", "instanceof", "Exception", ")", ")", "{", "throw", "$", "e", ";", "}", "}" ]
Converts the backup directory
[ "Converts", "the", "backup", "directory" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/convertlib.php#L122-L143
217,172
moodle/moodle
backup/converter/convertlib.php
base_converter.replace_tempdir
protected function replace_tempdir() { global $CFG; $tempdir = $this->get_tempdir_path(); if (empty($CFG->keeptempdirectoriesonbackup)) { fulldelete($tempdir); } else { if (!rename($tempdir, $tempdir . '_' . $this->get_name() . '_' . $this->id . '_source')) { throw new convert_exception('failed_rename_source_tempdir'); } } if (!rename($this->get_workdir_path(), $tempdir)) { throw new convert_exception('failed_move_converted_into_place'); } }
php
protected function replace_tempdir() { global $CFG; $tempdir = $this->get_tempdir_path(); if (empty($CFG->keeptempdirectoriesonbackup)) { fulldelete($tempdir); } else { if (!rename($tempdir, $tempdir . '_' . $this->get_name() . '_' . $this->id . '_source')) { throw new convert_exception('failed_rename_source_tempdir'); } } if (!rename($this->get_workdir_path(), $tempdir)) { throw new convert_exception('failed_move_converted_into_place'); } }
[ "protected", "function", "replace_tempdir", "(", ")", "{", "global", "$", "CFG", ";", "$", "tempdir", "=", "$", "this", "->", "get_tempdir_path", "(", ")", ";", "if", "(", "empty", "(", "$", "CFG", "->", "keeptempdirectoriesonbackup", ")", ")", "{", "fulldelete", "(", "$", "tempdir", ")", ";", "}", "else", "{", "if", "(", "!", "rename", "(", "$", "tempdir", ",", "$", "tempdir", ".", "'_'", ".", "$", "this", "->", "get_name", "(", ")", ".", "'_'", ".", "$", "this", "->", "id", ".", "'_source'", ")", ")", "{", "throw", "new", "convert_exception", "(", "'failed_rename_source_tempdir'", ")", ";", "}", "}", "if", "(", "!", "rename", "(", "$", "this", "->", "get_workdir_path", "(", ")", ",", "$", "tempdir", ")", ")", "{", "throw", "new", "convert_exception", "(", "'failed_move_converted_into_place'", ")", ";", "}", "}" ]
Replaces the source backup directory with the converted version If $CFG->keeptempdirectoriesonbackup is defined, the original source source backup directory is kept for debugging purposes.
[ "Replaces", "the", "source", "backup", "directory", "with", "the", "converted", "version" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/convertlib.php#L239-L255
217,173
moodle/moodle
mod/quiz/classes/structure.php
structure.create_for_quiz
public static function create_for_quiz($quizobj) { $structure = self::create(); $structure->quizobj = $quizobj; $structure->populate_structure($quizobj->get_quiz()); return $structure; }
php
public static function create_for_quiz($quizobj) { $structure = self::create(); $structure->quizobj = $quizobj; $structure->populate_structure($quizobj->get_quiz()); return $structure; }
[ "public", "static", "function", "create_for_quiz", "(", "$", "quizobj", ")", "{", "$", "structure", "=", "self", "::", "create", "(", ")", ";", "$", "structure", "->", "quizobj", "=", "$", "quizobj", ";", "$", "structure", "->", "populate_structure", "(", "$", "quizobj", "->", "get_quiz", "(", ")", ")", ";", "return", "$", "structure", ";", "}" ]
Create an instance of this class representing the structure of a given quiz. @param \quiz $quizobj the quiz. @return structure
[ "Create", "an", "instance", "of", "this", "class", "representing", "the", "structure", "of", "a", "given", "quiz", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/structure.php#L86-L91
217,174
moodle/moodle
mod/quiz/classes/structure.php
structure.can_finish_during_the_attempt
public function can_finish_during_the_attempt($slotnumber) { if ($this->quizobj->get_navigation_method() == QUIZ_NAVMETHOD_SEQ) { return false; } if ($this->slotsinorder[$slotnumber]->section->shufflequestions) { return false; } if (in_array($this->get_question_type_for_slot($slotnumber), array('random', 'missingtype'))) { return \question_engine::can_questions_finish_during_the_attempt( $this->quizobj->get_quiz()->preferredbehaviour); } if (isset($this->slotsinorder[$slotnumber]->canfinish)) { return $this->slotsinorder[$slotnumber]->canfinish; } try { $quba = \question_engine::make_questions_usage_by_activity('mod_quiz', $this->quizobj->get_context()); $tempslot = $quba->add_question(\question_bank::load_question( $this->slotsinorder[$slotnumber]->questionid)); $quba->set_preferred_behaviour($this->quizobj->get_quiz()->preferredbehaviour); $quba->start_all_questions(); $this->slotsinorder[$slotnumber]->canfinish = $quba->can_question_finish_during_attempt($tempslot); return $this->slotsinorder[$slotnumber]->canfinish; } catch (\Exception $e) { // If the question fails to start, this should not block editing. return false; } }
php
public function can_finish_during_the_attempt($slotnumber) { if ($this->quizobj->get_navigation_method() == QUIZ_NAVMETHOD_SEQ) { return false; } if ($this->slotsinorder[$slotnumber]->section->shufflequestions) { return false; } if (in_array($this->get_question_type_for_slot($slotnumber), array('random', 'missingtype'))) { return \question_engine::can_questions_finish_during_the_attempt( $this->quizobj->get_quiz()->preferredbehaviour); } if (isset($this->slotsinorder[$slotnumber]->canfinish)) { return $this->slotsinorder[$slotnumber]->canfinish; } try { $quba = \question_engine::make_questions_usage_by_activity('mod_quiz', $this->quizobj->get_context()); $tempslot = $quba->add_question(\question_bank::load_question( $this->slotsinorder[$slotnumber]->questionid)); $quba->set_preferred_behaviour($this->quizobj->get_quiz()->preferredbehaviour); $quba->start_all_questions(); $this->slotsinorder[$slotnumber]->canfinish = $quba->can_question_finish_during_attempt($tempslot); return $this->slotsinorder[$slotnumber]->canfinish; } catch (\Exception $e) { // If the question fails to start, this should not block editing. return false; } }
[ "public", "function", "can_finish_during_the_attempt", "(", "$", "slotnumber", ")", "{", "if", "(", "$", "this", "->", "quizobj", "->", "get_navigation_method", "(", ")", "==", "QUIZ_NAVMETHOD_SEQ", ")", "{", "return", "false", ";", "}", "if", "(", "$", "this", "->", "slotsinorder", "[", "$", "slotnumber", "]", "->", "section", "->", "shufflequestions", ")", "{", "return", "false", ";", "}", "if", "(", "in_array", "(", "$", "this", "->", "get_question_type_for_slot", "(", "$", "slotnumber", ")", ",", "array", "(", "'random'", ",", "'missingtype'", ")", ")", ")", "{", "return", "\\", "question_engine", "::", "can_questions_finish_during_the_attempt", "(", "$", "this", "->", "quizobj", "->", "get_quiz", "(", ")", "->", "preferredbehaviour", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "slotsinorder", "[", "$", "slotnumber", "]", "->", "canfinish", ")", ")", "{", "return", "$", "this", "->", "slotsinorder", "[", "$", "slotnumber", "]", "->", "canfinish", ";", "}", "try", "{", "$", "quba", "=", "\\", "question_engine", "::", "make_questions_usage_by_activity", "(", "'mod_quiz'", ",", "$", "this", "->", "quizobj", "->", "get_context", "(", ")", ")", ";", "$", "tempslot", "=", "$", "quba", "->", "add_question", "(", "\\", "question_bank", "::", "load_question", "(", "$", "this", "->", "slotsinorder", "[", "$", "slotnumber", "]", "->", "questionid", ")", ")", ";", "$", "quba", "->", "set_preferred_behaviour", "(", "$", "this", "->", "quizobj", "->", "get_quiz", "(", ")", "->", "preferredbehaviour", ")", ";", "$", "quba", "->", "start_all_questions", "(", ")", ";", "$", "this", "->", "slotsinorder", "[", "$", "slotnumber", "]", "->", "canfinish", "=", "$", "quba", "->", "can_question_finish_during_attempt", "(", "$", "tempslot", ")", ";", "return", "$", "this", "->", "slotsinorder", "[", "$", "slotnumber", "]", "->", "canfinish", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "// If the question fails to start, this should not block editing.", "return", "false", ";", "}", "}" ]
Whether it is possible for another question to depend on this one finishing. Note that the answer is not exact, because of random questions, and sometimes questions cannot be depended upon because of quiz options. @param int $slotnumber the index of the slot in question. @return bool can this question finish naturally during the attempt?
[ "Whether", "it", "is", "possible", "for", "another", "question", "to", "depend", "on", "this", "one", "finishing", ".", "Note", "that", "the", "answer", "is", "not", "exact", "because", "of", "random", "questions", "and", "sometimes", "questions", "cannot", "be", "depended", "upon", "because", "of", "quiz", "options", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/structure.php#L183-L214
217,175
moodle/moodle
mod/quiz/classes/structure.php
structure.can_be_edited
public function can_be_edited() { if ($this->canbeedited === null) { $this->canbeedited = !quiz_has_attempts($this->quizobj->get_quizid()); } return $this->canbeedited; }
php
public function can_be_edited() { if ($this->canbeedited === null) { $this->canbeedited = !quiz_has_attempts($this->quizobj->get_quizid()); } return $this->canbeedited; }
[ "public", "function", "can_be_edited", "(", ")", "{", "if", "(", "$", "this", "->", "canbeedited", "===", "null", ")", "{", "$", "this", "->", "canbeedited", "=", "!", "quiz_has_attempts", "(", "$", "this", "->", "quizobj", "->", "get_quizid", "(", ")", ")", ";", "}", "return", "$", "this", "->", "canbeedited", ";", "}" ]
Quizzes can only be edited if they have not been attempted. @return bool whether the quiz can be edited.
[ "Quizzes", "can", "only", "be", "edited", "if", "they", "have", "not", "been", "attempted", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/structure.php#L281-L286
217,176
moodle/moodle
mod/quiz/classes/structure.php
structure.check_can_be_edited
public function check_can_be_edited() { if (!$this->can_be_edited()) { $reportlink = quiz_attempt_summary_link_to_reports($this->get_quiz(), $this->quizobj->get_cm(), $this->quizobj->get_context()); throw new \moodle_exception('cannoteditafterattempts', 'quiz', new \moodle_url('/mod/quiz/edit.php', array('cmid' => $this->get_cmid())), $reportlink); } }
php
public function check_can_be_edited() { if (!$this->can_be_edited()) { $reportlink = quiz_attempt_summary_link_to_reports($this->get_quiz(), $this->quizobj->get_cm(), $this->quizobj->get_context()); throw new \moodle_exception('cannoteditafterattempts', 'quiz', new \moodle_url('/mod/quiz/edit.php', array('cmid' => $this->get_cmid())), $reportlink); } }
[ "public", "function", "check_can_be_edited", "(", ")", "{", "if", "(", "!", "$", "this", "->", "can_be_edited", "(", ")", ")", "{", "$", "reportlink", "=", "quiz_attempt_summary_link_to_reports", "(", "$", "this", "->", "get_quiz", "(", ")", ",", "$", "this", "->", "quizobj", "->", "get_cm", "(", ")", ",", "$", "this", "->", "quizobj", "->", "get_context", "(", ")", ")", ";", "throw", "new", "\\", "moodle_exception", "(", "'cannoteditafterattempts'", ",", "'quiz'", ",", "new", "\\", "moodle_url", "(", "'/mod/quiz/edit.php'", ",", "array", "(", "'cmid'", "=>", "$", "this", "->", "get_cmid", "(", ")", ")", ")", ",", "$", "reportlink", ")", ";", "}", "}" ]
This quiz can only be edited if they have not been attempted. Throw an exception if this is not the case.
[ "This", "quiz", "can", "only", "be", "edited", "if", "they", "have", "not", "been", "attempted", ".", "Throw", "an", "exception", "if", "this", "is", "not", "the", "case", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/structure.php#L292-L299
217,177
moodle/moodle
mod/quiz/classes/structure.php
structure.is_first_slot_on_page
public function is_first_slot_on_page($slotnumber) { if ($slotnumber == 1) { return true; } return $this->slotsinorder[$slotnumber]->page != $this->slotsinorder[$slotnumber - 1]->page; }
php
public function is_first_slot_on_page($slotnumber) { if ($slotnumber == 1) { return true; } return $this->slotsinorder[$slotnumber]->page != $this->slotsinorder[$slotnumber - 1]->page; }
[ "public", "function", "is_first_slot_on_page", "(", "$", "slotnumber", ")", "{", "if", "(", "$", "slotnumber", "==", "1", ")", "{", "return", "true", ";", "}", "return", "$", "this", "->", "slotsinorder", "[", "$", "slotnumber", "]", "->", "page", "!=", "$", "this", "->", "slotsinorder", "[", "$", "slotnumber", "-", "1", "]", "->", "page", ";", "}" ]
Is this slot the first one on its page? @param int $slotnumber the index of the slot in question. @return bool whether this slot the first one on its page.
[ "Is", "this", "slot", "the", "first", "one", "on", "its", "page?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/structure.php#L325-L330
217,178
moodle/moodle
mod/quiz/classes/structure.php
structure.is_last_slot_on_page
public function is_last_slot_on_page($slotnumber) { if (!isset($this->slotsinorder[$slotnumber + 1])) { return true; } return $this->slotsinorder[$slotnumber]->page != $this->slotsinorder[$slotnumber + 1]->page; }
php
public function is_last_slot_on_page($slotnumber) { if (!isset($this->slotsinorder[$slotnumber + 1])) { return true; } return $this->slotsinorder[$slotnumber]->page != $this->slotsinorder[$slotnumber + 1]->page; }
[ "public", "function", "is_last_slot_on_page", "(", "$", "slotnumber", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "slotsinorder", "[", "$", "slotnumber", "+", "1", "]", ")", ")", "{", "return", "true", ";", "}", "return", "$", "this", "->", "slotsinorder", "[", "$", "slotnumber", "]", "->", "page", "!=", "$", "this", "->", "slotsinorder", "[", "$", "slotnumber", "+", "1", "]", "->", "page", ";", "}" ]
Is this slot the last one on its page? @param int $slotnumber the index of the slot in question. @return bool whether this slot the last one on its page.
[ "Is", "this", "slot", "the", "last", "one", "on", "its", "page?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/structure.php#L337-L342
217,179
moodle/moodle
mod/quiz/classes/structure.php
structure.is_only_slot_in_section
public function is_only_slot_in_section($slotnumber) { return $this->slotsinorder[$slotnumber]->section->firstslot == $this->slotsinorder[$slotnumber]->section->lastslot; }
php
public function is_only_slot_in_section($slotnumber) { return $this->slotsinorder[$slotnumber]->section->firstslot == $this->slotsinorder[$slotnumber]->section->lastslot; }
[ "public", "function", "is_only_slot_in_section", "(", "$", "slotnumber", ")", "{", "return", "$", "this", "->", "slotsinorder", "[", "$", "slotnumber", "]", "->", "section", "->", "firstslot", "==", "$", "this", "->", "slotsinorder", "[", "$", "slotnumber", "]", "->", "section", "->", "lastslot", ";", "}" ]
Is this slot the only one in its section? @param int $slotnumber the index of the slot in question. @return bool whether this slot the only one on its section.
[ "Is", "this", "slot", "the", "only", "one", "in", "its", "section?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/structure.php#L358-L361
217,180
moodle/moodle
mod/quiz/classes/structure.php
structure.get_slot_by_id
public function get_slot_by_id($slotid) { if (!array_key_exists($slotid, $this->slots)) { throw new \coding_exception('The \'slotid\' could not be found.'); } return $this->slots[$slotid]; }
php
public function get_slot_by_id($slotid) { if (!array_key_exists($slotid, $this->slots)) { throw new \coding_exception('The \'slotid\' could not be found.'); } return $this->slots[$slotid]; }
[ "public", "function", "get_slot_by_id", "(", "$", "slotid", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "slotid", ",", "$", "this", "->", "slots", ")", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'The \\'slotid\\' could not be found.'", ")", ";", "}", "return", "$", "this", "->", "slots", "[", "$", "slotid", "]", ";", "}" ]
Get a slot by it's id. Throws an exception if it is missing. @param int $slotid the slot id. @return \stdClass the requested quiz_slots row.
[ "Get", "a", "slot", "by", "it", "s", "id", ".", "Throws", "an", "exception", "if", "it", "is", "missing", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/structure.php#L413-L418
217,181
moodle/moodle
mod/quiz/classes/structure.php
structure.get_slot_by_number
public function get_slot_by_number($slotnumber) { foreach ($this->slots as $slot) { if ($slot->slot == $slotnumber) { return $slot; } } throw new \coding_exception('The \'slotnumber\' could not be found.'); }
php
public function get_slot_by_number($slotnumber) { foreach ($this->slots as $slot) { if ($slot->slot == $slotnumber) { return $slot; } } throw new \coding_exception('The \'slotnumber\' could not be found.'); }
[ "public", "function", "get_slot_by_number", "(", "$", "slotnumber", ")", "{", "foreach", "(", "$", "this", "->", "slots", "as", "$", "slot", ")", "{", "if", "(", "$", "slot", "->", "slot", "==", "$", "slotnumber", ")", "{", "return", "$", "slot", ";", "}", "}", "throw", "new", "\\", "coding_exception", "(", "'The \\'slotnumber\\' could not be found.'", ")", ";", "}" ]
Get a slot by it's slot number. Throws an exception if it is missing. @param int $slotnumber The slot number @return \stdClass @throws \coding_exception
[ "Get", "a", "slot", "by", "it", "s", "slot", "number", ".", "Throws", "an", "exception", "if", "it", "is", "missing", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/structure.php#L427-L435
217,182
moodle/moodle
mod/quiz/classes/structure.php
structure.can_add_section_heading
public function can_add_section_heading($pagenumber) { // There is a default section heading on this page, // do not show adding new section heading in the Add menu. if ($pagenumber == 1) { return false; } // Get an array of firstslots. $firstslots = array(); foreach ($this->sections as $section) { $firstslots[] = $section->firstslot; } foreach ($this->slotsinorder as $slot) { if ($slot->page == $pagenumber) { if (in_array($slot->slot, $firstslots)) { return false; } } } // Do not show the adding section heading on the last add menu. if ($pagenumber == 0) { return false; } return true; }
php
public function can_add_section_heading($pagenumber) { // There is a default section heading on this page, // do not show adding new section heading in the Add menu. if ($pagenumber == 1) { return false; } // Get an array of firstslots. $firstslots = array(); foreach ($this->sections as $section) { $firstslots[] = $section->firstslot; } foreach ($this->slotsinorder as $slot) { if ($slot->page == $pagenumber) { if (in_array($slot->slot, $firstslots)) { return false; } } } // Do not show the adding section heading on the last add menu. if ($pagenumber == 0) { return false; } return true; }
[ "public", "function", "can_add_section_heading", "(", "$", "pagenumber", ")", "{", "// There is a default section heading on this page,", "// do not show adding new section heading in the Add menu.", "if", "(", "$", "pagenumber", "==", "1", ")", "{", "return", "false", ";", "}", "// Get an array of firstslots.", "$", "firstslots", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "sections", "as", "$", "section", ")", "{", "$", "firstslots", "[", "]", "=", "$", "section", "->", "firstslot", ";", "}", "foreach", "(", "$", "this", "->", "slotsinorder", "as", "$", "slot", ")", "{", "if", "(", "$", "slot", "->", "page", "==", "$", "pagenumber", ")", "{", "if", "(", "in_array", "(", "$", "slot", "->", "slot", ",", "$", "firstslots", ")", ")", "{", "return", "false", ";", "}", "}", "}", "// Do not show the adding section heading on the last add menu.", "if", "(", "$", "pagenumber", "==", "0", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Check whether adding a section heading is possible @param int $pagenumber the number of the page. @return boolean
[ "Check", "whether", "adding", "a", "section", "heading", "is", "possible" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/structure.php#L442-L465
217,183
moodle/moodle
mod/quiz/classes/structure.php
structure.get_slots_in_section
public function get_slots_in_section($sectionid) { $slots = array(); foreach ($this->slotsinorder as $slot) { if ($slot->section->id == $sectionid) { $slots[] = $slot->slot; } } return $slots; }
php
public function get_slots_in_section($sectionid) { $slots = array(); foreach ($this->slotsinorder as $slot) { if ($slot->section->id == $sectionid) { $slots[] = $slot->slot; } } return $slots; }
[ "public", "function", "get_slots_in_section", "(", "$", "sectionid", ")", "{", "$", "slots", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "slotsinorder", "as", "$", "slot", ")", "{", "if", "(", "$", "slot", "->", "section", "->", "id", "==", "$", "sectionid", ")", "{", "$", "slots", "[", "]", "=", "$", "slot", "->", "slot", ";", "}", "}", "return", "$", "slots", ";", "}" ]
Get all the slots in a section of the quiz. @param int $sectionid the section id. @return int[] slot numbers.
[ "Get", "all", "the", "slots", "in", "a", "section", "of", "the", "quiz", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/structure.php#L472-L480
217,184
moodle/moodle
mod/quiz/classes/structure.php
structure.get_edit_page_warnings
public function get_edit_page_warnings() { $warnings = array(); if (quiz_has_attempts($this->quizobj->get_quizid())) { $reviewlink = quiz_attempt_summary_link_to_reports($this->quizobj->get_quiz(), $this->quizobj->get_cm(), $this->quizobj->get_context()); $warnings[] = get_string('cannoteditafterattempts', 'quiz', $reviewlink); } return $warnings; }
php
public function get_edit_page_warnings() { $warnings = array(); if (quiz_has_attempts($this->quizobj->get_quizid())) { $reviewlink = quiz_attempt_summary_link_to_reports($this->quizobj->get_quiz(), $this->quizobj->get_cm(), $this->quizobj->get_context()); $warnings[] = get_string('cannoteditafterattempts', 'quiz', $reviewlink); } return $warnings; }
[ "public", "function", "get_edit_page_warnings", "(", ")", "{", "$", "warnings", "=", "array", "(", ")", ";", "if", "(", "quiz_has_attempts", "(", "$", "this", "->", "quizobj", "->", "get_quizid", "(", ")", ")", ")", "{", "$", "reviewlink", "=", "quiz_attempt_summary_link_to_reports", "(", "$", "this", "->", "quizobj", "->", "get_quiz", "(", ")", ",", "$", "this", "->", "quizobj", "->", "get_cm", "(", ")", ",", "$", "this", "->", "quizobj", "->", "get_context", "(", ")", ")", ";", "$", "warnings", "[", "]", "=", "get_string", "(", "'cannoteditafterattempts'", ",", "'quiz'", ",", "$", "reviewlink", ")", ";", "}", "return", "$", "warnings", ";", "}" ]
Get any warnings to show at the top of the edit page. @return string[] array of strings.
[ "Get", "any", "warnings", "to", "show", "at", "the", "top", "of", "the", "edit", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/structure.php#L543-L553
217,185
moodle/moodle
mod/quiz/classes/structure.php
structure.get_dates_summary
public function get_dates_summary() { $timenow = time(); $quiz = $this->quizobj->get_quiz(); // Exact open and close dates for the tool-tip. $dates = array(); if ($quiz->timeopen > 0) { if ($timenow > $quiz->timeopen) { $dates[] = get_string('quizopenedon', 'quiz', userdate($quiz->timeopen)); } else { $dates[] = get_string('quizwillopen', 'quiz', userdate($quiz->timeopen)); } } if ($quiz->timeclose > 0) { if ($timenow > $quiz->timeclose) { $dates[] = get_string('quizclosed', 'quiz', userdate($quiz->timeclose)); } else { $dates[] = get_string('quizcloseson', 'quiz', userdate($quiz->timeclose)); } } if (empty($dates)) { $dates[] = get_string('alwaysavailable', 'quiz'); } $explanation = implode(', ', $dates); // Brief summary on the page. if ($timenow < $quiz->timeopen) { $currentstatus = get_string('quizisclosedwillopen', 'quiz', userdate($quiz->timeopen, get_string('strftimedatetimeshort', 'langconfig'))); } else if ($quiz->timeclose && $timenow <= $quiz->timeclose) { $currentstatus = get_string('quizisopenwillclose', 'quiz', userdate($quiz->timeclose, get_string('strftimedatetimeshort', 'langconfig'))); } else if ($quiz->timeclose && $timenow > $quiz->timeclose) { $currentstatus = get_string('quizisclosed', 'quiz'); } else { $currentstatus = get_string('quizisopen', 'quiz'); } return array($currentstatus, $explanation); }
php
public function get_dates_summary() { $timenow = time(); $quiz = $this->quizobj->get_quiz(); // Exact open and close dates for the tool-tip. $dates = array(); if ($quiz->timeopen > 0) { if ($timenow > $quiz->timeopen) { $dates[] = get_string('quizopenedon', 'quiz', userdate($quiz->timeopen)); } else { $dates[] = get_string('quizwillopen', 'quiz', userdate($quiz->timeopen)); } } if ($quiz->timeclose > 0) { if ($timenow > $quiz->timeclose) { $dates[] = get_string('quizclosed', 'quiz', userdate($quiz->timeclose)); } else { $dates[] = get_string('quizcloseson', 'quiz', userdate($quiz->timeclose)); } } if (empty($dates)) { $dates[] = get_string('alwaysavailable', 'quiz'); } $explanation = implode(', ', $dates); // Brief summary on the page. if ($timenow < $quiz->timeopen) { $currentstatus = get_string('quizisclosedwillopen', 'quiz', userdate($quiz->timeopen, get_string('strftimedatetimeshort', 'langconfig'))); } else if ($quiz->timeclose && $timenow <= $quiz->timeclose) { $currentstatus = get_string('quizisopenwillclose', 'quiz', userdate($quiz->timeclose, get_string('strftimedatetimeshort', 'langconfig'))); } else if ($quiz->timeclose && $timenow > $quiz->timeclose) { $currentstatus = get_string('quizisclosed', 'quiz'); } else { $currentstatus = get_string('quizisopen', 'quiz'); } return array($currentstatus, $explanation); }
[ "public", "function", "get_dates_summary", "(", ")", "{", "$", "timenow", "=", "time", "(", ")", ";", "$", "quiz", "=", "$", "this", "->", "quizobj", "->", "get_quiz", "(", ")", ";", "// Exact open and close dates for the tool-tip.", "$", "dates", "=", "array", "(", ")", ";", "if", "(", "$", "quiz", "->", "timeopen", ">", "0", ")", "{", "if", "(", "$", "timenow", ">", "$", "quiz", "->", "timeopen", ")", "{", "$", "dates", "[", "]", "=", "get_string", "(", "'quizopenedon'", ",", "'quiz'", ",", "userdate", "(", "$", "quiz", "->", "timeopen", ")", ")", ";", "}", "else", "{", "$", "dates", "[", "]", "=", "get_string", "(", "'quizwillopen'", ",", "'quiz'", ",", "userdate", "(", "$", "quiz", "->", "timeopen", ")", ")", ";", "}", "}", "if", "(", "$", "quiz", "->", "timeclose", ">", "0", ")", "{", "if", "(", "$", "timenow", ">", "$", "quiz", "->", "timeclose", ")", "{", "$", "dates", "[", "]", "=", "get_string", "(", "'quizclosed'", ",", "'quiz'", ",", "userdate", "(", "$", "quiz", "->", "timeclose", ")", ")", ";", "}", "else", "{", "$", "dates", "[", "]", "=", "get_string", "(", "'quizcloseson'", ",", "'quiz'", ",", "userdate", "(", "$", "quiz", "->", "timeclose", ")", ")", ";", "}", "}", "if", "(", "empty", "(", "$", "dates", ")", ")", "{", "$", "dates", "[", "]", "=", "get_string", "(", "'alwaysavailable'", ",", "'quiz'", ")", ";", "}", "$", "explanation", "=", "implode", "(", "', '", ",", "$", "dates", ")", ";", "// Brief summary on the page.", "if", "(", "$", "timenow", "<", "$", "quiz", "->", "timeopen", ")", "{", "$", "currentstatus", "=", "get_string", "(", "'quizisclosedwillopen'", ",", "'quiz'", ",", "userdate", "(", "$", "quiz", "->", "timeopen", ",", "get_string", "(", "'strftimedatetimeshort'", ",", "'langconfig'", ")", ")", ")", ";", "}", "else", "if", "(", "$", "quiz", "->", "timeclose", "&&", "$", "timenow", "<=", "$", "quiz", "->", "timeclose", ")", "{", "$", "currentstatus", "=", "get_string", "(", "'quizisopenwillclose'", ",", "'quiz'", ",", "userdate", "(", "$", "quiz", "->", "timeclose", ",", "get_string", "(", "'strftimedatetimeshort'", ",", "'langconfig'", ")", ")", ")", ";", "}", "else", "if", "(", "$", "quiz", "->", "timeclose", "&&", "$", "timenow", ">", "$", "quiz", "->", "timeclose", ")", "{", "$", "currentstatus", "=", "get_string", "(", "'quizisclosed'", ",", "'quiz'", ")", ";", "}", "else", "{", "$", "currentstatus", "=", "get_string", "(", "'quizisopen'", ",", "'quiz'", ")", ";", "}", "return", "array", "(", "$", "currentstatus", ",", "$", "explanation", ")", ";", "}" ]
Get the date information about the current state of the quiz. @return string[] array of two strings. First a short summary, then a longer explanation of the current state, e.g. for a tool-tip.
[ "Get", "the", "date", "information", "about", "the", "current", "state", "of", "the", "quiz", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/structure.php#L560-L599
217,186
moodle/moodle
mod/quiz/classes/structure.php
structure.populate_structure
public function populate_structure($quiz) { global $DB; $slots = $DB->get_records_sql(" SELECT slot.id AS slotid, slot.slot, slot.questionid, slot.page, slot.maxmark, slot.requireprevious, q.*, qc.contextid FROM {quiz_slots} slot LEFT JOIN {question} q ON q.id = slot.questionid LEFT JOIN {question_categories} qc ON qc.id = q.category WHERE slot.quizid = ? ORDER BY slot.slot", array($quiz->id)); $slots = $this->populate_missing_questions($slots); $this->questions = array(); $this->slots = array(); $this->slotsinorder = array(); foreach ($slots as $slotdata) { $this->questions[$slotdata->questionid] = $slotdata; $slot = new \stdClass(); $slot->id = $slotdata->slotid; $slot->slot = $slotdata->slot; $slot->quizid = $quiz->id; $slot->page = $slotdata->page; $slot->questionid = $slotdata->questionid; $slot->maxmark = $slotdata->maxmark; $slot->requireprevious = $slotdata->requireprevious; $this->slots[$slot->id] = $slot; $this->slotsinorder[$slot->slot] = $slot; } // Get quiz sections in ascending order of the firstslot. $this->sections = $DB->get_records('quiz_sections', array('quizid' => $quiz->id), 'firstslot ASC'); $this->populate_slots_with_sections(); $this->populate_question_numbers(); }
php
public function populate_structure($quiz) { global $DB; $slots = $DB->get_records_sql(" SELECT slot.id AS slotid, slot.slot, slot.questionid, slot.page, slot.maxmark, slot.requireprevious, q.*, qc.contextid FROM {quiz_slots} slot LEFT JOIN {question} q ON q.id = slot.questionid LEFT JOIN {question_categories} qc ON qc.id = q.category WHERE slot.quizid = ? ORDER BY slot.slot", array($quiz->id)); $slots = $this->populate_missing_questions($slots); $this->questions = array(); $this->slots = array(); $this->slotsinorder = array(); foreach ($slots as $slotdata) { $this->questions[$slotdata->questionid] = $slotdata; $slot = new \stdClass(); $slot->id = $slotdata->slotid; $slot->slot = $slotdata->slot; $slot->quizid = $quiz->id; $slot->page = $slotdata->page; $slot->questionid = $slotdata->questionid; $slot->maxmark = $slotdata->maxmark; $slot->requireprevious = $slotdata->requireprevious; $this->slots[$slot->id] = $slot; $this->slotsinorder[$slot->slot] = $slot; } // Get quiz sections in ascending order of the firstslot. $this->sections = $DB->get_records('quiz_sections', array('quizid' => $quiz->id), 'firstslot ASC'); $this->populate_slots_with_sections(); $this->populate_question_numbers(); }
[ "public", "function", "populate_structure", "(", "$", "quiz", ")", "{", "global", "$", "DB", ";", "$", "slots", "=", "$", "DB", "->", "get_records_sql", "(", "\"\n SELECT slot.id AS slotid, slot.slot, slot.questionid, slot.page, slot.maxmark,\n slot.requireprevious, q.*, qc.contextid\n FROM {quiz_slots} slot\n LEFT JOIN {question} q ON q.id = slot.questionid\n LEFT JOIN {question_categories} qc ON qc.id = q.category\n WHERE slot.quizid = ?\n ORDER BY slot.slot\"", ",", "array", "(", "$", "quiz", "->", "id", ")", ")", ";", "$", "slots", "=", "$", "this", "->", "populate_missing_questions", "(", "$", "slots", ")", ";", "$", "this", "->", "questions", "=", "array", "(", ")", ";", "$", "this", "->", "slots", "=", "array", "(", ")", ";", "$", "this", "->", "slotsinorder", "=", "array", "(", ")", ";", "foreach", "(", "$", "slots", "as", "$", "slotdata", ")", "{", "$", "this", "->", "questions", "[", "$", "slotdata", "->", "questionid", "]", "=", "$", "slotdata", ";", "$", "slot", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "slot", "->", "id", "=", "$", "slotdata", "->", "slotid", ";", "$", "slot", "->", "slot", "=", "$", "slotdata", "->", "slot", ";", "$", "slot", "->", "quizid", "=", "$", "quiz", "->", "id", ";", "$", "slot", "->", "page", "=", "$", "slotdata", "->", "page", ";", "$", "slot", "->", "questionid", "=", "$", "slotdata", "->", "questionid", ";", "$", "slot", "->", "maxmark", "=", "$", "slotdata", "->", "maxmark", ";", "$", "slot", "->", "requireprevious", "=", "$", "slotdata", "->", "requireprevious", ";", "$", "this", "->", "slots", "[", "$", "slot", "->", "id", "]", "=", "$", "slot", ";", "$", "this", "->", "slotsinorder", "[", "$", "slot", "->", "slot", "]", "=", "$", "slot", ";", "}", "// Get quiz sections in ascending order of the firstslot.", "$", "this", "->", "sections", "=", "$", "DB", "->", "get_records", "(", "'quiz_sections'", ",", "array", "(", "'quizid'", "=>", "$", "quiz", "->", "id", ")", ",", "'firstslot ASC'", ")", ";", "$", "this", "->", "populate_slots_with_sections", "(", ")", ";", "$", "this", "->", "populate_question_numbers", "(", ")", ";", "}" ]
Set up this class with the structure for a given quiz. @param \stdClass $quiz the quiz settings.
[ "Set", "up", "this", "class", "with", "the", "structure", "for", "a", "given", "quiz", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/structure.php#L605-L642
217,187
moodle/moodle
mod/quiz/classes/structure.php
structure.populate_missing_questions
protected function populate_missing_questions($slots) { // Address missing question types. foreach ($slots as $slot) { if ($slot->qtype === null) { // If the questiontype is missing change the question type. $slot->id = $slot->questionid; $slot->category = 0; $slot->qtype = 'missingtype'; $slot->name = get_string('missingquestion', 'quiz'); $slot->slot = $slot->slot; $slot->maxmark = 0; $slot->requireprevious = 0; $slot->questiontext = ' '; $slot->questiontextformat = FORMAT_HTML; $slot->length = 1; } else if (!\question_bank::qtype_exists($slot->qtype)) { $slot->qtype = 'missingtype'; } } return $slots; }
php
protected function populate_missing_questions($slots) { // Address missing question types. foreach ($slots as $slot) { if ($slot->qtype === null) { // If the questiontype is missing change the question type. $slot->id = $slot->questionid; $slot->category = 0; $slot->qtype = 'missingtype'; $slot->name = get_string('missingquestion', 'quiz'); $slot->slot = $slot->slot; $slot->maxmark = 0; $slot->requireprevious = 0; $slot->questiontext = ' '; $slot->questiontextformat = FORMAT_HTML; $slot->length = 1; } else if (!\question_bank::qtype_exists($slot->qtype)) { $slot->qtype = 'missingtype'; } } return $slots; }
[ "protected", "function", "populate_missing_questions", "(", "$", "slots", ")", "{", "// Address missing question types.", "foreach", "(", "$", "slots", "as", "$", "slot", ")", "{", "if", "(", "$", "slot", "->", "qtype", "===", "null", ")", "{", "// If the questiontype is missing change the question type.", "$", "slot", "->", "id", "=", "$", "slot", "->", "questionid", ";", "$", "slot", "->", "category", "=", "0", ";", "$", "slot", "->", "qtype", "=", "'missingtype'", ";", "$", "slot", "->", "name", "=", "get_string", "(", "'missingquestion'", ",", "'quiz'", ")", ";", "$", "slot", "->", "slot", "=", "$", "slot", "->", "slot", ";", "$", "slot", "->", "maxmark", "=", "0", ";", "$", "slot", "->", "requireprevious", "=", "0", ";", "$", "slot", "->", "questiontext", "=", "' '", ";", "$", "slot", "->", "questiontextformat", "=", "FORMAT_HTML", ";", "$", "slot", "->", "length", "=", "1", ";", "}", "else", "if", "(", "!", "\\", "question_bank", "::", "qtype_exists", "(", "$", "slot", "->", "qtype", ")", ")", "{", "$", "slot", "->", "qtype", "=", "'missingtype'", ";", "}", "}", "return", "$", "slots", ";", "}" ]
Used by populate. Make up fake data for any missing questions. @param \stdClass[] $slots the data about the slots and questions in the quiz. @return \stdClass[] updated $slots array.
[ "Used", "by", "populate", ".", "Make", "up", "fake", "data", "for", "any", "missing", "questions", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/structure.php#L649-L671
217,188
moodle/moodle
mod/quiz/classes/structure.php
structure.populate_slots_with_sections
public function populate_slots_with_sections() { $sections = array_values($this->sections); foreach ($sections as $i => $section) { if (isset($sections[$i + 1])) { $section->lastslot = $sections[$i + 1]->firstslot - 1; } else { $section->lastslot = count($this->slotsinorder); } for ($slot = $section->firstslot; $slot <= $section->lastslot; $slot += 1) { $this->slotsinorder[$slot]->section = $section; } } }
php
public function populate_slots_with_sections() { $sections = array_values($this->sections); foreach ($sections as $i => $section) { if (isset($sections[$i + 1])) { $section->lastslot = $sections[$i + 1]->firstslot - 1; } else { $section->lastslot = count($this->slotsinorder); } for ($slot = $section->firstslot; $slot <= $section->lastslot; $slot += 1) { $this->slotsinorder[$slot]->section = $section; } } }
[ "public", "function", "populate_slots_with_sections", "(", ")", "{", "$", "sections", "=", "array_values", "(", "$", "this", "->", "sections", ")", ";", "foreach", "(", "$", "sections", "as", "$", "i", "=>", "$", "section", ")", "{", "if", "(", "isset", "(", "$", "sections", "[", "$", "i", "+", "1", "]", ")", ")", "{", "$", "section", "->", "lastslot", "=", "$", "sections", "[", "$", "i", "+", "1", "]", "->", "firstslot", "-", "1", ";", "}", "else", "{", "$", "section", "->", "lastslot", "=", "count", "(", "$", "this", "->", "slotsinorder", ")", ";", "}", "for", "(", "$", "slot", "=", "$", "section", "->", "firstslot", ";", "$", "slot", "<=", "$", "section", "->", "lastslot", ";", "$", "slot", "+=", "1", ")", "{", "$", "this", "->", "slotsinorder", "[", "$", "slot", "]", "->", "section", "=", "$", "section", ";", "}", "}", "}" ]
Fill in the section ids for each slot.
[ "Fill", "in", "the", "section", "ids", "for", "each", "slot", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/structure.php#L676-L688
217,189
moodle/moodle
mod/quiz/classes/structure.php
structure.populate_question_numbers
protected function populate_question_numbers() { $number = 1; foreach ($this->slots as $slot) { if ($this->questions[$slot->questionid]->length == 0) { $slot->displayednumber = get_string('infoshort', 'quiz'); } else { $slot->displayednumber = $number; $number += 1; } } }
php
protected function populate_question_numbers() { $number = 1; foreach ($this->slots as $slot) { if ($this->questions[$slot->questionid]->length == 0) { $slot->displayednumber = get_string('infoshort', 'quiz'); } else { $slot->displayednumber = $number; $number += 1; } } }
[ "protected", "function", "populate_question_numbers", "(", ")", "{", "$", "number", "=", "1", ";", "foreach", "(", "$", "this", "->", "slots", "as", "$", "slot", ")", "{", "if", "(", "$", "this", "->", "questions", "[", "$", "slot", "->", "questionid", "]", "->", "length", "==", "0", ")", "{", "$", "slot", "->", "displayednumber", "=", "get_string", "(", "'infoshort'", ",", "'quiz'", ")", ";", "}", "else", "{", "$", "slot", "->", "displayednumber", "=", "$", "number", ";", "$", "number", "+=", "1", ";", "}", "}", "}" ]
Number the questions.
[ "Number", "the", "questions", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/structure.php#L693-L703
217,190
moodle/moodle
mod/quiz/classes/structure.php
structure.refresh_page_numbers
public function refresh_page_numbers($slots = array()) { global $DB; // Get slots ordered by page then slot. if (!count($slots)) { $slots = $DB->get_records('quiz_slots', array('quizid' => $this->get_quizid()), 'slot, page'); } // Loop slots. Start Page number at 1 and increment as required. $pagenumbers = array('new' => 0, 'old' => 0); foreach ($slots as $slot) { if ($slot->page !== $pagenumbers['old']) { $pagenumbers['old'] = $slot->page; ++$pagenumbers['new']; } if ($pagenumbers['new'] == $slot->page) { continue; } $slot->page = $pagenumbers['new']; } return $slots; }
php
public function refresh_page_numbers($slots = array()) { global $DB; // Get slots ordered by page then slot. if (!count($slots)) { $slots = $DB->get_records('quiz_slots', array('quizid' => $this->get_quizid()), 'slot, page'); } // Loop slots. Start Page number at 1 and increment as required. $pagenumbers = array('new' => 0, 'old' => 0); foreach ($slots as $slot) { if ($slot->page !== $pagenumbers['old']) { $pagenumbers['old'] = $slot->page; ++$pagenumbers['new']; } if ($pagenumbers['new'] == $slot->page) { continue; } $slot->page = $pagenumbers['new']; } return $slots; }
[ "public", "function", "refresh_page_numbers", "(", "$", "slots", "=", "array", "(", ")", ")", "{", "global", "$", "DB", ";", "// Get slots ordered by page then slot.", "if", "(", "!", "count", "(", "$", "slots", ")", ")", "{", "$", "slots", "=", "$", "DB", "->", "get_records", "(", "'quiz_slots'", ",", "array", "(", "'quizid'", "=>", "$", "this", "->", "get_quizid", "(", ")", ")", ",", "'slot, page'", ")", ";", "}", "// Loop slots. Start Page number at 1 and increment as required.", "$", "pagenumbers", "=", "array", "(", "'new'", "=>", "0", ",", "'old'", "=>", "0", ")", ";", "foreach", "(", "$", "slots", "as", "$", "slot", ")", "{", "if", "(", "$", "slot", "->", "page", "!==", "$", "pagenumbers", "[", "'old'", "]", ")", "{", "$", "pagenumbers", "[", "'old'", "]", "=", "$", "slot", "->", "page", ";", "++", "$", "pagenumbers", "[", "'new'", "]", ";", "}", "if", "(", "$", "pagenumbers", "[", "'new'", "]", "==", "$", "slot", "->", "page", ")", "{", "continue", ";", "}", "$", "slot", "->", "page", "=", "$", "pagenumbers", "[", "'new'", "]", ";", "}", "return", "$", "slots", ";", "}" ]
Refresh page numbering of quiz slots. @param \stdClass[] $slots (optional) array of slot objects. @return \stdClass[] array of slot objects.
[ "Refresh", "page", "numbering", "of", "quiz", "slots", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/structure.php#L860-L883
217,191
moodle/moodle
mod/quiz/classes/structure.php
structure.refresh_page_numbers_and_update_db
public function refresh_page_numbers_and_update_db() { global $DB; $this->check_can_be_edited(); $slots = $this->refresh_page_numbers(); // Record new page order. foreach ($slots as $slot) { $DB->set_field('quiz_slots', 'page', $slot->page, array('id' => $slot->id)); } return $slots; }
php
public function refresh_page_numbers_and_update_db() { global $DB; $this->check_can_be_edited(); $slots = $this->refresh_page_numbers(); // Record new page order. foreach ($slots as $slot) { $DB->set_field('quiz_slots', 'page', $slot->page, array('id' => $slot->id)); } return $slots; }
[ "public", "function", "refresh_page_numbers_and_update_db", "(", ")", "{", "global", "$", "DB", ";", "$", "this", "->", "check_can_be_edited", "(", ")", ";", "$", "slots", "=", "$", "this", "->", "refresh_page_numbers", "(", ")", ";", "// Record new page order.", "foreach", "(", "$", "slots", "as", "$", "slot", ")", "{", "$", "DB", "->", "set_field", "(", "'quiz_slots'", ",", "'page'", ",", "$", "slot", "->", "page", ",", "array", "(", "'id'", "=>", "$", "slot", "->", "id", ")", ")", ";", "}", "return", "$", "slots", ";", "}" ]
Refresh page numbering of quiz slots and save to the database. @param \stdClass $quiz the quiz object. @return \stdClass[] array of slot objects.
[ "Refresh", "page", "numbering", "of", "quiz", "slots", "and", "save", "to", "the", "database", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/structure.php#L890-L903
217,192
moodle/moodle
mod/quiz/classes/structure.php
structure.remove_slot
public function remove_slot($slotnumber) { global $DB; $this->check_can_be_edited(); if ($this->is_only_slot_in_section($slotnumber) && $this->get_section_count() > 1) { throw new \coding_exception('You cannot remove the last slot in a section.'); } $slot = $DB->get_record('quiz_slots', array('quizid' => $this->get_quizid(), 'slot' => $slotnumber)); if (!$slot) { return; } $maxslot = $DB->get_field_sql('SELECT MAX(slot) FROM {quiz_slots} WHERE quizid = ?', array($this->get_quizid())); $trans = $DB->start_delegated_transaction(); $DB->delete_records('quiz_slot_tags', array('slotid' => $slot->id)); $DB->delete_records('quiz_slots', array('id' => $slot->id)); for ($i = $slot->slot + 1; $i <= $maxslot; $i++) { $DB->set_field('quiz_slots', 'slot', $i - 1, array('quizid' => $this->get_quizid(), 'slot' => $i)); } $qtype = $DB->get_field('question', 'qtype', array('id' => $slot->questionid)); if ($qtype === 'random') { // This function automatically checks if the question is in use, and won't delete if it is. question_delete_question($slot->questionid); } quiz_update_section_firstslots($this->get_quizid(), -1, $slotnumber); unset($this->questions[$slot->questionid]); $this->refresh_page_numbers_and_update_db(); $trans->allow_commit(); }
php
public function remove_slot($slotnumber) { global $DB; $this->check_can_be_edited(); if ($this->is_only_slot_in_section($slotnumber) && $this->get_section_count() > 1) { throw new \coding_exception('You cannot remove the last slot in a section.'); } $slot = $DB->get_record('quiz_slots', array('quizid' => $this->get_quizid(), 'slot' => $slotnumber)); if (!$slot) { return; } $maxslot = $DB->get_field_sql('SELECT MAX(slot) FROM {quiz_slots} WHERE quizid = ?', array($this->get_quizid())); $trans = $DB->start_delegated_transaction(); $DB->delete_records('quiz_slot_tags', array('slotid' => $slot->id)); $DB->delete_records('quiz_slots', array('id' => $slot->id)); for ($i = $slot->slot + 1; $i <= $maxslot; $i++) { $DB->set_field('quiz_slots', 'slot', $i - 1, array('quizid' => $this->get_quizid(), 'slot' => $i)); } $qtype = $DB->get_field('question', 'qtype', array('id' => $slot->questionid)); if ($qtype === 'random') { // This function automatically checks if the question is in use, and won't delete if it is. question_delete_question($slot->questionid); } quiz_update_section_firstslots($this->get_quizid(), -1, $slotnumber); unset($this->questions[$slot->questionid]); $this->refresh_page_numbers_and_update_db(); $trans->allow_commit(); }
[ "public", "function", "remove_slot", "(", "$", "slotnumber", ")", "{", "global", "$", "DB", ";", "$", "this", "->", "check_can_be_edited", "(", ")", ";", "if", "(", "$", "this", "->", "is_only_slot_in_section", "(", "$", "slotnumber", ")", "&&", "$", "this", "->", "get_section_count", "(", ")", ">", "1", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'You cannot remove the last slot in a section.'", ")", ";", "}", "$", "slot", "=", "$", "DB", "->", "get_record", "(", "'quiz_slots'", ",", "array", "(", "'quizid'", "=>", "$", "this", "->", "get_quizid", "(", ")", ",", "'slot'", "=>", "$", "slotnumber", ")", ")", ";", "if", "(", "!", "$", "slot", ")", "{", "return", ";", "}", "$", "maxslot", "=", "$", "DB", "->", "get_field_sql", "(", "'SELECT MAX(slot) FROM {quiz_slots} WHERE quizid = ?'", ",", "array", "(", "$", "this", "->", "get_quizid", "(", ")", ")", ")", ";", "$", "trans", "=", "$", "DB", "->", "start_delegated_transaction", "(", ")", ";", "$", "DB", "->", "delete_records", "(", "'quiz_slot_tags'", ",", "array", "(", "'slotid'", "=>", "$", "slot", "->", "id", ")", ")", ";", "$", "DB", "->", "delete_records", "(", "'quiz_slots'", ",", "array", "(", "'id'", "=>", "$", "slot", "->", "id", ")", ")", ";", "for", "(", "$", "i", "=", "$", "slot", "->", "slot", "+", "1", ";", "$", "i", "<=", "$", "maxslot", ";", "$", "i", "++", ")", "{", "$", "DB", "->", "set_field", "(", "'quiz_slots'", ",", "'slot'", ",", "$", "i", "-", "1", ",", "array", "(", "'quizid'", "=>", "$", "this", "->", "get_quizid", "(", ")", ",", "'slot'", "=>", "$", "i", ")", ")", ";", "}", "$", "qtype", "=", "$", "DB", "->", "get_field", "(", "'question'", ",", "'qtype'", ",", "array", "(", "'id'", "=>", "$", "slot", "->", "questionid", ")", ")", ";", "if", "(", "$", "qtype", "===", "'random'", ")", "{", "// This function automatically checks if the question is in use, and won't delete if it is.", "question_delete_question", "(", "$", "slot", "->", "questionid", ")", ";", "}", "quiz_update_section_firstslots", "(", "$", "this", "->", "get_quizid", "(", ")", ",", "-", "1", ",", "$", "slotnumber", ")", ";", "unset", "(", "$", "this", "->", "questions", "[", "$", "slot", "->", "questionid", "]", ")", ";", "$", "this", "->", "refresh_page_numbers_and_update_db", "(", ")", ";", "$", "trans", "->", "allow_commit", "(", ")", ";", "}" ]
Remove a slot from a quiz @param int $slotnumber The number of the slot to be deleted.
[ "Remove", "a", "slot", "from", "a", "quiz" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/structure.php#L909-L944
217,193
moodle/moodle
mod/quiz/classes/structure.php
structure.update_slot_maxmark
public function update_slot_maxmark($slot, $maxmark) { global $DB; if (abs($maxmark - $slot->maxmark) < 1e-7) { // Grade has not changed. Nothing to do. return false; } $trans = $DB->start_delegated_transaction(); $slot->maxmark = $maxmark; $DB->update_record('quiz_slots', $slot); \question_engine::set_max_mark_in_attempts(new \qubaids_for_quiz($slot->quizid), $slot->slot, $maxmark); $trans->allow_commit(); return true; }
php
public function update_slot_maxmark($slot, $maxmark) { global $DB; if (abs($maxmark - $slot->maxmark) < 1e-7) { // Grade has not changed. Nothing to do. return false; } $trans = $DB->start_delegated_transaction(); $slot->maxmark = $maxmark; $DB->update_record('quiz_slots', $slot); \question_engine::set_max_mark_in_attempts(new \qubaids_for_quiz($slot->quizid), $slot->slot, $maxmark); $trans->allow_commit(); return true; }
[ "public", "function", "update_slot_maxmark", "(", "$", "slot", ",", "$", "maxmark", ")", "{", "global", "$", "DB", ";", "if", "(", "abs", "(", "$", "maxmark", "-", "$", "slot", "->", "maxmark", ")", "<", "1e-7", ")", "{", "// Grade has not changed. Nothing to do.", "return", "false", ";", "}", "$", "trans", "=", "$", "DB", "->", "start_delegated_transaction", "(", ")", ";", "$", "slot", "->", "maxmark", "=", "$", "maxmark", ";", "$", "DB", "->", "update_record", "(", "'quiz_slots'", ",", "$", "slot", ")", ";", "\\", "question_engine", "::", "set_max_mark_in_attempts", "(", "new", "\\", "qubaids_for_quiz", "(", "$", "slot", "->", "quizid", ")", ",", "$", "slot", "->", "slot", ",", "$", "maxmark", ")", ";", "$", "trans", "->", "allow_commit", "(", ")", ";", "return", "true", ";", "}" ]
Change the max mark for a slot. Saves changes to the question grades in the quiz_slots table and any corresponding question_attempts. It does not update 'sumgrades' in the quiz table. @param \stdClass $slot row from the quiz_slots table. @param float $maxmark the new maxmark. @return bool true if the new grade is different from the old one.
[ "Change", "the", "max", "mark", "for", "a", "slot", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/structure.php#L957-L973
217,194
moodle/moodle
mod/quiz/classes/structure.php
structure.add_section_heading
public function add_section_heading($pagenumber, $heading = null) { global $DB; $section = new \stdClass(); if ($heading !== null) { $section->heading = $heading; } else { $section->heading = get_string('newsectionheading', 'quiz'); } $section->quizid = $this->get_quizid(); $slotsonpage = $DB->get_records('quiz_slots', array('quizid' => $this->get_quizid(), 'page' => $pagenumber), 'slot DESC'); $section->firstslot = end($slotsonpage)->slot; $section->shufflequestions = 0; return $DB->insert_record('quiz_sections', $section); }
php
public function add_section_heading($pagenumber, $heading = null) { global $DB; $section = new \stdClass(); if ($heading !== null) { $section->heading = $heading; } else { $section->heading = get_string('newsectionheading', 'quiz'); } $section->quizid = $this->get_quizid(); $slotsonpage = $DB->get_records('quiz_slots', array('quizid' => $this->get_quizid(), 'page' => $pagenumber), 'slot DESC'); $section->firstslot = end($slotsonpage)->slot; $section->shufflequestions = 0; return $DB->insert_record('quiz_sections', $section); }
[ "public", "function", "add_section_heading", "(", "$", "pagenumber", ",", "$", "heading", "=", "null", ")", "{", "global", "$", "DB", ";", "$", "section", "=", "new", "\\", "stdClass", "(", ")", ";", "if", "(", "$", "heading", "!==", "null", ")", "{", "$", "section", "->", "heading", "=", "$", "heading", ";", "}", "else", "{", "$", "section", "->", "heading", "=", "get_string", "(", "'newsectionheading'", ",", "'quiz'", ")", ";", "}", "$", "section", "->", "quizid", "=", "$", "this", "->", "get_quizid", "(", ")", ";", "$", "slotsonpage", "=", "$", "DB", "->", "get_records", "(", "'quiz_slots'", ",", "array", "(", "'quizid'", "=>", "$", "this", "->", "get_quizid", "(", ")", ",", "'page'", "=>", "$", "pagenumber", ")", ",", "'slot DESC'", ")", ";", "$", "section", "->", "firstslot", "=", "end", "(", "$", "slotsonpage", ")", "->", "slot", ";", "$", "section", "->", "shufflequestions", "=", "0", ";", "return", "$", "DB", "->", "insert_record", "(", "'quiz_sections'", ",", "$", "section", ")", ";", "}" ]
Add a section heading on a given page and return the sectionid @param int $pagenumber the number of the page where the section heading begins. @param string|null $heading the heading to add. If not given, a default is used.
[ "Add", "a", "section", "heading", "on", "a", "given", "page", "and", "return", "the", "sectionid" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/structure.php#L1013-L1026
217,195
moodle/moodle
mod/quiz/classes/structure.php
structure.set_section_heading
public function set_section_heading($id, $newheading) { global $DB; $section = $DB->get_record('quiz_sections', array('id' => $id), '*', MUST_EXIST); $section->heading = $newheading; $DB->update_record('quiz_sections', $section); }
php
public function set_section_heading($id, $newheading) { global $DB; $section = $DB->get_record('quiz_sections', array('id' => $id), '*', MUST_EXIST); $section->heading = $newheading; $DB->update_record('quiz_sections', $section); }
[ "public", "function", "set_section_heading", "(", "$", "id", ",", "$", "newheading", ")", "{", "global", "$", "DB", ";", "$", "section", "=", "$", "DB", "->", "get_record", "(", "'quiz_sections'", ",", "array", "(", "'id'", "=>", "$", "id", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "$", "section", "->", "heading", "=", "$", "newheading", ";", "$", "DB", "->", "update_record", "(", "'quiz_sections'", ",", "$", "section", ")", ";", "}" ]
Change the heading for a section. @param int $id the id of the section to change. @param string $newheading the new heading for this section.
[ "Change", "the", "heading", "for", "a", "section", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/structure.php#L1033-L1038
217,196
moodle/moodle
mod/quiz/classes/structure.php
structure.set_section_shuffle
public function set_section_shuffle($id, $shuffle) { global $DB; $section = $DB->get_record('quiz_sections', array('id' => $id), '*', MUST_EXIST); $section->shufflequestions = $shuffle; $DB->update_record('quiz_sections', $section); }
php
public function set_section_shuffle($id, $shuffle) { global $DB; $section = $DB->get_record('quiz_sections', array('id' => $id), '*', MUST_EXIST); $section->shufflequestions = $shuffle; $DB->update_record('quiz_sections', $section); }
[ "public", "function", "set_section_shuffle", "(", "$", "id", ",", "$", "shuffle", ")", "{", "global", "$", "DB", ";", "$", "section", "=", "$", "DB", "->", "get_record", "(", "'quiz_sections'", ",", "array", "(", "'id'", "=>", "$", "id", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "$", "section", "->", "shufflequestions", "=", "$", "shuffle", ";", "$", "DB", "->", "update_record", "(", "'quiz_sections'", ",", "$", "section", ")", ";", "}" ]
Change the shuffle setting for a section. @param int $id the id of the section to change. @param bool $shuffle whether this section should be shuffled.
[ "Change", "the", "shuffle", "setting", "for", "a", "section", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/structure.php#L1045-L1050
217,197
moodle/moodle
mod/quiz/classes/structure.php
structure.remove_section_heading
public function remove_section_heading($sectionid) { global $DB; $section = $DB->get_record('quiz_sections', array('id' => $sectionid), '*', MUST_EXIST); if ($section->firstslot == 1) { throw new \coding_exception('Cannot remove the first section in a quiz.'); } $DB->delete_records('quiz_sections', array('id' => $sectionid)); }
php
public function remove_section_heading($sectionid) { global $DB; $section = $DB->get_record('quiz_sections', array('id' => $sectionid), '*', MUST_EXIST); if ($section->firstslot == 1) { throw new \coding_exception('Cannot remove the first section in a quiz.'); } $DB->delete_records('quiz_sections', array('id' => $sectionid)); }
[ "public", "function", "remove_section_heading", "(", "$", "sectionid", ")", "{", "global", "$", "DB", ";", "$", "section", "=", "$", "DB", "->", "get_record", "(", "'quiz_sections'", ",", "array", "(", "'id'", "=>", "$", "sectionid", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "if", "(", "$", "section", "->", "firstslot", "==", "1", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'Cannot remove the first section in a quiz.'", ")", ";", "}", "$", "DB", "->", "delete_records", "(", "'quiz_sections'", ",", "array", "(", "'id'", "=>", "$", "sectionid", ")", ")", ";", "}" ]
Remove the section heading with the given id @param int $sectionid the section to remove.
[ "Remove", "the", "section", "heading", "with", "the", "given", "id" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/structure.php#L1056-L1063
217,198
moodle/moodle
mod/quiz/classes/structure.php
structure.get_slot_tags_for_slot_id
public function get_slot_tags_for_slot_id($slotid) { if (!$this->hasloadedtags) { // Lazy load the tags just in case they are never required. $this->populate_slot_tags(); $this->hasloadedtags = true; } return isset($this->slottags[$slotid]) ? $this->slottags[$slotid] : []; }
php
public function get_slot_tags_for_slot_id($slotid) { if (!$this->hasloadedtags) { // Lazy load the tags just in case they are never required. $this->populate_slot_tags(); $this->hasloadedtags = true; } return isset($this->slottags[$slotid]) ? $this->slottags[$slotid] : []; }
[ "public", "function", "get_slot_tags_for_slot_id", "(", "$", "slotid", ")", "{", "if", "(", "!", "$", "this", "->", "hasloadedtags", ")", "{", "// Lazy load the tags just in case they are never required.", "$", "this", "->", "populate_slot_tags", "(", ")", ";", "$", "this", "->", "hasloadedtags", "=", "true", ";", "}", "return", "isset", "(", "$", "this", "->", "slottags", "[", "$", "slotid", "]", ")", "?", "$", "this", "->", "slottags", "[", "$", "slotid", "]", ":", "[", "]", ";", "}" ]
Retrieve the list of slot tags for the given slot id. @param int $slotid The id for the slot @return \stdClass[] The list of slot tag records
[ "Retrieve", "the", "list", "of", "slot", "tags", "for", "the", "given", "slot", "id", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/structure.php#L1079-L1087
217,199
moodle/moodle
media/classes/manager.php
core_media_manager.instance
public static function instance($page = null) { // Use the passed $page if given, otherwise the $PAGE global. if (!$page) { global $PAGE; $page = $PAGE; } if (self::$instance === null || ($page && self::$instance->page !== $page)) { self::$instance = new self($page); } return self::$instance; }
php
public static function instance($page = null) { // Use the passed $page if given, otherwise the $PAGE global. if (!$page) { global $PAGE; $page = $PAGE; } if (self::$instance === null || ($page && self::$instance->page !== $page)) { self::$instance = new self($page); } return self::$instance; }
[ "public", "static", "function", "instance", "(", "$", "page", "=", "null", ")", "{", "// Use the passed $page if given, otherwise the $PAGE global.", "if", "(", "!", "$", "page", ")", "{", "global", "$", "PAGE", ";", "$", "page", "=", "$", "PAGE", ";", "}", "if", "(", "self", "::", "$", "instance", "===", "null", "||", "(", "$", "page", "&&", "self", "::", "$", "instance", "->", "page", "!==", "$", "page", ")", ")", "{", "self", "::", "$", "instance", "=", "new", "self", "(", "$", "page", ")", ";", "}", "return", "self", "::", "$", "instance", ";", "}" ]
Returns a singleton instance of a manager Note as of Moodle 3.3, this will call setup for you. @return core_media_manager
[ "Returns", "a", "singleton", "instance", "of", "a", "manager" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/media/classes/manager.php#L110-L120