id
int32 0
241k
| repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
|
|---|---|---|---|---|---|---|---|---|---|---|---|
219,100
|
moodle/moodle
|
admin/renderer.php
|
core_admin_renderer.upgrade_confirm_abort_install_page
|
public function upgrade_confirm_abort_install_page(array $abortable, moodle_url $continue) {
$pluginman = core_plugin_manager::instance();
if (empty($abortable)) {
// The UI should not allow this.
throw new moodle_exception('err_no_plugin_install_abortable', 'core_plugin');
}
$out = $this->output->header();
$out .= $this->output->heading(get_string('cancelinstallhead', 'core_plugin'), 3);
$out .= $this->output->container(get_string('cancelinstallinfo', 'core_plugin'), 'cancelinstallinfo');
foreach ($abortable as $pluginfo) {
$out .= $this->output->heading($pluginfo->displayname.' ('.$pluginfo->component.')', 4);
$out .= $this->output->container(get_string('cancelinstallinfodir', 'core_plugin', $pluginfo->rootdir));
if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) {
$out .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
'uninstalldeleteconfirmexternal');
}
}
$out .= $this->plugins_management_confirm_buttons($continue, $this->page->url);
$out .= $this->output->footer();
return $out;
}
|
php
|
public function upgrade_confirm_abort_install_page(array $abortable, moodle_url $continue) {
$pluginman = core_plugin_manager::instance();
if (empty($abortable)) {
// The UI should not allow this.
throw new moodle_exception('err_no_plugin_install_abortable', 'core_plugin');
}
$out = $this->output->header();
$out .= $this->output->heading(get_string('cancelinstallhead', 'core_plugin'), 3);
$out .= $this->output->container(get_string('cancelinstallinfo', 'core_plugin'), 'cancelinstallinfo');
foreach ($abortable as $pluginfo) {
$out .= $this->output->heading($pluginfo->displayname.' ('.$pluginfo->component.')', 4);
$out .= $this->output->container(get_string('cancelinstallinfodir', 'core_plugin', $pluginfo->rootdir));
if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) {
$out .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
'uninstalldeleteconfirmexternal');
}
}
$out .= $this->plugins_management_confirm_buttons($continue, $this->page->url);
$out .= $this->output->footer();
return $out;
}
|
[
"public",
"function",
"upgrade_confirm_abort_install_page",
"(",
"array",
"$",
"abortable",
",",
"moodle_url",
"$",
"continue",
")",
"{",
"$",
"pluginman",
"=",
"core_plugin_manager",
"::",
"instance",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"abortable",
")",
")",
"{",
"// The UI should not allow this.",
"throw",
"new",
"moodle_exception",
"(",
"'err_no_plugin_install_abortable'",
",",
"'core_plugin'",
")",
";",
"}",
"$",
"out",
"=",
"$",
"this",
"->",
"output",
"->",
"header",
"(",
")",
";",
"$",
"out",
".=",
"$",
"this",
"->",
"output",
"->",
"heading",
"(",
"get_string",
"(",
"'cancelinstallhead'",
",",
"'core_plugin'",
")",
",",
"3",
")",
";",
"$",
"out",
".=",
"$",
"this",
"->",
"output",
"->",
"container",
"(",
"get_string",
"(",
"'cancelinstallinfo'",
",",
"'core_plugin'",
")",
",",
"'cancelinstallinfo'",
")",
";",
"foreach",
"(",
"$",
"abortable",
"as",
"$",
"pluginfo",
")",
"{",
"$",
"out",
".=",
"$",
"this",
"->",
"output",
"->",
"heading",
"(",
"$",
"pluginfo",
"->",
"displayname",
".",
"' ('",
".",
"$",
"pluginfo",
"->",
"component",
".",
"')'",
",",
"4",
")",
";",
"$",
"out",
".=",
"$",
"this",
"->",
"output",
"->",
"container",
"(",
"get_string",
"(",
"'cancelinstallinfodir'",
",",
"'core_plugin'",
",",
"$",
"pluginfo",
"->",
"rootdir",
")",
")",
";",
"if",
"(",
"$",
"repotype",
"=",
"$",
"pluginman",
"->",
"plugin_external_source",
"(",
"$",
"pluginfo",
"->",
"component",
")",
")",
"{",
"$",
"out",
".=",
"$",
"this",
"->",
"output",
"->",
"container",
"(",
"get_string",
"(",
"'uninstalldeleteconfirmexternal'",
",",
"'core_plugin'",
",",
"$",
"repotype",
")",
",",
"'uninstalldeleteconfirmexternal'",
")",
";",
"}",
"}",
"$",
"out",
".=",
"$",
"this",
"->",
"plugins_management_confirm_buttons",
"(",
"$",
"continue",
",",
"$",
"this",
"->",
"page",
"->",
"url",
")",
";",
"$",
"out",
".=",
"$",
"this",
"->",
"output",
"->",
"footer",
"(",
")",
";",
"return",
"$",
"out",
";",
"}"
] |
Display a page to confirm plugin installation cancelation.
@param array $abortable list of \core\update\plugininfo
@param moodle_url $continue
@return string
|
[
"Display",
"a",
"page",
"to",
"confirm",
"plugin",
"installation",
"cancelation",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/renderer.php#L238-L264
|
219,101
|
moodle/moodle
|
admin/renderer.php
|
core_admin_renderer.check_for_updates_button
|
public function check_for_updates_button(\core\update\checker $checker, $reloadurl) {
$output = '';
if ($checker->enabled()) {
$output .= $this->container_start('checkforupdates');
$output .= $this->single_button(
new moodle_url($reloadurl, array('fetchupdates' => 1)),
get_string('checkforupdates', 'core_plugin')
);
if ($timefetched = $checker->get_last_timefetched()) {
$timefetched = userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'));
$output .= $this->container(get_string('checkforupdateslast', 'core_plugin', $timefetched), 'lasttimefetched');
}
$output .= $this->container_end();
}
return $output;
}
|
php
|
public function check_for_updates_button(\core\update\checker $checker, $reloadurl) {
$output = '';
if ($checker->enabled()) {
$output .= $this->container_start('checkforupdates');
$output .= $this->single_button(
new moodle_url($reloadurl, array('fetchupdates' => 1)),
get_string('checkforupdates', 'core_plugin')
);
if ($timefetched = $checker->get_last_timefetched()) {
$timefetched = userdate($timefetched, get_string('strftimedatetime', 'core_langconfig'));
$output .= $this->container(get_string('checkforupdateslast', 'core_plugin', $timefetched), 'lasttimefetched');
}
$output .= $this->container_end();
}
return $output;
}
|
[
"public",
"function",
"check_for_updates_button",
"(",
"\\",
"core",
"\\",
"update",
"\\",
"checker",
"$",
"checker",
",",
"$",
"reloadurl",
")",
"{",
"$",
"output",
"=",
"''",
";",
"if",
"(",
"$",
"checker",
"->",
"enabled",
"(",
")",
")",
"{",
"$",
"output",
".=",
"$",
"this",
"->",
"container_start",
"(",
"'checkforupdates'",
")",
";",
"$",
"output",
".=",
"$",
"this",
"->",
"single_button",
"(",
"new",
"moodle_url",
"(",
"$",
"reloadurl",
",",
"array",
"(",
"'fetchupdates'",
"=>",
"1",
")",
")",
",",
"get_string",
"(",
"'checkforupdates'",
",",
"'core_plugin'",
")",
")",
";",
"if",
"(",
"$",
"timefetched",
"=",
"$",
"checker",
"->",
"get_last_timefetched",
"(",
")",
")",
"{",
"$",
"timefetched",
"=",
"userdate",
"(",
"$",
"timefetched",
",",
"get_string",
"(",
"'strftimedatetime'",
",",
"'core_langconfig'",
")",
")",
";",
"$",
"output",
".=",
"$",
"this",
"->",
"container",
"(",
"get_string",
"(",
"'checkforupdateslast'",
",",
"'core_plugin'",
",",
"$",
"timefetched",
")",
",",
"'lasttimefetched'",
")",
";",
"}",
"$",
"output",
".=",
"$",
"this",
"->",
"container_end",
"(",
")",
";",
"}",
"return",
"$",
"output",
";",
"}"
] |
Renders a button to fetch for available updates.
@param \core\update\checker $checker
@param moodle_url $reloadurl
@return string HTML
|
[
"Renders",
"a",
"button",
"to",
"fetch",
"for",
"available",
"updates",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/renderer.php#L359-L377
|
219,102
|
moodle/moodle
|
admin/renderer.php
|
core_admin_renderer.plugin_uninstall_confirm_page
|
public function plugin_uninstall_confirm_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, moodle_url $continueurl, moodle_url $cancelurl) {
$output = '';
$pluginname = $pluginman->plugin_name($pluginfo->component);
$confirm = '<p>' . get_string('uninstallconfirm', 'core_plugin', array('name' => $pluginname)) . '</p>';
if ($extraconfirm = $pluginfo->get_uninstall_extra_warning()) {
$confirm .= $extraconfirm;
}
$output .= $this->output->header();
$output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
$output .= $this->output->confirm($confirm, $continueurl, $cancelurl);
$output .= $this->output->footer();
return $output;
}
|
php
|
public function plugin_uninstall_confirm_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, moodle_url $continueurl, moodle_url $cancelurl) {
$output = '';
$pluginname = $pluginman->plugin_name($pluginfo->component);
$confirm = '<p>' . get_string('uninstallconfirm', 'core_plugin', array('name' => $pluginname)) . '</p>';
if ($extraconfirm = $pluginfo->get_uninstall_extra_warning()) {
$confirm .= $extraconfirm;
}
$output .= $this->output->header();
$output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
$output .= $this->output->confirm($confirm, $continueurl, $cancelurl);
$output .= $this->output->footer();
return $output;
}
|
[
"public",
"function",
"plugin_uninstall_confirm_page",
"(",
"core_plugin_manager",
"$",
"pluginman",
",",
"\\",
"core",
"\\",
"plugininfo",
"\\",
"base",
"$",
"pluginfo",
",",
"moodle_url",
"$",
"continueurl",
",",
"moodle_url",
"$",
"cancelurl",
")",
"{",
"$",
"output",
"=",
"''",
";",
"$",
"pluginname",
"=",
"$",
"pluginman",
"->",
"plugin_name",
"(",
"$",
"pluginfo",
"->",
"component",
")",
";",
"$",
"confirm",
"=",
"'<p>'",
".",
"get_string",
"(",
"'uninstallconfirm'",
",",
"'core_plugin'",
",",
"array",
"(",
"'name'",
"=>",
"$",
"pluginname",
")",
")",
".",
"'</p>'",
";",
"if",
"(",
"$",
"extraconfirm",
"=",
"$",
"pluginfo",
"->",
"get_uninstall_extra_warning",
"(",
")",
")",
"{",
"$",
"confirm",
".=",
"$",
"extraconfirm",
";",
"}",
"$",
"output",
".=",
"$",
"this",
"->",
"output",
"->",
"header",
"(",
")",
";",
"$",
"output",
".=",
"$",
"this",
"->",
"output",
"->",
"heading",
"(",
"get_string",
"(",
"'uninstalling'",
",",
"'core_plugin'",
",",
"array",
"(",
"'name'",
"=>",
"$",
"pluginname",
")",
")",
")",
";",
"$",
"output",
".=",
"$",
"this",
"->",
"output",
"->",
"confirm",
"(",
"$",
"confirm",
",",
"$",
"continueurl",
",",
"$",
"cancelurl",
")",
";",
"$",
"output",
".=",
"$",
"this",
"->",
"output",
"->",
"footer",
"(",
")",
";",
"return",
"$",
"output",
";",
"}"
] |
Display a page to confirm the plugin uninstallation.
@param core_plugin_manager $pluginman
@param \core\plugininfo\base $pluginfo
@param moodle_url $continueurl URL to continue after confirmation
@param moodle_url $cancelurl URL to to go if cancelled
@return string
|
[
"Display",
"a",
"page",
"to",
"confirm",
"the",
"plugin",
"uninstallation",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/renderer.php#L388-L404
|
219,103
|
moodle/moodle
|
admin/renderer.php
|
core_admin_renderer.plugin_uninstall_results_removable_page
|
public function plugin_uninstall_results_removable_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo,
progress_trace_buffer $progress, moodle_url $continueurl) {
$output = '';
$pluginname = $pluginman->plugin_name($pluginfo->component);
// Do not show navigation here, they must click one of the buttons.
$this->page->set_pagelayout('maintenance');
$this->page->set_cacheable(false);
$output .= $this->output->header();
$output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
$output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
$confirm = $this->output->container(get_string('uninstalldeleteconfirm', 'core_plugin',
array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'uninstalldeleteconfirm');
if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) {
$confirm .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
'uninstalldeleteconfirmexternal');
}
// After any uninstall we must execute full upgrade to finish the cleanup!
$output .= $this->output->confirm($confirm, $continueurl, new moodle_url('/admin/index.php'));
$output .= $this->output->footer();
return $output;
}
|
php
|
public function plugin_uninstall_results_removable_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo,
progress_trace_buffer $progress, moodle_url $continueurl) {
$output = '';
$pluginname = $pluginman->plugin_name($pluginfo->component);
// Do not show navigation here, they must click one of the buttons.
$this->page->set_pagelayout('maintenance');
$this->page->set_cacheable(false);
$output .= $this->output->header();
$output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
$output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
$confirm = $this->output->container(get_string('uninstalldeleteconfirm', 'core_plugin',
array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'uninstalldeleteconfirm');
if ($repotype = $pluginman->plugin_external_source($pluginfo->component)) {
$confirm .= $this->output->container(get_string('uninstalldeleteconfirmexternal', 'core_plugin', $repotype),
'uninstalldeleteconfirmexternal');
}
// After any uninstall we must execute full upgrade to finish the cleanup!
$output .= $this->output->confirm($confirm, $continueurl, new moodle_url('/admin/index.php'));
$output .= $this->output->footer();
return $output;
}
|
[
"public",
"function",
"plugin_uninstall_results_removable_page",
"(",
"core_plugin_manager",
"$",
"pluginman",
",",
"\\",
"core",
"\\",
"plugininfo",
"\\",
"base",
"$",
"pluginfo",
",",
"progress_trace_buffer",
"$",
"progress",
",",
"moodle_url",
"$",
"continueurl",
")",
"{",
"$",
"output",
"=",
"''",
";",
"$",
"pluginname",
"=",
"$",
"pluginman",
"->",
"plugin_name",
"(",
"$",
"pluginfo",
"->",
"component",
")",
";",
"// Do not show navigation here, they must click one of the buttons.",
"$",
"this",
"->",
"page",
"->",
"set_pagelayout",
"(",
"'maintenance'",
")",
";",
"$",
"this",
"->",
"page",
"->",
"set_cacheable",
"(",
"false",
")",
";",
"$",
"output",
".=",
"$",
"this",
"->",
"output",
"->",
"header",
"(",
")",
";",
"$",
"output",
".=",
"$",
"this",
"->",
"output",
"->",
"heading",
"(",
"get_string",
"(",
"'uninstalling'",
",",
"'core_plugin'",
",",
"array",
"(",
"'name'",
"=>",
"$",
"pluginname",
")",
")",
")",
";",
"$",
"output",
".=",
"$",
"this",
"->",
"output",
"->",
"box",
"(",
"$",
"progress",
"->",
"get_buffer",
"(",
")",
",",
"'generalbox uninstallresultmessage'",
")",
";",
"$",
"confirm",
"=",
"$",
"this",
"->",
"output",
"->",
"container",
"(",
"get_string",
"(",
"'uninstalldeleteconfirm'",
",",
"'core_plugin'",
",",
"array",
"(",
"'name'",
"=>",
"$",
"pluginname",
",",
"'rootdir'",
"=>",
"$",
"pluginfo",
"->",
"rootdir",
")",
")",
",",
"'uninstalldeleteconfirm'",
")",
";",
"if",
"(",
"$",
"repotype",
"=",
"$",
"pluginman",
"->",
"plugin_external_source",
"(",
"$",
"pluginfo",
"->",
"component",
")",
")",
"{",
"$",
"confirm",
".=",
"$",
"this",
"->",
"output",
"->",
"container",
"(",
"get_string",
"(",
"'uninstalldeleteconfirmexternal'",
",",
"'core_plugin'",
",",
"$",
"repotype",
")",
",",
"'uninstalldeleteconfirmexternal'",
")",
";",
"}",
"// After any uninstall we must execute full upgrade to finish the cleanup!",
"$",
"output",
".=",
"$",
"this",
"->",
"output",
"->",
"confirm",
"(",
"$",
"confirm",
",",
"$",
"continueurl",
",",
"new",
"moodle_url",
"(",
"'/admin/index.php'",
")",
")",
";",
"$",
"output",
".=",
"$",
"this",
"->",
"output",
"->",
"footer",
"(",
")",
";",
"return",
"$",
"output",
";",
"}"
] |
Display a page with results of plugin uninstallation and offer removal of plugin files.
@param core_plugin_manager $pluginman
@param \core\plugininfo\base $pluginfo
@param progress_trace_buffer $progress
@param moodle_url $continueurl URL to continue to remove the plugin folder
@return string
|
[
"Display",
"a",
"page",
"with",
"results",
"of",
"plugin",
"uninstallation",
"and",
"offer",
"removal",
"of",
"plugin",
"files",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/renderer.php#L415-L443
|
219,104
|
moodle/moodle
|
admin/renderer.php
|
core_admin_renderer.plugin_uninstall_results_page
|
public function plugin_uninstall_results_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, progress_trace_buffer $progress) {
$output = '';
$pluginname = $pluginfo->component;
$output .= $this->output->header();
$output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
$output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
$output .= $this->output->box(get_string('uninstalldelete', 'core_plugin',
array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'generalbox uninstalldelete');
$output .= $this->output->continue_button(new moodle_url('/admin/index.php'));
$output .= $this->output->footer();
return $output;
}
|
php
|
public function plugin_uninstall_results_page(core_plugin_manager $pluginman, \core\plugininfo\base $pluginfo, progress_trace_buffer $progress) {
$output = '';
$pluginname = $pluginfo->component;
$output .= $this->output->header();
$output .= $this->output->heading(get_string('uninstalling', 'core_plugin', array('name' => $pluginname)));
$output .= $this->output->box($progress->get_buffer(), 'generalbox uninstallresultmessage');
$output .= $this->output->box(get_string('uninstalldelete', 'core_plugin',
array('name' => $pluginname, 'rootdir' => $pluginfo->rootdir)), 'generalbox uninstalldelete');
$output .= $this->output->continue_button(new moodle_url('/admin/index.php'));
$output .= $this->output->footer();
return $output;
}
|
[
"public",
"function",
"plugin_uninstall_results_page",
"(",
"core_plugin_manager",
"$",
"pluginman",
",",
"\\",
"core",
"\\",
"plugininfo",
"\\",
"base",
"$",
"pluginfo",
",",
"progress_trace_buffer",
"$",
"progress",
")",
"{",
"$",
"output",
"=",
"''",
";",
"$",
"pluginname",
"=",
"$",
"pluginfo",
"->",
"component",
";",
"$",
"output",
".=",
"$",
"this",
"->",
"output",
"->",
"header",
"(",
")",
";",
"$",
"output",
".=",
"$",
"this",
"->",
"output",
"->",
"heading",
"(",
"get_string",
"(",
"'uninstalling'",
",",
"'core_plugin'",
",",
"array",
"(",
"'name'",
"=>",
"$",
"pluginname",
")",
")",
")",
";",
"$",
"output",
".=",
"$",
"this",
"->",
"output",
"->",
"box",
"(",
"$",
"progress",
"->",
"get_buffer",
"(",
")",
",",
"'generalbox uninstallresultmessage'",
")",
";",
"$",
"output",
".=",
"$",
"this",
"->",
"output",
"->",
"box",
"(",
"get_string",
"(",
"'uninstalldelete'",
",",
"'core_plugin'",
",",
"array",
"(",
"'name'",
"=>",
"$",
"pluginname",
",",
"'rootdir'",
"=>",
"$",
"pluginfo",
"->",
"rootdir",
")",
")",
",",
"'generalbox uninstalldelete'",
")",
";",
"$",
"output",
".=",
"$",
"this",
"->",
"output",
"->",
"continue_button",
"(",
"new",
"moodle_url",
"(",
"'/admin/index.php'",
")",
")",
";",
"$",
"output",
".=",
"$",
"this",
"->",
"output",
"->",
"footer",
"(",
")",
";",
"return",
"$",
"output",
";",
"}"
] |
Display a page with results of plugin uninstallation and inform about the need to remove plugin files manually.
@param core_plugin_manager $pluginman
@param \core\plugininfo\base $pluginfo
@param progress_trace_buffer $progress
@return string
|
[
"Display",
"a",
"page",
"with",
"results",
"of",
"plugin",
"uninstallation",
"and",
"inform",
"about",
"the",
"need",
"to",
"remove",
"plugin",
"files",
"manually",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/renderer.php#L453-L469
|
219,105
|
moodle/moodle
|
admin/renderer.php
|
core_admin_renderer.insecure_dataroot_warning
|
protected function insecure_dataroot_warning($insecuredataroot) {
global $CFG;
if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot));
} else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'error');
} else {
return '';
}
}
|
php
|
protected function insecure_dataroot_warning($insecuredataroot) {
global $CFG;
if ($insecuredataroot == INSECURE_DATAROOT_WARNING) {
return $this->warning(get_string('datarootsecuritywarning', 'admin', $CFG->dataroot));
} else if ($insecuredataroot == INSECURE_DATAROOT_ERROR) {
return $this->warning(get_string('datarootsecurityerror', 'admin', $CFG->dataroot), 'error');
} else {
return '';
}
}
|
[
"protected",
"function",
"insecure_dataroot_warning",
"(",
"$",
"insecuredataroot",
")",
"{",
"global",
"$",
"CFG",
";",
"if",
"(",
"$",
"insecuredataroot",
"==",
"INSECURE_DATAROOT_WARNING",
")",
"{",
"return",
"$",
"this",
"->",
"warning",
"(",
"get_string",
"(",
"'datarootsecuritywarning'",
",",
"'admin'",
",",
"$",
"CFG",
"->",
"dataroot",
")",
")",
";",
"}",
"else",
"if",
"(",
"$",
"insecuredataroot",
"==",
"INSECURE_DATAROOT_ERROR",
")",
"{",
"return",
"$",
"this",
"->",
"warning",
"(",
"get_string",
"(",
"'datarootsecurityerror'",
",",
"'admin'",
",",
"$",
"CFG",
"->",
"dataroot",
")",
",",
"'error'",
")",
";",
"}",
"else",
"{",
"return",
"''",
";",
"}",
"}"
] |
Render an appropriate message if dataroot is insecure.
@param bool $insecuredataroot
@return string HTML to output.
|
[
"Render",
"an",
"appropriate",
"message",
"if",
"dataroot",
"is",
"insecure",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/renderer.php#L522-L534
|
219,106
|
moodle/moodle
|
admin/renderer.php
|
core_admin_renderer.development_libs_directories_warning
|
protected function development_libs_directories_warning($devlibdir) {
if ($devlibdir) {
$moreinfo = new moodle_url('/report/security/index.php');
$warning = get_string('devlibdirpresent', 'core_admin', ['moreinfourl' => $moreinfo->out()]);
return $this->warning($warning, 'error');
} else {
return '';
}
}
|
php
|
protected function development_libs_directories_warning($devlibdir) {
if ($devlibdir) {
$moreinfo = new moodle_url('/report/security/index.php');
$warning = get_string('devlibdirpresent', 'core_admin', ['moreinfourl' => $moreinfo->out()]);
return $this->warning($warning, 'error');
} else {
return '';
}
}
|
[
"protected",
"function",
"development_libs_directories_warning",
"(",
"$",
"devlibdir",
")",
"{",
"if",
"(",
"$",
"devlibdir",
")",
"{",
"$",
"moreinfo",
"=",
"new",
"moodle_url",
"(",
"'/report/security/index.php'",
")",
";",
"$",
"warning",
"=",
"get_string",
"(",
"'devlibdirpresent'",
",",
"'core_admin'",
",",
"[",
"'moreinfourl'",
"=>",
"$",
"moreinfo",
"->",
"out",
"(",
")",
"]",
")",
";",
"return",
"$",
"this",
"->",
"warning",
"(",
"$",
"warning",
",",
"'error'",
")",
";",
"}",
"else",
"{",
"return",
"''",
";",
"}",
"}"
] |
Render a warning that a directory with development libs is present.
@param bool $devlibdir True if the warning should be displayed.
@return string
|
[
"Render",
"a",
"warning",
"that",
"a",
"directory",
"with",
"development",
"libs",
"is",
"present",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/renderer.php#L542-L552
|
219,107
|
moodle/moodle
|
admin/renderer.php
|
core_admin_renderer.cron_overdue_warning
|
public function cron_overdue_warning($cronoverdue) {
global $CFG;
if (!$cronoverdue) {
return '';
}
if (empty($CFG->cronclionly)) {
$url = new moodle_url('/admin/cron.php');
if (!empty($CFG->cronremotepassword)) {
$url = new moodle_url('/admin/cron.php', array('password' => $CFG->cronremotepassword));
}
return $this->warning(get_string('cronwarning', 'admin', $url->out()) . ' ' .
$this->help_icon('cron', 'admin'));
}
// $CFG->cronclionly is not empty: cron can run only from CLI.
return $this->warning(get_string('cronwarningcli', 'admin') . ' ' .
$this->help_icon('cron', 'admin'));
}
|
php
|
public function cron_overdue_warning($cronoverdue) {
global $CFG;
if (!$cronoverdue) {
return '';
}
if (empty($CFG->cronclionly)) {
$url = new moodle_url('/admin/cron.php');
if (!empty($CFG->cronremotepassword)) {
$url = new moodle_url('/admin/cron.php', array('password' => $CFG->cronremotepassword));
}
return $this->warning(get_string('cronwarning', 'admin', $url->out()) . ' ' .
$this->help_icon('cron', 'admin'));
}
// $CFG->cronclionly is not empty: cron can run only from CLI.
return $this->warning(get_string('cronwarningcli', 'admin') . ' ' .
$this->help_icon('cron', 'admin'));
}
|
[
"public",
"function",
"cron_overdue_warning",
"(",
"$",
"cronoverdue",
")",
"{",
"global",
"$",
"CFG",
";",
"if",
"(",
"!",
"$",
"cronoverdue",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"CFG",
"->",
"cronclionly",
")",
")",
"{",
"$",
"url",
"=",
"new",
"moodle_url",
"(",
"'/admin/cron.php'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"CFG",
"->",
"cronremotepassword",
")",
")",
"{",
"$",
"url",
"=",
"new",
"moodle_url",
"(",
"'/admin/cron.php'",
",",
"array",
"(",
"'password'",
"=>",
"$",
"CFG",
"->",
"cronremotepassword",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"warning",
"(",
"get_string",
"(",
"'cronwarning'",
",",
"'admin'",
",",
"$",
"url",
"->",
"out",
"(",
")",
")",
".",
"' '",
".",
"$",
"this",
"->",
"help_icon",
"(",
"'cron'",
",",
"'admin'",
")",
")",
";",
"}",
"// $CFG->cronclionly is not empty: cron can run only from CLI.",
"return",
"$",
"this",
"->",
"warning",
"(",
"get_string",
"(",
"'cronwarningcli'",
",",
"'admin'",
")",
".",
"' '",
".",
"$",
"this",
"->",
"help_icon",
"(",
"'cron'",
",",
"'admin'",
")",
")",
";",
"}"
] |
Render an appropriate message if cron has not been run recently.
@param bool $cronoverdue
@return string HTML to output.
|
[
"Render",
"an",
"appropriate",
"message",
"if",
"cron",
"has",
"not",
"been",
"run",
"recently",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/renderer.php#L598-L617
|
219,108
|
moodle/moodle
|
admin/renderer.php
|
core_admin_renderer.events_handlers
|
public function events_handlers($eventshandlers) {
if ($eventshandlers) {
$components = '';
foreach ($eventshandlers as $eventhandler) {
$components .= $eventhandler->component . ', ';
}
$components = rtrim($components, ', ');
return $this->warning(get_string('eventshandlersinuse', 'admin', $components));
}
}
|
php
|
public function events_handlers($eventshandlers) {
if ($eventshandlers) {
$components = '';
foreach ($eventshandlers as $eventhandler) {
$components .= $eventhandler->component . ', ';
}
$components = rtrim($components, ', ');
return $this->warning(get_string('eventshandlersinuse', 'admin', $components));
}
}
|
[
"public",
"function",
"events_handlers",
"(",
"$",
"eventshandlers",
")",
"{",
"if",
"(",
"$",
"eventshandlers",
")",
"{",
"$",
"components",
"=",
"''",
";",
"foreach",
"(",
"$",
"eventshandlers",
"as",
"$",
"eventhandler",
")",
"{",
"$",
"components",
".=",
"$",
"eventhandler",
"->",
"component",
".",
"', '",
";",
"}",
"$",
"components",
"=",
"rtrim",
"(",
"$",
"components",
",",
"', '",
")",
";",
"return",
"$",
"this",
"->",
"warning",
"(",
"get_string",
"(",
"'eventshandlersinuse'",
",",
"'admin'",
",",
"$",
"components",
")",
")",
";",
"}",
"}"
] |
Renders events 1 API handlers warning.
@param array $eventshandlers
@return string
|
[
"Renders",
"events",
"1",
"API",
"handlers",
"warning",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/renderer.php#L669-L678
|
219,109
|
moodle/moodle
|
admin/renderer.php
|
core_admin_renderer.maintenance_mode_warning
|
public function maintenance_mode_warning($maintenancemode) {
if (!$maintenancemode) {
return '';
}
$url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'));
$url = $url->out(); // get_string() does not support objects in params
return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url));
}
|
php
|
public function maintenance_mode_warning($maintenancemode) {
if (!$maintenancemode) {
return '';
}
$url = new moodle_url('/admin/settings.php', array('section' => 'maintenancemode'));
$url = $url->out(); // get_string() does not support objects in params
return $this->warning(get_string('sitemaintenancewarning2', 'admin', $url));
}
|
[
"public",
"function",
"maintenance_mode_warning",
"(",
"$",
"maintenancemode",
")",
"{",
"if",
"(",
"!",
"$",
"maintenancemode",
")",
"{",
"return",
"''",
";",
"}",
"$",
"url",
"=",
"new",
"moodle_url",
"(",
"'/admin/settings.php'",
",",
"array",
"(",
"'section'",
"=>",
"'maintenancemode'",
")",
")",
";",
"$",
"url",
"=",
"$",
"url",
"->",
"out",
"(",
")",
";",
"// get_string() does not support objects in params",
"return",
"$",
"this",
"->",
"warning",
"(",
"get_string",
"(",
"'sitemaintenancewarning2'",
",",
"'admin'",
",",
"$",
"url",
")",
")",
";",
"}"
] |
Render an appropriate message if the site in in maintenance mode.
@param bool $maintenancemode
@return string HTML to output.
|
[
"Render",
"an",
"appropriate",
"message",
"if",
"the",
"site",
"in",
"in",
"maintenance",
"mode",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/renderer.php#L685-L694
|
219,110
|
moodle/moodle
|
admin/renderer.php
|
core_admin_renderer.moodle_copyright
|
protected function moodle_copyright() {
global $CFG;
//////////////////////////////////////////////////////////////////////////////////////////////////
//// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
$copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
'<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
'Copyright © 1999 onwards, Martin Dougiamas<br />'.
'and <a href="http://moodle.org/dev">many other contributors</a>.<br />'.
'<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
//////////////////////////////////////////////////////////////////////////////////////////////////
return $this->box($copyrighttext, 'copyright');
}
|
php
|
protected function moodle_copyright() {
global $CFG;
//////////////////////////////////////////////////////////////////////////////////////////////////
//// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///
$copyrighttext = '<a href="http://moodle.org/">Moodle</a> '.
'<a href="http://docs.moodle.org/dev/Releases" title="'.$CFG->version.'">'.$CFG->release.'</a><br />'.
'Copyright © 1999 onwards, Martin Dougiamas<br />'.
'and <a href="http://moodle.org/dev">many other contributors</a>.<br />'.
'<a href="http://docs.moodle.org/dev/License">GNU Public License</a>';
//////////////////////////////////////////////////////////////////////////////////////////////////
return $this->box($copyrighttext, 'copyright');
}
|
[
"protected",
"function",
"moodle_copyright",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"//////////////////////////////////////////////////////////////////////////////////////////////////",
"//// IT IS ILLEGAL AND A VIOLATION OF THE GPL TO HIDE, REMOVE OR MODIFY THIS COPYRIGHT NOTICE ///",
"$",
"copyrighttext",
"=",
"'<a href=\"http://moodle.org/\">Moodle</a> '",
".",
"'<a href=\"http://docs.moodle.org/dev/Releases\" title=\"'",
".",
"$",
"CFG",
"->",
"version",
".",
"'\">'",
".",
"$",
"CFG",
"->",
"release",
".",
"'</a><br />'",
".",
"'Copyright © 1999 onwards, Martin Dougiamas<br />'",
".",
"'and <a href=\"http://moodle.org/dev\">many other contributors</a>.<br />'",
".",
"'<a href=\"http://docs.moodle.org/dev/License\">GNU Public License</a>'",
";",
"//////////////////////////////////////////////////////////////////////////////////////////////////",
"return",
"$",
"this",
"->",
"box",
"(",
"$",
"copyrighttext",
",",
"'copyright'",
")",
";",
"}"
] |
Output the copyright notice.
@return string HTML to output.
|
[
"Output",
"the",
"copyright",
"notice",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/renderer.php#L747-L760
|
219,111
|
moodle/moodle
|
admin/renderer.php
|
core_admin_renderer.available_updates
|
protected function available_updates($updates, $fetch) {
$updateinfo = '';
$someupdateavailable = false;
if (is_array($updates)) {
if (is_array($updates['core'])) {
$someupdateavailable = true;
$updateinfo .= $this->heading(get_string('updateavailable', 'core_admin'), 3);
foreach ($updates['core'] as $update) {
$updateinfo .= $this->moodle_available_update_info($update);
}
$updateinfo .= html_writer::tag('p', get_string('updateavailablerecommendation', 'core_admin'),
array('class' => 'updateavailablerecommendation'));
}
unset($updates['core']);
// If something has left in the $updates array now, it is updates for plugins.
if (!empty($updates)) {
$someupdateavailable = true;
$updateinfo .= $this->heading(get_string('updateavailableforplugin', 'core_admin'), 3);
$pluginsoverviewurl = new moodle_url('/admin/plugins.php', array('updatesonly' => 1));
$updateinfo .= $this->container(get_string('pluginsoverviewsee', 'core_admin',
array('url' => $pluginsoverviewurl->out())));
}
}
if (!$someupdateavailable) {
$now = time();
if ($fetch and ($fetch <= $now) and ($now - $fetch < HOURSECS)) {
$updateinfo .= $this->heading(get_string('updateavailablenot', 'core_admin'), 3);
}
}
$updateinfo .= $this->container_start('checkforupdates');
$fetchurl = new moodle_url('/admin/index.php', array('fetchupdates' => 1, 'sesskey' => sesskey(), 'cache' => 0));
$updateinfo .= $this->single_button($fetchurl, get_string('checkforupdates', 'core_plugin'));
if ($fetch) {
$updateinfo .= $this->container(get_string('checkforupdateslast', 'core_plugin',
userdate($fetch, get_string('strftimedatetime', 'core_langconfig'))));
}
$updateinfo .= $this->container_end();
return $this->warning($updateinfo);
}
|
php
|
protected function available_updates($updates, $fetch) {
$updateinfo = '';
$someupdateavailable = false;
if (is_array($updates)) {
if (is_array($updates['core'])) {
$someupdateavailable = true;
$updateinfo .= $this->heading(get_string('updateavailable', 'core_admin'), 3);
foreach ($updates['core'] as $update) {
$updateinfo .= $this->moodle_available_update_info($update);
}
$updateinfo .= html_writer::tag('p', get_string('updateavailablerecommendation', 'core_admin'),
array('class' => 'updateavailablerecommendation'));
}
unset($updates['core']);
// If something has left in the $updates array now, it is updates for plugins.
if (!empty($updates)) {
$someupdateavailable = true;
$updateinfo .= $this->heading(get_string('updateavailableforplugin', 'core_admin'), 3);
$pluginsoverviewurl = new moodle_url('/admin/plugins.php', array('updatesonly' => 1));
$updateinfo .= $this->container(get_string('pluginsoverviewsee', 'core_admin',
array('url' => $pluginsoverviewurl->out())));
}
}
if (!$someupdateavailable) {
$now = time();
if ($fetch and ($fetch <= $now) and ($now - $fetch < HOURSECS)) {
$updateinfo .= $this->heading(get_string('updateavailablenot', 'core_admin'), 3);
}
}
$updateinfo .= $this->container_start('checkforupdates');
$fetchurl = new moodle_url('/admin/index.php', array('fetchupdates' => 1, 'sesskey' => sesskey(), 'cache' => 0));
$updateinfo .= $this->single_button($fetchurl, get_string('checkforupdates', 'core_plugin'));
if ($fetch) {
$updateinfo .= $this->container(get_string('checkforupdateslast', 'core_plugin',
userdate($fetch, get_string('strftimedatetime', 'core_langconfig'))));
}
$updateinfo .= $this->container_end();
return $this->warning($updateinfo);
}
|
[
"protected",
"function",
"available_updates",
"(",
"$",
"updates",
",",
"$",
"fetch",
")",
"{",
"$",
"updateinfo",
"=",
"''",
";",
"$",
"someupdateavailable",
"=",
"false",
";",
"if",
"(",
"is_array",
"(",
"$",
"updates",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"updates",
"[",
"'core'",
"]",
")",
")",
"{",
"$",
"someupdateavailable",
"=",
"true",
";",
"$",
"updateinfo",
".=",
"$",
"this",
"->",
"heading",
"(",
"get_string",
"(",
"'updateavailable'",
",",
"'core_admin'",
")",
",",
"3",
")",
";",
"foreach",
"(",
"$",
"updates",
"[",
"'core'",
"]",
"as",
"$",
"update",
")",
"{",
"$",
"updateinfo",
".=",
"$",
"this",
"->",
"moodle_available_update_info",
"(",
"$",
"update",
")",
";",
"}",
"$",
"updateinfo",
".=",
"html_writer",
"::",
"tag",
"(",
"'p'",
",",
"get_string",
"(",
"'updateavailablerecommendation'",
",",
"'core_admin'",
")",
",",
"array",
"(",
"'class'",
"=>",
"'updateavailablerecommendation'",
")",
")",
";",
"}",
"unset",
"(",
"$",
"updates",
"[",
"'core'",
"]",
")",
";",
"// If something has left in the $updates array now, it is updates for plugins.",
"if",
"(",
"!",
"empty",
"(",
"$",
"updates",
")",
")",
"{",
"$",
"someupdateavailable",
"=",
"true",
";",
"$",
"updateinfo",
".=",
"$",
"this",
"->",
"heading",
"(",
"get_string",
"(",
"'updateavailableforplugin'",
",",
"'core_admin'",
")",
",",
"3",
")",
";",
"$",
"pluginsoverviewurl",
"=",
"new",
"moodle_url",
"(",
"'/admin/plugins.php'",
",",
"array",
"(",
"'updatesonly'",
"=>",
"1",
")",
")",
";",
"$",
"updateinfo",
".=",
"$",
"this",
"->",
"container",
"(",
"get_string",
"(",
"'pluginsoverviewsee'",
",",
"'core_admin'",
",",
"array",
"(",
"'url'",
"=>",
"$",
"pluginsoverviewurl",
"->",
"out",
"(",
")",
")",
")",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"someupdateavailable",
")",
"{",
"$",
"now",
"=",
"time",
"(",
")",
";",
"if",
"(",
"$",
"fetch",
"and",
"(",
"$",
"fetch",
"<=",
"$",
"now",
")",
"and",
"(",
"$",
"now",
"-",
"$",
"fetch",
"<",
"HOURSECS",
")",
")",
"{",
"$",
"updateinfo",
".=",
"$",
"this",
"->",
"heading",
"(",
"get_string",
"(",
"'updateavailablenot'",
",",
"'core_admin'",
")",
",",
"3",
")",
";",
"}",
"}",
"$",
"updateinfo",
".=",
"$",
"this",
"->",
"container_start",
"(",
"'checkforupdates'",
")",
";",
"$",
"fetchurl",
"=",
"new",
"moodle_url",
"(",
"'/admin/index.php'",
",",
"array",
"(",
"'fetchupdates'",
"=>",
"1",
",",
"'sesskey'",
"=>",
"sesskey",
"(",
")",
",",
"'cache'",
"=>",
"0",
")",
")",
";",
"$",
"updateinfo",
".=",
"$",
"this",
"->",
"single_button",
"(",
"$",
"fetchurl",
",",
"get_string",
"(",
"'checkforupdates'",
",",
"'core_plugin'",
")",
")",
";",
"if",
"(",
"$",
"fetch",
")",
"{",
"$",
"updateinfo",
".=",
"$",
"this",
"->",
"container",
"(",
"get_string",
"(",
"'checkforupdateslast'",
",",
"'core_plugin'",
",",
"userdate",
"(",
"$",
"fetch",
",",
"get_string",
"(",
"'strftimedatetime'",
",",
"'core_langconfig'",
")",
")",
")",
")",
";",
"}",
"$",
"updateinfo",
".=",
"$",
"this",
"->",
"container_end",
"(",
")",
";",
"return",
"$",
"this",
"->",
"warning",
"(",
"$",
"updateinfo",
")",
";",
"}"
] |
Displays the info about available Moodle core and plugin updates
The structure of the $updates param has changed since 2.4. It contains not only updates
for the core itself, but also for all other installed plugins.
@param array|null $updates array of (string)component => array of \core\update\info objects or null
@param int|null $fetch timestamp of the most recent updates fetch or null (unknown)
@return string
|
[
"Displays",
"the",
"info",
"about",
"available",
"Moodle",
"core",
"and",
"plugin",
"updates"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/renderer.php#L794-L836
|
219,112
|
moodle/moodle
|
admin/renderer.php
|
core_admin_renderer.registration_warning
|
protected function registration_warning($registered) {
if (!$registered && site_is_public()) {
if (has_capability('moodle/site:config', context_system::instance())) {
$registerbutton = $this->single_button(new moodle_url('/admin/registration/index.php'),
get_string('register', 'admin'));
$str = 'registrationwarning';
} else {
$registerbutton = '';
$str = 'registrationwarningcontactadmin';
}
return $this->warning( get_string($str, 'admin')
. ' ' . $this->help_icon('registration', 'admin') . $registerbutton ,
'error alert alert-danger');
}
return '';
}
|
php
|
protected function registration_warning($registered) {
if (!$registered && site_is_public()) {
if (has_capability('moodle/site:config', context_system::instance())) {
$registerbutton = $this->single_button(new moodle_url('/admin/registration/index.php'),
get_string('register', 'admin'));
$str = 'registrationwarning';
} else {
$registerbutton = '';
$str = 'registrationwarningcontactadmin';
}
return $this->warning( get_string($str, 'admin')
. ' ' . $this->help_icon('registration', 'admin') . $registerbutton ,
'error alert alert-danger');
}
return '';
}
|
[
"protected",
"function",
"registration_warning",
"(",
"$",
"registered",
")",
"{",
"if",
"(",
"!",
"$",
"registered",
"&&",
"site_is_public",
"(",
")",
")",
"{",
"if",
"(",
"has_capability",
"(",
"'moodle/site:config'",
",",
"context_system",
"::",
"instance",
"(",
")",
")",
")",
"{",
"$",
"registerbutton",
"=",
"$",
"this",
"->",
"single_button",
"(",
"new",
"moodle_url",
"(",
"'/admin/registration/index.php'",
")",
",",
"get_string",
"(",
"'register'",
",",
"'admin'",
")",
")",
";",
"$",
"str",
"=",
"'registrationwarning'",
";",
"}",
"else",
"{",
"$",
"registerbutton",
"=",
"''",
";",
"$",
"str",
"=",
"'registrationwarningcontactadmin'",
";",
"}",
"return",
"$",
"this",
"->",
"warning",
"(",
"get_string",
"(",
"$",
"str",
",",
"'admin'",
")",
".",
"' '",
".",
"$",
"this",
"->",
"help_icon",
"(",
"'registration'",
",",
"'admin'",
")",
".",
"$",
"registerbutton",
",",
"'error alert alert-danger'",
")",
";",
"}",
"return",
"''",
";",
"}"
] |
Display a warning about not being registered on Moodle.org if necesary.
@param boolean $registered true if the site is registered on Moodle.org
@return string HTML to output.
|
[
"Display",
"a",
"warning",
"about",
"not",
"being",
"registered",
"on",
"Moodle",
".",
"org",
"if",
"necesary",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/renderer.php#L844-L862
|
219,113
|
moodle/moodle
|
admin/renderer.php
|
core_admin_renderer.mobile_configuration_warning
|
protected function mobile_configuration_warning($mobileconfigured) {
$output = '';
if (!$mobileconfigured) {
$settingslink = new moodle_url('/admin/settings.php', ['section' => 'mobilesettings']);
$configurebutton = $this->single_button($settingslink, get_string('enablemobilewebservice', 'admin'));
$output .= $this->warning(get_string('mobilenotconfiguredwarning', 'admin') . ' ' . $configurebutton);
}
return $output;
}
|
php
|
protected function mobile_configuration_warning($mobileconfigured) {
$output = '';
if (!$mobileconfigured) {
$settingslink = new moodle_url('/admin/settings.php', ['section' => 'mobilesettings']);
$configurebutton = $this->single_button($settingslink, get_string('enablemobilewebservice', 'admin'));
$output .= $this->warning(get_string('mobilenotconfiguredwarning', 'admin') . ' ' . $configurebutton);
}
return $output;
}
|
[
"protected",
"function",
"mobile_configuration_warning",
"(",
"$",
"mobileconfigured",
")",
"{",
"$",
"output",
"=",
"''",
";",
"if",
"(",
"!",
"$",
"mobileconfigured",
")",
"{",
"$",
"settingslink",
"=",
"new",
"moodle_url",
"(",
"'/admin/settings.php'",
",",
"[",
"'section'",
"=>",
"'mobilesettings'",
"]",
")",
";",
"$",
"configurebutton",
"=",
"$",
"this",
"->",
"single_button",
"(",
"$",
"settingslink",
",",
"get_string",
"(",
"'enablemobilewebservice'",
",",
"'admin'",
")",
")",
";",
"$",
"output",
".=",
"$",
"this",
"->",
"warning",
"(",
"get_string",
"(",
"'mobilenotconfiguredwarning'",
",",
"'admin'",
")",
".",
"' '",
".",
"$",
"configurebutton",
")",
";",
"}",
"return",
"$",
"output",
";",
"}"
] |
Display a warning about the Mobile Web Services being disabled.
@param boolean $mobileconfigured true if mobile web services are enabled
@return string HTML to output.
|
[
"Display",
"a",
"warning",
"about",
"the",
"Mobile",
"Web",
"Services",
"being",
"disabled",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/renderer.php#L879-L888
|
219,114
|
moodle/moodle
|
admin/renderer.php
|
core_admin_renderer.forgotten_password_url_warning
|
protected function forgotten_password_url_warning($invalidforgottenpasswordurl) {
$output = '';
if ($invalidforgottenpasswordurl) {
$settingslink = new moodle_url('/admin/settings.php', ['section' => 'manageauths']);
$configurebutton = $this->single_button($settingslink, get_string('check', 'moodle'));
$output .= $this->warning(get_string('invalidforgottenpasswordurl', 'admin') . ' ' . $configurebutton,
'error alert alert-danger');
}
return $output;
}
|
php
|
protected function forgotten_password_url_warning($invalidforgottenpasswordurl) {
$output = '';
if ($invalidforgottenpasswordurl) {
$settingslink = new moodle_url('/admin/settings.php', ['section' => 'manageauths']);
$configurebutton = $this->single_button($settingslink, get_string('check', 'moodle'));
$output .= $this->warning(get_string('invalidforgottenpasswordurl', 'admin') . ' ' . $configurebutton,
'error alert alert-danger');
}
return $output;
}
|
[
"protected",
"function",
"forgotten_password_url_warning",
"(",
"$",
"invalidforgottenpasswordurl",
")",
"{",
"$",
"output",
"=",
"''",
";",
"if",
"(",
"$",
"invalidforgottenpasswordurl",
")",
"{",
"$",
"settingslink",
"=",
"new",
"moodle_url",
"(",
"'/admin/settings.php'",
",",
"[",
"'section'",
"=>",
"'manageauths'",
"]",
")",
";",
"$",
"configurebutton",
"=",
"$",
"this",
"->",
"single_button",
"(",
"$",
"settingslink",
",",
"get_string",
"(",
"'check'",
",",
"'moodle'",
")",
")",
";",
"$",
"output",
".=",
"$",
"this",
"->",
"warning",
"(",
"get_string",
"(",
"'invalidforgottenpasswordurl'",
",",
"'admin'",
")",
".",
"' '",
".",
"$",
"configurebutton",
",",
"'error alert alert-danger'",
")",
";",
"}",
"return",
"$",
"output",
";",
"}"
] |
Display a warning about the forgotten password URL not linking to a valid URL.
@param boolean $invalidforgottenpasswordurl true if the forgotten password URL is not valid
@return string HTML to output.
|
[
"Display",
"a",
"warning",
"about",
"the",
"forgotten",
"password",
"URL",
"not",
"linking",
"to",
"a",
"valid",
"URL",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/renderer.php#L896-L906
|
219,115
|
moodle/moodle
|
admin/renderer.php
|
core_admin_renderer.moodle_available_update_info
|
protected function moodle_available_update_info(\core\update\info $updateinfo) {
$boxclasses = 'moodleupdateinfo';
$info = array();
if (isset($updateinfo->release)) {
$info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_admin', $updateinfo->release),
array('class' => 'info release'));
}
if (isset($updateinfo->version)) {
$info[] = html_writer::tag('span', get_string('updateavailable_version', 'core_admin', $updateinfo->version),
array('class' => 'info version'));
}
if (isset($updateinfo->maturity)) {
$info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
array('class' => 'info maturity'));
$boxclasses .= ' maturity'.$updateinfo->maturity;
}
if (isset($updateinfo->download)) {
$info[] = html_writer::link($updateinfo->download, get_string('download'), array('class' => 'info download'));
}
if (isset($updateinfo->url)) {
$info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
array('class' => 'info more'));
}
$box = $this->output->box_start($boxclasses);
$box .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '');
$box .= $this->output->box_end();
return $box;
}
|
php
|
protected function moodle_available_update_info(\core\update\info $updateinfo) {
$boxclasses = 'moodleupdateinfo';
$info = array();
if (isset($updateinfo->release)) {
$info[] = html_writer::tag('span', get_string('updateavailable_release', 'core_admin', $updateinfo->release),
array('class' => 'info release'));
}
if (isset($updateinfo->version)) {
$info[] = html_writer::tag('span', get_string('updateavailable_version', 'core_admin', $updateinfo->version),
array('class' => 'info version'));
}
if (isset($updateinfo->maturity)) {
$info[] = html_writer::tag('span', get_string('maturity'.$updateinfo->maturity, 'core_admin'),
array('class' => 'info maturity'));
$boxclasses .= ' maturity'.$updateinfo->maturity;
}
if (isset($updateinfo->download)) {
$info[] = html_writer::link($updateinfo->download, get_string('download'), array('class' => 'info download'));
}
if (isset($updateinfo->url)) {
$info[] = html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin'),
array('class' => 'info more'));
}
$box = $this->output->box_start($boxclasses);
$box .= $this->output->box(implode(html_writer::tag('span', ' ', array('class' => 'separator')), $info), '');
$box .= $this->output->box_end();
return $box;
}
|
[
"protected",
"function",
"moodle_available_update_info",
"(",
"\\",
"core",
"\\",
"update",
"\\",
"info",
"$",
"updateinfo",
")",
"{",
"$",
"boxclasses",
"=",
"'moodleupdateinfo'",
";",
"$",
"info",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"updateinfo",
"->",
"release",
")",
")",
"{",
"$",
"info",
"[",
"]",
"=",
"html_writer",
"::",
"tag",
"(",
"'span'",
",",
"get_string",
"(",
"'updateavailable_release'",
",",
"'core_admin'",
",",
"$",
"updateinfo",
"->",
"release",
")",
",",
"array",
"(",
"'class'",
"=>",
"'info release'",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"updateinfo",
"->",
"version",
")",
")",
"{",
"$",
"info",
"[",
"]",
"=",
"html_writer",
"::",
"tag",
"(",
"'span'",
",",
"get_string",
"(",
"'updateavailable_version'",
",",
"'core_admin'",
",",
"$",
"updateinfo",
"->",
"version",
")",
",",
"array",
"(",
"'class'",
"=>",
"'info version'",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"updateinfo",
"->",
"maturity",
")",
")",
"{",
"$",
"info",
"[",
"]",
"=",
"html_writer",
"::",
"tag",
"(",
"'span'",
",",
"get_string",
"(",
"'maturity'",
".",
"$",
"updateinfo",
"->",
"maturity",
",",
"'core_admin'",
")",
",",
"array",
"(",
"'class'",
"=>",
"'info maturity'",
")",
")",
";",
"$",
"boxclasses",
".=",
"' maturity'",
".",
"$",
"updateinfo",
"->",
"maturity",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"updateinfo",
"->",
"download",
")",
")",
"{",
"$",
"info",
"[",
"]",
"=",
"html_writer",
"::",
"link",
"(",
"$",
"updateinfo",
"->",
"download",
",",
"get_string",
"(",
"'download'",
")",
",",
"array",
"(",
"'class'",
"=>",
"'info download'",
")",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"updateinfo",
"->",
"url",
")",
")",
"{",
"$",
"info",
"[",
"]",
"=",
"html_writer",
"::",
"link",
"(",
"$",
"updateinfo",
"->",
"url",
",",
"get_string",
"(",
"'updateavailable_moreinfo'",
",",
"'core_plugin'",
")",
",",
"array",
"(",
"'class'",
"=>",
"'info more'",
")",
")",
";",
"}",
"$",
"box",
"=",
"$",
"this",
"->",
"output",
"->",
"box_start",
"(",
"$",
"boxclasses",
")",
";",
"$",
"box",
".=",
"$",
"this",
"->",
"output",
"->",
"box",
"(",
"implode",
"(",
"html_writer",
"::",
"tag",
"(",
"'span'",
",",
"' '",
",",
"array",
"(",
"'class'",
"=>",
"'separator'",
")",
")",
",",
"$",
"info",
")",
",",
"''",
")",
";",
"$",
"box",
".=",
"$",
"this",
"->",
"output",
"->",
"box_end",
"(",
")",
";",
"return",
"$",
"box",
";",
"}"
] |
Helper method to render the information about the available Moodle update
@param \core\update\info $updateinfo information about the available Moodle core update
|
[
"Helper",
"method",
"to",
"render",
"the",
"information",
"about",
"the",
"available",
"Moodle",
"update"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/renderer.php#L913-L948
|
219,116
|
moodle/moodle
|
admin/renderer.php
|
core_admin_renderer.plugin_available_update_info
|
protected function plugin_available_update_info(core_plugin_manager $pluginman, \core\update\info $updateinfo) {
$boxclasses = 'pluginupdateinfo';
$info = array();
if (isset($updateinfo->release)) {
$info[] = html_writer::div(
get_string('updateavailable_release', 'core_plugin', $updateinfo->release),
'info release'
);
}
if (isset($updateinfo->maturity)) {
$info[] = html_writer::div(
get_string('maturity'.$updateinfo->maturity, 'core_admin'),
'info maturity'
);
$boxclasses .= ' maturity'.$updateinfo->maturity;
}
if (isset($updateinfo->download)) {
$info[] = html_writer::div(
html_writer::link($updateinfo->download, get_string('download')),
'info download'
);
}
if (isset($updateinfo->url)) {
$info[] = html_writer::div(
html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin')),
'info more'
);
}
$box = html_writer::start_div($boxclasses);
$box .= html_writer::div(
get_string('updateavailable', 'core_plugin', $updateinfo->version),
'version'
);
$box .= html_writer::div(
implode(html_writer::span(' ', 'separator'), $info),
'infos'
);
if ($pluginman->is_remote_plugin_installable($updateinfo->component, $updateinfo->version, $reason)) {
$box .= $this->output->single_button(
new moodle_url($this->page->url, array('installupdate' => $updateinfo->component,
'installupdateversion' => $updateinfo->version)),
get_string('updateavailableinstall', 'core_admin'),
'post',
array('class' => 'singlebutton updateavailableinstall')
);
} else {
$reasonhelp = $this->info_remote_plugin_not_installable($reason);
if ($reasonhelp) {
$box .= html_writer::div($reasonhelp, 'reasonhelp updateavailableinstall');
}
}
$box .= html_writer::end_div();
return $box;
}
|
php
|
protected function plugin_available_update_info(core_plugin_manager $pluginman, \core\update\info $updateinfo) {
$boxclasses = 'pluginupdateinfo';
$info = array();
if (isset($updateinfo->release)) {
$info[] = html_writer::div(
get_string('updateavailable_release', 'core_plugin', $updateinfo->release),
'info release'
);
}
if (isset($updateinfo->maturity)) {
$info[] = html_writer::div(
get_string('maturity'.$updateinfo->maturity, 'core_admin'),
'info maturity'
);
$boxclasses .= ' maturity'.$updateinfo->maturity;
}
if (isset($updateinfo->download)) {
$info[] = html_writer::div(
html_writer::link($updateinfo->download, get_string('download')),
'info download'
);
}
if (isset($updateinfo->url)) {
$info[] = html_writer::div(
html_writer::link($updateinfo->url, get_string('updateavailable_moreinfo', 'core_plugin')),
'info more'
);
}
$box = html_writer::start_div($boxclasses);
$box .= html_writer::div(
get_string('updateavailable', 'core_plugin', $updateinfo->version),
'version'
);
$box .= html_writer::div(
implode(html_writer::span(' ', 'separator'), $info),
'infos'
);
if ($pluginman->is_remote_plugin_installable($updateinfo->component, $updateinfo->version, $reason)) {
$box .= $this->output->single_button(
new moodle_url($this->page->url, array('installupdate' => $updateinfo->component,
'installupdateversion' => $updateinfo->version)),
get_string('updateavailableinstall', 'core_admin'),
'post',
array('class' => 'singlebutton updateavailableinstall')
);
} else {
$reasonhelp = $this->info_remote_plugin_not_installable($reason);
if ($reasonhelp) {
$box .= html_writer::div($reasonhelp, 'reasonhelp updateavailableinstall');
}
}
$box .= html_writer::end_div();
return $box;
}
|
[
"protected",
"function",
"plugin_available_update_info",
"(",
"core_plugin_manager",
"$",
"pluginman",
",",
"\\",
"core",
"\\",
"update",
"\\",
"info",
"$",
"updateinfo",
")",
"{",
"$",
"boxclasses",
"=",
"'pluginupdateinfo'",
";",
"$",
"info",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"updateinfo",
"->",
"release",
")",
")",
"{",
"$",
"info",
"[",
"]",
"=",
"html_writer",
"::",
"div",
"(",
"get_string",
"(",
"'updateavailable_release'",
",",
"'core_plugin'",
",",
"$",
"updateinfo",
"->",
"release",
")",
",",
"'info release'",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"updateinfo",
"->",
"maturity",
")",
")",
"{",
"$",
"info",
"[",
"]",
"=",
"html_writer",
"::",
"div",
"(",
"get_string",
"(",
"'maturity'",
".",
"$",
"updateinfo",
"->",
"maturity",
",",
"'core_admin'",
")",
",",
"'info maturity'",
")",
";",
"$",
"boxclasses",
".=",
"' maturity'",
".",
"$",
"updateinfo",
"->",
"maturity",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"updateinfo",
"->",
"download",
")",
")",
"{",
"$",
"info",
"[",
"]",
"=",
"html_writer",
"::",
"div",
"(",
"html_writer",
"::",
"link",
"(",
"$",
"updateinfo",
"->",
"download",
",",
"get_string",
"(",
"'download'",
")",
")",
",",
"'info download'",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"updateinfo",
"->",
"url",
")",
")",
"{",
"$",
"info",
"[",
"]",
"=",
"html_writer",
"::",
"div",
"(",
"html_writer",
"::",
"link",
"(",
"$",
"updateinfo",
"->",
"url",
",",
"get_string",
"(",
"'updateavailable_moreinfo'",
",",
"'core_plugin'",
")",
")",
",",
"'info more'",
")",
";",
"}",
"$",
"box",
"=",
"html_writer",
"::",
"start_div",
"(",
"$",
"boxclasses",
")",
";",
"$",
"box",
".=",
"html_writer",
"::",
"div",
"(",
"get_string",
"(",
"'updateavailable'",
",",
"'core_plugin'",
",",
"$",
"updateinfo",
"->",
"version",
")",
",",
"'version'",
")",
";",
"$",
"box",
".=",
"html_writer",
"::",
"div",
"(",
"implode",
"(",
"html_writer",
"::",
"span",
"(",
"' '",
",",
"'separator'",
")",
",",
"$",
"info",
")",
",",
"'infos'",
")",
";",
"if",
"(",
"$",
"pluginman",
"->",
"is_remote_plugin_installable",
"(",
"$",
"updateinfo",
"->",
"component",
",",
"$",
"updateinfo",
"->",
"version",
",",
"$",
"reason",
")",
")",
"{",
"$",
"box",
".=",
"$",
"this",
"->",
"output",
"->",
"single_button",
"(",
"new",
"moodle_url",
"(",
"$",
"this",
"->",
"page",
"->",
"url",
",",
"array",
"(",
"'installupdate'",
"=>",
"$",
"updateinfo",
"->",
"component",
",",
"'installupdateversion'",
"=>",
"$",
"updateinfo",
"->",
"version",
")",
")",
",",
"get_string",
"(",
"'updateavailableinstall'",
",",
"'core_admin'",
")",
",",
"'post'",
",",
"array",
"(",
"'class'",
"=>",
"'singlebutton updateavailableinstall'",
")",
")",
";",
"}",
"else",
"{",
"$",
"reasonhelp",
"=",
"$",
"this",
"->",
"info_remote_plugin_not_installable",
"(",
"$",
"reason",
")",
";",
"if",
"(",
"$",
"reasonhelp",
")",
"{",
"$",
"box",
".=",
"html_writer",
"::",
"div",
"(",
"$",
"reasonhelp",
",",
"'reasonhelp updateavailableinstall'",
")",
";",
"}",
"}",
"$",
"box",
".=",
"html_writer",
"::",
"end_div",
"(",
")",
";",
"return",
"$",
"box",
";",
"}"
] |
Helper method to render the information about the available plugin update
@param core_plugin_manager $pluginman plugin manager instance
@param \core\update\info $updateinfo information about the available update for the plugin
|
[
"Helper",
"method",
"to",
"render",
"the",
"information",
"about",
"the",
"available",
"plugin",
"update"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/renderer.php#L1819-L1880
|
219,117
|
moodle/moodle
|
admin/renderer.php
|
core_admin_renderer.upgradekey_form_page
|
public function upgradekey_form_page($url) {
$output = '';
$output .= $this->header();
$output .= $this->container_start('upgradekeyreq');
$output .= $this->heading(get_string('upgradekeyreq', 'core_admin'));
$output .= html_writer::start_tag('form', array('method' => 'POST', 'action' => $url));
$output .= html_writer::empty_tag('input', array('name' => 'upgradekey', 'type' => 'password'));
$output .= html_writer::empty_tag('input', array('value' => get_string('submit'), 'type' => 'submit'));
$output .= html_writer::end_tag('form');
$output .= $this->container_end();
$output .= $this->footer();
return $output;
}
|
php
|
public function upgradekey_form_page($url) {
$output = '';
$output .= $this->header();
$output .= $this->container_start('upgradekeyreq');
$output .= $this->heading(get_string('upgradekeyreq', 'core_admin'));
$output .= html_writer::start_tag('form', array('method' => 'POST', 'action' => $url));
$output .= html_writer::empty_tag('input', array('name' => 'upgradekey', 'type' => 'password'));
$output .= html_writer::empty_tag('input', array('value' => get_string('submit'), 'type' => 'submit'));
$output .= html_writer::end_tag('form');
$output .= $this->container_end();
$output .= $this->footer();
return $output;
}
|
[
"public",
"function",
"upgradekey_form_page",
"(",
"$",
"url",
")",
"{",
"$",
"output",
"=",
"''",
";",
"$",
"output",
".=",
"$",
"this",
"->",
"header",
"(",
")",
";",
"$",
"output",
".=",
"$",
"this",
"->",
"container_start",
"(",
"'upgradekeyreq'",
")",
";",
"$",
"output",
".=",
"$",
"this",
"->",
"heading",
"(",
"get_string",
"(",
"'upgradekeyreq'",
",",
"'core_admin'",
")",
")",
";",
"$",
"output",
".=",
"html_writer",
"::",
"start_tag",
"(",
"'form'",
",",
"array",
"(",
"'method'",
"=>",
"'POST'",
",",
"'action'",
"=>",
"$",
"url",
")",
")",
";",
"$",
"output",
".=",
"html_writer",
"::",
"empty_tag",
"(",
"'input'",
",",
"array",
"(",
"'name'",
"=>",
"'upgradekey'",
",",
"'type'",
"=>",
"'password'",
")",
")",
";",
"$",
"output",
".=",
"html_writer",
"::",
"empty_tag",
"(",
"'input'",
",",
"array",
"(",
"'value'",
"=>",
"get_string",
"(",
"'submit'",
")",
",",
"'type'",
"=>",
"'submit'",
")",
")",
";",
"$",
"output",
".=",
"html_writer",
"::",
"end_tag",
"(",
"'form'",
")",
";",
"$",
"output",
".=",
"$",
"this",
"->",
"container_end",
"(",
")",
";",
"$",
"output",
".=",
"$",
"this",
"->",
"footer",
"(",
")",
";",
"return",
"$",
"output",
";",
"}"
] |
Render a simple page for providing the upgrade key.
@param moodle_url|string $url
@return string
|
[
"Render",
"a",
"simple",
"page",
"for",
"providing",
"the",
"upgrade",
"key",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/renderer.php#L2076-L2090
|
219,118
|
moodle/moodle
|
admin/renderer.php
|
core_admin_renderer.legacy_log_store_writing_error
|
protected function legacy_log_store_writing_error() {
$enabled = get_config('logstore_legacy', 'loglegacy');
$plugins = explode(',', get_config('tool_log', 'enabled_stores'));
$enabled = $enabled && in_array('logstore_legacy', $plugins);
if ($enabled) {
return $this->warning(get_string('legacylogginginuse'));
}
}
|
php
|
protected function legacy_log_store_writing_error() {
$enabled = get_config('logstore_legacy', 'loglegacy');
$plugins = explode(',', get_config('tool_log', 'enabled_stores'));
$enabled = $enabled && in_array('logstore_legacy', $plugins);
if ($enabled) {
return $this->warning(get_string('legacylogginginuse'));
}
}
|
[
"protected",
"function",
"legacy_log_store_writing_error",
"(",
")",
"{",
"$",
"enabled",
"=",
"get_config",
"(",
"'logstore_legacy'",
",",
"'loglegacy'",
")",
";",
"$",
"plugins",
"=",
"explode",
"(",
"','",
",",
"get_config",
"(",
"'tool_log'",
",",
"'enabled_stores'",
")",
")",
";",
"$",
"enabled",
"=",
"$",
"enabled",
"&&",
"in_array",
"(",
"'logstore_legacy'",
",",
"$",
"plugins",
")",
";",
"if",
"(",
"$",
"enabled",
")",
"{",
"return",
"$",
"this",
"->",
"warning",
"(",
"get_string",
"(",
"'legacylogginginuse'",
")",
")",
";",
"}",
"}"
] |
Check to see if writing to the deprecated legacy log store is enabled.
@return string An error message if writing to the legacy log store is enabled.
|
[
"Check",
"to",
"see",
"if",
"writing",
"to",
"the",
"deprecated",
"legacy",
"log",
"store",
"is",
"enabled",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/renderer.php#L2097-L2105
|
219,119
|
moodle/moodle
|
admin/tool/monitor/classes/output/managesubs/rules.php
|
rules.col_select
|
public function col_select(\tool_monitor\rule $rule) {
global $OUTPUT;
$options = $rule->get_subscribe_options($this->courseid);
$text = get_string('subscribeto', 'tool_monitor', $rule->get_name($this->context));
if ($options instanceof \single_select) {
$options->set_label($text, array('class' => 'accesshide'));
return $OUTPUT->render($options);
} else if ($options instanceof \moodle_url) {
// A \moodle_url to subscribe.
$icon = $OUTPUT->pix_icon('t/add', $text);
$link = new \action_link($options, $icon);
return $OUTPUT->render($link);
} else {
return $options;
}
}
|
php
|
public function col_select(\tool_monitor\rule $rule) {
global $OUTPUT;
$options = $rule->get_subscribe_options($this->courseid);
$text = get_string('subscribeto', 'tool_monitor', $rule->get_name($this->context));
if ($options instanceof \single_select) {
$options->set_label($text, array('class' => 'accesshide'));
return $OUTPUT->render($options);
} else if ($options instanceof \moodle_url) {
// A \moodle_url to subscribe.
$icon = $OUTPUT->pix_icon('t/add', $text);
$link = new \action_link($options, $icon);
return $OUTPUT->render($link);
} else {
return $options;
}
}
|
[
"public",
"function",
"col_select",
"(",
"\\",
"tool_monitor",
"\\",
"rule",
"$",
"rule",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"$",
"options",
"=",
"$",
"rule",
"->",
"get_subscribe_options",
"(",
"$",
"this",
"->",
"courseid",
")",
";",
"$",
"text",
"=",
"get_string",
"(",
"'subscribeto'",
",",
"'tool_monitor'",
",",
"$",
"rule",
"->",
"get_name",
"(",
"$",
"this",
"->",
"context",
")",
")",
";",
"if",
"(",
"$",
"options",
"instanceof",
"\\",
"single_select",
")",
"{",
"$",
"options",
"->",
"set_label",
"(",
"$",
"text",
",",
"array",
"(",
"'class'",
"=>",
"'accesshide'",
")",
")",
";",
"return",
"$",
"OUTPUT",
"->",
"render",
"(",
"$",
"options",
")",
";",
"}",
"else",
"if",
"(",
"$",
"options",
"instanceof",
"\\",
"moodle_url",
")",
"{",
"// A \\moodle_url to subscribe.",
"$",
"icon",
"=",
"$",
"OUTPUT",
"->",
"pix_icon",
"(",
"'t/add'",
",",
"$",
"text",
")",
";",
"$",
"link",
"=",
"new",
"\\",
"action_link",
"(",
"$",
"options",
",",
"$",
"icon",
")",
";",
"return",
"$",
"OUTPUT",
"->",
"render",
"(",
"$",
"link",
")",
";",
"}",
"else",
"{",
"return",
"$",
"options",
";",
"}",
"}"
] |
Generate content for select column.
@param \tool_monitor\rule $rule rule object
@return string html used to display the select field.
|
[
"Generate",
"content",
"for",
"select",
"column",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/output/managesubs/rules.php#L165-L182
|
219,120
|
moodle/moodle
|
admin/tool/monitor/classes/output/managesubs/rules.php
|
rules.get_user_courses_select
|
public function get_user_courses_select($choose = false) {
$options = tool_monitor_get_user_courses();
// If we have no options then don't create a select element.
if (!$options) {
return false;
}
$selected = $this->courseid;
$nothing = array();
if ($choose) {
$selected = null;
$nothing = array('choosedots');
}
$url = new \moodle_url('/admin/tool/monitor/index.php');
$select = new \single_select($url, 'courseid', $options, $selected, $nothing);
$select->set_label(get_string('selectacourse', 'tool_monitor'));
return $select;
}
|
php
|
public function get_user_courses_select($choose = false) {
$options = tool_monitor_get_user_courses();
// If we have no options then don't create a select element.
if (!$options) {
return false;
}
$selected = $this->courseid;
$nothing = array();
if ($choose) {
$selected = null;
$nothing = array('choosedots');
}
$url = new \moodle_url('/admin/tool/monitor/index.php');
$select = new \single_select($url, 'courseid', $options, $selected, $nothing);
$select->set_label(get_string('selectacourse', 'tool_monitor'));
return $select;
}
|
[
"public",
"function",
"get_user_courses_select",
"(",
"$",
"choose",
"=",
"false",
")",
"{",
"$",
"options",
"=",
"tool_monitor_get_user_courses",
"(",
")",
";",
"// If we have no options then don't create a select element.",
"if",
"(",
"!",
"$",
"options",
")",
"{",
"return",
"false",
";",
"}",
"$",
"selected",
"=",
"$",
"this",
"->",
"courseid",
";",
"$",
"nothing",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"choose",
")",
"{",
"$",
"selected",
"=",
"null",
";",
"$",
"nothing",
"=",
"array",
"(",
"'choosedots'",
")",
";",
"}",
"$",
"url",
"=",
"new",
"\\",
"moodle_url",
"(",
"'/admin/tool/monitor/index.php'",
")",
";",
"$",
"select",
"=",
"new",
"\\",
"single_select",
"(",
"$",
"url",
",",
"'courseid'",
",",
"$",
"options",
",",
"$",
"selected",
",",
"$",
"nothing",
")",
";",
"$",
"select",
"->",
"set_label",
"(",
"get_string",
"(",
"'selectacourse'",
",",
"'tool_monitor'",
")",
")",
";",
"return",
"$",
"select",
";",
"}"
] |
Gets a list of courses where the current user can subscribe to rules as a dropdown.
@param bool $choose A flag for whether to show the 'choose...' option in the select box.
@return \single_select|bool returns the list of courses, or false if the select box
should not be displayed.
|
[
"Gets",
"a",
"list",
"of",
"courses",
"where",
"the",
"current",
"user",
"can",
"subscribe",
"to",
"rules",
"as",
"a",
"dropdown",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/output/managesubs/rules.php#L210-L226
|
219,121
|
moodle/moodle
|
admin/tool/usertours/classes/configuration.php
|
configuration.get_placement_options
|
public static function get_placement_options($default = null) {
$values = [
'top' => get_string('above', 'tool_usertours'),
'bottom' => get_string('below', 'tool_usertours'),
'left' => get_string('left', 'tool_usertours'),
'right' => get_string('right', 'tool_usertours'),
];
if ($default === null) {
return $values;
}
if (!isset($values[$default])) {
$default = self::get_default_value('placement');
}
$values = array_reverse($values, true);
$values[self::TOURDEFAULT] = get_string('defaultvalue', 'tool_usertours', $values[$default]);
$values = array_reverse($values, true);
return $values;
}
|
php
|
public static function get_placement_options($default = null) {
$values = [
'top' => get_string('above', 'tool_usertours'),
'bottom' => get_string('below', 'tool_usertours'),
'left' => get_string('left', 'tool_usertours'),
'right' => get_string('right', 'tool_usertours'),
];
if ($default === null) {
return $values;
}
if (!isset($values[$default])) {
$default = self::get_default_value('placement');
}
$values = array_reverse($values, true);
$values[self::TOURDEFAULT] = get_string('defaultvalue', 'tool_usertours', $values[$default]);
$values = array_reverse($values, true);
return $values;
}
|
[
"public",
"static",
"function",
"get_placement_options",
"(",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"values",
"=",
"[",
"'top'",
"=>",
"get_string",
"(",
"'above'",
",",
"'tool_usertours'",
")",
",",
"'bottom'",
"=>",
"get_string",
"(",
"'below'",
",",
"'tool_usertours'",
")",
",",
"'left'",
"=>",
"get_string",
"(",
"'left'",
",",
"'tool_usertours'",
")",
",",
"'right'",
"=>",
"get_string",
"(",
"'right'",
",",
"'tool_usertours'",
")",
",",
"]",
";",
"if",
"(",
"$",
"default",
"===",
"null",
")",
"{",
"return",
"$",
"values",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"values",
"[",
"$",
"default",
"]",
")",
")",
"{",
"$",
"default",
"=",
"self",
"::",
"get_default_value",
"(",
"'placement'",
")",
";",
"}",
"$",
"values",
"=",
"array_reverse",
"(",
"$",
"values",
",",
"true",
")",
";",
"$",
"values",
"[",
"self",
"::",
"TOURDEFAULT",
"]",
"=",
"get_string",
"(",
"'defaultvalue'",
",",
"'tool_usertours'",
",",
"$",
"values",
"[",
"$",
"default",
"]",
")",
";",
"$",
"values",
"=",
"array_reverse",
"(",
"$",
"values",
",",
"true",
")",
";",
"return",
"$",
"values",
";",
"}"
] |
Get the list of possible placement options.
@param string $default The default option.
@return array
|
[
"Get",
"the",
"list",
"of",
"possible",
"placement",
"options",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/configuration.php#L95-L116
|
219,122
|
moodle/moodle
|
lib/pear/HTML/QuickForm/element.php
|
HTML_QuickForm_element._generateId
|
function _generateId() {
if ($this->getAttribute('id')) {
return;
}
$id = $this->getName();
$id = 'id_' . str_replace(array('qf_', '[', ']'), array('', '_', ''), $id);
$id = clean_param($id, PARAM_ALPHANUMEXT);
$this->updateAttributes(array('id' => $id));
}
|
php
|
function _generateId() {
if ($this->getAttribute('id')) {
return;
}
$id = $this->getName();
$id = 'id_' . str_replace(array('qf_', '[', ']'), array('', '_', ''), $id);
$id = clean_param($id, PARAM_ALPHANUMEXT);
$this->updateAttributes(array('id' => $id));
}
|
[
"function",
"_generateId",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getAttribute",
"(",
"'id'",
")",
")",
"{",
"return",
";",
"}",
"$",
"id",
"=",
"$",
"this",
"->",
"getName",
"(",
")",
";",
"$",
"id",
"=",
"'id_'",
".",
"str_replace",
"(",
"array",
"(",
"'qf_'",
",",
"'['",
",",
"']'",
")",
",",
"array",
"(",
"''",
",",
"'_'",
",",
"''",
")",
",",
"$",
"id",
")",
";",
"$",
"id",
"=",
"clean_param",
"(",
"$",
"id",
",",
"PARAM_ALPHANUMEXT",
")",
";",
"$",
"this",
"->",
"updateAttributes",
"(",
"array",
"(",
"'id'",
"=>",
"$",
"id",
")",
")",
";",
"}"
] |
Automatically generates and assigns an 'id' attribute for the element.
Currently used to ensure that labels work on radio buttons and
checkboxes. Per idea of Alexander Radivanovich.
@access private
@return void
|
[
"Automatically",
"generates",
"and",
"assigns",
"an",
"id",
"attribute",
"for",
"the",
"element",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/element.php#L445-L454
|
219,123
|
moodle/moodle
|
lib/dtl/database_mover.php
|
database_mover.begin_database_export
|
public function begin_database_export($version, $release, $timestamp, $description) {
$this->feedback->output(get_string('copyingtables', 'core_dbtransfer'));
$this->importer->begin_database_import($version, $timestamp, $description);
}
|
php
|
public function begin_database_export($version, $release, $timestamp, $description) {
$this->feedback->output(get_string('copyingtables', 'core_dbtransfer'));
$this->importer->begin_database_import($version, $timestamp, $description);
}
|
[
"public",
"function",
"begin_database_export",
"(",
"$",
"version",
",",
"$",
"release",
",",
"$",
"timestamp",
",",
"$",
"description",
")",
"{",
"$",
"this",
"->",
"feedback",
"->",
"output",
"(",
"get_string",
"(",
"'copyingtables'",
",",
"'core_dbtransfer'",
")",
")",
";",
"$",
"this",
"->",
"importer",
"->",
"begin_database_import",
"(",
"$",
"version",
",",
"$",
"timestamp",
",",
"$",
"description",
")",
";",
"}"
] |
Callback function. Calls importer's begin_database_import callback method.
@param float $version the version of the system which generating the data
@param string $release moodle release info
@param string $timestamp the timestamp of the data (in ISO 8601) format.
@param string $description a user description of the data.
@return void
|
[
"Callback",
"function",
".",
"Calls",
"importer",
"s",
"begin_database_import",
"callback",
"method",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dtl/database_mover.php#L77-L80
|
219,124
|
moodle/moodle
|
lib/dtl/database_mover.php
|
database_mover.begin_table_export
|
public function begin_table_export(xmldb_table $table) {
$this->feedback->output(get_string('copyingtable', 'core_dbtransfer', $table->getName()), 1);
$this->importer->begin_table_import($table->getName(), $table->getHash());
}
|
php
|
public function begin_table_export(xmldb_table $table) {
$this->feedback->output(get_string('copyingtable', 'core_dbtransfer', $table->getName()), 1);
$this->importer->begin_table_import($table->getName(), $table->getHash());
}
|
[
"public",
"function",
"begin_table_export",
"(",
"xmldb_table",
"$",
"table",
")",
"{",
"$",
"this",
"->",
"feedback",
"->",
"output",
"(",
"get_string",
"(",
"'copyingtable'",
",",
"'core_dbtransfer'",
",",
"$",
"table",
"->",
"getName",
"(",
")",
")",
",",
"1",
")",
";",
"$",
"this",
"->",
"importer",
"->",
"begin_table_import",
"(",
"$",
"table",
"->",
"getName",
"(",
")",
",",
"$",
"table",
"->",
"getHash",
"(",
")",
")",
";",
"}"
] |
Callback function. Calls importer's begin_table_import callback method.
@param xmldb_table $table - XMLDB object for the exported table
@return void
|
[
"Callback",
"function",
".",
"Calls",
"importer",
"s",
"begin_table_import",
"callback",
"method",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dtl/database_mover.php#L88-L91
|
219,125
|
moodle/moodle
|
lib/dtl/database_mover.php
|
database_mover.export_table_data
|
public function export_table_data(xmldb_table $table, $data) {
$this->importer->import_table_data($table->getName(), $data);
}
|
php
|
public function export_table_data(xmldb_table $table, $data) {
$this->importer->import_table_data($table->getName(), $data);
}
|
[
"public",
"function",
"export_table_data",
"(",
"xmldb_table",
"$",
"table",
",",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"importer",
"->",
"import_table_data",
"(",
"$",
"table",
"->",
"getName",
"(",
")",
",",
"$",
"data",
")",
";",
"}"
] |
Callback function. Calls importer's import_table_data callback method.
@param xmldb_table $table - XMLDB object of the table from which data
was retrieved
@param object $data - data object (fields and values from record)
@return void
|
[
"Callback",
"function",
".",
"Calls",
"importer",
"s",
"import_table_data",
"callback",
"method",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dtl/database_mover.php#L101-L103
|
219,126
|
moodle/moodle
|
lib/dtl/database_mover.php
|
database_mover.finish_table_export
|
public function finish_table_export(xmldb_table $table) {
$this->feedback->output(get_string('done', 'core_dbtransfer', $table->getName()), 2);
$this->importer->finish_table_import($table->getName());
}
|
php
|
public function finish_table_export(xmldb_table $table) {
$this->feedback->output(get_string('done', 'core_dbtransfer', $table->getName()), 2);
$this->importer->finish_table_import($table->getName());
}
|
[
"public",
"function",
"finish_table_export",
"(",
"xmldb_table",
"$",
"table",
")",
"{",
"$",
"this",
"->",
"feedback",
"->",
"output",
"(",
"get_string",
"(",
"'done'",
",",
"'core_dbtransfer'",
",",
"$",
"table",
"->",
"getName",
"(",
")",
")",
",",
"2",
")",
";",
"$",
"this",
"->",
"importer",
"->",
"finish_table_import",
"(",
"$",
"table",
"->",
"getName",
"(",
")",
")",
";",
"}"
] |
Callback function. Calls importer's finish_table_import callback method.
@param xmldb_table $table - XMLDB object for the exported table
@return void
|
[
"Callback",
"function",
".",
"Calls",
"importer",
"s",
"finish_table_import",
"callback",
"method",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/dtl/database_mover.php#L110-L113
|
219,127
|
moodle/moodle
|
question/type/multianswer/backup/moodle2/restore_qtype_multianswer_plugin.class.php
|
restore_qtype_multianswer_plugin.recode_legacy_state_answer
|
public function recode_legacy_state_answer($state) {
global $DB;
$answer = $state->answer;
$resultarr = array();
// Get sequence of questions.
$sequence = $DB->get_field('question_multianswer', 'sequence',
array('question' => $state->question));
$sequencearr = explode(',', $sequence);
// Let's process each pair.
foreach (explode(',', $answer) as $pair) {
$pairarr = explode('-', $pair);
$sequenceid = $pairarr[0];
$subanswer = $pairarr[1];
// Calculate the questionid based on sequenceid.
// Note it is already one *new* questionid that doesn't need mapping.
$questionid = $sequencearr[$sequenceid - 1];
// Fetch qtype of the question (needed for delegation).
$questionqtype = $DB->get_field('question', 'qtype', array('id' => $questionid));
// Delegate subanswer recode to proper qtype, faking one question_states record.
$substate = new stdClass();
$substate->question = $questionid;
$substate->answer = $subanswer;
$newanswer = $this->step->restore_recode_legacy_answer($substate, $questionqtype);
$resultarr[] = implode('-', array($sequenceid, $newanswer));
}
return implode(',', $resultarr);
}
|
php
|
public function recode_legacy_state_answer($state) {
global $DB;
$answer = $state->answer;
$resultarr = array();
// Get sequence of questions.
$sequence = $DB->get_field('question_multianswer', 'sequence',
array('question' => $state->question));
$sequencearr = explode(',', $sequence);
// Let's process each pair.
foreach (explode(',', $answer) as $pair) {
$pairarr = explode('-', $pair);
$sequenceid = $pairarr[0];
$subanswer = $pairarr[1];
// Calculate the questionid based on sequenceid.
// Note it is already one *new* questionid that doesn't need mapping.
$questionid = $sequencearr[$sequenceid - 1];
// Fetch qtype of the question (needed for delegation).
$questionqtype = $DB->get_field('question', 'qtype', array('id' => $questionid));
// Delegate subanswer recode to proper qtype, faking one question_states record.
$substate = new stdClass();
$substate->question = $questionid;
$substate->answer = $subanswer;
$newanswer = $this->step->restore_recode_legacy_answer($substate, $questionqtype);
$resultarr[] = implode('-', array($sequenceid, $newanswer));
}
return implode(',', $resultarr);
}
|
[
"public",
"function",
"recode_legacy_state_answer",
"(",
"$",
"state",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"answer",
"=",
"$",
"state",
"->",
"answer",
";",
"$",
"resultarr",
"=",
"array",
"(",
")",
";",
"// Get sequence of questions.",
"$",
"sequence",
"=",
"$",
"DB",
"->",
"get_field",
"(",
"'question_multianswer'",
",",
"'sequence'",
",",
"array",
"(",
"'question'",
"=>",
"$",
"state",
"->",
"question",
")",
")",
";",
"$",
"sequencearr",
"=",
"explode",
"(",
"','",
",",
"$",
"sequence",
")",
";",
"// Let's process each pair.",
"foreach",
"(",
"explode",
"(",
"','",
",",
"$",
"answer",
")",
"as",
"$",
"pair",
")",
"{",
"$",
"pairarr",
"=",
"explode",
"(",
"'-'",
",",
"$",
"pair",
")",
";",
"$",
"sequenceid",
"=",
"$",
"pairarr",
"[",
"0",
"]",
";",
"$",
"subanswer",
"=",
"$",
"pairarr",
"[",
"1",
"]",
";",
"// Calculate the questionid based on sequenceid.",
"// Note it is already one *new* questionid that doesn't need mapping.",
"$",
"questionid",
"=",
"$",
"sequencearr",
"[",
"$",
"sequenceid",
"-",
"1",
"]",
";",
"// Fetch qtype of the question (needed for delegation).",
"$",
"questionqtype",
"=",
"$",
"DB",
"->",
"get_field",
"(",
"'question'",
",",
"'qtype'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"questionid",
")",
")",
";",
"// Delegate subanswer recode to proper qtype, faking one question_states record.",
"$",
"substate",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"substate",
"->",
"question",
"=",
"$",
"questionid",
";",
"$",
"substate",
"->",
"answer",
"=",
"$",
"subanswer",
";",
"$",
"newanswer",
"=",
"$",
"this",
"->",
"step",
"->",
"restore_recode_legacy_answer",
"(",
"$",
"substate",
",",
"$",
"questionqtype",
")",
";",
"$",
"resultarr",
"[",
"]",
"=",
"implode",
"(",
"'-'",
",",
"array",
"(",
"$",
"sequenceid",
",",
"$",
"newanswer",
")",
")",
";",
"}",
"return",
"implode",
"(",
"','",
",",
"$",
"resultarr",
")",
";",
"}"
] |
Given one question_states record, return the answer
recoded pointing to all the restored stuff for multianswer questions
answer is one comma separated list of hypen separated pairs
containing sequence (pointing to questions sequence in question_multianswer)
and mixed answers. We'll delegate
the recoding of answers to the proper qtype
|
[
"Given",
"one",
"question_states",
"record",
"return",
"the",
"answer",
"recoded",
"pointing",
"to",
"all",
"the",
"restored",
"stuff",
"for",
"multianswer",
"questions"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/multianswer/backup/moodle2/restore_qtype_multianswer_plugin.class.php#L174-L200
|
219,128
|
moodle/moodle
|
lib/classes/upgrade/util.php
|
util.can_use_tls12
|
public static function can_use_tls12(array $curlinfo, $uname) {
// Do not compare the cURL version, e.g. $curlinfo['version_number'], with v7.34.0 (467456):
// some Linux distros backport security issues and keep lower version numbers.
if (!defined('CURL_SSLVERSION_TLSv1_2')) {
return false;
}
$sslversion = explode('/', $curlinfo['ssl_version']);
// NSS has a space in the version number 😦.
$flavour = explode(' ', $sslversion[0])[0];
$version = count($sslversion) == 2 ? $sslversion[1] : null;
$minversion = self::get_min_ssl_lib_version_for_tls12($flavour);
if (!$minversion) {
return false;
}
// Special case (see $versionmatrix above).
if ($flavour == 'WinSSL') {
return $uname >= '6.1';
}
// Special case (see $versionmatrix above).
if ($flavour == 'SecureTransport') {
return $uname >= '10.8.0';
}
return $version >= $minversion;
}
|
php
|
public static function can_use_tls12(array $curlinfo, $uname) {
// Do not compare the cURL version, e.g. $curlinfo['version_number'], with v7.34.0 (467456):
// some Linux distros backport security issues and keep lower version numbers.
if (!defined('CURL_SSLVERSION_TLSv1_2')) {
return false;
}
$sslversion = explode('/', $curlinfo['ssl_version']);
// NSS has a space in the version number 😦.
$flavour = explode(' ', $sslversion[0])[0];
$version = count($sslversion) == 2 ? $sslversion[1] : null;
$minversion = self::get_min_ssl_lib_version_for_tls12($flavour);
if (!$minversion) {
return false;
}
// Special case (see $versionmatrix above).
if ($flavour == 'WinSSL') {
return $uname >= '6.1';
}
// Special case (see $versionmatrix above).
if ($flavour == 'SecureTransport') {
return $uname >= '10.8.0';
}
return $version >= $minversion;
}
|
[
"public",
"static",
"function",
"can_use_tls12",
"(",
"array",
"$",
"curlinfo",
",",
"$",
"uname",
")",
"{",
"// Do not compare the cURL version, e.g. $curlinfo['version_number'], with v7.34.0 (467456):",
"// some Linux distros backport security issues and keep lower version numbers.",
"if",
"(",
"!",
"defined",
"(",
"'CURL_SSLVERSION_TLSv1_2'",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"sslversion",
"=",
"explode",
"(",
"'/'",
",",
"$",
"curlinfo",
"[",
"'ssl_version'",
"]",
")",
";",
"// NSS has a space in the version number 😦.",
"$",
"flavour",
"=",
"explode",
"(",
"' '",
",",
"$",
"sslversion",
"[",
"0",
"]",
")",
"[",
"0",
"]",
";",
"$",
"version",
"=",
"count",
"(",
"$",
"sslversion",
")",
"==",
"2",
"?",
"$",
"sslversion",
"[",
"1",
"]",
":",
"null",
";",
"$",
"minversion",
"=",
"self",
"::",
"get_min_ssl_lib_version_for_tls12",
"(",
"$",
"flavour",
")",
";",
"if",
"(",
"!",
"$",
"minversion",
")",
"{",
"return",
"false",
";",
"}",
"// Special case (see $versionmatrix above).",
"if",
"(",
"$",
"flavour",
"==",
"'WinSSL'",
")",
"{",
"return",
"$",
"uname",
">=",
"'6.1'",
";",
"}",
"// Special case (see $versionmatrix above).",
"if",
"(",
"$",
"flavour",
"==",
"'SecureTransport'",
")",
"{",
"return",
"$",
"uname",
">=",
"'10.8.0'",
";",
"}",
"return",
"$",
"version",
">=",
"$",
"minversion",
";",
"}"
] |
Tests if the system is capable of using TLS 1.2 for requests.
@param array $curlinfo array of cURL information as returned by curl_version()
@param string $uname server uname
@return bool
|
[
"Tests",
"if",
"the",
"system",
"is",
"capable",
"of",
"using",
"TLS",
"1",
".",
"2",
"for",
"requests",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/upgrade/util.php#L88-L116
|
219,129
|
moodle/moodle
|
lib/google/src/Google/Auth/AssertionCredentials.php
|
Google_Auth_AssertionCredentials.getCacheKey
|
public function getCacheKey()
{
if (!$this->useCache) {
return false;
}
$h = $this->sub;
$h .= $this->assertionType;
$h .= $this->privateKey;
$h .= $this->scopes;
$h .= $this->serviceAccountName;
return md5($h);
}
|
php
|
public function getCacheKey()
{
if (!$this->useCache) {
return false;
}
$h = $this->sub;
$h .= $this->assertionType;
$h .= $this->privateKey;
$h .= $this->scopes;
$h .= $this->serviceAccountName;
return md5($h);
}
|
[
"public",
"function",
"getCacheKey",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"useCache",
")",
"{",
"return",
"false",
";",
"}",
"$",
"h",
"=",
"$",
"this",
"->",
"sub",
";",
"$",
"h",
".=",
"$",
"this",
"->",
"assertionType",
";",
"$",
"h",
".=",
"$",
"this",
"->",
"privateKey",
";",
"$",
"h",
".=",
"$",
"this",
"->",
"scopes",
";",
"$",
"h",
".=",
"$",
"this",
"->",
"serviceAccountName",
";",
"return",
"md5",
"(",
"$",
"h",
")",
";",
"}"
] |
Generate a unique key to represent this credential.
@return string
|
[
"Generate",
"a",
"unique",
"key",
"to",
"represent",
"this",
"credential",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/google/src/Google/Auth/AssertionCredentials.php#L76-L87
|
219,130
|
moodle/moodle
|
lib/adodb/adodb-xmlschema.inc.php
|
dbTable._tag_cdata
|
function _tag_cdata( &$parser, $cdata ) {
switch( $this->currentElement ) {
// Table constraint
case 'CONSTRAINT':
if( isset( $this->current_field ) ) {
$this->addFieldOpt( $this->current_field, $this->currentElement, $cdata );
} else {
$this->addTableOpt( $cdata );
}
break;
// Table option
case 'OPT':
$this->addTableOpt( $cdata );
break;
default:
}
}
|
php
|
function _tag_cdata( &$parser, $cdata ) {
switch( $this->currentElement ) {
// Table constraint
case 'CONSTRAINT':
if( isset( $this->current_field ) ) {
$this->addFieldOpt( $this->current_field, $this->currentElement, $cdata );
} else {
$this->addTableOpt( $cdata );
}
break;
// Table option
case 'OPT':
$this->addTableOpt( $cdata );
break;
default:
}
}
|
[
"function",
"_tag_cdata",
"(",
"&",
"$",
"parser",
",",
"$",
"cdata",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"currentElement",
")",
"{",
"// Table constraint",
"case",
"'CONSTRAINT'",
":",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"current_field",
")",
")",
"{",
"$",
"this",
"->",
"addFieldOpt",
"(",
"$",
"this",
"->",
"current_field",
",",
"$",
"this",
"->",
"currentElement",
",",
"$",
"cdata",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"addTableOpt",
"(",
"$",
"cdata",
")",
";",
"}",
"break",
";",
"// Table option",
"case",
"'OPT'",
":",
"$",
"this",
"->",
"addTableOpt",
"(",
"$",
"cdata",
")",
";",
"break",
";",
"default",
":",
"}",
"}"
] |
XML Callback to process CDATA elements
@access private
|
[
"XML",
"Callback",
"to",
"process",
"CDATA",
"elements"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-xmlschema.inc.php#L320-L337
|
219,131
|
moodle/moodle
|
backup/externallib.php
|
core_backup_external.get_async_backup_progress
|
public static function get_async_backup_progress($backupids, $contextid) {
global $CFG;
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
// Parameter validation.
self::validate_parameters(
self::get_async_backup_progress_parameters(),
array(
'backupids' => $backupids,
'contextid' => $contextid
)
);
// Context validation.
list($context, $course, $cm) = get_context_info_array($contextid);
self::validate_context($context);
if ($cm) {
require_capability('moodle/backup:backupactivity', $context);
} else {
require_capability('moodle/backup:backupcourse', $context);
$instanceid = $course->id;
}
$results = array();
foreach ($backupids as $backupid) {
$results[] = backup_controller_dbops::get_progress($backupid);
}
return $results;
}
|
php
|
public static function get_async_backup_progress($backupids, $contextid) {
global $CFG;
require_once($CFG->dirroot . '/backup/util/includes/backup_includes.php');
require_once($CFG->dirroot . '/backup/util/includes/restore_includes.php');
// Parameter validation.
self::validate_parameters(
self::get_async_backup_progress_parameters(),
array(
'backupids' => $backupids,
'contextid' => $contextid
)
);
// Context validation.
list($context, $course, $cm) = get_context_info_array($contextid);
self::validate_context($context);
if ($cm) {
require_capability('moodle/backup:backupactivity', $context);
} else {
require_capability('moodle/backup:backupcourse', $context);
$instanceid = $course->id;
}
$results = array();
foreach ($backupids as $backupid) {
$results[] = backup_controller_dbops::get_progress($backupid);
}
return $results;
}
|
[
"public",
"static",
"function",
"get_async_backup_progress",
"(",
"$",
"backupids",
",",
"$",
"contextid",
")",
"{",
"global",
"$",
"CFG",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/backup/util/includes/backup_includes.php'",
")",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/backup/util/includes/restore_includes.php'",
")",
";",
"// Parameter validation.",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_async_backup_progress_parameters",
"(",
")",
",",
"array",
"(",
"'backupids'",
"=>",
"$",
"backupids",
",",
"'contextid'",
"=>",
"$",
"contextid",
")",
")",
";",
"// Context validation.",
"list",
"(",
"$",
"context",
",",
"$",
"course",
",",
"$",
"cm",
")",
"=",
"get_context_info_array",
"(",
"$",
"contextid",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"if",
"(",
"$",
"cm",
")",
"{",
"require_capability",
"(",
"'moodle/backup:backupactivity'",
",",
"$",
"context",
")",
";",
"}",
"else",
"{",
"require_capability",
"(",
"'moodle/backup:backupcourse'",
",",
"$",
"context",
")",
";",
"$",
"instanceid",
"=",
"$",
"course",
"->",
"id",
";",
"}",
"$",
"results",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"backupids",
"as",
"$",
"backupid",
")",
"{",
"$",
"results",
"[",
"]",
"=",
"backup_controller_dbops",
"::",
"get_progress",
"(",
"$",
"backupid",
")",
";",
"}",
"return",
"$",
"results",
";",
"}"
] |
Get asynchronous backup progress.
@param string $backupids The ids of the backup to get progress for.
@param int $contextid The context the backup relates to.
@return array $results The array of results.
@since Moodle 3.7
|
[
"Get",
"asynchronous",
"backup",
"progress",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/externallib.php#L69-L100
|
219,132
|
moodle/moodle
|
backup/externallib.php
|
core_backup_external.get_async_backup_links_backup
|
public static function get_async_backup_links_backup($filename, $contextid) {
// Parameter validation.
self::validate_parameters(
self::get_async_backup_links_backup_parameters(),
array(
'filename' => $filename,
'contextid' => $contextid
)
);
// Context validation.
list($context, $course, $cm) = get_context_info_array($contextid);
self::validate_context($context);
require_capability('moodle/backup:backupcourse', $context);
if ($cm) {
$filearea = 'activity';
} else {
$filearea = 'course';
}
$results = \async_helper::get_backup_file_info($filename, $filearea, $contextid);
return $results;
}
|
php
|
public static function get_async_backup_links_backup($filename, $contextid) {
// Parameter validation.
self::validate_parameters(
self::get_async_backup_links_backup_parameters(),
array(
'filename' => $filename,
'contextid' => $contextid
)
);
// Context validation.
list($context, $course, $cm) = get_context_info_array($contextid);
self::validate_context($context);
require_capability('moodle/backup:backupcourse', $context);
if ($cm) {
$filearea = 'activity';
} else {
$filearea = 'course';
}
$results = \async_helper::get_backup_file_info($filename, $filearea, $contextid);
return $results;
}
|
[
"public",
"static",
"function",
"get_async_backup_links_backup",
"(",
"$",
"filename",
",",
"$",
"contextid",
")",
"{",
"// Parameter validation.",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_async_backup_links_backup_parameters",
"(",
")",
",",
"array",
"(",
"'filename'",
"=>",
"$",
"filename",
",",
"'contextid'",
"=>",
"$",
"contextid",
")",
")",
";",
"// Context validation.",
"list",
"(",
"$",
"context",
",",
"$",
"course",
",",
"$",
"cm",
")",
"=",
"get_context_info_array",
"(",
"$",
"contextid",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"require_capability",
"(",
"'moodle/backup:backupcourse'",
",",
"$",
"context",
")",
";",
"if",
"(",
"$",
"cm",
")",
"{",
"$",
"filearea",
"=",
"'activity'",
";",
"}",
"else",
"{",
"$",
"filearea",
"=",
"'course'",
";",
"}",
"$",
"results",
"=",
"\\",
"async_helper",
"::",
"get_backup_file_info",
"(",
"$",
"filename",
",",
"$",
"filearea",
",",
"$",
"contextid",
")",
";",
"return",
"$",
"results",
";",
"}"
] |
Get the data to be used when generating the table row for an asynchronous backup,
the table row updates via ajax when backup is complete.
@param string $filename The file name of the backup file.
@param int $contextid The context the backup relates to.
@since Moodle 3.7
|
[
"Get",
"the",
"data",
"to",
"be",
"used",
"when",
"generating",
"the",
"table",
"row",
"for",
"an",
"asynchronous",
"backup",
"the",
"table",
"row",
"updates",
"via",
"ajax",
"when",
"backup",
"is",
"complete",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/externallib.php#L144-L168
|
219,133
|
moodle/moodle
|
backup/externallib.php
|
core_backup_external.get_async_backup_links_restore
|
public static function get_async_backup_links_restore($backupid, $contextid) {
// Parameter validation.
self::validate_parameters(
self::get_async_backup_links_restore_parameters(),
array(
'backupid' => $backupid,
'contextid' => $contextid
)
);
// Context validation.
$context = context::instance_by_id($contextid);
self::validate_context($context);
require_capability('moodle/restore:restorecourse', $context);
$results = \async_helper::get_restore_url($backupid);
return $results;
}
|
php
|
public static function get_async_backup_links_restore($backupid, $contextid) {
// Parameter validation.
self::validate_parameters(
self::get_async_backup_links_restore_parameters(),
array(
'backupid' => $backupid,
'contextid' => $contextid
)
);
// Context validation.
$context = context::instance_by_id($contextid);
self::validate_context($context);
require_capability('moodle/restore:restorecourse', $context);
$results = \async_helper::get_restore_url($backupid);
return $results;
}
|
[
"public",
"static",
"function",
"get_async_backup_links_restore",
"(",
"$",
"backupid",
",",
"$",
"contextid",
")",
"{",
"// Parameter validation.",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_async_backup_links_restore_parameters",
"(",
")",
",",
"array",
"(",
"'backupid'",
"=>",
"$",
"backupid",
",",
"'contextid'",
"=>",
"$",
"contextid",
")",
")",
";",
"// Context validation.",
"$",
"context",
"=",
"context",
"::",
"instance_by_id",
"(",
"$",
"contextid",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"require_capability",
"(",
"'moodle/restore:restorecourse'",
",",
"$",
"context",
")",
";",
"$",
"results",
"=",
"\\",
"async_helper",
"::",
"get_restore_url",
"(",
"$",
"backupid",
")",
";",
"return",
"$",
"results",
";",
"}"
] |
Get the data to be used when generating the table row for an asynchronous restore,
the table row updates via ajax when restore is complete.
@param string $backupid The id of the backup record.
@param int $contextid The context the restore relates to.
@return array $results The array of results.
@since Moodle 3.7
|
[
"Get",
"the",
"data",
"to",
"be",
"used",
"when",
"generating",
"the",
"table",
"row",
"for",
"an",
"asynchronous",
"restore",
"the",
"table",
"row",
"updates",
"via",
"ajax",
"when",
"restore",
"is",
"complete",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/externallib.php#L208-L226
|
219,134
|
moodle/moodle
|
course/format/weeks/classes/observer.php
|
format_weeks_observer.course_updated
|
public static function course_updated(\core\event\course_updated $event) {
if (class_exists('format_weeks', false)) {
// If class format_weeks was never loaded, this is definitely not a course in 'weeks' format.
// Course may still be in another format but format_weeks::update_end_date() will check it.
format_weeks::update_end_date($event->courseid);
}
}
|
php
|
public static function course_updated(\core\event\course_updated $event) {
if (class_exists('format_weeks', false)) {
// If class format_weeks was never loaded, this is definitely not a course in 'weeks' format.
// Course may still be in another format but format_weeks::update_end_date() will check it.
format_weeks::update_end_date($event->courseid);
}
}
|
[
"public",
"static",
"function",
"course_updated",
"(",
"\\",
"core",
"\\",
"event",
"\\",
"course_updated",
"$",
"event",
")",
"{",
"if",
"(",
"class_exists",
"(",
"'format_weeks'",
",",
"false",
")",
")",
"{",
"// If class format_weeks was never loaded, this is definitely not a course in 'weeks' format.",
"// Course may still be in another format but format_weeks::update_end_date() will check it.",
"format_weeks",
"::",
"update_end_date",
"(",
"$",
"event",
"->",
"courseid",
")",
";",
"}",
"}"
] |
Triggered via \core\event\course_updated event.
@param \core\event\course_updated $event
|
[
"Triggered",
"via",
"\\",
"core",
"\\",
"event",
"\\",
"course_updated",
"event",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/weeks/classes/observer.php#L41-L47
|
219,135
|
moodle/moodle
|
course/format/weeks/classes/observer.php
|
format_weeks_observer.course_section_created
|
public static function course_section_created(\core\event\course_section_created $event) {
if (class_exists('format_weeks', false)) {
// If class format_weeks was never loaded, this is definitely not a course in 'weeks' format.
// Course may still be in another format but format_weeks::update_end_date() will check it.
format_weeks::update_end_date($event->courseid);
}
}
|
php
|
public static function course_section_created(\core\event\course_section_created $event) {
if (class_exists('format_weeks', false)) {
// If class format_weeks was never loaded, this is definitely not a course in 'weeks' format.
// Course may still be in another format but format_weeks::update_end_date() will check it.
format_weeks::update_end_date($event->courseid);
}
}
|
[
"public",
"static",
"function",
"course_section_created",
"(",
"\\",
"core",
"\\",
"event",
"\\",
"course_section_created",
"$",
"event",
")",
"{",
"if",
"(",
"class_exists",
"(",
"'format_weeks'",
",",
"false",
")",
")",
"{",
"// If class format_weeks was never loaded, this is definitely not a course in 'weeks' format.",
"// Course may still be in another format but format_weeks::update_end_date() will check it.",
"format_weeks",
"::",
"update_end_date",
"(",
"$",
"event",
"->",
"courseid",
")",
";",
"}",
"}"
] |
Triggered via \core\event\course_section_created event.
@param \core\event\course_section_created $event
|
[
"Triggered",
"via",
"\\",
"core",
"\\",
"event",
"\\",
"course_section_created",
"event",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/weeks/classes/observer.php#L54-L60
|
219,136
|
moodle/moodle
|
course/format/weeks/classes/observer.php
|
format_weeks_observer.course_section_deleted
|
public static function course_section_deleted(\core\event\course_section_deleted $event) {
if (class_exists('format_weeks', false)) {
// If class format_weeks was never loaded, this is definitely not a course in 'weeks' format.
// Course may still be in another format but format_weeks::update_end_date() will check it.
format_weeks::update_end_date($event->courseid);
}
}
|
php
|
public static function course_section_deleted(\core\event\course_section_deleted $event) {
if (class_exists('format_weeks', false)) {
// If class format_weeks was never loaded, this is definitely not a course in 'weeks' format.
// Course may still be in another format but format_weeks::update_end_date() will check it.
format_weeks::update_end_date($event->courseid);
}
}
|
[
"public",
"static",
"function",
"course_section_deleted",
"(",
"\\",
"core",
"\\",
"event",
"\\",
"course_section_deleted",
"$",
"event",
")",
"{",
"if",
"(",
"class_exists",
"(",
"'format_weeks'",
",",
"false",
")",
")",
"{",
"// If class format_weeks was never loaded, this is definitely not a course in 'weeks' format.",
"// Course may still be in another format but format_weeks::update_end_date() will check it.",
"format_weeks",
"::",
"update_end_date",
"(",
"$",
"event",
"->",
"courseid",
")",
";",
"}",
"}"
] |
Triggered via \core\event\course_section_deleted event.
@param \core\event\course_section_deleted $event
|
[
"Triggered",
"via",
"\\",
"core",
"\\",
"event",
"\\",
"course_section_deleted",
"event",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/weeks/classes/observer.php#L67-L73
|
219,137
|
moodle/moodle
|
lib/classes/update/validator.php
|
validator.execute
|
public function execute() {
$this->result = (
$this->validate_files_layout()
and $this->validate_version_php()
and $this->validate_language_pack()
and $this->validate_target_location()
);
return $this->result;
}
|
php
|
public function execute() {
$this->result = (
$this->validate_files_layout()
and $this->validate_version_php()
and $this->validate_language_pack()
and $this->validate_target_location()
);
return $this->result;
}
|
[
"public",
"function",
"execute",
"(",
")",
"{",
"$",
"this",
"->",
"result",
"=",
"(",
"$",
"this",
"->",
"validate_files_layout",
"(",
")",
"and",
"$",
"this",
"->",
"validate_version_php",
"(",
")",
"and",
"$",
"this",
"->",
"validate_language_pack",
"(",
")",
"and",
"$",
"this",
"->",
"validate_target_location",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"result",
";",
"}"
] |
Execute the validation process against all explicit and implicit requirements
Returns true if the validation passes (all explicit and implicit requirements
pass) and the plugin can be installed. Returns false if the validation fails
(some explicit or implicit requirement fails) and the plugin must not be
installed.
@return bool
|
[
"Execute",
"the",
"validation",
"process",
"against",
"all",
"explicit",
"and",
"implicit",
"requirements"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/validator.php#L127-L137
|
219,138
|
moodle/moodle
|
lib/classes/update/validator.php
|
validator.message_code_name
|
public function message_code_name($msgcode) {
$stringman = get_string_manager();
if ($stringman->string_exists('validationmsg_'.$msgcode, 'core_plugin')) {
return get_string('validationmsg_'.$msgcode, 'core_plugin');
}
return $msgcode;
}
|
php
|
public function message_code_name($msgcode) {
$stringman = get_string_manager();
if ($stringman->string_exists('validationmsg_'.$msgcode, 'core_plugin')) {
return get_string('validationmsg_'.$msgcode, 'core_plugin');
}
return $msgcode;
}
|
[
"public",
"function",
"message_code_name",
"(",
"$",
"msgcode",
")",
"{",
"$",
"stringman",
"=",
"get_string_manager",
"(",
")",
";",
"if",
"(",
"$",
"stringman",
"->",
"string_exists",
"(",
"'validationmsg_'",
".",
"$",
"msgcode",
",",
"'core_plugin'",
")",
")",
"{",
"return",
"get_string",
"(",
"'validationmsg_'",
".",
"$",
"msgcode",
",",
"'core_plugin'",
")",
";",
"}",
"return",
"$",
"msgcode",
";",
"}"
] |
If defined, returns human readable validation code.
Otherwise, it simply returns the code itself as a fallback.
@param string $msgcode
@return string
|
[
"If",
"defined",
"returns",
"human",
"readable",
"validation",
"code",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/validator.php#L182-L191
|
219,139
|
moodle/moodle
|
lib/classes/update/validator.php
|
validator.message_help_icon
|
public function message_help_icon($msgcode) {
$stringman = get_string_manager();
if ($stringman->string_exists('validationmsg_'.$msgcode.'_help', 'core_plugin')) {
return new help_icon('validationmsg_'.$msgcode, 'core_plugin');
}
return false;
}
|
php
|
public function message_help_icon($msgcode) {
$stringman = get_string_manager();
if ($stringman->string_exists('validationmsg_'.$msgcode.'_help', 'core_plugin')) {
return new help_icon('validationmsg_'.$msgcode, 'core_plugin');
}
return false;
}
|
[
"public",
"function",
"message_help_icon",
"(",
"$",
"msgcode",
")",
"{",
"$",
"stringman",
"=",
"get_string_manager",
"(",
")",
";",
"if",
"(",
"$",
"stringman",
"->",
"string_exists",
"(",
"'validationmsg_'",
".",
"$",
"msgcode",
".",
"'_help'",
",",
"'core_plugin'",
")",
")",
"{",
"return",
"new",
"help_icon",
"(",
"'validationmsg_'",
".",
"$",
"msgcode",
",",
"'core_plugin'",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Returns help icon for the message code if defined.
@param string $msgcode
@return \help_icon|false
|
[
"Returns",
"help",
"icon",
"for",
"the",
"message",
"code",
"if",
"defined",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/validator.php#L199-L208
|
219,140
|
moodle/moodle
|
lib/classes/update/validator.php
|
validator.message_code_info
|
public function message_code_info($msgcode, $addinfo) {
$stringman = get_string_manager();
if ($addinfo !== null and $stringman->string_exists('validationmsg_'.$msgcode.'_info', 'core_plugin')) {
return get_string('validationmsg_'.$msgcode.'_info', 'core_plugin', $addinfo);
}
return '';
}
|
php
|
public function message_code_info($msgcode, $addinfo) {
$stringman = get_string_manager();
if ($addinfo !== null and $stringman->string_exists('validationmsg_'.$msgcode.'_info', 'core_plugin')) {
return get_string('validationmsg_'.$msgcode.'_info', 'core_plugin', $addinfo);
}
return '';
}
|
[
"public",
"function",
"message_code_info",
"(",
"$",
"msgcode",
",",
"$",
"addinfo",
")",
"{",
"$",
"stringman",
"=",
"get_string_manager",
"(",
")",
";",
"if",
"(",
"$",
"addinfo",
"!==",
"null",
"and",
"$",
"stringman",
"->",
"string_exists",
"(",
"'validationmsg_'",
".",
"$",
"msgcode",
".",
"'_info'",
",",
"'core_plugin'",
")",
")",
"{",
"return",
"get_string",
"(",
"'validationmsg_'",
".",
"$",
"msgcode",
".",
"'_info'",
",",
"'core_plugin'",
",",
"$",
"addinfo",
")",
";",
"}",
"return",
"''",
";",
"}"
] |
Localizes the message additional info if it exists.
@param string $msgcode
@param array|string|null $addinfo value for the $a placeholder in the string
@return string
|
[
"Localizes",
"the",
"message",
"additional",
"info",
"if",
"it",
"exists",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/validator.php#L217-L226
|
219,141
|
moodle/moodle
|
lib/classes/update/validator.php
|
validator.validate_files_layout
|
protected function validate_files_layout() {
if (!is_array($this->extractfiles) or count($this->extractfiles) < 4) {
// We need the English language pack with the name of the plugin at least.
$this->add_message(self::ERROR, 'filesnumber');
return false;
}
foreach ($this->extractfiles as $filerelname => $filestatus) {
if ($filestatus !== true) {
$this->add_message(self::ERROR, 'filestatus', array('file' => $filerelname, 'status' => $filestatus));
return false;
}
}
foreach (array_keys($this->extractfiles) as $filerelname) {
if (!file_exists($this->extractdir.'/'.$filerelname)) {
$this->add_message(self::ERROR, 'filenotexists', array('file' => $filerelname));
return false;
}
}
foreach (array_keys($this->extractfiles) as $filerelname) {
$matches = array();
if (!preg_match("#^([^/]+)/#", $filerelname, $matches)
or (!is_null($this->rootdir) and $this->rootdir !== $matches[1])) {
$this->add_message(self::ERROR, 'onedir');
return false;
}
$this->rootdir = $matches[1];
}
if ($this->rootdir !== clean_param($this->rootdir, PARAM_PLUGIN)) {
$this->add_message(self::ERROR, 'rootdirinvalid', $this->rootdir);
return false;
} else {
$this->add_message(self::INFO, 'rootdir', $this->rootdir);
}
return is_dir($this->extractdir.'/'.$this->rootdir);
}
|
php
|
protected function validate_files_layout() {
if (!is_array($this->extractfiles) or count($this->extractfiles) < 4) {
// We need the English language pack with the name of the plugin at least.
$this->add_message(self::ERROR, 'filesnumber');
return false;
}
foreach ($this->extractfiles as $filerelname => $filestatus) {
if ($filestatus !== true) {
$this->add_message(self::ERROR, 'filestatus', array('file' => $filerelname, 'status' => $filestatus));
return false;
}
}
foreach (array_keys($this->extractfiles) as $filerelname) {
if (!file_exists($this->extractdir.'/'.$filerelname)) {
$this->add_message(self::ERROR, 'filenotexists', array('file' => $filerelname));
return false;
}
}
foreach (array_keys($this->extractfiles) as $filerelname) {
$matches = array();
if (!preg_match("#^([^/]+)/#", $filerelname, $matches)
or (!is_null($this->rootdir) and $this->rootdir !== $matches[1])) {
$this->add_message(self::ERROR, 'onedir');
return false;
}
$this->rootdir = $matches[1];
}
if ($this->rootdir !== clean_param($this->rootdir, PARAM_PLUGIN)) {
$this->add_message(self::ERROR, 'rootdirinvalid', $this->rootdir);
return false;
} else {
$this->add_message(self::INFO, 'rootdir', $this->rootdir);
}
return is_dir($this->extractdir.'/'.$this->rootdir);
}
|
[
"protected",
"function",
"validate_files_layout",
"(",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"extractfiles",
")",
"or",
"count",
"(",
"$",
"this",
"->",
"extractfiles",
")",
"<",
"4",
")",
"{",
"// We need the English language pack with the name of the plugin at least.",
"$",
"this",
"->",
"add_message",
"(",
"self",
"::",
"ERROR",
",",
"'filesnumber'",
")",
";",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"extractfiles",
"as",
"$",
"filerelname",
"=>",
"$",
"filestatus",
")",
"{",
"if",
"(",
"$",
"filestatus",
"!==",
"true",
")",
"{",
"$",
"this",
"->",
"add_message",
"(",
"self",
"::",
"ERROR",
",",
"'filestatus'",
",",
"array",
"(",
"'file'",
"=>",
"$",
"filerelname",
",",
"'status'",
"=>",
"$",
"filestatus",
")",
")",
";",
"return",
"false",
";",
"}",
"}",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"extractfiles",
")",
"as",
"$",
"filerelname",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"extractdir",
".",
"'/'",
".",
"$",
"filerelname",
")",
")",
"{",
"$",
"this",
"->",
"add_message",
"(",
"self",
"::",
"ERROR",
",",
"'filenotexists'",
",",
"array",
"(",
"'file'",
"=>",
"$",
"filerelname",
")",
")",
";",
"return",
"false",
";",
"}",
"}",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"extractfiles",
")",
"as",
"$",
"filerelname",
")",
"{",
"$",
"matches",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"preg_match",
"(",
"\"#^([^/]+)/#\"",
",",
"$",
"filerelname",
",",
"$",
"matches",
")",
"or",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"rootdir",
")",
"and",
"$",
"this",
"->",
"rootdir",
"!==",
"$",
"matches",
"[",
"1",
"]",
")",
")",
"{",
"$",
"this",
"->",
"add_message",
"(",
"self",
"::",
"ERROR",
",",
"'onedir'",
")",
";",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"rootdir",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"rootdir",
"!==",
"clean_param",
"(",
"$",
"this",
"->",
"rootdir",
",",
"PARAM_PLUGIN",
")",
")",
"{",
"$",
"this",
"->",
"add_message",
"(",
"self",
"::",
"ERROR",
",",
"'rootdirinvalid'",
",",
"$",
"this",
"->",
"rootdir",
")",
";",
"return",
"false",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"add_message",
"(",
"self",
"::",
"INFO",
",",
"'rootdir'",
",",
"$",
"this",
"->",
"rootdir",
")",
";",
"}",
"return",
"is_dir",
"(",
"$",
"this",
"->",
"extractdir",
".",
"'/'",
".",
"$",
"this",
"->",
"rootdir",
")",
";",
"}"
] |
Returns false if files in the ZIP do not have required layout.
@return bool
|
[
"Returns",
"false",
"if",
"files",
"in",
"the",
"ZIP",
"do",
"not",
"have",
"required",
"layout",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/validator.php#L283-L323
|
219,142
|
moodle/moodle
|
lib/classes/update/validator.php
|
validator.validate_language_pack
|
protected function validate_language_pack() {
if (!isset($this->assertions['plugintype'])) {
throw new coding_exception('Required plugin type must be set before calling this');
}
if (!isset($this->extractfiles[$this->rootdir.'/lang/en/'])
or $this->extractfiles[$this->rootdir.'/lang/en/'] !== true
or !is_dir($this->extractdir.'/'.$this->rootdir.'/lang/en')) {
$this->add_message(self::ERROR, 'missinglangenfolder');
return false;
}
$langfiles = array();
foreach (array_keys($this->extractfiles) as $extractfile) {
$matches = array();
if (preg_match('#^'.preg_quote($this->rootdir).'/lang/en/([^/]+).php?$#i', $extractfile, $matches)) {
$langfiles[] = $matches[1];
}
}
if (empty($langfiles)) {
$this->add_message(self::ERROR, 'missinglangenfile');
return false;
} else if (count($langfiles) > 1) {
$this->add_message(self::WARNING, 'multiplelangenfiles');
} else {
$this->langfilename = $langfiles[0];
$this->add_message(self::DEBUG, 'foundlangfile', $this->langfilename);
}
if ($this->assertions['plugintype'] === 'mod') {
$expected = $this->rootdir.'.php';
} else {
$expected = $this->assertions['plugintype'].'_'.$this->rootdir.'.php';
}
if (!isset($this->extractfiles[$this->rootdir.'/lang/en/'.$expected])
or $this->extractfiles[$this->rootdir.'/lang/en/'.$expected] !== true
or !is_file($this->extractdir.'/'.$this->rootdir.'/lang/en/'.$expected)) {
$this->add_message(self::ERROR, 'missingexpectedlangenfile', $expected);
return false;
}
return true;
}
|
php
|
protected function validate_language_pack() {
if (!isset($this->assertions['plugintype'])) {
throw new coding_exception('Required plugin type must be set before calling this');
}
if (!isset($this->extractfiles[$this->rootdir.'/lang/en/'])
or $this->extractfiles[$this->rootdir.'/lang/en/'] !== true
or !is_dir($this->extractdir.'/'.$this->rootdir.'/lang/en')) {
$this->add_message(self::ERROR, 'missinglangenfolder');
return false;
}
$langfiles = array();
foreach (array_keys($this->extractfiles) as $extractfile) {
$matches = array();
if (preg_match('#^'.preg_quote($this->rootdir).'/lang/en/([^/]+).php?$#i', $extractfile, $matches)) {
$langfiles[] = $matches[1];
}
}
if (empty($langfiles)) {
$this->add_message(self::ERROR, 'missinglangenfile');
return false;
} else if (count($langfiles) > 1) {
$this->add_message(self::WARNING, 'multiplelangenfiles');
} else {
$this->langfilename = $langfiles[0];
$this->add_message(self::DEBUG, 'foundlangfile', $this->langfilename);
}
if ($this->assertions['plugintype'] === 'mod') {
$expected = $this->rootdir.'.php';
} else {
$expected = $this->assertions['plugintype'].'_'.$this->rootdir.'.php';
}
if (!isset($this->extractfiles[$this->rootdir.'/lang/en/'.$expected])
or $this->extractfiles[$this->rootdir.'/lang/en/'.$expected] !== true
or !is_file($this->extractdir.'/'.$this->rootdir.'/lang/en/'.$expected)) {
$this->add_message(self::ERROR, 'missingexpectedlangenfile', $expected);
return false;
}
return true;
}
|
[
"protected",
"function",
"validate_language_pack",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"assertions",
"[",
"'plugintype'",
"]",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Required plugin type must be set before calling this'",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"extractfiles",
"[",
"$",
"this",
"->",
"rootdir",
".",
"'/lang/en/'",
"]",
")",
"or",
"$",
"this",
"->",
"extractfiles",
"[",
"$",
"this",
"->",
"rootdir",
".",
"'/lang/en/'",
"]",
"!==",
"true",
"or",
"!",
"is_dir",
"(",
"$",
"this",
"->",
"extractdir",
".",
"'/'",
".",
"$",
"this",
"->",
"rootdir",
".",
"'/lang/en'",
")",
")",
"{",
"$",
"this",
"->",
"add_message",
"(",
"self",
"::",
"ERROR",
",",
"'missinglangenfolder'",
")",
";",
"return",
"false",
";",
"}",
"$",
"langfiles",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"extractfiles",
")",
"as",
"$",
"extractfile",
")",
"{",
"$",
"matches",
"=",
"array",
"(",
")",
";",
"if",
"(",
"preg_match",
"(",
"'#^'",
".",
"preg_quote",
"(",
"$",
"this",
"->",
"rootdir",
")",
".",
"'/lang/en/([^/]+).php?$#i'",
",",
"$",
"extractfile",
",",
"$",
"matches",
")",
")",
"{",
"$",
"langfiles",
"[",
"]",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"langfiles",
")",
")",
"{",
"$",
"this",
"->",
"add_message",
"(",
"self",
"::",
"ERROR",
",",
"'missinglangenfile'",
")",
";",
"return",
"false",
";",
"}",
"else",
"if",
"(",
"count",
"(",
"$",
"langfiles",
")",
">",
"1",
")",
"{",
"$",
"this",
"->",
"add_message",
"(",
"self",
"::",
"WARNING",
",",
"'multiplelangenfiles'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"langfilename",
"=",
"$",
"langfiles",
"[",
"0",
"]",
";",
"$",
"this",
"->",
"add_message",
"(",
"self",
"::",
"DEBUG",
",",
"'foundlangfile'",
",",
"$",
"this",
"->",
"langfilename",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"assertions",
"[",
"'plugintype'",
"]",
"===",
"'mod'",
")",
"{",
"$",
"expected",
"=",
"$",
"this",
"->",
"rootdir",
".",
"'.php'",
";",
"}",
"else",
"{",
"$",
"expected",
"=",
"$",
"this",
"->",
"assertions",
"[",
"'plugintype'",
"]",
".",
"'_'",
".",
"$",
"this",
"->",
"rootdir",
".",
"'.php'",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"extractfiles",
"[",
"$",
"this",
"->",
"rootdir",
".",
"'/lang/en/'",
".",
"$",
"expected",
"]",
")",
"or",
"$",
"this",
"->",
"extractfiles",
"[",
"$",
"this",
"->",
"rootdir",
".",
"'/lang/en/'",
".",
"$",
"expected",
"]",
"!==",
"true",
"or",
"!",
"is_file",
"(",
"$",
"this",
"->",
"extractdir",
".",
"'/'",
".",
"$",
"this",
"->",
"rootdir",
".",
"'/lang/en/'",
".",
"$",
"expected",
")",
")",
"{",
"$",
"this",
"->",
"add_message",
"(",
"self",
"::",
"ERROR",
",",
"'missingexpectedlangenfile'",
",",
"$",
"expected",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Returns false if the English language pack is not provided correctly.
@return bool
|
[
"Returns",
"false",
"if",
"the",
"English",
"language",
"pack",
"is",
"not",
"provided",
"correctly",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/validator.php#L419-L464
|
219,143
|
moodle/moodle
|
lib/classes/update/validator.php
|
validator.validate_target_location
|
public function validate_target_location() {
if (!isset($this->assertions['plugintype'])) {
throw new coding_exception('Required plugin type must be set before calling this');
}
$plugintypepath = $this->get_plugintype_location($this->assertions['plugintype']);
if (is_null($plugintypepath)) {
$this->add_message(self::ERROR, 'unknowntype', $this->assertions['plugintype']);
return false;
}
if (!is_dir($plugintypepath)) {
throw new coding_exception('Plugin type location does not exist!');
}
// Always check that the plugintype root is writable.
if (!is_writable($plugintypepath)) {
$this->add_message(self::ERROR, 'pathwritable', $plugintypepath);
return false;
} else {
$this->add_message(self::INFO, 'pathwritable', $plugintypepath);
}
// The target location itself may or may not exist. Even if installing an
// available update, the code could have been removed by accident (and
// be reported as missing) etc. So we just make sure that the code
// can be replaced if it already exists.
$target = $plugintypepath.'/'.$this->rootdir;
if (file_exists($target)) {
if (!is_dir($target)) {
$this->add_message(self::ERROR, 'targetnotdir', $target);
return false;
}
$this->add_message(self::WARNING, 'targetexists', $target);
if ($this->get_plugin_manager()->is_directory_removable($target)) {
$this->add_message(self::INFO, 'pathwritable', $target);
} else {
$this->add_message(self::ERROR, 'pathwritable', $target);
return false;
}
}
return true;
}
|
php
|
public function validate_target_location() {
if (!isset($this->assertions['plugintype'])) {
throw new coding_exception('Required plugin type must be set before calling this');
}
$plugintypepath = $this->get_plugintype_location($this->assertions['plugintype']);
if (is_null($plugintypepath)) {
$this->add_message(self::ERROR, 'unknowntype', $this->assertions['plugintype']);
return false;
}
if (!is_dir($plugintypepath)) {
throw new coding_exception('Plugin type location does not exist!');
}
// Always check that the plugintype root is writable.
if (!is_writable($plugintypepath)) {
$this->add_message(self::ERROR, 'pathwritable', $plugintypepath);
return false;
} else {
$this->add_message(self::INFO, 'pathwritable', $plugintypepath);
}
// The target location itself may or may not exist. Even if installing an
// available update, the code could have been removed by accident (and
// be reported as missing) etc. So we just make sure that the code
// can be replaced if it already exists.
$target = $plugintypepath.'/'.$this->rootdir;
if (file_exists($target)) {
if (!is_dir($target)) {
$this->add_message(self::ERROR, 'targetnotdir', $target);
return false;
}
$this->add_message(self::WARNING, 'targetexists', $target);
if ($this->get_plugin_manager()->is_directory_removable($target)) {
$this->add_message(self::INFO, 'pathwritable', $target);
} else {
$this->add_message(self::ERROR, 'pathwritable', $target);
return false;
}
}
return true;
}
|
[
"public",
"function",
"validate_target_location",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"assertions",
"[",
"'plugintype'",
"]",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Required plugin type must be set before calling this'",
")",
";",
"}",
"$",
"plugintypepath",
"=",
"$",
"this",
"->",
"get_plugintype_location",
"(",
"$",
"this",
"->",
"assertions",
"[",
"'plugintype'",
"]",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"plugintypepath",
")",
")",
"{",
"$",
"this",
"->",
"add_message",
"(",
"self",
"::",
"ERROR",
",",
"'unknowntype'",
",",
"$",
"this",
"->",
"assertions",
"[",
"'plugintype'",
"]",
")",
";",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"plugintypepath",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Plugin type location does not exist!'",
")",
";",
"}",
"// Always check that the plugintype root is writable.",
"if",
"(",
"!",
"is_writable",
"(",
"$",
"plugintypepath",
")",
")",
"{",
"$",
"this",
"->",
"add_message",
"(",
"self",
"::",
"ERROR",
",",
"'pathwritable'",
",",
"$",
"plugintypepath",
")",
";",
"return",
"false",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"add_message",
"(",
"self",
"::",
"INFO",
",",
"'pathwritable'",
",",
"$",
"plugintypepath",
")",
";",
"}",
"// The target location itself may or may not exist. Even if installing an",
"// available update, the code could have been removed by accident (and",
"// be reported as missing) etc. So we just make sure that the code",
"// can be replaced if it already exists.",
"$",
"target",
"=",
"$",
"plugintypepath",
".",
"'/'",
".",
"$",
"this",
"->",
"rootdir",
";",
"if",
"(",
"file_exists",
"(",
"$",
"target",
")",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"target",
")",
")",
"{",
"$",
"this",
"->",
"add_message",
"(",
"self",
"::",
"ERROR",
",",
"'targetnotdir'",
",",
"$",
"target",
")",
";",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"add_message",
"(",
"self",
"::",
"WARNING",
",",
"'targetexists'",
",",
"$",
"target",
")",
";",
"if",
"(",
"$",
"this",
"->",
"get_plugin_manager",
"(",
")",
"->",
"is_directory_removable",
"(",
"$",
"target",
")",
")",
"{",
"$",
"this",
"->",
"add_message",
"(",
"self",
"::",
"INFO",
",",
"'pathwritable'",
",",
"$",
"target",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"add_message",
"(",
"self",
"::",
"ERROR",
",",
"'pathwritable'",
",",
"$",
"target",
")",
";",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Returns false of the given add-on can't be installed into its location.
@return bool
|
[
"Returns",
"false",
"of",
"the",
"given",
"add",
"-",
"on",
"can",
"t",
"be",
"installed",
"into",
"its",
"location",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/validator.php#L471-L516
|
219,144
|
moodle/moodle
|
lib/classes/update/validator.php
|
validator.parse_version_php
|
protected function parse_version_php($fullpath) {
$content = $this->get_stripped_file_contents($fullpath);
preg_match_all('#\$((plugin|module)\->(version|maturity|release|requires))=()(\d+(\.\d+)?);#m', $content, $matches1);
preg_match_all('#\$((plugin|module)\->(maturity))=()(MATURITY_\w+);#m', $content, $matches2);
preg_match_all('#\$((plugin|module)\->(release))=([\'"])(.*?)\4;#m', $content, $matches3);
preg_match_all('#\$((plugin|module)\->(component))=([\'"])(.+?_.+?)\4;#m', $content, $matches4);
if (count($matches1[1]) + count($matches2[1]) + count($matches3[1]) + count($matches4[1])) {
$info = array_combine(
array_merge($matches1[1], $matches2[1], $matches3[1], $matches4[1]),
array_merge($matches1[5], $matches2[5], $matches3[5], $matches4[5])
);
} else {
$info = array();
}
return $info;
}
|
php
|
protected function parse_version_php($fullpath) {
$content = $this->get_stripped_file_contents($fullpath);
preg_match_all('#\$((plugin|module)\->(version|maturity|release|requires))=()(\d+(\.\d+)?);#m', $content, $matches1);
preg_match_all('#\$((plugin|module)\->(maturity))=()(MATURITY_\w+);#m', $content, $matches2);
preg_match_all('#\$((plugin|module)\->(release))=([\'"])(.*?)\4;#m', $content, $matches3);
preg_match_all('#\$((plugin|module)\->(component))=([\'"])(.+?_.+?)\4;#m', $content, $matches4);
if (count($matches1[1]) + count($matches2[1]) + count($matches3[1]) + count($matches4[1])) {
$info = array_combine(
array_merge($matches1[1], $matches2[1], $matches3[1], $matches4[1]),
array_merge($matches1[5], $matches2[5], $matches3[5], $matches4[5])
);
} else {
$info = array();
}
return $info;
}
|
[
"protected",
"function",
"parse_version_php",
"(",
"$",
"fullpath",
")",
"{",
"$",
"content",
"=",
"$",
"this",
"->",
"get_stripped_file_contents",
"(",
"$",
"fullpath",
")",
";",
"preg_match_all",
"(",
"'#\\$((plugin|module)\\->(version|maturity|release|requires))=()(\\d+(\\.\\d+)?);#m'",
",",
"$",
"content",
",",
"$",
"matches1",
")",
";",
"preg_match_all",
"(",
"'#\\$((plugin|module)\\->(maturity))=()(MATURITY_\\w+);#m'",
",",
"$",
"content",
",",
"$",
"matches2",
")",
";",
"preg_match_all",
"(",
"'#\\$((plugin|module)\\->(release))=([\\'\"])(.*?)\\4;#m'",
",",
"$",
"content",
",",
"$",
"matches3",
")",
";",
"preg_match_all",
"(",
"'#\\$((plugin|module)\\->(component))=([\\'\"])(.+?_.+?)\\4;#m'",
",",
"$",
"content",
",",
"$",
"matches4",
")",
";",
"if",
"(",
"count",
"(",
"$",
"matches1",
"[",
"1",
"]",
")",
"+",
"count",
"(",
"$",
"matches2",
"[",
"1",
"]",
")",
"+",
"count",
"(",
"$",
"matches3",
"[",
"1",
"]",
")",
"+",
"count",
"(",
"$",
"matches4",
"[",
"1",
"]",
")",
")",
"{",
"$",
"info",
"=",
"array_combine",
"(",
"array_merge",
"(",
"$",
"matches1",
"[",
"1",
"]",
",",
"$",
"matches2",
"[",
"1",
"]",
",",
"$",
"matches3",
"[",
"1",
"]",
",",
"$",
"matches4",
"[",
"1",
"]",
")",
",",
"array_merge",
"(",
"$",
"matches1",
"[",
"5",
"]",
",",
"$",
"matches2",
"[",
"5",
"]",
",",
"$",
"matches3",
"[",
"5",
"]",
",",
"$",
"matches4",
"[",
"5",
"]",
")",
")",
";",
"}",
"else",
"{",
"$",
"info",
"=",
"array",
"(",
")",
";",
"}",
"return",
"$",
"info",
";",
"}"
] |
Get as much information from existing version.php as possible
@param string $fullpath full path to the version.php file
@return array of found meta-info declarations
|
[
"Get",
"as",
"much",
"information",
"from",
"existing",
"version",
".",
"php",
"as",
"possible"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/validator.php#L526-L546
|
219,145
|
moodle/moodle
|
lib/classes/update/validator.php
|
validator.add_message
|
protected function add_message($level, $msgcode, $a = null) {
$msg = (object)array(
'level' => $level,
'msgcode' => $msgcode,
'addinfo' => $a,
);
$this->messages[] = $msg;
}
|
php
|
protected function add_message($level, $msgcode, $a = null) {
$msg = (object)array(
'level' => $level,
'msgcode' => $msgcode,
'addinfo' => $a,
);
$this->messages[] = $msg;
}
|
[
"protected",
"function",
"add_message",
"(",
"$",
"level",
",",
"$",
"msgcode",
",",
"$",
"a",
"=",
"null",
")",
"{",
"$",
"msg",
"=",
"(",
"object",
")",
"array",
"(",
"'level'",
"=>",
"$",
"level",
",",
"'msgcode'",
"=>",
"$",
"msgcode",
",",
"'addinfo'",
"=>",
"$",
"a",
",",
")",
";",
"$",
"this",
"->",
"messages",
"[",
"]",
"=",
"$",
"msg",
";",
"}"
] |
Append the given message to the messages log
@param string $level e.g. self::ERROR
@param string $msgcode may form a string
@param string|array|object $a optional additional info suitable for {@link get_string()}
|
[
"Append",
"the",
"given",
"message",
"to",
"the",
"messages",
"log"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/validator.php#L555-L562
|
219,146
|
moodle/moodle
|
lib/classes/update/validator.php
|
validator.get_stripped_file_contents
|
protected function get_stripped_file_contents($fullpath) {
$source = file_get_contents($fullpath);
$tokens = token_get_all($source);
$output = '';
$doprocess = false;
foreach ($tokens as $token) {
if (is_string($token)) {
// Simple one character token.
$id = -1;
$text = $token;
} else {
// Token array.
list($id, $text) = $token;
}
switch ($id) {
case T_WHITESPACE:
case T_COMMENT:
case T_ML_COMMENT:
case T_DOC_COMMENT:
// Ignore whitespaces, inline comments, multiline comments and docblocks.
break;
case T_OPEN_TAG:
// Start processing.
$doprocess = true;
break;
case T_CLOSE_TAG:
// Stop processing.
$doprocess = false;
break;
default:
// Anything else is within PHP tags, return it as is.
if ($doprocess) {
$output .= $text;
if ($text === 'function') {
// Explicitly keep the whitespace that would be ignored.
$output .= ' ';
}
}
break;
}
}
return $output;
}
|
php
|
protected function get_stripped_file_contents($fullpath) {
$source = file_get_contents($fullpath);
$tokens = token_get_all($source);
$output = '';
$doprocess = false;
foreach ($tokens as $token) {
if (is_string($token)) {
// Simple one character token.
$id = -1;
$text = $token;
} else {
// Token array.
list($id, $text) = $token;
}
switch ($id) {
case T_WHITESPACE:
case T_COMMENT:
case T_ML_COMMENT:
case T_DOC_COMMENT:
// Ignore whitespaces, inline comments, multiline comments and docblocks.
break;
case T_OPEN_TAG:
// Start processing.
$doprocess = true;
break;
case T_CLOSE_TAG:
// Stop processing.
$doprocess = false;
break;
default:
// Anything else is within PHP tags, return it as is.
if ($doprocess) {
$output .= $text;
if ($text === 'function') {
// Explicitly keep the whitespace that would be ignored.
$output .= ' ';
}
}
break;
}
}
return $output;
}
|
[
"protected",
"function",
"get_stripped_file_contents",
"(",
"$",
"fullpath",
")",
"{",
"$",
"source",
"=",
"file_get_contents",
"(",
"$",
"fullpath",
")",
";",
"$",
"tokens",
"=",
"token_get_all",
"(",
"$",
"source",
")",
";",
"$",
"output",
"=",
"''",
";",
"$",
"doprocess",
"=",
"false",
";",
"foreach",
"(",
"$",
"tokens",
"as",
"$",
"token",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"token",
")",
")",
"{",
"// Simple one character token.",
"$",
"id",
"=",
"-",
"1",
";",
"$",
"text",
"=",
"$",
"token",
";",
"}",
"else",
"{",
"// Token array.",
"list",
"(",
"$",
"id",
",",
"$",
"text",
")",
"=",
"$",
"token",
";",
"}",
"switch",
"(",
"$",
"id",
")",
"{",
"case",
"T_WHITESPACE",
":",
"case",
"T_COMMENT",
":",
"case",
"T_ML_COMMENT",
":",
"case",
"T_DOC_COMMENT",
":",
"// Ignore whitespaces, inline comments, multiline comments and docblocks.",
"break",
";",
"case",
"T_OPEN_TAG",
":",
"// Start processing.",
"$",
"doprocess",
"=",
"true",
";",
"break",
";",
"case",
"T_CLOSE_TAG",
":",
"// Stop processing.",
"$",
"doprocess",
"=",
"false",
";",
"break",
";",
"default",
":",
"// Anything else is within PHP tags, return it as is.",
"if",
"(",
"$",
"doprocess",
")",
"{",
"$",
"output",
".=",
"$",
"text",
";",
"if",
"(",
"$",
"text",
"===",
"'function'",
")",
"{",
"// Explicitly keep the whitespace that would be ignored.",
"$",
"output",
".=",
"' '",
";",
"}",
"}",
"break",
";",
"}",
"}",
"return",
"$",
"output",
";",
"}"
] |
Returns bare PHP code from the given file
Returns contents without PHP opening and closing tags, text outside php code,
comments and extra whitespaces.
@param string $fullpath full path to the file
@return string
|
[
"Returns",
"bare",
"PHP",
"code",
"from",
"the",
"given",
"file"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/validator.php#L573-L617
|
219,147
|
moodle/moodle
|
user/profile/field/checkbox/field.class.php
|
profile_field_checkbox.edit_field_add
|
public function edit_field_add($mform) {
// Create the form field.
$checkbox = $mform->addElement('advcheckbox', $this->inputname, format_string($this->field->name));
if ($this->data == '1') {
$checkbox->setChecked(true);
}
$mform->setType($this->inputname, PARAM_BOOL);
if ($this->is_required() and !has_capability('moodle/user:update', context_system::instance())) {
$mform->addRule($this->inputname, get_string('required'), 'nonzero', null, 'client');
}
}
|
php
|
public function edit_field_add($mform) {
// Create the form field.
$checkbox = $mform->addElement('advcheckbox', $this->inputname, format_string($this->field->name));
if ($this->data == '1') {
$checkbox->setChecked(true);
}
$mform->setType($this->inputname, PARAM_BOOL);
if ($this->is_required() and !has_capability('moodle/user:update', context_system::instance())) {
$mform->addRule($this->inputname, get_string('required'), 'nonzero', null, 'client');
}
}
|
[
"public",
"function",
"edit_field_add",
"(",
"$",
"mform",
")",
"{",
"// Create the form field.",
"$",
"checkbox",
"=",
"$",
"mform",
"->",
"addElement",
"(",
"'advcheckbox'",
",",
"$",
"this",
"->",
"inputname",
",",
"format_string",
"(",
"$",
"this",
"->",
"field",
"->",
"name",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"data",
"==",
"'1'",
")",
"{",
"$",
"checkbox",
"->",
"setChecked",
"(",
"true",
")",
";",
"}",
"$",
"mform",
"->",
"setType",
"(",
"$",
"this",
"->",
"inputname",
",",
"PARAM_BOOL",
")",
";",
"if",
"(",
"$",
"this",
"->",
"is_required",
"(",
")",
"and",
"!",
"has_capability",
"(",
"'moodle/user:update'",
",",
"context_system",
"::",
"instance",
"(",
")",
")",
")",
"{",
"$",
"mform",
"->",
"addRule",
"(",
"$",
"this",
"->",
"inputname",
",",
"get_string",
"(",
"'required'",
")",
",",
"'nonzero'",
",",
"null",
",",
"'client'",
")",
";",
"}",
"}"
] |
Add elements for editing the profile field value.
@param moodleform $mform
|
[
"Add",
"elements",
"for",
"editing",
"the",
"profile",
"field",
"value",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/profile/field/checkbox/field.class.php#L37-L47
|
219,148
|
moodle/moodle
|
user/profile/lib.php
|
profile_field_base.edit_field
|
public function edit_field($mform) {
if (!$this->is_editable()) {
return false;
}
$this->edit_field_add($mform);
$this->edit_field_set_default($mform);
$this->edit_field_set_required($mform);
return true;
}
|
php
|
public function edit_field($mform) {
if (!$this->is_editable()) {
return false;
}
$this->edit_field_add($mform);
$this->edit_field_set_default($mform);
$this->edit_field_set_required($mform);
return true;
}
|
[
"public",
"function",
"edit_field",
"(",
"$",
"mform",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"is_editable",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"edit_field_add",
"(",
"$",
"mform",
")",
";",
"$",
"this",
"->",
"edit_field_set_default",
"(",
"$",
"mform",
")",
";",
"$",
"this",
"->",
"edit_field_set_required",
"(",
"$",
"mform",
")",
";",
"return",
"true",
";",
"}"
] |
Print out the form field in the edit profile page
@param moodleform $mform instance of the moodleform class
@return bool
|
[
"Print",
"out",
"the",
"form",
"field",
"in",
"the",
"edit",
"profile",
"page"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/profile/lib.php#L147-L156
|
219,149
|
moodle/moodle
|
user/profile/lib.php
|
profile_field_base.edit_validate_field
|
public function edit_validate_field($usernew) {
global $DB;
$errors = array();
// Get input value.
if (isset($usernew->{$this->inputname})) {
if (is_array($usernew->{$this->inputname}) && isset($usernew->{$this->inputname}['text'])) {
$value = $usernew->{$this->inputname}['text'];
} else {
$value = $usernew->{$this->inputname};
}
} else {
$value = '';
}
// Check for uniqueness of data if required.
if ($this->is_unique() && (($value !== '') || $this->is_required())) {
$data = $DB->get_records_sql('
SELECT id, userid
FROM {user_info_data}
WHERE fieldid = ?
AND ' . $DB->sql_compare_text('data', 255) . ' = ' . $DB->sql_compare_text('?', 255),
array($this->field->id, $value));
if ($data) {
$existing = false;
foreach ($data as $v) {
if ($v->userid == $usernew->id) {
$existing = true;
break;
}
}
if (!$existing) {
$errors[$this->inputname] = get_string('valuealreadyused');
}
}
}
return $errors;
}
|
php
|
public function edit_validate_field($usernew) {
global $DB;
$errors = array();
// Get input value.
if (isset($usernew->{$this->inputname})) {
if (is_array($usernew->{$this->inputname}) && isset($usernew->{$this->inputname}['text'])) {
$value = $usernew->{$this->inputname}['text'];
} else {
$value = $usernew->{$this->inputname};
}
} else {
$value = '';
}
// Check for uniqueness of data if required.
if ($this->is_unique() && (($value !== '') || $this->is_required())) {
$data = $DB->get_records_sql('
SELECT id, userid
FROM {user_info_data}
WHERE fieldid = ?
AND ' . $DB->sql_compare_text('data', 255) . ' = ' . $DB->sql_compare_text('?', 255),
array($this->field->id, $value));
if ($data) {
$existing = false;
foreach ($data as $v) {
if ($v->userid == $usernew->id) {
$existing = true;
break;
}
}
if (!$existing) {
$errors[$this->inputname] = get_string('valuealreadyused');
}
}
}
return $errors;
}
|
[
"public",
"function",
"edit_validate_field",
"(",
"$",
"usernew",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"errors",
"=",
"array",
"(",
")",
";",
"// Get input value.",
"if",
"(",
"isset",
"(",
"$",
"usernew",
"->",
"{",
"$",
"this",
"->",
"inputname",
"}",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"usernew",
"->",
"{",
"$",
"this",
"->",
"inputname",
"}",
")",
"&&",
"isset",
"(",
"$",
"usernew",
"->",
"{",
"$",
"this",
"->",
"inputname",
"}",
"[",
"'text'",
"]",
")",
")",
"{",
"$",
"value",
"=",
"$",
"usernew",
"->",
"{",
"$",
"this",
"->",
"inputname",
"}",
"[",
"'text'",
"]",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"$",
"usernew",
"->",
"{",
"$",
"this",
"->",
"inputname",
"}",
";",
"}",
"}",
"else",
"{",
"$",
"value",
"=",
"''",
";",
"}",
"// Check for uniqueness of data if required.",
"if",
"(",
"$",
"this",
"->",
"is_unique",
"(",
")",
"&&",
"(",
"(",
"$",
"value",
"!==",
"''",
")",
"||",
"$",
"this",
"->",
"is_required",
"(",
")",
")",
")",
"{",
"$",
"data",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"'\n SELECT id, userid\n FROM {user_info_data}\n WHERE fieldid = ?\n AND '",
".",
"$",
"DB",
"->",
"sql_compare_text",
"(",
"'data'",
",",
"255",
")",
".",
"' = '",
".",
"$",
"DB",
"->",
"sql_compare_text",
"(",
"'?'",
",",
"255",
")",
",",
"array",
"(",
"$",
"this",
"->",
"field",
"->",
"id",
",",
"$",
"value",
")",
")",
";",
"if",
"(",
"$",
"data",
")",
"{",
"$",
"existing",
"=",
"false",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"v",
")",
"{",
"if",
"(",
"$",
"v",
"->",
"userid",
"==",
"$",
"usernew",
"->",
"id",
")",
"{",
"$",
"existing",
"=",
"true",
";",
"break",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"existing",
")",
"{",
"$",
"errors",
"[",
"$",
"this",
"->",
"inputname",
"]",
"=",
"get_string",
"(",
"'valuealreadyused'",
")",
";",
"}",
"}",
"}",
"return",
"$",
"errors",
";",
"}"
] |
Validate the form field from profile page
@param stdClass $usernew
@return string contains error message otherwise null
|
[
"Validate",
"the",
"form",
"field",
"from",
"profile",
"page"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/profile/lib.php#L211-L248
|
219,150
|
moodle/moodle
|
user/profile/lib.php
|
profile_field_base.edit_field_set_default
|
public function edit_field_set_default($mform) {
if (!empty($this->field->defaultdata)) {
$mform->setDefault($this->inputname, $this->field->defaultdata);
}
}
|
php
|
public function edit_field_set_default($mform) {
if (!empty($this->field->defaultdata)) {
$mform->setDefault($this->inputname, $this->field->defaultdata);
}
}
|
[
"public",
"function",
"edit_field_set_default",
"(",
"$",
"mform",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"field",
"->",
"defaultdata",
")",
")",
"{",
"$",
"mform",
"->",
"setDefault",
"(",
"$",
"this",
"->",
"inputname",
",",
"$",
"this",
"->",
"field",
"->",
"defaultdata",
")",
";",
"}",
"}"
] |
Sets the default data for the field in the form object
@param moodleform $mform instance of the moodleform class
|
[
"Sets",
"the",
"default",
"data",
"for",
"the",
"field",
"in",
"the",
"form",
"object"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/profile/lib.php#L254-L258
|
219,151
|
moodle/moodle
|
user/profile/lib.php
|
profile_field_base.edit_field_set_required
|
public function edit_field_set_required($mform) {
global $USER;
if ($this->is_required() && ($this->userid == $USER->id || isguestuser())) {
$mform->addRule($this->inputname, get_string('required'), 'required', null, 'client');
}
}
|
php
|
public function edit_field_set_required($mform) {
global $USER;
if ($this->is_required() && ($this->userid == $USER->id || isguestuser())) {
$mform->addRule($this->inputname, get_string('required'), 'required', null, 'client');
}
}
|
[
"public",
"function",
"edit_field_set_required",
"(",
"$",
"mform",
")",
"{",
"global",
"$",
"USER",
";",
"if",
"(",
"$",
"this",
"->",
"is_required",
"(",
")",
"&&",
"(",
"$",
"this",
"->",
"userid",
"==",
"$",
"USER",
"->",
"id",
"||",
"isguestuser",
"(",
")",
")",
")",
"{",
"$",
"mform",
"->",
"addRule",
"(",
"$",
"this",
"->",
"inputname",
",",
"get_string",
"(",
"'required'",
")",
",",
"'required'",
",",
"null",
",",
"'client'",
")",
";",
"}",
"}"
] |
Sets the required flag for the field in the form object
@param moodleform $mform instance of the moodleform class
|
[
"Sets",
"the",
"required",
"flag",
"for",
"the",
"field",
"in",
"the",
"form",
"object"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/profile/lib.php#L265-L270
|
219,152
|
moodle/moodle
|
user/profile/lib.php
|
profile_field_base.edit_load_user_data
|
public function edit_load_user_data($user) {
if ($this->data !== null) {
$user->{$this->inputname} = $this->data;
}
}
|
php
|
public function edit_load_user_data($user) {
if ($this->data !== null) {
$user->{$this->inputname} = $this->data;
}
}
|
[
"public",
"function",
"edit_load_user_data",
"(",
"$",
"user",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"data",
"!==",
"null",
")",
"{",
"$",
"user",
"->",
"{",
"$",
"this",
"->",
"inputname",
"}",
"=",
"$",
"this",
"->",
"data",
";",
"}",
"}"
] |
Loads a user object with data for this field ready for the edit profile
form
@param stdClass $user a user object
|
[
"Loads",
"a",
"user",
"object",
"with",
"data",
"for",
"this",
"field",
"ready",
"for",
"the",
"edit",
"profile",
"form"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/profile/lib.php#L301-L305
|
219,153
|
moodle/moodle
|
user/profile/lib.php
|
profile_field_base.get_category_name
|
public function get_category_name() {
global $DB;
if ($this->categoryname === null) {
$this->categoryname = $DB->get_field('user_info_category', 'name', ['id' => $this->field->categoryid]);
}
return $this->categoryname;
}
|
php
|
public function get_category_name() {
global $DB;
if ($this->categoryname === null) {
$this->categoryname = $DB->get_field('user_info_category', 'name', ['id' => $this->field->categoryid]);
}
return $this->categoryname;
}
|
[
"public",
"function",
"get_category_name",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"$",
"this",
"->",
"categoryname",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"categoryname",
"=",
"$",
"DB",
"->",
"get_field",
"(",
"'user_info_category'",
",",
"'name'",
",",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"field",
"->",
"categoryid",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"categoryname",
";",
"}"
] |
Returns the name of the profile category where this field is
@return string
|
[
"Returns",
"the",
"name",
"of",
"the",
"profile",
"category",
"where",
"this",
"field",
"is"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/profile/lib.php#L390-L396
|
219,154
|
moodle/moodle
|
user/profile/lib.php
|
profile_field_base.is_visible
|
public function is_visible() {
global $USER;
$context = ($this->userid > 0) ? context_user::instance($this->userid) : context_system::instance();
switch ($this->field->visible) {
case PROFILE_VISIBLE_ALL:
return true;
case PROFILE_VISIBLE_PRIVATE:
if ($this->is_signup_field() && (empty($this->userid) || isguestuser($this->userid))) {
return true;
} else if ($this->userid == $USER->id) {
return true;
} else {
return has_capability('moodle/user:viewalldetails', $context);
}
default:
return has_capability('moodle/user:viewalldetails', $context);
}
}
|
php
|
public function is_visible() {
global $USER;
$context = ($this->userid > 0) ? context_user::instance($this->userid) : context_system::instance();
switch ($this->field->visible) {
case PROFILE_VISIBLE_ALL:
return true;
case PROFILE_VISIBLE_PRIVATE:
if ($this->is_signup_field() && (empty($this->userid) || isguestuser($this->userid))) {
return true;
} else if ($this->userid == $USER->id) {
return true;
} else {
return has_capability('moodle/user:viewalldetails', $context);
}
default:
return has_capability('moodle/user:viewalldetails', $context);
}
}
|
[
"public",
"function",
"is_visible",
"(",
")",
"{",
"global",
"$",
"USER",
";",
"$",
"context",
"=",
"(",
"$",
"this",
"->",
"userid",
">",
"0",
")",
"?",
"context_user",
"::",
"instance",
"(",
"$",
"this",
"->",
"userid",
")",
":",
"context_system",
"::",
"instance",
"(",
")",
";",
"switch",
"(",
"$",
"this",
"->",
"field",
"->",
"visible",
")",
"{",
"case",
"PROFILE_VISIBLE_ALL",
":",
"return",
"true",
";",
"case",
"PROFILE_VISIBLE_PRIVATE",
":",
"if",
"(",
"$",
"this",
"->",
"is_signup_field",
"(",
")",
"&&",
"(",
"empty",
"(",
"$",
"this",
"->",
"userid",
")",
"||",
"isguestuser",
"(",
"$",
"this",
"->",
"userid",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"userid",
"==",
"$",
"USER",
"->",
"id",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"has_capability",
"(",
"'moodle/user:viewalldetails'",
",",
"$",
"context",
")",
";",
"}",
"default",
":",
"return",
"has_capability",
"(",
"'moodle/user:viewalldetails'",
",",
"$",
"context",
")",
";",
"}",
"}"
] |
Check if the field data is visible to the current user
@internal This method should not generally be overwritten by child classes.
@return bool
|
[
"Check",
"if",
"the",
"field",
"data",
"is",
"visible",
"to",
"the",
"current",
"user"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/profile/lib.php#L430-L449
|
219,155
|
moodle/moodle
|
user/profile/lib.php
|
profile_field_base.is_editable
|
public function is_editable() {
global $USER;
if (!$this->is_visible()) {
return false;
}
if ($this->is_signup_field() && (empty($this->userid) || isguestuser($this->userid))) {
// Allow editing the field on the signup page.
return true;
}
$systemcontext = context_system::instance();
if ($this->userid == $USER->id && has_capability('moodle/user:editownprofile', $systemcontext)) {
return true;
}
if (has_capability('moodle/user:update', $systemcontext)) {
return true;
}
return false;
}
|
php
|
public function is_editable() {
global $USER;
if (!$this->is_visible()) {
return false;
}
if ($this->is_signup_field() && (empty($this->userid) || isguestuser($this->userid))) {
// Allow editing the field on the signup page.
return true;
}
$systemcontext = context_system::instance();
if ($this->userid == $USER->id && has_capability('moodle/user:editownprofile', $systemcontext)) {
return true;
}
if (has_capability('moodle/user:update', $systemcontext)) {
return true;
}
return false;
}
|
[
"public",
"function",
"is_editable",
"(",
")",
"{",
"global",
"$",
"USER",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"is_visible",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"is_signup_field",
"(",
")",
"&&",
"(",
"empty",
"(",
"$",
"this",
"->",
"userid",
")",
"||",
"isguestuser",
"(",
"$",
"this",
"->",
"userid",
")",
")",
")",
"{",
"// Allow editing the field on the signup page.",
"return",
"true",
";",
"}",
"$",
"systemcontext",
"=",
"context_system",
"::",
"instance",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"userid",
"==",
"$",
"USER",
"->",
"id",
"&&",
"has_capability",
"(",
"'moodle/user:editownprofile'",
",",
"$",
"systemcontext",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"has_capability",
"(",
"'moodle/user:update'",
",",
"$",
"systemcontext",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Check if the field data is editable for the current user
This method should not generally be overwritten by child classes.
@return bool
|
[
"Check",
"if",
"the",
"field",
"data",
"is",
"editable",
"for",
"the",
"current",
"user",
"This",
"method",
"should",
"not",
"generally",
"be",
"overwritten",
"by",
"child",
"classes",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/profile/lib.php#L456-L479
|
219,156
|
moodle/moodle
|
repository/lib.php
|
repository_type.get_contextvisibility
|
public function get_contextvisibility($context) {
global $USER;
if ($context->contextlevel == CONTEXT_COURSE) {
return $this->_options['enablecourseinstances'];
}
if ($context->contextlevel == CONTEXT_USER) {
return $this->_options['enableuserinstances'];
}
//the context is SITE
return true;
}
|
php
|
public function get_contextvisibility($context) {
global $USER;
if ($context->contextlevel == CONTEXT_COURSE) {
return $this->_options['enablecourseinstances'];
}
if ($context->contextlevel == CONTEXT_USER) {
return $this->_options['enableuserinstances'];
}
//the context is SITE
return true;
}
|
[
"public",
"function",
"get_contextvisibility",
"(",
"$",
"context",
")",
"{",
"global",
"$",
"USER",
";",
"if",
"(",
"$",
"context",
"->",
"contextlevel",
"==",
"CONTEXT_COURSE",
")",
"{",
"return",
"$",
"this",
"->",
"_options",
"[",
"'enablecourseinstances'",
"]",
";",
"}",
"if",
"(",
"$",
"context",
"->",
"contextlevel",
"==",
"CONTEXT_USER",
")",
"{",
"return",
"$",
"this",
"->",
"_options",
"[",
"'enableuserinstances'",
"]",
";",
"}",
"//the context is SITE",
"return",
"true",
";",
"}"
] |
Return if the instance is visible in a context
@todo check if the context visibility has been overwritten by the plugin creator
(need to create special functions to be overvwritten in repository class)
@param stdClass $context context
@return bool
|
[
"Return",
"if",
"the",
"instance",
"is",
"visible",
"in",
"a",
"context"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L101-L114
|
219,157
|
moodle/moodle
|
repository/lib.php
|
repository_type.update_options
|
public function update_options($options = null) {
global $DB;
$classname = 'repository_' . $this->_typename;
$instanceoptions = repository::static_function($this->_typename, 'get_instance_option_names');
if (empty($instanceoptions)) {
// update repository instance name if this plugin type doesn't have muliti instances
$params = array();
$params['type'] = $this->_typename;
$instances = repository::get_instances($params);
$instance = array_pop($instances);
if ($instance) {
$DB->set_field('repository_instances', 'name', $options['pluginname'], array('id'=>$instance->id));
}
unset($options['pluginname']);
}
if (!empty($options)) {
$this->_options = $options;
}
foreach ($this->_options as $name => $value) {
set_config($name, $value, $this->_typename);
}
cache::make('core', 'repositories')->purge();
return true;
}
|
php
|
public function update_options($options = null) {
global $DB;
$classname = 'repository_' . $this->_typename;
$instanceoptions = repository::static_function($this->_typename, 'get_instance_option_names');
if (empty($instanceoptions)) {
// update repository instance name if this plugin type doesn't have muliti instances
$params = array();
$params['type'] = $this->_typename;
$instances = repository::get_instances($params);
$instance = array_pop($instances);
if ($instance) {
$DB->set_field('repository_instances', 'name', $options['pluginname'], array('id'=>$instance->id));
}
unset($options['pluginname']);
}
if (!empty($options)) {
$this->_options = $options;
}
foreach ($this->_options as $name => $value) {
set_config($name, $value, $this->_typename);
}
cache::make('core', 'repositories')->purge();
return true;
}
|
[
"public",
"function",
"update_options",
"(",
"$",
"options",
"=",
"null",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"classname",
"=",
"'repository_'",
".",
"$",
"this",
"->",
"_typename",
";",
"$",
"instanceoptions",
"=",
"repository",
"::",
"static_function",
"(",
"$",
"this",
"->",
"_typename",
",",
"'get_instance_option_names'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"instanceoptions",
")",
")",
"{",
"// update repository instance name if this plugin type doesn't have muliti instances",
"$",
"params",
"=",
"array",
"(",
")",
";",
"$",
"params",
"[",
"'type'",
"]",
"=",
"$",
"this",
"->",
"_typename",
";",
"$",
"instances",
"=",
"repository",
"::",
"get_instances",
"(",
"$",
"params",
")",
";",
"$",
"instance",
"=",
"array_pop",
"(",
"$",
"instances",
")",
";",
"if",
"(",
"$",
"instance",
")",
"{",
"$",
"DB",
"->",
"set_field",
"(",
"'repository_instances'",
",",
"'name'",
",",
"$",
"options",
"[",
"'pluginname'",
"]",
",",
"array",
"(",
"'id'",
"=>",
"$",
"instance",
"->",
"id",
")",
")",
";",
"}",
"unset",
"(",
"$",
"options",
"[",
"'pluginname'",
"]",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
")",
")",
"{",
"$",
"this",
"->",
"_options",
"=",
"$",
"options",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"_options",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"set_config",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"this",
"->",
"_typename",
")",
";",
"}",
"cache",
"::",
"make",
"(",
"'core'",
",",
"'repositories'",
")",
"->",
"purge",
"(",
")",
";",
"return",
"true",
";",
"}"
] |
Update plugin options into the config_plugin table
@param array $options
@return bool
|
[
"Update",
"plugin",
"options",
"into",
"the",
"config_plugin",
"table"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L290-L316
|
219,158
|
moodle/moodle
|
repository/lib.php
|
repository_type.update_visibility
|
public function update_visibility($visible = null) {
if (is_bool($visible)) {
$this->_visible = $visible;
} else {
$this->_visible = !$this->_visible;
}
return $this->update_visible();
}
|
php
|
public function update_visibility($visible = null) {
if (is_bool($visible)) {
$this->_visible = $visible;
} else {
$this->_visible = !$this->_visible;
}
return $this->update_visible();
}
|
[
"public",
"function",
"update_visibility",
"(",
"$",
"visible",
"=",
"null",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"visible",
")",
")",
"{",
"$",
"this",
"->",
"_visible",
"=",
"$",
"visible",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_visible",
"=",
"!",
"$",
"this",
"->",
"_visible",
";",
"}",
"return",
"$",
"this",
"->",
"update_visible",
"(",
")",
";",
"}"
] |
1. Change visibility to the value chosen
2. Update the type
@param bool $visible
@return bool
|
[
"1",
".",
"Change",
"visibility",
"to",
"the",
"value",
"chosen",
"2",
".",
"Update",
"the",
"type"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L419-L426
|
219,159
|
moodle/moodle
|
repository/lib.php
|
repository.get_repository_by_id
|
public static function get_repository_by_id($repositoryid, $context, $options = array()) {
global $CFG, $DB;
$cache = cache::make('core', 'repositories');
if (!is_object($context)) {
$context = context::instance_by_id($context);
}
$cachekey = 'rep:'. $repositoryid. ':'. $context->id. ':'. serialize($options);
if ($repository = $cache->get($cachekey)) {
return $repository;
}
if (!$record = $cache->get('i:'. $repositoryid)) {
$sql = "SELECT i.*, r.type AS repositorytype, r.visible, r.sortorder
FROM {repository_instances} i
JOIN {repository} r ON r.id = i.typeid
WHERE i.id = ?";
if (!$record = $DB->get_record_sql($sql, array($repositoryid))) {
throw new repository_exception('invalidrepositoryid', 'repository');
}
$cache->set('i:'. $record->id, $record);
}
$type = $record->repositorytype;
if (file_exists($CFG->dirroot . "/repository/$type/lib.php")) {
require_once($CFG->dirroot . "/repository/$type/lib.php");
$classname = 'repository_' . $type;
$options['type'] = $type;
$options['typeid'] = $record->typeid;
$options['visible'] = $record->visible;
if (empty($options['name'])) {
$options['name'] = $record->name;
}
$repository = new $classname($repositoryid, $context, $options, $record->readonly);
if (empty($repository->super_called)) {
// to make sure the super construct is called
debugging('parent::__construct must be called by '.$type.' plugin.');
}
$cache->set($cachekey, $repository);
return $repository;
} else {
throw new repository_exception('invalidplugin', 'repository');
}
}
|
php
|
public static function get_repository_by_id($repositoryid, $context, $options = array()) {
global $CFG, $DB;
$cache = cache::make('core', 'repositories');
if (!is_object($context)) {
$context = context::instance_by_id($context);
}
$cachekey = 'rep:'. $repositoryid. ':'. $context->id. ':'. serialize($options);
if ($repository = $cache->get($cachekey)) {
return $repository;
}
if (!$record = $cache->get('i:'. $repositoryid)) {
$sql = "SELECT i.*, r.type AS repositorytype, r.visible, r.sortorder
FROM {repository_instances} i
JOIN {repository} r ON r.id = i.typeid
WHERE i.id = ?";
if (!$record = $DB->get_record_sql($sql, array($repositoryid))) {
throw new repository_exception('invalidrepositoryid', 'repository');
}
$cache->set('i:'. $record->id, $record);
}
$type = $record->repositorytype;
if (file_exists($CFG->dirroot . "/repository/$type/lib.php")) {
require_once($CFG->dirroot . "/repository/$type/lib.php");
$classname = 'repository_' . $type;
$options['type'] = $type;
$options['typeid'] = $record->typeid;
$options['visible'] = $record->visible;
if (empty($options['name'])) {
$options['name'] = $record->name;
}
$repository = new $classname($repositoryid, $context, $options, $record->readonly);
if (empty($repository->super_called)) {
// to make sure the super construct is called
debugging('parent::__construct must be called by '.$type.' plugin.');
}
$cache->set($cachekey, $repository);
return $repository;
} else {
throw new repository_exception('invalidplugin', 'repository');
}
}
|
[
"public",
"static",
"function",
"get_repository_by_id",
"(",
"$",
"repositoryid",
",",
"$",
"context",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
";",
"$",
"cache",
"=",
"cache",
"::",
"make",
"(",
"'core'",
",",
"'repositories'",
")",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"context",
")",
")",
"{",
"$",
"context",
"=",
"context",
"::",
"instance_by_id",
"(",
"$",
"context",
")",
";",
"}",
"$",
"cachekey",
"=",
"'rep:'",
".",
"$",
"repositoryid",
".",
"':'",
".",
"$",
"context",
"->",
"id",
".",
"':'",
".",
"serialize",
"(",
"$",
"options",
")",
";",
"if",
"(",
"$",
"repository",
"=",
"$",
"cache",
"->",
"get",
"(",
"$",
"cachekey",
")",
")",
"{",
"return",
"$",
"repository",
";",
"}",
"if",
"(",
"!",
"$",
"record",
"=",
"$",
"cache",
"->",
"get",
"(",
"'i:'",
".",
"$",
"repositoryid",
")",
")",
"{",
"$",
"sql",
"=",
"\"SELECT i.*, r.type AS repositorytype, r.visible, r.sortorder\n FROM {repository_instances} i\n JOIN {repository} r ON r.id = i.typeid\n WHERE i.id = ?\"",
";",
"if",
"(",
"!",
"$",
"record",
"=",
"$",
"DB",
"->",
"get_record_sql",
"(",
"$",
"sql",
",",
"array",
"(",
"$",
"repositoryid",
")",
")",
")",
"{",
"throw",
"new",
"repository_exception",
"(",
"'invalidrepositoryid'",
",",
"'repository'",
")",
";",
"}",
"$",
"cache",
"->",
"set",
"(",
"'i:'",
".",
"$",
"record",
"->",
"id",
",",
"$",
"record",
")",
";",
"}",
"$",
"type",
"=",
"$",
"record",
"->",
"repositorytype",
";",
"if",
"(",
"file_exists",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"\"/repository/$type/lib.php\"",
")",
")",
"{",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"\"/repository/$type/lib.php\"",
")",
";",
"$",
"classname",
"=",
"'repository_'",
".",
"$",
"type",
";",
"$",
"options",
"[",
"'type'",
"]",
"=",
"$",
"type",
";",
"$",
"options",
"[",
"'typeid'",
"]",
"=",
"$",
"record",
"->",
"typeid",
";",
"$",
"options",
"[",
"'visible'",
"]",
"=",
"$",
"record",
"->",
"visible",
";",
"if",
"(",
"empty",
"(",
"$",
"options",
"[",
"'name'",
"]",
")",
")",
"{",
"$",
"options",
"[",
"'name'",
"]",
"=",
"$",
"record",
"->",
"name",
";",
"}",
"$",
"repository",
"=",
"new",
"$",
"classname",
"(",
"$",
"repositoryid",
",",
"$",
"context",
",",
"$",
"options",
",",
"$",
"record",
"->",
"readonly",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"repository",
"->",
"super_called",
")",
")",
"{",
"// to make sure the super construct is called",
"debugging",
"(",
"'parent::__construct must be called by '",
".",
"$",
"type",
".",
"' plugin.'",
")",
";",
"}",
"$",
"cache",
"->",
"set",
"(",
"$",
"cachekey",
",",
"$",
"repository",
")",
";",
"return",
"$",
"repository",
";",
"}",
"else",
"{",
"throw",
"new",
"repository_exception",
"(",
"'invalidplugin'",
",",
"'repository'",
")",
";",
"}",
"}"
] |
Get repository instance using repository id
Note that this function does not check permission to access repository contents
@throws repository_exception
@param int $repositoryid repository instance ID
@param context|int $context context instance or context ID where this repository will be used
@param array $options additional repository options
@return repository
|
[
"Get",
"repository",
"instance",
"using",
"repository",
"id"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L587-L629
|
219,160
|
moodle/moodle
|
repository/lib.php
|
repository.get_typename
|
public function get_typename() {
if (empty($this->typename)) {
$matches = array();
if (!preg_match("/^repository_(.*)$/", get_class($this), $matches)) {
throw new coding_exception('The class name of a repository should be repository_<typeofrepository>, '.
'e.g. repository_dropbox');
}
$this->typename = $matches[1];
}
return $this->typename;
}
|
php
|
public function get_typename() {
if (empty($this->typename)) {
$matches = array();
if (!preg_match("/^repository_(.*)$/", get_class($this), $matches)) {
throw new coding_exception('The class name of a repository should be repository_<typeofrepository>, '.
'e.g. repository_dropbox');
}
$this->typename = $matches[1];
}
return $this->typename;
}
|
[
"public",
"function",
"get_typename",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"typename",
")",
")",
"{",
"$",
"matches",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"preg_match",
"(",
"\"/^repository_(.*)$/\"",
",",
"get_class",
"(",
"$",
"this",
")",
",",
"$",
"matches",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The class name of a repository should be repository_<typeofrepository>, '",
".",
"'e.g. repository_dropbox'",
")",
";",
"}",
"$",
"this",
"->",
"typename",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"typename",
";",
"}"
] |
Returns the type name of the repository.
@return string type name of the repository.
@since Moodle 2.5
|
[
"Returns",
"the",
"type",
"name",
"of",
"the",
"repository",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L637-L647
|
219,161
|
moodle/moodle
|
repository/lib.php
|
repository.get_type_by_typename
|
public static function get_type_by_typename($typename) {
global $DB;
$cache = cache::make('core', 'repositories');
if (($repositorytype = $cache->get('typename:'. $typename)) === false) {
$repositorytype = null;
if ($record = $DB->get_record('repository', array('type' => $typename))) {
$repositorytype = new repository_type($record->type, (array)get_config($record->type), $record->visible, $record->sortorder);
$cache->set('typeid:'. $record->id, $repositorytype);
}
$cache->set('typename:'. $typename, $repositorytype);
}
return $repositorytype;
}
|
php
|
public static function get_type_by_typename($typename) {
global $DB;
$cache = cache::make('core', 'repositories');
if (($repositorytype = $cache->get('typename:'. $typename)) === false) {
$repositorytype = null;
if ($record = $DB->get_record('repository', array('type' => $typename))) {
$repositorytype = new repository_type($record->type, (array)get_config($record->type), $record->visible, $record->sortorder);
$cache->set('typeid:'. $record->id, $repositorytype);
}
$cache->set('typename:'. $typename, $repositorytype);
}
return $repositorytype;
}
|
[
"public",
"static",
"function",
"get_type_by_typename",
"(",
"$",
"typename",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"cache",
"=",
"cache",
"::",
"make",
"(",
"'core'",
",",
"'repositories'",
")",
";",
"if",
"(",
"(",
"$",
"repositorytype",
"=",
"$",
"cache",
"->",
"get",
"(",
"'typename:'",
".",
"$",
"typename",
")",
")",
"===",
"false",
")",
"{",
"$",
"repositorytype",
"=",
"null",
";",
"if",
"(",
"$",
"record",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'repository'",
",",
"array",
"(",
"'type'",
"=>",
"$",
"typename",
")",
")",
")",
"{",
"$",
"repositorytype",
"=",
"new",
"repository_type",
"(",
"$",
"record",
"->",
"type",
",",
"(",
"array",
")",
"get_config",
"(",
"$",
"record",
"->",
"type",
")",
",",
"$",
"record",
"->",
"visible",
",",
"$",
"record",
"->",
"sortorder",
")",
";",
"$",
"cache",
"->",
"set",
"(",
"'typeid:'",
".",
"$",
"record",
"->",
"id",
",",
"$",
"repositorytype",
")",
";",
"}",
"$",
"cache",
"->",
"set",
"(",
"'typename:'",
".",
"$",
"typename",
",",
"$",
"repositorytype",
")",
";",
"}",
"return",
"$",
"repositorytype",
";",
"}"
] |
Get a repository type object by a given type name.
@static
@param string $typename the repository type name
@return repository_type|bool
|
[
"Get",
"a",
"repository",
"type",
"object",
"by",
"a",
"given",
"type",
"name",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L656-L668
|
219,162
|
moodle/moodle
|
repository/lib.php
|
repository.check_capability
|
public final function check_capability() {
global $USER;
// The context we are on.
$currentcontext = $this->context;
// Ensure that the user can view the repository in the current context.
$can = has_capability('repository/'.$this->get_typename().':view', $currentcontext);
// Context in which the repository has been created.
$repocontext = context::instance_by_id($this->instance->contextid);
// Prevent access to private repositories when logged in as.
if ($can && \core\session\manager::is_loggedinas()) {
if ($this->contains_private_data() || $repocontext->contextlevel == CONTEXT_USER) {
$can = false;
}
}
// We are going to ensure that the current context was legit, and reliable to check
// the capability against. (No need to do that if we already cannot).
if ($can) {
if ($repocontext->contextlevel == CONTEXT_USER) {
// The repository is a user instance, ensure we're the right user to access it!
if ($repocontext->instanceid != $USER->id) {
$can = false;
}
} else if ($repocontext->contextlevel == CONTEXT_COURSE) {
// The repository is a course one. Let's check that we are on the right course.
if (in_array($currentcontext->contextlevel, array(CONTEXT_COURSE, CONTEXT_MODULE, CONTEXT_BLOCK))) {
$coursecontext = $currentcontext->get_course_context();
if ($coursecontext->instanceid != $repocontext->instanceid) {
$can = false;
}
} else {
// We are on a parent context, therefore it's legit to check the permissions
// in the current context.
}
} else {
// Nothing to check here, system instances can have different permissions on different
// levels. We do not want to prevent URL hack here, because it does not make sense to
// prevent a user to access a repository in a context if it's accessible in another one.
}
}
if ($can) {
return true;
}
throw new repository_exception('nopermissiontoaccess', 'repository');
}
|
php
|
public final function check_capability() {
global $USER;
// The context we are on.
$currentcontext = $this->context;
// Ensure that the user can view the repository in the current context.
$can = has_capability('repository/'.$this->get_typename().':view', $currentcontext);
// Context in which the repository has been created.
$repocontext = context::instance_by_id($this->instance->contextid);
// Prevent access to private repositories when logged in as.
if ($can && \core\session\manager::is_loggedinas()) {
if ($this->contains_private_data() || $repocontext->contextlevel == CONTEXT_USER) {
$can = false;
}
}
// We are going to ensure that the current context was legit, and reliable to check
// the capability against. (No need to do that if we already cannot).
if ($can) {
if ($repocontext->contextlevel == CONTEXT_USER) {
// The repository is a user instance, ensure we're the right user to access it!
if ($repocontext->instanceid != $USER->id) {
$can = false;
}
} else if ($repocontext->contextlevel == CONTEXT_COURSE) {
// The repository is a course one. Let's check that we are on the right course.
if (in_array($currentcontext->contextlevel, array(CONTEXT_COURSE, CONTEXT_MODULE, CONTEXT_BLOCK))) {
$coursecontext = $currentcontext->get_course_context();
if ($coursecontext->instanceid != $repocontext->instanceid) {
$can = false;
}
} else {
// We are on a parent context, therefore it's legit to check the permissions
// in the current context.
}
} else {
// Nothing to check here, system instances can have different permissions on different
// levels. We do not want to prevent URL hack here, because it does not make sense to
// prevent a user to access a repository in a context if it's accessible in another one.
}
}
if ($can) {
return true;
}
throw new repository_exception('nopermissiontoaccess', 'repository');
}
|
[
"public",
"final",
"function",
"check_capability",
"(",
")",
"{",
"global",
"$",
"USER",
";",
"// The context we are on.",
"$",
"currentcontext",
"=",
"$",
"this",
"->",
"context",
";",
"// Ensure that the user can view the repository in the current context.",
"$",
"can",
"=",
"has_capability",
"(",
"'repository/'",
".",
"$",
"this",
"->",
"get_typename",
"(",
")",
".",
"':view'",
",",
"$",
"currentcontext",
")",
";",
"// Context in which the repository has been created.",
"$",
"repocontext",
"=",
"context",
"::",
"instance_by_id",
"(",
"$",
"this",
"->",
"instance",
"->",
"contextid",
")",
";",
"// Prevent access to private repositories when logged in as.",
"if",
"(",
"$",
"can",
"&&",
"\\",
"core",
"\\",
"session",
"\\",
"manager",
"::",
"is_loggedinas",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"contains_private_data",
"(",
")",
"||",
"$",
"repocontext",
"->",
"contextlevel",
"==",
"CONTEXT_USER",
")",
"{",
"$",
"can",
"=",
"false",
";",
"}",
"}",
"// We are going to ensure that the current context was legit, and reliable to check",
"// the capability against. (No need to do that if we already cannot).",
"if",
"(",
"$",
"can",
")",
"{",
"if",
"(",
"$",
"repocontext",
"->",
"contextlevel",
"==",
"CONTEXT_USER",
")",
"{",
"// The repository is a user instance, ensure we're the right user to access it!",
"if",
"(",
"$",
"repocontext",
"->",
"instanceid",
"!=",
"$",
"USER",
"->",
"id",
")",
"{",
"$",
"can",
"=",
"false",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"repocontext",
"->",
"contextlevel",
"==",
"CONTEXT_COURSE",
")",
"{",
"// The repository is a course one. Let's check that we are on the right course.",
"if",
"(",
"in_array",
"(",
"$",
"currentcontext",
"->",
"contextlevel",
",",
"array",
"(",
"CONTEXT_COURSE",
",",
"CONTEXT_MODULE",
",",
"CONTEXT_BLOCK",
")",
")",
")",
"{",
"$",
"coursecontext",
"=",
"$",
"currentcontext",
"->",
"get_course_context",
"(",
")",
";",
"if",
"(",
"$",
"coursecontext",
"->",
"instanceid",
"!=",
"$",
"repocontext",
"->",
"instanceid",
")",
"{",
"$",
"can",
"=",
"false",
";",
"}",
"}",
"else",
"{",
"// We are on a parent context, therefore it's legit to check the permissions",
"// in the current context.",
"}",
"}",
"else",
"{",
"// Nothing to check here, system instances can have different permissions on different",
"// levels. We do not want to prevent URL hack here, because it does not make sense to",
"// prevent a user to access a repository in a context if it's accessible in another one.",
"}",
"}",
"if",
"(",
"$",
"can",
")",
"{",
"return",
"true",
";",
"}",
"throw",
"new",
"repository_exception",
"(",
"'nopermissiontoaccess'",
",",
"'repository'",
")",
";",
"}"
] |
Checks if user has a capability to view the current repository.
@return bool true when the user can, otherwise throws an exception.
@throws repository_exception when the user does not meet the requirements.
|
[
"Checks",
"if",
"user",
"has",
"a",
"capability",
"to",
"view",
"the",
"current",
"repository",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L746-L796
|
219,163
|
moodle/moodle
|
repository/lib.php
|
repository.draftfile_exists
|
public static function draftfile_exists($itemid, $filepath, $filename) {
global $USER;
$fs = get_file_storage();
$usercontext = context_user::instance($USER->id);
return $fs->file_exists($usercontext->id, 'user', 'draft', $itemid, $filepath, $filename);
}
|
php
|
public static function draftfile_exists($itemid, $filepath, $filename) {
global $USER;
$fs = get_file_storage();
$usercontext = context_user::instance($USER->id);
return $fs->file_exists($usercontext->id, 'user', 'draft', $itemid, $filepath, $filename);
}
|
[
"public",
"static",
"function",
"draftfile_exists",
"(",
"$",
"itemid",
",",
"$",
"filepath",
",",
"$",
"filename",
")",
"{",
"global",
"$",
"USER",
";",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"$",
"usercontext",
"=",
"context_user",
"::",
"instance",
"(",
"$",
"USER",
"->",
"id",
")",
";",
"return",
"$",
"fs",
"->",
"file_exists",
"(",
"$",
"usercontext",
"->",
"id",
",",
"'user'",
",",
"'draft'",
",",
"$",
"itemid",
",",
"$",
"filepath",
",",
"$",
"filename",
")",
";",
"}"
] |
Check if file already exists in draft area.
@static
@param int $itemid of the draft area.
@param string $filepath path to the file.
@param string $filename file name.
@return bool
|
[
"Check",
"if",
"file",
"already",
"exists",
"in",
"draft",
"area",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L807-L812
|
219,164
|
moodle/moodle
|
repository/lib.php
|
repository.get_moodle_file
|
public static function get_moodle_file($reference) {
$params = file_storage::unpack_reference($reference, true);
$fs = get_file_storage();
return $fs->get_file($params['contextid'], $params['component'], $params['filearea'],
$params['itemid'], $params['filepath'], $params['filename']);
}
|
php
|
public static function get_moodle_file($reference) {
$params = file_storage::unpack_reference($reference, true);
$fs = get_file_storage();
return $fs->get_file($params['contextid'], $params['component'], $params['filearea'],
$params['itemid'], $params['filepath'], $params['filename']);
}
|
[
"public",
"static",
"function",
"get_moodle_file",
"(",
"$",
"reference",
")",
"{",
"$",
"params",
"=",
"file_storage",
"::",
"unpack_reference",
"(",
"$",
"reference",
",",
"true",
")",
";",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"return",
"$",
"fs",
"->",
"get_file",
"(",
"$",
"params",
"[",
"'contextid'",
"]",
",",
"$",
"params",
"[",
"'component'",
"]",
",",
"$",
"params",
"[",
"'filearea'",
"]",
",",
"$",
"params",
"[",
"'itemid'",
"]",
",",
"$",
"params",
"[",
"'filepath'",
"]",
",",
"$",
"params",
"[",
"'filename'",
"]",
")",
";",
"}"
] |
Parses the moodle file reference and returns an instance of stored_file
@param string $reference reference to the moodle internal file as retruned by
{@link repository::get_file_reference()} or {@link file_storage::pack_reference()}
@return stored_file|null
|
[
"Parses",
"the",
"moodle",
"file",
"reference",
"and",
"returns",
"an",
"instance",
"of",
"stored_file"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L821-L826
|
219,165
|
moodle/moodle
|
repository/lib.php
|
repository.get_unused_filename
|
public static function get_unused_filename($itemid, $filepath, $filename) {
global $USER;
$contextid = context_user::instance($USER->id)->id;
$fs = get_file_storage();
return $fs->get_unused_filename($contextid, 'user', 'draft', $itemid, $filepath, $filename);
}
|
php
|
public static function get_unused_filename($itemid, $filepath, $filename) {
global $USER;
$contextid = context_user::instance($USER->id)->id;
$fs = get_file_storage();
return $fs->get_unused_filename($contextid, 'user', 'draft', $itemid, $filepath, $filename);
}
|
[
"public",
"static",
"function",
"get_unused_filename",
"(",
"$",
"itemid",
",",
"$",
"filepath",
",",
"$",
"filename",
")",
"{",
"global",
"$",
"USER",
";",
"$",
"contextid",
"=",
"context_user",
"::",
"instance",
"(",
"$",
"USER",
"->",
"id",
")",
"->",
"id",
";",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"return",
"$",
"fs",
"->",
"get_unused_filename",
"(",
"$",
"contextid",
",",
"'user'",
",",
"'draft'",
",",
"$",
"itemid",
",",
"$",
"filepath",
",",
"$",
"filename",
")",
";",
"}"
] |
Get an unused filename from the current draft area.
Will check if the file ends with ([0-9]) and increase the number.
@static
@param int $itemid draft item ID.
@param string $filepath path to the file.
@param string $filename name of the file.
@return string an unused file name.
|
[
"Get",
"an",
"unused",
"filename",
"from",
"the",
"current",
"draft",
"area",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L942-L947
|
219,166
|
moodle/moodle
|
repository/lib.php
|
repository.append_suffix
|
public static function append_suffix($filename) {
debugging('The function repository::append_suffix() has been deprecated. Use repository::get_unused_filename() instead.',
DEBUG_DEVELOPER);
$pathinfo = pathinfo($filename);
if (empty($pathinfo['extension'])) {
return $filename . RENAME_SUFFIX;
} else {
return $pathinfo['filename'] . RENAME_SUFFIX . '.' . $pathinfo['extension'];
}
}
|
php
|
public static function append_suffix($filename) {
debugging('The function repository::append_suffix() has been deprecated. Use repository::get_unused_filename() instead.',
DEBUG_DEVELOPER);
$pathinfo = pathinfo($filename);
if (empty($pathinfo['extension'])) {
return $filename . RENAME_SUFFIX;
} else {
return $pathinfo['filename'] . RENAME_SUFFIX . '.' . $pathinfo['extension'];
}
}
|
[
"public",
"static",
"function",
"append_suffix",
"(",
"$",
"filename",
")",
"{",
"debugging",
"(",
"'The function repository::append_suffix() has been deprecated. Use repository::get_unused_filename() instead.'",
",",
"DEBUG_DEVELOPER",
")",
";",
"$",
"pathinfo",
"=",
"pathinfo",
"(",
"$",
"filename",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"pathinfo",
"[",
"'extension'",
"]",
")",
")",
"{",
"return",
"$",
"filename",
".",
"RENAME_SUFFIX",
";",
"}",
"else",
"{",
"return",
"$",
"pathinfo",
"[",
"'filename'",
"]",
".",
"RENAME_SUFFIX",
".",
"'.'",
".",
"$",
"pathinfo",
"[",
"'extension'",
"]",
";",
"}",
"}"
] |
Append a suffix to filename.
@static
@param string $filename
@return string
@deprecated since 2.5
|
[
"Append",
"a",
"suffix",
"to",
"filename",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L957-L966
|
219,167
|
moodle/moodle
|
repository/lib.php
|
repository.static_function
|
public static function static_function($plugin, $function) {
global $CFG;
//check that the plugin exists
$typedirectory = $CFG->dirroot . '/repository/'. $plugin . '/lib.php';
if (!file_exists($typedirectory)) {
//throw new repository_exception('invalidplugin', 'repository');
return false;
}
$args = func_get_args();
if (count($args) <= 2) {
$args = array();
} else {
array_shift($args);
array_shift($args);
}
require_once($typedirectory);
return call_user_func_array(array('repository_' . $plugin, $function), $args);
}
|
php
|
public static function static_function($plugin, $function) {
global $CFG;
//check that the plugin exists
$typedirectory = $CFG->dirroot . '/repository/'. $plugin . '/lib.php';
if (!file_exists($typedirectory)) {
//throw new repository_exception('invalidplugin', 'repository');
return false;
}
$args = func_get_args();
if (count($args) <= 2) {
$args = array();
} else {
array_shift($args);
array_shift($args);
}
require_once($typedirectory);
return call_user_func_array(array('repository_' . $plugin, $function), $args);
}
|
[
"public",
"static",
"function",
"static_function",
"(",
"$",
"plugin",
",",
"$",
"function",
")",
"{",
"global",
"$",
"CFG",
";",
"//check that the plugin exists",
"$",
"typedirectory",
"=",
"$",
"CFG",
"->",
"dirroot",
".",
"'/repository/'",
".",
"$",
"plugin",
".",
"'/lib.php'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"typedirectory",
")",
")",
"{",
"//throw new repository_exception('invalidplugin', 'repository');",
"return",
"false",
";",
"}",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"args",
")",
"<=",
"2",
")",
"{",
"$",
"args",
"=",
"array",
"(",
")",
";",
"}",
"else",
"{",
"array_shift",
"(",
"$",
"args",
")",
";",
"array_shift",
"(",
"$",
"args",
")",
";",
"}",
"require_once",
"(",
"$",
"typedirectory",
")",
";",
"return",
"call_user_func_array",
"(",
"array",
"(",
"'repository_'",
".",
"$",
"plugin",
",",
"$",
"function",
")",
",",
"$",
"args",
")",
";",
"}"
] |
Call a static function. Any additional arguments than plugin and function will be passed through.
@static
@param string $plugin repository plugin name
@param string $function function name
@return mixed
|
[
"Call",
"a",
"static",
"function",
".",
"Any",
"additional",
"arguments",
"than",
"plugin",
"and",
"function",
"will",
"be",
"passed",
"through",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L1163-L1183
|
219,168
|
moodle/moodle
|
repository/lib.php
|
repository.antivir_scan_file
|
public static function antivir_scan_file($thefile, $filename, $deleteinfected) {
debugging('Please upgrade your code to use \core\antivirus\manager::scan_file instead', DEBUG_DEVELOPER);
\core\antivirus\manager::scan_file($thefile, $filename, $deleteinfected);
}
|
php
|
public static function antivir_scan_file($thefile, $filename, $deleteinfected) {
debugging('Please upgrade your code to use \core\antivirus\manager::scan_file instead', DEBUG_DEVELOPER);
\core\antivirus\manager::scan_file($thefile, $filename, $deleteinfected);
}
|
[
"public",
"static",
"function",
"antivir_scan_file",
"(",
"$",
"thefile",
",",
"$",
"filename",
",",
"$",
"deleteinfected",
")",
"{",
"debugging",
"(",
"'Please upgrade your code to use \\core\\antivirus\\manager::scan_file instead'",
",",
"DEBUG_DEVELOPER",
")",
";",
"\\",
"core",
"\\",
"antivirus",
"\\",
"manager",
"::",
"scan_file",
"(",
"$",
"thefile",
",",
"$",
"filename",
",",
"$",
"deleteinfected",
")",
";",
"}"
] |
Scan file, throws exception in case of infected file.
Please note that the scanning engine must be able to access the file,
permissions of the file are not modified here!
@static
@deprecated since Moodle 3.0
@param string $thefile
@param string $filename name of the file
@param bool $deleteinfected
|
[
"Scan",
"file",
"throws",
"exception",
"in",
"case",
"of",
"infected",
"file",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L1197-L1200
|
219,169
|
moodle/moodle
|
repository/lib.php
|
repository.move_to_filepool
|
public static function move_to_filepool($thefile, $record) {
global $DB, $CFG, $USER, $OUTPUT;
// scan for viruses if possible, throws exception if problem found
// TODO: MDL-28637 this repository_no_delete is a bloody hack!
\core\antivirus\manager::scan_file($thefile, $record->filename, empty($CFG->repository_no_delete));
$fs = get_file_storage();
// If file name being used.
if (repository::draftfile_exists($record->itemid, $record->filepath, $record->filename)) {
$draftitemid = $record->itemid;
$new_filename = repository::get_unused_filename($draftitemid, $record->filepath, $record->filename);
$old_filename = $record->filename;
// Create a tmp file.
$record->filename = $new_filename;
$newfile = $fs->create_file_from_pathname($record, $thefile);
$event = array();
$event['event'] = 'fileexists';
$event['newfile'] = new stdClass;
$event['newfile']->filepath = $record->filepath;
$event['newfile']->filename = $new_filename;
$event['newfile']->url = moodle_url::make_draftfile_url($draftitemid, $record->filepath, $new_filename)->out();
$event['existingfile'] = new stdClass;
$event['existingfile']->filepath = $record->filepath;
$event['existingfile']->filename = $old_filename;
$event['existingfile']->url = moodle_url::make_draftfile_url($draftitemid, $record->filepath, $old_filename)->out();
return $event;
}
if ($file = $fs->create_file_from_pathname($record, $thefile)) {
if (empty($CFG->repository_no_delete)) {
$delete = unlink($thefile);
unset($CFG->repository_no_delete);
}
return array(
'url'=>moodle_url::make_draftfile_url($file->get_itemid(), $file->get_filepath(), $file->get_filename())->out(),
'id'=>$file->get_itemid(),
'file'=>$file->get_filename(),
'icon' => $OUTPUT->image_url(file_extension_icon($thefile, 32))->out(),
);
} else {
return null;
}
}
|
php
|
public static function move_to_filepool($thefile, $record) {
global $DB, $CFG, $USER, $OUTPUT;
// scan for viruses if possible, throws exception if problem found
// TODO: MDL-28637 this repository_no_delete is a bloody hack!
\core\antivirus\manager::scan_file($thefile, $record->filename, empty($CFG->repository_no_delete));
$fs = get_file_storage();
// If file name being used.
if (repository::draftfile_exists($record->itemid, $record->filepath, $record->filename)) {
$draftitemid = $record->itemid;
$new_filename = repository::get_unused_filename($draftitemid, $record->filepath, $record->filename);
$old_filename = $record->filename;
// Create a tmp file.
$record->filename = $new_filename;
$newfile = $fs->create_file_from_pathname($record, $thefile);
$event = array();
$event['event'] = 'fileexists';
$event['newfile'] = new stdClass;
$event['newfile']->filepath = $record->filepath;
$event['newfile']->filename = $new_filename;
$event['newfile']->url = moodle_url::make_draftfile_url($draftitemid, $record->filepath, $new_filename)->out();
$event['existingfile'] = new stdClass;
$event['existingfile']->filepath = $record->filepath;
$event['existingfile']->filename = $old_filename;
$event['existingfile']->url = moodle_url::make_draftfile_url($draftitemid, $record->filepath, $old_filename)->out();
return $event;
}
if ($file = $fs->create_file_from_pathname($record, $thefile)) {
if (empty($CFG->repository_no_delete)) {
$delete = unlink($thefile);
unset($CFG->repository_no_delete);
}
return array(
'url'=>moodle_url::make_draftfile_url($file->get_itemid(), $file->get_filepath(), $file->get_filename())->out(),
'id'=>$file->get_itemid(),
'file'=>$file->get_filename(),
'icon' => $OUTPUT->image_url(file_extension_icon($thefile, 32))->out(),
);
} else {
return null;
}
}
|
[
"public",
"static",
"function",
"move_to_filepool",
"(",
"$",
"thefile",
",",
"$",
"record",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"CFG",
",",
"$",
"USER",
",",
"$",
"OUTPUT",
";",
"// scan for viruses if possible, throws exception if problem found",
"// TODO: MDL-28637 this repository_no_delete is a bloody hack!",
"\\",
"core",
"\\",
"antivirus",
"\\",
"manager",
"::",
"scan_file",
"(",
"$",
"thefile",
",",
"$",
"record",
"->",
"filename",
",",
"empty",
"(",
"$",
"CFG",
"->",
"repository_no_delete",
")",
")",
";",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"// If file name being used.",
"if",
"(",
"repository",
"::",
"draftfile_exists",
"(",
"$",
"record",
"->",
"itemid",
",",
"$",
"record",
"->",
"filepath",
",",
"$",
"record",
"->",
"filename",
")",
")",
"{",
"$",
"draftitemid",
"=",
"$",
"record",
"->",
"itemid",
";",
"$",
"new_filename",
"=",
"repository",
"::",
"get_unused_filename",
"(",
"$",
"draftitemid",
",",
"$",
"record",
"->",
"filepath",
",",
"$",
"record",
"->",
"filename",
")",
";",
"$",
"old_filename",
"=",
"$",
"record",
"->",
"filename",
";",
"// Create a tmp file.",
"$",
"record",
"->",
"filename",
"=",
"$",
"new_filename",
";",
"$",
"newfile",
"=",
"$",
"fs",
"->",
"create_file_from_pathname",
"(",
"$",
"record",
",",
"$",
"thefile",
")",
";",
"$",
"event",
"=",
"array",
"(",
")",
";",
"$",
"event",
"[",
"'event'",
"]",
"=",
"'fileexists'",
";",
"$",
"event",
"[",
"'newfile'",
"]",
"=",
"new",
"stdClass",
";",
"$",
"event",
"[",
"'newfile'",
"]",
"->",
"filepath",
"=",
"$",
"record",
"->",
"filepath",
";",
"$",
"event",
"[",
"'newfile'",
"]",
"->",
"filename",
"=",
"$",
"new_filename",
";",
"$",
"event",
"[",
"'newfile'",
"]",
"->",
"url",
"=",
"moodle_url",
"::",
"make_draftfile_url",
"(",
"$",
"draftitemid",
",",
"$",
"record",
"->",
"filepath",
",",
"$",
"new_filename",
")",
"->",
"out",
"(",
")",
";",
"$",
"event",
"[",
"'existingfile'",
"]",
"=",
"new",
"stdClass",
";",
"$",
"event",
"[",
"'existingfile'",
"]",
"->",
"filepath",
"=",
"$",
"record",
"->",
"filepath",
";",
"$",
"event",
"[",
"'existingfile'",
"]",
"->",
"filename",
"=",
"$",
"old_filename",
";",
"$",
"event",
"[",
"'existingfile'",
"]",
"->",
"url",
"=",
"moodle_url",
"::",
"make_draftfile_url",
"(",
"$",
"draftitemid",
",",
"$",
"record",
"->",
"filepath",
",",
"$",
"old_filename",
")",
"->",
"out",
"(",
")",
";",
"return",
"$",
"event",
";",
"}",
"if",
"(",
"$",
"file",
"=",
"$",
"fs",
"->",
"create_file_from_pathname",
"(",
"$",
"record",
",",
"$",
"thefile",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"CFG",
"->",
"repository_no_delete",
")",
")",
"{",
"$",
"delete",
"=",
"unlink",
"(",
"$",
"thefile",
")",
";",
"unset",
"(",
"$",
"CFG",
"->",
"repository_no_delete",
")",
";",
"}",
"return",
"array",
"(",
"'url'",
"=>",
"moodle_url",
"::",
"make_draftfile_url",
"(",
"$",
"file",
"->",
"get_itemid",
"(",
")",
",",
"$",
"file",
"->",
"get_filepath",
"(",
")",
",",
"$",
"file",
"->",
"get_filename",
"(",
")",
")",
"->",
"out",
"(",
")",
",",
"'id'",
"=>",
"$",
"file",
"->",
"get_itemid",
"(",
")",
",",
"'file'",
"=>",
"$",
"file",
"->",
"get_filename",
"(",
")",
",",
"'icon'",
"=>",
"$",
"OUTPUT",
"->",
"image_url",
"(",
"file_extension_icon",
"(",
"$",
"thefile",
",",
"32",
")",
")",
"->",
"out",
"(",
")",
",",
")",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] |
Move file from download folder to file pool using FILE API
@todo MDL-28637
@static
@param string $thefile file path in download folder
@param stdClass $record
@return array containing the following keys:
icon
file
id
url
|
[
"Move",
"file",
"from",
"download",
"folder",
"to",
"file",
"pool",
"using",
"FILE",
"API"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L1344-L1387
|
219,170
|
moodle/moodle
|
repository/lib.php
|
repository.get_file
|
public function get_file($url, $filename = '') {
global $CFG;
$path = $this->prepare_file($filename);
$c = new curl;
$result = $c->download_one($url, null, array('filepath' => $path, 'timeout' => $CFG->repositorygetfiletimeout));
if ($result !== true) {
throw new moodle_exception('errorwhiledownload', 'repository', '', $result);
}
return array('path'=>$path, 'url'=>$url);
}
|
php
|
public function get_file($url, $filename = '') {
global $CFG;
$path = $this->prepare_file($filename);
$c = new curl;
$result = $c->download_one($url, null, array('filepath' => $path, 'timeout' => $CFG->repositorygetfiletimeout));
if ($result !== true) {
throw new moodle_exception('errorwhiledownload', 'repository', '', $result);
}
return array('path'=>$path, 'url'=>$url);
}
|
[
"public",
"function",
"get_file",
"(",
"$",
"url",
",",
"$",
"filename",
"=",
"''",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"prepare_file",
"(",
"$",
"filename",
")",
";",
"$",
"c",
"=",
"new",
"curl",
";",
"$",
"result",
"=",
"$",
"c",
"->",
"download_one",
"(",
"$",
"url",
",",
"null",
",",
"array",
"(",
"'filepath'",
"=>",
"$",
"path",
",",
"'timeout'",
"=>",
"$",
"CFG",
"->",
"repositorygetfiletimeout",
")",
")",
";",
"if",
"(",
"$",
"result",
"!==",
"true",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'errorwhiledownload'",
",",
"'repository'",
",",
"''",
",",
"$",
"result",
")",
";",
"}",
"return",
"array",
"(",
"'path'",
"=>",
"$",
"path",
",",
"'url'",
"=>",
"$",
"url",
")",
";",
"}"
] |
Downloads a file from external repository and saves it in temp dir
Function get_file() must be implemented by repositories that support returntypes
FILE_INTERNAL or FILE_REFERENCE. It is invoked to pick up the file and copy it
to moodle. This function is not called for moodle repositories, the function
{@link repository::copy_to_area()} is used instead.
This function can be overridden by subclass if the files.reference field contains
not just URL or if request should be done differently.
@see curl
@throws file_exception when error occured
@param string $url the content of files.reference field, in this implementaion
it is asssumed that it contains the string with URL of the file
@param string $filename filename (without path) to save the downloaded file in the
temporary directory, if omitted or file already exists the new filename will be generated
@return array with elements:
path: internal location of the file
url: URL to the source (from parameters)
|
[
"Downloads",
"a",
"file",
"from",
"external",
"repository",
"and",
"saves",
"it",
"in",
"temp",
"dir"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L1693-L1704
|
219,171
|
moodle/moodle
|
repository/lib.php
|
repository.get_file_size
|
public function get_file_size($source) {
// TODO MDL-33297 remove this function completely?
$browser = get_file_browser();
$params = unserialize(base64_decode($source));
$contextid = clean_param($params['contextid'], PARAM_INT);
$fileitemid = clean_param($params['itemid'], PARAM_INT);
$filename = clean_param($params['filename'], PARAM_FILE);
$filepath = clean_param($params['filepath'], PARAM_PATH);
$filearea = clean_param($params['filearea'], PARAM_AREA);
$component = clean_param($params['component'], PARAM_COMPONENT);
$context = context::instance_by_id($contextid);
$file_info = $browser->get_file_info($context, $component, $filearea, $fileitemid, $filepath, $filename);
if (!empty($file_info)) {
$filesize = $file_info->get_filesize();
} else {
$filesize = null;
}
return $filesize;
}
|
php
|
public function get_file_size($source) {
// TODO MDL-33297 remove this function completely?
$browser = get_file_browser();
$params = unserialize(base64_decode($source));
$contextid = clean_param($params['contextid'], PARAM_INT);
$fileitemid = clean_param($params['itemid'], PARAM_INT);
$filename = clean_param($params['filename'], PARAM_FILE);
$filepath = clean_param($params['filepath'], PARAM_PATH);
$filearea = clean_param($params['filearea'], PARAM_AREA);
$component = clean_param($params['component'], PARAM_COMPONENT);
$context = context::instance_by_id($contextid);
$file_info = $browser->get_file_info($context, $component, $filearea, $fileitemid, $filepath, $filename);
if (!empty($file_info)) {
$filesize = $file_info->get_filesize();
} else {
$filesize = null;
}
return $filesize;
}
|
[
"public",
"function",
"get_file_size",
"(",
"$",
"source",
")",
"{",
"// TODO MDL-33297 remove this function completely?",
"$",
"browser",
"=",
"get_file_browser",
"(",
")",
";",
"$",
"params",
"=",
"unserialize",
"(",
"base64_decode",
"(",
"$",
"source",
")",
")",
";",
"$",
"contextid",
"=",
"clean_param",
"(",
"$",
"params",
"[",
"'contextid'",
"]",
",",
"PARAM_INT",
")",
";",
"$",
"fileitemid",
"=",
"clean_param",
"(",
"$",
"params",
"[",
"'itemid'",
"]",
",",
"PARAM_INT",
")",
";",
"$",
"filename",
"=",
"clean_param",
"(",
"$",
"params",
"[",
"'filename'",
"]",
",",
"PARAM_FILE",
")",
";",
"$",
"filepath",
"=",
"clean_param",
"(",
"$",
"params",
"[",
"'filepath'",
"]",
",",
"PARAM_PATH",
")",
";",
"$",
"filearea",
"=",
"clean_param",
"(",
"$",
"params",
"[",
"'filearea'",
"]",
",",
"PARAM_AREA",
")",
";",
"$",
"component",
"=",
"clean_param",
"(",
"$",
"params",
"[",
"'component'",
"]",
",",
"PARAM_COMPONENT",
")",
";",
"$",
"context",
"=",
"context",
"::",
"instance_by_id",
"(",
"$",
"contextid",
")",
";",
"$",
"file_info",
"=",
"$",
"browser",
"->",
"get_file_info",
"(",
"$",
"context",
",",
"$",
"component",
",",
"$",
"filearea",
",",
"$",
"fileitemid",
",",
"$",
"filepath",
",",
"$",
"filename",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"file_info",
")",
")",
"{",
"$",
"filesize",
"=",
"$",
"file_info",
"->",
"get_filesize",
"(",
")",
";",
"}",
"else",
"{",
"$",
"filesize",
"=",
"null",
";",
"}",
"return",
"$",
"filesize",
";",
"}"
] |
Return size of a file in bytes.
@param string $source encoded and serialized data of file
@return int file size in bytes
|
[
"Return",
"size",
"of",
"a",
"file",
"in",
"bytes",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L1782-L1800
|
219,172
|
moodle/moodle
|
repository/lib.php
|
repository.can_be_edited_by_user
|
public final function can_be_edited_by_user() {
global $USER;
// We need to be able to explore the repository.
try {
$this->check_capability();
} catch (repository_exception $e) {
return false;
}
$repocontext = context::instance_by_id($this->instance->contextid);
if ($repocontext->contextlevel == CONTEXT_USER && $repocontext->instanceid != $USER->id) {
// If the context of this instance is a user context, we need to be this user.
return false;
} else if ($repocontext->contextlevel == CONTEXT_MODULE && !has_capability('moodle/course:update', $repocontext)) {
// We need to have permissions on the course to edit the instance.
return false;
} else if ($repocontext->contextlevel == CONTEXT_SYSTEM && !has_capability('moodle/site:config', $repocontext)) {
// Do not meet the requirements for the context system.
return false;
}
return true;
}
|
php
|
public final function can_be_edited_by_user() {
global $USER;
// We need to be able to explore the repository.
try {
$this->check_capability();
} catch (repository_exception $e) {
return false;
}
$repocontext = context::instance_by_id($this->instance->contextid);
if ($repocontext->contextlevel == CONTEXT_USER && $repocontext->instanceid != $USER->id) {
// If the context of this instance is a user context, we need to be this user.
return false;
} else if ($repocontext->contextlevel == CONTEXT_MODULE && !has_capability('moodle/course:update', $repocontext)) {
// We need to have permissions on the course to edit the instance.
return false;
} else if ($repocontext->contextlevel == CONTEXT_SYSTEM && !has_capability('moodle/site:config', $repocontext)) {
// Do not meet the requirements for the context system.
return false;
}
return true;
}
|
[
"public",
"final",
"function",
"can_be_edited_by_user",
"(",
")",
"{",
"global",
"$",
"USER",
";",
"// We need to be able to explore the repository.",
"try",
"{",
"$",
"this",
"->",
"check_capability",
"(",
")",
";",
"}",
"catch",
"(",
"repository_exception",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"$",
"repocontext",
"=",
"context",
"::",
"instance_by_id",
"(",
"$",
"this",
"->",
"instance",
"->",
"contextid",
")",
";",
"if",
"(",
"$",
"repocontext",
"->",
"contextlevel",
"==",
"CONTEXT_USER",
"&&",
"$",
"repocontext",
"->",
"instanceid",
"!=",
"$",
"USER",
"->",
"id",
")",
"{",
"// If the context of this instance is a user context, we need to be this user.",
"return",
"false",
";",
"}",
"else",
"if",
"(",
"$",
"repocontext",
"->",
"contextlevel",
"==",
"CONTEXT_MODULE",
"&&",
"!",
"has_capability",
"(",
"'moodle/course:update'",
",",
"$",
"repocontext",
")",
")",
"{",
"// We need to have permissions on the course to edit the instance.",
"return",
"false",
";",
"}",
"else",
"if",
"(",
"$",
"repocontext",
"->",
"contextlevel",
"==",
"CONTEXT_SYSTEM",
"&&",
"!",
"has_capability",
"(",
"'moodle/site:config'",
",",
"$",
"repocontext",
")",
")",
"{",
"// Do not meet the requirements for the context system.",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Can the instance be edited by the current user?
The property $readonly must not be used within this method because
it only controls if the options from self::get_instance_option_names()
can be edited.
@return bool true if the user can edit the instance.
@since Moodle 2.5
|
[
"Can",
"the",
"instance",
"be",
"edited",
"by",
"the",
"current",
"user?"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L1832-L1855
|
219,173
|
moodle/moodle
|
repository/lib.php
|
repository.get_meta
|
final public function get_meta() {
global $CFG, $OUTPUT;
$meta = new stdClass();
$meta->id = $this->id;
$meta->name = format_string($this->get_name());
$meta->type = $this->get_typename();
$meta->icon = $OUTPUT->image_url('icon', 'repository_'.$meta->type)->out(false);
$meta->supported_types = file_get_typegroup('extension', $this->supported_filetypes());
$meta->return_types = $this->supported_returntypes();
$meta->defaultreturntype = $this->default_returntype();
$meta->sortorder = $this->options['sortorder'];
return $meta;
}
|
php
|
final public function get_meta() {
global $CFG, $OUTPUT;
$meta = new stdClass();
$meta->id = $this->id;
$meta->name = format_string($this->get_name());
$meta->type = $this->get_typename();
$meta->icon = $OUTPUT->image_url('icon', 'repository_'.$meta->type)->out(false);
$meta->supported_types = file_get_typegroup('extension', $this->supported_filetypes());
$meta->return_types = $this->supported_returntypes();
$meta->defaultreturntype = $this->default_returntype();
$meta->sortorder = $this->options['sortorder'];
return $meta;
}
|
[
"final",
"public",
"function",
"get_meta",
"(",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"OUTPUT",
";",
"$",
"meta",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"meta",
"->",
"id",
"=",
"$",
"this",
"->",
"id",
";",
"$",
"meta",
"->",
"name",
"=",
"format_string",
"(",
"$",
"this",
"->",
"get_name",
"(",
")",
")",
";",
"$",
"meta",
"->",
"type",
"=",
"$",
"this",
"->",
"get_typename",
"(",
")",
";",
"$",
"meta",
"->",
"icon",
"=",
"$",
"OUTPUT",
"->",
"image_url",
"(",
"'icon'",
",",
"'repository_'",
".",
"$",
"meta",
"->",
"type",
")",
"->",
"out",
"(",
"false",
")",
";",
"$",
"meta",
"->",
"supported_types",
"=",
"file_get_typegroup",
"(",
"'extension'",
",",
"$",
"this",
"->",
"supported_filetypes",
"(",
")",
")",
";",
"$",
"meta",
"->",
"return_types",
"=",
"$",
"this",
"->",
"supported_returntypes",
"(",
")",
";",
"$",
"meta",
"->",
"defaultreturntype",
"=",
"$",
"this",
"->",
"default_returntype",
"(",
")",
";",
"$",
"meta",
"->",
"sortorder",
"=",
"$",
"this",
"->",
"options",
"[",
"'sortorder'",
"]",
";",
"return",
"$",
"meta",
";",
"}"
] |
Provide repository instance information for Ajax
@return stdClass
|
[
"Provide",
"repository",
"instance",
"information",
"for",
"Ajax"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L1931-L1943
|
219,174
|
moodle/moodle
|
repository/lib.php
|
repository.delete
|
final public function delete($downloadcontents = false) {
global $DB;
if ($downloadcontents) {
$this->convert_references_to_local();
} else {
$this->remove_files();
}
cache::make('core', 'repositories')->purge();
try {
$DB->delete_records('repository_instances', array('id'=>$this->id));
$DB->delete_records('repository_instance_config', array('instanceid'=>$this->id));
} catch (dml_exception $ex) {
return false;
}
return true;
}
|
php
|
final public function delete($downloadcontents = false) {
global $DB;
if ($downloadcontents) {
$this->convert_references_to_local();
} else {
$this->remove_files();
}
cache::make('core', 'repositories')->purge();
try {
$DB->delete_records('repository_instances', array('id'=>$this->id));
$DB->delete_records('repository_instance_config', array('instanceid'=>$this->id));
} catch (dml_exception $ex) {
return false;
}
return true;
}
|
[
"final",
"public",
"function",
"delete",
"(",
"$",
"downloadcontents",
"=",
"false",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"$",
"downloadcontents",
")",
"{",
"$",
"this",
"->",
"convert_references_to_local",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"remove_files",
"(",
")",
";",
"}",
"cache",
"::",
"make",
"(",
"'core'",
",",
"'repositories'",
")",
"->",
"purge",
"(",
")",
";",
"try",
"{",
"$",
"DB",
"->",
"delete_records",
"(",
"'repository_instances'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"id",
")",
")",
";",
"$",
"DB",
"->",
"delete_records",
"(",
"'repository_instance_config'",
",",
"array",
"(",
"'instanceid'",
"=>",
"$",
"this",
"->",
"id",
")",
")",
";",
"}",
"catch",
"(",
"dml_exception",
"$",
"ex",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
delete a repository instance
@param bool $downloadcontents
@return bool
|
[
"delete",
"a",
"repository",
"instance"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L2003-L2018
|
219,175
|
moodle/moodle
|
repository/lib.php
|
repository.delete_all_for_context
|
final public static function delete_all_for_context($contextid, $downloadcontents = true) {
global $DB;
$repoids = $DB->get_fieldset_select('repository_instances', 'id', 'contextid = :contextid', array('contextid' => $contextid));
if ($downloadcontents) {
foreach ($repoids as $repoid) {
$repo = repository::get_repository_by_id($repoid, $contextid);
$repo->convert_references_to_local();
}
}
cache::make('core', 'repositories')->purge();
$DB->delete_records_list('repository_instances', 'id', $repoids);
$DB->delete_records_list('repository_instance_config', 'instanceid', $repoids);
}
|
php
|
final public static function delete_all_for_context($contextid, $downloadcontents = true) {
global $DB;
$repoids = $DB->get_fieldset_select('repository_instances', 'id', 'contextid = :contextid', array('contextid' => $contextid));
if ($downloadcontents) {
foreach ($repoids as $repoid) {
$repo = repository::get_repository_by_id($repoid, $contextid);
$repo->convert_references_to_local();
}
}
cache::make('core', 'repositories')->purge();
$DB->delete_records_list('repository_instances', 'id', $repoids);
$DB->delete_records_list('repository_instance_config', 'instanceid', $repoids);
}
|
[
"final",
"public",
"static",
"function",
"delete_all_for_context",
"(",
"$",
"contextid",
",",
"$",
"downloadcontents",
"=",
"true",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"repoids",
"=",
"$",
"DB",
"->",
"get_fieldset_select",
"(",
"'repository_instances'",
",",
"'id'",
",",
"'contextid = :contextid'",
",",
"array",
"(",
"'contextid'",
"=>",
"$",
"contextid",
")",
")",
";",
"if",
"(",
"$",
"downloadcontents",
")",
"{",
"foreach",
"(",
"$",
"repoids",
"as",
"$",
"repoid",
")",
"{",
"$",
"repo",
"=",
"repository",
"::",
"get_repository_by_id",
"(",
"$",
"repoid",
",",
"$",
"contextid",
")",
";",
"$",
"repo",
"->",
"convert_references_to_local",
"(",
")",
";",
"}",
"}",
"cache",
"::",
"make",
"(",
"'core'",
",",
"'repositories'",
")",
"->",
"purge",
"(",
")",
";",
"$",
"DB",
"->",
"delete_records_list",
"(",
"'repository_instances'",
",",
"'id'",
",",
"$",
"repoids",
")",
";",
"$",
"DB",
"->",
"delete_records_list",
"(",
"'repository_instance_config'",
",",
"'instanceid'",
",",
"$",
"repoids",
")",
";",
"}"
] |
Delete all the instances associated to a context.
This method is intended to be a callback when deleting
a course or a user to delete all the instances associated
to their context. The usual way to delete a single instance
is to use {@link self::delete()}.
@param int $contextid context ID.
@param boolean $downloadcontents true to convert references to hard copies.
@return void
|
[
"Delete",
"all",
"the",
"instances",
"associated",
"to",
"a",
"context",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L2032-L2044
|
219,176
|
moodle/moodle
|
repository/lib.php
|
repository.get_option
|
public function get_option($config = '') {
global $DB;
$cache = cache::make('core', 'repositories');
if (($entries = $cache->get('ops:'. $this->id)) === false) {
$entries = $DB->get_records('repository_instance_config', array('instanceid' => $this->id));
$cache->set('ops:'. $this->id, $entries);
}
$ret = array();
foreach($entries as $entry) {
$ret[$entry->name] = $entry->value;
}
if (!empty($config)) {
if (isset($ret[$config])) {
return $ret[$config];
} else {
return null;
}
} else {
return $ret;
}
}
|
php
|
public function get_option($config = '') {
global $DB;
$cache = cache::make('core', 'repositories');
if (($entries = $cache->get('ops:'. $this->id)) === false) {
$entries = $DB->get_records('repository_instance_config', array('instanceid' => $this->id));
$cache->set('ops:'. $this->id, $entries);
}
$ret = array();
foreach($entries as $entry) {
$ret[$entry->name] = $entry->value;
}
if (!empty($config)) {
if (isset($ret[$config])) {
return $ret[$config];
} else {
return null;
}
} else {
return $ret;
}
}
|
[
"public",
"function",
"get_option",
"(",
"$",
"config",
"=",
"''",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"cache",
"=",
"cache",
"::",
"make",
"(",
"'core'",
",",
"'repositories'",
")",
";",
"if",
"(",
"(",
"$",
"entries",
"=",
"$",
"cache",
"->",
"get",
"(",
"'ops:'",
".",
"$",
"this",
"->",
"id",
")",
")",
"===",
"false",
")",
"{",
"$",
"entries",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'repository_instance_config'",
",",
"array",
"(",
"'instanceid'",
"=>",
"$",
"this",
"->",
"id",
")",
")",
";",
"$",
"cache",
"->",
"set",
"(",
"'ops:'",
".",
"$",
"this",
"->",
"id",
",",
"$",
"entries",
")",
";",
"}",
"$",
"ret",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"entries",
"as",
"$",
"entry",
")",
"{",
"$",
"ret",
"[",
"$",
"entry",
"->",
"name",
"]",
"=",
"$",
"entry",
"->",
"value",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"config",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"ret",
"[",
"$",
"config",
"]",
")",
")",
"{",
"return",
"$",
"ret",
"[",
"$",
"config",
"]",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}",
"else",
"{",
"return",
"$",
"ret",
";",
"}",
"}"
] |
Get settings for repository instance.
@param string $config a specific option to get.
@return mixed returns an array of options. If $config is not empty, then it returns that option,
or null if the option does not exist.
|
[
"Get",
"settings",
"for",
"repository",
"instance",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L2112-L2134
|
219,177
|
moodle/moodle
|
repository/lib.php
|
repository.filter
|
public function filter(&$value) {
$accepted_types = optional_param_array('accepted_types', '', PARAM_RAW);
if (isset($value['children'])) {
if (!empty($value['children'])) {
$value['children'] = array_filter($value['children'], array($this, 'filter'));
}
return true; // always return directories
} else {
if ($accepted_types == '*' or empty($accepted_types)
or (is_array($accepted_types) and in_array('*', $accepted_types))) {
return true;
} else {
foreach ($accepted_types as $ext) {
if (preg_match('#'.$ext.'$#i', $value['title'])) {
return true;
}
}
}
}
return false;
}
|
php
|
public function filter(&$value) {
$accepted_types = optional_param_array('accepted_types', '', PARAM_RAW);
if (isset($value['children'])) {
if (!empty($value['children'])) {
$value['children'] = array_filter($value['children'], array($this, 'filter'));
}
return true; // always return directories
} else {
if ($accepted_types == '*' or empty($accepted_types)
or (is_array($accepted_types) and in_array('*', $accepted_types))) {
return true;
} else {
foreach ($accepted_types as $ext) {
if (preg_match('#'.$ext.'$#i', $value['title'])) {
return true;
}
}
}
}
return false;
}
|
[
"public",
"function",
"filter",
"(",
"&",
"$",
"value",
")",
"{",
"$",
"accepted_types",
"=",
"optional_param_array",
"(",
"'accepted_types'",
",",
"''",
",",
"PARAM_RAW",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"value",
"[",
"'children'",
"]",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"value",
"[",
"'children'",
"]",
")",
")",
"{",
"$",
"value",
"[",
"'children'",
"]",
"=",
"array_filter",
"(",
"$",
"value",
"[",
"'children'",
"]",
",",
"array",
"(",
"$",
"this",
",",
"'filter'",
")",
")",
";",
"}",
"return",
"true",
";",
"// always return directories",
"}",
"else",
"{",
"if",
"(",
"$",
"accepted_types",
"==",
"'*'",
"or",
"empty",
"(",
"$",
"accepted_types",
")",
"or",
"(",
"is_array",
"(",
"$",
"accepted_types",
")",
"and",
"in_array",
"(",
"'*'",
",",
"$",
"accepted_types",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"accepted_types",
"as",
"$",
"ext",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'#'",
".",
"$",
"ext",
".",
"'$#i'",
",",
"$",
"value",
"[",
"'title'",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] |
Filter file listing to display specific types
@param array $value
@return bool
|
[
"Filter",
"file",
"listing",
"to",
"display",
"specific",
"types"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L2142-L2162
|
219,178
|
moodle/moodle
|
repository/lib.php
|
repository.prepare_breadcrumb
|
protected static function prepare_breadcrumb($breadcrumb) {
global $OUTPUT;
$foldericon = $OUTPUT->image_url(file_folder_icon(24))->out(false);
$len = count($breadcrumb);
for ($i = 0; $i < $len; $i++) {
if (is_array($breadcrumb[$i]) && !isset($breadcrumb[$i]['icon'])) {
$breadcrumb[$i]['icon'] = $foldericon;
} else if (is_object($breadcrumb[$i]) && !isset($breadcrumb[$i]->icon)) {
$breadcrumb[$i]->icon = $foldericon;
}
}
return $breadcrumb;
}
|
php
|
protected static function prepare_breadcrumb($breadcrumb) {
global $OUTPUT;
$foldericon = $OUTPUT->image_url(file_folder_icon(24))->out(false);
$len = count($breadcrumb);
for ($i = 0; $i < $len; $i++) {
if (is_array($breadcrumb[$i]) && !isset($breadcrumb[$i]['icon'])) {
$breadcrumb[$i]['icon'] = $foldericon;
} else if (is_object($breadcrumb[$i]) && !isset($breadcrumb[$i]->icon)) {
$breadcrumb[$i]->icon = $foldericon;
}
}
return $breadcrumb;
}
|
[
"protected",
"static",
"function",
"prepare_breadcrumb",
"(",
"$",
"breadcrumb",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"$",
"foldericon",
"=",
"$",
"OUTPUT",
"->",
"image_url",
"(",
"file_folder_icon",
"(",
"24",
")",
")",
"->",
"out",
"(",
"false",
")",
";",
"$",
"len",
"=",
"count",
"(",
"$",
"breadcrumb",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"len",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"breadcrumb",
"[",
"$",
"i",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"breadcrumb",
"[",
"$",
"i",
"]",
"[",
"'icon'",
"]",
")",
")",
"{",
"$",
"breadcrumb",
"[",
"$",
"i",
"]",
"[",
"'icon'",
"]",
"=",
"$",
"foldericon",
";",
"}",
"else",
"if",
"(",
"is_object",
"(",
"$",
"breadcrumb",
"[",
"$",
"i",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"breadcrumb",
"[",
"$",
"i",
"]",
"->",
"icon",
")",
")",
"{",
"$",
"breadcrumb",
"[",
"$",
"i",
"]",
"->",
"icon",
"=",
"$",
"foldericon",
";",
"}",
"}",
"return",
"$",
"breadcrumb",
";",
"}"
] |
Prepare the breadcrumb.
@param array $breadcrumb contains each element of the breadcrumb.
@return array of breadcrumb elements.
@since Moodle 2.3.3
|
[
"Prepare",
"the",
"breadcrumb",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L2197-L2209
|
219,179
|
moodle/moodle
|
repository/lib.php
|
repository.prepare_listing
|
public static function prepare_listing($listing) {
$wasobject = false;
if (is_object($listing)) {
$listing = (array) $listing;
$wasobject = true;
}
// Prepare the breadcrumb, passed as 'path'.
if (isset($listing['path']) && is_array($listing['path'])) {
$listing['path'] = self::prepare_breadcrumb($listing['path']);
}
// Prepare the listing of objects.
if (isset($listing['list']) && is_array($listing['list'])) {
$listing['list'] = self::prepare_list($listing['list']);
}
// Convert back to an object.
if ($wasobject) {
$listing = (object) $listing;
}
return $listing;
}
|
php
|
public static function prepare_listing($listing) {
$wasobject = false;
if (is_object($listing)) {
$listing = (array) $listing;
$wasobject = true;
}
// Prepare the breadcrumb, passed as 'path'.
if (isset($listing['path']) && is_array($listing['path'])) {
$listing['path'] = self::prepare_breadcrumb($listing['path']);
}
// Prepare the listing of objects.
if (isset($listing['list']) && is_array($listing['list'])) {
$listing['list'] = self::prepare_list($listing['list']);
}
// Convert back to an object.
if ($wasobject) {
$listing = (object) $listing;
}
return $listing;
}
|
[
"public",
"static",
"function",
"prepare_listing",
"(",
"$",
"listing",
")",
"{",
"$",
"wasobject",
"=",
"false",
";",
"if",
"(",
"is_object",
"(",
"$",
"listing",
")",
")",
"{",
"$",
"listing",
"=",
"(",
"array",
")",
"$",
"listing",
";",
"$",
"wasobject",
"=",
"true",
";",
"}",
"// Prepare the breadcrumb, passed as 'path'.",
"if",
"(",
"isset",
"(",
"$",
"listing",
"[",
"'path'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"listing",
"[",
"'path'",
"]",
")",
")",
"{",
"$",
"listing",
"[",
"'path'",
"]",
"=",
"self",
"::",
"prepare_breadcrumb",
"(",
"$",
"listing",
"[",
"'path'",
"]",
")",
";",
"}",
"// Prepare the listing of objects.",
"if",
"(",
"isset",
"(",
"$",
"listing",
"[",
"'list'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"listing",
"[",
"'list'",
"]",
")",
")",
"{",
"$",
"listing",
"[",
"'list'",
"]",
"=",
"self",
"::",
"prepare_list",
"(",
"$",
"listing",
"[",
"'list'",
"]",
")",
";",
"}",
"// Convert back to an object.",
"if",
"(",
"$",
"wasobject",
")",
"{",
"$",
"listing",
"=",
"(",
"object",
")",
"$",
"listing",
";",
"}",
"return",
"$",
"listing",
";",
"}"
] |
Prepares list of files before passing it to AJAX, makes sure data is in the correct
format and stores formatted values.
@param array|stdClass $listing result of get_listing() or search() or file_get_drafarea_files()
@return array
|
[
"Prepares",
"list",
"of",
"files",
"before",
"passing",
"it",
"to",
"AJAX",
"makes",
"sure",
"data",
"is",
"in",
"the",
"correct",
"format",
"and",
"stores",
"formatted",
"values",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L2304-L2326
|
219,180
|
moodle/moodle
|
repository/lib.php
|
repository.get_short_filename
|
public function get_short_filename($str, $maxlength) {
if (core_text::strlen($str) >= $maxlength) {
return trim(core_text::substr($str, 0, $maxlength)).'...';
} else {
return $str;
}
}
|
php
|
public function get_short_filename($str, $maxlength) {
if (core_text::strlen($str) >= $maxlength) {
return trim(core_text::substr($str, 0, $maxlength)).'...';
} else {
return $str;
}
}
|
[
"public",
"function",
"get_short_filename",
"(",
"$",
"str",
",",
"$",
"maxlength",
")",
"{",
"if",
"(",
"core_text",
"::",
"strlen",
"(",
"$",
"str",
")",
">=",
"$",
"maxlength",
")",
"{",
"return",
"trim",
"(",
"core_text",
"::",
"substr",
"(",
"$",
"str",
",",
"0",
",",
"$",
"maxlength",
")",
")",
".",
"'...'",
";",
"}",
"else",
"{",
"return",
"$",
"str",
";",
"}",
"}"
] |
Create a shorten filename
@param string $str filename
@param int $maxlength max file name length
@return string short filename
|
[
"Create",
"a",
"shorten",
"filename"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L2496-L2502
|
219,181
|
moodle/moodle
|
repository/lib.php
|
repository.overwrite_existing_draftfile
|
public static function overwrite_existing_draftfile($itemid, $filepath, $filename, $newfilepath, $newfilename) {
global $USER;
$fs = get_file_storage();
$user_context = context_user::instance($USER->id);
if ($file = $fs->get_file($user_context->id, 'user', 'draft', $itemid, $filepath, $filename)) {
if ($tempfile = $fs->get_file($user_context->id, 'user', 'draft', $itemid, $newfilepath, $newfilename)) {
// Remember original file source field.
$source = @unserialize($file->get_source());
// Remember the original sortorder.
$sortorder = $file->get_sortorder();
if ($tempfile->is_external_file()) {
// New file is a reference. Check that existing file does not have any other files referencing to it
if (isset($source->original) && $fs->search_references_count($source->original)) {
return (object)array('error' => get_string('errordoublereference', 'repository'));
}
}
// delete existing file to release filename
$file->delete();
// create new file
$newfile = $fs->create_file_from_storedfile(array('filepath'=>$filepath, 'filename'=>$filename), $tempfile);
// Preserve original file location (stored in source field) for handling references
if (isset($source->original)) {
if (!($newfilesource = @unserialize($newfile->get_source()))) {
$newfilesource = new stdClass();
}
$newfilesource->original = $source->original;
$newfile->set_source(serialize($newfilesource));
}
$newfile->set_sortorder($sortorder);
// remove temp file
$tempfile->delete();
return true;
}
}
return false;
}
|
php
|
public static function overwrite_existing_draftfile($itemid, $filepath, $filename, $newfilepath, $newfilename) {
global $USER;
$fs = get_file_storage();
$user_context = context_user::instance($USER->id);
if ($file = $fs->get_file($user_context->id, 'user', 'draft', $itemid, $filepath, $filename)) {
if ($tempfile = $fs->get_file($user_context->id, 'user', 'draft', $itemid, $newfilepath, $newfilename)) {
// Remember original file source field.
$source = @unserialize($file->get_source());
// Remember the original sortorder.
$sortorder = $file->get_sortorder();
if ($tempfile->is_external_file()) {
// New file is a reference. Check that existing file does not have any other files referencing to it
if (isset($source->original) && $fs->search_references_count($source->original)) {
return (object)array('error' => get_string('errordoublereference', 'repository'));
}
}
// delete existing file to release filename
$file->delete();
// create new file
$newfile = $fs->create_file_from_storedfile(array('filepath'=>$filepath, 'filename'=>$filename), $tempfile);
// Preserve original file location (stored in source field) for handling references
if (isset($source->original)) {
if (!($newfilesource = @unserialize($newfile->get_source()))) {
$newfilesource = new stdClass();
}
$newfilesource->original = $source->original;
$newfile->set_source(serialize($newfilesource));
}
$newfile->set_sortorder($sortorder);
// remove temp file
$tempfile->delete();
return true;
}
}
return false;
}
|
[
"public",
"static",
"function",
"overwrite_existing_draftfile",
"(",
"$",
"itemid",
",",
"$",
"filepath",
",",
"$",
"filename",
",",
"$",
"newfilepath",
",",
"$",
"newfilename",
")",
"{",
"global",
"$",
"USER",
";",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"$",
"user_context",
"=",
"context_user",
"::",
"instance",
"(",
"$",
"USER",
"->",
"id",
")",
";",
"if",
"(",
"$",
"file",
"=",
"$",
"fs",
"->",
"get_file",
"(",
"$",
"user_context",
"->",
"id",
",",
"'user'",
",",
"'draft'",
",",
"$",
"itemid",
",",
"$",
"filepath",
",",
"$",
"filename",
")",
")",
"{",
"if",
"(",
"$",
"tempfile",
"=",
"$",
"fs",
"->",
"get_file",
"(",
"$",
"user_context",
"->",
"id",
",",
"'user'",
",",
"'draft'",
",",
"$",
"itemid",
",",
"$",
"newfilepath",
",",
"$",
"newfilename",
")",
")",
"{",
"// Remember original file source field.",
"$",
"source",
"=",
"@",
"unserialize",
"(",
"$",
"file",
"->",
"get_source",
"(",
")",
")",
";",
"// Remember the original sortorder.",
"$",
"sortorder",
"=",
"$",
"file",
"->",
"get_sortorder",
"(",
")",
";",
"if",
"(",
"$",
"tempfile",
"->",
"is_external_file",
"(",
")",
")",
"{",
"// New file is a reference. Check that existing file does not have any other files referencing to it",
"if",
"(",
"isset",
"(",
"$",
"source",
"->",
"original",
")",
"&&",
"$",
"fs",
"->",
"search_references_count",
"(",
"$",
"source",
"->",
"original",
")",
")",
"{",
"return",
"(",
"object",
")",
"array",
"(",
"'error'",
"=>",
"get_string",
"(",
"'errordoublereference'",
",",
"'repository'",
")",
")",
";",
"}",
"}",
"// delete existing file to release filename",
"$",
"file",
"->",
"delete",
"(",
")",
";",
"// create new file",
"$",
"newfile",
"=",
"$",
"fs",
"->",
"create_file_from_storedfile",
"(",
"array",
"(",
"'filepath'",
"=>",
"$",
"filepath",
",",
"'filename'",
"=>",
"$",
"filename",
")",
",",
"$",
"tempfile",
")",
";",
"// Preserve original file location (stored in source field) for handling references",
"if",
"(",
"isset",
"(",
"$",
"source",
"->",
"original",
")",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"newfilesource",
"=",
"@",
"unserialize",
"(",
"$",
"newfile",
"->",
"get_source",
"(",
")",
")",
")",
")",
"{",
"$",
"newfilesource",
"=",
"new",
"stdClass",
"(",
")",
";",
"}",
"$",
"newfilesource",
"->",
"original",
"=",
"$",
"source",
"->",
"original",
";",
"$",
"newfile",
"->",
"set_source",
"(",
"serialize",
"(",
"$",
"newfilesource",
")",
")",
";",
"}",
"$",
"newfile",
"->",
"set_sortorder",
"(",
"$",
"sortorder",
")",
";",
"// remove temp file",
"$",
"tempfile",
"->",
"delete",
"(",
")",
";",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Overwrite an existing file
@param int $itemid
@param string $filepath
@param string $filename
@param string $newfilepath
@param string $newfilename
@return bool
|
[
"Overwrite",
"an",
"existing",
"file"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L2514-L2549
|
219,182
|
moodle/moodle
|
repository/lib.php
|
repository.delete_tempfile_from_draft
|
public static function delete_tempfile_from_draft($draftitemid, $filepath, $filename) {
global $USER;
$fs = get_file_storage();
$user_context = context_user::instance($USER->id);
if ($file = $fs->get_file($user_context->id, 'user', 'draft', $draftitemid, $filepath, $filename)) {
$file->delete();
return true;
} else {
return false;
}
}
|
php
|
public static function delete_tempfile_from_draft($draftitemid, $filepath, $filename) {
global $USER;
$fs = get_file_storage();
$user_context = context_user::instance($USER->id);
if ($file = $fs->get_file($user_context->id, 'user', 'draft', $draftitemid, $filepath, $filename)) {
$file->delete();
return true;
} else {
return false;
}
}
|
[
"public",
"static",
"function",
"delete_tempfile_from_draft",
"(",
"$",
"draftitemid",
",",
"$",
"filepath",
",",
"$",
"filename",
")",
"{",
"global",
"$",
"USER",
";",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"$",
"user_context",
"=",
"context_user",
"::",
"instance",
"(",
"$",
"USER",
"->",
"id",
")",
";",
"if",
"(",
"$",
"file",
"=",
"$",
"fs",
"->",
"get_file",
"(",
"$",
"user_context",
"->",
"id",
",",
"'user'",
",",
"'draft'",
",",
"$",
"draftitemid",
",",
"$",
"filepath",
",",
"$",
"filename",
")",
")",
"{",
"$",
"file",
"->",
"delete",
"(",
")",
";",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] |
Delete a temp file from draft area
@param int $draftitemid
@param string $filepath
@param string $filename
@return bool
|
[
"Delete",
"a",
"temp",
"file",
"from",
"draft",
"area"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L2655-L2665
|
219,183
|
moodle/moodle
|
repository/lib.php
|
repository.convert_references_to_local
|
public function convert_references_to_local() {
$fs = get_file_storage();
$files = $fs->get_external_files($this->id);
foreach ($files as $storedfile) {
$fs->import_external_file($storedfile);
}
}
|
php
|
public function convert_references_to_local() {
$fs = get_file_storage();
$files = $fs->get_external_files($this->id);
foreach ($files as $storedfile) {
$fs->import_external_file($storedfile);
}
}
|
[
"public",
"function",
"convert_references_to_local",
"(",
")",
"{",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"$",
"files",
"=",
"$",
"fs",
"->",
"get_external_files",
"(",
"$",
"this",
"->",
"id",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"storedfile",
")",
"{",
"$",
"fs",
"->",
"import_external_file",
"(",
"$",
"storedfile",
")",
";",
"}",
"}"
] |
Find all external files in this repo and import them
|
[
"Find",
"all",
"external",
"files",
"in",
"this",
"repo",
"and",
"import",
"them"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L2670-L2676
|
219,184
|
moodle/moodle
|
repository/lib.php
|
repository.remove_files
|
public function remove_files() {
$fs = get_file_storage();
$files = $fs->get_external_files($this->id);
foreach ($files as $storedfile) {
$storedfile->delete();
}
}
|
php
|
public function remove_files() {
$fs = get_file_storage();
$files = $fs->get_external_files($this->id);
foreach ($files as $storedfile) {
$storedfile->delete();
}
}
|
[
"public",
"function",
"remove_files",
"(",
")",
"{",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"$",
"files",
"=",
"$",
"fs",
"->",
"get_external_files",
"(",
"$",
"this",
"->",
"id",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"storedfile",
")",
"{",
"$",
"storedfile",
"->",
"delete",
"(",
")",
";",
"}",
"}"
] |
Find all external files linked to this repository and delete them.
|
[
"Find",
"all",
"external",
"files",
"linked",
"to",
"this",
"repository",
"and",
"delete",
"them",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L2681-L2687
|
219,185
|
moodle/moodle
|
repository/lib.php
|
repository.prepare_to_cache
|
public function prepare_to_cache() {
return array(
'class' => get_class($this),
'id' => $this->id,
'ctxid' => $this->context->id,
'options' => $this->options,
'readonly' => $this->readonly
);
}
|
php
|
public function prepare_to_cache() {
return array(
'class' => get_class($this),
'id' => $this->id,
'ctxid' => $this->context->id,
'options' => $this->options,
'readonly' => $this->readonly
);
}
|
[
"public",
"function",
"prepare_to_cache",
"(",
")",
"{",
"return",
"array",
"(",
"'class'",
"=>",
"get_class",
"(",
"$",
"this",
")",
",",
"'id'",
"=>",
"$",
"this",
"->",
"id",
",",
"'ctxid'",
"=>",
"$",
"this",
"->",
"context",
"->",
"id",
",",
"'options'",
"=>",
"$",
"this",
"->",
"options",
",",
"'readonly'",
"=>",
"$",
"this",
"->",
"readonly",
")",
";",
"}"
] |
Prepares the repository to be cached. Implements method from cacheable_object interface.
@return array
|
[
"Prepares",
"the",
"repository",
"to",
"be",
"cached",
".",
"Implements",
"method",
"from",
"cacheable_object",
"interface",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L2790-L2798
|
219,186
|
moodle/moodle
|
repository/lib.php
|
repository.get_secret_key
|
final static public function get_secret_key() {
global $CFG;
if (!isset($CFG->reposecretkey)) {
set_config('reposecretkey', time() . random_string(32));
}
return $CFG->reposecretkey;
}
|
php
|
final static public function get_secret_key() {
global $CFG;
if (!isset($CFG->reposecretkey)) {
set_config('reposecretkey', time() . random_string(32));
}
return $CFG->reposecretkey;
}
|
[
"final",
"static",
"public",
"function",
"get_secret_key",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"CFG",
"->",
"reposecretkey",
")",
")",
"{",
"set_config",
"(",
"'reposecretkey'",
",",
"time",
"(",
")",
".",
"random_string",
"(",
"32",
")",
")",
";",
"}",
"return",
"$",
"CFG",
"->",
"reposecretkey",
";",
"}"
] |
Generate a secret key to be used for passing sensitive information around.
@return string repository secret key.
|
[
"Generate",
"a",
"secret",
"key",
"to",
"be",
"used",
"for",
"passing",
"sensitive",
"information",
"around",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L2851-L2858
|
219,187
|
moodle/moodle
|
repository/lib.php
|
repository_instance_form.add_defaults
|
protected function add_defaults() {
$mform =& $this->_form;
$strrequired = get_string('required');
$mform->addElement('hidden', 'edit', ($this->instance) ? $this->instance->id : 0);
$mform->setType('edit', PARAM_INT);
$mform->addElement('hidden', 'new', $this->plugin);
$mform->setType('new', PARAM_ALPHANUMEXT);
$mform->addElement('hidden', 'plugin', $this->plugin);
$mform->setType('plugin', PARAM_PLUGIN);
$mform->addElement('hidden', 'typeid', $this->typeid);
$mform->setType('typeid', PARAM_INT);
$mform->addElement('hidden', 'contextid', $this->contextid);
$mform->setType('contextid', PARAM_INT);
$mform->addElement('text', 'name', get_string('name'), 'maxlength="100" size="30"');
$mform->addRule('name', $strrequired, 'required', null, 'client');
$mform->setType('name', PARAM_TEXT);
}
|
php
|
protected function add_defaults() {
$mform =& $this->_form;
$strrequired = get_string('required');
$mform->addElement('hidden', 'edit', ($this->instance) ? $this->instance->id : 0);
$mform->setType('edit', PARAM_INT);
$mform->addElement('hidden', 'new', $this->plugin);
$mform->setType('new', PARAM_ALPHANUMEXT);
$mform->addElement('hidden', 'plugin', $this->plugin);
$mform->setType('plugin', PARAM_PLUGIN);
$mform->addElement('hidden', 'typeid', $this->typeid);
$mform->setType('typeid', PARAM_INT);
$mform->addElement('hidden', 'contextid', $this->contextid);
$mform->setType('contextid', PARAM_INT);
$mform->addElement('text', 'name', get_string('name'), 'maxlength="100" size="30"');
$mform->addRule('name', $strrequired, 'required', null, 'client');
$mform->setType('name', PARAM_TEXT);
}
|
[
"protected",
"function",
"add_defaults",
"(",
")",
"{",
"$",
"mform",
"=",
"&",
"$",
"this",
"->",
"_form",
";",
"$",
"strrequired",
"=",
"get_string",
"(",
"'required'",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'hidden'",
",",
"'edit'",
",",
"(",
"$",
"this",
"->",
"instance",
")",
"?",
"$",
"this",
"->",
"instance",
"->",
"id",
":",
"0",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'edit'",
",",
"PARAM_INT",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'hidden'",
",",
"'new'",
",",
"$",
"this",
"->",
"plugin",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'new'",
",",
"PARAM_ALPHANUMEXT",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'hidden'",
",",
"'plugin'",
",",
"$",
"this",
"->",
"plugin",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'plugin'",
",",
"PARAM_PLUGIN",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'hidden'",
",",
"'typeid'",
",",
"$",
"this",
"->",
"typeid",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'typeid'",
",",
"PARAM_INT",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'hidden'",
",",
"'contextid'",
",",
"$",
"this",
"->",
"contextid",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'contextid'",
",",
"PARAM_INT",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'text'",
",",
"'name'",
",",
"get_string",
"(",
"'name'",
")",
",",
"'maxlength=\"100\" size=\"30\"'",
")",
";",
"$",
"mform",
"->",
"addRule",
"(",
"'name'",
",",
"$",
"strrequired",
",",
"'required'",
",",
"null",
",",
"'client'",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'name'",
",",
"PARAM_TEXT",
")",
";",
"}"
] |
Added defaults to moodle form
|
[
"Added",
"defaults",
"to",
"moodle",
"form"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L2889-L2907
|
219,188
|
moodle/moodle
|
repository/lib.php
|
repository_instance_form.definition
|
public function definition() {
global $CFG;
// type of plugin, string
$this->plugin = $this->_customdata['plugin'];
$this->typeid = $this->_customdata['typeid'];
$this->contextid = $this->_customdata['contextid'];
$this->instance = (isset($this->_customdata['instance'])
&& is_subclass_of($this->_customdata['instance'], 'repository'))
? $this->_customdata['instance'] : null;
$mform =& $this->_form;
$this->add_defaults();
// Add instance config options.
$result = repository::static_function($this->plugin, 'instance_config_form', $mform);
if ($result === false) {
// Remove the name element if no other config options.
$mform->removeElement('name');
}
if ($this->instance) {
$data = array();
$data['name'] = $this->instance->name;
if (!$this->instance->readonly) {
// and set the data if we have some.
foreach ($this->instance->get_instance_option_names() as $config) {
if (!empty($this->instance->options[$config])) {
$data[$config] = $this->instance->options[$config];
} else {
$data[$config] = '';
}
}
}
$this->set_data($data);
}
if ($result === false) {
$mform->addElement('cancel');
} else {
$this->add_action_buttons(true, get_string('save','repository'));
}
}
|
php
|
public function definition() {
global $CFG;
// type of plugin, string
$this->plugin = $this->_customdata['plugin'];
$this->typeid = $this->_customdata['typeid'];
$this->contextid = $this->_customdata['contextid'];
$this->instance = (isset($this->_customdata['instance'])
&& is_subclass_of($this->_customdata['instance'], 'repository'))
? $this->_customdata['instance'] : null;
$mform =& $this->_form;
$this->add_defaults();
// Add instance config options.
$result = repository::static_function($this->plugin, 'instance_config_form', $mform);
if ($result === false) {
// Remove the name element if no other config options.
$mform->removeElement('name');
}
if ($this->instance) {
$data = array();
$data['name'] = $this->instance->name;
if (!$this->instance->readonly) {
// and set the data if we have some.
foreach ($this->instance->get_instance_option_names() as $config) {
if (!empty($this->instance->options[$config])) {
$data[$config] = $this->instance->options[$config];
} else {
$data[$config] = '';
}
}
}
$this->set_data($data);
}
if ($result === false) {
$mform->addElement('cancel');
} else {
$this->add_action_buttons(true, get_string('save','repository'));
}
}
|
[
"public",
"function",
"definition",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"// type of plugin, string",
"$",
"this",
"->",
"plugin",
"=",
"$",
"this",
"->",
"_customdata",
"[",
"'plugin'",
"]",
";",
"$",
"this",
"->",
"typeid",
"=",
"$",
"this",
"->",
"_customdata",
"[",
"'typeid'",
"]",
";",
"$",
"this",
"->",
"contextid",
"=",
"$",
"this",
"->",
"_customdata",
"[",
"'contextid'",
"]",
";",
"$",
"this",
"->",
"instance",
"=",
"(",
"isset",
"(",
"$",
"this",
"->",
"_customdata",
"[",
"'instance'",
"]",
")",
"&&",
"is_subclass_of",
"(",
"$",
"this",
"->",
"_customdata",
"[",
"'instance'",
"]",
",",
"'repository'",
")",
")",
"?",
"$",
"this",
"->",
"_customdata",
"[",
"'instance'",
"]",
":",
"null",
";",
"$",
"mform",
"=",
"&",
"$",
"this",
"->",
"_form",
";",
"$",
"this",
"->",
"add_defaults",
"(",
")",
";",
"// Add instance config options.",
"$",
"result",
"=",
"repository",
"::",
"static_function",
"(",
"$",
"this",
"->",
"plugin",
",",
"'instance_config_form'",
",",
"$",
"mform",
")",
";",
"if",
"(",
"$",
"result",
"===",
"false",
")",
"{",
"// Remove the name element if no other config options.",
"$",
"mform",
"->",
"removeElement",
"(",
"'name'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"instance",
")",
"{",
"$",
"data",
"=",
"array",
"(",
")",
";",
"$",
"data",
"[",
"'name'",
"]",
"=",
"$",
"this",
"->",
"instance",
"->",
"name",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"instance",
"->",
"readonly",
")",
"{",
"// and set the data if we have some.",
"foreach",
"(",
"$",
"this",
"->",
"instance",
"->",
"get_instance_option_names",
"(",
")",
"as",
"$",
"config",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"instance",
"->",
"options",
"[",
"$",
"config",
"]",
")",
")",
"{",
"$",
"data",
"[",
"$",
"config",
"]",
"=",
"$",
"this",
"->",
"instance",
"->",
"options",
"[",
"$",
"config",
"]",
";",
"}",
"else",
"{",
"$",
"data",
"[",
"$",
"config",
"]",
"=",
"''",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"set_data",
"(",
"$",
"data",
")",
";",
"}",
"if",
"(",
"$",
"result",
"===",
"false",
")",
"{",
"$",
"mform",
"->",
"addElement",
"(",
"'cancel'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"add_action_buttons",
"(",
"true",
",",
"get_string",
"(",
"'save'",
",",
"'repository'",
")",
")",
";",
"}",
"}"
] |
Define moodle form elements
|
[
"Define",
"moodle",
"form",
"elements"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/lib.php#L2912-L2953
|
219,189
|
moodle/moodle
|
report/outline/classes/filter_form.php
|
filter_form.definition_after_data
|
public function definition_after_data() {
$mform = $this->_form;
$filterstartdate = $mform->getElement('filterstartdate')->getValue();
$filterenddate = $mform->getElement('filterenddate')->getValue();
if (!empty($filterstartdate['enabled']) || !empty($filterenddate['enabled'])) {
$mform->setExpanded('filterheader', true);
}
}
|
php
|
public function definition_after_data() {
$mform = $this->_form;
$filterstartdate = $mform->getElement('filterstartdate')->getValue();
$filterenddate = $mform->getElement('filterenddate')->getValue();
if (!empty($filterstartdate['enabled']) || !empty($filterenddate['enabled'])) {
$mform->setExpanded('filterheader', true);
}
}
|
[
"public",
"function",
"definition_after_data",
"(",
")",
"{",
"$",
"mform",
"=",
"$",
"this",
"->",
"_form",
";",
"$",
"filterstartdate",
"=",
"$",
"mform",
"->",
"getElement",
"(",
"'filterstartdate'",
")",
"->",
"getValue",
"(",
")",
";",
"$",
"filterenddate",
"=",
"$",
"mform",
"->",
"getElement",
"(",
"'filterenddate'",
")",
"->",
"getValue",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"filterstartdate",
"[",
"'enabled'",
"]",
")",
"||",
"!",
"empty",
"(",
"$",
"filterenddate",
"[",
"'enabled'",
"]",
")",
")",
"{",
"$",
"mform",
"->",
"setExpanded",
"(",
"'filterheader'",
",",
"true",
")",
";",
"}",
"}"
] |
Expand the form contents if the filter is in use.
@throws \HTML_QuickForm_Error
|
[
"Expand",
"the",
"form",
"contents",
"if",
"the",
"filter",
"is",
"in",
"use",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/outline/classes/filter_form.php#L66-L73
|
219,190
|
moodle/moodle
|
lib/pear/HTML/QuickForm/checkbox.php
|
HTML_QuickForm_checkbox.toHtml
|
function toHtml()
{
$this->_generateId(); // Seems to be necessary when this is used in a group.
if (0 == strlen($this->_text)) {
$label = '';
} elseif ($this->_flagFrozen) {
$label = $this->_text;
} else {
$label = '<label for="' . $this->getAttribute('id') . '">' . $this->_text . '</label>';
}
return HTML_QuickForm_input::toHtml() . $label;
}
|
php
|
function toHtml()
{
$this->_generateId(); // Seems to be necessary when this is used in a group.
if (0 == strlen($this->_text)) {
$label = '';
} elseif ($this->_flagFrozen) {
$label = $this->_text;
} else {
$label = '<label for="' . $this->getAttribute('id') . '">' . $this->_text . '</label>';
}
return HTML_QuickForm_input::toHtml() . $label;
}
|
[
"function",
"toHtml",
"(",
")",
"{",
"$",
"this",
"->",
"_generateId",
"(",
")",
";",
"// Seems to be necessary when this is used in a group.",
"if",
"(",
"0",
"==",
"strlen",
"(",
"$",
"this",
"->",
"_text",
")",
")",
"{",
"$",
"label",
"=",
"''",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"_flagFrozen",
")",
"{",
"$",
"label",
"=",
"$",
"this",
"->",
"_text",
";",
"}",
"else",
"{",
"$",
"label",
"=",
"'<label for=\"'",
".",
"$",
"this",
"->",
"getAttribute",
"(",
"'id'",
")",
".",
"'\">'",
".",
"$",
"this",
"->",
"_text",
".",
"'</label>'",
";",
"}",
"return",
"HTML_QuickForm_input",
"::",
"toHtml",
"(",
")",
".",
"$",
"label",
";",
"}"
] |
Returns the checkbox element in HTML
@since 1.0
@access public
@return string
|
[
"Returns",
"the",
"checkbox",
"element",
"in",
"HTML"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/checkbox.php#L123-L134
|
219,191
|
moodle/moodle
|
repository/s3/lib.php
|
repository_s3.explode_path
|
protected function explode_path($path) {
$parts = explode('/', $path, 2);
if (isset($parts[1]) && $parts[1] !== '') {
list($bucket, $uri) = $parts;
} else {
$bucket = $parts[0];
$uri = '';
}
return array($bucket, $uri);
}
|
php
|
protected function explode_path($path) {
$parts = explode('/', $path, 2);
if (isset($parts[1]) && $parts[1] !== '') {
list($bucket, $uri) = $parts;
} else {
$bucket = $parts[0];
$uri = '';
}
return array($bucket, $uri);
}
|
[
"protected",
"function",
"explode_path",
"(",
"$",
"path",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'/'",
",",
"$",
"path",
",",
"2",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
"&&",
"$",
"parts",
"[",
"1",
"]",
"!==",
"''",
")",
"{",
"list",
"(",
"$",
"bucket",
",",
"$",
"uri",
")",
"=",
"$",
"parts",
";",
"}",
"else",
"{",
"$",
"bucket",
"=",
"$",
"parts",
"[",
"0",
"]",
";",
"$",
"uri",
"=",
"''",
";",
"}",
"return",
"array",
"(",
"$",
"bucket",
",",
"$",
"uri",
")",
";",
"}"
] |
Extracts the Bucket and URI from the path
@param string $path path in this format 'bucket/path/to/folder/and/file'
@return array including bucket and uri
|
[
"Extracts",
"the",
"Bucket",
"and",
"URI",
"from",
"the",
"path"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/s3/lib.php#L89-L98
|
219,192
|
moodle/moodle
|
repository/s3/lib.php
|
repository_s3.get_file
|
public function get_file($filepath, $file = '') {
list($bucket, $uri) = $this->explode_path($filepath);
$path = $this->prepare_file($file);
try {
$this->s->getObject($bucket, $uri, $path);
} catch (S3Exception $e) {
throw new moodle_exception(
'errorwhilecommunicatingwith',
'repository',
'',
$this->get_name(),
$e->getMessage()
);
}
return array('path' => $path);
}
|
php
|
public function get_file($filepath, $file = '') {
list($bucket, $uri) = $this->explode_path($filepath);
$path = $this->prepare_file($file);
try {
$this->s->getObject($bucket, $uri, $path);
} catch (S3Exception $e) {
throw new moodle_exception(
'errorwhilecommunicatingwith',
'repository',
'',
$this->get_name(),
$e->getMessage()
);
}
return array('path' => $path);
}
|
[
"public",
"function",
"get_file",
"(",
"$",
"filepath",
",",
"$",
"file",
"=",
"''",
")",
"{",
"list",
"(",
"$",
"bucket",
",",
"$",
"uri",
")",
"=",
"$",
"this",
"->",
"explode_path",
"(",
"$",
"filepath",
")",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"prepare_file",
"(",
"$",
"file",
")",
";",
"try",
"{",
"$",
"this",
"->",
"s",
"->",
"getObject",
"(",
"$",
"bucket",
",",
"$",
"uri",
",",
"$",
"path",
")",
";",
"}",
"catch",
"(",
"S3Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'errorwhilecommunicatingwith'",
",",
"'repository'",
",",
"''",
",",
"$",
"this",
"->",
"get_name",
"(",
")",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"array",
"(",
"'path'",
"=>",
"$",
"path",
")",
";",
"}"
] |
Download S3 files to moodle
@param string $filepath
@param string $file The file path in moodle
@return array The local stored path
|
[
"Download",
"S3",
"files",
"to",
"moodle"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/s3/lib.php#L234-L249
|
219,193
|
moodle/moodle
|
portfolio/googledocs/lib.php
|
portfolio_plugin_googledocs.get_access_token
|
private function get_access_token() {
global $SESSION;
if (isset($SESSION->{self::SESSIONKEY}) && $SESSION->{self::SESSIONKEY}) {
$this->client->setAccessToken($SESSION->{self::SESSIONKEY});
return $SESSION->{self::SESSIONKEY};
}
return null;
}
|
php
|
private function get_access_token() {
global $SESSION;
if (isset($SESSION->{self::SESSIONKEY}) && $SESSION->{self::SESSIONKEY}) {
$this->client->setAccessToken($SESSION->{self::SESSIONKEY});
return $SESSION->{self::SESSIONKEY};
}
return null;
}
|
[
"private",
"function",
"get_access_token",
"(",
")",
"{",
"global",
"$",
"SESSION",
";",
"if",
"(",
"isset",
"(",
"$",
"SESSION",
"->",
"{",
"self",
"::",
"SESSIONKEY",
"}",
")",
"&&",
"$",
"SESSION",
"->",
"{",
"self",
"::",
"SESSIONKEY",
"}",
")",
"{",
"$",
"this",
"->",
"client",
"->",
"setAccessToken",
"(",
"$",
"SESSION",
"->",
"{",
"self",
"::",
"SESSIONKEY",
"}",
")",
";",
"return",
"$",
"SESSION",
"->",
"{",
"self",
"::",
"SESSIONKEY",
"}",
";",
"}",
"return",
"null",
";",
"}"
] |
Gets the access token from session and sets it to client.
@return null|string null or token.
|
[
"Gets",
"the",
"access",
"token",
"from",
"session",
"and",
"sets",
"it",
"to",
"client",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/portfolio/googledocs/lib.php#L101-L108
|
219,194
|
moodle/moodle
|
lib/editor/atto/classes/privacy/provider.php
|
provider.export_autosaves
|
protected static function export_autosaves(\stdClass $user, \moodle_recordset $autosaves) {
foreach ($autosaves as $autosave) {
$context = \context::instance_by_id($autosave->contextid);
$subcontext = [
get_string('autosaves', 'editor_atto'),
$autosave->id,
];
$html = writer::with_context($context)
->rewrite_pluginfile_urls($subcontext, 'user', 'draft', $autosave->draftid, $autosave->drafttext);
$data = (object) [
'drafttext' => format_text($html, FORMAT_HTML, static::get_filter_options()),
'timemodified' => \core_privacy\local\request\transform::datetime($autosave->timemodified),
];
if ($autosave->userid != $user->id) {
$data->author = \core_privacy\local\request\transform::user($autosave->userid);
}
writer::with_context($context)
->export_data($subcontext, $data)
->export_area_files($subcontext, 'user', 'draft', $autosave->draftid);
}
$autosaves->close();
}
|
php
|
protected static function export_autosaves(\stdClass $user, \moodle_recordset $autosaves) {
foreach ($autosaves as $autosave) {
$context = \context::instance_by_id($autosave->contextid);
$subcontext = [
get_string('autosaves', 'editor_atto'),
$autosave->id,
];
$html = writer::with_context($context)
->rewrite_pluginfile_urls($subcontext, 'user', 'draft', $autosave->draftid, $autosave->drafttext);
$data = (object) [
'drafttext' => format_text($html, FORMAT_HTML, static::get_filter_options()),
'timemodified' => \core_privacy\local\request\transform::datetime($autosave->timemodified),
];
if ($autosave->userid != $user->id) {
$data->author = \core_privacy\local\request\transform::user($autosave->userid);
}
writer::with_context($context)
->export_data($subcontext, $data)
->export_area_files($subcontext, 'user', 'draft', $autosave->draftid);
}
$autosaves->close();
}
|
[
"protected",
"static",
"function",
"export_autosaves",
"(",
"\\",
"stdClass",
"$",
"user",
",",
"\\",
"moodle_recordset",
"$",
"autosaves",
")",
"{",
"foreach",
"(",
"$",
"autosaves",
"as",
"$",
"autosave",
")",
"{",
"$",
"context",
"=",
"\\",
"context",
"::",
"instance_by_id",
"(",
"$",
"autosave",
"->",
"contextid",
")",
";",
"$",
"subcontext",
"=",
"[",
"get_string",
"(",
"'autosaves'",
",",
"'editor_atto'",
")",
",",
"$",
"autosave",
"->",
"id",
",",
"]",
";",
"$",
"html",
"=",
"writer",
"::",
"with_context",
"(",
"$",
"context",
")",
"->",
"rewrite_pluginfile_urls",
"(",
"$",
"subcontext",
",",
"'user'",
",",
"'draft'",
",",
"$",
"autosave",
"->",
"draftid",
",",
"$",
"autosave",
"->",
"drafttext",
")",
";",
"$",
"data",
"=",
"(",
"object",
")",
"[",
"'drafttext'",
"=>",
"format_text",
"(",
"$",
"html",
",",
"FORMAT_HTML",
",",
"static",
"::",
"get_filter_options",
"(",
")",
")",
",",
"'timemodified'",
"=>",
"\\",
"core_privacy",
"\\",
"local",
"\\",
"request",
"\\",
"transform",
"::",
"datetime",
"(",
"$",
"autosave",
"->",
"timemodified",
")",
",",
"]",
";",
"if",
"(",
"$",
"autosave",
"->",
"userid",
"!=",
"$",
"user",
"->",
"id",
")",
"{",
"$",
"data",
"->",
"author",
"=",
"\\",
"core_privacy",
"\\",
"local",
"\\",
"request",
"\\",
"transform",
"::",
"user",
"(",
"$",
"autosave",
"->",
"userid",
")",
";",
"}",
"writer",
"::",
"with_context",
"(",
"$",
"context",
")",
"->",
"export_data",
"(",
"$",
"subcontext",
",",
"$",
"data",
")",
"->",
"export_area_files",
"(",
"$",
"subcontext",
",",
"'user'",
",",
"'draft'",
",",
"$",
"autosave",
"->",
"draftid",
")",
";",
"}",
"$",
"autosaves",
"->",
"close",
"(",
")",
";",
"}"
] |
Export all autosave records in the recordset, and close the recordset when finished.
@param \stdClass $user The user whose data is to be exported
@param \moodle_recordset $autosaves The recordset containing the data to export
|
[
"Export",
"all",
"autosave",
"records",
"in",
"the",
"recordset",
"and",
"close",
"the",
"recordset",
"when",
"finished",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/editor/atto/classes/privacy/provider.php#L155-L180
|
219,195
|
moodle/moodle
|
lib/classes/task/manager.php
|
manager.get_queued_adhoc_task_record
|
protected static function get_queued_adhoc_task_record($task) {
global $DB;
$record = self::record_from_adhoc_task($task);
$params = [$record->classname, $record->component, $record->customdata];
$sql = 'classname = ? AND component = ? AND ' .
$DB->sql_compare_text('customdata', \core_text::strlen($record->customdata) + 1) . ' = ?';
if ($record->userid) {
$params[] = $record->userid;
$sql .= " AND userid = ? ";
}
return $DB->get_record_select('task_adhoc', $sql, $params);
}
|
php
|
protected static function get_queued_adhoc_task_record($task) {
global $DB;
$record = self::record_from_adhoc_task($task);
$params = [$record->classname, $record->component, $record->customdata];
$sql = 'classname = ? AND component = ? AND ' .
$DB->sql_compare_text('customdata', \core_text::strlen($record->customdata) + 1) . ' = ?';
if ($record->userid) {
$params[] = $record->userid;
$sql .= " AND userid = ? ";
}
return $DB->get_record_select('task_adhoc', $sql, $params);
}
|
[
"protected",
"static",
"function",
"get_queued_adhoc_task_record",
"(",
"$",
"task",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"record",
"=",
"self",
"::",
"record_from_adhoc_task",
"(",
"$",
"task",
")",
";",
"$",
"params",
"=",
"[",
"$",
"record",
"->",
"classname",
",",
"$",
"record",
"->",
"component",
",",
"$",
"record",
"->",
"customdata",
"]",
";",
"$",
"sql",
"=",
"'classname = ? AND component = ? AND '",
".",
"$",
"DB",
"->",
"sql_compare_text",
"(",
"'customdata'",
",",
"\\",
"core_text",
"::",
"strlen",
"(",
"$",
"record",
"->",
"customdata",
")",
"+",
"1",
")",
".",
"' = ?'",
";",
"if",
"(",
"$",
"record",
"->",
"userid",
")",
"{",
"$",
"params",
"[",
"]",
"=",
"$",
"record",
"->",
"userid",
";",
"$",
"sql",
".=",
"\" AND userid = ? \"",
";",
"}",
"return",
"$",
"DB",
"->",
"get_record_select",
"(",
"'task_adhoc'",
",",
"$",
"sql",
",",
"$",
"params",
")",
";",
"}"
] |
Checks if the task with the same classname, component and customdata is already scheduled
@param adhoc_task $task
@return bool
|
[
"Checks",
"if",
"the",
"task",
"with",
"the",
"same",
"classname",
"component",
"and",
"customdata",
"is",
"already",
"scheduled"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/task/manager.php#L141-L154
|
219,196
|
moodle/moodle
|
lib/classes/task/manager.php
|
manager.reschedule_or_queue_adhoc_task
|
public static function reschedule_or_queue_adhoc_task(adhoc_task $task) : void {
global $DB;
if ($existingrecord = self::get_queued_adhoc_task_record($task)) {
// Only update the next run time if it is explicitly set on the task.
$nextruntime = $task->get_next_run_time();
if ($nextruntime && ($existingrecord->nextruntime != $nextruntime)) {
$DB->set_field('task_adhoc', 'nextruntime', $nextruntime, ['id' => $existingrecord->id]);
}
} else {
// There is nothing queued yet. Just queue as normal.
self::queue_adhoc_task($task);
}
}
|
php
|
public static function reschedule_or_queue_adhoc_task(adhoc_task $task) : void {
global $DB;
if ($existingrecord = self::get_queued_adhoc_task_record($task)) {
// Only update the next run time if it is explicitly set on the task.
$nextruntime = $task->get_next_run_time();
if ($nextruntime && ($existingrecord->nextruntime != $nextruntime)) {
$DB->set_field('task_adhoc', 'nextruntime', $nextruntime, ['id' => $existingrecord->id]);
}
} else {
// There is nothing queued yet. Just queue as normal.
self::queue_adhoc_task($task);
}
}
|
[
"public",
"static",
"function",
"reschedule_or_queue_adhoc_task",
"(",
"adhoc_task",
"$",
"task",
")",
":",
"void",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"$",
"existingrecord",
"=",
"self",
"::",
"get_queued_adhoc_task_record",
"(",
"$",
"task",
")",
")",
"{",
"// Only update the next run time if it is explicitly set on the task.",
"$",
"nextruntime",
"=",
"$",
"task",
"->",
"get_next_run_time",
"(",
")",
";",
"if",
"(",
"$",
"nextruntime",
"&&",
"(",
"$",
"existingrecord",
"->",
"nextruntime",
"!=",
"$",
"nextruntime",
")",
")",
"{",
"$",
"DB",
"->",
"set_field",
"(",
"'task_adhoc'",
",",
"'nextruntime'",
",",
"$",
"nextruntime",
",",
"[",
"'id'",
"=>",
"$",
"existingrecord",
"->",
"id",
"]",
")",
";",
"}",
"}",
"else",
"{",
"// There is nothing queued yet. Just queue as normal.",
"self",
"::",
"queue_adhoc_task",
"(",
"$",
"task",
")",
";",
"}",
"}"
] |
Schedule a new task, or reschedule an existing adhoc task which has matching data.
Only a task matching the same user, classname, component, and customdata will be rescheduled.
If these values do not match exactly then a new task is scheduled.
@param \core\task\adhoc_task $task - The new adhoc task information to store.
@since Moodle 3.7
|
[
"Schedule",
"a",
"new",
"task",
"or",
"reschedule",
"an",
"existing",
"adhoc",
"task",
"which",
"has",
"matching",
"data",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/task/manager.php#L165-L178
|
219,197
|
moodle/moodle
|
lib/classes/task/manager.php
|
manager.queue_adhoc_task
|
public static function queue_adhoc_task(adhoc_task $task, $checkforexisting = false) {
global $DB;
if ($userid = $task->get_userid()) {
// User found. Check that they are suitable.
\core_user::require_active_user(\core_user::get_user($userid, '*', MUST_EXIST), true, true);
}
$record = self::record_from_adhoc_task($task);
// Schedule it immediately if nextruntime not explicitly set.
if (!$task->get_next_run_time()) {
$record->nextruntime = time() - 1;
}
// Check if the same task is already scheduled.
if ($checkforexisting && self::task_is_scheduled($task)) {
return false;
}
// Queue the task.
$result = $DB->insert_record('task_adhoc', $record);
return $result;
}
|
php
|
public static function queue_adhoc_task(adhoc_task $task, $checkforexisting = false) {
global $DB;
if ($userid = $task->get_userid()) {
// User found. Check that they are suitable.
\core_user::require_active_user(\core_user::get_user($userid, '*', MUST_EXIST), true, true);
}
$record = self::record_from_adhoc_task($task);
// Schedule it immediately if nextruntime not explicitly set.
if (!$task->get_next_run_time()) {
$record->nextruntime = time() - 1;
}
// Check if the same task is already scheduled.
if ($checkforexisting && self::task_is_scheduled($task)) {
return false;
}
// Queue the task.
$result = $DB->insert_record('task_adhoc', $record);
return $result;
}
|
[
"public",
"static",
"function",
"queue_adhoc_task",
"(",
"adhoc_task",
"$",
"task",
",",
"$",
"checkforexisting",
"=",
"false",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"$",
"userid",
"=",
"$",
"task",
"->",
"get_userid",
"(",
")",
")",
"{",
"// User found. Check that they are suitable.",
"\\",
"core_user",
"::",
"require_active_user",
"(",
"\\",
"core_user",
"::",
"get_user",
"(",
"$",
"userid",
",",
"'*'",
",",
"MUST_EXIST",
")",
",",
"true",
",",
"true",
")",
";",
"}",
"$",
"record",
"=",
"self",
"::",
"record_from_adhoc_task",
"(",
"$",
"task",
")",
";",
"// Schedule it immediately if nextruntime not explicitly set.",
"if",
"(",
"!",
"$",
"task",
"->",
"get_next_run_time",
"(",
")",
")",
"{",
"$",
"record",
"->",
"nextruntime",
"=",
"time",
"(",
")",
"-",
"1",
";",
"}",
"// Check if the same task is already scheduled.",
"if",
"(",
"$",
"checkforexisting",
"&&",
"self",
"::",
"task_is_scheduled",
"(",
"$",
"task",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Queue the task.",
"$",
"result",
"=",
"$",
"DB",
"->",
"insert_record",
"(",
"'task_adhoc'",
",",
"$",
"record",
")",
";",
"return",
"$",
"result",
";",
"}"
] |
Queue an adhoc task to run in the background.
@param \core\task\adhoc_task $task - The new adhoc task information to store.
@param bool $checkforexisting - If set to true and the task with the same user, classname, component and customdata
is already scheduled then it will not schedule a new task. Can be used only for ASAP tasks.
@return boolean - True if the config was saved.
|
[
"Queue",
"an",
"adhoc",
"task",
"to",
"run",
"in",
"the",
"background",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/task/manager.php#L188-L211
|
219,198
|
moodle/moodle
|
lib/classes/task/manager.php
|
manager.record_from_scheduled_task
|
public static function record_from_scheduled_task($task) {
$record = new \stdClass();
$record->classname = self::get_canonical_class_name($task);
$record->component = $task->get_component();
$record->blocking = $task->is_blocking();
$record->customised = $task->is_customised();
$record->lastruntime = $task->get_last_run_time();
$record->nextruntime = $task->get_next_run_time();
$record->faildelay = $task->get_fail_delay();
$record->hour = $task->get_hour();
$record->minute = $task->get_minute();
$record->day = $task->get_day();
$record->dayofweek = $task->get_day_of_week();
$record->month = $task->get_month();
$record->disabled = $task->get_disabled();
return $record;
}
|
php
|
public static function record_from_scheduled_task($task) {
$record = new \stdClass();
$record->classname = self::get_canonical_class_name($task);
$record->component = $task->get_component();
$record->blocking = $task->is_blocking();
$record->customised = $task->is_customised();
$record->lastruntime = $task->get_last_run_time();
$record->nextruntime = $task->get_next_run_time();
$record->faildelay = $task->get_fail_delay();
$record->hour = $task->get_hour();
$record->minute = $task->get_minute();
$record->day = $task->get_day();
$record->dayofweek = $task->get_day_of_week();
$record->month = $task->get_month();
$record->disabled = $task->get_disabled();
return $record;
}
|
[
"public",
"static",
"function",
"record_from_scheduled_task",
"(",
"$",
"task",
")",
"{",
"$",
"record",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"record",
"->",
"classname",
"=",
"self",
"::",
"get_canonical_class_name",
"(",
"$",
"task",
")",
";",
"$",
"record",
"->",
"component",
"=",
"$",
"task",
"->",
"get_component",
"(",
")",
";",
"$",
"record",
"->",
"blocking",
"=",
"$",
"task",
"->",
"is_blocking",
"(",
")",
";",
"$",
"record",
"->",
"customised",
"=",
"$",
"task",
"->",
"is_customised",
"(",
")",
";",
"$",
"record",
"->",
"lastruntime",
"=",
"$",
"task",
"->",
"get_last_run_time",
"(",
")",
";",
"$",
"record",
"->",
"nextruntime",
"=",
"$",
"task",
"->",
"get_next_run_time",
"(",
")",
";",
"$",
"record",
"->",
"faildelay",
"=",
"$",
"task",
"->",
"get_fail_delay",
"(",
")",
";",
"$",
"record",
"->",
"hour",
"=",
"$",
"task",
"->",
"get_hour",
"(",
")",
";",
"$",
"record",
"->",
"minute",
"=",
"$",
"task",
"->",
"get_minute",
"(",
")",
";",
"$",
"record",
"->",
"day",
"=",
"$",
"task",
"->",
"get_day",
"(",
")",
";",
"$",
"record",
"->",
"dayofweek",
"=",
"$",
"task",
"->",
"get_day_of_week",
"(",
")",
";",
"$",
"record",
"->",
"month",
"=",
"$",
"task",
"->",
"get_month",
"(",
")",
";",
"$",
"record",
"->",
"disabled",
"=",
"$",
"task",
"->",
"get_disabled",
"(",
")",
";",
"return",
"$",
"record",
";",
"}"
] |
Utility method to create a DB record from a scheduled task.
@param \core\task\scheduled_task $task
@return \stdClass
|
[
"Utility",
"method",
"to",
"create",
"a",
"DB",
"record",
"from",
"a",
"scheduled",
"task",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/task/manager.php#L241-L258
|
219,199
|
moodle/moodle
|
lib/classes/task/manager.php
|
manager.record_from_adhoc_task
|
public static function record_from_adhoc_task($task) {
$record = new \stdClass();
$record->classname = self::get_canonical_class_name($task);
$record->id = $task->get_id();
$record->component = $task->get_component();
$record->blocking = $task->is_blocking();
$record->nextruntime = $task->get_next_run_time();
$record->faildelay = $task->get_fail_delay();
$record->customdata = $task->get_custom_data_as_string();
$record->userid = $task->get_userid();
return $record;
}
|
php
|
public static function record_from_adhoc_task($task) {
$record = new \stdClass();
$record->classname = self::get_canonical_class_name($task);
$record->id = $task->get_id();
$record->component = $task->get_component();
$record->blocking = $task->is_blocking();
$record->nextruntime = $task->get_next_run_time();
$record->faildelay = $task->get_fail_delay();
$record->customdata = $task->get_custom_data_as_string();
$record->userid = $task->get_userid();
return $record;
}
|
[
"public",
"static",
"function",
"record_from_adhoc_task",
"(",
"$",
"task",
")",
"{",
"$",
"record",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"record",
"->",
"classname",
"=",
"self",
"::",
"get_canonical_class_name",
"(",
"$",
"task",
")",
";",
"$",
"record",
"->",
"id",
"=",
"$",
"task",
"->",
"get_id",
"(",
")",
";",
"$",
"record",
"->",
"component",
"=",
"$",
"task",
"->",
"get_component",
"(",
")",
";",
"$",
"record",
"->",
"blocking",
"=",
"$",
"task",
"->",
"is_blocking",
"(",
")",
";",
"$",
"record",
"->",
"nextruntime",
"=",
"$",
"task",
"->",
"get_next_run_time",
"(",
")",
";",
"$",
"record",
"->",
"faildelay",
"=",
"$",
"task",
"->",
"get_fail_delay",
"(",
")",
";",
"$",
"record",
"->",
"customdata",
"=",
"$",
"task",
"->",
"get_custom_data_as_string",
"(",
")",
";",
"$",
"record",
"->",
"userid",
"=",
"$",
"task",
"->",
"get_userid",
"(",
")",
";",
"return",
"$",
"record",
";",
"}"
] |
Utility method to create a DB record from an adhoc task.
@param \core\task\adhoc_task $task
@return \stdClass
|
[
"Utility",
"method",
"to",
"create",
"a",
"DB",
"record",
"from",
"an",
"adhoc",
"task",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/task/manager.php#L266-L278
|
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.