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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
220,100
|
moodle/moodle
|
tag/classes/area.php
|
core_tag_area.create
|
protected static function create($record) {
global $DB;
if (empty($record->tagcollid)) {
$record->tagcollid = core_tag_collection::get_default();
}
$DB->insert_record('tag_area', array('component' => $record->component,
'itemtype' => $record->itemtype,
'tagcollid' => $record->tagcollid,
'callback' => $record->callback,
'callbackfile' => $record->callbackfile,
'showstandard' => isset($record->showstandard) ? $record->showstandard : core_tag_tag::BOTH_STANDARD_AND_NOT,
'multiplecontexts' => isset($record->multiplecontexts) ? $record->multiplecontexts : 0));
// Reset cache.
cache::make('core', 'tags')->delete('tag_area');
}
|
php
|
protected static function create($record) {
global $DB;
if (empty($record->tagcollid)) {
$record->tagcollid = core_tag_collection::get_default();
}
$DB->insert_record('tag_area', array('component' => $record->component,
'itemtype' => $record->itemtype,
'tagcollid' => $record->tagcollid,
'callback' => $record->callback,
'callbackfile' => $record->callbackfile,
'showstandard' => isset($record->showstandard) ? $record->showstandard : core_tag_tag::BOTH_STANDARD_AND_NOT,
'multiplecontexts' => isset($record->multiplecontexts) ? $record->multiplecontexts : 0));
// Reset cache.
cache::make('core', 'tags')->delete('tag_area');
}
|
[
"protected",
"static",
"function",
"create",
"(",
"$",
"record",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"empty",
"(",
"$",
"record",
"->",
"tagcollid",
")",
")",
"{",
"$",
"record",
"->",
"tagcollid",
"=",
"core_tag_collection",
"::",
"get_default",
"(",
")",
";",
"}",
"$",
"DB",
"->",
"insert_record",
"(",
"'tag_area'",
",",
"array",
"(",
"'component'",
"=>",
"$",
"record",
"->",
"component",
",",
"'itemtype'",
"=>",
"$",
"record",
"->",
"itemtype",
",",
"'tagcollid'",
"=>",
"$",
"record",
"->",
"tagcollid",
",",
"'callback'",
"=>",
"$",
"record",
"->",
"callback",
",",
"'callbackfile'",
"=>",
"$",
"record",
"->",
"callbackfile",
",",
"'showstandard'",
"=>",
"isset",
"(",
"$",
"record",
"->",
"showstandard",
")",
"?",
"$",
"record",
"->",
"showstandard",
":",
"core_tag_tag",
"::",
"BOTH_STANDARD_AND_NOT",
",",
"'multiplecontexts'",
"=>",
"isset",
"(",
"$",
"record",
"->",
"multiplecontexts",
")",
"?",
"$",
"record",
"->",
"multiplecontexts",
":",
"0",
")",
")",
";",
"// Reset cache.",
"cache",
"::",
"make",
"(",
"'core'",
",",
"'tags'",
")",
"->",
"delete",
"(",
"'tag_area'",
")",
";",
"}"
] |
Create a new tag area
@param stdClass $record
|
[
"Create",
"a",
"new",
"tag",
"area"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/area.php#L236-L251
|
220,101
|
moodle/moodle
|
tag/classes/area.php
|
core_tag_area.update
|
public static function update($existing, $data) {
global $DB;
$data = array_intersect_key((array)$data,
array('enabled' => 1, 'tagcollid' => 1,
'callback' => 1, 'callbackfile' => 1, 'showstandard' => 1,
'multiplecontexts' => 1));
foreach ($data as $key => $value) {
if ($existing->$key == $value) {
unset($data[$key]);
}
}
if (!$data) {
return;
}
if (!empty($data['tagcollid'])) {
self::move_tags($existing->component, $existing->itemtype, $data['tagcollid']);
}
$data['id'] = $existing->id;
$DB->update_record('tag_area', $data);
// Reset cache.
cache::make('core', 'tags')->delete('tag_area');
}
|
php
|
public static function update($existing, $data) {
global $DB;
$data = array_intersect_key((array)$data,
array('enabled' => 1, 'tagcollid' => 1,
'callback' => 1, 'callbackfile' => 1, 'showstandard' => 1,
'multiplecontexts' => 1));
foreach ($data as $key => $value) {
if ($existing->$key == $value) {
unset($data[$key]);
}
}
if (!$data) {
return;
}
if (!empty($data['tagcollid'])) {
self::move_tags($existing->component, $existing->itemtype, $data['tagcollid']);
}
$data['id'] = $existing->id;
$DB->update_record('tag_area', $data);
// Reset cache.
cache::make('core', 'tags')->delete('tag_area');
}
|
[
"public",
"static",
"function",
"update",
"(",
"$",
"existing",
",",
"$",
"data",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"data",
"=",
"array_intersect_key",
"(",
"(",
"array",
")",
"$",
"data",
",",
"array",
"(",
"'enabled'",
"=>",
"1",
",",
"'tagcollid'",
"=>",
"1",
",",
"'callback'",
"=>",
"1",
",",
"'callbackfile'",
"=>",
"1",
",",
"'showstandard'",
"=>",
"1",
",",
"'multiplecontexts'",
"=>",
"1",
")",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"existing",
"->",
"$",
"key",
"==",
"$",
"value",
")",
"{",
"unset",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"data",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"'tagcollid'",
"]",
")",
")",
"{",
"self",
"::",
"move_tags",
"(",
"$",
"existing",
"->",
"component",
",",
"$",
"existing",
"->",
"itemtype",
",",
"$",
"data",
"[",
"'tagcollid'",
"]",
")",
";",
"}",
"$",
"data",
"[",
"'id'",
"]",
"=",
"$",
"existing",
"->",
"id",
";",
"$",
"DB",
"->",
"update_record",
"(",
"'tag_area'",
",",
"$",
"data",
")",
";",
"// Reset cache.",
"cache",
"::",
"make",
"(",
"'core'",
",",
"'tags'",
")",
"->",
"delete",
"(",
"'tag_area'",
")",
";",
"}"
] |
Update the tag area
@param stdClass $existing current record from DB table tag_area
@param array|stdClass $data fields that need updating
|
[
"Update",
"the",
"tag",
"area"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/area.php#L259-L283
|
220,102
|
moodle/moodle
|
tag/classes/area.php
|
core_tag_area.uninstall
|
public static function uninstall($pluginname) {
global $DB;
list($a, $b) = core_component::normalize_component($pluginname);
if (empty($b) || $a === 'core') {
throw new coding_exception('Core component can not be uninstalled');
}
$component = $a . '_' . $b;
core_tag_tag::delete_instances($component);
$DB->delete_records('tag_area', array('component' => $component));
$DB->delete_records('tag_coll', array('component' => $component));
cache::make('core', 'tags')->delete_many(array('tag_area', 'tag_coll'));
}
|
php
|
public static function uninstall($pluginname) {
global $DB;
list($a, $b) = core_component::normalize_component($pluginname);
if (empty($b) || $a === 'core') {
throw new coding_exception('Core component can not be uninstalled');
}
$component = $a . '_' . $b;
core_tag_tag::delete_instances($component);
$DB->delete_records('tag_area', array('component' => $component));
$DB->delete_records('tag_coll', array('component' => $component));
cache::make('core', 'tags')->delete_many(array('tag_area', 'tag_coll'));
}
|
[
"public",
"static",
"function",
"uninstall",
"(",
"$",
"pluginname",
")",
"{",
"global",
"$",
"DB",
";",
"list",
"(",
"$",
"a",
",",
"$",
"b",
")",
"=",
"core_component",
"::",
"normalize_component",
"(",
"$",
"pluginname",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"b",
")",
"||",
"$",
"a",
"===",
"'core'",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Core component can not be uninstalled'",
")",
";",
"}",
"$",
"component",
"=",
"$",
"a",
".",
"'_'",
".",
"$",
"b",
";",
"core_tag_tag",
"::",
"delete_instances",
"(",
"$",
"component",
")",
";",
"$",
"DB",
"->",
"delete_records",
"(",
"'tag_area'",
",",
"array",
"(",
"'component'",
"=>",
"$",
"component",
")",
")",
";",
"$",
"DB",
"->",
"delete_records",
"(",
"'tag_coll'",
",",
"array",
"(",
"'component'",
"=>",
"$",
"component",
")",
")",
";",
"cache",
"::",
"make",
"(",
"'core'",
",",
"'tags'",
")",
"->",
"delete_many",
"(",
"array",
"(",
"'tag_area'",
",",
"'tag_coll'",
")",
")",
";",
"}"
] |
Deletes all tag areas, collections and instances associated with the plugin.
@param string $pluginname
|
[
"Deletes",
"all",
"tag",
"areas",
"collections",
"and",
"instances",
"associated",
"with",
"the",
"plugin",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/area.php#L386-L400
|
220,103
|
moodle/moodle
|
lib/simplepie/library/SimplePie/Misc.php
|
SimplePie_Misc.change_encoding
|
public static function change_encoding($data, $input, $output)
{
$input = SimplePie_Misc::encoding($input);
$output = SimplePie_Misc::encoding($output);
// We fail to fail on non US-ASCII bytes
if ($input === 'US-ASCII')
{
static $non_ascii_octects = '';
if (!$non_ascii_octects)
{
for ($i = 0x80; $i <= 0xFF; $i++)
{
$non_ascii_octects .= chr($i);
}
}
$data = substr($data, 0, strcspn($data, $non_ascii_octects));
}
// This is first, as behaviour of this is completely predictable
if ($input === 'windows-1252' && $output === 'UTF-8')
{
return SimplePie_Misc::windows_1252_to_utf8($data);
}
// This is second, as behaviour of this varies only with PHP version (the middle part of this expression checks the encoding is supported).
elseif (function_exists('mb_convert_encoding') && ($return = SimplePie_Misc::change_encoding_mbstring($data, $input, $output)))
{
return $return;
}
// This is third, as behaviour of this varies with OS userland and PHP version
elseif (function_exists('iconv') && ($return = SimplePie_Misc::change_encoding_iconv($data, $input, $output)))
{
return $return;
}
// This is last, as behaviour of this varies with OS userland and PHP version
elseif (class_exists('\UConverter') && ($return = SimplePie_Misc::change_encoding_uconverter($data, $input, $output)))
{
return $return;
}
// If we can't do anything, just fail
else
{
return false;
}
}
|
php
|
public static function change_encoding($data, $input, $output)
{
$input = SimplePie_Misc::encoding($input);
$output = SimplePie_Misc::encoding($output);
// We fail to fail on non US-ASCII bytes
if ($input === 'US-ASCII')
{
static $non_ascii_octects = '';
if (!$non_ascii_octects)
{
for ($i = 0x80; $i <= 0xFF; $i++)
{
$non_ascii_octects .= chr($i);
}
}
$data = substr($data, 0, strcspn($data, $non_ascii_octects));
}
// This is first, as behaviour of this is completely predictable
if ($input === 'windows-1252' && $output === 'UTF-8')
{
return SimplePie_Misc::windows_1252_to_utf8($data);
}
// This is second, as behaviour of this varies only with PHP version (the middle part of this expression checks the encoding is supported).
elseif (function_exists('mb_convert_encoding') && ($return = SimplePie_Misc::change_encoding_mbstring($data, $input, $output)))
{
return $return;
}
// This is third, as behaviour of this varies with OS userland and PHP version
elseif (function_exists('iconv') && ($return = SimplePie_Misc::change_encoding_iconv($data, $input, $output)))
{
return $return;
}
// This is last, as behaviour of this varies with OS userland and PHP version
elseif (class_exists('\UConverter') && ($return = SimplePie_Misc::change_encoding_uconverter($data, $input, $output)))
{
return $return;
}
// If we can't do anything, just fail
else
{
return false;
}
}
|
[
"public",
"static",
"function",
"change_encoding",
"(",
"$",
"data",
",",
"$",
"input",
",",
"$",
"output",
")",
"{",
"$",
"input",
"=",
"SimplePie_Misc",
"::",
"encoding",
"(",
"$",
"input",
")",
";",
"$",
"output",
"=",
"SimplePie_Misc",
"::",
"encoding",
"(",
"$",
"output",
")",
";",
"// We fail to fail on non US-ASCII bytes",
"if",
"(",
"$",
"input",
"===",
"'US-ASCII'",
")",
"{",
"static",
"$",
"non_ascii_octects",
"=",
"''",
";",
"if",
"(",
"!",
"$",
"non_ascii_octects",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0x80",
";",
"$",
"i",
"<=",
"0xFF",
";",
"$",
"i",
"++",
")",
"{",
"$",
"non_ascii_octects",
".=",
"chr",
"(",
"$",
"i",
")",
";",
"}",
"}",
"$",
"data",
"=",
"substr",
"(",
"$",
"data",
",",
"0",
",",
"strcspn",
"(",
"$",
"data",
",",
"$",
"non_ascii_octects",
")",
")",
";",
"}",
"// This is first, as behaviour of this is completely predictable",
"if",
"(",
"$",
"input",
"===",
"'windows-1252'",
"&&",
"$",
"output",
"===",
"'UTF-8'",
")",
"{",
"return",
"SimplePie_Misc",
"::",
"windows_1252_to_utf8",
"(",
"$",
"data",
")",
";",
"}",
"// This is second, as behaviour of this varies only with PHP version (the middle part of this expression checks the encoding is supported).",
"elseif",
"(",
"function_exists",
"(",
"'mb_convert_encoding'",
")",
"&&",
"(",
"$",
"return",
"=",
"SimplePie_Misc",
"::",
"change_encoding_mbstring",
"(",
"$",
"data",
",",
"$",
"input",
",",
"$",
"output",
")",
")",
")",
"{",
"return",
"$",
"return",
";",
"}",
"// This is third, as behaviour of this varies with OS userland and PHP version",
"elseif",
"(",
"function_exists",
"(",
"'iconv'",
")",
"&&",
"(",
"$",
"return",
"=",
"SimplePie_Misc",
"::",
"change_encoding_iconv",
"(",
"$",
"data",
",",
"$",
"input",
",",
"$",
"output",
")",
")",
")",
"{",
"return",
"$",
"return",
";",
"}",
"// This is last, as behaviour of this varies with OS userland and PHP version",
"elseif",
"(",
"class_exists",
"(",
"'\\UConverter'",
")",
"&&",
"(",
"$",
"return",
"=",
"SimplePie_Misc",
"::",
"change_encoding_uconverter",
"(",
"$",
"data",
",",
"$",
"input",
",",
"$",
"output",
")",
")",
")",
"{",
"return",
"$",
"return",
";",
"}",
"// If we can't do anything, just fail",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] |
Change a string from one encoding to another
@param string $data Raw data in $input encoding
@param string $input Encoding of $data
@param string $output Encoding you want
@return string|boolean False if we can't convert it
|
[
"Change",
"a",
"string",
"from",
"one",
"encoding",
"to",
"another"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/Misc.php#L307-L351
|
220,104
|
moodle/moodle
|
lib/simplepie/library/SimplePie/Misc.php
|
SimplePie_Misc.strip_comments
|
public static function strip_comments($data)
{
$output = '';
while (($start = strpos($data, '<!--')) !== false)
{
$output .= substr($data, 0, $start);
if (($end = strpos($data, '-->', $start)) !== false)
{
$data = substr_replace($data, '', 0, $end + 3);
}
else
{
$data = '';
}
}
return $output . $data;
}
|
php
|
public static function strip_comments($data)
{
$output = '';
while (($start = strpos($data, '<!--')) !== false)
{
$output .= substr($data, 0, $start);
if (($end = strpos($data, '-->', $start)) !== false)
{
$data = substr_replace($data, '', 0, $end + 3);
}
else
{
$data = '';
}
}
return $output . $data;
}
|
[
"public",
"static",
"function",
"strip_comments",
"(",
"$",
"data",
")",
"{",
"$",
"output",
"=",
"''",
";",
"while",
"(",
"(",
"$",
"start",
"=",
"strpos",
"(",
"$",
"data",
",",
"'<!--'",
")",
")",
"!==",
"false",
")",
"{",
"$",
"output",
".=",
"substr",
"(",
"$",
"data",
",",
"0",
",",
"$",
"start",
")",
";",
"if",
"(",
"(",
"$",
"end",
"=",
"strpos",
"(",
"$",
"data",
",",
"'-->'",
",",
"$",
"start",
")",
")",
"!==",
"false",
")",
"{",
"$",
"data",
"=",
"substr_replace",
"(",
"$",
"data",
",",
"''",
",",
"0",
",",
"$",
"end",
"+",
"3",
")",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"''",
";",
"}",
"}",
"return",
"$",
"output",
".",
"$",
"data",
";",
"}"
] |
Strip HTML comments
@param string $data Data to strip comments from
@return string Comment stripped string
|
[
"Strip",
"HTML",
"comments"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/Misc.php#L1758-L1774
|
220,105
|
moodle/moodle
|
lib/simplepie/library/SimplePie/Misc.php
|
SimplePie_Misc.uncomment_rfc822
|
public static function uncomment_rfc822($string)
{
$string = (string) $string;
$position = 0;
$length = strlen($string);
$depth = 0;
$output = '';
while ($position < $length && ($pos = strpos($string, '(', $position)) !== false)
{
$output .= substr($string, $position, $pos - $position);
$position = $pos + 1;
if ($string[$pos - 1] !== '\\')
{
$depth++;
while ($depth && $position < $length)
{
$position += strcspn($string, '()', $position);
if ($string[$position - 1] === '\\')
{
$position++;
continue;
}
elseif (isset($string[$position]))
{
switch ($string[$position])
{
case '(':
$depth++;
break;
case ')':
$depth--;
break;
}
$position++;
}
else
{
break;
}
}
}
else
{
$output .= '(';
}
}
$output .= substr($string, $position);
return $output;
}
|
php
|
public static function uncomment_rfc822($string)
{
$string = (string) $string;
$position = 0;
$length = strlen($string);
$depth = 0;
$output = '';
while ($position < $length && ($pos = strpos($string, '(', $position)) !== false)
{
$output .= substr($string, $position, $pos - $position);
$position = $pos + 1;
if ($string[$pos - 1] !== '\\')
{
$depth++;
while ($depth && $position < $length)
{
$position += strcspn($string, '()', $position);
if ($string[$position - 1] === '\\')
{
$position++;
continue;
}
elseif (isset($string[$position]))
{
switch ($string[$position])
{
case '(':
$depth++;
break;
case ')':
$depth--;
break;
}
$position++;
}
else
{
break;
}
}
}
else
{
$output .= '(';
}
}
$output .= substr($string, $position);
return $output;
}
|
[
"public",
"static",
"function",
"uncomment_rfc822",
"(",
"$",
"string",
")",
"{",
"$",
"string",
"=",
"(",
"string",
")",
"$",
"string",
";",
"$",
"position",
"=",
"0",
";",
"$",
"length",
"=",
"strlen",
"(",
"$",
"string",
")",
";",
"$",
"depth",
"=",
"0",
";",
"$",
"output",
"=",
"''",
";",
"while",
"(",
"$",
"position",
"<",
"$",
"length",
"&&",
"(",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"string",
",",
"'('",
",",
"$",
"position",
")",
")",
"!==",
"false",
")",
"{",
"$",
"output",
".=",
"substr",
"(",
"$",
"string",
",",
"$",
"position",
",",
"$",
"pos",
"-",
"$",
"position",
")",
";",
"$",
"position",
"=",
"$",
"pos",
"+",
"1",
";",
"if",
"(",
"$",
"string",
"[",
"$",
"pos",
"-",
"1",
"]",
"!==",
"'\\\\'",
")",
"{",
"$",
"depth",
"++",
";",
"while",
"(",
"$",
"depth",
"&&",
"$",
"position",
"<",
"$",
"length",
")",
"{",
"$",
"position",
"+=",
"strcspn",
"(",
"$",
"string",
",",
"'()'",
",",
"$",
"position",
")",
";",
"if",
"(",
"$",
"string",
"[",
"$",
"position",
"-",
"1",
"]",
"===",
"'\\\\'",
")",
"{",
"$",
"position",
"++",
";",
"continue",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"string",
"[",
"$",
"position",
"]",
")",
")",
"{",
"switch",
"(",
"$",
"string",
"[",
"$",
"position",
"]",
")",
"{",
"case",
"'('",
":",
"$",
"depth",
"++",
";",
"break",
";",
"case",
"')'",
":",
"$",
"depth",
"--",
";",
"break",
";",
"}",
"$",
"position",
"++",
";",
"}",
"else",
"{",
"break",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"output",
".=",
"'('",
";",
"}",
"}",
"$",
"output",
".=",
"substr",
"(",
"$",
"string",
",",
"$",
"position",
")",
";",
"return",
"$",
"output",
";",
"}"
] |
Remove RFC822 comments
@param string $data Data to strip comments from
@return string Comment stripped string
|
[
"Remove",
"RFC822",
"comments"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/Misc.php#L1801-L1853
|
220,106
|
moodle/moodle
|
lib/simplepie/library/SimplePie/Misc.php
|
SimplePie_Misc.codepoint_to_utf8
|
public static function codepoint_to_utf8($codepoint)
{
$codepoint = (int) $codepoint;
if ($codepoint < 0)
{
return false;
}
else if ($codepoint <= 0x7f)
{
return chr($codepoint);
}
else if ($codepoint <= 0x7ff)
{
return chr(0xc0 | ($codepoint >> 6)) . chr(0x80 | ($codepoint & 0x3f));
}
else if ($codepoint <= 0xffff)
{
return chr(0xe0 | ($codepoint >> 12)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f));
}
else if ($codepoint <= 0x10ffff)
{
return chr(0xf0 | ($codepoint >> 18)) . chr(0x80 | (($codepoint >> 12) & 0x3f)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f));
}
else
{
// U+FFFD REPLACEMENT CHARACTER
return "\xEF\xBF\xBD";
}
}
|
php
|
public static function codepoint_to_utf8($codepoint)
{
$codepoint = (int) $codepoint;
if ($codepoint < 0)
{
return false;
}
else if ($codepoint <= 0x7f)
{
return chr($codepoint);
}
else if ($codepoint <= 0x7ff)
{
return chr(0xc0 | ($codepoint >> 6)) . chr(0x80 | ($codepoint & 0x3f));
}
else if ($codepoint <= 0xffff)
{
return chr(0xe0 | ($codepoint >> 12)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f));
}
else if ($codepoint <= 0x10ffff)
{
return chr(0xf0 | ($codepoint >> 18)) . chr(0x80 | (($codepoint >> 12) & 0x3f)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f));
}
else
{
// U+FFFD REPLACEMENT CHARACTER
return "\xEF\xBF\xBD";
}
}
|
[
"public",
"static",
"function",
"codepoint_to_utf8",
"(",
"$",
"codepoint",
")",
"{",
"$",
"codepoint",
"=",
"(",
"int",
")",
"$",
"codepoint",
";",
"if",
"(",
"$",
"codepoint",
"<",
"0",
")",
"{",
"return",
"false",
";",
"}",
"else",
"if",
"(",
"$",
"codepoint",
"<=",
"0x7f",
")",
"{",
"return",
"chr",
"(",
"$",
"codepoint",
")",
";",
"}",
"else",
"if",
"(",
"$",
"codepoint",
"<=",
"0x7ff",
")",
"{",
"return",
"chr",
"(",
"0xc0",
"|",
"(",
"$",
"codepoint",
">>",
"6",
")",
")",
".",
"chr",
"(",
"0x80",
"|",
"(",
"$",
"codepoint",
"&",
"0x3f",
")",
")",
";",
"}",
"else",
"if",
"(",
"$",
"codepoint",
"<=",
"0xffff",
")",
"{",
"return",
"chr",
"(",
"0xe0",
"|",
"(",
"$",
"codepoint",
">>",
"12",
")",
")",
".",
"chr",
"(",
"0x80",
"|",
"(",
"(",
"$",
"codepoint",
">>",
"6",
")",
"&",
"0x3f",
")",
")",
".",
"chr",
"(",
"0x80",
"|",
"(",
"$",
"codepoint",
"&",
"0x3f",
")",
")",
";",
"}",
"else",
"if",
"(",
"$",
"codepoint",
"<=",
"0x10ffff",
")",
"{",
"return",
"chr",
"(",
"0xf0",
"|",
"(",
"$",
"codepoint",
">>",
"18",
")",
")",
".",
"chr",
"(",
"0x80",
"|",
"(",
"(",
"$",
"codepoint",
">>",
"12",
")",
"&",
"0x3f",
")",
")",
".",
"chr",
"(",
"0x80",
"|",
"(",
"(",
"$",
"codepoint",
">>",
"6",
")",
"&",
"0x3f",
")",
")",
".",
"chr",
"(",
"0x80",
"|",
"(",
"$",
"codepoint",
"&",
"0x3f",
")",
")",
";",
"}",
"else",
"{",
"// U+FFFD REPLACEMENT CHARACTER",
"return",
"\"\\xEF\\xBF\\xBD\"",
";",
"}",
"}"
] |
Converts a unicode codepoint to a UTF-8 character
@static
@param int $codepoint Unicode codepoint
@return string UTF-8 character
|
[
"Converts",
"a",
"unicode",
"codepoint",
"to",
"a",
"UTF",
"-",
"8",
"character"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/Misc.php#L1987-L2015
|
220,107
|
moodle/moodle
|
lib/simplepie/library/SimplePie/Misc.php
|
SimplePie_Misc.debug
|
public static function debug(&$sp)
{
$info = 'SimplePie ' . SIMPLEPIE_VERSION . ' Build ' . SIMPLEPIE_BUILD . "\n";
$info .= 'PHP ' . PHP_VERSION . "\n";
if ($sp->error() !== null)
{
$info .= 'Error occurred: ' . $sp->error() . "\n";
}
else
{
$info .= "No error found.\n";
}
$info .= "Extensions:\n";
$extensions = array('pcre', 'curl', 'zlib', 'mbstring', 'iconv', 'xmlreader', 'xml');
foreach ($extensions as $ext)
{
if (extension_loaded($ext))
{
$info .= " $ext loaded\n";
switch ($ext)
{
case 'pcre':
$info .= ' Version ' . PCRE_VERSION . "\n";
break;
case 'curl':
$version = curl_version();
$info .= ' Version ' . $version['version'] . "\n";
break;
case 'mbstring':
$info .= ' Overloading: ' . mb_get_info('func_overload') . "\n";
break;
case 'iconv':
$info .= ' Version ' . ICONV_VERSION . "\n";
break;
case 'xml':
$info .= ' Version ' . LIBXML_DOTTED_VERSION . "\n";
break;
}
}
else
{
$info .= " $ext not loaded\n";
}
}
return $info;
}
|
php
|
public static function debug(&$sp)
{
$info = 'SimplePie ' . SIMPLEPIE_VERSION . ' Build ' . SIMPLEPIE_BUILD . "\n";
$info .= 'PHP ' . PHP_VERSION . "\n";
if ($sp->error() !== null)
{
$info .= 'Error occurred: ' . $sp->error() . "\n";
}
else
{
$info .= "No error found.\n";
}
$info .= "Extensions:\n";
$extensions = array('pcre', 'curl', 'zlib', 'mbstring', 'iconv', 'xmlreader', 'xml');
foreach ($extensions as $ext)
{
if (extension_loaded($ext))
{
$info .= " $ext loaded\n";
switch ($ext)
{
case 'pcre':
$info .= ' Version ' . PCRE_VERSION . "\n";
break;
case 'curl':
$version = curl_version();
$info .= ' Version ' . $version['version'] . "\n";
break;
case 'mbstring':
$info .= ' Overloading: ' . mb_get_info('func_overload') . "\n";
break;
case 'iconv':
$info .= ' Version ' . ICONV_VERSION . "\n";
break;
case 'xml':
$info .= ' Version ' . LIBXML_DOTTED_VERSION . "\n";
break;
}
}
else
{
$info .= " $ext not loaded\n";
}
}
return $info;
}
|
[
"public",
"static",
"function",
"debug",
"(",
"&",
"$",
"sp",
")",
"{",
"$",
"info",
"=",
"'SimplePie '",
".",
"SIMPLEPIE_VERSION",
".",
"' Build '",
".",
"SIMPLEPIE_BUILD",
".",
"\"\\n\"",
";",
"$",
"info",
".=",
"'PHP '",
".",
"PHP_VERSION",
".",
"\"\\n\"",
";",
"if",
"(",
"$",
"sp",
"->",
"error",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"info",
".=",
"'Error occurred: '",
".",
"$",
"sp",
"->",
"error",
"(",
")",
".",
"\"\\n\"",
";",
"}",
"else",
"{",
"$",
"info",
".=",
"\"No error found.\\n\"",
";",
"}",
"$",
"info",
".=",
"\"Extensions:\\n\"",
";",
"$",
"extensions",
"=",
"array",
"(",
"'pcre'",
",",
"'curl'",
",",
"'zlib'",
",",
"'mbstring'",
",",
"'iconv'",
",",
"'xmlreader'",
",",
"'xml'",
")",
";",
"foreach",
"(",
"$",
"extensions",
"as",
"$",
"ext",
")",
"{",
"if",
"(",
"extension_loaded",
"(",
"$",
"ext",
")",
")",
"{",
"$",
"info",
".=",
"\" $ext loaded\\n\"",
";",
"switch",
"(",
"$",
"ext",
")",
"{",
"case",
"'pcre'",
":",
"$",
"info",
".=",
"' Version '",
".",
"PCRE_VERSION",
".",
"\"\\n\"",
";",
"break",
";",
"case",
"'curl'",
":",
"$",
"version",
"=",
"curl_version",
"(",
")",
";",
"$",
"info",
".=",
"' Version '",
".",
"$",
"version",
"[",
"'version'",
"]",
".",
"\"\\n\"",
";",
"break",
";",
"case",
"'mbstring'",
":",
"$",
"info",
".=",
"' Overloading: '",
".",
"mb_get_info",
"(",
"'func_overload'",
")",
".",
"\"\\n\"",
";",
"break",
";",
"case",
"'iconv'",
":",
"$",
"info",
".=",
"' Version '",
".",
"ICONV_VERSION",
".",
"\"\\n\"",
";",
"break",
";",
"case",
"'xml'",
":",
"$",
"info",
".=",
"' Version '",
".",
"LIBXML_DOTTED_VERSION",
".",
"\"\\n\"",
";",
"break",
";",
"}",
"}",
"else",
"{",
"$",
"info",
".=",
"\" $ext not loaded\\n\"",
";",
"}",
"}",
"return",
"$",
"info",
";",
"}"
] |
Format debugging information
|
[
"Format",
"debugging",
"information"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/Misc.php#L2227-L2272
|
220,108
|
moodle/moodle
|
blocks/activity_results/block_activity_results.php
|
block_activity_results.get_owning_activity
|
public function get_owning_activity() {
global $DB;
// Set some defaults.
$result = new stdClass();
$result->id = 0;
if (empty($this->instance->parentcontextid)) {
return $result;
}
$parentcontext = context::instance_by_id($this->instance->parentcontextid);
if ($parentcontext->contextlevel != CONTEXT_MODULE) {
return $result;
}
$cm = get_coursemodule_from_id($this->page->cm->modname, $parentcontext->instanceid);
if (!$cm) {
return $result;
}
// Get the grade_items id.
$rec = $DB->get_record('grade_items', array('iteminstance' => $cm->instance, 'itemmodule' => $this->page->cm->modname));
if (!$rec) {
return $result;
}
// See if it is a gradable activity.
if (($rec->gradetype != GRADE_TYPE_VALUE) && ($rec->gradetype != GRADE_TYPE_SCALE)) {
return $result;
}
return $rec;
}
|
php
|
public function get_owning_activity() {
global $DB;
// Set some defaults.
$result = new stdClass();
$result->id = 0;
if (empty($this->instance->parentcontextid)) {
return $result;
}
$parentcontext = context::instance_by_id($this->instance->parentcontextid);
if ($parentcontext->contextlevel != CONTEXT_MODULE) {
return $result;
}
$cm = get_coursemodule_from_id($this->page->cm->modname, $parentcontext->instanceid);
if (!$cm) {
return $result;
}
// Get the grade_items id.
$rec = $DB->get_record('grade_items', array('iteminstance' => $cm->instance, 'itemmodule' => $this->page->cm->modname));
if (!$rec) {
return $result;
}
// See if it is a gradable activity.
if (($rec->gradetype != GRADE_TYPE_VALUE) && ($rec->gradetype != GRADE_TYPE_SCALE)) {
return $result;
}
return $rec;
}
|
[
"public",
"function",
"get_owning_activity",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"// Set some defaults.",
"$",
"result",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"result",
"->",
"id",
"=",
"0",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"instance",
"->",
"parentcontextid",
")",
")",
"{",
"return",
"$",
"result",
";",
"}",
"$",
"parentcontext",
"=",
"context",
"::",
"instance_by_id",
"(",
"$",
"this",
"->",
"instance",
"->",
"parentcontextid",
")",
";",
"if",
"(",
"$",
"parentcontext",
"->",
"contextlevel",
"!=",
"CONTEXT_MODULE",
")",
"{",
"return",
"$",
"result",
";",
"}",
"$",
"cm",
"=",
"get_coursemodule_from_id",
"(",
"$",
"this",
"->",
"page",
"->",
"cm",
"->",
"modname",
",",
"$",
"parentcontext",
"->",
"instanceid",
")",
";",
"if",
"(",
"!",
"$",
"cm",
")",
"{",
"return",
"$",
"result",
";",
"}",
"// Get the grade_items id.",
"$",
"rec",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'grade_items'",
",",
"array",
"(",
"'iteminstance'",
"=>",
"$",
"cm",
"->",
"instance",
",",
"'itemmodule'",
"=>",
"$",
"this",
"->",
"page",
"->",
"cm",
"->",
"modname",
")",
")",
";",
"if",
"(",
"!",
"$",
"rec",
")",
"{",
"return",
"$",
"result",
";",
"}",
"// See if it is a gradable activity.",
"if",
"(",
"(",
"$",
"rec",
"->",
"gradetype",
"!=",
"GRADE_TYPE_VALUE",
")",
"&&",
"(",
"$",
"rec",
"->",
"gradetype",
"!=",
"GRADE_TYPE_SCALE",
")",
")",
"{",
"return",
"$",
"result",
";",
"}",
"return",
"$",
"rec",
";",
"}"
] |
If this block belongs to a activity context, then return that activity's id.
Otherwise, return 0.
@return stdclass the activity record.
|
[
"If",
"this",
"block",
"belongs",
"to",
"a",
"activity",
"context",
"then",
"return",
"that",
"activity",
"s",
"id",
".",
"Otherwise",
"return",
"0",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/activity_results/block_activity_results.php#L81-L109
|
220,109
|
moodle/moodle
|
blocks/activity_results/block_activity_results.php
|
block_activity_results.instance_config_save
|
public function instance_config_save($data, $nolongerused = false) {
global $DB;
if (empty($data->activitygradeitemid)) {
// Figure out info about parent module.
$info = $this->get_owning_activity();
$data->activitygradeitemid = $info->id;
if ($info->id < 1) {
// No activity was selected.
$info->itemmodule = '';
$info->iteminstance = '';
} else {
$data->activityparent = $info->itemmodule;
$data->activityparentid = $info->iteminstance;
}
} else {
// Lookup info about the parent module (we have the id from mdl_grade_items.
$info = $DB->get_record('grade_items', array('id' => $data->activitygradeitemid));
$data->activityparent = $info->itemmodule;
$data->activityparentid = $info->iteminstance;
}
parent::instance_config_save($data);
}
|
php
|
public function instance_config_save($data, $nolongerused = false) {
global $DB;
if (empty($data->activitygradeitemid)) {
// Figure out info about parent module.
$info = $this->get_owning_activity();
$data->activitygradeitemid = $info->id;
if ($info->id < 1) {
// No activity was selected.
$info->itemmodule = '';
$info->iteminstance = '';
} else {
$data->activityparent = $info->itemmodule;
$data->activityparentid = $info->iteminstance;
}
} else {
// Lookup info about the parent module (we have the id from mdl_grade_items.
$info = $DB->get_record('grade_items', array('id' => $data->activitygradeitemid));
$data->activityparent = $info->itemmodule;
$data->activityparentid = $info->iteminstance;
}
parent::instance_config_save($data);
}
|
[
"public",
"function",
"instance_config_save",
"(",
"$",
"data",
",",
"$",
"nolongerused",
"=",
"false",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"empty",
"(",
"$",
"data",
"->",
"activitygradeitemid",
")",
")",
"{",
"// Figure out info about parent module.",
"$",
"info",
"=",
"$",
"this",
"->",
"get_owning_activity",
"(",
")",
";",
"$",
"data",
"->",
"activitygradeitemid",
"=",
"$",
"info",
"->",
"id",
";",
"if",
"(",
"$",
"info",
"->",
"id",
"<",
"1",
")",
"{",
"// No activity was selected.",
"$",
"info",
"->",
"itemmodule",
"=",
"''",
";",
"$",
"info",
"->",
"iteminstance",
"=",
"''",
";",
"}",
"else",
"{",
"$",
"data",
"->",
"activityparent",
"=",
"$",
"info",
"->",
"itemmodule",
";",
"$",
"data",
"->",
"activityparentid",
"=",
"$",
"info",
"->",
"iteminstance",
";",
"}",
"}",
"else",
"{",
"// Lookup info about the parent module (we have the id from mdl_grade_items.",
"$",
"info",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'grade_items'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"data",
"->",
"activitygradeitemid",
")",
")",
";",
"$",
"data",
"->",
"activityparent",
"=",
"$",
"info",
"->",
"itemmodule",
";",
"$",
"data",
"->",
"activityparentid",
"=",
"$",
"info",
"->",
"iteminstance",
";",
"}",
"parent",
"::",
"instance_config_save",
"(",
"$",
"data",
")",
";",
"}"
] |
Used to save the form config data
@param stdclass $data
@param bool $nolongerused
|
[
"Used",
"to",
"save",
"the",
"form",
"config",
"data"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/activity_results/block_activity_results.php#L116-L137
|
220,110
|
moodle/moodle
|
blocks/activity_results/block_activity_results.php
|
block_activity_results.activity_format_grade
|
private function activity_format_grade($grade) {
if (is_null($grade)) {
return get_string('notyetgraded', 'block_activity_results');
}
return format_float($grade, $this->config->decimalpoints);
}
|
php
|
private function activity_format_grade($grade) {
if (is_null($grade)) {
return get_string('notyetgraded', 'block_activity_results');
}
return format_float($grade, $this->config->decimalpoints);
}
|
[
"private",
"function",
"activity_format_grade",
"(",
"$",
"grade",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"grade",
")",
")",
"{",
"return",
"get_string",
"(",
"'notyetgraded'",
",",
"'block_activity_results'",
")",
";",
"}",
"return",
"format_float",
"(",
"$",
"grade",
",",
"$",
"this",
"->",
"config",
"->",
"decimalpoints",
")",
";",
"}"
] |
Formats the grade to the specified decimal points
@param float $grade
@return string
|
[
"Formats",
"the",
"grade",
"to",
"the",
"specified",
"decimal",
"points"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/activity_results/block_activity_results.php#L673-L678
|
220,111
|
moodle/moodle
|
blocks/activity_results/block_activity_results.php
|
block_activity_results.activity_link
|
private function activity_link($activity, $cm) {
$o = html_writer::start_tag('h3');
$o .= html_writer::link(new moodle_url('/mod/'.$activity->itemmodule.'/view.php',
array('id' => $cm->id)), format_string(($activity->itemname), true, ['context' => context_module::instance($cm->id)]));
$o .= html_writer::end_tag('h3');
return $o;
}
|
php
|
private function activity_link($activity, $cm) {
$o = html_writer::start_tag('h3');
$o .= html_writer::link(new moodle_url('/mod/'.$activity->itemmodule.'/view.php',
array('id' => $cm->id)), format_string(($activity->itemname), true, ['context' => context_module::instance($cm->id)]));
$o .= html_writer::end_tag('h3');
return $o;
}
|
[
"private",
"function",
"activity_link",
"(",
"$",
"activity",
",",
"$",
"cm",
")",
"{",
"$",
"o",
"=",
"html_writer",
"::",
"start_tag",
"(",
"'h3'",
")",
";",
"$",
"o",
".=",
"html_writer",
"::",
"link",
"(",
"new",
"moodle_url",
"(",
"'/mod/'",
".",
"$",
"activity",
"->",
"itemmodule",
".",
"'/view.php'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"cm",
"->",
"id",
")",
")",
",",
"format_string",
"(",
"(",
"$",
"activity",
"->",
"itemname",
")",
",",
"true",
",",
"[",
"'context'",
"=>",
"context_module",
"::",
"instance",
"(",
"$",
"cm",
"->",
"id",
")",
"]",
")",
")",
";",
"$",
"o",
".=",
"html_writer",
"::",
"end_tag",
"(",
"'h3'",
")",
";",
"return",
"$",
"o",
";",
"}"
] |
Generates the Link to the activity module when displaed outside of the module
@param stdclass $activity
@param stdclass $cm
@return string
|
[
"Generates",
"the",
"Link",
"to",
"the",
"activity",
"module",
"when",
"displaed",
"outside",
"of",
"the",
"module"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/activity_results/block_activity_results.php#L686-L693
|
220,112
|
moodle/moodle
|
blocks/activity_results/block_activity_results.php
|
block_activity_results.get_scale
|
private function get_scale($scaleid) {
global $DB;
$scaletext = $DB->get_field('scale', 'scale', array('id' => $scaleid), IGNORE_MISSING);
$scale = explode ( ',', $scaletext);
return $scale;
}
|
php
|
private function get_scale($scaleid) {
global $DB;
$scaletext = $DB->get_field('scale', 'scale', array('id' => $scaleid), IGNORE_MISSING);
$scale = explode ( ',', $scaletext);
return $scale;
}
|
[
"private",
"function",
"get_scale",
"(",
"$",
"scaleid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"scaletext",
"=",
"$",
"DB",
"->",
"get_field",
"(",
"'scale'",
",",
"'scale'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"scaleid",
")",
",",
"IGNORE_MISSING",
")",
";",
"$",
"scale",
"=",
"explode",
"(",
"','",
",",
"$",
"scaletext",
")",
";",
"return",
"$",
"scale",
";",
"}"
] |
Generates a numeric array of scale entries
@param int $scaleid
@return array
|
[
"Generates",
"a",
"numeric",
"array",
"of",
"scale",
"entries"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/activity_results/block_activity_results.php#L700-L706
|
220,113
|
moodle/moodle
|
lib/ltiprovider/src/ToolProvider/ResourceLink.php
|
ResourceLink.doSettingService
|
public function doSettingService($action, $value = null)
{
$response = false;
$this->extResponse = null;
switch ($action) {
case self::EXT_READ:
$do = 'basic-lti-loadsetting';
break;
case self::EXT_WRITE:
$do = 'basic-lti-savesetting';
break;
case self::EXT_DELETE:
$do = 'basic-lti-deletesetting';
break;
}
if (isset($do)) {
$url = $this->getSetting('ext_ims_lti_tool_setting_url');
$params = array();
$params['id'] = $this->getSetting('ext_ims_lti_tool_setting_id');
if (is_null($value)) {
$value = '';
}
$params['setting'] = $value;
if ($this->doService($do, $url, $params)) {
switch ($action) {
case self::EXT_READ:
if (isset($this->extNodes['setting']['value'])) {
$response = $this->extNodes['setting']['value'];
if (is_array($response)) {
$response = '';
}
}
break;
case self::EXT_WRITE:
$this->setSetting('ext_ims_lti_tool_setting', $value);
$this->saveSettings();
$response = true;
break;
case self::EXT_DELETE:
$response = true;
break;
}
}
}
return $response;
}
|
php
|
public function doSettingService($action, $value = null)
{
$response = false;
$this->extResponse = null;
switch ($action) {
case self::EXT_READ:
$do = 'basic-lti-loadsetting';
break;
case self::EXT_WRITE:
$do = 'basic-lti-savesetting';
break;
case self::EXT_DELETE:
$do = 'basic-lti-deletesetting';
break;
}
if (isset($do)) {
$url = $this->getSetting('ext_ims_lti_tool_setting_url');
$params = array();
$params['id'] = $this->getSetting('ext_ims_lti_tool_setting_id');
if (is_null($value)) {
$value = '';
}
$params['setting'] = $value;
if ($this->doService($do, $url, $params)) {
switch ($action) {
case self::EXT_READ:
if (isset($this->extNodes['setting']['value'])) {
$response = $this->extNodes['setting']['value'];
if (is_array($response)) {
$response = '';
}
}
break;
case self::EXT_WRITE:
$this->setSetting('ext_ims_lti_tool_setting', $value);
$this->saveSettings();
$response = true;
break;
case self::EXT_DELETE:
$response = true;
break;
}
}
}
return $response;
}
|
[
"public",
"function",
"doSettingService",
"(",
"$",
"action",
",",
"$",
"value",
"=",
"null",
")",
"{",
"$",
"response",
"=",
"false",
";",
"$",
"this",
"->",
"extResponse",
"=",
"null",
";",
"switch",
"(",
"$",
"action",
")",
"{",
"case",
"self",
"::",
"EXT_READ",
":",
"$",
"do",
"=",
"'basic-lti-loadsetting'",
";",
"break",
";",
"case",
"self",
"::",
"EXT_WRITE",
":",
"$",
"do",
"=",
"'basic-lti-savesetting'",
";",
"break",
";",
"case",
"self",
"::",
"EXT_DELETE",
":",
"$",
"do",
"=",
"'basic-lti-deletesetting'",
";",
"break",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"do",
")",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"getSetting",
"(",
"'ext_ims_lti_tool_setting_url'",
")",
";",
"$",
"params",
"=",
"array",
"(",
")",
";",
"$",
"params",
"[",
"'id'",
"]",
"=",
"$",
"this",
"->",
"getSetting",
"(",
"'ext_ims_lti_tool_setting_id'",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"''",
";",
"}",
"$",
"params",
"[",
"'setting'",
"]",
"=",
"$",
"value",
";",
"if",
"(",
"$",
"this",
"->",
"doService",
"(",
"$",
"do",
",",
"$",
"url",
",",
"$",
"params",
")",
")",
"{",
"switch",
"(",
"$",
"action",
")",
"{",
"case",
"self",
"::",
"EXT_READ",
":",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"extNodes",
"[",
"'setting'",
"]",
"[",
"'value'",
"]",
")",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"extNodes",
"[",
"'setting'",
"]",
"[",
"'value'",
"]",
";",
"if",
"(",
"is_array",
"(",
"$",
"response",
")",
")",
"{",
"$",
"response",
"=",
"''",
";",
"}",
"}",
"break",
";",
"case",
"self",
"::",
"EXT_WRITE",
":",
"$",
"this",
"->",
"setSetting",
"(",
"'ext_ims_lti_tool_setting'",
",",
"$",
"value",
")",
";",
"$",
"this",
"->",
"saveSettings",
"(",
")",
";",
"$",
"response",
"=",
"true",
";",
"break",
";",
"case",
"self",
"::",
"EXT_DELETE",
":",
"$",
"response",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"return",
"$",
"response",
";",
"}"
] |
Perform a Setting service request.
@param int $action The action type constant
@param string $value The setting value (optional, default is null)
@return mixed The setting value for a read action, true if a write or delete action was successful, otherwise false
|
[
"Perform",
"a",
"Setting",
"service",
"request",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ltiprovider/src/ToolProvider/ResourceLink.php#L791-L841
|
220,114
|
moodle/moodle
|
lib/ltiprovider/src/ToolProvider/ResourceLink.php
|
ResourceLink.hasMembershipService
|
public function hasMembershipService()
{
$has = !empty($this->contextId);
if ($has) {
$has = !empty($this->getContext()->getSetting('custom_context_memberships_url'));
}
return $has;
}
|
php
|
public function hasMembershipService()
{
$has = !empty($this->contextId);
if ($has) {
$has = !empty($this->getContext()->getSetting('custom_context_memberships_url'));
}
return $has;
}
|
[
"public",
"function",
"hasMembershipService",
"(",
")",
"{",
"$",
"has",
"=",
"!",
"empty",
"(",
"$",
"this",
"->",
"contextId",
")",
";",
"if",
"(",
"$",
"has",
")",
"{",
"$",
"has",
"=",
"!",
"empty",
"(",
"$",
"this",
"->",
"getContext",
"(",
")",
"->",
"getSetting",
"(",
"'custom_context_memberships_url'",
")",
")",
";",
"}",
"return",
"$",
"has",
";",
"}"
] |
Check if the Membership service is supported.
@return boolean True if this resource link supports the Membership service
|
[
"Check",
"if",
"the",
"Membership",
"service",
"is",
"supported",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ltiprovider/src/ToolProvider/ResourceLink.php#L899-L909
|
220,115
|
moodle/moodle
|
lib/ltiprovider/src/ToolProvider/ResourceLink.php
|
ResourceLink.fromContext
|
public static function fromContext($context, $ltiResourceLinkId, $tempId = null)
{
$resourceLink = new ResourceLink();
$resourceLink->setContextId($context->getRecordId());
$resourceLink->context = $context;
$resourceLink->dataConnector = $context->getDataConnector();
$resourceLink->ltiResourceLinkId = $ltiResourceLinkId;
if (!empty($ltiResourceLinkId)) {
$resourceLink->load();
if (is_null($resourceLink->id) && !empty($tempId)) {
$resourceLink->ltiResourceLinkId = $tempId;
$resourceLink->load();
$resourceLink->ltiResourceLinkId = $ltiResourceLinkId;
}
}
return $resourceLink;
}
|
php
|
public static function fromContext($context, $ltiResourceLinkId, $tempId = null)
{
$resourceLink = new ResourceLink();
$resourceLink->setContextId($context->getRecordId());
$resourceLink->context = $context;
$resourceLink->dataConnector = $context->getDataConnector();
$resourceLink->ltiResourceLinkId = $ltiResourceLinkId;
if (!empty($ltiResourceLinkId)) {
$resourceLink->load();
if (is_null($resourceLink->id) && !empty($tempId)) {
$resourceLink->ltiResourceLinkId = $tempId;
$resourceLink->load();
$resourceLink->ltiResourceLinkId = $ltiResourceLinkId;
}
}
return $resourceLink;
}
|
[
"public",
"static",
"function",
"fromContext",
"(",
"$",
"context",
",",
"$",
"ltiResourceLinkId",
",",
"$",
"tempId",
"=",
"null",
")",
"{",
"$",
"resourceLink",
"=",
"new",
"ResourceLink",
"(",
")",
";",
"$",
"resourceLink",
"->",
"setContextId",
"(",
"$",
"context",
"->",
"getRecordId",
"(",
")",
")",
";",
"$",
"resourceLink",
"->",
"context",
"=",
"$",
"context",
";",
"$",
"resourceLink",
"->",
"dataConnector",
"=",
"$",
"context",
"->",
"getDataConnector",
"(",
")",
";",
"$",
"resourceLink",
"->",
"ltiResourceLinkId",
"=",
"$",
"ltiResourceLinkId",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"ltiResourceLinkId",
")",
")",
"{",
"$",
"resourceLink",
"->",
"load",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"resourceLink",
"->",
"id",
")",
"&&",
"!",
"empty",
"(",
"$",
"tempId",
")",
")",
"{",
"$",
"resourceLink",
"->",
"ltiResourceLinkId",
"=",
"$",
"tempId",
";",
"$",
"resourceLink",
"->",
"load",
"(",
")",
";",
"$",
"resourceLink",
"->",
"ltiResourceLinkId",
"=",
"$",
"ltiResourceLinkId",
";",
"}",
"}",
"return",
"$",
"resourceLink",
";",
"}"
] |
Class constructor from context.
@param Context $context Context object
@param string $ltiResourceLinkId Resource link ID value
@param string $tempId Temporary Resource link ID value (optional, default is null)
@return ResourceLink
|
[
"Class",
"constructor",
"from",
"context",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ltiprovider/src/ToolProvider/ResourceLink.php#L998-L1017
|
220,116
|
moodle/moodle
|
analytics/classes/site.php
|
site.get_start
|
public function get_start() {
if (!empty($this->start)) {
return $this->start;
}
// Much faster than reading the first log in the site.
$admins = get_admins();
$this->start = 9999999999;
foreach ($admins as $admin) {
if ($admin->firstaccess < $this->start) {
$this->start = $admin->firstaccess;
}
}
return $this->start;
}
|
php
|
public function get_start() {
if (!empty($this->start)) {
return $this->start;
}
// Much faster than reading the first log in the site.
$admins = get_admins();
$this->start = 9999999999;
foreach ($admins as $admin) {
if ($admin->firstaccess < $this->start) {
$this->start = $admin->firstaccess;
}
}
return $this->start;
}
|
[
"public",
"function",
"get_start",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"start",
")",
")",
"{",
"return",
"$",
"this",
"->",
"start",
";",
"}",
"// Much faster than reading the first log in the site.",
"$",
"admins",
"=",
"get_admins",
"(",
")",
";",
"$",
"this",
"->",
"start",
"=",
"9999999999",
";",
"foreach",
"(",
"$",
"admins",
"as",
"$",
"admin",
")",
"{",
"if",
"(",
"$",
"admin",
"->",
"firstaccess",
"<",
"$",
"this",
"->",
"start",
")",
"{",
"$",
"this",
"->",
"start",
"=",
"$",
"admin",
"->",
"firstaccess",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"start",
";",
"}"
] |
Analysable start timestamp.
@return int
|
[
"Analysable",
"start",
"timestamp",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/site.php#L80-L94
|
220,117
|
moodle/moodle
|
analytics/classes/site.php
|
site.get_end
|
public function get_end() {
if (!empty($this->end)) {
return $this->end;
}
$this->end = time();
return $this->end;
}
|
php
|
public function get_end() {
if (!empty($this->end)) {
return $this->end;
}
$this->end = time();
return $this->end;
}
|
[
"public",
"function",
"get_end",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"end",
")",
")",
"{",
"return",
"$",
"this",
"->",
"end",
";",
"}",
"$",
"this",
"->",
"end",
"=",
"time",
"(",
")",
";",
"return",
"$",
"this",
"->",
"end",
";",
"}"
] |
Analysable end timestamp.
@return int
|
[
"Analysable",
"end",
"timestamp",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/site.php#L101-L108
|
220,118
|
moodle/moodle
|
lib/adodb/drivers/adodb-oci8po.inc.php
|
ADORecordset_oci8po._FetchField
|
function _FetchField($fieldOffset = -1)
{
$fld = new ADOFieldObject;
$fieldOffset += 1;
$fld->name = OCIcolumnname($this->_queryID, $fieldOffset);
if (ADODB_ASSOC_CASE == ADODB_ASSOC_CASE_LOWER) {
$fld->name = strtolower($fld->name);
}
$fld->type = OCIcolumntype($this->_queryID, $fieldOffset);
$fld->max_length = OCIcolumnsize($this->_queryID, $fieldOffset);
if ($fld->type == 'NUMBER') {
$sc = OCIColumnScale($this->_queryID, $fieldOffset);
if ($sc == 0) {
$fld->type = 'INT';
}
}
return $fld;
}
|
php
|
function _FetchField($fieldOffset = -1)
{
$fld = new ADOFieldObject;
$fieldOffset += 1;
$fld->name = OCIcolumnname($this->_queryID, $fieldOffset);
if (ADODB_ASSOC_CASE == ADODB_ASSOC_CASE_LOWER) {
$fld->name = strtolower($fld->name);
}
$fld->type = OCIcolumntype($this->_queryID, $fieldOffset);
$fld->max_length = OCIcolumnsize($this->_queryID, $fieldOffset);
if ($fld->type == 'NUMBER') {
$sc = OCIColumnScale($this->_queryID, $fieldOffset);
if ($sc == 0) {
$fld->type = 'INT';
}
}
return $fld;
}
|
[
"function",
"_FetchField",
"(",
"$",
"fieldOffset",
"=",
"-",
"1",
")",
"{",
"$",
"fld",
"=",
"new",
"ADOFieldObject",
";",
"$",
"fieldOffset",
"+=",
"1",
";",
"$",
"fld",
"->",
"name",
"=",
"OCIcolumnname",
"(",
"$",
"this",
"->",
"_queryID",
",",
"$",
"fieldOffset",
")",
";",
"if",
"(",
"ADODB_ASSOC_CASE",
"==",
"ADODB_ASSOC_CASE_LOWER",
")",
"{",
"$",
"fld",
"->",
"name",
"=",
"strtolower",
"(",
"$",
"fld",
"->",
"name",
")",
";",
"}",
"$",
"fld",
"->",
"type",
"=",
"OCIcolumntype",
"(",
"$",
"this",
"->",
"_queryID",
",",
"$",
"fieldOffset",
")",
";",
"$",
"fld",
"->",
"max_length",
"=",
"OCIcolumnsize",
"(",
"$",
"this",
"->",
"_queryID",
",",
"$",
"fieldOffset",
")",
";",
"if",
"(",
"$",
"fld",
"->",
"type",
"==",
"'NUMBER'",
")",
"{",
"$",
"sc",
"=",
"OCIColumnScale",
"(",
"$",
"this",
"->",
"_queryID",
",",
"$",
"fieldOffset",
")",
";",
"if",
"(",
"$",
"sc",
"==",
"0",
")",
"{",
"$",
"fld",
"->",
"type",
"=",
"'INT'",
";",
"}",
"}",
"return",
"$",
"fld",
";",
"}"
] |
lowercase field names...
|
[
"lowercase",
"field",
"names",
"..."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/drivers/adodb-oci8po.inc.php#L137-L154
|
220,119
|
moodle/moodle
|
search/classes/base.php
|
base.get_visible_name
|
public function get_visible_name($lazyload = false) {
$component = $this->componentname;
// Core subsystem strings go to lang/XX/search.php.
if ($this->componenttype === 'core') {
$component = 'search';
}
return get_string('search:' . $this->areaname, $component, null, $lazyload);
}
|
php
|
public function get_visible_name($lazyload = false) {
$component = $this->componentname;
// Core subsystem strings go to lang/XX/search.php.
if ($this->componenttype === 'core') {
$component = 'search';
}
return get_string('search:' . $this->areaname, $component, null, $lazyload);
}
|
[
"public",
"function",
"get_visible_name",
"(",
"$",
"lazyload",
"=",
"false",
")",
"{",
"$",
"component",
"=",
"$",
"this",
"->",
"componentname",
";",
"// Core subsystem strings go to lang/XX/search.php.",
"if",
"(",
"$",
"this",
"->",
"componenttype",
"===",
"'core'",
")",
"{",
"$",
"component",
"=",
"'search'",
";",
"}",
"return",
"get_string",
"(",
"'search:'",
".",
"$",
"this",
"->",
"areaname",
",",
"$",
"component",
",",
"null",
",",
"$",
"lazyload",
")",
";",
"}"
] |
Returns the area visible name.
@param bool $lazyload Usually false, unless when in admin settings.
@return string
|
[
"Returns",
"the",
"area",
"visible",
"name",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/base.php#L138-L147
|
220,120
|
moodle/moodle
|
search/classes/base.php
|
base.get_config_var_name
|
public function get_config_var_name() {
if ($this->componenttype === 'core') {
// Core subsystems config in core_search and setting name using only [a-zA-Z0-9_]+.
$parts = \core_search\manager::extract_areaid_parts($this->areaid);
return array('core_search', $parts[0] . '_' . $parts[1]);
}
// Plugins config in the plugin scope.
return array($this->componentname, 'search_' . $this->areaname);
}
|
php
|
public function get_config_var_name() {
if ($this->componenttype === 'core') {
// Core subsystems config in core_search and setting name using only [a-zA-Z0-9_]+.
$parts = \core_search\manager::extract_areaid_parts($this->areaid);
return array('core_search', $parts[0] . '_' . $parts[1]);
}
// Plugins config in the plugin scope.
return array($this->componentname, 'search_' . $this->areaname);
}
|
[
"public",
"function",
"get_config_var_name",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"componenttype",
"===",
"'core'",
")",
"{",
"// Core subsystems config in core_search and setting name using only [a-zA-Z0-9_]+.",
"$",
"parts",
"=",
"\\",
"core_search",
"\\",
"manager",
"::",
"extract_areaid_parts",
"(",
"$",
"this",
"->",
"areaid",
")",
";",
"return",
"array",
"(",
"'core_search'",
",",
"$",
"parts",
"[",
"0",
"]",
".",
"'_'",
".",
"$",
"parts",
"[",
"1",
"]",
")",
";",
"}",
"// Plugins config in the plugin scope.",
"return",
"array",
"(",
"$",
"this",
"->",
"componentname",
",",
"'search_'",
".",
"$",
"this",
"->",
"areaname",
")",
";",
"}"
] |
Returns the config var name.
It depends on whether it is a moodle subsystem or a plugin as plugin-related config should remain in their own scope.
@access private
@return string Config var path including the plugin (or component) and the varname
|
[
"Returns",
"the",
"config",
"var",
"name",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/base.php#L157-L167
|
220,121
|
moodle/moodle
|
search/classes/base.php
|
base.get_config
|
public function get_config() {
list($componentname, $varname) = $this->get_config_var_name();
$config = [];
$settingnames = self::get_settingnames();
foreach ($settingnames as $name) {
$config[$varname . $name] = get_config($componentname, $varname . $name);
}
// Search areas are enabled by default.
if ($config[$varname . '_enabled'] === false) {
$config[$varname . '_enabled'] = 1;
}
return $config;
}
|
php
|
public function get_config() {
list($componentname, $varname) = $this->get_config_var_name();
$config = [];
$settingnames = self::get_settingnames();
foreach ($settingnames as $name) {
$config[$varname . $name] = get_config($componentname, $varname . $name);
}
// Search areas are enabled by default.
if ($config[$varname . '_enabled'] === false) {
$config[$varname . '_enabled'] = 1;
}
return $config;
}
|
[
"public",
"function",
"get_config",
"(",
")",
"{",
"list",
"(",
"$",
"componentname",
",",
"$",
"varname",
")",
"=",
"$",
"this",
"->",
"get_config_var_name",
"(",
")",
";",
"$",
"config",
"=",
"[",
"]",
";",
"$",
"settingnames",
"=",
"self",
"::",
"get_settingnames",
"(",
")",
";",
"foreach",
"(",
"$",
"settingnames",
"as",
"$",
"name",
")",
"{",
"$",
"config",
"[",
"$",
"varname",
".",
"$",
"name",
"]",
"=",
"get_config",
"(",
"$",
"componentname",
",",
"$",
"varname",
".",
"$",
"name",
")",
";",
"}",
"// Search areas are enabled by default.",
"if",
"(",
"$",
"config",
"[",
"$",
"varname",
".",
"'_enabled'",
"]",
"===",
"false",
")",
"{",
"$",
"config",
"[",
"$",
"varname",
".",
"'_enabled'",
"]",
"=",
"1",
";",
"}",
"return",
"$",
"config",
";",
"}"
] |
Returns all the search area configuration.
@return array
|
[
"Returns",
"all",
"the",
"search",
"area",
"configuration",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/base.php#L174-L188
|
220,122
|
moodle/moodle
|
search/classes/base.php
|
base.is_enabled
|
public function is_enabled() {
list($componentname, $varname) = $this->get_config_var_name();
$value = get_config($componentname, $varname . '_enabled');
// Search areas are enabled by default.
if ($value === false) {
$value = 1;
}
return (bool)$value;
}
|
php
|
public function is_enabled() {
list($componentname, $varname) = $this->get_config_var_name();
$value = get_config($componentname, $varname . '_enabled');
// Search areas are enabled by default.
if ($value === false) {
$value = 1;
}
return (bool)$value;
}
|
[
"public",
"function",
"is_enabled",
"(",
")",
"{",
"list",
"(",
"$",
"componentname",
",",
"$",
"varname",
")",
"=",
"$",
"this",
"->",
"get_config_var_name",
"(",
")",
";",
"$",
"value",
"=",
"get_config",
"(",
"$",
"componentname",
",",
"$",
"varname",
".",
"'_enabled'",
")",
";",
"// Search areas are enabled by default.",
"if",
"(",
"$",
"value",
"===",
"false",
")",
"{",
"$",
"value",
"=",
"1",
";",
"}",
"return",
"(",
"bool",
")",
"$",
"value",
";",
"}"
] |
Is the search component enabled by the system administrator?
@return bool
|
[
"Is",
"the",
"search",
"component",
"enabled",
"by",
"the",
"system",
"administrator?"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/base.php#L205-L215
|
220,123
|
moodle/moodle
|
search/classes/base.php
|
base.get_recordset_by_timestamp
|
public function get_recordset_by_timestamp($modifiedfrom = 0) {
$result = $this->get_document_recordset($modifiedfrom);
if ($result === false) {
throw new \coding_exception(
'Search area must implement get_document_recordset or get_recordset_by_timestamp');
}
return $result;
}
|
php
|
public function get_recordset_by_timestamp($modifiedfrom = 0) {
$result = $this->get_document_recordset($modifiedfrom);
if ($result === false) {
throw new \coding_exception(
'Search area must implement get_document_recordset or get_recordset_by_timestamp');
}
return $result;
}
|
[
"public",
"function",
"get_recordset_by_timestamp",
"(",
"$",
"modifiedfrom",
"=",
"0",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"get_document_recordset",
"(",
"$",
"modifiedfrom",
")",
";",
"if",
"(",
"$",
"result",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Search area must implement get_document_recordset or get_recordset_by_timestamp'",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Returns a recordset ordered by modification date ASC.
Each record can include any data self::get_document might need but it must:
- Include an 'id' field: Unique identifier (in this area's scope) of a document to index in the search engine
If the indexed content field can contain embedded files, the 'id' value should match the filearea itemid.
- Only return data modified since $modifiedfrom, including $modifiedform to prevent
some records from not being indexed (e.g. your-timemodified-fieldname >= $modifiedfrom)
- Order the returned data by time modified in ascending order, as \core_search::manager will need to store the modified time
of the last indexed document.
Since Moodle 3.4, subclasses should instead implement get_document_recordset, which has
an additional context parameter. This function continues to work for implementations which
haven't been updated, or where the context parameter is not required.
@param int $modifiedfrom
@return \moodle_recordset
|
[
"Returns",
"a",
"recordset",
"ordered",
"by",
"modification",
"date",
"ASC",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/base.php#L265-L272
|
220,124
|
moodle/moodle
|
search/classes/base.php
|
base.get_course_level_context_restriction_sql
|
protected function get_course_level_context_restriction_sql(\context $context = null,
$coursetable, $paramtype = SQL_PARAMS_QM) {
global $DB;
if (!$context) {
return ['', []];
}
switch ($paramtype) {
case SQL_PARAMS_QM:
$param1 = '?';
$param2 = '?';
$key1 = 0;
$key2 = 1;
break;
case SQL_PARAMS_NAMED:
$param1 = ':gclcrs0';
$param2 = ':gclcrs1';
$key1 = 'gclcrs0';
$key2 = 'gclcrs1';
break;
default:
throw new \coding_exception('Unexpected $paramtype: ' . $paramtype);
}
$params = [];
switch ($context->contextlevel) {
case CONTEXT_SYSTEM:
$sql = '';
break;
case CONTEXT_COURSECAT:
// Find all courses within the specified category or any sub-category.
$pathmatch = $DB->sql_like('gclcrscc2.path',
$DB->sql_concat('gclcrscc1.path', $param2));
$sql = " JOIN {course_categories} gclcrscc1 ON gclcrscc1.id = $param1
JOIN {course_categories} gclcrscc2 ON gclcrscc2.id = $coursetable.category
AND (gclcrscc2.id = gclcrscc1.id OR $pathmatch) ";
$params[$key1] = $context->instanceid;
// Note: This param is a bit annoying as it obviously never changes, but sql_like
// throws a debug warning if you pass it anything with quotes in, so it has to be
// a bound parameter.
$params[$key2] = '/%';
break;
case CONTEXT_COURSE:
// We just join again against the same course entry and confirm that it has the
// same id as the context.
$sql = " JOIN {course} gclcrsc ON gclcrsc.id = $coursetable.id
AND gclcrsc.id = $param1";
$params[$key1] = $context->instanceid;
break;
case CONTEXT_BLOCK:
case CONTEXT_MODULE:
case CONTEXT_USER:
// Context cannot contain any courses.
return [null, null];
default:
throw new \coding_exception('Unexpected contextlevel: ' . $context->contextlevel);
}
return [$sql, $params];
}
|
php
|
protected function get_course_level_context_restriction_sql(\context $context = null,
$coursetable, $paramtype = SQL_PARAMS_QM) {
global $DB;
if (!$context) {
return ['', []];
}
switch ($paramtype) {
case SQL_PARAMS_QM:
$param1 = '?';
$param2 = '?';
$key1 = 0;
$key2 = 1;
break;
case SQL_PARAMS_NAMED:
$param1 = ':gclcrs0';
$param2 = ':gclcrs1';
$key1 = 'gclcrs0';
$key2 = 'gclcrs1';
break;
default:
throw new \coding_exception('Unexpected $paramtype: ' . $paramtype);
}
$params = [];
switch ($context->contextlevel) {
case CONTEXT_SYSTEM:
$sql = '';
break;
case CONTEXT_COURSECAT:
// Find all courses within the specified category or any sub-category.
$pathmatch = $DB->sql_like('gclcrscc2.path',
$DB->sql_concat('gclcrscc1.path', $param2));
$sql = " JOIN {course_categories} gclcrscc1 ON gclcrscc1.id = $param1
JOIN {course_categories} gclcrscc2 ON gclcrscc2.id = $coursetable.category
AND (gclcrscc2.id = gclcrscc1.id OR $pathmatch) ";
$params[$key1] = $context->instanceid;
// Note: This param is a bit annoying as it obviously never changes, but sql_like
// throws a debug warning if you pass it anything with quotes in, so it has to be
// a bound parameter.
$params[$key2] = '/%';
break;
case CONTEXT_COURSE:
// We just join again against the same course entry and confirm that it has the
// same id as the context.
$sql = " JOIN {course} gclcrsc ON gclcrsc.id = $coursetable.id
AND gclcrsc.id = $param1";
$params[$key1] = $context->instanceid;
break;
case CONTEXT_BLOCK:
case CONTEXT_MODULE:
case CONTEXT_USER:
// Context cannot contain any courses.
return [null, null];
default:
throw new \coding_exception('Unexpected contextlevel: ' . $context->contextlevel);
}
return [$sql, $params];
}
|
[
"protected",
"function",
"get_course_level_context_restriction_sql",
"(",
"\\",
"context",
"$",
"context",
"=",
"null",
",",
"$",
"coursetable",
",",
"$",
"paramtype",
"=",
"SQL_PARAMS_QM",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"!",
"$",
"context",
")",
"{",
"return",
"[",
"''",
",",
"[",
"]",
"]",
";",
"}",
"switch",
"(",
"$",
"paramtype",
")",
"{",
"case",
"SQL_PARAMS_QM",
":",
"$",
"param1",
"=",
"'?'",
";",
"$",
"param2",
"=",
"'?'",
";",
"$",
"key1",
"=",
"0",
";",
"$",
"key2",
"=",
"1",
";",
"break",
";",
"case",
"SQL_PARAMS_NAMED",
":",
"$",
"param1",
"=",
"':gclcrs0'",
";",
"$",
"param2",
"=",
"':gclcrs1'",
";",
"$",
"key1",
"=",
"'gclcrs0'",
";",
"$",
"key2",
"=",
"'gclcrs1'",
";",
"break",
";",
"default",
":",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Unexpected $paramtype: '",
".",
"$",
"paramtype",
")",
";",
"}",
"$",
"params",
"=",
"[",
"]",
";",
"switch",
"(",
"$",
"context",
"->",
"contextlevel",
")",
"{",
"case",
"CONTEXT_SYSTEM",
":",
"$",
"sql",
"=",
"''",
";",
"break",
";",
"case",
"CONTEXT_COURSECAT",
":",
"// Find all courses within the specified category or any sub-category.",
"$",
"pathmatch",
"=",
"$",
"DB",
"->",
"sql_like",
"(",
"'gclcrscc2.path'",
",",
"$",
"DB",
"->",
"sql_concat",
"(",
"'gclcrscc1.path'",
",",
"$",
"param2",
")",
")",
";",
"$",
"sql",
"=",
"\" JOIN {course_categories} gclcrscc1 ON gclcrscc1.id = $param1\n JOIN {course_categories} gclcrscc2 ON gclcrscc2.id = $coursetable.category\n AND (gclcrscc2.id = gclcrscc1.id OR $pathmatch) \"",
";",
"$",
"params",
"[",
"$",
"key1",
"]",
"=",
"$",
"context",
"->",
"instanceid",
";",
"// Note: This param is a bit annoying as it obviously never changes, but sql_like",
"// throws a debug warning if you pass it anything with quotes in, so it has to be",
"// a bound parameter.",
"$",
"params",
"[",
"$",
"key2",
"]",
"=",
"'/%'",
";",
"break",
";",
"case",
"CONTEXT_COURSE",
":",
"// We just join again against the same course entry and confirm that it has the",
"// same id as the context.",
"$",
"sql",
"=",
"\" JOIN {course} gclcrsc ON gclcrsc.id = $coursetable.id\n AND gclcrsc.id = $param1\"",
";",
"$",
"params",
"[",
"$",
"key1",
"]",
"=",
"$",
"context",
"->",
"instanceid",
";",
"break",
";",
"case",
"CONTEXT_BLOCK",
":",
"case",
"CONTEXT_MODULE",
":",
"case",
"CONTEXT_USER",
":",
"// Context cannot contain any courses.",
"return",
"[",
"null",
",",
"null",
"]",
";",
"default",
":",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Unexpected contextlevel: '",
".",
"$",
"context",
"->",
"contextlevel",
")",
";",
"}",
"return",
"[",
"$",
"sql",
",",
"$",
"params",
"]",
";",
"}"
] |
Helper function that gets SQL useful for restricting a search query given a passed-in
context, for data stored at course level.
The SQL returned will be zero or more JOIN statements, surrounded by whitespace, which act
as restrictions on the query based on the rows in a module table.
You can pass in a null or system context, which will both return an empty string and no
params.
Returns an array with two nulls if there can be no results for a course within this context.
If named parameters are used, these will be named gclcrs0, gclcrs1, etc. The table aliases
used in SQL also all begin with gclcrs, to avoid conflicts.
@param \context|null $context Context to restrict the query
@param string $coursetable Name of alias for course table e.g. 'c'
@param int $paramtype Type of SQL parameters to use (default question mark)
@return array Array with SQL and parameters; both null if no need to query
@throws \coding_exception If called with invalid params
|
[
"Helper",
"function",
"that",
"gets",
"SQL",
"useful",
"for",
"restricting",
"a",
"search",
"query",
"given",
"a",
"passed",
"-",
"in",
"context",
"for",
"data",
"stored",
"at",
"course",
"level",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/base.php#L455-L519
|
220,125
|
moodle/moodle
|
question/classes/privacy/provider.php
|
provider.export_question_usage
|
public static function export_question_usage(
int $userid,
\context $context,
array $usagecontext,
int $usage,
\question_display_options $options,
bool $isowner
) {
// Determine the questions in this usage.
$quba = \question_engine::load_questions_usage_by_activity($usage);
$basepath = $usagecontext;
$questionscontext = array_merge($usagecontext, [
get_string('questions', 'core_question'),
]);
foreach ($quba->get_attempt_iterator() as $qa) {
$question = $qa->get_question();
$slotno = $qa->get_slot();
$questionnocontext = array_merge($questionscontext, [$slotno]);
if ($isowner) {
// This user is the overal owner of the question attempt and all data wil therefore be exported.
//
// Respect _some_ of the question_display_options to ensure that they don't have access to
// generalfeedback and mark if the display options prevent this.
// This is defensible because they can submit questions without completing a quiz and perform an SAR to
// get prior access to the feedback and mark to improve upon it.
// Export the response.
$data = (object) [
'name' => $question->name,
'question' => $qa->get_question_summary(),
'answer' => $qa->get_response_summary(),
'timemodified' => transform::datetime($qa->timemodified),
];
if ($options->marks >= \question_display_options::MARK_AND_MAX) {
$data->mark = $qa->format_mark($options->markdp);
}
if ($options->flags != \question_display_options::HIDDEN) {
$data->flagged = transform::yesno($qa->is_flagged());
}
if ($options->generalfeedback != \question_display_options::HIDDEN) {
$data->generalfeedback = $question->format_generalfeedback($qa);
}
if ($options->manualcomment != \question_display_options::HIDDEN) {
$behaviour = $qa->get_behaviour();
if ($qa->has_manual_comment()) {
// Note - the export of the step data will ensure that the files are exported.
// No need to do it again here.
list($comment, $commentformat, $step) = $qa->get_manual_comment();
$comment = writer::with_context($context)
->rewrite_pluginfile_urls(
$questionnocontext,
'question',
'response_bf_comment',
$step->get_id(),
$comment
);
$data->comment = $behaviour->format_comment($comment, $commentformat);
}
}
writer::with_context($context)
->export_data($questionnocontext, $data);
// Export the step data.
static::export_question_attempt_steps($userid, $context, $questionnocontext, $qa, $options, $isowner);
}
}
}
|
php
|
public static function export_question_usage(
int $userid,
\context $context,
array $usagecontext,
int $usage,
\question_display_options $options,
bool $isowner
) {
// Determine the questions in this usage.
$quba = \question_engine::load_questions_usage_by_activity($usage);
$basepath = $usagecontext;
$questionscontext = array_merge($usagecontext, [
get_string('questions', 'core_question'),
]);
foreach ($quba->get_attempt_iterator() as $qa) {
$question = $qa->get_question();
$slotno = $qa->get_slot();
$questionnocontext = array_merge($questionscontext, [$slotno]);
if ($isowner) {
// This user is the overal owner of the question attempt and all data wil therefore be exported.
//
// Respect _some_ of the question_display_options to ensure that they don't have access to
// generalfeedback and mark if the display options prevent this.
// This is defensible because they can submit questions without completing a quiz and perform an SAR to
// get prior access to the feedback and mark to improve upon it.
// Export the response.
$data = (object) [
'name' => $question->name,
'question' => $qa->get_question_summary(),
'answer' => $qa->get_response_summary(),
'timemodified' => transform::datetime($qa->timemodified),
];
if ($options->marks >= \question_display_options::MARK_AND_MAX) {
$data->mark = $qa->format_mark($options->markdp);
}
if ($options->flags != \question_display_options::HIDDEN) {
$data->flagged = transform::yesno($qa->is_flagged());
}
if ($options->generalfeedback != \question_display_options::HIDDEN) {
$data->generalfeedback = $question->format_generalfeedback($qa);
}
if ($options->manualcomment != \question_display_options::HIDDEN) {
$behaviour = $qa->get_behaviour();
if ($qa->has_manual_comment()) {
// Note - the export of the step data will ensure that the files are exported.
// No need to do it again here.
list($comment, $commentformat, $step) = $qa->get_manual_comment();
$comment = writer::with_context($context)
->rewrite_pluginfile_urls(
$questionnocontext,
'question',
'response_bf_comment',
$step->get_id(),
$comment
);
$data->comment = $behaviour->format_comment($comment, $commentformat);
}
}
writer::with_context($context)
->export_data($questionnocontext, $data);
// Export the step data.
static::export_question_attempt_steps($userid, $context, $questionnocontext, $qa, $options, $isowner);
}
}
}
|
[
"public",
"static",
"function",
"export_question_usage",
"(",
"int",
"$",
"userid",
",",
"\\",
"context",
"$",
"context",
",",
"array",
"$",
"usagecontext",
",",
"int",
"$",
"usage",
",",
"\\",
"question_display_options",
"$",
"options",
",",
"bool",
"$",
"isowner",
")",
"{",
"// Determine the questions in this usage.",
"$",
"quba",
"=",
"\\",
"question_engine",
"::",
"load_questions_usage_by_activity",
"(",
"$",
"usage",
")",
";",
"$",
"basepath",
"=",
"$",
"usagecontext",
";",
"$",
"questionscontext",
"=",
"array_merge",
"(",
"$",
"usagecontext",
",",
"[",
"get_string",
"(",
"'questions'",
",",
"'core_question'",
")",
",",
"]",
")",
";",
"foreach",
"(",
"$",
"quba",
"->",
"get_attempt_iterator",
"(",
")",
"as",
"$",
"qa",
")",
"{",
"$",
"question",
"=",
"$",
"qa",
"->",
"get_question",
"(",
")",
";",
"$",
"slotno",
"=",
"$",
"qa",
"->",
"get_slot",
"(",
")",
";",
"$",
"questionnocontext",
"=",
"array_merge",
"(",
"$",
"questionscontext",
",",
"[",
"$",
"slotno",
"]",
")",
";",
"if",
"(",
"$",
"isowner",
")",
"{",
"// This user is the overal owner of the question attempt and all data wil therefore be exported.",
"//",
"// Respect _some_ of the question_display_options to ensure that they don't have access to",
"// generalfeedback and mark if the display options prevent this.",
"// This is defensible because they can submit questions without completing a quiz and perform an SAR to",
"// get prior access to the feedback and mark to improve upon it.",
"// Export the response.",
"$",
"data",
"=",
"(",
"object",
")",
"[",
"'name'",
"=>",
"$",
"question",
"->",
"name",
",",
"'question'",
"=>",
"$",
"qa",
"->",
"get_question_summary",
"(",
")",
",",
"'answer'",
"=>",
"$",
"qa",
"->",
"get_response_summary",
"(",
")",
",",
"'timemodified'",
"=>",
"transform",
"::",
"datetime",
"(",
"$",
"qa",
"->",
"timemodified",
")",
",",
"]",
";",
"if",
"(",
"$",
"options",
"->",
"marks",
">=",
"\\",
"question_display_options",
"::",
"MARK_AND_MAX",
")",
"{",
"$",
"data",
"->",
"mark",
"=",
"$",
"qa",
"->",
"format_mark",
"(",
"$",
"options",
"->",
"markdp",
")",
";",
"}",
"if",
"(",
"$",
"options",
"->",
"flags",
"!=",
"\\",
"question_display_options",
"::",
"HIDDEN",
")",
"{",
"$",
"data",
"->",
"flagged",
"=",
"transform",
"::",
"yesno",
"(",
"$",
"qa",
"->",
"is_flagged",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"options",
"->",
"generalfeedback",
"!=",
"\\",
"question_display_options",
"::",
"HIDDEN",
")",
"{",
"$",
"data",
"->",
"generalfeedback",
"=",
"$",
"question",
"->",
"format_generalfeedback",
"(",
"$",
"qa",
")",
";",
"}",
"if",
"(",
"$",
"options",
"->",
"manualcomment",
"!=",
"\\",
"question_display_options",
"::",
"HIDDEN",
")",
"{",
"$",
"behaviour",
"=",
"$",
"qa",
"->",
"get_behaviour",
"(",
")",
";",
"if",
"(",
"$",
"qa",
"->",
"has_manual_comment",
"(",
")",
")",
"{",
"// Note - the export of the step data will ensure that the files are exported.",
"// No need to do it again here.",
"list",
"(",
"$",
"comment",
",",
"$",
"commentformat",
",",
"$",
"step",
")",
"=",
"$",
"qa",
"->",
"get_manual_comment",
"(",
")",
";",
"$",
"comment",
"=",
"writer",
"::",
"with_context",
"(",
"$",
"context",
")",
"->",
"rewrite_pluginfile_urls",
"(",
"$",
"questionnocontext",
",",
"'question'",
",",
"'response_bf_comment'",
",",
"$",
"step",
"->",
"get_id",
"(",
")",
",",
"$",
"comment",
")",
";",
"$",
"data",
"->",
"comment",
"=",
"$",
"behaviour",
"->",
"format_comment",
"(",
"$",
"comment",
",",
"$",
"commentformat",
")",
";",
"}",
"}",
"writer",
"::",
"with_context",
"(",
"$",
"context",
")",
"->",
"export_data",
"(",
"$",
"questionnocontext",
",",
"$",
"data",
")",
";",
"// Export the step data.",
"static",
"::",
"export_question_attempt_steps",
"(",
"$",
"userid",
",",
"$",
"context",
",",
"$",
"questionnocontext",
",",
"$",
"qa",
",",
"$",
"options",
",",
"$",
"isowner",
")",
";",
"}",
"}",
"}"
] |
Export the data for all question attempts on this question usage.
Where a user is the owner of the usage, then the full detail of that usage will be included.
Where a user has been involved in the usage, but it is not their own usage, then only their specific
involvement will be exported.
@param int $userid The userid to export.
@param \context $context The context that the question was used within.
@param array $usagecontext The subcontext of this usage.
@param int $usage The question usage ID.
@param \question_display_options $options The display options used for formatting.
@param bool $isowner Whether the user being exported is the user who used the question.
|
[
"Export",
"the",
"data",
"for",
"all",
"question",
"attempts",
"on",
"this",
"question",
"usage",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/privacy/provider.php#L151-L225
|
220,126
|
moodle/moodle
|
question/classes/privacy/provider.php
|
provider.export_question_attempt_steps
|
public static function export_question_attempt_steps(
int $userid,
\context $context,
array $questionnocontext,
\question_attempt $qa,
\question_display_options $options,
$isowner
) {
$attemptdata = (object) [
'steps' => [],
];
$stepno = 0;
foreach ($qa->get_step_iterator() as $i => $step) {
$stepno++;
if ($isowner || ($step->get_user_id() != $userid)) {
// The user is the owner, or the author of the step.
$restrictedqa = new \question_attempt_with_restricted_history($qa, $i, null);
$stepdata = (object) [
// Note: Do not include the user here.
'time' => transform::datetime($step->get_timecreated()),
'action' => $qa->summarise_action($step),
];
if ($options->marks >= \question_display_options::MARK_AND_MAX) {
$stepdata->mark = $qa->format_fraction_as_mark($step->get_fraction(), $options->markdp);
}
if ($options->correctness != \question_display_options::HIDDEN) {
$stepdata->state = $restrictedqa->get_state_string($options->correctness);
}
if ($step->has_behaviour_var('comment')) {
$behaviour = $qa->get_behaviour();
$comment = $step->get_behaviour_var('comment');
$commentformat = $step->get_behaviour_var('commentformat');
if (empty(trim($comment))) {
// Skip empty comments.
continue;
}
// Format the comment.
$comment = writer::with_context($context)
->rewrite_pluginfile_urls(
$questionnocontext,
'question',
'response_bf_comment',
$step->get_id(),
$comment
);
// Export any files associated with the comment files area.
writer::with_context($context)
->export_area_files(
$questionnocontext,
'question',
"response_bf_comment",
$step->get_id()
);
$stepdata->comment = $behaviour->format_comment($comment, $commentformat);
}
// Export any response files associated with this step.
foreach (\question_engine::get_all_response_file_areas() as $filearea) {
writer::with_context($context)
->export_area_files(
$questionnocontext,
'question',
$filearea,
$step->get_id()
);
}
$attemptdata->steps[$stepno] = $stepdata;
}
}
if (!empty($attemptdata->steps)) {
writer::with_context($context)
->export_related_data($questionnocontext, 'steps', $attemptdata);
}
}
|
php
|
public static function export_question_attempt_steps(
int $userid,
\context $context,
array $questionnocontext,
\question_attempt $qa,
\question_display_options $options,
$isowner
) {
$attemptdata = (object) [
'steps' => [],
];
$stepno = 0;
foreach ($qa->get_step_iterator() as $i => $step) {
$stepno++;
if ($isowner || ($step->get_user_id() != $userid)) {
// The user is the owner, or the author of the step.
$restrictedqa = new \question_attempt_with_restricted_history($qa, $i, null);
$stepdata = (object) [
// Note: Do not include the user here.
'time' => transform::datetime($step->get_timecreated()),
'action' => $qa->summarise_action($step),
];
if ($options->marks >= \question_display_options::MARK_AND_MAX) {
$stepdata->mark = $qa->format_fraction_as_mark($step->get_fraction(), $options->markdp);
}
if ($options->correctness != \question_display_options::HIDDEN) {
$stepdata->state = $restrictedqa->get_state_string($options->correctness);
}
if ($step->has_behaviour_var('comment')) {
$behaviour = $qa->get_behaviour();
$comment = $step->get_behaviour_var('comment');
$commentformat = $step->get_behaviour_var('commentformat');
if (empty(trim($comment))) {
// Skip empty comments.
continue;
}
// Format the comment.
$comment = writer::with_context($context)
->rewrite_pluginfile_urls(
$questionnocontext,
'question',
'response_bf_comment',
$step->get_id(),
$comment
);
// Export any files associated with the comment files area.
writer::with_context($context)
->export_area_files(
$questionnocontext,
'question',
"response_bf_comment",
$step->get_id()
);
$stepdata->comment = $behaviour->format_comment($comment, $commentformat);
}
// Export any response files associated with this step.
foreach (\question_engine::get_all_response_file_areas() as $filearea) {
writer::with_context($context)
->export_area_files(
$questionnocontext,
'question',
$filearea,
$step->get_id()
);
}
$attemptdata->steps[$stepno] = $stepdata;
}
}
if (!empty($attemptdata->steps)) {
writer::with_context($context)
->export_related_data($questionnocontext, 'steps', $attemptdata);
}
}
|
[
"public",
"static",
"function",
"export_question_attempt_steps",
"(",
"int",
"$",
"userid",
",",
"\\",
"context",
"$",
"context",
",",
"array",
"$",
"questionnocontext",
",",
"\\",
"question_attempt",
"$",
"qa",
",",
"\\",
"question_display_options",
"$",
"options",
",",
"$",
"isowner",
")",
"{",
"$",
"attemptdata",
"=",
"(",
"object",
")",
"[",
"'steps'",
"=>",
"[",
"]",
",",
"]",
";",
"$",
"stepno",
"=",
"0",
";",
"foreach",
"(",
"$",
"qa",
"->",
"get_step_iterator",
"(",
")",
"as",
"$",
"i",
"=>",
"$",
"step",
")",
"{",
"$",
"stepno",
"++",
";",
"if",
"(",
"$",
"isowner",
"||",
"(",
"$",
"step",
"->",
"get_user_id",
"(",
")",
"!=",
"$",
"userid",
")",
")",
"{",
"// The user is the owner, or the author of the step.",
"$",
"restrictedqa",
"=",
"new",
"\\",
"question_attempt_with_restricted_history",
"(",
"$",
"qa",
",",
"$",
"i",
",",
"null",
")",
";",
"$",
"stepdata",
"=",
"(",
"object",
")",
"[",
"// Note: Do not include the user here.",
"'time'",
"=>",
"transform",
"::",
"datetime",
"(",
"$",
"step",
"->",
"get_timecreated",
"(",
")",
")",
",",
"'action'",
"=>",
"$",
"qa",
"->",
"summarise_action",
"(",
"$",
"step",
")",
",",
"]",
";",
"if",
"(",
"$",
"options",
"->",
"marks",
">=",
"\\",
"question_display_options",
"::",
"MARK_AND_MAX",
")",
"{",
"$",
"stepdata",
"->",
"mark",
"=",
"$",
"qa",
"->",
"format_fraction_as_mark",
"(",
"$",
"step",
"->",
"get_fraction",
"(",
")",
",",
"$",
"options",
"->",
"markdp",
")",
";",
"}",
"if",
"(",
"$",
"options",
"->",
"correctness",
"!=",
"\\",
"question_display_options",
"::",
"HIDDEN",
")",
"{",
"$",
"stepdata",
"->",
"state",
"=",
"$",
"restrictedqa",
"->",
"get_state_string",
"(",
"$",
"options",
"->",
"correctness",
")",
";",
"}",
"if",
"(",
"$",
"step",
"->",
"has_behaviour_var",
"(",
"'comment'",
")",
")",
"{",
"$",
"behaviour",
"=",
"$",
"qa",
"->",
"get_behaviour",
"(",
")",
";",
"$",
"comment",
"=",
"$",
"step",
"->",
"get_behaviour_var",
"(",
"'comment'",
")",
";",
"$",
"commentformat",
"=",
"$",
"step",
"->",
"get_behaviour_var",
"(",
"'commentformat'",
")",
";",
"if",
"(",
"empty",
"(",
"trim",
"(",
"$",
"comment",
")",
")",
")",
"{",
"// Skip empty comments.",
"continue",
";",
"}",
"// Format the comment.",
"$",
"comment",
"=",
"writer",
"::",
"with_context",
"(",
"$",
"context",
")",
"->",
"rewrite_pluginfile_urls",
"(",
"$",
"questionnocontext",
",",
"'question'",
",",
"'response_bf_comment'",
",",
"$",
"step",
"->",
"get_id",
"(",
")",
",",
"$",
"comment",
")",
";",
"// Export any files associated with the comment files area.",
"writer",
"::",
"with_context",
"(",
"$",
"context",
")",
"->",
"export_area_files",
"(",
"$",
"questionnocontext",
",",
"'question'",
",",
"\"response_bf_comment\"",
",",
"$",
"step",
"->",
"get_id",
"(",
")",
")",
";",
"$",
"stepdata",
"->",
"comment",
"=",
"$",
"behaviour",
"->",
"format_comment",
"(",
"$",
"comment",
",",
"$",
"commentformat",
")",
";",
"}",
"// Export any response files associated with this step.",
"foreach",
"(",
"\\",
"question_engine",
"::",
"get_all_response_file_areas",
"(",
")",
"as",
"$",
"filearea",
")",
"{",
"writer",
"::",
"with_context",
"(",
"$",
"context",
")",
"->",
"export_area_files",
"(",
"$",
"questionnocontext",
",",
"'question'",
",",
"$",
"filearea",
",",
"$",
"step",
"->",
"get_id",
"(",
")",
")",
";",
"}",
"$",
"attemptdata",
"->",
"steps",
"[",
"$",
"stepno",
"]",
"=",
"$",
"stepdata",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"attemptdata",
"->",
"steps",
")",
")",
"{",
"writer",
"::",
"with_context",
"(",
"$",
"context",
")",
"->",
"export_related_data",
"(",
"$",
"questionnocontext",
",",
"'steps'",
",",
"$",
"attemptdata",
")",
";",
"}",
"}"
] |
Export the data for each step transition for each question in each question attempt.
Where a user is the owner of the usage, then all steps in the question usage will be exported.
Where a user is not the owner, but has been involved in the usage, then only their specific
involvement will be exported.
@param int $userid The user to export for
@param \context $context The context that the question was used within.
@param array $questionnocontext The subcontext of this question number.
@param \question_attempt $qa The attempt being checked
@param \question_display_options $options The display options used for formatting.
@param bool $isowner Whether the user being exported is the user who used the question.
|
[
"Export",
"the",
"data",
"for",
"each",
"step",
"transition",
"for",
"each",
"question",
"in",
"each",
"question",
"attempt",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/privacy/provider.php#L241-L325
|
220,127
|
moodle/moodle
|
question/classes/privacy/provider.php
|
provider.get_related_question_usages_for_user
|
public static function get_related_question_usages_for_user(string $prefix, string $component, string $joinfield, int $userid) : \qubaid_join {
return new \qubaid_join("
JOIN {question_usages} {$prefix}_qu ON {$prefix}_qu.id = {$joinfield}
AND {$prefix}_qu.component = :{$prefix}_usagecomponent
JOIN {question_attempts} {$prefix}_qa ON {$prefix}_qa.questionusageid = {$prefix}_qu.id
JOIN {question_attempt_steps} {$prefix}_qas ON {$prefix}_qas.questionattemptid = {$prefix}_qa.id",
"{$prefix}_qu.id",
"{$prefix}_qas.userid = :{$prefix}_stepuserid",
[
"{$prefix}_stepuserid" => $userid,
"{$prefix}_usagecomponent" => $component,
]);
}
|
php
|
public static function get_related_question_usages_for_user(string $prefix, string $component, string $joinfield, int $userid) : \qubaid_join {
return new \qubaid_join("
JOIN {question_usages} {$prefix}_qu ON {$prefix}_qu.id = {$joinfield}
AND {$prefix}_qu.component = :{$prefix}_usagecomponent
JOIN {question_attempts} {$prefix}_qa ON {$prefix}_qa.questionusageid = {$prefix}_qu.id
JOIN {question_attempt_steps} {$prefix}_qas ON {$prefix}_qas.questionattemptid = {$prefix}_qa.id",
"{$prefix}_qu.id",
"{$prefix}_qas.userid = :{$prefix}_stepuserid",
[
"{$prefix}_stepuserid" => $userid,
"{$prefix}_usagecomponent" => $component,
]);
}
|
[
"public",
"static",
"function",
"get_related_question_usages_for_user",
"(",
"string",
"$",
"prefix",
",",
"string",
"$",
"component",
",",
"string",
"$",
"joinfield",
",",
"int",
"$",
"userid",
")",
":",
"\\",
"qubaid_join",
"{",
"return",
"new",
"\\",
"qubaid_join",
"(",
"\"\n JOIN {question_usages} {$prefix}_qu ON {$prefix}_qu.id = {$joinfield}\n AND {$prefix}_qu.component = :{$prefix}_usagecomponent\n JOIN {question_attempts} {$prefix}_qa ON {$prefix}_qa.questionusageid = {$prefix}_qu.id\n JOIN {question_attempt_steps} {$prefix}_qas ON {$prefix}_qas.questionattemptid = {$prefix}_qa.id\"",
",",
"\"{$prefix}_qu.id\"",
",",
"\"{$prefix}_qas.userid = :{$prefix}_stepuserid\"",
",",
"[",
"\"{$prefix}_stepuserid\"",
"=>",
"$",
"userid",
",",
"\"{$prefix}_usagecomponent\"",
"=>",
"$",
"component",
",",
"]",
")",
";",
"}"
] |
Determine related question usages for a user.
@param string $prefix A unique prefix to add to the table alias
@param string $component The name of the component to fetch usages for.
@param string $joinfield The SQL field name to use in the JOIN ON - e.g. q.usageid
@param int $userid The user to search.
@return \qubaid_join
|
[
"Determine",
"related",
"question",
"usages",
"for",
"a",
"user",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/privacy/provider.php#L389-L401
|
220,128
|
moodle/moodle
|
lib/adodb/adodb-datadict.inc.php
|
ADODB_DataDict.ExecuteSQLArray
|
function ExecuteSQLArray($sql, $continueOnError = true)
{
$rez = 2;
$conn = $this->connection;
$saved = $conn->debug;
foreach($sql as $line) {
if ($this->debug) $conn->debug = true;
$ok = $conn->Execute($line);
$conn->debug = $saved;
if (!$ok) {
if ($this->debug) ADOConnection::outp($conn->ErrorMsg());
if (!$continueOnError) return 0;
$rez = 1;
}
}
return $rez;
}
|
php
|
function ExecuteSQLArray($sql, $continueOnError = true)
{
$rez = 2;
$conn = $this->connection;
$saved = $conn->debug;
foreach($sql as $line) {
if ($this->debug) $conn->debug = true;
$ok = $conn->Execute($line);
$conn->debug = $saved;
if (!$ok) {
if ($this->debug) ADOConnection::outp($conn->ErrorMsg());
if (!$continueOnError) return 0;
$rez = 1;
}
}
return $rez;
}
|
[
"function",
"ExecuteSQLArray",
"(",
"$",
"sql",
",",
"$",
"continueOnError",
"=",
"true",
")",
"{",
"$",
"rez",
"=",
"2",
";",
"$",
"conn",
"=",
"$",
"this",
"->",
"connection",
";",
"$",
"saved",
"=",
"$",
"conn",
"->",
"debug",
";",
"foreach",
"(",
"$",
"sql",
"as",
"$",
"line",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"debug",
")",
"$",
"conn",
"->",
"debug",
"=",
"true",
";",
"$",
"ok",
"=",
"$",
"conn",
"->",
"Execute",
"(",
"$",
"line",
")",
";",
"$",
"conn",
"->",
"debug",
"=",
"$",
"saved",
";",
"if",
"(",
"!",
"$",
"ok",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"debug",
")",
"ADOConnection",
"::",
"outp",
"(",
"$",
"conn",
"->",
"ErrorMsg",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"continueOnError",
")",
"return",
"0",
";",
"$",
"rez",
"=",
"1",
";",
"}",
"}",
"return",
"$",
"rez",
";",
"}"
] |
Executes the sql array returned by GetTableSQL and GetIndexSQL
|
[
"Executes",
"the",
"sql",
"array",
"returned",
"by",
"GetTableSQL",
"and",
"GetIndexSQL"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-datadict.inc.php#L372-L389
|
220,129
|
moodle/moodle
|
lib/adodb/adodb-datadict.inc.php
|
ADODB_DataDict.AlterColumnSQL
|
function AlterColumnSQL($tabname, $flds, $tableflds='',$tableoptions='')
{
$tabname = $this->TableName ($tabname);
$sql = array();
list($lines,$pkey,$idxs) = $this->_GenFields($flds);
// genfields can return FALSE at times
if ($lines == null) $lines = array();
$alter = 'ALTER TABLE ' . $tabname . $this->alterCol . ' ';
foreach($lines as $v) {
$sql[] = $alter . $v;
}
if (is_array($idxs)) {
foreach($idxs as $idx => $idxdef) {
$sql_idxs = $this->CreateIndexSql($idx, $tabname, $idxdef['cols'], $idxdef['opts']);
$sql = array_merge($sql, $sql_idxs);
}
}
return $sql;
}
|
php
|
function AlterColumnSQL($tabname, $flds, $tableflds='',$tableoptions='')
{
$tabname = $this->TableName ($tabname);
$sql = array();
list($lines,$pkey,$idxs) = $this->_GenFields($flds);
// genfields can return FALSE at times
if ($lines == null) $lines = array();
$alter = 'ALTER TABLE ' . $tabname . $this->alterCol . ' ';
foreach($lines as $v) {
$sql[] = $alter . $v;
}
if (is_array($idxs)) {
foreach($idxs as $idx => $idxdef) {
$sql_idxs = $this->CreateIndexSql($idx, $tabname, $idxdef['cols'], $idxdef['opts']);
$sql = array_merge($sql, $sql_idxs);
}
}
return $sql;
}
|
[
"function",
"AlterColumnSQL",
"(",
"$",
"tabname",
",",
"$",
"flds",
",",
"$",
"tableflds",
"=",
"''",
",",
"$",
"tableoptions",
"=",
"''",
")",
"{",
"$",
"tabname",
"=",
"$",
"this",
"->",
"TableName",
"(",
"$",
"tabname",
")",
";",
"$",
"sql",
"=",
"array",
"(",
")",
";",
"list",
"(",
"$",
"lines",
",",
"$",
"pkey",
",",
"$",
"idxs",
")",
"=",
"$",
"this",
"->",
"_GenFields",
"(",
"$",
"flds",
")",
";",
"// genfields can return FALSE at times",
"if",
"(",
"$",
"lines",
"==",
"null",
")",
"$",
"lines",
"=",
"array",
"(",
")",
";",
"$",
"alter",
"=",
"'ALTER TABLE '",
".",
"$",
"tabname",
".",
"$",
"this",
"->",
"alterCol",
".",
"' '",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"v",
")",
"{",
"$",
"sql",
"[",
"]",
"=",
"$",
"alter",
".",
"$",
"v",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"idxs",
")",
")",
"{",
"foreach",
"(",
"$",
"idxs",
"as",
"$",
"idx",
"=>",
"$",
"idxdef",
")",
"{",
"$",
"sql_idxs",
"=",
"$",
"this",
"->",
"CreateIndexSql",
"(",
"$",
"idx",
",",
"$",
"tabname",
",",
"$",
"idxdef",
"[",
"'cols'",
"]",
",",
"$",
"idxdef",
"[",
"'opts'",
"]",
")",
";",
"$",
"sql",
"=",
"array_merge",
"(",
"$",
"sql",
",",
"$",
"sql_idxs",
")",
";",
"}",
"}",
"return",
"$",
"sql",
";",
"}"
] |
Change the definition of one column
As some DBM's can't do that on there own, you need to supply the complete defintion of the new table,
to allow, recreating the table and copying the content over to the new table
@param string $tabname table-name
@param string $flds column-name and type for the changed column
@param string $tableflds='' complete defintion of the new table, eg. for postgres, default ''
@param array/string $tableoptions='' options for the new table see CreateTableSQL, default ''
@return array with SQL strings
|
[
"Change",
"the",
"definition",
"of",
"one",
"column"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-datadict.inc.php#L485-L504
|
220,130
|
moodle/moodle
|
lib/adodb/adodb-datadict.inc.php
|
ADODB_DataDict.RenameColumnSQL
|
function RenameColumnSQL($tabname,$oldcolumn,$newcolumn,$flds='')
{
$tabname = $this->TableName ($tabname);
if ($flds) {
list($lines,$pkey,$idxs) = $this->_GenFields($flds);
// genfields can return FALSE at times
if ($lines == null) $lines = array();
$first = current($lines);
list(,$column_def) = preg_split("/[\t ]+/",$first,2);
}
return array(sprintf($this->renameColumn,$tabname,$this->NameQuote($oldcolumn),$this->NameQuote($newcolumn),$column_def));
}
|
php
|
function RenameColumnSQL($tabname,$oldcolumn,$newcolumn,$flds='')
{
$tabname = $this->TableName ($tabname);
if ($flds) {
list($lines,$pkey,$idxs) = $this->_GenFields($flds);
// genfields can return FALSE at times
if ($lines == null) $lines = array();
$first = current($lines);
list(,$column_def) = preg_split("/[\t ]+/",$first,2);
}
return array(sprintf($this->renameColumn,$tabname,$this->NameQuote($oldcolumn),$this->NameQuote($newcolumn),$column_def));
}
|
[
"function",
"RenameColumnSQL",
"(",
"$",
"tabname",
",",
"$",
"oldcolumn",
",",
"$",
"newcolumn",
",",
"$",
"flds",
"=",
"''",
")",
"{",
"$",
"tabname",
"=",
"$",
"this",
"->",
"TableName",
"(",
"$",
"tabname",
")",
";",
"if",
"(",
"$",
"flds",
")",
"{",
"list",
"(",
"$",
"lines",
",",
"$",
"pkey",
",",
"$",
"idxs",
")",
"=",
"$",
"this",
"->",
"_GenFields",
"(",
"$",
"flds",
")",
";",
"// genfields can return FALSE at times",
"if",
"(",
"$",
"lines",
"==",
"null",
")",
"$",
"lines",
"=",
"array",
"(",
")",
";",
"$",
"first",
"=",
"current",
"(",
"$",
"lines",
")",
";",
"list",
"(",
",",
"$",
"column_def",
")",
"=",
"preg_split",
"(",
"\"/[\\t ]+/\"",
",",
"$",
"first",
",",
"2",
")",
";",
"}",
"return",
"array",
"(",
"sprintf",
"(",
"$",
"this",
"->",
"renameColumn",
",",
"$",
"tabname",
",",
"$",
"this",
"->",
"NameQuote",
"(",
"$",
"oldcolumn",
")",
",",
"$",
"this",
"->",
"NameQuote",
"(",
"$",
"newcolumn",
")",
",",
"$",
"column_def",
")",
")",
";",
"}"
] |
Rename one column
Some DBM's can only do this together with changeing the type of the column (even if that stays the same, eg. mysql)
@param string $tabname table-name
@param string $oldcolumn column-name to be renamed
@param string $newcolumn new column-name
@param string $flds='' complete column-defintion-string like for AddColumnSQL, only used by mysql atm., default=''
@return array with SQL strings
|
[
"Rename",
"one",
"column"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-datadict.inc.php#L516-L527
|
220,131
|
moodle/moodle
|
lib/adodb/adodb-datadict.inc.php
|
ADODB_DataDict.CreateTableSQL
|
function CreateTableSQL($tabname, $flds, $tableoptions=array())
{
list($lines,$pkey,$idxs) = $this->_GenFields($flds, true);
// genfields can return FALSE at times
if ($lines == null) $lines = array();
$taboptions = $this->_Options($tableoptions);
$tabname = $this->TableName ($tabname);
$sql = $this->_TableSQL($tabname,$lines,$pkey,$taboptions);
// ggiunta - 2006/10/12 - KLUDGE:
// if we are on autoincrement, and table options includes REPLACE, the
// autoincrement sequence has already been dropped on table creation sql, so
// we avoid passing REPLACE to trigger creation code. This prevents
// creating sql that double-drops the sequence
if ($this->autoIncrement && isset($taboptions['REPLACE']))
unset($taboptions['REPLACE']);
$tsql = $this->_Triggers($tabname,$taboptions);
foreach($tsql as $s) $sql[] = $s;
if (is_array($idxs)) {
foreach($idxs as $idx => $idxdef) {
$sql_idxs = $this->CreateIndexSql($idx, $tabname, $idxdef['cols'], $idxdef['opts']);
$sql = array_merge($sql, $sql_idxs);
}
}
return $sql;
}
|
php
|
function CreateTableSQL($tabname, $flds, $tableoptions=array())
{
list($lines,$pkey,$idxs) = $this->_GenFields($flds, true);
// genfields can return FALSE at times
if ($lines == null) $lines = array();
$taboptions = $this->_Options($tableoptions);
$tabname = $this->TableName ($tabname);
$sql = $this->_TableSQL($tabname,$lines,$pkey,$taboptions);
// ggiunta - 2006/10/12 - KLUDGE:
// if we are on autoincrement, and table options includes REPLACE, the
// autoincrement sequence has already been dropped on table creation sql, so
// we avoid passing REPLACE to trigger creation code. This prevents
// creating sql that double-drops the sequence
if ($this->autoIncrement && isset($taboptions['REPLACE']))
unset($taboptions['REPLACE']);
$tsql = $this->_Triggers($tabname,$taboptions);
foreach($tsql as $s) $sql[] = $s;
if (is_array($idxs)) {
foreach($idxs as $idx => $idxdef) {
$sql_idxs = $this->CreateIndexSql($idx, $tabname, $idxdef['cols'], $idxdef['opts']);
$sql = array_merge($sql, $sql_idxs);
}
}
return $sql;
}
|
[
"function",
"CreateTableSQL",
"(",
"$",
"tabname",
",",
"$",
"flds",
",",
"$",
"tableoptions",
"=",
"array",
"(",
")",
")",
"{",
"list",
"(",
"$",
"lines",
",",
"$",
"pkey",
",",
"$",
"idxs",
")",
"=",
"$",
"this",
"->",
"_GenFields",
"(",
"$",
"flds",
",",
"true",
")",
";",
"// genfields can return FALSE at times",
"if",
"(",
"$",
"lines",
"==",
"null",
")",
"$",
"lines",
"=",
"array",
"(",
")",
";",
"$",
"taboptions",
"=",
"$",
"this",
"->",
"_Options",
"(",
"$",
"tableoptions",
")",
";",
"$",
"tabname",
"=",
"$",
"this",
"->",
"TableName",
"(",
"$",
"tabname",
")",
";",
"$",
"sql",
"=",
"$",
"this",
"->",
"_TableSQL",
"(",
"$",
"tabname",
",",
"$",
"lines",
",",
"$",
"pkey",
",",
"$",
"taboptions",
")",
";",
"// ggiunta - 2006/10/12 - KLUDGE:",
"// if we are on autoincrement, and table options includes REPLACE, the",
"// autoincrement sequence has already been dropped on table creation sql, so",
"// we avoid passing REPLACE to trigger creation code. This prevents",
"// creating sql that double-drops the sequence",
"if",
"(",
"$",
"this",
"->",
"autoIncrement",
"&&",
"isset",
"(",
"$",
"taboptions",
"[",
"'REPLACE'",
"]",
")",
")",
"unset",
"(",
"$",
"taboptions",
"[",
"'REPLACE'",
"]",
")",
";",
"$",
"tsql",
"=",
"$",
"this",
"->",
"_Triggers",
"(",
"$",
"tabname",
",",
"$",
"taboptions",
")",
";",
"foreach",
"(",
"$",
"tsql",
"as",
"$",
"s",
")",
"$",
"sql",
"[",
"]",
"=",
"$",
"s",
";",
"if",
"(",
"is_array",
"(",
"$",
"idxs",
")",
")",
"{",
"foreach",
"(",
"$",
"idxs",
"as",
"$",
"idx",
"=>",
"$",
"idxdef",
")",
"{",
"$",
"sql_idxs",
"=",
"$",
"this",
"->",
"CreateIndexSql",
"(",
"$",
"idx",
",",
"$",
"tabname",
",",
"$",
"idxdef",
"[",
"'cols'",
"]",
",",
"$",
"idxdef",
"[",
"'opts'",
"]",
")",
";",
"$",
"sql",
"=",
"array_merge",
"(",
"$",
"sql",
",",
"$",
"sql_idxs",
")",
";",
"}",
"}",
"return",
"$",
"sql",
";",
"}"
] |
Generate the SQL to create table. Returns an array of sql strings.
|
[
"Generate",
"the",
"SQL",
"to",
"create",
"table",
".",
"Returns",
"an",
"array",
"of",
"sql",
"strings",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-datadict.inc.php#L565-L593
|
220,132
|
moodle/moodle
|
lib/adodb/adodb-datadict.inc.php
|
ADODB_DataDict._Options
|
function _Options($opts)
{
if (!is_array($opts)) return array();
$newopts = array();
foreach($opts as $k => $v) {
if (is_numeric($k)) $newopts[strtoupper($v)] = $v;
else $newopts[strtoupper($k)] = $v;
}
return $newopts;
}
|
php
|
function _Options($opts)
{
if (!is_array($opts)) return array();
$newopts = array();
foreach($opts as $k => $v) {
if (is_numeric($k)) $newopts[strtoupper($v)] = $v;
else $newopts[strtoupper($k)] = $v;
}
return $newopts;
}
|
[
"function",
"_Options",
"(",
"$",
"opts",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"opts",
")",
")",
"return",
"array",
"(",
")",
";",
"$",
"newopts",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"opts",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"k",
")",
")",
"$",
"newopts",
"[",
"strtoupper",
"(",
"$",
"v",
")",
"]",
"=",
"$",
"v",
";",
"else",
"$",
"newopts",
"[",
"strtoupper",
"(",
"$",
"k",
")",
"]",
"=",
"$",
"v",
";",
"}",
"return",
"$",
"newopts",
";",
"}"
] |
Sanitize options, so that array elements with no keys are promoted to keys
|
[
"Sanitize",
"options",
"so",
"that",
"array",
"elements",
"with",
"no",
"keys",
"are",
"promoted",
"to",
"keys"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-datadict.inc.php#L909-L918
|
220,133
|
moodle/moodle
|
lib/mlbackend/php/phpml/src/Phpml/Math/Set.php
|
Set.cartesian
|
public static function cartesian(Set $a, Set $b) : array
{
$cartesian = [];
foreach ($a as $multiplier) {
foreach ($b as $multiplicand) {
$cartesian[] = new self(array_merge([$multiplicand], [$multiplier]));
}
}
return $cartesian;
}
|
php
|
public static function cartesian(Set $a, Set $b) : array
{
$cartesian = [];
foreach ($a as $multiplier) {
foreach ($b as $multiplicand) {
$cartesian[] = new self(array_merge([$multiplicand], [$multiplier]));
}
}
return $cartesian;
}
|
[
"public",
"static",
"function",
"cartesian",
"(",
"Set",
"$",
"a",
",",
"Set",
"$",
"b",
")",
":",
"array",
"{",
"$",
"cartesian",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"a",
"as",
"$",
"multiplier",
")",
"{",
"foreach",
"(",
"$",
"b",
"as",
"$",
"multiplicand",
")",
"{",
"$",
"cartesian",
"[",
"]",
"=",
"new",
"self",
"(",
"array_merge",
"(",
"[",
"$",
"multiplicand",
"]",
",",
"[",
"$",
"multiplier",
"]",
")",
")",
";",
"}",
"}",
"return",
"$",
"cartesian",
";",
"}"
] |
Creates the Cartesian product of A and B.
@param Set $a
@param Set $b
@return Set[]
|
[
"Creates",
"the",
"Cartesian",
"product",
"of",
"A",
"and",
"B",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mlbackend/php/phpml/src/Phpml/Math/Set.php#L69-L80
|
220,134
|
moodle/moodle
|
lib/mlbackend/php/phpml/src/Phpml/Math/Set.php
|
Set.power
|
public static function power(Set $a) : array
{
$power = [new self()];
foreach ($a as $multiplicand) {
foreach ($power as $multiplier) {
$power[] = new self(array_merge([$multiplicand], $multiplier->toArray()));
}
}
return $power;
}
|
php
|
public static function power(Set $a) : array
{
$power = [new self()];
foreach ($a as $multiplicand) {
foreach ($power as $multiplier) {
$power[] = new self(array_merge([$multiplicand], $multiplier->toArray()));
}
}
return $power;
}
|
[
"public",
"static",
"function",
"power",
"(",
"Set",
"$",
"a",
")",
":",
"array",
"{",
"$",
"power",
"=",
"[",
"new",
"self",
"(",
")",
"]",
";",
"foreach",
"(",
"$",
"a",
"as",
"$",
"multiplicand",
")",
"{",
"foreach",
"(",
"$",
"power",
"as",
"$",
"multiplier",
")",
"{",
"$",
"power",
"[",
"]",
"=",
"new",
"self",
"(",
"array_merge",
"(",
"[",
"$",
"multiplicand",
"]",
",",
"$",
"multiplier",
"->",
"toArray",
"(",
")",
")",
")",
";",
"}",
"}",
"return",
"$",
"power",
";",
"}"
] |
Creates the power set of A.
@param Set $a
@return Set[]
|
[
"Creates",
"the",
"power",
"set",
"of",
"A",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mlbackend/php/phpml/src/Phpml/Math/Set.php#L89-L100
|
220,135
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Writer/Excel2007/Theme.php
|
PHPExcel_Writer_Excel2007_Theme.writeFonts
|
private function writeFonts($objWriter, $latinFont, $fontSet)
{
// a:latin
$objWriter->startElement('a:latin');
$objWriter->writeAttribute('typeface', $latinFont);
$objWriter->endElement();
// a:ea
$objWriter->startElement('a:ea');
$objWriter->writeAttribute('typeface', '');
$objWriter->endElement();
// a:cs
$objWriter->startElement('a:cs');
$objWriter->writeAttribute('typeface', '');
$objWriter->endElement();
foreach ($fontSet as $fontScript => $typeface) {
$objWriter->startElement('a:font');
$objWriter->writeAttribute('script', $fontScript);
$objWriter->writeAttribute('typeface', $typeface);
$objWriter->endElement();
}
}
|
php
|
private function writeFonts($objWriter, $latinFont, $fontSet)
{
// a:latin
$objWriter->startElement('a:latin');
$objWriter->writeAttribute('typeface', $latinFont);
$objWriter->endElement();
// a:ea
$objWriter->startElement('a:ea');
$objWriter->writeAttribute('typeface', '');
$objWriter->endElement();
// a:cs
$objWriter->startElement('a:cs');
$objWriter->writeAttribute('typeface', '');
$objWriter->endElement();
foreach ($fontSet as $fontScript => $typeface) {
$objWriter->startElement('a:font');
$objWriter->writeAttribute('script', $fontScript);
$objWriter->writeAttribute('typeface', $typeface);
$objWriter->endElement();
}
}
|
[
"private",
"function",
"writeFonts",
"(",
"$",
"objWriter",
",",
"$",
"latinFont",
",",
"$",
"fontSet",
")",
"{",
"// a:latin",
"$",
"objWriter",
"->",
"startElement",
"(",
"'a:latin'",
")",
";",
"$",
"objWriter",
"->",
"writeAttribute",
"(",
"'typeface'",
",",
"$",
"latinFont",
")",
";",
"$",
"objWriter",
"->",
"endElement",
"(",
")",
";",
"// a:ea",
"$",
"objWriter",
"->",
"startElement",
"(",
"'a:ea'",
")",
";",
"$",
"objWriter",
"->",
"writeAttribute",
"(",
"'typeface'",
",",
"''",
")",
";",
"$",
"objWriter",
"->",
"endElement",
"(",
")",
";",
"// a:cs",
"$",
"objWriter",
"->",
"startElement",
"(",
"'a:cs'",
")",
";",
"$",
"objWriter",
"->",
"writeAttribute",
"(",
"'typeface'",
",",
"''",
")",
";",
"$",
"objWriter",
"->",
"endElement",
"(",
")",
";",
"foreach",
"(",
"$",
"fontSet",
"as",
"$",
"fontScript",
"=>",
"$",
"typeface",
")",
"{",
"$",
"objWriter",
"->",
"startElement",
"(",
"'a:font'",
")",
";",
"$",
"objWriter",
"->",
"writeAttribute",
"(",
"'script'",
",",
"$",
"fontScript",
")",
";",
"$",
"objWriter",
"->",
"writeAttribute",
"(",
"'typeface'",
",",
"$",
"typeface",
")",
";",
"$",
"objWriter",
"->",
"endElement",
"(",
")",
";",
"}",
"}"
] |
Write fonts to XML format
@param PHPExcel_Shared_XMLWriter $objWriter
@param string $latinFont
@param array of string $fontSet
@return string XML Output
@throws PHPExcel_Writer_Exception
|
[
"Write",
"fonts",
"to",
"XML",
"format"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Writer/Excel2007/Theme.php#L825-L848
|
220,136
|
moodle/moodle
|
rating/lib.php
|
rating.update_rating
|
public function update_rating($rating) {
global $DB;
$time = time();
$data = new stdClass;
$data->rating = $rating;
$data->timemodified = $time;
$item = new stdclass();
$item->id = $this->itemid;
$items = array($item);
$ratingoptions = new stdClass;
$ratingoptions->context = $this->context;
$ratingoptions->component = $this->component;
$ratingoptions->ratingarea = $this->ratingarea;
$ratingoptions->items = $items;
$ratingoptions->aggregate = RATING_AGGREGATE_AVERAGE; // We dont actually care what aggregation method is applied.
$ratingoptions->scaleid = $this->scaleid;
$ratingoptions->userid = $this->userid;
$rm = new rating_manager();
$items = $rm->get_ratings($ratingoptions);
$firstitem = $items[0]->rating;
if (empty($firstitem->id)) {
// Insert a new rating.
$data->contextid = $this->context->id;
$data->component = $this->component;
$data->ratingarea = $this->ratingarea;
$data->rating = $rating;
$data->scaleid = $this->scaleid;
$data->userid = $this->userid;
$data->itemid = $this->itemid;
$data->timecreated = $time;
$data->timemodified = $time;
$DB->insert_record('rating', $data);
} else {
// Update the rating.
$data->id = $firstitem->id;
$DB->update_record('rating', $data);
}
}
|
php
|
public function update_rating($rating) {
global $DB;
$time = time();
$data = new stdClass;
$data->rating = $rating;
$data->timemodified = $time;
$item = new stdclass();
$item->id = $this->itemid;
$items = array($item);
$ratingoptions = new stdClass;
$ratingoptions->context = $this->context;
$ratingoptions->component = $this->component;
$ratingoptions->ratingarea = $this->ratingarea;
$ratingoptions->items = $items;
$ratingoptions->aggregate = RATING_AGGREGATE_AVERAGE; // We dont actually care what aggregation method is applied.
$ratingoptions->scaleid = $this->scaleid;
$ratingoptions->userid = $this->userid;
$rm = new rating_manager();
$items = $rm->get_ratings($ratingoptions);
$firstitem = $items[0]->rating;
if (empty($firstitem->id)) {
// Insert a new rating.
$data->contextid = $this->context->id;
$data->component = $this->component;
$data->ratingarea = $this->ratingarea;
$data->rating = $rating;
$data->scaleid = $this->scaleid;
$data->userid = $this->userid;
$data->itemid = $this->itemid;
$data->timecreated = $time;
$data->timemodified = $time;
$DB->insert_record('rating', $data);
} else {
// Update the rating.
$data->id = $firstitem->id;
$DB->update_record('rating', $data);
}
}
|
[
"public",
"function",
"update_rating",
"(",
"$",
"rating",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"time",
"=",
"time",
"(",
")",
";",
"$",
"data",
"=",
"new",
"stdClass",
";",
"$",
"data",
"->",
"rating",
"=",
"$",
"rating",
";",
"$",
"data",
"->",
"timemodified",
"=",
"$",
"time",
";",
"$",
"item",
"=",
"new",
"stdclass",
"(",
")",
";",
"$",
"item",
"->",
"id",
"=",
"$",
"this",
"->",
"itemid",
";",
"$",
"items",
"=",
"array",
"(",
"$",
"item",
")",
";",
"$",
"ratingoptions",
"=",
"new",
"stdClass",
";",
"$",
"ratingoptions",
"->",
"context",
"=",
"$",
"this",
"->",
"context",
";",
"$",
"ratingoptions",
"->",
"component",
"=",
"$",
"this",
"->",
"component",
";",
"$",
"ratingoptions",
"->",
"ratingarea",
"=",
"$",
"this",
"->",
"ratingarea",
";",
"$",
"ratingoptions",
"->",
"items",
"=",
"$",
"items",
";",
"$",
"ratingoptions",
"->",
"aggregate",
"=",
"RATING_AGGREGATE_AVERAGE",
";",
"// We dont actually care what aggregation method is applied.",
"$",
"ratingoptions",
"->",
"scaleid",
"=",
"$",
"this",
"->",
"scaleid",
";",
"$",
"ratingoptions",
"->",
"userid",
"=",
"$",
"this",
"->",
"userid",
";",
"$",
"rm",
"=",
"new",
"rating_manager",
"(",
")",
";",
"$",
"items",
"=",
"$",
"rm",
"->",
"get_ratings",
"(",
"$",
"ratingoptions",
")",
";",
"$",
"firstitem",
"=",
"$",
"items",
"[",
"0",
"]",
"->",
"rating",
";",
"if",
"(",
"empty",
"(",
"$",
"firstitem",
"->",
"id",
")",
")",
"{",
"// Insert a new rating.",
"$",
"data",
"->",
"contextid",
"=",
"$",
"this",
"->",
"context",
"->",
"id",
";",
"$",
"data",
"->",
"component",
"=",
"$",
"this",
"->",
"component",
";",
"$",
"data",
"->",
"ratingarea",
"=",
"$",
"this",
"->",
"ratingarea",
";",
"$",
"data",
"->",
"rating",
"=",
"$",
"rating",
";",
"$",
"data",
"->",
"scaleid",
"=",
"$",
"this",
"->",
"scaleid",
";",
"$",
"data",
"->",
"userid",
"=",
"$",
"this",
"->",
"userid",
";",
"$",
"data",
"->",
"itemid",
"=",
"$",
"this",
"->",
"itemid",
";",
"$",
"data",
"->",
"timecreated",
"=",
"$",
"time",
";",
"$",
"data",
"->",
"timemodified",
"=",
"$",
"time",
";",
"$",
"DB",
"->",
"insert_record",
"(",
"'rating'",
",",
"$",
"data",
")",
";",
"}",
"else",
"{",
"// Update the rating.",
"$",
"data",
"->",
"id",
"=",
"$",
"firstitem",
"->",
"id",
";",
"$",
"DB",
"->",
"update_record",
"(",
"'rating'",
",",
"$",
"data",
")",
";",
"}",
"}"
] |
Update this rating in the database
@param int $rating the integer value of this rating
|
[
"Update",
"this",
"rating",
"in",
"the",
"database"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/rating/lib.php#L161-L204
|
220,137
|
moodle/moodle
|
rating/lib.php
|
rating.get_aggregate_string
|
public function get_aggregate_string() {
$aggregate = $this->aggregate;
$method = $this->settings->aggregationmethod;
// Only display aggregate if aggregation method isn't COUNT.
$aggregatestr = '';
if (is_numeric($aggregate) && $method != RATING_AGGREGATE_COUNT) {
if ($method != RATING_AGGREGATE_SUM && !$this->settings->scale->isnumeric) {
// Round aggregate as we're using it as an index.
$aggregatestr .= $this->settings->scale->scaleitems[round($aggregate)];
} else { // Aggregation is SUM or the scale is numeric.
$aggregatestr .= round($aggregate, 1);
}
}
return $aggregatestr;
}
|
php
|
public function get_aggregate_string() {
$aggregate = $this->aggregate;
$method = $this->settings->aggregationmethod;
// Only display aggregate if aggregation method isn't COUNT.
$aggregatestr = '';
if (is_numeric($aggregate) && $method != RATING_AGGREGATE_COUNT) {
if ($method != RATING_AGGREGATE_SUM && !$this->settings->scale->isnumeric) {
// Round aggregate as we're using it as an index.
$aggregatestr .= $this->settings->scale->scaleitems[round($aggregate)];
} else { // Aggregation is SUM or the scale is numeric.
$aggregatestr .= round($aggregate, 1);
}
}
return $aggregatestr;
}
|
[
"public",
"function",
"get_aggregate_string",
"(",
")",
"{",
"$",
"aggregate",
"=",
"$",
"this",
"->",
"aggregate",
";",
"$",
"method",
"=",
"$",
"this",
"->",
"settings",
"->",
"aggregationmethod",
";",
"// Only display aggregate if aggregation method isn't COUNT.",
"$",
"aggregatestr",
"=",
"''",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"aggregate",
")",
"&&",
"$",
"method",
"!=",
"RATING_AGGREGATE_COUNT",
")",
"{",
"if",
"(",
"$",
"method",
"!=",
"RATING_AGGREGATE_SUM",
"&&",
"!",
"$",
"this",
"->",
"settings",
"->",
"scale",
"->",
"isnumeric",
")",
"{",
"// Round aggregate as we're using it as an index.",
"$",
"aggregatestr",
".=",
"$",
"this",
"->",
"settings",
"->",
"scale",
"->",
"scaleitems",
"[",
"round",
"(",
"$",
"aggregate",
")",
"]",
";",
"}",
"else",
"{",
"// Aggregation is SUM or the scale is numeric.",
"$",
"aggregatestr",
".=",
"round",
"(",
"$",
"aggregate",
",",
"1",
")",
";",
"}",
"}",
"return",
"$",
"aggregatestr",
";",
"}"
] |
Returns this ratings aggregate value as a string.
@return string ratings aggregate value
|
[
"Returns",
"this",
"ratings",
"aggregate",
"value",
"as",
"a",
"string",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/rating/lib.php#L220-L238
|
220,138
|
moodle/moodle
|
rating/lib.php
|
rating.user_can_rate
|
public function user_can_rate($userid = null) {
if (empty($userid)) {
global $USER;
$userid = $USER->id;
}
// You can't rate your item.
if ($this->itemuserid == $userid) {
return false;
}
// You can't rate if you don't have the system cap.
if (!$this->settings->permissions->rate) {
return false;
}
// You can't rate if you don't have the plugin cap.
if (!$this->settings->pluginpermissions->rate) {
return false;
}
// You can't rate if the item was outside of the assessment times.
$timestart = $this->settings->assesstimestart;
$timefinish = $this->settings->assesstimefinish;
$timecreated = $this->itemtimecreated;
if (!empty($timestart) && !empty($timefinish) && ($timecreated < $timestart || $timecreated > $timefinish)) {
return false;
}
return true;
}
|
php
|
public function user_can_rate($userid = null) {
if (empty($userid)) {
global $USER;
$userid = $USER->id;
}
// You can't rate your item.
if ($this->itemuserid == $userid) {
return false;
}
// You can't rate if you don't have the system cap.
if (!$this->settings->permissions->rate) {
return false;
}
// You can't rate if you don't have the plugin cap.
if (!$this->settings->pluginpermissions->rate) {
return false;
}
// You can't rate if the item was outside of the assessment times.
$timestart = $this->settings->assesstimestart;
$timefinish = $this->settings->assesstimefinish;
$timecreated = $this->itemtimecreated;
if (!empty($timestart) && !empty($timefinish) && ($timecreated < $timestart || $timecreated > $timefinish)) {
return false;
}
return true;
}
|
[
"public",
"function",
"user_can_rate",
"(",
"$",
"userid",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"userid",
")",
")",
"{",
"global",
"$",
"USER",
";",
"$",
"userid",
"=",
"$",
"USER",
"->",
"id",
";",
"}",
"// You can't rate your item.",
"if",
"(",
"$",
"this",
"->",
"itemuserid",
"==",
"$",
"userid",
")",
"{",
"return",
"false",
";",
"}",
"// You can't rate if you don't have the system cap.",
"if",
"(",
"!",
"$",
"this",
"->",
"settings",
"->",
"permissions",
"->",
"rate",
")",
"{",
"return",
"false",
";",
"}",
"// You can't rate if you don't have the plugin cap.",
"if",
"(",
"!",
"$",
"this",
"->",
"settings",
"->",
"pluginpermissions",
"->",
"rate",
")",
"{",
"return",
"false",
";",
"}",
"// You can't rate if the item was outside of the assessment times.",
"$",
"timestart",
"=",
"$",
"this",
"->",
"settings",
"->",
"assesstimestart",
";",
"$",
"timefinish",
"=",
"$",
"this",
"->",
"settings",
"->",
"assesstimefinish",
";",
"$",
"timecreated",
"=",
"$",
"this",
"->",
"itemtimecreated",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"timestart",
")",
"&&",
"!",
"empty",
"(",
"$",
"timefinish",
")",
"&&",
"(",
"$",
"timecreated",
"<",
"$",
"timestart",
"||",
"$",
"timecreated",
">",
"$",
"timefinish",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Returns true if the user is able to rate this rating object
@param int $userid Current user assumed if left empty
@return bool true if the user is able to rate this rating object
|
[
"Returns",
"true",
"if",
"the",
"user",
"is",
"able",
"to",
"rate",
"this",
"rating",
"object"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/rating/lib.php#L246-L272
|
220,139
|
moodle/moodle
|
rating/lib.php
|
rating.user_can_view_aggregate
|
public function user_can_view_aggregate($userid = null) {
if (empty($userid)) {
global $USER;
$userid = $USER->id;
}
// If the item doesnt belong to anyone or its another user's items and they can see the aggregate on items they don't own.
// Note that viewany doesnt mean you can see the aggregate or ratings of your own items.
if ((empty($this->itemuserid) or $this->itemuserid != $userid)
&& $this->settings->permissions->viewany
&& $this->settings->pluginpermissions->viewany ) {
return true;
}
// If its the current user's item and they have permission to view the aggregate on their own items.
if ($this->itemuserid == $userid
&& $this->settings->permissions->view
&& $this->settings->pluginpermissions->view) {
return true;
}
return false;
}
|
php
|
public function user_can_view_aggregate($userid = null) {
if (empty($userid)) {
global $USER;
$userid = $USER->id;
}
// If the item doesnt belong to anyone or its another user's items and they can see the aggregate on items they don't own.
// Note that viewany doesnt mean you can see the aggregate or ratings of your own items.
if ((empty($this->itemuserid) or $this->itemuserid != $userid)
&& $this->settings->permissions->viewany
&& $this->settings->pluginpermissions->viewany ) {
return true;
}
// If its the current user's item and they have permission to view the aggregate on their own items.
if ($this->itemuserid == $userid
&& $this->settings->permissions->view
&& $this->settings->pluginpermissions->view) {
return true;
}
return false;
}
|
[
"public",
"function",
"user_can_view_aggregate",
"(",
"$",
"userid",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"userid",
")",
")",
"{",
"global",
"$",
"USER",
";",
"$",
"userid",
"=",
"$",
"USER",
"->",
"id",
";",
"}",
"// If the item doesnt belong to anyone or its another user's items and they can see the aggregate on items they don't own.",
"// Note that viewany doesnt mean you can see the aggregate or ratings of your own items.",
"if",
"(",
"(",
"empty",
"(",
"$",
"this",
"->",
"itemuserid",
")",
"or",
"$",
"this",
"->",
"itemuserid",
"!=",
"$",
"userid",
")",
"&&",
"$",
"this",
"->",
"settings",
"->",
"permissions",
"->",
"viewany",
"&&",
"$",
"this",
"->",
"settings",
"->",
"pluginpermissions",
"->",
"viewany",
")",
"{",
"return",
"true",
";",
"}",
"// If its the current user's item and they have permission to view the aggregate on their own items.",
"if",
"(",
"$",
"this",
"->",
"itemuserid",
"==",
"$",
"userid",
"&&",
"$",
"this",
"->",
"settings",
"->",
"permissions",
"->",
"view",
"&&",
"$",
"this",
"->",
"settings",
"->",
"pluginpermissions",
"->",
"view",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Returns true if the user is able to view the aggregate for this rating object.
@param int|null $userid If left empty the current user is assumed.
@return bool true if the user is able to view the aggregate for this rating object
|
[
"Returns",
"true",
"if",
"the",
"user",
"is",
"able",
"to",
"view",
"the",
"aggregate",
"for",
"this",
"rating",
"object",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/rating/lib.php#L280-L304
|
220,140
|
moodle/moodle
|
rating/lib.php
|
rating.get_view_ratings_url
|
public function get_view_ratings_url($popup = false) {
$attributes = array(
'contextid' => $this->context->id,
'component' => $this->component,
'ratingarea' => $this->ratingarea,
'itemid' => $this->itemid,
'scaleid' => $this->settings->scale->id
);
if ($popup) {
$attributes['popup'] = 1;
}
return new moodle_url('/rating/index.php', $attributes);
}
|
php
|
public function get_view_ratings_url($popup = false) {
$attributes = array(
'contextid' => $this->context->id,
'component' => $this->component,
'ratingarea' => $this->ratingarea,
'itemid' => $this->itemid,
'scaleid' => $this->settings->scale->id
);
if ($popup) {
$attributes['popup'] = 1;
}
return new moodle_url('/rating/index.php', $attributes);
}
|
[
"public",
"function",
"get_view_ratings_url",
"(",
"$",
"popup",
"=",
"false",
")",
"{",
"$",
"attributes",
"=",
"array",
"(",
"'contextid'",
"=>",
"$",
"this",
"->",
"context",
"->",
"id",
",",
"'component'",
"=>",
"$",
"this",
"->",
"component",
",",
"'ratingarea'",
"=>",
"$",
"this",
"->",
"ratingarea",
",",
"'itemid'",
"=>",
"$",
"this",
"->",
"itemid",
",",
"'scaleid'",
"=>",
"$",
"this",
"->",
"settings",
"->",
"scale",
"->",
"id",
")",
";",
"if",
"(",
"$",
"popup",
")",
"{",
"$",
"attributes",
"[",
"'popup'",
"]",
"=",
"1",
";",
"}",
"return",
"new",
"moodle_url",
"(",
"'/rating/index.php'",
",",
"$",
"attributes",
")",
";",
"}"
] |
Returns a URL to view all of the ratings for the item this rating is for.
If this is a rating of a post then this URL will take the user to a page that shows all of the ratings for the post
(this one included).
@param bool $popup whether of not the URL should be loaded in a popup
@return moodle_url URL to view all of the ratings for the item this rating is for.
|
[
"Returns",
"a",
"URL",
"to",
"view",
"all",
"of",
"the",
"ratings",
"for",
"the",
"item",
"this",
"rating",
"is",
"for",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/rating/lib.php#L315-L327
|
220,141
|
moodle/moodle
|
rating/lib.php
|
rating.get_rate_url
|
public function get_rate_url($rating = null, $returnurl = null) {
if (empty($returnurl)) {
if (!empty($this->settings->returnurl)) {
$returnurl = $this->settings->returnurl;
} else {
global $PAGE;
$returnurl = $PAGE->url;
}
}
$args = array(
'contextid' => $this->context->id,
'component' => $this->component,
'ratingarea' => $this->ratingarea,
'itemid' => $this->itemid,
'scaleid' => $this->settings->scale->id,
'returnurl' => $returnurl,
'rateduserid' => $this->itemuserid,
'aggregation' => $this->settings->aggregationmethod,
'sesskey' => sesskey()
);
if (!empty($rating)) {
$args['rating'] = $rating;
}
$url = new moodle_url('/rating/rate.php', $args);
return $url;
}
|
php
|
public function get_rate_url($rating = null, $returnurl = null) {
if (empty($returnurl)) {
if (!empty($this->settings->returnurl)) {
$returnurl = $this->settings->returnurl;
} else {
global $PAGE;
$returnurl = $PAGE->url;
}
}
$args = array(
'contextid' => $this->context->id,
'component' => $this->component,
'ratingarea' => $this->ratingarea,
'itemid' => $this->itemid,
'scaleid' => $this->settings->scale->id,
'returnurl' => $returnurl,
'rateduserid' => $this->itemuserid,
'aggregation' => $this->settings->aggregationmethod,
'sesskey' => sesskey()
);
if (!empty($rating)) {
$args['rating'] = $rating;
}
$url = new moodle_url('/rating/rate.php', $args);
return $url;
}
|
[
"public",
"function",
"get_rate_url",
"(",
"$",
"rating",
"=",
"null",
",",
"$",
"returnurl",
"=",
"null",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"returnurl",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"settings",
"->",
"returnurl",
")",
")",
"{",
"$",
"returnurl",
"=",
"$",
"this",
"->",
"settings",
"->",
"returnurl",
";",
"}",
"else",
"{",
"global",
"$",
"PAGE",
";",
"$",
"returnurl",
"=",
"$",
"PAGE",
"->",
"url",
";",
"}",
"}",
"$",
"args",
"=",
"array",
"(",
"'contextid'",
"=>",
"$",
"this",
"->",
"context",
"->",
"id",
",",
"'component'",
"=>",
"$",
"this",
"->",
"component",
",",
"'ratingarea'",
"=>",
"$",
"this",
"->",
"ratingarea",
",",
"'itemid'",
"=>",
"$",
"this",
"->",
"itemid",
",",
"'scaleid'",
"=>",
"$",
"this",
"->",
"settings",
"->",
"scale",
"->",
"id",
",",
"'returnurl'",
"=>",
"$",
"returnurl",
",",
"'rateduserid'",
"=>",
"$",
"this",
"->",
"itemuserid",
",",
"'aggregation'",
"=>",
"$",
"this",
"->",
"settings",
"->",
"aggregationmethod",
",",
"'sesskey'",
"=>",
"sesskey",
"(",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"rating",
")",
")",
"{",
"$",
"args",
"[",
"'rating'",
"]",
"=",
"$",
"rating",
";",
"}",
"$",
"url",
"=",
"new",
"moodle_url",
"(",
"'/rating/rate.php'",
",",
"$",
"args",
")",
";",
"return",
"$",
"url",
";",
"}"
] |
Returns a URL that can be used to rate the associated item.
@param int|null $rating The rating to give the item, if null then no rating param is added.
@param moodle_url|string $returnurl The URL to return to.
@return moodle_url can be used to rate the associated item.
|
[
"Returns",
"a",
"URL",
"that",
"can",
"be",
"used",
"to",
"rate",
"the",
"associated",
"item",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/rating/lib.php#L336-L361
|
220,142
|
moodle/moodle
|
rating/lib.php
|
rating_manager.delete_ratings
|
public function delete_ratings($options) {
global $DB;
if (empty($options->contextid)) {
throw new coding_exception('The context option is a required option when deleting ratings.');
}
$conditions = array('contextid' => $options->contextid);
$possibleconditions = array(
'ratingid' => 'id',
'userid' => 'userid',
'itemid' => 'itemid',
'component' => 'component',
'ratingarea' => 'ratingarea'
);
foreach ($possibleconditions as $option => $field) {
if (isset($options->{$option})) {
$conditions[$field] = $options->{$option};
}
}
$DB->delete_records('rating', $conditions);
}
|
php
|
public function delete_ratings($options) {
global $DB;
if (empty($options->contextid)) {
throw new coding_exception('The context option is a required option when deleting ratings.');
}
$conditions = array('contextid' => $options->contextid);
$possibleconditions = array(
'ratingid' => 'id',
'userid' => 'userid',
'itemid' => 'itemid',
'component' => 'component',
'ratingarea' => 'ratingarea'
);
foreach ($possibleconditions as $option => $field) {
if (isset($options->{$option})) {
$conditions[$field] = $options->{$option};
}
}
$DB->delete_records('rating', $conditions);
}
|
[
"public",
"function",
"delete_ratings",
"(",
"$",
"options",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"empty",
"(",
"$",
"options",
"->",
"contextid",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The context option is a required option when deleting ratings.'",
")",
";",
"}",
"$",
"conditions",
"=",
"array",
"(",
"'contextid'",
"=>",
"$",
"options",
"->",
"contextid",
")",
";",
"$",
"possibleconditions",
"=",
"array",
"(",
"'ratingid'",
"=>",
"'id'",
",",
"'userid'",
"=>",
"'userid'",
",",
"'itemid'",
"=>",
"'itemid'",
",",
"'component'",
"=>",
"'component'",
",",
"'ratingarea'",
"=>",
"'ratingarea'",
")",
";",
"foreach",
"(",
"$",
"possibleconditions",
"as",
"$",
"option",
"=>",
"$",
"field",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"options",
"->",
"{",
"$",
"option",
"}",
")",
")",
"{",
"$",
"conditions",
"[",
"$",
"field",
"]",
"=",
"$",
"options",
"->",
"{",
"$",
"option",
"}",
";",
"}",
"}",
"$",
"DB",
"->",
"delete_records",
"(",
"'rating'",
",",
"$",
"conditions",
")",
";",
"}"
] |
Delete one or more ratings. Specify either a rating id, an item id or just the context id.
@global moodle_database $DB
@param stdClass $options {
contextid => int the context in which the ratings exist [required]
ratingid => int the id of an individual rating to delete [optional]
userid => int delete the ratings submitted by this user. May be used in conjuction with itemid [optional]
itemid => int delete all ratings attached to this item [optional]
component => string The component to delete ratings from [optional]
ratingarea => string The ratingarea to delete ratings from [optional]
}
|
[
"Delete",
"one",
"or",
"more",
"ratings",
".",
"Specify",
"either",
"a",
"rating",
"id",
"an",
"item",
"id",
"or",
"just",
"the",
"context",
"id",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/rating/lib.php#L394-L415
|
220,143
|
moodle/moodle
|
rating/lib.php
|
rating_manager.generate_rating_settings_object
|
protected function generate_rating_settings_object($options) {
if (!isset($options->context)) {
throw new coding_exception('The context option is a required option when generating a rating settings object.');
}
if (!isset($options->component)) {
throw new coding_exception('The component option is now a required option when generating a rating settings object.');
}
if (!isset($options->ratingarea)) {
throw new coding_exception('The ratingarea option is now a required option when generating a rating settings object.');
}
if (!isset($options->aggregate)) {
throw new coding_exception('The aggregate option is now a required option when generating a rating settings object.');
}
if (!isset($options->scaleid)) {
throw new coding_exception('The scaleid option is now a required option when generating a rating settings object.');
}
// Settings that are common to all ratings objects in this context.
$settings = new stdClass;
$settings->scale = $this->generate_rating_scale_object($options->scaleid); // The scale to use now.
$settings->aggregationmethod = $options->aggregate;
$settings->assesstimestart = null;
$settings->assesstimefinish = null;
// Collect options into the settings object.
if (!empty($options->assesstimestart)) {
$settings->assesstimestart = $options->assesstimestart;
}
if (!empty($options->assesstimefinish)) {
$settings->assesstimefinish = $options->assesstimefinish;
}
if (!empty($options->returnurl)) {
$settings->returnurl = $options->returnurl;
}
// Check site capabilities.
$settings->permissions = new stdClass;
// Can view the aggregate of ratings of their own items.
$settings->permissions->view = has_capability('moodle/rating:view', $options->context);
// Can view the aggregate of ratings of other people's items.
$settings->permissions->viewany = has_capability('moodle/rating:viewany', $options->context);
// Can view individual ratings.
$settings->permissions->viewall = has_capability('moodle/rating:viewall', $options->context);
// Can submit ratings.
$settings->permissions->rate = has_capability('moodle/rating:rate', $options->context);
// Check module capabilities
// This is mostly for backwards compatability with old modules that previously implemented their own ratings.
$pluginpermissionsarray = $this->get_plugin_permissions_array($options->context->id,
$options->component,
$options->ratingarea);
$settings->pluginpermissions = new stdClass;
$settings->pluginpermissions->view = $pluginpermissionsarray['view'];
$settings->pluginpermissions->viewany = $pluginpermissionsarray['viewany'];
$settings->pluginpermissions->viewall = $pluginpermissionsarray['viewall'];
$settings->pluginpermissions->rate = $pluginpermissionsarray['rate'];
return $settings;
}
|
php
|
protected function generate_rating_settings_object($options) {
if (!isset($options->context)) {
throw new coding_exception('The context option is a required option when generating a rating settings object.');
}
if (!isset($options->component)) {
throw new coding_exception('The component option is now a required option when generating a rating settings object.');
}
if (!isset($options->ratingarea)) {
throw new coding_exception('The ratingarea option is now a required option when generating a rating settings object.');
}
if (!isset($options->aggregate)) {
throw new coding_exception('The aggregate option is now a required option when generating a rating settings object.');
}
if (!isset($options->scaleid)) {
throw new coding_exception('The scaleid option is now a required option when generating a rating settings object.');
}
// Settings that are common to all ratings objects in this context.
$settings = new stdClass;
$settings->scale = $this->generate_rating_scale_object($options->scaleid); // The scale to use now.
$settings->aggregationmethod = $options->aggregate;
$settings->assesstimestart = null;
$settings->assesstimefinish = null;
// Collect options into the settings object.
if (!empty($options->assesstimestart)) {
$settings->assesstimestart = $options->assesstimestart;
}
if (!empty($options->assesstimefinish)) {
$settings->assesstimefinish = $options->assesstimefinish;
}
if (!empty($options->returnurl)) {
$settings->returnurl = $options->returnurl;
}
// Check site capabilities.
$settings->permissions = new stdClass;
// Can view the aggregate of ratings of their own items.
$settings->permissions->view = has_capability('moodle/rating:view', $options->context);
// Can view the aggregate of ratings of other people's items.
$settings->permissions->viewany = has_capability('moodle/rating:viewany', $options->context);
// Can view individual ratings.
$settings->permissions->viewall = has_capability('moodle/rating:viewall', $options->context);
// Can submit ratings.
$settings->permissions->rate = has_capability('moodle/rating:rate', $options->context);
// Check module capabilities
// This is mostly for backwards compatability with old modules that previously implemented their own ratings.
$pluginpermissionsarray = $this->get_plugin_permissions_array($options->context->id,
$options->component,
$options->ratingarea);
$settings->pluginpermissions = new stdClass;
$settings->pluginpermissions->view = $pluginpermissionsarray['view'];
$settings->pluginpermissions->viewany = $pluginpermissionsarray['viewany'];
$settings->pluginpermissions->viewall = $pluginpermissionsarray['viewall'];
$settings->pluginpermissions->rate = $pluginpermissionsarray['rate'];
return $settings;
}
|
[
"protected",
"function",
"generate_rating_settings_object",
"(",
"$",
"options",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"->",
"context",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The context option is a required option when generating a rating settings object.'",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"->",
"component",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The component option is now a required option when generating a rating settings object.'",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"->",
"ratingarea",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The ratingarea option is now a required option when generating a rating settings object.'",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"->",
"aggregate",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The aggregate option is now a required option when generating a rating settings object.'",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"->",
"scaleid",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The scaleid option is now a required option when generating a rating settings object.'",
")",
";",
"}",
"// Settings that are common to all ratings objects in this context.",
"$",
"settings",
"=",
"new",
"stdClass",
";",
"$",
"settings",
"->",
"scale",
"=",
"$",
"this",
"->",
"generate_rating_scale_object",
"(",
"$",
"options",
"->",
"scaleid",
")",
";",
"// The scale to use now.",
"$",
"settings",
"->",
"aggregationmethod",
"=",
"$",
"options",
"->",
"aggregate",
";",
"$",
"settings",
"->",
"assesstimestart",
"=",
"null",
";",
"$",
"settings",
"->",
"assesstimefinish",
"=",
"null",
";",
"// Collect options into the settings object.",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"->",
"assesstimestart",
")",
")",
"{",
"$",
"settings",
"->",
"assesstimestart",
"=",
"$",
"options",
"->",
"assesstimestart",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"->",
"assesstimefinish",
")",
")",
"{",
"$",
"settings",
"->",
"assesstimefinish",
"=",
"$",
"options",
"->",
"assesstimefinish",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"->",
"returnurl",
")",
")",
"{",
"$",
"settings",
"->",
"returnurl",
"=",
"$",
"options",
"->",
"returnurl",
";",
"}",
"// Check site capabilities.",
"$",
"settings",
"->",
"permissions",
"=",
"new",
"stdClass",
";",
"// Can view the aggregate of ratings of their own items.",
"$",
"settings",
"->",
"permissions",
"->",
"view",
"=",
"has_capability",
"(",
"'moodle/rating:view'",
",",
"$",
"options",
"->",
"context",
")",
";",
"// Can view the aggregate of ratings of other people's items.",
"$",
"settings",
"->",
"permissions",
"->",
"viewany",
"=",
"has_capability",
"(",
"'moodle/rating:viewany'",
",",
"$",
"options",
"->",
"context",
")",
";",
"// Can view individual ratings.",
"$",
"settings",
"->",
"permissions",
"->",
"viewall",
"=",
"has_capability",
"(",
"'moodle/rating:viewall'",
",",
"$",
"options",
"->",
"context",
")",
";",
"// Can submit ratings.",
"$",
"settings",
"->",
"permissions",
"->",
"rate",
"=",
"has_capability",
"(",
"'moodle/rating:rate'",
",",
"$",
"options",
"->",
"context",
")",
";",
"// Check module capabilities",
"// This is mostly for backwards compatability with old modules that previously implemented their own ratings.",
"$",
"pluginpermissionsarray",
"=",
"$",
"this",
"->",
"get_plugin_permissions_array",
"(",
"$",
"options",
"->",
"context",
"->",
"id",
",",
"$",
"options",
"->",
"component",
",",
"$",
"options",
"->",
"ratingarea",
")",
";",
"$",
"settings",
"->",
"pluginpermissions",
"=",
"new",
"stdClass",
";",
"$",
"settings",
"->",
"pluginpermissions",
"->",
"view",
"=",
"$",
"pluginpermissionsarray",
"[",
"'view'",
"]",
";",
"$",
"settings",
"->",
"pluginpermissions",
"->",
"viewany",
"=",
"$",
"pluginpermissionsarray",
"[",
"'viewany'",
"]",
";",
"$",
"settings",
"->",
"pluginpermissions",
"->",
"viewall",
"=",
"$",
"pluginpermissionsarray",
"[",
"'viewall'",
"]",
";",
"$",
"settings",
"->",
"pluginpermissions",
"->",
"rate",
"=",
"$",
"pluginpermissionsarray",
"[",
"'rate'",
"]",
";",
"return",
"$",
"settings",
";",
"}"
] |
Generates a rating settings object based upon the options it is provided.
@param stdClass $options {
context => context the context in which the ratings exists [required]
component => string The component the items belong to [required]
ratingarea => string The ratingarea the items belong to [required]
aggregate => int Aggregation method to apply. RATING_AGGREGATE_AVERAGE, RATING_AGGREGATE_MAXIMUM etc [required]
scaleid => int the scale from which the user can select a rating [required]
returnurl => string the url to return the user to after submitting a rating. Null for ajax requests [optional]
assesstimestart => int only allow rating of items created after this timestamp [optional]
assesstimefinish => int only allow rating of items created before this timestamp [optional]
plugintype => string plugin type ie 'mod' Used to find the permissions callback [optional]
pluginname => string plugin name ie 'forum' Used to find the permissions callback [optional]
}
@return stdClass rating settings object
|
[
"Generates",
"a",
"rating",
"settings",
"object",
"based",
"upon",
"the",
"options",
"it",
"is",
"provided",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/rating/lib.php#L638-L697
|
220,144
|
moodle/moodle
|
rating/lib.php
|
rating_manager.generate_rating_scale_object
|
protected function generate_rating_scale_object($scaleid) {
global $DB;
if (!array_key_exists('s'.$scaleid, $this->scales)) {
$scale = new stdClass;
$scale->id = $scaleid;
$scale->name = null;
$scale->courseid = null;
$scale->scaleitems = array();
$scale->isnumeric = true;
$scale->max = $scaleid;
if ($scaleid < 0) {
// It is a proper scale (not numeric).
$scalerecord = $DB->get_record('scale', array('id' => abs($scaleid)));
if ($scalerecord) {
// We need to generate an array with string keys starting at 1.
$scalearray = explode(',', $scalerecord->scale);
$c = count($scalearray);
for ($i = 0; $i < $c; $i++) {
// Treat index as a string to allow sorting without changing the value.
$scale->scaleitems[(string)($i + 1)] = $scalearray[$i];
}
krsort($scale->scaleitems); // Have the highest grade scale item appear first.
$scale->isnumeric = false;
$scale->name = $scalerecord->name;
$scale->courseid = $scalerecord->courseid;
$scale->max = count($scale->scaleitems);
}
} else {
// Generate an array of values for numeric scales.
for ($i = 0; $i <= (int)$scaleid; $i++) {
$scale->scaleitems[(string)$i] = $i;
}
}
$this->scales['s'.$scaleid] = $scale;
}
return $this->scales['s'.$scaleid];
}
|
php
|
protected function generate_rating_scale_object($scaleid) {
global $DB;
if (!array_key_exists('s'.$scaleid, $this->scales)) {
$scale = new stdClass;
$scale->id = $scaleid;
$scale->name = null;
$scale->courseid = null;
$scale->scaleitems = array();
$scale->isnumeric = true;
$scale->max = $scaleid;
if ($scaleid < 0) {
// It is a proper scale (not numeric).
$scalerecord = $DB->get_record('scale', array('id' => abs($scaleid)));
if ($scalerecord) {
// We need to generate an array with string keys starting at 1.
$scalearray = explode(',', $scalerecord->scale);
$c = count($scalearray);
for ($i = 0; $i < $c; $i++) {
// Treat index as a string to allow sorting without changing the value.
$scale->scaleitems[(string)($i + 1)] = $scalearray[$i];
}
krsort($scale->scaleitems); // Have the highest grade scale item appear first.
$scale->isnumeric = false;
$scale->name = $scalerecord->name;
$scale->courseid = $scalerecord->courseid;
$scale->max = count($scale->scaleitems);
}
} else {
// Generate an array of values for numeric scales.
for ($i = 0; $i <= (int)$scaleid; $i++) {
$scale->scaleitems[(string)$i] = $i;
}
}
$this->scales['s'.$scaleid] = $scale;
}
return $this->scales['s'.$scaleid];
}
|
[
"protected",
"function",
"generate_rating_scale_object",
"(",
"$",
"scaleid",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"'s'",
".",
"$",
"scaleid",
",",
"$",
"this",
"->",
"scales",
")",
")",
"{",
"$",
"scale",
"=",
"new",
"stdClass",
";",
"$",
"scale",
"->",
"id",
"=",
"$",
"scaleid",
";",
"$",
"scale",
"->",
"name",
"=",
"null",
";",
"$",
"scale",
"->",
"courseid",
"=",
"null",
";",
"$",
"scale",
"->",
"scaleitems",
"=",
"array",
"(",
")",
";",
"$",
"scale",
"->",
"isnumeric",
"=",
"true",
";",
"$",
"scale",
"->",
"max",
"=",
"$",
"scaleid",
";",
"if",
"(",
"$",
"scaleid",
"<",
"0",
")",
"{",
"// It is a proper scale (not numeric).",
"$",
"scalerecord",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'scale'",
",",
"array",
"(",
"'id'",
"=>",
"abs",
"(",
"$",
"scaleid",
")",
")",
")",
";",
"if",
"(",
"$",
"scalerecord",
")",
"{",
"// We need to generate an array with string keys starting at 1.",
"$",
"scalearray",
"=",
"explode",
"(",
"','",
",",
"$",
"scalerecord",
"->",
"scale",
")",
";",
"$",
"c",
"=",
"count",
"(",
"$",
"scalearray",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"c",
";",
"$",
"i",
"++",
")",
"{",
"// Treat index as a string to allow sorting without changing the value.",
"$",
"scale",
"->",
"scaleitems",
"[",
"(",
"string",
")",
"(",
"$",
"i",
"+",
"1",
")",
"]",
"=",
"$",
"scalearray",
"[",
"$",
"i",
"]",
";",
"}",
"krsort",
"(",
"$",
"scale",
"->",
"scaleitems",
")",
";",
"// Have the highest grade scale item appear first.",
"$",
"scale",
"->",
"isnumeric",
"=",
"false",
";",
"$",
"scale",
"->",
"name",
"=",
"$",
"scalerecord",
"->",
"name",
";",
"$",
"scale",
"->",
"courseid",
"=",
"$",
"scalerecord",
"->",
"courseid",
";",
"$",
"scale",
"->",
"max",
"=",
"count",
"(",
"$",
"scale",
"->",
"scaleitems",
")",
";",
"}",
"}",
"else",
"{",
"// Generate an array of values for numeric scales.",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<=",
"(",
"int",
")",
"$",
"scaleid",
";",
"$",
"i",
"++",
")",
"{",
"$",
"scale",
"->",
"scaleitems",
"[",
"(",
"string",
")",
"$",
"i",
"]",
"=",
"$",
"i",
";",
"}",
"}",
"$",
"this",
"->",
"scales",
"[",
"'s'",
".",
"$",
"scaleid",
"]",
"=",
"$",
"scale",
";",
"}",
"return",
"$",
"this",
"->",
"scales",
"[",
"'s'",
".",
"$",
"scaleid",
"]",
";",
"}"
] |
Generates a scale object that can be returned
@global moodle_database $DB moodle database object
@param int $scaleid scale-type identifier
@return stdClass scale for ratings
|
[
"Generates",
"a",
"scale",
"object",
"that",
"can",
"be",
"returned"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/rating/lib.php#L706-L743
|
220,145
|
moodle/moodle
|
rating/lib.php
|
rating_manager.get_item_time_created
|
protected function get_item_time_created($item) {
if (!empty($item->created)) {
return $item->created; // The forum_posts table has created instead of timecreated.
} else if (!empty($item->timecreated)) {
return $item->timecreated;
} else {
return null;
}
}
|
php
|
protected function get_item_time_created($item) {
if (!empty($item->created)) {
return $item->created; // The forum_posts table has created instead of timecreated.
} else if (!empty($item->timecreated)) {
return $item->timecreated;
} else {
return null;
}
}
|
[
"protected",
"function",
"get_item_time_created",
"(",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"item",
"->",
"created",
")",
")",
"{",
"return",
"$",
"item",
"->",
"created",
";",
"// The forum_posts table has created instead of timecreated.",
"}",
"else",
"if",
"(",
"!",
"empty",
"(",
"$",
"item",
"->",
"timecreated",
")",
")",
"{",
"return",
"$",
"item",
"->",
"timecreated",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] |
Gets the time the given item was created
TODO: MDL-31511 - Find a better solution for this, its not ideal to test for fields really we should be
asking the component the item belongs to what field to look for or even the value we
are looking for.
@param stdClass $item
@return int|null return null if the created time is unavailable, otherwise return a timestamp
|
[
"Gets",
"the",
"time",
"the",
"given",
"item",
"was",
"created"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/rating/lib.php#L755-L763
|
220,146
|
moodle/moodle
|
rating/lib.php
|
rating_manager.get_aggregate_types
|
public function get_aggregate_types() {
return array (RATING_AGGREGATE_NONE => get_string('aggregatenone', 'rating'),
RATING_AGGREGATE_AVERAGE => get_string('aggregateavg', 'rating'),
RATING_AGGREGATE_COUNT => get_string('aggregatecount', 'rating'),
RATING_AGGREGATE_MAXIMUM => get_string('aggregatemax', 'rating'),
RATING_AGGREGATE_MINIMUM => get_string('aggregatemin', 'rating'),
RATING_AGGREGATE_SUM => get_string('aggregatesum', 'rating'));
}
|
php
|
public function get_aggregate_types() {
return array (RATING_AGGREGATE_NONE => get_string('aggregatenone', 'rating'),
RATING_AGGREGATE_AVERAGE => get_string('aggregateavg', 'rating'),
RATING_AGGREGATE_COUNT => get_string('aggregatecount', 'rating'),
RATING_AGGREGATE_MAXIMUM => get_string('aggregatemax', 'rating'),
RATING_AGGREGATE_MINIMUM => get_string('aggregatemin', 'rating'),
RATING_AGGREGATE_SUM => get_string('aggregatesum', 'rating'));
}
|
[
"public",
"function",
"get_aggregate_types",
"(",
")",
"{",
"return",
"array",
"(",
"RATING_AGGREGATE_NONE",
"=>",
"get_string",
"(",
"'aggregatenone'",
",",
"'rating'",
")",
",",
"RATING_AGGREGATE_AVERAGE",
"=>",
"get_string",
"(",
"'aggregateavg'",
",",
"'rating'",
")",
",",
"RATING_AGGREGATE_COUNT",
"=>",
"get_string",
"(",
"'aggregatecount'",
",",
"'rating'",
")",
",",
"RATING_AGGREGATE_MAXIMUM",
"=>",
"get_string",
"(",
"'aggregatemax'",
",",
"'rating'",
")",
",",
"RATING_AGGREGATE_MINIMUM",
"=>",
"get_string",
"(",
"'aggregatemin'",
",",
"'rating'",
")",
",",
"RATING_AGGREGATE_SUM",
"=>",
"get_string",
"(",
"'aggregatesum'",
",",
"'rating'",
")",
")",
";",
"}"
] |
Returns array of aggregate types. Used by ratings.
@return array aggregate types
|
[
"Returns",
"array",
"of",
"aggregate",
"types",
".",
"Used",
"by",
"ratings",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/rating/lib.php#L889-L896
|
220,147
|
moodle/moodle
|
rating/lib.php
|
rating_manager.get_aggregation_method
|
public function get_aggregation_method($aggregate) {
$aggregatestr = null;
switch($aggregate){
case RATING_AGGREGATE_AVERAGE:
$aggregatestr = 'AVG';
break;
case RATING_AGGREGATE_COUNT:
$aggregatestr = 'COUNT';
break;
case RATING_AGGREGATE_MAXIMUM:
$aggregatestr = 'MAX';
break;
case RATING_AGGREGATE_MINIMUM:
$aggregatestr = 'MIN';
break;
case RATING_AGGREGATE_SUM:
$aggregatestr = 'SUM';
break;
default:
$aggregatestr = 'AVG'; // Default to this to avoid real breakage - MDL-22270.
debugging('Incorrect call to get_aggregation_method(), incorrect aggregate method ' . $aggregate, DEBUG_DEVELOPER);
}
return $aggregatestr;
}
|
php
|
public function get_aggregation_method($aggregate) {
$aggregatestr = null;
switch($aggregate){
case RATING_AGGREGATE_AVERAGE:
$aggregatestr = 'AVG';
break;
case RATING_AGGREGATE_COUNT:
$aggregatestr = 'COUNT';
break;
case RATING_AGGREGATE_MAXIMUM:
$aggregatestr = 'MAX';
break;
case RATING_AGGREGATE_MINIMUM:
$aggregatestr = 'MIN';
break;
case RATING_AGGREGATE_SUM:
$aggregatestr = 'SUM';
break;
default:
$aggregatestr = 'AVG'; // Default to this to avoid real breakage - MDL-22270.
debugging('Incorrect call to get_aggregation_method(), incorrect aggregate method ' . $aggregate, DEBUG_DEVELOPER);
}
return $aggregatestr;
}
|
[
"public",
"function",
"get_aggregation_method",
"(",
"$",
"aggregate",
")",
"{",
"$",
"aggregatestr",
"=",
"null",
";",
"switch",
"(",
"$",
"aggregate",
")",
"{",
"case",
"RATING_AGGREGATE_AVERAGE",
":",
"$",
"aggregatestr",
"=",
"'AVG'",
";",
"break",
";",
"case",
"RATING_AGGREGATE_COUNT",
":",
"$",
"aggregatestr",
"=",
"'COUNT'",
";",
"break",
";",
"case",
"RATING_AGGREGATE_MAXIMUM",
":",
"$",
"aggregatestr",
"=",
"'MAX'",
";",
"break",
";",
"case",
"RATING_AGGREGATE_MINIMUM",
":",
"$",
"aggregatestr",
"=",
"'MIN'",
";",
"break",
";",
"case",
"RATING_AGGREGATE_SUM",
":",
"$",
"aggregatestr",
"=",
"'SUM'",
";",
"break",
";",
"default",
":",
"$",
"aggregatestr",
"=",
"'AVG'",
";",
"// Default to this to avoid real breakage - MDL-22270.",
"debugging",
"(",
"'Incorrect call to get_aggregation_method(), incorrect aggregate method '",
".",
"$",
"aggregate",
",",
"DEBUG_DEVELOPER",
")",
";",
"}",
"return",
"$",
"aggregatestr",
";",
"}"
] |
Converts an aggregation method constant into something that can be included in SQL
@param int $aggregate An aggregation constant. For example, RATING_AGGREGATE_AVERAGE.
@return string an SQL aggregation method
|
[
"Converts",
"an",
"aggregation",
"method",
"constant",
"into",
"something",
"that",
"can",
"be",
"included",
"in",
"SQL"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/rating/lib.php#L904-L927
|
220,148
|
moodle/moodle
|
rating/lib.php
|
rating_manager.check_rating_is_valid
|
public function check_rating_is_valid($params) {
if (!isset($params['context'])) {
throw new coding_exception('The context option is a required option when checking rating validity.');
}
if (!isset($params['component'])) {
throw new coding_exception('The component option is now a required option when checking rating validity');
}
if (!isset($params['ratingarea'])) {
throw new coding_exception('The ratingarea option is now a required option when checking rating validity');
}
if (!isset($params['itemid'])) {
throw new coding_exception('The itemid option is now a required option when checking rating validity');
}
if (!isset($params['scaleid'])) {
throw new coding_exception('The scaleid option is now a required option when checking rating validity');
}
if (!isset($params['rateduserid'])) {
throw new coding_exception('The rateduserid option is now a required option when checking rating validity');
}
list($plugintype, $pluginname) = core_component::normalize_component($params['component']);
// This looks for a function like forum_rating_validate() in mod_forum lib.php
// wrapping the params array in another array as call_user_func_array() expands arrays into multiple arguments.
$isvalid = plugin_callback($plugintype, $pluginname, 'rating', 'validate', array($params), null);
// If null then the callback does not exist.
if ($isvalid === null) {
$isvalid = false;
debugging('rating validation callback not found for component '. clean_param($component, PARAM_ALPHANUMEXT));
}
return $isvalid;
}
|
php
|
public function check_rating_is_valid($params) {
if (!isset($params['context'])) {
throw new coding_exception('The context option is a required option when checking rating validity.');
}
if (!isset($params['component'])) {
throw new coding_exception('The component option is now a required option when checking rating validity');
}
if (!isset($params['ratingarea'])) {
throw new coding_exception('The ratingarea option is now a required option when checking rating validity');
}
if (!isset($params['itemid'])) {
throw new coding_exception('The itemid option is now a required option when checking rating validity');
}
if (!isset($params['scaleid'])) {
throw new coding_exception('The scaleid option is now a required option when checking rating validity');
}
if (!isset($params['rateduserid'])) {
throw new coding_exception('The rateduserid option is now a required option when checking rating validity');
}
list($plugintype, $pluginname) = core_component::normalize_component($params['component']);
// This looks for a function like forum_rating_validate() in mod_forum lib.php
// wrapping the params array in another array as call_user_func_array() expands arrays into multiple arguments.
$isvalid = plugin_callback($plugintype, $pluginname, 'rating', 'validate', array($params), null);
// If null then the callback does not exist.
if ($isvalid === null) {
$isvalid = false;
debugging('rating validation callback not found for component '. clean_param($component, PARAM_ALPHANUMEXT));
}
return $isvalid;
}
|
[
"public",
"function",
"check_rating_is_valid",
"(",
"$",
"params",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"params",
"[",
"'context'",
"]",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The context option is a required option when checking rating validity.'",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"params",
"[",
"'component'",
"]",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The component option is now a required option when checking rating validity'",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"params",
"[",
"'ratingarea'",
"]",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The ratingarea option is now a required option when checking rating validity'",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"params",
"[",
"'itemid'",
"]",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The itemid option is now a required option when checking rating validity'",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"params",
"[",
"'scaleid'",
"]",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The scaleid option is now a required option when checking rating validity'",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"params",
"[",
"'rateduserid'",
"]",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The rateduserid option is now a required option when checking rating validity'",
")",
";",
"}",
"list",
"(",
"$",
"plugintype",
",",
"$",
"pluginname",
")",
"=",
"core_component",
"::",
"normalize_component",
"(",
"$",
"params",
"[",
"'component'",
"]",
")",
";",
"// This looks for a function like forum_rating_validate() in mod_forum lib.php",
"// wrapping the params array in another array as call_user_func_array() expands arrays into multiple arguments.",
"$",
"isvalid",
"=",
"plugin_callback",
"(",
"$",
"plugintype",
",",
"$",
"pluginname",
",",
"'rating'",
",",
"'validate'",
",",
"array",
"(",
"$",
"params",
")",
",",
"null",
")",
";",
"// If null then the callback does not exist.",
"if",
"(",
"$",
"isvalid",
"===",
"null",
")",
"{",
"$",
"isvalid",
"=",
"false",
";",
"debugging",
"(",
"'rating validation callback not found for component '",
".",
"clean_param",
"(",
"$",
"component",
",",
"PARAM_ALPHANUMEXT",
")",
")",
";",
"}",
"return",
"$",
"isvalid",
";",
"}"
] |
Validates a submitted rating
@param array $params submitted data
context => object the context in which the rated items exists [required]
component => The component the rating belongs to [required]
ratingarea => The ratingarea the rating is associated with [required]
itemid => int the ID of the object being rated [required]
scaleid => int the scale from which the user can select a rating. Used for bounds checking. [required]
rating => int the submitted rating
rateduserid => int the id of the user whose items have been rated. 0 to update all. [required]
aggregation => int the aggregation method to apply when calculating grades ie RATING_AGGREGATE_AVERAGE [optional]
@return boolean true if the rating is valid, false if callback not found, throws rating_exception if rating is invalid
|
[
"Validates",
"a",
"submitted",
"rating"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/rating/lib.php#L969-L1002
|
220,149
|
moodle/moodle
|
rating/lib.php
|
rating_manager.initialise_rating_javascript
|
public function initialise_rating_javascript(moodle_page $page) {
global $CFG;
// Only needs to be initialized once.
static $done = false;
if ($done) {
return true;
}
$page->requires->js_init_call('M.core_rating.init');
$done = true;
return true;
}
|
php
|
public function initialise_rating_javascript(moodle_page $page) {
global $CFG;
// Only needs to be initialized once.
static $done = false;
if ($done) {
return true;
}
$page->requires->js_init_call('M.core_rating.init');
$done = true;
return true;
}
|
[
"public",
"function",
"initialise_rating_javascript",
"(",
"moodle_page",
"$",
"page",
")",
"{",
"global",
"$",
"CFG",
";",
"// Only needs to be initialized once.",
"static",
"$",
"done",
"=",
"false",
";",
"if",
"(",
"$",
"done",
")",
"{",
"return",
"true",
";",
"}",
"$",
"page",
"->",
"requires",
"->",
"js_init_call",
"(",
"'M.core_rating.init'",
")",
";",
"$",
"done",
"=",
"true",
";",
"return",
"true",
";",
"}"
] |
Initialises JavaScript to enable AJAX ratings on the provided page
@param moodle_page $page
@return true always returns true
|
[
"Initialises",
"JavaScript",
"to",
"enable",
"AJAX",
"ratings",
"on",
"the",
"provided",
"page"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/rating/lib.php#L1010-L1023
|
220,150
|
moodle/moodle
|
rating/lib.php
|
rating_manager.get_aggregate_label
|
public function get_aggregate_label($aggregationmethod) {
$aggregatelabel = '';
switch ($aggregationmethod) {
case RATING_AGGREGATE_AVERAGE :
$aggregatelabel .= get_string("aggregateavg", "rating");
break;
case RATING_AGGREGATE_COUNT :
$aggregatelabel .= get_string("aggregatecount", "rating");
break;
case RATING_AGGREGATE_MAXIMUM :
$aggregatelabel .= get_string("aggregatemax", "rating");
break;
case RATING_AGGREGATE_MINIMUM :
$aggregatelabel .= get_string("aggregatemin", "rating");
break;
case RATING_AGGREGATE_SUM :
$aggregatelabel .= get_string("aggregatesum", "rating");
break;
}
$aggregatelabel .= get_string('labelsep', 'langconfig');
return $aggregatelabel;
}
|
php
|
public function get_aggregate_label($aggregationmethod) {
$aggregatelabel = '';
switch ($aggregationmethod) {
case RATING_AGGREGATE_AVERAGE :
$aggregatelabel .= get_string("aggregateavg", "rating");
break;
case RATING_AGGREGATE_COUNT :
$aggregatelabel .= get_string("aggregatecount", "rating");
break;
case RATING_AGGREGATE_MAXIMUM :
$aggregatelabel .= get_string("aggregatemax", "rating");
break;
case RATING_AGGREGATE_MINIMUM :
$aggregatelabel .= get_string("aggregatemin", "rating");
break;
case RATING_AGGREGATE_SUM :
$aggregatelabel .= get_string("aggregatesum", "rating");
break;
}
$aggregatelabel .= get_string('labelsep', 'langconfig');
return $aggregatelabel;
}
|
[
"public",
"function",
"get_aggregate_label",
"(",
"$",
"aggregationmethod",
")",
"{",
"$",
"aggregatelabel",
"=",
"''",
";",
"switch",
"(",
"$",
"aggregationmethod",
")",
"{",
"case",
"RATING_AGGREGATE_AVERAGE",
":",
"$",
"aggregatelabel",
".=",
"get_string",
"(",
"\"aggregateavg\"",
",",
"\"rating\"",
")",
";",
"break",
";",
"case",
"RATING_AGGREGATE_COUNT",
":",
"$",
"aggregatelabel",
".=",
"get_string",
"(",
"\"aggregatecount\"",
",",
"\"rating\"",
")",
";",
"break",
";",
"case",
"RATING_AGGREGATE_MAXIMUM",
":",
"$",
"aggregatelabel",
".=",
"get_string",
"(",
"\"aggregatemax\"",
",",
"\"rating\"",
")",
";",
"break",
";",
"case",
"RATING_AGGREGATE_MINIMUM",
":",
"$",
"aggregatelabel",
".=",
"get_string",
"(",
"\"aggregatemin\"",
",",
"\"rating\"",
")",
";",
"break",
";",
"case",
"RATING_AGGREGATE_SUM",
":",
"$",
"aggregatelabel",
".=",
"get_string",
"(",
"\"aggregatesum\"",
",",
"\"rating\"",
")",
";",
"break",
";",
"}",
"$",
"aggregatelabel",
".=",
"get_string",
"(",
"'labelsep'",
",",
"'langconfig'",
")",
";",
"return",
"$",
"aggregatelabel",
";",
"}"
] |
Returns a string that describes the aggregation method that was provided.
@param string $aggregationmethod
@return string describes the aggregation method that was provided
|
[
"Returns",
"a",
"string",
"that",
"describes",
"the",
"aggregation",
"method",
"that",
"was",
"provided",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/rating/lib.php#L1031-L1052
|
220,151
|
moodle/moodle
|
rating/lib.php
|
rating_manager.get_component_ratings_since
|
public function get_component_ratings_since($context, $component, $since) {
global $DB, $USER;
$ratingssince = array();
$where = 'contextid = ? AND component = ? AND (timecreated > ? OR timemodified > ?)';
$ratings = $DB->get_records_select('rating', $where, array($context->id, $component, $since, $since));
// Check area by area if we have permissions.
$permissions = array();
$rm = new rating_manager();
foreach ($ratings as $rating) {
// Check if the permission array for the area is cached.
if (!isset($permissions[$rating->ratingarea])) {
$permissions[$rating->ratingarea] = $rm->get_plugin_permissions_array($context->id, $component,
$rating->ratingarea);
}
if (($permissions[$rating->ratingarea]['view'] and $rating->userid == $USER->id) or
($permissions[$rating->ratingarea]['viewany'] or $permissions[$rating->ratingarea]['viewall'])) {
$ratingssince[$rating->id] = $rating;
}
}
return $ratingssince;
}
|
php
|
public function get_component_ratings_since($context, $component, $since) {
global $DB, $USER;
$ratingssince = array();
$where = 'contextid = ? AND component = ? AND (timecreated > ? OR timemodified > ?)';
$ratings = $DB->get_records_select('rating', $where, array($context->id, $component, $since, $since));
// Check area by area if we have permissions.
$permissions = array();
$rm = new rating_manager();
foreach ($ratings as $rating) {
// Check if the permission array for the area is cached.
if (!isset($permissions[$rating->ratingarea])) {
$permissions[$rating->ratingarea] = $rm->get_plugin_permissions_array($context->id, $component,
$rating->ratingarea);
}
if (($permissions[$rating->ratingarea]['view'] and $rating->userid == $USER->id) or
($permissions[$rating->ratingarea]['viewany'] or $permissions[$rating->ratingarea]['viewall'])) {
$ratingssince[$rating->id] = $rating;
}
}
return $ratingssince;
}
|
[
"public",
"function",
"get_component_ratings_since",
"(",
"$",
"context",
",",
"$",
"component",
",",
"$",
"since",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"USER",
";",
"$",
"ratingssince",
"=",
"array",
"(",
")",
";",
"$",
"where",
"=",
"'contextid = ? AND component = ? AND (timecreated > ? OR timemodified > ?)'",
";",
"$",
"ratings",
"=",
"$",
"DB",
"->",
"get_records_select",
"(",
"'rating'",
",",
"$",
"where",
",",
"array",
"(",
"$",
"context",
"->",
"id",
",",
"$",
"component",
",",
"$",
"since",
",",
"$",
"since",
")",
")",
";",
"// Check area by area if we have permissions.",
"$",
"permissions",
"=",
"array",
"(",
")",
";",
"$",
"rm",
"=",
"new",
"rating_manager",
"(",
")",
";",
"foreach",
"(",
"$",
"ratings",
"as",
"$",
"rating",
")",
"{",
"// Check if the permission array for the area is cached.",
"if",
"(",
"!",
"isset",
"(",
"$",
"permissions",
"[",
"$",
"rating",
"->",
"ratingarea",
"]",
")",
")",
"{",
"$",
"permissions",
"[",
"$",
"rating",
"->",
"ratingarea",
"]",
"=",
"$",
"rm",
"->",
"get_plugin_permissions_array",
"(",
"$",
"context",
"->",
"id",
",",
"$",
"component",
",",
"$",
"rating",
"->",
"ratingarea",
")",
";",
"}",
"if",
"(",
"(",
"$",
"permissions",
"[",
"$",
"rating",
"->",
"ratingarea",
"]",
"[",
"'view'",
"]",
"and",
"$",
"rating",
"->",
"userid",
"==",
"$",
"USER",
"->",
"id",
")",
"or",
"(",
"$",
"permissions",
"[",
"$",
"rating",
"->",
"ratingarea",
"]",
"[",
"'viewany'",
"]",
"or",
"$",
"permissions",
"[",
"$",
"rating",
"->",
"ratingarea",
"]",
"[",
"'viewall'",
"]",
")",
")",
"{",
"$",
"ratingssince",
"[",
"$",
"rating",
"->",
"id",
"]",
"=",
"$",
"rating",
";",
"}",
"}",
"return",
"$",
"ratingssince",
";",
"}"
] |
Get ratings created since a given time.
@param stdClass $context context object
@param string $component component name
@param int $since the time to check
@return array list of ratings db records since the given timelimit
@since Moodle 3.2
|
[
"Get",
"ratings",
"created",
"since",
"a",
"given",
"time",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/rating/lib.php#L1187-L1210
|
220,152
|
moodle/moodle
|
admin/tool/lp/classes/output/template_plans_table.php
|
template_plans_table.col_name
|
protected function col_name($row) {
return html_writer::link(new moodle_url('/admin/tool/lp/plan.php', array('id' => $row->id)),
format_string($row->name, true, array('context' => $this->context)));
}
|
php
|
protected function col_name($row) {
return html_writer::link(new moodle_url('/admin/tool/lp/plan.php', array('id' => $row->id)),
format_string($row->name, true, array('context' => $this->context)));
}
|
[
"protected",
"function",
"col_name",
"(",
"$",
"row",
")",
"{",
"return",
"html_writer",
"::",
"link",
"(",
"new",
"moodle_url",
"(",
"'/admin/tool/lp/plan.php'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"row",
"->",
"id",
")",
")",
",",
"format_string",
"(",
"$",
"row",
"->",
"name",
",",
"true",
",",
"array",
"(",
"'context'",
"=>",
"$",
"this",
"->",
"context",
")",
")",
")",
";",
"}"
] |
Format column name.
@param stdClass $row
@return string
|
[
"Format",
"column",
"name",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lp/classes/output/template_plans_table.php#L86-L89
|
220,153
|
moodle/moodle
|
lib/classes/analytics/analyser/courses.php
|
courses.get_all_samples
|
public function get_all_samples(\core_analytics\analysable $course) {
$context = \context_course::instance($course->get_id());
// Just 1 sample per analysable.
return array(
array($course->get_id() => $course->get_id()),
array($course->get_id() => array('course' => $course->get_course_data(), 'context' => $context))
);
}
|
php
|
public function get_all_samples(\core_analytics\analysable $course) {
$context = \context_course::instance($course->get_id());
// Just 1 sample per analysable.
return array(
array($course->get_id() => $course->get_id()),
array($course->get_id() => array('course' => $course->get_course_data(), 'context' => $context))
);
}
|
[
"public",
"function",
"get_all_samples",
"(",
"\\",
"core_analytics",
"\\",
"analysable",
"$",
"course",
")",
"{",
"$",
"context",
"=",
"\\",
"context_course",
"::",
"instance",
"(",
"$",
"course",
"->",
"get_id",
"(",
")",
")",
";",
"// Just 1 sample per analysable.",
"return",
"array",
"(",
"array",
"(",
"$",
"course",
"->",
"get_id",
"(",
")",
"=>",
"$",
"course",
"->",
"get_id",
"(",
")",
")",
",",
"array",
"(",
"$",
"course",
"->",
"get_id",
"(",
")",
"=>",
"array",
"(",
"'course'",
"=>",
"$",
"course",
"->",
"get_course_data",
"(",
")",
",",
"'context'",
"=>",
"$",
"context",
")",
")",
")",
";",
"}"
] |
This will return just one course as we analyse 'by_course'.
@param \core_analytics\analysable $course
@return array
|
[
"This",
"will",
"return",
"just",
"one",
"course",
"as",
"we",
"analyse",
"by_course",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/analytics/analyser/courses.php#L91-L100
|
220,154
|
moodle/moodle
|
repository/flickr_public/lib.php
|
repository_flickr_public.print_login
|
public function print_login() {
if ($this->options['ajax']) {
$ret = array();
$fulltext = new stdClass();
$fulltext->label = get_string('fulltext', 'repository_flickr_public').': ';
$fulltext->id = 'el_fulltext';
$fulltext->type = 'text';
$fulltext->name = 'flickr_fulltext';
$tag = new stdClass();
$tag->label = get_string('tag', 'repository_flickr_public').': ';
$tag->id = 'el_tag';
$tag->type = 'text';
$tag->name = 'flickr_tag';
$email_field = new stdClass();
$email_field->label = get_string('username', 'repository_flickr_public').': ';
$email_field->id = 'account';
$email_field->type = 'text';
$email_field->name = 'flickr_account';
$commercial = new stdClass();
$commercial->label = get_string('commercialuse', 'repository_flickr_public').': ';
$commercial->id = 'flickr_commercial_id';
$commercial->type = 'checkbox';
$commercial->name = 'flickr_commercial';
$commercial->value = 'yes';
$modification = new stdClass();
$modification->label = get_string('modification', 'repository_flickr_public').': ';
$modification->id = 'flickr_modification_id';
$modification->type = 'checkbox';
$modification->name = 'flickr_modification';
$modification->value = 'yes';
$ret['login'] = array($fulltext, $tag, $email_field, $commercial, $modification);
$ret['login_btn_label'] = get_string('search');
$ret['login_btn_action'] = 'search';
return $ret;
} else {
echo '<table>';
echo '<tr><td><label>'.get_string('fulltext', 'repository_flickr_public').'</label></td>';
echo '<td><input type="text" name="flickr_fulltext" /></td></tr>';
echo '<tr><td><label>'.get_string('tag', 'repository_flickr_public').'</label></td>';
echo '<td><input type="text" name="flickr_tag" /></td></tr>';
echo '<tr><td><label>'.get_string('username', 'repository_flickr_public').'</label></td>';
echo '<td><input type="text" name="flickr_account" /></td></tr>';
echo '<tr><td><label>'.get_string('commercialuse', 'repository_flickr_public').'</label></td>';
echo '<td>';
echo '<input type="checkbox" name="flickr_commercial" value="yes" />';
echo '</td></tr>';
echo '<tr><td><label>'.get_string('modification', 'repository_flickr_public').'</label></td>';
echo '<td>';
echo '<input type="checkbox" name="flickr_modification" value="yes" />';
echo '</td></tr>';
echo '</table>';
echo '<input type="hidden" name="action" value="search" />';
echo '<input type="submit" value="'.get_string('search', 'repository').'" />';
}
}
|
php
|
public function print_login() {
if ($this->options['ajax']) {
$ret = array();
$fulltext = new stdClass();
$fulltext->label = get_string('fulltext', 'repository_flickr_public').': ';
$fulltext->id = 'el_fulltext';
$fulltext->type = 'text';
$fulltext->name = 'flickr_fulltext';
$tag = new stdClass();
$tag->label = get_string('tag', 'repository_flickr_public').': ';
$tag->id = 'el_tag';
$tag->type = 'text';
$tag->name = 'flickr_tag';
$email_field = new stdClass();
$email_field->label = get_string('username', 'repository_flickr_public').': ';
$email_field->id = 'account';
$email_field->type = 'text';
$email_field->name = 'flickr_account';
$commercial = new stdClass();
$commercial->label = get_string('commercialuse', 'repository_flickr_public').': ';
$commercial->id = 'flickr_commercial_id';
$commercial->type = 'checkbox';
$commercial->name = 'flickr_commercial';
$commercial->value = 'yes';
$modification = new stdClass();
$modification->label = get_string('modification', 'repository_flickr_public').': ';
$modification->id = 'flickr_modification_id';
$modification->type = 'checkbox';
$modification->name = 'flickr_modification';
$modification->value = 'yes';
$ret['login'] = array($fulltext, $tag, $email_field, $commercial, $modification);
$ret['login_btn_label'] = get_string('search');
$ret['login_btn_action'] = 'search';
return $ret;
} else {
echo '<table>';
echo '<tr><td><label>'.get_string('fulltext', 'repository_flickr_public').'</label></td>';
echo '<td><input type="text" name="flickr_fulltext" /></td></tr>';
echo '<tr><td><label>'.get_string('tag', 'repository_flickr_public').'</label></td>';
echo '<td><input type="text" name="flickr_tag" /></td></tr>';
echo '<tr><td><label>'.get_string('username', 'repository_flickr_public').'</label></td>';
echo '<td><input type="text" name="flickr_account" /></td></tr>';
echo '<tr><td><label>'.get_string('commercialuse', 'repository_flickr_public').'</label></td>';
echo '<td>';
echo '<input type="checkbox" name="flickr_commercial" value="yes" />';
echo '</td></tr>';
echo '<tr><td><label>'.get_string('modification', 'repository_flickr_public').'</label></td>';
echo '<td>';
echo '<input type="checkbox" name="flickr_modification" value="yes" />';
echo '</td></tr>';
echo '</table>';
echo '<input type="hidden" name="action" value="search" />';
echo '<input type="submit" value="'.get_string('search', 'repository').'" />';
}
}
|
[
"public",
"function",
"print_login",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"options",
"[",
"'ajax'",
"]",
")",
"{",
"$",
"ret",
"=",
"array",
"(",
")",
";",
"$",
"fulltext",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"fulltext",
"->",
"label",
"=",
"get_string",
"(",
"'fulltext'",
",",
"'repository_flickr_public'",
")",
".",
"': '",
";",
"$",
"fulltext",
"->",
"id",
"=",
"'el_fulltext'",
";",
"$",
"fulltext",
"->",
"type",
"=",
"'text'",
";",
"$",
"fulltext",
"->",
"name",
"=",
"'flickr_fulltext'",
";",
"$",
"tag",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"tag",
"->",
"label",
"=",
"get_string",
"(",
"'tag'",
",",
"'repository_flickr_public'",
")",
".",
"': '",
";",
"$",
"tag",
"->",
"id",
"=",
"'el_tag'",
";",
"$",
"tag",
"->",
"type",
"=",
"'text'",
";",
"$",
"tag",
"->",
"name",
"=",
"'flickr_tag'",
";",
"$",
"email_field",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"email_field",
"->",
"label",
"=",
"get_string",
"(",
"'username'",
",",
"'repository_flickr_public'",
")",
".",
"': '",
";",
"$",
"email_field",
"->",
"id",
"=",
"'account'",
";",
"$",
"email_field",
"->",
"type",
"=",
"'text'",
";",
"$",
"email_field",
"->",
"name",
"=",
"'flickr_account'",
";",
"$",
"commercial",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"commercial",
"->",
"label",
"=",
"get_string",
"(",
"'commercialuse'",
",",
"'repository_flickr_public'",
")",
".",
"': '",
";",
"$",
"commercial",
"->",
"id",
"=",
"'flickr_commercial_id'",
";",
"$",
"commercial",
"->",
"type",
"=",
"'checkbox'",
";",
"$",
"commercial",
"->",
"name",
"=",
"'flickr_commercial'",
";",
"$",
"commercial",
"->",
"value",
"=",
"'yes'",
";",
"$",
"modification",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"modification",
"->",
"label",
"=",
"get_string",
"(",
"'modification'",
",",
"'repository_flickr_public'",
")",
".",
"': '",
";",
"$",
"modification",
"->",
"id",
"=",
"'flickr_modification_id'",
";",
"$",
"modification",
"->",
"type",
"=",
"'checkbox'",
";",
"$",
"modification",
"->",
"name",
"=",
"'flickr_modification'",
";",
"$",
"modification",
"->",
"value",
"=",
"'yes'",
";",
"$",
"ret",
"[",
"'login'",
"]",
"=",
"array",
"(",
"$",
"fulltext",
",",
"$",
"tag",
",",
"$",
"email_field",
",",
"$",
"commercial",
",",
"$",
"modification",
")",
";",
"$",
"ret",
"[",
"'login_btn_label'",
"]",
"=",
"get_string",
"(",
"'search'",
")",
";",
"$",
"ret",
"[",
"'login_btn_action'",
"]",
"=",
"'search'",
";",
"return",
"$",
"ret",
";",
"}",
"else",
"{",
"echo",
"'<table>'",
";",
"echo",
"'<tr><td><label>'",
".",
"get_string",
"(",
"'fulltext'",
",",
"'repository_flickr_public'",
")",
".",
"'</label></td>'",
";",
"echo",
"'<td><input type=\"text\" name=\"flickr_fulltext\" /></td></tr>'",
";",
"echo",
"'<tr><td><label>'",
".",
"get_string",
"(",
"'tag'",
",",
"'repository_flickr_public'",
")",
".",
"'</label></td>'",
";",
"echo",
"'<td><input type=\"text\" name=\"flickr_tag\" /></td></tr>'",
";",
"echo",
"'<tr><td><label>'",
".",
"get_string",
"(",
"'username'",
",",
"'repository_flickr_public'",
")",
".",
"'</label></td>'",
";",
"echo",
"'<td><input type=\"text\" name=\"flickr_account\" /></td></tr>'",
";",
"echo",
"'<tr><td><label>'",
".",
"get_string",
"(",
"'commercialuse'",
",",
"'repository_flickr_public'",
")",
".",
"'</label></td>'",
";",
"echo",
"'<td>'",
";",
"echo",
"'<input type=\"checkbox\" name=\"flickr_commercial\" value=\"yes\" />'",
";",
"echo",
"'</td></tr>'",
";",
"echo",
"'<tr><td><label>'",
".",
"get_string",
"(",
"'modification'",
",",
"'repository_flickr_public'",
")",
".",
"'</label></td>'",
";",
"echo",
"'<td>'",
";",
"echo",
"'<input type=\"checkbox\" name=\"flickr_modification\" value=\"yes\" />'",
";",
"echo",
"'</td></tr>'",
";",
"echo",
"'</table>'",
";",
"echo",
"'<input type=\"hidden\" name=\"action\" value=\"search\" />'",
";",
"echo",
"'<input type=\"submit\" value=\"'",
".",
"get_string",
"(",
"'search'",
",",
"'repository'",
")",
".",
"'\" />'",
";",
"}",
"}"
] |
construct login form
@param boolean $ajax
@return array
|
[
"construct",
"login",
"form"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/flickr_public/lib.php#L141-L204
|
220,155
|
moodle/moodle
|
repository/flickr_public/lib.php
|
repository_flickr_public.get_listing
|
public function get_listing($path = '', $page = 1) {
$people = $this->flickr->people_findByEmail($this->flickr_account);
$this->nsid = $people['nsid'];
$photos = $this->flickr->people_getPublicPhotos($people['nsid'], 'original_format', 24, $page);
$ret = array();
return $this->build_list($photos, $page, $ret);
}
|
php
|
public function get_listing($path = '', $page = 1) {
$people = $this->flickr->people_findByEmail($this->flickr_account);
$this->nsid = $people['nsid'];
$photos = $this->flickr->people_getPublicPhotos($people['nsid'], 'original_format', 24, $page);
$ret = array();
return $this->build_list($photos, $page, $ret);
}
|
[
"public",
"function",
"get_listing",
"(",
"$",
"path",
"=",
"''",
",",
"$",
"page",
"=",
"1",
")",
"{",
"$",
"people",
"=",
"$",
"this",
"->",
"flickr",
"->",
"people_findByEmail",
"(",
"$",
"this",
"->",
"flickr_account",
")",
";",
"$",
"this",
"->",
"nsid",
"=",
"$",
"people",
"[",
"'nsid'",
"]",
";",
"$",
"photos",
"=",
"$",
"this",
"->",
"flickr",
"->",
"people_getPublicPhotos",
"(",
"$",
"people",
"[",
"'nsid'",
"]",
",",
"'original_format'",
",",
"24",
",",
"$",
"page",
")",
";",
"$",
"ret",
"=",
"array",
"(",
")",
";",
"return",
"$",
"this",
"->",
"build_list",
"(",
"$",
"photos",
",",
"$",
"page",
",",
"$",
"ret",
")",
";",
"}"
] |
return an image list
@param string $path
@param int $page
@return array
|
[
"return",
"an",
"image",
"list"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/flickr_public/lib.php#L326-L333
|
220,156
|
moodle/moodle
|
repository/flickr_public/lib.php
|
repository_flickr_public.build_list
|
private function build_list($photos, $page = 1, &$ret) {
if (!empty($this->nsid)) {
$photos_url = $this->flickr->urls_getUserPhotos($this->nsid);
$ret['manage'] = $photos_url;
}
$ret['list'] = array();
$ret['nosearch'] = true;
$ret['norefresh'] = true;
$ret['logouttext'] = get_string('backtosearch', 'repository_flickr_public');
$ret['pages'] = $photos['pages'];
if (is_int($page) && $page <= $ret['pages']) {
$ret['page'] = $page;
} else {
$ret['page'] = 1;
}
if (!empty($photos['photo'])) {
foreach ($photos['photo'] as $p) {
if(empty($p['title'])) {
$p['title'] = get_string('notitle', 'repository_flickr');
}
if (isset($p['originalformat'])) {
$format = $p['originalformat'];
} else {
$format = 'jpg';
}
$format = '.'.$format;
if (substr($p['title'], strlen($p['title'])-strlen($format)) != $format) {
// append author id
// $p['title'] .= '-'.$p['owner'];
// append file extension
$p['title'] .= $format;
}
$ret['list'][] = array(
'title'=>$p['title'],
'source'=>$p['id'],
'id'=>$p['id'],
'thumbnail'=>$this->flickr->buildPhotoURL($p, 'Square'),
'date'=>'',
'size'=>'unknown',
'url'=>'http://www.flickr.com/photos/'.$p['owner'].'/'.$p['id'],
'haslicense'=>true,
'hasauthor'=>true
);
}
}
return $ret;
}
|
php
|
private function build_list($photos, $page = 1, &$ret) {
if (!empty($this->nsid)) {
$photos_url = $this->flickr->urls_getUserPhotos($this->nsid);
$ret['manage'] = $photos_url;
}
$ret['list'] = array();
$ret['nosearch'] = true;
$ret['norefresh'] = true;
$ret['logouttext'] = get_string('backtosearch', 'repository_flickr_public');
$ret['pages'] = $photos['pages'];
if (is_int($page) && $page <= $ret['pages']) {
$ret['page'] = $page;
} else {
$ret['page'] = 1;
}
if (!empty($photos['photo'])) {
foreach ($photos['photo'] as $p) {
if(empty($p['title'])) {
$p['title'] = get_string('notitle', 'repository_flickr');
}
if (isset($p['originalformat'])) {
$format = $p['originalformat'];
} else {
$format = 'jpg';
}
$format = '.'.$format;
if (substr($p['title'], strlen($p['title'])-strlen($format)) != $format) {
// append author id
// $p['title'] .= '-'.$p['owner'];
// append file extension
$p['title'] .= $format;
}
$ret['list'][] = array(
'title'=>$p['title'],
'source'=>$p['id'],
'id'=>$p['id'],
'thumbnail'=>$this->flickr->buildPhotoURL($p, 'Square'),
'date'=>'',
'size'=>'unknown',
'url'=>'http://www.flickr.com/photos/'.$p['owner'].'/'.$p['id'],
'haslicense'=>true,
'hasauthor'=>true
);
}
}
return $ret;
}
|
[
"private",
"function",
"build_list",
"(",
"$",
"photos",
",",
"$",
"page",
"=",
"1",
",",
"&",
"$",
"ret",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"nsid",
")",
")",
"{",
"$",
"photos_url",
"=",
"$",
"this",
"->",
"flickr",
"->",
"urls_getUserPhotos",
"(",
"$",
"this",
"->",
"nsid",
")",
";",
"$",
"ret",
"[",
"'manage'",
"]",
"=",
"$",
"photos_url",
";",
"}",
"$",
"ret",
"[",
"'list'",
"]",
"=",
"array",
"(",
")",
";",
"$",
"ret",
"[",
"'nosearch'",
"]",
"=",
"true",
";",
"$",
"ret",
"[",
"'norefresh'",
"]",
"=",
"true",
";",
"$",
"ret",
"[",
"'logouttext'",
"]",
"=",
"get_string",
"(",
"'backtosearch'",
",",
"'repository_flickr_public'",
")",
";",
"$",
"ret",
"[",
"'pages'",
"]",
"=",
"$",
"photos",
"[",
"'pages'",
"]",
";",
"if",
"(",
"is_int",
"(",
"$",
"page",
")",
"&&",
"$",
"page",
"<=",
"$",
"ret",
"[",
"'pages'",
"]",
")",
"{",
"$",
"ret",
"[",
"'page'",
"]",
"=",
"$",
"page",
";",
"}",
"else",
"{",
"$",
"ret",
"[",
"'page'",
"]",
"=",
"1",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"photos",
"[",
"'photo'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"photos",
"[",
"'photo'",
"]",
"as",
"$",
"p",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"p",
"[",
"'title'",
"]",
")",
")",
"{",
"$",
"p",
"[",
"'title'",
"]",
"=",
"get_string",
"(",
"'notitle'",
",",
"'repository_flickr'",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"p",
"[",
"'originalformat'",
"]",
")",
")",
"{",
"$",
"format",
"=",
"$",
"p",
"[",
"'originalformat'",
"]",
";",
"}",
"else",
"{",
"$",
"format",
"=",
"'jpg'",
";",
"}",
"$",
"format",
"=",
"'.'",
".",
"$",
"format",
";",
"if",
"(",
"substr",
"(",
"$",
"p",
"[",
"'title'",
"]",
",",
"strlen",
"(",
"$",
"p",
"[",
"'title'",
"]",
")",
"-",
"strlen",
"(",
"$",
"format",
")",
")",
"!=",
"$",
"format",
")",
"{",
"// append author id",
"// $p['title'] .= '-'.$p['owner'];",
"// append file extension",
"$",
"p",
"[",
"'title'",
"]",
".=",
"$",
"format",
";",
"}",
"$",
"ret",
"[",
"'list'",
"]",
"[",
"]",
"=",
"array",
"(",
"'title'",
"=>",
"$",
"p",
"[",
"'title'",
"]",
",",
"'source'",
"=>",
"$",
"p",
"[",
"'id'",
"]",
",",
"'id'",
"=>",
"$",
"p",
"[",
"'id'",
"]",
",",
"'thumbnail'",
"=>",
"$",
"this",
"->",
"flickr",
"->",
"buildPhotoURL",
"(",
"$",
"p",
",",
"'Square'",
")",
",",
"'date'",
"=>",
"''",
",",
"'size'",
"=>",
"'unknown'",
",",
"'url'",
"=>",
"'http://www.flickr.com/photos/'",
".",
"$",
"p",
"[",
"'owner'",
"]",
".",
"'/'",
".",
"$",
"p",
"[",
"'id'",
"]",
",",
"'haslicense'",
"=>",
"true",
",",
"'hasauthor'",
"=>",
"true",
")",
";",
"}",
"}",
"return",
"$",
"ret",
";",
"}"
] |
build an image list
@param array $photos
@param int $page
@return array
|
[
"build",
"an",
"image",
"list"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/flickr_public/lib.php#L342-L388
|
220,157
|
moodle/moodle
|
repository/flickr_public/lib.php
|
repository_flickr_public.print_search
|
public function print_search() {
$str = '';
$str .= '<input type="hidden" name="repo_id" value="'.$this->id.'" />';
$str .= '<input type="hidden" name="ctx_id" value="'.$this->context->id.'" />';
$str .= '<input type="hidden" name="seekey" value="'.sesskey().'" />';
$str .= '<label>'.get_string('fulltext', 'repository_flickr_public').'</label><br/><input name="s" value="" /><br/>';
$str .= '<label>'.get_string('tag', 'repository_flickr_public').'</label><br /><input type="text" name="flickr_tag" /><br />';
return $str;
}
|
php
|
public function print_search() {
$str = '';
$str .= '<input type="hidden" name="repo_id" value="'.$this->id.'" />';
$str .= '<input type="hidden" name="ctx_id" value="'.$this->context->id.'" />';
$str .= '<input type="hidden" name="seekey" value="'.sesskey().'" />';
$str .= '<label>'.get_string('fulltext', 'repository_flickr_public').'</label><br/><input name="s" value="" /><br/>';
$str .= '<label>'.get_string('tag', 'repository_flickr_public').'</label><br /><input type="text" name="flickr_tag" /><br />';
return $str;
}
|
[
"public",
"function",
"print_search",
"(",
")",
"{",
"$",
"str",
"=",
"''",
";",
"$",
"str",
".=",
"'<input type=\"hidden\" name=\"repo_id\" value=\"'",
".",
"$",
"this",
"->",
"id",
".",
"'\" />'",
";",
"$",
"str",
".=",
"'<input type=\"hidden\" name=\"ctx_id\" value=\"'",
".",
"$",
"this",
"->",
"context",
"->",
"id",
".",
"'\" />'",
";",
"$",
"str",
".=",
"'<input type=\"hidden\" name=\"seekey\" value=\"'",
".",
"sesskey",
"(",
")",
".",
"'\" />'",
";",
"$",
"str",
".=",
"'<label>'",
".",
"get_string",
"(",
"'fulltext'",
",",
"'repository_flickr_public'",
")",
".",
"'</label><br/><input name=\"s\" value=\"\" /><br/>'",
";",
"$",
"str",
".=",
"'<label>'",
".",
"get_string",
"(",
"'tag'",
",",
"'repository_flickr_public'",
")",
".",
"'</label><br /><input type=\"text\" name=\"flickr_tag\" /><br />'",
";",
"return",
"$",
"str",
";",
"}"
] |
Print a search form
@return string
|
[
"Print",
"a",
"search",
"form"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/flickr_public/lib.php#L395-L403
|
220,158
|
moodle/moodle
|
repository/flickr_public/lib.php
|
repository_flickr_public.build_photo_url
|
private function build_photo_url($photoid) {
$bestsize = $this->get_best_size($photoid);
if (!isset($bestsize['source'])) {
throw new repository_exception('cannotdownload', 'repository');
}
return $bestsize['source'];
}
|
php
|
private function build_photo_url($photoid) {
$bestsize = $this->get_best_size($photoid);
if (!isset($bestsize['source'])) {
throw new repository_exception('cannotdownload', 'repository');
}
return $bestsize['source'];
}
|
[
"private",
"function",
"build_photo_url",
"(",
"$",
"photoid",
")",
"{",
"$",
"bestsize",
"=",
"$",
"this",
"->",
"get_best_size",
"(",
"$",
"photoid",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"bestsize",
"[",
"'source'",
"]",
")",
")",
"{",
"throw",
"new",
"repository_exception",
"(",
"'cannotdownload'",
",",
"'repository'",
")",
";",
"}",
"return",
"$",
"bestsize",
"[",
"'source'",
"]",
";",
"}"
] |
Return photo url by given photo id
@param string $photoid
@return string
|
[
"Return",
"photo",
"url",
"by",
"given",
"photo",
"id"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/flickr_public/lib.php#L410-L416
|
220,159
|
moodle/moodle
|
repository/flickr_public/lib.php
|
repository_flickr_public.get_best_size
|
protected function get_best_size($photoid) {
if (!isset(self::$sizes[$photoid])) {
// Sizes are returned from smallest to greatest.
self::$sizes[$photoid] = $this->flickr->photos_getSizes($photoid);
}
$sizes = self::$sizes[$photoid];
$bestsize = array();
if (is_array($sizes)) {
while ($bestsize = array_pop($sizes)) {
// Make sure the source is set. Exit the loop if found.
if (isset($bestsize['source'])) {
break;
}
}
}
return $bestsize;
}
|
php
|
protected function get_best_size($photoid) {
if (!isset(self::$sizes[$photoid])) {
// Sizes are returned from smallest to greatest.
self::$sizes[$photoid] = $this->flickr->photos_getSizes($photoid);
}
$sizes = self::$sizes[$photoid];
$bestsize = array();
if (is_array($sizes)) {
while ($bestsize = array_pop($sizes)) {
// Make sure the source is set. Exit the loop if found.
if (isset($bestsize['source'])) {
break;
}
}
}
return $bestsize;
}
|
[
"protected",
"function",
"get_best_size",
"(",
"$",
"photoid",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"sizes",
"[",
"$",
"photoid",
"]",
")",
")",
"{",
"// Sizes are returned from smallest to greatest.",
"self",
"::",
"$",
"sizes",
"[",
"$",
"photoid",
"]",
"=",
"$",
"this",
"->",
"flickr",
"->",
"photos_getSizes",
"(",
"$",
"photoid",
")",
";",
"}",
"$",
"sizes",
"=",
"self",
"::",
"$",
"sizes",
"[",
"$",
"photoid",
"]",
";",
"$",
"bestsize",
"=",
"array",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"sizes",
")",
")",
"{",
"while",
"(",
"$",
"bestsize",
"=",
"array_pop",
"(",
"$",
"sizes",
")",
")",
"{",
"// Make sure the source is set. Exit the loop if found.",
"if",
"(",
"isset",
"(",
"$",
"bestsize",
"[",
"'source'",
"]",
")",
")",
"{",
"break",
";",
"}",
"}",
"}",
"return",
"$",
"bestsize",
";",
"}"
] |
Returns the best size for a photo
@param string $photoid the photo identifier
@return array of information provided by the API
|
[
"Returns",
"the",
"best",
"size",
"for",
"a",
"photo"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/flickr_public/lib.php#L424-L440
|
220,160
|
moodle/moodle
|
repository/flickr_public/lib.php
|
repository_flickr_public.plugin_init
|
public static function plugin_init() {
//here we create a default instance for this type
$id = repository::static_function('flickr_public','create', 'flickr_public', 0, context_system::instance(), array('name'=>'', 'email_address' => null, 'usewatermarks' => false), 0);
if (empty($id)) {
return false;
} else {
return true;
}
}
|
php
|
public static function plugin_init() {
//here we create a default instance for this type
$id = repository::static_function('flickr_public','create', 'flickr_public', 0, context_system::instance(), array('name'=>'', 'email_address' => null, 'usewatermarks' => false), 0);
if (empty($id)) {
return false;
} else {
return true;
}
}
|
[
"public",
"static",
"function",
"plugin_init",
"(",
")",
"{",
"//here we create a default instance for this type",
"$",
"id",
"=",
"repository",
"::",
"static_function",
"(",
"'flickr_public'",
",",
"'create'",
",",
"'flickr_public'",
",",
"0",
",",
"context_system",
"::",
"instance",
"(",
")",
",",
"array",
"(",
"'name'",
"=>",
"''",
",",
"'email_address'",
"=>",
"null",
",",
"'usewatermarks'",
"=>",
"false",
")",
",",
"0",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"return",
"true",
";",
"}",
"}"
] |
is run when moodle administrator add the plugin
|
[
"is",
"run",
"when",
"moodle",
"administrator",
"add",
"the",
"plugin"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/flickr_public/lib.php#L529-L538
|
220,161
|
moodle/moodle
|
lib/htmlpurifier/HTMLPurifier/LanguageFactory.php
|
HTMLPurifier_LanguageFactory.instance
|
public static function instance($prototype = null)
{
static $instance = null;
if ($prototype !== null) {
$instance = $prototype;
} elseif ($instance === null || $prototype == true) {
$instance = new HTMLPurifier_LanguageFactory();
$instance->setup();
}
return $instance;
}
|
php
|
public static function instance($prototype = null)
{
static $instance = null;
if ($prototype !== null) {
$instance = $prototype;
} elseif ($instance === null || $prototype == true) {
$instance = new HTMLPurifier_LanguageFactory();
$instance->setup();
}
return $instance;
}
|
[
"public",
"static",
"function",
"instance",
"(",
"$",
"prototype",
"=",
"null",
")",
"{",
"static",
"$",
"instance",
"=",
"null",
";",
"if",
"(",
"$",
"prototype",
"!==",
"null",
")",
"{",
"$",
"instance",
"=",
"$",
"prototype",
";",
"}",
"elseif",
"(",
"$",
"instance",
"===",
"null",
"||",
"$",
"prototype",
"==",
"true",
")",
"{",
"$",
"instance",
"=",
"new",
"HTMLPurifier_LanguageFactory",
"(",
")",
";",
"$",
"instance",
"->",
"setup",
"(",
")",
";",
"}",
"return",
"$",
"instance",
";",
"}"
] |
Retrieve sole instance of the factory.
@param HTMLPurifier_LanguageFactory $prototype Optional prototype to overload sole instance with,
or bool true to reset to default factory.
@return HTMLPurifier_LanguageFactory
|
[
"Retrieve",
"sole",
"instance",
"of",
"the",
"factory",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/LanguageFactory.php#L59-L69
|
220,162
|
moodle/moodle
|
lib/htmlpurifier/HTMLPurifier/LanguageFactory.php
|
HTMLPurifier_LanguageFactory.create
|
public function create($config, $context, $code = false)
{
// validate language code
if ($code === false) {
$code = $this->validator->validate(
$config->get('Core.Language'),
$config,
$context
);
} else {
$code = $this->validator->validate($code, $config, $context);
}
if ($code === false) {
$code = 'en'; // malformed code becomes English
}
$pcode = str_replace('-', '_', $code); // make valid PHP classname
static $depth = 0; // recursion protection
if ($code == 'en') {
$lang = new HTMLPurifier_Language($config, $context);
} else {
$class = 'HTMLPurifier_Language_' . $pcode;
$file = $this->dir . '/Language/classes/' . $code . '.php';
if (file_exists($file) || class_exists($class, false)) {
$lang = new $class($config, $context);
} else {
// Go fallback
$raw_fallback = $this->getFallbackFor($code);
$fallback = $raw_fallback ? $raw_fallback : 'en';
$depth++;
$lang = $this->create($config, $context, $fallback);
if (!$raw_fallback) {
$lang->error = true;
}
$depth--;
}
}
$lang->code = $code;
return $lang;
}
|
php
|
public function create($config, $context, $code = false)
{
// validate language code
if ($code === false) {
$code = $this->validator->validate(
$config->get('Core.Language'),
$config,
$context
);
} else {
$code = $this->validator->validate($code, $config, $context);
}
if ($code === false) {
$code = 'en'; // malformed code becomes English
}
$pcode = str_replace('-', '_', $code); // make valid PHP classname
static $depth = 0; // recursion protection
if ($code == 'en') {
$lang = new HTMLPurifier_Language($config, $context);
} else {
$class = 'HTMLPurifier_Language_' . $pcode;
$file = $this->dir . '/Language/classes/' . $code . '.php';
if (file_exists($file) || class_exists($class, false)) {
$lang = new $class($config, $context);
} else {
// Go fallback
$raw_fallback = $this->getFallbackFor($code);
$fallback = $raw_fallback ? $raw_fallback : 'en';
$depth++;
$lang = $this->create($config, $context, $fallback);
if (!$raw_fallback) {
$lang->error = true;
}
$depth--;
}
}
$lang->code = $code;
return $lang;
}
|
[
"public",
"function",
"create",
"(",
"$",
"config",
",",
"$",
"context",
",",
"$",
"code",
"=",
"false",
")",
"{",
"// validate language code",
"if",
"(",
"$",
"code",
"===",
"false",
")",
"{",
"$",
"code",
"=",
"$",
"this",
"->",
"validator",
"->",
"validate",
"(",
"$",
"config",
"->",
"get",
"(",
"'Core.Language'",
")",
",",
"$",
"config",
",",
"$",
"context",
")",
";",
"}",
"else",
"{",
"$",
"code",
"=",
"$",
"this",
"->",
"validator",
"->",
"validate",
"(",
"$",
"code",
",",
"$",
"config",
",",
"$",
"context",
")",
";",
"}",
"if",
"(",
"$",
"code",
"===",
"false",
")",
"{",
"$",
"code",
"=",
"'en'",
";",
"// malformed code becomes English",
"}",
"$",
"pcode",
"=",
"str_replace",
"(",
"'-'",
",",
"'_'",
",",
"$",
"code",
")",
";",
"// make valid PHP classname",
"static",
"$",
"depth",
"=",
"0",
";",
"// recursion protection",
"if",
"(",
"$",
"code",
"==",
"'en'",
")",
"{",
"$",
"lang",
"=",
"new",
"HTMLPurifier_Language",
"(",
"$",
"config",
",",
"$",
"context",
")",
";",
"}",
"else",
"{",
"$",
"class",
"=",
"'HTMLPurifier_Language_'",
".",
"$",
"pcode",
";",
"$",
"file",
"=",
"$",
"this",
"->",
"dir",
".",
"'/Language/classes/'",
".",
"$",
"code",
".",
"'.php'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"file",
")",
"||",
"class_exists",
"(",
"$",
"class",
",",
"false",
")",
")",
"{",
"$",
"lang",
"=",
"new",
"$",
"class",
"(",
"$",
"config",
",",
"$",
"context",
")",
";",
"}",
"else",
"{",
"// Go fallback",
"$",
"raw_fallback",
"=",
"$",
"this",
"->",
"getFallbackFor",
"(",
"$",
"code",
")",
";",
"$",
"fallback",
"=",
"$",
"raw_fallback",
"?",
"$",
"raw_fallback",
":",
"'en'",
";",
"$",
"depth",
"++",
";",
"$",
"lang",
"=",
"$",
"this",
"->",
"create",
"(",
"$",
"config",
",",
"$",
"context",
",",
"$",
"fallback",
")",
";",
"if",
"(",
"!",
"$",
"raw_fallback",
")",
"{",
"$",
"lang",
"->",
"error",
"=",
"true",
";",
"}",
"$",
"depth",
"--",
";",
"}",
"}",
"$",
"lang",
"->",
"code",
"=",
"$",
"code",
";",
"return",
"$",
"lang",
";",
"}"
] |
Creates a language object, handles class fallbacks
@param HTMLPurifier_Config $config
@param HTMLPurifier_Context $context
@param bool|string $code Code to override configuration with. Private parameter.
@return HTMLPurifier_Language
|
[
"Creates",
"a",
"language",
"object",
"handles",
"class",
"fallbacks"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/LanguageFactory.php#L88-L128
|
220,163
|
moodle/moodle
|
lib/graphlib.php
|
graph.find_range
|
function find_range($data, $min, $max, $resolution) {
if (sizeof($data) == 0 ) return array('min' => 0, 'max' => 0);
foreach ($data as $key => $value) {
if ($value=='none') continue;
if ($value > $max) $max = $value;
if ($value < $min) $min = $value;
}
if ($max == 0) {
$factor = 1;
} else {
if ($max < 0) $factor = - pow(10, (floor(log10(abs($max))) + $resolution) );
else $factor = pow(10, (floor(log10(abs($max))) - $resolution) );
}
if ($factor > 0.1) { // To avoid some wierd rounding errors (Moodle)
$factor = round($factor * 1000.0) / 1000.0; // To avoid some wierd rounding errors (Moodle)
} // To avoid some wierd rounding errors (Moodle)
$max = $factor * @ceil($max / $factor);
$min = $factor * @floor($min / $factor);
//print "max=$max, min=$min<br />";
return array('min' => $min, 'max' => $max);
}
|
php
|
function find_range($data, $min, $max, $resolution) {
if (sizeof($data) == 0 ) return array('min' => 0, 'max' => 0);
foreach ($data as $key => $value) {
if ($value=='none') continue;
if ($value > $max) $max = $value;
if ($value < $min) $min = $value;
}
if ($max == 0) {
$factor = 1;
} else {
if ($max < 0) $factor = - pow(10, (floor(log10(abs($max))) + $resolution) );
else $factor = pow(10, (floor(log10(abs($max))) - $resolution) );
}
if ($factor > 0.1) { // To avoid some wierd rounding errors (Moodle)
$factor = round($factor * 1000.0) / 1000.0; // To avoid some wierd rounding errors (Moodle)
} // To avoid some wierd rounding errors (Moodle)
$max = $factor * @ceil($max / $factor);
$min = $factor * @floor($min / $factor);
//print "max=$max, min=$min<br />";
return array('min' => $min, 'max' => $max);
}
|
[
"function",
"find_range",
"(",
"$",
"data",
",",
"$",
"min",
",",
"$",
"max",
",",
"$",
"resolution",
")",
"{",
"if",
"(",
"sizeof",
"(",
"$",
"data",
")",
"==",
"0",
")",
"return",
"array",
"(",
"'min'",
"=>",
"0",
",",
"'max'",
"=>",
"0",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"==",
"'none'",
")",
"continue",
";",
"if",
"(",
"$",
"value",
">",
"$",
"max",
")",
"$",
"max",
"=",
"$",
"value",
";",
"if",
"(",
"$",
"value",
"<",
"$",
"min",
")",
"$",
"min",
"=",
"$",
"value",
";",
"}",
"if",
"(",
"$",
"max",
"==",
"0",
")",
"{",
"$",
"factor",
"=",
"1",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"max",
"<",
"0",
")",
"$",
"factor",
"=",
"-",
"pow",
"(",
"10",
",",
"(",
"floor",
"(",
"log10",
"(",
"abs",
"(",
"$",
"max",
")",
")",
")",
"+",
"$",
"resolution",
")",
")",
";",
"else",
"$",
"factor",
"=",
"pow",
"(",
"10",
",",
"(",
"floor",
"(",
"log10",
"(",
"abs",
"(",
"$",
"max",
")",
")",
")",
"-",
"$",
"resolution",
")",
")",
";",
"}",
"if",
"(",
"$",
"factor",
">",
"0.1",
")",
"{",
"// To avoid some wierd rounding errors (Moodle)",
"$",
"factor",
"=",
"round",
"(",
"$",
"factor",
"*",
"1000.0",
")",
"/",
"1000.0",
";",
"// To avoid some wierd rounding errors (Moodle)",
"}",
"// To avoid some wierd rounding errors (Moodle)",
"$",
"max",
"=",
"$",
"factor",
"*",
"@",
"ceil",
"(",
"$",
"max",
"/",
"$",
"factor",
")",
";",
"$",
"min",
"=",
"$",
"factor",
"*",
"@",
"floor",
"(",
"$",
"min",
"/",
"$",
"factor",
")",
";",
"//print \"max=$max, min=$min<br />\";",
"return",
"array",
"(",
"'min'",
"=>",
"$",
"min",
",",
"'max'",
"=>",
"$",
"max",
")",
";",
"}"
] |
find max and min values for a data array given the resolution.
|
[
"find",
"max",
"and",
"min",
"values",
"for",
"a",
"data",
"array",
"given",
"the",
"resolution",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/graphlib.php#L1150-L1174
|
220,164
|
moodle/moodle
|
lib/graphlib.php
|
graph.update_boundaryBox
|
function update_boundaryBox(&$boundaryBox, $coords) {
$width = $boundaryBox['width'];
$height = $boundaryBox['height'];
$x = $coords['x'];
$y = $coords['y'];
$reference = $coords['reference'];
switch ($reference) {
case 'top-left':
case 'left-top':
$top = $y;
$bottom = $y + $height;
$left = $x;
$right = $x + $width;
break;
case 'left-center':
$top = $y - ($height / 2);
$bottom = $y + ($height / 2);
$left = $x;
$right = $x + $width;
break;
case 'left-bottom':
$top = $y - $height;
$bottom = $y;
$left = $x;
$right = $x + $width;
break;
case 'top-center':
$top = $y;
$bottom = $y + $height;
$left = $x - ($width / 2);
$right = $x + ($width / 2);
break;
case 'right-top':
case 'top-right':
$top = $y;
$bottom = $y + $height;
$left = $x - $width;
$right = $x;
break;
case 'right-center':
$top = $y - ($height / 2);
$bottom = $y + ($height / 2);
$left = $x - $width;
$right = $x;
break;
case 'bottom=right':
case 'right-bottom':
$top = $y - $height;
$bottom = $y;
$left = $x - $width;
$right = $x;
break;
default:
$top = 0;
$bottom = $height;
$left = 0;
$right = $width;
break;
}
$boundaryBox = array_merge($boundaryBox, array('top' => $top,
'bottom' => $bottom,
'left' => $left,
'right' => $right,
'x' => $x,
'y' => $y,
'reference' => $reference));
}
|
php
|
function update_boundaryBox(&$boundaryBox, $coords) {
$width = $boundaryBox['width'];
$height = $boundaryBox['height'];
$x = $coords['x'];
$y = $coords['y'];
$reference = $coords['reference'];
switch ($reference) {
case 'top-left':
case 'left-top':
$top = $y;
$bottom = $y + $height;
$left = $x;
$right = $x + $width;
break;
case 'left-center':
$top = $y - ($height / 2);
$bottom = $y + ($height / 2);
$left = $x;
$right = $x + $width;
break;
case 'left-bottom':
$top = $y - $height;
$bottom = $y;
$left = $x;
$right = $x + $width;
break;
case 'top-center':
$top = $y;
$bottom = $y + $height;
$left = $x - ($width / 2);
$right = $x + ($width / 2);
break;
case 'right-top':
case 'top-right':
$top = $y;
$bottom = $y + $height;
$left = $x - $width;
$right = $x;
break;
case 'right-center':
$top = $y - ($height / 2);
$bottom = $y + ($height / 2);
$left = $x - $width;
$right = $x;
break;
case 'bottom=right':
case 'right-bottom':
$top = $y - $height;
$bottom = $y;
$left = $x - $width;
$right = $x;
break;
default:
$top = 0;
$bottom = $height;
$left = 0;
$right = $width;
break;
}
$boundaryBox = array_merge($boundaryBox, array('top' => $top,
'bottom' => $bottom,
'left' => $left,
'right' => $right,
'x' => $x,
'y' => $y,
'reference' => $reference));
}
|
[
"function",
"update_boundaryBox",
"(",
"&",
"$",
"boundaryBox",
",",
"$",
"coords",
")",
"{",
"$",
"width",
"=",
"$",
"boundaryBox",
"[",
"'width'",
"]",
";",
"$",
"height",
"=",
"$",
"boundaryBox",
"[",
"'height'",
"]",
";",
"$",
"x",
"=",
"$",
"coords",
"[",
"'x'",
"]",
";",
"$",
"y",
"=",
"$",
"coords",
"[",
"'y'",
"]",
";",
"$",
"reference",
"=",
"$",
"coords",
"[",
"'reference'",
"]",
";",
"switch",
"(",
"$",
"reference",
")",
"{",
"case",
"'top-left'",
":",
"case",
"'left-top'",
":",
"$",
"top",
"=",
"$",
"y",
";",
"$",
"bottom",
"=",
"$",
"y",
"+",
"$",
"height",
";",
"$",
"left",
"=",
"$",
"x",
";",
"$",
"right",
"=",
"$",
"x",
"+",
"$",
"width",
";",
"break",
";",
"case",
"'left-center'",
":",
"$",
"top",
"=",
"$",
"y",
"-",
"(",
"$",
"height",
"/",
"2",
")",
";",
"$",
"bottom",
"=",
"$",
"y",
"+",
"(",
"$",
"height",
"/",
"2",
")",
";",
"$",
"left",
"=",
"$",
"x",
";",
"$",
"right",
"=",
"$",
"x",
"+",
"$",
"width",
";",
"break",
";",
"case",
"'left-bottom'",
":",
"$",
"top",
"=",
"$",
"y",
"-",
"$",
"height",
";",
"$",
"bottom",
"=",
"$",
"y",
";",
"$",
"left",
"=",
"$",
"x",
";",
"$",
"right",
"=",
"$",
"x",
"+",
"$",
"width",
";",
"break",
";",
"case",
"'top-center'",
":",
"$",
"top",
"=",
"$",
"y",
";",
"$",
"bottom",
"=",
"$",
"y",
"+",
"$",
"height",
";",
"$",
"left",
"=",
"$",
"x",
"-",
"(",
"$",
"width",
"/",
"2",
")",
";",
"$",
"right",
"=",
"$",
"x",
"+",
"(",
"$",
"width",
"/",
"2",
")",
";",
"break",
";",
"case",
"'right-top'",
":",
"case",
"'top-right'",
":",
"$",
"top",
"=",
"$",
"y",
";",
"$",
"bottom",
"=",
"$",
"y",
"+",
"$",
"height",
";",
"$",
"left",
"=",
"$",
"x",
"-",
"$",
"width",
";",
"$",
"right",
"=",
"$",
"x",
";",
"break",
";",
"case",
"'right-center'",
":",
"$",
"top",
"=",
"$",
"y",
"-",
"(",
"$",
"height",
"/",
"2",
")",
";",
"$",
"bottom",
"=",
"$",
"y",
"+",
"(",
"$",
"height",
"/",
"2",
")",
";",
"$",
"left",
"=",
"$",
"x",
"-",
"$",
"width",
";",
"$",
"right",
"=",
"$",
"x",
";",
"break",
";",
"case",
"'bottom=right'",
":",
"case",
"'right-bottom'",
":",
"$",
"top",
"=",
"$",
"y",
"-",
"$",
"height",
";",
"$",
"bottom",
"=",
"$",
"y",
";",
"$",
"left",
"=",
"$",
"x",
"-",
"$",
"width",
";",
"$",
"right",
"=",
"$",
"x",
";",
"break",
";",
"default",
":",
"$",
"top",
"=",
"0",
";",
"$",
"bottom",
"=",
"$",
"height",
";",
"$",
"left",
"=",
"0",
";",
"$",
"right",
"=",
"$",
"width",
";",
"break",
";",
"}",
"$",
"boundaryBox",
"=",
"array_merge",
"(",
"$",
"boundaryBox",
",",
"array",
"(",
"'top'",
"=>",
"$",
"top",
",",
"'bottom'",
"=>",
"$",
"bottom",
",",
"'left'",
"=>",
"$",
"left",
",",
"'right'",
"=>",
"$",
"right",
",",
"'x'",
"=>",
"$",
"x",
",",
"'y'",
"=>",
"$",
"y",
",",
"'reference'",
"=>",
"$",
"reference",
")",
")",
";",
"}"
] |
move boundaryBox to coordinates specified
|
[
"move",
"boundaryBox",
"to",
"coordinates",
"specified"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/graphlib.php#L1282-L1349
|
220,165
|
moodle/moodle
|
lib/graphlib.php
|
graph.draw_brush_line
|
function draw_brush_line($x0, $y0, $x1, $y1, $size, $type, $colour) {
//$this->dbug("line: $x0, $y0, $x1, $y1");
$dy = $y1 - $y0;
$dx = $x1 - $x0;
$t = 0;
$watchdog = 1024; // precaution to prevent infinite loops.
$this->draw_brush($x0, $y0, $size, $type, $colour);
if (abs($dx) > abs($dy)) { // slope < 1
//$this->dbug("slope < 1");
$m = $dy / $dx; // compute slope
$t += $y0;
$dx = ($dx < 0) ? -1 : 1;
$m *= $dx;
while (round($x0) != round($x1)) {
if (!$watchdog--) break;
$x0 += $dx; // step to next x value
$t += $m; // add slope to y value
$y = round($t);
//$this->dbug("x0=$x0, x1=$x1, y=$y watchdog=$watchdog");
$this->draw_brush($x0, $y, $size, $type, $colour);
}
} else { // slope >= 1
//$this->dbug("slope >= 1");
$m = $dx / $dy; // compute slope
$t += $x0;
$dy = ($dy < 0) ? -1 : 1;
$m *= $dy;
while (round($y0) != round($y1)) {
if (!$watchdog--) break;
$y0 += $dy; // step to next y value
$t += $m; // add slope to x value
$x = round($t);
//$this->dbug("x=$x, y0=$y0, y1=$y1 watchdog=$watchdog");
$this->draw_brush($x, $y0, $size, $type, $colour);
}
}
}
|
php
|
function draw_brush_line($x0, $y0, $x1, $y1, $size, $type, $colour) {
//$this->dbug("line: $x0, $y0, $x1, $y1");
$dy = $y1 - $y0;
$dx = $x1 - $x0;
$t = 0;
$watchdog = 1024; // precaution to prevent infinite loops.
$this->draw_brush($x0, $y0, $size, $type, $colour);
if (abs($dx) > abs($dy)) { // slope < 1
//$this->dbug("slope < 1");
$m = $dy / $dx; // compute slope
$t += $y0;
$dx = ($dx < 0) ? -1 : 1;
$m *= $dx;
while (round($x0) != round($x1)) {
if (!$watchdog--) break;
$x0 += $dx; // step to next x value
$t += $m; // add slope to y value
$y = round($t);
//$this->dbug("x0=$x0, x1=$x1, y=$y watchdog=$watchdog");
$this->draw_brush($x0, $y, $size, $type, $colour);
}
} else { // slope >= 1
//$this->dbug("slope >= 1");
$m = $dx / $dy; // compute slope
$t += $x0;
$dy = ($dy < 0) ? -1 : 1;
$m *= $dy;
while (round($y0) != round($y1)) {
if (!$watchdog--) break;
$y0 += $dy; // step to next y value
$t += $m; // add slope to x value
$x = round($t);
//$this->dbug("x=$x, y0=$y0, y1=$y1 watchdog=$watchdog");
$this->draw_brush($x, $y0, $size, $type, $colour);
}
}
}
|
[
"function",
"draw_brush_line",
"(",
"$",
"x0",
",",
"$",
"y0",
",",
"$",
"x1",
",",
"$",
"y1",
",",
"$",
"size",
",",
"$",
"type",
",",
"$",
"colour",
")",
"{",
"//$this->dbug(\"line: $x0, $y0, $x1, $y1\");",
"$",
"dy",
"=",
"$",
"y1",
"-",
"$",
"y0",
";",
"$",
"dx",
"=",
"$",
"x1",
"-",
"$",
"x0",
";",
"$",
"t",
"=",
"0",
";",
"$",
"watchdog",
"=",
"1024",
";",
"// precaution to prevent infinite loops.",
"$",
"this",
"->",
"draw_brush",
"(",
"$",
"x0",
",",
"$",
"y0",
",",
"$",
"size",
",",
"$",
"type",
",",
"$",
"colour",
")",
";",
"if",
"(",
"abs",
"(",
"$",
"dx",
")",
">",
"abs",
"(",
"$",
"dy",
")",
")",
"{",
"// slope < 1",
"//$this->dbug(\"slope < 1\");",
"$",
"m",
"=",
"$",
"dy",
"/",
"$",
"dx",
";",
"// compute slope",
"$",
"t",
"+=",
"$",
"y0",
";",
"$",
"dx",
"=",
"(",
"$",
"dx",
"<",
"0",
")",
"?",
"-",
"1",
":",
"1",
";",
"$",
"m",
"*=",
"$",
"dx",
";",
"while",
"(",
"round",
"(",
"$",
"x0",
")",
"!=",
"round",
"(",
"$",
"x1",
")",
")",
"{",
"if",
"(",
"!",
"$",
"watchdog",
"--",
")",
"break",
";",
"$",
"x0",
"+=",
"$",
"dx",
";",
"// step to next x value",
"$",
"t",
"+=",
"$",
"m",
";",
"// add slope to y value",
"$",
"y",
"=",
"round",
"(",
"$",
"t",
")",
";",
"//$this->dbug(\"x0=$x0, x1=$x1, y=$y watchdog=$watchdog\");",
"$",
"this",
"->",
"draw_brush",
"(",
"$",
"x0",
",",
"$",
"y",
",",
"$",
"size",
",",
"$",
"type",
",",
"$",
"colour",
")",
";",
"}",
"}",
"else",
"{",
"// slope >= 1",
"//$this->dbug(\"slope >= 1\");",
"$",
"m",
"=",
"$",
"dx",
"/",
"$",
"dy",
";",
"// compute slope",
"$",
"t",
"+=",
"$",
"x0",
";",
"$",
"dy",
"=",
"(",
"$",
"dy",
"<",
"0",
")",
"?",
"-",
"1",
":",
"1",
";",
"$",
"m",
"*=",
"$",
"dy",
";",
"while",
"(",
"round",
"(",
"$",
"y0",
")",
"!=",
"round",
"(",
"$",
"y1",
")",
")",
"{",
"if",
"(",
"!",
"$",
"watchdog",
"--",
")",
"break",
";",
"$",
"y0",
"+=",
"$",
"dy",
";",
"// step to next y value",
"$",
"t",
"+=",
"$",
"m",
";",
"// add slope to x value",
"$",
"x",
"=",
"round",
"(",
"$",
"t",
")",
";",
"//$this->dbug(\"x=$x, y0=$y0, y1=$y1 watchdog=$watchdog\");",
"$",
"this",
"->",
"draw_brush",
"(",
"$",
"x",
",",
"$",
"y0",
",",
"$",
"size",
",",
"$",
"type",
",",
"$",
"colour",
")",
";",
"}",
"}",
"}"
] |
function to draw line. would prefer to use gdBrush but this is not supported yet.
|
[
"function",
"to",
"draw",
"line",
".",
"would",
"prefer",
"to",
"use",
"gdBrush",
"but",
"this",
"is",
"not",
"supported",
"yet",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/graphlib.php#L1719-L1758
|
220,166
|
moodle/moodle
|
course/format/singleactivity/lib.php
|
format_singleactivity.navigation_add_activity
|
protected function navigation_add_activity(navigation_node $node, $cm) {
if (!$cm->uservisible) {
return null;
}
$action = $cm->url;
if (!$action) {
// Do not add to navigation activity without url (i.e. labels).
return null;
}
$activityname = format_string($cm->name, true, array('context' => context_module::instance($cm->id)));
if ($cm->icon) {
$icon = new pix_icon($cm->icon, $cm->modfullname, $cm->iconcomponent);
} else {
$icon = new pix_icon('icon', $cm->modfullname, $cm->modname);
}
$activitynode = $node->add($activityname, $action, navigation_node::TYPE_ACTIVITY, null, $cm->id, $icon);
if (global_navigation::module_extends_navigation($cm->modname)) {
$activitynode->nodetype = navigation_node::NODETYPE_BRANCH;
} else {
$activitynode->nodetype = navigation_node::NODETYPE_LEAF;
}
return $activitynode;
}
|
php
|
protected function navigation_add_activity(navigation_node $node, $cm) {
if (!$cm->uservisible) {
return null;
}
$action = $cm->url;
if (!$action) {
// Do not add to navigation activity without url (i.e. labels).
return null;
}
$activityname = format_string($cm->name, true, array('context' => context_module::instance($cm->id)));
if ($cm->icon) {
$icon = new pix_icon($cm->icon, $cm->modfullname, $cm->iconcomponent);
} else {
$icon = new pix_icon('icon', $cm->modfullname, $cm->modname);
}
$activitynode = $node->add($activityname, $action, navigation_node::TYPE_ACTIVITY, null, $cm->id, $icon);
if (global_navigation::module_extends_navigation($cm->modname)) {
$activitynode->nodetype = navigation_node::NODETYPE_BRANCH;
} else {
$activitynode->nodetype = navigation_node::NODETYPE_LEAF;
}
return $activitynode;
}
|
[
"protected",
"function",
"navigation_add_activity",
"(",
"navigation_node",
"$",
"node",
",",
"$",
"cm",
")",
"{",
"if",
"(",
"!",
"$",
"cm",
"->",
"uservisible",
")",
"{",
"return",
"null",
";",
"}",
"$",
"action",
"=",
"$",
"cm",
"->",
"url",
";",
"if",
"(",
"!",
"$",
"action",
")",
"{",
"// Do not add to navigation activity without url (i.e. labels).",
"return",
"null",
";",
"}",
"$",
"activityname",
"=",
"format_string",
"(",
"$",
"cm",
"->",
"name",
",",
"true",
",",
"array",
"(",
"'context'",
"=>",
"context_module",
"::",
"instance",
"(",
"$",
"cm",
"->",
"id",
")",
")",
")",
";",
"if",
"(",
"$",
"cm",
"->",
"icon",
")",
"{",
"$",
"icon",
"=",
"new",
"pix_icon",
"(",
"$",
"cm",
"->",
"icon",
",",
"$",
"cm",
"->",
"modfullname",
",",
"$",
"cm",
"->",
"iconcomponent",
")",
";",
"}",
"else",
"{",
"$",
"icon",
"=",
"new",
"pix_icon",
"(",
"'icon'",
",",
"$",
"cm",
"->",
"modfullname",
",",
"$",
"cm",
"->",
"modname",
")",
";",
"}",
"$",
"activitynode",
"=",
"$",
"node",
"->",
"add",
"(",
"$",
"activityname",
",",
"$",
"action",
",",
"navigation_node",
"::",
"TYPE_ACTIVITY",
",",
"null",
",",
"$",
"cm",
"->",
"id",
",",
"$",
"icon",
")",
";",
"if",
"(",
"global_navigation",
"::",
"module_extends_navigation",
"(",
"$",
"cm",
"->",
"modname",
")",
")",
"{",
"$",
"activitynode",
"->",
"nodetype",
"=",
"navigation_node",
"::",
"NODETYPE_BRANCH",
";",
"}",
"else",
"{",
"$",
"activitynode",
"->",
"nodetype",
"=",
"navigation_node",
"::",
"NODETYPE_LEAF",
";",
"}",
"return",
"$",
"activitynode",
";",
"}"
] |
Adds a course module to the navigation node
This is basically copied from function global_navigation::load_section_activities()
because it is not accessible from outside.
@param navigation_node $node
@param cm_info $cm
@return null|navigation_node
|
[
"Adds",
"a",
"course",
"module",
"to",
"the",
"navigation",
"node"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/singleactivity/lib.php#L100-L122
|
220,167
|
moodle/moodle
|
course/format/singleactivity/lib.php
|
format_singleactivity.reorder_activities
|
public function reorder_activities() {
course_create_sections_if_missing($this->courseid, array(0, 1));
foreach ($this->get_sections() as $sectionnum => $section) {
if (($sectionnum && $section->visible) ||
(!$sectionnum && !$section->visible)) {
// Make sure that 0 section is visible and all others are hidden.
set_section_visible($this->courseid, $sectionnum, $sectionnum == 0);
}
}
$modinfo = get_fast_modinfo($this->courseid);
// Find the current activity (first activity with the specified type in all course activities).
$activitytype = $this->get_activitytype();
$activity = null;
if (!empty($activitytype)) {
foreach ($modinfo->sections as $sectionnum => $cmlist) {
foreach ($cmlist as $cmid) {
if ($modinfo->cms[$cmid]->modname === $activitytype) {
$activity = $modinfo->cms[$cmid];
break 2;
}
}
}
}
// Make sure the current activity is in the 0-section.
$changed = false;
if ($activity && $activity->sectionnum != 0) {
moveto_module($activity, $modinfo->get_section_info(0));
$changed = true;
}
if ($activity && !$activity->visible) {
set_coursemodule_visible($activity->id, 1);
$changed = true;
}
if ($changed) {
// Cache was reset so get modinfo again.
$modinfo = get_fast_modinfo($this->courseid);
}
// Move all other activities into section 1 (the order must be kept).
$hasvisibleactivities = false;
$firstorphanedcm = null;
foreach ($modinfo->sections as $sectionnum => $cmlist) {
if ($sectionnum && !empty($cmlist) && $firstorphanedcm === null) {
$firstorphanedcm = reset($cmlist);
}
foreach ($cmlist as $cmid) {
if ($sectionnum > 1) {
moveto_module($modinfo->get_cm($cmid), $modinfo->get_section_info(1));
} else if (!$hasvisibleactivities && $sectionnum == 1 && $modinfo->get_cm($cmid)->visible) {
$hasvisibleactivities = true;
}
}
}
if (!empty($modinfo->sections[0])) {
foreach ($modinfo->sections[0] as $cmid) {
if (!$activity || $cmid != $activity->id) {
moveto_module($modinfo->get_cm($cmid), $modinfo->get_section_info(1), $firstorphanedcm);
}
}
}
if ($hasvisibleactivities) {
set_section_visible($this->courseid, 1, false);
}
return $activity;
}
|
php
|
public function reorder_activities() {
course_create_sections_if_missing($this->courseid, array(0, 1));
foreach ($this->get_sections() as $sectionnum => $section) {
if (($sectionnum && $section->visible) ||
(!$sectionnum && !$section->visible)) {
// Make sure that 0 section is visible and all others are hidden.
set_section_visible($this->courseid, $sectionnum, $sectionnum == 0);
}
}
$modinfo = get_fast_modinfo($this->courseid);
// Find the current activity (first activity with the specified type in all course activities).
$activitytype = $this->get_activitytype();
$activity = null;
if (!empty($activitytype)) {
foreach ($modinfo->sections as $sectionnum => $cmlist) {
foreach ($cmlist as $cmid) {
if ($modinfo->cms[$cmid]->modname === $activitytype) {
$activity = $modinfo->cms[$cmid];
break 2;
}
}
}
}
// Make sure the current activity is in the 0-section.
$changed = false;
if ($activity && $activity->sectionnum != 0) {
moveto_module($activity, $modinfo->get_section_info(0));
$changed = true;
}
if ($activity && !$activity->visible) {
set_coursemodule_visible($activity->id, 1);
$changed = true;
}
if ($changed) {
// Cache was reset so get modinfo again.
$modinfo = get_fast_modinfo($this->courseid);
}
// Move all other activities into section 1 (the order must be kept).
$hasvisibleactivities = false;
$firstorphanedcm = null;
foreach ($modinfo->sections as $sectionnum => $cmlist) {
if ($sectionnum && !empty($cmlist) && $firstorphanedcm === null) {
$firstorphanedcm = reset($cmlist);
}
foreach ($cmlist as $cmid) {
if ($sectionnum > 1) {
moveto_module($modinfo->get_cm($cmid), $modinfo->get_section_info(1));
} else if (!$hasvisibleactivities && $sectionnum == 1 && $modinfo->get_cm($cmid)->visible) {
$hasvisibleactivities = true;
}
}
}
if (!empty($modinfo->sections[0])) {
foreach ($modinfo->sections[0] as $cmid) {
if (!$activity || $cmid != $activity->id) {
moveto_module($modinfo->get_cm($cmid), $modinfo->get_section_info(1), $firstorphanedcm);
}
}
}
if ($hasvisibleactivities) {
set_section_visible($this->courseid, 1, false);
}
return $activity;
}
|
[
"public",
"function",
"reorder_activities",
"(",
")",
"{",
"course_create_sections_if_missing",
"(",
"$",
"this",
"->",
"courseid",
",",
"array",
"(",
"0",
",",
"1",
")",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"get_sections",
"(",
")",
"as",
"$",
"sectionnum",
"=>",
"$",
"section",
")",
"{",
"if",
"(",
"(",
"$",
"sectionnum",
"&&",
"$",
"section",
"->",
"visible",
")",
"||",
"(",
"!",
"$",
"sectionnum",
"&&",
"!",
"$",
"section",
"->",
"visible",
")",
")",
"{",
"// Make sure that 0 section is visible and all others are hidden.",
"set_section_visible",
"(",
"$",
"this",
"->",
"courseid",
",",
"$",
"sectionnum",
",",
"$",
"sectionnum",
"==",
"0",
")",
";",
"}",
"}",
"$",
"modinfo",
"=",
"get_fast_modinfo",
"(",
"$",
"this",
"->",
"courseid",
")",
";",
"// Find the current activity (first activity with the specified type in all course activities).",
"$",
"activitytype",
"=",
"$",
"this",
"->",
"get_activitytype",
"(",
")",
";",
"$",
"activity",
"=",
"null",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"activitytype",
")",
")",
"{",
"foreach",
"(",
"$",
"modinfo",
"->",
"sections",
"as",
"$",
"sectionnum",
"=>",
"$",
"cmlist",
")",
"{",
"foreach",
"(",
"$",
"cmlist",
"as",
"$",
"cmid",
")",
"{",
"if",
"(",
"$",
"modinfo",
"->",
"cms",
"[",
"$",
"cmid",
"]",
"->",
"modname",
"===",
"$",
"activitytype",
")",
"{",
"$",
"activity",
"=",
"$",
"modinfo",
"->",
"cms",
"[",
"$",
"cmid",
"]",
";",
"break",
"2",
";",
"}",
"}",
"}",
"}",
"// Make sure the current activity is in the 0-section.",
"$",
"changed",
"=",
"false",
";",
"if",
"(",
"$",
"activity",
"&&",
"$",
"activity",
"->",
"sectionnum",
"!=",
"0",
")",
"{",
"moveto_module",
"(",
"$",
"activity",
",",
"$",
"modinfo",
"->",
"get_section_info",
"(",
"0",
")",
")",
";",
"$",
"changed",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"activity",
"&&",
"!",
"$",
"activity",
"->",
"visible",
")",
"{",
"set_coursemodule_visible",
"(",
"$",
"activity",
"->",
"id",
",",
"1",
")",
";",
"$",
"changed",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"changed",
")",
"{",
"// Cache was reset so get modinfo again.",
"$",
"modinfo",
"=",
"get_fast_modinfo",
"(",
"$",
"this",
"->",
"courseid",
")",
";",
"}",
"// Move all other activities into section 1 (the order must be kept).",
"$",
"hasvisibleactivities",
"=",
"false",
";",
"$",
"firstorphanedcm",
"=",
"null",
";",
"foreach",
"(",
"$",
"modinfo",
"->",
"sections",
"as",
"$",
"sectionnum",
"=>",
"$",
"cmlist",
")",
"{",
"if",
"(",
"$",
"sectionnum",
"&&",
"!",
"empty",
"(",
"$",
"cmlist",
")",
"&&",
"$",
"firstorphanedcm",
"===",
"null",
")",
"{",
"$",
"firstorphanedcm",
"=",
"reset",
"(",
"$",
"cmlist",
")",
";",
"}",
"foreach",
"(",
"$",
"cmlist",
"as",
"$",
"cmid",
")",
"{",
"if",
"(",
"$",
"sectionnum",
">",
"1",
")",
"{",
"moveto_module",
"(",
"$",
"modinfo",
"->",
"get_cm",
"(",
"$",
"cmid",
")",
",",
"$",
"modinfo",
"->",
"get_section_info",
"(",
"1",
")",
")",
";",
"}",
"else",
"if",
"(",
"!",
"$",
"hasvisibleactivities",
"&&",
"$",
"sectionnum",
"==",
"1",
"&&",
"$",
"modinfo",
"->",
"get_cm",
"(",
"$",
"cmid",
")",
"->",
"visible",
")",
"{",
"$",
"hasvisibleactivities",
"=",
"true",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"modinfo",
"->",
"sections",
"[",
"0",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"modinfo",
"->",
"sections",
"[",
"0",
"]",
"as",
"$",
"cmid",
")",
"{",
"if",
"(",
"!",
"$",
"activity",
"||",
"$",
"cmid",
"!=",
"$",
"activity",
"->",
"id",
")",
"{",
"moveto_module",
"(",
"$",
"modinfo",
"->",
"get_cm",
"(",
"$",
"cmid",
")",
",",
"$",
"modinfo",
"->",
"get_section_info",
"(",
"1",
")",
",",
"$",
"firstorphanedcm",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"hasvisibleactivities",
")",
"{",
"set_section_visible",
"(",
"$",
"this",
"->",
"courseid",
",",
"1",
",",
"false",
")",
";",
"}",
"return",
"$",
"activity",
";",
"}"
] |
Make sure that current active activity is in section 0
All other activities are moved to section 1 that will be displayed as 'Orphaned'.
It may be needed after the course format was changed or activitytype in
course settings has been changed.
@return null|cm_info current activity
|
[
"Make",
"sure",
"that",
"current",
"active",
"activity",
"is",
"in",
"section",
"0"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/singleactivity/lib.php#L207-L273
|
220,168
|
moodle/moodle
|
course/format/singleactivity/lib.php
|
format_singleactivity.get_activitytype
|
protected function get_activitytype() {
$options = $this->get_format_options();
$availabletypes = $this->get_supported_activities();
if (!empty($options['activitytype']) &&
array_key_exists($options['activitytype'], $availabletypes)) {
return $options['activitytype'];
} else {
return null;
}
}
|
php
|
protected function get_activitytype() {
$options = $this->get_format_options();
$availabletypes = $this->get_supported_activities();
if (!empty($options['activitytype']) &&
array_key_exists($options['activitytype'], $availabletypes)) {
return $options['activitytype'];
} else {
return null;
}
}
|
[
"protected",
"function",
"get_activitytype",
"(",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"get_format_options",
"(",
")",
";",
"$",
"availabletypes",
"=",
"$",
"this",
"->",
"get_supported_activities",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'activitytype'",
"]",
")",
"&&",
"array_key_exists",
"(",
"$",
"options",
"[",
"'activitytype'",
"]",
",",
"$",
"availabletypes",
")",
")",
"{",
"return",
"$",
"options",
"[",
"'activitytype'",
"]",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] |
Returns the name of activity type used for this course
@return string|null
|
[
"Returns",
"the",
"name",
"of",
"activity",
"type",
"used",
"for",
"this",
"course"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/singleactivity/lib.php#L280-L289
|
220,169
|
moodle/moodle
|
course/format/singleactivity/lib.php
|
format_singleactivity.get_activity
|
protected function get_activity() {
if ($this->activity === false) {
$this->activity = $this->reorder_activities();
}
return $this->activity;
}
|
php
|
protected function get_activity() {
if ($this->activity === false) {
$this->activity = $this->reorder_activities();
}
return $this->activity;
}
|
[
"protected",
"function",
"get_activity",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"activity",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"activity",
"=",
"$",
"this",
"->",
"reorder_activities",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"activity",
";",
"}"
] |
Returns the current activity if exists
@return null|cm_info
|
[
"Returns",
"the",
"current",
"activity",
"if",
"exists"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/singleactivity/lib.php#L296-L301
|
220,170
|
moodle/moodle
|
course/format/singleactivity/lib.php
|
format_singleactivity.get_supported_activities
|
public static function get_supported_activities() {
$availabletypes = get_module_types_names();
foreach ($availabletypes as $module => $name) {
if (plugin_supports('mod', $module, FEATURE_NO_VIEW_LINK, false)) {
unset($availabletypes[$module]);
}
}
return $availabletypes;
}
|
php
|
public static function get_supported_activities() {
$availabletypes = get_module_types_names();
foreach ($availabletypes as $module => $name) {
if (plugin_supports('mod', $module, FEATURE_NO_VIEW_LINK, false)) {
unset($availabletypes[$module]);
}
}
return $availabletypes;
}
|
[
"public",
"static",
"function",
"get_supported_activities",
"(",
")",
"{",
"$",
"availabletypes",
"=",
"get_module_types_names",
"(",
")",
";",
"foreach",
"(",
"$",
"availabletypes",
"as",
"$",
"module",
"=>",
"$",
"name",
")",
"{",
"if",
"(",
"plugin_supports",
"(",
"'mod'",
",",
"$",
"module",
",",
"FEATURE_NO_VIEW_LINK",
",",
"false",
")",
")",
"{",
"unset",
"(",
"$",
"availabletypes",
"[",
"$",
"module",
"]",
")",
";",
"}",
"}",
"return",
"$",
"availabletypes",
";",
"}"
] |
Get the activities supported by the format.
Here we ignore the modules that do not have a page of their own, like the label.
@return array array($module => $name of the module).
|
[
"Get",
"the",
"activities",
"supported",
"by",
"the",
"format",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/singleactivity/lib.php#L310-L318
|
220,171
|
moodle/moodle
|
course/format/singleactivity/lib.php
|
format_singleactivity.can_add_activity
|
protected function can_add_activity() {
global $CFG;
if (!($modname = $this->get_activitytype())) {
return false;
}
if (!has_capability('moodle/course:manageactivities', context_course::instance($this->courseid))) {
return false;
}
if (!course_allowed_module($this->get_course(), $modname)) {
return false;
}
$libfile = "$CFG->dirroot/mod/$modname/lib.php";
if (!file_exists($libfile)) {
return null;
}
return true;
}
|
php
|
protected function can_add_activity() {
global $CFG;
if (!($modname = $this->get_activitytype())) {
return false;
}
if (!has_capability('moodle/course:manageactivities', context_course::instance($this->courseid))) {
return false;
}
if (!course_allowed_module($this->get_course(), $modname)) {
return false;
}
$libfile = "$CFG->dirroot/mod/$modname/lib.php";
if (!file_exists($libfile)) {
return null;
}
return true;
}
|
[
"protected",
"function",
"can_add_activity",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"if",
"(",
"!",
"(",
"$",
"modname",
"=",
"$",
"this",
"->",
"get_activitytype",
"(",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"has_capability",
"(",
"'moodle/course:manageactivities'",
",",
"context_course",
"::",
"instance",
"(",
"$",
"this",
"->",
"courseid",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"course_allowed_module",
"(",
"$",
"this",
"->",
"get_course",
"(",
")",
",",
"$",
"modname",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"libfile",
"=",
"\"$CFG->dirroot/mod/$modname/lib.php\"",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"libfile",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"true",
";",
"}"
] |
Checks if the current user can add the activity of the specified type to this course.
@return bool
|
[
"Checks",
"if",
"the",
"current",
"user",
"can",
"add",
"the",
"activity",
"of",
"the",
"specified",
"type",
"to",
"this",
"course",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/singleactivity/lib.php#L325-L341
|
220,172
|
moodle/moodle
|
customfield/field/select/classes/field_controller.php
|
field_controller.config_form_definition
|
public function config_form_definition(\MoodleQuickForm $mform) {
$mform->addElement('header', 'header_specificsettings', get_string('specificsettings', 'customfield_select'));
$mform->setExpanded('header_specificsettings', true);
$mform->addElement('textarea', 'configdata[options]', get_string('menuoptions', 'customfield_select'));
$mform->setType('configdata[options]', PARAM_TEXT);
$mform->addElement('text', 'configdata[defaultvalue]', get_string('defaultvalue', 'core_customfield'), 'size="50"');
$mform->setType('configdata[defaultvalue]', PARAM_TEXT);
}
|
php
|
public function config_form_definition(\MoodleQuickForm $mform) {
$mform->addElement('header', 'header_specificsettings', get_string('specificsettings', 'customfield_select'));
$mform->setExpanded('header_specificsettings', true);
$mform->addElement('textarea', 'configdata[options]', get_string('menuoptions', 'customfield_select'));
$mform->setType('configdata[options]', PARAM_TEXT);
$mform->addElement('text', 'configdata[defaultvalue]', get_string('defaultvalue', 'core_customfield'), 'size="50"');
$mform->setType('configdata[defaultvalue]', PARAM_TEXT);
}
|
[
"public",
"function",
"config_form_definition",
"(",
"\\",
"MoodleQuickForm",
"$",
"mform",
")",
"{",
"$",
"mform",
"->",
"addElement",
"(",
"'header'",
",",
"'header_specificsettings'",
",",
"get_string",
"(",
"'specificsettings'",
",",
"'customfield_select'",
")",
")",
";",
"$",
"mform",
"->",
"setExpanded",
"(",
"'header_specificsettings'",
",",
"true",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'textarea'",
",",
"'configdata[options]'",
",",
"get_string",
"(",
"'menuoptions'",
",",
"'customfield_select'",
")",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'configdata[options]'",
",",
"PARAM_TEXT",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'text'",
",",
"'configdata[defaultvalue]'",
",",
"get_string",
"(",
"'defaultvalue'",
",",
"'core_customfield'",
")",
",",
"'size=\"50\"'",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'configdata[defaultvalue]'",
",",
"PARAM_TEXT",
")",
";",
"}"
] |
Add fields for editing a select field.
@param \MoodleQuickForm $mform
|
[
"Add",
"fields",
"for",
"editing",
"a",
"select",
"field",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/field/select/classes/field_controller.php#L47-L56
|
220,173
|
moodle/moodle
|
customfield/field/select/classes/field_controller.php
|
field_controller.get_options_array
|
public static function get_options_array(\core_customfield\field_controller $field) : array {
if ($field->get_configdata_property('options')) {
$options = preg_split("/\s*\n\s*/", trim($field->get_configdata_property('options')));
} else {
$options = array();
}
return array_merge([''], $options);
}
|
php
|
public static function get_options_array(\core_customfield\field_controller $field) : array {
if ($field->get_configdata_property('options')) {
$options = preg_split("/\s*\n\s*/", trim($field->get_configdata_property('options')));
} else {
$options = array();
}
return array_merge([''], $options);
}
|
[
"public",
"static",
"function",
"get_options_array",
"(",
"\\",
"core_customfield",
"\\",
"field_controller",
"$",
"field",
")",
":",
"array",
"{",
"if",
"(",
"$",
"field",
"->",
"get_configdata_property",
"(",
"'options'",
")",
")",
"{",
"$",
"options",
"=",
"preg_split",
"(",
"\"/\\s*\\n\\s*/\"",
",",
"trim",
"(",
"$",
"field",
"->",
"get_configdata_property",
"(",
"'options'",
")",
")",
")",
";",
"}",
"else",
"{",
"$",
"options",
"=",
"array",
"(",
")",
";",
"}",
"return",
"array_merge",
"(",
"[",
"''",
"]",
",",
"$",
"options",
")",
";",
"}"
] |
Returns the options available as an array.
@param \core_customfield\field_controller $field
@return array
|
[
"Returns",
"the",
"options",
"available",
"as",
"an",
"array",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/field/select/classes/field_controller.php#L64-L71
|
220,174
|
moodle/moodle
|
customfield/field/select/classes/field_controller.php
|
field_controller.config_form_validation
|
public function config_form_validation(array $data, $files = array()) : array {
$options = preg_split("/\s*\n\s*/", trim($data['configdata']['options']));
$errors = [];
if (!$options || count($options) < 2) {
$errors['configdata[options]'] = get_string('errornotenoughoptions', 'customfield_select');
} else if (!empty($data['configdata']['defaultvalue'])) {
$defaultkey = array_search($data['configdata']['defaultvalue'], $options);
if ($defaultkey === false) {
$errors['configdata[defaultvalue]'] = get_string('errordefaultvaluenotinlist', 'customfield_select');
}
}
return $errors;
}
|
php
|
public function config_form_validation(array $data, $files = array()) : array {
$options = preg_split("/\s*\n\s*/", trim($data['configdata']['options']));
$errors = [];
if (!$options || count($options) < 2) {
$errors['configdata[options]'] = get_string('errornotenoughoptions', 'customfield_select');
} else if (!empty($data['configdata']['defaultvalue'])) {
$defaultkey = array_search($data['configdata']['defaultvalue'], $options);
if ($defaultkey === false) {
$errors['configdata[defaultvalue]'] = get_string('errordefaultvaluenotinlist', 'customfield_select');
}
}
return $errors;
}
|
[
"public",
"function",
"config_form_validation",
"(",
"array",
"$",
"data",
",",
"$",
"files",
"=",
"array",
"(",
")",
")",
":",
"array",
"{",
"$",
"options",
"=",
"preg_split",
"(",
"\"/\\s*\\n\\s*/\"",
",",
"trim",
"(",
"$",
"data",
"[",
"'configdata'",
"]",
"[",
"'options'",
"]",
")",
")",
";",
"$",
"errors",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"$",
"options",
"||",
"count",
"(",
"$",
"options",
")",
"<",
"2",
")",
"{",
"$",
"errors",
"[",
"'configdata[options]'",
"]",
"=",
"get_string",
"(",
"'errornotenoughoptions'",
",",
"'customfield_select'",
")",
";",
"}",
"else",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"'configdata'",
"]",
"[",
"'defaultvalue'",
"]",
")",
")",
"{",
"$",
"defaultkey",
"=",
"array_search",
"(",
"$",
"data",
"[",
"'configdata'",
"]",
"[",
"'defaultvalue'",
"]",
",",
"$",
"options",
")",
";",
"if",
"(",
"$",
"defaultkey",
"===",
"false",
")",
"{",
"$",
"errors",
"[",
"'configdata[defaultvalue]'",
"]",
"=",
"get_string",
"(",
"'errordefaultvaluenotinlist'",
",",
"'customfield_select'",
")",
";",
"}",
"}",
"return",
"$",
"errors",
";",
"}"
] |
Validate the data from the config form.
Sub classes must reimplement it.
@param array $data from the add/edit profile field form
@param array $files
@return array associative array of error messages
|
[
"Validate",
"the",
"data",
"from",
"the",
"config",
"form",
".",
"Sub",
"classes",
"must",
"reimplement",
"it",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/field/select/classes/field_controller.php#L81-L93
|
220,175
|
moodle/moodle
|
mod/quiz/report/statistics/statistics_question_table.php
|
quiz_statistics_question_table.question_setup
|
public function question_setup($reporturl, $questiondata, $s, $responseanalysis) {
$this->questiondata = $questiondata;
$this->s = $s;
$this->define_baseurl($reporturl->out());
$this->collapsible(false);
$this->set_attribute('class', 'generaltable generalbox boxaligncenter quizresponseanalysis');
// Define the table columns.
$columns = array();
$headers = array();
if ($responseanalysis->has_subparts()) {
$columns[] = 'part';
$headers[] = get_string('partofquestion', 'quiz_statistics');
}
if ($responseanalysis->has_multiple_response_classes()) {
$columns[] = 'responseclass';
$headers[] = get_string('modelresponse', 'quiz_statistics');
if ($responseanalysis->has_actual_responses()) {
$columns[] = 'response';
$headers[] = get_string('actualresponse', 'quiz_statistics');
}
} else {
$columns[] = 'response';
$headers[] = get_string('response', 'quiz_statistics');
}
$columns[] = 'fraction';
$headers[] = get_string('optiongrade', 'quiz_statistics');
if (!$responseanalysis->has_multiple_tries_data()) {
$columns[] = 'totalcount';
$headers[] = get_string('count', 'quiz_statistics');
} else {
$countcolumns = range(1, $responseanalysis->get_maximum_tries());
foreach ($countcolumns as $countcolumn) {
$columns[] = 'trycount'.$countcolumn;
$headers[] = get_string('counttryno', 'quiz_statistics', $countcolumn);
}
}
$columns[] = 'frequency';
$headers[] = get_string('frequency', 'quiz_statistics');
$this->define_columns($columns);
$this->define_headers($headers);
$this->sortable(false);
$this->column_class('fraction', 'numcol');
$this->column_class('count', 'numcol');
$this->column_class('frequency', 'numcol');
$this->column_suppress('part');
$this->column_suppress('responseclass');
parent::setup();
}
|
php
|
public function question_setup($reporturl, $questiondata, $s, $responseanalysis) {
$this->questiondata = $questiondata;
$this->s = $s;
$this->define_baseurl($reporturl->out());
$this->collapsible(false);
$this->set_attribute('class', 'generaltable generalbox boxaligncenter quizresponseanalysis');
// Define the table columns.
$columns = array();
$headers = array();
if ($responseanalysis->has_subparts()) {
$columns[] = 'part';
$headers[] = get_string('partofquestion', 'quiz_statistics');
}
if ($responseanalysis->has_multiple_response_classes()) {
$columns[] = 'responseclass';
$headers[] = get_string('modelresponse', 'quiz_statistics');
if ($responseanalysis->has_actual_responses()) {
$columns[] = 'response';
$headers[] = get_string('actualresponse', 'quiz_statistics');
}
} else {
$columns[] = 'response';
$headers[] = get_string('response', 'quiz_statistics');
}
$columns[] = 'fraction';
$headers[] = get_string('optiongrade', 'quiz_statistics');
if (!$responseanalysis->has_multiple_tries_data()) {
$columns[] = 'totalcount';
$headers[] = get_string('count', 'quiz_statistics');
} else {
$countcolumns = range(1, $responseanalysis->get_maximum_tries());
foreach ($countcolumns as $countcolumn) {
$columns[] = 'trycount'.$countcolumn;
$headers[] = get_string('counttryno', 'quiz_statistics', $countcolumn);
}
}
$columns[] = 'frequency';
$headers[] = get_string('frequency', 'quiz_statistics');
$this->define_columns($columns);
$this->define_headers($headers);
$this->sortable(false);
$this->column_class('fraction', 'numcol');
$this->column_class('count', 'numcol');
$this->column_class('frequency', 'numcol');
$this->column_suppress('part');
$this->column_suppress('responseclass');
parent::setup();
}
|
[
"public",
"function",
"question_setup",
"(",
"$",
"reporturl",
",",
"$",
"questiondata",
",",
"$",
"s",
",",
"$",
"responseanalysis",
")",
"{",
"$",
"this",
"->",
"questiondata",
"=",
"$",
"questiondata",
";",
"$",
"this",
"->",
"s",
"=",
"$",
"s",
";",
"$",
"this",
"->",
"define_baseurl",
"(",
"$",
"reporturl",
"->",
"out",
"(",
")",
")",
";",
"$",
"this",
"->",
"collapsible",
"(",
"false",
")",
";",
"$",
"this",
"->",
"set_attribute",
"(",
"'class'",
",",
"'generaltable generalbox boxaligncenter quizresponseanalysis'",
")",
";",
"// Define the table columns.",
"$",
"columns",
"=",
"array",
"(",
")",
";",
"$",
"headers",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"responseanalysis",
"->",
"has_subparts",
"(",
")",
")",
"{",
"$",
"columns",
"[",
"]",
"=",
"'part'",
";",
"$",
"headers",
"[",
"]",
"=",
"get_string",
"(",
"'partofquestion'",
",",
"'quiz_statistics'",
")",
";",
"}",
"if",
"(",
"$",
"responseanalysis",
"->",
"has_multiple_response_classes",
"(",
")",
")",
"{",
"$",
"columns",
"[",
"]",
"=",
"'responseclass'",
";",
"$",
"headers",
"[",
"]",
"=",
"get_string",
"(",
"'modelresponse'",
",",
"'quiz_statistics'",
")",
";",
"if",
"(",
"$",
"responseanalysis",
"->",
"has_actual_responses",
"(",
")",
")",
"{",
"$",
"columns",
"[",
"]",
"=",
"'response'",
";",
"$",
"headers",
"[",
"]",
"=",
"get_string",
"(",
"'actualresponse'",
",",
"'quiz_statistics'",
")",
";",
"}",
"}",
"else",
"{",
"$",
"columns",
"[",
"]",
"=",
"'response'",
";",
"$",
"headers",
"[",
"]",
"=",
"get_string",
"(",
"'response'",
",",
"'quiz_statistics'",
")",
";",
"}",
"$",
"columns",
"[",
"]",
"=",
"'fraction'",
";",
"$",
"headers",
"[",
"]",
"=",
"get_string",
"(",
"'optiongrade'",
",",
"'quiz_statistics'",
")",
";",
"if",
"(",
"!",
"$",
"responseanalysis",
"->",
"has_multiple_tries_data",
"(",
")",
")",
"{",
"$",
"columns",
"[",
"]",
"=",
"'totalcount'",
";",
"$",
"headers",
"[",
"]",
"=",
"get_string",
"(",
"'count'",
",",
"'quiz_statistics'",
")",
";",
"}",
"else",
"{",
"$",
"countcolumns",
"=",
"range",
"(",
"1",
",",
"$",
"responseanalysis",
"->",
"get_maximum_tries",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"countcolumns",
"as",
"$",
"countcolumn",
")",
"{",
"$",
"columns",
"[",
"]",
"=",
"'trycount'",
".",
"$",
"countcolumn",
";",
"$",
"headers",
"[",
"]",
"=",
"get_string",
"(",
"'counttryno'",
",",
"'quiz_statistics'",
",",
"$",
"countcolumn",
")",
";",
"}",
"}",
"$",
"columns",
"[",
"]",
"=",
"'frequency'",
";",
"$",
"headers",
"[",
"]",
"=",
"get_string",
"(",
"'frequency'",
",",
"'quiz_statistics'",
")",
";",
"$",
"this",
"->",
"define_columns",
"(",
"$",
"columns",
")",
";",
"$",
"this",
"->",
"define_headers",
"(",
"$",
"headers",
")",
";",
"$",
"this",
"->",
"sortable",
"(",
"false",
")",
";",
"$",
"this",
"->",
"column_class",
"(",
"'fraction'",
",",
"'numcol'",
")",
";",
"$",
"this",
"->",
"column_class",
"(",
"'count'",
",",
"'numcol'",
")",
";",
"$",
"this",
"->",
"column_class",
"(",
"'frequency'",
",",
"'numcol'",
")",
";",
"$",
"this",
"->",
"column_suppress",
"(",
"'part'",
")",
";",
"$",
"this",
"->",
"column_suppress",
"(",
"'responseclass'",
")",
";",
"parent",
"::",
"setup",
"(",
")",
";",
"}"
] |
Set up columns and column names and other table settings.
@param moodle_url $reporturl
@param object $questiondata
@param integer $s number of attempts on this question.
@param \core_question\statistics\responses\analysis_for_question $responseanalysis
|
[
"Set",
"up",
"columns",
"and",
"column",
"names",
"and",
"other",
"table",
"settings",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/statistics/statistics_question_table.php#L67-L127
|
220,176
|
moodle/moodle
|
mod/quiz/report/statistics/statistics_question_table.php
|
quiz_statistics_question_table.col_frequency
|
protected function col_frequency($response) {
if (!$this->s) {
return '';
}
return $this->format_percentage($response->totalcount / $this->s);
}
|
php
|
protected function col_frequency($response) {
if (!$this->s) {
return '';
}
return $this->format_percentage($response->totalcount / $this->s);
}
|
[
"protected",
"function",
"col_frequency",
"(",
"$",
"response",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"s",
")",
"{",
"return",
"''",
";",
"}",
"return",
"$",
"this",
"->",
"format_percentage",
"(",
"$",
"response",
"->",
"totalcount",
"/",
"$",
"this",
"->",
"s",
")",
";",
"}"
] |
The frequency with which this response was given.
@param object $response contains the data to display.
@return string contents of this table cell.
|
[
"The",
"frequency",
"with",
"which",
"this",
"response",
"was",
"given",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/statistics/statistics_question_table.php#L157-L162
|
220,177
|
moodle/moodle
|
lib/classes/session/memcached.php
|
memcached.connection_string_to_memcache_servers
|
protected static function connection_string_to_memcache_servers(string $str) : array {
$servers = [];
$parts = explode(',', $str);
foreach ($parts as $part) {
$part = trim($part);
$pos = strrpos($part, ':');
if ($pos !== false) {
$host = substr($part, 0, $pos);
$port = substr($part, ($pos + 1));
} else {
$host = $part;
$port = 11211;
}
$servers[] = [$host, $port];
}
return $servers;
}
|
php
|
protected static function connection_string_to_memcache_servers(string $str) : array {
$servers = [];
$parts = explode(',', $str);
foreach ($parts as $part) {
$part = trim($part);
$pos = strrpos($part, ':');
if ($pos !== false) {
$host = substr($part, 0, $pos);
$port = substr($part, ($pos + 1));
} else {
$host = $part;
$port = 11211;
}
$servers[] = [$host, $port];
}
return $servers;
}
|
[
"protected",
"static",
"function",
"connection_string_to_memcache_servers",
"(",
"string",
"$",
"str",
")",
":",
"array",
"{",
"$",
"servers",
"=",
"[",
"]",
";",
"$",
"parts",
"=",
"explode",
"(",
"','",
",",
"$",
"str",
")",
";",
"foreach",
"(",
"$",
"parts",
"as",
"$",
"part",
")",
"{",
"$",
"part",
"=",
"trim",
"(",
"$",
"part",
")",
";",
"$",
"pos",
"=",
"strrpos",
"(",
"$",
"part",
",",
"':'",
")",
";",
"if",
"(",
"$",
"pos",
"!==",
"false",
")",
"{",
"$",
"host",
"=",
"substr",
"(",
"$",
"part",
",",
"0",
",",
"$",
"pos",
")",
";",
"$",
"port",
"=",
"substr",
"(",
"$",
"part",
",",
"(",
"$",
"pos",
"+",
"1",
")",
")",
";",
"}",
"else",
"{",
"$",
"host",
"=",
"$",
"part",
";",
"$",
"port",
"=",
"11211",
";",
"}",
"$",
"servers",
"[",
"]",
"=",
"[",
"$",
"host",
",",
"$",
"port",
"]",
";",
"}",
"return",
"$",
"servers",
";",
"}"
] |
Convert a connection string to an array of servers.
"abc:123, xyz:789" to
[
['abc', '123'],
['xyz', '789'],
]
@param string $str save_path value containing memcached connection string
@return array[]
|
[
"Convert",
"a",
"connection",
"string",
"to",
"an",
"array",
"of",
"servers",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/session/memcached.php#L283-L299
|
220,178
|
moodle/moodle
|
lib/pear/HTML/QuickForm/Rule/Callback.php
|
HTML_QuickForm_Rule_Callback.validate
|
function validate($value, $options = null)
{
if (isset($this->_data[$this->name])) {
$callback = $this->_data[$this->name];
if (isset($callback[1])) {
return call_user_func(array($callback[1], $callback[0]), $value, $options);
} elseif ($this->_BCMode[$this->name]) {
return $callback[0]('', $value, $options);
} else {
return $callback[0]($value, $options);
}
} elseif (is_callable($options)) {
return call_user_func($options, $value);
} else {
return true;
}
}
|
php
|
function validate($value, $options = null)
{
if (isset($this->_data[$this->name])) {
$callback = $this->_data[$this->name];
if (isset($callback[1])) {
return call_user_func(array($callback[1], $callback[0]), $value, $options);
} elseif ($this->_BCMode[$this->name]) {
return $callback[0]('', $value, $options);
} else {
return $callback[0]($value, $options);
}
} elseif (is_callable($options)) {
return call_user_func($options, $value);
} else {
return true;
}
}
|
[
"function",
"validate",
"(",
"$",
"value",
",",
"$",
"options",
"=",
"null",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_data",
"[",
"$",
"this",
"->",
"name",
"]",
")",
")",
"{",
"$",
"callback",
"=",
"$",
"this",
"->",
"_data",
"[",
"$",
"this",
"->",
"name",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"callback",
"[",
"1",
"]",
")",
")",
"{",
"return",
"call_user_func",
"(",
"array",
"(",
"$",
"callback",
"[",
"1",
"]",
",",
"$",
"callback",
"[",
"0",
"]",
")",
",",
"$",
"value",
",",
"$",
"options",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"_BCMode",
"[",
"$",
"this",
"->",
"name",
"]",
")",
"{",
"return",
"$",
"callback",
"[",
"0",
"]",
"(",
"''",
",",
"$",
"value",
",",
"$",
"options",
")",
";",
"}",
"else",
"{",
"return",
"$",
"callback",
"[",
"0",
"]",
"(",
"$",
"value",
",",
"$",
"options",
")",
";",
"}",
"}",
"elseif",
"(",
"is_callable",
"(",
"$",
"options",
")",
")",
"{",
"return",
"call_user_func",
"(",
"$",
"options",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"return",
"true",
";",
"}",
"}"
] |
Validates a value using a callback
@param string $value Value to be checked
@param mixed $options Options for callback
@access public
@return boolean true if value is valid
|
[
"Validates",
"a",
"value",
"using",
"a",
"callback"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/Rule/Callback.php#L61-L77
|
220,179
|
moodle/moodle
|
lib/pear/HTML/QuickForm/Rule/Callback.php
|
HTML_QuickForm_Rule_Callback.addData
|
function addData($name, $callback, $class = null, $BCMode = false)
{
if (!empty($class)) {
$this->_data[$name] = array($callback, $class);
} else {
$this->_data[$name] = array($callback);
}
$this->_BCMode[$name] = $BCMode;
}
|
php
|
function addData($name, $callback, $class = null, $BCMode = false)
{
if (!empty($class)) {
$this->_data[$name] = array($callback, $class);
} else {
$this->_data[$name] = array($callback);
}
$this->_BCMode[$name] = $BCMode;
}
|
[
"function",
"addData",
"(",
"$",
"name",
",",
"$",
"callback",
",",
"$",
"class",
"=",
"null",
",",
"$",
"BCMode",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"class",
")",
")",
"{",
"$",
"this",
"->",
"_data",
"[",
"$",
"name",
"]",
"=",
"array",
"(",
"$",
"callback",
",",
"$",
"class",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_data",
"[",
"$",
"name",
"]",
"=",
"array",
"(",
"$",
"callback",
")",
";",
"}",
"$",
"this",
"->",
"_BCMode",
"[",
"$",
"name",
"]",
"=",
"$",
"BCMode",
";",
"}"
] |
Adds new callbacks to the callbacks list
@param string $name Name of rule
@param string $callback Name of function or method
@param string $class Name of class containing the method
@param bool $BCMode Backwards compatibility mode
@access public
|
[
"Adds",
"new",
"callbacks",
"to",
"the",
"callbacks",
"list"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/Rule/Callback.php#L88-L96
|
220,180
|
moodle/moodle
|
blog/external_blog_edit_form.php
|
blog_edit_external_form.validation
|
public function validation($data, $files) {
global $CFG;
$errors = parent::validation($data, $files);
require_once($CFG->libdir . '/simplepie/moodle_simplepie.php');
$rss = new moodle_simplepie();
$rssfile = $rss->registry->create('File', array($data['url']));
$filetest = $rss->registry->create('Locator', array($rssfile));
if (!$filetest->is_feed($rssfile)) {
$errors['url'] = get_string('feedisinvalid', 'blog');
} else {
$rss->set_feed_url($data['url']);
if (!$rss->init()) {
$errors['url'] = get_string('emptyrssfeed', 'blog');
}
}
return $errors;
}
|
php
|
public function validation($data, $files) {
global $CFG;
$errors = parent::validation($data, $files);
require_once($CFG->libdir . '/simplepie/moodle_simplepie.php');
$rss = new moodle_simplepie();
$rssfile = $rss->registry->create('File', array($data['url']));
$filetest = $rss->registry->create('Locator', array($rssfile));
if (!$filetest->is_feed($rssfile)) {
$errors['url'] = get_string('feedisinvalid', 'blog');
} else {
$rss->set_feed_url($data['url']);
if (!$rss->init()) {
$errors['url'] = get_string('emptyrssfeed', 'blog');
}
}
return $errors;
}
|
[
"public",
"function",
"validation",
"(",
"$",
"data",
",",
"$",
"files",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"errors",
"=",
"parent",
"::",
"validation",
"(",
"$",
"data",
",",
"$",
"files",
")",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"libdir",
".",
"'/simplepie/moodle_simplepie.php'",
")",
";",
"$",
"rss",
"=",
"new",
"moodle_simplepie",
"(",
")",
";",
"$",
"rssfile",
"=",
"$",
"rss",
"->",
"registry",
"->",
"create",
"(",
"'File'",
",",
"array",
"(",
"$",
"data",
"[",
"'url'",
"]",
")",
")",
";",
"$",
"filetest",
"=",
"$",
"rss",
"->",
"registry",
"->",
"create",
"(",
"'Locator'",
",",
"array",
"(",
"$",
"rssfile",
")",
")",
";",
"if",
"(",
"!",
"$",
"filetest",
"->",
"is_feed",
"(",
"$",
"rssfile",
")",
")",
"{",
"$",
"errors",
"[",
"'url'",
"]",
"=",
"get_string",
"(",
"'feedisinvalid'",
",",
"'blog'",
")",
";",
"}",
"else",
"{",
"$",
"rss",
"->",
"set_feed_url",
"(",
"$",
"data",
"[",
"'url'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"rss",
"->",
"init",
"(",
")",
")",
"{",
"$",
"errors",
"[",
"'url'",
"]",
"=",
"get_string",
"(",
"'emptyrssfeed'",
",",
"'blog'",
")",
";",
"}",
"}",
"return",
"$",
"errors",
";",
"}"
] |
Additional validation includes checking URL and tags
|
[
"Additional",
"validation",
"includes",
"checking",
"URL",
"and",
"tags"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blog/external_blog_edit_form.php#L74-L95
|
220,181
|
moodle/moodle
|
mod/assign/feedback/editpdf/fpdi/fpdi_bridge.php
|
fpdi_bridge._getxobjectdict
|
protected function _getxobjectdict()
{
$out = parent::_getxobjectdict();
foreach ($this->_tpls as $tplIdx => $tpl) {
$out .= sprintf('%s%d %d 0 R', $this->tplPrefix, $tplIdx, $tpl['n']);
}
return $out;
}
|
php
|
protected function _getxobjectdict()
{
$out = parent::_getxobjectdict();
foreach ($this->_tpls as $tplIdx => $tpl) {
$out .= sprintf('%s%d %d 0 R', $this->tplPrefix, $tplIdx, $tpl['n']);
}
return $out;
}
|
[
"protected",
"function",
"_getxobjectdict",
"(",
")",
"{",
"$",
"out",
"=",
"parent",
"::",
"_getxobjectdict",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"_tpls",
"as",
"$",
"tplIdx",
"=>",
"$",
"tpl",
")",
"{",
"$",
"out",
".=",
"sprintf",
"(",
"'%s%d %d 0 R'",
",",
"$",
"this",
"->",
"tplPrefix",
",",
"$",
"tplIdx",
",",
"$",
"tpl",
"[",
"'n'",
"]",
")",
";",
"}",
"return",
"$",
"out",
";",
"}"
] |
Return XObjects Dictionary.
Overwritten to add additional XObjects to the resources dictionary of TCPDF
@return string
|
[
"Return",
"XObjects",
"Dictionary",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/fpdi/fpdi_bridge.php#L54-L62
|
220,182
|
moodle/moodle
|
mod/assign/feedback/editpdf/fpdi/fpdi_bridge.php
|
fpdi_bridge._prepareValue
|
protected function _prepareValue(&$value)
{
switch ($value[0]) {
case pdf_parser::TYPE_STRING:
if ($this->encrypted) {
$value[1] = $this->_unescape($value[1]);
$value[1] = $this->_encrypt_data($this->_currentObjId, $value[1]);
$value[1] = TCPDF_STATIC::_escape($value[1]);
}
break;
case pdf_parser::TYPE_STREAM:
if ($this->encrypted) {
$value[2][1] = $this->_encrypt_data($this->_currentObjId, $value[2][1]);
$value[1][1]['/Length'] = array(
pdf_parser::TYPE_NUMERIC,
strlen($value[2][1])
);
}
break;
case pdf_parser::TYPE_HEX:
if ($this->encrypted) {
$value[1] = $this->hex2str($value[1]);
$value[1] = $this->_encrypt_data($this->_currentObjId, $value[1]);
// remake hexstring of encrypted string
$value[1] = $this->str2hex($value[1]);
}
break;
}
}
|
php
|
protected function _prepareValue(&$value)
{
switch ($value[0]) {
case pdf_parser::TYPE_STRING:
if ($this->encrypted) {
$value[1] = $this->_unescape($value[1]);
$value[1] = $this->_encrypt_data($this->_currentObjId, $value[1]);
$value[1] = TCPDF_STATIC::_escape($value[1]);
}
break;
case pdf_parser::TYPE_STREAM:
if ($this->encrypted) {
$value[2][1] = $this->_encrypt_data($this->_currentObjId, $value[2][1]);
$value[1][1]['/Length'] = array(
pdf_parser::TYPE_NUMERIC,
strlen($value[2][1])
);
}
break;
case pdf_parser::TYPE_HEX:
if ($this->encrypted) {
$value[1] = $this->hex2str($value[1]);
$value[1] = $this->_encrypt_data($this->_currentObjId, $value[1]);
// remake hexstring of encrypted string
$value[1] = $this->str2hex($value[1]);
}
break;
}
}
|
[
"protected",
"function",
"_prepareValue",
"(",
"&",
"$",
"value",
")",
"{",
"switch",
"(",
"$",
"value",
"[",
"0",
"]",
")",
"{",
"case",
"pdf_parser",
"::",
"TYPE_STRING",
":",
"if",
"(",
"$",
"this",
"->",
"encrypted",
")",
"{",
"$",
"value",
"[",
"1",
"]",
"=",
"$",
"this",
"->",
"_unescape",
"(",
"$",
"value",
"[",
"1",
"]",
")",
";",
"$",
"value",
"[",
"1",
"]",
"=",
"$",
"this",
"->",
"_encrypt_data",
"(",
"$",
"this",
"->",
"_currentObjId",
",",
"$",
"value",
"[",
"1",
"]",
")",
";",
"$",
"value",
"[",
"1",
"]",
"=",
"TCPDF_STATIC",
"::",
"_escape",
"(",
"$",
"value",
"[",
"1",
"]",
")",
";",
"}",
"break",
";",
"case",
"pdf_parser",
"::",
"TYPE_STREAM",
":",
"if",
"(",
"$",
"this",
"->",
"encrypted",
")",
"{",
"$",
"value",
"[",
"2",
"]",
"[",
"1",
"]",
"=",
"$",
"this",
"->",
"_encrypt_data",
"(",
"$",
"this",
"->",
"_currentObjId",
",",
"$",
"value",
"[",
"2",
"]",
"[",
"1",
"]",
")",
";",
"$",
"value",
"[",
"1",
"]",
"[",
"1",
"]",
"[",
"'/Length'",
"]",
"=",
"array",
"(",
"pdf_parser",
"::",
"TYPE_NUMERIC",
",",
"strlen",
"(",
"$",
"value",
"[",
"2",
"]",
"[",
"1",
"]",
")",
")",
";",
"}",
"break",
";",
"case",
"pdf_parser",
"::",
"TYPE_HEX",
":",
"if",
"(",
"$",
"this",
"->",
"encrypted",
")",
"{",
"$",
"value",
"[",
"1",
"]",
"=",
"$",
"this",
"->",
"hex2str",
"(",
"$",
"value",
"[",
"1",
"]",
")",
";",
"$",
"value",
"[",
"1",
"]",
"=",
"$",
"this",
"->",
"_encrypt_data",
"(",
"$",
"this",
"->",
"_currentObjId",
",",
"$",
"value",
"[",
"1",
"]",
")",
";",
"// remake hexstring of encrypted string",
"$",
"value",
"[",
"1",
"]",
"=",
"$",
"this",
"->",
"str2hex",
"(",
"$",
"value",
"[",
"1",
"]",
")",
";",
"}",
"break",
";",
"}",
"}"
] |
Writes a PDF value to the resulting document.
Prepares the value for encryption of imported data by FPDI
@param array $value
|
[
"Writes",
"a",
"PDF",
"value",
"to",
"the",
"resulting",
"document",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/fpdi/fpdi_bridge.php#L71-L102
|
220,183
|
moodle/moodle
|
mod/assign/feedback/editpdf/fpdi/fpdi_bridge.php
|
fpdi_bridge._unescape
|
protected function _unescape($s)
{
$out = '';
for ($count = 0, $n = strlen($s); $count < $n; $count++) {
if ($s[$count] != '\\' || $count == $n-1) {
$out .= $s[$count];
} else {
switch ($s[++$count]) {
case ')':
case '(':
case '\\':
$out .= $s[$count];
break;
case 'f':
$out .= chr(0x0C);
break;
case 'b':
$out .= chr(0x08);
break;
case 't':
$out .= chr(0x09);
break;
case 'r':
$out .= chr(0x0D);
break;
case 'n':
$out .= chr(0x0A);
break;
case "\r":
if ($count != $n-1 && $s[$count+1] == "\n")
$count++;
break;
case "\n":
break;
default:
// Octal-Values
if (ord($s[$count]) >= ord('0') &&
ord($s[$count]) <= ord('9')) {
$oct = ''. $s[$count];
if (ord($s[$count+1]) >= ord('0') &&
ord($s[$count+1]) <= ord('9')) {
$oct .= $s[++$count];
if (ord($s[$count+1]) >= ord('0') &&
ord($s[$count+1]) <= ord('9')) {
$oct .= $s[++$count];
}
}
$out .= chr(octdec($oct));
} else {
$out .= $s[$count];
}
}
}
}
return $out;
}
|
php
|
protected function _unescape($s)
{
$out = '';
for ($count = 0, $n = strlen($s); $count < $n; $count++) {
if ($s[$count] != '\\' || $count == $n-1) {
$out .= $s[$count];
} else {
switch ($s[++$count]) {
case ')':
case '(':
case '\\':
$out .= $s[$count];
break;
case 'f':
$out .= chr(0x0C);
break;
case 'b':
$out .= chr(0x08);
break;
case 't':
$out .= chr(0x09);
break;
case 'r':
$out .= chr(0x0D);
break;
case 'n':
$out .= chr(0x0A);
break;
case "\r":
if ($count != $n-1 && $s[$count+1] == "\n")
$count++;
break;
case "\n":
break;
default:
// Octal-Values
if (ord($s[$count]) >= ord('0') &&
ord($s[$count]) <= ord('9')) {
$oct = ''. $s[$count];
if (ord($s[$count+1]) >= ord('0') &&
ord($s[$count+1]) <= ord('9')) {
$oct .= $s[++$count];
if (ord($s[$count+1]) >= ord('0') &&
ord($s[$count+1]) <= ord('9')) {
$oct .= $s[++$count];
}
}
$out .= chr(octdec($oct));
} else {
$out .= $s[$count];
}
}
}
}
return $out;
}
|
[
"protected",
"function",
"_unescape",
"(",
"$",
"s",
")",
"{",
"$",
"out",
"=",
"''",
";",
"for",
"(",
"$",
"count",
"=",
"0",
",",
"$",
"n",
"=",
"strlen",
"(",
"$",
"s",
")",
";",
"$",
"count",
"<",
"$",
"n",
";",
"$",
"count",
"++",
")",
"{",
"if",
"(",
"$",
"s",
"[",
"$",
"count",
"]",
"!=",
"'\\\\'",
"||",
"$",
"count",
"==",
"$",
"n",
"-",
"1",
")",
"{",
"$",
"out",
".=",
"$",
"s",
"[",
"$",
"count",
"]",
";",
"}",
"else",
"{",
"switch",
"(",
"$",
"s",
"[",
"++",
"$",
"count",
"]",
")",
"{",
"case",
"')'",
":",
"case",
"'('",
":",
"case",
"'\\\\'",
":",
"$",
"out",
".=",
"$",
"s",
"[",
"$",
"count",
"]",
";",
"break",
";",
"case",
"'f'",
":",
"$",
"out",
".=",
"chr",
"(",
"0x0C",
")",
";",
"break",
";",
"case",
"'b'",
":",
"$",
"out",
".=",
"chr",
"(",
"0x08",
")",
";",
"break",
";",
"case",
"'t'",
":",
"$",
"out",
".=",
"chr",
"(",
"0x09",
")",
";",
"break",
";",
"case",
"'r'",
":",
"$",
"out",
".=",
"chr",
"(",
"0x0D",
")",
";",
"break",
";",
"case",
"'n'",
":",
"$",
"out",
".=",
"chr",
"(",
"0x0A",
")",
";",
"break",
";",
"case",
"\"\\r\"",
":",
"if",
"(",
"$",
"count",
"!=",
"$",
"n",
"-",
"1",
"&&",
"$",
"s",
"[",
"$",
"count",
"+",
"1",
"]",
"==",
"\"\\n\"",
")",
"$",
"count",
"++",
";",
"break",
";",
"case",
"\"\\n\"",
":",
"break",
";",
"default",
":",
"// Octal-Values",
"if",
"(",
"ord",
"(",
"$",
"s",
"[",
"$",
"count",
"]",
")",
">=",
"ord",
"(",
"'0'",
")",
"&&",
"ord",
"(",
"$",
"s",
"[",
"$",
"count",
"]",
")",
"<=",
"ord",
"(",
"'9'",
")",
")",
"{",
"$",
"oct",
"=",
"''",
".",
"$",
"s",
"[",
"$",
"count",
"]",
";",
"if",
"(",
"ord",
"(",
"$",
"s",
"[",
"$",
"count",
"+",
"1",
"]",
")",
">=",
"ord",
"(",
"'0'",
")",
"&&",
"ord",
"(",
"$",
"s",
"[",
"$",
"count",
"+",
"1",
"]",
")",
"<=",
"ord",
"(",
"'9'",
")",
")",
"{",
"$",
"oct",
".=",
"$",
"s",
"[",
"++",
"$",
"count",
"]",
";",
"if",
"(",
"ord",
"(",
"$",
"s",
"[",
"$",
"count",
"+",
"1",
"]",
")",
">=",
"ord",
"(",
"'0'",
")",
"&&",
"ord",
"(",
"$",
"s",
"[",
"$",
"count",
"+",
"1",
"]",
")",
"<=",
"ord",
"(",
"'9'",
")",
")",
"{",
"$",
"oct",
".=",
"$",
"s",
"[",
"++",
"$",
"count",
"]",
";",
"}",
"}",
"$",
"out",
".=",
"chr",
"(",
"octdec",
"(",
"$",
"oct",
")",
")",
";",
"}",
"else",
"{",
"$",
"out",
".=",
"$",
"s",
"[",
"$",
"count",
"]",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"out",
";",
"}"
] |
Un-escapes a PDF string
@param string $s
@return string
|
[
"Un",
"-",
"escapes",
"a",
"PDF",
"string"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/fpdi/fpdi_bridge.php#L110-L168
|
220,184
|
moodle/moodle
|
mod/assign/feedback/editpdf/fpdi/fpdi_bridge.php
|
fpdi_bridge.hex2str
|
public function hex2str($data)
{
$data = preg_replace('/[^0-9A-Fa-f]/', '', rtrim($data, '>'));
if ((strlen($data) % 2) == 1) {
$data .= '0';
}
return pack('H*', $data);
}
|
php
|
public function hex2str($data)
{
$data = preg_replace('/[^0-9A-Fa-f]/', '', rtrim($data, '>'));
if ((strlen($data) % 2) == 1) {
$data .= '0';
}
return pack('H*', $data);
}
|
[
"public",
"function",
"hex2str",
"(",
"$",
"data",
")",
"{",
"$",
"data",
"=",
"preg_replace",
"(",
"'/[^0-9A-Fa-f]/'",
",",
"''",
",",
"rtrim",
"(",
"$",
"data",
",",
"'>'",
")",
")",
";",
"if",
"(",
"(",
"strlen",
"(",
"$",
"data",
")",
"%",
"2",
")",
"==",
"1",
")",
"{",
"$",
"data",
".=",
"'0'",
";",
"}",
"return",
"pack",
"(",
"'H*'",
",",
"$",
"data",
")",
";",
"}"
] |
Hexadecimal to string
@param string $data
@return string
|
[
"Hexadecimal",
"to",
"string"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/fpdi/fpdi_bridge.php#L176-L184
|
220,185
|
moodle/moodle
|
mod/forum/classes/local/factories/url.php
|
url.get_forum_view_url_from_forum
|
public function get_forum_view_url_from_forum(forum_entity $forum, ?int $pageno = null,
?int $sortorder = null) : moodle_url {
return $this->get_forum_view_url_from_course_module_id($forum->get_course_module_record()->id, $pageno, $sortorder);
}
|
php
|
public function get_forum_view_url_from_forum(forum_entity $forum, ?int $pageno = null,
?int $sortorder = null) : moodle_url {
return $this->get_forum_view_url_from_course_module_id($forum->get_course_module_record()->id, $pageno, $sortorder);
}
|
[
"public",
"function",
"get_forum_view_url_from_forum",
"(",
"forum_entity",
"$",
"forum",
",",
"?",
"int",
"$",
"pageno",
"=",
"null",
",",
"?",
"int",
"$",
"sortorder",
"=",
"null",
")",
":",
"moodle_url",
"{",
"return",
"$",
"this",
"->",
"get_forum_view_url_from_course_module_id",
"(",
"$",
"forum",
"->",
"get_course_module_record",
"(",
")",
"->",
"id",
",",
"$",
"pageno",
",",
"$",
"sortorder",
")",
";",
"}"
] |
Get the view forum url for the given forum and optionally a page number.
@param forum_entity $forum The forum entity
@param int|null $pageno The page number
@param int|null $sortorder The sorting order
@return moodle_url
|
[
"Get",
"the",
"view",
"forum",
"url",
"for",
"the",
"given",
"forum",
"and",
"optionally",
"a",
"page",
"number",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/url.php#L101-L105
|
220,186
|
moodle/moodle
|
mod/forum/classes/local/factories/url.php
|
url.get_forum_view_url_from_course_module_id
|
public function get_forum_view_url_from_course_module_id(int $coursemoduleid, ?int $pageno = null,
?int $sortorder = null) : moodle_url {
$url = new moodle_url('/mod/forum/view.php', [
'id' => $coursemoduleid,
]);
if (null !== $pageno) {
$url->param('p', $pageno);
}
if (null !== $sortorder) {
$url->param('o', $sortorder);
}
return $url;
}
|
php
|
public function get_forum_view_url_from_course_module_id(int $coursemoduleid, ?int $pageno = null,
?int $sortorder = null) : moodle_url {
$url = new moodle_url('/mod/forum/view.php', [
'id' => $coursemoduleid,
]);
if (null !== $pageno) {
$url->param('p', $pageno);
}
if (null !== $sortorder) {
$url->param('o', $sortorder);
}
return $url;
}
|
[
"public",
"function",
"get_forum_view_url_from_course_module_id",
"(",
"int",
"$",
"coursemoduleid",
",",
"?",
"int",
"$",
"pageno",
"=",
"null",
",",
"?",
"int",
"$",
"sortorder",
"=",
"null",
")",
":",
"moodle_url",
"{",
"$",
"url",
"=",
"new",
"moodle_url",
"(",
"'/mod/forum/view.php'",
",",
"[",
"'id'",
"=>",
"$",
"coursemoduleid",
",",
"]",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"pageno",
")",
"{",
"$",
"url",
"->",
"param",
"(",
"'p'",
",",
"$",
"pageno",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"sortorder",
")",
"{",
"$",
"url",
"->",
"param",
"(",
"'o'",
",",
"$",
"sortorder",
")",
";",
"}",
"return",
"$",
"url",
";",
"}"
] |
Get the view forum url for the given course module id and optionally a page number.
@param int $coursemoduleid The course module id
@param int|null $pageno The page number
@param int|null $sortorder The sorting order
@return moodle_url
|
[
"Get",
"the",
"view",
"forum",
"url",
"for",
"the",
"given",
"course",
"module",
"id",
"and",
"optionally",
"a",
"page",
"number",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/url.php#L115-L131
|
220,187
|
moodle/moodle
|
mod/forum/classes/local/factories/url.php
|
url.get_discussion_view_first_unread_post_url_from_discussion
|
public function get_discussion_view_first_unread_post_url_from_discussion(discussion_entity $discussion) {
$viewurl = $this->get_discussion_view_url_from_discussion_id($discussion->get_id());
$viewurl->set_anchor('unread');
return $viewurl;
}
|
php
|
public function get_discussion_view_first_unread_post_url_from_discussion(discussion_entity $discussion) {
$viewurl = $this->get_discussion_view_url_from_discussion_id($discussion->get_id());
$viewurl->set_anchor('unread');
return $viewurl;
}
|
[
"public",
"function",
"get_discussion_view_first_unread_post_url_from_discussion",
"(",
"discussion_entity",
"$",
"discussion",
")",
"{",
"$",
"viewurl",
"=",
"$",
"this",
"->",
"get_discussion_view_url_from_discussion_id",
"(",
"$",
"discussion",
"->",
"get_id",
"(",
")",
")",
";",
"$",
"viewurl",
"->",
"set_anchor",
"(",
"'unread'",
")",
";",
"return",
"$",
"viewurl",
";",
"}"
] |
Get the url to view the first unread post in a discussion.
@param discussion_entity $discussion The discussion
@return moodle_url
|
[
"Get",
"the",
"url",
"to",
"view",
"the",
"first",
"unread",
"post",
"in",
"a",
"discussion",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/url.php#L161-L166
|
220,188
|
moodle/moodle
|
mod/forum/classes/local/factories/url.php
|
url.get_view_post_url_from_post_id
|
public function get_view_post_url_from_post_id(int $discussionid, int $postid) : moodle_url {
$url = $this->get_discussion_view_url_from_discussion_id($discussionid);
$url->set_anchor('p' . $postid);
return $url;
}
|
php
|
public function get_view_post_url_from_post_id(int $discussionid, int $postid) : moodle_url {
$url = $this->get_discussion_view_url_from_discussion_id($discussionid);
$url->set_anchor('p' . $postid);
return $url;
}
|
[
"public",
"function",
"get_view_post_url_from_post_id",
"(",
"int",
"$",
"discussionid",
",",
"int",
"$",
"postid",
")",
":",
"moodle_url",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"get_discussion_view_url_from_discussion_id",
"(",
"$",
"discussionid",
")",
";",
"$",
"url",
"->",
"set_anchor",
"(",
"'p'",
".",
"$",
"postid",
")",
";",
"return",
"$",
"url",
";",
"}"
] |
Get the url to view a discussion from a discussion id and post id.
@param int $discussionid The discussion id
@param int $postid The post id
@return moodle_url
|
[
"Get",
"the",
"url",
"to",
"view",
"a",
"discussion",
"from",
"a",
"discussion",
"id",
"and",
"post",
"id",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/url.php#L201-L205
|
220,189
|
moodle/moodle
|
mod/forum/classes/local/factories/url.php
|
url.get_view_post_url_from_post
|
public function get_view_post_url_from_post(post_entity $post) : moodle_url {
return $this->get_view_post_url_from_post_id($post->get_discussion_id(), $post->get_id());
}
|
php
|
public function get_view_post_url_from_post(post_entity $post) : moodle_url {
return $this->get_view_post_url_from_post_id($post->get_discussion_id(), $post->get_id());
}
|
[
"public",
"function",
"get_view_post_url_from_post",
"(",
"post_entity",
"$",
"post",
")",
":",
"moodle_url",
"{",
"return",
"$",
"this",
"->",
"get_view_post_url_from_post_id",
"(",
"$",
"post",
"->",
"get_discussion_id",
"(",
")",
",",
"$",
"post",
"->",
"get_id",
"(",
")",
")",
";",
"}"
] |
Get the url to view a post in the context of the rest of the discussion.
@param post_entity $post The post
@return moodle_url
|
[
"Get",
"the",
"url",
"to",
"view",
"a",
"post",
"in",
"the",
"context",
"of",
"the",
"rest",
"of",
"the",
"discussion",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/url.php#L213-L215
|
220,190
|
moodle/moodle
|
mod/forum/classes/local/factories/url.php
|
url.get_edit_post_url_from_post
|
public function get_edit_post_url_from_post(forum_entity $forum, post_entity $post) : moodle_url {
if ($forum->get_type() == 'single') {
return new moodle_url('/course/modedit.php', [
'update' => $forum->get_course_module_record()->id,
'sesskey' => sesskey(),
'return' => 1
]);
} else {
return new moodle_url('/mod/forum/post.php', [
'edit' => $post->get_id()
]);
}
}
|
php
|
public function get_edit_post_url_from_post(forum_entity $forum, post_entity $post) : moodle_url {
if ($forum->get_type() == 'single') {
return new moodle_url('/course/modedit.php', [
'update' => $forum->get_course_module_record()->id,
'sesskey' => sesskey(),
'return' => 1
]);
} else {
return new moodle_url('/mod/forum/post.php', [
'edit' => $post->get_id()
]);
}
}
|
[
"public",
"function",
"get_edit_post_url_from_post",
"(",
"forum_entity",
"$",
"forum",
",",
"post_entity",
"$",
"post",
")",
":",
"moodle_url",
"{",
"if",
"(",
"$",
"forum",
"->",
"get_type",
"(",
")",
"==",
"'single'",
")",
"{",
"return",
"new",
"moodle_url",
"(",
"'/course/modedit.php'",
",",
"[",
"'update'",
"=>",
"$",
"forum",
"->",
"get_course_module_record",
"(",
")",
"->",
"id",
",",
"'sesskey'",
"=>",
"sesskey",
"(",
")",
",",
"'return'",
"=>",
"1",
"]",
")",
";",
"}",
"else",
"{",
"return",
"new",
"moodle_url",
"(",
"'/mod/forum/post.php'",
",",
"[",
"'edit'",
"=>",
"$",
"post",
"->",
"get_id",
"(",
")",
"]",
")",
";",
"}",
"}"
] |
Get the url to edit a post.
@param forum_entity $forum The forum the post belongs to
@param post_entity $post The post
@return moodle_url
|
[
"Get",
"the",
"url",
"to",
"edit",
"a",
"post",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/url.php#L249-L261
|
220,191
|
moodle/moodle
|
mod/forum/classes/local/factories/url.php
|
url.get_mark_post_as_read_url_from_post
|
public function get_mark_post_as_read_url_from_post(post_entity $post, int $displaymode = FORUM_MODE_THREADED) : moodle_url {
$params = [
'd' => $post->get_discussion_id(),
'postid' => $post->get_id(),
'mark' => 'read'
];
$url = new moodle_url('/mod/forum/discuss.php', $params);
if ($displaymode == FORUM_MODE_THREADED) {
$url->param('parent', $post->get_parent_id());
} else {
$url->set_anchor('p' . $post->get_id());
}
return $url;
}
|
php
|
public function get_mark_post_as_read_url_from_post(post_entity $post, int $displaymode = FORUM_MODE_THREADED) : moodle_url {
$params = [
'd' => $post->get_discussion_id(),
'postid' => $post->get_id(),
'mark' => 'read'
];
$url = new moodle_url('/mod/forum/discuss.php', $params);
if ($displaymode == FORUM_MODE_THREADED) {
$url->param('parent', $post->get_parent_id());
} else {
$url->set_anchor('p' . $post->get_id());
}
return $url;
}
|
[
"public",
"function",
"get_mark_post_as_read_url_from_post",
"(",
"post_entity",
"$",
"post",
",",
"int",
"$",
"displaymode",
"=",
"FORUM_MODE_THREADED",
")",
":",
"moodle_url",
"{",
"$",
"params",
"=",
"[",
"'d'",
"=>",
"$",
"post",
"->",
"get_discussion_id",
"(",
")",
",",
"'postid'",
"=>",
"$",
"post",
"->",
"get_id",
"(",
")",
",",
"'mark'",
"=>",
"'read'",
"]",
";",
"$",
"url",
"=",
"new",
"moodle_url",
"(",
"'/mod/forum/discuss.php'",
",",
"$",
"params",
")",
";",
"if",
"(",
"$",
"displaymode",
"==",
"FORUM_MODE_THREADED",
")",
"{",
"$",
"url",
"->",
"param",
"(",
"'parent'",
",",
"$",
"post",
"->",
"get_parent_id",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"url",
"->",
"set_anchor",
"(",
"'p'",
".",
"$",
"post",
"->",
"get_id",
"(",
")",
")",
";",
"}",
"return",
"$",
"url",
";",
"}"
] |
Get the url to mark a post as read.
@param post_entity $post The post
@param int $displaymode The display mode to show the forum in after marking as read
@return moodle_url
|
[
"Get",
"the",
"url",
"to",
"mark",
"a",
"post",
"as",
"read",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/url.php#L328-L344
|
220,192
|
moodle/moodle
|
mod/forum/classes/local/factories/url.php
|
url.get_export_attachment_url_from_post_and_attachment
|
public function get_export_attachment_url_from_post_and_attachment(post_entity $post, stored_file $attachment) : ?moodle_url {
global $CFG;
require_once($CFG->libdir . '/portfoliolib.php');
$button = new \portfolio_add_button();
$button->set_callback_options(
'forum_portfolio_caller',
['postid' => $post->get_id(), 'attachment' => $attachment->get_id()],
'mod_forum'
);
$button->set_format_by_file($attachment);
$url = $button->to_html(PORTFOLIO_ADD_MOODLE_URL);
return $url ?: null;
}
|
php
|
public function get_export_attachment_url_from_post_and_attachment(post_entity $post, stored_file $attachment) : ?moodle_url {
global $CFG;
require_once($CFG->libdir . '/portfoliolib.php');
$button = new \portfolio_add_button();
$button->set_callback_options(
'forum_portfolio_caller',
['postid' => $post->get_id(), 'attachment' => $attachment->get_id()],
'mod_forum'
);
$button->set_format_by_file($attachment);
$url = $button->to_html(PORTFOLIO_ADD_MOODLE_URL);
return $url ?: null;
}
|
[
"public",
"function",
"get_export_attachment_url_from_post_and_attachment",
"(",
"post_entity",
"$",
"post",
",",
"stored_file",
"$",
"attachment",
")",
":",
"?",
"moodle_url",
"{",
"global",
"$",
"CFG",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"libdir",
".",
"'/portfoliolib.php'",
")",
";",
"$",
"button",
"=",
"new",
"\\",
"portfolio_add_button",
"(",
")",
";",
"$",
"button",
"->",
"set_callback_options",
"(",
"'forum_portfolio_caller'",
",",
"[",
"'postid'",
"=>",
"$",
"post",
"->",
"get_id",
"(",
")",
",",
"'attachment'",
"=>",
"$",
"attachment",
"->",
"get_id",
"(",
")",
"]",
",",
"'mod_forum'",
")",
";",
"$",
"button",
"->",
"set_format_by_file",
"(",
"$",
"attachment",
")",
";",
"$",
"url",
"=",
"$",
"button",
"->",
"to_html",
"(",
"PORTFOLIO_ADD_MOODLE_URL",
")",
";",
"return",
"$",
"url",
"?",
":",
"null",
";",
"}"
] |
Get the url to export attachments for a post.
@param post_entity $post The post
@param stored_file $attachment
@return moodle_url|null
|
[
"Get",
"the",
"url",
"to",
"export",
"attachments",
"for",
"a",
"post",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/url.php#L378-L391
|
220,193
|
moodle/moodle
|
mod/forum/classes/local/factories/url.php
|
url.get_author_profile_image_url
|
public function get_author_profile_image_url(author_entity $author, int $authorcontextid = null) : moodle_url {
global $PAGE;
$datamapper = $this->legacydatamapperfactory->get_author_data_mapper();
$record = $datamapper->to_legacy_object($author);
$record->contextid = $authorcontextid;
$userpicture = new user_picture($record);
$userpicture->size = 2;
return $userpicture->get_url($PAGE);
}
|
php
|
public function get_author_profile_image_url(author_entity $author, int $authorcontextid = null) : moodle_url {
global $PAGE;
$datamapper = $this->legacydatamapperfactory->get_author_data_mapper();
$record = $datamapper->to_legacy_object($author);
$record->contextid = $authorcontextid;
$userpicture = new user_picture($record);
$userpicture->size = 2;
return $userpicture->get_url($PAGE);
}
|
[
"public",
"function",
"get_author_profile_image_url",
"(",
"author_entity",
"$",
"author",
",",
"int",
"$",
"authorcontextid",
"=",
"null",
")",
":",
"moodle_url",
"{",
"global",
"$",
"PAGE",
";",
"$",
"datamapper",
"=",
"$",
"this",
"->",
"legacydatamapperfactory",
"->",
"get_author_data_mapper",
"(",
")",
";",
"$",
"record",
"=",
"$",
"datamapper",
"->",
"to_legacy_object",
"(",
"$",
"author",
")",
";",
"$",
"record",
"->",
"contextid",
"=",
"$",
"authorcontextid",
";",
"$",
"userpicture",
"=",
"new",
"user_picture",
"(",
"$",
"record",
")",
";",
"$",
"userpicture",
"->",
"size",
"=",
"2",
";",
"return",
"$",
"userpicture",
"->",
"get_url",
"(",
"$",
"PAGE",
")",
";",
"}"
] |
Get the url to view the author's profile image. The author's context id should be
provided to prevent the code from needing to load it.
@param author_entity $author The author
@param int|null $authorcontextid The author context id
@return moodle_url
|
[
"Get",
"the",
"url",
"to",
"view",
"the",
"author",
"s",
"profile",
"image",
".",
"The",
"author",
"s",
"context",
"id",
"should",
"be",
"provided",
"to",
"prevent",
"the",
"code",
"from",
"needing",
"to",
"load",
"it",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/url.php#L413-L423
|
220,194
|
moodle/moodle
|
mod/forum/classes/local/factories/url.php
|
url.get_mark_discussion_as_read_url_from_discussion
|
public function get_mark_discussion_as_read_url_from_discussion(
forum_entity $forum,
discussion_entity $discussion
) : moodle_url {
return new moodle_url('/mod/forum/markposts.php', [
'f' => $discussion->get_forum_id(),
'd' => $discussion->get_id(),
'mark' => 'read',
'sesskey' => sesskey(),
'return' => $this->get_forum_view_url_from_forum($forum)->out(),
]);
}
|
php
|
public function get_mark_discussion_as_read_url_from_discussion(
forum_entity $forum,
discussion_entity $discussion
) : moodle_url {
return new moodle_url('/mod/forum/markposts.php', [
'f' => $discussion->get_forum_id(),
'd' => $discussion->get_id(),
'mark' => 'read',
'sesskey' => sesskey(),
'return' => $this->get_forum_view_url_from_forum($forum)->out(),
]);
}
|
[
"public",
"function",
"get_mark_discussion_as_read_url_from_discussion",
"(",
"forum_entity",
"$",
"forum",
",",
"discussion_entity",
"$",
"discussion",
")",
":",
"moodle_url",
"{",
"return",
"new",
"moodle_url",
"(",
"'/mod/forum/markposts.php'",
",",
"[",
"'f'",
"=>",
"$",
"discussion",
"->",
"get_forum_id",
"(",
")",
",",
"'d'",
"=>",
"$",
"discussion",
"->",
"get_id",
"(",
")",
",",
"'mark'",
"=>",
"'read'",
",",
"'sesskey'",
"=>",
"sesskey",
"(",
")",
",",
"'return'",
"=>",
"$",
"this",
"->",
"get_forum_view_url_from_forum",
"(",
"$",
"forum",
")",
"->",
"out",
"(",
")",
",",
"]",
")",
";",
"}"
] |
Get the url to mark a discussion as read.
@param forum_entity $forum The forum that the discussion belongs to
@param discussion_entity $discussion The discussion
@return moodle_url
|
[
"Get",
"the",
"url",
"to",
"mark",
"a",
"discussion",
"as",
"read",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/url.php#L432-L443
|
220,195
|
moodle/moodle
|
mod/forum/classes/local/factories/url.php
|
url.get_mark_all_discussions_as_read_url
|
public function get_mark_all_discussions_as_read_url(forum_entity $forum) : moodle_url {
return new moodle_url('/mod/forum/markposts.php', [
'f' => $forum->get_id(),
'mark' => 'read',
'sesskey' => sesskey(),
'return' => $this->get_forum_view_url_from_forum($forum)->out(),
]);
}
|
php
|
public function get_mark_all_discussions_as_read_url(forum_entity $forum) : moodle_url {
return new moodle_url('/mod/forum/markposts.php', [
'f' => $forum->get_id(),
'mark' => 'read',
'sesskey' => sesskey(),
'return' => $this->get_forum_view_url_from_forum($forum)->out(),
]);
}
|
[
"public",
"function",
"get_mark_all_discussions_as_read_url",
"(",
"forum_entity",
"$",
"forum",
")",
":",
"moodle_url",
"{",
"return",
"new",
"moodle_url",
"(",
"'/mod/forum/markposts.php'",
",",
"[",
"'f'",
"=>",
"$",
"forum",
"->",
"get_id",
"(",
")",
",",
"'mark'",
"=>",
"'read'",
",",
"'sesskey'",
"=>",
"sesskey",
"(",
")",
",",
"'return'",
"=>",
"$",
"this",
"->",
"get_forum_view_url_from_forum",
"(",
"$",
"forum",
")",
"->",
"out",
"(",
")",
",",
"]",
")",
";",
"}"
] |
Get the url to mark all discussions as read.
@param forum_entity $forum The forum that the discussions belong to
@return moodle_url
|
[
"Get",
"the",
"url",
"to",
"mark",
"all",
"discussions",
"as",
"read",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/url.php#L451-L458
|
220,196
|
moodle/moodle
|
mod/forum/classes/local/factories/url.php
|
url.get_discussion_subscribe_url
|
public function get_discussion_subscribe_url(discussion_entity $discussion) : moodle_url {
return new moodle_url('/mod/forum/subscribe.php', [
'sesskey' => sesskey(),
'id' => $discussion->get_forum_id(),
'd' => $discussion->get_id()
]);
}
|
php
|
public function get_discussion_subscribe_url(discussion_entity $discussion) : moodle_url {
return new moodle_url('/mod/forum/subscribe.php', [
'sesskey' => sesskey(),
'id' => $discussion->get_forum_id(),
'd' => $discussion->get_id()
]);
}
|
[
"public",
"function",
"get_discussion_subscribe_url",
"(",
"discussion_entity",
"$",
"discussion",
")",
":",
"moodle_url",
"{",
"return",
"new",
"moodle_url",
"(",
"'/mod/forum/subscribe.php'",
",",
"[",
"'sesskey'",
"=>",
"sesskey",
"(",
")",
",",
"'id'",
"=>",
"$",
"discussion",
"->",
"get_forum_id",
"(",
")",
",",
"'d'",
"=>",
"$",
"discussion",
"->",
"get_id",
"(",
")",
"]",
")",
";",
"}"
] |
Get the url to subscribe to a discussion.
@param discussion_entity $discussion The discussion
@return moodle_url
|
[
"Get",
"the",
"url",
"to",
"subscribe",
"to",
"a",
"discussion",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/url.php#L466-L472
|
220,197
|
moodle/moodle
|
mod/forum/classes/local/factories/url.php
|
url.get_pin_discussion_url_from_discussion
|
public function get_pin_discussion_url_from_discussion(discussion_entity $discussion) : moodle_url {
return new moodle_url('discuss.php', [
'sesskey' => sesskey(),
'd' => $discussion->get_id(),
'pin' => $discussion->is_pinned() ? FORUM_DISCUSSION_UNPINNED : FORUM_DISCUSSION_PINNED
]);
}
|
php
|
public function get_pin_discussion_url_from_discussion(discussion_entity $discussion) : moodle_url {
return new moodle_url('discuss.php', [
'sesskey' => sesskey(),
'd' => $discussion->get_id(),
'pin' => $discussion->is_pinned() ? FORUM_DISCUSSION_UNPINNED : FORUM_DISCUSSION_PINNED
]);
}
|
[
"public",
"function",
"get_pin_discussion_url_from_discussion",
"(",
"discussion_entity",
"$",
"discussion",
")",
":",
"moodle_url",
"{",
"return",
"new",
"moodle_url",
"(",
"'discuss.php'",
",",
"[",
"'sesskey'",
"=>",
"sesskey",
"(",
")",
",",
"'d'",
"=>",
"$",
"discussion",
"->",
"get_id",
"(",
")",
",",
"'pin'",
"=>",
"$",
"discussion",
"->",
"is_pinned",
"(",
")",
"?",
"FORUM_DISCUSSION_UNPINNED",
":",
"FORUM_DISCUSSION_PINNED",
"]",
")",
";",
"}"
] |
Generate the pinned discussion link
@param discussion_entity $discussion
@return moodle_url
@throws \moodle_exception
|
[
"Generate",
"the",
"pinned",
"discussion",
"link"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/url.php#L481-L487
|
220,198
|
moodle/moodle
|
admin/tool/uploadcourse/classes/tracker.php
|
tool_uploadcourse_tracker.finish
|
public function finish() {
if ($this->outputmode == self::NO_OUTPUT) {
return;
}
if ($this->outputmode == self::OUTPUT_HTML) {
echo html_writer::end_tag('table');
}
}
|
php
|
public function finish() {
if ($this->outputmode == self::NO_OUTPUT) {
return;
}
if ($this->outputmode == self::OUTPUT_HTML) {
echo html_writer::end_tag('table');
}
}
|
[
"public",
"function",
"finish",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"outputmode",
"==",
"self",
"::",
"NO_OUTPUT",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"outputmode",
"==",
"self",
"::",
"OUTPUT_HTML",
")",
"{",
"echo",
"html_writer",
"::",
"end_tag",
"(",
"'table'",
")",
";",
"}",
"}"
] |
Finish the output.
@return void
|
[
"Finish",
"the",
"output",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/uploadcourse/classes/tracker.php#L89-L97
|
220,199
|
moodle/moodle
|
admin/tool/uploadcourse/classes/tracker.php
|
tool_uploadcourse_tracker.results
|
public function results($total, $created, $updated, $deleted, $errors) {
if ($this->outputmode == self::NO_OUTPUT) {
return;
}
$message = array(
get_string('coursestotal', 'tool_uploadcourse', $total),
get_string('coursescreated', 'tool_uploadcourse', $created),
get_string('coursesupdated', 'tool_uploadcourse', $updated),
get_string('coursesdeleted', 'tool_uploadcourse', $deleted),
get_string('courseserrors', 'tool_uploadcourse', $errors)
);
if ($this->outputmode == self::OUTPUT_PLAIN) {
foreach ($message as $msg) {
$this->buffer->output($msg);
}
} else if ($this->outputmode == self::OUTPUT_HTML) {
$buffer = new progress_trace_buffer(new html_list_progress_trace());
foreach ($message as $msg) {
$buffer->output($msg);
}
$buffer->finished();
}
}
|
php
|
public function results($total, $created, $updated, $deleted, $errors) {
if ($this->outputmode == self::NO_OUTPUT) {
return;
}
$message = array(
get_string('coursestotal', 'tool_uploadcourse', $total),
get_string('coursescreated', 'tool_uploadcourse', $created),
get_string('coursesupdated', 'tool_uploadcourse', $updated),
get_string('coursesdeleted', 'tool_uploadcourse', $deleted),
get_string('courseserrors', 'tool_uploadcourse', $errors)
);
if ($this->outputmode == self::OUTPUT_PLAIN) {
foreach ($message as $msg) {
$this->buffer->output($msg);
}
} else if ($this->outputmode == self::OUTPUT_HTML) {
$buffer = new progress_trace_buffer(new html_list_progress_trace());
foreach ($message as $msg) {
$buffer->output($msg);
}
$buffer->finished();
}
}
|
[
"public",
"function",
"results",
"(",
"$",
"total",
",",
"$",
"created",
",",
"$",
"updated",
",",
"$",
"deleted",
",",
"$",
"errors",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"outputmode",
"==",
"self",
"::",
"NO_OUTPUT",
")",
"{",
"return",
";",
"}",
"$",
"message",
"=",
"array",
"(",
"get_string",
"(",
"'coursestotal'",
",",
"'tool_uploadcourse'",
",",
"$",
"total",
")",
",",
"get_string",
"(",
"'coursescreated'",
",",
"'tool_uploadcourse'",
",",
"$",
"created",
")",
",",
"get_string",
"(",
"'coursesupdated'",
",",
"'tool_uploadcourse'",
",",
"$",
"updated",
")",
",",
"get_string",
"(",
"'coursesdeleted'",
",",
"'tool_uploadcourse'",
",",
"$",
"deleted",
")",
",",
"get_string",
"(",
"'courseserrors'",
",",
"'tool_uploadcourse'",
",",
"$",
"errors",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"outputmode",
"==",
"self",
"::",
"OUTPUT_PLAIN",
")",
"{",
"foreach",
"(",
"$",
"message",
"as",
"$",
"msg",
")",
"{",
"$",
"this",
"->",
"buffer",
"->",
"output",
"(",
"$",
"msg",
")",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"outputmode",
"==",
"self",
"::",
"OUTPUT_HTML",
")",
"{",
"$",
"buffer",
"=",
"new",
"progress_trace_buffer",
"(",
"new",
"html_list_progress_trace",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"message",
"as",
"$",
"msg",
")",
"{",
"$",
"buffer",
"->",
"output",
"(",
"$",
"msg",
")",
";",
"}",
"$",
"buffer",
"->",
"finished",
"(",
")",
";",
"}",
"}"
] |
Output the results.
@param int $total total courses.
@param int $created count of courses created.
@param int $updated count of courses updated.
@param int $deleted count of courses deleted.
@param int $errors count of errors.
@return void
|
[
"Output",
"the",
"results",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/uploadcourse/classes/tracker.php#L109-L133
|
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.