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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
220,300
|
moodle/moodle
|
admin/tool/usertours/classes/output/step.php
|
step.export_for_template
|
public function export_for_template(\renderer_base $output) {
global $PAGE;
$step = $this->step;
$result = (object) [
'stepid' => $step->get_id(),
'title' => external_format_text(
stepsource::get_string_from_input($step->get_title()),
FORMAT_HTML,
$PAGE->context->id,
'tool_usertours'
)[0],
'content' => external_format_text(
stepsource::get_string_from_input($step->get_content()),
FORMAT_HTML,
$PAGE->context->id,
'tool_usertours'
)[0],
'element' => $step->get_target()->convert_to_css(),
];
$result->content = str_replace("\n", "<br>\n", $result->content);
foreach ($step->get_config_keys() as $key) {
$result->$key = $step->get_config($key);
}
return $result;
}
|
php
|
public function export_for_template(\renderer_base $output) {
global $PAGE;
$step = $this->step;
$result = (object) [
'stepid' => $step->get_id(),
'title' => external_format_text(
stepsource::get_string_from_input($step->get_title()),
FORMAT_HTML,
$PAGE->context->id,
'tool_usertours'
)[0],
'content' => external_format_text(
stepsource::get_string_from_input($step->get_content()),
FORMAT_HTML,
$PAGE->context->id,
'tool_usertours'
)[0],
'element' => $step->get_target()->convert_to_css(),
];
$result->content = str_replace("\n", "<br>\n", $result->content);
foreach ($step->get_config_keys() as $key) {
$result->$key = $step->get_config($key);
}
return $result;
}
|
[
"public",
"function",
"export_for_template",
"(",
"\\",
"renderer_base",
"$",
"output",
")",
"{",
"global",
"$",
"PAGE",
";",
"$",
"step",
"=",
"$",
"this",
"->",
"step",
";",
"$",
"result",
"=",
"(",
"object",
")",
"[",
"'stepid'",
"=>",
"$",
"step",
"->",
"get_id",
"(",
")",
",",
"'title'",
"=>",
"external_format_text",
"(",
"stepsource",
"::",
"get_string_from_input",
"(",
"$",
"step",
"->",
"get_title",
"(",
")",
")",
",",
"FORMAT_HTML",
",",
"$",
"PAGE",
"->",
"context",
"->",
"id",
",",
"'tool_usertours'",
")",
"[",
"0",
"]",
",",
"'content'",
"=>",
"external_format_text",
"(",
"stepsource",
"::",
"get_string_from_input",
"(",
"$",
"step",
"->",
"get_content",
"(",
")",
")",
",",
"FORMAT_HTML",
",",
"$",
"PAGE",
"->",
"context",
"->",
"id",
",",
"'tool_usertours'",
")",
"[",
"0",
"]",
",",
"'element'",
"=>",
"$",
"step",
"->",
"get_target",
"(",
")",
"->",
"convert_to_css",
"(",
")",
",",
"]",
";",
"$",
"result",
"->",
"content",
"=",
"str_replace",
"(",
"\"\\n\"",
",",
"\"<br>\\n\"",
",",
"$",
"result",
"->",
"content",
")",
";",
"foreach",
"(",
"$",
"step",
"->",
"get_config_keys",
"(",
")",
"as",
"$",
"key",
")",
"{",
"$",
"result",
"->",
"$",
"key",
"=",
"$",
"step",
"->",
"get_config",
"(",
"$",
"key",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Export the step configuration.
@param renderer_base $output The renderer.
@return object
|
[
"Export",
"the",
"step",
"configuration",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/output/step.php#L59-L87
|
220,301
|
moodle/moodle
|
grade/report/singleview/classes/local/screen/grade.php
|
grade.options
|
public function options() {
$options = array();
foreach ($this->items as $userid => $user) {
$options[$userid] = fullname($user);
}
return $options;
}
|
php
|
public function options() {
$options = array();
foreach ($this->items as $userid => $user) {
$options[$userid] = fullname($user);
}
return $options;
}
|
[
"public",
"function",
"options",
"(",
")",
"{",
"$",
"options",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"items",
"as",
"$",
"userid",
"=>",
"$",
"user",
")",
"{",
"$",
"options",
"[",
"$",
"userid",
"]",
"=",
"fullname",
"(",
"$",
"user",
")",
";",
"}",
"return",
"$",
"options",
";",
"}"
] |
Convert this list of items into an options list
@return array
|
[
"Convert",
"this",
"list",
"of",
"items",
"into",
"an",
"options",
"list"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/screen/grade.php#L95-L102
|
220,302
|
moodle/moodle
|
grade/report/singleview/classes/local/screen/grade.php
|
grade.init
|
public function init($selfitemisempty = false) {
$this->items = $this->load_users();
$this->totalitemcount = count($this->items);
if ($selfitemisempty) {
return;
}
$params = array(
'id' => $this->itemid,
'courseid' => $this->courseid
);
$this->item = grade_item::fetch($params);
if (!self::filter($this->item)) {
$this->items = array();
$this->set_init_error(get_string('gradeitemcannotbeoverridden', 'gradereport_singleview'));
}
$this->requiresextra = !$this->item->is_manual_item();
$this->setup_structure();
$this->set_definition($this->original_definition());
$this->set_headers($this->original_headers());
}
|
php
|
public function init($selfitemisempty = false) {
$this->items = $this->load_users();
$this->totalitemcount = count($this->items);
if ($selfitemisempty) {
return;
}
$params = array(
'id' => $this->itemid,
'courseid' => $this->courseid
);
$this->item = grade_item::fetch($params);
if (!self::filter($this->item)) {
$this->items = array();
$this->set_init_error(get_string('gradeitemcannotbeoverridden', 'gradereport_singleview'));
}
$this->requiresextra = !$this->item->is_manual_item();
$this->setup_structure();
$this->set_definition($this->original_definition());
$this->set_headers($this->original_headers());
}
|
[
"public",
"function",
"init",
"(",
"$",
"selfitemisempty",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"items",
"=",
"$",
"this",
"->",
"load_users",
"(",
")",
";",
"$",
"this",
"->",
"totalitemcount",
"=",
"count",
"(",
"$",
"this",
"->",
"items",
")",
";",
"if",
"(",
"$",
"selfitemisempty",
")",
"{",
"return",
";",
"}",
"$",
"params",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"itemid",
",",
"'courseid'",
"=>",
"$",
"this",
"->",
"courseid",
")",
";",
"$",
"this",
"->",
"item",
"=",
"grade_item",
"::",
"fetch",
"(",
"$",
"params",
")",
";",
"if",
"(",
"!",
"self",
"::",
"filter",
"(",
"$",
"this",
"->",
"item",
")",
")",
"{",
"$",
"this",
"->",
"items",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"set_init_error",
"(",
"get_string",
"(",
"'gradeitemcannotbeoverridden'",
",",
"'gradereport_singleview'",
")",
")",
";",
"}",
"$",
"this",
"->",
"requiresextra",
"=",
"!",
"$",
"this",
"->",
"item",
"->",
"is_manual_item",
"(",
")",
";",
"$",
"this",
"->",
"setup_structure",
"(",
")",
";",
"$",
"this",
"->",
"set_definition",
"(",
"$",
"this",
"->",
"original_definition",
"(",
")",
")",
";",
"$",
"this",
"->",
"set_headers",
"(",
"$",
"this",
"->",
"original_headers",
"(",
")",
")",
";",
"}"
] |
Init this page
@param bool $selfitemisempty True if we have not selected a user.
|
[
"Init",
"this",
"page"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/screen/grade.php#L131-L157
|
220,303
|
moodle/moodle
|
grade/report/singleview/classes/local/screen/grade.php
|
grade.format_line
|
public function format_line($item) {
global $OUTPUT;
$grade = $this->fetch_grade_or_default($this->item, $item->id);
$lockicon = '';
$lockedgrade = $lockedgradeitem = 0;
if (!empty($grade->locked)) {
$lockedgrade = 1;
}
if (!empty($grade->grade_item->locked)) {
$lockedgradeitem = 1;
}
// Check both grade and grade item.
if ( $lockedgrade || $lockedgradeitem ) {
$lockicon = $OUTPUT->pix_icon('t/locked', 'grade is locked') . ' ';
}
if (!empty($item->alternatename)) {
$fullname = $lockicon . $item->alternatename . ' (' . $item->firstname . ') ' . $item->lastname;
} else {
$fullname = $lockicon . fullname($item);
}
$item->imagealt = $fullname;
$url = new moodle_url("/user/view.php", array('id' => $item->id, 'course' => $this->courseid));
$iconstring = get_string('filtergrades', 'gradereport_singleview', $fullname);
$grade->label = $fullname;
$line = array(
$OUTPUT->action_icon($this->format_link('user', $item->id), new pix_icon('t/editstring', $iconstring)),
$OUTPUT->user_picture($item, array('visibletoscreenreaders' => false)) .
html_writer::link($url, $fullname),
$this->item_range()
);
$lineclasses = array(
"action",
"user",
"range"
);
$outputline = array();
$i = 0;
foreach ($line as $key => $value) {
$cell = new \html_table_cell($value);
if ($isheader = $i == 1) {
$cell->header = $isheader;
$cell->scope = "row";
}
if (array_key_exists($key, $lineclasses)) {
$cell->attributes['class'] = $lineclasses[$key];
}
$outputline[] = $cell;
$i++;
}
return $this->format_definition($outputline, $grade);
}
|
php
|
public function format_line($item) {
global $OUTPUT;
$grade = $this->fetch_grade_or_default($this->item, $item->id);
$lockicon = '';
$lockedgrade = $lockedgradeitem = 0;
if (!empty($grade->locked)) {
$lockedgrade = 1;
}
if (!empty($grade->grade_item->locked)) {
$lockedgradeitem = 1;
}
// Check both grade and grade item.
if ( $lockedgrade || $lockedgradeitem ) {
$lockicon = $OUTPUT->pix_icon('t/locked', 'grade is locked') . ' ';
}
if (!empty($item->alternatename)) {
$fullname = $lockicon . $item->alternatename . ' (' . $item->firstname . ') ' . $item->lastname;
} else {
$fullname = $lockicon . fullname($item);
}
$item->imagealt = $fullname;
$url = new moodle_url("/user/view.php", array('id' => $item->id, 'course' => $this->courseid));
$iconstring = get_string('filtergrades', 'gradereport_singleview', $fullname);
$grade->label = $fullname;
$line = array(
$OUTPUT->action_icon($this->format_link('user', $item->id), new pix_icon('t/editstring', $iconstring)),
$OUTPUT->user_picture($item, array('visibletoscreenreaders' => false)) .
html_writer::link($url, $fullname),
$this->item_range()
);
$lineclasses = array(
"action",
"user",
"range"
);
$outputline = array();
$i = 0;
foreach ($line as $key => $value) {
$cell = new \html_table_cell($value);
if ($isheader = $i == 1) {
$cell->header = $isheader;
$cell->scope = "row";
}
if (array_key_exists($key, $lineclasses)) {
$cell->attributes['class'] = $lineclasses[$key];
}
$outputline[] = $cell;
$i++;
}
return $this->format_definition($outputline, $grade);
}
|
[
"public",
"function",
"format_line",
"(",
"$",
"item",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"$",
"grade",
"=",
"$",
"this",
"->",
"fetch_grade_or_default",
"(",
"$",
"this",
"->",
"item",
",",
"$",
"item",
"->",
"id",
")",
";",
"$",
"lockicon",
"=",
"''",
";",
"$",
"lockedgrade",
"=",
"$",
"lockedgradeitem",
"=",
"0",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"grade",
"->",
"locked",
")",
")",
"{",
"$",
"lockedgrade",
"=",
"1",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"grade",
"->",
"grade_item",
"->",
"locked",
")",
")",
"{",
"$",
"lockedgradeitem",
"=",
"1",
";",
"}",
"// Check both grade and grade item.",
"if",
"(",
"$",
"lockedgrade",
"||",
"$",
"lockedgradeitem",
")",
"{",
"$",
"lockicon",
"=",
"$",
"OUTPUT",
"->",
"pix_icon",
"(",
"'t/locked'",
",",
"'grade is locked'",
")",
".",
"' '",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"item",
"->",
"alternatename",
")",
")",
"{",
"$",
"fullname",
"=",
"$",
"lockicon",
".",
"$",
"item",
"->",
"alternatename",
".",
"' ('",
".",
"$",
"item",
"->",
"firstname",
".",
"') '",
".",
"$",
"item",
"->",
"lastname",
";",
"}",
"else",
"{",
"$",
"fullname",
"=",
"$",
"lockicon",
".",
"fullname",
"(",
"$",
"item",
")",
";",
"}",
"$",
"item",
"->",
"imagealt",
"=",
"$",
"fullname",
";",
"$",
"url",
"=",
"new",
"moodle_url",
"(",
"\"/user/view.php\"",
",",
"array",
"(",
"'id'",
"=>",
"$",
"item",
"->",
"id",
",",
"'course'",
"=>",
"$",
"this",
"->",
"courseid",
")",
")",
";",
"$",
"iconstring",
"=",
"get_string",
"(",
"'filtergrades'",
",",
"'gradereport_singleview'",
",",
"$",
"fullname",
")",
";",
"$",
"grade",
"->",
"label",
"=",
"$",
"fullname",
";",
"$",
"line",
"=",
"array",
"(",
"$",
"OUTPUT",
"->",
"action_icon",
"(",
"$",
"this",
"->",
"format_link",
"(",
"'user'",
",",
"$",
"item",
"->",
"id",
")",
",",
"new",
"pix_icon",
"(",
"'t/editstring'",
",",
"$",
"iconstring",
")",
")",
",",
"$",
"OUTPUT",
"->",
"user_picture",
"(",
"$",
"item",
",",
"array",
"(",
"'visibletoscreenreaders'",
"=>",
"false",
")",
")",
".",
"html_writer",
"::",
"link",
"(",
"$",
"url",
",",
"$",
"fullname",
")",
",",
"$",
"this",
"->",
"item_range",
"(",
")",
")",
";",
"$",
"lineclasses",
"=",
"array",
"(",
"\"action\"",
",",
"\"user\"",
",",
"\"range\"",
")",
";",
"$",
"outputline",
"=",
"array",
"(",
")",
";",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"line",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"cell",
"=",
"new",
"\\",
"html_table_cell",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"isheader",
"=",
"$",
"i",
"==",
"1",
")",
"{",
"$",
"cell",
"->",
"header",
"=",
"$",
"isheader",
";",
"$",
"cell",
"->",
"scope",
"=",
"\"row\"",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"lineclasses",
")",
")",
"{",
"$",
"cell",
"->",
"attributes",
"[",
"'class'",
"]",
"=",
"$",
"lineclasses",
"[",
"$",
"key",
"]",
";",
"}",
"$",
"outputline",
"[",
"]",
"=",
"$",
"cell",
";",
"$",
"i",
"++",
";",
"}",
"return",
"$",
"this",
"->",
"format_definition",
"(",
"$",
"outputline",
",",
"$",
"grade",
")",
";",
"}"
] |
Format a row in the table
@param user $item
@return string
|
[
"Format",
"a",
"row",
"in",
"the",
"table"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/screen/grade.php#L182-L239
|
220,304
|
moodle/moodle
|
grade/report/singleview/classes/local/screen/grade.php
|
grade.item_range
|
public function item_range() {
if (empty($this->range)) {
$this->range = new range($this->item);
}
return $this->range;
}
|
php
|
public function item_range() {
if (empty($this->range)) {
$this->range = new range($this->item);
}
return $this->range;
}
|
[
"public",
"function",
"item_range",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"range",
")",
")",
"{",
"$",
"this",
"->",
"range",
"=",
"new",
"range",
"(",
"$",
"this",
"->",
"item",
")",
";",
"}",
"return",
"$",
"this",
"->",
"range",
";",
"}"
] |
Get the range ui element for this grade_item
@return element;
|
[
"Get",
"the",
"range",
"ui",
"element",
"for",
"this",
"grade_item"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/screen/grade.php#L246-L252
|
220,305
|
moodle/moodle
|
grade/report/singleview/classes/local/screen/grade.php
|
grade.pager
|
public function pager() {
global $OUTPUT;
return $OUTPUT->paging_bar(
$this->totalitemcount, $this->page, $this->perpage,
new moodle_url('/grade/report/singleview/index.php', array(
'perpage' => $this->perpage,
'id' => $this->courseid,
'group' => $this->groupid,
'itemid' => $this->itemid,
'item' => 'grade'
))
);
}
|
php
|
public function pager() {
global $OUTPUT;
return $OUTPUT->paging_bar(
$this->totalitemcount, $this->page, $this->perpage,
new moodle_url('/grade/report/singleview/index.php', array(
'perpage' => $this->perpage,
'id' => $this->courseid,
'group' => $this->groupid,
'itemid' => $this->itemid,
'item' => 'grade'
))
);
}
|
[
"public",
"function",
"pager",
"(",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"return",
"$",
"OUTPUT",
"->",
"paging_bar",
"(",
"$",
"this",
"->",
"totalitemcount",
",",
"$",
"this",
"->",
"page",
",",
"$",
"this",
"->",
"perpage",
",",
"new",
"moodle_url",
"(",
"'/grade/report/singleview/index.php'",
",",
"array",
"(",
"'perpage'",
"=>",
"$",
"this",
"->",
"perpage",
",",
"'id'",
"=>",
"$",
"this",
"->",
"courseid",
",",
"'group'",
"=>",
"$",
"this",
"->",
"groupid",
",",
"'itemid'",
"=>",
"$",
"this",
"->",
"itemid",
",",
"'item'",
"=>",
"'grade'",
")",
")",
")",
";",
"}"
] |
Get the pager for this page.
@return string
|
[
"Get",
"the",
"pager",
"for",
"this",
"page",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/screen/grade.php#L268-L281
|
220,306
|
moodle/moodle
|
mod/lti/service/gradebookservices/classes/local/resources/lineitem.php
|
lineitem.get_request
|
private function get_request($response, $item, $typeid) {
$response->set_content_type($this->formats[0]);
$lineitem = gradebookservices::item_for_json($item, substr(parent::get_endpoint(),
0, strrpos(parent::get_endpoint(), "/", -10)), $typeid);
$response->set_body(json_encode($lineitem));
}
|
php
|
private function get_request($response, $item, $typeid) {
$response->set_content_type($this->formats[0]);
$lineitem = gradebookservices::item_for_json($item, substr(parent::get_endpoint(),
0, strrpos(parent::get_endpoint(), "/", -10)), $typeid);
$response->set_body(json_encode($lineitem));
}
|
[
"private",
"function",
"get_request",
"(",
"$",
"response",
",",
"$",
"item",
",",
"$",
"typeid",
")",
"{",
"$",
"response",
"->",
"set_content_type",
"(",
"$",
"this",
"->",
"formats",
"[",
"0",
"]",
")",
";",
"$",
"lineitem",
"=",
"gradebookservices",
"::",
"item_for_json",
"(",
"$",
"item",
",",
"substr",
"(",
"parent",
"::",
"get_endpoint",
"(",
")",
",",
"0",
",",
"strrpos",
"(",
"parent",
"::",
"get_endpoint",
"(",
")",
",",
"\"/\"",
",",
"-",
"10",
")",
")",
",",
"$",
"typeid",
")",
";",
"$",
"response",
"->",
"set_body",
"(",
"json_encode",
"(",
"$",
"lineitem",
")",
")",
";",
"}"
] |
Process a GET request.
@param \mod_lti\local\ltiservice\response $response Response object for this request.
@param object $item Grade item instance.
@param string $typeid Tool Type Id
|
[
"Process",
"a",
"GET",
"request",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lti/service/gradebookservices/classes/local/resources/lineitem.php#L161-L168
|
220,307
|
moodle/moodle
|
mod/lti/service/gradebookservices/classes/local/resources/lineitem.php
|
lineitem.process_delete_request
|
private function process_delete_request($item) {
global $DB;
$gradeitem = \grade_item::fetch(array('id' => $item->id));
if (($gbs = gradebookservices::find_ltiservice_gradebookservice_for_lineitem($item->id)) == false) {
throw new \Exception(null, 403);
}
if (!$gradeitem->delete('mod/ltiservice_gradebookservices')) {
throw new \Exception(null, 500);
} else {
$sqlparams = array();
$sqlparams['id'] = $gbs->id;
if (!$DB->delete_records('ltiservice_gradebookservices', $sqlparams)) {
throw new \Exception(null, 500);
}
}
}
|
php
|
private function process_delete_request($item) {
global $DB;
$gradeitem = \grade_item::fetch(array('id' => $item->id));
if (($gbs = gradebookservices::find_ltiservice_gradebookservice_for_lineitem($item->id)) == false) {
throw new \Exception(null, 403);
}
if (!$gradeitem->delete('mod/ltiservice_gradebookservices')) {
throw new \Exception(null, 500);
} else {
$sqlparams = array();
$sqlparams['id'] = $gbs->id;
if (!$DB->delete_records('ltiservice_gradebookservices', $sqlparams)) {
throw new \Exception(null, 500);
}
}
}
|
[
"private",
"function",
"process_delete_request",
"(",
"$",
"item",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"gradeitem",
"=",
"\\",
"grade_item",
"::",
"fetch",
"(",
"array",
"(",
"'id'",
"=>",
"$",
"item",
"->",
"id",
")",
")",
";",
"if",
"(",
"(",
"$",
"gbs",
"=",
"gradebookservices",
"::",
"find_ltiservice_gradebookservice_for_lineitem",
"(",
"$",
"item",
"->",
"id",
")",
")",
"==",
"false",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"null",
",",
"403",
")",
";",
"}",
"if",
"(",
"!",
"$",
"gradeitem",
"->",
"delete",
"(",
"'mod/ltiservice_gradebookservices'",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"null",
",",
"500",
")",
";",
"}",
"else",
"{",
"$",
"sqlparams",
"=",
"array",
"(",
")",
";",
"$",
"sqlparams",
"[",
"'id'",
"]",
"=",
"$",
"gbs",
"->",
"id",
";",
"if",
"(",
"!",
"$",
"DB",
"->",
"delete_records",
"(",
"'ltiservice_gradebookservices'",
",",
"$",
"sqlparams",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"null",
",",
"500",
")",
";",
"}",
"}",
"}"
] |
Process a DELETE request.
@param \ltiservice_gradebookservices\local\resources\lineitem $item Grade item instance
@throws \Exception
|
[
"Process",
"a",
"DELETE",
"request",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lti/service/gradebookservices/classes/local/resources/lineitem.php#L301-L317
|
220,308
|
moodle/moodle
|
enrol/self/lib.php
|
enrol_self_plugin.enrol_self
|
public function enrol_self(stdClass $instance, $data = null) {
global $DB, $USER, $CFG;
// Don't enrol user if password is not passed when required.
if ($instance->password && !isset($data->enrolpassword)) {
return;
}
$timestart = time();
if ($instance->enrolperiod) {
$timeend = $timestart + $instance->enrolperiod;
} else {
$timeend = 0;
}
$this->enrol_user($instance, $USER->id, $instance->roleid, $timestart, $timeend);
if ($instance->password and $instance->customint1 and $data->enrolpassword !== $instance->password) {
// It must be a group enrolment, let's assign group too.
$groups = $DB->get_records('groups', array('courseid'=>$instance->courseid), 'id', 'id, enrolmentkey');
foreach ($groups as $group) {
if (empty($group->enrolmentkey)) {
continue;
}
if ($group->enrolmentkey === $data->enrolpassword) {
// Add user to group.
require_once($CFG->dirroot.'/group/lib.php');
groups_add_member($group->id, $USER->id);
break;
}
}
}
// Send welcome message.
if ($instance->customint4 != ENROL_DO_NOT_SEND_EMAIL) {
$this->email_welcome_message($instance, $USER);
}
}
|
php
|
public function enrol_self(stdClass $instance, $data = null) {
global $DB, $USER, $CFG;
// Don't enrol user if password is not passed when required.
if ($instance->password && !isset($data->enrolpassword)) {
return;
}
$timestart = time();
if ($instance->enrolperiod) {
$timeend = $timestart + $instance->enrolperiod;
} else {
$timeend = 0;
}
$this->enrol_user($instance, $USER->id, $instance->roleid, $timestart, $timeend);
if ($instance->password and $instance->customint1 and $data->enrolpassword !== $instance->password) {
// It must be a group enrolment, let's assign group too.
$groups = $DB->get_records('groups', array('courseid'=>$instance->courseid), 'id', 'id, enrolmentkey');
foreach ($groups as $group) {
if (empty($group->enrolmentkey)) {
continue;
}
if ($group->enrolmentkey === $data->enrolpassword) {
// Add user to group.
require_once($CFG->dirroot.'/group/lib.php');
groups_add_member($group->id, $USER->id);
break;
}
}
}
// Send welcome message.
if ($instance->customint4 != ENROL_DO_NOT_SEND_EMAIL) {
$this->email_welcome_message($instance, $USER);
}
}
|
[
"public",
"function",
"enrol_self",
"(",
"stdClass",
"$",
"instance",
",",
"$",
"data",
"=",
"null",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"USER",
",",
"$",
"CFG",
";",
"// Don't enrol user if password is not passed when required.",
"if",
"(",
"$",
"instance",
"->",
"password",
"&&",
"!",
"isset",
"(",
"$",
"data",
"->",
"enrolpassword",
")",
")",
"{",
"return",
";",
"}",
"$",
"timestart",
"=",
"time",
"(",
")",
";",
"if",
"(",
"$",
"instance",
"->",
"enrolperiod",
")",
"{",
"$",
"timeend",
"=",
"$",
"timestart",
"+",
"$",
"instance",
"->",
"enrolperiod",
";",
"}",
"else",
"{",
"$",
"timeend",
"=",
"0",
";",
"}",
"$",
"this",
"->",
"enrol_user",
"(",
"$",
"instance",
",",
"$",
"USER",
"->",
"id",
",",
"$",
"instance",
"->",
"roleid",
",",
"$",
"timestart",
",",
"$",
"timeend",
")",
";",
"if",
"(",
"$",
"instance",
"->",
"password",
"and",
"$",
"instance",
"->",
"customint1",
"and",
"$",
"data",
"->",
"enrolpassword",
"!==",
"$",
"instance",
"->",
"password",
")",
"{",
"// It must be a group enrolment, let's assign group too.",
"$",
"groups",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'groups'",
",",
"array",
"(",
"'courseid'",
"=>",
"$",
"instance",
"->",
"courseid",
")",
",",
"'id'",
",",
"'id, enrolmentkey'",
")",
";",
"foreach",
"(",
"$",
"groups",
"as",
"$",
"group",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"group",
"->",
"enrolmentkey",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"group",
"->",
"enrolmentkey",
"===",
"$",
"data",
"->",
"enrolpassword",
")",
"{",
"// Add user to group.",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/group/lib.php'",
")",
";",
"groups_add_member",
"(",
"$",
"group",
"->",
"id",
",",
"$",
"USER",
"->",
"id",
")",
";",
"break",
";",
"}",
"}",
"}",
"// Send welcome message.",
"if",
"(",
"$",
"instance",
"->",
"customint4",
"!=",
"ENROL_DO_NOT_SEND_EMAIL",
")",
"{",
"$",
"this",
"->",
"email_welcome_message",
"(",
"$",
"instance",
",",
"$",
"USER",
")",
";",
"}",
"}"
] |
Self enrol user to course
@param stdClass $instance enrolment instance
@param stdClass $data data needed for enrolment.
@return bool|array true if enroled else eddor code and messege
|
[
"Self",
"enrol",
"user",
"to",
"course"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/self/lib.php#L143-L179
|
220,309
|
moodle/moodle
|
enrol/self/lib.php
|
enrol_self_plugin.can_self_enrol
|
public function can_self_enrol(stdClass $instance, $checkuserenrolment = true) {
global $CFG, $DB, $OUTPUT, $USER;
if ($checkuserenrolment) {
if (isguestuser()) {
// Can not enrol guest.
return get_string('noguestaccess', 'enrol') . $OUTPUT->continue_button(get_login_url());
}
// Check if user is already enroled.
if ($DB->get_record('user_enrolments', array('userid' => $USER->id, 'enrolid' => $instance->id))) {
return get_string('canntenrol', 'enrol_self');
}
}
if ($instance->status != ENROL_INSTANCE_ENABLED) {
return get_string('canntenrol', 'enrol_self');
}
if ($instance->enrolstartdate != 0 and $instance->enrolstartdate > time()) {
return get_string('canntenrolearly', 'enrol_self', userdate($instance->enrolstartdate));
}
if ($instance->enrolenddate != 0 and $instance->enrolenddate < time()) {
return get_string('canntenrollate', 'enrol_self', userdate($instance->enrolenddate));
}
if (!$instance->customint6) {
// New enrols not allowed.
return get_string('canntenrol', 'enrol_self');
}
if ($DB->record_exists('user_enrolments', array('userid' => $USER->id, 'enrolid' => $instance->id))) {
return get_string('canntenrol', 'enrol_self');
}
if ($instance->customint3 > 0) {
// Max enrol limit specified.
$count = $DB->count_records('user_enrolments', array('enrolid' => $instance->id));
if ($count >= $instance->customint3) {
// Bad luck, no more self enrolments here.
return get_string('maxenrolledreached', 'enrol_self');
}
}
if ($instance->customint5) {
require_once("$CFG->dirroot/cohort/lib.php");
if (!cohort_is_member($instance->customint5, $USER->id)) {
$cohort = $DB->get_record('cohort', array('id' => $instance->customint5));
if (!$cohort) {
return null;
}
$a = format_string($cohort->name, true, array('context' => context::instance_by_id($cohort->contextid)));
return markdown_to_html(get_string('cohortnonmemberinfo', 'enrol_self', $a));
}
}
return true;
}
|
php
|
public function can_self_enrol(stdClass $instance, $checkuserenrolment = true) {
global $CFG, $DB, $OUTPUT, $USER;
if ($checkuserenrolment) {
if (isguestuser()) {
// Can not enrol guest.
return get_string('noguestaccess', 'enrol') . $OUTPUT->continue_button(get_login_url());
}
// Check if user is already enroled.
if ($DB->get_record('user_enrolments', array('userid' => $USER->id, 'enrolid' => $instance->id))) {
return get_string('canntenrol', 'enrol_self');
}
}
if ($instance->status != ENROL_INSTANCE_ENABLED) {
return get_string('canntenrol', 'enrol_self');
}
if ($instance->enrolstartdate != 0 and $instance->enrolstartdate > time()) {
return get_string('canntenrolearly', 'enrol_self', userdate($instance->enrolstartdate));
}
if ($instance->enrolenddate != 0 and $instance->enrolenddate < time()) {
return get_string('canntenrollate', 'enrol_self', userdate($instance->enrolenddate));
}
if (!$instance->customint6) {
// New enrols not allowed.
return get_string('canntenrol', 'enrol_self');
}
if ($DB->record_exists('user_enrolments', array('userid' => $USER->id, 'enrolid' => $instance->id))) {
return get_string('canntenrol', 'enrol_self');
}
if ($instance->customint3 > 0) {
// Max enrol limit specified.
$count = $DB->count_records('user_enrolments', array('enrolid' => $instance->id));
if ($count >= $instance->customint3) {
// Bad luck, no more self enrolments here.
return get_string('maxenrolledreached', 'enrol_self');
}
}
if ($instance->customint5) {
require_once("$CFG->dirroot/cohort/lib.php");
if (!cohort_is_member($instance->customint5, $USER->id)) {
$cohort = $DB->get_record('cohort', array('id' => $instance->customint5));
if (!$cohort) {
return null;
}
$a = format_string($cohort->name, true, array('context' => context::instance_by_id($cohort->contextid)));
return markdown_to_html(get_string('cohortnonmemberinfo', 'enrol_self', $a));
}
}
return true;
}
|
[
"public",
"function",
"can_self_enrol",
"(",
"stdClass",
"$",
"instance",
",",
"$",
"checkuserenrolment",
"=",
"true",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
",",
"$",
"OUTPUT",
",",
"$",
"USER",
";",
"if",
"(",
"$",
"checkuserenrolment",
")",
"{",
"if",
"(",
"isguestuser",
"(",
")",
")",
"{",
"// Can not enrol guest.",
"return",
"get_string",
"(",
"'noguestaccess'",
",",
"'enrol'",
")",
".",
"$",
"OUTPUT",
"->",
"continue_button",
"(",
"get_login_url",
"(",
")",
")",
";",
"}",
"// Check if user is already enroled.",
"if",
"(",
"$",
"DB",
"->",
"get_record",
"(",
"'user_enrolments'",
",",
"array",
"(",
"'userid'",
"=>",
"$",
"USER",
"->",
"id",
",",
"'enrolid'",
"=>",
"$",
"instance",
"->",
"id",
")",
")",
")",
"{",
"return",
"get_string",
"(",
"'canntenrol'",
",",
"'enrol_self'",
")",
";",
"}",
"}",
"if",
"(",
"$",
"instance",
"->",
"status",
"!=",
"ENROL_INSTANCE_ENABLED",
")",
"{",
"return",
"get_string",
"(",
"'canntenrol'",
",",
"'enrol_self'",
")",
";",
"}",
"if",
"(",
"$",
"instance",
"->",
"enrolstartdate",
"!=",
"0",
"and",
"$",
"instance",
"->",
"enrolstartdate",
">",
"time",
"(",
")",
")",
"{",
"return",
"get_string",
"(",
"'canntenrolearly'",
",",
"'enrol_self'",
",",
"userdate",
"(",
"$",
"instance",
"->",
"enrolstartdate",
")",
")",
";",
"}",
"if",
"(",
"$",
"instance",
"->",
"enrolenddate",
"!=",
"0",
"and",
"$",
"instance",
"->",
"enrolenddate",
"<",
"time",
"(",
")",
")",
"{",
"return",
"get_string",
"(",
"'canntenrollate'",
",",
"'enrol_self'",
",",
"userdate",
"(",
"$",
"instance",
"->",
"enrolenddate",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"instance",
"->",
"customint6",
")",
"{",
"// New enrols not allowed.",
"return",
"get_string",
"(",
"'canntenrol'",
",",
"'enrol_self'",
")",
";",
"}",
"if",
"(",
"$",
"DB",
"->",
"record_exists",
"(",
"'user_enrolments'",
",",
"array",
"(",
"'userid'",
"=>",
"$",
"USER",
"->",
"id",
",",
"'enrolid'",
"=>",
"$",
"instance",
"->",
"id",
")",
")",
")",
"{",
"return",
"get_string",
"(",
"'canntenrol'",
",",
"'enrol_self'",
")",
";",
"}",
"if",
"(",
"$",
"instance",
"->",
"customint3",
">",
"0",
")",
"{",
"// Max enrol limit specified.",
"$",
"count",
"=",
"$",
"DB",
"->",
"count_records",
"(",
"'user_enrolments'",
",",
"array",
"(",
"'enrolid'",
"=>",
"$",
"instance",
"->",
"id",
")",
")",
";",
"if",
"(",
"$",
"count",
">=",
"$",
"instance",
"->",
"customint3",
")",
"{",
"// Bad luck, no more self enrolments here.",
"return",
"get_string",
"(",
"'maxenrolledreached'",
",",
"'enrol_self'",
")",
";",
"}",
"}",
"if",
"(",
"$",
"instance",
"->",
"customint5",
")",
"{",
"require_once",
"(",
"\"$CFG->dirroot/cohort/lib.php\"",
")",
";",
"if",
"(",
"!",
"cohort_is_member",
"(",
"$",
"instance",
"->",
"customint5",
",",
"$",
"USER",
"->",
"id",
")",
")",
"{",
"$",
"cohort",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'cohort'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"instance",
"->",
"customint5",
")",
")",
";",
"if",
"(",
"!",
"$",
"cohort",
")",
"{",
"return",
"null",
";",
"}",
"$",
"a",
"=",
"format_string",
"(",
"$",
"cohort",
"->",
"name",
",",
"true",
",",
"array",
"(",
"'context'",
"=>",
"context",
"::",
"instance_by_id",
"(",
"$",
"cohort",
"->",
"contextid",
")",
")",
")",
";",
"return",
"markdown_to_html",
"(",
"get_string",
"(",
"'cohortnonmemberinfo'",
",",
"'enrol_self'",
",",
"$",
"a",
")",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Checks if user can self enrol.
@param stdClass $instance enrolment instance
@param bool $checkuserenrolment if true will check if user enrolment is inactive.
used by navigation to improve performance.
@return bool|string true if successful, else error message or false.
|
[
"Checks",
"if",
"user",
"can",
"self",
"enrol",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/self/lib.php#L231-L288
|
220,310
|
moodle/moodle
|
enrol/self/lib.php
|
enrol_self_plugin.get_instance_defaults
|
public function get_instance_defaults() {
$expirynotify = $this->get_config('expirynotify');
if ($expirynotify == 2) {
$expirynotify = 1;
$notifyall = 1;
} else {
$notifyall = 0;
}
$fields = array();
$fields['status'] = $this->get_config('status');
$fields['roleid'] = $this->get_config('roleid');
$fields['enrolperiod'] = $this->get_config('enrolperiod');
$fields['expirynotify'] = $expirynotify;
$fields['notifyall'] = $notifyall;
$fields['expirythreshold'] = $this->get_config('expirythreshold');
$fields['customint1'] = $this->get_config('groupkey');
$fields['customint2'] = $this->get_config('longtimenosee');
$fields['customint3'] = $this->get_config('maxenrolled');
$fields['customint4'] = $this->get_config('sendcoursewelcomemessage');
$fields['customint5'] = 0;
$fields['customint6'] = $this->get_config('newenrols');
return $fields;
}
|
php
|
public function get_instance_defaults() {
$expirynotify = $this->get_config('expirynotify');
if ($expirynotify == 2) {
$expirynotify = 1;
$notifyall = 1;
} else {
$notifyall = 0;
}
$fields = array();
$fields['status'] = $this->get_config('status');
$fields['roleid'] = $this->get_config('roleid');
$fields['enrolperiod'] = $this->get_config('enrolperiod');
$fields['expirynotify'] = $expirynotify;
$fields['notifyall'] = $notifyall;
$fields['expirythreshold'] = $this->get_config('expirythreshold');
$fields['customint1'] = $this->get_config('groupkey');
$fields['customint2'] = $this->get_config('longtimenosee');
$fields['customint3'] = $this->get_config('maxenrolled');
$fields['customint4'] = $this->get_config('sendcoursewelcomemessage');
$fields['customint5'] = 0;
$fields['customint6'] = $this->get_config('newenrols');
return $fields;
}
|
[
"public",
"function",
"get_instance_defaults",
"(",
")",
"{",
"$",
"expirynotify",
"=",
"$",
"this",
"->",
"get_config",
"(",
"'expirynotify'",
")",
";",
"if",
"(",
"$",
"expirynotify",
"==",
"2",
")",
"{",
"$",
"expirynotify",
"=",
"1",
";",
"$",
"notifyall",
"=",
"1",
";",
"}",
"else",
"{",
"$",
"notifyall",
"=",
"0",
";",
"}",
"$",
"fields",
"=",
"array",
"(",
")",
";",
"$",
"fields",
"[",
"'status'",
"]",
"=",
"$",
"this",
"->",
"get_config",
"(",
"'status'",
")",
";",
"$",
"fields",
"[",
"'roleid'",
"]",
"=",
"$",
"this",
"->",
"get_config",
"(",
"'roleid'",
")",
";",
"$",
"fields",
"[",
"'enrolperiod'",
"]",
"=",
"$",
"this",
"->",
"get_config",
"(",
"'enrolperiod'",
")",
";",
"$",
"fields",
"[",
"'expirynotify'",
"]",
"=",
"$",
"expirynotify",
";",
"$",
"fields",
"[",
"'notifyall'",
"]",
"=",
"$",
"notifyall",
";",
"$",
"fields",
"[",
"'expirythreshold'",
"]",
"=",
"$",
"this",
"->",
"get_config",
"(",
"'expirythreshold'",
")",
";",
"$",
"fields",
"[",
"'customint1'",
"]",
"=",
"$",
"this",
"->",
"get_config",
"(",
"'groupkey'",
")",
";",
"$",
"fields",
"[",
"'customint2'",
"]",
"=",
"$",
"this",
"->",
"get_config",
"(",
"'longtimenosee'",
")",
";",
"$",
"fields",
"[",
"'customint3'",
"]",
"=",
"$",
"this",
"->",
"get_config",
"(",
"'maxenrolled'",
")",
";",
"$",
"fields",
"[",
"'customint4'",
"]",
"=",
"$",
"this",
"->",
"get_config",
"(",
"'sendcoursewelcomemessage'",
")",
";",
"$",
"fields",
"[",
"'customint5'",
"]",
"=",
"0",
";",
"$",
"fields",
"[",
"'customint6'",
"]",
"=",
"$",
"this",
"->",
"get_config",
"(",
"'newenrols'",
")",
";",
"return",
"$",
"fields",
";",
"}"
] |
Returns defaults for new instances.
@return array
|
[
"Returns",
"defaults",
"for",
"new",
"instances",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/self/lib.php#L337-L361
|
220,311
|
moodle/moodle
|
enrol/self/lib.php
|
enrol_self_plugin.email_welcome_message
|
protected function email_welcome_message($instance, $user) {
global $CFG, $DB;
$course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_EXIST);
$context = context_course::instance($course->id);
$a = new stdClass();
$a->coursename = format_string($course->fullname, true, array('context'=>$context));
$a->profileurl = "$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id";
if (trim($instance->customtext1) !== '') {
$message = $instance->customtext1;
$key = array('{$a->coursename}', '{$a->profileurl}', '{$a->fullname}', '{$a->email}');
$value = array($a->coursename, $a->profileurl, fullname($user), $user->email);
$message = str_replace($key, $value, $message);
if (strpos($message, '<') === false) {
// Plain text only.
$messagetext = $message;
$messagehtml = text_to_html($messagetext, null, false, true);
} else {
// This is most probably the tag/newline soup known as FORMAT_MOODLE.
$messagehtml = format_text($message, FORMAT_MOODLE, array('context'=>$context, 'para'=>false, 'newlines'=>true, 'filter'=>true));
$messagetext = html_to_text($messagehtml);
}
} else {
$messagetext = get_string('welcometocoursetext', 'enrol_self', $a);
$messagehtml = text_to_html($messagetext, null, false, true);
}
$subject = get_string('welcometocourse', 'enrol_self', format_string($course->fullname, true, array('context'=>$context)));
$sendoption = $instance->customint4;
$contact = $this->get_welcome_email_contact($sendoption, $context);
// Directly emailing welcome message rather than using messaging.
email_to_user($user, $contact, $subject, $messagetext, $messagehtml);
}
|
php
|
protected function email_welcome_message($instance, $user) {
global $CFG, $DB;
$course = $DB->get_record('course', array('id'=>$instance->courseid), '*', MUST_EXIST);
$context = context_course::instance($course->id);
$a = new stdClass();
$a->coursename = format_string($course->fullname, true, array('context'=>$context));
$a->profileurl = "$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id";
if (trim($instance->customtext1) !== '') {
$message = $instance->customtext1;
$key = array('{$a->coursename}', '{$a->profileurl}', '{$a->fullname}', '{$a->email}');
$value = array($a->coursename, $a->profileurl, fullname($user), $user->email);
$message = str_replace($key, $value, $message);
if (strpos($message, '<') === false) {
// Plain text only.
$messagetext = $message;
$messagehtml = text_to_html($messagetext, null, false, true);
} else {
// This is most probably the tag/newline soup known as FORMAT_MOODLE.
$messagehtml = format_text($message, FORMAT_MOODLE, array('context'=>$context, 'para'=>false, 'newlines'=>true, 'filter'=>true));
$messagetext = html_to_text($messagehtml);
}
} else {
$messagetext = get_string('welcometocoursetext', 'enrol_self', $a);
$messagehtml = text_to_html($messagetext, null, false, true);
}
$subject = get_string('welcometocourse', 'enrol_self', format_string($course->fullname, true, array('context'=>$context)));
$sendoption = $instance->customint4;
$contact = $this->get_welcome_email_contact($sendoption, $context);
// Directly emailing welcome message rather than using messaging.
email_to_user($user, $contact, $subject, $messagetext, $messagehtml);
}
|
[
"protected",
"function",
"email_welcome_message",
"(",
"$",
"instance",
",",
"$",
"user",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
";",
"$",
"course",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'course'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"instance",
"->",
"courseid",
")",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"course",
"->",
"id",
")",
";",
"$",
"a",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"a",
"->",
"coursename",
"=",
"format_string",
"(",
"$",
"course",
"->",
"fullname",
",",
"true",
",",
"array",
"(",
"'context'",
"=>",
"$",
"context",
")",
")",
";",
"$",
"a",
"->",
"profileurl",
"=",
"\"$CFG->wwwroot/user/view.php?id=$user->id&course=$course->id\"",
";",
"if",
"(",
"trim",
"(",
"$",
"instance",
"->",
"customtext1",
")",
"!==",
"''",
")",
"{",
"$",
"message",
"=",
"$",
"instance",
"->",
"customtext1",
";",
"$",
"key",
"=",
"array",
"(",
"'{$a->coursename}'",
",",
"'{$a->profileurl}'",
",",
"'{$a->fullname}'",
",",
"'{$a->email}'",
")",
";",
"$",
"value",
"=",
"array",
"(",
"$",
"a",
"->",
"coursename",
",",
"$",
"a",
"->",
"profileurl",
",",
"fullname",
"(",
"$",
"user",
")",
",",
"$",
"user",
"->",
"email",
")",
";",
"$",
"message",
"=",
"str_replace",
"(",
"$",
"key",
",",
"$",
"value",
",",
"$",
"message",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"message",
",",
"'<'",
")",
"===",
"false",
")",
"{",
"// Plain text only.",
"$",
"messagetext",
"=",
"$",
"message",
";",
"$",
"messagehtml",
"=",
"text_to_html",
"(",
"$",
"messagetext",
",",
"null",
",",
"false",
",",
"true",
")",
";",
"}",
"else",
"{",
"// This is most probably the tag/newline soup known as FORMAT_MOODLE.",
"$",
"messagehtml",
"=",
"format_text",
"(",
"$",
"message",
",",
"FORMAT_MOODLE",
",",
"array",
"(",
"'context'",
"=>",
"$",
"context",
",",
"'para'",
"=>",
"false",
",",
"'newlines'",
"=>",
"true",
",",
"'filter'",
"=>",
"true",
")",
")",
";",
"$",
"messagetext",
"=",
"html_to_text",
"(",
"$",
"messagehtml",
")",
";",
"}",
"}",
"else",
"{",
"$",
"messagetext",
"=",
"get_string",
"(",
"'welcometocoursetext'",
",",
"'enrol_self'",
",",
"$",
"a",
")",
";",
"$",
"messagehtml",
"=",
"text_to_html",
"(",
"$",
"messagetext",
",",
"null",
",",
"false",
",",
"true",
")",
";",
"}",
"$",
"subject",
"=",
"get_string",
"(",
"'welcometocourse'",
",",
"'enrol_self'",
",",
"format_string",
"(",
"$",
"course",
"->",
"fullname",
",",
"true",
",",
"array",
"(",
"'context'",
"=>",
"$",
"context",
")",
")",
")",
";",
"$",
"sendoption",
"=",
"$",
"instance",
"->",
"customint4",
";",
"$",
"contact",
"=",
"$",
"this",
"->",
"get_welcome_email_contact",
"(",
"$",
"sendoption",
",",
"$",
"context",
")",
";",
"// Directly emailing welcome message rather than using messaging.",
"email_to_user",
"(",
"$",
"user",
",",
"$",
"contact",
",",
"$",
"subject",
",",
"$",
"messagetext",
",",
"$",
"messagehtml",
")",
";",
"}"
] |
Send welcome email to specified user.
@param stdClass $instance
@param stdClass $user user record
@return void
|
[
"Send",
"welcome",
"email",
"to",
"specified",
"user",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/self/lib.php#L370-L406
|
220,312
|
moodle/moodle
|
enrol/self/lib.php
|
enrol_self_plugin.get_enroller
|
protected function get_enroller($instanceid) {
global $DB;
if ($this->lasternollerinstanceid == $instanceid and $this->lasternoller) {
return $this->lasternoller;
}
$instance = $DB->get_record('enrol', array('id'=>$instanceid, 'enrol'=>$this->get_name()), '*', MUST_EXIST);
$context = context_course::instance($instance->courseid);
if ($users = get_enrolled_users($context, 'enrol/self:manage')) {
$users = sort_by_roleassignment_authority($users, $context);
$this->lasternoller = reset($users);
unset($users);
} else {
$this->lasternoller = parent::get_enroller($instanceid);
}
$this->lasternollerinstanceid = $instanceid;
return $this->lasternoller;
}
|
php
|
protected function get_enroller($instanceid) {
global $DB;
if ($this->lasternollerinstanceid == $instanceid and $this->lasternoller) {
return $this->lasternoller;
}
$instance = $DB->get_record('enrol', array('id'=>$instanceid, 'enrol'=>$this->get_name()), '*', MUST_EXIST);
$context = context_course::instance($instance->courseid);
if ($users = get_enrolled_users($context, 'enrol/self:manage')) {
$users = sort_by_roleassignment_authority($users, $context);
$this->lasternoller = reset($users);
unset($users);
} else {
$this->lasternoller = parent::get_enroller($instanceid);
}
$this->lasternollerinstanceid = $instanceid;
return $this->lasternoller;
}
|
[
"protected",
"function",
"get_enroller",
"(",
"$",
"instanceid",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"$",
"this",
"->",
"lasternollerinstanceid",
"==",
"$",
"instanceid",
"and",
"$",
"this",
"->",
"lasternoller",
")",
"{",
"return",
"$",
"this",
"->",
"lasternoller",
";",
"}",
"$",
"instance",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'enrol'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"instanceid",
",",
"'enrol'",
"=>",
"$",
"this",
"->",
"get_name",
"(",
")",
")",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"instance",
"->",
"courseid",
")",
";",
"if",
"(",
"$",
"users",
"=",
"get_enrolled_users",
"(",
"$",
"context",
",",
"'enrol/self:manage'",
")",
")",
"{",
"$",
"users",
"=",
"sort_by_roleassignment_authority",
"(",
"$",
"users",
",",
"$",
"context",
")",
";",
"$",
"this",
"->",
"lasternoller",
"=",
"reset",
"(",
"$",
"users",
")",
";",
"unset",
"(",
"$",
"users",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"lasternoller",
"=",
"parent",
"::",
"get_enroller",
"(",
"$",
"instanceid",
")",
";",
"}",
"$",
"this",
"->",
"lasternollerinstanceid",
"=",
"$",
"instanceid",
";",
"return",
"$",
"this",
"->",
"lasternoller",
";",
"}"
] |
Returns the user who is responsible for self enrolments in given instance.
Usually it is the first editing teacher - the person with "highest authority"
as defined by sort_by_roleassignment_authority() having 'enrol/self:manage'
capability.
@param int $instanceid enrolment instance id
@return stdClass user record
|
[
"Returns",
"the",
"user",
"who",
"is",
"responsible",
"for",
"self",
"enrolments",
"in",
"given",
"instance",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/self/lib.php#L491-L512
|
220,313
|
moodle/moodle
|
enrol/self/lib.php
|
enrol_self_plugin.get_longtimenosee_options
|
protected function get_longtimenosee_options() {
$options = array(0 => get_string('never'),
1800 * 3600 * 24 => get_string('numdays', '', 1800),
1000 * 3600 * 24 => get_string('numdays', '', 1000),
365 * 3600 * 24 => get_string('numdays', '', 365),
180 * 3600 * 24 => get_string('numdays', '', 180),
150 * 3600 * 24 => get_string('numdays', '', 150),
120 * 3600 * 24 => get_string('numdays', '', 120),
90 * 3600 * 24 => get_string('numdays', '', 90),
60 * 3600 * 24 => get_string('numdays', '', 60),
30 * 3600 * 24 => get_string('numdays', '', 30),
21 * 3600 * 24 => get_string('numdays', '', 21),
14 * 3600 * 24 => get_string('numdays', '', 14),
7 * 3600 * 24 => get_string('numdays', '', 7));
return $options;
}
|
php
|
protected function get_longtimenosee_options() {
$options = array(0 => get_string('never'),
1800 * 3600 * 24 => get_string('numdays', '', 1800),
1000 * 3600 * 24 => get_string('numdays', '', 1000),
365 * 3600 * 24 => get_string('numdays', '', 365),
180 * 3600 * 24 => get_string('numdays', '', 180),
150 * 3600 * 24 => get_string('numdays', '', 150),
120 * 3600 * 24 => get_string('numdays', '', 120),
90 * 3600 * 24 => get_string('numdays', '', 90),
60 * 3600 * 24 => get_string('numdays', '', 60),
30 * 3600 * 24 => get_string('numdays', '', 30),
21 * 3600 * 24 => get_string('numdays', '', 21),
14 * 3600 * 24 => get_string('numdays', '', 14),
7 * 3600 * 24 => get_string('numdays', '', 7));
return $options;
}
|
[
"protected",
"function",
"get_longtimenosee_options",
"(",
")",
"{",
"$",
"options",
"=",
"array",
"(",
"0",
"=>",
"get_string",
"(",
"'never'",
")",
",",
"1800",
"*",
"3600",
"*",
"24",
"=>",
"get_string",
"(",
"'numdays'",
",",
"''",
",",
"1800",
")",
",",
"1000",
"*",
"3600",
"*",
"24",
"=>",
"get_string",
"(",
"'numdays'",
",",
"''",
",",
"1000",
")",
",",
"365",
"*",
"3600",
"*",
"24",
"=>",
"get_string",
"(",
"'numdays'",
",",
"''",
",",
"365",
")",
",",
"180",
"*",
"3600",
"*",
"24",
"=>",
"get_string",
"(",
"'numdays'",
",",
"''",
",",
"180",
")",
",",
"150",
"*",
"3600",
"*",
"24",
"=>",
"get_string",
"(",
"'numdays'",
",",
"''",
",",
"150",
")",
",",
"120",
"*",
"3600",
"*",
"24",
"=>",
"get_string",
"(",
"'numdays'",
",",
"''",
",",
"120",
")",
",",
"90",
"*",
"3600",
"*",
"24",
"=>",
"get_string",
"(",
"'numdays'",
",",
"''",
",",
"90",
")",
",",
"60",
"*",
"3600",
"*",
"24",
"=>",
"get_string",
"(",
"'numdays'",
",",
"''",
",",
"60",
")",
",",
"30",
"*",
"3600",
"*",
"24",
"=>",
"get_string",
"(",
"'numdays'",
",",
"''",
",",
"30",
")",
",",
"21",
"*",
"3600",
"*",
"24",
"=>",
"get_string",
"(",
"'numdays'",
",",
"''",
",",
"21",
")",
",",
"14",
"*",
"3600",
"*",
"24",
"=>",
"get_string",
"(",
"'numdays'",
",",
"''",
",",
"14",
")",
",",
"7",
"*",
"3600",
"*",
"24",
"=>",
"get_string",
"(",
"'numdays'",
",",
"''",
",",
"7",
")",
")",
";",
"return",
"$",
"options",
";",
"}"
] |
Return an array of valid options for the longtimenosee property.
@return array
|
[
"Return",
"an",
"array",
"of",
"valid",
"options",
"for",
"the",
"longtimenosee",
"property",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/self/lib.php#L670-L685
|
220,314
|
moodle/moodle
|
enrol/self/lib.php
|
enrol_self_plugin.get_bulk_operations
|
public function get_bulk_operations(course_enrolment_manager $manager) {
global $CFG;
require_once($CFG->dirroot.'/enrol/self/locallib.php');
$context = $manager->get_context();
$bulkoperations = array();
if (has_capability("enrol/self:manage", $context)) {
$bulkoperations['editselectedusers'] = new enrol_self_editselectedusers_operation($manager, $this);
}
if (has_capability("enrol/self:unenrol", $context)) {
$bulkoperations['deleteselectedusers'] = new enrol_self_deleteselectedusers_operation($manager, $this);
}
return $bulkoperations;
}
|
php
|
public function get_bulk_operations(course_enrolment_manager $manager) {
global $CFG;
require_once($CFG->dirroot.'/enrol/self/locallib.php');
$context = $manager->get_context();
$bulkoperations = array();
if (has_capability("enrol/self:manage", $context)) {
$bulkoperations['editselectedusers'] = new enrol_self_editselectedusers_operation($manager, $this);
}
if (has_capability("enrol/self:unenrol", $context)) {
$bulkoperations['deleteselectedusers'] = new enrol_self_deleteselectedusers_operation($manager, $this);
}
return $bulkoperations;
}
|
[
"public",
"function",
"get_bulk_operations",
"(",
"course_enrolment_manager",
"$",
"manager",
")",
"{",
"global",
"$",
"CFG",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/enrol/self/locallib.php'",
")",
";",
"$",
"context",
"=",
"$",
"manager",
"->",
"get_context",
"(",
")",
";",
"$",
"bulkoperations",
"=",
"array",
"(",
")",
";",
"if",
"(",
"has_capability",
"(",
"\"enrol/self:manage\"",
",",
"$",
"context",
")",
")",
"{",
"$",
"bulkoperations",
"[",
"'editselectedusers'",
"]",
"=",
"new",
"enrol_self_editselectedusers_operation",
"(",
"$",
"manager",
",",
"$",
"this",
")",
";",
"}",
"if",
"(",
"has_capability",
"(",
"\"enrol/self:unenrol\"",
",",
"$",
"context",
")",
")",
"{",
"$",
"bulkoperations",
"[",
"'deleteselectedusers'",
"]",
"=",
"new",
"enrol_self_deleteselectedusers_operation",
"(",
"$",
"manager",
",",
"$",
"this",
")",
";",
"}",
"return",
"$",
"bulkoperations",
";",
"}"
] |
The self enrollment plugin has several bulk operations that can be performed.
@param course_enrolment_manager $manager
@return array
|
[
"The",
"self",
"enrollment",
"plugin",
"has",
"several",
"bulk",
"operations",
"that",
"can",
"be",
"performed",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/self/lib.php#L692-L704
|
220,315
|
moodle/moodle
|
enrol/self/lib.php
|
enrol_self_plugin.extend_assignable_roles
|
public function extend_assignable_roles($context, $defaultrole) {
global $DB;
$roles = get_assignable_roles($context, ROLENAME_BOTH);
if (!isset($roles[$defaultrole])) {
if ($role = $DB->get_record('role', array('id' => $defaultrole))) {
$roles[$defaultrole] = role_get_name($role, $context, ROLENAME_BOTH);
}
}
return $roles;
}
|
php
|
public function extend_assignable_roles($context, $defaultrole) {
global $DB;
$roles = get_assignable_roles($context, ROLENAME_BOTH);
if (!isset($roles[$defaultrole])) {
if ($role = $DB->get_record('role', array('id' => $defaultrole))) {
$roles[$defaultrole] = role_get_name($role, $context, ROLENAME_BOTH);
}
}
return $roles;
}
|
[
"public",
"function",
"extend_assignable_roles",
"(",
"$",
"context",
",",
"$",
"defaultrole",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"roles",
"=",
"get_assignable_roles",
"(",
"$",
"context",
",",
"ROLENAME_BOTH",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"roles",
"[",
"$",
"defaultrole",
"]",
")",
")",
"{",
"if",
"(",
"$",
"role",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'role'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"defaultrole",
")",
")",
")",
"{",
"$",
"roles",
"[",
"$",
"defaultrole",
"]",
"=",
"role_get_name",
"(",
"$",
"role",
",",
"$",
"context",
",",
"ROLENAME_BOTH",
")",
";",
"}",
"}",
"return",
"$",
"roles",
";",
"}"
] |
Gets a list of roles that this user can assign for the course as the default for self-enrolment.
@param context $context the context.
@param integer $defaultrole the id of the role that is set as the default for self-enrolment
@return array index is the role id, value is the role name
|
[
"Gets",
"a",
"list",
"of",
"roles",
"that",
"this",
"user",
"can",
"assign",
"for",
"the",
"course",
"as",
"the",
"default",
"for",
"self",
"-",
"enrolment",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/self/lib.php#L983-L993
|
220,316
|
moodle/moodle
|
enrol/self/lib.php
|
enrol_self_plugin.get_welcome_email_contact
|
public function get_welcome_email_contact($sendoption, $context) {
global $CFG;
$contact = null;
// Send as the first user assigned as the course contact.
if ($sendoption == ENROL_SEND_EMAIL_FROM_COURSE_CONTACT) {
$rusers = array();
if (!empty($CFG->coursecontact)) {
$croles = explode(',', $CFG->coursecontact);
list($sort, $sortparams) = users_order_by_sql('u');
// We only use the first user.
$i = 0;
do {
$allnames = get_all_user_name_fields(true, 'u');
$rusers = get_role_users($croles[$i], $context, true, 'u.id, u.confirmed, u.username, '. $allnames . ',
u.email, r.sortorder, ra.id', 'r.sortorder, ra.id ASC, ' . $sort, null, '', '', '', '', $sortparams);
$i++;
} while (empty($rusers) && !empty($croles[$i]));
}
if ($rusers) {
$contact = array_values($rusers)[0];
}
} else if ($sendoption == ENROL_SEND_EMAIL_FROM_KEY_HOLDER) {
// Send as the first user with enrol/self:holdkey capability assigned in the course.
list($sort) = users_order_by_sql('u');
$keyholders = get_users_by_capability($context, 'enrol/self:holdkey', 'u.*', $sort);
if (!empty($keyholders)) {
$contact = array_values($keyholders)[0];
}
}
// If send welcome email option is set to no reply or if none of the previous options have
// returned a contact send welcome message as noreplyuser.
if ($sendoption == ENROL_SEND_EMAIL_FROM_NOREPLY || empty($contact)) {
$contact = core_user::get_noreply_user();
}
return $contact;
}
|
php
|
public function get_welcome_email_contact($sendoption, $context) {
global $CFG;
$contact = null;
// Send as the first user assigned as the course contact.
if ($sendoption == ENROL_SEND_EMAIL_FROM_COURSE_CONTACT) {
$rusers = array();
if (!empty($CFG->coursecontact)) {
$croles = explode(',', $CFG->coursecontact);
list($sort, $sortparams) = users_order_by_sql('u');
// We only use the first user.
$i = 0;
do {
$allnames = get_all_user_name_fields(true, 'u');
$rusers = get_role_users($croles[$i], $context, true, 'u.id, u.confirmed, u.username, '. $allnames . ',
u.email, r.sortorder, ra.id', 'r.sortorder, ra.id ASC, ' . $sort, null, '', '', '', '', $sortparams);
$i++;
} while (empty($rusers) && !empty($croles[$i]));
}
if ($rusers) {
$contact = array_values($rusers)[0];
}
} else if ($sendoption == ENROL_SEND_EMAIL_FROM_KEY_HOLDER) {
// Send as the first user with enrol/self:holdkey capability assigned in the course.
list($sort) = users_order_by_sql('u');
$keyholders = get_users_by_capability($context, 'enrol/self:holdkey', 'u.*', $sort);
if (!empty($keyholders)) {
$contact = array_values($keyholders)[0];
}
}
// If send welcome email option is set to no reply or if none of the previous options have
// returned a contact send welcome message as noreplyuser.
if ($sendoption == ENROL_SEND_EMAIL_FROM_NOREPLY || empty($contact)) {
$contact = core_user::get_noreply_user();
}
return $contact;
}
|
[
"public",
"function",
"get_welcome_email_contact",
"(",
"$",
"sendoption",
",",
"$",
"context",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"contact",
"=",
"null",
";",
"// Send as the first user assigned as the course contact.",
"if",
"(",
"$",
"sendoption",
"==",
"ENROL_SEND_EMAIL_FROM_COURSE_CONTACT",
")",
"{",
"$",
"rusers",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"CFG",
"->",
"coursecontact",
")",
")",
"{",
"$",
"croles",
"=",
"explode",
"(",
"','",
",",
"$",
"CFG",
"->",
"coursecontact",
")",
";",
"list",
"(",
"$",
"sort",
",",
"$",
"sortparams",
")",
"=",
"users_order_by_sql",
"(",
"'u'",
")",
";",
"// We only use the first user.",
"$",
"i",
"=",
"0",
";",
"do",
"{",
"$",
"allnames",
"=",
"get_all_user_name_fields",
"(",
"true",
",",
"'u'",
")",
";",
"$",
"rusers",
"=",
"get_role_users",
"(",
"$",
"croles",
"[",
"$",
"i",
"]",
",",
"$",
"context",
",",
"true",
",",
"'u.id, u.confirmed, u.username, '",
".",
"$",
"allnames",
".",
"',\n u.email, r.sortorder, ra.id'",
",",
"'r.sortorder, ra.id ASC, '",
".",
"$",
"sort",
",",
"null",
",",
"''",
",",
"''",
",",
"''",
",",
"''",
",",
"$",
"sortparams",
")",
";",
"$",
"i",
"++",
";",
"}",
"while",
"(",
"empty",
"(",
"$",
"rusers",
")",
"&&",
"!",
"empty",
"(",
"$",
"croles",
"[",
"$",
"i",
"]",
")",
")",
";",
"}",
"if",
"(",
"$",
"rusers",
")",
"{",
"$",
"contact",
"=",
"array_values",
"(",
"$",
"rusers",
")",
"[",
"0",
"]",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"sendoption",
"==",
"ENROL_SEND_EMAIL_FROM_KEY_HOLDER",
")",
"{",
"// Send as the first user with enrol/self:holdkey capability assigned in the course.",
"list",
"(",
"$",
"sort",
")",
"=",
"users_order_by_sql",
"(",
"'u'",
")",
";",
"$",
"keyholders",
"=",
"get_users_by_capability",
"(",
"$",
"context",
",",
"'enrol/self:holdkey'",
",",
"'u.*'",
",",
"$",
"sort",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"keyholders",
")",
")",
"{",
"$",
"contact",
"=",
"array_values",
"(",
"$",
"keyholders",
")",
"[",
"0",
"]",
";",
"}",
"}",
"// If send welcome email option is set to no reply or if none of the previous options have",
"// returned a contact send welcome message as noreplyuser.",
"if",
"(",
"$",
"sendoption",
"==",
"ENROL_SEND_EMAIL_FROM_NOREPLY",
"||",
"empty",
"(",
"$",
"contact",
")",
")",
"{",
"$",
"contact",
"=",
"core_user",
"::",
"get_noreply_user",
"(",
")",
";",
"}",
"return",
"$",
"contact",
";",
"}"
] |
Get the "from" contact which the email will be sent from.
@param int $sendoption send email from constant ENROL_SEND_EMAIL_FROM_*
@param $context context where the user will be fetched
@return mixed|stdClass the contact user object.
|
[
"Get",
"the",
"from",
"contact",
"which",
"the",
"email",
"will",
"be",
"sent",
"from",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/self/lib.php#L1002-L1040
|
220,317
|
moodle/moodle
|
auth/manual/auth.php
|
auth_plugin_manual.password_expire
|
public function password_expire($username) {
$result = 0;
if (!empty($this->config->expirationtime)) {
$user = core_user::get_user_by_username($username, 'id,timecreated');
$lastpasswordupdatetime = get_user_preferences('auth_manual_passwordupdatetime', $user->timecreated, $user->id);
$expiretime = $lastpasswordupdatetime + $this->config->expirationtime * DAYSECS;
$now = time();
$result = ($expiretime - $now) / DAYSECS;
if ($expiretime > $now) {
$result = ceil($result);
} else {
$result = floor($result);
}
}
return $result;
}
|
php
|
public function password_expire($username) {
$result = 0;
if (!empty($this->config->expirationtime)) {
$user = core_user::get_user_by_username($username, 'id,timecreated');
$lastpasswordupdatetime = get_user_preferences('auth_manual_passwordupdatetime', $user->timecreated, $user->id);
$expiretime = $lastpasswordupdatetime + $this->config->expirationtime * DAYSECS;
$now = time();
$result = ($expiretime - $now) / DAYSECS;
if ($expiretime > $now) {
$result = ceil($result);
} else {
$result = floor($result);
}
}
return $result;
}
|
[
"public",
"function",
"password_expire",
"(",
"$",
"username",
")",
"{",
"$",
"result",
"=",
"0",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"config",
"->",
"expirationtime",
")",
")",
"{",
"$",
"user",
"=",
"core_user",
"::",
"get_user_by_username",
"(",
"$",
"username",
",",
"'id,timecreated'",
")",
";",
"$",
"lastpasswordupdatetime",
"=",
"get_user_preferences",
"(",
"'auth_manual_passwordupdatetime'",
",",
"$",
"user",
"->",
"timecreated",
",",
"$",
"user",
"->",
"id",
")",
";",
"$",
"expiretime",
"=",
"$",
"lastpasswordupdatetime",
"+",
"$",
"this",
"->",
"config",
"->",
"expirationtime",
"*",
"DAYSECS",
";",
"$",
"now",
"=",
"time",
"(",
")",
";",
"$",
"result",
"=",
"(",
"$",
"expiretime",
"-",
"$",
"now",
")",
"/",
"DAYSECS",
";",
"if",
"(",
"$",
"expiretime",
">",
"$",
"now",
")",
"{",
"$",
"result",
"=",
"ceil",
"(",
"$",
"result",
")",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"floor",
"(",
"$",
"result",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] |
Return number of days to user password expires.
If user password does not expire, it should return 0 or a positive value.
If user password is already expired, it should return negative value.
@param mixed $username username (with system magic quotes)
@return integer
|
[
"Return",
"number",
"of",
"days",
"to",
"user",
"password",
"expires",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/manual/auth.php#L169-L186
|
220,318
|
moodle/moodle
|
auth/manual/auth.php
|
auth_plugin_manual.user_confirm
|
function user_confirm($username, $confirmsecret = null) {
global $DB;
$user = get_complete_user_data('username', $username);
if (!empty($user)) {
if ($user->confirmed) {
return AUTH_CONFIRM_ALREADY;
} else {
$DB->set_field("user", "confirmed", 1, array("id"=>$user->id));
return AUTH_CONFIRM_OK;
}
} else {
return AUTH_CONFIRM_ERROR;
}
}
|
php
|
function user_confirm($username, $confirmsecret = null) {
global $DB;
$user = get_complete_user_data('username', $username);
if (!empty($user)) {
if ($user->confirmed) {
return AUTH_CONFIRM_ALREADY;
} else {
$DB->set_field("user", "confirmed", 1, array("id"=>$user->id));
return AUTH_CONFIRM_OK;
}
} else {
return AUTH_CONFIRM_ERROR;
}
}
|
[
"function",
"user_confirm",
"(",
"$",
"username",
",",
"$",
"confirmsecret",
"=",
"null",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"user",
"=",
"get_complete_user_data",
"(",
"'username'",
",",
"$",
"username",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"user",
")",
")",
"{",
"if",
"(",
"$",
"user",
"->",
"confirmed",
")",
"{",
"return",
"AUTH_CONFIRM_ALREADY",
";",
"}",
"else",
"{",
"$",
"DB",
"->",
"set_field",
"(",
"\"user\"",
",",
"\"confirmed\"",
",",
"1",
",",
"array",
"(",
"\"id\"",
"=>",
"$",
"user",
"->",
"id",
")",
")",
";",
"return",
"AUTH_CONFIRM_OK",
";",
"}",
"}",
"else",
"{",
"return",
"AUTH_CONFIRM_ERROR",
";",
"}",
"}"
] |
Confirm the new user as registered. This should normally not be used,
but it may be necessary if the user auth_method is changed to manual
before the user is confirmed.
@param string $username
@param string $confirmsecret
|
[
"Confirm",
"the",
"new",
"user",
"as",
"registered",
".",
"This",
"should",
"normally",
"not",
"be",
"used",
"but",
"it",
"may",
"be",
"necessary",
"if",
"the",
"user",
"auth_method",
"is",
"changed",
"to",
"manual",
"before",
"the",
"user",
"is",
"confirmed",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/manual/auth.php#L196-L211
|
220,319
|
moodle/moodle
|
mod/quiz/report/attemptsreport.php
|
quiz_attempts_report.init
|
protected function init($mode, $formclass, $quiz, $cm, $course) {
$this->mode = $mode;
$this->context = context_module::instance($cm->id);
list($currentgroup, $studentsjoins, $groupstudentsjoins, $allowedjoins) = $this->get_students_joins(
$cm, $course);
$this->qmsubselect = quiz_report_qm_filter_select($quiz);
$this->form = new $formclass($this->get_base_url(),
array('quiz' => $quiz, 'currentgroup' => $currentgroup, 'context' => $this->context));
return array($currentgroup, $studentsjoins, $groupstudentsjoins, $allowedjoins);
}
|
php
|
protected function init($mode, $formclass, $quiz, $cm, $course) {
$this->mode = $mode;
$this->context = context_module::instance($cm->id);
list($currentgroup, $studentsjoins, $groupstudentsjoins, $allowedjoins) = $this->get_students_joins(
$cm, $course);
$this->qmsubselect = quiz_report_qm_filter_select($quiz);
$this->form = new $formclass($this->get_base_url(),
array('quiz' => $quiz, 'currentgroup' => $currentgroup, 'context' => $this->context));
return array($currentgroup, $studentsjoins, $groupstudentsjoins, $allowedjoins);
}
|
[
"protected",
"function",
"init",
"(",
"$",
"mode",
",",
"$",
"formclass",
",",
"$",
"quiz",
",",
"$",
"cm",
",",
"$",
"course",
")",
"{",
"$",
"this",
"->",
"mode",
"=",
"$",
"mode",
";",
"$",
"this",
"->",
"context",
"=",
"context_module",
"::",
"instance",
"(",
"$",
"cm",
"->",
"id",
")",
";",
"list",
"(",
"$",
"currentgroup",
",",
"$",
"studentsjoins",
",",
"$",
"groupstudentsjoins",
",",
"$",
"allowedjoins",
")",
"=",
"$",
"this",
"->",
"get_students_joins",
"(",
"$",
"cm",
",",
"$",
"course",
")",
";",
"$",
"this",
"->",
"qmsubselect",
"=",
"quiz_report_qm_filter_select",
"(",
"$",
"quiz",
")",
";",
"$",
"this",
"->",
"form",
"=",
"new",
"$",
"formclass",
"(",
"$",
"this",
"->",
"get_base_url",
"(",
")",
",",
"array",
"(",
"'quiz'",
"=>",
"$",
"quiz",
",",
"'currentgroup'",
"=>",
"$",
"currentgroup",
",",
"'context'",
"=>",
"$",
"this",
"->",
"context",
")",
")",
";",
"return",
"array",
"(",
"$",
"currentgroup",
",",
"$",
"studentsjoins",
",",
"$",
"groupstudentsjoins",
",",
"$",
"allowedjoins",
")",
";",
"}"
] |
Initialise various aspects of this report.
@param string $mode
@param string $formclass
@param object $quiz
@param object $cm
@param object $course
@return array with four elements:
0 => integer the current group id (0 for none).
1 => \core\dml\sql_join Contains joins, wheres, params for all the students in this course.
2 => \core\dml\sql_join Contains joins, wheres, params for all the students in the current group.
3 => \core\dml\sql_join Contains joins, wheres, params for all the students to show in the report.
Will be the same as either element 1 or 2.
|
[
"Initialise",
"various",
"aspects",
"of",
"this",
"report",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/attemptsreport.php#L82-L96
|
220,320
|
moodle/moodle
|
mod/quiz/report/attemptsreport.php
|
quiz_attempts_report.print_standard_header_and_messages
|
protected function print_standard_header_and_messages($cm, $course, $quiz,
$options, $currentgroup, $hasquestions, $hasstudents) {
global $OUTPUT;
$this->print_header_and_tabs($cm, $course, $quiz, $this->mode);
if (groups_get_activity_groupmode($cm)) {
// Groups are being used, so output the group selector if we are not downloading.
groups_print_activity_menu($cm, $options->get_url());
}
// Print information on the number of existing attempts.
if ($strattemptnum = quiz_num_attempt_summary($quiz, $cm, true, $currentgroup)) {
echo '<div class="quizattemptcounts">' . $strattemptnum . '</div>';
}
if (!$hasquestions) {
echo quiz_no_questions_message($quiz, $cm, $this->context);
} else if ($currentgroup == self::NO_GROUPS_ALLOWED) {
echo $OUTPUT->notification(get_string('notingroup'));
} else if (!$hasstudents) {
echo $OUTPUT->notification(get_string('nostudentsyet'));
} else if ($currentgroup && !$this->hasgroupstudents) {
echo $OUTPUT->notification(get_string('nostudentsingroup'));
}
}
|
php
|
protected function print_standard_header_and_messages($cm, $course, $quiz,
$options, $currentgroup, $hasquestions, $hasstudents) {
global $OUTPUT;
$this->print_header_and_tabs($cm, $course, $quiz, $this->mode);
if (groups_get_activity_groupmode($cm)) {
// Groups are being used, so output the group selector if we are not downloading.
groups_print_activity_menu($cm, $options->get_url());
}
// Print information on the number of existing attempts.
if ($strattemptnum = quiz_num_attempt_summary($quiz, $cm, true, $currentgroup)) {
echo '<div class="quizattemptcounts">' . $strattemptnum . '</div>';
}
if (!$hasquestions) {
echo quiz_no_questions_message($quiz, $cm, $this->context);
} else if ($currentgroup == self::NO_GROUPS_ALLOWED) {
echo $OUTPUT->notification(get_string('notingroup'));
} else if (!$hasstudents) {
echo $OUTPUT->notification(get_string('nostudentsyet'));
} else if ($currentgroup && !$this->hasgroupstudents) {
echo $OUTPUT->notification(get_string('nostudentsingroup'));
}
}
|
[
"protected",
"function",
"print_standard_header_and_messages",
"(",
"$",
"cm",
",",
"$",
"course",
",",
"$",
"quiz",
",",
"$",
"options",
",",
"$",
"currentgroup",
",",
"$",
"hasquestions",
",",
"$",
"hasstudents",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"$",
"this",
"->",
"print_header_and_tabs",
"(",
"$",
"cm",
",",
"$",
"course",
",",
"$",
"quiz",
",",
"$",
"this",
"->",
"mode",
")",
";",
"if",
"(",
"groups_get_activity_groupmode",
"(",
"$",
"cm",
")",
")",
"{",
"// Groups are being used, so output the group selector if we are not downloading.",
"groups_print_activity_menu",
"(",
"$",
"cm",
",",
"$",
"options",
"->",
"get_url",
"(",
")",
")",
";",
"}",
"// Print information on the number of existing attempts.",
"if",
"(",
"$",
"strattemptnum",
"=",
"quiz_num_attempt_summary",
"(",
"$",
"quiz",
",",
"$",
"cm",
",",
"true",
",",
"$",
"currentgroup",
")",
")",
"{",
"echo",
"'<div class=\"quizattemptcounts\">'",
".",
"$",
"strattemptnum",
".",
"'</div>'",
";",
"}",
"if",
"(",
"!",
"$",
"hasquestions",
")",
"{",
"echo",
"quiz_no_questions_message",
"(",
"$",
"quiz",
",",
"$",
"cm",
",",
"$",
"this",
"->",
"context",
")",
";",
"}",
"else",
"if",
"(",
"$",
"currentgroup",
"==",
"self",
"::",
"NO_GROUPS_ALLOWED",
")",
"{",
"echo",
"$",
"OUTPUT",
"->",
"notification",
"(",
"get_string",
"(",
"'notingroup'",
")",
")",
";",
"}",
"else",
"if",
"(",
"!",
"$",
"hasstudents",
")",
"{",
"echo",
"$",
"OUTPUT",
"->",
"notification",
"(",
"get_string",
"(",
"'nostudentsyet'",
")",
")",
";",
"}",
"else",
"if",
"(",
"$",
"currentgroup",
"&&",
"!",
"$",
"this",
"->",
"hasgroupstudents",
")",
"{",
"echo",
"$",
"OUTPUT",
"->",
"notification",
"(",
"get_string",
"(",
"'nostudentsingroup'",
")",
")",
";",
"}",
"}"
] |
Outputs the things you commonly want at the top of a quiz report.
Calls through to {@link print_header_and_tabs()} and then
outputs the standard group selector, number of attempts summary,
and messages to cover common cases when the report can't be shown.
@param stdClass $cm the course_module information.
@param stdClass $course the course settings.
@param stdClass $quiz the quiz settings.
@param mod_quiz_attempts_report_options $options the current report settings.
@param int $currentgroup the current group.
@param bool $hasquestions whether there are any questions in the quiz.
@param bool $hasstudents whether there are any relevant students.
|
[
"Outputs",
"the",
"things",
"you",
"commonly",
"want",
"at",
"the",
"top",
"of",
"a",
"quiz",
"report",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/attemptsreport.php#L156-L181
|
220,321
|
moodle/moodle
|
mod/quiz/report/attemptsreport.php
|
quiz_attempts_report.configure_user_columns
|
protected function configure_user_columns($table) {
$table->column_suppress('picture');
$table->column_suppress('fullname');
$extrafields = get_extra_user_fields($this->context);
foreach ($extrafields as $field) {
$table->column_suppress($field);
}
$table->column_class('picture', 'picture');
$table->column_class('lastname', 'bold');
$table->column_class('firstname', 'bold');
$table->column_class('fullname', 'bold');
}
|
php
|
protected function configure_user_columns($table) {
$table->column_suppress('picture');
$table->column_suppress('fullname');
$extrafields = get_extra_user_fields($this->context);
foreach ($extrafields as $field) {
$table->column_suppress($field);
}
$table->column_class('picture', 'picture');
$table->column_class('lastname', 'bold');
$table->column_class('firstname', 'bold');
$table->column_class('fullname', 'bold');
}
|
[
"protected",
"function",
"configure_user_columns",
"(",
"$",
"table",
")",
"{",
"$",
"table",
"->",
"column_suppress",
"(",
"'picture'",
")",
";",
"$",
"table",
"->",
"column_suppress",
"(",
"'fullname'",
")",
";",
"$",
"extrafields",
"=",
"get_extra_user_fields",
"(",
"$",
"this",
"->",
"context",
")",
";",
"foreach",
"(",
"$",
"extrafields",
"as",
"$",
"field",
")",
"{",
"$",
"table",
"->",
"column_suppress",
"(",
"$",
"field",
")",
";",
"}",
"$",
"table",
"->",
"column_class",
"(",
"'picture'",
",",
"'picture'",
")",
";",
"$",
"table",
"->",
"column_class",
"(",
"'lastname'",
",",
"'bold'",
")",
";",
"$",
"table",
"->",
"column_class",
"(",
"'firstname'",
",",
"'bold'",
")",
";",
"$",
"table",
"->",
"column_class",
"(",
"'fullname'",
",",
"'bold'",
")",
";",
"}"
] |
Set the display options for the user-related columns in the table.
@param table_sql $table the table being constructed.
|
[
"Set",
"the",
"display",
"options",
"for",
"the",
"user",
"-",
"related",
"columns",
"in",
"the",
"table",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/attemptsreport.php#L216-L228
|
220,322
|
moodle/moodle
|
mod/quiz/report/attemptsreport.php
|
quiz_attempts_report.set_up_table_columns
|
protected function set_up_table_columns($table, $columns, $headers, $reporturl,
mod_quiz_attempts_report_options $options, $collapsible) {
$table->define_columns($columns);
$table->define_headers($headers);
$table->sortable(true, 'uniqueid');
$table->define_baseurl($options->get_url());
$this->configure_user_columns($table);
$table->no_sorting('feedbacktext');
$table->column_class('sumgrades', 'bold');
$table->set_attribute('id', 'attempts');
$table->collapsible($collapsible);
}
|
php
|
protected function set_up_table_columns($table, $columns, $headers, $reporturl,
mod_quiz_attempts_report_options $options, $collapsible) {
$table->define_columns($columns);
$table->define_headers($headers);
$table->sortable(true, 'uniqueid');
$table->define_baseurl($options->get_url());
$this->configure_user_columns($table);
$table->no_sorting('feedbacktext');
$table->column_class('sumgrades', 'bold');
$table->set_attribute('id', 'attempts');
$table->collapsible($collapsible);
}
|
[
"protected",
"function",
"set_up_table_columns",
"(",
"$",
"table",
",",
"$",
"columns",
",",
"$",
"headers",
",",
"$",
"reporturl",
",",
"mod_quiz_attempts_report_options",
"$",
"options",
",",
"$",
"collapsible",
")",
"{",
"$",
"table",
"->",
"define_columns",
"(",
"$",
"columns",
")",
";",
"$",
"table",
"->",
"define_headers",
"(",
"$",
"headers",
")",
";",
"$",
"table",
"->",
"sortable",
"(",
"true",
",",
"'uniqueid'",
")",
";",
"$",
"table",
"->",
"define_baseurl",
"(",
"$",
"options",
"->",
"get_url",
"(",
")",
")",
";",
"$",
"this",
"->",
"configure_user_columns",
"(",
"$",
"table",
")",
";",
"$",
"table",
"->",
"no_sorting",
"(",
"'feedbacktext'",
")",
";",
"$",
"table",
"->",
"column_class",
"(",
"'sumgrades'",
",",
"'bold'",
")",
";",
"$",
"table",
"->",
"set_attribute",
"(",
"'id'",
",",
"'attempts'",
")",
";",
"$",
"table",
"->",
"collapsible",
"(",
"$",
"collapsible",
")",
";",
"}"
] |
Set up the table.
@param table_sql $table the table being constructed.
@param array $columns the list of columns.
@param array $headers the columns headings.
@param moodle_url $reporturl the URL of this report.
@param mod_quiz_attempts_report_options $options the display options.
@param bool $collapsible whether to allow columns in the report to be collapsed.
|
[
"Set",
"up",
"the",
"table",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/attemptsreport.php#L287-L303
|
220,323
|
moodle/moodle
|
mod/quiz/report/attemptsreport.php
|
quiz_attempts_report.process_actions
|
protected function process_actions($quiz, $cm, $currentgroup, \core\dml\sql_join $groupstudentsjoins,
\core\dml\sql_join $allowedjoins, $redirecturl) {
if (empty($currentgroup) || $this->hasgroupstudents) {
if (optional_param('delete', 0, PARAM_BOOL) && confirm_sesskey()) {
if ($attemptids = optional_param_array('attemptid', array(), PARAM_INT)) {
require_capability('mod/quiz:deleteattempts', $this->context);
$this->delete_selected_attempts($quiz, $cm, $attemptids, $allowedjoins);
redirect($redirecturl);
}
}
}
}
|
php
|
protected function process_actions($quiz, $cm, $currentgroup, \core\dml\sql_join $groupstudentsjoins,
\core\dml\sql_join $allowedjoins, $redirecturl) {
if (empty($currentgroup) || $this->hasgroupstudents) {
if (optional_param('delete', 0, PARAM_BOOL) && confirm_sesskey()) {
if ($attemptids = optional_param_array('attemptid', array(), PARAM_INT)) {
require_capability('mod/quiz:deleteattempts', $this->context);
$this->delete_selected_attempts($quiz, $cm, $attemptids, $allowedjoins);
redirect($redirecturl);
}
}
}
}
|
[
"protected",
"function",
"process_actions",
"(",
"$",
"quiz",
",",
"$",
"cm",
",",
"$",
"currentgroup",
",",
"\\",
"core",
"\\",
"dml",
"\\",
"sql_join",
"$",
"groupstudentsjoins",
",",
"\\",
"core",
"\\",
"dml",
"\\",
"sql_join",
"$",
"allowedjoins",
",",
"$",
"redirecturl",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"currentgroup",
")",
"||",
"$",
"this",
"->",
"hasgroupstudents",
")",
"{",
"if",
"(",
"optional_param",
"(",
"'delete'",
",",
"0",
",",
"PARAM_BOOL",
")",
"&&",
"confirm_sesskey",
"(",
")",
")",
"{",
"if",
"(",
"$",
"attemptids",
"=",
"optional_param_array",
"(",
"'attemptid'",
",",
"array",
"(",
")",
",",
"PARAM_INT",
")",
")",
"{",
"require_capability",
"(",
"'mod/quiz:deleteattempts'",
",",
"$",
"this",
"->",
"context",
")",
";",
"$",
"this",
"->",
"delete_selected_attempts",
"(",
"$",
"quiz",
",",
"$",
"cm",
",",
"$",
"attemptids",
",",
"$",
"allowedjoins",
")",
";",
"redirect",
"(",
"$",
"redirecturl",
")",
";",
"}",
"}",
"}",
"}"
] |
Process any submitted actions.
@param object $quiz the quiz settings.
@param object $cm the cm object for the quiz.
@param int $currentgroup the currently selected group.
@param \core\dml\sql_join $groupstudentsjoins (joins, wheres, params) the students in the current group.
@param \core\dml\sql_join $allowedjoins (joins, wheres, params) the users whose attempt this user is allowed to modify.
@param moodle_url $redirecturl where to redircet to after a successful action.
|
[
"Process",
"any",
"submitted",
"actions",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/attemptsreport.php#L314-L325
|
220,324
|
moodle/moodle
|
mod/quiz/report/attemptsreport.php
|
quiz_attempts_report.delete_selected_attempts
|
protected function delete_selected_attempts($quiz, $cm, $attemptids, \core\dml\sql_join $allowedjoins) {
global $DB;
foreach ($attemptids as $attemptid) {
if (empty($allowedjoins->joins)) {
$sql = "SELECT quiza.*
FROM {quiz_attempts} quiza
JOIN {user} u ON u.id = quiza.userid
WHERE quiza.id = :attemptid";
} else {
$sql = "SELECT quiza.*
FROM {quiz_attempts} quiza
JOIN {user} u ON u.id = quiza.userid
{$allowedjoins->joins}
WHERE {$allowedjoins->wheres} AND quiza.id = :attemptid";
}
$params = $allowedjoins->params + array('attemptid' => $attemptid);
$attempt = $DB->get_record_sql($sql, $params);
if (!$attempt || $attempt->quiz != $quiz->id || $attempt->preview != 0) {
// Ensure the attempt exists, belongs to this quiz and belongs to
// a student included in the report. If not skip.
continue;
}
// Set the course module id before calling quiz_delete_attempt().
$quiz->cmid = $cm->id;
quiz_delete_attempt($attempt, $quiz);
}
}
|
php
|
protected function delete_selected_attempts($quiz, $cm, $attemptids, \core\dml\sql_join $allowedjoins) {
global $DB;
foreach ($attemptids as $attemptid) {
if (empty($allowedjoins->joins)) {
$sql = "SELECT quiza.*
FROM {quiz_attempts} quiza
JOIN {user} u ON u.id = quiza.userid
WHERE quiza.id = :attemptid";
} else {
$sql = "SELECT quiza.*
FROM {quiz_attempts} quiza
JOIN {user} u ON u.id = quiza.userid
{$allowedjoins->joins}
WHERE {$allowedjoins->wheres} AND quiza.id = :attemptid";
}
$params = $allowedjoins->params + array('attemptid' => $attemptid);
$attempt = $DB->get_record_sql($sql, $params);
if (!$attempt || $attempt->quiz != $quiz->id || $attempt->preview != 0) {
// Ensure the attempt exists, belongs to this quiz and belongs to
// a student included in the report. If not skip.
continue;
}
// Set the course module id before calling quiz_delete_attempt().
$quiz->cmid = $cm->id;
quiz_delete_attempt($attempt, $quiz);
}
}
|
[
"protected",
"function",
"delete_selected_attempts",
"(",
"$",
"quiz",
",",
"$",
"cm",
",",
"$",
"attemptids",
",",
"\\",
"core",
"\\",
"dml",
"\\",
"sql_join",
"$",
"allowedjoins",
")",
"{",
"global",
"$",
"DB",
";",
"foreach",
"(",
"$",
"attemptids",
"as",
"$",
"attemptid",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"allowedjoins",
"->",
"joins",
")",
")",
"{",
"$",
"sql",
"=",
"\"SELECT quiza.*\n FROM {quiz_attempts} quiza\n JOIN {user} u ON u.id = quiza.userid\n WHERE quiza.id = :attemptid\"",
";",
"}",
"else",
"{",
"$",
"sql",
"=",
"\"SELECT quiza.*\n FROM {quiz_attempts} quiza\n JOIN {user} u ON u.id = quiza.userid\n {$allowedjoins->joins}\n WHERE {$allowedjoins->wheres} AND quiza.id = :attemptid\"",
";",
"}",
"$",
"params",
"=",
"$",
"allowedjoins",
"->",
"params",
"+",
"array",
"(",
"'attemptid'",
"=>",
"$",
"attemptid",
")",
";",
"$",
"attempt",
"=",
"$",
"DB",
"->",
"get_record_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"if",
"(",
"!",
"$",
"attempt",
"||",
"$",
"attempt",
"->",
"quiz",
"!=",
"$",
"quiz",
"->",
"id",
"||",
"$",
"attempt",
"->",
"preview",
"!=",
"0",
")",
"{",
"// Ensure the attempt exists, belongs to this quiz and belongs to",
"// a student included in the report. If not skip.",
"continue",
";",
"}",
"// Set the course module id before calling quiz_delete_attempt().",
"$",
"quiz",
"->",
"cmid",
"=",
"$",
"cm",
"->",
"id",
";",
"quiz_delete_attempt",
"(",
"$",
"attempt",
",",
"$",
"quiz",
")",
";",
"}",
"}"
] |
Delete the quiz attempts
@param object $quiz the quiz settings. Attempts that don't belong to
this quiz are not deleted.
@param object $cm the course_module object.
@param array $attemptids the list of attempt ids to delete.
@param \core\dml\sql_join $allowedjoins (joins, wheres, params) This list of userids that are visible in the report.
Users can only delete attempts that they are allowed to see in the report.
Empty means all users.
|
[
"Delete",
"the",
"quiz",
"attempts"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/attemptsreport.php#L337-L365
|
220,325
|
moodle/moodle
|
admin/classes/task_log_table.php
|
task_log_table.col_classname
|
public function col_classname($row) : string {
$output = '';
if (class_exists($row->classname)) {
$task = new $row->classname;
if ($task instanceof \core\task\scheduled_task) {
$output = $task->get_name();
}
}
$output .= \html_writer::tag('div', "\\{$row->classname}", [
'class' => 'task-class',
]);
return $output;
}
|
php
|
public function col_classname($row) : string {
$output = '';
if (class_exists($row->classname)) {
$task = new $row->classname;
if ($task instanceof \core\task\scheduled_task) {
$output = $task->get_name();
}
}
$output .= \html_writer::tag('div', "\\{$row->classname}", [
'class' => 'task-class',
]);
return $output;
}
|
[
"public",
"function",
"col_classname",
"(",
"$",
"row",
")",
":",
"string",
"{",
"$",
"output",
"=",
"''",
";",
"if",
"(",
"class_exists",
"(",
"$",
"row",
"->",
"classname",
")",
")",
"{",
"$",
"task",
"=",
"new",
"$",
"row",
"->",
"classname",
";",
"if",
"(",
"$",
"task",
"instanceof",
"\\",
"core",
"\\",
"task",
"\\",
"scheduled_task",
")",
"{",
"$",
"output",
"=",
"$",
"task",
"->",
"get_name",
"(",
")",
";",
"}",
"}",
"$",
"output",
".=",
"\\",
"html_writer",
"::",
"tag",
"(",
"'div'",
",",
"\"\\\\{$row->classname}\"",
",",
"[",
"'class'",
"=>",
"'task-class'",
",",
"]",
")",
";",
"return",
"$",
"output",
";",
"}"
] |
Format the name cell.
@param \stdClass $row
@return string
|
[
"Format",
"the",
"name",
"cell",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/classes/task_log_table.php#L157-L170
|
220,326
|
moodle/moodle
|
admin/classes/task_log_table.php
|
task_log_table.col_type
|
public function col_type($row) : string {
if (\core\task\database_logger::TYPE_SCHEDULED == $row->type) {
return get_string('task_type:scheduled', 'admin');
} else {
return get_string('task_type:adhoc', 'admin');
}
}
|
php
|
public function col_type($row) : string {
if (\core\task\database_logger::TYPE_SCHEDULED == $row->type) {
return get_string('task_type:scheduled', 'admin');
} else {
return get_string('task_type:adhoc', 'admin');
}
}
|
[
"public",
"function",
"col_type",
"(",
"$",
"row",
")",
":",
"string",
"{",
"if",
"(",
"\\",
"core",
"\\",
"task",
"\\",
"database_logger",
"::",
"TYPE_SCHEDULED",
"==",
"$",
"row",
"->",
"type",
")",
"{",
"return",
"get_string",
"(",
"'task_type:scheduled'",
",",
"'admin'",
")",
";",
"}",
"else",
"{",
"return",
"get_string",
"(",
"'task_type:adhoc'",
",",
"'admin'",
")",
";",
"}",
"}"
] |
Format the type cell.
@param \stdClass $row
@return string
|
[
"Format",
"the",
"type",
"cell",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/classes/task_log_table.php#L178-L184
|
220,327
|
moodle/moodle
|
admin/classes/task_log_table.php
|
task_log_table.col_duration
|
public function col_duration($row) : string {
$duration = round($row->timeend - $row->timestart, 2);
if (empty($duration)) {
// The format_time function returns 'now' when the difference is exactly 0.
// Note: format_time performs concatenation in exactly this fashion so we should do this for consistency.
return '0 ' . get_string('secs', 'moodle');
}
return format_time($duration);
}
|
php
|
public function col_duration($row) : string {
$duration = round($row->timeend - $row->timestart, 2);
if (empty($duration)) {
// The format_time function returns 'now' when the difference is exactly 0.
// Note: format_time performs concatenation in exactly this fashion so we should do this for consistency.
return '0 ' . get_string('secs', 'moodle');
}
return format_time($duration);
}
|
[
"public",
"function",
"col_duration",
"(",
"$",
"row",
")",
":",
"string",
"{",
"$",
"duration",
"=",
"round",
"(",
"$",
"row",
"->",
"timeend",
"-",
"$",
"row",
"->",
"timestart",
",",
"2",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"duration",
")",
")",
"{",
"// The format_time function returns 'now' when the difference is exactly 0.",
"// Note: format_time performs concatenation in exactly this fashion so we should do this for consistency.",
"return",
"'0 '",
".",
"get_string",
"(",
"'secs'",
",",
"'moodle'",
")",
";",
"}",
"return",
"format_time",
"(",
"$",
"duration",
")",
";",
"}"
] |
Format the duration cell.
@param \stdClass $row
@return string
|
[
"Format",
"the",
"duration",
"cell",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/classes/task_log_table.php#L216-L226
|
220,328
|
moodle/moodle
|
admin/classes/task_log_table.php
|
task_log_table.col_db
|
public function col_db($row) : string {
$output = '';
$output .= \html_writer::div(get_string('task_stats:dbreads', 'admin', $row->dbreads));
$output .= \html_writer::div(get_string('task_stats:dbwrites', 'admin', $row->dbwrites));
return $output;
}
|
php
|
public function col_db($row) : string {
$output = '';
$output .= \html_writer::div(get_string('task_stats:dbreads', 'admin', $row->dbreads));
$output .= \html_writer::div(get_string('task_stats:dbwrites', 'admin', $row->dbwrites));
return $output;
}
|
[
"public",
"function",
"col_db",
"(",
"$",
"row",
")",
":",
"string",
"{",
"$",
"output",
"=",
"''",
";",
"$",
"output",
".=",
"\\",
"html_writer",
"::",
"div",
"(",
"get_string",
"(",
"'task_stats:dbreads'",
",",
"'admin'",
",",
"$",
"row",
"->",
"dbreads",
")",
")",
";",
"$",
"output",
".=",
"\\",
"html_writer",
"::",
"div",
"(",
"get_string",
"(",
"'task_stats:dbwrites'",
",",
"'admin'",
",",
"$",
"row",
"->",
"dbwrites",
")",
")",
";",
"return",
"$",
"output",
";",
"}"
] |
Format the DB details cell.
@param \stdClass $row
@return string
|
[
"Format",
"the",
"DB",
"details",
"cell",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/classes/task_log_table.php#L234-L241
|
220,329
|
moodle/moodle
|
admin/classes/task_log_table.php
|
task_log_table.col_actions
|
public function col_actions($row) : string {
global $OUTPUT;
$actions = [];
$url = new \moodle_url('/admin/tasklogs.php', ['logid' => $row->id]);
// Quick view.
$actions[] = $OUTPUT->action_icon(
$url,
new \pix_icon('e/search', get_string('view')),
new \popup_action('click', $url)
);
// Download.
$actions[] = $OUTPUT->action_icon(
new \moodle_url($url, ['download' => true]),
new \pix_icon('t/download', get_string('download'))
);
return implode(' ', $actions);
}
|
php
|
public function col_actions($row) : string {
global $OUTPUT;
$actions = [];
$url = new \moodle_url('/admin/tasklogs.php', ['logid' => $row->id]);
// Quick view.
$actions[] = $OUTPUT->action_icon(
$url,
new \pix_icon('e/search', get_string('view')),
new \popup_action('click', $url)
);
// Download.
$actions[] = $OUTPUT->action_icon(
new \moodle_url($url, ['download' => true]),
new \pix_icon('t/download', get_string('download'))
);
return implode(' ', $actions);
}
|
[
"public",
"function",
"col_actions",
"(",
"$",
"row",
")",
":",
"string",
"{",
"global",
"$",
"OUTPUT",
";",
"$",
"actions",
"=",
"[",
"]",
";",
"$",
"url",
"=",
"new",
"\\",
"moodle_url",
"(",
"'/admin/tasklogs.php'",
",",
"[",
"'logid'",
"=>",
"$",
"row",
"->",
"id",
"]",
")",
";",
"// Quick view.",
"$",
"actions",
"[",
"]",
"=",
"$",
"OUTPUT",
"->",
"action_icon",
"(",
"$",
"url",
",",
"new",
"\\",
"pix_icon",
"(",
"'e/search'",
",",
"get_string",
"(",
"'view'",
")",
")",
",",
"new",
"\\",
"popup_action",
"(",
"'click'",
",",
"$",
"url",
")",
")",
";",
"// Download.",
"$",
"actions",
"[",
"]",
"=",
"$",
"OUTPUT",
"->",
"action_icon",
"(",
"new",
"\\",
"moodle_url",
"(",
"$",
"url",
",",
"[",
"'download'",
"=>",
"true",
"]",
")",
",",
"new",
"\\",
"pix_icon",
"(",
"'t/download'",
",",
"get_string",
"(",
"'download'",
")",
")",
")",
";",
"return",
"implode",
"(",
"' '",
",",
"$",
"actions",
")",
";",
"}"
] |
Format the actions cell.
@param \stdClass $row
@return string
|
[
"Format",
"the",
"actions",
"cell",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/classes/task_log_table.php#L249-L270
|
220,330
|
moodle/moodle
|
admin/classes/task_log_table.php
|
task_log_table.col_userid
|
public function col_userid($row) : string {
if (empty($row->userid)) {
return '';
}
$user = (object) [];
username_load_fields_from_object($user, $row, 'user');
return fullname($user);
}
|
php
|
public function col_userid($row) : string {
if (empty($row->userid)) {
return '';
}
$user = (object) [];
username_load_fields_from_object($user, $row, 'user');
return fullname($user);
}
|
[
"public",
"function",
"col_userid",
"(",
"$",
"row",
")",
":",
"string",
"{",
"if",
"(",
"empty",
"(",
"$",
"row",
"->",
"userid",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"user",
"=",
"(",
"object",
")",
"[",
"]",
";",
"username_load_fields_from_object",
"(",
"$",
"user",
",",
"$",
"row",
",",
"'user'",
")",
";",
"return",
"fullname",
"(",
"$",
"user",
")",
";",
"}"
] |
Format the user cell.
@param \stdClass $row
@return string
|
[
"Format",
"the",
"user",
"cell",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/classes/task_log_table.php#L278-L287
|
220,331
|
moodle/moodle
|
question/type/ddimageortext/edit_ddtoimage_form_base.php
|
qtype_ddtoimage_edit_form_base.definition_drop_zones
|
protected function definition_drop_zones($mform, $imagerepeats) {
$mform->addElement('header', 'dropzoneheader', get_string('dropzoneheader', 'qtype_'.$this->qtype()));
$countdropzones = 0;
if (isset($this->question->id)) {
foreach ($this->question->options->drops as $drop) {
$countdropzones = max($countdropzones, $drop->no);
}
}
if (!$countdropzones) {
$countdropzones = self::START_NUM_ITEMS;
}
$dropzonerepeatsatstart = $countdropzones;
$this->repeat_elements($this->drop_zone($mform, $imagerepeats), $dropzonerepeatsatstart,
$this->drop_zones_repeated_options(),
'nodropzone', 'adddropzone', self::ADD_NUM_ITEMS,
get_string('addmoredropzones', 'qtype_ddimageortext'), true);
}
|
php
|
protected function definition_drop_zones($mform, $imagerepeats) {
$mform->addElement('header', 'dropzoneheader', get_string('dropzoneheader', 'qtype_'.$this->qtype()));
$countdropzones = 0;
if (isset($this->question->id)) {
foreach ($this->question->options->drops as $drop) {
$countdropzones = max($countdropzones, $drop->no);
}
}
if (!$countdropzones) {
$countdropzones = self::START_NUM_ITEMS;
}
$dropzonerepeatsatstart = $countdropzones;
$this->repeat_elements($this->drop_zone($mform, $imagerepeats), $dropzonerepeatsatstart,
$this->drop_zones_repeated_options(),
'nodropzone', 'adddropzone', self::ADD_NUM_ITEMS,
get_string('addmoredropzones', 'qtype_ddimageortext'), true);
}
|
[
"protected",
"function",
"definition_drop_zones",
"(",
"$",
"mform",
",",
"$",
"imagerepeats",
")",
"{",
"$",
"mform",
"->",
"addElement",
"(",
"'header'",
",",
"'dropzoneheader'",
",",
"get_string",
"(",
"'dropzoneheader'",
",",
"'qtype_'",
".",
"$",
"this",
"->",
"qtype",
"(",
")",
")",
")",
";",
"$",
"countdropzones",
"=",
"0",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"question",
"->",
"id",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"question",
"->",
"options",
"->",
"drops",
"as",
"$",
"drop",
")",
"{",
"$",
"countdropzones",
"=",
"max",
"(",
"$",
"countdropzones",
",",
"$",
"drop",
"->",
"no",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"countdropzones",
")",
"{",
"$",
"countdropzones",
"=",
"self",
"::",
"START_NUM_ITEMS",
";",
"}",
"$",
"dropzonerepeatsatstart",
"=",
"$",
"countdropzones",
";",
"$",
"this",
"->",
"repeat_elements",
"(",
"$",
"this",
"->",
"drop_zone",
"(",
"$",
"mform",
",",
"$",
"imagerepeats",
")",
",",
"$",
"dropzonerepeatsatstart",
",",
"$",
"this",
"->",
"drop_zones_repeated_options",
"(",
")",
",",
"'nodropzone'",
",",
"'adddropzone'",
",",
"self",
"::",
"ADD_NUM_ITEMS",
",",
"get_string",
"(",
"'addmoredropzones'",
",",
"'qtype_ddimageortext'",
")",
",",
"true",
")",
";",
"}"
] |
Make and add drop zones to the form.
@param object $mform The Moodle form object.
@param int $imagerepeats The initial number of repeat elements.
|
[
"Make",
"and",
"add",
"drop",
"zones",
"to",
"the",
"form",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/ddimageortext/edit_ddtoimage_form_base.php#L97-L116
|
220,332
|
moodle/moodle
|
question/type/ddimageortext/edit_ddtoimage_form_base.php
|
qtype_ddtoimage_edit_form_base.get_drag_item_repeats
|
protected function get_drag_item_repeats() {
$countimages = 0;
if (isset($this->question->id)) {
foreach ($this->question->options->drags as $drag) {
$countimages = max($countimages, $drag->no);
}
}
if (!$countimages) {
$countimages = self::START_NUM_ITEMS;
}
$itemrepeatsatstart = $countimages;
$imagerepeats = optional_param('noitems', $itemrepeatsatstart, PARAM_INT);
$addfields = optional_param('additems', false, PARAM_BOOL);
if ($addfields) {
$imagerepeats += self::ADD_NUM_ITEMS;
}
return array($itemrepeatsatstart, $imagerepeats);
}
|
php
|
protected function get_drag_item_repeats() {
$countimages = 0;
if (isset($this->question->id)) {
foreach ($this->question->options->drags as $drag) {
$countimages = max($countimages, $drag->no);
}
}
if (!$countimages) {
$countimages = self::START_NUM_ITEMS;
}
$itemrepeatsatstart = $countimages;
$imagerepeats = optional_param('noitems', $itemrepeatsatstart, PARAM_INT);
$addfields = optional_param('additems', false, PARAM_BOOL);
if ($addfields) {
$imagerepeats += self::ADD_NUM_ITEMS;
}
return array($itemrepeatsatstart, $imagerepeats);
}
|
[
"protected",
"function",
"get_drag_item_repeats",
"(",
")",
"{",
"$",
"countimages",
"=",
"0",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"question",
"->",
"id",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"question",
"->",
"options",
"->",
"drags",
"as",
"$",
"drag",
")",
"{",
"$",
"countimages",
"=",
"max",
"(",
"$",
"countimages",
",",
"$",
"drag",
"->",
"no",
")",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"countimages",
")",
"{",
"$",
"countimages",
"=",
"self",
"::",
"START_NUM_ITEMS",
";",
"}",
"$",
"itemrepeatsatstart",
"=",
"$",
"countimages",
";",
"$",
"imagerepeats",
"=",
"optional_param",
"(",
"'noitems'",
",",
"$",
"itemrepeatsatstart",
",",
"PARAM_INT",
")",
";",
"$",
"addfields",
"=",
"optional_param",
"(",
"'additems'",
",",
"false",
",",
"PARAM_BOOL",
")",
";",
"if",
"(",
"$",
"addfields",
")",
"{",
"$",
"imagerepeats",
"+=",
"self",
"::",
"ADD_NUM_ITEMS",
";",
"}",
"return",
"array",
"(",
"$",
"itemrepeatsatstart",
",",
"$",
"imagerepeats",
")",
";",
"}"
] |
Returns an array of starting number of repeats, and the total number of repeats.
@return array
|
[
"Returns",
"an",
"array",
"of",
"starting",
"number",
"of",
"repeats",
"and",
"the",
"total",
"number",
"of",
"repeats",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/ddimageortext/edit_ddtoimage_form_base.php#L162-L181
|
220,333
|
moodle/moodle
|
question/type/ddimageortext/edit_ddtoimage_form_base.php
|
qtype_ddtoimage_edit_form_base.file_uploaded
|
public static function file_uploaded($draftitemid) {
$draftareafiles = file_get_drafarea_files($draftitemid);
do {
$draftareafile = array_shift($draftareafiles->list);
} while ($draftareafile !== null && $draftareafile->filename == '.');
if ($draftareafile === null) {
return false;
}
return true;
}
|
php
|
public static function file_uploaded($draftitemid) {
$draftareafiles = file_get_drafarea_files($draftitemid);
do {
$draftareafile = array_shift($draftareafiles->list);
} while ($draftareafile !== null && $draftareafile->filename == '.');
if ($draftareafile === null) {
return false;
}
return true;
}
|
[
"public",
"static",
"function",
"file_uploaded",
"(",
"$",
"draftitemid",
")",
"{",
"$",
"draftareafiles",
"=",
"file_get_drafarea_files",
"(",
"$",
"draftitemid",
")",
";",
"do",
"{",
"$",
"draftareafile",
"=",
"array_shift",
"(",
"$",
"draftareafiles",
"->",
"list",
")",
";",
"}",
"while",
"(",
"$",
"draftareafile",
"!==",
"null",
"&&",
"$",
"draftareafile",
"->",
"filename",
"==",
"'.'",
")",
";",
"if",
"(",
"$",
"draftareafile",
"===",
"null",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Checks to see if a file has been uploaded.
@param string $draftitemid The draft id
@return bool True if files exist, false if not.
|
[
"Checks",
"to",
"see",
"if",
"a",
"file",
"has",
"been",
"uploaded",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/ddimageortext/edit_ddtoimage_form_base.php#L194-L203
|
220,334
|
moodle/moodle
|
course/classes/privacy/provider.php
|
provider.export_context_data
|
public static function export_context_data(\core_privacy\local\request\contextlist_collection $contextlistcollection) {
global $DB;
$coursecontextids = $DB->get_records_menu('context', ['contextlevel' => CONTEXT_COURSE], '', 'id, instanceid');
$courseids = [];
foreach ($contextlistcollection as $component) {
foreach ($component->get_contexts() as $context) {
// All course contexts have been accounted for, so skip all checks.
if (empty($coursecontextids)) {
break;
}
// Only course, module, and block contexts are checked.
if (in_array($context->contextlevel, [CONTEXT_USER, CONTEXT_SYSTEM, CONTEXT_COURSECAT])) {
continue;
}
// If the context is a course, then we just add it without the need to check context path.
if ($context->contextlevel == CONTEXT_COURSE) {
$courseids[$context->id] = $context->instanceid;
unset($coursecontextids[$context->id]);
continue;
}
// Otherwise, we need to check all the course context paths, to see if this context is a descendant.
foreach ($coursecontextids as $contextid => $instanceid) {
if (stripos($context->path, '/' . $contextid . '/') !== false) {
$courseids[$contextid] = $instanceid;
unset($coursecontextids[$contextid]);
}
}
}
}
if (empty($courseids)) {
return;
}
// Export general data for these contexts.
list($sql, $params) = $DB->get_in_or_equal($courseids);
$sql = 'id ' . $sql;
$coursedata = $DB->get_records_select('course', $sql, $params);
foreach ($coursedata as $course) {
$context = \context_course::instance($course->id);
$courseformat = $course->format !== 'site' ? get_string('pluginname', 'format_' . $course->format) : get_string('site');
$data = (object) [
'fullname' => $course->fullname,
'shortname' => $course->shortname,
'idnumber' => $course->idnumber,
'summary' => writer::with_context($context)->rewrite_pluginfile_urls([], 'course', 'summary', 0,
format_string($course->summary)),
'format' => $courseformat,
'startdate' => transform::datetime($course->startdate),
'enddate' => transform::datetime($course->enddate)
];
writer::with_context($context)
->export_area_files([], 'course', 'summary', 0)
->export_area_files([], 'course', 'overviewfiles', 0)
->export_data([], $data);
}
}
|
php
|
public static function export_context_data(\core_privacy\local\request\contextlist_collection $contextlistcollection) {
global $DB;
$coursecontextids = $DB->get_records_menu('context', ['contextlevel' => CONTEXT_COURSE], '', 'id, instanceid');
$courseids = [];
foreach ($contextlistcollection as $component) {
foreach ($component->get_contexts() as $context) {
// All course contexts have been accounted for, so skip all checks.
if (empty($coursecontextids)) {
break;
}
// Only course, module, and block contexts are checked.
if (in_array($context->contextlevel, [CONTEXT_USER, CONTEXT_SYSTEM, CONTEXT_COURSECAT])) {
continue;
}
// If the context is a course, then we just add it without the need to check context path.
if ($context->contextlevel == CONTEXT_COURSE) {
$courseids[$context->id] = $context->instanceid;
unset($coursecontextids[$context->id]);
continue;
}
// Otherwise, we need to check all the course context paths, to see if this context is a descendant.
foreach ($coursecontextids as $contextid => $instanceid) {
if (stripos($context->path, '/' . $contextid . '/') !== false) {
$courseids[$contextid] = $instanceid;
unset($coursecontextids[$contextid]);
}
}
}
}
if (empty($courseids)) {
return;
}
// Export general data for these contexts.
list($sql, $params) = $DB->get_in_or_equal($courseids);
$sql = 'id ' . $sql;
$coursedata = $DB->get_records_select('course', $sql, $params);
foreach ($coursedata as $course) {
$context = \context_course::instance($course->id);
$courseformat = $course->format !== 'site' ? get_string('pluginname', 'format_' . $course->format) : get_string('site');
$data = (object) [
'fullname' => $course->fullname,
'shortname' => $course->shortname,
'idnumber' => $course->idnumber,
'summary' => writer::with_context($context)->rewrite_pluginfile_urls([], 'course', 'summary', 0,
format_string($course->summary)),
'format' => $courseformat,
'startdate' => transform::datetime($course->startdate),
'enddate' => transform::datetime($course->enddate)
];
writer::with_context($context)
->export_area_files([], 'course', 'summary', 0)
->export_area_files([], 'course', 'overviewfiles', 0)
->export_data([], $data);
}
}
|
[
"public",
"static",
"function",
"export_context_data",
"(",
"\\",
"core_privacy",
"\\",
"local",
"\\",
"request",
"\\",
"contextlist_collection",
"$",
"contextlistcollection",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"coursecontextids",
"=",
"$",
"DB",
"->",
"get_records_menu",
"(",
"'context'",
",",
"[",
"'contextlevel'",
"=>",
"CONTEXT_COURSE",
"]",
",",
"''",
",",
"'id, instanceid'",
")",
";",
"$",
"courseids",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"contextlistcollection",
"as",
"$",
"component",
")",
"{",
"foreach",
"(",
"$",
"component",
"->",
"get_contexts",
"(",
")",
"as",
"$",
"context",
")",
"{",
"// All course contexts have been accounted for, so skip all checks.",
"if",
"(",
"empty",
"(",
"$",
"coursecontextids",
")",
")",
"{",
"break",
";",
"}",
"// Only course, module, and block contexts are checked.",
"if",
"(",
"in_array",
"(",
"$",
"context",
"->",
"contextlevel",
",",
"[",
"CONTEXT_USER",
",",
"CONTEXT_SYSTEM",
",",
"CONTEXT_COURSECAT",
"]",
")",
")",
"{",
"continue",
";",
"}",
"// If the context is a course, then we just add it without the need to check context path.",
"if",
"(",
"$",
"context",
"->",
"contextlevel",
"==",
"CONTEXT_COURSE",
")",
"{",
"$",
"courseids",
"[",
"$",
"context",
"->",
"id",
"]",
"=",
"$",
"context",
"->",
"instanceid",
";",
"unset",
"(",
"$",
"coursecontextids",
"[",
"$",
"context",
"->",
"id",
"]",
")",
";",
"continue",
";",
"}",
"// Otherwise, we need to check all the course context paths, to see if this context is a descendant.",
"foreach",
"(",
"$",
"coursecontextids",
"as",
"$",
"contextid",
"=>",
"$",
"instanceid",
")",
"{",
"if",
"(",
"stripos",
"(",
"$",
"context",
"->",
"path",
",",
"'/'",
".",
"$",
"contextid",
".",
"'/'",
")",
"!==",
"false",
")",
"{",
"$",
"courseids",
"[",
"$",
"contextid",
"]",
"=",
"$",
"instanceid",
";",
"unset",
"(",
"$",
"coursecontextids",
"[",
"$",
"contextid",
"]",
")",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"courseids",
")",
")",
"{",
"return",
";",
"}",
"// Export general data for these contexts.",
"list",
"(",
"$",
"sql",
",",
"$",
"params",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"courseids",
")",
";",
"$",
"sql",
"=",
"'id '",
".",
"$",
"sql",
";",
"$",
"coursedata",
"=",
"$",
"DB",
"->",
"get_records_select",
"(",
"'course'",
",",
"$",
"sql",
",",
"$",
"params",
")",
";",
"foreach",
"(",
"$",
"coursedata",
"as",
"$",
"course",
")",
"{",
"$",
"context",
"=",
"\\",
"context_course",
"::",
"instance",
"(",
"$",
"course",
"->",
"id",
")",
";",
"$",
"courseformat",
"=",
"$",
"course",
"->",
"format",
"!==",
"'site'",
"?",
"get_string",
"(",
"'pluginname'",
",",
"'format_'",
".",
"$",
"course",
"->",
"format",
")",
":",
"get_string",
"(",
"'site'",
")",
";",
"$",
"data",
"=",
"(",
"object",
")",
"[",
"'fullname'",
"=>",
"$",
"course",
"->",
"fullname",
",",
"'shortname'",
"=>",
"$",
"course",
"->",
"shortname",
",",
"'idnumber'",
"=>",
"$",
"course",
"->",
"idnumber",
",",
"'summary'",
"=>",
"writer",
"::",
"with_context",
"(",
"$",
"context",
")",
"->",
"rewrite_pluginfile_urls",
"(",
"[",
"]",
",",
"'course'",
",",
"'summary'",
",",
"0",
",",
"format_string",
"(",
"$",
"course",
"->",
"summary",
")",
")",
",",
"'format'",
"=>",
"$",
"courseformat",
",",
"'startdate'",
"=>",
"transform",
"::",
"datetime",
"(",
"$",
"course",
"->",
"startdate",
")",
",",
"'enddate'",
"=>",
"transform",
"::",
"datetime",
"(",
"$",
"course",
"->",
"enddate",
")",
"]",
";",
"writer",
"::",
"with_context",
"(",
"$",
"context",
")",
"->",
"export_area_files",
"(",
"[",
"]",
",",
"'course'",
",",
"'summary'",
",",
"0",
")",
"->",
"export_area_files",
"(",
"[",
"]",
",",
"'course'",
",",
"'overviewfiles'",
",",
"0",
")",
"->",
"export_data",
"(",
"[",
"]",
",",
"$",
"data",
")",
";",
"}",
"}"
] |
Give the component a chance to include any contextual information deemed relevant to any child contexts which are
exporting personal data.
By giving the component access to the full list of contexts being exported across all components, it can determine whether a
descendant context is being exported, and decide whether to add relevant contextual information about itself. Having access
to the full list of contexts being exported is what makes this component a context aware provider.
E.g.
If, during the core export process, a course module is included in the contextlist_collection but the course containing the
module is not (perhaps there's no longer a user enrolment), then the course should include general contextual information in
the export so we know basic details about which course the module belongs to. This method allows the course to make that
decision, based on the existence of any decendant module contexts in the collection.
@param \core_privacy\local\request\contextlist_collection $contextlistcollection
|
[
"Give",
"the",
"component",
"a",
"chance",
"to",
"include",
"any",
"contextual",
"information",
"deemed",
"relevant",
"to",
"any",
"child",
"contexts",
"which",
"are",
"exporting",
"personal",
"data",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/privacy/provider.php#L151-L208
|
220,335
|
moodle/moodle
|
user/profile/definelib.php
|
profile_define_base.define_form
|
public function define_form(&$form) {
$form->addElement('header', '_commonsettings', get_string('profilecommonsettings', 'admin'));
$this->define_form_common($form);
$form->addElement('header', '_specificsettings', get_string('profilespecificsettings', 'admin'));
$this->define_form_specific($form);
}
|
php
|
public function define_form(&$form) {
$form->addElement('header', '_commonsettings', get_string('profilecommonsettings', 'admin'));
$this->define_form_common($form);
$form->addElement('header', '_specificsettings', get_string('profilespecificsettings', 'admin'));
$this->define_form_specific($form);
}
|
[
"public",
"function",
"define_form",
"(",
"&",
"$",
"form",
")",
"{",
"$",
"form",
"->",
"addElement",
"(",
"'header'",
",",
"'_commonsettings'",
",",
"get_string",
"(",
"'profilecommonsettings'",
",",
"'admin'",
")",
")",
";",
"$",
"this",
"->",
"define_form_common",
"(",
"$",
"form",
")",
";",
"$",
"form",
"->",
"addElement",
"(",
"'header'",
",",
"'_specificsettings'",
",",
"get_string",
"(",
"'profilespecificsettings'",
",",
"'admin'",
")",
")",
";",
"$",
"this",
"->",
"define_form_specific",
"(",
"$",
"form",
")",
";",
"}"
] |
Prints out the form snippet for creating or editing a profile field
@param moodleform $form instance of the moodleform class
|
[
"Prints",
"out",
"the",
"form",
"snippet",
"for",
"creating",
"or",
"editing",
"a",
"profile",
"field"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/profile/definelib.php#L37-L43
|
220,336
|
moodle/moodle
|
user/profile/definelib.php
|
profile_define_base.define_form_common
|
public function define_form_common(&$form) {
$strrequired = get_string('required');
// Accepted values for 'shortname' would follow [a-zA-Z0-9_] pattern,
// but we are accepting any PARAM_TEXT value here,
// and checking [a-zA-Z0-9_] pattern in define_validate_common() function to throw an error when needed.
$form->addElement('text', 'shortname', get_string('profileshortname', 'admin'), 'maxlength="100" size="25"');
$form->addRule('shortname', $strrequired, 'required', null, 'client');
$form->setType('shortname', PARAM_TEXT);
$form->addElement('text', 'name', get_string('profilename', 'admin'), 'size="50"');
$form->addRule('name', $strrequired, 'required', null, 'client');
$form->setType('name', PARAM_TEXT);
$form->addElement('editor', 'description', get_string('profiledescription', 'admin'), null, null);
$form->addElement('selectyesno', 'required', get_string('profilerequired', 'admin'));
$form->addElement('selectyesno', 'locked', get_string('profilelocked', 'admin'));
$form->addElement('selectyesno', 'forceunique', get_string('profileforceunique', 'admin'));
$form->addElement('selectyesno', 'signup', get_string('profilesignup', 'admin'));
$choices = array();
$choices[PROFILE_VISIBLE_NONE] = get_string('profilevisiblenone', 'admin');
$choices[PROFILE_VISIBLE_PRIVATE] = get_string('profilevisibleprivate', 'admin');
$choices[PROFILE_VISIBLE_ALL] = get_string('profilevisibleall', 'admin');
$form->addElement('select', 'visible', get_string('profilevisible', 'admin'), $choices);
$form->addHelpButton('visible', 'profilevisible', 'admin');
$form->setDefault('visible', PROFILE_VISIBLE_ALL);
$choices = profile_list_categories();
$form->addElement('select', 'categoryid', get_string('profilecategory', 'admin'), $choices);
}
|
php
|
public function define_form_common(&$form) {
$strrequired = get_string('required');
// Accepted values for 'shortname' would follow [a-zA-Z0-9_] pattern,
// but we are accepting any PARAM_TEXT value here,
// and checking [a-zA-Z0-9_] pattern in define_validate_common() function to throw an error when needed.
$form->addElement('text', 'shortname', get_string('profileshortname', 'admin'), 'maxlength="100" size="25"');
$form->addRule('shortname', $strrequired, 'required', null, 'client');
$form->setType('shortname', PARAM_TEXT);
$form->addElement('text', 'name', get_string('profilename', 'admin'), 'size="50"');
$form->addRule('name', $strrequired, 'required', null, 'client');
$form->setType('name', PARAM_TEXT);
$form->addElement('editor', 'description', get_string('profiledescription', 'admin'), null, null);
$form->addElement('selectyesno', 'required', get_string('profilerequired', 'admin'));
$form->addElement('selectyesno', 'locked', get_string('profilelocked', 'admin'));
$form->addElement('selectyesno', 'forceunique', get_string('profileforceunique', 'admin'));
$form->addElement('selectyesno', 'signup', get_string('profilesignup', 'admin'));
$choices = array();
$choices[PROFILE_VISIBLE_NONE] = get_string('profilevisiblenone', 'admin');
$choices[PROFILE_VISIBLE_PRIVATE] = get_string('profilevisibleprivate', 'admin');
$choices[PROFILE_VISIBLE_ALL] = get_string('profilevisibleall', 'admin');
$form->addElement('select', 'visible', get_string('profilevisible', 'admin'), $choices);
$form->addHelpButton('visible', 'profilevisible', 'admin');
$form->setDefault('visible', PROFILE_VISIBLE_ALL);
$choices = profile_list_categories();
$form->addElement('select', 'categoryid', get_string('profilecategory', 'admin'), $choices);
}
|
[
"public",
"function",
"define_form_common",
"(",
"&",
"$",
"form",
")",
"{",
"$",
"strrequired",
"=",
"get_string",
"(",
"'required'",
")",
";",
"// Accepted values for 'shortname' would follow [a-zA-Z0-9_] pattern,",
"// but we are accepting any PARAM_TEXT value here,",
"// and checking [a-zA-Z0-9_] pattern in define_validate_common() function to throw an error when needed.",
"$",
"form",
"->",
"addElement",
"(",
"'text'",
",",
"'shortname'",
",",
"get_string",
"(",
"'profileshortname'",
",",
"'admin'",
")",
",",
"'maxlength=\"100\" size=\"25\"'",
")",
";",
"$",
"form",
"->",
"addRule",
"(",
"'shortname'",
",",
"$",
"strrequired",
",",
"'required'",
",",
"null",
",",
"'client'",
")",
";",
"$",
"form",
"->",
"setType",
"(",
"'shortname'",
",",
"PARAM_TEXT",
")",
";",
"$",
"form",
"->",
"addElement",
"(",
"'text'",
",",
"'name'",
",",
"get_string",
"(",
"'profilename'",
",",
"'admin'",
")",
",",
"'size=\"50\"'",
")",
";",
"$",
"form",
"->",
"addRule",
"(",
"'name'",
",",
"$",
"strrequired",
",",
"'required'",
",",
"null",
",",
"'client'",
")",
";",
"$",
"form",
"->",
"setType",
"(",
"'name'",
",",
"PARAM_TEXT",
")",
";",
"$",
"form",
"->",
"addElement",
"(",
"'editor'",
",",
"'description'",
",",
"get_string",
"(",
"'profiledescription'",
",",
"'admin'",
")",
",",
"null",
",",
"null",
")",
";",
"$",
"form",
"->",
"addElement",
"(",
"'selectyesno'",
",",
"'required'",
",",
"get_string",
"(",
"'profilerequired'",
",",
"'admin'",
")",
")",
";",
"$",
"form",
"->",
"addElement",
"(",
"'selectyesno'",
",",
"'locked'",
",",
"get_string",
"(",
"'profilelocked'",
",",
"'admin'",
")",
")",
";",
"$",
"form",
"->",
"addElement",
"(",
"'selectyesno'",
",",
"'forceunique'",
",",
"get_string",
"(",
"'profileforceunique'",
",",
"'admin'",
")",
")",
";",
"$",
"form",
"->",
"addElement",
"(",
"'selectyesno'",
",",
"'signup'",
",",
"get_string",
"(",
"'profilesignup'",
",",
"'admin'",
")",
")",
";",
"$",
"choices",
"=",
"array",
"(",
")",
";",
"$",
"choices",
"[",
"PROFILE_VISIBLE_NONE",
"]",
"=",
"get_string",
"(",
"'profilevisiblenone'",
",",
"'admin'",
")",
";",
"$",
"choices",
"[",
"PROFILE_VISIBLE_PRIVATE",
"]",
"=",
"get_string",
"(",
"'profilevisibleprivate'",
",",
"'admin'",
")",
";",
"$",
"choices",
"[",
"PROFILE_VISIBLE_ALL",
"]",
"=",
"get_string",
"(",
"'profilevisibleall'",
",",
"'admin'",
")",
";",
"$",
"form",
"->",
"addElement",
"(",
"'select'",
",",
"'visible'",
",",
"get_string",
"(",
"'profilevisible'",
",",
"'admin'",
")",
",",
"$",
"choices",
")",
";",
"$",
"form",
"->",
"addHelpButton",
"(",
"'visible'",
",",
"'profilevisible'",
",",
"'admin'",
")",
";",
"$",
"form",
"->",
"setDefault",
"(",
"'visible'",
",",
"PROFILE_VISIBLE_ALL",
")",
";",
"$",
"choices",
"=",
"profile_list_categories",
"(",
")",
";",
"$",
"form",
"->",
"addElement",
"(",
"'select'",
",",
"'categoryid'",
",",
"get_string",
"(",
"'profilecategory'",
",",
"'admin'",
")",
",",
"$",
"choices",
")",
";",
"}"
] |
Prints out the form snippet for the part of creating or editing a profile field common to all data types.
@param moodleform $form instance of the moodleform class
|
[
"Prints",
"out",
"the",
"form",
"snippet",
"for",
"the",
"part",
"of",
"creating",
"or",
"editing",
"a",
"profile",
"field",
"common",
"to",
"all",
"data",
"types",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/profile/definelib.php#L50-L85
|
220,337
|
moodle/moodle
|
user/profile/definelib.php
|
profile_define_base.define_save
|
public function define_save($data) {
global $DB;
$data = $this->define_save_preprocess($data); // Hook for child classes.
$old = false;
if (!empty($data->id)) {
$old = $DB->get_record('user_info_field', array('id' => (int)$data->id));
}
// Check to see if the category has changed.
if (!$old or $old->categoryid != $data->categoryid) {
$data->sortorder = $DB->count_records('user_info_field', array('categoryid' => $data->categoryid)) + 1;
}
if (empty($data->id)) {
unset($data->id);
$data->id = $DB->insert_record('user_info_field', $data);
} else {
$DB->update_record('user_info_field', $data);
}
$field = $DB->get_record('user_info_field', array('id' => $data->id));
if ($old) {
\core\event\user_info_field_updated::create_from_field($field)->trigger();
} else {
\core\event\user_info_field_created::create_from_field($field)->trigger();
}
}
|
php
|
public function define_save($data) {
global $DB;
$data = $this->define_save_preprocess($data); // Hook for child classes.
$old = false;
if (!empty($data->id)) {
$old = $DB->get_record('user_info_field', array('id' => (int)$data->id));
}
// Check to see if the category has changed.
if (!$old or $old->categoryid != $data->categoryid) {
$data->sortorder = $DB->count_records('user_info_field', array('categoryid' => $data->categoryid)) + 1;
}
if (empty($data->id)) {
unset($data->id);
$data->id = $DB->insert_record('user_info_field', $data);
} else {
$DB->update_record('user_info_field', $data);
}
$field = $DB->get_record('user_info_field', array('id' => $data->id));
if ($old) {
\core\event\user_info_field_updated::create_from_field($field)->trigger();
} else {
\core\event\user_info_field_created::create_from_field($field)->trigger();
}
}
|
[
"public",
"function",
"define_save",
"(",
"$",
"data",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"define_save_preprocess",
"(",
"$",
"data",
")",
";",
"// Hook for child classes.",
"$",
"old",
"=",
"false",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"->",
"id",
")",
")",
"{",
"$",
"old",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'user_info_field'",
",",
"array",
"(",
"'id'",
"=>",
"(",
"int",
")",
"$",
"data",
"->",
"id",
")",
")",
";",
"}",
"// Check to see if the category has changed.",
"if",
"(",
"!",
"$",
"old",
"or",
"$",
"old",
"->",
"categoryid",
"!=",
"$",
"data",
"->",
"categoryid",
")",
"{",
"$",
"data",
"->",
"sortorder",
"=",
"$",
"DB",
"->",
"count_records",
"(",
"'user_info_field'",
",",
"array",
"(",
"'categoryid'",
"=>",
"$",
"data",
"->",
"categoryid",
")",
")",
"+",
"1",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"data",
"->",
"id",
")",
")",
"{",
"unset",
"(",
"$",
"data",
"->",
"id",
")",
";",
"$",
"data",
"->",
"id",
"=",
"$",
"DB",
"->",
"insert_record",
"(",
"'user_info_field'",
",",
"$",
"data",
")",
";",
"}",
"else",
"{",
"$",
"DB",
"->",
"update_record",
"(",
"'user_info_field'",
",",
"$",
"data",
")",
";",
"}",
"$",
"field",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'user_info_field'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"data",
"->",
"id",
")",
")",
";",
"if",
"(",
"$",
"old",
")",
"{",
"\\",
"core",
"\\",
"event",
"\\",
"user_info_field_updated",
"::",
"create_from_field",
"(",
"$",
"field",
")",
"->",
"trigger",
"(",
")",
";",
"}",
"else",
"{",
"\\",
"core",
"\\",
"event",
"\\",
"user_info_field_created",
"::",
"create_from_field",
"(",
"$",
"field",
")",
"->",
"trigger",
"(",
")",
";",
"}",
"}"
] |
Add a new profile field or save changes to current field
@param array|stdClass $data from the add/edit profile field form
|
[
"Add",
"a",
"new",
"profile",
"field",
"or",
"save",
"changes",
"to",
"current",
"field"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/profile/definelib.php#L177-L205
|
220,338
|
moodle/moodle
|
lib/classes/event/tag_created.php
|
tag_created.create_from_tag
|
public static function create_from_tag($tag) {
$event = self::create(array(
'objectid' => $tag->id,
'relateduserid' => $tag->userid,
'context' => \context_system::instance(),
'other' => array(
'name' => $tag->name,
'rawname' => $tag->rawname
)
));
return $event;
}
|
php
|
public static function create_from_tag($tag) {
$event = self::create(array(
'objectid' => $tag->id,
'relateduserid' => $tag->userid,
'context' => \context_system::instance(),
'other' => array(
'name' => $tag->name,
'rawname' => $tag->rawname
)
));
return $event;
}
|
[
"public",
"static",
"function",
"create_from_tag",
"(",
"$",
"tag",
")",
"{",
"$",
"event",
"=",
"self",
"::",
"create",
"(",
"array",
"(",
"'objectid'",
"=>",
"$",
"tag",
"->",
"id",
",",
"'relateduserid'",
"=>",
"$",
"tag",
"->",
"userid",
",",
"'context'",
"=>",
"\\",
"context_system",
"::",
"instance",
"(",
")",
",",
"'other'",
"=>",
"array",
"(",
"'name'",
"=>",
"$",
"tag",
"->",
"name",
",",
"'rawname'",
"=>",
"$",
"tag",
"->",
"rawname",
")",
")",
")",
";",
"return",
"$",
"event",
";",
"}"
] |
Creates an event from tag object
@since Moodle 3.1
@param \core_tag_tag|\stdClass $tag
@return tag_created
|
[
"Creates",
"an",
"event",
"from",
"tag",
"object"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/event/tag_created.php#L62-L73
|
220,339
|
moodle/moodle
|
lib/classes/event/enrol_instance_deleted.php
|
enrol_instance_deleted.create_from_record
|
public static final function create_from_record($enrol) {
$event = static::create(array(
'context' => \context_course::instance($enrol->courseid),
'objectid' => $enrol->id,
'other' => array('enrol' => $enrol->enrol)
));
$event->add_record_snapshot('enrol', $enrol);
return $event;
}
|
php
|
public static final function create_from_record($enrol) {
$event = static::create(array(
'context' => \context_course::instance($enrol->courseid),
'objectid' => $enrol->id,
'other' => array('enrol' => $enrol->enrol)
));
$event->add_record_snapshot('enrol', $enrol);
return $event;
}
|
[
"public",
"static",
"final",
"function",
"create_from_record",
"(",
"$",
"enrol",
")",
"{",
"$",
"event",
"=",
"static",
"::",
"create",
"(",
"array",
"(",
"'context'",
"=>",
"\\",
"context_course",
"::",
"instance",
"(",
"$",
"enrol",
"->",
"courseid",
")",
",",
"'objectid'",
"=>",
"$",
"enrol",
"->",
"id",
",",
"'other'",
"=>",
"array",
"(",
"'enrol'",
"=>",
"$",
"enrol",
"->",
"enrol",
")",
")",
")",
";",
"$",
"event",
"->",
"add_record_snapshot",
"(",
"'enrol'",
",",
"$",
"enrol",
")",
";",
"return",
"$",
"event",
";",
"}"
] |
Api to Create new event from enrol object.
@param \stdClass $enrol record from DB table 'enrol'
@return \core\event\base returns instance of new event
|
[
"Api",
"to",
"Create",
"new",
"event",
"from",
"enrol",
"object",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/event/enrol_instance_deleted.php#L50-L58
|
220,340
|
moodle/moodle
|
lib/antivirus/clamav/classes/scanner.php
|
scanner.is_configured
|
public function is_configured() {
if ($this->get_config('runningmethod') === 'commandline') {
return (bool)$this->get_config('pathtoclam');
} else if ($this->get_config('runningmethod') === 'unixsocket') {
return (bool)$this->get_config('pathtounixsocket');
}
return false;
}
|
php
|
public function is_configured() {
if ($this->get_config('runningmethod') === 'commandline') {
return (bool)$this->get_config('pathtoclam');
} else if ($this->get_config('runningmethod') === 'unixsocket') {
return (bool)$this->get_config('pathtounixsocket');
}
return false;
}
|
[
"public",
"function",
"is_configured",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"get_config",
"(",
"'runningmethod'",
")",
"===",
"'commandline'",
")",
"{",
"return",
"(",
"bool",
")",
"$",
"this",
"->",
"get_config",
"(",
"'pathtoclam'",
")",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"get_config",
"(",
"'runningmethod'",
")",
"===",
"'unixsocket'",
")",
"{",
"return",
"(",
"bool",
")",
"$",
"this",
"->",
"get_config",
"(",
"'pathtounixsocket'",
")",
";",
"}",
"return",
"false",
";",
"}"
] |
Are the necessary antivirus settings configured?
@return bool True if all necessary config settings been entered
|
[
"Are",
"the",
"necessary",
"antivirus",
"settings",
"configured?"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/antivirus/clamav/classes/scanner.php#L45-L52
|
220,341
|
moodle/moodle
|
lib/antivirus/clamav/classes/scanner.php
|
scanner.scan_file
|
public function scan_file($file, $filename) {
if (!is_readable($file)) {
// This should not happen.
debugging('File is not readable.');
return self::SCAN_RESULT_ERROR;
}
// Execute the scan using preferable method.
$method = 'scan_file_execute_' . $this->get_config('runningmethod');
if (!method_exists($this, $method)) {
throw new \coding_exception('Attempting to call non-existing method ' . $method);
}
$return = $this->$method($file);
if ($return === self::SCAN_RESULT_ERROR) {
$this->message_admins($this->get_scanning_notice());
// If plugin settings require us to act like virus on any error,
// return SCAN_RESULT_FOUND result.
if ($this->get_config('clamfailureonupload') === 'actlikevirus') {
return self::SCAN_RESULT_FOUND;
}
}
return $return;
}
|
php
|
public function scan_file($file, $filename) {
if (!is_readable($file)) {
// This should not happen.
debugging('File is not readable.');
return self::SCAN_RESULT_ERROR;
}
// Execute the scan using preferable method.
$method = 'scan_file_execute_' . $this->get_config('runningmethod');
if (!method_exists($this, $method)) {
throw new \coding_exception('Attempting to call non-existing method ' . $method);
}
$return = $this->$method($file);
if ($return === self::SCAN_RESULT_ERROR) {
$this->message_admins($this->get_scanning_notice());
// If plugin settings require us to act like virus on any error,
// return SCAN_RESULT_FOUND result.
if ($this->get_config('clamfailureonupload') === 'actlikevirus') {
return self::SCAN_RESULT_FOUND;
}
}
return $return;
}
|
[
"public",
"function",
"scan_file",
"(",
"$",
"file",
",",
"$",
"filename",
")",
"{",
"if",
"(",
"!",
"is_readable",
"(",
"$",
"file",
")",
")",
"{",
"// This should not happen.",
"debugging",
"(",
"'File is not readable.'",
")",
";",
"return",
"self",
"::",
"SCAN_RESULT_ERROR",
";",
"}",
"// Execute the scan using preferable method.",
"$",
"method",
"=",
"'scan_file_execute_'",
".",
"$",
"this",
"->",
"get_config",
"(",
"'runningmethod'",
")",
";",
"if",
"(",
"!",
"method_exists",
"(",
"$",
"this",
",",
"$",
"method",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Attempting to call non-existing method '",
".",
"$",
"method",
")",
";",
"}",
"$",
"return",
"=",
"$",
"this",
"->",
"$",
"method",
"(",
"$",
"file",
")",
";",
"if",
"(",
"$",
"return",
"===",
"self",
"::",
"SCAN_RESULT_ERROR",
")",
"{",
"$",
"this",
"->",
"message_admins",
"(",
"$",
"this",
"->",
"get_scanning_notice",
"(",
")",
")",
";",
"// If plugin settings require us to act like virus on any error,",
"// return SCAN_RESULT_FOUND result.",
"if",
"(",
"$",
"this",
"->",
"get_config",
"(",
"'clamfailureonupload'",
")",
"===",
"'actlikevirus'",
")",
"{",
"return",
"self",
"::",
"SCAN_RESULT_FOUND",
";",
"}",
"}",
"return",
"$",
"return",
";",
"}"
] |
Scan file.
This method is normally called from antivirus manager (\core\antivirus\manager::scan_file).
@param string $file Full path to the file.
@param string $filename Name of the file (could be different from physical file if temp file is used).
@return int Scanning result constant.
|
[
"Scan",
"file",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/antivirus/clamav/classes/scanner.php#L63-L86
|
220,342
|
moodle/moodle
|
lib/antivirus/clamav/classes/scanner.php
|
scanner.get_clam_error_code
|
private function get_clam_error_code($returncode) {
$returncodes = array();
$returncodes[0] = 'No virus found.';
$returncodes[1] = 'Virus(es) found.';
$returncodes[2] = ' An error occured'; // Specific to clamdscan.
// All after here are specific to clamscan.
$returncodes[40] = 'Unknown option passed.';
$returncodes[50] = 'Database initialization error.';
$returncodes[52] = 'Not supported file type.';
$returncodes[53] = 'Can\'t open directory.';
$returncodes[54] = 'Can\'t open file. (ofm)';
$returncodes[55] = 'Error reading file. (ofm)';
$returncodes[56] = 'Can\'t stat input file / directory.';
$returncodes[57] = 'Can\'t get absolute path name of current working directory.';
$returncodes[58] = 'I/O error, please check your filesystem.';
$returncodes[59] = 'Can\'t get information about current user from /etc/passwd.';
$returncodes[60] = 'Can\'t get information about user \'clamav\' (default name) from /etc/passwd.';
$returncodes[61] = 'Can\'t fork.';
$returncodes[63] = 'Can\'t create temporary files/directories (check permissions).';
$returncodes[64] = 'Can\'t write to temporary directory (please specify another one).';
$returncodes[70] = 'Can\'t allocate and clear memory (calloc).';
$returncodes[71] = 'Can\'t allocate memory (malloc).';
if (isset($returncodes[$returncode])) {
return $returncodes[$returncode];
}
return get_string('unknownerror', 'antivirus_clamav');
}
|
php
|
private function get_clam_error_code($returncode) {
$returncodes = array();
$returncodes[0] = 'No virus found.';
$returncodes[1] = 'Virus(es) found.';
$returncodes[2] = ' An error occured'; // Specific to clamdscan.
// All after here are specific to clamscan.
$returncodes[40] = 'Unknown option passed.';
$returncodes[50] = 'Database initialization error.';
$returncodes[52] = 'Not supported file type.';
$returncodes[53] = 'Can\'t open directory.';
$returncodes[54] = 'Can\'t open file. (ofm)';
$returncodes[55] = 'Error reading file. (ofm)';
$returncodes[56] = 'Can\'t stat input file / directory.';
$returncodes[57] = 'Can\'t get absolute path name of current working directory.';
$returncodes[58] = 'I/O error, please check your filesystem.';
$returncodes[59] = 'Can\'t get information about current user from /etc/passwd.';
$returncodes[60] = 'Can\'t get information about user \'clamav\' (default name) from /etc/passwd.';
$returncodes[61] = 'Can\'t fork.';
$returncodes[63] = 'Can\'t create temporary files/directories (check permissions).';
$returncodes[64] = 'Can\'t write to temporary directory (please specify another one).';
$returncodes[70] = 'Can\'t allocate and clear memory (calloc).';
$returncodes[71] = 'Can\'t allocate memory (malloc).';
if (isset($returncodes[$returncode])) {
return $returncodes[$returncode];
}
return get_string('unknownerror', 'antivirus_clamav');
}
|
[
"private",
"function",
"get_clam_error_code",
"(",
"$",
"returncode",
")",
"{",
"$",
"returncodes",
"=",
"array",
"(",
")",
";",
"$",
"returncodes",
"[",
"0",
"]",
"=",
"'No virus found.'",
";",
"$",
"returncodes",
"[",
"1",
"]",
"=",
"'Virus(es) found.'",
";",
"$",
"returncodes",
"[",
"2",
"]",
"=",
"' An error occured'",
";",
"// Specific to clamdscan.",
"// All after here are specific to clamscan.",
"$",
"returncodes",
"[",
"40",
"]",
"=",
"'Unknown option passed.'",
";",
"$",
"returncodes",
"[",
"50",
"]",
"=",
"'Database initialization error.'",
";",
"$",
"returncodes",
"[",
"52",
"]",
"=",
"'Not supported file type.'",
";",
"$",
"returncodes",
"[",
"53",
"]",
"=",
"'Can\\'t open directory.'",
";",
"$",
"returncodes",
"[",
"54",
"]",
"=",
"'Can\\'t open file. (ofm)'",
";",
"$",
"returncodes",
"[",
"55",
"]",
"=",
"'Error reading file. (ofm)'",
";",
"$",
"returncodes",
"[",
"56",
"]",
"=",
"'Can\\'t stat input file / directory.'",
";",
"$",
"returncodes",
"[",
"57",
"]",
"=",
"'Can\\'t get absolute path name of current working directory.'",
";",
"$",
"returncodes",
"[",
"58",
"]",
"=",
"'I/O error, please check your filesystem.'",
";",
"$",
"returncodes",
"[",
"59",
"]",
"=",
"'Can\\'t get information about current user from /etc/passwd.'",
";",
"$",
"returncodes",
"[",
"60",
"]",
"=",
"'Can\\'t get information about user \\'clamav\\' (default name) from /etc/passwd.'",
";",
"$",
"returncodes",
"[",
"61",
"]",
"=",
"'Can\\'t fork.'",
";",
"$",
"returncodes",
"[",
"63",
"]",
"=",
"'Can\\'t create temporary files/directories (check permissions).'",
";",
"$",
"returncodes",
"[",
"64",
"]",
"=",
"'Can\\'t write to temporary directory (please specify another one).'",
";",
"$",
"returncodes",
"[",
"70",
"]",
"=",
"'Can\\'t allocate and clear memory (calloc).'",
";",
"$",
"returncodes",
"[",
"71",
"]",
"=",
"'Can\\'t allocate memory (malloc).'",
";",
"if",
"(",
"isset",
"(",
"$",
"returncodes",
"[",
"$",
"returncode",
"]",
")",
")",
"{",
"return",
"$",
"returncodes",
"[",
"$",
"returncode",
"]",
";",
"}",
"return",
"get_string",
"(",
"'unknownerror'",
",",
"'antivirus_clamav'",
")",
";",
"}"
] |
Returns the string equivalent of a numeric clam error code
@param int $returncode The numeric error code in question.
@return string The definition of the error code
|
[
"Returns",
"the",
"string",
"equivalent",
"of",
"a",
"numeric",
"clam",
"error",
"code"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/antivirus/clamav/classes/scanner.php#L120-L146
|
220,343
|
moodle/moodle
|
lib/antivirus/clamav/classes/scanner.php
|
scanner.scan_file_execute_commandline
|
public function scan_file_execute_commandline($file) {
$pathtoclam = trim($this->get_config('pathtoclam'));
if (!file_exists($pathtoclam) or !is_executable($pathtoclam)) {
// Misconfigured clam, notify admins.
$notice = get_string('invalidpathtoclam', 'antivirus_clamav', $pathtoclam);
$this->set_scanning_notice($notice);
return self::SCAN_RESULT_ERROR;
}
$clamparam = ' --stdout ';
// If we are dealing with clamdscan, clamd is likely run as a different user
// that might not have permissions to access your file.
// To make clamdscan work, we use --fdpass parameter that passes the file
// descriptor permissions to clamd, which allows it to scan given file
// irrespective of directory and file permissions.
if (basename($pathtoclam) == 'clamdscan') {
$clamparam .= '--fdpass ';
}
// Execute scan.
$cmd = escapeshellcmd($pathtoclam).$clamparam.escapeshellarg($file);
exec($cmd, $output, $return);
// Return variable will contain execution return code. It will be 0 if no virus is found,
// 1 if virus is found, and 2 or above for the error. Return codes 0 and 1 correspond to
// SCAN_RESULT_OK and SCAN_RESULT_FOUND constants, so we return them as it is.
// If there is an error, it gets stored as scanning notice and function
// returns SCAN_RESULT_ERROR.
if ($return > self::SCAN_RESULT_FOUND) {
$notice = get_string('clamfailed', 'antivirus_clamav', $this->get_clam_error_code($return));
$notice .= "\n\n". implode("\n", $output);
$this->set_scanning_notice($notice);
return self::SCAN_RESULT_ERROR;
}
return (int)$return;
}
|
php
|
public function scan_file_execute_commandline($file) {
$pathtoclam = trim($this->get_config('pathtoclam'));
if (!file_exists($pathtoclam) or !is_executable($pathtoclam)) {
// Misconfigured clam, notify admins.
$notice = get_string('invalidpathtoclam', 'antivirus_clamav', $pathtoclam);
$this->set_scanning_notice($notice);
return self::SCAN_RESULT_ERROR;
}
$clamparam = ' --stdout ';
// If we are dealing with clamdscan, clamd is likely run as a different user
// that might not have permissions to access your file.
// To make clamdscan work, we use --fdpass parameter that passes the file
// descriptor permissions to clamd, which allows it to scan given file
// irrespective of directory and file permissions.
if (basename($pathtoclam) == 'clamdscan') {
$clamparam .= '--fdpass ';
}
// Execute scan.
$cmd = escapeshellcmd($pathtoclam).$clamparam.escapeshellarg($file);
exec($cmd, $output, $return);
// Return variable will contain execution return code. It will be 0 if no virus is found,
// 1 if virus is found, and 2 or above for the error. Return codes 0 and 1 correspond to
// SCAN_RESULT_OK and SCAN_RESULT_FOUND constants, so we return them as it is.
// If there is an error, it gets stored as scanning notice and function
// returns SCAN_RESULT_ERROR.
if ($return > self::SCAN_RESULT_FOUND) {
$notice = get_string('clamfailed', 'antivirus_clamav', $this->get_clam_error_code($return));
$notice .= "\n\n". implode("\n", $output);
$this->set_scanning_notice($notice);
return self::SCAN_RESULT_ERROR;
}
return (int)$return;
}
|
[
"public",
"function",
"scan_file_execute_commandline",
"(",
"$",
"file",
")",
"{",
"$",
"pathtoclam",
"=",
"trim",
"(",
"$",
"this",
"->",
"get_config",
"(",
"'pathtoclam'",
")",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"pathtoclam",
")",
"or",
"!",
"is_executable",
"(",
"$",
"pathtoclam",
")",
")",
"{",
"// Misconfigured clam, notify admins.",
"$",
"notice",
"=",
"get_string",
"(",
"'invalidpathtoclam'",
",",
"'antivirus_clamav'",
",",
"$",
"pathtoclam",
")",
";",
"$",
"this",
"->",
"set_scanning_notice",
"(",
"$",
"notice",
")",
";",
"return",
"self",
"::",
"SCAN_RESULT_ERROR",
";",
"}",
"$",
"clamparam",
"=",
"' --stdout '",
";",
"// If we are dealing with clamdscan, clamd is likely run as a different user",
"// that might not have permissions to access your file.",
"// To make clamdscan work, we use --fdpass parameter that passes the file",
"// descriptor permissions to clamd, which allows it to scan given file",
"// irrespective of directory and file permissions.",
"if",
"(",
"basename",
"(",
"$",
"pathtoclam",
")",
"==",
"'clamdscan'",
")",
"{",
"$",
"clamparam",
".=",
"'--fdpass '",
";",
"}",
"// Execute scan.",
"$",
"cmd",
"=",
"escapeshellcmd",
"(",
"$",
"pathtoclam",
")",
".",
"$",
"clamparam",
".",
"escapeshellarg",
"(",
"$",
"file",
")",
";",
"exec",
"(",
"$",
"cmd",
",",
"$",
"output",
",",
"$",
"return",
")",
";",
"// Return variable will contain execution return code. It will be 0 if no virus is found,",
"// 1 if virus is found, and 2 or above for the error. Return codes 0 and 1 correspond to",
"// SCAN_RESULT_OK and SCAN_RESULT_FOUND constants, so we return them as it is.",
"// If there is an error, it gets stored as scanning notice and function",
"// returns SCAN_RESULT_ERROR.",
"if",
"(",
"$",
"return",
">",
"self",
"::",
"SCAN_RESULT_FOUND",
")",
"{",
"$",
"notice",
"=",
"get_string",
"(",
"'clamfailed'",
",",
"'antivirus_clamav'",
",",
"$",
"this",
"->",
"get_clam_error_code",
"(",
"$",
"return",
")",
")",
";",
"$",
"notice",
".=",
"\"\\n\\n\"",
".",
"implode",
"(",
"\"\\n\"",
",",
"$",
"output",
")",
";",
"$",
"this",
"->",
"set_scanning_notice",
"(",
"$",
"notice",
")",
";",
"return",
"self",
"::",
"SCAN_RESULT_ERROR",
";",
"}",
"return",
"(",
"int",
")",
"$",
"return",
";",
"}"
] |
Scan file using command line utility.
@param string $file Full path to the file.
@return int Scanning result constant.
|
[
"Scan",
"file",
"using",
"command",
"line",
"utility",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/antivirus/clamav/classes/scanner.php#L154-L189
|
220,344
|
moodle/moodle
|
lib/antivirus/clamav/classes/scanner.php
|
scanner.scan_file_execute_unixsocket
|
public function scan_file_execute_unixsocket($file) {
$socket = stream_socket_client('unix://' . $this->get_config('pathtounixsocket'),
$errno, $errstr, ANTIVIRUS_CLAMAV_SOCKET_TIMEOUT);
if (!$socket) {
// Can't open socket for some reason, notify admins.
$notice = get_string('errorcantopensocket', 'antivirus_clamav', "$errstr ($errno)");
$this->set_scanning_notice($notice);
return self::SCAN_RESULT_ERROR;
} else {
// Execute scanning. We are running SCAN command and passing file as an argument,
// it is the fastest option, but clamav user need to be able to access it, so
// we give group read permissions first and assume 'clamav' user is in web server
// group (in Debian the default webserver group is 'www-data').
// Using 'n' as command prefix is forcing clamav to only treat \n as newline delimeter,
// this is to avoid unexpected newline characters on different systems.
$perms = fileperms($file);
chmod($file, 0640);
fwrite($socket, "nSCAN ".$file."\n");
$output = stream_get_line($socket, 4096);
fclose($socket);
// After scanning we revert permissions to initial ones.
chmod($file, $perms);
// Parse the output.
return $this->parse_unixsocket_response($output);
}
}
|
php
|
public function scan_file_execute_unixsocket($file) {
$socket = stream_socket_client('unix://' . $this->get_config('pathtounixsocket'),
$errno, $errstr, ANTIVIRUS_CLAMAV_SOCKET_TIMEOUT);
if (!$socket) {
// Can't open socket for some reason, notify admins.
$notice = get_string('errorcantopensocket', 'antivirus_clamav', "$errstr ($errno)");
$this->set_scanning_notice($notice);
return self::SCAN_RESULT_ERROR;
} else {
// Execute scanning. We are running SCAN command and passing file as an argument,
// it is the fastest option, but clamav user need to be able to access it, so
// we give group read permissions first and assume 'clamav' user is in web server
// group (in Debian the default webserver group is 'www-data').
// Using 'n' as command prefix is forcing clamav to only treat \n as newline delimeter,
// this is to avoid unexpected newline characters on different systems.
$perms = fileperms($file);
chmod($file, 0640);
fwrite($socket, "nSCAN ".$file."\n");
$output = stream_get_line($socket, 4096);
fclose($socket);
// After scanning we revert permissions to initial ones.
chmod($file, $perms);
// Parse the output.
return $this->parse_unixsocket_response($output);
}
}
|
[
"public",
"function",
"scan_file_execute_unixsocket",
"(",
"$",
"file",
")",
"{",
"$",
"socket",
"=",
"stream_socket_client",
"(",
"'unix://'",
".",
"$",
"this",
"->",
"get_config",
"(",
"'pathtounixsocket'",
")",
",",
"$",
"errno",
",",
"$",
"errstr",
",",
"ANTIVIRUS_CLAMAV_SOCKET_TIMEOUT",
")",
";",
"if",
"(",
"!",
"$",
"socket",
")",
"{",
"// Can't open socket for some reason, notify admins.",
"$",
"notice",
"=",
"get_string",
"(",
"'errorcantopensocket'",
",",
"'antivirus_clamav'",
",",
"\"$errstr ($errno)\"",
")",
";",
"$",
"this",
"->",
"set_scanning_notice",
"(",
"$",
"notice",
")",
";",
"return",
"self",
"::",
"SCAN_RESULT_ERROR",
";",
"}",
"else",
"{",
"// Execute scanning. We are running SCAN command and passing file as an argument,",
"// it is the fastest option, but clamav user need to be able to access it, so",
"// we give group read permissions first and assume 'clamav' user is in web server",
"// group (in Debian the default webserver group is 'www-data').",
"// Using 'n' as command prefix is forcing clamav to only treat \\n as newline delimeter,",
"// this is to avoid unexpected newline characters on different systems.",
"$",
"perms",
"=",
"fileperms",
"(",
"$",
"file",
")",
";",
"chmod",
"(",
"$",
"file",
",",
"0640",
")",
";",
"fwrite",
"(",
"$",
"socket",
",",
"\"nSCAN \"",
".",
"$",
"file",
".",
"\"\\n\"",
")",
";",
"$",
"output",
"=",
"stream_get_line",
"(",
"$",
"socket",
",",
"4096",
")",
";",
"fclose",
"(",
"$",
"socket",
")",
";",
"// After scanning we revert permissions to initial ones.",
"chmod",
"(",
"$",
"file",
",",
"$",
"perms",
")",
";",
"// Parse the output.",
"return",
"$",
"this",
"->",
"parse_unixsocket_response",
"(",
"$",
"output",
")",
";",
"}",
"}"
] |
Scan file using Unix domain sockets.
@param string $file Full path to the file.
@return int Scanning result constant.
|
[
"Scan",
"file",
"using",
"Unix",
"domain",
"sockets",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/antivirus/clamav/classes/scanner.php#L197-L222
|
220,345
|
moodle/moodle
|
lib/antivirus/clamav/classes/scanner.php
|
scanner.scan_data_execute_unixsocket
|
public function scan_data_execute_unixsocket($data) {
$socket = stream_socket_client('unix://' . $this->get_config('pathtounixsocket'), $errno, $errstr, ANTIVIRUS_CLAMAV_SOCKET_TIMEOUT);
if (!$socket) {
// Can't open socket for some reason, notify admins.
$notice = get_string('errorcantopensocket', 'antivirus_clamav', "$errstr ($errno)");
$this->set_scanning_notice($notice);
return self::SCAN_RESULT_ERROR;
} else {
// Initiate data stream scanning.
// Using 'n' as command prefix is forcing clamav to only treat \n as newline delimeter,
// this is to avoid unexpected newline characters on different systems.
fwrite($socket, "nINSTREAM\n");
// Send data in chunks of ANTIVIRUS_CLAMAV_SOCKET_CHUNKSIZE size.
while (strlen($data) > 0) {
$chunk = substr($data, 0, ANTIVIRUS_CLAMAV_SOCKET_CHUNKSIZE);
$data = substr($data, ANTIVIRUS_CLAMAV_SOCKET_CHUNKSIZE);
$size = pack('N', strlen($chunk));
fwrite($socket, $size);
fwrite($socket, $chunk);
}
// Terminate streaming.
fwrite($socket, pack('N', 0));
$output = stream_get_line($socket, 4096);
fclose($socket);
// Parse the output.
return $this->parse_unixsocket_response($output);
}
}
|
php
|
public function scan_data_execute_unixsocket($data) {
$socket = stream_socket_client('unix://' . $this->get_config('pathtounixsocket'), $errno, $errstr, ANTIVIRUS_CLAMAV_SOCKET_TIMEOUT);
if (!$socket) {
// Can't open socket for some reason, notify admins.
$notice = get_string('errorcantopensocket', 'antivirus_clamav', "$errstr ($errno)");
$this->set_scanning_notice($notice);
return self::SCAN_RESULT_ERROR;
} else {
// Initiate data stream scanning.
// Using 'n' as command prefix is forcing clamav to only treat \n as newline delimeter,
// this is to avoid unexpected newline characters on different systems.
fwrite($socket, "nINSTREAM\n");
// Send data in chunks of ANTIVIRUS_CLAMAV_SOCKET_CHUNKSIZE size.
while (strlen($data) > 0) {
$chunk = substr($data, 0, ANTIVIRUS_CLAMAV_SOCKET_CHUNKSIZE);
$data = substr($data, ANTIVIRUS_CLAMAV_SOCKET_CHUNKSIZE);
$size = pack('N', strlen($chunk));
fwrite($socket, $size);
fwrite($socket, $chunk);
}
// Terminate streaming.
fwrite($socket, pack('N', 0));
$output = stream_get_line($socket, 4096);
fclose($socket);
// Parse the output.
return $this->parse_unixsocket_response($output);
}
}
|
[
"public",
"function",
"scan_data_execute_unixsocket",
"(",
"$",
"data",
")",
"{",
"$",
"socket",
"=",
"stream_socket_client",
"(",
"'unix://'",
".",
"$",
"this",
"->",
"get_config",
"(",
"'pathtounixsocket'",
")",
",",
"$",
"errno",
",",
"$",
"errstr",
",",
"ANTIVIRUS_CLAMAV_SOCKET_TIMEOUT",
")",
";",
"if",
"(",
"!",
"$",
"socket",
")",
"{",
"// Can't open socket for some reason, notify admins.",
"$",
"notice",
"=",
"get_string",
"(",
"'errorcantopensocket'",
",",
"'antivirus_clamav'",
",",
"\"$errstr ($errno)\"",
")",
";",
"$",
"this",
"->",
"set_scanning_notice",
"(",
"$",
"notice",
")",
";",
"return",
"self",
"::",
"SCAN_RESULT_ERROR",
";",
"}",
"else",
"{",
"// Initiate data stream scanning.",
"// Using 'n' as command prefix is forcing clamav to only treat \\n as newline delimeter,",
"// this is to avoid unexpected newline characters on different systems.",
"fwrite",
"(",
"$",
"socket",
",",
"\"nINSTREAM\\n\"",
")",
";",
"// Send data in chunks of ANTIVIRUS_CLAMAV_SOCKET_CHUNKSIZE size.",
"while",
"(",
"strlen",
"(",
"$",
"data",
")",
">",
"0",
")",
"{",
"$",
"chunk",
"=",
"substr",
"(",
"$",
"data",
",",
"0",
",",
"ANTIVIRUS_CLAMAV_SOCKET_CHUNKSIZE",
")",
";",
"$",
"data",
"=",
"substr",
"(",
"$",
"data",
",",
"ANTIVIRUS_CLAMAV_SOCKET_CHUNKSIZE",
")",
";",
"$",
"size",
"=",
"pack",
"(",
"'N'",
",",
"strlen",
"(",
"$",
"chunk",
")",
")",
";",
"fwrite",
"(",
"$",
"socket",
",",
"$",
"size",
")",
";",
"fwrite",
"(",
"$",
"socket",
",",
"$",
"chunk",
")",
";",
"}",
"// Terminate streaming.",
"fwrite",
"(",
"$",
"socket",
",",
"pack",
"(",
"'N'",
",",
"0",
")",
")",
";",
"$",
"output",
"=",
"stream_get_line",
"(",
"$",
"socket",
",",
"4096",
")",
";",
"fclose",
"(",
"$",
"socket",
")",
";",
"// Parse the output.",
"return",
"$",
"this",
"->",
"parse_unixsocket_response",
"(",
"$",
"output",
")",
";",
"}",
"}"
] |
Scan data using unix socket.
We are running INSTREAM command and passing data stream in chunks.
The format of the chunk is: <length><data> where <length> is the size of the following
data in bytes expressed as a 4 byte unsigned integer in network byte order and <data>
is the actual chunk. Streaming is terminated by sending a zero-length chunk.
Do not exceed StreamMaxLength as defined in clamd.conf, otherwise clamd will
reply with INSTREAM size limit exceeded and close the connection.
@param string $data The varaible containing the data to scan.
@return int Scanning result constant.
|
[
"Scan",
"data",
"using",
"unix",
"socket",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/antivirus/clamav/classes/scanner.php#L237-L266
|
220,346
|
moodle/moodle
|
lib/antivirus/clamav/classes/scanner.php
|
scanner.parse_unixsocket_response
|
private function parse_unixsocket_response($output) {
$splitoutput = explode(': ', $output);
$message = trim($splitoutput[1]);
if ($message === 'OK') {
return self::SCAN_RESULT_OK;
} else {
$parts = explode(' ', $message);
$status = array_pop($parts);
if ($status === 'FOUND') {
return self::SCAN_RESULT_FOUND;
} else {
$notice = get_string('clamfailed', 'antivirus_clamav', $this->get_clam_error_code(2));
$notice .= "\n\n" . $output;
$this->set_scanning_notice($notice);
return self::SCAN_RESULT_ERROR;
}
}
}
|
php
|
private function parse_unixsocket_response($output) {
$splitoutput = explode(': ', $output);
$message = trim($splitoutput[1]);
if ($message === 'OK') {
return self::SCAN_RESULT_OK;
} else {
$parts = explode(' ', $message);
$status = array_pop($parts);
if ($status === 'FOUND') {
return self::SCAN_RESULT_FOUND;
} else {
$notice = get_string('clamfailed', 'antivirus_clamav', $this->get_clam_error_code(2));
$notice .= "\n\n" . $output;
$this->set_scanning_notice($notice);
return self::SCAN_RESULT_ERROR;
}
}
}
|
[
"private",
"function",
"parse_unixsocket_response",
"(",
"$",
"output",
")",
"{",
"$",
"splitoutput",
"=",
"explode",
"(",
"': '",
",",
"$",
"output",
")",
";",
"$",
"message",
"=",
"trim",
"(",
"$",
"splitoutput",
"[",
"1",
"]",
")",
";",
"if",
"(",
"$",
"message",
"===",
"'OK'",
")",
"{",
"return",
"self",
"::",
"SCAN_RESULT_OK",
";",
"}",
"else",
"{",
"$",
"parts",
"=",
"explode",
"(",
"' '",
",",
"$",
"message",
")",
";",
"$",
"status",
"=",
"array_pop",
"(",
"$",
"parts",
")",
";",
"if",
"(",
"$",
"status",
"===",
"'FOUND'",
")",
"{",
"return",
"self",
"::",
"SCAN_RESULT_FOUND",
";",
"}",
"else",
"{",
"$",
"notice",
"=",
"get_string",
"(",
"'clamfailed'",
",",
"'antivirus_clamav'",
",",
"$",
"this",
"->",
"get_clam_error_code",
"(",
"2",
")",
")",
";",
"$",
"notice",
".=",
"\"\\n\\n\"",
".",
"$",
"output",
";",
"$",
"this",
"->",
"set_scanning_notice",
"(",
"$",
"notice",
")",
";",
"return",
"self",
"::",
"SCAN_RESULT_ERROR",
";",
"}",
"}",
"}"
] |
Parse unix socket command response.
@param string $output The unix socket command response.
@return int Scanning result constant.
|
[
"Parse",
"unix",
"socket",
"command",
"response",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/antivirus/clamav/classes/scanner.php#L274-L291
|
220,347
|
moodle/moodle
|
lib/classes/persistent.php
|
persistent.verify_protected_methods
|
final protected function verify_protected_methods() {
$properties = static::properties_definition();
foreach ($properties as $property => $definition) {
$method = 'get_' . $property;
if (method_exists($this, $method)) {
$reflection = new ReflectionMethod($this, $method);
if (!$reflection->isProtected()) {
throw new coding_exception('The method ' . get_class($this) . '::'. $method . ' should be protected.');
}
}
$method = 'set_' . $property;
if (method_exists($this, $method)) {
$reflection = new ReflectionMethod($this, $method);
if (!$reflection->isProtected()) {
throw new coding_exception('The method ' . get_class($this) . '::'. $method . ' should be protected.');
}
}
}
}
|
php
|
final protected function verify_protected_methods() {
$properties = static::properties_definition();
foreach ($properties as $property => $definition) {
$method = 'get_' . $property;
if (method_exists($this, $method)) {
$reflection = new ReflectionMethod($this, $method);
if (!$reflection->isProtected()) {
throw new coding_exception('The method ' . get_class($this) . '::'. $method . ' should be protected.');
}
}
$method = 'set_' . $property;
if (method_exists($this, $method)) {
$reflection = new ReflectionMethod($this, $method);
if (!$reflection->isProtected()) {
throw new coding_exception('The method ' . get_class($this) . '::'. $method . ' should be protected.');
}
}
}
}
|
[
"final",
"protected",
"function",
"verify_protected_methods",
"(",
")",
"{",
"$",
"properties",
"=",
"static",
"::",
"properties_definition",
"(",
")",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"property",
"=>",
"$",
"definition",
")",
"{",
"$",
"method",
"=",
"'get_'",
".",
"$",
"property",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"method",
")",
")",
"{",
"$",
"reflection",
"=",
"new",
"ReflectionMethod",
"(",
"$",
"this",
",",
"$",
"method",
")",
";",
"if",
"(",
"!",
"$",
"reflection",
"->",
"isProtected",
"(",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The method '",
".",
"get_class",
"(",
"$",
"this",
")",
".",
"'::'",
".",
"$",
"method",
".",
"' should be protected.'",
")",
";",
"}",
"}",
"$",
"method",
"=",
"'set_'",
".",
"$",
"property",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"method",
")",
")",
"{",
"$",
"reflection",
"=",
"new",
"ReflectionMethod",
"(",
"$",
"this",
",",
"$",
"method",
")",
";",
"if",
"(",
"!",
"$",
"reflection",
"->",
"isProtected",
"(",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The method '",
".",
"get_class",
"(",
"$",
"this",
")",
".",
"'::'",
".",
"$",
"method",
".",
"' should be protected.'",
")",
";",
"}",
"}",
"}",
"}"
] |
This function is used to verify that custom getters and setters are declared as protected.
Persistent properties should always be accessed via get('property') and set('property', 'value') which
will call the custom getter or setter if it exists. We do not want to allow inconsistent access to the properties.
|
[
"This",
"function",
"is",
"used",
"to",
"verify",
"that",
"custom",
"getters",
"and",
"setters",
"are",
"declared",
"as",
"protected",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/persistent.php#L81-L100
|
220,348
|
moodle/moodle
|
lib/classes/persistent.php
|
persistent.get
|
final public function get($property) {
if (!static::has_property($property)) {
throw new coding_exception('Unexpected property \'' . s($property) .'\' requested.');
}
$methodname = 'get_' . $property;
if (method_exists($this, $methodname)) {
return $this->$methodname();
}
return $this->raw_get($property);
}
|
php
|
final public function get($property) {
if (!static::has_property($property)) {
throw new coding_exception('Unexpected property \'' . s($property) .'\' requested.');
}
$methodname = 'get_' . $property;
if (method_exists($this, $methodname)) {
return $this->$methodname();
}
return $this->raw_get($property);
}
|
[
"final",
"public",
"function",
"get",
"(",
"$",
"property",
")",
"{",
"if",
"(",
"!",
"static",
"::",
"has_property",
"(",
"$",
"property",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Unexpected property \\''",
".",
"s",
"(",
"$",
"property",
")",
".",
"'\\' requested.'",
")",
";",
"}",
"$",
"methodname",
"=",
"'get_'",
".",
"$",
"property",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"methodname",
")",
")",
"{",
"return",
"$",
"this",
"->",
"$",
"methodname",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"raw_get",
"(",
"$",
"property",
")",
";",
"}"
] |
Data getter.
This is the main getter for all the properties. Developers can implement their own getters (get_propertyname)
and they will be called by this function. Custom getters can use raw_get to get the raw value.
Internally this is not used by {@link self::to_record()} or
{@link self::from_record()} because the data is not expected to be validated or changed when reading/writing
raw records from the DB.
@param string $property The property name.
@return mixed
|
[
"Data",
"getter",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/persistent.php#L138-L147
|
220,349
|
moodle/moodle
|
lib/classes/persistent.php
|
persistent.raw_get
|
final protected function raw_get($property) {
if (!static::has_property($property)) {
throw new coding_exception('Unexpected property \'' . s($property) .'\' requested.');
}
if (!array_key_exists($property, $this->data) && !static::is_property_required($property)) {
$this->raw_set($property, static::get_property_default_value($property));
}
return isset($this->data[$property]) ? $this->data[$property] : null;
}
|
php
|
final protected function raw_get($property) {
if (!static::has_property($property)) {
throw new coding_exception('Unexpected property \'' . s($property) .'\' requested.');
}
if (!array_key_exists($property, $this->data) && !static::is_property_required($property)) {
$this->raw_set($property, static::get_property_default_value($property));
}
return isset($this->data[$property]) ? $this->data[$property] : null;
}
|
[
"final",
"protected",
"function",
"raw_get",
"(",
"$",
"property",
")",
"{",
"if",
"(",
"!",
"static",
"::",
"has_property",
"(",
"$",
"property",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Unexpected property \\''",
".",
"s",
"(",
"$",
"property",
")",
".",
"'\\' requested.'",
")",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"property",
",",
"$",
"this",
"->",
"data",
")",
"&&",
"!",
"static",
"::",
"is_property_required",
"(",
"$",
"property",
")",
")",
"{",
"$",
"this",
"->",
"raw_set",
"(",
"$",
"property",
",",
"static",
"::",
"get_property_default_value",
"(",
"$",
"property",
")",
")",
";",
"}",
"return",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"property",
"]",
")",
"?",
"$",
"this",
"->",
"data",
"[",
"$",
"property",
"]",
":",
"null",
";",
"}"
] |
Internal Data getter.
This is the main getter for all the properties. Developers can implement their own getters
but they should be calling {@link self::get()} in order to retrieve the value. Essentially
the getters defined by the developers would only ever be used as helper methods and will not
be called internally at this stage. In other words, do not expect {@link self::to_record()} or
{@link self::from_record()} to use them.
This is protected because it is only for raw low level access to the data fields.
Note this function is named raw_get and not get_raw to avoid naming clashes with a property named raw.
@param string $property The property name.
@return mixed
|
[
"Internal",
"Data",
"getter",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/persistent.php#L164-L172
|
220,350
|
moodle/moodle
|
lib/classes/persistent.php
|
persistent.properties_definition
|
final public static function properties_definition() {
global $CFG;
static $def = null;
if ($def !== null) {
return $def;
}
$def = static::define_properties();
$def['id'] = array(
'default' => 0,
'type' => PARAM_INT,
);
$def['timecreated'] = array(
'default' => 0,
'type' => PARAM_INT,
);
$def['timemodified'] = array(
'default' => 0,
'type' => PARAM_INT
);
$def['usermodified'] = array(
'default' => 0,
'type' => PARAM_INT
);
// List of reserved property names. Mostly because we have methods (getters/setters) which would confict with them.
// Think about backwards compability before adding new ones here!
$reserved = array('errors', 'formatted_properties', 'records', 'records_select', 'property_default_value',
'property_error_message', 'sql_fields');
foreach ($def as $property => $definition) {
// Ensures that the null property is always set.
if (!array_key_exists('null', $definition)) {
$def[$property]['null'] = NULL_NOT_ALLOWED;
}
// Warn the developers when they are doing something wrong.
if ($CFG->debugdeveloper) {
if (!array_key_exists('type', $definition)) {
throw new coding_exception('Missing type for: ' . $property);
} else if (isset($definition['message']) && !($definition['message'] instanceof lang_string)) {
throw new coding_exception('Invalid error message for: ' . $property);
} else if (in_array($property, $reserved)) {
throw new coding_exception('This property cannot be defined: ' . $property);
}
}
}
return $def;
}
|
php
|
final public static function properties_definition() {
global $CFG;
static $def = null;
if ($def !== null) {
return $def;
}
$def = static::define_properties();
$def['id'] = array(
'default' => 0,
'type' => PARAM_INT,
);
$def['timecreated'] = array(
'default' => 0,
'type' => PARAM_INT,
);
$def['timemodified'] = array(
'default' => 0,
'type' => PARAM_INT
);
$def['usermodified'] = array(
'default' => 0,
'type' => PARAM_INT
);
// List of reserved property names. Mostly because we have methods (getters/setters) which would confict with them.
// Think about backwards compability before adding new ones here!
$reserved = array('errors', 'formatted_properties', 'records', 'records_select', 'property_default_value',
'property_error_message', 'sql_fields');
foreach ($def as $property => $definition) {
// Ensures that the null property is always set.
if (!array_key_exists('null', $definition)) {
$def[$property]['null'] = NULL_NOT_ALLOWED;
}
// Warn the developers when they are doing something wrong.
if ($CFG->debugdeveloper) {
if (!array_key_exists('type', $definition)) {
throw new coding_exception('Missing type for: ' . $property);
} else if (isset($definition['message']) && !($definition['message'] instanceof lang_string)) {
throw new coding_exception('Invalid error message for: ' . $property);
} else if (in_array($property, $reserved)) {
throw new coding_exception('This property cannot be defined: ' . $property);
}
}
}
return $def;
}
|
[
"final",
"public",
"static",
"function",
"properties_definition",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"static",
"$",
"def",
"=",
"null",
";",
"if",
"(",
"$",
"def",
"!==",
"null",
")",
"{",
"return",
"$",
"def",
";",
"}",
"$",
"def",
"=",
"static",
"::",
"define_properties",
"(",
")",
";",
"$",
"def",
"[",
"'id'",
"]",
"=",
"array",
"(",
"'default'",
"=>",
"0",
",",
"'type'",
"=>",
"PARAM_INT",
",",
")",
";",
"$",
"def",
"[",
"'timecreated'",
"]",
"=",
"array",
"(",
"'default'",
"=>",
"0",
",",
"'type'",
"=>",
"PARAM_INT",
",",
")",
";",
"$",
"def",
"[",
"'timemodified'",
"]",
"=",
"array",
"(",
"'default'",
"=>",
"0",
",",
"'type'",
"=>",
"PARAM_INT",
")",
";",
"$",
"def",
"[",
"'usermodified'",
"]",
"=",
"array",
"(",
"'default'",
"=>",
"0",
",",
"'type'",
"=>",
"PARAM_INT",
")",
";",
"// List of reserved property names. Mostly because we have methods (getters/setters) which would confict with them.",
"// Think about backwards compability before adding new ones here!",
"$",
"reserved",
"=",
"array",
"(",
"'errors'",
",",
"'formatted_properties'",
",",
"'records'",
",",
"'records_select'",
",",
"'property_default_value'",
",",
"'property_error_message'",
",",
"'sql_fields'",
")",
";",
"foreach",
"(",
"$",
"def",
"as",
"$",
"property",
"=>",
"$",
"definition",
")",
"{",
"// Ensures that the null property is always set.",
"if",
"(",
"!",
"array_key_exists",
"(",
"'null'",
",",
"$",
"definition",
")",
")",
"{",
"$",
"def",
"[",
"$",
"property",
"]",
"[",
"'null'",
"]",
"=",
"NULL_NOT_ALLOWED",
";",
"}",
"// Warn the developers when they are doing something wrong.",
"if",
"(",
"$",
"CFG",
"->",
"debugdeveloper",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"'type'",
",",
"$",
"definition",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Missing type for: '",
".",
"$",
"property",
")",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"definition",
"[",
"'message'",
"]",
")",
"&&",
"!",
"(",
"$",
"definition",
"[",
"'message'",
"]",
"instanceof",
"lang_string",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Invalid error message for: '",
".",
"$",
"property",
")",
";",
"}",
"else",
"if",
"(",
"in_array",
"(",
"$",
"property",
",",
"$",
"reserved",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'This property cannot be defined: '",
".",
"$",
"property",
")",
";",
"}",
"}",
"}",
"return",
"$",
"def",
";",
"}"
] |
Get the properties definition of this model..
@return array
|
[
"Get",
"the",
"properties",
"definition",
"of",
"this",
"model",
".."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/persistent.php#L246-L300
|
220,351
|
moodle/moodle
|
lib/classes/persistent.php
|
persistent.get_formatted_properties
|
final public static function get_formatted_properties() {
$properties = static::properties_definition();
$formatted = array();
foreach ($properties as $property => $definition) {
$propertyformat = $property . 'format';
if (($definition['type'] == PARAM_RAW || $definition['type'] == PARAM_CLEANHTML)
&& array_key_exists($propertyformat, $properties)
&& $properties[$propertyformat]['type'] == PARAM_INT) {
$formatted[$property] = $propertyformat;
}
}
return $formatted;
}
|
php
|
final public static function get_formatted_properties() {
$properties = static::properties_definition();
$formatted = array();
foreach ($properties as $property => $definition) {
$propertyformat = $property . 'format';
if (($definition['type'] == PARAM_RAW || $definition['type'] == PARAM_CLEANHTML)
&& array_key_exists($propertyformat, $properties)
&& $properties[$propertyformat]['type'] == PARAM_INT) {
$formatted[$property] = $propertyformat;
}
}
return $formatted;
}
|
[
"final",
"public",
"static",
"function",
"get_formatted_properties",
"(",
")",
"{",
"$",
"properties",
"=",
"static",
"::",
"properties_definition",
"(",
")",
";",
"$",
"formatted",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"property",
"=>",
"$",
"definition",
")",
"{",
"$",
"propertyformat",
"=",
"$",
"property",
".",
"'format'",
";",
"if",
"(",
"(",
"$",
"definition",
"[",
"'type'",
"]",
"==",
"PARAM_RAW",
"||",
"$",
"definition",
"[",
"'type'",
"]",
"==",
"PARAM_CLEANHTML",
")",
"&&",
"array_key_exists",
"(",
"$",
"propertyformat",
",",
"$",
"properties",
")",
"&&",
"$",
"properties",
"[",
"$",
"propertyformat",
"]",
"[",
"'type'",
"]",
"==",
"PARAM_INT",
")",
"{",
"$",
"formatted",
"[",
"$",
"property",
"]",
"=",
"$",
"propertyformat",
";",
"}",
"}",
"return",
"$",
"formatted",
";",
"}"
] |
Gets all the formatted properties.
Formatted properties are properties which have a format associated with them.
@return array Keys are property names, values are property format names.
|
[
"Gets",
"all",
"the",
"formatted",
"properties",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/persistent.php#L309-L323
|
220,352
|
moodle/moodle
|
lib/classes/persistent.php
|
persistent.get_property_default_value
|
final protected static function get_property_default_value($property) {
$properties = static::properties_definition();
if (!isset($properties[$property]['default'])) {
return null;
}
$value = $properties[$property]['default'];
if ($value instanceof \Closure) {
return $value();
}
return $value;
}
|
php
|
final protected static function get_property_default_value($property) {
$properties = static::properties_definition();
if (!isset($properties[$property]['default'])) {
return null;
}
$value = $properties[$property]['default'];
if ($value instanceof \Closure) {
return $value();
}
return $value;
}
|
[
"final",
"protected",
"static",
"function",
"get_property_default_value",
"(",
"$",
"property",
")",
"{",
"$",
"properties",
"=",
"static",
"::",
"properties_definition",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"properties",
"[",
"$",
"property",
"]",
"[",
"'default'",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"value",
"=",
"$",
"properties",
"[",
"$",
"property",
"]",
"[",
"'default'",
"]",
";",
"if",
"(",
"$",
"value",
"instanceof",
"\\",
"Closure",
")",
"{",
"return",
"$",
"value",
"(",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] |
Gets the default value for a property.
This assumes that the property exists.
@param string $property The property name.
@return mixed
|
[
"Gets",
"the",
"default",
"value",
"for",
"a",
"property",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/persistent.php#L333-L343
|
220,353
|
moodle/moodle
|
lib/classes/persistent.php
|
persistent.get_property_error_message
|
final protected static function get_property_error_message($property) {
$properties = static::properties_definition();
if (!isset($properties[$property]['message'])) {
return new lang_string('invaliddata', 'error');
}
return $properties[$property]['message'];
}
|
php
|
final protected static function get_property_error_message($property) {
$properties = static::properties_definition();
if (!isset($properties[$property]['message'])) {
return new lang_string('invaliddata', 'error');
}
return $properties[$property]['message'];
}
|
[
"final",
"protected",
"static",
"function",
"get_property_error_message",
"(",
"$",
"property",
")",
"{",
"$",
"properties",
"=",
"static",
"::",
"properties_definition",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"properties",
"[",
"$",
"property",
"]",
"[",
"'message'",
"]",
")",
")",
"{",
"return",
"new",
"lang_string",
"(",
"'invaliddata'",
",",
"'error'",
")",
";",
"}",
"return",
"$",
"properties",
"[",
"$",
"property",
"]",
"[",
"'message'",
"]",
";",
"}"
] |
Gets the error message for a property.
This assumes that the property exists.
@param string $property The property name.
@return lang_string
|
[
"Gets",
"the",
"error",
"message",
"for",
"a",
"property",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/persistent.php#L353-L359
|
220,354
|
moodle/moodle
|
lib/classes/persistent.php
|
persistent.from_record
|
final public function from_record(stdClass $record) {
$record = (array) $record;
foreach ($record as $property => $value) {
$this->raw_set($property, $value);
}
return $this;
}
|
php
|
final public function from_record(stdClass $record) {
$record = (array) $record;
foreach ($record as $property => $value) {
$this->raw_set($property, $value);
}
return $this;
}
|
[
"final",
"public",
"function",
"from_record",
"(",
"stdClass",
"$",
"record",
")",
"{",
"$",
"record",
"=",
"(",
"array",
")",
"$",
"record",
";",
"foreach",
"(",
"$",
"record",
"as",
"$",
"property",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"raw_set",
"(",
"$",
"property",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Populate this class with data from a DB record.
Note that this does not use any custom setter because the data here is intended to
represent what is stored in the database.
@param \stdClass $record A DB record.
@return persistent
|
[
"Populate",
"this",
"class",
"with",
"data",
"from",
"a",
"DB",
"record",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/persistent.php#L394-L400
|
220,355
|
moodle/moodle
|
lib/classes/persistent.php
|
persistent.to_record
|
final public function to_record() {
$data = new stdClass();
$properties = static::properties_definition();
foreach ($properties as $property => $definition) {
$data->$property = $this->raw_get($property);
}
return $data;
}
|
php
|
final public function to_record() {
$data = new stdClass();
$properties = static::properties_definition();
foreach ($properties as $property => $definition) {
$data->$property = $this->raw_get($property);
}
return $data;
}
|
[
"final",
"public",
"function",
"to_record",
"(",
")",
"{",
"$",
"data",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"properties",
"=",
"static",
"::",
"properties_definition",
"(",
")",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"property",
"=>",
"$",
"definition",
")",
"{",
"$",
"data",
"->",
"$",
"property",
"=",
"$",
"this",
"->",
"raw_get",
"(",
"$",
"property",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] |
Create a DB record from this class.
Note that this does not use any custom getter because the data here is intended to
represent what is stored in the database.
@return \stdClass
|
[
"Create",
"a",
"DB",
"record",
"from",
"this",
"class",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/persistent.php#L410-L417
|
220,356
|
moodle/moodle
|
lib/classes/persistent.php
|
persistent.read
|
final public function read() {
global $DB;
if ($this->get('id') <= 0) {
throw new coding_exception('id is required to load');
}
$record = $DB->get_record(static::TABLE, array('id' => $this->get('id')), '*', MUST_EXIST);
$this->from_record($record);
// Validate the data as it comes from the database.
$this->validated = true;
return $this;
}
|
php
|
final public function read() {
global $DB;
if ($this->get('id') <= 0) {
throw new coding_exception('id is required to load');
}
$record = $DB->get_record(static::TABLE, array('id' => $this->get('id')), '*', MUST_EXIST);
$this->from_record($record);
// Validate the data as it comes from the database.
$this->validated = true;
return $this;
}
|
[
"final",
"public",
"function",
"read",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
"<=",
"0",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'id is required to load'",
")",
";",
"}",
"$",
"record",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"static",
"::",
"TABLE",
",",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
")",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"$",
"this",
"->",
"from_record",
"(",
"$",
"record",
")",
";",
"// Validate the data as it comes from the database.",
"$",
"this",
"->",
"validated",
"=",
"true",
";",
"return",
"$",
"this",
";",
"}"
] |
Load the data from the DB.
@return persistent
|
[
"Load",
"the",
"data",
"from",
"the",
"DB",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/persistent.php#L424-L437
|
220,357
|
moodle/moodle
|
lib/classes/persistent.php
|
persistent.create
|
final public function create() {
global $DB, $USER;
if ($this->raw_get('id')) {
// The validation methods rely on the ID to know if we're updating or not, the ID should be
// falsy whenever we are creating an object.
throw new coding_exception('Cannot create an object that has an ID defined.');
}
if (!$this->is_valid()) {
throw new invalid_persistent_exception($this->get_errors());
}
// Before create hook.
$this->before_create();
// We can safely set those values bypassing the validation because we know what we're doing.
$now = time();
$this->raw_set('timecreated', $now);
$this->raw_set('timemodified', $now);
$this->raw_set('usermodified', $USER->id);
$record = $this->to_record();
unset($record->id);
$id = $DB->insert_record(static::TABLE, $record);
$this->raw_set('id', $id);
// We ensure that this is flagged as validated.
$this->validated = true;
// After create hook.
$this->after_create();
return $this;
}
|
php
|
final public function create() {
global $DB, $USER;
if ($this->raw_get('id')) {
// The validation methods rely on the ID to know if we're updating or not, the ID should be
// falsy whenever we are creating an object.
throw new coding_exception('Cannot create an object that has an ID defined.');
}
if (!$this->is_valid()) {
throw new invalid_persistent_exception($this->get_errors());
}
// Before create hook.
$this->before_create();
// We can safely set those values bypassing the validation because we know what we're doing.
$now = time();
$this->raw_set('timecreated', $now);
$this->raw_set('timemodified', $now);
$this->raw_set('usermodified', $USER->id);
$record = $this->to_record();
unset($record->id);
$id = $DB->insert_record(static::TABLE, $record);
$this->raw_set('id', $id);
// We ensure that this is flagged as validated.
$this->validated = true;
// After create hook.
$this->after_create();
return $this;
}
|
[
"final",
"public",
"function",
"create",
"(",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"USER",
";",
"if",
"(",
"$",
"this",
"->",
"raw_get",
"(",
"'id'",
")",
")",
"{",
"// The validation methods rely on the ID to know if we're updating or not, the ID should be",
"// falsy whenever we are creating an object.",
"throw",
"new",
"coding_exception",
"(",
"'Cannot create an object that has an ID defined.'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"is_valid",
"(",
")",
")",
"{",
"throw",
"new",
"invalid_persistent_exception",
"(",
"$",
"this",
"->",
"get_errors",
"(",
")",
")",
";",
"}",
"// Before create hook.",
"$",
"this",
"->",
"before_create",
"(",
")",
";",
"// We can safely set those values bypassing the validation because we know what we're doing.",
"$",
"now",
"=",
"time",
"(",
")",
";",
"$",
"this",
"->",
"raw_set",
"(",
"'timecreated'",
",",
"$",
"now",
")",
";",
"$",
"this",
"->",
"raw_set",
"(",
"'timemodified'",
",",
"$",
"now",
")",
";",
"$",
"this",
"->",
"raw_set",
"(",
"'usermodified'",
",",
"$",
"USER",
"->",
"id",
")",
";",
"$",
"record",
"=",
"$",
"this",
"->",
"to_record",
"(",
")",
";",
"unset",
"(",
"$",
"record",
"->",
"id",
")",
";",
"$",
"id",
"=",
"$",
"DB",
"->",
"insert_record",
"(",
"static",
"::",
"TABLE",
",",
"$",
"record",
")",
";",
"$",
"this",
"->",
"raw_set",
"(",
"'id'",
",",
"$",
"id",
")",
";",
"// We ensure that this is flagged as validated.",
"$",
"this",
"->",
"validated",
"=",
"true",
";",
"// After create hook.",
"$",
"this",
"->",
"after_create",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Insert a record in the DB.
@return persistent
|
[
"Insert",
"a",
"record",
"in",
"the",
"DB",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/persistent.php#L457-L492
|
220,358
|
moodle/moodle
|
lib/classes/persistent.php
|
persistent.update
|
final public function update() {
global $DB, $USER;
if ($this->raw_get('id') <= 0) {
throw new coding_exception('id is required to update');
} else if (!$this->is_valid()) {
throw new invalid_persistent_exception($this->get_errors());
}
// Before update hook.
$this->before_update();
// We can safely set those values after the validation because we know what we're doing.
$this->raw_set('timemodified', time());
$this->raw_set('usermodified', $USER->id);
$record = $this->to_record();
unset($record->timecreated);
$record = (array) $record;
// Save the record.
$result = $DB->update_record(static::TABLE, $record);
// We ensure that this is flagged as validated.
$this->validated = true;
// After update hook.
$this->after_update($result);
return $result;
}
|
php
|
final public function update() {
global $DB, $USER;
if ($this->raw_get('id') <= 0) {
throw new coding_exception('id is required to update');
} else if (!$this->is_valid()) {
throw new invalid_persistent_exception($this->get_errors());
}
// Before update hook.
$this->before_update();
// We can safely set those values after the validation because we know what we're doing.
$this->raw_set('timemodified', time());
$this->raw_set('usermodified', $USER->id);
$record = $this->to_record();
unset($record->timecreated);
$record = (array) $record;
// Save the record.
$result = $DB->update_record(static::TABLE, $record);
// We ensure that this is flagged as validated.
$this->validated = true;
// After update hook.
$this->after_update($result);
return $result;
}
|
[
"final",
"public",
"function",
"update",
"(",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"USER",
";",
"if",
"(",
"$",
"this",
"->",
"raw_get",
"(",
"'id'",
")",
"<=",
"0",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'id is required to update'",
")",
";",
"}",
"else",
"if",
"(",
"!",
"$",
"this",
"->",
"is_valid",
"(",
")",
")",
"{",
"throw",
"new",
"invalid_persistent_exception",
"(",
"$",
"this",
"->",
"get_errors",
"(",
")",
")",
";",
"}",
"// Before update hook.",
"$",
"this",
"->",
"before_update",
"(",
")",
";",
"// We can safely set those values after the validation because we know what we're doing.",
"$",
"this",
"->",
"raw_set",
"(",
"'timemodified'",
",",
"time",
"(",
")",
")",
";",
"$",
"this",
"->",
"raw_set",
"(",
"'usermodified'",
",",
"$",
"USER",
"->",
"id",
")",
";",
"$",
"record",
"=",
"$",
"this",
"->",
"to_record",
"(",
")",
";",
"unset",
"(",
"$",
"record",
"->",
"timecreated",
")",
";",
"$",
"record",
"=",
"(",
"array",
")",
"$",
"record",
";",
"// Save the record.",
"$",
"result",
"=",
"$",
"DB",
"->",
"update_record",
"(",
"static",
"::",
"TABLE",
",",
"$",
"record",
")",
";",
"// We ensure that this is flagged as validated.",
"$",
"this",
"->",
"validated",
"=",
"true",
";",
"// After update hook.",
"$",
"this",
"->",
"after_update",
"(",
"$",
"result",
")",
";",
"return",
"$",
"result",
";",
"}"
] |
Update the existing record in the DB.
@return bool True on success.
|
[
"Update",
"the",
"existing",
"record",
"in",
"the",
"DB",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/persistent.php#L522-L552
|
220,359
|
moodle/moodle
|
lib/classes/persistent.php
|
persistent.delete
|
final public function delete() {
global $DB;
if ($this->raw_get('id') <= 0) {
throw new coding_exception('id is required to delete');
}
// Hook before delete.
$this->before_delete();
$result = $DB->delete_records(static::TABLE, array('id' => $this->raw_get('id')));
// Hook after delete.
$this->after_delete($result);
// Reset the ID to avoid any confusion, this also invalidates the model's data.
if ($result) {
$this->raw_set('id', 0);
}
return $result;
}
|
php
|
final public function delete() {
global $DB;
if ($this->raw_get('id') <= 0) {
throw new coding_exception('id is required to delete');
}
// Hook before delete.
$this->before_delete();
$result = $DB->delete_records(static::TABLE, array('id' => $this->raw_get('id')));
// Hook after delete.
$this->after_delete($result);
// Reset the ID to avoid any confusion, this also invalidates the model's data.
if ($result) {
$this->raw_set('id', 0);
}
return $result;
}
|
[
"final",
"public",
"function",
"delete",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"$",
"this",
"->",
"raw_get",
"(",
"'id'",
")",
"<=",
"0",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'id is required to delete'",
")",
";",
"}",
"// Hook before delete.",
"$",
"this",
"->",
"before_delete",
"(",
")",
";",
"$",
"result",
"=",
"$",
"DB",
"->",
"delete_records",
"(",
"static",
"::",
"TABLE",
",",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"raw_get",
"(",
"'id'",
")",
")",
")",
";",
"// Hook after delete.",
"$",
"this",
"->",
"after_delete",
"(",
"$",
"result",
")",
";",
"// Reset the ID to avoid any confusion, this also invalidates the model's data.",
"if",
"(",
"$",
"result",
")",
"{",
"$",
"this",
"->",
"raw_set",
"(",
"'id'",
",",
"0",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Delete an entry from the database.
@return bool True on success.
|
[
"Delete",
"an",
"entry",
"from",
"the",
"database",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/persistent.php#L596-L617
|
220,360
|
moodle/moodle
|
lib/classes/persistent.php
|
persistent.validate
|
final public function validate() {
global $CFG;
// Before validate hook.
$this->before_validate();
// If this object has not been validated yet.
if ($this->validated !== true) {
$errors = array();
$properties = static::properties_definition();
foreach ($properties as $property => $definition) {
// Get the data, bypassing the potential custom getter which could alter the data.
$value = $this->raw_get($property);
// Check if the property is required.
if ($value === null && static::is_property_required($property)) {
$errors[$property] = new lang_string('requiredelement', 'form');
continue;
}
// Check that type of value is respected.
try {
if ($definition['type'] === PARAM_BOOL && $value === false) {
// Validate_param() does not like false with PARAM_BOOL, better to convert it to int.
$value = 0;
}
if ($definition['type'] === PARAM_CLEANHTML) {
// We silently clean for this type. It may introduce changes even to valid data.
$value = clean_param($value, PARAM_CLEANHTML);
}
validate_param($value, $definition['type'], $definition['null']);
} catch (invalid_parameter_exception $e) {
$errors[$property] = static::get_property_error_message($property);
continue;
}
// Check that the value is part of a list of allowed values.
if (isset($definition['choices']) && !in_array($value, $definition['choices'])) {
$errors[$property] = static::get_property_error_message($property);
continue;
}
// Call custom validation method.
$method = 'validate_' . $property;
if (method_exists($this, $method)) {
// Warn the developers when they are doing something wrong.
if ($CFG->debugdeveloper) {
$reflection = new ReflectionMethod($this, $method);
if (!$reflection->isProtected()) {
throw new coding_exception('The method ' . get_class($this) . '::'. $method . ' should be protected.');
}
}
$valid = $this->{$method}($value);
if ($valid !== true) {
if (!($valid instanceof lang_string)) {
throw new coding_exception('Unexpected error message.');
}
$errors[$property] = $valid;
continue;
}
}
}
$this->validated = true;
$this->errors = $errors;
}
return empty($this->errors) ? true : $this->errors;
}
|
php
|
final public function validate() {
global $CFG;
// Before validate hook.
$this->before_validate();
// If this object has not been validated yet.
if ($this->validated !== true) {
$errors = array();
$properties = static::properties_definition();
foreach ($properties as $property => $definition) {
// Get the data, bypassing the potential custom getter which could alter the data.
$value = $this->raw_get($property);
// Check if the property is required.
if ($value === null && static::is_property_required($property)) {
$errors[$property] = new lang_string('requiredelement', 'form');
continue;
}
// Check that type of value is respected.
try {
if ($definition['type'] === PARAM_BOOL && $value === false) {
// Validate_param() does not like false with PARAM_BOOL, better to convert it to int.
$value = 0;
}
if ($definition['type'] === PARAM_CLEANHTML) {
// We silently clean for this type. It may introduce changes even to valid data.
$value = clean_param($value, PARAM_CLEANHTML);
}
validate_param($value, $definition['type'], $definition['null']);
} catch (invalid_parameter_exception $e) {
$errors[$property] = static::get_property_error_message($property);
continue;
}
// Check that the value is part of a list of allowed values.
if (isset($definition['choices']) && !in_array($value, $definition['choices'])) {
$errors[$property] = static::get_property_error_message($property);
continue;
}
// Call custom validation method.
$method = 'validate_' . $property;
if (method_exists($this, $method)) {
// Warn the developers when they are doing something wrong.
if ($CFG->debugdeveloper) {
$reflection = new ReflectionMethod($this, $method);
if (!$reflection->isProtected()) {
throw new coding_exception('The method ' . get_class($this) . '::'. $method . ' should be protected.');
}
}
$valid = $this->{$method}($value);
if ($valid !== true) {
if (!($valid instanceof lang_string)) {
throw new coding_exception('Unexpected error message.');
}
$errors[$property] = $valid;
continue;
}
}
}
$this->validated = true;
$this->errors = $errors;
}
return empty($this->errors) ? true : $this->errors;
}
|
[
"final",
"public",
"function",
"validate",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"// Before validate hook.",
"$",
"this",
"->",
"before_validate",
"(",
")",
";",
"// If this object has not been validated yet.",
"if",
"(",
"$",
"this",
"->",
"validated",
"!==",
"true",
")",
"{",
"$",
"errors",
"=",
"array",
"(",
")",
";",
"$",
"properties",
"=",
"static",
"::",
"properties_definition",
"(",
")",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"property",
"=>",
"$",
"definition",
")",
"{",
"// Get the data, bypassing the potential custom getter which could alter the data.",
"$",
"value",
"=",
"$",
"this",
"->",
"raw_get",
"(",
"$",
"property",
")",
";",
"// Check if the property is required.",
"if",
"(",
"$",
"value",
"===",
"null",
"&&",
"static",
"::",
"is_property_required",
"(",
"$",
"property",
")",
")",
"{",
"$",
"errors",
"[",
"$",
"property",
"]",
"=",
"new",
"lang_string",
"(",
"'requiredelement'",
",",
"'form'",
")",
";",
"continue",
";",
"}",
"// Check that type of value is respected.",
"try",
"{",
"if",
"(",
"$",
"definition",
"[",
"'type'",
"]",
"===",
"PARAM_BOOL",
"&&",
"$",
"value",
"===",
"false",
")",
"{",
"// Validate_param() does not like false with PARAM_BOOL, better to convert it to int.",
"$",
"value",
"=",
"0",
";",
"}",
"if",
"(",
"$",
"definition",
"[",
"'type'",
"]",
"===",
"PARAM_CLEANHTML",
")",
"{",
"// We silently clean for this type. It may introduce changes even to valid data.",
"$",
"value",
"=",
"clean_param",
"(",
"$",
"value",
",",
"PARAM_CLEANHTML",
")",
";",
"}",
"validate_param",
"(",
"$",
"value",
",",
"$",
"definition",
"[",
"'type'",
"]",
",",
"$",
"definition",
"[",
"'null'",
"]",
")",
";",
"}",
"catch",
"(",
"invalid_parameter_exception",
"$",
"e",
")",
"{",
"$",
"errors",
"[",
"$",
"property",
"]",
"=",
"static",
"::",
"get_property_error_message",
"(",
"$",
"property",
")",
";",
"continue",
";",
"}",
"// Check that the value is part of a list of allowed values.",
"if",
"(",
"isset",
"(",
"$",
"definition",
"[",
"'choices'",
"]",
")",
"&&",
"!",
"in_array",
"(",
"$",
"value",
",",
"$",
"definition",
"[",
"'choices'",
"]",
")",
")",
"{",
"$",
"errors",
"[",
"$",
"property",
"]",
"=",
"static",
"::",
"get_property_error_message",
"(",
"$",
"property",
")",
";",
"continue",
";",
"}",
"// Call custom validation method.",
"$",
"method",
"=",
"'validate_'",
".",
"$",
"property",
";",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"$",
"method",
")",
")",
"{",
"// Warn the developers when they are doing something wrong.",
"if",
"(",
"$",
"CFG",
"->",
"debugdeveloper",
")",
"{",
"$",
"reflection",
"=",
"new",
"ReflectionMethod",
"(",
"$",
"this",
",",
"$",
"method",
")",
";",
"if",
"(",
"!",
"$",
"reflection",
"->",
"isProtected",
"(",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'The method '",
".",
"get_class",
"(",
"$",
"this",
")",
".",
"'::'",
".",
"$",
"method",
".",
"' should be protected.'",
")",
";",
"}",
"}",
"$",
"valid",
"=",
"$",
"this",
"->",
"{",
"$",
"method",
"}",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"valid",
"!==",
"true",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"valid",
"instanceof",
"lang_string",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Unexpected error message.'",
")",
";",
"}",
"$",
"errors",
"[",
"$",
"property",
"]",
"=",
"$",
"valid",
";",
"continue",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"validated",
"=",
"true",
";",
"$",
"this",
"->",
"errors",
"=",
"$",
"errors",
";",
"}",
"return",
"empty",
"(",
"$",
"this",
"->",
"errors",
")",
"?",
"true",
":",
"$",
"this",
"->",
"errors",
";",
"}"
] |
Validates the data.
Developers can implement addition validation by defining a method as follows. Note that
the method MUST return a lang_string() when there is an error, and true when the data is valid.
protected function validate_propertyname($value) {
if ($value !== 'My expected value') {
return new lang_string('invaliddata', 'error');
}
return true
}
It is OK to use other properties in your custom validation methods when you need to, however note
they might not have been validated yet, so try not to rely on them too much.
Note that the validation methods should be protected. Validating just one field is not
recommended because of the possible dependencies between one field and another,also the
field ID can be used to check whether the object is being updated or created.
When validating foreign keys the persistent should only check that the associated model
exists. The validation methods should not be used to check for a change in that relationship.
The API method setting the attributes on the model should be responsible for that.
E.g. On a course model, the method validate_categoryid will check that the category exists.
However, if a course can never be moved outside of its category it would be up to the calling
code to ensure that the category ID will not be altered.
@return array|true Returns true when the validation passed, or an array of properties with errors.
|
[
"Validates",
"the",
"data",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/persistent.php#L672-L744
|
220,361
|
moodle/moodle
|
lib/classes/persistent.php
|
persistent.extract_record
|
public static function extract_record($row, $prefix = null) {
if ($prefix === null) {
$prefix = str_replace('_', '', static::TABLE) . '_';
}
$prefixlength = strlen($prefix);
$data = new stdClass();
foreach ($row as $property => $value) {
if (strpos($property, $prefix) === 0) {
$propertyname = substr($property, $prefixlength);
$data->$propertyname = $value;
}
}
return $data;
}
|
php
|
public static function extract_record($row, $prefix = null) {
if ($prefix === null) {
$prefix = str_replace('_', '', static::TABLE) . '_';
}
$prefixlength = strlen($prefix);
$data = new stdClass();
foreach ($row as $property => $value) {
if (strpos($property, $prefix) === 0) {
$propertyname = substr($property, $prefixlength);
$data->$propertyname = $value;
}
}
return $data;
}
|
[
"public",
"static",
"function",
"extract_record",
"(",
"$",
"row",
",",
"$",
"prefix",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"prefix",
"===",
"null",
")",
"{",
"$",
"prefix",
"=",
"str_replace",
"(",
"'_'",
",",
"''",
",",
"static",
"::",
"TABLE",
")",
".",
"'_'",
";",
"}",
"$",
"prefixlength",
"=",
"strlen",
"(",
"$",
"prefix",
")",
";",
"$",
"data",
"=",
"new",
"stdClass",
"(",
")",
";",
"foreach",
"(",
"$",
"row",
"as",
"$",
"property",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"property",
",",
"$",
"prefix",
")",
"===",
"0",
")",
"{",
"$",
"propertyname",
"=",
"substr",
"(",
"$",
"property",
",",
"$",
"prefixlength",
")",
";",
"$",
"data",
"->",
"$",
"propertyname",
"=",
"$",
"value",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] |
Extract a record from a row of data.
Most likely used in combination with {@link self::get_sql_fields()}. This method is
simple enough to be used by non-persistent classes, keep that in mind when modifying it.
e.g. persistent::extract_record($row, 'user'); should work.
@param stdClass $row The row of data.
@param string $prefix The prefix the data fields are prefixed with, defaults to the table name followed by underscore.
@return stdClass The extracted data.
|
[
"Extract",
"a",
"record",
"from",
"a",
"row",
"of",
"data",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/persistent.php#L777-L792
|
220,362
|
moodle/moodle
|
lib/classes/persistent.php
|
persistent.get_records
|
public static function get_records($filters = array(), $sort = '', $order = 'ASC', $skip = 0, $limit = 0) {
global $DB;
$orderby = '';
if (!empty($sort)) {
$orderby = $sort . ' ' . $order;
}
$records = $DB->get_records(static::TABLE, $filters, $orderby, '*', $skip, $limit);
$instances = array();
foreach ($records as $record) {
$newrecord = new static(0, $record);
array_push($instances, $newrecord);
}
return $instances;
}
|
php
|
public static function get_records($filters = array(), $sort = '', $order = 'ASC', $skip = 0, $limit = 0) {
global $DB;
$orderby = '';
if (!empty($sort)) {
$orderby = $sort . ' ' . $order;
}
$records = $DB->get_records(static::TABLE, $filters, $orderby, '*', $skip, $limit);
$instances = array();
foreach ($records as $record) {
$newrecord = new static(0, $record);
array_push($instances, $newrecord);
}
return $instances;
}
|
[
"public",
"static",
"function",
"get_records",
"(",
"$",
"filters",
"=",
"array",
"(",
")",
",",
"$",
"sort",
"=",
"''",
",",
"$",
"order",
"=",
"'ASC'",
",",
"$",
"skip",
"=",
"0",
",",
"$",
"limit",
"=",
"0",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"orderby",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"sort",
")",
")",
"{",
"$",
"orderby",
"=",
"$",
"sort",
".",
"' '",
".",
"$",
"order",
";",
"}",
"$",
"records",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"static",
"::",
"TABLE",
",",
"$",
"filters",
",",
"$",
"orderby",
",",
"'*'",
",",
"$",
"skip",
",",
"$",
"limit",
")",
";",
"$",
"instances",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"records",
"as",
"$",
"record",
")",
"{",
"$",
"newrecord",
"=",
"new",
"static",
"(",
"0",
",",
"$",
"record",
")",
";",
"array_push",
"(",
"$",
"instances",
",",
"$",
"newrecord",
")",
";",
"}",
"return",
"$",
"instances",
";",
"}"
] |
Load a list of records.
@param array $filters Filters to apply.
@param string $sort Field to sort by.
@param string $order Sort order.
@param int $skip Limitstart.
@param int $limit Number of rows to return.
@return \core\persistent[]
|
[
"Load",
"a",
"list",
"of",
"records",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/persistent.php#L805-L821
|
220,363
|
moodle/moodle
|
lib/classes/persistent.php
|
persistent.get_record
|
public static function get_record($filters = array()) {
global $DB;
$record = $DB->get_record(static::TABLE, $filters);
return $record ? new static(0, $record) : false;
}
|
php
|
public static function get_record($filters = array()) {
global $DB;
$record = $DB->get_record(static::TABLE, $filters);
return $record ? new static(0, $record) : false;
}
|
[
"public",
"static",
"function",
"get_record",
"(",
"$",
"filters",
"=",
"array",
"(",
")",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"record",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"static",
"::",
"TABLE",
",",
"$",
"filters",
")",
";",
"return",
"$",
"record",
"?",
"new",
"static",
"(",
"0",
",",
"$",
"record",
")",
":",
"false",
";",
"}"
] |
Load a single record.
@param array $filters Filters to apply.
@return false|\core\persistent
|
[
"Load",
"a",
"single",
"record",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/persistent.php#L829-L834
|
220,364
|
moodle/moodle
|
lib/classes/persistent.php
|
persistent.get_records_select
|
public static function get_records_select($select, $params = null, $sort = '', $fields = '*', $limitfrom = 0, $limitnum = 0) {
global $DB;
$records = $DB->get_records_select(static::TABLE, $select, $params, $sort, $fields, $limitfrom, $limitnum);
// We return class instances.
$instances = array();
foreach ($records as $key => $record) {
$instances[$key] = new static(0, $record);
}
return $instances;
}
|
php
|
public static function get_records_select($select, $params = null, $sort = '', $fields = '*', $limitfrom = 0, $limitnum = 0) {
global $DB;
$records = $DB->get_records_select(static::TABLE, $select, $params, $sort, $fields, $limitfrom, $limitnum);
// We return class instances.
$instances = array();
foreach ($records as $key => $record) {
$instances[$key] = new static(0, $record);
}
return $instances;
}
|
[
"public",
"static",
"function",
"get_records_select",
"(",
"$",
"select",
",",
"$",
"params",
"=",
"null",
",",
"$",
"sort",
"=",
"''",
",",
"$",
"fields",
"=",
"'*'",
",",
"$",
"limitfrom",
"=",
"0",
",",
"$",
"limitnum",
"=",
"0",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"records",
"=",
"$",
"DB",
"->",
"get_records_select",
"(",
"static",
"::",
"TABLE",
",",
"$",
"select",
",",
"$",
"params",
",",
"$",
"sort",
",",
"$",
"fields",
",",
"$",
"limitfrom",
",",
"$",
"limitnum",
")",
";",
"// We return class instances.",
"$",
"instances",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"records",
"as",
"$",
"key",
"=>",
"$",
"record",
")",
"{",
"$",
"instances",
"[",
"$",
"key",
"]",
"=",
"new",
"static",
"(",
"0",
",",
"$",
"record",
")",
";",
"}",
"return",
"$",
"instances",
";",
"}"
] |
Load a list of records based on a select query.
@param string $select
@param array $params
@param string $sort
@param string $fields
@param int $limitfrom
@param int $limitnum
@return \core\persistent[]
|
[
"Load",
"a",
"list",
"of",
"records",
"based",
"on",
"a",
"select",
"query",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/persistent.php#L847-L860
|
220,365
|
moodle/moodle
|
lib/classes/persistent.php
|
persistent.get_sql_fields
|
public static function get_sql_fields($alias, $prefix = null) {
global $CFG;
$fields = array();
if ($prefix === null) {
$prefix = str_replace('_', '', static::TABLE) . '_';
}
// Get the properties and move ID to the top.
$properties = static::properties_definition();
$id = $properties['id'];
unset($properties['id']);
$properties = array('id' => $id) + $properties;
foreach ($properties as $property => $definition) {
$as = $prefix . $property;
$fields[] = $alias . '.' . $property . ' AS ' . $as;
// Warn developers that the query will not always work.
if ($CFG->debugdeveloper && strlen($as) > 30) {
throw new coding_exception("The alias '$as' for column '$alias.$property' exceeds 30 characters" .
" and will therefore not work across all supported databases.");
}
}
return implode(', ', $fields);
}
|
php
|
public static function get_sql_fields($alias, $prefix = null) {
global $CFG;
$fields = array();
if ($prefix === null) {
$prefix = str_replace('_', '', static::TABLE) . '_';
}
// Get the properties and move ID to the top.
$properties = static::properties_definition();
$id = $properties['id'];
unset($properties['id']);
$properties = array('id' => $id) + $properties;
foreach ($properties as $property => $definition) {
$as = $prefix . $property;
$fields[] = $alias . '.' . $property . ' AS ' . $as;
// Warn developers that the query will not always work.
if ($CFG->debugdeveloper && strlen($as) > 30) {
throw new coding_exception("The alias '$as' for column '$alias.$property' exceeds 30 characters" .
" and will therefore not work across all supported databases.");
}
}
return implode(', ', $fields);
}
|
[
"public",
"static",
"function",
"get_sql_fields",
"(",
"$",
"alias",
",",
"$",
"prefix",
"=",
"null",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"fields",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"prefix",
"===",
"null",
")",
"{",
"$",
"prefix",
"=",
"str_replace",
"(",
"'_'",
",",
"''",
",",
"static",
"::",
"TABLE",
")",
".",
"'_'",
";",
"}",
"// Get the properties and move ID to the top.",
"$",
"properties",
"=",
"static",
"::",
"properties_definition",
"(",
")",
";",
"$",
"id",
"=",
"$",
"properties",
"[",
"'id'",
"]",
";",
"unset",
"(",
"$",
"properties",
"[",
"'id'",
"]",
")",
";",
"$",
"properties",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"id",
")",
"+",
"$",
"properties",
";",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"property",
"=>",
"$",
"definition",
")",
"{",
"$",
"as",
"=",
"$",
"prefix",
".",
"$",
"property",
";",
"$",
"fields",
"[",
"]",
"=",
"$",
"alias",
".",
"'.'",
".",
"$",
"property",
".",
"' AS '",
".",
"$",
"as",
";",
"// Warn developers that the query will not always work.",
"if",
"(",
"$",
"CFG",
"->",
"debugdeveloper",
"&&",
"strlen",
"(",
"$",
"as",
")",
">",
"30",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"\"The alias '$as' for column '$alias.$property' exceeds 30 characters\"",
".",
"\" and will therefore not work across all supported databases.\"",
")",
";",
"}",
"}",
"return",
"implode",
"(",
"', '",
",",
"$",
"fields",
")",
";",
"}"
] |
Return the list of fields for use in a SELECT clause.
Having the complete list of fields prefixed allows for multiple persistents to be fetched
in a single query. Use {@link self::extract_record()} to extract the records from the query result.
@param string $alias The alias used for the table.
@param string $prefix The prefix to use for each field, defaults to the table name followed by underscore.
@return string The SQL fragment.
|
[
"Return",
"the",
"list",
"of",
"fields",
"for",
"use",
"in",
"a",
"SELECT",
"clause",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/persistent.php#L872-L898
|
220,366
|
moodle/moodle
|
lib/classes/persistent.php
|
persistent.count_records_select
|
public static function count_records_select($select, $params = null) {
global $DB;
$count = $DB->count_records_select(static::TABLE, $select, $params);
return $count;
}
|
php
|
public static function count_records_select($select, $params = null) {
global $DB;
$count = $DB->count_records_select(static::TABLE, $select, $params);
return $count;
}
|
[
"public",
"static",
"function",
"count_records_select",
"(",
"$",
"select",
",",
"$",
"params",
"=",
"null",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"count",
"=",
"$",
"DB",
"->",
"count_records_select",
"(",
"static",
"::",
"TABLE",
",",
"$",
"select",
",",
"$",
"params",
")",
";",
"return",
"$",
"count",
";",
"}"
] |
Count a list of records.
@param string $select
@param array $params
@return int
|
[
"Count",
"a",
"list",
"of",
"records",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/persistent.php#L920-L925
|
220,367
|
moodle/moodle
|
lib/classes/persistent.php
|
persistent.record_exists_select
|
public static function record_exists_select($select, array $params = null) {
global $DB;
return $DB->record_exists_select(static::TABLE, $select, $params);
}
|
php
|
public static function record_exists_select($select, array $params = null) {
global $DB;
return $DB->record_exists_select(static::TABLE, $select, $params);
}
|
[
"public",
"static",
"function",
"record_exists_select",
"(",
"$",
"select",
",",
"array",
"$",
"params",
"=",
"null",
")",
"{",
"global",
"$",
"DB",
";",
"return",
"$",
"DB",
"->",
"record_exists_select",
"(",
"static",
"::",
"TABLE",
",",
"$",
"select",
",",
"$",
"params",
")",
";",
"}"
] |
Check if a records exists.
@param string $select
@param array $params
@return bool
|
[
"Check",
"if",
"a",
"records",
"exists",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/persistent.php#L945-L948
|
220,368
|
moodle/moodle
|
lib/filestorage/tgz_extractor.php
|
tgz_extractor.extract
|
public function extract(tgz_extractor_handler $handler, file_progress $progress = null) {
$this->mode = self::MODE_EXTRACT;
$this->extract_or_list($handler, $progress);
$results = $this->results;
unset($this->results);
return $results;
}
|
php
|
public function extract(tgz_extractor_handler $handler, file_progress $progress = null) {
$this->mode = self::MODE_EXTRACT;
$this->extract_or_list($handler, $progress);
$results = $this->results;
unset($this->results);
return $results;
}
|
[
"public",
"function",
"extract",
"(",
"tgz_extractor_handler",
"$",
"handler",
",",
"file_progress",
"$",
"progress",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"mode",
"=",
"self",
"::",
"MODE_EXTRACT",
";",
"$",
"this",
"->",
"extract_or_list",
"(",
"$",
"handler",
",",
"$",
"progress",
")",
";",
"$",
"results",
"=",
"$",
"this",
"->",
"results",
";",
"unset",
"(",
"$",
"this",
"->",
"results",
")",
";",
"return",
"$",
"results",
";",
"}"
] |
Extracts the archive.
@param tgz_extractor_handler $handler Will be called for extracted files
@param file_progress $progress Optional progress reporting
@return array Array from archive path => true of processed files
@throws moodle_exception If there is any error processing the archive
|
[
"Extracts",
"the",
"archive",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/tgz_extractor.php#L140-L146
|
220,369
|
moodle/moodle
|
lib/filestorage/tgz_extractor.php
|
tgz_extractor.process_header
|
protected function process_header($block, $handler) {
// If the block consists entirely of nulls, ignore it. (This happens
// twice at end of archive.)
if ($block === str_pad('', tgz_packer::TAR_BLOCK_SIZE, "\0")) {
return;
}
// struct header_posix_ustar {
// char name[100];
$name = rtrim(substr($block, 0, 100), "\0");
// char mode[8];
// char uid[8];
// char gid[8];
// char size[12];
$filesize = octdec(substr($block, 124, 11));
// char mtime[12];
$mtime = octdec(substr($block, 136, 11));
// char checksum[8];
// char typeflag[1];
$typeflag = substr($block, 156, 1);
// char linkname[100];
// char magic[6];
$magic = substr($block, 257, 6);
if ($magic !== "ustar\0" && $magic !== "ustar ") {
// There are two checks above; the first is the correct POSIX format
// and the second is for GNU tar default format.
throw new moodle_exception('errorprocessingarchive', '', '', null,
'Header does not have POSIX ustar magic string');
}
// char version[2];
// char uname[32];
// char gname[32];
// char devmajor[8];
// char devminor[8];
// char prefix[155];
$prefix = rtrim(substr($block, 345, 155), "\0");
// char pad[12];
// };
$archivepath = ltrim($prefix . '/' . $name, '/');
// For security, ensure there is no .. folder in the archivepath.
$archivepath = clean_param($archivepath, PARAM_PATH);
// Handle file depending on the type.
switch ($typeflag) {
case '1' :
case '2' :
case '3' :
case '4' :
case '6' :
case '7' :
// Ignore these special cases.
break;
case '5' :
// Directory.
if ($this->mode === self::MODE_LIST) {
$this->listresults[] = (object)array(
'original_pathname' => $archivepath,
'pathname' => $archivepath,
'mtime' => $mtime,
'is_directory' => true,
'size' => 0);
} else if ($handler->tgz_directory($archivepath, $mtime)) {
$this->results[$archivepath] = true;
}
break;
default:
// All other values treated as normal file.
$this->start_current_file($archivepath, $filesize, $mtime, $handler);
break;
}
}
|
php
|
protected function process_header($block, $handler) {
// If the block consists entirely of nulls, ignore it. (This happens
// twice at end of archive.)
if ($block === str_pad('', tgz_packer::TAR_BLOCK_SIZE, "\0")) {
return;
}
// struct header_posix_ustar {
// char name[100];
$name = rtrim(substr($block, 0, 100), "\0");
// char mode[8];
// char uid[8];
// char gid[8];
// char size[12];
$filesize = octdec(substr($block, 124, 11));
// char mtime[12];
$mtime = octdec(substr($block, 136, 11));
// char checksum[8];
// char typeflag[1];
$typeflag = substr($block, 156, 1);
// char linkname[100];
// char magic[6];
$magic = substr($block, 257, 6);
if ($magic !== "ustar\0" && $magic !== "ustar ") {
// There are two checks above; the first is the correct POSIX format
// and the second is for GNU tar default format.
throw new moodle_exception('errorprocessingarchive', '', '', null,
'Header does not have POSIX ustar magic string');
}
// char version[2];
// char uname[32];
// char gname[32];
// char devmajor[8];
// char devminor[8];
// char prefix[155];
$prefix = rtrim(substr($block, 345, 155), "\0");
// char pad[12];
// };
$archivepath = ltrim($prefix . '/' . $name, '/');
// For security, ensure there is no .. folder in the archivepath.
$archivepath = clean_param($archivepath, PARAM_PATH);
// Handle file depending on the type.
switch ($typeflag) {
case '1' :
case '2' :
case '3' :
case '4' :
case '6' :
case '7' :
// Ignore these special cases.
break;
case '5' :
// Directory.
if ($this->mode === self::MODE_LIST) {
$this->listresults[] = (object)array(
'original_pathname' => $archivepath,
'pathname' => $archivepath,
'mtime' => $mtime,
'is_directory' => true,
'size' => 0);
} else if ($handler->tgz_directory($archivepath, $mtime)) {
$this->results[$archivepath] = true;
}
break;
default:
// All other values treated as normal file.
$this->start_current_file($archivepath, $filesize, $mtime, $handler);
break;
}
}
|
[
"protected",
"function",
"process_header",
"(",
"$",
"block",
",",
"$",
"handler",
")",
"{",
"// If the block consists entirely of nulls, ignore it. (This happens",
"// twice at end of archive.)",
"if",
"(",
"$",
"block",
"===",
"str_pad",
"(",
"''",
",",
"tgz_packer",
"::",
"TAR_BLOCK_SIZE",
",",
"\"\\0\"",
")",
")",
"{",
"return",
";",
"}",
"// struct header_posix_ustar {",
"// char name[100];",
"$",
"name",
"=",
"rtrim",
"(",
"substr",
"(",
"$",
"block",
",",
"0",
",",
"100",
")",
",",
"\"\\0\"",
")",
";",
"// char mode[8];",
"// char uid[8];",
"// char gid[8];",
"// char size[12];",
"$",
"filesize",
"=",
"octdec",
"(",
"substr",
"(",
"$",
"block",
",",
"124",
",",
"11",
")",
")",
";",
"// char mtime[12];",
"$",
"mtime",
"=",
"octdec",
"(",
"substr",
"(",
"$",
"block",
",",
"136",
",",
"11",
")",
")",
";",
"// char checksum[8];",
"// char typeflag[1];",
"$",
"typeflag",
"=",
"substr",
"(",
"$",
"block",
",",
"156",
",",
"1",
")",
";",
"// char linkname[100];",
"// char magic[6];",
"$",
"magic",
"=",
"substr",
"(",
"$",
"block",
",",
"257",
",",
"6",
")",
";",
"if",
"(",
"$",
"magic",
"!==",
"\"ustar\\0\"",
"&&",
"$",
"magic",
"!==",
"\"ustar \"",
")",
"{",
"// There are two checks above; the first is the correct POSIX format",
"// and the second is for GNU tar default format.",
"throw",
"new",
"moodle_exception",
"(",
"'errorprocessingarchive'",
",",
"''",
",",
"''",
",",
"null",
",",
"'Header does not have POSIX ustar magic string'",
")",
";",
"}",
"// char version[2];",
"// char uname[32];",
"// char gname[32];",
"// char devmajor[8];",
"// char devminor[8];",
"// char prefix[155];",
"$",
"prefix",
"=",
"rtrim",
"(",
"substr",
"(",
"$",
"block",
",",
"345",
",",
"155",
")",
",",
"\"\\0\"",
")",
";",
"// char pad[12];",
"// };",
"$",
"archivepath",
"=",
"ltrim",
"(",
"$",
"prefix",
".",
"'/'",
".",
"$",
"name",
",",
"'/'",
")",
";",
"// For security, ensure there is no .. folder in the archivepath.",
"$",
"archivepath",
"=",
"clean_param",
"(",
"$",
"archivepath",
",",
"PARAM_PATH",
")",
";",
"// Handle file depending on the type.",
"switch",
"(",
"$",
"typeflag",
")",
"{",
"case",
"'1'",
":",
"case",
"'2'",
":",
"case",
"'3'",
":",
"case",
"'4'",
":",
"case",
"'6'",
":",
"case",
"'7'",
":",
"// Ignore these special cases.",
"break",
";",
"case",
"'5'",
":",
"// Directory.",
"if",
"(",
"$",
"this",
"->",
"mode",
"===",
"self",
"::",
"MODE_LIST",
")",
"{",
"$",
"this",
"->",
"listresults",
"[",
"]",
"=",
"(",
"object",
")",
"array",
"(",
"'original_pathname'",
"=>",
"$",
"archivepath",
",",
"'pathname'",
"=>",
"$",
"archivepath",
",",
"'mtime'",
"=>",
"$",
"mtime",
",",
"'is_directory'",
"=>",
"true",
",",
"'size'",
"=>",
"0",
")",
";",
"}",
"else",
"if",
"(",
"$",
"handler",
"->",
"tgz_directory",
"(",
"$",
"archivepath",
",",
"$",
"mtime",
")",
")",
"{",
"$",
"this",
"->",
"results",
"[",
"$",
"archivepath",
"]",
"=",
"true",
";",
"}",
"break",
";",
"default",
":",
"// All other values treated as normal file.",
"$",
"this",
"->",
"start_current_file",
"(",
"$",
"archivepath",
",",
"$",
"filesize",
",",
"$",
"mtime",
",",
"$",
"handler",
")",
";",
"break",
";",
"}",
"}"
] |
Process 512-byte header block.
@param string $block Tar block
@param tgz_extractor_handler $handler Will be called for extracted files
|
[
"Process",
"512",
"-",
"byte",
"header",
"block",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/tgz_extractor.php#L260-L340
|
220,370
|
moodle/moodle
|
lib/filestorage/tgz_extractor.php
|
tgz_extractor.process_file_block
|
protected function process_file_block($block, tgz_extractor_handler $handler = null) {
// Write block into buffer.
$blocksize = tgz_packer::TAR_BLOCK_SIZE;
if ($this->currentfileprocessed + tgz_packer::TAR_BLOCK_SIZE > $this->currentfilesize) {
// Partial block at end of file.
$blocksize = $this->currentfilesize - $this->currentfileprocessed;
$this->filebuffer .= substr($block, 0, $blocksize);
} else {
// Full-length block.
$this->filebuffer .= $block;
}
$this->filebufferlength += $blocksize;
$this->currentfileprocessed += $blocksize;
// Write block to file if necessary.
$eof = $this->currentfileprocessed == $this->currentfilesize;
if ($this->filebufferlength >= self::WRITE_BLOCK_SIZE || $eof) {
// Except when skipping the file, write it out.
if ($this->currentfile !== true) {
if (!fwrite($this->currentfp, $this->filebuffer)) {
throw new moodle_exception('errorprocessingarchive', '', '', null,
'Failed to write buffer to output file: ' . $this->currentfile);
}
}
$this->filebuffer = '';
$this->filebufferlength = 0;
}
// If file is finished, close it.
if ($eof) {
$this->close_current_file($handler);
}
}
|
php
|
protected function process_file_block($block, tgz_extractor_handler $handler = null) {
// Write block into buffer.
$blocksize = tgz_packer::TAR_BLOCK_SIZE;
if ($this->currentfileprocessed + tgz_packer::TAR_BLOCK_SIZE > $this->currentfilesize) {
// Partial block at end of file.
$blocksize = $this->currentfilesize - $this->currentfileprocessed;
$this->filebuffer .= substr($block, 0, $blocksize);
} else {
// Full-length block.
$this->filebuffer .= $block;
}
$this->filebufferlength += $blocksize;
$this->currentfileprocessed += $blocksize;
// Write block to file if necessary.
$eof = $this->currentfileprocessed == $this->currentfilesize;
if ($this->filebufferlength >= self::WRITE_BLOCK_SIZE || $eof) {
// Except when skipping the file, write it out.
if ($this->currentfile !== true) {
if (!fwrite($this->currentfp, $this->filebuffer)) {
throw new moodle_exception('errorprocessingarchive', '', '', null,
'Failed to write buffer to output file: ' . $this->currentfile);
}
}
$this->filebuffer = '';
$this->filebufferlength = 0;
}
// If file is finished, close it.
if ($eof) {
$this->close_current_file($handler);
}
}
|
[
"protected",
"function",
"process_file_block",
"(",
"$",
"block",
",",
"tgz_extractor_handler",
"$",
"handler",
"=",
"null",
")",
"{",
"// Write block into buffer.",
"$",
"blocksize",
"=",
"tgz_packer",
"::",
"TAR_BLOCK_SIZE",
";",
"if",
"(",
"$",
"this",
"->",
"currentfileprocessed",
"+",
"tgz_packer",
"::",
"TAR_BLOCK_SIZE",
">",
"$",
"this",
"->",
"currentfilesize",
")",
"{",
"// Partial block at end of file.",
"$",
"blocksize",
"=",
"$",
"this",
"->",
"currentfilesize",
"-",
"$",
"this",
"->",
"currentfileprocessed",
";",
"$",
"this",
"->",
"filebuffer",
".=",
"substr",
"(",
"$",
"block",
",",
"0",
",",
"$",
"blocksize",
")",
";",
"}",
"else",
"{",
"// Full-length block.",
"$",
"this",
"->",
"filebuffer",
".=",
"$",
"block",
";",
"}",
"$",
"this",
"->",
"filebufferlength",
"+=",
"$",
"blocksize",
";",
"$",
"this",
"->",
"currentfileprocessed",
"+=",
"$",
"blocksize",
";",
"// Write block to file if necessary.",
"$",
"eof",
"=",
"$",
"this",
"->",
"currentfileprocessed",
"==",
"$",
"this",
"->",
"currentfilesize",
";",
"if",
"(",
"$",
"this",
"->",
"filebufferlength",
">=",
"self",
"::",
"WRITE_BLOCK_SIZE",
"||",
"$",
"eof",
")",
"{",
"// Except when skipping the file, write it out.",
"if",
"(",
"$",
"this",
"->",
"currentfile",
"!==",
"true",
")",
"{",
"if",
"(",
"!",
"fwrite",
"(",
"$",
"this",
"->",
"currentfp",
",",
"$",
"this",
"->",
"filebuffer",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'errorprocessingarchive'",
",",
"''",
",",
"''",
",",
"null",
",",
"'Failed to write buffer to output file: '",
".",
"$",
"this",
"->",
"currentfile",
")",
";",
"}",
"}",
"$",
"this",
"->",
"filebuffer",
"=",
"''",
";",
"$",
"this",
"->",
"filebufferlength",
"=",
"0",
";",
"}",
"// If file is finished, close it.",
"if",
"(",
"$",
"eof",
")",
"{",
"$",
"this",
"->",
"close_current_file",
"(",
"$",
"handler",
")",
";",
"}",
"}"
] |
Processes one 512-byte block of an existing file.
@param string $block Data block
@param tgz_extractor_handler $handler Will be called for extracted files
|
[
"Processes",
"one",
"512",
"-",
"byte",
"block",
"of",
"an",
"existing",
"file",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/tgz_extractor.php#L348-L380
|
220,371
|
moodle/moodle
|
lib/filestorage/tgz_extractor.php
|
tgz_extractor.start_current_file
|
protected function start_current_file($archivepath, $filesize, $mtime,
tgz_extractor_handler $handler = null) {
global $CFG;
$this->currentarchivepath = $archivepath;
$this->currentmtime = $mtime;
$this->currentfilesize = $filesize;
$this->currentfileprocessed = 0;
if ($archivepath === tgz_packer::ARCHIVE_INDEX_FILE) {
// For index file, store in temp directory.
$tempfolder = $CFG->tempdir . '/core_files';
check_dir_exists($tempfolder);
$this->currentfile = tempnam($tempfolder, '.index');
} else {
if ($this->mode === self::MODE_LIST) {
// If listing, add to list.
$this->listresults[] = (object)array(
'original_pathname' => $archivepath,
'pathname' => $archivepath,
'mtime' => $mtime,
'is_directory' => false,
'size' => $filesize);
// Discard file.
$this->currentfile = true;
} else {
// For other files, ask handler for location.
$this->currentfile = $handler->tgz_start_file($archivepath);
if ($this->currentfile === null) {
// This indicates that we are discarding the current file.
$this->currentfile = true;
}
}
}
$this->filebuffer = '';
$this->filebufferlength = 0;
// Open file.
if ($this->currentfile !== true) {
$this->currentfp = fopen($this->currentfile, 'wb');
if (!$this->currentfp) {
throw new moodle_exception('errorprocessingarchive', '', '', null,
'Failed to open output file: ' . $this->currentfile);
}
} else {
$this->currentfp = null;
}
// If it has no size, close it right away.
if ($filesize == 0) {
$this->close_current_file($handler);
}
}
|
php
|
protected function start_current_file($archivepath, $filesize, $mtime,
tgz_extractor_handler $handler = null) {
global $CFG;
$this->currentarchivepath = $archivepath;
$this->currentmtime = $mtime;
$this->currentfilesize = $filesize;
$this->currentfileprocessed = 0;
if ($archivepath === tgz_packer::ARCHIVE_INDEX_FILE) {
// For index file, store in temp directory.
$tempfolder = $CFG->tempdir . '/core_files';
check_dir_exists($tempfolder);
$this->currentfile = tempnam($tempfolder, '.index');
} else {
if ($this->mode === self::MODE_LIST) {
// If listing, add to list.
$this->listresults[] = (object)array(
'original_pathname' => $archivepath,
'pathname' => $archivepath,
'mtime' => $mtime,
'is_directory' => false,
'size' => $filesize);
// Discard file.
$this->currentfile = true;
} else {
// For other files, ask handler for location.
$this->currentfile = $handler->tgz_start_file($archivepath);
if ($this->currentfile === null) {
// This indicates that we are discarding the current file.
$this->currentfile = true;
}
}
}
$this->filebuffer = '';
$this->filebufferlength = 0;
// Open file.
if ($this->currentfile !== true) {
$this->currentfp = fopen($this->currentfile, 'wb');
if (!$this->currentfp) {
throw new moodle_exception('errorprocessingarchive', '', '', null,
'Failed to open output file: ' . $this->currentfile);
}
} else {
$this->currentfp = null;
}
// If it has no size, close it right away.
if ($filesize == 0) {
$this->close_current_file($handler);
}
}
|
[
"protected",
"function",
"start_current_file",
"(",
"$",
"archivepath",
",",
"$",
"filesize",
",",
"$",
"mtime",
",",
"tgz_extractor_handler",
"$",
"handler",
"=",
"null",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"this",
"->",
"currentarchivepath",
"=",
"$",
"archivepath",
";",
"$",
"this",
"->",
"currentmtime",
"=",
"$",
"mtime",
";",
"$",
"this",
"->",
"currentfilesize",
"=",
"$",
"filesize",
";",
"$",
"this",
"->",
"currentfileprocessed",
"=",
"0",
";",
"if",
"(",
"$",
"archivepath",
"===",
"tgz_packer",
"::",
"ARCHIVE_INDEX_FILE",
")",
"{",
"// For index file, store in temp directory.",
"$",
"tempfolder",
"=",
"$",
"CFG",
"->",
"tempdir",
".",
"'/core_files'",
";",
"check_dir_exists",
"(",
"$",
"tempfolder",
")",
";",
"$",
"this",
"->",
"currentfile",
"=",
"tempnam",
"(",
"$",
"tempfolder",
",",
"'.index'",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"mode",
"===",
"self",
"::",
"MODE_LIST",
")",
"{",
"// If listing, add to list.",
"$",
"this",
"->",
"listresults",
"[",
"]",
"=",
"(",
"object",
")",
"array",
"(",
"'original_pathname'",
"=>",
"$",
"archivepath",
",",
"'pathname'",
"=>",
"$",
"archivepath",
",",
"'mtime'",
"=>",
"$",
"mtime",
",",
"'is_directory'",
"=>",
"false",
",",
"'size'",
"=>",
"$",
"filesize",
")",
";",
"// Discard file.",
"$",
"this",
"->",
"currentfile",
"=",
"true",
";",
"}",
"else",
"{",
"// For other files, ask handler for location.",
"$",
"this",
"->",
"currentfile",
"=",
"$",
"handler",
"->",
"tgz_start_file",
"(",
"$",
"archivepath",
")",
";",
"if",
"(",
"$",
"this",
"->",
"currentfile",
"===",
"null",
")",
"{",
"// This indicates that we are discarding the current file.",
"$",
"this",
"->",
"currentfile",
"=",
"true",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"filebuffer",
"=",
"''",
";",
"$",
"this",
"->",
"filebufferlength",
"=",
"0",
";",
"// Open file.",
"if",
"(",
"$",
"this",
"->",
"currentfile",
"!==",
"true",
")",
"{",
"$",
"this",
"->",
"currentfp",
"=",
"fopen",
"(",
"$",
"this",
"->",
"currentfile",
",",
"'wb'",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"currentfp",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'errorprocessingarchive'",
",",
"''",
",",
"''",
",",
"null",
",",
"'Failed to open output file: '",
".",
"$",
"this",
"->",
"currentfile",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"currentfp",
"=",
"null",
";",
"}",
"// If it has no size, close it right away.",
"if",
"(",
"$",
"filesize",
"==",
"0",
")",
"{",
"$",
"this",
"->",
"close_current_file",
"(",
"$",
"handler",
")",
";",
"}",
"}"
] |
Starts processing a file from archive.
@param string $archivepath Path inside archive
@param int $filesize Size in bytes
@param int $mtime File-modified time
@param tgz_extractor_handler $handler Will be called for extracted files
@throws moodle_exception
|
[
"Starts",
"processing",
"a",
"file",
"from",
"archive",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/tgz_extractor.php#L391-L444
|
220,372
|
moodle/moodle
|
lib/filestorage/tgz_extractor.php
|
tgz_extractor.close_current_file
|
protected function close_current_file($handler) {
if ($this->currentfp !== null) {
if (!fclose($this->currentfp)) {
throw new moodle_exception('errorprocessingarchive', '', '', null,
'Failed to close output file: ' . $this->currentfile);
}
// At this point we should touch the file to set its modified
// time to $this->currentmtime. However, when extracting to the
// temp directory, cron will delete files more than a week old,
// so to avoid problems we leave all files at their current time.
}
if ($this->currentarchivepath === tgz_packer::ARCHIVE_INDEX_FILE) {
if ($this->mode === self::MODE_LIST) {
// When listing array, use the archive index to produce the list.
$index = file($this->currentfile);
$ok = true;
foreach ($index as $num => $value) {
// For first line (header), check it's valid then skip it.
if ($num == 0) {
if (preg_match('~^' . preg_quote(tgz_packer::ARCHIVE_INDEX_COUNT_PREFIX) . '~', $value)) {
continue;
} else {
// Not valid, better ignore the file.
$ok = false;
break;
}
}
// Split on tabs and store in results array.
$values = explode("\t", trim($value));
$this->listresults[] = (object)array(
'original_pathname' => $values[0],
'pathname' => $values[0],
'mtime' => ($values[3] === '?' ? tgz_packer::DEFAULT_TIMESTAMP : (int)$values[3]),
'is_directory' => $values[1] === 'd',
'size' => (int)$values[2]);
}
if ($ok) {
$this->mode = self::MODE_LIST_COMPLETE;
}
unlink($this->currentfile);
} else {
// For index file, get number of files and delete temp file.
$contents = file_get_contents($this->currentfile, null, null, null, 128);
$matches = array();
if (preg_match('~^' . preg_quote(tgz_packer::ARCHIVE_INDEX_COUNT_PREFIX) .
'([0-9]+)~', $contents, $matches)) {
$this->numfiles = (int)$matches[1];
}
unlink($this->currentfile);
}
} else {
// Report to handler and put in results.
if ($this->currentfp !== null) {
$handler->tgz_end_file($this->currentarchivepath, $this->currentfile);
$this->results[$this->currentarchivepath] = true;
}
$this->donefiles++;
}
// No longer have a current file.
$this->currentfp = null;
$this->currentfile = null;
$this->currentarchivepath = null;
}
|
php
|
protected function close_current_file($handler) {
if ($this->currentfp !== null) {
if (!fclose($this->currentfp)) {
throw new moodle_exception('errorprocessingarchive', '', '', null,
'Failed to close output file: ' . $this->currentfile);
}
// At this point we should touch the file to set its modified
// time to $this->currentmtime. However, when extracting to the
// temp directory, cron will delete files more than a week old,
// so to avoid problems we leave all files at their current time.
}
if ($this->currentarchivepath === tgz_packer::ARCHIVE_INDEX_FILE) {
if ($this->mode === self::MODE_LIST) {
// When listing array, use the archive index to produce the list.
$index = file($this->currentfile);
$ok = true;
foreach ($index as $num => $value) {
// For first line (header), check it's valid then skip it.
if ($num == 0) {
if (preg_match('~^' . preg_quote(tgz_packer::ARCHIVE_INDEX_COUNT_PREFIX) . '~', $value)) {
continue;
} else {
// Not valid, better ignore the file.
$ok = false;
break;
}
}
// Split on tabs and store in results array.
$values = explode("\t", trim($value));
$this->listresults[] = (object)array(
'original_pathname' => $values[0],
'pathname' => $values[0],
'mtime' => ($values[3] === '?' ? tgz_packer::DEFAULT_TIMESTAMP : (int)$values[3]),
'is_directory' => $values[1] === 'd',
'size' => (int)$values[2]);
}
if ($ok) {
$this->mode = self::MODE_LIST_COMPLETE;
}
unlink($this->currentfile);
} else {
// For index file, get number of files and delete temp file.
$contents = file_get_contents($this->currentfile, null, null, null, 128);
$matches = array();
if (preg_match('~^' . preg_quote(tgz_packer::ARCHIVE_INDEX_COUNT_PREFIX) .
'([0-9]+)~', $contents, $matches)) {
$this->numfiles = (int)$matches[1];
}
unlink($this->currentfile);
}
} else {
// Report to handler and put in results.
if ($this->currentfp !== null) {
$handler->tgz_end_file($this->currentarchivepath, $this->currentfile);
$this->results[$this->currentarchivepath] = true;
}
$this->donefiles++;
}
// No longer have a current file.
$this->currentfp = null;
$this->currentfile = null;
$this->currentarchivepath = null;
}
|
[
"protected",
"function",
"close_current_file",
"(",
"$",
"handler",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"currentfp",
"!==",
"null",
")",
"{",
"if",
"(",
"!",
"fclose",
"(",
"$",
"this",
"->",
"currentfp",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'errorprocessingarchive'",
",",
"''",
",",
"''",
",",
"null",
",",
"'Failed to close output file: '",
".",
"$",
"this",
"->",
"currentfile",
")",
";",
"}",
"// At this point we should touch the file to set its modified",
"// time to $this->currentmtime. However, when extracting to the",
"// temp directory, cron will delete files more than a week old,",
"// so to avoid problems we leave all files at their current time.",
"}",
"if",
"(",
"$",
"this",
"->",
"currentarchivepath",
"===",
"tgz_packer",
"::",
"ARCHIVE_INDEX_FILE",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"mode",
"===",
"self",
"::",
"MODE_LIST",
")",
"{",
"// When listing array, use the archive index to produce the list.",
"$",
"index",
"=",
"file",
"(",
"$",
"this",
"->",
"currentfile",
")",
";",
"$",
"ok",
"=",
"true",
";",
"foreach",
"(",
"$",
"index",
"as",
"$",
"num",
"=>",
"$",
"value",
")",
"{",
"// For first line (header), check it's valid then skip it.",
"if",
"(",
"$",
"num",
"==",
"0",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'~^'",
".",
"preg_quote",
"(",
"tgz_packer",
"::",
"ARCHIVE_INDEX_COUNT_PREFIX",
")",
".",
"'~'",
",",
"$",
"value",
")",
")",
"{",
"continue",
";",
"}",
"else",
"{",
"// Not valid, better ignore the file.",
"$",
"ok",
"=",
"false",
";",
"break",
";",
"}",
"}",
"// Split on tabs and store in results array.",
"$",
"values",
"=",
"explode",
"(",
"\"\\t\"",
",",
"trim",
"(",
"$",
"value",
")",
")",
";",
"$",
"this",
"->",
"listresults",
"[",
"]",
"=",
"(",
"object",
")",
"array",
"(",
"'original_pathname'",
"=>",
"$",
"values",
"[",
"0",
"]",
",",
"'pathname'",
"=>",
"$",
"values",
"[",
"0",
"]",
",",
"'mtime'",
"=>",
"(",
"$",
"values",
"[",
"3",
"]",
"===",
"'?'",
"?",
"tgz_packer",
"::",
"DEFAULT_TIMESTAMP",
":",
"(",
"int",
")",
"$",
"values",
"[",
"3",
"]",
")",
",",
"'is_directory'",
"=>",
"$",
"values",
"[",
"1",
"]",
"===",
"'d'",
",",
"'size'",
"=>",
"(",
"int",
")",
"$",
"values",
"[",
"2",
"]",
")",
";",
"}",
"if",
"(",
"$",
"ok",
")",
"{",
"$",
"this",
"->",
"mode",
"=",
"self",
"::",
"MODE_LIST_COMPLETE",
";",
"}",
"unlink",
"(",
"$",
"this",
"->",
"currentfile",
")",
";",
"}",
"else",
"{",
"// For index file, get number of files and delete temp file.",
"$",
"contents",
"=",
"file_get_contents",
"(",
"$",
"this",
"->",
"currentfile",
",",
"null",
",",
"null",
",",
"null",
",",
"128",
")",
";",
"$",
"matches",
"=",
"array",
"(",
")",
";",
"if",
"(",
"preg_match",
"(",
"'~^'",
".",
"preg_quote",
"(",
"tgz_packer",
"::",
"ARCHIVE_INDEX_COUNT_PREFIX",
")",
".",
"'([0-9]+)~'",
",",
"$",
"contents",
",",
"$",
"matches",
")",
")",
"{",
"$",
"this",
"->",
"numfiles",
"=",
"(",
"int",
")",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"unlink",
"(",
"$",
"this",
"->",
"currentfile",
")",
";",
"}",
"}",
"else",
"{",
"// Report to handler and put in results.",
"if",
"(",
"$",
"this",
"->",
"currentfp",
"!==",
"null",
")",
"{",
"$",
"handler",
"->",
"tgz_end_file",
"(",
"$",
"this",
"->",
"currentarchivepath",
",",
"$",
"this",
"->",
"currentfile",
")",
";",
"$",
"this",
"->",
"results",
"[",
"$",
"this",
"->",
"currentarchivepath",
"]",
"=",
"true",
";",
"}",
"$",
"this",
"->",
"donefiles",
"++",
";",
"}",
"// No longer have a current file.",
"$",
"this",
"->",
"currentfp",
"=",
"null",
";",
"$",
"this",
"->",
"currentfile",
"=",
"null",
";",
"$",
"this",
"->",
"currentarchivepath",
"=",
"null",
";",
"}"
] |
Closes the current file, calls handler, and sets up data.
@param tgz_extractor_handler $handler Will be called for extracted files
@throws moodle_exception If there is an error closing it
|
[
"Closes",
"the",
"current",
"file",
"calls",
"handler",
"and",
"sets",
"up",
"data",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/tgz_extractor.php#L452-L517
|
220,373
|
moodle/moodle
|
lib/filebrowser/file_browser.php
|
file_browser.get_file_info
|
public function get_file_info($context = NULL, $component = NULL, $filearea = NULL, $itemid = NULL, $filepath = NULL, $filename = NULL) {
if (!$context) {
$context = context_system::instance();
}
switch ($context->contextlevel) {
case CONTEXT_SYSTEM:
return $this->get_file_info_context_system($context, $component, $filearea, $itemid, $filepath, $filename);
case CONTEXT_USER:
return $this->get_file_info_context_user($context, $component, $filearea, $itemid, $filepath, $filename);
case CONTEXT_COURSECAT:
return $this->get_file_info_context_coursecat($context, $component, $filearea, $itemid, $filepath, $filename);
case CONTEXT_COURSE:
return $this->get_file_info_context_course($context, $component, $filearea, $itemid, $filepath, $filename);
case CONTEXT_MODULE:
return $this->get_file_info_context_module($context, $component, $filearea, $itemid, $filepath, $filename);
}
return null;
}
|
php
|
public function get_file_info($context = NULL, $component = NULL, $filearea = NULL, $itemid = NULL, $filepath = NULL, $filename = NULL) {
if (!$context) {
$context = context_system::instance();
}
switch ($context->contextlevel) {
case CONTEXT_SYSTEM:
return $this->get_file_info_context_system($context, $component, $filearea, $itemid, $filepath, $filename);
case CONTEXT_USER:
return $this->get_file_info_context_user($context, $component, $filearea, $itemid, $filepath, $filename);
case CONTEXT_COURSECAT:
return $this->get_file_info_context_coursecat($context, $component, $filearea, $itemid, $filepath, $filename);
case CONTEXT_COURSE:
return $this->get_file_info_context_course($context, $component, $filearea, $itemid, $filepath, $filename);
case CONTEXT_MODULE:
return $this->get_file_info_context_module($context, $component, $filearea, $itemid, $filepath, $filename);
}
return null;
}
|
[
"public",
"function",
"get_file_info",
"(",
"$",
"context",
"=",
"NULL",
",",
"$",
"component",
"=",
"NULL",
",",
"$",
"filearea",
"=",
"NULL",
",",
"$",
"itemid",
"=",
"NULL",
",",
"$",
"filepath",
"=",
"NULL",
",",
"$",
"filename",
"=",
"NULL",
")",
"{",
"if",
"(",
"!",
"$",
"context",
")",
"{",
"$",
"context",
"=",
"context_system",
"::",
"instance",
"(",
")",
";",
"}",
"switch",
"(",
"$",
"context",
"->",
"contextlevel",
")",
"{",
"case",
"CONTEXT_SYSTEM",
":",
"return",
"$",
"this",
"->",
"get_file_info_context_system",
"(",
"$",
"context",
",",
"$",
"component",
",",
"$",
"filearea",
",",
"$",
"itemid",
",",
"$",
"filepath",
",",
"$",
"filename",
")",
";",
"case",
"CONTEXT_USER",
":",
"return",
"$",
"this",
"->",
"get_file_info_context_user",
"(",
"$",
"context",
",",
"$",
"component",
",",
"$",
"filearea",
",",
"$",
"itemid",
",",
"$",
"filepath",
",",
"$",
"filename",
")",
";",
"case",
"CONTEXT_COURSECAT",
":",
"return",
"$",
"this",
"->",
"get_file_info_context_coursecat",
"(",
"$",
"context",
",",
"$",
"component",
",",
"$",
"filearea",
",",
"$",
"itemid",
",",
"$",
"filepath",
",",
"$",
"filename",
")",
";",
"case",
"CONTEXT_COURSE",
":",
"return",
"$",
"this",
"->",
"get_file_info_context_course",
"(",
"$",
"context",
",",
"$",
"component",
",",
"$",
"filearea",
",",
"$",
"itemid",
",",
"$",
"filepath",
",",
"$",
"filename",
")",
";",
"case",
"CONTEXT_MODULE",
":",
"return",
"$",
"this",
"->",
"get_file_info_context_module",
"(",
"$",
"context",
",",
"$",
"component",
",",
"$",
"filearea",
",",
"$",
"itemid",
",",
"$",
"filepath",
",",
"$",
"filename",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Looks up file_info instance
@param stdClass $context context object
@param string $component component
@param string $filearea file area
@param int $itemid item ID
@param string $filepath file path
@param string $filename file name
@return file_info|null file_info instance or null if not found or access not allowed
|
[
"Looks",
"up",
"file_info",
"instance"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filebrowser/file_browser.php#L77-L95
|
220,374
|
moodle/moodle
|
lib/filebrowser/file_browser.php
|
file_browser.get_file_info_context_user
|
private function get_file_info_context_user($context, $component, $filearea, $itemid, $filepath, $filename) {
global $DB, $USER;
if ($context->instanceid == $USER->id) {
$user = $USER;
} else {
$user = $DB->get_record('user', array('id'=>$context->instanceid));
}
if (isguestuser($user)) {
// guests do not have any files
return null;
}
if ($user->deleted) {
return null;
}
$level = new file_info_context_user($this, $context, $user);
return $level->get_file_info($component, $filearea, $itemid, $filepath, $filename);
}
|
php
|
private function get_file_info_context_user($context, $component, $filearea, $itemid, $filepath, $filename) {
global $DB, $USER;
if ($context->instanceid == $USER->id) {
$user = $USER;
} else {
$user = $DB->get_record('user', array('id'=>$context->instanceid));
}
if (isguestuser($user)) {
// guests do not have any files
return null;
}
if ($user->deleted) {
return null;
}
$level = new file_info_context_user($this, $context, $user);
return $level->get_file_info($component, $filearea, $itemid, $filepath, $filename);
}
|
[
"private",
"function",
"get_file_info_context_user",
"(",
"$",
"context",
",",
"$",
"component",
",",
"$",
"filearea",
",",
"$",
"itemid",
",",
"$",
"filepath",
",",
"$",
"filename",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"USER",
";",
"if",
"(",
"$",
"context",
"->",
"instanceid",
"==",
"$",
"USER",
"->",
"id",
")",
"{",
"$",
"user",
"=",
"$",
"USER",
";",
"}",
"else",
"{",
"$",
"user",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'user'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"context",
"->",
"instanceid",
")",
")",
";",
"}",
"if",
"(",
"isguestuser",
"(",
"$",
"user",
")",
")",
"{",
"// guests do not have any files",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"user",
"->",
"deleted",
")",
"{",
"return",
"null",
";",
"}",
"$",
"level",
"=",
"new",
"file_info_context_user",
"(",
"$",
"this",
",",
"$",
"context",
",",
"$",
"user",
")",
";",
"return",
"$",
"level",
"->",
"get_file_info",
"(",
"$",
"component",
",",
"$",
"filearea",
",",
"$",
"itemid",
",",
"$",
"filepath",
",",
"$",
"filename",
")",
";",
"}"
] |
Returns info about the files at User context
@param stdClass $context context object
@param string $component component
@param string $filearea file area
@param int $itemid item ID
@param string $filepath file path
@param string $filename file name
@return file_info|null file_info instance or null if not found or access not allowed
|
[
"Returns",
"info",
"about",
"the",
"files",
"at",
"User",
"context"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filebrowser/file_browser.php#L126-L145
|
220,375
|
moodle/moodle
|
lib/filebrowser/file_browser.php
|
file_browser.is_enrolled
|
public function is_enrolled($courseid) {
if ($this->enrolledcourses === null || PHPUNIT_TEST) {
// Since get_file_browser() returns a statically cached object we can't rely on cache
// inside the file_browser class in the unittests.
// TODO MDL-59964 remove this caching when it's implemented inside enrol_get_my_courses().
$this->enrolledcourses = enrol_get_my_courses(['id']);
}
return array_key_exists($courseid, $this->enrolledcourses);
}
|
php
|
public function is_enrolled($courseid) {
if ($this->enrolledcourses === null || PHPUNIT_TEST) {
// Since get_file_browser() returns a statically cached object we can't rely on cache
// inside the file_browser class in the unittests.
// TODO MDL-59964 remove this caching when it's implemented inside enrol_get_my_courses().
$this->enrolledcourses = enrol_get_my_courses(['id']);
}
return array_key_exists($courseid, $this->enrolledcourses);
}
|
[
"public",
"function",
"is_enrolled",
"(",
"$",
"courseid",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"enrolledcourses",
"===",
"null",
"||",
"PHPUNIT_TEST",
")",
"{",
"// Since get_file_browser() returns a statically cached object we can't rely on cache",
"// inside the file_browser class in the unittests.",
"// TODO MDL-59964 remove this caching when it's implemented inside enrol_get_my_courses().",
"$",
"this",
"->",
"enrolledcourses",
"=",
"enrol_get_my_courses",
"(",
"[",
"'id'",
"]",
")",
";",
"}",
"return",
"array_key_exists",
"(",
"$",
"courseid",
",",
"$",
"this",
"->",
"enrolledcourses",
")",
";",
"}"
] |
Check if user is enrolled into the course
This function keeps a cache of enrolled courses because it may be called multiple times for many courses in one request
@param int $courseid
@return bool
|
[
"Check",
"if",
"user",
"is",
"enrolled",
"into",
"the",
"course"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filebrowser/file_browser.php#L228-L236
|
220,376
|
moodle/moodle
|
lib/php-css-parser/CSSList/CSSList.php
|
CSSList.insert
|
public function insert($oItem, $oSibling) {
$iIndex = array_search($oSibling, $this->aContents);
if ($iIndex === false) {
return $this->append($oItem);
}
array_splice($this->aContents, $iIndex, 0, array($oItem));
}
|
php
|
public function insert($oItem, $oSibling) {
$iIndex = array_search($oSibling, $this->aContents);
if ($iIndex === false) {
return $this->append($oItem);
}
array_splice($this->aContents, $iIndex, 0, array($oItem));
}
|
[
"public",
"function",
"insert",
"(",
"$",
"oItem",
",",
"$",
"oSibling",
")",
"{",
"$",
"iIndex",
"=",
"array_search",
"(",
"$",
"oSibling",
",",
"$",
"this",
"->",
"aContents",
")",
";",
"if",
"(",
"$",
"iIndex",
"===",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"append",
"(",
"$",
"oItem",
")",
";",
"}",
"array_splice",
"(",
"$",
"this",
"->",
"aContents",
",",
"$",
"iIndex",
",",
"0",
",",
"array",
"(",
"$",
"oItem",
")",
")",
";",
"}"
] |
Insert an item before its sibling.
@param mixed $oItem The item.
@param mixed $oSibling The sibling.
|
[
"Insert",
"an",
"item",
"before",
"its",
"sibling",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/php-css-parser/CSSList/CSSList.php#L44-L50
|
220,377
|
moodle/moodle
|
lib/php-css-parser/CSSList/CSSList.php
|
CSSList.remove
|
public function remove($oItemToRemove) {
$iKey = array_search($oItemToRemove, $this->aContents, true);
if ($iKey !== false) {
unset($this->aContents[$iKey]);
return true;
}
return false;
}
|
php
|
public function remove($oItemToRemove) {
$iKey = array_search($oItemToRemove, $this->aContents, true);
if ($iKey !== false) {
unset($this->aContents[$iKey]);
return true;
}
return false;
}
|
[
"public",
"function",
"remove",
"(",
"$",
"oItemToRemove",
")",
"{",
"$",
"iKey",
"=",
"array_search",
"(",
"$",
"oItemToRemove",
",",
"$",
"this",
"->",
"aContents",
",",
"true",
")",
";",
"if",
"(",
"$",
"iKey",
"!==",
"false",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"aContents",
"[",
"$",
"iKey",
"]",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Removes an item from the CSS list.
@param RuleSet|Import|Charset|CSSList $oItemToRemove May be a RuleSet (most likely a DeclarationBlock), a Import, a Charset or another CSSList (most likely a MediaQuery)
|
[
"Removes",
"an",
"item",
"from",
"the",
"CSS",
"list",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/php-css-parser/CSSList/CSSList.php#L56-L63
|
220,378
|
moodle/moodle
|
lib/php-css-parser/CSSList/CSSList.php
|
CSSList.setContents
|
public function setContents(array $aContents) {
$this->aContents = array();
foreach ($aContents as $content) {
$this->append($content);
}
}
|
php
|
public function setContents(array $aContents) {
$this->aContents = array();
foreach ($aContents as $content) {
$this->append($content);
}
}
|
[
"public",
"function",
"setContents",
"(",
"array",
"$",
"aContents",
")",
"{",
"$",
"this",
"->",
"aContents",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"aContents",
"as",
"$",
"content",
")",
"{",
"$",
"this",
"->",
"append",
"(",
"$",
"content",
")",
";",
"}",
"}"
] |
Set the contents.
@param array $aContents Objects to set as content.
|
[
"Set",
"the",
"contents",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/php-css-parser/CSSList/CSSList.php#L69-L74
|
220,379
|
moodle/moodle
|
lib/php-css-parser/CSSList/CSSList.php
|
CSSList.removeDeclarationBlockBySelector
|
public function removeDeclarationBlockBySelector($mSelector, $bRemoveAll = false) {
if ($mSelector instanceof DeclarationBlock) {
$mSelector = $mSelector->getSelectors();
}
if (!is_array($mSelector)) {
$mSelector = explode(',', $mSelector);
}
foreach ($mSelector as $iKey => &$mSel) {
if (!($mSel instanceof Selector)) {
$mSel = new Selector($mSel);
}
}
foreach ($this->aContents as $iKey => $mItem) {
if (!($mItem instanceof DeclarationBlock)) {
continue;
}
if ($mItem->getSelectors() == $mSelector) {
unset($this->aContents[$iKey]);
if (!$bRemoveAll) {
return;
}
}
}
}
|
php
|
public function removeDeclarationBlockBySelector($mSelector, $bRemoveAll = false) {
if ($mSelector instanceof DeclarationBlock) {
$mSelector = $mSelector->getSelectors();
}
if (!is_array($mSelector)) {
$mSelector = explode(',', $mSelector);
}
foreach ($mSelector as $iKey => &$mSel) {
if (!($mSel instanceof Selector)) {
$mSel = new Selector($mSel);
}
}
foreach ($this->aContents as $iKey => $mItem) {
if (!($mItem instanceof DeclarationBlock)) {
continue;
}
if ($mItem->getSelectors() == $mSelector) {
unset($this->aContents[$iKey]);
if (!$bRemoveAll) {
return;
}
}
}
}
|
[
"public",
"function",
"removeDeclarationBlockBySelector",
"(",
"$",
"mSelector",
",",
"$",
"bRemoveAll",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"mSelector",
"instanceof",
"DeclarationBlock",
")",
"{",
"$",
"mSelector",
"=",
"$",
"mSelector",
"->",
"getSelectors",
"(",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"mSelector",
")",
")",
"{",
"$",
"mSelector",
"=",
"explode",
"(",
"','",
",",
"$",
"mSelector",
")",
";",
"}",
"foreach",
"(",
"$",
"mSelector",
"as",
"$",
"iKey",
"=>",
"&",
"$",
"mSel",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"mSel",
"instanceof",
"Selector",
")",
")",
"{",
"$",
"mSel",
"=",
"new",
"Selector",
"(",
"$",
"mSel",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"this",
"->",
"aContents",
"as",
"$",
"iKey",
"=>",
"$",
"mItem",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"mItem",
"instanceof",
"DeclarationBlock",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"mItem",
"->",
"getSelectors",
"(",
")",
"==",
"$",
"mSelector",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"aContents",
"[",
"$",
"iKey",
"]",
")",
";",
"if",
"(",
"!",
"$",
"bRemoveAll",
")",
"{",
"return",
";",
"}",
"}",
"}",
"}"
] |
Removes a declaration block from the CSS list if it matches all given selectors.
@param array|string $mSelector The selectors to match.
@param boolean $bRemoveAll Whether to stop at the first declaration block found or remove all blocks
|
[
"Removes",
"a",
"declaration",
"block",
"from",
"the",
"CSS",
"list",
"if",
"it",
"matches",
"all",
"given",
"selectors",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/php-css-parser/CSSList/CSSList.php#L81-L104
|
220,380
|
moodle/moodle
|
report/loglive/classes/renderer_ajax.php
|
report_loglive_renderer_ajax.render_report_loglive
|
protected function render_report_loglive(report_loglive_renderable $reportloglive) {
if (empty($reportloglive->selectedlogreader)) {
return null;
}
$table = $reportloglive->get_table(true);
return $table->out($reportloglive->perpage, false);
}
|
php
|
protected function render_report_loglive(report_loglive_renderable $reportloglive) {
if (empty($reportloglive->selectedlogreader)) {
return null;
}
$table = $reportloglive->get_table(true);
return $table->out($reportloglive->perpage, false);
}
|
[
"protected",
"function",
"render_report_loglive",
"(",
"report_loglive_renderable",
"$",
"reportloglive",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"reportloglive",
"->",
"selectedlogreader",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"table",
"=",
"$",
"reportloglive",
"->",
"get_table",
"(",
"true",
")",
";",
"return",
"$",
"table",
"->",
"out",
"(",
"$",
"reportloglive",
"->",
"perpage",
",",
"false",
")",
";",
"}"
] |
Render logs for ajax.
@param report_loglive_renderable $reportloglive object of report_loglive_renderable.
@return string html to be displayed to user.
|
[
"Render",
"logs",
"for",
"ajax",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/loglive/classes/renderer_ajax.php#L54-L60
|
220,381
|
moodle/moodle
|
lib/lessphp/Parser.php
|
Less_Parser.Reset
|
public function Reset( $options = null ){
$this->rules = array();
self::$imports = array();
self::$has_extends = false;
self::$imports = array();
self::$contentsMap = array();
$this->env = new Less_Environment($options);
$this->env->Init();
//set new options
if( is_array($options) ){
$this->SetOptions(Less_Parser::$default_options);
$this->SetOptions($options);
}
}
|
php
|
public function Reset( $options = null ){
$this->rules = array();
self::$imports = array();
self::$has_extends = false;
self::$imports = array();
self::$contentsMap = array();
$this->env = new Less_Environment($options);
$this->env->Init();
//set new options
if( is_array($options) ){
$this->SetOptions(Less_Parser::$default_options);
$this->SetOptions($options);
}
}
|
[
"public",
"function",
"Reset",
"(",
"$",
"options",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"rules",
"=",
"array",
"(",
")",
";",
"self",
"::",
"$",
"imports",
"=",
"array",
"(",
")",
";",
"self",
"::",
"$",
"has_extends",
"=",
"false",
";",
"self",
"::",
"$",
"imports",
"=",
"array",
"(",
")",
";",
"self",
"::",
"$",
"contentsMap",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"env",
"=",
"new",
"Less_Environment",
"(",
"$",
"options",
")",
";",
"$",
"this",
"->",
"env",
"->",
"Init",
"(",
")",
";",
"//set new options",
"if",
"(",
"is_array",
"(",
"$",
"options",
")",
")",
"{",
"$",
"this",
"->",
"SetOptions",
"(",
"Less_Parser",
"::",
"$",
"default_options",
")",
";",
"$",
"this",
"->",
"SetOptions",
"(",
"$",
"options",
")",
";",
"}",
"}"
] |
Reset the parser state completely
|
[
"Reset",
"the",
"parser",
"state",
"completely"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Parser.php#L104-L119
|
220,382
|
moodle/moodle
|
lib/lessphp/Parser.php
|
Less_Parser.SetOption
|
public function SetOption($option,$value){
switch($option){
case 'import_dirs':
$this->SetImportDirs($value);
return;
case 'cache_dir':
if( is_string($value) ){
Less_Cache::SetCacheDir($value);
Less_Cache::CheckCacheDir();
}
return;
}
Less_Parser::$options[$option] = $value;
}
|
php
|
public function SetOption($option,$value){
switch($option){
case 'import_dirs':
$this->SetImportDirs($value);
return;
case 'cache_dir':
if( is_string($value) ){
Less_Cache::SetCacheDir($value);
Less_Cache::CheckCacheDir();
}
return;
}
Less_Parser::$options[$option] = $value;
}
|
[
"public",
"function",
"SetOption",
"(",
"$",
"option",
",",
"$",
"value",
")",
"{",
"switch",
"(",
"$",
"option",
")",
"{",
"case",
"'import_dirs'",
":",
"$",
"this",
"->",
"SetImportDirs",
"(",
"$",
"value",
")",
";",
"return",
";",
"case",
"'cache_dir'",
":",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"Less_Cache",
"::",
"SetCacheDir",
"(",
"$",
"value",
")",
";",
"Less_Cache",
"::",
"CheckCacheDir",
"(",
")",
";",
"}",
"return",
";",
"}",
"Less_Parser",
"::",
"$",
"options",
"[",
"$",
"option",
"]",
"=",
"$",
"value",
";",
"}"
] |
Set one compiler option
|
[
"Set",
"one",
"compiler",
"option"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Parser.php#L136-L153
|
220,383
|
moodle/moodle
|
lib/lessphp/Parser.php
|
Less_Parser.unregisterFunction
|
public function unregisterFunction($name) {
if( isset($this->env->functions[$name]) )
unset($this->env->functions[$name]);
}
|
php
|
public function unregisterFunction($name) {
if( isset($this->env->functions[$name]) )
unset($this->env->functions[$name]);
}
|
[
"public",
"function",
"unregisterFunction",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"env",
"->",
"functions",
"[",
"$",
"name",
"]",
")",
")",
"unset",
"(",
"$",
"this",
"->",
"env",
"->",
"functions",
"[",
"$",
"name",
"]",
")",
";",
"}"
] |
Removed an already registered function
@param string $name function name
|
[
"Removed",
"an",
"already",
"registered",
"function"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Parser.php#L170-L173
|
220,384
|
moodle/moodle
|
lib/lessphp/Parser.php
|
Less_Parser.getCss
|
public function getCss(){
$precision = ini_get('precision');
@ini_set('precision',16);
$locale = setlocale(LC_NUMERIC, 0);
setlocale(LC_NUMERIC, "C");
try {
$root = new Less_Tree_Ruleset(array(), $this->rules );
$root->root = true;
$root->firstRoot = true;
$this->PreVisitors($root);
self::$has_extends = false;
$evaldRoot = $root->compile($this->env);
$this->PostVisitors($evaldRoot);
if( Less_Parser::$options['sourceMap'] ){
$generator = new Less_SourceMap_Generator($evaldRoot, Less_Parser::$contentsMap, Less_Parser::$options );
// will also save file
// FIXME: should happen somewhere else?
$css = $generator->generateCSS();
}else{
$css = $evaldRoot->toCSS();
}
if( Less_Parser::$options['compress'] ){
$css = preg_replace('/(^(\s)+)|((\s)+$)/', '', $css);
}
} catch (Exception $exc) {
// Intentional fall-through so we can reset environment
}
//reset php settings
@ini_set('precision',$precision);
setlocale(LC_NUMERIC, $locale);
// If you previously defined $this->mb_internal_encoding
// is required to return the encoding as it was before
if ($this->mb_internal_encoding != '') {
@ini_set("mbstring.internal_encoding", $this->mb_internal_encoding);
$this->mb_internal_encoding = '';
}
// Rethrow exception after we handled resetting the environment
if (!empty($exc)) {
throw $exc;
}
return $css;
}
|
php
|
public function getCss(){
$precision = ini_get('precision');
@ini_set('precision',16);
$locale = setlocale(LC_NUMERIC, 0);
setlocale(LC_NUMERIC, "C");
try {
$root = new Less_Tree_Ruleset(array(), $this->rules );
$root->root = true;
$root->firstRoot = true;
$this->PreVisitors($root);
self::$has_extends = false;
$evaldRoot = $root->compile($this->env);
$this->PostVisitors($evaldRoot);
if( Less_Parser::$options['sourceMap'] ){
$generator = new Less_SourceMap_Generator($evaldRoot, Less_Parser::$contentsMap, Less_Parser::$options );
// will also save file
// FIXME: should happen somewhere else?
$css = $generator->generateCSS();
}else{
$css = $evaldRoot->toCSS();
}
if( Less_Parser::$options['compress'] ){
$css = preg_replace('/(^(\s)+)|((\s)+$)/', '', $css);
}
} catch (Exception $exc) {
// Intentional fall-through so we can reset environment
}
//reset php settings
@ini_set('precision',$precision);
setlocale(LC_NUMERIC, $locale);
// If you previously defined $this->mb_internal_encoding
// is required to return the encoding as it was before
if ($this->mb_internal_encoding != '') {
@ini_set("mbstring.internal_encoding", $this->mb_internal_encoding);
$this->mb_internal_encoding = '';
}
// Rethrow exception after we handled resetting the environment
if (!empty($exc)) {
throw $exc;
}
return $css;
}
|
[
"public",
"function",
"getCss",
"(",
")",
"{",
"$",
"precision",
"=",
"ini_get",
"(",
"'precision'",
")",
";",
"@",
"ini_set",
"(",
"'precision'",
",",
"16",
")",
";",
"$",
"locale",
"=",
"setlocale",
"(",
"LC_NUMERIC",
",",
"0",
")",
";",
"setlocale",
"(",
"LC_NUMERIC",
",",
"\"C\"",
")",
";",
"try",
"{",
"$",
"root",
"=",
"new",
"Less_Tree_Ruleset",
"(",
"array",
"(",
")",
",",
"$",
"this",
"->",
"rules",
")",
";",
"$",
"root",
"->",
"root",
"=",
"true",
";",
"$",
"root",
"->",
"firstRoot",
"=",
"true",
";",
"$",
"this",
"->",
"PreVisitors",
"(",
"$",
"root",
")",
";",
"self",
"::",
"$",
"has_extends",
"=",
"false",
";",
"$",
"evaldRoot",
"=",
"$",
"root",
"->",
"compile",
"(",
"$",
"this",
"->",
"env",
")",
";",
"$",
"this",
"->",
"PostVisitors",
"(",
"$",
"evaldRoot",
")",
";",
"if",
"(",
"Less_Parser",
"::",
"$",
"options",
"[",
"'sourceMap'",
"]",
")",
"{",
"$",
"generator",
"=",
"new",
"Less_SourceMap_Generator",
"(",
"$",
"evaldRoot",
",",
"Less_Parser",
"::",
"$",
"contentsMap",
",",
"Less_Parser",
"::",
"$",
"options",
")",
";",
"// will also save file",
"// FIXME: should happen somewhere else?",
"$",
"css",
"=",
"$",
"generator",
"->",
"generateCSS",
"(",
")",
";",
"}",
"else",
"{",
"$",
"css",
"=",
"$",
"evaldRoot",
"->",
"toCSS",
"(",
")",
";",
"}",
"if",
"(",
"Less_Parser",
"::",
"$",
"options",
"[",
"'compress'",
"]",
")",
"{",
"$",
"css",
"=",
"preg_replace",
"(",
"'/(^(\\s)+)|((\\s)+$)/'",
",",
"''",
",",
"$",
"css",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"exc",
")",
"{",
"// Intentional fall-through so we can reset environment",
"}",
"//reset php settings",
"@",
"ini_set",
"(",
"'precision'",
",",
"$",
"precision",
")",
";",
"setlocale",
"(",
"LC_NUMERIC",
",",
"$",
"locale",
")",
";",
"// If you previously defined $this->mb_internal_encoding",
"// is required to return the encoding as it was before",
"if",
"(",
"$",
"this",
"->",
"mb_internal_encoding",
"!=",
"''",
")",
"{",
"@",
"ini_set",
"(",
"\"mbstring.internal_encoding\"",
",",
"$",
"this",
"->",
"mb_internal_encoding",
")",
";",
"$",
"this",
"->",
"mb_internal_encoding",
"=",
"''",
";",
"}",
"// Rethrow exception after we handled resetting the environment",
"if",
"(",
"!",
"empty",
"(",
"$",
"exc",
")",
")",
"{",
"throw",
"$",
"exc",
";",
"}",
"return",
"$",
"css",
";",
"}"
] |
Get the current css buffer
@return string
|
[
"Get",
"the",
"current",
"css",
"buffer"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Parser.php#L181-L240
|
220,385
|
moodle/moodle
|
lib/lessphp/Parser.php
|
Less_Parser.PreVisitors
|
private function PreVisitors($root){
if( Less_Parser::$options['plugins'] ){
foreach(Less_Parser::$options['plugins'] as $plugin){
if( !empty($plugin->isPreEvalVisitor) ){
$plugin->run($root);
}
}
}
}
|
php
|
private function PreVisitors($root){
if( Less_Parser::$options['plugins'] ){
foreach(Less_Parser::$options['plugins'] as $plugin){
if( !empty($plugin->isPreEvalVisitor) ){
$plugin->run($root);
}
}
}
}
|
[
"private",
"function",
"PreVisitors",
"(",
"$",
"root",
")",
"{",
"if",
"(",
"Less_Parser",
"::",
"$",
"options",
"[",
"'plugins'",
"]",
")",
"{",
"foreach",
"(",
"Less_Parser",
"::",
"$",
"options",
"[",
"'plugins'",
"]",
"as",
"$",
"plugin",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"plugin",
"->",
"isPreEvalVisitor",
")",
")",
"{",
"$",
"plugin",
"->",
"run",
"(",
"$",
"root",
")",
";",
"}",
"}",
"}",
"}"
] |
Run pre-compile visitors
|
[
"Run",
"pre",
"-",
"compile",
"visitors"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Parser.php#L246-L255
|
220,386
|
moodle/moodle
|
lib/lessphp/Parser.php
|
Less_Parser.PostVisitors
|
private function PostVisitors($evaldRoot){
$visitors = array();
$visitors[] = new Less_Visitor_joinSelector();
if( self::$has_extends ){
$visitors[] = new Less_Visitor_processExtends();
}
$visitors[] = new Less_Visitor_toCSS();
if( Less_Parser::$options['plugins'] ){
foreach(Less_Parser::$options['plugins'] as $plugin){
if( property_exists($plugin,'isPreEvalVisitor') && $plugin->isPreEvalVisitor ){
continue;
}
if( property_exists($plugin,'isPreVisitor') && $plugin->isPreVisitor ){
array_unshift( $visitors, $plugin);
}else{
$visitors[] = $plugin;
}
}
}
for($i = 0; $i < count($visitors); $i++ ){
$visitors[$i]->run($evaldRoot);
}
}
|
php
|
private function PostVisitors($evaldRoot){
$visitors = array();
$visitors[] = new Less_Visitor_joinSelector();
if( self::$has_extends ){
$visitors[] = new Less_Visitor_processExtends();
}
$visitors[] = new Less_Visitor_toCSS();
if( Less_Parser::$options['plugins'] ){
foreach(Less_Parser::$options['plugins'] as $plugin){
if( property_exists($plugin,'isPreEvalVisitor') && $plugin->isPreEvalVisitor ){
continue;
}
if( property_exists($plugin,'isPreVisitor') && $plugin->isPreVisitor ){
array_unshift( $visitors, $plugin);
}else{
$visitors[] = $plugin;
}
}
}
for($i = 0; $i < count($visitors); $i++ ){
$visitors[$i]->run($evaldRoot);
}
}
|
[
"private",
"function",
"PostVisitors",
"(",
"$",
"evaldRoot",
")",
"{",
"$",
"visitors",
"=",
"array",
"(",
")",
";",
"$",
"visitors",
"[",
"]",
"=",
"new",
"Less_Visitor_joinSelector",
"(",
")",
";",
"if",
"(",
"self",
"::",
"$",
"has_extends",
")",
"{",
"$",
"visitors",
"[",
"]",
"=",
"new",
"Less_Visitor_processExtends",
"(",
")",
";",
"}",
"$",
"visitors",
"[",
"]",
"=",
"new",
"Less_Visitor_toCSS",
"(",
")",
";",
"if",
"(",
"Less_Parser",
"::",
"$",
"options",
"[",
"'plugins'",
"]",
")",
"{",
"foreach",
"(",
"Less_Parser",
"::",
"$",
"options",
"[",
"'plugins'",
"]",
"as",
"$",
"plugin",
")",
"{",
"if",
"(",
"property_exists",
"(",
"$",
"plugin",
",",
"'isPreEvalVisitor'",
")",
"&&",
"$",
"plugin",
"->",
"isPreEvalVisitor",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"property_exists",
"(",
"$",
"plugin",
",",
"'isPreVisitor'",
")",
"&&",
"$",
"plugin",
"->",
"isPreVisitor",
")",
"{",
"array_unshift",
"(",
"$",
"visitors",
",",
"$",
"plugin",
")",
";",
"}",
"else",
"{",
"$",
"visitors",
"[",
"]",
"=",
"$",
"plugin",
";",
"}",
"}",
"}",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"visitors",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"visitors",
"[",
"$",
"i",
"]",
"->",
"run",
"(",
"$",
"evaldRoot",
")",
";",
"}",
"}"
] |
Run post-compile visitors
|
[
"Run",
"post",
"-",
"compile",
"visitors"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Parser.php#L262-L291
|
220,387
|
moodle/moodle
|
lib/lessphp/Parser.php
|
Less_Parser.parse
|
public function parse( $str, $file_uri = null ){
if( !$file_uri ){
$uri_root = '';
$filename = 'anonymous-file-'.Less_Parser::$next_id++.'.less';
}else{
$file_uri = self::WinPath($file_uri);
$filename = $file_uri;
$uri_root = dirname($file_uri);
}
$previousFileInfo = $this->env->currentFileInfo;
$uri_root = self::WinPath($uri_root);
$this->SetFileInfo($filename, $uri_root);
$this->input = $str;
$this->_parse();
if( $previousFileInfo ){
$this->env->currentFileInfo = $previousFileInfo;
}
return $this;
}
|
php
|
public function parse( $str, $file_uri = null ){
if( !$file_uri ){
$uri_root = '';
$filename = 'anonymous-file-'.Less_Parser::$next_id++.'.less';
}else{
$file_uri = self::WinPath($file_uri);
$filename = $file_uri;
$uri_root = dirname($file_uri);
}
$previousFileInfo = $this->env->currentFileInfo;
$uri_root = self::WinPath($uri_root);
$this->SetFileInfo($filename, $uri_root);
$this->input = $str;
$this->_parse();
if( $previousFileInfo ){
$this->env->currentFileInfo = $previousFileInfo;
}
return $this;
}
|
[
"public",
"function",
"parse",
"(",
"$",
"str",
",",
"$",
"file_uri",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"file_uri",
")",
"{",
"$",
"uri_root",
"=",
"''",
";",
"$",
"filename",
"=",
"'anonymous-file-'",
".",
"Less_Parser",
"::",
"$",
"next_id",
"++",
".",
"'.less'",
";",
"}",
"else",
"{",
"$",
"file_uri",
"=",
"self",
"::",
"WinPath",
"(",
"$",
"file_uri",
")",
";",
"$",
"filename",
"=",
"$",
"file_uri",
";",
"$",
"uri_root",
"=",
"dirname",
"(",
"$",
"file_uri",
")",
";",
"}",
"$",
"previousFileInfo",
"=",
"$",
"this",
"->",
"env",
"->",
"currentFileInfo",
";",
"$",
"uri_root",
"=",
"self",
"::",
"WinPath",
"(",
"$",
"uri_root",
")",
";",
"$",
"this",
"->",
"SetFileInfo",
"(",
"$",
"filename",
",",
"$",
"uri_root",
")",
";",
"$",
"this",
"->",
"input",
"=",
"$",
"str",
";",
"$",
"this",
"->",
"_parse",
"(",
")",
";",
"if",
"(",
"$",
"previousFileInfo",
")",
"{",
"$",
"this",
"->",
"env",
"->",
"currentFileInfo",
"=",
"$",
"previousFileInfo",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Parse a Less string into css
@param string $str The string to convert
@param string $uri_root The url of the file
@return Less_Tree_Ruleset|Less_Parser
|
[
"Parse",
"a",
"Less",
"string",
"into",
"css"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Parser.php#L301-L324
|
220,388
|
moodle/moodle
|
lib/lessphp/Parser.php
|
Less_Parser.ModifyVars
|
public function ModifyVars( $vars ){
$this->input = Less_Parser::serializeVars( $vars );
$this->_parse();
return $this;
}
|
php
|
public function ModifyVars( $vars ){
$this->input = Less_Parser::serializeVars( $vars );
$this->_parse();
return $this;
}
|
[
"public",
"function",
"ModifyVars",
"(",
"$",
"vars",
")",
"{",
"$",
"this",
"->",
"input",
"=",
"Less_Parser",
"::",
"serializeVars",
"(",
"$",
"vars",
")",
";",
"$",
"this",
"->",
"_parse",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Allows a user to set variables values
@param array $vars
@return Less_Parser
|
[
"Allows",
"a",
"user",
"to",
"set",
"variables",
"values"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Parser.php#L383-L389
|
220,389
|
moodle/moodle
|
lib/lessphp/Parser.php
|
Less_Parser.SetImportDirs
|
public function SetImportDirs( $dirs ){
Less_Parser::$options['import_dirs'] = array();
foreach($dirs as $path => $uri_root){
$path = self::WinPath($path);
if( !empty($path) ){
$path = rtrim($path,'/').'/';
}
if ( !is_callable($uri_root) ){
$uri_root = self::WinPath($uri_root);
if( !empty($uri_root) ){
$uri_root = rtrim($uri_root,'/').'/';
}
}
Less_Parser::$options['import_dirs'][$path] = $uri_root;
}
}
|
php
|
public function SetImportDirs( $dirs ){
Less_Parser::$options['import_dirs'] = array();
foreach($dirs as $path => $uri_root){
$path = self::WinPath($path);
if( !empty($path) ){
$path = rtrim($path,'/').'/';
}
if ( !is_callable($uri_root) ){
$uri_root = self::WinPath($uri_root);
if( !empty($uri_root) ){
$uri_root = rtrim($uri_root,'/').'/';
}
}
Less_Parser::$options['import_dirs'][$path] = $uri_root;
}
}
|
[
"public",
"function",
"SetImportDirs",
"(",
"$",
"dirs",
")",
"{",
"Less_Parser",
"::",
"$",
"options",
"[",
"'import_dirs'",
"]",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"dirs",
"as",
"$",
"path",
"=>",
"$",
"uri_root",
")",
"{",
"$",
"path",
"=",
"self",
"::",
"WinPath",
"(",
"$",
"path",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"path",
")",
")",
"{",
"$",
"path",
"=",
"rtrim",
"(",
"$",
"path",
",",
"'/'",
")",
".",
"'/'",
";",
"}",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"uri_root",
")",
")",
"{",
"$",
"uri_root",
"=",
"self",
"::",
"WinPath",
"(",
"$",
"uri_root",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"uri_root",
")",
")",
"{",
"$",
"uri_root",
"=",
"rtrim",
"(",
"$",
"uri_root",
",",
"'/'",
")",
".",
"'/'",
";",
"}",
"}",
"Less_Parser",
"::",
"$",
"options",
"[",
"'import_dirs'",
"]",
"[",
"$",
"path",
"]",
"=",
"$",
"uri_root",
";",
"}",
"}"
] |
Set a list of directories or callbacks the parser should use for determining import paths
@param array $dirs
|
[
"Set",
"a",
"list",
"of",
"directories",
"or",
"callbacks",
"the",
"parser",
"should",
"use",
"for",
"determining",
"import",
"paths"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Parser.php#L464-L483
|
220,390
|
moodle/moodle
|
lib/lessphp/Parser.php
|
Less_Parser.SetInput
|
public function SetInput( $file_path ){
if( $file_path ){
$this->input = file_get_contents( $file_path );
}
$this->pos = $this->furthest = 0;
// Remove potential UTF Byte Order Mark
$this->input = preg_replace('/\\G\xEF\xBB\xBF/', '', $this->input);
$this->input_len = strlen($this->input);
if( Less_Parser::$options['sourceMap'] && $this->env->currentFileInfo ){
$uri = $this->env->currentFileInfo['currentUri'];
Less_Parser::$contentsMap[$uri] = $this->input;
}
}
|
php
|
public function SetInput( $file_path ){
if( $file_path ){
$this->input = file_get_contents( $file_path );
}
$this->pos = $this->furthest = 0;
// Remove potential UTF Byte Order Mark
$this->input = preg_replace('/\\G\xEF\xBB\xBF/', '', $this->input);
$this->input_len = strlen($this->input);
if( Less_Parser::$options['sourceMap'] && $this->env->currentFileInfo ){
$uri = $this->env->currentFileInfo['currentUri'];
Less_Parser::$contentsMap[$uri] = $this->input;
}
}
|
[
"public",
"function",
"SetInput",
"(",
"$",
"file_path",
")",
"{",
"if",
"(",
"$",
"file_path",
")",
"{",
"$",
"this",
"->",
"input",
"=",
"file_get_contents",
"(",
"$",
"file_path",
")",
";",
"}",
"$",
"this",
"->",
"pos",
"=",
"$",
"this",
"->",
"furthest",
"=",
"0",
";",
"// Remove potential UTF Byte Order Mark",
"$",
"this",
"->",
"input",
"=",
"preg_replace",
"(",
"'/\\\\G\\xEF\\xBB\\xBF/'",
",",
"''",
",",
"$",
"this",
"->",
"input",
")",
";",
"$",
"this",
"->",
"input_len",
"=",
"strlen",
"(",
"$",
"this",
"->",
"input",
")",
";",
"if",
"(",
"Less_Parser",
"::",
"$",
"options",
"[",
"'sourceMap'",
"]",
"&&",
"$",
"this",
"->",
"env",
"->",
"currentFileInfo",
")",
"{",
"$",
"uri",
"=",
"$",
"this",
"->",
"env",
"->",
"currentFileInfo",
"[",
"'currentUri'",
"]",
";",
"Less_Parser",
"::",
"$",
"contentsMap",
"[",
"$",
"uri",
"]",
"=",
"$",
"this",
"->",
"input",
";",
"}",
"}"
] |
Set up the input buffer
|
[
"Set",
"up",
"the",
"input",
"buffer"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Parser.php#L588-L606
|
220,391
|
moodle/moodle
|
lib/lessphp/Parser.php
|
Less_Parser.UnsetInput
|
public function UnsetInput(){
unset($this->input, $this->pos, $this->input_len, $this->furthest);
$this->saveStack = array();
}
|
php
|
public function UnsetInput(){
unset($this->input, $this->pos, $this->input_len, $this->furthest);
$this->saveStack = array();
}
|
[
"public",
"function",
"UnsetInput",
"(",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"input",
",",
"$",
"this",
"->",
"pos",
",",
"$",
"this",
"->",
"input_len",
",",
"$",
"this",
"->",
"furthest",
")",
";",
"$",
"this",
"->",
"saveStack",
"=",
"array",
"(",
")",
";",
"}"
] |
Free up some memory
|
[
"Free",
"up",
"some",
"memory"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Parser.php#L613-L616
|
220,392
|
moodle/moodle
|
lib/lessphp/Parser.php
|
Less_Parser.match
|
private function match($toks){
// The match is confirmed, add the match length to `this::pos`,
// and consume any extra white-space characters (' ' || '\n')
// which come after that. The reason for this is that LeSS's
// grammar is mostly white-space insensitive.
//
foreach($toks as $tok){
$char = $tok[0];
if( $char === '/' ){
$match = $this->MatchReg($tok);
if( $match ){
return count($match) === 1 ? $match[0] : $match;
}
}elseif( $char === '#' ){
$match = $this->MatchChar($tok[1]);
}else{
// Non-terminal, match using a function call
$match = $this->$tok();
}
if( $match ){
return $match;
}
}
}
|
php
|
private function match($toks){
// The match is confirmed, add the match length to `this::pos`,
// and consume any extra white-space characters (' ' || '\n')
// which come after that. The reason for this is that LeSS's
// grammar is mostly white-space insensitive.
//
foreach($toks as $tok){
$char = $tok[0];
if( $char === '/' ){
$match = $this->MatchReg($tok);
if( $match ){
return count($match) === 1 ? $match[0] : $match;
}
}elseif( $char === '#' ){
$match = $this->MatchChar($tok[1]);
}else{
// Non-terminal, match using a function call
$match = $this->$tok();
}
if( $match ){
return $match;
}
}
}
|
[
"private",
"function",
"match",
"(",
"$",
"toks",
")",
"{",
"// The match is confirmed, add the match length to `this::pos`,",
"// and consume any extra white-space characters (' ' || '\\n')",
"// which come after that. The reason for this is that LeSS's",
"// grammar is mostly white-space insensitive.",
"//",
"foreach",
"(",
"$",
"toks",
"as",
"$",
"tok",
")",
"{",
"$",
"char",
"=",
"$",
"tok",
"[",
"0",
"]",
";",
"if",
"(",
"$",
"char",
"===",
"'/'",
")",
"{",
"$",
"match",
"=",
"$",
"this",
"->",
"MatchReg",
"(",
"$",
"tok",
")",
";",
"if",
"(",
"$",
"match",
")",
"{",
"return",
"count",
"(",
"$",
"match",
")",
"===",
"1",
"?",
"$",
"match",
"[",
"0",
"]",
":",
"$",
"match",
";",
"}",
"}",
"elseif",
"(",
"$",
"char",
"===",
"'#'",
")",
"{",
"$",
"match",
"=",
"$",
"this",
"->",
"MatchChar",
"(",
"$",
"tok",
"[",
"1",
"]",
")",
";",
"}",
"else",
"{",
"// Non-terminal, match using a function call",
"$",
"match",
"=",
"$",
"this",
"->",
"$",
"tok",
"(",
")",
";",
"}",
"if",
"(",
"$",
"match",
")",
"{",
"return",
"$",
"match",
";",
"}",
"}",
"}"
] |
Parse from a token, regexp or string, and move forward if match
@param array $toks
@return array
|
[
"Parse",
"from",
"a",
"token",
"regexp",
"or",
"string",
"and",
"move",
"forward",
"if",
"match"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Parser.php#L677-L709
|
220,393
|
moodle/moodle
|
lib/lessphp/Parser.php
|
Less_Parser.MatchChar
|
private function MatchChar($tok){
if( ($this->pos < $this->input_len) && ($this->input[$this->pos] === $tok) ){
$this->skipWhitespace(1);
return $tok;
}
}
|
php
|
private function MatchChar($tok){
if( ($this->pos < $this->input_len) && ($this->input[$this->pos] === $tok) ){
$this->skipWhitespace(1);
return $tok;
}
}
|
[
"private",
"function",
"MatchChar",
"(",
"$",
"tok",
")",
"{",
"if",
"(",
"(",
"$",
"this",
"->",
"pos",
"<",
"$",
"this",
"->",
"input_len",
")",
"&&",
"(",
"$",
"this",
"->",
"input",
"[",
"$",
"this",
"->",
"pos",
"]",
"===",
"$",
"tok",
")",
")",
"{",
"$",
"this",
"->",
"skipWhitespace",
"(",
"1",
")",
";",
"return",
"$",
"tok",
";",
"}",
"}"
] |
Match a single character in the input,
|
[
"Match",
"a",
"single",
"character",
"in",
"the",
"input"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Parser.php#L730-L735
|
220,394
|
moodle/moodle
|
lib/lessphp/Parser.php
|
Less_Parser.MatchReg
|
private function MatchReg($tok){
if( preg_match($tok, $this->input, $match, 0, $this->pos) ){
$this->skipWhitespace(strlen($match[0]));
return $match;
}
}
|
php
|
private function MatchReg($tok){
if( preg_match($tok, $this->input, $match, 0, $this->pos) ){
$this->skipWhitespace(strlen($match[0]));
return $match;
}
}
|
[
"private",
"function",
"MatchReg",
"(",
"$",
"tok",
")",
"{",
"if",
"(",
"preg_match",
"(",
"$",
"tok",
",",
"$",
"this",
"->",
"input",
",",
"$",
"match",
",",
"0",
",",
"$",
"this",
"->",
"pos",
")",
")",
"{",
"$",
"this",
"->",
"skipWhitespace",
"(",
"strlen",
"(",
"$",
"match",
"[",
"0",
"]",
")",
")",
";",
"return",
"$",
"match",
";",
"}",
"}"
] |
Match a regexp from the current start point
|
[
"Match",
"a",
"regexp",
"from",
"the",
"current",
"start",
"point"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Parser.php#L738-L744
|
220,395
|
moodle/moodle
|
lib/lessphp/Parser.php
|
Less_Parser.parseComment
|
private function parseComment(){
if( $this->input[$this->pos] !== '/' ){
return;
}
if( $this->input[$this->pos+1] === '/' ){
$match = $this->MatchReg('/\\G\/\/.*/');
return $this->NewObj4('Less_Tree_Comment',array($match[0], true, $this->pos, $this->env->currentFileInfo));
}
//$comment = $this->MatchReg('/\\G\/\*(?:[^*]|\*+[^\/*])*\*+\/\n?/');
$comment = $this->MatchReg('/\\G\/\*(?s).*?\*+\/\n?/');//not the same as less.js to prevent fatal errors
if( $comment ){
return $this->NewObj4('Less_Tree_Comment',array($comment[0], false, $this->pos, $this->env->currentFileInfo));
}
}
|
php
|
private function parseComment(){
if( $this->input[$this->pos] !== '/' ){
return;
}
if( $this->input[$this->pos+1] === '/' ){
$match = $this->MatchReg('/\\G\/\/.*/');
return $this->NewObj4('Less_Tree_Comment',array($match[0], true, $this->pos, $this->env->currentFileInfo));
}
//$comment = $this->MatchReg('/\\G\/\*(?:[^*]|\*+[^\/*])*\*+\/\n?/');
$comment = $this->MatchReg('/\\G\/\*(?s).*?\*+\/\n?/');//not the same as less.js to prevent fatal errors
if( $comment ){
return $this->NewObj4('Less_Tree_Comment',array($comment[0], false, $this->pos, $this->env->currentFileInfo));
}
}
|
[
"private",
"function",
"parseComment",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"input",
"[",
"$",
"this",
"->",
"pos",
"]",
"!==",
"'/'",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"input",
"[",
"$",
"this",
"->",
"pos",
"+",
"1",
"]",
"===",
"'/'",
")",
"{",
"$",
"match",
"=",
"$",
"this",
"->",
"MatchReg",
"(",
"'/\\\\G\\/\\/.*/'",
")",
";",
"return",
"$",
"this",
"->",
"NewObj4",
"(",
"'Less_Tree_Comment'",
",",
"array",
"(",
"$",
"match",
"[",
"0",
"]",
",",
"true",
",",
"$",
"this",
"->",
"pos",
",",
"$",
"this",
"->",
"env",
"->",
"currentFileInfo",
")",
")",
";",
"}",
"//$comment = $this->MatchReg('/\\\\G\\/\\*(?:[^*]|\\*+[^\\/*])*\\*+\\/\\n?/');",
"$",
"comment",
"=",
"$",
"this",
"->",
"MatchReg",
"(",
"'/\\\\G\\/\\*(?s).*?\\*+\\/\\n?/'",
")",
";",
"//not the same as less.js to prevent fatal errors",
"if",
"(",
"$",
"comment",
")",
"{",
"return",
"$",
"this",
"->",
"NewObj4",
"(",
"'Less_Tree_Comment'",
",",
"array",
"(",
"$",
"comment",
"[",
"0",
"]",
",",
"false",
",",
"$",
"this",
"->",
"pos",
",",
"$",
"this",
"->",
"env",
"->",
"currentFileInfo",
")",
")",
";",
"}",
"}"
] |
over them.
|
[
"over",
"them",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Parser.php#L891-L907
|
220,396
|
moodle/moodle
|
lib/lessphp/Parser.php
|
Less_Parser.parseEntitiesArguments
|
private function parseEntitiesArguments(){
$args = array();
while( true ){
$arg = $this->MatchFuncs( array('parseEntitiesAssignment','parseExpression') );
if( !$arg ){
break;
}
$args[] = $arg;
if( !$this->MatchChar(',') ){
break;
}
}
return $args;
}
|
php
|
private function parseEntitiesArguments(){
$args = array();
while( true ){
$arg = $this->MatchFuncs( array('parseEntitiesAssignment','parseExpression') );
if( !$arg ){
break;
}
$args[] = $arg;
if( !$this->MatchChar(',') ){
break;
}
}
return $args;
}
|
[
"private",
"function",
"parseEntitiesArguments",
"(",
")",
"{",
"$",
"args",
"=",
"array",
"(",
")",
";",
"while",
"(",
"true",
")",
"{",
"$",
"arg",
"=",
"$",
"this",
"->",
"MatchFuncs",
"(",
"array",
"(",
"'parseEntitiesAssignment'",
",",
"'parseExpression'",
")",
")",
";",
"if",
"(",
"!",
"$",
"arg",
")",
"{",
"break",
";",
"}",
"$",
"args",
"[",
"]",
"=",
"$",
"arg",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"MatchChar",
"(",
"','",
")",
")",
"{",
"break",
";",
"}",
"}",
"return",
"$",
"args",
";",
"}"
] |
Parse a list of arguments
@return array
|
[
"Parse",
"a",
"list",
"of",
"arguments"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Parser.php#L1044-L1059
|
220,397
|
moodle/moodle
|
lib/lessphp/Parser.php
|
Less_Parser.parseMultiplication
|
function parseMultiplication(){
$return = $m = $this->parseOperand();
if( $return ){
while( true ){
$isSpaced = $this->isWhitespace( -1 );
if( $this->PeekReg('/\\G\/[*\/]/') ){
break;
}
$op = $this->MatchChar('/');
if( !$op ){
$op = $this->MatchChar('*');
if( !$op ){
break;
}
}
$a = $this->parseOperand();
if(!$a) { break; }
$m->parensInOp = true;
$a->parensInOp = true;
$return = $this->NewObj3('Less_Tree_Operation',array( $op, array( $return, $a ), $isSpaced) );
}
}
return $return;
}
|
php
|
function parseMultiplication(){
$return = $m = $this->parseOperand();
if( $return ){
while( true ){
$isSpaced = $this->isWhitespace( -1 );
if( $this->PeekReg('/\\G\/[*\/]/') ){
break;
}
$op = $this->MatchChar('/');
if( !$op ){
$op = $this->MatchChar('*');
if( !$op ){
break;
}
}
$a = $this->parseOperand();
if(!$a) { break; }
$m->parensInOp = true;
$a->parensInOp = true;
$return = $this->NewObj3('Less_Tree_Operation',array( $op, array( $return, $a ), $isSpaced) );
}
}
return $return;
}
|
[
"function",
"parseMultiplication",
"(",
")",
"{",
"$",
"return",
"=",
"$",
"m",
"=",
"$",
"this",
"->",
"parseOperand",
"(",
")",
";",
"if",
"(",
"$",
"return",
")",
"{",
"while",
"(",
"true",
")",
"{",
"$",
"isSpaced",
"=",
"$",
"this",
"->",
"isWhitespace",
"(",
"-",
"1",
")",
";",
"if",
"(",
"$",
"this",
"->",
"PeekReg",
"(",
"'/\\\\G\\/[*\\/]/'",
")",
")",
"{",
"break",
";",
"}",
"$",
"op",
"=",
"$",
"this",
"->",
"MatchChar",
"(",
"'/'",
")",
";",
"if",
"(",
"!",
"$",
"op",
")",
"{",
"$",
"op",
"=",
"$",
"this",
"->",
"MatchChar",
"(",
"'*'",
")",
";",
"if",
"(",
"!",
"$",
"op",
")",
"{",
"break",
";",
"}",
"}",
"$",
"a",
"=",
"$",
"this",
"->",
"parseOperand",
"(",
")",
";",
"if",
"(",
"!",
"$",
"a",
")",
"{",
"break",
";",
"}",
"$",
"m",
"->",
"parensInOp",
"=",
"true",
";",
"$",
"a",
"->",
"parensInOp",
"=",
"true",
";",
"$",
"return",
"=",
"$",
"this",
"->",
"NewObj3",
"(",
"'Less_Tree_Operation'",
",",
"array",
"(",
"$",
"op",
",",
"array",
"(",
"$",
"return",
",",
"$",
"a",
")",
",",
"$",
"isSpaced",
")",
")",
";",
"}",
"}",
"return",
"$",
"return",
";",
"}"
] |
Parses multiplication operation
@return Less_Tree_Operation|null
|
[
"Parses",
"multiplication",
"operation"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Parser.php#L2222-L2253
|
220,398
|
moodle/moodle
|
lib/lessphp/Parser.php
|
Less_Parser.parseAddition
|
private function parseAddition (){
$return = $m = $this->parseMultiplication();
if( $return ){
while( true ){
$isSpaced = $this->isWhitespace( -1 );
$op = $this->MatchReg('/\\G[-+]\s+/');
if( $op ){
$op = $op[0];
}else{
if( !$isSpaced ){
$op = $this->match(array('#+','#-'));
}
if( !$op ){
break;
}
}
$a = $this->parseMultiplication();
if( !$a ){
break;
}
$m->parensInOp = true;
$a->parensInOp = true;
$return = $this->NewObj3('Less_Tree_Operation',array($op, array($return, $a), $isSpaced));
}
}
return $return;
}
|
php
|
private function parseAddition (){
$return = $m = $this->parseMultiplication();
if( $return ){
while( true ){
$isSpaced = $this->isWhitespace( -1 );
$op = $this->MatchReg('/\\G[-+]\s+/');
if( $op ){
$op = $op[0];
}else{
if( !$isSpaced ){
$op = $this->match(array('#+','#-'));
}
if( !$op ){
break;
}
}
$a = $this->parseMultiplication();
if( !$a ){
break;
}
$m->parensInOp = true;
$a->parensInOp = true;
$return = $this->NewObj3('Less_Tree_Operation',array($op, array($return, $a), $isSpaced));
}
}
return $return;
}
|
[
"private",
"function",
"parseAddition",
"(",
")",
"{",
"$",
"return",
"=",
"$",
"m",
"=",
"$",
"this",
"->",
"parseMultiplication",
"(",
")",
";",
"if",
"(",
"$",
"return",
")",
"{",
"while",
"(",
"true",
")",
"{",
"$",
"isSpaced",
"=",
"$",
"this",
"->",
"isWhitespace",
"(",
"-",
"1",
")",
";",
"$",
"op",
"=",
"$",
"this",
"->",
"MatchReg",
"(",
"'/\\\\G[-+]\\s+/'",
")",
";",
"if",
"(",
"$",
"op",
")",
"{",
"$",
"op",
"=",
"$",
"op",
"[",
"0",
"]",
";",
"}",
"else",
"{",
"if",
"(",
"!",
"$",
"isSpaced",
")",
"{",
"$",
"op",
"=",
"$",
"this",
"->",
"match",
"(",
"array",
"(",
"'#+'",
",",
"'#-'",
")",
")",
";",
"}",
"if",
"(",
"!",
"$",
"op",
")",
"{",
"break",
";",
"}",
"}",
"$",
"a",
"=",
"$",
"this",
"->",
"parseMultiplication",
"(",
")",
";",
"if",
"(",
"!",
"$",
"a",
")",
"{",
"break",
";",
"}",
"$",
"m",
"->",
"parensInOp",
"=",
"true",
";",
"$",
"a",
"->",
"parensInOp",
"=",
"true",
";",
"$",
"return",
"=",
"$",
"this",
"->",
"NewObj3",
"(",
"'Less_Tree_Operation'",
",",
"array",
"(",
"$",
"op",
",",
"array",
"(",
"$",
"return",
",",
"$",
"a",
")",
",",
"$",
"isSpaced",
")",
")",
";",
"}",
"}",
"return",
"$",
"return",
";",
"}"
] |
Parses an addition operation
@return Less_Tree_Operation|null
|
[
"Parses",
"an",
"addition",
"operation"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Parser.php#L2261-L2293
|
220,399
|
moodle/moodle
|
lib/lessphp/Parser.php
|
Less_Parser.parseConditions
|
private function parseConditions() {
$index = $this->pos;
$return = $a = $this->parseCondition();
if( $a ){
while( true ){
if( !$this->PeekReg('/\\G,\s*(not\s*)?\(/') || !$this->MatchChar(',') ){
break;
}
$b = $this->parseCondition();
if( !$b ){
break;
}
$return = $this->NewObj4('Less_Tree_Condition',array('or', $return, $b, $index));
}
return $return;
}
}
|
php
|
private function parseConditions() {
$index = $this->pos;
$return = $a = $this->parseCondition();
if( $a ){
while( true ){
if( !$this->PeekReg('/\\G,\s*(not\s*)?\(/') || !$this->MatchChar(',') ){
break;
}
$b = $this->parseCondition();
if( !$b ){
break;
}
$return = $this->NewObj4('Less_Tree_Condition',array('or', $return, $b, $index));
}
return $return;
}
}
|
[
"private",
"function",
"parseConditions",
"(",
")",
"{",
"$",
"index",
"=",
"$",
"this",
"->",
"pos",
";",
"$",
"return",
"=",
"$",
"a",
"=",
"$",
"this",
"->",
"parseCondition",
"(",
")",
";",
"if",
"(",
"$",
"a",
")",
"{",
"while",
"(",
"true",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"PeekReg",
"(",
"'/\\\\G,\\s*(not\\s*)?\\(/'",
")",
"||",
"!",
"$",
"this",
"->",
"MatchChar",
"(",
"','",
")",
")",
"{",
"break",
";",
"}",
"$",
"b",
"=",
"$",
"this",
"->",
"parseCondition",
"(",
")",
";",
"if",
"(",
"!",
"$",
"b",
")",
"{",
"break",
";",
"}",
"$",
"return",
"=",
"$",
"this",
"->",
"NewObj4",
"(",
"'Less_Tree_Condition'",
",",
"array",
"(",
"'or'",
",",
"$",
"return",
",",
"$",
"b",
",",
"$",
"index",
")",
")",
";",
"}",
"return",
"$",
"return",
";",
"}",
"}"
] |
Parses the conditions
@return Less_Tree_Condition|null
|
[
"Parses",
"the",
"conditions"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Parser.php#L2301-L2318
|
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.