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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
218,000
|
moodle/moodle
|
lib/classes/user.php
|
core_user.get_property_choices
|
public static function get_property_choices($property) {
self::fill_properties_cache();
if (!array_key_exists($property, self::$propertiescache) && !array_key_exists('choices',
self::$propertiescache[$property])) {
throw new coding_exception('Invalid property requested, or the property does not has a list of choices.');
}
return self::$propertiescache[$property]['choices'];
}
|
php
|
public static function get_property_choices($property) {
self::fill_properties_cache();
if (!array_key_exists($property, self::$propertiescache) && !array_key_exists('choices',
self::$propertiescache[$property])) {
throw new coding_exception('Invalid property requested, or the property does not has a list of choices.');
}
return self::$propertiescache[$property]['choices'];
}
|
[
"public",
"static",
"function",
"get_property_choices",
"(",
"$",
"property",
")",
"{",
"self",
"::",
"fill_properties_cache",
"(",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"property",
",",
"self",
"::",
"$",
"propertiescache",
")",
"&&",
"!",
"array_key_exists",
"(",
"'choices'",
",",
"self",
"::",
"$",
"propertiescache",
"[",
"$",
"property",
"]",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Invalid property requested, or the property does not has a list of choices.'",
")",
";",
"}",
"return",
"self",
"::",
"$",
"propertiescache",
"[",
"$",
"property",
"]",
"[",
"'choices'",
"]",
";",
"}"
] |
Get the choices of the property.
This is a helper method to validate a value against a list of acceptable choices.
For instance: country, language, themes and etc.
@param string $property property name to be retrieved.
@throws coding_exception if the requested property name is invalid or if it does not has a list of choices.
@return array the property parameter type.
|
[
"Get",
"the",
"choices",
"of",
"the",
"property",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/user.php#L900-L911
|
218,001
|
moodle/moodle
|
lib/classes/user.php
|
core_user.get_property_default
|
public static function get_property_default($property) {
self::fill_properties_cache();
if (!array_key_exists($property, self::$propertiescache) || !isset(self::$propertiescache[$property]['default'])) {
throw new coding_exception('Invalid property requested, or the property does not has a default value.');
}
return self::$propertiescache[$property]['default'];
}
|
php
|
public static function get_property_default($property) {
self::fill_properties_cache();
if (!array_key_exists($property, self::$propertiescache) || !isset(self::$propertiescache[$property]['default'])) {
throw new coding_exception('Invalid property requested, or the property does not has a default value.');
}
return self::$propertiescache[$property]['default'];
}
|
[
"public",
"static",
"function",
"get_property_default",
"(",
"$",
"property",
")",
"{",
"self",
"::",
"fill_properties_cache",
"(",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"property",
",",
"self",
"::",
"$",
"propertiescache",
")",
"||",
"!",
"isset",
"(",
"self",
"::",
"$",
"propertiescache",
"[",
"$",
"property",
"]",
"[",
"'default'",
"]",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Invalid property requested, or the property does not has a default value.'",
")",
";",
"}",
"return",
"self",
"::",
"$",
"propertiescache",
"[",
"$",
"property",
"]",
"[",
"'default'",
"]",
";",
"}"
] |
Get the property default.
This method gets the default value of a field (if exists).
@param string $property property name to be retrieved.
@throws coding_exception if the requested property name is invalid or if it does not has a default value.
@return string the property default value.
|
[
"Get",
"the",
"property",
"default",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/user.php#L922-L931
|
218,002
|
moodle/moodle
|
lib/classes/user.php
|
core_user.fill_preferences_cache
|
protected static function fill_preferences_cache() {
if (self::$preferencescache !== null) {
return;
}
// Array of user preferences and expected types/values.
// Every preference that can be updated directly by user should be added here.
$preferences = array();
$preferences['auth_forcepasswordchange'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED, 'choices' => array(0, 1),
'permissioncallback' => function($user, $preferencename) {
global $USER;
$systemcontext = context_system::instance();
return ($USER->id != $user->id && (has_capability('moodle/user:update', $systemcontext) ||
($user->timecreated > time() - 10 && has_capability('moodle/user:create', $systemcontext))));
});
$preferences['usemodchooser'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED, 'default' => 1,
'choices' => array(0, 1));
$preferences['forum_markasreadonnotification'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED, 'default' => 1,
'choices' => array(0, 1));
$preferences['htmleditor'] = array('type' => PARAM_NOTAGS, 'null' => NULL_ALLOWED,
'cleancallback' => function($value, $preferencename) {
if (empty($value) || !array_key_exists($value, core_component::get_plugin_list('editor'))) {
return null;
}
return $value;
});
$preferences['badgeprivacysetting'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED, 'default' => 1,
'choices' => array(0, 1), 'permissioncallback' => function($user, $preferencename) {
global $CFG, $USER;
return !empty($CFG->enablebadges) && $user->id == $USER->id;
});
$preferences['blogpagesize'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED, 'default' => 10,
'permissioncallback' => function($user, $preferencename) {
global $USER;
return $USER->id == $user->id && has_capability('moodle/blog:view', context_system::instance());
});
// Core components that may want to define their preferences.
// List of core components implementing callback is hardcoded here for performance reasons.
// TODO MDL-58184 cache list of core components implementing a function.
$corecomponents = ['core_message', 'core_calendar'];
foreach ($corecomponents as $component) {
if (($pluginpreferences = component_callback($component, 'user_preferences')) && is_array($pluginpreferences)) {
$preferences += $pluginpreferences;
}
}
// Plugins that may define their preferences.
if ($pluginsfunction = get_plugins_with_function('user_preferences')) {
foreach ($pluginsfunction as $plugintype => $plugins) {
foreach ($plugins as $function) {
if (($pluginpreferences = call_user_func($function)) && is_array($pluginpreferences)) {
$preferences += $pluginpreferences;
}
}
}
}
self::$preferencescache = $preferences;
}
|
php
|
protected static function fill_preferences_cache() {
if (self::$preferencescache !== null) {
return;
}
// Array of user preferences and expected types/values.
// Every preference that can be updated directly by user should be added here.
$preferences = array();
$preferences['auth_forcepasswordchange'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED, 'choices' => array(0, 1),
'permissioncallback' => function($user, $preferencename) {
global $USER;
$systemcontext = context_system::instance();
return ($USER->id != $user->id && (has_capability('moodle/user:update', $systemcontext) ||
($user->timecreated > time() - 10 && has_capability('moodle/user:create', $systemcontext))));
});
$preferences['usemodchooser'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED, 'default' => 1,
'choices' => array(0, 1));
$preferences['forum_markasreadonnotification'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED, 'default' => 1,
'choices' => array(0, 1));
$preferences['htmleditor'] = array('type' => PARAM_NOTAGS, 'null' => NULL_ALLOWED,
'cleancallback' => function($value, $preferencename) {
if (empty($value) || !array_key_exists($value, core_component::get_plugin_list('editor'))) {
return null;
}
return $value;
});
$preferences['badgeprivacysetting'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED, 'default' => 1,
'choices' => array(0, 1), 'permissioncallback' => function($user, $preferencename) {
global $CFG, $USER;
return !empty($CFG->enablebadges) && $user->id == $USER->id;
});
$preferences['blogpagesize'] = array('type' => PARAM_INT, 'null' => NULL_NOT_ALLOWED, 'default' => 10,
'permissioncallback' => function($user, $preferencename) {
global $USER;
return $USER->id == $user->id && has_capability('moodle/blog:view', context_system::instance());
});
// Core components that may want to define their preferences.
// List of core components implementing callback is hardcoded here for performance reasons.
// TODO MDL-58184 cache list of core components implementing a function.
$corecomponents = ['core_message', 'core_calendar'];
foreach ($corecomponents as $component) {
if (($pluginpreferences = component_callback($component, 'user_preferences')) && is_array($pluginpreferences)) {
$preferences += $pluginpreferences;
}
}
// Plugins that may define their preferences.
if ($pluginsfunction = get_plugins_with_function('user_preferences')) {
foreach ($pluginsfunction as $plugintype => $plugins) {
foreach ($plugins as $function) {
if (($pluginpreferences = call_user_func($function)) && is_array($pluginpreferences)) {
$preferences += $pluginpreferences;
}
}
}
}
self::$preferencescache = $preferences;
}
|
[
"protected",
"static",
"function",
"fill_preferences_cache",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"preferencescache",
"!==",
"null",
")",
"{",
"return",
";",
"}",
"// Array of user preferences and expected types/values.",
"// Every preference that can be updated directly by user should be added here.",
"$",
"preferences",
"=",
"array",
"(",
")",
";",
"$",
"preferences",
"[",
"'auth_forcepasswordchange'",
"]",
"=",
"array",
"(",
"'type'",
"=>",
"PARAM_INT",
",",
"'null'",
"=>",
"NULL_NOT_ALLOWED",
",",
"'choices'",
"=>",
"array",
"(",
"0",
",",
"1",
")",
",",
"'permissioncallback'",
"=>",
"function",
"(",
"$",
"user",
",",
"$",
"preferencename",
")",
"{",
"global",
"$",
"USER",
";",
"$",
"systemcontext",
"=",
"context_system",
"::",
"instance",
"(",
")",
";",
"return",
"(",
"$",
"USER",
"->",
"id",
"!=",
"$",
"user",
"->",
"id",
"&&",
"(",
"has_capability",
"(",
"'moodle/user:update'",
",",
"$",
"systemcontext",
")",
"||",
"(",
"$",
"user",
"->",
"timecreated",
">",
"time",
"(",
")",
"-",
"10",
"&&",
"has_capability",
"(",
"'moodle/user:create'",
",",
"$",
"systemcontext",
")",
")",
")",
")",
";",
"}",
")",
";",
"$",
"preferences",
"[",
"'usemodchooser'",
"]",
"=",
"array",
"(",
"'type'",
"=>",
"PARAM_INT",
",",
"'null'",
"=>",
"NULL_NOT_ALLOWED",
",",
"'default'",
"=>",
"1",
",",
"'choices'",
"=>",
"array",
"(",
"0",
",",
"1",
")",
")",
";",
"$",
"preferences",
"[",
"'forum_markasreadonnotification'",
"]",
"=",
"array",
"(",
"'type'",
"=>",
"PARAM_INT",
",",
"'null'",
"=>",
"NULL_NOT_ALLOWED",
",",
"'default'",
"=>",
"1",
",",
"'choices'",
"=>",
"array",
"(",
"0",
",",
"1",
")",
")",
";",
"$",
"preferences",
"[",
"'htmleditor'",
"]",
"=",
"array",
"(",
"'type'",
"=>",
"PARAM_NOTAGS",
",",
"'null'",
"=>",
"NULL_ALLOWED",
",",
"'cleancallback'",
"=>",
"function",
"(",
"$",
"value",
",",
"$",
"preferencename",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
"||",
"!",
"array_key_exists",
"(",
"$",
"value",
",",
"core_component",
"::",
"get_plugin_list",
"(",
"'editor'",
")",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"value",
";",
"}",
")",
";",
"$",
"preferences",
"[",
"'badgeprivacysetting'",
"]",
"=",
"array",
"(",
"'type'",
"=>",
"PARAM_INT",
",",
"'null'",
"=>",
"NULL_NOT_ALLOWED",
",",
"'default'",
"=>",
"1",
",",
"'choices'",
"=>",
"array",
"(",
"0",
",",
"1",
")",
",",
"'permissioncallback'",
"=>",
"function",
"(",
"$",
"user",
",",
"$",
"preferencename",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"USER",
";",
"return",
"!",
"empty",
"(",
"$",
"CFG",
"->",
"enablebadges",
")",
"&&",
"$",
"user",
"->",
"id",
"==",
"$",
"USER",
"->",
"id",
";",
"}",
")",
";",
"$",
"preferences",
"[",
"'blogpagesize'",
"]",
"=",
"array",
"(",
"'type'",
"=>",
"PARAM_INT",
",",
"'null'",
"=>",
"NULL_NOT_ALLOWED",
",",
"'default'",
"=>",
"10",
",",
"'permissioncallback'",
"=>",
"function",
"(",
"$",
"user",
",",
"$",
"preferencename",
")",
"{",
"global",
"$",
"USER",
";",
"return",
"$",
"USER",
"->",
"id",
"==",
"$",
"user",
"->",
"id",
"&&",
"has_capability",
"(",
"'moodle/blog:view'",
",",
"context_system",
"::",
"instance",
"(",
")",
")",
";",
"}",
")",
";",
"// Core components that may want to define their preferences.",
"// List of core components implementing callback is hardcoded here for performance reasons.",
"// TODO MDL-58184 cache list of core components implementing a function.",
"$",
"corecomponents",
"=",
"[",
"'core_message'",
",",
"'core_calendar'",
"]",
";",
"foreach",
"(",
"$",
"corecomponents",
"as",
"$",
"component",
")",
"{",
"if",
"(",
"(",
"$",
"pluginpreferences",
"=",
"component_callback",
"(",
"$",
"component",
",",
"'user_preferences'",
")",
")",
"&&",
"is_array",
"(",
"$",
"pluginpreferences",
")",
")",
"{",
"$",
"preferences",
"+=",
"$",
"pluginpreferences",
";",
"}",
"}",
"// Plugins that may define their preferences.",
"if",
"(",
"$",
"pluginsfunction",
"=",
"get_plugins_with_function",
"(",
"'user_preferences'",
")",
")",
"{",
"foreach",
"(",
"$",
"pluginsfunction",
"as",
"$",
"plugintype",
"=>",
"$",
"plugins",
")",
"{",
"foreach",
"(",
"$",
"plugins",
"as",
"$",
"function",
")",
"{",
"if",
"(",
"(",
"$",
"pluginpreferences",
"=",
"call_user_func",
"(",
"$",
"function",
")",
")",
"&&",
"is_array",
"(",
"$",
"pluginpreferences",
")",
")",
"{",
"$",
"preferences",
"+=",
"$",
"pluginpreferences",
";",
"}",
"}",
"}",
"}",
"self",
"::",
"$",
"preferencescache",
"=",
"$",
"preferences",
";",
"}"
] |
Definition of updateable user preferences and rules for data and access validation.
array(
'preferencename' => array( // Either exact preference name or a regular expression.
'null' => NULL_ALLOWED, // Defaults to NULL_NOT_ALLOWED. Takes NULL_NOT_ALLOWED or NULL_ALLOWED.
'type' => PARAM_TYPE, // Expected parameter type of the user field - mandatory
'choices' => array(1, 2..) // An array of accepted values of the user field - optional
'default' => $CFG->setting // An default value for the field - optional
'isregex' => false/true // Whether the name of the preference is a regular expression (default false).
'permissioncallback' => callable // Function accepting arguments ($user, $preferencename) that checks if current user
// is allowed to modify this preference for given user.
// If not specified core_user::default_preference_permission_check() will be assumed.
'cleancallback' => callable // Custom callback for cleaning value if something more difficult than just type/choices is needed
// accepts arguments ($value, $preferencename)
)
)
@return void
|
[
"Definition",
"of",
"updateable",
"user",
"preferences",
"and",
"rules",
"for",
"data",
"and",
"access",
"validation",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/user.php#L953-L1012
|
218,003
|
moodle/moodle
|
lib/classes/user.php
|
core_user.get_preference_definition
|
protected static function get_preference_definition($preferencename) {
self::fill_preferences_cache();
foreach (self::$preferencescache as $key => $preference) {
if (empty($preference['isregex'])) {
if ($key === $preferencename) {
return $preference;
}
} else {
if (preg_match($key, $preferencename)) {
return $preference;
}
}
}
throw new coding_exception('Invalid preference requested.');
}
|
php
|
protected static function get_preference_definition($preferencename) {
self::fill_preferences_cache();
foreach (self::$preferencescache as $key => $preference) {
if (empty($preference['isregex'])) {
if ($key === $preferencename) {
return $preference;
}
} else {
if (preg_match($key, $preferencename)) {
return $preference;
}
}
}
throw new coding_exception('Invalid preference requested.');
}
|
[
"protected",
"static",
"function",
"get_preference_definition",
"(",
"$",
"preferencename",
")",
"{",
"self",
"::",
"fill_preferences_cache",
"(",
")",
";",
"foreach",
"(",
"self",
"::",
"$",
"preferencescache",
"as",
"$",
"key",
"=>",
"$",
"preference",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"preference",
"[",
"'isregex'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"key",
"===",
"$",
"preferencename",
")",
"{",
"return",
"$",
"preference",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"preg_match",
"(",
"$",
"key",
",",
"$",
"preferencename",
")",
")",
"{",
"return",
"$",
"preference",
";",
"}",
"}",
"}",
"throw",
"new",
"coding_exception",
"(",
"'Invalid preference requested.'",
")",
";",
"}"
] |
Retrieves the preference definition
@param string $preferencename
@return array
|
[
"Retrieves",
"the",
"preference",
"definition"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/user.php#L1020-L1036
|
218,004
|
moodle/moodle
|
lib/classes/user.php
|
core_user.clean_preference
|
public static function clean_preference($value, $preferencename) {
$definition = self::get_preference_definition($preferencename);
if (isset($definition['type']) && $value !== null) {
$value = clean_param($value, $definition['type']);
}
if (isset($definition['cleancallback'])) {
$callback = $definition['cleancallback'];
if (is_callable($callback)) {
return $callback($value, $preferencename);
} else {
throw new coding_exception('Clean callback for preference ' . s($preferencename) . ' is not callable');
}
} else if ($value === null && (!isset($definition['null']) || $definition['null'] == NULL_ALLOWED)) {
return null;
} else if (isset($definition['choices'])) {
if (!in_array($value, $definition['choices'])) {
if (isset($definition['default'])) {
return $definition['default'];
} else {
$first = reset($definition['choices']);
return $first;
}
} else {
return $value;
}
} else {
if ($value === null) {
return isset($definition['default']) ? $definition['default'] : '';
}
return $value;
}
}
|
php
|
public static function clean_preference($value, $preferencename) {
$definition = self::get_preference_definition($preferencename);
if (isset($definition['type']) && $value !== null) {
$value = clean_param($value, $definition['type']);
}
if (isset($definition['cleancallback'])) {
$callback = $definition['cleancallback'];
if (is_callable($callback)) {
return $callback($value, $preferencename);
} else {
throw new coding_exception('Clean callback for preference ' . s($preferencename) . ' is not callable');
}
} else if ($value === null && (!isset($definition['null']) || $definition['null'] == NULL_ALLOWED)) {
return null;
} else if (isset($definition['choices'])) {
if (!in_array($value, $definition['choices'])) {
if (isset($definition['default'])) {
return $definition['default'];
} else {
$first = reset($definition['choices']);
return $first;
}
} else {
return $value;
}
} else {
if ($value === null) {
return isset($definition['default']) ? $definition['default'] : '';
}
return $value;
}
}
|
[
"public",
"static",
"function",
"clean_preference",
"(",
"$",
"value",
",",
"$",
"preferencename",
")",
"{",
"$",
"definition",
"=",
"self",
"::",
"get_preference_definition",
"(",
"$",
"preferencename",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"definition",
"[",
"'type'",
"]",
")",
"&&",
"$",
"value",
"!==",
"null",
")",
"{",
"$",
"value",
"=",
"clean_param",
"(",
"$",
"value",
",",
"$",
"definition",
"[",
"'type'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"definition",
"[",
"'cleancallback'",
"]",
")",
")",
"{",
"$",
"callback",
"=",
"$",
"definition",
"[",
"'cleancallback'",
"]",
";",
"if",
"(",
"is_callable",
"(",
"$",
"callback",
")",
")",
"{",
"return",
"$",
"callback",
"(",
"$",
"value",
",",
"$",
"preferencename",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Clean callback for preference '",
".",
"s",
"(",
"$",
"preferencename",
")",
".",
"' is not callable'",
")",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"value",
"===",
"null",
"&&",
"(",
"!",
"isset",
"(",
"$",
"definition",
"[",
"'null'",
"]",
")",
"||",
"$",
"definition",
"[",
"'null'",
"]",
"==",
"NULL_ALLOWED",
")",
")",
"{",
"return",
"null",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"definition",
"[",
"'choices'",
"]",
")",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"value",
",",
"$",
"definition",
"[",
"'choices'",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"definition",
"[",
"'default'",
"]",
")",
")",
"{",
"return",
"$",
"definition",
"[",
"'default'",
"]",
";",
"}",
"else",
"{",
"$",
"first",
"=",
"reset",
"(",
"$",
"definition",
"[",
"'choices'",
"]",
")",
";",
"return",
"$",
"first",
";",
"}",
"}",
"else",
"{",
"return",
"$",
"value",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"isset",
"(",
"$",
"definition",
"[",
"'default'",
"]",
")",
"?",
"$",
"definition",
"[",
"'default'",
"]",
":",
"''",
";",
"}",
"return",
"$",
"value",
";",
"}",
"}"
] |
Clean value of a user preference
@param string $value the user preference value to be cleaned.
@param string $preferencename the user preference name
@return string the cleaned preference value
|
[
"Clean",
"value",
"of",
"a",
"user",
"preference"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/user.php#L1114-L1148
|
218,005
|
moodle/moodle
|
analytics/classes/local/indicator/discrete.php
|
discrete.to_features
|
protected function to_features($calculatedvalues) {
$classes = static::get_classes();
foreach ($calculatedvalues as $sampleid => $calculatedvalue) {
// Using intval as it may come as a float from the db.
$classindex = array_search(intval($calculatedvalue), $classes, true);
if ($classindex === false && !is_null($calculatedvalue)) {
throw new \coding_exception(get_class($this) . ' calculated value "' . $calculatedvalue .
'" is not one of its defined classes (' . json_encode($classes) . ')');
}
// We transform the calculated value into multiple features, one for each of the possible classes.
$features = array_fill(0, count($classes), 0);
// 1 to the selected value.
if (!is_null($calculatedvalue)) {
$features[$classindex] = 1;
}
$calculatedvalues[$sampleid] = $features;
}
return $calculatedvalues;
}
|
php
|
protected function to_features($calculatedvalues) {
$classes = static::get_classes();
foreach ($calculatedvalues as $sampleid => $calculatedvalue) {
// Using intval as it may come as a float from the db.
$classindex = array_search(intval($calculatedvalue), $classes, true);
if ($classindex === false && !is_null($calculatedvalue)) {
throw new \coding_exception(get_class($this) . ' calculated value "' . $calculatedvalue .
'" is not one of its defined classes (' . json_encode($classes) . ')');
}
// We transform the calculated value into multiple features, one for each of the possible classes.
$features = array_fill(0, count($classes), 0);
// 1 to the selected value.
if (!is_null($calculatedvalue)) {
$features[$classindex] = 1;
}
$calculatedvalues[$sampleid] = $features;
}
return $calculatedvalues;
}
|
[
"protected",
"function",
"to_features",
"(",
"$",
"calculatedvalues",
")",
"{",
"$",
"classes",
"=",
"static",
"::",
"get_classes",
"(",
")",
";",
"foreach",
"(",
"$",
"calculatedvalues",
"as",
"$",
"sampleid",
"=>",
"$",
"calculatedvalue",
")",
"{",
"// Using intval as it may come as a float from the db.",
"$",
"classindex",
"=",
"array_search",
"(",
"intval",
"(",
"$",
"calculatedvalue",
")",
",",
"$",
"classes",
",",
"true",
")",
";",
"if",
"(",
"$",
"classindex",
"===",
"false",
"&&",
"!",
"is_null",
"(",
"$",
"calculatedvalue",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"get_class",
"(",
"$",
"this",
")",
".",
"' calculated value \"'",
".",
"$",
"calculatedvalue",
".",
"'\" is not one of its defined classes ('",
".",
"json_encode",
"(",
"$",
"classes",
")",
".",
"')'",
")",
";",
"}",
"// We transform the calculated value into multiple features, one for each of the possible classes.",
"$",
"features",
"=",
"array_fill",
"(",
"0",
",",
"count",
"(",
"$",
"classes",
")",
",",
"0",
")",
";",
"// 1 to the selected value.",
"if",
"(",
"!",
"is_null",
"(",
"$",
"calculatedvalue",
")",
")",
"{",
"$",
"features",
"[",
"$",
"classindex",
"]",
"=",
"1",
";",
"}",
"$",
"calculatedvalues",
"[",
"$",
"sampleid",
"]",
"=",
"$",
"features",
";",
"}",
"return",
"$",
"calculatedvalues",
";",
"}"
] |
From calculated values to dataset features.
One column for each class.
@param float[] $calculatedvalues
@return float[]
|
[
"From",
"calculated",
"values",
"to",
"dataset",
"features",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/indicator/discrete.php#L116-L142
|
218,006
|
moodle/moodle
|
lib/htmlpurifier/HTMLPurifier/Injector/AutoParagraph.php
|
HTMLPurifier_Injector_AutoParagraph._checkNeedsP
|
private function _checkNeedsP($current)
{
if ($current instanceof HTMLPurifier_Token_Start) {
if (!$this->_isInline($current)) {
// <div>PAR1<div>
// ----
// Terminate early, since we hit a block element
return false;
}
} elseif ($current instanceof HTMLPurifier_Token_Text) {
if (strpos($current->data, "\n\n") !== false) {
// <div>PAR1<b>PAR1\n\nPAR2
// ----
return true;
} else {
// <div>PAR1<b>PAR1...
// ----
}
}
return null;
}
|
php
|
private function _checkNeedsP($current)
{
if ($current instanceof HTMLPurifier_Token_Start) {
if (!$this->_isInline($current)) {
// <div>PAR1<div>
// ----
// Terminate early, since we hit a block element
return false;
}
} elseif ($current instanceof HTMLPurifier_Token_Text) {
if (strpos($current->data, "\n\n") !== false) {
// <div>PAR1<b>PAR1\n\nPAR2
// ----
return true;
} else {
// <div>PAR1<b>PAR1...
// ----
}
}
return null;
}
|
[
"private",
"function",
"_checkNeedsP",
"(",
"$",
"current",
")",
"{",
"if",
"(",
"$",
"current",
"instanceof",
"HTMLPurifier_Token_Start",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"_isInline",
"(",
"$",
"current",
")",
")",
"{",
"// <div>PAR1<div>",
"// ----",
"// Terminate early, since we hit a block element",
"return",
"false",
";",
"}",
"}",
"elseif",
"(",
"$",
"current",
"instanceof",
"HTMLPurifier_Token_Text",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"current",
"->",
"data",
",",
"\"\\n\\n\"",
")",
"!==",
"false",
")",
"{",
"// <div>PAR1<b>PAR1\\n\\nPAR2",
"// ----",
"return",
"true",
";",
"}",
"else",
"{",
"// <div>PAR1<b>PAR1...",
"// ----",
"}",
"}",
"return",
"null",
";",
"}"
] |
Determines if a particular token requires an earlier inline token
to get a paragraph. This should be used with _forwardUntilEndToken
@param HTMLPurifier_Token $current
@return bool
|
[
"Determines",
"if",
"a",
"particular",
"token",
"requires",
"an",
"earlier",
"inline",
"token",
"to",
"get",
"a",
"paragraph",
".",
"This",
"should",
"be",
"used",
"with",
"_forwardUntilEndToken"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Injector/AutoParagraph.php#L333-L353
|
218,007
|
moodle/moodle
|
lib/mlbackend/php/phpml/src/Phpml/Classification/DecisionTree/DecisionTreeLeaf.php
|
DecisionTreeLeaf.getHTML
|
public function getHTML($columnNames = null)
{
if ($this->isTerminal) {
$value = "<b>$this->classValue</b>";
} else {
$value = $this->value;
if ($columnNames !== null) {
$col = $columnNames[$this->columnIndex];
} else {
$col = "col_$this->columnIndex";
}
if (!preg_match("/^[<>=]{1,2}/", $value)) {
$value = "=$value";
}
$value = "<b>$col $value</b><br>Gini: ". number_format($this->giniIndex, 2);
}
$str = "<table ><tr><td colspan=3 align=center style='border:1px solid;'>
$value</td></tr>";
if ($this->leftLeaf || $this->rightLeaf) {
$str .='<tr>';
if ($this->leftLeaf) {
$str .="<td valign=top><b>| Yes</b><br>" . $this->leftLeaf->getHTML($columnNames) . "</td>";
} else {
$str .='<td></td>';
}
$str .='<td> </td>';
if ($this->rightLeaf) {
$str .="<td valign=top align=right><b>No |</b><br>" . $this->rightLeaf->getHTML($columnNames) . "</td>";
} else {
$str .='<td></td>';
}
$str .= '</tr>';
}
$str .= '</table>';
return $str;
}
|
php
|
public function getHTML($columnNames = null)
{
if ($this->isTerminal) {
$value = "<b>$this->classValue</b>";
} else {
$value = $this->value;
if ($columnNames !== null) {
$col = $columnNames[$this->columnIndex];
} else {
$col = "col_$this->columnIndex";
}
if (!preg_match("/^[<>=]{1,2}/", $value)) {
$value = "=$value";
}
$value = "<b>$col $value</b><br>Gini: ". number_format($this->giniIndex, 2);
}
$str = "<table ><tr><td colspan=3 align=center style='border:1px solid;'>
$value</td></tr>";
if ($this->leftLeaf || $this->rightLeaf) {
$str .='<tr>';
if ($this->leftLeaf) {
$str .="<td valign=top><b>| Yes</b><br>" . $this->leftLeaf->getHTML($columnNames) . "</td>";
} else {
$str .='<td></td>';
}
$str .='<td> </td>';
if ($this->rightLeaf) {
$str .="<td valign=top align=right><b>No |</b><br>" . $this->rightLeaf->getHTML($columnNames) . "</td>";
} else {
$str .='<td></td>';
}
$str .= '</tr>';
}
$str .= '</table>';
return $str;
}
|
[
"public",
"function",
"getHTML",
"(",
"$",
"columnNames",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isTerminal",
")",
"{",
"$",
"value",
"=",
"\"<b>$this->classValue</b>\"",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"value",
";",
"if",
"(",
"$",
"columnNames",
"!==",
"null",
")",
"{",
"$",
"col",
"=",
"$",
"columnNames",
"[",
"$",
"this",
"->",
"columnIndex",
"]",
";",
"}",
"else",
"{",
"$",
"col",
"=",
"\"col_$this->columnIndex\"",
";",
"}",
"if",
"(",
"!",
"preg_match",
"(",
"\"/^[<>=]{1,2}/\"",
",",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"\"=$value\"",
";",
"}",
"$",
"value",
"=",
"\"<b>$col $value</b><br>Gini: \"",
".",
"number_format",
"(",
"$",
"this",
"->",
"giniIndex",
",",
"2",
")",
";",
"}",
"$",
"str",
"=",
"\"<table ><tr><td colspan=3 align=center style='border:1px solid;'>\n\t\t\t\t$value</td></tr>\"",
";",
"if",
"(",
"$",
"this",
"->",
"leftLeaf",
"||",
"$",
"this",
"->",
"rightLeaf",
")",
"{",
"$",
"str",
".=",
"'<tr>'",
";",
"if",
"(",
"$",
"this",
"->",
"leftLeaf",
")",
"{",
"$",
"str",
".=",
"\"<td valign=top><b>| Yes</b><br>\"",
".",
"$",
"this",
"->",
"leftLeaf",
"->",
"getHTML",
"(",
"$",
"columnNames",
")",
".",
"\"</td>\"",
";",
"}",
"else",
"{",
"$",
"str",
".=",
"'<td></td>'",
";",
"}",
"$",
"str",
".=",
"'<td> </td>'",
";",
"if",
"(",
"$",
"this",
"->",
"rightLeaf",
")",
"{",
"$",
"str",
".=",
"\"<td valign=top align=right><b>No |</b><br>\"",
".",
"$",
"this",
"->",
"rightLeaf",
"->",
"getHTML",
"(",
"$",
"columnNames",
")",
".",
"\"</td>\"",
";",
"}",
"else",
"{",
"$",
"str",
".=",
"'<td></td>'",
";",
"}",
"$",
"str",
".=",
"'</tr>'",
";",
"}",
"$",
"str",
".=",
"'</table>'",
";",
"return",
"$",
"str",
";",
"}"
] |
Returns HTML representation of the node including children nodes
@param $columnNames
@return string
|
[
"Returns",
"HTML",
"representation",
"of",
"the",
"node",
"including",
"children",
"nodes"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mlbackend/php/phpml/src/Phpml/Classification/DecisionTree/DecisionTreeLeaf.php#L127-L162
|
218,008
|
moodle/moodle
|
customfield/classes/field_config_form.php
|
field_config_form.validation
|
public function validation($data, $files = array()) {
global $DB;
$errors = array();
/** @var field_controller $field */
$field = $this->_customdata['field'];
$handler = $field->get_handler();
// Check the shortname is specified and is unique for this component-area-itemid combination.
if (!preg_match('/^[a-z0-9_]+$/', $data['shortname'])) {
// Check allowed pattern (numbers, letters and underscore).
$errors['shortname'] = get_string('invalidshortnameerror', 'core_customfield');
} else if ($DB->record_exists_sql('SELECT 1 FROM {customfield_field} f ' .
'JOIN {customfield_category} c ON c.id = f.categoryid ' .
'WHERE f.shortname = ? AND f.id <> ? AND c.component = ? AND c.area = ? AND c.itemid = ?',
[$data['shortname'], $data['id'],
$handler->get_component(), $handler->get_area(), $handler->get_itemid()])) {
$errors['shortname'] = get_string('formfieldcheckshortname', 'core_customfield');
}
$errors = array_merge($errors, $field->config_form_validation($data, $files));
return $errors;
}
|
php
|
public function validation($data, $files = array()) {
global $DB;
$errors = array();
/** @var field_controller $field */
$field = $this->_customdata['field'];
$handler = $field->get_handler();
// Check the shortname is specified and is unique for this component-area-itemid combination.
if (!preg_match('/^[a-z0-9_]+$/', $data['shortname'])) {
// Check allowed pattern (numbers, letters and underscore).
$errors['shortname'] = get_string('invalidshortnameerror', 'core_customfield');
} else if ($DB->record_exists_sql('SELECT 1 FROM {customfield_field} f ' .
'JOIN {customfield_category} c ON c.id = f.categoryid ' .
'WHERE f.shortname = ? AND f.id <> ? AND c.component = ? AND c.area = ? AND c.itemid = ?',
[$data['shortname'], $data['id'],
$handler->get_component(), $handler->get_area(), $handler->get_itemid()])) {
$errors['shortname'] = get_string('formfieldcheckshortname', 'core_customfield');
}
$errors = array_merge($errors, $field->config_form_validation($data, $files));
return $errors;
}
|
[
"public",
"function",
"validation",
"(",
"$",
"data",
",",
"$",
"files",
"=",
"array",
"(",
")",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"errors",
"=",
"array",
"(",
")",
";",
"/** @var field_controller $field */",
"$",
"field",
"=",
"$",
"this",
"->",
"_customdata",
"[",
"'field'",
"]",
";",
"$",
"handler",
"=",
"$",
"field",
"->",
"get_handler",
"(",
")",
";",
"// Check the shortname is specified and is unique for this component-area-itemid combination.",
"if",
"(",
"!",
"preg_match",
"(",
"'/^[a-z0-9_]+$/'",
",",
"$",
"data",
"[",
"'shortname'",
"]",
")",
")",
"{",
"// Check allowed pattern (numbers, letters and underscore).",
"$",
"errors",
"[",
"'shortname'",
"]",
"=",
"get_string",
"(",
"'invalidshortnameerror'",
",",
"'core_customfield'",
")",
";",
"}",
"else",
"if",
"(",
"$",
"DB",
"->",
"record_exists_sql",
"(",
"'SELECT 1 FROM {customfield_field} f '",
".",
"'JOIN {customfield_category} c ON c.id = f.categoryid '",
".",
"'WHERE f.shortname = ? AND f.id <> ? AND c.component = ? AND c.area = ? AND c.itemid = ?'",
",",
"[",
"$",
"data",
"[",
"'shortname'",
"]",
",",
"$",
"data",
"[",
"'id'",
"]",
",",
"$",
"handler",
"->",
"get_component",
"(",
")",
",",
"$",
"handler",
"->",
"get_area",
"(",
")",
",",
"$",
"handler",
"->",
"get_itemid",
"(",
")",
"]",
")",
")",
"{",
"$",
"errors",
"[",
"'shortname'",
"]",
"=",
"get_string",
"(",
"'formfieldcheckshortname'",
",",
"'core_customfield'",
")",
";",
"}",
"$",
"errors",
"=",
"array_merge",
"(",
"$",
"errors",
",",
"$",
"field",
"->",
"config_form_validation",
"(",
"$",
"data",
",",
"$",
"files",
")",
")",
";",
"return",
"$",
"errors",
";",
"}"
] |
Field data validation
@param array $data
@param array $files
@return array
|
[
"Field",
"data",
"validation"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/field_config_form.php#L110-L133
|
218,009
|
moodle/moodle
|
lib/filebrowser/file_info_context_module.php
|
file_info_context_module.is_empty_area
|
public function is_empty_area() {
if ($child = $this->get_area_backup(0, '/', '.')) {
if (!$child->is_empty_area()) {
return false;
}
}
if ($child = $this->get_area_intro(0, '/', '.')) {
if (!$child->is_empty_area()) {
return false;
}
}
foreach ($this->areas as $area=>$desctiption) {
if ($child = $this->get_file_info('mod_'.$this->modname, $area, null, null, null)) {
if (!$child->is_empty_area()) {
return false;
}
}
}
return true;
}
|
php
|
public function is_empty_area() {
if ($child = $this->get_area_backup(0, '/', '.')) {
if (!$child->is_empty_area()) {
return false;
}
}
if ($child = $this->get_area_intro(0, '/', '.')) {
if (!$child->is_empty_area()) {
return false;
}
}
foreach ($this->areas as $area=>$desctiption) {
if ($child = $this->get_file_info('mod_'.$this->modname, $area, null, null, null)) {
if (!$child->is_empty_area()) {
return false;
}
}
}
return true;
}
|
[
"public",
"function",
"is_empty_area",
"(",
")",
"{",
"if",
"(",
"$",
"child",
"=",
"$",
"this",
"->",
"get_area_backup",
"(",
"0",
",",
"'/'",
",",
"'.'",
")",
")",
"{",
"if",
"(",
"!",
"$",
"child",
"->",
"is_empty_area",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"if",
"(",
"$",
"child",
"=",
"$",
"this",
"->",
"get_area_intro",
"(",
"0",
",",
"'/'",
",",
"'.'",
")",
")",
"{",
"if",
"(",
"!",
"$",
"child",
"->",
"is_empty_area",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"foreach",
"(",
"$",
"this",
"->",
"areas",
"as",
"$",
"area",
"=>",
"$",
"desctiption",
")",
"{",
"if",
"(",
"$",
"child",
"=",
"$",
"this",
"->",
"get_file_info",
"(",
"'mod_'",
".",
"$",
"this",
"->",
"modname",
",",
"$",
"area",
",",
"null",
",",
"null",
",",
"null",
")",
")",
"{",
"if",
"(",
"!",
"$",
"child",
"->",
"is_empty_area",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] |
Whether or not this is an emtpy area
@return bool
|
[
"Whether",
"or",
"not",
"this",
"is",
"an",
"emtpy",
"area"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filebrowser/file_info_context_module.php#L215-L236
|
218,010
|
moodle/moodle
|
admin/tool/dataprivacy/classes/manager_observer.php
|
manager_observer.handle_component_failure
|
public function handle_component_failure($e, $component, $interface, $methodname, array $params) {
// Get the list of the site Data Protection Officers.
$dpos = api::get_site_dpos();
$messagesubject = get_string('exceptionnotificationsubject', 'tool_dataprivacy');
$a = (object)[
'fullmethodname' => \core_privacy\manager::get_provider_classname_for_component($component) . '::' . $methodname,
'component' => $component,
'message' => $e->getMessage(),
'backtrace' => $e->getTraceAsString()
];
$messagebody = get_string('exceptionnotificationbody', 'tool_dataprivacy', $a);
// Email the data request to the Data Protection Officer(s)/Admin(s).
foreach ($dpos as $dpo) {
$message = new \core\message\message();
$message->courseid = SITEID;
$message->component = 'tool_dataprivacy';
$message->name = 'notifyexceptions';
$message->userfrom = \core_user::get_noreply_user();
$message->subject = $messagesubject;
$message->fullmessageformat = FORMAT_HTML;
$message->notification = 1;
$message->userto = $dpo;
$message->fullmessagehtml = $messagebody;
$message->fullmessage = html_to_text($messagebody);
// Send message.
message_send($message);
}
}
|
php
|
public function handle_component_failure($e, $component, $interface, $methodname, array $params) {
// Get the list of the site Data Protection Officers.
$dpos = api::get_site_dpos();
$messagesubject = get_string('exceptionnotificationsubject', 'tool_dataprivacy');
$a = (object)[
'fullmethodname' => \core_privacy\manager::get_provider_classname_for_component($component) . '::' . $methodname,
'component' => $component,
'message' => $e->getMessage(),
'backtrace' => $e->getTraceAsString()
];
$messagebody = get_string('exceptionnotificationbody', 'tool_dataprivacy', $a);
// Email the data request to the Data Protection Officer(s)/Admin(s).
foreach ($dpos as $dpo) {
$message = new \core\message\message();
$message->courseid = SITEID;
$message->component = 'tool_dataprivacy';
$message->name = 'notifyexceptions';
$message->userfrom = \core_user::get_noreply_user();
$message->subject = $messagesubject;
$message->fullmessageformat = FORMAT_HTML;
$message->notification = 1;
$message->userto = $dpo;
$message->fullmessagehtml = $messagebody;
$message->fullmessage = html_to_text($messagebody);
// Send message.
message_send($message);
}
}
|
[
"public",
"function",
"handle_component_failure",
"(",
"$",
"e",
",",
"$",
"component",
",",
"$",
"interface",
",",
"$",
"methodname",
",",
"array",
"$",
"params",
")",
"{",
"// Get the list of the site Data Protection Officers.",
"$",
"dpos",
"=",
"api",
"::",
"get_site_dpos",
"(",
")",
";",
"$",
"messagesubject",
"=",
"get_string",
"(",
"'exceptionnotificationsubject'",
",",
"'tool_dataprivacy'",
")",
";",
"$",
"a",
"=",
"(",
"object",
")",
"[",
"'fullmethodname'",
"=>",
"\\",
"core_privacy",
"\\",
"manager",
"::",
"get_provider_classname_for_component",
"(",
"$",
"component",
")",
".",
"'::'",
".",
"$",
"methodname",
",",
"'component'",
"=>",
"$",
"component",
",",
"'message'",
"=>",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"'backtrace'",
"=>",
"$",
"e",
"->",
"getTraceAsString",
"(",
")",
"]",
";",
"$",
"messagebody",
"=",
"get_string",
"(",
"'exceptionnotificationbody'",
",",
"'tool_dataprivacy'",
",",
"$",
"a",
")",
";",
"// Email the data request to the Data Protection Officer(s)/Admin(s).",
"foreach",
"(",
"$",
"dpos",
"as",
"$",
"dpo",
")",
"{",
"$",
"message",
"=",
"new",
"\\",
"core",
"\\",
"message",
"\\",
"message",
"(",
")",
";",
"$",
"message",
"->",
"courseid",
"=",
"SITEID",
";",
"$",
"message",
"->",
"component",
"=",
"'tool_dataprivacy'",
";",
"$",
"message",
"->",
"name",
"=",
"'notifyexceptions'",
";",
"$",
"message",
"->",
"userfrom",
"=",
"\\",
"core_user",
"::",
"get_noreply_user",
"(",
")",
";",
"$",
"message",
"->",
"subject",
"=",
"$",
"messagesubject",
";",
"$",
"message",
"->",
"fullmessageformat",
"=",
"FORMAT_HTML",
";",
"$",
"message",
"->",
"notification",
"=",
"1",
";",
"$",
"message",
"->",
"userto",
"=",
"$",
"dpo",
";",
"$",
"message",
"->",
"fullmessagehtml",
"=",
"$",
"messagebody",
";",
"$",
"message",
"->",
"fullmessage",
"=",
"html_to_text",
"(",
"$",
"messagebody",
")",
";",
"// Send message.",
"message_send",
"(",
"$",
"message",
")",
";",
"}",
"}"
] |
Notifies all DPOs that an exception occurred.
@param \Throwable $e
@param string $component
@param string $interface
@param string $methodname
@param array $params
|
[
"Notifies",
"all",
"DPOs",
"that",
"an",
"exception",
"occurred",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/manager_observer.php#L45-L75
|
218,011
|
moodle/moodle
|
lib/adodb/drivers/adodb-ado.inc.php
|
ADORecordSet_ado._seek
|
function _seek($row)
{
$rs = $this->_queryID;
// absoluteposition doesn't work -- my maths is wrong ?
// $rs->AbsolutePosition->$row-2;
// return true;
if ($this->_currentRow > $row) return false;
@$rs->Move((integer)$row - $this->_currentRow-1); //adBookmarkFirst
return true;
}
|
php
|
function _seek($row)
{
$rs = $this->_queryID;
// absoluteposition doesn't work -- my maths is wrong ?
// $rs->AbsolutePosition->$row-2;
// return true;
if ($this->_currentRow > $row) return false;
@$rs->Move((integer)$row - $this->_currentRow-1); //adBookmarkFirst
return true;
}
|
[
"function",
"_seek",
"(",
"$",
"row",
")",
"{",
"$",
"rs",
"=",
"$",
"this",
"->",
"_queryID",
";",
"// absoluteposition doesn't work -- my maths is wrong ?",
"//\t$rs->AbsolutePosition->$row-2;",
"//\treturn true;",
"if",
"(",
"$",
"this",
"->",
"_currentRow",
">",
"$",
"row",
")",
"return",
"false",
";",
"@",
"$",
"rs",
"->",
"Move",
"(",
"(",
"integer",
")",
"$",
"row",
"-",
"$",
"this",
"->",
"_currentRow",
"-",
"1",
")",
";",
"//adBookmarkFirst",
"return",
"true",
";",
"}"
] |
should only be used to move forward as we normally use forward-only cursors
|
[
"should",
"only",
"be",
"used",
"to",
"move",
"forward",
"as",
"we",
"normally",
"use",
"forward",
"-",
"only",
"cursors"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/drivers/adodb-ado.inc.php#L401-L410
|
218,012
|
moodle/moodle
|
enrol/category/classes/observer.php
|
enrol_category_observer.role_assigned
|
public static function role_assigned(\core\event\role_assigned $event) {
global $DB;
if (!enrol_is_enabled('category')) {
return;
}
$ra = new stdClass();
$ra->roleid = $event->objectid;
$ra->userid = $event->relateduserid;
$ra->contextid = $event->contextid;
//only category level roles are interesting
$parentcontext = context::instance_by_id($ra->contextid);
if ($parentcontext->contextlevel != CONTEXT_COURSECAT) {
return;
}
// Make sure the role is to be actually synchronised,
// please note we are ignoring overrides of the synchronised capability (for performance reasons in full sync).
$syscontext = context_system::instance();
if (!$DB->record_exists('role_capabilities', array('contextid'=>$syscontext->id, 'roleid'=>$ra->roleid, 'capability'=>'enrol/category:synchronised', 'permission'=>CAP_ALLOW))) {
return;
}
// Add necessary enrol instances.
$plugin = enrol_get_plugin('category');
$sql = "SELECT c.*
FROM {course} c
JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :courselevel AND ctx.path LIKE :match)
LEFT JOIN {enrol} e ON (e.courseid = c.id AND e.enrol = 'category')
WHERE e.id IS NULL";
$params = array('courselevel'=>CONTEXT_COURSE, 'match'=>$parentcontext->path.'/%');
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $course) {
$plugin->add_instance($course);
}
$rs->close();
// Now look for missing enrolments.
$sql = "SELECT e.*
FROM {course} c
JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :courselevel AND ctx.path LIKE :match)
JOIN {enrol} e ON (e.courseid = c.id AND e.enrol = 'category')
LEFT JOIN {user_enrolments} ue ON (ue.enrolid = e.id AND ue.userid = :userid)
WHERE ue.id IS NULL";
$params = array('courselevel'=>CONTEXT_COURSE, 'match'=>$parentcontext->path.'/%', 'userid'=>$ra->userid);
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $instance) {
$plugin->enrol_user($instance, $ra->userid, null, time());
}
$rs->close();
}
|
php
|
public static function role_assigned(\core\event\role_assigned $event) {
global $DB;
if (!enrol_is_enabled('category')) {
return;
}
$ra = new stdClass();
$ra->roleid = $event->objectid;
$ra->userid = $event->relateduserid;
$ra->contextid = $event->contextid;
//only category level roles are interesting
$parentcontext = context::instance_by_id($ra->contextid);
if ($parentcontext->contextlevel != CONTEXT_COURSECAT) {
return;
}
// Make sure the role is to be actually synchronised,
// please note we are ignoring overrides of the synchronised capability (for performance reasons in full sync).
$syscontext = context_system::instance();
if (!$DB->record_exists('role_capabilities', array('contextid'=>$syscontext->id, 'roleid'=>$ra->roleid, 'capability'=>'enrol/category:synchronised', 'permission'=>CAP_ALLOW))) {
return;
}
// Add necessary enrol instances.
$plugin = enrol_get_plugin('category');
$sql = "SELECT c.*
FROM {course} c
JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :courselevel AND ctx.path LIKE :match)
LEFT JOIN {enrol} e ON (e.courseid = c.id AND e.enrol = 'category')
WHERE e.id IS NULL";
$params = array('courselevel'=>CONTEXT_COURSE, 'match'=>$parentcontext->path.'/%');
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $course) {
$plugin->add_instance($course);
}
$rs->close();
// Now look for missing enrolments.
$sql = "SELECT e.*
FROM {course} c
JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :courselevel AND ctx.path LIKE :match)
JOIN {enrol} e ON (e.courseid = c.id AND e.enrol = 'category')
LEFT JOIN {user_enrolments} ue ON (ue.enrolid = e.id AND ue.userid = :userid)
WHERE ue.id IS NULL";
$params = array('courselevel'=>CONTEXT_COURSE, 'match'=>$parentcontext->path.'/%', 'userid'=>$ra->userid);
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $instance) {
$plugin->enrol_user($instance, $ra->userid, null, time());
}
$rs->close();
}
|
[
"public",
"static",
"function",
"role_assigned",
"(",
"\\",
"core",
"\\",
"event",
"\\",
"role_assigned",
"$",
"event",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"!",
"enrol_is_enabled",
"(",
"'category'",
")",
")",
"{",
"return",
";",
"}",
"$",
"ra",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"ra",
"->",
"roleid",
"=",
"$",
"event",
"->",
"objectid",
";",
"$",
"ra",
"->",
"userid",
"=",
"$",
"event",
"->",
"relateduserid",
";",
"$",
"ra",
"->",
"contextid",
"=",
"$",
"event",
"->",
"contextid",
";",
"//only category level roles are interesting",
"$",
"parentcontext",
"=",
"context",
"::",
"instance_by_id",
"(",
"$",
"ra",
"->",
"contextid",
")",
";",
"if",
"(",
"$",
"parentcontext",
"->",
"contextlevel",
"!=",
"CONTEXT_COURSECAT",
")",
"{",
"return",
";",
"}",
"// Make sure the role is to be actually synchronised,",
"// please note we are ignoring overrides of the synchronised capability (for performance reasons in full sync).",
"$",
"syscontext",
"=",
"context_system",
"::",
"instance",
"(",
")",
";",
"if",
"(",
"!",
"$",
"DB",
"->",
"record_exists",
"(",
"'role_capabilities'",
",",
"array",
"(",
"'contextid'",
"=>",
"$",
"syscontext",
"->",
"id",
",",
"'roleid'",
"=>",
"$",
"ra",
"->",
"roleid",
",",
"'capability'",
"=>",
"'enrol/category:synchronised'",
",",
"'permission'",
"=>",
"CAP_ALLOW",
")",
")",
")",
"{",
"return",
";",
"}",
"// Add necessary enrol instances.",
"$",
"plugin",
"=",
"enrol_get_plugin",
"(",
"'category'",
")",
";",
"$",
"sql",
"=",
"\"SELECT c.*\n FROM {course} c\n JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :courselevel AND ctx.path LIKE :match)\n LEFT JOIN {enrol} e ON (e.courseid = c.id AND e.enrol = 'category')\n WHERE e.id IS NULL\"",
";",
"$",
"params",
"=",
"array",
"(",
"'courselevel'",
"=>",
"CONTEXT_COURSE",
",",
"'match'",
"=>",
"$",
"parentcontext",
"->",
"path",
".",
"'/%'",
")",
";",
"$",
"rs",
"=",
"$",
"DB",
"->",
"get_recordset_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"foreach",
"(",
"$",
"rs",
"as",
"$",
"course",
")",
"{",
"$",
"plugin",
"->",
"add_instance",
"(",
"$",
"course",
")",
";",
"}",
"$",
"rs",
"->",
"close",
"(",
")",
";",
"// Now look for missing enrolments.",
"$",
"sql",
"=",
"\"SELECT e.*\n FROM {course} c\n JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :courselevel AND ctx.path LIKE :match)\n JOIN {enrol} e ON (e.courseid = c.id AND e.enrol = 'category')\n LEFT JOIN {user_enrolments} ue ON (ue.enrolid = e.id AND ue.userid = :userid)\n WHERE ue.id IS NULL\"",
";",
"$",
"params",
"=",
"array",
"(",
"'courselevel'",
"=>",
"CONTEXT_COURSE",
",",
"'match'",
"=>",
"$",
"parentcontext",
"->",
"path",
".",
"'/%'",
",",
"'userid'",
"=>",
"$",
"ra",
"->",
"userid",
")",
";",
"$",
"rs",
"=",
"$",
"DB",
"->",
"get_recordset_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"foreach",
"(",
"$",
"rs",
"as",
"$",
"instance",
")",
"{",
"$",
"plugin",
"->",
"enrol_user",
"(",
"$",
"instance",
",",
"$",
"ra",
"->",
"userid",
",",
"null",
",",
"time",
"(",
")",
")",
";",
"}",
"$",
"rs",
"->",
"close",
"(",
")",
";",
"}"
] |
Triggered when user is assigned a new role.
@param \core\event\role_assigned $event
|
[
"Triggered",
"when",
"user",
"is",
"assigned",
"a",
"new",
"role",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/category/classes/observer.php#L40-L92
|
218,013
|
moodle/moodle
|
enrol/category/classes/observer.php
|
enrol_category_observer.role_unassigned
|
public static function role_unassigned(\core\event\role_unassigned $event) {
global $DB;
if (!enrol_is_enabled('category')) {
return;
}
$ra = new stdClass();
$ra->userid = $event->relateduserid;
$ra->contextid = $event->contextid;
// only category level roles are interesting
$parentcontext = context::instance_by_id($ra->contextid);
if ($parentcontext->contextlevel != CONTEXT_COURSECAT) {
return;
}
// Now this is going to be a bit slow, take all enrolments in child courses and verify each separately.
$syscontext = context_system::instance();
if (!$roles = get_roles_with_capability('enrol/category:synchronised', CAP_ALLOW, $syscontext)) {
return;
}
$plugin = enrol_get_plugin('category');
$sql = "SELECT e.*
FROM {course} c
JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :courselevel AND ctx.path LIKE :match)
JOIN {enrol} e ON (e.courseid = c.id AND e.enrol = 'category')
JOIN {user_enrolments} ue ON (ue.enrolid = e.id AND ue.userid = :userid)";
$params = array('courselevel'=>CONTEXT_COURSE, 'match'=>$parentcontext->path.'/%', 'userid'=>$ra->userid);
$rs = $DB->get_recordset_sql($sql, $params);
list($roleids, $params) = $DB->get_in_or_equal(array_keys($roles), SQL_PARAMS_NAMED, 'r');
$params['userid'] = $ra->userid;
foreach ($rs as $instance) {
$coursecontext = context_course::instance($instance->courseid);
$contextids = $coursecontext->get_parent_context_ids();
array_pop($contextids); // Remove system context, we are interested in categories only.
list($contextids, $contextparams) = $DB->get_in_or_equal($contextids, SQL_PARAMS_NAMED, 'c');
$params = array_merge($params, $contextparams);
$sql = "SELECT ra.id
FROM {role_assignments} ra
WHERE ra.userid = :userid AND ra.contextid $contextids AND ra.roleid $roleids";
if (!$DB->record_exists_sql($sql, $params)) {
// User does not have any interesting role in any parent context, let's unenrol.
$plugin->unenrol_user($instance, $ra->userid);
}
}
$rs->close();
}
|
php
|
public static function role_unassigned(\core\event\role_unassigned $event) {
global $DB;
if (!enrol_is_enabled('category')) {
return;
}
$ra = new stdClass();
$ra->userid = $event->relateduserid;
$ra->contextid = $event->contextid;
// only category level roles are interesting
$parentcontext = context::instance_by_id($ra->contextid);
if ($parentcontext->contextlevel != CONTEXT_COURSECAT) {
return;
}
// Now this is going to be a bit slow, take all enrolments in child courses and verify each separately.
$syscontext = context_system::instance();
if (!$roles = get_roles_with_capability('enrol/category:synchronised', CAP_ALLOW, $syscontext)) {
return;
}
$plugin = enrol_get_plugin('category');
$sql = "SELECT e.*
FROM {course} c
JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :courselevel AND ctx.path LIKE :match)
JOIN {enrol} e ON (e.courseid = c.id AND e.enrol = 'category')
JOIN {user_enrolments} ue ON (ue.enrolid = e.id AND ue.userid = :userid)";
$params = array('courselevel'=>CONTEXT_COURSE, 'match'=>$parentcontext->path.'/%', 'userid'=>$ra->userid);
$rs = $DB->get_recordset_sql($sql, $params);
list($roleids, $params) = $DB->get_in_or_equal(array_keys($roles), SQL_PARAMS_NAMED, 'r');
$params['userid'] = $ra->userid;
foreach ($rs as $instance) {
$coursecontext = context_course::instance($instance->courseid);
$contextids = $coursecontext->get_parent_context_ids();
array_pop($contextids); // Remove system context, we are interested in categories only.
list($contextids, $contextparams) = $DB->get_in_or_equal($contextids, SQL_PARAMS_NAMED, 'c');
$params = array_merge($params, $contextparams);
$sql = "SELECT ra.id
FROM {role_assignments} ra
WHERE ra.userid = :userid AND ra.contextid $contextids AND ra.roleid $roleids";
if (!$DB->record_exists_sql($sql, $params)) {
// User does not have any interesting role in any parent context, let's unenrol.
$plugin->unenrol_user($instance, $ra->userid);
}
}
$rs->close();
}
|
[
"public",
"static",
"function",
"role_unassigned",
"(",
"\\",
"core",
"\\",
"event",
"\\",
"role_unassigned",
"$",
"event",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"!",
"enrol_is_enabled",
"(",
"'category'",
")",
")",
"{",
"return",
";",
"}",
"$",
"ra",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"ra",
"->",
"userid",
"=",
"$",
"event",
"->",
"relateduserid",
";",
"$",
"ra",
"->",
"contextid",
"=",
"$",
"event",
"->",
"contextid",
";",
"// only category level roles are interesting",
"$",
"parentcontext",
"=",
"context",
"::",
"instance_by_id",
"(",
"$",
"ra",
"->",
"contextid",
")",
";",
"if",
"(",
"$",
"parentcontext",
"->",
"contextlevel",
"!=",
"CONTEXT_COURSECAT",
")",
"{",
"return",
";",
"}",
"// Now this is going to be a bit slow, take all enrolments in child courses and verify each separately.",
"$",
"syscontext",
"=",
"context_system",
"::",
"instance",
"(",
")",
";",
"if",
"(",
"!",
"$",
"roles",
"=",
"get_roles_with_capability",
"(",
"'enrol/category:synchronised'",
",",
"CAP_ALLOW",
",",
"$",
"syscontext",
")",
")",
"{",
"return",
";",
"}",
"$",
"plugin",
"=",
"enrol_get_plugin",
"(",
"'category'",
")",
";",
"$",
"sql",
"=",
"\"SELECT e.*\n FROM {course} c\n JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :courselevel AND ctx.path LIKE :match)\n JOIN {enrol} e ON (e.courseid = c.id AND e.enrol = 'category')\n JOIN {user_enrolments} ue ON (ue.enrolid = e.id AND ue.userid = :userid)\"",
";",
"$",
"params",
"=",
"array",
"(",
"'courselevel'",
"=>",
"CONTEXT_COURSE",
",",
"'match'",
"=>",
"$",
"parentcontext",
"->",
"path",
".",
"'/%'",
",",
"'userid'",
"=>",
"$",
"ra",
"->",
"userid",
")",
";",
"$",
"rs",
"=",
"$",
"DB",
"->",
"get_recordset_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"list",
"(",
"$",
"roleids",
",",
"$",
"params",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"array_keys",
"(",
"$",
"roles",
")",
",",
"SQL_PARAMS_NAMED",
",",
"'r'",
")",
";",
"$",
"params",
"[",
"'userid'",
"]",
"=",
"$",
"ra",
"->",
"userid",
";",
"foreach",
"(",
"$",
"rs",
"as",
"$",
"instance",
")",
"{",
"$",
"coursecontext",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"instance",
"->",
"courseid",
")",
";",
"$",
"contextids",
"=",
"$",
"coursecontext",
"->",
"get_parent_context_ids",
"(",
")",
";",
"array_pop",
"(",
"$",
"contextids",
")",
";",
"// Remove system context, we are interested in categories only.",
"list",
"(",
"$",
"contextids",
",",
"$",
"contextparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"contextids",
",",
"SQL_PARAMS_NAMED",
",",
"'c'",
")",
";",
"$",
"params",
"=",
"array_merge",
"(",
"$",
"params",
",",
"$",
"contextparams",
")",
";",
"$",
"sql",
"=",
"\"SELECT ra.id\n FROM {role_assignments} ra\n WHERE ra.userid = :userid AND ra.contextid $contextids AND ra.roleid $roleids\"",
";",
"if",
"(",
"!",
"$",
"DB",
"->",
"record_exists_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
")",
"{",
"// User does not have any interesting role in any parent context, let's unenrol.",
"$",
"plugin",
"->",
"unenrol_user",
"(",
"$",
"instance",
",",
"$",
"ra",
"->",
"userid",
")",
";",
"}",
"}",
"$",
"rs",
"->",
"close",
"(",
")",
";",
"}"
] |
Triggered when user role is unassigned.
@param \core\event\role_unassigned $event
|
[
"Triggered",
"when",
"user",
"role",
"is",
"unassigned",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/category/classes/observer.php#L99-L152
|
218,014
|
moodle/moodle
|
admin/roles/classes/override_permissions_table_advanced.php
|
core_role_override_permissions_table_advanced.get_row_attributes
|
protected function get_row_attributes($capability) {
$rowattributes = parent::get_row_attributes($capability);
if ($this->permissions[$capability->name] !== 0) {
if (empty($rowattributes['class'])) {
$rowattributes['class'] = "overriddenpermission";
} else {
$rowattributes['class'] .= " overriddenpermission";
}
}
return $rowattributes;
}
|
php
|
protected function get_row_attributes($capability) {
$rowattributes = parent::get_row_attributes($capability);
if ($this->permissions[$capability->name] !== 0) {
if (empty($rowattributes['class'])) {
$rowattributes['class'] = "overriddenpermission";
} else {
$rowattributes['class'] .= " overriddenpermission";
}
}
return $rowattributes;
}
|
[
"protected",
"function",
"get_row_attributes",
"(",
"$",
"capability",
")",
"{",
"$",
"rowattributes",
"=",
"parent",
"::",
"get_row_attributes",
"(",
"$",
"capability",
")",
";",
"if",
"(",
"$",
"this",
"->",
"permissions",
"[",
"$",
"capability",
"->",
"name",
"]",
"!==",
"0",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"rowattributes",
"[",
"'class'",
"]",
")",
")",
"{",
"$",
"rowattributes",
"[",
"'class'",
"]",
"=",
"\"overriddenpermission\"",
";",
"}",
"else",
"{",
"$",
"rowattributes",
"[",
"'class'",
"]",
".=",
"\" overriddenpermission\"",
";",
"}",
"}",
"return",
"$",
"rowattributes",
";",
"}"
] |
This method adds an additional class to a row if capability is other than inherited.
@param stdClass $capability
@return array
|
[
"This",
"method",
"adds",
"an",
"additional",
"class",
"to",
"a",
"row",
"if",
"capability",
"is",
"other",
"than",
"inherited",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/roles/classes/override_permissions_table_advanced.php#L65-L75
|
218,015
|
moodle/moodle
|
lib/spout/src/Spout/Reader/ODS/Helper/CellValueFormatter.php
|
CellValueFormatter.formatStringCellValue
|
protected function formatStringCellValue($node)
{
$pNodeValues = [];
$pNodes = $node->getElementsByTagName(self::XML_NODE_P);
foreach ($pNodes as $pNode) {
$currentPValue = '';
foreach ($pNode->childNodes as $childNode) {
if ($childNode instanceof \DOMText) {
$currentPValue .= $childNode->nodeValue;
} else if ($childNode->nodeName === self::XML_NODE_S) {
$spaceAttribute = $childNode->getAttribute(self::XML_ATTRIBUTE_C);
$numSpaces = (!empty($spaceAttribute)) ? intval($spaceAttribute) : 1;
$currentPValue .= str_repeat(' ', $numSpaces);
} else if ($childNode->nodeName === self::XML_NODE_A || $childNode->nodeName === self::XML_NODE_SPAN) {
$currentPValue .= $childNode->nodeValue;
}
}
$pNodeValues[] = $currentPValue;
}
$escapedCellValue = implode("\n", $pNodeValues);
$cellValue = $this->escaper->unescape($escapedCellValue);
return $cellValue;
}
|
php
|
protected function formatStringCellValue($node)
{
$pNodeValues = [];
$pNodes = $node->getElementsByTagName(self::XML_NODE_P);
foreach ($pNodes as $pNode) {
$currentPValue = '';
foreach ($pNode->childNodes as $childNode) {
if ($childNode instanceof \DOMText) {
$currentPValue .= $childNode->nodeValue;
} else if ($childNode->nodeName === self::XML_NODE_S) {
$spaceAttribute = $childNode->getAttribute(self::XML_ATTRIBUTE_C);
$numSpaces = (!empty($spaceAttribute)) ? intval($spaceAttribute) : 1;
$currentPValue .= str_repeat(' ', $numSpaces);
} else if ($childNode->nodeName === self::XML_NODE_A || $childNode->nodeName === self::XML_NODE_SPAN) {
$currentPValue .= $childNode->nodeValue;
}
}
$pNodeValues[] = $currentPValue;
}
$escapedCellValue = implode("\n", $pNodeValues);
$cellValue = $this->escaper->unescape($escapedCellValue);
return $cellValue;
}
|
[
"protected",
"function",
"formatStringCellValue",
"(",
"$",
"node",
")",
"{",
"$",
"pNodeValues",
"=",
"[",
"]",
";",
"$",
"pNodes",
"=",
"$",
"node",
"->",
"getElementsByTagName",
"(",
"self",
"::",
"XML_NODE_P",
")",
";",
"foreach",
"(",
"$",
"pNodes",
"as",
"$",
"pNode",
")",
"{",
"$",
"currentPValue",
"=",
"''",
";",
"foreach",
"(",
"$",
"pNode",
"->",
"childNodes",
"as",
"$",
"childNode",
")",
"{",
"if",
"(",
"$",
"childNode",
"instanceof",
"\\",
"DOMText",
")",
"{",
"$",
"currentPValue",
".=",
"$",
"childNode",
"->",
"nodeValue",
";",
"}",
"else",
"if",
"(",
"$",
"childNode",
"->",
"nodeName",
"===",
"self",
"::",
"XML_NODE_S",
")",
"{",
"$",
"spaceAttribute",
"=",
"$",
"childNode",
"->",
"getAttribute",
"(",
"self",
"::",
"XML_ATTRIBUTE_C",
")",
";",
"$",
"numSpaces",
"=",
"(",
"!",
"empty",
"(",
"$",
"spaceAttribute",
")",
")",
"?",
"intval",
"(",
"$",
"spaceAttribute",
")",
":",
"1",
";",
"$",
"currentPValue",
".=",
"str_repeat",
"(",
"' '",
",",
"$",
"numSpaces",
")",
";",
"}",
"else",
"if",
"(",
"$",
"childNode",
"->",
"nodeName",
"===",
"self",
"::",
"XML_NODE_A",
"||",
"$",
"childNode",
"->",
"nodeName",
"===",
"self",
"::",
"XML_NODE_SPAN",
")",
"{",
"$",
"currentPValue",
".=",
"$",
"childNode",
"->",
"nodeValue",
";",
"}",
"}",
"$",
"pNodeValues",
"[",
"]",
"=",
"$",
"currentPValue",
";",
"}",
"$",
"escapedCellValue",
"=",
"implode",
"(",
"\"\\n\"",
",",
"$",
"pNodeValues",
")",
";",
"$",
"cellValue",
"=",
"$",
"this",
"->",
"escaper",
"->",
"unescape",
"(",
"$",
"escapedCellValue",
")",
";",
"return",
"$",
"cellValue",
";",
"}"
] |
Returns the cell String value.
@param \DOMNode $node
@return string The value associated with the cell
|
[
"Returns",
"the",
"cell",
"String",
"value",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Reader/ODS/Helper/CellValueFormatter.php#L93-L119
|
218,016
|
moodle/moodle
|
lib/spout/src/Spout/Reader/ODS/Helper/CellValueFormatter.php
|
CellValueFormatter.formatFloatCellValue
|
protected function formatFloatCellValue($node)
{
$nodeValue = $node->getAttribute(self::XML_ATTRIBUTE_VALUE);
$nodeIntValue = intval($nodeValue);
// The "==" is intentionally not a "===" because only the value matters, not the type
$cellValue = ($nodeIntValue == $nodeValue) ? $nodeIntValue : floatval($nodeValue);
return $cellValue;
}
|
php
|
protected function formatFloatCellValue($node)
{
$nodeValue = $node->getAttribute(self::XML_ATTRIBUTE_VALUE);
$nodeIntValue = intval($nodeValue);
// The "==" is intentionally not a "===" because only the value matters, not the type
$cellValue = ($nodeIntValue == $nodeValue) ? $nodeIntValue : floatval($nodeValue);
return $cellValue;
}
|
[
"protected",
"function",
"formatFloatCellValue",
"(",
"$",
"node",
")",
"{",
"$",
"nodeValue",
"=",
"$",
"node",
"->",
"getAttribute",
"(",
"self",
"::",
"XML_ATTRIBUTE_VALUE",
")",
";",
"$",
"nodeIntValue",
"=",
"intval",
"(",
"$",
"nodeValue",
")",
";",
"// The \"==\" is intentionally not a \"===\" because only the value matters, not the type",
"$",
"cellValue",
"=",
"(",
"$",
"nodeIntValue",
"==",
"$",
"nodeValue",
")",
"?",
"$",
"nodeIntValue",
":",
"floatval",
"(",
"$",
"nodeValue",
")",
";",
"return",
"$",
"cellValue",
";",
"}"
] |
Returns the cell Numeric value from the given node.
@param \DOMNode $node
@return int|float The value associated with the cell
|
[
"Returns",
"the",
"cell",
"Numeric",
"value",
"from",
"the",
"given",
"node",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Reader/ODS/Helper/CellValueFormatter.php#L127-L134
|
218,017
|
moodle/moodle
|
lib/spout/src/Spout/Reader/ODS/Helper/CellValueFormatter.php
|
CellValueFormatter.formatBooleanCellValue
|
protected function formatBooleanCellValue($node)
{
$nodeValue = $node->getAttribute(self::XML_ATTRIBUTE_BOOLEAN_VALUE);
// !! is similar to boolval()
$cellValue = !!$nodeValue;
return $cellValue;
}
|
php
|
protected function formatBooleanCellValue($node)
{
$nodeValue = $node->getAttribute(self::XML_ATTRIBUTE_BOOLEAN_VALUE);
// !! is similar to boolval()
$cellValue = !!$nodeValue;
return $cellValue;
}
|
[
"protected",
"function",
"formatBooleanCellValue",
"(",
"$",
"node",
")",
"{",
"$",
"nodeValue",
"=",
"$",
"node",
"->",
"getAttribute",
"(",
"self",
"::",
"XML_ATTRIBUTE_BOOLEAN_VALUE",
")",
";",
"// !! is similar to boolval()",
"$",
"cellValue",
"=",
"!",
"!",
"$",
"nodeValue",
";",
"return",
"$",
"cellValue",
";",
"}"
] |
Returns the cell Boolean value from the given node.
@param \DOMNode $node
@return bool The value associated with the cell
|
[
"Returns",
"the",
"cell",
"Boolean",
"value",
"from",
"the",
"given",
"node",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Reader/ODS/Helper/CellValueFormatter.php#L142-L148
|
218,018
|
moodle/moodle
|
lib/spout/src/Spout/Reader/ODS/Helper/CellValueFormatter.php
|
CellValueFormatter.formatDateCellValue
|
protected function formatDateCellValue($node)
{
// The XML node looks like this:
// <table:table-cell calcext:value-type="date" office:date-value="2016-05-19T16:39:00" office:value-type="date">
// <text:p>05/19/16 04:39 PM</text:p>
// </table:table-cell>
if ($this->shouldFormatDates) {
// The date is already formatted in the "p" tag
$nodeWithValueAlreadyFormatted = $node->getElementsByTagName(self::XML_NODE_P)->item(0);
return $nodeWithValueAlreadyFormatted->nodeValue;
} else {
// otherwise, get it from the "date-value" attribute
try {
$nodeValue = $node->getAttribute(self::XML_ATTRIBUTE_DATE_VALUE);
return new \DateTime($nodeValue);
} catch (\Exception $e) {
return null;
}
}
}
|
php
|
protected function formatDateCellValue($node)
{
// The XML node looks like this:
// <table:table-cell calcext:value-type="date" office:date-value="2016-05-19T16:39:00" office:value-type="date">
// <text:p>05/19/16 04:39 PM</text:p>
// </table:table-cell>
if ($this->shouldFormatDates) {
// The date is already formatted in the "p" tag
$nodeWithValueAlreadyFormatted = $node->getElementsByTagName(self::XML_NODE_P)->item(0);
return $nodeWithValueAlreadyFormatted->nodeValue;
} else {
// otherwise, get it from the "date-value" attribute
try {
$nodeValue = $node->getAttribute(self::XML_ATTRIBUTE_DATE_VALUE);
return new \DateTime($nodeValue);
} catch (\Exception $e) {
return null;
}
}
}
|
[
"protected",
"function",
"formatDateCellValue",
"(",
"$",
"node",
")",
"{",
"// The XML node looks like this:",
"// <table:table-cell calcext:value-type=\"date\" office:date-value=\"2016-05-19T16:39:00\" office:value-type=\"date\">",
"// <text:p>05/19/16 04:39 PM</text:p>",
"// </table:table-cell>",
"if",
"(",
"$",
"this",
"->",
"shouldFormatDates",
")",
"{",
"// The date is already formatted in the \"p\" tag",
"$",
"nodeWithValueAlreadyFormatted",
"=",
"$",
"node",
"->",
"getElementsByTagName",
"(",
"self",
"::",
"XML_NODE_P",
")",
"->",
"item",
"(",
"0",
")",
";",
"return",
"$",
"nodeWithValueAlreadyFormatted",
"->",
"nodeValue",
";",
"}",
"else",
"{",
"// otherwise, get it from the \"date-value\" attribute",
"try",
"{",
"$",
"nodeValue",
"=",
"$",
"node",
"->",
"getAttribute",
"(",
"self",
"::",
"XML_ATTRIBUTE_DATE_VALUE",
")",
";",
"return",
"new",
"\\",
"DateTime",
"(",
"$",
"nodeValue",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"null",
";",
"}",
"}",
"}"
] |
Returns the cell Date value from the given node.
@param \DOMNode $node
@return \DateTime|string|null The value associated with the cell or NULL if invalid date value
|
[
"Returns",
"the",
"cell",
"Date",
"value",
"from",
"the",
"given",
"node",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Reader/ODS/Helper/CellValueFormatter.php#L156-L176
|
218,019
|
moodle/moodle
|
lib/spout/src/Spout/Reader/ODS/Helper/CellValueFormatter.php
|
CellValueFormatter.formatTimeCellValue
|
protected function formatTimeCellValue($node)
{
// The XML node looks like this:
// <table:table-cell calcext:value-type="time" office:time-value="PT13H24M00S" office:value-type="time">
// <text:p>01:24:00 PM</text:p>
// </table:table-cell>
if ($this->shouldFormatDates) {
// The date is already formatted in the "p" tag
$nodeWithValueAlreadyFormatted = $node->getElementsByTagName(self::XML_NODE_P)->item(0);
return $nodeWithValueAlreadyFormatted->nodeValue;
} else {
// otherwise, get it from the "time-value" attribute
try {
$nodeValue = $node->getAttribute(self::XML_ATTRIBUTE_TIME_VALUE);
return new \DateInterval($nodeValue);
} catch (\Exception $e) {
return null;
}
}
}
|
php
|
protected function formatTimeCellValue($node)
{
// The XML node looks like this:
// <table:table-cell calcext:value-type="time" office:time-value="PT13H24M00S" office:value-type="time">
// <text:p>01:24:00 PM</text:p>
// </table:table-cell>
if ($this->shouldFormatDates) {
// The date is already formatted in the "p" tag
$nodeWithValueAlreadyFormatted = $node->getElementsByTagName(self::XML_NODE_P)->item(0);
return $nodeWithValueAlreadyFormatted->nodeValue;
} else {
// otherwise, get it from the "time-value" attribute
try {
$nodeValue = $node->getAttribute(self::XML_ATTRIBUTE_TIME_VALUE);
return new \DateInterval($nodeValue);
} catch (\Exception $e) {
return null;
}
}
}
|
[
"protected",
"function",
"formatTimeCellValue",
"(",
"$",
"node",
")",
"{",
"// The XML node looks like this:",
"// <table:table-cell calcext:value-type=\"time\" office:time-value=\"PT13H24M00S\" office:value-type=\"time\">",
"// <text:p>01:24:00 PM</text:p>",
"// </table:table-cell>",
"if",
"(",
"$",
"this",
"->",
"shouldFormatDates",
")",
"{",
"// The date is already formatted in the \"p\" tag",
"$",
"nodeWithValueAlreadyFormatted",
"=",
"$",
"node",
"->",
"getElementsByTagName",
"(",
"self",
"::",
"XML_NODE_P",
")",
"->",
"item",
"(",
"0",
")",
";",
"return",
"$",
"nodeWithValueAlreadyFormatted",
"->",
"nodeValue",
";",
"}",
"else",
"{",
"// otherwise, get it from the \"time-value\" attribute",
"try",
"{",
"$",
"nodeValue",
"=",
"$",
"node",
"->",
"getAttribute",
"(",
"self",
"::",
"XML_ATTRIBUTE_TIME_VALUE",
")",
";",
"return",
"new",
"\\",
"DateInterval",
"(",
"$",
"nodeValue",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"null",
";",
"}",
"}",
"}"
] |
Returns the cell Time value from the given node.
@param \DOMNode $node
@return \DateInterval|string|null The value associated with the cell or NULL if invalid time value
|
[
"Returns",
"the",
"cell",
"Time",
"value",
"from",
"the",
"given",
"node",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Reader/ODS/Helper/CellValueFormatter.php#L184-L204
|
218,020
|
moodle/moodle
|
lib/spout/src/Spout/Reader/ODS/Helper/CellValueFormatter.php
|
CellValueFormatter.formatCurrencyCellValue
|
protected function formatCurrencyCellValue($node)
{
$value = $node->getAttribute(self::XML_ATTRIBUTE_VALUE);
$currency = $node->getAttribute(self::XML_ATTRIBUTE_CURRENCY);
return "$value $currency";
}
|
php
|
protected function formatCurrencyCellValue($node)
{
$value = $node->getAttribute(self::XML_ATTRIBUTE_VALUE);
$currency = $node->getAttribute(self::XML_ATTRIBUTE_CURRENCY);
return "$value $currency";
}
|
[
"protected",
"function",
"formatCurrencyCellValue",
"(",
"$",
"node",
")",
"{",
"$",
"value",
"=",
"$",
"node",
"->",
"getAttribute",
"(",
"self",
"::",
"XML_ATTRIBUTE_VALUE",
")",
";",
"$",
"currency",
"=",
"$",
"node",
"->",
"getAttribute",
"(",
"self",
"::",
"XML_ATTRIBUTE_CURRENCY",
")",
";",
"return",
"\"$value $currency\"",
";",
"}"
] |
Returns the cell Currency value from the given node.
@param \DOMNode $node
@return string The value associated with the cell (e.g. "100 USD" or "9.99 EUR")
|
[
"Returns",
"the",
"cell",
"Currency",
"value",
"from",
"the",
"given",
"node",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Reader/ODS/Helper/CellValueFormatter.php#L212-L218
|
218,021
|
moodle/moodle
|
lib/spout/src/Spout/Reader/CSV/RowIterator.php
|
RowIterator.rewindAndSkipBom
|
protected function rewindAndSkipBom()
{
$byteOffsetToSkipBom = $this->encodingHelper->getBytesOffsetToSkipBOM($this->filePointer, $this->encoding);
// sets the cursor after the BOM (0 means no BOM, so rewind it)
$this->globalFunctionsHelper->fseek($this->filePointer, $byteOffsetToSkipBom);
}
|
php
|
protected function rewindAndSkipBom()
{
$byteOffsetToSkipBom = $this->encodingHelper->getBytesOffsetToSkipBOM($this->filePointer, $this->encoding);
// sets the cursor after the BOM (0 means no BOM, so rewind it)
$this->globalFunctionsHelper->fseek($this->filePointer, $byteOffsetToSkipBom);
}
|
[
"protected",
"function",
"rewindAndSkipBom",
"(",
")",
"{",
"$",
"byteOffsetToSkipBom",
"=",
"$",
"this",
"->",
"encodingHelper",
"->",
"getBytesOffsetToSkipBOM",
"(",
"$",
"this",
"->",
"filePointer",
",",
"$",
"this",
"->",
"encoding",
")",
";",
"// sets the cursor after the BOM (0 means no BOM, so rewind it)",
"$",
"this",
"->",
"globalFunctionsHelper",
"->",
"fseek",
"(",
"$",
"this",
"->",
"filePointer",
",",
"$",
"byteOffsetToSkipBom",
")",
";",
"}"
] |
This rewinds and skips the BOM if inserted at the beginning of the file
by moving the file pointer after it, so that it is not read.
@return void
|
[
"This",
"rewinds",
"and",
"skips",
"the",
"BOM",
"if",
"inserted",
"at",
"the",
"beginning",
"of",
"the",
"file",
"by",
"moving",
"the",
"file",
"pointer",
"after",
"it",
"so",
"that",
"it",
"is",
"not",
"read",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Reader/CSV/RowIterator.php#L97-L103
|
218,022
|
moodle/moodle
|
lib/spout/src/Spout/Reader/CSV/RowIterator.php
|
RowIterator.getEncodedEOLDelimiter
|
protected function getEncodedEOLDelimiter()
{
if (!isset($this->encodedEOLDelimiter)) {
$this->encodedEOLDelimiter = $this->encodingHelper->attemptConversionFromUTF8($this->inputEOLDelimiter, $this->encoding);
}
return $this->encodedEOLDelimiter;
}
|
php
|
protected function getEncodedEOLDelimiter()
{
if (!isset($this->encodedEOLDelimiter)) {
$this->encodedEOLDelimiter = $this->encodingHelper->attemptConversionFromUTF8($this->inputEOLDelimiter, $this->encoding);
}
return $this->encodedEOLDelimiter;
}
|
[
"protected",
"function",
"getEncodedEOLDelimiter",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"encodedEOLDelimiter",
")",
")",
"{",
"$",
"this",
"->",
"encodedEOLDelimiter",
"=",
"$",
"this",
"->",
"encodingHelper",
"->",
"attemptConversionFromUTF8",
"(",
"$",
"this",
"->",
"inputEOLDelimiter",
",",
"$",
"this",
"->",
"encoding",
")",
";",
"}",
"return",
"$",
"this",
"->",
"encodedEOLDelimiter",
";",
"}"
] |
Returns the end of line delimiter, encoded using the same encoding as the CSV.
The return value is cached.
@return string
|
[
"Returns",
"the",
"end",
"of",
"line",
"delimiter",
"encoded",
"using",
"the",
"same",
"encoding",
"as",
"the",
"CSV",
".",
"The",
"return",
"value",
"is",
"cached",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Reader/CSV/RowIterator.php#L211-L218
|
218,023
|
moodle/moodle
|
admin/tool/policy/classes/output/acceptances_filter.php
|
acceptances_filter.add_filter
|
protected function add_filter($key, $value, $allowmultiple = false) {
if ($allowmultiple || empty($this->get_filter_values($key))) {
$this->filtersapplied[] = [$key, $value];
}
}
|
php
|
protected function add_filter($key, $value, $allowmultiple = false) {
if ($allowmultiple || empty($this->get_filter_values($key))) {
$this->filtersapplied[] = [$key, $value];
}
}
|
[
"protected",
"function",
"add_filter",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"allowmultiple",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"allowmultiple",
"||",
"empty",
"(",
"$",
"this",
"->",
"get_filter_values",
"(",
"$",
"key",
")",
")",
")",
"{",
"$",
"this",
"->",
"filtersapplied",
"[",
"]",
"=",
"[",
"$",
"key",
",",
"$",
"value",
"]",
";",
"}",
"}"
] |
Adds an applied filter
@param mixed $key
@param mixed $value
@param bool $allowmultiple
|
[
"Adds",
"an",
"applied",
"filter"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/output/acceptances_filter.php#L128-L132
|
218,024
|
moodle/moodle
|
admin/tool/policy/classes/output/acceptances_filter.php
|
acceptances_filter.get_filter_values
|
protected function get_filter_values($filtername) {
$values = [];
foreach ($this->filtersapplied as $filter) {
if ($filter[0] == $filtername) {
$values[] = $filter[1];
}
}
return $values;
}
|
php
|
protected function get_filter_values($filtername) {
$values = [];
foreach ($this->filtersapplied as $filter) {
if ($filter[0] == $filtername) {
$values[] = $filter[1];
}
}
return $values;
}
|
[
"protected",
"function",
"get_filter_values",
"(",
"$",
"filtername",
")",
"{",
"$",
"values",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"filtersapplied",
"as",
"$",
"filter",
")",
"{",
"if",
"(",
"$",
"filter",
"[",
"0",
"]",
"==",
"$",
"filtername",
")",
"{",
"$",
"values",
"[",
"]",
"=",
"$",
"filter",
"[",
"1",
"]",
";",
"}",
"}",
"return",
"$",
"values",
";",
"}"
] |
Get all values of the applied filter
@param string $filtername
@return array
|
[
"Get",
"all",
"values",
"of",
"the",
"applied",
"filter"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/output/acceptances_filter.php#L194-L202
|
218,025
|
moodle/moodle
|
admin/tool/policy/classes/output/acceptances_filter.php
|
acceptances_filter.get_filter_value
|
protected function get_filter_value($filtername, $default = null) {
if ($values = $this->get_filter_values($filtername)) {
$value = reset($values);
return $value;
}
return $default;
}
|
php
|
protected function get_filter_value($filtername, $default = null) {
if ($values = $this->get_filter_values($filtername)) {
$value = reset($values);
return $value;
}
return $default;
}
|
[
"protected",
"function",
"get_filter_value",
"(",
"$",
"filtername",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"values",
"=",
"$",
"this",
"->",
"get_filter_values",
"(",
"$",
"filtername",
")",
")",
"{",
"$",
"value",
"=",
"reset",
"(",
"$",
"values",
")",
";",
"return",
"$",
"value",
";",
"}",
"return",
"$",
"default",
";",
"}"
] |
Get one value of the applied filter
@param string $filtername
@param string $default
@return mixed
|
[
"Get",
"one",
"value",
"of",
"the",
"applied",
"filter"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/output/acceptances_filter.php#L211-L217
|
218,026
|
moodle/moodle
|
admin/tool/policy/classes/output/acceptances_filter.php
|
acceptances_filter.get_versions
|
public function get_versions() {
if ($this->versions === null) {
$policyid = $this->get_policy_id_filter();
$versionid = $this->get_version_id_filter();
$this->versions = [];
foreach ($this->get_avaliable_policies() as $policy) {
if ($policyid && $policy->id != $policyid) {
continue;
}
if ($versionid) {
if (array_key_exists($versionid, $policy->versions)) {
$this->versions[$versionid] = $policy->versions[$versionid];
break; // No need to keep searching.
}
} else if ($policy->currentversion) {
$this->versions[$policy->currentversion->id] = $policy->currentversion;
}
}
}
return $this->versions;
}
|
php
|
public function get_versions() {
if ($this->versions === null) {
$policyid = $this->get_policy_id_filter();
$versionid = $this->get_version_id_filter();
$this->versions = [];
foreach ($this->get_avaliable_policies() as $policy) {
if ($policyid && $policy->id != $policyid) {
continue;
}
if ($versionid) {
if (array_key_exists($versionid, $policy->versions)) {
$this->versions[$versionid] = $policy->versions[$versionid];
break; // No need to keep searching.
}
} else if ($policy->currentversion) {
$this->versions[$policy->currentversion->id] = $policy->currentversion;
}
}
}
return $this->versions;
}
|
[
"public",
"function",
"get_versions",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"versions",
"===",
"null",
")",
"{",
"$",
"policyid",
"=",
"$",
"this",
"->",
"get_policy_id_filter",
"(",
")",
";",
"$",
"versionid",
"=",
"$",
"this",
"->",
"get_version_id_filter",
"(",
")",
";",
"$",
"this",
"->",
"versions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"get_avaliable_policies",
"(",
")",
"as",
"$",
"policy",
")",
"{",
"if",
"(",
"$",
"policyid",
"&&",
"$",
"policy",
"->",
"id",
"!=",
"$",
"policyid",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"versionid",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"versionid",
",",
"$",
"policy",
"->",
"versions",
")",
")",
"{",
"$",
"this",
"->",
"versions",
"[",
"$",
"versionid",
"]",
"=",
"$",
"policy",
"->",
"versions",
"[",
"$",
"versionid",
"]",
";",
"break",
";",
"// No need to keep searching.",
"}",
"}",
"else",
"if",
"(",
"$",
"policy",
"->",
"currentversion",
")",
"{",
"$",
"this",
"->",
"versions",
"[",
"$",
"policy",
"->",
"currentversion",
"->",
"id",
"]",
"=",
"$",
"policy",
"->",
"currentversion",
";",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"versions",
";",
"}"
] |
List of policies that match current filters
@return array of versions to display indexed by versionid
|
[
"List",
"of",
"policies",
"that",
"match",
"current",
"filters"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/output/acceptances_filter.php#L253-L273
|
218,027
|
moodle/moodle
|
admin/tool/policy/classes/output/acceptances_filter.php
|
acceptances_filter.get_single_version
|
public function get_single_version() {
if ($this->get_version_id_filter() || $this->get_policy_id_filter()) {
$versions = $this->get_versions();
return reset($versions);
}
return null;
}
|
php
|
public function get_single_version() {
if ($this->get_version_id_filter() || $this->get_policy_id_filter()) {
$versions = $this->get_versions();
return reset($versions);
}
return null;
}
|
[
"public",
"function",
"get_single_version",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"get_version_id_filter",
"(",
")",
"||",
"$",
"this",
"->",
"get_policy_id_filter",
"(",
")",
")",
"{",
"$",
"versions",
"=",
"$",
"this",
"->",
"get_versions",
"(",
")",
";",
"return",
"reset",
"(",
"$",
"versions",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
If policyid or versionid is specified return one single policy that needs to be shown
If neither policyid nor versionid is specified this method returns null.
When versionid is specified this method will always return an object (this is validated in {@link self::validate_ids()}
When only policyid is specified this method either returns the current version of the policy or null if there is
no current version (for example, it is an old policy).
@return mixed|null
|
[
"If",
"policyid",
"or",
"versionid",
"is",
"specified",
"return",
"one",
"single",
"policy",
"that",
"needs",
"to",
"be",
"shown"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/output/acceptances_filter.php#L304-L310
|
218,028
|
moodle/moodle
|
admin/tool/policy/classes/output/acceptances_filter.php
|
acceptances_filter.get_url
|
public function get_url() {
$urlparams = [];
if ($policyid = $this->get_policy_id_filter()) {
$urlparams['policyid'] = $policyid;
}
if ($versionid = $this->get_version_id_filter()) {
$urlparams['versionid'] = $versionid;
}
$i = 0;
foreach ($this->filtersapplied as $filter) {
if ($filter[0] != self::FILTER_POLICYID && $filter[0] != self::FILTER_VERSIONID) {
if ($filter[0] == self::FILTER_SEARCH_STRING) {
$urlparams['unified-filters['.($i++).']'] = $filter[1];
} else {
$urlparams['unified-filters['.($i++).']'] = join(':', $filter);
}
}
}
return new \moodle_url('/admin/tool/policy/acceptances.php', $urlparams);
}
|
php
|
public function get_url() {
$urlparams = [];
if ($policyid = $this->get_policy_id_filter()) {
$urlparams['policyid'] = $policyid;
}
if ($versionid = $this->get_version_id_filter()) {
$urlparams['versionid'] = $versionid;
}
$i = 0;
foreach ($this->filtersapplied as $filter) {
if ($filter[0] != self::FILTER_POLICYID && $filter[0] != self::FILTER_VERSIONID) {
if ($filter[0] == self::FILTER_SEARCH_STRING) {
$urlparams['unified-filters['.($i++).']'] = $filter[1];
} else {
$urlparams['unified-filters['.($i++).']'] = join(':', $filter);
}
}
}
return new \moodle_url('/admin/tool/policy/acceptances.php', $urlparams);
}
|
[
"public",
"function",
"get_url",
"(",
")",
"{",
"$",
"urlparams",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"policyid",
"=",
"$",
"this",
"->",
"get_policy_id_filter",
"(",
")",
")",
"{",
"$",
"urlparams",
"[",
"'policyid'",
"]",
"=",
"$",
"policyid",
";",
"}",
"if",
"(",
"$",
"versionid",
"=",
"$",
"this",
"->",
"get_version_id_filter",
"(",
")",
")",
"{",
"$",
"urlparams",
"[",
"'versionid'",
"]",
"=",
"$",
"versionid",
";",
"}",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"filtersapplied",
"as",
"$",
"filter",
")",
"{",
"if",
"(",
"$",
"filter",
"[",
"0",
"]",
"!=",
"self",
"::",
"FILTER_POLICYID",
"&&",
"$",
"filter",
"[",
"0",
"]",
"!=",
"self",
"::",
"FILTER_VERSIONID",
")",
"{",
"if",
"(",
"$",
"filter",
"[",
"0",
"]",
"==",
"self",
"::",
"FILTER_SEARCH_STRING",
")",
"{",
"$",
"urlparams",
"[",
"'unified-filters['",
".",
"(",
"$",
"i",
"++",
")",
".",
"']'",
"]",
"=",
"$",
"filter",
"[",
"1",
"]",
";",
"}",
"else",
"{",
"$",
"urlparams",
"[",
"'unified-filters['",
".",
"(",
"$",
"i",
"++",
")",
".",
"']'",
"]",
"=",
"join",
"(",
"':'",
",",
"$",
"filter",
")",
";",
"}",
"}",
"}",
"return",
"new",
"\\",
"moodle_url",
"(",
"'/admin/tool/policy/acceptances.php'",
",",
"$",
"urlparams",
")",
";",
"}"
] |
Returns URL of the acceptances page with all current filters applied
@return \moodle_url
|
[
"Returns",
"URL",
"of",
"the",
"acceptances",
"page",
"with",
"all",
"current",
"filters",
"applied"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/output/acceptances_filter.php#L317-L336
|
218,029
|
moodle/moodle
|
admin/tool/policy/classes/output/acceptances_filter.php
|
acceptances_filter.get_version_option_for_filter
|
protected function get_version_option_for_filter($version) {
if ($version->status == policy_version::STATUS_ACTIVE) {
$a = (object)[
'name' => format_string($version->revision),
'status' => get_string('status'.policy_version::STATUS_ACTIVE, 'tool_policy'),
];
return get_string('filterrevisionstatus', 'tool_policy', $a);
} else {
return get_string('filterrevision', 'tool_policy', $version->revision);
}
}
|
php
|
protected function get_version_option_for_filter($version) {
if ($version->status == policy_version::STATUS_ACTIVE) {
$a = (object)[
'name' => format_string($version->revision),
'status' => get_string('status'.policy_version::STATUS_ACTIVE, 'tool_policy'),
];
return get_string('filterrevisionstatus', 'tool_policy', $a);
} else {
return get_string('filterrevision', 'tool_policy', $version->revision);
}
}
|
[
"protected",
"function",
"get_version_option_for_filter",
"(",
"$",
"version",
")",
"{",
"if",
"(",
"$",
"version",
"->",
"status",
"==",
"policy_version",
"::",
"STATUS_ACTIVE",
")",
"{",
"$",
"a",
"=",
"(",
"object",
")",
"[",
"'name'",
"=>",
"format_string",
"(",
"$",
"version",
"->",
"revision",
")",
",",
"'status'",
"=>",
"get_string",
"(",
"'status'",
".",
"policy_version",
"::",
"STATUS_ACTIVE",
",",
"'tool_policy'",
")",
",",
"]",
";",
"return",
"get_string",
"(",
"'filterrevisionstatus'",
",",
"'tool_policy'",
",",
"$",
"a",
")",
";",
"}",
"else",
"{",
"return",
"get_string",
"(",
"'filterrevision'",
",",
"'tool_policy'",
",",
"$",
"version",
"->",
"revision",
")",
";",
"}",
"}"
] |
Creates an option name for the smart select for the version
@param \stdClass $version
@return string
|
[
"Creates",
"an",
"option",
"name",
"for",
"the",
"smart",
"select",
"for",
"the",
"version"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/output/acceptances_filter.php#L344-L354
|
218,030
|
moodle/moodle
|
customfield/classes/output/renderer.php
|
renderer.render_management
|
protected function render_management(\core_customfield\output\management $list) {
$context = $list->export_for_template($this);
return $this->render_from_template('core_customfield/list', $context);
}
|
php
|
protected function render_management(\core_customfield\output\management $list) {
$context = $list->export_for_template($this);
return $this->render_from_template('core_customfield/list', $context);
}
|
[
"protected",
"function",
"render_management",
"(",
"\\",
"core_customfield",
"\\",
"output",
"\\",
"management",
"$",
"list",
")",
"{",
"$",
"context",
"=",
"$",
"list",
"->",
"export_for_template",
"(",
"$",
"this",
")",
";",
"return",
"$",
"this",
"->",
"render_from_template",
"(",
"'core_customfield/list'",
",",
"$",
"context",
")",
";",
"}"
] |
Render custom field management interface.
@param \core_customfield\output\management $list
@return string HTML
|
[
"Render",
"custom",
"field",
"management",
"interface",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/output/renderer.php#L46-L50
|
218,031
|
moodle/moodle
|
customfield/classes/output/renderer.php
|
renderer.render_field_data
|
protected function render_field_data(\core_customfield\output\field_data $field) {
$context = $field->export_for_template($this);
return $this->render_from_template('core_customfield/field_data', $context);
}
|
php
|
protected function render_field_data(\core_customfield\output\field_data $field) {
$context = $field->export_for_template($this);
return $this->render_from_template('core_customfield/field_data', $context);
}
|
[
"protected",
"function",
"render_field_data",
"(",
"\\",
"core_customfield",
"\\",
"output",
"\\",
"field_data",
"$",
"field",
")",
"{",
"$",
"context",
"=",
"$",
"field",
"->",
"export_for_template",
"(",
"$",
"this",
")",
";",
"return",
"$",
"this",
"->",
"render_from_template",
"(",
"'core_customfield/field_data'",
",",
"$",
"context",
")",
";",
"}"
] |
Render single custom field value
@param \core_customfield\output\field_data $field
@return string HTML
|
[
"Render",
"single",
"custom",
"field",
"value"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/output/renderer.php#L58-L61
|
218,032
|
moodle/moodle
|
search/classes/document_factory.php
|
document_factory.instance
|
public static function instance($itemid, $componentname, $areaname, $engine = false) {
if ($engine === false) {
$search = \core_search\manager::instance();
$engine = $search->get_engine();
}
$pluginname = $engine->get_plugin_name();
if (!empty(self::$docclassnames[$pluginname])) {
return new self::$docclassnames[$pluginname]($itemid, $componentname, $areaname);
}
self::$docclassnames[$pluginname] = $engine->get_document_classname();
return new self::$docclassnames[$pluginname]($itemid, $componentname, $areaname);
}
|
php
|
public static function instance($itemid, $componentname, $areaname, $engine = false) {
if ($engine === false) {
$search = \core_search\manager::instance();
$engine = $search->get_engine();
}
$pluginname = $engine->get_plugin_name();
if (!empty(self::$docclassnames[$pluginname])) {
return new self::$docclassnames[$pluginname]($itemid, $componentname, $areaname);
}
self::$docclassnames[$pluginname] = $engine->get_document_classname();
return new self::$docclassnames[$pluginname]($itemid, $componentname, $areaname);
}
|
[
"public",
"static",
"function",
"instance",
"(",
"$",
"itemid",
",",
"$",
"componentname",
",",
"$",
"areaname",
",",
"$",
"engine",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"engine",
"===",
"false",
")",
"{",
"$",
"search",
"=",
"\\",
"core_search",
"\\",
"manager",
"::",
"instance",
"(",
")",
";",
"$",
"engine",
"=",
"$",
"search",
"->",
"get_engine",
"(",
")",
";",
"}",
"$",
"pluginname",
"=",
"$",
"engine",
"->",
"get_plugin_name",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"self",
"::",
"$",
"docclassnames",
"[",
"$",
"pluginname",
"]",
")",
")",
"{",
"return",
"new",
"self",
"::",
"$",
"docclassnames",
"[",
"$",
"pluginname",
"]",
"(",
"$",
"itemid",
",",
"$",
"componentname",
",",
"$",
"areaname",
")",
";",
"}",
"self",
"::",
"$",
"docclassnames",
"[",
"$",
"pluginname",
"]",
"=",
"$",
"engine",
"->",
"get_document_classname",
"(",
")",
";",
"return",
"new",
"self",
"::",
"$",
"docclassnames",
"[",
"$",
"pluginname",
"]",
"(",
"$",
"itemid",
",",
"$",
"componentname",
",",
"$",
"areaname",
")",
";",
"}"
] |
Returns the appropiate document object as it depends on the engine.
@param int $itemid Document itemid
@param string $componentname Document component name
@param string $areaname Document area name
@param \core_search\engine $engine Falls back to the search engine in use.
@return \core_search\document Base document or the engine implementation.
|
[
"Returns",
"the",
"appropiate",
"document",
"object",
"as",
"it",
"depends",
"on",
"the",
"engine",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/document_factory.php#L58-L74
|
218,033
|
moodle/moodle
|
mod/book/classes/search/chapter.php
|
chapter.get_document
|
public function get_document($record, $options = array()) {
try {
$cm = $this->get_cm('book', $record->bookid, $record->courseid);
$context = \context_module::instance($cm->id);
} catch (\dml_missing_record_exception $ex) {
// Notify it as we run here as admin, we should see everything.
debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document, not all required data is available: ' .
$ex->getMessage(), DEBUG_DEVELOPER);
return false;
} catch (\dml_exception $ex) {
// Notify it as we run here as admin, we should see everything.
debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document: ' . $ex->getMessage(), DEBUG_DEVELOPER);
return false;
}
// Prepare associative array with data from DB.
$doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname);
$doc->set('title', content_to_text($record->title, false));
$doc->set('content', content_to_text($record->content, $record->contentformat));
$doc->set('contextid', $context->id);
$doc->set('courseid', $record->courseid);
$doc->set('owneruserid', \core_search\manager::NO_OWNER_ID);
$doc->set('modified', $record->timemodified);
// Check if this document should be considered new.
if (isset($options['lastindexedtime']) && ($options['lastindexedtime'] < $record->timecreated)) {
// If the document was created after the last index time, it must be new.
$doc->set_is_new(true);
}
return $doc;
}
|
php
|
public function get_document($record, $options = array()) {
try {
$cm = $this->get_cm('book', $record->bookid, $record->courseid);
$context = \context_module::instance($cm->id);
} catch (\dml_missing_record_exception $ex) {
// Notify it as we run here as admin, we should see everything.
debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document, not all required data is available: ' .
$ex->getMessage(), DEBUG_DEVELOPER);
return false;
} catch (\dml_exception $ex) {
// Notify it as we run here as admin, we should see everything.
debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document: ' . $ex->getMessage(), DEBUG_DEVELOPER);
return false;
}
// Prepare associative array with data from DB.
$doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname);
$doc->set('title', content_to_text($record->title, false));
$doc->set('content', content_to_text($record->content, $record->contentformat));
$doc->set('contextid', $context->id);
$doc->set('courseid', $record->courseid);
$doc->set('owneruserid', \core_search\manager::NO_OWNER_ID);
$doc->set('modified', $record->timemodified);
// Check if this document should be considered new.
if (isset($options['lastindexedtime']) && ($options['lastindexedtime'] < $record->timecreated)) {
// If the document was created after the last index time, it must be new.
$doc->set_is_new(true);
}
return $doc;
}
|
[
"public",
"function",
"get_document",
"(",
"$",
"record",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"try",
"{",
"$",
"cm",
"=",
"$",
"this",
"->",
"get_cm",
"(",
"'book'",
",",
"$",
"record",
"->",
"bookid",
",",
"$",
"record",
"->",
"courseid",
")",
";",
"$",
"context",
"=",
"\\",
"context_module",
"::",
"instance",
"(",
"$",
"cm",
"->",
"id",
")",
";",
"}",
"catch",
"(",
"\\",
"dml_missing_record_exception",
"$",
"ex",
")",
"{",
"// Notify it as we run here as admin, we should see everything.",
"debugging",
"(",
"'Error retrieving '",
".",
"$",
"this",
"->",
"areaid",
".",
"' '",
".",
"$",
"record",
"->",
"id",
".",
"' document, not all required data is available: '",
".",
"$",
"ex",
"->",
"getMessage",
"(",
")",
",",
"DEBUG_DEVELOPER",
")",
";",
"return",
"false",
";",
"}",
"catch",
"(",
"\\",
"dml_exception",
"$",
"ex",
")",
"{",
"// Notify it as we run here as admin, we should see everything.",
"debugging",
"(",
"'Error retrieving '",
".",
"$",
"this",
"->",
"areaid",
".",
"' '",
".",
"$",
"record",
"->",
"id",
".",
"' document: '",
".",
"$",
"ex",
"->",
"getMessage",
"(",
")",
",",
"DEBUG_DEVELOPER",
")",
";",
"return",
"false",
";",
"}",
"// Prepare associative array with data from DB.",
"$",
"doc",
"=",
"\\",
"core_search",
"\\",
"document_factory",
"::",
"instance",
"(",
"$",
"record",
"->",
"id",
",",
"$",
"this",
"->",
"componentname",
",",
"$",
"this",
"->",
"areaname",
")",
";",
"$",
"doc",
"->",
"set",
"(",
"'title'",
",",
"content_to_text",
"(",
"$",
"record",
"->",
"title",
",",
"false",
")",
")",
";",
"$",
"doc",
"->",
"set",
"(",
"'content'",
",",
"content_to_text",
"(",
"$",
"record",
"->",
"content",
",",
"$",
"record",
"->",
"contentformat",
")",
")",
";",
"$",
"doc",
"->",
"set",
"(",
"'contextid'",
",",
"$",
"context",
"->",
"id",
")",
";",
"$",
"doc",
"->",
"set",
"(",
"'courseid'",
",",
"$",
"record",
"->",
"courseid",
")",
";",
"$",
"doc",
"->",
"set",
"(",
"'owneruserid'",
",",
"\\",
"core_search",
"\\",
"manager",
"::",
"NO_OWNER_ID",
")",
";",
"$",
"doc",
"->",
"set",
"(",
"'modified'",
",",
"$",
"record",
"->",
"timemodified",
")",
";",
"// Check if this document should be considered new.",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'lastindexedtime'",
"]",
")",
"&&",
"(",
"$",
"options",
"[",
"'lastindexedtime'",
"]",
"<",
"$",
"record",
"->",
"timecreated",
")",
")",
"{",
"// If the document was created after the last index time, it must be new.",
"$",
"doc",
"->",
"set_is_new",
"(",
"true",
")",
";",
"}",
"return",
"$",
"doc",
";",
"}"
] |
Returns the document for a particular chapter.
@param \stdClass $record A record containing, at least, the indexed document id and a modified timestamp
@param array $options Options for document creation
@return \core_search\document
|
[
"Returns",
"the",
"document",
"for",
"a",
"particular",
"chapter",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/book/classes/search/chapter.php#L73-L104
|
218,034
|
moodle/moodle
|
mod/book/classes/search/chapter.php
|
chapter.get_doc_url
|
public function get_doc_url(\core_search\document $doc) {
$contextmodule = \context::instance_by_id($doc->get('contextid'));
$params = array('id' => $contextmodule->instanceid, 'chapterid' => $doc->get('itemid'));
return new \moodle_url('/mod/book/view.php', $params);
}
|
php
|
public function get_doc_url(\core_search\document $doc) {
$contextmodule = \context::instance_by_id($doc->get('contextid'));
$params = array('id' => $contextmodule->instanceid, 'chapterid' => $doc->get('itemid'));
return new \moodle_url('/mod/book/view.php', $params);
}
|
[
"public",
"function",
"get_doc_url",
"(",
"\\",
"core_search",
"\\",
"document",
"$",
"doc",
")",
"{",
"$",
"contextmodule",
"=",
"\\",
"context",
"::",
"instance_by_id",
"(",
"$",
"doc",
"->",
"get",
"(",
"'contextid'",
")",
")",
";",
"$",
"params",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"contextmodule",
"->",
"instanceid",
",",
"'chapterid'",
"=>",
"$",
"doc",
"->",
"get",
"(",
"'itemid'",
")",
")",
";",
"return",
"new",
"\\",
"moodle_url",
"(",
"'/mod/book/view.php'",
",",
"$",
"params",
")",
";",
"}"
] |
Returns a url to the chapter.
@param \core_search\document $doc
@return \moodle_url
|
[
"Returns",
"a",
"url",
"to",
"the",
"chapter",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/book/classes/search/chapter.php#L153-L157
|
218,035
|
moodle/moodle
|
admin/tool/usertours/classes/event/tour_ended.php
|
tour_ended.get_other_mapping
|
public static function get_other_mapping() {
return [
'stepindex' => \core\event\base::NOT_MAPPED,
'stepid' => [
'db' => 'tool_usertours_steps',
'restore' => \core\event\base::NOT_MAPPED,
],
'pageurl' => \core\event\base::NOT_MAPPED,
];
}
|
php
|
public static function get_other_mapping() {
return [
'stepindex' => \core\event\base::NOT_MAPPED,
'stepid' => [
'db' => 'tool_usertours_steps',
'restore' => \core\event\base::NOT_MAPPED,
],
'pageurl' => \core\event\base::NOT_MAPPED,
];
}
|
[
"public",
"static",
"function",
"get_other_mapping",
"(",
")",
"{",
"return",
"[",
"'stepindex'",
"=>",
"\\",
"core",
"\\",
"event",
"\\",
"base",
"::",
"NOT_MAPPED",
",",
"'stepid'",
"=>",
"[",
"'db'",
"=>",
"'tool_usertours_steps'",
",",
"'restore'",
"=>",
"\\",
"core",
"\\",
"event",
"\\",
"base",
"::",
"NOT_MAPPED",
",",
"]",
",",
"'pageurl'",
"=>",
"\\",
"core",
"\\",
"event",
"\\",
"base",
"::",
"NOT_MAPPED",
",",
"]",
";",
"}"
] |
This is used when restoring course logs where it is required that we
map the information in 'other' to it's new value in the new course.
Does nothing in the base class except display a debugging message warning
the user that the event does not contain the required functionality to
map this information. For events that do not store any other information this
won't be called, so no debugging message will be displayed.
@return array an array of other values and their corresponding mapping
|
[
"This",
"is",
"used",
"when",
"restoring",
"course",
"logs",
"where",
"it",
"is",
"required",
"that",
"we",
"map",
"the",
"information",
"in",
"other",
"to",
"it",
"s",
"new",
"value",
"in",
"the",
"new",
"course",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/event/tour_ended.php#L96-L105
|
218,036
|
moodle/moodle
|
admin/tool/dataprivacy/classes/output/expired_contexts_table.php
|
expired_contexts_table.col_name
|
public function col_name($expiredctx) {
global $OUTPUT;
$context = context_helper::instance_by_id($expiredctx->get('contextid'));
$parent = $context->get_parent_context();
$contextdata = (object)[
'name' => $context->get_context_name(false, true),
'parent' => $parent->get_context_name(false, true),
];
$fullcontexts = $context->get_parent_contexts(true);
$contextsinpath = [];
foreach ($fullcontexts as $contextinpath) {
$contextsinpath[] = $contextinpath->get_context_name(false, true);
}
$infoicon = new pix_icon('i/info', implode(' / ', array_reverse($contextsinpath)));
$infoiconhtml = $OUTPUT->render($infoicon);
$name = html_writer::span(get_string('nameandparent', 'tool_dataprivacy', $contextdata), 'mr-1');
return $name . $infoiconhtml;
}
|
php
|
public function col_name($expiredctx) {
global $OUTPUT;
$context = context_helper::instance_by_id($expiredctx->get('contextid'));
$parent = $context->get_parent_context();
$contextdata = (object)[
'name' => $context->get_context_name(false, true),
'parent' => $parent->get_context_name(false, true),
];
$fullcontexts = $context->get_parent_contexts(true);
$contextsinpath = [];
foreach ($fullcontexts as $contextinpath) {
$contextsinpath[] = $contextinpath->get_context_name(false, true);
}
$infoicon = new pix_icon('i/info', implode(' / ', array_reverse($contextsinpath)));
$infoiconhtml = $OUTPUT->render($infoicon);
$name = html_writer::span(get_string('nameandparent', 'tool_dataprivacy', $contextdata), 'mr-1');
return $name . $infoiconhtml;
}
|
[
"public",
"function",
"col_name",
"(",
"$",
"expiredctx",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"$",
"context",
"=",
"context_helper",
"::",
"instance_by_id",
"(",
"$",
"expiredctx",
"->",
"get",
"(",
"'contextid'",
")",
")",
";",
"$",
"parent",
"=",
"$",
"context",
"->",
"get_parent_context",
"(",
")",
";",
"$",
"contextdata",
"=",
"(",
"object",
")",
"[",
"'name'",
"=>",
"$",
"context",
"->",
"get_context_name",
"(",
"false",
",",
"true",
")",
",",
"'parent'",
"=>",
"$",
"parent",
"->",
"get_context_name",
"(",
"false",
",",
"true",
")",
",",
"]",
";",
"$",
"fullcontexts",
"=",
"$",
"context",
"->",
"get_parent_contexts",
"(",
"true",
")",
";",
"$",
"contextsinpath",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"fullcontexts",
"as",
"$",
"contextinpath",
")",
"{",
"$",
"contextsinpath",
"[",
"]",
"=",
"$",
"contextinpath",
"->",
"get_context_name",
"(",
"false",
",",
"true",
")",
";",
"}",
"$",
"infoicon",
"=",
"new",
"pix_icon",
"(",
"'i/info'",
",",
"implode",
"(",
"' / '",
",",
"array_reverse",
"(",
"$",
"contextsinpath",
")",
")",
")",
";",
"$",
"infoiconhtml",
"=",
"$",
"OUTPUT",
"->",
"render",
"(",
"$",
"infoicon",
")",
";",
"$",
"name",
"=",
"html_writer",
"::",
"span",
"(",
"get_string",
"(",
"'nameandparent'",
",",
"'tool_dataprivacy'",
",",
"$",
"contextdata",
")",
",",
"'mr-1'",
")",
";",
"return",
"$",
"name",
".",
"$",
"infoiconhtml",
";",
"}"
] |
The context name column.
@param stdClass $expiredctx The row data.
@return string
@throws coding_exception
|
[
"The",
"context",
"name",
"column",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/output/expired_contexts_table.php#L119-L137
|
218,037
|
moodle/moodle
|
admin/tool/dataprivacy/classes/output/expired_contexts_table.php
|
expired_contexts_table.col_info
|
public function col_info($expiredctx) {
global $OUTPUT;
$context = context_helper::instance_by_id($expiredctx->get('contextid'));
$children = $context->get_child_contexts();
if (empty($children)) {
return get_string('none');
} else {
$childnames = [];
foreach ($children as $child) {
$childnames[] = $child->get_context_name(false, true);
}
$infoicon = new pix_icon('i/info', implode(', ', $childnames));
$infoiconhtml = $OUTPUT->render($infoicon);
$name = html_writer::span(get_string('nchildren', 'tool_dataprivacy', count($children)), 'mr-1');
return $name . $infoiconhtml;
}
}
|
php
|
public function col_info($expiredctx) {
global $OUTPUT;
$context = context_helper::instance_by_id($expiredctx->get('contextid'));
$children = $context->get_child_contexts();
if (empty($children)) {
return get_string('none');
} else {
$childnames = [];
foreach ($children as $child) {
$childnames[] = $child->get_context_name(false, true);
}
$infoicon = new pix_icon('i/info', implode(', ', $childnames));
$infoiconhtml = $OUTPUT->render($infoicon);
$name = html_writer::span(get_string('nchildren', 'tool_dataprivacy', count($children)), 'mr-1');
return $name . $infoiconhtml;
}
}
|
[
"public",
"function",
"col_info",
"(",
"$",
"expiredctx",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"$",
"context",
"=",
"context_helper",
"::",
"instance_by_id",
"(",
"$",
"expiredctx",
"->",
"get",
"(",
"'contextid'",
")",
")",
";",
"$",
"children",
"=",
"$",
"context",
"->",
"get_child_contexts",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"children",
")",
")",
"{",
"return",
"get_string",
"(",
"'none'",
")",
";",
"}",
"else",
"{",
"$",
"childnames",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"children",
"as",
"$",
"child",
")",
"{",
"$",
"childnames",
"[",
"]",
"=",
"$",
"child",
"->",
"get_context_name",
"(",
"false",
",",
"true",
")",
";",
"}",
"$",
"infoicon",
"=",
"new",
"pix_icon",
"(",
"'i/info'",
",",
"implode",
"(",
"', '",
",",
"$",
"childnames",
")",
")",
";",
"$",
"infoiconhtml",
"=",
"$",
"OUTPUT",
"->",
"render",
"(",
"$",
"infoicon",
")",
";",
"$",
"name",
"=",
"html_writer",
"::",
"span",
"(",
"get_string",
"(",
"'nchildren'",
",",
"'tool_dataprivacy'",
",",
"count",
"(",
"$",
"children",
")",
")",
",",
"'mr-1'",
")",
";",
"return",
"$",
"name",
".",
"$",
"infoiconhtml",
";",
"}",
"}"
] |
The context information column.
@param stdClass $expiredctx The row data.
@return string
@throws coding_exception
|
[
"The",
"context",
"information",
"column",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/output/expired_contexts_table.php#L146-L165
|
218,038
|
moodle/moodle
|
admin/tool/dataprivacy/classes/output/expired_contexts_table.php
|
expired_contexts_table.col_category
|
public function col_category($expiredctx) {
$context = context_helper::instance_by_id($expiredctx->get('contextid'));
$category = api::get_effective_context_category($context);
return s($category->get('name'));
}
|
php
|
public function col_category($expiredctx) {
$context = context_helper::instance_by_id($expiredctx->get('contextid'));
$category = api::get_effective_context_category($context);
return s($category->get('name'));
}
|
[
"public",
"function",
"col_category",
"(",
"$",
"expiredctx",
")",
"{",
"$",
"context",
"=",
"context_helper",
"::",
"instance_by_id",
"(",
"$",
"expiredctx",
"->",
"get",
"(",
"'contextid'",
")",
")",
";",
"$",
"category",
"=",
"api",
"::",
"get_effective_context_category",
"(",
"$",
"context",
")",
";",
"return",
"s",
"(",
"$",
"category",
"->",
"get",
"(",
"'name'",
")",
")",
";",
"}"
] |
The category name column.
@param stdClass $expiredctx The row data.
@return mixed
@throws coding_exception
@throws dml_exception
|
[
"The",
"category",
"name",
"column",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/output/expired_contexts_table.php#L175-L180
|
218,039
|
moodle/moodle
|
admin/tool/dataprivacy/classes/output/expired_contexts_table.php
|
expired_contexts_table.col_retentionperiod
|
public function col_retentionperiod($expiredctx) {
$purpose = $this->get_purpose_for_expiry($expiredctx);
$expiries = [];
$expiry = html_writer::tag('dt', get_string('default'), ['class' => 'col-sm-3']);
if ($expiredctx->get('defaultexpired')) {
$expiries[get_string('default')] = get_string('expiredrolewithretention', 'tool_dataprivacy', (object) [
'retention' => api::format_retention_period(new \DateInterval($purpose->get('retentionperiod'))),
]);
} else {
$expiries[get_string('default')] = get_string('unexpiredrolewithretention', 'tool_dataprivacy', (object) [
'retention' => api::format_retention_period(new \DateInterval($purpose->get('retentionperiod'))),
]);
}
if (!$expiredctx->is_fully_expired()) {
$purposeoverrides = $purpose->get_purpose_overrides();
foreach ($expiredctx->get('unexpiredroles') as $roleid) {
$role = $this->roles[$roleid];
$override = $purposeoverrides[$roleid];
$expiries[$role->localname] = get_string('unexpiredrolewithretention', 'tool_dataprivacy', (object) [
'retention' => api::format_retention_period(new \DateInterval($override->get('retentionperiod'))),
]);
}
foreach ($expiredctx->get('expiredroles') as $roleid) {
$role = $this->roles[$roleid];
$override = $purposeoverrides[$roleid];
$expiries[$role->localname] = get_string('expiredrolewithretention', 'tool_dataprivacy', (object) [
'retention' => api::format_retention_period(new \DateInterval($override->get('retentionperiod'))),
]);
}
}
$output = array_map(function($rolename, $expiry) {
$return = html_writer::tag('dt', $rolename, ['class' => 'col-sm-3']);
$return .= html_writer::tag('dd', $expiry, ['class' => 'col-sm-9']);
return $return;
}, array_keys($expiries), $expiries);
return html_writer::tag('dl', implode($output), ['class' => 'row']);
}
|
php
|
public function col_retentionperiod($expiredctx) {
$purpose = $this->get_purpose_for_expiry($expiredctx);
$expiries = [];
$expiry = html_writer::tag('dt', get_string('default'), ['class' => 'col-sm-3']);
if ($expiredctx->get('defaultexpired')) {
$expiries[get_string('default')] = get_string('expiredrolewithretention', 'tool_dataprivacy', (object) [
'retention' => api::format_retention_period(new \DateInterval($purpose->get('retentionperiod'))),
]);
} else {
$expiries[get_string('default')] = get_string('unexpiredrolewithretention', 'tool_dataprivacy', (object) [
'retention' => api::format_retention_period(new \DateInterval($purpose->get('retentionperiod'))),
]);
}
if (!$expiredctx->is_fully_expired()) {
$purposeoverrides = $purpose->get_purpose_overrides();
foreach ($expiredctx->get('unexpiredroles') as $roleid) {
$role = $this->roles[$roleid];
$override = $purposeoverrides[$roleid];
$expiries[$role->localname] = get_string('unexpiredrolewithretention', 'tool_dataprivacy', (object) [
'retention' => api::format_retention_period(new \DateInterval($override->get('retentionperiod'))),
]);
}
foreach ($expiredctx->get('expiredroles') as $roleid) {
$role = $this->roles[$roleid];
$override = $purposeoverrides[$roleid];
$expiries[$role->localname] = get_string('expiredrolewithretention', 'tool_dataprivacy', (object) [
'retention' => api::format_retention_period(new \DateInterval($override->get('retentionperiod'))),
]);
}
}
$output = array_map(function($rolename, $expiry) {
$return = html_writer::tag('dt', $rolename, ['class' => 'col-sm-3']);
$return .= html_writer::tag('dd', $expiry, ['class' => 'col-sm-9']);
return $return;
}, array_keys($expiries), $expiries);
return html_writer::tag('dl', implode($output), ['class' => 'row']);
}
|
[
"public",
"function",
"col_retentionperiod",
"(",
"$",
"expiredctx",
")",
"{",
"$",
"purpose",
"=",
"$",
"this",
"->",
"get_purpose_for_expiry",
"(",
"$",
"expiredctx",
")",
";",
"$",
"expiries",
"=",
"[",
"]",
";",
"$",
"expiry",
"=",
"html_writer",
"::",
"tag",
"(",
"'dt'",
",",
"get_string",
"(",
"'default'",
")",
",",
"[",
"'class'",
"=>",
"'col-sm-3'",
"]",
")",
";",
"if",
"(",
"$",
"expiredctx",
"->",
"get",
"(",
"'defaultexpired'",
")",
")",
"{",
"$",
"expiries",
"[",
"get_string",
"(",
"'default'",
")",
"]",
"=",
"get_string",
"(",
"'expiredrolewithretention'",
",",
"'tool_dataprivacy'",
",",
"(",
"object",
")",
"[",
"'retention'",
"=>",
"api",
"::",
"format_retention_period",
"(",
"new",
"\\",
"DateInterval",
"(",
"$",
"purpose",
"->",
"get",
"(",
"'retentionperiod'",
")",
")",
")",
",",
"]",
")",
";",
"}",
"else",
"{",
"$",
"expiries",
"[",
"get_string",
"(",
"'default'",
")",
"]",
"=",
"get_string",
"(",
"'unexpiredrolewithretention'",
",",
"'tool_dataprivacy'",
",",
"(",
"object",
")",
"[",
"'retention'",
"=>",
"api",
"::",
"format_retention_period",
"(",
"new",
"\\",
"DateInterval",
"(",
"$",
"purpose",
"->",
"get",
"(",
"'retentionperiod'",
")",
")",
")",
",",
"]",
")",
";",
"}",
"if",
"(",
"!",
"$",
"expiredctx",
"->",
"is_fully_expired",
"(",
")",
")",
"{",
"$",
"purposeoverrides",
"=",
"$",
"purpose",
"->",
"get_purpose_overrides",
"(",
")",
";",
"foreach",
"(",
"$",
"expiredctx",
"->",
"get",
"(",
"'unexpiredroles'",
")",
"as",
"$",
"roleid",
")",
"{",
"$",
"role",
"=",
"$",
"this",
"->",
"roles",
"[",
"$",
"roleid",
"]",
";",
"$",
"override",
"=",
"$",
"purposeoverrides",
"[",
"$",
"roleid",
"]",
";",
"$",
"expiries",
"[",
"$",
"role",
"->",
"localname",
"]",
"=",
"get_string",
"(",
"'unexpiredrolewithretention'",
",",
"'tool_dataprivacy'",
",",
"(",
"object",
")",
"[",
"'retention'",
"=>",
"api",
"::",
"format_retention_period",
"(",
"new",
"\\",
"DateInterval",
"(",
"$",
"override",
"->",
"get",
"(",
"'retentionperiod'",
")",
")",
")",
",",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"expiredctx",
"->",
"get",
"(",
"'expiredroles'",
")",
"as",
"$",
"roleid",
")",
"{",
"$",
"role",
"=",
"$",
"this",
"->",
"roles",
"[",
"$",
"roleid",
"]",
";",
"$",
"override",
"=",
"$",
"purposeoverrides",
"[",
"$",
"roleid",
"]",
";",
"$",
"expiries",
"[",
"$",
"role",
"->",
"localname",
"]",
"=",
"get_string",
"(",
"'expiredrolewithretention'",
",",
"'tool_dataprivacy'",
",",
"(",
"object",
")",
"[",
"'retention'",
"=>",
"api",
"::",
"format_retention_period",
"(",
"new",
"\\",
"DateInterval",
"(",
"$",
"override",
"->",
"get",
"(",
"'retentionperiod'",
")",
")",
")",
",",
"]",
")",
";",
"}",
"}",
"$",
"output",
"=",
"array_map",
"(",
"function",
"(",
"$",
"rolename",
",",
"$",
"expiry",
")",
"{",
"$",
"return",
"=",
"html_writer",
"::",
"tag",
"(",
"'dt'",
",",
"$",
"rolename",
",",
"[",
"'class'",
"=>",
"'col-sm-3'",
"]",
")",
";",
"$",
"return",
".=",
"html_writer",
"::",
"tag",
"(",
"'dd'",
",",
"$",
"expiry",
",",
"[",
"'class'",
"=>",
"'col-sm-9'",
"]",
")",
";",
"return",
"$",
"return",
";",
"}",
",",
"array_keys",
"(",
"$",
"expiries",
")",
",",
"$",
"expiries",
")",
";",
"return",
"html_writer",
"::",
"tag",
"(",
"'dl'",
",",
"implode",
"(",
"$",
"output",
")",
",",
"[",
"'class'",
"=>",
"'row'",
"]",
")",
";",
"}"
] |
The retention period column.
@param stdClass $expiredctx The row data.
@return string
|
[
"The",
"retention",
"period",
"column",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/output/expired_contexts_table.php#L201-L247
|
218,040
|
moodle/moodle
|
admin/tool/dataprivacy/classes/output/expired_contexts_table.php
|
expired_contexts_table.col_select
|
public function col_select($expiredctx) {
$id = $expiredctx->get('id');
return html_writer::checkbox('expiredcontext_' . $id, $id, $this->selectall, '', ['class' => 'selectcontext']);
}
|
php
|
public function col_select($expiredctx) {
$id = $expiredctx->get('id');
return html_writer::checkbox('expiredcontext_' . $id, $id, $this->selectall, '', ['class' => 'selectcontext']);
}
|
[
"public",
"function",
"col_select",
"(",
"$",
"expiredctx",
")",
"{",
"$",
"id",
"=",
"$",
"expiredctx",
"->",
"get",
"(",
"'id'",
")",
";",
"return",
"html_writer",
"::",
"checkbox",
"(",
"'expiredcontext_'",
".",
"$",
"id",
",",
"$",
"id",
",",
"$",
"this",
"->",
"selectall",
",",
"''",
",",
"[",
"'class'",
"=>",
"'selectcontext'",
"]",
")",
";",
"}"
] |
Generate the select column.
@param stdClass $expiredctx The row data.
@return string
|
[
"Generate",
"the",
"select",
"column",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/output/expired_contexts_table.php#L265-L268
|
218,041
|
moodle/moodle
|
admin/tool/dataprivacy/classes/output/expired_contexts_table.php
|
expired_contexts_table.col_tobedeleted
|
public function col_tobedeleted($expiredctx) {
if ($expiredctx->is_fully_expired()) {
return get_string('defaultexpired', 'tool_dataprivacy');
}
$purpose = $this->get_purpose_for_expiry($expiredctx);
$a = (object) [];
$expiredroles = [];
foreach ($expiredctx->get('expiredroles') as $roleid) {
$expiredroles[] = html_writer::tag('li', $this->roles[$roleid]->localname);
}
$a->expired = html_writer::tag('ul', implode($expiredroles));
$unexpiredroles = [];
foreach ($expiredctx->get('unexpiredroles') as $roleid) {
$unexpiredroles[] = html_writer::tag('li', $this->roles[$roleid]->localname);
}
$a->unexpired = html_writer::tag('ul', implode($unexpiredroles));
if ($expiredctx->get('defaultexpired')) {
return get_string('defaultexpiredexcept', 'tool_dataprivacy', $a);
} else if (empty($unexpiredroles)) {
return get_string('defaultunexpired', 'tool_dataprivacy', $a);
} else {
return get_string('defaultunexpiredwithexceptions', 'tool_dataprivacy', $a);
}
}
|
php
|
public function col_tobedeleted($expiredctx) {
if ($expiredctx->is_fully_expired()) {
return get_string('defaultexpired', 'tool_dataprivacy');
}
$purpose = $this->get_purpose_for_expiry($expiredctx);
$a = (object) [];
$expiredroles = [];
foreach ($expiredctx->get('expiredroles') as $roleid) {
$expiredroles[] = html_writer::tag('li', $this->roles[$roleid]->localname);
}
$a->expired = html_writer::tag('ul', implode($expiredroles));
$unexpiredroles = [];
foreach ($expiredctx->get('unexpiredroles') as $roleid) {
$unexpiredroles[] = html_writer::tag('li', $this->roles[$roleid]->localname);
}
$a->unexpired = html_writer::tag('ul', implode($unexpiredroles));
if ($expiredctx->get('defaultexpired')) {
return get_string('defaultexpiredexcept', 'tool_dataprivacy', $a);
} else if (empty($unexpiredroles)) {
return get_string('defaultunexpired', 'tool_dataprivacy', $a);
} else {
return get_string('defaultunexpiredwithexceptions', 'tool_dataprivacy', $a);
}
}
|
[
"public",
"function",
"col_tobedeleted",
"(",
"$",
"expiredctx",
")",
"{",
"if",
"(",
"$",
"expiredctx",
"->",
"is_fully_expired",
"(",
")",
")",
"{",
"return",
"get_string",
"(",
"'defaultexpired'",
",",
"'tool_dataprivacy'",
")",
";",
"}",
"$",
"purpose",
"=",
"$",
"this",
"->",
"get_purpose_for_expiry",
"(",
"$",
"expiredctx",
")",
";",
"$",
"a",
"=",
"(",
"object",
")",
"[",
"]",
";",
"$",
"expiredroles",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"expiredctx",
"->",
"get",
"(",
"'expiredroles'",
")",
"as",
"$",
"roleid",
")",
"{",
"$",
"expiredroles",
"[",
"]",
"=",
"html_writer",
"::",
"tag",
"(",
"'li'",
",",
"$",
"this",
"->",
"roles",
"[",
"$",
"roleid",
"]",
"->",
"localname",
")",
";",
"}",
"$",
"a",
"->",
"expired",
"=",
"html_writer",
"::",
"tag",
"(",
"'ul'",
",",
"implode",
"(",
"$",
"expiredroles",
")",
")",
";",
"$",
"unexpiredroles",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"expiredctx",
"->",
"get",
"(",
"'unexpiredroles'",
")",
"as",
"$",
"roleid",
")",
"{",
"$",
"unexpiredroles",
"[",
"]",
"=",
"html_writer",
"::",
"tag",
"(",
"'li'",
",",
"$",
"this",
"->",
"roles",
"[",
"$",
"roleid",
"]",
"->",
"localname",
")",
";",
"}",
"$",
"a",
"->",
"unexpired",
"=",
"html_writer",
"::",
"tag",
"(",
"'ul'",
",",
"implode",
"(",
"$",
"unexpiredroles",
")",
")",
";",
"if",
"(",
"$",
"expiredctx",
"->",
"get",
"(",
"'defaultexpired'",
")",
")",
"{",
"return",
"get_string",
"(",
"'defaultexpiredexcept'",
",",
"'tool_dataprivacy'",
",",
"$",
"a",
")",
";",
"}",
"else",
"if",
"(",
"empty",
"(",
"$",
"unexpiredroles",
")",
")",
"{",
"return",
"get_string",
"(",
"'defaultunexpired'",
",",
"'tool_dataprivacy'",
",",
"$",
"a",
")",
";",
"}",
"else",
"{",
"return",
"get_string",
"(",
"'defaultunexpiredwithexceptions'",
",",
"'tool_dataprivacy'",
",",
"$",
"a",
")",
";",
"}",
"}"
] |
Formatting for the 'tobedeleted' column which indicates in a friendlier fashion whose data will be removed.
@param stdClass $expiredctx The row data.
@return string
|
[
"Formatting",
"for",
"the",
"tobedeleted",
"column",
"which",
"indicates",
"in",
"a",
"friendlier",
"fashion",
"whose",
"data",
"will",
"be",
"removed",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/output/expired_contexts_table.php#L276-L304
|
218,042
|
moodle/moodle
|
admin/tool/dataprivacy/classes/output/expired_contexts_table.php
|
expired_contexts_table.get_purpose_for_expiry
|
protected function get_purpose_for_expiry(expired_context $expiredcontext) : purpose {
$context = context_helper::instance_by_id($expiredcontext->get('contextid'));
if (empty($this->purposemap[$context->id])) {
$purpose = api::get_effective_context_purpose($context);
$this->purposemap[$context->id] = $purpose->get('id');
if (empty($this->purposes[$purpose->get('id')])) {
$this->purposes[$purpose->get('id')] = $purpose;
}
}
return $this->purposes[$this->purposemap[$context->id]];
}
|
php
|
protected function get_purpose_for_expiry(expired_context $expiredcontext) : purpose {
$context = context_helper::instance_by_id($expiredcontext->get('contextid'));
if (empty($this->purposemap[$context->id])) {
$purpose = api::get_effective_context_purpose($context);
$this->purposemap[$context->id] = $purpose->get('id');
if (empty($this->purposes[$purpose->get('id')])) {
$this->purposes[$purpose->get('id')] = $purpose;
}
}
return $this->purposes[$this->purposemap[$context->id]];
}
|
[
"protected",
"function",
"get_purpose_for_expiry",
"(",
"expired_context",
"$",
"expiredcontext",
")",
":",
"purpose",
"{",
"$",
"context",
"=",
"context_helper",
"::",
"instance_by_id",
"(",
"$",
"expiredcontext",
"->",
"get",
"(",
"'contextid'",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"purposemap",
"[",
"$",
"context",
"->",
"id",
"]",
")",
")",
"{",
"$",
"purpose",
"=",
"api",
"::",
"get_effective_context_purpose",
"(",
"$",
"context",
")",
";",
"$",
"this",
"->",
"purposemap",
"[",
"$",
"context",
"->",
"id",
"]",
"=",
"$",
"purpose",
"->",
"get",
"(",
"'id'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"purposes",
"[",
"$",
"purpose",
"->",
"get",
"(",
"'id'",
")",
"]",
")",
")",
"{",
"$",
"this",
"->",
"purposes",
"[",
"$",
"purpose",
"->",
"get",
"(",
"'id'",
")",
"]",
"=",
"$",
"purpose",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"purposes",
"[",
"$",
"this",
"->",
"purposemap",
"[",
"$",
"context",
"->",
"id",
"]",
"]",
";",
"}"
] |
Get the purpose for the specified expired context.
@param expired_context $expiredcontext
@return purpose
|
[
"Get",
"the",
"purpose",
"for",
"the",
"specified",
"expired",
"context",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/output/expired_contexts_table.php#L373-L386
|
218,043
|
moodle/moodle
|
admin/tool/dataprivacy/classes/output/expired_contexts_table.php
|
expired_contexts_table.preload_contexts
|
protected function preload_contexts(array $contextids) {
global $DB;
if (empty($contextids)) {
return;
}
$ctxfields = \context_helper::get_preload_record_columns_sql('ctx');
list($insql, $inparams) = $DB->get_in_or_equal($contextids, SQL_PARAMS_NAMED);
$sql = "SELECT {$ctxfields} FROM {context} ctx WHERE ctx.id {$insql}";
$contextlist = $DB->get_recordset_sql($sql, $inparams);
foreach ($contextlist as $contextdata) {
\context_helper::preload_from_record($contextdata);
}
$contextlist->close();
}
|
php
|
protected function preload_contexts(array $contextids) {
global $DB;
if (empty($contextids)) {
return;
}
$ctxfields = \context_helper::get_preload_record_columns_sql('ctx');
list($insql, $inparams) = $DB->get_in_or_equal($contextids, SQL_PARAMS_NAMED);
$sql = "SELECT {$ctxfields} FROM {context} ctx WHERE ctx.id {$insql}";
$contextlist = $DB->get_recordset_sql($sql, $inparams);
foreach ($contextlist as $contextdata) {
\context_helper::preload_from_record($contextdata);
}
$contextlist->close();
}
|
[
"protected",
"function",
"preload_contexts",
"(",
"array",
"$",
"contextids",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"empty",
"(",
"$",
"contextids",
")",
")",
"{",
"return",
";",
"}",
"$",
"ctxfields",
"=",
"\\",
"context_helper",
"::",
"get_preload_record_columns_sql",
"(",
"'ctx'",
")",
";",
"list",
"(",
"$",
"insql",
",",
"$",
"inparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"contextids",
",",
"SQL_PARAMS_NAMED",
")",
";",
"$",
"sql",
"=",
"\"SELECT {$ctxfields} FROM {context} ctx WHERE ctx.id {$insql}\"",
";",
"$",
"contextlist",
"=",
"$",
"DB",
"->",
"get_recordset_sql",
"(",
"$",
"sql",
",",
"$",
"inparams",
")",
";",
"foreach",
"(",
"$",
"contextlist",
"as",
"$",
"contextdata",
")",
"{",
"\\",
"context_helper",
"::",
"preload_from_record",
"(",
"$",
"contextdata",
")",
";",
"}",
"$",
"contextlist",
"->",
"close",
"(",
")",
";",
"}"
] |
Preload context records given a set of contextids.
@param array $contextids
|
[
"Preload",
"context",
"records",
"given",
"a",
"set",
"of",
"contextids",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/output/expired_contexts_table.php#L393-L409
|
218,044
|
moodle/moodle
|
analytics/classes/local/target/binary.php
|
binary.get_calculation_outcome
|
public function get_calculation_outcome($value, $ignoredsubtype = false) {
if (!self::is_a_class($value)) {
throw new \moodle_exception('errorpredictionformat', 'analytics');
}
if (in_array($value, $this->ignored_predicted_classes(), false)) {
// Just in case, if it is ignored the prediction should not even be recorded but if it would, it is ignored now,
// which should mean that is it nothing serious.
return self::OUTCOME_VERY_POSITIVE;
}
// By default binaries are danger when prediction = 1.
if ($value) {
return self::OUTCOME_VERY_NEGATIVE;
}
return self::OUTCOME_VERY_POSITIVE;
}
|
php
|
public function get_calculation_outcome($value, $ignoredsubtype = false) {
if (!self::is_a_class($value)) {
throw new \moodle_exception('errorpredictionformat', 'analytics');
}
if (in_array($value, $this->ignored_predicted_classes(), false)) {
// Just in case, if it is ignored the prediction should not even be recorded but if it would, it is ignored now,
// which should mean that is it nothing serious.
return self::OUTCOME_VERY_POSITIVE;
}
// By default binaries are danger when prediction = 1.
if ($value) {
return self::OUTCOME_VERY_NEGATIVE;
}
return self::OUTCOME_VERY_POSITIVE;
}
|
[
"public",
"function",
"get_calculation_outcome",
"(",
"$",
"value",
",",
"$",
"ignoredsubtype",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"is_a_class",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'errorpredictionformat'",
",",
"'analytics'",
")",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"ignored_predicted_classes",
"(",
")",
",",
"false",
")",
")",
"{",
"// Just in case, if it is ignored the prediction should not even be recorded but if it would, it is ignored now,",
"// which should mean that is it nothing serious.",
"return",
"self",
"::",
"OUTCOME_VERY_POSITIVE",
";",
"}",
"// By default binaries are danger when prediction = 1.",
"if",
"(",
"$",
"value",
")",
"{",
"return",
"self",
"::",
"OUTCOME_VERY_NEGATIVE",
";",
"}",
"return",
"self",
"::",
"OUTCOME_VERY_POSITIVE",
";",
"}"
] |
Is the calculated value a positive outcome of this target?
@param string $value
@param string $ignoredsubtype
@return int
|
[
"Is",
"the",
"calculated",
"value",
"a",
"positive",
"outcome",
"of",
"this",
"target?"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/target/binary.php#L75-L92
|
218,045
|
moodle/moodle
|
lib/horde/framework/Horde/Support/StringStream.php
|
Horde_Support_StringStream.fopen
|
public function fopen()
{
return fopen(
self::WNAME . '://' . spl_object_hash($this),
'rb',
false,
stream_context_create(array(
self::WNAME => array(
'string' => $this
)
))
);
}
|
php
|
public function fopen()
{
return fopen(
self::WNAME . '://' . spl_object_hash($this),
'rb',
false,
stream_context_create(array(
self::WNAME => array(
'string' => $this
)
))
);
}
|
[
"public",
"function",
"fopen",
"(",
")",
"{",
"return",
"fopen",
"(",
"self",
"::",
"WNAME",
".",
"'://'",
".",
"spl_object_hash",
"(",
"$",
"this",
")",
",",
"'rb'",
",",
"false",
",",
"stream_context_create",
"(",
"array",
"(",
"self",
"::",
"WNAME",
"=>",
"array",
"(",
"'string'",
"=>",
"$",
"this",
")",
")",
")",
")",
";",
"}"
] |
Return a stream handle to this string stream.
@return resource
|
[
"Return",
"a",
"stream",
"handle",
"to",
"this",
"string",
"stream",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Support/StringStream.php#L46-L58
|
218,046
|
moodle/moodle
|
lib/horde/framework/Horde/Support/StringStream.php
|
Horde_Support_StringStream.getFileObject
|
public function getFileObject()
{
return new SplFileObject(
self::WNAME . '://' . spl_object_hash($this),
'rb',
false,
stream_context_create(array(
self::WNAME => array(
'string' => $this
)
))
);
}
|
php
|
public function getFileObject()
{
return new SplFileObject(
self::WNAME . '://' . spl_object_hash($this),
'rb',
false,
stream_context_create(array(
self::WNAME => array(
'string' => $this
)
))
);
}
|
[
"public",
"function",
"getFileObject",
"(",
")",
"{",
"return",
"new",
"SplFileObject",
"(",
"self",
"::",
"WNAME",
".",
"'://'",
".",
"spl_object_hash",
"(",
"$",
"this",
")",
",",
"'rb'",
",",
"false",
",",
"stream_context_create",
"(",
"array",
"(",
"self",
"::",
"WNAME",
"=>",
"array",
"(",
"'string'",
"=>",
"$",
"this",
")",
")",
")",
")",
";",
"}"
] |
Return an SplFileObject representing this string stream
@return SplFileObject
|
[
"Return",
"an",
"SplFileObject",
"representing",
"this",
"string",
"stream"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Support/StringStream.php#L65-L77
|
218,047
|
moodle/moodle
|
theme/boost/classes/admin_settingspage_tabs.php
|
theme_boost_admin_settingspage_tabs.add_tab
|
public function add_tab(admin_settingpage $tab) {
foreach ($tab->settings as $setting) {
$this->settings->{$setting->name} = $setting;
}
$this->tabs[] = $tab;
return true;
}
|
php
|
public function add_tab(admin_settingpage $tab) {
foreach ($tab->settings as $setting) {
$this->settings->{$setting->name} = $setting;
}
$this->tabs[] = $tab;
return true;
}
|
[
"public",
"function",
"add_tab",
"(",
"admin_settingpage",
"$",
"tab",
")",
"{",
"foreach",
"(",
"$",
"tab",
"->",
"settings",
"as",
"$",
"setting",
")",
"{",
"$",
"this",
"->",
"settings",
"->",
"{",
"$",
"setting",
"->",
"name",
"}",
"=",
"$",
"setting",
";",
"}",
"$",
"this",
"->",
"tabs",
"[",
"]",
"=",
"$",
"tab",
";",
"return",
"true",
";",
"}"
] |
Add a tab.
@param admin_settingpage $tab A tab.
|
[
"Add",
"a",
"tab",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/theme/boost/classes/admin_settingspage_tabs.php#L40-L46
|
218,048
|
moodle/moodle
|
theme/boost/classes/admin_settingspage_tabs.php
|
theme_boost_admin_settingspage_tabs.output_html
|
public function output_html() {
global $OUTPUT;
$activetab = optional_param('activetab', '', PARAM_TEXT);
$context = array('tabs' => array());
$havesetactive = false;
foreach ($this->get_tabs() as $tab) {
$active = false;
// Default to first tab it not told otherwise.
if (empty($activetab) && !$havesetactive) {
$active = true;
$havesetactive = true;
} else if ($activetab === $tab->name) {
$active = true;
}
$context['tabs'][] = array(
'name' => $tab->name,
'displayname' => $tab->visiblename,
'html' => $tab->output_html(),
'active' => $active,
);
}
if (empty($context['tabs'])) {
return '';
}
return $OUTPUT->render_from_template('theme_boost/admin_setting_tabs', $context);
}
|
php
|
public function output_html() {
global $OUTPUT;
$activetab = optional_param('activetab', '', PARAM_TEXT);
$context = array('tabs' => array());
$havesetactive = false;
foreach ($this->get_tabs() as $tab) {
$active = false;
// Default to first tab it not told otherwise.
if (empty($activetab) && !$havesetactive) {
$active = true;
$havesetactive = true;
} else if ($activetab === $tab->name) {
$active = true;
}
$context['tabs'][] = array(
'name' => $tab->name,
'displayname' => $tab->visiblename,
'html' => $tab->output_html(),
'active' => $active,
);
}
if (empty($context['tabs'])) {
return '';
}
return $OUTPUT->render_from_template('theme_boost/admin_setting_tabs', $context);
}
|
[
"public",
"function",
"output_html",
"(",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"$",
"activetab",
"=",
"optional_param",
"(",
"'activetab'",
",",
"''",
",",
"PARAM_TEXT",
")",
";",
"$",
"context",
"=",
"array",
"(",
"'tabs'",
"=>",
"array",
"(",
")",
")",
";",
"$",
"havesetactive",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"get_tabs",
"(",
")",
"as",
"$",
"tab",
")",
"{",
"$",
"active",
"=",
"false",
";",
"// Default to first tab it not told otherwise.",
"if",
"(",
"empty",
"(",
"$",
"activetab",
")",
"&&",
"!",
"$",
"havesetactive",
")",
"{",
"$",
"active",
"=",
"true",
";",
"$",
"havesetactive",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"$",
"activetab",
"===",
"$",
"tab",
"->",
"name",
")",
"{",
"$",
"active",
"=",
"true",
";",
"}",
"$",
"context",
"[",
"'tabs'",
"]",
"[",
"]",
"=",
"array",
"(",
"'name'",
"=>",
"$",
"tab",
"->",
"name",
",",
"'displayname'",
"=>",
"$",
"tab",
"->",
"visiblename",
",",
"'html'",
"=>",
"$",
"tab",
"->",
"output_html",
"(",
")",
",",
"'active'",
"=>",
"$",
"active",
",",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"context",
"[",
"'tabs'",
"]",
")",
")",
"{",
"return",
"''",
";",
"}",
"return",
"$",
"OUTPUT",
"->",
"render_from_template",
"(",
"'theme_boost/admin_setting_tabs'",
",",
"$",
"context",
")",
";",
"}"
] |
Generate the HTML output.
@return string
|
[
"Generate",
"the",
"HTML",
"output",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/theme/boost/classes/admin_settingspage_tabs.php#L66-L97
|
218,049
|
moodle/moodle
|
admin/tool/dataprivacy/classes/filtered_userlist.php
|
filtered_userlist.apply_expired_context_filters
|
public function apply_expired_context_filters(array $expireduserids, array $unexpireduserids) : filtered_userlist {
// The current userlist content.
$userids = $this->get_userids();
if (!empty($expireduserids)) {
// Now remove any not on the list of expired users.
$userids = array_intersect($userids, $expireduserids);
}
if (!empty($unexpireduserids)) {
// Remove any on the list of unexpiredusers users.
$userids = array_diff($userids, $unexpireduserids);
}
$this->set_userids($userids);
return $this;
}
|
php
|
public function apply_expired_context_filters(array $expireduserids, array $unexpireduserids) : filtered_userlist {
// The current userlist content.
$userids = $this->get_userids();
if (!empty($expireduserids)) {
// Now remove any not on the list of expired users.
$userids = array_intersect($userids, $expireduserids);
}
if (!empty($unexpireduserids)) {
// Remove any on the list of unexpiredusers users.
$userids = array_diff($userids, $unexpireduserids);
}
$this->set_userids($userids);
return $this;
}
|
[
"public",
"function",
"apply_expired_context_filters",
"(",
"array",
"$",
"expireduserids",
",",
"array",
"$",
"unexpireduserids",
")",
":",
"filtered_userlist",
"{",
"// The current userlist content.",
"$",
"userids",
"=",
"$",
"this",
"->",
"get_userids",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"expireduserids",
")",
")",
"{",
"// Now remove any not on the list of expired users.",
"$",
"userids",
"=",
"array_intersect",
"(",
"$",
"userids",
",",
"$",
"expireduserids",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"unexpireduserids",
")",
")",
"{",
"// Remove any on the list of unexpiredusers users.",
"$",
"userids",
"=",
"array_diff",
"(",
"$",
"userids",
",",
"$",
"unexpireduserids",
")",
";",
"}",
"$",
"this",
"->",
"set_userids",
"(",
"$",
"userids",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Apply filters to only remove users in the expireduserids list, and to remove any who are in the unexpired list.
The unexpired list wins where a user is in both lists.
@param int[] $expireduserids The list of userids for users who should be expired.
@param int[] $unexpireduserids The list of userids for those users who should not be expired.
@return $this
|
[
"Apply",
"filters",
"to",
"only",
"remove",
"users",
"in",
"the",
"expireduserids",
"list",
"and",
"to",
"remove",
"any",
"who",
"are",
"in",
"the",
"unexpired",
"list",
".",
"The",
"unexpired",
"list",
"wins",
"where",
"a",
"user",
"is",
"in",
"both",
"lists",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/filtered_userlist.php#L45-L62
|
218,050
|
moodle/moodle
|
mod/lti/service/toolsettings/classes/local/service/toolsettings.php
|
toolsettings.distinct_settings
|
public static function distinct_settings(&$systemsettings, &$contextsettings, $linksettings) {
if (!empty($systemsettings)) {
foreach ($systemsettings as $key => $value) {
if ((!empty($contextsettings) && array_key_exists($key, $contextsettings)) ||
(!empty($linksettings) && array_key_exists($key, $linksettings))) {
unset($systemsettings[$key]);
}
}
}
if (!empty($contextsettings)) {
foreach ($contextsettings as $key => $value) {
if (!empty($linksettings) && array_key_exists($key, $linksettings)) {
unset($contextsettings[$key]);
}
}
}
}
|
php
|
public static function distinct_settings(&$systemsettings, &$contextsettings, $linksettings) {
if (!empty($systemsettings)) {
foreach ($systemsettings as $key => $value) {
if ((!empty($contextsettings) && array_key_exists($key, $contextsettings)) ||
(!empty($linksettings) && array_key_exists($key, $linksettings))) {
unset($systemsettings[$key]);
}
}
}
if (!empty($contextsettings)) {
foreach ($contextsettings as $key => $value) {
if (!empty($linksettings) && array_key_exists($key, $linksettings)) {
unset($contextsettings[$key]);
}
}
}
}
|
[
"public",
"static",
"function",
"distinct_settings",
"(",
"&",
"$",
"systemsettings",
",",
"&",
"$",
"contextsettings",
",",
"$",
"linksettings",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"systemsettings",
")",
")",
"{",
"foreach",
"(",
"$",
"systemsettings",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"(",
"!",
"empty",
"(",
"$",
"contextsettings",
")",
"&&",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"contextsettings",
")",
")",
"||",
"(",
"!",
"empty",
"(",
"$",
"linksettings",
")",
"&&",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"linksettings",
")",
")",
")",
"{",
"unset",
"(",
"$",
"systemsettings",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"contextsettings",
")",
")",
"{",
"foreach",
"(",
"$",
"contextsettings",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"linksettings",
")",
"&&",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"linksettings",
")",
")",
"{",
"unset",
"(",
"$",
"contextsettings",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"}",
"}"
] |
Get the distinct settings from each level by removing any duplicates from higher levels.
@param array $systemsettings System level settings
@param array $contextsettings Context level settings
@param array $linksettings Link level settings
|
[
"Get",
"the",
"distinct",
"settings",
"from",
"each",
"level",
"by",
"removing",
"any",
"duplicates",
"from",
"higher",
"levels",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lti/service/toolsettings/classes/local/service/toolsettings.php#L77-L94
|
218,051
|
moodle/moodle
|
mod/lti/service/toolsettings/classes/local/service/toolsettings.php
|
toolsettings.settings_to_json
|
public static function settings_to_json($settings, $simpleformat, $type, $resource) {
$json = '';
if (!empty($resource)) {
$indent = '';
if (!$simpleformat) {
$json .= " {\n \"@type\":\"{$type}\",\n";
$json .= " \"@id\":\"{$resource->get_endpoint()}\",\n";
$json .= " \"custom\":{\n";
$json .= " \"@id\":\"{$resource->get_endpoint()}/custom\"";
$indent = ' ';
}
$isfirst = $simpleformat;
if (!empty($settings)) {
foreach ($settings as $key => $value) {
if (!$isfirst) {
$json .= ',';
} else {
$isfirst = false;
}
$json .= "\n{$indent} \"{$key}\":\"{$value}\"";
}
}
if (!$simpleformat) {
$json .= "\n{$indent}}\n }";
}
}
return $json;
}
|
php
|
public static function settings_to_json($settings, $simpleformat, $type, $resource) {
$json = '';
if (!empty($resource)) {
$indent = '';
if (!$simpleformat) {
$json .= " {\n \"@type\":\"{$type}\",\n";
$json .= " \"@id\":\"{$resource->get_endpoint()}\",\n";
$json .= " \"custom\":{\n";
$json .= " \"@id\":\"{$resource->get_endpoint()}/custom\"";
$indent = ' ';
}
$isfirst = $simpleformat;
if (!empty($settings)) {
foreach ($settings as $key => $value) {
if (!$isfirst) {
$json .= ',';
} else {
$isfirst = false;
}
$json .= "\n{$indent} \"{$key}\":\"{$value}\"";
}
}
if (!$simpleformat) {
$json .= "\n{$indent}}\n }";
}
}
return $json;
}
|
[
"public",
"static",
"function",
"settings_to_json",
"(",
"$",
"settings",
",",
"$",
"simpleformat",
",",
"$",
"type",
",",
"$",
"resource",
")",
"{",
"$",
"json",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"resource",
")",
")",
"{",
"$",
"indent",
"=",
"''",
";",
"if",
"(",
"!",
"$",
"simpleformat",
")",
"{",
"$",
"json",
".=",
"\" {\\n \\\"@type\\\":\\\"{$type}\\\",\\n\"",
";",
"$",
"json",
".=",
"\" \\\"@id\\\":\\\"{$resource->get_endpoint()}\\\",\\n\"",
";",
"$",
"json",
".=",
"\" \\\"custom\\\":{\\n\"",
";",
"$",
"json",
".=",
"\" \\\"@id\\\":\\\"{$resource->get_endpoint()}/custom\\\"\"",
";",
"$",
"indent",
"=",
"' '",
";",
"}",
"$",
"isfirst",
"=",
"$",
"simpleformat",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"settings",
")",
")",
"{",
"foreach",
"(",
"$",
"settings",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"$",
"isfirst",
")",
"{",
"$",
"json",
".=",
"','",
";",
"}",
"else",
"{",
"$",
"isfirst",
"=",
"false",
";",
"}",
"$",
"json",
".=",
"\"\\n{$indent} \\\"{$key}\\\":\\\"{$value}\\\"\"",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"simpleformat",
")",
"{",
"$",
"json",
".=",
"\"\\n{$indent}}\\n }\"",
";",
"}",
"}",
"return",
"$",
"json",
";",
"}"
] |
Get the JSON representation of the settings.
@param array $settings Settings
@param boolean $simpleformat <code>true</code> if simple JSON is to be returned
@param string $type JSON-LD type
@param \mod_lti\local\ltiservice\resource_base $resource Resource handling the request
@return string
|
[
"Get",
"the",
"JSON",
"representation",
"of",
"the",
"settings",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lti/service/toolsettings/classes/local/service/toolsettings.php#L106-L136
|
218,052
|
moodle/moodle
|
auth/webservice/auth.php
|
auth_plugin_webservice.user_login_webservice
|
function user_login_webservice($username, $password) {
global $CFG, $DB;
// special web service login
if ($user = $DB->get_record('user', array('username'=>$username, 'mnethostid'=>$CFG->mnet_localhost_id))) {
return validate_internal_user_password($user, $password);
}
return false;
}
|
php
|
function user_login_webservice($username, $password) {
global $CFG, $DB;
// special web service login
if ($user = $DB->get_record('user', array('username'=>$username, 'mnethostid'=>$CFG->mnet_localhost_id))) {
return validate_internal_user_password($user, $password);
}
return false;
}
|
[
"function",
"user_login_webservice",
"(",
"$",
"username",
",",
"$",
"password",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
";",
"// special web service login",
"if",
"(",
"$",
"user",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'user'",
",",
"array",
"(",
"'username'",
"=>",
"$",
"username",
",",
"'mnethostid'",
"=>",
"$",
"CFG",
"->",
"mnet_localhost_id",
")",
")",
")",
"{",
"return",
"validate_internal_user_password",
"(",
"$",
"user",
",",
"$",
"password",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Custom auth hook for web services.
@param string $username
@param string $password
@return bool success
|
[
"Custom",
"auth",
"hook",
"for",
"web",
"services",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/webservice/auth.php#L73-L80
|
218,053
|
moodle/moodle
|
rating/classes/external/util.php
|
util.external_ratings_structure
|
public static function external_ratings_structure() {
return new external_single_structure (
[
'contextid' => new external_value(PARAM_INT, 'Context id.'),
'component' => new external_value(PARAM_COMPONENT, 'Context name.'),
'ratingarea' => new external_value(PARAM_AREA, 'Rating area name.'),
'canviewall' => new external_value(PARAM_BOOL, 'Whether the user can view all the individual ratings.',
VALUE_OPTIONAL),
'canviewany' => new external_value(PARAM_BOOL, 'Whether the user can view aggregate of ratings of others.',
VALUE_OPTIONAL),
'scales' => new external_multiple_structure(
new external_single_structure (
[
'id' => new external_value(PARAM_INT, 'Scale id.'),
'courseid' => new external_value(PARAM_INT, 'Course id.', VALUE_OPTIONAL),
'name' => new external_value(PARAM_TEXT, 'Scale name (when a real scale is used).', VALUE_OPTIONAL),
'max' => new external_value(PARAM_INT, 'Max value for the scale.'),
'isnumeric' => new external_value(PARAM_BOOL, 'Whether is a numeric scale.'),
'items' => new external_multiple_structure(
new external_single_structure (
[
'value' => new external_value(PARAM_INT, 'Scale value/option id.'),
'name' => new external_value(PARAM_NOTAGS, 'Scale name.'),
]
), 'Scale items. Only returned for not numerical scales.', VALUE_OPTIONAL
)
], 'Scale information'
), 'Different scales used information', VALUE_OPTIONAL
),
'ratings' => new external_multiple_structure(
new external_single_structure (
[
'itemid' => new external_value(PARAM_INT, 'Item id.'),
'scaleid' => new external_value(PARAM_INT, 'Scale id.', VALUE_OPTIONAL),
'userid' => new external_value(PARAM_INT, 'User who rated id.', VALUE_OPTIONAL),
'aggregate' => new external_value(PARAM_FLOAT, 'Aggregated ratings grade.', VALUE_OPTIONAL),
'aggregatestr' => new external_value(PARAM_NOTAGS, 'Aggregated ratings as string.', VALUE_OPTIONAL),
'aggregatelabel' => new external_value(PARAM_NOTAGS, 'The aggregation label.', VALUE_OPTIONAL),
'count' => new external_value(PARAM_INT, 'Ratings count (used when aggregating).', VALUE_OPTIONAL),
'rating' => new external_value(PARAM_INT, 'The rating the user gave.', VALUE_OPTIONAL),
'canrate' => new external_value(PARAM_BOOL, 'Whether the user can rate the item.', VALUE_OPTIONAL),
'canviewaggregate' => new external_value(PARAM_BOOL, 'Whether the user can view the aggregated grade.',
VALUE_OPTIONAL),
]
), 'The ratings', VALUE_OPTIONAL
),
], 'Rating information', VALUE_OPTIONAL
);
}
|
php
|
public static function external_ratings_structure() {
return new external_single_structure (
[
'contextid' => new external_value(PARAM_INT, 'Context id.'),
'component' => new external_value(PARAM_COMPONENT, 'Context name.'),
'ratingarea' => new external_value(PARAM_AREA, 'Rating area name.'),
'canviewall' => new external_value(PARAM_BOOL, 'Whether the user can view all the individual ratings.',
VALUE_OPTIONAL),
'canviewany' => new external_value(PARAM_BOOL, 'Whether the user can view aggregate of ratings of others.',
VALUE_OPTIONAL),
'scales' => new external_multiple_structure(
new external_single_structure (
[
'id' => new external_value(PARAM_INT, 'Scale id.'),
'courseid' => new external_value(PARAM_INT, 'Course id.', VALUE_OPTIONAL),
'name' => new external_value(PARAM_TEXT, 'Scale name (when a real scale is used).', VALUE_OPTIONAL),
'max' => new external_value(PARAM_INT, 'Max value for the scale.'),
'isnumeric' => new external_value(PARAM_BOOL, 'Whether is a numeric scale.'),
'items' => new external_multiple_structure(
new external_single_structure (
[
'value' => new external_value(PARAM_INT, 'Scale value/option id.'),
'name' => new external_value(PARAM_NOTAGS, 'Scale name.'),
]
), 'Scale items. Only returned for not numerical scales.', VALUE_OPTIONAL
)
], 'Scale information'
), 'Different scales used information', VALUE_OPTIONAL
),
'ratings' => new external_multiple_structure(
new external_single_structure (
[
'itemid' => new external_value(PARAM_INT, 'Item id.'),
'scaleid' => new external_value(PARAM_INT, 'Scale id.', VALUE_OPTIONAL),
'userid' => new external_value(PARAM_INT, 'User who rated id.', VALUE_OPTIONAL),
'aggregate' => new external_value(PARAM_FLOAT, 'Aggregated ratings grade.', VALUE_OPTIONAL),
'aggregatestr' => new external_value(PARAM_NOTAGS, 'Aggregated ratings as string.', VALUE_OPTIONAL),
'aggregatelabel' => new external_value(PARAM_NOTAGS, 'The aggregation label.', VALUE_OPTIONAL),
'count' => new external_value(PARAM_INT, 'Ratings count (used when aggregating).', VALUE_OPTIONAL),
'rating' => new external_value(PARAM_INT, 'The rating the user gave.', VALUE_OPTIONAL),
'canrate' => new external_value(PARAM_BOOL, 'Whether the user can rate the item.', VALUE_OPTIONAL),
'canviewaggregate' => new external_value(PARAM_BOOL, 'Whether the user can view the aggregated grade.',
VALUE_OPTIONAL),
]
), 'The ratings', VALUE_OPTIONAL
),
], 'Rating information', VALUE_OPTIONAL
);
}
|
[
"public",
"static",
"function",
"external_ratings_structure",
"(",
")",
"{",
"return",
"new",
"external_single_structure",
"(",
"[",
"'contextid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Context id.'",
")",
",",
"'component'",
"=>",
"new",
"external_value",
"(",
"PARAM_COMPONENT",
",",
"'Context name.'",
")",
",",
"'ratingarea'",
"=>",
"new",
"external_value",
"(",
"PARAM_AREA",
",",
"'Rating area name.'",
")",
",",
"'canviewall'",
"=>",
"new",
"external_value",
"(",
"PARAM_BOOL",
",",
"'Whether the user can view all the individual ratings.'",
",",
"VALUE_OPTIONAL",
")",
",",
"'canviewany'",
"=>",
"new",
"external_value",
"(",
"PARAM_BOOL",
",",
"'Whether the user can view aggregate of ratings of others.'",
",",
"VALUE_OPTIONAL",
")",
",",
"'scales'",
"=>",
"new",
"external_multiple_structure",
"(",
"new",
"external_single_structure",
"(",
"[",
"'id'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Scale id.'",
")",
",",
"'courseid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Course id.'",
",",
"VALUE_OPTIONAL",
")",
",",
"'name'",
"=>",
"new",
"external_value",
"(",
"PARAM_TEXT",
",",
"'Scale name (when a real scale is used).'",
",",
"VALUE_OPTIONAL",
")",
",",
"'max'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Max value for the scale.'",
")",
",",
"'isnumeric'",
"=>",
"new",
"external_value",
"(",
"PARAM_BOOL",
",",
"'Whether is a numeric scale.'",
")",
",",
"'items'",
"=>",
"new",
"external_multiple_structure",
"(",
"new",
"external_single_structure",
"(",
"[",
"'value'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Scale value/option id.'",
")",
",",
"'name'",
"=>",
"new",
"external_value",
"(",
"PARAM_NOTAGS",
",",
"'Scale name.'",
")",
",",
"]",
")",
",",
"'Scale items. Only returned for not numerical scales.'",
",",
"VALUE_OPTIONAL",
")",
"]",
",",
"'Scale information'",
")",
",",
"'Different scales used information'",
",",
"VALUE_OPTIONAL",
")",
",",
"'ratings'",
"=>",
"new",
"external_multiple_structure",
"(",
"new",
"external_single_structure",
"(",
"[",
"'itemid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Item id.'",
")",
",",
"'scaleid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Scale id.'",
",",
"VALUE_OPTIONAL",
")",
",",
"'userid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'User who rated id.'",
",",
"VALUE_OPTIONAL",
")",
",",
"'aggregate'",
"=>",
"new",
"external_value",
"(",
"PARAM_FLOAT",
",",
"'Aggregated ratings grade.'",
",",
"VALUE_OPTIONAL",
")",
",",
"'aggregatestr'",
"=>",
"new",
"external_value",
"(",
"PARAM_NOTAGS",
",",
"'Aggregated ratings as string.'",
",",
"VALUE_OPTIONAL",
")",
",",
"'aggregatelabel'",
"=>",
"new",
"external_value",
"(",
"PARAM_NOTAGS",
",",
"'The aggregation label.'",
",",
"VALUE_OPTIONAL",
")",
",",
"'count'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Ratings count (used when aggregating).'",
",",
"VALUE_OPTIONAL",
")",
",",
"'rating'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'The rating the user gave.'",
",",
"VALUE_OPTIONAL",
")",
",",
"'canrate'",
"=>",
"new",
"external_value",
"(",
"PARAM_BOOL",
",",
"'Whether the user can rate the item.'",
",",
"VALUE_OPTIONAL",
")",
",",
"'canviewaggregate'",
"=>",
"new",
"external_value",
"(",
"PARAM_BOOL",
",",
"'Whether the user can view the aggregated grade.'",
",",
"VALUE_OPTIONAL",
")",
",",
"]",
")",
",",
"'The ratings'",
",",
"VALUE_OPTIONAL",
")",
",",
"]",
",",
"'Rating information'",
",",
"VALUE_OPTIONAL",
")",
";",
"}"
] |
Returns the ratings definition for external functions.
|
[
"Returns",
"the",
"ratings",
"definition",
"for",
"external",
"functions",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/rating/classes/external/util.php#L51-L100
|
218,054
|
moodle/moodle
|
mod/wiki/parser/markups/wikimarkup.php
|
wiki_markup_parser.before_parsing
|
protected function before_parsing() {
$this->toc = array();
$this->string = preg_replace('/\r\n/', "\n", $this->string);
$this->string = preg_replace('/\r/', "\n", $this->string);
$this->string .= "\n\n";
if (!$this->printable && $this->section_editing) {
$this->returnvalues['unparsed_text'] = $this->string;
$this->string = $this->get_repeated_sections($this->string);
}
}
|
php
|
protected function before_parsing() {
$this->toc = array();
$this->string = preg_replace('/\r\n/', "\n", $this->string);
$this->string = preg_replace('/\r/', "\n", $this->string);
$this->string .= "\n\n";
if (!$this->printable && $this->section_editing) {
$this->returnvalues['unparsed_text'] = $this->string;
$this->string = $this->get_repeated_sections($this->string);
}
}
|
[
"protected",
"function",
"before_parsing",
"(",
")",
"{",
"$",
"this",
"->",
"toc",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"string",
"=",
"preg_replace",
"(",
"'/\\r\\n/'",
",",
"\"\\n\"",
",",
"$",
"this",
"->",
"string",
")",
";",
"$",
"this",
"->",
"string",
"=",
"preg_replace",
"(",
"'/\\r/'",
",",
"\"\\n\"",
",",
"$",
"this",
"->",
"string",
")",
";",
"$",
"this",
"->",
"string",
".=",
"\"\\n\\n\"",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"printable",
"&&",
"$",
"this",
"->",
"section_editing",
")",
"{",
"$",
"this",
"->",
"returnvalues",
"[",
"'unparsed_text'",
"]",
"=",
"$",
"this",
"->",
"string",
";",
"$",
"this",
"->",
"string",
"=",
"$",
"this",
"->",
"get_repeated_sections",
"(",
"$",
"this",
"->",
"string",
")",
";",
"}",
"}"
] |
Before and after parsing...
|
[
"Before",
"and",
"after",
"parsing",
"..."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/parser/markups/wikimarkup.php#L53-L65
|
218,055
|
moodle/moodle
|
mod/wiki/parser/markups/wikimarkup.php
|
wiki_markup_parser.process_toc
|
protected function process_toc() {
if (empty($this->toc)) {
return;
}
$toc = "";
$currentsection = array(0, 0, 0);
$i = 1;
foreach ($this->toc as & $header) {
switch ($header[0]) {
case 1:
$currentsection = array($currentsection[0] + 1, 0, 0);
break;
case 2:
$currentsection[1]++;
$currentsection[2] = 0;
if ($currentsection[0] == 0) {
$currentsection[0]++;
}
break;
case 3:
$currentsection[2]++;
if ($currentsection[1] == 0) {
$currentsection[1]++;
}
if ($currentsection[0] == 0) {
$currentsection[0]++;
}
break;
default:
continue 2;
}
$number = "$currentsection[0]";
if (!empty($currentsection[1])) {
$number .= ".$currentsection[1]";
if (!empty($currentsection[2])) {
$number .= ".$currentsection[2]";
}
}
$toc .= parser_utils::h('p', $number . ". " .
parser_utils::h('a', str_replace(array('[[', ']]'), '', $header[1]), array('href' => "#toc-$i")),
array('class' => 'wiki-toc-section-' . $header[0] . " wiki-toc-section"));
$i++;
}
$this->returnvalues['toc'] = "<div class=\"wiki-toc\"><p class=\"wiki-toc-title\">" . get_string('tableofcontents', 'wiki') . "</p>$toc</div>";
}
|
php
|
protected function process_toc() {
if (empty($this->toc)) {
return;
}
$toc = "";
$currentsection = array(0, 0, 0);
$i = 1;
foreach ($this->toc as & $header) {
switch ($header[0]) {
case 1:
$currentsection = array($currentsection[0] + 1, 0, 0);
break;
case 2:
$currentsection[1]++;
$currentsection[2] = 0;
if ($currentsection[0] == 0) {
$currentsection[0]++;
}
break;
case 3:
$currentsection[2]++;
if ($currentsection[1] == 0) {
$currentsection[1]++;
}
if ($currentsection[0] == 0) {
$currentsection[0]++;
}
break;
default:
continue 2;
}
$number = "$currentsection[0]";
if (!empty($currentsection[1])) {
$number .= ".$currentsection[1]";
if (!empty($currentsection[2])) {
$number .= ".$currentsection[2]";
}
}
$toc .= parser_utils::h('p', $number . ". " .
parser_utils::h('a', str_replace(array('[[', ']]'), '', $header[1]), array('href' => "#toc-$i")),
array('class' => 'wiki-toc-section-' . $header[0] . " wiki-toc-section"));
$i++;
}
$this->returnvalues['toc'] = "<div class=\"wiki-toc\"><p class=\"wiki-toc-title\">" . get_string('tableofcontents', 'wiki') . "</p>$toc</div>";
}
|
[
"protected",
"function",
"process_toc",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"toc",
")",
")",
"{",
"return",
";",
"}",
"$",
"toc",
"=",
"\"\"",
";",
"$",
"currentsection",
"=",
"array",
"(",
"0",
",",
"0",
",",
"0",
")",
";",
"$",
"i",
"=",
"1",
";",
"foreach",
"(",
"$",
"this",
"->",
"toc",
"as",
"&",
"$",
"header",
")",
"{",
"switch",
"(",
"$",
"header",
"[",
"0",
"]",
")",
"{",
"case",
"1",
":",
"$",
"currentsection",
"=",
"array",
"(",
"$",
"currentsection",
"[",
"0",
"]",
"+",
"1",
",",
"0",
",",
"0",
")",
";",
"break",
";",
"case",
"2",
":",
"$",
"currentsection",
"[",
"1",
"]",
"++",
";",
"$",
"currentsection",
"[",
"2",
"]",
"=",
"0",
";",
"if",
"(",
"$",
"currentsection",
"[",
"0",
"]",
"==",
"0",
")",
"{",
"$",
"currentsection",
"[",
"0",
"]",
"++",
";",
"}",
"break",
";",
"case",
"3",
":",
"$",
"currentsection",
"[",
"2",
"]",
"++",
";",
"if",
"(",
"$",
"currentsection",
"[",
"1",
"]",
"==",
"0",
")",
"{",
"$",
"currentsection",
"[",
"1",
"]",
"++",
";",
"}",
"if",
"(",
"$",
"currentsection",
"[",
"0",
"]",
"==",
"0",
")",
"{",
"$",
"currentsection",
"[",
"0",
"]",
"++",
";",
"}",
"break",
";",
"default",
":",
"continue",
"2",
";",
"}",
"$",
"number",
"=",
"\"$currentsection[0]\"",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"currentsection",
"[",
"1",
"]",
")",
")",
"{",
"$",
"number",
".=",
"\".$currentsection[1]\"",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"currentsection",
"[",
"2",
"]",
")",
")",
"{",
"$",
"number",
".=",
"\".$currentsection[2]\"",
";",
"}",
"}",
"$",
"toc",
".=",
"parser_utils",
"::",
"h",
"(",
"'p'",
",",
"$",
"number",
".",
"\". \"",
".",
"parser_utils",
"::",
"h",
"(",
"'a'",
",",
"str_replace",
"(",
"array",
"(",
"'[['",
",",
"']]'",
")",
",",
"''",
",",
"$",
"header",
"[",
"1",
"]",
")",
",",
"array",
"(",
"'href'",
"=>",
"\"#toc-$i\"",
")",
")",
",",
"array",
"(",
"'class'",
"=>",
"'wiki-toc-section-'",
".",
"$",
"header",
"[",
"0",
"]",
".",
"\" wiki-toc-section\"",
")",
")",
";",
"$",
"i",
"++",
";",
"}",
"$",
"this",
"->",
"returnvalues",
"[",
"'toc'",
"]",
"=",
"\"<div class=\\\"wiki-toc\\\"><p class=\\\"wiki-toc-title\\\">\"",
".",
"get_string",
"(",
"'tableofcontents'",
",",
"'wiki'",
")",
".",
"\"</p>$toc</div>\"",
";",
"}"
] |
Table of contents processing after parsing
|
[
"Table",
"of",
"contents",
"processing",
"after",
"parsing"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/parser/markups/wikimarkup.php#L204-L250
|
218,056
|
moodle/moodle
|
mod/wiki/parser/markups/wikimarkup.php
|
wiki_markup_parser.link
|
protected function link($link, $anchor = "") {
$link = trim($link);
if (preg_match("/^(https?|s?ftp):\/\/.+$/i", $link)) {
$link = trim($link, ",.?!");
return array('content' => $link, 'url' => $link);
} else {
$callbackargs = $this->linkgeneratorcallbackargs;
$callbackargs['anchor'] = $anchor;
$link = call_user_func_array($this->linkgeneratorcallback, array($link, $callbackargs));
if (isset($link['link_info'])) {
$l = $link['link_info']['link'];
unset($link['link_info']['link']);
$this->returnvalues['link_count'][$l] = $link['link_info'];
}
return $link;
}
}
|
php
|
protected function link($link, $anchor = "") {
$link = trim($link);
if (preg_match("/^(https?|s?ftp):\/\/.+$/i", $link)) {
$link = trim($link, ",.?!");
return array('content' => $link, 'url' => $link);
} else {
$callbackargs = $this->linkgeneratorcallbackargs;
$callbackargs['anchor'] = $anchor;
$link = call_user_func_array($this->linkgeneratorcallback, array($link, $callbackargs));
if (isset($link['link_info'])) {
$l = $link['link_info']['link'];
unset($link['link_info']['link']);
$this->returnvalues['link_count'][$l] = $link['link_info'];
}
return $link;
}
}
|
[
"protected",
"function",
"link",
"(",
"$",
"link",
",",
"$",
"anchor",
"=",
"\"\"",
")",
"{",
"$",
"link",
"=",
"trim",
"(",
"$",
"link",
")",
";",
"if",
"(",
"preg_match",
"(",
"\"/^(https?|s?ftp):\\/\\/.+$/i\"",
",",
"$",
"link",
")",
")",
"{",
"$",
"link",
"=",
"trim",
"(",
"$",
"link",
",",
"\",.?!\"",
")",
";",
"return",
"array",
"(",
"'content'",
"=>",
"$",
"link",
",",
"'url'",
"=>",
"$",
"link",
")",
";",
"}",
"else",
"{",
"$",
"callbackargs",
"=",
"$",
"this",
"->",
"linkgeneratorcallbackargs",
";",
"$",
"callbackargs",
"[",
"'anchor'",
"]",
"=",
"$",
"anchor",
";",
"$",
"link",
"=",
"call_user_func_array",
"(",
"$",
"this",
"->",
"linkgeneratorcallback",
",",
"array",
"(",
"$",
"link",
",",
"$",
"callbackargs",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"link",
"[",
"'link_info'",
"]",
")",
")",
"{",
"$",
"l",
"=",
"$",
"link",
"[",
"'link_info'",
"]",
"[",
"'link'",
"]",
";",
"unset",
"(",
"$",
"link",
"[",
"'link_info'",
"]",
"[",
"'link'",
"]",
")",
";",
"$",
"this",
"->",
"returnvalues",
"[",
"'link_count'",
"]",
"[",
"$",
"l",
"]",
"=",
"$",
"link",
"[",
"'link_info'",
"]",
";",
"}",
"return",
"$",
"link",
";",
"}",
"}"
] |
Link internal callback
|
[
"Link",
"internal",
"callback"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/parser/markups/wikimarkup.php#L342-L359
|
218,057
|
moodle/moodle
|
mod/imscp/classes/external.php
|
mod_imscp_external.get_imscps_by_courses
|
public static function get_imscps_by_courses($courseids = array()) {
global $CFG;
$returnedimscps = array();
$warnings = array();
$params = self::validate_parameters(self::get_imscps_by_courses_parameters(), array('courseids' => $courseids));
$courses = array();
if (empty($params['courseids'])) {
$courses = enrol_get_my_courses();
$params['courseids'] = array_keys($courses);
}
// Ensure there are courseids to loop through.
if (!empty($params['courseids'])) {
list($courses, $warnings) = external_util::validate_courses($params['courseids'], $courses);
// Get the imscps in this course, this function checks users visibility permissions.
// We can avoid then additional validate_context calls.
$imscps = get_all_instances_in_courses("imscp", $courses);
foreach ($imscps as $imscp) {
$context = context_module::instance($imscp->coursemodule);
// Entry to return.
$imscpdetails = array();
// First, we return information that any user can see in the web interface.
$imscpdetails['id'] = $imscp->id;
$imscpdetails['coursemodule'] = $imscp->coursemodule;
$imscpdetails['course'] = $imscp->course;
$imscpdetails['name'] = external_format_string($imscp->name, $context->id);
if (has_capability('mod/imscp:view', $context)) {
// Format intro.
list($imscpdetails['intro'], $imscpdetails['introformat']) =
external_format_text($imscp->intro, $imscp->introformat, $context->id, 'mod_imscp', 'intro', null);
$imscpdetails['introfiles'] = external_util::get_area_files($context->id, 'mod_imscp', 'intro', false, false);
}
if (has_capability('moodle/course:manageactivities', $context)) {
$imscpdetails['revision'] = $imscp->revision;
$imscpdetails['keepold'] = $imscp->keepold;
$imscpdetails['structure'] = $imscp->structure;
$imscpdetails['timemodified'] = $imscp->timemodified;
$imscpdetails['section'] = $imscp->section;
$imscpdetails['visible'] = $imscp->visible;
$imscpdetails['groupmode'] = $imscp->groupmode;
$imscpdetails['groupingid'] = $imscp->groupingid;
}
$returnedimscps[] = $imscpdetails;
}
}
$result = array();
$result['imscps'] = $returnedimscps;
$result['warnings'] = $warnings;
return $result;
}
|
php
|
public static function get_imscps_by_courses($courseids = array()) {
global $CFG;
$returnedimscps = array();
$warnings = array();
$params = self::validate_parameters(self::get_imscps_by_courses_parameters(), array('courseids' => $courseids));
$courses = array();
if (empty($params['courseids'])) {
$courses = enrol_get_my_courses();
$params['courseids'] = array_keys($courses);
}
// Ensure there are courseids to loop through.
if (!empty($params['courseids'])) {
list($courses, $warnings) = external_util::validate_courses($params['courseids'], $courses);
// Get the imscps in this course, this function checks users visibility permissions.
// We can avoid then additional validate_context calls.
$imscps = get_all_instances_in_courses("imscp", $courses);
foreach ($imscps as $imscp) {
$context = context_module::instance($imscp->coursemodule);
// Entry to return.
$imscpdetails = array();
// First, we return information that any user can see in the web interface.
$imscpdetails['id'] = $imscp->id;
$imscpdetails['coursemodule'] = $imscp->coursemodule;
$imscpdetails['course'] = $imscp->course;
$imscpdetails['name'] = external_format_string($imscp->name, $context->id);
if (has_capability('mod/imscp:view', $context)) {
// Format intro.
list($imscpdetails['intro'], $imscpdetails['introformat']) =
external_format_text($imscp->intro, $imscp->introformat, $context->id, 'mod_imscp', 'intro', null);
$imscpdetails['introfiles'] = external_util::get_area_files($context->id, 'mod_imscp', 'intro', false, false);
}
if (has_capability('moodle/course:manageactivities', $context)) {
$imscpdetails['revision'] = $imscp->revision;
$imscpdetails['keepold'] = $imscp->keepold;
$imscpdetails['structure'] = $imscp->structure;
$imscpdetails['timemodified'] = $imscp->timemodified;
$imscpdetails['section'] = $imscp->section;
$imscpdetails['visible'] = $imscp->visible;
$imscpdetails['groupmode'] = $imscp->groupmode;
$imscpdetails['groupingid'] = $imscp->groupingid;
}
$returnedimscps[] = $imscpdetails;
}
}
$result = array();
$result['imscps'] = $returnedimscps;
$result['warnings'] = $warnings;
return $result;
}
|
[
"public",
"static",
"function",
"get_imscps_by_courses",
"(",
"$",
"courseids",
"=",
"array",
"(",
")",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"returnedimscps",
"=",
"array",
"(",
")",
";",
"$",
"warnings",
"=",
"array",
"(",
")",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_imscps_by_courses_parameters",
"(",
")",
",",
"array",
"(",
"'courseids'",
"=>",
"$",
"courseids",
")",
")",
";",
"$",
"courses",
"=",
"array",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"params",
"[",
"'courseids'",
"]",
")",
")",
"{",
"$",
"courses",
"=",
"enrol_get_my_courses",
"(",
")",
";",
"$",
"params",
"[",
"'courseids'",
"]",
"=",
"array_keys",
"(",
"$",
"courses",
")",
";",
"}",
"// Ensure there are courseids to loop through.",
"if",
"(",
"!",
"empty",
"(",
"$",
"params",
"[",
"'courseids'",
"]",
")",
")",
"{",
"list",
"(",
"$",
"courses",
",",
"$",
"warnings",
")",
"=",
"external_util",
"::",
"validate_courses",
"(",
"$",
"params",
"[",
"'courseids'",
"]",
",",
"$",
"courses",
")",
";",
"// Get the imscps in this course, this function checks users visibility permissions.",
"// We can avoid then additional validate_context calls.",
"$",
"imscps",
"=",
"get_all_instances_in_courses",
"(",
"\"imscp\"",
",",
"$",
"courses",
")",
";",
"foreach",
"(",
"$",
"imscps",
"as",
"$",
"imscp",
")",
"{",
"$",
"context",
"=",
"context_module",
"::",
"instance",
"(",
"$",
"imscp",
"->",
"coursemodule",
")",
";",
"// Entry to return.",
"$",
"imscpdetails",
"=",
"array",
"(",
")",
";",
"// First, we return information that any user can see in the web interface.",
"$",
"imscpdetails",
"[",
"'id'",
"]",
"=",
"$",
"imscp",
"->",
"id",
";",
"$",
"imscpdetails",
"[",
"'coursemodule'",
"]",
"=",
"$",
"imscp",
"->",
"coursemodule",
";",
"$",
"imscpdetails",
"[",
"'course'",
"]",
"=",
"$",
"imscp",
"->",
"course",
";",
"$",
"imscpdetails",
"[",
"'name'",
"]",
"=",
"external_format_string",
"(",
"$",
"imscp",
"->",
"name",
",",
"$",
"context",
"->",
"id",
")",
";",
"if",
"(",
"has_capability",
"(",
"'mod/imscp:view'",
",",
"$",
"context",
")",
")",
"{",
"// Format intro.",
"list",
"(",
"$",
"imscpdetails",
"[",
"'intro'",
"]",
",",
"$",
"imscpdetails",
"[",
"'introformat'",
"]",
")",
"=",
"external_format_text",
"(",
"$",
"imscp",
"->",
"intro",
",",
"$",
"imscp",
"->",
"introformat",
",",
"$",
"context",
"->",
"id",
",",
"'mod_imscp'",
",",
"'intro'",
",",
"null",
")",
";",
"$",
"imscpdetails",
"[",
"'introfiles'",
"]",
"=",
"external_util",
"::",
"get_area_files",
"(",
"$",
"context",
"->",
"id",
",",
"'mod_imscp'",
",",
"'intro'",
",",
"false",
",",
"false",
")",
";",
"}",
"if",
"(",
"has_capability",
"(",
"'moodle/course:manageactivities'",
",",
"$",
"context",
")",
")",
"{",
"$",
"imscpdetails",
"[",
"'revision'",
"]",
"=",
"$",
"imscp",
"->",
"revision",
";",
"$",
"imscpdetails",
"[",
"'keepold'",
"]",
"=",
"$",
"imscp",
"->",
"keepold",
";",
"$",
"imscpdetails",
"[",
"'structure'",
"]",
"=",
"$",
"imscp",
"->",
"structure",
";",
"$",
"imscpdetails",
"[",
"'timemodified'",
"]",
"=",
"$",
"imscp",
"->",
"timemodified",
";",
"$",
"imscpdetails",
"[",
"'section'",
"]",
"=",
"$",
"imscp",
"->",
"section",
";",
"$",
"imscpdetails",
"[",
"'visible'",
"]",
"=",
"$",
"imscp",
"->",
"visible",
";",
"$",
"imscpdetails",
"[",
"'groupmode'",
"]",
"=",
"$",
"imscp",
"->",
"groupmode",
";",
"$",
"imscpdetails",
"[",
"'groupingid'",
"]",
"=",
"$",
"imscp",
"->",
"groupingid",
";",
"}",
"$",
"returnedimscps",
"[",
"]",
"=",
"$",
"imscpdetails",
";",
"}",
"}",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"result",
"[",
"'imscps'",
"]",
"=",
"$",
"returnedimscps",
";",
"$",
"result",
"[",
"'warnings'",
"]",
"=",
"$",
"warnings",
";",
"return",
"$",
"result",
";",
"}"
] |
Returns a list of IMSCP packages in a provided list of courses,
if no list is provided all IMSCP packages that the user can view will be returned.
@param array $courseids the course ids
@return array of IMSCP packages details and possible warnings
@since Moodle 3.0
|
[
"Returns",
"a",
"list",
"of",
"IMSCP",
"packages",
"in",
"a",
"provided",
"list",
"of",
"courses",
"if",
"no",
"list",
"is",
"provided",
"all",
"IMSCP",
"packages",
"that",
"the",
"user",
"can",
"view",
"will",
"be",
"returned",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/imscp/classes/external.php#L131-L188
|
218,058
|
moodle/moodle
|
mod/imscp/classes/external.php
|
mod_imscp_external.get_imscps_by_courses_returns
|
public static function get_imscps_by_courses_returns() {
return new external_single_structure(
array(
'imscps' => new external_multiple_structure(
new external_single_structure(
array(
'id' => new external_value(PARAM_INT, 'IMSCP id'),
'coursemodule' => new external_value(PARAM_INT, 'Course module id'),
'course' => new external_value(PARAM_INT, 'Course id'),
'name' => new external_value(PARAM_RAW, 'Activity name'),
'intro' => new external_value(PARAM_RAW, 'The IMSCP intro', VALUE_OPTIONAL),
'introformat' => new external_format_value('intro', VALUE_OPTIONAL),
'introfiles' => new external_files('Files in the introduction text', VALUE_OPTIONAL),
'revision' => new external_value(PARAM_INT, 'Revision', VALUE_OPTIONAL),
'keepold' => new external_value(PARAM_INT, 'Number of old IMSCP to keep', VALUE_OPTIONAL),
'structure' => new external_value(PARAM_RAW, 'IMSCP structure', VALUE_OPTIONAL),
'timemodified' => new external_value(PARAM_RAW, 'Time of last modification', VALUE_OPTIONAL),
'section' => new external_value(PARAM_INT, 'Course section id', VALUE_OPTIONAL),
'visible' => new external_value(PARAM_BOOL, 'If visible', VALUE_OPTIONAL),
'groupmode' => new external_value(PARAM_INT, 'Group mode', VALUE_OPTIONAL),
'groupingid' => new external_value(PARAM_INT, 'Group id', VALUE_OPTIONAL),
), 'IMS content packages'
)
),
'warnings' => new external_warnings(),
)
);
}
|
php
|
public static function get_imscps_by_courses_returns() {
return new external_single_structure(
array(
'imscps' => new external_multiple_structure(
new external_single_structure(
array(
'id' => new external_value(PARAM_INT, 'IMSCP id'),
'coursemodule' => new external_value(PARAM_INT, 'Course module id'),
'course' => new external_value(PARAM_INT, 'Course id'),
'name' => new external_value(PARAM_RAW, 'Activity name'),
'intro' => new external_value(PARAM_RAW, 'The IMSCP intro', VALUE_OPTIONAL),
'introformat' => new external_format_value('intro', VALUE_OPTIONAL),
'introfiles' => new external_files('Files in the introduction text', VALUE_OPTIONAL),
'revision' => new external_value(PARAM_INT, 'Revision', VALUE_OPTIONAL),
'keepold' => new external_value(PARAM_INT, 'Number of old IMSCP to keep', VALUE_OPTIONAL),
'structure' => new external_value(PARAM_RAW, 'IMSCP structure', VALUE_OPTIONAL),
'timemodified' => new external_value(PARAM_RAW, 'Time of last modification', VALUE_OPTIONAL),
'section' => new external_value(PARAM_INT, 'Course section id', VALUE_OPTIONAL),
'visible' => new external_value(PARAM_BOOL, 'If visible', VALUE_OPTIONAL),
'groupmode' => new external_value(PARAM_INT, 'Group mode', VALUE_OPTIONAL),
'groupingid' => new external_value(PARAM_INT, 'Group id', VALUE_OPTIONAL),
), 'IMS content packages'
)
),
'warnings' => new external_warnings(),
)
);
}
|
[
"public",
"static",
"function",
"get_imscps_by_courses_returns",
"(",
")",
"{",
"return",
"new",
"external_single_structure",
"(",
"array",
"(",
"'imscps'",
"=>",
"new",
"external_multiple_structure",
"(",
"new",
"external_single_structure",
"(",
"array",
"(",
"'id'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'IMSCP id'",
")",
",",
"'coursemodule'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Course module id'",
")",
",",
"'course'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Course id'",
")",
",",
"'name'",
"=>",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'Activity name'",
")",
",",
"'intro'",
"=>",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'The IMSCP intro'",
",",
"VALUE_OPTIONAL",
")",
",",
"'introformat'",
"=>",
"new",
"external_format_value",
"(",
"'intro'",
",",
"VALUE_OPTIONAL",
")",
",",
"'introfiles'",
"=>",
"new",
"external_files",
"(",
"'Files in the introduction text'",
",",
"VALUE_OPTIONAL",
")",
",",
"'revision'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Revision'",
",",
"VALUE_OPTIONAL",
")",
",",
"'keepold'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Number of old IMSCP to keep'",
",",
"VALUE_OPTIONAL",
")",
",",
"'structure'",
"=>",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'IMSCP structure'",
",",
"VALUE_OPTIONAL",
")",
",",
"'timemodified'",
"=>",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'Time of last modification'",
",",
"VALUE_OPTIONAL",
")",
",",
"'section'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Course section id'",
",",
"VALUE_OPTIONAL",
")",
",",
"'visible'",
"=>",
"new",
"external_value",
"(",
"PARAM_BOOL",
",",
"'If visible'",
",",
"VALUE_OPTIONAL",
")",
",",
"'groupmode'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Group mode'",
",",
"VALUE_OPTIONAL",
")",
",",
"'groupingid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Group id'",
",",
"VALUE_OPTIONAL",
")",
",",
")",
",",
"'IMS content packages'",
")",
")",
",",
"'warnings'",
"=>",
"new",
"external_warnings",
"(",
")",
",",
")",
")",
";",
"}"
] |
Describes the get_imscps_by_courses return value.
@return external_single_structure
@since Moodle 3.0
|
[
"Describes",
"the",
"get_imscps_by_courses",
"return",
"value",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/imscp/classes/external.php#L196-L223
|
218,059
|
moodle/moodle
|
enrol/externallib.php
|
core_enrol_external.get_potential_users_parameters
|
public static function get_potential_users_parameters() {
return new external_function_parameters(
array(
'courseid' => new external_value(PARAM_INT, 'course id'),
'enrolid' => new external_value(PARAM_INT, 'enrolment id'),
'search' => new external_value(PARAM_RAW, 'query'),
'searchanywhere' => new external_value(PARAM_BOOL, 'find a match anywhere, or only at the beginning'),
'page' => new external_value(PARAM_INT, 'Page number'),
'perpage' => new external_value(PARAM_INT, 'Number per page'),
)
);
}
|
php
|
public static function get_potential_users_parameters() {
return new external_function_parameters(
array(
'courseid' => new external_value(PARAM_INT, 'course id'),
'enrolid' => new external_value(PARAM_INT, 'enrolment id'),
'search' => new external_value(PARAM_RAW, 'query'),
'searchanywhere' => new external_value(PARAM_BOOL, 'find a match anywhere, or only at the beginning'),
'page' => new external_value(PARAM_INT, 'Page number'),
'perpage' => new external_value(PARAM_INT, 'Number per page'),
)
);
}
|
[
"public",
"static",
"function",
"get_potential_users_parameters",
"(",
")",
"{",
"return",
"new",
"external_function_parameters",
"(",
"array",
"(",
"'courseid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'course id'",
")",
",",
"'enrolid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'enrolment id'",
")",
",",
"'search'",
"=>",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'query'",
")",
",",
"'searchanywhere'",
"=>",
"new",
"external_value",
"(",
"PARAM_BOOL",
",",
"'find a match anywhere, or only at the beginning'",
")",
",",
"'page'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Page number'",
")",
",",
"'perpage'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Number per page'",
")",
",",
")",
")",
";",
"}"
] |
Returns description of method parameters value
@return external_description
|
[
"Returns",
"description",
"of",
"method",
"parameters",
"value"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/externallib.php#L497-L508
|
218,060
|
moodle/moodle
|
enrol/externallib.php
|
core_enrol_external.get_potential_users
|
public static function get_potential_users($courseid, $enrolid, $search, $searchanywhere, $page, $perpage) {
global $PAGE, $DB, $CFG;
require_once($CFG->dirroot.'/enrol/locallib.php');
require_once($CFG->dirroot.'/user/lib.php');
$params = self::validate_parameters(
self::get_potential_users_parameters(),
array(
'courseid' => $courseid,
'enrolid' => $enrolid,
'search' => $search,
'searchanywhere' => $searchanywhere,
'page' => $page,
'perpage' => $perpage
)
);
$context = context_course::instance($params['courseid']);
try {
self::validate_context($context);
} catch (Exception $e) {
$exceptionparam = new stdClass();
$exceptionparam->message = $e->getMessage();
$exceptionparam->courseid = $params['courseid'];
throw new moodle_exception('errorcoursecontextnotvalid' , 'webservice', '', $exceptionparam);
}
require_capability('moodle/course:enrolreview', $context);
$course = $DB->get_record('course', array('id' => $params['courseid']));
$manager = new course_enrolment_manager($PAGE, $course);
$users = $manager->get_potential_users($params['enrolid'],
$params['search'],
$params['searchanywhere'],
$params['page'],
$params['perpage']);
$results = array();
// Add also extra user fields.
$requiredfields = array_merge(
['id', 'fullname', 'profileimageurl', 'profileimageurlsmall'],
get_extra_user_fields($context)
);
foreach ($users['users'] as $id => $user) {
// Note: We pass the course here to validate that the current user can at least view user details in this course.
// The user we are looking at is not in this course yet though - but we only fetch the minimal set of
// user records, and the user has been validated to have course:enrolreview in this course. Otherwise
// there is no way to find users who aren't in the course in order to enrol them.
if ($userdetails = user_get_user_details($user, $course, $requiredfields)) {
$results[] = $userdetails;
}
}
return $results;
}
|
php
|
public static function get_potential_users($courseid, $enrolid, $search, $searchanywhere, $page, $perpage) {
global $PAGE, $DB, $CFG;
require_once($CFG->dirroot.'/enrol/locallib.php');
require_once($CFG->dirroot.'/user/lib.php');
$params = self::validate_parameters(
self::get_potential_users_parameters(),
array(
'courseid' => $courseid,
'enrolid' => $enrolid,
'search' => $search,
'searchanywhere' => $searchanywhere,
'page' => $page,
'perpage' => $perpage
)
);
$context = context_course::instance($params['courseid']);
try {
self::validate_context($context);
} catch (Exception $e) {
$exceptionparam = new stdClass();
$exceptionparam->message = $e->getMessage();
$exceptionparam->courseid = $params['courseid'];
throw new moodle_exception('errorcoursecontextnotvalid' , 'webservice', '', $exceptionparam);
}
require_capability('moodle/course:enrolreview', $context);
$course = $DB->get_record('course', array('id' => $params['courseid']));
$manager = new course_enrolment_manager($PAGE, $course);
$users = $manager->get_potential_users($params['enrolid'],
$params['search'],
$params['searchanywhere'],
$params['page'],
$params['perpage']);
$results = array();
// Add also extra user fields.
$requiredfields = array_merge(
['id', 'fullname', 'profileimageurl', 'profileimageurlsmall'],
get_extra_user_fields($context)
);
foreach ($users['users'] as $id => $user) {
// Note: We pass the course here to validate that the current user can at least view user details in this course.
// The user we are looking at is not in this course yet though - but we only fetch the minimal set of
// user records, and the user has been validated to have course:enrolreview in this course. Otherwise
// there is no way to find users who aren't in the course in order to enrol them.
if ($userdetails = user_get_user_details($user, $course, $requiredfields)) {
$results[] = $userdetails;
}
}
return $results;
}
|
[
"public",
"static",
"function",
"get_potential_users",
"(",
"$",
"courseid",
",",
"$",
"enrolid",
",",
"$",
"search",
",",
"$",
"searchanywhere",
",",
"$",
"page",
",",
"$",
"perpage",
")",
"{",
"global",
"$",
"PAGE",
",",
"$",
"DB",
",",
"$",
"CFG",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/enrol/locallib.php'",
")",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/user/lib.php'",
")",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_potential_users_parameters",
"(",
")",
",",
"array",
"(",
"'courseid'",
"=>",
"$",
"courseid",
",",
"'enrolid'",
"=>",
"$",
"enrolid",
",",
"'search'",
"=>",
"$",
"search",
",",
"'searchanywhere'",
"=>",
"$",
"searchanywhere",
",",
"'page'",
"=>",
"$",
"page",
",",
"'perpage'",
"=>",
"$",
"perpage",
")",
")",
";",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"params",
"[",
"'courseid'",
"]",
")",
";",
"try",
"{",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"exceptionparam",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"exceptionparam",
"->",
"message",
"=",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"$",
"exceptionparam",
"->",
"courseid",
"=",
"$",
"params",
"[",
"'courseid'",
"]",
";",
"throw",
"new",
"moodle_exception",
"(",
"'errorcoursecontextnotvalid'",
",",
"'webservice'",
",",
"''",
",",
"$",
"exceptionparam",
")",
";",
"}",
"require_capability",
"(",
"'moodle/course:enrolreview'",
",",
"$",
"context",
")",
";",
"$",
"course",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'course'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"params",
"[",
"'courseid'",
"]",
")",
")",
";",
"$",
"manager",
"=",
"new",
"course_enrolment_manager",
"(",
"$",
"PAGE",
",",
"$",
"course",
")",
";",
"$",
"users",
"=",
"$",
"manager",
"->",
"get_potential_users",
"(",
"$",
"params",
"[",
"'enrolid'",
"]",
",",
"$",
"params",
"[",
"'search'",
"]",
",",
"$",
"params",
"[",
"'searchanywhere'",
"]",
",",
"$",
"params",
"[",
"'page'",
"]",
",",
"$",
"params",
"[",
"'perpage'",
"]",
")",
";",
"$",
"results",
"=",
"array",
"(",
")",
";",
"// Add also extra user fields.",
"$",
"requiredfields",
"=",
"array_merge",
"(",
"[",
"'id'",
",",
"'fullname'",
",",
"'profileimageurl'",
",",
"'profileimageurlsmall'",
"]",
",",
"get_extra_user_fields",
"(",
"$",
"context",
")",
")",
";",
"foreach",
"(",
"$",
"users",
"[",
"'users'",
"]",
"as",
"$",
"id",
"=>",
"$",
"user",
")",
"{",
"// Note: We pass the course here to validate that the current user can at least view user details in this course.",
"// The user we are looking at is not in this course yet though - but we only fetch the minimal set of",
"// user records, and the user has been validated to have course:enrolreview in this course. Otherwise",
"// there is no way to find users who aren't in the course in order to enrol them.",
"if",
"(",
"$",
"userdetails",
"=",
"user_get_user_details",
"(",
"$",
"user",
",",
"$",
"course",
",",
"$",
"requiredfields",
")",
")",
"{",
"$",
"results",
"[",
"]",
"=",
"$",
"userdetails",
";",
"}",
"}",
"return",
"$",
"results",
";",
"}"
] |
Get potential users.
@param int $courseid Course id
@param int $enrolid Enrolment id
@param string $search The query
@param boolean $searchanywhere Match anywhere in the string
@param int $page Page number
@param int $perpage Max per page
@return array An array of users
|
[
"Get",
"potential",
"users",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/externallib.php#L521-L574
|
218,061
|
moodle/moodle
|
enrol/externallib.php
|
core_enrol_external.get_course_enrolment_methods
|
public static function get_course_enrolment_methods($courseid) {
global $DB;
$params = self::validate_parameters(self::get_course_enrolment_methods_parameters(), array('courseid' => $courseid));
self::validate_context(context_system::instance());
$course = $DB->get_record('course', array('id' => $params['courseid']), '*', MUST_EXIST);
if (!core_course_category::can_view_course_info($course) && !can_access_course($course)) {
throw new moodle_exception('coursehidden');
}
$result = array();
$enrolinstances = enrol_get_instances($params['courseid'], true);
foreach ($enrolinstances as $enrolinstance) {
if ($enrolplugin = enrol_get_plugin($enrolinstance->enrol)) {
if ($instanceinfo = $enrolplugin->get_enrol_info($enrolinstance)) {
$result[] = (array) $instanceinfo;
}
}
}
return $result;
}
|
php
|
public static function get_course_enrolment_methods($courseid) {
global $DB;
$params = self::validate_parameters(self::get_course_enrolment_methods_parameters(), array('courseid' => $courseid));
self::validate_context(context_system::instance());
$course = $DB->get_record('course', array('id' => $params['courseid']), '*', MUST_EXIST);
if (!core_course_category::can_view_course_info($course) && !can_access_course($course)) {
throw new moodle_exception('coursehidden');
}
$result = array();
$enrolinstances = enrol_get_instances($params['courseid'], true);
foreach ($enrolinstances as $enrolinstance) {
if ($enrolplugin = enrol_get_plugin($enrolinstance->enrol)) {
if ($instanceinfo = $enrolplugin->get_enrol_info($enrolinstance)) {
$result[] = (array) $instanceinfo;
}
}
}
return $result;
}
|
[
"public",
"static",
"function",
"get_course_enrolment_methods",
"(",
"$",
"courseid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_course_enrolment_methods_parameters",
"(",
")",
",",
"array",
"(",
"'courseid'",
"=>",
"$",
"courseid",
")",
")",
";",
"self",
"::",
"validate_context",
"(",
"context_system",
"::",
"instance",
"(",
")",
")",
";",
"$",
"course",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'course'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"params",
"[",
"'courseid'",
"]",
")",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"if",
"(",
"!",
"core_course_category",
"::",
"can_view_course_info",
"(",
"$",
"course",
")",
"&&",
"!",
"can_access_course",
"(",
"$",
"course",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'coursehidden'",
")",
";",
"}",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"enrolinstances",
"=",
"enrol_get_instances",
"(",
"$",
"params",
"[",
"'courseid'",
"]",
",",
"true",
")",
";",
"foreach",
"(",
"$",
"enrolinstances",
"as",
"$",
"enrolinstance",
")",
"{",
"if",
"(",
"$",
"enrolplugin",
"=",
"enrol_get_plugin",
"(",
"$",
"enrolinstance",
"->",
"enrol",
")",
")",
"{",
"if",
"(",
"$",
"instanceinfo",
"=",
"$",
"enrolplugin",
"->",
"get_enrol_info",
"(",
"$",
"enrolinstance",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"(",
"array",
")",
"$",
"instanceinfo",
";",
"}",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] |
Get list of active course enrolment methods for current user.
@param int $courseid
@return array of course enrolment methods
@throws moodle_exception
|
[
"Get",
"list",
"of",
"active",
"course",
"enrolment",
"methods",
"for",
"current",
"user",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/externallib.php#L876-L897
|
218,062
|
moodle/moodle
|
enrol/externallib.php
|
core_enrol_external.edit_user_enrolment
|
public static function edit_user_enrolment($courseid, $ueid, $status, $timestart = 0, $timeend = 0) {
global $CFG, $DB, $PAGE;
$params = self::validate_parameters(self::edit_user_enrolment_parameters(), [
'courseid' => $courseid,
'ueid' => $ueid,
'status' => $status,
'timestart' => $timestart,
'timeend' => $timeend,
]);
$course = get_course($courseid);
$context = context_course::instance($course->id);
self::validate_context($context);
$userenrolment = $DB->get_record('user_enrolments', ['id' => $params['ueid']], '*', MUST_EXIST);
$userenroldata = [
'status' => $params['status'],
'timestart' => $params['timestart'],
'timeend' => $params['timeend'],
];
$result = false;
$errors = [];
// Validate data against the edit user enrolment form.
$instance = $DB->get_record('enrol', ['id' => $userenrolment->enrolid], '*', MUST_EXIST);
$plugin = enrol_get_plugin($instance->enrol);
require_once("$CFG->dirroot/enrol/editenrolment_form.php");
$customformdata = [
'ue' => $userenrolment,
'modal' => true,
'enrolinstancename' => $plugin->get_instance_name($instance)
];
$mform = new \enrol_user_enrolment_form(null, $customformdata, 'post', '', null, true, $userenroldata);
$mform->set_data($userenroldata);
$validationerrors = $mform->validation($userenroldata, null);
if (empty($validationerrors)) {
require_once($CFG->dirroot . '/enrol/locallib.php');
$manager = new course_enrolment_manager($PAGE, $course);
$result = $manager->edit_enrolment($userenrolment, (object)$userenroldata);
} else {
foreach ($validationerrors as $key => $errormessage) {
$errors[] = (object)[
'key' => $key,
'message' => $errormessage
];
}
}
return [
'result' => $result,
'errors' => $errors,
];
}
|
php
|
public static function edit_user_enrolment($courseid, $ueid, $status, $timestart = 0, $timeend = 0) {
global $CFG, $DB, $PAGE;
$params = self::validate_parameters(self::edit_user_enrolment_parameters(), [
'courseid' => $courseid,
'ueid' => $ueid,
'status' => $status,
'timestart' => $timestart,
'timeend' => $timeend,
]);
$course = get_course($courseid);
$context = context_course::instance($course->id);
self::validate_context($context);
$userenrolment = $DB->get_record('user_enrolments', ['id' => $params['ueid']], '*', MUST_EXIST);
$userenroldata = [
'status' => $params['status'],
'timestart' => $params['timestart'],
'timeend' => $params['timeend'],
];
$result = false;
$errors = [];
// Validate data against the edit user enrolment form.
$instance = $DB->get_record('enrol', ['id' => $userenrolment->enrolid], '*', MUST_EXIST);
$plugin = enrol_get_plugin($instance->enrol);
require_once("$CFG->dirroot/enrol/editenrolment_form.php");
$customformdata = [
'ue' => $userenrolment,
'modal' => true,
'enrolinstancename' => $plugin->get_instance_name($instance)
];
$mform = new \enrol_user_enrolment_form(null, $customformdata, 'post', '', null, true, $userenroldata);
$mform->set_data($userenroldata);
$validationerrors = $mform->validation($userenroldata, null);
if (empty($validationerrors)) {
require_once($CFG->dirroot . '/enrol/locallib.php');
$manager = new course_enrolment_manager($PAGE, $course);
$result = $manager->edit_enrolment($userenrolment, (object)$userenroldata);
} else {
foreach ($validationerrors as $key => $errormessage) {
$errors[] = (object)[
'key' => $key,
'message' => $errormessage
];
}
}
return [
'result' => $result,
'errors' => $errors,
];
}
|
[
"public",
"static",
"function",
"edit_user_enrolment",
"(",
"$",
"courseid",
",",
"$",
"ueid",
",",
"$",
"status",
",",
"$",
"timestart",
"=",
"0",
",",
"$",
"timeend",
"=",
"0",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
",",
"$",
"PAGE",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"edit_user_enrolment_parameters",
"(",
")",
",",
"[",
"'courseid'",
"=>",
"$",
"courseid",
",",
"'ueid'",
"=>",
"$",
"ueid",
",",
"'status'",
"=>",
"$",
"status",
",",
"'timestart'",
"=>",
"$",
"timestart",
",",
"'timeend'",
"=>",
"$",
"timeend",
",",
"]",
")",
";",
"$",
"course",
"=",
"get_course",
"(",
"$",
"courseid",
")",
";",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"course",
"->",
"id",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"$",
"userenrolment",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'user_enrolments'",
",",
"[",
"'id'",
"=>",
"$",
"params",
"[",
"'ueid'",
"]",
"]",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"$",
"userenroldata",
"=",
"[",
"'status'",
"=>",
"$",
"params",
"[",
"'status'",
"]",
",",
"'timestart'",
"=>",
"$",
"params",
"[",
"'timestart'",
"]",
",",
"'timeend'",
"=>",
"$",
"params",
"[",
"'timeend'",
"]",
",",
"]",
";",
"$",
"result",
"=",
"false",
";",
"$",
"errors",
"=",
"[",
"]",
";",
"// Validate data against the edit user enrolment form.",
"$",
"instance",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'enrol'",
",",
"[",
"'id'",
"=>",
"$",
"userenrolment",
"->",
"enrolid",
"]",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"$",
"plugin",
"=",
"enrol_get_plugin",
"(",
"$",
"instance",
"->",
"enrol",
")",
";",
"require_once",
"(",
"\"$CFG->dirroot/enrol/editenrolment_form.php\"",
")",
";",
"$",
"customformdata",
"=",
"[",
"'ue'",
"=>",
"$",
"userenrolment",
",",
"'modal'",
"=>",
"true",
",",
"'enrolinstancename'",
"=>",
"$",
"plugin",
"->",
"get_instance_name",
"(",
"$",
"instance",
")",
"]",
";",
"$",
"mform",
"=",
"new",
"\\",
"enrol_user_enrolment_form",
"(",
"null",
",",
"$",
"customformdata",
",",
"'post'",
",",
"''",
",",
"null",
",",
"true",
",",
"$",
"userenroldata",
")",
";",
"$",
"mform",
"->",
"set_data",
"(",
"$",
"userenroldata",
")",
";",
"$",
"validationerrors",
"=",
"$",
"mform",
"->",
"validation",
"(",
"$",
"userenroldata",
",",
"null",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"validationerrors",
")",
")",
"{",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/enrol/locallib.php'",
")",
";",
"$",
"manager",
"=",
"new",
"course_enrolment_manager",
"(",
"$",
"PAGE",
",",
"$",
"course",
")",
";",
"$",
"result",
"=",
"$",
"manager",
"->",
"edit_enrolment",
"(",
"$",
"userenrolment",
",",
"(",
"object",
")",
"$",
"userenroldata",
")",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"validationerrors",
"as",
"$",
"key",
"=>",
"$",
"errormessage",
")",
"{",
"$",
"errors",
"[",
"]",
"=",
"(",
"object",
")",
"[",
"'key'",
"=>",
"$",
"key",
",",
"'message'",
"=>",
"$",
"errormessage",
"]",
";",
"}",
"}",
"return",
"[",
"'result'",
"=>",
"$",
"result",
",",
"'errors'",
"=>",
"$",
"errors",
",",
"]",
";",
"}"
] |
External function that updates a given user enrolment.
@param int $courseid The course ID.
@param int $ueid The user enrolment ID.
@param int $status The enrolment status.
@param int $timestart Enrolment start timestamp.
@param int $timeend Enrolment end timestamp.
@return array An array consisting of the processing result, errors and form output, if available.
|
[
"External",
"function",
"that",
"updates",
"a",
"given",
"user",
"enrolment",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/externallib.php#L946-L1000
|
218,063
|
moodle/moodle
|
enrol/externallib.php
|
core_enrol_external.unenrol_user_enrolment
|
public static function unenrol_user_enrolment($ueid) {
global $CFG, $DB, $PAGE;
$params = self::validate_parameters(self::unenrol_user_enrolment_parameters(), [
'ueid' => $ueid
]);
$result = false;
$errors = [];
$userenrolment = $DB->get_record('user_enrolments', ['id' => $params['ueid']], '*');
if ($userenrolment) {
$userid = $userenrolment->userid;
$enrolid = $userenrolment->enrolid;
$enrol = $DB->get_record('enrol', ['id' => $enrolid], '*', MUST_EXIST);
$courseid = $enrol->courseid;
$course = get_course($courseid);
$context = context_course::instance($course->id);
self::validate_context($context);
} else {
$validationerrors['invalidrequest'] = get_string('invalidrequest', 'enrol');
}
// If the userenrolment exists, unenrol the user.
if (!isset($validationerrors)) {
require_once($CFG->dirroot . '/enrol/locallib.php');
$manager = new course_enrolment_manager($PAGE, $course);
$result = $manager->unenrol_user($userenrolment);
} else {
foreach ($validationerrors as $key => $errormessage) {
$errors[] = (object)[
'key' => $key,
'message' => $errormessage
];
}
}
return [
'result' => $result,
'errors' => $errors,
];
}
|
php
|
public static function unenrol_user_enrolment($ueid) {
global $CFG, $DB, $PAGE;
$params = self::validate_parameters(self::unenrol_user_enrolment_parameters(), [
'ueid' => $ueid
]);
$result = false;
$errors = [];
$userenrolment = $DB->get_record('user_enrolments', ['id' => $params['ueid']], '*');
if ($userenrolment) {
$userid = $userenrolment->userid;
$enrolid = $userenrolment->enrolid;
$enrol = $DB->get_record('enrol', ['id' => $enrolid], '*', MUST_EXIST);
$courseid = $enrol->courseid;
$course = get_course($courseid);
$context = context_course::instance($course->id);
self::validate_context($context);
} else {
$validationerrors['invalidrequest'] = get_string('invalidrequest', 'enrol');
}
// If the userenrolment exists, unenrol the user.
if (!isset($validationerrors)) {
require_once($CFG->dirroot . '/enrol/locallib.php');
$manager = new course_enrolment_manager($PAGE, $course);
$result = $manager->unenrol_user($userenrolment);
} else {
foreach ($validationerrors as $key => $errormessage) {
$errors[] = (object)[
'key' => $key,
'message' => $errormessage
];
}
}
return [
'result' => $result,
'errors' => $errors,
];
}
|
[
"public",
"static",
"function",
"unenrol_user_enrolment",
"(",
"$",
"ueid",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
",",
"$",
"PAGE",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"unenrol_user_enrolment_parameters",
"(",
")",
",",
"[",
"'ueid'",
"=>",
"$",
"ueid",
"]",
")",
";",
"$",
"result",
"=",
"false",
";",
"$",
"errors",
"=",
"[",
"]",
";",
"$",
"userenrolment",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'user_enrolments'",
",",
"[",
"'id'",
"=>",
"$",
"params",
"[",
"'ueid'",
"]",
"]",
",",
"'*'",
")",
";",
"if",
"(",
"$",
"userenrolment",
")",
"{",
"$",
"userid",
"=",
"$",
"userenrolment",
"->",
"userid",
";",
"$",
"enrolid",
"=",
"$",
"userenrolment",
"->",
"enrolid",
";",
"$",
"enrol",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'enrol'",
",",
"[",
"'id'",
"=>",
"$",
"enrolid",
"]",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"$",
"courseid",
"=",
"$",
"enrol",
"->",
"courseid",
";",
"$",
"course",
"=",
"get_course",
"(",
"$",
"courseid",
")",
";",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"course",
"->",
"id",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"}",
"else",
"{",
"$",
"validationerrors",
"[",
"'invalidrequest'",
"]",
"=",
"get_string",
"(",
"'invalidrequest'",
",",
"'enrol'",
")",
";",
"}",
"// If the userenrolment exists, unenrol the user.",
"if",
"(",
"!",
"isset",
"(",
"$",
"validationerrors",
")",
")",
"{",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/enrol/locallib.php'",
")",
";",
"$",
"manager",
"=",
"new",
"course_enrolment_manager",
"(",
"$",
"PAGE",
",",
"$",
"course",
")",
";",
"$",
"result",
"=",
"$",
"manager",
"->",
"unenrol_user",
"(",
"$",
"userenrolment",
")",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"validationerrors",
"as",
"$",
"key",
"=>",
"$",
"errormessage",
")",
"{",
"$",
"errors",
"[",
"]",
"=",
"(",
"object",
")",
"[",
"'key'",
"=>",
"$",
"key",
",",
"'message'",
"=>",
"$",
"errormessage",
"]",
";",
"}",
"}",
"return",
"[",
"'result'",
"=>",
"$",
"result",
",",
"'errors'",
"=>",
"$",
"errors",
",",
"]",
";",
"}"
] |
External function that unenrols a given user enrolment.
@param int $ueid The user enrolment ID.
@return array An array consisting of the processing result, errors.
|
[
"External",
"function",
"that",
"unenrols",
"a",
"given",
"user",
"enrolment",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/externallib.php#L1042-L1083
|
218,064
|
moodle/moodle
|
enrol/externallib.php
|
core_role_external.assign_roles
|
public static function assign_roles($assignments) {
global $DB;
// Do basic automatic PARAM checks on incoming data, using params description
// If any problems are found then exceptions are thrown with helpful error messages
$params = self::validate_parameters(self::assign_roles_parameters(), array('assignments'=>$assignments));
$transaction = $DB->start_delegated_transaction();
foreach ($params['assignments'] as $assignment) {
// Ensure correct context level with a instance id or contextid is passed.
$context = self::get_context_from_params($assignment);
// Ensure the current user is allowed to run this function in the enrolment context.
self::validate_context($context);
require_capability('moodle/role:assign', $context);
// throw an exception if user is not able to assign the role in this context
$roles = get_assignable_roles($context, ROLENAME_SHORT);
if (!array_key_exists($assignment['roleid'], $roles)) {
throw new invalid_parameter_exception('Can not assign roleid='.$assignment['roleid'].' in contextid='.$assignment['contextid']);
}
role_assign($assignment['roleid'], $assignment['userid'], $context->id);
}
$transaction->allow_commit();
}
|
php
|
public static function assign_roles($assignments) {
global $DB;
// Do basic automatic PARAM checks on incoming data, using params description
// If any problems are found then exceptions are thrown with helpful error messages
$params = self::validate_parameters(self::assign_roles_parameters(), array('assignments'=>$assignments));
$transaction = $DB->start_delegated_transaction();
foreach ($params['assignments'] as $assignment) {
// Ensure correct context level with a instance id or contextid is passed.
$context = self::get_context_from_params($assignment);
// Ensure the current user is allowed to run this function in the enrolment context.
self::validate_context($context);
require_capability('moodle/role:assign', $context);
// throw an exception if user is not able to assign the role in this context
$roles = get_assignable_roles($context, ROLENAME_SHORT);
if (!array_key_exists($assignment['roleid'], $roles)) {
throw new invalid_parameter_exception('Can not assign roleid='.$assignment['roleid'].' in contextid='.$assignment['contextid']);
}
role_assign($assignment['roleid'], $assignment['userid'], $context->id);
}
$transaction->allow_commit();
}
|
[
"public",
"static",
"function",
"assign_roles",
"(",
"$",
"assignments",
")",
"{",
"global",
"$",
"DB",
";",
"// Do basic automatic PARAM checks on incoming data, using params description",
"// If any problems are found then exceptions are thrown with helpful error messages",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"assign_roles_parameters",
"(",
")",
",",
"array",
"(",
"'assignments'",
"=>",
"$",
"assignments",
")",
")",
";",
"$",
"transaction",
"=",
"$",
"DB",
"->",
"start_delegated_transaction",
"(",
")",
";",
"foreach",
"(",
"$",
"params",
"[",
"'assignments'",
"]",
"as",
"$",
"assignment",
")",
"{",
"// Ensure correct context level with a instance id or contextid is passed.",
"$",
"context",
"=",
"self",
"::",
"get_context_from_params",
"(",
"$",
"assignment",
")",
";",
"// Ensure the current user is allowed to run this function in the enrolment context.",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"require_capability",
"(",
"'moodle/role:assign'",
",",
"$",
"context",
")",
";",
"// throw an exception if user is not able to assign the role in this context",
"$",
"roles",
"=",
"get_assignable_roles",
"(",
"$",
"context",
",",
"ROLENAME_SHORT",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"assignment",
"[",
"'roleid'",
"]",
",",
"$",
"roles",
")",
")",
"{",
"throw",
"new",
"invalid_parameter_exception",
"(",
"'Can not assign roleid='",
".",
"$",
"assignment",
"[",
"'roleid'",
"]",
".",
"' in contextid='",
".",
"$",
"assignment",
"[",
"'contextid'",
"]",
")",
";",
"}",
"role_assign",
"(",
"$",
"assignment",
"[",
"'roleid'",
"]",
",",
"$",
"assignment",
"[",
"'userid'",
"]",
",",
"$",
"context",
"->",
"id",
")",
";",
"}",
"$",
"transaction",
"->",
"allow_commit",
"(",
")",
";",
"}"
] |
Manual role assignments to users
@param array $assignments An array of manual role assignment
|
[
"Manual",
"role",
"assignments",
"to",
"users"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/externallib.php#L1147-L1175
|
218,065
|
moodle/moodle
|
enrol/externallib.php
|
core_role_external.unassign_roles
|
public static function unassign_roles($unassignments) {
global $DB;
// Do basic automatic PARAM checks on incoming data, using params description
// If any problems are found then exceptions are thrown with helpful error messages
$params = self::validate_parameters(self::unassign_roles_parameters(), array('unassignments'=>$unassignments));
$transaction = $DB->start_delegated_transaction();
foreach ($params['unassignments'] as $unassignment) {
// Ensure the current user is allowed to run this function in the unassignment context
$context = self::get_context_from_params($unassignment);
self::validate_context($context);
require_capability('moodle/role:assign', $context);
// throw an exception if user is not able to unassign the role in this context
$roles = get_assignable_roles($context, ROLENAME_SHORT);
if (!array_key_exists($unassignment['roleid'], $roles)) {
throw new invalid_parameter_exception('Can not unassign roleid='.$unassignment['roleid'].' in contextid='.$unassignment['contextid']);
}
role_unassign($unassignment['roleid'], $unassignment['userid'], $context->id);
}
$transaction->allow_commit();
}
|
php
|
public static function unassign_roles($unassignments) {
global $DB;
// Do basic automatic PARAM checks on incoming data, using params description
// If any problems are found then exceptions are thrown with helpful error messages
$params = self::validate_parameters(self::unassign_roles_parameters(), array('unassignments'=>$unassignments));
$transaction = $DB->start_delegated_transaction();
foreach ($params['unassignments'] as $unassignment) {
// Ensure the current user is allowed to run this function in the unassignment context
$context = self::get_context_from_params($unassignment);
self::validate_context($context);
require_capability('moodle/role:assign', $context);
// throw an exception if user is not able to unassign the role in this context
$roles = get_assignable_roles($context, ROLENAME_SHORT);
if (!array_key_exists($unassignment['roleid'], $roles)) {
throw new invalid_parameter_exception('Can not unassign roleid='.$unassignment['roleid'].' in contextid='.$unassignment['contextid']);
}
role_unassign($unassignment['roleid'], $unassignment['userid'], $context->id);
}
$transaction->allow_commit();
}
|
[
"public",
"static",
"function",
"unassign_roles",
"(",
"$",
"unassignments",
")",
"{",
"global",
"$",
"DB",
";",
"// Do basic automatic PARAM checks on incoming data, using params description",
"// If any problems are found then exceptions are thrown with helpful error messages",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"unassign_roles_parameters",
"(",
")",
",",
"array",
"(",
"'unassignments'",
"=>",
"$",
"unassignments",
")",
")",
";",
"$",
"transaction",
"=",
"$",
"DB",
"->",
"start_delegated_transaction",
"(",
")",
";",
"foreach",
"(",
"$",
"params",
"[",
"'unassignments'",
"]",
"as",
"$",
"unassignment",
")",
"{",
"// Ensure the current user is allowed to run this function in the unassignment context",
"$",
"context",
"=",
"self",
"::",
"get_context_from_params",
"(",
"$",
"unassignment",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"require_capability",
"(",
"'moodle/role:assign'",
",",
"$",
"context",
")",
";",
"// throw an exception if user is not able to unassign the role in this context",
"$",
"roles",
"=",
"get_assignable_roles",
"(",
"$",
"context",
",",
"ROLENAME_SHORT",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"unassignment",
"[",
"'roleid'",
"]",
",",
"$",
"roles",
")",
")",
"{",
"throw",
"new",
"invalid_parameter_exception",
"(",
"'Can not unassign roleid='",
".",
"$",
"unassignment",
"[",
"'roleid'",
"]",
".",
"' in contextid='",
".",
"$",
"unassignment",
"[",
"'contextid'",
"]",
")",
";",
"}",
"role_unassign",
"(",
"$",
"unassignment",
"[",
"'roleid'",
"]",
",",
"$",
"unassignment",
"[",
"'userid'",
"]",
",",
"$",
"context",
"->",
"id",
")",
";",
"}",
"$",
"transaction",
"->",
"allow_commit",
"(",
")",
";",
"}"
] |
Unassign roles from users
@param array $unassignments An array of unassignment
|
[
"Unassign",
"roles",
"from",
"users"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/externallib.php#L1216-L1241
|
218,066
|
moodle/moodle
|
lib/classes/useragent.php
|
core_useragent.instance
|
public static function instance($reload = false, $forceuseragent = null) {
if (!self::$instance || $reload) {
self::$instance = new core_useragent($forceuseragent);
}
return self::$instance;
}
|
php
|
public static function instance($reload = false, $forceuseragent = null) {
if (!self::$instance || $reload) {
self::$instance = new core_useragent($forceuseragent);
}
return self::$instance;
}
|
[
"public",
"static",
"function",
"instance",
"(",
"$",
"reload",
"=",
"false",
",",
"$",
"forceuseragent",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"instance",
"||",
"$",
"reload",
")",
"{",
"self",
"::",
"$",
"instance",
"=",
"new",
"core_useragent",
"(",
"$",
"forceuseragent",
")",
";",
"}",
"return",
"self",
"::",
"$",
"instance",
";",
"}"
] |
Get an instance of the user agent object.
@param bool $reload If set to true the user agent will be reset and all ascertations remade.
@param string $forceuseragent The string to force as the user agent, don't use unless absolutely unavoidable.
@return core_useragent
|
[
"Get",
"an",
"instance",
"of",
"the",
"user",
"agent",
"object",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/useragent.php#L108-L113
|
218,067
|
moodle/moodle
|
lib/classes/useragent.php
|
core_useragent.get_device_type
|
public static function get_device_type() {
$instance = self::instance();
if ($instance->devicetype === null) {
return $instance->guess_device_type();
}
return $instance->devicetype;
}
|
php
|
public static function get_device_type() {
$instance = self::instance();
if ($instance->devicetype === null) {
return $instance->guess_device_type();
}
return $instance->devicetype;
}
|
[
"public",
"static",
"function",
"get_device_type",
"(",
")",
"{",
"$",
"instance",
"=",
"self",
"::",
"instance",
"(",
")",
";",
"if",
"(",
"$",
"instance",
"->",
"devicetype",
"===",
"null",
")",
"{",
"return",
"$",
"instance",
"->",
"guess_device_type",
"(",
")",
";",
"}",
"return",
"$",
"instance",
"->",
"devicetype",
";",
"}"
] |
Returns the device type we believe is being used.
@return string
|
[
"Returns",
"the",
"device",
"type",
"we",
"believe",
"is",
"being",
"used",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/useragent.php#L153-L159
|
218,068
|
moodle/moodle
|
lib/classes/useragent.php
|
core_useragent.guess_device_type
|
protected function guess_device_type() {
global $CFG;
if (empty($CFG->enabledevicedetection)) {
$this->devicetype = self::DEVICETYPE_DEFAULT;
return $this->devicetype;
}
foreach ($this->devicetypecustoms as $value => $regex) {
if (preg_match($regex, $this->useragent)) {
$this->devicetype = $value;
return $this->devicetype;
}
}
if ($this->is_useragent_mobile()) {
$this->devicetype = self::DEVICETYPE_MOBILE;
} else if ($this->is_useragent_tablet()) {
$this->devicetype = self::DEVICETYPE_TABLET;
} else if (self::check_ie_version('0') && !self::check_ie_version('7.0')) {
// IE 6 and before are considered legacy.
$this->devicetype = self::DEVICETYPE_LEGACY;
} else {
$this->devicetype = self::DEVICETYPE_DEFAULT;
}
return $this->devicetype;
}
|
php
|
protected function guess_device_type() {
global $CFG;
if (empty($CFG->enabledevicedetection)) {
$this->devicetype = self::DEVICETYPE_DEFAULT;
return $this->devicetype;
}
foreach ($this->devicetypecustoms as $value => $regex) {
if (preg_match($regex, $this->useragent)) {
$this->devicetype = $value;
return $this->devicetype;
}
}
if ($this->is_useragent_mobile()) {
$this->devicetype = self::DEVICETYPE_MOBILE;
} else if ($this->is_useragent_tablet()) {
$this->devicetype = self::DEVICETYPE_TABLET;
} else if (self::check_ie_version('0') && !self::check_ie_version('7.0')) {
// IE 6 and before are considered legacy.
$this->devicetype = self::DEVICETYPE_LEGACY;
} else {
$this->devicetype = self::DEVICETYPE_DEFAULT;
}
return $this->devicetype;
}
|
[
"protected",
"function",
"guess_device_type",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"if",
"(",
"empty",
"(",
"$",
"CFG",
"->",
"enabledevicedetection",
")",
")",
"{",
"$",
"this",
"->",
"devicetype",
"=",
"self",
"::",
"DEVICETYPE_DEFAULT",
";",
"return",
"$",
"this",
"->",
"devicetype",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"devicetypecustoms",
"as",
"$",
"value",
"=>",
"$",
"regex",
")",
"{",
"if",
"(",
"preg_match",
"(",
"$",
"regex",
",",
"$",
"this",
"->",
"useragent",
")",
")",
"{",
"$",
"this",
"->",
"devicetype",
"=",
"$",
"value",
";",
"return",
"$",
"this",
"->",
"devicetype",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"is_useragent_mobile",
"(",
")",
")",
"{",
"$",
"this",
"->",
"devicetype",
"=",
"self",
"::",
"DEVICETYPE_MOBILE",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"is_useragent_tablet",
"(",
")",
")",
"{",
"$",
"this",
"->",
"devicetype",
"=",
"self",
"::",
"DEVICETYPE_TABLET",
";",
"}",
"else",
"if",
"(",
"self",
"::",
"check_ie_version",
"(",
"'0'",
")",
"&&",
"!",
"self",
"::",
"check_ie_version",
"(",
"'7.0'",
")",
")",
"{",
"// IE 6 and before are considered legacy.",
"$",
"this",
"->",
"devicetype",
"=",
"self",
"::",
"DEVICETYPE_LEGACY",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"devicetype",
"=",
"self",
"::",
"DEVICETYPE_DEFAULT",
";",
"}",
"return",
"$",
"this",
"->",
"devicetype",
";",
"}"
] |
Guesses the device type the user agent is running on.
@return string
|
[
"Guesses",
"the",
"device",
"type",
"the",
"user",
"agent",
"is",
"running",
"on",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/useragent.php#L166-L189
|
218,069
|
moodle/moodle
|
lib/classes/useragent.php
|
core_useragent.is_useragent_mobile
|
protected function is_useragent_mobile() {
// Mobile detection PHP direct copy from open source detectmobilebrowser.com.
$phonesregex = '/android .+ mobile|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i';
$modelsregex = '/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i';
return (preg_match($phonesregex, $this->useragent) || preg_match($modelsregex, substr($this->useragent, 0, 4)));
}
|
php
|
protected function is_useragent_mobile() {
// Mobile detection PHP direct copy from open source detectmobilebrowser.com.
$phonesregex = '/android .+ mobile|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i';
$modelsregex = '/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|e\-|e\/|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\-|2|g)|yas\-|your|zeto|zte\-/i';
return (preg_match($phonesregex, $this->useragent) || preg_match($modelsregex, substr($this->useragent, 0, 4)));
}
|
[
"protected",
"function",
"is_useragent_mobile",
"(",
")",
"{",
"// Mobile detection PHP direct copy from open source detectmobilebrowser.com.",
"$",
"phonesregex",
"=",
"'/android .+ mobile|avantgo|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|symbian|treo|up\\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i'",
";",
"$",
"modelsregex",
"=",
"'/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\\-(n|u)|c55\\/|capi|ccwa|cdm\\-|cell|chtm|cldc|cmd\\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\\-s|devi|dica|dmob|do(c|p)o|ds(12|\\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\\-|_)|g1 u|g560|gene|gf\\-5|g\\-mo|go(\\.w|od)|gr(ad|un)|haie|hcit|hd\\-(m|p|t)|hei\\-|hi(pt|ta)|hp( i|ip)|hs\\-c|ht(c(\\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\\-(20|go|ma)|i230|iac( |\\-|\\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\\/)|klon|kpt |kwc\\-|kyo(c|k)|le(no|xi)|lg( g|\\/(k|l|u)|50|54|e\\-|e\\/|\\-[a-w])|libw|lynx|m1\\-w|m3ga|m50\\/|ma(te|ui|xo)|mc(01|21|ca)|m\\-cr|me(di|rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\\-2|po(ck|rt|se)|prox|psio|pt\\-g|qa\\-a|qc(07|12|21|32|60|\\-[2-7]|i\\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\\-|oo|p\\-)|sdk\\/|se(c(\\-|0|1)|47|mc|nd|ri)|sgh\\-|shar|sie(\\-|m)|sk\\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\\-|v\\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\\-|tdg\\-|tel(i|m)|tim\\-|t\\-mo|to(pl|sh)|ts(70|m\\-|m3|m5)|tx\\-9|up(\\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|xda(\\-|2|g)|yas\\-|your|zeto|zte\\-/i'",
";",
"return",
"(",
"preg_match",
"(",
"$",
"phonesregex",
",",
"$",
"this",
"->",
"useragent",
")",
"||",
"preg_match",
"(",
"$",
"modelsregex",
",",
"substr",
"(",
"$",
"this",
"->",
"useragent",
",",
"0",
",",
"4",
")",
")",
")",
";",
"}"
] |
Returns true if the user appears to be on a mobile device.
@return bool
|
[
"Returns",
"true",
"if",
"the",
"user",
"appears",
"to",
"be",
"on",
"a",
"mobile",
"device",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/useragent.php#L195-L200
|
218,070
|
moodle/moodle
|
lib/classes/useragent.php
|
core_useragent.get_device_type_list
|
public static function get_device_type_list($includecustomtypes = true) {
$types = self::$devicetypes;
if ($includecustomtypes) {
$instance = self::instance();
$types = array_merge($types, array_keys($instance->devicetypecustoms));
}
return $types;
}
|
php
|
public static function get_device_type_list($includecustomtypes = true) {
$types = self::$devicetypes;
if ($includecustomtypes) {
$instance = self::instance();
$types = array_merge($types, array_keys($instance->devicetypecustoms));
}
return $types;
}
|
[
"public",
"static",
"function",
"get_device_type_list",
"(",
"$",
"includecustomtypes",
"=",
"true",
")",
"{",
"$",
"types",
"=",
"self",
"::",
"$",
"devicetypes",
";",
"if",
"(",
"$",
"includecustomtypes",
")",
"{",
"$",
"instance",
"=",
"self",
"::",
"instance",
"(",
")",
";",
"$",
"types",
"=",
"array_merge",
"(",
"$",
"types",
",",
"array_keys",
"(",
"$",
"instance",
"->",
"devicetypecustoms",
")",
")",
";",
"}",
"return",
"$",
"types",
";",
"}"
] |
Gets a list of known device types.
@param bool $includecustomtypes If set to true we'll include types that have been added by the admin.
@return array
|
[
"Gets",
"a",
"list",
"of",
"known",
"device",
"types",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/useragent.php#L228-L235
|
218,071
|
moodle/moodle
|
lib/classes/useragent.php
|
core_useragent.get_device_type_theme
|
public static function get_device_type_theme($devicetype = null) {
global $CFG;
if ($devicetype === null) {
$devicetype = self::get_device_type();
}
$themevarname = self::get_device_type_cfg_var_name($devicetype);
if (empty($CFG->$themevarname)) {
return false;
}
return $CFG->$themevarname;
}
|
php
|
public static function get_device_type_theme($devicetype = null) {
global $CFG;
if ($devicetype === null) {
$devicetype = self::get_device_type();
}
$themevarname = self::get_device_type_cfg_var_name($devicetype);
if (empty($CFG->$themevarname)) {
return false;
}
return $CFG->$themevarname;
}
|
[
"public",
"static",
"function",
"get_device_type_theme",
"(",
"$",
"devicetype",
"=",
"null",
")",
"{",
"global",
"$",
"CFG",
";",
"if",
"(",
"$",
"devicetype",
"===",
"null",
")",
"{",
"$",
"devicetype",
"=",
"self",
"::",
"get_device_type",
"(",
")",
";",
"}",
"$",
"themevarname",
"=",
"self",
"::",
"get_device_type_cfg_var_name",
"(",
"$",
"devicetype",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"CFG",
"->",
"$",
"themevarname",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"CFG",
"->",
"$",
"themevarname",
";",
"}"
] |
Returns the theme to use for the given device type.
This used to be get_selected_theme_for_device_type.
@param null|string $devicetype The device type to find out for. Defaults to the device the user is using,
@return bool
|
[
"Returns",
"the",
"theme",
"to",
"use",
"for",
"the",
"given",
"device",
"type",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/useragent.php#L244-L254
|
218,072
|
moodle/moodle
|
lib/classes/useragent.php
|
core_useragent.get_user_device_type
|
public static function get_user_device_type() {
$device = self::get_device_type();
$switched = get_user_preferences('switchdevice'.$device, false);
if ($switched != false) {
return $switched;
}
return $device;
}
|
php
|
public static function get_user_device_type() {
$device = self::get_device_type();
$switched = get_user_preferences('switchdevice'.$device, false);
if ($switched != false) {
return $switched;
}
return $device;
}
|
[
"public",
"static",
"function",
"get_user_device_type",
"(",
")",
"{",
"$",
"device",
"=",
"self",
"::",
"get_device_type",
"(",
")",
";",
"$",
"switched",
"=",
"get_user_preferences",
"(",
"'switchdevice'",
".",
"$",
"device",
",",
"false",
")",
";",
"if",
"(",
"$",
"switched",
"!=",
"false",
")",
"{",
"return",
"$",
"switched",
";",
"}",
"return",
"$",
"device",
";",
"}"
] |
Gets the device type the user is currently using.
@return string
|
[
"Gets",
"the",
"device",
"type",
"the",
"user",
"is",
"currently",
"using",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/useragent.php#L275-L282
|
218,073
|
moodle/moodle
|
lib/classes/useragent.php
|
core_useragent.set_user_device_type
|
public static function set_user_device_type($newdevice) {
$devicetype = self::get_device_type();
if ($newdevice == $devicetype) {
unset_user_preference('switchdevice'.$devicetype);
return true;
} else {
$devicetypes = self::get_device_type_list();
if (in_array($newdevice, $devicetypes)) {
set_user_preference('switchdevice'.$devicetype, $newdevice);
return true;
}
}
throw new coding_exception('Invalid device type provided to set_user_device_type');
}
|
php
|
public static function set_user_device_type($newdevice) {
$devicetype = self::get_device_type();
if ($newdevice == $devicetype) {
unset_user_preference('switchdevice'.$devicetype);
return true;
} else {
$devicetypes = self::get_device_type_list();
if (in_array($newdevice, $devicetypes)) {
set_user_preference('switchdevice'.$devicetype, $newdevice);
return true;
}
}
throw new coding_exception('Invalid device type provided to set_user_device_type');
}
|
[
"public",
"static",
"function",
"set_user_device_type",
"(",
"$",
"newdevice",
")",
"{",
"$",
"devicetype",
"=",
"self",
"::",
"get_device_type",
"(",
")",
";",
"if",
"(",
"$",
"newdevice",
"==",
"$",
"devicetype",
")",
"{",
"unset_user_preference",
"(",
"'switchdevice'",
".",
"$",
"devicetype",
")",
";",
"return",
"true",
";",
"}",
"else",
"{",
"$",
"devicetypes",
"=",
"self",
"::",
"get_device_type_list",
"(",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"newdevice",
",",
"$",
"devicetypes",
")",
")",
"{",
"set_user_preference",
"(",
"'switchdevice'",
".",
"$",
"devicetype",
",",
"$",
"newdevice",
")",
";",
"return",
"true",
";",
"}",
"}",
"throw",
"new",
"coding_exception",
"(",
"'Invalid device type provided to set_user_device_type'",
")",
";",
"}"
] |
Switches the device type we think the user is using to what ever was given.
@param string $newdevice
@return bool
@throws coding_exception
|
[
"Switches",
"the",
"device",
"type",
"we",
"think",
"the",
"user",
"is",
"using",
"to",
"what",
"ever",
"was",
"given",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/useragent.php#L290-L303
|
218,074
|
moodle/moodle
|
lib/classes/useragent.php
|
core_useragent.check_browser_version
|
public static function check_browser_version($brand, $version = null) {
switch ($brand) {
case 'MSIE':
// Internet Explorer.
return self::check_ie_version($version);
case 'Edge':
// Microsoft Edge.
return self::check_edge_version($version);
case 'Firefox':
// Mozilla Firefox browsers.
return self::check_firefox_version($version);
case 'Chrome':
return self::check_chrome_version($version);
case 'Opera':
// Opera.
return self::check_opera_version($version);
case 'Safari':
// Desktop version of Apple Safari browser - no mobile or touch devices.
return self::check_safari_version($version);
case 'Safari iOS':
// Safari on iPhone, iPad and iPod touch.
return self::check_safari_ios_version($version);
case 'WebKit':
// WebKit based browser - everything derived from it (Safari, Chrome, iOS, Android and other mobiles).
return self::check_webkit_version($version);
case 'Gecko':
// Gecko based browsers.
return self::check_gecko_version($version);
case 'WebKit Android':
// WebKit browser on Android.
return self::check_webkit_android_version($version);
case 'Camino':
// OSX browser using Gecke engine.
return self::check_camino_version($version);
}
// Who knows?! doesn't pass anyway.
return false;
}
|
php
|
public static function check_browser_version($brand, $version = null) {
switch ($brand) {
case 'MSIE':
// Internet Explorer.
return self::check_ie_version($version);
case 'Edge':
// Microsoft Edge.
return self::check_edge_version($version);
case 'Firefox':
// Mozilla Firefox browsers.
return self::check_firefox_version($version);
case 'Chrome':
return self::check_chrome_version($version);
case 'Opera':
// Opera.
return self::check_opera_version($version);
case 'Safari':
// Desktop version of Apple Safari browser - no mobile or touch devices.
return self::check_safari_version($version);
case 'Safari iOS':
// Safari on iPhone, iPad and iPod touch.
return self::check_safari_ios_version($version);
case 'WebKit':
// WebKit based browser - everything derived from it (Safari, Chrome, iOS, Android and other mobiles).
return self::check_webkit_version($version);
case 'Gecko':
// Gecko based browsers.
return self::check_gecko_version($version);
case 'WebKit Android':
// WebKit browser on Android.
return self::check_webkit_android_version($version);
case 'Camino':
// OSX browser using Gecke engine.
return self::check_camino_version($version);
}
// Who knows?! doesn't pass anyway.
return false;
}
|
[
"public",
"static",
"function",
"check_browser_version",
"(",
"$",
"brand",
",",
"$",
"version",
"=",
"null",
")",
"{",
"switch",
"(",
"$",
"brand",
")",
"{",
"case",
"'MSIE'",
":",
"// Internet Explorer.",
"return",
"self",
"::",
"check_ie_version",
"(",
"$",
"version",
")",
";",
"case",
"'Edge'",
":",
"// Microsoft Edge.",
"return",
"self",
"::",
"check_edge_version",
"(",
"$",
"version",
")",
";",
"case",
"'Firefox'",
":",
"// Mozilla Firefox browsers.",
"return",
"self",
"::",
"check_firefox_version",
"(",
"$",
"version",
")",
";",
"case",
"'Chrome'",
":",
"return",
"self",
"::",
"check_chrome_version",
"(",
"$",
"version",
")",
";",
"case",
"'Opera'",
":",
"// Opera.",
"return",
"self",
"::",
"check_opera_version",
"(",
"$",
"version",
")",
";",
"case",
"'Safari'",
":",
"// Desktop version of Apple Safari browser - no mobile or touch devices.",
"return",
"self",
"::",
"check_safari_version",
"(",
"$",
"version",
")",
";",
"case",
"'Safari iOS'",
":",
"// Safari on iPhone, iPad and iPod touch.",
"return",
"self",
"::",
"check_safari_ios_version",
"(",
"$",
"version",
")",
";",
"case",
"'WebKit'",
":",
"// WebKit based browser - everything derived from it (Safari, Chrome, iOS, Android and other mobiles).",
"return",
"self",
"::",
"check_webkit_version",
"(",
"$",
"version",
")",
";",
"case",
"'Gecko'",
":",
"// Gecko based browsers.",
"return",
"self",
"::",
"check_gecko_version",
"(",
"$",
"version",
")",
";",
"case",
"'WebKit Android'",
":",
"// WebKit browser on Android.",
"return",
"self",
"::",
"check_webkit_android_version",
"(",
"$",
"version",
")",
";",
"case",
"'Camino'",
":",
"// OSX browser using Gecke engine.",
"return",
"self",
"::",
"check_camino_version",
"(",
"$",
"version",
")",
";",
"}",
"// Who knows?! doesn't pass anyway.",
"return",
"false",
";",
"}"
] |
Returns true if the user agent matches the given brand and the version is equal to or greater than that specified.
@param string $brand The branch to check for.
@param scalar $version The version if we need to find out if it is equal to or greater than that specified.
@return bool
|
[
"Returns",
"true",
"if",
"the",
"user",
"agent",
"matches",
"the",
"given",
"brand",
"and",
"the",
"version",
"is",
"equal",
"to",
"or",
"greater",
"than",
"that",
"specified",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/useragent.php#L312-L360
|
218,075
|
moodle/moodle
|
lib/classes/useragent.php
|
core_useragent.check_gecko_version
|
public static function check_gecko_version($version = null) {
// Gecko based browsers.
// Do not look for dates any more, we expect real Firefox version here.
$useragent = self::get_user_agent_string();
if ($useragent === false) {
return false;
}
if (empty($version)) {
$version = 1;
} else if ($version > 20000000) {
// This is just a guess, it is not supposed to be 100% accurate!
if (preg_match('/^201/', $version)) {
$version = 3.6;
} else if (preg_match('/^200[7-9]/', $version)) {
$version = 3;
} else if (preg_match('/^2006/', $version)) {
$version = 2;
} else {
$version = 1.5;
}
}
if (preg_match("/(Iceweasel|Firefox)\/([0-9\.]+)/i", $useragent, $match)) {
// Use real Firefox version if specified in user agent string.
if (version_compare($match[2], $version) >= 0) {
return true;
}
} else if (preg_match("/Gecko\/([0-9\.]+)/i", $useragent, $match)) {
// Gecko might contain date or Firefox revision, let's just guess the Firefox version from the date.
$browserver = $match[1];
if ($browserver > 20000000) {
// This is just a guess, it is not supposed to be 100% accurate!
if (preg_match('/^201/', $browserver)) {
$browserver = 3.6;
} else if (preg_match('/^200[7-9]/', $browserver)) {
$browserver = 3;
} else if (preg_match('/^2006/', $version)) {
$browserver = 2;
} else {
$browserver = 1.5;
}
}
if (version_compare($browserver, $version) >= 0) {
return true;
}
}
return false;
}
|
php
|
public static function check_gecko_version($version = null) {
// Gecko based browsers.
// Do not look for dates any more, we expect real Firefox version here.
$useragent = self::get_user_agent_string();
if ($useragent === false) {
return false;
}
if (empty($version)) {
$version = 1;
} else if ($version > 20000000) {
// This is just a guess, it is not supposed to be 100% accurate!
if (preg_match('/^201/', $version)) {
$version = 3.6;
} else if (preg_match('/^200[7-9]/', $version)) {
$version = 3;
} else if (preg_match('/^2006/', $version)) {
$version = 2;
} else {
$version = 1.5;
}
}
if (preg_match("/(Iceweasel|Firefox)\/([0-9\.]+)/i", $useragent, $match)) {
// Use real Firefox version if specified in user agent string.
if (version_compare($match[2], $version) >= 0) {
return true;
}
} else if (preg_match("/Gecko\/([0-9\.]+)/i", $useragent, $match)) {
// Gecko might contain date or Firefox revision, let's just guess the Firefox version from the date.
$browserver = $match[1];
if ($browserver > 20000000) {
// This is just a guess, it is not supposed to be 100% accurate!
if (preg_match('/^201/', $browserver)) {
$browserver = 3.6;
} else if (preg_match('/^200[7-9]/', $browserver)) {
$browserver = 3;
} else if (preg_match('/^2006/', $version)) {
$browserver = 2;
} else {
$browserver = 1.5;
}
}
if (version_compare($browserver, $version) >= 0) {
return true;
}
}
return false;
}
|
[
"public",
"static",
"function",
"check_gecko_version",
"(",
"$",
"version",
"=",
"null",
")",
"{",
"// Gecko based browsers.",
"// Do not look for dates any more, we expect real Firefox version here.",
"$",
"useragent",
"=",
"self",
"::",
"get_user_agent_string",
"(",
")",
";",
"if",
"(",
"$",
"useragent",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"version",
")",
")",
"{",
"$",
"version",
"=",
"1",
";",
"}",
"else",
"if",
"(",
"$",
"version",
">",
"20000000",
")",
"{",
"// This is just a guess, it is not supposed to be 100% accurate!",
"if",
"(",
"preg_match",
"(",
"'/^201/'",
",",
"$",
"version",
")",
")",
"{",
"$",
"version",
"=",
"3.6",
";",
"}",
"else",
"if",
"(",
"preg_match",
"(",
"'/^200[7-9]/'",
",",
"$",
"version",
")",
")",
"{",
"$",
"version",
"=",
"3",
";",
"}",
"else",
"if",
"(",
"preg_match",
"(",
"'/^2006/'",
",",
"$",
"version",
")",
")",
"{",
"$",
"version",
"=",
"2",
";",
"}",
"else",
"{",
"$",
"version",
"=",
"1.5",
";",
"}",
"}",
"if",
"(",
"preg_match",
"(",
"\"/(Iceweasel|Firefox)\\/([0-9\\.]+)/i\"",
",",
"$",
"useragent",
",",
"$",
"match",
")",
")",
"{",
"// Use real Firefox version if specified in user agent string.",
"if",
"(",
"version_compare",
"(",
"$",
"match",
"[",
"2",
"]",
",",
"$",
"version",
")",
">=",
"0",
")",
"{",
"return",
"true",
";",
"}",
"}",
"else",
"if",
"(",
"preg_match",
"(",
"\"/Gecko\\/([0-9\\.]+)/i\"",
",",
"$",
"useragent",
",",
"$",
"match",
")",
")",
"{",
"// Gecko might contain date or Firefox revision, let's just guess the Firefox version from the date.",
"$",
"browserver",
"=",
"$",
"match",
"[",
"1",
"]",
";",
"if",
"(",
"$",
"browserver",
">",
"20000000",
")",
"{",
"// This is just a guess, it is not supposed to be 100% accurate!",
"if",
"(",
"preg_match",
"(",
"'/^201/'",
",",
"$",
"browserver",
")",
")",
"{",
"$",
"browserver",
"=",
"3.6",
";",
"}",
"else",
"if",
"(",
"preg_match",
"(",
"'/^200[7-9]/'",
",",
"$",
"browserver",
")",
")",
"{",
"$",
"browserver",
"=",
"3",
";",
"}",
"else",
"if",
"(",
"preg_match",
"(",
"'/^2006/'",
",",
"$",
"version",
")",
")",
"{",
"$",
"browserver",
"=",
"2",
";",
"}",
"else",
"{",
"$",
"browserver",
"=",
"1.5",
";",
"}",
"}",
"if",
"(",
"version_compare",
"(",
"$",
"browserver",
",",
"$",
"version",
")",
">=",
"0",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Checks the user agent is Gecko based and that the version is equal to or greater than that specified.
@param string|int $version A version to check for, returns true if its equal to or greater than that specified.
@return bool
|
[
"Checks",
"the",
"user",
"agent",
"is",
"Gecko",
"based",
"and",
"that",
"the",
"version",
"is",
"equal",
"to",
"or",
"greater",
"than",
"that",
"specified",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/useragent.php#L440-L486
|
218,076
|
moodle/moodle
|
lib/classes/useragent.php
|
core_useragent.check_edge_version
|
public static function check_edge_version($version = null) {
$useragent = self::get_user_agent_string();
if ($useragent === false) {
// No User Agent found.
return false;
}
if (strpos($useragent, 'Edge/') === false) {
// Edge was not found in the UA - this is not Edge.
return false;
}
if (empty($version)) {
// No version to check.
return true;
}
// Find the version.
// Edge versions are always in the format:
// Edge/<version>.<OS build number>
preg_match('%Edge/([\d]+)\.(.*)$%', $useragent, $matches);
// Just to be safe, round the version being tested.
// Edge only uses integer versions - the second component is the OS build number.
$version = round($version);
// Check whether the version specified is >= the version found.
return version_compare($matches[1], $version, '>=');
}
|
php
|
public static function check_edge_version($version = null) {
$useragent = self::get_user_agent_string();
if ($useragent === false) {
// No User Agent found.
return false;
}
if (strpos($useragent, 'Edge/') === false) {
// Edge was not found in the UA - this is not Edge.
return false;
}
if (empty($version)) {
// No version to check.
return true;
}
// Find the version.
// Edge versions are always in the format:
// Edge/<version>.<OS build number>
preg_match('%Edge/([\d]+)\.(.*)$%', $useragent, $matches);
// Just to be safe, round the version being tested.
// Edge only uses integer versions - the second component is the OS build number.
$version = round($version);
// Check whether the version specified is >= the version found.
return version_compare($matches[1], $version, '>=');
}
|
[
"public",
"static",
"function",
"check_edge_version",
"(",
"$",
"version",
"=",
"null",
")",
"{",
"$",
"useragent",
"=",
"self",
"::",
"get_user_agent_string",
"(",
")",
";",
"if",
"(",
"$",
"useragent",
"===",
"false",
")",
"{",
"// No User Agent found.",
"return",
"false",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"useragent",
",",
"'Edge/'",
")",
"===",
"false",
")",
"{",
"// Edge was not found in the UA - this is not Edge.",
"return",
"false",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"version",
")",
")",
"{",
"// No version to check.",
"return",
"true",
";",
"}",
"// Find the version.",
"// Edge versions are always in the format:",
"// Edge/<version>.<OS build number>",
"preg_match",
"(",
"'%Edge/([\\d]+)\\.(.*)$%'",
",",
"$",
"useragent",
",",
"$",
"matches",
")",
";",
"// Just to be safe, round the version being tested.",
"// Edge only uses integer versions - the second component is the OS build number.",
"$",
"version",
"=",
"round",
"(",
"$",
"version",
")",
";",
"// Check whether the version specified is >= the version found.",
"return",
"version_compare",
"(",
"$",
"matches",
"[",
"1",
"]",
",",
"$",
"version",
",",
"'>='",
")",
";",
"}"
] |
Check the User Agent for the version of Edge.
@param string|int $version A version to check for, returns true if its equal to or greater than that specified.
@return bool
|
[
"Check",
"the",
"User",
"Agent",
"for",
"the",
"version",
"of",
"Edge",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/useragent.php#L503-L532
|
218,077
|
moodle/moodle
|
lib/classes/useragent.php
|
core_useragent.check_ie_version
|
public static function check_ie_version($version = null) {
// Internet Explorer.
$properties = self::check_ie_properties();
if (!is_array($properties)) {
return false;
}
// In case of IE we have to deal with BC of the version parameter.
if (is_null($version)) {
$version = 5.5; // Anything older is not considered a browser at all!
}
// IE uses simple versions, let's cast it to float to simplify the logic here.
$version = round($version, 1);
return ($properties['version'] >= $version);
}
|
php
|
public static function check_ie_version($version = null) {
// Internet Explorer.
$properties = self::check_ie_properties();
if (!is_array($properties)) {
return false;
}
// In case of IE we have to deal with BC of the version parameter.
if (is_null($version)) {
$version = 5.5; // Anything older is not considered a browser at all!
}
// IE uses simple versions, let's cast it to float to simplify the logic here.
$version = round($version, 1);
return ($properties['version'] >= $version);
}
|
[
"public",
"static",
"function",
"check_ie_version",
"(",
"$",
"version",
"=",
"null",
")",
"{",
"// Internet Explorer.",
"$",
"properties",
"=",
"self",
"::",
"check_ie_properties",
"(",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"properties",
")",
")",
"{",
"return",
"false",
";",
"}",
"// In case of IE we have to deal with BC of the version parameter.",
"if",
"(",
"is_null",
"(",
"$",
"version",
")",
")",
"{",
"$",
"version",
"=",
"5.5",
";",
"// Anything older is not considered a browser at all!",
"}",
"// IE uses simple versions, let's cast it to float to simplify the logic here.",
"$",
"version",
"=",
"round",
"(",
"$",
"version",
",",
"1",
")",
";",
"return",
"(",
"$",
"properties",
"[",
"'version'",
"]",
">=",
"$",
"version",
")",
";",
"}"
] |
Checks the user agent is IE and that the version is equal to or greater than that specified.
@param string|int $version A version to check for, returns true if its equal to or greater than that specified.
@return bool
|
[
"Checks",
"the",
"user",
"agent",
"is",
"IE",
"and",
"that",
"the",
"version",
"is",
"equal",
"to",
"or",
"greater",
"than",
"that",
"specified",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/useragent.php#L590-L603
|
218,078
|
moodle/moodle
|
lib/classes/useragent.php
|
core_useragent.check_webkit_android_version
|
public static function check_webkit_android_version($version = null) {
// WebKit browser on Android.
$useragent = self::get_user_agent_string();
if ($useragent === false) {
return false;
}
if (strpos($useragent, 'Android') === false) {
return false;
}
if (empty($version)) {
return true; // No version specified.
}
if (preg_match("/AppleWebKit\/([0-9]+)/i", $useragent, $match)) {
if (version_compare($match[1], $version) >= 0) {
return true;
}
}
return false;
}
|
php
|
public static function check_webkit_android_version($version = null) {
// WebKit browser on Android.
$useragent = self::get_user_agent_string();
if ($useragent === false) {
return false;
}
if (strpos($useragent, 'Android') === false) {
return false;
}
if (empty($version)) {
return true; // No version specified.
}
if (preg_match("/AppleWebKit\/([0-9]+)/i", $useragent, $match)) {
if (version_compare($match[1], $version) >= 0) {
return true;
}
}
return false;
}
|
[
"public",
"static",
"function",
"check_webkit_android_version",
"(",
"$",
"version",
"=",
"null",
")",
"{",
"// WebKit browser on Android.",
"$",
"useragent",
"=",
"self",
"::",
"get_user_agent_string",
"(",
")",
";",
"if",
"(",
"$",
"useragent",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"useragent",
",",
"'Android'",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"version",
")",
")",
"{",
"return",
"true",
";",
"// No version specified.",
"}",
"if",
"(",
"preg_match",
"(",
"\"/AppleWebKit\\/([0-9]+)/i\"",
",",
"$",
"useragent",
",",
"$",
"match",
")",
")",
"{",
"if",
"(",
"version_compare",
"(",
"$",
"match",
"[",
"1",
"]",
",",
"$",
"version",
")",
">=",
"0",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Checks the user agent is Webkit based and on Android and that the version is equal to or greater than that specified.
@param string|int $version A version to check for, returns true if its equal to or greater than that specified.
@return bool
|
[
"Checks",
"the",
"user",
"agent",
"is",
"Webkit",
"based",
"and",
"on",
"Android",
"and",
"that",
"the",
"version",
"is",
"equal",
"to",
"or",
"greater",
"than",
"that",
"specified",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/useragent.php#L817-L835
|
218,079
|
moodle/moodle
|
lib/classes/useragent.php
|
core_useragent.get_browser_version_classes
|
public static function get_browser_version_classes() {
$classes = array();
if (self::is_edge()) {
$classes[] = 'edge';
} else if (self::is_ie()) {
$classes[] = 'ie';
for ($i = 12; $i >= 6; $i--) {
if (self::check_ie_version($i)) {
$classes[] = 'ie'.$i;
break;
}
}
} else if (self::is_firefox() || self::is_gecko() || self::check_camino_version()) {
$classes[] = 'gecko';
if (preg_match('/rv\:([1-2])\.([0-9])/', self::get_user_agent_string(), $matches)) {
$classes[] = "gecko{$matches[1]}{$matches[2]}";
}
} else if (self::is_chrome()) {
$classes[] = 'chrome';
if (self::is_webkit_android()) {
$classes[] = 'android';
}
} else if (self::is_webkit()) {
if (self::is_safari()) {
$classes[] = 'safari';
}
if (self::is_safari_ios()) {
$classes[] = 'ios';
} else if (self::is_webkit_android()) {
$classes[] = 'android'; // Old pre-Chrome android browsers.
}
} else if (self::is_opera()) {
$classes[] = 'opera';
}
return $classes;
}
|
php
|
public static function get_browser_version_classes() {
$classes = array();
if (self::is_edge()) {
$classes[] = 'edge';
} else if (self::is_ie()) {
$classes[] = 'ie';
for ($i = 12; $i >= 6; $i--) {
if (self::check_ie_version($i)) {
$classes[] = 'ie'.$i;
break;
}
}
} else if (self::is_firefox() || self::is_gecko() || self::check_camino_version()) {
$classes[] = 'gecko';
if (preg_match('/rv\:([1-2])\.([0-9])/', self::get_user_agent_string(), $matches)) {
$classes[] = "gecko{$matches[1]}{$matches[2]}";
}
} else if (self::is_chrome()) {
$classes[] = 'chrome';
if (self::is_webkit_android()) {
$classes[] = 'android';
}
} else if (self::is_webkit()) {
if (self::is_safari()) {
$classes[] = 'safari';
}
if (self::is_safari_ios()) {
$classes[] = 'ios';
} else if (self::is_webkit_android()) {
$classes[] = 'android'; // Old pre-Chrome android browsers.
}
} else if (self::is_opera()) {
$classes[] = 'opera';
}
return $classes;
}
|
[
"public",
"static",
"function",
"get_browser_version_classes",
"(",
")",
"{",
"$",
"classes",
"=",
"array",
"(",
")",
";",
"if",
"(",
"self",
"::",
"is_edge",
"(",
")",
")",
"{",
"$",
"classes",
"[",
"]",
"=",
"'edge'",
";",
"}",
"else",
"if",
"(",
"self",
"::",
"is_ie",
"(",
")",
")",
"{",
"$",
"classes",
"[",
"]",
"=",
"'ie'",
";",
"for",
"(",
"$",
"i",
"=",
"12",
";",
"$",
"i",
">=",
"6",
";",
"$",
"i",
"--",
")",
"{",
"if",
"(",
"self",
"::",
"check_ie_version",
"(",
"$",
"i",
")",
")",
"{",
"$",
"classes",
"[",
"]",
"=",
"'ie'",
".",
"$",
"i",
";",
"break",
";",
"}",
"}",
"}",
"else",
"if",
"(",
"self",
"::",
"is_firefox",
"(",
")",
"||",
"self",
"::",
"is_gecko",
"(",
")",
"||",
"self",
"::",
"check_camino_version",
"(",
")",
")",
"{",
"$",
"classes",
"[",
"]",
"=",
"'gecko'",
";",
"if",
"(",
"preg_match",
"(",
"'/rv\\:([1-2])\\.([0-9])/'",
",",
"self",
"::",
"get_user_agent_string",
"(",
")",
",",
"$",
"matches",
")",
")",
"{",
"$",
"classes",
"[",
"]",
"=",
"\"gecko{$matches[1]}{$matches[2]}\"",
";",
"}",
"}",
"else",
"if",
"(",
"self",
"::",
"is_chrome",
"(",
")",
")",
"{",
"$",
"classes",
"[",
"]",
"=",
"'chrome'",
";",
"if",
"(",
"self",
"::",
"is_webkit_android",
"(",
")",
")",
"{",
"$",
"classes",
"[",
"]",
"=",
"'android'",
";",
"}",
"}",
"else",
"if",
"(",
"self",
"::",
"is_webkit",
"(",
")",
")",
"{",
"if",
"(",
"self",
"::",
"is_safari",
"(",
")",
")",
"{",
"$",
"classes",
"[",
"]",
"=",
"'safari'",
";",
"}",
"if",
"(",
"self",
"::",
"is_safari_ios",
"(",
")",
")",
"{",
"$",
"classes",
"[",
"]",
"=",
"'ios'",
";",
"}",
"else",
"if",
"(",
"self",
"::",
"is_webkit_android",
"(",
")",
")",
"{",
"$",
"classes",
"[",
"]",
"=",
"'android'",
";",
"// Old pre-Chrome android browsers.",
"}",
"}",
"else",
"if",
"(",
"self",
"::",
"is_opera",
"(",
")",
")",
"{",
"$",
"classes",
"[",
"]",
"=",
"'opera'",
";",
"}",
"return",
"$",
"classes",
";",
"}"
] |
Gets an array of CSS classes to represent the user agent.
@return array
|
[
"Gets",
"an",
"array",
"of",
"CSS",
"classes",
"to",
"represent",
"the",
"user",
"agent",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/useragent.php#L911-L946
|
218,080
|
moodle/moodle
|
lib/classes/useragent.php
|
core_useragent.supports_svg
|
public static function supports_svg() {
// IE 5 - 8 don't support SVG at all.
$instance = self::instance();
if ($instance->supportssvg === null) {
if ($instance->useragent === false) {
// Can't be sure, just say no.
$instance->supportssvg = false;
} else if (self::check_ie_version('0') and !self::check_ie_version('9')) {
// IE < 9 doesn't support SVG. Say no.
$instance->supportssvg = false;
} else if (self::is_ie() and !self::check_ie_version('10') and self::check_ie_compatibility_view()) {
// IE 9 Compatibility View doesn't support SVG. Say no.
$instance->supportssvg = false;
} else if (preg_match('#Android +[0-2]\.#', $instance->useragent)) {
// Android < 3 doesn't support SVG. Say no.
$instance->supportssvg = false;
} else if (self::is_opera()) {
// Opera 12 still does not support SVG well enough. Say no.
$instance->supportssvg = false;
} else {
// Presumed fine.
$instance->supportssvg = true;
}
}
return $instance->supportssvg;
}
|
php
|
public static function supports_svg() {
// IE 5 - 8 don't support SVG at all.
$instance = self::instance();
if ($instance->supportssvg === null) {
if ($instance->useragent === false) {
// Can't be sure, just say no.
$instance->supportssvg = false;
} else if (self::check_ie_version('0') and !self::check_ie_version('9')) {
// IE < 9 doesn't support SVG. Say no.
$instance->supportssvg = false;
} else if (self::is_ie() and !self::check_ie_version('10') and self::check_ie_compatibility_view()) {
// IE 9 Compatibility View doesn't support SVG. Say no.
$instance->supportssvg = false;
} else if (preg_match('#Android +[0-2]\.#', $instance->useragent)) {
// Android < 3 doesn't support SVG. Say no.
$instance->supportssvg = false;
} else if (self::is_opera()) {
// Opera 12 still does not support SVG well enough. Say no.
$instance->supportssvg = false;
} else {
// Presumed fine.
$instance->supportssvg = true;
}
}
return $instance->supportssvg;
}
|
[
"public",
"static",
"function",
"supports_svg",
"(",
")",
"{",
"// IE 5 - 8 don't support SVG at all.",
"$",
"instance",
"=",
"self",
"::",
"instance",
"(",
")",
";",
"if",
"(",
"$",
"instance",
"->",
"supportssvg",
"===",
"null",
")",
"{",
"if",
"(",
"$",
"instance",
"->",
"useragent",
"===",
"false",
")",
"{",
"// Can't be sure, just say no.",
"$",
"instance",
"->",
"supportssvg",
"=",
"false",
";",
"}",
"else",
"if",
"(",
"self",
"::",
"check_ie_version",
"(",
"'0'",
")",
"and",
"!",
"self",
"::",
"check_ie_version",
"(",
"'9'",
")",
")",
"{",
"// IE < 9 doesn't support SVG. Say no.",
"$",
"instance",
"->",
"supportssvg",
"=",
"false",
";",
"}",
"else",
"if",
"(",
"self",
"::",
"is_ie",
"(",
")",
"and",
"!",
"self",
"::",
"check_ie_version",
"(",
"'10'",
")",
"and",
"self",
"::",
"check_ie_compatibility_view",
"(",
")",
")",
"{",
"// IE 9 Compatibility View doesn't support SVG. Say no.",
"$",
"instance",
"->",
"supportssvg",
"=",
"false",
";",
"}",
"else",
"if",
"(",
"preg_match",
"(",
"'#Android +[0-2]\\.#'",
",",
"$",
"instance",
"->",
"useragent",
")",
")",
"{",
"// Android < 3 doesn't support SVG. Say no.",
"$",
"instance",
"->",
"supportssvg",
"=",
"false",
";",
"}",
"else",
"if",
"(",
"self",
"::",
"is_opera",
"(",
")",
")",
"{",
"// Opera 12 still does not support SVG well enough. Say no.",
"$",
"instance",
"->",
"supportssvg",
"=",
"false",
";",
"}",
"else",
"{",
"// Presumed fine.",
"$",
"instance",
"->",
"supportssvg",
"=",
"true",
";",
"}",
"}",
"return",
"$",
"instance",
"->",
"supportssvg",
";",
"}"
] |
Returns true if the user agent supports the display of SVG images.
@return bool
|
[
"Returns",
"true",
"if",
"the",
"user",
"agent",
"supports",
"the",
"display",
"of",
"SVG",
"images",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/useragent.php#L953-L978
|
218,081
|
moodle/moodle
|
lib/classes/useragent.php
|
core_useragent.supports_json_contenttype
|
public static function supports_json_contenttype() {
// Modern browsers other than IE correctly supports 'application/json' media type.
if (!self::check_ie_version('0')) {
return true;
}
// IE8+ supports 'application/json' media type, when NOT in Compatibility View mode.
// Refs:
// - http://blogs.msdn.com/b/ie/archive/2008/09/10/native-json-in-ie8.aspx;
// - MDL-39810: issues when using 'text/plain' in Compatibility View for the body of an HTTP POST response.
if (self::check_ie_version(8) && !self::check_ie_compatibility_view()) {
return true;
}
// This browser does not support json.
return false;
}
|
php
|
public static function supports_json_contenttype() {
// Modern browsers other than IE correctly supports 'application/json' media type.
if (!self::check_ie_version('0')) {
return true;
}
// IE8+ supports 'application/json' media type, when NOT in Compatibility View mode.
// Refs:
// - http://blogs.msdn.com/b/ie/archive/2008/09/10/native-json-in-ie8.aspx;
// - MDL-39810: issues when using 'text/plain' in Compatibility View for the body of an HTTP POST response.
if (self::check_ie_version(8) && !self::check_ie_compatibility_view()) {
return true;
}
// This browser does not support json.
return false;
}
|
[
"public",
"static",
"function",
"supports_json_contenttype",
"(",
")",
"{",
"// Modern browsers other than IE correctly supports 'application/json' media type.",
"if",
"(",
"!",
"self",
"::",
"check_ie_version",
"(",
"'0'",
")",
")",
"{",
"return",
"true",
";",
"}",
"// IE8+ supports 'application/json' media type, when NOT in Compatibility View mode.",
"// Refs:",
"// - http://blogs.msdn.com/b/ie/archive/2008/09/10/native-json-in-ie8.aspx;",
"// - MDL-39810: issues when using 'text/plain' in Compatibility View for the body of an HTTP POST response.",
"if",
"(",
"self",
"::",
"check_ie_version",
"(",
"8",
")",
"&&",
"!",
"self",
"::",
"check_ie_compatibility_view",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"// This browser does not support json.",
"return",
"false",
";",
"}"
] |
Returns true if the user agent supports the MIME media type for JSON text, as defined in RFC 4627.
@return bool
|
[
"Returns",
"true",
"if",
"the",
"user",
"agent",
"supports",
"the",
"MIME",
"media",
"type",
"for",
"JSON",
"text",
"as",
"defined",
"in",
"RFC",
"4627",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/useragent.php#L985-L1001
|
218,082
|
moodle/moodle
|
analytics/classes/local/indicator/base.php
|
base.calculate
|
public function calculate($sampleids, $samplesorigin, $starttime = false, $endtime = false, $existingcalculations = array()) {
if (!PHPUNIT_TEST && CLI_SCRIPT) {
echo '.';
}
$calculations = array();
$newcalculations = array();
$notnulls = array();
foreach ($sampleids as $sampleid => $unusedsampleid) {
if (isset($existingcalculations[$sampleid])) {
$calculatedvalue = $existingcalculations[$sampleid];
} else {
$calculatedvalue = $this->calculate_sample($sampleid, $samplesorigin, $starttime, $endtime);
$newcalculations[$sampleid] = $calculatedvalue;
}
if (!is_null($calculatedvalue)) {
$notnulls[$sampleid] = $sampleid;
$this->validate_calculated_value($calculatedvalue);
}
$calculations[$sampleid] = $calculatedvalue;
}
$features = $this->to_features($calculations);
return array($features, $newcalculations, $notnulls);
}
|
php
|
public function calculate($sampleids, $samplesorigin, $starttime = false, $endtime = false, $existingcalculations = array()) {
if (!PHPUNIT_TEST && CLI_SCRIPT) {
echo '.';
}
$calculations = array();
$newcalculations = array();
$notnulls = array();
foreach ($sampleids as $sampleid => $unusedsampleid) {
if (isset($existingcalculations[$sampleid])) {
$calculatedvalue = $existingcalculations[$sampleid];
} else {
$calculatedvalue = $this->calculate_sample($sampleid, $samplesorigin, $starttime, $endtime);
$newcalculations[$sampleid] = $calculatedvalue;
}
if (!is_null($calculatedvalue)) {
$notnulls[$sampleid] = $sampleid;
$this->validate_calculated_value($calculatedvalue);
}
$calculations[$sampleid] = $calculatedvalue;
}
$features = $this->to_features($calculations);
return array($features, $newcalculations, $notnulls);
}
|
[
"public",
"function",
"calculate",
"(",
"$",
"sampleids",
",",
"$",
"samplesorigin",
",",
"$",
"starttime",
"=",
"false",
",",
"$",
"endtime",
"=",
"false",
",",
"$",
"existingcalculations",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"PHPUNIT_TEST",
"&&",
"CLI_SCRIPT",
")",
"{",
"echo",
"'.'",
";",
"}",
"$",
"calculations",
"=",
"array",
"(",
")",
";",
"$",
"newcalculations",
"=",
"array",
"(",
")",
";",
"$",
"notnulls",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"sampleids",
"as",
"$",
"sampleid",
"=>",
"$",
"unusedsampleid",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"existingcalculations",
"[",
"$",
"sampleid",
"]",
")",
")",
"{",
"$",
"calculatedvalue",
"=",
"$",
"existingcalculations",
"[",
"$",
"sampleid",
"]",
";",
"}",
"else",
"{",
"$",
"calculatedvalue",
"=",
"$",
"this",
"->",
"calculate_sample",
"(",
"$",
"sampleid",
",",
"$",
"samplesorigin",
",",
"$",
"starttime",
",",
"$",
"endtime",
")",
";",
"$",
"newcalculations",
"[",
"$",
"sampleid",
"]",
"=",
"$",
"calculatedvalue",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"calculatedvalue",
")",
")",
"{",
"$",
"notnulls",
"[",
"$",
"sampleid",
"]",
"=",
"$",
"sampleid",
";",
"$",
"this",
"->",
"validate_calculated_value",
"(",
"$",
"calculatedvalue",
")",
";",
"}",
"$",
"calculations",
"[",
"$",
"sampleid",
"]",
"=",
"$",
"calculatedvalue",
";",
"}",
"$",
"features",
"=",
"$",
"this",
"->",
"to_features",
"(",
"$",
"calculations",
")",
";",
"return",
"array",
"(",
"$",
"features",
",",
"$",
"newcalculations",
",",
"$",
"notnulls",
")",
";",
"}"
] |
Calculates the indicator.
Returns an array of values which size matches $sampleids size.
@param int[] $sampleids
@param string $samplesorigin
@param integer $starttime Limit the calculation to this timestart
@param integer $endtime Limit the calculation to this timeend
@param array $existingcalculations Existing calculations of this indicator, indexed by sampleid.
@return array [0] = [$sampleid => int[]|float[]], [1] = [$sampleid => int|float], [2] = [$sampleid => $sampleid]
|
[
"Calculates",
"the",
"indicator",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/indicator/base.php#L152-L181
|
218,083
|
moodle/moodle
|
mod/lti/register_form.php
|
mod_lti_register_types_form.definition
|
public function definition() {
global $CFG;
$mform =& $this->_form;
$mform->addElement('header', 'setup', get_string('registration_options', 'lti'));
// Tool Provider name.
$strrequired = get_string('required');
$mform->addElement('text', 'lti_registrationname', get_string('registrationname', 'lti'));
$mform->setType('lti_registrationname', PARAM_TEXT);
$mform->addHelpButton('lti_registrationname', 'registrationname', 'lti');
$mform->addRule('lti_registrationname', $strrequired, 'required', null, 'client');
// Registration URL.
$mform->addElement('text', 'lti_registrationurl', get_string('registrationurl', 'lti'), array('size' => '64'));
$mform->setType('lti_registrationurl', PARAM_URL);
$mform->addHelpButton('lti_registrationurl', 'registrationurl', 'lti');
$mform->addRule('lti_registrationurl', $strrequired, 'required', null, 'client');
// LTI Capabilities.
$options = array_keys(lti_get_capabilities());
natcasesort($options);
$attributes = array( 'multiple' => 1, 'size' => min(count($options), 10) );
$mform->addElement('select', 'lti_capabilities', get_string('capabilities', 'lti'),
array_combine($options, $options), $attributes);
$mform->setType('lti_capabilities', PARAM_TEXT);
$mform->addHelpButton('lti_capabilities', 'capabilities', 'lti');
$mform->addRule('lti_capabilities', $strrequired, 'required', null, 'client');
// LTI Services.
$services = lti_get_services();
$options = array();
foreach ($services as $service) {
$options[$service->get_id()] = $service->get_name();
}
$attributes = array( 'multiple' => 1, 'size' => min(count($options), 10) );
$mform->addElement('select', 'lti_services', get_string('services', 'lti'), $options, $attributes);
$mform->setType('lti_services', PARAM_TEXT);
$mform->addHelpButton('lti_services', 'services', 'lti');
$mform->addRule('lti_services', $strrequired, 'required', null, 'client');
$mform->addElement('hidden', 'toolproxyid');
$mform->setType('toolproxyid', PARAM_INT);
$tab = optional_param('tab', '', PARAM_ALPHAEXT);
$mform->addElement('hidden', 'tab', $tab);
$mform->setType('tab', PARAM_ALPHAEXT);
$courseid = optional_param('course', 1, PARAM_INT);
$mform->addElement('hidden', 'course', $courseid);
$mform->setType('course', PARAM_INT);
// Add standard buttons, common to all modules.
$this->add_action_buttons();
}
|
php
|
public function definition() {
global $CFG;
$mform =& $this->_form;
$mform->addElement('header', 'setup', get_string('registration_options', 'lti'));
// Tool Provider name.
$strrequired = get_string('required');
$mform->addElement('text', 'lti_registrationname', get_string('registrationname', 'lti'));
$mform->setType('lti_registrationname', PARAM_TEXT);
$mform->addHelpButton('lti_registrationname', 'registrationname', 'lti');
$mform->addRule('lti_registrationname', $strrequired, 'required', null, 'client');
// Registration URL.
$mform->addElement('text', 'lti_registrationurl', get_string('registrationurl', 'lti'), array('size' => '64'));
$mform->setType('lti_registrationurl', PARAM_URL);
$mform->addHelpButton('lti_registrationurl', 'registrationurl', 'lti');
$mform->addRule('lti_registrationurl', $strrequired, 'required', null, 'client');
// LTI Capabilities.
$options = array_keys(lti_get_capabilities());
natcasesort($options);
$attributes = array( 'multiple' => 1, 'size' => min(count($options), 10) );
$mform->addElement('select', 'lti_capabilities', get_string('capabilities', 'lti'),
array_combine($options, $options), $attributes);
$mform->setType('lti_capabilities', PARAM_TEXT);
$mform->addHelpButton('lti_capabilities', 'capabilities', 'lti');
$mform->addRule('lti_capabilities', $strrequired, 'required', null, 'client');
// LTI Services.
$services = lti_get_services();
$options = array();
foreach ($services as $service) {
$options[$service->get_id()] = $service->get_name();
}
$attributes = array( 'multiple' => 1, 'size' => min(count($options), 10) );
$mform->addElement('select', 'lti_services', get_string('services', 'lti'), $options, $attributes);
$mform->setType('lti_services', PARAM_TEXT);
$mform->addHelpButton('lti_services', 'services', 'lti');
$mform->addRule('lti_services', $strrequired, 'required', null, 'client');
$mform->addElement('hidden', 'toolproxyid');
$mform->setType('toolproxyid', PARAM_INT);
$tab = optional_param('tab', '', PARAM_ALPHAEXT);
$mform->addElement('hidden', 'tab', $tab);
$mform->setType('tab', PARAM_ALPHAEXT);
$courseid = optional_param('course', 1, PARAM_INT);
$mform->addElement('hidden', 'course', $courseid);
$mform->setType('course', PARAM_INT);
// Add standard buttons, common to all modules.
$this->add_action_buttons();
}
|
[
"public",
"function",
"definition",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"mform",
"=",
"&",
"$",
"this",
"->",
"_form",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'header'",
",",
"'setup'",
",",
"get_string",
"(",
"'registration_options'",
",",
"'lti'",
")",
")",
";",
"// Tool Provider name.",
"$",
"strrequired",
"=",
"get_string",
"(",
"'required'",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'text'",
",",
"'lti_registrationname'",
",",
"get_string",
"(",
"'registrationname'",
",",
"'lti'",
")",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'lti_registrationname'",
",",
"PARAM_TEXT",
")",
";",
"$",
"mform",
"->",
"addHelpButton",
"(",
"'lti_registrationname'",
",",
"'registrationname'",
",",
"'lti'",
")",
";",
"$",
"mform",
"->",
"addRule",
"(",
"'lti_registrationname'",
",",
"$",
"strrequired",
",",
"'required'",
",",
"null",
",",
"'client'",
")",
";",
"// Registration URL.",
"$",
"mform",
"->",
"addElement",
"(",
"'text'",
",",
"'lti_registrationurl'",
",",
"get_string",
"(",
"'registrationurl'",
",",
"'lti'",
")",
",",
"array",
"(",
"'size'",
"=>",
"'64'",
")",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'lti_registrationurl'",
",",
"PARAM_URL",
")",
";",
"$",
"mform",
"->",
"addHelpButton",
"(",
"'lti_registrationurl'",
",",
"'registrationurl'",
",",
"'lti'",
")",
";",
"$",
"mform",
"->",
"addRule",
"(",
"'lti_registrationurl'",
",",
"$",
"strrequired",
",",
"'required'",
",",
"null",
",",
"'client'",
")",
";",
"// LTI Capabilities.",
"$",
"options",
"=",
"array_keys",
"(",
"lti_get_capabilities",
"(",
")",
")",
";",
"natcasesort",
"(",
"$",
"options",
")",
";",
"$",
"attributes",
"=",
"array",
"(",
"'multiple'",
"=>",
"1",
",",
"'size'",
"=>",
"min",
"(",
"count",
"(",
"$",
"options",
")",
",",
"10",
")",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'select'",
",",
"'lti_capabilities'",
",",
"get_string",
"(",
"'capabilities'",
",",
"'lti'",
")",
",",
"array_combine",
"(",
"$",
"options",
",",
"$",
"options",
")",
",",
"$",
"attributes",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'lti_capabilities'",
",",
"PARAM_TEXT",
")",
";",
"$",
"mform",
"->",
"addHelpButton",
"(",
"'lti_capabilities'",
",",
"'capabilities'",
",",
"'lti'",
")",
";",
"$",
"mform",
"->",
"addRule",
"(",
"'lti_capabilities'",
",",
"$",
"strrequired",
",",
"'required'",
",",
"null",
",",
"'client'",
")",
";",
"// LTI Services.",
"$",
"services",
"=",
"lti_get_services",
"(",
")",
";",
"$",
"options",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"services",
"as",
"$",
"service",
")",
"{",
"$",
"options",
"[",
"$",
"service",
"->",
"get_id",
"(",
")",
"]",
"=",
"$",
"service",
"->",
"get_name",
"(",
")",
";",
"}",
"$",
"attributes",
"=",
"array",
"(",
"'multiple'",
"=>",
"1",
",",
"'size'",
"=>",
"min",
"(",
"count",
"(",
"$",
"options",
")",
",",
"10",
")",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'select'",
",",
"'lti_services'",
",",
"get_string",
"(",
"'services'",
",",
"'lti'",
")",
",",
"$",
"options",
",",
"$",
"attributes",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'lti_services'",
",",
"PARAM_TEXT",
")",
";",
"$",
"mform",
"->",
"addHelpButton",
"(",
"'lti_services'",
",",
"'services'",
",",
"'lti'",
")",
";",
"$",
"mform",
"->",
"addRule",
"(",
"'lti_services'",
",",
"$",
"strrequired",
",",
"'required'",
",",
"null",
",",
"'client'",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'hidden'",
",",
"'toolproxyid'",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'toolproxyid'",
",",
"PARAM_INT",
")",
";",
"$",
"tab",
"=",
"optional_param",
"(",
"'tab'",
",",
"''",
",",
"PARAM_ALPHAEXT",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'hidden'",
",",
"'tab'",
",",
"$",
"tab",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'tab'",
",",
"PARAM_ALPHAEXT",
")",
";",
"$",
"courseid",
"=",
"optional_param",
"(",
"'course'",
",",
"1",
",",
"PARAM_INT",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'hidden'",
",",
"'course'",
",",
"$",
"courseid",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'course'",
",",
"PARAM_INT",
")",
";",
"// Add standard buttons, common to all modules.",
"$",
"this",
"->",
"add_action_buttons",
"(",
")",
";",
"}"
] |
Set up the form definition.
|
[
"Set",
"up",
"the",
"form",
"definition",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lti/register_form.php#L44-L104
|
218,084
|
moodle/moodle
|
mod/lti/register_form.php
|
mod_lti_register_types_form.disable_fields
|
public function disable_fields() {
$mform =& $this->_form;
$mform->disabledIf('lti_registrationurl', null);
$mform->disabledIf('lti_capabilities', null);
$mform->disabledIf('lti_services', null);
}
|
php
|
public function disable_fields() {
$mform =& $this->_form;
$mform->disabledIf('lti_registrationurl', null);
$mform->disabledIf('lti_capabilities', null);
$mform->disabledIf('lti_services', null);
}
|
[
"public",
"function",
"disable_fields",
"(",
")",
"{",
"$",
"mform",
"=",
"&",
"$",
"this",
"->",
"_form",
";",
"$",
"mform",
"->",
"disabledIf",
"(",
"'lti_registrationurl'",
",",
"null",
")",
";",
"$",
"mform",
"->",
"disabledIf",
"(",
"'lti_capabilities'",
",",
"null",
")",
";",
"$",
"mform",
"->",
"disabledIf",
"(",
"'lti_services'",
",",
"null",
")",
";",
"}"
] |
Set up rules for disabling fields.
|
[
"Set",
"up",
"rules",
"for",
"disabling",
"fields",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lti/register_form.php#L109-L117
|
218,085
|
moodle/moodle
|
lib/filebrowser/file_info_context_course.php
|
file_info_context_course.get_course_areas
|
protected function get_course_areas($extensions = '*', $returnemptyfolders = false) {
global $DB;
$allareas = [
'course_summary',
'course_overviewfiles',
'course_section',
'backup_section',
'backup_course',
'backup_automated',
'course_legacy'
];
if ($returnemptyfolders) {
return $allareas;
}
$params1 = ['contextid' => $this->context->id, 'emptyfilename' => '.'];
$sql1 = "SELECT " . $DB->sql_concat('f.component', "'_'", 'f.filearea') . "
FROM {files} f
WHERE f.filename <> :emptyfilename AND f.contextid = :contextid ";
$sql3 = ' GROUP BY f.component, f.filearea';
list($sql2, $params2) = $this->build_search_files_sql($extensions);
$areaswithfiles = $DB->get_fieldset_sql($sql1 . $sql2 . $sql3, array_merge($params1, $params2));
return array_intersect($allareas, $areaswithfiles);
}
|
php
|
protected function get_course_areas($extensions = '*', $returnemptyfolders = false) {
global $DB;
$allareas = [
'course_summary',
'course_overviewfiles',
'course_section',
'backup_section',
'backup_course',
'backup_automated',
'course_legacy'
];
if ($returnemptyfolders) {
return $allareas;
}
$params1 = ['contextid' => $this->context->id, 'emptyfilename' => '.'];
$sql1 = "SELECT " . $DB->sql_concat('f.component', "'_'", 'f.filearea') . "
FROM {files} f
WHERE f.filename <> :emptyfilename AND f.contextid = :contextid ";
$sql3 = ' GROUP BY f.component, f.filearea';
list($sql2, $params2) = $this->build_search_files_sql($extensions);
$areaswithfiles = $DB->get_fieldset_sql($sql1 . $sql2 . $sql3, array_merge($params1, $params2));
return array_intersect($allareas, $areaswithfiles);
}
|
[
"protected",
"function",
"get_course_areas",
"(",
"$",
"extensions",
"=",
"'*'",
",",
"$",
"returnemptyfolders",
"=",
"false",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"allareas",
"=",
"[",
"'course_summary'",
",",
"'course_overviewfiles'",
",",
"'course_section'",
",",
"'backup_section'",
",",
"'backup_course'",
",",
"'backup_automated'",
",",
"'course_legacy'",
"]",
";",
"if",
"(",
"$",
"returnemptyfolders",
")",
"{",
"return",
"$",
"allareas",
";",
"}",
"$",
"params1",
"=",
"[",
"'contextid'",
"=>",
"$",
"this",
"->",
"context",
"->",
"id",
",",
"'emptyfilename'",
"=>",
"'.'",
"]",
";",
"$",
"sql1",
"=",
"\"SELECT \"",
".",
"$",
"DB",
"->",
"sql_concat",
"(",
"'f.component'",
",",
"\"'_'\"",
",",
"'f.filearea'",
")",
".",
"\"\n FROM {files} f\n WHERE f.filename <> :emptyfilename AND f.contextid = :contextid \"",
";",
"$",
"sql3",
"=",
"' GROUP BY f.component, f.filearea'",
";",
"list",
"(",
"$",
"sql2",
",",
"$",
"params2",
")",
"=",
"$",
"this",
"->",
"build_search_files_sql",
"(",
"$",
"extensions",
")",
";",
"$",
"areaswithfiles",
"=",
"$",
"DB",
"->",
"get_fieldset_sql",
"(",
"$",
"sql1",
".",
"$",
"sql2",
".",
"$",
"sql3",
",",
"array_merge",
"(",
"$",
"params1",
",",
"$",
"params2",
")",
")",
";",
"return",
"array_intersect",
"(",
"$",
"allareas",
",",
"$",
"areaswithfiles",
")",
";",
"}"
] |
Returns list of areas inside this course
@param string $extensions Only return areas that have files with these extensions
@param bool $returnemptyfolders return all areas always, if true it will ignore the previous argument
@return array
|
[
"Returns",
"list",
"of",
"areas",
"inside",
"this",
"course"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filebrowser/file_info_context_course.php#L99-L125
|
218,086
|
moodle/moodle
|
lib/filebrowser/file_info_context_course.php
|
file_info_context_course.get_area_course_section
|
protected function get_area_course_section($itemid, $filepath, $filename) {
global $CFG, $DB;
if (!has_capability('moodle/course:update', $this->context)) {
return null;
}
if (empty($itemid)) {
// list all sections
return new file_info_area_course_section($this->browser, $this->context, $this->course, $this);
}
if (!$section = $DB->get_record('course_sections', array('course'=>$this->course->id, 'id'=>$itemid))) {
return null; // does not exist
}
$fs = get_file_storage();
$filepath = is_null($filepath) ? '/' : $filepath;
$filename = is_null($filename) ? '.' : $filename;
if (!$storedfile = $fs->get_file($this->context->id, 'course', 'section', $itemid, $filepath, $filename)) {
if ($filepath === '/' and $filename === '.') {
$storedfile = new virtual_root_file($this->context->id, 'course', 'section', $itemid);
} else {
// not found
return null;
}
}
$urlbase = $CFG->wwwroot.'/pluginfile.php';
require_once($CFG->dirroot.'/course/lib.php');
$sectionname = get_section_name($this->course, $section);
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, $sectionname, true, true, true, false);
}
|
php
|
protected function get_area_course_section($itemid, $filepath, $filename) {
global $CFG, $DB;
if (!has_capability('moodle/course:update', $this->context)) {
return null;
}
if (empty($itemid)) {
// list all sections
return new file_info_area_course_section($this->browser, $this->context, $this->course, $this);
}
if (!$section = $DB->get_record('course_sections', array('course'=>$this->course->id, 'id'=>$itemid))) {
return null; // does not exist
}
$fs = get_file_storage();
$filepath = is_null($filepath) ? '/' : $filepath;
$filename = is_null($filename) ? '.' : $filename;
if (!$storedfile = $fs->get_file($this->context->id, 'course', 'section', $itemid, $filepath, $filename)) {
if ($filepath === '/' and $filename === '.') {
$storedfile = new virtual_root_file($this->context->id, 'course', 'section', $itemid);
} else {
// not found
return null;
}
}
$urlbase = $CFG->wwwroot.'/pluginfile.php';
require_once($CFG->dirroot.'/course/lib.php');
$sectionname = get_section_name($this->course, $section);
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, $sectionname, true, true, true, false);
}
|
[
"protected",
"function",
"get_area_course_section",
"(",
"$",
"itemid",
",",
"$",
"filepath",
",",
"$",
"filename",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
";",
"if",
"(",
"!",
"has_capability",
"(",
"'moodle/course:update'",
",",
"$",
"this",
"->",
"context",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"itemid",
")",
")",
"{",
"// list all sections",
"return",
"new",
"file_info_area_course_section",
"(",
"$",
"this",
"->",
"browser",
",",
"$",
"this",
"->",
"context",
",",
"$",
"this",
"->",
"course",
",",
"$",
"this",
")",
";",
"}",
"if",
"(",
"!",
"$",
"section",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'course_sections'",
",",
"array",
"(",
"'course'",
"=>",
"$",
"this",
"->",
"course",
"->",
"id",
",",
"'id'",
"=>",
"$",
"itemid",
")",
")",
")",
"{",
"return",
"null",
";",
"// does not exist",
"}",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"$",
"filepath",
"=",
"is_null",
"(",
"$",
"filepath",
")",
"?",
"'/'",
":",
"$",
"filepath",
";",
"$",
"filename",
"=",
"is_null",
"(",
"$",
"filename",
")",
"?",
"'.'",
":",
"$",
"filename",
";",
"if",
"(",
"!",
"$",
"storedfile",
"=",
"$",
"fs",
"->",
"get_file",
"(",
"$",
"this",
"->",
"context",
"->",
"id",
",",
"'course'",
",",
"'section'",
",",
"$",
"itemid",
",",
"$",
"filepath",
",",
"$",
"filename",
")",
")",
"{",
"if",
"(",
"$",
"filepath",
"===",
"'/'",
"and",
"$",
"filename",
"===",
"'.'",
")",
"{",
"$",
"storedfile",
"=",
"new",
"virtual_root_file",
"(",
"$",
"this",
"->",
"context",
"->",
"id",
",",
"'course'",
",",
"'section'",
",",
"$",
"itemid",
")",
";",
"}",
"else",
"{",
"// not found",
"return",
"null",
";",
"}",
"}",
"$",
"urlbase",
"=",
"$",
"CFG",
"->",
"wwwroot",
".",
"'/pluginfile.php'",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/course/lib.php'",
")",
";",
"$",
"sectionname",
"=",
"get_section_name",
"(",
"$",
"this",
"->",
"course",
",",
"$",
"section",
")",
";",
"return",
"new",
"file_info_stored",
"(",
"$",
"this",
"->",
"browser",
",",
"$",
"this",
"->",
"context",
",",
"$",
"storedfile",
",",
"$",
"urlbase",
",",
"$",
"sectionname",
",",
"true",
",",
"true",
",",
"true",
",",
"false",
")",
";",
"}"
] |
Gets a stored file for the course section filearea directory
@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
|
[
"Gets",
"a",
"stored",
"file",
"for",
"the",
"course",
"section",
"filearea",
"directory"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filebrowser/file_info_context_course.php#L203-L235
|
218,087
|
moodle/moodle
|
lib/filebrowser/file_info_context_course.php
|
file_info_context_course.get_area_course_legacy
|
protected function get_area_course_legacy($itemid, $filepath, $filename) {
if (!has_capability('moodle/course:managefiles', $this->context)) {
return null;
}
if ($this->course->id != SITEID and $this->course->legacyfiles != 2) {
// bad luck, legacy course files not used any more
}
if (is_null($itemid)) {
return $this;
}
$fs = get_file_storage();
$filepath = is_null($filepath) ? '/' : $filepath;
$filename = is_null($filename) ? '.' : $filename;
if (!$storedfile = $fs->get_file($this->context->id, 'course', 'legacy', 0, $filepath, $filename)) {
if ($filepath === '/' and $filename === '.') {
$storedfile = new virtual_root_file($this->context->id, 'course', 'legacy', 0);
} else {
// not found
return null;
}
}
return new file_info_area_course_legacy($this->browser, $this->context, $storedfile);
}
|
php
|
protected function get_area_course_legacy($itemid, $filepath, $filename) {
if (!has_capability('moodle/course:managefiles', $this->context)) {
return null;
}
if ($this->course->id != SITEID and $this->course->legacyfiles != 2) {
// bad luck, legacy course files not used any more
}
if (is_null($itemid)) {
return $this;
}
$fs = get_file_storage();
$filepath = is_null($filepath) ? '/' : $filepath;
$filename = is_null($filename) ? '.' : $filename;
if (!$storedfile = $fs->get_file($this->context->id, 'course', 'legacy', 0, $filepath, $filename)) {
if ($filepath === '/' and $filename === '.') {
$storedfile = new virtual_root_file($this->context->id, 'course', 'legacy', 0);
} else {
// not found
return null;
}
}
return new file_info_area_course_legacy($this->browser, $this->context, $storedfile);
}
|
[
"protected",
"function",
"get_area_course_legacy",
"(",
"$",
"itemid",
",",
"$",
"filepath",
",",
"$",
"filename",
")",
"{",
"if",
"(",
"!",
"has_capability",
"(",
"'moodle/course:managefiles'",
",",
"$",
"this",
"->",
"context",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"course",
"->",
"id",
"!=",
"SITEID",
"and",
"$",
"this",
"->",
"course",
"->",
"legacyfiles",
"!=",
"2",
")",
"{",
"// bad luck, legacy course files not used any more",
"}",
"if",
"(",
"is_null",
"(",
"$",
"itemid",
")",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"$",
"filepath",
"=",
"is_null",
"(",
"$",
"filepath",
")",
"?",
"'/'",
":",
"$",
"filepath",
";",
"$",
"filename",
"=",
"is_null",
"(",
"$",
"filename",
")",
"?",
"'.'",
":",
"$",
"filename",
";",
"if",
"(",
"!",
"$",
"storedfile",
"=",
"$",
"fs",
"->",
"get_file",
"(",
"$",
"this",
"->",
"context",
"->",
"id",
",",
"'course'",
",",
"'legacy'",
",",
"0",
",",
"$",
"filepath",
",",
"$",
"filename",
")",
")",
"{",
"if",
"(",
"$",
"filepath",
"===",
"'/'",
"and",
"$",
"filename",
"===",
"'.'",
")",
"{",
"$",
"storedfile",
"=",
"new",
"virtual_root_file",
"(",
"$",
"this",
"->",
"context",
"->",
"id",
",",
"'course'",
",",
"'legacy'",
",",
"0",
")",
";",
"}",
"else",
"{",
"// not found",
"return",
"null",
";",
"}",
"}",
"return",
"new",
"file_info_area_course_legacy",
"(",
"$",
"this",
"->",
"browser",
",",
"$",
"this",
"->",
"context",
",",
"$",
"storedfile",
")",
";",
"}"
] |
Gets a stored file for the course legacy filearea directory
@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
|
[
"Gets",
"a",
"stored",
"file",
"for",
"the",
"course",
"legacy",
"filearea",
"directory"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filebrowser/file_info_context_course.php#L245-L272
|
218,088
|
moodle/moodle
|
lib/filebrowser/file_info_context_course.php
|
file_info_context_course.get_area_backup_section
|
protected function get_area_backup_section($itemid, $filepath, $filename) {
global $CFG, $DB;
if (!has_capability('moodle/backup:backupcourse', $this->context) and !has_capability('moodle/restore:restorecourse', $this->context)) {
return null;
}
if (empty($itemid)) {
// list all sections
return new file_info_area_backup_section($this->browser, $this->context, $this->course, $this);
}
if (!$section = $DB->get_record('course_sections', array('course'=>$this->course->id, 'id'=>$itemid))) {
return null; // does not exist
}
$fs = get_file_storage();
$filepath = is_null($filepath) ? '/' : $filepath;
$filename = is_null($filename) ? '.' : $filename;
if (!$storedfile = $fs->get_file($this->context->id, 'backup', 'section', $itemid, $filepath, $filename)) {
if ($filepath === '/' and $filename === '.') {
$storedfile = new virtual_root_file($this->context->id, 'backup', 'section', $itemid);
} else {
// not found
return null;
}
}
$downloadable = has_capability('moodle/backup:downloadfile', $this->context);
$uploadable = has_capability('moodle/restore:uploadfile', $this->context);
$urlbase = $CFG->wwwroot.'/pluginfile.php';
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, $section->id, true, $downloadable, $uploadable, false);
}
|
php
|
protected function get_area_backup_section($itemid, $filepath, $filename) {
global $CFG, $DB;
if (!has_capability('moodle/backup:backupcourse', $this->context) and !has_capability('moodle/restore:restorecourse', $this->context)) {
return null;
}
if (empty($itemid)) {
// list all sections
return new file_info_area_backup_section($this->browser, $this->context, $this->course, $this);
}
if (!$section = $DB->get_record('course_sections', array('course'=>$this->course->id, 'id'=>$itemid))) {
return null; // does not exist
}
$fs = get_file_storage();
$filepath = is_null($filepath) ? '/' : $filepath;
$filename = is_null($filename) ? '.' : $filename;
if (!$storedfile = $fs->get_file($this->context->id, 'backup', 'section', $itemid, $filepath, $filename)) {
if ($filepath === '/' and $filename === '.') {
$storedfile = new virtual_root_file($this->context->id, 'backup', 'section', $itemid);
} else {
// not found
return null;
}
}
$downloadable = has_capability('moodle/backup:downloadfile', $this->context);
$uploadable = has_capability('moodle/restore:uploadfile', $this->context);
$urlbase = $CFG->wwwroot.'/pluginfile.php';
return new file_info_stored($this->browser, $this->context, $storedfile, $urlbase, $section->id, true, $downloadable, $uploadable, false);
}
|
[
"protected",
"function",
"get_area_backup_section",
"(",
"$",
"itemid",
",",
"$",
"filepath",
",",
"$",
"filename",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
";",
"if",
"(",
"!",
"has_capability",
"(",
"'moodle/backup:backupcourse'",
",",
"$",
"this",
"->",
"context",
")",
"and",
"!",
"has_capability",
"(",
"'moodle/restore:restorecourse'",
",",
"$",
"this",
"->",
"context",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"itemid",
")",
")",
"{",
"// list all sections",
"return",
"new",
"file_info_area_backup_section",
"(",
"$",
"this",
"->",
"browser",
",",
"$",
"this",
"->",
"context",
",",
"$",
"this",
"->",
"course",
",",
"$",
"this",
")",
";",
"}",
"if",
"(",
"!",
"$",
"section",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'course_sections'",
",",
"array",
"(",
"'course'",
"=>",
"$",
"this",
"->",
"course",
"->",
"id",
",",
"'id'",
"=>",
"$",
"itemid",
")",
")",
")",
"{",
"return",
"null",
";",
"// does not exist",
"}",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"$",
"filepath",
"=",
"is_null",
"(",
"$",
"filepath",
")",
"?",
"'/'",
":",
"$",
"filepath",
";",
"$",
"filename",
"=",
"is_null",
"(",
"$",
"filename",
")",
"?",
"'.'",
":",
"$",
"filename",
";",
"if",
"(",
"!",
"$",
"storedfile",
"=",
"$",
"fs",
"->",
"get_file",
"(",
"$",
"this",
"->",
"context",
"->",
"id",
",",
"'backup'",
",",
"'section'",
",",
"$",
"itemid",
",",
"$",
"filepath",
",",
"$",
"filename",
")",
")",
"{",
"if",
"(",
"$",
"filepath",
"===",
"'/'",
"and",
"$",
"filename",
"===",
"'.'",
")",
"{",
"$",
"storedfile",
"=",
"new",
"virtual_root_file",
"(",
"$",
"this",
"->",
"context",
"->",
"id",
",",
"'backup'",
",",
"'section'",
",",
"$",
"itemid",
")",
";",
"}",
"else",
"{",
"// not found",
"return",
"null",
";",
"}",
"}",
"$",
"downloadable",
"=",
"has_capability",
"(",
"'moodle/backup:downloadfile'",
",",
"$",
"this",
"->",
"context",
")",
";",
"$",
"uploadable",
"=",
"has_capability",
"(",
"'moodle/restore:uploadfile'",
",",
"$",
"this",
"->",
"context",
")",
";",
"$",
"urlbase",
"=",
"$",
"CFG",
"->",
"wwwroot",
".",
"'/pluginfile.php'",
";",
"return",
"new",
"file_info_stored",
"(",
"$",
"this",
"->",
"browser",
",",
"$",
"this",
"->",
"context",
",",
"$",
"storedfile",
",",
"$",
"urlbase",
",",
"$",
"section",
"->",
"id",
",",
"true",
",",
"$",
"downloadable",
",",
"$",
"uploadable",
",",
"false",
")",
";",
"}"
] |
Gets a stored file for the backup section filearea directory
@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
|
[
"Gets",
"a",
"stored",
"file",
"for",
"the",
"backup",
"section",
"filearea",
"directory"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filebrowser/file_info_context_course.php#L360-L394
|
218,089
|
moodle/moodle
|
lib/filebrowser/file_info_context_course.php
|
file_info_context_course.get_child_module
|
protected function get_child_module($cm) {
$cmid = is_object($cm) ? $cm->id : $cm;
if (!array_key_exists($cmid, $this->childrenmodules)) {
$this->childrenmodules[$cmid] = null;
if (!($cm instanceof cm_info)) {
$cms = get_fast_modinfo($this->course)->cms;
$cm = array_key_exists($cmid, $cms) ? $cms[$cmid] : null;
}
if ($cm && $cm->uservisible) {
$this->childrenmodules[$cmid] = new file_info_context_module($this->browser,
$cm->context, $this->course, $cm, $cm->modname);
}
}
return $this->childrenmodules[$cmid];
}
|
php
|
protected function get_child_module($cm) {
$cmid = is_object($cm) ? $cm->id : $cm;
if (!array_key_exists($cmid, $this->childrenmodules)) {
$this->childrenmodules[$cmid] = null;
if (!($cm instanceof cm_info)) {
$cms = get_fast_modinfo($this->course)->cms;
$cm = array_key_exists($cmid, $cms) ? $cms[$cmid] : null;
}
if ($cm && $cm->uservisible) {
$this->childrenmodules[$cmid] = new file_info_context_module($this->browser,
$cm->context, $this->course, $cm, $cm->modname);
}
}
return $this->childrenmodules[$cmid];
}
|
[
"protected",
"function",
"get_child_module",
"(",
"$",
"cm",
")",
"{",
"$",
"cmid",
"=",
"is_object",
"(",
"$",
"cm",
")",
"?",
"$",
"cm",
"->",
"id",
":",
"$",
"cm",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"cmid",
",",
"$",
"this",
"->",
"childrenmodules",
")",
")",
"{",
"$",
"this",
"->",
"childrenmodules",
"[",
"$",
"cmid",
"]",
"=",
"null",
";",
"if",
"(",
"!",
"(",
"$",
"cm",
"instanceof",
"cm_info",
")",
")",
"{",
"$",
"cms",
"=",
"get_fast_modinfo",
"(",
"$",
"this",
"->",
"course",
")",
"->",
"cms",
";",
"$",
"cm",
"=",
"array_key_exists",
"(",
"$",
"cmid",
",",
"$",
"cms",
")",
"?",
"$",
"cms",
"[",
"$",
"cmid",
"]",
":",
"null",
";",
"}",
"if",
"(",
"$",
"cm",
"&&",
"$",
"cm",
"->",
"uservisible",
")",
"{",
"$",
"this",
"->",
"childrenmodules",
"[",
"$",
"cmid",
"]",
"=",
"new",
"file_info_context_module",
"(",
"$",
"this",
"->",
"browser",
",",
"$",
"cm",
"->",
"context",
",",
"$",
"this",
"->",
"course",
",",
"$",
"cm",
",",
"$",
"cm",
"->",
"modname",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"childrenmodules",
"[",
"$",
"cmid",
"]",
";",
"}"
] |
Returns the child module if it is accessible by the current user
@param cm_info|int $cm
@return file_info_context_module|null
|
[
"Returns",
"the",
"child",
"module",
"if",
"it",
"is",
"accessible",
"by",
"the",
"current",
"user"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filebrowser/file_info_context_course.php#L438-L452
|
218,090
|
moodle/moodle
|
lib/filebrowser/file_info_context_course.php
|
file_info_context_course.get_module_areas_with_files
|
protected function get_module_areas_with_files($extensions = '*') {
global $DB;
$params1 = ['contextid' => $this->context->id,
'emptyfilename' => '.',
'contextlevel' => CONTEXT_MODULE,
'course' => $this->course->id];
$ctxfieldsas = context_helper::get_preload_record_columns_sql('ctx');
$ctxfields = implode(', ', array_keys(context_helper::get_preload_record_columns('ctx')));
$sql1 = "SELECT
ctx.id AS contextid,
f.component,
f.filearea,
f.itemid,
ctx.instanceid AS cmid,
{$ctxfieldsas}
FROM {files} f
INNER JOIN {context} ctx ON ctx.id = f.contextid
INNER JOIN {course_modules} cm ON cm.id = ctx.instanceid
WHERE f.filename <> :emptyfilename
AND cm.course = :course
AND ctx.contextlevel = :contextlevel";
$sql3 = "
GROUP BY ctx.id, f.component, f.filearea, f.itemid, {$ctxfields}
ORDER BY ctx.id, f.component, f.filearea, f.itemid";
list($sql2, $params2) = $this->build_search_files_sql($extensions);
$areas = [];
if ($rs = $DB->get_recordset_sql($sql1. $sql2 . $sql3, array_merge($params1, $params2))) {
foreach ($rs as $record) {
context_helper::preload_from_record($record);
$areas[] = $record;
}
$rs->close();
}
// Sort areas so 'backup' and 'intro' are in the beginning of the list, they are the easiest to check access to.
usort($areas, function($a, $b) {
$aeasy = ($a->filearea === 'intro' && substr($a->component, 0, 4) === 'mod_') ||
($a->filearea === 'activity' && $a->component === 'backup');
$beasy = ($b->filearea === 'intro' && substr($b->component, 0, 4) === 'mod_') ||
($b->filearea === 'activity' && $b->component === 'backup');
return $aeasy == $beasy ? 0 : ($aeasy ? -1 : 1);
});
return $areas;
}
|
php
|
protected function get_module_areas_with_files($extensions = '*') {
global $DB;
$params1 = ['contextid' => $this->context->id,
'emptyfilename' => '.',
'contextlevel' => CONTEXT_MODULE,
'course' => $this->course->id];
$ctxfieldsas = context_helper::get_preload_record_columns_sql('ctx');
$ctxfields = implode(', ', array_keys(context_helper::get_preload_record_columns('ctx')));
$sql1 = "SELECT
ctx.id AS contextid,
f.component,
f.filearea,
f.itemid,
ctx.instanceid AS cmid,
{$ctxfieldsas}
FROM {files} f
INNER JOIN {context} ctx ON ctx.id = f.contextid
INNER JOIN {course_modules} cm ON cm.id = ctx.instanceid
WHERE f.filename <> :emptyfilename
AND cm.course = :course
AND ctx.contextlevel = :contextlevel";
$sql3 = "
GROUP BY ctx.id, f.component, f.filearea, f.itemid, {$ctxfields}
ORDER BY ctx.id, f.component, f.filearea, f.itemid";
list($sql2, $params2) = $this->build_search_files_sql($extensions);
$areas = [];
if ($rs = $DB->get_recordset_sql($sql1. $sql2 . $sql3, array_merge($params1, $params2))) {
foreach ($rs as $record) {
context_helper::preload_from_record($record);
$areas[] = $record;
}
$rs->close();
}
// Sort areas so 'backup' and 'intro' are in the beginning of the list, they are the easiest to check access to.
usort($areas, function($a, $b) {
$aeasy = ($a->filearea === 'intro' && substr($a->component, 0, 4) === 'mod_') ||
($a->filearea === 'activity' && $a->component === 'backup');
$beasy = ($b->filearea === 'intro' && substr($b->component, 0, 4) === 'mod_') ||
($b->filearea === 'activity' && $b->component === 'backup');
return $aeasy == $beasy ? 0 : ($aeasy ? -1 : 1);
});
return $areas;
}
|
[
"protected",
"function",
"get_module_areas_with_files",
"(",
"$",
"extensions",
"=",
"'*'",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"params1",
"=",
"[",
"'contextid'",
"=>",
"$",
"this",
"->",
"context",
"->",
"id",
",",
"'emptyfilename'",
"=>",
"'.'",
",",
"'contextlevel'",
"=>",
"CONTEXT_MODULE",
",",
"'course'",
"=>",
"$",
"this",
"->",
"course",
"->",
"id",
"]",
";",
"$",
"ctxfieldsas",
"=",
"context_helper",
"::",
"get_preload_record_columns_sql",
"(",
"'ctx'",
")",
";",
"$",
"ctxfields",
"=",
"implode",
"(",
"', '",
",",
"array_keys",
"(",
"context_helper",
"::",
"get_preload_record_columns",
"(",
"'ctx'",
")",
")",
")",
";",
"$",
"sql1",
"=",
"\"SELECT\n ctx.id AS contextid,\n f.component,\n f.filearea,\n f.itemid,\n ctx.instanceid AS cmid,\n {$ctxfieldsas}\n FROM {files} f\n INNER JOIN {context} ctx ON ctx.id = f.contextid\n INNER JOIN {course_modules} cm ON cm.id = ctx.instanceid\n WHERE f.filename <> :emptyfilename\n AND cm.course = :course\n AND ctx.contextlevel = :contextlevel\"",
";",
"$",
"sql3",
"=",
"\"\n GROUP BY ctx.id, f.component, f.filearea, f.itemid, {$ctxfields}\n ORDER BY ctx.id, f.component, f.filearea, f.itemid\"",
";",
"list",
"(",
"$",
"sql2",
",",
"$",
"params2",
")",
"=",
"$",
"this",
"->",
"build_search_files_sql",
"(",
"$",
"extensions",
")",
";",
"$",
"areas",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"rs",
"=",
"$",
"DB",
"->",
"get_recordset_sql",
"(",
"$",
"sql1",
".",
"$",
"sql2",
".",
"$",
"sql3",
",",
"array_merge",
"(",
"$",
"params1",
",",
"$",
"params2",
")",
")",
")",
"{",
"foreach",
"(",
"$",
"rs",
"as",
"$",
"record",
")",
"{",
"context_helper",
"::",
"preload_from_record",
"(",
"$",
"record",
")",
";",
"$",
"areas",
"[",
"]",
"=",
"$",
"record",
";",
"}",
"$",
"rs",
"->",
"close",
"(",
")",
";",
"}",
"// Sort areas so 'backup' and 'intro' are in the beginning of the list, they are the easiest to check access to.",
"usort",
"(",
"$",
"areas",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"$",
"aeasy",
"=",
"(",
"$",
"a",
"->",
"filearea",
"===",
"'intro'",
"&&",
"substr",
"(",
"$",
"a",
"->",
"component",
",",
"0",
",",
"4",
")",
"===",
"'mod_'",
")",
"||",
"(",
"$",
"a",
"->",
"filearea",
"===",
"'activity'",
"&&",
"$",
"a",
"->",
"component",
"===",
"'backup'",
")",
";",
"$",
"beasy",
"=",
"(",
"$",
"b",
"->",
"filearea",
"===",
"'intro'",
"&&",
"substr",
"(",
"$",
"b",
"->",
"component",
",",
"0",
",",
"4",
")",
"===",
"'mod_'",
")",
"||",
"(",
"$",
"b",
"->",
"filearea",
"===",
"'activity'",
"&&",
"$",
"b",
"->",
"component",
"===",
"'backup'",
")",
";",
"return",
"$",
"aeasy",
"==",
"$",
"beasy",
"?",
"0",
":",
"(",
"$",
"aeasy",
"?",
"-",
"1",
":",
"1",
")",
";",
"}",
")",
";",
"return",
"$",
"areas",
";",
"}"
] |
Returns list of areas inside the course modules that have files with the given extension
@param string $extensions
@return array
|
[
"Returns",
"list",
"of",
"areas",
"inside",
"the",
"course",
"modules",
"that",
"have",
"files",
"with",
"the",
"given",
"extension"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filebrowser/file_info_context_course.php#L525-L569
|
218,091
|
moodle/moodle
|
lib/classes/message/message.php
|
message.get_fullmessagehtml
|
protected function get_fullmessagehtml($processorname = '') {
if (!empty($processorname) && isset($this->additionalcontent[$processorname])) {
return $this->get_message_with_additional_content($processorname, 'fullmessagehtml');
} else {
return $this->fullmessagehtml;
}
}
|
php
|
protected function get_fullmessagehtml($processorname = '') {
if (!empty($processorname) && isset($this->additionalcontent[$processorname])) {
return $this->get_message_with_additional_content($processorname, 'fullmessagehtml');
} else {
return $this->fullmessagehtml;
}
}
|
[
"protected",
"function",
"get_fullmessagehtml",
"(",
"$",
"processorname",
"=",
"''",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"processorname",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"additionalcontent",
"[",
"$",
"processorname",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"get_message_with_additional_content",
"(",
"$",
"processorname",
",",
"'fullmessagehtml'",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"fullmessagehtml",
";",
"}",
"}"
] |
Fullmessagehtml content including any processor specific content.
@param string $processorname Name of the processor.
@return mixed|string
|
[
"Fullmessagehtml",
"content",
"including",
"any",
"processor",
"specific",
"content",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/message/message.php#L173-L179
|
218,092
|
moodle/moodle
|
lib/classes/message/message.php
|
message.get_fullmessage
|
protected function get_fullmessage($processorname = '') {
if (!empty($processorname) && isset($this->additionalcontent[$processorname])) {
return $this->get_message_with_additional_content($processorname, 'fullmessage');
} else {
return $this->fullmessage;
}
}
|
php
|
protected function get_fullmessage($processorname = '') {
if (!empty($processorname) && isset($this->additionalcontent[$processorname])) {
return $this->get_message_with_additional_content($processorname, 'fullmessage');
} else {
return $this->fullmessage;
}
}
|
[
"protected",
"function",
"get_fullmessage",
"(",
"$",
"processorname",
"=",
"''",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"processorname",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"additionalcontent",
"[",
"$",
"processorname",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"get_message_with_additional_content",
"(",
"$",
"processorname",
",",
"'fullmessage'",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"fullmessage",
";",
"}",
"}"
] |
Fullmessage content including any processor specific content.
@param string $processorname Name of the processor.
@return mixed|string
|
[
"Fullmessage",
"content",
"including",
"any",
"processor",
"specific",
"content",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/message/message.php#L188-L194
|
218,093
|
moodle/moodle
|
lib/classes/message/message.php
|
message.get_smallmessage
|
protected function get_smallmessage($processorname = '') {
if (!empty($processorname) && isset($this->additionalcontent[$processorname])) {
return $this->get_message_with_additional_content($processorname, 'smallmessage');
} else {
return $this->smallmessage;
}
}
|
php
|
protected function get_smallmessage($processorname = '') {
if (!empty($processorname) && isset($this->additionalcontent[$processorname])) {
return $this->get_message_with_additional_content($processorname, 'smallmessage');
} else {
return $this->smallmessage;
}
}
|
[
"protected",
"function",
"get_smallmessage",
"(",
"$",
"processorname",
"=",
"''",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"processorname",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"additionalcontent",
"[",
"$",
"processorname",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"get_message_with_additional_content",
"(",
"$",
"processorname",
",",
"'smallmessage'",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"smallmessage",
";",
"}",
"}"
] |
Smallmessage content including any processor specific content.
@param string $processorname Name of the processor.
@return mixed|string
|
[
"Smallmessage",
"content",
"including",
"any",
"processor",
"specific",
"content",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/message/message.php#L203-L209
|
218,094
|
moodle/moodle
|
lib/classes/message/message.php
|
message.set_customdata
|
protected function set_customdata($customdata) {
// Always include the courseid (because is not stored in the notifications or messages table).
if (!empty($this->courseid) && (is_object($customdata) || is_array($customdata))) {
$customdata = (array) $customdata;
$customdata['courseid'] = $this->courseid;
}
$this->customdata = json_encode($customdata);
}
|
php
|
protected function set_customdata($customdata) {
// Always include the courseid (because is not stored in the notifications or messages table).
if (!empty($this->courseid) && (is_object($customdata) || is_array($customdata))) {
$customdata = (array) $customdata;
$customdata['courseid'] = $this->courseid;
}
$this->customdata = json_encode($customdata);
}
|
[
"protected",
"function",
"set_customdata",
"(",
"$",
"customdata",
")",
"{",
"// Always include the courseid (because is not stored in the notifications or messages table).",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"courseid",
")",
"&&",
"(",
"is_object",
"(",
"$",
"customdata",
")",
"||",
"is_array",
"(",
"$",
"customdata",
")",
")",
")",
"{",
"$",
"customdata",
"=",
"(",
"array",
")",
"$",
"customdata",
";",
"$",
"customdata",
"[",
"'courseid'",
"]",
"=",
"$",
"this",
"->",
"courseid",
";",
"}",
"$",
"this",
"->",
"customdata",
"=",
"json_encode",
"(",
"$",
"customdata",
")",
";",
"}"
] |
Always JSON encode customdata.
@param mixed $customdata a data structure that must be serialisable using json_encode().
|
[
"Always",
"JSON",
"encode",
"customdata",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/message/message.php#L216-L223
|
218,095
|
moodle/moodle
|
lib/classes/message/message.php
|
message.get_message_with_additional_content
|
protected function get_message_with_additional_content($processorname, $messagetype) {
$message = $this->$messagetype;
if (isset($this->additionalcontent[$processorname]['*'])) {
// Content that needs to be added to all format.
$pattern = $this->additionalcontent[$processorname]['*'];
$message = empty($pattern['header']) ? $message : $pattern['header'] . $message;
$message = empty($pattern['footer']) ? $message : $message . $pattern['footer'];
}
if (isset($this->additionalcontent[$processorname][$messagetype])) {
// Content that needs to be added to the specific given format.
$pattern = $this->additionalcontent[$processorname][$messagetype];
$message = empty($pattern['header']) ? $message : $pattern['header'] . $message;
$message = empty($pattern['footer']) ? $message : $message . $pattern['footer'];
}
return $message;
}
|
php
|
protected function get_message_with_additional_content($processorname, $messagetype) {
$message = $this->$messagetype;
if (isset($this->additionalcontent[$processorname]['*'])) {
// Content that needs to be added to all format.
$pattern = $this->additionalcontent[$processorname]['*'];
$message = empty($pattern['header']) ? $message : $pattern['header'] . $message;
$message = empty($pattern['footer']) ? $message : $message . $pattern['footer'];
}
if (isset($this->additionalcontent[$processorname][$messagetype])) {
// Content that needs to be added to the specific given format.
$pattern = $this->additionalcontent[$processorname][$messagetype];
$message = empty($pattern['header']) ? $message : $pattern['header'] . $message;
$message = empty($pattern['footer']) ? $message : $message . $pattern['footer'];
}
return $message;
}
|
[
"protected",
"function",
"get_message_with_additional_content",
"(",
"$",
"processorname",
",",
"$",
"messagetype",
")",
"{",
"$",
"message",
"=",
"$",
"this",
"->",
"$",
"messagetype",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"additionalcontent",
"[",
"$",
"processorname",
"]",
"[",
"'*'",
"]",
")",
")",
"{",
"// Content that needs to be added to all format.",
"$",
"pattern",
"=",
"$",
"this",
"->",
"additionalcontent",
"[",
"$",
"processorname",
"]",
"[",
"'*'",
"]",
";",
"$",
"message",
"=",
"empty",
"(",
"$",
"pattern",
"[",
"'header'",
"]",
")",
"?",
"$",
"message",
":",
"$",
"pattern",
"[",
"'header'",
"]",
".",
"$",
"message",
";",
"$",
"message",
"=",
"empty",
"(",
"$",
"pattern",
"[",
"'footer'",
"]",
")",
"?",
"$",
"message",
":",
"$",
"message",
".",
"$",
"pattern",
"[",
"'footer'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"additionalcontent",
"[",
"$",
"processorname",
"]",
"[",
"$",
"messagetype",
"]",
")",
")",
"{",
"// Content that needs to be added to the specific given format.",
"$",
"pattern",
"=",
"$",
"this",
"->",
"additionalcontent",
"[",
"$",
"processorname",
"]",
"[",
"$",
"messagetype",
"]",
";",
"$",
"message",
"=",
"empty",
"(",
"$",
"pattern",
"[",
"'header'",
"]",
")",
"?",
"$",
"message",
":",
"$",
"pattern",
"[",
"'header'",
"]",
".",
"$",
"message",
";",
"$",
"message",
"=",
"empty",
"(",
"$",
"pattern",
"[",
"'footer'",
"]",
")",
"?",
"$",
"message",
":",
"$",
"message",
".",
"$",
"pattern",
"[",
"'footer'",
"]",
";",
"}",
"return",
"$",
"message",
";",
"}"
] |
Helper method used to get message content added with processor specific content.
@param string $processorname Name of the processor.
@param string $messagetype one of 'fullmessagehtml', 'fullmessage', 'smallmessage'.
@return mixed|string
|
[
"Helper",
"method",
"used",
"to",
"get",
"message",
"content",
"added",
"with",
"processor",
"specific",
"content",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/message/message.php#L233-L250
|
218,096
|
moodle/moodle
|
lib/classes/message/message.php
|
message.__isset
|
public function __isset($prop) {
if (in_array($prop, $this->properties)) {
return isset($this->$prop);
}
throw new \coding_exception("Invalid property $prop specified");
}
|
php
|
public function __isset($prop) {
if (in_array($prop, $this->properties)) {
return isset($this->$prop);
}
throw new \coding_exception("Invalid property $prop specified");
}
|
[
"public",
"function",
"__isset",
"(",
"$",
"prop",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"prop",
",",
"$",
"this",
"->",
"properties",
")",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"$",
"prop",
")",
";",
"}",
"throw",
"new",
"\\",
"coding_exception",
"(",
"\"Invalid property $prop specified\"",
")",
";",
"}"
] |
Magic method to check if property is set.
@param string $prop name of property to check.
@return bool
@throws \coding_exception
|
[
"Magic",
"method",
"to",
"check",
"if",
"property",
"is",
"set",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/message/message.php#L296-L301
|
218,097
|
moodle/moodle
|
lib/classes/message/message.php
|
message.get_eventobject_for_processor
|
public function get_eventobject_for_processor($processorname) {
// This is done for Backwards compatibility. We should consider throwing notices here in future versions and requesting
// them to use proper api.
$eventdata = new \stdClass();
foreach ($this->properties as $prop) {
$func = "get_$prop";
$eventdata->$prop = method_exists($this, $func) ? $this->$func($processorname) : $this->$prop;
}
return $eventdata;
}
|
php
|
public function get_eventobject_for_processor($processorname) {
// This is done for Backwards compatibility. We should consider throwing notices here in future versions and requesting
// them to use proper api.
$eventdata = new \stdClass();
foreach ($this->properties as $prop) {
$func = "get_$prop";
$eventdata->$prop = method_exists($this, $func) ? $this->$func($processorname) : $this->$prop;
}
return $eventdata;
}
|
[
"public",
"function",
"get_eventobject_for_processor",
"(",
"$",
"processorname",
")",
"{",
"// This is done for Backwards compatibility. We should consider throwing notices here in future versions and requesting",
"// them to use proper api.",
"$",
"eventdata",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"properties",
"as",
"$",
"prop",
")",
"{",
"$",
"func",
"=",
"\"get_$prop\"",
";",
"$",
"eventdata",
"->",
"$",
"prop",
"=",
"method_exists",
"(",
"$",
"this",
",",
"$",
"func",
")",
"?",
"$",
"this",
"->",
"$",
"func",
"(",
"$",
"processorname",
")",
":",
"$",
"this",
"->",
"$",
"prop",
";",
"}",
"return",
"$",
"eventdata",
";",
"}"
] |
Get a event object for a specific processor in stdClass format.
@param string $processorname Name of the processor.
@return \stdClass event object in stdClass format.
|
[
"Get",
"a",
"event",
"object",
"for",
"a",
"specific",
"processor",
"in",
"stdClass",
"format",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/message/message.php#L326-L336
|
218,098
|
moodle/moodle
|
lib/classes/plugininfo/media.php
|
media.set_enabled_plugins
|
public static function set_enabled_plugins($list) {
if (empty($list)) {
$list = [];
} else if (!is_array($list)) {
$list = explode(',', $list);
}
if ($list) {
$plugins = \core_plugin_manager::instance()->get_installed_plugins('media');
$list = array_intersect($list, array_keys($plugins));
}
set_config('media_plugins_sortorder', join(',', $list));
\core_plugin_manager::reset_caches();
\core_media_manager::reset_caches();
}
|
php
|
public static function set_enabled_plugins($list) {
if (empty($list)) {
$list = [];
} else if (!is_array($list)) {
$list = explode(',', $list);
}
if ($list) {
$plugins = \core_plugin_manager::instance()->get_installed_plugins('media');
$list = array_intersect($list, array_keys($plugins));
}
set_config('media_plugins_sortorder', join(',', $list));
\core_plugin_manager::reset_caches();
\core_media_manager::reset_caches();
}
|
[
"public",
"static",
"function",
"set_enabled_plugins",
"(",
"$",
"list",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"list",
")",
")",
"{",
"$",
"list",
"=",
"[",
"]",
";",
"}",
"else",
"if",
"(",
"!",
"is_array",
"(",
"$",
"list",
")",
")",
"{",
"$",
"list",
"=",
"explode",
"(",
"','",
",",
"$",
"list",
")",
";",
"}",
"if",
"(",
"$",
"list",
")",
"{",
"$",
"plugins",
"=",
"\\",
"core_plugin_manager",
"::",
"instance",
"(",
")",
"->",
"get_installed_plugins",
"(",
"'media'",
")",
";",
"$",
"list",
"=",
"array_intersect",
"(",
"$",
"list",
",",
"array_keys",
"(",
"$",
"plugins",
")",
")",
";",
"}",
"set_config",
"(",
"'media_plugins_sortorder'",
",",
"join",
"(",
"','",
",",
"$",
"list",
")",
")",
";",
"\\",
"core_plugin_manager",
"::",
"reset_caches",
"(",
")",
";",
"\\",
"core_media_manager",
"::",
"reset_caches",
"(",
")",
";",
"}"
] |
Set the list of enabled media players in the specified sort order
To be used when changing settings or in unit tests
@param string|array $list list of plugin names without frankenstyle prefix - comma-separated string or an array
|
[
"Set",
"the",
"list",
"of",
"enabled",
"media",
"players",
"in",
"the",
"specified",
"sort",
"order",
"To",
"be",
"used",
"when",
"changing",
"settings",
"or",
"in",
"unit",
"tests"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/plugininfo/media.php#L143-L156
|
218,099
|
moodle/moodle
|
lib/classes/plugininfo/media.php
|
media.get_rank
|
public function get_rank() {
$classname = '\media_'.$this->name.'_plugin';
if (class_exists($classname)) {
$object = new $classname();
return $object->get_rank();
}
return 0;
}
|
php
|
public function get_rank() {
$classname = '\media_'.$this->name.'_plugin';
if (class_exists($classname)) {
$object = new $classname();
return $object->get_rank();
}
return 0;
}
|
[
"public",
"function",
"get_rank",
"(",
")",
"{",
"$",
"classname",
"=",
"'\\media_'",
".",
"$",
"this",
"->",
"name",
".",
"'_plugin'",
";",
"if",
"(",
"class_exists",
"(",
"$",
"classname",
")",
")",
"{",
"$",
"object",
"=",
"new",
"$",
"classname",
"(",
")",
";",
"return",
"$",
"object",
"->",
"get_rank",
"(",
")",
";",
"}",
"return",
"0",
";",
"}"
] |
Returns the default rank of this plugin for default sort order
@return int
|
[
"Returns",
"the",
"default",
"rank",
"of",
"this",
"plugin",
"for",
"default",
"sort",
"order"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/plugininfo/media.php#L162-L169
|
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.