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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
219,800
|
moodle/moodle
|
lib/outputcomponents.php
|
html_writer.select_time
|
public static function select_time($type, $name, $currenttime = 0, $step = 5, array $attributes = null) {
global $OUTPUT;
if (!$currenttime) {
$currenttime = time();
}
$calendartype = \core_calendar\type_factory::get_calendar_instance();
$currentdate = $calendartype->timestamp_to_date_array($currenttime);
$userdatetype = $type;
$timeunits = array();
switch ($type) {
case 'years':
$timeunits = $calendartype->get_years();
$userdatetype = 'year';
break;
case 'months':
$timeunits = $calendartype->get_months();
$userdatetype = 'month';
$currentdate['month'] = (int)$currentdate['mon'];
break;
case 'days':
$timeunits = $calendartype->get_days();
$userdatetype = 'mday';
break;
case 'hours':
for ($i=0; $i<=23; $i++) {
$timeunits[$i] = sprintf("%02d",$i);
}
break;
case 'minutes':
if ($step != 1) {
$currentdate['minutes'] = ceil($currentdate['minutes']/$step)*$step;
}
for ($i=0; $i<=59; $i+=$step) {
$timeunits[$i] = sprintf("%02d",$i);
}
break;
default:
throw new coding_exception("Time type $type is not supported by html_writer::select_time().");
}
$attributes = (array) $attributes;
$data = (object) [
'name' => $name,
'id' => !empty($attributes['id']) ? $attributes['id'] : self::random_id('ts_'),
'label' => get_string(substr($type, 0, -1), 'form'),
'options' => array_map(function($value) use ($timeunits, $currentdate, $userdatetype) {
return [
'name' => $timeunits[$value],
'value' => $value,
'selected' => $currentdate[$userdatetype] == $value
];
}, array_keys($timeunits)),
];
unset($attributes['id']);
unset($attributes['name']);
$data->attributes = array_map(function($name) use ($attributes) {
return [
'name' => $name,
'value' => $attributes[$name]
];
}, array_keys($attributes));
return $OUTPUT->render_from_template('core/select_time', $data);
}
|
php
|
public static function select_time($type, $name, $currenttime = 0, $step = 5, array $attributes = null) {
global $OUTPUT;
if (!$currenttime) {
$currenttime = time();
}
$calendartype = \core_calendar\type_factory::get_calendar_instance();
$currentdate = $calendartype->timestamp_to_date_array($currenttime);
$userdatetype = $type;
$timeunits = array();
switch ($type) {
case 'years':
$timeunits = $calendartype->get_years();
$userdatetype = 'year';
break;
case 'months':
$timeunits = $calendartype->get_months();
$userdatetype = 'month';
$currentdate['month'] = (int)$currentdate['mon'];
break;
case 'days':
$timeunits = $calendartype->get_days();
$userdatetype = 'mday';
break;
case 'hours':
for ($i=0; $i<=23; $i++) {
$timeunits[$i] = sprintf("%02d",$i);
}
break;
case 'minutes':
if ($step != 1) {
$currentdate['minutes'] = ceil($currentdate['minutes']/$step)*$step;
}
for ($i=0; $i<=59; $i+=$step) {
$timeunits[$i] = sprintf("%02d",$i);
}
break;
default:
throw new coding_exception("Time type $type is not supported by html_writer::select_time().");
}
$attributes = (array) $attributes;
$data = (object) [
'name' => $name,
'id' => !empty($attributes['id']) ? $attributes['id'] : self::random_id('ts_'),
'label' => get_string(substr($type, 0, -1), 'form'),
'options' => array_map(function($value) use ($timeunits, $currentdate, $userdatetype) {
return [
'name' => $timeunits[$value],
'value' => $value,
'selected' => $currentdate[$userdatetype] == $value
];
}, array_keys($timeunits)),
];
unset($attributes['id']);
unset($attributes['name']);
$data->attributes = array_map(function($name) use ($attributes) {
return [
'name' => $name,
'value' => $attributes[$name]
];
}, array_keys($attributes));
return $OUTPUT->render_from_template('core/select_time', $data);
}
|
[
"public",
"static",
"function",
"select_time",
"(",
"$",
"type",
",",
"$",
"name",
",",
"$",
"currenttime",
"=",
"0",
",",
"$",
"step",
"=",
"5",
",",
"array",
"$",
"attributes",
"=",
"null",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"if",
"(",
"!",
"$",
"currenttime",
")",
"{",
"$",
"currenttime",
"=",
"time",
"(",
")",
";",
"}",
"$",
"calendartype",
"=",
"\\",
"core_calendar",
"\\",
"type_factory",
"::",
"get_calendar_instance",
"(",
")",
";",
"$",
"currentdate",
"=",
"$",
"calendartype",
"->",
"timestamp_to_date_array",
"(",
"$",
"currenttime",
")",
";",
"$",
"userdatetype",
"=",
"$",
"type",
";",
"$",
"timeunits",
"=",
"array",
"(",
")",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'years'",
":",
"$",
"timeunits",
"=",
"$",
"calendartype",
"->",
"get_years",
"(",
")",
";",
"$",
"userdatetype",
"=",
"'year'",
";",
"break",
";",
"case",
"'months'",
":",
"$",
"timeunits",
"=",
"$",
"calendartype",
"->",
"get_months",
"(",
")",
";",
"$",
"userdatetype",
"=",
"'month'",
";",
"$",
"currentdate",
"[",
"'month'",
"]",
"=",
"(",
"int",
")",
"$",
"currentdate",
"[",
"'mon'",
"]",
";",
"break",
";",
"case",
"'days'",
":",
"$",
"timeunits",
"=",
"$",
"calendartype",
"->",
"get_days",
"(",
")",
";",
"$",
"userdatetype",
"=",
"'mday'",
";",
"break",
";",
"case",
"'hours'",
":",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<=",
"23",
";",
"$",
"i",
"++",
")",
"{",
"$",
"timeunits",
"[",
"$",
"i",
"]",
"=",
"sprintf",
"(",
"\"%02d\"",
",",
"$",
"i",
")",
";",
"}",
"break",
";",
"case",
"'minutes'",
":",
"if",
"(",
"$",
"step",
"!=",
"1",
")",
"{",
"$",
"currentdate",
"[",
"'minutes'",
"]",
"=",
"ceil",
"(",
"$",
"currentdate",
"[",
"'minutes'",
"]",
"/",
"$",
"step",
")",
"*",
"$",
"step",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<=",
"59",
";",
"$",
"i",
"+=",
"$",
"step",
")",
"{",
"$",
"timeunits",
"[",
"$",
"i",
"]",
"=",
"sprintf",
"(",
"\"%02d\"",
",",
"$",
"i",
")",
";",
"}",
"break",
";",
"default",
":",
"throw",
"new",
"coding_exception",
"(",
"\"Time type $type is not supported by html_writer::select_time().\"",
")",
";",
"}",
"$",
"attributes",
"=",
"(",
"array",
")",
"$",
"attributes",
";",
"$",
"data",
"=",
"(",
"object",
")",
"[",
"'name'",
"=>",
"$",
"name",
",",
"'id'",
"=>",
"!",
"empty",
"(",
"$",
"attributes",
"[",
"'id'",
"]",
")",
"?",
"$",
"attributes",
"[",
"'id'",
"]",
":",
"self",
"::",
"random_id",
"(",
"'ts_'",
")",
",",
"'label'",
"=>",
"get_string",
"(",
"substr",
"(",
"$",
"type",
",",
"0",
",",
"-",
"1",
")",
",",
"'form'",
")",
",",
"'options'",
"=>",
"array_map",
"(",
"function",
"(",
"$",
"value",
")",
"use",
"(",
"$",
"timeunits",
",",
"$",
"currentdate",
",",
"$",
"userdatetype",
")",
"{",
"return",
"[",
"'name'",
"=>",
"$",
"timeunits",
"[",
"$",
"value",
"]",
",",
"'value'",
"=>",
"$",
"value",
",",
"'selected'",
"=>",
"$",
"currentdate",
"[",
"$",
"userdatetype",
"]",
"==",
"$",
"value",
"]",
";",
"}",
",",
"array_keys",
"(",
"$",
"timeunits",
")",
")",
",",
"]",
";",
"unset",
"(",
"$",
"attributes",
"[",
"'id'",
"]",
")",
";",
"unset",
"(",
"$",
"attributes",
"[",
"'name'",
"]",
")",
";",
"$",
"data",
"->",
"attributes",
"=",
"array_map",
"(",
"function",
"(",
"$",
"name",
")",
"use",
"(",
"$",
"attributes",
")",
"{",
"return",
"[",
"'name'",
"=>",
"$",
"name",
",",
"'value'",
"=>",
"$",
"attributes",
"[",
"$",
"name",
"]",
"]",
";",
"}",
",",
"array_keys",
"(",
"$",
"attributes",
")",
")",
";",
"return",
"$",
"OUTPUT",
"->",
"render_from_template",
"(",
"'core/select_time'",
",",
"$",
"data",
")",
";",
"}"
] |
This is a shortcut for making an hour selector menu.
@param string $type The type of selector (years, months, days, hours, minutes)
@param string $name fieldname
@param int $currenttime A default timestamp in GMT
@param int $step minute spacing
@param array $attributes - html select element attributes
@return HTML fragment
|
[
"This",
"is",
"a",
"shortcut",
"for",
"making",
"an",
"hour",
"selector",
"menu",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L1946-L2013
|
219,801
|
moodle/moodle
|
lib/outputcomponents.php
|
html_writer.alist
|
public static function alist(array $items, array $attributes = null, $tag = 'ul') {
$output = html_writer::start_tag($tag, $attributes)."\n";
foreach ($items as $item) {
$output .= html_writer::tag('li', $item)."\n";
}
$output .= html_writer::end_tag($tag);
return $output;
}
|
php
|
public static function alist(array $items, array $attributes = null, $tag = 'ul') {
$output = html_writer::start_tag($tag, $attributes)."\n";
foreach ($items as $item) {
$output .= html_writer::tag('li', $item)."\n";
}
$output .= html_writer::end_tag($tag);
return $output;
}
|
[
"public",
"static",
"function",
"alist",
"(",
"array",
"$",
"items",
",",
"array",
"$",
"attributes",
"=",
"null",
",",
"$",
"tag",
"=",
"'ul'",
")",
"{",
"$",
"output",
"=",
"html_writer",
"::",
"start_tag",
"(",
"$",
"tag",
",",
"$",
"attributes",
")",
".",
"\"\\n\"",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"$",
"output",
".=",
"html_writer",
"::",
"tag",
"(",
"'li'",
",",
"$",
"item",
")",
".",
"\"\\n\"",
";",
"}",
"$",
"output",
".=",
"html_writer",
"::",
"end_tag",
"(",
"$",
"tag",
")",
";",
"return",
"$",
"output",
";",
"}"
] |
Shortcut for quick making of lists
Note: 'list' is a reserved keyword ;-)
@param array $items
@param array $attributes
@param string $tag ul or ol
@return string
|
[
"Shortcut",
"for",
"quick",
"making",
"of",
"lists"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L2025-L2032
|
219,802
|
moodle/moodle
|
lib/outputcomponents.php
|
html_writer.input_hidden_params
|
public static function input_hidden_params(moodle_url $url, array $exclude = null) {
$exclude = (array)$exclude;
$params = $url->params();
foreach ($exclude as $key) {
unset($params[$key]);
}
$output = '';
foreach ($params as $key => $value) {
$attributes = array('type'=>'hidden', 'name'=>$key, 'value'=>$value);
$output .= self::empty_tag('input', $attributes)."\n";
}
return $output;
}
|
php
|
public static function input_hidden_params(moodle_url $url, array $exclude = null) {
$exclude = (array)$exclude;
$params = $url->params();
foreach ($exclude as $key) {
unset($params[$key]);
}
$output = '';
foreach ($params as $key => $value) {
$attributes = array('type'=>'hidden', 'name'=>$key, 'value'=>$value);
$output .= self::empty_tag('input', $attributes)."\n";
}
return $output;
}
|
[
"public",
"static",
"function",
"input_hidden_params",
"(",
"moodle_url",
"$",
"url",
",",
"array",
"$",
"exclude",
"=",
"null",
")",
"{",
"$",
"exclude",
"=",
"(",
"array",
")",
"$",
"exclude",
";",
"$",
"params",
"=",
"$",
"url",
"->",
"params",
"(",
")",
";",
"foreach",
"(",
"$",
"exclude",
"as",
"$",
"key",
")",
"{",
"unset",
"(",
"$",
"params",
"[",
"$",
"key",
"]",
")",
";",
"}",
"$",
"output",
"=",
"''",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"attributes",
"=",
"array",
"(",
"'type'",
"=>",
"'hidden'",
",",
"'name'",
"=>",
"$",
"key",
",",
"'value'",
"=>",
"$",
"value",
")",
";",
"$",
"output",
".=",
"self",
"::",
"empty_tag",
"(",
"'input'",
",",
"$",
"attributes",
")",
".",
"\"\\n\"",
";",
"}",
"return",
"$",
"output",
";",
"}"
] |
Returns hidden input fields created from url parameters.
@param moodle_url $url
@param array $exclude list of excluded parameters
@return string HTML fragment
|
[
"Returns",
"hidden",
"input",
"fields",
"created",
"from",
"url",
"parameters",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L2041-L2054
|
219,803
|
moodle/moodle
|
lib/outputcomponents.php
|
html_writer.script
|
public static function script($jscode, $url=null) {
if ($jscode) {
$attributes = array('type'=>'text/javascript');
return self::tag('script', "\n//<![CDATA[\n$jscode\n//]]>\n", $attributes) . "\n";
} else if ($url) {
$attributes = array('type'=>'text/javascript', 'src'=>$url);
return self::tag('script', '', $attributes) . "\n";
} else {
return '';
}
}
|
php
|
public static function script($jscode, $url=null) {
if ($jscode) {
$attributes = array('type'=>'text/javascript');
return self::tag('script', "\n//<![CDATA[\n$jscode\n//]]>\n", $attributes) . "\n";
} else if ($url) {
$attributes = array('type'=>'text/javascript', 'src'=>$url);
return self::tag('script', '', $attributes) . "\n";
} else {
return '';
}
}
|
[
"public",
"static",
"function",
"script",
"(",
"$",
"jscode",
",",
"$",
"url",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"jscode",
")",
"{",
"$",
"attributes",
"=",
"array",
"(",
"'type'",
"=>",
"'text/javascript'",
")",
";",
"return",
"self",
"::",
"tag",
"(",
"'script'",
",",
"\"\\n//<![CDATA[\\n$jscode\\n//]]>\\n\"",
",",
"$",
"attributes",
")",
".",
"\"\\n\"",
";",
"}",
"else",
"if",
"(",
"$",
"url",
")",
"{",
"$",
"attributes",
"=",
"array",
"(",
"'type'",
"=>",
"'text/javascript'",
",",
"'src'",
"=>",
"$",
"url",
")",
";",
"return",
"self",
"::",
"tag",
"(",
"'script'",
",",
"''",
",",
"$",
"attributes",
")",
".",
"\"\\n\"",
";",
"}",
"else",
"{",
"return",
"''",
";",
"}",
"}"
] |
Generate a script tag containing the the specified code.
@param string $jscode the JavaScript code
@param moodle_url|string $url optional url of the external script, $code ignored if specified
@return string HTML, the code wrapped in <script> tags.
|
[
"Generate",
"a",
"script",
"tag",
"containing",
"the",
"the",
"specified",
"code",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L2063-L2075
|
219,804
|
moodle/moodle
|
lib/outputcomponents.php
|
html_writer.label
|
public static function label($text, $for, $colonize = true, array $attributes=array()) {
if (!is_null($for)) {
$attributes = array_merge($attributes, array('for' => $for));
}
$text = trim($text);
$label = self::tag('label', $text, $attributes);
// TODO MDL-12192 $colonize disabled for now yet
// if (!empty($text) and $colonize) {
// // the $text may end with the colon already, though it is bad string definition style
// $colon = get_string('labelsep', 'langconfig');
// if (!empty($colon)) {
// $trimmed = trim($colon);
// if ((substr($text, -strlen($trimmed)) == $trimmed) or (substr($text, -1) == ':')) {
// //debugging('The label text should not end with colon or other label separator,
// // please fix the string definition.', DEBUG_DEVELOPER);
// } else {
// $label .= $colon;
// }
// }
// }
return $label;
}
|
php
|
public static function label($text, $for, $colonize = true, array $attributes=array()) {
if (!is_null($for)) {
$attributes = array_merge($attributes, array('for' => $for));
}
$text = trim($text);
$label = self::tag('label', $text, $attributes);
// TODO MDL-12192 $colonize disabled for now yet
// if (!empty($text) and $colonize) {
// // the $text may end with the colon already, though it is bad string definition style
// $colon = get_string('labelsep', 'langconfig');
// if (!empty($colon)) {
// $trimmed = trim($colon);
// if ((substr($text, -strlen($trimmed)) == $trimmed) or (substr($text, -1) == ':')) {
// //debugging('The label text should not end with colon or other label separator,
// // please fix the string definition.', DEBUG_DEVELOPER);
// } else {
// $label .= $colon;
// }
// }
// }
return $label;
}
|
[
"public",
"static",
"function",
"label",
"(",
"$",
"text",
",",
"$",
"for",
",",
"$",
"colonize",
"=",
"true",
",",
"array",
"$",
"attributes",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"for",
")",
")",
"{",
"$",
"attributes",
"=",
"array_merge",
"(",
"$",
"attributes",
",",
"array",
"(",
"'for'",
"=>",
"$",
"for",
")",
")",
";",
"}",
"$",
"text",
"=",
"trim",
"(",
"$",
"text",
")",
";",
"$",
"label",
"=",
"self",
"::",
"tag",
"(",
"'label'",
",",
"$",
"text",
",",
"$",
"attributes",
")",
";",
"// TODO MDL-12192 $colonize disabled for now yet",
"// if (!empty($text) and $colonize) {",
"// // the $text may end with the colon already, though it is bad string definition style",
"// $colon = get_string('labelsep', 'langconfig');",
"// if (!empty($colon)) {",
"// $trimmed = trim($colon);",
"// if ((substr($text, -strlen($trimmed)) == $trimmed) or (substr($text, -1) == ':')) {",
"// //debugging('The label text should not end with colon or other label separator,",
"// // please fix the string definition.', DEBUG_DEVELOPER);",
"// } else {",
"// $label .= $colon;",
"// }",
"// }",
"// }",
"return",
"$",
"label",
";",
"}"
] |
Renders form element label
By default, the label is suffixed with a label separator defined in the
current language pack (colon by default in the English lang pack).
Adding the colon can be explicitly disabled if needed. Label separators
are put outside the label tag itself so they are not read by
screenreaders (accessibility).
Parameter $for explicitly associates the label with a form control. When
set, the value of this attribute must be the same as the value of
the id attribute of the form control in the same document. When null,
the label being defined is associated with the control inside the label
element.
@param string $text content of the label tag
@param string|null $for id of the element this label is associated with, null for no association
@param bool $colonize add label separator (colon) to the label text, if it is not there yet
@param array $attributes to be inserted in the tab, for example array('accesskey' => 'a')
@return string HTML of the label element
|
[
"Renders",
"form",
"element",
"label"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L2342-L2365
|
219,805
|
moodle/moodle
|
lib/outputcomponents.php
|
html_writer.add_class
|
private static function add_class($class = '', array $attributes = null) {
if ($class !== '') {
$classattribute = array('class' => $class);
if ($attributes) {
if (array_key_exists('class', $attributes)) {
$attributes['class'] = trim($attributes['class'] . ' ' . $class);
} else {
$attributes = $classattribute + $attributes;
}
} else {
$attributes = $classattribute;
}
}
return $attributes;
}
|
php
|
private static function add_class($class = '', array $attributes = null) {
if ($class !== '') {
$classattribute = array('class' => $class);
if ($attributes) {
if (array_key_exists('class', $attributes)) {
$attributes['class'] = trim($attributes['class'] . ' ' . $class);
} else {
$attributes = $classattribute + $attributes;
}
} else {
$attributes = $classattribute;
}
}
return $attributes;
}
|
[
"private",
"static",
"function",
"add_class",
"(",
"$",
"class",
"=",
"''",
",",
"array",
"$",
"attributes",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"class",
"!==",
"''",
")",
"{",
"$",
"classattribute",
"=",
"array",
"(",
"'class'",
"=>",
"$",
"class",
")",
";",
"if",
"(",
"$",
"attributes",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"'class'",
",",
"$",
"attributes",
")",
")",
"{",
"$",
"attributes",
"[",
"'class'",
"]",
"=",
"trim",
"(",
"$",
"attributes",
"[",
"'class'",
"]",
".",
"' '",
".",
"$",
"class",
")",
";",
"}",
"else",
"{",
"$",
"attributes",
"=",
"$",
"classattribute",
"+",
"$",
"attributes",
";",
"}",
"}",
"else",
"{",
"$",
"attributes",
"=",
"$",
"classattribute",
";",
"}",
"}",
"return",
"$",
"attributes",
";",
"}"
] |
Combines a class parameter with other attributes. Aids in code reduction
because the class parameter is very frequently used.
If the class attribute is specified both in the attributes and in the
class parameter, the two values are combined with a space between.
@param string $class Optional CSS class (or classes as space-separated list)
@param array $attributes Optional other attributes as array
@return array Attributes (or null if still none)
|
[
"Combines",
"a",
"class",
"parameter",
"with",
"other",
"attributes",
".",
"Aids",
"in",
"code",
"reduction",
"because",
"the",
"class",
"parameter",
"is",
"very",
"frequently",
"used",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L2378-L2392
|
219,806
|
moodle/moodle
|
lib/outputcomponents.php
|
js_writer.function_call
|
public static function function_call($function, array $arguments = null, $delay=0) {
if ($arguments) {
$arguments = array_map('json_encode', convert_to_array($arguments));
$arguments = implode(', ', $arguments);
} else {
$arguments = '';
}
$js = "$function($arguments);";
if ($delay) {
$delay = $delay * 1000; // in miliseconds
$js = "setTimeout(function() { $js }, $delay);";
}
return $js . "\n";
}
|
php
|
public static function function_call($function, array $arguments = null, $delay=0) {
if ($arguments) {
$arguments = array_map('json_encode', convert_to_array($arguments));
$arguments = implode(', ', $arguments);
} else {
$arguments = '';
}
$js = "$function($arguments);";
if ($delay) {
$delay = $delay * 1000; // in miliseconds
$js = "setTimeout(function() { $js }, $delay);";
}
return $js . "\n";
}
|
[
"public",
"static",
"function",
"function_call",
"(",
"$",
"function",
",",
"array",
"$",
"arguments",
"=",
"null",
",",
"$",
"delay",
"=",
"0",
")",
"{",
"if",
"(",
"$",
"arguments",
")",
"{",
"$",
"arguments",
"=",
"array_map",
"(",
"'json_encode'",
",",
"convert_to_array",
"(",
"$",
"arguments",
")",
")",
";",
"$",
"arguments",
"=",
"implode",
"(",
"', '",
",",
"$",
"arguments",
")",
";",
"}",
"else",
"{",
"$",
"arguments",
"=",
"''",
";",
"}",
"$",
"js",
"=",
"\"$function($arguments);\"",
";",
"if",
"(",
"$",
"delay",
")",
"{",
"$",
"delay",
"=",
"$",
"delay",
"*",
"1000",
";",
"// in miliseconds",
"$",
"js",
"=",
"\"setTimeout(function() { $js }, $delay);\"",
";",
"}",
"return",
"$",
"js",
".",
"\"\\n\"",
";",
"}"
] |
Returns javascript code calling the function
@param string $function function name, can be complex like Y.Event.purgeElement
@param array $arguments parameters
@param int $delay execution delay in seconds
@return string JS code fragment
|
[
"Returns",
"javascript",
"code",
"calling",
"the",
"function"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L2478-L2492
|
219,807
|
moodle/moodle
|
lib/outputcomponents.php
|
js_writer.function_call_with_Y
|
public static function function_call_with_Y($function, array $extraarguments = null) {
if ($extraarguments) {
$extraarguments = array_map('json_encode', convert_to_array($extraarguments));
$arguments = 'Y, ' . implode(', ', $extraarguments);
} else {
$arguments = 'Y';
}
return "$function($arguments);\n";
}
|
php
|
public static function function_call_with_Y($function, array $extraarguments = null) {
if ($extraarguments) {
$extraarguments = array_map('json_encode', convert_to_array($extraarguments));
$arguments = 'Y, ' . implode(', ', $extraarguments);
} else {
$arguments = 'Y';
}
return "$function($arguments);\n";
}
|
[
"public",
"static",
"function",
"function_call_with_Y",
"(",
"$",
"function",
",",
"array",
"$",
"extraarguments",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"extraarguments",
")",
"{",
"$",
"extraarguments",
"=",
"array_map",
"(",
"'json_encode'",
",",
"convert_to_array",
"(",
"$",
"extraarguments",
")",
")",
";",
"$",
"arguments",
"=",
"'Y, '",
".",
"implode",
"(",
"', '",
",",
"$",
"extraarguments",
")",
";",
"}",
"else",
"{",
"$",
"arguments",
"=",
"'Y'",
";",
"}",
"return",
"\"$function($arguments);\\n\"",
";",
"}"
] |
Special function which adds Y as first argument of function call.
@param string $function The function to call
@param array $extraarguments Any arguments to pass to it
@return string Some JS code
|
[
"Special",
"function",
"which",
"adds",
"Y",
"as",
"first",
"argument",
"of",
"function",
"call",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L2501-L2509
|
219,808
|
moodle/moodle
|
lib/outputcomponents.php
|
js_writer.object_init
|
public static function object_init($var, $class, array $arguments = null, array $requirements = null, $delay=0) {
if (is_array($arguments)) {
$arguments = array_map('json_encode', convert_to_array($arguments));
$arguments = implode(', ', $arguments);
}
if ($var === null) {
$js = "new $class(Y, $arguments);";
} else if (strpos($var, '.')!==false) {
$js = "$var = new $class(Y, $arguments);";
} else {
$js = "var $var = new $class(Y, $arguments);";
}
if ($delay) {
$delay = $delay * 1000; // in miliseconds
$js = "setTimeout(function() { $js }, $delay);";
}
if (count($requirements) > 0) {
$requirements = implode("', '", $requirements);
$js = "Y.use('$requirements', function(Y){ $js });";
}
return $js."\n";
}
|
php
|
public static function object_init($var, $class, array $arguments = null, array $requirements = null, $delay=0) {
if (is_array($arguments)) {
$arguments = array_map('json_encode', convert_to_array($arguments));
$arguments = implode(', ', $arguments);
}
if ($var === null) {
$js = "new $class(Y, $arguments);";
} else if (strpos($var, '.')!==false) {
$js = "$var = new $class(Y, $arguments);";
} else {
$js = "var $var = new $class(Y, $arguments);";
}
if ($delay) {
$delay = $delay * 1000; // in miliseconds
$js = "setTimeout(function() { $js }, $delay);";
}
if (count($requirements) > 0) {
$requirements = implode("', '", $requirements);
$js = "Y.use('$requirements', function(Y){ $js });";
}
return $js."\n";
}
|
[
"public",
"static",
"function",
"object_init",
"(",
"$",
"var",
",",
"$",
"class",
",",
"array",
"$",
"arguments",
"=",
"null",
",",
"array",
"$",
"requirements",
"=",
"null",
",",
"$",
"delay",
"=",
"0",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"arguments",
")",
")",
"{",
"$",
"arguments",
"=",
"array_map",
"(",
"'json_encode'",
",",
"convert_to_array",
"(",
"$",
"arguments",
")",
")",
";",
"$",
"arguments",
"=",
"implode",
"(",
"', '",
",",
"$",
"arguments",
")",
";",
"}",
"if",
"(",
"$",
"var",
"===",
"null",
")",
"{",
"$",
"js",
"=",
"\"new $class(Y, $arguments);\"",
";",
"}",
"else",
"if",
"(",
"strpos",
"(",
"$",
"var",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"$",
"js",
"=",
"\"$var = new $class(Y, $arguments);\"",
";",
"}",
"else",
"{",
"$",
"js",
"=",
"\"var $var = new $class(Y, $arguments);\"",
";",
"}",
"if",
"(",
"$",
"delay",
")",
"{",
"$",
"delay",
"=",
"$",
"delay",
"*",
"1000",
";",
"// in miliseconds",
"$",
"js",
"=",
"\"setTimeout(function() { $js }, $delay);\"",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"requirements",
")",
">",
"0",
")",
"{",
"$",
"requirements",
"=",
"implode",
"(",
"\"', '\"",
",",
"$",
"requirements",
")",
";",
"$",
"js",
"=",
"\"Y.use('$requirements', function(Y){ $js });\"",
";",
"}",
"return",
"$",
"js",
".",
"\"\\n\"",
";",
"}"
] |
Returns JavaScript code to initialise a new object
@param string $var If it is null then no var is assigned the new object.
@param string $class The class to initialise an object for.
@param array $arguments An array of args to pass to the init method.
@param array $requirements Any modules required for this class.
@param int $delay The delay before initialisation. 0 = no delay.
@return string Some JS code
|
[
"Returns",
"JavaScript",
"code",
"to",
"initialise",
"a",
"new",
"object"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L2521-L2545
|
219,809
|
moodle/moodle
|
lib/outputcomponents.php
|
js_writer.set_variable
|
public static function set_variable($name, $value, $usevar = true) {
$output = '';
if ($usevar) {
if (strpos($name, '.')) {
$output .= '';
} else {
$output .= 'var ';
}
}
$output .= "$name = ".json_encode($value).";";
return $output;
}
|
php
|
public static function set_variable($name, $value, $usevar = true) {
$output = '';
if ($usevar) {
if (strpos($name, '.')) {
$output .= '';
} else {
$output .= 'var ';
}
}
$output .= "$name = ".json_encode($value).";";
return $output;
}
|
[
"public",
"static",
"function",
"set_variable",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"usevar",
"=",
"true",
")",
"{",
"$",
"output",
"=",
"''",
";",
"if",
"(",
"$",
"usevar",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"name",
",",
"'.'",
")",
")",
"{",
"$",
"output",
".=",
"''",
";",
"}",
"else",
"{",
"$",
"output",
".=",
"'var '",
";",
"}",
"}",
"$",
"output",
".=",
"\"$name = \"",
".",
"json_encode",
"(",
"$",
"value",
")",
".",
"\";\"",
";",
"return",
"$",
"output",
";",
"}"
] |
Returns code setting value to variable
@param string $name
@param mixed $value json serialised value
@param bool $usevar add var definition, ignored for nested properties
@return string JS code fragment
|
[
"Returns",
"code",
"setting",
"value",
"to",
"variable"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L2555-L2569
|
219,810
|
moodle/moodle
|
lib/outputcomponents.php
|
js_writer.event_handler
|
public static function event_handler($selector, $event, $function, array $arguments = null) {
$selector = json_encode($selector);
$output = "Y.on('$event', $function, $selector, null";
if (!empty($arguments)) {
$output .= ', ' . json_encode($arguments);
}
return $output . ");\n";
}
|
php
|
public static function event_handler($selector, $event, $function, array $arguments = null) {
$selector = json_encode($selector);
$output = "Y.on('$event', $function, $selector, null";
if (!empty($arguments)) {
$output .= ', ' . json_encode($arguments);
}
return $output . ");\n";
}
|
[
"public",
"static",
"function",
"event_handler",
"(",
"$",
"selector",
",",
"$",
"event",
",",
"$",
"function",
",",
"array",
"$",
"arguments",
"=",
"null",
")",
"{",
"$",
"selector",
"=",
"json_encode",
"(",
"$",
"selector",
")",
";",
"$",
"output",
"=",
"\"Y.on('$event', $function, $selector, null\"",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"arguments",
")",
")",
"{",
"$",
"output",
".=",
"', '",
".",
"json_encode",
"(",
"$",
"arguments",
")",
";",
"}",
"return",
"$",
"output",
".",
"\");\\n\"",
";",
"}"
] |
Writes event handler attaching code
@param array|string $selector standard YUI selector for elements, may be
array or string, element id is in the form "#idvalue"
@param string $event A valid DOM event (click, mousedown, change etc.)
@param string $function The name of the function to call
@param array $arguments An optional array of argument parameters to pass to the function
@return string JS code fragment
|
[
"Writes",
"event",
"handler",
"attaching",
"code"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L2581-L2588
|
219,811
|
moodle/moodle
|
lib/outputcomponents.php
|
custom_menu_item.add
|
public function add($text, moodle_url $url = null, $title = null, $sort = null) {
$key = count($this->children);
if (empty($sort)) {
$sort = $this->lastsort + 1;
}
$this->children[$key] = new custom_menu_item($text, $url, $title, $sort, $this);
$this->lastsort = (int)$sort;
return $this->children[$key];
}
|
php
|
public function add($text, moodle_url $url = null, $title = null, $sort = null) {
$key = count($this->children);
if (empty($sort)) {
$sort = $this->lastsort + 1;
}
$this->children[$key] = new custom_menu_item($text, $url, $title, $sort, $this);
$this->lastsort = (int)$sort;
return $this->children[$key];
}
|
[
"public",
"function",
"add",
"(",
"$",
"text",
",",
"moodle_url",
"$",
"url",
"=",
"null",
",",
"$",
"title",
"=",
"null",
",",
"$",
"sort",
"=",
"null",
")",
"{",
"$",
"key",
"=",
"count",
"(",
"$",
"this",
"->",
"children",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"sort",
")",
")",
"{",
"$",
"sort",
"=",
"$",
"this",
"->",
"lastsort",
"+",
"1",
";",
"}",
"$",
"this",
"->",
"children",
"[",
"$",
"key",
"]",
"=",
"new",
"custom_menu_item",
"(",
"$",
"text",
",",
"$",
"url",
",",
"$",
"title",
",",
"$",
"sort",
",",
"$",
"this",
")",
";",
"$",
"this",
"->",
"lastsort",
"=",
"(",
"int",
")",
"$",
"sort",
";",
"return",
"$",
"this",
"->",
"children",
"[",
"$",
"key",
"]",
";",
"}"
] |
Adds a custom menu item as a child of this node given its properties.
@param string $text
@param moodle_url $url
@param string $title
@param int $sort
@return custom_menu_item
|
[
"Adds",
"a",
"custom",
"menu",
"item",
"as",
"a",
"child",
"of",
"this",
"node",
"given",
"its",
"properties",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L3485-L3493
|
219,812
|
moodle/moodle
|
lib/outputcomponents.php
|
custom_menu_item.remove_child
|
public function remove_child(custom_menu_item $menuitem) {
$removed = false;
if (($key = array_search($menuitem, $this->children)) !== false) {
unset($this->children[$key]);
$this->children = array_values($this->children);
$removed = true;
} else {
foreach ($this->children as $child) {
if ($removed = $child->remove_child($menuitem)) {
break;
}
}
}
return $removed;
}
|
php
|
public function remove_child(custom_menu_item $menuitem) {
$removed = false;
if (($key = array_search($menuitem, $this->children)) !== false) {
unset($this->children[$key]);
$this->children = array_values($this->children);
$removed = true;
} else {
foreach ($this->children as $child) {
if ($removed = $child->remove_child($menuitem)) {
break;
}
}
}
return $removed;
}
|
[
"public",
"function",
"remove_child",
"(",
"custom_menu_item",
"$",
"menuitem",
")",
"{",
"$",
"removed",
"=",
"false",
";",
"if",
"(",
"(",
"$",
"key",
"=",
"array_search",
"(",
"$",
"menuitem",
",",
"$",
"this",
"->",
"children",
")",
")",
"!==",
"false",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"children",
"[",
"$",
"key",
"]",
")",
";",
"$",
"this",
"->",
"children",
"=",
"array_values",
"(",
"$",
"this",
"->",
"children",
")",
";",
"$",
"removed",
"=",
"true",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"this",
"->",
"children",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"$",
"removed",
"=",
"$",
"child",
"->",
"remove_child",
"(",
"$",
"menuitem",
")",
")",
"{",
"break",
";",
"}",
"}",
"}",
"return",
"$",
"removed",
";",
"}"
] |
Removes a custom menu item that is a child or descendant to the current menu.
Returns true if child was found and removed.
@param custom_menu_item $menuitem
@return bool
|
[
"Removes",
"a",
"custom",
"menu",
"item",
"that",
"is",
"a",
"child",
"or",
"descendant",
"to",
"the",
"current",
"menu",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L3503-L3517
|
219,813
|
moodle/moodle
|
lib/outputcomponents.php
|
custom_menu.convert_text_to_menu_nodes
|
public static function convert_text_to_menu_nodes($text, $language = null) {
$root = new custom_menu();
$lastitem = $root;
$lastdepth = 0;
$hiddenitems = array();
$lines = explode("\n", $text);
foreach ($lines as $linenumber => $line) {
$line = trim($line);
if (strlen($line) == 0) {
continue;
}
// Parse item settings.
$itemtext = null;
$itemurl = null;
$itemtitle = null;
$itemvisible = true;
$settings = explode('|', $line);
foreach ($settings as $i => $setting) {
$setting = trim($setting);
if (!empty($setting)) {
switch ($i) {
case 0:
$itemtext = ltrim($setting, '-');
$itemtitle = $itemtext;
break;
case 1:
try {
$itemurl = new moodle_url($setting);
} catch (moodle_exception $exception) {
// We're not actually worried about this, we don't want to mess up the display
// just for a wrongly entered URL.
$itemurl = null;
}
break;
case 2:
$itemtitle = $setting;
break;
case 3:
if (!empty($language)) {
$itemlanguages = array_map('trim', explode(',', $setting));
$itemvisible &= in_array($language, $itemlanguages);
}
break;
}
}
}
// Get depth of new item.
preg_match('/^(\-*)/', $line, $match);
$itemdepth = strlen($match[1]) + 1;
// Find parent item for new item.
while (($lastdepth - $itemdepth) >= 0) {
$lastitem = $lastitem->get_parent();
$lastdepth--;
}
$lastitem = $lastitem->add($itemtext, $itemurl, $itemtitle, $linenumber + 1);
$lastdepth++;
if (!$itemvisible) {
$hiddenitems[] = $lastitem;
}
}
foreach ($hiddenitems as $item) {
$item->parent->remove_child($item);
}
return $root->get_children();
}
|
php
|
public static function convert_text_to_menu_nodes($text, $language = null) {
$root = new custom_menu();
$lastitem = $root;
$lastdepth = 0;
$hiddenitems = array();
$lines = explode("\n", $text);
foreach ($lines as $linenumber => $line) {
$line = trim($line);
if (strlen($line) == 0) {
continue;
}
// Parse item settings.
$itemtext = null;
$itemurl = null;
$itemtitle = null;
$itemvisible = true;
$settings = explode('|', $line);
foreach ($settings as $i => $setting) {
$setting = trim($setting);
if (!empty($setting)) {
switch ($i) {
case 0:
$itemtext = ltrim($setting, '-');
$itemtitle = $itemtext;
break;
case 1:
try {
$itemurl = new moodle_url($setting);
} catch (moodle_exception $exception) {
// We're not actually worried about this, we don't want to mess up the display
// just for a wrongly entered URL.
$itemurl = null;
}
break;
case 2:
$itemtitle = $setting;
break;
case 3:
if (!empty($language)) {
$itemlanguages = array_map('trim', explode(',', $setting));
$itemvisible &= in_array($language, $itemlanguages);
}
break;
}
}
}
// Get depth of new item.
preg_match('/^(\-*)/', $line, $match);
$itemdepth = strlen($match[1]) + 1;
// Find parent item for new item.
while (($lastdepth - $itemdepth) >= 0) {
$lastitem = $lastitem->get_parent();
$lastdepth--;
}
$lastitem = $lastitem->add($itemtext, $itemurl, $itemtitle, $linenumber + 1);
$lastdepth++;
if (!$itemvisible) {
$hiddenitems[] = $lastitem;
}
}
foreach ($hiddenitems as $item) {
$item->parent->remove_child($item);
}
return $root->get_children();
}
|
[
"public",
"static",
"function",
"convert_text_to_menu_nodes",
"(",
"$",
"text",
",",
"$",
"language",
"=",
"null",
")",
"{",
"$",
"root",
"=",
"new",
"custom_menu",
"(",
")",
";",
"$",
"lastitem",
"=",
"$",
"root",
";",
"$",
"lastdepth",
"=",
"0",
";",
"$",
"hiddenitems",
"=",
"array",
"(",
")",
";",
"$",
"lines",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"text",
")",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"linenumber",
"=>",
"$",
"line",
")",
"{",
"$",
"line",
"=",
"trim",
"(",
"$",
"line",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"line",
")",
"==",
"0",
")",
"{",
"continue",
";",
"}",
"// Parse item settings.",
"$",
"itemtext",
"=",
"null",
";",
"$",
"itemurl",
"=",
"null",
";",
"$",
"itemtitle",
"=",
"null",
";",
"$",
"itemvisible",
"=",
"true",
";",
"$",
"settings",
"=",
"explode",
"(",
"'|'",
",",
"$",
"line",
")",
";",
"foreach",
"(",
"$",
"settings",
"as",
"$",
"i",
"=>",
"$",
"setting",
")",
"{",
"$",
"setting",
"=",
"trim",
"(",
"$",
"setting",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"setting",
")",
")",
"{",
"switch",
"(",
"$",
"i",
")",
"{",
"case",
"0",
":",
"$",
"itemtext",
"=",
"ltrim",
"(",
"$",
"setting",
",",
"'-'",
")",
";",
"$",
"itemtitle",
"=",
"$",
"itemtext",
";",
"break",
";",
"case",
"1",
":",
"try",
"{",
"$",
"itemurl",
"=",
"new",
"moodle_url",
"(",
"$",
"setting",
")",
";",
"}",
"catch",
"(",
"moodle_exception",
"$",
"exception",
")",
"{",
"// We're not actually worried about this, we don't want to mess up the display",
"// just for a wrongly entered URL.",
"$",
"itemurl",
"=",
"null",
";",
"}",
"break",
";",
"case",
"2",
":",
"$",
"itemtitle",
"=",
"$",
"setting",
";",
"break",
";",
"case",
"3",
":",
"if",
"(",
"!",
"empty",
"(",
"$",
"language",
")",
")",
"{",
"$",
"itemlanguages",
"=",
"array_map",
"(",
"'trim'",
",",
"explode",
"(",
"','",
",",
"$",
"setting",
")",
")",
";",
"$",
"itemvisible",
"&=",
"in_array",
"(",
"$",
"language",
",",
"$",
"itemlanguages",
")",
";",
"}",
"break",
";",
"}",
"}",
"}",
"// Get depth of new item.",
"preg_match",
"(",
"'/^(\\-*)/'",
",",
"$",
"line",
",",
"$",
"match",
")",
";",
"$",
"itemdepth",
"=",
"strlen",
"(",
"$",
"match",
"[",
"1",
"]",
")",
"+",
"1",
";",
"// Find parent item for new item.",
"while",
"(",
"(",
"$",
"lastdepth",
"-",
"$",
"itemdepth",
")",
">=",
"0",
")",
"{",
"$",
"lastitem",
"=",
"$",
"lastitem",
"->",
"get_parent",
"(",
")",
";",
"$",
"lastdepth",
"--",
";",
"}",
"$",
"lastitem",
"=",
"$",
"lastitem",
"->",
"add",
"(",
"$",
"itemtext",
",",
"$",
"itemurl",
",",
"$",
"itemtitle",
",",
"$",
"linenumber",
"+",
"1",
")",
";",
"$",
"lastdepth",
"++",
";",
"if",
"(",
"!",
"$",
"itemvisible",
")",
"{",
"$",
"hiddenitems",
"[",
"]",
"=",
"$",
"lastitem",
";",
"}",
"}",
"foreach",
"(",
"$",
"hiddenitems",
"as",
"$",
"item",
")",
"{",
"$",
"item",
"->",
"parent",
"->",
"remove_child",
"(",
"$",
"item",
")",
";",
"}",
"return",
"$",
"root",
"->",
"get_children",
"(",
")",
";",
"}"
] |
Converts a string into a structured array of custom_menu_items which can
then be added to a custom menu.
Structure:
text|url|title|langs
The number of hyphens at the start determines the depth of the item. The
languages are optional, comma separated list of languages the line is for.
Example structure:
First level first item|http://www.moodle.com/
-Second level first item|http://www.moodle.com/partners/
-Second level second item|http://www.moodle.com/hq/
--Third level first item|http://www.moodle.com/jobs/
-Second level third item|http://www.moodle.com/development/
First level second item|http://www.moodle.com/feedback/
First level third item
English only|http://moodle.com|English only item|en
German only|http://moodle.de|Deutsch|de,de_du,de_kids
@static
@param string $text the menu items definition
@param string $language the language code, null disables multilang support
@return array
|
[
"Converts",
"a",
"string",
"into",
"a",
"structured",
"array",
"of",
"custom_menu_items",
"which",
"can",
"then",
"be",
"added",
"to",
"a",
"custom",
"menu",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L3717-L3781
|
219,814
|
moodle/moodle
|
lib/outputcomponents.php
|
custom_menu.sort_custom_menu_items
|
public static function sort_custom_menu_items(custom_menu_item $itema, custom_menu_item $itemb) {
$itema = $itema->get_sort_order();
$itemb = $itemb->get_sort_order();
if ($itema == $itemb) {
return 0;
}
return ($itema > $itemb) ? +1 : -1;
}
|
php
|
public static function sort_custom_menu_items(custom_menu_item $itema, custom_menu_item $itemb) {
$itema = $itema->get_sort_order();
$itemb = $itemb->get_sort_order();
if ($itema == $itemb) {
return 0;
}
return ($itema > $itemb) ? +1 : -1;
}
|
[
"public",
"static",
"function",
"sort_custom_menu_items",
"(",
"custom_menu_item",
"$",
"itema",
",",
"custom_menu_item",
"$",
"itemb",
")",
"{",
"$",
"itema",
"=",
"$",
"itema",
"->",
"get_sort_order",
"(",
")",
";",
"$",
"itemb",
"=",
"$",
"itemb",
"->",
"get_sort_order",
"(",
")",
";",
"if",
"(",
"$",
"itema",
"==",
"$",
"itemb",
")",
"{",
"return",
"0",
";",
"}",
"return",
"(",
"$",
"itema",
">",
"$",
"itemb",
")",
"?",
"+",
"1",
":",
"-",
"1",
";",
"}"
] |
Sorts two custom menu items
This function is designed to be used with the usort method
usort($this->children, array('custom_menu','sort_custom_menu_items'));
@static
@param custom_menu_item $itema
@param custom_menu_item $itemb
@return int
|
[
"Sorts",
"two",
"custom",
"menu",
"items"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L3794-L3801
|
219,815
|
moodle/moodle
|
lib/outputcomponents.php
|
tabobject.set_selected
|
protected function set_selected($selected) {
if ((string)$selected === (string)$this->id) {
$this->selected = true;
// This tab is selected. No need to travel through subtree.
return true;
}
foreach ($this->subtree as $subitem) {
if ($subitem->set_selected($selected)) {
// This tab has child that is selected. Mark it as activated. No need to check other children.
$this->activated = true;
return true;
}
}
return false;
}
|
php
|
protected function set_selected($selected) {
if ((string)$selected === (string)$this->id) {
$this->selected = true;
// This tab is selected. No need to travel through subtree.
return true;
}
foreach ($this->subtree as $subitem) {
if ($subitem->set_selected($selected)) {
// This tab has child that is selected. Mark it as activated. No need to check other children.
$this->activated = true;
return true;
}
}
return false;
}
|
[
"protected",
"function",
"set_selected",
"(",
"$",
"selected",
")",
"{",
"if",
"(",
"(",
"string",
")",
"$",
"selected",
"===",
"(",
"string",
")",
"$",
"this",
"->",
"id",
")",
"{",
"$",
"this",
"->",
"selected",
"=",
"true",
";",
"// This tab is selected. No need to travel through subtree.",
"return",
"true",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"subtree",
"as",
"$",
"subitem",
")",
"{",
"if",
"(",
"$",
"subitem",
"->",
"set_selected",
"(",
"$",
"selected",
")",
")",
"{",
"// This tab has child that is selected. Mark it as activated. No need to check other children.",
"$",
"this",
"->",
"activated",
"=",
"true",
";",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Travels through tree and finds the tab to mark as selected, all parents are automatically marked as activated
@param string $selected the id of the selected tab (whatever row it's on),
if null marks all tabs as unselected
@return bool whether this tab is selected or contains selected tab in its subtree
|
[
"Travels",
"through",
"tree",
"and",
"finds",
"the",
"tab",
"to",
"mark",
"as",
"selected",
"all",
"parents",
"are",
"automatically",
"marked",
"as",
"activated"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L3856-L3870
|
219,816
|
moodle/moodle
|
lib/outputcomponents.php
|
tabobject.find
|
public function find($id) {
if ((string)$this->id === (string)$id) {
return $this;
}
foreach ($this->subtree as $tab) {
if ($obj = $tab->find($id)) {
return $obj;
}
}
return null;
}
|
php
|
public function find($id) {
if ((string)$this->id === (string)$id) {
return $this;
}
foreach ($this->subtree as $tab) {
if ($obj = $tab->find($id)) {
return $obj;
}
}
return null;
}
|
[
"public",
"function",
"find",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"(",
"string",
")",
"$",
"this",
"->",
"id",
"===",
"(",
"string",
")",
"$",
"id",
")",
"{",
"return",
"$",
"this",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"subtree",
"as",
"$",
"tab",
")",
"{",
"if",
"(",
"$",
"obj",
"=",
"$",
"tab",
"->",
"find",
"(",
"$",
"id",
")",
")",
"{",
"return",
"$",
"obj",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Travels through tree and finds a tab with specified id
@param string $id
@return tabtree|null
|
[
"Travels",
"through",
"tree",
"and",
"finds",
"a",
"tab",
"with",
"specified",
"id"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L3878-L3888
|
219,817
|
moodle/moodle
|
lib/outputcomponents.php
|
tabobject.set_level
|
protected function set_level($level) {
$this->level = $level;
foreach ($this->subtree as $tab) {
$tab->set_level($level + 1);
}
}
|
php
|
protected function set_level($level) {
$this->level = $level;
foreach ($this->subtree as $tab) {
$tab->set_level($level + 1);
}
}
|
[
"protected",
"function",
"set_level",
"(",
"$",
"level",
")",
"{",
"$",
"this",
"->",
"level",
"=",
"$",
"level",
";",
"foreach",
"(",
"$",
"this",
"->",
"subtree",
"as",
"$",
"tab",
")",
"{",
"$",
"tab",
"->",
"set_level",
"(",
"$",
"level",
"+",
"1",
")",
";",
"}",
"}"
] |
Allows to mark each tab's level in the tree before rendering.
@param int $level
|
[
"Allows",
"to",
"mark",
"each",
"tab",
"s",
"level",
"in",
"the",
"tree",
"before",
"rendering",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L3895-L3900
|
219,818
|
moodle/moodle
|
lib/outputcomponents.php
|
context_header.format_button_images
|
protected function format_button_images() {
foreach ($this->additionalbuttons as $buttontype => $button) {
$page = $button['page'];
// If no image is provided then just use the title.
if (!isset($button['image'])) {
$this->additionalbuttons[$buttontype]['formattedimage'] = $button['title'];
} else {
// Check to see if this is an internal Moodle icon.
$internalimage = $page->theme->resolve_image_location('t/' . $button['image'], 'moodle');
if ($internalimage) {
$this->additionalbuttons[$buttontype]['formattedimage'] = 't/' . $button['image'];
} else {
// Treat as an external image.
$this->additionalbuttons[$buttontype]['formattedimage'] = $button['image'];
}
}
if (isset($button['linkattributes']['class'])) {
$class = $button['linkattributes']['class'] . ' btn';
} else {
$class = 'btn';
}
// Add the bootstrap 'btn' class for formatting.
$this->additionalbuttons[$buttontype]['linkattributes'] = array_merge($button['linkattributes'],
array('class' => $class));
}
}
|
php
|
protected function format_button_images() {
foreach ($this->additionalbuttons as $buttontype => $button) {
$page = $button['page'];
// If no image is provided then just use the title.
if (!isset($button['image'])) {
$this->additionalbuttons[$buttontype]['formattedimage'] = $button['title'];
} else {
// Check to see if this is an internal Moodle icon.
$internalimage = $page->theme->resolve_image_location('t/' . $button['image'], 'moodle');
if ($internalimage) {
$this->additionalbuttons[$buttontype]['formattedimage'] = 't/' . $button['image'];
} else {
// Treat as an external image.
$this->additionalbuttons[$buttontype]['formattedimage'] = $button['image'];
}
}
if (isset($button['linkattributes']['class'])) {
$class = $button['linkattributes']['class'] . ' btn';
} else {
$class = 'btn';
}
// Add the bootstrap 'btn' class for formatting.
$this->additionalbuttons[$buttontype]['linkattributes'] = array_merge($button['linkattributes'],
array('class' => $class));
}
}
|
[
"protected",
"function",
"format_button_images",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"additionalbuttons",
"as",
"$",
"buttontype",
"=>",
"$",
"button",
")",
"{",
"$",
"page",
"=",
"$",
"button",
"[",
"'page'",
"]",
";",
"// If no image is provided then just use the title.",
"if",
"(",
"!",
"isset",
"(",
"$",
"button",
"[",
"'image'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"additionalbuttons",
"[",
"$",
"buttontype",
"]",
"[",
"'formattedimage'",
"]",
"=",
"$",
"button",
"[",
"'title'",
"]",
";",
"}",
"else",
"{",
"// Check to see if this is an internal Moodle icon.",
"$",
"internalimage",
"=",
"$",
"page",
"->",
"theme",
"->",
"resolve_image_location",
"(",
"'t/'",
".",
"$",
"button",
"[",
"'image'",
"]",
",",
"'moodle'",
")",
";",
"if",
"(",
"$",
"internalimage",
")",
"{",
"$",
"this",
"->",
"additionalbuttons",
"[",
"$",
"buttontype",
"]",
"[",
"'formattedimage'",
"]",
"=",
"'t/'",
".",
"$",
"button",
"[",
"'image'",
"]",
";",
"}",
"else",
"{",
"// Treat as an external image.",
"$",
"this",
"->",
"additionalbuttons",
"[",
"$",
"buttontype",
"]",
"[",
"'formattedimage'",
"]",
"=",
"$",
"button",
"[",
"'image'",
"]",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"button",
"[",
"'linkattributes'",
"]",
"[",
"'class'",
"]",
")",
")",
"{",
"$",
"class",
"=",
"$",
"button",
"[",
"'linkattributes'",
"]",
"[",
"'class'",
"]",
".",
"' btn'",
";",
"}",
"else",
"{",
"$",
"class",
"=",
"'btn'",
";",
"}",
"// Add the bootstrap 'btn' class for formatting.",
"$",
"this",
"->",
"additionalbuttons",
"[",
"$",
"buttontype",
"]",
"[",
"'linkattributes'",
"]",
"=",
"array_merge",
"(",
"$",
"button",
"[",
"'linkattributes'",
"]",
",",
"array",
"(",
"'class'",
"=>",
"$",
"class",
")",
")",
";",
"}",
"}"
] |
Adds an array element for a formatted image.
|
[
"Adds",
"an",
"array",
"element",
"for",
"a",
"formatted",
"image",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L3985-L4012
|
219,819
|
moodle/moodle
|
lib/outputcomponents.php
|
action_menu.initialise_js
|
public function initialise_js(moodle_page $page) {
static $initialised = false;
if (!$initialised) {
$page->requires->yui_module('moodle-core-actionmenu', 'M.core.actionmenu.init');
$initialised = true;
}
}
|
php
|
public function initialise_js(moodle_page $page) {
static $initialised = false;
if (!$initialised) {
$page->requires->yui_module('moodle-core-actionmenu', 'M.core.actionmenu.init');
$initialised = true;
}
}
|
[
"public",
"function",
"initialise_js",
"(",
"moodle_page",
"$",
"page",
")",
"{",
"static",
"$",
"initialised",
"=",
"false",
";",
"if",
"(",
"!",
"$",
"initialised",
")",
"{",
"$",
"page",
"->",
"requires",
"->",
"yui_module",
"(",
"'moodle-core-actionmenu'",
",",
"'M.core.actionmenu.init'",
")",
";",
"$",
"initialised",
"=",
"true",
";",
"}",
"}"
] |
Initialises JS required fore the action menu.
The JS is only required once as it manages all action menu's on the page.
@param moodle_page $page
|
[
"Initialises",
"JS",
"required",
"fore",
"the",
"action",
"menu",
".",
"The",
"JS",
"is",
"only",
"required",
"once",
"as",
"it",
"manages",
"all",
"action",
"menu",
"s",
"on",
"the",
"page",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L4268-L4274
|
219,820
|
moodle/moodle
|
lib/outputcomponents.php
|
action_menu.add
|
public function add($action) {
if ($action instanceof action_link) {
if ($action->primary) {
$this->add_primary_action($action);
} else {
$this->add_secondary_action($action);
}
} else if ($action instanceof pix_icon) {
$this->add_primary_action($action);
} else {
$this->add_secondary_action($action);
}
}
|
php
|
public function add($action) {
if ($action instanceof action_link) {
if ($action->primary) {
$this->add_primary_action($action);
} else {
$this->add_secondary_action($action);
}
} else if ($action instanceof pix_icon) {
$this->add_primary_action($action);
} else {
$this->add_secondary_action($action);
}
}
|
[
"public",
"function",
"add",
"(",
"$",
"action",
")",
"{",
"if",
"(",
"$",
"action",
"instanceof",
"action_link",
")",
"{",
"if",
"(",
"$",
"action",
"->",
"primary",
")",
"{",
"$",
"this",
"->",
"add_primary_action",
"(",
"$",
"action",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"add_secondary_action",
"(",
"$",
"action",
")",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"action",
"instanceof",
"pix_icon",
")",
"{",
"$",
"this",
"->",
"add_primary_action",
"(",
"$",
"action",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"add_secondary_action",
"(",
"$",
"action",
")",
";",
"}",
"}"
] |
Adds an action to this action menu.
@param action_menu_link|pix_icon|string $action
|
[
"Adds",
"an",
"action",
"to",
"this",
"action",
"menu",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L4281-L4293
|
219,821
|
moodle/moodle
|
lib/outputcomponents.php
|
action_menu.add_primary_action
|
public function add_primary_action($action) {
if ($action instanceof action_link || $action instanceof pix_icon) {
$action->attributes['role'] = 'menuitem';
if ($action instanceof action_menu_link) {
$action->actionmenu = $this;
}
}
$this->primaryactions[] = $action;
}
|
php
|
public function add_primary_action($action) {
if ($action instanceof action_link || $action instanceof pix_icon) {
$action->attributes['role'] = 'menuitem';
if ($action instanceof action_menu_link) {
$action->actionmenu = $this;
}
}
$this->primaryactions[] = $action;
}
|
[
"public",
"function",
"add_primary_action",
"(",
"$",
"action",
")",
"{",
"if",
"(",
"$",
"action",
"instanceof",
"action_link",
"||",
"$",
"action",
"instanceof",
"pix_icon",
")",
"{",
"$",
"action",
"->",
"attributes",
"[",
"'role'",
"]",
"=",
"'menuitem'",
";",
"if",
"(",
"$",
"action",
"instanceof",
"action_menu_link",
")",
"{",
"$",
"action",
"->",
"actionmenu",
"=",
"$",
"this",
";",
"}",
"}",
"$",
"this",
"->",
"primaryactions",
"[",
"]",
"=",
"$",
"action",
";",
"}"
] |
Adds a primary action to the action menu.
@param action_menu_link|action_link|pix_icon|string $action
|
[
"Adds",
"a",
"primary",
"action",
"to",
"the",
"action",
"menu",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L4300-L4308
|
219,822
|
moodle/moodle
|
lib/outputcomponents.php
|
action_menu.add_secondary_action
|
public function add_secondary_action($action) {
if ($action instanceof action_link || $action instanceof pix_icon) {
$action->attributes['role'] = 'menuitem';
if ($action instanceof action_menu_link) {
$action->actionmenu = $this;
}
}
$this->secondaryactions[] = $action;
}
|
php
|
public function add_secondary_action($action) {
if ($action instanceof action_link || $action instanceof pix_icon) {
$action->attributes['role'] = 'menuitem';
if ($action instanceof action_menu_link) {
$action->actionmenu = $this;
}
}
$this->secondaryactions[] = $action;
}
|
[
"public",
"function",
"add_secondary_action",
"(",
"$",
"action",
")",
"{",
"if",
"(",
"$",
"action",
"instanceof",
"action_link",
"||",
"$",
"action",
"instanceof",
"pix_icon",
")",
"{",
"$",
"action",
"->",
"attributes",
"[",
"'role'",
"]",
"=",
"'menuitem'",
";",
"if",
"(",
"$",
"action",
"instanceof",
"action_menu_link",
")",
"{",
"$",
"action",
"->",
"actionmenu",
"=",
"$",
"this",
";",
"}",
"}",
"$",
"this",
"->",
"secondaryactions",
"[",
"]",
"=",
"$",
"action",
";",
"}"
] |
Adds a secondary action to the action menu.
@param action_link|pix_icon|string $action
|
[
"Adds",
"a",
"secondary",
"action",
"to",
"the",
"action",
"menu",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L4315-L4323
|
219,823
|
moodle/moodle
|
lib/outputcomponents.php
|
action_menu.get_primary_actions
|
public function get_primary_actions(core_renderer $output = null) {
global $OUTPUT;
if ($output === null) {
$output = $OUTPUT;
}
$pixicon = $this->actionicon;
$linkclasses = array('toggle-display');
$title = '';
if (!empty($this->menutrigger)) {
$pixicon = '<b class="caret"></b>';
$linkclasses[] = 'textmenu';
} else {
$title = new lang_string('actionsmenu', 'moodle');
$this->actionicon = new pix_icon(
't/edit_menu',
'',
'moodle',
array('class' => 'iconsmall actionmenu', 'title' => '')
);
$pixicon = $this->actionicon;
}
if ($pixicon instanceof renderable) {
$pixicon = $output->render($pixicon);
if ($pixicon instanceof pix_icon && isset($pixicon->attributes['alt'])) {
$title = $pixicon->attributes['alt'];
}
}
$string = '';
if ($this->actiontext) {
$string = $this->actiontext;
}
$label = '';
if ($this->actionlabel) {
$label = $this->actionlabel;
} else {
$label = $title;
}
$actions = $this->primaryactions;
$attributes = array(
'class' => implode(' ', $linkclasses),
'title' => $title,
'aria-label' => $label,
'id' => 'action-menu-toggle-'.$this->instance,
'role' => 'menuitem'
);
$link = html_writer::link('#', $string . $this->menutrigger . $pixicon, $attributes);
if ($this->prioritise) {
array_unshift($actions, $link);
} else {
$actions[] = $link;
}
return $actions;
}
|
php
|
public function get_primary_actions(core_renderer $output = null) {
global $OUTPUT;
if ($output === null) {
$output = $OUTPUT;
}
$pixicon = $this->actionicon;
$linkclasses = array('toggle-display');
$title = '';
if (!empty($this->menutrigger)) {
$pixicon = '<b class="caret"></b>';
$linkclasses[] = 'textmenu';
} else {
$title = new lang_string('actionsmenu', 'moodle');
$this->actionicon = new pix_icon(
't/edit_menu',
'',
'moodle',
array('class' => 'iconsmall actionmenu', 'title' => '')
);
$pixicon = $this->actionicon;
}
if ($pixicon instanceof renderable) {
$pixicon = $output->render($pixicon);
if ($pixicon instanceof pix_icon && isset($pixicon->attributes['alt'])) {
$title = $pixicon->attributes['alt'];
}
}
$string = '';
if ($this->actiontext) {
$string = $this->actiontext;
}
$label = '';
if ($this->actionlabel) {
$label = $this->actionlabel;
} else {
$label = $title;
}
$actions = $this->primaryactions;
$attributes = array(
'class' => implode(' ', $linkclasses),
'title' => $title,
'aria-label' => $label,
'id' => 'action-menu-toggle-'.$this->instance,
'role' => 'menuitem'
);
$link = html_writer::link('#', $string . $this->menutrigger . $pixicon, $attributes);
if ($this->prioritise) {
array_unshift($actions, $link);
} else {
$actions[] = $link;
}
return $actions;
}
|
[
"public",
"function",
"get_primary_actions",
"(",
"core_renderer",
"$",
"output",
"=",
"null",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"if",
"(",
"$",
"output",
"===",
"null",
")",
"{",
"$",
"output",
"=",
"$",
"OUTPUT",
";",
"}",
"$",
"pixicon",
"=",
"$",
"this",
"->",
"actionicon",
";",
"$",
"linkclasses",
"=",
"array",
"(",
"'toggle-display'",
")",
";",
"$",
"title",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"menutrigger",
")",
")",
"{",
"$",
"pixicon",
"=",
"'<b class=\"caret\"></b>'",
";",
"$",
"linkclasses",
"[",
"]",
"=",
"'textmenu'",
";",
"}",
"else",
"{",
"$",
"title",
"=",
"new",
"lang_string",
"(",
"'actionsmenu'",
",",
"'moodle'",
")",
";",
"$",
"this",
"->",
"actionicon",
"=",
"new",
"pix_icon",
"(",
"'t/edit_menu'",
",",
"''",
",",
"'moodle'",
",",
"array",
"(",
"'class'",
"=>",
"'iconsmall actionmenu'",
",",
"'title'",
"=>",
"''",
")",
")",
";",
"$",
"pixicon",
"=",
"$",
"this",
"->",
"actionicon",
";",
"}",
"if",
"(",
"$",
"pixicon",
"instanceof",
"renderable",
")",
"{",
"$",
"pixicon",
"=",
"$",
"output",
"->",
"render",
"(",
"$",
"pixicon",
")",
";",
"if",
"(",
"$",
"pixicon",
"instanceof",
"pix_icon",
"&&",
"isset",
"(",
"$",
"pixicon",
"->",
"attributes",
"[",
"'alt'",
"]",
")",
")",
"{",
"$",
"title",
"=",
"$",
"pixicon",
"->",
"attributes",
"[",
"'alt'",
"]",
";",
"}",
"}",
"$",
"string",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"actiontext",
")",
"{",
"$",
"string",
"=",
"$",
"this",
"->",
"actiontext",
";",
"}",
"$",
"label",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"actionlabel",
")",
"{",
"$",
"label",
"=",
"$",
"this",
"->",
"actionlabel",
";",
"}",
"else",
"{",
"$",
"label",
"=",
"$",
"title",
";",
"}",
"$",
"actions",
"=",
"$",
"this",
"->",
"primaryactions",
";",
"$",
"attributes",
"=",
"array",
"(",
"'class'",
"=>",
"implode",
"(",
"' '",
",",
"$",
"linkclasses",
")",
",",
"'title'",
"=>",
"$",
"title",
",",
"'aria-label'",
"=>",
"$",
"label",
",",
"'id'",
"=>",
"'action-menu-toggle-'",
".",
"$",
"this",
"->",
"instance",
",",
"'role'",
"=>",
"'menuitem'",
")",
";",
"$",
"link",
"=",
"html_writer",
"::",
"link",
"(",
"'#'",
",",
"$",
"string",
".",
"$",
"this",
"->",
"menutrigger",
".",
"$",
"pixicon",
",",
"$",
"attributes",
")",
";",
"if",
"(",
"$",
"this",
"->",
"prioritise",
")",
"{",
"array_unshift",
"(",
"$",
"actions",
",",
"$",
"link",
")",
";",
"}",
"else",
"{",
"$",
"actions",
"[",
"]",
"=",
"$",
"link",
";",
"}",
"return",
"$",
"actions",
";",
"}"
] |
Returns the primary actions ready to be rendered.
@param core_renderer $output The renderer to use for getting icons.
@return array
|
[
"Returns",
"the",
"primary",
"actions",
"ready",
"to",
"be",
"rendered",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L4331-L4384
|
219,824
|
moodle/moodle
|
lib/outputcomponents.php
|
action_menu.set_alignment
|
public function set_alignment($dialogue, $button) {
if (isset($this->attributessecondary['data-align'])) {
// We've already got one set, lets remove the old class so as to avoid troubles.
$class = $this->attributessecondary['class'];
$search = 'align-'.$this->attributessecondary['data-align'];
$this->attributessecondary['class'] = str_replace($search, '', $class);
}
$align = $this->get_align_string($dialogue) . '-' . $this->get_align_string($button);
$this->attributessecondary['data-align'] = $align;
$this->attributessecondary['class'] .= ' align-'.$align;
}
|
php
|
public function set_alignment($dialogue, $button) {
if (isset($this->attributessecondary['data-align'])) {
// We've already got one set, lets remove the old class so as to avoid troubles.
$class = $this->attributessecondary['class'];
$search = 'align-'.$this->attributessecondary['data-align'];
$this->attributessecondary['class'] = str_replace($search, '', $class);
}
$align = $this->get_align_string($dialogue) . '-' . $this->get_align_string($button);
$this->attributessecondary['data-align'] = $align;
$this->attributessecondary['class'] .= ' align-'.$align;
}
|
[
"public",
"function",
"set_alignment",
"(",
"$",
"dialogue",
",",
"$",
"button",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"attributessecondary",
"[",
"'data-align'",
"]",
")",
")",
"{",
"// We've already got one set, lets remove the old class so as to avoid troubles.",
"$",
"class",
"=",
"$",
"this",
"->",
"attributessecondary",
"[",
"'class'",
"]",
";",
"$",
"search",
"=",
"'align-'",
".",
"$",
"this",
"->",
"attributessecondary",
"[",
"'data-align'",
"]",
";",
"$",
"this",
"->",
"attributessecondary",
"[",
"'class'",
"]",
"=",
"str_replace",
"(",
"$",
"search",
",",
"''",
",",
"$",
"class",
")",
";",
"}",
"$",
"align",
"=",
"$",
"this",
"->",
"get_align_string",
"(",
"$",
"dialogue",
")",
".",
"'-'",
".",
"$",
"this",
"->",
"get_align_string",
"(",
"$",
"button",
")",
";",
"$",
"this",
"->",
"attributessecondary",
"[",
"'data-align'",
"]",
"=",
"$",
"align",
";",
"$",
"this",
"->",
"attributessecondary",
"[",
"'class'",
"]",
".=",
"' align-'",
".",
"$",
"align",
";",
"}"
] |
Sets the alignment of the dialogue in relation to button used to toggle it.
@param int $dialogue One of action_menu::TL, action_menu::TR, action_menu::BL, action_menu::BR.
@param int $button One of action_menu::TL, action_menu::TR, action_menu::BL, action_menu::BR.
|
[
"Sets",
"the",
"alignment",
"of",
"the",
"dialogue",
"in",
"relation",
"to",
"button",
"used",
"to",
"toggle",
"it",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L4408-L4418
|
219,825
|
moodle/moodle
|
lib/outputcomponents.php
|
action_menu.get_align_string
|
protected function get_align_string($align) {
switch ($align) {
case self::TL :
return 'tl';
case self::TR :
return 'tr';
case self::BL :
return 'bl';
case self::BR :
return 'br';
default :
return 'tl';
}
}
|
php
|
protected function get_align_string($align) {
switch ($align) {
case self::TL :
return 'tl';
case self::TR :
return 'tr';
case self::BL :
return 'bl';
case self::BR :
return 'br';
default :
return 'tl';
}
}
|
[
"protected",
"function",
"get_align_string",
"(",
"$",
"align",
")",
"{",
"switch",
"(",
"$",
"align",
")",
"{",
"case",
"self",
"::",
"TL",
":",
"return",
"'tl'",
";",
"case",
"self",
"::",
"TR",
":",
"return",
"'tr'",
";",
"case",
"self",
"::",
"BL",
":",
"return",
"'bl'",
";",
"case",
"self",
"::",
"BR",
":",
"return",
"'br'",
";",
"default",
":",
"return",
"'tl'",
";",
"}",
"}"
] |
Returns a string to describe the alignment.
@param int $align One of action_menu::TL, action_menu::TR, action_menu::BL, action_menu::BR.
@return string
|
[
"Returns",
"a",
"string",
"to",
"describe",
"the",
"alignment",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L4426-L4439
|
219,826
|
moodle/moodle
|
lib/outputcomponents.php
|
action_menu.set_nowrap_on_items
|
public function set_nowrap_on_items($value = true) {
$class = 'nowrap-items';
if (!empty($this->attributes['class'])) {
$pos = strpos($this->attributes['class'], $class);
if ($value === true && $pos === false) {
// The value is true and the class has not been set yet. Add it.
$this->attributes['class'] .= ' '.$class;
} else if ($value === false && $pos !== false) {
// The value is false and the class has been set. Remove it.
$this->attributes['class'] = substr($this->attributes['class'], $pos, strlen($class));
}
} else if ($value) {
// The value is true and the class has not been set yet. Add it.
$this->attributes['class'] = $class;
}
}
|
php
|
public function set_nowrap_on_items($value = true) {
$class = 'nowrap-items';
if (!empty($this->attributes['class'])) {
$pos = strpos($this->attributes['class'], $class);
if ($value === true && $pos === false) {
// The value is true and the class has not been set yet. Add it.
$this->attributes['class'] .= ' '.$class;
} else if ($value === false && $pos !== false) {
// The value is false and the class has been set. Remove it.
$this->attributes['class'] = substr($this->attributes['class'], $pos, strlen($class));
}
} else if ($value) {
// The value is true and the class has not been set yet. Add it.
$this->attributes['class'] = $class;
}
}
|
[
"public",
"function",
"set_nowrap_on_items",
"(",
"$",
"value",
"=",
"true",
")",
"{",
"$",
"class",
"=",
"'nowrap-items'",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"attributes",
"[",
"'class'",
"]",
")",
")",
"{",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"this",
"->",
"attributes",
"[",
"'class'",
"]",
",",
"$",
"class",
")",
";",
"if",
"(",
"$",
"value",
"===",
"true",
"&&",
"$",
"pos",
"===",
"false",
")",
"{",
"// The value is true and the class has not been set yet. Add it.",
"$",
"this",
"->",
"attributes",
"[",
"'class'",
"]",
".=",
"' '",
".",
"$",
"class",
";",
"}",
"else",
"if",
"(",
"$",
"value",
"===",
"false",
"&&",
"$",
"pos",
"!==",
"false",
")",
"{",
"// The value is false and the class has been set. Remove it.",
"$",
"this",
"->",
"attributes",
"[",
"'class'",
"]",
"=",
"substr",
"(",
"$",
"this",
"->",
"attributes",
"[",
"'class'",
"]",
",",
"$",
"pos",
",",
"strlen",
"(",
"$",
"class",
")",
")",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"value",
")",
"{",
"// The value is true and the class has not been set yet. Add it.",
"$",
"this",
"->",
"attributes",
"[",
"'class'",
"]",
"=",
"$",
"class",
";",
"}",
"}"
] |
Sets nowrap on items. If true menu items should not wrap lines if they are longer than the available space.
This property can be useful when the action menu is displayed within a parent element that is either floated
or relatively positioned.
In that situation the width of the menu is determined by the width of the parent element which may not be large
enough for the menu items without them wrapping.
This disables the wrapping so that the menu takes on the width of the longest item.
@param bool $value If true nowrap gets set, if false it gets removed. Defaults to true.
|
[
"Sets",
"nowrap",
"on",
"items",
".",
"If",
"true",
"menu",
"items",
"should",
"not",
"wrap",
"lines",
"if",
"they",
"are",
"longer",
"than",
"the",
"available",
"space",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L4487-L4502
|
219,827
|
moodle/moodle
|
lib/outputcomponents.php
|
progress_bar.create
|
public function create() {
global $OUTPUT;
$this->time_start = microtime(true);
if (CLI_SCRIPT) {
return; // Temporary solution for cli scripts.
}
flush();
echo $OUTPUT->render($this);
flush();
}
|
php
|
public function create() {
global $OUTPUT;
$this->time_start = microtime(true);
if (CLI_SCRIPT) {
return; // Temporary solution for cli scripts.
}
flush();
echo $OUTPUT->render($this);
flush();
}
|
[
"public",
"function",
"create",
"(",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"$",
"this",
"->",
"time_start",
"=",
"microtime",
"(",
"true",
")",
";",
"if",
"(",
"CLI_SCRIPT",
")",
"{",
"return",
";",
"// Temporary solution for cli scripts.",
"}",
"flush",
"(",
")",
";",
"echo",
"$",
"OUTPUT",
"->",
"render",
"(",
"$",
"this",
")",
";",
"flush",
"(",
")",
";",
"}"
] |
Create a new progress bar, this function will output html.
@return void Echo's output
|
[
"Create",
"a",
"new",
"progress",
"bar",
"this",
"function",
"will",
"output",
"html",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L4879-L4890
|
219,828
|
moodle/moodle
|
lib/outputcomponents.php
|
progress_bar._update
|
private function _update($percent, $msg) {
if (empty($this->time_start)) {
throw new coding_exception('You must call create() (or use the $autostart ' .
'argument to the constructor) before you try updating the progress bar.');
}
if (CLI_SCRIPT) {
return; // Temporary solution for cli scripts.
}
$estimate = $this->estimate($percent);
if ($estimate === null) {
// Always do the first and last updates.
} else if ($estimate == 0) {
// Always do the last updates.
} else if ($this->lastupdate + 20 < time()) {
// We must update otherwise browser would time out.
} else if (round($this->percent, 2) === round($percent, 2)) {
// No significant change, no need to update anything.
return;
}
$estimatemsg = null;
if (is_numeric($estimate)) {
$estimatemsg = get_string('secondsleft', 'moodle', round($estimate, 2));
}
$this->percent = round($percent, 2);
$this->lastupdate = microtime(true);
echo html_writer::script(js_writer::function_call('updateProgressBar',
array($this->html_id, $this->percent, $msg, $estimatemsg)));
flush();
}
|
php
|
private function _update($percent, $msg) {
if (empty($this->time_start)) {
throw new coding_exception('You must call create() (or use the $autostart ' .
'argument to the constructor) before you try updating the progress bar.');
}
if (CLI_SCRIPT) {
return; // Temporary solution for cli scripts.
}
$estimate = $this->estimate($percent);
if ($estimate === null) {
// Always do the first and last updates.
} else if ($estimate == 0) {
// Always do the last updates.
} else if ($this->lastupdate + 20 < time()) {
// We must update otherwise browser would time out.
} else if (round($this->percent, 2) === round($percent, 2)) {
// No significant change, no need to update anything.
return;
}
$estimatemsg = null;
if (is_numeric($estimate)) {
$estimatemsg = get_string('secondsleft', 'moodle', round($estimate, 2));
}
$this->percent = round($percent, 2);
$this->lastupdate = microtime(true);
echo html_writer::script(js_writer::function_call('updateProgressBar',
array($this->html_id, $this->percent, $msg, $estimatemsg)));
flush();
}
|
[
"private",
"function",
"_update",
"(",
"$",
"percent",
",",
"$",
"msg",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"time_start",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'You must call create() (or use the $autostart '",
".",
"'argument to the constructor) before you try updating the progress bar.'",
")",
";",
"}",
"if",
"(",
"CLI_SCRIPT",
")",
"{",
"return",
";",
"// Temporary solution for cli scripts.",
"}",
"$",
"estimate",
"=",
"$",
"this",
"->",
"estimate",
"(",
"$",
"percent",
")",
";",
"if",
"(",
"$",
"estimate",
"===",
"null",
")",
"{",
"// Always do the first and last updates.",
"}",
"else",
"if",
"(",
"$",
"estimate",
"==",
"0",
")",
"{",
"// Always do the last updates.",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"lastupdate",
"+",
"20",
"<",
"time",
"(",
")",
")",
"{",
"// We must update otherwise browser would time out.",
"}",
"else",
"if",
"(",
"round",
"(",
"$",
"this",
"->",
"percent",
",",
"2",
")",
"===",
"round",
"(",
"$",
"percent",
",",
"2",
")",
")",
"{",
"// No significant change, no need to update anything.",
"return",
";",
"}",
"$",
"estimatemsg",
"=",
"null",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"estimate",
")",
")",
"{",
"$",
"estimatemsg",
"=",
"get_string",
"(",
"'secondsleft'",
",",
"'moodle'",
",",
"round",
"(",
"$",
"estimate",
",",
"2",
")",
")",
";",
"}",
"$",
"this",
"->",
"percent",
"=",
"round",
"(",
"$",
"percent",
",",
"2",
")",
";",
"$",
"this",
"->",
"lastupdate",
"=",
"microtime",
"(",
"true",
")",
";",
"echo",
"html_writer",
"::",
"script",
"(",
"js_writer",
"::",
"function_call",
"(",
"'updateProgressBar'",
",",
"array",
"(",
"$",
"this",
"->",
"html_id",
",",
"$",
"this",
"->",
"percent",
",",
"$",
"msg",
",",
"$",
"estimatemsg",
")",
")",
")",
";",
"flush",
"(",
")",
";",
"}"
] |
Update the progress bar.
@param int $percent From 1-100.
@param string $msg The message.
@return void Echo's output
@throws coding_exception
|
[
"Update",
"the",
"progress",
"bar",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L4900-L4934
|
219,829
|
moodle/moodle
|
lib/outputcomponents.php
|
progress_bar.estimate
|
private function estimate($pt) {
if ($this->lastupdate == 0) {
return null;
}
if ($pt < 0.00001) {
return null; // We do not know yet how long it will take.
}
if ($pt > 99.99999) {
return 0; // Nearly done, right?
}
$consumed = microtime(true) - $this->time_start;
if ($consumed < 0.001) {
return null;
}
return (100 - $pt) * ($consumed / $pt);
}
|
php
|
private function estimate($pt) {
if ($this->lastupdate == 0) {
return null;
}
if ($pt < 0.00001) {
return null; // We do not know yet how long it will take.
}
if ($pt > 99.99999) {
return 0; // Nearly done, right?
}
$consumed = microtime(true) - $this->time_start;
if ($consumed < 0.001) {
return null;
}
return (100 - $pt) * ($consumed / $pt);
}
|
[
"private",
"function",
"estimate",
"(",
"$",
"pt",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"lastupdate",
"==",
"0",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"pt",
"<",
"0.00001",
")",
"{",
"return",
"null",
";",
"// We do not know yet how long it will take.",
"}",
"if",
"(",
"$",
"pt",
">",
"99.99999",
")",
"{",
"return",
"0",
";",
"// Nearly done, right?",
"}",
"$",
"consumed",
"=",
"microtime",
"(",
"true",
")",
"-",
"$",
"this",
"->",
"time_start",
";",
"if",
"(",
"$",
"consumed",
"<",
"0.001",
")",
"{",
"return",
"null",
";",
"}",
"return",
"(",
"100",
"-",
"$",
"pt",
")",
"*",
"(",
"$",
"consumed",
"/",
"$",
"pt",
")",
";",
"}"
] |
Estimate how much time it is going to take.
@param int $pt From 1-100.
@return mixed Null (unknown), or int.
|
[
"Estimate",
"how",
"much",
"time",
"it",
"is",
"going",
"to",
"take",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L4942-L4958
|
219,830
|
moodle/moodle
|
lib/outputcomponents.php
|
progress_bar.update_full
|
public function update_full($percent, $msg) {
$percent = max(min($percent, 100), 0);
$this->_update($percent, $msg);
}
|
php
|
public function update_full($percent, $msg) {
$percent = max(min($percent, 100), 0);
$this->_update($percent, $msg);
}
|
[
"public",
"function",
"update_full",
"(",
"$",
"percent",
",",
"$",
"msg",
")",
"{",
"$",
"percent",
"=",
"max",
"(",
"min",
"(",
"$",
"percent",
",",
"100",
")",
",",
"0",
")",
";",
"$",
"this",
"->",
"_update",
"(",
"$",
"percent",
",",
"$",
"msg",
")",
";",
"}"
] |
Update progress bar according percent.
@param int $percent From 1-100.
@param string $msg The message needed to be shown.
|
[
"Update",
"progress",
"bar",
"according",
"percent",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L4966-L4969
|
219,831
|
moodle/moodle
|
lib/outputcomponents.php
|
progress_bar.update
|
public function update($cur, $total, $msg) {
$percent = ($cur / $total) * 100;
$this->update_full($percent, $msg);
}
|
php
|
public function update($cur, $total, $msg) {
$percent = ($cur / $total) * 100;
$this->update_full($percent, $msg);
}
|
[
"public",
"function",
"update",
"(",
"$",
"cur",
",",
"$",
"total",
",",
"$",
"msg",
")",
"{",
"$",
"percent",
"=",
"(",
"$",
"cur",
"/",
"$",
"total",
")",
"*",
"100",
";",
"$",
"this",
"->",
"update_full",
"(",
"$",
"percent",
",",
"$",
"msg",
")",
";",
"}"
] |
Update progress bar according the number of tasks.
@param int $cur Current task number.
@param int $total Total task number.
@param string $msg The message needed to be shown.
|
[
"Update",
"progress",
"bar",
"according",
"the",
"number",
"of",
"tasks",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/outputcomponents.php#L4978-L4981
|
219,832
|
moodle/moodle
|
mod/assign/feedback/editpdf/locallib.php
|
assign_feedback_editpdf.get_widget
|
public function get_widget($userid, $grade, $readonly) {
$attempt = -1;
if ($grade && isset($grade->attemptnumber)) {
$attempt = $grade->attemptnumber;
} else {
$grade = $this->assignment->get_user_grade($userid, true);
}
$feedbackfile = document_services::get_feedback_document($this->assignment->get_instance()->id,
$userid,
$attempt);
$stampfiles = array();
$fs = get_file_storage();
$syscontext = context_system::instance();
// Copy any new stamps to this instance.
if ($files = $fs->get_area_files($syscontext->id,
'assignfeedback_editpdf',
'stamps',
0,
"filename",
false)) {
foreach ($files as $file) {
$filename = $file->get_filename();
if ($filename !== '.') {
$existingfile = $fs->get_file($this->assignment->get_context()->id,
'assignfeedback_editpdf',
'stamps',
$grade->id,
'/',
$file->get_filename());
if (!$existingfile) {
$newrecord = new stdClass();
$newrecord->contextid = $this->assignment->get_context()->id;
$newrecord->itemid = $grade->id;
$fs->create_file_from_storedfile($newrecord, $file);
}
}
}
}
// Now get the full list of stamp files for this instance.
if ($files = $fs->get_area_files($this->assignment->get_context()->id,
'assignfeedback_editpdf',
'stamps',
$grade->id,
"filename",
false)) {
foreach ($files as $file) {
$filename = $file->get_filename();
if ($filename !== '.') {
$url = moodle_url::make_pluginfile_url($this->assignment->get_context()->id,
'assignfeedback_editpdf',
'stamps',
$grade->id,
'/',
$file->get_filename(),
false);
array_push($stampfiles, $url->out());
}
}
}
$url = false;
$filename = '';
if ($feedbackfile) {
$url = moodle_url::make_pluginfile_url($this->assignment->get_context()->id,
'assignfeedback_editpdf',
document_services::FINAL_PDF_FILEAREA,
$grade->id,
'/',
$feedbackfile->get_filename(),
false);
$filename = $feedbackfile->get_filename();
}
$widget = new assignfeedback_editpdf_widget($this->assignment->get_instance()->id,
$userid,
$attempt,
$url,
$filename,
$stampfiles,
$readonly
);
return $widget;
}
|
php
|
public function get_widget($userid, $grade, $readonly) {
$attempt = -1;
if ($grade && isset($grade->attemptnumber)) {
$attempt = $grade->attemptnumber;
} else {
$grade = $this->assignment->get_user_grade($userid, true);
}
$feedbackfile = document_services::get_feedback_document($this->assignment->get_instance()->id,
$userid,
$attempt);
$stampfiles = array();
$fs = get_file_storage();
$syscontext = context_system::instance();
// Copy any new stamps to this instance.
if ($files = $fs->get_area_files($syscontext->id,
'assignfeedback_editpdf',
'stamps',
0,
"filename",
false)) {
foreach ($files as $file) {
$filename = $file->get_filename();
if ($filename !== '.') {
$existingfile = $fs->get_file($this->assignment->get_context()->id,
'assignfeedback_editpdf',
'stamps',
$grade->id,
'/',
$file->get_filename());
if (!$existingfile) {
$newrecord = new stdClass();
$newrecord->contextid = $this->assignment->get_context()->id;
$newrecord->itemid = $grade->id;
$fs->create_file_from_storedfile($newrecord, $file);
}
}
}
}
// Now get the full list of stamp files for this instance.
if ($files = $fs->get_area_files($this->assignment->get_context()->id,
'assignfeedback_editpdf',
'stamps',
$grade->id,
"filename",
false)) {
foreach ($files as $file) {
$filename = $file->get_filename();
if ($filename !== '.') {
$url = moodle_url::make_pluginfile_url($this->assignment->get_context()->id,
'assignfeedback_editpdf',
'stamps',
$grade->id,
'/',
$file->get_filename(),
false);
array_push($stampfiles, $url->out());
}
}
}
$url = false;
$filename = '';
if ($feedbackfile) {
$url = moodle_url::make_pluginfile_url($this->assignment->get_context()->id,
'assignfeedback_editpdf',
document_services::FINAL_PDF_FILEAREA,
$grade->id,
'/',
$feedbackfile->get_filename(),
false);
$filename = $feedbackfile->get_filename();
}
$widget = new assignfeedback_editpdf_widget($this->assignment->get_instance()->id,
$userid,
$attempt,
$url,
$filename,
$stampfiles,
$readonly
);
return $widget;
}
|
[
"public",
"function",
"get_widget",
"(",
"$",
"userid",
",",
"$",
"grade",
",",
"$",
"readonly",
")",
"{",
"$",
"attempt",
"=",
"-",
"1",
";",
"if",
"(",
"$",
"grade",
"&&",
"isset",
"(",
"$",
"grade",
"->",
"attemptnumber",
")",
")",
"{",
"$",
"attempt",
"=",
"$",
"grade",
"->",
"attemptnumber",
";",
"}",
"else",
"{",
"$",
"grade",
"=",
"$",
"this",
"->",
"assignment",
"->",
"get_user_grade",
"(",
"$",
"userid",
",",
"true",
")",
";",
"}",
"$",
"feedbackfile",
"=",
"document_services",
"::",
"get_feedback_document",
"(",
"$",
"this",
"->",
"assignment",
"->",
"get_instance",
"(",
")",
"->",
"id",
",",
"$",
"userid",
",",
"$",
"attempt",
")",
";",
"$",
"stampfiles",
"=",
"array",
"(",
")",
";",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"$",
"syscontext",
"=",
"context_system",
"::",
"instance",
"(",
")",
";",
"// Copy any new stamps to this instance.",
"if",
"(",
"$",
"files",
"=",
"$",
"fs",
"->",
"get_area_files",
"(",
"$",
"syscontext",
"->",
"id",
",",
"'assignfeedback_editpdf'",
",",
"'stamps'",
",",
"0",
",",
"\"filename\"",
",",
"false",
")",
")",
"{",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"filename",
"=",
"$",
"file",
"->",
"get_filename",
"(",
")",
";",
"if",
"(",
"$",
"filename",
"!==",
"'.'",
")",
"{",
"$",
"existingfile",
"=",
"$",
"fs",
"->",
"get_file",
"(",
"$",
"this",
"->",
"assignment",
"->",
"get_context",
"(",
")",
"->",
"id",
",",
"'assignfeedback_editpdf'",
",",
"'stamps'",
",",
"$",
"grade",
"->",
"id",
",",
"'/'",
",",
"$",
"file",
"->",
"get_filename",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"existingfile",
")",
"{",
"$",
"newrecord",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"newrecord",
"->",
"contextid",
"=",
"$",
"this",
"->",
"assignment",
"->",
"get_context",
"(",
")",
"->",
"id",
";",
"$",
"newrecord",
"->",
"itemid",
"=",
"$",
"grade",
"->",
"id",
";",
"$",
"fs",
"->",
"create_file_from_storedfile",
"(",
"$",
"newrecord",
",",
"$",
"file",
")",
";",
"}",
"}",
"}",
"}",
"// Now get the full list of stamp files for this instance.",
"if",
"(",
"$",
"files",
"=",
"$",
"fs",
"->",
"get_area_files",
"(",
"$",
"this",
"->",
"assignment",
"->",
"get_context",
"(",
")",
"->",
"id",
",",
"'assignfeedback_editpdf'",
",",
"'stamps'",
",",
"$",
"grade",
"->",
"id",
",",
"\"filename\"",
",",
"false",
")",
")",
"{",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"filename",
"=",
"$",
"file",
"->",
"get_filename",
"(",
")",
";",
"if",
"(",
"$",
"filename",
"!==",
"'.'",
")",
"{",
"$",
"url",
"=",
"moodle_url",
"::",
"make_pluginfile_url",
"(",
"$",
"this",
"->",
"assignment",
"->",
"get_context",
"(",
")",
"->",
"id",
",",
"'assignfeedback_editpdf'",
",",
"'stamps'",
",",
"$",
"grade",
"->",
"id",
",",
"'/'",
",",
"$",
"file",
"->",
"get_filename",
"(",
")",
",",
"false",
")",
";",
"array_push",
"(",
"$",
"stampfiles",
",",
"$",
"url",
"->",
"out",
"(",
")",
")",
";",
"}",
"}",
"}",
"$",
"url",
"=",
"false",
";",
"$",
"filename",
"=",
"''",
";",
"if",
"(",
"$",
"feedbackfile",
")",
"{",
"$",
"url",
"=",
"moodle_url",
"::",
"make_pluginfile_url",
"(",
"$",
"this",
"->",
"assignment",
"->",
"get_context",
"(",
")",
"->",
"id",
",",
"'assignfeedback_editpdf'",
",",
"document_services",
"::",
"FINAL_PDF_FILEAREA",
",",
"$",
"grade",
"->",
"id",
",",
"'/'",
",",
"$",
"feedbackfile",
"->",
"get_filename",
"(",
")",
",",
"false",
")",
";",
"$",
"filename",
"=",
"$",
"feedbackfile",
"->",
"get_filename",
"(",
")",
";",
"}",
"$",
"widget",
"=",
"new",
"assignfeedback_editpdf_widget",
"(",
"$",
"this",
"->",
"assignment",
"->",
"get_instance",
"(",
")",
"->",
"id",
",",
"$",
"userid",
",",
"$",
"attempt",
",",
"$",
"url",
",",
"$",
"filename",
",",
"$",
"stampfiles",
",",
"$",
"readonly",
")",
";",
"return",
"$",
"widget",
";",
"}"
] |
Create a widget for rendering the editor.
@param int $userid
@param stdClass $grade
@param bool $readonly
@return assignfeedback_editpdf_widget
|
[
"Create",
"a",
"widget",
"for",
"rendering",
"the",
"editor",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/locallib.php#L59-L146
|
219,833
|
moodle/moodle
|
mod/assign/feedback/editpdf/locallib.php
|
assign_feedback_editpdf.get_form_elements_for_user
|
public function get_form_elements_for_user($grade, MoodleQuickForm $mform, stdClass $data, $userid) {
global $PAGE;
$attempt = -1;
if ($grade) {
$attempt = $grade->attemptnumber;
}
$renderer = $PAGE->get_renderer('assignfeedback_editpdf');
$widget = $this->get_widget($userid, $grade, false);
$html = $renderer->render($widget);
$mform->addElement('static', 'editpdf', get_string('editpdf', 'assignfeedback_editpdf'), $html);
$mform->addHelpButton('editpdf', 'editpdf', 'assignfeedback_editpdf');
$mform->addElement('hidden', 'editpdf_source_userid', $userid);
$mform->setType('editpdf_source_userid', PARAM_INT);
$mform->setConstant('editpdf_source_userid', $userid);
}
|
php
|
public function get_form_elements_for_user($grade, MoodleQuickForm $mform, stdClass $data, $userid) {
global $PAGE;
$attempt = -1;
if ($grade) {
$attempt = $grade->attemptnumber;
}
$renderer = $PAGE->get_renderer('assignfeedback_editpdf');
$widget = $this->get_widget($userid, $grade, false);
$html = $renderer->render($widget);
$mform->addElement('static', 'editpdf', get_string('editpdf', 'assignfeedback_editpdf'), $html);
$mform->addHelpButton('editpdf', 'editpdf', 'assignfeedback_editpdf');
$mform->addElement('hidden', 'editpdf_source_userid', $userid);
$mform->setType('editpdf_source_userid', PARAM_INT);
$mform->setConstant('editpdf_source_userid', $userid);
}
|
[
"public",
"function",
"get_form_elements_for_user",
"(",
"$",
"grade",
",",
"MoodleQuickForm",
"$",
"mform",
",",
"stdClass",
"$",
"data",
",",
"$",
"userid",
")",
"{",
"global",
"$",
"PAGE",
";",
"$",
"attempt",
"=",
"-",
"1",
";",
"if",
"(",
"$",
"grade",
")",
"{",
"$",
"attempt",
"=",
"$",
"grade",
"->",
"attemptnumber",
";",
"}",
"$",
"renderer",
"=",
"$",
"PAGE",
"->",
"get_renderer",
"(",
"'assignfeedback_editpdf'",
")",
";",
"$",
"widget",
"=",
"$",
"this",
"->",
"get_widget",
"(",
"$",
"userid",
",",
"$",
"grade",
",",
"false",
")",
";",
"$",
"html",
"=",
"$",
"renderer",
"->",
"render",
"(",
"$",
"widget",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'static'",
",",
"'editpdf'",
",",
"get_string",
"(",
"'editpdf'",
",",
"'assignfeedback_editpdf'",
")",
",",
"$",
"html",
")",
";",
"$",
"mform",
"->",
"addHelpButton",
"(",
"'editpdf'",
",",
"'editpdf'",
",",
"'assignfeedback_editpdf'",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'hidden'",
",",
"'editpdf_source_userid'",
",",
"$",
"userid",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'editpdf_source_userid'",
",",
"PARAM_INT",
")",
";",
"$",
"mform",
"->",
"setConstant",
"(",
"'editpdf_source_userid'",
",",
"$",
"userid",
")",
";",
"}"
] |
Get form elements for grading form
@param stdClass $grade
@param MoodleQuickForm $mform
@param stdClass $data
@param int $userid
@return bool true if elements were added to the form
|
[
"Get",
"form",
"elements",
"for",
"grading",
"form"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/locallib.php#L157-L175
|
219,834
|
moodle/moodle
|
mod/assign/feedback/editpdf/locallib.php
|
assign_feedback_editpdf.is_feedback_modified
|
public function is_feedback_modified(stdClass $grade, stdClass $data) {
// We only need to know if the source user's PDF has changed. If so then all
// following users will have the same status. If it's only an individual annotation
// then only one user will come through this method.
// Source user id is only added to the form if there was a pdf.
if (!empty($data->editpdf_source_userid)) {
$sourceuserid = $data->editpdf_source_userid;
// Retrieve the grade information for the source user.
$sourcegrade = $this->assignment->get_user_grade($sourceuserid, true, $grade->attemptnumber);
$pagenumbercount = document_services::page_number_for_attempt($this->assignment, $sourceuserid, $sourcegrade->attemptnumber);
for ($i = 0; $i < $pagenumbercount; $i++) {
// Select all annotations.
$draftannotations = page_editor::get_annotations($sourcegrade->id, $i, true);
$nondraftannotations = page_editor::get_annotations($grade->id, $i, false);
// Check to see if the count is the same.
if (count($draftannotations) != count($nondraftannotations)) {
// The count is different so we have a modification.
return true;
} else {
$matches = 0;
// Have a closer look and see if the draft files match all the non draft files.
foreach ($nondraftannotations as $ndannotation) {
foreach ($draftannotations as $dannotation) {
foreach ($ndannotation as $key => $value) {
if ($key != 'id' && $value != $dannotation->{$key}) {
continue 2;
}
}
$matches++;
}
}
if ($matches !== count($nondraftannotations)) {
return true;
}
}
// Select all comments.
$draftcomments = page_editor::get_comments($sourcegrade->id, $i, true);
$nondraftcomments = page_editor::get_comments($grade->id, $i, false);
if (count($draftcomments) != count($nondraftcomments)) {
return true;
} else {
// Go for a closer inspection.
$matches = 0;
foreach ($nondraftcomments as $ndcomment) {
foreach ($draftcomments as $dcomment) {
foreach ($ndcomment as $key => $value) {
if ($key != 'id' && $value != $dcomment->{$key}) {
continue 2;
}
}
$matches++;
}
}
if ($matches !== count($nondraftcomments)) {
return true;
}
}
}
}
return false;
}
|
php
|
public function is_feedback_modified(stdClass $grade, stdClass $data) {
// We only need to know if the source user's PDF has changed. If so then all
// following users will have the same status. If it's only an individual annotation
// then only one user will come through this method.
// Source user id is only added to the form if there was a pdf.
if (!empty($data->editpdf_source_userid)) {
$sourceuserid = $data->editpdf_source_userid;
// Retrieve the grade information for the source user.
$sourcegrade = $this->assignment->get_user_grade($sourceuserid, true, $grade->attemptnumber);
$pagenumbercount = document_services::page_number_for_attempt($this->assignment, $sourceuserid, $sourcegrade->attemptnumber);
for ($i = 0; $i < $pagenumbercount; $i++) {
// Select all annotations.
$draftannotations = page_editor::get_annotations($sourcegrade->id, $i, true);
$nondraftannotations = page_editor::get_annotations($grade->id, $i, false);
// Check to see if the count is the same.
if (count($draftannotations) != count($nondraftannotations)) {
// The count is different so we have a modification.
return true;
} else {
$matches = 0;
// Have a closer look and see if the draft files match all the non draft files.
foreach ($nondraftannotations as $ndannotation) {
foreach ($draftannotations as $dannotation) {
foreach ($ndannotation as $key => $value) {
if ($key != 'id' && $value != $dannotation->{$key}) {
continue 2;
}
}
$matches++;
}
}
if ($matches !== count($nondraftannotations)) {
return true;
}
}
// Select all comments.
$draftcomments = page_editor::get_comments($sourcegrade->id, $i, true);
$nondraftcomments = page_editor::get_comments($grade->id, $i, false);
if (count($draftcomments) != count($nondraftcomments)) {
return true;
} else {
// Go for a closer inspection.
$matches = 0;
foreach ($nondraftcomments as $ndcomment) {
foreach ($draftcomments as $dcomment) {
foreach ($ndcomment as $key => $value) {
if ($key != 'id' && $value != $dcomment->{$key}) {
continue 2;
}
}
$matches++;
}
}
if ($matches !== count($nondraftcomments)) {
return true;
}
}
}
}
return false;
}
|
[
"public",
"function",
"is_feedback_modified",
"(",
"stdClass",
"$",
"grade",
",",
"stdClass",
"$",
"data",
")",
"{",
"// We only need to know if the source user's PDF has changed. If so then all",
"// following users will have the same status. If it's only an individual annotation",
"// then only one user will come through this method.",
"// Source user id is only added to the form if there was a pdf.",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"->",
"editpdf_source_userid",
")",
")",
"{",
"$",
"sourceuserid",
"=",
"$",
"data",
"->",
"editpdf_source_userid",
";",
"// Retrieve the grade information for the source user.",
"$",
"sourcegrade",
"=",
"$",
"this",
"->",
"assignment",
"->",
"get_user_grade",
"(",
"$",
"sourceuserid",
",",
"true",
",",
"$",
"grade",
"->",
"attemptnumber",
")",
";",
"$",
"pagenumbercount",
"=",
"document_services",
"::",
"page_number_for_attempt",
"(",
"$",
"this",
"->",
"assignment",
",",
"$",
"sourceuserid",
",",
"$",
"sourcegrade",
"->",
"attemptnumber",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"pagenumbercount",
";",
"$",
"i",
"++",
")",
"{",
"// Select all annotations.",
"$",
"draftannotations",
"=",
"page_editor",
"::",
"get_annotations",
"(",
"$",
"sourcegrade",
"->",
"id",
",",
"$",
"i",
",",
"true",
")",
";",
"$",
"nondraftannotations",
"=",
"page_editor",
"::",
"get_annotations",
"(",
"$",
"grade",
"->",
"id",
",",
"$",
"i",
",",
"false",
")",
";",
"// Check to see if the count is the same.",
"if",
"(",
"count",
"(",
"$",
"draftannotations",
")",
"!=",
"count",
"(",
"$",
"nondraftannotations",
")",
")",
"{",
"// The count is different so we have a modification.",
"return",
"true",
";",
"}",
"else",
"{",
"$",
"matches",
"=",
"0",
";",
"// Have a closer look and see if the draft files match all the non draft files.",
"foreach",
"(",
"$",
"nondraftannotations",
"as",
"$",
"ndannotation",
")",
"{",
"foreach",
"(",
"$",
"draftannotations",
"as",
"$",
"dannotation",
")",
"{",
"foreach",
"(",
"$",
"ndannotation",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"key",
"!=",
"'id'",
"&&",
"$",
"value",
"!=",
"$",
"dannotation",
"->",
"{",
"$",
"key",
"}",
")",
"{",
"continue",
"2",
";",
"}",
"}",
"$",
"matches",
"++",
";",
"}",
"}",
"if",
"(",
"$",
"matches",
"!==",
"count",
"(",
"$",
"nondraftannotations",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"// Select all comments.",
"$",
"draftcomments",
"=",
"page_editor",
"::",
"get_comments",
"(",
"$",
"sourcegrade",
"->",
"id",
",",
"$",
"i",
",",
"true",
")",
";",
"$",
"nondraftcomments",
"=",
"page_editor",
"::",
"get_comments",
"(",
"$",
"grade",
"->",
"id",
",",
"$",
"i",
",",
"false",
")",
";",
"if",
"(",
"count",
"(",
"$",
"draftcomments",
")",
"!=",
"count",
"(",
"$",
"nondraftcomments",
")",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"// Go for a closer inspection.",
"$",
"matches",
"=",
"0",
";",
"foreach",
"(",
"$",
"nondraftcomments",
"as",
"$",
"ndcomment",
")",
"{",
"foreach",
"(",
"$",
"draftcomments",
"as",
"$",
"dcomment",
")",
"{",
"foreach",
"(",
"$",
"ndcomment",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"key",
"!=",
"'id'",
"&&",
"$",
"value",
"!=",
"$",
"dcomment",
"->",
"{",
"$",
"key",
"}",
")",
"{",
"continue",
"2",
";",
"}",
"}",
"$",
"matches",
"++",
";",
"}",
"}",
"if",
"(",
"$",
"matches",
"!==",
"count",
"(",
"$",
"nondraftcomments",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] |
Check to see if the grade feedback for the pdf has been modified.
@param stdClass $grade Grade object.
@param stdClass $data Data from the form submission (not used).
@return boolean True if the pdf has been modified, else false.
|
[
"Check",
"to",
"see",
"if",
"the",
"grade",
"feedback",
"for",
"the",
"pdf",
"has",
"been",
"modified",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/locallib.php#L184-L244
|
219,835
|
moodle/moodle
|
mod/assign/feedback/editpdf/locallib.php
|
assign_feedback_editpdf.delete_instance
|
public function delete_instance() {
global $DB;
$grades = $DB->get_records('assign_grades', array('assignment'=>$this->assignment->get_instance()->id), '', 'id');
if ($grades) {
list($gradeids, $params) = $DB->get_in_or_equal(array_keys($grades), SQL_PARAMS_NAMED);
$DB->delete_records_select('assignfeedback_editpdf_annot', 'gradeid ' . $gradeids, $params);
$DB->delete_records_select('assignfeedback_editpdf_cmnt', 'gradeid ' . $gradeids, $params);
}
return true;
}
|
php
|
public function delete_instance() {
global $DB;
$grades = $DB->get_records('assign_grades', array('assignment'=>$this->assignment->get_instance()->id), '', 'id');
if ($grades) {
list($gradeids, $params) = $DB->get_in_or_equal(array_keys($grades), SQL_PARAMS_NAMED);
$DB->delete_records_select('assignfeedback_editpdf_annot', 'gradeid ' . $gradeids, $params);
$DB->delete_records_select('assignfeedback_editpdf_cmnt', 'gradeid ' . $gradeids, $params);
}
return true;
}
|
[
"public",
"function",
"delete_instance",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"grades",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'assign_grades'",
",",
"array",
"(",
"'assignment'",
"=>",
"$",
"this",
"->",
"assignment",
"->",
"get_instance",
"(",
")",
"->",
"id",
")",
",",
"''",
",",
"'id'",
")",
";",
"if",
"(",
"$",
"grades",
")",
"{",
"list",
"(",
"$",
"gradeids",
",",
"$",
"params",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"array_keys",
"(",
"$",
"grades",
")",
",",
"SQL_PARAMS_NAMED",
")",
";",
"$",
"DB",
"->",
"delete_records_select",
"(",
"'assignfeedback_editpdf_annot'",
",",
"'gradeid '",
".",
"$",
"gradeids",
",",
"$",
"params",
")",
";",
"$",
"DB",
"->",
"delete_records_select",
"(",
"'assignfeedback_editpdf_cmnt'",
",",
"'gradeid '",
".",
"$",
"gradeids",
",",
"$",
"params",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
The assignment has been deleted - remove the plugin specific data
@return bool
|
[
"The",
"assignment",
"has",
"been",
"deleted",
"-",
"remove",
"the",
"plugin",
"specific",
"data"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/locallib.php#L323-L332
|
219,836
|
moodle/moodle
|
mod/assign/feedback/editpdf/locallib.php
|
assign_feedback_editpdf.is_available
|
public function is_available() {
if ($this->enabledcache === null) {
$testpath = assignfeedback_editpdf\pdf::test_gs_path(false);
$this->enabledcache = ($testpath->status == assignfeedback_editpdf\pdf::GSPATH_OK);
}
return $this->enabledcache;
}
|
php
|
public function is_available() {
if ($this->enabledcache === null) {
$testpath = assignfeedback_editpdf\pdf::test_gs_path(false);
$this->enabledcache = ($testpath->status == assignfeedback_editpdf\pdf::GSPATH_OK);
}
return $this->enabledcache;
}
|
[
"public",
"function",
"is_available",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"enabledcache",
"===",
"null",
")",
"{",
"$",
"testpath",
"=",
"assignfeedback_editpdf",
"\\",
"pdf",
"::",
"test_gs_path",
"(",
"false",
")",
";",
"$",
"this",
"->",
"enabledcache",
"=",
"(",
"$",
"testpath",
"->",
"status",
"==",
"assignfeedback_editpdf",
"\\",
"pdf",
"::",
"GSPATH_OK",
")",
";",
"}",
"return",
"$",
"this",
"->",
"enabledcache",
";",
"}"
] |
Determine if ghostscript is available and working.
@return bool
|
[
"Determine",
"if",
"ghostscript",
"is",
"available",
"and",
"working",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/locallib.php#L339-L345
|
219,837
|
moodle/moodle
|
lib/simplepie/library/SimplePie/Registry.php
|
SimplePie_Registry.register
|
public function register($type, $class, $legacy = false)
{
if (!@is_subclass_of($class, $this->default[$type]))
{
return false;
}
$this->classes[$type] = $class;
if ($legacy)
{
$this->legacy[] = $class;
}
return true;
}
|
php
|
public function register($type, $class, $legacy = false)
{
if (!@is_subclass_of($class, $this->default[$type]))
{
return false;
}
$this->classes[$type] = $class;
if ($legacy)
{
$this->legacy[] = $class;
}
return true;
}
|
[
"public",
"function",
"register",
"(",
"$",
"type",
",",
"$",
"class",
",",
"$",
"legacy",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"@",
"is_subclass_of",
"(",
"$",
"class",
",",
"$",
"this",
"->",
"default",
"[",
"$",
"type",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"classes",
"[",
"$",
"type",
"]",
"=",
"$",
"class",
";",
"if",
"(",
"$",
"legacy",
")",
"{",
"$",
"this",
"->",
"legacy",
"[",
"]",
"=",
"$",
"class",
";",
"}",
"return",
"true",
";",
"}"
] |
Register a class
@param string $type See {@see $default} for names
@param string $class Class name, must subclass the corresponding default
@param bool $legacy Whether to enable legacy support for this class
@return bool Successfulness
|
[
"Register",
"a",
"class"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/Registry.php#L113-L128
|
219,838
|
moodle/moodle
|
lib/simplepie/library/SimplePie/Registry.php
|
SimplePie_Registry.get_class
|
public function get_class($type)
{
if (!empty($this->classes[$type]))
{
return $this->classes[$type];
}
if (!empty($this->default[$type]))
{
return $this->default[$type];
}
return null;
}
|
php
|
public function get_class($type)
{
if (!empty($this->classes[$type]))
{
return $this->classes[$type];
}
if (!empty($this->default[$type]))
{
return $this->default[$type];
}
return null;
}
|
[
"public",
"function",
"get_class",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"classes",
"[",
"$",
"type",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"classes",
"[",
"$",
"type",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"default",
"[",
"$",
"type",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"default",
"[",
"$",
"type",
"]",
";",
"}",
"return",
"null",
";",
"}"
] |
Get the class registered for a type
Where possible, use {@see create()} or {@see call()} instead
@param string $type
@return string|null
|
[
"Get",
"the",
"class",
"registered",
"for",
"a",
"type"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/Registry.php#L138-L150
|
219,839
|
moodle/moodle
|
lib/simplepie/library/SimplePie/Registry.php
|
SimplePie_Registry.&
|
public function &create($type, $parameters = array())
{
$class = $this->get_class($type);
if (in_array($class, $this->legacy))
{
switch ($type)
{
case 'locator':
// Legacy: file, timeout, useragent, file_class, max_checked_feeds, content_type_sniffer_class
// Specified: file, timeout, useragent, max_checked_feeds
$replacement = array($this->get_class('file'), $parameters[3], $this->get_class('content_type_sniffer'));
array_splice($parameters, 3, 1, $replacement);
break;
}
}
if (!method_exists($class, '__construct'))
{
$instance = new $class;
}
else
{
$reflector = new ReflectionClass($class);
$instance = $reflector->newInstanceArgs($parameters);
}
if (method_exists($instance, 'set_registry'))
{
$instance->set_registry($this);
}
return $instance;
}
|
php
|
public function &create($type, $parameters = array())
{
$class = $this->get_class($type);
if (in_array($class, $this->legacy))
{
switch ($type)
{
case 'locator':
// Legacy: file, timeout, useragent, file_class, max_checked_feeds, content_type_sniffer_class
// Specified: file, timeout, useragent, max_checked_feeds
$replacement = array($this->get_class('file'), $parameters[3], $this->get_class('content_type_sniffer'));
array_splice($parameters, 3, 1, $replacement);
break;
}
}
if (!method_exists($class, '__construct'))
{
$instance = new $class;
}
else
{
$reflector = new ReflectionClass($class);
$instance = $reflector->newInstanceArgs($parameters);
}
if (method_exists($instance, 'set_registry'))
{
$instance->set_registry($this);
}
return $instance;
}
|
[
"public",
"function",
"&",
"create",
"(",
"$",
"type",
",",
"$",
"parameters",
"=",
"array",
"(",
")",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"get_class",
"(",
"$",
"type",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"class",
",",
"$",
"this",
"->",
"legacy",
")",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'locator'",
":",
"// Legacy: file, timeout, useragent, file_class, max_checked_feeds, content_type_sniffer_class",
"// Specified: file, timeout, useragent, max_checked_feeds",
"$",
"replacement",
"=",
"array",
"(",
"$",
"this",
"->",
"get_class",
"(",
"'file'",
")",
",",
"$",
"parameters",
"[",
"3",
"]",
",",
"$",
"this",
"->",
"get_class",
"(",
"'content_type_sniffer'",
")",
")",
";",
"array_splice",
"(",
"$",
"parameters",
",",
"3",
",",
"1",
",",
"$",
"replacement",
")",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"class",
",",
"'__construct'",
")",
")",
"{",
"$",
"instance",
"=",
"new",
"$",
"class",
";",
"}",
"else",
"{",
"$",
"reflector",
"=",
"new",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"$",
"instance",
"=",
"$",
"reflector",
"->",
"newInstanceArgs",
"(",
"$",
"parameters",
")",
";",
"}",
"if",
"(",
"method_exists",
"(",
"$",
"instance",
",",
"'set_registry'",
")",
")",
"{",
"$",
"instance",
"->",
"set_registry",
"(",
"$",
"this",
")",
";",
"}",
"return",
"$",
"instance",
";",
"}"
] |
Create a new instance of a given type
@param string $type
@param array $parameters Parameters to pass to the constructor
@return object Instance of class
|
[
"Create",
"a",
"new",
"instance",
"of",
"a",
"given",
"type"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/Registry.php#L159-L191
|
219,840
|
moodle/moodle
|
lib/simplepie/library/SimplePie/Registry.php
|
SimplePie_Registry.&
|
public function &call($type, $method, $parameters = array())
{
$class = $this->get_class($type);
if (in_array($class, $this->legacy))
{
switch ($type)
{
case 'Cache':
// For backwards compatibility with old non-static
// Cache::create() methods
if ($method === 'get_handler')
{
$result = @call_user_func_array(array($class, 'create'), $parameters);
return $result;
}
break;
}
}
$result = call_user_func_array(array($class, $method), $parameters);
return $result;
}
|
php
|
public function &call($type, $method, $parameters = array())
{
$class = $this->get_class($type);
if (in_array($class, $this->legacy))
{
switch ($type)
{
case 'Cache':
// For backwards compatibility with old non-static
// Cache::create() methods
if ($method === 'get_handler')
{
$result = @call_user_func_array(array($class, 'create'), $parameters);
return $result;
}
break;
}
}
$result = call_user_func_array(array($class, $method), $parameters);
return $result;
}
|
[
"public",
"function",
"&",
"call",
"(",
"$",
"type",
",",
"$",
"method",
",",
"$",
"parameters",
"=",
"array",
"(",
")",
")",
"{",
"$",
"class",
"=",
"$",
"this",
"->",
"get_class",
"(",
"$",
"type",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"class",
",",
"$",
"this",
"->",
"legacy",
")",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'Cache'",
":",
"// For backwards compatibility with old non-static",
"// Cache::create() methods",
"if",
"(",
"$",
"method",
"===",
"'get_handler'",
")",
"{",
"$",
"result",
"=",
"@",
"call_user_func_array",
"(",
"array",
"(",
"$",
"class",
",",
"'create'",
")",
",",
"$",
"parameters",
")",
";",
"return",
"$",
"result",
";",
"}",
"break",
";",
"}",
"}",
"$",
"result",
"=",
"call_user_func_array",
"(",
"array",
"(",
"$",
"class",
",",
"$",
"method",
")",
",",
"$",
"parameters",
")",
";",
"return",
"$",
"result",
";",
"}"
] |
Call a static method for a type
@param string $type
@param string $method
@param array $parameters
@return mixed
|
[
"Call",
"a",
"static",
"method",
"for",
"a",
"type"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/Registry.php#L201-L223
|
219,841
|
moodle/moodle
|
lib/dml/mysqli_native_moodle_database.php
|
mysqli_native_moodle_database.create_database
|
public function create_database($dbhost, $dbuser, $dbpass, $dbname, array $dboptions=null) {
$driverstatus = $this->driver_installed();
if ($driverstatus !== true) {
throw new dml_exception('dbdriverproblem', $driverstatus);
}
if (!empty($dboptions['dbsocket'])
and (strpos($dboptions['dbsocket'], '/') !== false or strpos($dboptions['dbsocket'], '\\') !== false)) {
$dbsocket = $dboptions['dbsocket'];
} else {
$dbsocket = ini_get('mysqli.default_socket');
}
if (empty($dboptions['dbport'])) {
$dbport = (int)ini_get('mysqli.default_port');
} else {
$dbport = (int)$dboptions['dbport'];
}
// verify ini.get does not return nonsense
if (empty($dbport)) {
$dbport = 3306;
}
ob_start();
$conn = new mysqli($dbhost, $dbuser, $dbpass, '', $dbport, $dbsocket); // Connect without db
$dberr = ob_get_contents();
ob_end_clean();
$errorno = @$conn->connect_errno;
if ($errorno !== 0) {
throw new dml_connection_exception($dberr);
}
// Normally a check would be done before setting utf8mb4, but the database can be created
// before the enviroment checks are done. We'll proceed with creating the database and then do checks next.
$charset = 'utf8mb4';
if (isset($dboptions['dbcollation']) and (strpos($dboptions['dbcollation'], 'utf8_') === 0
|| strpos($dboptions['dbcollation'], 'utf8mb4_') === 0)) {
$collation = $dboptions['dbcollation'];
$collationinfo = explode('_', $dboptions['dbcollation']);
$charset = reset($collationinfo);
} else {
$collation = 'utf8mb4_unicode_ci';
}
$result = $conn->query("CREATE DATABASE $dbname DEFAULT CHARACTER SET $charset DEFAULT COLLATE ".$collation);
$conn->close();
if (!$result) {
throw new dml_exception('cannotcreatedb');
}
return true;
}
|
php
|
public function create_database($dbhost, $dbuser, $dbpass, $dbname, array $dboptions=null) {
$driverstatus = $this->driver_installed();
if ($driverstatus !== true) {
throw new dml_exception('dbdriverproblem', $driverstatus);
}
if (!empty($dboptions['dbsocket'])
and (strpos($dboptions['dbsocket'], '/') !== false or strpos($dboptions['dbsocket'], '\\') !== false)) {
$dbsocket = $dboptions['dbsocket'];
} else {
$dbsocket = ini_get('mysqli.default_socket');
}
if (empty($dboptions['dbport'])) {
$dbport = (int)ini_get('mysqli.default_port');
} else {
$dbport = (int)$dboptions['dbport'];
}
// verify ini.get does not return nonsense
if (empty($dbport)) {
$dbport = 3306;
}
ob_start();
$conn = new mysqli($dbhost, $dbuser, $dbpass, '', $dbport, $dbsocket); // Connect without db
$dberr = ob_get_contents();
ob_end_clean();
$errorno = @$conn->connect_errno;
if ($errorno !== 0) {
throw new dml_connection_exception($dberr);
}
// Normally a check would be done before setting utf8mb4, but the database can be created
// before the enviroment checks are done. We'll proceed with creating the database and then do checks next.
$charset = 'utf8mb4';
if (isset($dboptions['dbcollation']) and (strpos($dboptions['dbcollation'], 'utf8_') === 0
|| strpos($dboptions['dbcollation'], 'utf8mb4_') === 0)) {
$collation = $dboptions['dbcollation'];
$collationinfo = explode('_', $dboptions['dbcollation']);
$charset = reset($collationinfo);
} else {
$collation = 'utf8mb4_unicode_ci';
}
$result = $conn->query("CREATE DATABASE $dbname DEFAULT CHARACTER SET $charset DEFAULT COLLATE ".$collation);
$conn->close();
if (!$result) {
throw new dml_exception('cannotcreatedb');
}
return true;
}
|
[
"public",
"function",
"create_database",
"(",
"$",
"dbhost",
",",
"$",
"dbuser",
",",
"$",
"dbpass",
",",
"$",
"dbname",
",",
"array",
"$",
"dboptions",
"=",
"null",
")",
"{",
"$",
"driverstatus",
"=",
"$",
"this",
"->",
"driver_installed",
"(",
")",
";",
"if",
"(",
"$",
"driverstatus",
"!==",
"true",
")",
"{",
"throw",
"new",
"dml_exception",
"(",
"'dbdriverproblem'",
",",
"$",
"driverstatus",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"dboptions",
"[",
"'dbsocket'",
"]",
")",
"and",
"(",
"strpos",
"(",
"$",
"dboptions",
"[",
"'dbsocket'",
"]",
",",
"'/'",
")",
"!==",
"false",
"or",
"strpos",
"(",
"$",
"dboptions",
"[",
"'dbsocket'",
"]",
",",
"'\\\\'",
")",
"!==",
"false",
")",
")",
"{",
"$",
"dbsocket",
"=",
"$",
"dboptions",
"[",
"'dbsocket'",
"]",
";",
"}",
"else",
"{",
"$",
"dbsocket",
"=",
"ini_get",
"(",
"'mysqli.default_socket'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"dboptions",
"[",
"'dbport'",
"]",
")",
")",
"{",
"$",
"dbport",
"=",
"(",
"int",
")",
"ini_get",
"(",
"'mysqli.default_port'",
")",
";",
"}",
"else",
"{",
"$",
"dbport",
"=",
"(",
"int",
")",
"$",
"dboptions",
"[",
"'dbport'",
"]",
";",
"}",
"// verify ini.get does not return nonsense",
"if",
"(",
"empty",
"(",
"$",
"dbport",
")",
")",
"{",
"$",
"dbport",
"=",
"3306",
";",
"}",
"ob_start",
"(",
")",
";",
"$",
"conn",
"=",
"new",
"mysqli",
"(",
"$",
"dbhost",
",",
"$",
"dbuser",
",",
"$",
"dbpass",
",",
"''",
",",
"$",
"dbport",
",",
"$",
"dbsocket",
")",
";",
"// Connect without db",
"$",
"dberr",
"=",
"ob_get_contents",
"(",
")",
";",
"ob_end_clean",
"(",
")",
";",
"$",
"errorno",
"=",
"@",
"$",
"conn",
"->",
"connect_errno",
";",
"if",
"(",
"$",
"errorno",
"!==",
"0",
")",
"{",
"throw",
"new",
"dml_connection_exception",
"(",
"$",
"dberr",
")",
";",
"}",
"// Normally a check would be done before setting utf8mb4, but the database can be created",
"// before the enviroment checks are done. We'll proceed with creating the database and then do checks next.",
"$",
"charset",
"=",
"'utf8mb4'",
";",
"if",
"(",
"isset",
"(",
"$",
"dboptions",
"[",
"'dbcollation'",
"]",
")",
"and",
"(",
"strpos",
"(",
"$",
"dboptions",
"[",
"'dbcollation'",
"]",
",",
"'utf8_'",
")",
"===",
"0",
"||",
"strpos",
"(",
"$",
"dboptions",
"[",
"'dbcollation'",
"]",
",",
"'utf8mb4_'",
")",
"===",
"0",
")",
")",
"{",
"$",
"collation",
"=",
"$",
"dboptions",
"[",
"'dbcollation'",
"]",
";",
"$",
"collationinfo",
"=",
"explode",
"(",
"'_'",
",",
"$",
"dboptions",
"[",
"'dbcollation'",
"]",
")",
";",
"$",
"charset",
"=",
"reset",
"(",
"$",
"collationinfo",
")",
";",
"}",
"else",
"{",
"$",
"collation",
"=",
"'utf8mb4_unicode_ci'",
";",
"}",
"$",
"result",
"=",
"$",
"conn",
"->",
"query",
"(",
"\"CREATE DATABASE $dbname DEFAULT CHARACTER SET $charset DEFAULT COLLATE \"",
".",
"$",
"collation",
")",
";",
"$",
"conn",
"->",
"close",
"(",
")",
";",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"throw",
"new",
"dml_exception",
"(",
"'cannotcreatedb'",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Attempt to create the database
@param string $dbhost
@param string $dbuser
@param string $dbpass
@param string $dbname
@return bool success
@throws dml_exception A DML specific exception is thrown for any errors.
|
[
"Attempt",
"to",
"create",
"the",
"database"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/mysqli_native_moodle_database.php#L56-L109
|
219,842
|
moodle/moodle
|
lib/dml/mysqli_native_moodle_database.php
|
mysqli_native_moodle_database.get_dbengine
|
public function get_dbengine() {
if (isset($this->dboptions['dbengine'])) {
return $this->dboptions['dbengine'];
}
if ($this->external) {
return null;
}
$engine = null;
// Look for current engine of our config table (the first table that gets created),
// so that we create all tables with the same engine.
$sql = "SELECT engine
FROM INFORMATION_SCHEMA.TABLES
WHERE table_schema = DATABASE() AND table_name = '{$this->prefix}config'";
$this->query_start($sql, NULL, SQL_QUERY_AUX);
$result = $this->mysqli->query($sql);
$this->query_end($result);
if ($rec = $result->fetch_assoc()) {
// MySQL 8 BC: information_schema.* returns the fields in upper case.
$rec = array_change_key_case($rec, CASE_LOWER);
$engine = $rec['engine'];
}
$result->close();
if ($engine) {
// Cache the result to improve performance.
$this->dboptions['dbengine'] = $engine;
return $engine;
}
// Get the default database engine.
$sql = "SELECT @@default_storage_engine engine";
$this->query_start($sql, NULL, SQL_QUERY_AUX);
$result = $this->mysqli->query($sql);
$this->query_end($result);
if ($rec = $result->fetch_assoc()) {
$engine = $rec['engine'];
}
$result->close();
if ($engine === 'MyISAM') {
// we really do not want MyISAM for Moodle, InnoDB or XtraDB is a reasonable defaults if supported
$sql = "SHOW STORAGE ENGINES";
$this->query_start($sql, NULL, SQL_QUERY_AUX);
$result = $this->mysqli->query($sql);
$this->query_end($result);
$engines = array();
while ($res = $result->fetch_assoc()) {
if ($res['Support'] === 'YES' or $res['Support'] === 'DEFAULT') {
$engines[$res['Engine']] = true;
}
}
$result->close();
if (isset($engines['InnoDB'])) {
$engine = 'InnoDB';
}
if (isset($engines['XtraDB'])) {
$engine = 'XtraDB';
}
}
// Cache the result to improve performance.
$this->dboptions['dbengine'] = $engine;
return $engine;
}
|
php
|
public function get_dbengine() {
if (isset($this->dboptions['dbengine'])) {
return $this->dboptions['dbengine'];
}
if ($this->external) {
return null;
}
$engine = null;
// Look for current engine of our config table (the first table that gets created),
// so that we create all tables with the same engine.
$sql = "SELECT engine
FROM INFORMATION_SCHEMA.TABLES
WHERE table_schema = DATABASE() AND table_name = '{$this->prefix}config'";
$this->query_start($sql, NULL, SQL_QUERY_AUX);
$result = $this->mysqli->query($sql);
$this->query_end($result);
if ($rec = $result->fetch_assoc()) {
// MySQL 8 BC: information_schema.* returns the fields in upper case.
$rec = array_change_key_case($rec, CASE_LOWER);
$engine = $rec['engine'];
}
$result->close();
if ($engine) {
// Cache the result to improve performance.
$this->dboptions['dbengine'] = $engine;
return $engine;
}
// Get the default database engine.
$sql = "SELECT @@default_storage_engine engine";
$this->query_start($sql, NULL, SQL_QUERY_AUX);
$result = $this->mysqli->query($sql);
$this->query_end($result);
if ($rec = $result->fetch_assoc()) {
$engine = $rec['engine'];
}
$result->close();
if ($engine === 'MyISAM') {
// we really do not want MyISAM for Moodle, InnoDB or XtraDB is a reasonable defaults if supported
$sql = "SHOW STORAGE ENGINES";
$this->query_start($sql, NULL, SQL_QUERY_AUX);
$result = $this->mysqli->query($sql);
$this->query_end($result);
$engines = array();
while ($res = $result->fetch_assoc()) {
if ($res['Support'] === 'YES' or $res['Support'] === 'DEFAULT') {
$engines[$res['Engine']] = true;
}
}
$result->close();
if (isset($engines['InnoDB'])) {
$engine = 'InnoDB';
}
if (isset($engines['XtraDB'])) {
$engine = 'XtraDB';
}
}
// Cache the result to improve performance.
$this->dboptions['dbengine'] = $engine;
return $engine;
}
|
[
"public",
"function",
"get_dbengine",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"dboptions",
"[",
"'dbengine'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"dboptions",
"[",
"'dbengine'",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"external",
")",
"{",
"return",
"null",
";",
"}",
"$",
"engine",
"=",
"null",
";",
"// Look for current engine of our config table (the first table that gets created),",
"// so that we create all tables with the same engine.",
"$",
"sql",
"=",
"\"SELECT engine\n FROM INFORMATION_SCHEMA.TABLES\n WHERE table_schema = DATABASE() AND table_name = '{$this->prefix}config'\"",
";",
"$",
"this",
"->",
"query_start",
"(",
"$",
"sql",
",",
"NULL",
",",
"SQL_QUERY_AUX",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"mysqli",
"->",
"query",
"(",
"$",
"sql",
")",
";",
"$",
"this",
"->",
"query_end",
"(",
"$",
"result",
")",
";",
"if",
"(",
"$",
"rec",
"=",
"$",
"result",
"->",
"fetch_assoc",
"(",
")",
")",
"{",
"// MySQL 8 BC: information_schema.* returns the fields in upper case.",
"$",
"rec",
"=",
"array_change_key_case",
"(",
"$",
"rec",
",",
"CASE_LOWER",
")",
";",
"$",
"engine",
"=",
"$",
"rec",
"[",
"'engine'",
"]",
";",
"}",
"$",
"result",
"->",
"close",
"(",
")",
";",
"if",
"(",
"$",
"engine",
")",
"{",
"// Cache the result to improve performance.",
"$",
"this",
"->",
"dboptions",
"[",
"'dbengine'",
"]",
"=",
"$",
"engine",
";",
"return",
"$",
"engine",
";",
"}",
"// Get the default database engine.",
"$",
"sql",
"=",
"\"SELECT @@default_storage_engine engine\"",
";",
"$",
"this",
"->",
"query_start",
"(",
"$",
"sql",
",",
"NULL",
",",
"SQL_QUERY_AUX",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"mysqli",
"->",
"query",
"(",
"$",
"sql",
")",
";",
"$",
"this",
"->",
"query_end",
"(",
"$",
"result",
")",
";",
"if",
"(",
"$",
"rec",
"=",
"$",
"result",
"->",
"fetch_assoc",
"(",
")",
")",
"{",
"$",
"engine",
"=",
"$",
"rec",
"[",
"'engine'",
"]",
";",
"}",
"$",
"result",
"->",
"close",
"(",
")",
";",
"if",
"(",
"$",
"engine",
"===",
"'MyISAM'",
")",
"{",
"// we really do not want MyISAM for Moodle, InnoDB or XtraDB is a reasonable defaults if supported",
"$",
"sql",
"=",
"\"SHOW STORAGE ENGINES\"",
";",
"$",
"this",
"->",
"query_start",
"(",
"$",
"sql",
",",
"NULL",
",",
"SQL_QUERY_AUX",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"mysqli",
"->",
"query",
"(",
"$",
"sql",
")",
";",
"$",
"this",
"->",
"query_end",
"(",
"$",
"result",
")",
";",
"$",
"engines",
"=",
"array",
"(",
")",
";",
"while",
"(",
"$",
"res",
"=",
"$",
"result",
"->",
"fetch_assoc",
"(",
")",
")",
"{",
"if",
"(",
"$",
"res",
"[",
"'Support'",
"]",
"===",
"'YES'",
"or",
"$",
"res",
"[",
"'Support'",
"]",
"===",
"'DEFAULT'",
")",
"{",
"$",
"engines",
"[",
"$",
"res",
"[",
"'Engine'",
"]",
"]",
"=",
"true",
";",
"}",
"}",
"$",
"result",
"->",
"close",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"engines",
"[",
"'InnoDB'",
"]",
")",
")",
"{",
"$",
"engine",
"=",
"'InnoDB'",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"engines",
"[",
"'XtraDB'",
"]",
")",
")",
"{",
"$",
"engine",
"=",
"'XtraDB'",
";",
"}",
"}",
"// Cache the result to improve performance.",
"$",
"this",
"->",
"dboptions",
"[",
"'dbengine'",
"]",
"=",
"$",
"engine",
";",
"return",
"$",
"engine",
";",
"}"
] |
Returns the current MySQL db engine.
This is an ugly workaround for MySQL default engine problems,
Moodle is designed to work best on ACID compliant databases
with full transaction support. Do not use MyISAM.
@return string or null MySQL engine name
|
[
"Returns",
"the",
"current",
"MySQL",
"db",
"engine",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/mysqli_native_moodle_database.php#L159-L225
|
219,843
|
moodle/moodle
|
lib/dml/mysqli_native_moodle_database.php
|
mysqli_native_moodle_database.get_dbcollation
|
public function get_dbcollation() {
if (isset($this->dboptions['dbcollation'])) {
return $this->dboptions['dbcollation'];
}
if ($this->external) {
return null;
}
$collation = null;
// Look for current collation of our config table (the first table that gets created),
// so that we create all tables with the same collation.
$sql = "SELECT collation_name
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_schema = DATABASE() AND table_name = '{$this->prefix}config' AND column_name = 'value'";
$this->query_start($sql, NULL, SQL_QUERY_AUX);
$result = $this->mysqli->query($sql);
$this->query_end($result);
if ($rec = $result->fetch_assoc()) {
// MySQL 8 BC: information_schema.* returns the fields in upper case.
$rec = array_change_key_case($rec, CASE_LOWER);
$collation = $rec['collation_name'];
}
$result->close();
if (!$collation) {
// Get the default database collation, but only if using UTF-8.
$sql = "SELECT @@collation_database";
$this->query_start($sql, NULL, SQL_QUERY_AUX);
$result = $this->mysqli->query($sql);
$this->query_end($result);
if ($rec = $result->fetch_assoc()) {
if (strpos($rec['@@collation_database'], 'utf8_') === 0 || strpos($rec['@@collation_database'], 'utf8mb4_') === 0) {
$collation = $rec['@@collation_database'];
}
}
$result->close();
}
if (!$collation) {
// We want only utf8 compatible collations.
$collation = null;
$sql = "SHOW COLLATION WHERE Collation LIKE 'utf8mb4\_%' AND Charset = 'utf8mb4'";
$this->query_start($sql, NULL, SQL_QUERY_AUX);
$result = $this->mysqli->query($sql);
$this->query_end($result);
while ($res = $result->fetch_assoc()) {
$collation = $res['Collation'];
if (strtoupper($res['Default']) === 'YES') {
$collation = $res['Collation'];
break;
}
}
$result->close();
}
// Cache the result to improve performance.
$this->dboptions['dbcollation'] = $collation;
return $collation;
}
|
php
|
public function get_dbcollation() {
if (isset($this->dboptions['dbcollation'])) {
return $this->dboptions['dbcollation'];
}
if ($this->external) {
return null;
}
$collation = null;
// Look for current collation of our config table (the first table that gets created),
// so that we create all tables with the same collation.
$sql = "SELECT collation_name
FROM INFORMATION_SCHEMA.COLUMNS
WHERE table_schema = DATABASE() AND table_name = '{$this->prefix}config' AND column_name = 'value'";
$this->query_start($sql, NULL, SQL_QUERY_AUX);
$result = $this->mysqli->query($sql);
$this->query_end($result);
if ($rec = $result->fetch_assoc()) {
// MySQL 8 BC: information_schema.* returns the fields in upper case.
$rec = array_change_key_case($rec, CASE_LOWER);
$collation = $rec['collation_name'];
}
$result->close();
if (!$collation) {
// Get the default database collation, but only if using UTF-8.
$sql = "SELECT @@collation_database";
$this->query_start($sql, NULL, SQL_QUERY_AUX);
$result = $this->mysqli->query($sql);
$this->query_end($result);
if ($rec = $result->fetch_assoc()) {
if (strpos($rec['@@collation_database'], 'utf8_') === 0 || strpos($rec['@@collation_database'], 'utf8mb4_') === 0) {
$collation = $rec['@@collation_database'];
}
}
$result->close();
}
if (!$collation) {
// We want only utf8 compatible collations.
$collation = null;
$sql = "SHOW COLLATION WHERE Collation LIKE 'utf8mb4\_%' AND Charset = 'utf8mb4'";
$this->query_start($sql, NULL, SQL_QUERY_AUX);
$result = $this->mysqli->query($sql);
$this->query_end($result);
while ($res = $result->fetch_assoc()) {
$collation = $res['Collation'];
if (strtoupper($res['Default']) === 'YES') {
$collation = $res['Collation'];
break;
}
}
$result->close();
}
// Cache the result to improve performance.
$this->dboptions['dbcollation'] = $collation;
return $collation;
}
|
[
"public",
"function",
"get_dbcollation",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"dboptions",
"[",
"'dbcollation'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"dboptions",
"[",
"'dbcollation'",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"external",
")",
"{",
"return",
"null",
";",
"}",
"$",
"collation",
"=",
"null",
";",
"// Look for current collation of our config table (the first table that gets created),",
"// so that we create all tables with the same collation.",
"$",
"sql",
"=",
"\"SELECT collation_name\n FROM INFORMATION_SCHEMA.COLUMNS\n WHERE table_schema = DATABASE() AND table_name = '{$this->prefix}config' AND column_name = 'value'\"",
";",
"$",
"this",
"->",
"query_start",
"(",
"$",
"sql",
",",
"NULL",
",",
"SQL_QUERY_AUX",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"mysqli",
"->",
"query",
"(",
"$",
"sql",
")",
";",
"$",
"this",
"->",
"query_end",
"(",
"$",
"result",
")",
";",
"if",
"(",
"$",
"rec",
"=",
"$",
"result",
"->",
"fetch_assoc",
"(",
")",
")",
"{",
"// MySQL 8 BC: information_schema.* returns the fields in upper case.",
"$",
"rec",
"=",
"array_change_key_case",
"(",
"$",
"rec",
",",
"CASE_LOWER",
")",
";",
"$",
"collation",
"=",
"$",
"rec",
"[",
"'collation_name'",
"]",
";",
"}",
"$",
"result",
"->",
"close",
"(",
")",
";",
"if",
"(",
"!",
"$",
"collation",
")",
"{",
"// Get the default database collation, but only if using UTF-8.",
"$",
"sql",
"=",
"\"SELECT @@collation_database\"",
";",
"$",
"this",
"->",
"query_start",
"(",
"$",
"sql",
",",
"NULL",
",",
"SQL_QUERY_AUX",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"mysqli",
"->",
"query",
"(",
"$",
"sql",
")",
";",
"$",
"this",
"->",
"query_end",
"(",
"$",
"result",
")",
";",
"if",
"(",
"$",
"rec",
"=",
"$",
"result",
"->",
"fetch_assoc",
"(",
")",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"rec",
"[",
"'@@collation_database'",
"]",
",",
"'utf8_'",
")",
"===",
"0",
"||",
"strpos",
"(",
"$",
"rec",
"[",
"'@@collation_database'",
"]",
",",
"'utf8mb4_'",
")",
"===",
"0",
")",
"{",
"$",
"collation",
"=",
"$",
"rec",
"[",
"'@@collation_database'",
"]",
";",
"}",
"}",
"$",
"result",
"->",
"close",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"collation",
")",
"{",
"// We want only utf8 compatible collations.",
"$",
"collation",
"=",
"null",
";",
"$",
"sql",
"=",
"\"SHOW COLLATION WHERE Collation LIKE 'utf8mb4\\_%' AND Charset = 'utf8mb4'\"",
";",
"$",
"this",
"->",
"query_start",
"(",
"$",
"sql",
",",
"NULL",
",",
"SQL_QUERY_AUX",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"mysqli",
"->",
"query",
"(",
"$",
"sql",
")",
";",
"$",
"this",
"->",
"query_end",
"(",
"$",
"result",
")",
";",
"while",
"(",
"$",
"res",
"=",
"$",
"result",
"->",
"fetch_assoc",
"(",
")",
")",
"{",
"$",
"collation",
"=",
"$",
"res",
"[",
"'Collation'",
"]",
";",
"if",
"(",
"strtoupper",
"(",
"$",
"res",
"[",
"'Default'",
"]",
")",
"===",
"'YES'",
")",
"{",
"$",
"collation",
"=",
"$",
"res",
"[",
"'Collation'",
"]",
";",
"break",
";",
"}",
"}",
"$",
"result",
"->",
"close",
"(",
")",
";",
"}",
"// Cache the result to improve performance.",
"$",
"this",
"->",
"dboptions",
"[",
"'dbcollation'",
"]",
"=",
"$",
"collation",
";",
"return",
"$",
"collation",
";",
"}"
] |
Returns the current MySQL db collation.
This is an ugly workaround for MySQL default collation problems.
@return string or null MySQL collation name
|
[
"Returns",
"the",
"current",
"MySQL",
"db",
"collation",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/mysqli_native_moodle_database.php#L234-L294
|
219,844
|
moodle/moodle
|
lib/dml/mysqli_native_moodle_database.php
|
mysqli_native_moodle_database.get_row_format
|
public function get_row_format($table = null) {
$rowformat = null;
if (isset($table)) {
$table = $this->mysqli->real_escape_string($table);
$sql = "SELECT row_format
FROM INFORMATION_SCHEMA.TABLES
WHERE table_schema = DATABASE() AND table_name = '{$this->prefix}$table'";
} else {
if ($this->is_antelope_file_format_no_more_supported()) {
// Breaking change: Antelope file format support has been removed, only Barracuda.
$dbengine = $this->get_dbengine();
$supporteddbengines = array('InnoDB', 'XtraDB');
if (in_array($dbengine, $supporteddbengines)) {
$rowformat = 'Barracuda';
}
return $rowformat;
}
$sql = "SHOW VARIABLES LIKE 'innodb_file_format'";
}
$this->query_start($sql, NULL, SQL_QUERY_AUX);
$result = $this->mysqli->query($sql);
$this->query_end($result);
if ($rec = $result->fetch_assoc()) {
// MySQL 8 BC: information_schema.* returns the fields in upper case.
$rec = array_change_key_case($rec, CASE_LOWER);
if (isset($table)) {
$rowformat = $rec['row_format'];
} else {
$rowformat = $rec['value'];
}
}
$result->close();
return $rowformat;
}
|
php
|
public function get_row_format($table = null) {
$rowformat = null;
if (isset($table)) {
$table = $this->mysqli->real_escape_string($table);
$sql = "SELECT row_format
FROM INFORMATION_SCHEMA.TABLES
WHERE table_schema = DATABASE() AND table_name = '{$this->prefix}$table'";
} else {
if ($this->is_antelope_file_format_no_more_supported()) {
// Breaking change: Antelope file format support has been removed, only Barracuda.
$dbengine = $this->get_dbengine();
$supporteddbengines = array('InnoDB', 'XtraDB');
if (in_array($dbengine, $supporteddbengines)) {
$rowformat = 'Barracuda';
}
return $rowformat;
}
$sql = "SHOW VARIABLES LIKE 'innodb_file_format'";
}
$this->query_start($sql, NULL, SQL_QUERY_AUX);
$result = $this->mysqli->query($sql);
$this->query_end($result);
if ($rec = $result->fetch_assoc()) {
// MySQL 8 BC: information_schema.* returns the fields in upper case.
$rec = array_change_key_case($rec, CASE_LOWER);
if (isset($table)) {
$rowformat = $rec['row_format'];
} else {
$rowformat = $rec['value'];
}
}
$result->close();
return $rowformat;
}
|
[
"public",
"function",
"get_row_format",
"(",
"$",
"table",
"=",
"null",
")",
"{",
"$",
"rowformat",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"table",
")",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"mysqli",
"->",
"real_escape_string",
"(",
"$",
"table",
")",
";",
"$",
"sql",
"=",
"\"SELECT row_format\n FROM INFORMATION_SCHEMA.TABLES\n WHERE table_schema = DATABASE() AND table_name = '{$this->prefix}$table'\"",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"is_antelope_file_format_no_more_supported",
"(",
")",
")",
"{",
"// Breaking change: Antelope file format support has been removed, only Barracuda.",
"$",
"dbengine",
"=",
"$",
"this",
"->",
"get_dbengine",
"(",
")",
";",
"$",
"supporteddbengines",
"=",
"array",
"(",
"'InnoDB'",
",",
"'XtraDB'",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"dbengine",
",",
"$",
"supporteddbengines",
")",
")",
"{",
"$",
"rowformat",
"=",
"'Barracuda'",
";",
"}",
"return",
"$",
"rowformat",
";",
"}",
"$",
"sql",
"=",
"\"SHOW VARIABLES LIKE 'innodb_file_format'\"",
";",
"}",
"$",
"this",
"->",
"query_start",
"(",
"$",
"sql",
",",
"NULL",
",",
"SQL_QUERY_AUX",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"mysqli",
"->",
"query",
"(",
"$",
"sql",
")",
";",
"$",
"this",
"->",
"query_end",
"(",
"$",
"result",
")",
";",
"if",
"(",
"$",
"rec",
"=",
"$",
"result",
"->",
"fetch_assoc",
"(",
")",
")",
"{",
"// MySQL 8 BC: information_schema.* returns the fields in upper case.",
"$",
"rec",
"=",
"array_change_key_case",
"(",
"$",
"rec",
",",
"CASE_LOWER",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"table",
")",
")",
"{",
"$",
"rowformat",
"=",
"$",
"rec",
"[",
"'row_format'",
"]",
";",
"}",
"else",
"{",
"$",
"rowformat",
"=",
"$",
"rec",
"[",
"'value'",
"]",
";",
"}",
"}",
"$",
"result",
"->",
"close",
"(",
")",
";",
"return",
"$",
"rowformat",
";",
"}"
] |
Get the row format from the database schema.
@param string $table
@return string row_format name or null if not known or table does not exist.
|
[
"Get",
"the",
"row",
"format",
"from",
"the",
"database",
"schema",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/mysqli_native_moodle_database.php#L325-L361
|
219,845
|
moodle/moodle
|
lib/dml/mysqli_native_moodle_database.php
|
mysqli_native_moodle_database.is_large_prefix_enabled
|
public function is_large_prefix_enabled() {
if ($this->is_antelope_file_format_no_more_supported()) {
// Breaking change: Antelope file format support has been removed, only Barracuda.
return true;
}
if ($largeprefix = $this->get_record_sql("SHOW VARIABLES LIKE 'innodb_large_prefix'")) {
if ($largeprefix->value == 'ON') {
return true;
}
}
return false;
}
|
php
|
public function is_large_prefix_enabled() {
if ($this->is_antelope_file_format_no_more_supported()) {
// Breaking change: Antelope file format support has been removed, only Barracuda.
return true;
}
if ($largeprefix = $this->get_record_sql("SHOW VARIABLES LIKE 'innodb_large_prefix'")) {
if ($largeprefix->value == 'ON') {
return true;
}
}
return false;
}
|
[
"public",
"function",
"is_large_prefix_enabled",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"is_antelope_file_format_no_more_supported",
"(",
")",
")",
"{",
"// Breaking change: Antelope file format support has been removed, only Barracuda.",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"largeprefix",
"=",
"$",
"this",
"->",
"get_record_sql",
"(",
"\"SHOW VARIABLES LIKE 'innodb_large_prefix'\"",
")",
")",
"{",
"if",
"(",
"$",
"largeprefix",
"->",
"value",
"==",
"'ON'",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Check the database to see if innodb_large_prefix is on.
@return bool True if on otherwise false.
|
[
"Check",
"the",
"database",
"to",
"see",
"if",
"innodb_large_prefix",
"is",
"on",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/mysqli_native_moodle_database.php#L420-L432
|
219,846
|
moodle/moodle
|
lib/dml/mysqli_native_moodle_database.php
|
mysqli_native_moodle_database.get_row_format_sql
|
public function get_row_format_sql($engine = null, $collation = null) {
if (!isset($engine)) {
$engine = $this->get_dbengine();
}
$engine = strtolower($engine);
if (!isset($collation)) {
$collation = $this->get_dbcollation();
}
$rowformat = '';
if (($engine === 'innodb' || $engine === 'xtradb') && strpos($collation, 'utf8mb4_') === 0) {
if ($this->is_compressed_row_format_supported()) {
$rowformat = "ROW_FORMAT=Compressed";
} else {
$rowformat = "ROW_FORMAT=Dynamic";
}
}
return $rowformat;
}
|
php
|
public function get_row_format_sql($engine = null, $collation = null) {
if (!isset($engine)) {
$engine = $this->get_dbengine();
}
$engine = strtolower($engine);
if (!isset($collation)) {
$collation = $this->get_dbcollation();
}
$rowformat = '';
if (($engine === 'innodb' || $engine === 'xtradb') && strpos($collation, 'utf8mb4_') === 0) {
if ($this->is_compressed_row_format_supported()) {
$rowformat = "ROW_FORMAT=Compressed";
} else {
$rowformat = "ROW_FORMAT=Dynamic";
}
}
return $rowformat;
}
|
[
"public",
"function",
"get_row_format_sql",
"(",
"$",
"engine",
"=",
"null",
",",
"$",
"collation",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"engine",
")",
")",
"{",
"$",
"engine",
"=",
"$",
"this",
"->",
"get_dbengine",
"(",
")",
";",
"}",
"$",
"engine",
"=",
"strtolower",
"(",
"$",
"engine",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"collation",
")",
")",
"{",
"$",
"collation",
"=",
"$",
"this",
"->",
"get_dbcollation",
"(",
")",
";",
"}",
"$",
"rowformat",
"=",
"''",
";",
"if",
"(",
"(",
"$",
"engine",
"===",
"'innodb'",
"||",
"$",
"engine",
"===",
"'xtradb'",
")",
"&&",
"strpos",
"(",
"$",
"collation",
",",
"'utf8mb4_'",
")",
"===",
"0",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"is_compressed_row_format_supported",
"(",
")",
")",
"{",
"$",
"rowformat",
"=",
"\"ROW_FORMAT=Compressed\"",
";",
"}",
"else",
"{",
"$",
"rowformat",
"=",
"\"ROW_FORMAT=Dynamic\"",
";",
"}",
"}",
"return",
"$",
"rowformat",
";",
"}"
] |
Determine if the row format should be set to compressed, dynamic, or default.
Terrible kludge. If we're using utf8mb4 AND we're using InnoDB, we need to specify row format to
be either dynamic or compressed (default is compact) in order to allow for bigger indexes (MySQL
errors #1709 and #1071).
@param string $engine The database engine being used. Will be looked up if not supplied.
@param string $collation The database collation to use. Will look up the current collation if not supplied.
@return string An sql fragment to add to sql statements.
|
[
"Determine",
"if",
"the",
"row",
"format",
"should",
"be",
"set",
"to",
"compressed",
"dynamic",
"or",
"default",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/mysqli_native_moodle_database.php#L445-L465
|
219,847
|
moodle/moodle
|
lib/dml/mysqli_native_moodle_database.php
|
mysqli_native_moodle_database.mysqltype2moodletype
|
private function mysqltype2moodletype($mysql_type) {
$type = null;
switch(strtoupper($mysql_type)) {
case 'BIT':
$type = 'L';
break;
case 'TINYINT':
case 'SMALLINT':
case 'MEDIUMINT':
case 'INT':
case 'INTEGER':
case 'BIGINT':
$type = 'I';
break;
case 'FLOAT':
case 'DOUBLE':
case 'DECIMAL':
$type = 'N';
break;
case 'CHAR':
case 'ENUM':
case 'SET':
case 'VARCHAR':
$type = 'C';
break;
case 'TINYTEXT':
case 'TEXT':
case 'MEDIUMTEXT':
case 'LONGTEXT':
$type = 'X';
break;
case 'BINARY':
case 'VARBINARY':
case 'BLOB':
case 'TINYBLOB':
case 'MEDIUMBLOB':
case 'LONGBLOB':
$type = 'B';
break;
case 'DATE':
case 'TIME':
case 'DATETIME':
case 'TIMESTAMP':
case 'YEAR':
$type = 'D';
break;
}
if (!$type) {
throw new dml_exception('invalidmysqlnativetype', $mysql_type);
}
return $type;
}
|
php
|
private function mysqltype2moodletype($mysql_type) {
$type = null;
switch(strtoupper($mysql_type)) {
case 'BIT':
$type = 'L';
break;
case 'TINYINT':
case 'SMALLINT':
case 'MEDIUMINT':
case 'INT':
case 'INTEGER':
case 'BIGINT':
$type = 'I';
break;
case 'FLOAT':
case 'DOUBLE':
case 'DECIMAL':
$type = 'N';
break;
case 'CHAR':
case 'ENUM':
case 'SET':
case 'VARCHAR':
$type = 'C';
break;
case 'TINYTEXT':
case 'TEXT':
case 'MEDIUMTEXT':
case 'LONGTEXT':
$type = 'X';
break;
case 'BINARY':
case 'VARBINARY':
case 'BLOB':
case 'TINYBLOB':
case 'MEDIUMBLOB':
case 'LONGBLOB':
$type = 'B';
break;
case 'DATE':
case 'TIME':
case 'DATETIME':
case 'TIMESTAMP':
case 'YEAR':
$type = 'D';
break;
}
if (!$type) {
throw new dml_exception('invalidmysqlnativetype', $mysql_type);
}
return $type;
}
|
[
"private",
"function",
"mysqltype2moodletype",
"(",
"$",
"mysql_type",
")",
"{",
"$",
"type",
"=",
"null",
";",
"switch",
"(",
"strtoupper",
"(",
"$",
"mysql_type",
")",
")",
"{",
"case",
"'BIT'",
":",
"$",
"type",
"=",
"'L'",
";",
"break",
";",
"case",
"'TINYINT'",
":",
"case",
"'SMALLINT'",
":",
"case",
"'MEDIUMINT'",
":",
"case",
"'INT'",
":",
"case",
"'INTEGER'",
":",
"case",
"'BIGINT'",
":",
"$",
"type",
"=",
"'I'",
";",
"break",
";",
"case",
"'FLOAT'",
":",
"case",
"'DOUBLE'",
":",
"case",
"'DECIMAL'",
":",
"$",
"type",
"=",
"'N'",
";",
"break",
";",
"case",
"'CHAR'",
":",
"case",
"'ENUM'",
":",
"case",
"'SET'",
":",
"case",
"'VARCHAR'",
":",
"$",
"type",
"=",
"'C'",
";",
"break",
";",
"case",
"'TINYTEXT'",
":",
"case",
"'TEXT'",
":",
"case",
"'MEDIUMTEXT'",
":",
"case",
"'LONGTEXT'",
":",
"$",
"type",
"=",
"'X'",
";",
"break",
";",
"case",
"'BINARY'",
":",
"case",
"'VARBINARY'",
":",
"case",
"'BLOB'",
":",
"case",
"'TINYBLOB'",
":",
"case",
"'MEDIUMBLOB'",
":",
"case",
"'LONGBLOB'",
":",
"$",
"type",
"=",
"'B'",
";",
"break",
";",
"case",
"'DATE'",
":",
"case",
"'TIME'",
":",
"case",
"'DATETIME'",
":",
"case",
"'TIMESTAMP'",
":",
"case",
"'YEAR'",
":",
"$",
"type",
"=",
"'D'",
";",
"break",
";",
"}",
"if",
"(",
"!",
"$",
"type",
")",
"{",
"throw",
"new",
"dml_exception",
"(",
"'invalidmysqlnativetype'",
",",
"$",
"mysql_type",
")",
";",
"}",
"return",
"$",
"type",
";",
"}"
] |
Normalise column type.
@param string $mysql_type
@return string one character
@throws dml_exception
|
[
"Normalise",
"column",
"type",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/mysqli_native_moodle_database.php#L941-L1000
|
219,848
|
moodle/moodle
|
lib/dml/mysqli_native_moodle_database.php
|
mysqli_native_moodle_database.setup_is_unicodedb
|
public function setup_is_unicodedb() {
// All new tables are created with this collation, we just have to make sure it is utf8 compatible,
// if config table already exists it has this collation too.
$collation = $this->get_dbcollation();
$collationinfo = explode('_', $collation);
$charset = reset($collationinfo);
$sql = "SHOW COLLATION WHERE Collation ='$collation' AND Charset = '$charset'";
$this->query_start($sql, NULL, SQL_QUERY_AUX);
$result = $this->mysqli->query($sql);
$this->query_end($result);
if ($result->fetch_assoc()) {
$return = true;
} else {
$return = false;
}
$result->close();
return $return;
}
|
php
|
public function setup_is_unicodedb() {
// All new tables are created with this collation, we just have to make sure it is utf8 compatible,
// if config table already exists it has this collation too.
$collation = $this->get_dbcollation();
$collationinfo = explode('_', $collation);
$charset = reset($collationinfo);
$sql = "SHOW COLLATION WHERE Collation ='$collation' AND Charset = '$charset'";
$this->query_start($sql, NULL, SQL_QUERY_AUX);
$result = $this->mysqli->query($sql);
$this->query_end($result);
if ($result->fetch_assoc()) {
$return = true;
} else {
$return = false;
}
$result->close();
return $return;
}
|
[
"public",
"function",
"setup_is_unicodedb",
"(",
")",
"{",
"// All new tables are created with this collation, we just have to make sure it is utf8 compatible,",
"// if config table already exists it has this collation too.",
"$",
"collation",
"=",
"$",
"this",
"->",
"get_dbcollation",
"(",
")",
";",
"$",
"collationinfo",
"=",
"explode",
"(",
"'_'",
",",
"$",
"collation",
")",
";",
"$",
"charset",
"=",
"reset",
"(",
"$",
"collationinfo",
")",
";",
"$",
"sql",
"=",
"\"SHOW COLLATION WHERE Collation ='$collation' AND Charset = '$charset'\"",
";",
"$",
"this",
"->",
"query_start",
"(",
"$",
"sql",
",",
"NULL",
",",
"SQL_QUERY_AUX",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"mysqli",
"->",
"query",
"(",
"$",
"sql",
")",
";",
"$",
"this",
"->",
"query_end",
"(",
"$",
"result",
")",
";",
"if",
"(",
"$",
"result",
"->",
"fetch_assoc",
"(",
")",
")",
"{",
"$",
"return",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"return",
"=",
"false",
";",
"}",
"$",
"result",
"->",
"close",
"(",
")",
";",
"return",
"$",
"return",
";",
"}"
] |
Is this database compatible with utf8?
@return bool
|
[
"Is",
"this",
"database",
"compatible",
"with",
"utf8?"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/mysqli_native_moodle_database.php#L1031-L1051
|
219,849
|
moodle/moodle
|
lib/dml/mysqli_native_moodle_database.php
|
mysqli_native_moodle_database.emulate_bound_params
|
protected function emulate_bound_params($sql, array $params=null) {
if (empty($params)) {
return $sql;
}
// ok, we have verified sql statement with ? and correct number of params
$parts = array_reverse(explode('?', $sql));
$return = array_pop($parts);
foreach ($params as $param) {
if (is_bool($param)) {
$return .= (int)$param;
} else if (is_null($param)) {
$return .= 'NULL';
} else if (is_number($param)) {
$return .= "'".$param."'"; // we have to always use strings because mysql is using weird automatic int casting
} else if (is_float($param)) {
$return .= $param;
} else {
$param = $this->mysqli->real_escape_string($param);
$return .= "'$param'";
}
$return .= array_pop($parts);
}
return $return;
}
|
php
|
protected function emulate_bound_params($sql, array $params=null) {
if (empty($params)) {
return $sql;
}
// ok, we have verified sql statement with ? and correct number of params
$parts = array_reverse(explode('?', $sql));
$return = array_pop($parts);
foreach ($params as $param) {
if (is_bool($param)) {
$return .= (int)$param;
} else if (is_null($param)) {
$return .= 'NULL';
} else if (is_number($param)) {
$return .= "'".$param."'"; // we have to always use strings because mysql is using weird automatic int casting
} else if (is_float($param)) {
$return .= $param;
} else {
$param = $this->mysqli->real_escape_string($param);
$return .= "'$param'";
}
$return .= array_pop($parts);
}
return $return;
}
|
[
"protected",
"function",
"emulate_bound_params",
"(",
"$",
"sql",
",",
"array",
"$",
"params",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"params",
")",
")",
"{",
"return",
"$",
"sql",
";",
"}",
"// ok, we have verified sql statement with ? and correct number of params",
"$",
"parts",
"=",
"array_reverse",
"(",
"explode",
"(",
"'?'",
",",
"$",
"sql",
")",
")",
";",
"$",
"return",
"=",
"array_pop",
"(",
"$",
"parts",
")",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"param",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"param",
")",
")",
"{",
"$",
"return",
".=",
"(",
"int",
")",
"$",
"param",
";",
"}",
"else",
"if",
"(",
"is_null",
"(",
"$",
"param",
")",
")",
"{",
"$",
"return",
".=",
"'NULL'",
";",
"}",
"else",
"if",
"(",
"is_number",
"(",
"$",
"param",
")",
")",
"{",
"$",
"return",
".=",
"\"'\"",
".",
"$",
"param",
".",
"\"'\"",
";",
"// we have to always use strings because mysql is using weird automatic int casting",
"}",
"else",
"if",
"(",
"is_float",
"(",
"$",
"param",
")",
")",
"{",
"$",
"return",
".=",
"$",
"param",
";",
"}",
"else",
"{",
"$",
"param",
"=",
"$",
"this",
"->",
"mysqli",
"->",
"real_escape_string",
"(",
"$",
"param",
")",
";",
"$",
"return",
".=",
"\"'$param'\"",
";",
"}",
"$",
"return",
".=",
"array_pop",
"(",
"$",
"parts",
")",
";",
"}",
"return",
"$",
"return",
";",
"}"
] |
Very ugly hack which emulates bound parameters in queries
because prepared statements do not use query cache.
|
[
"Very",
"ugly",
"hack",
"which",
"emulates",
"bound",
"parameters",
"in",
"queries",
"because",
"prepared",
"statements",
"do",
"not",
"use",
"query",
"cache",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/mysqli_native_moodle_database.php#L1095-L1118
|
219,850
|
moodle/moodle
|
lib/dml/mysqli_native_moodle_database.php
|
mysqli_native_moodle_database.export_table_recordset
|
public function export_table_recordset($table) {
$sql = $this->fix_table_names("SELECT * FROM {{$table}}");
$this->query_start($sql, array(), SQL_QUERY_SELECT);
// MYSQLI_STORE_RESULT may eat all memory for large tables, unfortunately MYSQLI_USE_RESULT blocks other queries.
$result = $this->mysqli->query($sql, MYSQLI_USE_RESULT);
$this->query_end($result);
return $this->create_recordset($result);
}
|
php
|
public function export_table_recordset($table) {
$sql = $this->fix_table_names("SELECT * FROM {{$table}}");
$this->query_start($sql, array(), SQL_QUERY_SELECT);
// MYSQLI_STORE_RESULT may eat all memory for large tables, unfortunately MYSQLI_USE_RESULT blocks other queries.
$result = $this->mysqli->query($sql, MYSQLI_USE_RESULT);
$this->query_end($result);
return $this->create_recordset($result);
}
|
[
"public",
"function",
"export_table_recordset",
"(",
"$",
"table",
")",
"{",
"$",
"sql",
"=",
"$",
"this",
"->",
"fix_table_names",
"(",
"\"SELECT * FROM {{$table}}\"",
")",
";",
"$",
"this",
"->",
"query_start",
"(",
"$",
"sql",
",",
"array",
"(",
")",
",",
"SQL_QUERY_SELECT",
")",
";",
"// MYSQLI_STORE_RESULT may eat all memory for large tables, unfortunately MYSQLI_USE_RESULT blocks other queries.",
"$",
"result",
"=",
"$",
"this",
"->",
"mysqli",
"->",
"query",
"(",
"$",
"sql",
",",
"MYSQLI_USE_RESULT",
")",
";",
"$",
"this",
"->",
"query_end",
"(",
"$",
"result",
")",
";",
"return",
"$",
"this",
"->",
"create_recordset",
"(",
"$",
"result",
")",
";",
"}"
] |
Get all records from a table.
This method works around potential memory problems and may improve performance,
this method may block access to table until the recordset is closed.
@param string $table Name of database table.
@return moodle_recordset A moodle_recordset instance {@link function get_recordset}.
@throws dml_exception A DML specific exception is thrown for any errors.
|
[
"Get",
"all",
"records",
"from",
"a",
"table",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/mysqli_native_moodle_database.php#L1199-L1208
|
219,851
|
moodle/moodle
|
lib/dml/mysqli_native_moodle_database.php
|
mysqli_native_moodle_database.insert_chunk
|
protected function insert_chunk($table, array $chunk, array $columns) {
$fieldssql = '('.implode(',', array_keys($columns)).')';
$valuessql = '('.implode(',', array_fill(0, count($columns), '?')).')';
$valuessql = implode(',', array_fill(0, count($chunk), $valuessql));
$params = array();
foreach ($chunk as $dataobject) {
foreach ($columns as $field => $column) {
$params[] = $this->normalise_value($column, $dataobject[$field]);
}
}
$sql = "INSERT INTO {$this->prefix}$table $fieldssql VALUES $valuessql";
list($sql, $params, $type) = $this->fix_sql_params($sql, $params);
$rawsql = $this->emulate_bound_params($sql, $params);
$this->query_start($sql, $params, SQL_QUERY_INSERT);
$result = $this->mysqli->query($rawsql);
$this->query_end($result);
}
|
php
|
protected function insert_chunk($table, array $chunk, array $columns) {
$fieldssql = '('.implode(',', array_keys($columns)).')';
$valuessql = '('.implode(',', array_fill(0, count($columns), '?')).')';
$valuessql = implode(',', array_fill(0, count($chunk), $valuessql));
$params = array();
foreach ($chunk as $dataobject) {
foreach ($columns as $field => $column) {
$params[] = $this->normalise_value($column, $dataobject[$field]);
}
}
$sql = "INSERT INTO {$this->prefix}$table $fieldssql VALUES $valuessql";
list($sql, $params, $type) = $this->fix_sql_params($sql, $params);
$rawsql = $this->emulate_bound_params($sql, $params);
$this->query_start($sql, $params, SQL_QUERY_INSERT);
$result = $this->mysqli->query($rawsql);
$this->query_end($result);
}
|
[
"protected",
"function",
"insert_chunk",
"(",
"$",
"table",
",",
"array",
"$",
"chunk",
",",
"array",
"$",
"columns",
")",
"{",
"$",
"fieldssql",
"=",
"'('",
".",
"implode",
"(",
"','",
",",
"array_keys",
"(",
"$",
"columns",
")",
")",
".",
"')'",
";",
"$",
"valuessql",
"=",
"'('",
".",
"implode",
"(",
"','",
",",
"array_fill",
"(",
"0",
",",
"count",
"(",
"$",
"columns",
")",
",",
"'?'",
")",
")",
".",
"')'",
";",
"$",
"valuessql",
"=",
"implode",
"(",
"','",
",",
"array_fill",
"(",
"0",
",",
"count",
"(",
"$",
"chunk",
")",
",",
"$",
"valuessql",
")",
")",
";",
"$",
"params",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"chunk",
"as",
"$",
"dataobject",
")",
"{",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"field",
"=>",
"$",
"column",
")",
"{",
"$",
"params",
"[",
"]",
"=",
"$",
"this",
"->",
"normalise_value",
"(",
"$",
"column",
",",
"$",
"dataobject",
"[",
"$",
"field",
"]",
")",
";",
"}",
"}",
"$",
"sql",
"=",
"\"INSERT INTO {$this->prefix}$table $fieldssql VALUES $valuessql\"",
";",
"list",
"(",
"$",
"sql",
",",
"$",
"params",
",",
"$",
"type",
")",
"=",
"$",
"this",
"->",
"fix_sql_params",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"$",
"rawsql",
"=",
"$",
"this",
"->",
"emulate_bound_params",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"query_start",
"(",
"$",
"sql",
",",
"$",
"params",
",",
"SQL_QUERY_INSERT",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"mysqli",
"->",
"query",
"(",
"$",
"rawsql",
")",
";",
"$",
"this",
"->",
"query_end",
"(",
"$",
"result",
")",
";",
"}"
] |
Insert records in chunks.
Note: can be used only from insert_records().
@param string $table
@param array $chunk
@param database_column_info[] $columns
|
[
"Insert",
"records",
"in",
"chunks",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/mysqli_native_moodle_database.php#L1473-L1494
|
219,852
|
moodle/moodle
|
lib/dml/mysqli_native_moodle_database.php
|
mysqli_native_moodle_database.sql_regex
|
public function sql_regex($positivematch = true, $casesensitive = false) {
$collation = '';
if ($casesensitive) {
if (substr($this->get_dbcollation(), -4) !== '_bin') {
$collationinfo = explode('_', $this->get_dbcollation());
$collation = 'COLLATE ' . $collationinfo[0] . '_bin ';
}
} else {
if ($this->get_dbcollation() == 'utf8_bin') {
$collation = 'COLLATE utf8_unicode_ci ';
} else if ($this->get_dbcollation() == 'utf8mb4_bin') {
$collation = 'COLLATE utf8mb4_unicode_ci ';
}
}
return $collation . ($positivematch ? 'REGEXP' : 'NOT REGEXP');
}
|
php
|
public function sql_regex($positivematch = true, $casesensitive = false) {
$collation = '';
if ($casesensitive) {
if (substr($this->get_dbcollation(), -4) !== '_bin') {
$collationinfo = explode('_', $this->get_dbcollation());
$collation = 'COLLATE ' . $collationinfo[0] . '_bin ';
}
} else {
if ($this->get_dbcollation() == 'utf8_bin') {
$collation = 'COLLATE utf8_unicode_ci ';
} else if ($this->get_dbcollation() == 'utf8mb4_bin') {
$collation = 'COLLATE utf8mb4_unicode_ci ';
}
}
return $collation . ($positivematch ? 'REGEXP' : 'NOT REGEXP');
}
|
[
"public",
"function",
"sql_regex",
"(",
"$",
"positivematch",
"=",
"true",
",",
"$",
"casesensitive",
"=",
"false",
")",
"{",
"$",
"collation",
"=",
"''",
";",
"if",
"(",
"$",
"casesensitive",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"this",
"->",
"get_dbcollation",
"(",
")",
",",
"-",
"4",
")",
"!==",
"'_bin'",
")",
"{",
"$",
"collationinfo",
"=",
"explode",
"(",
"'_'",
",",
"$",
"this",
"->",
"get_dbcollation",
"(",
")",
")",
";",
"$",
"collation",
"=",
"'COLLATE '",
".",
"$",
"collationinfo",
"[",
"0",
"]",
".",
"'_bin '",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"get_dbcollation",
"(",
")",
"==",
"'utf8_bin'",
")",
"{",
"$",
"collation",
"=",
"'COLLATE utf8_unicode_ci '",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"get_dbcollation",
"(",
")",
"==",
"'utf8mb4_bin'",
")",
"{",
"$",
"collation",
"=",
"'COLLATE utf8mb4_unicode_ci '",
";",
"}",
"}",
"return",
"$",
"collation",
".",
"(",
"$",
"positivematch",
"?",
"'REGEXP'",
":",
"'NOT REGEXP'",
")",
";",
"}"
] |
Return regex positive or negative match sql
@param bool $positivematch
@param bool $casesensitive
@return string or empty if not supported
|
[
"Return",
"regex",
"positive",
"or",
"negative",
"match",
"sql"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/mysqli_native_moodle_database.php#L1799-L1815
|
219,853
|
moodle/moodle
|
lib/dml/mysqli_native_moodle_database.php
|
mysqli_native_moodle_database.transactions_supported
|
protected function transactions_supported() {
if (!is_null($this->transactions_supported)) {
return $this->transactions_supported;
}
// this is all just guessing, might be better to just specify it in config.php
if (isset($this->dboptions['dbtransactions'])) {
$this->transactions_supported = $this->dboptions['dbtransactions'];
return $this->transactions_supported;
}
$this->transactions_supported = false;
$engine = $this->get_dbengine();
// Only will accept transactions if using compatible storage engine (more engines can be added easily BDB, Falcon...)
if (in_array($engine, array('InnoDB', 'INNOBASE', 'BDB', 'XtraDB', 'Aria', 'Falcon'))) {
$this->transactions_supported = true;
}
return $this->transactions_supported;
}
|
php
|
protected function transactions_supported() {
if (!is_null($this->transactions_supported)) {
return $this->transactions_supported;
}
// this is all just guessing, might be better to just specify it in config.php
if (isset($this->dboptions['dbtransactions'])) {
$this->transactions_supported = $this->dboptions['dbtransactions'];
return $this->transactions_supported;
}
$this->transactions_supported = false;
$engine = $this->get_dbengine();
// Only will accept transactions if using compatible storage engine (more engines can be added easily BDB, Falcon...)
if (in_array($engine, array('InnoDB', 'INNOBASE', 'BDB', 'XtraDB', 'Aria', 'Falcon'))) {
$this->transactions_supported = true;
}
return $this->transactions_supported;
}
|
[
"protected",
"function",
"transactions_supported",
"(",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"transactions_supported",
")",
")",
"{",
"return",
"$",
"this",
"->",
"transactions_supported",
";",
"}",
"// this is all just guessing, might be better to just specify it in config.php",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"dboptions",
"[",
"'dbtransactions'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"transactions_supported",
"=",
"$",
"this",
"->",
"dboptions",
"[",
"'dbtransactions'",
"]",
";",
"return",
"$",
"this",
"->",
"transactions_supported",
";",
"}",
"$",
"this",
"->",
"transactions_supported",
"=",
"false",
";",
"$",
"engine",
"=",
"$",
"this",
"->",
"get_dbengine",
"(",
")",
";",
"// Only will accept transactions if using compatible storage engine (more engines can be added easily BDB, Falcon...)",
"if",
"(",
"in_array",
"(",
"$",
"engine",
",",
"array",
"(",
"'InnoDB'",
",",
"'INNOBASE'",
",",
"'BDB'",
",",
"'XtraDB'",
",",
"'Aria'",
",",
"'Falcon'",
")",
")",
")",
"{",
"$",
"this",
"->",
"transactions_supported",
"=",
"true",
";",
"}",
"return",
"$",
"this",
"->",
"transactions_supported",
";",
"}"
] |
Are transactions supported?
It is not responsible to run productions servers
on databases without transaction support ;-)
MyISAM does not support support transactions.
You can override this via the dbtransactions option.
@return bool
|
[
"Are",
"transactions",
"supported?",
"It",
"is",
"not",
"responsible",
"to",
"run",
"productions",
"servers",
"on",
"databases",
"without",
"transaction",
"support",
";",
"-",
")"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/mysqli_native_moodle_database.php#L1930-L1951
|
219,854
|
moodle/moodle
|
lib/dml/mysqli_native_moodle_database.php
|
mysqli_native_moodle_database.convert_table_row_format
|
public function convert_table_row_format($tablename) {
$currentrowformat = $this->get_row_format($tablename);
if ($currentrowformat == 'Compact' || $currentrowformat == 'Redundant') {
$rowformat = ($this->is_compressed_row_format_supported(false)) ? "ROW_FORMAT=Compressed" : "ROW_FORMAT=Dynamic";
$prefix = $this->get_prefix();
$this->change_database_structure("ALTER TABLE {$prefix}$tablename $rowformat");
}
}
|
php
|
public function convert_table_row_format($tablename) {
$currentrowformat = $this->get_row_format($tablename);
if ($currentrowformat == 'Compact' || $currentrowformat == 'Redundant') {
$rowformat = ($this->is_compressed_row_format_supported(false)) ? "ROW_FORMAT=Compressed" : "ROW_FORMAT=Dynamic";
$prefix = $this->get_prefix();
$this->change_database_structure("ALTER TABLE {$prefix}$tablename $rowformat");
}
}
|
[
"public",
"function",
"convert_table_row_format",
"(",
"$",
"tablename",
")",
"{",
"$",
"currentrowformat",
"=",
"$",
"this",
"->",
"get_row_format",
"(",
"$",
"tablename",
")",
";",
"if",
"(",
"$",
"currentrowformat",
"==",
"'Compact'",
"||",
"$",
"currentrowformat",
"==",
"'Redundant'",
")",
"{",
"$",
"rowformat",
"=",
"(",
"$",
"this",
"->",
"is_compressed_row_format_supported",
"(",
"false",
")",
")",
"?",
"\"ROW_FORMAT=Compressed\"",
":",
"\"ROW_FORMAT=Dynamic\"",
";",
"$",
"prefix",
"=",
"$",
"this",
"->",
"get_prefix",
"(",
")",
";",
"$",
"this",
"->",
"change_database_structure",
"(",
"\"ALTER TABLE {$prefix}$tablename $rowformat\"",
")",
";",
"}",
"}"
] |
Converts a table to either 'Compressed' or 'Dynamic' row format.
@param string $tablename Name of the table to convert to the new row format.
|
[
"Converts",
"a",
"table",
"to",
"either",
"Compressed",
"or",
"Dynamic",
"row",
"format",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dml/mysqli_native_moodle_database.php#L2013-L2020
|
219,855
|
moodle/moodle
|
grade/report/history/classes/output/renderer.php
|
renderer.render_user_button
|
protected function render_user_button(user_button $button) {
$data = $button->export_for_template($this);
return $this->render_from_template('gradereport_history/user_button', $data);
}
|
php
|
protected function render_user_button(user_button $button) {
$data = $button->export_for_template($this);
return $this->render_from_template('gradereport_history/user_button', $data);
}
|
[
"protected",
"function",
"render_user_button",
"(",
"user_button",
"$",
"button",
")",
"{",
"$",
"data",
"=",
"$",
"button",
"->",
"export_for_template",
"(",
"$",
"this",
")",
";",
"return",
"$",
"this",
"->",
"render_from_template",
"(",
"'gradereport_history/user_button'",
",",
"$",
"data",
")",
";",
"}"
] |
Render for the select user button.
@param user_button $button instance of gradereport_history_user_button to render
@return string HTML to display
|
[
"Render",
"for",
"the",
"select",
"user",
"button",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/history/classes/output/renderer.php#L48-L51
|
219,856
|
moodle/moodle
|
mod/quiz/report/responses/first_or_all_responses_table.php
|
quiz_first_or_all_responses_table.get_summary_after_try
|
public function get_summary_after_try($tablerow, $slot) {
$qa = $this->get_question_attempt($tablerow->usageid, $slot);
if (!($qa->get_question() instanceof question_manually_gradable)) {
// No responses, and we cannot call summarise_response below.
return null;
}
$submissionsteps = $qa->get_steps_with_submitted_response_iterator();
$step = $submissionsteps[$tablerow->try];
if ($step === null) {
return null;
}
$qtdata = $step->get_qt_data();
return $qa->get_question()->summarise_response($qtdata);
}
|
php
|
public function get_summary_after_try($tablerow, $slot) {
$qa = $this->get_question_attempt($tablerow->usageid, $slot);
if (!($qa->get_question() instanceof question_manually_gradable)) {
// No responses, and we cannot call summarise_response below.
return null;
}
$submissionsteps = $qa->get_steps_with_submitted_response_iterator();
$step = $submissionsteps[$tablerow->try];
if ($step === null) {
return null;
}
$qtdata = $step->get_qt_data();
return $qa->get_question()->summarise_response($qtdata);
}
|
[
"public",
"function",
"get_summary_after_try",
"(",
"$",
"tablerow",
",",
"$",
"slot",
")",
"{",
"$",
"qa",
"=",
"$",
"this",
"->",
"get_question_attempt",
"(",
"$",
"tablerow",
"->",
"usageid",
",",
"$",
"slot",
")",
";",
"if",
"(",
"!",
"(",
"$",
"qa",
"->",
"get_question",
"(",
")",
"instanceof",
"question_manually_gradable",
")",
")",
"{",
"// No responses, and we cannot call summarise_response below.",
"return",
"null",
";",
"}",
"$",
"submissionsteps",
"=",
"$",
"qa",
"->",
"get_steps_with_submitted_response_iterator",
"(",
")",
";",
"$",
"step",
"=",
"$",
"submissionsteps",
"[",
"$",
"tablerow",
"->",
"try",
"]",
";",
"if",
"(",
"$",
"step",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"$",
"qtdata",
"=",
"$",
"step",
"->",
"get_qt_data",
"(",
")",
";",
"return",
"$",
"qa",
"->",
"get_question",
"(",
")",
"->",
"summarise_response",
"(",
"$",
"qtdata",
")",
";",
"}"
] |
Get the summary of the response after the try.
@param object $tablerow row data
@param int $slot Slot number.
@return string summary for the question after this try.
|
[
"Get",
"the",
"summary",
"of",
"the",
"response",
"after",
"the",
"try",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/responses/first_or_all_responses_table.php#L142-L155
|
219,857
|
moodle/moodle
|
mod/quiz/report/responses/first_or_all_responses_table.php
|
quiz_first_or_all_responses_table.slot_fraction
|
protected function slot_fraction($tablerow, $slot) {
$qa = $this->get_question_attempt($tablerow->usageid, $slot);
$submissionsteps = $qa->get_steps_with_submitted_response_iterator();
$step = $submissionsteps[$tablerow->try];
if ($step === null) {
return null;
}
if ($this->is_last_try($tablerow, $slot, $tablerow->try)) {
// If this is the last try then the step with the try data does not contain the correct fraction. We need to
// use the last step's fraction, after the attempt has been finished.
return $qa->get_fraction();
}
return $step->get_fraction();
}
|
php
|
protected function slot_fraction($tablerow, $slot) {
$qa = $this->get_question_attempt($tablerow->usageid, $slot);
$submissionsteps = $qa->get_steps_with_submitted_response_iterator();
$step = $submissionsteps[$tablerow->try];
if ($step === null) {
return null;
}
if ($this->is_last_try($tablerow, $slot, $tablerow->try)) {
// If this is the last try then the step with the try data does not contain the correct fraction. We need to
// use the last step's fraction, after the attempt has been finished.
return $qa->get_fraction();
}
return $step->get_fraction();
}
|
[
"protected",
"function",
"slot_fraction",
"(",
"$",
"tablerow",
",",
"$",
"slot",
")",
"{",
"$",
"qa",
"=",
"$",
"this",
"->",
"get_question_attempt",
"(",
"$",
"tablerow",
"->",
"usageid",
",",
"$",
"slot",
")",
";",
"$",
"submissionsteps",
"=",
"$",
"qa",
"->",
"get_steps_with_submitted_response_iterator",
"(",
")",
";",
"$",
"step",
"=",
"$",
"submissionsteps",
"[",
"$",
"tablerow",
"->",
"try",
"]",
";",
"if",
"(",
"$",
"step",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"is_last_try",
"(",
"$",
"tablerow",
",",
"$",
"slot",
",",
"$",
"tablerow",
"->",
"try",
")",
")",
"{",
"// If this is the last try then the step with the try data does not contain the correct fraction. We need to",
"// use the last step's fraction, after the attempt has been finished.",
"return",
"$",
"qa",
"->",
"get_fraction",
"(",
")",
";",
"}",
"return",
"$",
"step",
"->",
"get_fraction",
"(",
")",
";",
"}"
] |
The grade for this slot after this try.
@param object $tablerow attempt data from db.
@param int $slot Slot number.
@return float The fraction.
|
[
"The",
"grade",
"for",
"this",
"slot",
"after",
"this",
"try",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/responses/first_or_all_responses_table.php#L175-L188
|
219,858
|
moodle/moodle
|
mod/quiz/report/responses/first_or_all_responses_table.php
|
quiz_first_or_all_responses_table.get_no_of_tries
|
public function get_no_of_tries($tablerow, $slot) {
return count($this->get_question_attempt($tablerow->usageid, $slot)->get_steps_with_submitted_response_iterator());
}
|
php
|
public function get_no_of_tries($tablerow, $slot) {
return count($this->get_question_attempt($tablerow->usageid, $slot)->get_steps_with_submitted_response_iterator());
}
|
[
"public",
"function",
"get_no_of_tries",
"(",
"$",
"tablerow",
",",
"$",
"slot",
")",
"{",
"return",
"count",
"(",
"$",
"this",
"->",
"get_question_attempt",
"(",
"$",
"tablerow",
"->",
"usageid",
",",
"$",
"slot",
")",
"->",
"get_steps_with_submitted_response_iterator",
"(",
")",
")",
";",
"}"
] |
How many tries were attempted at this question in this slot, during this usage?
@param object $tablerow attempt data from db.
@param int $slot Slot number
@return int the number of tries in the question attempt for slot $slot.
|
[
"How",
"many",
"tries",
"were",
"attempted",
"at",
"this",
"question",
"in",
"this",
"slot",
"during",
"this",
"usage?"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/responses/first_or_all_responses_table.php#L209-L211
|
219,859
|
moodle/moodle
|
mod/quiz/report/responses/first_or_all_responses_table.php
|
quiz_first_or_all_responses_table.step_no_for_try
|
protected function step_no_for_try($questionusageid, $slot, $tryno) {
$qa = $this->get_question_attempt($questionusageid, $slot);
return $qa->get_steps_with_submitted_response_iterator()->step_no_for_try($tryno);
}
|
php
|
protected function step_no_for_try($questionusageid, $slot, $tryno) {
$qa = $this->get_question_attempt($questionusageid, $slot);
return $qa->get_steps_with_submitted_response_iterator()->step_no_for_try($tryno);
}
|
[
"protected",
"function",
"step_no_for_try",
"(",
"$",
"questionusageid",
",",
"$",
"slot",
",",
"$",
"tryno",
")",
"{",
"$",
"qa",
"=",
"$",
"this",
"->",
"get_question_attempt",
"(",
"$",
"questionusageid",
",",
"$",
"slot",
")",
";",
"return",
"$",
"qa",
"->",
"get_steps_with_submitted_response_iterator",
"(",
")",
"->",
"step_no_for_try",
"(",
"$",
"tryno",
")",
";",
"}"
] |
What is the step no this try was seen in?
@param int $questionusageid The question usage id.
@param int $slot Slot number
@param int $tryno Try no
@return int the step no or zero if not found
|
[
"What",
"is",
"the",
"step",
"no",
"this",
"try",
"was",
"seen",
"in?"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/responses/first_or_all_responses_table.php#L222-L225
|
219,860
|
moodle/moodle
|
report/performance/locallib.php
|
report_performance.doc_link
|
public function doc_link($issue, $name) {
global $CFG, $OUTPUT;
if (empty($CFG->docroot)) {
return $name;
}
return $OUTPUT->doc_link('report/performance/'.$issue, $name);
}
|
php
|
public function doc_link($issue, $name) {
global $CFG, $OUTPUT;
if (empty($CFG->docroot)) {
return $name;
}
return $OUTPUT->doc_link('report/performance/'.$issue, $name);
}
|
[
"public",
"function",
"doc_link",
"(",
"$",
"issue",
",",
"$",
"name",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"OUTPUT",
";",
"if",
"(",
"empty",
"(",
"$",
"CFG",
"->",
"docroot",
")",
")",
"{",
"return",
"$",
"name",
";",
"}",
"return",
"$",
"OUTPUT",
"->",
"doc_link",
"(",
"'report/performance/'",
".",
"$",
"issue",
",",
"$",
"name",
")",
";",
"}"
] |
Returns document link for performance issue
@param string $issue string describing issue
@param string $name name of issue
@return string issue link pointing to docs page.
|
[
"Returns",
"document",
"link",
"for",
"performance",
"issue"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/performance/locallib.php#L101-L109
|
219,861
|
moodle/moodle
|
report/performance/locallib.php
|
report_performance.add_issue_to_table
|
public function add_issue_to_table(&$table, $issueresult, $detailed = false) {
global $OUTPUT;
$statusarr = array(self::REPORT_PERFORMANCE_OK => 'statusok',
self::REPORT_PERFORMANCE_WARNING => 'statuswarning',
self::REPORT_PERFORMANCE_SERIOUS => 'statusserious',
self::REPORT_PERFORMANCE_CRITICAL => 'statuscritical');
$row = array();
if ($detailed) {
$row[0] = $this->doc_link($issueresult->issue, $issueresult->name);
} else {
$url = new moodle_url('/report/performance/index.php', array('issue' => $issueresult->issue));
$row[0] = html_writer::link($url, $issueresult->name);
}
$row[1] = html_writer::tag('span', $issueresult->statusstr, array('class' => $statusarr[$issueresult->status]));
$row[2] = $issueresult->comment;
if (!empty($issueresult->configlink)) {
$editicon = $OUTPUT->pix_icon('i/settings', $issueresult->issue);
$row[3] = $OUTPUT->action_link($issueresult->configlink, $editicon);
} else {
$row[3] = '';
}
$table->data[] = $row;
}
|
php
|
public function add_issue_to_table(&$table, $issueresult, $detailed = false) {
global $OUTPUT;
$statusarr = array(self::REPORT_PERFORMANCE_OK => 'statusok',
self::REPORT_PERFORMANCE_WARNING => 'statuswarning',
self::REPORT_PERFORMANCE_SERIOUS => 'statusserious',
self::REPORT_PERFORMANCE_CRITICAL => 'statuscritical');
$row = array();
if ($detailed) {
$row[0] = $this->doc_link($issueresult->issue, $issueresult->name);
} else {
$url = new moodle_url('/report/performance/index.php', array('issue' => $issueresult->issue));
$row[0] = html_writer::link($url, $issueresult->name);
}
$row[1] = html_writer::tag('span', $issueresult->statusstr, array('class' => $statusarr[$issueresult->status]));
$row[2] = $issueresult->comment;
if (!empty($issueresult->configlink)) {
$editicon = $OUTPUT->pix_icon('i/settings', $issueresult->issue);
$row[3] = $OUTPUT->action_link($issueresult->configlink, $editicon);
} else {
$row[3] = '';
}
$table->data[] = $row;
}
|
[
"public",
"function",
"add_issue_to_table",
"(",
"&",
"$",
"table",
",",
"$",
"issueresult",
",",
"$",
"detailed",
"=",
"false",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"$",
"statusarr",
"=",
"array",
"(",
"self",
"::",
"REPORT_PERFORMANCE_OK",
"=>",
"'statusok'",
",",
"self",
"::",
"REPORT_PERFORMANCE_WARNING",
"=>",
"'statuswarning'",
",",
"self",
"::",
"REPORT_PERFORMANCE_SERIOUS",
"=>",
"'statusserious'",
",",
"self",
"::",
"REPORT_PERFORMANCE_CRITICAL",
"=>",
"'statuscritical'",
")",
";",
"$",
"row",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"detailed",
")",
"{",
"$",
"row",
"[",
"0",
"]",
"=",
"$",
"this",
"->",
"doc_link",
"(",
"$",
"issueresult",
"->",
"issue",
",",
"$",
"issueresult",
"->",
"name",
")",
";",
"}",
"else",
"{",
"$",
"url",
"=",
"new",
"moodle_url",
"(",
"'/report/performance/index.php'",
",",
"array",
"(",
"'issue'",
"=>",
"$",
"issueresult",
"->",
"issue",
")",
")",
";",
"$",
"row",
"[",
"0",
"]",
"=",
"html_writer",
"::",
"link",
"(",
"$",
"url",
",",
"$",
"issueresult",
"->",
"name",
")",
";",
"}",
"$",
"row",
"[",
"1",
"]",
"=",
"html_writer",
"::",
"tag",
"(",
"'span'",
",",
"$",
"issueresult",
"->",
"statusstr",
",",
"array",
"(",
"'class'",
"=>",
"$",
"statusarr",
"[",
"$",
"issueresult",
"->",
"status",
"]",
")",
")",
";",
"$",
"row",
"[",
"2",
"]",
"=",
"$",
"issueresult",
"->",
"comment",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"issueresult",
"->",
"configlink",
")",
")",
"{",
"$",
"editicon",
"=",
"$",
"OUTPUT",
"->",
"pix_icon",
"(",
"'i/settings'",
",",
"$",
"issueresult",
"->",
"issue",
")",
";",
"$",
"row",
"[",
"3",
"]",
"=",
"$",
"OUTPUT",
"->",
"action_link",
"(",
"$",
"issueresult",
"->",
"configlink",
",",
"$",
"editicon",
")",
";",
"}",
"else",
"{",
"$",
"row",
"[",
"3",
"]",
"=",
"''",
";",
"}",
"$",
"table",
"->",
"data",
"[",
"]",
"=",
"$",
"row",
";",
"}"
] |
Helper function to add issue details to table.
@param html_table $table table in which issue details should be added
@param report_performance_issues $issueresult issue result to be added
@param bool $detail true if issue if displayed in detail.
|
[
"Helper",
"function",
"to",
"add",
"issue",
"details",
"to",
"table",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/performance/locallib.php#L118-L142
|
219,862
|
moodle/moodle
|
report/performance/locallib.php
|
report_performance.report_performance_check_themedesignermode
|
public static function report_performance_check_themedesignermode() {
global $CFG;
$issueresult = new report_performance_issue();
$issueresult->issue = 'report_performance_check_themedesignermode';
$issueresult->name = get_string('themedesignermode', 'admin');
if (empty($CFG->themedesignermode)) {
$issueresult->statusstr = get_string('disabled', 'report_performance');
$issueresult->status = self::REPORT_PERFORMANCE_OK;
$issueresult->comment = get_string('check_themedesignermode_comment_disable', 'report_performance');
} else {
$issueresult->statusstr = get_string('enabled', 'report_performance');
$issueresult->status = self::REPORT_PERFORMANCE_CRITICAL;
$issueresult->comment = get_string('check_themedesignermode_comment_enable', 'report_performance');
}
$issueresult->details = get_string('check_themedesignermode_details', 'report_performance');
$issueresult->configlink = new moodle_url('/admin/search.php', array('query' => 'themedesignermode'));
return $issueresult;
}
|
php
|
public static function report_performance_check_themedesignermode() {
global $CFG;
$issueresult = new report_performance_issue();
$issueresult->issue = 'report_performance_check_themedesignermode';
$issueresult->name = get_string('themedesignermode', 'admin');
if (empty($CFG->themedesignermode)) {
$issueresult->statusstr = get_string('disabled', 'report_performance');
$issueresult->status = self::REPORT_PERFORMANCE_OK;
$issueresult->comment = get_string('check_themedesignermode_comment_disable', 'report_performance');
} else {
$issueresult->statusstr = get_string('enabled', 'report_performance');
$issueresult->status = self::REPORT_PERFORMANCE_CRITICAL;
$issueresult->comment = get_string('check_themedesignermode_comment_enable', 'report_performance');
}
$issueresult->details = get_string('check_themedesignermode_details', 'report_performance');
$issueresult->configlink = new moodle_url('/admin/search.php', array('query' => 'themedesignermode'));
return $issueresult;
}
|
[
"public",
"static",
"function",
"report_performance_check_themedesignermode",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"issueresult",
"=",
"new",
"report_performance_issue",
"(",
")",
";",
"$",
"issueresult",
"->",
"issue",
"=",
"'report_performance_check_themedesignermode'",
";",
"$",
"issueresult",
"->",
"name",
"=",
"get_string",
"(",
"'themedesignermode'",
",",
"'admin'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"CFG",
"->",
"themedesignermode",
")",
")",
"{",
"$",
"issueresult",
"->",
"statusstr",
"=",
"get_string",
"(",
"'disabled'",
",",
"'report_performance'",
")",
";",
"$",
"issueresult",
"->",
"status",
"=",
"self",
"::",
"REPORT_PERFORMANCE_OK",
";",
"$",
"issueresult",
"->",
"comment",
"=",
"get_string",
"(",
"'check_themedesignermode_comment_disable'",
",",
"'report_performance'",
")",
";",
"}",
"else",
"{",
"$",
"issueresult",
"->",
"statusstr",
"=",
"get_string",
"(",
"'enabled'",
",",
"'report_performance'",
")",
";",
"$",
"issueresult",
"->",
"status",
"=",
"self",
"::",
"REPORT_PERFORMANCE_CRITICAL",
";",
"$",
"issueresult",
"->",
"comment",
"=",
"get_string",
"(",
"'check_themedesignermode_comment_enable'",
",",
"'report_performance'",
")",
";",
"}",
"$",
"issueresult",
"->",
"details",
"=",
"get_string",
"(",
"'check_themedesignermode_details'",
",",
"'report_performance'",
")",
";",
"$",
"issueresult",
"->",
"configlink",
"=",
"new",
"moodle_url",
"(",
"'/admin/search.php'",
",",
"array",
"(",
"'query'",
"=>",
"'themedesignermode'",
")",
")",
";",
"return",
"$",
"issueresult",
";",
"}"
] |
Verifies if theme designer mode is enabled.
@return report_performance_issue result of themedesigner issue.
|
[
"Verifies",
"if",
"theme",
"designer",
"mode",
"is",
"enabled",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/performance/locallib.php#L149-L168
|
219,863
|
moodle/moodle
|
report/performance/locallib.php
|
report_performance.report_performance_check_debugmsg
|
public static function report_performance_check_debugmsg() {
global $CFG;
$issueresult = new report_performance_issue();
$issueresult->issue = 'report_performance_check_debugmsg';
$issueresult->name = get_string('debug', 'admin');
$debugchoices = array(DEBUG_NONE => 'debugnone',
DEBUG_MINIMAL => 'debugminimal',
DEBUG_NORMAL => 'debugnormal',
DEBUG_ALL => 'debugall',
DEBUG_DEVELOPER => 'debugdeveloper');
$issueresult->statusstr = get_string($debugchoices[$CFG->debug], 'admin');
if (!$CFG->debugdeveloper) {
$issueresult->status = self::REPORT_PERFORMANCE_OK;
$issueresult->comment = get_string('check_debugmsg_comment_nodeveloper', 'report_performance');
} else {
$issueresult->status = self::REPORT_PERFORMANCE_WARNING;
$issueresult->comment = get_string('check_debugmsg_comment_developer', 'report_performance');
}
$issueresult->details = get_string('check_debugmsg_details', 'report_performance');
$issueresult->configlink = new moodle_url('/admin/settings.php', array('section' => 'debugging'));
return $issueresult;
}
|
php
|
public static function report_performance_check_debugmsg() {
global $CFG;
$issueresult = new report_performance_issue();
$issueresult->issue = 'report_performance_check_debugmsg';
$issueresult->name = get_string('debug', 'admin');
$debugchoices = array(DEBUG_NONE => 'debugnone',
DEBUG_MINIMAL => 'debugminimal',
DEBUG_NORMAL => 'debugnormal',
DEBUG_ALL => 'debugall',
DEBUG_DEVELOPER => 'debugdeveloper');
$issueresult->statusstr = get_string($debugchoices[$CFG->debug], 'admin');
if (!$CFG->debugdeveloper) {
$issueresult->status = self::REPORT_PERFORMANCE_OK;
$issueresult->comment = get_string('check_debugmsg_comment_nodeveloper', 'report_performance');
} else {
$issueresult->status = self::REPORT_PERFORMANCE_WARNING;
$issueresult->comment = get_string('check_debugmsg_comment_developer', 'report_performance');
}
$issueresult->details = get_string('check_debugmsg_details', 'report_performance');
$issueresult->configlink = new moodle_url('/admin/settings.php', array('section' => 'debugging'));
return $issueresult;
}
|
[
"public",
"static",
"function",
"report_performance_check_debugmsg",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"issueresult",
"=",
"new",
"report_performance_issue",
"(",
")",
";",
"$",
"issueresult",
"->",
"issue",
"=",
"'report_performance_check_debugmsg'",
";",
"$",
"issueresult",
"->",
"name",
"=",
"get_string",
"(",
"'debug'",
",",
"'admin'",
")",
";",
"$",
"debugchoices",
"=",
"array",
"(",
"DEBUG_NONE",
"=>",
"'debugnone'",
",",
"DEBUG_MINIMAL",
"=>",
"'debugminimal'",
",",
"DEBUG_NORMAL",
"=>",
"'debugnormal'",
",",
"DEBUG_ALL",
"=>",
"'debugall'",
",",
"DEBUG_DEVELOPER",
"=>",
"'debugdeveloper'",
")",
";",
"$",
"issueresult",
"->",
"statusstr",
"=",
"get_string",
"(",
"$",
"debugchoices",
"[",
"$",
"CFG",
"->",
"debug",
"]",
",",
"'admin'",
")",
";",
"if",
"(",
"!",
"$",
"CFG",
"->",
"debugdeveloper",
")",
"{",
"$",
"issueresult",
"->",
"status",
"=",
"self",
"::",
"REPORT_PERFORMANCE_OK",
";",
"$",
"issueresult",
"->",
"comment",
"=",
"get_string",
"(",
"'check_debugmsg_comment_nodeveloper'",
",",
"'report_performance'",
")",
";",
"}",
"else",
"{",
"$",
"issueresult",
"->",
"status",
"=",
"self",
"::",
"REPORT_PERFORMANCE_WARNING",
";",
"$",
"issueresult",
"->",
"comment",
"=",
"get_string",
"(",
"'check_debugmsg_comment_developer'",
",",
"'report_performance'",
")",
";",
"}",
"$",
"issueresult",
"->",
"details",
"=",
"get_string",
"(",
"'check_debugmsg_details'",
",",
"'report_performance'",
")",
";",
"$",
"issueresult",
"->",
"configlink",
"=",
"new",
"moodle_url",
"(",
"'/admin/settings.php'",
",",
"array",
"(",
"'section'",
"=>",
"'debugging'",
")",
")",
";",
"return",
"$",
"issueresult",
";",
"}"
] |
Checks debug config.
@return report_performance_issue result of debugmsg issue.
|
[
"Checks",
"debug",
"config",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/performance/locallib.php#L201-L225
|
219,864
|
moodle/moodle
|
report/performance/locallib.php
|
report_performance.report_performance_check_automatic_backup
|
public static function report_performance_check_automatic_backup() {
global $CFG;
require_once($CFG->dirroot . '/backup/util/helper/backup_cron_helper.class.php');
$issueresult = new report_performance_issue();
$issueresult->issue = 'report_performance_check_automatic_backup';
$issueresult->name = get_string('check_backup', 'report_performance');
$automatedbackupsenabled = get_config('backup', 'backup_auto_active');
if ($automatedbackupsenabled == backup_cron_automated_helper::AUTO_BACKUP_ENABLED) {
$issueresult->statusstr = get_string('autoactiveenabled', 'backup');
$issueresult->status = self::REPORT_PERFORMANCE_WARNING;
$issueresult->comment = get_string('check_backup_comment_enable', 'report_performance');
} else {
if ($automatedbackupsenabled == backup_cron_automated_helper::AUTO_BACKUP_DISABLED) {
$issueresult->statusstr = get_string('autoactivedisabled', 'backup');
} else {
$issueresult->statusstr = get_string('autoactivemanual', 'backup');
}
$issueresult->status = self::REPORT_PERFORMANCE_OK;
$issueresult->comment = get_string('check_backup_comment_disable', 'report_performance');
}
$issueresult->details = get_string('check_backup_details', 'report_performance');
$issueresult->configlink = new moodle_url('/admin/search.php', array('query' => 'backup_auto_active'));
return $issueresult;
}
|
php
|
public static function report_performance_check_automatic_backup() {
global $CFG;
require_once($CFG->dirroot . '/backup/util/helper/backup_cron_helper.class.php');
$issueresult = new report_performance_issue();
$issueresult->issue = 'report_performance_check_automatic_backup';
$issueresult->name = get_string('check_backup', 'report_performance');
$automatedbackupsenabled = get_config('backup', 'backup_auto_active');
if ($automatedbackupsenabled == backup_cron_automated_helper::AUTO_BACKUP_ENABLED) {
$issueresult->statusstr = get_string('autoactiveenabled', 'backup');
$issueresult->status = self::REPORT_PERFORMANCE_WARNING;
$issueresult->comment = get_string('check_backup_comment_enable', 'report_performance');
} else {
if ($automatedbackupsenabled == backup_cron_automated_helper::AUTO_BACKUP_DISABLED) {
$issueresult->statusstr = get_string('autoactivedisabled', 'backup');
} else {
$issueresult->statusstr = get_string('autoactivemanual', 'backup');
}
$issueresult->status = self::REPORT_PERFORMANCE_OK;
$issueresult->comment = get_string('check_backup_comment_disable', 'report_performance');
}
$issueresult->details = get_string('check_backup_details', 'report_performance');
$issueresult->configlink = new moodle_url('/admin/search.php', array('query' => 'backup_auto_active'));
return $issueresult;
}
|
[
"public",
"static",
"function",
"report_performance_check_automatic_backup",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/backup/util/helper/backup_cron_helper.class.php'",
")",
";",
"$",
"issueresult",
"=",
"new",
"report_performance_issue",
"(",
")",
";",
"$",
"issueresult",
"->",
"issue",
"=",
"'report_performance_check_automatic_backup'",
";",
"$",
"issueresult",
"->",
"name",
"=",
"get_string",
"(",
"'check_backup'",
",",
"'report_performance'",
")",
";",
"$",
"automatedbackupsenabled",
"=",
"get_config",
"(",
"'backup'",
",",
"'backup_auto_active'",
")",
";",
"if",
"(",
"$",
"automatedbackupsenabled",
"==",
"backup_cron_automated_helper",
"::",
"AUTO_BACKUP_ENABLED",
")",
"{",
"$",
"issueresult",
"->",
"statusstr",
"=",
"get_string",
"(",
"'autoactiveenabled'",
",",
"'backup'",
")",
";",
"$",
"issueresult",
"->",
"status",
"=",
"self",
"::",
"REPORT_PERFORMANCE_WARNING",
";",
"$",
"issueresult",
"->",
"comment",
"=",
"get_string",
"(",
"'check_backup_comment_enable'",
",",
"'report_performance'",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"automatedbackupsenabled",
"==",
"backup_cron_automated_helper",
"::",
"AUTO_BACKUP_DISABLED",
")",
"{",
"$",
"issueresult",
"->",
"statusstr",
"=",
"get_string",
"(",
"'autoactivedisabled'",
",",
"'backup'",
")",
";",
"}",
"else",
"{",
"$",
"issueresult",
"->",
"statusstr",
"=",
"get_string",
"(",
"'autoactivemanual'",
",",
"'backup'",
")",
";",
"}",
"$",
"issueresult",
"->",
"status",
"=",
"self",
"::",
"REPORT_PERFORMANCE_OK",
";",
"$",
"issueresult",
"->",
"comment",
"=",
"get_string",
"(",
"'check_backup_comment_disable'",
",",
"'report_performance'",
")",
";",
"}",
"$",
"issueresult",
"->",
"details",
"=",
"get_string",
"(",
"'check_backup_details'",
",",
"'report_performance'",
")",
";",
"$",
"issueresult",
"->",
"configlink",
"=",
"new",
"moodle_url",
"(",
"'/admin/search.php'",
",",
"array",
"(",
"'query'",
"=>",
"'backup_auto_active'",
")",
")",
";",
"return",
"$",
"issueresult",
";",
"}"
] |
Checks automatic backup config.
@return report_performance_issue result of automatic backup issue.
|
[
"Checks",
"automatic",
"backup",
"config",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/performance/locallib.php#L232-L258
|
219,865
|
moodle/moodle
|
report/performance/locallib.php
|
report_performance.report_performance_check_enablestats
|
public static function report_performance_check_enablestats() {
global $CFG;
$issueresult = new report_performance_issue();
$issueresult->issue = 'report_performance_check_enablestats';
$issueresult->name = get_string('enablestats', 'admin');
if (!empty($CFG->enablestats)) {
$issueresult->statusstr = get_string('enabled', 'report_performance');
$issueresult->status = self::REPORT_PERFORMANCE_WARNING;
$issueresult->comment = get_string('check_enablestats_comment_enable', 'report_performance');
} else {
$issueresult->statusstr = get_string('disabled', 'report_performance');
$issueresult->status = self::REPORT_PERFORMANCE_OK;
$issueresult->comment = get_string('check_enablestats_comment_disable', 'report_performance');
}
$issueresult->details = get_string('check_enablestats_details', 'report_performance');
$issueresult->configlink = new moodle_url('/admin/search.php', array('query' => 'enablestats'));
return $issueresult;
}
|
php
|
public static function report_performance_check_enablestats() {
global $CFG;
$issueresult = new report_performance_issue();
$issueresult->issue = 'report_performance_check_enablestats';
$issueresult->name = get_string('enablestats', 'admin');
if (!empty($CFG->enablestats)) {
$issueresult->statusstr = get_string('enabled', 'report_performance');
$issueresult->status = self::REPORT_PERFORMANCE_WARNING;
$issueresult->comment = get_string('check_enablestats_comment_enable', 'report_performance');
} else {
$issueresult->statusstr = get_string('disabled', 'report_performance');
$issueresult->status = self::REPORT_PERFORMANCE_OK;
$issueresult->comment = get_string('check_enablestats_comment_disable', 'report_performance');
}
$issueresult->details = get_string('check_enablestats_details', 'report_performance');
$issueresult->configlink = new moodle_url('/admin/search.php', array('query' => 'enablestats'));
return $issueresult;
}
|
[
"public",
"static",
"function",
"report_performance_check_enablestats",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"issueresult",
"=",
"new",
"report_performance_issue",
"(",
")",
";",
"$",
"issueresult",
"->",
"issue",
"=",
"'report_performance_check_enablestats'",
";",
"$",
"issueresult",
"->",
"name",
"=",
"get_string",
"(",
"'enablestats'",
",",
"'admin'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"CFG",
"->",
"enablestats",
")",
")",
"{",
"$",
"issueresult",
"->",
"statusstr",
"=",
"get_string",
"(",
"'enabled'",
",",
"'report_performance'",
")",
";",
"$",
"issueresult",
"->",
"status",
"=",
"self",
"::",
"REPORT_PERFORMANCE_WARNING",
";",
"$",
"issueresult",
"->",
"comment",
"=",
"get_string",
"(",
"'check_enablestats_comment_enable'",
",",
"'report_performance'",
")",
";",
"}",
"else",
"{",
"$",
"issueresult",
"->",
"statusstr",
"=",
"get_string",
"(",
"'disabled'",
",",
"'report_performance'",
")",
";",
"$",
"issueresult",
"->",
"status",
"=",
"self",
"::",
"REPORT_PERFORMANCE_OK",
";",
"$",
"issueresult",
"->",
"comment",
"=",
"get_string",
"(",
"'check_enablestats_comment_disable'",
",",
"'report_performance'",
")",
";",
"}",
"$",
"issueresult",
"->",
"details",
"=",
"get_string",
"(",
"'check_enablestats_details'",
",",
"'report_performance'",
")",
";",
"$",
"issueresult",
"->",
"configlink",
"=",
"new",
"moodle_url",
"(",
"'/admin/search.php'",
",",
"array",
"(",
"'query'",
"=>",
"'enablestats'",
")",
")",
";",
"return",
"$",
"issueresult",
";",
"}"
] |
Checks if stats are enabled.
|
[
"Checks",
"if",
"stats",
"are",
"enabled",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/performance/locallib.php#L263-L282
|
219,866
|
moodle/moodle
|
lib/horde/framework/Horde/Mail/Rfc822/Identification.php
|
Horde_Mail_Rfc822_Identification.parse
|
public function parse($value)
{
if (!strlen($value)) {
return;
}
$this->_data = $value;
$this->_datalen = strlen($value);
$this->_params['validate'] = true;
$this->_ptr = 0;
$this->_rfc822SkipLwsp();
while ($this->_curr() !== false) {
try {
$this->ids[] = $this->_parseMessageId();
} catch (Horde_Mail_Exception $e) {
break;
}
// Some mailers incorrectly insert commas between reference items
if ($this->_curr() == ',') {
$this->_rfc822SkipLwsp(true);
}
}
}
|
php
|
public function parse($value)
{
if (!strlen($value)) {
return;
}
$this->_data = $value;
$this->_datalen = strlen($value);
$this->_params['validate'] = true;
$this->_ptr = 0;
$this->_rfc822SkipLwsp();
while ($this->_curr() !== false) {
try {
$this->ids[] = $this->_parseMessageId();
} catch (Horde_Mail_Exception $e) {
break;
}
// Some mailers incorrectly insert commas between reference items
if ($this->_curr() == ',') {
$this->_rfc822SkipLwsp(true);
}
}
}
|
[
"public",
"function",
"parse",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"strlen",
"(",
"$",
"value",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"_data",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"_datalen",
"=",
"strlen",
"(",
"$",
"value",
")",
";",
"$",
"this",
"->",
"_params",
"[",
"'validate'",
"]",
"=",
"true",
";",
"$",
"this",
"->",
"_ptr",
"=",
"0",
";",
"$",
"this",
"->",
"_rfc822SkipLwsp",
"(",
")",
";",
"while",
"(",
"$",
"this",
"->",
"_curr",
"(",
")",
"!==",
"false",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"ids",
"[",
"]",
"=",
"$",
"this",
"->",
"_parseMessageId",
"(",
")",
";",
"}",
"catch",
"(",
"Horde_Mail_Exception",
"$",
"e",
")",
"{",
"break",
";",
"}",
"// Some mailers incorrectly insert commas between reference items",
"if",
"(",
"$",
"this",
"->",
"_curr",
"(",
")",
"==",
"','",
")",
"{",
"$",
"this",
"->",
"_rfc822SkipLwsp",
"(",
"true",
")",
";",
"}",
"}",
"}"
] |
Parse an identification header.
@param string $value Identification field value to parse.
|
[
"Parse",
"an",
"identification",
"header",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mail/Rfc822/Identification.php#L49-L74
|
219,867
|
moodle/moodle
|
mod/lti/classes/local/ltiservice/response.php
|
response.get_reason
|
public function get_reason() {
if (empty($this->reason)) {
$this->reason = $this->responsecodes[$this->code];
}
// Use generic reason for this category (based on first digit) if a specific reason is not defined.
if (empty($this->reason)) {
$this->reason = $this->responsecodes[intval($this->code / 100) * 100];
}
return $this->reason;
}
|
php
|
public function get_reason() {
if (empty($this->reason)) {
$this->reason = $this->responsecodes[$this->code];
}
// Use generic reason for this category (based on first digit) if a specific reason is not defined.
if (empty($this->reason)) {
$this->reason = $this->responsecodes[intval($this->code / 100) * 100];
}
return $this->reason;
}
|
[
"public",
"function",
"get_reason",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"reason",
")",
")",
"{",
"$",
"this",
"->",
"reason",
"=",
"$",
"this",
"->",
"responsecodes",
"[",
"$",
"this",
"->",
"code",
"]",
";",
"}",
"// Use generic reason for this category (based on first digit) if a specific reason is not defined.",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"reason",
")",
")",
"{",
"$",
"this",
"->",
"reason",
"=",
"$",
"this",
"->",
"responsecodes",
"[",
"intval",
"(",
"$",
"this",
"->",
"code",
"/",
"100",
")",
"*",
"100",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"reason",
";",
"}"
] |
Get the response reason.
@return string
|
[
"Get",
"the",
"response",
"reason",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lti/classes/local/ltiservice/response.php#L116-L125
|
219,868
|
moodle/moodle
|
mod/forum/classes/privacy/subcontext_info.php
|
subcontext_info.get_discussion_area
|
protected static function get_discussion_area(\stdClass $discussion) : Array {
$pathparts = [];
if (!empty($discussion->groupname)) {
$pathparts[] = get_string('groups');
$pathparts[] = $discussion->groupname;
}
$parts = [
$discussion->id,
$discussion->name,
];
$discussionname = implode('-', $parts);
$pathparts[] = get_string('discussions', 'mod_forum');
$pathparts[] = $discussionname;
return $pathparts;
}
|
php
|
protected static function get_discussion_area(\stdClass $discussion) : Array {
$pathparts = [];
if (!empty($discussion->groupname)) {
$pathparts[] = get_string('groups');
$pathparts[] = $discussion->groupname;
}
$parts = [
$discussion->id,
$discussion->name,
];
$discussionname = implode('-', $parts);
$pathparts[] = get_string('discussions', 'mod_forum');
$pathparts[] = $discussionname;
return $pathparts;
}
|
[
"protected",
"static",
"function",
"get_discussion_area",
"(",
"\\",
"stdClass",
"$",
"discussion",
")",
":",
"Array",
"{",
"$",
"pathparts",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"discussion",
"->",
"groupname",
")",
")",
"{",
"$",
"pathparts",
"[",
"]",
"=",
"get_string",
"(",
"'groups'",
")",
";",
"$",
"pathparts",
"[",
"]",
"=",
"$",
"discussion",
"->",
"groupname",
";",
"}",
"$",
"parts",
"=",
"[",
"$",
"discussion",
"->",
"id",
",",
"$",
"discussion",
"->",
"name",
",",
"]",
";",
"$",
"discussionname",
"=",
"implode",
"(",
"'-'",
",",
"$",
"parts",
")",
";",
"$",
"pathparts",
"[",
"]",
"=",
"get_string",
"(",
"'discussions'",
",",
"'mod_forum'",
")",
";",
"$",
"pathparts",
"[",
"]",
"=",
"$",
"discussionname",
";",
"return",
"$",
"pathparts",
";",
"}"
] |
Get the discussion part of the subcontext.
@param \stdClass $discussion The discussion
@return array
|
[
"Get",
"the",
"discussion",
"part",
"of",
"the",
"subcontext",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/privacy/subcontext_info.php#L46-L64
|
219,869
|
moodle/moodle
|
mod/forum/classes/privacy/subcontext_info.php
|
subcontext_info.get_post_area
|
protected static function get_post_area(\stdClass $post) : Array {
$parts = [
$post->created,
$post->subject,
$post->id,
];
$area[] = implode('-', $parts);
return $area;
}
|
php
|
protected static function get_post_area(\stdClass $post) : Array {
$parts = [
$post->created,
$post->subject,
$post->id,
];
$area[] = implode('-', $parts);
return $area;
}
|
[
"protected",
"static",
"function",
"get_post_area",
"(",
"\\",
"stdClass",
"$",
"post",
")",
":",
"Array",
"{",
"$",
"parts",
"=",
"[",
"$",
"post",
"->",
"created",
",",
"$",
"post",
"->",
"subject",
",",
"$",
"post",
"->",
"id",
",",
"]",
";",
"$",
"area",
"[",
"]",
"=",
"implode",
"(",
"'-'",
",",
"$",
"parts",
")",
";",
"return",
"$",
"area",
";",
"}"
] |
Get the post part of the subcontext.
@param \stdClass $post The post.
@return array
|
[
"Get",
"the",
"post",
"part",
"of",
"the",
"subcontext",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/privacy/subcontext_info.php#L72-L81
|
219,870
|
moodle/moodle
|
mod/forum/classes/privacy/subcontext_info.php
|
subcontext_info.get_post_area_for_parent
|
protected static function get_post_area_for_parent(\stdClass $post) {
global $DB;
$subcontext = [];
if ($parent = $DB->get_record('forum_posts', ['id' => $post->parent], 'id, created, subject')) {
$subcontext = array_merge($subcontext, static::get_post_area($parent));
}
$subcontext = array_merge($subcontext, static::get_post_area($post));
return $subcontext;
}
|
php
|
protected static function get_post_area_for_parent(\stdClass $post) {
global $DB;
$subcontext = [];
if ($parent = $DB->get_record('forum_posts', ['id' => $post->parent], 'id, created, subject')) {
$subcontext = array_merge($subcontext, static::get_post_area($parent));
}
$subcontext = array_merge($subcontext, static::get_post_area($post));
return $subcontext;
}
|
[
"protected",
"static",
"function",
"get_post_area_for_parent",
"(",
"\\",
"stdClass",
"$",
"post",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"subcontext",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"parent",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'forum_posts'",
",",
"[",
"'id'",
"=>",
"$",
"post",
"->",
"parent",
"]",
",",
"'id, created, subject'",
")",
")",
"{",
"$",
"subcontext",
"=",
"array_merge",
"(",
"$",
"subcontext",
",",
"static",
"::",
"get_post_area",
"(",
"$",
"parent",
")",
")",
";",
"}",
"$",
"subcontext",
"=",
"array_merge",
"(",
"$",
"subcontext",
",",
"static",
"::",
"get_post_area",
"(",
"$",
"post",
")",
")",
";",
"return",
"$",
"subcontext",
";",
"}"
] |
Get the parent subcontext for the supplied forum, discussion, and post combination.
@param \stdClass $post The post.
@return array
|
[
"Get",
"the",
"parent",
"subcontext",
"for",
"the",
"supplied",
"forum",
"discussion",
"and",
"post",
"combination",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/privacy/subcontext_info.php#L89-L99
|
219,871
|
moodle/moodle
|
mod/forum/classes/privacy/subcontext_info.php
|
subcontext_info.get_subcontext
|
protected static function get_subcontext($forum, $discussion = null, $post = null) {
$subcontext = [];
if (null !== $discussion) {
$subcontext += self::get_discussion_area($discussion);
if (null !== $post) {
$subcontext[] = get_string('posts', 'mod_forum');
$subcontext = array_merge($subcontext, static::get_post_area_for_parent($post));
}
}
return $subcontext;
}
|
php
|
protected static function get_subcontext($forum, $discussion = null, $post = null) {
$subcontext = [];
if (null !== $discussion) {
$subcontext += self::get_discussion_area($discussion);
if (null !== $post) {
$subcontext[] = get_string('posts', 'mod_forum');
$subcontext = array_merge($subcontext, static::get_post_area_for_parent($post));
}
}
return $subcontext;
}
|
[
"protected",
"static",
"function",
"get_subcontext",
"(",
"$",
"forum",
",",
"$",
"discussion",
"=",
"null",
",",
"$",
"post",
"=",
"null",
")",
"{",
"$",
"subcontext",
"=",
"[",
"]",
";",
"if",
"(",
"null",
"!==",
"$",
"discussion",
")",
"{",
"$",
"subcontext",
"+=",
"self",
"::",
"get_discussion_area",
"(",
"$",
"discussion",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"post",
")",
"{",
"$",
"subcontext",
"[",
"]",
"=",
"get_string",
"(",
"'posts'",
",",
"'mod_forum'",
")",
";",
"$",
"subcontext",
"=",
"array_merge",
"(",
"$",
"subcontext",
",",
"static",
"::",
"get_post_area_for_parent",
"(",
"$",
"post",
")",
")",
";",
"}",
"}",
"return",
"$",
"subcontext",
";",
"}"
] |
Get the subcontext for the supplied forum, discussion, and post combination.
@param \stdClass $forum The forum.
@param \stdClass $discussion The discussion
@param \stdClass $post The post.
@return array
|
[
"Get",
"the",
"subcontext",
"for",
"the",
"supplied",
"forum",
"discussion",
"and",
"post",
"combination",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/privacy/subcontext_info.php#L109-L122
|
219,872
|
moodle/moodle
|
lib/classes/hub/api.php
|
api.call
|
protected static function call($function, array $data = [], $allowpublic = false) {
$token = registration::get_token() ?: 'publichub';
if (!$allowpublic && $token === 'publichub') {
// This will throw an exception.
registration::require_registration();
}
return self::call_rest($token, $function, $data);
}
|
php
|
protected static function call($function, array $data = [], $allowpublic = false) {
$token = registration::get_token() ?: 'publichub';
if (!$allowpublic && $token === 'publichub') {
// This will throw an exception.
registration::require_registration();
}
return self::call_rest($token, $function, $data);
}
|
[
"protected",
"static",
"function",
"call",
"(",
"$",
"function",
",",
"array",
"$",
"data",
"=",
"[",
"]",
",",
"$",
"allowpublic",
"=",
"false",
")",
"{",
"$",
"token",
"=",
"registration",
"::",
"get_token",
"(",
")",
"?",
":",
"'publichub'",
";",
"if",
"(",
"!",
"$",
"allowpublic",
"&&",
"$",
"token",
"===",
"'publichub'",
")",
"{",
"// This will throw an exception.",
"registration",
"::",
"require_registration",
"(",
")",
";",
"}",
"return",
"self",
"::",
"call_rest",
"(",
"$",
"token",
",",
"$",
"function",
",",
"$",
"data",
")",
";",
"}"
] |
Calls moodle.net WS
@param string $function name of WS function
@param array $data parameters of WS function
@param bool $allowpublic allow request without moodle.net registration
@return mixed depends on the function
@throws moodle_exception
|
[
"Calls",
"moodle",
".",
"net",
"WS"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/hub/api.php#L62-L71
|
219,873
|
moodle/moodle
|
lib/classes/hub/api.php
|
api.process_curl_exception
|
protected static function process_curl_exception($token, $curloutput) {
if (!isset($curloutput['exception'])) {
return;
}
if ($token === registration::get_token()) {
// Check if registration token was rejected or there are other problems with registration.
if (($curloutput['exception'] === 'moodle_exception' && $curloutput['errorcode'] === 'invalidtoken')
|| $curloutput['exception'] === 'registration_exception') {
// Force admin to repeat site registration process.
registration::reset_token();
throw new moodle_exception('errorwstokenreset', 'hub', '', $curloutput['message']);
}
}
throw new moodle_exception('errorws', 'hub', '', $curloutput['message']);
}
|
php
|
protected static function process_curl_exception($token, $curloutput) {
if (!isset($curloutput['exception'])) {
return;
}
if ($token === registration::get_token()) {
// Check if registration token was rejected or there are other problems with registration.
if (($curloutput['exception'] === 'moodle_exception' && $curloutput['errorcode'] === 'invalidtoken')
|| $curloutput['exception'] === 'registration_exception') {
// Force admin to repeat site registration process.
registration::reset_token();
throw new moodle_exception('errorwstokenreset', 'hub', '', $curloutput['message']);
}
}
throw new moodle_exception('errorws', 'hub', '', $curloutput['message']);
}
|
[
"protected",
"static",
"function",
"process_curl_exception",
"(",
"$",
"token",
",",
"$",
"curloutput",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"curloutput",
"[",
"'exception'",
"]",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"token",
"===",
"registration",
"::",
"get_token",
"(",
")",
")",
"{",
"// Check if registration token was rejected or there are other problems with registration.",
"if",
"(",
"(",
"$",
"curloutput",
"[",
"'exception'",
"]",
"===",
"'moodle_exception'",
"&&",
"$",
"curloutput",
"[",
"'errorcode'",
"]",
"===",
"'invalidtoken'",
")",
"||",
"$",
"curloutput",
"[",
"'exception'",
"]",
"===",
"'registration_exception'",
")",
"{",
"// Force admin to repeat site registration process.",
"registration",
"::",
"reset_token",
"(",
")",
";",
"throw",
"new",
"moodle_exception",
"(",
"'errorwstokenreset'",
",",
"'hub'",
",",
"''",
",",
"$",
"curloutput",
"[",
"'message'",
"]",
")",
";",
"}",
"}",
"throw",
"new",
"moodle_exception",
"(",
"'errorws'",
",",
"'hub'",
",",
"''",
",",
"$",
"curloutput",
"[",
"'message'",
"]",
")",
";",
"}"
] |
Analyses exception received from moodle.net
@param string $token token used for CURL request
@param array $curloutput output from CURL request
@throws moodle_exception
|
[
"Analyses",
"exception",
"received",
"from",
"moodle",
".",
"net"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/hub/api.php#L113-L127
|
219,874
|
moodle/moodle
|
lib/classes/hub/api.php
|
api.get_hub_info
|
public static function get_hub_info() {
$info = self::call('hub_get_info', [], true);
$info['imgurl'] = new moodle_url(HUB_MOODLEORGHUBURL . '/local/hub/webservice/download.php',
['filetype' => self::HUB_HUBSCREENSHOT_FILE_TYPE]);
return $info;
}
|
php
|
public static function get_hub_info() {
$info = self::call('hub_get_info', [], true);
$info['imgurl'] = new moodle_url(HUB_MOODLEORGHUBURL . '/local/hub/webservice/download.php',
['filetype' => self::HUB_HUBSCREENSHOT_FILE_TYPE]);
return $info;
}
|
[
"public",
"static",
"function",
"get_hub_info",
"(",
")",
"{",
"$",
"info",
"=",
"self",
"::",
"call",
"(",
"'hub_get_info'",
",",
"[",
"]",
",",
"true",
")",
";",
"$",
"info",
"[",
"'imgurl'",
"]",
"=",
"new",
"moodle_url",
"(",
"HUB_MOODLEORGHUBURL",
".",
"'/local/hub/webservice/download.php'",
",",
"[",
"'filetype'",
"=>",
"self",
"::",
"HUB_HUBSCREENSHOT_FILE_TYPE",
"]",
")",
";",
"return",
"$",
"info",
";",
"}"
] |
Returns information about moodle.net
Example of the return array:
{
"courses": 384,
"description": "Moodle.net connects you with free content and courses shared by Moodle ...",
"downloadablecourses": 190,
"enrollablecourses": 194,
"hublogo": 1,
"language": "en",
"name": "Moodle.net",
"sites": 274175,
"url": "https://moodle.net",
"imgurl": "https://moodle.net/local/hub/webservice/download.php?filetype=hubscreenshot"
}
@return array
@throws moodle_exception
|
[
"Returns",
"information",
"about",
"moodle",
".",
"net"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/hub/api.php#L160-L165
|
219,875
|
moodle/moodle
|
lib/classes/hub/api.php
|
api.get_courses
|
public static function get_courses($search, $downloadable, $enrollable, $options) {
static $availableoptions = ['ids', 'sitecourseids', 'coverage', 'licenceshortname', 'subject', 'audience',
'educationallevel', 'language', 'orderby', 'givememore', 'allsitecourses'];
if (empty($options)) {
$options = [];
} else if (is_object($options)) {
$options = (array)$options;
} else if (!is_array($options)) {
throw new \coding_exception('Parameter $options is invalid');
}
if ($unknownkeys = array_diff(array_keys($options), $availableoptions)) {
throw new \coding_exception('Unknown option(s): ' . join(', ', $unknownkeys));
}
$params = [
'search' => $search,
'downloadable' => (int)(bool)$downloadable,
'enrollable' => (int)(bool)$enrollable,
'options' => $options
];
$result = self::call('hub_get_courses', $params, true);
$courses = $result['courses'];
$coursetotal = $result['coursetotal'];
foreach ($courses as $idx => $course) {
$courses[$idx]['screenshotbaseurl'] = null;
if (!empty($course['screenshots'])) {
$courses[$idx]['screenshotbaseurl'] = new moodle_url(HUB_MOODLEORGHUBURL . '/local/hub/webservice/download.php',
array('courseid' => $course['id'],
'filetype' => self::HUB_SCREENSHOT_FILE_TYPE));
}
$courses[$idx]['commenturl'] = new moodle_url(HUB_MOODLEORGHUBURL,
array('courseid' => $course['id'], 'mustbelogged' => true));
}
return [$courses, $coursetotal];
}
|
php
|
public static function get_courses($search, $downloadable, $enrollable, $options) {
static $availableoptions = ['ids', 'sitecourseids', 'coverage', 'licenceshortname', 'subject', 'audience',
'educationallevel', 'language', 'orderby', 'givememore', 'allsitecourses'];
if (empty($options)) {
$options = [];
} else if (is_object($options)) {
$options = (array)$options;
} else if (!is_array($options)) {
throw new \coding_exception('Parameter $options is invalid');
}
if ($unknownkeys = array_diff(array_keys($options), $availableoptions)) {
throw new \coding_exception('Unknown option(s): ' . join(', ', $unknownkeys));
}
$params = [
'search' => $search,
'downloadable' => (int)(bool)$downloadable,
'enrollable' => (int)(bool)$enrollable,
'options' => $options
];
$result = self::call('hub_get_courses', $params, true);
$courses = $result['courses'];
$coursetotal = $result['coursetotal'];
foreach ($courses as $idx => $course) {
$courses[$idx]['screenshotbaseurl'] = null;
if (!empty($course['screenshots'])) {
$courses[$idx]['screenshotbaseurl'] = new moodle_url(HUB_MOODLEORGHUBURL . '/local/hub/webservice/download.php',
array('courseid' => $course['id'],
'filetype' => self::HUB_SCREENSHOT_FILE_TYPE));
}
$courses[$idx]['commenturl'] = new moodle_url(HUB_MOODLEORGHUBURL,
array('courseid' => $course['id'], 'mustbelogged' => true));
}
return [$courses, $coursetotal];
}
|
[
"public",
"static",
"function",
"get_courses",
"(",
"$",
"search",
",",
"$",
"downloadable",
",",
"$",
"enrollable",
",",
"$",
"options",
")",
"{",
"static",
"$",
"availableoptions",
"=",
"[",
"'ids'",
",",
"'sitecourseids'",
",",
"'coverage'",
",",
"'licenceshortname'",
",",
"'subject'",
",",
"'audience'",
",",
"'educationallevel'",
",",
"'language'",
",",
"'orderby'",
",",
"'givememore'",
",",
"'allsitecourses'",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"options",
")",
")",
"{",
"$",
"options",
"=",
"[",
"]",
";",
"}",
"else",
"if",
"(",
"is_object",
"(",
"$",
"options",
")",
")",
"{",
"$",
"options",
"=",
"(",
"array",
")",
"$",
"options",
";",
"}",
"else",
"if",
"(",
"!",
"is_array",
"(",
"$",
"options",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Parameter $options is invalid'",
")",
";",
"}",
"if",
"(",
"$",
"unknownkeys",
"=",
"array_diff",
"(",
"array_keys",
"(",
"$",
"options",
")",
",",
"$",
"availableoptions",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Unknown option(s): '",
".",
"join",
"(",
"', '",
",",
"$",
"unknownkeys",
")",
")",
";",
"}",
"$",
"params",
"=",
"[",
"'search'",
"=>",
"$",
"search",
",",
"'downloadable'",
"=>",
"(",
"int",
")",
"(",
"bool",
")",
"$",
"downloadable",
",",
"'enrollable'",
"=>",
"(",
"int",
")",
"(",
"bool",
")",
"$",
"enrollable",
",",
"'options'",
"=>",
"$",
"options",
"]",
";",
"$",
"result",
"=",
"self",
"::",
"call",
"(",
"'hub_get_courses'",
",",
"$",
"params",
",",
"true",
")",
";",
"$",
"courses",
"=",
"$",
"result",
"[",
"'courses'",
"]",
";",
"$",
"coursetotal",
"=",
"$",
"result",
"[",
"'coursetotal'",
"]",
";",
"foreach",
"(",
"$",
"courses",
"as",
"$",
"idx",
"=>",
"$",
"course",
")",
"{",
"$",
"courses",
"[",
"$",
"idx",
"]",
"[",
"'screenshotbaseurl'",
"]",
"=",
"null",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"course",
"[",
"'screenshots'",
"]",
")",
")",
"{",
"$",
"courses",
"[",
"$",
"idx",
"]",
"[",
"'screenshotbaseurl'",
"]",
"=",
"new",
"moodle_url",
"(",
"HUB_MOODLEORGHUBURL",
".",
"'/local/hub/webservice/download.php'",
",",
"array",
"(",
"'courseid'",
"=>",
"$",
"course",
"[",
"'id'",
"]",
",",
"'filetype'",
"=>",
"self",
"::",
"HUB_SCREENSHOT_FILE_TYPE",
")",
")",
";",
"}",
"$",
"courses",
"[",
"$",
"idx",
"]",
"[",
"'commenturl'",
"]",
"=",
"new",
"moodle_url",
"(",
"HUB_MOODLEORGHUBURL",
",",
"array",
"(",
"'courseid'",
"=>",
"$",
"course",
"[",
"'id'",
"]",
",",
"'mustbelogged'",
"=>",
"true",
")",
")",
";",
"}",
"return",
"[",
"$",
"courses",
",",
"$",
"coursetotal",
"]",
";",
"}"
] |
Calls WS function hub_get_courses
Parameter $options may have any of these fields:
[
'ids' => new external_multiple_structure(new external_value(PARAM_INTEGER, 'id of a course in the hub course
directory'), 'ids of course', VALUE_OPTIONAL),
'sitecourseids' => new external_multiple_structure(new external_value(PARAM_INTEGER, 'id of a course in the
site'), 'ids of course in the site', VALUE_OPTIONAL),
'coverage' => new external_value(PARAM_TEXT, 'coverage', VALUE_OPTIONAL),
'licenceshortname' => new external_value(PARAM_ALPHANUMEXT, 'licence short name', VALUE_OPTIONAL),
'subject' => new external_value(PARAM_ALPHANUM, 'subject', VALUE_OPTIONAL),
'audience' => new external_value(PARAM_ALPHA, 'audience', VALUE_OPTIONAL),
'educationallevel' => new external_value(PARAM_ALPHA, 'educational level', VALUE_OPTIONAL),
'language' => new external_value(PARAM_ALPHANUMEXT, 'language', VALUE_OPTIONAL),
'orderby' => new external_value(PARAM_ALPHA, 'orderby method: newest, eldest, publisher, fullname,
ratingaverage', VALUE_OPTIONAL),
'givememore' => new external_value(PARAM_INT, 'next range of result - range size being set by the hub
server ', VALUE_OPTIONAL),
'allsitecourses' => new external_value(PARAM_INTEGER,
'if 1 return all not visible and visible courses whose siteid is the site
matching token. Only courses of this site are returned.
givememore parameter is ignored if this param = 1.
In case of public token access, this param option is ignored', VALUE_DEFAULT, 0),
]
Each course in the returned array of courses will have fields:
[
'id' => new external_value(PARAM_INTEGER, 'id'),
'fullname' => new external_value(PARAM_TEXT, 'course name'),
'shortname' => new external_value(PARAM_TEXT, 'course short name'),
'description' => new external_value(PARAM_TEXT, 'course description'),
'language' => new external_value(PARAM_ALPHANUMEXT, 'course language'),
'publishername' => new external_value(PARAM_TEXT, 'publisher name'),
'publisheremail' => new external_value(PARAM_EMAIL, 'publisher email', VALUE_OPTIONAL),
'privacy' => new external_value(PARAM_INT, 'privacy: published or not', VALUE_OPTIONAL),
'sitecourseid' => new external_value(PARAM_INT, 'course id on the site', VALUE_OPTIONAL),
'contributornames' => new external_value(PARAM_TEXT, 'contributor names', VALUE_OPTIONAL),
'coverage' => new external_value(PARAM_TEXT, 'coverage', VALUE_OPTIONAL),
'creatorname' => new external_value(PARAM_TEXT, 'creator name'),
'licenceshortname' => new external_value(PARAM_ALPHANUMEXT, 'licence short name'),
'subject' => new external_value(PARAM_ALPHANUM, 'subject'),
'audience' => new external_value(PARAM_ALPHA, 'audience'),
'educationallevel' => new external_value(PARAM_ALPHA, 'educational level'),
'creatornotes' => new external_value(PARAM_RAW, 'creator notes'),
'creatornotesformat' => new external_value(PARAM_INTEGER, 'notes format'),
'demourl' => new external_value(PARAM_URL, 'demo URL', VALUE_OPTIONAL),
'courseurl' => new external_value(PARAM_URL, 'course URL', VALUE_OPTIONAL),
'backupsize' => new external_value(PARAM_INT, 'course backup size in bytes', VALUE_OPTIONAL),
'enrollable' => new external_value(PARAM_BOOL, 'is the course enrollable'),
'screenshots' => new external_value(PARAM_INT, 'total number of screenshots'),
'timemodified' => new external_value(PARAM_INT, 'time of last modification - timestamp'),
'contents' => new external_multiple_structure(new external_single_structure(
array(
'moduletype' => new external_value(PARAM_ALPHA, 'the type of module (activity/block)'),
'modulename' => new external_value(PARAM_TEXT, 'the name of the module (forum, resource etc)'),
'contentcount' => new external_value(PARAM_INT, 'how many time the module is used in the course'),
)), 'contents', VALUE_OPTIONAL),
'rating' => new external_single_structure (
array(
'aggregate' => new external_value(PARAM_FLOAT, 'Rating average', VALUE_OPTIONAL),
'scaleid' => new external_value(PARAM_INT, 'Rating scale'),
'count' => new external_value(PARAM_INT, 'Rating count'),
), 'rating', VALUE_OPTIONAL),
'comments' => new external_multiple_structure(new external_single_structure (
array(
'comment' => new external_value(PARAM_TEXT, 'the comment'),
'commentator' => new external_value(PARAM_TEXT, 'the name of commentator'),
'date' => new external_value(PARAM_INT, 'date of the comment'),
)), 'contents', VALUE_OPTIONAL),
'outcomes' => new external_multiple_structure(new external_single_structure(
array(
'fullname' => new external_value(PARAM_TEXT, 'the outcome fullname')
)), 'outcomes', VALUE_OPTIONAL)
]
Additional fields for each course:
'screenshotbaseurl' (moodle_url) URL of the first screenshot, only set if $course['screenshots']>0
'commenturl' (moodle_url) URL for comments
@param string $search search string
@param bool $downloadable return downloadable courses
@param bool $enrollable return enrollable courses
@param array|\stdClass $options other options from the list of allowed options:
'ids', 'sitecourseids', 'coverage', 'licenceshortname', 'subject', 'audience',
'educationallevel', 'language', 'orderby', 'givememore', 'allsitecourses'
@return array of two elements: [$courses, $coursetotal]
@throws \coding_exception
@throws moodle_exception
|
[
"Calls",
"WS",
"function",
"hub_get_courses"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/hub/api.php#L257-L295
|
219,876
|
moodle/moodle
|
lib/classes/hub/api.php
|
api.register_course
|
public static function register_course($courseinfo) {
$params = array('courses' => array($courseinfo));
$hubcourseids = self::call('hub_register_courses', $params);
if (count($hubcourseids) != 1) {
throw new moodle_exception('errorcoursewronglypublished', 'hub');
}
return $hubcourseids[0];
}
|
php
|
public static function register_course($courseinfo) {
$params = array('courses' => array($courseinfo));
$hubcourseids = self::call('hub_register_courses', $params);
if (count($hubcourseids) != 1) {
throw new moodle_exception('errorcoursewronglypublished', 'hub');
}
return $hubcourseids[0];
}
|
[
"public",
"static",
"function",
"register_course",
"(",
"$",
"courseinfo",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'courses'",
"=>",
"array",
"(",
"$",
"courseinfo",
")",
")",
";",
"$",
"hubcourseids",
"=",
"self",
"::",
"call",
"(",
"'hub_register_courses'",
",",
"$",
"params",
")",
";",
"if",
"(",
"count",
"(",
"$",
"hubcourseids",
")",
"!=",
"1",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'errorcoursewronglypublished'",
",",
"'hub'",
")",
";",
"}",
"return",
"$",
"hubcourseids",
"[",
"0",
"]",
";",
"}"
] |
Publish one course
Expected contents of $courseinfo:
[
'sitecourseid' => new external_value(PARAM_INT, 'the id of the course on the publishing site'),
'fullname' => new external_value(PARAM_TEXT, 'course name'),
'shortname' => new external_value(PARAM_TEXT, 'course short name'),
'description' => new external_value(PARAM_TEXT, 'course description'),
'language' => new external_value(PARAM_ALPHANUMEXT, 'course language'),
'publishername' => new external_value(PARAM_TEXT, 'publisher name'),
'publisheremail' => new external_value(PARAM_EMAIL, 'publisher email'),
'contributornames' => new external_value(PARAM_TEXT, 'contributor names'),
'coverage' => new external_value(PARAM_TEXT, 'coverage'),
'creatorname' => new external_value(PARAM_TEXT, 'creator name'),
'licenceshortname' => new external_value(PARAM_ALPHANUMEXT, 'licence short name'),
'subject' => new external_value(PARAM_ALPHANUM, 'subject'),
'audience' => new external_value(PARAM_ALPHA, 'audience'),
'educationallevel' => new external_value(PARAM_ALPHA, 'educational level'),
'creatornotes' => new external_value(PARAM_RAW, 'creator notes'),
'creatornotesformat' => new external_value(PARAM_INTEGER, 'notes format'),
'demourl' => new external_value(PARAM_URL, 'demo URL', VALUE_OPTIONAL),
'courseurl' => new external_value(PARAM_URL, 'course URL', VALUE_OPTIONAL),
'enrollable' => new external_value(PARAM_BOOL, 'is the course enrollable', VALUE_DEFAULT, 0),
'screenshots' => new external_value(PARAM_INT, 'the number of screenhots', VALUE_OPTIONAL),
'deletescreenshots' => new external_value(PARAM_INT, 'ask to delete all the existing screenshot files
(it does not reset the screenshot number)', VALUE_DEFAULT, 0),
'contents' => new external_multiple_structure(new external_single_structure(
array(
'moduletype' => new external_value(PARAM_ALPHA, 'the type of module (activity/block)'),
'modulename' => new external_value(PARAM_TEXT, 'the name of the module (forum, resource etc)'),
'contentcount' => new external_value(PARAM_INT, 'how many time the module is used in the course'),
)), 'contents', VALUE_OPTIONAL),
'outcomes' => new external_multiple_structure(new external_single_structure(
array(
'fullname' => new external_value(PARAM_TEXT, 'the outcome fullname')
)), 'outcomes', VALUE_OPTIONAL)
]
@param array|\stdClass $courseinfo
@return int id of the published course on the hub
@throws moodle_exception if communication to moodle.net failed or course could not be published
|
[
"Publish",
"one",
"course"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/hub/api.php#L362-L369
|
219,877
|
moodle/moodle
|
lib/classes/hub/api.php
|
api.add_screenshot
|
public static function add_screenshot($hubcourseid, \stored_file $file, $screenshotnumber) {
$curl = new \curl();
$params = array();
$params['filetype'] = self::HUB_SCREENSHOT_FILE_TYPE;
$params['file'] = $file;
$params['courseid'] = $hubcourseid;
$params['filename'] = $file->get_filename();
$params['screenshotnumber'] = $screenshotnumber;
$params['token'] = registration::get_token(MUST_EXIST);
$curl->post(HUB_MOODLEORGHUBURL . "/local/hub/webservice/upload.php", $params);
}
|
php
|
public static function add_screenshot($hubcourseid, \stored_file $file, $screenshotnumber) {
$curl = new \curl();
$params = array();
$params['filetype'] = self::HUB_SCREENSHOT_FILE_TYPE;
$params['file'] = $file;
$params['courseid'] = $hubcourseid;
$params['filename'] = $file->get_filename();
$params['screenshotnumber'] = $screenshotnumber;
$params['token'] = registration::get_token(MUST_EXIST);
$curl->post(HUB_MOODLEORGHUBURL . "/local/hub/webservice/upload.php", $params);
}
|
[
"public",
"static",
"function",
"add_screenshot",
"(",
"$",
"hubcourseid",
",",
"\\",
"stored_file",
"$",
"file",
",",
"$",
"screenshotnumber",
")",
"{",
"$",
"curl",
"=",
"new",
"\\",
"curl",
"(",
")",
";",
"$",
"params",
"=",
"array",
"(",
")",
";",
"$",
"params",
"[",
"'filetype'",
"]",
"=",
"self",
"::",
"HUB_SCREENSHOT_FILE_TYPE",
";",
"$",
"params",
"[",
"'file'",
"]",
"=",
"$",
"file",
";",
"$",
"params",
"[",
"'courseid'",
"]",
"=",
"$",
"hubcourseid",
";",
"$",
"params",
"[",
"'filename'",
"]",
"=",
"$",
"file",
"->",
"get_filename",
"(",
")",
";",
"$",
"params",
"[",
"'screenshotnumber'",
"]",
"=",
"$",
"screenshotnumber",
";",
"$",
"params",
"[",
"'token'",
"]",
"=",
"registration",
"::",
"get_token",
"(",
"MUST_EXIST",
")",
";",
"$",
"curl",
"->",
"post",
"(",
"HUB_MOODLEORGHUBURL",
".",
"\"/local/hub/webservice/upload.php\"",
",",
"$",
"params",
")",
";",
"}"
] |
Uploads a screenshot for the published course
@param int $hubcourseid id of the published course on moodle.net, it must be published from this site
@param \stored_file $file
@param int $screenshotnumber ordinal number of the screenshot
|
[
"Uploads",
"a",
"screenshot",
"for",
"the",
"published",
"course"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/hub/api.php#L378-L388
|
219,878
|
moodle/moodle
|
lib/classes/hub/api.php
|
api.download_course_backup
|
public static function download_course_backup($hubcourseid, $path) {
$fp = fopen($path, 'w');
$curlurl = new \moodle_url(HUB_MOODLEORGHUBURL . '/local/hub/webservice/download.php',
['filetype' => self::HUB_BACKUP_FILE_TYPE, 'courseid' => $hubcourseid]);
// Send an identification token if the site is registered.
if ($token = registration::get_token()) {
$curlurl->param('token', $token);
}
$ch = curl_init($curlurl->out(false));
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec($ch);
curl_close($ch);
fclose($fp);
}
|
php
|
public static function download_course_backup($hubcourseid, $path) {
$fp = fopen($path, 'w');
$curlurl = new \moodle_url(HUB_MOODLEORGHUBURL . '/local/hub/webservice/download.php',
['filetype' => self::HUB_BACKUP_FILE_TYPE, 'courseid' => $hubcourseid]);
// Send an identification token if the site is registered.
if ($token = registration::get_token()) {
$curlurl->param('token', $token);
}
$ch = curl_init($curlurl->out(false));
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec($ch);
curl_close($ch);
fclose($fp);
}
|
[
"public",
"static",
"function",
"download_course_backup",
"(",
"$",
"hubcourseid",
",",
"$",
"path",
")",
"{",
"$",
"fp",
"=",
"fopen",
"(",
"$",
"path",
",",
"'w'",
")",
";",
"$",
"curlurl",
"=",
"new",
"\\",
"moodle_url",
"(",
"HUB_MOODLEORGHUBURL",
".",
"'/local/hub/webservice/download.php'",
",",
"[",
"'filetype'",
"=>",
"self",
"::",
"HUB_BACKUP_FILE_TYPE",
",",
"'courseid'",
"=>",
"$",
"hubcourseid",
"]",
")",
";",
"// Send an identification token if the site is registered.",
"if",
"(",
"$",
"token",
"=",
"registration",
"::",
"get_token",
"(",
")",
")",
"{",
"$",
"curlurl",
"->",
"param",
"(",
"'token'",
",",
"$",
"token",
")",
";",
"}",
"$",
"ch",
"=",
"curl_init",
"(",
"$",
"curlurl",
"->",
"out",
"(",
"false",
")",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_FILE",
",",
"$",
"fp",
")",
";",
"curl_exec",
"(",
"$",
"ch",
")",
";",
"curl_close",
"(",
"$",
"ch",
")",
";",
"fclose",
"(",
"$",
"fp",
")",
";",
"}"
] |
Downloads course backup
@param int $hubcourseid id of the course on moodle.net
@param string $path local path (in tempdir) to save the downloaded backup to.
|
[
"Downloads",
"course",
"backup"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/hub/api.php#L396-L412
|
219,879
|
moodle/moodle
|
lib/classes/hub/api.php
|
api.upload_course_backup
|
public static function upload_course_backup($hubcourseid, \stored_file $backupfile) {
$curl = new \curl();
$params = array();
$params['filetype'] = self::HUB_BACKUP_FILE_TYPE;
$params['courseid'] = $hubcourseid;
$params['file'] = $backupfile;
$params['token'] = registration::get_token();
$curl->post(HUB_MOODLEORGHUBURL . '/local/hub/webservice/upload.php', $params);
}
|
php
|
public static function upload_course_backup($hubcourseid, \stored_file $backupfile) {
$curl = new \curl();
$params = array();
$params['filetype'] = self::HUB_BACKUP_FILE_TYPE;
$params['courseid'] = $hubcourseid;
$params['file'] = $backupfile;
$params['token'] = registration::get_token();
$curl->post(HUB_MOODLEORGHUBURL . '/local/hub/webservice/upload.php', $params);
}
|
[
"public",
"static",
"function",
"upload_course_backup",
"(",
"$",
"hubcourseid",
",",
"\\",
"stored_file",
"$",
"backupfile",
")",
"{",
"$",
"curl",
"=",
"new",
"\\",
"curl",
"(",
")",
";",
"$",
"params",
"=",
"array",
"(",
")",
";",
"$",
"params",
"[",
"'filetype'",
"]",
"=",
"self",
"::",
"HUB_BACKUP_FILE_TYPE",
";",
"$",
"params",
"[",
"'courseid'",
"]",
"=",
"$",
"hubcourseid",
";",
"$",
"params",
"[",
"'file'",
"]",
"=",
"$",
"backupfile",
";",
"$",
"params",
"[",
"'token'",
"]",
"=",
"registration",
"::",
"get_token",
"(",
")",
";",
"$",
"curl",
"->",
"post",
"(",
"HUB_MOODLEORGHUBURL",
".",
"'/local/hub/webservice/upload.php'",
",",
"$",
"params",
")",
";",
"}"
] |
Uploads a course backup
@param int $hubcourseid id of the published course on moodle.net, it must be published from this site
@param \stored_file $backupfile
|
[
"Uploads",
"a",
"course",
"backup"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/hub/api.php#L420-L428
|
219,880
|
moodle/moodle
|
mod/assign/feedback/editpdf/fpdi/filters/FilterLZW.php
|
FilterLZW.decode
|
public function decode($data)
{
if ($data[0] == 0x00 && $data[1] == 0x01) {
throw new Exception('LZW flavour not supported.');
}
$this->_initsTable();
$this->_data = $data;
$this->_dataLength = strlen($data);
// Initialize pointers
$this->_bytePointer = 0;
$this->_bitPointer = 0;
$this->_nextData = 0;
$this->_nextBits = 0;
$oldCode = 0;
$unCompData = '';
while (($code = $this->_getNextCode()) != 257) {
if ($code == 256) {
$this->_initsTable();
$code = $this->_getNextCode();
if ($code == 257) {
break;
}
if (!isset($this->_sTable[$code])) {
throw new Exception('Error while decompression LZW compressed data.');
}
$unCompData .= $this->_sTable[$code];
$oldCode = $code;
} else {
if ($code < $this->_tIdx) {
$string = $this->_sTable[$code];
$unCompData .= $string;
$this->_addStringToTable($this->_sTable[$oldCode], $string[0]);
$oldCode = $code;
} else {
$string = $this->_sTable[$oldCode];
$string = $string . $string[0];
$unCompData .= $string;
$this->_addStringToTable($string);
$oldCode = $code;
}
}
}
return $unCompData;
}
|
php
|
public function decode($data)
{
if ($data[0] == 0x00 && $data[1] == 0x01) {
throw new Exception('LZW flavour not supported.');
}
$this->_initsTable();
$this->_data = $data;
$this->_dataLength = strlen($data);
// Initialize pointers
$this->_bytePointer = 0;
$this->_bitPointer = 0;
$this->_nextData = 0;
$this->_nextBits = 0;
$oldCode = 0;
$unCompData = '';
while (($code = $this->_getNextCode()) != 257) {
if ($code == 256) {
$this->_initsTable();
$code = $this->_getNextCode();
if ($code == 257) {
break;
}
if (!isset($this->_sTable[$code])) {
throw new Exception('Error while decompression LZW compressed data.');
}
$unCompData .= $this->_sTable[$code];
$oldCode = $code;
} else {
if ($code < $this->_tIdx) {
$string = $this->_sTable[$code];
$unCompData .= $string;
$this->_addStringToTable($this->_sTable[$oldCode], $string[0]);
$oldCode = $code;
} else {
$string = $this->_sTable[$oldCode];
$string = $string . $string[0];
$unCompData .= $string;
$this->_addStringToTable($string);
$oldCode = $code;
}
}
}
return $unCompData;
}
|
[
"public",
"function",
"decode",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"data",
"[",
"0",
"]",
"==",
"0x00",
"&&",
"$",
"data",
"[",
"1",
"]",
"==",
"0x01",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'LZW flavour not supported.'",
")",
";",
"}",
"$",
"this",
"->",
"_initsTable",
"(",
")",
";",
"$",
"this",
"->",
"_data",
"=",
"$",
"data",
";",
"$",
"this",
"->",
"_dataLength",
"=",
"strlen",
"(",
"$",
"data",
")",
";",
"// Initialize pointers",
"$",
"this",
"->",
"_bytePointer",
"=",
"0",
";",
"$",
"this",
"->",
"_bitPointer",
"=",
"0",
";",
"$",
"this",
"->",
"_nextData",
"=",
"0",
";",
"$",
"this",
"->",
"_nextBits",
"=",
"0",
";",
"$",
"oldCode",
"=",
"0",
";",
"$",
"unCompData",
"=",
"''",
";",
"while",
"(",
"(",
"$",
"code",
"=",
"$",
"this",
"->",
"_getNextCode",
"(",
")",
")",
"!=",
"257",
")",
"{",
"if",
"(",
"$",
"code",
"==",
"256",
")",
"{",
"$",
"this",
"->",
"_initsTable",
"(",
")",
";",
"$",
"code",
"=",
"$",
"this",
"->",
"_getNextCode",
"(",
")",
";",
"if",
"(",
"$",
"code",
"==",
"257",
")",
"{",
"break",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_sTable",
"[",
"$",
"code",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Error while decompression LZW compressed data.'",
")",
";",
"}",
"$",
"unCompData",
".=",
"$",
"this",
"->",
"_sTable",
"[",
"$",
"code",
"]",
";",
"$",
"oldCode",
"=",
"$",
"code",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"code",
"<",
"$",
"this",
"->",
"_tIdx",
")",
"{",
"$",
"string",
"=",
"$",
"this",
"->",
"_sTable",
"[",
"$",
"code",
"]",
";",
"$",
"unCompData",
".=",
"$",
"string",
";",
"$",
"this",
"->",
"_addStringToTable",
"(",
"$",
"this",
"->",
"_sTable",
"[",
"$",
"oldCode",
"]",
",",
"$",
"string",
"[",
"0",
"]",
")",
";",
"$",
"oldCode",
"=",
"$",
"code",
";",
"}",
"else",
"{",
"$",
"string",
"=",
"$",
"this",
"->",
"_sTable",
"[",
"$",
"oldCode",
"]",
";",
"$",
"string",
"=",
"$",
"string",
".",
"$",
"string",
"[",
"0",
"]",
";",
"$",
"unCompData",
".=",
"$",
"string",
";",
"$",
"this",
"->",
"_addStringToTable",
"(",
"$",
"string",
")",
";",
"$",
"oldCode",
"=",
"$",
"code",
";",
"}",
"}",
"}",
"return",
"$",
"unCompData",
";",
"}"
] |
Decodes LZW compressed data.
@param string $data The compressed data.
@throws Exception
@return string
|
[
"Decodes",
"LZW",
"compressed",
"data",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/fpdi/filters/FilterLZW.php#L34-L92
|
219,881
|
moodle/moodle
|
mod/assign/feedback/editpdf/fpdi/filters/FilterLZW.php
|
FilterLZW._getNextCode
|
protected function _getNextCode()
{
if ($this->_bytePointer == $this->_dataLength) {
return 257;
}
$this->_nextData = ($this->_nextData << 8) | (ord($this->_data[$this->_bytePointer++]) & 0xff);
$this->_nextBits += 8;
if ($this->_nextBits < $this->_bitsToGet) {
$this->_nextData = ($this->_nextData << 8) | (ord($this->_data[$this->_bytePointer++]) & 0xff);
$this->_nextBits += 8;
}
$code = ($this->_nextData >> ($this->_nextBits - $this->_bitsToGet)) & $this->_andTable[$this->_bitsToGet-9];
$this->_nextBits -= $this->_bitsToGet;
return $code;
}
|
php
|
protected function _getNextCode()
{
if ($this->_bytePointer == $this->_dataLength) {
return 257;
}
$this->_nextData = ($this->_nextData << 8) | (ord($this->_data[$this->_bytePointer++]) & 0xff);
$this->_nextBits += 8;
if ($this->_nextBits < $this->_bitsToGet) {
$this->_nextData = ($this->_nextData << 8) | (ord($this->_data[$this->_bytePointer++]) & 0xff);
$this->_nextBits += 8;
}
$code = ($this->_nextData >> ($this->_nextBits - $this->_bitsToGet)) & $this->_andTable[$this->_bitsToGet-9];
$this->_nextBits -= $this->_bitsToGet;
return $code;
}
|
[
"protected",
"function",
"_getNextCode",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_bytePointer",
"==",
"$",
"this",
"->",
"_dataLength",
")",
"{",
"return",
"257",
";",
"}",
"$",
"this",
"->",
"_nextData",
"=",
"(",
"$",
"this",
"->",
"_nextData",
"<<",
"8",
")",
"|",
"(",
"ord",
"(",
"$",
"this",
"->",
"_data",
"[",
"$",
"this",
"->",
"_bytePointer",
"++",
"]",
")",
"&",
"0xff",
")",
";",
"$",
"this",
"->",
"_nextBits",
"+=",
"8",
";",
"if",
"(",
"$",
"this",
"->",
"_nextBits",
"<",
"$",
"this",
"->",
"_bitsToGet",
")",
"{",
"$",
"this",
"->",
"_nextData",
"=",
"(",
"$",
"this",
"->",
"_nextData",
"<<",
"8",
")",
"|",
"(",
"ord",
"(",
"$",
"this",
"->",
"_data",
"[",
"$",
"this",
"->",
"_bytePointer",
"++",
"]",
")",
"&",
"0xff",
")",
";",
"$",
"this",
"->",
"_nextBits",
"+=",
"8",
";",
"}",
"$",
"code",
"=",
"(",
"$",
"this",
"->",
"_nextData",
">>",
"(",
"$",
"this",
"->",
"_nextBits",
"-",
"$",
"this",
"->",
"_bitsToGet",
")",
")",
"&",
"$",
"this",
"->",
"_andTable",
"[",
"$",
"this",
"->",
"_bitsToGet",
"-",
"9",
"]",
";",
"$",
"this",
"->",
"_nextBits",
"-=",
"$",
"this",
"->",
"_bitsToGet",
";",
"return",
"$",
"code",
";",
"}"
] |
Returns the next 9, 10, 11 or 12 bits
@return int
|
[
"Returns",
"the",
"next",
"9",
"10",
"11",
"or",
"12",
"bits"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/fpdi/filters/FilterLZW.php#L133-L151
|
219,882
|
moodle/moodle
|
lib/phpunit/classes/coverage_info.php
|
phpunit_coverage_info.get_whitelists
|
final public function get_whitelists(string $plugindir) : array {
$filters = [];
if (!empty($plugindir)) {
$plugindir .= "/";
}
foreach ($this->whitelistfolders as $folder) {
$filters[] = html_writer::tag('directory', "{$plugindir}{$folder}", ['suffix' => '.php']);
}
foreach ($this->whitelistfiles as $file) {
$filters[] = html_writer::tag('file', "{$plugindir}{$file}");
}
return $filters;
}
|
php
|
final public function get_whitelists(string $plugindir) : array {
$filters = [];
if (!empty($plugindir)) {
$plugindir .= "/";
}
foreach ($this->whitelistfolders as $folder) {
$filters[] = html_writer::tag('directory', "{$plugindir}{$folder}", ['suffix' => '.php']);
}
foreach ($this->whitelistfiles as $file) {
$filters[] = html_writer::tag('file', "{$plugindir}{$file}");
}
return $filters;
}
|
[
"final",
"public",
"function",
"get_whitelists",
"(",
"string",
"$",
"plugindir",
")",
":",
"array",
"{",
"$",
"filters",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"plugindir",
")",
")",
"{",
"$",
"plugindir",
".=",
"\"/\"",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"whitelistfolders",
"as",
"$",
"folder",
")",
"{",
"$",
"filters",
"[",
"]",
"=",
"html_writer",
"::",
"tag",
"(",
"'directory'",
",",
"\"{$plugindir}{$folder}\"",
",",
"[",
"'suffix'",
"=>",
"'.php'",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"whitelistfiles",
"as",
"$",
"file",
")",
"{",
"$",
"filters",
"[",
"]",
"=",
"html_writer",
"::",
"tag",
"(",
"'file'",
",",
"\"{$plugindir}{$file}\"",
")",
";",
"}",
"return",
"$",
"filters",
";",
"}"
] |
Get the formatted XML list of files and folders to whitelist.
@param string $plugindir The root of the plugin, relative to the dataroot.
@return array
|
[
"Get",
"the",
"formatted",
"XML",
"list",
"of",
"files",
"and",
"folders",
"to",
"whitelist",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpunit/classes/coverage_info.php#L54-L70
|
219,883
|
moodle/moodle
|
lib/phpunit/classes/coverage_info.php
|
phpunit_coverage_info.get_excludelists
|
final public function get_excludelists(string $plugindir) : array {
$filters = [];
if (!empty($plugindir)) {
$plugindir .= "/";
}
foreach ($this->excludelistfolders as $folder) {
$filters[] = html_writer::tag('directory', "{$plugindir}{$folder}", ['suffix' => '.php']);
}
foreach ($this->excludelistfiles as $file) {
$filters[] = html_writer::tag('file', "{$plugindir}{$file}");
}
return $filters;
}
|
php
|
final public function get_excludelists(string $plugindir) : array {
$filters = [];
if (!empty($plugindir)) {
$plugindir .= "/";
}
foreach ($this->excludelistfolders as $folder) {
$filters[] = html_writer::tag('directory', "{$plugindir}{$folder}", ['suffix' => '.php']);
}
foreach ($this->excludelistfiles as $file) {
$filters[] = html_writer::tag('file', "{$plugindir}{$file}");
}
return $filters;
}
|
[
"final",
"public",
"function",
"get_excludelists",
"(",
"string",
"$",
"plugindir",
")",
":",
"array",
"{",
"$",
"filters",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"plugindir",
")",
")",
"{",
"$",
"plugindir",
".=",
"\"/\"",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"excludelistfolders",
"as",
"$",
"folder",
")",
"{",
"$",
"filters",
"[",
"]",
"=",
"html_writer",
"::",
"tag",
"(",
"'directory'",
",",
"\"{$plugindir}{$folder}\"",
",",
"[",
"'suffix'",
"=>",
"'.php'",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"excludelistfiles",
"as",
"$",
"file",
")",
"{",
"$",
"filters",
"[",
"]",
"=",
"html_writer",
"::",
"tag",
"(",
"'file'",
",",
"\"{$plugindir}{$file}\"",
")",
";",
"}",
"return",
"$",
"filters",
";",
"}"
] |
Get the formatted XML list of files and folders to exclude.
@param string $plugindir The root of the plugin, relative to the dataroot.
@return array
|
[
"Get",
"the",
"formatted",
"XML",
"list",
"of",
"files",
"and",
"folders",
"to",
"exclude",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpunit/classes/coverage_info.php#L78-L94
|
219,884
|
moodle/moodle
|
grade/import/direct/classes/import_form.php
|
gradeimport_direct_import_form.definition
|
public function definition() {
global $COURSE;
$mform = $this->_form;
if (isset($this->_customdata)) { // Hardcoding plugin names here is hacky.
$features = $this->_customdata;
} else {
$features = array();
}
// Course id needs to be passed for auth purposes.
$mform->addElement('hidden', 'id', optional_param('id', 0, PARAM_INT));
$mform->setType('id', PARAM_INT);
$mform->addElement('header', 'general', get_string('pluginname', 'gradeimport_direct'));
// Data upload from copy/paste.
$mform->addElement('textarea', 'userdata', 'Data', array('rows' => 10, 'class' => 'gradeimport_data_area'));
$mform->addRule('userdata', null, 'required');
$mform->setType('userdata', PARAM_RAW);
$encodings = core_text::get_encodings();
$mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings);
$mform->addHelpButton('encoding', 'encoding', 'grades');
if (!empty($features['verbosescales'])) {
$options = array(1 => get_string('yes'), 0 => get_string('no'));
$mform->addElement('select', 'verbosescales', get_string('verbosescales', 'grades'), $options);
$mform->addHelpButton('verbosescales', 'verbosescales', 'grades');
}
$options = array('10' => 10, '20' => 20, '100' => 100, '1000' => 1000, '100000' => 100000);
$mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'grades'), $options);
$mform->addHelpButton('previewrows', 'rowpreviewnum', 'grades');
$mform->setType('previewrows', PARAM_INT);
$mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE));
$mform->setType('groupid', PARAM_INT);
$mform->addElement('advcheckbox', 'forceimport', get_string('forceimport', 'grades'));
$mform->addHelpButton('forceimport', 'forceimport', 'grades');
$mform->setDefault('forceimport', false);
$this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
}
|
php
|
public function definition() {
global $COURSE;
$mform = $this->_form;
if (isset($this->_customdata)) { // Hardcoding plugin names here is hacky.
$features = $this->_customdata;
} else {
$features = array();
}
// Course id needs to be passed for auth purposes.
$mform->addElement('hidden', 'id', optional_param('id', 0, PARAM_INT));
$mform->setType('id', PARAM_INT);
$mform->addElement('header', 'general', get_string('pluginname', 'gradeimport_direct'));
// Data upload from copy/paste.
$mform->addElement('textarea', 'userdata', 'Data', array('rows' => 10, 'class' => 'gradeimport_data_area'));
$mform->addRule('userdata', null, 'required');
$mform->setType('userdata', PARAM_RAW);
$encodings = core_text::get_encodings();
$mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings);
$mform->addHelpButton('encoding', 'encoding', 'grades');
if (!empty($features['verbosescales'])) {
$options = array(1 => get_string('yes'), 0 => get_string('no'));
$mform->addElement('select', 'verbosescales', get_string('verbosescales', 'grades'), $options);
$mform->addHelpButton('verbosescales', 'verbosescales', 'grades');
}
$options = array('10' => 10, '20' => 20, '100' => 100, '1000' => 1000, '100000' => 100000);
$mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'grades'), $options);
$mform->addHelpButton('previewrows', 'rowpreviewnum', 'grades');
$mform->setType('previewrows', PARAM_INT);
$mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE));
$mform->setType('groupid', PARAM_INT);
$mform->addElement('advcheckbox', 'forceimport', get_string('forceimport', 'grades'));
$mform->addHelpButton('forceimport', 'forceimport', 'grades');
$mform->setDefault('forceimport', false);
$this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
}
|
[
"public",
"function",
"definition",
"(",
")",
"{",
"global",
"$",
"COURSE",
";",
"$",
"mform",
"=",
"$",
"this",
"->",
"_form",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_customdata",
")",
")",
"{",
"// Hardcoding plugin names here is hacky.",
"$",
"features",
"=",
"$",
"this",
"->",
"_customdata",
";",
"}",
"else",
"{",
"$",
"features",
"=",
"array",
"(",
")",
";",
"}",
"// Course id needs to be passed for auth purposes.",
"$",
"mform",
"->",
"addElement",
"(",
"'hidden'",
",",
"'id'",
",",
"optional_param",
"(",
"'id'",
",",
"0",
",",
"PARAM_INT",
")",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'id'",
",",
"PARAM_INT",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'header'",
",",
"'general'",
",",
"get_string",
"(",
"'pluginname'",
",",
"'gradeimport_direct'",
")",
")",
";",
"// Data upload from copy/paste.",
"$",
"mform",
"->",
"addElement",
"(",
"'textarea'",
",",
"'userdata'",
",",
"'Data'",
",",
"array",
"(",
"'rows'",
"=>",
"10",
",",
"'class'",
"=>",
"'gradeimport_data_area'",
")",
")",
";",
"$",
"mform",
"->",
"addRule",
"(",
"'userdata'",
",",
"null",
",",
"'required'",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'userdata'",
",",
"PARAM_RAW",
")",
";",
"$",
"encodings",
"=",
"core_text",
"::",
"get_encodings",
"(",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'select'",
",",
"'encoding'",
",",
"get_string",
"(",
"'encoding'",
",",
"'grades'",
")",
",",
"$",
"encodings",
")",
";",
"$",
"mform",
"->",
"addHelpButton",
"(",
"'encoding'",
",",
"'encoding'",
",",
"'grades'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"features",
"[",
"'verbosescales'",
"]",
")",
")",
"{",
"$",
"options",
"=",
"array",
"(",
"1",
"=>",
"get_string",
"(",
"'yes'",
")",
",",
"0",
"=>",
"get_string",
"(",
"'no'",
")",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'select'",
",",
"'verbosescales'",
",",
"get_string",
"(",
"'verbosescales'",
",",
"'grades'",
")",
",",
"$",
"options",
")",
";",
"$",
"mform",
"->",
"addHelpButton",
"(",
"'verbosescales'",
",",
"'verbosescales'",
",",
"'grades'",
")",
";",
"}",
"$",
"options",
"=",
"array",
"(",
"'10'",
"=>",
"10",
",",
"'20'",
"=>",
"20",
",",
"'100'",
"=>",
"100",
",",
"'1000'",
"=>",
"1000",
",",
"'100000'",
"=>",
"100000",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'select'",
",",
"'previewrows'",
",",
"get_string",
"(",
"'rowpreviewnum'",
",",
"'grades'",
")",
",",
"$",
"options",
")",
";",
"$",
"mform",
"->",
"addHelpButton",
"(",
"'previewrows'",
",",
"'rowpreviewnum'",
",",
"'grades'",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'previewrows'",
",",
"PARAM_INT",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'hidden'",
",",
"'groupid'",
",",
"groups_get_course_group",
"(",
"$",
"COURSE",
")",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'groupid'",
",",
"PARAM_INT",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'advcheckbox'",
",",
"'forceimport'",
",",
"get_string",
"(",
"'forceimport'",
",",
"'grades'",
")",
")",
";",
"$",
"mform",
"->",
"addHelpButton",
"(",
"'forceimport'",
",",
"'forceimport'",
",",
"'grades'",
")",
";",
"$",
"mform",
"->",
"setDefault",
"(",
"'forceimport'",
",",
"false",
")",
";",
"$",
"this",
"->",
"add_action_buttons",
"(",
"false",
",",
"get_string",
"(",
"'uploadgrades'",
",",
"'grades'",
")",
")",
";",
"}"
] |
Definition method.
|
[
"Definition",
"method",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/import/direct/classes/import_form.php#L35-L76
|
219,885
|
moodle/moodle
|
blocks/recentlyaccesseditems/classes/helper.php
|
helper.get_recent_items
|
public static function get_recent_items(int $limit = 0) {
global $USER, $DB;
$userid = $USER->id;
$courses = array();
$recentitems = array();
if (!isloggedin() or \core\session\manager::is_loggedinas() or isguestuser()) {
// No access tracking.
return $recentitems;
}
// Determine sort sql clause.
$sort = 'timeaccess DESC';
$paramsql = array('userid' => $userid);
$records = $DB->get_records('block_recentlyaccesseditems', $paramsql, $sort);
$order = 0;
// Get array of items by course. Use $order index to keep sql sorted results.
foreach ($records as $record) {
$courses[$record->courseid][$order++] = $record;
}
// Group by courses to reduce get_fast_modinfo requests.
foreach ($courses as $key => $items) {
$modinfo = get_fast_modinfo($key);
if (!can_access_course($modinfo->get_course(), null, '', true)) {
continue;
}
foreach ($items as $key => $item) {
// Exclude not visible items.
if (!$modinfo->cms[$item->cmid]->uservisible) {
continue;
}
$item->modname = $modinfo->cms[$item->cmid]->modname;
$item->name = $modinfo->cms[$item->cmid]->name;
$item->coursename = get_course_display_name_for_list($modinfo->get_course());
$recentitems[$key] = $item;
}
}
ksort($recentitems);
// Apply limit.
if (!$limit) {
$limit = count($recentitems);
}
$recentitems = array_slice($recentitems, 0, $limit);
return $recentitems;
}
|
php
|
public static function get_recent_items(int $limit = 0) {
global $USER, $DB;
$userid = $USER->id;
$courses = array();
$recentitems = array();
if (!isloggedin() or \core\session\manager::is_loggedinas() or isguestuser()) {
// No access tracking.
return $recentitems;
}
// Determine sort sql clause.
$sort = 'timeaccess DESC';
$paramsql = array('userid' => $userid);
$records = $DB->get_records('block_recentlyaccesseditems', $paramsql, $sort);
$order = 0;
// Get array of items by course. Use $order index to keep sql sorted results.
foreach ($records as $record) {
$courses[$record->courseid][$order++] = $record;
}
// Group by courses to reduce get_fast_modinfo requests.
foreach ($courses as $key => $items) {
$modinfo = get_fast_modinfo($key);
if (!can_access_course($modinfo->get_course(), null, '', true)) {
continue;
}
foreach ($items as $key => $item) {
// Exclude not visible items.
if (!$modinfo->cms[$item->cmid]->uservisible) {
continue;
}
$item->modname = $modinfo->cms[$item->cmid]->modname;
$item->name = $modinfo->cms[$item->cmid]->name;
$item->coursename = get_course_display_name_for_list($modinfo->get_course());
$recentitems[$key] = $item;
}
}
ksort($recentitems);
// Apply limit.
if (!$limit) {
$limit = count($recentitems);
}
$recentitems = array_slice($recentitems, 0, $limit);
return $recentitems;
}
|
[
"public",
"static",
"function",
"get_recent_items",
"(",
"int",
"$",
"limit",
"=",
"0",
")",
"{",
"global",
"$",
"USER",
",",
"$",
"DB",
";",
"$",
"userid",
"=",
"$",
"USER",
"->",
"id",
";",
"$",
"courses",
"=",
"array",
"(",
")",
";",
"$",
"recentitems",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"isloggedin",
"(",
")",
"or",
"\\",
"core",
"\\",
"session",
"\\",
"manager",
"::",
"is_loggedinas",
"(",
")",
"or",
"isguestuser",
"(",
")",
")",
"{",
"// No access tracking.",
"return",
"$",
"recentitems",
";",
"}",
"// Determine sort sql clause.",
"$",
"sort",
"=",
"'timeaccess DESC'",
";",
"$",
"paramsql",
"=",
"array",
"(",
"'userid'",
"=>",
"$",
"userid",
")",
";",
"$",
"records",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'block_recentlyaccesseditems'",
",",
"$",
"paramsql",
",",
"$",
"sort",
")",
";",
"$",
"order",
"=",
"0",
";",
"// Get array of items by course. Use $order index to keep sql sorted results.",
"foreach",
"(",
"$",
"records",
"as",
"$",
"record",
")",
"{",
"$",
"courses",
"[",
"$",
"record",
"->",
"courseid",
"]",
"[",
"$",
"order",
"++",
"]",
"=",
"$",
"record",
";",
"}",
"// Group by courses to reduce get_fast_modinfo requests.",
"foreach",
"(",
"$",
"courses",
"as",
"$",
"key",
"=>",
"$",
"items",
")",
"{",
"$",
"modinfo",
"=",
"get_fast_modinfo",
"(",
"$",
"key",
")",
";",
"if",
"(",
"!",
"can_access_course",
"(",
"$",
"modinfo",
"->",
"get_course",
"(",
")",
",",
"null",
",",
"''",
",",
"true",
")",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"items",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"// Exclude not visible items.",
"if",
"(",
"!",
"$",
"modinfo",
"->",
"cms",
"[",
"$",
"item",
"->",
"cmid",
"]",
"->",
"uservisible",
")",
"{",
"continue",
";",
"}",
"$",
"item",
"->",
"modname",
"=",
"$",
"modinfo",
"->",
"cms",
"[",
"$",
"item",
"->",
"cmid",
"]",
"->",
"modname",
";",
"$",
"item",
"->",
"name",
"=",
"$",
"modinfo",
"->",
"cms",
"[",
"$",
"item",
"->",
"cmid",
"]",
"->",
"name",
";",
"$",
"item",
"->",
"coursename",
"=",
"get_course_display_name_for_list",
"(",
"$",
"modinfo",
"->",
"get_course",
"(",
")",
")",
";",
"$",
"recentitems",
"[",
"$",
"key",
"]",
"=",
"$",
"item",
";",
"}",
"}",
"ksort",
"(",
"$",
"recentitems",
")",
";",
"// Apply limit.",
"if",
"(",
"!",
"$",
"limit",
")",
"{",
"$",
"limit",
"=",
"count",
"(",
"$",
"recentitems",
")",
";",
"}",
"$",
"recentitems",
"=",
"array_slice",
"(",
"$",
"recentitems",
",",
"0",
",",
"$",
"limit",
")",
";",
"return",
"$",
"recentitems",
";",
"}"
] |
Returns a list of the most recently items accessed by the logged user
@param int $limit Restrict result set to this amount
@return array List of recent items accessed by userid
|
[
"Returns",
"a",
"list",
"of",
"the",
"most",
"recently",
"items",
"accessed",
"by",
"the",
"logged",
"user"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/recentlyaccesseditems/classes/helper.php#L43-L95
|
219,886
|
moodle/moodle
|
repository/wikimedia/lib.php
|
repository_wikimedia.get_maxwidth
|
public function get_maxwidth() {
$param = optional_param('wikimedia_maxwidth', 0, PARAM_INT);
$pref = get_user_preferences('repository_wikimedia_maxwidth', WIKIMEDIA_IMAGE_SIDE_LENGTH);
if ($param > 0 && $param != $pref) {
$pref = $param;
set_user_preference('repository_wikimedia_maxwidth', $pref);
}
return $pref;
}
|
php
|
public function get_maxwidth() {
$param = optional_param('wikimedia_maxwidth', 0, PARAM_INT);
$pref = get_user_preferences('repository_wikimedia_maxwidth', WIKIMEDIA_IMAGE_SIDE_LENGTH);
if ($param > 0 && $param != $pref) {
$pref = $param;
set_user_preference('repository_wikimedia_maxwidth', $pref);
}
return $pref;
}
|
[
"public",
"function",
"get_maxwidth",
"(",
")",
"{",
"$",
"param",
"=",
"optional_param",
"(",
"'wikimedia_maxwidth'",
",",
"0",
",",
"PARAM_INT",
")",
";",
"$",
"pref",
"=",
"get_user_preferences",
"(",
"'repository_wikimedia_maxwidth'",
",",
"WIKIMEDIA_IMAGE_SIDE_LENGTH",
")",
";",
"if",
"(",
"$",
"param",
">",
"0",
"&&",
"$",
"param",
"!=",
"$",
"pref",
")",
"{",
"$",
"pref",
"=",
"$",
"param",
";",
"set_user_preference",
"(",
"'repository_wikimedia_maxwidth'",
",",
"$",
"pref",
")",
";",
"}",
"return",
"$",
"pref",
";",
"}"
] |
Returns maximum width for images
Takes the maximum width for images eithre from search form or from
user preferences, updates user preferences if needed
@return int
|
[
"Returns",
"maximum",
"width",
"for",
"images"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/wikimedia/lib.php#L49-L57
|
219,887
|
moodle/moodle
|
repository/wikimedia/lib.php
|
repository_wikimedia.get_maxheight
|
public function get_maxheight() {
$param = optional_param('wikimedia_maxheight', 0, PARAM_INT);
$pref = get_user_preferences('repository_wikimedia_maxheight', WIKIMEDIA_IMAGE_SIDE_LENGTH);
if ($param > 0 && $param != $pref) {
$pref = $param;
set_user_preference('repository_wikimedia_maxheight', $pref);
}
return $pref;
}
|
php
|
public function get_maxheight() {
$param = optional_param('wikimedia_maxheight', 0, PARAM_INT);
$pref = get_user_preferences('repository_wikimedia_maxheight', WIKIMEDIA_IMAGE_SIDE_LENGTH);
if ($param > 0 && $param != $pref) {
$pref = $param;
set_user_preference('repository_wikimedia_maxheight', $pref);
}
return $pref;
}
|
[
"public",
"function",
"get_maxheight",
"(",
")",
"{",
"$",
"param",
"=",
"optional_param",
"(",
"'wikimedia_maxheight'",
",",
"0",
",",
"PARAM_INT",
")",
";",
"$",
"pref",
"=",
"get_user_preferences",
"(",
"'repository_wikimedia_maxheight'",
",",
"WIKIMEDIA_IMAGE_SIDE_LENGTH",
")",
";",
"if",
"(",
"$",
"param",
">",
"0",
"&&",
"$",
"param",
"!=",
"$",
"pref",
")",
"{",
"$",
"pref",
"=",
"$",
"param",
";",
"set_user_preference",
"(",
"'repository_wikimedia_maxheight'",
",",
"$",
"pref",
")",
";",
"}",
"return",
"$",
"pref",
";",
"}"
] |
Returns maximum height for images
Takes the maximum height for images eithre from search form or from
user preferences, updates user preferences if needed
@return int
|
[
"Returns",
"maximum",
"height",
"for",
"images"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/wikimedia/lib.php#L67-L75
|
219,888
|
moodle/moodle
|
repository/wikimedia/lib.php
|
repository_wikimedia.print_login
|
public function print_login() {
$keyword = new stdClass();
$keyword->label = get_string('keyword', 'repository_wikimedia').': ';
$keyword->id = 'input_text_keyword';
$keyword->type = 'text';
$keyword->name = 'wikimedia_keyword';
$keyword->value = '';
$maxwidth = array(
'label' => get_string('maxwidth', 'repository_wikimedia').': ',
'type' => 'text',
'name' => 'wikimedia_maxwidth',
'value' => get_user_preferences('repository_wikimedia_maxwidth', WIKIMEDIA_IMAGE_SIDE_LENGTH),
);
$maxheight = array(
'label' => get_string('maxheight', 'repository_wikimedia').': ',
'type' => 'text',
'name' => 'wikimedia_maxheight',
'value' => get_user_preferences('repository_wikimedia_maxheight', WIKIMEDIA_IMAGE_SIDE_LENGTH),
);
if ($this->options['ajax']) {
$form = array();
$form['login'] = array($keyword, (object)$maxwidth, (object)$maxheight);
$form['nologin'] = true;
$form['norefresh'] = true;
$form['nosearch'] = true;
$form['allowcaching'] = false; // indicates that login form can NOT
// be cached in filepicker.js (maxwidth and maxheight are dynamic)
return $form;
} else {
echo <<<EOD
<table>
<tr>
<td>{$keyword->label}</td><td><input name="{$keyword->name}" type="text" /></td>
</tr>
</table>
<input type="submit" />
EOD;
}
}
|
php
|
public function print_login() {
$keyword = new stdClass();
$keyword->label = get_string('keyword', 'repository_wikimedia').': ';
$keyword->id = 'input_text_keyword';
$keyword->type = 'text';
$keyword->name = 'wikimedia_keyword';
$keyword->value = '';
$maxwidth = array(
'label' => get_string('maxwidth', 'repository_wikimedia').': ',
'type' => 'text',
'name' => 'wikimedia_maxwidth',
'value' => get_user_preferences('repository_wikimedia_maxwidth', WIKIMEDIA_IMAGE_SIDE_LENGTH),
);
$maxheight = array(
'label' => get_string('maxheight', 'repository_wikimedia').': ',
'type' => 'text',
'name' => 'wikimedia_maxheight',
'value' => get_user_preferences('repository_wikimedia_maxheight', WIKIMEDIA_IMAGE_SIDE_LENGTH),
);
if ($this->options['ajax']) {
$form = array();
$form['login'] = array($keyword, (object)$maxwidth, (object)$maxheight);
$form['nologin'] = true;
$form['norefresh'] = true;
$form['nosearch'] = true;
$form['allowcaching'] = false; // indicates that login form can NOT
// be cached in filepicker.js (maxwidth and maxheight are dynamic)
return $form;
} else {
echo <<<EOD
<table>
<tr>
<td>{$keyword->label}</td><td><input name="{$keyword->name}" type="text" /></td>
</tr>
</table>
<input type="submit" />
EOD;
}
}
|
[
"public",
"function",
"print_login",
"(",
")",
"{",
"$",
"keyword",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"keyword",
"->",
"label",
"=",
"get_string",
"(",
"'keyword'",
",",
"'repository_wikimedia'",
")",
".",
"': '",
";",
"$",
"keyword",
"->",
"id",
"=",
"'input_text_keyword'",
";",
"$",
"keyword",
"->",
"type",
"=",
"'text'",
";",
"$",
"keyword",
"->",
"name",
"=",
"'wikimedia_keyword'",
";",
"$",
"keyword",
"->",
"value",
"=",
"''",
";",
"$",
"maxwidth",
"=",
"array",
"(",
"'label'",
"=>",
"get_string",
"(",
"'maxwidth'",
",",
"'repository_wikimedia'",
")",
".",
"': '",
",",
"'type'",
"=>",
"'text'",
",",
"'name'",
"=>",
"'wikimedia_maxwidth'",
",",
"'value'",
"=>",
"get_user_preferences",
"(",
"'repository_wikimedia_maxwidth'",
",",
"WIKIMEDIA_IMAGE_SIDE_LENGTH",
")",
",",
")",
";",
"$",
"maxheight",
"=",
"array",
"(",
"'label'",
"=>",
"get_string",
"(",
"'maxheight'",
",",
"'repository_wikimedia'",
")",
".",
"': '",
",",
"'type'",
"=>",
"'text'",
",",
"'name'",
"=>",
"'wikimedia_maxheight'",
",",
"'value'",
"=>",
"get_user_preferences",
"(",
"'repository_wikimedia_maxheight'",
",",
"WIKIMEDIA_IMAGE_SIDE_LENGTH",
")",
",",
")",
";",
"if",
"(",
"$",
"this",
"->",
"options",
"[",
"'ajax'",
"]",
")",
"{",
"$",
"form",
"=",
"array",
"(",
")",
";",
"$",
"form",
"[",
"'login'",
"]",
"=",
"array",
"(",
"$",
"keyword",
",",
"(",
"object",
")",
"$",
"maxwidth",
",",
"(",
"object",
")",
"$",
"maxheight",
")",
";",
"$",
"form",
"[",
"'nologin'",
"]",
"=",
"true",
";",
"$",
"form",
"[",
"'norefresh'",
"]",
"=",
"true",
";",
"$",
"form",
"[",
"'nosearch'",
"]",
"=",
"true",
";",
"$",
"form",
"[",
"'allowcaching'",
"]",
"=",
"false",
";",
"// indicates that login form can NOT",
"// be cached in filepicker.js (maxwidth and maxheight are dynamic)",
"return",
"$",
"form",
";",
"}",
"else",
"{",
"echo",
" <<<EOD\n<table>\n<tr>\n<td>{$keyword->label}</td><td><input name=\"{$keyword->name}\" type=\"text\" /></td>\n</tr>\n</table>\n<input type=\"submit\" />\nEOD",
";",
"}",
"}"
] |
this function will be called to print a login form.
|
[
"this",
"function",
"will",
"be",
"called",
"to",
"print",
"a",
"login",
"form",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/wikimedia/lib.php#L120-L158
|
219,889
|
moodle/moodle
|
tag/classes/manage_table.php
|
core_tag_manage_table.col_isstandard
|
public function col_isstandard($tag) {
global $OUTPUT;
$tagoutput = new core_tag\output\tagisstandard($tag);
return $tagoutput->render($OUTPUT);
}
|
php
|
public function col_isstandard($tag) {
global $OUTPUT;
$tagoutput = new core_tag\output\tagisstandard($tag);
return $tagoutput->render($OUTPUT);
}
|
[
"public",
"function",
"col_isstandard",
"(",
"$",
"tag",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"$",
"tagoutput",
"=",
"new",
"core_tag",
"\\",
"output",
"\\",
"tagisstandard",
"(",
"$",
"tag",
")",
";",
"return",
"$",
"tagoutput",
"->",
"render",
"(",
"$",
"OUTPUT",
")",
";",
"}"
] |
Column tag type
@param stdClass $tag
@return string
|
[
"Column",
"tag",
"type"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/manage_table.php#L241-L245
|
219,890
|
moodle/moodle
|
question/engine/datalib.php
|
question_engine_data_mapper.load_questions_usages_question_state_summary
|
public function load_questions_usages_question_state_summary(
qubaid_condition $qubaids, $slots) {
list($slottest, $params) = $this->db->get_in_or_equal($slots, SQL_PARAMS_NAMED, 'slot');
$rs = $this->db->get_recordset_sql("
SELECT
qa.slot,
qa.questionid,
q.name,
CASE qas.state
{$this->full_states_to_summary_state_sql()}
END AS summarystate,
COUNT(1) AS numattempts
FROM {$qubaids->from_question_attempts('qa')}
JOIN {question_attempt_steps} qas ON qas.questionattemptid = qa.id
AND qas.sequencenumber = {$this->latest_step_for_qa_subquery()}
JOIN {question} q ON q.id = qa.questionid
WHERE
{$qubaids->where()} AND
qa.slot $slottest
GROUP BY
qa.slot,
qa.questionid,
q.name,
q.id,
CASE qas.state
{$this->full_states_to_summary_state_sql()}
END
ORDER BY
qa.slot,
qa.questionid,
q.name,
q.id
", $params + $qubaids->from_where_params());
$results = array();
foreach ($rs as $row) {
$index = $row->slot . ',' . $row->questionid;
if (!array_key_exists($index, $results)) {
$res = new stdClass();
$res->slot = $row->slot;
$res->questionid = $row->questionid;
$res->name = $row->name;
$res->inprogress = 0;
$res->needsgrading = 0;
$res->autograded = 0;
$res->manuallygraded = 0;
$res->all = 0;
$results[$index] = $res;
}
$results[$index]->{$row->summarystate} = $row->numattempts;
$results[$index]->all += $row->numattempts;
}
$rs->close();
return $results;
}
|
php
|
public function load_questions_usages_question_state_summary(
qubaid_condition $qubaids, $slots) {
list($slottest, $params) = $this->db->get_in_or_equal($slots, SQL_PARAMS_NAMED, 'slot');
$rs = $this->db->get_recordset_sql("
SELECT
qa.slot,
qa.questionid,
q.name,
CASE qas.state
{$this->full_states_to_summary_state_sql()}
END AS summarystate,
COUNT(1) AS numattempts
FROM {$qubaids->from_question_attempts('qa')}
JOIN {question_attempt_steps} qas ON qas.questionattemptid = qa.id
AND qas.sequencenumber = {$this->latest_step_for_qa_subquery()}
JOIN {question} q ON q.id = qa.questionid
WHERE
{$qubaids->where()} AND
qa.slot $slottest
GROUP BY
qa.slot,
qa.questionid,
q.name,
q.id,
CASE qas.state
{$this->full_states_to_summary_state_sql()}
END
ORDER BY
qa.slot,
qa.questionid,
q.name,
q.id
", $params + $qubaids->from_where_params());
$results = array();
foreach ($rs as $row) {
$index = $row->slot . ',' . $row->questionid;
if (!array_key_exists($index, $results)) {
$res = new stdClass();
$res->slot = $row->slot;
$res->questionid = $row->questionid;
$res->name = $row->name;
$res->inprogress = 0;
$res->needsgrading = 0;
$res->autograded = 0;
$res->manuallygraded = 0;
$res->all = 0;
$results[$index] = $res;
}
$results[$index]->{$row->summarystate} = $row->numattempts;
$results[$index]->all += $row->numattempts;
}
$rs->close();
return $results;
}
|
[
"public",
"function",
"load_questions_usages_question_state_summary",
"(",
"qubaid_condition",
"$",
"qubaids",
",",
"$",
"slots",
")",
"{",
"list",
"(",
"$",
"slottest",
",",
"$",
"params",
")",
"=",
"$",
"this",
"->",
"db",
"->",
"get_in_or_equal",
"(",
"$",
"slots",
",",
"SQL_PARAMS_NAMED",
",",
"'slot'",
")",
";",
"$",
"rs",
"=",
"$",
"this",
"->",
"db",
"->",
"get_recordset_sql",
"(",
"\"\nSELECT\n qa.slot,\n qa.questionid,\n q.name,\n CASE qas.state\n {$this->full_states_to_summary_state_sql()}\n END AS summarystate,\n COUNT(1) AS numattempts\n\nFROM {$qubaids->from_question_attempts('qa')}\nJOIN {question_attempt_steps} qas ON qas.questionattemptid = qa.id\n AND qas.sequencenumber = {$this->latest_step_for_qa_subquery()}\nJOIN {question} q ON q.id = qa.questionid\n\nWHERE\n {$qubaids->where()} AND\n qa.slot $slottest\n\nGROUP BY\n qa.slot,\n qa.questionid,\n q.name,\n q.id,\n CASE qas.state\n {$this->full_states_to_summary_state_sql()}\n END\n\nORDER BY\n qa.slot,\n qa.questionid,\n q.name,\n q.id\n \"",
",",
"$",
"params",
"+",
"$",
"qubaids",
"->",
"from_where_params",
"(",
")",
")",
";",
"$",
"results",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"rs",
"as",
"$",
"row",
")",
"{",
"$",
"index",
"=",
"$",
"row",
"->",
"slot",
".",
"','",
".",
"$",
"row",
"->",
"questionid",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"index",
",",
"$",
"results",
")",
")",
"{",
"$",
"res",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"res",
"->",
"slot",
"=",
"$",
"row",
"->",
"slot",
";",
"$",
"res",
"->",
"questionid",
"=",
"$",
"row",
"->",
"questionid",
";",
"$",
"res",
"->",
"name",
"=",
"$",
"row",
"->",
"name",
";",
"$",
"res",
"->",
"inprogress",
"=",
"0",
";",
"$",
"res",
"->",
"needsgrading",
"=",
"0",
";",
"$",
"res",
"->",
"autograded",
"=",
"0",
";",
"$",
"res",
"->",
"manuallygraded",
"=",
"0",
";",
"$",
"res",
"->",
"all",
"=",
"0",
";",
"$",
"results",
"[",
"$",
"index",
"]",
"=",
"$",
"res",
";",
"}",
"$",
"results",
"[",
"$",
"index",
"]",
"->",
"{",
"$",
"row",
"->",
"summarystate",
"}",
"=",
"$",
"row",
"->",
"numattempts",
";",
"$",
"results",
"[",
"$",
"index",
"]",
"->",
"all",
"+=",
"$",
"row",
"->",
"numattempts",
";",
"}",
"$",
"rs",
"->",
"close",
"(",
")",
";",
"return",
"$",
"results",
";",
"}"
] |
Load summary information about the state of each question in a group of
attempts. This is used, for example, by the quiz manual grading report,
to show how many attempts at each question need to be graded.
This method may be called publicly.
@param qubaid_condition $qubaids used to restrict which usages are included
in the query. See {@link qubaid_condition}.
@param array $slots A list of slots for the questions you want to konw about.
@return array The array keys are slot,qestionid. The values are objects with
fields $slot, $questionid, $inprogress, $name, $needsgrading, $autograded,
$manuallygraded and $all.
|
[
"Load",
"summary",
"information",
"about",
"the",
"state",
"of",
"each",
"question",
"in",
"a",
"group",
"of",
"attempts",
".",
"This",
"is",
"used",
"for",
"example",
"by",
"the",
"quiz",
"manual",
"grading",
"report",
"to",
"show",
"how",
"many",
"attempts",
"at",
"each",
"question",
"need",
"to",
"be",
"graded",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/datalib.php#L608-L670
|
219,891
|
moodle/moodle
|
question/engine/datalib.php
|
question_engine_data_mapper.load_average_marks
|
public function load_average_marks(qubaid_condition $qubaids, $slots = null) {
if (!empty($slots)) {
list($slottest, $slotsparams) = $this->db->get_in_or_equal(
$slots, SQL_PARAMS_NAMED, 'slot');
$slotwhere = " AND qa.slot {$slottest}";
} else {
$slotwhere = '';
$slotsparams = array();
}
list($statetest, $stateparams) = $this->db->get_in_or_equal(array(
(string) question_state::$gaveup,
(string) question_state::$gradedwrong,
(string) question_state::$gradedpartial,
(string) question_state::$gradedright,
(string) question_state::$mangaveup,
(string) question_state::$mangrwrong,
(string) question_state::$mangrpartial,
(string) question_state::$mangrright), SQL_PARAMS_NAMED, 'st');
return $this->db->get_records_sql("
SELECT
qa.slot,
AVG(COALESCE(qas.fraction, 0)) AS averagefraction,
COUNT(1) AS numaveraged
FROM {$qubaids->from_question_attempts('qa')}
JOIN {question_attempt_steps} qas ON qas.questionattemptid = qa.id
AND qas.sequencenumber = {$this->latest_step_for_qa_subquery()}
WHERE
{$qubaids->where()}
$slotwhere
AND qas.state $statetest
GROUP BY qa.slot
ORDER BY qa.slot
", $slotsparams + $stateparams + $qubaids->from_where_params());
}
|
php
|
public function load_average_marks(qubaid_condition $qubaids, $slots = null) {
if (!empty($slots)) {
list($slottest, $slotsparams) = $this->db->get_in_or_equal(
$slots, SQL_PARAMS_NAMED, 'slot');
$slotwhere = " AND qa.slot {$slottest}";
} else {
$slotwhere = '';
$slotsparams = array();
}
list($statetest, $stateparams) = $this->db->get_in_or_equal(array(
(string) question_state::$gaveup,
(string) question_state::$gradedwrong,
(string) question_state::$gradedpartial,
(string) question_state::$gradedright,
(string) question_state::$mangaveup,
(string) question_state::$mangrwrong,
(string) question_state::$mangrpartial,
(string) question_state::$mangrright), SQL_PARAMS_NAMED, 'st');
return $this->db->get_records_sql("
SELECT
qa.slot,
AVG(COALESCE(qas.fraction, 0)) AS averagefraction,
COUNT(1) AS numaveraged
FROM {$qubaids->from_question_attempts('qa')}
JOIN {question_attempt_steps} qas ON qas.questionattemptid = qa.id
AND qas.sequencenumber = {$this->latest_step_for_qa_subquery()}
WHERE
{$qubaids->where()}
$slotwhere
AND qas.state $statetest
GROUP BY qa.slot
ORDER BY qa.slot
", $slotsparams + $stateparams + $qubaids->from_where_params());
}
|
[
"public",
"function",
"load_average_marks",
"(",
"qubaid_condition",
"$",
"qubaids",
",",
"$",
"slots",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"slots",
")",
")",
"{",
"list",
"(",
"$",
"slottest",
",",
"$",
"slotsparams",
")",
"=",
"$",
"this",
"->",
"db",
"->",
"get_in_or_equal",
"(",
"$",
"slots",
",",
"SQL_PARAMS_NAMED",
",",
"'slot'",
")",
";",
"$",
"slotwhere",
"=",
"\" AND qa.slot {$slottest}\"",
";",
"}",
"else",
"{",
"$",
"slotwhere",
"=",
"''",
";",
"$",
"slotsparams",
"=",
"array",
"(",
")",
";",
"}",
"list",
"(",
"$",
"statetest",
",",
"$",
"stateparams",
")",
"=",
"$",
"this",
"->",
"db",
"->",
"get_in_or_equal",
"(",
"array",
"(",
"(",
"string",
")",
"question_state",
"::",
"$",
"gaveup",
",",
"(",
"string",
")",
"question_state",
"::",
"$",
"gradedwrong",
",",
"(",
"string",
")",
"question_state",
"::",
"$",
"gradedpartial",
",",
"(",
"string",
")",
"question_state",
"::",
"$",
"gradedright",
",",
"(",
"string",
")",
"question_state",
"::",
"$",
"mangaveup",
",",
"(",
"string",
")",
"question_state",
"::",
"$",
"mangrwrong",
",",
"(",
"string",
")",
"question_state",
"::",
"$",
"mangrpartial",
",",
"(",
"string",
")",
"question_state",
"::",
"$",
"mangrright",
")",
",",
"SQL_PARAMS_NAMED",
",",
"'st'",
")",
";",
"return",
"$",
"this",
"->",
"db",
"->",
"get_records_sql",
"(",
"\"\nSELECT\n qa.slot,\n AVG(COALESCE(qas.fraction, 0)) AS averagefraction,\n COUNT(1) AS numaveraged\n\nFROM {$qubaids->from_question_attempts('qa')}\nJOIN {question_attempt_steps} qas ON qas.questionattemptid = qa.id\n AND qas.sequencenumber = {$this->latest_step_for_qa_subquery()}\n\nWHERE\n {$qubaids->where()}\n $slotwhere\n AND qas.state $statetest\n\nGROUP BY qa.slot\n\nORDER BY qa.slot\n \"",
",",
"$",
"slotsparams",
"+",
"$",
"stateparams",
"+",
"$",
"qubaids",
"->",
"from_where_params",
"(",
")",
")",
";",
"}"
] |
Load the average mark, and number of attempts, for each slot in a set of
question usages..
This method may be called publicly.
@param qubaid_condition $qubaids used to restrict which usages are included
in the query. See {@link qubaid_condition}.
@param array $slots if null, load info for all quesitions, otherwise only
load the averages for the specified questions.
@return array of objects with fields ->slot, ->averagefraction and ->numaveraged.
|
[
"Load",
"the",
"average",
"mark",
"and",
"number",
"of",
"attempts",
"for",
"each",
"slot",
"in",
"a",
"set",
"of",
"question",
"usages",
".."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/datalib.php#L773-L812
|
219,892
|
moodle/moodle
|
question/engine/datalib.php
|
question_engine_data_mapper.load_attempts_at_question
|
public function load_attempts_at_question($questionid, qubaid_condition $qubaids) {
$sql = "
SELECT
quba.contextid,
quba.preferredbehaviour,
qa.id AS questionattemptid,
qa.questionusageid,
qa.slot,
qa.behaviour,
qa.questionid,
qa.variant,
qa.maxmark,
qa.minfraction,
qa.maxfraction,
qa.flagged,
qa.questionsummary,
qa.rightanswer,
qa.responsesummary,
qa.timemodified,
qas.id AS attemptstepid,
qas.sequencenumber,
qas.state,
qas.fraction,
qas.timecreated,
qas.userid,
qasd.name,
qasd.value
FROM {$qubaids->from_question_attempts('qa')}
JOIN {question_usages} quba ON quba.id = qa.questionusageid
LEFT JOIN {question_attempt_steps} qas ON qas.questionattemptid = qa.id
LEFT JOIN {question_attempt_step_data} qasd ON qasd.attemptstepid = qas.id
WHERE
{$qubaids->where()} AND
qa.questionid = :questionid
ORDER BY
quba.id,
qa.id,
qas.sequencenumber";
// For qubaid_list must call this after calling methods that generate sql.
$params = $qubaids->from_where_params();
$params['questionid'] = $questionid;
$records = $this->db->get_recordset_sql($sql, $params);
$questionattempts = array();
while ($records->valid()) {
$record = $records->current();
$questionattempts[$record->questionattemptid] =
question_attempt::load_from_records($records,
$record->questionattemptid, new question_usage_null_observer(),
$record->preferredbehaviour);
}
$records->close();
return $questionattempts;
}
|
php
|
public function load_attempts_at_question($questionid, qubaid_condition $qubaids) {
$sql = "
SELECT
quba.contextid,
quba.preferredbehaviour,
qa.id AS questionattemptid,
qa.questionusageid,
qa.slot,
qa.behaviour,
qa.questionid,
qa.variant,
qa.maxmark,
qa.minfraction,
qa.maxfraction,
qa.flagged,
qa.questionsummary,
qa.rightanswer,
qa.responsesummary,
qa.timemodified,
qas.id AS attemptstepid,
qas.sequencenumber,
qas.state,
qas.fraction,
qas.timecreated,
qas.userid,
qasd.name,
qasd.value
FROM {$qubaids->from_question_attempts('qa')}
JOIN {question_usages} quba ON quba.id = qa.questionusageid
LEFT JOIN {question_attempt_steps} qas ON qas.questionattemptid = qa.id
LEFT JOIN {question_attempt_step_data} qasd ON qasd.attemptstepid = qas.id
WHERE
{$qubaids->where()} AND
qa.questionid = :questionid
ORDER BY
quba.id,
qa.id,
qas.sequencenumber";
// For qubaid_list must call this after calling methods that generate sql.
$params = $qubaids->from_where_params();
$params['questionid'] = $questionid;
$records = $this->db->get_recordset_sql($sql, $params);
$questionattempts = array();
while ($records->valid()) {
$record = $records->current();
$questionattempts[$record->questionattemptid] =
question_attempt::load_from_records($records,
$record->questionattemptid, new question_usage_null_observer(),
$record->preferredbehaviour);
}
$records->close();
return $questionattempts;
}
|
[
"public",
"function",
"load_attempts_at_question",
"(",
"$",
"questionid",
",",
"qubaid_condition",
"$",
"qubaids",
")",
"{",
"$",
"sql",
"=",
"\"\nSELECT\n quba.contextid,\n quba.preferredbehaviour,\n qa.id AS questionattemptid,\n qa.questionusageid,\n qa.slot,\n qa.behaviour,\n qa.questionid,\n qa.variant,\n qa.maxmark,\n qa.minfraction,\n qa.maxfraction,\n qa.flagged,\n qa.questionsummary,\n qa.rightanswer,\n qa.responsesummary,\n qa.timemodified,\n qas.id AS attemptstepid,\n qas.sequencenumber,\n qas.state,\n qas.fraction,\n qas.timecreated,\n qas.userid,\n qasd.name,\n qasd.value\n\nFROM {$qubaids->from_question_attempts('qa')}\nJOIN {question_usages} quba ON quba.id = qa.questionusageid\nLEFT JOIN {question_attempt_steps} qas ON qas.questionattemptid = qa.id\nLEFT JOIN {question_attempt_step_data} qasd ON qasd.attemptstepid = qas.id\n\nWHERE\n {$qubaids->where()} AND\n qa.questionid = :questionid\n\nORDER BY\n quba.id,\n qa.id,\n qas.sequencenumber\"",
";",
"// For qubaid_list must call this after calling methods that generate sql.",
"$",
"params",
"=",
"$",
"qubaids",
"->",
"from_where_params",
"(",
")",
";",
"$",
"params",
"[",
"'questionid'",
"]",
"=",
"$",
"questionid",
";",
"$",
"records",
"=",
"$",
"this",
"->",
"db",
"->",
"get_recordset_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"$",
"questionattempts",
"=",
"array",
"(",
")",
";",
"while",
"(",
"$",
"records",
"->",
"valid",
"(",
")",
")",
"{",
"$",
"record",
"=",
"$",
"records",
"->",
"current",
"(",
")",
";",
"$",
"questionattempts",
"[",
"$",
"record",
"->",
"questionattemptid",
"]",
"=",
"question_attempt",
"::",
"load_from_records",
"(",
"$",
"records",
",",
"$",
"record",
"->",
"questionattemptid",
",",
"new",
"question_usage_null_observer",
"(",
")",
",",
"$",
"record",
"->",
"preferredbehaviour",
")",
";",
"}",
"$",
"records",
"->",
"close",
"(",
")",
";",
"return",
"$",
"questionattempts",
";",
"}"
] |
Load all the attempts at a given queston from a set of question_usages.
steps.
This method may be called publicly.
@param int $questionid the question to load all the attempts fors.
@param qubaid_condition $qubaids used to restrict which usages are included
in the query. See {@link qubaid_condition}.
@return question_attempt[] array of question_attempts that were loaded.
|
[
"Load",
"all",
"the",
"attempts",
"at",
"a",
"given",
"queston",
"from",
"a",
"set",
"of",
"question_usages",
".",
"steps",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/datalib.php#L825-L884
|
219,893
|
moodle/moodle
|
question/engine/datalib.php
|
question_engine_data_mapper.update_questions_usage_by_activity
|
public function update_questions_usage_by_activity(question_usage_by_activity $quba) {
$record = new stdClass();
$record->id = $quba->get_id();
$record->contextid = $quba->get_owning_context()->id;
$record->component = $quba->get_owning_component();
$record->preferredbehaviour = $quba->get_preferred_behaviour();
$this->db->update_record('question_usages', $record);
}
|
php
|
public function update_questions_usage_by_activity(question_usage_by_activity $quba) {
$record = new stdClass();
$record->id = $quba->get_id();
$record->contextid = $quba->get_owning_context()->id;
$record->component = $quba->get_owning_component();
$record->preferredbehaviour = $quba->get_preferred_behaviour();
$this->db->update_record('question_usages', $record);
}
|
[
"public",
"function",
"update_questions_usage_by_activity",
"(",
"question_usage_by_activity",
"$",
"quba",
")",
"{",
"$",
"record",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"record",
"->",
"id",
"=",
"$",
"quba",
"->",
"get_id",
"(",
")",
";",
"$",
"record",
"->",
"contextid",
"=",
"$",
"quba",
"->",
"get_owning_context",
"(",
")",
"->",
"id",
";",
"$",
"record",
"->",
"component",
"=",
"$",
"quba",
"->",
"get_owning_component",
"(",
")",
";",
"$",
"record",
"->",
"preferredbehaviour",
"=",
"$",
"quba",
"->",
"get_preferred_behaviour",
"(",
")",
";",
"$",
"this",
"->",
"db",
"->",
"update_record",
"(",
"'question_usages'",
",",
"$",
"record",
")",
";",
"}"
] |
Update a question_usages row to refect any changes in a usage (but not
any of its question_attempts.
You should not call this method directly. You should use
@link question_engine::save_questions_usage_by_activity()}.
@param question_usage_by_activity $quba the usage that has changed.
|
[
"Update",
"a",
"question_usages",
"row",
"to",
"refect",
"any",
"changes",
"in",
"a",
"usage",
"(",
"but",
"not",
"any",
"of",
"its",
"question_attempts",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/datalib.php#L895-L903
|
219,894
|
moodle/moodle
|
question/engine/datalib.php
|
question_engine_data_mapper.delete_questions_usage_by_activities
|
public function delete_questions_usage_by_activities(qubaid_condition $qubaids) {
$where = "qa.questionusageid {$qubaids->usage_id_in()}";
$params = $qubaids->usage_id_in_params();
$contextids = $this->db->get_records_sql_menu("
SELECT DISTINCT contextid, 1
FROM {question_usages}
WHERE id {$qubaids->usage_id_in()}", $qubaids->usage_id_in_params());
foreach ($contextids as $contextid => $notused) {
$this->delete_response_files($contextid, "IN (
SELECT qas.id
FROM {question_attempts} qa
JOIN {question_attempt_steps} qas ON qas.questionattemptid = qa.id
WHERE $where)", $params);
}
if ($this->db->get_dbfamily() == 'mysql') {
$this->delete_usage_records_for_mysql($qubaids);
return;
}
$this->db->delete_records_select('question_attempt_step_data', "attemptstepid IN (
SELECT qas.id
FROM {question_attempts} qa
JOIN {question_attempt_steps} qas ON qas.questionattemptid = qa.id
WHERE $where)", $params);
$this->db->delete_records_select('question_attempt_steps', "questionattemptid IN (
SELECT qa.id
FROM {question_attempts} qa
WHERE $where)", $params);
$this->db->delete_records_select('question_attempts',
"{question_attempts}.questionusageid {$qubaids->usage_id_in()}",
$qubaids->usage_id_in_params());
$this->db->delete_records_select('question_usages',
"{question_usages}.id {$qubaids->usage_id_in()}", $qubaids->usage_id_in_params());
}
|
php
|
public function delete_questions_usage_by_activities(qubaid_condition $qubaids) {
$where = "qa.questionusageid {$qubaids->usage_id_in()}";
$params = $qubaids->usage_id_in_params();
$contextids = $this->db->get_records_sql_menu("
SELECT DISTINCT contextid, 1
FROM {question_usages}
WHERE id {$qubaids->usage_id_in()}", $qubaids->usage_id_in_params());
foreach ($contextids as $contextid => $notused) {
$this->delete_response_files($contextid, "IN (
SELECT qas.id
FROM {question_attempts} qa
JOIN {question_attempt_steps} qas ON qas.questionattemptid = qa.id
WHERE $where)", $params);
}
if ($this->db->get_dbfamily() == 'mysql') {
$this->delete_usage_records_for_mysql($qubaids);
return;
}
$this->db->delete_records_select('question_attempt_step_data', "attemptstepid IN (
SELECT qas.id
FROM {question_attempts} qa
JOIN {question_attempt_steps} qas ON qas.questionattemptid = qa.id
WHERE $where)", $params);
$this->db->delete_records_select('question_attempt_steps', "questionattemptid IN (
SELECT qa.id
FROM {question_attempts} qa
WHERE $where)", $params);
$this->db->delete_records_select('question_attempts',
"{question_attempts}.questionusageid {$qubaids->usage_id_in()}",
$qubaids->usage_id_in_params());
$this->db->delete_records_select('question_usages',
"{question_usages}.id {$qubaids->usage_id_in()}", $qubaids->usage_id_in_params());
}
|
[
"public",
"function",
"delete_questions_usage_by_activities",
"(",
"qubaid_condition",
"$",
"qubaids",
")",
"{",
"$",
"where",
"=",
"\"qa.questionusageid {$qubaids->usage_id_in()}\"",
";",
"$",
"params",
"=",
"$",
"qubaids",
"->",
"usage_id_in_params",
"(",
")",
";",
"$",
"contextids",
"=",
"$",
"this",
"->",
"db",
"->",
"get_records_sql_menu",
"(",
"\"\n SELECT DISTINCT contextid, 1\n FROM {question_usages}\n WHERE id {$qubaids->usage_id_in()}\"",
",",
"$",
"qubaids",
"->",
"usage_id_in_params",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"contextids",
"as",
"$",
"contextid",
"=>",
"$",
"notused",
")",
"{",
"$",
"this",
"->",
"delete_response_files",
"(",
"$",
"contextid",
",",
"\"IN (\n SELECT qas.id\n FROM {question_attempts} qa\n JOIN {question_attempt_steps} qas ON qas.questionattemptid = qa.id\n WHERE $where)\"",
",",
"$",
"params",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"db",
"->",
"get_dbfamily",
"(",
")",
"==",
"'mysql'",
")",
"{",
"$",
"this",
"->",
"delete_usage_records_for_mysql",
"(",
"$",
"qubaids",
")",
";",
"return",
";",
"}",
"$",
"this",
"->",
"db",
"->",
"delete_records_select",
"(",
"'question_attempt_step_data'",
",",
"\"attemptstepid IN (\n SELECT qas.id\n FROM {question_attempts} qa\n JOIN {question_attempt_steps} qas ON qas.questionattemptid = qa.id\n WHERE $where)\"",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"db",
"->",
"delete_records_select",
"(",
"'question_attempt_steps'",
",",
"\"questionattemptid IN (\n SELECT qa.id\n FROM {question_attempts} qa\n WHERE $where)\"",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"db",
"->",
"delete_records_select",
"(",
"'question_attempts'",
",",
"\"{question_attempts}.questionusageid {$qubaids->usage_id_in()}\"",
",",
"$",
"qubaids",
"->",
"usage_id_in_params",
"(",
")",
")",
";",
"$",
"this",
"->",
"db",
"->",
"delete_records_select",
"(",
"'question_usages'",
",",
"\"{question_usages}.id {$qubaids->usage_id_in()}\"",
",",
"$",
"qubaids",
"->",
"usage_id_in_params",
"(",
")",
")",
";",
"}"
] |
Delete a question_usage_by_activity and all its associated
You should not call this method directly. You should use
@link question_engine::delete_questions_usage_by_activities()}.
{@link question_attempts} and {@link question_attempt_steps} from the
database.
@param qubaid_condition $qubaids identifies which question useages to delete.
|
[
"Delete",
"a",
"question_usage_by_activity",
"and",
"all",
"its",
"associated"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/datalib.php#L941-L979
|
219,895
|
moodle/moodle
|
question/engine/datalib.php
|
question_engine_data_mapper.delete_steps
|
public function delete_steps($stepids, $context) {
if (empty($stepids)) {
return;
}
list($test, $params) = $this->db->get_in_or_equal($stepids, SQL_PARAMS_NAMED);
$this->delete_response_files($context->id, $test, $params);
$this->db->delete_records_select('question_attempt_step_data',
"attemptstepid {$test}", $params);
$this->db->delete_records_select('question_attempt_steps',
"id {$test}", $params);
}
|
php
|
public function delete_steps($stepids, $context) {
if (empty($stepids)) {
return;
}
list($test, $params) = $this->db->get_in_or_equal($stepids, SQL_PARAMS_NAMED);
$this->delete_response_files($context->id, $test, $params);
$this->db->delete_records_select('question_attempt_step_data',
"attemptstepid {$test}", $params);
$this->db->delete_records_select('question_attempt_steps',
"id {$test}", $params);
}
|
[
"public",
"function",
"delete_steps",
"(",
"$",
"stepids",
",",
"$",
"context",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"stepids",
")",
")",
"{",
"return",
";",
"}",
"list",
"(",
"$",
"test",
",",
"$",
"params",
")",
"=",
"$",
"this",
"->",
"db",
"->",
"get_in_or_equal",
"(",
"$",
"stepids",
",",
"SQL_PARAMS_NAMED",
")",
";",
"$",
"this",
"->",
"delete_response_files",
"(",
"$",
"context",
"->",
"id",
",",
"$",
"test",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"db",
"->",
"delete_records_select",
"(",
"'question_attempt_step_data'",
",",
"\"attemptstepid {$test}\"",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"db",
"->",
"delete_records_select",
"(",
"'question_attempt_steps'",
",",
"\"id {$test}\"",
",",
"$",
"params",
")",
";",
"}"
] |
Delete all the steps for a question attempt.
Private method, only for use by other parts of the question engine.
@param int $qaids question_attempt id.
@param context $context the context that the $quba belongs to.
|
[
"Delete",
"all",
"the",
"steps",
"for",
"a",
"question",
"attempt",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/datalib.php#L1016-L1028
|
219,896
|
moodle/moodle
|
question/engine/datalib.php
|
question_engine_data_mapper.delete_response_files
|
protected function delete_response_files($contextid, $itemidstest, $params) {
$fs = get_file_storage();
foreach (question_engine::get_all_response_file_areas() as $filearea) {
$fs->delete_area_files_select($contextid, 'question', $filearea,
$itemidstest, $params);
}
}
|
php
|
protected function delete_response_files($contextid, $itemidstest, $params) {
$fs = get_file_storage();
foreach (question_engine::get_all_response_file_areas() as $filearea) {
$fs->delete_area_files_select($contextid, 'question', $filearea,
$itemidstest, $params);
}
}
|
[
"protected",
"function",
"delete_response_files",
"(",
"$",
"contextid",
",",
"$",
"itemidstest",
",",
"$",
"params",
")",
"{",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"foreach",
"(",
"question_engine",
"::",
"get_all_response_file_areas",
"(",
")",
"as",
"$",
"filearea",
")",
"{",
"$",
"fs",
"->",
"delete_area_files_select",
"(",
"$",
"contextid",
",",
"'question'",
",",
"$",
"filearea",
",",
"$",
"itemidstest",
",",
"$",
"params",
")",
";",
"}",
"}"
] |
Delete all the files belonging to the response variables in the gives
question attempt steps.
@param int $contextid the context these attempts belong to.
@param string $itemidstest a bit of SQL that can be used in a
WHERE itemid $itemidstest clause. Must use named params.
@param array $params any query parameters used in $itemidstest.
|
[
"Delete",
"all",
"the",
"files",
"belonging",
"to",
"the",
"response",
"variables",
"in",
"the",
"gives",
"question",
"attempt",
"steps",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/datalib.php#L1038-L1044
|
219,897
|
moodle/moodle
|
question/engine/datalib.php
|
question_engine_data_mapper.delete_previews
|
public function delete_previews($questionid) {
$previews = $this->db->get_records_sql_menu("
SELECT DISTINCT quba.id, 1
FROM {question_usages} quba
JOIN {question_attempts} qa ON qa.questionusageid = quba.id
WHERE quba.component = 'core_question_preview' AND
qa.questionid = ?", array($questionid));
if (empty($previews)) {
return;
}
$this->delete_questions_usage_by_activities(new qubaid_list($previews));
}
|
php
|
public function delete_previews($questionid) {
$previews = $this->db->get_records_sql_menu("
SELECT DISTINCT quba.id, 1
FROM {question_usages} quba
JOIN {question_attempts} qa ON qa.questionusageid = quba.id
WHERE quba.component = 'core_question_preview' AND
qa.questionid = ?", array($questionid));
if (empty($previews)) {
return;
}
$this->delete_questions_usage_by_activities(new qubaid_list($previews));
}
|
[
"public",
"function",
"delete_previews",
"(",
"$",
"questionid",
")",
"{",
"$",
"previews",
"=",
"$",
"this",
"->",
"db",
"->",
"get_records_sql_menu",
"(",
"\"\n SELECT DISTINCT quba.id, 1\n FROM {question_usages} quba\n JOIN {question_attempts} qa ON qa.questionusageid = quba.id\n WHERE quba.component = 'core_question_preview' AND\n qa.questionid = ?\"",
",",
"array",
"(",
"$",
"questionid",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"previews",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"delete_questions_usage_by_activities",
"(",
"new",
"qubaid_list",
"(",
"$",
"previews",
")",
")",
";",
"}"
] |
Delete all the previews for a given question.
Private method, only for use by other parts of the question engine.
@param int $questionid question id.
|
[
"Delete",
"all",
"the",
"previews",
"for",
"a",
"given",
"question",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/datalib.php#L1053-L1064
|
219,898
|
moodle/moodle
|
question/engine/datalib.php
|
question_engine_data_mapper.update_question_attempt_flag
|
public function update_question_attempt_flag($qubaid, $questionid, $qaid, $slot, $newstate) {
if (!$this->db->record_exists('question_attempts', array('id' => $qaid,
'questionusageid' => $qubaid, 'questionid' => $questionid, 'slot' => $slot))) {
throw new moodle_exception('errorsavingflags', 'question');
}
$this->db->set_field('question_attempts', 'flagged', $newstate, array('id' => $qaid));
}
|
php
|
public function update_question_attempt_flag($qubaid, $questionid, $qaid, $slot, $newstate) {
if (!$this->db->record_exists('question_attempts', array('id' => $qaid,
'questionusageid' => $qubaid, 'questionid' => $questionid, 'slot' => $slot))) {
throw new moodle_exception('errorsavingflags', 'question');
}
$this->db->set_field('question_attempts', 'flagged', $newstate, array('id' => $qaid));
}
|
[
"public",
"function",
"update_question_attempt_flag",
"(",
"$",
"qubaid",
",",
"$",
"questionid",
",",
"$",
"qaid",
",",
"$",
"slot",
",",
"$",
"newstate",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"db",
"->",
"record_exists",
"(",
"'question_attempts'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"qaid",
",",
"'questionusageid'",
"=>",
"$",
"qubaid",
",",
"'questionid'",
"=>",
"$",
"questionid",
",",
"'slot'",
"=>",
"$",
"slot",
")",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'errorsavingflags'",
",",
"'question'",
")",
";",
"}",
"$",
"this",
"->",
"db",
"->",
"set_field",
"(",
"'question_attempts'",
",",
"'flagged'",
",",
"$",
"newstate",
",",
"array",
"(",
"'id'",
"=>",
"$",
"qaid",
")",
")",
";",
"}"
] |
Update the flagged state of a question in the database.
You should call {@link question_engine::update_flag()()}
rather than calling this method directly.
@param int $qubaid the question usage id.
@param int $questionid the question id.
@param int $sessionid the question_attempt id.
@param bool $newstate the new state of the flag. true = flagged.
|
[
"Update",
"the",
"flagged",
"state",
"of",
"a",
"question",
"in",
"the",
"database",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/datalib.php#L1077-L1084
|
219,899
|
moodle/moodle
|
question/engine/datalib.php
|
question_engine_data_mapper.questions_in_use
|
public function questions_in_use(array $questionids, qubaid_condition $qubaids) {
list($test, $params) = $this->db->get_in_or_equal($questionids);
return $this->db->record_exists_select('question_attempts',
'questionid ' . $test . ' AND questionusageid ' .
$qubaids->usage_id_in(), $params + $qubaids->usage_id_in_params());
}
|
php
|
public function questions_in_use(array $questionids, qubaid_condition $qubaids) {
list($test, $params) = $this->db->get_in_or_equal($questionids);
return $this->db->record_exists_select('question_attempts',
'questionid ' . $test . ' AND questionusageid ' .
$qubaids->usage_id_in(), $params + $qubaids->usage_id_in_params());
}
|
[
"public",
"function",
"questions_in_use",
"(",
"array",
"$",
"questionids",
",",
"qubaid_condition",
"$",
"qubaids",
")",
"{",
"list",
"(",
"$",
"test",
",",
"$",
"params",
")",
"=",
"$",
"this",
"->",
"db",
"->",
"get_in_or_equal",
"(",
"$",
"questionids",
")",
";",
"return",
"$",
"this",
"->",
"db",
"->",
"record_exists_select",
"(",
"'question_attempts'",
",",
"'questionid '",
".",
"$",
"test",
".",
"' AND questionusageid '",
".",
"$",
"qubaids",
"->",
"usage_id_in",
"(",
")",
",",
"$",
"params",
"+",
"$",
"qubaids",
"->",
"usage_id_in_params",
"(",
")",
")",
";",
"}"
] |
Are any of these questions are currently in use?
You should call {@link question_engine::questions_in_use()}
rather than calling this method directly.
@param array $questionids of question ids.
@param qubaid_condition $qubaids ids of the usages to consider.
@return bool whether any of these questions are being used by any of
those usages.
|
[
"Are",
"any",
"of",
"these",
"questions",
"are",
"currently",
"in",
"use?"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/datalib.php#L1244-L1249
|
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.