id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
|
|---|---|---|---|---|---|---|---|---|---|---|---|
217,500
|
moodle/moodle
|
lib/horde/framework/Horde/Imap/Client/Interaction/Pipeline.php
|
Horde_Imap_Client_Interaction_Pipeline.complete
|
public function complete(Horde_Imap_Client_Interaction_Server_Tagged $resp)
{
if (isset($this->_commands[$resp->tag])) {
$cmd = $this->_commands[$resp->tag];
$cmd->response = $resp;
unset($this->_todo[$resp->tag]);
} else {
/* This can be reached if a previous pipeline action was aborted,
* e.g. via an Exception. */
$cmd = null;
}
return $cmd;
}
|
php
|
public function complete(Horde_Imap_Client_Interaction_Server_Tagged $resp)
{
if (isset($this->_commands[$resp->tag])) {
$cmd = $this->_commands[$resp->tag];
$cmd->response = $resp;
unset($this->_todo[$resp->tag]);
} else {
/* This can be reached if a previous pipeline action was aborted,
* e.g. via an Exception. */
$cmd = null;
}
return $cmd;
}
|
[
"public",
"function",
"complete",
"(",
"Horde_Imap_Client_Interaction_Server_Tagged",
"$",
"resp",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_commands",
"[",
"$",
"resp",
"->",
"tag",
"]",
")",
")",
"{",
"$",
"cmd",
"=",
"$",
"this",
"->",
"_commands",
"[",
"$",
"resp",
"->",
"tag",
"]",
";",
"$",
"cmd",
"->",
"response",
"=",
"$",
"resp",
";",
"unset",
"(",
"$",
"this",
"->",
"_todo",
"[",
"$",
"resp",
"->",
"tag",
"]",
")",
";",
"}",
"else",
"{",
"/* This can be reached if a previous pipeline action was aborted,\n * e.g. via an Exception. */",
"$",
"cmd",
"=",
"null",
";",
"}",
"return",
"$",
"cmd",
";",
"}"
] |
Mark a command as completed.
@param Horde_Imap_Client_Interaction_Server_Tagged $resp Tagged server
response.
@return Horde_Imap_Client_Interaction_Command Command that was
completed. Returns null
if tagged response
is not contained in this
pipeline object.
|
[
"Mark",
"a",
"command",
"as",
"completed",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Interaction/Pipeline.php#L111-L124
|
217,501
|
moodle/moodle
|
lib/horde/framework/Horde/Imap/Client/Interaction/Pipeline.php
|
Horde_Imap_Client_Interaction_Pipeline.getCmd
|
public function getCmd($tag)
{
return isset($this->_commands[$tag])
? $this->_commands[$tag]
: null;
}
|
php
|
public function getCmd($tag)
{
return isset($this->_commands[$tag])
? $this->_commands[$tag]
: null;
}
|
[
"public",
"function",
"getCmd",
"(",
"$",
"tag",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"_commands",
"[",
"$",
"tag",
"]",
")",
"?",
"$",
"this",
"->",
"_commands",
"[",
"$",
"tag",
"]",
":",
"null",
";",
"}"
] |
Return the command for a given tag.
@param string $tag The command tag.
@return Horde_Imap_Client_Interaction_Command A command object (or
null if the tag does
not exist).
|
[
"Return",
"the",
"command",
"for",
"a",
"given",
"tag",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Interaction/Pipeline.php#L135-L140
|
217,502
|
moodle/moodle
|
mod/forum/classes/local/factories/entity.php
|
entity.get_author_from_stdclass
|
public function get_author_from_stdclass(stdClass $record) : author_entity {
return new author_entity(
$record->id,
$record->picture,
$record->firstname,
$record->lastname,
fullname($record),
$record->email,
$record->middlename,
$record->firstnamephonetic,
$record->lastnamephonetic,
$record->alternatename,
$record->imagealt
);
}
|
php
|
public function get_author_from_stdclass(stdClass $record) : author_entity {
return new author_entity(
$record->id,
$record->picture,
$record->firstname,
$record->lastname,
fullname($record),
$record->email,
$record->middlename,
$record->firstnamephonetic,
$record->lastnamephonetic,
$record->alternatename,
$record->imagealt
);
}
|
[
"public",
"function",
"get_author_from_stdclass",
"(",
"stdClass",
"$",
"record",
")",
":",
"author_entity",
"{",
"return",
"new",
"author_entity",
"(",
"$",
"record",
"->",
"id",
",",
"$",
"record",
"->",
"picture",
",",
"$",
"record",
"->",
"firstname",
",",
"$",
"record",
"->",
"lastname",
",",
"fullname",
"(",
"$",
"record",
")",
",",
"$",
"record",
"->",
"email",
",",
"$",
"record",
"->",
"middlename",
",",
"$",
"record",
"->",
"firstnamephonetic",
",",
"$",
"record",
"->",
"lastnamephonetic",
",",
"$",
"record",
"->",
"alternatename",
",",
"$",
"record",
"->",
"imagealt",
")",
";",
"}"
] |
Create an author entity from a user record.
@param stdClass $record The user record
@return author_entity
|
[
"Create",
"an",
"author",
"entity",
"from",
"a",
"user",
"record",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/entity.php#L167-L181
|
217,503
|
moodle/moodle
|
mod/forum/classes/local/factories/entity.php
|
entity.get_discussion_summary_from_stdclass
|
public function get_discussion_summary_from_stdclass(
stdClass $discussion,
stdClass $firstpost,
stdClass $firstpostauthor,
stdClass $latestpostauthor
) : discussion_summary_entity {
$firstpostauthorentity = $this->get_author_from_stdclass($firstpostauthor);
return new discussion_summary_entity(
$this->get_discussion_from_stdclass($discussion),
$this->get_post_from_stdclass($firstpost, $firstpostauthorentity),
$firstpostauthorentity,
$this->get_author_from_stdclass($latestpostauthor)
);
}
|
php
|
public function get_discussion_summary_from_stdclass(
stdClass $discussion,
stdClass $firstpost,
stdClass $firstpostauthor,
stdClass $latestpostauthor
) : discussion_summary_entity {
$firstpostauthorentity = $this->get_author_from_stdclass($firstpostauthor);
return new discussion_summary_entity(
$this->get_discussion_from_stdclass($discussion),
$this->get_post_from_stdclass($firstpost, $firstpostauthorentity),
$firstpostauthorentity,
$this->get_author_from_stdclass($latestpostauthor)
);
}
|
[
"public",
"function",
"get_discussion_summary_from_stdclass",
"(",
"stdClass",
"$",
"discussion",
",",
"stdClass",
"$",
"firstpost",
",",
"stdClass",
"$",
"firstpostauthor",
",",
"stdClass",
"$",
"latestpostauthor",
")",
":",
"discussion_summary_entity",
"{",
"$",
"firstpostauthorentity",
"=",
"$",
"this",
"->",
"get_author_from_stdclass",
"(",
"$",
"firstpostauthor",
")",
";",
"return",
"new",
"discussion_summary_entity",
"(",
"$",
"this",
"->",
"get_discussion_from_stdclass",
"(",
"$",
"discussion",
")",
",",
"$",
"this",
"->",
"get_post_from_stdclass",
"(",
"$",
"firstpost",
",",
"$",
"firstpostauthorentity",
")",
",",
"$",
"firstpostauthorentity",
",",
"$",
"this",
"->",
"get_author_from_stdclass",
"(",
"$",
"latestpostauthor",
")",
")",
";",
"}"
] |
Create a discussion summary enttiy from stdClasses.
@param stdClass $discussion The discussion record
@param stdClass $firstpost A post record for the first post in the discussion
@param stdClass $firstpostauthor A user record for the author of the first post
@param stdClass $latestpostauthor A user record for the author of the latest post in the discussion
@return discussion_summary_entity
|
[
"Create",
"a",
"discussion",
"summary",
"enttiy",
"from",
"stdClasses",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/entity.php#L192-L206
|
217,504
|
moodle/moodle
|
mod/forum/classes/local/factories/entity.php
|
entity.get_posts_sorter
|
public function get_posts_sorter() : sorter_entity {
return new sorter_entity(
// Get id function for a post_entity.
function(post_entity $post) {
return $post->get_id();
},
// Get parent id function for a post_entity.
function(post_entity $post) {
return $post->get_parent_id();
}
);
}
|
php
|
public function get_posts_sorter() : sorter_entity {
return new sorter_entity(
// Get id function for a post_entity.
function(post_entity $post) {
return $post->get_id();
},
// Get parent id function for a post_entity.
function(post_entity $post) {
return $post->get_parent_id();
}
);
}
|
[
"public",
"function",
"get_posts_sorter",
"(",
")",
":",
"sorter_entity",
"{",
"return",
"new",
"sorter_entity",
"(",
"// Get id function for a post_entity.",
"function",
"(",
"post_entity",
"$",
"post",
")",
"{",
"return",
"$",
"post",
"->",
"get_id",
"(",
")",
";",
"}",
",",
"// Get parent id function for a post_entity.",
"function",
"(",
"post_entity",
"$",
"post",
")",
"{",
"return",
"$",
"post",
"->",
"get_parent_id",
"(",
")",
";",
"}",
")",
";",
"}"
] |
Create a sorter entity to sort post entities.
@return sorter_entity
|
[
"Create",
"a",
"sorter",
"entity",
"to",
"sort",
"post",
"entities",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/entity.php#L223-L234
|
217,505
|
moodle/moodle
|
mod/forum/classes/local/factories/entity.php
|
entity.get_exported_posts_sorter
|
public function get_exported_posts_sorter() : sorter_entity {
return new sorter_entity(
// Get id function for an exported post.
function(stdClass $post) {
return $post->id;
},
// Get parent id function for an exported post.
function(stdClass $post) {
return $post->parentid;
}
);
}
|
php
|
public function get_exported_posts_sorter() : sorter_entity {
return new sorter_entity(
// Get id function for an exported post.
function(stdClass $post) {
return $post->id;
},
// Get parent id function for an exported post.
function(stdClass $post) {
return $post->parentid;
}
);
}
|
[
"public",
"function",
"get_exported_posts_sorter",
"(",
")",
":",
"sorter_entity",
"{",
"return",
"new",
"sorter_entity",
"(",
"// Get id function for an exported post.",
"function",
"(",
"stdClass",
"$",
"post",
")",
"{",
"return",
"$",
"post",
"->",
"id",
";",
"}",
",",
"// Get parent id function for an exported post.",
"function",
"(",
"stdClass",
"$",
"post",
")",
"{",
"return",
"$",
"post",
"->",
"parentid",
";",
"}",
")",
";",
"}"
] |
Create a sorter entity to sort exported posts.
@return sorter_entity
|
[
"Create",
"a",
"sorter",
"entity",
"to",
"sort",
"exported",
"posts",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/entity.php#L241-L252
|
217,506
|
moodle/moodle
|
lib/form/classes/filetypes_util.php
|
filetypes_util.is_filetype_group
|
public function is_filetype_group($type) {
$info = $this->get_groups_info();
if (isset($info[$type])) {
return $info[$type];
} else {
return false;
}
}
|
php
|
public function is_filetype_group($type) {
$info = $this->get_groups_info();
if (isset($info[$type])) {
return $info[$type];
} else {
return false;
}
}
|
[
"public",
"function",
"is_filetype_group",
"(",
"$",
"type",
")",
"{",
"$",
"info",
"=",
"$",
"this",
"->",
"get_groups_info",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"info",
"[",
"$",
"type",
"]",
")",
")",
"{",
"return",
"$",
"info",
"[",
"$",
"type",
"]",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] |
Is the given string a known filetype group?
@param string $type
@return bool|object false or the group info
|
[
"Is",
"the",
"given",
"string",
"a",
"known",
"filetype",
"group?"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/classes/filetypes_util.php#L136-L146
|
217,507
|
moodle/moodle
|
lib/form/classes/filetypes_util.php
|
filetypes_util.get_groups_info
|
public function get_groups_info() {
if ($this->cachegroups !== null) {
return $this->cachegroups;
}
$groups = [];
foreach (core_filetypes::get_types() as $ext => $info) {
if (isset($info['groups']) && is_array($info['groups'])) {
foreach ($info['groups'] as $group) {
if (!isset($groups[$group])) {
$groups[$group] = (object) [
'extensions' => [],
'mimetypes' => [],
];
}
$groups[$group]->extensions['.'.$ext] = true;
if (isset($info['type'])) {
$groups[$group]->mimetypes[$info['type']] = true;
}
}
}
}
foreach ($groups as $group => $info) {
$info->extensions = array_keys($info->extensions);
$info->mimetypes = array_keys($info->mimetypes);
}
$this->cachegroups = $groups;
return $this->cachegroups;
}
|
php
|
public function get_groups_info() {
if ($this->cachegroups !== null) {
return $this->cachegroups;
}
$groups = [];
foreach (core_filetypes::get_types() as $ext => $info) {
if (isset($info['groups']) && is_array($info['groups'])) {
foreach ($info['groups'] as $group) {
if (!isset($groups[$group])) {
$groups[$group] = (object) [
'extensions' => [],
'mimetypes' => [],
];
}
$groups[$group]->extensions['.'.$ext] = true;
if (isset($info['type'])) {
$groups[$group]->mimetypes[$info['type']] = true;
}
}
}
}
foreach ($groups as $group => $info) {
$info->extensions = array_keys($info->extensions);
$info->mimetypes = array_keys($info->mimetypes);
}
$this->cachegroups = $groups;
return $this->cachegroups;
}
|
[
"public",
"function",
"get_groups_info",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"cachegroups",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"cachegroups",
";",
"}",
"$",
"groups",
"=",
"[",
"]",
";",
"foreach",
"(",
"core_filetypes",
"::",
"get_types",
"(",
")",
"as",
"$",
"ext",
"=>",
"$",
"info",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"info",
"[",
"'groups'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"info",
"[",
"'groups'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"info",
"[",
"'groups'",
"]",
"as",
"$",
"group",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"groups",
"[",
"$",
"group",
"]",
")",
")",
"{",
"$",
"groups",
"[",
"$",
"group",
"]",
"=",
"(",
"object",
")",
"[",
"'extensions'",
"=>",
"[",
"]",
",",
"'mimetypes'",
"=>",
"[",
"]",
",",
"]",
";",
"}",
"$",
"groups",
"[",
"$",
"group",
"]",
"->",
"extensions",
"[",
"'.'",
".",
"$",
"ext",
"]",
"=",
"true",
";",
"if",
"(",
"isset",
"(",
"$",
"info",
"[",
"'type'",
"]",
")",
")",
"{",
"$",
"groups",
"[",
"$",
"group",
"]",
"->",
"mimetypes",
"[",
"$",
"info",
"[",
"'type'",
"]",
"]",
"=",
"true",
";",
"}",
"}",
"}",
"}",
"foreach",
"(",
"$",
"groups",
"as",
"$",
"group",
"=>",
"$",
"info",
")",
"{",
"$",
"info",
"->",
"extensions",
"=",
"array_keys",
"(",
"$",
"info",
"->",
"extensions",
")",
";",
"$",
"info",
"->",
"mimetypes",
"=",
"array_keys",
"(",
"$",
"info",
"->",
"mimetypes",
")",
";",
"}",
"$",
"this",
"->",
"cachegroups",
"=",
"$",
"groups",
";",
"return",
"$",
"this",
"->",
"cachegroups",
";",
"}"
] |
Provides a list of all known file type groups and their properties.
@return array
|
[
"Provides",
"a",
"list",
"of",
"all",
"known",
"file",
"type",
"groups",
"and",
"their",
"properties",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/classes/filetypes_util.php#L153-L185
|
217,508
|
moodle/moodle
|
lib/form/classes/filetypes_util.php
|
filetypes_util.describe_file_types
|
public function describe_file_types($types) {
$descriptions = [];
$types = $this->normalize_file_types($types);
foreach ($types as $type) {
if ($type === '*') {
$desc = get_string('filetypesany', 'core_form');
$descriptions[$desc] = [];
} else if ($group = $this->is_filetype_group($type)) {
$desc = $this->get_group_description($type);
$descriptions[$desc] = $group->extensions;
} else if ($this->looks_like_mimetype($type)) {
$desc = get_mimetype_description($type);
$descriptions[$desc] = file_get_typegroup('extension', [$type]);
} else {
$desc = get_mimetype_description(['filename' => 'fakefile'.$type]);
if (isset($descriptions[$desc])) {
$descriptions[$desc][] = $type;
} else {
$descriptions[$desc] = [$type];
}
}
}
$data = [];
foreach ($descriptions as $desc => $exts) {
sort($exts);
$data[] = (object)[
'description' => $desc,
'extensions' => join(' ', $exts),
];
}
core_collator::asort_objects_by_property($data, 'description', core_collator::SORT_NATURAL);
return (object)[
'hasdescriptions' => !empty($data),
'descriptions' => array_values($data),
];
}
|
php
|
public function describe_file_types($types) {
$descriptions = [];
$types = $this->normalize_file_types($types);
foreach ($types as $type) {
if ($type === '*') {
$desc = get_string('filetypesany', 'core_form');
$descriptions[$desc] = [];
} else if ($group = $this->is_filetype_group($type)) {
$desc = $this->get_group_description($type);
$descriptions[$desc] = $group->extensions;
} else if ($this->looks_like_mimetype($type)) {
$desc = get_mimetype_description($type);
$descriptions[$desc] = file_get_typegroup('extension', [$type]);
} else {
$desc = get_mimetype_description(['filename' => 'fakefile'.$type]);
if (isset($descriptions[$desc])) {
$descriptions[$desc][] = $type;
} else {
$descriptions[$desc] = [$type];
}
}
}
$data = [];
foreach ($descriptions as $desc => $exts) {
sort($exts);
$data[] = (object)[
'description' => $desc,
'extensions' => join(' ', $exts),
];
}
core_collator::asort_objects_by_property($data, 'description', core_collator::SORT_NATURAL);
return (object)[
'hasdescriptions' => !empty($data),
'descriptions' => array_values($data),
];
}
|
[
"public",
"function",
"describe_file_types",
"(",
"$",
"types",
")",
"{",
"$",
"descriptions",
"=",
"[",
"]",
";",
"$",
"types",
"=",
"$",
"this",
"->",
"normalize_file_types",
"(",
"$",
"types",
")",
";",
"foreach",
"(",
"$",
"types",
"as",
"$",
"type",
")",
"{",
"if",
"(",
"$",
"type",
"===",
"'*'",
")",
"{",
"$",
"desc",
"=",
"get_string",
"(",
"'filetypesany'",
",",
"'core_form'",
")",
";",
"$",
"descriptions",
"[",
"$",
"desc",
"]",
"=",
"[",
"]",
";",
"}",
"else",
"if",
"(",
"$",
"group",
"=",
"$",
"this",
"->",
"is_filetype_group",
"(",
"$",
"type",
")",
")",
"{",
"$",
"desc",
"=",
"$",
"this",
"->",
"get_group_description",
"(",
"$",
"type",
")",
";",
"$",
"descriptions",
"[",
"$",
"desc",
"]",
"=",
"$",
"group",
"->",
"extensions",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"looks_like_mimetype",
"(",
"$",
"type",
")",
")",
"{",
"$",
"desc",
"=",
"get_mimetype_description",
"(",
"$",
"type",
")",
";",
"$",
"descriptions",
"[",
"$",
"desc",
"]",
"=",
"file_get_typegroup",
"(",
"'extension'",
",",
"[",
"$",
"type",
"]",
")",
";",
"}",
"else",
"{",
"$",
"desc",
"=",
"get_mimetype_description",
"(",
"[",
"'filename'",
"=>",
"'fakefile'",
".",
"$",
"type",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"descriptions",
"[",
"$",
"desc",
"]",
")",
")",
"{",
"$",
"descriptions",
"[",
"$",
"desc",
"]",
"[",
"]",
"=",
"$",
"type",
";",
"}",
"else",
"{",
"$",
"descriptions",
"[",
"$",
"desc",
"]",
"=",
"[",
"$",
"type",
"]",
";",
"}",
"}",
"}",
"$",
"data",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"descriptions",
"as",
"$",
"desc",
"=>",
"$",
"exts",
")",
"{",
"sort",
"(",
"$",
"exts",
")",
";",
"$",
"data",
"[",
"]",
"=",
"(",
"object",
")",
"[",
"'description'",
"=>",
"$",
"desc",
",",
"'extensions'",
"=>",
"join",
"(",
"' '",
",",
"$",
"exts",
")",
",",
"]",
";",
"}",
"core_collator",
"::",
"asort_objects_by_property",
"(",
"$",
"data",
",",
"'description'",
",",
"core_collator",
"::",
"SORT_NATURAL",
")",
";",
"return",
"(",
"object",
")",
"[",
"'hasdescriptions'",
"=>",
"!",
"empty",
"(",
"$",
"data",
")",
",",
"'descriptions'",
"=>",
"array_values",
"(",
"$",
"data",
")",
",",
"]",
";",
"}"
] |
Describe the list of file types for human user.
Given the list of file types, return a list of human readable
descriptive names of relevant groups, types or file formats.
@param string|array $types
@return object
|
[
"Describe",
"the",
"list",
"of",
"file",
"types",
"for",
"human",
"user",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/classes/filetypes_util.php#L211-L254
|
217,509
|
moodle/moodle
|
lib/form/classes/filetypes_util.php
|
filetypes_util.expand
|
public function expand($types, $keepgroups=false, $keepmimetypes=false) {
$expanded = [];
foreach ($this->normalize_file_types($types) as $type) {
if ($group = $this->is_filetype_group($type)) {
foreach ($group->extensions as $ext) {
$expanded[$ext] = true;
}
if ($keepgroups) {
$expanded[$type] = true;
}
} else if ($this->looks_like_mimetype($type)) {
// A mime type expands to the associated extensions.
foreach (file_get_typegroup('extension', [$type]) as $ext) {
$expanded[$ext] = true;
}
if ($keepmimetypes) {
$expanded[$type] = true;
}
} else {
// Single extension expands to itself.
$expanded[$type] = true;
}
}
return array_keys($expanded);
}
|
php
|
public function expand($types, $keepgroups=false, $keepmimetypes=false) {
$expanded = [];
foreach ($this->normalize_file_types($types) as $type) {
if ($group = $this->is_filetype_group($type)) {
foreach ($group->extensions as $ext) {
$expanded[$ext] = true;
}
if ($keepgroups) {
$expanded[$type] = true;
}
} else if ($this->looks_like_mimetype($type)) {
// A mime type expands to the associated extensions.
foreach (file_get_typegroup('extension', [$type]) as $ext) {
$expanded[$ext] = true;
}
if ($keepmimetypes) {
$expanded[$type] = true;
}
} else {
// Single extension expands to itself.
$expanded[$type] = true;
}
}
return array_keys($expanded);
}
|
[
"public",
"function",
"expand",
"(",
"$",
"types",
",",
"$",
"keepgroups",
"=",
"false",
",",
"$",
"keepmimetypes",
"=",
"false",
")",
"{",
"$",
"expanded",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"normalize_file_types",
"(",
"$",
"types",
")",
"as",
"$",
"type",
")",
"{",
"if",
"(",
"$",
"group",
"=",
"$",
"this",
"->",
"is_filetype_group",
"(",
"$",
"type",
")",
")",
"{",
"foreach",
"(",
"$",
"group",
"->",
"extensions",
"as",
"$",
"ext",
")",
"{",
"$",
"expanded",
"[",
"$",
"ext",
"]",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"keepgroups",
")",
"{",
"$",
"expanded",
"[",
"$",
"type",
"]",
"=",
"true",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"looks_like_mimetype",
"(",
"$",
"type",
")",
")",
"{",
"// A mime type expands to the associated extensions.",
"foreach",
"(",
"file_get_typegroup",
"(",
"'extension'",
",",
"[",
"$",
"type",
"]",
")",
"as",
"$",
"ext",
")",
"{",
"$",
"expanded",
"[",
"$",
"ext",
"]",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"keepmimetypes",
")",
"{",
"$",
"expanded",
"[",
"$",
"type",
"]",
"=",
"true",
";",
"}",
"}",
"else",
"{",
"// Single extension expands to itself.",
"$",
"expanded",
"[",
"$",
"type",
"]",
"=",
"true",
";",
"}",
"}",
"return",
"array_keys",
"(",
"$",
"expanded",
")",
";",
"}"
] |
Expands the file types into the list of file extensions.
The groups and mimetypes are expanded into the list of their associated file
extensions. Depending on the $keepgroups and $keepmimetypes, the groups
and mimetypes themselves are either kept in the list or removed.
@param string|array $types
@param bool $keepgroups Keep the group item in the list after expansion
@param bool $keepmimetypes Keep the mimetype item in the list after expansion
@return array list of extensions and eventually groups and types
|
[
"Expands",
"the",
"file",
"types",
"into",
"the",
"list",
"of",
"file",
"extensions",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/classes/filetypes_util.php#L387-L416
|
217,510
|
moodle/moodle
|
lib/form/classes/filetypes_util.php
|
filetypes_util.get_not_whitelisted
|
public function get_not_whitelisted($types, $whitelist) {
$whitelistedtypes = $this->expand($whitelist, true, true);
if (empty($whitelistedtypes) || $whitelistedtypes == ['*']) {
return [];
}
$giventypes = $this->normalize_file_types($types);
if (empty($giventypes)) {
return [];
}
return array_diff($giventypes, $whitelistedtypes);
}
|
php
|
public function get_not_whitelisted($types, $whitelist) {
$whitelistedtypes = $this->expand($whitelist, true, true);
if (empty($whitelistedtypes) || $whitelistedtypes == ['*']) {
return [];
}
$giventypes = $this->normalize_file_types($types);
if (empty($giventypes)) {
return [];
}
return array_diff($giventypes, $whitelistedtypes);
}
|
[
"public",
"function",
"get_not_whitelisted",
"(",
"$",
"types",
",",
"$",
"whitelist",
")",
"{",
"$",
"whitelistedtypes",
"=",
"$",
"this",
"->",
"expand",
"(",
"$",
"whitelist",
",",
"true",
",",
"true",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"whitelistedtypes",
")",
"||",
"$",
"whitelistedtypes",
"==",
"[",
"'*'",
"]",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"giventypes",
"=",
"$",
"this",
"->",
"normalize_file_types",
"(",
"$",
"types",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"giventypes",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"array_diff",
"(",
"$",
"giventypes",
",",
"$",
"whitelistedtypes",
")",
";",
"}"
] |
Returns all types that are not part of the give whitelist.
This is similar check to the {@link self::is_whitelisted()} but this one
actually returns the extra types.
@param string|array $types File types to be checked
@param string|array $whitelist An array or string of whitelisted types
@return array Types not present in the whitelist
|
[
"Returns",
"all",
"types",
"that",
"are",
"not",
"part",
"of",
"the",
"give",
"whitelist",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/classes/filetypes_util.php#L443-L458
|
217,511
|
moodle/moodle
|
lib/form/classes/filetypes_util.php
|
filetypes_util.is_allowed_file_type
|
public function is_allowed_file_type($filename, $whitelist) {
$allowedextensions = $this->expand($whitelist);
if (empty($allowedextensions) || $allowedextensions == ['*']) {
return true;
}
$haystack = strrev(trim(core_text::strtolower($filename)));
foreach ($allowedextensions as $extension) {
if (strpos($haystack, strrev($extension)) === 0) {
// The file name ends with the extension.
return true;
}
}
return false;
}
|
php
|
public function is_allowed_file_type($filename, $whitelist) {
$allowedextensions = $this->expand($whitelist);
if (empty($allowedextensions) || $allowedextensions == ['*']) {
return true;
}
$haystack = strrev(trim(core_text::strtolower($filename)));
foreach ($allowedextensions as $extension) {
if (strpos($haystack, strrev($extension)) === 0) {
// The file name ends with the extension.
return true;
}
}
return false;
}
|
[
"public",
"function",
"is_allowed_file_type",
"(",
"$",
"filename",
",",
"$",
"whitelist",
")",
"{",
"$",
"allowedextensions",
"=",
"$",
"this",
"->",
"expand",
"(",
"$",
"whitelist",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"allowedextensions",
")",
"||",
"$",
"allowedextensions",
"==",
"[",
"'*'",
"]",
")",
"{",
"return",
"true",
";",
"}",
"$",
"haystack",
"=",
"strrev",
"(",
"trim",
"(",
"core_text",
"::",
"strtolower",
"(",
"$",
"filename",
")",
")",
")",
";",
"foreach",
"(",
"$",
"allowedextensions",
"as",
"$",
"extension",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"haystack",
",",
"strrev",
"(",
"$",
"extension",
")",
")",
"===",
"0",
")",
"{",
"// The file name ends with the extension.",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Is the given filename of an allowed file type?
Empty whitelist is interpretted as "any file type is allowed" rather
than "no file can be uploaded".
@param string $filename the file name
@param string|array $whitelist list of allowed file extensions
@return boolean True if the file type is allowed, false if not
|
[
"Is",
"the",
"given",
"filename",
"of",
"an",
"allowed",
"file",
"type?"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/classes/filetypes_util.php#L470-L488
|
217,512
|
moodle/moodle
|
lib/form/classes/filetypes_util.php
|
filetypes_util.get_unknown_file_types
|
public function get_unknown_file_types($types) {
$unknown = [];
foreach ($this->normalize_file_types($types) as $type) {
if ($type === '*') {
// Any file is considered as a known type.
continue;
} else if ($type === '.xxx') {
$unknown[$type] = true;
} else if ($this->is_filetype_group($type)) {
// The type is a group that exists.
continue;
} else if ($this->looks_like_mimetype($type)) {
// If there's no extension associated with that mimetype, we consider it unknown.
if (empty(file_get_typegroup('extension', [$type]))) {
$unknown[$type] = true;
}
} else {
$coretypes = core_filetypes::get_types();
$typecleaned = str_replace(".", "", $type);
if (empty($coretypes[$typecleaned])) {
// If there's no extension, it doesn't exist.
$unknown[$type] = true;
}
}
}
return array_keys($unknown);
}
|
php
|
public function get_unknown_file_types($types) {
$unknown = [];
foreach ($this->normalize_file_types($types) as $type) {
if ($type === '*') {
// Any file is considered as a known type.
continue;
} else if ($type === '.xxx') {
$unknown[$type] = true;
} else if ($this->is_filetype_group($type)) {
// The type is a group that exists.
continue;
} else if ($this->looks_like_mimetype($type)) {
// If there's no extension associated with that mimetype, we consider it unknown.
if (empty(file_get_typegroup('extension', [$type]))) {
$unknown[$type] = true;
}
} else {
$coretypes = core_filetypes::get_types();
$typecleaned = str_replace(".", "", $type);
if (empty($coretypes[$typecleaned])) {
// If there's no extension, it doesn't exist.
$unknown[$type] = true;
}
}
}
return array_keys($unknown);
}
|
[
"public",
"function",
"get_unknown_file_types",
"(",
"$",
"types",
")",
"{",
"$",
"unknown",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"normalize_file_types",
"(",
"$",
"types",
")",
"as",
"$",
"type",
")",
"{",
"if",
"(",
"$",
"type",
"===",
"'*'",
")",
"{",
"// Any file is considered as a known type.",
"continue",
";",
"}",
"else",
"if",
"(",
"$",
"type",
"===",
"'.xxx'",
")",
"{",
"$",
"unknown",
"[",
"$",
"type",
"]",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"is_filetype_group",
"(",
"$",
"type",
")",
")",
"{",
"// The type is a group that exists.",
"continue",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"looks_like_mimetype",
"(",
"$",
"type",
")",
")",
"{",
"// If there's no extension associated with that mimetype, we consider it unknown.",
"if",
"(",
"empty",
"(",
"file_get_typegroup",
"(",
"'extension'",
",",
"[",
"$",
"type",
"]",
")",
")",
")",
"{",
"$",
"unknown",
"[",
"$",
"type",
"]",
"=",
"true",
";",
"}",
"}",
"else",
"{",
"$",
"coretypes",
"=",
"core_filetypes",
"::",
"get_types",
"(",
")",
";",
"$",
"typecleaned",
"=",
"str_replace",
"(",
"\".\"",
",",
"\"\"",
",",
"$",
"type",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"coretypes",
"[",
"$",
"typecleaned",
"]",
")",
")",
"{",
"// If there's no extension, it doesn't exist.",
"$",
"unknown",
"[",
"$",
"type",
"]",
"=",
"true",
";",
"}",
"}",
"}",
"return",
"array_keys",
"(",
"$",
"unknown",
")",
";",
"}"
] |
Returns file types from the list that are not recognized
@param string|array $types list of user-defined file types
@return array A list of unknown file types.
|
[
"Returns",
"file",
"types",
"from",
"the",
"list",
"that",
"are",
"not",
"recognized"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/classes/filetypes_util.php#L496-L524
|
217,513
|
moodle/moodle
|
lib/lessphp/Tree/Import.php
|
Less_Tree_Import.ParseImport
|
public function ParseImport( $full_path, $uri, $env ){
$import_env = clone $env;
if( (isset($this->options['reference']) && $this->options['reference']) || isset($this->currentFileInfo['reference']) ){
$import_env->currentFileInfo['reference'] = true;
}
if( (isset($this->options['multiple']) && $this->options['multiple']) ){
$import_env->importMultiple = true;
}
$parser = new Less_Parser($import_env);
$root = $parser->parseFile($full_path, $uri, true);
$ruleset = new Less_Tree_Ruleset(array(), $root->rules );
$ruleset->evalImports($import_env);
return $this->features ? new Less_Tree_Media($ruleset->rules, $this->features->value) : $ruleset->rules;
}
|
php
|
public function ParseImport( $full_path, $uri, $env ){
$import_env = clone $env;
if( (isset($this->options['reference']) && $this->options['reference']) || isset($this->currentFileInfo['reference']) ){
$import_env->currentFileInfo['reference'] = true;
}
if( (isset($this->options['multiple']) && $this->options['multiple']) ){
$import_env->importMultiple = true;
}
$parser = new Less_Parser($import_env);
$root = $parser->parseFile($full_path, $uri, true);
$ruleset = new Less_Tree_Ruleset(array(), $root->rules );
$ruleset->evalImports($import_env);
return $this->features ? new Less_Tree_Media($ruleset->rules, $this->features->value) : $ruleset->rules;
}
|
[
"public",
"function",
"ParseImport",
"(",
"$",
"full_path",
",",
"$",
"uri",
",",
"$",
"env",
")",
"{",
"$",
"import_env",
"=",
"clone",
"$",
"env",
";",
"if",
"(",
"(",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'reference'",
"]",
")",
"&&",
"$",
"this",
"->",
"options",
"[",
"'reference'",
"]",
")",
"||",
"isset",
"(",
"$",
"this",
"->",
"currentFileInfo",
"[",
"'reference'",
"]",
")",
")",
"{",
"$",
"import_env",
"->",
"currentFileInfo",
"[",
"'reference'",
"]",
"=",
"true",
";",
"}",
"if",
"(",
"(",
"isset",
"(",
"$",
"this",
"->",
"options",
"[",
"'multiple'",
"]",
")",
"&&",
"$",
"this",
"->",
"options",
"[",
"'multiple'",
"]",
")",
")",
"{",
"$",
"import_env",
"->",
"importMultiple",
"=",
"true",
";",
"}",
"$",
"parser",
"=",
"new",
"Less_Parser",
"(",
"$",
"import_env",
")",
";",
"$",
"root",
"=",
"$",
"parser",
"->",
"parseFile",
"(",
"$",
"full_path",
",",
"$",
"uri",
",",
"true",
")",
";",
"$",
"ruleset",
"=",
"new",
"Less_Tree_Ruleset",
"(",
"array",
"(",
")",
",",
"$",
"root",
"->",
"rules",
")",
";",
"$",
"ruleset",
"->",
"evalImports",
"(",
"$",
"import_env",
")",
";",
"return",
"$",
"this",
"->",
"features",
"?",
"new",
"Less_Tree_Media",
"(",
"$",
"ruleset",
"->",
"rules",
",",
"$",
"this",
"->",
"features",
"->",
"value",
")",
":",
"$",
"ruleset",
"->",
"rules",
";",
"}"
] |
Parse the import url and return the rules
@return Less_Tree_Media|array
|
[
"Parse",
"the",
"import",
"url",
"and",
"return",
"the",
"rules"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Tree/Import.php#L270-L289
|
217,514
|
moodle/moodle
|
favourites/classes/local/repository/favourite_repository.php
|
favourite_repository.get_favourite_from_record
|
protected function get_favourite_from_record(\stdClass $record) : favourite {
$favourite = new favourite(
$record->component,
$record->itemtype,
$record->itemid,
$record->contextid,
$record->userid
);
$favourite->id = $record->id;
$favourite->ordering = $record->ordering ?? null;
$favourite->timecreated = $record->timecreated ?? null;
$favourite->timemodified = $record->timemodified ?? null;
return $favourite;
}
|
php
|
protected function get_favourite_from_record(\stdClass $record) : favourite {
$favourite = new favourite(
$record->component,
$record->itemtype,
$record->itemid,
$record->contextid,
$record->userid
);
$favourite->id = $record->id;
$favourite->ordering = $record->ordering ?? null;
$favourite->timecreated = $record->timecreated ?? null;
$favourite->timemodified = $record->timemodified ?? null;
return $favourite;
}
|
[
"protected",
"function",
"get_favourite_from_record",
"(",
"\\",
"stdClass",
"$",
"record",
")",
":",
"favourite",
"{",
"$",
"favourite",
"=",
"new",
"favourite",
"(",
"$",
"record",
"->",
"component",
",",
"$",
"record",
"->",
"itemtype",
",",
"$",
"record",
"->",
"itemid",
",",
"$",
"record",
"->",
"contextid",
",",
"$",
"record",
"->",
"userid",
")",
";",
"$",
"favourite",
"->",
"id",
"=",
"$",
"record",
"->",
"id",
";",
"$",
"favourite",
"->",
"ordering",
"=",
"$",
"record",
"->",
"ordering",
"??",
"null",
";",
"$",
"favourite",
"->",
"timecreated",
"=",
"$",
"record",
"->",
"timecreated",
"??",
"null",
";",
"$",
"favourite",
"->",
"timemodified",
"=",
"$",
"record",
"->",
"timemodified",
"??",
"null",
";",
"return",
"$",
"favourite",
";",
"}"
] |
Get a favourite object, based on a full record.
@param \stdClass $record the record we wish to hydrate.
@return favourite the favourite record.
|
[
"Get",
"a",
"favourite",
"object",
"based",
"on",
"a",
"full",
"record",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/favourites/classes/local/repository/favourite_repository.php#L48-L62
|
217,515
|
moodle/moodle
|
favourites/classes/local/repository/favourite_repository.php
|
favourite_repository.get_list_of_favourites_from_records
|
protected function get_list_of_favourites_from_records(array $records) {
$list = [];
foreach ($records as $index => $record) {
$list[$index] = $this->get_favourite_from_record($record);
}
return $list;
}
|
php
|
protected function get_list_of_favourites_from_records(array $records) {
$list = [];
foreach ($records as $index => $record) {
$list[$index] = $this->get_favourite_from_record($record);
}
return $list;
}
|
[
"protected",
"function",
"get_list_of_favourites_from_records",
"(",
"array",
"$",
"records",
")",
"{",
"$",
"list",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"records",
"as",
"$",
"index",
"=>",
"$",
"record",
")",
"{",
"$",
"list",
"[",
"$",
"index",
"]",
"=",
"$",
"this",
"->",
"get_favourite_from_record",
"(",
"$",
"record",
")",
";",
"}",
"return",
"$",
"list",
";",
"}"
] |
Get a list of favourite objects, based on a list of records.
@param array $records the record we wish to hydrate.
@return array the list of favourites.
|
[
"Get",
"a",
"list",
"of",
"favourite",
"objects",
"based",
"on",
"a",
"list",
"of",
"records",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/favourites/classes/local/repository/favourite_repository.php#L69-L75
|
217,516
|
moodle/moodle
|
favourites/classes/local/repository/favourite_repository.php
|
favourite_repository.validate
|
protected function validate(favourite $favourite) {
$favourite = (array)$favourite;
// The allowed fields, and whether or not each is required to create a record.
// The timecreated, timemodified and id fields are generated during create/update.
$allowedfields = [
'userid' => true,
'component' => true,
'itemtype' => true,
'itemid' => true,
'contextid' => true,
'ordering' => false,
'timecreated' => false,
'timemodified' => false,
'id' => false
];
$requiredfields = array_filter($allowedfields, function($field) {
return $field;
});
if ($missingfields = array_keys(array_diff_key($requiredfields, $favourite))) {
throw new \moodle_exception("Missing object property(s) '" . join(', ', $missingfields) . "'.");
}
// If the record contains fields we don't allow, throw an exception.
if ($unsupportedfields = array_keys(array_diff_key($favourite, $allowedfields))) {
throw new \moodle_exception("Unexpected object property(s) '" . join(', ', $unsupportedfields) . "'.");
}
}
|
php
|
protected function validate(favourite $favourite) {
$favourite = (array)$favourite;
// The allowed fields, and whether or not each is required to create a record.
// The timecreated, timemodified and id fields are generated during create/update.
$allowedfields = [
'userid' => true,
'component' => true,
'itemtype' => true,
'itemid' => true,
'contextid' => true,
'ordering' => false,
'timecreated' => false,
'timemodified' => false,
'id' => false
];
$requiredfields = array_filter($allowedfields, function($field) {
return $field;
});
if ($missingfields = array_keys(array_diff_key($requiredfields, $favourite))) {
throw new \moodle_exception("Missing object property(s) '" . join(', ', $missingfields) . "'.");
}
// If the record contains fields we don't allow, throw an exception.
if ($unsupportedfields = array_keys(array_diff_key($favourite, $allowedfields))) {
throw new \moodle_exception("Unexpected object property(s) '" . join(', ', $unsupportedfields) . "'.");
}
}
|
[
"protected",
"function",
"validate",
"(",
"favourite",
"$",
"favourite",
")",
"{",
"$",
"favourite",
"=",
"(",
"array",
")",
"$",
"favourite",
";",
"// The allowed fields, and whether or not each is required to create a record.",
"// The timecreated, timemodified and id fields are generated during create/update.",
"$",
"allowedfields",
"=",
"[",
"'userid'",
"=>",
"true",
",",
"'component'",
"=>",
"true",
",",
"'itemtype'",
"=>",
"true",
",",
"'itemid'",
"=>",
"true",
",",
"'contextid'",
"=>",
"true",
",",
"'ordering'",
"=>",
"false",
",",
"'timecreated'",
"=>",
"false",
",",
"'timemodified'",
"=>",
"false",
",",
"'id'",
"=>",
"false",
"]",
";",
"$",
"requiredfields",
"=",
"array_filter",
"(",
"$",
"allowedfields",
",",
"function",
"(",
"$",
"field",
")",
"{",
"return",
"$",
"field",
";",
"}",
")",
";",
"if",
"(",
"$",
"missingfields",
"=",
"array_keys",
"(",
"array_diff_key",
"(",
"$",
"requiredfields",
",",
"$",
"favourite",
")",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"\"Missing object property(s) '\"",
".",
"join",
"(",
"', '",
",",
"$",
"missingfields",
")",
".",
"\"'.\"",
")",
";",
"}",
"// If the record contains fields we don't allow, throw an exception.",
"if",
"(",
"$",
"unsupportedfields",
"=",
"array_keys",
"(",
"array_diff_key",
"(",
"$",
"favourite",
",",
"$",
"allowedfields",
")",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"\"Unexpected object property(s) '\"",
".",
"join",
"(",
"', '",
",",
"$",
"unsupportedfields",
")",
".",
"\"'.\"",
")",
";",
"}",
"}"
] |
Basic validation, confirming we have the minimum field set needed to save a record to the store.
@param favourite $favourite the favourite record to validate.
@throws \moodle_exception if the supplied favourite has missing or unsupported fields.
|
[
"Basic",
"validation",
"confirming",
"we",
"have",
"the",
"minimum",
"field",
"set",
"needed",
"to",
"save",
"a",
"record",
"to",
"the",
"store",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/favourites/classes/local/repository/favourite_repository.php#L83-L113
|
217,517
|
moodle/moodle
|
favourites/classes/local/repository/favourite_repository.php
|
favourite_repository.add
|
public function add(favourite $favourite) : favourite {
global $DB;
$this->validate($favourite);
$favourite = (array)$favourite;
$time = time();
$favourite['timecreated'] = $time;
$favourite['timemodified'] = $time;
$id = $DB->insert_record($this->favouritetable, $favourite);
return $this->find($id);
}
|
php
|
public function add(favourite $favourite) : favourite {
global $DB;
$this->validate($favourite);
$favourite = (array)$favourite;
$time = time();
$favourite['timecreated'] = $time;
$favourite['timemodified'] = $time;
$id = $DB->insert_record($this->favouritetable, $favourite);
return $this->find($id);
}
|
[
"public",
"function",
"add",
"(",
"favourite",
"$",
"favourite",
")",
":",
"favourite",
"{",
"global",
"$",
"DB",
";",
"$",
"this",
"->",
"validate",
"(",
"$",
"favourite",
")",
";",
"$",
"favourite",
"=",
"(",
"array",
")",
"$",
"favourite",
";",
"$",
"time",
"=",
"time",
"(",
")",
";",
"$",
"favourite",
"[",
"'timecreated'",
"]",
"=",
"$",
"time",
";",
"$",
"favourite",
"[",
"'timemodified'",
"]",
"=",
"$",
"time",
";",
"$",
"id",
"=",
"$",
"DB",
"->",
"insert_record",
"(",
"$",
"this",
"->",
"favouritetable",
",",
"$",
"favourite",
")",
";",
"return",
"$",
"this",
"->",
"find",
"(",
"$",
"id",
")",
";",
"}"
] |
Add a favourite to the repository.
@param favourite $favourite the favourite to add.
@return favourite the favourite which has been stored.
@throws \dml_exception if any database errors are encountered.
@throws \moodle_exception if the favourite has missing or invalid properties.
|
[
"Add",
"a",
"favourite",
"to",
"the",
"repository",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/favourites/classes/local/repository/favourite_repository.php#L123-L132
|
217,518
|
moodle/moodle
|
favourites/classes/local/repository/favourite_repository.php
|
favourite_repository.add_all
|
public function add_all(array $items) : array {
global $DB;
$time = time();
foreach ($items as $item) {
$this->validate($item);
$favourite = (array)$item;
$favourite['timecreated'] = $time;
$favourite['timemodified'] = $time;
$ids[] = $DB->insert_record($this->favouritetable, $favourite);
}
list($insql, $params) = $DB->get_in_or_equal($ids);
$records = $DB->get_records_select($this->favouritetable, "id $insql", $params);
return $this->get_list_of_favourites_from_records($records);
}
|
php
|
public function add_all(array $items) : array {
global $DB;
$time = time();
foreach ($items as $item) {
$this->validate($item);
$favourite = (array)$item;
$favourite['timecreated'] = $time;
$favourite['timemodified'] = $time;
$ids[] = $DB->insert_record($this->favouritetable, $favourite);
}
list($insql, $params) = $DB->get_in_or_equal($ids);
$records = $DB->get_records_select($this->favouritetable, "id $insql", $params);
return $this->get_list_of_favourites_from_records($records);
}
|
[
"public",
"function",
"add_all",
"(",
"array",
"$",
"items",
")",
":",
"array",
"{",
"global",
"$",
"DB",
";",
"$",
"time",
"=",
"time",
"(",
")",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"$",
"this",
"->",
"validate",
"(",
"$",
"item",
")",
";",
"$",
"favourite",
"=",
"(",
"array",
")",
"$",
"item",
";",
"$",
"favourite",
"[",
"'timecreated'",
"]",
"=",
"$",
"time",
";",
"$",
"favourite",
"[",
"'timemodified'",
"]",
"=",
"$",
"time",
";",
"$",
"ids",
"[",
"]",
"=",
"$",
"DB",
"->",
"insert_record",
"(",
"$",
"this",
"->",
"favouritetable",
",",
"$",
"favourite",
")",
";",
"}",
"list",
"(",
"$",
"insql",
",",
"$",
"params",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"ids",
")",
";",
"$",
"records",
"=",
"$",
"DB",
"->",
"get_records_select",
"(",
"$",
"this",
"->",
"favouritetable",
",",
"\"id $insql\"",
",",
"$",
"params",
")",
";",
"return",
"$",
"this",
"->",
"get_list_of_favourites_from_records",
"(",
"$",
"records",
")",
";",
"}"
] |
Add a collection of favourites to the repository.
@param array $items the list of favourites to add.
@return array the list of favourites which have been stored.
@throws \dml_exception if any database errors are encountered.
@throws \moodle_exception if any of the favourites have missing or invalid properties.
|
[
"Add",
"a",
"collection",
"of",
"favourites",
"to",
"the",
"repository",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/favourites/classes/local/repository/favourite_repository.php#L142-L155
|
217,519
|
moodle/moodle
|
favourites/classes/local/repository/favourite_repository.php
|
favourite_repository.find
|
public function find(int $id) : favourite {
global $DB;
$record = $DB->get_record($this->favouritetable, ['id' => $id], '*', MUST_EXIST);
return $this->get_favourite_from_record($record);
}
|
php
|
public function find(int $id) : favourite {
global $DB;
$record = $DB->get_record($this->favouritetable, ['id' => $id], '*', MUST_EXIST);
return $this->get_favourite_from_record($record);
}
|
[
"public",
"function",
"find",
"(",
"int",
"$",
"id",
")",
":",
"favourite",
"{",
"global",
"$",
"DB",
";",
"$",
"record",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"$",
"this",
"->",
"favouritetable",
",",
"[",
"'id'",
"=>",
"$",
"id",
"]",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"return",
"$",
"this",
"->",
"get_favourite_from_record",
"(",
"$",
"record",
")",
";",
"}"
] |
Find a favourite by id.
@param int $id the id of the favourite.
@return favourite the favourite.
@throws \dml_exception if any database errors are encountered.
|
[
"Find",
"a",
"favourite",
"by",
"id",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/favourites/classes/local/repository/favourite_repository.php#L164-L168
|
217,520
|
moodle/moodle
|
favourites/classes/local/repository/favourite_repository.php
|
favourite_repository.find_all
|
public function find_all(int $limitfrom = 0, int $limitnum = 0) : array {
global $DB;
$records = $DB->get_records($this->favouritetable, null, '', '*', $limitfrom, $limitnum);
return $this->get_list_of_favourites_from_records($records);
}
|
php
|
public function find_all(int $limitfrom = 0, int $limitnum = 0) : array {
global $DB;
$records = $DB->get_records($this->favouritetable, null, '', '*', $limitfrom, $limitnum);
return $this->get_list_of_favourites_from_records($records);
}
|
[
"public",
"function",
"find_all",
"(",
"int",
"$",
"limitfrom",
"=",
"0",
",",
"int",
"$",
"limitnum",
"=",
"0",
")",
":",
"array",
"{",
"global",
"$",
"DB",
";",
"$",
"records",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"$",
"this",
"->",
"favouritetable",
",",
"null",
",",
"''",
",",
"'*'",
",",
"$",
"limitfrom",
",",
"$",
"limitnum",
")",
";",
"return",
"$",
"this",
"->",
"get_list_of_favourites_from_records",
"(",
"$",
"records",
")",
";",
"}"
] |
Return all items in this repository, as an array, indexed by id.
@param int $limitfrom optional pagination control for returning a subset of records, starting at this point.
@param int $limitnum optional pagination control for returning a subset comprising this many records.
@return array the list of all favourites stored within this repository.
@throws \dml_exception if any database errors are encountered.
|
[
"Return",
"all",
"items",
"in",
"this",
"repository",
"as",
"an",
"array",
"indexed",
"by",
"id",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/favourites/classes/local/repository/favourite_repository.php#L178-L182
|
217,521
|
moodle/moodle
|
favourites/classes/local/repository/favourite_repository.php
|
favourite_repository.find_favourite
|
public function find_favourite(int $userid, string $component, string $itemtype, int $itemid, int $contextid) : favourite {
global $DB;
// Favourites model: We know that only one favourite can exist based on these properties.
$record = $DB->get_record($this->favouritetable, [
'userid' => $userid,
'component' => $component,
'itemtype' => $itemtype,
'itemid' => $itemid,
'contextid' => $contextid
], '*', MUST_EXIST);
return $this->get_favourite_from_record($record);
}
|
php
|
public function find_favourite(int $userid, string $component, string $itemtype, int $itemid, int $contextid) : favourite {
global $DB;
// Favourites model: We know that only one favourite can exist based on these properties.
$record = $DB->get_record($this->favouritetable, [
'userid' => $userid,
'component' => $component,
'itemtype' => $itemtype,
'itemid' => $itemid,
'contextid' => $contextid
], '*', MUST_EXIST);
return $this->get_favourite_from_record($record);
}
|
[
"public",
"function",
"find_favourite",
"(",
"int",
"$",
"userid",
",",
"string",
"$",
"component",
",",
"string",
"$",
"itemtype",
",",
"int",
"$",
"itemid",
",",
"int",
"$",
"contextid",
")",
":",
"favourite",
"{",
"global",
"$",
"DB",
";",
"// Favourites model: We know that only one favourite can exist based on these properties.",
"$",
"record",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"$",
"this",
"->",
"favouritetable",
",",
"[",
"'userid'",
"=>",
"$",
"userid",
",",
"'component'",
"=>",
"$",
"component",
",",
"'itemtype'",
"=>",
"$",
"itemtype",
",",
"'itemid'",
"=>",
"$",
"itemid",
",",
"'contextid'",
"=>",
"$",
"contextid",
"]",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"return",
"$",
"this",
"->",
"get_favourite_from_record",
"(",
"$",
"record",
")",
";",
"}"
] |
Find a specific favourite, based on the properties known to identify it.
Used if we don't know its id.
@param int $userid the id of the user to which the favourite belongs.
@param string $component the frankenstyle component name.
@param string $itemtype the type of the favourited item.
@param int $itemid the id of the item which was favourited (not the favourite's id).
@param int $contextid the contextid of the item which was favourited.
@return favourite the favourite.
@throws \dml_exception if any database errors are encountered or if the record could not be found.
|
[
"Find",
"a",
"specific",
"favourite",
"based",
"on",
"the",
"properties",
"known",
"to",
"identify",
"it",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/favourites/classes/local/repository/favourite_repository.php#L212-L223
|
217,522
|
moodle/moodle
|
favourites/classes/local/repository/favourite_repository.php
|
favourite_repository.exists
|
public function exists(int $id) : bool {
global $DB;
return $DB->record_exists($this->favouritetable, ['id' => $id]);
}
|
php
|
public function exists(int $id) : bool {
global $DB;
return $DB->record_exists($this->favouritetable, ['id' => $id]);
}
|
[
"public",
"function",
"exists",
"(",
"int",
"$",
"id",
")",
":",
"bool",
"{",
"global",
"$",
"DB",
";",
"return",
"$",
"DB",
"->",
"record_exists",
"(",
"$",
"this",
"->",
"favouritetable",
",",
"[",
"'id'",
"=>",
"$",
"id",
"]",
")",
";",
"}"
] |
Check whether a favourite exists in this repository, based on its id.
@param int $id the id to search for.
@return bool true if the favourite exists, false otherwise.
@throws \dml_exception if any database errors are encountered.
|
[
"Check",
"whether",
"a",
"favourite",
"exists",
"in",
"this",
"repository",
"based",
"on",
"its",
"id",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/favourites/classes/local/repository/favourite_repository.php#L232-L235
|
217,523
|
moodle/moodle
|
favourites/classes/local/repository/favourite_repository.php
|
favourite_repository.update
|
public function update(favourite $favourite) : favourite {
global $DB;
$time = time();
$favourite->timemodified = $time;
$DB->update_record($this->favouritetable, $favourite);
return $this->find($favourite->id);
}
|
php
|
public function update(favourite $favourite) : favourite {
global $DB;
$time = time();
$favourite->timemodified = $time;
$DB->update_record($this->favouritetable, $favourite);
return $this->find($favourite->id);
}
|
[
"public",
"function",
"update",
"(",
"favourite",
"$",
"favourite",
")",
":",
"favourite",
"{",
"global",
"$",
"DB",
";",
"$",
"time",
"=",
"time",
"(",
")",
";",
"$",
"favourite",
"->",
"timemodified",
"=",
"$",
"time",
";",
"$",
"DB",
"->",
"update_record",
"(",
"$",
"this",
"->",
"favouritetable",
",",
"$",
"favourite",
")",
";",
"return",
"$",
"this",
"->",
"find",
"(",
"$",
"favourite",
"->",
"id",
")",
";",
"}"
] |
Update a favourite.
@param favourite $favourite the favourite to update.
@return favourite the updated favourite.
@throws \dml_exception if any database errors are encountered.
|
[
"Update",
"a",
"favourite",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/favourites/classes/local/repository/favourite_repository.php#L256-L262
|
217,524
|
moodle/moodle
|
admin/tool/recyclebin/classes/course_bin.php
|
course_bin.store_item
|
public function store_item($cm) {
global $CFG, $DB;
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
// Get more information.
$modinfo = get_fast_modinfo($cm->course);
if (!isset($modinfo->cms[$cm->id])) {
return; // Can't continue without the module information.
}
$cminfo = $modinfo->cms[$cm->id];
// Check backup/restore support.
if (!plugin_supports('mod', $cminfo->modname , FEATURE_BACKUP_MOODLE2)) {
return;
}
// As far as recycle bin is using MODE_AUTOMATED, it observes the backup_auto_storage
// setting (storing backups @ real location. For recycle bin we want to ensure that
// backup files are always stored in Moodle file area. In order to achieve that, we
// hack the setting here via $CFG->forced_plugin_settings, so it won't interfere other
// operations. See MDL-65218 for more information.
// This hack will be removed once recycle bin switches to use its own backup mode, with
// own preferences and 100% appart from MODLE_AUTOMATED.
// TODO: Remove this as part of MDL-65228.
$CFG->forced_plugin_settings['backup'] = ['backup_auto_storage' => 0];
// Backup the activity.
$user = get_admin();
$controller = new \backup_controller(
\backup::TYPE_1ACTIVITY,
$cm->id,
\backup::FORMAT_MOODLE,
\backup::INTERACTIVE_NO,
\backup::MODE_AUTOMATED,
$user->id
);
$controller->execute_plan();
// We don't need the forced setting anymore, hence unsetting it.
// TODO: Remove this as part of MDL-65228.
unset($CFG->forced_plugin_settings['backup']);
// Grab the result.
$result = $controller->get_results();
if (!isset($result['backup_destination'])) {
throw new \moodle_exception('Failed to backup activity prior to deletion.');
}
// Have finished with the controller, let's destroy it, freeing mem and resources.
$controller->destroy();
// Grab the filename.
$file = $result['backup_destination'];
if (!$file->get_contenthash()) {
throw new \moodle_exception('Failed to backup activity prior to deletion (invalid file).');
}
// Record the activity, get an ID.
$activity = new \stdClass();
$activity->courseid = $cm->course;
$activity->section = $cm->section;
$activity->module = $cm->module;
$activity->name = $cminfo->name;
$activity->timecreated = time();
$binid = $DB->insert_record('tool_recyclebin_course', $activity);
// Create the location we want to copy this file to.
$filerecord = array(
'contextid' => \context_course::instance($this->_courseid)->id,
'component' => 'tool_recyclebin',
'filearea' => TOOL_RECYCLEBIN_COURSE_BIN_FILEAREA,
'itemid' => $binid,
'timemodified' => time()
);
// Move the file to our own special little place.
$fs = get_file_storage();
if (!$fs->create_file_from_storedfile($filerecord, $file)) {
// Failed, cleanup first.
$DB->delete_records('tool_recyclebin_course', array(
'id' => $binid
));
throw new \moodle_exception("Failed to copy backup file to recyclebin.");
}
// Delete the old file.
$file->delete();
// Fire event.
$event = \tool_recyclebin\event\course_bin_item_created::create(array(
'objectid' => $binid,
'context' => \context_course::instance($cm->course)
));
$event->trigger();
}
|
php
|
public function store_item($cm) {
global $CFG, $DB;
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
// Get more information.
$modinfo = get_fast_modinfo($cm->course);
if (!isset($modinfo->cms[$cm->id])) {
return; // Can't continue without the module information.
}
$cminfo = $modinfo->cms[$cm->id];
// Check backup/restore support.
if (!plugin_supports('mod', $cminfo->modname , FEATURE_BACKUP_MOODLE2)) {
return;
}
// As far as recycle bin is using MODE_AUTOMATED, it observes the backup_auto_storage
// setting (storing backups @ real location. For recycle bin we want to ensure that
// backup files are always stored in Moodle file area. In order to achieve that, we
// hack the setting here via $CFG->forced_plugin_settings, so it won't interfere other
// operations. See MDL-65218 for more information.
// This hack will be removed once recycle bin switches to use its own backup mode, with
// own preferences and 100% appart from MODLE_AUTOMATED.
// TODO: Remove this as part of MDL-65228.
$CFG->forced_plugin_settings['backup'] = ['backup_auto_storage' => 0];
// Backup the activity.
$user = get_admin();
$controller = new \backup_controller(
\backup::TYPE_1ACTIVITY,
$cm->id,
\backup::FORMAT_MOODLE,
\backup::INTERACTIVE_NO,
\backup::MODE_AUTOMATED,
$user->id
);
$controller->execute_plan();
// We don't need the forced setting anymore, hence unsetting it.
// TODO: Remove this as part of MDL-65228.
unset($CFG->forced_plugin_settings['backup']);
// Grab the result.
$result = $controller->get_results();
if (!isset($result['backup_destination'])) {
throw new \moodle_exception('Failed to backup activity prior to deletion.');
}
// Have finished with the controller, let's destroy it, freeing mem and resources.
$controller->destroy();
// Grab the filename.
$file = $result['backup_destination'];
if (!$file->get_contenthash()) {
throw new \moodle_exception('Failed to backup activity prior to deletion (invalid file).');
}
// Record the activity, get an ID.
$activity = new \stdClass();
$activity->courseid = $cm->course;
$activity->section = $cm->section;
$activity->module = $cm->module;
$activity->name = $cminfo->name;
$activity->timecreated = time();
$binid = $DB->insert_record('tool_recyclebin_course', $activity);
// Create the location we want to copy this file to.
$filerecord = array(
'contextid' => \context_course::instance($this->_courseid)->id,
'component' => 'tool_recyclebin',
'filearea' => TOOL_RECYCLEBIN_COURSE_BIN_FILEAREA,
'itemid' => $binid,
'timemodified' => time()
);
// Move the file to our own special little place.
$fs = get_file_storage();
if (!$fs->create_file_from_storedfile($filerecord, $file)) {
// Failed, cleanup first.
$DB->delete_records('tool_recyclebin_course', array(
'id' => $binid
));
throw new \moodle_exception("Failed to copy backup file to recyclebin.");
}
// Delete the old file.
$file->delete();
// Fire event.
$event = \tool_recyclebin\event\course_bin_item_created::create(array(
'objectid' => $binid,
'context' => \context_course::instance($cm->course)
));
$event->trigger();
}
|
[
"public",
"function",
"store_item",
"(",
"$",
"cm",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/backup/util/includes/backup_includes.php'",
")",
";",
"// Get more information.",
"$",
"modinfo",
"=",
"get_fast_modinfo",
"(",
"$",
"cm",
"->",
"course",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"modinfo",
"->",
"cms",
"[",
"$",
"cm",
"->",
"id",
"]",
")",
")",
"{",
"return",
";",
"// Can't continue without the module information.",
"}",
"$",
"cminfo",
"=",
"$",
"modinfo",
"->",
"cms",
"[",
"$",
"cm",
"->",
"id",
"]",
";",
"// Check backup/restore support.",
"if",
"(",
"!",
"plugin_supports",
"(",
"'mod'",
",",
"$",
"cminfo",
"->",
"modname",
",",
"FEATURE_BACKUP_MOODLE2",
")",
")",
"{",
"return",
";",
"}",
"// As far as recycle bin is using MODE_AUTOMATED, it observes the backup_auto_storage",
"// setting (storing backups @ real location. For recycle bin we want to ensure that",
"// backup files are always stored in Moodle file area. In order to achieve that, we",
"// hack the setting here via $CFG->forced_plugin_settings, so it won't interfere other",
"// operations. See MDL-65218 for more information.",
"// This hack will be removed once recycle bin switches to use its own backup mode, with",
"// own preferences and 100% appart from MODLE_AUTOMATED.",
"// TODO: Remove this as part of MDL-65228.",
"$",
"CFG",
"->",
"forced_plugin_settings",
"[",
"'backup'",
"]",
"=",
"[",
"'backup_auto_storage'",
"=>",
"0",
"]",
";",
"// Backup the activity.",
"$",
"user",
"=",
"get_admin",
"(",
")",
";",
"$",
"controller",
"=",
"new",
"\\",
"backup_controller",
"(",
"\\",
"backup",
"::",
"TYPE_1ACTIVITY",
",",
"$",
"cm",
"->",
"id",
",",
"\\",
"backup",
"::",
"FORMAT_MOODLE",
",",
"\\",
"backup",
"::",
"INTERACTIVE_NO",
",",
"\\",
"backup",
"::",
"MODE_AUTOMATED",
",",
"$",
"user",
"->",
"id",
")",
";",
"$",
"controller",
"->",
"execute_plan",
"(",
")",
";",
"// We don't need the forced setting anymore, hence unsetting it.",
"// TODO: Remove this as part of MDL-65228.",
"unset",
"(",
"$",
"CFG",
"->",
"forced_plugin_settings",
"[",
"'backup'",
"]",
")",
";",
"// Grab the result.",
"$",
"result",
"=",
"$",
"controller",
"->",
"get_results",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"result",
"[",
"'backup_destination'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'Failed to backup activity prior to deletion.'",
")",
";",
"}",
"// Have finished with the controller, let's destroy it, freeing mem and resources.",
"$",
"controller",
"->",
"destroy",
"(",
")",
";",
"// Grab the filename.",
"$",
"file",
"=",
"$",
"result",
"[",
"'backup_destination'",
"]",
";",
"if",
"(",
"!",
"$",
"file",
"->",
"get_contenthash",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'Failed to backup activity prior to deletion (invalid file).'",
")",
";",
"}",
"// Record the activity, get an ID.",
"$",
"activity",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"activity",
"->",
"courseid",
"=",
"$",
"cm",
"->",
"course",
";",
"$",
"activity",
"->",
"section",
"=",
"$",
"cm",
"->",
"section",
";",
"$",
"activity",
"->",
"module",
"=",
"$",
"cm",
"->",
"module",
";",
"$",
"activity",
"->",
"name",
"=",
"$",
"cminfo",
"->",
"name",
";",
"$",
"activity",
"->",
"timecreated",
"=",
"time",
"(",
")",
";",
"$",
"binid",
"=",
"$",
"DB",
"->",
"insert_record",
"(",
"'tool_recyclebin_course'",
",",
"$",
"activity",
")",
";",
"// Create the location we want to copy this file to.",
"$",
"filerecord",
"=",
"array",
"(",
"'contextid'",
"=>",
"\\",
"context_course",
"::",
"instance",
"(",
"$",
"this",
"->",
"_courseid",
")",
"->",
"id",
",",
"'component'",
"=>",
"'tool_recyclebin'",
",",
"'filearea'",
"=>",
"TOOL_RECYCLEBIN_COURSE_BIN_FILEAREA",
",",
"'itemid'",
"=>",
"$",
"binid",
",",
"'timemodified'",
"=>",
"time",
"(",
")",
")",
";",
"// Move the file to our own special little place.",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"if",
"(",
"!",
"$",
"fs",
"->",
"create_file_from_storedfile",
"(",
"$",
"filerecord",
",",
"$",
"file",
")",
")",
"{",
"// Failed, cleanup first.",
"$",
"DB",
"->",
"delete_records",
"(",
"'tool_recyclebin_course'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"binid",
")",
")",
";",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"\"Failed to copy backup file to recyclebin.\"",
")",
";",
"}",
"// Delete the old file.",
"$",
"file",
"->",
"delete",
"(",
")",
";",
"// Fire event.",
"$",
"event",
"=",
"\\",
"tool_recyclebin",
"\\",
"event",
"\\",
"course_bin_item_created",
"::",
"create",
"(",
"array",
"(",
"'objectid'",
"=>",
"$",
"binid",
",",
"'context'",
"=>",
"\\",
"context_course",
"::",
"instance",
"(",
"$",
"cm",
"->",
"course",
")",
")",
")",
";",
"$",
"event",
"->",
"trigger",
"(",
")",
";",
"}"
] |
Store a course module in the recycle bin.
@param \stdClass $cm Course module
@throws \moodle_exception
|
[
"Store",
"a",
"course",
"module",
"in",
"the",
"recycle",
"bin",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/recyclebin/classes/course_bin.php#L96-L194
|
217,525
|
moodle/moodle
|
lib/filestorage/zip_packer.php
|
zip_packer.archive_to_storage
|
public function archive_to_storage(array $files, $contextid,
$component, $filearea, $itemid, $filepath, $filename,
$userid = NULL, $ignoreinvalidfiles=true, file_progress $progress = null) {
global $CFG;
$fs = get_file_storage();
check_dir_exists($CFG->tempdir.'/zip');
$tmpfile = tempnam($CFG->tempdir.'/zip', 'zipstor');
if ($result = $this->archive_to_pathname($files, $tmpfile, $ignoreinvalidfiles, $progress)) {
if ($file = $fs->get_file($contextid, $component, $filearea, $itemid, $filepath, $filename)) {
if (!$file->delete()) {
@unlink($tmpfile);
return false;
}
}
$file_record = new stdClass();
$file_record->contextid = $contextid;
$file_record->component = $component;
$file_record->filearea = $filearea;
$file_record->itemid = $itemid;
$file_record->filepath = $filepath;
$file_record->filename = $filename;
$file_record->userid = $userid;
$file_record->mimetype = 'application/zip';
$result = $fs->create_file_from_pathname($file_record, $tmpfile);
}
@unlink($tmpfile);
return $result;
}
|
php
|
public function archive_to_storage(array $files, $contextid,
$component, $filearea, $itemid, $filepath, $filename,
$userid = NULL, $ignoreinvalidfiles=true, file_progress $progress = null) {
global $CFG;
$fs = get_file_storage();
check_dir_exists($CFG->tempdir.'/zip');
$tmpfile = tempnam($CFG->tempdir.'/zip', 'zipstor');
if ($result = $this->archive_to_pathname($files, $tmpfile, $ignoreinvalidfiles, $progress)) {
if ($file = $fs->get_file($contextid, $component, $filearea, $itemid, $filepath, $filename)) {
if (!$file->delete()) {
@unlink($tmpfile);
return false;
}
}
$file_record = new stdClass();
$file_record->contextid = $contextid;
$file_record->component = $component;
$file_record->filearea = $filearea;
$file_record->itemid = $itemid;
$file_record->filepath = $filepath;
$file_record->filename = $filename;
$file_record->userid = $userid;
$file_record->mimetype = 'application/zip';
$result = $fs->create_file_from_pathname($file_record, $tmpfile);
}
@unlink($tmpfile);
return $result;
}
|
[
"public",
"function",
"archive_to_storage",
"(",
"array",
"$",
"files",
",",
"$",
"contextid",
",",
"$",
"component",
",",
"$",
"filearea",
",",
"$",
"itemid",
",",
"$",
"filepath",
",",
"$",
"filename",
",",
"$",
"userid",
"=",
"NULL",
",",
"$",
"ignoreinvalidfiles",
"=",
"true",
",",
"file_progress",
"$",
"progress",
"=",
"null",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"check_dir_exists",
"(",
"$",
"CFG",
"->",
"tempdir",
".",
"'/zip'",
")",
";",
"$",
"tmpfile",
"=",
"tempnam",
"(",
"$",
"CFG",
"->",
"tempdir",
".",
"'/zip'",
",",
"'zipstor'",
")",
";",
"if",
"(",
"$",
"result",
"=",
"$",
"this",
"->",
"archive_to_pathname",
"(",
"$",
"files",
",",
"$",
"tmpfile",
",",
"$",
"ignoreinvalidfiles",
",",
"$",
"progress",
")",
")",
"{",
"if",
"(",
"$",
"file",
"=",
"$",
"fs",
"->",
"get_file",
"(",
"$",
"contextid",
",",
"$",
"component",
",",
"$",
"filearea",
",",
"$",
"itemid",
",",
"$",
"filepath",
",",
"$",
"filename",
")",
")",
"{",
"if",
"(",
"!",
"$",
"file",
"->",
"delete",
"(",
")",
")",
"{",
"@",
"unlink",
"(",
"$",
"tmpfile",
")",
";",
"return",
"false",
";",
"}",
"}",
"$",
"file_record",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"file_record",
"->",
"contextid",
"=",
"$",
"contextid",
";",
"$",
"file_record",
"->",
"component",
"=",
"$",
"component",
";",
"$",
"file_record",
"->",
"filearea",
"=",
"$",
"filearea",
";",
"$",
"file_record",
"->",
"itemid",
"=",
"$",
"itemid",
";",
"$",
"file_record",
"->",
"filepath",
"=",
"$",
"filepath",
";",
"$",
"file_record",
"->",
"filename",
"=",
"$",
"filename",
";",
"$",
"file_record",
"->",
"userid",
"=",
"$",
"userid",
";",
"$",
"file_record",
"->",
"mimetype",
"=",
"'application/zip'",
";",
"$",
"result",
"=",
"$",
"fs",
"->",
"create_file_from_pathname",
"(",
"$",
"file_record",
",",
"$",
"tmpfile",
")",
";",
"}",
"@",
"unlink",
"(",
"$",
"tmpfile",
")",
";",
"return",
"$",
"result",
";",
"}"
] |
Zip files and store the result in file storage.
@param array $files array with full zip paths (including directory information)
as keys (archivepath=>ospathname or archivepath/subdir=>stored_file or archivepath=>array('content_as_string'))
@param int $contextid context ID
@param string $component component
@param string $filearea file area
@param int $itemid item ID
@param string $filepath file path
@param string $filename file name
@param int $userid user ID
@param bool $ignoreinvalidfiles true means ignore missing or invalid files, false means abort on any error
@param file_progress $progress Progress indicator callback or null if not required
@return stored_file|bool false if error stored_file instance if ok
|
[
"Zip",
"files",
"and",
"store",
"the",
"result",
"in",
"file",
"storage",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/zip_packer.php#L56-L87
|
217,526
|
moodle/moodle
|
lib/filestorage/zip_packer.php
|
zip_packer.archive_to_pathname
|
public function archive_to_pathname(array $files, $archivefile,
$ignoreinvalidfiles=true, file_progress $progress = null) {
$ziparch = new zip_archive();
if (!$ziparch->open($archivefile, file_archive::OVERWRITE)) {
return false;
}
$abort = false;
foreach ($files as $archivepath => $file) {
$archivepath = trim($archivepath, '/');
// Record progress each time around this loop.
if ($progress) {
$progress->progress();
}
if (is_null($file)) {
// Directories have null as content.
if (!$ziparch->add_directory($archivepath.'/')) {
debugging("Can not zip '$archivepath' directory", DEBUG_DEVELOPER);
if (!$ignoreinvalidfiles) {
$abort = true;
break;
}
}
} else if (is_string($file)) {
if (!$this->archive_pathname($ziparch, $archivepath, $file, $progress)) {
debugging("Can not zip '$archivepath' file", DEBUG_DEVELOPER);
if (!$ignoreinvalidfiles) {
$abort = true;
break;
}
}
} else if (is_array($file)) {
$content = reset($file);
if (!$ziparch->add_file_from_string($archivepath, $content)) {
debugging("Can not zip '$archivepath' file", DEBUG_DEVELOPER);
if (!$ignoreinvalidfiles) {
$abort = true;
break;
}
}
} else {
if (!$this->archive_stored($ziparch, $archivepath, $file, $progress)) {
debugging("Can not zip '$archivepath' file", DEBUG_DEVELOPER);
if (!$ignoreinvalidfiles) {
$abort = true;
break;
}
}
}
}
if (!$ziparch->close()) {
@unlink($archivefile);
return false;
}
if ($abort) {
@unlink($archivefile);
return false;
}
return true;
}
|
php
|
public function archive_to_pathname(array $files, $archivefile,
$ignoreinvalidfiles=true, file_progress $progress = null) {
$ziparch = new zip_archive();
if (!$ziparch->open($archivefile, file_archive::OVERWRITE)) {
return false;
}
$abort = false;
foreach ($files as $archivepath => $file) {
$archivepath = trim($archivepath, '/');
// Record progress each time around this loop.
if ($progress) {
$progress->progress();
}
if (is_null($file)) {
// Directories have null as content.
if (!$ziparch->add_directory($archivepath.'/')) {
debugging("Can not zip '$archivepath' directory", DEBUG_DEVELOPER);
if (!$ignoreinvalidfiles) {
$abort = true;
break;
}
}
} else if (is_string($file)) {
if (!$this->archive_pathname($ziparch, $archivepath, $file, $progress)) {
debugging("Can not zip '$archivepath' file", DEBUG_DEVELOPER);
if (!$ignoreinvalidfiles) {
$abort = true;
break;
}
}
} else if (is_array($file)) {
$content = reset($file);
if (!$ziparch->add_file_from_string($archivepath, $content)) {
debugging("Can not zip '$archivepath' file", DEBUG_DEVELOPER);
if (!$ignoreinvalidfiles) {
$abort = true;
break;
}
}
} else {
if (!$this->archive_stored($ziparch, $archivepath, $file, $progress)) {
debugging("Can not zip '$archivepath' file", DEBUG_DEVELOPER);
if (!$ignoreinvalidfiles) {
$abort = true;
break;
}
}
}
}
if (!$ziparch->close()) {
@unlink($archivefile);
return false;
}
if ($abort) {
@unlink($archivefile);
return false;
}
return true;
}
|
[
"public",
"function",
"archive_to_pathname",
"(",
"array",
"$",
"files",
",",
"$",
"archivefile",
",",
"$",
"ignoreinvalidfiles",
"=",
"true",
",",
"file_progress",
"$",
"progress",
"=",
"null",
")",
"{",
"$",
"ziparch",
"=",
"new",
"zip_archive",
"(",
")",
";",
"if",
"(",
"!",
"$",
"ziparch",
"->",
"open",
"(",
"$",
"archivefile",
",",
"file_archive",
"::",
"OVERWRITE",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"abort",
"=",
"false",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"archivepath",
"=>",
"$",
"file",
")",
"{",
"$",
"archivepath",
"=",
"trim",
"(",
"$",
"archivepath",
",",
"'/'",
")",
";",
"// Record progress each time around this loop.",
"if",
"(",
"$",
"progress",
")",
"{",
"$",
"progress",
"->",
"progress",
"(",
")",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"file",
")",
")",
"{",
"// Directories have null as content.",
"if",
"(",
"!",
"$",
"ziparch",
"->",
"add_directory",
"(",
"$",
"archivepath",
".",
"'/'",
")",
")",
"{",
"debugging",
"(",
"\"Can not zip '$archivepath' directory\"",
",",
"DEBUG_DEVELOPER",
")",
";",
"if",
"(",
"!",
"$",
"ignoreinvalidfiles",
")",
"{",
"$",
"abort",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"else",
"if",
"(",
"is_string",
"(",
"$",
"file",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"archive_pathname",
"(",
"$",
"ziparch",
",",
"$",
"archivepath",
",",
"$",
"file",
",",
"$",
"progress",
")",
")",
"{",
"debugging",
"(",
"\"Can not zip '$archivepath' file\"",
",",
"DEBUG_DEVELOPER",
")",
";",
"if",
"(",
"!",
"$",
"ignoreinvalidfiles",
")",
"{",
"$",
"abort",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"file",
")",
")",
"{",
"$",
"content",
"=",
"reset",
"(",
"$",
"file",
")",
";",
"if",
"(",
"!",
"$",
"ziparch",
"->",
"add_file_from_string",
"(",
"$",
"archivepath",
",",
"$",
"content",
")",
")",
"{",
"debugging",
"(",
"\"Can not zip '$archivepath' file\"",
",",
"DEBUG_DEVELOPER",
")",
";",
"if",
"(",
"!",
"$",
"ignoreinvalidfiles",
")",
"{",
"$",
"abort",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"archive_stored",
"(",
"$",
"ziparch",
",",
"$",
"archivepath",
",",
"$",
"file",
",",
"$",
"progress",
")",
")",
"{",
"debugging",
"(",
"\"Can not zip '$archivepath' file\"",
",",
"DEBUG_DEVELOPER",
")",
";",
"if",
"(",
"!",
"$",
"ignoreinvalidfiles",
")",
"{",
"$",
"abort",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"!",
"$",
"ziparch",
"->",
"close",
"(",
")",
")",
"{",
"@",
"unlink",
"(",
"$",
"archivefile",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"abort",
")",
"{",
"@",
"unlink",
"(",
"$",
"archivefile",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Zip files and store the result in os file.
@param array $files array with zip paths as keys (archivepath=>ospathname or archivepath=>stored_file or archivepath=>array('content_as_string'))
@param string $archivefile path to target zip file
@param bool $ignoreinvalidfiles true means ignore missing or invalid files, false means abort on any error
@param file_progress $progress Progress indicator callback or null if not required
@return bool true if file created, false if not
|
[
"Zip",
"files",
"and",
"store",
"the",
"result",
"in",
"os",
"file",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/zip_packer.php#L98-L165
|
217,527
|
moodle/moodle
|
lib/filestorage/zip_packer.php
|
zip_packer.archive_stored
|
private function archive_stored($ziparch, $archivepath, $file, file_progress $progress = null) {
$result = $file->archive_file($ziparch, $archivepath);
if (!$result) {
return false;
}
if (!$file->is_directory()) {
return true;
}
$baselength = strlen($file->get_filepath());
$fs = get_file_storage();
$files = $fs->get_directory_files($file->get_contextid(), $file->get_component(), $file->get_filearea(), $file->get_itemid(),
$file->get_filepath(), true, true);
foreach ($files as $file) {
// Record progress for each file.
if ($progress) {
$progress->progress();
}
$path = $file->get_filepath();
$path = substr($path, $baselength);
$path = $archivepath.'/'.$path;
if (!$file->is_directory()) {
$path = $path.$file->get_filename();
}
// Ignore result here, partial zipping is ok for now.
$file->archive_file($ziparch, $path);
}
return true;
}
|
php
|
private function archive_stored($ziparch, $archivepath, $file, file_progress $progress = null) {
$result = $file->archive_file($ziparch, $archivepath);
if (!$result) {
return false;
}
if (!$file->is_directory()) {
return true;
}
$baselength = strlen($file->get_filepath());
$fs = get_file_storage();
$files = $fs->get_directory_files($file->get_contextid(), $file->get_component(), $file->get_filearea(), $file->get_itemid(),
$file->get_filepath(), true, true);
foreach ($files as $file) {
// Record progress for each file.
if ($progress) {
$progress->progress();
}
$path = $file->get_filepath();
$path = substr($path, $baselength);
$path = $archivepath.'/'.$path;
if (!$file->is_directory()) {
$path = $path.$file->get_filename();
}
// Ignore result here, partial zipping is ok for now.
$file->archive_file($ziparch, $path);
}
return true;
}
|
[
"private",
"function",
"archive_stored",
"(",
"$",
"ziparch",
",",
"$",
"archivepath",
",",
"$",
"file",
",",
"file_progress",
"$",
"progress",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"$",
"file",
"->",
"archive_file",
"(",
"$",
"ziparch",
",",
"$",
"archivepath",
")",
";",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"file",
"->",
"is_directory",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"baselength",
"=",
"strlen",
"(",
"$",
"file",
"->",
"get_filepath",
"(",
")",
")",
";",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"$",
"files",
"=",
"$",
"fs",
"->",
"get_directory_files",
"(",
"$",
"file",
"->",
"get_contextid",
"(",
")",
",",
"$",
"file",
"->",
"get_component",
"(",
")",
",",
"$",
"file",
"->",
"get_filearea",
"(",
")",
",",
"$",
"file",
"->",
"get_itemid",
"(",
")",
",",
"$",
"file",
"->",
"get_filepath",
"(",
")",
",",
"true",
",",
"true",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"// Record progress for each file.",
"if",
"(",
"$",
"progress",
")",
"{",
"$",
"progress",
"->",
"progress",
"(",
")",
";",
"}",
"$",
"path",
"=",
"$",
"file",
"->",
"get_filepath",
"(",
")",
";",
"$",
"path",
"=",
"substr",
"(",
"$",
"path",
",",
"$",
"baselength",
")",
";",
"$",
"path",
"=",
"$",
"archivepath",
".",
"'/'",
".",
"$",
"path",
";",
"if",
"(",
"!",
"$",
"file",
"->",
"is_directory",
"(",
")",
")",
"{",
"$",
"path",
"=",
"$",
"path",
".",
"$",
"file",
"->",
"get_filename",
"(",
")",
";",
"}",
"// Ignore result here, partial zipping is ok for now.",
"$",
"file",
"->",
"archive_file",
"(",
"$",
"ziparch",
",",
"$",
"path",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Perform archiving file from stored file.
@param zip_archive $ziparch zip archive instance
@param string $archivepath file path to archive
@param stored_file $file stored_file object
@param file_progress $progress Progress indicator callback or null if not required
@return bool success
|
[
"Perform",
"archiving",
"file",
"from",
"stored",
"file",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/zip_packer.php#L176-L207
|
217,528
|
moodle/moodle
|
lib/filestorage/zip_packer.php
|
zip_packer.archive_pathname
|
private function archive_pathname($ziparch, $archivepath, $file,
file_progress $progress = null) {
// Record progress each time this function is called.
if ($progress) {
$progress->progress();
}
if (!file_exists($file)) {
return false;
}
if (is_file($file)) {
if (!is_readable($file)) {
return false;
}
return $ziparch->add_file_from_pathname($archivepath, $file);
}
if (is_dir($file)) {
if ($archivepath !== '') {
$ziparch->add_directory($archivepath);
}
$files = new DirectoryIterator($file);
foreach ($files as $file) {
if ($file->isDot()) {
continue;
}
$newpath = $archivepath.'/'.$file->getFilename();
$this->archive_pathname($ziparch, $newpath, $file->getPathname(), $progress);
}
unset($files); // Release file handles.
return true;
}
}
|
php
|
private function archive_pathname($ziparch, $archivepath, $file,
file_progress $progress = null) {
// Record progress each time this function is called.
if ($progress) {
$progress->progress();
}
if (!file_exists($file)) {
return false;
}
if (is_file($file)) {
if (!is_readable($file)) {
return false;
}
return $ziparch->add_file_from_pathname($archivepath, $file);
}
if (is_dir($file)) {
if ($archivepath !== '') {
$ziparch->add_directory($archivepath);
}
$files = new DirectoryIterator($file);
foreach ($files as $file) {
if ($file->isDot()) {
continue;
}
$newpath = $archivepath.'/'.$file->getFilename();
$this->archive_pathname($ziparch, $newpath, $file->getPathname(), $progress);
}
unset($files); // Release file handles.
return true;
}
}
|
[
"private",
"function",
"archive_pathname",
"(",
"$",
"ziparch",
",",
"$",
"archivepath",
",",
"$",
"file",
",",
"file_progress",
"$",
"progress",
"=",
"null",
")",
"{",
"// Record progress each time this function is called.",
"if",
"(",
"$",
"progress",
")",
"{",
"$",
"progress",
"->",
"progress",
"(",
")",
";",
"}",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"is_file",
"(",
"$",
"file",
")",
")",
"{",
"if",
"(",
"!",
"is_readable",
"(",
"$",
"file",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"ziparch",
"->",
"add_file_from_pathname",
"(",
"$",
"archivepath",
",",
"$",
"file",
")",
";",
"}",
"if",
"(",
"is_dir",
"(",
"$",
"file",
")",
")",
"{",
"if",
"(",
"$",
"archivepath",
"!==",
"''",
")",
"{",
"$",
"ziparch",
"->",
"add_directory",
"(",
"$",
"archivepath",
")",
";",
"}",
"$",
"files",
"=",
"new",
"DirectoryIterator",
"(",
"$",
"file",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"->",
"isDot",
"(",
")",
")",
"{",
"continue",
";",
"}",
"$",
"newpath",
"=",
"$",
"archivepath",
".",
"'/'",
".",
"$",
"file",
"->",
"getFilename",
"(",
")",
";",
"$",
"this",
"->",
"archive_pathname",
"(",
"$",
"ziparch",
",",
"$",
"newpath",
",",
"$",
"file",
"->",
"getPathname",
"(",
")",
",",
"$",
"progress",
")",
";",
"}",
"unset",
"(",
"$",
"files",
")",
";",
"// Release file handles.",
"return",
"true",
";",
"}",
"}"
] |
Perform archiving file from file path.
@param zip_archive $ziparch zip archive instance
@param string $archivepath file path to archive
@param string $file path name of the file
@param file_progress $progress Progress indicator callback or null if not required
@return bool success
|
[
"Perform",
"archiving",
"file",
"from",
"file",
"path",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/zip_packer.php#L218-L250
|
217,529
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Calculation/Engineering.php
|
PHPExcel_Calculation_Engineering.nbrConversionFormat
|
private static function nbrConversionFormat($xVal, $places)
{
if (!is_null($places)) {
if (strlen($xVal) <= $places) {
return substr(str_pad($xVal, $places, '0', STR_PAD_LEFT), -10);
} else {
return PHPExcel_Calculation_Functions::NaN();
}
}
return substr($xVal, -10);
}
|
php
|
private static function nbrConversionFormat($xVal, $places)
{
if (!is_null($places)) {
if (strlen($xVal) <= $places) {
return substr(str_pad($xVal, $places, '0', STR_PAD_LEFT), -10);
} else {
return PHPExcel_Calculation_Functions::NaN();
}
}
return substr($xVal, -10);
}
|
[
"private",
"static",
"function",
"nbrConversionFormat",
"(",
"$",
"xVal",
",",
"$",
"places",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"places",
")",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"xVal",
")",
"<=",
"$",
"places",
")",
"{",
"return",
"substr",
"(",
"str_pad",
"(",
"$",
"xVal",
",",
"$",
"places",
",",
"'0'",
",",
"STR_PAD_LEFT",
")",
",",
"-",
"10",
")",
";",
"}",
"else",
"{",
"return",
"PHPExcel_Calculation_Functions",
"::",
"NaN",
"(",
")",
";",
"}",
"}",
"return",
"substr",
"(",
"$",
"xVal",
",",
"-",
"10",
")",
";",
"}"
] |
Formats a number base string value with leading zeroes
@param string $xVal The "number" to pad
@param integer $places The length that we want to pad this value
@return string The padded "number"
|
[
"Formats",
"a",
"number",
"base",
"string",
"value",
"with",
"leading",
"zeroes"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Calculation/Engineering.php#L834-L845
|
217,530
|
moodle/moodle
|
question/type/essay/backup/moodle2/restore_qtype_essay_plugin.class.php
|
restore_qtype_essay_plugin.after_execute_question
|
protected function after_execute_question() {
global $DB;
$essayswithoutoptions = $DB->get_records_sql("
SELECT q.*
FROM {question} q
JOIN {backup_ids_temp} bi ON bi.newitemid = q.id
LEFT JOIN {qtype_essay_options} qeo ON qeo.questionid = q.id
WHERE q.qtype = ?
AND qeo.id IS NULL
AND bi.backupid = ?
AND bi.itemname = ?
", array('essay', $this->get_restoreid(), 'question_created'));
foreach ($essayswithoutoptions as $q) {
$defaultoptions = new stdClass();
$defaultoptions->questionid = $q->id;
$defaultoptions->responseformat = 'editor';
$defaultoptions->responserequired = 1;
$defaultoptions->responsefieldlines = 15;
$defaultoptions->attachments = 0;
$defaultoptions->attachmentsrequired = 0;
$defaultoptions->graderinfo = '';
$defaultoptions->graderinfoformat = FORMAT_HTML;
$defaultoptions->responsetemplate = '';
$defaultoptions->responsetemplateformat = FORMAT_HTML;
$DB->insert_record('qtype_essay_options', $defaultoptions);
}
}
|
php
|
protected function after_execute_question() {
global $DB;
$essayswithoutoptions = $DB->get_records_sql("
SELECT q.*
FROM {question} q
JOIN {backup_ids_temp} bi ON bi.newitemid = q.id
LEFT JOIN {qtype_essay_options} qeo ON qeo.questionid = q.id
WHERE q.qtype = ?
AND qeo.id IS NULL
AND bi.backupid = ?
AND bi.itemname = ?
", array('essay', $this->get_restoreid(), 'question_created'));
foreach ($essayswithoutoptions as $q) {
$defaultoptions = new stdClass();
$defaultoptions->questionid = $q->id;
$defaultoptions->responseformat = 'editor';
$defaultoptions->responserequired = 1;
$defaultoptions->responsefieldlines = 15;
$defaultoptions->attachments = 0;
$defaultoptions->attachmentsrequired = 0;
$defaultoptions->graderinfo = '';
$defaultoptions->graderinfoformat = FORMAT_HTML;
$defaultoptions->responsetemplate = '';
$defaultoptions->responsetemplateformat = FORMAT_HTML;
$DB->insert_record('qtype_essay_options', $defaultoptions);
}
}
|
[
"protected",
"function",
"after_execute_question",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"essayswithoutoptions",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"\"\n SELECT q.*\n FROM {question} q\n JOIN {backup_ids_temp} bi ON bi.newitemid = q.id\n LEFT JOIN {qtype_essay_options} qeo ON qeo.questionid = q.id\n WHERE q.qtype = ?\n AND qeo.id IS NULL\n AND bi.backupid = ?\n AND bi.itemname = ?\n \"",
",",
"array",
"(",
"'essay'",
",",
"$",
"this",
"->",
"get_restoreid",
"(",
")",
",",
"'question_created'",
")",
")",
";",
"foreach",
"(",
"$",
"essayswithoutoptions",
"as",
"$",
"q",
")",
"{",
"$",
"defaultoptions",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"defaultoptions",
"->",
"questionid",
"=",
"$",
"q",
"->",
"id",
";",
"$",
"defaultoptions",
"->",
"responseformat",
"=",
"'editor'",
";",
"$",
"defaultoptions",
"->",
"responserequired",
"=",
"1",
";",
"$",
"defaultoptions",
"->",
"responsefieldlines",
"=",
"15",
";",
"$",
"defaultoptions",
"->",
"attachments",
"=",
"0",
";",
"$",
"defaultoptions",
"->",
"attachmentsrequired",
"=",
"0",
";",
"$",
"defaultoptions",
"->",
"graderinfo",
"=",
"''",
";",
"$",
"defaultoptions",
"->",
"graderinfoformat",
"=",
"FORMAT_HTML",
";",
"$",
"defaultoptions",
"->",
"responsetemplate",
"=",
"''",
";",
"$",
"defaultoptions",
"->",
"responsetemplateformat",
"=",
"FORMAT_HTML",
";",
"$",
"DB",
"->",
"insert_record",
"(",
"'qtype_essay_options'",
",",
"$",
"defaultoptions",
")",
";",
"}",
"}"
] |
When restoring old data, that does not have the essay options information
in the XML, supply defaults.
|
[
"When",
"restoring",
"old",
"data",
"that",
"does",
"not",
"have",
"the",
"essay",
"options",
"information",
"in",
"the",
"XML",
"supply",
"defaults",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/essay/backup/moodle2/restore_qtype_essay_plugin.class.php#L94-L122
|
217,531
|
moodle/moodle
|
lib/spout/src/Spout/Writer/Common/Sheet.php
|
Sheet.doesStartOrEndWithSingleQuote
|
protected function doesStartOrEndWithSingleQuote($name)
{
$startsWithSingleQuote = ($this->stringHelper->getCharFirstOccurrencePosition('\'', $name) === 0);
$endsWithSingleQuote = ($this->stringHelper->getCharLastOccurrencePosition('\'', $name) === ($this->stringHelper->getStringLength($name) - 1));
return ($startsWithSingleQuote || $endsWithSingleQuote);
}
|
php
|
protected function doesStartOrEndWithSingleQuote($name)
{
$startsWithSingleQuote = ($this->stringHelper->getCharFirstOccurrencePosition('\'', $name) === 0);
$endsWithSingleQuote = ($this->stringHelper->getCharLastOccurrencePosition('\'', $name) === ($this->stringHelper->getStringLength($name) - 1));
return ($startsWithSingleQuote || $endsWithSingleQuote);
}
|
[
"protected",
"function",
"doesStartOrEndWithSingleQuote",
"(",
"$",
"name",
")",
"{",
"$",
"startsWithSingleQuote",
"=",
"(",
"$",
"this",
"->",
"stringHelper",
"->",
"getCharFirstOccurrencePosition",
"(",
"'\\''",
",",
"$",
"name",
")",
"===",
"0",
")",
";",
"$",
"endsWithSingleQuote",
"=",
"(",
"$",
"this",
"->",
"stringHelper",
"->",
"getCharLastOccurrencePosition",
"(",
"'\\''",
",",
"$",
"name",
")",
"===",
"(",
"$",
"this",
"->",
"stringHelper",
"->",
"getStringLength",
"(",
"$",
"name",
")",
"-",
"1",
")",
")",
";",
"return",
"(",
"$",
"startsWithSingleQuote",
"||",
"$",
"endsWithSingleQuote",
")",
";",
"}"
] |
Returns whether the given name starts or ends with a single quote
@param string $name
@return bool TRUE if the name starts or ends with a single quote, FALSE otherwise.
|
[
"Returns",
"whether",
"the",
"given",
"name",
"starts",
"or",
"ends",
"with",
"a",
"single",
"quote"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/Common/Sheet.php#L159-L165
|
217,532
|
moodle/moodle
|
lib/spout/src/Spout/Writer/Common/Sheet.php
|
Sheet.isNameUnique
|
protected function isNameUnique($name)
{
foreach (self::$SHEETS_NAME_USED[$this->associatedWorkbookId] as $sheetIndex => $sheetName) {
if ($sheetIndex !== $this->index && $sheetName === $name) {
return false;
}
}
return true;
}
|
php
|
protected function isNameUnique($name)
{
foreach (self::$SHEETS_NAME_USED[$this->associatedWorkbookId] as $sheetIndex => $sheetName) {
if ($sheetIndex !== $this->index && $sheetName === $name) {
return false;
}
}
return true;
}
|
[
"protected",
"function",
"isNameUnique",
"(",
"$",
"name",
")",
"{",
"foreach",
"(",
"self",
"::",
"$",
"SHEETS_NAME_USED",
"[",
"$",
"this",
"->",
"associatedWorkbookId",
"]",
"as",
"$",
"sheetIndex",
"=>",
"$",
"sheetName",
")",
"{",
"if",
"(",
"$",
"sheetIndex",
"!==",
"$",
"this",
"->",
"index",
"&&",
"$",
"sheetName",
"===",
"$",
"name",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Returns whether the given name is unique.
@param string $name
@return bool TRUE if the name is unique, FALSE otherwise.
|
[
"Returns",
"whether",
"the",
"given",
"name",
"is",
"unique",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/Common/Sheet.php#L173-L182
|
217,533
|
moodle/moodle
|
report/eventlist/classes/renderer.php
|
report_eventlist_renderer.render_event_list
|
public function render_event_list($form, $tabledata) {
global $PAGE;
$title = get_string('pluginname', 'report_eventlist');
// Header.
$html = $this->output->header();
$html .= $this->output->heading($title);
// Form.
ob_start();
$form->display();
$html .= ob_get_contents();
ob_end_clean();
$PAGE->requires->yui_module('moodle-report_eventlist-eventfilter', 'Y.M.report_eventlist.EventFilter.init',
array(array('tabledata' => $tabledata)));
$PAGE->requires->strings_for_js(array(
'eventname',
'component',
'action',
'crud',
'edulevel',
'affectedtable',
'dname',
'legacyevent',
'since'
), 'report_eventlist');
$html .= html_writer::start_div('report-eventlist-data-table', array('id' => 'report-eventlist-table'));
$html .= html_writer::end_div();
$html .= $this->output->footer();
return $html;
}
|
php
|
public function render_event_list($form, $tabledata) {
global $PAGE;
$title = get_string('pluginname', 'report_eventlist');
// Header.
$html = $this->output->header();
$html .= $this->output->heading($title);
// Form.
ob_start();
$form->display();
$html .= ob_get_contents();
ob_end_clean();
$PAGE->requires->yui_module('moodle-report_eventlist-eventfilter', 'Y.M.report_eventlist.EventFilter.init',
array(array('tabledata' => $tabledata)));
$PAGE->requires->strings_for_js(array(
'eventname',
'component',
'action',
'crud',
'edulevel',
'affectedtable',
'dname',
'legacyevent',
'since'
), 'report_eventlist');
$html .= html_writer::start_div('report-eventlist-data-table', array('id' => 'report-eventlist-table'));
$html .= html_writer::end_div();
$html .= $this->output->footer();
return $html;
}
|
[
"public",
"function",
"render_event_list",
"(",
"$",
"form",
",",
"$",
"tabledata",
")",
"{",
"global",
"$",
"PAGE",
";",
"$",
"title",
"=",
"get_string",
"(",
"'pluginname'",
",",
"'report_eventlist'",
")",
";",
"// Header.",
"$",
"html",
"=",
"$",
"this",
"->",
"output",
"->",
"header",
"(",
")",
";",
"$",
"html",
".=",
"$",
"this",
"->",
"output",
"->",
"heading",
"(",
"$",
"title",
")",
";",
"// Form.",
"ob_start",
"(",
")",
";",
"$",
"form",
"->",
"display",
"(",
")",
";",
"$",
"html",
".=",
"ob_get_contents",
"(",
")",
";",
"ob_end_clean",
"(",
")",
";",
"$",
"PAGE",
"->",
"requires",
"->",
"yui_module",
"(",
"'moodle-report_eventlist-eventfilter'",
",",
"'Y.M.report_eventlist.EventFilter.init'",
",",
"array",
"(",
"array",
"(",
"'tabledata'",
"=>",
"$",
"tabledata",
")",
")",
")",
";",
"$",
"PAGE",
"->",
"requires",
"->",
"strings_for_js",
"(",
"array",
"(",
"'eventname'",
",",
"'component'",
",",
"'action'",
",",
"'crud'",
",",
"'edulevel'",
",",
"'affectedtable'",
",",
"'dname'",
",",
"'legacyevent'",
",",
"'since'",
")",
",",
"'report_eventlist'",
")",
";",
"$",
"html",
".=",
"html_writer",
"::",
"start_div",
"(",
"'report-eventlist-data-table'",
",",
"array",
"(",
"'id'",
"=>",
"'report-eventlist-table'",
")",
")",
";",
"$",
"html",
".=",
"html_writer",
"::",
"end_div",
"(",
")",
";",
"$",
"html",
".=",
"$",
"this",
"->",
"output",
"->",
"footer",
"(",
")",
";",
"return",
"$",
"html",
";",
"}"
] |
Renders the event list page with filter form and datatable.
@param eventfilter_form $form Event filter form.
@param array $tabledata An array of event data to be used by the datatable.
@return string HTML to be displayed.
|
[
"Renders",
"the",
"event",
"list",
"page",
"with",
"filter",
"form",
"and",
"datatable",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/eventlist/classes/renderer.php#L43-L76
|
217,534
|
moodle/moodle
|
lib/ddl/oracle_sql_generator.php
|
oracle_sql_generator.getTableName
|
public function getTableName(xmldb_table $xmldb_table, $quoted=true) {
// Get the name, supporting special oci names for temp tables
if ($this->temptables->is_temptable($xmldb_table->getName())) {
$tablename = $this->temptables->get_correct_name($xmldb_table->getName());
} else {
$tablename = $this->prefix . $xmldb_table->getName();
}
// Apply quotes optionally
if ($quoted) {
$tablename = $this->getEncQuoted($tablename);
}
return $tablename;
}
|
php
|
public function getTableName(xmldb_table $xmldb_table, $quoted=true) {
// Get the name, supporting special oci names for temp tables
if ($this->temptables->is_temptable($xmldb_table->getName())) {
$tablename = $this->temptables->get_correct_name($xmldb_table->getName());
} else {
$tablename = $this->prefix . $xmldb_table->getName();
}
// Apply quotes optionally
if ($quoted) {
$tablename = $this->getEncQuoted($tablename);
}
return $tablename;
}
|
[
"public",
"function",
"getTableName",
"(",
"xmldb_table",
"$",
"xmldb_table",
",",
"$",
"quoted",
"=",
"true",
")",
"{",
"// Get the name, supporting special oci names for temp tables",
"if",
"(",
"$",
"this",
"->",
"temptables",
"->",
"is_temptable",
"(",
"$",
"xmldb_table",
"->",
"getName",
"(",
")",
")",
")",
"{",
"$",
"tablename",
"=",
"$",
"this",
"->",
"temptables",
"->",
"get_correct_name",
"(",
"$",
"xmldb_table",
"->",
"getName",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"tablename",
"=",
"$",
"this",
"->",
"prefix",
".",
"$",
"xmldb_table",
"->",
"getName",
"(",
")",
";",
"}",
"// Apply quotes optionally",
"if",
"(",
"$",
"quoted",
")",
"{",
"$",
"tablename",
"=",
"$",
"this",
"->",
"getEncQuoted",
"(",
"$",
"tablename",
")",
";",
"}",
"return",
"$",
"tablename",
";",
"}"
] |
Given one xmldb_table, returns it's correct name, depending of all the parametrization
Overridden to allow change of names in temp tables
@param xmldb_table table whose name we want
@param boolean to specify if the name must be quoted (if reserved word, only!)
@return string the correct name of the table
|
[
"Given",
"one",
"xmldb_table",
"returns",
"it",
"s",
"correct",
"name",
"depending",
"of",
"all",
"the",
"parametrization",
"Overridden",
"to",
"allow",
"change",
"of",
"names",
"in",
"temp",
"tables"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ddl/oracle_sql_generator.php#L118-L132
|
217,535
|
moodle/moodle
|
lib/ddl/oracle_sql_generator.php
|
oracle_sql_generator.getCreateTriggerSQL
|
public function getCreateTriggerSQL($xmldb_table, $xmldb_field, $sequence_name) {
$trigger_name = $this->getNameForObject($xmldb_table->getName(), $xmldb_field->getName(), 'trg');
$trigger = "CREATE TRIGGER " . $trigger_name;
$trigger.= "\n BEFORE INSERT";
$trigger.= "\nON " . $this->getTableName($xmldb_table);
$trigger.= "\n FOR EACH ROW";
$trigger.= "\nBEGIN";
$trigger.= "\n IF :new." . $this->getEncQuoted($xmldb_field->getName()) . ' IS NULL THEN';
$trigger.= "\n SELECT " . $sequence_name . '.nextval INTO :new.' . $this->getEncQuoted($xmldb_field->getName()) . " FROM dual;";
$trigger.= "\n END IF;";
$trigger.= "\nEND;";
return array($trigger);
}
|
php
|
public function getCreateTriggerSQL($xmldb_table, $xmldb_field, $sequence_name) {
$trigger_name = $this->getNameForObject($xmldb_table->getName(), $xmldb_field->getName(), 'trg');
$trigger = "CREATE TRIGGER " . $trigger_name;
$trigger.= "\n BEFORE INSERT";
$trigger.= "\nON " . $this->getTableName($xmldb_table);
$trigger.= "\n FOR EACH ROW";
$trigger.= "\nBEGIN";
$trigger.= "\n IF :new." . $this->getEncQuoted($xmldb_field->getName()) . ' IS NULL THEN';
$trigger.= "\n SELECT " . $sequence_name . '.nextval INTO :new.' . $this->getEncQuoted($xmldb_field->getName()) . " FROM dual;";
$trigger.= "\n END IF;";
$trigger.= "\nEND;";
return array($trigger);
}
|
[
"public",
"function",
"getCreateTriggerSQL",
"(",
"$",
"xmldb_table",
",",
"$",
"xmldb_field",
",",
"$",
"sequence_name",
")",
"{",
"$",
"trigger_name",
"=",
"$",
"this",
"->",
"getNameForObject",
"(",
"$",
"xmldb_table",
"->",
"getName",
"(",
")",
",",
"$",
"xmldb_field",
"->",
"getName",
"(",
")",
",",
"'trg'",
")",
";",
"$",
"trigger",
"=",
"\"CREATE TRIGGER \"",
".",
"$",
"trigger_name",
";",
"$",
"trigger",
".=",
"\"\\n BEFORE INSERT\"",
";",
"$",
"trigger",
".=",
"\"\\nON \"",
".",
"$",
"this",
"->",
"getTableName",
"(",
"$",
"xmldb_table",
")",
";",
"$",
"trigger",
".=",
"\"\\n FOR EACH ROW\"",
";",
"$",
"trigger",
".=",
"\"\\nBEGIN\"",
";",
"$",
"trigger",
".=",
"\"\\n IF :new.\"",
".",
"$",
"this",
"->",
"getEncQuoted",
"(",
"$",
"xmldb_field",
"->",
"getName",
"(",
")",
")",
".",
"' IS NULL THEN'",
";",
"$",
"trigger",
".=",
"\"\\n SELECT \"",
".",
"$",
"sequence_name",
".",
"'.nextval INTO :new.'",
".",
"$",
"this",
"->",
"getEncQuoted",
"(",
"$",
"xmldb_field",
"->",
"getName",
"(",
")",
")",
".",
"\" FROM dual;\"",
";",
"$",
"trigger",
".=",
"\"\\n END IF;\"",
";",
"$",
"trigger",
".=",
"\"\\nEND;\"",
";",
"return",
"array",
"(",
"$",
"trigger",
")",
";",
"}"
] |
Returns the code needed to create one trigger for the xmldb_table and xmldb_field passed
@param xmldb_table $xmldb_table The xmldb_table object instance.
@param xmldb_field $xmldb_field The xmldb_field object instance.
@param string $sequence_name
@return array Array of SQL statements to create the sequence.
|
[
"Returns",
"the",
"code",
"needed",
"to",
"create",
"one",
"trigger",
"for",
"the",
"xmldb_table",
"and",
"xmldb_field",
"passed"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ddl/oracle_sql_generator.php#L301-L316
|
217,536
|
moodle/moodle
|
lib/ddl/oracle_sql_generator.php
|
oracle_sql_generator.getDropSequenceSQL
|
public function getDropSequenceSQL($xmldb_table, $xmldb_field, $include_trigger=false) {
$result = array();
if ($sequence_name = $this->getSequenceFromDB($xmldb_table)) {
$result[] = "DROP SEQUENCE " . $sequence_name;
}
if ($trigger_name = $this->getTriggerFromDB($xmldb_table) && $include_trigger) {
$result[] = "DROP TRIGGER " . $trigger_name;
}
return $result;
}
|
php
|
public function getDropSequenceSQL($xmldb_table, $xmldb_field, $include_trigger=false) {
$result = array();
if ($sequence_name = $this->getSequenceFromDB($xmldb_table)) {
$result[] = "DROP SEQUENCE " . $sequence_name;
}
if ($trigger_name = $this->getTriggerFromDB($xmldb_table) && $include_trigger) {
$result[] = "DROP TRIGGER " . $trigger_name;
}
return $result;
}
|
[
"public",
"function",
"getDropSequenceSQL",
"(",
"$",
"xmldb_table",
",",
"$",
"xmldb_field",
",",
"$",
"include_trigger",
"=",
"false",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"sequence_name",
"=",
"$",
"this",
"->",
"getSequenceFromDB",
"(",
"$",
"xmldb_table",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"\"DROP SEQUENCE \"",
".",
"$",
"sequence_name",
";",
"}",
"if",
"(",
"$",
"trigger_name",
"=",
"$",
"this",
"->",
"getTriggerFromDB",
"(",
"$",
"xmldb_table",
")",
"&&",
"$",
"include_trigger",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"\"DROP TRIGGER \"",
".",
"$",
"trigger_name",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Returns the code needed to drop one sequence for the xmldb_table and xmldb_field passed
Can, optionally, specify if the underlying trigger will be also dropped
@param xmldb_table $xmldb_table The xmldb_table object instance.
@param xmldb_field $xmldb_field The xmldb_field object instance.
@param bool $include_trigger
@return array Array of SQL statements to create the sequence.
|
[
"Returns",
"the",
"code",
"needed",
"to",
"drop",
"one",
"sequence",
"for",
"the",
"xmldb_table",
"and",
"xmldb_field",
"passed",
"Can",
"optionally",
"specify",
"if",
"the",
"underlying",
"trigger",
"will",
"be",
"also",
"dropped"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ddl/oracle_sql_generator.php#L327-L340
|
217,537
|
moodle/moodle
|
question/type/calculated/backup/moodle1/lib.php
|
moodle1_qtype_calculated_handler.process_question
|
public function process_question(array $data, array $raw) {
// Convert and write the answers first.
if (isset($data['answers'])) {
$this->write_answers($data['answers'], $this->pluginname);
}
// Convert and write the numerical units and numerical options.
if (isset($data['calculated'][0]['numerical_units'])) {
$numericalunits = $data['calculated'][0]['numerical_units'];
} else {
$numericalunits = array();
}
$numericaloptions = $this->get_default_numerical_options(
$data['oldquestiontextformat'], $numericalunits);
$this->write_numerical_units($numericalunits);
$this->write_numerical_options($numericaloptions);
// Write dataset_definitions.
if (isset($data['calculated'][0]['dataset_definitions']['dataset_definition'])) {
$datasetdefinitions = $data['calculated'][0]['dataset_definitions']['dataset_definition'];
} else {
$datasetdefinitions = array();
}
$this->write_dataset_definitions($datasetdefinitions);
// Write calculated_records.
$this->xmlwriter->begin_tag('calculated_records');
foreach ($data['calculated'] as $calculatedrecord) {
$record = array(
'id' => $this->converter->get_nextid(),
'answer' => $calculatedrecord['answer'],
'tolerance' => $calculatedrecord['tolerance'],
'tolerancetype' => $calculatedrecord['tolerancetype'],
'correctanswerlength' => $calculatedrecord['correctanswerlength'],
'correctanswerformat' => $calculatedrecord['correctanswerformat']
);
$this->write_xml('calculated_record', $record, array('/calculated_record/id'));
}
$this->xmlwriter->end_tag('calculated_records');
// Write calculated_options.
$options = array(
'calculate_option' => array(
'id' => $this->converter->get_nextid(),
'synchronize' => 0,
'single' => 0,
'shuffleanswers' => 0,
'correctfeedback' => null,
'correctfeedbackformat' => FORMAT_HTML,
'partiallycorrectfeedback' => null,
'partiallycorrectfeedbackformat' => FORMAT_HTML,
'incorrectfeedback' => null,
'incorrectfeedbackformat' => FORMAT_HTML,
'answernumbering' => 'abc'
)
);
$this->write_xml('calculated_options', $options, array('/calculated_options/calculate_option/id'));
}
|
php
|
public function process_question(array $data, array $raw) {
// Convert and write the answers first.
if (isset($data['answers'])) {
$this->write_answers($data['answers'], $this->pluginname);
}
// Convert and write the numerical units and numerical options.
if (isset($data['calculated'][0]['numerical_units'])) {
$numericalunits = $data['calculated'][0]['numerical_units'];
} else {
$numericalunits = array();
}
$numericaloptions = $this->get_default_numerical_options(
$data['oldquestiontextformat'], $numericalunits);
$this->write_numerical_units($numericalunits);
$this->write_numerical_options($numericaloptions);
// Write dataset_definitions.
if (isset($data['calculated'][0]['dataset_definitions']['dataset_definition'])) {
$datasetdefinitions = $data['calculated'][0]['dataset_definitions']['dataset_definition'];
} else {
$datasetdefinitions = array();
}
$this->write_dataset_definitions($datasetdefinitions);
// Write calculated_records.
$this->xmlwriter->begin_tag('calculated_records');
foreach ($data['calculated'] as $calculatedrecord) {
$record = array(
'id' => $this->converter->get_nextid(),
'answer' => $calculatedrecord['answer'],
'tolerance' => $calculatedrecord['tolerance'],
'tolerancetype' => $calculatedrecord['tolerancetype'],
'correctanswerlength' => $calculatedrecord['correctanswerlength'],
'correctanswerformat' => $calculatedrecord['correctanswerformat']
);
$this->write_xml('calculated_record', $record, array('/calculated_record/id'));
}
$this->xmlwriter->end_tag('calculated_records');
// Write calculated_options.
$options = array(
'calculate_option' => array(
'id' => $this->converter->get_nextid(),
'synchronize' => 0,
'single' => 0,
'shuffleanswers' => 0,
'correctfeedback' => null,
'correctfeedbackformat' => FORMAT_HTML,
'partiallycorrectfeedback' => null,
'partiallycorrectfeedbackformat' => FORMAT_HTML,
'incorrectfeedback' => null,
'incorrectfeedbackformat' => FORMAT_HTML,
'answernumbering' => 'abc'
)
);
$this->write_xml('calculated_options', $options, array('/calculated_options/calculate_option/id'));
}
|
[
"public",
"function",
"process_question",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"raw",
")",
"{",
"// Convert and write the answers first.",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'answers'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"write_answers",
"(",
"$",
"data",
"[",
"'answers'",
"]",
",",
"$",
"this",
"->",
"pluginname",
")",
";",
"}",
"// Convert and write the numerical units and numerical options.",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'calculated'",
"]",
"[",
"0",
"]",
"[",
"'numerical_units'",
"]",
")",
")",
"{",
"$",
"numericalunits",
"=",
"$",
"data",
"[",
"'calculated'",
"]",
"[",
"0",
"]",
"[",
"'numerical_units'",
"]",
";",
"}",
"else",
"{",
"$",
"numericalunits",
"=",
"array",
"(",
")",
";",
"}",
"$",
"numericaloptions",
"=",
"$",
"this",
"->",
"get_default_numerical_options",
"(",
"$",
"data",
"[",
"'oldquestiontextformat'",
"]",
",",
"$",
"numericalunits",
")",
";",
"$",
"this",
"->",
"write_numerical_units",
"(",
"$",
"numericalunits",
")",
";",
"$",
"this",
"->",
"write_numerical_options",
"(",
"$",
"numericaloptions",
")",
";",
"// Write dataset_definitions.",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'calculated'",
"]",
"[",
"0",
"]",
"[",
"'dataset_definitions'",
"]",
"[",
"'dataset_definition'",
"]",
")",
")",
"{",
"$",
"datasetdefinitions",
"=",
"$",
"data",
"[",
"'calculated'",
"]",
"[",
"0",
"]",
"[",
"'dataset_definitions'",
"]",
"[",
"'dataset_definition'",
"]",
";",
"}",
"else",
"{",
"$",
"datasetdefinitions",
"=",
"array",
"(",
")",
";",
"}",
"$",
"this",
"->",
"write_dataset_definitions",
"(",
"$",
"datasetdefinitions",
")",
";",
"// Write calculated_records.",
"$",
"this",
"->",
"xmlwriter",
"->",
"begin_tag",
"(",
"'calculated_records'",
")",
";",
"foreach",
"(",
"$",
"data",
"[",
"'calculated'",
"]",
"as",
"$",
"calculatedrecord",
")",
"{",
"$",
"record",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"converter",
"->",
"get_nextid",
"(",
")",
",",
"'answer'",
"=>",
"$",
"calculatedrecord",
"[",
"'answer'",
"]",
",",
"'tolerance'",
"=>",
"$",
"calculatedrecord",
"[",
"'tolerance'",
"]",
",",
"'tolerancetype'",
"=>",
"$",
"calculatedrecord",
"[",
"'tolerancetype'",
"]",
",",
"'correctanswerlength'",
"=>",
"$",
"calculatedrecord",
"[",
"'correctanswerlength'",
"]",
",",
"'correctanswerformat'",
"=>",
"$",
"calculatedrecord",
"[",
"'correctanswerformat'",
"]",
")",
";",
"$",
"this",
"->",
"write_xml",
"(",
"'calculated_record'",
",",
"$",
"record",
",",
"array",
"(",
"'/calculated_record/id'",
")",
")",
";",
"}",
"$",
"this",
"->",
"xmlwriter",
"->",
"end_tag",
"(",
"'calculated_records'",
")",
";",
"// Write calculated_options.",
"$",
"options",
"=",
"array",
"(",
"'calculate_option'",
"=>",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"converter",
"->",
"get_nextid",
"(",
")",
",",
"'synchronize'",
"=>",
"0",
",",
"'single'",
"=>",
"0",
",",
"'shuffleanswers'",
"=>",
"0",
",",
"'correctfeedback'",
"=>",
"null",
",",
"'correctfeedbackformat'",
"=>",
"FORMAT_HTML",
",",
"'partiallycorrectfeedback'",
"=>",
"null",
",",
"'partiallycorrectfeedbackformat'",
"=>",
"FORMAT_HTML",
",",
"'incorrectfeedback'",
"=>",
"null",
",",
"'incorrectfeedbackformat'",
"=>",
"FORMAT_HTML",
",",
"'answernumbering'",
"=>",
"'abc'",
")",
")",
";",
"$",
"this",
"->",
"write_xml",
"(",
"'calculated_options'",
",",
"$",
"options",
",",
"array",
"(",
"'/calculated_options/calculate_option/id'",
")",
")",
";",
"}"
] |
Appends the calculated specific information to the question
|
[
"Appends",
"the",
"calculated",
"specific",
"information",
"to",
"the",
"question"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/calculated/backup/moodle1/lib.php#L47-L106
|
217,538
|
moodle/moodle
|
backup/cc/cc_lib/cc_utils.php
|
cc_helpers.uuidgen
|
public static function uuidgen($prefix = '', $suffix = '', $uppercase = true) {
$uuid = trim(sprintf('%s%04x%04x%s', $prefix, mt_rand(0, 65535), mt_rand(0, 65535), $suffix));
$result = $uppercase ? strtoupper($uuid) : strtolower($uuid);
return $result;
}
|
php
|
public static function uuidgen($prefix = '', $suffix = '', $uppercase = true) {
$uuid = trim(sprintf('%s%04x%04x%s', $prefix, mt_rand(0, 65535), mt_rand(0, 65535), $suffix));
$result = $uppercase ? strtoupper($uuid) : strtolower($uuid);
return $result;
}
|
[
"public",
"static",
"function",
"uuidgen",
"(",
"$",
"prefix",
"=",
"''",
",",
"$",
"suffix",
"=",
"''",
",",
"$",
"uppercase",
"=",
"true",
")",
"{",
"$",
"uuid",
"=",
"trim",
"(",
"sprintf",
"(",
"'%s%04x%04x%s'",
",",
"$",
"prefix",
",",
"mt_rand",
"(",
"0",
",",
"65535",
")",
",",
"mt_rand",
"(",
"0",
",",
"65535",
")",
",",
"$",
"suffix",
")",
")",
";",
"$",
"result",
"=",
"$",
"uppercase",
"?",
"strtoupper",
"(",
"$",
"uuid",
")",
":",
"strtolower",
"(",
"$",
"uuid",
")",
";",
"return",
"$",
"result",
";",
"}"
] |
Generates unique identifier
@param string $prefix
@param string $suffix
@return string
|
[
"Generates",
"unique",
"identifier"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/cc/cc_lib/cc_utils.php#L50-L54
|
217,539
|
moodle/moodle
|
backup/cc/cc_lib/cc_utils.php
|
cc_helpers.randomdir
|
public static function randomdir($where, $prefix = '', $suffix = '') {
global $CFG;
$dirname = false;
$randomname = self::uuidgen($prefix, $suffix, false);
$newdirname = $where.DIRECTORY_SEPARATOR.$randomname;
if (mkdir($newdirname)) {
chmod($newdirname, $CFG->directorypermissions);
$dirname = $randomname;
}
return $dirname;
}
|
php
|
public static function randomdir($where, $prefix = '', $suffix = '') {
global $CFG;
$dirname = false;
$randomname = self::uuidgen($prefix, $suffix, false);
$newdirname = $where.DIRECTORY_SEPARATOR.$randomname;
if (mkdir($newdirname)) {
chmod($newdirname, $CFG->directorypermissions);
$dirname = $randomname;
}
return $dirname;
}
|
[
"public",
"static",
"function",
"randomdir",
"(",
"$",
"where",
",",
"$",
"prefix",
"=",
"''",
",",
"$",
"suffix",
"=",
"''",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"dirname",
"=",
"false",
";",
"$",
"randomname",
"=",
"self",
"::",
"uuidgen",
"(",
"$",
"prefix",
",",
"$",
"suffix",
",",
"false",
")",
";",
"$",
"newdirname",
"=",
"$",
"where",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"randomname",
";",
"if",
"(",
"mkdir",
"(",
"$",
"newdirname",
")",
")",
"{",
"chmod",
"(",
"$",
"newdirname",
",",
"$",
"CFG",
"->",
"directorypermissions",
")",
";",
"$",
"dirname",
"=",
"$",
"randomname",
";",
"}",
"return",
"$",
"dirname",
";",
"}"
] |
Creates new folder with random name
@param string $where
@param string $prefix
@param string $suffix
@return mixed - directory short name or false in case of failure
|
[
"Creates",
"new",
"folder",
"with",
"random",
"name"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/cc/cc_lib/cc_utils.php#L63-L74
|
217,540
|
moodle/moodle
|
lib/mustache/src/Mustache/Tokenizer.php
|
Mustache_Tokenizer.reset
|
private function reset()
{
$this->state = self::IN_TEXT;
$this->tagType = null;
$this->buffer = '';
$this->tokens = array();
$this->seenTag = false;
$this->line = 0;
$this->otag = '{{';
$this->ctag = '}}';
$this->otagLen = 2;
$this->ctagLen = 2;
}
|
php
|
private function reset()
{
$this->state = self::IN_TEXT;
$this->tagType = null;
$this->buffer = '';
$this->tokens = array();
$this->seenTag = false;
$this->line = 0;
$this->otag = '{{';
$this->ctag = '}}';
$this->otagLen = 2;
$this->ctagLen = 2;
}
|
[
"private",
"function",
"reset",
"(",
")",
"{",
"$",
"this",
"->",
"state",
"=",
"self",
"::",
"IN_TEXT",
";",
"$",
"this",
"->",
"tagType",
"=",
"null",
";",
"$",
"this",
"->",
"buffer",
"=",
"''",
";",
"$",
"this",
"->",
"tokens",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"seenTag",
"=",
"false",
";",
"$",
"this",
"->",
"line",
"=",
"0",
";",
"$",
"this",
"->",
"otag",
"=",
"'{{'",
";",
"$",
"this",
"->",
"ctag",
"=",
"'}}'",
";",
"$",
"this",
"->",
"otagLen",
"=",
"2",
";",
"$",
"this",
"->",
"ctagLen",
"=",
"2",
";",
"}"
] |
Helper function to reset tokenizer internal state.
|
[
"Helper",
"function",
"to",
"reset",
"tokenizer",
"internal",
"state",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Tokenizer.php#L220-L232
|
217,541
|
moodle/moodle
|
lib/mustache/src/Mustache/Tokenizer.php
|
Mustache_Tokenizer.flushBuffer
|
private function flushBuffer()
{
if (strlen($this->buffer) > 0) {
$this->tokens[] = array(
self::TYPE => self::T_TEXT,
self::LINE => $this->line,
self::VALUE => $this->buffer,
);
$this->buffer = '';
}
}
|
php
|
private function flushBuffer()
{
if (strlen($this->buffer) > 0) {
$this->tokens[] = array(
self::TYPE => self::T_TEXT,
self::LINE => $this->line,
self::VALUE => $this->buffer,
);
$this->buffer = '';
}
}
|
[
"private",
"function",
"flushBuffer",
"(",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"this",
"->",
"buffer",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"tokens",
"[",
"]",
"=",
"array",
"(",
"self",
"::",
"TYPE",
"=>",
"self",
"::",
"T_TEXT",
",",
"self",
"::",
"LINE",
"=>",
"$",
"this",
"->",
"line",
",",
"self",
"::",
"VALUE",
"=>",
"$",
"this",
"->",
"buffer",
",",
")",
";",
"$",
"this",
"->",
"buffer",
"=",
"''",
";",
"}",
"}"
] |
Flush the current buffer to a token.
|
[
"Flush",
"the",
"current",
"buffer",
"to",
"a",
"token",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Tokenizer.php#L237-L247
|
217,542
|
moodle/moodle
|
lib/mustache/src/Mustache/Tokenizer.php
|
Mustache_Tokenizer.changeDelimiters
|
private function changeDelimiters($text, $index)
{
$startIndex = strpos($text, '=', $index) + 1;
$close = '=' . $this->ctag;
$closeIndex = strpos($text, $close, $index);
$this->setDelimiters(trim(substr($text, $startIndex, $closeIndex - $startIndex)));
$this->tokens[] = array(
self::TYPE => self::T_DELIM_CHANGE,
self::LINE => $this->line,
);
return $closeIndex + strlen($close) - 1;
}
|
php
|
private function changeDelimiters($text, $index)
{
$startIndex = strpos($text, '=', $index) + 1;
$close = '=' . $this->ctag;
$closeIndex = strpos($text, $close, $index);
$this->setDelimiters(trim(substr($text, $startIndex, $closeIndex - $startIndex)));
$this->tokens[] = array(
self::TYPE => self::T_DELIM_CHANGE,
self::LINE => $this->line,
);
return $closeIndex + strlen($close) - 1;
}
|
[
"private",
"function",
"changeDelimiters",
"(",
"$",
"text",
",",
"$",
"index",
")",
"{",
"$",
"startIndex",
"=",
"strpos",
"(",
"$",
"text",
",",
"'='",
",",
"$",
"index",
")",
"+",
"1",
";",
"$",
"close",
"=",
"'='",
".",
"$",
"this",
"->",
"ctag",
";",
"$",
"closeIndex",
"=",
"strpos",
"(",
"$",
"text",
",",
"$",
"close",
",",
"$",
"index",
")",
";",
"$",
"this",
"->",
"setDelimiters",
"(",
"trim",
"(",
"substr",
"(",
"$",
"text",
",",
"$",
"startIndex",
",",
"$",
"closeIndex",
"-",
"$",
"startIndex",
")",
")",
")",
";",
"$",
"this",
"->",
"tokens",
"[",
"]",
"=",
"array",
"(",
"self",
"::",
"TYPE",
"=>",
"self",
"::",
"T_DELIM_CHANGE",
",",
"self",
"::",
"LINE",
"=>",
"$",
"this",
"->",
"line",
",",
")",
";",
"return",
"$",
"closeIndex",
"+",
"strlen",
"(",
"$",
"close",
")",
"-",
"1",
";",
"}"
] |
Change the current Mustache delimiters. Set new `otag` and `ctag` values.
@param string $text Mustache template source
@param int $index Current tokenizer index
@return int New index value
|
[
"Change",
"the",
"current",
"Mustache",
"delimiters",
".",
"Set",
"new",
"otag",
"and",
"ctag",
"values",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Tokenizer.php#L257-L271
|
217,543
|
moodle/moodle
|
lib/mustache/src/Mustache/Tokenizer.php
|
Mustache_Tokenizer.setDelimiters
|
private function setDelimiters($delimiters)
{
list($otag, $ctag) = explode(' ', $delimiters);
$this->otag = $otag;
$this->ctag = $ctag;
$this->otagLen = strlen($otag);
$this->ctagLen = strlen($ctag);
}
|
php
|
private function setDelimiters($delimiters)
{
list($otag, $ctag) = explode(' ', $delimiters);
$this->otag = $otag;
$this->ctag = $ctag;
$this->otagLen = strlen($otag);
$this->ctagLen = strlen($ctag);
}
|
[
"private",
"function",
"setDelimiters",
"(",
"$",
"delimiters",
")",
"{",
"list",
"(",
"$",
"otag",
",",
"$",
"ctag",
")",
"=",
"explode",
"(",
"' '",
",",
"$",
"delimiters",
")",
";",
"$",
"this",
"->",
"otag",
"=",
"$",
"otag",
";",
"$",
"this",
"->",
"ctag",
"=",
"$",
"ctag",
";",
"$",
"this",
"->",
"otagLen",
"=",
"strlen",
"(",
"$",
"otag",
")",
";",
"$",
"this",
"->",
"ctagLen",
"=",
"strlen",
"(",
"$",
"ctag",
")",
";",
"}"
] |
Set the current Mustache `otag` and `ctag` delimiters.
@param string $delimiters
|
[
"Set",
"the",
"current",
"Mustache",
"otag",
"and",
"ctag",
"delimiters",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Tokenizer.php#L278-L285
|
217,544
|
moodle/moodle
|
lib/mustache/src/Mustache/Tokenizer.php
|
Mustache_Tokenizer.addPragma
|
private function addPragma($text, $index)
{
$end = strpos($text, $this->ctag, $index);
$pragma = trim(substr($text, $index + 2, $end - $index - 2));
// Pragmas are hoisted to the front of the template.
array_unshift($this->tokens, array(
self::TYPE => self::T_PRAGMA,
self::NAME => $pragma,
self::LINE => 0,
));
return $end + $this->ctagLen - 1;
}
|
php
|
private function addPragma($text, $index)
{
$end = strpos($text, $this->ctag, $index);
$pragma = trim(substr($text, $index + 2, $end - $index - 2));
// Pragmas are hoisted to the front of the template.
array_unshift($this->tokens, array(
self::TYPE => self::T_PRAGMA,
self::NAME => $pragma,
self::LINE => 0,
));
return $end + $this->ctagLen - 1;
}
|
[
"private",
"function",
"addPragma",
"(",
"$",
"text",
",",
"$",
"index",
")",
"{",
"$",
"end",
"=",
"strpos",
"(",
"$",
"text",
",",
"$",
"this",
"->",
"ctag",
",",
"$",
"index",
")",
";",
"$",
"pragma",
"=",
"trim",
"(",
"substr",
"(",
"$",
"text",
",",
"$",
"index",
"+",
"2",
",",
"$",
"end",
"-",
"$",
"index",
"-",
"2",
")",
")",
";",
"// Pragmas are hoisted to the front of the template.",
"array_unshift",
"(",
"$",
"this",
"->",
"tokens",
",",
"array",
"(",
"self",
"::",
"TYPE",
"=>",
"self",
"::",
"T_PRAGMA",
",",
"self",
"::",
"NAME",
"=>",
"$",
"pragma",
",",
"self",
"::",
"LINE",
"=>",
"0",
",",
")",
")",
";",
"return",
"$",
"end",
"+",
"$",
"this",
"->",
"ctagLen",
"-",
"1",
";",
"}"
] |
Add pragma token.
Pragmas are hoisted to the front of the template, so all pragma tokens
will appear at the front of the token list.
@param string $text
@param int $index
@return int New index value
|
[
"Add",
"pragma",
"token",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Tokenizer.php#L298-L311
|
217,545
|
moodle/moodle
|
lib/mustache/src/Mustache/Tokenizer.php
|
Mustache_Tokenizer.tagChange
|
private function tagChange($tag, $tagLen, $text, $index)
{
return substr($text, $index, $tagLen) === $tag;
}
|
php
|
private function tagChange($tag, $tagLen, $text, $index)
{
return substr($text, $index, $tagLen) === $tag;
}
|
[
"private",
"function",
"tagChange",
"(",
"$",
"tag",
",",
"$",
"tagLen",
",",
"$",
"text",
",",
"$",
"index",
")",
"{",
"return",
"substr",
"(",
"$",
"text",
",",
"$",
"index",
",",
"$",
"tagLen",
")",
"===",
"$",
"tag",
";",
"}"
] |
Test whether it's time to change tags.
@param string $tag Current tag name
@param int $tagLen Current tag name length
@param string $text Mustache template source
@param int $index Current tokenizer index
@return bool True if this is a closing section tag
|
[
"Test",
"whether",
"it",
"s",
"time",
"to",
"change",
"tags",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Tokenizer.php#L323-L326
|
217,546
|
moodle/moodle
|
lib/google/src/Google/Config.php
|
Google_Config.setAuthClass
|
public function setAuthClass($class)
{
$prev = $this->configuration['auth_class'];
if (!isset($this->configuration['classes'][$class]) &&
isset($this->configuration['classes'][$prev])) {
$this->configuration['classes'][$class] =
$this->configuration['classes'][$prev];
}
$this->configuration['auth_class'] = $class;
}
|
php
|
public function setAuthClass($class)
{
$prev = $this->configuration['auth_class'];
if (!isset($this->configuration['classes'][$class]) &&
isset($this->configuration['classes'][$prev])) {
$this->configuration['classes'][$class] =
$this->configuration['classes'][$prev];
}
$this->configuration['auth_class'] = $class;
}
|
[
"public",
"function",
"setAuthClass",
"(",
"$",
"class",
")",
"{",
"$",
"prev",
"=",
"$",
"this",
"->",
"configuration",
"[",
"'auth_class'",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"configuration",
"[",
"'classes'",
"]",
"[",
"$",
"class",
"]",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"configuration",
"[",
"'classes'",
"]",
"[",
"$",
"prev",
"]",
")",
")",
"{",
"$",
"this",
"->",
"configuration",
"[",
"'classes'",
"]",
"[",
"$",
"class",
"]",
"=",
"$",
"this",
"->",
"configuration",
"[",
"'classes'",
"]",
"[",
"$",
"prev",
"]",
";",
"}",
"$",
"this",
"->",
"configuration",
"[",
"'auth_class'",
"]",
"=",
"$",
"class",
";",
"}"
] |
Set the auth class.
@param $class string the class name to set
|
[
"Set",
"the",
"auth",
"class",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/google/src/Google/Config.php#L223-L232
|
217,547
|
moodle/moodle
|
lib/google/src/Google/Config.php
|
Google_Config.setIoClass
|
public function setIoClass($class)
{
$prev = $this->configuration['io_class'];
if (!isset($this->configuration['classes'][$class]) &&
isset($this->configuration['classes'][$prev])) {
$this->configuration['classes'][$class] =
$this->configuration['classes'][$prev];
}
$this->configuration['io_class'] = $class;
}
|
php
|
public function setIoClass($class)
{
$prev = $this->configuration['io_class'];
if (!isset($this->configuration['classes'][$class]) &&
isset($this->configuration['classes'][$prev])) {
$this->configuration['classes'][$class] =
$this->configuration['classes'][$prev];
}
$this->configuration['io_class'] = $class;
}
|
[
"public",
"function",
"setIoClass",
"(",
"$",
"class",
")",
"{",
"$",
"prev",
"=",
"$",
"this",
"->",
"configuration",
"[",
"'io_class'",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"configuration",
"[",
"'classes'",
"]",
"[",
"$",
"class",
"]",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"configuration",
"[",
"'classes'",
"]",
"[",
"$",
"prev",
"]",
")",
")",
"{",
"$",
"this",
"->",
"configuration",
"[",
"'classes'",
"]",
"[",
"$",
"class",
"]",
"=",
"$",
"this",
"->",
"configuration",
"[",
"'classes'",
"]",
"[",
"$",
"prev",
"]",
";",
"}",
"$",
"this",
"->",
"configuration",
"[",
"'io_class'",
"]",
"=",
"$",
"class",
";",
"}"
] |
Set the IO class.
@param $class string the class name to set
|
[
"Set",
"the",
"IO",
"class",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/google/src/Google/Config.php#L239-L248
|
217,548
|
moodle/moodle
|
lib/google/src/Google/Config.php
|
Google_Config.setCacheClass
|
public function setCacheClass($class)
{
$prev = $this->configuration['cache_class'];
if (!isset($this->configuration['classes'][$class]) &&
isset($this->configuration['classes'][$prev])) {
$this->configuration['classes'][$class] =
$this->configuration['classes'][$prev];
}
$this->configuration['cache_class'] = $class;
}
|
php
|
public function setCacheClass($class)
{
$prev = $this->configuration['cache_class'];
if (!isset($this->configuration['classes'][$class]) &&
isset($this->configuration['classes'][$prev])) {
$this->configuration['classes'][$class] =
$this->configuration['classes'][$prev];
}
$this->configuration['cache_class'] = $class;
}
|
[
"public",
"function",
"setCacheClass",
"(",
"$",
"class",
")",
"{",
"$",
"prev",
"=",
"$",
"this",
"->",
"configuration",
"[",
"'cache_class'",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"configuration",
"[",
"'classes'",
"]",
"[",
"$",
"class",
"]",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"configuration",
"[",
"'classes'",
"]",
"[",
"$",
"prev",
"]",
")",
")",
"{",
"$",
"this",
"->",
"configuration",
"[",
"'classes'",
"]",
"[",
"$",
"class",
"]",
"=",
"$",
"this",
"->",
"configuration",
"[",
"'classes'",
"]",
"[",
"$",
"prev",
"]",
";",
"}",
"$",
"this",
"->",
"configuration",
"[",
"'cache_class'",
"]",
"=",
"$",
"class",
";",
"}"
] |
Set the cache class.
@param $class string the class name to set
|
[
"Set",
"the",
"cache",
"class",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/google/src/Google/Config.php#L255-L264
|
217,549
|
moodle/moodle
|
lib/google/src/Google/Config.php
|
Google_Config.setLoggerClass
|
public function setLoggerClass($class)
{
$prev = $this->configuration['logger_class'];
if (!isset($this->configuration['classes'][$class]) &&
isset($this->configuration['classes'][$prev])) {
$this->configuration['classes'][$class] =
$this->configuration['classes'][$prev];
}
$this->configuration['logger_class'] = $class;
}
|
php
|
public function setLoggerClass($class)
{
$prev = $this->configuration['logger_class'];
if (!isset($this->configuration['classes'][$class]) &&
isset($this->configuration['classes'][$prev])) {
$this->configuration['classes'][$class] =
$this->configuration['classes'][$prev];
}
$this->configuration['logger_class'] = $class;
}
|
[
"public",
"function",
"setLoggerClass",
"(",
"$",
"class",
")",
"{",
"$",
"prev",
"=",
"$",
"this",
"->",
"configuration",
"[",
"'logger_class'",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"configuration",
"[",
"'classes'",
"]",
"[",
"$",
"class",
"]",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"configuration",
"[",
"'classes'",
"]",
"[",
"$",
"prev",
"]",
")",
")",
"{",
"$",
"this",
"->",
"configuration",
"[",
"'classes'",
"]",
"[",
"$",
"class",
"]",
"=",
"$",
"this",
"->",
"configuration",
"[",
"'classes'",
"]",
"[",
"$",
"prev",
"]",
";",
"}",
"$",
"this",
"->",
"configuration",
"[",
"'logger_class'",
"]",
"=",
"$",
"class",
";",
"}"
] |
Set the logger class.
@param $class string the class name to set
|
[
"Set",
"the",
"logger",
"class",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/google/src/Google/Config.php#L271-L280
|
217,550
|
moodle/moodle
|
lib/google/src/Google/Config.php
|
Google_Config.setAuthConfig
|
private function setAuthConfig($key, $value)
{
if (!isset($this->configuration['classes'][$this->getAuthClass()])) {
$this->configuration['classes'][$this->getAuthClass()] = array();
}
$this->configuration['classes'][$this->getAuthClass()][$key] = $value;
}
|
php
|
private function setAuthConfig($key, $value)
{
if (!isset($this->configuration['classes'][$this->getAuthClass()])) {
$this->configuration['classes'][$this->getAuthClass()] = array();
}
$this->configuration['classes'][$this->getAuthClass()][$key] = $value;
}
|
[
"private",
"function",
"setAuthConfig",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"configuration",
"[",
"'classes'",
"]",
"[",
"$",
"this",
"->",
"getAuthClass",
"(",
")",
"]",
")",
")",
"{",
"$",
"this",
"->",
"configuration",
"[",
"'classes'",
"]",
"[",
"$",
"this",
"->",
"getAuthClass",
"(",
")",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"this",
"->",
"configuration",
"[",
"'classes'",
"]",
"[",
"$",
"this",
"->",
"getAuthClass",
"(",
")",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}"
] |
Set the auth configuration for the current auth class.
@param $key - the key to set
@param $value - the parameter value
|
[
"Set",
"the",
"auth",
"configuration",
"for",
"the",
"current",
"auth",
"class",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/google/src/Google/Config.php#L449-L455
|
217,551
|
moodle/moodle
|
notes/externallib.php
|
core_notes_external.get_notes
|
public static function get_notes($notes) {
global $CFG;
$params = self::validate_parameters(self::get_notes_parameters(), array('notes' => $notes));
// Check if note system is enabled.
if (!$CFG->enablenotes) {
throw new moodle_exception('notesdisabled', 'notes');
}
$resultnotes = array();
foreach ($params['notes'] as $noteid) {
$resultnote = array();
$note = note_load($noteid);
if (isset($note->id)) {
// Ensure the current user is allowed to run this function.
$context = context_course::instance($note->courseid);
self::validate_context($context);
require_capability('moodle/notes:view', $context);
list($gotnote['text'], $gotnote['format']) = external_format_text($note->content,
$note->format,
$context->id,
'notes',
'',
'');
$gotnote['noteid'] = $note->id;
$gotnote['userid'] = $note->userid;
$gotnote['publishstate'] = $note->publishstate;
$gotnote['courseid'] = $note->courseid;
$resultnotes["notes"][] = $gotnote;
} else {
$resultnotes["warnings"][] = array('item' => 'note',
'itemid' => $noteid,
'warningcode' => 'badid',
'message' => 'Note does not exist');
}
}
return $resultnotes;
}
|
php
|
public static function get_notes($notes) {
global $CFG;
$params = self::validate_parameters(self::get_notes_parameters(), array('notes' => $notes));
// Check if note system is enabled.
if (!$CFG->enablenotes) {
throw new moodle_exception('notesdisabled', 'notes');
}
$resultnotes = array();
foreach ($params['notes'] as $noteid) {
$resultnote = array();
$note = note_load($noteid);
if (isset($note->id)) {
// Ensure the current user is allowed to run this function.
$context = context_course::instance($note->courseid);
self::validate_context($context);
require_capability('moodle/notes:view', $context);
list($gotnote['text'], $gotnote['format']) = external_format_text($note->content,
$note->format,
$context->id,
'notes',
'',
'');
$gotnote['noteid'] = $note->id;
$gotnote['userid'] = $note->userid;
$gotnote['publishstate'] = $note->publishstate;
$gotnote['courseid'] = $note->courseid;
$resultnotes["notes"][] = $gotnote;
} else {
$resultnotes["warnings"][] = array('item' => 'note',
'itemid' => $noteid,
'warningcode' => 'badid',
'message' => 'Note does not exist');
}
}
return $resultnotes;
}
|
[
"public",
"static",
"function",
"get_notes",
"(",
"$",
"notes",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_notes_parameters",
"(",
")",
",",
"array",
"(",
"'notes'",
"=>",
"$",
"notes",
")",
")",
";",
"// Check if note system is enabled.",
"if",
"(",
"!",
"$",
"CFG",
"->",
"enablenotes",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'notesdisabled'",
",",
"'notes'",
")",
";",
"}",
"$",
"resultnotes",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"params",
"[",
"'notes'",
"]",
"as",
"$",
"noteid",
")",
"{",
"$",
"resultnote",
"=",
"array",
"(",
")",
";",
"$",
"note",
"=",
"note_load",
"(",
"$",
"noteid",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"note",
"->",
"id",
")",
")",
"{",
"// Ensure the current user is allowed to run this function.",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"note",
"->",
"courseid",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"require_capability",
"(",
"'moodle/notes:view'",
",",
"$",
"context",
")",
";",
"list",
"(",
"$",
"gotnote",
"[",
"'text'",
"]",
",",
"$",
"gotnote",
"[",
"'format'",
"]",
")",
"=",
"external_format_text",
"(",
"$",
"note",
"->",
"content",
",",
"$",
"note",
"->",
"format",
",",
"$",
"context",
"->",
"id",
",",
"'notes'",
",",
"''",
",",
"''",
")",
";",
"$",
"gotnote",
"[",
"'noteid'",
"]",
"=",
"$",
"note",
"->",
"id",
";",
"$",
"gotnote",
"[",
"'userid'",
"]",
"=",
"$",
"note",
"->",
"userid",
";",
"$",
"gotnote",
"[",
"'publishstate'",
"]",
"=",
"$",
"note",
"->",
"publishstate",
";",
"$",
"gotnote",
"[",
"'courseid'",
"]",
"=",
"$",
"note",
"->",
"courseid",
";",
"$",
"resultnotes",
"[",
"\"notes\"",
"]",
"[",
"]",
"=",
"$",
"gotnote",
";",
"}",
"else",
"{",
"$",
"resultnotes",
"[",
"\"warnings\"",
"]",
"[",
"]",
"=",
"array",
"(",
"'item'",
"=>",
"'note'",
",",
"'itemid'",
"=>",
"$",
"noteid",
",",
"'warningcode'",
"=>",
"'badid'",
",",
"'message'",
"=>",
"'Note does not exist'",
")",
";",
"}",
"}",
"return",
"$",
"resultnotes",
";",
"}"
] |
Get notes about users.
@param array $notes An array of ids for the notes to retrieve.
@return null
@since Moodle 2.5
|
[
"Get",
"notes",
"about",
"users",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/notes/externallib.php#L290-L327
|
217,552
|
moodle/moodle
|
notes/externallib.php
|
core_notes_external.get_notes_returns
|
public static function get_notes_returns() {
return new external_single_structure(
array(
'notes' => new external_multiple_structure(
new external_single_structure(
array(
'noteid' => new external_value(PARAM_INT, 'id of the note', VALUE_OPTIONAL),
'userid' => new external_value(PARAM_INT, 'id of the user the note is about', VALUE_OPTIONAL),
'publishstate' => new external_value(PARAM_ALPHA, '\'personal\', \'course\' or \'site\'', VALUE_OPTIONAL),
'courseid' => new external_value(PARAM_INT, 'course id of the note', VALUE_OPTIONAL),
'text' => new external_value(PARAM_RAW, 'the text of the message - text or HTML', VALUE_OPTIONAL),
'format' => new external_format_value('text', VALUE_OPTIONAL),
), 'note'
)
),
'warnings' => new external_warnings('item is always \'note\'',
'When errorcode is savedfailed the note could not be modified.' .
'When errorcode is badparam, an incorrect parameter was provided.' .
'When errorcode is badid, the note does not exist',
'errorcode can be badparam (incorrect parameter), savedfailed (could not be modified), or badid (note does not exist)')
)
);
}
|
php
|
public static function get_notes_returns() {
return new external_single_structure(
array(
'notes' => new external_multiple_structure(
new external_single_structure(
array(
'noteid' => new external_value(PARAM_INT, 'id of the note', VALUE_OPTIONAL),
'userid' => new external_value(PARAM_INT, 'id of the user the note is about', VALUE_OPTIONAL),
'publishstate' => new external_value(PARAM_ALPHA, '\'personal\', \'course\' or \'site\'', VALUE_OPTIONAL),
'courseid' => new external_value(PARAM_INT, 'course id of the note', VALUE_OPTIONAL),
'text' => new external_value(PARAM_RAW, 'the text of the message - text or HTML', VALUE_OPTIONAL),
'format' => new external_format_value('text', VALUE_OPTIONAL),
), 'note'
)
),
'warnings' => new external_warnings('item is always \'note\'',
'When errorcode is savedfailed the note could not be modified.' .
'When errorcode is badparam, an incorrect parameter was provided.' .
'When errorcode is badid, the note does not exist',
'errorcode can be badparam (incorrect parameter), savedfailed (could not be modified), or badid (note does not exist)')
)
);
}
|
[
"public",
"static",
"function",
"get_notes_returns",
"(",
")",
"{",
"return",
"new",
"external_single_structure",
"(",
"array",
"(",
"'notes'",
"=>",
"new",
"external_multiple_structure",
"(",
"new",
"external_single_structure",
"(",
"array",
"(",
"'noteid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'id of the note'",
",",
"VALUE_OPTIONAL",
")",
",",
"'userid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'id of the user the note is about'",
",",
"VALUE_OPTIONAL",
")",
",",
"'publishstate'",
"=>",
"new",
"external_value",
"(",
"PARAM_ALPHA",
",",
"'\\'personal\\', \\'course\\' or \\'site\\''",
",",
"VALUE_OPTIONAL",
")",
",",
"'courseid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'course id of the note'",
",",
"VALUE_OPTIONAL",
")",
",",
"'text'",
"=>",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'the text of the message - text or HTML'",
",",
"VALUE_OPTIONAL",
")",
",",
"'format'",
"=>",
"new",
"external_format_value",
"(",
"'text'",
",",
"VALUE_OPTIONAL",
")",
",",
")",
",",
"'note'",
")",
")",
",",
"'warnings'",
"=>",
"new",
"external_warnings",
"(",
"'item is always \\'note\\''",
",",
"'When errorcode is savedfailed the note could not be modified.'",
".",
"'When errorcode is badparam, an incorrect parameter was provided.'",
".",
"'When errorcode is badid, the note does not exist'",
",",
"'errorcode can be badparam (incorrect parameter), savedfailed (could not be modified), or badid (note does not exist)'",
")",
")",
")",
";",
"}"
] |
Returns description of get_notes result value.
@return external_description
@since Moodle 2.5
|
[
"Returns",
"description",
"of",
"get_notes",
"result",
"value",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/notes/externallib.php#L335-L357
|
217,553
|
moodle/moodle
|
notes/externallib.php
|
core_notes_external.update_notes_parameters
|
public static function update_notes_parameters() {
return new external_function_parameters(
array(
'notes' => new external_multiple_structure(
new external_single_structure(
array(
'id' => new external_value(PARAM_INT, 'id of the note'),
'publishstate' => new external_value(PARAM_ALPHA, '\'personal\', \'course\' or \'site\''),
'text' => new external_value(PARAM_RAW, 'the text of the message - text or HTML'),
'format' => new external_format_value('text', VALUE_DEFAULT),
)
), "Array of Notes", VALUE_DEFAULT, array()
)
)
);
}
|
php
|
public static function update_notes_parameters() {
return new external_function_parameters(
array(
'notes' => new external_multiple_structure(
new external_single_structure(
array(
'id' => new external_value(PARAM_INT, 'id of the note'),
'publishstate' => new external_value(PARAM_ALPHA, '\'personal\', \'course\' or \'site\''),
'text' => new external_value(PARAM_RAW, 'the text of the message - text or HTML'),
'format' => new external_format_value('text', VALUE_DEFAULT),
)
), "Array of Notes", VALUE_DEFAULT, array()
)
)
);
}
|
[
"public",
"static",
"function",
"update_notes_parameters",
"(",
")",
"{",
"return",
"new",
"external_function_parameters",
"(",
"array",
"(",
"'notes'",
"=>",
"new",
"external_multiple_structure",
"(",
"new",
"external_single_structure",
"(",
"array",
"(",
"'id'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'id of the note'",
")",
",",
"'publishstate'",
"=>",
"new",
"external_value",
"(",
"PARAM_ALPHA",
",",
"'\\'personal\\', \\'course\\' or \\'site\\''",
")",
",",
"'text'",
"=>",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'the text of the message - text or HTML'",
")",
",",
"'format'",
"=>",
"new",
"external_format_value",
"(",
"'text'",
",",
"VALUE_DEFAULT",
")",
",",
")",
")",
",",
"\"Array of Notes\"",
",",
"VALUE_DEFAULT",
",",
"array",
"(",
")",
")",
")",
")",
";",
"}"
] |
Returns description of update_notes parameters.
@return external_function_parameters
@since Moodle 2.5
|
[
"Returns",
"description",
"of",
"update_notes",
"parameters",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/notes/externallib.php#L365-L380
|
217,554
|
moodle/moodle
|
notes/externallib.php
|
core_notes_external.update_notes
|
public static function update_notes($notes = array()) {
global $CFG, $DB;
$params = self::validate_parameters(self::update_notes_parameters(), array('notes' => $notes));
// Check if note system is enabled.
if (!$CFG->enablenotes) {
throw new moodle_exception('notesdisabled', 'notes');
}
$warnings = array();
foreach ($params['notes'] as $note) {
$notedetails = note_load($note['id']);
if (isset($notedetails->id)) {
// Ensure the current user is allowed to run this function.
$context = context_course::instance($notedetails->courseid);
self::validate_context($context);
require_capability('moodle/notes:manage', $context);
$dbnote = new stdClass;
$dbnote->id = $note['id'];
$dbnote->content = $note['text'];
$dbnote->format = external_validate_format($note['format']);
// Get the state ('personal', 'course', 'site').
switch ($note['publishstate']) {
case 'personal':
$dbnote->publishstate = NOTES_STATE_DRAFT;
break;
case 'course':
$dbnote->publishstate = NOTES_STATE_PUBLIC;
break;
case 'site':
$dbnote->publishstate = NOTES_STATE_SITE;
$dbnote->courseid = SITEID;
break;
default:
$warnings[] = array('item' => 'note',
'itemid' => $note["id"],
'warningcode' => 'badparam',
'message' => 'Provided publishstate incorrect');
break;
}
if (!note_save($dbnote)) {
$warnings[] = array('item' => 'note',
'itemid' => $note["id"],
'warningcode' => 'savedfailed',
'message' => 'Note could not be modified');
}
} else {
$warnings[] = array('item' => 'note',
'itemid' => $note["id"],
'warningcode' => 'badid',
'message' => 'Note does not exist');
}
}
return $warnings;
}
|
php
|
public static function update_notes($notes = array()) {
global $CFG, $DB;
$params = self::validate_parameters(self::update_notes_parameters(), array('notes' => $notes));
// Check if note system is enabled.
if (!$CFG->enablenotes) {
throw new moodle_exception('notesdisabled', 'notes');
}
$warnings = array();
foreach ($params['notes'] as $note) {
$notedetails = note_load($note['id']);
if (isset($notedetails->id)) {
// Ensure the current user is allowed to run this function.
$context = context_course::instance($notedetails->courseid);
self::validate_context($context);
require_capability('moodle/notes:manage', $context);
$dbnote = new stdClass;
$dbnote->id = $note['id'];
$dbnote->content = $note['text'];
$dbnote->format = external_validate_format($note['format']);
// Get the state ('personal', 'course', 'site').
switch ($note['publishstate']) {
case 'personal':
$dbnote->publishstate = NOTES_STATE_DRAFT;
break;
case 'course':
$dbnote->publishstate = NOTES_STATE_PUBLIC;
break;
case 'site':
$dbnote->publishstate = NOTES_STATE_SITE;
$dbnote->courseid = SITEID;
break;
default:
$warnings[] = array('item' => 'note',
'itemid' => $note["id"],
'warningcode' => 'badparam',
'message' => 'Provided publishstate incorrect');
break;
}
if (!note_save($dbnote)) {
$warnings[] = array('item' => 'note',
'itemid' => $note["id"],
'warningcode' => 'savedfailed',
'message' => 'Note could not be modified');
}
} else {
$warnings[] = array('item' => 'note',
'itemid' => $note["id"],
'warningcode' => 'badid',
'message' => 'Note does not exist');
}
}
return $warnings;
}
|
[
"public",
"static",
"function",
"update_notes",
"(",
"$",
"notes",
"=",
"array",
"(",
")",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"update_notes_parameters",
"(",
")",
",",
"array",
"(",
"'notes'",
"=>",
"$",
"notes",
")",
")",
";",
"// Check if note system is enabled.",
"if",
"(",
"!",
"$",
"CFG",
"->",
"enablenotes",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'notesdisabled'",
",",
"'notes'",
")",
";",
"}",
"$",
"warnings",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"params",
"[",
"'notes'",
"]",
"as",
"$",
"note",
")",
"{",
"$",
"notedetails",
"=",
"note_load",
"(",
"$",
"note",
"[",
"'id'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"notedetails",
"->",
"id",
")",
")",
"{",
"// Ensure the current user is allowed to run this function.",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"notedetails",
"->",
"courseid",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"require_capability",
"(",
"'moodle/notes:manage'",
",",
"$",
"context",
")",
";",
"$",
"dbnote",
"=",
"new",
"stdClass",
";",
"$",
"dbnote",
"->",
"id",
"=",
"$",
"note",
"[",
"'id'",
"]",
";",
"$",
"dbnote",
"->",
"content",
"=",
"$",
"note",
"[",
"'text'",
"]",
";",
"$",
"dbnote",
"->",
"format",
"=",
"external_validate_format",
"(",
"$",
"note",
"[",
"'format'",
"]",
")",
";",
"// Get the state ('personal', 'course', 'site').",
"switch",
"(",
"$",
"note",
"[",
"'publishstate'",
"]",
")",
"{",
"case",
"'personal'",
":",
"$",
"dbnote",
"->",
"publishstate",
"=",
"NOTES_STATE_DRAFT",
";",
"break",
";",
"case",
"'course'",
":",
"$",
"dbnote",
"->",
"publishstate",
"=",
"NOTES_STATE_PUBLIC",
";",
"break",
";",
"case",
"'site'",
":",
"$",
"dbnote",
"->",
"publishstate",
"=",
"NOTES_STATE_SITE",
";",
"$",
"dbnote",
"->",
"courseid",
"=",
"SITEID",
";",
"break",
";",
"default",
":",
"$",
"warnings",
"[",
"]",
"=",
"array",
"(",
"'item'",
"=>",
"'note'",
",",
"'itemid'",
"=>",
"$",
"note",
"[",
"\"id\"",
"]",
",",
"'warningcode'",
"=>",
"'badparam'",
",",
"'message'",
"=>",
"'Provided publishstate incorrect'",
")",
";",
"break",
";",
"}",
"if",
"(",
"!",
"note_save",
"(",
"$",
"dbnote",
")",
")",
"{",
"$",
"warnings",
"[",
"]",
"=",
"array",
"(",
"'item'",
"=>",
"'note'",
",",
"'itemid'",
"=>",
"$",
"note",
"[",
"\"id\"",
"]",
",",
"'warningcode'",
"=>",
"'savedfailed'",
",",
"'message'",
"=>",
"'Note could not be modified'",
")",
";",
"}",
"}",
"else",
"{",
"$",
"warnings",
"[",
"]",
"=",
"array",
"(",
"'item'",
"=>",
"'note'",
",",
"'itemid'",
"=>",
"$",
"note",
"[",
"\"id\"",
"]",
",",
"'warningcode'",
"=>",
"'badid'",
",",
"'message'",
"=>",
"'Note does not exist'",
")",
";",
"}",
"}",
"return",
"$",
"warnings",
";",
"}"
] |
Update notes about users.
@param array $notes An array of ids for the notes to update.
@return array fail infos.
@since Moodle 2.2
|
[
"Update",
"notes",
"about",
"users",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/notes/externallib.php#L389-L445
|
217,555
|
moodle/moodle
|
notes/externallib.php
|
core_notes_external.create_note_list
|
protected static function create_note_list($courseid, $context, $userid, $state, $author = 0) {
$results = array();
$notes = note_list($courseid, $userid, $state, $author);
foreach ($notes as $key => $note) {
$note = (array)$note;
list($note['content'], $note['format']) = external_format_text($note['content'],
$note['format'],
$context->id,
'',
'',
0);
$results[$key] = $note;
}
return $results;
}
|
php
|
protected static function create_note_list($courseid, $context, $userid, $state, $author = 0) {
$results = array();
$notes = note_list($courseid, $userid, $state, $author);
foreach ($notes as $key => $note) {
$note = (array)$note;
list($note['content'], $note['format']) = external_format_text($note['content'],
$note['format'],
$context->id,
'',
'',
0);
$results[$key] = $note;
}
return $results;
}
|
[
"protected",
"static",
"function",
"create_note_list",
"(",
"$",
"courseid",
",",
"$",
"context",
",",
"$",
"userid",
",",
"$",
"state",
",",
"$",
"author",
"=",
"0",
")",
"{",
"$",
"results",
"=",
"array",
"(",
")",
";",
"$",
"notes",
"=",
"note_list",
"(",
"$",
"courseid",
",",
"$",
"userid",
",",
"$",
"state",
",",
"$",
"author",
")",
";",
"foreach",
"(",
"$",
"notes",
"as",
"$",
"key",
"=>",
"$",
"note",
")",
"{",
"$",
"note",
"=",
"(",
"array",
")",
"$",
"note",
";",
"list",
"(",
"$",
"note",
"[",
"'content'",
"]",
",",
"$",
"note",
"[",
"'format'",
"]",
")",
"=",
"external_format_text",
"(",
"$",
"note",
"[",
"'content'",
"]",
",",
"$",
"note",
"[",
"'format'",
"]",
",",
"$",
"context",
"->",
"id",
",",
"''",
",",
"''",
",",
"0",
")",
";",
"$",
"results",
"[",
"$",
"key",
"]",
"=",
"$",
"note",
";",
"}",
"return",
"$",
"results",
";",
"}"
] |
Create a notes list
@param int $courseid ID of the Course
@param stdClass $context context object
@param int $userid ID of the User
@param int $state
@param int $author
@return array of notes
@since Moodle 2.9
|
[
"Create",
"a",
"notes",
"list"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/notes/externallib.php#L487-L501
|
217,556
|
moodle/moodle
|
notes/externallib.php
|
core_notes_external.get_course_notes
|
public static function get_course_notes($courseid, $userid = 0) {
global $CFG, $USER;
if (empty($CFG->enablenotes)) {
throw new moodle_exception('notesdisabled', 'notes');
}
$warnings = array();
$arrayparams = array(
'courseid' => $courseid,
'userid' => $userid,
);
$params = self::validate_parameters(self::get_course_notes_parameters(), $arrayparams);
if (empty($params['courseid'])) {
$params['courseid'] = SITEID;
}
$user = null;
if (!empty($params['userid'])) {
$user = core_user::get_user($params['userid'], '*', MUST_EXIST);
core_user::require_active_user($user);
}
$course = get_course($params['courseid']);
$systemcontext = context_system::instance();
$canmanagesystemnotes = has_capability('moodle/notes:manage', $systemcontext);
if ($course->id == SITEID) {
$context = $systemcontext;
$canmanagecoursenotes = $canmanagesystemnotes;
} else {
$context = context_course::instance($course->id);
$canmanagecoursenotes = has_capability('moodle/notes:manage', $context);
}
self::validate_context($context);
$sitenotes = array();
$coursenotes = array();
$personalnotes = array();
if ($course->id != SITEID) {
require_capability('moodle/notes:view', $context);
$sitenotes = self::create_note_list(0, $systemcontext, $params['userid'], NOTES_STATE_SITE);
$coursenotes = self::create_note_list($course->id, $context, $params['userid'], NOTES_STATE_PUBLIC);
$personalnotes = self::create_note_list($course->id, $context, $params['userid'], NOTES_STATE_DRAFT,
$USER->id);
} else {
if (has_capability('moodle/notes:view', $context)) {
$sitenotes = self::create_note_list(0, $context, $params['userid'], NOTES_STATE_SITE);
}
// It returns notes only for a specific user!
if (!empty($user)) {
$usercourses = enrol_get_users_courses($user->id, true);
foreach ($usercourses as $c) {
// All notes at course level, only if we have capability on every course.
if (has_capability('moodle/notes:view', context_course::instance($c->id))) {
$coursenotes += self::create_note_list($c->id, $context, $params['userid'], NOTES_STATE_PUBLIC);
}
}
}
}
$results = array(
'sitenotes' => $sitenotes,
'coursenotes' => $coursenotes,
'personalnotes' => $personalnotes,
'canmanagesystemnotes' => $canmanagesystemnotes,
'canmanagecoursenotes' => $canmanagecoursenotes,
'warnings' => $warnings
);
return $results;
}
|
php
|
public static function get_course_notes($courseid, $userid = 0) {
global $CFG, $USER;
if (empty($CFG->enablenotes)) {
throw new moodle_exception('notesdisabled', 'notes');
}
$warnings = array();
$arrayparams = array(
'courseid' => $courseid,
'userid' => $userid,
);
$params = self::validate_parameters(self::get_course_notes_parameters(), $arrayparams);
if (empty($params['courseid'])) {
$params['courseid'] = SITEID;
}
$user = null;
if (!empty($params['userid'])) {
$user = core_user::get_user($params['userid'], '*', MUST_EXIST);
core_user::require_active_user($user);
}
$course = get_course($params['courseid']);
$systemcontext = context_system::instance();
$canmanagesystemnotes = has_capability('moodle/notes:manage', $systemcontext);
if ($course->id == SITEID) {
$context = $systemcontext;
$canmanagecoursenotes = $canmanagesystemnotes;
} else {
$context = context_course::instance($course->id);
$canmanagecoursenotes = has_capability('moodle/notes:manage', $context);
}
self::validate_context($context);
$sitenotes = array();
$coursenotes = array();
$personalnotes = array();
if ($course->id != SITEID) {
require_capability('moodle/notes:view', $context);
$sitenotes = self::create_note_list(0, $systemcontext, $params['userid'], NOTES_STATE_SITE);
$coursenotes = self::create_note_list($course->id, $context, $params['userid'], NOTES_STATE_PUBLIC);
$personalnotes = self::create_note_list($course->id, $context, $params['userid'], NOTES_STATE_DRAFT,
$USER->id);
} else {
if (has_capability('moodle/notes:view', $context)) {
$sitenotes = self::create_note_list(0, $context, $params['userid'], NOTES_STATE_SITE);
}
// It returns notes only for a specific user!
if (!empty($user)) {
$usercourses = enrol_get_users_courses($user->id, true);
foreach ($usercourses as $c) {
// All notes at course level, only if we have capability on every course.
if (has_capability('moodle/notes:view', context_course::instance($c->id))) {
$coursenotes += self::create_note_list($c->id, $context, $params['userid'], NOTES_STATE_PUBLIC);
}
}
}
}
$results = array(
'sitenotes' => $sitenotes,
'coursenotes' => $coursenotes,
'personalnotes' => $personalnotes,
'canmanagesystemnotes' => $canmanagesystemnotes,
'canmanagecoursenotes' => $canmanagecoursenotes,
'warnings' => $warnings
);
return $results;
}
|
[
"public",
"static",
"function",
"get_course_notes",
"(",
"$",
"courseid",
",",
"$",
"userid",
"=",
"0",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"USER",
";",
"if",
"(",
"empty",
"(",
"$",
"CFG",
"->",
"enablenotes",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'notesdisabled'",
",",
"'notes'",
")",
";",
"}",
"$",
"warnings",
"=",
"array",
"(",
")",
";",
"$",
"arrayparams",
"=",
"array",
"(",
"'courseid'",
"=>",
"$",
"courseid",
",",
"'userid'",
"=>",
"$",
"userid",
",",
")",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_course_notes_parameters",
"(",
")",
",",
"$",
"arrayparams",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"params",
"[",
"'courseid'",
"]",
")",
")",
"{",
"$",
"params",
"[",
"'courseid'",
"]",
"=",
"SITEID",
";",
"}",
"$",
"user",
"=",
"null",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"params",
"[",
"'userid'",
"]",
")",
")",
"{",
"$",
"user",
"=",
"core_user",
"::",
"get_user",
"(",
"$",
"params",
"[",
"'userid'",
"]",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"core_user",
"::",
"require_active_user",
"(",
"$",
"user",
")",
";",
"}",
"$",
"course",
"=",
"get_course",
"(",
"$",
"params",
"[",
"'courseid'",
"]",
")",
";",
"$",
"systemcontext",
"=",
"context_system",
"::",
"instance",
"(",
")",
";",
"$",
"canmanagesystemnotes",
"=",
"has_capability",
"(",
"'moodle/notes:manage'",
",",
"$",
"systemcontext",
")",
";",
"if",
"(",
"$",
"course",
"->",
"id",
"==",
"SITEID",
")",
"{",
"$",
"context",
"=",
"$",
"systemcontext",
";",
"$",
"canmanagecoursenotes",
"=",
"$",
"canmanagesystemnotes",
";",
"}",
"else",
"{",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"course",
"->",
"id",
")",
";",
"$",
"canmanagecoursenotes",
"=",
"has_capability",
"(",
"'moodle/notes:manage'",
",",
"$",
"context",
")",
";",
"}",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"$",
"sitenotes",
"=",
"array",
"(",
")",
";",
"$",
"coursenotes",
"=",
"array",
"(",
")",
";",
"$",
"personalnotes",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"course",
"->",
"id",
"!=",
"SITEID",
")",
"{",
"require_capability",
"(",
"'moodle/notes:view'",
",",
"$",
"context",
")",
";",
"$",
"sitenotes",
"=",
"self",
"::",
"create_note_list",
"(",
"0",
",",
"$",
"systemcontext",
",",
"$",
"params",
"[",
"'userid'",
"]",
",",
"NOTES_STATE_SITE",
")",
";",
"$",
"coursenotes",
"=",
"self",
"::",
"create_note_list",
"(",
"$",
"course",
"->",
"id",
",",
"$",
"context",
",",
"$",
"params",
"[",
"'userid'",
"]",
",",
"NOTES_STATE_PUBLIC",
")",
";",
"$",
"personalnotes",
"=",
"self",
"::",
"create_note_list",
"(",
"$",
"course",
"->",
"id",
",",
"$",
"context",
",",
"$",
"params",
"[",
"'userid'",
"]",
",",
"NOTES_STATE_DRAFT",
",",
"$",
"USER",
"->",
"id",
")",
";",
"}",
"else",
"{",
"if",
"(",
"has_capability",
"(",
"'moodle/notes:view'",
",",
"$",
"context",
")",
")",
"{",
"$",
"sitenotes",
"=",
"self",
"::",
"create_note_list",
"(",
"0",
",",
"$",
"context",
",",
"$",
"params",
"[",
"'userid'",
"]",
",",
"NOTES_STATE_SITE",
")",
";",
"}",
"// It returns notes only for a specific user!",
"if",
"(",
"!",
"empty",
"(",
"$",
"user",
")",
")",
"{",
"$",
"usercourses",
"=",
"enrol_get_users_courses",
"(",
"$",
"user",
"->",
"id",
",",
"true",
")",
";",
"foreach",
"(",
"$",
"usercourses",
"as",
"$",
"c",
")",
"{",
"// All notes at course level, only if we have capability on every course.",
"if",
"(",
"has_capability",
"(",
"'moodle/notes:view'",
",",
"context_course",
"::",
"instance",
"(",
"$",
"c",
"->",
"id",
")",
")",
")",
"{",
"$",
"coursenotes",
"+=",
"self",
"::",
"create_note_list",
"(",
"$",
"c",
"->",
"id",
",",
"$",
"context",
",",
"$",
"params",
"[",
"'userid'",
"]",
",",
"NOTES_STATE_PUBLIC",
")",
";",
"}",
"}",
"}",
"}",
"$",
"results",
"=",
"array",
"(",
"'sitenotes'",
"=>",
"$",
"sitenotes",
",",
"'coursenotes'",
"=>",
"$",
"coursenotes",
",",
"'personalnotes'",
"=>",
"$",
"personalnotes",
",",
"'canmanagesystemnotes'",
"=>",
"$",
"canmanagesystemnotes",
",",
"'canmanagecoursenotes'",
"=>",
"$",
"canmanagecoursenotes",
",",
"'warnings'",
"=>",
"$",
"warnings",
")",
";",
"return",
"$",
"results",
";",
"}"
] |
Get a list of course notes
@param int $courseid ID of the Course
@param int $userid ID of the User
@return array of site, course and personal notes and warnings
@since Moodle 2.9
@throws moodle_exception
|
[
"Get",
"a",
"list",
"of",
"course",
"notes"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/notes/externallib.php#L512-L586
|
217,557
|
moodle/moodle
|
notes/externallib.php
|
core_notes_external.get_note_structure
|
protected static function get_note_structure() {
return array(
'id' => new external_value(PARAM_INT, 'id of this note'),
'courseid' => new external_value(PARAM_INT, 'id of the course'),
'userid' => new external_value(PARAM_INT, 'user id'),
'content' => new external_value(PARAM_RAW, 'the content text formated'),
'format' => new external_format_value('content'),
'created' => new external_value(PARAM_INT, 'time created (timestamp)'),
'lastmodified' => new external_value(PARAM_INT, 'time of last modification (timestamp)'),
'usermodified' => new external_value(PARAM_INT, 'user id of the creator of this note'),
'publishstate' => new external_value(PARAM_ALPHA, "state of the note (i.e. draft, public, site) ")
);
}
|
php
|
protected static function get_note_structure() {
return array(
'id' => new external_value(PARAM_INT, 'id of this note'),
'courseid' => new external_value(PARAM_INT, 'id of the course'),
'userid' => new external_value(PARAM_INT, 'user id'),
'content' => new external_value(PARAM_RAW, 'the content text formated'),
'format' => new external_format_value('content'),
'created' => new external_value(PARAM_INT, 'time created (timestamp)'),
'lastmodified' => new external_value(PARAM_INT, 'time of last modification (timestamp)'),
'usermodified' => new external_value(PARAM_INT, 'user id of the creator of this note'),
'publishstate' => new external_value(PARAM_ALPHA, "state of the note (i.e. draft, public, site) ")
);
}
|
[
"protected",
"static",
"function",
"get_note_structure",
"(",
")",
"{",
"return",
"array",
"(",
"'id'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'id of this note'",
")",
",",
"'courseid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'id of the course'",
")",
",",
"'userid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'user id'",
")",
",",
"'content'",
"=>",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'the content text formated'",
")",
",",
"'format'",
"=>",
"new",
"external_format_value",
"(",
"'content'",
")",
",",
"'created'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'time created (timestamp)'",
")",
",",
"'lastmodified'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'time of last modification (timestamp)'",
")",
",",
"'usermodified'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'user id of the creator of this note'",
")",
",",
"'publishstate'",
"=>",
"new",
"external_value",
"(",
"PARAM_ALPHA",
",",
"\"state of the note (i.e. draft, public, site) \"",
")",
")",
";",
"}"
] |
Returns array of note structure
@return external_description
@since Moodle 2.9
|
[
"Returns",
"array",
"of",
"note",
"structure"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/notes/externallib.php#L594-L606
|
217,558
|
moodle/moodle
|
lib/classes/plugininfo/base.php
|
base.make_plugin_instance
|
protected static function make_plugin_instance($type, $typerootdir, $name, $namerootdir, $typeclass, $pluginman) {
$plugin = new $typeclass();
$plugin->type = $type;
$plugin->typerootdir = $typerootdir;
$plugin->name = $name;
$plugin->rootdir = $namerootdir;
$plugin->pluginman = $pluginman;
$plugin->init_display_name();
$plugin->load_disk_version();
$plugin->load_db_version();
$plugin->init_is_standard();
return $plugin;
}
|
php
|
protected static function make_plugin_instance($type, $typerootdir, $name, $namerootdir, $typeclass, $pluginman) {
$plugin = new $typeclass();
$plugin->type = $type;
$plugin->typerootdir = $typerootdir;
$plugin->name = $name;
$plugin->rootdir = $namerootdir;
$plugin->pluginman = $pluginman;
$plugin->init_display_name();
$plugin->load_disk_version();
$plugin->load_db_version();
$plugin->init_is_standard();
return $plugin;
}
|
[
"protected",
"static",
"function",
"make_plugin_instance",
"(",
"$",
"type",
",",
"$",
"typerootdir",
",",
"$",
"name",
",",
"$",
"namerootdir",
",",
"$",
"typeclass",
",",
"$",
"pluginman",
")",
"{",
"$",
"plugin",
"=",
"new",
"$",
"typeclass",
"(",
")",
";",
"$",
"plugin",
"->",
"type",
"=",
"$",
"type",
";",
"$",
"plugin",
"->",
"typerootdir",
"=",
"$",
"typerootdir",
";",
"$",
"plugin",
"->",
"name",
"=",
"$",
"name",
";",
"$",
"plugin",
"->",
"rootdir",
"=",
"$",
"namerootdir",
";",
"$",
"plugin",
"->",
"pluginman",
"=",
"$",
"pluginman",
";",
"$",
"plugin",
"->",
"init_display_name",
"(",
")",
";",
"$",
"plugin",
"->",
"load_disk_version",
"(",
")",
";",
"$",
"plugin",
"->",
"load_db_version",
"(",
")",
";",
"$",
"plugin",
"->",
"init_is_standard",
"(",
")",
";",
"return",
"$",
"plugin",
";",
"}"
] |
Makes a new instance of the plugininfo class
@param string $type the plugin type, eg. 'mod'
@param string $typerootdir full path to the location of all the plugins of this type
@param string $name the plugin name, eg. 'workshop'
@param string $namerootdir full path to the location of the plugin
@param string $typeclass the name of class that holds the info about the plugin
@param core_plugin_manager $pluginman the plugin manager of the new instance
@return base the instance of $typeclass
|
[
"Makes",
"a",
"new",
"instance",
"of",
"the",
"plugininfo",
"class"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/plugininfo/base.php#L134-L148
|
217,559
|
moodle/moodle
|
lib/classes/plugininfo/base.php
|
base.is_installed_and_upgraded
|
public function is_installed_and_upgraded() {
if (!$this->rootdir) {
return false;
}
if ($this->versiondb === null and $this->versiondisk === null) {
// There is no version.php or version info inside it.
return false;
}
return ((float)$this->versiondb === (float)$this->versiondisk);
}
|
php
|
public function is_installed_and_upgraded() {
if (!$this->rootdir) {
return false;
}
if ($this->versiondb === null and $this->versiondisk === null) {
// There is no version.php or version info inside it.
return false;
}
return ((float)$this->versiondb === (float)$this->versiondisk);
}
|
[
"public",
"function",
"is_installed_and_upgraded",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"rootdir",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"versiondb",
"===",
"null",
"and",
"$",
"this",
"->",
"versiondisk",
"===",
"null",
")",
"{",
"// There is no version.php or version info inside it.",
"return",
"false",
";",
"}",
"return",
"(",
"(",
"float",
")",
"$",
"this",
"->",
"versiondb",
"===",
"(",
"float",
")",
"$",
"this",
"->",
"versiondisk",
")",
";",
"}"
] |
Is this plugin already installed and updated?
@return bool true if plugin installed and upgraded.
|
[
"Is",
"this",
"plugin",
"already",
"installed",
"and",
"updated?"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/plugininfo/base.php#L154-L164
|
217,560
|
moodle/moodle
|
lib/classes/plugininfo/base.php
|
base.is_core_dependency_satisfied
|
public function is_core_dependency_satisfied($moodleversion) {
if (empty($this->versionrequires)) {
return true;
} else {
return (double)$this->versionrequires <= (double)$moodleversion;
}
}
|
php
|
public function is_core_dependency_satisfied($moodleversion) {
if (empty($this->versionrequires)) {
return true;
} else {
return (double)$this->versionrequires <= (double)$moodleversion;
}
}
|
[
"public",
"function",
"is_core_dependency_satisfied",
"(",
"$",
"moodleversion",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"versionrequires",
")",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"(",
"double",
")",
"$",
"this",
"->",
"versionrequires",
"<=",
"(",
"double",
")",
"$",
"moodleversion",
";",
"}",
"}"
] |
Returns true if the the given Moodle version is enough to run this plugin
@param string|int|double $moodleversion
@return bool
|
[
"Returns",
"true",
"if",
"the",
"the",
"given",
"Moodle",
"version",
"is",
"enough",
"to",
"run",
"this",
"plugin"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/plugininfo/base.php#L334-L342
|
217,561
|
moodle/moodle
|
lib/classes/plugininfo/base.php
|
base.get_status
|
public function get_status() {
$pluginman = $this->pluginman;
if (is_null($this->versiondb) and is_null($this->versiondisk)) {
return core_plugin_manager::PLUGIN_STATUS_NODB;
} else if (is_null($this->versiondb) and !is_null($this->versiondisk)) {
return core_plugin_manager::PLUGIN_STATUS_NEW;
} else if (!is_null($this->versiondb) and is_null($this->versiondisk)) {
if ($pluginman::is_deleted_standard_plugin($this->type, $this->name)) {
return core_plugin_manager::PLUGIN_STATUS_DELETE;
} else {
return core_plugin_manager::PLUGIN_STATUS_MISSING;
}
} else if ((float)$this->versiondb === (float)$this->versiondisk) {
// Note: the float comparison should work fine here
// because there are no arithmetic operations with the numbers.
return core_plugin_manager::PLUGIN_STATUS_UPTODATE;
} else if ($this->versiondb < $this->versiondisk) {
return core_plugin_manager::PLUGIN_STATUS_UPGRADE;
} else if ($this->versiondb > $this->versiondisk) {
return core_plugin_manager::PLUGIN_STATUS_DOWNGRADE;
} else {
// $version = pi(); and similar funny jokes - hopefully Donald E. Knuth will never contribute to Moodle ;-)
throw new coding_exception('Unable to determine plugin state, check the plugin versions');
}
}
|
php
|
public function get_status() {
$pluginman = $this->pluginman;
if (is_null($this->versiondb) and is_null($this->versiondisk)) {
return core_plugin_manager::PLUGIN_STATUS_NODB;
} else if (is_null($this->versiondb) and !is_null($this->versiondisk)) {
return core_plugin_manager::PLUGIN_STATUS_NEW;
} else if (!is_null($this->versiondb) and is_null($this->versiondisk)) {
if ($pluginman::is_deleted_standard_plugin($this->type, $this->name)) {
return core_plugin_manager::PLUGIN_STATUS_DELETE;
} else {
return core_plugin_manager::PLUGIN_STATUS_MISSING;
}
} else if ((float)$this->versiondb === (float)$this->versiondisk) {
// Note: the float comparison should work fine here
// because there are no arithmetic operations with the numbers.
return core_plugin_manager::PLUGIN_STATUS_UPTODATE;
} else if ($this->versiondb < $this->versiondisk) {
return core_plugin_manager::PLUGIN_STATUS_UPGRADE;
} else if ($this->versiondb > $this->versiondisk) {
return core_plugin_manager::PLUGIN_STATUS_DOWNGRADE;
} else {
// $version = pi(); and similar funny jokes - hopefully Donald E. Knuth will never contribute to Moodle ;-)
throw new coding_exception('Unable to determine plugin state, check the plugin versions');
}
}
|
[
"public",
"function",
"get_status",
"(",
")",
"{",
"$",
"pluginman",
"=",
"$",
"this",
"->",
"pluginman",
";",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"versiondb",
")",
"and",
"is_null",
"(",
"$",
"this",
"->",
"versiondisk",
")",
")",
"{",
"return",
"core_plugin_manager",
"::",
"PLUGIN_STATUS_NODB",
";",
"}",
"else",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"versiondb",
")",
"and",
"!",
"is_null",
"(",
"$",
"this",
"->",
"versiondisk",
")",
")",
"{",
"return",
"core_plugin_manager",
"::",
"PLUGIN_STATUS_NEW",
";",
"}",
"else",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"versiondb",
")",
"and",
"is_null",
"(",
"$",
"this",
"->",
"versiondisk",
")",
")",
"{",
"if",
"(",
"$",
"pluginman",
"::",
"is_deleted_standard_plugin",
"(",
"$",
"this",
"->",
"type",
",",
"$",
"this",
"->",
"name",
")",
")",
"{",
"return",
"core_plugin_manager",
"::",
"PLUGIN_STATUS_DELETE",
";",
"}",
"else",
"{",
"return",
"core_plugin_manager",
"::",
"PLUGIN_STATUS_MISSING",
";",
"}",
"}",
"else",
"if",
"(",
"(",
"float",
")",
"$",
"this",
"->",
"versiondb",
"===",
"(",
"float",
")",
"$",
"this",
"->",
"versiondisk",
")",
"{",
"// Note: the float comparison should work fine here",
"// because there are no arithmetic operations with the numbers.",
"return",
"core_plugin_manager",
"::",
"PLUGIN_STATUS_UPTODATE",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"versiondb",
"<",
"$",
"this",
"->",
"versiondisk",
")",
"{",
"return",
"core_plugin_manager",
"::",
"PLUGIN_STATUS_UPGRADE",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"versiondb",
">",
"$",
"this",
"->",
"versiondisk",
")",
"{",
"return",
"core_plugin_manager",
"::",
"PLUGIN_STATUS_DOWNGRADE",
";",
"}",
"else",
"{",
"// $version = pi(); and similar funny jokes - hopefully Donald E. Knuth will never contribute to Moodle ;-)",
"throw",
"new",
"coding_exception",
"(",
"'Unable to determine plugin state, check the plugin versions'",
")",
";",
"}",
"}"
] |
Returns the status of the plugin
@return string one of core_plugin_manager::PLUGIN_STATUS_xxx constants
|
[
"Returns",
"the",
"status",
"of",
"the",
"plugin"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/plugininfo/base.php#L349-L381
|
217,562
|
moodle/moodle
|
lib/classes/plugininfo/base.php
|
base.is_enabled
|
public function is_enabled() {
if (!$this->rootdir) {
// Plugin missing.
return false;
}
$enabled = $this->pluginman->get_enabled_plugins($this->type);
if (!is_array($enabled)) {
return null;
}
return isset($enabled[$this->name]);
}
|
php
|
public function is_enabled() {
if (!$this->rootdir) {
// Plugin missing.
return false;
}
$enabled = $this->pluginman->get_enabled_plugins($this->type);
if (!is_array($enabled)) {
return null;
}
return isset($enabled[$this->name]);
}
|
[
"public",
"function",
"is_enabled",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"rootdir",
")",
"{",
"// Plugin missing.",
"return",
"false",
";",
"}",
"$",
"enabled",
"=",
"$",
"this",
"->",
"pluginman",
"->",
"get_enabled_plugins",
"(",
"$",
"this",
"->",
"type",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"enabled",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"isset",
"(",
"$",
"enabled",
"[",
"$",
"this",
"->",
"name",
"]",
")",
";",
"}"
] |
Returns the information about plugin availability
True means that the plugin is enabled. False means that the plugin is
disabled. Null means that the information is not available, or the
plugin does not support configurable availability or the availability
can not be changed.
@return null|bool
|
[
"Returns",
"the",
"information",
"about",
"plugin",
"availability"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/plugininfo/base.php#L393-L406
|
217,563
|
moodle/moodle
|
lib/classes/plugininfo/base.php
|
base.available_updates
|
public function available_updates() {
if ($this->availableupdates === null) {
// Lazy load the information about available updates.
$this->availableupdates = $this->pluginman->load_available_updates_for_plugin($this->component);
}
if (empty($this->availableupdates) or !is_array($this->availableupdates)) {
$this->availableupdates = array();
return null;
}
$updates = array();
foreach ($this->availableupdates as $availableupdate) {
if ($availableupdate->version > $this->versiondisk) {
$updates[] = $availableupdate;
}
}
if (empty($updates)) {
return null;
}
return $updates;
}
|
php
|
public function available_updates() {
if ($this->availableupdates === null) {
// Lazy load the information about available updates.
$this->availableupdates = $this->pluginman->load_available_updates_for_plugin($this->component);
}
if (empty($this->availableupdates) or !is_array($this->availableupdates)) {
$this->availableupdates = array();
return null;
}
$updates = array();
foreach ($this->availableupdates as $availableupdate) {
if ($availableupdate->version > $this->versiondisk) {
$updates[] = $availableupdate;
}
}
if (empty($updates)) {
return null;
}
return $updates;
}
|
[
"public",
"function",
"available_updates",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"availableupdates",
"===",
"null",
")",
"{",
"// Lazy load the information about available updates.",
"$",
"this",
"->",
"availableupdates",
"=",
"$",
"this",
"->",
"pluginman",
"->",
"load_available_updates_for_plugin",
"(",
"$",
"this",
"->",
"component",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"availableupdates",
")",
"or",
"!",
"is_array",
"(",
"$",
"this",
"->",
"availableupdates",
")",
")",
"{",
"$",
"this",
"->",
"availableupdates",
"=",
"array",
"(",
")",
";",
"return",
"null",
";",
"}",
"$",
"updates",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"availableupdates",
"as",
"$",
"availableupdate",
")",
"{",
"if",
"(",
"$",
"availableupdate",
"->",
"version",
">",
"$",
"this",
"->",
"versiondisk",
")",
"{",
"$",
"updates",
"[",
"]",
"=",
"$",
"availableupdate",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"updates",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"updates",
";",
"}"
] |
If there are updates for this plugin available, returns them.
Returns array of {@link \core\update\info} objects, if some update
is available. Returns null if there is no update available or if the update
availability is unknown.
Populates the property {@link $availableupdates} on first call (lazy
loading).
@return array|null
|
[
"If",
"there",
"are",
"updates",
"for",
"this",
"plugin",
"available",
"returns",
"them",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/plugininfo/base.php#L420-L445
|
217,564
|
moodle/moodle
|
lib/classes/plugininfo/base.php
|
base.get_settings_url
|
public function get_settings_url() {
$section = $this->get_settings_section_name();
if ($section === null) {
return null;
}
$settings = admin_get_root()->locate($section);
if ($settings && $settings instanceof \admin_settingpage) {
return new moodle_url('/admin/settings.php', array('section' => $section));
} else if ($settings && $settings instanceof \admin_externalpage) {
return new moodle_url($settings->url);
} else {
return null;
}
}
|
php
|
public function get_settings_url() {
$section = $this->get_settings_section_name();
if ($section === null) {
return null;
}
$settings = admin_get_root()->locate($section);
if ($settings && $settings instanceof \admin_settingpage) {
return new moodle_url('/admin/settings.php', array('section' => $section));
} else if ($settings && $settings instanceof \admin_externalpage) {
return new moodle_url($settings->url);
} else {
return null;
}
}
|
[
"public",
"function",
"get_settings_url",
"(",
")",
"{",
"$",
"section",
"=",
"$",
"this",
"->",
"get_settings_section_name",
"(",
")",
";",
"if",
"(",
"$",
"section",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"$",
"settings",
"=",
"admin_get_root",
"(",
")",
"->",
"locate",
"(",
"$",
"section",
")",
";",
"if",
"(",
"$",
"settings",
"&&",
"$",
"settings",
"instanceof",
"\\",
"admin_settingpage",
")",
"{",
"return",
"new",
"moodle_url",
"(",
"'/admin/settings.php'",
",",
"array",
"(",
"'section'",
"=>",
"$",
"section",
")",
")",
";",
"}",
"else",
"if",
"(",
"$",
"settings",
"&&",
"$",
"settings",
"instanceof",
"\\",
"admin_externalpage",
")",
"{",
"return",
"new",
"moodle_url",
"(",
"$",
"settings",
"->",
"url",
")",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] |
Returns the URL of the plugin settings screen
Null value means that the plugin either does not have the settings screen
or its location is not available via this library.
@return null|moodle_url
|
[
"Returns",
"the",
"URL",
"of",
"the",
"plugin",
"settings",
"screen"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/plugininfo/base.php#L464-L477
|
217,565
|
moodle/moodle
|
lib/horde/framework/Horde/Array/Sort/Helper.php
|
Horde_Array_Sort_Helper.compareKeys
|
public function compareKeys($a, $b)
{
return strcoll(Horde_String::lower($a, true, 'UTF-8'), Horde_String::lower($b, true, 'UTF-8'));
}
|
php
|
public function compareKeys($a, $b)
{
return strcoll(Horde_String::lower($a, true, 'UTF-8'), Horde_String::lower($b, true, 'UTF-8'));
}
|
[
"public",
"function",
"compareKeys",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"return",
"strcoll",
"(",
"Horde_String",
"::",
"lower",
"(",
"$",
"a",
",",
"true",
",",
"'UTF-8'",
")",
",",
"Horde_String",
"::",
"lower",
"(",
"$",
"b",
",",
"true",
",",
"'UTF-8'",
")",
")",
";",
"}"
] |
Compare array keys case insensitively for uksort.
@param scalar $a TODO
@param scalar $b TODO
@return TODO
|
[
"Compare",
"array",
"keys",
"case",
"insensitively",
"for",
"uksort",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Array/Sort/Helper.php#L59-L62
|
217,566
|
moodle/moodle
|
lib/horde/framework/Horde/Array/Sort/Helper.php
|
Horde_Array_Sort_Helper.reverseCompareKeys
|
public function reverseCompareKeys($a, $b)
{
return strcoll(Horde_String::lower($b, true, 'UTF-8'), Horde_String::lower($a, true, 'UTF-8'));
}
|
php
|
public function reverseCompareKeys($a, $b)
{
return strcoll(Horde_String::lower($b, true, 'UTF-8'), Horde_String::lower($a, true, 'UTF-8'));
}
|
[
"public",
"function",
"reverseCompareKeys",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"return",
"strcoll",
"(",
"Horde_String",
"::",
"lower",
"(",
"$",
"b",
",",
"true",
",",
"'UTF-8'",
")",
",",
"Horde_String",
"::",
"lower",
"(",
"$",
"a",
",",
"true",
",",
"'UTF-8'",
")",
")",
";",
"}"
] |
Compare, in reverse order, array keys case insensitively for uksort.
@param scalar $a TODO
@param scalar $b TODO
@return TODO
|
[
"Compare",
"in",
"reverse",
"order",
"array",
"keys",
"case",
"insensitively",
"for",
"uksort",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Array/Sort/Helper.php#L72-L75
|
217,567
|
moodle/moodle
|
auth/oauth2/classes/api.php
|
api.get_linked_logins
|
public static function get_linked_logins($userid = false) {
global $USER;
if ($userid === false) {
$userid = $USER->id;
}
if (\core\session\manager::is_loggedinas()) {
throw new moodle_exception('notwhileloggedinas', 'auth_oauth2');
}
$context = context_user::instance($userid);
require_capability('auth/oauth2:managelinkedlogins', $context);
return linked_login::get_records(['userid' => $userid, 'confirmtoken' => '']);
}
|
php
|
public static function get_linked_logins($userid = false) {
global $USER;
if ($userid === false) {
$userid = $USER->id;
}
if (\core\session\manager::is_loggedinas()) {
throw new moodle_exception('notwhileloggedinas', 'auth_oauth2');
}
$context = context_user::instance($userid);
require_capability('auth/oauth2:managelinkedlogins', $context);
return linked_login::get_records(['userid' => $userid, 'confirmtoken' => '']);
}
|
[
"public",
"static",
"function",
"get_linked_logins",
"(",
"$",
"userid",
"=",
"false",
")",
"{",
"global",
"$",
"USER",
";",
"if",
"(",
"$",
"userid",
"===",
"false",
")",
"{",
"$",
"userid",
"=",
"$",
"USER",
"->",
"id",
";",
"}",
"if",
"(",
"\\",
"core",
"\\",
"session",
"\\",
"manager",
"::",
"is_loggedinas",
"(",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'notwhileloggedinas'",
",",
"'auth_oauth2'",
")",
";",
"}",
"$",
"context",
"=",
"context_user",
"::",
"instance",
"(",
"$",
"userid",
")",
";",
"require_capability",
"(",
"'auth/oauth2:managelinkedlogins'",
",",
"$",
"context",
")",
";",
"return",
"linked_login",
"::",
"get_records",
"(",
"[",
"'userid'",
"=>",
"$",
"userid",
",",
"'confirmtoken'",
"=>",
"''",
"]",
")",
";",
"}"
] |
List linked logins
Requires auth/oauth2:managelinkedlogins capability at the user context.
@param int $userid (defaults to $USER->id)
@return boolean
|
[
"List",
"linked",
"logins"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/oauth2/classes/api.php#L60-L75
|
217,568
|
moodle/moodle
|
auth/oauth2/classes/api.php
|
api.match_username_to_user
|
public static function match_username_to_user($username, $issuer) {
$params = [
'issuerid' => $issuer->get('id'),
'username' => $username
];
$result = linked_login::get_record($params);
if ($result) {
$user = \core_user::get_user($result->get('userid'));
if (!empty($user) && !$user->deleted) {
return $result;
}
}
return false;
}
|
php
|
public static function match_username_to_user($username, $issuer) {
$params = [
'issuerid' => $issuer->get('id'),
'username' => $username
];
$result = linked_login::get_record($params);
if ($result) {
$user = \core_user::get_user($result->get('userid'));
if (!empty($user) && !$user->deleted) {
return $result;
}
}
return false;
}
|
[
"public",
"static",
"function",
"match_username_to_user",
"(",
"$",
"username",
",",
"$",
"issuer",
")",
"{",
"$",
"params",
"=",
"[",
"'issuerid'",
"=>",
"$",
"issuer",
"->",
"get",
"(",
"'id'",
")",
",",
"'username'",
"=>",
"$",
"username",
"]",
";",
"$",
"result",
"=",
"linked_login",
"::",
"get_record",
"(",
"$",
"params",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"$",
"user",
"=",
"\\",
"core_user",
"::",
"get_user",
"(",
"$",
"result",
"->",
"get",
"(",
"'userid'",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"user",
")",
"&&",
"!",
"$",
"user",
"->",
"deleted",
")",
"{",
"return",
"$",
"result",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
See if there is a match for this username and issuer in the linked_login table.
@param string $username as returned from an oauth client.
@param \core\oauth2\issuer $issuer
@return stdClass User record if found.
|
[
"See",
"if",
"there",
"is",
"a",
"match",
"for",
"this",
"username",
"and",
"issuer",
"in",
"the",
"linked_login",
"table",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/oauth2/classes/api.php#L84-L98
|
217,569
|
moodle/moodle
|
auth/oauth2/classes/api.php
|
api.link_login
|
public static function link_login($userinfo, $issuer, $userid = false, $skippermissions = false) {
global $USER;
if ($userid === false) {
$userid = $USER->id;
}
if (linked_login::has_existing_issuer_match($issuer, $userinfo['username'])) {
throw new moodle_exception('alreadylinked', 'auth_oauth2');
}
if (\core\session\manager::is_loggedinas()) {
throw new moodle_exception('notwhileloggedinas', 'auth_oauth2');
}
$context = context_user::instance($userid);
if (!$skippermissions) {
require_capability('auth/oauth2:managelinkedlogins', $context);
}
$record = new stdClass();
$record->issuerid = $issuer->get('id');
$record->username = $userinfo['username'];
$record->userid = $userid;
$existing = linked_login::get_record((array)$record);
if ($existing) {
$existing->set('confirmtoken', '');
$existing->update();
return $existing;
}
$record->email = $userinfo['email'];
$record->confirmtoken = '';
$record->confirmtokenexpires = 0;
$linkedlogin = new linked_login(0, $record);
return $linkedlogin->create();
}
|
php
|
public static function link_login($userinfo, $issuer, $userid = false, $skippermissions = false) {
global $USER;
if ($userid === false) {
$userid = $USER->id;
}
if (linked_login::has_existing_issuer_match($issuer, $userinfo['username'])) {
throw new moodle_exception('alreadylinked', 'auth_oauth2');
}
if (\core\session\manager::is_loggedinas()) {
throw new moodle_exception('notwhileloggedinas', 'auth_oauth2');
}
$context = context_user::instance($userid);
if (!$skippermissions) {
require_capability('auth/oauth2:managelinkedlogins', $context);
}
$record = new stdClass();
$record->issuerid = $issuer->get('id');
$record->username = $userinfo['username'];
$record->userid = $userid;
$existing = linked_login::get_record((array)$record);
if ($existing) {
$existing->set('confirmtoken', '');
$existing->update();
return $existing;
}
$record->email = $userinfo['email'];
$record->confirmtoken = '';
$record->confirmtokenexpires = 0;
$linkedlogin = new linked_login(0, $record);
return $linkedlogin->create();
}
|
[
"public",
"static",
"function",
"link_login",
"(",
"$",
"userinfo",
",",
"$",
"issuer",
",",
"$",
"userid",
"=",
"false",
",",
"$",
"skippermissions",
"=",
"false",
")",
"{",
"global",
"$",
"USER",
";",
"if",
"(",
"$",
"userid",
"===",
"false",
")",
"{",
"$",
"userid",
"=",
"$",
"USER",
"->",
"id",
";",
"}",
"if",
"(",
"linked_login",
"::",
"has_existing_issuer_match",
"(",
"$",
"issuer",
",",
"$",
"userinfo",
"[",
"'username'",
"]",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'alreadylinked'",
",",
"'auth_oauth2'",
")",
";",
"}",
"if",
"(",
"\\",
"core",
"\\",
"session",
"\\",
"manager",
"::",
"is_loggedinas",
"(",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'notwhileloggedinas'",
",",
"'auth_oauth2'",
")",
";",
"}",
"$",
"context",
"=",
"context_user",
"::",
"instance",
"(",
"$",
"userid",
")",
";",
"if",
"(",
"!",
"$",
"skippermissions",
")",
"{",
"require_capability",
"(",
"'auth/oauth2:managelinkedlogins'",
",",
"$",
"context",
")",
";",
"}",
"$",
"record",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"record",
"->",
"issuerid",
"=",
"$",
"issuer",
"->",
"get",
"(",
"'id'",
")",
";",
"$",
"record",
"->",
"username",
"=",
"$",
"userinfo",
"[",
"'username'",
"]",
";",
"$",
"record",
"->",
"userid",
"=",
"$",
"userid",
";",
"$",
"existing",
"=",
"linked_login",
"::",
"get_record",
"(",
"(",
"array",
")",
"$",
"record",
")",
";",
"if",
"(",
"$",
"existing",
")",
"{",
"$",
"existing",
"->",
"set",
"(",
"'confirmtoken'",
",",
"''",
")",
";",
"$",
"existing",
"->",
"update",
"(",
")",
";",
"return",
"$",
"existing",
";",
"}",
"$",
"record",
"->",
"email",
"=",
"$",
"userinfo",
"[",
"'email'",
"]",
";",
"$",
"record",
"->",
"confirmtoken",
"=",
"''",
";",
"$",
"record",
"->",
"confirmtokenexpires",
"=",
"0",
";",
"$",
"linkedlogin",
"=",
"new",
"linked_login",
"(",
"0",
",",
"$",
"record",
")",
";",
"return",
"$",
"linkedlogin",
"->",
"create",
"(",
")",
";",
"}"
] |
Link a login to this account.
Requires auth/oauth2:managelinkedlogins capability at the user context.
@param array $userinfo as returned from an oauth client.
@param \core\oauth2\issuer $issuer
@param int $userid (defaults to $USER->id)
@param bool $skippermissions During signup we need to set this before the user is setup for capability checks.
@return bool
|
[
"Link",
"a",
"login",
"to",
"this",
"account",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/oauth2/classes/api.php#L111-L146
|
217,570
|
moodle/moodle
|
auth/oauth2/classes/api.php
|
api.send_confirm_link_login_email
|
public static function send_confirm_link_login_email($userinfo, $issuer, $userid) {
$record = new stdClass();
$record->issuerid = $issuer->get('id');
$record->username = $userinfo['username'];
$record->userid = $userid;
if (linked_login::has_existing_issuer_match($issuer, $userinfo['username'])) {
throw new moodle_exception('alreadylinked', 'auth_oauth2');
}
$record->email = $userinfo['email'];
$record->confirmtoken = random_string(32);
$expires = new \DateTime('NOW');
$expires->add(new \DateInterval('PT30M'));
$record->confirmtokenexpires = $expires->getTimestamp();
$linkedlogin = new linked_login(0, $record);
$linkedlogin->create();
// Construct the email.
$site = get_site();
$supportuser = \core_user::get_support_user();
$user = get_complete_user_data('id', $userid);
$data = new stdClass();
$data->fullname = fullname($user);
$data->sitename = format_string($site->fullname);
$data->admin = generate_email_signoff();
$data->issuername = format_string($issuer->get('name'));
$data->linkedemail = format_string($linkedlogin->get('email'));
$subject = get_string('confirmlinkedloginemailsubject', 'auth_oauth2', format_string($site->fullname));
$params = [
'token' => $linkedlogin->get('confirmtoken'),
'userid' => $userid,
'username' => $userinfo['username'],
'issuerid' => $issuer->get('id'),
];
$confirmationurl = new moodle_url('/auth/oauth2/confirm-linkedlogin.php', $params);
$data->link = $confirmationurl->out(false);
$message = get_string('confirmlinkedloginemail', 'auth_oauth2', $data);
$data->link = $confirmationurl->out();
$messagehtml = text_to_html(get_string('confirmlinkedloginemail', 'auth_oauth2', $data), false, false, true);
$user->mailformat = 1; // Always send HTML version as well.
// Directly email rather than using the messaging system to ensure its not routed to a popup or jabber.
return email_to_user($user, $supportuser, $subject, $message, $messagehtml);
}
|
php
|
public static function send_confirm_link_login_email($userinfo, $issuer, $userid) {
$record = new stdClass();
$record->issuerid = $issuer->get('id');
$record->username = $userinfo['username'];
$record->userid = $userid;
if (linked_login::has_existing_issuer_match($issuer, $userinfo['username'])) {
throw new moodle_exception('alreadylinked', 'auth_oauth2');
}
$record->email = $userinfo['email'];
$record->confirmtoken = random_string(32);
$expires = new \DateTime('NOW');
$expires->add(new \DateInterval('PT30M'));
$record->confirmtokenexpires = $expires->getTimestamp();
$linkedlogin = new linked_login(0, $record);
$linkedlogin->create();
// Construct the email.
$site = get_site();
$supportuser = \core_user::get_support_user();
$user = get_complete_user_data('id', $userid);
$data = new stdClass();
$data->fullname = fullname($user);
$data->sitename = format_string($site->fullname);
$data->admin = generate_email_signoff();
$data->issuername = format_string($issuer->get('name'));
$data->linkedemail = format_string($linkedlogin->get('email'));
$subject = get_string('confirmlinkedloginemailsubject', 'auth_oauth2', format_string($site->fullname));
$params = [
'token' => $linkedlogin->get('confirmtoken'),
'userid' => $userid,
'username' => $userinfo['username'],
'issuerid' => $issuer->get('id'),
];
$confirmationurl = new moodle_url('/auth/oauth2/confirm-linkedlogin.php', $params);
$data->link = $confirmationurl->out(false);
$message = get_string('confirmlinkedloginemail', 'auth_oauth2', $data);
$data->link = $confirmationurl->out();
$messagehtml = text_to_html(get_string('confirmlinkedloginemail', 'auth_oauth2', $data), false, false, true);
$user->mailformat = 1; // Always send HTML version as well.
// Directly email rather than using the messaging system to ensure its not routed to a popup or jabber.
return email_to_user($user, $supportuser, $subject, $message, $messagehtml);
}
|
[
"public",
"static",
"function",
"send_confirm_link_login_email",
"(",
"$",
"userinfo",
",",
"$",
"issuer",
",",
"$",
"userid",
")",
"{",
"$",
"record",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"record",
"->",
"issuerid",
"=",
"$",
"issuer",
"->",
"get",
"(",
"'id'",
")",
";",
"$",
"record",
"->",
"username",
"=",
"$",
"userinfo",
"[",
"'username'",
"]",
";",
"$",
"record",
"->",
"userid",
"=",
"$",
"userid",
";",
"if",
"(",
"linked_login",
"::",
"has_existing_issuer_match",
"(",
"$",
"issuer",
",",
"$",
"userinfo",
"[",
"'username'",
"]",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'alreadylinked'",
",",
"'auth_oauth2'",
")",
";",
"}",
"$",
"record",
"->",
"email",
"=",
"$",
"userinfo",
"[",
"'email'",
"]",
";",
"$",
"record",
"->",
"confirmtoken",
"=",
"random_string",
"(",
"32",
")",
";",
"$",
"expires",
"=",
"new",
"\\",
"DateTime",
"(",
"'NOW'",
")",
";",
"$",
"expires",
"->",
"add",
"(",
"new",
"\\",
"DateInterval",
"(",
"'PT30M'",
")",
")",
";",
"$",
"record",
"->",
"confirmtokenexpires",
"=",
"$",
"expires",
"->",
"getTimestamp",
"(",
")",
";",
"$",
"linkedlogin",
"=",
"new",
"linked_login",
"(",
"0",
",",
"$",
"record",
")",
";",
"$",
"linkedlogin",
"->",
"create",
"(",
")",
";",
"// Construct the email.",
"$",
"site",
"=",
"get_site",
"(",
")",
";",
"$",
"supportuser",
"=",
"\\",
"core_user",
"::",
"get_support_user",
"(",
")",
";",
"$",
"user",
"=",
"get_complete_user_data",
"(",
"'id'",
",",
"$",
"userid",
")",
";",
"$",
"data",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"data",
"->",
"fullname",
"=",
"fullname",
"(",
"$",
"user",
")",
";",
"$",
"data",
"->",
"sitename",
"=",
"format_string",
"(",
"$",
"site",
"->",
"fullname",
")",
";",
"$",
"data",
"->",
"admin",
"=",
"generate_email_signoff",
"(",
")",
";",
"$",
"data",
"->",
"issuername",
"=",
"format_string",
"(",
"$",
"issuer",
"->",
"get",
"(",
"'name'",
")",
")",
";",
"$",
"data",
"->",
"linkedemail",
"=",
"format_string",
"(",
"$",
"linkedlogin",
"->",
"get",
"(",
"'email'",
")",
")",
";",
"$",
"subject",
"=",
"get_string",
"(",
"'confirmlinkedloginemailsubject'",
",",
"'auth_oauth2'",
",",
"format_string",
"(",
"$",
"site",
"->",
"fullname",
")",
")",
";",
"$",
"params",
"=",
"[",
"'token'",
"=>",
"$",
"linkedlogin",
"->",
"get",
"(",
"'confirmtoken'",
")",
",",
"'userid'",
"=>",
"$",
"userid",
",",
"'username'",
"=>",
"$",
"userinfo",
"[",
"'username'",
"]",
",",
"'issuerid'",
"=>",
"$",
"issuer",
"->",
"get",
"(",
"'id'",
")",
",",
"]",
";",
"$",
"confirmationurl",
"=",
"new",
"moodle_url",
"(",
"'/auth/oauth2/confirm-linkedlogin.php'",
",",
"$",
"params",
")",
";",
"$",
"data",
"->",
"link",
"=",
"$",
"confirmationurl",
"->",
"out",
"(",
"false",
")",
";",
"$",
"message",
"=",
"get_string",
"(",
"'confirmlinkedloginemail'",
",",
"'auth_oauth2'",
",",
"$",
"data",
")",
";",
"$",
"data",
"->",
"link",
"=",
"$",
"confirmationurl",
"->",
"out",
"(",
")",
";",
"$",
"messagehtml",
"=",
"text_to_html",
"(",
"get_string",
"(",
"'confirmlinkedloginemail'",
",",
"'auth_oauth2'",
",",
"$",
"data",
")",
",",
"false",
",",
"false",
",",
"true",
")",
";",
"$",
"user",
"->",
"mailformat",
"=",
"1",
";",
"// Always send HTML version as well.",
"// Directly email rather than using the messaging system to ensure its not routed to a popup or jabber.",
"return",
"email_to_user",
"(",
"$",
"user",
",",
"$",
"supportuser",
",",
"$",
"subject",
",",
"$",
"message",
",",
"$",
"messagehtml",
")",
";",
"}"
] |
Send an email with a link to confirm linking this account.
@param array $userinfo as returned from an oauth client.
@param \core\oauth2\issuer $issuer
@param int $userid (defaults to $USER->id)
@return bool
|
[
"Send",
"an",
"email",
"with",
"a",
"link",
"to",
"confirm",
"linking",
"this",
"account",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/oauth2/classes/api.php#L156-L205
|
217,571
|
moodle/moodle
|
auth/oauth2/classes/api.php
|
api.confirm_link_login
|
public static function confirm_link_login($userid, $username, $issuerid, $token) {
if (empty($token) || empty($userid) || empty($issuerid) || empty($username)) {
return false;
}
$params = [
'userid' => $userid,
'username' => $username,
'issuerid' => $issuerid,
'confirmtoken' => $token,
];
$login = linked_login::get_record($params);
if (empty($login)) {
return false;
}
$expires = $login->get('confirmtokenexpires');
if (time() > $expires) {
$login->delete();
return;
}
$login->set('confirmtokenexpires', 0);
$login->set('confirmtoken', '');
$login->update();
return true;
}
|
php
|
public static function confirm_link_login($userid, $username, $issuerid, $token) {
if (empty($token) || empty($userid) || empty($issuerid) || empty($username)) {
return false;
}
$params = [
'userid' => $userid,
'username' => $username,
'issuerid' => $issuerid,
'confirmtoken' => $token,
];
$login = linked_login::get_record($params);
if (empty($login)) {
return false;
}
$expires = $login->get('confirmtokenexpires');
if (time() > $expires) {
$login->delete();
return;
}
$login->set('confirmtokenexpires', 0);
$login->set('confirmtoken', '');
$login->update();
return true;
}
|
[
"public",
"static",
"function",
"confirm_link_login",
"(",
"$",
"userid",
",",
"$",
"username",
",",
"$",
"issuerid",
",",
"$",
"token",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"token",
")",
"||",
"empty",
"(",
"$",
"userid",
")",
"||",
"empty",
"(",
"$",
"issuerid",
")",
"||",
"empty",
"(",
"$",
"username",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"params",
"=",
"[",
"'userid'",
"=>",
"$",
"userid",
",",
"'username'",
"=>",
"$",
"username",
",",
"'issuerid'",
"=>",
"$",
"issuerid",
",",
"'confirmtoken'",
"=>",
"$",
"token",
",",
"]",
";",
"$",
"login",
"=",
"linked_login",
"::",
"get_record",
"(",
"$",
"params",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"login",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"expires",
"=",
"$",
"login",
"->",
"get",
"(",
"'confirmtokenexpires'",
")",
";",
"if",
"(",
"time",
"(",
")",
">",
"$",
"expires",
")",
"{",
"$",
"login",
"->",
"delete",
"(",
")",
";",
"return",
";",
"}",
"$",
"login",
"->",
"set",
"(",
"'confirmtokenexpires'",
",",
"0",
")",
";",
"$",
"login",
"->",
"set",
"(",
"'confirmtoken'",
",",
"''",
")",
";",
"$",
"login",
"->",
"update",
"(",
")",
";",
"return",
"true",
";",
"}"
] |
Look for a waiting confirmation token, and if we find a match - confirm it.
@param int $userid
@param string $username
@param int $issuerid
@param string $token
@return boolean True if we linked.
|
[
"Look",
"for",
"a",
"waiting",
"confirmation",
"token",
"and",
"if",
"we",
"find",
"a",
"match",
"-",
"confirm",
"it",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/oauth2/classes/api.php#L216-L240
|
217,572
|
moodle/moodle
|
auth/oauth2/classes/api.php
|
api.create_new_confirmed_account
|
public static function create_new_confirmed_account($userinfo, $issuer) {
global $CFG, $DB;
require_once($CFG->dirroot.'/user/profile/lib.php');
require_once($CFG->dirroot.'/user/lib.php');
$user = new stdClass();
$user->username = $userinfo['username'];
$user->email = $userinfo['email'];
$user->auth = 'oauth2';
$user->mnethostid = $CFG->mnet_localhost_id;
$user->lastname = isset($userinfo['lastname']) ? $userinfo['lastname'] : '';
$user->firstname = isset($userinfo['firstname']) ? $userinfo['firstname'] : '';
$user->url = isset($userinfo['url']) ? $userinfo['url'] : '';
$user->alternatename = isset($userinfo['alternatename']) ? $userinfo['alternatename'] : '';
$user->secret = random_string(15);
$user->password = '';
// This user is confirmed.
$user->confirmed = 1;
$user->id = user_create_user($user, false, true);
// The linked account is pre-confirmed.
$record = new stdClass();
$record->issuerid = $issuer->get('id');
$record->username = $userinfo['username'];
$record->userid = $user->id;
$record->email = $userinfo['email'];
$record->confirmtoken = '';
$record->confirmtokenexpires = 0;
$linkedlogin = new linked_login(0, $record);
$linkedlogin->create();
return $user;
}
|
php
|
public static function create_new_confirmed_account($userinfo, $issuer) {
global $CFG, $DB;
require_once($CFG->dirroot.'/user/profile/lib.php');
require_once($CFG->dirroot.'/user/lib.php');
$user = new stdClass();
$user->username = $userinfo['username'];
$user->email = $userinfo['email'];
$user->auth = 'oauth2';
$user->mnethostid = $CFG->mnet_localhost_id;
$user->lastname = isset($userinfo['lastname']) ? $userinfo['lastname'] : '';
$user->firstname = isset($userinfo['firstname']) ? $userinfo['firstname'] : '';
$user->url = isset($userinfo['url']) ? $userinfo['url'] : '';
$user->alternatename = isset($userinfo['alternatename']) ? $userinfo['alternatename'] : '';
$user->secret = random_string(15);
$user->password = '';
// This user is confirmed.
$user->confirmed = 1;
$user->id = user_create_user($user, false, true);
// The linked account is pre-confirmed.
$record = new stdClass();
$record->issuerid = $issuer->get('id');
$record->username = $userinfo['username'];
$record->userid = $user->id;
$record->email = $userinfo['email'];
$record->confirmtoken = '';
$record->confirmtokenexpires = 0;
$linkedlogin = new linked_login(0, $record);
$linkedlogin->create();
return $user;
}
|
[
"public",
"static",
"function",
"create_new_confirmed_account",
"(",
"$",
"userinfo",
",",
"$",
"issuer",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/user/profile/lib.php'",
")",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/user/lib.php'",
")",
";",
"$",
"user",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"user",
"->",
"username",
"=",
"$",
"userinfo",
"[",
"'username'",
"]",
";",
"$",
"user",
"->",
"email",
"=",
"$",
"userinfo",
"[",
"'email'",
"]",
";",
"$",
"user",
"->",
"auth",
"=",
"'oauth2'",
";",
"$",
"user",
"->",
"mnethostid",
"=",
"$",
"CFG",
"->",
"mnet_localhost_id",
";",
"$",
"user",
"->",
"lastname",
"=",
"isset",
"(",
"$",
"userinfo",
"[",
"'lastname'",
"]",
")",
"?",
"$",
"userinfo",
"[",
"'lastname'",
"]",
":",
"''",
";",
"$",
"user",
"->",
"firstname",
"=",
"isset",
"(",
"$",
"userinfo",
"[",
"'firstname'",
"]",
")",
"?",
"$",
"userinfo",
"[",
"'firstname'",
"]",
":",
"''",
";",
"$",
"user",
"->",
"url",
"=",
"isset",
"(",
"$",
"userinfo",
"[",
"'url'",
"]",
")",
"?",
"$",
"userinfo",
"[",
"'url'",
"]",
":",
"''",
";",
"$",
"user",
"->",
"alternatename",
"=",
"isset",
"(",
"$",
"userinfo",
"[",
"'alternatename'",
"]",
")",
"?",
"$",
"userinfo",
"[",
"'alternatename'",
"]",
":",
"''",
";",
"$",
"user",
"->",
"secret",
"=",
"random_string",
"(",
"15",
")",
";",
"$",
"user",
"->",
"password",
"=",
"''",
";",
"// This user is confirmed.",
"$",
"user",
"->",
"confirmed",
"=",
"1",
";",
"$",
"user",
"->",
"id",
"=",
"user_create_user",
"(",
"$",
"user",
",",
"false",
",",
"true",
")",
";",
"// The linked account is pre-confirmed.",
"$",
"record",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"record",
"->",
"issuerid",
"=",
"$",
"issuer",
"->",
"get",
"(",
"'id'",
")",
";",
"$",
"record",
"->",
"username",
"=",
"$",
"userinfo",
"[",
"'username'",
"]",
";",
"$",
"record",
"->",
"userid",
"=",
"$",
"user",
"->",
"id",
";",
"$",
"record",
"->",
"email",
"=",
"$",
"userinfo",
"[",
"'email'",
"]",
";",
"$",
"record",
"->",
"confirmtoken",
"=",
"''",
";",
"$",
"record",
"->",
"confirmtokenexpires",
"=",
"0",
";",
"$",
"linkedlogin",
"=",
"new",
"linked_login",
"(",
"0",
",",
"$",
"record",
")",
";",
"$",
"linkedlogin",
"->",
"create",
"(",
")",
";",
"return",
"$",
"user",
";",
"}"
] |
Create an account with a linked login that is already confirmed.
@param array $userinfo as returned from an oauth client.
@param \core\oauth2\issuer $issuer
@return bool
|
[
"Create",
"an",
"account",
"with",
"a",
"linked",
"login",
"that",
"is",
"already",
"confirmed",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/oauth2/classes/api.php#L249-L284
|
217,573
|
moodle/moodle
|
auth/oauth2/classes/api.php
|
api.delete_linked_login
|
public static function delete_linked_login($linkedloginid) {
$login = new linked_login($linkedloginid);
$userid = $login->get('userid');
if (\core\session\manager::is_loggedinas()) {
throw new moodle_exception('notwhileloggedinas', 'auth_oauth2');
}
$context = context_user::instance($userid);
require_capability('auth/oauth2:managelinkedlogins', $context);
$login->delete();
}
|
php
|
public static function delete_linked_login($linkedloginid) {
$login = new linked_login($linkedloginid);
$userid = $login->get('userid');
if (\core\session\manager::is_loggedinas()) {
throw new moodle_exception('notwhileloggedinas', 'auth_oauth2');
}
$context = context_user::instance($userid);
require_capability('auth/oauth2:managelinkedlogins', $context);
$login->delete();
}
|
[
"public",
"static",
"function",
"delete_linked_login",
"(",
"$",
"linkedloginid",
")",
"{",
"$",
"login",
"=",
"new",
"linked_login",
"(",
"$",
"linkedloginid",
")",
";",
"$",
"userid",
"=",
"$",
"login",
"->",
"get",
"(",
"'userid'",
")",
";",
"if",
"(",
"\\",
"core",
"\\",
"session",
"\\",
"manager",
"::",
"is_loggedinas",
"(",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'notwhileloggedinas'",
",",
"'auth_oauth2'",
")",
";",
"}",
"$",
"context",
"=",
"context_user",
"::",
"instance",
"(",
"$",
"userid",
")",
";",
"require_capability",
"(",
"'auth/oauth2:managelinkedlogins'",
",",
"$",
"context",
")",
";",
"$",
"login",
"->",
"delete",
"(",
")",
";",
"}"
] |
Delete linked login
Requires auth/oauth2:managelinkedlogins capability at the user context.
@param int $linkedloginid
@return boolean
|
[
"Delete",
"linked",
"login"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/oauth2/classes/api.php#L371-L383
|
217,574
|
moodle/moodle
|
auth/oauth2/classes/api.php
|
api.user_deleted
|
public static function user_deleted(\core\event\user_deleted $event) {
global $DB;
$userid = $event->objectid;
return $DB->delete_records(linked_login::TABLE, ['userid' => $userid]);
}
|
php
|
public static function user_deleted(\core\event\user_deleted $event) {
global $DB;
$userid = $event->objectid;
return $DB->delete_records(linked_login::TABLE, ['userid' => $userid]);
}
|
[
"public",
"static",
"function",
"user_deleted",
"(",
"\\",
"core",
"\\",
"event",
"\\",
"user_deleted",
"$",
"event",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"userid",
"=",
"$",
"event",
"->",
"objectid",
";",
"return",
"$",
"DB",
"->",
"delete_records",
"(",
"linked_login",
"::",
"TABLE",
",",
"[",
"'userid'",
"=>",
"$",
"userid",
"]",
")",
";",
"}"
] |
Delete linked logins for a user.
@param \core\event\user_deleted $event
@return boolean
|
[
"Delete",
"linked",
"logins",
"for",
"a",
"user",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/oauth2/classes/api.php#L391-L397
|
217,575
|
moodle/moodle
|
lib/googleapi.php
|
google_docs.send_file
|
public function send_file($file) {
// First we create the 'resumable upload request'.
$this->googleoauth->setHeader("Content-Length: 0");
$this->googleoauth->setHeader("X-Upload-Content-Length: ". $file->get_filesize());
$this->googleoauth->setHeader("X-Upload-Content-Type: ". $file->get_mimetype());
$this->googleoauth->setHeader("Slug: ". $file->get_filename());
$this->googleoauth->post(self::UPLOAD_URL);
if ($this->googleoauth->info['http_code'] !== 200) {
throw new moodle_exception('Cantpostupload');
}
// Now we http PUT the file in the location returned.
$location = $this->googleoauth->response['Location'];
if (empty($location)) {
throw new moodle_exception('Nouploadlocation');
}
// Reset the curl object for actually sending the file.
$this->reset_curl_state();
$this->googleoauth->setHeader("Content-Length: ". $file->get_filesize());
$this->googleoauth->setHeader("Content-Type: ". $file->get_mimetype());
// We can't get a filepointer, so have to copy the file..
$tmproot = make_temp_directory('googledocsuploads');
$tmpfilepath = $tmproot.'/'.$file->get_contenthash();
$file->copy_content_to($tmpfilepath);
// HTTP PUT the file.
$this->googleoauth->put($location, array('file'=>$tmpfilepath));
// Remove the temporary file we created..
unlink($tmpfilepath);
if ($this->googleoauth->info['http_code'] === 201) {
// Clear headers for further requests.
$this->reset_curl_state();
return true;
} else {
return false;
}
}
|
php
|
public function send_file($file) {
// First we create the 'resumable upload request'.
$this->googleoauth->setHeader("Content-Length: 0");
$this->googleoauth->setHeader("X-Upload-Content-Length: ". $file->get_filesize());
$this->googleoauth->setHeader("X-Upload-Content-Type: ". $file->get_mimetype());
$this->googleoauth->setHeader("Slug: ". $file->get_filename());
$this->googleoauth->post(self::UPLOAD_URL);
if ($this->googleoauth->info['http_code'] !== 200) {
throw new moodle_exception('Cantpostupload');
}
// Now we http PUT the file in the location returned.
$location = $this->googleoauth->response['Location'];
if (empty($location)) {
throw new moodle_exception('Nouploadlocation');
}
// Reset the curl object for actually sending the file.
$this->reset_curl_state();
$this->googleoauth->setHeader("Content-Length: ". $file->get_filesize());
$this->googleoauth->setHeader("Content-Type: ". $file->get_mimetype());
// We can't get a filepointer, so have to copy the file..
$tmproot = make_temp_directory('googledocsuploads');
$tmpfilepath = $tmproot.'/'.$file->get_contenthash();
$file->copy_content_to($tmpfilepath);
// HTTP PUT the file.
$this->googleoauth->put($location, array('file'=>$tmpfilepath));
// Remove the temporary file we created..
unlink($tmpfilepath);
if ($this->googleoauth->info['http_code'] === 201) {
// Clear headers for further requests.
$this->reset_curl_state();
return true;
} else {
return false;
}
}
|
[
"public",
"function",
"send_file",
"(",
"$",
"file",
")",
"{",
"// First we create the 'resumable upload request'.",
"$",
"this",
"->",
"googleoauth",
"->",
"setHeader",
"(",
"\"Content-Length: 0\"",
")",
";",
"$",
"this",
"->",
"googleoauth",
"->",
"setHeader",
"(",
"\"X-Upload-Content-Length: \"",
".",
"$",
"file",
"->",
"get_filesize",
"(",
")",
")",
";",
"$",
"this",
"->",
"googleoauth",
"->",
"setHeader",
"(",
"\"X-Upload-Content-Type: \"",
".",
"$",
"file",
"->",
"get_mimetype",
"(",
")",
")",
";",
"$",
"this",
"->",
"googleoauth",
"->",
"setHeader",
"(",
"\"Slug: \"",
".",
"$",
"file",
"->",
"get_filename",
"(",
")",
")",
";",
"$",
"this",
"->",
"googleoauth",
"->",
"post",
"(",
"self",
"::",
"UPLOAD_URL",
")",
";",
"if",
"(",
"$",
"this",
"->",
"googleoauth",
"->",
"info",
"[",
"'http_code'",
"]",
"!==",
"200",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'Cantpostupload'",
")",
";",
"}",
"// Now we http PUT the file in the location returned.",
"$",
"location",
"=",
"$",
"this",
"->",
"googleoauth",
"->",
"response",
"[",
"'Location'",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"location",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'Nouploadlocation'",
")",
";",
"}",
"// Reset the curl object for actually sending the file.",
"$",
"this",
"->",
"reset_curl_state",
"(",
")",
";",
"$",
"this",
"->",
"googleoauth",
"->",
"setHeader",
"(",
"\"Content-Length: \"",
".",
"$",
"file",
"->",
"get_filesize",
"(",
")",
")",
";",
"$",
"this",
"->",
"googleoauth",
"->",
"setHeader",
"(",
"\"Content-Type: \"",
".",
"$",
"file",
"->",
"get_mimetype",
"(",
")",
")",
";",
"// We can't get a filepointer, so have to copy the file..",
"$",
"tmproot",
"=",
"make_temp_directory",
"(",
"'googledocsuploads'",
")",
";",
"$",
"tmpfilepath",
"=",
"$",
"tmproot",
".",
"'/'",
".",
"$",
"file",
"->",
"get_contenthash",
"(",
")",
";",
"$",
"file",
"->",
"copy_content_to",
"(",
"$",
"tmpfilepath",
")",
";",
"// HTTP PUT the file.",
"$",
"this",
"->",
"googleoauth",
"->",
"put",
"(",
"$",
"location",
",",
"array",
"(",
"'file'",
"=>",
"$",
"tmpfilepath",
")",
")",
";",
"// Remove the temporary file we created..",
"unlink",
"(",
"$",
"tmpfilepath",
")",
";",
"if",
"(",
"$",
"this",
"->",
"googleoauth",
"->",
"info",
"[",
"'http_code'",
"]",
"===",
"201",
")",
"{",
"// Clear headers for further requests.",
"$",
"this",
"->",
"reset_curl_state",
"(",
")",
";",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] |
Sends a file object to google documents
@param object $file File object
@return boolean True on success
|
[
"Sends",
"a",
"file",
"object",
"to",
"google",
"documents"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/googleapi.php#L148-L189
|
217,576
|
moodle/moodle
|
lib/googleapi.php
|
google_docs.download_file
|
public function download_file($url, $path, $timeout = 0) {
$result = $this->googleoauth->download_one($url, null, array('filepath' => $path, 'timeout' => $timeout));
if ($result === true) {
$info = $this->googleoauth->get_info();
if (isset($info['http_code']) && $info['http_code'] == 200) {
return array('path'=>$path, 'url'=>$url);
} else {
throw new moodle_exception('cannotdownload', 'repository');
}
} else {
throw new moodle_exception('errorwhiledownload', 'repository', '', $result);
}
}
|
php
|
public function download_file($url, $path, $timeout = 0) {
$result = $this->googleoauth->download_one($url, null, array('filepath' => $path, 'timeout' => $timeout));
if ($result === true) {
$info = $this->googleoauth->get_info();
if (isset($info['http_code']) && $info['http_code'] == 200) {
return array('path'=>$path, 'url'=>$url);
} else {
throw new moodle_exception('cannotdownload', 'repository');
}
} else {
throw new moodle_exception('errorwhiledownload', 'repository', '', $result);
}
}
|
[
"public",
"function",
"download_file",
"(",
"$",
"url",
",",
"$",
"path",
",",
"$",
"timeout",
"=",
"0",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"googleoauth",
"->",
"download_one",
"(",
"$",
"url",
",",
"null",
",",
"array",
"(",
"'filepath'",
"=>",
"$",
"path",
",",
"'timeout'",
"=>",
"$",
"timeout",
")",
")",
";",
"if",
"(",
"$",
"result",
"===",
"true",
")",
"{",
"$",
"info",
"=",
"$",
"this",
"->",
"googleoauth",
"->",
"get_info",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"info",
"[",
"'http_code'",
"]",
")",
"&&",
"$",
"info",
"[",
"'http_code'",
"]",
"==",
"200",
")",
"{",
"return",
"array",
"(",
"'path'",
"=>",
"$",
"path",
",",
"'url'",
"=>",
"$",
"url",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'cannotdownload'",
",",
"'repository'",
")",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'errorwhiledownload'",
",",
"'repository'",
",",
"''",
",",
"$",
"result",
")",
";",
"}",
"}"
] |
Downloads a file using authentication
@param string $url url of file
@param string $path path to save file to
@param int $timeout request timeout, default 0 which means no timeout
@return array stucture for repository download_file
|
[
"Downloads",
"a",
"file",
"using",
"authentication"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/googleapi.php#L199-L211
|
217,577
|
moodle/moodle
|
lib/googleapi.php
|
google_picasa.send_file
|
public function send_file($file) {
$this->googleoauth->setHeader("Content-Length: ". $file->get_filesize());
$this->googleoauth->setHeader("Content-Type: ". $file->get_mimetype());
$this->googleoauth->setHeader("Slug: ". $file->get_filename());
$this->googleoauth->post(self::UPLOAD_LOCATION, $file->get_content());
if ($this->googleoauth->info['http_code'] === 201) {
return true;
} else {
return false;
}
}
|
php
|
public function send_file($file) {
$this->googleoauth->setHeader("Content-Length: ". $file->get_filesize());
$this->googleoauth->setHeader("Content-Type: ". $file->get_mimetype());
$this->googleoauth->setHeader("Slug: ". $file->get_filename());
$this->googleoauth->post(self::UPLOAD_LOCATION, $file->get_content());
if ($this->googleoauth->info['http_code'] === 201) {
return true;
} else {
return false;
}
}
|
[
"public",
"function",
"send_file",
"(",
"$",
"file",
")",
"{",
"$",
"this",
"->",
"googleoauth",
"->",
"setHeader",
"(",
"\"Content-Length: \"",
".",
"$",
"file",
"->",
"get_filesize",
"(",
")",
")",
";",
"$",
"this",
"->",
"googleoauth",
"->",
"setHeader",
"(",
"\"Content-Type: \"",
".",
"$",
"file",
"->",
"get_mimetype",
"(",
")",
")",
";",
"$",
"this",
"->",
"googleoauth",
"->",
"setHeader",
"(",
"\"Slug: \"",
".",
"$",
"file",
"->",
"get_filename",
"(",
")",
")",
";",
"$",
"this",
"->",
"googleoauth",
"->",
"post",
"(",
"self",
"::",
"UPLOAD_LOCATION",
",",
"$",
"file",
"->",
"get_content",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"googleoauth",
"->",
"info",
"[",
"'http_code'",
"]",
"===",
"201",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] |
Sends a file object to picasaweb
@param object $file File object
@return boolean True on success
|
[
"Sends",
"a",
"file",
"object",
"to",
"picasaweb"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/googleapi.php#L259-L271
|
217,578
|
moodle/moodle
|
lib/googleapi.php
|
google_picasa.get_album_photos
|
public function get_album_photos($albumid) {
$albumcontent = $this->googleoauth->get(self::ALBUM_PHOTO_LIST.$albumid);
return $this->get_photo_details($albumcontent);
}
|
php
|
public function get_album_photos($albumid) {
$albumcontent = $this->googleoauth->get(self::ALBUM_PHOTO_LIST.$albumid);
return $this->get_photo_details($albumcontent);
}
|
[
"public",
"function",
"get_album_photos",
"(",
"$",
"albumid",
")",
"{",
"$",
"albumcontent",
"=",
"$",
"this",
"->",
"googleoauth",
"->",
"get",
"(",
"self",
"::",
"ALBUM_PHOTO_LIST",
".",
"$",
"albumid",
")",
";",
"return",
"$",
"this",
"->",
"get_photo_details",
"(",
"$",
"albumcontent",
")",
";",
"}"
] |
Returns list of photos in album specified
@param int $albumid Photo album to list photos from
@return mixed $files A list of files for the file picker
|
[
"Returns",
"list",
"of",
"photos",
"in",
"album",
"specified"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/googleapi.php#L295-L299
|
217,579
|
moodle/moodle
|
lib/googleapi.php
|
google_picasa.do_photo_search
|
public function do_photo_search($query) {
$content = $this->googleoauth->get(self::PHOTO_SEARCH_URL.htmlentities($query));
return $this->get_photo_details($content);
}
|
php
|
public function do_photo_search($query) {
$content = $this->googleoauth->get(self::PHOTO_SEARCH_URL.htmlentities($query));
return $this->get_photo_details($content);
}
|
[
"public",
"function",
"do_photo_search",
"(",
"$",
"query",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"googleoauth",
"->",
"get",
"(",
"self",
"::",
"PHOTO_SEARCH_URL",
".",
"htmlentities",
"(",
"$",
"query",
")",
")",
";",
"return",
"$",
"this",
"->",
"get_photo_details",
"(",
"$",
"content",
")",
";",
"}"
] |
Does text search on the users photos and returns
matches in format for picasa api
@param string $query Search terms
@return mixed $files A list of files for the file picker
|
[
"Does",
"text",
"search",
"on",
"the",
"users",
"photos",
"and",
"returns",
"matches",
"in",
"format",
"for",
"picasa",
"api"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/googleapi.php#L317-L321
|
217,580
|
moodle/moodle
|
lib/googleapi.php
|
google_picasa.get_albums
|
public function get_albums() {
$files = array();
$content = $this->googleoauth->get(self::LIST_ALBUMS_URL);
try {
if (strpos($content, '<?xml') !== 0) {
throw new moodle_exception('invalidxmlresponse');
}
$xml = new SimpleXMLElement($content);
} catch (Exception $e) {
// An error occured while trying to parse the XML, let's just return nothing. SimpleXML does not
// return a more specific Exception, that's why the global Exception class is caught here.
return $files;
}
foreach ($xml->entry as $album) {
$gphoto = $album->children('http://schemas.google.com/photos/2007');
$mediainfo = $album->children('http://search.yahoo.com/mrss/');
// Hacky...
$thumbnailinfo = $mediainfo->group->thumbnail[0]->attributes();
$files[] = array( 'title' => (string) $album->title,
'date' => userdate($gphoto->timestamp),
'size' => (int) $gphoto->bytesUsed,
'path' => (string) $gphoto->id,
'thumbnail' => (string) $thumbnailinfo['url'],
'thumbnail_width' => 160, // 160 is the native maximum dimension.
'thumbnail_height' => 160,
'children' => array(),
);
}
return $files;
}
|
php
|
public function get_albums() {
$files = array();
$content = $this->googleoauth->get(self::LIST_ALBUMS_URL);
try {
if (strpos($content, '<?xml') !== 0) {
throw new moodle_exception('invalidxmlresponse');
}
$xml = new SimpleXMLElement($content);
} catch (Exception $e) {
// An error occured while trying to parse the XML, let's just return nothing. SimpleXML does not
// return a more specific Exception, that's why the global Exception class is caught here.
return $files;
}
foreach ($xml->entry as $album) {
$gphoto = $album->children('http://schemas.google.com/photos/2007');
$mediainfo = $album->children('http://search.yahoo.com/mrss/');
// Hacky...
$thumbnailinfo = $mediainfo->group->thumbnail[0]->attributes();
$files[] = array( 'title' => (string) $album->title,
'date' => userdate($gphoto->timestamp),
'size' => (int) $gphoto->bytesUsed,
'path' => (string) $gphoto->id,
'thumbnail' => (string) $thumbnailinfo['url'],
'thumbnail_width' => 160, // 160 is the native maximum dimension.
'thumbnail_height' => 160,
'children' => array(),
);
}
return $files;
}
|
[
"public",
"function",
"get_albums",
"(",
")",
"{",
"$",
"files",
"=",
"array",
"(",
")",
";",
"$",
"content",
"=",
"$",
"this",
"->",
"googleoauth",
"->",
"get",
"(",
"self",
"::",
"LIST_ALBUMS_URL",
")",
";",
"try",
"{",
"if",
"(",
"strpos",
"(",
"$",
"content",
",",
"'<?xml'",
")",
"!==",
"0",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'invalidxmlresponse'",
")",
";",
"}",
"$",
"xml",
"=",
"new",
"SimpleXMLElement",
"(",
"$",
"content",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"// An error occured while trying to parse the XML, let's just return nothing. SimpleXML does not",
"// return a more specific Exception, that's why the global Exception class is caught here.",
"return",
"$",
"files",
";",
"}",
"foreach",
"(",
"$",
"xml",
"->",
"entry",
"as",
"$",
"album",
")",
"{",
"$",
"gphoto",
"=",
"$",
"album",
"->",
"children",
"(",
"'http://schemas.google.com/photos/2007'",
")",
";",
"$",
"mediainfo",
"=",
"$",
"album",
"->",
"children",
"(",
"'http://search.yahoo.com/mrss/'",
")",
";",
"// Hacky...",
"$",
"thumbnailinfo",
"=",
"$",
"mediainfo",
"->",
"group",
"->",
"thumbnail",
"[",
"0",
"]",
"->",
"attributes",
"(",
")",
";",
"$",
"files",
"[",
"]",
"=",
"array",
"(",
"'title'",
"=>",
"(",
"string",
")",
"$",
"album",
"->",
"title",
",",
"'date'",
"=>",
"userdate",
"(",
"$",
"gphoto",
"->",
"timestamp",
")",
",",
"'size'",
"=>",
"(",
"int",
")",
"$",
"gphoto",
"->",
"bytesUsed",
",",
"'path'",
"=>",
"(",
"string",
")",
"$",
"gphoto",
"->",
"id",
",",
"'thumbnail'",
"=>",
"(",
"string",
")",
"$",
"thumbnailinfo",
"[",
"'url'",
"]",
",",
"'thumbnail_width'",
"=>",
"160",
",",
"// 160 is the native maximum dimension.",
"'thumbnail_height'",
"=>",
"160",
",",
"'children'",
"=>",
"array",
"(",
")",
",",
")",
";",
"}",
"return",
"$",
"files",
";",
"}"
] |
Gets all the users albums and returns them as a list of folders
for the file picker
@return mixes $files Array in the format get_listing uses for folders
|
[
"Gets",
"all",
"the",
"users",
"albums",
"and",
"returns",
"them",
"as",
"a",
"list",
"of",
"folders",
"for",
"the",
"file",
"picker"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/googleapi.php#L329-L363
|
217,581
|
moodle/moodle
|
lib/googleapi.php
|
google_picasa.get_photo_details
|
public function get_photo_details($rawxml) {
$files = array();
try {
if (strpos($rawxml, '<?xml') !== 0) {
throw new moodle_exception('invalidxmlresponse');
}
$xml = new SimpleXMLElement($rawxml);
} catch (Exception $e) {
// An error occured while trying to parse the XML, let's just return nothing. SimpleXML does not
// return a more specific Exception, that's why the global Exception class is caught here.
return $files;
}
$this->lastalbumname = (string)$xml->title;
foreach ($xml->entry as $photo) {
$gphoto = $photo->children('http://schemas.google.com/photos/2007');
$mediainfo = $photo->children('http://search.yahoo.com/mrss/');
$fullinfo = $mediainfo->group->content->attributes();
// Hacky...
$thumbnailinfo = $mediainfo->group->thumbnail[0]->attributes();
// Derive the nicest file name we can.
if (!empty($mediainfo->group->description)) {
$title = shorten_text((string)$mediainfo->group->description, 20, false, '');
$title = clean_filename($title).'.jpg';
} else {
$title = (string)$mediainfo->group->title;
}
$files[] = array(
'title' => $title,
'date' => userdate($gphoto->timestamp),
'size' => (int) $gphoto->size,
'path' => $gphoto->albumid.'/'.$gphoto->id,
'thumbnail' => (string) $thumbnailinfo['url'],
'thumbnail_width' => 72, // 72 is the native maximum dimension.
'thumbnail_height' => 72,
'source' => (string) $fullinfo['url'],
'url' => (string) $fullinfo['url']
);
}
return $files;
}
|
php
|
public function get_photo_details($rawxml) {
$files = array();
try {
if (strpos($rawxml, '<?xml') !== 0) {
throw new moodle_exception('invalidxmlresponse');
}
$xml = new SimpleXMLElement($rawxml);
} catch (Exception $e) {
// An error occured while trying to parse the XML, let's just return nothing. SimpleXML does not
// return a more specific Exception, that's why the global Exception class is caught here.
return $files;
}
$this->lastalbumname = (string)$xml->title;
foreach ($xml->entry as $photo) {
$gphoto = $photo->children('http://schemas.google.com/photos/2007');
$mediainfo = $photo->children('http://search.yahoo.com/mrss/');
$fullinfo = $mediainfo->group->content->attributes();
// Hacky...
$thumbnailinfo = $mediainfo->group->thumbnail[0]->attributes();
// Derive the nicest file name we can.
if (!empty($mediainfo->group->description)) {
$title = shorten_text((string)$mediainfo->group->description, 20, false, '');
$title = clean_filename($title).'.jpg';
} else {
$title = (string)$mediainfo->group->title;
}
$files[] = array(
'title' => $title,
'date' => userdate($gphoto->timestamp),
'size' => (int) $gphoto->size,
'path' => $gphoto->albumid.'/'.$gphoto->id,
'thumbnail' => (string) $thumbnailinfo['url'],
'thumbnail_width' => 72, // 72 is the native maximum dimension.
'thumbnail_height' => 72,
'source' => (string) $fullinfo['url'],
'url' => (string) $fullinfo['url']
);
}
return $files;
}
|
[
"public",
"function",
"get_photo_details",
"(",
"$",
"rawxml",
")",
"{",
"$",
"files",
"=",
"array",
"(",
")",
";",
"try",
"{",
"if",
"(",
"strpos",
"(",
"$",
"rawxml",
",",
"'<?xml'",
")",
"!==",
"0",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'invalidxmlresponse'",
")",
";",
"}",
"$",
"xml",
"=",
"new",
"SimpleXMLElement",
"(",
"$",
"rawxml",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"// An error occured while trying to parse the XML, let's just return nothing. SimpleXML does not",
"// return a more specific Exception, that's why the global Exception class is caught here.",
"return",
"$",
"files",
";",
"}",
"$",
"this",
"->",
"lastalbumname",
"=",
"(",
"string",
")",
"$",
"xml",
"->",
"title",
";",
"foreach",
"(",
"$",
"xml",
"->",
"entry",
"as",
"$",
"photo",
")",
"{",
"$",
"gphoto",
"=",
"$",
"photo",
"->",
"children",
"(",
"'http://schemas.google.com/photos/2007'",
")",
";",
"$",
"mediainfo",
"=",
"$",
"photo",
"->",
"children",
"(",
"'http://search.yahoo.com/mrss/'",
")",
";",
"$",
"fullinfo",
"=",
"$",
"mediainfo",
"->",
"group",
"->",
"content",
"->",
"attributes",
"(",
")",
";",
"// Hacky...",
"$",
"thumbnailinfo",
"=",
"$",
"mediainfo",
"->",
"group",
"->",
"thumbnail",
"[",
"0",
"]",
"->",
"attributes",
"(",
")",
";",
"// Derive the nicest file name we can.",
"if",
"(",
"!",
"empty",
"(",
"$",
"mediainfo",
"->",
"group",
"->",
"description",
")",
")",
"{",
"$",
"title",
"=",
"shorten_text",
"(",
"(",
"string",
")",
"$",
"mediainfo",
"->",
"group",
"->",
"description",
",",
"20",
",",
"false",
",",
"''",
")",
";",
"$",
"title",
"=",
"clean_filename",
"(",
"$",
"title",
")",
".",
"'.jpg'",
";",
"}",
"else",
"{",
"$",
"title",
"=",
"(",
"string",
")",
"$",
"mediainfo",
"->",
"group",
"->",
"title",
";",
"}",
"$",
"files",
"[",
"]",
"=",
"array",
"(",
"'title'",
"=>",
"$",
"title",
",",
"'date'",
"=>",
"userdate",
"(",
"$",
"gphoto",
"->",
"timestamp",
")",
",",
"'size'",
"=>",
"(",
"int",
")",
"$",
"gphoto",
"->",
"size",
",",
"'path'",
"=>",
"$",
"gphoto",
"->",
"albumid",
".",
"'/'",
".",
"$",
"gphoto",
"->",
"id",
",",
"'thumbnail'",
"=>",
"(",
"string",
")",
"$",
"thumbnailinfo",
"[",
"'url'",
"]",
",",
"'thumbnail_width'",
"=>",
"72",
",",
"// 72 is the native maximum dimension.",
"'thumbnail_height'",
"=>",
"72",
",",
"'source'",
"=>",
"(",
"string",
")",
"$",
"fullinfo",
"[",
"'url'",
"]",
",",
"'url'",
"=>",
"(",
"string",
")",
"$",
"fullinfo",
"[",
"'url'",
"]",
")",
";",
"}",
"return",
"$",
"files",
";",
"}"
] |
Recieves XML from a picasa list of photos and returns
array in format for file picker.
@param string $rawxml XML from picasa api
@return mixed $files A list of files for the file picker
|
[
"Recieves",
"XML",
"from",
"a",
"picasa",
"list",
"of",
"photos",
"and",
"returns",
"array",
"in",
"format",
"for",
"file",
"picker",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/googleapi.php#L372-L417
|
217,582
|
moodle/moodle
|
lib/mustache/src/Mustache/Cache/FilesystemCache.php
|
Mustache_Cache_FilesystemCache.load
|
public function load($key)
{
$fileName = $this->getCacheFilename($key);
if (!is_file($fileName)) {
return false;
}
require_once $fileName;
return true;
}
|
php
|
public function load($key)
{
$fileName = $this->getCacheFilename($key);
if (!is_file($fileName)) {
return false;
}
require_once $fileName;
return true;
}
|
[
"public",
"function",
"load",
"(",
"$",
"key",
")",
"{",
"$",
"fileName",
"=",
"$",
"this",
"->",
"getCacheFilename",
"(",
"$",
"key",
")",
";",
"if",
"(",
"!",
"is_file",
"(",
"$",
"fileName",
")",
")",
"{",
"return",
"false",
";",
"}",
"require_once",
"$",
"fileName",
";",
"return",
"true",
";",
"}"
] |
Load the class from cache using `require_once`.
@param string $key
@return bool
|
[
"Load",
"the",
"class",
"from",
"cache",
"using",
"require_once",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Cache/FilesystemCache.php#L46-L56
|
217,583
|
moodle/moodle
|
lib/mustache/src/Mustache/Cache/FilesystemCache.php
|
Mustache_Cache_FilesystemCache.cache
|
public function cache($key, $value)
{
$fileName = $this->getCacheFilename($key);
$this->log(
Mustache_Logger::DEBUG,
'Writing to template cache: "{fileName}"',
array('fileName' => $fileName)
);
$this->writeFile($fileName, $value);
$this->load($key);
}
|
php
|
public function cache($key, $value)
{
$fileName = $this->getCacheFilename($key);
$this->log(
Mustache_Logger::DEBUG,
'Writing to template cache: "{fileName}"',
array('fileName' => $fileName)
);
$this->writeFile($fileName, $value);
$this->load($key);
}
|
[
"public",
"function",
"cache",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"fileName",
"=",
"$",
"this",
"->",
"getCacheFilename",
"(",
"$",
"key",
")",
";",
"$",
"this",
"->",
"log",
"(",
"Mustache_Logger",
"::",
"DEBUG",
",",
"'Writing to template cache: \"{fileName}\"'",
",",
"array",
"(",
"'fileName'",
"=>",
"$",
"fileName",
")",
")",
";",
"$",
"this",
"->",
"writeFile",
"(",
"$",
"fileName",
",",
"$",
"value",
")",
";",
"$",
"this",
"->",
"load",
"(",
"$",
"key",
")",
";",
"}"
] |
Cache and load the compiled class.
@param string $key
@param string $value
|
[
"Cache",
"and",
"load",
"the",
"compiled",
"class",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Cache/FilesystemCache.php#L64-L76
|
217,584
|
moodle/moodle
|
lib/mustache/src/Mustache/Cache/FilesystemCache.php
|
Mustache_Cache_FilesystemCache.buildDirectoryForFilename
|
private function buildDirectoryForFilename($fileName)
{
$dirName = dirname($fileName);
if (!is_dir($dirName)) {
$this->log(
Mustache_Logger::INFO,
'Creating Mustache template cache directory: "{dirName}"',
array('dirName' => $dirName)
);
@mkdir($dirName, 0777, true);
// @codeCoverageIgnoreStart
if (!is_dir($dirName)) {
throw new Mustache_Exception_RuntimeException(sprintf('Failed to create cache directory "%s".', $dirName));
}
// @codeCoverageIgnoreEnd
}
return $dirName;
}
|
php
|
private function buildDirectoryForFilename($fileName)
{
$dirName = dirname($fileName);
if (!is_dir($dirName)) {
$this->log(
Mustache_Logger::INFO,
'Creating Mustache template cache directory: "{dirName}"',
array('dirName' => $dirName)
);
@mkdir($dirName, 0777, true);
// @codeCoverageIgnoreStart
if (!is_dir($dirName)) {
throw new Mustache_Exception_RuntimeException(sprintf('Failed to create cache directory "%s".', $dirName));
}
// @codeCoverageIgnoreEnd
}
return $dirName;
}
|
[
"private",
"function",
"buildDirectoryForFilename",
"(",
"$",
"fileName",
")",
"{",
"$",
"dirName",
"=",
"dirname",
"(",
"$",
"fileName",
")",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dirName",
")",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"Mustache_Logger",
"::",
"INFO",
",",
"'Creating Mustache template cache directory: \"{dirName}\"'",
",",
"array",
"(",
"'dirName'",
"=>",
"$",
"dirName",
")",
")",
";",
"@",
"mkdir",
"(",
"$",
"dirName",
",",
"0777",
",",
"true",
")",
";",
"// @codeCoverageIgnoreStart",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dirName",
")",
")",
"{",
"throw",
"new",
"Mustache_Exception_RuntimeException",
"(",
"sprintf",
"(",
"'Failed to create cache directory \"%s\".'",
",",
"$",
"dirName",
")",
")",
";",
"}",
"// @codeCoverageIgnoreEnd",
"}",
"return",
"$",
"dirName",
";",
"}"
] |
Create cache directory.
@throws Mustache_Exception_RuntimeException If unable to create directory
@param string $fileName
@return string
|
[
"Create",
"cache",
"directory",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Cache/FilesystemCache.php#L100-L119
|
217,585
|
moodle/moodle
|
lib/mustache/src/Mustache/Cache/FilesystemCache.php
|
Mustache_Cache_FilesystemCache.writeFile
|
private function writeFile($fileName, $value)
{
$dirName = $this->buildDirectoryForFilename($fileName);
$this->log(
Mustache_Logger::DEBUG,
'Caching compiled template to "{fileName}"',
array('fileName' => $fileName)
);
$tempFile = tempnam($dirName, basename($fileName));
if (false !== @file_put_contents($tempFile, $value)) {
if (@rename($tempFile, $fileName)) {
$mode = isset($this->fileMode) ? $this->fileMode : (0666 & ~umask());
@chmod($fileName, $mode);
return;
}
// @codeCoverageIgnoreStart
$this->log(
Mustache_Logger::ERROR,
'Unable to rename Mustache temp cache file: "{tempName}" -> "{fileName}"',
array('tempName' => $tempFile, 'fileName' => $fileName)
);
// @codeCoverageIgnoreEnd
}
// @codeCoverageIgnoreStart
throw new Mustache_Exception_RuntimeException(sprintf('Failed to write cache file "%s".', $fileName));
// @codeCoverageIgnoreEnd
}
|
php
|
private function writeFile($fileName, $value)
{
$dirName = $this->buildDirectoryForFilename($fileName);
$this->log(
Mustache_Logger::DEBUG,
'Caching compiled template to "{fileName}"',
array('fileName' => $fileName)
);
$tempFile = tempnam($dirName, basename($fileName));
if (false !== @file_put_contents($tempFile, $value)) {
if (@rename($tempFile, $fileName)) {
$mode = isset($this->fileMode) ? $this->fileMode : (0666 & ~umask());
@chmod($fileName, $mode);
return;
}
// @codeCoverageIgnoreStart
$this->log(
Mustache_Logger::ERROR,
'Unable to rename Mustache temp cache file: "{tempName}" -> "{fileName}"',
array('tempName' => $tempFile, 'fileName' => $fileName)
);
// @codeCoverageIgnoreEnd
}
// @codeCoverageIgnoreStart
throw new Mustache_Exception_RuntimeException(sprintf('Failed to write cache file "%s".', $fileName));
// @codeCoverageIgnoreEnd
}
|
[
"private",
"function",
"writeFile",
"(",
"$",
"fileName",
",",
"$",
"value",
")",
"{",
"$",
"dirName",
"=",
"$",
"this",
"->",
"buildDirectoryForFilename",
"(",
"$",
"fileName",
")",
";",
"$",
"this",
"->",
"log",
"(",
"Mustache_Logger",
"::",
"DEBUG",
",",
"'Caching compiled template to \"{fileName}\"'",
",",
"array",
"(",
"'fileName'",
"=>",
"$",
"fileName",
")",
")",
";",
"$",
"tempFile",
"=",
"tempnam",
"(",
"$",
"dirName",
",",
"basename",
"(",
"$",
"fileName",
")",
")",
";",
"if",
"(",
"false",
"!==",
"@",
"file_put_contents",
"(",
"$",
"tempFile",
",",
"$",
"value",
")",
")",
"{",
"if",
"(",
"@",
"rename",
"(",
"$",
"tempFile",
",",
"$",
"fileName",
")",
")",
"{",
"$",
"mode",
"=",
"isset",
"(",
"$",
"this",
"->",
"fileMode",
")",
"?",
"$",
"this",
"->",
"fileMode",
":",
"(",
"0666",
"&",
"~",
"umask",
"(",
")",
")",
";",
"@",
"chmod",
"(",
"$",
"fileName",
",",
"$",
"mode",
")",
";",
"return",
";",
"}",
"// @codeCoverageIgnoreStart",
"$",
"this",
"->",
"log",
"(",
"Mustache_Logger",
"::",
"ERROR",
",",
"'Unable to rename Mustache temp cache file: \"{tempName}\" -> \"{fileName}\"'",
",",
"array",
"(",
"'tempName'",
"=>",
"$",
"tempFile",
",",
"'fileName'",
"=>",
"$",
"fileName",
")",
")",
";",
"// @codeCoverageIgnoreEnd",
"}",
"// @codeCoverageIgnoreStart",
"throw",
"new",
"Mustache_Exception_RuntimeException",
"(",
"sprintf",
"(",
"'Failed to write cache file \"%s\".'",
",",
"$",
"fileName",
")",
")",
";",
"// @codeCoverageIgnoreEnd",
"}"
] |
Write cache file.
@throws Mustache_Exception_RuntimeException If unable to write file
@param string $fileName
@param string $value
|
[
"Write",
"cache",
"file",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Cache/FilesystemCache.php#L129-L160
|
217,586
|
moodle/moodle
|
backup/util/dbops/restore_dbops.class.php
|
restore_dbops.load_inforef_to_tempids
|
public static function load_inforef_to_tempids($restoreid, $inforeffile,
\core\progress\base $progress = null) {
if (!file_exists($inforeffile)) { // Shouldn't happen ever, but...
throw new backup_helper_exception('missing_inforef_xml_file', $inforeffile);
}
// Set up progress tracking (indeterminate).
if (!$progress) {
$progress = new \core\progress\none();
}
$progress->start_progress('Loading inforef.xml file');
// Let's parse, custom processor will do its work, sending info to DB
$xmlparser = new progressive_parser();
$xmlparser->set_file($inforeffile);
$xmlprocessor = new restore_inforef_parser_processor($restoreid);
$xmlparser->set_processor($xmlprocessor);
$xmlparser->set_progress($progress);
$xmlparser->process();
// Finish progress
$progress->end_progress();
}
|
php
|
public static function load_inforef_to_tempids($restoreid, $inforeffile,
\core\progress\base $progress = null) {
if (!file_exists($inforeffile)) { // Shouldn't happen ever, but...
throw new backup_helper_exception('missing_inforef_xml_file', $inforeffile);
}
// Set up progress tracking (indeterminate).
if (!$progress) {
$progress = new \core\progress\none();
}
$progress->start_progress('Loading inforef.xml file');
// Let's parse, custom processor will do its work, sending info to DB
$xmlparser = new progressive_parser();
$xmlparser->set_file($inforeffile);
$xmlprocessor = new restore_inforef_parser_processor($restoreid);
$xmlparser->set_processor($xmlprocessor);
$xmlparser->set_progress($progress);
$xmlparser->process();
// Finish progress
$progress->end_progress();
}
|
[
"public",
"static",
"function",
"load_inforef_to_tempids",
"(",
"$",
"restoreid",
",",
"$",
"inforeffile",
",",
"\\",
"core",
"\\",
"progress",
"\\",
"base",
"$",
"progress",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"inforeffile",
")",
")",
"{",
"// Shouldn't happen ever, but...",
"throw",
"new",
"backup_helper_exception",
"(",
"'missing_inforef_xml_file'",
",",
"$",
"inforeffile",
")",
";",
"}",
"// Set up progress tracking (indeterminate).",
"if",
"(",
"!",
"$",
"progress",
")",
"{",
"$",
"progress",
"=",
"new",
"\\",
"core",
"\\",
"progress",
"\\",
"none",
"(",
")",
";",
"}",
"$",
"progress",
"->",
"start_progress",
"(",
"'Loading inforef.xml file'",
")",
";",
"// Let's parse, custom processor will do its work, sending info to DB",
"$",
"xmlparser",
"=",
"new",
"progressive_parser",
"(",
")",
";",
"$",
"xmlparser",
"->",
"set_file",
"(",
"$",
"inforeffile",
")",
";",
"$",
"xmlprocessor",
"=",
"new",
"restore_inforef_parser_processor",
"(",
"$",
"restoreid",
")",
";",
"$",
"xmlparser",
"->",
"set_processor",
"(",
"$",
"xmlprocessor",
")",
";",
"$",
"xmlparser",
"->",
"set_progress",
"(",
"$",
"progress",
")",
";",
"$",
"xmlparser",
"->",
"process",
"(",
")",
";",
"// Finish progress",
"$",
"progress",
"->",
"end_progress",
"(",
")",
";",
"}"
] |
Load one inforef.xml file to backup_ids table for future reference
@param string $restoreid Restore id
@param string $inforeffile File path
@param \core\progress\base $progress Progress tracker
|
[
"Load",
"one",
"inforef",
".",
"xml",
"file",
"to",
"backup_ids",
"table",
"for",
"future",
"reference"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/dbops/restore_dbops.class.php#L119-L142
|
217,587
|
moodle/moodle
|
backup/util/dbops/restore_dbops.class.php
|
restore_dbops.load_roles_to_tempids
|
public static function load_roles_to_tempids($restoreid, $rolesfile) {
if (!file_exists($rolesfile)) { // Shouldn't happen ever, but...
throw new backup_helper_exception('missing_roles_xml_file', $rolesfile);
}
// Let's parse, custom processor will do its work, sending info to DB
$xmlparser = new progressive_parser();
$xmlparser->set_file($rolesfile);
$xmlprocessor = new restore_roles_parser_processor($restoreid);
$xmlparser->set_processor($xmlprocessor);
$xmlparser->process();
}
|
php
|
public static function load_roles_to_tempids($restoreid, $rolesfile) {
if (!file_exists($rolesfile)) { // Shouldn't happen ever, but...
throw new backup_helper_exception('missing_roles_xml_file', $rolesfile);
}
// Let's parse, custom processor will do its work, sending info to DB
$xmlparser = new progressive_parser();
$xmlparser->set_file($rolesfile);
$xmlprocessor = new restore_roles_parser_processor($restoreid);
$xmlparser->set_processor($xmlprocessor);
$xmlparser->process();
}
|
[
"public",
"static",
"function",
"load_roles_to_tempids",
"(",
"$",
"restoreid",
",",
"$",
"rolesfile",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"rolesfile",
")",
")",
"{",
"// Shouldn't happen ever, but...",
"throw",
"new",
"backup_helper_exception",
"(",
"'missing_roles_xml_file'",
",",
"$",
"rolesfile",
")",
";",
"}",
"// Let's parse, custom processor will do its work, sending info to DB",
"$",
"xmlparser",
"=",
"new",
"progressive_parser",
"(",
")",
";",
"$",
"xmlparser",
"->",
"set_file",
"(",
"$",
"rolesfile",
")",
";",
"$",
"xmlprocessor",
"=",
"new",
"restore_roles_parser_processor",
"(",
"$",
"restoreid",
")",
";",
"$",
"xmlparser",
"->",
"set_processor",
"(",
"$",
"xmlprocessor",
")",
";",
"$",
"xmlparser",
"->",
"process",
"(",
")",
";",
"}"
] |
Load the needed role.xml file to backup_ids table for future reference
|
[
"Load",
"the",
"needed",
"role",
".",
"xml",
"file",
"to",
"backup_ids",
"table",
"for",
"future",
"reference"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/dbops/restore_dbops.class.php#L147-L158
|
217,588
|
moodle/moodle
|
backup/util/dbops/restore_dbops.class.php
|
restore_dbops.get_backup_ids_cached
|
protected static function get_backup_ids_cached($restoreid, $itemname, $itemid) {
global $DB;
$key = "$itemid $itemname $restoreid";
// If record exists in cache then return.
if (isset(self::$backupidsexist[$key]) && isset(self::$backupidscache[$key])) {
// Return a copy of cached data, to avoid any alterations in cached data.
return clone self::$backupidscache[$key];
}
// Clean cache, if it's full.
if (self::$backupidscachesize <= 0) {
// Remove some records, to keep memory in limit.
self::$backupidscache = array_slice(self::$backupidscache, self::$backupidsslice, null, true);
self::$backupidscachesize = self::$backupidscachesize + self::$backupidsslice;
}
if (self::$backupidsexistsize <= 0) {
self::$backupidsexist = array_slice(self::$backupidsexist, self::$backupidsslice, null, true);
self::$backupidsexistsize = self::$backupidsexistsize + self::$backupidsslice;
}
// Retrive record from database.
$record = array(
'backupid' => $restoreid,
'itemname' => $itemname,
'itemid' => $itemid
);
if ($dbrec = $DB->get_record('backup_ids_temp', $record)) {
self::$backupidsexist[$key] = $dbrec->id;
self::$backupidscache[$key] = $dbrec;
self::$backupidscachesize--;
self::$backupidsexistsize--;
return $dbrec;
} else {
return false;
}
}
|
php
|
protected static function get_backup_ids_cached($restoreid, $itemname, $itemid) {
global $DB;
$key = "$itemid $itemname $restoreid";
// If record exists in cache then return.
if (isset(self::$backupidsexist[$key]) && isset(self::$backupidscache[$key])) {
// Return a copy of cached data, to avoid any alterations in cached data.
return clone self::$backupidscache[$key];
}
// Clean cache, if it's full.
if (self::$backupidscachesize <= 0) {
// Remove some records, to keep memory in limit.
self::$backupidscache = array_slice(self::$backupidscache, self::$backupidsslice, null, true);
self::$backupidscachesize = self::$backupidscachesize + self::$backupidsslice;
}
if (self::$backupidsexistsize <= 0) {
self::$backupidsexist = array_slice(self::$backupidsexist, self::$backupidsslice, null, true);
self::$backupidsexistsize = self::$backupidsexistsize + self::$backupidsslice;
}
// Retrive record from database.
$record = array(
'backupid' => $restoreid,
'itemname' => $itemname,
'itemid' => $itemid
);
if ($dbrec = $DB->get_record('backup_ids_temp', $record)) {
self::$backupidsexist[$key] = $dbrec->id;
self::$backupidscache[$key] = $dbrec;
self::$backupidscachesize--;
self::$backupidsexistsize--;
return $dbrec;
} else {
return false;
}
}
|
[
"protected",
"static",
"function",
"get_backup_ids_cached",
"(",
"$",
"restoreid",
",",
"$",
"itemname",
",",
"$",
"itemid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"key",
"=",
"\"$itemid $itemname $restoreid\"",
";",
"// If record exists in cache then return.",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"backupidsexist",
"[",
"$",
"key",
"]",
")",
"&&",
"isset",
"(",
"self",
"::",
"$",
"backupidscache",
"[",
"$",
"key",
"]",
")",
")",
"{",
"// Return a copy of cached data, to avoid any alterations in cached data.",
"return",
"clone",
"self",
"::",
"$",
"backupidscache",
"[",
"$",
"key",
"]",
";",
"}",
"// Clean cache, if it's full.",
"if",
"(",
"self",
"::",
"$",
"backupidscachesize",
"<=",
"0",
")",
"{",
"// Remove some records, to keep memory in limit.",
"self",
"::",
"$",
"backupidscache",
"=",
"array_slice",
"(",
"self",
"::",
"$",
"backupidscache",
",",
"self",
"::",
"$",
"backupidsslice",
",",
"null",
",",
"true",
")",
";",
"self",
"::",
"$",
"backupidscachesize",
"=",
"self",
"::",
"$",
"backupidscachesize",
"+",
"self",
"::",
"$",
"backupidsslice",
";",
"}",
"if",
"(",
"self",
"::",
"$",
"backupidsexistsize",
"<=",
"0",
")",
"{",
"self",
"::",
"$",
"backupidsexist",
"=",
"array_slice",
"(",
"self",
"::",
"$",
"backupidsexist",
",",
"self",
"::",
"$",
"backupidsslice",
",",
"null",
",",
"true",
")",
";",
"self",
"::",
"$",
"backupidsexistsize",
"=",
"self",
"::",
"$",
"backupidsexistsize",
"+",
"self",
"::",
"$",
"backupidsslice",
";",
"}",
"// Retrive record from database.",
"$",
"record",
"=",
"array",
"(",
"'backupid'",
"=>",
"$",
"restoreid",
",",
"'itemname'",
"=>",
"$",
"itemname",
",",
"'itemid'",
"=>",
"$",
"itemid",
")",
";",
"if",
"(",
"$",
"dbrec",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'backup_ids_temp'",
",",
"$",
"record",
")",
")",
"{",
"self",
"::",
"$",
"backupidsexist",
"[",
"$",
"key",
"]",
"=",
"$",
"dbrec",
"->",
"id",
";",
"self",
"::",
"$",
"backupidscache",
"[",
"$",
"key",
"]",
"=",
"$",
"dbrec",
";",
"self",
"::",
"$",
"backupidscachesize",
"--",
";",
"self",
"::",
"$",
"backupidsexistsize",
"--",
";",
"return",
"$",
"dbrec",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] |
Return cached backup id's
@param int $restoreid id of backup
@param string $itemname name of the item
@param int $itemid id of item
@return array backup id's
@todo MDL-25290 replace static backupids* with MUC code
|
[
"Return",
"cached",
"backup",
"id",
"s"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/dbops/restore_dbops.class.php#L212-L249
|
217,589
|
moodle/moodle
|
backup/util/dbops/restore_dbops.class.php
|
restore_dbops.set_backup_ids_cached
|
protected static function set_backup_ids_cached($restoreid, $itemname, $itemid, $extrarecord) {
global $DB;
$key = "$itemid $itemname $restoreid";
$record = array(
'backupid' => $restoreid,
'itemname' => $itemname,
'itemid' => $itemid,
);
// If record is not cached then add one.
if (!isset(self::$backupidsexist[$key])) {
// If we have this record in db, then just update this.
if ($existingrecord = $DB->get_record('backup_ids_temp', $record)) {
self::$backupidsexist[$key] = $existingrecord->id;
self::$backupidsexistsize--;
self::update_backup_cached_record($record, $extrarecord, $key, $existingrecord);
} else {
// Add new record to cache and db.
$recorddefault = array (
'newitemid' => 0,
'parentitemid' => null,
'info' => null);
$record = array_merge($record, $recorddefault, $extrarecord);
$record['id'] = $DB->insert_record('backup_ids_temp', $record);
self::$backupidsexist[$key] = $record['id'];
self::$backupidsexistsize--;
if (self::$backupidscachesize > 0) {
// Cache new records if we haven't got many yet.
self::$backupidscache[$key] = (object) $record;
self::$backupidscachesize--;
}
}
} else {
self::update_backup_cached_record($record, $extrarecord, $key);
}
}
|
php
|
protected static function set_backup_ids_cached($restoreid, $itemname, $itemid, $extrarecord) {
global $DB;
$key = "$itemid $itemname $restoreid";
$record = array(
'backupid' => $restoreid,
'itemname' => $itemname,
'itemid' => $itemid,
);
// If record is not cached then add one.
if (!isset(self::$backupidsexist[$key])) {
// If we have this record in db, then just update this.
if ($existingrecord = $DB->get_record('backup_ids_temp', $record)) {
self::$backupidsexist[$key] = $existingrecord->id;
self::$backupidsexistsize--;
self::update_backup_cached_record($record, $extrarecord, $key, $existingrecord);
} else {
// Add new record to cache and db.
$recorddefault = array (
'newitemid' => 0,
'parentitemid' => null,
'info' => null);
$record = array_merge($record, $recorddefault, $extrarecord);
$record['id'] = $DB->insert_record('backup_ids_temp', $record);
self::$backupidsexist[$key] = $record['id'];
self::$backupidsexistsize--;
if (self::$backupidscachesize > 0) {
// Cache new records if we haven't got many yet.
self::$backupidscache[$key] = (object) $record;
self::$backupidscachesize--;
}
}
} else {
self::update_backup_cached_record($record, $extrarecord, $key);
}
}
|
[
"protected",
"static",
"function",
"set_backup_ids_cached",
"(",
"$",
"restoreid",
",",
"$",
"itemname",
",",
"$",
"itemid",
",",
"$",
"extrarecord",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"key",
"=",
"\"$itemid $itemname $restoreid\"",
";",
"$",
"record",
"=",
"array",
"(",
"'backupid'",
"=>",
"$",
"restoreid",
",",
"'itemname'",
"=>",
"$",
"itemname",
",",
"'itemid'",
"=>",
"$",
"itemid",
",",
")",
";",
"// If record is not cached then add one.",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"backupidsexist",
"[",
"$",
"key",
"]",
")",
")",
"{",
"// If we have this record in db, then just update this.",
"if",
"(",
"$",
"existingrecord",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'backup_ids_temp'",
",",
"$",
"record",
")",
")",
"{",
"self",
"::",
"$",
"backupidsexist",
"[",
"$",
"key",
"]",
"=",
"$",
"existingrecord",
"->",
"id",
";",
"self",
"::",
"$",
"backupidsexistsize",
"--",
";",
"self",
"::",
"update_backup_cached_record",
"(",
"$",
"record",
",",
"$",
"extrarecord",
",",
"$",
"key",
",",
"$",
"existingrecord",
")",
";",
"}",
"else",
"{",
"// Add new record to cache and db.",
"$",
"recorddefault",
"=",
"array",
"(",
"'newitemid'",
"=>",
"0",
",",
"'parentitemid'",
"=>",
"null",
",",
"'info'",
"=>",
"null",
")",
";",
"$",
"record",
"=",
"array_merge",
"(",
"$",
"record",
",",
"$",
"recorddefault",
",",
"$",
"extrarecord",
")",
";",
"$",
"record",
"[",
"'id'",
"]",
"=",
"$",
"DB",
"->",
"insert_record",
"(",
"'backup_ids_temp'",
",",
"$",
"record",
")",
";",
"self",
"::",
"$",
"backupidsexist",
"[",
"$",
"key",
"]",
"=",
"$",
"record",
"[",
"'id'",
"]",
";",
"self",
"::",
"$",
"backupidsexistsize",
"--",
";",
"if",
"(",
"self",
"::",
"$",
"backupidscachesize",
">",
"0",
")",
"{",
"// Cache new records if we haven't got many yet.",
"self",
"::",
"$",
"backupidscache",
"[",
"$",
"key",
"]",
"=",
"(",
"object",
")",
"$",
"record",
";",
"self",
"::",
"$",
"backupidscachesize",
"--",
";",
"}",
"}",
"}",
"else",
"{",
"self",
"::",
"update_backup_cached_record",
"(",
"$",
"record",
",",
"$",
"extrarecord",
",",
"$",
"key",
")",
";",
"}",
"}"
] |
Cache backup ids'
@param int $restoreid id of backup
@param string $itemname name of the item
@param int $itemid id of item
@param array $extrarecord extra record which needs to be updated
@return void
@todo MDL-25290 replace static BACKUP_IDS_* with MUC code
|
[
"Cache",
"backup",
"ids"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/dbops/restore_dbops.class.php#L261-L298
|
217,590
|
moodle/moodle
|
backup/util/dbops/restore_dbops.class.php
|
restore_dbops.update_backup_cached_record
|
protected static function update_backup_cached_record($record, $extrarecord, $key, $existingrecord = null) {
global $DB;
// Update only if extrarecord is not empty.
if (!empty($extrarecord)) {
$extrarecord['id'] = self::$backupidsexist[$key];
$DB->update_record('backup_ids_temp', $extrarecord);
// Update existing cache or add new record to cache.
if (isset(self::$backupidscache[$key])) {
$record = array_merge((array)self::$backupidscache[$key], $extrarecord);
self::$backupidscache[$key] = (object) $record;
} else if (self::$backupidscachesize > 0) {
if ($existingrecord) {
self::$backupidscache[$key] = $existingrecord;
} else {
// Retrive record from database and cache updated records.
self::$backupidscache[$key] = $DB->get_record('backup_ids_temp', $record);
}
$record = array_merge((array)self::$backupidscache[$key], $extrarecord);
self::$backupidscache[$key] = (object) $record;
self::$backupidscachesize--;
}
}
}
|
php
|
protected static function update_backup_cached_record($record, $extrarecord, $key, $existingrecord = null) {
global $DB;
// Update only if extrarecord is not empty.
if (!empty($extrarecord)) {
$extrarecord['id'] = self::$backupidsexist[$key];
$DB->update_record('backup_ids_temp', $extrarecord);
// Update existing cache or add new record to cache.
if (isset(self::$backupidscache[$key])) {
$record = array_merge((array)self::$backupidscache[$key], $extrarecord);
self::$backupidscache[$key] = (object) $record;
} else if (self::$backupidscachesize > 0) {
if ($existingrecord) {
self::$backupidscache[$key] = $existingrecord;
} else {
// Retrive record from database and cache updated records.
self::$backupidscache[$key] = $DB->get_record('backup_ids_temp', $record);
}
$record = array_merge((array)self::$backupidscache[$key], $extrarecord);
self::$backupidscache[$key] = (object) $record;
self::$backupidscachesize--;
}
}
}
|
[
"protected",
"static",
"function",
"update_backup_cached_record",
"(",
"$",
"record",
",",
"$",
"extrarecord",
",",
"$",
"key",
",",
"$",
"existingrecord",
"=",
"null",
")",
"{",
"global",
"$",
"DB",
";",
"// Update only if extrarecord is not empty.",
"if",
"(",
"!",
"empty",
"(",
"$",
"extrarecord",
")",
")",
"{",
"$",
"extrarecord",
"[",
"'id'",
"]",
"=",
"self",
"::",
"$",
"backupidsexist",
"[",
"$",
"key",
"]",
";",
"$",
"DB",
"->",
"update_record",
"(",
"'backup_ids_temp'",
",",
"$",
"extrarecord",
")",
";",
"// Update existing cache or add new record to cache.",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"backupidscache",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"record",
"=",
"array_merge",
"(",
"(",
"array",
")",
"self",
"::",
"$",
"backupidscache",
"[",
"$",
"key",
"]",
",",
"$",
"extrarecord",
")",
";",
"self",
"::",
"$",
"backupidscache",
"[",
"$",
"key",
"]",
"=",
"(",
"object",
")",
"$",
"record",
";",
"}",
"else",
"if",
"(",
"self",
"::",
"$",
"backupidscachesize",
">",
"0",
")",
"{",
"if",
"(",
"$",
"existingrecord",
")",
"{",
"self",
"::",
"$",
"backupidscache",
"[",
"$",
"key",
"]",
"=",
"$",
"existingrecord",
";",
"}",
"else",
"{",
"// Retrive record from database and cache updated records.",
"self",
"::",
"$",
"backupidscache",
"[",
"$",
"key",
"]",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'backup_ids_temp'",
",",
"$",
"record",
")",
";",
"}",
"$",
"record",
"=",
"array_merge",
"(",
"(",
"array",
")",
"self",
"::",
"$",
"backupidscache",
"[",
"$",
"key",
"]",
",",
"$",
"extrarecord",
")",
";",
"self",
"::",
"$",
"backupidscache",
"[",
"$",
"key",
"]",
"=",
"(",
"object",
")",
"$",
"record",
";",
"self",
"::",
"$",
"backupidscachesize",
"--",
";",
"}",
"}",
"}"
] |
Updates existing backup record
@param array $record record which needs to be updated
@param array $extrarecord extra record which needs to be updated
@param string $key unique key which is used to identify cached record
@param stdClass $existingrecord (optional) existing record
|
[
"Updates",
"existing",
"backup",
"record"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/dbops/restore_dbops.class.php#L308-L330
|
217,591
|
moodle/moodle
|
backup/util/dbops/restore_dbops.class.php
|
restore_dbops.reset_backup_ids_cached
|
public static function reset_backup_ids_cached() {
// Reset the ids cache.
$cachetoadd = count(self::$backupidscache);
self::$backupidscache = array();
self::$backupidscachesize = self::$backupidscachesize + $cachetoadd;
// Reset the exists cache.
$existstoadd = count(self::$backupidsexist);
self::$backupidsexist = array();
self::$backupidsexistsize = self::$backupidsexistsize + $existstoadd;
}
|
php
|
public static function reset_backup_ids_cached() {
// Reset the ids cache.
$cachetoadd = count(self::$backupidscache);
self::$backupidscache = array();
self::$backupidscachesize = self::$backupidscachesize + $cachetoadd;
// Reset the exists cache.
$existstoadd = count(self::$backupidsexist);
self::$backupidsexist = array();
self::$backupidsexistsize = self::$backupidsexistsize + $existstoadd;
}
|
[
"public",
"static",
"function",
"reset_backup_ids_cached",
"(",
")",
"{",
"// Reset the ids cache.",
"$",
"cachetoadd",
"=",
"count",
"(",
"self",
"::",
"$",
"backupidscache",
")",
";",
"self",
"::",
"$",
"backupidscache",
"=",
"array",
"(",
")",
";",
"self",
"::",
"$",
"backupidscachesize",
"=",
"self",
"::",
"$",
"backupidscachesize",
"+",
"$",
"cachetoadd",
";",
"// Reset the exists cache.",
"$",
"existstoadd",
"=",
"count",
"(",
"self",
"::",
"$",
"backupidsexist",
")",
";",
"self",
"::",
"$",
"backupidsexist",
"=",
"array",
"(",
")",
";",
"self",
"::",
"$",
"backupidsexistsize",
"=",
"self",
"::",
"$",
"backupidsexistsize",
"+",
"$",
"existstoadd",
";",
"}"
] |
Reset the ids caches completely
Any destructive operation (partial delete, truncate, drop or recreate) performed
with the backup_ids table must cause the backup_ids caches to be
invalidated by calling this method. See MDL-33630.
Note that right now, the only operation of that type is the recreation
(drop & restore) of the table that may happen once the prechecks have ended. All
the rest of operations are always routed via {@link set_backup_ids_record()}, 1 by 1,
keeping the caches on sync.
@todo MDL-25290 static should be replaced with MUC code.
|
[
"Reset",
"the",
"ids",
"caches",
"completely"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/dbops/restore_dbops.class.php#L346-L355
|
217,592
|
moodle/moodle
|
backup/util/dbops/restore_dbops.class.php
|
restore_dbops.load_users_to_tempids
|
public static function load_users_to_tempids($restoreid, $usersfile,
\core\progress\base $progress = null) {
if (!file_exists($usersfile)) { // Shouldn't happen ever, but...
throw new backup_helper_exception('missing_users_xml_file', $usersfile);
}
// Set up progress tracking (indeterminate).
if (!$progress) {
$progress = new \core\progress\none();
}
$progress->start_progress('Loading users into temporary table');
// Let's parse, custom processor will do its work, sending info to DB
$xmlparser = new progressive_parser();
$xmlparser->set_file($usersfile);
$xmlprocessor = new restore_users_parser_processor($restoreid);
$xmlparser->set_processor($xmlprocessor);
$xmlparser->set_progress($progress);
$xmlparser->process();
// Finish progress.
$progress->end_progress();
}
|
php
|
public static function load_users_to_tempids($restoreid, $usersfile,
\core\progress\base $progress = null) {
if (!file_exists($usersfile)) { // Shouldn't happen ever, but...
throw new backup_helper_exception('missing_users_xml_file', $usersfile);
}
// Set up progress tracking (indeterminate).
if (!$progress) {
$progress = new \core\progress\none();
}
$progress->start_progress('Loading users into temporary table');
// Let's parse, custom processor will do its work, sending info to DB
$xmlparser = new progressive_parser();
$xmlparser->set_file($usersfile);
$xmlprocessor = new restore_users_parser_processor($restoreid);
$xmlparser->set_processor($xmlprocessor);
$xmlparser->set_progress($progress);
$xmlparser->process();
// Finish progress.
$progress->end_progress();
}
|
[
"public",
"static",
"function",
"load_users_to_tempids",
"(",
"$",
"restoreid",
",",
"$",
"usersfile",
",",
"\\",
"core",
"\\",
"progress",
"\\",
"base",
"$",
"progress",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"usersfile",
")",
")",
"{",
"// Shouldn't happen ever, but...",
"throw",
"new",
"backup_helper_exception",
"(",
"'missing_users_xml_file'",
",",
"$",
"usersfile",
")",
";",
"}",
"// Set up progress tracking (indeterminate).",
"if",
"(",
"!",
"$",
"progress",
")",
"{",
"$",
"progress",
"=",
"new",
"\\",
"core",
"\\",
"progress",
"\\",
"none",
"(",
")",
";",
"}",
"$",
"progress",
"->",
"start_progress",
"(",
"'Loading users into temporary table'",
")",
";",
"// Let's parse, custom processor will do its work, sending info to DB",
"$",
"xmlparser",
"=",
"new",
"progressive_parser",
"(",
")",
";",
"$",
"xmlparser",
"->",
"set_file",
"(",
"$",
"usersfile",
")",
";",
"$",
"xmlprocessor",
"=",
"new",
"restore_users_parser_processor",
"(",
"$",
"restoreid",
")",
";",
"$",
"xmlparser",
"->",
"set_processor",
"(",
"$",
"xmlprocessor",
")",
";",
"$",
"xmlparser",
"->",
"set_progress",
"(",
"$",
"progress",
")",
";",
"$",
"xmlparser",
"->",
"process",
"(",
")",
";",
"// Finish progress.",
"$",
"progress",
"->",
"end_progress",
"(",
")",
";",
"}"
] |
Load the needed users.xml file to backup_ids table for future reference
@param string $restoreid Restore id
@param string $usersfile File path
@param \core\progress\base $progress Progress tracker
|
[
"Load",
"the",
"needed",
"users",
".",
"xml",
"file",
"to",
"backup_ids",
"table",
"for",
"future",
"reference"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/dbops/restore_dbops.class.php#L426-L449
|
217,593
|
moodle/moodle
|
backup/util/dbops/restore_dbops.class.php
|
restore_dbops.load_categories_and_questions_to_tempids
|
public static function load_categories_and_questions_to_tempids($restoreid, $questionsfile) {
if (!file_exists($questionsfile)) { // Shouldn't happen ever, but...
throw new backup_helper_exception('missing_questions_xml_file', $questionsfile);
}
// Let's parse, custom processor will do its work, sending info to DB
$xmlparser = new progressive_parser();
$xmlparser->set_file($questionsfile);
$xmlprocessor = new restore_questions_parser_processor($restoreid);
$xmlparser->set_processor($xmlprocessor);
$xmlparser->process();
}
|
php
|
public static function load_categories_and_questions_to_tempids($restoreid, $questionsfile) {
if (!file_exists($questionsfile)) { // Shouldn't happen ever, but...
throw new backup_helper_exception('missing_questions_xml_file', $questionsfile);
}
// Let's parse, custom processor will do its work, sending info to DB
$xmlparser = new progressive_parser();
$xmlparser->set_file($questionsfile);
$xmlprocessor = new restore_questions_parser_processor($restoreid);
$xmlparser->set_processor($xmlprocessor);
$xmlparser->process();
}
|
[
"public",
"static",
"function",
"load_categories_and_questions_to_tempids",
"(",
"$",
"restoreid",
",",
"$",
"questionsfile",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"questionsfile",
")",
")",
"{",
"// Shouldn't happen ever, but...",
"throw",
"new",
"backup_helper_exception",
"(",
"'missing_questions_xml_file'",
",",
"$",
"questionsfile",
")",
";",
"}",
"// Let's parse, custom processor will do its work, sending info to DB",
"$",
"xmlparser",
"=",
"new",
"progressive_parser",
"(",
")",
";",
"$",
"xmlparser",
"->",
"set_file",
"(",
"$",
"questionsfile",
")",
";",
"$",
"xmlprocessor",
"=",
"new",
"restore_questions_parser_processor",
"(",
"$",
"restoreid",
")",
";",
"$",
"xmlparser",
"->",
"set_processor",
"(",
"$",
"xmlprocessor",
")",
";",
"$",
"xmlparser",
"->",
"process",
"(",
")",
";",
"}"
] |
Load the needed questions.xml file to backup_ids table for future reference
|
[
"Load",
"the",
"needed",
"questions",
".",
"xml",
"file",
"to",
"backup_ids",
"table",
"for",
"future",
"reference"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/dbops/restore_dbops.class.php#L454-L465
|
217,594
|
moodle/moodle
|
backup/util/dbops/restore_dbops.class.php
|
restore_dbops.restore_get_question_banks
|
public static function restore_get_question_banks($restoreid, $contextlevel = null) {
global $DB;
$results = array();
$qcats = $DB->get_recordset_sql("SELECT itemid, parentitemid AS contextid, info
FROM {backup_ids_temp}
WHERE backupid = ?
AND itemname = 'question_category'", array($restoreid));
foreach ($qcats as $qcat) {
// If this qcat context haven't been acummulated yet, do that
if (!isset($results[$qcat->contextid])) {
$info = backup_controller_dbops::decode_backup_temp_info($qcat->info);
// Filter by contextlevel if necessary
if (is_null($contextlevel) || $contextlevel == $info->contextlevel) {
$results[$qcat->contextid] = $info->contextlevel;
}
}
}
$qcats->close();
// Sort by value (contextlevel from CONTEXT_SYSTEM downto CONTEXT_MODULE)
asort($results);
return $results;
}
|
php
|
public static function restore_get_question_banks($restoreid, $contextlevel = null) {
global $DB;
$results = array();
$qcats = $DB->get_recordset_sql("SELECT itemid, parentitemid AS contextid, info
FROM {backup_ids_temp}
WHERE backupid = ?
AND itemname = 'question_category'", array($restoreid));
foreach ($qcats as $qcat) {
// If this qcat context haven't been acummulated yet, do that
if (!isset($results[$qcat->contextid])) {
$info = backup_controller_dbops::decode_backup_temp_info($qcat->info);
// Filter by contextlevel if necessary
if (is_null($contextlevel) || $contextlevel == $info->contextlevel) {
$results[$qcat->contextid] = $info->contextlevel;
}
}
}
$qcats->close();
// Sort by value (contextlevel from CONTEXT_SYSTEM downto CONTEXT_MODULE)
asort($results);
return $results;
}
|
[
"public",
"static",
"function",
"restore_get_question_banks",
"(",
"$",
"restoreid",
",",
"$",
"contextlevel",
"=",
"null",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"results",
"=",
"array",
"(",
")",
";",
"$",
"qcats",
"=",
"$",
"DB",
"->",
"get_recordset_sql",
"(",
"\"SELECT itemid, parentitemid AS contextid, info\n FROM {backup_ids_temp}\n WHERE backupid = ?\n AND itemname = 'question_category'\"",
",",
"array",
"(",
"$",
"restoreid",
")",
")",
";",
"foreach",
"(",
"$",
"qcats",
"as",
"$",
"qcat",
")",
"{",
"// If this qcat context haven't been acummulated yet, do that",
"if",
"(",
"!",
"isset",
"(",
"$",
"results",
"[",
"$",
"qcat",
"->",
"contextid",
"]",
")",
")",
"{",
"$",
"info",
"=",
"backup_controller_dbops",
"::",
"decode_backup_temp_info",
"(",
"$",
"qcat",
"->",
"info",
")",
";",
"// Filter by contextlevel if necessary",
"if",
"(",
"is_null",
"(",
"$",
"contextlevel",
")",
"||",
"$",
"contextlevel",
"==",
"$",
"info",
"->",
"contextlevel",
")",
"{",
"$",
"results",
"[",
"$",
"qcat",
"->",
"contextid",
"]",
"=",
"$",
"info",
"->",
"contextlevel",
";",
"}",
"}",
"}",
"$",
"qcats",
"->",
"close",
"(",
")",
";",
"// Sort by value (contextlevel from CONTEXT_SYSTEM downto CONTEXT_MODULE)",
"asort",
"(",
"$",
"results",
")",
";",
"return",
"$",
"results",
";",
"}"
] |
Return one array of contextid => contextlevel pairs
of question banks to be checked for one given restore operation
ordered from CONTEXT_SYSTEM downto CONTEXT_MODULE
If contextlevel is specified, then only banks corresponding to
that level are returned
|
[
"Return",
"one",
"array",
"of",
"contextid",
"=",
">",
"contextlevel",
"pairs",
"of",
"question",
"banks",
"to",
"be",
"checked",
"for",
"one",
"given",
"restore",
"operation",
"ordered",
"from",
"CONTEXT_SYSTEM",
"downto",
"CONTEXT_MODULE",
"If",
"contextlevel",
"is",
"specified",
"then",
"only",
"banks",
"corresponding",
"to",
"that",
"level",
"are",
"returned"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/dbops/restore_dbops.class.php#L741-L763
|
217,595
|
moodle/moodle
|
backup/util/dbops/restore_dbops.class.php
|
restore_dbops.restore_get_questions
|
public static function restore_get_questions($restoreid, $qcatid) {
global $DB;
$results = array();
$qs = $DB->get_recordset_sql("SELECT itemid, info
FROM {backup_ids_temp}
WHERE backupid = ?
AND itemname = 'question'
AND parentitemid = ?", array($restoreid, $qcatid));
foreach ($qs as $q) {
$results[$q->itemid] = backup_controller_dbops::decode_backup_temp_info($q->info);
}
$qs->close();
return $results;
}
|
php
|
public static function restore_get_questions($restoreid, $qcatid) {
global $DB;
$results = array();
$qs = $DB->get_recordset_sql("SELECT itemid, info
FROM {backup_ids_temp}
WHERE backupid = ?
AND itemname = 'question'
AND parentitemid = ?", array($restoreid, $qcatid));
foreach ($qs as $q) {
$results[$q->itemid] = backup_controller_dbops::decode_backup_temp_info($q->info);
}
$qs->close();
return $results;
}
|
[
"public",
"static",
"function",
"restore_get_questions",
"(",
"$",
"restoreid",
",",
"$",
"qcatid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"results",
"=",
"array",
"(",
")",
";",
"$",
"qs",
"=",
"$",
"DB",
"->",
"get_recordset_sql",
"(",
"\"SELECT itemid, info\n FROM {backup_ids_temp}\n WHERE backupid = ?\n AND itemname = 'question'\n AND parentitemid = ?\"",
",",
"array",
"(",
"$",
"restoreid",
",",
"$",
"qcatid",
")",
")",
";",
"foreach",
"(",
"$",
"qs",
"as",
"$",
"q",
")",
"{",
"$",
"results",
"[",
"$",
"q",
"->",
"itemid",
"]",
"=",
"backup_controller_dbops",
"::",
"decode_backup_temp_info",
"(",
"$",
"q",
"->",
"info",
")",
";",
"}",
"$",
"qs",
"->",
"close",
"(",
")",
";",
"return",
"$",
"results",
";",
"}"
] |
Return one array of question records for
a given restore operation and one question category
|
[
"Return",
"one",
"array",
"of",
"question",
"records",
"for",
"a",
"given",
"restore",
"operation",
"and",
"one",
"question",
"category"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/dbops/restore_dbops.class.php#L868-L882
|
217,596
|
moodle/moodle
|
backup/util/dbops/restore_dbops.class.php
|
restore_dbops.get_missing_file_result
|
protected static function get_missing_file_result($file) {
$result = new stdClass();
$result->code = 'file_missing_in_backup';
$result->message = 'Missing file in backup: ' . $file->filepath . $file->filename .
' (old context ' . $file->contextid . ', component ' . $file->component .
', filearea ' . $file->filearea . ', old itemid ' . $file->itemid . ')';
$result->level = backup::LOG_WARNING;
return $result;
}
|
php
|
protected static function get_missing_file_result($file) {
$result = new stdClass();
$result->code = 'file_missing_in_backup';
$result->message = 'Missing file in backup: ' . $file->filepath . $file->filename .
' (old context ' . $file->contextid . ', component ' . $file->component .
', filearea ' . $file->filearea . ', old itemid ' . $file->itemid . ')';
$result->level = backup::LOG_WARNING;
return $result;
}
|
[
"protected",
"static",
"function",
"get_missing_file_result",
"(",
"$",
"file",
")",
"{",
"$",
"result",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"result",
"->",
"code",
"=",
"'file_missing_in_backup'",
";",
"$",
"result",
"->",
"message",
"=",
"'Missing file in backup: '",
".",
"$",
"file",
"->",
"filepath",
".",
"$",
"file",
"->",
"filename",
".",
"' (old context '",
".",
"$",
"file",
"->",
"contextid",
".",
"', component '",
".",
"$",
"file",
"->",
"component",
".",
"', filearea '",
".",
"$",
"file",
"->",
"filearea",
".",
"', old itemid '",
".",
"$",
"file",
"->",
"itemid",
".",
"')'",
";",
"$",
"result",
"->",
"level",
"=",
"backup",
"::",
"LOG_WARNING",
";",
"return",
"$",
"result",
";",
"}"
] |
Returns suitable entry to include in log when there is a missing file.
@param stdClass $file File definition
@return stdClass Log entry
|
[
"Returns",
"suitable",
"entry",
"to",
"include",
"in",
"log",
"when",
"there",
"is",
"a",
"missing",
"file",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/dbops/restore_dbops.class.php#L1103-L1111
|
217,597
|
moodle/moodle
|
backup/util/dbops/restore_dbops.class.php
|
restore_dbops.set_course_role_names
|
public static function set_course_role_names($restoreid, $courseid) {
global $DB;
// Get the course context
$coursectx = context_course::instance($courseid);
// Get all the mapped roles we have
$rs = $DB->get_recordset('backup_ids_temp', array('backupid' => $restoreid, 'itemname' => 'role'), '', 'itemid, info, newitemid');
foreach ($rs as $recrole) {
$info = backup_controller_dbops::decode_backup_temp_info($recrole->info);
// If it's one mapped role and we have one name for it
if (!empty($recrole->newitemid) && !empty($info['nameincourse'])) {
// If role name doesn't exist, add it
$rolename = new stdclass();
$rolename->roleid = $recrole->newitemid;
$rolename->contextid = $coursectx->id;
if (!$DB->record_exists('role_names', (array)$rolename)) {
$rolename->name = $info['nameincourse'];
$DB->insert_record('role_names', $rolename);
}
}
}
$rs->close();
}
|
php
|
public static function set_course_role_names($restoreid, $courseid) {
global $DB;
// Get the course context
$coursectx = context_course::instance($courseid);
// Get all the mapped roles we have
$rs = $DB->get_recordset('backup_ids_temp', array('backupid' => $restoreid, 'itemname' => 'role'), '', 'itemid, info, newitemid');
foreach ($rs as $recrole) {
$info = backup_controller_dbops::decode_backup_temp_info($recrole->info);
// If it's one mapped role and we have one name for it
if (!empty($recrole->newitemid) && !empty($info['nameincourse'])) {
// If role name doesn't exist, add it
$rolename = new stdclass();
$rolename->roleid = $recrole->newitemid;
$rolename->contextid = $coursectx->id;
if (!$DB->record_exists('role_names', (array)$rolename)) {
$rolename->name = $info['nameincourse'];
$DB->insert_record('role_names', $rolename);
}
}
}
$rs->close();
}
|
[
"public",
"static",
"function",
"set_course_role_names",
"(",
"$",
"restoreid",
",",
"$",
"courseid",
")",
"{",
"global",
"$",
"DB",
";",
"// Get the course context",
"$",
"coursectx",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"courseid",
")",
";",
"// Get all the mapped roles we have",
"$",
"rs",
"=",
"$",
"DB",
"->",
"get_recordset",
"(",
"'backup_ids_temp'",
",",
"array",
"(",
"'backupid'",
"=>",
"$",
"restoreid",
",",
"'itemname'",
"=>",
"'role'",
")",
",",
"''",
",",
"'itemid, info, newitemid'",
")",
";",
"foreach",
"(",
"$",
"rs",
"as",
"$",
"recrole",
")",
"{",
"$",
"info",
"=",
"backup_controller_dbops",
"::",
"decode_backup_temp_info",
"(",
"$",
"recrole",
"->",
"info",
")",
";",
"// If it's one mapped role and we have one name for it",
"if",
"(",
"!",
"empty",
"(",
"$",
"recrole",
"->",
"newitemid",
")",
"&&",
"!",
"empty",
"(",
"$",
"info",
"[",
"'nameincourse'",
"]",
")",
")",
"{",
"// If role name doesn't exist, add it",
"$",
"rolename",
"=",
"new",
"stdclass",
"(",
")",
";",
"$",
"rolename",
"->",
"roleid",
"=",
"$",
"recrole",
"->",
"newitemid",
";",
"$",
"rolename",
"->",
"contextid",
"=",
"$",
"coursectx",
"->",
"id",
";",
"if",
"(",
"!",
"$",
"DB",
"->",
"record_exists",
"(",
"'role_names'",
",",
"(",
"array",
")",
"$",
"rolename",
")",
")",
"{",
"$",
"rolename",
"->",
"name",
"=",
"$",
"info",
"[",
"'nameincourse'",
"]",
";",
"$",
"DB",
"->",
"insert_record",
"(",
"'role_names'",
",",
"$",
"rolename",
")",
";",
"}",
"}",
"}",
"$",
"rs",
"->",
"close",
"(",
")",
";",
"}"
] |
For the target course context, put as many custom role names as possible
|
[
"For",
"the",
"target",
"course",
"context",
"put",
"as",
"many",
"custom",
"role",
"names",
"as",
"possible"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/dbops/restore_dbops.class.php#L1752-L1774
|
217,598
|
moodle/moodle
|
backup/util/dbops/restore_dbops.class.php
|
restore_dbops.create_new_course
|
public static function create_new_course($fullname, $shortname, $categoryid) {
global $DB;
$category = $DB->get_record('course_categories', array('id'=>$categoryid), '*', MUST_EXIST);
$course = new stdClass;
$course->fullname = $fullname;
$course->shortname = $shortname;
$course->category = $category->id;
$course->sortorder = 0;
$course->timecreated = time();
$course->timemodified = $course->timecreated;
// forcing skeleton courses to be hidden instead of going by $category->visible , until MDL-27790 is resolved.
$course->visible = 0;
$courseid = $DB->insert_record('course', $course);
$category->coursecount++;
$DB->update_record('course_categories', $category);
return $courseid;
}
|
php
|
public static function create_new_course($fullname, $shortname, $categoryid) {
global $DB;
$category = $DB->get_record('course_categories', array('id'=>$categoryid), '*', MUST_EXIST);
$course = new stdClass;
$course->fullname = $fullname;
$course->shortname = $shortname;
$course->category = $category->id;
$course->sortorder = 0;
$course->timecreated = time();
$course->timemodified = $course->timecreated;
// forcing skeleton courses to be hidden instead of going by $category->visible , until MDL-27790 is resolved.
$course->visible = 0;
$courseid = $DB->insert_record('course', $course);
$category->coursecount++;
$DB->update_record('course_categories', $category);
return $courseid;
}
|
[
"public",
"static",
"function",
"create_new_course",
"(",
"$",
"fullname",
",",
"$",
"shortname",
",",
"$",
"categoryid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"category",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'course_categories'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"categoryid",
")",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"$",
"course",
"=",
"new",
"stdClass",
";",
"$",
"course",
"->",
"fullname",
"=",
"$",
"fullname",
";",
"$",
"course",
"->",
"shortname",
"=",
"$",
"shortname",
";",
"$",
"course",
"->",
"category",
"=",
"$",
"category",
"->",
"id",
";",
"$",
"course",
"->",
"sortorder",
"=",
"0",
";",
"$",
"course",
"->",
"timecreated",
"=",
"time",
"(",
")",
";",
"$",
"course",
"->",
"timemodified",
"=",
"$",
"course",
"->",
"timecreated",
";",
"// forcing skeleton courses to be hidden instead of going by $category->visible , until MDL-27790 is resolved.",
"$",
"course",
"->",
"visible",
"=",
"0",
";",
"$",
"courseid",
"=",
"$",
"DB",
"->",
"insert_record",
"(",
"'course'",
",",
"$",
"course",
")",
";",
"$",
"category",
"->",
"coursecount",
"++",
";",
"$",
"DB",
"->",
"update_record",
"(",
"'course_categories'",
",",
"$",
"category",
")",
";",
"return",
"$",
"courseid",
";",
"}"
] |
Creates a skeleton record within the database using the passed parameters
and returns the new course id.
@global moodle_database $DB
@param string $fullname
@param string $shortname
@param int $categoryid
@return int The new course id
|
[
"Creates",
"a",
"skeleton",
"record",
"within",
"the",
"database",
"using",
"the",
"passed",
"parameters",
"and",
"returns",
"the",
"new",
"course",
"id",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/dbops/restore_dbops.class.php#L1786-L1806
|
217,599
|
moodle/moodle
|
lib/behat/behat_field_manager.php
|
behat_field_manager.get_form_field_from_label
|
public static function get_form_field_from_label($label, RawMinkContext $context) {
// There are moodle form elements that are not directly related with
// a basic HTML form field, we should also take care of them.
// The DOM node.
$fieldnode = $context->find_field($label);
// The behat field manager.
return self::get_form_field($fieldnode, $context->getSession());
}
|
php
|
public static function get_form_field_from_label($label, RawMinkContext $context) {
// There are moodle form elements that are not directly related with
// a basic HTML form field, we should also take care of them.
// The DOM node.
$fieldnode = $context->find_field($label);
// The behat field manager.
return self::get_form_field($fieldnode, $context->getSession());
}
|
[
"public",
"static",
"function",
"get_form_field_from_label",
"(",
"$",
"label",
",",
"RawMinkContext",
"$",
"context",
")",
"{",
"// There are moodle form elements that are not directly related with",
"// a basic HTML form field, we should also take care of them.",
"// The DOM node.",
"$",
"fieldnode",
"=",
"$",
"context",
"->",
"find_field",
"(",
"$",
"label",
")",
";",
"// The behat field manager.",
"return",
"self",
"::",
"get_form_field",
"(",
"$",
"fieldnode",
",",
"$",
"context",
"->",
"getSession",
"(",
")",
")",
";",
"}"
] |
Gets an instance of the form field from it's label
@param string $label
@param RawMinkContext $context
@return behat_form_field
|
[
"Gets",
"an",
"instance",
"of",
"the",
"form",
"field",
"from",
"it",
"s",
"label"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/behat_field_manager.php#L50-L59
|
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.