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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
212,400 | moodle/moodle | mod/workshop/form/accumulative/lib.php | workshop_accumulative_strategy.scale_used | public static function scale_used($scaleid, $workshopid=null) {
global $DB;
$conditions['grade'] = -$scaleid;
if (!is_null($workshopid)) {
$conditions['workshopid'] = $workshopid;
}
return $DB->record_exists('workshopform_accumulative', $conditions);
} | php | public static function scale_used($scaleid, $workshopid=null) {
global $DB;
$conditions['grade'] = -$scaleid;
if (!is_null($workshopid)) {
$conditions['workshopid'] = $workshopid;
}
return $DB->record_exists('workshopform_accumulative', $conditions);
} | [
"public",
"static",
"function",
"scale_used",
"(",
"$",
"scaleid",
",",
"$",
"workshopid",
"=",
"null",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"conditions",
"[",
"'grade'",
"]",
"=",
"-",
"$",
"scaleid",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"workshopid",
")",
")",
"{",
"$",
"conditions",
"[",
"'workshopid'",
"]",
"=",
"$",
"workshopid",
";",
"}",
"return",
"$",
"DB",
"->",
"record_exists",
"(",
"'workshopform_accumulative'",
",",
"$",
"conditions",
")",
";",
"}"
] | Is a given scale used by the instance of workshop?
@param int $scaleid id of the scale to check
@param int|null $workshopid id of workshop instance to check, checks all in case of null
@return bool | [
"Is",
"a",
"given",
"scale",
"used",
"by",
"the",
"instance",
"of",
"workshop?"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/form/accumulative/lib.php#L366-L374 |
212,401 | moodle/moodle | mod/workshop/form/accumulative/lib.php | workshop_accumulative_strategy.update_peer_grade | protected function update_peer_grade(stdclass $assessment) {
$grades = $this->get_current_assessment_data($assessment);
$suggested = $this->calculate_peer_grade($grades);
if (!is_null($suggested)) {
$this->workshop->set_peer_grade($assessment->id, $suggested);
}
return $suggested;
} | php | protected function update_peer_grade(stdclass $assessment) {
$grades = $this->get_current_assessment_data($assessment);
$suggested = $this->calculate_peer_grade($grades);
if (!is_null($suggested)) {
$this->workshop->set_peer_grade($assessment->id, $suggested);
}
return $suggested;
} | [
"protected",
"function",
"update_peer_grade",
"(",
"stdclass",
"$",
"assessment",
")",
"{",
"$",
"grades",
"=",
"$",
"this",
"->",
"get_current_assessment_data",
"(",
"$",
"assessment",
")",
";",
"$",
"suggested",
"=",
"$",
"this",
"->",
"calculate_peer_grade",
"(",
"$",
"grades",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"suggested",
")",
")",
"{",
"$",
"this",
"->",
"workshop",
"->",
"set_peer_grade",
"(",
"$",
"assessment",
"->",
"id",
",",
"$",
"suggested",
")",
";",
"}",
"return",
"$",
"suggested",
";",
"}"
] | Aggregates the assessment form data and sets the grade for the submission given by the peer
@param stdClass $assessment Assessment record
@return float|null Raw grade (from 0.00000 to 100.00000) for submission as suggested by the peer | [
"Aggregates",
"the",
"assessment",
"form",
"data",
"and",
"sets",
"the",
"grade",
"for",
"the",
"submission",
"given",
"by",
"the",
"peer"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/form/accumulative/lib.php#L509-L516 |
212,402 | moodle/moodle | mod/workshop/form/accumulative/lib.php | workshop_accumulative_strategy.scale_to_grade | protected function scale_to_grade($scaleid, $item) {
global $DB;
/** @var cache of numbers of scale items */
static $numofscaleitems = array();
if (!isset($numofscaleitems[$scaleid])) {
$scale = $DB->get_field('scale', 'scale', array('id' => $scaleid), MUST_EXIST);
$items = explode(',', $scale);
$numofscaleitems[$scaleid] = count($items);
unset($scale);
unset($items);
}
if ($numofscaleitems[$scaleid] <= 1) {
throw new coding_exception('Invalid scale definition, no scale items found');
}
if ($item <= 0 or $numofscaleitems[$scaleid] < $item) {
throw new coding_exception('Invalid scale item number');
}
return ($item - 1) / ($numofscaleitems[$scaleid] - 1);
} | php | protected function scale_to_grade($scaleid, $item) {
global $DB;
/** @var cache of numbers of scale items */
static $numofscaleitems = array();
if (!isset($numofscaleitems[$scaleid])) {
$scale = $DB->get_field('scale', 'scale', array('id' => $scaleid), MUST_EXIST);
$items = explode(',', $scale);
$numofscaleitems[$scaleid] = count($items);
unset($scale);
unset($items);
}
if ($numofscaleitems[$scaleid] <= 1) {
throw new coding_exception('Invalid scale definition, no scale items found');
}
if ($item <= 0 or $numofscaleitems[$scaleid] < $item) {
throw new coding_exception('Invalid scale item number');
}
return ($item - 1) / ($numofscaleitems[$scaleid] - 1);
} | [
"protected",
"function",
"scale_to_grade",
"(",
"$",
"scaleid",
",",
"$",
"item",
")",
"{",
"global",
"$",
"DB",
";",
"/** @var cache of numbers of scale items */",
"static",
"$",
"numofscaleitems",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"numofscaleitems",
"[",
"$",
"scaleid",
"]",
")",
")",
"{",
"$",
"scale",
"=",
"$",
"DB",
"->",
"get_field",
"(",
"'scale'",
",",
"'scale'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"scaleid",
")",
",",
"MUST_EXIST",
")",
";",
"$",
"items",
"=",
"explode",
"(",
"','",
",",
"$",
"scale",
")",
";",
"$",
"numofscaleitems",
"[",
"$",
"scaleid",
"]",
"=",
"count",
"(",
"$",
"items",
")",
";",
"unset",
"(",
"$",
"scale",
")",
";",
"unset",
"(",
"$",
"items",
")",
";",
"}",
"if",
"(",
"$",
"numofscaleitems",
"[",
"$",
"scaleid",
"]",
"<=",
"1",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Invalid scale definition, no scale items found'",
")",
";",
"}",
"if",
"(",
"$",
"item",
"<=",
"0",
"or",
"$",
"numofscaleitems",
"[",
"$",
"scaleid",
"]",
"<",
"$",
"item",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Invalid scale item number'",
")",
";",
"}",
"return",
"(",
"$",
"item",
"-",
"1",
")",
"/",
"(",
"$",
"numofscaleitems",
"[",
"$",
"scaleid",
"]",
"-",
"1",
")",
";",
"}"
] | Convert scale grade to numerical grades
In accumulative grading strategy, scales are considered as grades from 0 to M-1, where M is the number of scale items.
@throws coding_exception
@param string $scaleid Scale identifier
@param int $item Selected scale item number, numbered 1, 2, 3, ... M
@return float | [
"Convert",
"scale",
"grade",
"to",
"numerical",
"grades"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/form/accumulative/lib.php#L569-L592 |
212,403 | moodle/moodle | auth/mnet/classes/task/cron_task.php | cron_task.execute | public function execute() {
global $DB, $CFG;
require_once($CFG->dirroot . '/auth/mnet/auth.php');
$mnetplugin = new \auth_plugin_mnet();
$mnetplugin->keepalive_client();
$random100 = rand(0,100);
if ($random100 < 10) {
$longtime = time() - DAYSECS;
$DB->delete_records_select('mnet_session', "expires < ?", [$longtime]);
}
} | php | public function execute() {
global $DB, $CFG;
require_once($CFG->dirroot . '/auth/mnet/auth.php');
$mnetplugin = new \auth_plugin_mnet();
$mnetplugin->keepalive_client();
$random100 = rand(0,100);
if ($random100 < 10) {
$longtime = time() - DAYSECS;
$DB->delete_records_select('mnet_session', "expires < ?", [$longtime]);
}
} | [
"public",
"function",
"execute",
"(",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"CFG",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/auth/mnet/auth.php'",
")",
";",
"$",
"mnetplugin",
"=",
"new",
"\\",
"auth_plugin_mnet",
"(",
")",
";",
"$",
"mnetplugin",
"->",
"keepalive_client",
"(",
")",
";",
"$",
"random100",
"=",
"rand",
"(",
"0",
",",
"100",
")",
";",
"if",
"(",
"$",
"random100",
"<",
"10",
")",
"{",
"$",
"longtime",
"=",
"time",
"(",
")",
"-",
"DAYSECS",
";",
"$",
"DB",
"->",
"delete_records_select",
"(",
"'mnet_session'",
",",
"\"expires < ?\"",
",",
"[",
"$",
"longtime",
"]",
")",
";",
"}",
"}"
] | Run auth mnet cron. | [
"Run",
"auth",
"mnet",
"cron",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/mnet/classes/task/cron_task.php#L39-L51 |
212,404 | moodle/moodle | admin/tool/oauth2/classes/output/renderer.php | renderer.endpoints_table | public function endpoints_table($endpoints, $issuerid) {
global $CFG;
$table = new html_table();
$table->head = [
get_string('name'),
get_string('url'),
get_string('edit'),
];
$table->attributes['class'] = 'admintable generaltable';
$data = [];
$index = 0;
foreach ($endpoints as $endpoint) {
// Name.
$name = $endpoint->get('name');
$namecell = new html_table_cell(s($name));
$namecell->header = true;
// Url.
$url = $endpoint->get('url');
$urlcell = new html_table_cell(s($url));
$links = '';
// Action links.
$editparams = ['issuerid' => $issuerid, 'endpointid' => $endpoint->get('id'), 'action' => 'edit'];
$editurl = new moodle_url('/admin/tool/oauth2/endpoints.php', $editparams);
$editlink = html_writer::link($editurl, $this->pix_icon('t/edit', get_string('edit')));
$links .= ' ' . $editlink;
// Delete.
$deleteparams = ['issuerid' => $issuerid, 'endpointid' => $endpoint->get('id'), 'action' => 'delete'];
$deleteurl = new moodle_url('/admin/tool/oauth2/endpoints.php', $deleteparams);
$deletelink = html_writer::link($deleteurl, $this->pix_icon('t/delete', get_string('delete')));
$links .= ' ' . $deletelink;
$editcell = new html_table_cell($links);
$row = new html_table_row([
$namecell,
$urlcell,
$editcell,
]);
$data[] = $row;
$index++;
}
$table->data = $data;
return html_writer::table($table);
} | php | public function endpoints_table($endpoints, $issuerid) {
global $CFG;
$table = new html_table();
$table->head = [
get_string('name'),
get_string('url'),
get_string('edit'),
];
$table->attributes['class'] = 'admintable generaltable';
$data = [];
$index = 0;
foreach ($endpoints as $endpoint) {
// Name.
$name = $endpoint->get('name');
$namecell = new html_table_cell(s($name));
$namecell->header = true;
// Url.
$url = $endpoint->get('url');
$urlcell = new html_table_cell(s($url));
$links = '';
// Action links.
$editparams = ['issuerid' => $issuerid, 'endpointid' => $endpoint->get('id'), 'action' => 'edit'];
$editurl = new moodle_url('/admin/tool/oauth2/endpoints.php', $editparams);
$editlink = html_writer::link($editurl, $this->pix_icon('t/edit', get_string('edit')));
$links .= ' ' . $editlink;
// Delete.
$deleteparams = ['issuerid' => $issuerid, 'endpointid' => $endpoint->get('id'), 'action' => 'delete'];
$deleteurl = new moodle_url('/admin/tool/oauth2/endpoints.php', $deleteparams);
$deletelink = html_writer::link($deleteurl, $this->pix_icon('t/delete', get_string('delete')));
$links .= ' ' . $deletelink;
$editcell = new html_table_cell($links);
$row = new html_table_row([
$namecell,
$urlcell,
$editcell,
]);
$data[] = $row;
$index++;
}
$table->data = $data;
return html_writer::table($table);
} | [
"public",
"function",
"endpoints_table",
"(",
"$",
"endpoints",
",",
"$",
"issuerid",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"table",
"=",
"new",
"html_table",
"(",
")",
";",
"$",
"table",
"->",
"head",
"=",
"[",
"get_string",
"(",
"'name'",
")",
",",
"get_string",
"(",
"'url'",
")",
",",
"get_string",
"(",
"'edit'",
")",
",",
"]",
";",
"$",
"table",
"->",
"attributes",
"[",
"'class'",
"]",
"=",
"'admintable generaltable'",
";",
"$",
"data",
"=",
"[",
"]",
";",
"$",
"index",
"=",
"0",
";",
"foreach",
"(",
"$",
"endpoints",
"as",
"$",
"endpoint",
")",
"{",
"// Name.",
"$",
"name",
"=",
"$",
"endpoint",
"->",
"get",
"(",
"'name'",
")",
";",
"$",
"namecell",
"=",
"new",
"html_table_cell",
"(",
"s",
"(",
"$",
"name",
")",
")",
";",
"$",
"namecell",
"->",
"header",
"=",
"true",
";",
"// Url.",
"$",
"url",
"=",
"$",
"endpoint",
"->",
"get",
"(",
"'url'",
")",
";",
"$",
"urlcell",
"=",
"new",
"html_table_cell",
"(",
"s",
"(",
"$",
"url",
")",
")",
";",
"$",
"links",
"=",
"''",
";",
"// Action links.",
"$",
"editparams",
"=",
"[",
"'issuerid'",
"=>",
"$",
"issuerid",
",",
"'endpointid'",
"=>",
"$",
"endpoint",
"->",
"get",
"(",
"'id'",
")",
",",
"'action'",
"=>",
"'edit'",
"]",
";",
"$",
"editurl",
"=",
"new",
"moodle_url",
"(",
"'/admin/tool/oauth2/endpoints.php'",
",",
"$",
"editparams",
")",
";",
"$",
"editlink",
"=",
"html_writer",
"::",
"link",
"(",
"$",
"editurl",
",",
"$",
"this",
"->",
"pix_icon",
"(",
"'t/edit'",
",",
"get_string",
"(",
"'edit'",
")",
")",
")",
";",
"$",
"links",
".=",
"' '",
".",
"$",
"editlink",
";",
"// Delete.",
"$",
"deleteparams",
"=",
"[",
"'issuerid'",
"=>",
"$",
"issuerid",
",",
"'endpointid'",
"=>",
"$",
"endpoint",
"->",
"get",
"(",
"'id'",
")",
",",
"'action'",
"=>",
"'delete'",
"]",
";",
"$",
"deleteurl",
"=",
"new",
"moodle_url",
"(",
"'/admin/tool/oauth2/endpoints.php'",
",",
"$",
"deleteparams",
")",
";",
"$",
"deletelink",
"=",
"html_writer",
"::",
"link",
"(",
"$",
"deleteurl",
",",
"$",
"this",
"->",
"pix_icon",
"(",
"'t/delete'",
",",
"get_string",
"(",
"'delete'",
")",
")",
")",
";",
"$",
"links",
".=",
"' '",
".",
"$",
"deletelink",
";",
"$",
"editcell",
"=",
"new",
"html_table_cell",
"(",
"$",
"links",
")",
";",
"$",
"row",
"=",
"new",
"html_table_row",
"(",
"[",
"$",
"namecell",
",",
"$",
"urlcell",
",",
"$",
"editcell",
",",
"]",
")",
";",
"$",
"data",
"[",
"]",
"=",
"$",
"row",
";",
"$",
"index",
"++",
";",
"}",
"$",
"table",
"->",
"data",
"=",
"$",
"data",
";",
"return",
"html_writer",
"::",
"table",
"(",
"$",
"table",
")",
";",
"}"
] | This function will render one beautiful table with all the endpoints.
@param \core\oauth2\endpoint[] $endpoints - list of all endpoints.
@param int $issuerid
@return string HTML to output. | [
"This",
"function",
"will",
"render",
"one",
"beautiful",
"table",
"with",
"all",
"the",
"endpoints",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/oauth2/classes/output/renderer.php#L210-L260 |
212,405 | moodle/moodle | admin/tool/oauth2/classes/output/renderer.php | renderer.user_field_mappings_table | public function user_field_mappings_table($userfieldmappings, $issuerid) {
global $CFG;
$table = new html_table();
$table->head = [
get_string('userfieldexternalfield', 'tool_oauth2'),
get_string('userfieldinternalfield', 'tool_oauth2'),
get_string('edit'),
];
$table->attributes['class'] = 'admintable generaltable';
$data = [];
$index = 0;
foreach ($userfieldmappings as $userfieldmapping) {
// External field.
$externalfield = $userfieldmapping->get('externalfield');
$externalfieldcell = new html_table_cell(s($externalfield));
// Internal field.
$internalfield = $userfieldmapping->get('internalfield');
$internalfieldcell = new html_table_cell(s($internalfield));
$links = '';
// Action links.
$editparams = ['issuerid' => $issuerid, 'userfieldmappingid' => $userfieldmapping->get('id'), 'action' => 'edit'];
$editurl = new moodle_url('/admin/tool/oauth2/userfieldmappings.php', $editparams);
$editlink = html_writer::link($editurl, $this->pix_icon('t/edit', get_string('edit')));
$links .= ' ' . $editlink;
// Delete.
$deleteparams = ['issuerid' => $issuerid, 'userfieldmappingid' => $userfieldmapping->get('id'), 'action' => 'delete'];
$deleteurl = new moodle_url('/admin/tool/oauth2/userfieldmappings.php', $deleteparams);
$deletelink = html_writer::link($deleteurl, $this->pix_icon('t/delete', get_string('delete')));
$links .= ' ' . $deletelink;
$editcell = new html_table_cell($links);
$row = new html_table_row([
$externalfieldcell,
$internalfieldcell,
$editcell,
]);
$data[] = $row;
$index++;
}
$table->data = $data;
return html_writer::table($table);
} | php | public function user_field_mappings_table($userfieldmappings, $issuerid) {
global $CFG;
$table = new html_table();
$table->head = [
get_string('userfieldexternalfield', 'tool_oauth2'),
get_string('userfieldinternalfield', 'tool_oauth2'),
get_string('edit'),
];
$table->attributes['class'] = 'admintable generaltable';
$data = [];
$index = 0;
foreach ($userfieldmappings as $userfieldmapping) {
// External field.
$externalfield = $userfieldmapping->get('externalfield');
$externalfieldcell = new html_table_cell(s($externalfield));
// Internal field.
$internalfield = $userfieldmapping->get('internalfield');
$internalfieldcell = new html_table_cell(s($internalfield));
$links = '';
// Action links.
$editparams = ['issuerid' => $issuerid, 'userfieldmappingid' => $userfieldmapping->get('id'), 'action' => 'edit'];
$editurl = new moodle_url('/admin/tool/oauth2/userfieldmappings.php', $editparams);
$editlink = html_writer::link($editurl, $this->pix_icon('t/edit', get_string('edit')));
$links .= ' ' . $editlink;
// Delete.
$deleteparams = ['issuerid' => $issuerid, 'userfieldmappingid' => $userfieldmapping->get('id'), 'action' => 'delete'];
$deleteurl = new moodle_url('/admin/tool/oauth2/userfieldmappings.php', $deleteparams);
$deletelink = html_writer::link($deleteurl, $this->pix_icon('t/delete', get_string('delete')));
$links .= ' ' . $deletelink;
$editcell = new html_table_cell($links);
$row = new html_table_row([
$externalfieldcell,
$internalfieldcell,
$editcell,
]);
$data[] = $row;
$index++;
}
$table->data = $data;
return html_writer::table($table);
} | [
"public",
"function",
"user_field_mappings_table",
"(",
"$",
"userfieldmappings",
",",
"$",
"issuerid",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"table",
"=",
"new",
"html_table",
"(",
")",
";",
"$",
"table",
"->",
"head",
"=",
"[",
"get_string",
"(",
"'userfieldexternalfield'",
",",
"'tool_oauth2'",
")",
",",
"get_string",
"(",
"'userfieldinternalfield'",
",",
"'tool_oauth2'",
")",
",",
"get_string",
"(",
"'edit'",
")",
",",
"]",
";",
"$",
"table",
"->",
"attributes",
"[",
"'class'",
"]",
"=",
"'admintable generaltable'",
";",
"$",
"data",
"=",
"[",
"]",
";",
"$",
"index",
"=",
"0",
";",
"foreach",
"(",
"$",
"userfieldmappings",
"as",
"$",
"userfieldmapping",
")",
"{",
"// External field.",
"$",
"externalfield",
"=",
"$",
"userfieldmapping",
"->",
"get",
"(",
"'externalfield'",
")",
";",
"$",
"externalfieldcell",
"=",
"new",
"html_table_cell",
"(",
"s",
"(",
"$",
"externalfield",
")",
")",
";",
"// Internal field.",
"$",
"internalfield",
"=",
"$",
"userfieldmapping",
"->",
"get",
"(",
"'internalfield'",
")",
";",
"$",
"internalfieldcell",
"=",
"new",
"html_table_cell",
"(",
"s",
"(",
"$",
"internalfield",
")",
")",
";",
"$",
"links",
"=",
"''",
";",
"// Action links.",
"$",
"editparams",
"=",
"[",
"'issuerid'",
"=>",
"$",
"issuerid",
",",
"'userfieldmappingid'",
"=>",
"$",
"userfieldmapping",
"->",
"get",
"(",
"'id'",
")",
",",
"'action'",
"=>",
"'edit'",
"]",
";",
"$",
"editurl",
"=",
"new",
"moodle_url",
"(",
"'/admin/tool/oauth2/userfieldmappings.php'",
",",
"$",
"editparams",
")",
";",
"$",
"editlink",
"=",
"html_writer",
"::",
"link",
"(",
"$",
"editurl",
",",
"$",
"this",
"->",
"pix_icon",
"(",
"'t/edit'",
",",
"get_string",
"(",
"'edit'",
")",
")",
")",
";",
"$",
"links",
".=",
"' '",
".",
"$",
"editlink",
";",
"// Delete.",
"$",
"deleteparams",
"=",
"[",
"'issuerid'",
"=>",
"$",
"issuerid",
",",
"'userfieldmappingid'",
"=>",
"$",
"userfieldmapping",
"->",
"get",
"(",
"'id'",
")",
",",
"'action'",
"=>",
"'delete'",
"]",
";",
"$",
"deleteurl",
"=",
"new",
"moodle_url",
"(",
"'/admin/tool/oauth2/userfieldmappings.php'",
",",
"$",
"deleteparams",
")",
";",
"$",
"deletelink",
"=",
"html_writer",
"::",
"link",
"(",
"$",
"deleteurl",
",",
"$",
"this",
"->",
"pix_icon",
"(",
"'t/delete'",
",",
"get_string",
"(",
"'delete'",
")",
")",
")",
";",
"$",
"links",
".=",
"' '",
".",
"$",
"deletelink",
";",
"$",
"editcell",
"=",
"new",
"html_table_cell",
"(",
"$",
"links",
")",
";",
"$",
"row",
"=",
"new",
"html_table_row",
"(",
"[",
"$",
"externalfieldcell",
",",
"$",
"internalfieldcell",
",",
"$",
"editcell",
",",
"]",
")",
";",
"$",
"data",
"[",
"]",
"=",
"$",
"row",
";",
"$",
"index",
"++",
";",
"}",
"$",
"table",
"->",
"data",
"=",
"$",
"data",
";",
"return",
"html_writer",
"::",
"table",
"(",
"$",
"table",
")",
";",
"}"
] | This function will render one beautiful table with all the user_field_mappings.
@param \core\oauth2\user_field_mapping[] $userfieldmappings - list of all user_field_mappings.
@param int $issuerid
@return string HTML to output. | [
"This",
"function",
"will",
"render",
"one",
"beautiful",
"table",
"with",
"all",
"the",
"user_field_mappings",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/oauth2/classes/output/renderer.php#L269-L318 |
212,406 | moodle/moodle | grade/grading/form/lib.php | gradingform_controller.is_own_form | public function is_own_form($userid = null) {
global $USER;
if (!$this->is_form_defined()) {
return null;
}
if (is_null($userid)) {
$userid = $USER->id;
}
return ($this->definition->usercreated == $userid);
} | php | public function is_own_form($userid = null) {
global $USER;
if (!$this->is_form_defined()) {
return null;
}
if (is_null($userid)) {
$userid = $USER->id;
}
return ($this->definition->usercreated == $userid);
} | [
"public",
"function",
"is_own_form",
"(",
"$",
"userid",
"=",
"null",
")",
"{",
"global",
"$",
"USER",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"is_form_defined",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"userid",
")",
")",
"{",
"$",
"userid",
"=",
"$",
"USER",
"->",
"id",
";",
"}",
"return",
"(",
"$",
"this",
"->",
"definition",
"->",
"usercreated",
"==",
"$",
"userid",
")",
";",
"}"
] | Is the grading form owned by the given user?
The form owner is the user who created this instance of the form.
@param int $userid the user id to check, defaults to the current user
@return boolean|null null if the form not defined yet, boolean otherwise | [
"Is",
"the",
"grading",
"form",
"owned",
"by",
"the",
"given",
"user?"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/lib.php#L177-L187 |
212,407 | moodle/moodle | grade/grading/form/lib.php | gradingform_controller.get_editor_url | public function get_editor_url(moodle_url $returnurl = null) {
$params = array('areaid' => $this->areaid);
if (!is_null($returnurl)) {
$params['returnurl'] = $returnurl->out(false);
}
return new moodle_url('/grade/grading/form/'.$this->get_method_name().'/edit.php', $params);
} | php | public function get_editor_url(moodle_url $returnurl = null) {
$params = array('areaid' => $this->areaid);
if (!is_null($returnurl)) {
$params['returnurl'] = $returnurl->out(false);
}
return new moodle_url('/grade/grading/form/'.$this->get_method_name().'/edit.php', $params);
} | [
"public",
"function",
"get_editor_url",
"(",
"moodle_url",
"$",
"returnurl",
"=",
"null",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'areaid'",
"=>",
"$",
"this",
"->",
"areaid",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"returnurl",
")",
")",
"{",
"$",
"params",
"[",
"'returnurl'",
"]",
"=",
"$",
"returnurl",
"->",
"out",
"(",
"false",
")",
";",
"}",
"return",
"new",
"moodle_url",
"(",
"'/grade/grading/form/'",
".",
"$",
"this",
"->",
"get_method_name",
"(",
")",
".",
"'/edit.php'",
",",
"$",
"params",
")",
";",
"}"
] | Returns URL of a page where the grading form can be defined and edited.
@param moodle_url $returnurl optional URL of a page where the user should be sent once they are finished with editing
@return moodle_url | [
"Returns",
"URL",
"of",
"a",
"page",
"where",
"the",
"grading",
"form",
"can",
"be",
"defined",
"and",
"edited",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/lib.php#L208-L217 |
212,408 | moodle/moodle | grade/grading/form/lib.php | gradingform_controller.get_definition | public function get_definition($force = false) {
if ($this->definition === false || $force) {
$this->load_definition();
}
return $this->definition;
} | php | public function get_definition($force = false) {
if ($this->definition === false || $force) {
$this->load_definition();
}
return $this->definition;
} | [
"public",
"function",
"get_definition",
"(",
"$",
"force",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"definition",
"===",
"false",
"||",
"$",
"force",
")",
"{",
"$",
"this",
"->",
"load_definition",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"definition",
";",
"}"
] | Returns the grading form definition structure
@param boolean $force whether to force loading from DB even if it was already loaded
@return stdClass|false definition data or false if the form is not defined yet | [
"Returns",
"the",
"grading",
"form",
"definition",
"structure"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/lib.php#L252-L257 |
212,409 | moodle/moodle | grade/grading/form/lib.php | gradingform_controller.update_definition | public function update_definition(stdClass $definition, $usermodified = null) {
global $DB, $USER;
if (is_null($usermodified)) {
$usermodified = $USER->id;
}
if (!empty($this->definition->id)) {
// prepare a record to be updated
$record = new stdClass();
// populate it with scalar values from the passed definition structure
foreach ($definition as $prop => $val) {
if (is_array($val) or is_object($val)) {
// probably plugin's data
continue;
}
$record->{$prop} = $val;
}
// make sure we do not override some crucial values by accident
if (!empty($record->id) and $record->id != $this->definition->id) {
throw new coding_exception('Attempting to update other definition record.');
}
$record->id = $this->definition->id;
unset($record->areaid);
unset($record->method);
unset($record->timecreated);
// set the modification flags
$record->timemodified = time();
$record->usermodified = $usermodified;
$DB->update_record('grading_definitions', $record);
} else if ($this->definition === false) {
// prepare a record to be inserted
$record = new stdClass();
// populate it with scalar values from the passed definition structure
foreach ($definition as $prop => $val) {
if (is_array($val) or is_object($val)) {
// probably plugin's data
continue;
}
$record->{$prop} = $val;
}
// make sure we do not override some crucial values by accident
if (!empty($record->id)) {
throw new coding_exception('Attempting to create a new record while there is already one existing.');
}
unset($record->id);
$record->areaid = $this->areaid;
$record->method = $this->get_method_name();
$record->timecreated = time();
$record->usercreated = $usermodified;
$record->timemodified = $record->timecreated;
$record->usermodified = $record->usercreated;
if (empty($record->status)) {
$record->status = self::DEFINITION_STATUS_DRAFT;
}
if (empty($record->descriptionformat)) {
$record->descriptionformat = FORMAT_MOODLE; // field can not be empty
}
$DB->insert_record('grading_definitions', $record);
} else {
throw new coding_exception('Unknown status of the cached definition record.');
}
} | php | public function update_definition(stdClass $definition, $usermodified = null) {
global $DB, $USER;
if (is_null($usermodified)) {
$usermodified = $USER->id;
}
if (!empty($this->definition->id)) {
// prepare a record to be updated
$record = new stdClass();
// populate it with scalar values from the passed definition structure
foreach ($definition as $prop => $val) {
if (is_array($val) or is_object($val)) {
// probably plugin's data
continue;
}
$record->{$prop} = $val;
}
// make sure we do not override some crucial values by accident
if (!empty($record->id) and $record->id != $this->definition->id) {
throw new coding_exception('Attempting to update other definition record.');
}
$record->id = $this->definition->id;
unset($record->areaid);
unset($record->method);
unset($record->timecreated);
// set the modification flags
$record->timemodified = time();
$record->usermodified = $usermodified;
$DB->update_record('grading_definitions', $record);
} else if ($this->definition === false) {
// prepare a record to be inserted
$record = new stdClass();
// populate it with scalar values from the passed definition structure
foreach ($definition as $prop => $val) {
if (is_array($val) or is_object($val)) {
// probably plugin's data
continue;
}
$record->{$prop} = $val;
}
// make sure we do not override some crucial values by accident
if (!empty($record->id)) {
throw new coding_exception('Attempting to create a new record while there is already one existing.');
}
unset($record->id);
$record->areaid = $this->areaid;
$record->method = $this->get_method_name();
$record->timecreated = time();
$record->usercreated = $usermodified;
$record->timemodified = $record->timecreated;
$record->usermodified = $record->usercreated;
if (empty($record->status)) {
$record->status = self::DEFINITION_STATUS_DRAFT;
}
if (empty($record->descriptionformat)) {
$record->descriptionformat = FORMAT_MOODLE; // field can not be empty
}
$DB->insert_record('grading_definitions', $record);
} else {
throw new coding_exception('Unknown status of the cached definition record.');
}
} | [
"public",
"function",
"update_definition",
"(",
"stdClass",
"$",
"definition",
",",
"$",
"usermodified",
"=",
"null",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"USER",
";",
"if",
"(",
"is_null",
"(",
"$",
"usermodified",
")",
")",
"{",
"$",
"usermodified",
"=",
"$",
"USER",
"->",
"id",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"definition",
"->",
"id",
")",
")",
"{",
"// prepare a record to be updated",
"$",
"record",
"=",
"new",
"stdClass",
"(",
")",
";",
"// populate it with scalar values from the passed definition structure",
"foreach",
"(",
"$",
"definition",
"as",
"$",
"prop",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"val",
")",
"or",
"is_object",
"(",
"$",
"val",
")",
")",
"{",
"// probably plugin's data",
"continue",
";",
"}",
"$",
"record",
"->",
"{",
"$",
"prop",
"}",
"=",
"$",
"val",
";",
"}",
"// make sure we do not override some crucial values by accident",
"if",
"(",
"!",
"empty",
"(",
"$",
"record",
"->",
"id",
")",
"and",
"$",
"record",
"->",
"id",
"!=",
"$",
"this",
"->",
"definition",
"->",
"id",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Attempting to update other definition record.'",
")",
";",
"}",
"$",
"record",
"->",
"id",
"=",
"$",
"this",
"->",
"definition",
"->",
"id",
";",
"unset",
"(",
"$",
"record",
"->",
"areaid",
")",
";",
"unset",
"(",
"$",
"record",
"->",
"method",
")",
";",
"unset",
"(",
"$",
"record",
"->",
"timecreated",
")",
";",
"// set the modification flags",
"$",
"record",
"->",
"timemodified",
"=",
"time",
"(",
")",
";",
"$",
"record",
"->",
"usermodified",
"=",
"$",
"usermodified",
";",
"$",
"DB",
"->",
"update_record",
"(",
"'grading_definitions'",
",",
"$",
"record",
")",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"definition",
"===",
"false",
")",
"{",
"// prepare a record to be inserted",
"$",
"record",
"=",
"new",
"stdClass",
"(",
")",
";",
"// populate it with scalar values from the passed definition structure",
"foreach",
"(",
"$",
"definition",
"as",
"$",
"prop",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"val",
")",
"or",
"is_object",
"(",
"$",
"val",
")",
")",
"{",
"// probably plugin's data",
"continue",
";",
"}",
"$",
"record",
"->",
"{",
"$",
"prop",
"}",
"=",
"$",
"val",
";",
"}",
"// make sure we do not override some crucial values by accident",
"if",
"(",
"!",
"empty",
"(",
"$",
"record",
"->",
"id",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Attempting to create a new record while there is already one existing.'",
")",
";",
"}",
"unset",
"(",
"$",
"record",
"->",
"id",
")",
";",
"$",
"record",
"->",
"areaid",
"=",
"$",
"this",
"->",
"areaid",
";",
"$",
"record",
"->",
"method",
"=",
"$",
"this",
"->",
"get_method_name",
"(",
")",
";",
"$",
"record",
"->",
"timecreated",
"=",
"time",
"(",
")",
";",
"$",
"record",
"->",
"usercreated",
"=",
"$",
"usermodified",
";",
"$",
"record",
"->",
"timemodified",
"=",
"$",
"record",
"->",
"timecreated",
";",
"$",
"record",
"->",
"usermodified",
"=",
"$",
"record",
"->",
"usercreated",
";",
"if",
"(",
"empty",
"(",
"$",
"record",
"->",
"status",
")",
")",
"{",
"$",
"record",
"->",
"status",
"=",
"self",
"::",
"DEFINITION_STATUS_DRAFT",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"record",
"->",
"descriptionformat",
")",
")",
"{",
"$",
"record",
"->",
"descriptionformat",
"=",
"FORMAT_MOODLE",
";",
"// field can not be empty",
"}",
"$",
"DB",
"->",
"insert_record",
"(",
"'grading_definitions'",
",",
"$",
"record",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Unknown status of the cached definition record.'",
")",
";",
"}",
"}"
] | Saves the defintion data into the database
The implementation in this base class stores the common data into the record
into the {grading_definition} table. The plugins are likely to extend this
and save their data into own tables, too.
@param stdClass $definition data containing values for the {grading_definition} table
@param int|null $usermodified optional userid of the author of the definition, defaults to the current user | [
"Saves",
"the",
"defintion",
"data",
"into",
"the",
"database"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/lib.php#L300-L366 |
212,410 | moodle/moodle | grade/grading/form/lib.php | gradingform_controller.has_active_instances | public function has_active_instances() {
global $DB;
if (empty($this->definition->id)) {
return false;
}
if ($this->hasactiveinstances === null) {
$conditions = array('definitionid' => $this->definition->id,
'status' => gradingform_instance::INSTANCE_STATUS_ACTIVE);
$this->hasactiveinstances = $DB->record_exists('grading_instances', $conditions);
}
return $this->hasactiveinstances;
} | php | public function has_active_instances() {
global $DB;
if (empty($this->definition->id)) {
return false;
}
if ($this->hasactiveinstances === null) {
$conditions = array('definitionid' => $this->definition->id,
'status' => gradingform_instance::INSTANCE_STATUS_ACTIVE);
$this->hasactiveinstances = $DB->record_exists('grading_instances', $conditions);
}
return $this->hasactiveinstances;
} | [
"public",
"function",
"has_active_instances",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"definition",
"->",
"id",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"hasactiveinstances",
"===",
"null",
")",
"{",
"$",
"conditions",
"=",
"array",
"(",
"'definitionid'",
"=>",
"$",
"this",
"->",
"definition",
"->",
"id",
",",
"'status'",
"=>",
"gradingform_instance",
"::",
"INSTANCE_STATUS_ACTIVE",
")",
";",
"$",
"this",
"->",
"hasactiveinstances",
"=",
"$",
"DB",
"->",
"record_exists",
"(",
"'grading_instances'",
",",
"$",
"conditions",
")",
";",
"}",
"return",
"$",
"this",
"->",
"hasactiveinstances",
";",
"}"
] | Returns true if there are already people who has been graded on this definition.
In this case plugins may restrict changes of the grading definition
@return boolean | [
"Returns",
"true",
"if",
"there",
"are",
"already",
"people",
"who",
"has",
"been",
"graded",
"on",
"this",
"definition",
".",
"In",
"this",
"case",
"plugins",
"may",
"restrict",
"changes",
"of",
"the",
"grading",
"definition"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/lib.php#L462-L473 |
212,411 | moodle/moodle | grade/grading/form/lib.php | gradingform_controller.get_or_create_instance | public function get_or_create_instance($instanceid, $raterid, $itemid) {
global $DB;
if ($instanceid &&
$instance = $DB->get_record('grading_instances', array('id' => $instanceid, 'raterid' => $raterid, 'itemid' => $itemid), '*', IGNORE_MISSING)) {
return $this->get_instance($instance);
}
return $this->create_instance($raterid, $itemid);
} | php | public function get_or_create_instance($instanceid, $raterid, $itemid) {
global $DB;
if ($instanceid &&
$instance = $DB->get_record('grading_instances', array('id' => $instanceid, 'raterid' => $raterid, 'itemid' => $itemid), '*', IGNORE_MISSING)) {
return $this->get_instance($instance);
}
return $this->create_instance($raterid, $itemid);
} | [
"public",
"function",
"get_or_create_instance",
"(",
"$",
"instanceid",
",",
"$",
"raterid",
",",
"$",
"itemid",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"$",
"instanceid",
"&&",
"$",
"instance",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'grading_instances'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"instanceid",
",",
"'raterid'",
"=>",
"$",
"raterid",
",",
"'itemid'",
"=>",
"$",
"itemid",
")",
",",
"'*'",
",",
"IGNORE_MISSING",
")",
")",
"{",
"return",
"$",
"this",
"->",
"get_instance",
"(",
"$",
"instance",
")",
";",
"}",
"return",
"$",
"this",
"->",
"create_instance",
"(",
"$",
"raterid",
",",
"$",
"itemid",
")",
";",
"}"
] | If instanceid is specified and grading instance exists and it is created by this rater for
this item, this instance is returned.
Otherwise new instance is created for the specified rater and itemid
@param int $instanceid
@param int $raterid
@param int $itemid
@return gradingform_instance | [
"If",
"instanceid",
"is",
"specified",
"and",
"grading",
"instance",
"exists",
"and",
"it",
"is",
"created",
"by",
"this",
"rater",
"for",
"this",
"item",
"this",
"instance",
"is",
"returned",
".",
"Otherwise",
"new",
"instance",
"is",
"created",
"for",
"the",
"specified",
"rater",
"and",
"itemid"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/lib.php#L525-L532 |
212,412 | moodle/moodle | grade/grading/form/lib.php | gradingform_controller.delete_definition | public function delete_definition() {
global $DB;
if (!$this->is_form_defined()) {
// nothing to do
return;
}
// firstly, let the plugin delete everything from their own tables
$this->delete_plugin_definition();
// then, delete all instances left
$DB->delete_records('grading_instances', array('definitionid' => $this->definition->id));
// finally, delete the main definition record
$DB->delete_records('grading_definitions', array('id' => $this->definition->id));
$this->definition = false;
} | php | public function delete_definition() {
global $DB;
if (!$this->is_form_defined()) {
// nothing to do
return;
}
// firstly, let the plugin delete everything from their own tables
$this->delete_plugin_definition();
// then, delete all instances left
$DB->delete_records('grading_instances', array('definitionid' => $this->definition->id));
// finally, delete the main definition record
$DB->delete_records('grading_definitions', array('id' => $this->definition->id));
$this->definition = false;
} | [
"public",
"function",
"delete_definition",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"is_form_defined",
"(",
")",
")",
"{",
"// nothing to do",
"return",
";",
"}",
"// firstly, let the plugin delete everything from their own tables",
"$",
"this",
"->",
"delete_plugin_definition",
"(",
")",
";",
"// then, delete all instances left",
"$",
"DB",
"->",
"delete_records",
"(",
"'grading_instances'",
",",
"array",
"(",
"'definitionid'",
"=>",
"$",
"this",
"->",
"definition",
"->",
"id",
")",
")",
";",
"// finally, delete the main definition record",
"$",
"DB",
"->",
"delete_records",
"(",
"'grading_definitions'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"definition",
"->",
"id",
")",
")",
";",
"$",
"this",
"->",
"definition",
"=",
"false",
";",
"}"
] | Deletes the form definition and all the associated data
@see delete_plugin_definition()
@return void | [
"Deletes",
"the",
"form",
"definition",
"and",
"all",
"the",
"associated",
"data"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/lib.php#L551-L567 |
212,413 | moodle/moodle | grade/grading/form/lib.php | gradingform_controller.load_definition | protected function load_definition() {
global $DB;
$this->definition = $DB->get_record('grading_definitions', array(
'areaid' => $this->areaid,
'method' => $this->get_method_name()), '*', IGNORE_MISSING);
} | php | protected function load_definition() {
global $DB;
$this->definition = $DB->get_record('grading_definitions', array(
'areaid' => $this->areaid,
'method' => $this->get_method_name()), '*', IGNORE_MISSING);
} | [
"protected",
"function",
"load_definition",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"this",
"->",
"definition",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'grading_definitions'",
",",
"array",
"(",
"'areaid'",
"=>",
"$",
"this",
"->",
"areaid",
",",
"'method'",
"=>",
"$",
"this",
"->",
"get_method_name",
"(",
")",
")",
",",
"'*'",
",",
"IGNORE_MISSING",
")",
";",
"}"
] | Loads the form definition if it exists
The default implementation just tries to load the record from the {grading_definitions}
table. The plugins are likely to override this with a more complex query that loads
all required data at once. | [
"Loads",
"the",
"form",
"definition",
"if",
"it",
"exists"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/lib.php#L606-L611 |
212,414 | moodle/moodle | grade/grading/form/lib.php | gradingform_controller.set_grade_range | public final function set_grade_range(array $graderange, $allowgradedecimals = false) {
$this->graderange = $graderange;
$this->allowgradedecimals = $allowgradedecimals;
} | php | public final function set_grade_range(array $graderange, $allowgradedecimals = false) {
$this->graderange = $graderange;
$this->allowgradedecimals = $allowgradedecimals;
} | [
"public",
"final",
"function",
"set_grade_range",
"(",
"array",
"$",
"graderange",
",",
"$",
"allowgradedecimals",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"graderange",
"=",
"$",
"graderange",
";",
"$",
"this",
"->",
"allowgradedecimals",
"=",
"$",
"allowgradedecimals",
";",
"}"
] | Sets the range of grades used in this area. This is usually either range like 0-100
or the scale where keys start from 1.
Typically modules will call it:
$controller->set_grade_range(make_grades_menu($gradingtype), $gradingtype > 0);
Negative $gradingtype means that scale is used and the grade must be rounded
to the nearest int. Positive $gradingtype means that range 0..$gradingtype
is used for the grades and in this case grade does not have to be rounded.
Sometimes modules always expect grade to be rounded (like mod_assignment does).
@param array $graderange array where first _key_ is the minimum grade and the
last key is the maximum grade.
@param bool $allowgradedecimals if decimal values are allowed as grades. | [
"Sets",
"the",
"range",
"of",
"grades",
"used",
"in",
"this",
"area",
".",
"This",
"is",
"usually",
"either",
"range",
"like",
"0",
"-",
"100",
"or",
"the",
"scale",
"where",
"keys",
"start",
"from",
"1",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/lib.php#L664-L667 |
212,415 | moodle/moodle | grade/grading/form/lib.php | gradingform_instance.create_new | public static function create_new($definitionid, $raterid, $itemid) {
global $DB;
$instance = new stdClass();
$instance->definitionid = $definitionid;
$instance->raterid = $raterid;
$instance->itemid = $itemid;
$instance->status = self::INSTANCE_STATUS_INCOMPLETE;
$instance->timemodified = time();
$instance->feedbackformat = FORMAT_MOODLE;
$instanceid = $DB->insert_record('grading_instances', $instance);
return $instanceid;
} | php | public static function create_new($definitionid, $raterid, $itemid) {
global $DB;
$instance = new stdClass();
$instance->definitionid = $definitionid;
$instance->raterid = $raterid;
$instance->itemid = $itemid;
$instance->status = self::INSTANCE_STATUS_INCOMPLETE;
$instance->timemodified = time();
$instance->feedbackformat = FORMAT_MOODLE;
$instanceid = $DB->insert_record('grading_instances', $instance);
return $instanceid;
} | [
"public",
"static",
"function",
"create_new",
"(",
"$",
"definitionid",
",",
"$",
"raterid",
",",
"$",
"itemid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"instance",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"instance",
"->",
"definitionid",
"=",
"$",
"definitionid",
";",
"$",
"instance",
"->",
"raterid",
"=",
"$",
"raterid",
";",
"$",
"instance",
"->",
"itemid",
"=",
"$",
"itemid",
";",
"$",
"instance",
"->",
"status",
"=",
"self",
"::",
"INSTANCE_STATUS_INCOMPLETE",
";",
"$",
"instance",
"->",
"timemodified",
"=",
"time",
"(",
")",
";",
"$",
"instance",
"->",
"feedbackformat",
"=",
"FORMAT_MOODLE",
";",
"$",
"instanceid",
"=",
"$",
"DB",
"->",
"insert_record",
"(",
"'grading_instances'",
",",
"$",
"instance",
")",
";",
"return",
"$",
"instanceid",
";",
"}"
] | Creates a new empty instance in DB and mark its status as INCOMPLETE
@param int $definitionid
@param int $raterid
@param int $itemid
@return int id of the created instance | [
"Creates",
"a",
"new",
"empty",
"instance",
"in",
"DB",
"and",
"mark",
"its",
"status",
"as",
"INCOMPLETE"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/lib.php#L786-L797 |
212,416 | moodle/moodle | search/engine/solr/classes/schema.php | schema.can_setup_server | public function can_setup_server() {
$status = $this->engine->is_server_configured();
if ($status !== true) {
return $status;
}
// At this stage we know that the server is properly configured with a valid host:port and indexname.
// We're not too concerned about repeating the SolrClient::system() call (already called in
// is_server_configured) because this is just a setup script.
if ($this->engine->get_solr_major_version() < 5) {
// Schema setup script only available for 5.0 onwards.
return get_string('schemasetupfromsolr5', 'search_solr');
}
return true;
} | php | public function can_setup_server() {
$status = $this->engine->is_server_configured();
if ($status !== true) {
return $status;
}
// At this stage we know that the server is properly configured with a valid host:port and indexname.
// We're not too concerned about repeating the SolrClient::system() call (already called in
// is_server_configured) because this is just a setup script.
if ($this->engine->get_solr_major_version() < 5) {
// Schema setup script only available for 5.0 onwards.
return get_string('schemasetupfromsolr5', 'search_solr');
}
return true;
} | [
"public",
"function",
"can_setup_server",
"(",
")",
"{",
"$",
"status",
"=",
"$",
"this",
"->",
"engine",
"->",
"is_server_configured",
"(",
")",
";",
"if",
"(",
"$",
"status",
"!==",
"true",
")",
"{",
"return",
"$",
"status",
";",
"}",
"// At this stage we know that the server is properly configured with a valid host:port and indexname.",
"// We're not too concerned about repeating the SolrClient::system() call (already called in",
"// is_server_configured) because this is just a setup script.",
"if",
"(",
"$",
"this",
"->",
"engine",
"->",
"get_solr_major_version",
"(",
")",
"<",
"5",
")",
"{",
"// Schema setup script only available for 5.0 onwards.",
"return",
"get_string",
"(",
"'schemasetupfromsolr5'",
",",
"'search_solr'",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Can setup be executed against the configured server.
@return true|string True or error message. | [
"Can",
"setup",
"be",
"executed",
"against",
"the",
"configured",
"server",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/engine/solr/classes/schema.php#L87-L103 |
212,417 | moodle/moodle | search/engine/solr/classes/schema.php | schema.setup | public function setup($checkexisting = true) {
$fields = \search_solr\document::get_default_fields_definition();
// Field id is already there.
unset($fields['id']);
$this->check_index();
$return = $this->add_fields($fields, $checkexisting);
// Tell the engine we are now using the latest schema version.
$this->engine->record_applied_schema_version(document::SCHEMA_VERSION);
return $return;
} | php | public function setup($checkexisting = true) {
$fields = \search_solr\document::get_default_fields_definition();
// Field id is already there.
unset($fields['id']);
$this->check_index();
$return = $this->add_fields($fields, $checkexisting);
// Tell the engine we are now using the latest schema version.
$this->engine->record_applied_schema_version(document::SCHEMA_VERSION);
return $return;
} | [
"public",
"function",
"setup",
"(",
"$",
"checkexisting",
"=",
"true",
")",
"{",
"$",
"fields",
"=",
"\\",
"search_solr",
"\\",
"document",
"::",
"get_default_fields_definition",
"(",
")",
";",
"// Field id is already there.",
"unset",
"(",
"$",
"fields",
"[",
"'id'",
"]",
")",
";",
"$",
"this",
"->",
"check_index",
"(",
")",
";",
"$",
"return",
"=",
"$",
"this",
"->",
"add_fields",
"(",
"$",
"fields",
",",
"$",
"checkexisting",
")",
";",
"// Tell the engine we are now using the latest schema version.",
"$",
"this",
"->",
"engine",
"->",
"record_applied_schema_version",
"(",
"document",
"::",
"SCHEMA_VERSION",
")",
";",
"return",
"$",
"return",
";",
"}"
] | Setup solr stuff required by moodle.
@param bool $checkexisting Whether to check if the fields already exist or not
@return bool | [
"Setup",
"solr",
"stuff",
"required",
"by",
"moodle",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/engine/solr/classes/schema.php#L111-L125 |
212,418 | moodle/moodle | search/engine/solr/classes/schema.php | schema.validate_setup | public function validate_setup() {
$fields = \search_solr\document::get_default_fields_definition();
// Field id is already there.
unset($fields['id']);
$this->check_index();
$this->validate_fields($fields, true);
} | php | public function validate_setup() {
$fields = \search_solr\document::get_default_fields_definition();
// Field id is already there.
unset($fields['id']);
$this->check_index();
$this->validate_fields($fields, true);
} | [
"public",
"function",
"validate_setup",
"(",
")",
"{",
"$",
"fields",
"=",
"\\",
"search_solr",
"\\",
"document",
"::",
"get_default_fields_definition",
"(",
")",
";",
"// Field id is already there.",
"unset",
"(",
"$",
"fields",
"[",
"'id'",
"]",
")",
";",
"$",
"this",
"->",
"check_index",
"(",
")",
";",
"$",
"this",
"->",
"validate_fields",
"(",
"$",
"fields",
",",
"true",
")",
";",
"}"
] | Checks the schema is properly set up.
@throws \moodle_exception
@return void | [
"Checks",
"the",
"schema",
"is",
"properly",
"set",
"up",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/engine/solr/classes/schema.php#L133-L141 |
212,419 | moodle/moodle | search/engine/solr/classes/schema.php | schema.check_index | protected function check_index() {
// Check that the server is available and the index exists.
$url = $this->engine->get_connection_url('/select?wt=json');
$result = $this->curl->get($url);
if ($this->curl->error) {
throw new \moodle_exception('connectionerror', 'search_solr');
}
if ($this->curl->info['http_code'] === 404) {
throw new \moodle_exception('connectionerror', 'search_solr');
}
} | php | protected function check_index() {
// Check that the server is available and the index exists.
$url = $this->engine->get_connection_url('/select?wt=json');
$result = $this->curl->get($url);
if ($this->curl->error) {
throw new \moodle_exception('connectionerror', 'search_solr');
}
if ($this->curl->info['http_code'] === 404) {
throw new \moodle_exception('connectionerror', 'search_solr');
}
} | [
"protected",
"function",
"check_index",
"(",
")",
"{",
"// Check that the server is available and the index exists.",
"$",
"url",
"=",
"$",
"this",
"->",
"engine",
"->",
"get_connection_url",
"(",
"'/select?wt=json'",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"curl",
"->",
"get",
"(",
"$",
"url",
")",
";",
"if",
"(",
"$",
"this",
"->",
"curl",
"->",
"error",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'connectionerror'",
",",
"'search_solr'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"curl",
"->",
"info",
"[",
"'http_code'",
"]",
"===",
"404",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'connectionerror'",
",",
"'search_solr'",
")",
";",
"}",
"}"
] | Checks if the index is ready, triggers an exception otherwise.
@throws \moodle_exception
@return void | [
"Checks",
"if",
"the",
"index",
"is",
"ready",
"triggers",
"an",
"exception",
"otherwise",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/engine/solr/classes/schema.php#L149-L160 |
212,420 | moodle/moodle | search/engine/solr/classes/schema.php | schema.add_fields | protected function add_fields($fields, $checkexisting = true) {
if ($checkexisting) {
// Check that non of them exists.
$this->validate_fields($fields, false);
}
$url = $this->engine->get_connection_url('/schema');
// Add all fields.
foreach ($fields as $fieldname => $data) {
if (!isset($data['type']) || !isset($data['stored']) || !isset($data['indexed'])) {
throw new \coding_exception($fieldname . ' does not define all required field params: type, stored and indexed.');
}
$type = $this->doc_field_to_solr_field($data['type']);
// Changing default multiValued value to false as we want to match values easily.
$params = array(
'add-field' => array(
'name' => $fieldname,
'type' => $type,
'stored' => $data['stored'],
'multiValued' => false,
'indexed' => $data['indexed']
)
);
$results = $this->curl->post($url, json_encode($params));
// We only validate if we are interested on it.
if ($checkexisting) {
if ($this->curl->error) {
throw new \moodle_exception('errorcreatingschema', 'search_solr', '', $this->curl->error);
}
$this->validate_add_field_result($results);
}
}
return true;
} | php | protected function add_fields($fields, $checkexisting = true) {
if ($checkexisting) {
// Check that non of them exists.
$this->validate_fields($fields, false);
}
$url = $this->engine->get_connection_url('/schema');
// Add all fields.
foreach ($fields as $fieldname => $data) {
if (!isset($data['type']) || !isset($data['stored']) || !isset($data['indexed'])) {
throw new \coding_exception($fieldname . ' does not define all required field params: type, stored and indexed.');
}
$type = $this->doc_field_to_solr_field($data['type']);
// Changing default multiValued value to false as we want to match values easily.
$params = array(
'add-field' => array(
'name' => $fieldname,
'type' => $type,
'stored' => $data['stored'],
'multiValued' => false,
'indexed' => $data['indexed']
)
);
$results = $this->curl->post($url, json_encode($params));
// We only validate if we are interested on it.
if ($checkexisting) {
if ($this->curl->error) {
throw new \moodle_exception('errorcreatingschema', 'search_solr', '', $this->curl->error);
}
$this->validate_add_field_result($results);
}
}
return true;
} | [
"protected",
"function",
"add_fields",
"(",
"$",
"fields",
",",
"$",
"checkexisting",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"checkexisting",
")",
"{",
"// Check that non of them exists.",
"$",
"this",
"->",
"validate_fields",
"(",
"$",
"fields",
",",
"false",
")",
";",
"}",
"$",
"url",
"=",
"$",
"this",
"->",
"engine",
"->",
"get_connection_url",
"(",
"'/schema'",
")",
";",
"// Add all fields.",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"fieldname",
"=>",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"'type'",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"data",
"[",
"'stored'",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"data",
"[",
"'indexed'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"$",
"fieldname",
".",
"' does not define all required field params: type, stored and indexed.'",
")",
";",
"}",
"$",
"type",
"=",
"$",
"this",
"->",
"doc_field_to_solr_field",
"(",
"$",
"data",
"[",
"'type'",
"]",
")",
";",
"// Changing default multiValued value to false as we want to match values easily.",
"$",
"params",
"=",
"array",
"(",
"'add-field'",
"=>",
"array",
"(",
"'name'",
"=>",
"$",
"fieldname",
",",
"'type'",
"=>",
"$",
"type",
",",
"'stored'",
"=>",
"$",
"data",
"[",
"'stored'",
"]",
",",
"'multiValued'",
"=>",
"false",
",",
"'indexed'",
"=>",
"$",
"data",
"[",
"'indexed'",
"]",
")",
")",
";",
"$",
"results",
"=",
"$",
"this",
"->",
"curl",
"->",
"post",
"(",
"$",
"url",
",",
"json_encode",
"(",
"$",
"params",
")",
")",
";",
"// We only validate if we are interested on it.",
"if",
"(",
"$",
"checkexisting",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"curl",
"->",
"error",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'errorcreatingschema'",
",",
"'search_solr'",
",",
"''",
",",
"$",
"this",
"->",
"curl",
"->",
"error",
")",
";",
"}",
"$",
"this",
"->",
"validate_add_field_result",
"(",
"$",
"results",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Adds the provided fields to Solr schema.
Intentionally separated from create(), it can be called to add extra fields.
fields separately.
@throws \coding_exception
@throws \moodle_exception
@param array $fields \core_search\document::$requiredfields format
@param bool $checkexisting Whether to check if the fields already exist or not
@return bool | [
"Adds",
"the",
"provided",
"fields",
"to",
"Solr",
"schema",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/engine/solr/classes/schema.php#L174-L213 |
212,421 | moodle/moodle | search/engine/solr/classes/schema.php | schema.validate_fields | protected function validate_fields(&$fields, $requireexisting = false) {
global $CFG;
foreach ($fields as $fieldname => $data) {
$url = $this->engine->get_connection_url('/schema/fields/' . $fieldname);
$results = $this->curl->get($url);
if ($this->curl->error) {
throw new \moodle_exception('errorcreatingschema', 'search_solr', '', $this->curl->error);
}
if (!$results) {
throw new \moodle_exception('errorcreatingschema', 'search_solr', '', get_string('nodatafromserver', 'search_solr'));
}
$results = json_decode($results);
if ($requireexisting && !empty($results->error) && $results->error->code === 404) {
$a = new \stdClass();
$a->fieldname = $fieldname;
$a->setupurl = $CFG->wwwroot . '/search/engine/solr/setup_schema.php';
throw new \moodle_exception('errorvalidatingschema', 'search_solr', '', $a);
}
// The field should not exist so we only accept 404 errors.
if (empty($results->error) || (!empty($results->error) && $results->error->code !== 404)) {
if (!empty($results->error)) {
throw new \moodle_exception('errorcreatingschema', 'search_solr', '', $results->error->msg);
} else {
// All these field attributes are set when fields are added through this script and should
// be returned and match the defined field's values.
$expectedsolrfield = $this->doc_field_to_solr_field($data['type']);
if (empty($results->field) || !isset($results->field->type) ||
!isset($results->field->multiValued) || !isset($results->field->indexed) ||
!isset($results->field->stored)) {
throw new \moodle_exception('errorcreatingschema', 'search_solr', '',
get_string('schemafieldautocreated', 'search_solr', $fieldname));
} else if ($results->field->type !== $expectedsolrfield ||
$results->field->multiValued !== false ||
$results->field->indexed !== $data['indexed'] ||
$results->field->stored !== $data['stored']) {
throw new \moodle_exception('errorcreatingschema', 'search_solr', '',
get_string('schemafieldautocreated', 'search_solr', $fieldname));
} else {
// The field already exists and it is properly defined, no need to create it.
unset($fields[$fieldname]);
}
}
}
}
} | php | protected function validate_fields(&$fields, $requireexisting = false) {
global $CFG;
foreach ($fields as $fieldname => $data) {
$url = $this->engine->get_connection_url('/schema/fields/' . $fieldname);
$results = $this->curl->get($url);
if ($this->curl->error) {
throw new \moodle_exception('errorcreatingschema', 'search_solr', '', $this->curl->error);
}
if (!$results) {
throw new \moodle_exception('errorcreatingschema', 'search_solr', '', get_string('nodatafromserver', 'search_solr'));
}
$results = json_decode($results);
if ($requireexisting && !empty($results->error) && $results->error->code === 404) {
$a = new \stdClass();
$a->fieldname = $fieldname;
$a->setupurl = $CFG->wwwroot . '/search/engine/solr/setup_schema.php';
throw new \moodle_exception('errorvalidatingschema', 'search_solr', '', $a);
}
// The field should not exist so we only accept 404 errors.
if (empty($results->error) || (!empty($results->error) && $results->error->code !== 404)) {
if (!empty($results->error)) {
throw new \moodle_exception('errorcreatingschema', 'search_solr', '', $results->error->msg);
} else {
// All these field attributes are set when fields are added through this script and should
// be returned and match the defined field's values.
$expectedsolrfield = $this->doc_field_to_solr_field($data['type']);
if (empty($results->field) || !isset($results->field->type) ||
!isset($results->field->multiValued) || !isset($results->field->indexed) ||
!isset($results->field->stored)) {
throw new \moodle_exception('errorcreatingschema', 'search_solr', '',
get_string('schemafieldautocreated', 'search_solr', $fieldname));
} else if ($results->field->type !== $expectedsolrfield ||
$results->field->multiValued !== false ||
$results->field->indexed !== $data['indexed'] ||
$results->field->stored !== $data['stored']) {
throw new \moodle_exception('errorcreatingschema', 'search_solr', '',
get_string('schemafieldautocreated', 'search_solr', $fieldname));
} else {
// The field already exists and it is properly defined, no need to create it.
unset($fields[$fieldname]);
}
}
}
}
} | [
"protected",
"function",
"validate_fields",
"(",
"&",
"$",
"fields",
",",
"$",
"requireexisting",
"=",
"false",
")",
"{",
"global",
"$",
"CFG",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"fieldname",
"=>",
"$",
"data",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"engine",
"->",
"get_connection_url",
"(",
"'/schema/fields/'",
".",
"$",
"fieldname",
")",
";",
"$",
"results",
"=",
"$",
"this",
"->",
"curl",
"->",
"get",
"(",
"$",
"url",
")",
";",
"if",
"(",
"$",
"this",
"->",
"curl",
"->",
"error",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'errorcreatingschema'",
",",
"'search_solr'",
",",
"''",
",",
"$",
"this",
"->",
"curl",
"->",
"error",
")",
";",
"}",
"if",
"(",
"!",
"$",
"results",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'errorcreatingschema'",
",",
"'search_solr'",
",",
"''",
",",
"get_string",
"(",
"'nodatafromserver'",
",",
"'search_solr'",
")",
")",
";",
"}",
"$",
"results",
"=",
"json_decode",
"(",
"$",
"results",
")",
";",
"if",
"(",
"$",
"requireexisting",
"&&",
"!",
"empty",
"(",
"$",
"results",
"->",
"error",
")",
"&&",
"$",
"results",
"->",
"error",
"->",
"code",
"===",
"404",
")",
"{",
"$",
"a",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"a",
"->",
"fieldname",
"=",
"$",
"fieldname",
";",
"$",
"a",
"->",
"setupurl",
"=",
"$",
"CFG",
"->",
"wwwroot",
".",
"'/search/engine/solr/setup_schema.php'",
";",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'errorvalidatingschema'",
",",
"'search_solr'",
",",
"''",
",",
"$",
"a",
")",
";",
"}",
"// The field should not exist so we only accept 404 errors.",
"if",
"(",
"empty",
"(",
"$",
"results",
"->",
"error",
")",
"||",
"(",
"!",
"empty",
"(",
"$",
"results",
"->",
"error",
")",
"&&",
"$",
"results",
"->",
"error",
"->",
"code",
"!==",
"404",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"results",
"->",
"error",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'errorcreatingschema'",
",",
"'search_solr'",
",",
"''",
",",
"$",
"results",
"->",
"error",
"->",
"msg",
")",
";",
"}",
"else",
"{",
"// All these field attributes are set when fields are added through this script and should",
"// be returned and match the defined field's values.",
"$",
"expectedsolrfield",
"=",
"$",
"this",
"->",
"doc_field_to_solr_field",
"(",
"$",
"data",
"[",
"'type'",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"results",
"->",
"field",
")",
"||",
"!",
"isset",
"(",
"$",
"results",
"->",
"field",
"->",
"type",
")",
"||",
"!",
"isset",
"(",
"$",
"results",
"->",
"field",
"->",
"multiValued",
")",
"||",
"!",
"isset",
"(",
"$",
"results",
"->",
"field",
"->",
"indexed",
")",
"||",
"!",
"isset",
"(",
"$",
"results",
"->",
"field",
"->",
"stored",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'errorcreatingschema'",
",",
"'search_solr'",
",",
"''",
",",
"get_string",
"(",
"'schemafieldautocreated'",
",",
"'search_solr'",
",",
"$",
"fieldname",
")",
")",
";",
"}",
"else",
"if",
"(",
"$",
"results",
"->",
"field",
"->",
"type",
"!==",
"$",
"expectedsolrfield",
"||",
"$",
"results",
"->",
"field",
"->",
"multiValued",
"!==",
"false",
"||",
"$",
"results",
"->",
"field",
"->",
"indexed",
"!==",
"$",
"data",
"[",
"'indexed'",
"]",
"||",
"$",
"results",
"->",
"field",
"->",
"stored",
"!==",
"$",
"data",
"[",
"'stored'",
"]",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'errorcreatingschema'",
",",
"'search_solr'",
",",
"''",
",",
"get_string",
"(",
"'schemafieldautocreated'",
",",
"'search_solr'",
",",
"$",
"fieldname",
")",
")",
";",
"}",
"else",
"{",
"// The field already exists and it is properly defined, no need to create it.",
"unset",
"(",
"$",
"fields",
"[",
"$",
"fieldname",
"]",
")",
";",
"}",
"}",
"}",
"}",
"}"
] | Checks if the schema existing fields are properly set, triggers an exception otherwise.
@throws \moodle_exception
@param array $fields
@param bool $requireexisting Require the fields to exist, otherwise exception.
@return void | [
"Checks",
"if",
"the",
"schema",
"existing",
"fields",
"are",
"properly",
"set",
"triggers",
"an",
"exception",
"otherwise",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/engine/solr/classes/schema.php#L223-L276 |
212,422 | moodle/moodle | search/engine/solr/classes/schema.php | schema.validate_add_field_result | protected function validate_add_field_result($result) {
if (!$result) {
throw new \moodle_exception('errorcreatingschema', 'search_solr', '', get_string('nodatafromserver', 'search_solr'));
}
$results = json_decode($result);
if (!$results) {
if (is_scalar($result)) {
$errormsg = $result;
} else {
$errormsg = json_encode($result);
}
throw new \moodle_exception('errorcreatingschema', 'search_solr', '', $errormsg);
}
// It comes as error when fetching fields data.
if (!empty($results->error)) {
throw new \moodle_exception('errorcreatingschema', 'search_solr', '', $results->error);
}
// It comes as errors when adding fields.
if (!empty($results->errors)) {
// We treat this error separately.
$errorstr = '';
foreach ($results->errors as $error) {
$errorstr .= implode(', ', $error->errorMessages);
}
throw new \moodle_exception('errorcreatingschema', 'search_solr', '', $errorstr);
}
} | php | protected function validate_add_field_result($result) {
if (!$result) {
throw new \moodle_exception('errorcreatingschema', 'search_solr', '', get_string('nodatafromserver', 'search_solr'));
}
$results = json_decode($result);
if (!$results) {
if (is_scalar($result)) {
$errormsg = $result;
} else {
$errormsg = json_encode($result);
}
throw new \moodle_exception('errorcreatingschema', 'search_solr', '', $errormsg);
}
// It comes as error when fetching fields data.
if (!empty($results->error)) {
throw new \moodle_exception('errorcreatingschema', 'search_solr', '', $results->error);
}
// It comes as errors when adding fields.
if (!empty($results->errors)) {
// We treat this error separately.
$errorstr = '';
foreach ($results->errors as $error) {
$errorstr .= implode(', ', $error->errorMessages);
}
throw new \moodle_exception('errorcreatingschema', 'search_solr', '', $errorstr);
}
} | [
"protected",
"function",
"validate_add_field_result",
"(",
"$",
"result",
")",
"{",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'errorcreatingschema'",
",",
"'search_solr'",
",",
"''",
",",
"get_string",
"(",
"'nodatafromserver'",
",",
"'search_solr'",
")",
")",
";",
"}",
"$",
"results",
"=",
"json_decode",
"(",
"$",
"result",
")",
";",
"if",
"(",
"!",
"$",
"results",
")",
"{",
"if",
"(",
"is_scalar",
"(",
"$",
"result",
")",
")",
"{",
"$",
"errormsg",
"=",
"$",
"result",
";",
"}",
"else",
"{",
"$",
"errormsg",
"=",
"json_encode",
"(",
"$",
"result",
")",
";",
"}",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'errorcreatingschema'",
",",
"'search_solr'",
",",
"''",
",",
"$",
"errormsg",
")",
";",
"}",
"// It comes as error when fetching fields data.",
"if",
"(",
"!",
"empty",
"(",
"$",
"results",
"->",
"error",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'errorcreatingschema'",
",",
"'search_solr'",
",",
"''",
",",
"$",
"results",
"->",
"error",
")",
";",
"}",
"// It comes as errors when adding fields.",
"if",
"(",
"!",
"empty",
"(",
"$",
"results",
"->",
"errors",
")",
")",
"{",
"// We treat this error separately.",
"$",
"errorstr",
"=",
"''",
";",
"foreach",
"(",
"$",
"results",
"->",
"errors",
"as",
"$",
"error",
")",
"{",
"$",
"errorstr",
".=",
"implode",
"(",
"', '",
",",
"$",
"error",
"->",
"errorMessages",
")",
";",
"}",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'errorcreatingschema'",
",",
"'search_solr'",
",",
"''",
",",
"$",
"errorstr",
")",
";",
"}",
"}"
] | Checks that the field results do not contain errors.
@throws \moodle_exception
@param string $results curl response body
@return void | [
"Checks",
"that",
"the",
"field",
"results",
"do",
"not",
"contain",
"errors",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/engine/solr/classes/schema.php#L285-L317 |
212,423 | moodle/moodle | search/engine/solr/classes/schema.php | schema.doc_field_to_solr_field | private function doc_field_to_solr_field($datatype) {
$type = $datatype;
$solrversion = $this->engine->get_solr_major_version();
switch($datatype) {
case 'text':
$type = 'text_general';
break;
case 'int':
if ($solrversion >= 7) {
$type = 'pint';
}
break;
case 'tdate':
if ($solrversion >= 7) {
$type = 'pdate';
}
break;
}
return $type;
} | php | private function doc_field_to_solr_field($datatype) {
$type = $datatype;
$solrversion = $this->engine->get_solr_major_version();
switch($datatype) {
case 'text':
$type = 'text_general';
break;
case 'int':
if ($solrversion >= 7) {
$type = 'pint';
}
break;
case 'tdate':
if ($solrversion >= 7) {
$type = 'pdate';
}
break;
}
return $type;
} | [
"private",
"function",
"doc_field_to_solr_field",
"(",
"$",
"datatype",
")",
"{",
"$",
"type",
"=",
"$",
"datatype",
";",
"$",
"solrversion",
"=",
"$",
"this",
"->",
"engine",
"->",
"get_solr_major_version",
"(",
")",
";",
"switch",
"(",
"$",
"datatype",
")",
"{",
"case",
"'text'",
":",
"$",
"type",
"=",
"'text_general'",
";",
"break",
";",
"case",
"'int'",
":",
"if",
"(",
"$",
"solrversion",
">=",
"7",
")",
"{",
"$",
"type",
"=",
"'pint'",
";",
"}",
"break",
";",
"case",
"'tdate'",
":",
"if",
"(",
"$",
"solrversion",
">=",
"7",
")",
"{",
"$",
"type",
"=",
"'pdate'",
";",
"}",
"break",
";",
"}",
"return",
"$",
"type",
";",
"}"
] | Returns the solr field type from the document field type string.
@param string $datatype
@return string | [
"Returns",
"the",
"solr",
"field",
"type",
"from",
"the",
"document",
"field",
"type",
"string",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/engine/solr/classes/schema.php#L325-L347 |
212,424 | moodle/moodle | lib/scssphp/Node/Number.php | Number.coerce | public function coerce($units)
{
if ($this->unitless()) {
return new Number($this->dimension, $units);
}
$dimension = $this->dimension;
foreach (static::$unitTable['in'] as $unit => $conv) {
$from = isset($this->units[$unit]) ? $this->units[$unit] : 0;
$to = isset($units[$unit]) ? $units[$unit] : 0;
$factor = pow($conv, $from - $to);
$dimension /= $factor;
}
return new Number($dimension, $units);
} | php | public function coerce($units)
{
if ($this->unitless()) {
return new Number($this->dimension, $units);
}
$dimension = $this->dimension;
foreach (static::$unitTable['in'] as $unit => $conv) {
$from = isset($this->units[$unit]) ? $this->units[$unit] : 0;
$to = isset($units[$unit]) ? $units[$unit] : 0;
$factor = pow($conv, $from - $to);
$dimension /= $factor;
}
return new Number($dimension, $units);
} | [
"public",
"function",
"coerce",
"(",
"$",
"units",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"unitless",
"(",
")",
")",
"{",
"return",
"new",
"Number",
"(",
"$",
"this",
"->",
"dimension",
",",
"$",
"units",
")",
";",
"}",
"$",
"dimension",
"=",
"$",
"this",
"->",
"dimension",
";",
"foreach",
"(",
"static",
"::",
"$",
"unitTable",
"[",
"'in'",
"]",
"as",
"$",
"unit",
"=>",
"$",
"conv",
")",
"{",
"$",
"from",
"=",
"isset",
"(",
"$",
"this",
"->",
"units",
"[",
"$",
"unit",
"]",
")",
"?",
"$",
"this",
"->",
"units",
"[",
"$",
"unit",
"]",
":",
"0",
";",
"$",
"to",
"=",
"isset",
"(",
"$",
"units",
"[",
"$",
"unit",
"]",
")",
"?",
"$",
"units",
"[",
"$",
"unit",
"]",
":",
"0",
";",
"$",
"factor",
"=",
"pow",
"(",
"$",
"conv",
",",
"$",
"from",
"-",
"$",
"to",
")",
";",
"$",
"dimension",
"/=",
"$",
"factor",
";",
"}",
"return",
"new",
"Number",
"(",
"$",
"dimension",
",",
"$",
"units",
")",
";",
"}"
] | Coerce number to target units
@param array $units
@return \Leafo\ScssPhp\Node\Number | [
"Coerce",
"number",
"to",
"target",
"units"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Node/Number.php#L105-L121 |
212,425 | moodle/moodle | question/classes/statistics/responses/analysis_for_class.php | analysis_for_class.count_response | public function count_response($actualresponse, $fraction, $try) {
if (!isset($this->actualresponses[$actualresponse])) {
if ($fraction === null) {
$fraction = $this->fraction;
}
$this->add_response($actualresponse, $fraction);
}
$this->get_response($actualresponse)->increment_count($try);
} | php | public function count_response($actualresponse, $fraction, $try) {
if (!isset($this->actualresponses[$actualresponse])) {
if ($fraction === null) {
$fraction = $this->fraction;
}
$this->add_response($actualresponse, $fraction);
}
$this->get_response($actualresponse)->increment_count($try);
} | [
"public",
"function",
"count_response",
"(",
"$",
"actualresponse",
",",
"$",
"fraction",
",",
"$",
"try",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"actualresponses",
"[",
"$",
"actualresponse",
"]",
")",
")",
"{",
"if",
"(",
"$",
"fraction",
"===",
"null",
")",
"{",
"$",
"fraction",
"=",
"$",
"this",
"->",
"fraction",
";",
"}",
"$",
"this",
"->",
"add_response",
"(",
"$",
"actualresponse",
",",
"$",
"fraction",
")",
";",
"}",
"$",
"this",
"->",
"get_response",
"(",
"$",
"actualresponse",
")",
"->",
"increment_count",
"(",
"$",
"try",
")",
";",
"}"
] | Keep a count of a response to this question sub part that falls within this class.
@param string $actualresponse
@param float|null $fraction
@param int $try
@return \core_question\statistics\responses\analysis_for_actual_response | [
"Keep",
"a",
"count",
"of",
"a",
"response",
"to",
"this",
"question",
"sub",
"part",
"that",
"falls",
"within",
"this",
"class",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/responses/analysis_for_class.php#L88-L96 |
212,426 | moodle/moodle | question/classes/statistics/responses/analysis_for_class.php | analysis_for_class.has_actual_responses | public function has_actual_responses() {
$actualresponses = $this->get_responses();
if (count($actualresponses) > 1) {
return true;
} else if (count($actualresponses) === 1) {
$singleactualresponse = reset($actualresponses);
return (string)$singleactualresponse !== (string)$this->modelresponse;
}
return false;
} | php | public function has_actual_responses() {
$actualresponses = $this->get_responses();
if (count($actualresponses) > 1) {
return true;
} else if (count($actualresponses) === 1) {
$singleactualresponse = reset($actualresponses);
return (string)$singleactualresponse !== (string)$this->modelresponse;
}
return false;
} | [
"public",
"function",
"has_actual_responses",
"(",
")",
"{",
"$",
"actualresponses",
"=",
"$",
"this",
"->",
"get_responses",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"actualresponses",
")",
">",
"1",
")",
"{",
"return",
"true",
";",
"}",
"else",
"if",
"(",
"count",
"(",
"$",
"actualresponses",
")",
"===",
"1",
")",
"{",
"$",
"singleactualresponse",
"=",
"reset",
"(",
"$",
"actualresponses",
")",
";",
"return",
"(",
"string",
")",
"$",
"singleactualresponse",
"!==",
"(",
"string",
")",
"$",
"this",
"->",
"modelresponse",
";",
"}",
"return",
"false",
";",
"}"
] | Are there actual responses to sub parts that where classified into this class?
@return bool whether this analysis has a response class with more than one
different actual response, or if the actual response is different from
the model response. | [
"Are",
"there",
"actual",
"responses",
"to",
"sub",
"parts",
"that",
"where",
"classified",
"into",
"this",
"class?"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/responses/analysis_for_class.php#L142-L151 |
212,427 | moodle/moodle | question/classes/statistics/responses/analysis_for_class.php | analysis_for_class.data_for_question_response_table | public function data_for_question_response_table($responseclasscolumn, $partid) {
$return = array();
if (count($this->get_responses()) == 0) {
$rowdata = new \stdClass();
$rowdata->part = $partid;
$rowdata->responseclass = $this->modelresponse;
if (!$responseclasscolumn) {
$rowdata->response = $this->modelresponse;
} else {
$rowdata->response = '';
}
$rowdata->fraction = $this->fraction;
$rowdata->totalcount = 0;
$rowdata->trycount = array();
$return[] = $rowdata;
} else {
foreach ($this->get_responses() as $actualresponse) {
$response = $this->get_response($actualresponse);
$return[] = $response->data_for_question_response_table($partid, $this->modelresponse);
}
}
return $return;
} | php | public function data_for_question_response_table($responseclasscolumn, $partid) {
$return = array();
if (count($this->get_responses()) == 0) {
$rowdata = new \stdClass();
$rowdata->part = $partid;
$rowdata->responseclass = $this->modelresponse;
if (!$responseclasscolumn) {
$rowdata->response = $this->modelresponse;
} else {
$rowdata->response = '';
}
$rowdata->fraction = $this->fraction;
$rowdata->totalcount = 0;
$rowdata->trycount = array();
$return[] = $rowdata;
} else {
foreach ($this->get_responses() as $actualresponse) {
$response = $this->get_response($actualresponse);
$return[] = $response->data_for_question_response_table($partid, $this->modelresponse);
}
}
return $return;
} | [
"public",
"function",
"data_for_question_response_table",
"(",
"$",
"responseclasscolumn",
",",
"$",
"partid",
")",
"{",
"$",
"return",
"=",
"array",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"get_responses",
"(",
")",
")",
"==",
"0",
")",
"{",
"$",
"rowdata",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"rowdata",
"->",
"part",
"=",
"$",
"partid",
";",
"$",
"rowdata",
"->",
"responseclass",
"=",
"$",
"this",
"->",
"modelresponse",
";",
"if",
"(",
"!",
"$",
"responseclasscolumn",
")",
"{",
"$",
"rowdata",
"->",
"response",
"=",
"$",
"this",
"->",
"modelresponse",
";",
"}",
"else",
"{",
"$",
"rowdata",
"->",
"response",
"=",
"''",
";",
"}",
"$",
"rowdata",
"->",
"fraction",
"=",
"$",
"this",
"->",
"fraction",
";",
"$",
"rowdata",
"->",
"totalcount",
"=",
"0",
";",
"$",
"rowdata",
"->",
"trycount",
"=",
"array",
"(",
")",
";",
"$",
"return",
"[",
"]",
"=",
"$",
"rowdata",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"this",
"->",
"get_responses",
"(",
")",
"as",
"$",
"actualresponse",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"get_response",
"(",
"$",
"actualresponse",
")",
";",
"$",
"return",
"[",
"]",
"=",
"$",
"response",
"->",
"data_for_question_response_table",
"(",
"$",
"partid",
",",
"$",
"this",
"->",
"modelresponse",
")",
";",
"}",
"}",
"return",
"$",
"return",
";",
"}"
] | Return the data to display in the response analysis table.
@param bool $responseclasscolumn
@param string $partid
@return object[] | [
"Return",
"the",
"data",
"to",
"display",
"in",
"the",
"response",
"analysis",
"table",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/responses/analysis_for_class.php#L160-L182 |
212,428 | moodle/moodle | question/classes/statistics/responses/analysis_for_class.php | analysis_for_class.get_maximum_tries | public function get_maximum_tries() {
$max = 1;
foreach ($this->get_responses() as $actualresponse) {
$max = max($max, $this->get_response($actualresponse)->get_maximum_tries());
}
return $max;
} | php | public function get_maximum_tries() {
$max = 1;
foreach ($this->get_responses() as $actualresponse) {
$max = max($max, $this->get_response($actualresponse)->get_maximum_tries());
}
return $max;
} | [
"public",
"function",
"get_maximum_tries",
"(",
")",
"{",
"$",
"max",
"=",
"1",
";",
"foreach",
"(",
"$",
"this",
"->",
"get_responses",
"(",
")",
"as",
"$",
"actualresponse",
")",
"{",
"$",
"max",
"=",
"max",
"(",
"$",
"max",
",",
"$",
"this",
"->",
"get_response",
"(",
"$",
"actualresponse",
")",
"->",
"get_maximum_tries",
"(",
")",
")",
";",
"}",
"return",
"$",
"max",
";",
"}"
] | What is the highest try number that an actual response of this response class has been seen?
@return int try number | [
"What",
"is",
"the",
"highest",
"try",
"number",
"that",
"an",
"actual",
"response",
"of",
"this",
"response",
"class",
"has",
"been",
"seen?"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/responses/analysis_for_class.php#L189-L195 |
212,429 | moodle/moodle | lib/adodb/drivers/adodb-odbc_mssql.inc.php | ADODB_odbc_mssql.ServerInfo | function ServerInfo()
{
global $ADODB_FETCH_MODE;
$save = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
$row = $this->GetRow("execute sp_server_info 2");
$ADODB_FETCH_MODE = $save;
if (!is_array($row)) return false;
$arr['description'] = $row[2];
$arr['version'] = ADOConnection::_findvers($arr['description']);
return $arr;
} | php | function ServerInfo()
{
global $ADODB_FETCH_MODE;
$save = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = ADODB_FETCH_NUM;
$row = $this->GetRow("execute sp_server_info 2");
$ADODB_FETCH_MODE = $save;
if (!is_array($row)) return false;
$arr['description'] = $row[2];
$arr['version'] = ADOConnection::_findvers($arr['description']);
return $arr;
} | [
"function",
"ServerInfo",
"(",
")",
"{",
"global",
"$",
"ADODB_FETCH_MODE",
";",
"$",
"save",
"=",
"$",
"ADODB_FETCH_MODE",
";",
"$",
"ADODB_FETCH_MODE",
"=",
"ADODB_FETCH_NUM",
";",
"$",
"row",
"=",
"$",
"this",
"->",
"GetRow",
"(",
"\"execute sp_server_info 2\"",
")",
";",
"$",
"ADODB_FETCH_MODE",
"=",
"$",
"save",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"row",
")",
")",
"return",
"false",
";",
"$",
"arr",
"[",
"'description'",
"]",
"=",
"$",
"row",
"[",
"2",
"]",
";",
"$",
"arr",
"[",
"'version'",
"]",
"=",
"ADOConnection",
"::",
"_findvers",
"(",
"$",
"arr",
"[",
"'description'",
"]",
")",
";",
"return",
"$",
"arr",
";",
"}"
] | crashes php... | [
"crashes",
"php",
"..."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/drivers/adodb-odbc_mssql.inc.php#L57-L68 |
212,430 | moodle/moodle | backup/moodle2/restore_settingslib.php | restore_course_defaultcustom_setting.get_normalized_value | public function get_normalized_value() {
$value = $this->get_value();
if ($value === false && $this->get_ui() instanceof backup_setting_ui_defaultcustom) {
$attributes = $this->get_ui()->get_attributes();
return $attributes['defaultvalue'];
}
return $value;
} | php | public function get_normalized_value() {
$value = $this->get_value();
if ($value === false && $this->get_ui() instanceof backup_setting_ui_defaultcustom) {
$attributes = $this->get_ui()->get_attributes();
return $attributes['defaultvalue'];
}
return $value;
} | [
"public",
"function",
"get_normalized_value",
"(",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"get_value",
"(",
")",
";",
"if",
"(",
"$",
"value",
"===",
"false",
"&&",
"$",
"this",
"->",
"get_ui",
"(",
")",
"instanceof",
"backup_setting_ui_defaultcustom",
")",
"{",
"$",
"attributes",
"=",
"$",
"this",
"->",
"get_ui",
"(",
")",
"->",
"get_attributes",
"(",
")",
";",
"return",
"$",
"attributes",
"[",
"'defaultvalue'",
"]",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Special method for this element only. When value is "false" returns the default value.
@return mixed | [
"Special",
"method",
"for",
"this",
"element",
"only",
".",
"When",
"value",
"is",
"false",
"returns",
"the",
"default",
"value",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/moodle2/restore_settingslib.php#L180-L187 |
212,431 | moodle/moodle | lib/horde/framework/Horde/Imap/Client/Exception.php | Horde_Imap_Client_Exception.messagePrintf | public function messagePrintf(array $args = array())
{
$this->raw_msg = vsprintf($this->raw_msg, $args);
$this->message = vsprintf($this->message, $args);
} | php | public function messagePrintf(array $args = array())
{
$this->raw_msg = vsprintf($this->raw_msg, $args);
$this->message = vsprintf($this->message, $args);
} | [
"public",
"function",
"messagePrintf",
"(",
"array",
"$",
"args",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"raw_msg",
"=",
"vsprintf",
"(",
"$",
"this",
"->",
"raw_msg",
",",
"$",
"args",
")",
";",
"$",
"this",
"->",
"message",
"=",
"vsprintf",
"(",
"$",
"this",
"->",
"message",
",",
"$",
"args",
")",
";",
"}"
] | Perform substitution of variables in the error message.
Needed to allow for correct translation of error message.
@since 2.22.0
@param array $args Arguments used for substitution. | [
"Perform",
"substitution",
"of",
"variables",
"in",
"the",
"error",
"message",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Exception.php#L297-L301 |
212,432 | moodle/moodle | auth/cas/CAS/CAS.php | phpCAS.client | public static function client($server_version, $server_hostname,
$server_port, $server_uri, $changeSessionID = true
) {
phpCAS :: traceBegin();
if (is_object(self::$_PHPCAS_CLIENT)) {
phpCAS :: error(self::$_PHPCAS_INIT_CALL['method'] . '() has already been called (at ' . self::$_PHPCAS_INIT_CALL['file'] . ':' . self::$_PHPCAS_INIT_CALL['line'] . ')');
}
// store where the initializer is called from
$dbg = debug_backtrace();
self::$_PHPCAS_INIT_CALL = array (
'done' => true,
'file' => $dbg[0]['file'],
'line' => $dbg[0]['line'],
'method' => __CLASS__ . '::' . __FUNCTION__
);
// initialize the object $_PHPCAS_CLIENT
try {
self::$_PHPCAS_CLIENT = new CAS_Client(
$server_version, false, $server_hostname, $server_port, $server_uri,
$changeSessionID
);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
phpCAS :: traceEnd();
} | php | public static function client($server_version, $server_hostname,
$server_port, $server_uri, $changeSessionID = true
) {
phpCAS :: traceBegin();
if (is_object(self::$_PHPCAS_CLIENT)) {
phpCAS :: error(self::$_PHPCAS_INIT_CALL['method'] . '() has already been called (at ' . self::$_PHPCAS_INIT_CALL['file'] . ':' . self::$_PHPCAS_INIT_CALL['line'] . ')');
}
// store where the initializer is called from
$dbg = debug_backtrace();
self::$_PHPCAS_INIT_CALL = array (
'done' => true,
'file' => $dbg[0]['file'],
'line' => $dbg[0]['line'],
'method' => __CLASS__ . '::' . __FUNCTION__
);
// initialize the object $_PHPCAS_CLIENT
try {
self::$_PHPCAS_CLIENT = new CAS_Client(
$server_version, false, $server_hostname, $server_port, $server_uri,
$changeSessionID
);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
phpCAS :: traceEnd();
} | [
"public",
"static",
"function",
"client",
"(",
"$",
"server_version",
",",
"$",
"server_hostname",
",",
"$",
"server_port",
",",
"$",
"server_uri",
",",
"$",
"changeSessionID",
"=",
"true",
")",
"{",
"phpCAS",
"::",
"traceBegin",
"(",
")",
";",
"if",
"(",
"is_object",
"(",
"self",
"::",
"$",
"_PHPCAS_CLIENT",
")",
")",
"{",
"phpCAS",
"::",
"error",
"(",
"self",
"::",
"$",
"_PHPCAS_INIT_CALL",
"[",
"'method'",
"]",
".",
"'() has already been called (at '",
".",
"self",
"::",
"$",
"_PHPCAS_INIT_CALL",
"[",
"'file'",
"]",
".",
"':'",
".",
"self",
"::",
"$",
"_PHPCAS_INIT_CALL",
"[",
"'line'",
"]",
".",
"')'",
")",
";",
"}",
"// store where the initializer is called from",
"$",
"dbg",
"=",
"debug_backtrace",
"(",
")",
";",
"self",
"::",
"$",
"_PHPCAS_INIT_CALL",
"=",
"array",
"(",
"'done'",
"=>",
"true",
",",
"'file'",
"=>",
"$",
"dbg",
"[",
"0",
"]",
"[",
"'file'",
"]",
",",
"'line'",
"=>",
"$",
"dbg",
"[",
"0",
"]",
"[",
"'line'",
"]",
",",
"'method'",
"=>",
"__CLASS__",
".",
"'::'",
".",
"__FUNCTION__",
")",
";",
"// initialize the object $_PHPCAS_CLIENT",
"try",
"{",
"self",
"::",
"$",
"_PHPCAS_CLIENT",
"=",
"new",
"CAS_Client",
"(",
"$",
"server_version",
",",
"false",
",",
"$",
"server_hostname",
",",
"$",
"server_port",
",",
"$",
"server_uri",
",",
"$",
"changeSessionID",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"phpCAS",
"::",
"error",
"(",
"get_class",
"(",
"$",
"e",
")",
".",
"': '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"phpCAS",
"::",
"traceEnd",
"(",
")",
";",
"}"
] | phpCAS client initializer.
@param string $server_version the version of the CAS server
@param string $server_hostname the hostname of the CAS server
@param string $server_port the port the CAS server is running on
@param string $server_uri the URI the CAS server is responding on
@param bool $changeSessionID Allow phpCAS to change the session_id (Single
Sign Out/handleLogoutRequests is based on that change)
@return a newly created CAS_Client object
@note Only one of the phpCAS::client() and phpCAS::proxy functions should be
called, only once, and before all other methods (except phpCAS::getVersion()
and phpCAS::setDebug()). | [
"phpCAS",
"client",
"initializer",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS.php#L338-L365 |
212,433 | moodle/moodle | auth/cas/CAS/CAS.php | phpCAS.setVerbose | public static function setVerbose($verbose)
{
if ($verbose === true) {
self::$_PHPCAS_VERBOSE = true;
} else {
self::$_PHPCAS_VERBOSE = false;
}
} | php | public static function setVerbose($verbose)
{
if ($verbose === true) {
self::$_PHPCAS_VERBOSE = true;
} else {
self::$_PHPCAS_VERBOSE = false;
}
} | [
"public",
"static",
"function",
"setVerbose",
"(",
"$",
"verbose",
")",
"{",
"if",
"(",
"$",
"verbose",
"===",
"true",
")",
"{",
"self",
"::",
"$",
"_PHPCAS_VERBOSE",
"=",
"true",
";",
"}",
"else",
"{",
"self",
"::",
"$",
"_PHPCAS_VERBOSE",
"=",
"false",
";",
"}",
"}"
] | Enable verbose errors messages in the website output
This is a security relevant since internal status info may leak an may
help an attacker. Default is therefore false
@param bool $verbose enable verbose output
@return void | [
"Enable",
"verbose",
"errors",
"messages",
"in",
"the",
"website",
"output",
"This",
"is",
"a",
"security",
"relevant",
"since",
"internal",
"status",
"info",
"may",
"leak",
"an",
"may",
"help",
"an",
"attacker",
".",
"Default",
"is",
"therefore",
"false"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS.php#L481-L488 |
212,434 | moodle/moodle | auth/cas/CAS/CAS.php | phpCAS.log | public static function log($str)
{
$indent_str = ".";
if (!empty(self::$_PHPCAS_DEBUG['filename'])) {
// Check if file exists and modifiy file permissions to be only
// readable by the webserver
if (!file_exists(self::$_PHPCAS_DEBUG['filename'])) {
touch(self::$_PHPCAS_DEBUG['filename']);
// Chmod will fail on windows
@chmod(self::$_PHPCAS_DEBUG['filename'], 0600);
}
for ($i = 0; $i < self::$_PHPCAS_DEBUG['indent']; $i++) {
$indent_str .= '| ';
}
// allow for multiline output with proper identing. Usefull for
// dumping cas answers etc.
$str2 = str_replace("\n", "\n" . self::$_PHPCAS_DEBUG['unique_id'] . ' ' . $indent_str, $str);
error_log(self::$_PHPCAS_DEBUG['unique_id'] . ' ' . $indent_str . $str2 . "\n", 3, self::$_PHPCAS_DEBUG['filename']);
}
} | php | public static function log($str)
{
$indent_str = ".";
if (!empty(self::$_PHPCAS_DEBUG['filename'])) {
// Check if file exists and modifiy file permissions to be only
// readable by the webserver
if (!file_exists(self::$_PHPCAS_DEBUG['filename'])) {
touch(self::$_PHPCAS_DEBUG['filename']);
// Chmod will fail on windows
@chmod(self::$_PHPCAS_DEBUG['filename'], 0600);
}
for ($i = 0; $i < self::$_PHPCAS_DEBUG['indent']; $i++) {
$indent_str .= '| ';
}
// allow for multiline output with proper identing. Usefull for
// dumping cas answers etc.
$str2 = str_replace("\n", "\n" . self::$_PHPCAS_DEBUG['unique_id'] . ' ' . $indent_str, $str);
error_log(self::$_PHPCAS_DEBUG['unique_id'] . ' ' . $indent_str . $str2 . "\n", 3, self::$_PHPCAS_DEBUG['filename']);
}
} | [
"public",
"static",
"function",
"log",
"(",
"$",
"str",
")",
"{",
"$",
"indent_str",
"=",
"\".\"",
";",
"if",
"(",
"!",
"empty",
"(",
"self",
"::",
"$",
"_PHPCAS_DEBUG",
"[",
"'filename'",
"]",
")",
")",
"{",
"// Check if file exists and modifiy file permissions to be only",
"// readable by the webserver",
"if",
"(",
"!",
"file_exists",
"(",
"self",
"::",
"$",
"_PHPCAS_DEBUG",
"[",
"'filename'",
"]",
")",
")",
"{",
"touch",
"(",
"self",
"::",
"$",
"_PHPCAS_DEBUG",
"[",
"'filename'",
"]",
")",
";",
"// Chmod will fail on windows",
"@",
"chmod",
"(",
"self",
"::",
"$",
"_PHPCAS_DEBUG",
"[",
"'filename'",
"]",
",",
"0600",
")",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"self",
"::",
"$",
"_PHPCAS_DEBUG",
"[",
"'indent'",
"]",
";",
"$",
"i",
"++",
")",
"{",
"$",
"indent_str",
".=",
"'| '",
";",
"}",
"// allow for multiline output with proper identing. Usefull for",
"// dumping cas answers etc.",
"$",
"str2",
"=",
"str_replace",
"(",
"\"\\n\"",
",",
"\"\\n\"",
".",
"self",
"::",
"$",
"_PHPCAS_DEBUG",
"[",
"'unique_id'",
"]",
".",
"' '",
".",
"$",
"indent_str",
",",
"$",
"str",
")",
";",
"error_log",
"(",
"self",
"::",
"$",
"_PHPCAS_DEBUG",
"[",
"'unique_id'",
"]",
".",
"' '",
".",
"$",
"indent_str",
".",
"$",
"str2",
".",
"\"\\n\"",
",",
"3",
",",
"self",
"::",
"$",
"_PHPCAS_DEBUG",
"[",
"'filename'",
"]",
")",
";",
"}",
"}"
] | Logs a string in debug mode.
@param string $str the string to write
@return void
@private | [
"Logs",
"a",
"string",
"in",
"debug",
"mode",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS.php#L509-L532 |
212,435 | moodle/moodle | auth/cas/CAS/CAS.php | phpCAS.error | public static function error($msg)
{
phpCAS :: traceBegin();
$dbg = debug_backtrace();
$function = '?';
$file = '?';
$line = '?';
if (is_array($dbg)) {
for ($i = 1; $i < sizeof($dbg); $i++) {
if (is_array($dbg[$i]) && isset($dbg[$i]['class']) ) {
if ($dbg[$i]['class'] == __CLASS__) {
$function = $dbg[$i]['function'];
$file = $dbg[$i]['file'];
$line = $dbg[$i]['line'];
}
}
}
}
if (self::$_PHPCAS_VERBOSE) {
echo "<br />\n<b>phpCAS error</b>: <font color=\"FF0000\"><b>" . __CLASS__ . "::" . $function . '(): ' . htmlentities($msg) . "</b></font> in <b>" . $file . "</b> on line <b>" . $line . "</b><br />\n";
} else {
echo "<br />\n<b>Error</b>: <font color=\"FF0000\"><b>". DEFAULT_ERROR ."</b><br />\n";
}
phpCAS :: trace($msg . ' in ' . $file . 'on line ' . $line );
phpCAS :: traceEnd();
throw new CAS_GracefullTerminationException(__CLASS__ . "::" . $function . '(): ' . $msg);
} | php | public static function error($msg)
{
phpCAS :: traceBegin();
$dbg = debug_backtrace();
$function = '?';
$file = '?';
$line = '?';
if (is_array($dbg)) {
for ($i = 1; $i < sizeof($dbg); $i++) {
if (is_array($dbg[$i]) && isset($dbg[$i]['class']) ) {
if ($dbg[$i]['class'] == __CLASS__) {
$function = $dbg[$i]['function'];
$file = $dbg[$i]['file'];
$line = $dbg[$i]['line'];
}
}
}
}
if (self::$_PHPCAS_VERBOSE) {
echo "<br />\n<b>phpCAS error</b>: <font color=\"FF0000\"><b>" . __CLASS__ . "::" . $function . '(): ' . htmlentities($msg) . "</b></font> in <b>" . $file . "</b> on line <b>" . $line . "</b><br />\n";
} else {
echo "<br />\n<b>Error</b>: <font color=\"FF0000\"><b>". DEFAULT_ERROR ."</b><br />\n";
}
phpCAS :: trace($msg . ' in ' . $file . 'on line ' . $line );
phpCAS :: traceEnd();
throw new CAS_GracefullTerminationException(__CLASS__ . "::" . $function . '(): ' . $msg);
} | [
"public",
"static",
"function",
"error",
"(",
"$",
"msg",
")",
"{",
"phpCAS",
"::",
"traceBegin",
"(",
")",
";",
"$",
"dbg",
"=",
"debug_backtrace",
"(",
")",
";",
"$",
"function",
"=",
"'?'",
";",
"$",
"file",
"=",
"'?'",
";",
"$",
"line",
"=",
"'?'",
";",
"if",
"(",
"is_array",
"(",
"$",
"dbg",
")",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<",
"sizeof",
"(",
"$",
"dbg",
")",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"dbg",
"[",
"$",
"i",
"]",
")",
"&&",
"isset",
"(",
"$",
"dbg",
"[",
"$",
"i",
"]",
"[",
"'class'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"dbg",
"[",
"$",
"i",
"]",
"[",
"'class'",
"]",
"==",
"__CLASS__",
")",
"{",
"$",
"function",
"=",
"$",
"dbg",
"[",
"$",
"i",
"]",
"[",
"'function'",
"]",
";",
"$",
"file",
"=",
"$",
"dbg",
"[",
"$",
"i",
"]",
"[",
"'file'",
"]",
";",
"$",
"line",
"=",
"$",
"dbg",
"[",
"$",
"i",
"]",
"[",
"'line'",
"]",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"self",
"::",
"$",
"_PHPCAS_VERBOSE",
")",
"{",
"echo",
"\"<br />\\n<b>phpCAS error</b>: <font color=\\\"FF0000\\\"><b>\"",
".",
"__CLASS__",
".",
"\"::\"",
".",
"$",
"function",
".",
"'(): '",
".",
"htmlentities",
"(",
"$",
"msg",
")",
".",
"\"</b></font> in <b>\"",
".",
"$",
"file",
".",
"\"</b> on line <b>\"",
".",
"$",
"line",
".",
"\"</b><br />\\n\"",
";",
"}",
"else",
"{",
"echo",
"\"<br />\\n<b>Error</b>: <font color=\\\"FF0000\\\"><b>\"",
".",
"DEFAULT_ERROR",
".",
"\"</b><br />\\n\"",
";",
"}",
"phpCAS",
"::",
"trace",
"(",
"$",
"msg",
".",
"' in '",
".",
"$",
"file",
".",
"'on line '",
".",
"$",
"line",
")",
";",
"phpCAS",
"::",
"traceEnd",
"(",
")",
";",
"throw",
"new",
"CAS_GracefullTerminationException",
"(",
"__CLASS__",
".",
"\"::\"",
".",
"$",
"function",
".",
"'(): '",
".",
"$",
"msg",
")",
";",
"}"
] | This method is used by interface methods to print an error and where the
function was originally called from.
@param string $msg the message to print
@return void
@private | [
"This",
"method",
"is",
"used",
"by",
"interface",
"methods",
"to",
"print",
"an",
"error",
"and",
"where",
"the",
"function",
"was",
"originally",
"called",
"from",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS.php#L543-L570 |
212,436 | moodle/moodle | auth/cas/CAS/CAS.php | phpCAS.trace | public static function trace($str)
{
$dbg = debug_backtrace();
phpCAS :: log($str . ' [' . basename($dbg[0]['file']) . ':' . $dbg[0]['line'] . ']');
} | php | public static function trace($str)
{
$dbg = debug_backtrace();
phpCAS :: log($str . ' [' . basename($dbg[0]['file']) . ':' . $dbg[0]['line'] . ']');
} | [
"public",
"static",
"function",
"trace",
"(",
"$",
"str",
")",
"{",
"$",
"dbg",
"=",
"debug_backtrace",
"(",
")",
";",
"phpCAS",
"::",
"log",
"(",
"$",
"str",
".",
"' ['",
".",
"basename",
"(",
"$",
"dbg",
"[",
"0",
"]",
"[",
"'file'",
"]",
")",
".",
"':'",
".",
"$",
"dbg",
"[",
"0",
"]",
"[",
"'line'",
"]",
".",
"']'",
")",
";",
"}"
] | This method is used to log something in debug mode.
@param string $str string to log
@return void | [
"This",
"method",
"is",
"used",
"to",
"log",
"something",
"in",
"debug",
"mode",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS.php#L579-L583 |
212,437 | moodle/moodle | auth/cas/CAS/CAS.php | phpCAS.traceBegin | public static function traceBegin()
{
$dbg = debug_backtrace();
$str = '=> ';
if (!empty ($dbg[1]['class'])) {
$str .= $dbg[1]['class'] . '::';
}
$str .= $dbg[1]['function'] . '(';
if (is_array($dbg[1]['args'])) {
foreach ($dbg[1]['args'] as $index => $arg) {
if ($index != 0) {
$str .= ', ';
}
if (is_object($arg)) {
$str .= get_class($arg);
} else {
$str .= str_replace(array("\r\n", "\n", "\r"), "", var_export($arg, true));
}
}
}
if (isset($dbg[1]['file'])) {
$file = basename($dbg[1]['file']);
} else {
$file = 'unknown_file';
}
if (isset($dbg[1]['line'])) {
$line = $dbg[1]['line'];
} else {
$line = 'unknown_line';
}
$str .= ') [' . $file . ':' . $line . ']';
phpCAS :: log($str);
if (!isset(self::$_PHPCAS_DEBUG['indent'])) {
self::$_PHPCAS_DEBUG['indent'] = 0;
} else {
self::$_PHPCAS_DEBUG['indent']++;
}
} | php | public static function traceBegin()
{
$dbg = debug_backtrace();
$str = '=> ';
if (!empty ($dbg[1]['class'])) {
$str .= $dbg[1]['class'] . '::';
}
$str .= $dbg[1]['function'] . '(';
if (is_array($dbg[1]['args'])) {
foreach ($dbg[1]['args'] as $index => $arg) {
if ($index != 0) {
$str .= ', ';
}
if (is_object($arg)) {
$str .= get_class($arg);
} else {
$str .= str_replace(array("\r\n", "\n", "\r"), "", var_export($arg, true));
}
}
}
if (isset($dbg[1]['file'])) {
$file = basename($dbg[1]['file']);
} else {
$file = 'unknown_file';
}
if (isset($dbg[1]['line'])) {
$line = $dbg[1]['line'];
} else {
$line = 'unknown_line';
}
$str .= ') [' . $file . ':' . $line . ']';
phpCAS :: log($str);
if (!isset(self::$_PHPCAS_DEBUG['indent'])) {
self::$_PHPCAS_DEBUG['indent'] = 0;
} else {
self::$_PHPCAS_DEBUG['indent']++;
}
} | [
"public",
"static",
"function",
"traceBegin",
"(",
")",
"{",
"$",
"dbg",
"=",
"debug_backtrace",
"(",
")",
";",
"$",
"str",
"=",
"'=> '",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"dbg",
"[",
"1",
"]",
"[",
"'class'",
"]",
")",
")",
"{",
"$",
"str",
".=",
"$",
"dbg",
"[",
"1",
"]",
"[",
"'class'",
"]",
".",
"'::'",
";",
"}",
"$",
"str",
".=",
"$",
"dbg",
"[",
"1",
"]",
"[",
"'function'",
"]",
".",
"'('",
";",
"if",
"(",
"is_array",
"(",
"$",
"dbg",
"[",
"1",
"]",
"[",
"'args'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"dbg",
"[",
"1",
"]",
"[",
"'args'",
"]",
"as",
"$",
"index",
"=>",
"$",
"arg",
")",
"{",
"if",
"(",
"$",
"index",
"!=",
"0",
")",
"{",
"$",
"str",
".=",
"', '",
";",
"}",
"if",
"(",
"is_object",
"(",
"$",
"arg",
")",
")",
"{",
"$",
"str",
".=",
"get_class",
"(",
"$",
"arg",
")",
";",
"}",
"else",
"{",
"$",
"str",
".=",
"str_replace",
"(",
"array",
"(",
"\"\\r\\n\"",
",",
"\"\\n\"",
",",
"\"\\r\"",
")",
",",
"\"\"",
",",
"var_export",
"(",
"$",
"arg",
",",
"true",
")",
")",
";",
"}",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"dbg",
"[",
"1",
"]",
"[",
"'file'",
"]",
")",
")",
"{",
"$",
"file",
"=",
"basename",
"(",
"$",
"dbg",
"[",
"1",
"]",
"[",
"'file'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"file",
"=",
"'unknown_file'",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"dbg",
"[",
"1",
"]",
"[",
"'line'",
"]",
")",
")",
"{",
"$",
"line",
"=",
"$",
"dbg",
"[",
"1",
"]",
"[",
"'line'",
"]",
";",
"}",
"else",
"{",
"$",
"line",
"=",
"'unknown_line'",
";",
"}",
"$",
"str",
".=",
"') ['",
".",
"$",
"file",
".",
"':'",
".",
"$",
"line",
".",
"']'",
";",
"phpCAS",
"::",
"log",
"(",
"$",
"str",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"_PHPCAS_DEBUG",
"[",
"'indent'",
"]",
")",
")",
"{",
"self",
"::",
"$",
"_PHPCAS_DEBUG",
"[",
"'indent'",
"]",
"=",
"0",
";",
"}",
"else",
"{",
"self",
"::",
"$",
"_PHPCAS_DEBUG",
"[",
"'indent'",
"]",
"++",
";",
"}",
"}"
] | This method is used to indicate the start of the execution of a function
in debug mode.
@return void | [
"This",
"method",
"is",
"used",
"to",
"indicate",
"the",
"start",
"of",
"the",
"execution",
"of",
"a",
"function",
"in",
"debug",
"mode",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS.php#L591-L628 |
212,438 | moodle/moodle | auth/cas/CAS/CAS.php | phpCAS.traceEnd | public static function traceEnd($res = '')
{
if (empty(self::$_PHPCAS_DEBUG['indent'])) {
self::$_PHPCAS_DEBUG['indent'] = 0;
} else {
self::$_PHPCAS_DEBUG['indent']--;
}
$dbg = debug_backtrace();
$str = '';
if (is_object($res)) {
$str .= '<= ' . get_class($res);
} else {
$str .= '<= ' . str_replace(array("\r\n", "\n", "\r"), "", var_export($res, true));
}
phpCAS :: log($str);
} | php | public static function traceEnd($res = '')
{
if (empty(self::$_PHPCAS_DEBUG['indent'])) {
self::$_PHPCAS_DEBUG['indent'] = 0;
} else {
self::$_PHPCAS_DEBUG['indent']--;
}
$dbg = debug_backtrace();
$str = '';
if (is_object($res)) {
$str .= '<= ' . get_class($res);
} else {
$str .= '<= ' . str_replace(array("\r\n", "\n", "\r"), "", var_export($res, true));
}
phpCAS :: log($str);
} | [
"public",
"static",
"function",
"traceEnd",
"(",
"$",
"res",
"=",
"''",
")",
"{",
"if",
"(",
"empty",
"(",
"self",
"::",
"$",
"_PHPCAS_DEBUG",
"[",
"'indent'",
"]",
")",
")",
"{",
"self",
"::",
"$",
"_PHPCAS_DEBUG",
"[",
"'indent'",
"]",
"=",
"0",
";",
"}",
"else",
"{",
"self",
"::",
"$",
"_PHPCAS_DEBUG",
"[",
"'indent'",
"]",
"--",
";",
"}",
"$",
"dbg",
"=",
"debug_backtrace",
"(",
")",
";",
"$",
"str",
"=",
"''",
";",
"if",
"(",
"is_object",
"(",
"$",
"res",
")",
")",
"{",
"$",
"str",
".=",
"'<= '",
".",
"get_class",
"(",
"$",
"res",
")",
";",
"}",
"else",
"{",
"$",
"str",
".=",
"'<= '",
".",
"str_replace",
"(",
"array",
"(",
"\"\\r\\n\"",
",",
"\"\\n\"",
",",
"\"\\r\"",
")",
",",
"\"\"",
",",
"var_export",
"(",
"$",
"res",
",",
"true",
")",
")",
";",
"}",
"phpCAS",
"::",
"log",
"(",
"$",
"str",
")",
";",
"}"
] | This method is used to indicate the end of the execution of a function in
debug mode.
@param string $res the result of the function
@return void | [
"This",
"method",
"is",
"used",
"to",
"indicate",
"the",
"end",
"of",
"the",
"execution",
"of",
"a",
"function",
"in",
"debug",
"mode",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS.php#L638-L654 |
212,439 | moodle/moodle | auth/cas/CAS/CAS.php | phpCAS.setHTMLHeader | public static function setHTMLHeader($header)
{
phpCAS::_validateClientExists();
try {
self::$_PHPCAS_CLIENT->setHTMLHeader($header);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
} | php | public static function setHTMLHeader($header)
{
phpCAS::_validateClientExists();
try {
self::$_PHPCAS_CLIENT->setHTMLHeader($header);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
} | [
"public",
"static",
"function",
"setHTMLHeader",
"(",
"$",
"header",
")",
"{",
"phpCAS",
"::",
"_validateClientExists",
"(",
")",
";",
"try",
"{",
"self",
"::",
"$",
"_PHPCAS_CLIENT",
"->",
"setHTMLHeader",
"(",
"$",
"header",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"phpCAS",
"::",
"error",
"(",
"get_class",
"(",
"$",
"e",
")",
".",
"': '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] | This method sets the HTML header used for all outputs.
@param string $header the HTML header.
@return void | [
"This",
"method",
"sets",
"the",
"HTML",
"header",
"used",
"for",
"all",
"outputs",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS.php#L735-L744 |
212,440 | moodle/moodle | auth/cas/CAS/CAS.php | phpCAS.setHTMLFooter | public static function setHTMLFooter($footer)
{
phpCAS::_validateClientExists();
try {
self::$_PHPCAS_CLIENT->setHTMLFooter($footer);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
} | php | public static function setHTMLFooter($footer)
{
phpCAS::_validateClientExists();
try {
self::$_PHPCAS_CLIENT->setHTMLFooter($footer);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
} | [
"public",
"static",
"function",
"setHTMLFooter",
"(",
"$",
"footer",
")",
"{",
"phpCAS",
"::",
"_validateClientExists",
"(",
")",
";",
"try",
"{",
"self",
"::",
"$",
"_PHPCAS_CLIENT",
"->",
"setHTMLFooter",
"(",
"$",
"footer",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"phpCAS",
"::",
"error",
"(",
"get_class",
"(",
"$",
"e",
")",
".",
"': '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] | This method sets the HTML footer used for all outputs.
@param string $footer the HTML footer.
@return void | [
"This",
"method",
"sets",
"the",
"HTML",
"footer",
"used",
"for",
"all",
"outputs",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS.php#L753-L762 |
212,441 | moodle/moodle | auth/cas/CAS/CAS.php | phpCAS.hasAttribute | public static function hasAttribute($key)
{
phpCAS::_validateClientExists();
try {
return self::$_PHPCAS_CLIENT->hasAttribute($key);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
} | php | public static function hasAttribute($key)
{
phpCAS::_validateClientExists();
try {
return self::$_PHPCAS_CLIENT->hasAttribute($key);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
} | [
"public",
"static",
"function",
"hasAttribute",
"(",
"$",
"key",
")",
"{",
"phpCAS",
"::",
"_validateClientExists",
"(",
")",
";",
"try",
"{",
"return",
"self",
"::",
"$",
"_PHPCAS_CLIENT",
"->",
"hasAttribute",
"(",
"$",
"key",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"phpCAS",
"::",
"error",
"(",
"get_class",
"(",
"$",
"e",
")",
".",
"': '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] | Answer true if an attribute exists for the authenticated user.
@param string $key attribute name
@return bool
@warning should only be called after phpCAS::forceAuthentication()
or phpCAS::checkAuthentication(). | [
"Answer",
"true",
"if",
"an",
"attribute",
"exists",
"for",
"the",
"authenticated",
"user",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS.php#L1233-L1242 |
212,442 | moodle/moodle | auth/cas/CAS/CAS.php | phpCAS.handleLogoutRequests | public static function handleLogoutRequests($check_client = true, $allowed_clients = false)
{
phpCAS::_validateClientExists();
return (self::$_PHPCAS_CLIENT->handleLogoutRequests($check_client, $allowed_clients));
} | php | public static function handleLogoutRequests($check_client = true, $allowed_clients = false)
{
phpCAS::_validateClientExists();
return (self::$_PHPCAS_CLIENT->handleLogoutRequests($check_client, $allowed_clients));
} | [
"public",
"static",
"function",
"handleLogoutRequests",
"(",
"$",
"check_client",
"=",
"true",
",",
"$",
"allowed_clients",
"=",
"false",
")",
"{",
"phpCAS",
"::",
"_validateClientExists",
"(",
")",
";",
"return",
"(",
"self",
"::",
"$",
"_PHPCAS_CLIENT",
"->",
"handleLogoutRequests",
"(",
"$",
"check_client",
",",
"$",
"allowed_clients",
")",
")",
";",
"}"
] | Handle logout requests.
@param bool $check_client additional safety check
@param array $allowed_clients array of allowed clients
@return void | [
"Handle",
"logout",
"requests",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS.php#L1272-L1277 |
212,443 | moodle/moodle | auth/cas/CAS/CAS.php | phpCAS.setServerLoginURL | public static function setServerLoginURL($url = '')
{
phpCAS :: traceBegin();
phpCAS::_validateClientExists();
try {
self::$_PHPCAS_CLIENT->setServerLoginURL($url);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
phpCAS :: traceEnd();
} | php | public static function setServerLoginURL($url = '')
{
phpCAS :: traceBegin();
phpCAS::_validateClientExists();
try {
self::$_PHPCAS_CLIENT->setServerLoginURL($url);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
phpCAS :: traceEnd();
} | [
"public",
"static",
"function",
"setServerLoginURL",
"(",
"$",
"url",
"=",
"''",
")",
"{",
"phpCAS",
"::",
"traceBegin",
"(",
")",
";",
"phpCAS",
"::",
"_validateClientExists",
"(",
")",
";",
"try",
"{",
"self",
"::",
"$",
"_PHPCAS_CLIENT",
"->",
"setServerLoginURL",
"(",
"$",
"url",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"phpCAS",
"::",
"error",
"(",
"get_class",
"(",
"$",
"e",
")",
".",
"': '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"phpCAS",
"::",
"traceEnd",
"(",
")",
";",
"}"
] | Set the login URL of the CAS server.
@param string $url the login URL
@return void
@since 0.4.21 by Wyman Chan | [
"Set",
"the",
"login",
"URL",
"of",
"the",
"CAS",
"server",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS.php#L1300-L1312 |
212,444 | moodle/moodle | auth/cas/CAS/CAS.php | phpCAS.setFixedCallbackURL | public static function setFixedCallbackURL($url = '')
{
phpCAS :: traceBegin();
phpCAS::_validateProxyExists();
try {
self::$_PHPCAS_CLIENT->setCallbackURL($url);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
phpCAS :: traceEnd();
} | php | public static function setFixedCallbackURL($url = '')
{
phpCAS :: traceBegin();
phpCAS::_validateProxyExists();
try {
self::$_PHPCAS_CLIENT->setCallbackURL($url);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
phpCAS :: traceEnd();
} | [
"public",
"static",
"function",
"setFixedCallbackURL",
"(",
"$",
"url",
"=",
"''",
")",
"{",
"phpCAS",
"::",
"traceBegin",
"(",
")",
";",
"phpCAS",
"::",
"_validateProxyExists",
"(",
")",
";",
"try",
"{",
"self",
"::",
"$",
"_PHPCAS_CLIENT",
"->",
"setCallbackURL",
"(",
"$",
"url",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"phpCAS",
"::",
"error",
"(",
"get_class",
"(",
"$",
"e",
")",
".",
"': '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"phpCAS",
"::",
"traceEnd",
"(",
")",
";",
"}"
] | Set the fixed URL that will be used by the CAS server to transmit the
PGT. When this method is not called, a phpCAS script uses its own URL
for the callback.
@param string $url the URL
@return void | [
"Set",
"the",
"fixed",
"URL",
"that",
"will",
"be",
"used",
"by",
"the",
"CAS",
"server",
"to",
"transmit",
"the",
"PGT",
".",
"When",
"this",
"method",
"is",
"not",
"called",
"a",
"phpCAS",
"script",
"uses",
"its",
"own",
"URL",
"for",
"the",
"callback",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS.php#L1544-L1556 |
212,445 | moodle/moodle | auth/cas/CAS/CAS.php | phpCAS.setFixedServiceURL | public static function setFixedServiceURL($url)
{
phpCAS :: traceBegin();
phpCAS::_validateProxyExists();
try {
self::$_PHPCAS_CLIENT->setURL($url);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
phpCAS :: traceEnd();
} | php | public static function setFixedServiceURL($url)
{
phpCAS :: traceBegin();
phpCAS::_validateProxyExists();
try {
self::$_PHPCAS_CLIENT->setURL($url);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
phpCAS :: traceEnd();
} | [
"public",
"static",
"function",
"setFixedServiceURL",
"(",
"$",
"url",
")",
"{",
"phpCAS",
"::",
"traceBegin",
"(",
")",
";",
"phpCAS",
"::",
"_validateProxyExists",
"(",
")",
";",
"try",
"{",
"self",
"::",
"$",
"_PHPCAS_CLIENT",
"->",
"setURL",
"(",
"$",
"url",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"phpCAS",
"::",
"error",
"(",
"get_class",
"(",
"$",
"e",
")",
".",
"': '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"phpCAS",
"::",
"traceEnd",
"(",
")",
";",
"}"
] | Set the fixed URL that will be set as the CAS service parameter. When this
method is not called, a phpCAS script uses its own URL.
@param string $url the URL
@return void | [
"Set",
"the",
"fixed",
"URL",
"that",
"will",
"be",
"set",
"as",
"the",
"CAS",
"service",
"parameter",
".",
"When",
"this",
"method",
"is",
"not",
"called",
"a",
"phpCAS",
"script",
"uses",
"its",
"own",
"URL",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS.php#L1566-L1578 |
212,446 | moodle/moodle | auth/cas/CAS/CAS.php | phpCAS.retrievePT | public static function retrievePT($target_service, & $err_code, & $err_msg)
{
phpCAS::_validateProxyExists();
try {
return (self::$_PHPCAS_CLIENT->retrievePT($target_service, $err_code, $err_msg));
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
} | php | public static function retrievePT($target_service, & $err_code, & $err_msg)
{
phpCAS::_validateProxyExists();
try {
return (self::$_PHPCAS_CLIENT->retrievePT($target_service, $err_code, $err_msg));
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
} | [
"public",
"static",
"function",
"retrievePT",
"(",
"$",
"target_service",
",",
"&",
"$",
"err_code",
",",
"&",
"$",
"err_msg",
")",
"{",
"phpCAS",
"::",
"_validateProxyExists",
"(",
")",
";",
"try",
"{",
"return",
"(",
"self",
"::",
"$",
"_PHPCAS_CLIENT",
"->",
"retrievePT",
"(",
"$",
"target_service",
",",
"$",
"err_code",
",",
"$",
"err_msg",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"phpCAS",
"::",
"error",
"(",
"get_class",
"(",
"$",
"e",
")",
".",
"': '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"}"
] | Retrieve a Proxy Ticket from the CAS server.
@param string $target_service Url string of service to proxy
@param string &$err_code error code
@param string &$err_msg error message
@return string Proxy Ticket | [
"Retrieve",
"a",
"Proxy",
"Ticket",
"from",
"the",
"CAS",
"server",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS.php#L1600-L1609 |
212,447 | moodle/moodle | auth/cas/CAS/CAS.php | phpCAS.setCasServerCACert | public static function setCasServerCACert($cert, $validate_cn = true)
{
phpCAS :: traceBegin();
phpCAS::_validateClientExists();
try {
self::$_PHPCAS_CLIENT->setCasServerCACert($cert, $validate_cn);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
phpCAS :: traceEnd();
} | php | public static function setCasServerCACert($cert, $validate_cn = true)
{
phpCAS :: traceBegin();
phpCAS::_validateClientExists();
try {
self::$_PHPCAS_CLIENT->setCasServerCACert($cert, $validate_cn);
} catch (Exception $e) {
phpCAS :: error(get_class($e) . ': ' . $e->getMessage());
}
phpCAS :: traceEnd();
} | [
"public",
"static",
"function",
"setCasServerCACert",
"(",
"$",
"cert",
",",
"$",
"validate_cn",
"=",
"true",
")",
"{",
"phpCAS",
"::",
"traceBegin",
"(",
")",
";",
"phpCAS",
"::",
"_validateClientExists",
"(",
")",
";",
"try",
"{",
"self",
"::",
"$",
"_PHPCAS_CLIENT",
"->",
"setCasServerCACert",
"(",
"$",
"cert",
",",
"$",
"validate_cn",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"phpCAS",
"::",
"error",
"(",
"get_class",
"(",
"$",
"e",
")",
".",
"': '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"phpCAS",
"::",
"traceEnd",
"(",
")",
";",
"}"
] | Set the certificate of the CAS server CA and if the CN should be properly
verified.
@param string $cert CA certificate file name
@param bool $validate_cn Validate CN in certificate (default true)
@return void | [
"Set",
"the",
"certificate",
"of",
"the",
"CAS",
"server",
"CA",
"and",
"if",
"the",
"CN",
"should",
"be",
"properly",
"verified",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS.php#L1620-L1632 |
212,448 | moodle/moodle | auth/cas/CAS/CAS.php | phpCAS.setNoCasServerValidation | public static function setNoCasServerValidation()
{
phpCAS :: traceBegin();
phpCAS::_validateClientExists();
phpCAS :: trace('You have configured no validation of the legitimacy of the cas server. This is not recommended for production use.');
self::$_PHPCAS_CLIENT->setNoCasServerValidation();
phpCAS :: traceEnd();
} | php | public static function setNoCasServerValidation()
{
phpCAS :: traceBegin();
phpCAS::_validateClientExists();
phpCAS :: trace('You have configured no validation of the legitimacy of the cas server. This is not recommended for production use.');
self::$_PHPCAS_CLIENT->setNoCasServerValidation();
phpCAS :: traceEnd();
} | [
"public",
"static",
"function",
"setNoCasServerValidation",
"(",
")",
"{",
"phpCAS",
"::",
"traceBegin",
"(",
")",
";",
"phpCAS",
"::",
"_validateClientExists",
"(",
")",
";",
"phpCAS",
"::",
"trace",
"(",
"'You have configured no validation of the legitimacy of the cas server. This is not recommended for production use.'",
")",
";",
"self",
"::",
"$",
"_PHPCAS_CLIENT",
"->",
"setNoCasServerValidation",
"(",
")",
";",
"phpCAS",
"::",
"traceEnd",
"(",
")",
";",
"}"
] | Set no SSL validation for the CAS server.
@return void | [
"Set",
"no",
"SSL",
"validation",
"for",
"the",
"CAS",
"server",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS.php#L1639-L1647 |
212,449 | moodle/moodle | auth/cas/CAS/CAS.php | phpCAS.setExtraCurlOption | public static function setExtraCurlOption($key, $value)
{
phpCAS :: traceBegin();
phpCAS::_validateClientExists();
self::$_PHPCAS_CLIENT->setExtraCurlOption($key, $value);
phpCAS :: traceEnd();
} | php | public static function setExtraCurlOption($key, $value)
{
phpCAS :: traceBegin();
phpCAS::_validateClientExists();
self::$_PHPCAS_CLIENT->setExtraCurlOption($key, $value);
phpCAS :: traceEnd();
} | [
"public",
"static",
"function",
"setExtraCurlOption",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"phpCAS",
"::",
"traceBegin",
"(",
")",
";",
"phpCAS",
"::",
"_validateClientExists",
"(",
")",
";",
"self",
"::",
"$",
"_PHPCAS_CLIENT",
"->",
"setExtraCurlOption",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"phpCAS",
"::",
"traceEnd",
"(",
")",
";",
"}"
] | Change CURL options.
CURL is used to connect through HTTPS to CAS server
@param string $key the option key
@param string $value the value to set
@return void | [
"Change",
"CURL",
"options",
".",
"CURL",
"is",
"used",
"to",
"connect",
"through",
"HTTPS",
"to",
"CAS",
"server"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS.php#L1679-L1686 |
212,450 | moodle/moodle | badges/lib/bakerlib.php | PNG_MetaDataHandler.check_chunks | public function check_chunks($type, $check) {
if (array_key_exists($type, $this->_chunks)) {
foreach (array_keys($this->_chunks[$type]) as $typekey) {
list($key, $data) = explode("\0", $this->_chunks[$type][$typekey]);
if (strcmp($key, $check) == 0) {
debugging('Key "' . $check . '" already exists in "' . $type . '" chunk.');
return false;
}
}
}
return true;
} | php | public function check_chunks($type, $check) {
if (array_key_exists($type, $this->_chunks)) {
foreach (array_keys($this->_chunks[$type]) as $typekey) {
list($key, $data) = explode("\0", $this->_chunks[$type][$typekey]);
if (strcmp($key, $check) == 0) {
debugging('Key "' . $check . '" already exists in "' . $type . '" chunk.');
return false;
}
}
}
return true;
} | [
"public",
"function",
"check_chunks",
"(",
"$",
"type",
",",
"$",
"check",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"_chunks",
")",
")",
"{",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"_chunks",
"[",
"$",
"type",
"]",
")",
"as",
"$",
"typekey",
")",
"{",
"list",
"(",
"$",
"key",
",",
"$",
"data",
")",
"=",
"explode",
"(",
"\"\\0\"",
",",
"$",
"this",
"->",
"_chunks",
"[",
"$",
"type",
"]",
"[",
"$",
"typekey",
"]",
")",
";",
"if",
"(",
"strcmp",
"(",
"$",
"key",
",",
"$",
"check",
")",
"==",
"0",
")",
"{",
"debugging",
"(",
"'Key \"'",
".",
"$",
"check",
".",
"'\" already exists in \"'",
".",
"$",
"type",
".",
"'\" chunk.'",
")",
";",
"return",
"false",
";",
"}",
"}",
"}",
"return",
"true",
";",
"}"
] | Checks if a key already exists in the chunk of said type.
We need to avoid writing same keyword into file chunks.
@param string $type Chunk type, like iTXt, tEXt, etc.
@param string $check Keyword that needs to be checked.
@return boolean (true|false) True if file is safe to write this keyword, false otherwise. | [
"Checks",
"if",
"a",
"key",
"already",
"exists",
"in",
"the",
"chunk",
"of",
"said",
"type",
".",
"We",
"need",
"to",
"avoid",
"writing",
"same",
"keyword",
"into",
"file",
"chunks",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/badges/lib/bakerlib.php#L94-L106 |
212,451 | moodle/moodle | badges/lib/bakerlib.php | PNG_MetaDataHandler.add_chunks | public function add_chunks($type, $key, $value) {
if (strlen($key) > 79) {
debugging('Key is too big');
}
// tEXt Textual data.
// Keyword: 1-79 bytes (character string)
// Null separator: 1 byte
// Text: n bytes (character string)
$data = $key . "\0" . $value;
$crc = pack("N", crc32($type . $data));
$len = pack("N", strlen($data));
// Chunk format: length + type + data + CRC.
// CRC is a CRC-32 computed over the chunk type and chunk data.
$newchunk = $len . $type . $data . $crc;
$result = substr($this->_contents, 0, $this->_size - 12)
. $newchunk
. substr($this->_contents, $this->_size - 12, 12);
return $result;
} | php | public function add_chunks($type, $key, $value) {
if (strlen($key) > 79) {
debugging('Key is too big');
}
// tEXt Textual data.
// Keyword: 1-79 bytes (character string)
// Null separator: 1 byte
// Text: n bytes (character string)
$data = $key . "\0" . $value;
$crc = pack("N", crc32($type . $data));
$len = pack("N", strlen($data));
// Chunk format: length + type + data + CRC.
// CRC is a CRC-32 computed over the chunk type and chunk data.
$newchunk = $len . $type . $data . $crc;
$result = substr($this->_contents, 0, $this->_size - 12)
. $newchunk
. substr($this->_contents, $this->_size - 12, 12);
return $result;
} | [
"public",
"function",
"add_chunks",
"(",
"$",
"type",
",",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"key",
")",
">",
"79",
")",
"{",
"debugging",
"(",
"'Key is too big'",
")",
";",
"}",
"// tEXt Textual data.",
"// Keyword: 1-79 bytes (character string)",
"// Null separator: 1 byte",
"// Text: n bytes (character string)",
"$",
"data",
"=",
"$",
"key",
".",
"\"\\0\"",
".",
"$",
"value",
";",
"$",
"crc",
"=",
"pack",
"(",
"\"N\"",
",",
"crc32",
"(",
"$",
"type",
".",
"$",
"data",
")",
")",
";",
"$",
"len",
"=",
"pack",
"(",
"\"N\"",
",",
"strlen",
"(",
"$",
"data",
")",
")",
";",
"// Chunk format: length + type + data + CRC.",
"// CRC is a CRC-32 computed over the chunk type and chunk data.",
"$",
"newchunk",
"=",
"$",
"len",
".",
"$",
"type",
".",
"$",
"data",
".",
"$",
"crc",
";",
"$",
"result",
"=",
"substr",
"(",
"$",
"this",
"->",
"_contents",
",",
"0",
",",
"$",
"this",
"->",
"_size",
"-",
"12",
")",
".",
"$",
"newchunk",
".",
"substr",
"(",
"$",
"this",
"->",
"_contents",
",",
"$",
"this",
"->",
"_size",
"-",
"12",
",",
"12",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Adds a chunk with keyword and data to the file content.
Chunk is added to the end of the file, before IEND image trailer.
@param string $type Chunk type, like iTXt, tEXt, etc.
@param string $key Keyword that needs to be added.
@param string $value Currently an assertion URL that is added to an image metadata.
@return string $result File content with a new chunk as a string. Can be used in file_put_contents() to write to a file. | [
"Adds",
"a",
"chunk",
"with",
"keyword",
"and",
"data",
"to",
"the",
"file",
"content",
".",
"Chunk",
"is",
"added",
"to",
"the",
"end",
"of",
"the",
"file",
"before",
"IEND",
"image",
"trailer",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/badges/lib/bakerlib.php#L118-L140 |
212,452 | moodle/moodle | repository/local/lib.php | repository_local.get_non_empty_children | private function get_non_empty_children(file_info $fileinfo, $extensions) {
$nonemptychildren = $fileinfo->get_non_empty_children($extensions);
$list = array();
foreach ($nonemptychildren as $child) {
if ($this->can_skip($child, $extensions, $fileinfo)) {
$list = array_merge($list, $this->get_non_empty_children($child, $extensions));
} else {
$list[] = $this->get_node($child);
}
}
return $list;
} | php | private function get_non_empty_children(file_info $fileinfo, $extensions) {
$nonemptychildren = $fileinfo->get_non_empty_children($extensions);
$list = array();
foreach ($nonemptychildren as $child) {
if ($this->can_skip($child, $extensions, $fileinfo)) {
$list = array_merge($list, $this->get_non_empty_children($child, $extensions));
} else {
$list[] = $this->get_node($child);
}
}
return $list;
} | [
"private",
"function",
"get_non_empty_children",
"(",
"file_info",
"$",
"fileinfo",
",",
"$",
"extensions",
")",
"{",
"$",
"nonemptychildren",
"=",
"$",
"fileinfo",
"->",
"get_non_empty_children",
"(",
"$",
"extensions",
")",
";",
"$",
"list",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"nonemptychildren",
"as",
"$",
"child",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"can_skip",
"(",
"$",
"child",
",",
"$",
"extensions",
",",
"$",
"fileinfo",
")",
")",
"{",
"$",
"list",
"=",
"array_merge",
"(",
"$",
"list",
",",
"$",
"this",
"->",
"get_non_empty_children",
"(",
"$",
"child",
",",
"$",
"extensions",
")",
")",
";",
"}",
"else",
"{",
"$",
"list",
"[",
"]",
"=",
"$",
"this",
"->",
"get_node",
"(",
"$",
"child",
")",
";",
"}",
"}",
"return",
"$",
"list",
";",
"}"
] | Returns all children elements that have one of the specified extensions
This function may skip subfolders and recursively add their children
{@link repository_local::can_skip()}
@param file_info $fileinfo
@param string|array $extensions, for example '*' or array('.gif','.jpg')
@return array array of file_info elements | [
"Returns",
"all",
"children",
"elements",
"that",
"have",
"one",
"of",
"the",
"specified",
"extensions"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/local/lib.php#L139-L150 |
212,453 | moodle/moodle | repository/local/lib.php | repository_local.can_skip | private function can_skip(file_info $fileinfo, $extensions, $parent = -1) {
global $CFG;
if (!$fileinfo->is_directory()) {
// do not skip files
return false;
}
if ($fileinfo instanceof file_info_context_course ||
$fileinfo instanceof file_info_context_user ||
$fileinfo instanceof file_info_area_course_legacy ||
$fileinfo instanceof file_info_context_module ||
$fileinfo instanceof file_info_context_system) {
// These instances can never be filearea inside an activity, they will never be skipped.
return false;
} else if ($fileinfo instanceof file_info_context_coursecat) {
// This is a course category. For non-admins we do not display categories
return empty($CFG->navshowmycoursecategories) &&
!has_capability('moodle/course:update', context_system::instance());
} else {
$params = $fileinfo->get_params();
if (strlen($params['filearea']) &&
($params['filepath'] === '/' || empty($params['filepath'])) &&
($params['filename'] === '.' || empty($params['filename'])) &&
context::instance_by_id($params['contextid'])->contextlevel == CONTEXT_MODULE) {
if ($parent === -1) {
$parent = $fileinfo->get_parent();
}
// This is a filearea inside an activity, it can be skipped if it has no non-empty siblings
if ($parent && ($parent instanceof file_info_context_module)) {
if ($parent->count_non_empty_children($extensions, 2) <= 1) {
return true;
}
}
}
}
return false;
} | php | private function can_skip(file_info $fileinfo, $extensions, $parent = -1) {
global $CFG;
if (!$fileinfo->is_directory()) {
// do not skip files
return false;
}
if ($fileinfo instanceof file_info_context_course ||
$fileinfo instanceof file_info_context_user ||
$fileinfo instanceof file_info_area_course_legacy ||
$fileinfo instanceof file_info_context_module ||
$fileinfo instanceof file_info_context_system) {
// These instances can never be filearea inside an activity, they will never be skipped.
return false;
} else if ($fileinfo instanceof file_info_context_coursecat) {
// This is a course category. For non-admins we do not display categories
return empty($CFG->navshowmycoursecategories) &&
!has_capability('moodle/course:update', context_system::instance());
} else {
$params = $fileinfo->get_params();
if (strlen($params['filearea']) &&
($params['filepath'] === '/' || empty($params['filepath'])) &&
($params['filename'] === '.' || empty($params['filename'])) &&
context::instance_by_id($params['contextid'])->contextlevel == CONTEXT_MODULE) {
if ($parent === -1) {
$parent = $fileinfo->get_parent();
}
// This is a filearea inside an activity, it can be skipped if it has no non-empty siblings
if ($parent && ($parent instanceof file_info_context_module)) {
if ($parent->count_non_empty_children($extensions, 2) <= 1) {
return true;
}
}
}
}
return false;
} | [
"private",
"function",
"can_skip",
"(",
"file_info",
"$",
"fileinfo",
",",
"$",
"extensions",
",",
"$",
"parent",
"=",
"-",
"1",
")",
"{",
"global",
"$",
"CFG",
";",
"if",
"(",
"!",
"$",
"fileinfo",
"->",
"is_directory",
"(",
")",
")",
"{",
"// do not skip files",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"fileinfo",
"instanceof",
"file_info_context_course",
"||",
"$",
"fileinfo",
"instanceof",
"file_info_context_user",
"||",
"$",
"fileinfo",
"instanceof",
"file_info_area_course_legacy",
"||",
"$",
"fileinfo",
"instanceof",
"file_info_context_module",
"||",
"$",
"fileinfo",
"instanceof",
"file_info_context_system",
")",
"{",
"// These instances can never be filearea inside an activity, they will never be skipped.",
"return",
"false",
";",
"}",
"else",
"if",
"(",
"$",
"fileinfo",
"instanceof",
"file_info_context_coursecat",
")",
"{",
"// This is a course category. For non-admins we do not display categories",
"return",
"empty",
"(",
"$",
"CFG",
"->",
"navshowmycoursecategories",
")",
"&&",
"!",
"has_capability",
"(",
"'moodle/course:update'",
",",
"context_system",
"::",
"instance",
"(",
")",
")",
";",
"}",
"else",
"{",
"$",
"params",
"=",
"$",
"fileinfo",
"->",
"get_params",
"(",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"params",
"[",
"'filearea'",
"]",
")",
"&&",
"(",
"$",
"params",
"[",
"'filepath'",
"]",
"===",
"'/'",
"||",
"empty",
"(",
"$",
"params",
"[",
"'filepath'",
"]",
")",
")",
"&&",
"(",
"$",
"params",
"[",
"'filename'",
"]",
"===",
"'.'",
"||",
"empty",
"(",
"$",
"params",
"[",
"'filename'",
"]",
")",
")",
"&&",
"context",
"::",
"instance_by_id",
"(",
"$",
"params",
"[",
"'contextid'",
"]",
")",
"->",
"contextlevel",
"==",
"CONTEXT_MODULE",
")",
"{",
"if",
"(",
"$",
"parent",
"===",
"-",
"1",
")",
"{",
"$",
"parent",
"=",
"$",
"fileinfo",
"->",
"get_parent",
"(",
")",
";",
"}",
"// This is a filearea inside an activity, it can be skipped if it has no non-empty siblings",
"if",
"(",
"$",
"parent",
"&&",
"(",
"$",
"parent",
"instanceof",
"file_info_context_module",
")",
")",
"{",
"if",
"(",
"$",
"parent",
"->",
"count_non_empty_children",
"(",
"$",
"extensions",
",",
"2",
")",
"<=",
"1",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | Whether this folder may be skipped in folder hierarchy
1. Skip the name of a single filearea in a module
2. Skip course categories for non-admins who do not have navshowmycoursecategories setting
@param file_info $fileinfo
@param string|array $extensions, for example '*' or array('.gif','.jpg')
@param file_info|int $parent specify parent here if we know it to avoid creating extra objects
@return bool | [
"Whether",
"this",
"folder",
"may",
"be",
"skipped",
"in",
"folder",
"hierarchy"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/local/lib.php#L163-L198 |
212,454 | moodle/moodle | repository/local/lib.php | repository_local.get_node | private function get_node(file_info $fileinfo) {
global $OUTPUT;
$encodedpath = base64_encode(json_encode($fileinfo->get_params()));
$node = array(
'title' => $fileinfo->get_visible_name(),
'datemodified' => $fileinfo->get_timemodified(),
'datecreated' => $fileinfo->get_timecreated()
);
if ($fileinfo->is_directory()) {
$node['path'] = $encodedpath;
$node['thumbnail'] = $OUTPUT->image_url(file_folder_icon(90))->out(false);
$node['children'] = array();
} else {
$node['size'] = $fileinfo->get_filesize();
$node['author'] = $fileinfo->get_author();
$node['license'] = $fileinfo->get_license();
$node['isref'] = $fileinfo->is_external_file();
if ($fileinfo->get_status() == 666) {
$node['originalmissing'] = true;
}
$node['source'] = $encodedpath;
$node['thumbnail'] = $OUTPUT->image_url(file_file_icon($fileinfo, 90))->out(false);
$node['icon'] = $OUTPUT->image_url(file_file_icon($fileinfo, 24))->out(false);
if ($imageinfo = $fileinfo->get_imageinfo()) {
// what a beautiful picture, isn't it
$fileurl = new moodle_url($fileinfo->get_url());
$node['realthumbnail'] = $fileurl->out(false, array('preview' => 'thumb', 'oid' => $fileinfo->get_timemodified()));
$node['realicon'] = $fileurl->out(false, array('preview' => 'tinyicon', 'oid' => $fileinfo->get_timemodified()));
$node['image_width'] = $imageinfo['width'];
$node['image_height'] = $imageinfo['height'];
}
}
return $node;
} | php | private function get_node(file_info $fileinfo) {
global $OUTPUT;
$encodedpath = base64_encode(json_encode($fileinfo->get_params()));
$node = array(
'title' => $fileinfo->get_visible_name(),
'datemodified' => $fileinfo->get_timemodified(),
'datecreated' => $fileinfo->get_timecreated()
);
if ($fileinfo->is_directory()) {
$node['path'] = $encodedpath;
$node['thumbnail'] = $OUTPUT->image_url(file_folder_icon(90))->out(false);
$node['children'] = array();
} else {
$node['size'] = $fileinfo->get_filesize();
$node['author'] = $fileinfo->get_author();
$node['license'] = $fileinfo->get_license();
$node['isref'] = $fileinfo->is_external_file();
if ($fileinfo->get_status() == 666) {
$node['originalmissing'] = true;
}
$node['source'] = $encodedpath;
$node['thumbnail'] = $OUTPUT->image_url(file_file_icon($fileinfo, 90))->out(false);
$node['icon'] = $OUTPUT->image_url(file_file_icon($fileinfo, 24))->out(false);
if ($imageinfo = $fileinfo->get_imageinfo()) {
// what a beautiful picture, isn't it
$fileurl = new moodle_url($fileinfo->get_url());
$node['realthumbnail'] = $fileurl->out(false, array('preview' => 'thumb', 'oid' => $fileinfo->get_timemodified()));
$node['realicon'] = $fileurl->out(false, array('preview' => 'tinyicon', 'oid' => $fileinfo->get_timemodified()));
$node['image_width'] = $imageinfo['width'];
$node['image_height'] = $imageinfo['height'];
}
}
return $node;
} | [
"private",
"function",
"get_node",
"(",
"file_info",
"$",
"fileinfo",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"$",
"encodedpath",
"=",
"base64_encode",
"(",
"json_encode",
"(",
"$",
"fileinfo",
"->",
"get_params",
"(",
")",
")",
")",
";",
"$",
"node",
"=",
"array",
"(",
"'title'",
"=>",
"$",
"fileinfo",
"->",
"get_visible_name",
"(",
")",
",",
"'datemodified'",
"=>",
"$",
"fileinfo",
"->",
"get_timemodified",
"(",
")",
",",
"'datecreated'",
"=>",
"$",
"fileinfo",
"->",
"get_timecreated",
"(",
")",
")",
";",
"if",
"(",
"$",
"fileinfo",
"->",
"is_directory",
"(",
")",
")",
"{",
"$",
"node",
"[",
"'path'",
"]",
"=",
"$",
"encodedpath",
";",
"$",
"node",
"[",
"'thumbnail'",
"]",
"=",
"$",
"OUTPUT",
"->",
"image_url",
"(",
"file_folder_icon",
"(",
"90",
")",
")",
"->",
"out",
"(",
"false",
")",
";",
"$",
"node",
"[",
"'children'",
"]",
"=",
"array",
"(",
")",
";",
"}",
"else",
"{",
"$",
"node",
"[",
"'size'",
"]",
"=",
"$",
"fileinfo",
"->",
"get_filesize",
"(",
")",
";",
"$",
"node",
"[",
"'author'",
"]",
"=",
"$",
"fileinfo",
"->",
"get_author",
"(",
")",
";",
"$",
"node",
"[",
"'license'",
"]",
"=",
"$",
"fileinfo",
"->",
"get_license",
"(",
")",
";",
"$",
"node",
"[",
"'isref'",
"]",
"=",
"$",
"fileinfo",
"->",
"is_external_file",
"(",
")",
";",
"if",
"(",
"$",
"fileinfo",
"->",
"get_status",
"(",
")",
"==",
"666",
")",
"{",
"$",
"node",
"[",
"'originalmissing'",
"]",
"=",
"true",
";",
"}",
"$",
"node",
"[",
"'source'",
"]",
"=",
"$",
"encodedpath",
";",
"$",
"node",
"[",
"'thumbnail'",
"]",
"=",
"$",
"OUTPUT",
"->",
"image_url",
"(",
"file_file_icon",
"(",
"$",
"fileinfo",
",",
"90",
")",
")",
"->",
"out",
"(",
"false",
")",
";",
"$",
"node",
"[",
"'icon'",
"]",
"=",
"$",
"OUTPUT",
"->",
"image_url",
"(",
"file_file_icon",
"(",
"$",
"fileinfo",
",",
"24",
")",
")",
"->",
"out",
"(",
"false",
")",
";",
"if",
"(",
"$",
"imageinfo",
"=",
"$",
"fileinfo",
"->",
"get_imageinfo",
"(",
")",
")",
"{",
"// what a beautiful picture, isn't it",
"$",
"fileurl",
"=",
"new",
"moodle_url",
"(",
"$",
"fileinfo",
"->",
"get_url",
"(",
")",
")",
";",
"$",
"node",
"[",
"'realthumbnail'",
"]",
"=",
"$",
"fileurl",
"->",
"out",
"(",
"false",
",",
"array",
"(",
"'preview'",
"=>",
"'thumb'",
",",
"'oid'",
"=>",
"$",
"fileinfo",
"->",
"get_timemodified",
"(",
")",
")",
")",
";",
"$",
"node",
"[",
"'realicon'",
"]",
"=",
"$",
"fileurl",
"->",
"out",
"(",
"false",
",",
"array",
"(",
"'preview'",
"=>",
"'tinyicon'",
",",
"'oid'",
"=>",
"$",
"fileinfo",
"->",
"get_timemodified",
"(",
")",
")",
")",
";",
"$",
"node",
"[",
"'image_width'",
"]",
"=",
"$",
"imageinfo",
"[",
"'width'",
"]",
";",
"$",
"node",
"[",
"'image_height'",
"]",
"=",
"$",
"imageinfo",
"[",
"'height'",
"]",
";",
"}",
"}",
"return",
"$",
"node",
";",
"}"
] | Converts file_info object to element of repository return list
@param file_info $fileinfo
@return array | [
"Converts",
"file_info",
"object",
"to",
"element",
"of",
"repository",
"return",
"list"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/local/lib.php#L206-L239 |
212,455 | moodle/moodle | repository/local/lib.php | repository_local.get_node_path | private function get_node_path(file_info $fileinfo) {
$encodedpath = base64_encode(json_encode($fileinfo->get_params()));
return array(
'path' => $encodedpath,
'name' => $fileinfo->get_visible_name()
);
} | php | private function get_node_path(file_info $fileinfo) {
$encodedpath = base64_encode(json_encode($fileinfo->get_params()));
return array(
'path' => $encodedpath,
'name' => $fileinfo->get_visible_name()
);
} | [
"private",
"function",
"get_node_path",
"(",
"file_info",
"$",
"fileinfo",
")",
"{",
"$",
"encodedpath",
"=",
"base64_encode",
"(",
"json_encode",
"(",
"$",
"fileinfo",
"->",
"get_params",
"(",
")",
")",
")",
";",
"return",
"array",
"(",
"'path'",
"=>",
"$",
"encodedpath",
",",
"'name'",
"=>",
"$",
"fileinfo",
"->",
"get_visible_name",
"(",
")",
")",
";",
"}"
] | Converts file_info object to element of repository return path
@param file_info $fileinfo
@return array | [
"Converts",
"file_info",
"object",
"to",
"element",
"of",
"repository",
"return",
"path"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/local/lib.php#L247-L253 |
212,456 | moodle/moodle | repository/local/lib.php | repository_local.search | public function search($q, $page = 1) {
global $DB, $SESSION;
// Because the repository API is weird, the first page is 0, but it should be 1.
if (!$page) {
$page = 1;
}
if (!isset($SESSION->repository_local_search)) {
$SESSION->repository_local_search = array();
}
$fs = get_file_storage();
$fb = get_file_browser();
$max = 50;
$limit = 100;
if ($page <= 1) {
$SESSION->repository_local_search['query'] = $q;
$SESSION->repository_local_search['from'] = 0;
$from = 0;
} else {
// Yes, the repository does not send the query again...
$q = $SESSION->repository_local_search['query'];
$from = (int) $SESSION->repository_local_search['from'];
}
$count = $fs->search_server_files('%' . $DB->sql_like_escape($q) . '%', null, null, true);
$remaining = $count - $from;
$maxloops = 3000;
$loops = 0;
$results = array();
while (count($results) < $max && $maxloops > 0 && $remaining > 0) {
if (empty($files)) {
$files = $fs->search_server_files('%' . $DB->sql_like_escape($q) . '%', $from, $limit);
$from += $limit;
};
$remaining--;
$maxloops--;
$loops++;
$file = array_shift($files);
if (!$file) {
// This should not happen.
throw new coding_exception('Unexpected end of files list.');
}
$key = $file->get_contenthash() . ':' . $file->get_filename();
if (isset($results[$key])) {
// We found the file with same content and same name, let's skip it.
continue;
}
$ctx = context::instance_by_id($file->get_contextid());
$fileinfo = $fb->get_file_info($ctx, $file->get_component(), $file->get_filearea(), $file->get_itemid(),
$file->get_filepath(), $file->get_filename());
if ($fileinfo) {
$results[$key] = $this->get_node($fileinfo);
}
}
// Save the position for the paging to work.
if ($maxloops > 0 && $remaining > 0) {
$SESSION->repository_local_search['from'] += $loops;
$pages = -1;
} else {
$SESSION->repository_local_search['from'] = 0;
$pages = 0;
}
$return = array(
'list' => array_values($results),
'dynload' => true,
'pages' => $pages,
'page' => $page
);
return $return;
} | php | public function search($q, $page = 1) {
global $DB, $SESSION;
// Because the repository API is weird, the first page is 0, but it should be 1.
if (!$page) {
$page = 1;
}
if (!isset($SESSION->repository_local_search)) {
$SESSION->repository_local_search = array();
}
$fs = get_file_storage();
$fb = get_file_browser();
$max = 50;
$limit = 100;
if ($page <= 1) {
$SESSION->repository_local_search['query'] = $q;
$SESSION->repository_local_search['from'] = 0;
$from = 0;
} else {
// Yes, the repository does not send the query again...
$q = $SESSION->repository_local_search['query'];
$from = (int) $SESSION->repository_local_search['from'];
}
$count = $fs->search_server_files('%' . $DB->sql_like_escape($q) . '%', null, null, true);
$remaining = $count - $from;
$maxloops = 3000;
$loops = 0;
$results = array();
while (count($results) < $max && $maxloops > 0 && $remaining > 0) {
if (empty($files)) {
$files = $fs->search_server_files('%' . $DB->sql_like_escape($q) . '%', $from, $limit);
$from += $limit;
};
$remaining--;
$maxloops--;
$loops++;
$file = array_shift($files);
if (!$file) {
// This should not happen.
throw new coding_exception('Unexpected end of files list.');
}
$key = $file->get_contenthash() . ':' . $file->get_filename();
if (isset($results[$key])) {
// We found the file with same content and same name, let's skip it.
continue;
}
$ctx = context::instance_by_id($file->get_contextid());
$fileinfo = $fb->get_file_info($ctx, $file->get_component(), $file->get_filearea(), $file->get_itemid(),
$file->get_filepath(), $file->get_filename());
if ($fileinfo) {
$results[$key] = $this->get_node($fileinfo);
}
}
// Save the position for the paging to work.
if ($maxloops > 0 && $remaining > 0) {
$SESSION->repository_local_search['from'] += $loops;
$pages = -1;
} else {
$SESSION->repository_local_search['from'] = 0;
$pages = 0;
}
$return = array(
'list' => array_values($results),
'dynload' => true,
'pages' => $pages,
'page' => $page
);
return $return;
} | [
"public",
"function",
"search",
"(",
"$",
"q",
",",
"$",
"page",
"=",
"1",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"SESSION",
";",
"// Because the repository API is weird, the first page is 0, but it should be 1.",
"if",
"(",
"!",
"$",
"page",
")",
"{",
"$",
"page",
"=",
"1",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"SESSION",
"->",
"repository_local_search",
")",
")",
"{",
"$",
"SESSION",
"->",
"repository_local_search",
"=",
"array",
"(",
")",
";",
"}",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"$",
"fb",
"=",
"get_file_browser",
"(",
")",
";",
"$",
"max",
"=",
"50",
";",
"$",
"limit",
"=",
"100",
";",
"if",
"(",
"$",
"page",
"<=",
"1",
")",
"{",
"$",
"SESSION",
"->",
"repository_local_search",
"[",
"'query'",
"]",
"=",
"$",
"q",
";",
"$",
"SESSION",
"->",
"repository_local_search",
"[",
"'from'",
"]",
"=",
"0",
";",
"$",
"from",
"=",
"0",
";",
"}",
"else",
"{",
"// Yes, the repository does not send the query again...",
"$",
"q",
"=",
"$",
"SESSION",
"->",
"repository_local_search",
"[",
"'query'",
"]",
";",
"$",
"from",
"=",
"(",
"int",
")",
"$",
"SESSION",
"->",
"repository_local_search",
"[",
"'from'",
"]",
";",
"}",
"$",
"count",
"=",
"$",
"fs",
"->",
"search_server_files",
"(",
"'%'",
".",
"$",
"DB",
"->",
"sql_like_escape",
"(",
"$",
"q",
")",
".",
"'%'",
",",
"null",
",",
"null",
",",
"true",
")",
";",
"$",
"remaining",
"=",
"$",
"count",
"-",
"$",
"from",
";",
"$",
"maxloops",
"=",
"3000",
";",
"$",
"loops",
"=",
"0",
";",
"$",
"results",
"=",
"array",
"(",
")",
";",
"while",
"(",
"count",
"(",
"$",
"results",
")",
"<",
"$",
"max",
"&&",
"$",
"maxloops",
">",
"0",
"&&",
"$",
"remaining",
">",
"0",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"files",
")",
")",
"{",
"$",
"files",
"=",
"$",
"fs",
"->",
"search_server_files",
"(",
"'%'",
".",
"$",
"DB",
"->",
"sql_like_escape",
"(",
"$",
"q",
")",
".",
"'%'",
",",
"$",
"from",
",",
"$",
"limit",
")",
";",
"$",
"from",
"+=",
"$",
"limit",
";",
"}",
";",
"$",
"remaining",
"--",
";",
"$",
"maxloops",
"--",
";",
"$",
"loops",
"++",
";",
"$",
"file",
"=",
"array_shift",
"(",
"$",
"files",
")",
";",
"if",
"(",
"!",
"$",
"file",
")",
"{",
"// This should not happen.",
"throw",
"new",
"coding_exception",
"(",
"'Unexpected end of files list.'",
")",
";",
"}",
"$",
"key",
"=",
"$",
"file",
"->",
"get_contenthash",
"(",
")",
".",
"':'",
".",
"$",
"file",
"->",
"get_filename",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"results",
"[",
"$",
"key",
"]",
")",
")",
"{",
"// We found the file with same content and same name, let's skip it.",
"continue",
";",
"}",
"$",
"ctx",
"=",
"context",
"::",
"instance_by_id",
"(",
"$",
"file",
"->",
"get_contextid",
"(",
")",
")",
";",
"$",
"fileinfo",
"=",
"$",
"fb",
"->",
"get_file_info",
"(",
"$",
"ctx",
",",
"$",
"file",
"->",
"get_component",
"(",
")",
",",
"$",
"file",
"->",
"get_filearea",
"(",
")",
",",
"$",
"file",
"->",
"get_itemid",
"(",
")",
",",
"$",
"file",
"->",
"get_filepath",
"(",
")",
",",
"$",
"file",
"->",
"get_filename",
"(",
")",
")",
";",
"if",
"(",
"$",
"fileinfo",
")",
"{",
"$",
"results",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"get_node",
"(",
"$",
"fileinfo",
")",
";",
"}",
"}",
"// Save the position for the paging to work.",
"if",
"(",
"$",
"maxloops",
">",
"0",
"&&",
"$",
"remaining",
">",
"0",
")",
"{",
"$",
"SESSION",
"->",
"repository_local_search",
"[",
"'from'",
"]",
"+=",
"$",
"loops",
";",
"$",
"pages",
"=",
"-",
"1",
";",
"}",
"else",
"{",
"$",
"SESSION",
"->",
"repository_local_search",
"[",
"'from'",
"]",
"=",
"0",
";",
"$",
"pages",
"=",
"0",
";",
"}",
"$",
"return",
"=",
"array",
"(",
"'list'",
"=>",
"array_values",
"(",
"$",
"results",
")",
",",
"'dynload'",
"=>",
"true",
",",
"'pages'",
"=>",
"$",
"pages",
",",
"'page'",
"=>",
"$",
"page",
")",
";",
"return",
"$",
"return",
";",
"}"
] | Search through all the files.
This method will do a raw search through the database, then will try
to match with files that a user can access. A maximum of 50 files will be
returned at a time, excluding possible duplicates found along the way.
Queries are done in chunk of 100 files to prevent too many records to be fetched
at once. When too many files are not included, or a maximum of 10 queries are
performed we consider that this was the last page.
@param String $q The query string.
@param integer $page The page number.
@return array of results. | [
"Search",
"through",
"all",
"the",
"files",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/local/lib.php#L270-L351 |
212,457 | moodle/moodle | analytics/classes/local/indicator/community_of_inquiry_activity.php | community_of_inquiry_activity.fill_per_analysable_caches | public function fill_per_analysable_caches(\core_analytics\analysable $analysable) {
// Better to check it, we can not be 100% it will be a \core_analytics\course object.
if ($analysable instanceof \core_analytics\course) {
$this->fetch_student_grades($analysable);
}
} | php | public function fill_per_analysable_caches(\core_analytics\analysable $analysable) {
// Better to check it, we can not be 100% it will be a \core_analytics\course object.
if ($analysable instanceof \core_analytics\course) {
$this->fetch_student_grades($analysable);
}
} | [
"public",
"function",
"fill_per_analysable_caches",
"(",
"\\",
"core_analytics",
"\\",
"analysable",
"$",
"analysable",
")",
"{",
"// Better to check it, we can not be 100% it will be a \\core_analytics\\course object.",
"if",
"(",
"$",
"analysable",
"instanceof",
"\\",
"core_analytics",
"\\",
"course",
")",
"{",
"$",
"this",
"->",
"fetch_student_grades",
"(",
"$",
"analysable",
")",
";",
"}",
"}"
] | Fetch the course grades of this activity type instances.
@param \core_analytics\analysable $analysable
@return void | [
"Fetch",
"the",
"course",
"grades",
"of",
"this",
"activity",
"type",
"instances",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/indicator/community_of_inquiry_activity.php#L136-L142 |
212,458 | moodle/moodle | analytics/classes/local/indicator/community_of_inquiry_activity.php | community_of_inquiry_activity.get_activity_type | public final function get_activity_type() {
$class = get_class($this);
$package = stristr($class, "\\", true);
$type = str_replace("mod_", "", $package);
if ($type === $package) {
throw new \coding_exception("$class does not belong to any module specific namespace");
}
return $type;
} | php | public final function get_activity_type() {
$class = get_class($this);
$package = stristr($class, "\\", true);
$type = str_replace("mod_", "", $package);
if ($type === $package) {
throw new \coding_exception("$class does not belong to any module specific namespace");
}
return $type;
} | [
"public",
"final",
"function",
"get_activity_type",
"(",
")",
"{",
"$",
"class",
"=",
"get_class",
"(",
"$",
"this",
")",
";",
"$",
"package",
"=",
"stristr",
"(",
"$",
"class",
",",
"\"\\\\\"",
",",
"true",
")",
";",
"$",
"type",
"=",
"str_replace",
"(",
"\"mod_\"",
",",
"\"\"",
",",
"$",
"package",
")",
";",
"if",
"(",
"$",
"type",
"===",
"$",
"package",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"\"$class does not belong to any module specific namespace\"",
")",
";",
"}",
"return",
"$",
"type",
";",
"}"
] | Returns the activity type. No point in changing this class in children classes.
@var string The activity name (e.g. assign or quiz) | [
"Returns",
"the",
"activity",
"type",
".",
"No",
"point",
"in",
"changing",
"this",
"class",
"in",
"children",
"classes",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/indicator/community_of_inquiry_activity.php#L149-L157 |
212,459 | moodle/moodle | analytics/classes/local/indicator/community_of_inquiry_activity.php | community_of_inquiry_activity.any_log | protected final function any_log($contextid, $user) {
if (empty($this->activitylogs[$contextid])) {
return false;
}
// Someone interacted with the activity if there is no user or the user interacted with the
// activity if there is a user.
if (empty($user) ||
(!empty($user) && !empty($this->activitylogs[$contextid][$user->id]))) {
return true;
}
return false;
} | php | protected final function any_log($contextid, $user) {
if (empty($this->activitylogs[$contextid])) {
return false;
}
// Someone interacted with the activity if there is no user or the user interacted with the
// activity if there is a user.
if (empty($user) ||
(!empty($user) && !empty($this->activitylogs[$contextid][$user->id]))) {
return true;
}
return false;
} | [
"protected",
"final",
"function",
"any_log",
"(",
"$",
"contextid",
",",
"$",
"user",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"activitylogs",
"[",
"$",
"contextid",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Someone interacted with the activity if there is no user or the user interacted with the",
"// activity if there is a user.",
"if",
"(",
"empty",
"(",
"$",
"user",
")",
"||",
"(",
"!",
"empty",
"(",
"$",
"user",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"activitylogs",
"[",
"$",
"contextid",
"]",
"[",
"$",
"user",
"->",
"id",
"]",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Do activity logs contain any log of user in this context?
If user is empty we look for any log in this context.
@param int $contextid
@param \stdClass|false $user
@return bool | [
"Do",
"activity",
"logs",
"contain",
"any",
"log",
"of",
"user",
"in",
"this",
"context?"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/indicator/community_of_inquiry_activity.php#L200-L213 |
212,460 | moodle/moodle | analytics/classes/local/indicator/community_of_inquiry_activity.php | community_of_inquiry_activity.any_write_log | protected final function any_write_log($contextid, $user) {
if (empty($this->activitylogs[$contextid])) {
return false;
}
// No specific user, we look at all activity logs.
$it = $this->activitylogs[$contextid];
if ($user) {
if (empty($this->activitylogs[$contextid][$user->id])) {
return false;
}
$it = array($user->id => $this->activitylogs[$contextid][$user->id]);
}
foreach ($it as $events) {
foreach ($events as $log) {
if ($log->crud === 'c' || $log->crud === 'u') {
return true;
}
}
}
return false;
} | php | protected final function any_write_log($contextid, $user) {
if (empty($this->activitylogs[$contextid])) {
return false;
}
// No specific user, we look at all activity logs.
$it = $this->activitylogs[$contextid];
if ($user) {
if (empty($this->activitylogs[$contextid][$user->id])) {
return false;
}
$it = array($user->id => $this->activitylogs[$contextid][$user->id]);
}
foreach ($it as $events) {
foreach ($events as $log) {
if ($log->crud === 'c' || $log->crud === 'u') {
return true;
}
}
}
return false;
} | [
"protected",
"final",
"function",
"any_write_log",
"(",
"$",
"contextid",
",",
"$",
"user",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"activitylogs",
"[",
"$",
"contextid",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"// No specific user, we look at all activity logs.",
"$",
"it",
"=",
"$",
"this",
"->",
"activitylogs",
"[",
"$",
"contextid",
"]",
";",
"if",
"(",
"$",
"user",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"activitylogs",
"[",
"$",
"contextid",
"]",
"[",
"$",
"user",
"->",
"id",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"it",
"=",
"array",
"(",
"$",
"user",
"->",
"id",
"=>",
"$",
"this",
"->",
"activitylogs",
"[",
"$",
"contextid",
"]",
"[",
"$",
"user",
"->",
"id",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"it",
"as",
"$",
"events",
")",
"{",
"foreach",
"(",
"$",
"events",
"as",
"$",
"log",
")",
"{",
"if",
"(",
"$",
"log",
"->",
"crud",
"===",
"'c'",
"||",
"$",
"log",
"->",
"crud",
"===",
"'u'",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] | Do activity logs contain any write log of user in this context?
If user is empty we look for any write log in this context.
@param int $contextid
@param \stdClass|false $user
@return bool | [
"Do",
"activity",
"logs",
"contain",
"any",
"write",
"log",
"of",
"user",
"in",
"this",
"context?"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/indicator/community_of_inquiry_activity.php#L224-L246 |
212,461 | moodle/moodle | analytics/classes/local/indicator/community_of_inquiry_activity.php | community_of_inquiry_activity.any_feedback | protected function any_feedback($action, \cm_info $cm, $contextid, $user) {
if (!in_array($action, ['submitted', 'replied', 'viewed'])) {
throw new \coding_exception('Provided action "' . $action . '" is not valid.');
}
if (empty($this->activitylogs[$contextid])) {
return false;
}
if (empty($this->grades[$contextid]) && $this->feedback_check_grades()) {
// If there are no grades there is no feedback.
return false;
}
$it = $this->activitylogs[$contextid];
if ($user) {
if (empty($this->activitylogs[$contextid][$user->id])) {
return false;
}
$it = array($user->id => $this->activitylogs[$contextid][$user->id]);
}
foreach ($this->activitylogs[$contextid] as $userid => $events) {
$methodname = 'feedback_' . $action;
if ($this->{$methodname}($cm, $contextid, $userid)) {
return true;
}
// If it wasn't viewed try with the next user.
}
return false;
} | php | protected function any_feedback($action, \cm_info $cm, $contextid, $user) {
if (!in_array($action, ['submitted', 'replied', 'viewed'])) {
throw new \coding_exception('Provided action "' . $action . '" is not valid.');
}
if (empty($this->activitylogs[$contextid])) {
return false;
}
if (empty($this->grades[$contextid]) && $this->feedback_check_grades()) {
// If there are no grades there is no feedback.
return false;
}
$it = $this->activitylogs[$contextid];
if ($user) {
if (empty($this->activitylogs[$contextid][$user->id])) {
return false;
}
$it = array($user->id => $this->activitylogs[$contextid][$user->id]);
}
foreach ($this->activitylogs[$contextid] as $userid => $events) {
$methodname = 'feedback_' . $action;
if ($this->{$methodname}($cm, $contextid, $userid)) {
return true;
}
// If it wasn't viewed try with the next user.
}
return false;
} | [
"protected",
"function",
"any_feedback",
"(",
"$",
"action",
",",
"\\",
"cm_info",
"$",
"cm",
",",
"$",
"contextid",
",",
"$",
"user",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"action",
",",
"[",
"'submitted'",
",",
"'replied'",
",",
"'viewed'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Provided action \"'",
".",
"$",
"action",
".",
"'\" is not valid.'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"activitylogs",
"[",
"$",
"contextid",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"grades",
"[",
"$",
"contextid",
"]",
")",
"&&",
"$",
"this",
"->",
"feedback_check_grades",
"(",
")",
")",
"{",
"// If there are no grades there is no feedback.",
"return",
"false",
";",
"}",
"$",
"it",
"=",
"$",
"this",
"->",
"activitylogs",
"[",
"$",
"contextid",
"]",
";",
"if",
"(",
"$",
"user",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"activitylogs",
"[",
"$",
"contextid",
"]",
"[",
"$",
"user",
"->",
"id",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"it",
"=",
"array",
"(",
"$",
"user",
"->",
"id",
"=>",
"$",
"this",
"->",
"activitylogs",
"[",
"$",
"contextid",
"]",
"[",
"$",
"user",
"->",
"id",
"]",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"activitylogs",
"[",
"$",
"contextid",
"]",
"as",
"$",
"userid",
"=>",
"$",
"events",
")",
"{",
"$",
"methodname",
"=",
"'feedback_'",
".",
"$",
"action",
";",
"if",
"(",
"$",
"this",
"->",
"{",
"$",
"methodname",
"}",
"(",
"$",
"cm",
",",
"$",
"contextid",
",",
"$",
"userid",
")",
")",
"{",
"return",
"true",
";",
"}",
"// If it wasn't viewed try with the next user.",
"}",
"return",
"false",
";",
"}"
] | Is there any feedback activity log for this user in this context?
This method returns true if $user is empty and there is any feedback activity logs.
@param string $action
@param \cm_info $cm
@param int $contextid
@param \stdClass|false $user
@return bool | [
"Is",
"there",
"any",
"feedback",
"activity",
"log",
"for",
"this",
"user",
"in",
"this",
"context?"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/indicator/community_of_inquiry_activity.php#L259-L290 |
212,462 | moodle/moodle | analytics/classes/local/indicator/community_of_inquiry_activity.php | community_of_inquiry_activity.get_graded_date | protected function get_graded_date($contextid, $userid, $checkfeedback = false) {
if (empty($this->grades[$contextid][$userid])) {
return false;
}
foreach ($this->grades[$contextid][$userid] as $gradeitemid => $gradeitem) {
// We check that either feedback or the grade is set.
if (($checkfeedback && $gradeitem->feedback) || $gradeitem->grade) {
// Grab the first graded date.
if ($gradeitem->dategraded && (empty($after) || $gradeitem->dategraded < $after)) {
$after = $gradeitem->dategraded;
}
}
}
if (!isset($after)) {
// False if there are no graded items.
return false;
}
return $after;
} | php | protected function get_graded_date($contextid, $userid, $checkfeedback = false) {
if (empty($this->grades[$contextid][$userid])) {
return false;
}
foreach ($this->grades[$contextid][$userid] as $gradeitemid => $gradeitem) {
// We check that either feedback or the grade is set.
if (($checkfeedback && $gradeitem->feedback) || $gradeitem->grade) {
// Grab the first graded date.
if ($gradeitem->dategraded && (empty($after) || $gradeitem->dategraded < $after)) {
$after = $gradeitem->dategraded;
}
}
}
if (!isset($after)) {
// False if there are no graded items.
return false;
}
return $after;
} | [
"protected",
"function",
"get_graded_date",
"(",
"$",
"contextid",
",",
"$",
"userid",
",",
"$",
"checkfeedback",
"=",
"false",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"grades",
"[",
"$",
"contextid",
"]",
"[",
"$",
"userid",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"grades",
"[",
"$",
"contextid",
"]",
"[",
"$",
"userid",
"]",
"as",
"$",
"gradeitemid",
"=>",
"$",
"gradeitem",
")",
"{",
"// We check that either feedback or the grade is set.",
"if",
"(",
"(",
"$",
"checkfeedback",
"&&",
"$",
"gradeitem",
"->",
"feedback",
")",
"||",
"$",
"gradeitem",
"->",
"grade",
")",
"{",
"// Grab the first graded date.",
"if",
"(",
"$",
"gradeitem",
"->",
"dategraded",
"&&",
"(",
"empty",
"(",
"$",
"after",
")",
"||",
"$",
"gradeitem",
"->",
"dategraded",
"<",
"$",
"after",
")",
")",
"{",
"$",
"after",
"=",
"$",
"gradeitem",
"->",
"dategraded",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"after",
")",
")",
"{",
"// False if there are no graded items.",
"return",
"false",
";",
"}",
"return",
"$",
"after",
";",
"}"
] | Returns the date a user was graded.
@param int $contextid
@param int $userid
@param bool $checkfeedback Check that the student was graded or check that feedback was given
@return int|false | [
"Returns",
"the",
"date",
"a",
"user",
"was",
"graded",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/indicator/community_of_inquiry_activity.php#L423-L445 |
212,463 | moodle/moodle | analytics/classes/local/indicator/community_of_inquiry_activity.php | community_of_inquiry_activity.get_student_activities | protected function get_student_activities($sampleid, $tablename, $starttime, $endtime) {
// May not be available.
$user = $this->retrieve('user', $sampleid);
if ($this->course === null) {
// The indicator scope is a range, so all activities belong to the same course.
$this->course = \core_analytics\course::instance($this->retrieve('course', $sampleid));
}
if ($this->activitylogs === null) {
// Fetch all activity logs in each activity in the course, not restricted to a specific sample so we can cache it.
$courseactivities = $this->course->get_all_activities($this->get_activity_type());
// Null if no activities of this type in this course.
if (empty($courseactivities)) {
$this->activitylogs = false;
return null;
}
$this->activitylogs = $this->fetch_activity_logs($courseactivities, $starttime, $endtime);
}
if ($this->grades === null) {
// Even if this is probably already filled during fill_per_analysable_caches.
$this->fetch_student_grades($this->course);
}
if ($cm = $this->retrieve('cm', $sampleid)) {
// Samples are at cm level or below.
$useractivities = array(\context_module::instance($cm->id)->id => $cm);
} else {
// Activities that should be completed during this time period.
$useractivities = $this->get_activities($starttime, $endtime, $user);
}
return $useractivities;
} | php | protected function get_student_activities($sampleid, $tablename, $starttime, $endtime) {
// May not be available.
$user = $this->retrieve('user', $sampleid);
if ($this->course === null) {
// The indicator scope is a range, so all activities belong to the same course.
$this->course = \core_analytics\course::instance($this->retrieve('course', $sampleid));
}
if ($this->activitylogs === null) {
// Fetch all activity logs in each activity in the course, not restricted to a specific sample so we can cache it.
$courseactivities = $this->course->get_all_activities($this->get_activity_type());
// Null if no activities of this type in this course.
if (empty($courseactivities)) {
$this->activitylogs = false;
return null;
}
$this->activitylogs = $this->fetch_activity_logs($courseactivities, $starttime, $endtime);
}
if ($this->grades === null) {
// Even if this is probably already filled during fill_per_analysable_caches.
$this->fetch_student_grades($this->course);
}
if ($cm = $this->retrieve('cm', $sampleid)) {
// Samples are at cm level or below.
$useractivities = array(\context_module::instance($cm->id)->id => $cm);
} else {
// Activities that should be completed during this time period.
$useractivities = $this->get_activities($starttime, $endtime, $user);
}
return $useractivities;
} | [
"protected",
"function",
"get_student_activities",
"(",
"$",
"sampleid",
",",
"$",
"tablename",
",",
"$",
"starttime",
",",
"$",
"endtime",
")",
"{",
"// May not be available.",
"$",
"user",
"=",
"$",
"this",
"->",
"retrieve",
"(",
"'user'",
",",
"$",
"sampleid",
")",
";",
"if",
"(",
"$",
"this",
"->",
"course",
"===",
"null",
")",
"{",
"// The indicator scope is a range, so all activities belong to the same course.",
"$",
"this",
"->",
"course",
"=",
"\\",
"core_analytics",
"\\",
"course",
"::",
"instance",
"(",
"$",
"this",
"->",
"retrieve",
"(",
"'course'",
",",
"$",
"sampleid",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"activitylogs",
"===",
"null",
")",
"{",
"// Fetch all activity logs in each activity in the course, not restricted to a specific sample so we can cache it.",
"$",
"courseactivities",
"=",
"$",
"this",
"->",
"course",
"->",
"get_all_activities",
"(",
"$",
"this",
"->",
"get_activity_type",
"(",
")",
")",
";",
"// Null if no activities of this type in this course.",
"if",
"(",
"empty",
"(",
"$",
"courseactivities",
")",
")",
"{",
"$",
"this",
"->",
"activitylogs",
"=",
"false",
";",
"return",
"null",
";",
"}",
"$",
"this",
"->",
"activitylogs",
"=",
"$",
"this",
"->",
"fetch_activity_logs",
"(",
"$",
"courseactivities",
",",
"$",
"starttime",
",",
"$",
"endtime",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"grades",
"===",
"null",
")",
"{",
"// Even if this is probably already filled during fill_per_analysable_caches.",
"$",
"this",
"->",
"fetch_student_grades",
"(",
"$",
"this",
"->",
"course",
")",
";",
"}",
"if",
"(",
"$",
"cm",
"=",
"$",
"this",
"->",
"retrieve",
"(",
"'cm'",
",",
"$",
"sampleid",
")",
")",
"{",
"// Samples are at cm level or below.",
"$",
"useractivities",
"=",
"array",
"(",
"\\",
"context_module",
"::",
"instance",
"(",
"$",
"cm",
"->",
"id",
")",
"->",
"id",
"=>",
"$",
"cm",
")",
";",
"}",
"else",
"{",
"// Activities that should be completed during this time period.",
"$",
"useractivities",
"=",
"$",
"this",
"->",
"get_activities",
"(",
"$",
"starttime",
",",
"$",
"endtime",
",",
"$",
"user",
")",
";",
"}",
"return",
"$",
"useractivities",
";",
"}"
] | Returns the activities the user had access to between a time period.
@param int $sampleid
@param string $tablename
@param int $starttime
@param int $endtime
@return array | [
"Returns",
"the",
"activities",
"the",
"user",
"had",
"access",
"to",
"between",
"a",
"time",
"period",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/indicator/community_of_inquiry_activity.php#L456-L493 |
212,464 | moodle/moodle | analytics/classes/local/indicator/community_of_inquiry_activity.php | community_of_inquiry_activity.fetch_activity_logs | protected function fetch_activity_logs($activities, $starttime = false, $endtime = false) {
global $DB;
// Filter by context to use the db table index.
list($contextsql, $contextparams) = $DB->get_in_or_equal(array_keys($activities), SQL_PARAMS_NAMED);
$select = "contextid $contextsql AND timecreated > :starttime AND timecreated <= :endtime";
$params = $contextparams + array('starttime' => $starttime, 'endtime' => $endtime);
// Pity that we need to pass through logging readers API when most of the people just uses the standard one.
if (!$logstore = \core_analytics\manager::get_analytics_logstore()) {
throw new \coding_exception('No log store available');
}
$events = $logstore->get_events_select_iterator($select, $params, 'timecreated ASC', 0, 0);
// Returs the logs organised by contextid, userid and eventname so it is easier to calculate activities data later.
// At the same time we want to keep this array reasonably "not-massive".
$processedevents = array();
foreach ($events as $event) {
if (!isset($processedevents[$event->contextid])) {
$processedevents[$event->contextid] = array();
}
if (!isset($processedevents[$event->contextid][$event->userid])) {
$processedevents[$event->contextid][$event->userid] = array();
}
// Contextid and userid have already been used to index the events, the next field to index by is eventname:
// crud is unique per eventname, courseid is the same for all records and we append timecreated.
if (!isset($processedevents[$event->contextid][$event->userid][$event->eventname])) {
// Remove all data that can change between events of the same type.
$data = (object)$event->get_data();
unset($data->id);
unset($data->anonymous);
unset($data->relateduserid);
unset($data->other);
unset($data->origin);
unset($data->ip);
$processedevents[$event->contextid][$event->userid][$event->eventname] = $data;
// We want timecreated attribute to be an array containing all user access times.
$processedevents[$event->contextid][$event->userid][$event->eventname]->timecreated = array();
}
// Add the event timecreated.
$processedevents[$event->contextid][$event->userid][$event->eventname]->timecreated[] = intval($event->timecreated);
}
$events->close();
return $processedevents;
} | php | protected function fetch_activity_logs($activities, $starttime = false, $endtime = false) {
global $DB;
// Filter by context to use the db table index.
list($contextsql, $contextparams) = $DB->get_in_or_equal(array_keys($activities), SQL_PARAMS_NAMED);
$select = "contextid $contextsql AND timecreated > :starttime AND timecreated <= :endtime";
$params = $contextparams + array('starttime' => $starttime, 'endtime' => $endtime);
// Pity that we need to pass through logging readers API when most of the people just uses the standard one.
if (!$logstore = \core_analytics\manager::get_analytics_logstore()) {
throw new \coding_exception('No log store available');
}
$events = $logstore->get_events_select_iterator($select, $params, 'timecreated ASC', 0, 0);
// Returs the logs organised by contextid, userid and eventname so it is easier to calculate activities data later.
// At the same time we want to keep this array reasonably "not-massive".
$processedevents = array();
foreach ($events as $event) {
if (!isset($processedevents[$event->contextid])) {
$processedevents[$event->contextid] = array();
}
if (!isset($processedevents[$event->contextid][$event->userid])) {
$processedevents[$event->contextid][$event->userid] = array();
}
// Contextid and userid have already been used to index the events, the next field to index by is eventname:
// crud is unique per eventname, courseid is the same for all records and we append timecreated.
if (!isset($processedevents[$event->contextid][$event->userid][$event->eventname])) {
// Remove all data that can change between events of the same type.
$data = (object)$event->get_data();
unset($data->id);
unset($data->anonymous);
unset($data->relateduserid);
unset($data->other);
unset($data->origin);
unset($data->ip);
$processedevents[$event->contextid][$event->userid][$event->eventname] = $data;
// We want timecreated attribute to be an array containing all user access times.
$processedevents[$event->contextid][$event->userid][$event->eventname]->timecreated = array();
}
// Add the event timecreated.
$processedevents[$event->contextid][$event->userid][$event->eventname]->timecreated[] = intval($event->timecreated);
}
$events->close();
return $processedevents;
} | [
"protected",
"function",
"fetch_activity_logs",
"(",
"$",
"activities",
",",
"$",
"starttime",
"=",
"false",
",",
"$",
"endtime",
"=",
"false",
")",
"{",
"global",
"$",
"DB",
";",
"// Filter by context to use the db table index.",
"list",
"(",
"$",
"contextsql",
",",
"$",
"contextparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"array_keys",
"(",
"$",
"activities",
")",
",",
"SQL_PARAMS_NAMED",
")",
";",
"$",
"select",
"=",
"\"contextid $contextsql AND timecreated > :starttime AND timecreated <= :endtime\"",
";",
"$",
"params",
"=",
"$",
"contextparams",
"+",
"array",
"(",
"'starttime'",
"=>",
"$",
"starttime",
",",
"'endtime'",
"=>",
"$",
"endtime",
")",
";",
"// Pity that we need to pass through logging readers API when most of the people just uses the standard one.",
"if",
"(",
"!",
"$",
"logstore",
"=",
"\\",
"core_analytics",
"\\",
"manager",
"::",
"get_analytics_logstore",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'No log store available'",
")",
";",
"}",
"$",
"events",
"=",
"$",
"logstore",
"->",
"get_events_select_iterator",
"(",
"$",
"select",
",",
"$",
"params",
",",
"'timecreated ASC'",
",",
"0",
",",
"0",
")",
";",
"// Returs the logs organised by contextid, userid and eventname so it is easier to calculate activities data later.",
"// At the same time we want to keep this array reasonably \"not-massive\".",
"$",
"processedevents",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"events",
"as",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"processedevents",
"[",
"$",
"event",
"->",
"contextid",
"]",
")",
")",
"{",
"$",
"processedevents",
"[",
"$",
"event",
"->",
"contextid",
"]",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"processedevents",
"[",
"$",
"event",
"->",
"contextid",
"]",
"[",
"$",
"event",
"->",
"userid",
"]",
")",
")",
"{",
"$",
"processedevents",
"[",
"$",
"event",
"->",
"contextid",
"]",
"[",
"$",
"event",
"->",
"userid",
"]",
"=",
"array",
"(",
")",
";",
"}",
"// Contextid and userid have already been used to index the events, the next field to index by is eventname:",
"// crud is unique per eventname, courseid is the same for all records and we append timecreated.",
"if",
"(",
"!",
"isset",
"(",
"$",
"processedevents",
"[",
"$",
"event",
"->",
"contextid",
"]",
"[",
"$",
"event",
"->",
"userid",
"]",
"[",
"$",
"event",
"->",
"eventname",
"]",
")",
")",
"{",
"// Remove all data that can change between events of the same type.",
"$",
"data",
"=",
"(",
"object",
")",
"$",
"event",
"->",
"get_data",
"(",
")",
";",
"unset",
"(",
"$",
"data",
"->",
"id",
")",
";",
"unset",
"(",
"$",
"data",
"->",
"anonymous",
")",
";",
"unset",
"(",
"$",
"data",
"->",
"relateduserid",
")",
";",
"unset",
"(",
"$",
"data",
"->",
"other",
")",
";",
"unset",
"(",
"$",
"data",
"->",
"origin",
")",
";",
"unset",
"(",
"$",
"data",
"->",
"ip",
")",
";",
"$",
"processedevents",
"[",
"$",
"event",
"->",
"contextid",
"]",
"[",
"$",
"event",
"->",
"userid",
"]",
"[",
"$",
"event",
"->",
"eventname",
"]",
"=",
"$",
"data",
";",
"// We want timecreated attribute to be an array containing all user access times.",
"$",
"processedevents",
"[",
"$",
"event",
"->",
"contextid",
"]",
"[",
"$",
"event",
"->",
"userid",
"]",
"[",
"$",
"event",
"->",
"eventname",
"]",
"->",
"timecreated",
"=",
"array",
"(",
")",
";",
"}",
"// Add the event timecreated.",
"$",
"processedevents",
"[",
"$",
"event",
"->",
"contextid",
"]",
"[",
"$",
"event",
"->",
"userid",
"]",
"[",
"$",
"event",
"->",
"eventname",
"]",
"->",
"timecreated",
"[",
"]",
"=",
"intval",
"(",
"$",
"event",
"->",
"timecreated",
")",
";",
"}",
"$",
"events",
"->",
"close",
"(",
")",
";",
"return",
"$",
"processedevents",
";",
"}"
] | Fetch acitivity logs from database
@param array $activities
@param int $starttime
@param int $endtime
@return array | [
"Fetch",
"acitivity",
"logs",
"from",
"database"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/indicator/community_of_inquiry_activity.php#L503-L551 |
212,465 | moodle/moodle | analytics/classes/local/indicator/community_of_inquiry_activity.php | community_of_inquiry_activity.cognitive_calculate_sample | protected function cognitive_calculate_sample($sampleid, $tablename, $starttime = false, $endtime = false) {
// May not be available.
$user = $this->retrieve('user', $sampleid);
if (!$useractivities = $this->get_student_activities($sampleid, $tablename, $starttime, $endtime)) {
// Null if no activities.
return null;
}
$scoreperactivity = (self::get_max_value() - self::get_min_value()) / count($useractivities);
$score = self::get_min_value();
// Iterate through the module activities/resources which due date is part of this time range.
foreach ($useractivities as $contextid => $cm) {
$potentiallevel = $this->get_cognitive_depth_level($cm);
if (!is_int($potentiallevel)
|| $potentiallevel > self::MAX_COGNITIVE_LEVEL
|| $potentiallevel < self::COGNITIVE_LEVEL_1) {
throw new \coding_exception('Activities\' potential cognitive depth go from 1 to 5.');
}
$scoreperlevel = $scoreperactivity / $potentiallevel;
switch ($potentiallevel) {
case self::COGNITIVE_LEVEL_5:
// Cognitive level 5 is to submit after feedback.
if ($this->any_feedback('submitted', $cm, $contextid, $user)) {
$score += $scoreperlevel * 5;
break;
}
// The user didn't reach the activity max cognitive depth, continue with level 2.
case self::COGNITIVE_LEVEL_4:
// Cognitive level 4 is to comment on feedback.
if ($this->any_feedback('replied', $cm, $contextid, $user)) {
$score += $scoreperlevel * 4;
break;
}
// The user didn't reach the activity max cognitive depth, continue with level 2.
case self::COGNITIVE_LEVEL_3:
// Cognitive level 3 is to view feedback.
if ($this->any_feedback('viewed', $cm, $contextid, $user)) {
// Max score for level 3.
$score += $scoreperlevel * 3;
break;
}
// The user didn't reach the activity max cognitive depth, continue with level 2.
case self::COGNITIVE_LEVEL_2:
// Cognitive depth level 2 is to submit content.
if ($this->any_write_log($contextid, $user)) {
$score += $scoreperlevel * 2;
break;
}
// The user didn't reach the activity max cognitive depth, continue with level 1.
case self::COGNITIVE_LEVEL_1:
// Cognitive depth level 1 is just accessing the activity.
if ($this->any_log($contextid, $user)) {
$score += $scoreperlevel;
}
default:
}
}
// To avoid decimal problems.
if ($score > self::MAX_VALUE) {
return self::MAX_VALUE;
} else if ($score < self::MIN_VALUE) {
return self::MIN_VALUE;
}
return $score;
} | php | protected function cognitive_calculate_sample($sampleid, $tablename, $starttime = false, $endtime = false) {
// May not be available.
$user = $this->retrieve('user', $sampleid);
if (!$useractivities = $this->get_student_activities($sampleid, $tablename, $starttime, $endtime)) {
// Null if no activities.
return null;
}
$scoreperactivity = (self::get_max_value() - self::get_min_value()) / count($useractivities);
$score = self::get_min_value();
// Iterate through the module activities/resources which due date is part of this time range.
foreach ($useractivities as $contextid => $cm) {
$potentiallevel = $this->get_cognitive_depth_level($cm);
if (!is_int($potentiallevel)
|| $potentiallevel > self::MAX_COGNITIVE_LEVEL
|| $potentiallevel < self::COGNITIVE_LEVEL_1) {
throw new \coding_exception('Activities\' potential cognitive depth go from 1 to 5.');
}
$scoreperlevel = $scoreperactivity / $potentiallevel;
switch ($potentiallevel) {
case self::COGNITIVE_LEVEL_5:
// Cognitive level 5 is to submit after feedback.
if ($this->any_feedback('submitted', $cm, $contextid, $user)) {
$score += $scoreperlevel * 5;
break;
}
// The user didn't reach the activity max cognitive depth, continue with level 2.
case self::COGNITIVE_LEVEL_4:
// Cognitive level 4 is to comment on feedback.
if ($this->any_feedback('replied', $cm, $contextid, $user)) {
$score += $scoreperlevel * 4;
break;
}
// The user didn't reach the activity max cognitive depth, continue with level 2.
case self::COGNITIVE_LEVEL_3:
// Cognitive level 3 is to view feedback.
if ($this->any_feedback('viewed', $cm, $contextid, $user)) {
// Max score for level 3.
$score += $scoreperlevel * 3;
break;
}
// The user didn't reach the activity max cognitive depth, continue with level 2.
case self::COGNITIVE_LEVEL_2:
// Cognitive depth level 2 is to submit content.
if ($this->any_write_log($contextid, $user)) {
$score += $scoreperlevel * 2;
break;
}
// The user didn't reach the activity max cognitive depth, continue with level 1.
case self::COGNITIVE_LEVEL_1:
// Cognitive depth level 1 is just accessing the activity.
if ($this->any_log($contextid, $user)) {
$score += $scoreperlevel;
}
default:
}
}
// To avoid decimal problems.
if ($score > self::MAX_VALUE) {
return self::MAX_VALUE;
} else if ($score < self::MIN_VALUE) {
return self::MIN_VALUE;
}
return $score;
} | [
"protected",
"function",
"cognitive_calculate_sample",
"(",
"$",
"sampleid",
",",
"$",
"tablename",
",",
"$",
"starttime",
"=",
"false",
",",
"$",
"endtime",
"=",
"false",
")",
"{",
"// May not be available.",
"$",
"user",
"=",
"$",
"this",
"->",
"retrieve",
"(",
"'user'",
",",
"$",
"sampleid",
")",
";",
"if",
"(",
"!",
"$",
"useractivities",
"=",
"$",
"this",
"->",
"get_student_activities",
"(",
"$",
"sampleid",
",",
"$",
"tablename",
",",
"$",
"starttime",
",",
"$",
"endtime",
")",
")",
"{",
"// Null if no activities.",
"return",
"null",
";",
"}",
"$",
"scoreperactivity",
"=",
"(",
"self",
"::",
"get_max_value",
"(",
")",
"-",
"self",
"::",
"get_min_value",
"(",
")",
")",
"/",
"count",
"(",
"$",
"useractivities",
")",
";",
"$",
"score",
"=",
"self",
"::",
"get_min_value",
"(",
")",
";",
"// Iterate through the module activities/resources which due date is part of this time range.",
"foreach",
"(",
"$",
"useractivities",
"as",
"$",
"contextid",
"=>",
"$",
"cm",
")",
"{",
"$",
"potentiallevel",
"=",
"$",
"this",
"->",
"get_cognitive_depth_level",
"(",
"$",
"cm",
")",
";",
"if",
"(",
"!",
"is_int",
"(",
"$",
"potentiallevel",
")",
"||",
"$",
"potentiallevel",
">",
"self",
"::",
"MAX_COGNITIVE_LEVEL",
"||",
"$",
"potentiallevel",
"<",
"self",
"::",
"COGNITIVE_LEVEL_1",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Activities\\' potential cognitive depth go from 1 to 5.'",
")",
";",
"}",
"$",
"scoreperlevel",
"=",
"$",
"scoreperactivity",
"/",
"$",
"potentiallevel",
";",
"switch",
"(",
"$",
"potentiallevel",
")",
"{",
"case",
"self",
"::",
"COGNITIVE_LEVEL_5",
":",
"// Cognitive level 5 is to submit after feedback.",
"if",
"(",
"$",
"this",
"->",
"any_feedback",
"(",
"'submitted'",
",",
"$",
"cm",
",",
"$",
"contextid",
",",
"$",
"user",
")",
")",
"{",
"$",
"score",
"+=",
"$",
"scoreperlevel",
"*",
"5",
";",
"break",
";",
"}",
"// The user didn't reach the activity max cognitive depth, continue with level 2.",
"case",
"self",
"::",
"COGNITIVE_LEVEL_4",
":",
"// Cognitive level 4 is to comment on feedback.",
"if",
"(",
"$",
"this",
"->",
"any_feedback",
"(",
"'replied'",
",",
"$",
"cm",
",",
"$",
"contextid",
",",
"$",
"user",
")",
")",
"{",
"$",
"score",
"+=",
"$",
"scoreperlevel",
"*",
"4",
";",
"break",
";",
"}",
"// The user didn't reach the activity max cognitive depth, continue with level 2.",
"case",
"self",
"::",
"COGNITIVE_LEVEL_3",
":",
"// Cognitive level 3 is to view feedback.",
"if",
"(",
"$",
"this",
"->",
"any_feedback",
"(",
"'viewed'",
",",
"$",
"cm",
",",
"$",
"contextid",
",",
"$",
"user",
")",
")",
"{",
"// Max score for level 3.",
"$",
"score",
"+=",
"$",
"scoreperlevel",
"*",
"3",
";",
"break",
";",
"}",
"// The user didn't reach the activity max cognitive depth, continue with level 2.",
"case",
"self",
"::",
"COGNITIVE_LEVEL_2",
":",
"// Cognitive depth level 2 is to submit content.",
"if",
"(",
"$",
"this",
"->",
"any_write_log",
"(",
"$",
"contextid",
",",
"$",
"user",
")",
")",
"{",
"$",
"score",
"+=",
"$",
"scoreperlevel",
"*",
"2",
";",
"break",
";",
"}",
"// The user didn't reach the activity max cognitive depth, continue with level 1.",
"case",
"self",
"::",
"COGNITIVE_LEVEL_1",
":",
"// Cognitive depth level 1 is just accessing the activity.",
"if",
"(",
"$",
"this",
"->",
"any_log",
"(",
"$",
"contextid",
",",
"$",
"user",
")",
")",
"{",
"$",
"score",
"+=",
"$",
"scoreperlevel",
";",
"}",
"default",
":",
"}",
"}",
"// To avoid decimal problems.",
"if",
"(",
"$",
"score",
">",
"self",
"::",
"MAX_VALUE",
")",
"{",
"return",
"self",
"::",
"MAX_VALUE",
";",
"}",
"else",
"if",
"(",
"$",
"score",
"<",
"self",
"::",
"MIN_VALUE",
")",
"{",
"return",
"self",
"::",
"MIN_VALUE",
";",
"}",
"return",
"$",
"score",
";",
"}"
] | Calculates the cognitive depth of a sample.
@param int $sampleid
@param string $tablename
@param int $starttime
@param int $endtime
@return float|int|null
@throws \coding_exception | [
"Calculates",
"the",
"cognitive",
"depth",
"of",
"a",
"sample",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/indicator/community_of_inquiry_activity.php#L572-L651 |
212,466 | moodle/moodle | analytics/classes/local/indicator/community_of_inquiry_activity.php | community_of_inquiry_activity.social_calculate_sample | protected function social_calculate_sample($sampleid, $tablename, $starttime = false, $endtime = false) {
// May not be available.
$user = $this->retrieve('user', $sampleid);
if (!$useractivities = $this->get_student_activities($sampleid, $tablename, $starttime, $endtime)) {
// Null if no activities.
return null;
}
$scoreperactivity = (self::get_max_value() - self::get_min_value()) / count($useractivities);
$score = self::get_min_value();
foreach ($useractivities as $contextid => $cm) {
$potentiallevel = $this->get_social_breadth_level($cm);
if (!is_int($potentiallevel)
|| $potentiallevel > self::MAX_SOCIAL_LEVEL
|| $potentiallevel < self::SOCIAL_LEVEL_1) {
throw new \coding_exception('Activities\' potential social breadth go from 1 to ' .
community_of_inquiry_activity::MAX_SOCIAL_LEVEL . '.');
}
$scoreperlevel = $scoreperactivity / $potentiallevel;
switch ($potentiallevel) {
case self::SOCIAL_LEVEL_2:
case self::SOCIAL_LEVEL_3:
case self::SOCIAL_LEVEL_4:
case self::SOCIAL_LEVEL_5:
// Core activities social breadth only reaches level 2, until core activities social
// breadth do not reach level 5 we limit it to what we currently support, which is level 2.
// Social breadth level 2 is to view feedback. (Same as cognitive level 3).
if ($this->any_feedback('viewed', $cm, $contextid, $user)) {
// Max score for level 2.
$score += $scoreperlevel * 2;
break;
}
// The user didn't reach the activity max social breadth, continue with level 1.
case self::SOCIAL_LEVEL_1:
// Social breadth level 1 is just accessing the activity.
if ($this->any_log($contextid, $user)) {
$score += $scoreperlevel;
}
}
}
// To avoid decimal problems.
if ($score > self::MAX_VALUE) {
return self::MAX_VALUE;
} else if ($score < self::MIN_VALUE) {
return self::MIN_VALUE;
}
return $score;
} | php | protected function social_calculate_sample($sampleid, $tablename, $starttime = false, $endtime = false) {
// May not be available.
$user = $this->retrieve('user', $sampleid);
if (!$useractivities = $this->get_student_activities($sampleid, $tablename, $starttime, $endtime)) {
// Null if no activities.
return null;
}
$scoreperactivity = (self::get_max_value() - self::get_min_value()) / count($useractivities);
$score = self::get_min_value();
foreach ($useractivities as $contextid => $cm) {
$potentiallevel = $this->get_social_breadth_level($cm);
if (!is_int($potentiallevel)
|| $potentiallevel > self::MAX_SOCIAL_LEVEL
|| $potentiallevel < self::SOCIAL_LEVEL_1) {
throw new \coding_exception('Activities\' potential social breadth go from 1 to ' .
community_of_inquiry_activity::MAX_SOCIAL_LEVEL . '.');
}
$scoreperlevel = $scoreperactivity / $potentiallevel;
switch ($potentiallevel) {
case self::SOCIAL_LEVEL_2:
case self::SOCIAL_LEVEL_3:
case self::SOCIAL_LEVEL_4:
case self::SOCIAL_LEVEL_5:
// Core activities social breadth only reaches level 2, until core activities social
// breadth do not reach level 5 we limit it to what we currently support, which is level 2.
// Social breadth level 2 is to view feedback. (Same as cognitive level 3).
if ($this->any_feedback('viewed', $cm, $contextid, $user)) {
// Max score for level 2.
$score += $scoreperlevel * 2;
break;
}
// The user didn't reach the activity max social breadth, continue with level 1.
case self::SOCIAL_LEVEL_1:
// Social breadth level 1 is just accessing the activity.
if ($this->any_log($contextid, $user)) {
$score += $scoreperlevel;
}
}
}
// To avoid decimal problems.
if ($score > self::MAX_VALUE) {
return self::MAX_VALUE;
} else if ($score < self::MIN_VALUE) {
return self::MIN_VALUE;
}
return $score;
} | [
"protected",
"function",
"social_calculate_sample",
"(",
"$",
"sampleid",
",",
"$",
"tablename",
",",
"$",
"starttime",
"=",
"false",
",",
"$",
"endtime",
"=",
"false",
")",
"{",
"// May not be available.",
"$",
"user",
"=",
"$",
"this",
"->",
"retrieve",
"(",
"'user'",
",",
"$",
"sampleid",
")",
";",
"if",
"(",
"!",
"$",
"useractivities",
"=",
"$",
"this",
"->",
"get_student_activities",
"(",
"$",
"sampleid",
",",
"$",
"tablename",
",",
"$",
"starttime",
",",
"$",
"endtime",
")",
")",
"{",
"// Null if no activities.",
"return",
"null",
";",
"}",
"$",
"scoreperactivity",
"=",
"(",
"self",
"::",
"get_max_value",
"(",
")",
"-",
"self",
"::",
"get_min_value",
"(",
")",
")",
"/",
"count",
"(",
"$",
"useractivities",
")",
";",
"$",
"score",
"=",
"self",
"::",
"get_min_value",
"(",
")",
";",
"foreach",
"(",
"$",
"useractivities",
"as",
"$",
"contextid",
"=>",
"$",
"cm",
")",
"{",
"$",
"potentiallevel",
"=",
"$",
"this",
"->",
"get_social_breadth_level",
"(",
"$",
"cm",
")",
";",
"if",
"(",
"!",
"is_int",
"(",
"$",
"potentiallevel",
")",
"||",
"$",
"potentiallevel",
">",
"self",
"::",
"MAX_SOCIAL_LEVEL",
"||",
"$",
"potentiallevel",
"<",
"self",
"::",
"SOCIAL_LEVEL_1",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Activities\\' potential social breadth go from 1 to '",
".",
"community_of_inquiry_activity",
"::",
"MAX_SOCIAL_LEVEL",
".",
"'.'",
")",
";",
"}",
"$",
"scoreperlevel",
"=",
"$",
"scoreperactivity",
"/",
"$",
"potentiallevel",
";",
"switch",
"(",
"$",
"potentiallevel",
")",
"{",
"case",
"self",
"::",
"SOCIAL_LEVEL_2",
":",
"case",
"self",
"::",
"SOCIAL_LEVEL_3",
":",
"case",
"self",
"::",
"SOCIAL_LEVEL_4",
":",
"case",
"self",
"::",
"SOCIAL_LEVEL_5",
":",
"// Core activities social breadth only reaches level 2, until core activities social",
"// breadth do not reach level 5 we limit it to what we currently support, which is level 2.",
"// Social breadth level 2 is to view feedback. (Same as cognitive level 3).",
"if",
"(",
"$",
"this",
"->",
"any_feedback",
"(",
"'viewed'",
",",
"$",
"cm",
",",
"$",
"contextid",
",",
"$",
"user",
")",
")",
"{",
"// Max score for level 2.",
"$",
"score",
"+=",
"$",
"scoreperlevel",
"*",
"2",
";",
"break",
";",
"}",
"// The user didn't reach the activity max social breadth, continue with level 1.",
"case",
"self",
"::",
"SOCIAL_LEVEL_1",
":",
"// Social breadth level 1 is just accessing the activity.",
"if",
"(",
"$",
"this",
"->",
"any_log",
"(",
"$",
"contextid",
",",
"$",
"user",
")",
")",
"{",
"$",
"score",
"+=",
"$",
"scoreperlevel",
";",
"}",
"}",
"}",
"// To avoid decimal problems.",
"if",
"(",
"$",
"score",
">",
"self",
"::",
"MAX_VALUE",
")",
"{",
"return",
"self",
"::",
"MAX_VALUE",
";",
"}",
"else",
"if",
"(",
"$",
"score",
"<",
"self",
"::",
"MIN_VALUE",
")",
"{",
"return",
"self",
"::",
"MIN_VALUE",
";",
"}",
"return",
"$",
"score",
";",
"}"
] | Calculates the social breadth of a sample.
@param int $sampleid
@param string $tablename
@param int $starttime
@param int $endtime
@return float|int|null | [
"Calculates",
"the",
"social",
"breadth",
"of",
"a",
"sample",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/indicator/community_of_inquiry_activity.php#L662-L719 |
212,467 | moodle/moodle | analytics/classes/local/indicator/community_of_inquiry_activity.php | community_of_inquiry_activity.fetch_student_grades | protected function fetch_student_grades(\core_analytics\course $course) {
$courseactivities = $course->get_all_activities($this->get_activity_type());
$this->grades = $course->get_student_grades($courseactivities);
} | php | protected function fetch_student_grades(\core_analytics\course $course) {
$courseactivities = $course->get_all_activities($this->get_activity_type());
$this->grades = $course->get_student_grades($courseactivities);
} | [
"protected",
"function",
"fetch_student_grades",
"(",
"\\",
"core_analytics",
"\\",
"course",
"$",
"course",
")",
"{",
"$",
"courseactivities",
"=",
"$",
"course",
"->",
"get_all_activities",
"(",
"$",
"this",
"->",
"get_activity_type",
"(",
")",
")",
";",
"$",
"this",
"->",
"grades",
"=",
"$",
"course",
"->",
"get_student_grades",
"(",
"$",
"courseactivities",
")",
";",
"}"
] | Gets the course student grades.
@param \core_analytics\course $course
@return void | [
"Gets",
"the",
"course",
"student",
"grades",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/indicator/community_of_inquiry_activity.php#L746-L749 |
212,468 | moodle/moodle | analytics/classes/local/indicator/community_of_inquiry_activity.php | community_of_inquiry_activity.get_activities | protected function get_activities($starttime, $endtime, $student = false) {
$activitytype = $this->get_activity_type();
// Var $student may not be available, default to not calculating dynamic data.
$studentid = -1;
if ($student) {
$studentid = $student->id;
}
$modinfo = get_fast_modinfo($this->course->get_course_data(), $studentid);
$activities = $modinfo->get_instances_of($activitytype);
$timerangeactivities = array();
foreach ($activities as $activity) {
if (!$this->activity_completed_by($activity, $starttime, $endtime, $student)) {
continue;
}
$timerangeactivities[$activity->context->id] = $activity;
}
return $timerangeactivities;
} | php | protected function get_activities($starttime, $endtime, $student = false) {
$activitytype = $this->get_activity_type();
// Var $student may not be available, default to not calculating dynamic data.
$studentid = -1;
if ($student) {
$studentid = $student->id;
}
$modinfo = get_fast_modinfo($this->course->get_course_data(), $studentid);
$activities = $modinfo->get_instances_of($activitytype);
$timerangeactivities = array();
foreach ($activities as $activity) {
if (!$this->activity_completed_by($activity, $starttime, $endtime, $student)) {
continue;
}
$timerangeactivities[$activity->context->id] = $activity;
}
return $timerangeactivities;
} | [
"protected",
"function",
"get_activities",
"(",
"$",
"starttime",
",",
"$",
"endtime",
",",
"$",
"student",
"=",
"false",
")",
"{",
"$",
"activitytype",
"=",
"$",
"this",
"->",
"get_activity_type",
"(",
")",
";",
"// Var $student may not be available, default to not calculating dynamic data.",
"$",
"studentid",
"=",
"-",
"1",
";",
"if",
"(",
"$",
"student",
")",
"{",
"$",
"studentid",
"=",
"$",
"student",
"->",
"id",
";",
"}",
"$",
"modinfo",
"=",
"get_fast_modinfo",
"(",
"$",
"this",
"->",
"course",
"->",
"get_course_data",
"(",
")",
",",
"$",
"studentid",
")",
";",
"$",
"activities",
"=",
"$",
"modinfo",
"->",
"get_instances_of",
"(",
"$",
"activitytype",
")",
";",
"$",
"timerangeactivities",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"activities",
"as",
"$",
"activity",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"activity_completed_by",
"(",
"$",
"activity",
",",
"$",
"starttime",
",",
"$",
"endtime",
",",
"$",
"student",
")",
")",
"{",
"continue",
";",
"}",
"$",
"timerangeactivities",
"[",
"$",
"activity",
"->",
"context",
"->",
"id",
"]",
"=",
"$",
"activity",
";",
"}",
"return",
"$",
"timerangeactivities",
";",
"}"
] | Guesses all activities that were available during a period of time.
@param int $starttime
@param int $endtime
@param \stdClass|false $student
@return array | [
"Guesses",
"all",
"activities",
"that",
"were",
"available",
"during",
"a",
"period",
"of",
"time",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/indicator/community_of_inquiry_activity.php#L759-L782 |
212,469 | moodle/moodle | analytics/classes/local/indicator/community_of_inquiry_activity.php | community_of_inquiry_activity.activity_type_completed_by | protected function activity_type_completed_by(\cm_info $activity, $starttime, $endtime, $student = false) {
$fieldname = $this->get_timeclose_field();
if (!$fieldname) {
// This activity type do not have its own availability control.
return null;
}
$this->fill_instance_data($activity);
$instance = $this->instancedata[$activity->instance];
if (!$instance->{$fieldname}) {
return null;
}
if ($starttime < $instance->{$fieldname} && $endtime >= $instance->{$fieldname}) {
return true;
}
return false;
} | php | protected function activity_type_completed_by(\cm_info $activity, $starttime, $endtime, $student = false) {
$fieldname = $this->get_timeclose_field();
if (!$fieldname) {
// This activity type do not have its own availability control.
return null;
}
$this->fill_instance_data($activity);
$instance = $this->instancedata[$activity->instance];
if (!$instance->{$fieldname}) {
return null;
}
if ($starttime < $instance->{$fieldname} && $endtime >= $instance->{$fieldname}) {
return true;
}
return false;
} | [
"protected",
"function",
"activity_type_completed_by",
"(",
"\\",
"cm_info",
"$",
"activity",
",",
"$",
"starttime",
",",
"$",
"endtime",
",",
"$",
"student",
"=",
"false",
")",
"{",
"$",
"fieldname",
"=",
"$",
"this",
"->",
"get_timeclose_field",
"(",
")",
";",
"if",
"(",
"!",
"$",
"fieldname",
")",
"{",
"// This activity type do not have its own availability control.",
"return",
"null",
";",
"}",
"$",
"this",
"->",
"fill_instance_data",
"(",
"$",
"activity",
")",
";",
"$",
"instance",
"=",
"$",
"this",
"->",
"instancedata",
"[",
"$",
"activity",
"->",
"instance",
"]",
";",
"if",
"(",
"!",
"$",
"instance",
"->",
"{",
"$",
"fieldname",
"}",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"starttime",
"<",
"$",
"instance",
"->",
"{",
"$",
"fieldname",
"}",
"&&",
"$",
"endtime",
">=",
"$",
"instance",
"->",
"{",
"$",
"fieldname",
"}",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | True if the activity is due or it has been closed during this period, false if during another period, null if no due time.
It can be overwritten by activities that allow teachers to set a due date or a time close separately
from Moodle availability system. Note that in most of the cases overwriting get_timeclose_field should
be enough.
Returns true or false if the time close date falls into the provided time range. Null otherwise.
@param \cm_info $activity
@param int $starttime
@param int $endtime
@param \stdClass|false $student
@return null | [
"True",
"if",
"the",
"activity",
"is",
"due",
"or",
"it",
"has",
"been",
"closed",
"during",
"this",
"period",
"false",
"if",
"during",
"another",
"period",
"null",
"if",
"no",
"due",
"time",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/indicator/community_of_inquiry_activity.php#L908-L928 |
212,470 | moodle/moodle | analytics/classes/local/indicator/community_of_inquiry_activity.php | community_of_inquiry_activity.fill_instance_data | protected function fill_instance_data(\cm_info $cm) {
global $DB;
if (!isset($this->instancedata[$cm->instance])) {
$this->instancedata[$cm->instance] = $DB->get_record($this->get_activity_type(), array('id' => $cm->instance),
'*', MUST_EXIST);
}
} | php | protected function fill_instance_data(\cm_info $cm) {
global $DB;
if (!isset($this->instancedata[$cm->instance])) {
$this->instancedata[$cm->instance] = $DB->get_record($this->get_activity_type(), array('id' => $cm->instance),
'*', MUST_EXIST);
}
} | [
"protected",
"function",
"fill_instance_data",
"(",
"\\",
"cm_info",
"$",
"cm",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"instancedata",
"[",
"$",
"cm",
"->",
"instance",
"]",
")",
")",
"{",
"$",
"this",
"->",
"instancedata",
"[",
"$",
"cm",
"->",
"instance",
"]",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"$",
"this",
"->",
"get_activity_type",
"(",
")",
",",
"array",
"(",
"'id'",
"=>",
"$",
"cm",
"->",
"instance",
")",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"}",
"}"
] | Fills in activity instance data.
@param \cm_info $cm
@return void | [
"Fills",
"in",
"activity",
"instance",
"data",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/indicator/community_of_inquiry_activity.php#L986-L993 |
212,471 | moodle/moodle | rating/classes/phpunit/privacy_helper.php | privacy_helper.get_ratings_on_subcontext | protected function get_ratings_on_subcontext(\context $context, array $subcontext) {
$writer = \core_privacy\local\request\writer::with_context($context);
return $writer->get_related_data($subcontext, 'rating');
} | php | protected function get_ratings_on_subcontext(\context $context, array $subcontext) {
$writer = \core_privacy\local\request\writer::with_context($context);
return $writer->get_related_data($subcontext, 'rating');
} | [
"protected",
"function",
"get_ratings_on_subcontext",
"(",
"\\",
"context",
"$",
"context",
",",
"array",
"$",
"subcontext",
")",
"{",
"$",
"writer",
"=",
"\\",
"core_privacy",
"\\",
"local",
"\\",
"request",
"\\",
"writer",
"::",
"with_context",
"(",
"$",
"context",
")",
";",
"return",
"$",
"writer",
"->",
"get_related_data",
"(",
"$",
"subcontext",
",",
"'rating'",
")",
";",
"}"
] | Fetch all ratings on a subcontext.
@param \context $context The context being stored.
@param array $subcontext The subcontext path to check.
@return array | [
"Fetch",
"all",
"ratings",
"on",
"a",
"subcontext",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/rating/classes/phpunit/privacy_helper.php#L47-L50 |
212,472 | moodle/moodle | rating/classes/phpunit/privacy_helper.php | privacy_helper.assert_all_own_ratings_on_context | protected function assert_all_own_ratings_on_context(
int $userid,
\context $context,
array $subcontext,
$component,
$ratingarea,
$itemid
) {
$writer = \core_privacy\local\request\writer::with_context($context);
$rm = new \rating_manager();
$dbratings = $rm->get_all_ratings_for_item((object) [
'context' => $context,
'component' => $component,
'ratingarea' => $ratingarea,
'itemid' => $itemid,
]);
$exportedratings = $this->get_ratings_on_subcontext($context, $subcontext);
foreach ($exportedratings as $ratingid => $rating) {
$this->assertTrue(isset($dbratings[$ratingid]));
$this->assertEquals($userid, $rating->author);
$this->assert_rating_matches($dbratings[$ratingid], $rating);
}
foreach ($dbratings as $rating) {
if ($rating->userid == $userid) {
$this->assertEquals($rating->id, $ratingid);
}
}
} | php | protected function assert_all_own_ratings_on_context(
int $userid,
\context $context,
array $subcontext,
$component,
$ratingarea,
$itemid
) {
$writer = \core_privacy\local\request\writer::with_context($context);
$rm = new \rating_manager();
$dbratings = $rm->get_all_ratings_for_item((object) [
'context' => $context,
'component' => $component,
'ratingarea' => $ratingarea,
'itemid' => $itemid,
]);
$exportedratings = $this->get_ratings_on_subcontext($context, $subcontext);
foreach ($exportedratings as $ratingid => $rating) {
$this->assertTrue(isset($dbratings[$ratingid]));
$this->assertEquals($userid, $rating->author);
$this->assert_rating_matches($dbratings[$ratingid], $rating);
}
foreach ($dbratings as $rating) {
if ($rating->userid == $userid) {
$this->assertEquals($rating->id, $ratingid);
}
}
} | [
"protected",
"function",
"assert_all_own_ratings_on_context",
"(",
"int",
"$",
"userid",
",",
"\\",
"context",
"$",
"context",
",",
"array",
"$",
"subcontext",
",",
"$",
"component",
",",
"$",
"ratingarea",
",",
"$",
"itemid",
")",
"{",
"$",
"writer",
"=",
"\\",
"core_privacy",
"\\",
"local",
"\\",
"request",
"\\",
"writer",
"::",
"with_context",
"(",
"$",
"context",
")",
";",
"$",
"rm",
"=",
"new",
"\\",
"rating_manager",
"(",
")",
";",
"$",
"dbratings",
"=",
"$",
"rm",
"->",
"get_all_ratings_for_item",
"(",
"(",
"object",
")",
"[",
"'context'",
"=>",
"$",
"context",
",",
"'component'",
"=>",
"$",
"component",
",",
"'ratingarea'",
"=>",
"$",
"ratingarea",
",",
"'itemid'",
"=>",
"$",
"itemid",
",",
"]",
")",
";",
"$",
"exportedratings",
"=",
"$",
"this",
"->",
"get_ratings_on_subcontext",
"(",
"$",
"context",
",",
"$",
"subcontext",
")",
";",
"foreach",
"(",
"$",
"exportedratings",
"as",
"$",
"ratingid",
"=>",
"$",
"rating",
")",
"{",
"$",
"this",
"->",
"assertTrue",
"(",
"isset",
"(",
"$",
"dbratings",
"[",
"$",
"ratingid",
"]",
")",
")",
";",
"$",
"this",
"->",
"assertEquals",
"(",
"$",
"userid",
",",
"$",
"rating",
"->",
"author",
")",
";",
"$",
"this",
"->",
"assert_rating_matches",
"(",
"$",
"dbratings",
"[",
"$",
"ratingid",
"]",
",",
"$",
"rating",
")",
";",
"}",
"foreach",
"(",
"$",
"dbratings",
"as",
"$",
"rating",
")",
"{",
"if",
"(",
"$",
"rating",
"->",
"userid",
"==",
"$",
"userid",
")",
"{",
"$",
"this",
"->",
"assertEquals",
"(",
"$",
"rating",
"->",
"id",
",",
"$",
"ratingid",
")",
";",
"}",
"}",
"}"
] | Check that all included ratings belong to the specified user.
@param int $userid The ID of the user being stored.
@param \context $context The context being stored.
@param array $subcontext The subcontext path to check.
@param string $component The component being stored.
@param string $ratingarea The rating area to store results for.
@param int $itemid The itemid to store. | [
"Check",
"that",
"all",
"included",
"ratings",
"belong",
"to",
"the",
"specified",
"user",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/rating/classes/phpunit/privacy_helper.php#L62-L92 |
212,473 | moodle/moodle | rating/classes/phpunit/privacy_helper.php | privacy_helper.assert_rating_matches | protected function assert_rating_matches($expected, $stored) {
$this->assertEquals($expected->rating, $stored->rating);
$this->assertEquals($expected->userid, $stored->author);
} | php | protected function assert_rating_matches($expected, $stored) {
$this->assertEquals($expected->rating, $stored->rating);
$this->assertEquals($expected->userid, $stored->author);
} | [
"protected",
"function",
"assert_rating_matches",
"(",
"$",
"expected",
",",
"$",
"stored",
")",
"{",
"$",
"this",
"->",
"assertEquals",
"(",
"$",
"expected",
"->",
"rating",
",",
"$",
"stored",
"->",
"rating",
")",
";",
"$",
"this",
"->",
"assertEquals",
"(",
"$",
"expected",
"->",
"userid",
",",
"$",
"stored",
"->",
"author",
")",
";",
"}"
] | Assert that the rating matches.
@param \stdClass $expected The expected rating structure
@param \stdClass $stored The actual rating structure | [
"Assert",
"that",
"the",
"rating",
"matches",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/rating/classes/phpunit/privacy_helper.php#L131-L134 |
212,474 | moodle/moodle | admin/tool/log/classes/local/privacy/helper.php | helper.restore_event_from_standard_record | protected static function restore_event_from_standard_record($data) {
$extra = ['origin' => $data->origin, 'ip' => $data->ip, 'realuserid' => $data->realuserid];
$data = (array) $data;
$id = $data['id'];
$data['other'] = self::decode_other($data['other']);
if ($data['other'] === false) {
$data['other'] = [];
}
unset($data['origin']);
unset($data['ip']);
unset($data['realuserid']);
unset($data['id']);
if (!$event = \core\event\base::restore($data, $extra)) {
return null;
}
return $event;
} | php | protected static function restore_event_from_standard_record($data) {
$extra = ['origin' => $data->origin, 'ip' => $data->ip, 'realuserid' => $data->realuserid];
$data = (array) $data;
$id = $data['id'];
$data['other'] = self::decode_other($data['other']);
if ($data['other'] === false) {
$data['other'] = [];
}
unset($data['origin']);
unset($data['ip']);
unset($data['realuserid']);
unset($data['id']);
if (!$event = \core\event\base::restore($data, $extra)) {
return null;
}
return $event;
} | [
"protected",
"static",
"function",
"restore_event_from_standard_record",
"(",
"$",
"data",
")",
"{",
"$",
"extra",
"=",
"[",
"'origin'",
"=>",
"$",
"data",
"->",
"origin",
",",
"'ip'",
"=>",
"$",
"data",
"->",
"ip",
",",
"'realuserid'",
"=>",
"$",
"data",
"->",
"realuserid",
"]",
";",
"$",
"data",
"=",
"(",
"array",
")",
"$",
"data",
";",
"$",
"id",
"=",
"$",
"data",
"[",
"'id'",
"]",
";",
"$",
"data",
"[",
"'other'",
"]",
"=",
"self",
"::",
"decode_other",
"(",
"$",
"data",
"[",
"'other'",
"]",
")",
";",
"if",
"(",
"$",
"data",
"[",
"'other'",
"]",
"===",
"false",
")",
"{",
"$",
"data",
"[",
"'other'",
"]",
"=",
"[",
"]",
";",
"}",
"unset",
"(",
"$",
"data",
"[",
"'origin'",
"]",
")",
";",
"unset",
"(",
"$",
"data",
"[",
"'ip'",
"]",
")",
";",
"unset",
"(",
"$",
"data",
"[",
"'realuserid'",
"]",
")",
";",
"unset",
"(",
"$",
"data",
"[",
"'id'",
"]",
")",
";",
"if",
"(",
"!",
"$",
"event",
"=",
"\\",
"core",
"\\",
"event",
"\\",
"base",
"::",
"restore",
"(",
"$",
"data",
",",
"$",
"extra",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"event",
";",
"}"
] | Returns an event from a standard record.
@see \logstore_standard\log\store::get_log_event()
@param object $data Log data.
@return \core\event\base | [
"Returns",
"an",
"event",
"from",
"a",
"standard",
"record",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/log/classes/local/privacy/helper.php#L49-L67 |
212,475 | moodle/moodle | admin/tool/log/classes/local/privacy/helper.php | helper.transform_standard_log_record_for_userid | public static function transform_standard_log_record_for_userid($record, $userid) {
// Restore the event to try to get the name, description and other field.
$restoredevent = static::restore_event_from_standard_record($record);
if ($restoredevent) {
$name = $restoredevent->get_name();
$description = $restoredevent->get_description();
$other = $restoredevent->other;
} else {
$name = $record->eventname;
$description = "Unknown event ({$name})";
$other = \tool_log\helper\reader::decode_other($record->other);
}
$realuserid = $record->realuserid;
$isauthor = $record->userid == $userid;
$isrelated = $record->relateduserid == $userid;
$isrealuser = $realuserid == $userid;
$ismasqueraded = $realuserid !== null && $record->userid != $realuserid;
$ismasquerading = $isrealuser && !$isauthor;
$isanonymous = $record->anonymous;
$data = [
'name' => $name,
'description' => $description,
'timecreated' => transform::datetime($record->timecreated),
'origin' => static::transform_origin($record->origin),
'ip' => $isauthor ? $record->ip : '',
'other' => $other ? $other : []
];
if ($isanonymous) {
$data['action_was_done_anonymously'] = transform::yesno($isanonymous);
}
if ($isauthor || !$isanonymous) {
$data['authorid'] = transform::user($record->userid);
$data['author_of_the_action_was_you'] = transform::yesno($isauthor);
}
if ($record->relateduserid) {
$data['relateduserid'] = transform::user($record->relateduserid);
$data['related_user_was_you'] = transform::yesno($isrelated);
}
if ($ismasqueraded) {
$data['author_of_the_action_was_masqueraded'] = transform::yesno(true);
if ($ismasquerading || !$isanonymous) {
$data['masqueradinguserid'] = transform::user($realuserid);
$data['masquerading_user_was_you'] = transform::yesno($ismasquerading);
}
}
return $data;
} | php | public static function transform_standard_log_record_for_userid($record, $userid) {
// Restore the event to try to get the name, description and other field.
$restoredevent = static::restore_event_from_standard_record($record);
if ($restoredevent) {
$name = $restoredevent->get_name();
$description = $restoredevent->get_description();
$other = $restoredevent->other;
} else {
$name = $record->eventname;
$description = "Unknown event ({$name})";
$other = \tool_log\helper\reader::decode_other($record->other);
}
$realuserid = $record->realuserid;
$isauthor = $record->userid == $userid;
$isrelated = $record->relateduserid == $userid;
$isrealuser = $realuserid == $userid;
$ismasqueraded = $realuserid !== null && $record->userid != $realuserid;
$ismasquerading = $isrealuser && !$isauthor;
$isanonymous = $record->anonymous;
$data = [
'name' => $name,
'description' => $description,
'timecreated' => transform::datetime($record->timecreated),
'origin' => static::transform_origin($record->origin),
'ip' => $isauthor ? $record->ip : '',
'other' => $other ? $other : []
];
if ($isanonymous) {
$data['action_was_done_anonymously'] = transform::yesno($isanonymous);
}
if ($isauthor || !$isanonymous) {
$data['authorid'] = transform::user($record->userid);
$data['author_of_the_action_was_you'] = transform::yesno($isauthor);
}
if ($record->relateduserid) {
$data['relateduserid'] = transform::user($record->relateduserid);
$data['related_user_was_you'] = transform::yesno($isrelated);
}
if ($ismasqueraded) {
$data['author_of_the_action_was_masqueraded'] = transform::yesno(true);
if ($ismasquerading || !$isanonymous) {
$data['masqueradinguserid'] = transform::user($realuserid);
$data['masquerading_user_was_you'] = transform::yesno($ismasquerading);
}
}
return $data;
} | [
"public",
"static",
"function",
"transform_standard_log_record_for_userid",
"(",
"$",
"record",
",",
"$",
"userid",
")",
"{",
"// Restore the event to try to get the name, description and other field.",
"$",
"restoredevent",
"=",
"static",
"::",
"restore_event_from_standard_record",
"(",
"$",
"record",
")",
";",
"if",
"(",
"$",
"restoredevent",
")",
"{",
"$",
"name",
"=",
"$",
"restoredevent",
"->",
"get_name",
"(",
")",
";",
"$",
"description",
"=",
"$",
"restoredevent",
"->",
"get_description",
"(",
")",
";",
"$",
"other",
"=",
"$",
"restoredevent",
"->",
"other",
";",
"}",
"else",
"{",
"$",
"name",
"=",
"$",
"record",
"->",
"eventname",
";",
"$",
"description",
"=",
"\"Unknown event ({$name})\"",
";",
"$",
"other",
"=",
"\\",
"tool_log",
"\\",
"helper",
"\\",
"reader",
"::",
"decode_other",
"(",
"$",
"record",
"->",
"other",
")",
";",
"}",
"$",
"realuserid",
"=",
"$",
"record",
"->",
"realuserid",
";",
"$",
"isauthor",
"=",
"$",
"record",
"->",
"userid",
"==",
"$",
"userid",
";",
"$",
"isrelated",
"=",
"$",
"record",
"->",
"relateduserid",
"==",
"$",
"userid",
";",
"$",
"isrealuser",
"=",
"$",
"realuserid",
"==",
"$",
"userid",
";",
"$",
"ismasqueraded",
"=",
"$",
"realuserid",
"!==",
"null",
"&&",
"$",
"record",
"->",
"userid",
"!=",
"$",
"realuserid",
";",
"$",
"ismasquerading",
"=",
"$",
"isrealuser",
"&&",
"!",
"$",
"isauthor",
";",
"$",
"isanonymous",
"=",
"$",
"record",
"->",
"anonymous",
";",
"$",
"data",
"=",
"[",
"'name'",
"=>",
"$",
"name",
",",
"'description'",
"=>",
"$",
"description",
",",
"'timecreated'",
"=>",
"transform",
"::",
"datetime",
"(",
"$",
"record",
"->",
"timecreated",
")",
",",
"'origin'",
"=>",
"static",
"::",
"transform_origin",
"(",
"$",
"record",
"->",
"origin",
")",
",",
"'ip'",
"=>",
"$",
"isauthor",
"?",
"$",
"record",
"->",
"ip",
":",
"''",
",",
"'other'",
"=>",
"$",
"other",
"?",
"$",
"other",
":",
"[",
"]",
"]",
";",
"if",
"(",
"$",
"isanonymous",
")",
"{",
"$",
"data",
"[",
"'action_was_done_anonymously'",
"]",
"=",
"transform",
"::",
"yesno",
"(",
"$",
"isanonymous",
")",
";",
"}",
"if",
"(",
"$",
"isauthor",
"||",
"!",
"$",
"isanonymous",
")",
"{",
"$",
"data",
"[",
"'authorid'",
"]",
"=",
"transform",
"::",
"user",
"(",
"$",
"record",
"->",
"userid",
")",
";",
"$",
"data",
"[",
"'author_of_the_action_was_you'",
"]",
"=",
"transform",
"::",
"yesno",
"(",
"$",
"isauthor",
")",
";",
"}",
"if",
"(",
"$",
"record",
"->",
"relateduserid",
")",
"{",
"$",
"data",
"[",
"'relateduserid'",
"]",
"=",
"transform",
"::",
"user",
"(",
"$",
"record",
"->",
"relateduserid",
")",
";",
"$",
"data",
"[",
"'related_user_was_you'",
"]",
"=",
"transform",
"::",
"yesno",
"(",
"$",
"isrelated",
")",
";",
"}",
"if",
"(",
"$",
"ismasqueraded",
")",
"{",
"$",
"data",
"[",
"'author_of_the_action_was_masqueraded'",
"]",
"=",
"transform",
"::",
"yesno",
"(",
"true",
")",
";",
"if",
"(",
"$",
"ismasquerading",
"||",
"!",
"$",
"isanonymous",
")",
"{",
"$",
"data",
"[",
"'masqueradinguserid'",
"]",
"=",
"transform",
"::",
"user",
"(",
"$",
"realuserid",
")",
";",
"$",
"data",
"[",
"'masquerading_user_was_you'",
"]",
"=",
"transform",
"::",
"yesno",
"(",
"$",
"ismasquerading",
")",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | Transform a standard log record for a user.
@param object $record The record.
@param int $userid The user ID.
@return array | [
"Transform",
"a",
"standard",
"log",
"record",
"for",
"a",
"user",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/log/classes/local/privacy/helper.php#L76-L130 |
212,476 | moodle/moodle | lib/horde/framework/Horde/Mail/Transport/Smtpmx.php | Horde_Mail_Transport_Smtpmx._getMx | protected function _getMx($host)
{
$mx = array();
if ($this->params['netdns']) {
$this->_loadNetDns();
try {
$response = $this->_resolver->query($host, 'MX');
if (!$response) {
return false;
}
} catch (Exception $e) {
throw new Horde_Mail_Exception($e);
}
foreach ($response->answer as $rr) {
if ($rr->type == 'MX') {
$mx[$rr->exchange] = $rr->preference;
}
}
} else {
$mxHost = $mxWeight = array();
if (!getmxrr($host, $mxHost, $mxWeight)) {
return false;
}
for ($i = 0; $i < count($mxHost); ++$i) {
$mx[$mxHost[$i]] = $mxWeight[$i];
}
}
asort($mx);
return $mx;
} | php | protected function _getMx($host)
{
$mx = array();
if ($this->params['netdns']) {
$this->_loadNetDns();
try {
$response = $this->_resolver->query($host, 'MX');
if (!$response) {
return false;
}
} catch (Exception $e) {
throw new Horde_Mail_Exception($e);
}
foreach ($response->answer as $rr) {
if ($rr->type == 'MX') {
$mx[$rr->exchange] = $rr->preference;
}
}
} else {
$mxHost = $mxWeight = array();
if (!getmxrr($host, $mxHost, $mxWeight)) {
return false;
}
for ($i = 0; $i < count($mxHost); ++$i) {
$mx[$mxHost[$i]] = $mxWeight[$i];
}
}
asort($mx);
return $mx;
} | [
"protected",
"function",
"_getMx",
"(",
"$",
"host",
")",
"{",
"$",
"mx",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"params",
"[",
"'netdns'",
"]",
")",
"{",
"$",
"this",
"->",
"_loadNetDns",
"(",
")",
";",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"_resolver",
"->",
"query",
"(",
"$",
"host",
",",
"'MX'",
")",
";",
"if",
"(",
"!",
"$",
"response",
")",
"{",
"return",
"false",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"Horde_Mail_Exception",
"(",
"$",
"e",
")",
";",
"}",
"foreach",
"(",
"$",
"response",
"->",
"answer",
"as",
"$",
"rr",
")",
"{",
"if",
"(",
"$",
"rr",
"->",
"type",
"==",
"'MX'",
")",
"{",
"$",
"mx",
"[",
"$",
"rr",
"->",
"exchange",
"]",
"=",
"$",
"rr",
"->",
"preference",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"mxHost",
"=",
"$",
"mxWeight",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"getmxrr",
"(",
"$",
"host",
",",
"$",
"mxHost",
",",
"$",
"mxWeight",
")",
")",
"{",
"return",
"false",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"mxHost",
")",
";",
"++",
"$",
"i",
")",
"{",
"$",
"mx",
"[",
"$",
"mxHost",
"[",
"$",
"i",
"]",
"]",
"=",
"$",
"mxWeight",
"[",
"$",
"i",
"]",
";",
"}",
"}",
"asort",
"(",
"$",
"mx",
")",
";",
"return",
"$",
"mx",
";",
"}"
] | Recieve MX records for a host.
@param string $host Mail host.
@return mixed Sorted MX list or false on error. | [
"Recieve",
"MX",
"records",
"for",
"a",
"host",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mail/Transport/Smtpmx.php#L284-L320 |
212,477 | moodle/moodle | lib/horde/framework/Horde/Mail/Transport/Smtpmx.php | Horde_Mail_Transport_Smtpmx._error | protected function _error($id, $info = array())
{
$msg = $this->_errorCode[$id]['msg'];
// include info to messages
if (!empty($info)) {
$replace = $search = array();
foreach ($info as $key => $value) {
$search[] = '{' . Horde_String::upper($key) . '}';
$replace[] = $value;
}
$msg = str_replace($search, $replace, $msg);
}
throw new Horde_Mail_Exception($msg, $this->_errorCode[$id]['code']);
} | php | protected function _error($id, $info = array())
{
$msg = $this->_errorCode[$id]['msg'];
// include info to messages
if (!empty($info)) {
$replace = $search = array();
foreach ($info as $key => $value) {
$search[] = '{' . Horde_String::upper($key) . '}';
$replace[] = $value;
}
$msg = str_replace($search, $replace, $msg);
}
throw new Horde_Mail_Exception($msg, $this->_errorCode[$id]['code']);
} | [
"protected",
"function",
"_error",
"(",
"$",
"id",
",",
"$",
"info",
"=",
"array",
"(",
")",
")",
"{",
"$",
"msg",
"=",
"$",
"this",
"->",
"_errorCode",
"[",
"$",
"id",
"]",
"[",
"'msg'",
"]",
";",
"// include info to messages",
"if",
"(",
"!",
"empty",
"(",
"$",
"info",
")",
")",
"{",
"$",
"replace",
"=",
"$",
"search",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"info",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"search",
"[",
"]",
"=",
"'{'",
".",
"Horde_String",
"::",
"upper",
"(",
"$",
"key",
")",
".",
"'}'",
";",
"$",
"replace",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"$",
"msg",
"=",
"str_replace",
"(",
"$",
"search",
",",
"$",
"replace",
",",
"$",
"msg",
")",
";",
"}",
"throw",
"new",
"Horde_Mail_Exception",
"(",
"$",
"msg",
",",
"$",
"this",
"->",
"_errorCode",
"[",
"$",
"id",
"]",
"[",
"'code'",
"]",
")",
";",
"}"
] | Format error message.
@param string $id Maps error ids to codes and message.
@param array $info Optional information in associative array.
@throws Horde_Mail_Exception | [
"Format",
"error",
"message",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mail/Transport/Smtpmx.php#L343-L360 |
212,478 | moodle/moodle | admin/tool/policy/classes/form/accept_policy.php | accept_policy.validate_and_get_users | protected function validate_and_get_users($versionids, $userids, $action) {
global $DB;
$usernames = [];
list($sql, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
$params['usercontextlevel'] = CONTEXT_USER;
$users = $DB->get_records_sql("SELECT u.id, " . get_all_user_name_fields(true, 'u') . ", " .
\context_helper::get_preload_record_columns_sql('ctx') .
" FROM {user} u JOIN {context} ctx ON ctx.contextlevel=:usercontextlevel AND ctx.instanceid = u.id
WHERE u.id " . $sql, $params);
foreach ($userids as $userid) {
if (!isset($users[$userid])) {
throw new \dml_missing_record_exception('user', 'id=?', [$userid]);
}
$user = $users[$userid];
if (isguestuser($user)) {
throw new \moodle_exception('noguest');
}
\context_helper::preload_from_record($user);
if ($action === 'revoke') {
api::can_revoke_policies($versionids, $userid, true);
} else if ($action === 'accept') {
api::can_accept_policies($versionids, $userid, true);
} else if ($action === 'decline') {
api::can_decline_policies($versionids, $userid, true);
}
$usernames[$userid] = fullname($user);
}
return $usernames;
} | php | protected function validate_and_get_users($versionids, $userids, $action) {
global $DB;
$usernames = [];
list($sql, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
$params['usercontextlevel'] = CONTEXT_USER;
$users = $DB->get_records_sql("SELECT u.id, " . get_all_user_name_fields(true, 'u') . ", " .
\context_helper::get_preload_record_columns_sql('ctx') .
" FROM {user} u JOIN {context} ctx ON ctx.contextlevel=:usercontextlevel AND ctx.instanceid = u.id
WHERE u.id " . $sql, $params);
foreach ($userids as $userid) {
if (!isset($users[$userid])) {
throw new \dml_missing_record_exception('user', 'id=?', [$userid]);
}
$user = $users[$userid];
if (isguestuser($user)) {
throw new \moodle_exception('noguest');
}
\context_helper::preload_from_record($user);
if ($action === 'revoke') {
api::can_revoke_policies($versionids, $userid, true);
} else if ($action === 'accept') {
api::can_accept_policies($versionids, $userid, true);
} else if ($action === 'decline') {
api::can_decline_policies($versionids, $userid, true);
}
$usernames[$userid] = fullname($user);
}
return $usernames;
} | [
"protected",
"function",
"validate_and_get_users",
"(",
"$",
"versionids",
",",
"$",
"userids",
",",
"$",
"action",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"usernames",
"=",
"[",
"]",
";",
"list",
"(",
"$",
"sql",
",",
"$",
"params",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"userids",
",",
"SQL_PARAMS_NAMED",
")",
";",
"$",
"params",
"[",
"'usercontextlevel'",
"]",
"=",
"CONTEXT_USER",
";",
"$",
"users",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"\"SELECT u.id, \"",
".",
"get_all_user_name_fields",
"(",
"true",
",",
"'u'",
")",
".",
"\", \"",
".",
"\\",
"context_helper",
"::",
"get_preload_record_columns_sql",
"(",
"'ctx'",
")",
".",
"\" FROM {user} u JOIN {context} ctx ON ctx.contextlevel=:usercontextlevel AND ctx.instanceid = u.id\n WHERE u.id \"",
".",
"$",
"sql",
",",
"$",
"params",
")",
";",
"foreach",
"(",
"$",
"userids",
"as",
"$",
"userid",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"users",
"[",
"$",
"userid",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"dml_missing_record_exception",
"(",
"'user'",
",",
"'id=?'",
",",
"[",
"$",
"userid",
"]",
")",
";",
"}",
"$",
"user",
"=",
"$",
"users",
"[",
"$",
"userid",
"]",
";",
"if",
"(",
"isguestuser",
"(",
"$",
"user",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'noguest'",
")",
";",
"}",
"\\",
"context_helper",
"::",
"preload_from_record",
"(",
"$",
"user",
")",
";",
"if",
"(",
"$",
"action",
"===",
"'revoke'",
")",
"{",
"api",
"::",
"can_revoke_policies",
"(",
"$",
"versionids",
",",
"$",
"userid",
",",
"true",
")",
";",
"}",
"else",
"if",
"(",
"$",
"action",
"===",
"'accept'",
")",
"{",
"api",
"::",
"can_accept_policies",
"(",
"$",
"versionids",
",",
"$",
"userid",
",",
"true",
")",
";",
"}",
"else",
"if",
"(",
"$",
"action",
"===",
"'decline'",
")",
"{",
"api",
"::",
"can_decline_policies",
"(",
"$",
"versionids",
",",
"$",
"userid",
",",
"true",
")",
";",
"}",
"$",
"usernames",
"[",
"$",
"userid",
"]",
"=",
"fullname",
"(",
"$",
"user",
")",
";",
"}",
"return",
"$",
"usernames",
";",
"}"
] | Validate userids and return usernames
@param array $versionids int[] List of policy version ids to process.
@param array $userids
@param string $action accept|decline|revoke
@return array (userid=>username) | [
"Validate",
"userids",
"and",
"return",
"usernames"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/form/accept_policy.php#L125-L155 |
212,479 | moodle/moodle | admin/tool/policy/classes/form/accept_policy.php | accept_policy.validate_and_get_versions | protected function validate_and_get_versions($versionids) {
$versionnames = [];
$policies = api::list_policies();
foreach ($versionids as $versionid) {
$version = api::get_policy_version($versionid, $policies);
if ($version->audience == policy_version::AUDIENCE_GUESTS) {
throw new \moodle_exception('errorpolicyversionnotfound', 'tool_policy');
}
$url = new \moodle_url('/admin/tool/policy/view.php', ['versionid' => $version->id]);
$policyname = $version->name;
if ($version->status != policy_version::STATUS_ACTIVE) {
$policyname .= ' ' . $version->revision;
}
$versionnames[$version->id] = \html_writer::link($url, $policyname,
['data-action' => 'view', 'data-versionid' => $version->id]);
}
return $versionnames;
} | php | protected function validate_and_get_versions($versionids) {
$versionnames = [];
$policies = api::list_policies();
foreach ($versionids as $versionid) {
$version = api::get_policy_version($versionid, $policies);
if ($version->audience == policy_version::AUDIENCE_GUESTS) {
throw new \moodle_exception('errorpolicyversionnotfound', 'tool_policy');
}
$url = new \moodle_url('/admin/tool/policy/view.php', ['versionid' => $version->id]);
$policyname = $version->name;
if ($version->status != policy_version::STATUS_ACTIVE) {
$policyname .= ' ' . $version->revision;
}
$versionnames[$version->id] = \html_writer::link($url, $policyname,
['data-action' => 'view', 'data-versionid' => $version->id]);
}
return $versionnames;
} | [
"protected",
"function",
"validate_and_get_versions",
"(",
"$",
"versionids",
")",
"{",
"$",
"versionnames",
"=",
"[",
"]",
";",
"$",
"policies",
"=",
"api",
"::",
"list_policies",
"(",
")",
";",
"foreach",
"(",
"$",
"versionids",
"as",
"$",
"versionid",
")",
"{",
"$",
"version",
"=",
"api",
"::",
"get_policy_version",
"(",
"$",
"versionid",
",",
"$",
"policies",
")",
";",
"if",
"(",
"$",
"version",
"->",
"audience",
"==",
"policy_version",
"::",
"AUDIENCE_GUESTS",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'errorpolicyversionnotfound'",
",",
"'tool_policy'",
")",
";",
"}",
"$",
"url",
"=",
"new",
"\\",
"moodle_url",
"(",
"'/admin/tool/policy/view.php'",
",",
"[",
"'versionid'",
"=>",
"$",
"version",
"->",
"id",
"]",
")",
";",
"$",
"policyname",
"=",
"$",
"version",
"->",
"name",
";",
"if",
"(",
"$",
"version",
"->",
"status",
"!=",
"policy_version",
"::",
"STATUS_ACTIVE",
")",
"{",
"$",
"policyname",
".=",
"' '",
".",
"$",
"version",
"->",
"revision",
";",
"}",
"$",
"versionnames",
"[",
"$",
"version",
"->",
"id",
"]",
"=",
"\\",
"html_writer",
"::",
"link",
"(",
"$",
"url",
",",
"$",
"policyname",
",",
"[",
"'data-action'",
"=>",
"'view'",
",",
"'data-versionid'",
"=>",
"$",
"version",
"->",
"id",
"]",
")",
";",
"}",
"return",
"$",
"versionnames",
";",
"}"
] | Validate versionids and return their names
@param array $versionids
@return array (versionid=>name) | [
"Validate",
"versionids",
"and",
"return",
"their",
"names"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/form/accept_policy.php#L163-L180 |
212,480 | moodle/moodle | admin/tool/policy/classes/form/accept_policy.php | accept_policy.process | public function process() {
if ($data = $this->get_data()) {
foreach ($data->userids as $userid) {
if ($data->action === 'revoke') {
foreach ($data->versionids as $versionid) {
\tool_policy\api::revoke_acceptance($versionid, $userid, $data->note);
}
} else if ($data->action === 'accept') {
\tool_policy\api::accept_policies($data->versionids, $userid, $data->note);
} else if ($data->action === 'decline') {
\tool_policy\api::decline_policies($data->versionids, $userid, $data->note);
}
}
}
} | php | public function process() {
if ($data = $this->get_data()) {
foreach ($data->userids as $userid) {
if ($data->action === 'revoke') {
foreach ($data->versionids as $versionid) {
\tool_policy\api::revoke_acceptance($versionid, $userid, $data->note);
}
} else if ($data->action === 'accept') {
\tool_policy\api::accept_policies($data->versionids, $userid, $data->note);
} else if ($data->action === 'decline') {
\tool_policy\api::decline_policies($data->versionids, $userid, $data->note);
}
}
}
} | [
"public",
"function",
"process",
"(",
")",
"{",
"if",
"(",
"$",
"data",
"=",
"$",
"this",
"->",
"get_data",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"data",
"->",
"userids",
"as",
"$",
"userid",
")",
"{",
"if",
"(",
"$",
"data",
"->",
"action",
"===",
"'revoke'",
")",
"{",
"foreach",
"(",
"$",
"data",
"->",
"versionids",
"as",
"$",
"versionid",
")",
"{",
"\\",
"tool_policy",
"\\",
"api",
"::",
"revoke_acceptance",
"(",
"$",
"versionid",
",",
"$",
"userid",
",",
"$",
"data",
"->",
"note",
")",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"data",
"->",
"action",
"===",
"'accept'",
")",
"{",
"\\",
"tool_policy",
"\\",
"api",
"::",
"accept_policies",
"(",
"$",
"data",
"->",
"versionids",
",",
"$",
"userid",
",",
"$",
"data",
"->",
"note",
")",
";",
"}",
"else",
"if",
"(",
"$",
"data",
"->",
"action",
"===",
"'decline'",
")",
"{",
"\\",
"tool_policy",
"\\",
"api",
"::",
"decline_policies",
"(",
"$",
"data",
"->",
"versionids",
",",
"$",
"userid",
",",
"$",
"data",
"->",
"note",
")",
";",
"}",
"}",
"}",
"}"
] | Process form submission | [
"Process",
"form",
"submission"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/form/accept_policy.php#L185-L199 |
212,481 | moodle/moodle | mod/page/mod_form.php | mod_page_mod_form.data_preprocessing | public function data_preprocessing(&$defaultvalues) {
if ($this->current->instance) {
$draftitemid = file_get_submitted_draft_itemid('page');
$defaultvalues['page']['format'] = $defaultvalues['contentformat'];
$defaultvalues['page']['text'] = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_page',
'content', 0, page_get_editor_options($this->context), $defaultvalues['content']);
$defaultvalues['page']['itemid'] = $draftitemid;
}
if (!empty($defaultvalues['displayoptions'])) {
$displayoptions = unserialize($defaultvalues['displayoptions']);
if (isset($displayoptions['printintro'])) {
$defaultvalues['printintro'] = $displayoptions['printintro'];
}
if (isset($displayoptions['printheading'])) {
$defaultvalues['printheading'] = $displayoptions['printheading'];
}
if (isset($displayoptions['printlastmodified'])) {
$defaultvalues['printlastmodified'] = $displayoptions['printlastmodified'];
}
if (!empty($displayoptions['popupwidth'])) {
$defaultvalues['popupwidth'] = $displayoptions['popupwidth'];
}
if (!empty($displayoptions['popupheight'])) {
$defaultvalues['popupheight'] = $displayoptions['popupheight'];
}
}
} | php | public function data_preprocessing(&$defaultvalues) {
if ($this->current->instance) {
$draftitemid = file_get_submitted_draft_itemid('page');
$defaultvalues['page']['format'] = $defaultvalues['contentformat'];
$defaultvalues['page']['text'] = file_prepare_draft_area($draftitemid, $this->context->id, 'mod_page',
'content', 0, page_get_editor_options($this->context), $defaultvalues['content']);
$defaultvalues['page']['itemid'] = $draftitemid;
}
if (!empty($defaultvalues['displayoptions'])) {
$displayoptions = unserialize($defaultvalues['displayoptions']);
if (isset($displayoptions['printintro'])) {
$defaultvalues['printintro'] = $displayoptions['printintro'];
}
if (isset($displayoptions['printheading'])) {
$defaultvalues['printheading'] = $displayoptions['printheading'];
}
if (isset($displayoptions['printlastmodified'])) {
$defaultvalues['printlastmodified'] = $displayoptions['printlastmodified'];
}
if (!empty($displayoptions['popupwidth'])) {
$defaultvalues['popupwidth'] = $displayoptions['popupwidth'];
}
if (!empty($displayoptions['popupheight'])) {
$defaultvalues['popupheight'] = $displayoptions['popupheight'];
}
}
} | [
"public",
"function",
"data_preprocessing",
"(",
"&",
"$",
"defaultvalues",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"current",
"->",
"instance",
")",
"{",
"$",
"draftitemid",
"=",
"file_get_submitted_draft_itemid",
"(",
"'page'",
")",
";",
"$",
"defaultvalues",
"[",
"'page'",
"]",
"[",
"'format'",
"]",
"=",
"$",
"defaultvalues",
"[",
"'contentformat'",
"]",
";",
"$",
"defaultvalues",
"[",
"'page'",
"]",
"[",
"'text'",
"]",
"=",
"file_prepare_draft_area",
"(",
"$",
"draftitemid",
",",
"$",
"this",
"->",
"context",
"->",
"id",
",",
"'mod_page'",
",",
"'content'",
",",
"0",
",",
"page_get_editor_options",
"(",
"$",
"this",
"->",
"context",
")",
",",
"$",
"defaultvalues",
"[",
"'content'",
"]",
")",
";",
"$",
"defaultvalues",
"[",
"'page'",
"]",
"[",
"'itemid'",
"]",
"=",
"$",
"draftitemid",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"defaultvalues",
"[",
"'displayoptions'",
"]",
")",
")",
"{",
"$",
"displayoptions",
"=",
"unserialize",
"(",
"$",
"defaultvalues",
"[",
"'displayoptions'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"displayoptions",
"[",
"'printintro'",
"]",
")",
")",
"{",
"$",
"defaultvalues",
"[",
"'printintro'",
"]",
"=",
"$",
"displayoptions",
"[",
"'printintro'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"displayoptions",
"[",
"'printheading'",
"]",
")",
")",
"{",
"$",
"defaultvalues",
"[",
"'printheading'",
"]",
"=",
"$",
"displayoptions",
"[",
"'printheading'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"displayoptions",
"[",
"'printlastmodified'",
"]",
")",
")",
"{",
"$",
"defaultvalues",
"[",
"'printlastmodified'",
"]",
"=",
"$",
"displayoptions",
"[",
"'printlastmodified'",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"displayoptions",
"[",
"'popupwidth'",
"]",
")",
")",
"{",
"$",
"defaultvalues",
"[",
"'popupwidth'",
"]",
"=",
"$",
"displayoptions",
"[",
"'popupwidth'",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"displayoptions",
"[",
"'popupheight'",
"]",
")",
")",
"{",
"$",
"defaultvalues",
"[",
"'popupheight'",
"]",
"=",
"$",
"displayoptions",
"[",
"'popupheight'",
"]",
";",
"}",
"}",
"}"
] | Enforce defaults here.
@param array $defaultvalues Form defaults
@return void | [
"Enforce",
"defaults",
"here",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/page/mod_form.php#L124-L150 |
212,482 | moodle/moodle | lib/horde/framework/Horde/Mail/Rfc822/Object.php | Horde_Mail_Rfc822_Object.writeAddress | public function writeAddress($opts = array())
{
if ($opts === true) {
$opts = array(
'encode' => 'UTF-8',
'idn' => true
);
} elseif (!empty($opts['encode']) && ($opts['encode'] === true)) {
$opts['encode'] = 'UTF-8';
}
return $this->_writeAddress($opts);
} | php | public function writeAddress($opts = array())
{
if ($opts === true) {
$opts = array(
'encode' => 'UTF-8',
'idn' => true
);
} elseif (!empty($opts['encode']) && ($opts['encode'] === true)) {
$opts['encode'] = 'UTF-8';
}
return $this->_writeAddress($opts);
} | [
"public",
"function",
"writeAddress",
"(",
"$",
"opts",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"$",
"opts",
"===",
"true",
")",
"{",
"$",
"opts",
"=",
"array",
"(",
"'encode'",
"=>",
"'UTF-8'",
",",
"'idn'",
"=>",
"true",
")",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"opts",
"[",
"'encode'",
"]",
")",
"&&",
"(",
"$",
"opts",
"[",
"'encode'",
"]",
"===",
"true",
")",
")",
"{",
"$",
"opts",
"[",
"'encode'",
"]",
"=",
"'UTF-8'",
";",
"}",
"return",
"$",
"this",
"->",
"_writeAddress",
"(",
"$",
"opts",
")",
";",
"}"
] | Write an address given information in this part.
@param mixed $opts If boolean true, is equivalent to passing true for
both 'encode' and 'idn'. If an array, these
keys are supported:
- comment: (boolean) If true, include comment(s) in output?
@since 2.6.0
DEFAULT: false
- encode: (mixed) MIME encode the personal/groupname parts?
If boolean true, encodes in 'UTF-8'.
If a string, encodes using this charset.
DEFAULT: false
- idn: (boolean) If true, encodes IDN domain names (RFC 3490).
DEFAULT: false
- noquote: (boolean) If true, don't quote personal part. [@since
2.4.0]
DEFAULT: false
@return string The correctly escaped/quoted address. | [
"Write",
"an",
"address",
"given",
"information",
"in",
"this",
"part",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mail/Rfc822/Object.php#L56-L68 |
212,483 | moodle/moodle | course/classes/customfield/course_handler.php | course_handler.can_edit | public function can_edit(field_controller $field, int $instanceid = 0) : bool {
if ($instanceid) {
$context = $this->get_instance_context($instanceid);
return (!$field->get_configdata_property('locked') ||
has_capability('moodle/course:changelockedcustomfields', $context));
} else {
$context = $this->get_parent_context();
return (!$field->get_configdata_property('locked') ||
guess_if_creator_will_have_course_capability('moodle/course:changelockedcustomfields', $context));
}
} | php | public function can_edit(field_controller $field, int $instanceid = 0) : bool {
if ($instanceid) {
$context = $this->get_instance_context($instanceid);
return (!$field->get_configdata_property('locked') ||
has_capability('moodle/course:changelockedcustomfields', $context));
} else {
$context = $this->get_parent_context();
return (!$field->get_configdata_property('locked') ||
guess_if_creator_will_have_course_capability('moodle/course:changelockedcustomfields', $context));
}
} | [
"public",
"function",
"can_edit",
"(",
"field_controller",
"$",
"field",
",",
"int",
"$",
"instanceid",
"=",
"0",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"instanceid",
")",
"{",
"$",
"context",
"=",
"$",
"this",
"->",
"get_instance_context",
"(",
"$",
"instanceid",
")",
";",
"return",
"(",
"!",
"$",
"field",
"->",
"get_configdata_property",
"(",
"'locked'",
")",
"||",
"has_capability",
"(",
"'moodle/course:changelockedcustomfields'",
",",
"$",
"context",
")",
")",
";",
"}",
"else",
"{",
"$",
"context",
"=",
"$",
"this",
"->",
"get_parent_context",
"(",
")",
";",
"return",
"(",
"!",
"$",
"field",
"->",
"get_configdata_property",
"(",
"'locked'",
")",
"||",
"guess_if_creator_will_have_course_capability",
"(",
"'moodle/course:changelockedcustomfields'",
",",
"$",
"context",
")",
")",
";",
"}",
"}"
] | The current user can edit custom fields on the given course.
@param field_controller $field
@param int $instanceid id of the course to test edit permission
@return bool true if the current can edit custom fields, false otherwise | [
"The",
"current",
"user",
"can",
"edit",
"custom",
"fields",
"on",
"the",
"given",
"course",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/customfield/course_handler.php#L87-L97 |
212,484 | moodle/moodle | course/classes/customfield/course_handler.php | course_handler.can_view | public function can_view(field_controller $field, int $instanceid) : bool {
$visibility = $field->get_configdata_property('visibility');
if ($visibility == self::NOTVISIBLE) {
return false;
} else if ($visibility == self::VISIBLETOTEACHERS) {
return has_capability('moodle/course:update', $this->get_instance_context($instanceid));
} else {
return true;
}
} | php | public function can_view(field_controller $field, int $instanceid) : bool {
$visibility = $field->get_configdata_property('visibility');
if ($visibility == self::NOTVISIBLE) {
return false;
} else if ($visibility == self::VISIBLETOTEACHERS) {
return has_capability('moodle/course:update', $this->get_instance_context($instanceid));
} else {
return true;
}
} | [
"public",
"function",
"can_view",
"(",
"field_controller",
"$",
"field",
",",
"int",
"$",
"instanceid",
")",
":",
"bool",
"{",
"$",
"visibility",
"=",
"$",
"field",
"->",
"get_configdata_property",
"(",
"'visibility'",
")",
";",
"if",
"(",
"$",
"visibility",
"==",
"self",
"::",
"NOTVISIBLE",
")",
"{",
"return",
"false",
";",
"}",
"else",
"if",
"(",
"$",
"visibility",
"==",
"self",
"::",
"VISIBLETOTEACHERS",
")",
"{",
"return",
"has_capability",
"(",
"'moodle/course:update'",
",",
"$",
"this",
"->",
"get_instance_context",
"(",
"$",
"instanceid",
")",
")",
";",
"}",
"else",
"{",
"return",
"true",
";",
"}",
"}"
] | The current user can view custom fields on the given course.
@param field_controller $field
@param int $instanceid id of the course to test edit permission
@return bool true if the current can edit custom fields, false otherwise | [
"The",
"current",
"user",
"can",
"view",
"custom",
"fields",
"on",
"the",
"given",
"course",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/customfield/course_handler.php#L106-L115 |
212,485 | moodle/moodle | course/classes/customfield/course_handler.php | course_handler.get_parent_context | protected function get_parent_context() : \context {
global $PAGE;
if ($this->parentcontext) {
return $this->parentcontext;
} else if ($PAGE->context && $PAGE->context instanceof \context_coursecat) {
return $PAGE->context;
}
return \context_system::instance();
} | php | protected function get_parent_context() : \context {
global $PAGE;
if ($this->parentcontext) {
return $this->parentcontext;
} else if ($PAGE->context && $PAGE->context instanceof \context_coursecat) {
return $PAGE->context;
}
return \context_system::instance();
} | [
"protected",
"function",
"get_parent_context",
"(",
")",
":",
"\\",
"context",
"{",
"global",
"$",
"PAGE",
";",
"if",
"(",
"$",
"this",
"->",
"parentcontext",
")",
"{",
"return",
"$",
"this",
"->",
"parentcontext",
";",
"}",
"else",
"if",
"(",
"$",
"PAGE",
"->",
"context",
"&&",
"$",
"PAGE",
"->",
"context",
"instanceof",
"\\",
"context_coursecat",
")",
"{",
"return",
"$",
"PAGE",
"->",
"context",
";",
"}",
"return",
"\\",
"context_system",
"::",
"instance",
"(",
")",
";",
"}"
] | Returns the parent context for the course
@return \context | [
"Returns",
"the",
"parent",
"context",
"for",
"the",
"course"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/customfield/course_handler.php#L133-L141 |
212,486 | moodle/moodle | course/classes/customfield/course_handler.php | course_handler.get_instance_context | public function get_instance_context(int $instanceid = 0) : \context {
if ($instanceid > 0) {
return \context_course::instance($instanceid);
} else {
return \context_system::instance();
}
} | php | public function get_instance_context(int $instanceid = 0) : \context {
if ($instanceid > 0) {
return \context_course::instance($instanceid);
} else {
return \context_system::instance();
}
} | [
"public",
"function",
"get_instance_context",
"(",
"int",
"$",
"instanceid",
"=",
"0",
")",
":",
"\\",
"context",
"{",
"if",
"(",
"$",
"instanceid",
">",
"0",
")",
"{",
"return",
"\\",
"context_course",
"::",
"instance",
"(",
"$",
"instanceid",
")",
";",
"}",
"else",
"{",
"return",
"\\",
"context_system",
"::",
"instance",
"(",
")",
";",
"}",
"}"
] | Returns the context for the data associated with the given instanceid.
@param int $instanceid id of the record to get the context for
@return \context the context for the given record | [
"Returns",
"the",
"context",
"for",
"the",
"data",
"associated",
"with",
"the",
"given",
"instanceid",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/customfield/course_handler.php#L167-L173 |
212,487 | moodle/moodle | course/classes/customfield/course_handler.php | course_handler.config_form_definition | public function config_form_definition(\MoodleQuickForm $mform) {
$mform->addElement('header', 'course_handler_header', get_string('customfieldsettings', 'core_course'));
$mform->setExpanded('course_handler_header', true);
// If field is locked.
$mform->addElement('selectyesno', 'configdata[locked]', get_string('customfield_islocked', 'core_course'));
$mform->addHelpButton('configdata[locked]', 'customfield_islocked', 'core_course');
// Field data visibility.
$visibilityoptions = [self::VISIBLETOALL => get_string('customfield_visibletoall', 'core_course'),
self::VISIBLETOTEACHERS => get_string('customfield_visibletoteachers', 'core_course'),
self::NOTVISIBLE => get_string('customfield_notvisible', 'core_course')];
$mform->addElement('select', 'configdata[visibility]', get_string('customfield_visibility', 'core_course'),
$visibilityoptions);
$mform->addHelpButton('configdata[visibility]', 'customfield_visibility', 'core_course');
} | php | public function config_form_definition(\MoodleQuickForm $mform) {
$mform->addElement('header', 'course_handler_header', get_string('customfieldsettings', 'core_course'));
$mform->setExpanded('course_handler_header', true);
// If field is locked.
$mform->addElement('selectyesno', 'configdata[locked]', get_string('customfield_islocked', 'core_course'));
$mform->addHelpButton('configdata[locked]', 'customfield_islocked', 'core_course');
// Field data visibility.
$visibilityoptions = [self::VISIBLETOALL => get_string('customfield_visibletoall', 'core_course'),
self::VISIBLETOTEACHERS => get_string('customfield_visibletoteachers', 'core_course'),
self::NOTVISIBLE => get_string('customfield_notvisible', 'core_course')];
$mform->addElement('select', 'configdata[visibility]', get_string('customfield_visibility', 'core_course'),
$visibilityoptions);
$mform->addHelpButton('configdata[visibility]', 'customfield_visibility', 'core_course');
} | [
"public",
"function",
"config_form_definition",
"(",
"\\",
"MoodleQuickForm",
"$",
"mform",
")",
"{",
"$",
"mform",
"->",
"addElement",
"(",
"'header'",
",",
"'course_handler_header'",
",",
"get_string",
"(",
"'customfieldsettings'",
",",
"'core_course'",
")",
")",
";",
"$",
"mform",
"->",
"setExpanded",
"(",
"'course_handler_header'",
",",
"true",
")",
";",
"// If field is locked.",
"$",
"mform",
"->",
"addElement",
"(",
"'selectyesno'",
",",
"'configdata[locked]'",
",",
"get_string",
"(",
"'customfield_islocked'",
",",
"'core_course'",
")",
")",
";",
"$",
"mform",
"->",
"addHelpButton",
"(",
"'configdata[locked]'",
",",
"'customfield_islocked'",
",",
"'core_course'",
")",
";",
"// Field data visibility.",
"$",
"visibilityoptions",
"=",
"[",
"self",
"::",
"VISIBLETOALL",
"=>",
"get_string",
"(",
"'customfield_visibletoall'",
",",
"'core_course'",
")",
",",
"self",
"::",
"VISIBLETOTEACHERS",
"=>",
"get_string",
"(",
"'customfield_visibletoteachers'",
",",
"'core_course'",
")",
",",
"self",
"::",
"NOTVISIBLE",
"=>",
"get_string",
"(",
"'customfield_notvisible'",
",",
"'core_course'",
")",
"]",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'select'",
",",
"'configdata[visibility]'",
",",
"get_string",
"(",
"'customfield_visibility'",
",",
"'core_course'",
")",
",",
"$",
"visibilityoptions",
")",
";",
"$",
"mform",
"->",
"addHelpButton",
"(",
"'configdata[visibility]'",
",",
"'customfield_visibility'",
",",
"'core_course'",
")",
";",
"}"
] | Allows to add custom controls to the field configuration form that will be saved in configdata
@param \MoodleQuickForm $mform | [
"Allows",
"to",
"add",
"custom",
"controls",
"to",
"the",
"field",
"configuration",
"form",
"that",
"will",
"be",
"saved",
"in",
"configdata"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/customfield/course_handler.php#L180-L195 |
212,488 | moodle/moodle | course/classes/customfield/course_handler.php | course_handler.restore_instance_data_from_backup | public function restore_instance_data_from_backup(\restore_task $task, array $data) {
$courseid = $task->get_courseid();
$context = $this->get_instance_context($courseid);
$editablefields = $this->get_editable_fields($courseid);
$records = api::get_instance_fields_data($editablefields, $courseid);
$target = $task->get_target();
$override = ($target != \backup::TARGET_CURRENT_ADDING && $target != \backup::TARGET_EXISTING_ADDING);
foreach ($records as $d) {
$field = $d->get_field();
if ($field->get('shortname') === $data['shortname'] && $field->get('type') === $data['type']) {
if (!$d->get('id') || $override) {
$d->set($d->datafield(), $data['value']);
$d->set('value', $data['value']);
$d->set('valueformat', $data['valueformat']);
$d->set('contextid', $context->id);
$d->save();
}
return;
}
}
} | php | public function restore_instance_data_from_backup(\restore_task $task, array $data) {
$courseid = $task->get_courseid();
$context = $this->get_instance_context($courseid);
$editablefields = $this->get_editable_fields($courseid);
$records = api::get_instance_fields_data($editablefields, $courseid);
$target = $task->get_target();
$override = ($target != \backup::TARGET_CURRENT_ADDING && $target != \backup::TARGET_EXISTING_ADDING);
foreach ($records as $d) {
$field = $d->get_field();
if ($field->get('shortname') === $data['shortname'] && $field->get('type') === $data['type']) {
if (!$d->get('id') || $override) {
$d->set($d->datafield(), $data['value']);
$d->set('value', $data['value']);
$d->set('valueformat', $data['valueformat']);
$d->set('contextid', $context->id);
$d->save();
}
return;
}
}
} | [
"public",
"function",
"restore_instance_data_from_backup",
"(",
"\\",
"restore_task",
"$",
"task",
",",
"array",
"$",
"data",
")",
"{",
"$",
"courseid",
"=",
"$",
"task",
"->",
"get_courseid",
"(",
")",
";",
"$",
"context",
"=",
"$",
"this",
"->",
"get_instance_context",
"(",
"$",
"courseid",
")",
";",
"$",
"editablefields",
"=",
"$",
"this",
"->",
"get_editable_fields",
"(",
"$",
"courseid",
")",
";",
"$",
"records",
"=",
"api",
"::",
"get_instance_fields_data",
"(",
"$",
"editablefields",
",",
"$",
"courseid",
")",
";",
"$",
"target",
"=",
"$",
"task",
"->",
"get_target",
"(",
")",
";",
"$",
"override",
"=",
"(",
"$",
"target",
"!=",
"\\",
"backup",
"::",
"TARGET_CURRENT_ADDING",
"&&",
"$",
"target",
"!=",
"\\",
"backup",
"::",
"TARGET_EXISTING_ADDING",
")",
";",
"foreach",
"(",
"$",
"records",
"as",
"$",
"d",
")",
"{",
"$",
"field",
"=",
"$",
"d",
"->",
"get_field",
"(",
")",
";",
"if",
"(",
"$",
"field",
"->",
"get",
"(",
"'shortname'",
")",
"===",
"$",
"data",
"[",
"'shortname'",
"]",
"&&",
"$",
"field",
"->",
"get",
"(",
"'type'",
")",
"===",
"$",
"data",
"[",
"'type'",
"]",
")",
"{",
"if",
"(",
"!",
"$",
"d",
"->",
"get",
"(",
"'id'",
")",
"||",
"$",
"override",
")",
"{",
"$",
"d",
"->",
"set",
"(",
"$",
"d",
"->",
"datafield",
"(",
")",
",",
"$",
"data",
"[",
"'value'",
"]",
")",
";",
"$",
"d",
"->",
"set",
"(",
"'value'",
",",
"$",
"data",
"[",
"'value'",
"]",
")",
";",
"$",
"d",
"->",
"set",
"(",
"'valueformat'",
",",
"$",
"data",
"[",
"'valueformat'",
"]",
")",
";",
"$",
"d",
"->",
"set",
"(",
"'contextid'",
",",
"$",
"context",
"->",
"id",
")",
";",
"$",
"d",
"->",
"save",
"(",
")",
";",
"}",
"return",
";",
"}",
"}",
"}"
] | Creates or updates custom field data.
@param \restore_task $task
@param array $data | [
"Creates",
"or",
"updates",
"custom",
"field",
"data",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/customfield/course_handler.php#L203-L224 |
212,489 | moodle/moodle | lib/ltiprovider/src/ToolProvider/Service/Service.php | Service.send | public function send($method, $parameters = array(), $body = null)
{
$url = $this->endpoint;
if (!empty($parameters)) {
if (strpos($url, '?') === false) {
$sep = '?';
} else {
$sep = '&';
}
foreach ($parameters as $name => $value) {
$url .= $sep . urlencode($name) . '=' . urlencode($value);
$sep = '&';
}
}
if (!$this->unsigned) {
$header = ToolProvider\ToolConsumer::addSignature($url, $this->consumer->getKey(), $this->consumer->secret, $body, $method, $this->mediaType);
} else {
$header = null;
}
// Connect to tool consumer
$http = new HTTPMessage($url, $method, $body, $header);
// Parse JSON response
if ($http->send() && !empty($http->response)) {
$http->responseJson = json_decode($http->response);
$http->ok = !is_null($http->responseJson);
}
return $http;
} | php | public function send($method, $parameters = array(), $body = null)
{
$url = $this->endpoint;
if (!empty($parameters)) {
if (strpos($url, '?') === false) {
$sep = '?';
} else {
$sep = '&';
}
foreach ($parameters as $name => $value) {
$url .= $sep . urlencode($name) . '=' . urlencode($value);
$sep = '&';
}
}
if (!$this->unsigned) {
$header = ToolProvider\ToolConsumer::addSignature($url, $this->consumer->getKey(), $this->consumer->secret, $body, $method, $this->mediaType);
} else {
$header = null;
}
// Connect to tool consumer
$http = new HTTPMessage($url, $method, $body, $header);
// Parse JSON response
if ($http->send() && !empty($http->response)) {
$http->responseJson = json_decode($http->response);
$http->ok = !is_null($http->responseJson);
}
return $http;
} | [
"public",
"function",
"send",
"(",
"$",
"method",
",",
"$",
"parameters",
"=",
"array",
"(",
")",
",",
"$",
"body",
"=",
"null",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"endpoint",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"parameters",
")",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"url",
",",
"'?'",
")",
"===",
"false",
")",
"{",
"$",
"sep",
"=",
"'?'",
";",
"}",
"else",
"{",
"$",
"sep",
"=",
"'&'",
";",
"}",
"foreach",
"(",
"$",
"parameters",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"url",
".=",
"$",
"sep",
".",
"urlencode",
"(",
"$",
"name",
")",
".",
"'='",
".",
"urlencode",
"(",
"$",
"value",
")",
";",
"$",
"sep",
"=",
"'&'",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"unsigned",
")",
"{",
"$",
"header",
"=",
"ToolProvider",
"\\",
"ToolConsumer",
"::",
"addSignature",
"(",
"$",
"url",
",",
"$",
"this",
"->",
"consumer",
"->",
"getKey",
"(",
")",
",",
"$",
"this",
"->",
"consumer",
"->",
"secret",
",",
"$",
"body",
",",
"$",
"method",
",",
"$",
"this",
"->",
"mediaType",
")",
";",
"}",
"else",
"{",
"$",
"header",
"=",
"null",
";",
"}",
"// Connect to tool consumer",
"$",
"http",
"=",
"new",
"HTTPMessage",
"(",
"$",
"url",
",",
"$",
"method",
",",
"$",
"body",
",",
"$",
"header",
")",
";",
"// Parse JSON response",
"if",
"(",
"$",
"http",
"->",
"send",
"(",
")",
"&&",
"!",
"empty",
"(",
"$",
"http",
"->",
"response",
")",
")",
"{",
"$",
"http",
"->",
"responseJson",
"=",
"json_decode",
"(",
"$",
"http",
"->",
"response",
")",
";",
"$",
"http",
"->",
"ok",
"=",
"!",
"is_null",
"(",
"$",
"http",
"->",
"responseJson",
")",
";",
"}",
"return",
"$",
"http",
";",
"}"
] | Send a service request.
@param string $method The action type constant (optional, default is GET)
@param array $parameters Query parameters to add to endpoint (optional, default is none)
@param string $body Body of request (optional, default is null)
@return HTTPMessage HTTP object containing request and response details | [
"Send",
"a",
"service",
"request",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ltiprovider/src/ToolProvider/Service/Service.php#L71-L102 |
212,490 | moodle/moodle | lib/webdavlib.php | webdav_client.iso8601totime | function iso8601totime($iso8601) {
/*
date-time = full-date "T" full-time
full-date = date-fullyear "-" date-month "-" date-mday
full-time = partial-time time-offset
date-fullyear = 4DIGIT
date-month = 2DIGIT ; 01-12
date-mday = 2DIGIT ; 01-28, 01-29, 01-30, 01-31 based on
month/year
time-hour = 2DIGIT ; 00-23
time-minute = 2DIGIT ; 00-59
time-second = 2DIGIT ; 00-59, 00-60 based on leap second rules
time-secfrac = "." 1*DIGIT
time-numoffset = ("+" / "-") time-hour ":" time-minute
time-offset = "Z" / time-numoffset
partial-time = time-hour ":" time-minute ":" time-second
[time-secfrac]
*/
$regs = array();
/* [1] [2] [3] [4] [5] [6] */
if (preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})Z$/', $iso8601, $regs)) {
return mktime($regs[4],$regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
}
// to be done: regex for partial-time...apache webdav mod never returns partial-time
return false;
} | php | function iso8601totime($iso8601) {
/*
date-time = full-date "T" full-time
full-date = date-fullyear "-" date-month "-" date-mday
full-time = partial-time time-offset
date-fullyear = 4DIGIT
date-month = 2DIGIT ; 01-12
date-mday = 2DIGIT ; 01-28, 01-29, 01-30, 01-31 based on
month/year
time-hour = 2DIGIT ; 00-23
time-minute = 2DIGIT ; 00-59
time-second = 2DIGIT ; 00-59, 00-60 based on leap second rules
time-secfrac = "." 1*DIGIT
time-numoffset = ("+" / "-") time-hour ":" time-minute
time-offset = "Z" / time-numoffset
partial-time = time-hour ":" time-minute ":" time-second
[time-secfrac]
*/
$regs = array();
/* [1] [2] [3] [4] [5] [6] */
if (preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})Z$/', $iso8601, $regs)) {
return mktime($regs[4],$regs[5], $regs[6], $regs[2], $regs[3], $regs[1]);
}
// to be done: regex for partial-time...apache webdav mod never returns partial-time
return false;
} | [
"function",
"iso8601totime",
"(",
"$",
"iso8601",
")",
"{",
"/*\n\n date-time = full-date \"T\" full-time\n\n full-date = date-fullyear \"-\" date-month \"-\" date-mday\n full-time = partial-time time-offset\n\n date-fullyear = 4DIGIT\n date-month = 2DIGIT ; 01-12\n date-mday = 2DIGIT ; 01-28, 01-29, 01-30, 01-31 based on\n month/year\n time-hour = 2DIGIT ; 00-23\n time-minute = 2DIGIT ; 00-59\n time-second = 2DIGIT ; 00-59, 00-60 based on leap second rules\n time-secfrac = \".\" 1*DIGIT\n time-numoffset = (\"+\" / \"-\") time-hour \":\" time-minute\n time-offset = \"Z\" / time-numoffset\n\n partial-time = time-hour \":\" time-minute \":\" time-second\n [time-secfrac]\n */",
"$",
"regs",
"=",
"array",
"(",
")",
";",
"/* [1] [2] [3] [4] [5] [6] */",
"if",
"(",
"preg_match",
"(",
"'/^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})Z$/'",
",",
"$",
"iso8601",
",",
"$",
"regs",
")",
")",
"{",
"return",
"mktime",
"(",
"$",
"regs",
"[",
"4",
"]",
",",
"$",
"regs",
"[",
"5",
"]",
",",
"$",
"regs",
"[",
"6",
"]",
",",
"$",
"regs",
"[",
"2",
"]",
",",
"$",
"regs",
"[",
"3",
"]",
",",
"$",
"regs",
"[",
"1",
"]",
")",
";",
"}",
"// to be done: regex for partial-time...apache webdav mod never returns partial-time",
"return",
"false",
";",
"}"
] | Convert ISO 8601 Date and Time Profile used in RFC 2518 to an unix timestamp.
@access private
@param string iso8601
@return unixtimestamp on sucess. Otherwise false. | [
"Convert",
"ISO",
"8601",
"Date",
"and",
"Time",
"Profile",
"used",
"in",
"RFC",
"2518",
"to",
"an",
"unix",
"timestamp",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/webdavlib.php#L141-L172 |
212,491 | moodle/moodle | lib/webdavlib.php | webdav_client.open | function open() {
// let's try to open a socket
$this->_error_log('open a socket connection');
$this->sock = fsockopen($this->_socket . $this->_server, $this->_port, $this->_errno, $this->_errstr, $this->_socket_timeout);
core_php_time_limit::raise(30);
if (is_resource($this->sock)) {
socket_set_blocking($this->sock, true);
$this->_connection_closed = false;
$this->_error_log('socket is open: ' . $this->sock);
return true;
} else {
$this->_error_log("$this->_errstr ($this->_errno)\n");
return false;
}
} | php | function open() {
// let's try to open a socket
$this->_error_log('open a socket connection');
$this->sock = fsockopen($this->_socket . $this->_server, $this->_port, $this->_errno, $this->_errstr, $this->_socket_timeout);
core_php_time_limit::raise(30);
if (is_resource($this->sock)) {
socket_set_blocking($this->sock, true);
$this->_connection_closed = false;
$this->_error_log('socket is open: ' . $this->sock);
return true;
} else {
$this->_error_log("$this->_errstr ($this->_errno)\n");
return false;
}
} | [
"function",
"open",
"(",
")",
"{",
"// let's try to open a socket",
"$",
"this",
"->",
"_error_log",
"(",
"'open a socket connection'",
")",
";",
"$",
"this",
"->",
"sock",
"=",
"fsockopen",
"(",
"$",
"this",
"->",
"_socket",
".",
"$",
"this",
"->",
"_server",
",",
"$",
"this",
"->",
"_port",
",",
"$",
"this",
"->",
"_errno",
",",
"$",
"this",
"->",
"_errstr",
",",
"$",
"this",
"->",
"_socket_timeout",
")",
";",
"core_php_time_limit",
"::",
"raise",
"(",
"30",
")",
";",
"if",
"(",
"is_resource",
"(",
"$",
"this",
"->",
"sock",
")",
")",
"{",
"socket_set_blocking",
"(",
"$",
"this",
"->",
"sock",
",",
"true",
")",
";",
"$",
"this",
"->",
"_connection_closed",
"=",
"false",
";",
"$",
"this",
"->",
"_error_log",
"(",
"'socket is open: '",
".",
"$",
"this",
"->",
"sock",
")",
";",
"return",
"true",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_error_log",
"(",
"\"$this->_errstr ($this->_errno)\\n\"",
")",
";",
"return",
"false",
";",
"}",
"}"
] | Open's a socket to a webdav server
@return bool true on success. Otherwise false. | [
"Open",
"s",
"a",
"socket",
"to",
"a",
"webdav",
"server"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/webdavlib.php#L178-L192 |
212,492 | moodle/moodle | lib/webdavlib.php | webdav_client.close | function close() {
$this->_error_log('closing socket ' . $this->sock);
$this->_connection_closed = true;
fclose($this->sock);
} | php | function close() {
$this->_error_log('closing socket ' . $this->sock);
$this->_connection_closed = true;
fclose($this->sock);
} | [
"function",
"close",
"(",
")",
"{",
"$",
"this",
"->",
"_error_log",
"(",
"'closing socket '",
".",
"$",
"this",
"->",
"sock",
")",
";",
"$",
"this",
"->",
"_connection_closed",
"=",
"true",
";",
"fclose",
"(",
"$",
"this",
"->",
"sock",
")",
";",
"}"
] | Closes an open socket. | [
"Closes",
"an",
"open",
"socket",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/webdavlib.php#L197-L201 |
212,493 | moodle/moodle | lib/webdavlib.php | webdav_client.check_webdav | function check_webdav() {
$resp = $this->options();
if (!$resp) {
return false;
}
$this->_error_log($resp['header']['DAV']);
// check schema
if (preg_match('/1,2/', $resp['header']['DAV'])) {
return true;
}
// otherwise return false
return false;
} | php | function check_webdav() {
$resp = $this->options();
if (!$resp) {
return false;
}
$this->_error_log($resp['header']['DAV']);
// check schema
if (preg_match('/1,2/', $resp['header']['DAV'])) {
return true;
}
// otherwise return false
return false;
} | [
"function",
"check_webdav",
"(",
")",
"{",
"$",
"resp",
"=",
"$",
"this",
"->",
"options",
"(",
")",
";",
"if",
"(",
"!",
"$",
"resp",
")",
"{",
"return",
"false",
";",
"}",
"$",
"this",
"->",
"_error_log",
"(",
"$",
"resp",
"[",
"'header'",
"]",
"[",
"'DAV'",
"]",
")",
";",
"// check schema",
"if",
"(",
"preg_match",
"(",
"'/1,2/'",
",",
"$",
"resp",
"[",
"'header'",
"]",
"[",
"'DAV'",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"// otherwise return false",
"return",
"false",
";",
"}"
] | Check's if server is a webdav compliant server.
True if server returns a DAV Element in Header and when
schema 1,2 is supported.
@return bool true if server is webdav server. Otherwise false. | [
"Check",
"s",
"if",
"server",
"is",
"a",
"webdav",
"compliant",
"server",
".",
"True",
"if",
"server",
"returns",
"a",
"DAV",
"Element",
"in",
"Header",
"and",
"when",
"schema",
"1",
"2",
"is",
"supported",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/webdavlib.php#L209-L221 |
212,494 | moodle/moodle | lib/webdavlib.php | webdav_client.options | function options() {
$this->header_unset();
$this->create_basic_request('OPTIONS');
$this->send_request();
$this->get_respond();
$response = $this->process_respond();
// validate the response ...
// check http-version
if ($response['status']['http-version'] == 'HTTP/1.1' ||
$response['status']['http-version'] == 'HTTP/1.0') {
return $response;
}
$this->_error_log('Response was not even http');
return false;
} | php | function options() {
$this->header_unset();
$this->create_basic_request('OPTIONS');
$this->send_request();
$this->get_respond();
$response = $this->process_respond();
// validate the response ...
// check http-version
if ($response['status']['http-version'] == 'HTTP/1.1' ||
$response['status']['http-version'] == 'HTTP/1.0') {
return $response;
}
$this->_error_log('Response was not even http');
return false;
} | [
"function",
"options",
"(",
")",
"{",
"$",
"this",
"->",
"header_unset",
"(",
")",
";",
"$",
"this",
"->",
"create_basic_request",
"(",
"'OPTIONS'",
")",
";",
"$",
"this",
"->",
"send_request",
"(",
")",
";",
"$",
"this",
"->",
"get_respond",
"(",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"process_respond",
"(",
")",
";",
"// validate the response ...",
"// check http-version",
"if",
"(",
"$",
"response",
"[",
"'status'",
"]",
"[",
"'http-version'",
"]",
"==",
"'HTTP/1.1'",
"||",
"$",
"response",
"[",
"'status'",
"]",
"[",
"'http-version'",
"]",
"==",
"'HTTP/1.0'",
")",
"{",
"return",
"$",
"response",
";",
"}",
"$",
"this",
"->",
"_error_log",
"(",
"'Response was not even http'",
")",
";",
"return",
"false",
";",
"}"
] | Get options from webdav server.
@return array with all header fields returned from webdav server. false if server does not speak http. | [
"Get",
"options",
"from",
"webdav",
"server",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/webdavlib.php#L228-L243 |
212,495 | moodle/moodle | lib/webdavlib.php | webdav_client.mkcol | function mkcol($path) {
$this->_path = $this->translate_uri($path);
$this->header_unset();
$this->create_basic_request('MKCOL');
$this->send_request();
$this->get_respond();
$response = $this->process_respond();
// validate the response ...
// check http-version
$http_version = $response['status']['http-version'];
if ($http_version == 'HTTP/1.1' || $http_version == 'HTTP/1.0') {
/** seems to be http ... proceed
* just return what server gave us
* rfc 2518 says:
* 201 (Created) - The collection or structured resource was created in its entirety.
* 403 (Forbidden) - This indicates at least one of two conditions:
* 1) the server does not allow the creation of collections at the given location in its namespace, or
* 2) the parent collection of the Request-URI exists but cannot accept members.
* 405 (Method Not Allowed) - MKCOL can only be executed on a deleted/non-existent resource.
* 409 (Conflict) - A collection cannot be made at the Request-URI until one or more intermediate
* collections have been created.
* 415 (Unsupported Media Type)- The server does not support the request type of the body.
* 507 (Insufficient Storage) - The resource does not have sufficient space to record the state of the
* resource after the execution of this method.
*/
return $response['status']['status-code'];
}
} | php | function mkcol($path) {
$this->_path = $this->translate_uri($path);
$this->header_unset();
$this->create_basic_request('MKCOL');
$this->send_request();
$this->get_respond();
$response = $this->process_respond();
// validate the response ...
// check http-version
$http_version = $response['status']['http-version'];
if ($http_version == 'HTTP/1.1' || $http_version == 'HTTP/1.0') {
/** seems to be http ... proceed
* just return what server gave us
* rfc 2518 says:
* 201 (Created) - The collection or structured resource was created in its entirety.
* 403 (Forbidden) - This indicates at least one of two conditions:
* 1) the server does not allow the creation of collections at the given location in its namespace, or
* 2) the parent collection of the Request-URI exists but cannot accept members.
* 405 (Method Not Allowed) - MKCOL can only be executed on a deleted/non-existent resource.
* 409 (Conflict) - A collection cannot be made at the Request-URI until one or more intermediate
* collections have been created.
* 415 (Unsupported Media Type)- The server does not support the request type of the body.
* 507 (Insufficient Storage) - The resource does not have sufficient space to record the state of the
* resource after the execution of this method.
*/
return $response['status']['status-code'];
}
} | [
"function",
"mkcol",
"(",
"$",
"path",
")",
"{",
"$",
"this",
"->",
"_path",
"=",
"$",
"this",
"->",
"translate_uri",
"(",
"$",
"path",
")",
";",
"$",
"this",
"->",
"header_unset",
"(",
")",
";",
"$",
"this",
"->",
"create_basic_request",
"(",
"'MKCOL'",
")",
";",
"$",
"this",
"->",
"send_request",
"(",
")",
";",
"$",
"this",
"->",
"get_respond",
"(",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"process_respond",
"(",
")",
";",
"// validate the response ...",
"// check http-version",
"$",
"http_version",
"=",
"$",
"response",
"[",
"'status'",
"]",
"[",
"'http-version'",
"]",
";",
"if",
"(",
"$",
"http_version",
"==",
"'HTTP/1.1'",
"||",
"$",
"http_version",
"==",
"'HTTP/1.0'",
")",
"{",
"/** seems to be http ... proceed\n * just return what server gave us\n * rfc 2518 says:\n * 201 (Created) - The collection or structured resource was created in its entirety.\n * 403 (Forbidden) - This indicates at least one of two conditions:\n * 1) the server does not allow the creation of collections at the given location in its namespace, or\n * 2) the parent collection of the Request-URI exists but cannot accept members.\n * 405 (Method Not Allowed) - MKCOL can only be executed on a deleted/non-existent resource.\n * 409 (Conflict) - A collection cannot be made at the Request-URI until one or more intermediate\n * collections have been created.\n * 415 (Unsupported Media Type)- The server does not support the request type of the body.\n * 507 (Insufficient Storage) - The resource does not have sufficient space to record the state of the\n * resource after the execution of this method.\n */",
"return",
"$",
"response",
"[",
"'status'",
"]",
"[",
"'status-code'",
"]",
";",
"}",
"}"
] | Public method mkcol
Creates a new collection/directory on a webdav server
@param string path
@return int status code received as response from webdav server (see rfc 2518) | [
"Public",
"method",
"mkcol"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/webdavlib.php#L252-L280 |
212,496 | moodle/moodle | lib/webdavlib.php | webdav_client.get | function get($path, &$buffer, $fp = null) {
$this->_path = $this->translate_uri($path);
$this->header_unset();
$this->create_basic_request('GET');
$this->send_request();
$this->get_respond($fp);
$response = $this->process_respond();
$http_version = $response['status']['http-version'];
// validate the response
// check http-version
if ($http_version == 'HTTP/1.1' || $http_version == 'HTTP/1.0') {
// seems to be http ... proceed
// We expect a 200 code
if ($response['status']['status-code'] == 200 ) {
if (!is_null($fp)) {
$stat = fstat($fp);
$this->_error_log('file created with ' . $stat['size'] . ' bytes.');
} else {
$this->_error_log('returning buffer with ' . strlen($response['body']) . ' bytes.');
$buffer = $response['body'];
}
}
return $response['status']['status-code'];
}
// ups: no http status was returned ?
return false;
} | php | function get($path, &$buffer, $fp = null) {
$this->_path = $this->translate_uri($path);
$this->header_unset();
$this->create_basic_request('GET');
$this->send_request();
$this->get_respond($fp);
$response = $this->process_respond();
$http_version = $response['status']['http-version'];
// validate the response
// check http-version
if ($http_version == 'HTTP/1.1' || $http_version == 'HTTP/1.0') {
// seems to be http ... proceed
// We expect a 200 code
if ($response['status']['status-code'] == 200 ) {
if (!is_null($fp)) {
$stat = fstat($fp);
$this->_error_log('file created with ' . $stat['size'] . ' bytes.');
} else {
$this->_error_log('returning buffer with ' . strlen($response['body']) . ' bytes.');
$buffer = $response['body'];
}
}
return $response['status']['status-code'];
}
// ups: no http status was returned ?
return false;
} | [
"function",
"get",
"(",
"$",
"path",
",",
"&",
"$",
"buffer",
",",
"$",
"fp",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"_path",
"=",
"$",
"this",
"->",
"translate_uri",
"(",
"$",
"path",
")",
";",
"$",
"this",
"->",
"header_unset",
"(",
")",
";",
"$",
"this",
"->",
"create_basic_request",
"(",
"'GET'",
")",
";",
"$",
"this",
"->",
"send_request",
"(",
")",
";",
"$",
"this",
"->",
"get_respond",
"(",
"$",
"fp",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"process_respond",
"(",
")",
";",
"$",
"http_version",
"=",
"$",
"response",
"[",
"'status'",
"]",
"[",
"'http-version'",
"]",
";",
"// validate the response",
"// check http-version",
"if",
"(",
"$",
"http_version",
"==",
"'HTTP/1.1'",
"||",
"$",
"http_version",
"==",
"'HTTP/1.0'",
")",
"{",
"// seems to be http ... proceed",
"// We expect a 200 code",
"if",
"(",
"$",
"response",
"[",
"'status'",
"]",
"[",
"'status-code'",
"]",
"==",
"200",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"fp",
")",
")",
"{",
"$",
"stat",
"=",
"fstat",
"(",
"$",
"fp",
")",
";",
"$",
"this",
"->",
"_error_log",
"(",
"'file created with '",
".",
"$",
"stat",
"[",
"'size'",
"]",
".",
"' bytes.'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_error_log",
"(",
"'returning buffer with '",
".",
"strlen",
"(",
"$",
"response",
"[",
"'body'",
"]",
")",
".",
"' bytes.'",
")",
";",
"$",
"buffer",
"=",
"$",
"response",
"[",
"'body'",
"]",
";",
"}",
"}",
"return",
"$",
"response",
"[",
"'status'",
"]",
"[",
"'status-code'",
"]",
";",
"}",
"// ups: no http status was returned ?",
"return",
"false",
";",
"}"
] | Public method get
Gets a file from a webdav collection.
@param string $path the path to the file on the webdav server
@param string &$buffer the buffer to store the data in
@param resource $fp optional if included, the data is written directly to this resource and not to the buffer
@return string|bool status code and &$buffer (by reference) with response data from server on success. False on error. | [
"Public",
"method",
"get"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/webdavlib.php#L291-L318 |
212,497 | moodle/moodle | lib/webdavlib.php | webdav_client.put | function put($path, $data ) {
$this->_path = $this->translate_uri($path);
$this->header_unset();
$this->create_basic_request('PUT');
// add more needed header information ...
$this->header_add('Content-length: ' . strlen($data));
$this->header_add('Content-type: application/octet-stream');
// send header
$this->send_request();
// send the rest (data)
fputs($this->sock, $data);
$this->get_respond();
$response = $this->process_respond();
// validate the response
// check http-version
if ($response['status']['http-version'] == 'HTTP/1.1' ||
$response['status']['http-version'] == 'HTTP/1.0') {
// seems to be http ... proceed
// We expect a 200 or 204 status code
// see rfc 2068 - 9.6 PUT...
// print 'http ok<br>';
return $response['status']['status-code'];
}
// ups: no http status was returned ?
return false;
} | php | function put($path, $data ) {
$this->_path = $this->translate_uri($path);
$this->header_unset();
$this->create_basic_request('PUT');
// add more needed header information ...
$this->header_add('Content-length: ' . strlen($data));
$this->header_add('Content-type: application/octet-stream');
// send header
$this->send_request();
// send the rest (data)
fputs($this->sock, $data);
$this->get_respond();
$response = $this->process_respond();
// validate the response
// check http-version
if ($response['status']['http-version'] == 'HTTP/1.1' ||
$response['status']['http-version'] == 'HTTP/1.0') {
// seems to be http ... proceed
// We expect a 200 or 204 status code
// see rfc 2068 - 9.6 PUT...
// print 'http ok<br>';
return $response['status']['status-code'];
}
// ups: no http status was returned ?
return false;
} | [
"function",
"put",
"(",
"$",
"path",
",",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"_path",
"=",
"$",
"this",
"->",
"translate_uri",
"(",
"$",
"path",
")",
";",
"$",
"this",
"->",
"header_unset",
"(",
")",
";",
"$",
"this",
"->",
"create_basic_request",
"(",
"'PUT'",
")",
";",
"// add more needed header information ...",
"$",
"this",
"->",
"header_add",
"(",
"'Content-length: '",
".",
"strlen",
"(",
"$",
"data",
")",
")",
";",
"$",
"this",
"->",
"header_add",
"(",
"'Content-type: application/octet-stream'",
")",
";",
"// send header",
"$",
"this",
"->",
"send_request",
"(",
")",
";",
"// send the rest (data)",
"fputs",
"(",
"$",
"this",
"->",
"sock",
",",
"$",
"data",
")",
";",
"$",
"this",
"->",
"get_respond",
"(",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"process_respond",
"(",
")",
";",
"// validate the response",
"// check http-version",
"if",
"(",
"$",
"response",
"[",
"'status'",
"]",
"[",
"'http-version'",
"]",
"==",
"'HTTP/1.1'",
"||",
"$",
"response",
"[",
"'status'",
"]",
"[",
"'http-version'",
"]",
"==",
"'HTTP/1.0'",
")",
"{",
"// seems to be http ... proceed",
"// We expect a 200 or 204 status code",
"// see rfc 2068 - 9.6 PUT...",
"// print 'http ok<br>';",
"return",
"$",
"response",
"[",
"'status'",
"]",
"[",
"'status-code'",
"]",
";",
"}",
"// ups: no http status was returned ?",
"return",
"false",
";",
"}"
] | Public method put
Puts a file into a collection.
Data is putted as one chunk!
@param string path, string data
@return int status-code read from webdavserver. False on error. | [
"Public",
"method",
"put"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/webdavlib.php#L328-L354 |
212,498 | moodle/moodle | lib/webdavlib.php | webdav_client.put_file | function put_file($path, $filename) {
// try to open the file ...
$handle = @fopen ($filename, 'r');
if ($handle) {
// $this->sock = pfsockopen ($this->_server, $this->_port, $this->_errno, $this->_errstr, $this->_socket_timeout);
$this->_path = $this->translate_uri($path);
$this->header_unset();
$this->create_basic_request('PUT');
// add more needed header information ...
$this->header_add('Content-length: ' . filesize($filename));
$this->header_add('Content-type: application/octet-stream');
// send header
$this->send_request();
while (!feof($handle)) {
fputs($this->sock,fgets($handle,4096));
}
fclose($handle);
$this->get_respond();
$response = $this->process_respond();
// validate the response
// check http-version
if ($response['status']['http-version'] == 'HTTP/1.1' ||
$response['status']['http-version'] == 'HTTP/1.0') {
// seems to be http ... proceed
// We expect a 200 or 204 status code
// see rfc 2068 - 9.6 PUT...
// print 'http ok<br>';
return $response['status']['status-code'];
}
// ups: no http status was returned ?
return false;
} else {
$this->_error_log('put_file: could not open ' . $filename);
return false;
}
} | php | function put_file($path, $filename) {
// try to open the file ...
$handle = @fopen ($filename, 'r');
if ($handle) {
// $this->sock = pfsockopen ($this->_server, $this->_port, $this->_errno, $this->_errstr, $this->_socket_timeout);
$this->_path = $this->translate_uri($path);
$this->header_unset();
$this->create_basic_request('PUT');
// add more needed header information ...
$this->header_add('Content-length: ' . filesize($filename));
$this->header_add('Content-type: application/octet-stream');
// send header
$this->send_request();
while (!feof($handle)) {
fputs($this->sock,fgets($handle,4096));
}
fclose($handle);
$this->get_respond();
$response = $this->process_respond();
// validate the response
// check http-version
if ($response['status']['http-version'] == 'HTTP/1.1' ||
$response['status']['http-version'] == 'HTTP/1.0') {
// seems to be http ... proceed
// We expect a 200 or 204 status code
// see rfc 2068 - 9.6 PUT...
// print 'http ok<br>';
return $response['status']['status-code'];
}
// ups: no http status was returned ?
return false;
} else {
$this->_error_log('put_file: could not open ' . $filename);
return false;
}
} | [
"function",
"put_file",
"(",
"$",
"path",
",",
"$",
"filename",
")",
"{",
"// try to open the file ...",
"$",
"handle",
"=",
"@",
"fopen",
"(",
"$",
"filename",
",",
"'r'",
")",
";",
"if",
"(",
"$",
"handle",
")",
"{",
"// $this->sock = pfsockopen ($this->_server, $this->_port, $this->_errno, $this->_errstr, $this->_socket_timeout);",
"$",
"this",
"->",
"_path",
"=",
"$",
"this",
"->",
"translate_uri",
"(",
"$",
"path",
")",
";",
"$",
"this",
"->",
"header_unset",
"(",
")",
";",
"$",
"this",
"->",
"create_basic_request",
"(",
"'PUT'",
")",
";",
"// add more needed header information ...",
"$",
"this",
"->",
"header_add",
"(",
"'Content-length: '",
".",
"filesize",
"(",
"$",
"filename",
")",
")",
";",
"$",
"this",
"->",
"header_add",
"(",
"'Content-type: application/octet-stream'",
")",
";",
"// send header",
"$",
"this",
"->",
"send_request",
"(",
")",
";",
"while",
"(",
"!",
"feof",
"(",
"$",
"handle",
")",
")",
"{",
"fputs",
"(",
"$",
"this",
"->",
"sock",
",",
"fgets",
"(",
"$",
"handle",
",",
"4096",
")",
")",
";",
"}",
"fclose",
"(",
"$",
"handle",
")",
";",
"$",
"this",
"->",
"get_respond",
"(",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"process_respond",
"(",
")",
";",
"// validate the response",
"// check http-version",
"if",
"(",
"$",
"response",
"[",
"'status'",
"]",
"[",
"'http-version'",
"]",
"==",
"'HTTP/1.1'",
"||",
"$",
"response",
"[",
"'status'",
"]",
"[",
"'http-version'",
"]",
"==",
"'HTTP/1.0'",
")",
"{",
"// seems to be http ... proceed",
"// We expect a 200 or 204 status code",
"// see rfc 2068 - 9.6 PUT...",
"// print 'http ok<br>';",
"return",
"$",
"response",
"[",
"'status'",
"]",
"[",
"'status-code'",
"]",
";",
"}",
"// ups: no http status was returned ?",
"return",
"false",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_error_log",
"(",
"'put_file: could not open '",
".",
"$",
"filename",
")",
";",
"return",
"false",
";",
"}",
"}"
] | Public method put_file
Read a file as stream and puts it chunk by chunk into webdav server collection.
Look at php documenation for legal filenames with fopen();
The filename will be translated into utf-8 if not allready in utf-8.
@param string targetpath, string filename
@return int status code. False on error. | [
"Public",
"method",
"put_file"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/webdavlib.php#L367-L407 |
212,499 | moodle/moodle | lib/webdavlib.php | webdav_client.get_file | function get_file($srcpath, $localpath) {
$localpath = $this->utf_decode_path($localpath);
$handle = fopen($localpath, 'wb');
if ($handle) {
$unused = '';
$ret = $this->get($srcpath, $unused, $handle);
fclose($handle);
if ($ret) {
return true;
}
}
return false;
} | php | function get_file($srcpath, $localpath) {
$localpath = $this->utf_decode_path($localpath);
$handle = fopen($localpath, 'wb');
if ($handle) {
$unused = '';
$ret = $this->get($srcpath, $unused, $handle);
fclose($handle);
if ($ret) {
return true;
}
}
return false;
} | [
"function",
"get_file",
"(",
"$",
"srcpath",
",",
"$",
"localpath",
")",
"{",
"$",
"localpath",
"=",
"$",
"this",
"->",
"utf_decode_path",
"(",
"$",
"localpath",
")",
";",
"$",
"handle",
"=",
"fopen",
"(",
"$",
"localpath",
",",
"'wb'",
")",
";",
"if",
"(",
"$",
"handle",
")",
"{",
"$",
"unused",
"=",
"''",
";",
"$",
"ret",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"srcpath",
",",
"$",
"unused",
",",
"$",
"handle",
")",
";",
"fclose",
"(",
"$",
"handle",
")",
";",
"if",
"(",
"$",
"ret",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Public method get_file
Gets a file from a collection into local filesystem.
fopen() is used.
@param string $srcpath
@param string $localpath
@return bool true on success. false on error. | [
"Public",
"method",
"get_file"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/webdavlib.php#L419-L433 |
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.