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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
216,500
|
moodle/moodle
|
repository/filesystem/lib.php
|
repository_filesystem.build_breadcrumb
|
protected function build_breadcrumb($path) {
$breadcrumb = array(array(
'name' => get_string('root', 'repository_filesystem'),
'path' => $this->build_node_path('root')
));
$crumbs = explode('|', $path);
$trail = '';
foreach ($crumbs as $crumb) {
list($mode, $nodepath, $display) = $this->explode_node_path($crumb);
switch ($mode) {
case 'search':
$breadcrumb[] = array(
'name' => get_string('searchresults', 'repository_filesystem'),
'path' => $this->build_node_path($mode, $nodepath, $display, $trail),
);
break;
case 'browse':
$breadcrumb[] = array(
'name' => $display,
'path' => $this->build_node_path($mode, $nodepath, $display, $trail),
);
break;
}
$lastcrumb = end($breadcrumb);
$trail = $lastcrumb['path'];
}
return $breadcrumb;
}
|
php
|
protected function build_breadcrumb($path) {
$breadcrumb = array(array(
'name' => get_string('root', 'repository_filesystem'),
'path' => $this->build_node_path('root')
));
$crumbs = explode('|', $path);
$trail = '';
foreach ($crumbs as $crumb) {
list($mode, $nodepath, $display) = $this->explode_node_path($crumb);
switch ($mode) {
case 'search':
$breadcrumb[] = array(
'name' => get_string('searchresults', 'repository_filesystem'),
'path' => $this->build_node_path($mode, $nodepath, $display, $trail),
);
break;
case 'browse':
$breadcrumb[] = array(
'name' => $display,
'path' => $this->build_node_path($mode, $nodepath, $display, $trail),
);
break;
}
$lastcrumb = end($breadcrumb);
$trail = $lastcrumb['path'];
}
return $breadcrumb;
}
|
[
"protected",
"function",
"build_breadcrumb",
"(",
"$",
"path",
")",
"{",
"$",
"breadcrumb",
"=",
"array",
"(",
"array",
"(",
"'name'",
"=>",
"get_string",
"(",
"'root'",
",",
"'repository_filesystem'",
")",
",",
"'path'",
"=>",
"$",
"this",
"->",
"build_node_path",
"(",
"'root'",
")",
")",
")",
";",
"$",
"crumbs",
"=",
"explode",
"(",
"'|'",
",",
"$",
"path",
")",
";",
"$",
"trail",
"=",
"''",
";",
"foreach",
"(",
"$",
"crumbs",
"as",
"$",
"crumb",
")",
"{",
"list",
"(",
"$",
"mode",
",",
"$",
"nodepath",
",",
"$",
"display",
")",
"=",
"$",
"this",
"->",
"explode_node_path",
"(",
"$",
"crumb",
")",
";",
"switch",
"(",
"$",
"mode",
")",
"{",
"case",
"'search'",
":",
"$",
"breadcrumb",
"[",
"]",
"=",
"array",
"(",
"'name'",
"=>",
"get_string",
"(",
"'searchresults'",
",",
"'repository_filesystem'",
")",
",",
"'path'",
"=>",
"$",
"this",
"->",
"build_node_path",
"(",
"$",
"mode",
",",
"$",
"nodepath",
",",
"$",
"display",
",",
"$",
"trail",
")",
",",
")",
";",
"break",
";",
"case",
"'browse'",
":",
"$",
"breadcrumb",
"[",
"]",
"=",
"array",
"(",
"'name'",
"=>",
"$",
"display",
",",
"'path'",
"=>",
"$",
"this",
"->",
"build_node_path",
"(",
"$",
"mode",
",",
"$",
"nodepath",
",",
"$",
"display",
",",
"$",
"trail",
")",
",",
")",
";",
"break",
";",
"}",
"$",
"lastcrumb",
"=",
"end",
"(",
"$",
"breadcrumb",
")",
";",
"$",
"trail",
"=",
"$",
"lastcrumb",
"[",
"'path'",
"]",
";",
"}",
"return",
"$",
"breadcrumb",
";",
"}"
] |
Build the breadcrumb from a full path.
@param string $path A path generated by {@link self::build_node_path()}.
@return array
|
[
"Build",
"the",
"breadcrumb",
"from",
"a",
"full",
"path",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/filesystem/lib.php#L257-L289
|
216,501
|
moodle/moodle
|
repository/filesystem/lib.php
|
repository_filesystem.build_node
|
protected function build_node($rootpath, $path, $name, $isdir, $rootnodepath) {
global $OUTPUT;
$relpath = trim($path, '/') . '/' . $name;
$abspath = $rootpath . $relpath;
$node = array(
'title' => $name,
'datecreated' => filectime($abspath),
'datemodified' => filemtime($abspath),
);
if ($isdir) {
$node['children'] = array();
$node['thumbnail'] = $OUTPUT->image_url(file_folder_icon(90))->out(false);
$node['path'] = $this->build_node_path('browse', $relpath, $name, $rootnodepath);
} else {
$node['source'] = $relpath;
$node['size'] = filesize($abspath);
$node['thumbnail'] = $OUTPUT->image_url(file_extension_icon($name, 90))->out(false);
$node['icon'] = $OUTPUT->image_url(file_extension_icon($name, 24))->out(false);
$node['path'] = $relpath;
if (file_extension_in_typegroup($name, 'image') && ($imageinfo = @getimagesize($abspath))) {
// This means it is an image and we can return dimensions and try to generate thumbnail/icon.
$token = $node['datemodified'] . $node['size']; // To prevent caching by browser.
$node['realthumbnail'] = $this->get_thumbnail_url($relpath, 'thumb', $token)->out(false);
$node['realicon'] = $this->get_thumbnail_url($relpath, 'icon', $token)->out(false);
$node['image_width'] = $imageinfo[0];
$node['image_height'] = $imageinfo[1];
}
}
return $node;
}
|
php
|
protected function build_node($rootpath, $path, $name, $isdir, $rootnodepath) {
global $OUTPUT;
$relpath = trim($path, '/') . '/' . $name;
$abspath = $rootpath . $relpath;
$node = array(
'title' => $name,
'datecreated' => filectime($abspath),
'datemodified' => filemtime($abspath),
);
if ($isdir) {
$node['children'] = array();
$node['thumbnail'] = $OUTPUT->image_url(file_folder_icon(90))->out(false);
$node['path'] = $this->build_node_path('browse', $relpath, $name, $rootnodepath);
} else {
$node['source'] = $relpath;
$node['size'] = filesize($abspath);
$node['thumbnail'] = $OUTPUT->image_url(file_extension_icon($name, 90))->out(false);
$node['icon'] = $OUTPUT->image_url(file_extension_icon($name, 24))->out(false);
$node['path'] = $relpath;
if (file_extension_in_typegroup($name, 'image') && ($imageinfo = @getimagesize($abspath))) {
// This means it is an image and we can return dimensions and try to generate thumbnail/icon.
$token = $node['datemodified'] . $node['size']; // To prevent caching by browser.
$node['realthumbnail'] = $this->get_thumbnail_url($relpath, 'thumb', $token)->out(false);
$node['realicon'] = $this->get_thumbnail_url($relpath, 'icon', $token)->out(false);
$node['image_width'] = $imageinfo[0];
$node['image_height'] = $imageinfo[1];
}
}
return $node;
}
|
[
"protected",
"function",
"build_node",
"(",
"$",
"rootpath",
",",
"$",
"path",
",",
"$",
"name",
",",
"$",
"isdir",
",",
"$",
"rootnodepath",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"$",
"relpath",
"=",
"trim",
"(",
"$",
"path",
",",
"'/'",
")",
".",
"'/'",
".",
"$",
"name",
";",
"$",
"abspath",
"=",
"$",
"rootpath",
".",
"$",
"relpath",
";",
"$",
"node",
"=",
"array",
"(",
"'title'",
"=>",
"$",
"name",
",",
"'datecreated'",
"=>",
"filectime",
"(",
"$",
"abspath",
")",
",",
"'datemodified'",
"=>",
"filemtime",
"(",
"$",
"abspath",
")",
",",
")",
";",
"if",
"(",
"$",
"isdir",
")",
"{",
"$",
"node",
"[",
"'children'",
"]",
"=",
"array",
"(",
")",
";",
"$",
"node",
"[",
"'thumbnail'",
"]",
"=",
"$",
"OUTPUT",
"->",
"image_url",
"(",
"file_folder_icon",
"(",
"90",
")",
")",
"->",
"out",
"(",
"false",
")",
";",
"$",
"node",
"[",
"'path'",
"]",
"=",
"$",
"this",
"->",
"build_node_path",
"(",
"'browse'",
",",
"$",
"relpath",
",",
"$",
"name",
",",
"$",
"rootnodepath",
")",
";",
"}",
"else",
"{",
"$",
"node",
"[",
"'source'",
"]",
"=",
"$",
"relpath",
";",
"$",
"node",
"[",
"'size'",
"]",
"=",
"filesize",
"(",
"$",
"abspath",
")",
";",
"$",
"node",
"[",
"'thumbnail'",
"]",
"=",
"$",
"OUTPUT",
"->",
"image_url",
"(",
"file_extension_icon",
"(",
"$",
"name",
",",
"90",
")",
")",
"->",
"out",
"(",
"false",
")",
";",
"$",
"node",
"[",
"'icon'",
"]",
"=",
"$",
"OUTPUT",
"->",
"image_url",
"(",
"file_extension_icon",
"(",
"$",
"name",
",",
"24",
")",
")",
"->",
"out",
"(",
"false",
")",
";",
"$",
"node",
"[",
"'path'",
"]",
"=",
"$",
"relpath",
";",
"if",
"(",
"file_extension_in_typegroup",
"(",
"$",
"name",
",",
"'image'",
")",
"&&",
"(",
"$",
"imageinfo",
"=",
"@",
"getimagesize",
"(",
"$",
"abspath",
")",
")",
")",
"{",
"// This means it is an image and we can return dimensions and try to generate thumbnail/icon.",
"$",
"token",
"=",
"$",
"node",
"[",
"'datemodified'",
"]",
".",
"$",
"node",
"[",
"'size'",
"]",
";",
"// To prevent caching by browser.",
"$",
"node",
"[",
"'realthumbnail'",
"]",
"=",
"$",
"this",
"->",
"get_thumbnail_url",
"(",
"$",
"relpath",
",",
"'thumb'",
",",
"$",
"token",
")",
"->",
"out",
"(",
"false",
")",
";",
"$",
"node",
"[",
"'realicon'",
"]",
"=",
"$",
"this",
"->",
"get_thumbnail_url",
"(",
"$",
"relpath",
",",
"'icon'",
",",
"$",
"token",
")",
"->",
"out",
"(",
"false",
")",
";",
"$",
"node",
"[",
"'image_width'",
"]",
"=",
"$",
"imageinfo",
"[",
"0",
"]",
";",
"$",
"node",
"[",
"'image_height'",
"]",
"=",
"$",
"imageinfo",
"[",
"1",
"]",
";",
"}",
"}",
"return",
"$",
"node",
";",
"}"
] |
Build a file or directory node.
@param string $rootpath The absolute path to the repository.
@param string $path The relative path of the object
@param string $name The name of the object
@param string $isdir Is the object a directory?
@param string $rootnodepath The node leading to this node (for breadcrumb).
@return array
|
[
"Build",
"a",
"file",
"or",
"directory",
"node",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/filesystem/lib.php#L301-L335
|
216,502
|
moodle/moodle
|
repository/filesystem/lib.php
|
repository_filesystem.build_node_path
|
protected function build_node_path($mode, $realpath = '', $display = '', $root = '') {
$path = $mode . ':' . base64_encode($realpath) . ':' . base64_encode($display);
if (!empty($root)) {
$path = $root . '|' . $path;
}
return $path;
}
|
php
|
protected function build_node_path($mode, $realpath = '', $display = '', $root = '') {
$path = $mode . ':' . base64_encode($realpath) . ':' . base64_encode($display);
if (!empty($root)) {
$path = $root . '|' . $path;
}
return $path;
}
|
[
"protected",
"function",
"build_node_path",
"(",
"$",
"mode",
",",
"$",
"realpath",
"=",
"''",
",",
"$",
"display",
"=",
"''",
",",
"$",
"root",
"=",
"''",
")",
"{",
"$",
"path",
"=",
"$",
"mode",
".",
"':'",
".",
"base64_encode",
"(",
"$",
"realpath",
")",
".",
"':'",
".",
"base64_encode",
"(",
"$",
"display",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"root",
")",
")",
"{",
"$",
"path",
"=",
"$",
"root",
".",
"'|'",
".",
"$",
"path",
";",
"}",
"return",
"$",
"path",
";",
"}"
] |
Build the path to a browsable node.
@param string $mode The type of browse mode.
@param string $realpath The path, or similar.
@param string $display The way to display the node.
@param string $root The path preceding this node.
@return string
|
[
"Build",
"the",
"path",
"to",
"a",
"browsable",
"node",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/filesystem/lib.php#L346-L352
|
216,503
|
moodle/moodle
|
repository/filesystem/lib.php
|
repository_filesystem.explode_node_path
|
protected function explode_node_path($path) {
list($mode, $realpath, $display) = explode(':', $path);
return array(
$mode,
base64_decode($realpath),
base64_decode($display)
);
}
|
php
|
protected function explode_node_path($path) {
list($mode, $realpath, $display) = explode(':', $path);
return array(
$mode,
base64_decode($realpath),
base64_decode($display)
);
}
|
[
"protected",
"function",
"explode_node_path",
"(",
"$",
"path",
")",
"{",
"list",
"(",
"$",
"mode",
",",
"$",
"realpath",
",",
"$",
"display",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"path",
")",
";",
"return",
"array",
"(",
"$",
"mode",
",",
"base64_decode",
"(",
"$",
"realpath",
")",
",",
"base64_decode",
"(",
"$",
"display",
")",
")",
";",
"}"
] |
Extract information from a node path.
Note, this should not include preceding paths.
@param string $path The path of the node.
@return array Contains the mode, the relative path, and the display text.
|
[
"Extract",
"information",
"from",
"a",
"node",
"path",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/filesystem/lib.php#L362-L369
|
216,504
|
moodle/moodle
|
repository/filesystem/lib.php
|
repository_filesystem.get_file
|
public function get_file($file, $title = '') {
global $CFG;
$file = ltrim($file, '/');
if (!$this->is_in_repository($file)) {
throw new repository_exception('Invalid file requested.');
}
$file = $this->get_rootpath() . $file;
// This is a hack to prevent move_to_file deleting files in local repository.
$CFG->repository_no_delete = true;
return array('path' => $file, 'url' => '');
}
|
php
|
public function get_file($file, $title = '') {
global $CFG;
$file = ltrim($file, '/');
if (!$this->is_in_repository($file)) {
throw new repository_exception('Invalid file requested.');
}
$file = $this->get_rootpath() . $file;
// This is a hack to prevent move_to_file deleting files in local repository.
$CFG->repository_no_delete = true;
return array('path' => $file, 'url' => '');
}
|
[
"public",
"function",
"get_file",
"(",
"$",
"file",
",",
"$",
"title",
"=",
"''",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"file",
"=",
"ltrim",
"(",
"$",
"file",
",",
"'/'",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"is_in_repository",
"(",
"$",
"file",
")",
")",
"{",
"throw",
"new",
"repository_exception",
"(",
"'Invalid file requested.'",
")",
";",
"}",
"$",
"file",
"=",
"$",
"this",
"->",
"get_rootpath",
"(",
")",
".",
"$",
"file",
";",
"// This is a hack to prevent move_to_file deleting files in local repository.",
"$",
"CFG",
"->",
"repository_no_delete",
"=",
"true",
";",
"return",
"array",
"(",
"'path'",
"=>",
"$",
"file",
",",
"'url'",
"=>",
"''",
")",
";",
"}"
] |
Return file path.
@return array
|
[
"Return",
"file",
"path",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/filesystem/lib.php#L402-L413
|
216,505
|
moodle/moodle
|
repository/filesystem/lib.php
|
repository_filesystem.instance_form_validation
|
public static function instance_form_validation($mform, $data, $errors) {
$fspath = clean_param(trim($data['fs_path'], '/'), PARAM_PATH);
if (empty($fspath) && !is_numeric($fspath)) {
$errors['fs_path'] = get_string('invalidadminsettingname', 'error', 'fs_path');
}
return $errors;
}
|
php
|
public static function instance_form_validation($mform, $data, $errors) {
$fspath = clean_param(trim($data['fs_path'], '/'), PARAM_PATH);
if (empty($fspath) && !is_numeric($fspath)) {
$errors['fs_path'] = get_string('invalidadminsettingname', 'error', 'fs_path');
}
return $errors;
}
|
[
"public",
"static",
"function",
"instance_form_validation",
"(",
"$",
"mform",
",",
"$",
"data",
",",
"$",
"errors",
")",
"{",
"$",
"fspath",
"=",
"clean_param",
"(",
"trim",
"(",
"$",
"data",
"[",
"'fs_path'",
"]",
",",
"'/'",
")",
",",
"PARAM_PATH",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"fspath",
")",
"&&",
"!",
"is_numeric",
"(",
"$",
"fspath",
")",
")",
"{",
"$",
"errors",
"[",
"'fs_path'",
"]",
"=",
"get_string",
"(",
"'invalidadminsettingname'",
",",
"'error'",
",",
"'fs_path'",
")",
";",
"}",
"return",
"$",
"errors",
";",
"}"
] |
Validate repository plugin instance form
@param moodleform $mform moodle form
@param array $data form data
@param array $errors errors
@return array errors
|
[
"Validate",
"repository",
"plugin",
"instance",
"form"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/filesystem/lib.php#L526-L532
|
216,506
|
moodle/moodle
|
repository/filesystem/lib.php
|
repository_filesystem.get_rootpath
|
public function get_rootpath() {
global $CFG;
$subdir = clean_param(trim($this->subdir, '/'), PARAM_PATH);
$path = $CFG->dataroot . '/repository/' . $this->subdir . '/';
if ((empty($this->subdir) && !is_numeric($this->subdir)) || $subdir != $this->subdir || !is_dir($path)) {
throw new repository_exception('The instance is not properly configured, invalid path.');
}
return $path;
}
|
php
|
public function get_rootpath() {
global $CFG;
$subdir = clean_param(trim($this->subdir, '/'), PARAM_PATH);
$path = $CFG->dataroot . '/repository/' . $this->subdir . '/';
if ((empty($this->subdir) && !is_numeric($this->subdir)) || $subdir != $this->subdir || !is_dir($path)) {
throw new repository_exception('The instance is not properly configured, invalid path.');
}
return $path;
}
|
[
"public",
"function",
"get_rootpath",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"subdir",
"=",
"clean_param",
"(",
"trim",
"(",
"$",
"this",
"->",
"subdir",
",",
"'/'",
")",
",",
"PARAM_PATH",
")",
";",
"$",
"path",
"=",
"$",
"CFG",
"->",
"dataroot",
".",
"'/repository/'",
".",
"$",
"this",
"->",
"subdir",
".",
"'/'",
";",
"if",
"(",
"(",
"empty",
"(",
"$",
"this",
"->",
"subdir",
")",
"&&",
"!",
"is_numeric",
"(",
"$",
"this",
"->",
"subdir",
")",
")",
"||",
"$",
"subdir",
"!=",
"$",
"this",
"->",
"subdir",
"||",
"!",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"repository_exception",
"(",
"'The instance is not properly configured, invalid path.'",
")",
";",
"}",
"return",
"$",
"path",
";",
"}"
] |
Return the rootpath of this repository instance.
Trim() is a necessary step to ensure that the subdirectory is not '/'.
@return string path
@throws repository_exception If the subdir is unsafe, or invalid.
|
[
"Return",
"the",
"rootpath",
"of",
"this",
"repository",
"instance",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/filesystem/lib.php#L647-L655
|
216,507
|
moodle/moodle
|
repository/filesystem/lib.php
|
repository_filesystem.get_thumbnail_url
|
protected function get_thumbnail_url($filepath, $thumbsize, $token) {
return moodle_url::make_pluginfile_url($this->context->id, 'repository_filesystem', $thumbsize, $this->id,
'/' . trim($filepath, '/') . '/', $token);
}
|
php
|
protected function get_thumbnail_url($filepath, $thumbsize, $token) {
return moodle_url::make_pluginfile_url($this->context->id, 'repository_filesystem', $thumbsize, $this->id,
'/' . trim($filepath, '/') . '/', $token);
}
|
[
"protected",
"function",
"get_thumbnail_url",
"(",
"$",
"filepath",
",",
"$",
"thumbsize",
",",
"$",
"token",
")",
"{",
"return",
"moodle_url",
"::",
"make_pluginfile_url",
"(",
"$",
"this",
"->",
"context",
"->",
"id",
",",
"'repository_filesystem'",
",",
"$",
"thumbsize",
",",
"$",
"this",
"->",
"id",
",",
"'/'",
".",
"trim",
"(",
"$",
"filepath",
",",
"'/'",
")",
".",
"'/'",
",",
"$",
"token",
")",
";",
"}"
] |
Returns url of thumbnail file.
@param string $filepath current path in repository (dir and filename)
@param string $thumbsize 'thumb' or 'icon'
@param string $token identifier of the file contents - to prevent browser from caching changed file
@return moodle_url
|
[
"Returns",
"url",
"of",
"thumbnail",
"file",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/filesystem/lib.php#L685-L688
|
216,508
|
moodle/moodle
|
repository/filesystem/lib.php
|
repository_filesystem.get_thumbnail
|
public function get_thumbnail($filepath, $thumbsize) {
global $CFG;
$filepath = trim($filepath, '/');
$origfile = $this->get_rootpath() . $filepath;
// As thumbnail filename we use original file content hash.
if (!$this->is_in_repository($filepath) || !($filecontents = @file_get_contents($origfile))) {
// File is not found or is not readable.
return null;
}
$filename = file_storage::hash_from_string($filecontents);
// Try to get generated thumbnail for this file.
$fs = get_file_storage();
if (!($file = $fs->get_file(SYSCONTEXTID, 'repository_filesystem', $thumbsize, $this->id, '/' . $filepath . '/',
$filename))) {
// Thumbnail not found . Generate and store thumbnail.
require_once($CFG->libdir . '/gdlib.php');
if ($thumbsize === 'thumb') {
$size = 90;
} else {
$size = 24;
}
if (!$data = generate_image_thumbnail_from_string($filecontents, $size, $size)) {
// Generation failed.
return null;
}
$record = array(
'contextid' => SYSCONTEXTID,
'component' => 'repository_filesystem',
'filearea' => $thumbsize,
'itemid' => $this->id,
'filepath' => '/' . $filepath . '/',
'filename' => $filename,
);
$file = $fs->create_file_from_string($record, $data);
}
return $file;
}
|
php
|
public function get_thumbnail($filepath, $thumbsize) {
global $CFG;
$filepath = trim($filepath, '/');
$origfile = $this->get_rootpath() . $filepath;
// As thumbnail filename we use original file content hash.
if (!$this->is_in_repository($filepath) || !($filecontents = @file_get_contents($origfile))) {
// File is not found or is not readable.
return null;
}
$filename = file_storage::hash_from_string($filecontents);
// Try to get generated thumbnail for this file.
$fs = get_file_storage();
if (!($file = $fs->get_file(SYSCONTEXTID, 'repository_filesystem', $thumbsize, $this->id, '/' . $filepath . '/',
$filename))) {
// Thumbnail not found . Generate and store thumbnail.
require_once($CFG->libdir . '/gdlib.php');
if ($thumbsize === 'thumb') {
$size = 90;
} else {
$size = 24;
}
if (!$data = generate_image_thumbnail_from_string($filecontents, $size, $size)) {
// Generation failed.
return null;
}
$record = array(
'contextid' => SYSCONTEXTID,
'component' => 'repository_filesystem',
'filearea' => $thumbsize,
'itemid' => $this->id,
'filepath' => '/' . $filepath . '/',
'filename' => $filename,
);
$file = $fs->create_file_from_string($record, $data);
}
return $file;
}
|
[
"public",
"function",
"get_thumbnail",
"(",
"$",
"filepath",
",",
"$",
"thumbsize",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"filepath",
"=",
"trim",
"(",
"$",
"filepath",
",",
"'/'",
")",
";",
"$",
"origfile",
"=",
"$",
"this",
"->",
"get_rootpath",
"(",
")",
".",
"$",
"filepath",
";",
"// As thumbnail filename we use original file content hash.",
"if",
"(",
"!",
"$",
"this",
"->",
"is_in_repository",
"(",
"$",
"filepath",
")",
"||",
"!",
"(",
"$",
"filecontents",
"=",
"@",
"file_get_contents",
"(",
"$",
"origfile",
")",
")",
")",
"{",
"// File is not found or is not readable.",
"return",
"null",
";",
"}",
"$",
"filename",
"=",
"file_storage",
"::",
"hash_from_string",
"(",
"$",
"filecontents",
")",
";",
"// Try to get generated thumbnail for this file.",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"if",
"(",
"!",
"(",
"$",
"file",
"=",
"$",
"fs",
"->",
"get_file",
"(",
"SYSCONTEXTID",
",",
"'repository_filesystem'",
",",
"$",
"thumbsize",
",",
"$",
"this",
"->",
"id",
",",
"'/'",
".",
"$",
"filepath",
".",
"'/'",
",",
"$",
"filename",
")",
")",
")",
"{",
"// Thumbnail not found . Generate and store thumbnail.",
"require_once",
"(",
"$",
"CFG",
"->",
"libdir",
".",
"'/gdlib.php'",
")",
";",
"if",
"(",
"$",
"thumbsize",
"===",
"'thumb'",
")",
"{",
"$",
"size",
"=",
"90",
";",
"}",
"else",
"{",
"$",
"size",
"=",
"24",
";",
"}",
"if",
"(",
"!",
"$",
"data",
"=",
"generate_image_thumbnail_from_string",
"(",
"$",
"filecontents",
",",
"$",
"size",
",",
"$",
"size",
")",
")",
"{",
"// Generation failed.",
"return",
"null",
";",
"}",
"$",
"record",
"=",
"array",
"(",
"'contextid'",
"=>",
"SYSCONTEXTID",
",",
"'component'",
"=>",
"'repository_filesystem'",
",",
"'filearea'",
"=>",
"$",
"thumbsize",
",",
"'itemid'",
"=>",
"$",
"this",
"->",
"id",
",",
"'filepath'",
"=>",
"'/'",
".",
"$",
"filepath",
".",
"'/'",
",",
"'filename'",
"=>",
"$",
"filename",
",",
")",
";",
"$",
"file",
"=",
"$",
"fs",
"->",
"create_file_from_string",
"(",
"$",
"record",
",",
"$",
"data",
")",
";",
"}",
"return",
"$",
"file",
";",
"}"
] |
Returns the stored thumbnail file, generates it if not present.
@param string $filepath current path in repository (dir and filename)
@param string $thumbsize 'thumb' or 'icon'
@return null|stored_file
|
[
"Returns",
"the",
"stored",
"thumbnail",
"file",
"generates",
"it",
"if",
"not",
"present",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/filesystem/lib.php#L697-L735
|
216,509
|
moodle/moodle
|
repository/filesystem/lib.php
|
repository_filesystem.send_relative_file
|
public function send_relative_file(stored_file $mainfile, $relativepath) {
global $CFG;
// Check if this repository is allowed to use relative linking.
$allowlinks = $this->supports_relative_file();
if (!empty($allowlinks)) {
// Get path to the mainfile.
$mainfilepath = $mainfile->get_source();
// Strip out filename from the path.
$filename = $mainfile->get_filename();
$basepath = strstr($mainfilepath, $filename, true);
$fullrelativefilepath = realpath($this->get_rootpath().$basepath.$relativepath);
// Sanity check to make sure this path is inside this repository and the file exists.
if (strpos($fullrelativefilepath, realpath($this->get_rootpath())) === 0 && file_exists($fullrelativefilepath)) {
send_file($fullrelativefilepath, basename($relativepath), null, 0);
}
}
send_file_not_found();
}
|
php
|
public function send_relative_file(stored_file $mainfile, $relativepath) {
global $CFG;
// Check if this repository is allowed to use relative linking.
$allowlinks = $this->supports_relative_file();
if (!empty($allowlinks)) {
// Get path to the mainfile.
$mainfilepath = $mainfile->get_source();
// Strip out filename from the path.
$filename = $mainfile->get_filename();
$basepath = strstr($mainfilepath, $filename, true);
$fullrelativefilepath = realpath($this->get_rootpath().$basepath.$relativepath);
// Sanity check to make sure this path is inside this repository and the file exists.
if (strpos($fullrelativefilepath, realpath($this->get_rootpath())) === 0 && file_exists($fullrelativefilepath)) {
send_file($fullrelativefilepath, basename($relativepath), null, 0);
}
}
send_file_not_found();
}
|
[
"public",
"function",
"send_relative_file",
"(",
"stored_file",
"$",
"mainfile",
",",
"$",
"relativepath",
")",
"{",
"global",
"$",
"CFG",
";",
"// Check if this repository is allowed to use relative linking.",
"$",
"allowlinks",
"=",
"$",
"this",
"->",
"supports_relative_file",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"allowlinks",
")",
")",
"{",
"// Get path to the mainfile.",
"$",
"mainfilepath",
"=",
"$",
"mainfile",
"->",
"get_source",
"(",
")",
";",
"// Strip out filename from the path.",
"$",
"filename",
"=",
"$",
"mainfile",
"->",
"get_filename",
"(",
")",
";",
"$",
"basepath",
"=",
"strstr",
"(",
"$",
"mainfilepath",
",",
"$",
"filename",
",",
"true",
")",
";",
"$",
"fullrelativefilepath",
"=",
"realpath",
"(",
"$",
"this",
"->",
"get_rootpath",
"(",
")",
".",
"$",
"basepath",
".",
"$",
"relativepath",
")",
";",
"// Sanity check to make sure this path is inside this repository and the file exists.",
"if",
"(",
"strpos",
"(",
"$",
"fullrelativefilepath",
",",
"realpath",
"(",
"$",
"this",
"->",
"get_rootpath",
"(",
")",
")",
")",
"===",
"0",
"&&",
"file_exists",
"(",
"$",
"fullrelativefilepath",
")",
")",
"{",
"send_file",
"(",
"$",
"fullrelativefilepath",
",",
"basename",
"(",
"$",
"relativepath",
")",
",",
"null",
",",
"0",
")",
";",
"}",
"}",
"send_file_not_found",
"(",
")",
";",
"}"
] |
Gets a file relative to this file in the repository and sends it to the browser.
@param stored_file $mainfile The main file we are trying to access relative files for.
@param string $relativepath the relative path to the file we are trying to access.
|
[
"Gets",
"a",
"file",
"relative",
"to",
"this",
"file",
"in",
"the",
"repository",
"and",
"sends",
"it",
"to",
"the",
"browser",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/filesystem/lib.php#L786-L806
|
216,510
|
moodle/moodle
|
webservice/renderer.php
|
core_webservice_renderer.admin_authorised_user_list
|
public function admin_authorised_user_list($users, $serviceid) {
global $CFG;
$html = $this->output->box_start('generalbox', 'alloweduserlist');
foreach ($users as $user) {
$modifiedauthoriseduserurl = new moodle_url('/' . $CFG->admin . '/webservice/service_user_settings.php',
array('userid' => $user->id, 'serviceid' => $serviceid));
$html .= html_writer::tag('a', $user->firstname . " "
. $user->lastname . ", " . $user->email,
array('href' => $modifiedauthoriseduserurl));
//add missing capabilities
if (!empty($user->missingcapabilities)) {
$html .= html_writer::tag('div',
get_string('usermissingcaps', 'webservice', $user->missingcapabilities)
. ' ' . $this->output->help_icon('missingcaps', 'webservice'),
array('class' => 'missingcaps', 'id' => 'usermissingcaps'));
$html .= html_writer::empty_tag('br');
} else {
$html .= html_writer::empty_tag('br') . html_writer::empty_tag('br');
}
}
$html .= $this->output->box_end();
return $html;
}
|
php
|
public function admin_authorised_user_list($users, $serviceid) {
global $CFG;
$html = $this->output->box_start('generalbox', 'alloweduserlist');
foreach ($users as $user) {
$modifiedauthoriseduserurl = new moodle_url('/' . $CFG->admin . '/webservice/service_user_settings.php',
array('userid' => $user->id, 'serviceid' => $serviceid));
$html .= html_writer::tag('a', $user->firstname . " "
. $user->lastname . ", " . $user->email,
array('href' => $modifiedauthoriseduserurl));
//add missing capabilities
if (!empty($user->missingcapabilities)) {
$html .= html_writer::tag('div',
get_string('usermissingcaps', 'webservice', $user->missingcapabilities)
. ' ' . $this->output->help_icon('missingcaps', 'webservice'),
array('class' => 'missingcaps', 'id' => 'usermissingcaps'));
$html .= html_writer::empty_tag('br');
} else {
$html .= html_writer::empty_tag('br') . html_writer::empty_tag('br');
}
}
$html .= $this->output->box_end();
return $html;
}
|
[
"public",
"function",
"admin_authorised_user_list",
"(",
"$",
"users",
",",
"$",
"serviceid",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"html",
"=",
"$",
"this",
"->",
"output",
"->",
"box_start",
"(",
"'generalbox'",
",",
"'alloweduserlist'",
")",
";",
"foreach",
"(",
"$",
"users",
"as",
"$",
"user",
")",
"{",
"$",
"modifiedauthoriseduserurl",
"=",
"new",
"moodle_url",
"(",
"'/'",
".",
"$",
"CFG",
"->",
"admin",
".",
"'/webservice/service_user_settings.php'",
",",
"array",
"(",
"'userid'",
"=>",
"$",
"user",
"->",
"id",
",",
"'serviceid'",
"=>",
"$",
"serviceid",
")",
")",
";",
"$",
"html",
".=",
"html_writer",
"::",
"tag",
"(",
"'a'",
",",
"$",
"user",
"->",
"firstname",
".",
"\" \"",
".",
"$",
"user",
"->",
"lastname",
".",
"\", \"",
".",
"$",
"user",
"->",
"email",
",",
"array",
"(",
"'href'",
"=>",
"$",
"modifiedauthoriseduserurl",
")",
")",
";",
"//add missing capabilities",
"if",
"(",
"!",
"empty",
"(",
"$",
"user",
"->",
"missingcapabilities",
")",
")",
"{",
"$",
"html",
".=",
"html_writer",
"::",
"tag",
"(",
"'div'",
",",
"get_string",
"(",
"'usermissingcaps'",
",",
"'webservice'",
",",
"$",
"user",
"->",
"missingcapabilities",
")",
".",
"' '",
".",
"$",
"this",
"->",
"output",
"->",
"help_icon",
"(",
"'missingcaps'",
",",
"'webservice'",
")",
",",
"array",
"(",
"'class'",
"=>",
"'missingcaps'",
",",
"'id'",
"=>",
"'usermissingcaps'",
")",
")",
";",
"$",
"html",
".=",
"html_writer",
"::",
"empty_tag",
"(",
"'br'",
")",
";",
"}",
"else",
"{",
"$",
"html",
".=",
"html_writer",
"::",
"empty_tag",
"(",
"'br'",
")",
".",
"html_writer",
"::",
"empty_tag",
"(",
"'br'",
")",
";",
"}",
"}",
"$",
"html",
".=",
"$",
"this",
"->",
"output",
"->",
"box_end",
"(",
")",
";",
"return",
"$",
"html",
";",
"}"
] |
Display list of authorised users
@param array $users authorised users
@param int $serviceid service id
@return string $html
|
[
"Display",
"list",
"of",
"authorised",
"users"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/webservice/renderer.php#L105-L127
|
216,511
|
moodle/moodle
|
webservice/renderer.php
|
core_webservice_renderer.admin_remove_service_function_confirmation
|
public function admin_remove_service_function_confirmation($function, $service) {
$optionsyes = array('id' => $service->id, 'action' => 'delete',
'confirm' => 1, 'sesskey' => sesskey(), 'fid' => $function->id);
$optionsno = array('id' => $service->id);
$formcontinue = new single_button(new moodle_url('service_functions.php',
$optionsyes), get_string('remove'));
$formcancel = new single_button(new moodle_url('service_functions.php',
$optionsno), get_string('cancel'), 'get');
return $this->output->confirm(get_string('removefunctionconfirm', 'webservice',
(object) array('service' => $service->name, 'function' => $function->name)),
$formcontinue, $formcancel);
}
|
php
|
public function admin_remove_service_function_confirmation($function, $service) {
$optionsyes = array('id' => $service->id, 'action' => 'delete',
'confirm' => 1, 'sesskey' => sesskey(), 'fid' => $function->id);
$optionsno = array('id' => $service->id);
$formcontinue = new single_button(new moodle_url('service_functions.php',
$optionsyes), get_string('remove'));
$formcancel = new single_button(new moodle_url('service_functions.php',
$optionsno), get_string('cancel'), 'get');
return $this->output->confirm(get_string('removefunctionconfirm', 'webservice',
(object) array('service' => $service->name, 'function' => $function->name)),
$formcontinue, $formcancel);
}
|
[
"public",
"function",
"admin_remove_service_function_confirmation",
"(",
"$",
"function",
",",
"$",
"service",
")",
"{",
"$",
"optionsyes",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"service",
"->",
"id",
",",
"'action'",
"=>",
"'delete'",
",",
"'confirm'",
"=>",
"1",
",",
"'sesskey'",
"=>",
"sesskey",
"(",
")",
",",
"'fid'",
"=>",
"$",
"function",
"->",
"id",
")",
";",
"$",
"optionsno",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"service",
"->",
"id",
")",
";",
"$",
"formcontinue",
"=",
"new",
"single_button",
"(",
"new",
"moodle_url",
"(",
"'service_functions.php'",
",",
"$",
"optionsyes",
")",
",",
"get_string",
"(",
"'remove'",
")",
")",
";",
"$",
"formcancel",
"=",
"new",
"single_button",
"(",
"new",
"moodle_url",
"(",
"'service_functions.php'",
",",
"$",
"optionsno",
")",
",",
"get_string",
"(",
"'cancel'",
")",
",",
"'get'",
")",
";",
"return",
"$",
"this",
"->",
"output",
"->",
"confirm",
"(",
"get_string",
"(",
"'removefunctionconfirm'",
",",
"'webservice'",
",",
"(",
"object",
")",
"array",
"(",
"'service'",
"=>",
"$",
"service",
"->",
"name",
",",
"'function'",
"=>",
"$",
"function",
"->",
"name",
")",
")",
",",
"$",
"formcontinue",
",",
"$",
"formcancel",
")",
";",
"}"
] |
Display a confirmation page to remove a function from a service
@param stdClass $function It needs function id + function name properties.
@param stdClass $service It needs service id + service name properties.
@return string html
|
[
"Display",
"a",
"confirmation",
"page",
"to",
"remove",
"a",
"function",
"from",
"a",
"service"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/webservice/renderer.php#L136-L147
|
216,512
|
moodle/moodle
|
webservice/renderer.php
|
core_webservice_renderer.admin_remove_service_confirmation
|
public function admin_remove_service_confirmation($service) {
global $CFG;
$optionsyes = array('id' => $service->id, 'action' => 'delete',
'confirm' => 1, 'sesskey' => sesskey());
$optionsno = array('section' => 'externalservices');
$formcontinue = new single_button(new moodle_url('service.php', $optionsyes),
get_string('delete'), 'post');
$formcancel = new single_button(
new moodle_url($CFG->wwwroot . "/" . $CFG->admin . "/settings.php", $optionsno),
get_string('cancel'), 'get');
return $this->output->confirm(get_string('deleteserviceconfirm', 'webservice', $service->name),
$formcontinue, $formcancel);
}
|
php
|
public function admin_remove_service_confirmation($service) {
global $CFG;
$optionsyes = array('id' => $service->id, 'action' => 'delete',
'confirm' => 1, 'sesskey' => sesskey());
$optionsno = array('section' => 'externalservices');
$formcontinue = new single_button(new moodle_url('service.php', $optionsyes),
get_string('delete'), 'post');
$formcancel = new single_button(
new moodle_url($CFG->wwwroot . "/" . $CFG->admin . "/settings.php", $optionsno),
get_string('cancel'), 'get');
return $this->output->confirm(get_string('deleteserviceconfirm', 'webservice', $service->name),
$formcontinue, $formcancel);
}
|
[
"public",
"function",
"admin_remove_service_confirmation",
"(",
"$",
"service",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"optionsyes",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"service",
"->",
"id",
",",
"'action'",
"=>",
"'delete'",
",",
"'confirm'",
"=>",
"1",
",",
"'sesskey'",
"=>",
"sesskey",
"(",
")",
")",
";",
"$",
"optionsno",
"=",
"array",
"(",
"'section'",
"=>",
"'externalservices'",
")",
";",
"$",
"formcontinue",
"=",
"new",
"single_button",
"(",
"new",
"moodle_url",
"(",
"'service.php'",
",",
"$",
"optionsyes",
")",
",",
"get_string",
"(",
"'delete'",
")",
",",
"'post'",
")",
";",
"$",
"formcancel",
"=",
"new",
"single_button",
"(",
"new",
"moodle_url",
"(",
"$",
"CFG",
"->",
"wwwroot",
".",
"\"/\"",
".",
"$",
"CFG",
"->",
"admin",
".",
"\"/settings.php\"",
",",
"$",
"optionsno",
")",
",",
"get_string",
"(",
"'cancel'",
")",
",",
"'get'",
")",
";",
"return",
"$",
"this",
"->",
"output",
"->",
"confirm",
"(",
"get_string",
"(",
"'deleteserviceconfirm'",
",",
"'webservice'",
",",
"$",
"service",
"->",
"name",
")",
",",
"$",
"formcontinue",
",",
"$",
"formcancel",
")",
";",
"}"
] |
Display a confirmation page to remove a service
@param stdClass $service It needs service id + service name properties.
@return string html
|
[
"Display",
"a",
"confirmation",
"page",
"to",
"remove",
"a",
"service"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/webservice/renderer.php#L155-L167
|
216,513
|
moodle/moodle
|
webservice/renderer.php
|
core_webservice_renderer.admin_delete_token_confirmation
|
public function admin_delete_token_confirmation($token) {
global $CFG;
$optionsyes = array('tokenid' => $token->id, 'action' => 'delete',
'confirm' => 1, 'sesskey' => sesskey());
$optionsno = array('section' => 'webservicetokens', 'sesskey' => sesskey());
$formcontinue = new single_button(
new moodle_url('/' . $CFG->admin . '/webservice/tokens.php', $optionsyes),
get_string('delete'));
$formcancel = new single_button(
new moodle_url('/' . $CFG->admin . '/settings.php', $optionsno),
get_string('cancel'), 'get');
return $this->output->confirm(get_string('deletetokenconfirm', 'webservice',
(object) array('user' => $token->firstname . " "
. $token->lastname, 'service' => $token->name)),
$formcontinue, $formcancel);
}
|
php
|
public function admin_delete_token_confirmation($token) {
global $CFG;
$optionsyes = array('tokenid' => $token->id, 'action' => 'delete',
'confirm' => 1, 'sesskey' => sesskey());
$optionsno = array('section' => 'webservicetokens', 'sesskey' => sesskey());
$formcontinue = new single_button(
new moodle_url('/' . $CFG->admin . '/webservice/tokens.php', $optionsyes),
get_string('delete'));
$formcancel = new single_button(
new moodle_url('/' . $CFG->admin . '/settings.php', $optionsno),
get_string('cancel'), 'get');
return $this->output->confirm(get_string('deletetokenconfirm', 'webservice',
(object) array('user' => $token->firstname . " "
. $token->lastname, 'service' => $token->name)),
$formcontinue, $formcancel);
}
|
[
"public",
"function",
"admin_delete_token_confirmation",
"(",
"$",
"token",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"optionsyes",
"=",
"array",
"(",
"'tokenid'",
"=>",
"$",
"token",
"->",
"id",
",",
"'action'",
"=>",
"'delete'",
",",
"'confirm'",
"=>",
"1",
",",
"'sesskey'",
"=>",
"sesskey",
"(",
")",
")",
";",
"$",
"optionsno",
"=",
"array",
"(",
"'section'",
"=>",
"'webservicetokens'",
",",
"'sesskey'",
"=>",
"sesskey",
"(",
")",
")",
";",
"$",
"formcontinue",
"=",
"new",
"single_button",
"(",
"new",
"moodle_url",
"(",
"'/'",
".",
"$",
"CFG",
"->",
"admin",
".",
"'/webservice/tokens.php'",
",",
"$",
"optionsyes",
")",
",",
"get_string",
"(",
"'delete'",
")",
")",
";",
"$",
"formcancel",
"=",
"new",
"single_button",
"(",
"new",
"moodle_url",
"(",
"'/'",
".",
"$",
"CFG",
"->",
"admin",
".",
"'/settings.php'",
",",
"$",
"optionsno",
")",
",",
"get_string",
"(",
"'cancel'",
")",
",",
"'get'",
")",
";",
"return",
"$",
"this",
"->",
"output",
"->",
"confirm",
"(",
"get_string",
"(",
"'deletetokenconfirm'",
",",
"'webservice'",
",",
"(",
"object",
")",
"array",
"(",
"'user'",
"=>",
"$",
"token",
"->",
"firstname",
".",
"\" \"",
".",
"$",
"token",
"->",
"lastname",
",",
"'service'",
"=>",
"$",
"token",
"->",
"name",
")",
")",
",",
"$",
"formcontinue",
",",
"$",
"formcancel",
")",
";",
"}"
] |
Display a confirmation page to delete a token
@param stdClass $token Required properties: id (token id), firstname (user firstname), lastname (user lastname), name (service name)
@return string html
|
[
"Display",
"a",
"confirmation",
"page",
"to",
"delete",
"a",
"token"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/webservice/renderer.php#L175-L190
|
216,514
|
moodle/moodle
|
webservice/renderer.php
|
core_webservice_renderer.user_reset_token_confirmation
|
public function user_reset_token_confirmation($token) {
global $CFG;
$managetokenurl = $CFG->wwwroot . "/user/managetoken.php?sesskey=" . sesskey();
$optionsyes = array('tokenid' => $token->id, 'action' => 'resetwstoken', 'confirm' => 1,
'sesskey' => sesskey());
$optionsno = array('section' => 'webservicetokens', 'sesskey' => sesskey());
$formcontinue = new single_button(new moodle_url($managetokenurl, $optionsyes),
get_string('reset'));
$formcancel = new single_button(new moodle_url($managetokenurl, $optionsno),
get_string('cancel'), 'get');
$html = $this->output->confirm(get_string('resettokenconfirm', 'webservice',
(object) array('user' => $token->firstname . " " .
$token->lastname, 'service' => $token->name)),
$formcontinue, $formcancel);
return $html;
}
|
php
|
public function user_reset_token_confirmation($token) {
global $CFG;
$managetokenurl = $CFG->wwwroot . "/user/managetoken.php?sesskey=" . sesskey();
$optionsyes = array('tokenid' => $token->id, 'action' => 'resetwstoken', 'confirm' => 1,
'sesskey' => sesskey());
$optionsno = array('section' => 'webservicetokens', 'sesskey' => sesskey());
$formcontinue = new single_button(new moodle_url($managetokenurl, $optionsyes),
get_string('reset'));
$formcancel = new single_button(new moodle_url($managetokenurl, $optionsno),
get_string('cancel'), 'get');
$html = $this->output->confirm(get_string('resettokenconfirm', 'webservice',
(object) array('user' => $token->firstname . " " .
$token->lastname, 'service' => $token->name)),
$formcontinue, $formcancel);
return $html;
}
|
[
"public",
"function",
"user_reset_token_confirmation",
"(",
"$",
"token",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"managetokenurl",
"=",
"$",
"CFG",
"->",
"wwwroot",
".",
"\"/user/managetoken.php?sesskey=\"",
".",
"sesskey",
"(",
")",
";",
"$",
"optionsyes",
"=",
"array",
"(",
"'tokenid'",
"=>",
"$",
"token",
"->",
"id",
",",
"'action'",
"=>",
"'resetwstoken'",
",",
"'confirm'",
"=>",
"1",
",",
"'sesskey'",
"=>",
"sesskey",
"(",
")",
")",
";",
"$",
"optionsno",
"=",
"array",
"(",
"'section'",
"=>",
"'webservicetokens'",
",",
"'sesskey'",
"=>",
"sesskey",
"(",
")",
")",
";",
"$",
"formcontinue",
"=",
"new",
"single_button",
"(",
"new",
"moodle_url",
"(",
"$",
"managetokenurl",
",",
"$",
"optionsyes",
")",
",",
"get_string",
"(",
"'reset'",
")",
")",
";",
"$",
"formcancel",
"=",
"new",
"single_button",
"(",
"new",
"moodle_url",
"(",
"$",
"managetokenurl",
",",
"$",
"optionsno",
")",
",",
"get_string",
"(",
"'cancel'",
")",
",",
"'get'",
")",
";",
"$",
"html",
"=",
"$",
"this",
"->",
"output",
"->",
"confirm",
"(",
"get_string",
"(",
"'resettokenconfirm'",
",",
"'webservice'",
",",
"(",
"object",
")",
"array",
"(",
"'user'",
"=>",
"$",
"token",
"->",
"firstname",
".",
"\" \"",
".",
"$",
"token",
"->",
"lastname",
",",
"'service'",
"=>",
"$",
"token",
"->",
"name",
")",
")",
",",
"$",
"formcontinue",
",",
"$",
"formcancel",
")",
";",
"return",
"$",
"html",
";",
"}"
] |
Display Reset token confirmation box
@param stdClass $token token to reset
@return string html
|
[
"Display",
"Reset",
"token",
"confirmation",
"box"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/webservice/renderer.php#L270-L285
|
216,515
|
moodle/moodle
|
webservice/renderer.php
|
core_webservice_renderer.detailed_description_html
|
public function detailed_description_html($params) {
// retrieve the description of the description object
$paramdesc = "";
if (!empty($params->desc)) {
$paramdesc .= html_writer::start_tag('span', array('style' => "color:#2A33A6"));
if ($params->required == VALUE_REQUIRED) {
$required = '';
}
if ($params->required == VALUE_DEFAULT) {
if ($params->default === null) {
$params->default = "null";
}
$required = html_writer::start_tag('b', array()) .
get_string('default', 'webservice', print_r($params->default, true))
. html_writer::end_tag('b');
}
if ($params->required == VALUE_OPTIONAL) {
$required = html_writer::start_tag('b', array()) .
get_string('optional', 'webservice') . html_writer::end_tag('b');
}
$paramdesc .= " " . $required . " ";
$paramdesc .= html_writer::start_tag('i', array());
$paramdesc .= "//";
$paramdesc .= s($params->desc);
$paramdesc .= html_writer::end_tag('i');
$paramdesc .= html_writer::end_tag('span');
$paramdesc .= html_writer::empty_tag('br', array());
}
// description object is a list
if ($params instanceof external_multiple_structure) {
return $paramdesc . "list of ( " . html_writer::empty_tag('br', array())
. $this->detailed_description_html($params->content) . ")";
} else if ($params instanceof external_single_structure) {
// description object is an object
$singlestructuredesc = $paramdesc . "object {" . html_writer::empty_tag('br', array());
foreach ($params->keys as $attributname => $attribut) {
$singlestructuredesc .= html_writer::start_tag('b', array());
$singlestructuredesc .= $attributname;
$singlestructuredesc .= html_writer::end_tag('b');
$singlestructuredesc .= " " .
$this->detailed_description_html($params->keys[$attributname]);
}
$singlestructuredesc .= "} ";
$singlestructuredesc .= html_writer::empty_tag('br', array());
return $singlestructuredesc;
} else {
// description object is a primary type (string, integer)
switch ($params->type) {
case PARAM_BOOL: // 0 or 1 only for now
case PARAM_INT:
$type = 'int';
break;
case PARAM_FLOAT;
$type = 'double';
break;
default:
$type = 'string';
}
return $type . " " . $paramdesc;
}
}
|
php
|
public function detailed_description_html($params) {
// retrieve the description of the description object
$paramdesc = "";
if (!empty($params->desc)) {
$paramdesc .= html_writer::start_tag('span', array('style' => "color:#2A33A6"));
if ($params->required == VALUE_REQUIRED) {
$required = '';
}
if ($params->required == VALUE_DEFAULT) {
if ($params->default === null) {
$params->default = "null";
}
$required = html_writer::start_tag('b', array()) .
get_string('default', 'webservice', print_r($params->default, true))
. html_writer::end_tag('b');
}
if ($params->required == VALUE_OPTIONAL) {
$required = html_writer::start_tag('b', array()) .
get_string('optional', 'webservice') . html_writer::end_tag('b');
}
$paramdesc .= " " . $required . " ";
$paramdesc .= html_writer::start_tag('i', array());
$paramdesc .= "//";
$paramdesc .= s($params->desc);
$paramdesc .= html_writer::end_tag('i');
$paramdesc .= html_writer::end_tag('span');
$paramdesc .= html_writer::empty_tag('br', array());
}
// description object is a list
if ($params instanceof external_multiple_structure) {
return $paramdesc . "list of ( " . html_writer::empty_tag('br', array())
. $this->detailed_description_html($params->content) . ")";
} else if ($params instanceof external_single_structure) {
// description object is an object
$singlestructuredesc = $paramdesc . "object {" . html_writer::empty_tag('br', array());
foreach ($params->keys as $attributname => $attribut) {
$singlestructuredesc .= html_writer::start_tag('b', array());
$singlestructuredesc .= $attributname;
$singlestructuredesc .= html_writer::end_tag('b');
$singlestructuredesc .= " " .
$this->detailed_description_html($params->keys[$attributname]);
}
$singlestructuredesc .= "} ";
$singlestructuredesc .= html_writer::empty_tag('br', array());
return $singlestructuredesc;
} else {
// description object is a primary type (string, integer)
switch ($params->type) {
case PARAM_BOOL: // 0 or 1 only for now
case PARAM_INT:
$type = 'int';
break;
case PARAM_FLOAT;
$type = 'double';
break;
default:
$type = 'string';
}
return $type . " " . $paramdesc;
}
}
|
[
"public",
"function",
"detailed_description_html",
"(",
"$",
"params",
")",
"{",
"// retrieve the description of the description object",
"$",
"paramdesc",
"=",
"\"\"",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"params",
"->",
"desc",
")",
")",
"{",
"$",
"paramdesc",
".=",
"html_writer",
"::",
"start_tag",
"(",
"'span'",
",",
"array",
"(",
"'style'",
"=>",
"\"color:#2A33A6\"",
")",
")",
";",
"if",
"(",
"$",
"params",
"->",
"required",
"==",
"VALUE_REQUIRED",
")",
"{",
"$",
"required",
"=",
"''",
";",
"}",
"if",
"(",
"$",
"params",
"->",
"required",
"==",
"VALUE_DEFAULT",
")",
"{",
"if",
"(",
"$",
"params",
"->",
"default",
"===",
"null",
")",
"{",
"$",
"params",
"->",
"default",
"=",
"\"null\"",
";",
"}",
"$",
"required",
"=",
"html_writer",
"::",
"start_tag",
"(",
"'b'",
",",
"array",
"(",
")",
")",
".",
"get_string",
"(",
"'default'",
",",
"'webservice'",
",",
"print_r",
"(",
"$",
"params",
"->",
"default",
",",
"true",
")",
")",
".",
"html_writer",
"::",
"end_tag",
"(",
"'b'",
")",
";",
"}",
"if",
"(",
"$",
"params",
"->",
"required",
"==",
"VALUE_OPTIONAL",
")",
"{",
"$",
"required",
"=",
"html_writer",
"::",
"start_tag",
"(",
"'b'",
",",
"array",
"(",
")",
")",
".",
"get_string",
"(",
"'optional'",
",",
"'webservice'",
")",
".",
"html_writer",
"::",
"end_tag",
"(",
"'b'",
")",
";",
"}",
"$",
"paramdesc",
".=",
"\" \"",
".",
"$",
"required",
".",
"\" \"",
";",
"$",
"paramdesc",
".=",
"html_writer",
"::",
"start_tag",
"(",
"'i'",
",",
"array",
"(",
")",
")",
";",
"$",
"paramdesc",
".=",
"\"//\"",
";",
"$",
"paramdesc",
".=",
"s",
"(",
"$",
"params",
"->",
"desc",
")",
";",
"$",
"paramdesc",
".=",
"html_writer",
"::",
"end_tag",
"(",
"'i'",
")",
";",
"$",
"paramdesc",
".=",
"html_writer",
"::",
"end_tag",
"(",
"'span'",
")",
";",
"$",
"paramdesc",
".=",
"html_writer",
"::",
"empty_tag",
"(",
"'br'",
",",
"array",
"(",
")",
")",
";",
"}",
"// description object is a list",
"if",
"(",
"$",
"params",
"instanceof",
"external_multiple_structure",
")",
"{",
"return",
"$",
"paramdesc",
".",
"\"list of ( \"",
".",
"html_writer",
"::",
"empty_tag",
"(",
"'br'",
",",
"array",
"(",
")",
")",
".",
"$",
"this",
"->",
"detailed_description_html",
"(",
"$",
"params",
"->",
"content",
")",
".",
"\")\"",
";",
"}",
"else",
"if",
"(",
"$",
"params",
"instanceof",
"external_single_structure",
")",
"{",
"// description object is an object",
"$",
"singlestructuredesc",
"=",
"$",
"paramdesc",
".",
"\"object {\"",
".",
"html_writer",
"::",
"empty_tag",
"(",
"'br'",
",",
"array",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"params",
"->",
"keys",
"as",
"$",
"attributname",
"=>",
"$",
"attribut",
")",
"{",
"$",
"singlestructuredesc",
".=",
"html_writer",
"::",
"start_tag",
"(",
"'b'",
",",
"array",
"(",
")",
")",
";",
"$",
"singlestructuredesc",
".=",
"$",
"attributname",
";",
"$",
"singlestructuredesc",
".=",
"html_writer",
"::",
"end_tag",
"(",
"'b'",
")",
";",
"$",
"singlestructuredesc",
".=",
"\" \"",
".",
"$",
"this",
"->",
"detailed_description_html",
"(",
"$",
"params",
"->",
"keys",
"[",
"$",
"attributname",
"]",
")",
";",
"}",
"$",
"singlestructuredesc",
".=",
"\"} \"",
";",
"$",
"singlestructuredesc",
".=",
"html_writer",
"::",
"empty_tag",
"(",
"'br'",
",",
"array",
"(",
")",
")",
";",
"return",
"$",
"singlestructuredesc",
";",
"}",
"else",
"{",
"// description object is a primary type (string, integer)",
"switch",
"(",
"$",
"params",
"->",
"type",
")",
"{",
"case",
"PARAM_BOOL",
":",
"// 0 or 1 only for now",
"case",
"PARAM_INT",
":",
"$",
"type",
"=",
"'int'",
";",
"break",
";",
"case",
"PARAM_FLOAT",
";",
"$",
"type",
"=",
"'double'",
";",
"break",
";",
"default",
":",
"$",
"type",
"=",
"'string'",
";",
"}",
"return",
"$",
"type",
".",
"\" \"",
".",
"$",
"paramdesc",
";",
"}",
"}"
] |
Return documentation for a ws description object
ws description object can be 'external_multiple_structure', 'external_single_structure'
or 'external_value'
Example of documentation for core_group_create_groups function:
list of (
object {
courseid int //id of course
name string //multilang compatible name, course unique
description string //group description text
enrolmentkey string //group enrol secret phrase
}
)
@param stdClass $params a part of parameter/return description
@return string the html to display
|
[
"Return",
"documentation",
"for",
"a",
"ws",
"description",
"object",
"ws",
"description",
"object",
"can",
"be",
"external_multiple_structure",
"external_single_structure",
"or",
"external_value"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/webservice/renderer.php#L389-L453
|
216,516
|
moodle/moodle
|
webservice/renderer.php
|
core_webservice_renderer.xmlrpc_param_description_html
|
public function xmlrpc_param_description_html($paramdescription, $indentation = "") {
$indentation = $indentation . " ";
$brakeline = <<<EOF
EOF;
// description object is a list
if ($paramdescription instanceof external_multiple_structure) {
$return = $brakeline . $indentation . "Array ";
$indentation = $indentation . " ";
$return .= $brakeline . $indentation . "(";
$return .= $brakeline . $indentation . "[0] =>";
$return .= $this->xmlrpc_param_description_html($paramdescription->content, $indentation);
$return .= $brakeline . $indentation . ")";
return $return;
} else if ($paramdescription instanceof external_single_structure) {
// description object is an object
$singlestructuredesc = $brakeline . $indentation . "Array ";
$keyindentation = $indentation . " ";
$singlestructuredesc .= $brakeline . $keyindentation . "(";
foreach ($paramdescription->keys as $attributname => $attribut) {
$singlestructuredesc .= $brakeline . $keyindentation . "[" . $attributname . "] =>" .
$this->xmlrpc_param_description_html(
$paramdescription->keys[$attributname], $keyindentation) .
$keyindentation;
}
$singlestructuredesc .= $brakeline . $keyindentation . ")";
return $singlestructuredesc;
} else {
// description object is a primary type (string, integer)
switch ($paramdescription->type) {
case PARAM_BOOL: // 0 or 1 only for now
case PARAM_INT:
$type = 'int';
break;
case PARAM_FLOAT;
$type = 'double';
break;
default:
$type = 'string';
}
return " " . $type;
}
}
|
php
|
public function xmlrpc_param_description_html($paramdescription, $indentation = "") {
$indentation = $indentation . " ";
$brakeline = <<<EOF
EOF;
// description object is a list
if ($paramdescription instanceof external_multiple_structure) {
$return = $brakeline . $indentation . "Array ";
$indentation = $indentation . " ";
$return .= $brakeline . $indentation . "(";
$return .= $brakeline . $indentation . "[0] =>";
$return .= $this->xmlrpc_param_description_html($paramdescription->content, $indentation);
$return .= $brakeline . $indentation . ")";
return $return;
} else if ($paramdescription instanceof external_single_structure) {
// description object is an object
$singlestructuredesc = $brakeline . $indentation . "Array ";
$keyindentation = $indentation . " ";
$singlestructuredesc .= $brakeline . $keyindentation . "(";
foreach ($paramdescription->keys as $attributname => $attribut) {
$singlestructuredesc .= $brakeline . $keyindentation . "[" . $attributname . "] =>" .
$this->xmlrpc_param_description_html(
$paramdescription->keys[$attributname], $keyindentation) .
$keyindentation;
}
$singlestructuredesc .= $brakeline . $keyindentation . ")";
return $singlestructuredesc;
} else {
// description object is a primary type (string, integer)
switch ($paramdescription->type) {
case PARAM_BOOL: // 0 or 1 only for now
case PARAM_INT:
$type = 'int';
break;
case PARAM_FLOAT;
$type = 'double';
break;
default:
$type = 'string';
}
return " " . $type;
}
}
|
[
"public",
"function",
"xmlrpc_param_description_html",
"(",
"$",
"paramdescription",
",",
"$",
"indentation",
"=",
"\"\"",
")",
"{",
"$",
"indentation",
"=",
"$",
"indentation",
".",
"\" \"",
";",
"$",
"brakeline",
"=",
" <<<EOF\n\n\nEOF",
";",
"// description object is a list",
"if",
"(",
"$",
"paramdescription",
"instanceof",
"external_multiple_structure",
")",
"{",
"$",
"return",
"=",
"$",
"brakeline",
".",
"$",
"indentation",
".",
"\"Array \"",
";",
"$",
"indentation",
"=",
"$",
"indentation",
".",
"\" \"",
";",
"$",
"return",
".=",
"$",
"brakeline",
".",
"$",
"indentation",
".",
"\"(\"",
";",
"$",
"return",
".=",
"$",
"brakeline",
".",
"$",
"indentation",
".",
"\"[0] =>\"",
";",
"$",
"return",
".=",
"$",
"this",
"->",
"xmlrpc_param_description_html",
"(",
"$",
"paramdescription",
"->",
"content",
",",
"$",
"indentation",
")",
";",
"$",
"return",
".=",
"$",
"brakeline",
".",
"$",
"indentation",
".",
"\")\"",
";",
"return",
"$",
"return",
";",
"}",
"else",
"if",
"(",
"$",
"paramdescription",
"instanceof",
"external_single_structure",
")",
"{",
"// description object is an object",
"$",
"singlestructuredesc",
"=",
"$",
"brakeline",
".",
"$",
"indentation",
".",
"\"Array \"",
";",
"$",
"keyindentation",
"=",
"$",
"indentation",
".",
"\" \"",
";",
"$",
"singlestructuredesc",
".=",
"$",
"brakeline",
".",
"$",
"keyindentation",
".",
"\"(\"",
";",
"foreach",
"(",
"$",
"paramdescription",
"->",
"keys",
"as",
"$",
"attributname",
"=>",
"$",
"attribut",
")",
"{",
"$",
"singlestructuredesc",
".=",
"$",
"brakeline",
".",
"$",
"keyindentation",
".",
"\"[\"",
".",
"$",
"attributname",
".",
"\"] =>\"",
".",
"$",
"this",
"->",
"xmlrpc_param_description_html",
"(",
"$",
"paramdescription",
"->",
"keys",
"[",
"$",
"attributname",
"]",
",",
"$",
"keyindentation",
")",
".",
"$",
"keyindentation",
";",
"}",
"$",
"singlestructuredesc",
".=",
"$",
"brakeline",
".",
"$",
"keyindentation",
".",
"\")\"",
";",
"return",
"$",
"singlestructuredesc",
";",
"}",
"else",
"{",
"// description object is a primary type (string, integer)",
"switch",
"(",
"$",
"paramdescription",
"->",
"type",
")",
"{",
"case",
"PARAM_BOOL",
":",
"// 0 or 1 only for now",
"case",
"PARAM_INT",
":",
"$",
"type",
"=",
"'int'",
";",
"break",
";",
"case",
"PARAM_FLOAT",
";",
"$",
"type",
"=",
"'double'",
";",
"break",
";",
"default",
":",
"$",
"type",
"=",
"'string'",
";",
"}",
"return",
"\" \"",
".",
"$",
"type",
";",
"}",
"}"
] |
Create indented XML-RPC param description
@param external_description $paramdescription the description structure of the web service function parameters
@param string $indentation Indentation in the generated HTML code; should contain only spaces.
@return string the html to diplay
|
[
"Create",
"indented",
"XML",
"-",
"RPC",
"param",
"description"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/webservice/renderer.php#L513-L556
|
216,517
|
moodle/moodle
|
webservice/renderer.php
|
core_webservice_renderer.colored_box_with_pre_tag
|
public function colored_box_with_pre_tag($title, $content, $rgb = 'FEEBE5') {
//TODO MDL-31192 this tag removes xhtml strict error but cause warning
$coloredbox = html_writer::start_tag('div', array());
$coloredbox .= html_writer::start_tag('div',
array('style' => "border:solid 1px #DEDEDE;background:#" . $rgb
. ";color:#222222;padding:4px;"));
$coloredbox .= html_writer::start_tag('pre', array());
$coloredbox .= html_writer::start_tag('b', array());
$coloredbox .= $title;
$coloredbox .= html_writer::end_tag('b', array());
$coloredbox .= html_writer::empty_tag('br', array());
$coloredbox .= "\n" . $content . "\n";
$coloredbox .= html_writer::end_tag('pre', array());
$coloredbox .= html_writer::end_tag('div', array());
$coloredbox .= html_writer::end_tag('div', array());
return $coloredbox;
}
|
php
|
public function colored_box_with_pre_tag($title, $content, $rgb = 'FEEBE5') {
//TODO MDL-31192 this tag removes xhtml strict error but cause warning
$coloredbox = html_writer::start_tag('div', array());
$coloredbox .= html_writer::start_tag('div',
array('style' => "border:solid 1px #DEDEDE;background:#" . $rgb
. ";color:#222222;padding:4px;"));
$coloredbox .= html_writer::start_tag('pre', array());
$coloredbox .= html_writer::start_tag('b', array());
$coloredbox .= $title;
$coloredbox .= html_writer::end_tag('b', array());
$coloredbox .= html_writer::empty_tag('br', array());
$coloredbox .= "\n" . $content . "\n";
$coloredbox .= html_writer::end_tag('pre', array());
$coloredbox .= html_writer::end_tag('div', array());
$coloredbox .= html_writer::end_tag('div', array());
return $coloredbox;
}
|
[
"public",
"function",
"colored_box_with_pre_tag",
"(",
"$",
"title",
",",
"$",
"content",
",",
"$",
"rgb",
"=",
"'FEEBE5'",
")",
"{",
"//TODO MDL-31192 this tag removes xhtml strict error but cause warning",
"$",
"coloredbox",
"=",
"html_writer",
"::",
"start_tag",
"(",
"'div'",
",",
"array",
"(",
")",
")",
";",
"$",
"coloredbox",
".=",
"html_writer",
"::",
"start_tag",
"(",
"'div'",
",",
"array",
"(",
"'style'",
"=>",
"\"border:solid 1px #DEDEDE;background:#\"",
".",
"$",
"rgb",
".",
"\";color:#222222;padding:4px;\"",
")",
")",
";",
"$",
"coloredbox",
".=",
"html_writer",
"::",
"start_tag",
"(",
"'pre'",
",",
"array",
"(",
")",
")",
";",
"$",
"coloredbox",
".=",
"html_writer",
"::",
"start_tag",
"(",
"'b'",
",",
"array",
"(",
")",
")",
";",
"$",
"coloredbox",
".=",
"$",
"title",
";",
"$",
"coloredbox",
".=",
"html_writer",
"::",
"end_tag",
"(",
"'b'",
",",
"array",
"(",
")",
")",
";",
"$",
"coloredbox",
".=",
"html_writer",
"::",
"empty_tag",
"(",
"'br'",
",",
"array",
"(",
")",
")",
";",
"$",
"coloredbox",
".=",
"\"\\n\"",
".",
"$",
"content",
".",
"\"\\n\"",
";",
"$",
"coloredbox",
".=",
"html_writer",
"::",
"end_tag",
"(",
"'pre'",
",",
"array",
"(",
")",
")",
";",
"$",
"coloredbox",
".=",
"html_writer",
"::",
"end_tag",
"(",
"'div'",
",",
"array",
"(",
")",
")",
";",
"$",
"coloredbox",
".=",
"html_writer",
"::",
"end_tag",
"(",
"'div'",
",",
"array",
"(",
")",
")",
";",
"return",
"$",
"coloredbox",
";",
"}"
] |
Return the html of a coloured box with content
@param string $title - the title of the box
@param string $content - the content to displayed
@param string $rgb - the background color of the box
@return string HTML code
|
[
"Return",
"the",
"html",
"of",
"a",
"coloured",
"box",
"with",
"content"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/webservice/renderer.php#L566-L582
|
216,518
|
moodle/moodle
|
webservice/renderer.php
|
core_webservice_renderer.rest_param_description_html
|
public function rest_param_description_html($paramdescription, $paramstring) {
$brakeline = <<<EOF
EOF;
// description object is a list
if ($paramdescription instanceof external_multiple_structure) {
$paramstring = $paramstring . '[0]';
$return = $this->rest_param_description_html($paramdescription->content, $paramstring);
return $return;
} else if ($paramdescription instanceof external_single_structure) {
// description object is an object
$singlestructuredesc = "";
$initialparamstring = $paramstring;
foreach ($paramdescription->keys as $attributname => $attribut) {
$paramstring = $initialparamstring . '[' . $attributname . ']';
$singlestructuredesc .= $this->rest_param_description_html(
$paramdescription->keys[$attributname], $paramstring);
}
return $singlestructuredesc;
} else {
// description object is a primary type (string, integer)
$paramstring = $paramstring . '=';
switch ($paramdescription->type) {
case PARAM_BOOL: // 0 or 1 only for now
case PARAM_INT:
$type = 'int';
break;
case PARAM_FLOAT;
$type = 'double';
break;
default:
$type = 'string';
}
return $paramstring . " " . $type . $brakeline;
}
}
|
php
|
public function rest_param_description_html($paramdescription, $paramstring) {
$brakeline = <<<EOF
EOF;
// description object is a list
if ($paramdescription instanceof external_multiple_structure) {
$paramstring = $paramstring . '[0]';
$return = $this->rest_param_description_html($paramdescription->content, $paramstring);
return $return;
} else if ($paramdescription instanceof external_single_structure) {
// description object is an object
$singlestructuredesc = "";
$initialparamstring = $paramstring;
foreach ($paramdescription->keys as $attributname => $attribut) {
$paramstring = $initialparamstring . '[' . $attributname . ']';
$singlestructuredesc .= $this->rest_param_description_html(
$paramdescription->keys[$attributname], $paramstring);
}
return $singlestructuredesc;
} else {
// description object is a primary type (string, integer)
$paramstring = $paramstring . '=';
switch ($paramdescription->type) {
case PARAM_BOOL: // 0 or 1 only for now
case PARAM_INT:
$type = 'int';
break;
case PARAM_FLOAT;
$type = 'double';
break;
default:
$type = 'string';
}
return $paramstring . " " . $type . $brakeline;
}
}
|
[
"public",
"function",
"rest_param_description_html",
"(",
"$",
"paramdescription",
",",
"$",
"paramstring",
")",
"{",
"$",
"brakeline",
"=",
" <<<EOF\n\n\nEOF",
";",
"// description object is a list",
"if",
"(",
"$",
"paramdescription",
"instanceof",
"external_multiple_structure",
")",
"{",
"$",
"paramstring",
"=",
"$",
"paramstring",
".",
"'[0]'",
";",
"$",
"return",
"=",
"$",
"this",
"->",
"rest_param_description_html",
"(",
"$",
"paramdescription",
"->",
"content",
",",
"$",
"paramstring",
")",
";",
"return",
"$",
"return",
";",
"}",
"else",
"if",
"(",
"$",
"paramdescription",
"instanceof",
"external_single_structure",
")",
"{",
"// description object is an object",
"$",
"singlestructuredesc",
"=",
"\"\"",
";",
"$",
"initialparamstring",
"=",
"$",
"paramstring",
";",
"foreach",
"(",
"$",
"paramdescription",
"->",
"keys",
"as",
"$",
"attributname",
"=>",
"$",
"attribut",
")",
"{",
"$",
"paramstring",
"=",
"$",
"initialparamstring",
".",
"'['",
".",
"$",
"attributname",
".",
"']'",
";",
"$",
"singlestructuredesc",
".=",
"$",
"this",
"->",
"rest_param_description_html",
"(",
"$",
"paramdescription",
"->",
"keys",
"[",
"$",
"attributname",
"]",
",",
"$",
"paramstring",
")",
";",
"}",
"return",
"$",
"singlestructuredesc",
";",
"}",
"else",
"{",
"// description object is a primary type (string, integer)",
"$",
"paramstring",
"=",
"$",
"paramstring",
".",
"'='",
";",
"switch",
"(",
"$",
"paramdescription",
"->",
"type",
")",
"{",
"case",
"PARAM_BOOL",
":",
"// 0 or 1 only for now",
"case",
"PARAM_INT",
":",
"$",
"type",
"=",
"'int'",
";",
"break",
";",
"case",
"PARAM_FLOAT",
";",
"$",
"type",
"=",
"'double'",
";",
"break",
";",
"default",
":",
"$",
"type",
"=",
"'string'",
";",
"}",
"return",
"$",
"paramstring",
".",
"\" \"",
".",
"$",
"type",
".",
"$",
"brakeline",
";",
"}",
"}"
] |
Return indented REST param description
@param external_description $paramdescription the description structure of the web service function parameters
@param string $paramstring parameter
@return string the html to diplay
|
[
"Return",
"indented",
"REST",
"param",
"description"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/webservice/renderer.php#L591-L627
|
216,519
|
moodle/moodle
|
admin/tool/lpimportcsv/classes/framework_importer.php
|
framework_importer.list_required_headers
|
public static function list_required_headers() {
return array(
get_string('parentidnumber', 'tool_lpimportcsv'),
get_string('idnumber', 'tool_lpimportcsv'),
get_string('shortname', 'tool_lpimportcsv'),
get_string('description', 'tool_lpimportcsv'),
get_string('descriptionformat', 'tool_lpimportcsv'),
get_string('scalevalues', 'tool_lpimportcsv'),
get_string('scaleconfiguration', 'tool_lpimportcsv'),
get_string('ruletype', 'tool_lpimportcsv'),
get_string('ruleoutcome', 'tool_lpimportcsv'),
get_string('ruleconfig', 'tool_lpimportcsv'),
get_string('relatedidnumbers', 'tool_lpimportcsv'),
get_string('exportid', 'tool_lpimportcsv'),
get_string('isframework', 'tool_lpimportcsv'),
get_string('taxonomy', 'tool_lpimportcsv'),
);
}
|
php
|
public static function list_required_headers() {
return array(
get_string('parentidnumber', 'tool_lpimportcsv'),
get_string('idnumber', 'tool_lpimportcsv'),
get_string('shortname', 'tool_lpimportcsv'),
get_string('description', 'tool_lpimportcsv'),
get_string('descriptionformat', 'tool_lpimportcsv'),
get_string('scalevalues', 'tool_lpimportcsv'),
get_string('scaleconfiguration', 'tool_lpimportcsv'),
get_string('ruletype', 'tool_lpimportcsv'),
get_string('ruleoutcome', 'tool_lpimportcsv'),
get_string('ruleconfig', 'tool_lpimportcsv'),
get_string('relatedidnumbers', 'tool_lpimportcsv'),
get_string('exportid', 'tool_lpimportcsv'),
get_string('isframework', 'tool_lpimportcsv'),
get_string('taxonomy', 'tool_lpimportcsv'),
);
}
|
[
"public",
"static",
"function",
"list_required_headers",
"(",
")",
"{",
"return",
"array",
"(",
"get_string",
"(",
"'parentidnumber'",
",",
"'tool_lpimportcsv'",
")",
",",
"get_string",
"(",
"'idnumber'",
",",
"'tool_lpimportcsv'",
")",
",",
"get_string",
"(",
"'shortname'",
",",
"'tool_lpimportcsv'",
")",
",",
"get_string",
"(",
"'description'",
",",
"'tool_lpimportcsv'",
")",
",",
"get_string",
"(",
"'descriptionformat'",
",",
"'tool_lpimportcsv'",
")",
",",
"get_string",
"(",
"'scalevalues'",
",",
"'tool_lpimportcsv'",
")",
",",
"get_string",
"(",
"'scaleconfiguration'",
",",
"'tool_lpimportcsv'",
")",
",",
"get_string",
"(",
"'ruletype'",
",",
"'tool_lpimportcsv'",
")",
",",
"get_string",
"(",
"'ruleoutcome'",
",",
"'tool_lpimportcsv'",
")",
",",
"get_string",
"(",
"'ruleconfig'",
",",
"'tool_lpimportcsv'",
")",
",",
"get_string",
"(",
"'relatedidnumbers'",
",",
"'tool_lpimportcsv'",
")",
",",
"get_string",
"(",
"'exportid'",
",",
"'tool_lpimportcsv'",
")",
",",
"get_string",
"(",
"'isframework'",
",",
"'tool_lpimportcsv'",
")",
",",
"get_string",
"(",
"'taxonomy'",
",",
"'tool_lpimportcsv'",
")",
",",
")",
";",
"}"
] |
Get the list of headers required for import.
@return array The headers (lang strings)
|
[
"Get",
"the",
"list",
"of",
"headers",
"required",
"for",
"import",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lpimportcsv/classes/framework_importer.php#L82-L99
|
216,520
|
moodle/moodle
|
admin/tool/lpimportcsv/classes/framework_importer.php
|
framework_importer.read_mapping_data
|
protected function read_mapping_data($data) {
if ($data) {
return array(
'parentidnumber' => $data->header0,
'idnumber' => $data->header1,
'shortname' => $data->header2,
'description' => $data->header3,
'descriptionformat' => $data->header4,
'scalevalues' => $data->header5,
'scaleconfiguration' => $data->header6,
'ruletype' => $data->header7,
'ruleoutcome' => $data->header8,
'ruleconfig' => $data->header9,
'relatedidnumbers' => $data->header10,
'exportid' => $data->header11,
'isframework' => $data->header12,
'taxonomies' => $data->header13
);
} else {
return array(
'parentidnumber' => 0,
'idnumber' => 1,
'shortname' => 2,
'description' => 3,
'descriptionformat' => 4,
'scalevalues' => 5,
'scaleconfiguration' => 6,
'ruletype' => 7,
'ruleoutcome' => 8,
'ruleconfig' => 9,
'relatedidnumbers' => 10,
'exportid' => 11,
'isframework' => 12,
'taxonomies' => 13
);
}
}
|
php
|
protected function read_mapping_data($data) {
if ($data) {
return array(
'parentidnumber' => $data->header0,
'idnumber' => $data->header1,
'shortname' => $data->header2,
'description' => $data->header3,
'descriptionformat' => $data->header4,
'scalevalues' => $data->header5,
'scaleconfiguration' => $data->header6,
'ruletype' => $data->header7,
'ruleoutcome' => $data->header8,
'ruleconfig' => $data->header9,
'relatedidnumbers' => $data->header10,
'exportid' => $data->header11,
'isframework' => $data->header12,
'taxonomies' => $data->header13
);
} else {
return array(
'parentidnumber' => 0,
'idnumber' => 1,
'shortname' => 2,
'description' => 3,
'descriptionformat' => 4,
'scalevalues' => 5,
'scaleconfiguration' => 6,
'ruletype' => 7,
'ruleoutcome' => 8,
'ruleconfig' => 9,
'relatedidnumbers' => 10,
'exportid' => 11,
'isframework' => 12,
'taxonomies' => 13
);
}
}
|
[
"protected",
"function",
"read_mapping_data",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"data",
")",
"{",
"return",
"array",
"(",
"'parentidnumber'",
"=>",
"$",
"data",
"->",
"header0",
",",
"'idnumber'",
"=>",
"$",
"data",
"->",
"header1",
",",
"'shortname'",
"=>",
"$",
"data",
"->",
"header2",
",",
"'description'",
"=>",
"$",
"data",
"->",
"header3",
",",
"'descriptionformat'",
"=>",
"$",
"data",
"->",
"header4",
",",
"'scalevalues'",
"=>",
"$",
"data",
"->",
"header5",
",",
"'scaleconfiguration'",
"=>",
"$",
"data",
"->",
"header6",
",",
"'ruletype'",
"=>",
"$",
"data",
"->",
"header7",
",",
"'ruleoutcome'",
"=>",
"$",
"data",
"->",
"header8",
",",
"'ruleconfig'",
"=>",
"$",
"data",
"->",
"header9",
",",
"'relatedidnumbers'",
"=>",
"$",
"data",
"->",
"header10",
",",
"'exportid'",
"=>",
"$",
"data",
"->",
"header11",
",",
"'isframework'",
"=>",
"$",
"data",
"->",
"header12",
",",
"'taxonomies'",
"=>",
"$",
"data",
"->",
"header13",
")",
";",
"}",
"else",
"{",
"return",
"array",
"(",
"'parentidnumber'",
"=>",
"0",
",",
"'idnumber'",
"=>",
"1",
",",
"'shortname'",
"=>",
"2",
",",
"'description'",
"=>",
"3",
",",
"'descriptionformat'",
"=>",
"4",
",",
"'scalevalues'",
"=>",
"5",
",",
"'scaleconfiguration'",
"=>",
"6",
",",
"'ruletype'",
"=>",
"7",
",",
"'ruleoutcome'",
"=>",
"8",
",",
"'ruleconfig'",
"=>",
"9",
",",
"'relatedidnumbers'",
"=>",
"10",
",",
"'exportid'",
"=>",
"11",
",",
"'isframework'",
"=>",
"12",
",",
"'taxonomies'",
"=>",
"13",
")",
";",
"}",
"}"
] |
Read the data from the mapping form.
@param array The mapping data.
|
[
"Read",
"the",
"data",
"from",
"the",
"mapping",
"form",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lpimportcsv/classes/framework_importer.php#L113-L149
|
216,521
|
moodle/moodle
|
admin/tool/lpimportcsv/classes/framework_importer.php
|
framework_importer.add_children
|
public function add_children(& $node, $parentidnumber) {
foreach ($this->flat as $competency) {
if ($competency->parentidnumber == $parentidnumber) {
$this->progress->increment_progress();
$node->children[] = $competency;
$this->add_children($competency, $competency->idnumber);
}
}
}
|
php
|
public function add_children(& $node, $parentidnumber) {
foreach ($this->flat as $competency) {
if ($competency->parentidnumber == $parentidnumber) {
$this->progress->increment_progress();
$node->children[] = $competency;
$this->add_children($competency, $competency->idnumber);
}
}
}
|
[
"public",
"function",
"add_children",
"(",
"&",
"$",
"node",
",",
"$",
"parentidnumber",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"flat",
"as",
"$",
"competency",
")",
"{",
"if",
"(",
"$",
"competency",
"->",
"parentidnumber",
"==",
"$",
"parentidnumber",
")",
"{",
"$",
"this",
"->",
"progress",
"->",
"increment_progress",
"(",
")",
";",
"$",
"node",
"->",
"children",
"[",
"]",
"=",
"$",
"competency",
";",
"$",
"this",
"->",
"add_children",
"(",
"$",
"competency",
",",
"$",
"competency",
"->",
"idnumber",
")",
";",
"}",
"}",
"}"
] |
Add a competency to the parent with the specified idnumber.
@param competency $node (pass by reference)
@param string $parentidnumber Add this competency to the parent with this idnumber.
|
[
"Add",
"a",
"competency",
"to",
"the",
"parent",
"with",
"the",
"specified",
"idnumber",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lpimportcsv/classes/framework_importer.php#L295-L303
|
216,522
|
moodle/moodle
|
admin/tool/lpimportcsv/classes/framework_importer.php
|
framework_importer.create_competency
|
public function create_competency($record, $parent, $framework) {
$competency = new stdClass();
$competency->competencyframeworkid = $framework->get('id');
$competency->shortname = $record->shortname;
if (!empty($record->description)) {
$competency->description = $record->description;
$competency->descriptionformat = $record->descriptionformat;
}
if ($record->scalevalues) {
$competency->scaleid = $this->get_scale_id($record->scalevalues, $competency->shortname);
$competency->scaleconfiguration = $this->get_scale_configuration($competency->scaleid, $record->scaleconfiguration);
}
if ($parent) {
$competency->parentid = $parent->get('id');
} else {
$competency->parentid = 0;
}
$competency->idnumber = $record->idnumber;
if (!empty($competency->idnumber) && !empty($competency->shortname)) {
$comp = api::create_competency($competency);
if ($record->exportid) {
$this->mappings[$record->exportid] = $comp;
}
$record->createdcomp = $comp;
foreach ($record->children as $child) {
$this->create_competency($child, $comp, $framework);
}
return $comp;
}
return false;
}
|
php
|
public function create_competency($record, $parent, $framework) {
$competency = new stdClass();
$competency->competencyframeworkid = $framework->get('id');
$competency->shortname = $record->shortname;
if (!empty($record->description)) {
$competency->description = $record->description;
$competency->descriptionformat = $record->descriptionformat;
}
if ($record->scalevalues) {
$competency->scaleid = $this->get_scale_id($record->scalevalues, $competency->shortname);
$competency->scaleconfiguration = $this->get_scale_configuration($competency->scaleid, $record->scaleconfiguration);
}
if ($parent) {
$competency->parentid = $parent->get('id');
} else {
$competency->parentid = 0;
}
$competency->idnumber = $record->idnumber;
if (!empty($competency->idnumber) && !empty($competency->shortname)) {
$comp = api::create_competency($competency);
if ($record->exportid) {
$this->mappings[$record->exportid] = $comp;
}
$record->createdcomp = $comp;
foreach ($record->children as $child) {
$this->create_competency($child, $comp, $framework);
}
return $comp;
}
return false;
}
|
[
"public",
"function",
"create_competency",
"(",
"$",
"record",
",",
"$",
"parent",
",",
"$",
"framework",
")",
"{",
"$",
"competency",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"competency",
"->",
"competencyframeworkid",
"=",
"$",
"framework",
"->",
"get",
"(",
"'id'",
")",
";",
"$",
"competency",
"->",
"shortname",
"=",
"$",
"record",
"->",
"shortname",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"record",
"->",
"description",
")",
")",
"{",
"$",
"competency",
"->",
"description",
"=",
"$",
"record",
"->",
"description",
";",
"$",
"competency",
"->",
"descriptionformat",
"=",
"$",
"record",
"->",
"descriptionformat",
";",
"}",
"if",
"(",
"$",
"record",
"->",
"scalevalues",
")",
"{",
"$",
"competency",
"->",
"scaleid",
"=",
"$",
"this",
"->",
"get_scale_id",
"(",
"$",
"record",
"->",
"scalevalues",
",",
"$",
"competency",
"->",
"shortname",
")",
";",
"$",
"competency",
"->",
"scaleconfiguration",
"=",
"$",
"this",
"->",
"get_scale_configuration",
"(",
"$",
"competency",
"->",
"scaleid",
",",
"$",
"record",
"->",
"scaleconfiguration",
")",
";",
"}",
"if",
"(",
"$",
"parent",
")",
"{",
"$",
"competency",
"->",
"parentid",
"=",
"$",
"parent",
"->",
"get",
"(",
"'id'",
")",
";",
"}",
"else",
"{",
"$",
"competency",
"->",
"parentid",
"=",
"0",
";",
"}",
"$",
"competency",
"->",
"idnumber",
"=",
"$",
"record",
"->",
"idnumber",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"competency",
"->",
"idnumber",
")",
"&&",
"!",
"empty",
"(",
"$",
"competency",
"->",
"shortname",
")",
")",
"{",
"$",
"comp",
"=",
"api",
"::",
"create_competency",
"(",
"$",
"competency",
")",
";",
"if",
"(",
"$",
"record",
"->",
"exportid",
")",
"{",
"$",
"this",
"->",
"mappings",
"[",
"$",
"record",
"->",
"exportid",
"]",
"=",
"$",
"comp",
";",
"}",
"$",
"record",
"->",
"createdcomp",
"=",
"$",
"comp",
";",
"foreach",
"(",
"$",
"record",
"->",
"children",
"as",
"$",
"child",
")",
"{",
"$",
"this",
"->",
"create_competency",
"(",
"$",
"child",
",",
"$",
"comp",
",",
"$",
"framework",
")",
";",
"}",
"return",
"$",
"comp",
";",
"}",
"return",
"false",
";",
"}"
] |
Recursive function to add a competency with all it's children.
@param stdClass $record Raw data for the new competency
@param competency $parent
@param competency_framework $framework
|
[
"Recursive",
"function",
"to",
"add",
"a",
"competency",
"with",
"all",
"it",
"s",
"children",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lpimportcsv/classes/framework_importer.php#L320-L352
|
216,523
|
moodle/moodle
|
admin/tool/lpimportcsv/classes/framework_importer.php
|
framework_importer.get_scale_configuration
|
public function get_scale_configuration($scaleid, $config) {
$asarray = json_decode($config);
$asarray[0]->scaleid = $scaleid;
return json_encode($asarray);
}
|
php
|
public function get_scale_configuration($scaleid, $config) {
$asarray = json_decode($config);
$asarray[0]->scaleid = $scaleid;
return json_encode($asarray);
}
|
[
"public",
"function",
"get_scale_configuration",
"(",
"$",
"scaleid",
",",
"$",
"config",
")",
"{",
"$",
"asarray",
"=",
"json_decode",
"(",
"$",
"config",
")",
";",
"$",
"asarray",
"[",
"0",
"]",
"->",
"scaleid",
"=",
"$",
"scaleid",
";",
"return",
"json_encode",
"(",
"$",
"asarray",
")",
";",
"}"
] |
Recreate the scale config to point to a new scaleid.
@param int $scaleid
@param string $config json encoded scale data.
|
[
"Recreate",
"the",
"scale",
"config",
"to",
"point",
"to",
"a",
"new",
"scaleid",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lpimportcsv/classes/framework_importer.php#L359-L363
|
216,524
|
moodle/moodle
|
admin/tool/lpimportcsv/classes/framework_importer.php
|
framework_importer.get_scale_id
|
public function get_scale_id($scalevalues, $competencyname) {
global $CFG, $USER;
require_once($CFG->libdir . '/gradelib.php');
if (empty($this->scalecache)) {
$allscales = grade_scale::fetch_all_global();
foreach ($allscales as $scale) {
$scale->load_items();
$this->scalecache[$scale->compact_items()] = $scale;
}
}
$matchingscale = false;
if (isset($this->scalecache[$scalevalues])) {
$matchingscale = $this->scalecache[$scalevalues];
}
if (!$matchingscale) {
// Create it.
$newscale = new grade_scale();
$newscale->name = get_string('competencyscale', 'tool_lpimportcsv', $competencyname);
$newscale->courseid = 0;
$newscale->userid = $USER->id;
$newscale->scale = $scalevalues;
$newscale->description = get_string('competencyscaledescription', 'tool_lpimportcsv');
$newscale->insert();
$this->scalecache[$scalevalues] = $newscale;
return $newscale->id;
}
return $matchingscale->id;
}
|
php
|
public function get_scale_id($scalevalues, $competencyname) {
global $CFG, $USER;
require_once($CFG->libdir . '/gradelib.php');
if (empty($this->scalecache)) {
$allscales = grade_scale::fetch_all_global();
foreach ($allscales as $scale) {
$scale->load_items();
$this->scalecache[$scale->compact_items()] = $scale;
}
}
$matchingscale = false;
if (isset($this->scalecache[$scalevalues])) {
$matchingscale = $this->scalecache[$scalevalues];
}
if (!$matchingscale) {
// Create it.
$newscale = new grade_scale();
$newscale->name = get_string('competencyscale', 'tool_lpimportcsv', $competencyname);
$newscale->courseid = 0;
$newscale->userid = $USER->id;
$newscale->scale = $scalevalues;
$newscale->description = get_string('competencyscaledescription', 'tool_lpimportcsv');
$newscale->insert();
$this->scalecache[$scalevalues] = $newscale;
return $newscale->id;
}
return $matchingscale->id;
}
|
[
"public",
"function",
"get_scale_id",
"(",
"$",
"scalevalues",
",",
"$",
"competencyname",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"USER",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"libdir",
".",
"'/gradelib.php'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"scalecache",
")",
")",
"{",
"$",
"allscales",
"=",
"grade_scale",
"::",
"fetch_all_global",
"(",
")",
";",
"foreach",
"(",
"$",
"allscales",
"as",
"$",
"scale",
")",
"{",
"$",
"scale",
"->",
"load_items",
"(",
")",
";",
"$",
"this",
"->",
"scalecache",
"[",
"$",
"scale",
"->",
"compact_items",
"(",
")",
"]",
"=",
"$",
"scale",
";",
"}",
"}",
"$",
"matchingscale",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"scalecache",
"[",
"$",
"scalevalues",
"]",
")",
")",
"{",
"$",
"matchingscale",
"=",
"$",
"this",
"->",
"scalecache",
"[",
"$",
"scalevalues",
"]",
";",
"}",
"if",
"(",
"!",
"$",
"matchingscale",
")",
"{",
"// Create it.",
"$",
"newscale",
"=",
"new",
"grade_scale",
"(",
")",
";",
"$",
"newscale",
"->",
"name",
"=",
"get_string",
"(",
"'competencyscale'",
",",
"'tool_lpimportcsv'",
",",
"$",
"competencyname",
")",
";",
"$",
"newscale",
"->",
"courseid",
"=",
"0",
";",
"$",
"newscale",
"->",
"userid",
"=",
"$",
"USER",
"->",
"id",
";",
"$",
"newscale",
"->",
"scale",
"=",
"$",
"scalevalues",
";",
"$",
"newscale",
"->",
"description",
"=",
"get_string",
"(",
"'competencyscaledescription'",
",",
"'tool_lpimportcsv'",
")",
";",
"$",
"newscale",
"->",
"insert",
"(",
")",
";",
"$",
"this",
"->",
"scalecache",
"[",
"$",
"scalevalues",
"]",
"=",
"$",
"newscale",
";",
"return",
"$",
"newscale",
"->",
"id",
";",
"}",
"return",
"$",
"matchingscale",
"->",
"id",
";",
"}"
] |
Search for a global scale that matches this set of scalevalues.
If one is not found it will be created.
@param array $scalevalues
@param string $competencyname (Used to create a new scale if required)
@return int The id of the scale
|
[
"Search",
"for",
"a",
"global",
"scale",
"that",
"matches",
"this",
"set",
"of",
"scalevalues",
".",
"If",
"one",
"is",
"not",
"found",
"it",
"will",
"be",
"created",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lpimportcsv/classes/framework_importer.php#L372-L401
|
216,525
|
moodle/moodle
|
admin/tool/lpimportcsv/classes/framework_importer.php
|
framework_importer.set_related
|
protected function set_related($record) {
$comp = $record->createdcomp;
if ($record->relatedidnumbers) {
$allidnumbers = explode(',', $record->relatedidnumbers);
foreach ($allidnumbers as $rawidnumber) {
$idnumber = str_replace('%2C', ',', $rawidnumber);
if (isset($this->flat[$idnumber])) {
$relatedcomp = $this->flat[$idnumber]->createdcomp;
api::add_related_competency($comp->get('id'), $relatedcomp->get('id'));
}
}
}
foreach ($record->children as $child) {
$this->set_related($child);
}
}
|
php
|
protected function set_related($record) {
$comp = $record->createdcomp;
if ($record->relatedidnumbers) {
$allidnumbers = explode(',', $record->relatedidnumbers);
foreach ($allidnumbers as $rawidnumber) {
$idnumber = str_replace('%2C', ',', $rawidnumber);
if (isset($this->flat[$idnumber])) {
$relatedcomp = $this->flat[$idnumber]->createdcomp;
api::add_related_competency($comp->get('id'), $relatedcomp->get('id'));
}
}
}
foreach ($record->children as $child) {
$this->set_related($child);
}
}
|
[
"protected",
"function",
"set_related",
"(",
"$",
"record",
")",
"{",
"$",
"comp",
"=",
"$",
"record",
"->",
"createdcomp",
";",
"if",
"(",
"$",
"record",
"->",
"relatedidnumbers",
")",
"{",
"$",
"allidnumbers",
"=",
"explode",
"(",
"','",
",",
"$",
"record",
"->",
"relatedidnumbers",
")",
";",
"foreach",
"(",
"$",
"allidnumbers",
"as",
"$",
"rawidnumber",
")",
"{",
"$",
"idnumber",
"=",
"str_replace",
"(",
"'%2C'",
",",
"','",
",",
"$",
"rawidnumber",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"flat",
"[",
"$",
"idnumber",
"]",
")",
")",
"{",
"$",
"relatedcomp",
"=",
"$",
"this",
"->",
"flat",
"[",
"$",
"idnumber",
"]",
"->",
"createdcomp",
";",
"api",
"::",
"add_related_competency",
"(",
"$",
"comp",
"->",
"get",
"(",
"'id'",
")",
",",
"$",
"relatedcomp",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"}",
"}",
"}",
"foreach",
"(",
"$",
"record",
"->",
"children",
"as",
"$",
"child",
")",
"{",
"$",
"this",
"->",
"set_related",
"(",
"$",
"child",
")",
";",
"}",
"}"
] |
Walk through the idnumbers in the relatedidnumbers col and set the relations.
@param stdClass $record
|
[
"Walk",
"through",
"the",
"idnumbers",
"in",
"the",
"relatedidnumbers",
"col",
"and",
"set",
"the",
"relations",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lpimportcsv/classes/framework_importer.php#L407-L423
|
216,526
|
moodle/moodle
|
admin/tool/lpimportcsv/classes/framework_importer.php
|
framework_importer.set_rules
|
protected function set_rules($record) {
$comp = $record->createdcomp;
if ($record->ruletype) {
$class = $record->ruletype;
if (class_exists($class)) {
$oldruleconfig = $record->ruleconfig;
if ($oldruleconfig == "null") {
$oldruleconfig = null;
}
$newruleconfig = $class::migrate_config($oldruleconfig, $this->mappings);
$comp->set('ruleconfig', $newruleconfig);
$comp->set('ruletype', $class);
$comp->set('ruleoutcome', $record->ruleoutcome);
$comp->update();
}
}
foreach ($record->children as $child) {
$this->set_rules($child);
}
}
|
php
|
protected function set_rules($record) {
$comp = $record->createdcomp;
if ($record->ruletype) {
$class = $record->ruletype;
if (class_exists($class)) {
$oldruleconfig = $record->ruleconfig;
if ($oldruleconfig == "null") {
$oldruleconfig = null;
}
$newruleconfig = $class::migrate_config($oldruleconfig, $this->mappings);
$comp->set('ruleconfig', $newruleconfig);
$comp->set('ruletype', $class);
$comp->set('ruleoutcome', $record->ruleoutcome);
$comp->update();
}
}
foreach ($record->children as $child) {
$this->set_rules($child);
}
}
|
[
"protected",
"function",
"set_rules",
"(",
"$",
"record",
")",
"{",
"$",
"comp",
"=",
"$",
"record",
"->",
"createdcomp",
";",
"if",
"(",
"$",
"record",
"->",
"ruletype",
")",
"{",
"$",
"class",
"=",
"$",
"record",
"->",
"ruletype",
";",
"if",
"(",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"$",
"oldruleconfig",
"=",
"$",
"record",
"->",
"ruleconfig",
";",
"if",
"(",
"$",
"oldruleconfig",
"==",
"\"null\"",
")",
"{",
"$",
"oldruleconfig",
"=",
"null",
";",
"}",
"$",
"newruleconfig",
"=",
"$",
"class",
"::",
"migrate_config",
"(",
"$",
"oldruleconfig",
",",
"$",
"this",
"->",
"mappings",
")",
";",
"$",
"comp",
"->",
"set",
"(",
"'ruleconfig'",
",",
"$",
"newruleconfig",
")",
";",
"$",
"comp",
"->",
"set",
"(",
"'ruletype'",
",",
"$",
"class",
")",
";",
"$",
"comp",
"->",
"set",
"(",
"'ruleoutcome'",
",",
"$",
"record",
"->",
"ruleoutcome",
")",
";",
"$",
"comp",
"->",
"update",
"(",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"record",
"->",
"children",
"as",
"$",
"child",
")",
"{",
"$",
"this",
"->",
"set_rules",
"(",
"$",
"child",
")",
";",
"}",
"}"
] |
Create any completion rule attached to this competency.
@param stdClass $record
|
[
"Create",
"any",
"completion",
"rule",
"attached",
"to",
"this",
"competency",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lpimportcsv/classes/framework_importer.php#L429-L448
|
216,527
|
moodle/moodle
|
grade/report/user/renderer.php
|
gradereport_user_renderer.view_user_selector
|
public function view_user_selector($userid, $userview) {
global $PAGE, $USER;
$url = $PAGE->url;
if ($userid != $USER->id) {
$url->param('userid', $userid);
}
$options = array(GRADE_REPORT_USER_VIEW_USER => get_string('otheruser', 'gradereport_user'),
GRADE_REPORT_USER_VIEW_SELF => get_string('myself', 'gradereport_user'));
$select = new single_select($url, 'userview', $options, $userview, null);
$select->label = get_string('viewas', 'gradereport_user');
$output = html_writer::tag('div', $this->output->render($select), array('class' => 'view_users_selector'));
return $output;
}
|
php
|
public function view_user_selector($userid, $userview) {
global $PAGE, $USER;
$url = $PAGE->url;
if ($userid != $USER->id) {
$url->param('userid', $userid);
}
$options = array(GRADE_REPORT_USER_VIEW_USER => get_string('otheruser', 'gradereport_user'),
GRADE_REPORT_USER_VIEW_SELF => get_string('myself', 'gradereport_user'));
$select = new single_select($url, 'userview', $options, $userview, null);
$select->label = get_string('viewas', 'gradereport_user');
$output = html_writer::tag('div', $this->output->render($select), array('class' => 'view_users_selector'));
return $output;
}
|
[
"public",
"function",
"view_user_selector",
"(",
"$",
"userid",
",",
"$",
"userview",
")",
"{",
"global",
"$",
"PAGE",
",",
"$",
"USER",
";",
"$",
"url",
"=",
"$",
"PAGE",
"->",
"url",
";",
"if",
"(",
"$",
"userid",
"!=",
"$",
"USER",
"->",
"id",
")",
"{",
"$",
"url",
"->",
"param",
"(",
"'userid'",
",",
"$",
"userid",
")",
";",
"}",
"$",
"options",
"=",
"array",
"(",
"GRADE_REPORT_USER_VIEW_USER",
"=>",
"get_string",
"(",
"'otheruser'",
",",
"'gradereport_user'",
")",
",",
"GRADE_REPORT_USER_VIEW_SELF",
"=>",
"get_string",
"(",
"'myself'",
",",
"'gradereport_user'",
")",
")",
";",
"$",
"select",
"=",
"new",
"single_select",
"(",
"$",
"url",
",",
"'userview'",
",",
"$",
"options",
",",
"$",
"userview",
",",
"null",
")",
";",
"$",
"select",
"->",
"label",
"=",
"get_string",
"(",
"'viewas'",
",",
"'gradereport_user'",
")",
";",
"$",
"output",
"=",
"html_writer",
"::",
"tag",
"(",
"'div'",
",",
"$",
"this",
"->",
"output",
"->",
"render",
"(",
"$",
"select",
")",
",",
"array",
"(",
"'class'",
"=>",
"'view_users_selector'",
")",
")",
";",
"return",
"$",
"output",
";",
"}"
] |
Creates and renders the single select box for the user view.
@param int $userid The selected userid
@param int $userview The current view user setting constant
@return string
|
[
"Creates",
"and",
"renders",
"the",
"single",
"select",
"box",
"for",
"the",
"user",
"view",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/user/renderer.php#L53-L69
|
216,528
|
moodle/moodle
|
course/classes/management/helper.php
|
helper.get_course_listitem_actions
|
public static function get_course_listitem_actions(\core_course_category $category, \core_course_list_element $course) {
$baseurl = new \moodle_url(
'/course/management.php',
array('courseid' => $course->id, 'categoryid' => $course->category, 'sesskey' => \sesskey())
);
$actions = array();
// Edit.
if ($course->can_edit()) {
$actions[] = array(
'url' => new \moodle_url('/course/edit.php', array('id' => $course->id, 'returnto' => 'catmanage')),
'icon' => new \pix_icon('t/edit', \get_string('edit')),
'attributes' => array('class' => 'action-edit')
);
}
// Delete.
if ($course->can_delete()) {
$actions[] = array(
'url' => new \moodle_url('/course/delete.php', array('id' => $course->id)),
'icon' => new \pix_icon('t/delete', \get_string('delete')),
'attributes' => array('class' => 'action-delete')
);
}
// Show/Hide.
if ($course->can_change_visibility()) {
$actions[] = array(
'url' => new \moodle_url($baseurl, array('action' => 'hidecourse')),
'icon' => new \pix_icon('t/hide', \get_string('hide')),
'attributes' => array('data-action' => 'hide', 'class' => 'action-hide')
);
$actions[] = array(
'url' => new \moodle_url($baseurl, array('action' => 'showcourse')),
'icon' => new \pix_icon('t/show', \get_string('show')),
'attributes' => array('data-action' => 'show', 'class' => 'action-show')
);
}
// Move up/down.
if ($category->can_resort_courses()) {
$actions[] = array(
'url' => new \moodle_url($baseurl, array('action' => 'movecourseup')),
'icon' => new \pix_icon('t/up', \get_string('up')),
'attributes' => array('data-action' => 'moveup', 'class' => 'action-moveup')
);
$actions[] = array(
'url' => new \moodle_url($baseurl, array('action' => 'movecoursedown')),
'icon' => new \pix_icon('t/down', \get_string('down')),
'attributes' => array('data-action' => 'movedown', 'class' => 'action-movedown')
);
}
return $actions;
}
|
php
|
public static function get_course_listitem_actions(\core_course_category $category, \core_course_list_element $course) {
$baseurl = new \moodle_url(
'/course/management.php',
array('courseid' => $course->id, 'categoryid' => $course->category, 'sesskey' => \sesskey())
);
$actions = array();
// Edit.
if ($course->can_edit()) {
$actions[] = array(
'url' => new \moodle_url('/course/edit.php', array('id' => $course->id, 'returnto' => 'catmanage')),
'icon' => new \pix_icon('t/edit', \get_string('edit')),
'attributes' => array('class' => 'action-edit')
);
}
// Delete.
if ($course->can_delete()) {
$actions[] = array(
'url' => new \moodle_url('/course/delete.php', array('id' => $course->id)),
'icon' => new \pix_icon('t/delete', \get_string('delete')),
'attributes' => array('class' => 'action-delete')
);
}
// Show/Hide.
if ($course->can_change_visibility()) {
$actions[] = array(
'url' => new \moodle_url($baseurl, array('action' => 'hidecourse')),
'icon' => new \pix_icon('t/hide', \get_string('hide')),
'attributes' => array('data-action' => 'hide', 'class' => 'action-hide')
);
$actions[] = array(
'url' => new \moodle_url($baseurl, array('action' => 'showcourse')),
'icon' => new \pix_icon('t/show', \get_string('show')),
'attributes' => array('data-action' => 'show', 'class' => 'action-show')
);
}
// Move up/down.
if ($category->can_resort_courses()) {
$actions[] = array(
'url' => new \moodle_url($baseurl, array('action' => 'movecourseup')),
'icon' => new \pix_icon('t/up', \get_string('up')),
'attributes' => array('data-action' => 'moveup', 'class' => 'action-moveup')
);
$actions[] = array(
'url' => new \moodle_url($baseurl, array('action' => 'movecoursedown')),
'icon' => new \pix_icon('t/down', \get_string('down')),
'attributes' => array('data-action' => 'movedown', 'class' => 'action-movedown')
);
}
return $actions;
}
|
[
"public",
"static",
"function",
"get_course_listitem_actions",
"(",
"\\",
"core_course_category",
"$",
"category",
",",
"\\",
"core_course_list_element",
"$",
"course",
")",
"{",
"$",
"baseurl",
"=",
"new",
"\\",
"moodle_url",
"(",
"'/course/management.php'",
",",
"array",
"(",
"'courseid'",
"=>",
"$",
"course",
"->",
"id",
",",
"'categoryid'",
"=>",
"$",
"course",
"->",
"category",
",",
"'sesskey'",
"=>",
"\\",
"sesskey",
"(",
")",
")",
")",
";",
"$",
"actions",
"=",
"array",
"(",
")",
";",
"// Edit.",
"if",
"(",
"$",
"course",
"->",
"can_edit",
"(",
")",
")",
"{",
"$",
"actions",
"[",
"]",
"=",
"array",
"(",
"'url'",
"=>",
"new",
"\\",
"moodle_url",
"(",
"'/course/edit.php'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"course",
"->",
"id",
",",
"'returnto'",
"=>",
"'catmanage'",
")",
")",
",",
"'icon'",
"=>",
"new",
"\\",
"pix_icon",
"(",
"'t/edit'",
",",
"\\",
"get_string",
"(",
"'edit'",
")",
")",
",",
"'attributes'",
"=>",
"array",
"(",
"'class'",
"=>",
"'action-edit'",
")",
")",
";",
"}",
"// Delete.",
"if",
"(",
"$",
"course",
"->",
"can_delete",
"(",
")",
")",
"{",
"$",
"actions",
"[",
"]",
"=",
"array",
"(",
"'url'",
"=>",
"new",
"\\",
"moodle_url",
"(",
"'/course/delete.php'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"course",
"->",
"id",
")",
")",
",",
"'icon'",
"=>",
"new",
"\\",
"pix_icon",
"(",
"'t/delete'",
",",
"\\",
"get_string",
"(",
"'delete'",
")",
")",
",",
"'attributes'",
"=>",
"array",
"(",
"'class'",
"=>",
"'action-delete'",
")",
")",
";",
"}",
"// Show/Hide.",
"if",
"(",
"$",
"course",
"->",
"can_change_visibility",
"(",
")",
")",
"{",
"$",
"actions",
"[",
"]",
"=",
"array",
"(",
"'url'",
"=>",
"new",
"\\",
"moodle_url",
"(",
"$",
"baseurl",
",",
"array",
"(",
"'action'",
"=>",
"'hidecourse'",
")",
")",
",",
"'icon'",
"=>",
"new",
"\\",
"pix_icon",
"(",
"'t/hide'",
",",
"\\",
"get_string",
"(",
"'hide'",
")",
")",
",",
"'attributes'",
"=>",
"array",
"(",
"'data-action'",
"=>",
"'hide'",
",",
"'class'",
"=>",
"'action-hide'",
")",
")",
";",
"$",
"actions",
"[",
"]",
"=",
"array",
"(",
"'url'",
"=>",
"new",
"\\",
"moodle_url",
"(",
"$",
"baseurl",
",",
"array",
"(",
"'action'",
"=>",
"'showcourse'",
")",
")",
",",
"'icon'",
"=>",
"new",
"\\",
"pix_icon",
"(",
"'t/show'",
",",
"\\",
"get_string",
"(",
"'show'",
")",
")",
",",
"'attributes'",
"=>",
"array",
"(",
"'data-action'",
"=>",
"'show'",
",",
"'class'",
"=>",
"'action-show'",
")",
")",
";",
"}",
"// Move up/down.",
"if",
"(",
"$",
"category",
"->",
"can_resort_courses",
"(",
")",
")",
"{",
"$",
"actions",
"[",
"]",
"=",
"array",
"(",
"'url'",
"=>",
"new",
"\\",
"moodle_url",
"(",
"$",
"baseurl",
",",
"array",
"(",
"'action'",
"=>",
"'movecourseup'",
")",
")",
",",
"'icon'",
"=>",
"new",
"\\",
"pix_icon",
"(",
"'t/up'",
",",
"\\",
"get_string",
"(",
"'up'",
")",
")",
",",
"'attributes'",
"=>",
"array",
"(",
"'data-action'",
"=>",
"'moveup'",
",",
"'class'",
"=>",
"'action-moveup'",
")",
")",
";",
"$",
"actions",
"[",
"]",
"=",
"array",
"(",
"'url'",
"=>",
"new",
"\\",
"moodle_url",
"(",
"$",
"baseurl",
",",
"array",
"(",
"'action'",
"=>",
"'movecoursedown'",
")",
")",
",",
"'icon'",
"=>",
"new",
"\\",
"pix_icon",
"(",
"'t/down'",
",",
"\\",
"get_string",
"(",
"'down'",
")",
")",
",",
"'attributes'",
"=>",
"array",
"(",
"'data-action'",
"=>",
"'movedown'",
",",
"'class'",
"=>",
"'action-movedown'",
")",
")",
";",
"}",
"return",
"$",
"actions",
";",
"}"
] |
Returns an array of actions for a course listitem.
@param \core_course_category $category
@param \core_course_list_element $course
@return string
|
[
"Returns",
"an",
"array",
"of",
"actions",
"for",
"a",
"course",
"listitem",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/management/helper.php#L344-L393
|
216,529
|
moodle/moodle
|
course/classes/management/helper.php
|
helper.get_course_detail_actions
|
public static function get_course_detail_actions(\core_course_list_element $course) {
$params = array('courseid' => $course->id, 'categoryid' => $course->category, 'sesskey' => \sesskey());
$baseurl = new \moodle_url('/course/management.php', $params);
$actions = array();
// View.
$actions['view'] = array(
'url' => new \moodle_url('/course/view.php', array('id' => $course->id)),
'string' => \get_string('view')
);
// Edit.
if ($course->can_edit()) {
$actions['edit'] = array(
'url' => new \moodle_url('/course/edit.php', array('id' => $course->id)),
'string' => \get_string('edit')
);
}
// Permissions.
if ($course->can_review_enrolments()) {
$actions['enrolledusers'] = array(
'url' => new \moodle_url('/user/index.php', array('id' => $course->id)),
'string' => \get_string('enrolledusers', 'enrol')
);
}
// Delete.
if ($course->can_delete()) {
$actions['delete'] = array(
'url' => new \moodle_url('/course/delete.php', array('id' => $course->id)),
'string' => \get_string('delete')
);
}
// Show/Hide.
if ($course->can_change_visibility()) {
if ($course->visible) {
$actions['hide'] = array(
'url' => new \moodle_url($baseurl, array('action' => 'hidecourse')),
'string' => \get_string('hide')
);
} else {
$actions['show'] = array(
'url' => new \moodle_url($baseurl, array('action' => 'showcourse')),
'string' => \get_string('show')
);
}
}
// Backup.
if ($course->can_backup()) {
$actions['backup'] = array(
'url' => new \moodle_url('/backup/backup.php', array('id' => $course->id)),
'string' => \get_string('backup')
);
}
// Restore.
if ($course->can_restore()) {
$actions['restore'] = array(
'url' => new \moodle_url('/backup/restorefile.php', array('contextid' => $course->get_context()->id)),
'string' => \get_string('restore')
);
}
return $actions;
}
|
php
|
public static function get_course_detail_actions(\core_course_list_element $course) {
$params = array('courseid' => $course->id, 'categoryid' => $course->category, 'sesskey' => \sesskey());
$baseurl = new \moodle_url('/course/management.php', $params);
$actions = array();
// View.
$actions['view'] = array(
'url' => new \moodle_url('/course/view.php', array('id' => $course->id)),
'string' => \get_string('view')
);
// Edit.
if ($course->can_edit()) {
$actions['edit'] = array(
'url' => new \moodle_url('/course/edit.php', array('id' => $course->id)),
'string' => \get_string('edit')
);
}
// Permissions.
if ($course->can_review_enrolments()) {
$actions['enrolledusers'] = array(
'url' => new \moodle_url('/user/index.php', array('id' => $course->id)),
'string' => \get_string('enrolledusers', 'enrol')
);
}
// Delete.
if ($course->can_delete()) {
$actions['delete'] = array(
'url' => new \moodle_url('/course/delete.php', array('id' => $course->id)),
'string' => \get_string('delete')
);
}
// Show/Hide.
if ($course->can_change_visibility()) {
if ($course->visible) {
$actions['hide'] = array(
'url' => new \moodle_url($baseurl, array('action' => 'hidecourse')),
'string' => \get_string('hide')
);
} else {
$actions['show'] = array(
'url' => new \moodle_url($baseurl, array('action' => 'showcourse')),
'string' => \get_string('show')
);
}
}
// Backup.
if ($course->can_backup()) {
$actions['backup'] = array(
'url' => new \moodle_url('/backup/backup.php', array('id' => $course->id)),
'string' => \get_string('backup')
);
}
// Restore.
if ($course->can_restore()) {
$actions['restore'] = array(
'url' => new \moodle_url('/backup/restorefile.php', array('contextid' => $course->get_context()->id)),
'string' => \get_string('restore')
);
}
return $actions;
}
|
[
"public",
"static",
"function",
"get_course_detail_actions",
"(",
"\\",
"core_course_list_element",
"$",
"course",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'courseid'",
"=>",
"$",
"course",
"->",
"id",
",",
"'categoryid'",
"=>",
"$",
"course",
"->",
"category",
",",
"'sesskey'",
"=>",
"\\",
"sesskey",
"(",
")",
")",
";",
"$",
"baseurl",
"=",
"new",
"\\",
"moodle_url",
"(",
"'/course/management.php'",
",",
"$",
"params",
")",
";",
"$",
"actions",
"=",
"array",
"(",
")",
";",
"// View.",
"$",
"actions",
"[",
"'view'",
"]",
"=",
"array",
"(",
"'url'",
"=>",
"new",
"\\",
"moodle_url",
"(",
"'/course/view.php'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"course",
"->",
"id",
")",
")",
",",
"'string'",
"=>",
"\\",
"get_string",
"(",
"'view'",
")",
")",
";",
"// Edit.",
"if",
"(",
"$",
"course",
"->",
"can_edit",
"(",
")",
")",
"{",
"$",
"actions",
"[",
"'edit'",
"]",
"=",
"array",
"(",
"'url'",
"=>",
"new",
"\\",
"moodle_url",
"(",
"'/course/edit.php'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"course",
"->",
"id",
")",
")",
",",
"'string'",
"=>",
"\\",
"get_string",
"(",
"'edit'",
")",
")",
";",
"}",
"// Permissions.",
"if",
"(",
"$",
"course",
"->",
"can_review_enrolments",
"(",
")",
")",
"{",
"$",
"actions",
"[",
"'enrolledusers'",
"]",
"=",
"array",
"(",
"'url'",
"=>",
"new",
"\\",
"moodle_url",
"(",
"'/user/index.php'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"course",
"->",
"id",
")",
")",
",",
"'string'",
"=>",
"\\",
"get_string",
"(",
"'enrolledusers'",
",",
"'enrol'",
")",
")",
";",
"}",
"// Delete.",
"if",
"(",
"$",
"course",
"->",
"can_delete",
"(",
")",
")",
"{",
"$",
"actions",
"[",
"'delete'",
"]",
"=",
"array",
"(",
"'url'",
"=>",
"new",
"\\",
"moodle_url",
"(",
"'/course/delete.php'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"course",
"->",
"id",
")",
")",
",",
"'string'",
"=>",
"\\",
"get_string",
"(",
"'delete'",
")",
")",
";",
"}",
"// Show/Hide.",
"if",
"(",
"$",
"course",
"->",
"can_change_visibility",
"(",
")",
")",
"{",
"if",
"(",
"$",
"course",
"->",
"visible",
")",
"{",
"$",
"actions",
"[",
"'hide'",
"]",
"=",
"array",
"(",
"'url'",
"=>",
"new",
"\\",
"moodle_url",
"(",
"$",
"baseurl",
",",
"array",
"(",
"'action'",
"=>",
"'hidecourse'",
")",
")",
",",
"'string'",
"=>",
"\\",
"get_string",
"(",
"'hide'",
")",
")",
";",
"}",
"else",
"{",
"$",
"actions",
"[",
"'show'",
"]",
"=",
"array",
"(",
"'url'",
"=>",
"new",
"\\",
"moodle_url",
"(",
"$",
"baseurl",
",",
"array",
"(",
"'action'",
"=>",
"'showcourse'",
")",
")",
",",
"'string'",
"=>",
"\\",
"get_string",
"(",
"'show'",
")",
")",
";",
"}",
"}",
"// Backup.",
"if",
"(",
"$",
"course",
"->",
"can_backup",
"(",
")",
")",
"{",
"$",
"actions",
"[",
"'backup'",
"]",
"=",
"array",
"(",
"'url'",
"=>",
"new",
"\\",
"moodle_url",
"(",
"'/backup/backup.php'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"course",
"->",
"id",
")",
")",
",",
"'string'",
"=>",
"\\",
"get_string",
"(",
"'backup'",
")",
")",
";",
"}",
"// Restore.",
"if",
"(",
"$",
"course",
"->",
"can_restore",
"(",
")",
")",
"{",
"$",
"actions",
"[",
"'restore'",
"]",
"=",
"array",
"(",
"'url'",
"=>",
"new",
"\\",
"moodle_url",
"(",
"'/backup/restorefile.php'",
",",
"array",
"(",
"'contextid'",
"=>",
"$",
"course",
"->",
"get_context",
"(",
")",
"->",
"id",
")",
")",
",",
"'string'",
"=>",
"\\",
"get_string",
"(",
"'restore'",
")",
")",
";",
"}",
"return",
"$",
"actions",
";",
"}"
] |
Returns an array of actions that can be performed on the course being displayed.
@param \core_course_list_element $course
@return array
|
[
"Returns",
"an",
"array",
"of",
"actions",
"that",
"can",
"be",
"performed",
"on",
"the",
"course",
"being",
"displayed",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/management/helper.php#L401-L460
|
216,530
|
moodle/moodle
|
course/classes/management/helper.php
|
helper.action_course_change_sortorder_after_course
|
public static function action_course_change_sortorder_after_course($courserecordorid, $moveaftercourseid) {
$course = \get_course($courserecordorid);
$category = \core_course_category::get($course->category);
if (!$category->can_resort_courses()) {
$url = '/course/management.php?categoryid='.$course->category;
throw new \moodle_exception('nopermissions', 'error', $url, \get_string('resortcourses', 'moodle'));
}
return \course_change_sortorder_after_course($course, $moveaftercourseid);
}
|
php
|
public static function action_course_change_sortorder_after_course($courserecordorid, $moveaftercourseid) {
$course = \get_course($courserecordorid);
$category = \core_course_category::get($course->category);
if (!$category->can_resort_courses()) {
$url = '/course/management.php?categoryid='.$course->category;
throw new \moodle_exception('nopermissions', 'error', $url, \get_string('resortcourses', 'moodle'));
}
return \course_change_sortorder_after_course($course, $moveaftercourseid);
}
|
[
"public",
"static",
"function",
"action_course_change_sortorder_after_course",
"(",
"$",
"courserecordorid",
",",
"$",
"moveaftercourseid",
")",
"{",
"$",
"course",
"=",
"\\",
"get_course",
"(",
"$",
"courserecordorid",
")",
";",
"$",
"category",
"=",
"\\",
"core_course_category",
"::",
"get",
"(",
"$",
"course",
"->",
"category",
")",
";",
"if",
"(",
"!",
"$",
"category",
"->",
"can_resort_courses",
"(",
")",
")",
"{",
"$",
"url",
"=",
"'/course/management.php?categoryid='",
".",
"$",
"course",
"->",
"category",
";",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'nopermissions'",
",",
"'error'",
",",
"$",
"url",
",",
"\\",
"get_string",
"(",
"'resortcourses'",
",",
"'moodle'",
")",
")",
";",
"}",
"return",
"\\",
"course_change_sortorder_after_course",
"(",
"$",
"course",
",",
"$",
"moveaftercourseid",
")",
";",
"}"
] |
Changes the sort order so that the first course appears after the second course.
@param int|\stdClass $courserecordorid
@param int $moveaftercourseid
@return bool
@throws \moodle_exception
|
[
"Changes",
"the",
"sort",
"order",
"so",
"that",
"the",
"first",
"course",
"appears",
"after",
"the",
"second",
"course",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/management/helper.php#L534-L542
|
216,531
|
moodle/moodle
|
course/classes/management/helper.php
|
helper.action_course_show
|
public static function action_course_show(\core_course_list_element $course) {
if (!$course->can_change_visibility()) {
throw new \moodle_exception('permissiondenied', 'error', '', null,
'core_course_list_element::can_change_visbility');
}
return course_change_visibility($course->id, true);
}
|
php
|
public static function action_course_show(\core_course_list_element $course) {
if (!$course->can_change_visibility()) {
throw new \moodle_exception('permissiondenied', 'error', '', null,
'core_course_list_element::can_change_visbility');
}
return course_change_visibility($course->id, true);
}
|
[
"public",
"static",
"function",
"action_course_show",
"(",
"\\",
"core_course_list_element",
"$",
"course",
")",
"{",
"if",
"(",
"!",
"$",
"course",
"->",
"can_change_visibility",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'permissiondenied'",
",",
"'error'",
",",
"''",
",",
"null",
",",
"'core_course_list_element::can_change_visbility'",
")",
";",
"}",
"return",
"course_change_visibility",
"(",
"$",
"course",
"->",
"id",
",",
"true",
")",
";",
"}"
] |
Makes a course visible given a \core_course_list_element object.
@param \core_course_list_element $course
@return bool
@throws \moodle_exception
|
[
"Makes",
"a",
"course",
"visible",
"given",
"a",
"\\",
"core_course_list_element",
"object",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/management/helper.php#L551-L557
|
216,532
|
moodle/moodle
|
course/classes/management/helper.php
|
helper.action_course_hide
|
public static function action_course_hide(\core_course_list_element $course) {
if (!$course->can_change_visibility()) {
throw new \moodle_exception('permissiondenied', 'error', '', null,
'core_course_list_element::can_change_visbility');
}
return course_change_visibility($course->id, false);
}
|
php
|
public static function action_course_hide(\core_course_list_element $course) {
if (!$course->can_change_visibility()) {
throw new \moodle_exception('permissiondenied', 'error', '', null,
'core_course_list_element::can_change_visbility');
}
return course_change_visibility($course->id, false);
}
|
[
"public",
"static",
"function",
"action_course_hide",
"(",
"\\",
"core_course_list_element",
"$",
"course",
")",
"{",
"if",
"(",
"!",
"$",
"course",
"->",
"can_change_visibility",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'permissiondenied'",
",",
"'error'",
",",
"''",
",",
"null",
",",
"'core_course_list_element::can_change_visbility'",
")",
";",
"}",
"return",
"course_change_visibility",
"(",
"$",
"course",
"->",
"id",
",",
"false",
")",
";",
"}"
] |
Makes a course hidden given a \core_course_list_element object.
@param \core_course_list_element $course
@return bool
@throws \moodle_exception
|
[
"Makes",
"a",
"course",
"hidden",
"given",
"a",
"\\",
"core_course_list_element",
"object",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/management/helper.php#L566-L572
|
216,533
|
moodle/moodle
|
course/classes/management/helper.php
|
helper.action_course_show_by_record
|
public static function action_course_show_by_record($courserecordorid) {
if (is_int($courserecordorid)) {
$courserecordorid = get_course($courserecordorid);
}
$course = new \core_course_list_element($courserecordorid);
return self::action_course_show($course);
}
|
php
|
public static function action_course_show_by_record($courserecordorid) {
if (is_int($courserecordorid)) {
$courserecordorid = get_course($courserecordorid);
}
$course = new \core_course_list_element($courserecordorid);
return self::action_course_show($course);
}
|
[
"public",
"static",
"function",
"action_course_show_by_record",
"(",
"$",
"courserecordorid",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"courserecordorid",
")",
")",
"{",
"$",
"courserecordorid",
"=",
"get_course",
"(",
"$",
"courserecordorid",
")",
";",
"}",
"$",
"course",
"=",
"new",
"\\",
"core_course_list_element",
"(",
"$",
"courserecordorid",
")",
";",
"return",
"self",
"::",
"action_course_show",
"(",
"$",
"course",
")",
";",
"}"
] |
Makes a course visible given a course id or a database record.
@global \moodle_database $DB
@param int|\stdClass $courserecordorid
@return bool
|
[
"Makes",
"a",
"course",
"visible",
"given",
"a",
"course",
"id",
"or",
"a",
"database",
"record",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/management/helper.php#L581-L587
|
216,534
|
moodle/moodle
|
course/classes/management/helper.php
|
helper.action_course_hide_by_record
|
public static function action_course_hide_by_record($courserecordorid) {
if (is_int($courserecordorid)) {
$courserecordorid = get_course($courserecordorid);
}
$course = new \core_course_list_element($courserecordorid);
return self::action_course_hide($course);
}
|
php
|
public static function action_course_hide_by_record($courserecordorid) {
if (is_int($courserecordorid)) {
$courserecordorid = get_course($courserecordorid);
}
$course = new \core_course_list_element($courserecordorid);
return self::action_course_hide($course);
}
|
[
"public",
"static",
"function",
"action_course_hide_by_record",
"(",
"$",
"courserecordorid",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"courserecordorid",
")",
")",
"{",
"$",
"courserecordorid",
"=",
"get_course",
"(",
"$",
"courserecordorid",
")",
";",
"}",
"$",
"course",
"=",
"new",
"\\",
"core_course_list_element",
"(",
"$",
"courserecordorid",
")",
";",
"return",
"self",
"::",
"action_course_hide",
"(",
"$",
"course",
")",
";",
"}"
] |
Makes a course hidden given a course id or a database record.
@global \moodle_database $DB
@param int|\stdClass $courserecordorid
@return bool
|
[
"Makes",
"a",
"course",
"hidden",
"given",
"a",
"course",
"id",
"or",
"a",
"database",
"record",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/management/helper.php#L596-L602
|
216,535
|
moodle/moodle
|
course/classes/management/helper.php
|
helper.action_category_change_sortorder_up_one
|
public static function action_category_change_sortorder_up_one(\core_course_category $category) {
if (!$category->can_change_sortorder()) {
throw new \moodle_exception('permissiondenied', 'error', '', null, 'core_course_category::can_change_sortorder');
}
return $category->change_sortorder_by_one(true);
}
|
php
|
public static function action_category_change_sortorder_up_one(\core_course_category $category) {
if (!$category->can_change_sortorder()) {
throw new \moodle_exception('permissiondenied', 'error', '', null, 'core_course_category::can_change_sortorder');
}
return $category->change_sortorder_by_one(true);
}
|
[
"public",
"static",
"function",
"action_category_change_sortorder_up_one",
"(",
"\\",
"core_course_category",
"$",
"category",
")",
"{",
"if",
"(",
"!",
"$",
"category",
"->",
"can_change_sortorder",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'permissiondenied'",
",",
"'error'",
",",
"''",
",",
"null",
",",
"'core_course_category::can_change_sortorder'",
")",
";",
"}",
"return",
"$",
"category",
"->",
"change_sortorder_by_one",
"(",
"true",
")",
";",
"}"
] |
Resort a categories subcategories shifting the given category up one.
@param \core_course_category $category
@return bool
@throws \moodle_exception
|
[
"Resort",
"a",
"categories",
"subcategories",
"shifting",
"the",
"given",
"category",
"up",
"one",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/management/helper.php#L611-L616
|
216,536
|
moodle/moodle
|
course/classes/management/helper.php
|
helper.action_category_change_sortorder_down_one
|
public static function action_category_change_sortorder_down_one(\core_course_category $category) {
if (!$category->can_change_sortorder()) {
throw new \moodle_exception('permissiondenied', 'error', '', null, 'core_course_category::can_change_sortorder');
}
return $category->change_sortorder_by_one(false);
}
|
php
|
public static function action_category_change_sortorder_down_one(\core_course_category $category) {
if (!$category->can_change_sortorder()) {
throw new \moodle_exception('permissiondenied', 'error', '', null, 'core_course_category::can_change_sortorder');
}
return $category->change_sortorder_by_one(false);
}
|
[
"public",
"static",
"function",
"action_category_change_sortorder_down_one",
"(",
"\\",
"core_course_category",
"$",
"category",
")",
"{",
"if",
"(",
"!",
"$",
"category",
"->",
"can_change_sortorder",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'permissiondenied'",
",",
"'error'",
",",
"''",
",",
"null",
",",
"'core_course_category::can_change_sortorder'",
")",
";",
"}",
"return",
"$",
"category",
"->",
"change_sortorder_by_one",
"(",
"false",
")",
";",
"}"
] |
Resort a categories subcategories shifting the given category down one.
@param \core_course_category $category
@return bool
@throws \moodle_exception
|
[
"Resort",
"a",
"categories",
"subcategories",
"shifting",
"the",
"given",
"category",
"down",
"one",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/management/helper.php#L625-L630
|
216,537
|
moodle/moodle
|
course/classes/management/helper.php
|
helper.action_category_hide
|
public static function action_category_hide(\core_course_category $category) {
if (!$category->can_change_visibility()) {
throw new \moodle_exception('permissiondenied', 'error', '', null, 'core_course_category::can_change_visbility');
}
$category->hide();
return true;
}
|
php
|
public static function action_category_hide(\core_course_category $category) {
if (!$category->can_change_visibility()) {
throw new \moodle_exception('permissiondenied', 'error', '', null, 'core_course_category::can_change_visbility');
}
$category->hide();
return true;
}
|
[
"public",
"static",
"function",
"action_category_hide",
"(",
"\\",
"core_course_category",
"$",
"category",
")",
"{",
"if",
"(",
"!",
"$",
"category",
"->",
"can_change_visibility",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'permissiondenied'",
",",
"'error'",
",",
"''",
",",
"null",
",",
"'core_course_category::can_change_visbility'",
")",
";",
"}",
"$",
"category",
"->",
"hide",
"(",
")",
";",
"return",
"true",
";",
"}"
] |
Makes a category hidden given a core_course_category object.
@param \core_course_category $category
@return bool
@throws \moodle_exception
|
[
"Makes",
"a",
"category",
"hidden",
"given",
"a",
"core_course_category",
"object",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/management/helper.php#L661-L667
|
216,538
|
moodle/moodle
|
course/classes/management/helper.php
|
helper.action_category_show
|
public static function action_category_show(\core_course_category $category) {
if (!$category->can_change_visibility()) {
throw new \moodle_exception('permissiondenied', 'error', '', null, 'core_course_category::can_change_visbility');
}
$category->show();
return true;
}
|
php
|
public static function action_category_show(\core_course_category $category) {
if (!$category->can_change_visibility()) {
throw new \moodle_exception('permissiondenied', 'error', '', null, 'core_course_category::can_change_visbility');
}
$category->show();
return true;
}
|
[
"public",
"static",
"function",
"action_category_show",
"(",
"\\",
"core_course_category",
"$",
"category",
")",
"{",
"if",
"(",
"!",
"$",
"category",
"->",
"can_change_visibility",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'permissiondenied'",
",",
"'error'",
",",
"''",
",",
"null",
",",
"'core_course_category::can_change_visbility'",
")",
";",
"}",
"$",
"category",
"->",
"show",
"(",
")",
";",
"return",
"true",
";",
"}"
] |
Makes a category visible given a core_course_category object.
@param \core_course_category $category
@return bool
@throws \moodle_exception
|
[
"Makes",
"a",
"category",
"visible",
"given",
"a",
"core_course_category",
"object",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/management/helper.php#L676-L682
|
216,539
|
moodle/moodle
|
course/classes/management/helper.php
|
helper.action_category_resort_subcategories
|
public static function action_category_resort_subcategories(\core_course_category $category, $sort, $cleanup = true) {
if (!$category->can_resort_subcategories()) {
throw new \moodle_exception('permissiondenied', 'error', '', null, 'core_course_category::can_resort');
}
return $category->resort_subcategories($sort, $cleanup);
}
|
php
|
public static function action_category_resort_subcategories(\core_course_category $category, $sort, $cleanup = true) {
if (!$category->can_resort_subcategories()) {
throw new \moodle_exception('permissiondenied', 'error', '', null, 'core_course_category::can_resort');
}
return $category->resort_subcategories($sort, $cleanup);
}
|
[
"public",
"static",
"function",
"action_category_resort_subcategories",
"(",
"\\",
"core_course_category",
"$",
"category",
",",
"$",
"sort",
",",
"$",
"cleanup",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"$",
"category",
"->",
"can_resort_subcategories",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'permissiondenied'",
",",
"'error'",
",",
"''",
",",
"null",
",",
"'core_course_category::can_resort'",
")",
";",
"}",
"return",
"$",
"category",
"->",
"resort_subcategories",
"(",
"$",
"sort",
",",
"$",
"cleanup",
")",
";",
"}"
] |
Resorts the sub categories of the given category.
@param \core_course_category $category
@param string $sort One of idnumber or name.
@param bool $cleanup If true cleanup will be done, if false you will need to do it manually later.
@return bool
@throws \moodle_exception
|
[
"Resorts",
"the",
"sub",
"categories",
"of",
"the",
"given",
"category",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/management/helper.php#L713-L718
|
216,540
|
moodle/moodle
|
course/classes/management/helper.php
|
helper.action_category_resort_courses
|
public static function action_category_resort_courses(\core_course_category $category, $sort, $cleanup = true) {
if (!$category->can_resort_courses()) {
throw new \moodle_exception('permissiondenied', 'error', '', null, 'core_course_category::can_resort');
}
return $category->resort_courses($sort, $cleanup);
}
|
php
|
public static function action_category_resort_courses(\core_course_category $category, $sort, $cleanup = true) {
if (!$category->can_resort_courses()) {
throw new \moodle_exception('permissiondenied', 'error', '', null, 'core_course_category::can_resort');
}
return $category->resort_courses($sort, $cleanup);
}
|
[
"public",
"static",
"function",
"action_category_resort_courses",
"(",
"\\",
"core_course_category",
"$",
"category",
",",
"$",
"sort",
",",
"$",
"cleanup",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"$",
"category",
"->",
"can_resort_courses",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'permissiondenied'",
",",
"'error'",
",",
"''",
",",
"null",
",",
"'core_course_category::can_resort'",
")",
";",
"}",
"return",
"$",
"category",
"->",
"resort_courses",
"(",
"$",
"sort",
",",
"$",
"cleanup",
")",
";",
"}"
] |
Resorts the courses within the given category.
@param \core_course_category $category
@param string $sort One of fullname, shortname or idnumber
@param bool $cleanup If true cleanup will be done, if false you will need to do it manually later.
@return bool
@throws \moodle_exception
|
[
"Resorts",
"the",
"courses",
"within",
"the",
"given",
"category",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/management/helper.php#L729-L734
|
216,541
|
moodle/moodle
|
course/classes/management/helper.php
|
helper.action_category_move_courses_into
|
public static function action_category_move_courses_into(\core_course_category $oldcategory,
\core_course_category $newcategory, array $courseids) {
global $DB;
list($where, $params) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED);
$params['categoryid'] = $oldcategory->id;
$sql = "SELECT c.id FROM {course} c WHERE c.id {$where} AND c.category <> :categoryid";
if ($DB->record_exists_sql($sql, $params)) {
// Likely being tinkered with.
throw new \moodle_exception('coursedoesnotbelongtocategory');
}
// All courses are currently within the old category.
return self::move_courses_into_category($newcategory, $courseids);
}
|
php
|
public static function action_category_move_courses_into(\core_course_category $oldcategory,
\core_course_category $newcategory, array $courseids) {
global $DB;
list($where, $params) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED);
$params['categoryid'] = $oldcategory->id;
$sql = "SELECT c.id FROM {course} c WHERE c.id {$where} AND c.category <> :categoryid";
if ($DB->record_exists_sql($sql, $params)) {
// Likely being tinkered with.
throw new \moodle_exception('coursedoesnotbelongtocategory');
}
// All courses are currently within the old category.
return self::move_courses_into_category($newcategory, $courseids);
}
|
[
"public",
"static",
"function",
"action_category_move_courses_into",
"(",
"\\",
"core_course_category",
"$",
"oldcategory",
",",
"\\",
"core_course_category",
"$",
"newcategory",
",",
"array",
"$",
"courseids",
")",
"{",
"global",
"$",
"DB",
";",
"list",
"(",
"$",
"where",
",",
"$",
"params",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"courseids",
",",
"SQL_PARAMS_NAMED",
")",
";",
"$",
"params",
"[",
"'categoryid'",
"]",
"=",
"$",
"oldcategory",
"->",
"id",
";",
"$",
"sql",
"=",
"\"SELECT c.id FROM {course} c WHERE c.id {$where} AND c.category <> :categoryid\"",
";",
"if",
"(",
"$",
"DB",
"->",
"record_exists_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
")",
"{",
"// Likely being tinkered with.",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'coursedoesnotbelongtocategory'",
")",
";",
"}",
"// All courses are currently within the old category.",
"return",
"self",
"::",
"move_courses_into_category",
"(",
"$",
"newcategory",
",",
"$",
"courseids",
")",
";",
"}"
] |
Moves courses out of one category and into a new category.
@param \core_course_category $oldcategory The category we are moving courses out of.
@param \core_course_category $newcategory The category we are moving courses into.
@param array $courseids The ID's of the courses we want to move.
@return bool True on success.
@throws \moodle_exception
|
[
"Moves",
"courses",
"out",
"of",
"one",
"category",
"and",
"into",
"a",
"new",
"category",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/management/helper.php#L745-L759
|
216,542
|
moodle/moodle
|
course/classes/management/helper.php
|
helper.search_courses
|
public static function search_courses($search, $blocklist, $modulelist, $page = 0, $perpage = null) {
global $CFG;
if ($perpage === null) {
$perpage = $CFG->coursesperpage;
}
$searchcriteria = array();
if (!empty($search)) {
$searchcriteria = array('search' => $search);
} else if (!empty($blocklist)) {
$searchcriteria = array('blocklist' => $blocklist);
} else if (!empty($modulelist)) {
$searchcriteria = array('modulelist' => $modulelist);
}
$topcat = \core_course_category::top();
$courses = $topcat->search_courses($searchcriteria, array(
'recursive' => true,
'offset' => $page * $perpage,
'limit' => $perpage,
'sort' => array('fullname' => 1)
));
$totalcount = $topcat->search_courses_count($searchcriteria, array('recursive' => true));
return array($courses, \count($courses), $totalcount);
}
|
php
|
public static function search_courses($search, $blocklist, $modulelist, $page = 0, $perpage = null) {
global $CFG;
if ($perpage === null) {
$perpage = $CFG->coursesperpage;
}
$searchcriteria = array();
if (!empty($search)) {
$searchcriteria = array('search' => $search);
} else if (!empty($blocklist)) {
$searchcriteria = array('blocklist' => $blocklist);
} else if (!empty($modulelist)) {
$searchcriteria = array('modulelist' => $modulelist);
}
$topcat = \core_course_category::top();
$courses = $topcat->search_courses($searchcriteria, array(
'recursive' => true,
'offset' => $page * $perpage,
'limit' => $perpage,
'sort' => array('fullname' => 1)
));
$totalcount = $topcat->search_courses_count($searchcriteria, array('recursive' => true));
return array($courses, \count($courses), $totalcount);
}
|
[
"public",
"static",
"function",
"search_courses",
"(",
"$",
"search",
",",
"$",
"blocklist",
",",
"$",
"modulelist",
",",
"$",
"page",
"=",
"0",
",",
"$",
"perpage",
"=",
"null",
")",
"{",
"global",
"$",
"CFG",
";",
"if",
"(",
"$",
"perpage",
"===",
"null",
")",
"{",
"$",
"perpage",
"=",
"$",
"CFG",
"->",
"coursesperpage",
";",
"}",
"$",
"searchcriteria",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"search",
")",
")",
"{",
"$",
"searchcriteria",
"=",
"array",
"(",
"'search'",
"=>",
"$",
"search",
")",
";",
"}",
"else",
"if",
"(",
"!",
"empty",
"(",
"$",
"blocklist",
")",
")",
"{",
"$",
"searchcriteria",
"=",
"array",
"(",
"'blocklist'",
"=>",
"$",
"blocklist",
")",
";",
"}",
"else",
"if",
"(",
"!",
"empty",
"(",
"$",
"modulelist",
")",
")",
"{",
"$",
"searchcriteria",
"=",
"array",
"(",
"'modulelist'",
"=>",
"$",
"modulelist",
")",
";",
"}",
"$",
"topcat",
"=",
"\\",
"core_course_category",
"::",
"top",
"(",
")",
";",
"$",
"courses",
"=",
"$",
"topcat",
"->",
"search_courses",
"(",
"$",
"searchcriteria",
",",
"array",
"(",
"'recursive'",
"=>",
"true",
",",
"'offset'",
"=>",
"$",
"page",
"*",
"$",
"perpage",
",",
"'limit'",
"=>",
"$",
"perpage",
",",
"'sort'",
"=>",
"array",
"(",
"'fullname'",
"=>",
"1",
")",
")",
")",
";",
"$",
"totalcount",
"=",
"$",
"topcat",
"->",
"search_courses_count",
"(",
"$",
"searchcriteria",
",",
"array",
"(",
"'recursive'",
"=>",
"true",
")",
")",
";",
"return",
"array",
"(",
"$",
"courses",
",",
"\\",
"count",
"(",
"$",
"courses",
")",
",",
"$",
"totalcount",
")",
";",
"}"
] |
Search for courses with matching params.
Please note that only one of search, blocklist, or modulelist can be specified at a time.
Specifying more than one will result in only the first being used.
@param string $search Words to search for. We search fullname, shortname, idnumber and summary.
@param int $blocklist The ID of a block, courses will only be returned if they use this block.
@param string $modulelist The name of a module (relates to database table name). Only courses containing this module
will be returned.
@param int $page The page number to display, starting at 0.
@param int $perpage The number of courses to display per page.
@return array
|
[
"Search",
"for",
"courses",
"with",
"matching",
"params",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/management/helper.php#L787-L813
|
216,543
|
moodle/moodle
|
course/classes/management/helper.php
|
helper.move_courses_into_category
|
public static function move_courses_into_category($categoryorid, $courseids = array()) {
global $DB;
if (!is_array($courseids)) {
// Just a single course ID.
$courseids = array($courseids);
}
// Bulk move courses from one category to another.
if (count($courseids) === 0) {
return false;
}
if ($categoryorid instanceof \core_course_category) {
$moveto = $categoryorid;
} else {
$moveto = \core_course_category::get($categoryorid);
}
if (!$moveto->can_move_courses_out_of() || !$moveto->can_move_courses_into()) {
throw new \moodle_exception('cannotmovecourses');
}
list($where, $params) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED);
$sql = "SELECT c.id, c.category FROM {course} c WHERE c.id {$where}";
$courses = $DB->get_records_sql($sql, $params);
$checks = array();
foreach ($courseids as $id) {
if (!isset($courses[$id])) {
throw new \moodle_exception('invalidcourseid');
}
$catid = $courses[$id]->category;
if (!isset($checks[$catid])) {
$coursecat = \core_course_category::get($catid);
$checks[$catid] = $coursecat->can_move_courses_out_of() && $coursecat->can_move_courses_into();
}
if (!$checks[$catid]) {
throw new \moodle_exception('cannotmovecourses');
}
}
return \move_courses($courseids, $moveto->id);
}
|
php
|
public static function move_courses_into_category($categoryorid, $courseids = array()) {
global $DB;
if (!is_array($courseids)) {
// Just a single course ID.
$courseids = array($courseids);
}
// Bulk move courses from one category to another.
if (count($courseids) === 0) {
return false;
}
if ($categoryorid instanceof \core_course_category) {
$moveto = $categoryorid;
} else {
$moveto = \core_course_category::get($categoryorid);
}
if (!$moveto->can_move_courses_out_of() || !$moveto->can_move_courses_into()) {
throw new \moodle_exception('cannotmovecourses');
}
list($where, $params) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED);
$sql = "SELECT c.id, c.category FROM {course} c WHERE c.id {$where}";
$courses = $DB->get_records_sql($sql, $params);
$checks = array();
foreach ($courseids as $id) {
if (!isset($courses[$id])) {
throw new \moodle_exception('invalidcourseid');
}
$catid = $courses[$id]->category;
if (!isset($checks[$catid])) {
$coursecat = \core_course_category::get($catid);
$checks[$catid] = $coursecat->can_move_courses_out_of() && $coursecat->can_move_courses_into();
}
if (!$checks[$catid]) {
throw new \moodle_exception('cannotmovecourses');
}
}
return \move_courses($courseids, $moveto->id);
}
|
[
"public",
"static",
"function",
"move_courses_into_category",
"(",
"$",
"categoryorid",
",",
"$",
"courseids",
"=",
"array",
"(",
")",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"courseids",
")",
")",
"{",
"// Just a single course ID.",
"$",
"courseids",
"=",
"array",
"(",
"$",
"courseids",
")",
";",
"}",
"// Bulk move courses from one category to another.",
"if",
"(",
"count",
"(",
"$",
"courseids",
")",
"===",
"0",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"categoryorid",
"instanceof",
"\\",
"core_course_category",
")",
"{",
"$",
"moveto",
"=",
"$",
"categoryorid",
";",
"}",
"else",
"{",
"$",
"moveto",
"=",
"\\",
"core_course_category",
"::",
"get",
"(",
"$",
"categoryorid",
")",
";",
"}",
"if",
"(",
"!",
"$",
"moveto",
"->",
"can_move_courses_out_of",
"(",
")",
"||",
"!",
"$",
"moveto",
"->",
"can_move_courses_into",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'cannotmovecourses'",
")",
";",
"}",
"list",
"(",
"$",
"where",
",",
"$",
"params",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"courseids",
",",
"SQL_PARAMS_NAMED",
")",
";",
"$",
"sql",
"=",
"\"SELECT c.id, c.category FROM {course} c WHERE c.id {$where}\"",
";",
"$",
"courses",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"$",
"checks",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"courseids",
"as",
"$",
"id",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"courses",
"[",
"$",
"id",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'invalidcourseid'",
")",
";",
"}",
"$",
"catid",
"=",
"$",
"courses",
"[",
"$",
"id",
"]",
"->",
"category",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"checks",
"[",
"$",
"catid",
"]",
")",
")",
"{",
"$",
"coursecat",
"=",
"\\",
"core_course_category",
"::",
"get",
"(",
"$",
"catid",
")",
";",
"$",
"checks",
"[",
"$",
"catid",
"]",
"=",
"$",
"coursecat",
"->",
"can_move_courses_out_of",
"(",
")",
"&&",
"$",
"coursecat",
"->",
"can_move_courses_into",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"checks",
"[",
"$",
"catid",
"]",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'cannotmovecourses'",
")",
";",
"}",
"}",
"return",
"\\",
"move_courses",
"(",
"$",
"courseids",
",",
"$",
"moveto",
"->",
"id",
")",
";",
"}"
] |
Moves one or more courses out of the category they are currently in and into a new category.
This function works much the same way as action_category_move_courses_into however it allows courses from multiple
categories to be moved into a single category.
@param int|\core_course_category $categoryorid The category to move them into.
@param array|int $courseids An array of course id's or optionally just a single course id.
@return bool True on success or false on failure.
@throws \moodle_exception
|
[
"Moves",
"one",
"or",
"more",
"courses",
"out",
"of",
"the",
"category",
"they",
"are",
"currently",
"in",
"and",
"into",
"a",
"new",
"category",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/management/helper.php#L826-L863
|
216,544
|
moodle/moodle
|
course/classes/management/helper.php
|
helper.get_category_courses_visibility
|
public static function get_category_courses_visibility($categoryid) {
global $DB;
$sql = "SELECT c.id, c.visible
FROM {course} c
WHERE c.category = :category";
$params = array('category' => (int)$categoryid);
return $DB->get_records_sql($sql, $params);
}
|
php
|
public static function get_category_courses_visibility($categoryid) {
global $DB;
$sql = "SELECT c.id, c.visible
FROM {course} c
WHERE c.category = :category";
$params = array('category' => (int)$categoryid);
return $DB->get_records_sql($sql, $params);
}
|
[
"public",
"static",
"function",
"get_category_courses_visibility",
"(",
"$",
"categoryid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"sql",
"=",
"\"SELECT c.id, c.visible\n FROM {course} c\n WHERE c.category = :category\"",
";",
"$",
"params",
"=",
"array",
"(",
"'category'",
"=>",
"(",
"int",
")",
"$",
"categoryid",
")",
";",
"return",
"$",
"DB",
"->",
"get_records_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"}"
] |
Returns an array of courseids and visiblity for all courses within the given category.
@param int $categoryid
@return array
|
[
"Returns",
"an",
"array",
"of",
"courseids",
"and",
"visiblity",
"for",
"all",
"courses",
"within",
"the",
"given",
"category",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/management/helper.php#L870-L877
|
216,545
|
moodle/moodle
|
course/classes/management/helper.php
|
helper.get_category_children_visibility
|
public static function get_category_children_visibility($categoryid) {
global $DB;
$category = \core_course_category::get($categoryid);
$select = $DB->sql_like('path', ':path');
$path = $category->path . '/%';
$sql = "SELECT c.id, c.visible
FROM {course_categories} c
WHERE ".$select;
$params = array('path' => $path);
return $DB->get_records_sql($sql, $params);
}
|
php
|
public static function get_category_children_visibility($categoryid) {
global $DB;
$category = \core_course_category::get($categoryid);
$select = $DB->sql_like('path', ':path');
$path = $category->path . '/%';
$sql = "SELECT c.id, c.visible
FROM {course_categories} c
WHERE ".$select;
$params = array('path' => $path);
return $DB->get_records_sql($sql, $params);
}
|
[
"public",
"static",
"function",
"get_category_children_visibility",
"(",
"$",
"categoryid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"category",
"=",
"\\",
"core_course_category",
"::",
"get",
"(",
"$",
"categoryid",
")",
";",
"$",
"select",
"=",
"$",
"DB",
"->",
"sql_like",
"(",
"'path'",
",",
"':path'",
")",
";",
"$",
"path",
"=",
"$",
"category",
"->",
"path",
".",
"'/%'",
";",
"$",
"sql",
"=",
"\"SELECT c.id, c.visible\n FROM {course_categories} c\n WHERE \"",
".",
"$",
"select",
";",
"$",
"params",
"=",
"array",
"(",
"'path'",
"=>",
"$",
"path",
")",
";",
"return",
"$",
"DB",
"->",
"get_records_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"}"
] |
Returns an array of all categoryids that have the given category as a parent and their visible value.
@param int $categoryid
@return array
|
[
"Returns",
"an",
"array",
"of",
"all",
"categoryids",
"that",
"have",
"the",
"given",
"category",
"as",
"a",
"parent",
"and",
"their",
"visible",
"value",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/management/helper.php#L884-L895
|
216,546
|
moodle/moodle
|
course/classes/management/helper.php
|
helper.record_expanded_category
|
public static function record_expanded_category(\core_course_category $coursecat, $expanded = true) {
// If this ever changes we are going to reset it and reload the categories as required.
self::$expandedcategories = null;
$categoryid = $coursecat->id;
$path = $coursecat->get_parents();
/* @var \cache_session $cache */
$cache = \cache::make('core', 'userselections');
$categories = $cache->get('categorymanagementexpanded');
if (!is_array($categories)) {
if (!$expanded) {
// No categories recorded, nothing to remove.
return;
}
$categories = array();
}
if ($expanded) {
$ref =& $categories;
foreach ($coursecat->get_parents() as $path) {
if (!isset($ref[$path]) || !is_array($ref[$path])) {
$ref[$path] = array();
}
$ref =& $ref[$path];
}
if (!isset($ref[$categoryid])) {
$ref[$categoryid] = true;
}
} else {
$found = true;
$ref =& $categories;
foreach ($coursecat->get_parents() as $path) {
if (!isset($ref[$path])) {
$found = false;
break;
}
$ref =& $ref[$path];
}
if ($found) {
$ref[$categoryid] = null;
unset($ref[$categoryid]);
}
}
$cache->set('categorymanagementexpanded', $categories);
}
|
php
|
public static function record_expanded_category(\core_course_category $coursecat, $expanded = true) {
// If this ever changes we are going to reset it and reload the categories as required.
self::$expandedcategories = null;
$categoryid = $coursecat->id;
$path = $coursecat->get_parents();
/* @var \cache_session $cache */
$cache = \cache::make('core', 'userselections');
$categories = $cache->get('categorymanagementexpanded');
if (!is_array($categories)) {
if (!$expanded) {
// No categories recorded, nothing to remove.
return;
}
$categories = array();
}
if ($expanded) {
$ref =& $categories;
foreach ($coursecat->get_parents() as $path) {
if (!isset($ref[$path]) || !is_array($ref[$path])) {
$ref[$path] = array();
}
$ref =& $ref[$path];
}
if (!isset($ref[$categoryid])) {
$ref[$categoryid] = true;
}
} else {
$found = true;
$ref =& $categories;
foreach ($coursecat->get_parents() as $path) {
if (!isset($ref[$path])) {
$found = false;
break;
}
$ref =& $ref[$path];
}
if ($found) {
$ref[$categoryid] = null;
unset($ref[$categoryid]);
}
}
$cache->set('categorymanagementexpanded', $categories);
}
|
[
"public",
"static",
"function",
"record_expanded_category",
"(",
"\\",
"core_course_category",
"$",
"coursecat",
",",
"$",
"expanded",
"=",
"true",
")",
"{",
"// If this ever changes we are going to reset it and reload the categories as required.",
"self",
"::",
"$",
"expandedcategories",
"=",
"null",
";",
"$",
"categoryid",
"=",
"$",
"coursecat",
"->",
"id",
";",
"$",
"path",
"=",
"$",
"coursecat",
"->",
"get_parents",
"(",
")",
";",
"/* @var \\cache_session $cache */",
"$",
"cache",
"=",
"\\",
"cache",
"::",
"make",
"(",
"'core'",
",",
"'userselections'",
")",
";",
"$",
"categories",
"=",
"$",
"cache",
"->",
"get",
"(",
"'categorymanagementexpanded'",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"categories",
")",
")",
"{",
"if",
"(",
"!",
"$",
"expanded",
")",
"{",
"// No categories recorded, nothing to remove.",
"return",
";",
"}",
"$",
"categories",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"$",
"expanded",
")",
"{",
"$",
"ref",
"=",
"&",
"$",
"categories",
";",
"foreach",
"(",
"$",
"coursecat",
"->",
"get_parents",
"(",
")",
"as",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"ref",
"[",
"$",
"path",
"]",
")",
"||",
"!",
"is_array",
"(",
"$",
"ref",
"[",
"$",
"path",
"]",
")",
")",
"{",
"$",
"ref",
"[",
"$",
"path",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"ref",
"=",
"&",
"$",
"ref",
"[",
"$",
"path",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"ref",
"[",
"$",
"categoryid",
"]",
")",
")",
"{",
"$",
"ref",
"[",
"$",
"categoryid",
"]",
"=",
"true",
";",
"}",
"}",
"else",
"{",
"$",
"found",
"=",
"true",
";",
"$",
"ref",
"=",
"&",
"$",
"categories",
";",
"foreach",
"(",
"$",
"coursecat",
"->",
"get_parents",
"(",
")",
"as",
"$",
"path",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"ref",
"[",
"$",
"path",
"]",
")",
")",
"{",
"$",
"found",
"=",
"false",
";",
"break",
";",
"}",
"$",
"ref",
"=",
"&",
"$",
"ref",
"[",
"$",
"path",
"]",
";",
"}",
"if",
"(",
"$",
"found",
")",
"{",
"$",
"ref",
"[",
"$",
"categoryid",
"]",
"=",
"null",
";",
"unset",
"(",
"$",
"ref",
"[",
"$",
"categoryid",
"]",
")",
";",
"}",
"}",
"$",
"cache",
"->",
"set",
"(",
"'categorymanagementexpanded'",
",",
"$",
"categories",
")",
";",
"}"
] |
Records when a category is expanded or collapsed so that when the user
@param \core_course_category $coursecat The category we're working with.
@param bool $expanded True if the category is expanded now.
|
[
"Records",
"when",
"a",
"category",
"is",
"expanded",
"or",
"collapsed",
"so",
"that",
"when",
"the",
"user"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/management/helper.php#L903-L945
|
216,547
|
moodle/moodle
|
course/classes/management/helper.php
|
helper.get_expanded_categories
|
public static function get_expanded_categories($withpath = null) {
if (self::$expandedcategories === null) {
/* @var \cache_session $cache */
$cache = \cache::make('core', 'userselections');
self::$expandedcategories = $cache->get('categorymanagementexpanded');
if (self::$expandedcategories === false) {
self::$expandedcategories = array();
}
}
if (empty($withpath)) {
return array_keys(self::$expandedcategories);
}
$parents = explode('/', trim($withpath, '/'));
$ref =& self::$expandedcategories;
foreach ($parents as $parent) {
if (!isset($ref[$parent])) {
return array();
}
$ref =& $ref[$parent];
}
if (is_array($ref)) {
return array_keys($ref);
} else {
return array($parent);
}
}
|
php
|
public static function get_expanded_categories($withpath = null) {
if (self::$expandedcategories === null) {
/* @var \cache_session $cache */
$cache = \cache::make('core', 'userselections');
self::$expandedcategories = $cache->get('categorymanagementexpanded');
if (self::$expandedcategories === false) {
self::$expandedcategories = array();
}
}
if (empty($withpath)) {
return array_keys(self::$expandedcategories);
}
$parents = explode('/', trim($withpath, '/'));
$ref =& self::$expandedcategories;
foreach ($parents as $parent) {
if (!isset($ref[$parent])) {
return array();
}
$ref =& $ref[$parent];
}
if (is_array($ref)) {
return array_keys($ref);
} else {
return array($parent);
}
}
|
[
"public",
"static",
"function",
"get_expanded_categories",
"(",
"$",
"withpath",
"=",
"null",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"expandedcategories",
"===",
"null",
")",
"{",
"/* @var \\cache_session $cache */",
"$",
"cache",
"=",
"\\",
"cache",
"::",
"make",
"(",
"'core'",
",",
"'userselections'",
")",
";",
"self",
"::",
"$",
"expandedcategories",
"=",
"$",
"cache",
"->",
"get",
"(",
"'categorymanagementexpanded'",
")",
";",
"if",
"(",
"self",
"::",
"$",
"expandedcategories",
"===",
"false",
")",
"{",
"self",
"::",
"$",
"expandedcategories",
"=",
"array",
"(",
")",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"withpath",
")",
")",
"{",
"return",
"array_keys",
"(",
"self",
"::",
"$",
"expandedcategories",
")",
";",
"}",
"$",
"parents",
"=",
"explode",
"(",
"'/'",
",",
"trim",
"(",
"$",
"withpath",
",",
"'/'",
")",
")",
";",
"$",
"ref",
"=",
"&",
"self",
"::",
"$",
"expandedcategories",
";",
"foreach",
"(",
"$",
"parents",
"as",
"$",
"parent",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"ref",
"[",
"$",
"parent",
"]",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"ref",
"=",
"&",
"$",
"ref",
"[",
"$",
"parent",
"]",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"ref",
")",
")",
"{",
"return",
"array_keys",
"(",
"$",
"ref",
")",
";",
"}",
"else",
"{",
"return",
"array",
"(",
"$",
"parent",
")",
";",
"}",
"}"
] |
Returns the categories that should be expanded when displaying the interface.
@param int|null $withpath If specified a path to require as the parent.
@return \core_course_category[] An array of Category ID's to expand.
|
[
"Returns",
"the",
"categories",
"that",
"should",
"be",
"expanded",
"when",
"displaying",
"the",
"interface",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/management/helper.php#L953-L978
|
216,548
|
moodle/moodle
|
lib/horde/framework/Horde/Translation/Autodetect.php
|
Horde_Translation_Autodetect.loadHandler
|
public static function loadHandler($handlerClass)
{
if (!static::$_domain) {
throw new Horde_Translation_Exception('The domain property must be set by the class that extends Horde_Translation_Autodetect.');
}
$directory = static::_searchLocaleDirectory();
if (!$directory) {
throw new Horde_Translation_Exception(sprintf('Could not found find any locale directory for %s domain.', static::$_domain));
}
static::$_directory = $directory;
parent::loadHandler($handlerClass);
}
|
php
|
public static function loadHandler($handlerClass)
{
if (!static::$_domain) {
throw new Horde_Translation_Exception('The domain property must be set by the class that extends Horde_Translation_Autodetect.');
}
$directory = static::_searchLocaleDirectory();
if (!$directory) {
throw new Horde_Translation_Exception(sprintf('Could not found find any locale directory for %s domain.', static::$_domain));
}
static::$_directory = $directory;
parent::loadHandler($handlerClass);
}
|
[
"public",
"static",
"function",
"loadHandler",
"(",
"$",
"handlerClass",
")",
"{",
"if",
"(",
"!",
"static",
"::",
"$",
"_domain",
")",
"{",
"throw",
"new",
"Horde_Translation_Exception",
"(",
"'The domain property must be set by the class that extends Horde_Translation_Autodetect.'",
")",
";",
"}",
"$",
"directory",
"=",
"static",
"::",
"_searchLocaleDirectory",
"(",
")",
";",
"if",
"(",
"!",
"$",
"directory",
")",
"{",
"throw",
"new",
"Horde_Translation_Exception",
"(",
"sprintf",
"(",
"'Could not found find any locale directory for %s domain.'",
",",
"static",
"::",
"$",
"_domain",
")",
")",
";",
"}",
"static",
"::",
"$",
"_directory",
"=",
"$",
"directory",
";",
"parent",
"::",
"loadHandler",
"(",
"$",
"handlerClass",
")",
";",
"}"
] |
Auto detects the locale directory location.
@param string $handlerClass The name of a class implementing the
Horde_Translation_Handler interface.
|
[
"Auto",
"detects",
"the",
"locale",
"directory",
"location",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Translation/Autodetect.php#L43-L56
|
216,549
|
moodle/moodle
|
lib/horde/framework/Horde/Translation/Autodetect.php
|
Horde_Translation_Autodetect._getSearchDirectories
|
protected static function _getSearchDirectories()
{
$className = get_called_class();
$class = new ReflectionClass($className);
$basedir = dirname($class->getFilename());
$depth = substr_count($className, '\\')
?: substr_count($className, '_');
return array(
/* Composer */
$basedir . str_repeat('/..', $depth) . '/data/locale',
/* Source */
$basedir . str_repeat('/..', $depth + 1) . '/locale'
);
}
|
php
|
protected static function _getSearchDirectories()
{
$className = get_called_class();
$class = new ReflectionClass($className);
$basedir = dirname($class->getFilename());
$depth = substr_count($className, '\\')
?: substr_count($className, '_');
return array(
/* Composer */
$basedir . str_repeat('/..', $depth) . '/data/locale',
/* Source */
$basedir . str_repeat('/..', $depth + 1) . '/locale'
);
}
|
[
"protected",
"static",
"function",
"_getSearchDirectories",
"(",
")",
"{",
"$",
"className",
"=",
"get_called_class",
"(",
")",
";",
"$",
"class",
"=",
"new",
"ReflectionClass",
"(",
"$",
"className",
")",
";",
"$",
"basedir",
"=",
"dirname",
"(",
"$",
"class",
"->",
"getFilename",
"(",
")",
")",
";",
"$",
"depth",
"=",
"substr_count",
"(",
"$",
"className",
",",
"'\\\\'",
")",
"?",
":",
"substr_count",
"(",
"$",
"className",
",",
"'_'",
")",
";",
"return",
"array",
"(",
"/* Composer */",
"$",
"basedir",
".",
"str_repeat",
"(",
"'/..'",
",",
"$",
"depth",
")",
".",
"'/data/locale'",
",",
"/* Source */",
"$",
"basedir",
".",
"str_repeat",
"(",
"'/..'",
",",
"$",
"depth",
"+",
"1",
")",
".",
"'/locale'",
")",
";",
"}"
] |
Get potential locations for the locale directory.
@var array List of directories
|
[
"Get",
"potential",
"locations",
"for",
"the",
"locale",
"directory",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Translation/Autodetect.php#L87-L101
|
216,550
|
moodle/moodle
|
question/type/questiontypebase.php
|
question_type.get_heading
|
public function get_heading($adding = false) {
if ($adding) {
$string = 'pluginnameadding';
} else {
$string = 'pluginnameediting';
}
return get_string($string, $this->plugin_name());
}
|
php
|
public function get_heading($adding = false) {
if ($adding) {
$string = 'pluginnameadding';
} else {
$string = 'pluginnameediting';
}
return get_string($string, $this->plugin_name());
}
|
[
"public",
"function",
"get_heading",
"(",
"$",
"adding",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"adding",
")",
"{",
"$",
"string",
"=",
"'pluginnameadding'",
";",
"}",
"else",
"{",
"$",
"string",
"=",
"'pluginnameediting'",
";",
"}",
"return",
"get_string",
"(",
"$",
"string",
",",
"$",
"this",
"->",
"plugin_name",
"(",
")",
")",
";",
"}"
] |
Method called by display_question_editing_page and by question.php to get
heading for breadcrumbs.
@return string the heading
|
[
"Method",
"called",
"by",
"display_question_editing_page",
"and",
"by",
"question",
".",
"php",
"to",
"get",
"heading",
"for",
"breadcrumbs",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/questiontypebase.php#L257-L264
|
216,551
|
moodle/moodle
|
question/type/questiontypebase.php
|
question_type.save_question_options
|
public function save_question_options($question) {
global $DB;
$extraquestionfields = $this->extra_question_fields();
if (is_array($extraquestionfields)) {
$question_extension_table = array_shift($extraquestionfields);
$function = 'update_record';
$questionidcolname = $this->questionid_column_name();
$options = $DB->get_record($question_extension_table,
array($questionidcolname => $question->id));
if (!$options) {
$function = 'insert_record';
$options = new stdClass();
$options->$questionidcolname = $question->id;
}
foreach ($extraquestionfields as $field) {
if (property_exists($question, $field)) {
$options->$field = $question->$field;
}
}
$DB->{$function}($question_extension_table, $options);
}
}
|
php
|
public function save_question_options($question) {
global $DB;
$extraquestionfields = $this->extra_question_fields();
if (is_array($extraquestionfields)) {
$question_extension_table = array_shift($extraquestionfields);
$function = 'update_record';
$questionidcolname = $this->questionid_column_name();
$options = $DB->get_record($question_extension_table,
array($questionidcolname => $question->id));
if (!$options) {
$function = 'insert_record';
$options = new stdClass();
$options->$questionidcolname = $question->id;
}
foreach ($extraquestionfields as $field) {
if (property_exists($question, $field)) {
$options->$field = $question->$field;
}
}
$DB->{$function}($question_extension_table, $options);
}
}
|
[
"public",
"function",
"save_question_options",
"(",
"$",
"question",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"extraquestionfields",
"=",
"$",
"this",
"->",
"extra_question_fields",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"extraquestionfields",
")",
")",
"{",
"$",
"question_extension_table",
"=",
"array_shift",
"(",
"$",
"extraquestionfields",
")",
";",
"$",
"function",
"=",
"'update_record'",
";",
"$",
"questionidcolname",
"=",
"$",
"this",
"->",
"questionid_column_name",
"(",
")",
";",
"$",
"options",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"$",
"question_extension_table",
",",
"array",
"(",
"$",
"questionidcolname",
"=>",
"$",
"question",
"->",
"id",
")",
")",
";",
"if",
"(",
"!",
"$",
"options",
")",
"{",
"$",
"function",
"=",
"'insert_record'",
";",
"$",
"options",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"options",
"->",
"$",
"questionidcolname",
"=",
"$",
"question",
"->",
"id",
";",
"}",
"foreach",
"(",
"$",
"extraquestionfields",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"property_exists",
"(",
"$",
"question",
",",
"$",
"field",
")",
")",
"{",
"$",
"options",
"->",
"$",
"field",
"=",
"$",
"question",
"->",
"$",
"field",
";",
"}",
"}",
"$",
"DB",
"->",
"{",
"$",
"function",
"}",
"(",
"$",
"question_extension_table",
",",
"$",
"options",
")",
";",
"}",
"}"
] |
Saves question-type specific options
This is called by {@link save_question()} to save the question-type specific data
@return object $result->error or $result->notice
@param object $question This holds the information from the editing form,
it is not a standard question object.
|
[
"Saves",
"question",
"-",
"type",
"specific",
"options"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/questiontypebase.php#L445-L469
|
216,552
|
moodle/moodle
|
question/type/questiontypebase.php
|
question_type.count_hints_on_form
|
protected function count_hints_on_form($formdata, $withparts) {
if (!empty($formdata->hint)) {
$numhints = max(array_keys($formdata->hint)) + 1;
} else {
$numhints = 0;
}
if ($withparts) {
if (!empty($formdata->hintclearwrong)) {
$numclears = max(array_keys($formdata->hintclearwrong)) + 1;
} else {
$numclears = 0;
}
if (!empty($formdata->hintshownumcorrect)) {
$numshows = max(array_keys($formdata->hintshownumcorrect)) + 1;
} else {
$numshows = 0;
}
$numhints = max($numhints, $numclears, $numshows);
}
return $numhints;
}
|
php
|
protected function count_hints_on_form($formdata, $withparts) {
if (!empty($formdata->hint)) {
$numhints = max(array_keys($formdata->hint)) + 1;
} else {
$numhints = 0;
}
if ($withparts) {
if (!empty($formdata->hintclearwrong)) {
$numclears = max(array_keys($formdata->hintclearwrong)) + 1;
} else {
$numclears = 0;
}
if (!empty($formdata->hintshownumcorrect)) {
$numshows = max(array_keys($formdata->hintshownumcorrect)) + 1;
} else {
$numshows = 0;
}
$numhints = max($numhints, $numclears, $numshows);
}
return $numhints;
}
|
[
"protected",
"function",
"count_hints_on_form",
"(",
"$",
"formdata",
",",
"$",
"withparts",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"formdata",
"->",
"hint",
")",
")",
"{",
"$",
"numhints",
"=",
"max",
"(",
"array_keys",
"(",
"$",
"formdata",
"->",
"hint",
")",
")",
"+",
"1",
";",
"}",
"else",
"{",
"$",
"numhints",
"=",
"0",
";",
"}",
"if",
"(",
"$",
"withparts",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"formdata",
"->",
"hintclearwrong",
")",
")",
"{",
"$",
"numclears",
"=",
"max",
"(",
"array_keys",
"(",
"$",
"formdata",
"->",
"hintclearwrong",
")",
")",
"+",
"1",
";",
"}",
"else",
"{",
"$",
"numclears",
"=",
"0",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"formdata",
"->",
"hintshownumcorrect",
")",
")",
"{",
"$",
"numshows",
"=",
"max",
"(",
"array_keys",
"(",
"$",
"formdata",
"->",
"hintshownumcorrect",
")",
")",
"+",
"1",
";",
"}",
"else",
"{",
"$",
"numshows",
"=",
"0",
";",
"}",
"$",
"numhints",
"=",
"max",
"(",
"$",
"numhints",
",",
"$",
"numclears",
",",
"$",
"numshows",
")",
";",
"}",
"return",
"$",
"numhints",
";",
"}"
] |
Count number of hints on the form.
Overload if you use custom hint controls.
@param object $formdata the data from the form.
@param bool $withparts whether to take into account clearwrong and shownumcorrect options.
@return int count of hints on the form.
|
[
"Count",
"number",
"of",
"hints",
"on",
"the",
"form",
".",
"Overload",
"if",
"you",
"use",
"custom",
"hint",
"controls",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/questiontypebase.php#L686-L707
|
216,553
|
moodle/moodle
|
question/type/questiontypebase.php
|
question_type.is_hint_empty_in_form_data
|
protected function is_hint_empty_in_form_data($formdata, $number, $withparts) {
if ($withparts) {
return empty($formdata->hint[$number]['text']) && empty($formdata->hintclearwrong[$number]) &&
empty($formdata->hintshownumcorrect[$number]);
} else {
return empty($formdata->hint[$number]['text']);
}
}
|
php
|
protected function is_hint_empty_in_form_data($formdata, $number, $withparts) {
if ($withparts) {
return empty($formdata->hint[$number]['text']) && empty($formdata->hintclearwrong[$number]) &&
empty($formdata->hintshownumcorrect[$number]);
} else {
return empty($formdata->hint[$number]['text']);
}
}
|
[
"protected",
"function",
"is_hint_empty_in_form_data",
"(",
"$",
"formdata",
",",
"$",
"number",
",",
"$",
"withparts",
")",
"{",
"if",
"(",
"$",
"withparts",
")",
"{",
"return",
"empty",
"(",
"$",
"formdata",
"->",
"hint",
"[",
"$",
"number",
"]",
"[",
"'text'",
"]",
")",
"&&",
"empty",
"(",
"$",
"formdata",
"->",
"hintclearwrong",
"[",
"$",
"number",
"]",
")",
"&&",
"empty",
"(",
"$",
"formdata",
"->",
"hintshownumcorrect",
"[",
"$",
"number",
"]",
")",
";",
"}",
"else",
"{",
"return",
"empty",
"(",
"$",
"formdata",
"->",
"hint",
"[",
"$",
"number",
"]",
"[",
"'text'",
"]",
")",
";",
"}",
"}"
] |
Determine if the hint with specified number is not empty and should be saved.
Overload if you use custom hint controls.
@param object $formdata the data from the form.
@param int $number number of hint under question.
@param bool $withparts whether to take into account clearwrong and shownumcorrect options.
@return bool is this particular hint data empty.
|
[
"Determine",
"if",
"the",
"hint",
"with",
"specified",
"number",
"is",
"not",
"empty",
"and",
"should",
"be",
"saved",
".",
"Overload",
"if",
"you",
"use",
"custom",
"hint",
"controls",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/questiontypebase.php#L717-L724
|
216,554
|
moodle/moodle
|
question/type/questiontypebase.php
|
question_type.make_question
|
public function make_question($questiondata) {
$question = $this->make_question_instance($questiondata);
$this->initialise_question_instance($question, $questiondata);
return $question;
}
|
php
|
public function make_question($questiondata) {
$question = $this->make_question_instance($questiondata);
$this->initialise_question_instance($question, $questiondata);
return $question;
}
|
[
"public",
"function",
"make_question",
"(",
"$",
"questiondata",
")",
"{",
"$",
"question",
"=",
"$",
"this",
"->",
"make_question_instance",
"(",
"$",
"questiondata",
")",
";",
"$",
"this",
"->",
"initialise_question_instance",
"(",
"$",
"question",
",",
"$",
"questiondata",
")",
";",
"return",
"$",
"question",
";",
"}"
] |
Create an appropriate question_definition for the question of this type
using data loaded from the database.
@param object $questiondata the question data loaded from the database.
@return question_definition the corresponding question_definition.
|
[
"Create",
"an",
"appropriate",
"question_definition",
"for",
"the",
"question",
"of",
"this",
"type",
"using",
"data",
"loaded",
"from",
"the",
"database",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/questiontypebase.php#L838-L842
|
216,555
|
moodle/moodle
|
question/type/questiontypebase.php
|
question_type.initialise_question_instance
|
protected function initialise_question_instance(question_definition $question, $questiondata) {
$question->id = $questiondata->id;
$question->category = $questiondata->category;
$question->contextid = $questiondata->contextid;
$question->parent = $questiondata->parent;
$question->qtype = $this;
$question->name = $questiondata->name;
$question->questiontext = $questiondata->questiontext;
$question->questiontextformat = $questiondata->questiontextformat;
$question->generalfeedback = $questiondata->generalfeedback;
$question->generalfeedbackformat = $questiondata->generalfeedbackformat;
$question->defaultmark = $questiondata->defaultmark + 0;
$question->length = $questiondata->length;
$question->penalty = $questiondata->penalty;
$question->stamp = $questiondata->stamp;
$question->version = $questiondata->version;
$question->hidden = $questiondata->hidden;
$question->idnumber = $questiondata->idnumber;
$question->timecreated = $questiondata->timecreated;
$question->timemodified = $questiondata->timemodified;
$question->createdby = $questiondata->createdby;
$question->modifiedby = $questiondata->modifiedby;
// Fill extra question fields values.
$extraquestionfields = $this->extra_question_fields();
if (is_array($extraquestionfields)) {
// Omit table name.
array_shift($extraquestionfields);
foreach ($extraquestionfields as $field) {
$question->$field = $questiondata->options->$field;
}
}
$this->initialise_question_hints($question, $questiondata);
}
|
php
|
protected function initialise_question_instance(question_definition $question, $questiondata) {
$question->id = $questiondata->id;
$question->category = $questiondata->category;
$question->contextid = $questiondata->contextid;
$question->parent = $questiondata->parent;
$question->qtype = $this;
$question->name = $questiondata->name;
$question->questiontext = $questiondata->questiontext;
$question->questiontextformat = $questiondata->questiontextformat;
$question->generalfeedback = $questiondata->generalfeedback;
$question->generalfeedbackformat = $questiondata->generalfeedbackformat;
$question->defaultmark = $questiondata->defaultmark + 0;
$question->length = $questiondata->length;
$question->penalty = $questiondata->penalty;
$question->stamp = $questiondata->stamp;
$question->version = $questiondata->version;
$question->hidden = $questiondata->hidden;
$question->idnumber = $questiondata->idnumber;
$question->timecreated = $questiondata->timecreated;
$question->timemodified = $questiondata->timemodified;
$question->createdby = $questiondata->createdby;
$question->modifiedby = $questiondata->modifiedby;
// Fill extra question fields values.
$extraquestionfields = $this->extra_question_fields();
if (is_array($extraquestionfields)) {
// Omit table name.
array_shift($extraquestionfields);
foreach ($extraquestionfields as $field) {
$question->$field = $questiondata->options->$field;
}
}
$this->initialise_question_hints($question, $questiondata);
}
|
[
"protected",
"function",
"initialise_question_instance",
"(",
"question_definition",
"$",
"question",
",",
"$",
"questiondata",
")",
"{",
"$",
"question",
"->",
"id",
"=",
"$",
"questiondata",
"->",
"id",
";",
"$",
"question",
"->",
"category",
"=",
"$",
"questiondata",
"->",
"category",
";",
"$",
"question",
"->",
"contextid",
"=",
"$",
"questiondata",
"->",
"contextid",
";",
"$",
"question",
"->",
"parent",
"=",
"$",
"questiondata",
"->",
"parent",
";",
"$",
"question",
"->",
"qtype",
"=",
"$",
"this",
";",
"$",
"question",
"->",
"name",
"=",
"$",
"questiondata",
"->",
"name",
";",
"$",
"question",
"->",
"questiontext",
"=",
"$",
"questiondata",
"->",
"questiontext",
";",
"$",
"question",
"->",
"questiontextformat",
"=",
"$",
"questiondata",
"->",
"questiontextformat",
";",
"$",
"question",
"->",
"generalfeedback",
"=",
"$",
"questiondata",
"->",
"generalfeedback",
";",
"$",
"question",
"->",
"generalfeedbackformat",
"=",
"$",
"questiondata",
"->",
"generalfeedbackformat",
";",
"$",
"question",
"->",
"defaultmark",
"=",
"$",
"questiondata",
"->",
"defaultmark",
"+",
"0",
";",
"$",
"question",
"->",
"length",
"=",
"$",
"questiondata",
"->",
"length",
";",
"$",
"question",
"->",
"penalty",
"=",
"$",
"questiondata",
"->",
"penalty",
";",
"$",
"question",
"->",
"stamp",
"=",
"$",
"questiondata",
"->",
"stamp",
";",
"$",
"question",
"->",
"version",
"=",
"$",
"questiondata",
"->",
"version",
";",
"$",
"question",
"->",
"hidden",
"=",
"$",
"questiondata",
"->",
"hidden",
";",
"$",
"question",
"->",
"idnumber",
"=",
"$",
"questiondata",
"->",
"idnumber",
";",
"$",
"question",
"->",
"timecreated",
"=",
"$",
"questiondata",
"->",
"timecreated",
";",
"$",
"question",
"->",
"timemodified",
"=",
"$",
"questiondata",
"->",
"timemodified",
";",
"$",
"question",
"->",
"createdby",
"=",
"$",
"questiondata",
"->",
"createdby",
";",
"$",
"question",
"->",
"modifiedby",
"=",
"$",
"questiondata",
"->",
"modifiedby",
";",
"// Fill extra question fields values.",
"$",
"extraquestionfields",
"=",
"$",
"this",
"->",
"extra_question_fields",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"extraquestionfields",
")",
")",
"{",
"// Omit table name.",
"array_shift",
"(",
"$",
"extraquestionfields",
")",
";",
"foreach",
"(",
"$",
"extraquestionfields",
"as",
"$",
"field",
")",
"{",
"$",
"question",
"->",
"$",
"field",
"=",
"$",
"questiondata",
"->",
"options",
"->",
"$",
"field",
";",
"}",
"}",
"$",
"this",
"->",
"initialise_question_hints",
"(",
"$",
"question",
",",
"$",
"questiondata",
")",
";",
"}"
] |
Initialise the common question_definition fields.
@param question_definition $question the question_definition we are creating.
@param object $questiondata the question data loaded from the database.
|
[
"Initialise",
"the",
"common",
"question_definition",
"fields",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/questiontypebase.php#L862-L896
|
216,556
|
moodle/moodle
|
question/type/questiontypebase.php
|
question_type.initialise_combined_feedback
|
protected function initialise_combined_feedback(question_definition $question,
$questiondata, $withparts = false) {
$question->correctfeedback = $questiondata->options->correctfeedback;
$question->correctfeedbackformat = $questiondata->options->correctfeedbackformat;
$question->partiallycorrectfeedback = $questiondata->options->partiallycorrectfeedback;
$question->partiallycorrectfeedbackformat =
$questiondata->options->partiallycorrectfeedbackformat;
$question->incorrectfeedback = $questiondata->options->incorrectfeedback;
$question->incorrectfeedbackformat = $questiondata->options->incorrectfeedbackformat;
if ($withparts) {
$question->shownumcorrect = $questiondata->options->shownumcorrect;
}
}
|
php
|
protected function initialise_combined_feedback(question_definition $question,
$questiondata, $withparts = false) {
$question->correctfeedback = $questiondata->options->correctfeedback;
$question->correctfeedbackformat = $questiondata->options->correctfeedbackformat;
$question->partiallycorrectfeedback = $questiondata->options->partiallycorrectfeedback;
$question->partiallycorrectfeedbackformat =
$questiondata->options->partiallycorrectfeedbackformat;
$question->incorrectfeedback = $questiondata->options->incorrectfeedback;
$question->incorrectfeedbackformat = $questiondata->options->incorrectfeedbackformat;
if ($withparts) {
$question->shownumcorrect = $questiondata->options->shownumcorrect;
}
}
|
[
"protected",
"function",
"initialise_combined_feedback",
"(",
"question_definition",
"$",
"question",
",",
"$",
"questiondata",
",",
"$",
"withparts",
"=",
"false",
")",
"{",
"$",
"question",
"->",
"correctfeedback",
"=",
"$",
"questiondata",
"->",
"options",
"->",
"correctfeedback",
";",
"$",
"question",
"->",
"correctfeedbackformat",
"=",
"$",
"questiondata",
"->",
"options",
"->",
"correctfeedbackformat",
";",
"$",
"question",
"->",
"partiallycorrectfeedback",
"=",
"$",
"questiondata",
"->",
"options",
"->",
"partiallycorrectfeedback",
";",
"$",
"question",
"->",
"partiallycorrectfeedbackformat",
"=",
"$",
"questiondata",
"->",
"options",
"->",
"partiallycorrectfeedbackformat",
";",
"$",
"question",
"->",
"incorrectfeedback",
"=",
"$",
"questiondata",
"->",
"options",
"->",
"incorrectfeedback",
";",
"$",
"question",
"->",
"incorrectfeedbackformat",
"=",
"$",
"questiondata",
"->",
"options",
"->",
"incorrectfeedbackformat",
";",
"if",
"(",
"$",
"withparts",
")",
"{",
"$",
"question",
"->",
"shownumcorrect",
"=",
"$",
"questiondata",
"->",
"options",
"->",
"shownumcorrect",
";",
"}",
"}"
] |
Initialise the combined feedback fields.
@param question_definition $question the question_definition we are creating.
@param object $questiondata the question data loaded from the database.
@param bool $withparts whether to set the shownumcorrect field.
|
[
"Initialise",
"the",
"combined",
"feedback",
"fields",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/questiontypebase.php#L928-L940
|
216,557
|
moodle/moodle
|
question/type/questiontypebase.php
|
question_type.make_answer
|
protected function make_answer($answer) {
return new question_answer($answer->id, $answer->answer,
$answer->fraction, $answer->feedback, $answer->feedbackformat);
}
|
php
|
protected function make_answer($answer) {
return new question_answer($answer->id, $answer->answer,
$answer->fraction, $answer->feedback, $answer->feedbackformat);
}
|
[
"protected",
"function",
"make_answer",
"(",
"$",
"answer",
")",
"{",
"return",
"new",
"question_answer",
"(",
"$",
"answer",
"->",
"id",
",",
"$",
"answer",
"->",
"answer",
",",
"$",
"answer",
"->",
"fraction",
",",
"$",
"answer",
"->",
"feedback",
",",
"$",
"answer",
"->",
"feedbackformat",
")",
";",
"}"
] |
Create a question_answer, or an appropriate subclass for this question,
from a row loaded from the database.
@param object $answer the DB row from the question_answers table plus extra answer fields.
@return question_answer
|
[
"Create",
"a",
"question_answer",
"or",
"an",
"appropriate",
"subclass",
"for",
"this",
"question",
"from",
"a",
"row",
"loaded",
"from",
"the",
"database",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/questiontypebase.php#L972-L975
|
216,558
|
moodle/moodle
|
question/type/questiontypebase.php
|
question_type.delete_question
|
public function delete_question($questionid, $contextid) {
global $DB;
$this->delete_files($questionid, $contextid);
$extraquestionfields = $this->extra_question_fields();
if (is_array($extraquestionfields)) {
$question_extension_table = array_shift($extraquestionfields);
$DB->delete_records($question_extension_table,
array($this->questionid_column_name() => $questionid));
}
$extraanswerfields = $this->extra_answer_fields();
if (is_array($extraanswerfields)) {
$answer_extension_table = array_shift($extraanswerfields);
$DB->delete_records_select($answer_extension_table,
'answerid IN (SELECT qa.id FROM {question_answers} qa WHERE qa.question = ?)',
array($questionid));
}
$DB->delete_records('question_answers', array('question' => $questionid));
$DB->delete_records('question_hints', array('questionid' => $questionid));
}
|
php
|
public function delete_question($questionid, $contextid) {
global $DB;
$this->delete_files($questionid, $contextid);
$extraquestionfields = $this->extra_question_fields();
if (is_array($extraquestionfields)) {
$question_extension_table = array_shift($extraquestionfields);
$DB->delete_records($question_extension_table,
array($this->questionid_column_name() => $questionid));
}
$extraanswerfields = $this->extra_answer_fields();
if (is_array($extraanswerfields)) {
$answer_extension_table = array_shift($extraanswerfields);
$DB->delete_records_select($answer_extension_table,
'answerid IN (SELECT qa.id FROM {question_answers} qa WHERE qa.question = ?)',
array($questionid));
}
$DB->delete_records('question_answers', array('question' => $questionid));
$DB->delete_records('question_hints', array('questionid' => $questionid));
}
|
[
"public",
"function",
"delete_question",
"(",
"$",
"questionid",
",",
"$",
"contextid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"this",
"->",
"delete_files",
"(",
"$",
"questionid",
",",
"$",
"contextid",
")",
";",
"$",
"extraquestionfields",
"=",
"$",
"this",
"->",
"extra_question_fields",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"extraquestionfields",
")",
")",
"{",
"$",
"question_extension_table",
"=",
"array_shift",
"(",
"$",
"extraquestionfields",
")",
";",
"$",
"DB",
"->",
"delete_records",
"(",
"$",
"question_extension_table",
",",
"array",
"(",
"$",
"this",
"->",
"questionid_column_name",
"(",
")",
"=>",
"$",
"questionid",
")",
")",
";",
"}",
"$",
"extraanswerfields",
"=",
"$",
"this",
"->",
"extra_answer_fields",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"extraanswerfields",
")",
")",
"{",
"$",
"answer_extension_table",
"=",
"array_shift",
"(",
"$",
"extraanswerfields",
")",
";",
"$",
"DB",
"->",
"delete_records_select",
"(",
"$",
"answer_extension_table",
",",
"'answerid IN (SELECT qa.id FROM {question_answers} qa WHERE qa.question = ?)'",
",",
"array",
"(",
"$",
"questionid",
")",
")",
";",
"}",
"$",
"DB",
"->",
"delete_records",
"(",
"'question_answers'",
",",
"array",
"(",
"'question'",
"=>",
"$",
"questionid",
")",
")",
";",
"$",
"DB",
"->",
"delete_records",
"(",
"'question_hints'",
",",
"array",
"(",
"'questionid'",
"=>",
"$",
"questionid",
")",
")",
";",
"}"
] |
Deletes the question-type specific data when a question is deleted.
@param int $question the question being deleted.
@param int $contextid the context this quesiotn belongs to.
|
[
"Deletes",
"the",
"question",
"-",
"type",
"specific",
"data",
"when",
"a",
"question",
"is",
"deleted",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/questiontypebase.php#L982-L1005
|
216,559
|
moodle/moodle
|
question/type/questiontypebase.php
|
question_type.get_context_by_category_id
|
protected function get_context_by_category_id($category) {
global $DB;
$contextid = $DB->get_field('question_categories', 'contextid', array('id'=>$category));
$context = context::instance_by_id($contextid, IGNORE_MISSING);
return $context;
}
|
php
|
protected function get_context_by_category_id($category) {
global $DB;
$contextid = $DB->get_field('question_categories', 'contextid', array('id'=>$category));
$context = context::instance_by_id($contextid, IGNORE_MISSING);
return $context;
}
|
[
"protected",
"function",
"get_context_by_category_id",
"(",
"$",
"category",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"contextid",
"=",
"$",
"DB",
"->",
"get_field",
"(",
"'question_categories'",
",",
"'contextid'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"category",
")",
")",
";",
"$",
"context",
"=",
"context",
"::",
"instance_by_id",
"(",
"$",
"contextid",
",",
"IGNORE_MISSING",
")",
";",
"return",
"$",
"context",
";",
"}"
] |
Get question context by category id
@param int $category
@return object $context
|
[
"Get",
"question",
"context",
"by",
"category",
"id"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/questiontypebase.php#L1237-L1242
|
216,560
|
moodle/moodle
|
question/type/questiontypebase.php
|
question_type.import_or_save_files
|
protected function import_or_save_files($field, $context, $component, $filearea, $itemid) {
if (!empty($field['itemid'])) {
// This is the normal case. We are safing the questions editing form.
return file_save_draft_area_files($field['itemid'], $context->id, $component,
$filearea, $itemid, $this->fileoptions, trim($field['text']));
} else if (!empty($field['files'])) {
// This is the case when we are doing an import.
foreach ($field['files'] as $file) {
$this->import_file($context, $component, $filearea, $itemid, $file);
}
}
return trim($field['text']);
}
|
php
|
protected function import_or_save_files($field, $context, $component, $filearea, $itemid) {
if (!empty($field['itemid'])) {
// This is the normal case. We are safing the questions editing form.
return file_save_draft_area_files($field['itemid'], $context->id, $component,
$filearea, $itemid, $this->fileoptions, trim($field['text']));
} else if (!empty($field['files'])) {
// This is the case when we are doing an import.
foreach ($field['files'] as $file) {
$this->import_file($context, $component, $filearea, $itemid, $file);
}
}
return trim($field['text']);
}
|
[
"protected",
"function",
"import_or_save_files",
"(",
"$",
"field",
",",
"$",
"context",
",",
"$",
"component",
",",
"$",
"filearea",
",",
"$",
"itemid",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"field",
"[",
"'itemid'",
"]",
")",
")",
"{",
"// This is the normal case. We are safing the questions editing form.",
"return",
"file_save_draft_area_files",
"(",
"$",
"field",
"[",
"'itemid'",
"]",
",",
"$",
"context",
"->",
"id",
",",
"$",
"component",
",",
"$",
"filearea",
",",
"$",
"itemid",
",",
"$",
"this",
"->",
"fileoptions",
",",
"trim",
"(",
"$",
"field",
"[",
"'text'",
"]",
")",
")",
";",
"}",
"else",
"if",
"(",
"!",
"empty",
"(",
"$",
"field",
"[",
"'files'",
"]",
")",
")",
"{",
"// This is the case when we are doing an import.",
"foreach",
"(",
"$",
"field",
"[",
"'files'",
"]",
"as",
"$",
"file",
")",
"{",
"$",
"this",
"->",
"import_file",
"(",
"$",
"context",
",",
"$",
"component",
",",
"$",
"filearea",
",",
"$",
"itemid",
",",
"$",
"file",
")",
";",
"}",
"}",
"return",
"trim",
"(",
"$",
"field",
"[",
"'text'",
"]",
")",
";",
"}"
] |
Save the file belonging to one text field.
@param array $field the data from the form (or from import). This will
normally have come from the formslib editor element, so it will be an
array with keys 'text', 'format' and 'itemid'. However, when we are
importing, it will be an array with keys 'text', 'format' and 'files'
@param object $context the context the question is in.
@param string $component indentifies the file area question.
@param string $filearea indentifies the file area questiontext,
generalfeedback, answerfeedback, etc.
@param int $itemid identifies the file area.
@return string the text for this field, after files have been processed.
|
[
"Save",
"the",
"file",
"belonging",
"to",
"one",
"text",
"field",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/questiontypebase.php#L1259-L1272
|
216,561
|
moodle/moodle
|
question/type/questiontypebase.php
|
question_type.move_files
|
public function move_files($questionid, $oldcontextid, $newcontextid) {
$fs = get_file_storage();
$fs->move_area_files_to_new_context($oldcontextid,
$newcontextid, 'question', 'questiontext', $questionid);
$fs->move_area_files_to_new_context($oldcontextid,
$newcontextid, 'question', 'generalfeedback', $questionid);
}
|
php
|
public function move_files($questionid, $oldcontextid, $newcontextid) {
$fs = get_file_storage();
$fs->move_area_files_to_new_context($oldcontextid,
$newcontextid, 'question', 'questiontext', $questionid);
$fs->move_area_files_to_new_context($oldcontextid,
$newcontextid, 'question', 'generalfeedback', $questionid);
}
|
[
"public",
"function",
"move_files",
"(",
"$",
"questionid",
",",
"$",
"oldcontextid",
",",
"$",
"newcontextid",
")",
"{",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"$",
"fs",
"->",
"move_area_files_to_new_context",
"(",
"$",
"oldcontextid",
",",
"$",
"newcontextid",
",",
"'question'",
",",
"'questiontext'",
",",
"$",
"questionid",
")",
";",
"$",
"fs",
"->",
"move_area_files_to_new_context",
"(",
"$",
"oldcontextid",
",",
"$",
"newcontextid",
",",
"'question'",
",",
"'generalfeedback'",
",",
"$",
"questionid",
")",
";",
"}"
] |
Move all the files belonging to this question from one context to another.
@param int $questionid the question being moved.
@param int $oldcontextid the context it is moving from.
@param int $newcontextid the context it is moving to.
|
[
"Move",
"all",
"the",
"files",
"belonging",
"to",
"this",
"question",
"from",
"one",
"context",
"to",
"another",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/questiontypebase.php#L1280-L1286
|
216,562
|
moodle/moodle
|
question/type/questiontypebase.php
|
question_type.move_files_in_hints
|
protected function move_files_in_hints($questionid, $oldcontextid, $newcontextid) {
global $DB;
$fs = get_file_storage();
$hintids = $DB->get_records_menu('question_hints',
array('questionid' => $questionid), 'id', 'id,1');
foreach ($hintids as $hintid => $notused) {
$fs->move_area_files_to_new_context($oldcontextid,
$newcontextid, 'question', 'hint', $hintid);
}
}
|
php
|
protected function move_files_in_hints($questionid, $oldcontextid, $newcontextid) {
global $DB;
$fs = get_file_storage();
$hintids = $DB->get_records_menu('question_hints',
array('questionid' => $questionid), 'id', 'id,1');
foreach ($hintids as $hintid => $notused) {
$fs->move_area_files_to_new_context($oldcontextid,
$newcontextid, 'question', 'hint', $hintid);
}
}
|
[
"protected",
"function",
"move_files_in_hints",
"(",
"$",
"questionid",
",",
"$",
"oldcontextid",
",",
"$",
"newcontextid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"$",
"hintids",
"=",
"$",
"DB",
"->",
"get_records_menu",
"(",
"'question_hints'",
",",
"array",
"(",
"'questionid'",
"=>",
"$",
"questionid",
")",
",",
"'id'",
",",
"'id,1'",
")",
";",
"foreach",
"(",
"$",
"hintids",
"as",
"$",
"hintid",
"=>",
"$",
"notused",
")",
"{",
"$",
"fs",
"->",
"move_area_files_to_new_context",
"(",
"$",
"oldcontextid",
",",
"$",
"newcontextid",
",",
"'question'",
",",
"'hint'",
",",
"$",
"hintid",
")",
";",
"}",
"}"
] |
Move all the files belonging to this question's hints when the question
is moved from one context to another.
@param int $questionid the question being moved.
@param int $oldcontextid the context it is moving from.
@param int $newcontextid the context it is moving to.
@param bool $answerstoo whether there is an 'answer' question area,
as well as an 'answerfeedback' one. Default false.
|
[
"Move",
"all",
"the",
"files",
"belonging",
"to",
"this",
"question",
"s",
"hints",
"when",
"the",
"question",
"is",
"moved",
"from",
"one",
"context",
"to",
"another",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/questiontypebase.php#L1323-L1333
|
216,563
|
moodle/moodle
|
question/type/questiontypebase.php
|
question_type.delete_files_in_hints
|
protected function delete_files_in_hints($questionid, $contextid) {
global $DB;
$fs = get_file_storage();
$hintids = $DB->get_records_menu('question_hints',
array('questionid' => $questionid), 'id', 'id,1');
foreach ($hintids as $hintid => $notused) {
$fs->delete_area_files($contextid, 'question', 'hint', $hintid);
}
}
|
php
|
protected function delete_files_in_hints($questionid, $contextid) {
global $DB;
$fs = get_file_storage();
$hintids = $DB->get_records_menu('question_hints',
array('questionid' => $questionid), 'id', 'id,1');
foreach ($hintids as $hintid => $notused) {
$fs->delete_area_files($contextid, 'question', 'hint', $hintid);
}
}
|
[
"protected",
"function",
"delete_files_in_hints",
"(",
"$",
"questionid",
",",
"$",
"contextid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"$",
"hintids",
"=",
"$",
"DB",
"->",
"get_records_menu",
"(",
"'question_hints'",
",",
"array",
"(",
"'questionid'",
"=>",
"$",
"questionid",
")",
",",
"'id'",
",",
"'id,1'",
")",
";",
"foreach",
"(",
"$",
"hintids",
"as",
"$",
"hintid",
"=>",
"$",
"notused",
")",
"{",
"$",
"fs",
"->",
"delete_area_files",
"(",
"$",
"contextid",
",",
"'question'",
",",
"'hint'",
",",
"$",
"hintid",
")",
";",
"}",
"}"
] |
Delete all the files belonging to this question's hints.
@param int $questionid the question being deleted.
@param int $contextid the context the question is in.
|
[
"Delete",
"all",
"the",
"files",
"belonging",
"to",
"this",
"question",
"s",
"hints",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/questiontypebase.php#L1394-L1403
|
216,564
|
moodle/moodle
|
admin/tool/lp/classes/external.php
|
external.get_context_parameters
|
protected static function get_context_parameters() {
$id = new external_value(
PARAM_INT,
'Context ID. Either use this value, or level and instanceid.',
VALUE_DEFAULT,
0
);
$level = new external_value(
PARAM_ALPHA,
'Context level. To be used with instanceid.',
VALUE_DEFAULT,
''
);
$instanceid = new external_value(
PARAM_INT,
'Context instance ID. To be used with level',
VALUE_DEFAULT,
0
);
return new external_single_structure(array(
'contextid' => $id,
'contextlevel' => $level,
'instanceid' => $instanceid,
));
}
|
php
|
protected static function get_context_parameters() {
$id = new external_value(
PARAM_INT,
'Context ID. Either use this value, or level and instanceid.',
VALUE_DEFAULT,
0
);
$level = new external_value(
PARAM_ALPHA,
'Context level. To be used with instanceid.',
VALUE_DEFAULT,
''
);
$instanceid = new external_value(
PARAM_INT,
'Context instance ID. To be used with level',
VALUE_DEFAULT,
0
);
return new external_single_structure(array(
'contextid' => $id,
'contextlevel' => $level,
'instanceid' => $instanceid,
));
}
|
[
"protected",
"static",
"function",
"get_context_parameters",
"(",
")",
"{",
"$",
"id",
"=",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Context ID. Either use this value, or level and instanceid.'",
",",
"VALUE_DEFAULT",
",",
"0",
")",
";",
"$",
"level",
"=",
"new",
"external_value",
"(",
"PARAM_ALPHA",
",",
"'Context level. To be used with instanceid.'",
",",
"VALUE_DEFAULT",
",",
"''",
")",
";",
"$",
"instanceid",
"=",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Context instance ID. To be used with level'",
",",
"VALUE_DEFAULT",
",",
"0",
")",
";",
"return",
"new",
"external_single_structure",
"(",
"array",
"(",
"'contextid'",
"=>",
"$",
"id",
",",
"'contextlevel'",
"=>",
"$",
"level",
",",
"'instanceid'",
"=>",
"$",
"instanceid",
",",
")",
")",
";",
"}"
] |
Returns a prepared structure to use a context parameters.
@return external_single_structure
|
[
"Returns",
"a",
"prepared",
"structure",
"to",
"use",
"a",
"context",
"parameters",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lp/classes/external.php#L83-L107
|
216,565
|
moodle/moodle
|
admin/tool/lp/classes/external.php
|
external.data_for_competency_frameworks_manage_page
|
public static function data_for_competency_frameworks_manage_page($pagecontext) {
global $PAGE;
$params = self::validate_parameters(
self::data_for_competency_frameworks_manage_page_parameters(),
array(
'pagecontext' => $pagecontext
)
);
$context = self::get_context_from_params($params['pagecontext']);
self::validate_context($context);
$renderable = new output\manage_competency_frameworks_page($context);
$renderer = $PAGE->get_renderer('tool_lp');
$data = $renderable->export_for_template($renderer);
return $data;
}
|
php
|
public static function data_for_competency_frameworks_manage_page($pagecontext) {
global $PAGE;
$params = self::validate_parameters(
self::data_for_competency_frameworks_manage_page_parameters(),
array(
'pagecontext' => $pagecontext
)
);
$context = self::get_context_from_params($params['pagecontext']);
self::validate_context($context);
$renderable = new output\manage_competency_frameworks_page($context);
$renderer = $PAGE->get_renderer('tool_lp');
$data = $renderable->export_for_template($renderer);
return $data;
}
|
[
"public",
"static",
"function",
"data_for_competency_frameworks_manage_page",
"(",
"$",
"pagecontext",
")",
"{",
"global",
"$",
"PAGE",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"data_for_competency_frameworks_manage_page_parameters",
"(",
")",
",",
"array",
"(",
"'pagecontext'",
"=>",
"$",
"pagecontext",
")",
")",
";",
"$",
"context",
"=",
"self",
"::",
"get_context_from_params",
"(",
"$",
"params",
"[",
"'pagecontext'",
"]",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"$",
"renderable",
"=",
"new",
"output",
"\\",
"manage_competency_frameworks_page",
"(",
"$",
"context",
")",
";",
"$",
"renderer",
"=",
"$",
"PAGE",
"->",
"get_renderer",
"(",
"'tool_lp'",
")",
";",
"$",
"data",
"=",
"$",
"renderable",
"->",
"export_for_template",
"(",
"$",
"renderer",
")",
";",
"return",
"$",
"data",
";",
"}"
] |
Loads the data required to render the competency_frameworks_manage_page template.
@param context $pagecontext The page context
@return \stdClass
|
[
"Loads",
"the",
"data",
"required",
"to",
"render",
"the",
"competency_frameworks_manage_page",
"template",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lp/classes/external.php#L125-L143
|
216,566
|
moodle/moodle
|
admin/tool/lp/classes/external.php
|
external.data_for_competencies_manage_page
|
public static function data_for_competencies_manage_page($competencyframeworkid, $search) {
global $PAGE;
$params = self::validate_parameters(self::data_for_competencies_manage_page_parameters(), array(
'competencyframeworkid' => $competencyframeworkid,
'search' => $search
));
$framework = api::read_framework($params['competencyframeworkid']);
self::validate_context($framework->get_context());
$output = $PAGE->get_renderer('tool_lp');
$renderable = new output\manage_competencies_page($framework, $params['search'], $framework->get_context(), null);
$data = $renderable->export_for_template($output);
return $data;
}
|
php
|
public static function data_for_competencies_manage_page($competencyframeworkid, $search) {
global $PAGE;
$params = self::validate_parameters(self::data_for_competencies_manage_page_parameters(), array(
'competencyframeworkid' => $competencyframeworkid,
'search' => $search
));
$framework = api::read_framework($params['competencyframeworkid']);
self::validate_context($framework->get_context());
$output = $PAGE->get_renderer('tool_lp');
$renderable = new output\manage_competencies_page($framework, $params['search'], $framework->get_context(), null);
$data = $renderable->export_for_template($output);
return $data;
}
|
[
"public",
"static",
"function",
"data_for_competencies_manage_page",
"(",
"$",
"competencyframeworkid",
",",
"$",
"search",
")",
"{",
"global",
"$",
"PAGE",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"data_for_competencies_manage_page_parameters",
"(",
")",
",",
"array",
"(",
"'competencyframeworkid'",
"=>",
"$",
"competencyframeworkid",
",",
"'search'",
"=>",
"$",
"search",
")",
")",
";",
"$",
"framework",
"=",
"api",
"::",
"read_framework",
"(",
"$",
"params",
"[",
"'competencyframeworkid'",
"]",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"framework",
"->",
"get_context",
"(",
")",
")",
";",
"$",
"output",
"=",
"$",
"PAGE",
"->",
"get_renderer",
"(",
"'tool_lp'",
")",
";",
"$",
"renderable",
"=",
"new",
"output",
"\\",
"manage_competencies_page",
"(",
"$",
"framework",
",",
"$",
"params",
"[",
"'search'",
"]",
",",
"$",
"framework",
"->",
"get_context",
"(",
")",
",",
"null",
")",
";",
"$",
"data",
"=",
"$",
"renderable",
"->",
"export_for_template",
"(",
"$",
"output",
")",
";",
"return",
"$",
"data",
";",
"}"
] |
Loads the data required to render the competencies_manage_page template.
@param int $competencyframeworkid Framework id.
@param string $search Text to search.
@return boolean
|
[
"Loads",
"the",
"data",
"required",
"to",
"render",
"the",
"competencies_manage_page",
"template",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lp/classes/external.php#L196-L213
|
216,567
|
moodle/moodle
|
admin/tool/lp/classes/external.php
|
external.data_for_competency_summary
|
public static function data_for_competency_summary($competencyid, $includerelated = false, $includecourses = false) {
global $PAGE;
$params = self::validate_parameters(self::data_for_competency_summary_parameters(), array(
'competencyid' => $competencyid,
'includerelated' => $includerelated,
'includecourses' => $includecourses
));
$competency = api::read_competency($params['competencyid']);
$framework = api::read_framework($competency->get_competencyframeworkid());
self::validate_context($framework->get_context());
$renderable = new output\competency_summary($competency, $framework, $params['includerelated'], $params['includecourses']);
$renderer = $PAGE->get_renderer('tool_lp');
$data = $renderable->export_for_template($renderer);
return $data;
}
|
php
|
public static function data_for_competency_summary($competencyid, $includerelated = false, $includecourses = false) {
global $PAGE;
$params = self::validate_parameters(self::data_for_competency_summary_parameters(), array(
'competencyid' => $competencyid,
'includerelated' => $includerelated,
'includecourses' => $includecourses
));
$competency = api::read_competency($params['competencyid']);
$framework = api::read_framework($competency->get_competencyframeworkid());
self::validate_context($framework->get_context());
$renderable = new output\competency_summary($competency, $framework, $params['includerelated'], $params['includecourses']);
$renderer = $PAGE->get_renderer('tool_lp');
$data = $renderable->export_for_template($renderer);
return $data;
}
|
[
"public",
"static",
"function",
"data_for_competency_summary",
"(",
"$",
"competencyid",
",",
"$",
"includerelated",
"=",
"false",
",",
"$",
"includecourses",
"=",
"false",
")",
"{",
"global",
"$",
"PAGE",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"data_for_competency_summary_parameters",
"(",
")",
",",
"array",
"(",
"'competencyid'",
"=>",
"$",
"competencyid",
",",
"'includerelated'",
"=>",
"$",
"includerelated",
",",
"'includecourses'",
"=>",
"$",
"includecourses",
")",
")",
";",
"$",
"competency",
"=",
"api",
"::",
"read_competency",
"(",
"$",
"params",
"[",
"'competencyid'",
"]",
")",
";",
"$",
"framework",
"=",
"api",
"::",
"read_framework",
"(",
"$",
"competency",
"->",
"get_competencyframeworkid",
"(",
")",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"framework",
"->",
"get_context",
"(",
")",
")",
";",
"$",
"renderable",
"=",
"new",
"output",
"\\",
"competency_summary",
"(",
"$",
"competency",
",",
"$",
"framework",
",",
"$",
"params",
"[",
"'includerelated'",
"]",
",",
"$",
"params",
"[",
"'includecourses'",
"]",
")",
";",
"$",
"renderer",
"=",
"$",
"PAGE",
"->",
"get_renderer",
"(",
"'tool_lp'",
")",
";",
"$",
"data",
"=",
"$",
"renderable",
"->",
"export_for_template",
"(",
"$",
"renderer",
")",
";",
"return",
"$",
"data",
";",
"}"
] |
Loads the data required to render the competency_page template.
@param int $competencyid Competency id.
@param boolean $includerelated Include or not related competencies.
@param boolean $includecourses Include or not competency courses.
@return \stdClass
|
[
"Loads",
"the",
"data",
"required",
"to",
"render",
"the",
"competency_page",
"template",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lp/classes/external.php#L272-L289
|
216,568
|
moodle/moodle
|
admin/tool/lp/classes/external.php
|
external.data_for_course_competencies_page
|
public static function data_for_course_competencies_page($courseid) {
global $PAGE;
$params = self::validate_parameters(self::data_for_course_competencies_page_parameters(), array(
'courseid' => $courseid,
));
self::validate_context(context_course::instance($params['courseid']));
$renderable = new output\course_competencies_page($params['courseid']);
$renderer = $PAGE->get_renderer('tool_lp');
$data = $renderable->export_for_template($renderer);
return $data;
}
|
php
|
public static function data_for_course_competencies_page($courseid) {
global $PAGE;
$params = self::validate_parameters(self::data_for_course_competencies_page_parameters(), array(
'courseid' => $courseid,
));
self::validate_context(context_course::instance($params['courseid']));
$renderable = new output\course_competencies_page($params['courseid']);
$renderer = $PAGE->get_renderer('tool_lp');
$data = $renderable->export_for_template($renderer);
return $data;
}
|
[
"public",
"static",
"function",
"data_for_course_competencies_page",
"(",
"$",
"courseid",
")",
"{",
"global",
"$",
"PAGE",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"data_for_course_competencies_page_parameters",
"(",
")",
",",
"array",
"(",
"'courseid'",
"=>",
"$",
"courseid",
",",
")",
")",
";",
"self",
"::",
"validate_context",
"(",
"context_course",
"::",
"instance",
"(",
"$",
"params",
"[",
"'courseid'",
"]",
")",
")",
";",
"$",
"renderable",
"=",
"new",
"output",
"\\",
"course_competencies_page",
"(",
"$",
"params",
"[",
"'courseid'",
"]",
")",
";",
"$",
"renderer",
"=",
"$",
"PAGE",
"->",
"get_renderer",
"(",
"'tool_lp'",
")",
";",
"$",
"data",
"=",
"$",
"renderable",
"->",
"export_for_template",
"(",
"$",
"renderer",
")",
";",
"return",
"$",
"data",
";",
"}"
] |
Loads the data required to render the course_competencies_page template.
@param int $courseid The course id to check.
@return boolean
|
[
"Loads",
"the",
"data",
"required",
"to",
"render",
"the",
"course_competencies_page",
"template",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lp/classes/external.php#L376-L389
|
216,569
|
moodle/moodle
|
admin/tool/lp/classes/external.php
|
external.data_for_templates_manage_page
|
public static function data_for_templates_manage_page($pagecontext) {
global $PAGE;
$params = self::validate_parameters(self::data_for_templates_manage_page_parameters(), array(
'pagecontext' => $pagecontext
));
$context = self::get_context_from_params($params['pagecontext']);
self::validate_context($context);
$renderable = new output\manage_templates_page($context);
$renderer = $PAGE->get_renderer('tool_lp');
$data = $renderable->export_for_template($renderer);
return $data;
}
|
php
|
public static function data_for_templates_manage_page($pagecontext) {
global $PAGE;
$params = self::validate_parameters(self::data_for_templates_manage_page_parameters(), array(
'pagecontext' => $pagecontext
));
$context = self::get_context_from_params($params['pagecontext']);
self::validate_context($context);
$renderable = new output\manage_templates_page($context);
$renderer = $PAGE->get_renderer('tool_lp');
$data = $renderable->export_for_template($renderer);
return $data;
}
|
[
"public",
"static",
"function",
"data_for_templates_manage_page",
"(",
"$",
"pagecontext",
")",
"{",
"global",
"$",
"PAGE",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"data_for_templates_manage_page_parameters",
"(",
")",
",",
"array",
"(",
"'pagecontext'",
"=>",
"$",
"pagecontext",
")",
")",
";",
"$",
"context",
"=",
"self",
"::",
"get_context_from_params",
"(",
"$",
"params",
"[",
"'pagecontext'",
"]",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"$",
"renderable",
"=",
"new",
"output",
"\\",
"manage_templates_page",
"(",
"$",
"context",
")",
";",
"$",
"renderer",
"=",
"$",
"PAGE",
"->",
"get_renderer",
"(",
"'tool_lp'",
")",
";",
"$",
"data",
"=",
"$",
"renderable",
"->",
"export_for_template",
"(",
"$",
"renderer",
")",
";",
"return",
"$",
"data",
";",
"}"
] |
Loads the data required to render the templates_manage_page template.
@param array $pagecontext The page context info.
@return boolean
|
[
"Loads",
"the",
"data",
"required",
"to",
"render",
"the",
"templates_manage_page",
"template",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lp/classes/external.php#L448-L463
|
216,570
|
moodle/moodle
|
admin/tool/lp/classes/external.php
|
external.data_for_template_competencies_page
|
public static function data_for_template_competencies_page($templateid, $pagecontext) {
global $PAGE;
$params = self::validate_parameters(self::data_for_template_competencies_page_parameters(), array(
'templateid' => $templateid,
'pagecontext' => $pagecontext
));
$context = self::get_context_from_params($params['pagecontext']);
self::validate_context($context);
$template = api::read_template($params['templateid']);
$renderable = new output\template_competencies_page($template, $context);
$renderer = $PAGE->get_renderer('tool_lp');
$data = $renderable->export_for_template($renderer);
return $data;
}
|
php
|
public static function data_for_template_competencies_page($templateid, $pagecontext) {
global $PAGE;
$params = self::validate_parameters(self::data_for_template_competencies_page_parameters(), array(
'templateid' => $templateid,
'pagecontext' => $pagecontext
));
$context = self::get_context_from_params($params['pagecontext']);
self::validate_context($context);
$template = api::read_template($params['templateid']);
$renderable = new output\template_competencies_page($template, $context);
$renderer = $PAGE->get_renderer('tool_lp');
$data = $renderable->export_for_template($renderer);
return $data;
}
|
[
"public",
"static",
"function",
"data_for_template_competencies_page",
"(",
"$",
"templateid",
",",
"$",
"pagecontext",
")",
"{",
"global",
"$",
"PAGE",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"data_for_template_competencies_page_parameters",
"(",
")",
",",
"array",
"(",
"'templateid'",
"=>",
"$",
"templateid",
",",
"'pagecontext'",
"=>",
"$",
"pagecontext",
")",
")",
";",
"$",
"context",
"=",
"self",
"::",
"get_context_from_params",
"(",
"$",
"params",
"[",
"'pagecontext'",
"]",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"$",
"template",
"=",
"api",
"::",
"read_template",
"(",
"$",
"params",
"[",
"'templateid'",
"]",
")",
";",
"$",
"renderable",
"=",
"new",
"output",
"\\",
"template_competencies_page",
"(",
"$",
"template",
",",
"$",
"context",
")",
";",
"$",
"renderer",
"=",
"$",
"PAGE",
"->",
"get_renderer",
"(",
"'tool_lp'",
")",
";",
"$",
"data",
"=",
"$",
"renderable",
"->",
"export_for_template",
"(",
"$",
"renderer",
")",
";",
"return",
"$",
"data",
";",
"}"
] |
Loads the data required to render the template_competencies_page template.
@param int $templateid Template id.
@param array $pagecontext The page context info.
@return boolean
|
[
"Loads",
"the",
"data",
"required",
"to",
"render",
"the",
"template_competencies_page",
"template",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lp/classes/external.php#L507-L524
|
216,571
|
moodle/moodle
|
admin/tool/lp/classes/external.php
|
external.data_for_plan_page
|
public static function data_for_plan_page($planid) {
global $PAGE;
$params = self::validate_parameters(self::data_for_plan_page_parameters(), array(
'planid' => $planid
));
$plan = api::read_plan($params['planid']);
self::validate_context($plan->get_context());
$renderable = new output\plan_page($plan);
$renderer = $PAGE->get_renderer('tool_lp');
$data = $renderable->export_for_template($renderer);
return $data;
}
|
php
|
public static function data_for_plan_page($planid) {
global $PAGE;
$params = self::validate_parameters(self::data_for_plan_page_parameters(), array(
'planid' => $planid
));
$plan = api::read_plan($params['planid']);
self::validate_context($plan->get_context());
$renderable = new output\plan_page($plan);
$renderer = $PAGE->get_renderer('tool_lp');
$data = $renderable->export_for_template($renderer);
return $data;
}
|
[
"public",
"static",
"function",
"data_for_plan_page",
"(",
"$",
"planid",
")",
"{",
"global",
"$",
"PAGE",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"data_for_plan_page_parameters",
"(",
")",
",",
"array",
"(",
"'planid'",
"=>",
"$",
"planid",
")",
")",
";",
"$",
"plan",
"=",
"api",
"::",
"read_plan",
"(",
"$",
"params",
"[",
"'planid'",
"]",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"plan",
"->",
"get_context",
"(",
")",
")",
";",
"$",
"renderable",
"=",
"new",
"output",
"\\",
"plan_page",
"(",
"$",
"plan",
")",
";",
"$",
"renderer",
"=",
"$",
"PAGE",
"->",
"get_renderer",
"(",
"'tool_lp'",
")",
";",
"$",
"data",
"=",
"$",
"renderable",
"->",
"export_for_template",
"(",
"$",
"renderer",
")",
";",
"return",
"$",
"data",
";",
"}"
] |
Loads the data required to render the plan_page template.
@param int $planid Learning Plan id.
@return boolean
|
[
"Loads",
"the",
"data",
"required",
"to",
"render",
"the",
"plan_page",
"template",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lp/classes/external.php#L568-L582
|
216,572
|
moodle/moodle
|
admin/tool/lp/classes/external.php
|
external.data_for_plans_page
|
public static function data_for_plans_page($userid) {
global $PAGE;
$params = self::validate_parameters(self::data_for_plans_page_parameters(), array(
'userid' => $userid,
));
$context = context_user::instance($params['userid']);
self::validate_context($context);
$output = $PAGE->get_renderer('tool_lp');
$renderable = new \tool_lp\output\plans_page($params['userid']);
return $renderable->export_for_template($output);
}
|
php
|
public static function data_for_plans_page($userid) {
global $PAGE;
$params = self::validate_parameters(self::data_for_plans_page_parameters(), array(
'userid' => $userid,
));
$context = context_user::instance($params['userid']);
self::validate_context($context);
$output = $PAGE->get_renderer('tool_lp');
$renderable = new \tool_lp\output\plans_page($params['userid']);
return $renderable->export_for_template($output);
}
|
[
"public",
"static",
"function",
"data_for_plans_page",
"(",
"$",
"userid",
")",
"{",
"global",
"$",
"PAGE",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"data_for_plans_page_parameters",
"(",
")",
",",
"array",
"(",
"'userid'",
"=>",
"$",
"userid",
",",
")",
")",
";",
"$",
"context",
"=",
"context_user",
"::",
"instance",
"(",
"$",
"params",
"[",
"'userid'",
"]",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"$",
"output",
"=",
"$",
"PAGE",
"->",
"get_renderer",
"(",
"'tool_lp'",
")",
";",
"$",
"renderable",
"=",
"new",
"\\",
"tool_lp",
"\\",
"output",
"\\",
"plans_page",
"(",
"$",
"params",
"[",
"'userid'",
"]",
")",
";",
"return",
"$",
"renderable",
"->",
"export_for_template",
"(",
"$",
"output",
")",
";",
"}"
] |
Loads the data required to render the plans_page template.
@param int $userid User id.
@return boolean
|
[
"Loads",
"the",
"data",
"required",
"to",
"render",
"the",
"plans_page",
"template",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lp/classes/external.php#L636-L650
|
216,573
|
moodle/moodle
|
admin/tool/lp/classes/external.php
|
external.data_for_user_evidence_list_page
|
public static function data_for_user_evidence_list_page($userid) {
global $PAGE;
$params = self::validate_parameters(self::data_for_user_evidence_list_page_parameters(),
array('userid' => $userid));
$context = context_user::instance($params['userid']);
self::validate_context($context);
$output = $PAGE->get_renderer('tool_lp');
$renderable = new \tool_lp\output\user_evidence_list_page($params['userid']);
return $renderable->export_for_template($output);
}
|
php
|
public static function data_for_user_evidence_list_page($userid) {
global $PAGE;
$params = self::validate_parameters(self::data_for_user_evidence_list_page_parameters(),
array('userid' => $userid));
$context = context_user::instance($params['userid']);
self::validate_context($context);
$output = $PAGE->get_renderer('tool_lp');
$renderable = new \tool_lp\output\user_evidence_list_page($params['userid']);
return $renderable->export_for_template($output);
}
|
[
"public",
"static",
"function",
"data_for_user_evidence_list_page",
"(",
"$",
"userid",
")",
"{",
"global",
"$",
"PAGE",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"data_for_user_evidence_list_page_parameters",
"(",
")",
",",
"array",
"(",
"'userid'",
"=>",
"$",
"userid",
")",
")",
";",
"$",
"context",
"=",
"context_user",
"::",
"instance",
"(",
"$",
"params",
"[",
"'userid'",
"]",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"$",
"output",
"=",
"$",
"PAGE",
"->",
"get_renderer",
"(",
"'tool_lp'",
")",
";",
"$",
"renderable",
"=",
"new",
"\\",
"tool_lp",
"\\",
"output",
"\\",
"user_evidence_list_page",
"(",
"$",
"params",
"[",
"'userid'",
"]",
")",
";",
"return",
"$",
"renderable",
"->",
"export_for_template",
"(",
"$",
"output",
")",
";",
"}"
] |
Loads the data required to render the user_evidence_list_page template.
@param int $userid User id.
@return boolean
|
[
"Loads",
"the",
"data",
"required",
"to",
"render",
"the",
"user_evidence_list_page",
"template",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lp/classes/external.php#L689-L700
|
216,574
|
moodle/moodle
|
admin/tool/lp/classes/external.php
|
external.data_for_user_evidence_page
|
public static function data_for_user_evidence_page($id) {
global $PAGE;
$params = self::validate_parameters(self::data_for_user_evidence_page_parameters(),
array('id' => $id));
$userevidence = api::read_user_evidence($id);
self::validate_context($userevidence->get_context());
$output = $PAGE->get_renderer('tool_lp');
$renderable = new \tool_lp\output\user_evidence_page($userevidence);
return $renderable->export_for_template($output);
}
|
php
|
public static function data_for_user_evidence_page($id) {
global $PAGE;
$params = self::validate_parameters(self::data_for_user_evidence_page_parameters(),
array('id' => $id));
$userevidence = api::read_user_evidence($id);
self::validate_context($userevidence->get_context());
$output = $PAGE->get_renderer('tool_lp');
$renderable = new \tool_lp\output\user_evidence_page($userevidence);
return $renderable->export_for_template($output);
}
|
[
"public",
"static",
"function",
"data_for_user_evidence_page",
"(",
"$",
"id",
")",
"{",
"global",
"$",
"PAGE",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"data_for_user_evidence_page_parameters",
"(",
")",
",",
"array",
"(",
"'id'",
"=>",
"$",
"id",
")",
")",
";",
"$",
"userevidence",
"=",
"api",
"::",
"read_user_evidence",
"(",
"$",
"id",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"userevidence",
"->",
"get_context",
"(",
")",
")",
";",
"$",
"output",
"=",
"$",
"PAGE",
"->",
"get_renderer",
"(",
"'tool_lp'",
")",
";",
"$",
"renderable",
"=",
"new",
"\\",
"tool_lp",
"\\",
"output",
"\\",
"user_evidence_page",
"(",
"$",
"userevidence",
")",
";",
"return",
"$",
"renderable",
"->",
"export_for_template",
"(",
"$",
"output",
")",
";",
"}"
] |
Loads the data required to render the user_evidence_page template.
@param int $id User id.
@return boolean
|
[
"Loads",
"the",
"data",
"required",
"to",
"render",
"the",
"user_evidence_page",
"template",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lp/classes/external.php#L736-L747
|
216,575
|
moodle/moodle
|
admin/tool/lp/classes/external.php
|
external.data_for_related_competencies_section
|
public static function data_for_related_competencies_section($competencyid) {
global $PAGE;
$params = self::validate_parameters(self::data_for_related_competencies_section_parameters(), array(
'competencyid' => $competencyid,
));
$competency = api::read_competency($params['competencyid']);
self::validate_context($competency->get_context());
$renderable = new \tool_lp\output\related_competencies($params['competencyid']);
$renderer = $PAGE->get_renderer('tool_lp');
return $renderable->export_for_template($renderer);
}
|
php
|
public static function data_for_related_competencies_section($competencyid) {
global $PAGE;
$params = self::validate_parameters(self::data_for_related_competencies_section_parameters(), array(
'competencyid' => $competencyid,
));
$competency = api::read_competency($params['competencyid']);
self::validate_context($competency->get_context());
$renderable = new \tool_lp\output\related_competencies($params['competencyid']);
$renderer = $PAGE->get_renderer('tool_lp');
return $renderable->export_for_template($renderer);
}
|
[
"public",
"static",
"function",
"data_for_related_competencies_section",
"(",
"$",
"competencyid",
")",
"{",
"global",
"$",
"PAGE",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"data_for_related_competencies_section_parameters",
"(",
")",
",",
"array",
"(",
"'competencyid'",
"=>",
"$",
"competencyid",
",",
")",
")",
";",
"$",
"competency",
"=",
"api",
"::",
"read_competency",
"(",
"$",
"params",
"[",
"'competencyid'",
"]",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"competency",
"->",
"get_context",
"(",
")",
")",
";",
"$",
"renderable",
"=",
"new",
"\\",
"tool_lp",
"\\",
"output",
"\\",
"related_competencies",
"(",
"$",
"params",
"[",
"'competencyid'",
"]",
")",
";",
"$",
"renderer",
"=",
"$",
"PAGE",
"->",
"get_renderer",
"(",
"'tool_lp'",
")",
";",
"return",
"$",
"renderable",
"->",
"export_for_template",
"(",
"$",
"renderer",
")",
";",
"}"
] |
Data to render in the related competencies section.
@param int $competencyid
@return array Related competencies and whether to show delete action button or not.
|
[
"Data",
"to",
"render",
"in",
"the",
"related",
"competencies",
"section",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lp/classes/external.php#L781-L794
|
216,576
|
moodle/moodle
|
admin/tool/lp/classes/external.php
|
external.data_for_user_competency_summary_parameters
|
public static function data_for_user_competency_summary_parameters() {
$userid = new external_value(
PARAM_INT,
'Data base record id for the user',
VALUE_REQUIRED
);
$competencyid = new external_value(
PARAM_INT,
'Data base record id for the competency',
VALUE_REQUIRED
);
$params = array(
'userid' => $userid,
'competencyid' => $competencyid,
);
return new external_function_parameters($params);
}
|
php
|
public static function data_for_user_competency_summary_parameters() {
$userid = new external_value(
PARAM_INT,
'Data base record id for the user',
VALUE_REQUIRED
);
$competencyid = new external_value(
PARAM_INT,
'Data base record id for the competency',
VALUE_REQUIRED
);
$params = array(
'userid' => $userid,
'competencyid' => $competencyid,
);
return new external_function_parameters($params);
}
|
[
"public",
"static",
"function",
"data_for_user_competency_summary_parameters",
"(",
")",
"{",
"$",
"userid",
"=",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Data base record id for the user'",
",",
"VALUE_REQUIRED",
")",
";",
"$",
"competencyid",
"=",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Data base record id for the competency'",
",",
"VALUE_REQUIRED",
")",
";",
"$",
"params",
"=",
"array",
"(",
"'userid'",
"=>",
"$",
"userid",
",",
"'competencyid'",
"=>",
"$",
"competencyid",
",",
")",
";",
"return",
"new",
"external_function_parameters",
"(",
"$",
"params",
")",
";",
"}"
] |
Returns description of external function.
@return \external_function_parameters
|
[
"Returns",
"description",
"of",
"external",
"function",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lp/classes/external.php#L931-L947
|
216,577
|
moodle/moodle
|
admin/tool/lp/classes/external.php
|
external.data_for_user_competency_summary
|
public static function data_for_user_competency_summary($userid, $competencyid) {
global $PAGE;
$params = self::validate_parameters(self::data_for_user_competency_summary_parameters(), array(
'userid' => $userid,
'competencyid' => $competencyid,
));
$uc = api::get_user_competency($params['userid'], $params['competencyid']);
self::validate_context($uc->get_context());
$output = $PAGE->get_renderer('tool_lp');
$renderable = new \tool_lp\output\user_competency_summary($uc);
return $renderable->export_for_template($output);
}
|
php
|
public static function data_for_user_competency_summary($userid, $competencyid) {
global $PAGE;
$params = self::validate_parameters(self::data_for_user_competency_summary_parameters(), array(
'userid' => $userid,
'competencyid' => $competencyid,
));
$uc = api::get_user_competency($params['userid'], $params['competencyid']);
self::validate_context($uc->get_context());
$output = $PAGE->get_renderer('tool_lp');
$renderable = new \tool_lp\output\user_competency_summary($uc);
return $renderable->export_for_template($output);
}
|
[
"public",
"static",
"function",
"data_for_user_competency_summary",
"(",
"$",
"userid",
",",
"$",
"competencyid",
")",
"{",
"global",
"$",
"PAGE",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"data_for_user_competency_summary_parameters",
"(",
")",
",",
"array",
"(",
"'userid'",
"=>",
"$",
"userid",
",",
"'competencyid'",
"=>",
"$",
"competencyid",
",",
")",
")",
";",
"$",
"uc",
"=",
"api",
"::",
"get_user_competency",
"(",
"$",
"params",
"[",
"'userid'",
"]",
",",
"$",
"params",
"[",
"'competencyid'",
"]",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"uc",
"->",
"get_context",
"(",
")",
")",
";",
"$",
"output",
"=",
"$",
"PAGE",
"->",
"get_renderer",
"(",
"'tool_lp'",
")",
";",
"$",
"renderable",
"=",
"new",
"\\",
"tool_lp",
"\\",
"output",
"\\",
"user_competency_summary",
"(",
"$",
"uc",
")",
";",
"return",
"$",
"renderable",
"->",
"export_for_template",
"(",
"$",
"output",
")",
";",
"}"
] |
Data for user competency summary.
@param int $userid The user ID
@param int $competencyid The competency ID
@return \stdClass
|
[
"Data",
"for",
"user",
"competency",
"summary",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lp/classes/external.php#L956-L969
|
216,578
|
moodle/moodle
|
lib/classes/event/manager.php
|
manager.dispatch
|
public static function dispatch(\core\event\base $event) {
if (during_initial_install()) {
return;
}
if (!$event->is_triggered() or $event->is_dispatched()) {
throw new \coding_exception('Illegal event dispatching attempted.');
}
self::$buffer[] = $event;
if (self::$dispatching) {
return;
}
self::$dispatching = true;
self::process_buffers();
self::$dispatching = false;
}
|
php
|
public static function dispatch(\core\event\base $event) {
if (during_initial_install()) {
return;
}
if (!$event->is_triggered() or $event->is_dispatched()) {
throw new \coding_exception('Illegal event dispatching attempted.');
}
self::$buffer[] = $event;
if (self::$dispatching) {
return;
}
self::$dispatching = true;
self::process_buffers();
self::$dispatching = false;
}
|
[
"public",
"static",
"function",
"dispatch",
"(",
"\\",
"core",
"\\",
"event",
"\\",
"base",
"$",
"event",
")",
"{",
"if",
"(",
"during_initial_install",
"(",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"$",
"event",
"->",
"is_triggered",
"(",
")",
"or",
"$",
"event",
"->",
"is_dispatched",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Illegal event dispatching attempted.'",
")",
";",
"}",
"self",
"::",
"$",
"buffer",
"[",
"]",
"=",
"$",
"event",
";",
"if",
"(",
"self",
"::",
"$",
"dispatching",
")",
"{",
"return",
";",
"}",
"self",
"::",
"$",
"dispatching",
"=",
"true",
";",
"self",
"::",
"process_buffers",
"(",
")",
";",
"self",
"::",
"$",
"dispatching",
"=",
"false",
";",
"}"
] |
Trigger new event.
@internal to be used only from \core\event\base::trigger() method.
@param \core\event\base $event
@throws \coding_Exception if used directly.
|
[
"Trigger",
"new",
"event",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/event/manager.php#L60-L77
|
216,579
|
moodle/moodle
|
lib/classes/event/manager.php
|
manager.database_transaction_commited
|
public static function database_transaction_commited() {
if (self::$dispatching or empty(self::$extbuffer)) {
return;
}
self::$dispatching = true;
self::process_buffers();
self::$dispatching = false;
}
|
php
|
public static function database_transaction_commited() {
if (self::$dispatching or empty(self::$extbuffer)) {
return;
}
self::$dispatching = true;
self::process_buffers();
self::$dispatching = false;
}
|
[
"public",
"static",
"function",
"database_transaction_commited",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"dispatching",
"or",
"empty",
"(",
"self",
"::",
"$",
"extbuffer",
")",
")",
"{",
"return",
";",
"}",
"self",
"::",
"$",
"dispatching",
"=",
"true",
";",
"self",
"::",
"process_buffers",
"(",
")",
";",
"self",
"::",
"$",
"dispatching",
"=",
"false",
";",
"}"
] |
Notification from DML layer.
@internal to be used from DML layer only.
|
[
"Notification",
"from",
"DML",
"layer",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/event/manager.php#L83-L91
|
216,580
|
moodle/moodle
|
lib/classes/event/manager.php
|
manager.get_observing_classes
|
protected static function get_observing_classes(\core\event\base $event) {
$classname = get_class($event);
$observers = array('\\'.$classname);
while ($classname = get_parent_class($classname)) {
$observers[] = '\\'.$classname;
}
$observers = array_reverse($observers, false);
return $observers;
}
|
php
|
protected static function get_observing_classes(\core\event\base $event) {
$classname = get_class($event);
$observers = array('\\'.$classname);
while ($classname = get_parent_class($classname)) {
$observers[] = '\\'.$classname;
}
$observers = array_reverse($observers, false);
return $observers;
}
|
[
"protected",
"static",
"function",
"get_observing_classes",
"(",
"\\",
"core",
"\\",
"event",
"\\",
"base",
"$",
"event",
")",
"{",
"$",
"classname",
"=",
"get_class",
"(",
"$",
"event",
")",
";",
"$",
"observers",
"=",
"array",
"(",
"'\\\\'",
".",
"$",
"classname",
")",
";",
"while",
"(",
"$",
"classname",
"=",
"get_parent_class",
"(",
"$",
"classname",
")",
")",
"{",
"$",
"observers",
"[",
"]",
"=",
"'\\\\'",
".",
"$",
"classname",
";",
"}",
"$",
"observers",
"=",
"array_reverse",
"(",
"$",
"observers",
",",
"false",
")",
";",
"return",
"$",
"observers",
";",
"}"
] |
Returns list of classes related to this event.
@param \core\event\base $event
@return array
|
[
"Returns",
"list",
"of",
"classes",
"related",
"to",
"this",
"event",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/event/manager.php#L178-L187
|
216,581
|
moodle/moodle
|
lib/classes/event/manager.php
|
manager.init_all_observers
|
protected static function init_all_observers() {
global $CFG;
if (is_array(self::$allobservers)) {
return;
}
if (!PHPUNIT_TEST and !during_initial_install()) {
$cache = \cache::make('core', 'observers');
$cached = $cache->get('all');
$dirroot = $cache->get('dirroot');
if ($dirroot === $CFG->dirroot and is_array($cached)) {
self::$allobservers = $cached;
return;
}
}
self::$allobservers = array();
$plugintypes = \core_component::get_plugin_types();
$plugintypes = array_merge(array('core' => 'not used'), $plugintypes);
$systemdone = false;
foreach ($plugintypes as $plugintype => $ignored) {
if ($plugintype === 'core') {
$plugins['core'] = "$CFG->dirroot/lib";
} else {
$plugins = \core_component::get_plugin_list($plugintype);
}
foreach ($plugins as $plugin => $fulldir) {
if (!file_exists("$fulldir/db/events.php")) {
continue;
}
$observers = null;
include("$fulldir/db/events.php");
if (!is_array($observers)) {
continue;
}
self::add_observers($observers, "$fulldir/db/events.php", $plugintype, $plugin);
}
}
self::order_all_observers();
if (!PHPUNIT_TEST and !during_initial_install()) {
$cache->set('all', self::$allobservers);
$cache->set('dirroot', $CFG->dirroot);
}
}
|
php
|
protected static function init_all_observers() {
global $CFG;
if (is_array(self::$allobservers)) {
return;
}
if (!PHPUNIT_TEST and !during_initial_install()) {
$cache = \cache::make('core', 'observers');
$cached = $cache->get('all');
$dirroot = $cache->get('dirroot');
if ($dirroot === $CFG->dirroot and is_array($cached)) {
self::$allobservers = $cached;
return;
}
}
self::$allobservers = array();
$plugintypes = \core_component::get_plugin_types();
$plugintypes = array_merge(array('core' => 'not used'), $plugintypes);
$systemdone = false;
foreach ($plugintypes as $plugintype => $ignored) {
if ($plugintype === 'core') {
$plugins['core'] = "$CFG->dirroot/lib";
} else {
$plugins = \core_component::get_plugin_list($plugintype);
}
foreach ($plugins as $plugin => $fulldir) {
if (!file_exists("$fulldir/db/events.php")) {
continue;
}
$observers = null;
include("$fulldir/db/events.php");
if (!is_array($observers)) {
continue;
}
self::add_observers($observers, "$fulldir/db/events.php", $plugintype, $plugin);
}
}
self::order_all_observers();
if (!PHPUNIT_TEST and !during_initial_install()) {
$cache->set('all', self::$allobservers);
$cache->set('dirroot', $CFG->dirroot);
}
}
|
[
"protected",
"static",
"function",
"init_all_observers",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"if",
"(",
"is_array",
"(",
"self",
"::",
"$",
"allobservers",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"PHPUNIT_TEST",
"and",
"!",
"during_initial_install",
"(",
")",
")",
"{",
"$",
"cache",
"=",
"\\",
"cache",
"::",
"make",
"(",
"'core'",
",",
"'observers'",
")",
";",
"$",
"cached",
"=",
"$",
"cache",
"->",
"get",
"(",
"'all'",
")",
";",
"$",
"dirroot",
"=",
"$",
"cache",
"->",
"get",
"(",
"'dirroot'",
")",
";",
"if",
"(",
"$",
"dirroot",
"===",
"$",
"CFG",
"->",
"dirroot",
"and",
"is_array",
"(",
"$",
"cached",
")",
")",
"{",
"self",
"::",
"$",
"allobservers",
"=",
"$",
"cached",
";",
"return",
";",
"}",
"}",
"self",
"::",
"$",
"allobservers",
"=",
"array",
"(",
")",
";",
"$",
"plugintypes",
"=",
"\\",
"core_component",
"::",
"get_plugin_types",
"(",
")",
";",
"$",
"plugintypes",
"=",
"array_merge",
"(",
"array",
"(",
"'core'",
"=>",
"'not used'",
")",
",",
"$",
"plugintypes",
")",
";",
"$",
"systemdone",
"=",
"false",
";",
"foreach",
"(",
"$",
"plugintypes",
"as",
"$",
"plugintype",
"=>",
"$",
"ignored",
")",
"{",
"if",
"(",
"$",
"plugintype",
"===",
"'core'",
")",
"{",
"$",
"plugins",
"[",
"'core'",
"]",
"=",
"\"$CFG->dirroot/lib\"",
";",
"}",
"else",
"{",
"$",
"plugins",
"=",
"\\",
"core_component",
"::",
"get_plugin_list",
"(",
"$",
"plugintype",
")",
";",
"}",
"foreach",
"(",
"$",
"plugins",
"as",
"$",
"plugin",
"=>",
"$",
"fulldir",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"\"$fulldir/db/events.php\"",
")",
")",
"{",
"continue",
";",
"}",
"$",
"observers",
"=",
"null",
";",
"include",
"(",
"\"$fulldir/db/events.php\"",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"observers",
")",
")",
"{",
"continue",
";",
"}",
"self",
"::",
"add_observers",
"(",
"$",
"observers",
",",
"\"$fulldir/db/events.php\"",
",",
"$",
"plugintype",
",",
"$",
"plugin",
")",
";",
"}",
"}",
"self",
"::",
"order_all_observers",
"(",
")",
";",
"if",
"(",
"!",
"PHPUNIT_TEST",
"and",
"!",
"during_initial_install",
"(",
")",
")",
"{",
"$",
"cache",
"->",
"set",
"(",
"'all'",
",",
"self",
"::",
"$",
"allobservers",
")",
";",
"$",
"cache",
"->",
"set",
"(",
"'dirroot'",
",",
"$",
"CFG",
"->",
"dirroot",
")",
";",
"}",
"}"
] |
Initialise the list of observers.
|
[
"Initialise",
"the",
"list",
"of",
"observers",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/event/manager.php#L192-L240
|
216,582
|
moodle/moodle
|
lib/classes/event/manager.php
|
manager.add_observers
|
protected static function add_observers(array $observers, $file, $plugintype = null, $plugin = null) {
global $CFG;
foreach ($observers as $observer) {
if (empty($observer['eventname']) or !is_string($observer['eventname'])) {
debugging("Invalid 'eventname' detected in $file observer definition", DEBUG_DEVELOPER);
continue;
}
if ($observer['eventname'] === '*') {
$observer['eventname'] = '\core\event\base';
}
if (strpos($observer['eventname'], '\\') !== 0) {
$observer['eventname'] = '\\'.$observer['eventname'];
}
if (empty($observer['callback'])) {
debugging("Invalid 'callback' detected in $file observer definition", DEBUG_DEVELOPER);
continue;
}
$o = new \stdClass();
$o->callable = $observer['callback'];
if (!isset($observer['priority'])) {
$o->priority = 0;
} else {
$o->priority = (int)$observer['priority'];
}
if (!isset($observer['internal'])) {
$o->internal = true;
} else {
$o->internal = (bool)$observer['internal'];
}
if (empty($observer['includefile'])) {
$o->includefile = null;
} else {
if ($CFG->admin !== 'admin' and strpos($observer['includefile'], '/admin/') === 0) {
$observer['includefile'] = preg_replace('|^/admin/|', '/'.$CFG->admin.'/', $observer['includefile']);
}
$observer['includefile'] = $CFG->dirroot . '/' . ltrim($observer['includefile'], '/');
if (!file_exists($observer['includefile'])) {
debugging("Invalid 'includefile' detected in $file observer definition", DEBUG_DEVELOPER);
continue;
}
$o->includefile = $observer['includefile'];
}
$o->plugintype = $plugintype;
$o->plugin = $plugin;
self::$allobservers[$observer['eventname']][] = $o;
}
}
|
php
|
protected static function add_observers(array $observers, $file, $plugintype = null, $plugin = null) {
global $CFG;
foreach ($observers as $observer) {
if (empty($observer['eventname']) or !is_string($observer['eventname'])) {
debugging("Invalid 'eventname' detected in $file observer definition", DEBUG_DEVELOPER);
continue;
}
if ($observer['eventname'] === '*') {
$observer['eventname'] = '\core\event\base';
}
if (strpos($observer['eventname'], '\\') !== 0) {
$observer['eventname'] = '\\'.$observer['eventname'];
}
if (empty($observer['callback'])) {
debugging("Invalid 'callback' detected in $file observer definition", DEBUG_DEVELOPER);
continue;
}
$o = new \stdClass();
$o->callable = $observer['callback'];
if (!isset($observer['priority'])) {
$o->priority = 0;
} else {
$o->priority = (int)$observer['priority'];
}
if (!isset($observer['internal'])) {
$o->internal = true;
} else {
$o->internal = (bool)$observer['internal'];
}
if (empty($observer['includefile'])) {
$o->includefile = null;
} else {
if ($CFG->admin !== 'admin' and strpos($observer['includefile'], '/admin/') === 0) {
$observer['includefile'] = preg_replace('|^/admin/|', '/'.$CFG->admin.'/', $observer['includefile']);
}
$observer['includefile'] = $CFG->dirroot . '/' . ltrim($observer['includefile'], '/');
if (!file_exists($observer['includefile'])) {
debugging("Invalid 'includefile' detected in $file observer definition", DEBUG_DEVELOPER);
continue;
}
$o->includefile = $observer['includefile'];
}
$o->plugintype = $plugintype;
$o->plugin = $plugin;
self::$allobservers[$observer['eventname']][] = $o;
}
}
|
[
"protected",
"static",
"function",
"add_observers",
"(",
"array",
"$",
"observers",
",",
"$",
"file",
",",
"$",
"plugintype",
"=",
"null",
",",
"$",
"plugin",
"=",
"null",
")",
"{",
"global",
"$",
"CFG",
";",
"foreach",
"(",
"$",
"observers",
"as",
"$",
"observer",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"observer",
"[",
"'eventname'",
"]",
")",
"or",
"!",
"is_string",
"(",
"$",
"observer",
"[",
"'eventname'",
"]",
")",
")",
"{",
"debugging",
"(",
"\"Invalid 'eventname' detected in $file observer definition\"",
",",
"DEBUG_DEVELOPER",
")",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"observer",
"[",
"'eventname'",
"]",
"===",
"'*'",
")",
"{",
"$",
"observer",
"[",
"'eventname'",
"]",
"=",
"'\\core\\event\\base'",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"observer",
"[",
"'eventname'",
"]",
",",
"'\\\\'",
")",
"!==",
"0",
")",
"{",
"$",
"observer",
"[",
"'eventname'",
"]",
"=",
"'\\\\'",
".",
"$",
"observer",
"[",
"'eventname'",
"]",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"observer",
"[",
"'callback'",
"]",
")",
")",
"{",
"debugging",
"(",
"\"Invalid 'callback' detected in $file observer definition\"",
",",
"DEBUG_DEVELOPER",
")",
";",
"continue",
";",
"}",
"$",
"o",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"o",
"->",
"callable",
"=",
"$",
"observer",
"[",
"'callback'",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"observer",
"[",
"'priority'",
"]",
")",
")",
"{",
"$",
"o",
"->",
"priority",
"=",
"0",
";",
"}",
"else",
"{",
"$",
"o",
"->",
"priority",
"=",
"(",
"int",
")",
"$",
"observer",
"[",
"'priority'",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"observer",
"[",
"'internal'",
"]",
")",
")",
"{",
"$",
"o",
"->",
"internal",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"o",
"->",
"internal",
"=",
"(",
"bool",
")",
"$",
"observer",
"[",
"'internal'",
"]",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"observer",
"[",
"'includefile'",
"]",
")",
")",
"{",
"$",
"o",
"->",
"includefile",
"=",
"null",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"CFG",
"->",
"admin",
"!==",
"'admin'",
"and",
"strpos",
"(",
"$",
"observer",
"[",
"'includefile'",
"]",
",",
"'/admin/'",
")",
"===",
"0",
")",
"{",
"$",
"observer",
"[",
"'includefile'",
"]",
"=",
"preg_replace",
"(",
"'|^/admin/|'",
",",
"'/'",
".",
"$",
"CFG",
"->",
"admin",
".",
"'/'",
",",
"$",
"observer",
"[",
"'includefile'",
"]",
")",
";",
"}",
"$",
"observer",
"[",
"'includefile'",
"]",
"=",
"$",
"CFG",
"->",
"dirroot",
".",
"'/'",
".",
"ltrim",
"(",
"$",
"observer",
"[",
"'includefile'",
"]",
",",
"'/'",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"observer",
"[",
"'includefile'",
"]",
")",
")",
"{",
"debugging",
"(",
"\"Invalid 'includefile' detected in $file observer definition\"",
",",
"DEBUG_DEVELOPER",
")",
";",
"continue",
";",
"}",
"$",
"o",
"->",
"includefile",
"=",
"$",
"observer",
"[",
"'includefile'",
"]",
";",
"}",
"$",
"o",
"->",
"plugintype",
"=",
"$",
"plugintype",
";",
"$",
"o",
"->",
"plugin",
"=",
"$",
"plugin",
";",
"self",
"::",
"$",
"allobservers",
"[",
"$",
"observer",
"[",
"'eventname'",
"]",
"]",
"[",
"]",
"=",
"$",
"o",
";",
"}",
"}"
] |
Add observers.
@param array $observers
@param string $file
@param string $plugintype Plugin type of the observer.
@param string $plugin Plugin of the observer.
|
[
"Add",
"observers",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/event/manager.php#L249-L296
|
216,583
|
moodle/moodle
|
lib/classes/event/manager.php
|
manager.order_all_observers
|
protected static function order_all_observers() {
foreach (self::$allobservers as $classname => $observers) {
\core_collator::asort_objects_by_property($observers, 'priority', \core_collator::SORT_NUMERIC);
self::$allobservers[$classname] = array_reverse($observers);
}
}
|
php
|
protected static function order_all_observers() {
foreach (self::$allobservers as $classname => $observers) {
\core_collator::asort_objects_by_property($observers, 'priority', \core_collator::SORT_NUMERIC);
self::$allobservers[$classname] = array_reverse($observers);
}
}
|
[
"protected",
"static",
"function",
"order_all_observers",
"(",
")",
"{",
"foreach",
"(",
"self",
"::",
"$",
"allobservers",
"as",
"$",
"classname",
"=>",
"$",
"observers",
")",
"{",
"\\",
"core_collator",
"::",
"asort_objects_by_property",
"(",
"$",
"observers",
",",
"'priority'",
",",
"\\",
"core_collator",
"::",
"SORT_NUMERIC",
")",
";",
"self",
"::",
"$",
"allobservers",
"[",
"$",
"classname",
"]",
"=",
"array_reverse",
"(",
"$",
"observers",
")",
";",
"}",
"}"
] |
Reorder observers to allow quick lookup of observer for each event.
|
[
"Reorder",
"observers",
"to",
"allow",
"quick",
"lookup",
"of",
"observer",
"for",
"each",
"event",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/event/manager.php#L301-L306
|
216,584
|
moodle/moodle
|
repository/boxnet/lib.php
|
repository_boxnet.build_breadcrumb
|
protected function build_breadcrumb($fullpath) {
$breadcrumb = array(array(
'name' => get_string('pluginname', 'repository_boxnet'),
'path' => ''
));
$breadcrumbpath = '';
$crumbs = explode('/', $fullpath);
foreach ($crumbs as $crumb) {
if (empty($crumb)) {
// That is probably the root crumb, we've already added it.
continue;
}
list($unused, $tosplit) = explode(':', $crumb, 2);
if (strpos($tosplit, '|') !== false) {
list($id, $crumbname) = explode('|', $tosplit, 2);
} else {
$crumbname = $tosplit;
}
$breadcrumbpath .= '/' . $crumb;
$breadcrumb[] = array(
'name' => urldecode($crumbname),
'path' => $breadcrumbpath
);
}
return $breadcrumb;
}
|
php
|
protected function build_breadcrumb($fullpath) {
$breadcrumb = array(array(
'name' => get_string('pluginname', 'repository_boxnet'),
'path' => ''
));
$breadcrumbpath = '';
$crumbs = explode('/', $fullpath);
foreach ($crumbs as $crumb) {
if (empty($crumb)) {
// That is probably the root crumb, we've already added it.
continue;
}
list($unused, $tosplit) = explode(':', $crumb, 2);
if (strpos($tosplit, '|') !== false) {
list($id, $crumbname) = explode('|', $tosplit, 2);
} else {
$crumbname = $tosplit;
}
$breadcrumbpath .= '/' . $crumb;
$breadcrumb[] = array(
'name' => urldecode($crumbname),
'path' => $breadcrumbpath
);
}
return $breadcrumb;
}
|
[
"protected",
"function",
"build_breadcrumb",
"(",
"$",
"fullpath",
")",
"{",
"$",
"breadcrumb",
"=",
"array",
"(",
"array",
"(",
"'name'",
"=>",
"get_string",
"(",
"'pluginname'",
",",
"'repository_boxnet'",
")",
",",
"'path'",
"=>",
"''",
")",
")",
";",
"$",
"breadcrumbpath",
"=",
"''",
";",
"$",
"crumbs",
"=",
"explode",
"(",
"'/'",
",",
"$",
"fullpath",
")",
";",
"foreach",
"(",
"$",
"crumbs",
"as",
"$",
"crumb",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"crumb",
")",
")",
"{",
"// That is probably the root crumb, we've already added it.",
"continue",
";",
"}",
"list",
"(",
"$",
"unused",
",",
"$",
"tosplit",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"crumb",
",",
"2",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"tosplit",
",",
"'|'",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"id",
",",
"$",
"crumbname",
")",
"=",
"explode",
"(",
"'|'",
",",
"$",
"tosplit",
",",
"2",
")",
";",
"}",
"else",
"{",
"$",
"crumbname",
"=",
"$",
"tosplit",
";",
"}",
"$",
"breadcrumbpath",
".=",
"'/'",
".",
"$",
"crumb",
";",
"$",
"breadcrumb",
"[",
"]",
"=",
"array",
"(",
"'name'",
"=>",
"urldecode",
"(",
"$",
"crumbname",
")",
",",
"'path'",
"=>",
"$",
"breadcrumbpath",
")",
";",
"}",
"return",
"$",
"breadcrumb",
";",
"}"
] |
Construct a breadcrumb from a path.
@param string $fullpath Path containing multiple parts separated by slashes.
@return array Array expected to be generated in {@link self::get_listing()}.
|
[
"Construct",
"a",
"breadcrumb",
"from",
"a",
"path",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/boxnet/lib.php#L82-L107
|
216,585
|
moodle/moodle
|
repository/boxnet/lib.php
|
repository_boxnet.build_part
|
protected function build_part($type, $value, $name = '') {
$return = $type . ':' . urlencode($value);
if ($name !== '') {
$return .= '|' . urlencode($name);
}
return $return;
}
|
php
|
protected function build_part($type, $value, $name = '') {
$return = $type . ':' . urlencode($value);
if ($name !== '') {
$return .= '|' . urlencode($name);
}
return $return;
}
|
[
"protected",
"function",
"build_part",
"(",
"$",
"type",
",",
"$",
"value",
",",
"$",
"name",
"=",
"''",
")",
"{",
"$",
"return",
"=",
"$",
"type",
".",
"':'",
".",
"urlencode",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"name",
"!==",
"''",
")",
"{",
"$",
"return",
".=",
"'|'",
".",
"urlencode",
"(",
"$",
"name",
")",
";",
"}",
"return",
"$",
"return",
";",
"}"
] |
Build a part of the path.
This is used to construct the path that the user is currently browsing.
It must contain a 'type', and a 'value'. Then it can also contain a
'name' which is very useful to prevent extra queries to get the name only.
See {@link self::split_part} to extra the information from a part.
@param string $type Type of part, typically 'folder' or 'search'.
@param string $value The value of the part, eg. a folder ID or search terms.
@param string $name The name of the part.
@return string type:value or type:value|name
|
[
"Build",
"a",
"part",
"of",
"the",
"path",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/boxnet/lib.php#L123-L129
|
216,586
|
moodle/moodle
|
repository/boxnet/lib.php
|
repository_boxnet.split_part
|
protected function split_part($part) {
list($type, $tosplit) = explode(':', $part);
$name = '';
if (strpos($tosplit, '|') !== false) {
list($value, $name) = explode('|', $tosplit, 2);
} else {
$value = $tosplit;
}
return array($type, urldecode($value), urldecode($name));
}
|
php
|
protected function split_part($part) {
list($type, $tosplit) = explode(':', $part);
$name = '';
if (strpos($tosplit, '|') !== false) {
list($value, $name) = explode('|', $tosplit, 2);
} else {
$value = $tosplit;
}
return array($type, urldecode($value), urldecode($name));
}
|
[
"protected",
"function",
"split_part",
"(",
"$",
"part",
")",
"{",
"list",
"(",
"$",
"type",
",",
"$",
"tosplit",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"part",
")",
";",
"$",
"name",
"=",
"''",
";",
"if",
"(",
"strpos",
"(",
"$",
"tosplit",
",",
"'|'",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"value",
",",
"$",
"name",
")",
"=",
"explode",
"(",
"'|'",
",",
"$",
"tosplit",
",",
"2",
")",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"tosplit",
";",
"}",
"return",
"array",
"(",
"$",
"type",
",",
"urldecode",
"(",
"$",
"value",
")",
",",
"urldecode",
"(",
"$",
"name",
")",
")",
";",
"}"
] |
Extract information from a part of path.
@param string $part value generated from {@link self::build_parth()}.
@return array containing type, value and name.
|
[
"Extract",
"information",
"from",
"a",
"part",
"of",
"path",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/boxnet/lib.php#L137-L146
|
216,587
|
moodle/moodle
|
repository/boxnet/lib.php
|
repository_boxnet.print_login
|
public function print_login(){
$url = $this->boxnetclient->get_login_url();
if ($this->options['ajax']) {
$ret = array();
$popup_btn = new stdClass();
$popup_btn->type = 'popup';
$popup_btn->url = $url->out(false);
$ret['login'] = array($popup_btn);
return $ret;
} else {
echo html_writer::link($url, get_string('login', 'repository'), array('target' => '_blank'));
}
}
|
php
|
public function print_login(){
$url = $this->boxnetclient->get_login_url();
if ($this->options['ajax']) {
$ret = array();
$popup_btn = new stdClass();
$popup_btn->type = 'popup';
$popup_btn->url = $url->out(false);
$ret['login'] = array($popup_btn);
return $ret;
} else {
echo html_writer::link($url, get_string('login', 'repository'), array('target' => '_blank'));
}
}
|
[
"public",
"function",
"print_login",
"(",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"boxnetclient",
"->",
"get_login_url",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"options",
"[",
"'ajax'",
"]",
")",
"{",
"$",
"ret",
"=",
"array",
"(",
")",
";",
"$",
"popup_btn",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"popup_btn",
"->",
"type",
"=",
"'popup'",
";",
"$",
"popup_btn",
"->",
"url",
"=",
"$",
"url",
"->",
"out",
"(",
"false",
")",
";",
"$",
"ret",
"[",
"'login'",
"]",
"=",
"array",
"(",
"$",
"popup_btn",
")",
";",
"return",
"$",
"ret",
";",
"}",
"else",
"{",
"echo",
"html_writer",
"::",
"link",
"(",
"$",
"url",
",",
"get_string",
"(",
"'login'",
",",
"'repository'",
")",
",",
"array",
"(",
"'target'",
"=>",
"'_blank'",
")",
")",
";",
"}",
"}"
] |
Return login form
@return array
|
[
"Return",
"login",
"form"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/boxnet/lib.php#L281-L293
|
216,588
|
moodle/moodle
|
repository/boxnet/lib.php
|
repository_boxnet.get_link
|
public function get_link($reference) {
$reference = unserialize(self::convert_to_valid_reference($reference));
$shareinfo = $this->boxnetclient->share_file($reference->fileid, false);
return $shareinfo->url;
}
|
php
|
public function get_link($reference) {
$reference = unserialize(self::convert_to_valid_reference($reference));
$shareinfo = $this->boxnetclient->share_file($reference->fileid, false);
return $shareinfo->url;
}
|
[
"public",
"function",
"get_link",
"(",
"$",
"reference",
")",
"{",
"$",
"reference",
"=",
"unserialize",
"(",
"self",
"::",
"convert_to_valid_reference",
"(",
"$",
"reference",
")",
")",
";",
"$",
"shareinfo",
"=",
"$",
"this",
"->",
"boxnetclient",
"->",
"share_file",
"(",
"$",
"reference",
"->",
"fileid",
",",
"false",
")",
";",
"return",
"$",
"shareinfo",
"->",
"url",
";",
"}"
] |
Get a link to the file.
This returns the URL of the web view of the file. To generate this link the
file must be shared.
@param stdClass $reference Reference.
@return string URL.
|
[
"Get",
"a",
"link",
"to",
"the",
"file",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/boxnet/lib.php#L407-L411
|
216,589
|
moodle/moodle
|
repository/boxnet/lib.php
|
repository_boxnet.sync_reference
|
public function sync_reference(stored_file $file) {
global $CFG;
if ($file->get_referencelastsync() + DAYSECS > time()) {
// Synchronise not more often than once a day.
return false;
}
$c = new curl();
$reference = unserialize(self::convert_to_valid_reference($file->get_reference()));
$url = $reference->downloadurl;
if (file_extension_in_typegroup($file->get_filename(), 'web_image')) {
$path = $this->prepare_file('');
$result = $c->download_one($url, null, array('filepath' => $path, 'timeout' => $CFG->repositorysyncimagetimeout));
$info = $c->get_info();
if ($result === true && isset($info['http_code']) && $info['http_code'] == 200) {
$file->set_synchronised_content_from_file($path);
return true;
}
}
$c->get($url, null, array('timeout' => $CFG->repositorysyncimagetimeout, 'followlocation' => true, 'nobody' => true));
$info = $c->get_info();
if (isset($info['http_code']) && $info['http_code'] == 200 &&
array_key_exists('download_content_length', $info) &&
$info['download_content_length'] >= 0) {
$filesize = (int)$info['download_content_length'];
$file->set_synchronized(null, $filesize);
return true;
}
$file->set_missingsource();
return true;
}
|
php
|
public function sync_reference(stored_file $file) {
global $CFG;
if ($file->get_referencelastsync() + DAYSECS > time()) {
// Synchronise not more often than once a day.
return false;
}
$c = new curl();
$reference = unserialize(self::convert_to_valid_reference($file->get_reference()));
$url = $reference->downloadurl;
if (file_extension_in_typegroup($file->get_filename(), 'web_image')) {
$path = $this->prepare_file('');
$result = $c->download_one($url, null, array('filepath' => $path, 'timeout' => $CFG->repositorysyncimagetimeout));
$info = $c->get_info();
if ($result === true && isset($info['http_code']) && $info['http_code'] == 200) {
$file->set_synchronised_content_from_file($path);
return true;
}
}
$c->get($url, null, array('timeout' => $CFG->repositorysyncimagetimeout, 'followlocation' => true, 'nobody' => true));
$info = $c->get_info();
if (isset($info['http_code']) && $info['http_code'] == 200 &&
array_key_exists('download_content_length', $info) &&
$info['download_content_length'] >= 0) {
$filesize = (int)$info['download_content_length'];
$file->set_synchronized(null, $filesize);
return true;
}
$file->set_missingsource();
return true;
}
|
[
"public",
"function",
"sync_reference",
"(",
"stored_file",
"$",
"file",
")",
"{",
"global",
"$",
"CFG",
";",
"if",
"(",
"$",
"file",
"->",
"get_referencelastsync",
"(",
")",
"+",
"DAYSECS",
">",
"time",
"(",
")",
")",
"{",
"// Synchronise not more often than once a day.",
"return",
"false",
";",
"}",
"$",
"c",
"=",
"new",
"curl",
"(",
")",
";",
"$",
"reference",
"=",
"unserialize",
"(",
"self",
"::",
"convert_to_valid_reference",
"(",
"$",
"file",
"->",
"get_reference",
"(",
")",
")",
")",
";",
"$",
"url",
"=",
"$",
"reference",
"->",
"downloadurl",
";",
"if",
"(",
"file_extension_in_typegroup",
"(",
"$",
"file",
"->",
"get_filename",
"(",
")",
",",
"'web_image'",
")",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"prepare_file",
"(",
"''",
")",
";",
"$",
"result",
"=",
"$",
"c",
"->",
"download_one",
"(",
"$",
"url",
",",
"null",
",",
"array",
"(",
"'filepath'",
"=>",
"$",
"path",
",",
"'timeout'",
"=>",
"$",
"CFG",
"->",
"repositorysyncimagetimeout",
")",
")",
";",
"$",
"info",
"=",
"$",
"c",
"->",
"get_info",
"(",
")",
";",
"if",
"(",
"$",
"result",
"===",
"true",
"&&",
"isset",
"(",
"$",
"info",
"[",
"'http_code'",
"]",
")",
"&&",
"$",
"info",
"[",
"'http_code'",
"]",
"==",
"200",
")",
"{",
"$",
"file",
"->",
"set_synchronised_content_from_file",
"(",
"$",
"path",
")",
";",
"return",
"true",
";",
"}",
"}",
"$",
"c",
"->",
"get",
"(",
"$",
"url",
",",
"null",
",",
"array",
"(",
"'timeout'",
"=>",
"$",
"CFG",
"->",
"repositorysyncimagetimeout",
",",
"'followlocation'",
"=>",
"true",
",",
"'nobody'",
"=>",
"true",
")",
")",
";",
"$",
"info",
"=",
"$",
"c",
"->",
"get_info",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"info",
"[",
"'http_code'",
"]",
")",
"&&",
"$",
"info",
"[",
"'http_code'",
"]",
"==",
"200",
"&&",
"array_key_exists",
"(",
"'download_content_length'",
",",
"$",
"info",
")",
"&&",
"$",
"info",
"[",
"'download_content_length'",
"]",
">=",
"0",
")",
"{",
"$",
"filesize",
"=",
"(",
"int",
")",
"$",
"info",
"[",
"'download_content_length'",
"]",
";",
"$",
"file",
"->",
"set_synchronized",
"(",
"null",
",",
"$",
"filesize",
")",
";",
"return",
"true",
";",
"}",
"$",
"file",
"->",
"set_missingsource",
"(",
")",
";",
"return",
"true",
";",
"}"
] |
Synchronize the references.
@param stored_file $file Stored file.
@return boolean
|
[
"Synchronize",
"the",
"references",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/boxnet/lib.php#L419-L448
|
216,590
|
moodle/moodle
|
repository/boxnet/lib.php
|
repository_boxnet.get_file_source_info
|
public function get_file_source_info($source) {
global $USER;
list($type, $fileid, $filename) = $this->split_part($source);
return 'Box ('. fullname($USER) . '): ' . $filename;
}
|
php
|
public function get_file_source_info($source) {
global $USER;
list($type, $fileid, $filename) = $this->split_part($source);
return 'Box ('. fullname($USER) . '): ' . $filename;
}
|
[
"public",
"function",
"get_file_source_info",
"(",
"$",
"source",
")",
"{",
"global",
"$",
"USER",
";",
"list",
"(",
"$",
"type",
",",
"$",
"fileid",
",",
"$",
"filename",
")",
"=",
"$",
"this",
"->",
"split_part",
"(",
"$",
"source",
")",
";",
"return",
"'Box ('",
".",
"fullname",
"(",
"$",
"USER",
")",
".",
"'): '",
".",
"$",
"filename",
";",
"}"
] |
Return the source information.
@param string $source Not the reference, just the source.
@return string|null
|
[
"Return",
"the",
"source",
"information",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/boxnet/lib.php#L474-L478
|
216,591
|
moodle/moodle
|
analytics/classes/model.php
|
model.is_available
|
public function is_available() {
$target = $this->get_target();
if (!$target) {
return false;
}
$classname = $target->get_analyser_class();
if (!class_exists($classname)) {
return false;
}
return true;
}
|
php
|
public function is_available() {
$target = $this->get_target();
if (!$target) {
return false;
}
$classname = $target->get_analyser_class();
if (!class_exists($classname)) {
return false;
}
return true;
}
|
[
"public",
"function",
"is_available",
"(",
")",
"{",
"$",
"target",
"=",
"$",
"this",
"->",
"get_target",
"(",
")",
";",
"if",
"(",
"!",
"$",
"target",
")",
"{",
"return",
"false",
";",
"}",
"$",
"classname",
"=",
"$",
"target",
"->",
"get_analyser_class",
"(",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"classname",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Quick safety check to discard site models which required components are not available anymore.
@return bool
|
[
"Quick",
"safety",
"check",
"to",
"discard",
"site",
"models",
"which",
"required",
"components",
"are",
"not",
"available",
"anymore",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L153-L165
|
216,592
|
moodle/moodle
|
analytics/classes/model.php
|
model.get_target
|
public function get_target() {
if ($this->target !== null) {
return $this->target;
}
$instance = \core_analytics\manager::get_target($this->model->target);
$this->target = $instance;
return $this->target;
}
|
php
|
public function get_target() {
if ($this->target !== null) {
return $this->target;
}
$instance = \core_analytics\manager::get_target($this->model->target);
$this->target = $instance;
return $this->target;
}
|
[
"public",
"function",
"get_target",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"target",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"target",
";",
"}",
"$",
"instance",
"=",
"\\",
"core_analytics",
"\\",
"manager",
"::",
"get_target",
"(",
"$",
"this",
"->",
"model",
"->",
"target",
")",
";",
"$",
"this",
"->",
"target",
"=",
"$",
"instance",
";",
"return",
"$",
"this",
"->",
"target",
";",
"}"
] |
Returns the model target.
@return \core_analytics\local\target\base
|
[
"Returns",
"the",
"model",
"target",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L190-L198
|
216,593
|
moodle/moodle
|
analytics/classes/model.php
|
model.get_indicators
|
public function get_indicators() {
if ($this->indicators !== null) {
return $this->indicators;
}
$fullclassnames = json_decode($this->model->indicators);
if (!is_array($fullclassnames)) {
throw new \coding_exception('Model ' . $this->model->id . ' indicators can not be read');
}
$this->indicators = array();
foreach ($fullclassnames as $fullclassname) {
$instance = \core_analytics\manager::get_indicator($fullclassname);
if ($instance) {
$this->indicators[$fullclassname] = $instance;
} else {
debugging('Can\'t load ' . $fullclassname . ' indicator', DEBUG_DEVELOPER);
}
}
return $this->indicators;
}
|
php
|
public function get_indicators() {
if ($this->indicators !== null) {
return $this->indicators;
}
$fullclassnames = json_decode($this->model->indicators);
if (!is_array($fullclassnames)) {
throw new \coding_exception('Model ' . $this->model->id . ' indicators can not be read');
}
$this->indicators = array();
foreach ($fullclassnames as $fullclassname) {
$instance = \core_analytics\manager::get_indicator($fullclassname);
if ($instance) {
$this->indicators[$fullclassname] = $instance;
} else {
debugging('Can\'t load ' . $fullclassname . ' indicator', DEBUG_DEVELOPER);
}
}
return $this->indicators;
}
|
[
"public",
"function",
"get_indicators",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"indicators",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"indicators",
";",
"}",
"$",
"fullclassnames",
"=",
"json_decode",
"(",
"$",
"this",
"->",
"model",
"->",
"indicators",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"fullclassnames",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Model '",
".",
"$",
"this",
"->",
"model",
"->",
"id",
".",
"' indicators can not be read'",
")",
";",
"}",
"$",
"this",
"->",
"indicators",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"fullclassnames",
"as",
"$",
"fullclassname",
")",
"{",
"$",
"instance",
"=",
"\\",
"core_analytics",
"\\",
"manager",
"::",
"get_indicator",
"(",
"$",
"fullclassname",
")",
";",
"if",
"(",
"$",
"instance",
")",
"{",
"$",
"this",
"->",
"indicators",
"[",
"$",
"fullclassname",
"]",
"=",
"$",
"instance",
";",
"}",
"else",
"{",
"debugging",
"(",
"'Can\\'t load '",
".",
"$",
"fullclassname",
".",
"' indicator'",
",",
"DEBUG_DEVELOPER",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"indicators",
";",
"}"
] |
Returns the model indicators.
@return \core_analytics\local\indicator\base[]
|
[
"Returns",
"the",
"model",
"indicators",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L205-L227
|
216,594
|
moodle/moodle
|
analytics/classes/model.php
|
model.get_potential_indicators
|
public function get_potential_indicators() {
$indicators = \core_analytics\manager::get_all_indicators();
if (empty($this->analyser)) {
$this->init_analyser(array('evaluation' => true));
}
foreach ($indicators as $classname => $indicator) {
if ($this->analyser->check_indicator_requirements($indicator) !== true) {
unset($indicators[$classname]);
}
}
return $indicators;
}
|
php
|
public function get_potential_indicators() {
$indicators = \core_analytics\manager::get_all_indicators();
if (empty($this->analyser)) {
$this->init_analyser(array('evaluation' => true));
}
foreach ($indicators as $classname => $indicator) {
if ($this->analyser->check_indicator_requirements($indicator) !== true) {
unset($indicators[$classname]);
}
}
return $indicators;
}
|
[
"public",
"function",
"get_potential_indicators",
"(",
")",
"{",
"$",
"indicators",
"=",
"\\",
"core_analytics",
"\\",
"manager",
"::",
"get_all_indicators",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"analyser",
")",
")",
"{",
"$",
"this",
"->",
"init_analyser",
"(",
"array",
"(",
"'evaluation'",
"=>",
"true",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"indicators",
"as",
"$",
"classname",
"=>",
"$",
"indicator",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"analyser",
"->",
"check_indicator_requirements",
"(",
"$",
"indicator",
")",
"!==",
"true",
")",
"{",
"unset",
"(",
"$",
"indicators",
"[",
"$",
"classname",
"]",
")",
";",
"}",
"}",
"return",
"$",
"indicators",
";",
"}"
] |
Returns the list of indicators that could potentially be used by the model target.
It includes the indicators that are part of the model.
@return \core_analytics\local\indicator\base[]
|
[
"Returns",
"the",
"list",
"of",
"indicators",
"that",
"could",
"potentially",
"be",
"used",
"by",
"the",
"model",
"target",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L236-L250
|
216,595
|
moodle/moodle
|
analytics/classes/model.php
|
model.init_analyser
|
protected function init_analyser($options = array()) {
$target = $this->get_target();
$indicators = $this->get_indicators();
if (empty($target)) {
throw new \moodle_exception('errornotarget', 'analytics');
}
$timesplittings = array();
if (empty($options['notimesplitting'])) {
if (!empty($options['evaluation'])) {
// The evaluation process will run using all available time splitting methods unless one is specified.
if (!empty($options['timesplitting'])) {
$timesplitting = \core_analytics\manager::get_time_splitting($options['timesplitting']);
$timesplittings = array($timesplitting->get_id() => $timesplitting);
} else {
$timesplittings = \core_analytics\manager::get_time_splitting_methods_for_evaluation();
}
} else {
if (empty($this->model->timesplitting)) {
throw new \moodle_exception('invalidtimesplitting', 'analytics', '', $this->model->id);
}
// Returned as an array as all actions (evaluation, training and prediction) go through the same process.
$timesplittings = array($this->model->timesplitting => $this->get_time_splitting());
}
if (empty($timesplittings)) {
throw new \moodle_exception('errornotimesplittings', 'analytics');
}
}
$classname = $target->get_analyser_class();
if (!class_exists($classname)) {
throw new \coding_exception($classname . ' class does not exists');
}
// Returns a \core_analytics\local\analyser\base class.
$this->analyser = new $classname($this->model->id, $target, $indicators, $timesplittings, $options);
}
|
php
|
protected function init_analyser($options = array()) {
$target = $this->get_target();
$indicators = $this->get_indicators();
if (empty($target)) {
throw new \moodle_exception('errornotarget', 'analytics');
}
$timesplittings = array();
if (empty($options['notimesplitting'])) {
if (!empty($options['evaluation'])) {
// The evaluation process will run using all available time splitting methods unless one is specified.
if (!empty($options['timesplitting'])) {
$timesplitting = \core_analytics\manager::get_time_splitting($options['timesplitting']);
$timesplittings = array($timesplitting->get_id() => $timesplitting);
} else {
$timesplittings = \core_analytics\manager::get_time_splitting_methods_for_evaluation();
}
} else {
if (empty($this->model->timesplitting)) {
throw new \moodle_exception('invalidtimesplitting', 'analytics', '', $this->model->id);
}
// Returned as an array as all actions (evaluation, training and prediction) go through the same process.
$timesplittings = array($this->model->timesplitting => $this->get_time_splitting());
}
if (empty($timesplittings)) {
throw new \moodle_exception('errornotimesplittings', 'analytics');
}
}
$classname = $target->get_analyser_class();
if (!class_exists($classname)) {
throw new \coding_exception($classname . ' class does not exists');
}
// Returns a \core_analytics\local\analyser\base class.
$this->analyser = new $classname($this->model->id, $target, $indicators, $timesplittings, $options);
}
|
[
"protected",
"function",
"init_analyser",
"(",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"$",
"target",
"=",
"$",
"this",
"->",
"get_target",
"(",
")",
";",
"$",
"indicators",
"=",
"$",
"this",
"->",
"get_indicators",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"target",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'errornotarget'",
",",
"'analytics'",
")",
";",
"}",
"$",
"timesplittings",
"=",
"array",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'notimesplitting'",
"]",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'evaluation'",
"]",
")",
")",
"{",
"// The evaluation process will run using all available time splitting methods unless one is specified.",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'timesplitting'",
"]",
")",
")",
"{",
"$",
"timesplitting",
"=",
"\\",
"core_analytics",
"\\",
"manager",
"::",
"get_time_splitting",
"(",
"$",
"options",
"[",
"'timesplitting'",
"]",
")",
";",
"$",
"timesplittings",
"=",
"array",
"(",
"$",
"timesplitting",
"->",
"get_id",
"(",
")",
"=>",
"$",
"timesplitting",
")",
";",
"}",
"else",
"{",
"$",
"timesplittings",
"=",
"\\",
"core_analytics",
"\\",
"manager",
"::",
"get_time_splitting_methods_for_evaluation",
"(",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"model",
"->",
"timesplitting",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'invalidtimesplitting'",
",",
"'analytics'",
",",
"''",
",",
"$",
"this",
"->",
"model",
"->",
"id",
")",
";",
"}",
"// Returned as an array as all actions (evaluation, training and prediction) go through the same process.",
"$",
"timesplittings",
"=",
"array",
"(",
"$",
"this",
"->",
"model",
"->",
"timesplitting",
"=>",
"$",
"this",
"->",
"get_time_splitting",
"(",
")",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"timesplittings",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'errornotimesplittings'",
",",
"'analytics'",
")",
";",
"}",
"}",
"$",
"classname",
"=",
"$",
"target",
"->",
"get_analyser_class",
"(",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"classname",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"$",
"classname",
".",
"' class does not exists'",
")",
";",
"}",
"// Returns a \\core_analytics\\local\\analyser\\base class.",
"$",
"this",
"->",
"analyser",
"=",
"new",
"$",
"classname",
"(",
"$",
"this",
"->",
"model",
"->",
"id",
",",
"$",
"target",
",",
"$",
"indicators",
",",
"$",
"timesplittings",
",",
"$",
"options",
")",
";",
"}"
] |
Initialises the model analyser.
@throws \coding_exception
@param array $options
@return void
|
[
"Initialises",
"the",
"model",
"analyser",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L275-L316
|
216,596
|
moodle/moodle
|
analytics/classes/model.php
|
model.get_time_splitting
|
public function get_time_splitting() {
if (empty($this->model->timesplitting)) {
return false;
}
return \core_analytics\manager::get_time_splitting($this->model->timesplitting);
}
|
php
|
public function get_time_splitting() {
if (empty($this->model->timesplitting)) {
return false;
}
return \core_analytics\manager::get_time_splitting($this->model->timesplitting);
}
|
[
"public",
"function",
"get_time_splitting",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"model",
"->",
"timesplitting",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"\\",
"core_analytics",
"\\",
"manager",
"::",
"get_time_splitting",
"(",
"$",
"this",
"->",
"model",
"->",
"timesplitting",
")",
";",
"}"
] |
Returns the model time splitting method.
@return \core_analytics\local\time_splitting\base|false Returns false if no time splitting.
|
[
"Returns",
"the",
"model",
"time",
"splitting",
"method",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L323-L328
|
216,597
|
moodle/moodle
|
analytics/classes/model.php
|
model.exists
|
public static function exists(\core_analytics\local\target\base $target, $indicators = false) {
global $DB;
$existingmodels = $DB->get_records('analytics_models', array('target' => $target->get_id()));
if (!$existingmodels) {
return false;
}
if (!$indicators && $existingmodels) {
return true;
}
$indicatorids = array_keys($indicators);
sort($indicatorids);
foreach ($existingmodels as $modelobj) {
$model = new \core_analytics\model($modelobj);
$modelindicatorids = array_keys($model->get_indicators());
sort($modelindicatorids);
if ($indicatorids === $modelindicatorids) {
return true;
}
}
return false;
}
|
php
|
public static function exists(\core_analytics\local\target\base $target, $indicators = false) {
global $DB;
$existingmodels = $DB->get_records('analytics_models', array('target' => $target->get_id()));
if (!$existingmodels) {
return false;
}
if (!$indicators && $existingmodels) {
return true;
}
$indicatorids = array_keys($indicators);
sort($indicatorids);
foreach ($existingmodels as $modelobj) {
$model = new \core_analytics\model($modelobj);
$modelindicatorids = array_keys($model->get_indicators());
sort($modelindicatorids);
if ($indicatorids === $modelindicatorids) {
return true;
}
}
return false;
}
|
[
"public",
"static",
"function",
"exists",
"(",
"\\",
"core_analytics",
"\\",
"local",
"\\",
"target",
"\\",
"base",
"$",
"target",
",",
"$",
"indicators",
"=",
"false",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"existingmodels",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'analytics_models'",
",",
"array",
"(",
"'target'",
"=>",
"$",
"target",
"->",
"get_id",
"(",
")",
")",
")",
";",
"if",
"(",
"!",
"$",
"existingmodels",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"indicators",
"&&",
"$",
"existingmodels",
")",
"{",
"return",
"true",
";",
"}",
"$",
"indicatorids",
"=",
"array_keys",
"(",
"$",
"indicators",
")",
";",
"sort",
"(",
"$",
"indicatorids",
")",
";",
"foreach",
"(",
"$",
"existingmodels",
"as",
"$",
"modelobj",
")",
"{",
"$",
"model",
"=",
"new",
"\\",
"core_analytics",
"\\",
"model",
"(",
"$",
"modelobj",
")",
";",
"$",
"modelindicatorids",
"=",
"array_keys",
"(",
"$",
"model",
"->",
"get_indicators",
"(",
")",
")",
";",
"sort",
"(",
"$",
"modelindicatorids",
")",
";",
"if",
"(",
"$",
"indicatorids",
"===",
"$",
"modelindicatorids",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Does this model exist?
If no indicators are provided it considers any model with the provided
target a match.
@param \core_analytics\local\target\base $target
@param \core_analytics\local\indicator\base[]|false $indicators
@return bool
|
[
"Does",
"this",
"model",
"exist?"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L397-L423
|
216,598
|
moodle/moodle
|
analytics/classes/model.php
|
model.delete
|
public function delete() {
global $DB;
\core_analytics\manager::check_can_manage_models();
$this->clear();
// Method self::clear is already clearing the current model version.
$predictor = $this->get_predictions_processor(false);
if ($predictor->is_ready() !== true) {
$predictorname = \core_analytics\manager::get_predictions_processor_name($predictor);
debugging('Prediction processor ' . $predictorname . ' is not ready to be used. Model ' .
$this->model->id . ' could not be deleted.');
} else {
$predictor->delete_output_dir($this->get_output_dir(array(), true));
}
$DB->delete_records('analytics_models', array('id' => $this->model->id));
$DB->delete_records('analytics_models_log', array('modelid' => $this->model->id));
}
|
php
|
public function delete() {
global $DB;
\core_analytics\manager::check_can_manage_models();
$this->clear();
// Method self::clear is already clearing the current model version.
$predictor = $this->get_predictions_processor(false);
if ($predictor->is_ready() !== true) {
$predictorname = \core_analytics\manager::get_predictions_processor_name($predictor);
debugging('Prediction processor ' . $predictorname . ' is not ready to be used. Model ' .
$this->model->id . ' could not be deleted.');
} else {
$predictor->delete_output_dir($this->get_output_dir(array(), true));
}
$DB->delete_records('analytics_models', array('id' => $this->model->id));
$DB->delete_records('analytics_models_log', array('modelid' => $this->model->id));
}
|
[
"public",
"function",
"delete",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"\\",
"core_analytics",
"\\",
"manager",
"::",
"check_can_manage_models",
"(",
")",
";",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"// Method self::clear is already clearing the current model version.",
"$",
"predictor",
"=",
"$",
"this",
"->",
"get_predictions_processor",
"(",
"false",
")",
";",
"if",
"(",
"$",
"predictor",
"->",
"is_ready",
"(",
")",
"!==",
"true",
")",
"{",
"$",
"predictorname",
"=",
"\\",
"core_analytics",
"\\",
"manager",
"::",
"get_predictions_processor_name",
"(",
"$",
"predictor",
")",
";",
"debugging",
"(",
"'Prediction processor '",
".",
"$",
"predictorname",
".",
"' is not ready to be used. Model '",
".",
"$",
"this",
"->",
"model",
"->",
"id",
".",
"' could not be deleted.'",
")",
";",
"}",
"else",
"{",
"$",
"predictor",
"->",
"delete_output_dir",
"(",
"$",
"this",
"->",
"get_output_dir",
"(",
"array",
"(",
")",
",",
"true",
")",
")",
";",
"}",
"$",
"DB",
"->",
"delete_records",
"(",
"'analytics_models'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"model",
"->",
"id",
")",
")",
";",
"$",
"DB",
"->",
"delete_records",
"(",
"'analytics_models_log'",
",",
"array",
"(",
"'modelid'",
"=>",
"$",
"this",
"->",
"model",
"->",
"id",
")",
")",
";",
"}"
] |
Removes the model.
@return void
|
[
"Removes",
"the",
"model",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L498-L517
|
216,599
|
moodle/moodle
|
analytics/classes/model.php
|
model.train
|
public function train() {
\core_analytics\manager::check_can_manage_models();
if ($this->is_static()) {
$this->get_analyser()->add_log(get_string('notrainingbasedassumptions', 'analytics'));
$result = new \stdClass();
$result->status = self::OK;
return $result;
}
if (!$this->is_enabled() || empty($this->model->timesplitting)) {
throw new \moodle_exception('invalidtimesplitting', 'analytics', '', $this->model->id);
}
if (empty($this->get_indicators())) {
throw new \moodle_exception('errornoindicators', 'analytics');
}
$this->heavy_duty_mode();
// Before get_labelled_data call so we get an early exception if it is not writable.
$outputdir = $this->get_output_dir(array('execution'));
// Before get_labelled_data call so we get an early exception if it is not ready.
$predictor = $this->get_predictions_processor();
$datasets = $this->get_analyser()->get_labelled_data();
// No training if no files have been provided.
if (empty($datasets) || empty($datasets[$this->model->timesplitting])) {
$result = new \stdClass();
$result->status = self::NO_DATASET;
$result->info = $this->get_analyser()->get_logs();
return $result;
}
$samplesfile = $datasets[$this->model->timesplitting];
// Train using the dataset.
if ($this->get_target()->is_linear()) {
$predictorresult = $predictor->train_regression($this->get_unique_id(), $samplesfile, $outputdir);
} else {
$predictorresult = $predictor->train_classification($this->get_unique_id(), $samplesfile, $outputdir);
}
$result = new \stdClass();
$result->status = $predictorresult->status;
$result->info = $predictorresult->info;
if ($result->status !== self::OK) {
return $result;
}
$this->flag_file_as_used($samplesfile, 'trained');
// Mark the model as trained if it wasn't.
if ($this->model->trained == false) {
$this->mark_as_trained();
}
return $result;
}
|
php
|
public function train() {
\core_analytics\manager::check_can_manage_models();
if ($this->is_static()) {
$this->get_analyser()->add_log(get_string('notrainingbasedassumptions', 'analytics'));
$result = new \stdClass();
$result->status = self::OK;
return $result;
}
if (!$this->is_enabled() || empty($this->model->timesplitting)) {
throw new \moodle_exception('invalidtimesplitting', 'analytics', '', $this->model->id);
}
if (empty($this->get_indicators())) {
throw new \moodle_exception('errornoindicators', 'analytics');
}
$this->heavy_duty_mode();
// Before get_labelled_data call so we get an early exception if it is not writable.
$outputdir = $this->get_output_dir(array('execution'));
// Before get_labelled_data call so we get an early exception if it is not ready.
$predictor = $this->get_predictions_processor();
$datasets = $this->get_analyser()->get_labelled_data();
// No training if no files have been provided.
if (empty($datasets) || empty($datasets[$this->model->timesplitting])) {
$result = new \stdClass();
$result->status = self::NO_DATASET;
$result->info = $this->get_analyser()->get_logs();
return $result;
}
$samplesfile = $datasets[$this->model->timesplitting];
// Train using the dataset.
if ($this->get_target()->is_linear()) {
$predictorresult = $predictor->train_regression($this->get_unique_id(), $samplesfile, $outputdir);
} else {
$predictorresult = $predictor->train_classification($this->get_unique_id(), $samplesfile, $outputdir);
}
$result = new \stdClass();
$result->status = $predictorresult->status;
$result->info = $predictorresult->info;
if ($result->status !== self::OK) {
return $result;
}
$this->flag_file_as_used($samplesfile, 'trained');
// Mark the model as trained if it wasn't.
if ($this->model->trained == false) {
$this->mark_as_trained();
}
return $result;
}
|
[
"public",
"function",
"train",
"(",
")",
"{",
"\\",
"core_analytics",
"\\",
"manager",
"::",
"check_can_manage_models",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"is_static",
"(",
")",
")",
"{",
"$",
"this",
"->",
"get_analyser",
"(",
")",
"->",
"add_log",
"(",
"get_string",
"(",
"'notrainingbasedassumptions'",
",",
"'analytics'",
")",
")",
";",
"$",
"result",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"result",
"->",
"status",
"=",
"self",
"::",
"OK",
";",
"return",
"$",
"result",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"is_enabled",
"(",
")",
"||",
"empty",
"(",
"$",
"this",
"->",
"model",
"->",
"timesplitting",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'invalidtimesplitting'",
",",
"'analytics'",
",",
"''",
",",
"$",
"this",
"->",
"model",
"->",
"id",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"get_indicators",
"(",
")",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'errornoindicators'",
",",
"'analytics'",
")",
";",
"}",
"$",
"this",
"->",
"heavy_duty_mode",
"(",
")",
";",
"// Before get_labelled_data call so we get an early exception if it is not writable.",
"$",
"outputdir",
"=",
"$",
"this",
"->",
"get_output_dir",
"(",
"array",
"(",
"'execution'",
")",
")",
";",
"// Before get_labelled_data call so we get an early exception if it is not ready.",
"$",
"predictor",
"=",
"$",
"this",
"->",
"get_predictions_processor",
"(",
")",
";",
"$",
"datasets",
"=",
"$",
"this",
"->",
"get_analyser",
"(",
")",
"->",
"get_labelled_data",
"(",
")",
";",
"// No training if no files have been provided.",
"if",
"(",
"empty",
"(",
"$",
"datasets",
")",
"||",
"empty",
"(",
"$",
"datasets",
"[",
"$",
"this",
"->",
"model",
"->",
"timesplitting",
"]",
")",
")",
"{",
"$",
"result",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"result",
"->",
"status",
"=",
"self",
"::",
"NO_DATASET",
";",
"$",
"result",
"->",
"info",
"=",
"$",
"this",
"->",
"get_analyser",
"(",
")",
"->",
"get_logs",
"(",
")",
";",
"return",
"$",
"result",
";",
"}",
"$",
"samplesfile",
"=",
"$",
"datasets",
"[",
"$",
"this",
"->",
"model",
"->",
"timesplitting",
"]",
";",
"// Train using the dataset.",
"if",
"(",
"$",
"this",
"->",
"get_target",
"(",
")",
"->",
"is_linear",
"(",
")",
")",
"{",
"$",
"predictorresult",
"=",
"$",
"predictor",
"->",
"train_regression",
"(",
"$",
"this",
"->",
"get_unique_id",
"(",
")",
",",
"$",
"samplesfile",
",",
"$",
"outputdir",
")",
";",
"}",
"else",
"{",
"$",
"predictorresult",
"=",
"$",
"predictor",
"->",
"train_classification",
"(",
"$",
"this",
"->",
"get_unique_id",
"(",
")",
",",
"$",
"samplesfile",
",",
"$",
"outputdir",
")",
";",
"}",
"$",
"result",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"result",
"->",
"status",
"=",
"$",
"predictorresult",
"->",
"status",
";",
"$",
"result",
"->",
"info",
"=",
"$",
"predictorresult",
"->",
"info",
";",
"if",
"(",
"$",
"result",
"->",
"status",
"!==",
"self",
"::",
"OK",
")",
"{",
"return",
"$",
"result",
";",
"}",
"$",
"this",
"->",
"flag_file_as_used",
"(",
"$",
"samplesfile",
",",
"'trained'",
")",
";",
"// Mark the model as trained if it wasn't.",
"if",
"(",
"$",
"this",
"->",
"model",
"->",
"trained",
"==",
"false",
")",
"{",
"$",
"this",
"->",
"mark_as_trained",
"(",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Trains the model using the site contents.
This method prepares a dataset from the site contents (through the analyser)
and passes it to the machine learning backends. Static models are skipped as
they do not require training.
@return \stdClass
|
[
"Trains",
"the",
"model",
"using",
"the",
"site",
"contents",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/model.php#L641-L703
|
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.