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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
215,700
|
moodle/moodle
|
question/type/multichoice/backup/moodle1/lib.php
|
moodle1_qtype_multichoice_handler.write_multichoice
|
protected function write_multichoice(array $multichoices, $oldquestiontextformat, $questionid) {
global $CFG;
// The grouped array is supposed to have just one element - let us use foreach anyway
// just to be sure we do not loose anything.
foreach ($multichoices as $multichoice) {
// Append an artificial 'id' attribute (is not included in moodle.xml).
$multichoice['id'] = $this->converter->get_nextid();
// Replay the upgrade step 2009021801.
$multichoice['correctfeedbackformat'] = 0;
$multichoice['partiallycorrectfeedbackformat'] = 0;
$multichoice['incorrectfeedbackformat'] = 0;
if ($CFG->texteditors !== 'textarea' and $oldquestiontextformat == FORMAT_MOODLE) {
$multichoice['correctfeedback'] = text_to_html($multichoice['correctfeedback'], false, false, true);
$multichoice['correctfeedbackformat'] = FORMAT_HTML;
$multichoice['partiallycorrectfeedback'] = text_to_html($multichoice['partiallycorrectfeedback'], false, false, true);
$multichoice['partiallycorrectfeedbackformat'] = FORMAT_HTML;
$multichoice['incorrectfeedback'] = text_to_html($multichoice['incorrectfeedback'], false, false, true);
$multichoice['incorrectfeedbackformat'] = FORMAT_HTML;
} else {
$multichoice['correctfeedbackformat'] = $oldquestiontextformat;
$multichoice['partiallycorrectfeedbackformat'] = $oldquestiontextformat;
$multichoice['incorrectfeedbackformat'] = $oldquestiontextformat;
}
$multichoice['correctfeedback'] = $this->migrate_files(
$multichoice['correctfeedback'], 'question', 'correctfeedback', $questionid);
$multichoice['partiallycorrectfeedback'] = $this->migrate_files(
$multichoice['partiallycorrectfeedback'], 'question', 'partiallycorrectfeedback', $questionid);
$multichoice['incorrectfeedback'] = $this->migrate_files(
$multichoice['incorrectfeedback'], 'question', 'incorrectfeedback', $questionid);
$this->write_xml('multichoice', $multichoice, array('/multichoice/id'));
}
}
|
php
|
protected function write_multichoice(array $multichoices, $oldquestiontextformat, $questionid) {
global $CFG;
// The grouped array is supposed to have just one element - let us use foreach anyway
// just to be sure we do not loose anything.
foreach ($multichoices as $multichoice) {
// Append an artificial 'id' attribute (is not included in moodle.xml).
$multichoice['id'] = $this->converter->get_nextid();
// Replay the upgrade step 2009021801.
$multichoice['correctfeedbackformat'] = 0;
$multichoice['partiallycorrectfeedbackformat'] = 0;
$multichoice['incorrectfeedbackformat'] = 0;
if ($CFG->texteditors !== 'textarea' and $oldquestiontextformat == FORMAT_MOODLE) {
$multichoice['correctfeedback'] = text_to_html($multichoice['correctfeedback'], false, false, true);
$multichoice['correctfeedbackformat'] = FORMAT_HTML;
$multichoice['partiallycorrectfeedback'] = text_to_html($multichoice['partiallycorrectfeedback'], false, false, true);
$multichoice['partiallycorrectfeedbackformat'] = FORMAT_HTML;
$multichoice['incorrectfeedback'] = text_to_html($multichoice['incorrectfeedback'], false, false, true);
$multichoice['incorrectfeedbackformat'] = FORMAT_HTML;
} else {
$multichoice['correctfeedbackformat'] = $oldquestiontextformat;
$multichoice['partiallycorrectfeedbackformat'] = $oldquestiontextformat;
$multichoice['incorrectfeedbackformat'] = $oldquestiontextformat;
}
$multichoice['correctfeedback'] = $this->migrate_files(
$multichoice['correctfeedback'], 'question', 'correctfeedback', $questionid);
$multichoice['partiallycorrectfeedback'] = $this->migrate_files(
$multichoice['partiallycorrectfeedback'], 'question', 'partiallycorrectfeedback', $questionid);
$multichoice['incorrectfeedback'] = $this->migrate_files(
$multichoice['incorrectfeedback'], 'question', 'incorrectfeedback', $questionid);
$this->write_xml('multichoice', $multichoice, array('/multichoice/id'));
}
}
|
[
"protected",
"function",
"write_multichoice",
"(",
"array",
"$",
"multichoices",
",",
"$",
"oldquestiontextformat",
",",
"$",
"questionid",
")",
"{",
"global",
"$",
"CFG",
";",
"// The grouped array is supposed to have just one element - let us use foreach anyway",
"// just to be sure we do not loose anything.",
"foreach",
"(",
"$",
"multichoices",
"as",
"$",
"multichoice",
")",
"{",
"// Append an artificial 'id' attribute (is not included in moodle.xml).",
"$",
"multichoice",
"[",
"'id'",
"]",
"=",
"$",
"this",
"->",
"converter",
"->",
"get_nextid",
"(",
")",
";",
"// Replay the upgrade step 2009021801.",
"$",
"multichoice",
"[",
"'correctfeedbackformat'",
"]",
"=",
"0",
";",
"$",
"multichoice",
"[",
"'partiallycorrectfeedbackformat'",
"]",
"=",
"0",
";",
"$",
"multichoice",
"[",
"'incorrectfeedbackformat'",
"]",
"=",
"0",
";",
"if",
"(",
"$",
"CFG",
"->",
"texteditors",
"!==",
"'textarea'",
"and",
"$",
"oldquestiontextformat",
"==",
"FORMAT_MOODLE",
")",
"{",
"$",
"multichoice",
"[",
"'correctfeedback'",
"]",
"=",
"text_to_html",
"(",
"$",
"multichoice",
"[",
"'correctfeedback'",
"]",
",",
"false",
",",
"false",
",",
"true",
")",
";",
"$",
"multichoice",
"[",
"'correctfeedbackformat'",
"]",
"=",
"FORMAT_HTML",
";",
"$",
"multichoice",
"[",
"'partiallycorrectfeedback'",
"]",
"=",
"text_to_html",
"(",
"$",
"multichoice",
"[",
"'partiallycorrectfeedback'",
"]",
",",
"false",
",",
"false",
",",
"true",
")",
";",
"$",
"multichoice",
"[",
"'partiallycorrectfeedbackformat'",
"]",
"=",
"FORMAT_HTML",
";",
"$",
"multichoice",
"[",
"'incorrectfeedback'",
"]",
"=",
"text_to_html",
"(",
"$",
"multichoice",
"[",
"'incorrectfeedback'",
"]",
",",
"false",
",",
"false",
",",
"true",
")",
";",
"$",
"multichoice",
"[",
"'incorrectfeedbackformat'",
"]",
"=",
"FORMAT_HTML",
";",
"}",
"else",
"{",
"$",
"multichoice",
"[",
"'correctfeedbackformat'",
"]",
"=",
"$",
"oldquestiontextformat",
";",
"$",
"multichoice",
"[",
"'partiallycorrectfeedbackformat'",
"]",
"=",
"$",
"oldquestiontextformat",
";",
"$",
"multichoice",
"[",
"'incorrectfeedbackformat'",
"]",
"=",
"$",
"oldquestiontextformat",
";",
"}",
"$",
"multichoice",
"[",
"'correctfeedback'",
"]",
"=",
"$",
"this",
"->",
"migrate_files",
"(",
"$",
"multichoice",
"[",
"'correctfeedback'",
"]",
",",
"'question'",
",",
"'correctfeedback'",
",",
"$",
"questionid",
")",
";",
"$",
"multichoice",
"[",
"'partiallycorrectfeedback'",
"]",
"=",
"$",
"this",
"->",
"migrate_files",
"(",
"$",
"multichoice",
"[",
"'partiallycorrectfeedback'",
"]",
",",
"'question'",
",",
"'partiallycorrectfeedback'",
",",
"$",
"questionid",
")",
";",
"$",
"multichoice",
"[",
"'incorrectfeedback'",
"]",
"=",
"$",
"this",
"->",
"migrate_files",
"(",
"$",
"multichoice",
"[",
"'incorrectfeedback'",
"]",
",",
"'question'",
",",
"'incorrectfeedback'",
",",
"$",
"questionid",
")",
";",
"$",
"this",
"->",
"write_xml",
"(",
"'multichoice'",
",",
"$",
"multichoice",
",",
"array",
"(",
"'/multichoice/id'",
")",
")",
";",
"}",
"}"
] |
Converts the multichoice info and writes it into the question.xml
@param array $multichoices the grouped structure
@param int $oldquestiontextformat - {@see moodle1_question_bank_handler::process_question()}
@param int $questionid question id
|
[
"Converts",
"the",
"multichoice",
"info",
"and",
"writes",
"it",
"into",
"the",
"question",
".",
"xml"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/multichoice/backup/moodle1/lib.php#L77-L113
|
215,701
|
moodle/moodle
|
backup/moodle2/backup_stepslib.php
|
backup_activity_structure_step.prepare_activity_structure
|
protected function prepare_activity_structure($activitystructure) {
// Create the wrap element
$activity = new backup_nested_element('activity', array('id', 'moduleid', 'modulename', 'contextid'), null);
// Build the tree
$activity->add_child($activitystructure);
// Set the source
$activityarr = array((object)array(
'id' => $this->task->get_activityid(),
'moduleid' => $this->task->get_moduleid(),
'modulename' => $this->task->get_modulename(),
'contextid' => $this->task->get_contextid()));
$activity->set_source_array($activityarr);
// Return the root element (activity)
return $activity;
}
|
php
|
protected function prepare_activity_structure($activitystructure) {
// Create the wrap element
$activity = new backup_nested_element('activity', array('id', 'moduleid', 'modulename', 'contextid'), null);
// Build the tree
$activity->add_child($activitystructure);
// Set the source
$activityarr = array((object)array(
'id' => $this->task->get_activityid(),
'moduleid' => $this->task->get_moduleid(),
'modulename' => $this->task->get_modulename(),
'contextid' => $this->task->get_contextid()));
$activity->set_source_array($activityarr);
// Return the root element (activity)
return $activity;
}
|
[
"protected",
"function",
"prepare_activity_structure",
"(",
"$",
"activitystructure",
")",
"{",
"// Create the wrap element",
"$",
"activity",
"=",
"new",
"backup_nested_element",
"(",
"'activity'",
",",
"array",
"(",
"'id'",
",",
"'moduleid'",
",",
"'modulename'",
",",
"'contextid'",
")",
",",
"null",
")",
";",
"// Build the tree",
"$",
"activity",
"->",
"add_child",
"(",
"$",
"activitystructure",
")",
";",
"// Set the source",
"$",
"activityarr",
"=",
"array",
"(",
"(",
"object",
")",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"task",
"->",
"get_activityid",
"(",
")",
",",
"'moduleid'",
"=>",
"$",
"this",
"->",
"task",
"->",
"get_moduleid",
"(",
")",
",",
"'modulename'",
"=>",
"$",
"this",
"->",
"task",
"->",
"get_modulename",
"(",
")",
",",
"'contextid'",
"=>",
"$",
"this",
"->",
"task",
"->",
"get_contextid",
"(",
")",
")",
")",
";",
"$",
"activity",
"->",
"set_source_array",
"(",
"$",
"activityarr",
")",
";",
"// Return the root element (activity)",
"return",
"$",
"activity",
";",
"}"
] |
Wraps any activity backup structure within the common 'activity' element
that will include common to all activities information like id, context...
@param backup_nested_element $activitystructure the element to wrap
@return backup_nested_element the $activitystructure wrapped by the common 'activity' element
|
[
"Wraps",
"any",
"activity",
"backup",
"structure",
"within",
"the",
"common",
"activity",
"element",
"that",
"will",
"include",
"common",
"to",
"all",
"activities",
"information",
"like",
"id",
"context",
"..."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/moodle2/backup_stepslib.php#L105-L124
|
215,702
|
moodle/moodle
|
backup/moodle2/backup_stepslib.php
|
backup_gradebook_structure_step.execute_condition
|
protected function execute_condition() {
$courseid = $this->get_courseid();
if ($courseid == SITEID) {
return false;
}
return backup_plan_dbops::require_gradebook_backup($courseid, $this->get_backupid());
}
|
php
|
protected function execute_condition() {
$courseid = $this->get_courseid();
if ($courseid == SITEID) {
return false;
}
return backup_plan_dbops::require_gradebook_backup($courseid, $this->get_backupid());
}
|
[
"protected",
"function",
"execute_condition",
"(",
")",
"{",
"$",
"courseid",
"=",
"$",
"this",
"->",
"get_courseid",
"(",
")",
";",
"if",
"(",
"$",
"courseid",
"==",
"SITEID",
")",
"{",
"return",
"false",
";",
"}",
"return",
"backup_plan_dbops",
"::",
"require_gradebook_backup",
"(",
"$",
"courseid",
",",
"$",
"this",
"->",
"get_backupid",
"(",
")",
")",
";",
"}"
] |
We need to decide conditionally, based on dynamic information
about the execution of this step. Only will be executed if all
the module gradeitems have been already included in backup
|
[
"We",
"need",
"to",
"decide",
"conditionally",
"based",
"on",
"dynamic",
"information",
"about",
"the",
"execution",
"of",
"this",
"step",
".",
"Only",
"will",
"be",
"executed",
"if",
"all",
"the",
"module",
"gradeitems",
"have",
"been",
"already",
"included",
"in",
"backup"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/moodle2/backup_stepslib.php#L961-L968
|
215,703
|
moodle/moodle
|
backup/moodle2/backup_stepslib.php
|
backup_enrolments_execution_step.define_execution
|
protected function define_execution() {
global $DB;
$plugins = enrol_get_plugins(true);
$enrols = $DB->get_records('enrol', array(
'courseid' => $this->task->get_courseid()));
// Allow each enrol plugin to add annotations.
foreach ($enrols as $enrol) {
if (isset($plugins[$enrol->enrol])) {
$plugins[$enrol->enrol]->backup_annotate_custom_fields($this, $enrol);
}
}
}
|
php
|
protected function define_execution() {
global $DB;
$plugins = enrol_get_plugins(true);
$enrols = $DB->get_records('enrol', array(
'courseid' => $this->task->get_courseid()));
// Allow each enrol plugin to add annotations.
foreach ($enrols as $enrol) {
if (isset($plugins[$enrol->enrol])) {
$plugins[$enrol->enrol]->backup_annotate_custom_fields($this, $enrol);
}
}
}
|
[
"protected",
"function",
"define_execution",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"plugins",
"=",
"enrol_get_plugins",
"(",
"true",
")",
";",
"$",
"enrols",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'enrol'",
",",
"array",
"(",
"'courseid'",
"=>",
"$",
"this",
"->",
"task",
"->",
"get_courseid",
"(",
")",
")",
")",
";",
"// Allow each enrol plugin to add annotations.",
"foreach",
"(",
"$",
"enrols",
"as",
"$",
"enrol",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"plugins",
"[",
"$",
"enrol",
"->",
"enrol",
"]",
")",
")",
"{",
"$",
"plugins",
"[",
"$",
"enrol",
"->",
"enrol",
"]",
"->",
"backup_annotate_custom_fields",
"(",
"$",
"this",
",",
"$",
"enrol",
")",
";",
"}",
"}",
"}"
] |
Function that will contain all the code to be executed.
|
[
"Function",
"that",
"will",
"contain",
"all",
"the",
"code",
"to",
"be",
"executed",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/moodle2/backup_stepslib.php#L2090-L2103
|
215,704
|
moodle/moodle
|
backup/moodle2/backup_stepslib.php
|
backup_activity_grading_structure_step.execute_condition
|
protected function execute_condition() {
// No grades on the front page.
if ($this->get_courseid() == SITEID) {
return false;
}
return plugin_supports('mod', $this->get_task()->get_modulename(), FEATURE_ADVANCED_GRADING, false);
}
|
php
|
protected function execute_condition() {
// No grades on the front page.
if ($this->get_courseid() == SITEID) {
return false;
}
return plugin_supports('mod', $this->get_task()->get_modulename(), FEATURE_ADVANCED_GRADING, false);
}
|
[
"protected",
"function",
"execute_condition",
"(",
")",
"{",
"// No grades on the front page.",
"if",
"(",
"$",
"this",
"->",
"get_courseid",
"(",
")",
"==",
"SITEID",
")",
"{",
"return",
"false",
";",
"}",
"return",
"plugin_supports",
"(",
"'mod'",
",",
"$",
"this",
"->",
"get_task",
"(",
")",
"->",
"get_modulename",
"(",
")",
",",
"FEATURE_ADVANCED_GRADING",
",",
"false",
")",
";",
"}"
] |
Include the grading.xml only if the module supports advanced grading
|
[
"Include",
"the",
"grading",
".",
"xml",
"only",
"if",
"the",
"module",
"supports",
"advanced",
"grading"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/moodle2/backup_stepslib.php#L2374-L2382
|
215,705
|
moodle/moodle
|
backup/moodle2/backup_stepslib.php
|
backup_activity_grading_structure_step.define_structure
|
protected function define_structure() {
// To know if we are including userinfo
$userinfo = $this->get_setting_value('userinfo');
// Define the elements
$areas = new backup_nested_element('areas');
$area = new backup_nested_element('area', array('id'), array(
'areaname', 'activemethod'));
$definitions = new backup_nested_element('definitions');
$definition = new backup_nested_element('definition', array('id'), array(
'method', 'name', 'description', 'descriptionformat', 'status',
'timecreated', 'timemodified', 'options'));
$instances = new backup_nested_element('instances');
$instance = new backup_nested_element('instance', array('id'), array(
'raterid', 'itemid', 'rawgrade', 'status', 'feedback',
'feedbackformat', 'timemodified'));
// Build the tree including the method specific structures
// (beware - the order of how gradingform plugins structures are attached is important)
$areas->add_child($area);
// attach local plugin stucture to $area element, multiple allowed
$this->add_plugin_structure('local', $area, true);
$area->add_child($definitions);
$definitions->add_child($definition);
$this->add_plugin_structure('gradingform', $definition, true);
// attach local plugin stucture to $definition element, multiple allowed
$this->add_plugin_structure('local', $definition, true);
$definition->add_child($instances);
$instances->add_child($instance);
$this->add_plugin_structure('gradingform', $instance, false);
// attach local plugin stucture to $instance element, multiple allowed
$this->add_plugin_structure('local', $instance, true);
// Define data sources
$area->set_source_table('grading_areas', array('contextid' => backup::VAR_CONTEXTID,
'component' => array('sqlparam' => 'mod_'.$this->get_task()->get_modulename())));
$definition->set_source_table('grading_definitions', array('areaid' => backup::VAR_PARENTID));
if ($userinfo) {
$instance->set_source_table('grading_instances', array('definitionid' => backup::VAR_PARENTID));
}
// Annotate references
$definition->annotate_files('grading', 'description', 'id');
$instance->annotate_ids('user', 'raterid');
// Return the root element
return $areas;
}
|
php
|
protected function define_structure() {
// To know if we are including userinfo
$userinfo = $this->get_setting_value('userinfo');
// Define the elements
$areas = new backup_nested_element('areas');
$area = new backup_nested_element('area', array('id'), array(
'areaname', 'activemethod'));
$definitions = new backup_nested_element('definitions');
$definition = new backup_nested_element('definition', array('id'), array(
'method', 'name', 'description', 'descriptionformat', 'status',
'timecreated', 'timemodified', 'options'));
$instances = new backup_nested_element('instances');
$instance = new backup_nested_element('instance', array('id'), array(
'raterid', 'itemid', 'rawgrade', 'status', 'feedback',
'feedbackformat', 'timemodified'));
// Build the tree including the method specific structures
// (beware - the order of how gradingform plugins structures are attached is important)
$areas->add_child($area);
// attach local plugin stucture to $area element, multiple allowed
$this->add_plugin_structure('local', $area, true);
$area->add_child($definitions);
$definitions->add_child($definition);
$this->add_plugin_structure('gradingform', $definition, true);
// attach local plugin stucture to $definition element, multiple allowed
$this->add_plugin_structure('local', $definition, true);
$definition->add_child($instances);
$instances->add_child($instance);
$this->add_plugin_structure('gradingform', $instance, false);
// attach local plugin stucture to $instance element, multiple allowed
$this->add_plugin_structure('local', $instance, true);
// Define data sources
$area->set_source_table('grading_areas', array('contextid' => backup::VAR_CONTEXTID,
'component' => array('sqlparam' => 'mod_'.$this->get_task()->get_modulename())));
$definition->set_source_table('grading_definitions', array('areaid' => backup::VAR_PARENTID));
if ($userinfo) {
$instance->set_source_table('grading_instances', array('definitionid' => backup::VAR_PARENTID));
}
// Annotate references
$definition->annotate_files('grading', 'description', 'id');
$instance->annotate_ids('user', 'raterid');
// Return the root element
return $areas;
}
|
[
"protected",
"function",
"define_structure",
"(",
")",
"{",
"// To know if we are including userinfo",
"$",
"userinfo",
"=",
"$",
"this",
"->",
"get_setting_value",
"(",
"'userinfo'",
")",
";",
"// Define the elements",
"$",
"areas",
"=",
"new",
"backup_nested_element",
"(",
"'areas'",
")",
";",
"$",
"area",
"=",
"new",
"backup_nested_element",
"(",
"'area'",
",",
"array",
"(",
"'id'",
")",
",",
"array",
"(",
"'areaname'",
",",
"'activemethod'",
")",
")",
";",
"$",
"definitions",
"=",
"new",
"backup_nested_element",
"(",
"'definitions'",
")",
";",
"$",
"definition",
"=",
"new",
"backup_nested_element",
"(",
"'definition'",
",",
"array",
"(",
"'id'",
")",
",",
"array",
"(",
"'method'",
",",
"'name'",
",",
"'description'",
",",
"'descriptionformat'",
",",
"'status'",
",",
"'timecreated'",
",",
"'timemodified'",
",",
"'options'",
")",
")",
";",
"$",
"instances",
"=",
"new",
"backup_nested_element",
"(",
"'instances'",
")",
";",
"$",
"instance",
"=",
"new",
"backup_nested_element",
"(",
"'instance'",
",",
"array",
"(",
"'id'",
")",
",",
"array",
"(",
"'raterid'",
",",
"'itemid'",
",",
"'rawgrade'",
",",
"'status'",
",",
"'feedback'",
",",
"'feedbackformat'",
",",
"'timemodified'",
")",
")",
";",
"// Build the tree including the method specific structures",
"// (beware - the order of how gradingform plugins structures are attached is important)",
"$",
"areas",
"->",
"add_child",
"(",
"$",
"area",
")",
";",
"// attach local plugin stucture to $area element, multiple allowed",
"$",
"this",
"->",
"add_plugin_structure",
"(",
"'local'",
",",
"$",
"area",
",",
"true",
")",
";",
"$",
"area",
"->",
"add_child",
"(",
"$",
"definitions",
")",
";",
"$",
"definitions",
"->",
"add_child",
"(",
"$",
"definition",
")",
";",
"$",
"this",
"->",
"add_plugin_structure",
"(",
"'gradingform'",
",",
"$",
"definition",
",",
"true",
")",
";",
"// attach local plugin stucture to $definition element, multiple allowed",
"$",
"this",
"->",
"add_plugin_structure",
"(",
"'local'",
",",
"$",
"definition",
",",
"true",
")",
";",
"$",
"definition",
"->",
"add_child",
"(",
"$",
"instances",
")",
";",
"$",
"instances",
"->",
"add_child",
"(",
"$",
"instance",
")",
";",
"$",
"this",
"->",
"add_plugin_structure",
"(",
"'gradingform'",
",",
"$",
"instance",
",",
"false",
")",
";",
"// attach local plugin stucture to $instance element, multiple allowed",
"$",
"this",
"->",
"add_plugin_structure",
"(",
"'local'",
",",
"$",
"instance",
",",
"true",
")",
";",
"// Define data sources",
"$",
"area",
"->",
"set_source_table",
"(",
"'grading_areas'",
",",
"array",
"(",
"'contextid'",
"=>",
"backup",
"::",
"VAR_CONTEXTID",
",",
"'component'",
"=>",
"array",
"(",
"'sqlparam'",
"=>",
"'mod_'",
".",
"$",
"this",
"->",
"get_task",
"(",
")",
"->",
"get_modulename",
"(",
")",
")",
")",
")",
";",
"$",
"definition",
"->",
"set_source_table",
"(",
"'grading_definitions'",
",",
"array",
"(",
"'areaid'",
"=>",
"backup",
"::",
"VAR_PARENTID",
")",
")",
";",
"if",
"(",
"$",
"userinfo",
")",
"{",
"$",
"instance",
"->",
"set_source_table",
"(",
"'grading_instances'",
",",
"array",
"(",
"'definitionid'",
"=>",
"backup",
"::",
"VAR_PARENTID",
")",
")",
";",
"}",
"// Annotate references",
"$",
"definition",
"->",
"annotate_files",
"(",
"'grading'",
",",
"'description'",
",",
"'id'",
")",
";",
"$",
"instance",
"->",
"annotate_ids",
"(",
"'user'",
",",
"'raterid'",
")",
";",
"// Return the root element",
"return",
"$",
"areas",
";",
"}"
] |
Declares the gradable areas structures and data sources
|
[
"Declares",
"the",
"gradable",
"areas",
"structures",
"and",
"data",
"sources"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/moodle2/backup_stepslib.php#L2387-L2444
|
215,706
|
moodle/moodle
|
lib/behat/form_field/behat_form_checkbox.php
|
behat_form_checkbox.set_value
|
public function set_value($value) {
if (!empty($value) && !$this->field->isChecked()) {
if (!$this->running_javascript()) {
$this->field->check();
return;
}
// Check it if it should be checked and it is not.
$this->field->click();
// Trigger the onchange event as triggered when 'checking' the checkbox.
$this->trigger_on_change();
} else if (empty($value) && $this->field->isChecked()) {
if (!$this->running_javascript()) {
$this->field->uncheck();
return;
}
// Uncheck if it is checked and shouldn't.
$this->field->click();
// Trigger the onchange event as triggered when 'checking' the checkbox.
$this->trigger_on_change();
}
}
|
php
|
public function set_value($value) {
if (!empty($value) && !$this->field->isChecked()) {
if (!$this->running_javascript()) {
$this->field->check();
return;
}
// Check it if it should be checked and it is not.
$this->field->click();
// Trigger the onchange event as triggered when 'checking' the checkbox.
$this->trigger_on_change();
} else if (empty($value) && $this->field->isChecked()) {
if (!$this->running_javascript()) {
$this->field->uncheck();
return;
}
// Uncheck if it is checked and shouldn't.
$this->field->click();
// Trigger the onchange event as triggered when 'checking' the checkbox.
$this->trigger_on_change();
}
}
|
[
"public",
"function",
"set_value",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"value",
")",
"&&",
"!",
"$",
"this",
"->",
"field",
"->",
"isChecked",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"running_javascript",
"(",
")",
")",
"{",
"$",
"this",
"->",
"field",
"->",
"check",
"(",
")",
";",
"return",
";",
"}",
"// Check it if it should be checked and it is not.",
"$",
"this",
"->",
"field",
"->",
"click",
"(",
")",
";",
"// Trigger the onchange event as triggered when 'checking' the checkbox.",
"$",
"this",
"->",
"trigger_on_change",
"(",
")",
";",
"}",
"else",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
"&&",
"$",
"this",
"->",
"field",
"->",
"isChecked",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"running_javascript",
"(",
")",
")",
"{",
"$",
"this",
"->",
"field",
"->",
"uncheck",
"(",
")",
";",
"return",
";",
"}",
"// Uncheck if it is checked and shouldn't.",
"$",
"this",
"->",
"field",
"->",
"click",
"(",
")",
";",
"// Trigger the onchange event as triggered when 'checking' the checkbox.",
"$",
"this",
"->",
"trigger_on_change",
"(",
")",
";",
"}",
"}"
] |
Sets the value of a checkbox.
Anything !empty() is considered checked.
@param string $value
@return void
|
[
"Sets",
"the",
"value",
"of",
"a",
"checkbox",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/form_field/behat_form_checkbox.php#L48-L76
|
215,707
|
moodle/moodle
|
lib/behat/form_field/behat_form_checkbox.php
|
behat_form_checkbox.matches
|
public function matches($expectedvalue = false) {
$ischecked = $this->field->isChecked();
// Any non-empty value provided means that it should be checked.
if (!empty($expectedvalue) && $ischecked) {
return true;
} else if (empty($expectedvalue) && !$ischecked) {
return true;
}
return false;
}
|
php
|
public function matches($expectedvalue = false) {
$ischecked = $this->field->isChecked();
// Any non-empty value provided means that it should be checked.
if (!empty($expectedvalue) && $ischecked) {
return true;
} else if (empty($expectedvalue) && !$ischecked) {
return true;
}
return false;
}
|
[
"public",
"function",
"matches",
"(",
"$",
"expectedvalue",
"=",
"false",
")",
"{",
"$",
"ischecked",
"=",
"$",
"this",
"->",
"field",
"->",
"isChecked",
"(",
")",
";",
"// Any non-empty value provided means that it should be checked.",
"if",
"(",
"!",
"empty",
"(",
"$",
"expectedvalue",
")",
"&&",
"$",
"ischecked",
")",
"{",
"return",
"true",
";",
"}",
"else",
"if",
"(",
"empty",
"(",
"$",
"expectedvalue",
")",
"&&",
"!",
"$",
"ischecked",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Is it enabled?
@param string $expectedvalue Anything !empty() is considered checked.
@return bool
|
[
"Is",
"it",
"enabled?"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/form_field/behat_form_checkbox.php#L93-L105
|
215,708
|
moodle/moodle
|
lib/behat/form_field/behat_form_checkbox.php
|
behat_form_checkbox.trigger_on_change
|
protected function trigger_on_change() {
$driver = $this->session->getDriver();
if ($driver instanceof \Moodle\BehatExtension\Driver\MoodleSelenium2Driver) {
$driver->triggerSynScript(
$this->field->getXPath(),
"Syn.trigger('change', {}, {{ELEMENT}})"
);
}
}
|
php
|
protected function trigger_on_change() {
$driver = $this->session->getDriver();
if ($driver instanceof \Moodle\BehatExtension\Driver\MoodleSelenium2Driver) {
$driver->triggerSynScript(
$this->field->getXPath(),
"Syn.trigger('change', {}, {{ELEMENT}})"
);
}
}
|
[
"protected",
"function",
"trigger_on_change",
"(",
")",
"{",
"$",
"driver",
"=",
"$",
"this",
"->",
"session",
"->",
"getDriver",
"(",
")",
";",
"if",
"(",
"$",
"driver",
"instanceof",
"\\",
"Moodle",
"\\",
"BehatExtension",
"\\",
"Driver",
"\\",
"MoodleSelenium2Driver",
")",
"{",
"$",
"driver",
"->",
"triggerSynScript",
"(",
"$",
"this",
"->",
"field",
"->",
"getXPath",
"(",
")",
",",
"\"Syn.trigger('change', {}, {{ELEMENT}})\"",
")",
";",
"}",
"}"
] |
Trigger on change event.
|
[
"Trigger",
"on",
"change",
"event",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/form_field/behat_form_checkbox.php#L110-L118
|
215,709
|
moodle/moodle
|
lib/classes/progress/display.php
|
display.start_html
|
public function start_html() {
if ($this->bar) {
throw new \coding_exception('Already started');
}
$this->bar = new \progress_bar();
$this->bar->create();
echo \html_writer::start_div('wibbler');
}
|
php
|
public function start_html() {
if ($this->bar) {
throw new \coding_exception('Already started');
}
$this->bar = new \progress_bar();
$this->bar->create();
echo \html_writer::start_div('wibbler');
}
|
[
"public",
"function",
"start_html",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"bar",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Already started'",
")",
";",
"}",
"$",
"this",
"->",
"bar",
"=",
"new",
"\\",
"progress_bar",
"(",
")",
";",
"$",
"this",
"->",
"bar",
"->",
"create",
"(",
")",
";",
"echo",
"\\",
"html_writer",
"::",
"start_div",
"(",
"'wibbler'",
")",
";",
"}"
] |
Starts to output progress.
Called in constructor and in update_progress if required.
@throws \coding_exception If already started
|
[
"Starts",
"to",
"output",
"progress",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/progress/display.php#L78-L85
|
215,710
|
moodle/moodle
|
lib/classes/progress/display.php
|
display.update_progress
|
public function update_progress() {
// If finished...
if (!$this->is_in_progress_section()) {
if ($this->bar) {
$this->end_html();
}
} else {
if (!$this->bar) {
$this->start_html();
}
// In case of indeterminate or small progress, update the wibbler
// (up to once per second).
if (time() != $this->lastwibble) {
$this->lastwibble = time();
echo \html_writer::div('', 'wibble state' . $this->currentstate);
// Go on to next colour.
$this->currentstate += $this->direction;
if ($this->currentstate < 0 || $this->currentstate >= self::WIBBLE_STATES) {
$this->direction = -$this->direction;
$this->currentstate += 2 * $this->direction;
}
$buffersize = ini_get('output_buffering');
if (!is_numeric($buffersize)) {
// The output_buffering setting can be a number, but can also be "On" or "Off".
// If "Off", there's no buffer, if "On", there's no limit to the size. In either case,
// there's no point in trying to fill the buffer.
$buffersize = 0;
}
if ($buffersize) {
// Force the buffer full.
echo str_pad('', $buffersize);
}
}
// Get progress.
list ($min, $max) = $this->get_progress_proportion_range();
// Update progress bar.
$message = '';
if ($this->displaynames) {
$message = $this->get_current_description();
}
$this->bar->update_full($min * 100, $message);
// Flush output.
flush();
}
}
|
php
|
public function update_progress() {
// If finished...
if (!$this->is_in_progress_section()) {
if ($this->bar) {
$this->end_html();
}
} else {
if (!$this->bar) {
$this->start_html();
}
// In case of indeterminate or small progress, update the wibbler
// (up to once per second).
if (time() != $this->lastwibble) {
$this->lastwibble = time();
echo \html_writer::div('', 'wibble state' . $this->currentstate);
// Go on to next colour.
$this->currentstate += $this->direction;
if ($this->currentstate < 0 || $this->currentstate >= self::WIBBLE_STATES) {
$this->direction = -$this->direction;
$this->currentstate += 2 * $this->direction;
}
$buffersize = ini_get('output_buffering');
if (!is_numeric($buffersize)) {
// The output_buffering setting can be a number, but can also be "On" or "Off".
// If "Off", there's no buffer, if "On", there's no limit to the size. In either case,
// there's no point in trying to fill the buffer.
$buffersize = 0;
}
if ($buffersize) {
// Force the buffer full.
echo str_pad('', $buffersize);
}
}
// Get progress.
list ($min, $max) = $this->get_progress_proportion_range();
// Update progress bar.
$message = '';
if ($this->displaynames) {
$message = $this->get_current_description();
}
$this->bar->update_full($min * 100, $message);
// Flush output.
flush();
}
}
|
[
"public",
"function",
"update_progress",
"(",
")",
"{",
"// If finished...",
"if",
"(",
"!",
"$",
"this",
"->",
"is_in_progress_section",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"bar",
")",
"{",
"$",
"this",
"->",
"end_html",
"(",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"bar",
")",
"{",
"$",
"this",
"->",
"start_html",
"(",
")",
";",
"}",
"// In case of indeterminate or small progress, update the wibbler",
"// (up to once per second).",
"if",
"(",
"time",
"(",
")",
"!=",
"$",
"this",
"->",
"lastwibble",
")",
"{",
"$",
"this",
"->",
"lastwibble",
"=",
"time",
"(",
")",
";",
"echo",
"\\",
"html_writer",
"::",
"div",
"(",
"''",
",",
"'wibble state'",
".",
"$",
"this",
"->",
"currentstate",
")",
";",
"// Go on to next colour.",
"$",
"this",
"->",
"currentstate",
"+=",
"$",
"this",
"->",
"direction",
";",
"if",
"(",
"$",
"this",
"->",
"currentstate",
"<",
"0",
"||",
"$",
"this",
"->",
"currentstate",
">=",
"self",
"::",
"WIBBLE_STATES",
")",
"{",
"$",
"this",
"->",
"direction",
"=",
"-",
"$",
"this",
"->",
"direction",
";",
"$",
"this",
"->",
"currentstate",
"+=",
"2",
"*",
"$",
"this",
"->",
"direction",
";",
"}",
"$",
"buffersize",
"=",
"ini_get",
"(",
"'output_buffering'",
")",
";",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"buffersize",
")",
")",
"{",
"// The output_buffering setting can be a number, but can also be \"On\" or \"Off\".",
"// If \"Off\", there's no buffer, if \"On\", there's no limit to the size. In either case,",
"// there's no point in trying to fill the buffer.",
"$",
"buffersize",
"=",
"0",
";",
"}",
"if",
"(",
"$",
"buffersize",
")",
"{",
"// Force the buffer full.",
"echo",
"str_pad",
"(",
"''",
",",
"$",
"buffersize",
")",
";",
"}",
"}",
"// Get progress.",
"list",
"(",
"$",
"min",
",",
"$",
"max",
")",
"=",
"$",
"this",
"->",
"get_progress_proportion_range",
"(",
")",
";",
"// Update progress bar.",
"$",
"message",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"displaynames",
")",
"{",
"$",
"message",
"=",
"$",
"this",
"->",
"get_current_description",
"(",
")",
";",
"}",
"$",
"this",
"->",
"bar",
"->",
"update_full",
"(",
"$",
"min",
"*",
"100",
",",
"$",
"message",
")",
";",
"// Flush output.",
"flush",
"(",
")",
";",
"}",
"}"
] |
When progress is updated, updates the bar.
@see \core\progress\base::update_progress()
|
[
"When",
"progress",
"is",
"updated",
"updates",
"the",
"bar",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/progress/display.php#L107-L155
|
215,711
|
moodle/moodle
|
mod/assign/upgradelib.php
|
assign_upgrade_manager.duplicate_course_module
|
private function duplicate_course_module(stdClass $cm, $moduleid, $newinstanceid) {
global $DB, $CFG;
$newcm = new stdClass();
$newcm->course = $cm->course;
$newcm->module = $moduleid;
$newcm->instance = $newinstanceid;
$newcm->visible = $cm->visible;
$newcm->section = $cm->section;
$newcm->score = $cm->score;
$newcm->indent = $cm->indent;
$newcm->groupmode = $cm->groupmode;
$newcm->groupingid = $cm->groupingid;
$newcm->completion = $cm->completion;
$newcm->completiongradeitemnumber = $cm->completiongradeitemnumber;
$newcm->completionview = $cm->completionview;
$newcm->completionexpected = $cm->completionexpected;
if (!empty($CFG->enableavailability)) {
$newcm->availability = $cm->availability;
}
$newcm->showdescription = $cm->showdescription;
$newcmid = add_course_module($newcm);
$newcm = get_coursemodule_from_id('', $newcmid, $cm->course);
if (!$newcm) {
return false;
}
$section = $DB->get_record("course_sections", array("id"=>$newcm->section));
if (!$section) {
return false;
}
$newcm->section = course_add_cm_to_section($newcm->course, $newcm->id, $section->section, $cm->id);
// Make sure visibility is set correctly (in particular in calendar).
// Note: Allow them to set it even without moodle/course:activityvisibility.
set_coursemodule_visible($newcm->id, $newcm->visible);
return $newcm;
}
|
php
|
private function duplicate_course_module(stdClass $cm, $moduleid, $newinstanceid) {
global $DB, $CFG;
$newcm = new stdClass();
$newcm->course = $cm->course;
$newcm->module = $moduleid;
$newcm->instance = $newinstanceid;
$newcm->visible = $cm->visible;
$newcm->section = $cm->section;
$newcm->score = $cm->score;
$newcm->indent = $cm->indent;
$newcm->groupmode = $cm->groupmode;
$newcm->groupingid = $cm->groupingid;
$newcm->completion = $cm->completion;
$newcm->completiongradeitemnumber = $cm->completiongradeitemnumber;
$newcm->completionview = $cm->completionview;
$newcm->completionexpected = $cm->completionexpected;
if (!empty($CFG->enableavailability)) {
$newcm->availability = $cm->availability;
}
$newcm->showdescription = $cm->showdescription;
$newcmid = add_course_module($newcm);
$newcm = get_coursemodule_from_id('', $newcmid, $cm->course);
if (!$newcm) {
return false;
}
$section = $DB->get_record("course_sections", array("id"=>$newcm->section));
if (!$section) {
return false;
}
$newcm->section = course_add_cm_to_section($newcm->course, $newcm->id, $section->section, $cm->id);
// Make sure visibility is set correctly (in particular in calendar).
// Note: Allow them to set it even without moodle/course:activityvisibility.
set_coursemodule_visible($newcm->id, $newcm->visible);
return $newcm;
}
|
[
"private",
"function",
"duplicate_course_module",
"(",
"stdClass",
"$",
"cm",
",",
"$",
"moduleid",
",",
"$",
"newinstanceid",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"CFG",
";",
"$",
"newcm",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"newcm",
"->",
"course",
"=",
"$",
"cm",
"->",
"course",
";",
"$",
"newcm",
"->",
"module",
"=",
"$",
"moduleid",
";",
"$",
"newcm",
"->",
"instance",
"=",
"$",
"newinstanceid",
";",
"$",
"newcm",
"->",
"visible",
"=",
"$",
"cm",
"->",
"visible",
";",
"$",
"newcm",
"->",
"section",
"=",
"$",
"cm",
"->",
"section",
";",
"$",
"newcm",
"->",
"score",
"=",
"$",
"cm",
"->",
"score",
";",
"$",
"newcm",
"->",
"indent",
"=",
"$",
"cm",
"->",
"indent",
";",
"$",
"newcm",
"->",
"groupmode",
"=",
"$",
"cm",
"->",
"groupmode",
";",
"$",
"newcm",
"->",
"groupingid",
"=",
"$",
"cm",
"->",
"groupingid",
";",
"$",
"newcm",
"->",
"completion",
"=",
"$",
"cm",
"->",
"completion",
";",
"$",
"newcm",
"->",
"completiongradeitemnumber",
"=",
"$",
"cm",
"->",
"completiongradeitemnumber",
";",
"$",
"newcm",
"->",
"completionview",
"=",
"$",
"cm",
"->",
"completionview",
";",
"$",
"newcm",
"->",
"completionexpected",
"=",
"$",
"cm",
"->",
"completionexpected",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"CFG",
"->",
"enableavailability",
")",
")",
"{",
"$",
"newcm",
"->",
"availability",
"=",
"$",
"cm",
"->",
"availability",
";",
"}",
"$",
"newcm",
"->",
"showdescription",
"=",
"$",
"cm",
"->",
"showdescription",
";",
"$",
"newcmid",
"=",
"add_course_module",
"(",
"$",
"newcm",
")",
";",
"$",
"newcm",
"=",
"get_coursemodule_from_id",
"(",
"''",
",",
"$",
"newcmid",
",",
"$",
"cm",
"->",
"course",
")",
";",
"if",
"(",
"!",
"$",
"newcm",
")",
"{",
"return",
"false",
";",
"}",
"$",
"section",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"\"course_sections\"",
",",
"array",
"(",
"\"id\"",
"=>",
"$",
"newcm",
"->",
"section",
")",
")",
";",
"if",
"(",
"!",
"$",
"section",
")",
"{",
"return",
"false",
";",
"}",
"$",
"newcm",
"->",
"section",
"=",
"course_add_cm_to_section",
"(",
"$",
"newcm",
"->",
"course",
",",
"$",
"newcm",
"->",
"id",
",",
"$",
"section",
"->",
"section",
",",
"$",
"cm",
"->",
"id",
")",
";",
"// Make sure visibility is set correctly (in particular in calendar).",
"// Note: Allow them to set it even without moodle/course:activityvisibility.",
"set_coursemodule_visible",
"(",
"$",
"newcm",
"->",
"id",
",",
"$",
"newcm",
"->",
"visible",
")",
";",
"return",
"$",
"newcm",
";",
"}"
] |
Create a duplicate course module record so we can create the upgraded
assign module alongside the old assignment module.
@param stdClass $cm The old course module record
@param int $moduleid The id of the new assign module
@param int $newinstanceid The id of the new instance of the assign module
@return mixed stdClass|bool The new course module record or FALSE
|
[
"Create",
"a",
"duplicate",
"course",
"module",
"record",
"so",
"we",
"can",
"create",
"the",
"upgraded",
"assign",
"module",
"alongside",
"the",
"old",
"assignment",
"module",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/upgradelib.php#L376-L415
|
215,712
|
moodle/moodle
|
lib/google/src/Google/Service/Compute.php
|
Google_Service_Compute_Images_Resource.listImages
|
public function listImages($project, $optParams = array())
{
$params = array('project' => $project);
$params = array_merge($params, $optParams);
return $this->call('list', array($params), "Google_Service_Compute_ImageList");
}
|
php
|
public function listImages($project, $optParams = array())
{
$params = array('project' => $project);
$params = array_merge($params, $optParams);
return $this->call('list', array($params), "Google_Service_Compute_ImageList");
}
|
[
"public",
"function",
"listImages",
"(",
"$",
"project",
",",
"$",
"optParams",
"=",
"array",
"(",
")",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'project'",
"=>",
"$",
"project",
")",
";",
"$",
"params",
"=",
"array_merge",
"(",
"$",
"params",
",",
"$",
"optParams",
")",
";",
"return",
"$",
"this",
"->",
"call",
"(",
"'list'",
",",
"array",
"(",
"$",
"params",
")",
",",
"\"Google_Service_Compute_ImageList\"",
")",
";",
"}"
] |
Retrieves the list of private images available to the specified project.
Private images are images you create that belong to your project. This method
does not get any images that belong to other projects, including publicly-
available images, like Debian 7. If you want to get a list of publicly-
available images, use this method to make a request to the respective image
project, such as debian-cloud or windows-cloud.
See Accessing images for more information. (images.listImages)
@param string $project Project ID for this request.
@param array $optParams Optional parameters.
@opt_param string filter Sets a filter expression for filtering listed
resources, in the form filter={expression}. Your {expression} must be in the
format: FIELD_NAME COMPARISON_STRING LITERAL_STRING.
The FIELD_NAME is the name of the field you want to compare. Only atomic
field types are supported (string, number, boolean). The COMPARISON_STRING
must be either eq (equals) or ne (not equals). The LITERAL_STRING is the
string value to filter to. The literal value must be valid for the type of
field (string, number, boolean). For string fields, the literal value is
interpreted as a regular expression using RE2 syntax. The literal value must
match the entire field.
For example, filter=name ne example-instance.
@opt_param string pageToken Specifies a page token to use. Use this parameter
if you want to list the next page of results. Set pageToken to the
nextPageToken returned by a previous list request.
@opt_param string maxResults Maximum count of results to be returned.
@return Google_Service_Compute_ImageList
|
[
"Retrieves",
"the",
"list",
"of",
"private",
"images",
"available",
"to",
"the",
"specified",
"project",
".",
"Private",
"images",
"are",
"images",
"you",
"create",
"that",
"belong",
"to",
"your",
"project",
".",
"This",
"method",
"does",
"not",
"get",
"any",
"images",
"that",
"belong",
"to",
"other",
"projects",
"including",
"publicly",
"-",
"available",
"images",
"like",
"Debian",
"7",
".",
"If",
"you",
"want",
"to",
"get",
"a",
"list",
"of",
"publicly",
"-",
"available",
"images",
"use",
"this",
"method",
"to",
"make",
"a",
"request",
"to",
"the",
"respective",
"image",
"project",
"such",
"as",
"debian",
"-",
"cloud",
"or",
"windows",
"-",
"cloud",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/google/src/Google/Service/Compute.php#L5605-L5610
|
215,713
|
moodle/moodle
|
question/type/randomsamatch/db/upgradelib.php
|
qtype_randomsamatch_qe2_attempt_updater.explode_answer
|
protected function explode_answer($answer) {
if (!$answer) {
return array();
}
$bits = explode(',', $answer);
$selections = array();
foreach ($bits as $bit) {
list($stem, $choice) = explode('-', $bit);
$selections[$stem] = $choice;
}
return $selections;
}
|
php
|
protected function explode_answer($answer) {
if (!$answer) {
return array();
}
$bits = explode(',', $answer);
$selections = array();
foreach ($bits as $bit) {
list($stem, $choice) = explode('-', $bit);
$selections[$stem] = $choice;
}
return $selections;
}
|
[
"protected",
"function",
"explode_answer",
"(",
"$",
"answer",
")",
"{",
"if",
"(",
"!",
"$",
"answer",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"bits",
"=",
"explode",
"(",
"','",
",",
"$",
"answer",
")",
";",
"$",
"selections",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"bits",
"as",
"$",
"bit",
")",
"{",
"list",
"(",
"$",
"stem",
",",
"$",
"choice",
")",
"=",
"explode",
"(",
"'-'",
",",
"$",
"bit",
")",
";",
"$",
"selections",
"[",
"$",
"stem",
"]",
"=",
"$",
"choice",
";",
"}",
"return",
"$",
"selections",
";",
"}"
] |
Explode the answer saved as a string in state
@param string $answer comma separated list of dash separated pairs
@return array
|
[
"Explode",
"the",
"answer",
"saved",
"as",
"a",
"string",
"in",
"state"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/randomsamatch/db/upgradelib.php#L70-L81
|
215,714
|
moodle/moodle
|
question/type/randomsamatch/db/upgradelib.php
|
qtype_randomsamatch_qe2_attempt_updater.lookup_choice
|
protected function lookup_choice($choice) {
if (array_key_exists($choice, $this->choices)) {
// Easy case: choice is a key in the choices array.
return $choice;
} else {
// But choice can also be the id of a shortanser correct answer
// without been a key of the choices array, in that case we need
// to first find the shortanswer id, then find the choices index
// associated to it.
$questionid = array_search($choice, $this->rightanswerid);
if ($questionid) {
return $this->right[$questionid];
}
}
return null;
}
|
php
|
protected function lookup_choice($choice) {
if (array_key_exists($choice, $this->choices)) {
// Easy case: choice is a key in the choices array.
return $choice;
} else {
// But choice can also be the id of a shortanser correct answer
// without been a key of the choices array, in that case we need
// to first find the shortanswer id, then find the choices index
// associated to it.
$questionid = array_search($choice, $this->rightanswerid);
if ($questionid) {
return $this->right[$questionid];
}
}
return null;
}
|
[
"protected",
"function",
"lookup_choice",
"(",
"$",
"choice",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"choice",
",",
"$",
"this",
"->",
"choices",
")",
")",
"{",
"// Easy case: choice is a key in the choices array.",
"return",
"$",
"choice",
";",
"}",
"else",
"{",
"// But choice can also be the id of a shortanser correct answer",
"// without been a key of the choices array, in that case we need",
"// to first find the shortanswer id, then find the choices index",
"// associated to it.",
"$",
"questionid",
"=",
"array_search",
"(",
"$",
"choice",
",",
"$",
"this",
"->",
"rightanswerid",
")",
";",
"if",
"(",
"$",
"questionid",
")",
"{",
"return",
"$",
"this",
"->",
"right",
"[",
"$",
"questionid",
"]",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Find the index corresponding to a choice
@param integer $choice
@return integer
|
[
"Find",
"the",
"index",
"corresponding",
"to",
"a",
"choice"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/randomsamatch/db/upgradelib.php#L97-L112
|
215,715
|
moodle/moodle
|
auth/ldap/classes/admin_setting_special_ntlm_configtext.php
|
auth_ldap_admin_setting_special_ntlm_configtext.validate
|
public function validate($data) {
if (get_config('auth_ldap', 'ntlmsso_type') === 'ntlm') {
$format = trim($data);
if (!empty($format) && !preg_match('/%username%/i', $format)) {
return get_string('auth_ntlmsso_missing_username', 'auth_ldap');
}
}
return parent::validate($data);
}
|
php
|
public function validate($data) {
if (get_config('auth_ldap', 'ntlmsso_type') === 'ntlm') {
$format = trim($data);
if (!empty($format) && !preg_match('/%username%/i', $format)) {
return get_string('auth_ntlmsso_missing_username', 'auth_ldap');
}
}
return parent::validate($data);
}
|
[
"public",
"function",
"validate",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"get_config",
"(",
"'auth_ldap'",
",",
"'ntlmsso_type'",
")",
"===",
"'ntlm'",
")",
"{",
"$",
"format",
"=",
"trim",
"(",
"$",
"data",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"format",
")",
"&&",
"!",
"preg_match",
"(",
"'/%username%/i'",
",",
"$",
"format",
")",
")",
"{",
"return",
"get_string",
"(",
"'auth_ntlmsso_missing_username'",
",",
"'auth_ldap'",
")",
";",
"}",
"}",
"return",
"parent",
"::",
"validate",
"(",
"$",
"data",
")",
";",
"}"
] |
We need to validate the username format when using NTLM.
@param string $data Form data.
@return string Empty when no errors.
|
[
"We",
"need",
"to",
"validate",
"the",
"username",
"format",
"when",
"using",
"NTLM",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/ldap/classes/admin_setting_special_ntlm_configtext.php#L42-L52
|
215,716
|
moodle/moodle
|
lib/classes/update/api.php
|
api.find_plugin
|
public function find_plugin($component, $reqversion=ANY_VERSION, $branch=null) {
global $CFG;
$params = array(
'plugin' => $component,
'format' => 'json',
);
if ($reqversion === ANY_VERSION) {
$params['minversion'] = 0;
} else {
$params['minversion'] = $reqversion;
}
if ($branch === null) {
$branch = $CFG->branch;
}
$params['branch'] = $this->convert_branch_numbering_format($branch);
return $this->call_pluginfo_service($params);
}
|
php
|
public function find_plugin($component, $reqversion=ANY_VERSION, $branch=null) {
global $CFG;
$params = array(
'plugin' => $component,
'format' => 'json',
);
if ($reqversion === ANY_VERSION) {
$params['minversion'] = 0;
} else {
$params['minversion'] = $reqversion;
}
if ($branch === null) {
$branch = $CFG->branch;
}
$params['branch'] = $this->convert_branch_numbering_format($branch);
return $this->call_pluginfo_service($params);
}
|
[
"public",
"function",
"find_plugin",
"(",
"$",
"component",
",",
"$",
"reqversion",
"=",
"ANY_VERSION",
",",
"$",
"branch",
"=",
"null",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"params",
"=",
"array",
"(",
"'plugin'",
"=>",
"$",
"component",
",",
"'format'",
"=>",
"'json'",
",",
")",
";",
"if",
"(",
"$",
"reqversion",
"===",
"ANY_VERSION",
")",
"{",
"$",
"params",
"[",
"'minversion'",
"]",
"=",
"0",
";",
"}",
"else",
"{",
"$",
"params",
"[",
"'minversion'",
"]",
"=",
"$",
"reqversion",
";",
"}",
"if",
"(",
"$",
"branch",
"===",
"null",
")",
"{",
"$",
"branch",
"=",
"$",
"CFG",
"->",
"branch",
";",
"}",
"$",
"params",
"[",
"'branch'",
"]",
"=",
"$",
"this",
"->",
"convert_branch_numbering_format",
"(",
"$",
"branch",
")",
";",
"return",
"$",
"this",
"->",
"call_pluginfo_service",
"(",
"$",
"params",
")",
";",
"}"
] |
Locate the given plugin in the plugin directory.
Uses pluginfo.php end-point to find a plugin with the given component
name, that suits best for the given Moodle core branch. Minimal required
plugin version can be specified. This is typically used for resolving
dependencies.
False is returned on error, or if there is no plugin with such component
name found in the plugins directory via the API.
If a plugin with the given component name is found, data about the
plugin are returned as an object. The ->version property of the object
contains the information about the particular plugin version that
matches best the given critera. The ->version property is false if no
suitable version of the plugin was found (yet the plugin itself is
known).
@param string $component frankenstyle name of the plugin
@param string|int $reqversion minimal required version of the plugin, defaults to ANY_VERSION
@param int $branch moodle core branch such as 29, 30, 31 etc, defaults to $CFG->branch
@return \core\update\remote_info|bool
|
[
"Locate",
"the",
"given",
"plugin",
"in",
"the",
"plugin",
"directory",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/api.php#L128-L149
|
215,717
|
moodle/moodle
|
lib/classes/update/api.php
|
api.validate_pluginfo_format
|
public function validate_pluginfo_format($data) {
if (empty($data) or !is_object($data)) {
return false;
}
$output = new remote_info();
$rootproperties = array('id' => 1, 'name' => 1, 'component' => 1, 'source' => 0, 'doc' => 0,
'bugs' => 0, 'discussion' => 0, 'version' => 0);
foreach ($rootproperties as $property => $required) {
if (!property_exists($data, $property)) {
return false;
}
if ($required and empty($data->$property)) {
return false;
}
$output->$property = $data->$property;
}
if (!empty($data->version)) {
if (!is_object($data->version)) {
return false;
}
$versionproperties = array('id' => 1, 'version' => 1, 'release' => 0, 'maturity' => 0,
'downloadurl' => 1, 'downloadmd5' => 1, 'vcssystem' => 0, 'vcssystemother' => 0,
'vcsrepositoryurl' => 0, 'vcsbranch' => 0, 'vcstag' => 0, 'supportedmoodles' => 0);
foreach ($versionproperties as $property => $required) {
if (!property_exists($data->version, $property)) {
return false;
}
if ($required and empty($data->version->$property)) {
return false;
}
}
if (!preg_match('|^https?://|i', $data->version->downloadurl)) {
return false;
}
if (!empty($data->version->supportedmoodles)) {
if (!is_array($data->version->supportedmoodles)) {
return false;
}
foreach ($data->version->supportedmoodles as $supportedmoodle) {
if (!is_object($supportedmoodle)) {
return false;
}
if (empty($supportedmoodle->version) or empty($supportedmoodle->release)) {
return false;
}
}
}
}
return $output;
}
|
php
|
public function validate_pluginfo_format($data) {
if (empty($data) or !is_object($data)) {
return false;
}
$output = new remote_info();
$rootproperties = array('id' => 1, 'name' => 1, 'component' => 1, 'source' => 0, 'doc' => 0,
'bugs' => 0, 'discussion' => 0, 'version' => 0);
foreach ($rootproperties as $property => $required) {
if (!property_exists($data, $property)) {
return false;
}
if ($required and empty($data->$property)) {
return false;
}
$output->$property = $data->$property;
}
if (!empty($data->version)) {
if (!is_object($data->version)) {
return false;
}
$versionproperties = array('id' => 1, 'version' => 1, 'release' => 0, 'maturity' => 0,
'downloadurl' => 1, 'downloadmd5' => 1, 'vcssystem' => 0, 'vcssystemother' => 0,
'vcsrepositoryurl' => 0, 'vcsbranch' => 0, 'vcstag' => 0, 'supportedmoodles' => 0);
foreach ($versionproperties as $property => $required) {
if (!property_exists($data->version, $property)) {
return false;
}
if ($required and empty($data->version->$property)) {
return false;
}
}
if (!preg_match('|^https?://|i', $data->version->downloadurl)) {
return false;
}
if (!empty($data->version->supportedmoodles)) {
if (!is_array($data->version->supportedmoodles)) {
return false;
}
foreach ($data->version->supportedmoodles as $supportedmoodle) {
if (!is_object($supportedmoodle)) {
return false;
}
if (empty($supportedmoodle->version) or empty($supportedmoodle->release)) {
return false;
}
}
}
}
return $output;
}
|
[
"public",
"function",
"validate_pluginfo_format",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"data",
")",
"or",
"!",
"is_object",
"(",
"$",
"data",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"output",
"=",
"new",
"remote_info",
"(",
")",
";",
"$",
"rootproperties",
"=",
"array",
"(",
"'id'",
"=>",
"1",
",",
"'name'",
"=>",
"1",
",",
"'component'",
"=>",
"1",
",",
"'source'",
"=>",
"0",
",",
"'doc'",
"=>",
"0",
",",
"'bugs'",
"=>",
"0",
",",
"'discussion'",
"=>",
"0",
",",
"'version'",
"=>",
"0",
")",
";",
"foreach",
"(",
"$",
"rootproperties",
"as",
"$",
"property",
"=>",
"$",
"required",
")",
"{",
"if",
"(",
"!",
"property_exists",
"(",
"$",
"data",
",",
"$",
"property",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"required",
"and",
"empty",
"(",
"$",
"data",
"->",
"$",
"property",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"output",
"->",
"$",
"property",
"=",
"$",
"data",
"->",
"$",
"property",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"->",
"version",
")",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"data",
"->",
"version",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"versionproperties",
"=",
"array",
"(",
"'id'",
"=>",
"1",
",",
"'version'",
"=>",
"1",
",",
"'release'",
"=>",
"0",
",",
"'maturity'",
"=>",
"0",
",",
"'downloadurl'",
"=>",
"1",
",",
"'downloadmd5'",
"=>",
"1",
",",
"'vcssystem'",
"=>",
"0",
",",
"'vcssystemother'",
"=>",
"0",
",",
"'vcsrepositoryurl'",
"=>",
"0",
",",
"'vcsbranch'",
"=>",
"0",
",",
"'vcstag'",
"=>",
"0",
",",
"'supportedmoodles'",
"=>",
"0",
")",
";",
"foreach",
"(",
"$",
"versionproperties",
"as",
"$",
"property",
"=>",
"$",
"required",
")",
"{",
"if",
"(",
"!",
"property_exists",
"(",
"$",
"data",
"->",
"version",
",",
"$",
"property",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"required",
"and",
"empty",
"(",
"$",
"data",
"->",
"version",
"->",
"$",
"property",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"if",
"(",
"!",
"preg_match",
"(",
"'|^https?://|i'",
",",
"$",
"data",
"->",
"version",
"->",
"downloadurl",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"->",
"version",
"->",
"supportedmoodles",
")",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
"->",
"version",
"->",
"supportedmoodles",
")",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"data",
"->",
"version",
"->",
"supportedmoodles",
"as",
"$",
"supportedmoodle",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"supportedmoodle",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"supportedmoodle",
"->",
"version",
")",
"or",
"empty",
"(",
"$",
"supportedmoodle",
"->",
"release",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"output",
";",
"}"
] |
Makes sure the given data format match the expected output of the pluginfo service.
Object validated by this method is guaranteed to contain all the data
provided by the pluginfo.php version this client works with (self::APIVER).
@param stdClass $data
@return \core\update\remote_info|bool false if data are not valid, original data otherwise
|
[
"Makes",
"sure",
"the",
"given",
"data",
"format",
"match",
"the",
"expected",
"output",
"of",
"the",
"pluginfo",
"service",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/api.php#L160-L215
|
215,718
|
moodle/moodle
|
lib/classes/update/api.php
|
api.call_pluginfo_service
|
protected function call_pluginfo_service(array $params) {
$serviceurl = $this->get_serviceurl_pluginfo();
$response = $this->call_service($serviceurl, $params);
if ($response) {
if ($response->info['http_code'] == 404) {
// There is no such plugin found in the plugins directory.
return false;
} else if ($response->info['http_code'] == 200 and isset($response->data->status)
and $response->data->status === 'OK' and $response->data->apiver == self::APIVER
and isset($response->data->pluginfo)) {
return $this->validate_pluginfo_format($response->data->pluginfo);
} else {
debugging('cURL: Unexpected response', DEBUG_DEVELOPER);
return false;
}
}
return false;
}
|
php
|
protected function call_pluginfo_service(array $params) {
$serviceurl = $this->get_serviceurl_pluginfo();
$response = $this->call_service($serviceurl, $params);
if ($response) {
if ($response->info['http_code'] == 404) {
// There is no such plugin found in the plugins directory.
return false;
} else if ($response->info['http_code'] == 200 and isset($response->data->status)
and $response->data->status === 'OK' and $response->data->apiver == self::APIVER
and isset($response->data->pluginfo)) {
return $this->validate_pluginfo_format($response->data->pluginfo);
} else {
debugging('cURL: Unexpected response', DEBUG_DEVELOPER);
return false;
}
}
return false;
}
|
[
"protected",
"function",
"call_pluginfo_service",
"(",
"array",
"$",
"params",
")",
"{",
"$",
"serviceurl",
"=",
"$",
"this",
"->",
"get_serviceurl_pluginfo",
"(",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"call_service",
"(",
"$",
"serviceurl",
",",
"$",
"params",
")",
";",
"if",
"(",
"$",
"response",
")",
"{",
"if",
"(",
"$",
"response",
"->",
"info",
"[",
"'http_code'",
"]",
"==",
"404",
")",
"{",
"// There is no such plugin found in the plugins directory.",
"return",
"false",
";",
"}",
"else",
"if",
"(",
"$",
"response",
"->",
"info",
"[",
"'http_code'",
"]",
"==",
"200",
"and",
"isset",
"(",
"$",
"response",
"->",
"data",
"->",
"status",
")",
"and",
"$",
"response",
"->",
"data",
"->",
"status",
"===",
"'OK'",
"and",
"$",
"response",
"->",
"data",
"->",
"apiver",
"==",
"self",
"::",
"APIVER",
"and",
"isset",
"(",
"$",
"response",
"->",
"data",
"->",
"pluginfo",
")",
")",
"{",
"return",
"$",
"this",
"->",
"validate_pluginfo_format",
"(",
"$",
"response",
"->",
"data",
"->",
"pluginfo",
")",
";",
"}",
"else",
"{",
"debugging",
"(",
"'cURL: Unexpected response'",
",",
"DEBUG_DEVELOPER",
")",
";",
"return",
"false",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Calls the pluginfo.php end-point with given parameters.
@param array $params
@return \core\update\remote_info|bool
|
[
"Calls",
"the",
"pluginfo",
".",
"php",
"end",
"-",
"point",
"with",
"given",
"parameters",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/api.php#L223-L245
|
215,719
|
moodle/moodle
|
lib/classes/update/api.php
|
api.call_service
|
protected function call_service($serviceurl, array $params=array()) {
$response = (object)array(
'data' => null,
'info' => null,
'status' => null,
);
$curl = new curl();
$response->data = json_decode($curl->get($serviceurl, $params, array(
'CURLOPT_SSL_VERIFYHOST' => 2,
'CURLOPT_SSL_VERIFYPEER' => true,
)));
$curlerrno = $curl->get_errno();
if (!empty($curlerrno)) {
debugging('cURL: Error '.$curlerrno.' when calling '.$serviceurl, DEBUG_DEVELOPER);
return false;
}
$response->info = $curl->get_info();
if (isset($response->info['ssl_verify_result']) and $response->info['ssl_verify_result'] != 0) {
debugging('cURL/SSL: Unable to verify remote service response when calling '.$serviceurl, DEBUG_DEVELOPER);
return false;
}
// The first response header with the HTTP status code and reason phrase.
$response->status = array_shift($curl->response);
return $response;
}
|
php
|
protected function call_service($serviceurl, array $params=array()) {
$response = (object)array(
'data' => null,
'info' => null,
'status' => null,
);
$curl = new curl();
$response->data = json_decode($curl->get($serviceurl, $params, array(
'CURLOPT_SSL_VERIFYHOST' => 2,
'CURLOPT_SSL_VERIFYPEER' => true,
)));
$curlerrno = $curl->get_errno();
if (!empty($curlerrno)) {
debugging('cURL: Error '.$curlerrno.' when calling '.$serviceurl, DEBUG_DEVELOPER);
return false;
}
$response->info = $curl->get_info();
if (isset($response->info['ssl_verify_result']) and $response->info['ssl_verify_result'] != 0) {
debugging('cURL/SSL: Unable to verify remote service response when calling '.$serviceurl, DEBUG_DEVELOPER);
return false;
}
// The first response header with the HTTP status code and reason phrase.
$response->status = array_shift($curl->response);
return $response;
}
|
[
"protected",
"function",
"call_service",
"(",
"$",
"serviceurl",
",",
"array",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"$",
"response",
"=",
"(",
"object",
")",
"array",
"(",
"'data'",
"=>",
"null",
",",
"'info'",
"=>",
"null",
",",
"'status'",
"=>",
"null",
",",
")",
";",
"$",
"curl",
"=",
"new",
"curl",
"(",
")",
";",
"$",
"response",
"->",
"data",
"=",
"json_decode",
"(",
"$",
"curl",
"->",
"get",
"(",
"$",
"serviceurl",
",",
"$",
"params",
",",
"array",
"(",
"'CURLOPT_SSL_VERIFYHOST'",
"=>",
"2",
",",
"'CURLOPT_SSL_VERIFYPEER'",
"=>",
"true",
",",
")",
")",
")",
";",
"$",
"curlerrno",
"=",
"$",
"curl",
"->",
"get_errno",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"curlerrno",
")",
")",
"{",
"debugging",
"(",
"'cURL: Error '",
".",
"$",
"curlerrno",
".",
"' when calling '",
".",
"$",
"serviceurl",
",",
"DEBUG_DEVELOPER",
")",
";",
"return",
"false",
";",
"}",
"$",
"response",
"->",
"info",
"=",
"$",
"curl",
"->",
"get_info",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"response",
"->",
"info",
"[",
"'ssl_verify_result'",
"]",
")",
"and",
"$",
"response",
"->",
"info",
"[",
"'ssl_verify_result'",
"]",
"!=",
"0",
")",
"{",
"debugging",
"(",
"'cURL/SSL: Unable to verify remote service response when calling '",
".",
"$",
"serviceurl",
",",
"DEBUG_DEVELOPER",
")",
";",
"return",
"false",
";",
"}",
"// The first response header with the HTTP status code and reason phrase.",
"$",
"response",
"->",
"status",
"=",
"array_shift",
"(",
"$",
"curl",
"->",
"response",
")",
";",
"return",
"$",
"response",
";",
"}"
] |
Calls the given end-point service with the given parameters.
Returns false on cURL error and/or SSL verification failure. Otherwise
an object with the response, cURL info and HTTP status message is
returned.
@param string $serviceurl
@param array $params
@return stdClass|bool
|
[
"Calls",
"the",
"given",
"end",
"-",
"point",
"service",
"with",
"the",
"given",
"parameters",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/api.php#L258-L291
|
215,720
|
moodle/moodle
|
lib/classes/update/api.php
|
api.convert_branch_numbering_format
|
protected function convert_branch_numbering_format($branch) {
$branch = (string)$branch;
if (strpos($branch, '.') === false) {
$branch = substr($branch, 0, -1).'.'.substr($branch, -1);
}
return $branch;
}
|
php
|
protected function convert_branch_numbering_format($branch) {
$branch = (string)$branch;
if (strpos($branch, '.') === false) {
$branch = substr($branch, 0, -1).'.'.substr($branch, -1);
}
return $branch;
}
|
[
"protected",
"function",
"convert_branch_numbering_format",
"(",
"$",
"branch",
")",
"{",
"$",
"branch",
"=",
"(",
"string",
")",
"$",
"branch",
";",
"if",
"(",
"strpos",
"(",
"$",
"branch",
",",
"'.'",
")",
"===",
"false",
")",
"{",
"$",
"branch",
"=",
"substr",
"(",
"$",
"branch",
",",
"0",
",",
"-",
"1",
")",
".",
"'.'",
".",
"substr",
"(",
"$",
"branch",
",",
"-",
"1",
")",
";",
"}",
"return",
"$",
"branch",
";",
"}"
] |
Converts the given branch from XY format to the X.Y format
The syntax of $CFG->branch uses the XY format that suits the Moodle docs
versioning and stable branches numbering scheme. The API at
download.moodle.org uses the X.Y numbering scheme.
@param int $branch moodle branch in the XY format (e.g. 29, 30, 31 etc)
@return string moodle branch in the X.Y format (e.g. 2.9, 3.0, 3.1 etc)
|
[
"Converts",
"the",
"given",
"branch",
"from",
"XY",
"format",
"to",
"the",
"X",
".",
"Y",
"format"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/api.php#L303-L312
|
215,721
|
moodle/moodle
|
lib/classes/update/api.php
|
api.get_serviceurl_pluginfo
|
protected function get_serviceurl_pluginfo() {
global $CFG;
if (!empty($CFG->config_php_settings['alternativepluginfoserviceurl'])) {
return $CFG->config_php_settings['alternativepluginfoserviceurl'];
} else {
return self::APIROOT.'/'.self::APIVER.'/pluginfo.php';
}
}
|
php
|
protected function get_serviceurl_pluginfo() {
global $CFG;
if (!empty($CFG->config_php_settings['alternativepluginfoserviceurl'])) {
return $CFG->config_php_settings['alternativepluginfoserviceurl'];
} else {
return self::APIROOT.'/'.self::APIVER.'/pluginfo.php';
}
}
|
[
"protected",
"function",
"get_serviceurl_pluginfo",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"CFG",
"->",
"config_php_settings",
"[",
"'alternativepluginfoserviceurl'",
"]",
")",
")",
"{",
"return",
"$",
"CFG",
"->",
"config_php_settings",
"[",
"'alternativepluginfoserviceurl'",
"]",
";",
"}",
"else",
"{",
"return",
"self",
"::",
"APIROOT",
".",
"'/'",
".",
"self",
"::",
"APIVER",
".",
"'/pluginfo.php'",
";",
"}",
"}"
] |
Returns URL of the pluginfo.php API end-point.
@return string
|
[
"Returns",
"URL",
"of",
"the",
"pluginfo",
".",
"php",
"API",
"end",
"-",
"point",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/api.php#L319-L327
|
215,722
|
moodle/moodle
|
mod/book/tool/print/classes/output/renderer.php
|
renderer.render_print_book_page
|
public function render_print_book_page(print_book_page $page) {
$data = $page->export_for_template($this);
return parent::render_from_template('booktool_print/print_book', $data);
}
|
php
|
public function render_print_book_page(print_book_page $page) {
$data = $page->export_for_template($this);
return parent::render_from_template('booktool_print/print_book', $data);
}
|
[
"public",
"function",
"render_print_book_page",
"(",
"print_book_page",
"$",
"page",
")",
"{",
"$",
"data",
"=",
"$",
"page",
"->",
"export_for_template",
"(",
"$",
"this",
")",
";",
"return",
"parent",
"::",
"render_from_template",
"(",
"'booktool_print/print_book'",
",",
"$",
"data",
")",
";",
"}"
] |
Render the print book page.
@param print_book_page $page
@return string html for the page
@throws moodle_exception
|
[
"Render",
"the",
"print",
"book",
"page",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/book/tool/print/classes/output/renderer.php#L50-L53
|
215,723
|
moodle/moodle
|
mod/book/tool/print/classes/output/renderer.php
|
renderer.render_print_book_chapter_page
|
public function render_print_book_chapter_page(print_book_chapter_page $page) {
$data = $page->export_for_template($this);
return parent::render_from_template('booktool_print/print_book_chapter', $data);
}
|
php
|
public function render_print_book_chapter_page(print_book_chapter_page $page) {
$data = $page->export_for_template($this);
return parent::render_from_template('booktool_print/print_book_chapter', $data);
}
|
[
"public",
"function",
"render_print_book_chapter_page",
"(",
"print_book_chapter_page",
"$",
"page",
")",
"{",
"$",
"data",
"=",
"$",
"page",
"->",
"export_for_template",
"(",
"$",
"this",
")",
";",
"return",
"parent",
"::",
"render_from_template",
"(",
"'booktool_print/print_book_chapter'",
",",
"$",
"data",
")",
";",
"}"
] |
Render the print book chapter page.
@param print_book_chapter_page $page
@return string html for the page
@throws moodle_exception
|
[
"Render",
"the",
"print",
"book",
"chapter",
"page",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/book/tool/print/classes/output/renderer.php#L62-L65
|
215,724
|
moodle/moodle
|
mod/book/tool/print/classes/output/renderer.php
|
renderer.render_print_book_chapter_dialog_link
|
public function render_print_book_chapter_dialog_link() {
$printtext = get_string('printchapter', 'booktool_print');
$printicon = $this->output->pix_icon('chapter', $printtext, 'booktool_print',
array('class' => 'icon'));
$printlinkatt = array('onclick' => 'window.print();return false;', 'class' => 'hidden-print');
return html_writer::link('#', $printicon . $printtext, $printlinkatt);
}
|
php
|
public function render_print_book_chapter_dialog_link() {
$printtext = get_string('printchapter', 'booktool_print');
$printicon = $this->output->pix_icon('chapter', $printtext, 'booktool_print',
array('class' => 'icon'));
$printlinkatt = array('onclick' => 'window.print();return false;', 'class' => 'hidden-print');
return html_writer::link('#', $printicon . $printtext, $printlinkatt);
}
|
[
"public",
"function",
"render_print_book_chapter_dialog_link",
"(",
")",
"{",
"$",
"printtext",
"=",
"get_string",
"(",
"'printchapter'",
",",
"'booktool_print'",
")",
";",
"$",
"printicon",
"=",
"$",
"this",
"->",
"output",
"->",
"pix_icon",
"(",
"'chapter'",
",",
"$",
"printtext",
",",
"'booktool_print'",
",",
"array",
"(",
"'class'",
"=>",
"'icon'",
")",
")",
";",
"$",
"printlinkatt",
"=",
"array",
"(",
"'onclick'",
"=>",
"'window.print();return false;'",
",",
"'class'",
"=>",
"'hidden-print'",
")",
";",
"return",
"html_writer",
"::",
"link",
"(",
"'#'",
",",
"$",
"printicon",
".",
"$",
"printtext",
",",
"$",
"printlinkatt",
")",
";",
"}"
] |
Render the print book chapter link.
@return string html for the link
|
[
"Render",
"the",
"print",
"book",
"chapter",
"link",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/book/tool/print/classes/output/renderer.php#L72-L78
|
215,725
|
moodle/moodle
|
mod/book/tool/print/classes/output/renderer.php
|
renderer.render_print_book_toc
|
public function render_print_book_toc($chapters, $book, $cm) {
$first = true;
$context = context_module::instance($cm->id);
$toc = ''; // Representation of toc (HTML).
switch ($book->numbering) {
case BOOK_NUM_NONE:
$toc .= html_writer::start_tag('div', array('class' => 'book_toc_none'));
break;
case BOOK_NUM_NUMBERS:
$toc .= html_writer::start_tag('div', array('class' => 'book_toc_numbered'));
break;
case BOOK_NUM_BULLETS:
$toc .= html_writer::start_tag('div', array('class' => 'book_toc_bullets'));
break;
case BOOK_NUM_INDENTED:
$toc .= html_writer::start_tag('div', array('class' => 'book_toc_indented'));
break;
}
$toc .= html_writer::tag('a', '', array('name' => 'toc')); // Representation of toc (HTML).
$toc .= html_writer::tag('h2', get_string('toc', 'mod_book'), ['class' => 'text-center p-b-2']);
$toc .= html_writer::start_tag('ul');
foreach ($chapters as $ch) {
if (!$ch->hidden) {
$title = book_get_chapter_title($ch->id, $chapters, $book, $context);
if (!$ch->subchapter) {
if ($first) {
$toc .= html_writer::start_tag('li');
} else {
$toc .= html_writer::end_tag('ul');
$toc .= html_writer::end_tag('li');
$toc .= html_writer::start_tag('li');
}
} else {
if ($first) {
$toc .= html_writer::start_tag('li');
$toc .= html_writer::start_tag('ul');
$toc .= html_writer::start_tag('li');
} else {
$toc .= html_writer::start_tag('li');
}
}
if (!$ch->subchapter) {
$toc .= html_writer::link(new moodle_url('#ch' . $ch->id), $title,
array('title' => s($title), 'class' => 'font-weight-bold text-decoration-none'));
$toc .= html_writer::start_tag('ul');
} else {
$toc .= html_writer::link(new moodle_url('#ch' . $ch->id), $title,
array('title' => s($title), 'class' => 'text-decoration-none'));
$toc .= html_writer::end_tag('li');
}
$first = false;
}
}
$toc .= html_writer::end_tag('ul');
$toc .= html_writer::end_tag('li');
$toc .= html_writer::end_tag('ul');
$toc .= html_writer::end_tag('div');
$toc = str_replace('<ul></ul>', '', $toc); // Cleanup of invalid structures.
return $toc;
}
|
php
|
public function render_print_book_toc($chapters, $book, $cm) {
$first = true;
$context = context_module::instance($cm->id);
$toc = ''; // Representation of toc (HTML).
switch ($book->numbering) {
case BOOK_NUM_NONE:
$toc .= html_writer::start_tag('div', array('class' => 'book_toc_none'));
break;
case BOOK_NUM_NUMBERS:
$toc .= html_writer::start_tag('div', array('class' => 'book_toc_numbered'));
break;
case BOOK_NUM_BULLETS:
$toc .= html_writer::start_tag('div', array('class' => 'book_toc_bullets'));
break;
case BOOK_NUM_INDENTED:
$toc .= html_writer::start_tag('div', array('class' => 'book_toc_indented'));
break;
}
$toc .= html_writer::tag('a', '', array('name' => 'toc')); // Representation of toc (HTML).
$toc .= html_writer::tag('h2', get_string('toc', 'mod_book'), ['class' => 'text-center p-b-2']);
$toc .= html_writer::start_tag('ul');
foreach ($chapters as $ch) {
if (!$ch->hidden) {
$title = book_get_chapter_title($ch->id, $chapters, $book, $context);
if (!$ch->subchapter) {
if ($first) {
$toc .= html_writer::start_tag('li');
} else {
$toc .= html_writer::end_tag('ul');
$toc .= html_writer::end_tag('li');
$toc .= html_writer::start_tag('li');
}
} else {
if ($first) {
$toc .= html_writer::start_tag('li');
$toc .= html_writer::start_tag('ul');
$toc .= html_writer::start_tag('li');
} else {
$toc .= html_writer::start_tag('li');
}
}
if (!$ch->subchapter) {
$toc .= html_writer::link(new moodle_url('#ch' . $ch->id), $title,
array('title' => s($title), 'class' => 'font-weight-bold text-decoration-none'));
$toc .= html_writer::start_tag('ul');
} else {
$toc .= html_writer::link(new moodle_url('#ch' . $ch->id), $title,
array('title' => s($title), 'class' => 'text-decoration-none'));
$toc .= html_writer::end_tag('li');
}
$first = false;
}
}
$toc .= html_writer::end_tag('ul');
$toc .= html_writer::end_tag('li');
$toc .= html_writer::end_tag('ul');
$toc .= html_writer::end_tag('div');
$toc = str_replace('<ul></ul>', '', $toc); // Cleanup of invalid structures.
return $toc;
}
|
[
"public",
"function",
"render_print_book_toc",
"(",
"$",
"chapters",
",",
"$",
"book",
",",
"$",
"cm",
")",
"{",
"$",
"first",
"=",
"true",
";",
"$",
"context",
"=",
"context_module",
"::",
"instance",
"(",
"$",
"cm",
"->",
"id",
")",
";",
"$",
"toc",
"=",
"''",
";",
"// Representation of toc (HTML).",
"switch",
"(",
"$",
"book",
"->",
"numbering",
")",
"{",
"case",
"BOOK_NUM_NONE",
":",
"$",
"toc",
".=",
"html_writer",
"::",
"start_tag",
"(",
"'div'",
",",
"array",
"(",
"'class'",
"=>",
"'book_toc_none'",
")",
")",
";",
"break",
";",
"case",
"BOOK_NUM_NUMBERS",
":",
"$",
"toc",
".=",
"html_writer",
"::",
"start_tag",
"(",
"'div'",
",",
"array",
"(",
"'class'",
"=>",
"'book_toc_numbered'",
")",
")",
";",
"break",
";",
"case",
"BOOK_NUM_BULLETS",
":",
"$",
"toc",
".=",
"html_writer",
"::",
"start_tag",
"(",
"'div'",
",",
"array",
"(",
"'class'",
"=>",
"'book_toc_bullets'",
")",
")",
";",
"break",
";",
"case",
"BOOK_NUM_INDENTED",
":",
"$",
"toc",
".=",
"html_writer",
"::",
"start_tag",
"(",
"'div'",
",",
"array",
"(",
"'class'",
"=>",
"'book_toc_indented'",
")",
")",
";",
"break",
";",
"}",
"$",
"toc",
".=",
"html_writer",
"::",
"tag",
"(",
"'a'",
",",
"''",
",",
"array",
"(",
"'name'",
"=>",
"'toc'",
")",
")",
";",
"// Representation of toc (HTML).",
"$",
"toc",
".=",
"html_writer",
"::",
"tag",
"(",
"'h2'",
",",
"get_string",
"(",
"'toc'",
",",
"'mod_book'",
")",
",",
"[",
"'class'",
"=>",
"'text-center p-b-2'",
"]",
")",
";",
"$",
"toc",
".=",
"html_writer",
"::",
"start_tag",
"(",
"'ul'",
")",
";",
"foreach",
"(",
"$",
"chapters",
"as",
"$",
"ch",
")",
"{",
"if",
"(",
"!",
"$",
"ch",
"->",
"hidden",
")",
"{",
"$",
"title",
"=",
"book_get_chapter_title",
"(",
"$",
"ch",
"->",
"id",
",",
"$",
"chapters",
",",
"$",
"book",
",",
"$",
"context",
")",
";",
"if",
"(",
"!",
"$",
"ch",
"->",
"subchapter",
")",
"{",
"if",
"(",
"$",
"first",
")",
"{",
"$",
"toc",
".=",
"html_writer",
"::",
"start_tag",
"(",
"'li'",
")",
";",
"}",
"else",
"{",
"$",
"toc",
".=",
"html_writer",
"::",
"end_tag",
"(",
"'ul'",
")",
";",
"$",
"toc",
".=",
"html_writer",
"::",
"end_tag",
"(",
"'li'",
")",
";",
"$",
"toc",
".=",
"html_writer",
"::",
"start_tag",
"(",
"'li'",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"first",
")",
"{",
"$",
"toc",
".=",
"html_writer",
"::",
"start_tag",
"(",
"'li'",
")",
";",
"$",
"toc",
".=",
"html_writer",
"::",
"start_tag",
"(",
"'ul'",
")",
";",
"$",
"toc",
".=",
"html_writer",
"::",
"start_tag",
"(",
"'li'",
")",
";",
"}",
"else",
"{",
"$",
"toc",
".=",
"html_writer",
"::",
"start_tag",
"(",
"'li'",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"ch",
"->",
"subchapter",
")",
"{",
"$",
"toc",
".=",
"html_writer",
"::",
"link",
"(",
"new",
"moodle_url",
"(",
"'#ch'",
".",
"$",
"ch",
"->",
"id",
")",
",",
"$",
"title",
",",
"array",
"(",
"'title'",
"=>",
"s",
"(",
"$",
"title",
")",
",",
"'class'",
"=>",
"'font-weight-bold text-decoration-none'",
")",
")",
";",
"$",
"toc",
".=",
"html_writer",
"::",
"start_tag",
"(",
"'ul'",
")",
";",
"}",
"else",
"{",
"$",
"toc",
".=",
"html_writer",
"::",
"link",
"(",
"new",
"moodle_url",
"(",
"'#ch'",
".",
"$",
"ch",
"->",
"id",
")",
",",
"$",
"title",
",",
"array",
"(",
"'title'",
"=>",
"s",
"(",
"$",
"title",
")",
",",
"'class'",
"=>",
"'text-decoration-none'",
")",
")",
";",
"$",
"toc",
".=",
"html_writer",
"::",
"end_tag",
"(",
"'li'",
")",
";",
"}",
"$",
"first",
"=",
"false",
";",
"}",
"}",
"$",
"toc",
".=",
"html_writer",
"::",
"end_tag",
"(",
"'ul'",
")",
";",
"$",
"toc",
".=",
"html_writer",
"::",
"end_tag",
"(",
"'li'",
")",
";",
"$",
"toc",
".=",
"html_writer",
"::",
"end_tag",
"(",
"'ul'",
")",
";",
"$",
"toc",
".=",
"html_writer",
"::",
"end_tag",
"(",
"'div'",
")",
";",
"$",
"toc",
"=",
"str_replace",
"(",
"'<ul></ul>'",
",",
"''",
",",
"$",
"toc",
")",
";",
"// Cleanup of invalid structures.",
"return",
"$",
"toc",
";",
"}"
] |
Render the print book table of contents.
@param array $chapters Array of book chapters
@param object $book The book object
@param object $cm The curse module object
@return string html for the TOC
|
[
"Render",
"the",
"print",
"book",
"table",
"of",
"contents",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/book/tool/print/classes/output/renderer.php#L101-L174
|
215,726
|
moodle/moodle
|
mod/book/tool/print/classes/output/renderer.php
|
renderer.render_print_book_chapter
|
public function render_print_book_chapter($chapter, $chapters, $book, $cm) {
global $OUTPUT;
$context = context_module::instance($cm->id);
$title = book_get_chapter_title($chapter->id, $chapters, $book, $context);
$chaptervisible = $chapter->hidden ? false : true;
$bookchapter = '';
$bookchapter .= html_writer::start_div('book_chapter p-t-1', ['id' => 'ch' . $chapter->id]);
if (!$book->customtitles) {
if (!$chapter->subchapter) {
$bookchapter .= $OUTPUT->heading($title, 2, 'text-center p-b-2');
} else {
$bookchapter .= $OUTPUT->heading($title, 3, 'text-center p-b-2');
}
}
$chaptertext = file_rewrite_pluginfile_urls($chapter->content, 'pluginfile.php', $context->id,
'mod_book', 'chapter', $chapter->id);
$bookchapter .= format_text($chaptertext, $chapter->contentformat, array('noclean' => true, 'context' => $context));
$bookchapter .= html_writer::end_div();
return array($bookchapter, $chaptervisible);
}
|
php
|
public function render_print_book_chapter($chapter, $chapters, $book, $cm) {
global $OUTPUT;
$context = context_module::instance($cm->id);
$title = book_get_chapter_title($chapter->id, $chapters, $book, $context);
$chaptervisible = $chapter->hidden ? false : true;
$bookchapter = '';
$bookchapter .= html_writer::start_div('book_chapter p-t-1', ['id' => 'ch' . $chapter->id]);
if (!$book->customtitles) {
if (!$chapter->subchapter) {
$bookchapter .= $OUTPUT->heading($title, 2, 'text-center p-b-2');
} else {
$bookchapter .= $OUTPUT->heading($title, 3, 'text-center p-b-2');
}
}
$chaptertext = file_rewrite_pluginfile_urls($chapter->content, 'pluginfile.php', $context->id,
'mod_book', 'chapter', $chapter->id);
$bookchapter .= format_text($chaptertext, $chapter->contentformat, array('noclean' => true, 'context' => $context));
$bookchapter .= html_writer::end_div();
return array($bookchapter, $chaptervisible);
}
|
[
"public",
"function",
"render_print_book_chapter",
"(",
"$",
"chapter",
",",
"$",
"chapters",
",",
"$",
"book",
",",
"$",
"cm",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"$",
"context",
"=",
"context_module",
"::",
"instance",
"(",
"$",
"cm",
"->",
"id",
")",
";",
"$",
"title",
"=",
"book_get_chapter_title",
"(",
"$",
"chapter",
"->",
"id",
",",
"$",
"chapters",
",",
"$",
"book",
",",
"$",
"context",
")",
";",
"$",
"chaptervisible",
"=",
"$",
"chapter",
"->",
"hidden",
"?",
"false",
":",
"true",
";",
"$",
"bookchapter",
"=",
"''",
";",
"$",
"bookchapter",
".=",
"html_writer",
"::",
"start_div",
"(",
"'book_chapter p-t-1'",
",",
"[",
"'id'",
"=>",
"'ch'",
".",
"$",
"chapter",
"->",
"id",
"]",
")",
";",
"if",
"(",
"!",
"$",
"book",
"->",
"customtitles",
")",
"{",
"if",
"(",
"!",
"$",
"chapter",
"->",
"subchapter",
")",
"{",
"$",
"bookchapter",
".=",
"$",
"OUTPUT",
"->",
"heading",
"(",
"$",
"title",
",",
"2",
",",
"'text-center p-b-2'",
")",
";",
"}",
"else",
"{",
"$",
"bookchapter",
".=",
"$",
"OUTPUT",
"->",
"heading",
"(",
"$",
"title",
",",
"3",
",",
"'text-center p-b-2'",
")",
";",
"}",
"}",
"$",
"chaptertext",
"=",
"file_rewrite_pluginfile_urls",
"(",
"$",
"chapter",
"->",
"content",
",",
"'pluginfile.php'",
",",
"$",
"context",
"->",
"id",
",",
"'mod_book'",
",",
"'chapter'",
",",
"$",
"chapter",
"->",
"id",
")",
";",
"$",
"bookchapter",
".=",
"format_text",
"(",
"$",
"chaptertext",
",",
"$",
"chapter",
"->",
"contentformat",
",",
"array",
"(",
"'noclean'",
"=>",
"true",
",",
"'context'",
"=>",
"$",
"context",
")",
")",
";",
"$",
"bookchapter",
".=",
"html_writer",
"::",
"end_div",
"(",
")",
";",
"return",
"array",
"(",
"$",
"bookchapter",
",",
"$",
"chaptervisible",
")",
";",
"}"
] |
Render the print book chapter.
@param object $chapter The book chapter object
@param array $chapters The array of book chapters
@param object $book The book object
@param object $cm The course module object
@return array The array containing the content of the book chapter and visibility information
|
[
"Render",
"the",
"print",
"book",
"chapter",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/book/tool/print/classes/output/renderer.php#L185-L209
|
215,727
|
moodle/moodle
|
badges/classes/external.php
|
core_badges_external.get_user_badges_parameters
|
public static function get_user_badges_parameters() {
return new external_function_parameters (
array(
'userid' => new external_value(PARAM_INT, 'Badges only for this user id, empty for current user', VALUE_DEFAULT, 0),
'courseid' => new external_value(PARAM_INT, 'Filter badges by course id, empty all the courses', VALUE_DEFAULT, 0),
'page' => new external_value(PARAM_INT, 'The page of records to return.', VALUE_DEFAULT, 0),
'perpage' => new external_value(PARAM_INT, 'The number of records to return per page', VALUE_DEFAULT, 0),
'search' => new external_value(PARAM_RAW, 'A simple string to search for', VALUE_DEFAULT, ''),
'onlypublic' => new external_value(PARAM_BOOL, 'Whether to return only public badges', VALUE_DEFAULT, false),
)
);
}
|
php
|
public static function get_user_badges_parameters() {
return new external_function_parameters (
array(
'userid' => new external_value(PARAM_INT, 'Badges only for this user id, empty for current user', VALUE_DEFAULT, 0),
'courseid' => new external_value(PARAM_INT, 'Filter badges by course id, empty all the courses', VALUE_DEFAULT, 0),
'page' => new external_value(PARAM_INT, 'The page of records to return.', VALUE_DEFAULT, 0),
'perpage' => new external_value(PARAM_INT, 'The number of records to return per page', VALUE_DEFAULT, 0),
'search' => new external_value(PARAM_RAW, 'A simple string to search for', VALUE_DEFAULT, ''),
'onlypublic' => new external_value(PARAM_BOOL, 'Whether to return only public badges', VALUE_DEFAULT, false),
)
);
}
|
[
"public",
"static",
"function",
"get_user_badges_parameters",
"(",
")",
"{",
"return",
"new",
"external_function_parameters",
"(",
"array",
"(",
"'userid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Badges only for this user id, empty for current user'",
",",
"VALUE_DEFAULT",
",",
"0",
")",
",",
"'courseid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Filter badges by course id, empty all the courses'",
",",
"VALUE_DEFAULT",
",",
"0",
")",
",",
"'page'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'The page of records to return.'",
",",
"VALUE_DEFAULT",
",",
"0",
")",
",",
"'perpage'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'The number of records to return per page'",
",",
"VALUE_DEFAULT",
",",
"0",
")",
",",
"'search'",
"=>",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'A simple string to search for'",
",",
"VALUE_DEFAULT",
",",
"''",
")",
",",
"'onlypublic'",
"=>",
"new",
"external_value",
"(",
"PARAM_BOOL",
",",
"'Whether to return only public badges'",
",",
"VALUE_DEFAULT",
",",
"false",
")",
",",
")",
")",
";",
"}"
] |
Describes the parameters for get_user_badges.
@return external_function_parameters
@since Moodle 3.1
|
[
"Describes",
"the",
"parameters",
"for",
"get_user_badges",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/badges/classes/external.php#L51-L62
|
215,728
|
moodle/moodle
|
lib/horde/framework/Horde/Imap/Client/Cache/Backend/Cache.php
|
Horde_Imap_Client_Cache_Backend_Cache._getCid
|
protected function _getCid($mailbox, $slice)
{
return implode('|', array(
'horde_imap_client',
$this->_params['username'],
$mailbox,
$this->_params['hostspec'],
$this->_params['port'],
$slice,
self::VERSION
));
}
|
php
|
protected function _getCid($mailbox, $slice)
{
return implode('|', array(
'horde_imap_client',
$this->_params['username'],
$mailbox,
$this->_params['hostspec'],
$this->_params['port'],
$slice,
self::VERSION
));
}
|
[
"protected",
"function",
"_getCid",
"(",
"$",
"mailbox",
",",
"$",
"slice",
")",
"{",
"return",
"implode",
"(",
"'|'",
",",
"array",
"(",
"'horde_imap_client'",
",",
"$",
"this",
"->",
"_params",
"[",
"'username'",
"]",
",",
"$",
"mailbox",
",",
"$",
"this",
"->",
"_params",
"[",
"'hostspec'",
"]",
",",
"$",
"this",
"->",
"_params",
"[",
"'port'",
"]",
",",
"$",
"slice",
",",
"self",
"::",
"VERSION",
")",
")",
";",
"}"
] |
Create the unique ID used to store the data in the cache.
@param string $mailbox The mailbox to cache.
@param string $slice The cache slice.
@return string The cache ID.
|
[
"Create",
"the",
"unique",
"ID",
"used",
"to",
"store",
"the",
"data",
"in",
"the",
"cache",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Cache/Backend/Cache.php#L337-L348
|
215,729
|
moodle/moodle
|
lib/horde/framework/Horde/Imap/Client/Cache/Backend/Cache.php
|
Horde_Imap_Client_Cache_Backend_Cache._loadSlice
|
protected function _loadSlice($mailbox, $slice)
{
$cache_id = $this->_getCid($mailbox, $slice);
if (!empty($this->_loaded[$cache_id])) {
return;
}
if (($data = $this->_cache->get($cache_id, 0)) !== false) {
try {
$data = @unserialize($data);
} catch (Exception $e) {}
}
if (($data !== false) && is_array($data)) {
$this->_data[$mailbox] += $data;
$this->_loaded[$cache_id] = true;
} else {
$ptr = &$this->_slicemap[$mailbox];
// Slice data is corrupt; remove from slicemap.
foreach (array_keys($ptr['s'], $slice) as $val) {
unset($ptr['s'][$val]);
}
if ($slice == $ptr['i']) {
$ptr['c'] = 0;
}
}
}
|
php
|
protected function _loadSlice($mailbox, $slice)
{
$cache_id = $this->_getCid($mailbox, $slice);
if (!empty($this->_loaded[$cache_id])) {
return;
}
if (($data = $this->_cache->get($cache_id, 0)) !== false) {
try {
$data = @unserialize($data);
} catch (Exception $e) {}
}
if (($data !== false) && is_array($data)) {
$this->_data[$mailbox] += $data;
$this->_loaded[$cache_id] = true;
} else {
$ptr = &$this->_slicemap[$mailbox];
// Slice data is corrupt; remove from slicemap.
foreach (array_keys($ptr['s'], $slice) as $val) {
unset($ptr['s'][$val]);
}
if ($slice == $ptr['i']) {
$ptr['c'] = 0;
}
}
}
|
[
"protected",
"function",
"_loadSlice",
"(",
"$",
"mailbox",
",",
"$",
"slice",
")",
"{",
"$",
"cache_id",
"=",
"$",
"this",
"->",
"_getCid",
"(",
"$",
"mailbox",
",",
"$",
"slice",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_loaded",
"[",
"$",
"cache_id",
"]",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"(",
"$",
"data",
"=",
"$",
"this",
"->",
"_cache",
"->",
"get",
"(",
"$",
"cache_id",
",",
"0",
")",
")",
"!==",
"false",
")",
"{",
"try",
"{",
"$",
"data",
"=",
"@",
"unserialize",
"(",
"$",
"data",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"}",
"}",
"if",
"(",
"(",
"$",
"data",
"!==",
"false",
")",
"&&",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"$",
"this",
"->",
"_data",
"[",
"$",
"mailbox",
"]",
"+=",
"$",
"data",
";",
"$",
"this",
"->",
"_loaded",
"[",
"$",
"cache_id",
"]",
"=",
"true",
";",
"}",
"else",
"{",
"$",
"ptr",
"=",
"&",
"$",
"this",
"->",
"_slicemap",
"[",
"$",
"mailbox",
"]",
";",
"// Slice data is corrupt; remove from slicemap.",
"foreach",
"(",
"array_keys",
"(",
"$",
"ptr",
"[",
"'s'",
"]",
",",
"$",
"slice",
")",
"as",
"$",
"val",
")",
"{",
"unset",
"(",
"$",
"ptr",
"[",
"'s'",
"]",
"[",
"$",
"val",
"]",
")",
";",
"}",
"if",
"(",
"$",
"slice",
"==",
"$",
"ptr",
"[",
"'i'",
"]",
")",
"{",
"$",
"ptr",
"[",
"'c'",
"]",
"=",
"0",
";",
"}",
"}",
"}"
] |
Load UIDs from a cache slice.
@param string $mailbox The mailbox to load.
@param integer $slice The slice to load.
|
[
"Load",
"UIDs",
"from",
"a",
"cache",
"slice",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Cache/Backend/Cache.php#L398-L427
|
215,730
|
moodle/moodle
|
lib/horde/framework/Horde/Imap/Client/Cache/Backend/Cache.php
|
Horde_Imap_Client_Cache_Backend_Cache._loadSliceMap
|
protected function _loadSliceMap($mailbox, $uidvalid = null)
{
if (!isset($this->_slicemap[$mailbox]) &&
(($data = $this->_cache->get($this->_getCid($mailbox, 'slicemap'), 0)) !== false)) {
try {
if (($slice = @unserialize($data)) &&
is_array($slice)) {
$this->_slicemap[$mailbox] = $slice;
}
} catch (Exception $e) {}
}
if (isset($this->_slicemap[$mailbox])) {
$ptr = &$this->_slicemap[$mailbox];
if (is_null($ptr['d']['uidvalid'])) {
$ptr['d']['uidvalid'] = $uidvalid;
return;
} elseif (!is_null($uidvalid) &&
($ptr['d']['uidvalid'] != $uidvalid)) {
$this->_deleteMailbox($mailbox);
} else {
return;
}
}
$this->_slicemap[$mailbox] = array(
// Tracking count for purposes of determining slices
'c' => 0,
// Metadata storage
// By default includes UIDVALIDITY of mailbox.
'd' => array('uidvalid' => $uidvalid),
// The ID of the last slice.
'i' => 0,
// The slice list.
's' => array()
);
}
|
php
|
protected function _loadSliceMap($mailbox, $uidvalid = null)
{
if (!isset($this->_slicemap[$mailbox]) &&
(($data = $this->_cache->get($this->_getCid($mailbox, 'slicemap'), 0)) !== false)) {
try {
if (($slice = @unserialize($data)) &&
is_array($slice)) {
$this->_slicemap[$mailbox] = $slice;
}
} catch (Exception $e) {}
}
if (isset($this->_slicemap[$mailbox])) {
$ptr = &$this->_slicemap[$mailbox];
if (is_null($ptr['d']['uidvalid'])) {
$ptr['d']['uidvalid'] = $uidvalid;
return;
} elseif (!is_null($uidvalid) &&
($ptr['d']['uidvalid'] != $uidvalid)) {
$this->_deleteMailbox($mailbox);
} else {
return;
}
}
$this->_slicemap[$mailbox] = array(
// Tracking count for purposes of determining slices
'c' => 0,
// Metadata storage
// By default includes UIDVALIDITY of mailbox.
'd' => array('uidvalid' => $uidvalid),
// The ID of the last slice.
'i' => 0,
// The slice list.
's' => array()
);
}
|
[
"protected",
"function",
"_loadSliceMap",
"(",
"$",
"mailbox",
",",
"$",
"uidvalid",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_slicemap",
"[",
"$",
"mailbox",
"]",
")",
"&&",
"(",
"(",
"$",
"data",
"=",
"$",
"this",
"->",
"_cache",
"->",
"get",
"(",
"$",
"this",
"->",
"_getCid",
"(",
"$",
"mailbox",
",",
"'slicemap'",
")",
",",
"0",
")",
")",
"!==",
"false",
")",
")",
"{",
"try",
"{",
"if",
"(",
"(",
"$",
"slice",
"=",
"@",
"unserialize",
"(",
"$",
"data",
")",
")",
"&&",
"is_array",
"(",
"$",
"slice",
")",
")",
"{",
"$",
"this",
"->",
"_slicemap",
"[",
"$",
"mailbox",
"]",
"=",
"$",
"slice",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_slicemap",
"[",
"$",
"mailbox",
"]",
")",
")",
"{",
"$",
"ptr",
"=",
"&",
"$",
"this",
"->",
"_slicemap",
"[",
"$",
"mailbox",
"]",
";",
"if",
"(",
"is_null",
"(",
"$",
"ptr",
"[",
"'d'",
"]",
"[",
"'uidvalid'",
"]",
")",
")",
"{",
"$",
"ptr",
"[",
"'d'",
"]",
"[",
"'uidvalid'",
"]",
"=",
"$",
"uidvalid",
";",
"return",
";",
"}",
"elseif",
"(",
"!",
"is_null",
"(",
"$",
"uidvalid",
")",
"&&",
"(",
"$",
"ptr",
"[",
"'d'",
"]",
"[",
"'uidvalid'",
"]",
"!=",
"$",
"uidvalid",
")",
")",
"{",
"$",
"this",
"->",
"_deleteMailbox",
"(",
"$",
"mailbox",
")",
";",
"}",
"else",
"{",
"return",
";",
"}",
"}",
"$",
"this",
"->",
"_slicemap",
"[",
"$",
"mailbox",
"]",
"=",
"array",
"(",
"// Tracking count for purposes of determining slices",
"'c'",
"=>",
"0",
",",
"// Metadata storage",
"// By default includes UIDVALIDITY of mailbox.",
"'d'",
"=>",
"array",
"(",
"'uidvalid'",
"=>",
"$",
"uidvalid",
")",
",",
"// The ID of the last slice.",
"'i'",
"=>",
"0",
",",
"// The slice list.",
"'s'",
"=>",
"array",
"(",
")",
")",
";",
"}"
] |
Load the slicemap for a given mailbox. The slicemap contains
the uidvalidity information, the UIDs->slice lookup table, and any
metadata that needs to be saved for the mailbox.
@param string $mailbox The mailbox.
@param integer $uidvalid The IMAP uidvalidity value of the mailbox.
|
[
"Load",
"the",
"slicemap",
"for",
"a",
"given",
"mailbox",
".",
"The",
"slicemap",
"contains",
"the",
"uidvalidity",
"information",
"the",
"UIDs",
"-",
">",
"slice",
"lookup",
"table",
"and",
"any",
"metadata",
"that",
"needs",
"to",
"be",
"saved",
"for",
"the",
"mailbox",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Cache/Backend/Cache.php#L437-L473
|
215,731
|
moodle/moodle
|
lib/horde/framework/Horde/Imap/Client/Cache/Backend/Cache.php
|
Horde_Imap_Client_Cache_Backend_Cache._toUpdate
|
protected function _toUpdate($mailbox, $type, $data)
{
if (!isset($this->_update[$mailbox])) {
$this->_update[$mailbox] = array(
'add' => array(),
'slice' => array()
);
}
$this->_update[$mailbox][$type] = ($type == 'slicemap')
? $data
: array_merge($this->_update[$mailbox][$type], $data);
}
|
php
|
protected function _toUpdate($mailbox, $type, $data)
{
if (!isset($this->_update[$mailbox])) {
$this->_update[$mailbox] = array(
'add' => array(),
'slice' => array()
);
}
$this->_update[$mailbox][$type] = ($type == 'slicemap')
? $data
: array_merge($this->_update[$mailbox][$type], $data);
}
|
[
"protected",
"function",
"_toUpdate",
"(",
"$",
"mailbox",
",",
"$",
"type",
",",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_update",
"[",
"$",
"mailbox",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_update",
"[",
"$",
"mailbox",
"]",
"=",
"array",
"(",
"'add'",
"=>",
"array",
"(",
")",
",",
"'slice'",
"=>",
"array",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"_update",
"[",
"$",
"mailbox",
"]",
"[",
"$",
"type",
"]",
"=",
"(",
"$",
"type",
"==",
"'slicemap'",
")",
"?",
"$",
"data",
":",
"array_merge",
"(",
"$",
"this",
"->",
"_update",
"[",
"$",
"mailbox",
"]",
"[",
"$",
"type",
"]",
",",
"$",
"data",
")",
";",
"}"
] |
Add update entry for a mailbox.
@param string $mailbox The mailbox.
@param string $type 'add', 'slice', or 'slicemap'.
@param mixed $data The data to update.
|
[
"Add",
"update",
"entry",
"for",
"a",
"mailbox",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Cache/Backend/Cache.php#L482-L494
|
215,732
|
moodle/moodle
|
lib/xmldb/xmldb_index.php
|
xmldb_index.set_attributes
|
public function set_attributes($type, $fields, $hints = array()) {
$this->unique = !empty($type) ? true : false;
$this->fields = $fields;
$this->hints = $hints;
}
|
php
|
public function set_attributes($type, $fields, $hints = array()) {
$this->unique = !empty($type) ? true : false;
$this->fields = $fields;
$this->hints = $hints;
}
|
[
"public",
"function",
"set_attributes",
"(",
"$",
"type",
",",
"$",
"fields",
",",
"$",
"hints",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"unique",
"=",
"!",
"empty",
"(",
"$",
"type",
")",
"?",
"true",
":",
"false",
";",
"$",
"this",
"->",
"fields",
"=",
"$",
"fields",
";",
"$",
"this",
"->",
"hints",
"=",
"$",
"hints",
";",
"}"
] |
Set all the attributes of one xmldb_index
@param string type XMLDB_INDEX_UNIQUE, XMLDB_INDEX_NOTUNIQUE
@param array fields an array of fieldnames to build the index over
@param array $hints array of optional hints
|
[
"Set",
"all",
"the",
"attributes",
"of",
"one",
"xmldb_index"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/xmldb/xmldb_index.php#L79-L83
|
215,733
|
moodle/moodle
|
lib/xmldb/xmldb_index.php
|
xmldb_index.calculateHash
|
public function calculateHash($recursive = false) {
if (!$this->loaded) {
$this->hash = null;
} else {
$key = $this->unique . implode (', ', $this->fields) . implode (', ', $this->hints);
$this->hash = md5($key);
}
}
|
php
|
public function calculateHash($recursive = false) {
if (!$this->loaded) {
$this->hash = null;
} else {
$key = $this->unique . implode (', ', $this->fields) . implode (', ', $this->hints);
$this->hash = md5($key);
}
}
|
[
"public",
"function",
"calculateHash",
"(",
"$",
"recursive",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"loaded",
")",
"{",
"$",
"this",
"->",
"hash",
"=",
"null",
";",
"}",
"else",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"unique",
".",
"implode",
"(",
"', '",
",",
"$",
"this",
"->",
"fields",
")",
".",
"implode",
"(",
"', '",
",",
"$",
"this",
"->",
"hints",
")",
";",
"$",
"this",
"->",
"hash",
"=",
"md5",
"(",
"$",
"key",
")",
";",
"}",
"}"
] |
This function calculate and set the hash of one xmldb_index
@retur nvoid, changes $this->hash
|
[
"This",
"function",
"calculate",
"and",
"set",
"the",
"hash",
"of",
"one",
"xmldb_index"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/xmldb/xmldb_index.php#L224-L231
|
215,734
|
moodle/moodle
|
lib/xmldb/xmldb_index.php
|
xmldb_index.xmlOutput
|
public function xmlOutput() {
$o = '';
$o.= ' <INDEX NAME="' . $this->name . '"';
if ($this->unique) {
$unique = 'true';
} else {
$unique = 'false';
}
$o.= ' UNIQUE="' . $unique . '"';
$o.= ' FIELDS="' . implode(', ', $this->fields) . '"';
if ($this->hints) {
$o.= ' HINTS="' . implode(', ', $this->hints) . '"';
}
if ($this->comment) {
$o.= ' COMMENT="' . htmlspecialchars($this->comment) . '"';
}
$o.= '/>' . "\n";
return $o;
}
|
php
|
public function xmlOutput() {
$o = '';
$o.= ' <INDEX NAME="' . $this->name . '"';
if ($this->unique) {
$unique = 'true';
} else {
$unique = 'false';
}
$o.= ' UNIQUE="' . $unique . '"';
$o.= ' FIELDS="' . implode(', ', $this->fields) . '"';
if ($this->hints) {
$o.= ' HINTS="' . implode(', ', $this->hints) . '"';
}
if ($this->comment) {
$o.= ' COMMENT="' . htmlspecialchars($this->comment) . '"';
}
$o.= '/>' . "\n";
return $o;
}
|
[
"public",
"function",
"xmlOutput",
"(",
")",
"{",
"$",
"o",
"=",
"''",
";",
"$",
"o",
".=",
"' <INDEX NAME=\"'",
".",
"$",
"this",
"->",
"name",
".",
"'\"'",
";",
"if",
"(",
"$",
"this",
"->",
"unique",
")",
"{",
"$",
"unique",
"=",
"'true'",
";",
"}",
"else",
"{",
"$",
"unique",
"=",
"'false'",
";",
"}",
"$",
"o",
".=",
"' UNIQUE=\"'",
".",
"$",
"unique",
".",
"'\"'",
";",
"$",
"o",
".=",
"' FIELDS=\"'",
".",
"implode",
"(",
"', '",
",",
"$",
"this",
"->",
"fields",
")",
".",
"'\"'",
";",
"if",
"(",
"$",
"this",
"->",
"hints",
")",
"{",
"$",
"o",
".=",
"' HINTS=\"'",
".",
"implode",
"(",
"', '",
",",
"$",
"this",
"->",
"hints",
")",
".",
"'\"'",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"comment",
")",
"{",
"$",
"o",
".=",
"' COMMENT=\"'",
".",
"htmlspecialchars",
"(",
"$",
"this",
"->",
"comment",
")",
".",
"'\"'",
";",
"}",
"$",
"o",
".=",
"'/>'",
".",
"\"\\n\"",
";",
"return",
"$",
"o",
";",
"}"
] |
This function will output the XML text for one index
@return string
|
[
"This",
"function",
"will",
"output",
"the",
"XML",
"text",
"for",
"one",
"index"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/xmldb/xmldb_index.php#L237-L256
|
215,735
|
moodle/moodle
|
lib/xmldb/xmldb_index.php
|
xmldb_index.setFromADOIndex
|
public function setFromADOIndex($adoindex) {
// Set the unique field
$this->unique = false;
// Set the fields, converting all them to lowercase
$fields = array_flip(array_change_key_case(array_flip($adoindex['columns'])));
$this->fields = $fields;
// Some more fields
$this->loaded = true;
$this->changed = true;
}
|
php
|
public function setFromADOIndex($adoindex) {
// Set the unique field
$this->unique = false;
// Set the fields, converting all them to lowercase
$fields = array_flip(array_change_key_case(array_flip($adoindex['columns'])));
$this->fields = $fields;
// Some more fields
$this->loaded = true;
$this->changed = true;
}
|
[
"public",
"function",
"setFromADOIndex",
"(",
"$",
"adoindex",
")",
"{",
"// Set the unique field",
"$",
"this",
"->",
"unique",
"=",
"false",
";",
"// Set the fields, converting all them to lowercase",
"$",
"fields",
"=",
"array_flip",
"(",
"array_change_key_case",
"(",
"array_flip",
"(",
"$",
"adoindex",
"[",
"'columns'",
"]",
")",
")",
")",
";",
"$",
"this",
"->",
"fields",
"=",
"$",
"fields",
";",
"// Some more fields",
"$",
"this",
"->",
"loaded",
"=",
"true",
";",
"$",
"this",
"->",
"changed",
"=",
"true",
";",
"}"
] |
This function will set all the attributes of the xmldb_index object
based on information passed in one ADOindex
@param array
@return void
|
[
"This",
"function",
"will",
"set",
"all",
"the",
"attributes",
"of",
"the",
"xmldb_index",
"object",
"based",
"on",
"information",
"passed",
"in",
"one",
"ADOindex"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/xmldb/xmldb_index.php#L264-L274
|
215,736
|
moodle/moodle
|
lib/xmldb/xmldb_index.php
|
xmldb_index.getPHP
|
public function getPHP() {
$result = '';
// The type
$unique = $this->getUnique();
if (!empty($unique)) {
$result .= 'XMLDB_INDEX_UNIQUE, ';
} else {
$result .= 'XMLDB_INDEX_NOTUNIQUE, ';
}
// The fields
$indexfields = $this->getFields();
if (!empty($indexfields)) {
$result .= "['". implode("', '", $indexfields) . "']";
} else {
$result .= 'null';
}
// Hints
$hints = $this->getHints();
if (!empty($hints)) {
$result .= ", ['". implode("', '", $hints) . "']";
}
// Return result
return $result;
}
|
php
|
public function getPHP() {
$result = '';
// The type
$unique = $this->getUnique();
if (!empty($unique)) {
$result .= 'XMLDB_INDEX_UNIQUE, ';
} else {
$result .= 'XMLDB_INDEX_NOTUNIQUE, ';
}
// The fields
$indexfields = $this->getFields();
if (!empty($indexfields)) {
$result .= "['". implode("', '", $indexfields) . "']";
} else {
$result .= 'null';
}
// Hints
$hints = $this->getHints();
if (!empty($hints)) {
$result .= ", ['". implode("', '", $hints) . "']";
}
// Return result
return $result;
}
|
[
"public",
"function",
"getPHP",
"(",
")",
"{",
"$",
"result",
"=",
"''",
";",
"// The type",
"$",
"unique",
"=",
"$",
"this",
"->",
"getUnique",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"unique",
")",
")",
"{",
"$",
"result",
".=",
"'XMLDB_INDEX_UNIQUE, '",
";",
"}",
"else",
"{",
"$",
"result",
".=",
"'XMLDB_INDEX_NOTUNIQUE, '",
";",
"}",
"// The fields",
"$",
"indexfields",
"=",
"$",
"this",
"->",
"getFields",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"indexfields",
")",
")",
"{",
"$",
"result",
".=",
"\"['\"",
".",
"implode",
"(",
"\"', '\"",
",",
"$",
"indexfields",
")",
".",
"\"']\"",
";",
"}",
"else",
"{",
"$",
"result",
".=",
"'null'",
";",
"}",
"// Hints",
"$",
"hints",
"=",
"$",
"this",
"->",
"getHints",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"hints",
")",
")",
"{",
"$",
"result",
".=",
"\", ['\"",
".",
"implode",
"(",
"\"', '\"",
",",
"$",
"hints",
")",
".",
"\"']\"",
";",
"}",
"// Return result",
"return",
"$",
"result",
";",
"}"
] |
Returns the PHP code needed to define one xmldb_index
@return string
|
[
"Returns",
"the",
"PHP",
"code",
"needed",
"to",
"define",
"one",
"xmldb_index"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/xmldb/xmldb_index.php#L280-L306
|
215,737
|
moodle/moodle
|
lib/xmldb/xmldb_index.php
|
xmldb_index.validateDefinition
|
public function validateDefinition(xmldb_table $xmldb_table=null) {
if (!$xmldb_table) {
return 'Invalid xmldb_index->validateDefinition() call, $xmldb_table is required.';
}
$total = 0;
foreach ($this->getFields() as $fieldname) {
if (!$field = $xmldb_table->getField($fieldname)) {
// argh, we do not have the fields loaded yet, this should not happen during install
continue;
}
switch ($field->getType()) {
case XMLDB_TYPE_INTEGER:
$total += 8; // big int
break;
case XMLDB_TYPE_NUMBER:
$total += 12; // this is just a guess
break;
case XMLDB_TYPE_FLOAT:
$total += 8; // double precision
break;
case XMLDB_TYPE_CHAR:
if ($field->getLength() > self::INDEX_MAX_BYTES / 3) {
return 'Invalid index definition in table {'.$xmldb_table->getName(). '}: XMLDB_TYPE_CHAR field "'.$field->getName().'" can not be indexed because it is too long.'
.' Limit is '.(self::INDEX_MAX_BYTES/3).' chars.';
}
$total += ($field->getLength() * 3); // the most complex utf-8 chars have 3 bytes
break;
case XMLDB_TYPE_TEXT:
return 'Invalid index definition in table {'.$xmldb_table->getName(). '}: XMLDB_TYPE_TEXT field "'.$field->getName().'" can not be indexed';
break;
case XMLDB_TYPE_BINARY:
return 'Invalid index definition in table {'.$xmldb_table->getName(). '}: XMLDB_TYPE_BINARY field "'.$field->getName().'" can not be indexed';
break;
case XMLDB_TYPE_DATETIME:
$total += 8; // this is just a guess
break;
case XMLDB_TYPE_TIMESTAMP:
$total += 8; // this is just a guess
break;
}
}
if ($total > self::INDEX_COMPOSED_MAX_BYTES) {
return 'Invalid index definition in table {'.$xmldb_table->getName(). '}: the composed index on fields "'.implode(',', $this->getFields()).'" is too long.'
.' Limit is '.self::INDEX_COMPOSED_MAX_BYTES.' bytes / '.(self::INDEX_COMPOSED_MAX_BYTES/3).' chars.';
}
return null;
}
|
php
|
public function validateDefinition(xmldb_table $xmldb_table=null) {
if (!$xmldb_table) {
return 'Invalid xmldb_index->validateDefinition() call, $xmldb_table is required.';
}
$total = 0;
foreach ($this->getFields() as $fieldname) {
if (!$field = $xmldb_table->getField($fieldname)) {
// argh, we do not have the fields loaded yet, this should not happen during install
continue;
}
switch ($field->getType()) {
case XMLDB_TYPE_INTEGER:
$total += 8; // big int
break;
case XMLDB_TYPE_NUMBER:
$total += 12; // this is just a guess
break;
case XMLDB_TYPE_FLOAT:
$total += 8; // double precision
break;
case XMLDB_TYPE_CHAR:
if ($field->getLength() > self::INDEX_MAX_BYTES / 3) {
return 'Invalid index definition in table {'.$xmldb_table->getName(). '}: XMLDB_TYPE_CHAR field "'.$field->getName().'" can not be indexed because it is too long.'
.' Limit is '.(self::INDEX_MAX_BYTES/3).' chars.';
}
$total += ($field->getLength() * 3); // the most complex utf-8 chars have 3 bytes
break;
case XMLDB_TYPE_TEXT:
return 'Invalid index definition in table {'.$xmldb_table->getName(). '}: XMLDB_TYPE_TEXT field "'.$field->getName().'" can not be indexed';
break;
case XMLDB_TYPE_BINARY:
return 'Invalid index definition in table {'.$xmldb_table->getName(). '}: XMLDB_TYPE_BINARY field "'.$field->getName().'" can not be indexed';
break;
case XMLDB_TYPE_DATETIME:
$total += 8; // this is just a guess
break;
case XMLDB_TYPE_TIMESTAMP:
$total += 8; // this is just a guess
break;
}
}
if ($total > self::INDEX_COMPOSED_MAX_BYTES) {
return 'Invalid index definition in table {'.$xmldb_table->getName(). '}: the composed index on fields "'.implode(',', $this->getFields()).'" is too long.'
.' Limit is '.self::INDEX_COMPOSED_MAX_BYTES.' bytes / '.(self::INDEX_COMPOSED_MAX_BYTES/3).' chars.';
}
return null;
}
|
[
"public",
"function",
"validateDefinition",
"(",
"xmldb_table",
"$",
"xmldb_table",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"xmldb_table",
")",
"{",
"return",
"'Invalid xmldb_index->validateDefinition() call, $xmldb_table is required.'",
";",
"}",
"$",
"total",
"=",
"0",
";",
"foreach",
"(",
"$",
"this",
"->",
"getFields",
"(",
")",
"as",
"$",
"fieldname",
")",
"{",
"if",
"(",
"!",
"$",
"field",
"=",
"$",
"xmldb_table",
"->",
"getField",
"(",
"$",
"fieldname",
")",
")",
"{",
"// argh, we do not have the fields loaded yet, this should not happen during install",
"continue",
";",
"}",
"switch",
"(",
"$",
"field",
"->",
"getType",
"(",
")",
")",
"{",
"case",
"XMLDB_TYPE_INTEGER",
":",
"$",
"total",
"+=",
"8",
";",
"// big int",
"break",
";",
"case",
"XMLDB_TYPE_NUMBER",
":",
"$",
"total",
"+=",
"12",
";",
"// this is just a guess",
"break",
";",
"case",
"XMLDB_TYPE_FLOAT",
":",
"$",
"total",
"+=",
"8",
";",
"// double precision",
"break",
";",
"case",
"XMLDB_TYPE_CHAR",
":",
"if",
"(",
"$",
"field",
"->",
"getLength",
"(",
")",
">",
"self",
"::",
"INDEX_MAX_BYTES",
"/",
"3",
")",
"{",
"return",
"'Invalid index definition in table {'",
".",
"$",
"xmldb_table",
"->",
"getName",
"(",
")",
".",
"'}: XMLDB_TYPE_CHAR field \"'",
".",
"$",
"field",
"->",
"getName",
"(",
")",
".",
"'\" can not be indexed because it is too long.'",
".",
"' Limit is '",
".",
"(",
"self",
"::",
"INDEX_MAX_BYTES",
"/",
"3",
")",
".",
"' chars.'",
";",
"}",
"$",
"total",
"+=",
"(",
"$",
"field",
"->",
"getLength",
"(",
")",
"*",
"3",
")",
";",
"// the most complex utf-8 chars have 3 bytes",
"break",
";",
"case",
"XMLDB_TYPE_TEXT",
":",
"return",
"'Invalid index definition in table {'",
".",
"$",
"xmldb_table",
"->",
"getName",
"(",
")",
".",
"'}: XMLDB_TYPE_TEXT field \"'",
".",
"$",
"field",
"->",
"getName",
"(",
")",
".",
"'\" can not be indexed'",
";",
"break",
";",
"case",
"XMLDB_TYPE_BINARY",
":",
"return",
"'Invalid index definition in table {'",
".",
"$",
"xmldb_table",
"->",
"getName",
"(",
")",
".",
"'}: XMLDB_TYPE_BINARY field \"'",
".",
"$",
"field",
"->",
"getName",
"(",
")",
".",
"'\" can not be indexed'",
";",
"break",
";",
"case",
"XMLDB_TYPE_DATETIME",
":",
"$",
"total",
"+=",
"8",
";",
"// this is just a guess",
"break",
";",
"case",
"XMLDB_TYPE_TIMESTAMP",
":",
"$",
"total",
"+=",
"8",
";",
"// this is just a guess",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"total",
">",
"self",
"::",
"INDEX_COMPOSED_MAX_BYTES",
")",
"{",
"return",
"'Invalid index definition in table {'",
".",
"$",
"xmldb_table",
"->",
"getName",
"(",
")",
".",
"'}: the composed index on fields \"'",
".",
"implode",
"(",
"','",
",",
"$",
"this",
"->",
"getFields",
"(",
")",
")",
".",
"'\" is too long.'",
".",
"' Limit is '",
".",
"self",
"::",
"INDEX_COMPOSED_MAX_BYTES",
".",
"' bytes / '",
".",
"(",
"self",
"::",
"INDEX_COMPOSED_MAX_BYTES",
"/",
"3",
")",
".",
"' chars.'",
";",
"}",
"return",
"null",
";",
"}"
] |
Validates the index restrictions.
The error message should not be localised because it is intended for developers,
end users and admins should never see these problems!
@param xmldb_table $xmldb_table optional when object is table
@return string null if ok, error message if problem found
|
[
"Validates",
"the",
"index",
"restrictions",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/xmldb/xmldb_index.php#L339-L396
|
215,738
|
moodle/moodle
|
lib/adminlib.php
|
admin_category.set_sorting
|
public function set_sorting($sort, $asc = true, $split = true) {
$this->sort = (bool)$sort;
$this->sortasc = (bool)$asc;
$this->sortsplit = (bool)$split;
}
|
php
|
public function set_sorting($sort, $asc = true, $split = true) {
$this->sort = (bool)$sort;
$this->sortasc = (bool)$asc;
$this->sortsplit = (bool)$split;
}
|
[
"public",
"function",
"set_sorting",
"(",
"$",
"sort",
",",
"$",
"asc",
"=",
"true",
",",
"$",
"split",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"sort",
"=",
"(",
"bool",
")",
"$",
"sort",
";",
"$",
"this",
"->",
"sortasc",
"=",
"(",
"bool",
")",
"$",
"asc",
";",
"$",
"this",
"->",
"sortsplit",
"=",
"(",
"bool",
")",
"$",
"split",
";",
"}"
] |
Sets sorting on this category.
Please note this function doesn't actually do the sorting.
It can be called anytime.
Sorting occurs when the user calls get_children.
Code using the children array directly won't see the sorted results.
@param bool $sort If set to true children will be sorted, if false they won't be.
@param bool $asc If true sorting will be ascending, otherwise descending.
@param bool $split If true we sort pages and sub categories separately.
|
[
"Sets",
"sorting",
"on",
"this",
"category",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L1026-L1030
|
215,739
|
moodle/moodle
|
lib/adminlib.php
|
admin_category.get_children
|
public function get_children() {
// If we should sort and it hasn't already been sorted.
if ($this->sort && !$this->sorted) {
if ($this->sortsplit) {
$categories = array();
$pages = array();
foreach ($this->children as $child) {
if ($child instanceof admin_category) {
$categories[] = $child;
} else {
$pages[] = $child;
}
}
core_collator::asort_objects_by_property($categories, 'visiblename');
core_collator::asort_objects_by_property($pages, 'visiblename');
if (!$this->sortasc) {
$categories = array_reverse($categories);
$pages = array_reverse($pages);
}
$this->children = array_merge($pages, $categories);
} else {
core_collator::asort_objects_by_property($this->children, 'visiblename');
if (!$this->sortasc) {
$this->children = array_reverse($this->children);
}
}
$this->sorted = true;
}
return $this->children;
}
|
php
|
public function get_children() {
// If we should sort and it hasn't already been sorted.
if ($this->sort && !$this->sorted) {
if ($this->sortsplit) {
$categories = array();
$pages = array();
foreach ($this->children as $child) {
if ($child instanceof admin_category) {
$categories[] = $child;
} else {
$pages[] = $child;
}
}
core_collator::asort_objects_by_property($categories, 'visiblename');
core_collator::asort_objects_by_property($pages, 'visiblename');
if (!$this->sortasc) {
$categories = array_reverse($categories);
$pages = array_reverse($pages);
}
$this->children = array_merge($pages, $categories);
} else {
core_collator::asort_objects_by_property($this->children, 'visiblename');
if (!$this->sortasc) {
$this->children = array_reverse($this->children);
}
}
$this->sorted = true;
}
return $this->children;
}
|
[
"public",
"function",
"get_children",
"(",
")",
"{",
"// If we should sort and it hasn't already been sorted.",
"if",
"(",
"$",
"this",
"->",
"sort",
"&&",
"!",
"$",
"this",
"->",
"sorted",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"sortsplit",
")",
"{",
"$",
"categories",
"=",
"array",
"(",
")",
";",
"$",
"pages",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"children",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"$",
"child",
"instanceof",
"admin_category",
")",
"{",
"$",
"categories",
"[",
"]",
"=",
"$",
"child",
";",
"}",
"else",
"{",
"$",
"pages",
"[",
"]",
"=",
"$",
"child",
";",
"}",
"}",
"core_collator",
"::",
"asort_objects_by_property",
"(",
"$",
"categories",
",",
"'visiblename'",
")",
";",
"core_collator",
"::",
"asort_objects_by_property",
"(",
"$",
"pages",
",",
"'visiblename'",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"sortasc",
")",
"{",
"$",
"categories",
"=",
"array_reverse",
"(",
"$",
"categories",
")",
";",
"$",
"pages",
"=",
"array_reverse",
"(",
"$",
"pages",
")",
";",
"}",
"$",
"this",
"->",
"children",
"=",
"array_merge",
"(",
"$",
"pages",
",",
"$",
"categories",
")",
";",
"}",
"else",
"{",
"core_collator",
"::",
"asort_objects_by_property",
"(",
"$",
"this",
"->",
"children",
",",
"'visiblename'",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"sortasc",
")",
"{",
"$",
"this",
"->",
"children",
"=",
"array_reverse",
"(",
"$",
"this",
"->",
"children",
")",
";",
"}",
"}",
"$",
"this",
"->",
"sorted",
"=",
"true",
";",
"}",
"return",
"$",
"this",
"->",
"children",
";",
"}"
] |
Returns the children associated with this category.
@return part_of_admin_tree[]
|
[
"Returns",
"the",
"children",
"associated",
"with",
"this",
"category",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L1037-L1066
|
215,740
|
moodle/moodle
|
lib/adminlib.php
|
admin_root.purge_children
|
public function purge_children($requirefulltree) {
$this->children = array();
$this->fulltree = ($requirefulltree || $this->fulltree);
$this->loaded = false;
//break circular dependencies - this helps PHP 5.2
while($this->category_cache) {
array_pop($this->category_cache);
}
$this->category_cache = array();
}
|
php
|
public function purge_children($requirefulltree) {
$this->children = array();
$this->fulltree = ($requirefulltree || $this->fulltree);
$this->loaded = false;
//break circular dependencies - this helps PHP 5.2
while($this->category_cache) {
array_pop($this->category_cache);
}
$this->category_cache = array();
}
|
[
"public",
"function",
"purge_children",
"(",
"$",
"requirefulltree",
")",
"{",
"$",
"this",
"->",
"children",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"fulltree",
"=",
"(",
"$",
"requirefulltree",
"||",
"$",
"this",
"->",
"fulltree",
")",
";",
"$",
"this",
"->",
"loaded",
"=",
"false",
";",
"//break circular dependencies - this helps PHP 5.2",
"while",
"(",
"$",
"this",
"->",
"category_cache",
")",
"{",
"array_pop",
"(",
"$",
"this",
"->",
"category_cache",
")",
";",
"}",
"$",
"this",
"->",
"category_cache",
"=",
"array",
"(",
")",
";",
"}"
] |
Empties children array, and sets loaded to false
@param bool $requirefulltree
|
[
"Empties",
"children",
"array",
"and",
"sets",
"loaded",
"to",
"false"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L1163-L1172
|
215,741
|
moodle/moodle
|
lib/adminlib.php
|
admin_settingdependency.parse_name
|
private function parse_name($name) {
$bits = explode('/', $name);
$name = array_pop($bits);
$plugin = '';
if ($bits) {
$plugin = array_pop($bits);
if ($plugin === 'moodle') {
$plugin = '';
}
}
return 's_'.$plugin.'_'.$name;
}
|
php
|
private function parse_name($name) {
$bits = explode('/', $name);
$name = array_pop($bits);
$plugin = '';
if ($bits) {
$plugin = array_pop($bits);
if ($plugin === 'moodle') {
$plugin = '';
}
}
return 's_'.$plugin.'_'.$name;
}
|
[
"private",
"function",
"parse_name",
"(",
"$",
"name",
")",
"{",
"$",
"bits",
"=",
"explode",
"(",
"'/'",
",",
"$",
"name",
")",
";",
"$",
"name",
"=",
"array_pop",
"(",
"$",
"bits",
")",
";",
"$",
"plugin",
"=",
"''",
";",
"if",
"(",
"$",
"bits",
")",
"{",
"$",
"plugin",
"=",
"array_pop",
"(",
"$",
"bits",
")",
";",
"if",
"(",
"$",
"plugin",
"===",
"'moodle'",
")",
"{",
"$",
"plugin",
"=",
"''",
";",
"}",
"}",
"return",
"'s_'",
".",
"$",
"plugin",
".",
"'_'",
".",
"$",
"name",
";",
"}"
] |
Convert the setting name into the form field name.
@param string $name
@return string
|
[
"Convert",
"the",
"setting",
"name",
"into",
"the",
"form",
"field",
"name",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L1363-L1374
|
215,742
|
moodle/moodle
|
lib/adminlib.php
|
admin_settingdependency.prepare_for_javascript
|
public static function prepare_for_javascript($dependencies) {
$result = [];
foreach ($dependencies as $d) {
if (!isset($result[$d->dependenton])) {
$result[$d->dependenton] = [];
}
if (!isset($result[$d->dependenton][$d->condition])) {
$result[$d->dependenton][$d->condition] = [];
}
if (!isset($result[$d->dependenton][$d->condition][$d->value])) {
$result[$d->dependenton][$d->condition][$d->value] = [];
}
$result[$d->dependenton][$d->condition][$d->value][] = $d->settingname;
}
return $result;
}
|
php
|
public static function prepare_for_javascript($dependencies) {
$result = [];
foreach ($dependencies as $d) {
if (!isset($result[$d->dependenton])) {
$result[$d->dependenton] = [];
}
if (!isset($result[$d->dependenton][$d->condition])) {
$result[$d->dependenton][$d->condition] = [];
}
if (!isset($result[$d->dependenton][$d->condition][$d->value])) {
$result[$d->dependenton][$d->condition][$d->value] = [];
}
$result[$d->dependenton][$d->condition][$d->value][] = $d->settingname;
}
return $result;
}
|
[
"public",
"static",
"function",
"prepare_for_javascript",
"(",
"$",
"dependencies",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"dependencies",
"as",
"$",
"d",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"result",
"[",
"$",
"d",
"->",
"dependenton",
"]",
")",
")",
"{",
"$",
"result",
"[",
"$",
"d",
"->",
"dependenton",
"]",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"result",
"[",
"$",
"d",
"->",
"dependenton",
"]",
"[",
"$",
"d",
"->",
"condition",
"]",
")",
")",
"{",
"$",
"result",
"[",
"$",
"d",
"->",
"dependenton",
"]",
"[",
"$",
"d",
"->",
"condition",
"]",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"result",
"[",
"$",
"d",
"->",
"dependenton",
"]",
"[",
"$",
"d",
"->",
"condition",
"]",
"[",
"$",
"d",
"->",
"value",
"]",
")",
")",
"{",
"$",
"result",
"[",
"$",
"d",
"->",
"dependenton",
"]",
"[",
"$",
"d",
"->",
"condition",
"]",
"[",
"$",
"d",
"->",
"value",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"result",
"[",
"$",
"d",
"->",
"dependenton",
"]",
"[",
"$",
"d",
"->",
"condition",
"]",
"[",
"$",
"d",
"->",
"value",
"]",
"[",
"]",
"=",
"$",
"d",
"->",
"settingname",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Gather together all the dependencies in a format suitable for initialising javascript
@param admin_settingdependency[] $dependencies
@return array
|
[
"Gather",
"together",
"all",
"the",
"dependencies",
"in",
"a",
"format",
"suitable",
"for",
"initialising",
"javascript"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L1381-L1396
|
215,743
|
moodle/moodle
|
lib/adminlib.php
|
admin_settingpage.search
|
public function search($query) {
$found = array();
foreach ($this->settings as $setting) {
if ($setting->is_related($query)) {
$found[] = $setting;
}
}
if ($found) {
$result = new stdClass();
$result->page = $this;
$result->settings = $found;
return array($this->name => $result);
}
$found = false;
if (strpos(strtolower($this->name), $query) !== false) {
$found = true;
} else if (strpos(core_text::strtolower($this->visiblename), $query) !== false) {
$found = true;
}
if ($found) {
$result = new stdClass();
$result->page = $this;
$result->settings = array();
return array($this->name => $result);
} else {
return array();
}
}
|
php
|
public function search($query) {
$found = array();
foreach ($this->settings as $setting) {
if ($setting->is_related($query)) {
$found[] = $setting;
}
}
if ($found) {
$result = new stdClass();
$result->page = $this;
$result->settings = $found;
return array($this->name => $result);
}
$found = false;
if (strpos(strtolower($this->name), $query) !== false) {
$found = true;
} else if (strpos(core_text::strtolower($this->visiblename), $query) !== false) {
$found = true;
}
if ($found) {
$result = new stdClass();
$result->page = $this;
$result->settings = array();
return array($this->name => $result);
} else {
return array();
}
}
|
[
"public",
"function",
"search",
"(",
"$",
"query",
")",
"{",
"$",
"found",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"settings",
"as",
"$",
"setting",
")",
"{",
"if",
"(",
"$",
"setting",
"->",
"is_related",
"(",
"$",
"query",
")",
")",
"{",
"$",
"found",
"[",
"]",
"=",
"$",
"setting",
";",
"}",
"}",
"if",
"(",
"$",
"found",
")",
"{",
"$",
"result",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"result",
"->",
"page",
"=",
"$",
"this",
";",
"$",
"result",
"->",
"settings",
"=",
"$",
"found",
";",
"return",
"array",
"(",
"$",
"this",
"->",
"name",
"=>",
"$",
"result",
")",
";",
"}",
"$",
"found",
"=",
"false",
";",
"if",
"(",
"strpos",
"(",
"strtolower",
"(",
"$",
"this",
"->",
"name",
")",
",",
"$",
"query",
")",
"!==",
"false",
")",
"{",
"$",
"found",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"strpos",
"(",
"core_text",
"::",
"strtolower",
"(",
"$",
"this",
"->",
"visiblename",
")",
",",
"$",
"query",
")",
"!==",
"false",
")",
"{",
"$",
"found",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"found",
")",
"{",
"$",
"result",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"result",
"->",
"page",
"=",
"$",
"this",
";",
"$",
"result",
"->",
"settings",
"=",
"array",
"(",
")",
";",
"return",
"array",
"(",
"$",
"this",
"->",
"name",
"=>",
"$",
"result",
")",
";",
"}",
"else",
"{",
"return",
"array",
"(",
")",
";",
"}",
"}"
] |
Search string in settings page.
@param string $query
@return array
|
[
"Search",
"string",
"in",
"settings",
"page",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L1482-L1512
|
215,744
|
moodle/moodle
|
lib/adminlib.php
|
admin_settingpage.add
|
public function add($setting) {
if (!($setting instanceof admin_setting)) {
debugging('error - not a setting instance');
return false;
}
$name = $setting->name;
if ($setting->plugin) {
$name = $setting->plugin . $name;
}
$this->settings->{$name} = $setting;
return true;
}
|
php
|
public function add($setting) {
if (!($setting instanceof admin_setting)) {
debugging('error - not a setting instance');
return false;
}
$name = $setting->name;
if ($setting->plugin) {
$name = $setting->plugin . $name;
}
$this->settings->{$name} = $setting;
return true;
}
|
[
"public",
"function",
"add",
"(",
"$",
"setting",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"setting",
"instanceof",
"admin_setting",
")",
")",
"{",
"debugging",
"(",
"'error - not a setting instance'",
")",
";",
"return",
"false",
";",
"}",
"$",
"name",
"=",
"$",
"setting",
"->",
"name",
";",
"if",
"(",
"$",
"setting",
"->",
"plugin",
")",
"{",
"$",
"name",
"=",
"$",
"setting",
"->",
"plugin",
".",
"$",
"name",
";",
"}",
"$",
"this",
"->",
"settings",
"->",
"{",
"$",
"name",
"}",
"=",
"$",
"setting",
";",
"return",
"true",
";",
"}"
] |
adds an admin_setting to this admin_settingpage
not the same as add for admin_category. adds an admin_setting to this admin_settingpage. settings appear (on the settingpage) in the order in which they're added
n.b. each admin_setting in an admin_settingpage must have a unique internal name
@param object $setting is the admin_setting object you want to add
@return bool true if successful, false if not
|
[
"adds",
"an",
"admin_setting",
"to",
"this",
"admin_settingpage"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L1533-L1545
|
215,745
|
moodle/moodle
|
lib/adminlib.php
|
admin_settingpage.hide_if
|
public function hide_if($settingname, $dependenton, $condition = 'notchecked', $value = '1') {
$this->dependencies[] = new admin_settingdependency($settingname, $dependenton, $condition, $value);
// Reformat the dependency name to the plugin | name format used in the display.
$dependenton = str_replace('/', ' | ', $dependenton);
// Let the setting know, so it can be displayed underneath.
$findname = str_replace('/', '', $settingname);
foreach ($this->settings as $name => $setting) {
if ($name === $findname) {
$setting->add_dependent_on($dependenton);
}
}
}
|
php
|
public function hide_if($settingname, $dependenton, $condition = 'notchecked', $value = '1') {
$this->dependencies[] = new admin_settingdependency($settingname, $dependenton, $condition, $value);
// Reformat the dependency name to the plugin | name format used in the display.
$dependenton = str_replace('/', ' | ', $dependenton);
// Let the setting know, so it can be displayed underneath.
$findname = str_replace('/', '', $settingname);
foreach ($this->settings as $name => $setting) {
if ($name === $findname) {
$setting->add_dependent_on($dependenton);
}
}
}
|
[
"public",
"function",
"hide_if",
"(",
"$",
"settingname",
",",
"$",
"dependenton",
",",
"$",
"condition",
"=",
"'notchecked'",
",",
"$",
"value",
"=",
"'1'",
")",
"{",
"$",
"this",
"->",
"dependencies",
"[",
"]",
"=",
"new",
"admin_settingdependency",
"(",
"$",
"settingname",
",",
"$",
"dependenton",
",",
"$",
"condition",
",",
"$",
"value",
")",
";",
"// Reformat the dependency name to the plugin | name format used in the display.",
"$",
"dependenton",
"=",
"str_replace",
"(",
"'/'",
",",
"' | '",
",",
"$",
"dependenton",
")",
";",
"// Let the setting know, so it can be displayed underneath.",
"$",
"findname",
"=",
"str_replace",
"(",
"'/'",
",",
"''",
",",
"$",
"settingname",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"settings",
"as",
"$",
"name",
"=>",
"$",
"setting",
")",
"{",
"if",
"(",
"$",
"name",
"===",
"$",
"findname",
")",
"{",
"$",
"setting",
"->",
"add_dependent_on",
"(",
"$",
"dependenton",
")",
";",
"}",
"}",
"}"
] |
Hide the named setting if the specified condition is matched.
@param string $settingname
@param string $dependenton
@param string $condition
@param string $value
|
[
"Hide",
"the",
"named",
"setting",
"if",
"the",
"specified",
"condition",
"is",
"matched",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L1555-L1568
|
215,746
|
moodle/moodle
|
lib/adminlib.php
|
admin_settingpage.show_save
|
public function show_save() {
foreach($this->settings as $setting) {
if (empty($setting->nosave)) {
return true;
}
}
return false;
}
|
php
|
public function show_save() {
foreach($this->settings as $setting) {
if (empty($setting->nosave)) {
return true;
}
}
return false;
}
|
[
"public",
"function",
"show_save",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"settings",
"as",
"$",
"setting",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"setting",
"->",
"nosave",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Show we display Save button at the page bottom?
@return bool
|
[
"Show",
"we",
"display",
"Save",
"button",
"at",
"the",
"page",
"bottom?"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L1620-L1627
|
215,747
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting.set_flag_options
|
protected function set_flag_options($enabled, $default, $shortname, $displayname) {
if (empty($this->flags[$shortname])) {
$this->flags[$shortname] = new admin_setting_flag($enabled, $default, $shortname, $displayname);
} else {
$this->flags[$shortname]->set_options($enabled, $default);
}
}
|
php
|
protected function set_flag_options($enabled, $default, $shortname, $displayname) {
if (empty($this->flags[$shortname])) {
$this->flags[$shortname] = new admin_setting_flag($enabled, $default, $shortname, $displayname);
} else {
$this->flags[$shortname]->set_options($enabled, $default);
}
}
|
[
"protected",
"function",
"set_flag_options",
"(",
"$",
"enabled",
",",
"$",
"default",
",",
"$",
"shortname",
",",
"$",
"displayname",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"flags",
"[",
"$",
"shortname",
"]",
")",
")",
"{",
"$",
"this",
"->",
"flags",
"[",
"$",
"shortname",
"]",
"=",
"new",
"admin_setting_flag",
"(",
"$",
"enabled",
",",
"$",
"default",
",",
"$",
"shortname",
",",
"$",
"displayname",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"flags",
"[",
"$",
"shortname",
"]",
"->",
"set_options",
"(",
"$",
"enabled",
",",
"$",
"default",
")",
";",
"}",
"}"
] |
Generic function to add a flag to this admin setting.
@param bool $enabled - One of self::OPTION_ENABLED or self::OPTION_DISABLED
@param bool $default - The default for the flag
@param string $shortname - The shortname for this flag. Used as a suffix for the setting name.
@param string $displayname - The display name for this flag. Used as a label next to the checkbox.
|
[
"Generic",
"function",
"to",
"add",
"a",
"flag",
"to",
"this",
"admin",
"setting",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L1703-L1709
|
215,748
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting.get_setting_flag_value
|
public function get_setting_flag_value(admin_setting_flag $flag) {
$value = $this->config_read($this->name . '_' . $flag->get_shortname());
if (!isset($value)) {
$value = $flag->get_default();
}
return !empty($value);
}
|
php
|
public function get_setting_flag_value(admin_setting_flag $flag) {
$value = $this->config_read($this->name . '_' . $flag->get_shortname());
if (!isset($value)) {
$value = $flag->get_default();
}
return !empty($value);
}
|
[
"public",
"function",
"get_setting_flag_value",
"(",
"admin_setting_flag",
"$",
"flag",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"config_read",
"(",
"$",
"this",
"->",
"name",
".",
"'_'",
".",
"$",
"flag",
"->",
"get_shortname",
"(",
")",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"$",
"flag",
"->",
"get_default",
"(",
")",
";",
"}",
"return",
"!",
"empty",
"(",
"$",
"value",
")",
";",
"}"
] |
Get the currently saved value for a setting flag
@param admin_setting_flag $flag - One of the admin_setting_flag for this admin_setting.
@return bool
|
[
"Get",
"the",
"currently",
"saved",
"value",
"for",
"a",
"setting",
"flag"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L1748-L1755
|
215,749
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting.get_setting_flag_defaults
|
public function get_setting_flag_defaults(& $defaults) {
foreach ($this->flags as $flag) {
if ($flag->is_enabled() && $flag->get_default()) {
$defaults[] = $flag->get_displayname();
}
}
}
|
php
|
public function get_setting_flag_defaults(& $defaults) {
foreach ($this->flags as $flag) {
if ($flag->is_enabled() && $flag->get_default()) {
$defaults[] = $flag->get_displayname();
}
}
}
|
[
"public",
"function",
"get_setting_flag_defaults",
"(",
"&",
"$",
"defaults",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"flags",
"as",
"$",
"flag",
")",
"{",
"if",
"(",
"$",
"flag",
"->",
"is_enabled",
"(",
")",
"&&",
"$",
"flag",
"->",
"get_default",
"(",
")",
")",
"{",
"$",
"defaults",
"[",
"]",
"=",
"$",
"flag",
"->",
"get_displayname",
"(",
")",
";",
"}",
"}",
"}"
] |
Get the list of defaults for the flags on this setting.
@param array of strings describing the defaults for this setting. This is appended to by this function.
|
[
"Get",
"the",
"list",
"of",
"defaults",
"for",
"the",
"flags",
"on",
"this",
"setting",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L1762-L1768
|
215,750
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting.output_setting_flags
|
public function output_setting_flags() {
$output = '';
foreach ($this->flags as $flag) {
if ($flag->is_enabled()) {
$output .= $flag->output_setting_flag($this);
}
}
if (!empty($output)) {
return html_writer::tag('span', $output, array('class' => 'adminsettingsflags'));
}
return $output;
}
|
php
|
public function output_setting_flags() {
$output = '';
foreach ($this->flags as $flag) {
if ($flag->is_enabled()) {
$output .= $flag->output_setting_flag($this);
}
}
if (!empty($output)) {
return html_writer::tag('span', $output, array('class' => 'adminsettingsflags'));
}
return $output;
}
|
[
"public",
"function",
"output_setting_flags",
"(",
")",
"{",
"$",
"output",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"flags",
"as",
"$",
"flag",
")",
"{",
"if",
"(",
"$",
"flag",
"->",
"is_enabled",
"(",
")",
")",
"{",
"$",
"output",
".=",
"$",
"flag",
"->",
"output_setting_flag",
"(",
"$",
"this",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"output",
")",
")",
"{",
"return",
"html_writer",
"::",
"tag",
"(",
"'span'",
",",
"$",
"output",
",",
"array",
"(",
"'class'",
"=>",
"'adminsettingsflags'",
")",
")",
";",
"}",
"return",
"$",
"output",
";",
"}"
] |
Output the input fields for the advanced and locked flags on this setting.
@param bool $adv - The current value of the advanced flag.
@param bool $locked - The current value of the locked flag.
@return string $output - The html for the flags.
|
[
"Output",
"the",
"input",
"fields",
"for",
"the",
"advanced",
"and",
"locked",
"flags",
"on",
"this",
"setting",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L1777-L1790
|
215,751
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting.write_setting_flags
|
public function write_setting_flags($data) {
$result = true;
foreach ($this->flags as $flag) {
$result = $result && $flag->write_setting_flag($this, $data);
}
return $result;
}
|
php
|
public function write_setting_flags($data) {
$result = true;
foreach ($this->flags as $flag) {
$result = $result && $flag->write_setting_flag($this, $data);
}
return $result;
}
|
[
"public",
"function",
"write_setting_flags",
"(",
"$",
"data",
")",
"{",
"$",
"result",
"=",
"true",
";",
"foreach",
"(",
"$",
"this",
"->",
"flags",
"as",
"$",
"flag",
")",
"{",
"$",
"result",
"=",
"$",
"result",
"&&",
"$",
"flag",
"->",
"write_setting_flag",
"(",
"$",
"this",
",",
"$",
"data",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Write the values of the flags for this admin setting.
@param array $data - The data submitted from the form or null to set the default value for new installs.
@return bool - true if successful.
|
[
"Write",
"the",
"values",
"of",
"the",
"flags",
"for",
"this",
"admin",
"setting",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L1798-L1804
|
215,752
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting.config_read
|
public function config_read($name) {
global $CFG;
if (!empty($this->plugin)) {
$value = get_config($this->plugin, $name);
return $value === false ? NULL : $value;
} else {
if (isset($CFG->$name)) {
return $CFG->$name;
} else {
return NULL;
}
}
}
|
php
|
public function config_read($name) {
global $CFG;
if (!empty($this->plugin)) {
$value = get_config($this->plugin, $name);
return $value === false ? NULL : $value;
} else {
if (isset($CFG->$name)) {
return $CFG->$name;
} else {
return NULL;
}
}
}
|
[
"public",
"function",
"config_read",
"(",
"$",
"name",
")",
"{",
"global",
"$",
"CFG",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"plugin",
")",
")",
"{",
"$",
"value",
"=",
"get_config",
"(",
"$",
"this",
"->",
"plugin",
",",
"$",
"name",
")",
";",
"return",
"$",
"value",
"===",
"false",
"?",
"NULL",
":",
"$",
"value",
";",
"}",
"else",
"{",
"if",
"(",
"isset",
"(",
"$",
"CFG",
"->",
"$",
"name",
")",
")",
"{",
"return",
"$",
"CFG",
"->",
"$",
"name",
";",
"}",
"else",
"{",
"return",
"NULL",
";",
"}",
"}",
"}"
] |
Returns the config if possible
@return mixed returns config if successful else null
|
[
"Returns",
"the",
"config",
"if",
"possible"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L1864-L1877
|
215,753
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting.config_write
|
public function config_write($name, $value) {
global $DB, $USER, $CFG;
if ($this->nosave) {
return true;
}
// make sure it is a real change
$oldvalue = get_config($this->plugin, $name);
$oldvalue = ($oldvalue === false) ? null : $oldvalue; // normalise
$value = is_null($value) ? null : (string)$value;
if ($oldvalue === $value) {
return true;
}
// store change
set_config($name, $value, $this->plugin);
// Some admin settings affect course modinfo
if ($this->affectsmodinfo) {
// Clear course cache for all courses
rebuild_course_cache(0, true);
}
$this->add_to_config_log($name, $oldvalue, $value);
return true; // BC only
}
|
php
|
public function config_write($name, $value) {
global $DB, $USER, $CFG;
if ($this->nosave) {
return true;
}
// make sure it is a real change
$oldvalue = get_config($this->plugin, $name);
$oldvalue = ($oldvalue === false) ? null : $oldvalue; // normalise
$value = is_null($value) ? null : (string)$value;
if ($oldvalue === $value) {
return true;
}
// store change
set_config($name, $value, $this->plugin);
// Some admin settings affect course modinfo
if ($this->affectsmodinfo) {
// Clear course cache for all courses
rebuild_course_cache(0, true);
}
$this->add_to_config_log($name, $oldvalue, $value);
return true; // BC only
}
|
[
"public",
"function",
"config_write",
"(",
"$",
"name",
",",
"$",
"value",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"USER",
",",
"$",
"CFG",
";",
"if",
"(",
"$",
"this",
"->",
"nosave",
")",
"{",
"return",
"true",
";",
"}",
"// make sure it is a real change",
"$",
"oldvalue",
"=",
"get_config",
"(",
"$",
"this",
"->",
"plugin",
",",
"$",
"name",
")",
";",
"$",
"oldvalue",
"=",
"(",
"$",
"oldvalue",
"===",
"false",
")",
"?",
"null",
":",
"$",
"oldvalue",
";",
"// normalise",
"$",
"value",
"=",
"is_null",
"(",
"$",
"value",
")",
"?",
"null",
":",
"(",
"string",
")",
"$",
"value",
";",
"if",
"(",
"$",
"oldvalue",
"===",
"$",
"value",
")",
"{",
"return",
"true",
";",
"}",
"// store change",
"set_config",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"this",
"->",
"plugin",
")",
";",
"// Some admin settings affect course modinfo",
"if",
"(",
"$",
"this",
"->",
"affectsmodinfo",
")",
"{",
"// Clear course cache for all courses",
"rebuild_course_cache",
"(",
"0",
",",
"true",
")",
";",
"}",
"$",
"this",
"->",
"add_to_config_log",
"(",
"$",
"name",
",",
"$",
"oldvalue",
",",
"$",
"value",
")",
";",
"return",
"true",
";",
"// BC only",
"}"
] |
Used to set a config pair and log change
@param string $name
@param mixed $value Gets converted to string if not null
@return bool Write setting to config table
|
[
"Used",
"to",
"set",
"a",
"config",
"pair",
"and",
"log",
"change"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L1886-L1914
|
215,754
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting.get_defaultsetting
|
public function get_defaultsetting() {
$adminroot = admin_get_root(false, false);
if (!empty($adminroot->custom_defaults)) {
$plugin = is_null($this->plugin) ? 'moodle' : $this->plugin;
if (isset($adminroot->custom_defaults[$plugin])) {
if (array_key_exists($this->name, $adminroot->custom_defaults[$plugin])) { // null is valid value here ;-)
return $adminroot->custom_defaults[$plugin][$this->name];
}
}
}
return $this->defaultsetting;
}
|
php
|
public function get_defaultsetting() {
$adminroot = admin_get_root(false, false);
if (!empty($adminroot->custom_defaults)) {
$plugin = is_null($this->plugin) ? 'moodle' : $this->plugin;
if (isset($adminroot->custom_defaults[$plugin])) {
if (array_key_exists($this->name, $adminroot->custom_defaults[$plugin])) { // null is valid value here ;-)
return $adminroot->custom_defaults[$plugin][$this->name];
}
}
}
return $this->defaultsetting;
}
|
[
"public",
"function",
"get_defaultsetting",
"(",
")",
"{",
"$",
"adminroot",
"=",
"admin_get_root",
"(",
"false",
",",
"false",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"adminroot",
"->",
"custom_defaults",
")",
")",
"{",
"$",
"plugin",
"=",
"is_null",
"(",
"$",
"this",
"->",
"plugin",
")",
"?",
"'moodle'",
":",
"$",
"this",
"->",
"plugin",
";",
"if",
"(",
"isset",
"(",
"$",
"adminroot",
"->",
"custom_defaults",
"[",
"$",
"plugin",
"]",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"adminroot",
"->",
"custom_defaults",
"[",
"$",
"plugin",
"]",
")",
")",
"{",
"// null is valid value here ;-)",
"return",
"$",
"adminroot",
"->",
"custom_defaults",
"[",
"$",
"plugin",
"]",
"[",
"$",
"this",
"->",
"name",
"]",
";",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"defaultsetting",
";",
"}"
] |
Returns default setting if exists
@return mixed array or string depending on instance; NULL means no default, user must supply
|
[
"Returns",
"default",
"setting",
"if",
"exists"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L1936-L1947
|
215,755
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting.post_write_settings
|
public function post_write_settings($original) {
// Comparison must work for arrays too.
if (serialize($original) === serialize($this->get_setting())) {
return false;
}
$callbackfunction = $this->updatedcallback;
if (!empty($callbackfunction) and is_callable($callbackfunction)) {
$callbackfunction($this->get_full_name());
}
return true;
}
|
php
|
public function post_write_settings($original) {
// Comparison must work for arrays too.
if (serialize($original) === serialize($this->get_setting())) {
return false;
}
$callbackfunction = $this->updatedcallback;
if (!empty($callbackfunction) and is_callable($callbackfunction)) {
$callbackfunction($this->get_full_name());
}
return true;
}
|
[
"public",
"function",
"post_write_settings",
"(",
"$",
"original",
")",
"{",
"// Comparison must work for arrays too.",
"if",
"(",
"serialize",
"(",
"$",
"original",
")",
"===",
"serialize",
"(",
"$",
"this",
"->",
"get_setting",
"(",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"callbackfunction",
"=",
"$",
"this",
"->",
"updatedcallback",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"callbackfunction",
")",
"and",
"is_callable",
"(",
"$",
"callbackfunction",
")",
")",
"{",
"$",
"callbackfunction",
"(",
"$",
"this",
"->",
"get_full_name",
"(",
")",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Execute postupdatecallback if necessary.
@param mixed $original original value before write_setting()
@return bool true if changed, false if not.
|
[
"Execute",
"postupdatecallback",
"if",
"necessary",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L1984-L1995
|
215,756
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_flag.output_setting_flag
|
public function output_setting_flag(admin_setting $setting) {
global $OUTPUT;
$value = $setting->get_setting_flag_value($this);
$context = new stdClass();
$context->id = $setting->get_id() . '_' . $this->get_shortname();
$context->name = $setting->get_full_name() . '_' . $this->get_shortname();
$context->value = 1;
$context->checked = $value ? true : false;
$context->label = $this->get_displayname();
return $OUTPUT->render_from_template('core_admin/setting_flag', $context);
}
|
php
|
public function output_setting_flag(admin_setting $setting) {
global $OUTPUT;
$value = $setting->get_setting_flag_value($this);
$context = new stdClass();
$context->id = $setting->get_id() . '_' . $this->get_shortname();
$context->name = $setting->get_full_name() . '_' . $this->get_shortname();
$context->value = 1;
$context->checked = $value ? true : false;
$context->label = $this->get_displayname();
return $OUTPUT->render_from_template('core_admin/setting_flag', $context);
}
|
[
"public",
"function",
"output_setting_flag",
"(",
"admin_setting",
"$",
"setting",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"$",
"value",
"=",
"$",
"setting",
"->",
"get_setting_flag_value",
"(",
"$",
"this",
")",
";",
"$",
"context",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"context",
"->",
"id",
"=",
"$",
"setting",
"->",
"get_id",
"(",
")",
".",
"'_'",
".",
"$",
"this",
"->",
"get_shortname",
"(",
")",
";",
"$",
"context",
"->",
"name",
"=",
"$",
"setting",
"->",
"get_full_name",
"(",
")",
".",
"'_'",
".",
"$",
"this",
"->",
"get_shortname",
"(",
")",
";",
"$",
"context",
"->",
"value",
"=",
"1",
";",
"$",
"context",
"->",
"checked",
"=",
"$",
"value",
"?",
"true",
":",
"false",
";",
"$",
"context",
"->",
"label",
"=",
"$",
"this",
"->",
"get_displayname",
"(",
")",
";",
"return",
"$",
"OUTPUT",
"->",
"render_from_template",
"(",
"'core_admin/setting_flag'",
",",
"$",
"context",
")",
";",
"}"
] |
Output the checkbox for this setting flag. Should only be called if the flag is enabled.
@param admin_setting $setting - The admin setting for this flag
@return string - The html for the checkbox.
|
[
"Output",
"the",
"checkbox",
"for",
"this",
"setting",
"flag",
".",
"Should",
"only",
"be",
"called",
"if",
"the",
"flag",
"is",
"enabled",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L2177-L2190
|
215,757
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_configtext.get_force_ltr
|
public function get_force_ltr() {
$forceltr = parent::get_force_ltr();
if ($forceltr === null) {
return !is_rtl_compatible($this->paramtype);
}
return $forceltr;
}
|
php
|
public function get_force_ltr() {
$forceltr = parent::get_force_ltr();
if ($forceltr === null) {
return !is_rtl_compatible($this->paramtype);
}
return $forceltr;
}
|
[
"public",
"function",
"get_force_ltr",
"(",
")",
"{",
"$",
"forceltr",
"=",
"parent",
"::",
"get_force_ltr",
"(",
")",
";",
"if",
"(",
"$",
"forceltr",
"===",
"null",
")",
"{",
"return",
"!",
"is_rtl_compatible",
"(",
"$",
"this",
"->",
"paramtype",
")",
";",
"}",
"return",
"$",
"forceltr",
";",
"}"
] |
Get whether this should be displayed in LTR mode.
Try to guess from the PARAM type unless specifically set.
|
[
"Get",
"whether",
"this",
"should",
"be",
"displayed",
"in",
"LTR",
"mode",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L2360-L2366
|
215,758
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_configtext.output_html
|
public function output_html($data, $query='') {
global $OUTPUT;
$default = $this->get_defaultsetting();
$context = (object) [
'size' => $this->size,
'id' => $this->get_id(),
'name' => $this->get_full_name(),
'value' => $data,
'forceltr' => $this->get_force_ltr(),
];
$element = $OUTPUT->render_from_template('core_admin/setting_configtext', $context);
return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', $default, $query);
}
|
php
|
public function output_html($data, $query='') {
global $OUTPUT;
$default = $this->get_defaultsetting();
$context = (object) [
'size' => $this->size,
'id' => $this->get_id(),
'name' => $this->get_full_name(),
'value' => $data,
'forceltr' => $this->get_force_ltr(),
];
$element = $OUTPUT->render_from_template('core_admin/setting_configtext', $context);
return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', $default, $query);
}
|
[
"public",
"function",
"output_html",
"(",
"$",
"data",
",",
"$",
"query",
"=",
"''",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"$",
"default",
"=",
"$",
"this",
"->",
"get_defaultsetting",
"(",
")",
";",
"$",
"context",
"=",
"(",
"object",
")",
"[",
"'size'",
"=>",
"$",
"this",
"->",
"size",
",",
"'id'",
"=>",
"$",
"this",
"->",
"get_id",
"(",
")",
",",
"'name'",
"=>",
"$",
"this",
"->",
"get_full_name",
"(",
")",
",",
"'value'",
"=>",
"$",
"data",
",",
"'forceltr'",
"=>",
"$",
"this",
"->",
"get_force_ltr",
"(",
")",
",",
"]",
";",
"$",
"element",
"=",
"$",
"OUTPUT",
"->",
"render_from_template",
"(",
"'core_admin/setting_configtext'",
",",
"$",
"context",
")",
";",
"return",
"format_admin_setting",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"visiblename",
",",
"$",
"element",
",",
"$",
"this",
"->",
"description",
",",
"true",
",",
"''",
",",
"$",
"default",
",",
"$",
"query",
")",
";",
"}"
] |
Return an XHTML string for the setting
@return string Returns an XHTML string
|
[
"Return",
"an",
"XHTML",
"string",
"for",
"the",
"setting"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L2421-L2435
|
215,759
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_configempty.output_html
|
public function output_html($data, $query='') {
global $OUTPUT;
$context = (object) [
'id' => $this->get_id(),
'name' => $this->get_full_name()
];
$element = $OUTPUT->render_from_template('core_admin/setting_configempty', $context);
return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', get_string('none'), $query);
}
|
php
|
public function output_html($data, $query='') {
global $OUTPUT;
$context = (object) [
'id' => $this->get_id(),
'name' => $this->get_full_name()
];
$element = $OUTPUT->render_from_template('core_admin/setting_configempty', $context);
return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', get_string('none'), $query);
}
|
[
"public",
"function",
"output_html",
"(",
"$",
"data",
",",
"$",
"query",
"=",
"''",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"$",
"context",
"=",
"(",
"object",
")",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"get_id",
"(",
")",
",",
"'name'",
"=>",
"$",
"this",
"->",
"get_full_name",
"(",
")",
"]",
";",
"$",
"element",
"=",
"$",
"OUTPUT",
"->",
"render_from_template",
"(",
"'core_admin/setting_configempty'",
",",
"$",
"context",
")",
";",
"return",
"format_admin_setting",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"visiblename",
",",
"$",
"element",
",",
"$",
"this",
"->",
"description",
",",
"true",
",",
"''",
",",
"get_string",
"(",
"'none'",
")",
",",
"$",
"query",
")",
";",
"}"
] |
Returns an XHTML string for the hidden field
@param string $data
@param string $query
@return string XHTML string for the editor
|
[
"Returns",
"an",
"XHTML",
"string",
"for",
"the",
"hidden",
"field"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L2681-L2691
|
215,760
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_configfile.write_setting
|
public function write_setting($data) {
global $CFG;
if (!empty($CFG->preventexecpath)) {
if ($this->get_setting() === null) {
// Use default during installation.
$data = $this->get_defaultsetting();
if ($data === null) {
$data = '';
}
} else {
return '';
}
}
return parent::write_setting($data);
}
|
php
|
public function write_setting($data) {
global $CFG;
if (!empty($CFG->preventexecpath)) {
if ($this->get_setting() === null) {
// Use default during installation.
$data = $this->get_defaultsetting();
if ($data === null) {
$data = '';
}
} else {
return '';
}
}
return parent::write_setting($data);
}
|
[
"public",
"function",
"write_setting",
"(",
"$",
"data",
")",
"{",
"global",
"$",
"CFG",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"CFG",
"->",
"preventexecpath",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"get_setting",
"(",
")",
"===",
"null",
")",
"{",
"// Use default during installation.",
"$",
"data",
"=",
"$",
"this",
"->",
"get_defaultsetting",
"(",
")",
";",
"if",
"(",
"$",
"data",
"===",
"null",
")",
"{",
"$",
"data",
"=",
"''",
";",
"}",
"}",
"else",
"{",
"return",
"''",
";",
"}",
"}",
"return",
"parent",
"::",
"write_setting",
"(",
"$",
"data",
")",
";",
"}"
] |
Checks if execpatch has been disabled in config.php
|
[
"Checks",
"if",
"execpatch",
"has",
"been",
"disabled",
"in",
"config",
".",
"php"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L2749-L2763
|
215,761
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_configexecutable.output_html
|
public function output_html($data, $query='') {
global $CFG, $OUTPUT;
$default = $this->get_defaultsetting();
require_once("$CFG->libdir/filelib.php");
$context = (object) [
'id' => $this->get_id(),
'name' => $this->get_full_name(),
'size' => $this->size,
'value' => $data,
'showvalidity' => !empty($data),
'valid' => $data && file_exists($data) && !is_dir($data) && file_is_executable($data),
'readonly' => !empty($CFG->preventexecpath),
'forceltr' => $this->get_force_ltr()
];
if (!empty($CFG->preventexecpath)) {
$this->visiblename .= '<div class="form-overridden">'.get_string('execpathnotallowed', 'admin').'</div>';
}
$element = $OUTPUT->render_from_template('core_admin/setting_configexecutable', $context);
return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', $default, $query);
}
|
php
|
public function output_html($data, $query='') {
global $CFG, $OUTPUT;
$default = $this->get_defaultsetting();
require_once("$CFG->libdir/filelib.php");
$context = (object) [
'id' => $this->get_id(),
'name' => $this->get_full_name(),
'size' => $this->size,
'value' => $data,
'showvalidity' => !empty($data),
'valid' => $data && file_exists($data) && !is_dir($data) && file_is_executable($data),
'readonly' => !empty($CFG->preventexecpath),
'forceltr' => $this->get_force_ltr()
];
if (!empty($CFG->preventexecpath)) {
$this->visiblename .= '<div class="form-overridden">'.get_string('execpathnotallowed', 'admin').'</div>';
}
$element = $OUTPUT->render_from_template('core_admin/setting_configexecutable', $context);
return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', $default, $query);
}
|
[
"public",
"function",
"output_html",
"(",
"$",
"data",
",",
"$",
"query",
"=",
"''",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"OUTPUT",
";",
"$",
"default",
"=",
"$",
"this",
"->",
"get_defaultsetting",
"(",
")",
";",
"require_once",
"(",
"\"$CFG->libdir/filelib.php\"",
")",
";",
"$",
"context",
"=",
"(",
"object",
")",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"get_id",
"(",
")",
",",
"'name'",
"=>",
"$",
"this",
"->",
"get_full_name",
"(",
")",
",",
"'size'",
"=>",
"$",
"this",
"->",
"size",
",",
"'value'",
"=>",
"$",
"data",
",",
"'showvalidity'",
"=>",
"!",
"empty",
"(",
"$",
"data",
")",
",",
"'valid'",
"=>",
"$",
"data",
"&&",
"file_exists",
"(",
"$",
"data",
")",
"&&",
"!",
"is_dir",
"(",
"$",
"data",
")",
"&&",
"file_is_executable",
"(",
"$",
"data",
")",
",",
"'readonly'",
"=>",
"!",
"empty",
"(",
"$",
"CFG",
"->",
"preventexecpath",
")",
",",
"'forceltr'",
"=>",
"$",
"this",
"->",
"get_force_ltr",
"(",
")",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"CFG",
"->",
"preventexecpath",
")",
")",
"{",
"$",
"this",
"->",
"visiblename",
".=",
"'<div class=\"form-overridden\">'",
".",
"get_string",
"(",
"'execpathnotallowed'",
",",
"'admin'",
")",
".",
"'</div>'",
";",
"}",
"$",
"element",
"=",
"$",
"OUTPUT",
"->",
"render_from_template",
"(",
"'core_admin/setting_configexecutable'",
",",
"$",
"context",
")",
";",
"return",
"format_admin_setting",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"visiblename",
",",
"$",
"element",
",",
"$",
"this",
"->",
"description",
",",
"true",
",",
"''",
",",
"$",
"default",
",",
"$",
"query",
")",
";",
"}"
] |
Returns an XHTML field
@param string $data This is the value for the field
@param string $query
@return string XHTML field
|
[
"Returns",
"an",
"XHTML",
"field"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L2782-L2805
|
215,762
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_configcheckbox.write_setting
|
public function write_setting($data) {
if ((string)$data === $this->yes) { // convert to strings before comparison
$data = $this->yes;
} else {
$data = $this->no;
}
return ($this->config_write($this->name, $data) ? '' : get_string('errorsetting', 'admin'));
}
|
php
|
public function write_setting($data) {
if ((string)$data === $this->yes) { // convert to strings before comparison
$data = $this->yes;
} else {
$data = $this->no;
}
return ($this->config_write($this->name, $data) ? '' : get_string('errorsetting', 'admin'));
}
|
[
"public",
"function",
"write_setting",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"(",
"string",
")",
"$",
"data",
"===",
"$",
"this",
"->",
"yes",
")",
"{",
"// convert to strings before comparison",
"$",
"data",
"=",
"$",
"this",
"->",
"yes",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"no",
";",
"}",
"return",
"(",
"$",
"this",
"->",
"config_write",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"data",
")",
"?",
"''",
":",
"get_string",
"(",
"'errorsetting'",
",",
"'admin'",
")",
")",
";",
"}"
] |
Sets the value for the setting
Sets the value for the setting to either the yes or no values
of the object by comparing $data to yes
@param mixed $data Gets converted to str for comparison against yes value
@return string empty string or error
|
[
"Sets",
"the",
"value",
"for",
"the",
"setting"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L2893-L2900
|
215,763
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_configcheckbox.output_html
|
public function output_html($data, $query='') {
global $OUTPUT;
$context = (object) [
'id' => $this->get_id(),
'name' => $this->get_full_name(),
'no' => $this->no,
'value' => $this->yes,
'checked' => (string) $data === $this->yes,
];
$default = $this->get_defaultsetting();
if (!is_null($default)) {
if ((string)$default === $this->yes) {
$defaultinfo = get_string('checkboxyes', 'admin');
} else {
$defaultinfo = get_string('checkboxno', 'admin');
}
} else {
$defaultinfo = NULL;
}
$element = $OUTPUT->render_from_template('core_admin/setting_configcheckbox', $context);
return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', $defaultinfo, $query);
}
|
php
|
public function output_html($data, $query='') {
global $OUTPUT;
$context = (object) [
'id' => $this->get_id(),
'name' => $this->get_full_name(),
'no' => $this->no,
'value' => $this->yes,
'checked' => (string) $data === $this->yes,
];
$default = $this->get_defaultsetting();
if (!is_null($default)) {
if ((string)$default === $this->yes) {
$defaultinfo = get_string('checkboxyes', 'admin');
} else {
$defaultinfo = get_string('checkboxno', 'admin');
}
} else {
$defaultinfo = NULL;
}
$element = $OUTPUT->render_from_template('core_admin/setting_configcheckbox', $context);
return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', $defaultinfo, $query);
}
|
[
"public",
"function",
"output_html",
"(",
"$",
"data",
",",
"$",
"query",
"=",
"''",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"$",
"context",
"=",
"(",
"object",
")",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"get_id",
"(",
")",
",",
"'name'",
"=>",
"$",
"this",
"->",
"get_full_name",
"(",
")",
",",
"'no'",
"=>",
"$",
"this",
"->",
"no",
",",
"'value'",
"=>",
"$",
"this",
"->",
"yes",
",",
"'checked'",
"=>",
"(",
"string",
")",
"$",
"data",
"===",
"$",
"this",
"->",
"yes",
",",
"]",
";",
"$",
"default",
"=",
"$",
"this",
"->",
"get_defaultsetting",
"(",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"default",
")",
")",
"{",
"if",
"(",
"(",
"string",
")",
"$",
"default",
"===",
"$",
"this",
"->",
"yes",
")",
"{",
"$",
"defaultinfo",
"=",
"get_string",
"(",
"'checkboxyes'",
",",
"'admin'",
")",
";",
"}",
"else",
"{",
"$",
"defaultinfo",
"=",
"get_string",
"(",
"'checkboxno'",
",",
"'admin'",
")",
";",
"}",
"}",
"else",
"{",
"$",
"defaultinfo",
"=",
"NULL",
";",
"}",
"$",
"element",
"=",
"$",
"OUTPUT",
"->",
"render_from_template",
"(",
"'core_admin/setting_configcheckbox'",
",",
"$",
"context",
")",
";",
"return",
"format_admin_setting",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"visiblename",
",",
"$",
"element",
",",
"$",
"this",
"->",
"description",
",",
"true",
",",
"''",
",",
"$",
"defaultinfo",
",",
"$",
"query",
")",
";",
"}"
] |
Returns an XHTML checkbox field
@param string $data If $data matches yes then checkbox is checked
@param string $query
@return string XHTML field
|
[
"Returns",
"an",
"XHTML",
"checkbox",
"field"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L2909-L2934
|
215,764
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_configmulticheckbox2.get_setting
|
public function get_setting() {
$result = $this->config_read($this->name);
if (is_null($result)) {
return NULL;
}
if (!$this->load_choices()) {
return NULL;
}
$result = str_pad($result, count($this->choices), '0');
$result = preg_split('//', $result, -1, PREG_SPLIT_NO_EMPTY);
$setting = array();
foreach ($this->choices as $key=>$unused) {
$value = array_shift($result);
if ($value) {
$setting[$key] = 1;
}
}
return $setting;
}
|
php
|
public function get_setting() {
$result = $this->config_read($this->name);
if (is_null($result)) {
return NULL;
}
if (!$this->load_choices()) {
return NULL;
}
$result = str_pad($result, count($this->choices), '0');
$result = preg_split('//', $result, -1, PREG_SPLIT_NO_EMPTY);
$setting = array();
foreach ($this->choices as $key=>$unused) {
$value = array_shift($result);
if ($value) {
$setting[$key] = 1;
}
}
return $setting;
}
|
[
"public",
"function",
"get_setting",
"(",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"config_read",
"(",
"$",
"this",
"->",
"name",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"result",
")",
")",
"{",
"return",
"NULL",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"load_choices",
"(",
")",
")",
"{",
"return",
"NULL",
";",
"}",
"$",
"result",
"=",
"str_pad",
"(",
"$",
"result",
",",
"count",
"(",
"$",
"this",
"->",
"choices",
")",
",",
"'0'",
")",
";",
"$",
"result",
"=",
"preg_split",
"(",
"'//'",
",",
"$",
"result",
",",
"-",
"1",
",",
"PREG_SPLIT_NO_EMPTY",
")",
";",
"$",
"setting",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"choices",
"as",
"$",
"key",
"=>",
"$",
"unused",
")",
"{",
"$",
"value",
"=",
"array_shift",
"(",
"$",
"result",
")",
";",
"if",
"(",
"$",
"value",
")",
"{",
"$",
"setting",
"[",
"$",
"key",
"]",
"=",
"1",
";",
"}",
"}",
"return",
"$",
"setting",
";",
"}"
] |
Returns the setting if set
@return mixed null if not set, else an array of set settings
|
[
"Returns",
"the",
"setting",
"if",
"set"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L3122-L3140
|
215,765
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_configmultiselect.output_html
|
public function output_html($data, $query='') {
global $OUTPUT;
if (!$this->load_choices() or empty($this->choices)) {
return '';
}
$default = $this->get_defaultsetting();
if (is_null($default)) {
$default = array();
}
if (is_null($data)) {
$data = array();
}
$context = (object) [
'id' => $this->get_id(),
'name' => $this->get_full_name(),
'size' => min(10, count($this->choices))
];
$defaults = [];
$options = [];
$template = 'core_admin/setting_configmultiselect';
if (!empty($this->optgroups)) {
$optgroups = [];
foreach ($this->optgroups as $label => $choices) {
$optgroup = array('label' => $label, 'options' => []);
foreach ($choices as $value => $name) {
if (in_array($value, $default)) {
$defaults[] = $name;
}
$optgroup['options'][] = [
'value' => $value,
'name' => $name,
'selected' => in_array($value, $data)
];
unset($this->choices[$value]);
}
$optgroups[] = $optgroup;
}
$context->optgroups = $optgroups;
$template = 'core_admin/setting_configmultiselect_optgroup';
}
foreach ($this->choices as $value => $name) {
if (in_array($value, $default)) {
$defaults[] = $name;
}
$options[] = [
'value' => $value,
'name' => $name,
'selected' => in_array($value, $data)
];
}
$context->options = $options;
if (is_null($default)) {
$defaultinfo = NULL;
} if (!empty($defaults)) {
$defaultinfo = implode(', ', $defaults);
} else {
$defaultinfo = get_string('none');
}
$element = $OUTPUT->render_from_template($template, $context);
return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', $defaultinfo, $query);
}
|
php
|
public function output_html($data, $query='') {
global $OUTPUT;
if (!$this->load_choices() or empty($this->choices)) {
return '';
}
$default = $this->get_defaultsetting();
if (is_null($default)) {
$default = array();
}
if (is_null($data)) {
$data = array();
}
$context = (object) [
'id' => $this->get_id(),
'name' => $this->get_full_name(),
'size' => min(10, count($this->choices))
];
$defaults = [];
$options = [];
$template = 'core_admin/setting_configmultiselect';
if (!empty($this->optgroups)) {
$optgroups = [];
foreach ($this->optgroups as $label => $choices) {
$optgroup = array('label' => $label, 'options' => []);
foreach ($choices as $value => $name) {
if (in_array($value, $default)) {
$defaults[] = $name;
}
$optgroup['options'][] = [
'value' => $value,
'name' => $name,
'selected' => in_array($value, $data)
];
unset($this->choices[$value]);
}
$optgroups[] = $optgroup;
}
$context->optgroups = $optgroups;
$template = 'core_admin/setting_configmultiselect_optgroup';
}
foreach ($this->choices as $value => $name) {
if (in_array($value, $default)) {
$defaults[] = $name;
}
$options[] = [
'value' => $value,
'name' => $name,
'selected' => in_array($value, $data)
];
}
$context->options = $options;
if (is_null($default)) {
$defaultinfo = NULL;
} if (!empty($defaults)) {
$defaultinfo = implode(', ', $defaults);
} else {
$defaultinfo = get_string('none');
}
$element = $OUTPUT->render_from_template($template, $context);
return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', $defaultinfo, $query);
}
|
[
"public",
"function",
"output_html",
"(",
"$",
"data",
",",
"$",
"query",
"=",
"''",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"load_choices",
"(",
")",
"or",
"empty",
"(",
"$",
"this",
"->",
"choices",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"default",
"=",
"$",
"this",
"->",
"get_defaultsetting",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"default",
")",
")",
"{",
"$",
"default",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"data",
")",
")",
"{",
"$",
"data",
"=",
"array",
"(",
")",
";",
"}",
"$",
"context",
"=",
"(",
"object",
")",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"get_id",
"(",
")",
",",
"'name'",
"=>",
"$",
"this",
"->",
"get_full_name",
"(",
")",
",",
"'size'",
"=>",
"min",
"(",
"10",
",",
"count",
"(",
"$",
"this",
"->",
"choices",
")",
")",
"]",
";",
"$",
"defaults",
"=",
"[",
"]",
";",
"$",
"options",
"=",
"[",
"]",
";",
"$",
"template",
"=",
"'core_admin/setting_configmultiselect'",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"optgroups",
")",
")",
"{",
"$",
"optgroups",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"optgroups",
"as",
"$",
"label",
"=>",
"$",
"choices",
")",
"{",
"$",
"optgroup",
"=",
"array",
"(",
"'label'",
"=>",
"$",
"label",
",",
"'options'",
"=>",
"[",
"]",
")",
";",
"foreach",
"(",
"$",
"choices",
"as",
"$",
"value",
"=>",
"$",
"name",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"value",
",",
"$",
"default",
")",
")",
"{",
"$",
"defaults",
"[",
"]",
"=",
"$",
"name",
";",
"}",
"$",
"optgroup",
"[",
"'options'",
"]",
"[",
"]",
"=",
"[",
"'value'",
"=>",
"$",
"value",
",",
"'name'",
"=>",
"$",
"name",
",",
"'selected'",
"=>",
"in_array",
"(",
"$",
"value",
",",
"$",
"data",
")",
"]",
";",
"unset",
"(",
"$",
"this",
"->",
"choices",
"[",
"$",
"value",
"]",
")",
";",
"}",
"$",
"optgroups",
"[",
"]",
"=",
"$",
"optgroup",
";",
"}",
"$",
"context",
"->",
"optgroups",
"=",
"$",
"optgroups",
";",
"$",
"template",
"=",
"'core_admin/setting_configmultiselect_optgroup'",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"choices",
"as",
"$",
"value",
"=>",
"$",
"name",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"value",
",",
"$",
"default",
")",
")",
"{",
"$",
"defaults",
"[",
"]",
"=",
"$",
"name",
";",
"}",
"$",
"options",
"[",
"]",
"=",
"[",
"'value'",
"=>",
"$",
"value",
",",
"'name'",
"=>",
"$",
"name",
",",
"'selected'",
"=>",
"in_array",
"(",
"$",
"value",
",",
"$",
"data",
")",
"]",
";",
"}",
"$",
"context",
"->",
"options",
"=",
"$",
"options",
";",
"if",
"(",
"is_null",
"(",
"$",
"default",
")",
")",
"{",
"$",
"defaultinfo",
"=",
"NULL",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"defaults",
")",
")",
"{",
"$",
"defaultinfo",
"=",
"implode",
"(",
"', '",
",",
"$",
"defaults",
")",
";",
"}",
"else",
"{",
"$",
"defaultinfo",
"=",
"get_string",
"(",
"'none'",
")",
";",
"}",
"$",
"element",
"=",
"$",
"OUTPUT",
"->",
"render_from_template",
"(",
"$",
"template",
",",
"$",
"context",
")",
";",
"return",
"format_admin_setting",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"visiblename",
",",
"$",
"element",
",",
"$",
"this",
"->",
"description",
",",
"true",
",",
"''",
",",
"$",
"defaultinfo",
",",
"$",
"query",
")",
";",
"}"
] |
Returns XHTML multi-select field
@todo Add vartype handling to ensure $data is an array
@param array $data Array of values to select by default
@param string $query
@return string XHTML multi-select field
|
[
"Returns",
"XHTML",
"multi",
"-",
"select",
"field"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L3463-L3532
|
215,766
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_configtime.get_setting
|
public function get_setting() {
$result1 = $this->config_read($this->name);
$result2 = $this->config_read($this->name2);
if (is_null($result1) or is_null($result2)) {
return NULL;
}
return array('h' => $result1, 'm' => $result2);
}
|
php
|
public function get_setting() {
$result1 = $this->config_read($this->name);
$result2 = $this->config_read($this->name2);
if (is_null($result1) or is_null($result2)) {
return NULL;
}
return array('h' => $result1, 'm' => $result2);
}
|
[
"public",
"function",
"get_setting",
"(",
")",
"{",
"$",
"result1",
"=",
"$",
"this",
"->",
"config_read",
"(",
"$",
"this",
"->",
"name",
")",
";",
"$",
"result2",
"=",
"$",
"this",
"->",
"config_read",
"(",
"$",
"this",
"->",
"name2",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"result1",
")",
"or",
"is_null",
"(",
"$",
"result2",
")",
")",
"{",
"return",
"NULL",
";",
"}",
"return",
"array",
"(",
"'h'",
"=>",
"$",
"result1",
",",
"'m'",
"=>",
"$",
"result2",
")",
";",
"}"
] |
Get the selected time
@return mixed An array containing 'h'=>xx, 'm'=>xx, or null if not set
|
[
"Get",
"the",
"selected",
"time"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L3565-L3573
|
215,767
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_configtime.output_html
|
public function output_html($data, $query='') {
global $OUTPUT;
$default = $this->get_defaultsetting();
if (is_array($default)) {
$defaultinfo = $default['h'].':'.$default['m'];
} else {
$defaultinfo = NULL;
}
$context = (object) [
'id' => $this->get_id(),
'name' => $this->get_full_name(),
'hours' => array_map(function($i) use ($data) {
return [
'value' => $i,
'name' => $i,
'selected' => $i == $data['h']
];
}, range(0, 23)),
'minutes' => array_map(function($i) use ($data) {
return [
'value' => $i,
'name' => $i,
'selected' => $i == $data['m']
];
}, range(0, 59, 5))
];
$element = $OUTPUT->render_from_template('core_admin/setting_configtime', $context);
return format_admin_setting($this, $this->visiblename, $element, $this->description,
$this->get_id() . 'h', '', $defaultinfo, $query);
}
|
php
|
public function output_html($data, $query='') {
global $OUTPUT;
$default = $this->get_defaultsetting();
if (is_array($default)) {
$defaultinfo = $default['h'].':'.$default['m'];
} else {
$defaultinfo = NULL;
}
$context = (object) [
'id' => $this->get_id(),
'name' => $this->get_full_name(),
'hours' => array_map(function($i) use ($data) {
return [
'value' => $i,
'name' => $i,
'selected' => $i == $data['h']
];
}, range(0, 23)),
'minutes' => array_map(function($i) use ($data) {
return [
'value' => $i,
'name' => $i,
'selected' => $i == $data['m']
];
}, range(0, 59, 5))
];
$element = $OUTPUT->render_from_template('core_admin/setting_configtime', $context);
return format_admin_setting($this, $this->visiblename, $element, $this->description,
$this->get_id() . 'h', '', $defaultinfo, $query);
}
|
[
"public",
"function",
"output_html",
"(",
"$",
"data",
",",
"$",
"query",
"=",
"''",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"$",
"default",
"=",
"$",
"this",
"->",
"get_defaultsetting",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"default",
")",
")",
"{",
"$",
"defaultinfo",
"=",
"$",
"default",
"[",
"'h'",
"]",
".",
"':'",
".",
"$",
"default",
"[",
"'m'",
"]",
";",
"}",
"else",
"{",
"$",
"defaultinfo",
"=",
"NULL",
";",
"}",
"$",
"context",
"=",
"(",
"object",
")",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"get_id",
"(",
")",
",",
"'name'",
"=>",
"$",
"this",
"->",
"get_full_name",
"(",
")",
",",
"'hours'",
"=>",
"array_map",
"(",
"function",
"(",
"$",
"i",
")",
"use",
"(",
"$",
"data",
")",
"{",
"return",
"[",
"'value'",
"=>",
"$",
"i",
",",
"'name'",
"=>",
"$",
"i",
",",
"'selected'",
"=>",
"$",
"i",
"==",
"$",
"data",
"[",
"'h'",
"]",
"]",
";",
"}",
",",
"range",
"(",
"0",
",",
"23",
")",
")",
",",
"'minutes'",
"=>",
"array_map",
"(",
"function",
"(",
"$",
"i",
")",
"use",
"(",
"$",
"data",
")",
"{",
"return",
"[",
"'value'",
"=>",
"$",
"i",
",",
"'name'",
"=>",
"$",
"i",
",",
"'selected'",
"=>",
"$",
"i",
"==",
"$",
"data",
"[",
"'m'",
"]",
"]",
";",
"}",
",",
"range",
"(",
"0",
",",
"59",
",",
"5",
")",
")",
"]",
";",
"$",
"element",
"=",
"$",
"OUTPUT",
"->",
"render_from_template",
"(",
"'core_admin/setting_configtime'",
",",
"$",
"context",
")",
";",
"return",
"format_admin_setting",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"visiblename",
",",
"$",
"element",
",",
"$",
"this",
"->",
"description",
",",
"$",
"this",
"->",
"get_id",
"(",
")",
".",
"'h'",
",",
"''",
",",
"$",
"defaultinfo",
",",
"$",
"query",
")",
";",
"}"
] |
Returns XHTML time select fields
@param array $data Must be form 'h'=>xx, 'm'=>xx
@param string $query
@return string XHTML time select fields and wrapping div(s)
|
[
"Returns",
"XHTML",
"time",
"select",
"fields"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L3597-L3630
|
215,768
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_configduration.get_duration_text
|
protected static function get_duration_text($seconds) {
if (empty($seconds)) {
return get_string('none');
}
$data = self::parse_seconds($seconds);
switch ($data['u']) {
case (60*60*24*7):
return get_string('numweeks', '', $data['v']);
case (60*60*24):
return get_string('numdays', '', $data['v']);
case (60*60):
return get_string('numhours', '', $data['v']);
case (60):
return get_string('numminutes', '', $data['v']);
default:
return get_string('numseconds', '', $data['v']*$data['u']);
}
}
|
php
|
protected static function get_duration_text($seconds) {
if (empty($seconds)) {
return get_string('none');
}
$data = self::parse_seconds($seconds);
switch ($data['u']) {
case (60*60*24*7):
return get_string('numweeks', '', $data['v']);
case (60*60*24):
return get_string('numdays', '', $data['v']);
case (60*60):
return get_string('numhours', '', $data['v']);
case (60):
return get_string('numminutes', '', $data['v']);
default:
return get_string('numseconds', '', $data['v']*$data['u']);
}
}
|
[
"protected",
"static",
"function",
"get_duration_text",
"(",
"$",
"seconds",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"seconds",
")",
")",
"{",
"return",
"get_string",
"(",
"'none'",
")",
";",
"}",
"$",
"data",
"=",
"self",
"::",
"parse_seconds",
"(",
"$",
"seconds",
")",
";",
"switch",
"(",
"$",
"data",
"[",
"'u'",
"]",
")",
"{",
"case",
"(",
"60",
"*",
"60",
"*",
"24",
"*",
"7",
")",
":",
"return",
"get_string",
"(",
"'numweeks'",
",",
"''",
",",
"$",
"data",
"[",
"'v'",
"]",
")",
";",
"case",
"(",
"60",
"*",
"60",
"*",
"24",
")",
":",
"return",
"get_string",
"(",
"'numdays'",
",",
"''",
",",
"$",
"data",
"[",
"'v'",
"]",
")",
";",
"case",
"(",
"60",
"*",
"60",
")",
":",
"return",
"get_string",
"(",
"'numhours'",
",",
"''",
",",
"$",
"data",
"[",
"'v'",
"]",
")",
";",
"case",
"(",
"60",
")",
":",
"return",
"get_string",
"(",
"'numminutes'",
",",
"''",
",",
"$",
"data",
"[",
"'v'",
"]",
")",
";",
"default",
":",
"return",
"get_string",
"(",
"'numseconds'",
",",
"''",
",",
"$",
"data",
"[",
"'v'",
"]",
"*",
"$",
"data",
"[",
"'u'",
"]",
")",
";",
"}",
"}"
] |
Converts seconds to some more user friendly string.
@static
@param int $seconds
@return string
|
[
"Converts",
"seconds",
"to",
"some",
"more",
"user",
"friendly",
"string",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L3689-L3706
|
215,769
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_configduration.parse_seconds
|
protected static function parse_seconds($seconds) {
foreach (self::get_units() as $unit => $unused) {
if ($seconds % $unit === 0) {
return array('v'=>(int)($seconds/$unit), 'u'=>$unit);
}
}
return array('v'=>(int)$seconds, 'u'=>1);
}
|
php
|
protected static function parse_seconds($seconds) {
foreach (self::get_units() as $unit => $unused) {
if ($seconds % $unit === 0) {
return array('v'=>(int)($seconds/$unit), 'u'=>$unit);
}
}
return array('v'=>(int)$seconds, 'u'=>1);
}
|
[
"protected",
"static",
"function",
"parse_seconds",
"(",
"$",
"seconds",
")",
"{",
"foreach",
"(",
"self",
"::",
"get_units",
"(",
")",
"as",
"$",
"unit",
"=>",
"$",
"unused",
")",
"{",
"if",
"(",
"$",
"seconds",
"%",
"$",
"unit",
"===",
"0",
")",
"{",
"return",
"array",
"(",
"'v'",
"=>",
"(",
"int",
")",
"(",
"$",
"seconds",
"/",
"$",
"unit",
")",
",",
"'u'",
"=>",
"$",
"unit",
")",
";",
"}",
"}",
"return",
"array",
"(",
"'v'",
"=>",
"(",
"int",
")",
"$",
"seconds",
",",
"'u'",
"=>",
"1",
")",
";",
"}"
] |
Finds suitable units for given duration.
@static
@param int $seconds
@return array
|
[
"Finds",
"suitable",
"units",
"for",
"given",
"duration",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L3714-L3721
|
215,770
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_configduration.get_setting
|
public function get_setting() {
$seconds = $this->config_read($this->name);
if (is_null($seconds)) {
return null;
}
return self::parse_seconds($seconds);
}
|
php
|
public function get_setting() {
$seconds = $this->config_read($this->name);
if (is_null($seconds)) {
return null;
}
return self::parse_seconds($seconds);
}
|
[
"public",
"function",
"get_setting",
"(",
")",
"{",
"$",
"seconds",
"=",
"$",
"this",
"->",
"config_read",
"(",
"$",
"this",
"->",
"name",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"seconds",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"self",
"::",
"parse_seconds",
"(",
"$",
"seconds",
")",
";",
"}"
] |
Get the selected duration as array.
@return mixed An array containing 'v'=>xx, 'u'=>xx, or null if not set
|
[
"Get",
"the",
"selected",
"duration",
"as",
"array",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L3728-L3735
|
215,771
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_configduration.write_setting
|
public function write_setting($data) {
if (!is_array($data)) {
return '';
}
$seconds = (int)($data['v']*$data['u']);
if ($seconds < 0) {
return get_string('errorsetting', 'admin');
}
$result = $this->config_write($this->name, $seconds);
return ($result ? '' : get_string('errorsetting', 'admin'));
}
|
php
|
public function write_setting($data) {
if (!is_array($data)) {
return '';
}
$seconds = (int)($data['v']*$data['u']);
if ($seconds < 0) {
return get_string('errorsetting', 'admin');
}
$result = $this->config_write($this->name, $seconds);
return ($result ? '' : get_string('errorsetting', 'admin'));
}
|
[
"public",
"function",
"write_setting",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"seconds",
"=",
"(",
"int",
")",
"(",
"$",
"data",
"[",
"'v'",
"]",
"*",
"$",
"data",
"[",
"'u'",
"]",
")",
";",
"if",
"(",
"$",
"seconds",
"<",
"0",
")",
"{",
"return",
"get_string",
"(",
"'errorsetting'",
",",
"'admin'",
")",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"config_write",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"seconds",
")",
";",
"return",
"(",
"$",
"result",
"?",
"''",
":",
"get_string",
"(",
"'errorsetting'",
",",
"'admin'",
")",
")",
";",
"}"
] |
Store the duration as seconds.
@param array $data Must be form 'h'=>xx, 'm'=>xx
@return bool true if success, false if not
|
[
"Store",
"the",
"duration",
"as",
"seconds",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L3743-L3755
|
215,772
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_configduration.output_html
|
public function output_html($data, $query='') {
global $OUTPUT;
$default = $this->get_defaultsetting();
if (is_number($default)) {
$defaultinfo = self::get_duration_text($default);
} else if (is_array($default)) {
$defaultinfo = self::get_duration_text($default['v']*$default['u']);
} else {
$defaultinfo = null;
}
$inputid = $this->get_id() . 'v';
$units = self::get_units();
$defaultunit = $this->defaultunit;
$context = (object) [
'id' => $this->get_id(),
'name' => $this->get_full_name(),
'value' => $data['v'],
'options' => array_map(function($unit) use ($units, $data, $defaultunit) {
return [
'value' => $unit,
'name' => $units[$unit],
'selected' => ($data['v'] == 0 && $unit == $defaultunit) || $unit == $data['u']
];
}, array_keys($units))
];
$element = $OUTPUT->render_from_template('core_admin/setting_configduration', $context);
return format_admin_setting($this, $this->visiblename, $element, $this->description, $inputid, '', $defaultinfo, $query);
}
|
php
|
public function output_html($data, $query='') {
global $OUTPUT;
$default = $this->get_defaultsetting();
if (is_number($default)) {
$defaultinfo = self::get_duration_text($default);
} else if (is_array($default)) {
$defaultinfo = self::get_duration_text($default['v']*$default['u']);
} else {
$defaultinfo = null;
}
$inputid = $this->get_id() . 'v';
$units = self::get_units();
$defaultunit = $this->defaultunit;
$context = (object) [
'id' => $this->get_id(),
'name' => $this->get_full_name(),
'value' => $data['v'],
'options' => array_map(function($unit) use ($units, $data, $defaultunit) {
return [
'value' => $unit,
'name' => $units[$unit],
'selected' => ($data['v'] == 0 && $unit == $defaultunit) || $unit == $data['u']
];
}, array_keys($units))
];
$element = $OUTPUT->render_from_template('core_admin/setting_configduration', $context);
return format_admin_setting($this, $this->visiblename, $element, $this->description, $inputid, '', $defaultinfo, $query);
}
|
[
"public",
"function",
"output_html",
"(",
"$",
"data",
",",
"$",
"query",
"=",
"''",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"$",
"default",
"=",
"$",
"this",
"->",
"get_defaultsetting",
"(",
")",
";",
"if",
"(",
"is_number",
"(",
"$",
"default",
")",
")",
"{",
"$",
"defaultinfo",
"=",
"self",
"::",
"get_duration_text",
"(",
"$",
"default",
")",
";",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"default",
")",
")",
"{",
"$",
"defaultinfo",
"=",
"self",
"::",
"get_duration_text",
"(",
"$",
"default",
"[",
"'v'",
"]",
"*",
"$",
"default",
"[",
"'u'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"defaultinfo",
"=",
"null",
";",
"}",
"$",
"inputid",
"=",
"$",
"this",
"->",
"get_id",
"(",
")",
".",
"'v'",
";",
"$",
"units",
"=",
"self",
"::",
"get_units",
"(",
")",
";",
"$",
"defaultunit",
"=",
"$",
"this",
"->",
"defaultunit",
";",
"$",
"context",
"=",
"(",
"object",
")",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"get_id",
"(",
")",
",",
"'name'",
"=>",
"$",
"this",
"->",
"get_full_name",
"(",
")",
",",
"'value'",
"=>",
"$",
"data",
"[",
"'v'",
"]",
",",
"'options'",
"=>",
"array_map",
"(",
"function",
"(",
"$",
"unit",
")",
"use",
"(",
"$",
"units",
",",
"$",
"data",
",",
"$",
"defaultunit",
")",
"{",
"return",
"[",
"'value'",
"=>",
"$",
"unit",
",",
"'name'",
"=>",
"$",
"units",
"[",
"$",
"unit",
"]",
",",
"'selected'",
"=>",
"(",
"$",
"data",
"[",
"'v'",
"]",
"==",
"0",
"&&",
"$",
"unit",
"==",
"$",
"defaultunit",
")",
"||",
"$",
"unit",
"==",
"$",
"data",
"[",
"'u'",
"]",
"]",
";",
"}",
",",
"array_keys",
"(",
"$",
"units",
")",
")",
"]",
";",
"$",
"element",
"=",
"$",
"OUTPUT",
"->",
"render_from_template",
"(",
"'core_admin/setting_configduration'",
",",
"$",
"context",
")",
";",
"return",
"format_admin_setting",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"visiblename",
",",
"$",
"element",
",",
"$",
"this",
"->",
"description",
",",
"$",
"inputid",
",",
"''",
",",
"$",
"defaultinfo",
",",
"$",
"query",
")",
";",
"}"
] |
Returns duration text+select fields.
@param array $data Must be form 'v'=>xx, 'u'=>xx
@param string $query
@return string duration text+select fields and wrapping div(s)
|
[
"Returns",
"duration",
"text",
"+",
"select",
"fields",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L3764-L3796
|
215,773
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_configiplist.validate
|
public function validate($data) {
if(!empty($data)) {
$lines = explode("\n", $data);
} else {
return true;
}
$result = true;
$badips = array();
foreach ($lines as $line) {
$tokens = explode('#', $line);
$ip = trim($tokens[0]);
if (empty($ip)) {
continue;
}
if (preg_match('#^(\d{1,3})(\.\d{1,3}){0,3}$#', $ip, $match) ||
preg_match('#^(\d{1,3})(\.\d{1,3}){0,3}(\/\d{1,2})$#', $ip, $match) ||
preg_match('#^(\d{1,3})(\.\d{1,3}){3}(-\d{1,3})$#', $ip, $match)) {
} else {
$result = false;
$badips[] = $ip;
}
}
if($result) {
return true;
} else {
return get_string('validateiperror', 'admin', join(', ', $badips));
}
}
|
php
|
public function validate($data) {
if(!empty($data)) {
$lines = explode("\n", $data);
} else {
return true;
}
$result = true;
$badips = array();
foreach ($lines as $line) {
$tokens = explode('#', $line);
$ip = trim($tokens[0]);
if (empty($ip)) {
continue;
}
if (preg_match('#^(\d{1,3})(\.\d{1,3}){0,3}$#', $ip, $match) ||
preg_match('#^(\d{1,3})(\.\d{1,3}){0,3}(\/\d{1,2})$#', $ip, $match) ||
preg_match('#^(\d{1,3})(\.\d{1,3}){3}(-\d{1,3})$#', $ip, $match)) {
} else {
$result = false;
$badips[] = $ip;
}
}
if($result) {
return true;
} else {
return get_string('validateiperror', 'admin', join(', ', $badips));
}
}
|
[
"public",
"function",
"validate",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"$",
"lines",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"data",
")",
";",
"}",
"else",
"{",
"return",
"true",
";",
"}",
"$",
"result",
"=",
"true",
";",
"$",
"badips",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"line",
")",
"{",
"$",
"tokens",
"=",
"explode",
"(",
"'#'",
",",
"$",
"line",
")",
";",
"$",
"ip",
"=",
"trim",
"(",
"$",
"tokens",
"[",
"0",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"ip",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'#^(\\d{1,3})(\\.\\d{1,3}){0,3}$#'",
",",
"$",
"ip",
",",
"$",
"match",
")",
"||",
"preg_match",
"(",
"'#^(\\d{1,3})(\\.\\d{1,3}){0,3}(\\/\\d{1,2})$#'",
",",
"$",
"ip",
",",
"$",
"match",
")",
"||",
"preg_match",
"(",
"'#^(\\d{1,3})(\\.\\d{1,3}){3}(-\\d{1,3})$#'",
",",
"$",
"ip",
",",
"$",
"match",
")",
")",
"{",
"}",
"else",
"{",
"$",
"result",
"=",
"false",
";",
"$",
"badips",
"[",
"]",
"=",
"$",
"ip",
";",
"}",
"}",
"if",
"(",
"$",
"result",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"get_string",
"(",
"'validateiperror'",
",",
"'admin'",
",",
"join",
"(",
"', '",
",",
"$",
"badips",
")",
")",
";",
"}",
"}"
] |
Validate the contents of the textarea as IP addresses
Used to validate a new line separated list of IP addresses collected from
a textarea control
@param string $data A list of IP Addresses separated by new lines
@return mixed bool true for success or string:error on failure
|
[
"Validate",
"the",
"contents",
"of",
"the",
"textarea",
"as",
"IP",
"addresses"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L3842-L3869
|
215,774
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_configmixedhostiplist.ace_decode
|
protected function ace_decode($data) {
$entries = explode("\n", $data);
foreach ($entries as $key => $entry) {
$entry = trim($entry);
if (strpos($entry, 'xn--') !== false) {
$entries[$key] = idn_to_utf8($entry, IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46);
}
}
return implode("\n", $entries);
}
|
php
|
protected function ace_decode($data) {
$entries = explode("\n", $data);
foreach ($entries as $key => $entry) {
$entry = trim($entry);
if (strpos($entry, 'xn--') !== false) {
$entries[$key] = idn_to_utf8($entry, IDNA_NONTRANSITIONAL_TO_ASCII, INTL_IDNA_VARIANT_UTS46);
}
}
return implode("\n", $entries);
}
|
[
"protected",
"function",
"ace_decode",
"(",
"$",
"data",
")",
"{",
"$",
"entries",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"data",
")",
";",
"foreach",
"(",
"$",
"entries",
"as",
"$",
"key",
"=>",
"$",
"entry",
")",
"{",
"$",
"entry",
"=",
"trim",
"(",
"$",
"entry",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"entry",
",",
"'xn--'",
")",
"!==",
"false",
")",
"{",
"$",
"entries",
"[",
"$",
"key",
"]",
"=",
"idn_to_utf8",
"(",
"$",
"entry",
",",
"IDNA_NONTRANSITIONAL_TO_ASCII",
",",
"INTL_IDNA_VARIANT_UTS46",
")",
";",
"}",
"}",
"return",
"implode",
"(",
"\"\\n\"",
",",
"$",
"entries",
")",
";",
"}"
] |
Decode any ascii-encoded domain names back to their utf-8 representation for display.
@param string $data the setting data, as found in the database.
@return string $data the setting data, with all ascii-encoded IDNs decoded back to their utf-8 representation.
|
[
"Decode",
"any",
"ascii",
"-",
"encoded",
"domain",
"names",
"back",
"to",
"their",
"utf",
"-",
"8",
"representation",
"for",
"display",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L3951-L3960
|
215,775
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_configmixedhostiplist.get_setting
|
public function get_setting() {
// Here, we need to decode any ascii-encoded IDNs back to their native, utf-8 representation.
$data = $this->config_read($this->name);
if (function_exists('idn_to_utf8') && !is_null($data)) {
$data = $this->ace_decode($data);
}
return $data;
}
|
php
|
public function get_setting() {
// Here, we need to decode any ascii-encoded IDNs back to their native, utf-8 representation.
$data = $this->config_read($this->name);
if (function_exists('idn_to_utf8') && !is_null($data)) {
$data = $this->ace_decode($data);
}
return $data;
}
|
[
"public",
"function",
"get_setting",
"(",
")",
"{",
"// Here, we need to decode any ascii-encoded IDNs back to their native, utf-8 representation.",
"$",
"data",
"=",
"$",
"this",
"->",
"config_read",
"(",
"$",
"this",
"->",
"name",
")",
";",
"if",
"(",
"function_exists",
"(",
"'idn_to_utf8'",
")",
"&&",
"!",
"is_null",
"(",
"$",
"data",
")",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"ace_decode",
"(",
"$",
"data",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] |
Override, providing utf8-decoding for ascii-encoded IDN strings.
@return mixed returns punycode-converted setting string if successful, else null.
|
[
"Override",
"providing",
"utf8",
"-",
"decoding",
"for",
"ascii",
"-",
"encoded",
"IDN",
"strings",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L3967-L3974
|
215,776
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_configportlist.validate
|
public function validate($data) {
if (empty($data)) {
return true;
}
$ports = explode("\n", $data);
$badentries = [];
foreach ($ports as $port) {
$port = trim($port);
if (empty($port)) {
return get_string('validateemptylineerror', 'admin');
}
// Is the string a valid integer number?
if (strval(intval($port)) !== $port || intval($port) <= 0) {
$badentries[] = $port;
}
}
if ($badentries) {
return get_string('validateerrorlist', 'admin', $badentries);
}
return true;
}
|
php
|
public function validate($data) {
if (empty($data)) {
return true;
}
$ports = explode("\n", $data);
$badentries = [];
foreach ($ports as $port) {
$port = trim($port);
if (empty($port)) {
return get_string('validateemptylineerror', 'admin');
}
// Is the string a valid integer number?
if (strval(intval($port)) !== $port || intval($port) <= 0) {
$badentries[] = $port;
}
}
if ($badentries) {
return get_string('validateerrorlist', 'admin', $badentries);
}
return true;
}
|
[
"public",
"function",
"validate",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"ports",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"data",
")",
";",
"$",
"badentries",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"ports",
"as",
"$",
"port",
")",
"{",
"$",
"port",
"=",
"trim",
"(",
"$",
"port",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"port",
")",
")",
"{",
"return",
"get_string",
"(",
"'validateemptylineerror'",
",",
"'admin'",
")",
";",
"}",
"// Is the string a valid integer number?",
"if",
"(",
"strval",
"(",
"intval",
"(",
"$",
"port",
")",
")",
"!==",
"$",
"port",
"||",
"intval",
"(",
"$",
"port",
")",
"<=",
"0",
")",
"{",
"$",
"badentries",
"[",
"]",
"=",
"$",
"port",
";",
"}",
"}",
"if",
"(",
"$",
"badentries",
")",
"{",
"return",
"get_string",
"(",
"'validateerrorlist'",
",",
"'admin'",
",",
"$",
"badentries",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Validate the contents of the textarea as port numbers.
Used to validate a new line separated list of ports collected from a textarea control.
@param string $data A list of ports separated by new lines
@return mixed bool true for success or string:error on failure
|
[
"Validate",
"the",
"contents",
"of",
"the",
"textarea",
"as",
"port",
"numbers",
".",
"Used",
"to",
"validate",
"a",
"new",
"line",
"separated",
"list",
"of",
"ports",
"collected",
"from",
"a",
"textarea",
"control",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L4016-L4037
|
215,777
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_users_with_capability.load_choices
|
function load_choices() {
if (is_array($this->choices)) {
return true;
}
list($sort, $sortparams) = users_order_by_sql('u');
if (!empty($sortparams)) {
throw new coding_exception('users_order_by_sql returned some query parameters. ' .
'This is unexpected, and a problem because there is no way to pass these ' .
'parameters to get_users_by_capability. See MDL-34657.');
}
$userfields = 'u.id, u.username, ' . get_all_user_name_fields(true, 'u');
$users = get_users_by_capability(context_system::instance(), $this->capability, $userfields, $sort);
$this->choices = array(
'$@NONE@$' => get_string('nobody'),
'$@ALL@$' => get_string('everyonewhocan', 'admin', get_capability_string($this->capability)),
);
if ($this->includeadmins) {
$admins = get_admins();
foreach ($admins as $user) {
$this->choices[$user->id] = fullname($user);
}
}
if (is_array($users)) {
foreach ($users as $user) {
$this->choices[$user->id] = fullname($user);
}
}
return true;
}
|
php
|
function load_choices() {
if (is_array($this->choices)) {
return true;
}
list($sort, $sortparams) = users_order_by_sql('u');
if (!empty($sortparams)) {
throw new coding_exception('users_order_by_sql returned some query parameters. ' .
'This is unexpected, and a problem because there is no way to pass these ' .
'parameters to get_users_by_capability. See MDL-34657.');
}
$userfields = 'u.id, u.username, ' . get_all_user_name_fields(true, 'u');
$users = get_users_by_capability(context_system::instance(), $this->capability, $userfields, $sort);
$this->choices = array(
'$@NONE@$' => get_string('nobody'),
'$@ALL@$' => get_string('everyonewhocan', 'admin', get_capability_string($this->capability)),
);
if ($this->includeadmins) {
$admins = get_admins();
foreach ($admins as $user) {
$this->choices[$user->id] = fullname($user);
}
}
if (is_array($users)) {
foreach ($users as $user) {
$this->choices[$user->id] = fullname($user);
}
}
return true;
}
|
[
"function",
"load_choices",
"(",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"choices",
")",
")",
"{",
"return",
"true",
";",
"}",
"list",
"(",
"$",
"sort",
",",
"$",
"sortparams",
")",
"=",
"users_order_by_sql",
"(",
"'u'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"sortparams",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'users_order_by_sql returned some query parameters. '",
".",
"'This is unexpected, and a problem because there is no way to pass these '",
".",
"'parameters to get_users_by_capability. See MDL-34657.'",
")",
";",
"}",
"$",
"userfields",
"=",
"'u.id, u.username, '",
".",
"get_all_user_name_fields",
"(",
"true",
",",
"'u'",
")",
";",
"$",
"users",
"=",
"get_users_by_capability",
"(",
"context_system",
"::",
"instance",
"(",
")",
",",
"$",
"this",
"->",
"capability",
",",
"$",
"userfields",
",",
"$",
"sort",
")",
";",
"$",
"this",
"->",
"choices",
"=",
"array",
"(",
"'$@NONE@$'",
"=>",
"get_string",
"(",
"'nobody'",
")",
",",
"'$@ALL@$'",
"=>",
"get_string",
"(",
"'everyonewhocan'",
",",
"'admin'",
",",
"get_capability_string",
"(",
"$",
"this",
"->",
"capability",
")",
")",
",",
")",
";",
"if",
"(",
"$",
"this",
"->",
"includeadmins",
")",
"{",
"$",
"admins",
"=",
"get_admins",
"(",
")",
";",
"foreach",
"(",
"$",
"admins",
"as",
"$",
"user",
")",
"{",
"$",
"this",
"->",
"choices",
"[",
"$",
"user",
"->",
"id",
"]",
"=",
"fullname",
"(",
"$",
"user",
")",
";",
"}",
"}",
"if",
"(",
"is_array",
"(",
"$",
"users",
")",
")",
"{",
"foreach",
"(",
"$",
"users",
"as",
"$",
"user",
")",
"{",
"$",
"this",
"->",
"choices",
"[",
"$",
"user",
"->",
"id",
"]",
"=",
"fullname",
"(",
"$",
"user",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Load all of the uses who have the capability into choice array
@return bool Always returns true
|
[
"Load",
"all",
"of",
"the",
"uses",
"who",
"have",
"the",
"capability",
"into",
"choice",
"array"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L4081-L4109
|
215,778
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_users_with_capability.get_defaultsetting
|
public function get_defaultsetting() {
$this->load_choices();
$defaultsetting = parent::get_defaultsetting();
if (empty($defaultsetting)) {
return array('$@NONE@$');
} else if (array_key_exists($defaultsetting, $this->choices)) {
return $defaultsetting;
} else {
return '';
}
}
|
php
|
public function get_defaultsetting() {
$this->load_choices();
$defaultsetting = parent::get_defaultsetting();
if (empty($defaultsetting)) {
return array('$@NONE@$');
} else if (array_key_exists($defaultsetting, $this->choices)) {
return $defaultsetting;
} else {
return '';
}
}
|
[
"public",
"function",
"get_defaultsetting",
"(",
")",
"{",
"$",
"this",
"->",
"load_choices",
"(",
")",
";",
"$",
"defaultsetting",
"=",
"parent",
"::",
"get_defaultsetting",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"defaultsetting",
")",
")",
"{",
"return",
"array",
"(",
"'$@NONE@$'",
")",
";",
"}",
"else",
"if",
"(",
"array_key_exists",
"(",
"$",
"defaultsetting",
",",
"$",
"this",
"->",
"choices",
")",
")",
"{",
"return",
"$",
"defaultsetting",
";",
"}",
"else",
"{",
"return",
"''",
";",
"}",
"}"
] |
Returns the default setting for class
@return mixed Array, or string. Empty string if no default
|
[
"Returns",
"the",
"default",
"setting",
"for",
"class"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L4116-L4126
|
215,779
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_users_with_capability.get_setting
|
public function get_setting() {
$result = parent::get_setting();
if ($result === null) {
// this is necessary for settings upgrade
return null;
}
if (empty($result)) {
$result = array('$@NONE@$');
}
return $result;
}
|
php
|
public function get_setting() {
$result = parent::get_setting();
if ($result === null) {
// this is necessary for settings upgrade
return null;
}
if (empty($result)) {
$result = array('$@NONE@$');
}
return $result;
}
|
[
"public",
"function",
"get_setting",
"(",
")",
"{",
"$",
"result",
"=",
"parent",
"::",
"get_setting",
"(",
")",
";",
"if",
"(",
"$",
"result",
"===",
"null",
")",
"{",
"// this is necessary for settings upgrade",
"return",
"null",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"result",
")",
")",
"{",
"$",
"result",
"=",
"array",
"(",
"'$@NONE@$'",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Returns the current setting
@return mixed array or string
|
[
"Returns",
"the",
"current",
"setting"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L4133-L4143
|
215,780
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_courselist_frontpage.load_choices
|
public function load_choices() {
if (is_array($this->choices)) {
return true;
}
$this->choices = array(FRONTPAGENEWS => get_string('frontpagenews'),
FRONTPAGEALLCOURSELIST => get_string('frontpagecourselist'),
FRONTPAGEENROLLEDCOURSELIST => get_string('frontpageenrolledcourselist'),
FRONTPAGECATEGORYNAMES => get_string('frontpagecategorynames'),
FRONTPAGECATEGORYCOMBO => get_string('frontpagecategorycombo'),
FRONTPAGECOURSESEARCH => get_string('frontpagecoursesearch'),
'none' => get_string('none'));
if ($this->name === 'frontpage') {
unset($this->choices[FRONTPAGEENROLLEDCOURSELIST]);
}
return true;
}
|
php
|
public function load_choices() {
if (is_array($this->choices)) {
return true;
}
$this->choices = array(FRONTPAGENEWS => get_string('frontpagenews'),
FRONTPAGEALLCOURSELIST => get_string('frontpagecourselist'),
FRONTPAGEENROLLEDCOURSELIST => get_string('frontpageenrolledcourselist'),
FRONTPAGECATEGORYNAMES => get_string('frontpagecategorynames'),
FRONTPAGECATEGORYCOMBO => get_string('frontpagecategorycombo'),
FRONTPAGECOURSESEARCH => get_string('frontpagecoursesearch'),
'none' => get_string('none'));
if ($this->name === 'frontpage') {
unset($this->choices[FRONTPAGEENROLLEDCOURSELIST]);
}
return true;
}
|
[
"public",
"function",
"load_choices",
"(",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"choices",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"choices",
"=",
"array",
"(",
"FRONTPAGENEWS",
"=>",
"get_string",
"(",
"'frontpagenews'",
")",
",",
"FRONTPAGEALLCOURSELIST",
"=>",
"get_string",
"(",
"'frontpagecourselist'",
")",
",",
"FRONTPAGEENROLLEDCOURSELIST",
"=>",
"get_string",
"(",
"'frontpageenrolledcourselist'",
")",
",",
"FRONTPAGECATEGORYNAMES",
"=>",
"get_string",
"(",
"'frontpagecategorynames'",
")",
",",
"FRONTPAGECATEGORYCOMBO",
"=>",
"get_string",
"(",
"'frontpagecategorycombo'",
")",
",",
"FRONTPAGECOURSESEARCH",
"=>",
"get_string",
"(",
"'frontpagecoursesearch'",
")",
",",
"'none'",
"=>",
"get_string",
"(",
"'none'",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"name",
"===",
"'frontpage'",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"choices",
"[",
"FRONTPAGEENROLLEDCOURSELIST",
"]",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Loads the choices available
@return bool always returns true
|
[
"Loads",
"the",
"choices",
"available"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L4342-L4357
|
215,781
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_courselist_frontpage.write_setting
|
public function write_setting($data) {
if (!is_array($data)) {
return '';
}
$this->load_choices();
$save = array();
foreach($data as $datum) {
if ($datum == 'none' or !array_key_exists($datum, $this->choices)) {
continue;
}
$save[$datum] = $datum; // no duplicates
}
return ($this->config_write($this->name, implode(',', $save)) ? '' : get_string('errorsetting', 'admin'));
}
|
php
|
public function write_setting($data) {
if (!is_array($data)) {
return '';
}
$this->load_choices();
$save = array();
foreach($data as $datum) {
if ($datum == 'none' or !array_key_exists($datum, $this->choices)) {
continue;
}
$save[$datum] = $datum; // no duplicates
}
return ($this->config_write($this->name, implode(',', $save)) ? '' : get_string('errorsetting', 'admin'));
}
|
[
"public",
"function",
"write_setting",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"this",
"->",
"load_choices",
"(",
")",
";",
"$",
"save",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"datum",
")",
"{",
"if",
"(",
"$",
"datum",
"==",
"'none'",
"or",
"!",
"array_key_exists",
"(",
"$",
"datum",
",",
"$",
"this",
"->",
"choices",
")",
")",
"{",
"continue",
";",
"}",
"$",
"save",
"[",
"$",
"datum",
"]",
"=",
"$",
"datum",
";",
"// no duplicates",
"}",
"return",
"(",
"$",
"this",
"->",
"config_write",
"(",
"$",
"this",
"->",
"name",
",",
"implode",
"(",
"','",
",",
"$",
"save",
")",
")",
"?",
"''",
":",
"get_string",
"(",
"'errorsetting'",
",",
"'admin'",
")",
")",
";",
"}"
] |
Save the selected options
@param array $data
@return mixed empty string (data is not an array) or bool true=success false=failure
|
[
"Save",
"the",
"selected",
"options"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L4381-L4394
|
215,782
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_courselist_frontpage.output_html
|
public function output_html($data, $query='') {
global $OUTPUT;
$this->load_choices();
$currentsetting = array();
foreach ($data as $key) {
if ($key != 'none' and array_key_exists($key, $this->choices)) {
$currentsetting[] = $key; // already selected first
}
}
$context = (object) [
'id' => $this->get_id(),
'name' => $this->get_full_name(),
];
$options = $this->choices;
$selects = [];
for ($i = 0; $i < count($this->choices) - 1; $i++) {
if (!array_key_exists($i, $currentsetting)) {
$currentsetting[$i] = 'none';
}
$selects[] = [
'key' => $i,
'options' => array_map(function($option) use ($options, $currentsetting, $i) {
return [
'name' => $options[$option],
'value' => $option,
'selected' => $currentsetting[$i] == $option
];
}, array_keys($options))
];
}
$context->selects = $selects;
$element = $OUTPUT->render_from_template('core_admin/setting_courselist_frontpage', $context);
return format_admin_setting($this, $this->visiblename, $element, $this->description, false, '', null, $query);
}
|
php
|
public function output_html($data, $query='') {
global $OUTPUT;
$this->load_choices();
$currentsetting = array();
foreach ($data as $key) {
if ($key != 'none' and array_key_exists($key, $this->choices)) {
$currentsetting[] = $key; // already selected first
}
}
$context = (object) [
'id' => $this->get_id(),
'name' => $this->get_full_name(),
];
$options = $this->choices;
$selects = [];
for ($i = 0; $i < count($this->choices) - 1; $i++) {
if (!array_key_exists($i, $currentsetting)) {
$currentsetting[$i] = 'none';
}
$selects[] = [
'key' => $i,
'options' => array_map(function($option) use ($options, $currentsetting, $i) {
return [
'name' => $options[$option],
'value' => $option,
'selected' => $currentsetting[$i] == $option
];
}, array_keys($options))
];
}
$context->selects = $selects;
$element = $OUTPUT->render_from_template('core_admin/setting_courselist_frontpage', $context);
return format_admin_setting($this, $this->visiblename, $element, $this->description, false, '', null, $query);
}
|
[
"public",
"function",
"output_html",
"(",
"$",
"data",
",",
"$",
"query",
"=",
"''",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"$",
"this",
"->",
"load_choices",
"(",
")",
";",
"$",
"currentsetting",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"key",
"!=",
"'none'",
"and",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"choices",
")",
")",
"{",
"$",
"currentsetting",
"[",
"]",
"=",
"$",
"key",
";",
"// already selected first",
"}",
"}",
"$",
"context",
"=",
"(",
"object",
")",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"get_id",
"(",
")",
",",
"'name'",
"=>",
"$",
"this",
"->",
"get_full_name",
"(",
")",
",",
"]",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"choices",
";",
"$",
"selects",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"this",
"->",
"choices",
")",
"-",
"1",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"i",
",",
"$",
"currentsetting",
")",
")",
"{",
"$",
"currentsetting",
"[",
"$",
"i",
"]",
"=",
"'none'",
";",
"}",
"$",
"selects",
"[",
"]",
"=",
"[",
"'key'",
"=>",
"$",
"i",
",",
"'options'",
"=>",
"array_map",
"(",
"function",
"(",
"$",
"option",
")",
"use",
"(",
"$",
"options",
",",
"$",
"currentsetting",
",",
"$",
"i",
")",
"{",
"return",
"[",
"'name'",
"=>",
"$",
"options",
"[",
"$",
"option",
"]",
",",
"'value'",
"=>",
"$",
"option",
",",
"'selected'",
"=>",
"$",
"currentsetting",
"[",
"$",
"i",
"]",
"==",
"$",
"option",
"]",
";",
"}",
",",
"array_keys",
"(",
"$",
"options",
")",
")",
"]",
";",
"}",
"$",
"context",
"->",
"selects",
"=",
"$",
"selects",
";",
"$",
"element",
"=",
"$",
"OUTPUT",
"->",
"render_from_template",
"(",
"'core_admin/setting_courselist_frontpage'",
",",
"$",
"context",
")",
";",
"return",
"format_admin_setting",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"visiblename",
",",
"$",
"element",
",",
"$",
"this",
"->",
"description",
",",
"false",
",",
"''",
",",
"null",
",",
"$",
"query",
")",
";",
"}"
] |
Return XHTML select field and wrapping div
@todo Add vartype handling to make sure $data is an array
@param array $data Array of elements to select by default
@return string XHTML select field and wrapping div
|
[
"Return",
"XHTML",
"select",
"field",
"and",
"wrapping",
"div"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L4403-L4441
|
215,783
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_sitesettext.get_setting
|
public function get_setting() {
$site = course_get_format(get_site())->get_course();
return $site->{$this->name} != '' ? $site->{$this->name} : NULL;
}
|
php
|
public function get_setting() {
$site = course_get_format(get_site())->get_course();
return $site->{$this->name} != '' ? $site->{$this->name} : NULL;
}
|
[
"public",
"function",
"get_setting",
"(",
")",
"{",
"$",
"site",
"=",
"course_get_format",
"(",
"get_site",
"(",
")",
")",
"->",
"get_course",
"(",
")",
";",
"return",
"$",
"site",
"->",
"{",
"$",
"this",
"->",
"name",
"}",
"!=",
"''",
"?",
"$",
"site",
"->",
"{",
"$",
"this",
"->",
"name",
"}",
":",
"NULL",
";",
"}"
] |
Return the current setting
@return mixed string or null
|
[
"Return",
"the",
"current",
"setting"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L4509-L4512
|
215,784
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_sitesettext.validate
|
public function validate($data) {
global $DB, $SITE;
$cleaned = clean_param($data, PARAM_TEXT);
if ($cleaned === '') {
return get_string('required');
}
if ($this->name ==='shortname' &&
$DB->record_exists_sql('SELECT id from {course} WHERE shortname = ? AND id <> ?', array($data, $SITE->id))) {
return get_string('shortnametaken', 'error', $data);
}
if ("$data" == "$cleaned") { // implicit conversion to string is needed to do exact comparison
return true;
} else {
return get_string('validateerror', 'admin');
}
}
|
php
|
public function validate($data) {
global $DB, $SITE;
$cleaned = clean_param($data, PARAM_TEXT);
if ($cleaned === '') {
return get_string('required');
}
if ($this->name ==='shortname' &&
$DB->record_exists_sql('SELECT id from {course} WHERE shortname = ? AND id <> ?', array($data, $SITE->id))) {
return get_string('shortnametaken', 'error', $data);
}
if ("$data" == "$cleaned") { // implicit conversion to string is needed to do exact comparison
return true;
} else {
return get_string('validateerror', 'admin');
}
}
|
[
"public",
"function",
"validate",
"(",
"$",
"data",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"SITE",
";",
"$",
"cleaned",
"=",
"clean_param",
"(",
"$",
"data",
",",
"PARAM_TEXT",
")",
";",
"if",
"(",
"$",
"cleaned",
"===",
"''",
")",
"{",
"return",
"get_string",
"(",
"'required'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"name",
"===",
"'shortname'",
"&&",
"$",
"DB",
"->",
"record_exists_sql",
"(",
"'SELECT id from {course} WHERE shortname = ? AND id <> ?'",
",",
"array",
"(",
"$",
"data",
",",
"$",
"SITE",
"->",
"id",
")",
")",
")",
"{",
"return",
"get_string",
"(",
"'shortnametaken'",
",",
"'error'",
",",
"$",
"data",
")",
";",
"}",
"if",
"(",
"\"$data\"",
"==",
"\"$cleaned\"",
")",
"{",
"// implicit conversion to string is needed to do exact comparison",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"get_string",
"(",
"'validateerror'",
",",
"'admin'",
")",
";",
"}",
"}"
] |
Validate the selected data
@param string $data The selected value to validate
@return mixed true or message string
|
[
"Validate",
"the",
"selected",
"data"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L4520-L4535
|
215,785
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_emoticons.process_form_data
|
protected function process_form_data(array $form) {
$count = count($form); // number of form field values
if ($count % 5) {
// we must get five fields per emoticon object
return false;
}
$emoticons = array();
for ($i = 0; $i < $count / 5; $i++) {
$emoticon = new stdClass();
$emoticon->text = clean_param(trim($form['text'.$i]), PARAM_NOTAGS);
$emoticon->imagename = clean_param(trim($form['imagename'.$i]), PARAM_PATH);
$emoticon->imagecomponent = clean_param(trim($form['imagecomponent'.$i]), PARAM_COMPONENT);
$emoticon->altidentifier = clean_param(trim($form['altidentifier'.$i]), PARAM_STRINGID);
$emoticon->altcomponent = clean_param(trim($form['altcomponent'.$i]), PARAM_COMPONENT);
if (strpos($emoticon->text, ':/') !== false or strpos($emoticon->text, '//') !== false) {
// prevent from breaking http://url.addresses by accident
$emoticon->text = '';
}
if (strlen($emoticon->text) < 2) {
// do not allow single character emoticons
$emoticon->text = '';
}
if (preg_match('/^[a-zA-Z]+[a-zA-Z0-9]*$/', $emoticon->text)) {
// emoticon text must contain some non-alphanumeric character to prevent
// breaking HTML tags
$emoticon->text = '';
}
if ($emoticon->text !== '' and $emoticon->imagename !== '' and $emoticon->imagecomponent !== '') {
$emoticons[] = $emoticon;
}
}
return $emoticons;
}
|
php
|
protected function process_form_data(array $form) {
$count = count($form); // number of form field values
if ($count % 5) {
// we must get five fields per emoticon object
return false;
}
$emoticons = array();
for ($i = 0; $i < $count / 5; $i++) {
$emoticon = new stdClass();
$emoticon->text = clean_param(trim($form['text'.$i]), PARAM_NOTAGS);
$emoticon->imagename = clean_param(trim($form['imagename'.$i]), PARAM_PATH);
$emoticon->imagecomponent = clean_param(trim($form['imagecomponent'.$i]), PARAM_COMPONENT);
$emoticon->altidentifier = clean_param(trim($form['altidentifier'.$i]), PARAM_STRINGID);
$emoticon->altcomponent = clean_param(trim($form['altcomponent'.$i]), PARAM_COMPONENT);
if (strpos($emoticon->text, ':/') !== false or strpos($emoticon->text, '//') !== false) {
// prevent from breaking http://url.addresses by accident
$emoticon->text = '';
}
if (strlen($emoticon->text) < 2) {
// do not allow single character emoticons
$emoticon->text = '';
}
if (preg_match('/^[a-zA-Z]+[a-zA-Z0-9]*$/', $emoticon->text)) {
// emoticon text must contain some non-alphanumeric character to prevent
// breaking HTML tags
$emoticon->text = '';
}
if ($emoticon->text !== '' and $emoticon->imagename !== '' and $emoticon->imagecomponent !== '') {
$emoticons[] = $emoticon;
}
}
return $emoticons;
}
|
[
"protected",
"function",
"process_form_data",
"(",
"array",
"$",
"form",
")",
"{",
"$",
"count",
"=",
"count",
"(",
"$",
"form",
")",
";",
"// number of form field values",
"if",
"(",
"$",
"count",
"%",
"5",
")",
"{",
"// we must get five fields per emoticon object",
"return",
"false",
";",
"}",
"$",
"emoticons",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"count",
"/",
"5",
";",
"$",
"i",
"++",
")",
"{",
"$",
"emoticon",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"emoticon",
"->",
"text",
"=",
"clean_param",
"(",
"trim",
"(",
"$",
"form",
"[",
"'text'",
".",
"$",
"i",
"]",
")",
",",
"PARAM_NOTAGS",
")",
";",
"$",
"emoticon",
"->",
"imagename",
"=",
"clean_param",
"(",
"trim",
"(",
"$",
"form",
"[",
"'imagename'",
".",
"$",
"i",
"]",
")",
",",
"PARAM_PATH",
")",
";",
"$",
"emoticon",
"->",
"imagecomponent",
"=",
"clean_param",
"(",
"trim",
"(",
"$",
"form",
"[",
"'imagecomponent'",
".",
"$",
"i",
"]",
")",
",",
"PARAM_COMPONENT",
")",
";",
"$",
"emoticon",
"->",
"altidentifier",
"=",
"clean_param",
"(",
"trim",
"(",
"$",
"form",
"[",
"'altidentifier'",
".",
"$",
"i",
"]",
")",
",",
"PARAM_STRINGID",
")",
";",
"$",
"emoticon",
"->",
"altcomponent",
"=",
"clean_param",
"(",
"trim",
"(",
"$",
"form",
"[",
"'altcomponent'",
".",
"$",
"i",
"]",
")",
",",
"PARAM_COMPONENT",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"emoticon",
"->",
"text",
",",
"':/'",
")",
"!==",
"false",
"or",
"strpos",
"(",
"$",
"emoticon",
"->",
"text",
",",
"'//'",
")",
"!==",
"false",
")",
"{",
"// prevent from breaking http://url.addresses by accident",
"$",
"emoticon",
"->",
"text",
"=",
"''",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"emoticon",
"->",
"text",
")",
"<",
"2",
")",
"{",
"// do not allow single character emoticons",
"$",
"emoticon",
"->",
"text",
"=",
"''",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'/^[a-zA-Z]+[a-zA-Z0-9]*$/'",
",",
"$",
"emoticon",
"->",
"text",
")",
")",
"{",
"// emoticon text must contain some non-alphanumeric character to prevent",
"// breaking HTML tags",
"$",
"emoticon",
"->",
"text",
"=",
"''",
";",
"}",
"if",
"(",
"$",
"emoticon",
"->",
"text",
"!==",
"''",
"and",
"$",
"emoticon",
"->",
"imagename",
"!==",
"''",
"and",
"$",
"emoticon",
"->",
"imagecomponent",
"!==",
"''",
")",
"{",
"$",
"emoticons",
"[",
"]",
"=",
"$",
"emoticon",
";",
"}",
"}",
"return",
"$",
"emoticons",
";",
"}"
] |
Converts the data from admin settings form into an array of emoticon objects
@see self::prepare_form_data()
@param array $data array of admin form fields and values
@return false|array of emoticon objects
|
[
"Converts",
"the",
"data",
"from",
"admin",
"settings",
"form",
"into",
"an",
"array",
"of",
"emoticon",
"objects"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L4776-L4815
|
215,786
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_special_calendar_weekend.get_setting
|
public function get_setting() {
$result = $this->config_read($this->name);
if (is_null($result)) {
return NULL;
}
if ($result === '') {
return array();
}
$settings = array();
for ($i=0; $i<7; $i++) {
if ($result & (1 << $i)) {
$settings[] = $i;
}
}
return $settings;
}
|
php
|
public function get_setting() {
$result = $this->config_read($this->name);
if (is_null($result)) {
return NULL;
}
if ($result === '') {
return array();
}
$settings = array();
for ($i=0; $i<7; $i++) {
if ($result & (1 << $i)) {
$settings[] = $i;
}
}
return $settings;
}
|
[
"public",
"function",
"get_setting",
"(",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"config_read",
"(",
"$",
"this",
"->",
"name",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"result",
")",
")",
"{",
"return",
"NULL",
";",
"}",
"if",
"(",
"$",
"result",
"===",
"''",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"settings",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"7",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"result",
"&",
"(",
"1",
"<<",
"$",
"i",
")",
")",
"{",
"$",
"settings",
"[",
"]",
"=",
"$",
"i",
";",
"}",
"}",
"return",
"$",
"settings",
";",
"}"
] |
Gets the current settings as an array
@return mixed Null if none, else array of settings
|
[
"Gets",
"the",
"current",
"settings",
"as",
"an",
"array"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L5057-L5072
|
215,787
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_special_calendar_weekend.write_setting
|
public function write_setting($data) {
if (!is_array($data)) {
return '';
}
unset($data['xxxxx']);
$result = 0;
foreach($data as $index) {
$result |= 1 << $index;
}
return ($this->config_write($this->name, $result) ? '' : get_string('errorsetting', 'admin'));
}
|
php
|
public function write_setting($data) {
if (!is_array($data)) {
return '';
}
unset($data['xxxxx']);
$result = 0;
foreach($data as $index) {
$result |= 1 << $index;
}
return ($this->config_write($this->name, $result) ? '' : get_string('errorsetting', 'admin'));
}
|
[
"public",
"function",
"write_setting",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"return",
"''",
";",
"}",
"unset",
"(",
"$",
"data",
"[",
"'xxxxx'",
"]",
")",
";",
"$",
"result",
"=",
"0",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"index",
")",
"{",
"$",
"result",
"|=",
"1",
"<<",
"$",
"index",
";",
"}",
"return",
"(",
"$",
"this",
"->",
"config_write",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"result",
")",
"?",
"''",
":",
"get_string",
"(",
"'errorsetting'",
",",
"'admin'",
")",
")",
";",
"}"
] |
Save the new settings
@param array $data Array of new settings
@return bool
|
[
"Save",
"the",
"new",
"settings"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L5080-L5090
|
215,788
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_special_calendar_weekend.output_html
|
public function output_html($data, $query='') {
global $OUTPUT;
// The order matters very much because of the implied numeric keys.
$days = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday');
$context = (object) [
'name' => $this->get_full_name(),
'id' => $this->get_id(),
'days' => array_map(function($index) use ($days, $data) {
return [
'index' => $index,
'label' => get_string($days[$index], 'calendar'),
'checked' => in_array($index, $data)
];
}, array_keys($days))
];
$element = $OUTPUT->render_from_template('core_admin/setting_special_calendar_weekend', $context);
return format_admin_setting($this, $this->visiblename, $element, $this->description, false, '', NULL, $query);
}
|
php
|
public function output_html($data, $query='') {
global $OUTPUT;
// The order matters very much because of the implied numeric keys.
$days = array('sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday');
$context = (object) [
'name' => $this->get_full_name(),
'id' => $this->get_id(),
'days' => array_map(function($index) use ($days, $data) {
return [
'index' => $index,
'label' => get_string($days[$index], 'calendar'),
'checked' => in_array($index, $data)
];
}, array_keys($days))
];
$element = $OUTPUT->render_from_template('core_admin/setting_special_calendar_weekend', $context);
return format_admin_setting($this, $this->visiblename, $element, $this->description, false, '', NULL, $query);
}
|
[
"public",
"function",
"output_html",
"(",
"$",
"data",
",",
"$",
"query",
"=",
"''",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"// The order matters very much because of the implied numeric keys.",
"$",
"days",
"=",
"array",
"(",
"'sunday'",
",",
"'monday'",
",",
"'tuesday'",
",",
"'wednesday'",
",",
"'thursday'",
",",
"'friday'",
",",
"'saturday'",
")",
";",
"$",
"context",
"=",
"(",
"object",
")",
"[",
"'name'",
"=>",
"$",
"this",
"->",
"get_full_name",
"(",
")",
",",
"'id'",
"=>",
"$",
"this",
"->",
"get_id",
"(",
")",
",",
"'days'",
"=>",
"array_map",
"(",
"function",
"(",
"$",
"index",
")",
"use",
"(",
"$",
"days",
",",
"$",
"data",
")",
"{",
"return",
"[",
"'index'",
"=>",
"$",
"index",
",",
"'label'",
"=>",
"get_string",
"(",
"$",
"days",
"[",
"$",
"index",
"]",
",",
"'calendar'",
")",
",",
"'checked'",
"=>",
"in_array",
"(",
"$",
"index",
",",
"$",
"data",
")",
"]",
";",
"}",
",",
"array_keys",
"(",
"$",
"days",
")",
")",
"]",
";",
"$",
"element",
"=",
"$",
"OUTPUT",
"->",
"render_from_template",
"(",
"'core_admin/setting_special_calendar_weekend'",
",",
"$",
"context",
")",
";",
"return",
"format_admin_setting",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"visiblename",
",",
"$",
"element",
",",
"$",
"this",
"->",
"description",
",",
"false",
",",
"''",
",",
"NULL",
",",
"$",
"query",
")",
";",
"}"
] |
Return XHTML to display the control
@param array $data array of selected days
@param string $query
@return string XHTML for display (field + wrapping div(s)
|
[
"Return",
"XHTML",
"to",
"display",
"the",
"control"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L5099-L5120
|
215,789
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_pickroles.load_choices
|
public function load_choices() {
global $CFG, $DB;
if (during_initial_install()) {
return false;
}
if (is_array($this->choices)) {
return true;
}
if ($roles = get_all_roles()) {
$this->choices = role_fix_names($roles, null, ROLENAME_ORIGINAL, true);
return true;
} else {
return false;
}
}
|
php
|
public function load_choices() {
global $CFG, $DB;
if (during_initial_install()) {
return false;
}
if (is_array($this->choices)) {
return true;
}
if ($roles = get_all_roles()) {
$this->choices = role_fix_names($roles, null, ROLENAME_ORIGINAL, true);
return true;
} else {
return false;
}
}
|
[
"public",
"function",
"load_choices",
"(",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
";",
"if",
"(",
"during_initial_install",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"choices",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"roles",
"=",
"get_all_roles",
"(",
")",
")",
"{",
"$",
"this",
"->",
"choices",
"=",
"role_fix_names",
"(",
"$",
"roles",
",",
"null",
",",
"ROLENAME_ORIGINAL",
",",
"true",
")",
";",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] |
Load roles as choices
@return bool true=>success, false=>error
|
[
"Load",
"roles",
"as",
"choices"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L5179-L5193
|
215,790
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_pickroles.get_defaultsetting
|
public function get_defaultsetting() {
global $CFG;
if (during_initial_install()) {
return null;
}
$result = array();
foreach($this->types as $archetype) {
if ($caproles = get_archetype_roles($archetype)) {
foreach ($caproles as $caprole) {
$result[$caprole->id] = 1;
}
}
}
return $result;
}
|
php
|
public function get_defaultsetting() {
global $CFG;
if (during_initial_install()) {
return null;
}
$result = array();
foreach($this->types as $archetype) {
if ($caproles = get_archetype_roles($archetype)) {
foreach ($caproles as $caprole) {
$result[$caprole->id] = 1;
}
}
}
return $result;
}
|
[
"public",
"function",
"get_defaultsetting",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"if",
"(",
"during_initial_install",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"types",
"as",
"$",
"archetype",
")",
"{",
"if",
"(",
"$",
"caproles",
"=",
"get_archetype_roles",
"(",
"$",
"archetype",
")",
")",
"{",
"foreach",
"(",
"$",
"caproles",
"as",
"$",
"caprole",
")",
"{",
"$",
"result",
"[",
"$",
"caprole",
"->",
"id",
"]",
"=",
"1",
";",
"}",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] |
Return the default setting for this control
@return array Array of default settings
|
[
"Return",
"the",
"default",
"setting",
"for",
"this",
"control"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L5200-L5215
|
215,791
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_special_gradelimiting.write_setting
|
function write_setting($data) {
$previous = $this->get_setting();
if ($previous === null) {
if ($data) {
$this->regrade_all();
}
} else {
if ($data != $previous) {
$this->regrade_all();
}
}
return ($this->config_write($this->name, $data) ? '' : get_string('errorsetting', 'admin'));
}
|
php
|
function write_setting($data) {
$previous = $this->get_setting();
if ($previous === null) {
if ($data) {
$this->regrade_all();
}
} else {
if ($data != $previous) {
$this->regrade_all();
}
}
return ($this->config_write($this->name, $data) ? '' : get_string('errorsetting', 'admin'));
}
|
[
"function",
"write_setting",
"(",
"$",
"data",
")",
"{",
"$",
"previous",
"=",
"$",
"this",
"->",
"get_setting",
"(",
")",
";",
"if",
"(",
"$",
"previous",
"===",
"null",
")",
"{",
"if",
"(",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"regrade_all",
"(",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"data",
"!=",
"$",
"previous",
")",
"{",
"$",
"this",
"->",
"regrade_all",
"(",
")",
";",
"}",
"}",
"return",
"(",
"$",
"this",
"->",
"config_write",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"data",
")",
"?",
"''",
":",
"get_string",
"(",
"'errorsetting'",
",",
"'admin'",
")",
")",
";",
"}"
] |
Saves the new settings
@param mixed $data
@return string empty string or error message
|
[
"Saves",
"the",
"new",
"settings"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L5478-L5491
|
215,792
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_special_grademinmaxtouse.write_setting
|
function write_setting($data) {
global $CFG;
$previous = $this->get_setting();
$result = parent::write_setting($data);
// If saved and the value has changed.
if (empty($result) && $previous != $data) {
require_once($CFG->libdir . '/gradelib.php');
grade_force_site_regrading();
}
return $result;
}
|
php
|
function write_setting($data) {
global $CFG;
$previous = $this->get_setting();
$result = parent::write_setting($data);
// If saved and the value has changed.
if (empty($result) && $previous != $data) {
require_once($CFG->libdir . '/gradelib.php');
grade_force_site_regrading();
}
return $result;
}
|
[
"function",
"write_setting",
"(",
"$",
"data",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"previous",
"=",
"$",
"this",
"->",
"get_setting",
"(",
")",
";",
"$",
"result",
"=",
"parent",
"::",
"write_setting",
"(",
"$",
"data",
")",
";",
"// If saved and the value has changed.",
"if",
"(",
"empty",
"(",
"$",
"result",
")",
"&&",
"$",
"previous",
"!=",
"$",
"data",
")",
"{",
"require_once",
"(",
"$",
"CFG",
"->",
"libdir",
".",
"'/gradelib.php'",
")",
";",
"grade_force_site_regrading",
"(",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Saves the new setting.
@param mixed $data
@return string empty string or error message
|
[
"Saves",
"the",
"new",
"setting",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L5523-L5536
|
215,793
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_special_gradeexport.load_choices
|
public function load_choices() {
if (is_array($this->choices)) {
return true;
}
$this->choices = array();
if ($plugins = core_component::get_plugin_list('gradeexport')) {
foreach($plugins as $plugin => $unused) {
$this->choices[$plugin] = get_string('pluginname', 'gradeexport_'.$plugin);
}
}
return true;
}
|
php
|
public function load_choices() {
if (is_array($this->choices)) {
return true;
}
$this->choices = array();
if ($plugins = core_component::get_plugin_list('gradeexport')) {
foreach($plugins as $plugin => $unused) {
$this->choices[$plugin] = get_string('pluginname', 'gradeexport_'.$plugin);
}
}
return true;
}
|
[
"public",
"function",
"load_choices",
"(",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"choices",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"choices",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"plugins",
"=",
"core_component",
"::",
"get_plugin_list",
"(",
"'gradeexport'",
")",
")",
"{",
"foreach",
"(",
"$",
"plugins",
"as",
"$",
"plugin",
"=>",
"$",
"unused",
")",
"{",
"$",
"this",
"->",
"choices",
"[",
"$",
"plugin",
"]",
"=",
"get_string",
"(",
"'pluginname'",
",",
"'gradeexport_'",
".",
"$",
"plugin",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Load the available choices for the multicheckbox
@return bool always returns true
|
[
"Load",
"the",
"available",
"choices",
"for",
"the",
"multicheckbox"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L5560-L5572
|
215,794
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_gradecat_combo.output_html
|
public function output_html($data, $query='') {
global $OUTPUT;
$value = $data['value'];
$default = $this->get_defaultsetting();
if (!is_null($default)) {
$defaultinfo = array();
if (isset($this->choices[$default['value']])) {
$defaultinfo[] = $this->choices[$default['value']];
}
if (!empty($default['forced'])) {
$defaultinfo[] = get_string('force');
}
if (!empty($default['adv'])) {
$defaultinfo[] = get_string('advanced');
}
$defaultinfo = implode(', ', $defaultinfo);
} else {
$defaultinfo = NULL;
}
$options = $this->choices;
$context = (object) [
'id' => $this->get_id(),
'name' => $this->get_full_name(),
'forced' => !empty($data['forced']),
'advanced' => !empty($data['adv']),
'options' => array_map(function($option) use ($options, $value) {
return [
'value' => $option,
'name' => $options[$option],
'selected' => $option == $value
];
}, array_keys($options)),
];
$element = $OUTPUT->render_from_template('core_admin/setting_gradecat_combo', $context);
return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', $defaultinfo, $query);
}
|
php
|
public function output_html($data, $query='') {
global $OUTPUT;
$value = $data['value'];
$default = $this->get_defaultsetting();
if (!is_null($default)) {
$defaultinfo = array();
if (isset($this->choices[$default['value']])) {
$defaultinfo[] = $this->choices[$default['value']];
}
if (!empty($default['forced'])) {
$defaultinfo[] = get_string('force');
}
if (!empty($default['adv'])) {
$defaultinfo[] = get_string('advanced');
}
$defaultinfo = implode(', ', $defaultinfo);
} else {
$defaultinfo = NULL;
}
$options = $this->choices;
$context = (object) [
'id' => $this->get_id(),
'name' => $this->get_full_name(),
'forced' => !empty($data['forced']),
'advanced' => !empty($data['adv']),
'options' => array_map(function($option) use ($options, $value) {
return [
'value' => $option,
'name' => $options[$option],
'selected' => $option == $value
];
}, array_keys($options)),
];
$element = $OUTPUT->render_from_template('core_admin/setting_gradecat_combo', $context);
return format_admin_setting($this, $this->visiblename, $element, $this->description, true, '', $defaultinfo, $query);
}
|
[
"public",
"function",
"output_html",
"(",
"$",
"data",
",",
"$",
"query",
"=",
"''",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"$",
"value",
"=",
"$",
"data",
"[",
"'value'",
"]",
";",
"$",
"default",
"=",
"$",
"this",
"->",
"get_defaultsetting",
"(",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"default",
")",
")",
"{",
"$",
"defaultinfo",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"choices",
"[",
"$",
"default",
"[",
"'value'",
"]",
"]",
")",
")",
"{",
"$",
"defaultinfo",
"[",
"]",
"=",
"$",
"this",
"->",
"choices",
"[",
"$",
"default",
"[",
"'value'",
"]",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"default",
"[",
"'forced'",
"]",
")",
")",
"{",
"$",
"defaultinfo",
"[",
"]",
"=",
"get_string",
"(",
"'force'",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"default",
"[",
"'adv'",
"]",
")",
")",
"{",
"$",
"defaultinfo",
"[",
"]",
"=",
"get_string",
"(",
"'advanced'",
")",
";",
"}",
"$",
"defaultinfo",
"=",
"implode",
"(",
"', '",
",",
"$",
"defaultinfo",
")",
";",
"}",
"else",
"{",
"$",
"defaultinfo",
"=",
"NULL",
";",
"}",
"$",
"options",
"=",
"$",
"this",
"->",
"choices",
";",
"$",
"context",
"=",
"(",
"object",
")",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"get_id",
"(",
")",
",",
"'name'",
"=>",
"$",
"this",
"->",
"get_full_name",
"(",
")",
",",
"'forced'",
"=>",
"!",
"empty",
"(",
"$",
"data",
"[",
"'forced'",
"]",
")",
",",
"'advanced'",
"=>",
"!",
"empty",
"(",
"$",
"data",
"[",
"'adv'",
"]",
")",
",",
"'options'",
"=>",
"array_map",
"(",
"function",
"(",
"$",
"option",
")",
"use",
"(",
"$",
"options",
",",
"$",
"value",
")",
"{",
"return",
"[",
"'value'",
"=>",
"$",
"option",
",",
"'name'",
"=>",
"$",
"options",
"[",
"$",
"option",
"]",
",",
"'selected'",
"=>",
"$",
"option",
"==",
"$",
"value",
"]",
";",
"}",
",",
"array_keys",
"(",
"$",
"options",
")",
")",
",",
"]",
";",
"$",
"element",
"=",
"$",
"OUTPUT",
"->",
"render_from_template",
"(",
"'core_admin/setting_gradecat_combo'",
",",
"$",
"context",
")",
";",
"return",
"format_admin_setting",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"visiblename",
",",
"$",
"element",
",",
"$",
"this",
"->",
"description",
",",
"true",
",",
"''",
",",
"$",
"defaultinfo",
",",
"$",
"query",
")",
";",
"}"
] |
Return XHTML to display the field and wrapping div
@todo Add vartype handling to ensure $data is array
@param array $data Associative array of value=>xx, forced=>xx, adv=>xx
@param string $query
@return string XHTML to display control
|
[
"Return",
"XHTML",
"to",
"display",
"the",
"field",
"and",
"wrapping",
"div"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L5791-L5832
|
215,795
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_grade_profilereport.load_choices
|
public function load_choices() {
if (is_array($this->choices)) {
return true;
}
$this->choices = array();
global $CFG;
require_once($CFG->libdir.'/gradelib.php');
foreach (core_component::get_plugin_list('gradereport') as $plugin => $plugindir) {
if (file_exists($plugindir.'/lib.php')) {
require_once($plugindir.'/lib.php');
$functionname = 'grade_report_'.$plugin.'_profilereport';
if (function_exists($functionname)) {
$this->choices[$plugin] = get_string('pluginname', 'gradereport_'.$plugin);
}
}
}
return true;
}
|
php
|
public function load_choices() {
if (is_array($this->choices)) {
return true;
}
$this->choices = array();
global $CFG;
require_once($CFG->libdir.'/gradelib.php');
foreach (core_component::get_plugin_list('gradereport') as $plugin => $plugindir) {
if (file_exists($plugindir.'/lib.php')) {
require_once($plugindir.'/lib.php');
$functionname = 'grade_report_'.$plugin.'_profilereport';
if (function_exists($functionname)) {
$this->choices[$plugin] = get_string('pluginname', 'gradereport_'.$plugin);
}
}
}
return true;
}
|
[
"public",
"function",
"load_choices",
"(",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"choices",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"choices",
"=",
"array",
"(",
")",
";",
"global",
"$",
"CFG",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"libdir",
".",
"'/gradelib.php'",
")",
";",
"foreach",
"(",
"core_component",
"::",
"get_plugin_list",
"(",
"'gradereport'",
")",
"as",
"$",
"plugin",
"=>",
"$",
"plugindir",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"plugindir",
".",
"'/lib.php'",
")",
")",
"{",
"require_once",
"(",
"$",
"plugindir",
".",
"'/lib.php'",
")",
";",
"$",
"functionname",
"=",
"'grade_report_'",
".",
"$",
"plugin",
".",
"'_profilereport'",
";",
"if",
"(",
"function_exists",
"(",
"$",
"functionname",
")",
")",
"{",
"$",
"this",
"->",
"choices",
"[",
"$",
"plugin",
"]",
"=",
"get_string",
"(",
"'pluginname'",
",",
"'gradereport_'",
".",
"$",
"plugin",
")",
";",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] |
Loads an array of choices for the configselect control
@return bool always return true
|
[
"Loads",
"an",
"array",
"of",
"choices",
"for",
"the",
"configselect",
"control"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L5854-L5873
|
215,796
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_my_grades_report.load_choices
|
public function load_choices() {
global $CFG; // Remove this line and behold the horror of behat test failures!
$this->choices = array();
foreach (core_component::get_plugin_list('gradereport') as $plugin => $plugindir) {
if (file_exists($plugindir . '/lib.php')) {
require_once($plugindir . '/lib.php');
// Check to see if the class exists. Check the correct plugin convention first.
if (class_exists('gradereport_' . $plugin)) {
$classname = 'gradereport_' . $plugin;
} else if (class_exists('grade_report_' . $plugin)) {
// We are using the old plugin naming convention.
$classname = 'grade_report_' . $plugin;
} else {
continue;
}
if ($classname::supports_mygrades()) {
$this->choices[$plugin] = get_string('pluginname', 'gradereport_' . $plugin);
}
}
}
// Add an option to specify an external url.
$this->choices['external'] = get_string('externalurl', 'grades');
return true;
}
|
php
|
public function load_choices() {
global $CFG; // Remove this line and behold the horror of behat test failures!
$this->choices = array();
foreach (core_component::get_plugin_list('gradereport') as $plugin => $plugindir) {
if (file_exists($plugindir . '/lib.php')) {
require_once($plugindir . '/lib.php');
// Check to see if the class exists. Check the correct plugin convention first.
if (class_exists('gradereport_' . $plugin)) {
$classname = 'gradereport_' . $plugin;
} else if (class_exists('grade_report_' . $plugin)) {
// We are using the old plugin naming convention.
$classname = 'grade_report_' . $plugin;
} else {
continue;
}
if ($classname::supports_mygrades()) {
$this->choices[$plugin] = get_string('pluginname', 'gradereport_' . $plugin);
}
}
}
// Add an option to specify an external url.
$this->choices['external'] = get_string('externalurl', 'grades');
return true;
}
|
[
"public",
"function",
"load_choices",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"// Remove this line and behold the horror of behat test failures!",
"$",
"this",
"->",
"choices",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"core_component",
"::",
"get_plugin_list",
"(",
"'gradereport'",
")",
"as",
"$",
"plugin",
"=>",
"$",
"plugindir",
")",
"{",
"if",
"(",
"file_exists",
"(",
"$",
"plugindir",
".",
"'/lib.php'",
")",
")",
"{",
"require_once",
"(",
"$",
"plugindir",
".",
"'/lib.php'",
")",
";",
"// Check to see if the class exists. Check the correct plugin convention first.",
"if",
"(",
"class_exists",
"(",
"'gradereport_'",
".",
"$",
"plugin",
")",
")",
"{",
"$",
"classname",
"=",
"'gradereport_'",
".",
"$",
"plugin",
";",
"}",
"else",
"if",
"(",
"class_exists",
"(",
"'grade_report_'",
".",
"$",
"plugin",
")",
")",
"{",
"// We are using the old plugin naming convention.",
"$",
"classname",
"=",
"'grade_report_'",
".",
"$",
"plugin",
";",
"}",
"else",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"classname",
"::",
"supports_mygrades",
"(",
")",
")",
"{",
"$",
"this",
"->",
"choices",
"[",
"$",
"plugin",
"]",
"=",
"get_string",
"(",
"'pluginname'",
",",
"'gradereport_'",
".",
"$",
"plugin",
")",
";",
"}",
"}",
"}",
"// Add an option to specify an external url.",
"$",
"this",
"->",
"choices",
"[",
"'external'",
"]",
"=",
"get_string",
"(",
"'externalurl'",
",",
"'grades'",
")",
";",
"return",
"true",
";",
"}"
] |
Loads an array of choices for the configselect control.
@return bool always returns true.
|
[
"Loads",
"an",
"array",
"of",
"choices",
"for",
"the",
"configselect",
"control",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L5897-L5920
|
215,797
|
moodle/moodle
|
lib/adminlib.php
|
admin_setting_special_registerauth.load_choices
|
public function load_choices() {
global $CFG;
if (is_array($this->choices)) {
return true;
}
$this->choices = array();
$this->choices[''] = get_string('disable');
$authsenabled = get_enabled_auth_plugins(true);
foreach ($authsenabled as $auth) {
$authplugin = get_auth_plugin($auth);
if (!$authplugin->can_signup()) {
continue;
}
// Get the auth title (from core or own auth lang files)
$authtitle = $authplugin->get_title();
$this->choices[$auth] = $authtitle;
}
return true;
}
|
php
|
public function load_choices() {
global $CFG;
if (is_array($this->choices)) {
return true;
}
$this->choices = array();
$this->choices[''] = get_string('disable');
$authsenabled = get_enabled_auth_plugins(true);
foreach ($authsenabled as $auth) {
$authplugin = get_auth_plugin($auth);
if (!$authplugin->can_signup()) {
continue;
}
// Get the auth title (from core or own auth lang files)
$authtitle = $authplugin->get_title();
$this->choices[$auth] = $authtitle;
}
return true;
}
|
[
"public",
"function",
"load_choices",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"choices",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"choices",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"choices",
"[",
"''",
"]",
"=",
"get_string",
"(",
"'disable'",
")",
";",
"$",
"authsenabled",
"=",
"get_enabled_auth_plugins",
"(",
"true",
")",
";",
"foreach",
"(",
"$",
"authsenabled",
"as",
"$",
"auth",
")",
"{",
"$",
"authplugin",
"=",
"get_auth_plugin",
"(",
"$",
"auth",
")",
";",
"if",
"(",
"!",
"$",
"authplugin",
"->",
"can_signup",
"(",
")",
")",
"{",
"continue",
";",
"}",
"// Get the auth title (from core or own auth lang files)",
"$",
"authtitle",
"=",
"$",
"authplugin",
"->",
"get_title",
"(",
")",
";",
"$",
"this",
"->",
"choices",
"[",
"$",
"auth",
"]",
"=",
"$",
"authtitle",
";",
"}",
"return",
"true",
";",
"}"
] |
Loads the possible choices for the array
@return bool always returns true
|
[
"Loads",
"the",
"possible",
"choices",
"for",
"the",
"array"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L5956-L5977
|
215,798
|
moodle/moodle
|
lib/adminlib.php
|
admin_page_managemods.search
|
public function search($query) {
global $CFG, $DB;
if ($result = parent::search($query)) {
return $result;
}
$found = false;
if ($modules = $DB->get_records('modules')) {
foreach ($modules as $module) {
if (!file_exists("$CFG->dirroot/mod/$module->name/lib.php")) {
continue;
}
if (strpos($module->name, $query) !== false) {
$found = true;
break;
}
$strmodulename = get_string('modulename', $module->name);
if (strpos(core_text::strtolower($strmodulename), $query) !== false) {
$found = true;
break;
}
}
}
if ($found) {
$result = new stdClass();
$result->page = $this;
$result->settings = array();
return array($this->name => $result);
} else {
return array();
}
}
|
php
|
public function search($query) {
global $CFG, $DB;
if ($result = parent::search($query)) {
return $result;
}
$found = false;
if ($modules = $DB->get_records('modules')) {
foreach ($modules as $module) {
if (!file_exists("$CFG->dirroot/mod/$module->name/lib.php")) {
continue;
}
if (strpos($module->name, $query) !== false) {
$found = true;
break;
}
$strmodulename = get_string('modulename', $module->name);
if (strpos(core_text::strtolower($strmodulename), $query) !== false) {
$found = true;
break;
}
}
}
if ($found) {
$result = new stdClass();
$result->page = $this;
$result->settings = array();
return array($this->name => $result);
} else {
return array();
}
}
|
[
"public",
"function",
"search",
"(",
"$",
"query",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
";",
"if",
"(",
"$",
"result",
"=",
"parent",
"::",
"search",
"(",
"$",
"query",
")",
")",
"{",
"return",
"$",
"result",
";",
"}",
"$",
"found",
"=",
"false",
";",
"if",
"(",
"$",
"modules",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'modules'",
")",
")",
"{",
"foreach",
"(",
"$",
"modules",
"as",
"$",
"module",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"\"$CFG->dirroot/mod/$module->name/lib.php\"",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"module",
"->",
"name",
",",
"$",
"query",
")",
"!==",
"false",
")",
"{",
"$",
"found",
"=",
"true",
";",
"break",
";",
"}",
"$",
"strmodulename",
"=",
"get_string",
"(",
"'modulename'",
",",
"$",
"module",
"->",
"name",
")",
";",
"if",
"(",
"strpos",
"(",
"core_text",
"::",
"strtolower",
"(",
"$",
"strmodulename",
")",
",",
"$",
"query",
")",
"!==",
"false",
")",
"{",
"$",
"found",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"found",
")",
"{",
"$",
"result",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"result",
"->",
"page",
"=",
"$",
"this",
";",
"$",
"result",
"->",
"settings",
"=",
"array",
"(",
")",
";",
"return",
"array",
"(",
"$",
"this",
"->",
"name",
"=>",
"$",
"result",
")",
";",
"}",
"else",
"{",
"return",
"array",
"(",
")",
";",
"}",
"}"
] |
Try to find the specified module
@param string $query The module to search for
@return array
|
[
"Try",
"to",
"find",
"the",
"specified",
"module"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L6016-L6047
|
215,799
|
moodle/moodle
|
lib/adminlib.php
|
admin_page_manageblocks.search
|
public function search($query) {
global $CFG, $DB;
if ($result = parent::search($query)) {
return $result;
}
$found = false;
if ($blocks = $DB->get_records('block')) {
foreach ($blocks as $block) {
if (!file_exists("$CFG->dirroot/blocks/$block->name/")) {
continue;
}
if (strpos($block->name, $query) !== false) {
$found = true;
break;
}
$strblockname = get_string('pluginname', 'block_'.$block->name);
if (strpos(core_text::strtolower($strblockname), $query) !== false) {
$found = true;
break;
}
}
}
if ($found) {
$result = new stdClass();
$result->page = $this;
$result->settings = array();
return array($this->name => $result);
} else {
return array();
}
}
|
php
|
public function search($query) {
global $CFG, $DB;
if ($result = parent::search($query)) {
return $result;
}
$found = false;
if ($blocks = $DB->get_records('block')) {
foreach ($blocks as $block) {
if (!file_exists("$CFG->dirroot/blocks/$block->name/")) {
continue;
}
if (strpos($block->name, $query) !== false) {
$found = true;
break;
}
$strblockname = get_string('pluginname', 'block_'.$block->name);
if (strpos(core_text::strtolower($strblockname), $query) !== false) {
$found = true;
break;
}
}
}
if ($found) {
$result = new stdClass();
$result->page = $this;
$result->settings = array();
return array($this->name => $result);
} else {
return array();
}
}
|
[
"public",
"function",
"search",
"(",
"$",
"query",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
";",
"if",
"(",
"$",
"result",
"=",
"parent",
"::",
"search",
"(",
"$",
"query",
")",
")",
"{",
"return",
"$",
"result",
";",
"}",
"$",
"found",
"=",
"false",
";",
"if",
"(",
"$",
"blocks",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'block'",
")",
")",
"{",
"foreach",
"(",
"$",
"blocks",
"as",
"$",
"block",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"\"$CFG->dirroot/blocks/$block->name/\"",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"block",
"->",
"name",
",",
"$",
"query",
")",
"!==",
"false",
")",
"{",
"$",
"found",
"=",
"true",
";",
"break",
";",
"}",
"$",
"strblockname",
"=",
"get_string",
"(",
"'pluginname'",
",",
"'block_'",
".",
"$",
"block",
"->",
"name",
")",
";",
"if",
"(",
"strpos",
"(",
"core_text",
"::",
"strtolower",
"(",
"$",
"strblockname",
")",
",",
"$",
"query",
")",
"!==",
"false",
")",
"{",
"$",
"found",
"=",
"true",
";",
"break",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"found",
")",
"{",
"$",
"result",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"result",
"->",
"page",
"=",
"$",
"this",
";",
"$",
"result",
"->",
"settings",
"=",
"array",
"(",
")",
";",
"return",
"array",
"(",
"$",
"this",
"->",
"name",
"=>",
"$",
"result",
")",
";",
"}",
"else",
"{",
"return",
"array",
"(",
")",
";",
"}",
"}"
] |
Search for a specific block
@param string $query The string to search for
@return array
|
[
"Search",
"for",
"a",
"specific",
"block"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adminlib.php#L6297-L6328
|
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.