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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
218,800
|
moodle/moodle
|
mod/lesson/renderer.php
|
mod_lesson_renderer.add_page_links
|
public function add_page_links(lesson $lesson, $prevpageid=false) {
global $CFG;
$links = array();
$importquestionsurl = new moodle_url('/mod/lesson/import.php',array('id'=>$this->page->cm->id, 'pageid'=>$prevpageid));
$links[] = html_writer::link($importquestionsurl, get_string('importquestions', 'lesson'));
$manager = lesson_page_type_manager::get($lesson);
foreach($manager->get_add_page_type_links($prevpageid) as $link) {
$links[] = html_writer::link($link['addurl'], $link['name']);
}
$addquestionurl = new moodle_url('/mod/lesson/editpage.php', array('id'=>$this->page->cm->id, 'pageid'=>$prevpageid));
$links[] = html_writer::link($addquestionurl, get_string('addaquestionpagehere', 'lesson'));
return $this->output->box(implode(" | \n", $links), 'addlinks');
}
|
php
|
public function add_page_links(lesson $lesson, $prevpageid=false) {
global $CFG;
$links = array();
$importquestionsurl = new moodle_url('/mod/lesson/import.php',array('id'=>$this->page->cm->id, 'pageid'=>$prevpageid));
$links[] = html_writer::link($importquestionsurl, get_string('importquestions', 'lesson'));
$manager = lesson_page_type_manager::get($lesson);
foreach($manager->get_add_page_type_links($prevpageid) as $link) {
$links[] = html_writer::link($link['addurl'], $link['name']);
}
$addquestionurl = new moodle_url('/mod/lesson/editpage.php', array('id'=>$this->page->cm->id, 'pageid'=>$prevpageid));
$links[] = html_writer::link($addquestionurl, get_string('addaquestionpagehere', 'lesson'));
return $this->output->box(implode(" | \n", $links), 'addlinks');
}
|
[
"public",
"function",
"add_page_links",
"(",
"lesson",
"$",
"lesson",
",",
"$",
"prevpageid",
"=",
"false",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"links",
"=",
"array",
"(",
")",
";",
"$",
"importquestionsurl",
"=",
"new",
"moodle_url",
"(",
"'/mod/lesson/import.php'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"page",
"->",
"cm",
"->",
"id",
",",
"'pageid'",
"=>",
"$",
"prevpageid",
")",
")",
";",
"$",
"links",
"[",
"]",
"=",
"html_writer",
"::",
"link",
"(",
"$",
"importquestionsurl",
",",
"get_string",
"(",
"'importquestions'",
",",
"'lesson'",
")",
")",
";",
"$",
"manager",
"=",
"lesson_page_type_manager",
"::",
"get",
"(",
"$",
"lesson",
")",
";",
"foreach",
"(",
"$",
"manager",
"->",
"get_add_page_type_links",
"(",
"$",
"prevpageid",
")",
"as",
"$",
"link",
")",
"{",
"$",
"links",
"[",
"]",
"=",
"html_writer",
"::",
"link",
"(",
"$",
"link",
"[",
"'addurl'",
"]",
",",
"$",
"link",
"[",
"'name'",
"]",
")",
";",
"}",
"$",
"addquestionurl",
"=",
"new",
"moodle_url",
"(",
"'/mod/lesson/editpage.php'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"page",
"->",
"cm",
"->",
"id",
",",
"'pageid'",
"=>",
"$",
"prevpageid",
")",
")",
";",
"$",
"links",
"[",
"]",
"=",
"html_writer",
"::",
"link",
"(",
"$",
"addquestionurl",
",",
"get_string",
"(",
"'addaquestionpagehere'",
",",
"'lesson'",
")",
")",
";",
"return",
"$",
"this",
"->",
"output",
"->",
"box",
"(",
"implode",
"(",
"\" | \\n\"",
",",
"$",
"links",
")",
",",
"'addlinks'",
")",
";",
"}"
] |
Returns HTML to display the add page links
@param lesson $lesson
@param int $prevpageid
@return string
|
[
"Returns",
"HTML",
"to",
"display",
"the",
"add",
"page",
"links"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/renderer.php#L347-L364
|
218,801
|
moodle/moodle
|
mod/lesson/renderer.php
|
mod_lesson_renderer.progress_bar
|
public function progress_bar(lesson $lesson, $progress = null) {
$context = context_module::instance($this->page->cm->id);
// lesson setting to turn progress bar on or off
if (!$lesson->progressbar) {
return '';
}
// catch teachers
if (has_capability('mod/lesson:manage', $context)) {
return $this->output->notification(get_string('progressbarteacherwarning2', 'lesson'));
}
if ($progress === null) {
$progress = $lesson->calculate_progress();
}
$content = html_writer::start_tag('div');
$content .= html_writer::start_tag('div', array('class' => 'progress'));
$content .= html_writer::start_tag('div', array('class' => 'progress-bar bar', 'role' => 'progressbar',
'style' => 'width: ' . $progress .'%', 'aria-valuenow' => $progress, 'aria-valuemin' => 0, 'aria-valuemax' => 100));
$content .= $progress . "%";
$content .= html_writer::end_tag('div');
$content .= html_writer::end_tag('div');
$printprogress = html_writer::tag('div', get_string('progresscompleted', 'lesson', $progress) . $content);
return $this->output->box($printprogress, 'progress_bar');
}
|
php
|
public function progress_bar(lesson $lesson, $progress = null) {
$context = context_module::instance($this->page->cm->id);
// lesson setting to turn progress bar on or off
if (!$lesson->progressbar) {
return '';
}
// catch teachers
if (has_capability('mod/lesson:manage', $context)) {
return $this->output->notification(get_string('progressbarteacherwarning2', 'lesson'));
}
if ($progress === null) {
$progress = $lesson->calculate_progress();
}
$content = html_writer::start_tag('div');
$content .= html_writer::start_tag('div', array('class' => 'progress'));
$content .= html_writer::start_tag('div', array('class' => 'progress-bar bar', 'role' => 'progressbar',
'style' => 'width: ' . $progress .'%', 'aria-valuenow' => $progress, 'aria-valuemin' => 0, 'aria-valuemax' => 100));
$content .= $progress . "%";
$content .= html_writer::end_tag('div');
$content .= html_writer::end_tag('div');
$printprogress = html_writer::tag('div', get_string('progresscompleted', 'lesson', $progress) . $content);
return $this->output->box($printprogress, 'progress_bar');
}
|
[
"public",
"function",
"progress_bar",
"(",
"lesson",
"$",
"lesson",
",",
"$",
"progress",
"=",
"null",
")",
"{",
"$",
"context",
"=",
"context_module",
"::",
"instance",
"(",
"$",
"this",
"->",
"page",
"->",
"cm",
"->",
"id",
")",
";",
"// lesson setting to turn progress bar on or off",
"if",
"(",
"!",
"$",
"lesson",
"->",
"progressbar",
")",
"{",
"return",
"''",
";",
"}",
"// catch teachers",
"if",
"(",
"has_capability",
"(",
"'mod/lesson:manage'",
",",
"$",
"context",
")",
")",
"{",
"return",
"$",
"this",
"->",
"output",
"->",
"notification",
"(",
"get_string",
"(",
"'progressbarteacherwarning2'",
",",
"'lesson'",
")",
")",
";",
"}",
"if",
"(",
"$",
"progress",
"===",
"null",
")",
"{",
"$",
"progress",
"=",
"$",
"lesson",
"->",
"calculate_progress",
"(",
")",
";",
"}",
"$",
"content",
"=",
"html_writer",
"::",
"start_tag",
"(",
"'div'",
")",
";",
"$",
"content",
".=",
"html_writer",
"::",
"start_tag",
"(",
"'div'",
",",
"array",
"(",
"'class'",
"=>",
"'progress'",
")",
")",
";",
"$",
"content",
".=",
"html_writer",
"::",
"start_tag",
"(",
"'div'",
",",
"array",
"(",
"'class'",
"=>",
"'progress-bar bar'",
",",
"'role'",
"=>",
"'progressbar'",
",",
"'style'",
"=>",
"'width: '",
".",
"$",
"progress",
".",
"'%'",
",",
"'aria-valuenow'",
"=>",
"$",
"progress",
",",
"'aria-valuemin'",
"=>",
"0",
",",
"'aria-valuemax'",
"=>",
"100",
")",
")",
";",
"$",
"content",
".=",
"$",
"progress",
".",
"\"%\"",
";",
"$",
"content",
".=",
"html_writer",
"::",
"end_tag",
"(",
"'div'",
")",
";",
"$",
"content",
".=",
"html_writer",
"::",
"end_tag",
"(",
"'div'",
")",
";",
"$",
"printprogress",
"=",
"html_writer",
"::",
"tag",
"(",
"'div'",
",",
"get_string",
"(",
"'progresscompleted'",
",",
"'lesson'",
",",
"$",
"progress",
")",
".",
"$",
"content",
")",
";",
"return",
"$",
"this",
"->",
"output",
"->",
"box",
"(",
"$",
"printprogress",
",",
"'progress_bar'",
")",
";",
"}"
] |
Returns HTML to display a progress bar of progression through a lesson
@param lesson $lesson
@param int $progress optional, if empty it will be calculated
@return string
|
[
"Returns",
"HTML",
"to",
"display",
"a",
"progress",
"bar",
"of",
"progression",
"through",
"a",
"lesson"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/renderer.php#L491-L517
|
218,802
|
moodle/moodle
|
mod/lesson/renderer.php
|
mod_lesson_renderer.slideshow_start
|
public function slideshow_start(lesson $lesson) {
$attributes = array();
$attributes['class'] = 'slideshow';
$attributes['style'] = 'background-color:'.$lesson->properties()->bgcolor.';height:'.
$lesson->properties()->height.'px;width:'.$lesson->properties()->width.'px;';
$output = html_writer::start_tag('div', $attributes);
return $output;
}
|
php
|
public function slideshow_start(lesson $lesson) {
$attributes = array();
$attributes['class'] = 'slideshow';
$attributes['style'] = 'background-color:'.$lesson->properties()->bgcolor.';height:'.
$lesson->properties()->height.'px;width:'.$lesson->properties()->width.'px;';
$output = html_writer::start_tag('div', $attributes);
return $output;
}
|
[
"public",
"function",
"slideshow_start",
"(",
"lesson",
"$",
"lesson",
")",
"{",
"$",
"attributes",
"=",
"array",
"(",
")",
";",
"$",
"attributes",
"[",
"'class'",
"]",
"=",
"'slideshow'",
";",
"$",
"attributes",
"[",
"'style'",
"]",
"=",
"'background-color:'",
".",
"$",
"lesson",
"->",
"properties",
"(",
")",
"->",
"bgcolor",
".",
"';height:'",
".",
"$",
"lesson",
"->",
"properties",
"(",
")",
"->",
"height",
".",
"'px;width:'",
".",
"$",
"lesson",
"->",
"properties",
"(",
")",
"->",
"width",
".",
"'px;'",
";",
"$",
"output",
"=",
"html_writer",
"::",
"start_tag",
"(",
"'div'",
",",
"$",
"attributes",
")",
";",
"return",
"$",
"output",
";",
"}"
] |
Returns HTML to show the start of a slideshow
@param lesson $lesson
|
[
"Returns",
"HTML",
"to",
"show",
"the",
"start",
"of",
"a",
"slideshow"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/renderer.php#L523-L530
|
218,803
|
moodle/moodle
|
mod/lesson/renderer.php
|
mod_lesson_renderer.paragraph
|
public function paragraph($contents, $class='') {
$attributes = array();
if ($class !== '') {
$attributes['class'] = $class;
}
$output = html_writer::tag('p', $contents, $attributes);
return $output;
}
|
php
|
public function paragraph($contents, $class='') {
$attributes = array();
if ($class !== '') {
$attributes['class'] = $class;
}
$output = html_writer::tag('p', $contents, $attributes);
return $output;
}
|
[
"public",
"function",
"paragraph",
"(",
"$",
"contents",
",",
"$",
"class",
"=",
"''",
")",
"{",
"$",
"attributes",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"class",
"!==",
"''",
")",
"{",
"$",
"attributes",
"[",
"'class'",
"]",
"=",
"$",
"class",
";",
"}",
"$",
"output",
"=",
"html_writer",
"::",
"tag",
"(",
"'p'",
",",
"$",
"contents",
",",
"$",
"attributes",
")",
";",
"return",
"$",
"output",
";",
"}"
] |
Returns a P tag containing contents
@param string $contents
@param string $class
|
[
"Returns",
"a",
"P",
"tag",
"containing",
"contents"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lesson/renderer.php#L543-L550
|
218,804
|
moodle/moodle
|
mod/quiz/report/statistics/statistics_table.php
|
quiz_statistics_table.col_number
|
protected function col_number($questionstat) {
if ($this->is_calculated_question_summary($questionstat)) {
return '';
}
if (!isset($questionstat->question->number)) {
return '';
}
$number = $questionstat->question->number;
if (isset($questionstat->subqdisplayorder)) {
$number = $number . '.'.$questionstat->subqdisplayorder;
}
if ($questionstat->question->qtype != 'random' && !is_null($questionstat->variant)) {
$number = $number . '.'.$questionstat->variant;
}
return $number;
}
|
php
|
protected function col_number($questionstat) {
if ($this->is_calculated_question_summary($questionstat)) {
return '';
}
if (!isset($questionstat->question->number)) {
return '';
}
$number = $questionstat->question->number;
if (isset($questionstat->subqdisplayorder)) {
$number = $number . '.'.$questionstat->subqdisplayorder;
}
if ($questionstat->question->qtype != 'random' && !is_null($questionstat->variant)) {
$number = $number . '.'.$questionstat->variant;
}
return $number;
}
|
[
"protected",
"function",
"col_number",
"(",
"$",
"questionstat",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"is_calculated_question_summary",
"(",
"$",
"questionstat",
")",
")",
"{",
"return",
"''",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"questionstat",
"->",
"question",
"->",
"number",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"number",
"=",
"$",
"questionstat",
"->",
"question",
"->",
"number",
";",
"if",
"(",
"isset",
"(",
"$",
"questionstat",
"->",
"subqdisplayorder",
")",
")",
"{",
"$",
"number",
"=",
"$",
"number",
".",
"'.'",
".",
"$",
"questionstat",
"->",
"subqdisplayorder",
";",
"}",
"if",
"(",
"$",
"questionstat",
"->",
"question",
"->",
"qtype",
"!=",
"'random'",
"&&",
"!",
"is_null",
"(",
"$",
"questionstat",
"->",
"variant",
")",
")",
"{",
"$",
"number",
"=",
"$",
"number",
".",
"'.'",
".",
"$",
"questionstat",
"->",
"variant",
";",
"}",
"return",
"$",
"number",
";",
"}"
] |
The question number.
@param \core_question\statistics\questions\calculated $questionstat stats for the question.
@return string contents of this table cell.
|
[
"The",
"question",
"number",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/statistics/statistics_table.php#L162-L180
|
218,805
|
moodle/moodle
|
mod/quiz/report/statistics/statistics_table.php
|
quiz_statistics_table.col_s
|
protected function col_s($questionstat) {
if ($this->is_calculated_question_summary($questionstat)) {
list($min, $max) = $questionstat->get_min_max_of('s');
$min = $min ?: 0;
$max = $max ?: 0;
return $this->format_range($min, $max);
} else if (!isset($questionstat->s)) {
return 0;
} else {
return $questionstat->s;
}
}
|
php
|
protected function col_s($questionstat) {
if ($this->is_calculated_question_summary($questionstat)) {
list($min, $max) = $questionstat->get_min_max_of('s');
$min = $min ?: 0;
$max = $max ?: 0;
return $this->format_range($min, $max);
} else if (!isset($questionstat->s)) {
return 0;
} else {
return $questionstat->s;
}
}
|
[
"protected",
"function",
"col_s",
"(",
"$",
"questionstat",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"is_calculated_question_summary",
"(",
"$",
"questionstat",
")",
")",
"{",
"list",
"(",
"$",
"min",
",",
"$",
"max",
")",
"=",
"$",
"questionstat",
"->",
"get_min_max_of",
"(",
"'s'",
")",
";",
"$",
"min",
"=",
"$",
"min",
"?",
":",
"0",
";",
"$",
"max",
"=",
"$",
"max",
"?",
":",
"0",
";",
"return",
"$",
"this",
"->",
"format_range",
"(",
"$",
"min",
",",
"$",
"max",
")",
";",
"}",
"else",
"if",
"(",
"!",
"isset",
"(",
"$",
"questionstat",
"->",
"s",
")",
")",
"{",
"return",
"0",
";",
"}",
"else",
"{",
"return",
"$",
"questionstat",
"->",
"s",
";",
"}",
"}"
] |
The number of attempts at this question.
@param \core_question\statistics\questions\calculated $questionstat stats for the question.
@return string contents of this table cell.
|
[
"The",
"number",
"of",
"attempts",
"at",
"this",
"question",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/statistics/statistics_table.php#L301-L312
|
218,806
|
moodle/moodle
|
mod/quiz/report/statistics/statistics_table.php
|
quiz_statistics_table.col_sd
|
protected function col_sd($questionstat) {
if ($this->is_calculated_question_summary($questionstat)) {
list($min, $max) = $questionstat->get_min_max_of('sd');
return $this->format_percentage_range($min, $max);
} else if (is_null($questionstat->sd) || $questionstat->maxmark == 0) {
return '';
} else {
return $this->format_percentage($questionstat->sd / $questionstat->maxmark);
}
}
|
php
|
protected function col_sd($questionstat) {
if ($this->is_calculated_question_summary($questionstat)) {
list($min, $max) = $questionstat->get_min_max_of('sd');
return $this->format_percentage_range($min, $max);
} else if (is_null($questionstat->sd) || $questionstat->maxmark == 0) {
return '';
} else {
return $this->format_percentage($questionstat->sd / $questionstat->maxmark);
}
}
|
[
"protected",
"function",
"col_sd",
"(",
"$",
"questionstat",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"is_calculated_question_summary",
"(",
"$",
"questionstat",
")",
")",
"{",
"list",
"(",
"$",
"min",
",",
"$",
"max",
")",
"=",
"$",
"questionstat",
"->",
"get_min_max_of",
"(",
"'sd'",
")",
";",
"return",
"$",
"this",
"->",
"format_percentage_range",
"(",
"$",
"min",
",",
"$",
"max",
")",
";",
"}",
"else",
"if",
"(",
"is_null",
"(",
"$",
"questionstat",
"->",
"sd",
")",
"||",
"$",
"questionstat",
"->",
"maxmark",
"==",
"0",
")",
"{",
"return",
"''",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"format_percentage",
"(",
"$",
"questionstat",
"->",
"sd",
"/",
"$",
"questionstat",
"->",
"maxmark",
")",
";",
"}",
"}"
] |
The standard deviation of the fractions.
@param \core_question\statistics\questions\calculated $questionstat stats for the question.
@return string contents of this table cell.
|
[
"The",
"standard",
"deviation",
"of",
"the",
"fractions",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/statistics/statistics_table.php#L335-L344
|
218,807
|
moodle/moodle
|
mod/quiz/report/statistics/statistics_table.php
|
quiz_statistics_table.col_random_guess_score
|
protected function col_random_guess_score($questionstat) {
if ($this->is_calculated_question_summary($questionstat)) {
list($min, $max) = $questionstat->get_min_max_of('randomguessscore');
return $this->format_percentage_range($min, $max);
} else if (is_null($questionstat->randomguessscore)) {
return '';
} else {
return $this->format_percentage($questionstat->randomguessscore);
}
}
|
php
|
protected function col_random_guess_score($questionstat) {
if ($this->is_calculated_question_summary($questionstat)) {
list($min, $max) = $questionstat->get_min_max_of('randomguessscore');
return $this->format_percentage_range($min, $max);
} else if (is_null($questionstat->randomguessscore)) {
return '';
} else {
return $this->format_percentage($questionstat->randomguessscore);
}
}
|
[
"protected",
"function",
"col_random_guess_score",
"(",
"$",
"questionstat",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"is_calculated_question_summary",
"(",
"$",
"questionstat",
")",
")",
"{",
"list",
"(",
"$",
"min",
",",
"$",
"max",
")",
"=",
"$",
"questionstat",
"->",
"get_min_max_of",
"(",
"'randomguessscore'",
")",
";",
"return",
"$",
"this",
"->",
"format_percentage_range",
"(",
"$",
"min",
",",
"$",
"max",
")",
";",
"}",
"else",
"if",
"(",
"is_null",
"(",
"$",
"questionstat",
"->",
"randomguessscore",
")",
")",
"{",
"return",
"''",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"format_percentage",
"(",
"$",
"questionstat",
"->",
"randomguessscore",
")",
";",
"}",
"}"
] |
An estimate of the fraction a student would get by guessing randomly.
@param \core_question\statistics\questions\calculated $questionstat stats for the question.
@return string contents of this table cell.
|
[
"An",
"estimate",
"of",
"the",
"fraction",
"a",
"student",
"would",
"get",
"by",
"guessing",
"randomly",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/statistics/statistics_table.php#L351-L360
|
218,808
|
moodle/moodle
|
mod/quiz/report/statistics/statistics_table.php
|
quiz_statistics_table.col_intended_weight
|
protected function col_intended_weight($questionstat) {
if ($this->is_calculated_question_summary($questionstat)) {
list($min, $max) = $questionstat->get_min_max_of('maxmark');
if (is_null($min) && is_null($max)) {
return '';
} else {
$min = quiz_report_scale_summarks_as_percentage($min, $this->quiz);
$max = quiz_report_scale_summarks_as_percentage($max, $this->quiz);
return $this->format_range($min, $max);
}
} else {
return quiz_report_scale_summarks_as_percentage($questionstat->maxmark, $this->quiz);
}
}
|
php
|
protected function col_intended_weight($questionstat) {
if ($this->is_calculated_question_summary($questionstat)) {
list($min, $max) = $questionstat->get_min_max_of('maxmark');
if (is_null($min) && is_null($max)) {
return '';
} else {
$min = quiz_report_scale_summarks_as_percentage($min, $this->quiz);
$max = quiz_report_scale_summarks_as_percentage($max, $this->quiz);
return $this->format_range($min, $max);
}
} else {
return quiz_report_scale_summarks_as_percentage($questionstat->maxmark, $this->quiz);
}
}
|
[
"protected",
"function",
"col_intended_weight",
"(",
"$",
"questionstat",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"is_calculated_question_summary",
"(",
"$",
"questionstat",
")",
")",
"{",
"list",
"(",
"$",
"min",
",",
"$",
"max",
")",
"=",
"$",
"questionstat",
"->",
"get_min_max_of",
"(",
"'maxmark'",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"min",
")",
"&&",
"is_null",
"(",
"$",
"max",
")",
")",
"{",
"return",
"''",
";",
"}",
"else",
"{",
"$",
"min",
"=",
"quiz_report_scale_summarks_as_percentage",
"(",
"$",
"min",
",",
"$",
"this",
"->",
"quiz",
")",
";",
"$",
"max",
"=",
"quiz_report_scale_summarks_as_percentage",
"(",
"$",
"max",
",",
"$",
"this",
"->",
"quiz",
")",
";",
"return",
"$",
"this",
"->",
"format_range",
"(",
"$",
"min",
",",
"$",
"max",
")",
";",
"}",
"}",
"else",
"{",
"return",
"quiz_report_scale_summarks_as_percentage",
"(",
"$",
"questionstat",
"->",
"maxmark",
",",
"$",
"this",
"->",
"quiz",
")",
";",
"}",
"}"
] |
The intended question weight. Maximum mark for the question as a percentage
of maximum mark for the quiz. That is, the indended influence this question
on the student's overall mark.
@param \core_question\statistics\questions\calculated $questionstat stats for the question.
@return string contents of this table cell.
|
[
"The",
"intended",
"question",
"weight",
".",
"Maximum",
"mark",
"for",
"the",
"question",
"as",
"a",
"percentage",
"of",
"maximum",
"mark",
"for",
"the",
"quiz",
".",
"That",
"is",
"the",
"indended",
"influence",
"this",
"question",
"on",
"the",
"student",
"s",
"overall",
"mark",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/statistics/statistics_table.php#L369-L383
|
218,809
|
moodle/moodle
|
mod/quiz/report/statistics/statistics_table.php
|
quiz_statistics_table.col_effective_weight
|
protected function col_effective_weight($questionstat) {
global $OUTPUT;
if ($this->is_calculated_question_summary($questionstat)) {
list($min, $max) = $questionstat->get_min_max_of('effectiveweight');
if (is_null($min) && is_null($max)) {
return '';
} else {
list( , $negcovar) = $questionstat->get_min_max_of('negcovar');
if ($negcovar) {
$min = get_string('negcovar', 'quiz_statistics');
}
return $this->format_range($min, $max);
}
} else if (is_null($questionstat->effectiveweight)) {
return '';
} else if ($questionstat->negcovar) {
$negcovar = get_string('negcovar', 'quiz_statistics');
if (!$this->is_downloading()) {
$negcovar = html_writer::tag('div',
$negcovar . $OUTPUT->help_icon('negcovar', 'quiz_statistics'),
array('class' => 'negcovar'));
}
return $negcovar;
} else {
return $this->format_percentage($questionstat->effectiveweight, false);
}
}
|
php
|
protected function col_effective_weight($questionstat) {
global $OUTPUT;
if ($this->is_calculated_question_summary($questionstat)) {
list($min, $max) = $questionstat->get_min_max_of('effectiveweight');
if (is_null($min) && is_null($max)) {
return '';
} else {
list( , $negcovar) = $questionstat->get_min_max_of('negcovar');
if ($negcovar) {
$min = get_string('negcovar', 'quiz_statistics');
}
return $this->format_range($min, $max);
}
} else if (is_null($questionstat->effectiveweight)) {
return '';
} else if ($questionstat->negcovar) {
$negcovar = get_string('negcovar', 'quiz_statistics');
if (!$this->is_downloading()) {
$negcovar = html_writer::tag('div',
$negcovar . $OUTPUT->help_icon('negcovar', 'quiz_statistics'),
array('class' => 'negcovar'));
}
return $negcovar;
} else {
return $this->format_percentage($questionstat->effectiveweight, false);
}
}
|
[
"protected",
"function",
"col_effective_weight",
"(",
"$",
"questionstat",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"if",
"(",
"$",
"this",
"->",
"is_calculated_question_summary",
"(",
"$",
"questionstat",
")",
")",
"{",
"list",
"(",
"$",
"min",
",",
"$",
"max",
")",
"=",
"$",
"questionstat",
"->",
"get_min_max_of",
"(",
"'effectiveweight'",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"min",
")",
"&&",
"is_null",
"(",
"$",
"max",
")",
")",
"{",
"return",
"''",
";",
"}",
"else",
"{",
"list",
"(",
",",
"$",
"negcovar",
")",
"=",
"$",
"questionstat",
"->",
"get_min_max_of",
"(",
"'negcovar'",
")",
";",
"if",
"(",
"$",
"negcovar",
")",
"{",
"$",
"min",
"=",
"get_string",
"(",
"'negcovar'",
",",
"'quiz_statistics'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"format_range",
"(",
"$",
"min",
",",
"$",
"max",
")",
";",
"}",
"}",
"else",
"if",
"(",
"is_null",
"(",
"$",
"questionstat",
"->",
"effectiveweight",
")",
")",
"{",
"return",
"''",
";",
"}",
"else",
"if",
"(",
"$",
"questionstat",
"->",
"negcovar",
")",
"{",
"$",
"negcovar",
"=",
"get_string",
"(",
"'negcovar'",
",",
"'quiz_statistics'",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"is_downloading",
"(",
")",
")",
"{",
"$",
"negcovar",
"=",
"html_writer",
"::",
"tag",
"(",
"'div'",
",",
"$",
"negcovar",
".",
"$",
"OUTPUT",
"->",
"help_icon",
"(",
"'negcovar'",
",",
"'quiz_statistics'",
")",
",",
"array",
"(",
"'class'",
"=>",
"'negcovar'",
")",
")",
";",
"}",
"return",
"$",
"negcovar",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"format_percentage",
"(",
"$",
"questionstat",
"->",
"effectiveweight",
",",
"false",
")",
";",
"}",
"}"
] |
The effective question weight. That is, an estimate of the actual
influence this question has on the student's overall mark.
@param \core_question\statistics\questions\calculated $questionstat stats for the question.
@return string contents of this table cell.
|
[
"The",
"effective",
"question",
"weight",
".",
"That",
"is",
"an",
"estimate",
"of",
"the",
"actual",
"influence",
"this",
"question",
"has",
"on",
"the",
"student",
"s",
"overall",
"mark",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/statistics/statistics_table.php#L391-L422
|
218,810
|
moodle/moodle
|
mod/quiz/report/statistics/statistics_table.php
|
quiz_statistics_table.col_discrimination_index
|
protected function col_discrimination_index($questionstat) {
if ($this->is_calculated_question_summary($questionstat)) {
list($min, $max) = $questionstat->get_min_max_of('discriminationindex');
if (isset($max)) {
$min = $min ?: 0;
}
if (is_numeric($min)) {
$min = $this->format_percentage($min, false);
}
if (is_numeric($max)) {
$max = $this->format_percentage($max, false);
}
return $this->format_range($min, $max);
} else if (!is_numeric($questionstat->discriminationindex)) {
return $questionstat->discriminationindex;
} else {
return $this->format_percentage($questionstat->discriminationindex, false);
}
}
|
php
|
protected function col_discrimination_index($questionstat) {
if ($this->is_calculated_question_summary($questionstat)) {
list($min, $max) = $questionstat->get_min_max_of('discriminationindex');
if (isset($max)) {
$min = $min ?: 0;
}
if (is_numeric($min)) {
$min = $this->format_percentage($min, false);
}
if (is_numeric($max)) {
$max = $this->format_percentage($max, false);
}
return $this->format_range($min, $max);
} else if (!is_numeric($questionstat->discriminationindex)) {
return $questionstat->discriminationindex;
} else {
return $this->format_percentage($questionstat->discriminationindex, false);
}
}
|
[
"protected",
"function",
"col_discrimination_index",
"(",
"$",
"questionstat",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"is_calculated_question_summary",
"(",
"$",
"questionstat",
")",
")",
"{",
"list",
"(",
"$",
"min",
",",
"$",
"max",
")",
"=",
"$",
"questionstat",
"->",
"get_min_max_of",
"(",
"'discriminationindex'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"max",
")",
")",
"{",
"$",
"min",
"=",
"$",
"min",
"?",
":",
"0",
";",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"min",
")",
")",
"{",
"$",
"min",
"=",
"$",
"this",
"->",
"format_percentage",
"(",
"$",
"min",
",",
"false",
")",
";",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"max",
")",
")",
"{",
"$",
"max",
"=",
"$",
"this",
"->",
"format_percentage",
"(",
"$",
"max",
",",
"false",
")",
";",
"}",
"return",
"$",
"this",
"->",
"format_range",
"(",
"$",
"min",
",",
"$",
"max",
")",
";",
"}",
"else",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"questionstat",
"->",
"discriminationindex",
")",
")",
"{",
"return",
"$",
"questionstat",
"->",
"discriminationindex",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"format_percentage",
"(",
"$",
"questionstat",
"->",
"discriminationindex",
",",
"false",
")",
";",
"}",
"}"
] |
Discrimination index. This is the product moment correlation coefficient
between the fraction for this question, and the average fraction for the
other questions in this quiz.
@param \core_question\statistics\questions\calculated $questionstat stats for the question.
@return string contents of this table cell.
|
[
"Discrimination",
"index",
".",
"This",
"is",
"the",
"product",
"moment",
"correlation",
"coefficient",
"between",
"the",
"fraction",
"for",
"this",
"question",
"and",
"the",
"average",
"fraction",
"for",
"the",
"other",
"questions",
"in",
"this",
"quiz",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/statistics/statistics_table.php#L431-L452
|
218,811
|
moodle/moodle
|
mod/quiz/report/statistics/statistics_table.php
|
quiz_statistics_table.col_discriminative_efficiency
|
protected function col_discriminative_efficiency($questionstat) {
if ($this->is_calculated_question_summary($questionstat)) {
list($min, $max) = $questionstat->get_min_max_of('discriminativeefficiency');
if (!is_numeric($min) && !is_numeric($max)) {
return '';
} else {
return $this->format_percentage_range($min, $max, false);
}
} else if (!is_numeric($questionstat->discriminativeefficiency)) {
return '';
} else {
return $this->format_percentage($questionstat->discriminativeefficiency);
}
}
|
php
|
protected function col_discriminative_efficiency($questionstat) {
if ($this->is_calculated_question_summary($questionstat)) {
list($min, $max) = $questionstat->get_min_max_of('discriminativeefficiency');
if (!is_numeric($min) && !is_numeric($max)) {
return '';
} else {
return $this->format_percentage_range($min, $max, false);
}
} else if (!is_numeric($questionstat->discriminativeefficiency)) {
return '';
} else {
return $this->format_percentage($questionstat->discriminativeefficiency);
}
}
|
[
"protected",
"function",
"col_discriminative_efficiency",
"(",
"$",
"questionstat",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"is_calculated_question_summary",
"(",
"$",
"questionstat",
")",
")",
"{",
"list",
"(",
"$",
"min",
",",
"$",
"max",
")",
"=",
"$",
"questionstat",
"->",
"get_min_max_of",
"(",
"'discriminativeefficiency'",
")",
";",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"min",
")",
"&&",
"!",
"is_numeric",
"(",
"$",
"max",
")",
")",
"{",
"return",
"''",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"format_percentage_range",
"(",
"$",
"min",
",",
"$",
"max",
",",
"false",
")",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"questionstat",
"->",
"discriminativeefficiency",
")",
")",
"{",
"return",
"''",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"format_percentage",
"(",
"$",
"questionstat",
"->",
"discriminativeefficiency",
")",
";",
"}",
"}"
] |
Discrimination efficiency, similar to, but different from, the Discrimination index.
@param \core_question\statistics\questions\calculated $questionstat stats for the question.
@return string contents of this table cell.
|
[
"Discrimination",
"efficiency",
"similar",
"to",
"but",
"different",
"from",
"the",
"Discrimination",
"index",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/statistics/statistics_table.php#L460-L474
|
218,812
|
moodle/moodle
|
mod/quiz/report/statistics/statistics_table.php
|
quiz_statistics_table.is_dubious_question
|
protected function is_dubious_question($questionstat) {
if ($this->is_calculated_question_summary($questionstat)) {
// We only care about the minimum value here.
// If the minimum value is less than the threshold, then we know that there is at least one value below the threshold.
list($discriminativeefficiency) = $questionstat->get_min_max_of('discriminativeefficiency');
} else {
$discriminativeefficiency = $questionstat->discriminativeefficiency;
}
if (!is_numeric($discriminativeefficiency)) {
return false;
}
return $discriminativeefficiency < 15;
}
|
php
|
protected function is_dubious_question($questionstat) {
if ($this->is_calculated_question_summary($questionstat)) {
// We only care about the minimum value here.
// If the minimum value is less than the threshold, then we know that there is at least one value below the threshold.
list($discriminativeefficiency) = $questionstat->get_min_max_of('discriminativeefficiency');
} else {
$discriminativeefficiency = $questionstat->discriminativeefficiency;
}
if (!is_numeric($discriminativeefficiency)) {
return false;
}
return $discriminativeefficiency < 15;
}
|
[
"protected",
"function",
"is_dubious_question",
"(",
"$",
"questionstat",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"is_calculated_question_summary",
"(",
"$",
"questionstat",
")",
")",
"{",
"// We only care about the minimum value here.",
"// If the minimum value is less than the threshold, then we know that there is at least one value below the threshold.",
"list",
"(",
"$",
"discriminativeefficiency",
")",
"=",
"$",
"questionstat",
"->",
"get_min_max_of",
"(",
"'discriminativeefficiency'",
")",
";",
"}",
"else",
"{",
"$",
"discriminativeefficiency",
"=",
"$",
"questionstat",
"->",
"discriminativeefficiency",
";",
"}",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"discriminativeefficiency",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"discriminativeefficiency",
"<",
"15",
";",
"}"
] |
This method encapsulates the test for wheter a question should be considered dubious.
@param \core_question\statistics\questions\calculated $questionstat stats for the question.
@return bool is this question possibly not pulling it's weight?
|
[
"This",
"method",
"encapsulates",
"the",
"test",
"for",
"wheter",
"a",
"question",
"should",
"be",
"considered",
"dubious",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/statistics/statistics_table.php#L481-L495
|
218,813
|
moodle/moodle
|
mod/quiz/report/statistics/statistics_table.php
|
quiz_statistics_table.format_percentage
|
protected function format_percentage(float $number, bool $fraction = true, int $decimals = 2) {
$coefficient = $fraction ? 100 : 1;
return get_string('percents', 'moodle', format_float($number * $coefficient, $decimals));
}
|
php
|
protected function format_percentage(float $number, bool $fraction = true, int $decimals = 2) {
$coefficient = $fraction ? 100 : 1;
return get_string('percents', 'moodle', format_float($number * $coefficient, $decimals));
}
|
[
"protected",
"function",
"format_percentage",
"(",
"float",
"$",
"number",
",",
"bool",
"$",
"fraction",
"=",
"true",
",",
"int",
"$",
"decimals",
"=",
"2",
")",
"{",
"$",
"coefficient",
"=",
"$",
"fraction",
"?",
"100",
":",
"1",
";",
"return",
"get_string",
"(",
"'percents'",
",",
"'moodle'",
",",
"format_float",
"(",
"$",
"number",
"*",
"$",
"coefficient",
",",
"$",
"decimals",
")",
")",
";",
"}"
] |
Format a number to a localised percentage with specified decimal points.
@param float $number The number being formatted
@param bool $fraction An indicator for whether the number is a fraction or is already multiplied by 100
@param int $decimals Sets the number of decimal points
@return string
|
[
"Format",
"a",
"number",
"to",
"a",
"localised",
"percentage",
"with",
"specified",
"decimal",
"points",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/statistics/statistics_table.php#L536-L539
|
218,814
|
moodle/moodle
|
admin/tool/dbtransfer/database_export_form.php
|
database_export_form.definition
|
public function definition() {
$mform = $this->_form;
$mform->addElement('header', 'database', get_string('dbexport', 'tool_dbtransfer'));
$mform->addElement('textarea', 'description', get_string('description'), array('rows'=>5, 'cols'=>60));
$mform->setType('description', PARAM_TEXT);
$this->add_action_buttons(false, get_string('exportdata', 'tool_dbtransfer'));
}
|
php
|
public function definition() {
$mform = $this->_form;
$mform->addElement('header', 'database', get_string('dbexport', 'tool_dbtransfer'));
$mform->addElement('textarea', 'description', get_string('description'), array('rows'=>5, 'cols'=>60));
$mform->setType('description', PARAM_TEXT);
$this->add_action_buttons(false, get_string('exportdata', 'tool_dbtransfer'));
}
|
[
"public",
"function",
"definition",
"(",
")",
"{",
"$",
"mform",
"=",
"$",
"this",
"->",
"_form",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'header'",
",",
"'database'",
",",
"get_string",
"(",
"'dbexport'",
",",
"'tool_dbtransfer'",
")",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'textarea'",
",",
"'description'",
",",
"get_string",
"(",
"'description'",
")",
",",
"array",
"(",
"'rows'",
"=>",
"5",
",",
"'cols'",
"=>",
"60",
")",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'description'",
",",
"PARAM_TEXT",
")",
";",
"$",
"this",
"->",
"add_action_buttons",
"(",
"false",
",",
"get_string",
"(",
"'exportdata'",
",",
"'tool_dbtransfer'",
")",
")",
";",
"}"
] |
Define the export form.
|
[
"Define",
"the",
"export",
"form",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dbtransfer/database_export_form.php#L41-L49
|
218,815
|
moodle/moodle
|
calendar/classes/local/event/forms/create.php
|
create.build_editor_options
|
public static function build_editor_options(\context $context) {
global $CFG;
return [
'context' => $context,
'maxfiles' => EDITOR_UNLIMITED_FILES,
'maxbytes' => $CFG->maxbytes,
'noclean' => true,
'autosave' => false
];
}
|
php
|
public static function build_editor_options(\context $context) {
global $CFG;
return [
'context' => $context,
'maxfiles' => EDITOR_UNLIMITED_FILES,
'maxbytes' => $CFG->maxbytes,
'noclean' => true,
'autosave' => false
];
}
|
[
"public",
"static",
"function",
"build_editor_options",
"(",
"\\",
"context",
"$",
"context",
")",
"{",
"global",
"$",
"CFG",
";",
"return",
"[",
"'context'",
"=>",
"$",
"context",
",",
"'maxfiles'",
"=>",
"EDITOR_UNLIMITED_FILES",
",",
"'maxbytes'",
"=>",
"$",
"CFG",
"->",
"maxbytes",
",",
"'noclean'",
"=>",
"true",
",",
"'autosave'",
"=>",
"false",
"]",
";",
"}"
] |
Build the editor options using the given context.
@param \context $context A Moodle context
@return array
|
[
"Build",
"the",
"editor",
"options",
"using",
"the",
"given",
"context",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/local/event/forms/create.php#L48-L58
|
218,816
|
moodle/moodle
|
calendar/classes/local/event/forms/create.php
|
create.add_default_hidden_elements
|
protected function add_default_hidden_elements($mform) {
global $USER;
// Add some hidden fields.
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$mform->setDefault('id', 0);
$mform->addElement('hidden', 'userid');
$mform->setType('userid', PARAM_INT);
$mform->setDefault('userid', $USER->id);
$mform->addElement('hidden', 'modulename');
$mform->setType('modulename', PARAM_INT);
$mform->setDefault('modulename', '');
$mform->addElement('hidden', 'instance');
$mform->setType('instance', PARAM_INT);
$mform->setDefault('instance', 0);
$mform->addElement('hidden', 'visible');
$mform->setType('visible', PARAM_INT);
$mform->setDefault('visible', 1);
}
|
php
|
protected function add_default_hidden_elements($mform) {
global $USER;
// Add some hidden fields.
$mform->addElement('hidden', 'id');
$mform->setType('id', PARAM_INT);
$mform->setDefault('id', 0);
$mform->addElement('hidden', 'userid');
$mform->setType('userid', PARAM_INT);
$mform->setDefault('userid', $USER->id);
$mform->addElement('hidden', 'modulename');
$mform->setType('modulename', PARAM_INT);
$mform->setDefault('modulename', '');
$mform->addElement('hidden', 'instance');
$mform->setType('instance', PARAM_INT);
$mform->setDefault('instance', 0);
$mform->addElement('hidden', 'visible');
$mform->setType('visible', PARAM_INT);
$mform->setDefault('visible', 1);
}
|
[
"protected",
"function",
"add_default_hidden_elements",
"(",
"$",
"mform",
")",
"{",
"global",
"$",
"USER",
";",
"// Add some hidden fields.",
"$",
"mform",
"->",
"addElement",
"(",
"'hidden'",
",",
"'id'",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'id'",
",",
"PARAM_INT",
")",
";",
"$",
"mform",
"->",
"setDefault",
"(",
"'id'",
",",
"0",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'hidden'",
",",
"'userid'",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'userid'",
",",
"PARAM_INT",
")",
";",
"$",
"mform",
"->",
"setDefault",
"(",
"'userid'",
",",
"$",
"USER",
"->",
"id",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'hidden'",
",",
"'modulename'",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'modulename'",
",",
"PARAM_INT",
")",
";",
"$",
"mform",
"->",
"setDefault",
"(",
"'modulename'",
",",
"''",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'hidden'",
",",
"'instance'",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'instance'",
",",
"PARAM_INT",
")",
";",
"$",
"mform",
"->",
"setDefault",
"(",
"'instance'",
",",
"0",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'hidden'",
",",
"'visible'",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'visible'",
",",
"PARAM_INT",
")",
";",
"$",
"mform",
"->",
"setDefault",
"(",
"'visible'",
",",
"1",
")",
";",
"}"
] |
Add the list of hidden elements that should appear in this form each
time. These elements will never be visible to the user.
@param MoodleQuickForm $mform
|
[
"Add",
"the",
"list",
"of",
"hidden",
"elements",
"that",
"should",
"appear",
"in",
"this",
"form",
"each",
"time",
".",
"These",
"elements",
"will",
"never",
"be",
"visible",
"to",
"the",
"user",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/local/event/forms/create.php#L174-L197
|
218,817
|
moodle/moodle
|
calendar/classes/local/event/forms/create.php
|
create.add_event_duration_elements
|
protected function add_event_duration_elements($mform) {
$group = [];
$group[] = $mform->createElement('radio', 'duration', null, get_string('durationnone', 'calendar'), 0);
$group[] = $mform->createElement('radio', 'duration', null, get_string('durationuntil', 'calendar'), 1);
$group[] = $mform->createElement('date_time_selector', 'timedurationuntil', '');
$group[] = $mform->createElement('radio', 'duration', null, get_string('durationminutes', 'calendar'), 2);
$group[] = $mform->createElement('text', 'timedurationminutes', get_string('durationminutes', 'calendar'));
$mform->addGroup($group, 'durationgroup', get_string('eventduration', 'calendar'), '<br />', false);
$mform->setAdvanced('durationgroup');
$mform->disabledIf('timedurationuntil', 'duration', 'noteq', 1);
$mform->disabledIf('timedurationuntil[day]', 'duration', 'noteq', 1);
$mform->disabledIf('timedurationuntil[month]', 'duration', 'noteq', 1);
$mform->disabledIf('timedurationuntil[year]', 'duration', 'noteq', 1);
$mform->disabledIf('timedurationuntil[hour]', 'duration', 'noteq', 1);
$mform->disabledIf('timedurationuntil[minute]', 'duration', 'noteq', 1);
$mform->setType('timedurationminutes', PARAM_INT);
$mform->disabledIf('timedurationminutes', 'duration', 'noteq', 2);
$mform->setDefault('duration', 0);
}
|
php
|
protected function add_event_duration_elements($mform) {
$group = [];
$group[] = $mform->createElement('radio', 'duration', null, get_string('durationnone', 'calendar'), 0);
$group[] = $mform->createElement('radio', 'duration', null, get_string('durationuntil', 'calendar'), 1);
$group[] = $mform->createElement('date_time_selector', 'timedurationuntil', '');
$group[] = $mform->createElement('radio', 'duration', null, get_string('durationminutes', 'calendar'), 2);
$group[] = $mform->createElement('text', 'timedurationminutes', get_string('durationminutes', 'calendar'));
$mform->addGroup($group, 'durationgroup', get_string('eventduration', 'calendar'), '<br />', false);
$mform->setAdvanced('durationgroup');
$mform->disabledIf('timedurationuntil', 'duration', 'noteq', 1);
$mform->disabledIf('timedurationuntil[day]', 'duration', 'noteq', 1);
$mform->disabledIf('timedurationuntil[month]', 'duration', 'noteq', 1);
$mform->disabledIf('timedurationuntil[year]', 'duration', 'noteq', 1);
$mform->disabledIf('timedurationuntil[hour]', 'duration', 'noteq', 1);
$mform->disabledIf('timedurationuntil[minute]', 'duration', 'noteq', 1);
$mform->setType('timedurationminutes', PARAM_INT);
$mform->disabledIf('timedurationminutes', 'duration', 'noteq', 2);
$mform->setDefault('duration', 0);
}
|
[
"protected",
"function",
"add_event_duration_elements",
"(",
"$",
"mform",
")",
"{",
"$",
"group",
"=",
"[",
"]",
";",
"$",
"group",
"[",
"]",
"=",
"$",
"mform",
"->",
"createElement",
"(",
"'radio'",
",",
"'duration'",
",",
"null",
",",
"get_string",
"(",
"'durationnone'",
",",
"'calendar'",
")",
",",
"0",
")",
";",
"$",
"group",
"[",
"]",
"=",
"$",
"mform",
"->",
"createElement",
"(",
"'radio'",
",",
"'duration'",
",",
"null",
",",
"get_string",
"(",
"'durationuntil'",
",",
"'calendar'",
")",
",",
"1",
")",
";",
"$",
"group",
"[",
"]",
"=",
"$",
"mform",
"->",
"createElement",
"(",
"'date_time_selector'",
",",
"'timedurationuntil'",
",",
"''",
")",
";",
"$",
"group",
"[",
"]",
"=",
"$",
"mform",
"->",
"createElement",
"(",
"'radio'",
",",
"'duration'",
",",
"null",
",",
"get_string",
"(",
"'durationminutes'",
",",
"'calendar'",
")",
",",
"2",
")",
";",
"$",
"group",
"[",
"]",
"=",
"$",
"mform",
"->",
"createElement",
"(",
"'text'",
",",
"'timedurationminutes'",
",",
"get_string",
"(",
"'durationminutes'",
",",
"'calendar'",
")",
")",
";",
"$",
"mform",
"->",
"addGroup",
"(",
"$",
"group",
",",
"'durationgroup'",
",",
"get_string",
"(",
"'eventduration'",
",",
"'calendar'",
")",
",",
"'<br />'",
",",
"false",
")",
";",
"$",
"mform",
"->",
"setAdvanced",
"(",
"'durationgroup'",
")",
";",
"$",
"mform",
"->",
"disabledIf",
"(",
"'timedurationuntil'",
",",
"'duration'",
",",
"'noteq'",
",",
"1",
")",
";",
"$",
"mform",
"->",
"disabledIf",
"(",
"'timedurationuntil[day]'",
",",
"'duration'",
",",
"'noteq'",
",",
"1",
")",
";",
"$",
"mform",
"->",
"disabledIf",
"(",
"'timedurationuntil[month]'",
",",
"'duration'",
",",
"'noteq'",
",",
"1",
")",
";",
"$",
"mform",
"->",
"disabledIf",
"(",
"'timedurationuntil[year]'",
",",
"'duration'",
",",
"'noteq'",
",",
"1",
")",
";",
"$",
"mform",
"->",
"disabledIf",
"(",
"'timedurationuntil[hour]'",
",",
"'duration'",
",",
"'noteq'",
",",
"1",
")",
";",
"$",
"mform",
"->",
"disabledIf",
"(",
"'timedurationuntil[minute]'",
",",
"'duration'",
",",
"'noteq'",
",",
"1",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'timedurationminutes'",
",",
"PARAM_INT",
")",
";",
"$",
"mform",
"->",
"disabledIf",
"(",
"'timedurationminutes'",
",",
"'duration'",
",",
"'noteq'",
",",
"2",
")",
";",
"$",
"mform",
"->",
"setDefault",
"(",
"'duration'",
",",
"0",
")",
";",
"}"
] |
Add the various elements to express the duration options available
for an event.
@param MoodleQuickForm $mform
|
[
"Add",
"the",
"various",
"elements",
"to",
"express",
"the",
"duration",
"options",
"available",
"for",
"an",
"event",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/local/event/forms/create.php#L205-L227
|
218,818
|
moodle/moodle
|
calendar/classes/local/event/forms/create.php
|
create.add_event_repeat_elements
|
protected function add_event_repeat_elements($mform) {
$mform->addElement('checkbox', 'repeat', get_string('repeatevent', 'calendar'), null);
$mform->addElement('text', 'repeats', get_string('repeatweeksl', 'calendar'), 'maxlength="10" size="10"');
$mform->setType('repeats', PARAM_INT);
$mform->setDefault('repeats', 1);
$mform->disabledIf('repeats', 'repeat', 'notchecked');
$mform->setAdvanced('repeat');
$mform->setAdvanced('repeats');
}
|
php
|
protected function add_event_repeat_elements($mform) {
$mform->addElement('checkbox', 'repeat', get_string('repeatevent', 'calendar'), null);
$mform->addElement('text', 'repeats', get_string('repeatweeksl', 'calendar'), 'maxlength="10" size="10"');
$mform->setType('repeats', PARAM_INT);
$mform->setDefault('repeats', 1);
$mform->disabledIf('repeats', 'repeat', 'notchecked');
$mform->setAdvanced('repeat');
$mform->setAdvanced('repeats');
}
|
[
"protected",
"function",
"add_event_repeat_elements",
"(",
"$",
"mform",
")",
"{",
"$",
"mform",
"->",
"addElement",
"(",
"'checkbox'",
",",
"'repeat'",
",",
"get_string",
"(",
"'repeatevent'",
",",
"'calendar'",
")",
",",
"null",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'text'",
",",
"'repeats'",
",",
"get_string",
"(",
"'repeatweeksl'",
",",
"'calendar'",
")",
",",
"'maxlength=\"10\" size=\"10\"'",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'repeats'",
",",
"PARAM_INT",
")",
";",
"$",
"mform",
"->",
"setDefault",
"(",
"'repeats'",
",",
"1",
")",
";",
"$",
"mform",
"->",
"disabledIf",
"(",
"'repeats'",
",",
"'repeat'",
",",
"'notchecked'",
")",
";",
"$",
"mform",
"->",
"setAdvanced",
"(",
"'repeat'",
")",
";",
"$",
"mform",
"->",
"setAdvanced",
"(",
"'repeats'",
")",
";",
"}"
] |
Add the repeat elements for the form when creating a new event.
@param MoodleQuickForm $mform
|
[
"Add",
"the",
"repeat",
"elements",
"for",
"the",
"form",
"when",
"creating",
"a",
"new",
"event",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/local/event/forms/create.php#L234-L242
|
218,819
|
moodle/moodle
|
admin/tool/dataprivacy/classes/api.php
|
api.check_can_manage_data_registry
|
public static function check_can_manage_data_registry($contextid = false) {
if ($contextid) {
$context = \context_helper::instance_by_id($contextid);
} else {
$context = \context_system::instance();
}
require_capability('tool/dataprivacy:managedataregistry', $context);
}
|
php
|
public static function check_can_manage_data_registry($contextid = false) {
if ($contextid) {
$context = \context_helper::instance_by_id($contextid);
} else {
$context = \context_system::instance();
}
require_capability('tool/dataprivacy:managedataregistry', $context);
}
|
[
"public",
"static",
"function",
"check_can_manage_data_registry",
"(",
"$",
"contextid",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"contextid",
")",
"{",
"$",
"context",
"=",
"\\",
"context_helper",
"::",
"instance_by_id",
"(",
"$",
"contextid",
")",
";",
"}",
"else",
"{",
"$",
"context",
"=",
"\\",
"context_system",
"::",
"instance",
"(",
")",
";",
"}",
"require_capability",
"(",
"'tool/dataprivacy:managedataregistry'",
",",
"$",
"context",
")",
";",
"}"
] |
Checks if the current user can manage the data registry at the provided id.
@param int $contextid Fallback to system context id.
@throws \required_capability_exception
@return null
|
[
"Checks",
"if",
"the",
"current",
"user",
"can",
"manage",
"the",
"data",
"registry",
"at",
"the",
"provided",
"id",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/api.php#L128-L136
|
218,820
|
moodle/moodle
|
admin/tool/dataprivacy/classes/api.php
|
api.get_assigned_privacy_officer_roles
|
public static function get_assigned_privacy_officer_roles() {
$roleids = [];
// Get roles from config.
$configroleids = explode(',', str_replace(' ', '', get_config('tool_dataprivacy', 'dporoles')));
if (!empty($configroleids)) {
// Fetch roles that have the capability to manage data requests.
$capableroles = array_keys(get_roles_with_capability('tool/dataprivacy:managedatarequests'));
// Extract the configured roles that have the capability from the list of capable roles.
$roleids = array_intersect($capableroles, $configroleids);
}
return $roleids;
}
|
php
|
public static function get_assigned_privacy_officer_roles() {
$roleids = [];
// Get roles from config.
$configroleids = explode(',', str_replace(' ', '', get_config('tool_dataprivacy', 'dporoles')));
if (!empty($configroleids)) {
// Fetch roles that have the capability to manage data requests.
$capableroles = array_keys(get_roles_with_capability('tool/dataprivacy:managedatarequests'));
// Extract the configured roles that have the capability from the list of capable roles.
$roleids = array_intersect($capableroles, $configroleids);
}
return $roleids;
}
|
[
"public",
"static",
"function",
"get_assigned_privacy_officer_roles",
"(",
")",
"{",
"$",
"roleids",
"=",
"[",
"]",
";",
"// Get roles from config.",
"$",
"configroleids",
"=",
"explode",
"(",
"','",
",",
"str_replace",
"(",
"' '",
",",
"''",
",",
"get_config",
"(",
"'tool_dataprivacy'",
",",
"'dporoles'",
")",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"configroleids",
")",
")",
"{",
"// Fetch roles that have the capability to manage data requests.",
"$",
"capableroles",
"=",
"array_keys",
"(",
"get_roles_with_capability",
"(",
"'tool/dataprivacy:managedatarequests'",
")",
")",
";",
"// Extract the configured roles that have the capability from the list of capable roles.",
"$",
"roleids",
"=",
"array_intersect",
"(",
"$",
"capableroles",
",",
"$",
"configroleids",
")",
";",
"}",
"return",
"$",
"roleids",
";",
"}"
] |
Fetches the list of configured privacy officer roles.
Every time this function is called, it checks each role if they have the 'managedatarequests' capability and removes
any role that doesn't have the required capability anymore.
@return int[]
@throws dml_exception
|
[
"Fetches",
"the",
"list",
"of",
"configured",
"privacy",
"officer",
"roles",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/api.php#L147-L161
|
218,821
|
moodle/moodle
|
admin/tool/dataprivacy/classes/api.php
|
api.get_dpo_role_names
|
public static function get_dpo_role_names() : array {
global $DB;
$dporoleids = self::get_assigned_privacy_officer_roles();
$dponames = array();
if (!empty($dporoleids)) {
list($insql, $inparams) = $DB->get_in_or_equal($dporoleids);
$dponames = $DB->get_fieldset_select('role', 'shortname', "id {$insql}", $inparams);
}
return $dponames;
}
|
php
|
public static function get_dpo_role_names() : array {
global $DB;
$dporoleids = self::get_assigned_privacy_officer_roles();
$dponames = array();
if (!empty($dporoleids)) {
list($insql, $inparams) = $DB->get_in_or_equal($dporoleids);
$dponames = $DB->get_fieldset_select('role', 'shortname', "id {$insql}", $inparams);
}
return $dponames;
}
|
[
"public",
"static",
"function",
"get_dpo_role_names",
"(",
")",
":",
"array",
"{",
"global",
"$",
"DB",
";",
"$",
"dporoleids",
"=",
"self",
"::",
"get_assigned_privacy_officer_roles",
"(",
")",
";",
"$",
"dponames",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"dporoleids",
")",
")",
"{",
"list",
"(",
"$",
"insql",
",",
"$",
"inparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"dporoleids",
")",
";",
"$",
"dponames",
"=",
"$",
"DB",
"->",
"get_fieldset_select",
"(",
"'role'",
",",
"'shortname'",
",",
"\"id {$insql}\"",
",",
"$",
"inparams",
")",
";",
"}",
"return",
"$",
"dponames",
";",
"}"
] |
Fetches the role shortnames of Data Protection Officer roles.
@return array An array of the DPO role shortnames
|
[
"Fetches",
"the",
"role",
"shortnames",
"of",
"Data",
"Protection",
"Officer",
"roles",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/api.php#L168-L180
|
218,822
|
moodle/moodle
|
admin/tool/dataprivacy/classes/api.php
|
api.get_site_dpos
|
public static function get_site_dpos() {
// Get role(s) that can manage data requests.
$dporoles = self::get_assigned_privacy_officer_roles();
$dpos = [];
$context = context_system::instance();
foreach ($dporoles as $roleid) {
$allnames = get_all_user_name_fields(true, 'u');
$fields = 'u.id, u.confirmed, u.username, '. $allnames . ', ' .
'u.maildisplay, u.mailformat, u.maildigest, u.email, u.emailstop, u.city, '.
'u.country, u.picture, u.idnumber, u.department, u.institution, '.
'u.lang, u.timezone, u.lastaccess, u.mnethostid, u.auth, u.suspended, u.deleted, ' .
'r.name AS rolename, r.sortorder, '.
'r.shortname AS roleshortname, rn.name AS rolecoursealias';
// Fetch users that can manage data requests.
$dpos += get_role_users($roleid, $context, false, $fields);
}
// If the site has no data protection officer, defer to site admin(s).
if (empty($dpos)) {
$dpos = get_admins();
}
return $dpos;
}
|
php
|
public static function get_site_dpos() {
// Get role(s) that can manage data requests.
$dporoles = self::get_assigned_privacy_officer_roles();
$dpos = [];
$context = context_system::instance();
foreach ($dporoles as $roleid) {
$allnames = get_all_user_name_fields(true, 'u');
$fields = 'u.id, u.confirmed, u.username, '. $allnames . ', ' .
'u.maildisplay, u.mailformat, u.maildigest, u.email, u.emailstop, u.city, '.
'u.country, u.picture, u.idnumber, u.department, u.institution, '.
'u.lang, u.timezone, u.lastaccess, u.mnethostid, u.auth, u.suspended, u.deleted, ' .
'r.name AS rolename, r.sortorder, '.
'r.shortname AS roleshortname, rn.name AS rolecoursealias';
// Fetch users that can manage data requests.
$dpos += get_role_users($roleid, $context, false, $fields);
}
// If the site has no data protection officer, defer to site admin(s).
if (empty($dpos)) {
$dpos = get_admins();
}
return $dpos;
}
|
[
"public",
"static",
"function",
"get_site_dpos",
"(",
")",
"{",
"// Get role(s) that can manage data requests.",
"$",
"dporoles",
"=",
"self",
"::",
"get_assigned_privacy_officer_roles",
"(",
")",
";",
"$",
"dpos",
"=",
"[",
"]",
";",
"$",
"context",
"=",
"context_system",
"::",
"instance",
"(",
")",
";",
"foreach",
"(",
"$",
"dporoles",
"as",
"$",
"roleid",
")",
"{",
"$",
"allnames",
"=",
"get_all_user_name_fields",
"(",
"true",
",",
"'u'",
")",
";",
"$",
"fields",
"=",
"'u.id, u.confirmed, u.username, '",
".",
"$",
"allnames",
".",
"', '",
".",
"'u.maildisplay, u.mailformat, u.maildigest, u.email, u.emailstop, u.city, '",
".",
"'u.country, u.picture, u.idnumber, u.department, u.institution, '",
".",
"'u.lang, u.timezone, u.lastaccess, u.mnethostid, u.auth, u.suspended, u.deleted, '",
".",
"'r.name AS rolename, r.sortorder, '",
".",
"'r.shortname AS roleshortname, rn.name AS rolecoursealias'",
";",
"// Fetch users that can manage data requests.",
"$",
"dpos",
"+=",
"get_role_users",
"(",
"$",
"roleid",
",",
"$",
"context",
",",
"false",
",",
"$",
"fields",
")",
";",
"}",
"// If the site has no data protection officer, defer to site admin(s).",
"if",
"(",
"empty",
"(",
"$",
"dpos",
")",
")",
"{",
"$",
"dpos",
"=",
"get_admins",
"(",
")",
";",
"}",
"return",
"$",
"dpos",
";",
"}"
] |
Fetches the list of users with the Privacy Officer role.
|
[
"Fetches",
"the",
"list",
"of",
"users",
"with",
"the",
"Privacy",
"Officer",
"role",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/api.php#L185-L208
|
218,823
|
moodle/moodle
|
admin/tool/dataprivacy/classes/api.php
|
api.get_data_requests_count
|
public static function get_data_requests_count($userid = 0, $statuses = [], $types = [], $creationmethods = []) {
global $DB, $USER;
$count = 0;
$sqlparams = [];
$sqlconditions = [];
if (!empty($statuses)) {
list($statusinsql, $sqlparams) = $DB->get_in_or_equal($statuses, SQL_PARAMS_NAMED);
$sqlconditions[] = "status $statusinsql";
}
if (!empty($types)) {
list($typeinsql, $typeparams) = $DB->get_in_or_equal($types, SQL_PARAMS_NAMED);
$sqlconditions[] = "type $typeinsql";
$sqlparams = array_merge($sqlparams, $typeparams);
}
if (!empty($creationmethods)) {
list($typeinsql, $typeparams) = $DB->get_in_or_equal($creationmethods, SQL_PARAMS_NAMED);
$sqlconditions[] = "creationmethod $typeinsql";
$sqlparams = array_merge($sqlparams, $typeparams);
}
if ($userid) {
// Get the data requests for the user or data requests made by the user.
$sqlconditions[] = "(userid = :userid OR requestedby = :requestedby)";
$params = [
'userid' => $userid,
'requestedby' => $userid
];
// Build a list of user IDs that the user is allowed to make data requests for.
// Of course, the user should be included in this list.
$alloweduserids = [$userid];
// Get any users that the user can make data requests for.
if ($children = helper::get_children_of_user($userid)) {
// Get the list of user IDs of the children and merge to the allowed user IDs.
$alloweduserids = array_merge($alloweduserids, array_keys($children));
}
list($insql, $inparams) = $DB->get_in_or_equal($alloweduserids, SQL_PARAMS_NAMED);
$sqlconditions[] .= "userid $insql";
$select = implode(' AND ', $sqlconditions);
$params = array_merge($params, $inparams, $sqlparams);
$count = data_request::count_records_select($select, $params);
} else {
// If the current user is one of the site's Data Protection Officers, then fetch all data requests.
if (self::is_site_dpo($USER->id)) {
if (!empty($sqlconditions)) {
$select = implode(' AND ', $sqlconditions);
$count = data_request::count_records_select($select, $sqlparams);
} else {
$count = data_request::count_records();
}
}
}
return $count;
}
|
php
|
public static function get_data_requests_count($userid = 0, $statuses = [], $types = [], $creationmethods = []) {
global $DB, $USER;
$count = 0;
$sqlparams = [];
$sqlconditions = [];
if (!empty($statuses)) {
list($statusinsql, $sqlparams) = $DB->get_in_or_equal($statuses, SQL_PARAMS_NAMED);
$sqlconditions[] = "status $statusinsql";
}
if (!empty($types)) {
list($typeinsql, $typeparams) = $DB->get_in_or_equal($types, SQL_PARAMS_NAMED);
$sqlconditions[] = "type $typeinsql";
$sqlparams = array_merge($sqlparams, $typeparams);
}
if (!empty($creationmethods)) {
list($typeinsql, $typeparams) = $DB->get_in_or_equal($creationmethods, SQL_PARAMS_NAMED);
$sqlconditions[] = "creationmethod $typeinsql";
$sqlparams = array_merge($sqlparams, $typeparams);
}
if ($userid) {
// Get the data requests for the user or data requests made by the user.
$sqlconditions[] = "(userid = :userid OR requestedby = :requestedby)";
$params = [
'userid' => $userid,
'requestedby' => $userid
];
// Build a list of user IDs that the user is allowed to make data requests for.
// Of course, the user should be included in this list.
$alloweduserids = [$userid];
// Get any users that the user can make data requests for.
if ($children = helper::get_children_of_user($userid)) {
// Get the list of user IDs of the children and merge to the allowed user IDs.
$alloweduserids = array_merge($alloweduserids, array_keys($children));
}
list($insql, $inparams) = $DB->get_in_or_equal($alloweduserids, SQL_PARAMS_NAMED);
$sqlconditions[] .= "userid $insql";
$select = implode(' AND ', $sqlconditions);
$params = array_merge($params, $inparams, $sqlparams);
$count = data_request::count_records_select($select, $params);
} else {
// If the current user is one of the site's Data Protection Officers, then fetch all data requests.
if (self::is_site_dpo($USER->id)) {
if (!empty($sqlconditions)) {
$select = implode(' AND ', $sqlconditions);
$count = data_request::count_records_select($select, $sqlparams);
} else {
$count = data_request::count_records();
}
}
}
return $count;
}
|
[
"public",
"static",
"function",
"get_data_requests_count",
"(",
"$",
"userid",
"=",
"0",
",",
"$",
"statuses",
"=",
"[",
"]",
",",
"$",
"types",
"=",
"[",
"]",
",",
"$",
"creationmethods",
"=",
"[",
"]",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"USER",
";",
"$",
"count",
"=",
"0",
";",
"$",
"sqlparams",
"=",
"[",
"]",
";",
"$",
"sqlconditions",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"statuses",
")",
")",
"{",
"list",
"(",
"$",
"statusinsql",
",",
"$",
"sqlparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"statuses",
",",
"SQL_PARAMS_NAMED",
")",
";",
"$",
"sqlconditions",
"[",
"]",
"=",
"\"status $statusinsql\"",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"types",
")",
")",
"{",
"list",
"(",
"$",
"typeinsql",
",",
"$",
"typeparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"types",
",",
"SQL_PARAMS_NAMED",
")",
";",
"$",
"sqlconditions",
"[",
"]",
"=",
"\"type $typeinsql\"",
";",
"$",
"sqlparams",
"=",
"array_merge",
"(",
"$",
"sqlparams",
",",
"$",
"typeparams",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"creationmethods",
")",
")",
"{",
"list",
"(",
"$",
"typeinsql",
",",
"$",
"typeparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"creationmethods",
",",
"SQL_PARAMS_NAMED",
")",
";",
"$",
"sqlconditions",
"[",
"]",
"=",
"\"creationmethod $typeinsql\"",
";",
"$",
"sqlparams",
"=",
"array_merge",
"(",
"$",
"sqlparams",
",",
"$",
"typeparams",
")",
";",
"}",
"if",
"(",
"$",
"userid",
")",
"{",
"// Get the data requests for the user or data requests made by the user.",
"$",
"sqlconditions",
"[",
"]",
"=",
"\"(userid = :userid OR requestedby = :requestedby)\"",
";",
"$",
"params",
"=",
"[",
"'userid'",
"=>",
"$",
"userid",
",",
"'requestedby'",
"=>",
"$",
"userid",
"]",
";",
"// Build a list of user IDs that the user is allowed to make data requests for.",
"// Of course, the user should be included in this list.",
"$",
"alloweduserids",
"=",
"[",
"$",
"userid",
"]",
";",
"// Get any users that the user can make data requests for.",
"if",
"(",
"$",
"children",
"=",
"helper",
"::",
"get_children_of_user",
"(",
"$",
"userid",
")",
")",
"{",
"// Get the list of user IDs of the children and merge to the allowed user IDs.",
"$",
"alloweduserids",
"=",
"array_merge",
"(",
"$",
"alloweduserids",
",",
"array_keys",
"(",
"$",
"children",
")",
")",
";",
"}",
"list",
"(",
"$",
"insql",
",",
"$",
"inparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"alloweduserids",
",",
"SQL_PARAMS_NAMED",
")",
";",
"$",
"sqlconditions",
"[",
"]",
".=",
"\"userid $insql\"",
";",
"$",
"select",
"=",
"implode",
"(",
"' AND '",
",",
"$",
"sqlconditions",
")",
";",
"$",
"params",
"=",
"array_merge",
"(",
"$",
"params",
",",
"$",
"inparams",
",",
"$",
"sqlparams",
")",
";",
"$",
"count",
"=",
"data_request",
"::",
"count_records_select",
"(",
"$",
"select",
",",
"$",
"params",
")",
";",
"}",
"else",
"{",
"// If the current user is one of the site's Data Protection Officers, then fetch all data requests.",
"if",
"(",
"self",
"::",
"is_site_dpo",
"(",
"$",
"USER",
"->",
"id",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"sqlconditions",
")",
")",
"{",
"$",
"select",
"=",
"implode",
"(",
"' AND '",
",",
"$",
"sqlconditions",
")",
";",
"$",
"count",
"=",
"data_request",
"::",
"count_records_select",
"(",
"$",
"select",
",",
"$",
"sqlparams",
")",
";",
"}",
"else",
"{",
"$",
"count",
"=",
"data_request",
"::",
"count_records",
"(",
")",
";",
"}",
"}",
"}",
"return",
"$",
"count",
";",
"}"
] |
Fetches the count of data request records based on the given parameters.
@param int $userid The User ID.
@param int[] $statuses The status filters.
@param int[] $types The request type filters.
@param int[] $creationmethods The request creation method filters.
@return int
@throws coding_exception
@throws dml_exception
|
[
"Fetches",
"the",
"count",
"of",
"data",
"request",
"records",
"based",
"on",
"the",
"given",
"parameters",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/api.php#L395-L449
|
218,824
|
moodle/moodle
|
admin/tool/dataprivacy/classes/api.php
|
api.find_ongoing_request_types_for_users
|
public static function find_ongoing_request_types_for_users(array $userids) : array {
global $DB;
if (empty($userids)) {
return [];
}
// Check if the user already has an incomplete data request of the same type.
$nonpendingstatuses = [
self::DATAREQUEST_STATUS_COMPLETE,
self::DATAREQUEST_STATUS_CANCELLED,
self::DATAREQUEST_STATUS_REJECTED,
self::DATAREQUEST_STATUS_DOWNLOAD_READY,
self::DATAREQUEST_STATUS_EXPIRED,
self::DATAREQUEST_STATUS_DELETED,
];
list($statusinsql, $statusparams) = $DB->get_in_or_equal($nonpendingstatuses, SQL_PARAMS_NAMED, 'st', false);
list($userinsql, $userparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED, 'us');
$select = "userid {$userinsql} AND status {$statusinsql}";
$params = array_merge($statusparams, $userparams);
$requests = $DB->get_records_select(data_request::TABLE, $select, $params, 'userid', 'id, userid, type');
$returnval = [];
foreach ($userids as $userid) {
$returnval[$userid] = (object) [];
}
foreach ($requests as $request) {
$returnval[$request->userid]->{$request->type} = true;
}
return $returnval;
}
|
php
|
public static function find_ongoing_request_types_for_users(array $userids) : array {
global $DB;
if (empty($userids)) {
return [];
}
// Check if the user already has an incomplete data request of the same type.
$nonpendingstatuses = [
self::DATAREQUEST_STATUS_COMPLETE,
self::DATAREQUEST_STATUS_CANCELLED,
self::DATAREQUEST_STATUS_REJECTED,
self::DATAREQUEST_STATUS_DOWNLOAD_READY,
self::DATAREQUEST_STATUS_EXPIRED,
self::DATAREQUEST_STATUS_DELETED,
];
list($statusinsql, $statusparams) = $DB->get_in_or_equal($nonpendingstatuses, SQL_PARAMS_NAMED, 'st', false);
list($userinsql, $userparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED, 'us');
$select = "userid {$userinsql} AND status {$statusinsql}";
$params = array_merge($statusparams, $userparams);
$requests = $DB->get_records_select(data_request::TABLE, $select, $params, 'userid', 'id, userid, type');
$returnval = [];
foreach ($userids as $userid) {
$returnval[$userid] = (object) [];
}
foreach ($requests as $request) {
$returnval[$request->userid]->{$request->type} = true;
}
return $returnval;
}
|
[
"public",
"static",
"function",
"find_ongoing_request_types_for_users",
"(",
"array",
"$",
"userids",
")",
":",
"array",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"empty",
"(",
"$",
"userids",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"// Check if the user already has an incomplete data request of the same type.",
"$",
"nonpendingstatuses",
"=",
"[",
"self",
"::",
"DATAREQUEST_STATUS_COMPLETE",
",",
"self",
"::",
"DATAREQUEST_STATUS_CANCELLED",
",",
"self",
"::",
"DATAREQUEST_STATUS_REJECTED",
",",
"self",
"::",
"DATAREQUEST_STATUS_DOWNLOAD_READY",
",",
"self",
"::",
"DATAREQUEST_STATUS_EXPIRED",
",",
"self",
"::",
"DATAREQUEST_STATUS_DELETED",
",",
"]",
";",
"list",
"(",
"$",
"statusinsql",
",",
"$",
"statusparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"nonpendingstatuses",
",",
"SQL_PARAMS_NAMED",
",",
"'st'",
",",
"false",
")",
";",
"list",
"(",
"$",
"userinsql",
",",
"$",
"userparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"userids",
",",
"SQL_PARAMS_NAMED",
",",
"'us'",
")",
";",
"$",
"select",
"=",
"\"userid {$userinsql} AND status {$statusinsql}\"",
";",
"$",
"params",
"=",
"array_merge",
"(",
"$",
"statusparams",
",",
"$",
"userparams",
")",
";",
"$",
"requests",
"=",
"$",
"DB",
"->",
"get_records_select",
"(",
"data_request",
"::",
"TABLE",
",",
"$",
"select",
",",
"$",
"params",
",",
"'userid'",
",",
"'id, userid, type'",
")",
";",
"$",
"returnval",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"userids",
"as",
"$",
"userid",
")",
"{",
"$",
"returnval",
"[",
"$",
"userid",
"]",
"=",
"(",
"object",
")",
"[",
"]",
";",
"}",
"foreach",
"(",
"$",
"requests",
"as",
"$",
"request",
")",
"{",
"$",
"returnval",
"[",
"$",
"request",
"->",
"userid",
"]",
"->",
"{",
"$",
"request",
"->",
"type",
"}",
"=",
"true",
";",
"}",
"return",
"$",
"returnval",
";",
"}"
] |
Find whether any ongoing requests exist for a set of users.
@param array $userids
@return array
|
[
"Find",
"whether",
"any",
"ongoing",
"requests",
"exist",
"for",
"a",
"set",
"of",
"users",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/api.php#L488-L522
|
218,825
|
moodle/moodle
|
admin/tool/dataprivacy/classes/api.php
|
api.is_active
|
public static function is_active($status) {
// List of statuses which doesn't require any further processing.
$finalstatuses = [
self::DATAREQUEST_STATUS_COMPLETE,
self::DATAREQUEST_STATUS_CANCELLED,
self::DATAREQUEST_STATUS_REJECTED,
self::DATAREQUEST_STATUS_DOWNLOAD_READY,
self::DATAREQUEST_STATUS_EXPIRED,
self::DATAREQUEST_STATUS_DELETED,
];
return !in_array($status, $finalstatuses);
}
|
php
|
public static function is_active($status) {
// List of statuses which doesn't require any further processing.
$finalstatuses = [
self::DATAREQUEST_STATUS_COMPLETE,
self::DATAREQUEST_STATUS_CANCELLED,
self::DATAREQUEST_STATUS_REJECTED,
self::DATAREQUEST_STATUS_DOWNLOAD_READY,
self::DATAREQUEST_STATUS_EXPIRED,
self::DATAREQUEST_STATUS_DELETED,
];
return !in_array($status, $finalstatuses);
}
|
[
"public",
"static",
"function",
"is_active",
"(",
"$",
"status",
")",
"{",
"// List of statuses which doesn't require any further processing.",
"$",
"finalstatuses",
"=",
"[",
"self",
"::",
"DATAREQUEST_STATUS_COMPLETE",
",",
"self",
"::",
"DATAREQUEST_STATUS_CANCELLED",
",",
"self",
"::",
"DATAREQUEST_STATUS_REJECTED",
",",
"self",
"::",
"DATAREQUEST_STATUS_DOWNLOAD_READY",
",",
"self",
"::",
"DATAREQUEST_STATUS_EXPIRED",
",",
"self",
"::",
"DATAREQUEST_STATUS_DELETED",
",",
"]",
";",
"return",
"!",
"in_array",
"(",
"$",
"status",
",",
"$",
"finalstatuses",
")",
";",
"}"
] |
Determines whether a request is active or not based on its status.
@param int $status The request status.
@return bool
|
[
"Determines",
"whether",
"a",
"request",
"is",
"active",
"or",
"not",
"based",
"on",
"its",
"status",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/api.php#L530-L542
|
218,826
|
moodle/moodle
|
admin/tool/dataprivacy/classes/api.php
|
api.update_request_status
|
public static function update_request_status($requestid, $status, $dpoid = 0, $comment = '') {
// Update the request.
$datarequest = new data_request($requestid);
$datarequest->set('status', $status);
if ($dpoid) {
$datarequest->set('dpo', $dpoid);
}
// Update the comment if necessary.
if (!empty(trim($comment))) {
$params = [
'date' => userdate(time()),
'comment' => $comment
];
$commenttosave = get_string('datecomment', 'tool_dataprivacy', $params);
// Check if there's an existing DPO comment.
$currentcomment = trim($datarequest->get('dpocomment'));
if ($currentcomment) {
// Append the new comment to the current comment and give them 1 line space in between.
$commenttosave = $currentcomment . PHP_EOL . PHP_EOL . $commenttosave;
}
$datarequest->set('dpocomment', $commenttosave);
}
return $datarequest->update();
}
|
php
|
public static function update_request_status($requestid, $status, $dpoid = 0, $comment = '') {
// Update the request.
$datarequest = new data_request($requestid);
$datarequest->set('status', $status);
if ($dpoid) {
$datarequest->set('dpo', $dpoid);
}
// Update the comment if necessary.
if (!empty(trim($comment))) {
$params = [
'date' => userdate(time()),
'comment' => $comment
];
$commenttosave = get_string('datecomment', 'tool_dataprivacy', $params);
// Check if there's an existing DPO comment.
$currentcomment = trim($datarequest->get('dpocomment'));
if ($currentcomment) {
// Append the new comment to the current comment and give them 1 line space in between.
$commenttosave = $currentcomment . PHP_EOL . PHP_EOL . $commenttosave;
}
$datarequest->set('dpocomment', $commenttosave);
}
return $datarequest->update();
}
|
[
"public",
"static",
"function",
"update_request_status",
"(",
"$",
"requestid",
",",
"$",
"status",
",",
"$",
"dpoid",
"=",
"0",
",",
"$",
"comment",
"=",
"''",
")",
"{",
"// Update the request.",
"$",
"datarequest",
"=",
"new",
"data_request",
"(",
"$",
"requestid",
")",
";",
"$",
"datarequest",
"->",
"set",
"(",
"'status'",
",",
"$",
"status",
")",
";",
"if",
"(",
"$",
"dpoid",
")",
"{",
"$",
"datarequest",
"->",
"set",
"(",
"'dpo'",
",",
"$",
"dpoid",
")",
";",
"}",
"// Update the comment if necessary.",
"if",
"(",
"!",
"empty",
"(",
"trim",
"(",
"$",
"comment",
")",
")",
")",
"{",
"$",
"params",
"=",
"[",
"'date'",
"=>",
"userdate",
"(",
"time",
"(",
")",
")",
",",
"'comment'",
"=>",
"$",
"comment",
"]",
";",
"$",
"commenttosave",
"=",
"get_string",
"(",
"'datecomment'",
",",
"'tool_dataprivacy'",
",",
"$",
"params",
")",
";",
"// Check if there's an existing DPO comment.",
"$",
"currentcomment",
"=",
"trim",
"(",
"$",
"datarequest",
"->",
"get",
"(",
"'dpocomment'",
")",
")",
";",
"if",
"(",
"$",
"currentcomment",
")",
"{",
"// Append the new comment to the current comment and give them 1 line space in between.",
"$",
"commenttosave",
"=",
"$",
"currentcomment",
".",
"PHP_EOL",
".",
"PHP_EOL",
".",
"$",
"commenttosave",
";",
"}",
"$",
"datarequest",
"->",
"set",
"(",
"'dpocomment'",
",",
"$",
"commenttosave",
")",
";",
"}",
"return",
"$",
"datarequest",
"->",
"update",
"(",
")",
";",
"}"
] |
Cancels the data request for a given request ID.
@param int $requestid The request identifier.
@param int $status The request status.
@param int $dpoid The user ID of the Data Protection Officer
@param string $comment The comment about the status update.
@return bool
@throws invalid_persistent_exception
@throws coding_exception
|
[
"Cancels",
"the",
"data",
"request",
"for",
"a",
"given",
"request",
"ID",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/api.php#L555-L579
|
218,827
|
moodle/moodle
|
admin/tool/dataprivacy/classes/api.php
|
api.approve_data_request
|
public static function approve_data_request($requestid) {
global $USER;
// Check first whether the user can manage data requests.
if (!self::can_manage_data_requests($USER->id)) {
$context = context_system::instance();
throw new required_capability_exception($context, 'tool/dataprivacy:managedatarequests', 'nopermissions', '');
}
// Check if request is already awaiting for approval.
$request = new data_request($requestid);
if ($request->get('status') != self::DATAREQUEST_STATUS_AWAITING_APPROVAL) {
throw new moodle_exception('errorrequestnotwaitingforapproval', 'tool_dataprivacy');
}
// Check if current user has permission to approve delete data request.
if ($request->get('type') == self::DATAREQUEST_TYPE_DELETE && !self::can_create_data_deletion_request_for_other()) {
throw new required_capability_exception(context_system::instance(),
'tool/dataprivacy:requestdeleteforotheruser', 'nopermissions', '');
}
// Update the status and the DPO.
$result = self::update_request_status($requestid, self::DATAREQUEST_STATUS_APPROVED, $USER->id);
// Fire an ad hoc task to initiate the data request process.
$task = new process_data_request_task();
$task->set_custom_data(['requestid' => $requestid]);
if ($request->get('type') == self::DATAREQUEST_TYPE_EXPORT) {
$task->set_userid($request->get('userid'));
}
manager::queue_adhoc_task($task, true);
return $result;
}
|
php
|
public static function approve_data_request($requestid) {
global $USER;
// Check first whether the user can manage data requests.
if (!self::can_manage_data_requests($USER->id)) {
$context = context_system::instance();
throw new required_capability_exception($context, 'tool/dataprivacy:managedatarequests', 'nopermissions', '');
}
// Check if request is already awaiting for approval.
$request = new data_request($requestid);
if ($request->get('status') != self::DATAREQUEST_STATUS_AWAITING_APPROVAL) {
throw new moodle_exception('errorrequestnotwaitingforapproval', 'tool_dataprivacy');
}
// Check if current user has permission to approve delete data request.
if ($request->get('type') == self::DATAREQUEST_TYPE_DELETE && !self::can_create_data_deletion_request_for_other()) {
throw new required_capability_exception(context_system::instance(),
'tool/dataprivacy:requestdeleteforotheruser', 'nopermissions', '');
}
// Update the status and the DPO.
$result = self::update_request_status($requestid, self::DATAREQUEST_STATUS_APPROVED, $USER->id);
// Fire an ad hoc task to initiate the data request process.
$task = new process_data_request_task();
$task->set_custom_data(['requestid' => $requestid]);
if ($request->get('type') == self::DATAREQUEST_TYPE_EXPORT) {
$task->set_userid($request->get('userid'));
}
manager::queue_adhoc_task($task, true);
return $result;
}
|
[
"public",
"static",
"function",
"approve_data_request",
"(",
"$",
"requestid",
")",
"{",
"global",
"$",
"USER",
";",
"// Check first whether the user can manage data requests.",
"if",
"(",
"!",
"self",
"::",
"can_manage_data_requests",
"(",
"$",
"USER",
"->",
"id",
")",
")",
"{",
"$",
"context",
"=",
"context_system",
"::",
"instance",
"(",
")",
";",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'tool/dataprivacy:managedatarequests'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// Check if request is already awaiting for approval.",
"$",
"request",
"=",
"new",
"data_request",
"(",
"$",
"requestid",
")",
";",
"if",
"(",
"$",
"request",
"->",
"get",
"(",
"'status'",
")",
"!=",
"self",
"::",
"DATAREQUEST_STATUS_AWAITING_APPROVAL",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'errorrequestnotwaitingforapproval'",
",",
"'tool_dataprivacy'",
")",
";",
"}",
"// Check if current user has permission to approve delete data request.",
"if",
"(",
"$",
"request",
"->",
"get",
"(",
"'type'",
")",
"==",
"self",
"::",
"DATAREQUEST_TYPE_DELETE",
"&&",
"!",
"self",
"::",
"can_create_data_deletion_request_for_other",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"context_system",
"::",
"instance",
"(",
")",
",",
"'tool/dataprivacy:requestdeleteforotheruser'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// Update the status and the DPO.",
"$",
"result",
"=",
"self",
"::",
"update_request_status",
"(",
"$",
"requestid",
",",
"self",
"::",
"DATAREQUEST_STATUS_APPROVED",
",",
"$",
"USER",
"->",
"id",
")",
";",
"// Fire an ad hoc task to initiate the data request process.",
"$",
"task",
"=",
"new",
"process_data_request_task",
"(",
")",
";",
"$",
"task",
"->",
"set_custom_data",
"(",
"[",
"'requestid'",
"=>",
"$",
"requestid",
"]",
")",
";",
"if",
"(",
"$",
"request",
"->",
"get",
"(",
"'type'",
")",
"==",
"self",
"::",
"DATAREQUEST_TYPE_EXPORT",
")",
"{",
"$",
"task",
"->",
"set_userid",
"(",
"$",
"request",
"->",
"get",
"(",
"'userid'",
")",
")",
";",
"}",
"manager",
"::",
"queue_adhoc_task",
"(",
"$",
"task",
",",
"true",
")",
";",
"return",
"$",
"result",
";",
"}"
] |
Approves a data request based on the request ID.
@param int $requestid The request identifier
@return bool
@throws coding_exception
@throws dml_exception
@throws invalid_persistent_exception
@throws required_capability_exception
@throws moodle_exception
|
[
"Approves",
"a",
"data",
"request",
"based",
"on",
"the",
"request",
"ID",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/api.php#L602-L635
|
218,828
|
moodle/moodle
|
admin/tool/dataprivacy/classes/api.php
|
api.deny_data_request
|
public static function deny_data_request($requestid) {
global $USER;
if (!self::can_manage_data_requests($USER->id)) {
$context = context_system::instance();
throw new required_capability_exception($context, 'tool/dataprivacy:managedatarequests', 'nopermissions', '');
}
// Check if request is already awaiting for approval.
$request = new data_request($requestid);
if ($request->get('status') != self::DATAREQUEST_STATUS_AWAITING_APPROVAL) {
throw new moodle_exception('errorrequestnotwaitingforapproval', 'tool_dataprivacy');
}
// Check if current user has permission to reject delete data request.
if ($request->get('type') == self::DATAREQUEST_TYPE_DELETE && !self::can_create_data_deletion_request_for_other()) {
throw new required_capability_exception(context_system::instance(),
'tool/dataprivacy:requestdeleteforotheruser', 'nopermissions', '');
}
// Update the status and the DPO.
return self::update_request_status($requestid, self::DATAREQUEST_STATUS_REJECTED, $USER->id);
}
|
php
|
public static function deny_data_request($requestid) {
global $USER;
if (!self::can_manage_data_requests($USER->id)) {
$context = context_system::instance();
throw new required_capability_exception($context, 'tool/dataprivacy:managedatarequests', 'nopermissions', '');
}
// Check if request is already awaiting for approval.
$request = new data_request($requestid);
if ($request->get('status') != self::DATAREQUEST_STATUS_AWAITING_APPROVAL) {
throw new moodle_exception('errorrequestnotwaitingforapproval', 'tool_dataprivacy');
}
// Check if current user has permission to reject delete data request.
if ($request->get('type') == self::DATAREQUEST_TYPE_DELETE && !self::can_create_data_deletion_request_for_other()) {
throw new required_capability_exception(context_system::instance(),
'tool/dataprivacy:requestdeleteforotheruser', 'nopermissions', '');
}
// Update the status and the DPO.
return self::update_request_status($requestid, self::DATAREQUEST_STATUS_REJECTED, $USER->id);
}
|
[
"public",
"static",
"function",
"deny_data_request",
"(",
"$",
"requestid",
")",
"{",
"global",
"$",
"USER",
";",
"if",
"(",
"!",
"self",
"::",
"can_manage_data_requests",
"(",
"$",
"USER",
"->",
"id",
")",
")",
"{",
"$",
"context",
"=",
"context_system",
"::",
"instance",
"(",
")",
";",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'tool/dataprivacy:managedatarequests'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// Check if request is already awaiting for approval.",
"$",
"request",
"=",
"new",
"data_request",
"(",
"$",
"requestid",
")",
";",
"if",
"(",
"$",
"request",
"->",
"get",
"(",
"'status'",
")",
"!=",
"self",
"::",
"DATAREQUEST_STATUS_AWAITING_APPROVAL",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'errorrequestnotwaitingforapproval'",
",",
"'tool_dataprivacy'",
")",
";",
"}",
"// Check if current user has permission to reject delete data request.",
"if",
"(",
"$",
"request",
"->",
"get",
"(",
"'type'",
")",
"==",
"self",
"::",
"DATAREQUEST_TYPE_DELETE",
"&&",
"!",
"self",
"::",
"can_create_data_deletion_request_for_other",
"(",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"context_system",
"::",
"instance",
"(",
")",
",",
"'tool/dataprivacy:requestdeleteforotheruser'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// Update the status and the DPO.",
"return",
"self",
"::",
"update_request_status",
"(",
"$",
"requestid",
",",
"self",
"::",
"DATAREQUEST_STATUS_REJECTED",
",",
"$",
"USER",
"->",
"id",
")",
";",
"}"
] |
Rejects a data request based on the request ID.
@param int $requestid The request identifier
@return bool
@throws coding_exception
@throws dml_exception
@throws invalid_persistent_exception
@throws required_capability_exception
@throws moodle_exception
|
[
"Rejects",
"a",
"data",
"request",
"based",
"on",
"the",
"request",
"ID",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/api.php#L648-L670
|
218,829
|
moodle/moodle
|
admin/tool/dataprivacy/classes/api.php
|
api.notify_dpo
|
public static function notify_dpo($dpo, data_request $request) {
global $PAGE, $SITE;
$output = $PAGE->get_renderer('tool_dataprivacy');
$usercontext = \context_user::instance($request->get('requestedby'));
$requestexporter = new data_request_exporter($request, ['context' => $usercontext]);
$requestdata = $requestexporter->export($output);
// Create message to send to the Data Protection Officer(s).
$typetext = null;
$typetext = $requestdata->typename;
$subject = get_string('datarequestemailsubject', 'tool_dataprivacy', $typetext);
$requestedby = $requestdata->requestedbyuser;
$datarequestsurl = new moodle_url('/admin/tool/dataprivacy/datarequests.php');
$message = new message();
$message->courseid = $SITE->id;
$message->component = 'tool_dataprivacy';
$message->name = 'contactdataprotectionofficer';
$message->userfrom = $requestedby->id;
$message->replyto = $requestedby->email;
$message->replytoname = $requestedby->fullname;
$message->subject = $subject;
$message->fullmessageformat = FORMAT_HTML;
$message->notification = 1;
$message->contexturl = $datarequestsurl;
$message->contexturlname = get_string('datarequests', 'tool_dataprivacy');
// Prepare the context data for the email message body.
$messagetextdata = [
'requestedby' => $requestedby->fullname,
'requesttype' => $typetext,
'requestdate' => userdate($requestdata->timecreated),
'requestorigin' => $SITE->fullname,
'requestoriginurl' => new moodle_url('/'),
'requestcomments' => $requestdata->messagehtml,
'datarequestsurl' => $datarequestsurl
];
$requestingfor = $requestdata->foruser;
if ($requestedby->id == $requestingfor->id) {
$messagetextdata['requestfor'] = $messagetextdata['requestedby'];
} else {
$messagetextdata['requestfor'] = $requestingfor->fullname;
}
// Email the data request to the Data Protection Officer(s)/Admin(s).
$messagetextdata['dponame'] = fullname($dpo);
// Render message email body.
$messagehtml = $output->render_from_template('tool_dataprivacy/data_request_email', $messagetextdata);
$message->userto = $dpo;
$message->fullmessage = html_to_text($messagehtml);
$message->fullmessagehtml = $messagehtml;
// Send message.
return message_send($message);
}
|
php
|
public static function notify_dpo($dpo, data_request $request) {
global $PAGE, $SITE;
$output = $PAGE->get_renderer('tool_dataprivacy');
$usercontext = \context_user::instance($request->get('requestedby'));
$requestexporter = new data_request_exporter($request, ['context' => $usercontext]);
$requestdata = $requestexporter->export($output);
// Create message to send to the Data Protection Officer(s).
$typetext = null;
$typetext = $requestdata->typename;
$subject = get_string('datarequestemailsubject', 'tool_dataprivacy', $typetext);
$requestedby = $requestdata->requestedbyuser;
$datarequestsurl = new moodle_url('/admin/tool/dataprivacy/datarequests.php');
$message = new message();
$message->courseid = $SITE->id;
$message->component = 'tool_dataprivacy';
$message->name = 'contactdataprotectionofficer';
$message->userfrom = $requestedby->id;
$message->replyto = $requestedby->email;
$message->replytoname = $requestedby->fullname;
$message->subject = $subject;
$message->fullmessageformat = FORMAT_HTML;
$message->notification = 1;
$message->contexturl = $datarequestsurl;
$message->contexturlname = get_string('datarequests', 'tool_dataprivacy');
// Prepare the context data for the email message body.
$messagetextdata = [
'requestedby' => $requestedby->fullname,
'requesttype' => $typetext,
'requestdate' => userdate($requestdata->timecreated),
'requestorigin' => $SITE->fullname,
'requestoriginurl' => new moodle_url('/'),
'requestcomments' => $requestdata->messagehtml,
'datarequestsurl' => $datarequestsurl
];
$requestingfor = $requestdata->foruser;
if ($requestedby->id == $requestingfor->id) {
$messagetextdata['requestfor'] = $messagetextdata['requestedby'];
} else {
$messagetextdata['requestfor'] = $requestingfor->fullname;
}
// Email the data request to the Data Protection Officer(s)/Admin(s).
$messagetextdata['dponame'] = fullname($dpo);
// Render message email body.
$messagehtml = $output->render_from_template('tool_dataprivacy/data_request_email', $messagetextdata);
$message->userto = $dpo;
$message->fullmessage = html_to_text($messagehtml);
$message->fullmessagehtml = $messagehtml;
// Send message.
return message_send($message);
}
|
[
"public",
"static",
"function",
"notify_dpo",
"(",
"$",
"dpo",
",",
"data_request",
"$",
"request",
")",
"{",
"global",
"$",
"PAGE",
",",
"$",
"SITE",
";",
"$",
"output",
"=",
"$",
"PAGE",
"->",
"get_renderer",
"(",
"'tool_dataprivacy'",
")",
";",
"$",
"usercontext",
"=",
"\\",
"context_user",
"::",
"instance",
"(",
"$",
"request",
"->",
"get",
"(",
"'requestedby'",
")",
")",
";",
"$",
"requestexporter",
"=",
"new",
"data_request_exporter",
"(",
"$",
"request",
",",
"[",
"'context'",
"=>",
"$",
"usercontext",
"]",
")",
";",
"$",
"requestdata",
"=",
"$",
"requestexporter",
"->",
"export",
"(",
"$",
"output",
")",
";",
"// Create message to send to the Data Protection Officer(s).",
"$",
"typetext",
"=",
"null",
";",
"$",
"typetext",
"=",
"$",
"requestdata",
"->",
"typename",
";",
"$",
"subject",
"=",
"get_string",
"(",
"'datarequestemailsubject'",
",",
"'tool_dataprivacy'",
",",
"$",
"typetext",
")",
";",
"$",
"requestedby",
"=",
"$",
"requestdata",
"->",
"requestedbyuser",
";",
"$",
"datarequestsurl",
"=",
"new",
"moodle_url",
"(",
"'/admin/tool/dataprivacy/datarequests.php'",
")",
";",
"$",
"message",
"=",
"new",
"message",
"(",
")",
";",
"$",
"message",
"->",
"courseid",
"=",
"$",
"SITE",
"->",
"id",
";",
"$",
"message",
"->",
"component",
"=",
"'tool_dataprivacy'",
";",
"$",
"message",
"->",
"name",
"=",
"'contactdataprotectionofficer'",
";",
"$",
"message",
"->",
"userfrom",
"=",
"$",
"requestedby",
"->",
"id",
";",
"$",
"message",
"->",
"replyto",
"=",
"$",
"requestedby",
"->",
"email",
";",
"$",
"message",
"->",
"replytoname",
"=",
"$",
"requestedby",
"->",
"fullname",
";",
"$",
"message",
"->",
"subject",
"=",
"$",
"subject",
";",
"$",
"message",
"->",
"fullmessageformat",
"=",
"FORMAT_HTML",
";",
"$",
"message",
"->",
"notification",
"=",
"1",
";",
"$",
"message",
"->",
"contexturl",
"=",
"$",
"datarequestsurl",
";",
"$",
"message",
"->",
"contexturlname",
"=",
"get_string",
"(",
"'datarequests'",
",",
"'tool_dataprivacy'",
")",
";",
"// Prepare the context data for the email message body.",
"$",
"messagetextdata",
"=",
"[",
"'requestedby'",
"=>",
"$",
"requestedby",
"->",
"fullname",
",",
"'requesttype'",
"=>",
"$",
"typetext",
",",
"'requestdate'",
"=>",
"userdate",
"(",
"$",
"requestdata",
"->",
"timecreated",
")",
",",
"'requestorigin'",
"=>",
"$",
"SITE",
"->",
"fullname",
",",
"'requestoriginurl'",
"=>",
"new",
"moodle_url",
"(",
"'/'",
")",
",",
"'requestcomments'",
"=>",
"$",
"requestdata",
"->",
"messagehtml",
",",
"'datarequestsurl'",
"=>",
"$",
"datarequestsurl",
"]",
";",
"$",
"requestingfor",
"=",
"$",
"requestdata",
"->",
"foruser",
";",
"if",
"(",
"$",
"requestedby",
"->",
"id",
"==",
"$",
"requestingfor",
"->",
"id",
")",
"{",
"$",
"messagetextdata",
"[",
"'requestfor'",
"]",
"=",
"$",
"messagetextdata",
"[",
"'requestedby'",
"]",
";",
"}",
"else",
"{",
"$",
"messagetextdata",
"[",
"'requestfor'",
"]",
"=",
"$",
"requestingfor",
"->",
"fullname",
";",
"}",
"// Email the data request to the Data Protection Officer(s)/Admin(s).",
"$",
"messagetextdata",
"[",
"'dponame'",
"]",
"=",
"fullname",
"(",
"$",
"dpo",
")",
";",
"// Render message email body.",
"$",
"messagehtml",
"=",
"$",
"output",
"->",
"render_from_template",
"(",
"'tool_dataprivacy/data_request_email'",
",",
"$",
"messagetextdata",
")",
";",
"$",
"message",
"->",
"userto",
"=",
"$",
"dpo",
";",
"$",
"message",
"->",
"fullmessage",
"=",
"html_to_text",
"(",
"$",
"messagehtml",
")",
";",
"$",
"message",
"->",
"fullmessagehtml",
"=",
"$",
"messagehtml",
";",
"// Send message.",
"return",
"message_send",
"(",
"$",
"message",
")",
";",
"}"
] |
Sends a message to the site's Data Protection Officer about a request.
@param stdClass $dpo The DPO user record
@param data_request $request The data request
@return int|false
@throws coding_exception
@throws moodle_exception
|
[
"Sends",
"a",
"message",
"to",
"the",
"site",
"s",
"Data",
"Protection",
"Officer",
"about",
"a",
"request",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/api.php#L681-L737
|
218,830
|
moodle/moodle
|
admin/tool/dataprivacy/classes/api.php
|
api.can_create_data_request_for_user
|
public static function can_create_data_request_for_user($user, $requester = null) {
$usercontext = \context_user::instance($user);
return has_capability('tool/dataprivacy:makedatarequestsforchildren', $usercontext, $requester);
}
|
php
|
public static function can_create_data_request_for_user($user, $requester = null) {
$usercontext = \context_user::instance($user);
return has_capability('tool/dataprivacy:makedatarequestsforchildren', $usercontext, $requester);
}
|
[
"public",
"static",
"function",
"can_create_data_request_for_user",
"(",
"$",
"user",
",",
"$",
"requester",
"=",
"null",
")",
"{",
"$",
"usercontext",
"=",
"\\",
"context_user",
"::",
"instance",
"(",
"$",
"user",
")",
";",
"return",
"has_capability",
"(",
"'tool/dataprivacy:makedatarequestsforchildren'",
",",
"$",
"usercontext",
",",
"$",
"requester",
")",
";",
"}"
] |
Checks whether a non-DPO user can make a data request for another user.
@param int $user The user ID of the target user.
@param int $requester The user ID of the user making the request.
@return bool
|
[
"Checks",
"whether",
"a",
"non",
"-",
"DPO",
"user",
"can",
"make",
"a",
"data",
"request",
"for",
"another",
"user",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/api.php#L746-L750
|
218,831
|
moodle/moodle
|
admin/tool/dataprivacy/classes/api.php
|
api.require_can_create_data_request_for_user
|
public static function require_can_create_data_request_for_user($user, $requester = null) {
$usercontext = \context_user::instance($user);
require_capability('tool/dataprivacy:makedatarequestsforchildren', $usercontext, $requester);
return true;
}
|
php
|
public static function require_can_create_data_request_for_user($user, $requester = null) {
$usercontext = \context_user::instance($user);
require_capability('tool/dataprivacy:makedatarequestsforchildren', $usercontext, $requester);
return true;
}
|
[
"public",
"static",
"function",
"require_can_create_data_request_for_user",
"(",
"$",
"user",
",",
"$",
"requester",
"=",
"null",
")",
"{",
"$",
"usercontext",
"=",
"\\",
"context_user",
"::",
"instance",
"(",
"$",
"user",
")",
";",
"require_capability",
"(",
"'tool/dataprivacy:makedatarequestsforchildren'",
",",
"$",
"usercontext",
",",
"$",
"requester",
")",
";",
"return",
"true",
";",
"}"
] |
Require that the current user can make a data request for the specified other user.
@param int $user The user ID of the target user.
@param int $requester The user ID of the user making the request.
@return bool
|
[
"Require",
"that",
"the",
"current",
"user",
"can",
"make",
"a",
"data",
"request",
"for",
"the",
"specified",
"other",
"user",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/api.php#L759-L765
|
218,832
|
moodle/moodle
|
admin/tool/dataprivacy/classes/api.php
|
api.can_create_data_deletion_request_for_self
|
public static function can_create_data_deletion_request_for_self(int $userid = null): bool {
global $USER;
$userid = $userid ?: $USER->id;
return has_capability('tool/dataprivacy:requestdelete', \context_user::instance($userid), $userid);
}
|
php
|
public static function can_create_data_deletion_request_for_self(int $userid = null): bool {
global $USER;
$userid = $userid ?: $USER->id;
return has_capability('tool/dataprivacy:requestdelete', \context_user::instance($userid), $userid);
}
|
[
"public",
"static",
"function",
"can_create_data_deletion_request_for_self",
"(",
"int",
"$",
"userid",
"=",
"null",
")",
":",
"bool",
"{",
"global",
"$",
"USER",
";",
"$",
"userid",
"=",
"$",
"userid",
"?",
":",
"$",
"USER",
"->",
"id",
";",
"return",
"has_capability",
"(",
"'tool/dataprivacy:requestdelete'",
",",
"\\",
"context_user",
"::",
"instance",
"(",
"$",
"userid",
")",
",",
"$",
"userid",
")",
";",
"}"
] |
Check if user has permisson to create data deletion request for themselves.
@param int|null $userid ID of the user.
@return bool
@throws coding_exception
|
[
"Check",
"if",
"user",
"has",
"permisson",
"to",
"create",
"data",
"deletion",
"request",
"for",
"themselves",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/api.php#L774-L778
|
218,833
|
moodle/moodle
|
admin/tool/dataprivacy/classes/api.php
|
api.can_create_data_deletion_request_for_other
|
public static function can_create_data_deletion_request_for_other(int $userid = null): bool {
global $USER;
$userid = $userid ?: $USER->id;
return has_capability('tool/dataprivacy:requestdeleteforotheruser', context_system::instance(), $userid);
}
|
php
|
public static function can_create_data_deletion_request_for_other(int $userid = null): bool {
global $USER;
$userid = $userid ?: $USER->id;
return has_capability('tool/dataprivacy:requestdeleteforotheruser', context_system::instance(), $userid);
}
|
[
"public",
"static",
"function",
"can_create_data_deletion_request_for_other",
"(",
"int",
"$",
"userid",
"=",
"null",
")",
":",
"bool",
"{",
"global",
"$",
"USER",
";",
"$",
"userid",
"=",
"$",
"userid",
"?",
":",
"$",
"USER",
"->",
"id",
";",
"return",
"has_capability",
"(",
"'tool/dataprivacy:requestdeleteforotheruser'",
",",
"context_system",
"::",
"instance",
"(",
")",
",",
"$",
"userid",
")",
";",
"}"
] |
Check if user has permission to create data deletion request for another user.
@param int|null $userid ID of the user.
@return bool
@throws coding_exception
@throws dml_exception
|
[
"Check",
"if",
"user",
"has",
"permission",
"to",
"create",
"data",
"deletion",
"request",
"for",
"another",
"user",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/api.php#L788-L792
|
218,834
|
moodle/moodle
|
admin/tool/dataprivacy/classes/api.php
|
api.can_create_data_deletion_request_for_children
|
public static function can_create_data_deletion_request_for_children(int $userid, int $requesterid = null): bool {
global $USER;
$requesterid = $requesterid ?: $USER->id;
return has_capability('tool/dataprivacy:makedatadeletionrequestsforchildren', \context_user::instance($userid),
$requesterid);
}
|
php
|
public static function can_create_data_deletion_request_for_children(int $userid, int $requesterid = null): bool {
global $USER;
$requesterid = $requesterid ?: $USER->id;
return has_capability('tool/dataprivacy:makedatadeletionrequestsforchildren', \context_user::instance($userid),
$requesterid);
}
|
[
"public",
"static",
"function",
"can_create_data_deletion_request_for_children",
"(",
"int",
"$",
"userid",
",",
"int",
"$",
"requesterid",
"=",
"null",
")",
":",
"bool",
"{",
"global",
"$",
"USER",
";",
"$",
"requesterid",
"=",
"$",
"requesterid",
"?",
":",
"$",
"USER",
"->",
"id",
";",
"return",
"has_capability",
"(",
"'tool/dataprivacy:makedatadeletionrequestsforchildren'",
",",
"\\",
"context_user",
"::",
"instance",
"(",
"$",
"userid",
")",
",",
"$",
"requesterid",
")",
";",
"}"
] |
Check if parent can create data deletion request for their children.
@param int $userid ID of a user being requested.
@param int|null $requesterid ID of a user making request.
@return bool
@throws coding_exception
|
[
"Check",
"if",
"parent",
"can",
"create",
"data",
"deletion",
"request",
"for",
"their",
"children",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/api.php#L802-L807
|
218,835
|
moodle/moodle
|
admin/tool/dataprivacy/classes/api.php
|
api.can_download_data_request_for_user
|
public static function can_download_data_request_for_user($userid, $requesterid, $downloaderid = null) {
global $USER;
if (!$downloaderid) {
$downloaderid = $USER->id;
}
$usercontext = \context_user::instance($userid);
// If it's your own and you have the right capability, you can download it.
if ($userid == $downloaderid && has_capability('tool/dataprivacy:downloadownrequest', $usercontext, $downloaderid)) {
return true;
}
// If you can download anyone's in that context, you can download it.
if (has_capability('tool/dataprivacy:downloadallrequests', $usercontext, $downloaderid)) {
return true;
}
// If you can have the 'child access' ability to request in that context, and you are the one
// who requested it, then you can download it.
if ($requesterid == $downloaderid && self::can_create_data_request_for_user($userid, $requesterid)) {
return true;
}
return false;
}
|
php
|
public static function can_download_data_request_for_user($userid, $requesterid, $downloaderid = null) {
global $USER;
if (!$downloaderid) {
$downloaderid = $USER->id;
}
$usercontext = \context_user::instance($userid);
// If it's your own and you have the right capability, you can download it.
if ($userid == $downloaderid && has_capability('tool/dataprivacy:downloadownrequest', $usercontext, $downloaderid)) {
return true;
}
// If you can download anyone's in that context, you can download it.
if (has_capability('tool/dataprivacy:downloadallrequests', $usercontext, $downloaderid)) {
return true;
}
// If you can have the 'child access' ability to request in that context, and you are the one
// who requested it, then you can download it.
if ($requesterid == $downloaderid && self::can_create_data_request_for_user($userid, $requesterid)) {
return true;
}
return false;
}
|
[
"public",
"static",
"function",
"can_download_data_request_for_user",
"(",
"$",
"userid",
",",
"$",
"requesterid",
",",
"$",
"downloaderid",
"=",
"null",
")",
"{",
"global",
"$",
"USER",
";",
"if",
"(",
"!",
"$",
"downloaderid",
")",
"{",
"$",
"downloaderid",
"=",
"$",
"USER",
"->",
"id",
";",
"}",
"$",
"usercontext",
"=",
"\\",
"context_user",
"::",
"instance",
"(",
"$",
"userid",
")",
";",
"// If it's your own and you have the right capability, you can download it.",
"if",
"(",
"$",
"userid",
"==",
"$",
"downloaderid",
"&&",
"has_capability",
"(",
"'tool/dataprivacy:downloadownrequest'",
",",
"$",
"usercontext",
",",
"$",
"downloaderid",
")",
")",
"{",
"return",
"true",
";",
"}",
"// If you can download anyone's in that context, you can download it.",
"if",
"(",
"has_capability",
"(",
"'tool/dataprivacy:downloadallrequests'",
",",
"$",
"usercontext",
",",
"$",
"downloaderid",
")",
")",
"{",
"return",
"true",
";",
"}",
"// If you can have the 'child access' ability to request in that context, and you are the one",
"// who requested it, then you can download it.",
"if",
"(",
"$",
"requesterid",
"==",
"$",
"downloaderid",
"&&",
"self",
"::",
"can_create_data_request_for_user",
"(",
"$",
"userid",
",",
"$",
"requesterid",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Checks whether a user can download a data request.
@param int $userid Target user id (subject of data request)
@param int $requesterid Requester user id (person who requsted it)
@param int|null $downloaderid Person who wants to download user id (default current)
@return bool
@throws coding_exception
|
[
"Checks",
"whether",
"a",
"user",
"can",
"download",
"a",
"data",
"request",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/api.php#L818-L840
|
218,836
|
moodle/moodle
|
admin/tool/dataprivacy/classes/api.php
|
api.get_download_link
|
public static function get_download_link(\context_user $usercontext, $requestid) {
$downloadurl = moodle_url::make_pluginfile_url($usercontext->id,
'tool_dataprivacy', 'export', $requestid, '/', 'export.zip', true);
$downloadtext = get_string('download', 'tool_dataprivacy');
return new \action_menu_link_secondary($downloadurl, null, $downloadtext);
}
|
php
|
public static function get_download_link(\context_user $usercontext, $requestid) {
$downloadurl = moodle_url::make_pluginfile_url($usercontext->id,
'tool_dataprivacy', 'export', $requestid, '/', 'export.zip', true);
$downloadtext = get_string('download', 'tool_dataprivacy');
return new \action_menu_link_secondary($downloadurl, null, $downloadtext);
}
|
[
"public",
"static",
"function",
"get_download_link",
"(",
"\\",
"context_user",
"$",
"usercontext",
",",
"$",
"requestid",
")",
"{",
"$",
"downloadurl",
"=",
"moodle_url",
"::",
"make_pluginfile_url",
"(",
"$",
"usercontext",
"->",
"id",
",",
"'tool_dataprivacy'",
",",
"'export'",
",",
"$",
"requestid",
",",
"'/'",
",",
"'export.zip'",
",",
"true",
")",
";",
"$",
"downloadtext",
"=",
"get_string",
"(",
"'download'",
",",
"'tool_dataprivacy'",
")",
";",
"return",
"new",
"\\",
"action_menu_link_secondary",
"(",
"$",
"downloadurl",
",",
"null",
",",
"$",
"downloadtext",
")",
";",
"}"
] |
Gets an action menu link to download a data request.
@param \context_user $usercontext User context (of user who the data is for)
@param int $requestid Request id
@return \action_menu_link_secondary Action menu link
@throws coding_exception
|
[
"Gets",
"an",
"action",
"menu",
"link",
"to",
"download",
"a",
"data",
"request",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/api.php#L850-L855
|
218,837
|
moodle/moodle
|
admin/tool/dataprivacy/classes/api.php
|
api.update_purpose
|
public static function update_purpose(stdClass $record) {
if (!isset($record->sensitivedatareasons)) {
$record->sensitivedatareasons = '';
}
$purpose = new purpose($record->id);
$purpose->from_record($record);
$result = $purpose->update();
return $purpose;
}
|
php
|
public static function update_purpose(stdClass $record) {
if (!isset($record->sensitivedatareasons)) {
$record->sensitivedatareasons = '';
}
$purpose = new purpose($record->id);
$purpose->from_record($record);
$result = $purpose->update();
return $purpose;
}
|
[
"public",
"static",
"function",
"update_purpose",
"(",
"stdClass",
"$",
"record",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"record",
"->",
"sensitivedatareasons",
")",
")",
"{",
"$",
"record",
"->",
"sensitivedatareasons",
"=",
"''",
";",
"}",
"$",
"purpose",
"=",
"new",
"purpose",
"(",
"$",
"record",
"->",
"id",
")",
";",
"$",
"purpose",
"->",
"from_record",
"(",
"$",
"record",
")",
";",
"$",
"result",
"=",
"$",
"purpose",
"->",
"update",
"(",
")",
";",
"return",
"$",
"purpose",
";",
"}"
] |
Updates an existing data purpose.
@param stdClass $record
@return \tool_dataprivacy\purpose.
|
[
"Updates",
"an",
"existing",
"data",
"purpose",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/api.php#L876-L887
|
218,838
|
moodle/moodle
|
admin/tool/dataprivacy/classes/api.php
|
api.update_category
|
public static function update_category(stdClass $record) {
$category = new category($record->id);
$category->from_record($record);
$result = $category->update();
return $category;
}
|
php
|
public static function update_category(stdClass $record) {
$category = new category($record->id);
$category->from_record($record);
$result = $category->update();
return $category;
}
|
[
"public",
"static",
"function",
"update_category",
"(",
"stdClass",
"$",
"record",
")",
"{",
"$",
"category",
"=",
"new",
"category",
"(",
"$",
"record",
"->",
"id",
")",
";",
"$",
"category",
"->",
"from_record",
"(",
"$",
"record",
")",
";",
"$",
"result",
"=",
"$",
"category",
"->",
"update",
"(",
")",
";",
"return",
"$",
"category",
";",
"}"
] |
Updates an existing data category.
@param stdClass $record
@return \tool_dataprivacy\category.
|
[
"Updates",
"an",
"existing",
"data",
"category",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/api.php#L931-L938
|
218,839
|
moodle/moodle
|
admin/tool/dataprivacy/classes/api.php
|
api.set_context_instance
|
public static function set_context_instance($record) {
if ($instance = context_instance::get_record_by_contextid($record->contextid, false)) {
// Update.
$instance->from_record($record);
if (empty($record->purposeid) && empty($record->categoryid)) {
// We accept one of them to be null but we delete it if both are null.
self::unset_context_instance($instance);
return;
}
} else {
// Add.
$instance = new context_instance(0, $record);
}
$instance->save();
return $instance;
}
|
php
|
public static function set_context_instance($record) {
if ($instance = context_instance::get_record_by_contextid($record->contextid, false)) {
// Update.
$instance->from_record($record);
if (empty($record->purposeid) && empty($record->categoryid)) {
// We accept one of them to be null but we delete it if both are null.
self::unset_context_instance($instance);
return;
}
} else {
// Add.
$instance = new context_instance(0, $record);
}
$instance->save();
return $instance;
}
|
[
"public",
"static",
"function",
"set_context_instance",
"(",
"$",
"record",
")",
"{",
"if",
"(",
"$",
"instance",
"=",
"context_instance",
"::",
"get_record_by_contextid",
"(",
"$",
"record",
"->",
"contextid",
",",
"false",
")",
")",
"{",
"// Update.",
"$",
"instance",
"->",
"from_record",
"(",
"$",
"record",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"record",
"->",
"purposeid",
")",
"&&",
"empty",
"(",
"$",
"record",
"->",
"categoryid",
")",
")",
"{",
"// We accept one of them to be null but we delete it if both are null.",
"self",
"::",
"unset_context_instance",
"(",
"$",
"instance",
")",
";",
"return",
";",
"}",
"}",
"else",
"{",
"// Add.",
"$",
"instance",
"=",
"new",
"context_instance",
"(",
"0",
",",
"$",
"record",
")",
";",
"}",
"$",
"instance",
"->",
"save",
"(",
")",
";",
"return",
"$",
"instance",
";",
"}"
] |
Sets the context instance purpose and category.
@param \stdClass $record
@return \tool_dataprivacy\context_instance
|
[
"Sets",
"the",
"context",
"instance",
"purpose",
"and",
"category",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/api.php#L969-L987
|
218,840
|
moodle/moodle
|
admin/tool/dataprivacy/classes/api.php
|
api.set_contextlevel
|
public static function set_contextlevel($record) {
global $DB;
if ($record->contextlevel != CONTEXT_SYSTEM && $record->contextlevel != CONTEXT_USER) {
throw new \coding_exception('Only context system and context user can set a contextlevel ' .
'purpose and retention');
}
if ($contextlevel = contextlevel::get_record_by_contextlevel($record->contextlevel, false)) {
// Update.
$contextlevel->from_record($record);
} else {
// Add.
$contextlevel = new contextlevel(0, $record);
}
$contextlevel->save();
// We sync with their defaults as we removed these options from the defaults page.
$classname = \context_helper::get_class_for_level($record->contextlevel);
list($purposevar, $categoryvar) = data_registry::var_names_from_context($classname);
set_config($purposevar, $record->purposeid, 'tool_dataprivacy');
set_config($categoryvar, $record->categoryid, 'tool_dataprivacy');
return $contextlevel;
}
|
php
|
public static function set_contextlevel($record) {
global $DB;
if ($record->contextlevel != CONTEXT_SYSTEM && $record->contextlevel != CONTEXT_USER) {
throw new \coding_exception('Only context system and context user can set a contextlevel ' .
'purpose and retention');
}
if ($contextlevel = contextlevel::get_record_by_contextlevel($record->contextlevel, false)) {
// Update.
$contextlevel->from_record($record);
} else {
// Add.
$contextlevel = new contextlevel(0, $record);
}
$contextlevel->save();
// We sync with their defaults as we removed these options from the defaults page.
$classname = \context_helper::get_class_for_level($record->contextlevel);
list($purposevar, $categoryvar) = data_registry::var_names_from_context($classname);
set_config($purposevar, $record->purposeid, 'tool_dataprivacy');
set_config($categoryvar, $record->categoryid, 'tool_dataprivacy');
return $contextlevel;
}
|
[
"public",
"static",
"function",
"set_contextlevel",
"(",
"$",
"record",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"$",
"record",
"->",
"contextlevel",
"!=",
"CONTEXT_SYSTEM",
"&&",
"$",
"record",
"->",
"contextlevel",
"!=",
"CONTEXT_USER",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Only context system and context user can set a contextlevel '",
".",
"'purpose and retention'",
")",
";",
"}",
"if",
"(",
"$",
"contextlevel",
"=",
"contextlevel",
"::",
"get_record_by_contextlevel",
"(",
"$",
"record",
"->",
"contextlevel",
",",
"false",
")",
")",
"{",
"// Update.",
"$",
"contextlevel",
"->",
"from_record",
"(",
"$",
"record",
")",
";",
"}",
"else",
"{",
"// Add.",
"$",
"contextlevel",
"=",
"new",
"contextlevel",
"(",
"0",
",",
"$",
"record",
")",
";",
"}",
"$",
"contextlevel",
"->",
"save",
"(",
")",
";",
"// We sync with their defaults as we removed these options from the defaults page.",
"$",
"classname",
"=",
"\\",
"context_helper",
"::",
"get_class_for_level",
"(",
"$",
"record",
"->",
"contextlevel",
")",
";",
"list",
"(",
"$",
"purposevar",
",",
"$",
"categoryvar",
")",
"=",
"data_registry",
"::",
"var_names_from_context",
"(",
"$",
"classname",
")",
";",
"set_config",
"(",
"$",
"purposevar",
",",
"$",
"record",
"->",
"purposeid",
",",
"'tool_dataprivacy'",
")",
";",
"set_config",
"(",
"$",
"categoryvar",
",",
"$",
"record",
"->",
"categoryid",
",",
"'tool_dataprivacy'",
")",
";",
"return",
"$",
"contextlevel",
";",
"}"
] |
Sets the context level purpose and category.
@throws \coding_exception
@param \stdClass $record
@return contextlevel
|
[
"Sets",
"the",
"context",
"level",
"purpose",
"and",
"category",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/api.php#L1006-L1030
|
218,841
|
moodle/moodle
|
admin/tool/dataprivacy/classes/api.php
|
api.get_effective_context_category
|
public static function get_effective_context_category(\context $context, $forcedvalue = false) {
if (!data_registry::defaults_set()) {
return false;
}
return data_registry::get_effective_context_value($context, 'category', $forcedvalue);
}
|
php
|
public static function get_effective_context_category(\context $context, $forcedvalue = false) {
if (!data_registry::defaults_set()) {
return false;
}
return data_registry::get_effective_context_value($context, 'category', $forcedvalue);
}
|
[
"public",
"static",
"function",
"get_effective_context_category",
"(",
"\\",
"context",
"$",
"context",
",",
"$",
"forcedvalue",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"data_registry",
"::",
"defaults_set",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"data_registry",
"::",
"get_effective_context_value",
"(",
"$",
"context",
",",
"'category'",
",",
"$",
"forcedvalue",
")",
";",
"}"
] |
Returns the effective category given a context instance.
@param \context $context
@param int $forcedvalue Use this categoryid value as if this was this context instance category.
@return category|false
|
[
"Returns",
"the",
"effective",
"category",
"given",
"a",
"context",
"instance",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/api.php#L1039-L1045
|
218,842
|
moodle/moodle
|
admin/tool/dataprivacy/classes/api.php
|
api.get_effective_context_purpose
|
public static function get_effective_context_purpose(\context $context, $forcedvalue = false) {
if (!data_registry::defaults_set()) {
return false;
}
return data_registry::get_effective_context_value($context, 'purpose', $forcedvalue);
}
|
php
|
public static function get_effective_context_purpose(\context $context, $forcedvalue = false) {
if (!data_registry::defaults_set()) {
return false;
}
return data_registry::get_effective_context_value($context, 'purpose', $forcedvalue);
}
|
[
"public",
"static",
"function",
"get_effective_context_purpose",
"(",
"\\",
"context",
"$",
"context",
",",
"$",
"forcedvalue",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"data_registry",
"::",
"defaults_set",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"data_registry",
"::",
"get_effective_context_value",
"(",
"$",
"context",
",",
"'purpose'",
",",
"$",
"forcedvalue",
")",
";",
"}"
] |
Returns the effective purpose given a context instance.
@param \context $context
@param int $forcedvalue Use this purposeid value as if this was this context instance purpose.
@return purpose|false
|
[
"Returns",
"the",
"effective",
"purpose",
"given",
"a",
"context",
"instance",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/api.php#L1054-L1060
|
218,843
|
moodle/moodle
|
admin/tool/dataprivacy/classes/api.php
|
api.get_effective_contextlevel_purpose
|
public static function get_effective_contextlevel_purpose($contextlevel, $forcedvalue=false) {
if (!data_registry::defaults_set()) {
return false;
}
return data_registry::get_effective_contextlevel_value($contextlevel, 'purpose', $forcedvalue);
}
|
php
|
public static function get_effective_contextlevel_purpose($contextlevel, $forcedvalue=false) {
if (!data_registry::defaults_set()) {
return false;
}
return data_registry::get_effective_contextlevel_value($contextlevel, 'purpose', $forcedvalue);
}
|
[
"public",
"static",
"function",
"get_effective_contextlevel_purpose",
"(",
"$",
"contextlevel",
",",
"$",
"forcedvalue",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"data_registry",
"::",
"defaults_set",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"data_registry",
"::",
"get_effective_contextlevel_value",
"(",
"$",
"contextlevel",
",",
"'purpose'",
",",
"$",
"forcedvalue",
")",
";",
"}"
] |
Returns the effective purpose given a context level.
@param int $contextlevel
@param int $forcedvalue Use this purposeid value as if this was this context level purpose.
@return purpose|false
|
[
"Returns",
"the",
"effective",
"purpose",
"given",
"a",
"context",
"level",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/api.php#L1083-L1089
|
218,844
|
moodle/moodle
|
admin/tool/dataprivacy/classes/api.php
|
api.create_expired_context
|
public static function create_expired_context($contextid) {
$record = (object)[
'contextid' => $contextid,
'status' => expired_context::STATUS_EXPIRED,
];
$expiredctx = new expired_context(0, $record);
$expiredctx->save();
return $expiredctx;
}
|
php
|
public static function create_expired_context($contextid) {
$record = (object)[
'contextid' => $contextid,
'status' => expired_context::STATUS_EXPIRED,
];
$expiredctx = new expired_context(0, $record);
$expiredctx->save();
return $expiredctx;
}
|
[
"public",
"static",
"function",
"create_expired_context",
"(",
"$",
"contextid",
")",
"{",
"$",
"record",
"=",
"(",
"object",
")",
"[",
"'contextid'",
"=>",
"$",
"contextid",
",",
"'status'",
"=>",
"expired_context",
"::",
"STATUS_EXPIRED",
",",
"]",
";",
"$",
"expiredctx",
"=",
"new",
"expired_context",
"(",
"0",
",",
"$",
"record",
")",
";",
"$",
"expiredctx",
"->",
"save",
"(",
")",
";",
"return",
"$",
"expiredctx",
";",
"}"
] |
Creates an expired context record for the provided context id.
@param int $contextid
@return \tool_dataprivacy\expired_context
|
[
"Creates",
"an",
"expired",
"context",
"record",
"for",
"the",
"provided",
"context",
"id",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/api.php#L1097-L1106
|
218,845
|
moodle/moodle
|
admin/tool/dataprivacy/classes/api.php
|
api.get_approved_contextlist_collection_for_collection
|
public static function get_approved_contextlist_collection_for_collection(contextlist_collection $collection,
\stdClass $foruser, int $type) : contextlist_collection {
// Create the approved contextlist collection object.
$approvedcollection = new contextlist_collection($collection->get_userid());
$isconfigured = data_registry::defaults_set();
foreach ($collection as $contextlist) {
$contextids = [];
foreach ($contextlist as $context) {
if ($isconfigured && self::DATAREQUEST_TYPE_DELETE == $type) {
// Data can only be deleted from it if the context is either expired, or unprotected.
// Note: We can only check whether a context is expired or unprotected if the site is configured and
// defaults are set appropriately. If they are not, we treat all contexts as though they are
// unprotected.
$purpose = static::get_effective_context_purpose($context);
if (!expired_contexts_manager::is_context_expired_or_unprotected_for_user($context, $foruser)) {
continue;
}
}
$contextids[] = $context->id;
}
// The data for the last component contextlist won't have been written yet, so write it now.
if (!empty($contextids)) {
$approvedcollection->add_contextlist(
new approved_contextlist($foruser, $contextlist->get_component(), $contextids)
);
}
}
return $approvedcollection;
}
|
php
|
public static function get_approved_contextlist_collection_for_collection(contextlist_collection $collection,
\stdClass $foruser, int $type) : contextlist_collection {
// Create the approved contextlist collection object.
$approvedcollection = new contextlist_collection($collection->get_userid());
$isconfigured = data_registry::defaults_set();
foreach ($collection as $contextlist) {
$contextids = [];
foreach ($contextlist as $context) {
if ($isconfigured && self::DATAREQUEST_TYPE_DELETE == $type) {
// Data can only be deleted from it if the context is either expired, or unprotected.
// Note: We can only check whether a context is expired or unprotected if the site is configured and
// defaults are set appropriately. If they are not, we treat all contexts as though they are
// unprotected.
$purpose = static::get_effective_context_purpose($context);
if (!expired_contexts_manager::is_context_expired_or_unprotected_for_user($context, $foruser)) {
continue;
}
}
$contextids[] = $context->id;
}
// The data for the last component contextlist won't have been written yet, so write it now.
if (!empty($contextids)) {
$approvedcollection->add_contextlist(
new approved_contextlist($foruser, $contextlist->get_component(), $contextids)
);
}
}
return $approvedcollection;
}
|
[
"public",
"static",
"function",
"get_approved_contextlist_collection_for_collection",
"(",
"contextlist_collection",
"$",
"collection",
",",
"\\",
"stdClass",
"$",
"foruser",
",",
"int",
"$",
"type",
")",
":",
"contextlist_collection",
"{",
"// Create the approved contextlist collection object.",
"$",
"approvedcollection",
"=",
"new",
"contextlist_collection",
"(",
"$",
"collection",
"->",
"get_userid",
"(",
")",
")",
";",
"$",
"isconfigured",
"=",
"data_registry",
"::",
"defaults_set",
"(",
")",
";",
"foreach",
"(",
"$",
"collection",
"as",
"$",
"contextlist",
")",
"{",
"$",
"contextids",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"contextlist",
"as",
"$",
"context",
")",
"{",
"if",
"(",
"$",
"isconfigured",
"&&",
"self",
"::",
"DATAREQUEST_TYPE_DELETE",
"==",
"$",
"type",
")",
"{",
"// Data can only be deleted from it if the context is either expired, or unprotected.",
"// Note: We can only check whether a context is expired or unprotected if the site is configured and",
"// defaults are set appropriately. If they are not, we treat all contexts as though they are",
"// unprotected.",
"$",
"purpose",
"=",
"static",
"::",
"get_effective_context_purpose",
"(",
"$",
"context",
")",
";",
"if",
"(",
"!",
"expired_contexts_manager",
"::",
"is_context_expired_or_unprotected_for_user",
"(",
"$",
"context",
",",
"$",
"foruser",
")",
")",
"{",
"continue",
";",
"}",
"}",
"$",
"contextids",
"[",
"]",
"=",
"$",
"context",
"->",
"id",
";",
"}",
"// The data for the last component contextlist won't have been written yet, so write it now.",
"if",
"(",
"!",
"empty",
"(",
"$",
"contextids",
")",
")",
"{",
"$",
"approvedcollection",
"->",
"add_contextlist",
"(",
"new",
"approved_contextlist",
"(",
"$",
"foruser",
",",
"$",
"contextlist",
"->",
"get_component",
"(",
")",
",",
"$",
"contextids",
")",
")",
";",
"}",
"}",
"return",
"$",
"approvedcollection",
";",
"}"
] |
Finds all contextlists having at least one approved context, and returns them as in a contextlist_collection.
@param contextlist_collection $collection The collection of unapproved contextlist objects.
@param \stdClass $foruser The target user
@param int $type The purpose of the collection
@return contextlist_collection The collection of approved_contextlist objects.
|
[
"Finds",
"all",
"contextlists",
"having",
"at",
"least",
"one",
"approved",
"context",
"and",
"returns",
"them",
"as",
"in",
"a",
"contextlist_collection",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/api.php#L1139-L1172
|
218,846
|
moodle/moodle
|
admin/tool/dataprivacy/classes/api.php
|
api.format_retention_period
|
public static function format_retention_period(\DateInterval $interval) : string {
// It is one or another.
if ($interval->y) {
$formattedtime = get_string('numyears', 'moodle', $interval->format('%y'));
} else if ($interval->m) {
$formattedtime = get_string('nummonths', 'moodle', $interval->format('%m'));
} else if ($interval->d) {
$formattedtime = get_string('numdays', 'moodle', $interval->format('%d'));
} else {
$formattedtime = get_string('retentionperiodzero', 'tool_dataprivacy');
}
return $formattedtime;
}
|
php
|
public static function format_retention_period(\DateInterval $interval) : string {
// It is one or another.
if ($interval->y) {
$formattedtime = get_string('numyears', 'moodle', $interval->format('%y'));
} else if ($interval->m) {
$formattedtime = get_string('nummonths', 'moodle', $interval->format('%m'));
} else if ($interval->d) {
$formattedtime = get_string('numdays', 'moodle', $interval->format('%d'));
} else {
$formattedtime = get_string('retentionperiodzero', 'tool_dataprivacy');
}
return $formattedtime;
}
|
[
"public",
"static",
"function",
"format_retention_period",
"(",
"\\",
"DateInterval",
"$",
"interval",
")",
":",
"string",
"{",
"// It is one or another.",
"if",
"(",
"$",
"interval",
"->",
"y",
")",
"{",
"$",
"formattedtime",
"=",
"get_string",
"(",
"'numyears'",
",",
"'moodle'",
",",
"$",
"interval",
"->",
"format",
"(",
"'%y'",
")",
")",
";",
"}",
"else",
"if",
"(",
"$",
"interval",
"->",
"m",
")",
"{",
"$",
"formattedtime",
"=",
"get_string",
"(",
"'nummonths'",
",",
"'moodle'",
",",
"$",
"interval",
"->",
"format",
"(",
"'%m'",
")",
")",
";",
"}",
"else",
"if",
"(",
"$",
"interval",
"->",
"d",
")",
"{",
"$",
"formattedtime",
"=",
"get_string",
"(",
"'numdays'",
",",
"'moodle'",
",",
"$",
"interval",
"->",
"format",
"(",
"'%d'",
")",
")",
";",
"}",
"else",
"{",
"$",
"formattedtime",
"=",
"get_string",
"(",
"'retentionperiodzero'",
",",
"'tool_dataprivacy'",
")",
";",
"}",
"return",
"$",
"formattedtime",
";",
"}"
] |
Format the supplied date interval as a retention period.
@param \DateInterval $interval
@return string
|
[
"Format",
"the",
"supplied",
"date",
"interval",
"as",
"a",
"retention",
"period",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/api.php#L1265-L1278
|
218,847
|
moodle/moodle
|
question/type/ddimageortext/questiontypebase.php
|
qtype_ddtoimage_base.write_files
|
public function write_files($files, $indent) {
if (empty($files)) {
return '';
}
$string = '';
foreach ($files as $file) {
if ($file->is_directory()) {
continue;
}
$string .= str_repeat(' ', $indent);
$string .= '<file name="' . $file->get_filename() . '" encoding="base64">';
$string .= base64_encode($file->get_content());
$string .= "</file>\n";
}
return $string;
}
|
php
|
public function write_files($files, $indent) {
if (empty($files)) {
return '';
}
$string = '';
foreach ($files as $file) {
if ($file->is_directory()) {
continue;
}
$string .= str_repeat(' ', $indent);
$string .= '<file name="' . $file->get_filename() . '" encoding="base64">';
$string .= base64_encode($file->get_content());
$string .= "</file>\n";
}
return $string;
}
|
[
"public",
"function",
"write_files",
"(",
"$",
"files",
",",
"$",
"indent",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"files",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"string",
"=",
"''",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"->",
"is_directory",
"(",
")",
")",
"{",
"continue",
";",
"}",
"$",
"string",
".=",
"str_repeat",
"(",
"' '",
",",
"$",
"indent",
")",
";",
"$",
"string",
".=",
"'<file name=\"'",
".",
"$",
"file",
"->",
"get_filename",
"(",
")",
".",
"'\" encoding=\"base64\">'",
";",
"$",
"string",
".=",
"base64_encode",
"(",
"$",
"file",
"->",
"get_content",
"(",
")",
")",
";",
"$",
"string",
".=",
"\"</file>\\n\"",
";",
"}",
"return",
"$",
"string",
";",
"}"
] |
Convert files into text output in the given format.
This method is copied from qformat_default as a quick fix, as the method there is
protected.
@param array $files
@param int $indent Number of spaces to indent
@return string $string
|
[
"Convert",
"files",
"into",
"text",
"output",
"in",
"the",
"given",
"format",
".",
"This",
"method",
"is",
"copied",
"from",
"qformat_default",
"as",
"a",
"quick",
"fix",
"as",
"the",
"method",
"there",
"is",
"protected",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/ddimageortext/questiontypebase.php#L157-L172
|
218,848
|
moodle/moodle
|
lib/form/recaptcha.php
|
MoodleQuickForm_recaptcha.verify
|
public function verify($responsestr) {
global $CFG;
require_once($CFG->libdir . '/recaptchalib_v2.php');
$response = recaptcha_check_response(RECAPTCHA_VERIFY_URL, $CFG->recaptchaprivatekey,
getremoteaddr(), $responsestr);
if (!$response['isvalid']) {
$attributes = $this->getAttributes();
$attributes['error_message'] = $response['error'];
$this->setAttributes($attributes);
return $response['error'];
}
return true;
}
|
php
|
public function verify($responsestr) {
global $CFG;
require_once($CFG->libdir . '/recaptchalib_v2.php');
$response = recaptcha_check_response(RECAPTCHA_VERIFY_URL, $CFG->recaptchaprivatekey,
getremoteaddr(), $responsestr);
if (!$response['isvalid']) {
$attributes = $this->getAttributes();
$attributes['error_message'] = $response['error'];
$this->setAttributes($attributes);
return $response['error'];
}
return true;
}
|
[
"public",
"function",
"verify",
"(",
"$",
"responsestr",
")",
"{",
"global",
"$",
"CFG",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"libdir",
".",
"'/recaptchalib_v2.php'",
")",
";",
"$",
"response",
"=",
"recaptcha_check_response",
"(",
"RECAPTCHA_VERIFY_URL",
",",
"$",
"CFG",
"->",
"recaptchaprivatekey",
",",
"getremoteaddr",
"(",
")",
",",
"$",
"responsestr",
")",
";",
"if",
"(",
"!",
"$",
"response",
"[",
"'isvalid'",
"]",
")",
"{",
"$",
"attributes",
"=",
"$",
"this",
"->",
"getAttributes",
"(",
")",
";",
"$",
"attributes",
"[",
"'error_message'",
"]",
"=",
"$",
"response",
"[",
"'error'",
"]",
";",
"$",
"this",
"->",
"setAttributes",
"(",
"$",
"attributes",
")",
";",
"return",
"$",
"response",
"[",
"'error'",
"]",
";",
"}",
"return",
"true",
";",
"}"
] |
Checks recaptcha response with Google.
@param string $responsestr
@return bool
|
[
"Checks",
"recaptcha",
"response",
"with",
"Google",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/recaptcha.php#L99-L112
|
218,849
|
moodle/moodle
|
lib/spout/src/Spout/Common/Escaper/XLSX.php
|
XLSX.init
|
protected function init()
{
$this->escapableControlCharactersPattern = $this->getEscapableControlCharactersPattern();
$this->controlCharactersEscapingMap = $this->getControlCharactersEscapingMap();
$this->controlCharactersEscapingReverseMap = array_flip($this->controlCharactersEscapingMap);
}
|
php
|
protected function init()
{
$this->escapableControlCharactersPattern = $this->getEscapableControlCharactersPattern();
$this->controlCharactersEscapingMap = $this->getControlCharactersEscapingMap();
$this->controlCharactersEscapingReverseMap = array_flip($this->controlCharactersEscapingMap);
}
|
[
"protected",
"function",
"init",
"(",
")",
"{",
"$",
"this",
"->",
"escapableControlCharactersPattern",
"=",
"$",
"this",
"->",
"getEscapableControlCharactersPattern",
"(",
")",
";",
"$",
"this",
"->",
"controlCharactersEscapingMap",
"=",
"$",
"this",
"->",
"getControlCharactersEscapingMap",
"(",
")",
";",
"$",
"this",
"->",
"controlCharactersEscapingReverseMap",
"=",
"array_flip",
"(",
"$",
"this",
"->",
"controlCharactersEscapingMap",
")",
";",
"}"
] |
Initializes the singleton instance
|
[
"Initializes",
"the",
"singleton",
"instance"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Common/Escaper/XLSX.php#L29-L34
|
218,850
|
moodle/moodle
|
lib/spout/src/Spout/Common/Escaper/XLSX.php
|
XLSX.getControlCharactersEscapingMap
|
protected function getControlCharactersEscapingMap()
{
$controlCharactersEscapingMap = [];
// control characters values are from 0 to 1F (hex values) in the ASCII table
for ($charValue = 0x00; $charValue <= 0x1F; $charValue++) {
$character = chr($charValue);
if (preg_match("/{$this->escapableControlCharactersPattern}/", $character)) {
$charHexValue = dechex($charValue);
$escapedChar = '_x' . sprintf('%04s' , strtoupper($charHexValue)) . '_';
$controlCharactersEscapingMap[$escapedChar] = $character;
}
}
return $controlCharactersEscapingMap;
}
|
php
|
protected function getControlCharactersEscapingMap()
{
$controlCharactersEscapingMap = [];
// control characters values are from 0 to 1F (hex values) in the ASCII table
for ($charValue = 0x00; $charValue <= 0x1F; $charValue++) {
$character = chr($charValue);
if (preg_match("/{$this->escapableControlCharactersPattern}/", $character)) {
$charHexValue = dechex($charValue);
$escapedChar = '_x' . sprintf('%04s' , strtoupper($charHexValue)) . '_';
$controlCharactersEscapingMap[$escapedChar] = $character;
}
}
return $controlCharactersEscapingMap;
}
|
[
"protected",
"function",
"getControlCharactersEscapingMap",
"(",
")",
"{",
"$",
"controlCharactersEscapingMap",
"=",
"[",
"]",
";",
"// control characters values are from 0 to 1F (hex values) in the ASCII table",
"for",
"(",
"$",
"charValue",
"=",
"0x00",
";",
"$",
"charValue",
"<=",
"0x1F",
";",
"$",
"charValue",
"++",
")",
"{",
"$",
"character",
"=",
"chr",
"(",
"$",
"charValue",
")",
";",
"if",
"(",
"preg_match",
"(",
"\"/{$this->escapableControlCharactersPattern}/\"",
",",
"$",
"character",
")",
")",
"{",
"$",
"charHexValue",
"=",
"dechex",
"(",
"$",
"charValue",
")",
";",
"$",
"escapedChar",
"=",
"'_x'",
".",
"sprintf",
"(",
"'%04s'",
",",
"strtoupper",
"(",
"$",
"charHexValue",
")",
")",
".",
"'_'",
";",
"$",
"controlCharactersEscapingMap",
"[",
"$",
"escapedChar",
"]",
"=",
"$",
"character",
";",
"}",
"}",
"return",
"$",
"controlCharactersEscapingMap",
";",
"}"
] |
Builds the map containing control characters to be escaped
mapped to their escaped values.
"\t", "\r" and "\n" don't need to be escaped.
NOTE: the logic has been adapted from the XlsxWriter library (BSD License)
@link https://github.com/jmcnamara/XlsxWriter/blob/f1e610f29/xlsxwriter/sharedstrings.py#L89
@return string[]
|
[
"Builds",
"the",
"map",
"containing",
"control",
"characters",
"to",
"be",
"escaped",
"mapped",
"to",
"their",
"escaped",
"values",
".",
"\\",
"t",
"\\",
"r",
"and",
"\\",
"n",
"don",
"t",
"need",
"to",
"be",
"escaped",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Common/Escaper/XLSX.php#L95-L110
|
218,851
|
moodle/moodle
|
lib/spout/src/Spout/Common/Escaper/XLSX.php
|
XLSX.escapeControlCharacters
|
protected function escapeControlCharacters($string)
{
$escapedString = $this->escapeEscapeCharacter($string);
// if no control characters
if (!preg_match("/{$this->escapableControlCharactersPattern}/", $escapedString)) {
return $escapedString;
}
return preg_replace_callback("/({$this->escapableControlCharactersPattern})/", function($matches) {
return $this->controlCharactersEscapingReverseMap[$matches[0]];
}, $escapedString);
}
|
php
|
protected function escapeControlCharacters($string)
{
$escapedString = $this->escapeEscapeCharacter($string);
// if no control characters
if (!preg_match("/{$this->escapableControlCharactersPattern}/", $escapedString)) {
return $escapedString;
}
return preg_replace_callback("/({$this->escapableControlCharactersPattern})/", function($matches) {
return $this->controlCharactersEscapingReverseMap[$matches[0]];
}, $escapedString);
}
|
[
"protected",
"function",
"escapeControlCharacters",
"(",
"$",
"string",
")",
"{",
"$",
"escapedString",
"=",
"$",
"this",
"->",
"escapeEscapeCharacter",
"(",
"$",
"string",
")",
";",
"// if no control characters",
"if",
"(",
"!",
"preg_match",
"(",
"\"/{$this->escapableControlCharactersPattern}/\"",
",",
"$",
"escapedString",
")",
")",
"{",
"return",
"$",
"escapedString",
";",
"}",
"return",
"preg_replace_callback",
"(",
"\"/({$this->escapableControlCharactersPattern})/\"",
",",
"function",
"(",
"$",
"matches",
")",
"{",
"return",
"$",
"this",
"->",
"controlCharactersEscapingReverseMap",
"[",
"$",
"matches",
"[",
"0",
"]",
"]",
";",
"}",
",",
"$",
"escapedString",
")",
";",
"}"
] |
Converts PHP control characters from the given string to OpenXML escaped control characters
Excel escapes control characters with _xHHHH_ and also escapes any
literal strings of that type by encoding the leading underscore.
So "\0" -> _x0000_ and "_x0000_" -> _x005F_x0000_.
NOTE: the logic has been adapted from the XlsxWriter library (BSD License)
@link https://github.com/jmcnamara/XlsxWriter/blob/f1e610f29/xlsxwriter/sharedstrings.py#L89
@param string $string String to escape
@return string
|
[
"Converts",
"PHP",
"control",
"characters",
"from",
"the",
"given",
"string",
"to",
"OpenXML",
"escaped",
"control",
"characters"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Common/Escaper/XLSX.php#L125-L137
|
218,852
|
moodle/moodle
|
lib/spout/src/Spout/Common/Escaper/XLSX.php
|
XLSX.unescapeControlCharacters
|
protected function unescapeControlCharacters($string)
{
$unescapedString = $string;
foreach ($this->controlCharactersEscapingMap as $escapedCharValue => $charValue) {
// only unescape characters that don't contain the escaped escape character for now
$unescapedString = preg_replace("/(?<!_x005F)($escapedCharValue)/", $charValue, $unescapedString);
}
return $this->unescapeEscapeCharacter($unescapedString);
}
|
php
|
protected function unescapeControlCharacters($string)
{
$unescapedString = $string;
foreach ($this->controlCharactersEscapingMap as $escapedCharValue => $charValue) {
// only unescape characters that don't contain the escaped escape character for now
$unescapedString = preg_replace("/(?<!_x005F)($escapedCharValue)/", $charValue, $unescapedString);
}
return $this->unescapeEscapeCharacter($unescapedString);
}
|
[
"protected",
"function",
"unescapeControlCharacters",
"(",
"$",
"string",
")",
"{",
"$",
"unescapedString",
"=",
"$",
"string",
";",
"foreach",
"(",
"$",
"this",
"->",
"controlCharactersEscapingMap",
"as",
"$",
"escapedCharValue",
"=>",
"$",
"charValue",
")",
"{",
"// only unescape characters that don't contain the escaped escape character for now",
"$",
"unescapedString",
"=",
"preg_replace",
"(",
"\"/(?<!_x005F)($escapedCharValue)/\"",
",",
"$",
"charValue",
",",
"$",
"unescapedString",
")",
";",
"}",
"return",
"$",
"this",
"->",
"unescapeEscapeCharacter",
"(",
"$",
"unescapedString",
")",
";",
"}"
] |
Converts OpenXML escaped control characters from the given string to PHP control characters
Excel escapes control characters with _xHHHH_ and also escapes any
literal strings of that type by encoding the leading underscore.
So "_x0000_" -> "\0" and "_x005F_x0000_" -> "_x0000_"
NOTE: the logic has been adapted from the XlsxWriter library (BSD License)
@link https://github.com/jmcnamara/XlsxWriter/blob/f1e610f29/xlsxwriter/sharedstrings.py#L89
@param string $string String to unescape
@return string
|
[
"Converts",
"OpenXML",
"escaped",
"control",
"characters",
"from",
"the",
"given",
"string",
"to",
"PHP",
"control",
"characters"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Common/Escaper/XLSX.php#L163-L173
|
218,853
|
moodle/moodle
|
lib/classes/message/inbound/manager.php
|
manager.is_enabled
|
public static function is_enabled() {
global $CFG;
// Check whether Inbound Message is enabled at all.
if (!isset($CFG->messageinbound_enabled) || !$CFG->messageinbound_enabled) {
return false;
}
// Check whether the outgoing mailbox and domain are configured properly.
if (!isset($CFG->messageinbound_mailbox) || empty($CFG->messageinbound_mailbox)) {
return false;
}
if (!isset($CFG->messageinbound_domain) || empty($CFG->messageinbound_domain)) {
return false;
}
return true;
}
|
php
|
public static function is_enabled() {
global $CFG;
// Check whether Inbound Message is enabled at all.
if (!isset($CFG->messageinbound_enabled) || !$CFG->messageinbound_enabled) {
return false;
}
// Check whether the outgoing mailbox and domain are configured properly.
if (!isset($CFG->messageinbound_mailbox) || empty($CFG->messageinbound_mailbox)) {
return false;
}
if (!isset($CFG->messageinbound_domain) || empty($CFG->messageinbound_domain)) {
return false;
}
return true;
}
|
[
"public",
"static",
"function",
"is_enabled",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"// Check whether Inbound Message is enabled at all.",
"if",
"(",
"!",
"isset",
"(",
"$",
"CFG",
"->",
"messageinbound_enabled",
")",
"||",
"!",
"$",
"CFG",
"->",
"messageinbound_enabled",
")",
"{",
"return",
"false",
";",
"}",
"// Check whether the outgoing mailbox and domain are configured properly.",
"if",
"(",
"!",
"isset",
"(",
"$",
"CFG",
"->",
"messageinbound_mailbox",
")",
"||",
"empty",
"(",
"$",
"CFG",
"->",
"messageinbound_mailbox",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"CFG",
"->",
"messageinbound_domain",
")",
"||",
"empty",
"(",
"$",
"CFG",
"->",
"messageinbound_domain",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Whether the Inbound Message interface is enabled.
@return bool
|
[
"Whether",
"the",
"Inbound",
"Message",
"interface",
"is",
"enabled",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/message/inbound/manager.php#L42-L60
|
218,854
|
moodle/moodle
|
lib/classes/message/inbound/manager.php
|
manager.update_handlers_for_component
|
public static function update_handlers_for_component($componentname) {
global $DB;
$componentname = \core_component::normalize_componentname($componentname);
$existinghandlers = $DB->get_recordset('messageinbound_handlers', array('component' => $componentname));
foreach ($existinghandlers as $handler) {
if (!class_exists($handler->classname)) {
self::remove_messageinbound_handler($handler);
}
}
$existinghandlers->close();
self::create_missing_messageinbound_handlers_for_component($componentname);
}
|
php
|
public static function update_handlers_for_component($componentname) {
global $DB;
$componentname = \core_component::normalize_componentname($componentname);
$existinghandlers = $DB->get_recordset('messageinbound_handlers', array('component' => $componentname));
foreach ($existinghandlers as $handler) {
if (!class_exists($handler->classname)) {
self::remove_messageinbound_handler($handler);
}
}
$existinghandlers->close();
self::create_missing_messageinbound_handlers_for_component($componentname);
}
|
[
"public",
"static",
"function",
"update_handlers_for_component",
"(",
"$",
"componentname",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"componentname",
"=",
"\\",
"core_component",
"::",
"normalize_componentname",
"(",
"$",
"componentname",
")",
";",
"$",
"existinghandlers",
"=",
"$",
"DB",
"->",
"get_recordset",
"(",
"'messageinbound_handlers'",
",",
"array",
"(",
"'component'",
"=>",
"$",
"componentname",
")",
")",
";",
"foreach",
"(",
"$",
"existinghandlers",
"as",
"$",
"handler",
")",
"{",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"handler",
"->",
"classname",
")",
")",
"{",
"self",
"::",
"remove_messageinbound_handler",
"(",
"$",
"handler",
")",
";",
"}",
"}",
"$",
"existinghandlers",
"->",
"close",
"(",
")",
";",
"self",
"::",
"create_missing_messageinbound_handlers_for_component",
"(",
"$",
"componentname",
")",
";",
"}"
] |
Update the database to create, update, and remove handlers.
@param string $componentname - The frankenstyle component name.
|
[
"Update",
"the",
"database",
"to",
"create",
"update",
"and",
"remove",
"handlers",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/message/inbound/manager.php#L67-L80
|
218,855
|
moodle/moodle
|
lib/classes/message/inbound/manager.php
|
manager.create_missing_messageinbound_handlers_for_component
|
public static function create_missing_messageinbound_handlers_for_component($componentname) {
global $DB;
$componentname = \core_component::normalize_componentname($componentname);
$expectedhandlers = self::load_default_handlers_for_component($componentname);
foreach ($expectedhandlers as $handler) {
$recordexists = $DB->record_exists('messageinbound_handlers', array(
'component' => $componentname,
'classname' => $handler->classname,
));
if (!$recordexists) {
$record = self::record_from_handler($handler);
$record->component = $componentname;
$DB->insert_record('messageinbound_handlers', $record);
}
}
}
|
php
|
public static function create_missing_messageinbound_handlers_for_component($componentname) {
global $DB;
$componentname = \core_component::normalize_componentname($componentname);
$expectedhandlers = self::load_default_handlers_for_component($componentname);
foreach ($expectedhandlers as $handler) {
$recordexists = $DB->record_exists('messageinbound_handlers', array(
'component' => $componentname,
'classname' => $handler->classname,
));
if (!$recordexists) {
$record = self::record_from_handler($handler);
$record->component = $componentname;
$DB->insert_record('messageinbound_handlers', $record);
}
}
}
|
[
"public",
"static",
"function",
"create_missing_messageinbound_handlers_for_component",
"(",
"$",
"componentname",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"componentname",
"=",
"\\",
"core_component",
"::",
"normalize_componentname",
"(",
"$",
"componentname",
")",
";",
"$",
"expectedhandlers",
"=",
"self",
"::",
"load_default_handlers_for_component",
"(",
"$",
"componentname",
")",
";",
"foreach",
"(",
"$",
"expectedhandlers",
"as",
"$",
"handler",
")",
"{",
"$",
"recordexists",
"=",
"$",
"DB",
"->",
"record_exists",
"(",
"'messageinbound_handlers'",
",",
"array",
"(",
"'component'",
"=>",
"$",
"componentname",
",",
"'classname'",
"=>",
"$",
"handler",
"->",
"classname",
",",
")",
")",
";",
"if",
"(",
"!",
"$",
"recordexists",
")",
"{",
"$",
"record",
"=",
"self",
"::",
"record_from_handler",
"(",
"$",
"handler",
")",
";",
"$",
"record",
"->",
"component",
"=",
"$",
"componentname",
";",
"$",
"DB",
"->",
"insert_record",
"(",
"'messageinbound_handlers'",
",",
"$",
"record",
")",
";",
"}",
"}",
"}"
] |
Update the database to contain a list of handlers for a component,
adding any handlers which do not exist in the database.
@param string $componentname - The frankenstyle component name.
|
[
"Update",
"the",
"database",
"to",
"contain",
"a",
"list",
"of",
"handlers",
"for",
"a",
"component",
"adding",
"any",
"handlers",
"which",
"do",
"not",
"exist",
"in",
"the",
"database",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/message/inbound/manager.php#L129-L146
|
218,856
|
moodle/moodle
|
lib/classes/message/inbound/manager.php
|
manager.remove_messageinbound_handler
|
public static function remove_messageinbound_handler($handler) {
global $DB;
// Delete Inbound Message datakeys.
$DB->delete_records('messageinbound_datakeys', array('handler' => $handler->id));
// Delete Inbound Message handlers.
$DB->delete_records('messageinbound_handlers', array('id' => $handler->id));
}
|
php
|
public static function remove_messageinbound_handler($handler) {
global $DB;
// Delete Inbound Message datakeys.
$DB->delete_records('messageinbound_datakeys', array('handler' => $handler->id));
// Delete Inbound Message handlers.
$DB->delete_records('messageinbound_handlers', array('id' => $handler->id));
}
|
[
"public",
"static",
"function",
"remove_messageinbound_handler",
"(",
"$",
"handler",
")",
"{",
"global",
"$",
"DB",
";",
"// Delete Inbound Message datakeys.",
"$",
"DB",
"->",
"delete_records",
"(",
"'messageinbound_datakeys'",
",",
"array",
"(",
"'handler'",
"=>",
"$",
"handler",
"->",
"id",
")",
")",
";",
"// Delete Inbound Message handlers.",
"$",
"DB",
"->",
"delete_records",
"(",
"'messageinbound_handlers'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"handler",
"->",
"id",
")",
")",
";",
"}"
] |
Remove the specified handler.
@param \core\message\inbound\handler $handler The handler to remove
|
[
"Remove",
"the",
"specified",
"handler",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/message/inbound/manager.php#L153-L161
|
218,857
|
moodle/moodle
|
lib/classes/message/inbound/manager.php
|
manager.record_from_handler
|
public static function record_from_handler($handler) {
$record = new \stdClass();
$record->id = $handler->id;
$record->component = $handler->component;
$record->classname = get_class($handler);
if (strpos($record->classname, '\\') !== 0) {
$record->classname = '\\' . $record->classname;
}
$record->defaultexpiration = $handler->defaultexpiration;
$record->validateaddress = $handler->validateaddress;
$record->enabled = $handler->enabled;
return $record;
}
|
php
|
public static function record_from_handler($handler) {
$record = new \stdClass();
$record->id = $handler->id;
$record->component = $handler->component;
$record->classname = get_class($handler);
if (strpos($record->classname, '\\') !== 0) {
$record->classname = '\\' . $record->classname;
}
$record->defaultexpiration = $handler->defaultexpiration;
$record->validateaddress = $handler->validateaddress;
$record->enabled = $handler->enabled;
return $record;
}
|
[
"public",
"static",
"function",
"record_from_handler",
"(",
"$",
"handler",
")",
"{",
"$",
"record",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"record",
"->",
"id",
"=",
"$",
"handler",
"->",
"id",
";",
"$",
"record",
"->",
"component",
"=",
"$",
"handler",
"->",
"component",
";",
"$",
"record",
"->",
"classname",
"=",
"get_class",
"(",
"$",
"handler",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"record",
"->",
"classname",
",",
"'\\\\'",
")",
"!==",
"0",
")",
"{",
"$",
"record",
"->",
"classname",
"=",
"'\\\\'",
".",
"$",
"record",
"->",
"classname",
";",
"}",
"$",
"record",
"->",
"defaultexpiration",
"=",
"$",
"handler",
"->",
"defaultexpiration",
";",
"$",
"record",
"->",
"validateaddress",
"=",
"$",
"handler",
"->",
"validateaddress",
";",
"$",
"record",
"->",
"enabled",
"=",
"$",
"handler",
"->",
"enabled",
";",
"return",
"$",
"record",
";",
"}"
] |
Create a flat stdClass for the handler, appropriate for inserting
into the database.
@param \core\message\inbound\handler $handler The handler to retrieve the record for.
@return \stdClass
|
[
"Create",
"a",
"flat",
"stdClass",
"for",
"the",
"handler",
"appropriate",
"for",
"inserting",
"into",
"the",
"database",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/message/inbound/manager.php#L170-L183
|
218,858
|
moodle/moodle
|
lib/classes/message/inbound/manager.php
|
manager.handler_from_record
|
protected static function handler_from_record($record) {
$classname = $record->classname;
if (strpos($classname, '\\') !== 0) {
$classname = '\\' . $classname;
}
if (!class_exists($classname)) {
return false;
}
$handler = new $classname;
if (isset($record->id)) {
$handler->set_id($record->id);
}
$handler->set_component($record->component);
// Overload fields which can be modified.
if (isset($record->defaultexpiration)) {
$handler->set_defaultexpiration($record->defaultexpiration);
}
if (isset($record->validateaddress)) {
$handler->set_validateaddress($record->validateaddress);
}
if (isset($record->enabled)) {
$handler->set_enabled($record->enabled);
}
return $handler;
}
|
php
|
protected static function handler_from_record($record) {
$classname = $record->classname;
if (strpos($classname, '\\') !== 0) {
$classname = '\\' . $classname;
}
if (!class_exists($classname)) {
return false;
}
$handler = new $classname;
if (isset($record->id)) {
$handler->set_id($record->id);
}
$handler->set_component($record->component);
// Overload fields which can be modified.
if (isset($record->defaultexpiration)) {
$handler->set_defaultexpiration($record->defaultexpiration);
}
if (isset($record->validateaddress)) {
$handler->set_validateaddress($record->validateaddress);
}
if (isset($record->enabled)) {
$handler->set_enabled($record->enabled);
}
return $handler;
}
|
[
"protected",
"static",
"function",
"handler_from_record",
"(",
"$",
"record",
")",
"{",
"$",
"classname",
"=",
"$",
"record",
"->",
"classname",
";",
"if",
"(",
"strpos",
"(",
"$",
"classname",
",",
"'\\\\'",
")",
"!==",
"0",
")",
"{",
"$",
"classname",
"=",
"'\\\\'",
".",
"$",
"classname",
";",
"}",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"classname",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"handler",
"=",
"new",
"$",
"classname",
";",
"if",
"(",
"isset",
"(",
"$",
"record",
"->",
"id",
")",
")",
"{",
"$",
"handler",
"->",
"set_id",
"(",
"$",
"record",
"->",
"id",
")",
";",
"}",
"$",
"handler",
"->",
"set_component",
"(",
"$",
"record",
"->",
"component",
")",
";",
"// Overload fields which can be modified.",
"if",
"(",
"isset",
"(",
"$",
"record",
"->",
"defaultexpiration",
")",
")",
"{",
"$",
"handler",
"->",
"set_defaultexpiration",
"(",
"$",
"record",
"->",
"defaultexpiration",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"record",
"->",
"validateaddress",
")",
")",
"{",
"$",
"handler",
"->",
"set_validateaddress",
"(",
"$",
"record",
"->",
"validateaddress",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"record",
"->",
"enabled",
")",
")",
"{",
"$",
"handler",
"->",
"set_enabled",
"(",
"$",
"record",
"->",
"enabled",
")",
";",
"}",
"return",
"$",
"handler",
";",
"}"
] |
Load the Inbound Message handler details for a given record.
@param \stdClass $record The record to retrieve the handler for.
@return \core\message\inbound\handler or false
|
[
"Load",
"the",
"Inbound",
"Message",
"handler",
"details",
"for",
"a",
"given",
"record",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/message/inbound/manager.php#L191-L220
|
218,859
|
moodle/moodle
|
lib/classes/message/inbound/manager.php
|
manager.get_handler
|
public static function get_handler($classname) {
global $DB;
if (strpos($classname, '\\') !== 0) {
$classname = '\\' . $classname;
}
$record = $DB->get_record('messageinbound_handlers', array('classname' => $classname), '*', IGNORE_MISSING);
if (!$record) {
return false;
}
return self::handler_from_record($record);
}
|
php
|
public static function get_handler($classname) {
global $DB;
if (strpos($classname, '\\') !== 0) {
$classname = '\\' . $classname;
}
$record = $DB->get_record('messageinbound_handlers', array('classname' => $classname), '*', IGNORE_MISSING);
if (!$record) {
return false;
}
return self::handler_from_record($record);
}
|
[
"public",
"static",
"function",
"get_handler",
"(",
"$",
"classname",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"strpos",
"(",
"$",
"classname",
",",
"'\\\\'",
")",
"!==",
"0",
")",
"{",
"$",
"classname",
"=",
"'\\\\'",
".",
"$",
"classname",
";",
"}",
"$",
"record",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'messageinbound_handlers'",
",",
"array",
"(",
"'classname'",
"=>",
"$",
"classname",
")",
",",
"'*'",
",",
"IGNORE_MISSING",
")",
";",
"if",
"(",
"!",
"$",
"record",
")",
"{",
"return",
"false",
";",
"}",
"return",
"self",
"::",
"handler_from_record",
"(",
"$",
"record",
")",
";",
"}"
] |
Load the Inbound Message handler details for a given classname.
@param string $classname The name of the class for the handler.
@return \core\message\inbound\handler or false
|
[
"Load",
"the",
"Inbound",
"Message",
"handler",
"details",
"for",
"a",
"given",
"classname",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/message/inbound/manager.php#L228-L240
|
218,860
|
moodle/moodle
|
lib/classes/message/inbound/manager.php
|
manager.get_handler_from_id
|
public static function get_handler_from_id($id) {
global $DB;
$record = $DB->get_record('messageinbound_handlers', array('id' => $id), '*', IGNORE_MISSING);
if (!$record) {
return false;
}
return self::handler_from_record($record);
}
|
php
|
public static function get_handler_from_id($id) {
global $DB;
$record = $DB->get_record('messageinbound_handlers', array('id' => $id), '*', IGNORE_MISSING);
if (!$record) {
return false;
}
return self::handler_from_record($record);
}
|
[
"public",
"static",
"function",
"get_handler_from_id",
"(",
"$",
"id",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"record",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'messageinbound_handlers'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"id",
")",
",",
"'*'",
",",
"IGNORE_MISSING",
")",
";",
"if",
"(",
"!",
"$",
"record",
")",
"{",
"return",
"false",
";",
"}",
"return",
"self",
"::",
"handler_from_record",
"(",
"$",
"record",
")",
";",
"}"
] |
Load the Inbound Message handler with a given ID
@param int $id
@return \core\message\inbound\handler or false
|
[
"Load",
"the",
"Inbound",
"Message",
"handler",
"with",
"a",
"given",
"ID"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/message/inbound/manager.php#L248-L256
|
218,861
|
moodle/moodle
|
question/type/shortanswer/backup/moodle1/lib.php
|
moodle1_qtype_shortanswer_handler.process_question
|
public function process_question(array $data, array $raw) {
// Convert and write the answers first.
if (isset($data['answers'])) {
$this->write_answers($data['answers'], $this->pluginname);
}
// Convert and write the shortanswer extra fields.
foreach ($data['shortanswer'] as $shortanswer) {
$shortanswer['id'] = $this->converter->get_nextid();
$this->write_xml('shortanswer', $shortanswer, array('/shortanswer/id'));
}
}
|
php
|
public function process_question(array $data, array $raw) {
// Convert and write the answers first.
if (isset($data['answers'])) {
$this->write_answers($data['answers'], $this->pluginname);
}
// Convert and write the shortanswer extra fields.
foreach ($data['shortanswer'] as $shortanswer) {
$shortanswer['id'] = $this->converter->get_nextid();
$this->write_xml('shortanswer', $shortanswer, array('/shortanswer/id'));
}
}
|
[
"public",
"function",
"process_question",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"raw",
")",
"{",
"// Convert and write the answers first.",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'answers'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"write_answers",
"(",
"$",
"data",
"[",
"'answers'",
"]",
",",
"$",
"this",
"->",
"pluginname",
")",
";",
"}",
"// Convert and write the shortanswer extra fields.",
"foreach",
"(",
"$",
"data",
"[",
"'shortanswer'",
"]",
"as",
"$",
"shortanswer",
")",
"{",
"$",
"shortanswer",
"[",
"'id'",
"]",
"=",
"$",
"this",
"->",
"converter",
"->",
"get_nextid",
"(",
")",
";",
"$",
"this",
"->",
"write_xml",
"(",
"'shortanswer'",
",",
"$",
"shortanswer",
",",
"array",
"(",
"'/shortanswer/id'",
")",
")",
";",
"}",
"}"
] |
Appends the shortanswer specific information to the question
|
[
"Appends",
"the",
"shortanswer",
"specific",
"information",
"to",
"the",
"question"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/shortanswer/backup/moodle1/lib.php#L44-L56
|
218,862
|
moodle/moodle
|
backup/util/ui/backup_ui_stage.class.php
|
backup_ui_stage_initial.get_next_stage
|
public function get_next_stage() {
if ($this->oneclickbackup) {
// Its a one click backup.
// The default filename is backup.mbz, this normally gets set to something useful in the confirmation stage.
// because we skipped that stage we must manually set this to a useful value.
$tasks = $this->ui->get_tasks();
foreach ($tasks as $task) {
if ($task instanceof backup_root_task) {
// Find the filename setting.
$setting = $task->get_setting('filename');
if ($setting) {
// Use the helper objects to get a useful name.
$filename = backup_plan_dbops::get_default_backup_filename(
$this->ui->get_format(),
$this->ui->get_type(),
$this->ui->get_controller_id(),
$this->ui->get_setting_value('users'),
$this->ui->get_setting_value('anonymize')
);
$setting->set_value($filename);
}
}
}
return backup_ui::STAGE_FINAL;
}
return parent::get_next_stage();
}
|
php
|
public function get_next_stage() {
if ($this->oneclickbackup) {
// Its a one click backup.
// The default filename is backup.mbz, this normally gets set to something useful in the confirmation stage.
// because we skipped that stage we must manually set this to a useful value.
$tasks = $this->ui->get_tasks();
foreach ($tasks as $task) {
if ($task instanceof backup_root_task) {
// Find the filename setting.
$setting = $task->get_setting('filename');
if ($setting) {
// Use the helper objects to get a useful name.
$filename = backup_plan_dbops::get_default_backup_filename(
$this->ui->get_format(),
$this->ui->get_type(),
$this->ui->get_controller_id(),
$this->ui->get_setting_value('users'),
$this->ui->get_setting_value('anonymize')
);
$setting->set_value($filename);
}
}
}
return backup_ui::STAGE_FINAL;
}
return parent::get_next_stage();
}
|
[
"public",
"function",
"get_next_stage",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"oneclickbackup",
")",
"{",
"// Its a one click backup.",
"// The default filename is backup.mbz, this normally gets set to something useful in the confirmation stage.",
"// because we skipped that stage we must manually set this to a useful value.",
"$",
"tasks",
"=",
"$",
"this",
"->",
"ui",
"->",
"get_tasks",
"(",
")",
";",
"foreach",
"(",
"$",
"tasks",
"as",
"$",
"task",
")",
"{",
"if",
"(",
"$",
"task",
"instanceof",
"backup_root_task",
")",
"{",
"// Find the filename setting.",
"$",
"setting",
"=",
"$",
"task",
"->",
"get_setting",
"(",
"'filename'",
")",
";",
"if",
"(",
"$",
"setting",
")",
"{",
"// Use the helper objects to get a useful name.",
"$",
"filename",
"=",
"backup_plan_dbops",
"::",
"get_default_backup_filename",
"(",
"$",
"this",
"->",
"ui",
"->",
"get_format",
"(",
")",
",",
"$",
"this",
"->",
"ui",
"->",
"get_type",
"(",
")",
",",
"$",
"this",
"->",
"ui",
"->",
"get_controller_id",
"(",
")",
",",
"$",
"this",
"->",
"ui",
"->",
"get_setting_value",
"(",
"'users'",
")",
",",
"$",
"this",
"->",
"ui",
"->",
"get_setting_value",
"(",
"'anonymize'",
")",
")",
";",
"$",
"setting",
"->",
"set_value",
"(",
"$",
"filename",
")",
";",
"}",
"}",
"}",
"return",
"backup_ui",
"::",
"STAGE_FINAL",
";",
"}",
"return",
"parent",
"::",
"get_next_stage",
"(",
")",
";",
"}"
] |
Gets the next stage for the backup.
We override this function to implement the one click backup.
When the user performs a one click backup we jump straight to the final stage.
@return int
|
[
"Gets",
"the",
"next",
"stage",
"for",
"the",
"backup",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/backup_ui_stage.class.php#L141-L167
|
218,863
|
moodle/moodle
|
backup/util/ui/backup_ui_stage.class.php
|
backup_ui_stage_initial.initialise_stage_form
|
protected function initialise_stage_form() {
global $PAGE;
if ($this->stageform === null) {
$form = new backup_initial_form($this, $PAGE->url);
// Store as a variable so we can iterate by reference.
$tasks = $this->ui->get_tasks();
// Iterate all tasks by reference.
$add_settings = array();
$dependencies = array();
foreach ($tasks as &$task) {
// For the initial stage we are only interested in the root settings.
if ($task instanceof backup_root_task) {
if ($this->ui instanceof import_ui) {
$form->add_heading('rootsettings', get_string('importrootsettings', 'backup'));
} else {
$form->add_heading('rootsettings', get_string('rootsettings', 'backup'));
}
$settings = $task->get_settings();
// First add all settings except the filename setting.
foreach ($settings as &$setting) {
if ($setting->get_name() == 'filename') {
continue;
}
$add_settings[] = array($setting, $task);
}
// Then add all dependencies.
foreach ($settings as &$setting) {
if ($setting->get_name() == 'filename') {
continue;
}
$dependencies[] = $setting;
}
}
}
// Add all settings at once.
$form->add_settings($add_settings);
// Add dependencies.
foreach ($dependencies as $depsetting) {
$form->add_dependencies($depsetting);
}
$this->stageform = $form;
}
// Return the form.
return $this->stageform;
}
|
php
|
protected function initialise_stage_form() {
global $PAGE;
if ($this->stageform === null) {
$form = new backup_initial_form($this, $PAGE->url);
// Store as a variable so we can iterate by reference.
$tasks = $this->ui->get_tasks();
// Iterate all tasks by reference.
$add_settings = array();
$dependencies = array();
foreach ($tasks as &$task) {
// For the initial stage we are only interested in the root settings.
if ($task instanceof backup_root_task) {
if ($this->ui instanceof import_ui) {
$form->add_heading('rootsettings', get_string('importrootsettings', 'backup'));
} else {
$form->add_heading('rootsettings', get_string('rootsettings', 'backup'));
}
$settings = $task->get_settings();
// First add all settings except the filename setting.
foreach ($settings as &$setting) {
if ($setting->get_name() == 'filename') {
continue;
}
$add_settings[] = array($setting, $task);
}
// Then add all dependencies.
foreach ($settings as &$setting) {
if ($setting->get_name() == 'filename') {
continue;
}
$dependencies[] = $setting;
}
}
}
// Add all settings at once.
$form->add_settings($add_settings);
// Add dependencies.
foreach ($dependencies as $depsetting) {
$form->add_dependencies($depsetting);
}
$this->stageform = $form;
}
// Return the form.
return $this->stageform;
}
|
[
"protected",
"function",
"initialise_stage_form",
"(",
")",
"{",
"global",
"$",
"PAGE",
";",
"if",
"(",
"$",
"this",
"->",
"stageform",
"===",
"null",
")",
"{",
"$",
"form",
"=",
"new",
"backup_initial_form",
"(",
"$",
"this",
",",
"$",
"PAGE",
"->",
"url",
")",
";",
"// Store as a variable so we can iterate by reference.",
"$",
"tasks",
"=",
"$",
"this",
"->",
"ui",
"->",
"get_tasks",
"(",
")",
";",
"// Iterate all tasks by reference.",
"$",
"add_settings",
"=",
"array",
"(",
")",
";",
"$",
"dependencies",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"tasks",
"as",
"&",
"$",
"task",
")",
"{",
"// For the initial stage we are only interested in the root settings.",
"if",
"(",
"$",
"task",
"instanceof",
"backup_root_task",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"ui",
"instanceof",
"import_ui",
")",
"{",
"$",
"form",
"->",
"add_heading",
"(",
"'rootsettings'",
",",
"get_string",
"(",
"'importrootsettings'",
",",
"'backup'",
")",
")",
";",
"}",
"else",
"{",
"$",
"form",
"->",
"add_heading",
"(",
"'rootsettings'",
",",
"get_string",
"(",
"'rootsettings'",
",",
"'backup'",
")",
")",
";",
"}",
"$",
"settings",
"=",
"$",
"task",
"->",
"get_settings",
"(",
")",
";",
"// First add all settings except the filename setting.",
"foreach",
"(",
"$",
"settings",
"as",
"&",
"$",
"setting",
")",
"{",
"if",
"(",
"$",
"setting",
"->",
"get_name",
"(",
")",
"==",
"'filename'",
")",
"{",
"continue",
";",
"}",
"$",
"add_settings",
"[",
"]",
"=",
"array",
"(",
"$",
"setting",
",",
"$",
"task",
")",
";",
"}",
"// Then add all dependencies.",
"foreach",
"(",
"$",
"settings",
"as",
"&",
"$",
"setting",
")",
"{",
"if",
"(",
"$",
"setting",
"->",
"get_name",
"(",
")",
"==",
"'filename'",
")",
"{",
"continue",
";",
"}",
"$",
"dependencies",
"[",
"]",
"=",
"$",
"setting",
";",
"}",
"}",
"}",
"// Add all settings at once.",
"$",
"form",
"->",
"add_settings",
"(",
"$",
"add_settings",
")",
";",
"// Add dependencies.",
"foreach",
"(",
"$",
"dependencies",
"as",
"$",
"depsetting",
")",
"{",
"$",
"form",
"->",
"add_dependencies",
"(",
"$",
"depsetting",
")",
";",
"}",
"$",
"this",
"->",
"stageform",
"=",
"$",
"form",
";",
"}",
"// Return the form.",
"return",
"$",
"this",
"->",
"stageform",
";",
"}"
] |
Initialises the backup_moodleform instance for this stage
@return backup_initial_form
|
[
"Initialises",
"the",
"backup_moodleform",
"instance",
"for",
"this",
"stage"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/backup_ui_stage.class.php#L174-L218
|
218,864
|
moodle/moodle
|
analytics/classes/privacy/provider.php
|
provider.get_models_with_user_data
|
private static function get_models_with_user_data() {
$models = \core_analytics\manager::get_all_models();
foreach ($models as $modelid => $model) {
$analyser = $model->get_analyser(['notimesplitting' => true]);
if (!$analyser->processes_user_data()) {
unset($models[$modelid]);
}
}
return $models;
}
|
php
|
private static function get_models_with_user_data() {
$models = \core_analytics\manager::get_all_models();
foreach ($models as $modelid => $model) {
$analyser = $model->get_analyser(['notimesplitting' => true]);
if (!$analyser->processes_user_data()) {
unset($models[$modelid]);
}
}
return $models;
}
|
[
"private",
"static",
"function",
"get_models_with_user_data",
"(",
")",
"{",
"$",
"models",
"=",
"\\",
"core_analytics",
"\\",
"manager",
"::",
"get_all_models",
"(",
")",
";",
"foreach",
"(",
"$",
"models",
"as",
"$",
"modelid",
"=>",
"$",
"model",
")",
"{",
"$",
"analyser",
"=",
"$",
"model",
"->",
"get_analyser",
"(",
"[",
"'notimesplitting'",
"=>",
"true",
"]",
")",
";",
"if",
"(",
"!",
"$",
"analyser",
"->",
"processes_user_data",
"(",
")",
")",
"{",
"unset",
"(",
"$",
"models",
"[",
"$",
"modelid",
"]",
")",
";",
"}",
"}",
"return",
"$",
"models",
";",
"}"
] |
Returns a list of models with user data.
@return \core_analytics\model[]
|
[
"Returns",
"a",
"list",
"of",
"models",
"with",
"user",
"data",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/privacy/provider.php#L447-L456
|
218,865
|
moodle/moodle
|
analytics/classes/privacy/provider.php
|
provider.analytics_prediction_actions_user_sql
|
private static function analytics_prediction_actions_user_sql($userid, $modelids, $contextsql = false) {
global $DB;
list($insql, $params) = $DB->get_in_or_equal($modelids, SQL_PARAMS_NAMED);
$sql = " FROM {analytics_predictions} ap
JOIN {context} ctx ON ctx.id = ap.contextid
JOIN {analytics_prediction_actions} apa ON apa.predictionid = ap.id
JOIN {analytics_models} am ON ap.modelid = am.id
WHERE apa.userid = :userid AND ap.modelid {$insql}";
$params['userid'] = $userid;
if ($contextsql) {
$sql .= " AND ap.contextid $contextsql";
}
return [$sql, $params];
}
|
php
|
private static function analytics_prediction_actions_user_sql($userid, $modelids, $contextsql = false) {
global $DB;
list($insql, $params) = $DB->get_in_or_equal($modelids, SQL_PARAMS_NAMED);
$sql = " FROM {analytics_predictions} ap
JOIN {context} ctx ON ctx.id = ap.contextid
JOIN {analytics_prediction_actions} apa ON apa.predictionid = ap.id
JOIN {analytics_models} am ON ap.modelid = am.id
WHERE apa.userid = :userid AND ap.modelid {$insql}";
$params['userid'] = $userid;
if ($contextsql) {
$sql .= " AND ap.contextid $contextsql";
}
return [$sql, $params];
}
|
[
"private",
"static",
"function",
"analytics_prediction_actions_user_sql",
"(",
"$",
"userid",
",",
"$",
"modelids",
",",
"$",
"contextsql",
"=",
"false",
")",
"{",
"global",
"$",
"DB",
";",
"list",
"(",
"$",
"insql",
",",
"$",
"params",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"modelids",
",",
"SQL_PARAMS_NAMED",
")",
";",
"$",
"sql",
"=",
"\" FROM {analytics_predictions} ap\n JOIN {context} ctx ON ctx.id = ap.contextid\n JOIN {analytics_prediction_actions} apa ON apa.predictionid = ap.id\n JOIN {analytics_models} am ON ap.modelid = am.id\n WHERE apa.userid = :userid AND ap.modelid {$insql}\"",
";",
"$",
"params",
"[",
"'userid'",
"]",
"=",
"$",
"userid",
";",
"if",
"(",
"$",
"contextsql",
")",
"{",
"$",
"sql",
".=",
"\" AND ap.contextid $contextsql\"",
";",
"}",
"return",
"[",
"$",
"sql",
",",
"$",
"params",
"]",
";",
"}"
] |
Returns the sql query to query analytics_prediction_actions table by user ID.
@param int $userid The user ID of the analytics prediction.
@param int[] $modelids Model IDs to include in the SQL.
@param string $contextsql Optional "in or equal" SQL to also query by context ID(s).
@return array sql string in [0] and params in [1].
|
[
"Returns",
"the",
"sql",
"query",
"to",
"query",
"analytics_prediction_actions",
"table",
"by",
"user",
"ID",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/privacy/provider.php#L466-L482
|
218,866
|
moodle/moodle
|
analytics/classes/privacy/provider.php
|
provider.analytics_prediction_actions_context_sql
|
private static function analytics_prediction_actions_context_sql($contextid, $modelids, $usersql = false) {
global $DB;
list($insql, $params) = $DB->get_in_or_equal($modelids, SQL_PARAMS_NAMED);
$sql = " FROM {analytics_predictions} ap
JOIN {analytics_prediction_actions} apa ON apa.predictionid = ap.id
WHERE ap.contextid = :contextid
AND ap.modelid {$insql}";
$params['contextid'] = $contextid;
if ($usersql) {
$sql .= " AND apa.userid {$usersql}";
}
return [$sql, $params];
}
|
php
|
private static function analytics_prediction_actions_context_sql($contextid, $modelids, $usersql = false) {
global $DB;
list($insql, $params) = $DB->get_in_or_equal($modelids, SQL_PARAMS_NAMED);
$sql = " FROM {analytics_predictions} ap
JOIN {analytics_prediction_actions} apa ON apa.predictionid = ap.id
WHERE ap.contextid = :contextid
AND ap.modelid {$insql}";
$params['contextid'] = $contextid;
if ($usersql) {
$sql .= " AND apa.userid {$usersql}";
}
return [$sql, $params];
}
|
[
"private",
"static",
"function",
"analytics_prediction_actions_context_sql",
"(",
"$",
"contextid",
",",
"$",
"modelids",
",",
"$",
"usersql",
"=",
"false",
")",
"{",
"global",
"$",
"DB",
";",
"list",
"(",
"$",
"insql",
",",
"$",
"params",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"modelids",
",",
"SQL_PARAMS_NAMED",
")",
";",
"$",
"sql",
"=",
"\" FROM {analytics_predictions} ap\n JOIN {analytics_prediction_actions} apa ON apa.predictionid = ap.id\n WHERE ap.contextid = :contextid\n AND ap.modelid {$insql}\"",
";",
"$",
"params",
"[",
"'contextid'",
"]",
"=",
"$",
"contextid",
";",
"if",
"(",
"$",
"usersql",
")",
"{",
"$",
"sql",
".=",
"\" AND apa.userid {$usersql}\"",
";",
"}",
"return",
"[",
"$",
"sql",
",",
"$",
"params",
"]",
";",
"}"
] |
Returns the sql query to query analytics_prediction_actions table by context ID.
@param int $contextid The context ID of the analytics prediction.
@param int[] $modelids Model IDs to include in the SQL.
@param string $usersql Optional "in or equal" SQL to also query by user ID(s).
@return array sql string in [0] and params in [1].
|
[
"Returns",
"the",
"sql",
"query",
"to",
"query",
"analytics_prediction_actions",
"table",
"by",
"context",
"ID",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/privacy/provider.php#L492-L507
|
218,867
|
moodle/moodle
|
mod/feedback/item/feedback_item_class.php
|
feedback_item_base.get_display_name
|
public function get_display_name($item, $withpostfix = true) {
return format_text($item->name, FORMAT_HTML, array('noclean' => true, 'para' => false)) .
($withpostfix ? $this->get_display_name_postfix($item) : '');
}
|
php
|
public function get_display_name($item, $withpostfix = true) {
return format_text($item->name, FORMAT_HTML, array('noclean' => true, 'para' => false)) .
($withpostfix ? $this->get_display_name_postfix($item) : '');
}
|
[
"public",
"function",
"get_display_name",
"(",
"$",
"item",
",",
"$",
"withpostfix",
"=",
"true",
")",
"{",
"return",
"format_text",
"(",
"$",
"item",
"->",
"name",
",",
"FORMAT_HTML",
",",
"array",
"(",
"'noclean'",
"=>",
"true",
",",
"'para'",
"=>",
"false",
")",
")",
".",
"(",
"$",
"withpostfix",
"?",
"$",
"this",
"->",
"get_display_name_postfix",
"(",
"$",
"item",
")",
":",
"''",
")",
";",
"}"
] |
Returns the formatted name of the item for the complete form or response view
@param stdClass $item
@param bool $withpostfix
@return string
|
[
"Returns",
"the",
"formatted",
"name",
"of",
"the",
"item",
"for",
"the",
"complete",
"form",
"or",
"response",
"view"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/item/feedback_item_class.php#L169-L172
|
218,868
|
moodle/moodle
|
mod/feedback/item/feedback_item_class.php
|
feedback_item_pagebreak.complete_form_element
|
public function complete_form_element($item, $form) {
$form->add_form_element($item,
['static',
$item->typ.'_'.$item->id,
'',
html_writer::empty_tag('hr', ['class' => 'feedback_pagebreak', 'id' => 'feedback_item_' . $item->id])
]);
}
|
php
|
public function complete_form_element($item, $form) {
$form->add_form_element($item,
['static',
$item->typ.'_'.$item->id,
'',
html_writer::empty_tag('hr', ['class' => 'feedback_pagebreak', 'id' => 'feedback_item_' . $item->id])
]);
}
|
[
"public",
"function",
"complete_form_element",
"(",
"$",
"item",
",",
"$",
"form",
")",
"{",
"$",
"form",
"->",
"add_form_element",
"(",
"$",
"item",
",",
"[",
"'static'",
",",
"$",
"item",
"->",
"typ",
".",
"'_'",
".",
"$",
"item",
"->",
"id",
",",
"''",
",",
"html_writer",
"::",
"empty_tag",
"(",
"'hr'",
",",
"[",
"'class'",
"=>",
"'feedback_pagebreak'",
",",
"'id'",
"=>",
"'feedback_item_'",
".",
"$",
"item",
"->",
"id",
"]",
")",
"]",
")",
";",
"}"
] |
Adds an input element to the complete form
@param stdClass $item
@param mod_feedback_complete_form $form
|
[
"Adds",
"an",
"input",
"element",
"to",
"the",
"complete",
"form"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/item/feedback_item_class.php#L333-L340
|
218,869
|
moodle/moodle
|
admin/tool/dataprivacy/classes/expired_context.php
|
expired_context.get_records_by_contextlevel
|
public static function get_records_by_contextlevel($contextlevel = null, $status = false, $sort = 'timecreated',
$offset = 0, $limit = 0) {
global $DB;
$sql = "SELECT expiredctx.*
FROM {" . self::TABLE . "} expiredctx
JOIN {context} ctx
ON ctx.id = expiredctx.contextid";
$params = [];
$conditions = [];
if (!empty($contextlevel)) {
$conditions[] = "ctx.contextlevel = :contextlevel";
$params['contextlevel'] = intval($contextlevel);
}
if ($status !== false) {
$conditions[] = "expiredctx.status = :status";
$params['status'] = intval($status);
}
if (!empty($conditions)) {
$sql .= ' WHERE ' . implode(' AND ', $conditions);
}
$sql .= " ORDER BY expiredctx.{$sort}";
$records = $DB->get_records_sql($sql, $params, $offset, $limit);
// 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_by_contextlevel($contextlevel = null, $status = false, $sort = 'timecreated',
$offset = 0, $limit = 0) {
global $DB;
$sql = "SELECT expiredctx.*
FROM {" . self::TABLE . "} expiredctx
JOIN {context} ctx
ON ctx.id = expiredctx.contextid";
$params = [];
$conditions = [];
if (!empty($contextlevel)) {
$conditions[] = "ctx.contextlevel = :contextlevel";
$params['contextlevel'] = intval($contextlevel);
}
if ($status !== false) {
$conditions[] = "expiredctx.status = :status";
$params['status'] = intval($status);
}
if (!empty($conditions)) {
$sql .= ' WHERE ' . implode(' AND ', $conditions);
}
$sql .= " ORDER BY expiredctx.{$sort}";
$records = $DB->get_records_sql($sql, $params, $offset, $limit);
// We return class instances.
$instances = array();
foreach ($records as $key => $record) {
$instances[$key] = new static(0, $record);
}
return $instances;
}
|
[
"public",
"static",
"function",
"get_records_by_contextlevel",
"(",
"$",
"contextlevel",
"=",
"null",
",",
"$",
"status",
"=",
"false",
",",
"$",
"sort",
"=",
"'timecreated'",
",",
"$",
"offset",
"=",
"0",
",",
"$",
"limit",
"=",
"0",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"sql",
"=",
"\"SELECT expiredctx.*\n FROM {\"",
".",
"self",
"::",
"TABLE",
".",
"\"} expiredctx\n JOIN {context} ctx\n ON ctx.id = expiredctx.contextid\"",
";",
"$",
"params",
"=",
"[",
"]",
";",
"$",
"conditions",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"contextlevel",
")",
")",
"{",
"$",
"conditions",
"[",
"]",
"=",
"\"ctx.contextlevel = :contextlevel\"",
";",
"$",
"params",
"[",
"'contextlevel'",
"]",
"=",
"intval",
"(",
"$",
"contextlevel",
")",
";",
"}",
"if",
"(",
"$",
"status",
"!==",
"false",
")",
"{",
"$",
"conditions",
"[",
"]",
"=",
"\"expiredctx.status = :status\"",
";",
"$",
"params",
"[",
"'status'",
"]",
"=",
"intval",
"(",
"$",
"status",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"conditions",
")",
")",
"{",
"$",
"sql",
".=",
"' WHERE '",
".",
"implode",
"(",
"' AND '",
",",
"$",
"conditions",
")",
";",
"}",
"$",
"sql",
".=",
"\" ORDER BY expiredctx.{$sort}\"",
";",
"$",
"records",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"$",
"sql",
",",
"$",
"params",
",",
"$",
"offset",
",",
"$",
"limit",
")",
";",
"// We return class instances.",
"$",
"instances",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"records",
"as",
"$",
"key",
"=>",
"$",
"record",
")",
"{",
"$",
"instances",
"[",
"$",
"key",
"]",
"=",
"new",
"static",
"(",
"0",
",",
"$",
"record",
")",
";",
"}",
"return",
"$",
"instances",
";",
"}"
] |
Returns expired_contexts instances that match the provided level and status.
@param int $contextlevel The context level filter criterion.
@param bool $status The expired context record's status.
@param string $sort The sort column. Must match the column name in {tool_dataprivacy_ctxexpired} table
@param int $offset The query offset.
@param int $limit The query limit.
@return expired_context[]
@throws dml_exception
|
[
"Returns",
"expired_contexts",
"instances",
"that",
"match",
"the",
"provided",
"level",
"and",
"status",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/expired_context.php#L106-L141
|
218,870
|
moodle/moodle
|
admin/tool/dataprivacy/classes/expired_context.php
|
expired_context.get_record_count_by_contextlevel
|
public static function get_record_count_by_contextlevel($contextlevel = null, $status = false) {
global $DB;
$sql = "SELECT COUNT(1)
FROM {" . self::TABLE . "} expiredctx
JOIN {context} ctx
ON ctx.id = expiredctx.contextid";
$conditions = [];
$params = [];
if (!empty($contextlevel)) {
$conditions[] = "ctx.contextlevel = :contextlevel";
$params['contextlevel'] = intval($contextlevel);
}
if ($status !== false) {
$sql .= " AND expiredctx.status = :status";
$params['status'] = intval($status);
}
if (!empty($conditions)) {
$sql .= ' WHERE ' . implode(' AND ', $conditions);
}
return $DB->count_records_sql($sql, $params);
}
|
php
|
public static function get_record_count_by_contextlevel($contextlevel = null, $status = false) {
global $DB;
$sql = "SELECT COUNT(1)
FROM {" . self::TABLE . "} expiredctx
JOIN {context} ctx
ON ctx.id = expiredctx.contextid";
$conditions = [];
$params = [];
if (!empty($contextlevel)) {
$conditions[] = "ctx.contextlevel = :contextlevel";
$params['contextlevel'] = intval($contextlevel);
}
if ($status !== false) {
$sql .= " AND expiredctx.status = :status";
$params['status'] = intval($status);
}
if (!empty($conditions)) {
$sql .= ' WHERE ' . implode(' AND ', $conditions);
}
return $DB->count_records_sql($sql, $params);
}
|
[
"public",
"static",
"function",
"get_record_count_by_contextlevel",
"(",
"$",
"contextlevel",
"=",
"null",
",",
"$",
"status",
"=",
"false",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"sql",
"=",
"\"SELECT COUNT(1)\n FROM {\"",
".",
"self",
"::",
"TABLE",
".",
"\"} expiredctx\n JOIN {context} ctx\n ON ctx.id = expiredctx.contextid\"",
";",
"$",
"conditions",
"=",
"[",
"]",
";",
"$",
"params",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"contextlevel",
")",
")",
"{",
"$",
"conditions",
"[",
"]",
"=",
"\"ctx.contextlevel = :contextlevel\"",
";",
"$",
"params",
"[",
"'contextlevel'",
"]",
"=",
"intval",
"(",
"$",
"contextlevel",
")",
";",
"}",
"if",
"(",
"$",
"status",
"!==",
"false",
")",
"{",
"$",
"sql",
".=",
"\" AND expiredctx.status = :status\"",
";",
"$",
"params",
"[",
"'status'",
"]",
"=",
"intval",
"(",
"$",
"status",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"conditions",
")",
")",
"{",
"$",
"sql",
".=",
"' WHERE '",
".",
"implode",
"(",
"' AND '",
",",
"$",
"conditions",
")",
";",
"}",
"return",
"$",
"DB",
"->",
"count_records_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"}"
] |
Returns the number of expired_contexts instances that match the provided level and status.
@param int $contextlevel
@param bool $status
@return int
@throws dml_exception
|
[
"Returns",
"the",
"number",
"of",
"expired_contexts",
"instances",
"that",
"match",
"the",
"provided",
"level",
"and",
"status",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/expired_context.php#L151-L176
|
218,871
|
moodle/moodle
|
admin/tool/dataprivacy/classes/expired_context.php
|
expired_context.set_roleids_for
|
protected function set_roleids_for(string $field, array $roleids) : expired_context {
$roledata = json_encode($roleids);
$this->raw_set($field, $roledata);
return $this;
}
|
php
|
protected function set_roleids_for(string $field, array $roleids) : expired_context {
$roledata = json_encode($roleids);
$this->raw_set($field, $roledata);
return $this;
}
|
[
"protected",
"function",
"set_roleids_for",
"(",
"string",
"$",
"field",
",",
"array",
"$",
"roleids",
")",
":",
"expired_context",
"{",
"$",
"roledata",
"=",
"json_encode",
"(",
"$",
"roleids",
")",
";",
"$",
"this",
"->",
"raw_set",
"(",
"$",
"field",
",",
"$",
"roledata",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Set the list of role IDs for either expiredroles, or unexpiredroles.
@param string $field
@param int[] $roleids
@return expired_context
|
[
"Set",
"the",
"list",
"of",
"role",
"IDs",
"for",
"either",
"expiredroles",
"or",
"unexpiredroles",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/expired_context.php#L185-L191
|
218,872
|
moodle/moodle
|
admin/tool/dataprivacy/classes/expired_context.php
|
expired_context.get_roleids_for
|
protected function get_roleids_for(string $field) {
$value = $this->raw_get($field);
if (empty($value)) {
return [];
}
return json_decode($value);
}
|
php
|
protected function get_roleids_for(string $field) {
$value = $this->raw_get($field);
if (empty($value)) {
return [];
}
return json_decode($value);
}
|
[
"protected",
"function",
"get_roleids_for",
"(",
"string",
"$",
"field",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"raw_get",
"(",
"$",
"field",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"json_decode",
"(",
"$",
"value",
")",
";",
"}"
] |
Get the list of role IDs for either expiredroles, or unexpiredroles.
@param string $field
@return int[]
|
[
"Get",
"the",
"list",
"of",
"role",
"IDs",
"for",
"either",
"expiredroles",
"or",
"unexpiredroles",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/expired_context.php#L199-L206
|
218,873
|
moodle/moodle
|
admin/tool/dataprivacy/classes/expired_context.php
|
expired_context.add_expiredroles
|
public function add_expiredroles(array $roleids) : expired_context {
$existing = $this->get('expiredroles');
$newvalue = array_merge($existing, $roleids);
$this->set('expiredroles', $newvalue);
return $this;
}
|
php
|
public function add_expiredroles(array $roleids) : expired_context {
$existing = $this->get('expiredroles');
$newvalue = array_merge($existing, $roleids);
$this->set('expiredroles', $newvalue);
return $this;
}
|
[
"public",
"function",
"add_expiredroles",
"(",
"array",
"$",
"roleids",
")",
":",
"expired_context",
"{",
"$",
"existing",
"=",
"$",
"this",
"->",
"get",
"(",
"'expiredroles'",
")",
";",
"$",
"newvalue",
"=",
"array_merge",
"(",
"$",
"existing",
",",
"$",
"roleids",
")",
";",
"$",
"this",
"->",
"set",
"(",
"'expiredroles'",
",",
"$",
"newvalue",
")",
";",
"return",
"$",
"this",
";",
"}"
] |
Add a set of role IDs to the list of expired role IDs.
@param int[] $roleids
@return expired_context
|
[
"Add",
"a",
"set",
"of",
"role",
"IDs",
"to",
"the",
"list",
"of",
"expired",
"role",
"IDs",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/expired_context.php#L226-L233
|
218,874
|
moodle/moodle
|
admin/tool/dataprivacy/classes/expired_context.php
|
expired_context.create_from_expiry_info
|
public static function create_from_expiry_info(\context $context, expiry_info $info, bool $save = true) : expired_context {
$record = (object) [
'contextid' => $context->id,
'status' => self::STATUS_EXPIRED,
'defaultexpired' => (int) $info->is_default_expired(),
];
$expiredcontext = new static(0, $record);
$expiredcontext->set('expiredroles', $info->get_expired_roles());
$expiredcontext->set('unexpiredroles', $info->get_unexpired_roles());
if ($save) {
$expiredcontext->save();
}
return $expiredcontext;
}
|
php
|
public static function create_from_expiry_info(\context $context, expiry_info $info, bool $save = true) : expired_context {
$record = (object) [
'contextid' => $context->id,
'status' => self::STATUS_EXPIRED,
'defaultexpired' => (int) $info->is_default_expired(),
];
$expiredcontext = new static(0, $record);
$expiredcontext->set('expiredroles', $info->get_expired_roles());
$expiredcontext->set('unexpiredroles', $info->get_unexpired_roles());
if ($save) {
$expiredcontext->save();
}
return $expiredcontext;
}
|
[
"public",
"static",
"function",
"create_from_expiry_info",
"(",
"\\",
"context",
"$",
"context",
",",
"expiry_info",
"$",
"info",
",",
"bool",
"$",
"save",
"=",
"true",
")",
":",
"expired_context",
"{",
"$",
"record",
"=",
"(",
"object",
")",
"[",
"'contextid'",
"=>",
"$",
"context",
"->",
"id",
",",
"'status'",
"=>",
"self",
"::",
"STATUS_EXPIRED",
",",
"'defaultexpired'",
"=>",
"(",
"int",
")",
"$",
"info",
"->",
"is_default_expired",
"(",
")",
",",
"]",
";",
"$",
"expiredcontext",
"=",
"new",
"static",
"(",
"0",
",",
"$",
"record",
")",
";",
"$",
"expiredcontext",
"->",
"set",
"(",
"'expiredroles'",
",",
"$",
"info",
"->",
"get_expired_roles",
"(",
")",
")",
";",
"$",
"expiredcontext",
"->",
"set",
"(",
"'unexpiredroles'",
",",
"$",
"info",
"->",
"get_unexpired_roles",
"(",
")",
")",
";",
"if",
"(",
"$",
"save",
")",
"{",
"$",
"expiredcontext",
"->",
"save",
"(",
")",
";",
"}",
"return",
"$",
"expiredcontext",
";",
"}"
] |
Create a new expired_context based on the context, and expiry_info object.
@param \context $context
@param expiry_info $info
@param boolean $save
@return expired_context
|
[
"Create",
"a",
"new",
"expired_context",
"based",
"on",
"the",
"context",
"and",
"expiry_info",
"object",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/expired_context.php#L288-L304
|
218,875
|
moodle/moodle
|
admin/tool/dataprivacy/classes/expired_context.php
|
expired_context.update_from_expiry_info
|
public function update_from_expiry_info(expiry_info $info) : expired_context {
$save = false;
// Compare the expiredroles.
$thisexpired = $this->get('expiredroles');
$infoexpired = $info->get_expired_roles();
sort($thisexpired);
sort($infoexpired);
if ($infoexpired != $thisexpired) {
$this->set('expiredroles', $infoexpired);
$save = true;
}
// Compare the unexpiredroles.
$thisunexpired = $this->get('unexpiredroles');
$infounexpired = $info->get_unexpired_roles();
sort($thisunexpired);
sort($infounexpired);
if ($infounexpired != $thisunexpired) {
$this->set('unexpiredroles', $infounexpired);
$save = true;
}
if (empty($this->get('defaultexpired')) == $info->is_default_expired()) {
$this->set('defaultexpired', (int) $info->is_default_expired());
$save = true;
}
if ($save) {
$this->set('status', self::STATUS_EXPIRED);
$this->save();
}
return $this;
}
|
php
|
public function update_from_expiry_info(expiry_info $info) : expired_context {
$save = false;
// Compare the expiredroles.
$thisexpired = $this->get('expiredroles');
$infoexpired = $info->get_expired_roles();
sort($thisexpired);
sort($infoexpired);
if ($infoexpired != $thisexpired) {
$this->set('expiredroles', $infoexpired);
$save = true;
}
// Compare the unexpiredroles.
$thisunexpired = $this->get('unexpiredroles');
$infounexpired = $info->get_unexpired_roles();
sort($thisunexpired);
sort($infounexpired);
if ($infounexpired != $thisunexpired) {
$this->set('unexpiredroles', $infounexpired);
$save = true;
}
if (empty($this->get('defaultexpired')) == $info->is_default_expired()) {
$this->set('defaultexpired', (int) $info->is_default_expired());
$save = true;
}
if ($save) {
$this->set('status', self::STATUS_EXPIRED);
$this->save();
}
return $this;
}
|
[
"public",
"function",
"update_from_expiry_info",
"(",
"expiry_info",
"$",
"info",
")",
":",
"expired_context",
"{",
"$",
"save",
"=",
"false",
";",
"// Compare the expiredroles.",
"$",
"thisexpired",
"=",
"$",
"this",
"->",
"get",
"(",
"'expiredroles'",
")",
";",
"$",
"infoexpired",
"=",
"$",
"info",
"->",
"get_expired_roles",
"(",
")",
";",
"sort",
"(",
"$",
"thisexpired",
")",
";",
"sort",
"(",
"$",
"infoexpired",
")",
";",
"if",
"(",
"$",
"infoexpired",
"!=",
"$",
"thisexpired",
")",
"{",
"$",
"this",
"->",
"set",
"(",
"'expiredroles'",
",",
"$",
"infoexpired",
")",
";",
"$",
"save",
"=",
"true",
";",
"}",
"// Compare the unexpiredroles.",
"$",
"thisunexpired",
"=",
"$",
"this",
"->",
"get",
"(",
"'unexpiredroles'",
")",
";",
"$",
"infounexpired",
"=",
"$",
"info",
"->",
"get_unexpired_roles",
"(",
")",
";",
"sort",
"(",
"$",
"thisunexpired",
")",
";",
"sort",
"(",
"$",
"infounexpired",
")",
";",
"if",
"(",
"$",
"infounexpired",
"!=",
"$",
"thisunexpired",
")",
"{",
"$",
"this",
"->",
"set",
"(",
"'unexpiredroles'",
",",
"$",
"infounexpired",
")",
";",
"$",
"save",
"=",
"true",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"get",
"(",
"'defaultexpired'",
")",
")",
"==",
"$",
"info",
"->",
"is_default_expired",
"(",
")",
")",
"{",
"$",
"this",
"->",
"set",
"(",
"'defaultexpired'",
",",
"(",
"int",
")",
"$",
"info",
"->",
"is_default_expired",
"(",
")",
")",
";",
"$",
"save",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"save",
")",
"{",
"$",
"this",
"->",
"set",
"(",
"'status'",
",",
"self",
"::",
"STATUS_EXPIRED",
")",
";",
"$",
"this",
"->",
"save",
"(",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Update the expired_context from an expiry_info object which relates to this context.
@param expiry_info $info
@return $this
|
[
"Update",
"the",
"expired_context",
"from",
"an",
"expiry_info",
"object",
"which",
"relates",
"to",
"this",
"context",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/expired_context.php#L312-L349
|
218,876
|
moodle/moodle
|
lib/classes/lock/db_record_lock_factory.php
|
db_record_lock_factory.extend_lock
|
public function extend_lock(lock $lock, $maxlifetime = 86400) {
$now = time();
$expires = $now + $maxlifetime;
$params = array('expires' => $expires,
'token' => $lock->get_key());
$sql = 'UPDATE {lock_db}
SET
expires = :expires,
WHERE
owner = :token';
$this->db->execute($sql, $params);
$countparams = array('owner' => $lock->get_key());
$result = $this->count_records('lock_db', $countparams);
return $result === 0;
}
|
php
|
public function extend_lock(lock $lock, $maxlifetime = 86400) {
$now = time();
$expires = $now + $maxlifetime;
$params = array('expires' => $expires,
'token' => $lock->get_key());
$sql = 'UPDATE {lock_db}
SET
expires = :expires,
WHERE
owner = :token';
$this->db->execute($sql, $params);
$countparams = array('owner' => $lock->get_key());
$result = $this->count_records('lock_db', $countparams);
return $result === 0;
}
|
[
"public",
"function",
"extend_lock",
"(",
"lock",
"$",
"lock",
",",
"$",
"maxlifetime",
"=",
"86400",
")",
"{",
"$",
"now",
"=",
"time",
"(",
")",
";",
"$",
"expires",
"=",
"$",
"now",
"+",
"$",
"maxlifetime",
";",
"$",
"params",
"=",
"array",
"(",
"'expires'",
"=>",
"$",
"expires",
",",
"'token'",
"=>",
"$",
"lock",
"->",
"get_key",
"(",
")",
")",
";",
"$",
"sql",
"=",
"'UPDATE {lock_db}\n SET\n expires = :expires,\n WHERE\n owner = :token'",
";",
"$",
"this",
"->",
"db",
"->",
"execute",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"$",
"countparams",
"=",
"array",
"(",
"'owner'",
"=>",
"$",
"lock",
"->",
"get_key",
"(",
")",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"count_records",
"(",
"'lock_db'",
",",
"$",
"countparams",
")",
";",
"return",
"$",
"result",
"===",
"0",
";",
"}"
] |
Extend a lock that was previously obtained with @lock.
@param lock $lock - a lock obtained from this factory.
@param int $maxlifetime - the new lifetime for the lock (in seconds).
@return boolean - true if the lock was extended.
|
[
"Extend",
"a",
"lock",
"that",
"was",
"previously",
"obtained",
"with"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/lock/db_record_lock_factory.php#L192-L209
|
218,877
|
moodle/moodle
|
competency/classes/related_competency.php
|
related_competency.validate_relatedcompetencyid
|
protected function validate_relatedcompetencyid($data) {
if ($this->get('competencyid') == $data) {
// A competency cannot be related to itself.
return new lang_string('invaliddata', 'error');
} if ($this->get('competencyid') > $data) {
// The competency ID must be lower than the related competency ID.
return new lang_string('invaliddata', 'error');
} else if (!competency::record_exists($data)) {
return new lang_string('invaliddata', 'error');
} else if (!competency::share_same_framework(array($data, $this->get('competencyid')))) {
// The competencies must belong to the same framework.
return new lang_string('invaliddata', 'error');
}
return true;
}
|
php
|
protected function validate_relatedcompetencyid($data) {
if ($this->get('competencyid') == $data) {
// A competency cannot be related to itself.
return new lang_string('invaliddata', 'error');
} if ($this->get('competencyid') > $data) {
// The competency ID must be lower than the related competency ID.
return new lang_string('invaliddata', 'error');
} else if (!competency::record_exists($data)) {
return new lang_string('invaliddata', 'error');
} else if (!competency::share_same_framework(array($data, $this->get('competencyid')))) {
// The competencies must belong to the same framework.
return new lang_string('invaliddata', 'error');
}
return true;
}
|
[
"protected",
"function",
"validate_relatedcompetencyid",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"get",
"(",
"'competencyid'",
")",
"==",
"$",
"data",
")",
"{",
"// A competency cannot be related to itself.",
"return",
"new",
"lang_string",
"(",
"'invaliddata'",
",",
"'error'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"get",
"(",
"'competencyid'",
")",
">",
"$",
"data",
")",
"{",
"// The competency ID must be lower than the related competency ID.",
"return",
"new",
"lang_string",
"(",
"'invaliddata'",
",",
"'error'",
")",
";",
"}",
"else",
"if",
"(",
"!",
"competency",
"::",
"record_exists",
"(",
"$",
"data",
")",
")",
"{",
"return",
"new",
"lang_string",
"(",
"'invaliddata'",
",",
"'error'",
")",
";",
"}",
"else",
"if",
"(",
"!",
"competency",
"::",
"share_same_framework",
"(",
"array",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"get",
"(",
"'competencyid'",
")",
")",
")",
")",
"{",
"// The competencies must belong to the same framework.",
"return",
"new",
"lang_string",
"(",
"'invaliddata'",
",",
"'error'",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Validate related competency ID.
@param int $data The related competency ID.
@return true|lang_string
|
[
"Validate",
"related",
"competency",
"ID",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/related_competency.php#L76-L95
|
218,878
|
moodle/moodle
|
competency/classes/related_competency.php
|
related_competency.get_relation
|
public static function get_relation($competencyid, $relatedcompetencyid) {
global $DB;
// Lower id always as competencyid so we know which one is competencyid and which one relatedcompetencyid.
$relation = new static();
if ($competencyid > $relatedcompetencyid) {
$relation->set('competencyid', $relatedcompetencyid);
$relation->set('relatedcompetencyid', $competencyid);
} else {
$relation->set('competencyid', $competencyid);
$relation->set('relatedcompetencyid', $relatedcompetencyid);
}
// We can do it because we have bidirectional relations in the DB.
$params = array(
'competencyid' => $relation->get('competencyid'),
'relatedcompetencyid' => $relation->get('relatedcompetencyid')
);
if ($record = $DB->get_record(self::TABLE, $params)) {
$relation->from_record($record);
}
return $relation;
}
|
php
|
public static function get_relation($competencyid, $relatedcompetencyid) {
global $DB;
// Lower id always as competencyid so we know which one is competencyid and which one relatedcompetencyid.
$relation = new static();
if ($competencyid > $relatedcompetencyid) {
$relation->set('competencyid', $relatedcompetencyid);
$relation->set('relatedcompetencyid', $competencyid);
} else {
$relation->set('competencyid', $competencyid);
$relation->set('relatedcompetencyid', $relatedcompetencyid);
}
// We can do it because we have bidirectional relations in the DB.
$params = array(
'competencyid' => $relation->get('competencyid'),
'relatedcompetencyid' => $relation->get('relatedcompetencyid')
);
if ($record = $DB->get_record(self::TABLE, $params)) {
$relation->from_record($record);
}
return $relation;
}
|
[
"public",
"static",
"function",
"get_relation",
"(",
"$",
"competencyid",
",",
"$",
"relatedcompetencyid",
")",
"{",
"global",
"$",
"DB",
";",
"// Lower id always as competencyid so we know which one is competencyid and which one relatedcompetencyid.",
"$",
"relation",
"=",
"new",
"static",
"(",
")",
";",
"if",
"(",
"$",
"competencyid",
">",
"$",
"relatedcompetencyid",
")",
"{",
"$",
"relation",
"->",
"set",
"(",
"'competencyid'",
",",
"$",
"relatedcompetencyid",
")",
";",
"$",
"relation",
"->",
"set",
"(",
"'relatedcompetencyid'",
",",
"$",
"competencyid",
")",
";",
"}",
"else",
"{",
"$",
"relation",
"->",
"set",
"(",
"'competencyid'",
",",
"$",
"competencyid",
")",
";",
"$",
"relation",
"->",
"set",
"(",
"'relatedcompetencyid'",
",",
"$",
"relatedcompetencyid",
")",
";",
"}",
"// We can do it because we have bidirectional relations in the DB.",
"$",
"params",
"=",
"array",
"(",
"'competencyid'",
"=>",
"$",
"relation",
"->",
"get",
"(",
"'competencyid'",
")",
",",
"'relatedcompetencyid'",
"=>",
"$",
"relation",
"->",
"get",
"(",
"'relatedcompetencyid'",
")",
")",
";",
"if",
"(",
"$",
"record",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"self",
"::",
"TABLE",
",",
"$",
"params",
")",
")",
"{",
"$",
"relation",
"->",
"from_record",
"(",
"$",
"record",
")",
";",
"}",
"return",
"$",
"relation",
";",
"}"
] |
Get relation specifying both competencies.
This does not perform any validation on the data passed. If the relation exists in the database
then it is loaded in a the model, if not then it is up to the developer to save the model.
@param int $competencyid
@param int $relatedcompetencyid
@return related_competency
|
[
"Get",
"relation",
"specifying",
"both",
"competencies",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/related_competency.php#L107-L130
|
218,879
|
moodle/moodle
|
competency/classes/related_competency.php
|
related_competency.get_related_competencies
|
public static function get_related_competencies($competencyid) {
global $DB;
$fields = competency::get_sql_fields('c', 'c_');
$sql = "(SELECT $fields, " . $DB->sql_concat('rc.relatedcompetencyid', "'_'", 'rc.competencyid') . " AS rid
FROM {" . self::TABLE . "} rc
JOIN {" . competency::TABLE . "} c
ON c.id = rc.relatedcompetencyid
WHERE rc.competencyid = :cid)
UNION ALL
(SELECT $fields, " . $DB->sql_concat('rc.competencyid', "'_'", 'rc.relatedcompetencyid') . " AS rid
FROM {" . self::TABLE . "} rc
JOIN {" . competency::TABLE . "} c
ON c.id = rc.competencyid
WHERE rc.relatedcompetencyid = :cid2)
ORDER BY c_path ASC, c_sortorder ASC";
$competencies = array();
$records = $DB->get_recordset_sql($sql, array('cid' => $competencyid, 'cid2' => $competencyid));
foreach ($records as $record) {
unset($record->rid);
$competencies[$record->c_id] = new competency(null, competency::extract_record($record, 'c_'));
}
$records->close();
return $competencies;
}
|
php
|
public static function get_related_competencies($competencyid) {
global $DB;
$fields = competency::get_sql_fields('c', 'c_');
$sql = "(SELECT $fields, " . $DB->sql_concat('rc.relatedcompetencyid', "'_'", 'rc.competencyid') . " AS rid
FROM {" . self::TABLE . "} rc
JOIN {" . competency::TABLE . "} c
ON c.id = rc.relatedcompetencyid
WHERE rc.competencyid = :cid)
UNION ALL
(SELECT $fields, " . $DB->sql_concat('rc.competencyid', "'_'", 'rc.relatedcompetencyid') . " AS rid
FROM {" . self::TABLE . "} rc
JOIN {" . competency::TABLE . "} c
ON c.id = rc.competencyid
WHERE rc.relatedcompetencyid = :cid2)
ORDER BY c_path ASC, c_sortorder ASC";
$competencies = array();
$records = $DB->get_recordset_sql($sql, array('cid' => $competencyid, 'cid2' => $competencyid));
foreach ($records as $record) {
unset($record->rid);
$competencies[$record->c_id] = new competency(null, competency::extract_record($record, 'c_'));
}
$records->close();
return $competencies;
}
|
[
"public",
"static",
"function",
"get_related_competencies",
"(",
"$",
"competencyid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"fields",
"=",
"competency",
"::",
"get_sql_fields",
"(",
"'c'",
",",
"'c_'",
")",
";",
"$",
"sql",
"=",
"\"(SELECT $fields, \"",
".",
"$",
"DB",
"->",
"sql_concat",
"(",
"'rc.relatedcompetencyid'",
",",
"\"'_'\"",
",",
"'rc.competencyid'",
")",
".",
"\" AS rid\n FROM {\"",
".",
"self",
"::",
"TABLE",
".",
"\"} rc\n JOIN {\"",
".",
"competency",
"::",
"TABLE",
".",
"\"} c\n ON c.id = rc.relatedcompetencyid\n WHERE rc.competencyid = :cid)\n UNION ALL\n (SELECT $fields, \"",
".",
"$",
"DB",
"->",
"sql_concat",
"(",
"'rc.competencyid'",
",",
"\"'_'\"",
",",
"'rc.relatedcompetencyid'",
")",
".",
"\" AS rid\n FROM {\"",
".",
"self",
"::",
"TABLE",
".",
"\"} rc\n JOIN {\"",
".",
"competency",
"::",
"TABLE",
".",
"\"} c\n ON c.id = rc.competencyid\n WHERE rc.relatedcompetencyid = :cid2)\n ORDER BY c_path ASC, c_sortorder ASC\"",
";",
"$",
"competencies",
"=",
"array",
"(",
")",
";",
"$",
"records",
"=",
"$",
"DB",
"->",
"get_recordset_sql",
"(",
"$",
"sql",
",",
"array",
"(",
"'cid'",
"=>",
"$",
"competencyid",
",",
"'cid2'",
"=>",
"$",
"competencyid",
")",
")",
";",
"foreach",
"(",
"$",
"records",
"as",
"$",
"record",
")",
"{",
"unset",
"(",
"$",
"record",
"->",
"rid",
")",
";",
"$",
"competencies",
"[",
"$",
"record",
"->",
"c_id",
"]",
"=",
"new",
"competency",
"(",
"null",
",",
"competency",
"::",
"extract_record",
"(",
"$",
"record",
",",
"'c_'",
")",
")",
";",
"}",
"$",
"records",
"->",
"close",
"(",
")",
";",
"return",
"$",
"competencies",
";",
"}"
] |
Get the competencies related to a competency.
@param int $competencyid The competency ID.
@return competency[]
|
[
"Get",
"the",
"competencies",
"related",
"to",
"a",
"competency",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/related_competency.php#L138-L164
|
218,880
|
moodle/moodle
|
competency/classes/related_competency.php
|
related_competency.get_multiple_relations
|
public static function get_multiple_relations($competencyids) {
global $DB;
if (empty($competencyids)) {
return array();
}
list($insql, $params) = $DB->get_in_or_equal($competencyids);
$records = $DB->get_records_select(self::TABLE,
"competencyid $insql OR relatedcompetencyid $insql",
array_merge($params, $params)
);
$relatedcompetencies = array();
foreach ($records as $record) {
unset($record->id);
$relatedcompetencies[] = new related_competency(null, $record);
}
return $relatedcompetencies;
}
|
php
|
public static function get_multiple_relations($competencyids) {
global $DB;
if (empty($competencyids)) {
return array();
}
list($insql, $params) = $DB->get_in_or_equal($competencyids);
$records = $DB->get_records_select(self::TABLE,
"competencyid $insql OR relatedcompetencyid $insql",
array_merge($params, $params)
);
$relatedcompetencies = array();
foreach ($records as $record) {
unset($record->id);
$relatedcompetencies[] = new related_competency(null, $record);
}
return $relatedcompetencies;
}
|
[
"public",
"static",
"function",
"get_multiple_relations",
"(",
"$",
"competencyids",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"empty",
"(",
"$",
"competencyids",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"list",
"(",
"$",
"insql",
",",
"$",
"params",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"competencyids",
")",
";",
"$",
"records",
"=",
"$",
"DB",
"->",
"get_records_select",
"(",
"self",
"::",
"TABLE",
",",
"\"competencyid $insql OR relatedcompetencyid $insql\"",
",",
"array_merge",
"(",
"$",
"params",
",",
"$",
"params",
")",
")",
";",
"$",
"relatedcompetencies",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"records",
"as",
"$",
"record",
")",
"{",
"unset",
"(",
"$",
"record",
"->",
"id",
")",
";",
"$",
"relatedcompetencies",
"[",
"]",
"=",
"new",
"related_competency",
"(",
"null",
",",
"$",
"record",
")",
";",
"}",
"return",
"$",
"relatedcompetencies",
";",
"}"
] |
Get the related competencies from competency ids.
@param int[] $competencyids Array of competency ids.
@return related_competency[]
|
[
"Get",
"the",
"related",
"competencies",
"from",
"competency",
"ids",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/related_competency.php#L172-L192
|
218,881
|
moodle/moodle
|
competency/classes/related_competency.php
|
related_competency.delete_multiple_relations
|
public static function delete_multiple_relations($competencyids) {
global $DB;
if (empty($competencyids)) {
return true;
}
list($insql, $params) = $DB->get_in_or_equal($competencyids);
return $DB->delete_records_select(self::TABLE,
"competencyid $insql OR relatedcompetencyid $insql",
array_merge($params, $params)
);
}
|
php
|
public static function delete_multiple_relations($competencyids) {
global $DB;
if (empty($competencyids)) {
return true;
}
list($insql, $params) = $DB->get_in_or_equal($competencyids);
return $DB->delete_records_select(self::TABLE,
"competencyid $insql OR relatedcompetencyid $insql",
array_merge($params, $params)
);
}
|
[
"public",
"static",
"function",
"delete_multiple_relations",
"(",
"$",
"competencyids",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"empty",
"(",
"$",
"competencyids",
")",
")",
"{",
"return",
"true",
";",
"}",
"list",
"(",
"$",
"insql",
",",
"$",
"params",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"competencyids",
")",
";",
"return",
"$",
"DB",
"->",
"delete_records_select",
"(",
"self",
"::",
"TABLE",
",",
"\"competencyid $insql OR relatedcompetencyid $insql\"",
",",
"array_merge",
"(",
"$",
"params",
",",
"$",
"params",
")",
")",
";",
"}"
] |
Delete relations using competencies.
@param array $competencyids Array of competencies ids.
@return bool True if relations were deleted successfully.
|
[
"Delete",
"relations",
"using",
"competencies",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/related_competency.php#L200-L211
|
218,882
|
moodle/moodle
|
lib/classes/event/user_enrolment_created.php
|
user_enrolment_created.get_legacy_eventdata
|
protected function get_legacy_eventdata() {
$legacyeventdata = $this->get_record_snapshot('user_enrolments', $this->objectid);
$legacyeventdata->enrol = $this->other['enrol'];
$legacyeventdata->courseid = $this->courseid;
return $legacyeventdata;
}
|
php
|
protected function get_legacy_eventdata() {
$legacyeventdata = $this->get_record_snapshot('user_enrolments', $this->objectid);
$legacyeventdata->enrol = $this->other['enrol'];
$legacyeventdata->courseid = $this->courseid;
return $legacyeventdata;
}
|
[
"protected",
"function",
"get_legacy_eventdata",
"(",
")",
"{",
"$",
"legacyeventdata",
"=",
"$",
"this",
"->",
"get_record_snapshot",
"(",
"'user_enrolments'",
",",
"$",
"this",
"->",
"objectid",
")",
";",
"$",
"legacyeventdata",
"->",
"enrol",
"=",
"$",
"this",
"->",
"other",
"[",
"'enrol'",
"]",
";",
"$",
"legacyeventdata",
"->",
"courseid",
"=",
"$",
"this",
"->",
"courseid",
";",
"return",
"$",
"legacyeventdata",
";",
"}"
] |
Return user_enrolled legacy event data.
@return \stdClass
|
[
"Return",
"user_enrolled",
"legacy",
"event",
"data",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/event/user_enrolment_created.php#L95-L100
|
218,883
|
moodle/moodle
|
mod/assign/gradingtable.php
|
assign_grading_table.format_row
|
public function format_row($row) {
if ($this->rownum < 0) {
$this->rownum = $this->currpage * $this->pagesize;
} else {
$this->rownum += 1;
}
return parent::format_row($row);
}
|
php
|
public function format_row($row) {
if ($this->rownum < 0) {
$this->rownum = $this->currpage * $this->pagesize;
} else {
$this->rownum += 1;
}
return parent::format_row($row);
}
|
[
"public",
"function",
"format_row",
"(",
"$",
"row",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"rownum",
"<",
"0",
")",
"{",
"$",
"this",
"->",
"rownum",
"=",
"$",
"this",
"->",
"currpage",
"*",
"$",
"this",
"->",
"pagesize",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"rownum",
"+=",
"1",
";",
"}",
"return",
"parent",
"::",
"format_row",
"(",
"$",
"row",
")",
";",
"}"
] |
Before adding each row to the table make sure rownum is incremented.
@param array $row row of data from db used to make one row of the table.
@return array one row for the table
|
[
"Before",
"adding",
"each",
"row",
"to",
"the",
"table",
"make",
"sure",
"rownum",
"is",
"incremented",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/gradingtable.php#L537-L545
|
218,884
|
moodle/moodle
|
mod/assign/gradingtable.php
|
assign_grading_table.col_recordid
|
public function col_recordid(stdClass $row) {
if (empty($row->recordid)) {
$row->recordid = $this->assignment->get_uniqueid_for_user($row->userid);
}
return get_string('hiddenuser', 'assign') . $row->recordid;
}
|
php
|
public function col_recordid(stdClass $row) {
if (empty($row->recordid)) {
$row->recordid = $this->assignment->get_uniqueid_for_user($row->userid);
}
return get_string('hiddenuser', 'assign') . $row->recordid;
}
|
[
"public",
"function",
"col_recordid",
"(",
"stdClass",
"$",
"row",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"row",
"->",
"recordid",
")",
")",
"{",
"$",
"row",
"->",
"recordid",
"=",
"$",
"this",
"->",
"assignment",
"->",
"get_uniqueid_for_user",
"(",
"$",
"row",
"->",
"userid",
")",
";",
"}",
"return",
"get_string",
"(",
"'hiddenuser'",
",",
"'assign'",
")",
".",
"$",
"row",
"->",
"recordid",
";",
"}"
] |
Add a column with an ID that uniquely identifies this user in this assignment.
@param stdClass $row
@return string
|
[
"Add",
"a",
"column",
"with",
"an",
"ID",
"that",
"uniquely",
"identifies",
"this",
"user",
"in",
"this",
"assignment",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/gradingtable.php#L553-L558
|
218,885
|
moodle/moodle
|
mod/assign/gradingtable.php
|
assign_grading_table.col_workflowstatus
|
public function col_workflowstatus(stdClass $row) {
$o = '';
$gradingdisabled = $this->assignment->grading_disabled($row->id);
// The function in the assignment keeps a static cache of this list of states.
$workflowstates = $this->assignment->get_marking_workflow_states_for_current_user();
$workflowstate = $row->workflowstate;
if (empty($workflowstate)) {
$workflowstate = ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED;
}
if ($this->quickgrading && !$gradingdisabled) {
$notmarked = get_string('markingworkflowstatenotmarked', 'assign');
$name = 'quickgrade_' . $row->id . '_workflowstate';
$o .= html_writer::select($workflowstates, $name, $workflowstate, array('' => $notmarked));
// Check if this user is a marker that can't manage allocations and doesn't have the marker column added.
if ($this->assignment->get_instance()->markingworkflow &&
$this->assignment->get_instance()->markingallocation &&
!has_capability('mod/assign:manageallocations', $this->assignment->get_context())) {
$name = 'quickgrade_' . $row->id . '_allocatedmarker';
$o .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $name,
'value' => $row->allocatedmarker));
}
} else {
$o .= $this->output->container(get_string('markingworkflowstate' . $workflowstate, 'assign'), $workflowstate);
}
return $o;
}
|
php
|
public function col_workflowstatus(stdClass $row) {
$o = '';
$gradingdisabled = $this->assignment->grading_disabled($row->id);
// The function in the assignment keeps a static cache of this list of states.
$workflowstates = $this->assignment->get_marking_workflow_states_for_current_user();
$workflowstate = $row->workflowstate;
if (empty($workflowstate)) {
$workflowstate = ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED;
}
if ($this->quickgrading && !$gradingdisabled) {
$notmarked = get_string('markingworkflowstatenotmarked', 'assign');
$name = 'quickgrade_' . $row->id . '_workflowstate';
$o .= html_writer::select($workflowstates, $name, $workflowstate, array('' => $notmarked));
// Check if this user is a marker that can't manage allocations and doesn't have the marker column added.
if ($this->assignment->get_instance()->markingworkflow &&
$this->assignment->get_instance()->markingallocation &&
!has_capability('mod/assign:manageallocations', $this->assignment->get_context())) {
$name = 'quickgrade_' . $row->id . '_allocatedmarker';
$o .= html_writer::empty_tag('input', array('type' => 'hidden', 'name' => $name,
'value' => $row->allocatedmarker));
}
} else {
$o .= $this->output->container(get_string('markingworkflowstate' . $workflowstate, 'assign'), $workflowstate);
}
return $o;
}
|
[
"public",
"function",
"col_workflowstatus",
"(",
"stdClass",
"$",
"row",
")",
"{",
"$",
"o",
"=",
"''",
";",
"$",
"gradingdisabled",
"=",
"$",
"this",
"->",
"assignment",
"->",
"grading_disabled",
"(",
"$",
"row",
"->",
"id",
")",
";",
"// The function in the assignment keeps a static cache of this list of states.",
"$",
"workflowstates",
"=",
"$",
"this",
"->",
"assignment",
"->",
"get_marking_workflow_states_for_current_user",
"(",
")",
";",
"$",
"workflowstate",
"=",
"$",
"row",
"->",
"workflowstate",
";",
"if",
"(",
"empty",
"(",
"$",
"workflowstate",
")",
")",
"{",
"$",
"workflowstate",
"=",
"ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"quickgrading",
"&&",
"!",
"$",
"gradingdisabled",
")",
"{",
"$",
"notmarked",
"=",
"get_string",
"(",
"'markingworkflowstatenotmarked'",
",",
"'assign'",
")",
";",
"$",
"name",
"=",
"'quickgrade_'",
".",
"$",
"row",
"->",
"id",
".",
"'_workflowstate'",
";",
"$",
"o",
".=",
"html_writer",
"::",
"select",
"(",
"$",
"workflowstates",
",",
"$",
"name",
",",
"$",
"workflowstate",
",",
"array",
"(",
"''",
"=>",
"$",
"notmarked",
")",
")",
";",
"// Check if this user is a marker that can't manage allocations and doesn't have the marker column added.",
"if",
"(",
"$",
"this",
"->",
"assignment",
"->",
"get_instance",
"(",
")",
"->",
"markingworkflow",
"&&",
"$",
"this",
"->",
"assignment",
"->",
"get_instance",
"(",
")",
"->",
"markingallocation",
"&&",
"!",
"has_capability",
"(",
"'mod/assign:manageallocations'",
",",
"$",
"this",
"->",
"assignment",
"->",
"get_context",
"(",
")",
")",
")",
"{",
"$",
"name",
"=",
"'quickgrade_'",
".",
"$",
"row",
"->",
"id",
".",
"'_allocatedmarker'",
";",
"$",
"o",
".=",
"html_writer",
"::",
"empty_tag",
"(",
"'input'",
",",
"array",
"(",
"'type'",
"=>",
"'hidden'",
",",
"'name'",
"=>",
"$",
"name",
",",
"'value'",
"=>",
"$",
"row",
"->",
"allocatedmarker",
")",
")",
";",
"}",
"}",
"else",
"{",
"$",
"o",
".=",
"$",
"this",
"->",
"output",
"->",
"container",
"(",
"get_string",
"(",
"'markingworkflowstate'",
".",
"$",
"workflowstate",
",",
"'assign'",
")",
",",
"$",
"workflowstate",
")",
";",
"}",
"return",
"$",
"o",
";",
"}"
] |
list current marking workflow state
@param stdClass $row
@return string
|
[
"list",
"current",
"marking",
"workflow",
"state"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/gradingtable.php#L586-L613
|
218,886
|
moodle/moodle
|
mod/assign/gradingtable.php
|
assign_grading_table.col_workflowstate
|
public function col_workflowstate($row) {
$state = $row->workflowstate;
if (empty($state)) {
$state = ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED;
}
return get_string('markingworkflowstate' . $state, 'assign');
}
|
php
|
public function col_workflowstate($row) {
$state = $row->workflowstate;
if (empty($state)) {
$state = ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED;
}
return get_string('markingworkflowstate' . $state, 'assign');
}
|
[
"public",
"function",
"col_workflowstate",
"(",
"$",
"row",
")",
"{",
"$",
"state",
"=",
"$",
"row",
"->",
"workflowstate",
";",
"if",
"(",
"empty",
"(",
"$",
"state",
")",
")",
"{",
"$",
"state",
"=",
"ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED",
";",
"}",
"return",
"get_string",
"(",
"'markingworkflowstate'",
".",
"$",
"state",
",",
"'assign'",
")",
";",
"}"
] |
For download only - list current marking workflow state
@param stdClass $row - The row of data
@return string The current marking workflow state
|
[
"For",
"download",
"only",
"-",
"list",
"current",
"marking",
"workflow",
"state"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/gradingtable.php#L621-L628
|
218,887
|
moodle/moodle
|
mod/assign/gradingtable.php
|
assign_grading_table.col_allocatedmarker
|
public function col_allocatedmarker(stdClass $row) {
static $markers = null;
static $markerlist = array();
if ($markers === null) {
list($sort, $params) = users_order_by_sql('u');
// Only enrolled users could be assigned as potential markers.
$markers = get_enrolled_users($this->assignment->get_context(), 'mod/assign:grade', 0, 'u.*', $sort);
$markerlist[0] = get_string('choosemarker', 'assign');
$viewfullnames = has_capability('moodle/site:viewfullnames', $this->assignment->get_context());
foreach ($markers as $marker) {
$markerlist[$marker->id] = fullname($marker, $viewfullnames);
}
}
if (empty($markerlist)) {
// TODO: add some form of notification here that no markers are available.
return '';
}
if ($this->is_downloading()) {
if (isset($markers[$row->allocatedmarker])) {
return fullname($markers[$row->allocatedmarker],
has_capability('moodle/site:viewfullnames', $this->assignment->get_context()));
} else {
return '';
}
}
if ($this->quickgrading && has_capability('mod/assign:manageallocations', $this->assignment->get_context()) &&
(empty($row->workflowstate) ||
$row->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_INMARKING ||
$row->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED)) {
$name = 'quickgrade_' . $row->id . '_allocatedmarker';
return html_writer::select($markerlist, $name, $row->allocatedmarker, false);
} else if (!empty($row->allocatedmarker)) {
$output = '';
if ($this->quickgrading) { // Add hidden field for quickgrading page.
$name = 'quickgrade_' . $row->id . '_allocatedmarker';
$attributes = ['type' => 'hidden', 'name' => $name, 'value' => $row->allocatedmarker];
$output .= html_writer::empty_tag('input', $attributes);
}
$output .= $markerlist[$row->allocatedmarker];
return $output;
}
}
|
php
|
public function col_allocatedmarker(stdClass $row) {
static $markers = null;
static $markerlist = array();
if ($markers === null) {
list($sort, $params) = users_order_by_sql('u');
// Only enrolled users could be assigned as potential markers.
$markers = get_enrolled_users($this->assignment->get_context(), 'mod/assign:grade', 0, 'u.*', $sort);
$markerlist[0] = get_string('choosemarker', 'assign');
$viewfullnames = has_capability('moodle/site:viewfullnames', $this->assignment->get_context());
foreach ($markers as $marker) {
$markerlist[$marker->id] = fullname($marker, $viewfullnames);
}
}
if (empty($markerlist)) {
// TODO: add some form of notification here that no markers are available.
return '';
}
if ($this->is_downloading()) {
if (isset($markers[$row->allocatedmarker])) {
return fullname($markers[$row->allocatedmarker],
has_capability('moodle/site:viewfullnames', $this->assignment->get_context()));
} else {
return '';
}
}
if ($this->quickgrading && has_capability('mod/assign:manageallocations', $this->assignment->get_context()) &&
(empty($row->workflowstate) ||
$row->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_INMARKING ||
$row->workflowstate == ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED)) {
$name = 'quickgrade_' . $row->id . '_allocatedmarker';
return html_writer::select($markerlist, $name, $row->allocatedmarker, false);
} else if (!empty($row->allocatedmarker)) {
$output = '';
if ($this->quickgrading) { // Add hidden field for quickgrading page.
$name = 'quickgrade_' . $row->id . '_allocatedmarker';
$attributes = ['type' => 'hidden', 'name' => $name, 'value' => $row->allocatedmarker];
$output .= html_writer::empty_tag('input', $attributes);
}
$output .= $markerlist[$row->allocatedmarker];
return $output;
}
}
|
[
"public",
"function",
"col_allocatedmarker",
"(",
"stdClass",
"$",
"row",
")",
"{",
"static",
"$",
"markers",
"=",
"null",
";",
"static",
"$",
"markerlist",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"markers",
"===",
"null",
")",
"{",
"list",
"(",
"$",
"sort",
",",
"$",
"params",
")",
"=",
"users_order_by_sql",
"(",
"'u'",
")",
";",
"// Only enrolled users could be assigned as potential markers.",
"$",
"markers",
"=",
"get_enrolled_users",
"(",
"$",
"this",
"->",
"assignment",
"->",
"get_context",
"(",
")",
",",
"'mod/assign:grade'",
",",
"0",
",",
"'u.*'",
",",
"$",
"sort",
")",
";",
"$",
"markerlist",
"[",
"0",
"]",
"=",
"get_string",
"(",
"'choosemarker'",
",",
"'assign'",
")",
";",
"$",
"viewfullnames",
"=",
"has_capability",
"(",
"'moodle/site:viewfullnames'",
",",
"$",
"this",
"->",
"assignment",
"->",
"get_context",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"markers",
"as",
"$",
"marker",
")",
"{",
"$",
"markerlist",
"[",
"$",
"marker",
"->",
"id",
"]",
"=",
"fullname",
"(",
"$",
"marker",
",",
"$",
"viewfullnames",
")",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"markerlist",
")",
")",
"{",
"// TODO: add some form of notification here that no markers are available.",
"return",
"''",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"is_downloading",
"(",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"markers",
"[",
"$",
"row",
"->",
"allocatedmarker",
"]",
")",
")",
"{",
"return",
"fullname",
"(",
"$",
"markers",
"[",
"$",
"row",
"->",
"allocatedmarker",
"]",
",",
"has_capability",
"(",
"'moodle/site:viewfullnames'",
",",
"$",
"this",
"->",
"assignment",
"->",
"get_context",
"(",
")",
")",
")",
";",
"}",
"else",
"{",
"return",
"''",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"quickgrading",
"&&",
"has_capability",
"(",
"'mod/assign:manageallocations'",
",",
"$",
"this",
"->",
"assignment",
"->",
"get_context",
"(",
")",
")",
"&&",
"(",
"empty",
"(",
"$",
"row",
"->",
"workflowstate",
")",
"||",
"$",
"row",
"->",
"workflowstate",
"==",
"ASSIGN_MARKING_WORKFLOW_STATE_INMARKING",
"||",
"$",
"row",
"->",
"workflowstate",
"==",
"ASSIGN_MARKING_WORKFLOW_STATE_NOTMARKED",
")",
")",
"{",
"$",
"name",
"=",
"'quickgrade_'",
".",
"$",
"row",
"->",
"id",
".",
"'_allocatedmarker'",
";",
"return",
"html_writer",
"::",
"select",
"(",
"$",
"markerlist",
",",
"$",
"name",
",",
"$",
"row",
"->",
"allocatedmarker",
",",
"false",
")",
";",
"}",
"else",
"if",
"(",
"!",
"empty",
"(",
"$",
"row",
"->",
"allocatedmarker",
")",
")",
"{",
"$",
"output",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"quickgrading",
")",
"{",
"// Add hidden field for quickgrading page.",
"$",
"name",
"=",
"'quickgrade_'",
".",
"$",
"row",
"->",
"id",
".",
"'_allocatedmarker'",
";",
"$",
"attributes",
"=",
"[",
"'type'",
"=>",
"'hidden'",
",",
"'name'",
"=>",
"$",
"name",
",",
"'value'",
"=>",
"$",
"row",
"->",
"allocatedmarker",
"]",
";",
"$",
"output",
".=",
"html_writer",
"::",
"empty_tag",
"(",
"'input'",
",",
"$",
"attributes",
")",
";",
"}",
"$",
"output",
".=",
"$",
"markerlist",
"[",
"$",
"row",
"->",
"allocatedmarker",
"]",
";",
"return",
"$",
"output",
";",
"}",
"}"
] |
list current marker
@param stdClass $row - The row of data
@return id the user->id of the marker.
|
[
"list",
"current",
"marker"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/gradingtable.php#L636-L679
|
218,888
|
moodle/moodle
|
mod/assign/gradingtable.php
|
assign_grading_table.col_scale
|
public function col_scale($row) {
global $DB;
if (empty($this->scale)) {
$dbparams = array('id' => -($this->assignment->get_instance()->grade));
$this->scale = $DB->get_record('scale', $dbparams);
}
if (!empty($this->scale->scale)) {
return implode("\n", explode(',', $this->scale->scale));
}
return '';
}
|
php
|
public function col_scale($row) {
global $DB;
if (empty($this->scale)) {
$dbparams = array('id' => -($this->assignment->get_instance()->grade));
$this->scale = $DB->get_record('scale', $dbparams);
}
if (!empty($this->scale->scale)) {
return implode("\n", explode(',', $this->scale->scale));
}
return '';
}
|
[
"public",
"function",
"col_scale",
"(",
"$",
"row",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"scale",
")",
")",
"{",
"$",
"dbparams",
"=",
"array",
"(",
"'id'",
"=>",
"-",
"(",
"$",
"this",
"->",
"assignment",
"->",
"get_instance",
"(",
")",
"->",
"grade",
")",
")",
";",
"$",
"this",
"->",
"scale",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'scale'",
",",
"$",
"dbparams",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"scale",
"->",
"scale",
")",
")",
"{",
"return",
"implode",
"(",
"\"\\n\"",
",",
"explode",
"(",
"','",
",",
"$",
"this",
"->",
"scale",
"->",
"scale",
")",
")",
";",
"}",
"return",
"''",
";",
"}"
] |
For download only - list all the valid options for this custom scale.
@param stdClass $row - The row of data
@return string A list of valid options for the current scale
|
[
"For",
"download",
"only",
"-",
"list",
"all",
"the",
"valid",
"options",
"for",
"this",
"custom",
"scale",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/gradingtable.php#L686-L698
|
218,889
|
moodle/moodle
|
mod/assign/gradingtable.php
|
assign_grading_table.display_grade
|
public function display_grade($grade, $editable, $userid, $modified) {
if ($this->is_downloading()) {
if ($this->assignment->get_instance()->grade >= 0) {
if ($grade == -1 || $grade === null) {
return '';
}
$gradeitem = $this->assignment->get_grade_item();
return format_float($grade, $gradeitem->get_decimals());
} else {
// This is a custom scale.
$scale = $this->assignment->display_grade($grade, false);
if ($scale == '-') {
$scale = '';
}
return $scale;
}
}
return $this->assignment->display_grade($grade, $editable, $userid, $modified);
}
|
php
|
public function display_grade($grade, $editable, $userid, $modified) {
if ($this->is_downloading()) {
if ($this->assignment->get_instance()->grade >= 0) {
if ($grade == -1 || $grade === null) {
return '';
}
$gradeitem = $this->assignment->get_grade_item();
return format_float($grade, $gradeitem->get_decimals());
} else {
// This is a custom scale.
$scale = $this->assignment->display_grade($grade, false);
if ($scale == '-') {
$scale = '';
}
return $scale;
}
}
return $this->assignment->display_grade($grade, $editable, $userid, $modified);
}
|
[
"public",
"function",
"display_grade",
"(",
"$",
"grade",
",",
"$",
"editable",
",",
"$",
"userid",
",",
"$",
"modified",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"is_downloading",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"assignment",
"->",
"get_instance",
"(",
")",
"->",
"grade",
">=",
"0",
")",
"{",
"if",
"(",
"$",
"grade",
"==",
"-",
"1",
"||",
"$",
"grade",
"===",
"null",
")",
"{",
"return",
"''",
";",
"}",
"$",
"gradeitem",
"=",
"$",
"this",
"->",
"assignment",
"->",
"get_grade_item",
"(",
")",
";",
"return",
"format_float",
"(",
"$",
"grade",
",",
"$",
"gradeitem",
"->",
"get_decimals",
"(",
")",
")",
";",
"}",
"else",
"{",
"// This is a custom scale.",
"$",
"scale",
"=",
"$",
"this",
"->",
"assignment",
"->",
"display_grade",
"(",
"$",
"grade",
",",
"false",
")",
";",
"if",
"(",
"$",
"scale",
"==",
"'-'",
")",
"{",
"$",
"scale",
"=",
"''",
";",
"}",
"return",
"$",
"scale",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"assignment",
"->",
"display_grade",
"(",
"$",
"grade",
",",
"$",
"editable",
",",
"$",
"userid",
",",
"$",
"modified",
")",
";",
"}"
] |
Display a grade with scales etc.
@param string $grade
@param boolean $editable
@param int $userid The user id of the user this grade belongs to
@param int $modified Timestamp showing when the grade was last modified
@return string The formatted grade
|
[
"Display",
"a",
"grade",
"with",
"scales",
"etc",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/gradingtable.php#L709-L727
|
218,890
|
moodle/moodle
|
mod/assign/gradingtable.php
|
assign_grading_table.col_team
|
public function col_team(stdClass $row) {
$submission = false;
$group = false;
$this->get_group_and_submission($row->id, $group, $submission, -1);
if ($group) {
return $group->name;
} else if ($this->assignment->get_instance()->preventsubmissionnotingroup) {
$usergroups = $this->assignment->get_all_groups($row->id);
if (count($usergroups) > 1) {
return get_string('multipleteamsgrader', 'assign');
} else {
return get_string('noteamgrader', 'assign');
}
}
return get_string('defaultteam', 'assign');
}
|
php
|
public function col_team(stdClass $row) {
$submission = false;
$group = false;
$this->get_group_and_submission($row->id, $group, $submission, -1);
if ($group) {
return $group->name;
} else if ($this->assignment->get_instance()->preventsubmissionnotingroup) {
$usergroups = $this->assignment->get_all_groups($row->id);
if (count($usergroups) > 1) {
return get_string('multipleteamsgrader', 'assign');
} else {
return get_string('noteamgrader', 'assign');
}
}
return get_string('defaultteam', 'assign');
}
|
[
"public",
"function",
"col_team",
"(",
"stdClass",
"$",
"row",
")",
"{",
"$",
"submission",
"=",
"false",
";",
"$",
"group",
"=",
"false",
";",
"$",
"this",
"->",
"get_group_and_submission",
"(",
"$",
"row",
"->",
"id",
",",
"$",
"group",
",",
"$",
"submission",
",",
"-",
"1",
")",
";",
"if",
"(",
"$",
"group",
")",
"{",
"return",
"$",
"group",
"->",
"name",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"assignment",
"->",
"get_instance",
"(",
")",
"->",
"preventsubmissionnotingroup",
")",
"{",
"$",
"usergroups",
"=",
"$",
"this",
"->",
"assignment",
"->",
"get_all_groups",
"(",
"$",
"row",
"->",
"id",
")",
";",
"if",
"(",
"count",
"(",
"$",
"usergroups",
")",
">",
"1",
")",
"{",
"return",
"get_string",
"(",
"'multipleteamsgrader'",
",",
"'assign'",
")",
";",
"}",
"else",
"{",
"return",
"get_string",
"(",
"'noteamgrader'",
",",
"'assign'",
")",
";",
"}",
"}",
"return",
"get_string",
"(",
"'defaultteam'",
",",
"'assign'",
")",
";",
"}"
] |
Get the team info for this user.
@param stdClass $row
@return string The team name
|
[
"Get",
"the",
"team",
"info",
"for",
"this",
"user",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/gradingtable.php#L735-L750
|
218,891
|
moodle/moodle
|
mod/assign/gradingtable.php
|
assign_grading_table.get_group_and_submission
|
protected function get_group_and_submission($userid, &$group, &$submission, $attemptnumber) {
$group = false;
if (isset($this->submissiongroups[$userid])) {
$group = $this->submissiongroups[$userid];
} else {
$group = $this->assignment->get_submission_group($userid, false);
$this->submissiongroups[$userid] = $group;
}
$groupid = 0;
if ($group) {
$groupid = $group->id;
}
// Static cache is keyed by groupid and attemptnumber.
// We may need both the latest and previous attempt in the same page.
if (isset($this->groupsubmissions[$groupid . ':' . $attemptnumber])) {
$submission = $this->groupsubmissions[$groupid . ':' . $attemptnumber];
} else {
$submission = $this->assignment->get_group_submission($userid, $groupid, false, $attemptnumber);
$this->groupsubmissions[$groupid . ':' . $attemptnumber] = $submission;
}
}
|
php
|
protected function get_group_and_submission($userid, &$group, &$submission, $attemptnumber) {
$group = false;
if (isset($this->submissiongroups[$userid])) {
$group = $this->submissiongroups[$userid];
} else {
$group = $this->assignment->get_submission_group($userid, false);
$this->submissiongroups[$userid] = $group;
}
$groupid = 0;
if ($group) {
$groupid = $group->id;
}
// Static cache is keyed by groupid and attemptnumber.
// We may need both the latest and previous attempt in the same page.
if (isset($this->groupsubmissions[$groupid . ':' . $attemptnumber])) {
$submission = $this->groupsubmissions[$groupid . ':' . $attemptnumber];
} else {
$submission = $this->assignment->get_group_submission($userid, $groupid, false, $attemptnumber);
$this->groupsubmissions[$groupid . ':' . $attemptnumber] = $submission;
}
}
|
[
"protected",
"function",
"get_group_and_submission",
"(",
"$",
"userid",
",",
"&",
"$",
"group",
",",
"&",
"$",
"submission",
",",
"$",
"attemptnumber",
")",
"{",
"$",
"group",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"submissiongroups",
"[",
"$",
"userid",
"]",
")",
")",
"{",
"$",
"group",
"=",
"$",
"this",
"->",
"submissiongroups",
"[",
"$",
"userid",
"]",
";",
"}",
"else",
"{",
"$",
"group",
"=",
"$",
"this",
"->",
"assignment",
"->",
"get_submission_group",
"(",
"$",
"userid",
",",
"false",
")",
";",
"$",
"this",
"->",
"submissiongroups",
"[",
"$",
"userid",
"]",
"=",
"$",
"group",
";",
"}",
"$",
"groupid",
"=",
"0",
";",
"if",
"(",
"$",
"group",
")",
"{",
"$",
"groupid",
"=",
"$",
"group",
"->",
"id",
";",
"}",
"// Static cache is keyed by groupid and attemptnumber.",
"// We may need both the latest and previous attempt in the same page.",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"groupsubmissions",
"[",
"$",
"groupid",
".",
"':'",
".",
"$",
"attemptnumber",
"]",
")",
")",
"{",
"$",
"submission",
"=",
"$",
"this",
"->",
"groupsubmissions",
"[",
"$",
"groupid",
".",
"':'",
".",
"$",
"attemptnumber",
"]",
";",
"}",
"else",
"{",
"$",
"submission",
"=",
"$",
"this",
"->",
"assignment",
"->",
"get_group_submission",
"(",
"$",
"userid",
",",
"$",
"groupid",
",",
"false",
",",
"$",
"attemptnumber",
")",
";",
"$",
"this",
"->",
"groupsubmissions",
"[",
"$",
"groupid",
".",
"':'",
".",
"$",
"attemptnumber",
"]",
"=",
"$",
"submission",
";",
"}",
"}"
] |
Use a static cache to try and reduce DB calls.
@param int $userid The user id for this submission
@param int $group The groupid (returned)
@param stdClass|false $submission The stdClass submission or false (returned)
@param int $attemptnumber Return a specific attempt number (-1 for latest)
|
[
"Use",
"a",
"static",
"cache",
"to",
"try",
"and",
"reduce",
"DB",
"calls",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/gradingtable.php#L760-L782
|
218,892
|
moodle/moodle
|
mod/assign/gradingtable.php
|
assign_grading_table.col_outcomes
|
public function col_outcomes(stdClass $row) {
$outcomes = '';
foreach ($this->gradinginfo->outcomes as $index => $outcome) {
$options = make_grades_menu(-$outcome->scaleid);
$options[0] = get_string('nooutcome', 'grades');
if ($this->quickgrading && !($outcome->grades[$row->userid]->locked)) {
$select = '<select name="outcome_' . $index . '_' . $row->userid . '" class="quickgrade">';
foreach ($options as $optionindex => $optionvalue) {
$selected = '';
if ($outcome->grades[$row->userid]->grade == $optionindex) {
$selected = 'selected="selected"';
}
$select .= '<option value="' . $optionindex . '"' . $selected . '>' . $optionvalue . '</option>';
}
$select .= '</select>';
$outcomes .= $this->output->container($outcome->name . ': ' . $select, 'outcome');
} else {
$name = $outcome->name . ': ' . $options[$outcome->grades[$row->userid]->grade];
if ($this->is_downloading()) {
$outcomes .= $name;
} else {
$outcomes .= $this->output->container($name, 'outcome');
}
}
}
return $outcomes;
}
|
php
|
public function col_outcomes(stdClass $row) {
$outcomes = '';
foreach ($this->gradinginfo->outcomes as $index => $outcome) {
$options = make_grades_menu(-$outcome->scaleid);
$options[0] = get_string('nooutcome', 'grades');
if ($this->quickgrading && !($outcome->grades[$row->userid]->locked)) {
$select = '<select name="outcome_' . $index . '_' . $row->userid . '" class="quickgrade">';
foreach ($options as $optionindex => $optionvalue) {
$selected = '';
if ($outcome->grades[$row->userid]->grade == $optionindex) {
$selected = 'selected="selected"';
}
$select .= '<option value="' . $optionindex . '"' . $selected . '>' . $optionvalue . '</option>';
}
$select .= '</select>';
$outcomes .= $this->output->container($outcome->name . ': ' . $select, 'outcome');
} else {
$name = $outcome->name . ': ' . $options[$outcome->grades[$row->userid]->grade];
if ($this->is_downloading()) {
$outcomes .= $name;
} else {
$outcomes .= $this->output->container($name, 'outcome');
}
}
}
return $outcomes;
}
|
[
"public",
"function",
"col_outcomes",
"(",
"stdClass",
"$",
"row",
")",
"{",
"$",
"outcomes",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"gradinginfo",
"->",
"outcomes",
"as",
"$",
"index",
"=>",
"$",
"outcome",
")",
"{",
"$",
"options",
"=",
"make_grades_menu",
"(",
"-",
"$",
"outcome",
"->",
"scaleid",
")",
";",
"$",
"options",
"[",
"0",
"]",
"=",
"get_string",
"(",
"'nooutcome'",
",",
"'grades'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"quickgrading",
"&&",
"!",
"(",
"$",
"outcome",
"->",
"grades",
"[",
"$",
"row",
"->",
"userid",
"]",
"->",
"locked",
")",
")",
"{",
"$",
"select",
"=",
"'<select name=\"outcome_'",
".",
"$",
"index",
".",
"'_'",
".",
"$",
"row",
"->",
"userid",
".",
"'\" class=\"quickgrade\">'",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"optionindex",
"=>",
"$",
"optionvalue",
")",
"{",
"$",
"selected",
"=",
"''",
";",
"if",
"(",
"$",
"outcome",
"->",
"grades",
"[",
"$",
"row",
"->",
"userid",
"]",
"->",
"grade",
"==",
"$",
"optionindex",
")",
"{",
"$",
"selected",
"=",
"'selected=\"selected\"'",
";",
"}",
"$",
"select",
".=",
"'<option value=\"'",
".",
"$",
"optionindex",
".",
"'\"'",
".",
"$",
"selected",
".",
"'>'",
".",
"$",
"optionvalue",
".",
"'</option>'",
";",
"}",
"$",
"select",
".=",
"'</select>'",
";",
"$",
"outcomes",
".=",
"$",
"this",
"->",
"output",
"->",
"container",
"(",
"$",
"outcome",
"->",
"name",
".",
"': '",
".",
"$",
"select",
",",
"'outcome'",
")",
";",
"}",
"else",
"{",
"$",
"name",
"=",
"$",
"outcome",
"->",
"name",
".",
"': '",
".",
"$",
"options",
"[",
"$",
"outcome",
"->",
"grades",
"[",
"$",
"row",
"->",
"userid",
"]",
"->",
"grade",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"is_downloading",
"(",
")",
")",
"{",
"$",
"outcomes",
".=",
"$",
"name",
";",
"}",
"else",
"{",
"$",
"outcomes",
".=",
"$",
"this",
"->",
"output",
"->",
"container",
"(",
"$",
"name",
",",
"'outcome'",
")",
";",
"}",
"}",
"}",
"return",
"$",
"outcomes",
";",
"}"
] |
Format a list of outcomes.
@param stdClass $row
@return string
|
[
"Format",
"a",
"list",
"of",
"outcomes",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/gradingtable.php#L790-L818
|
218,893
|
moodle/moodle
|
mod/assign/gradingtable.php
|
assign_grading_table.col_select
|
public function col_select(stdClass $row) {
$selectcol = '<label class="accesshide" for="selectuser_' . $row->userid . '">';
$selectcol .= get_string('selectuser', 'assign', $this->assignment->fullname($row));
$selectcol .= '</label>';
$selectcol .= '<input type="checkbox"
id="selectuser_' . $row->userid . '"
name="selectedusers"
value="' . $row->userid . '"/>';
$selectcol .= '<input type="hidden"
name="grademodified_' . $row->userid . '"
value="' . $row->timemarked . '"/>';
$selectcol .= '<input type="hidden"
name="gradeattempt_' . $row->userid . '"
value="' . $row->attemptnumber . '"/>';
return $selectcol;
}
|
php
|
public function col_select(stdClass $row) {
$selectcol = '<label class="accesshide" for="selectuser_' . $row->userid . '">';
$selectcol .= get_string('selectuser', 'assign', $this->assignment->fullname($row));
$selectcol .= '</label>';
$selectcol .= '<input type="checkbox"
id="selectuser_' . $row->userid . '"
name="selectedusers"
value="' . $row->userid . '"/>';
$selectcol .= '<input type="hidden"
name="grademodified_' . $row->userid . '"
value="' . $row->timemarked . '"/>';
$selectcol .= '<input type="hidden"
name="gradeattempt_' . $row->userid . '"
value="' . $row->attemptnumber . '"/>';
return $selectcol;
}
|
[
"public",
"function",
"col_select",
"(",
"stdClass",
"$",
"row",
")",
"{",
"$",
"selectcol",
"=",
"'<label class=\"accesshide\" for=\"selectuser_'",
".",
"$",
"row",
"->",
"userid",
".",
"'\">'",
";",
"$",
"selectcol",
".=",
"get_string",
"(",
"'selectuser'",
",",
"'assign'",
",",
"$",
"this",
"->",
"assignment",
"->",
"fullname",
"(",
"$",
"row",
")",
")",
";",
"$",
"selectcol",
".=",
"'</label>'",
";",
"$",
"selectcol",
".=",
"'<input type=\"checkbox\"\n id=\"selectuser_'",
".",
"$",
"row",
"->",
"userid",
".",
"'\"\n name=\"selectedusers\"\n value=\"'",
".",
"$",
"row",
"->",
"userid",
".",
"'\"/>'",
";",
"$",
"selectcol",
".=",
"'<input type=\"hidden\"\n name=\"grademodified_'",
".",
"$",
"row",
"->",
"userid",
".",
"'\"\n value=\"'",
".",
"$",
"row",
"->",
"timemarked",
".",
"'\"/>'",
";",
"$",
"selectcol",
".=",
"'<input type=\"hidden\"\n name=\"gradeattempt_'",
".",
"$",
"row",
"->",
"userid",
".",
"'\"\n value=\"'",
".",
"$",
"row",
"->",
"attemptnumber",
".",
"'\"/>'",
";",
"return",
"$",
"selectcol",
";",
"}"
] |
Insert a checkbox for selecting the current row for batch operations.
@param stdClass $row
@return string
|
[
"Insert",
"a",
"checkbox",
"for",
"selecting",
"the",
"current",
"row",
"for",
"batch",
"operations",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/gradingtable.php#L860-L875
|
218,894
|
moodle/moodle
|
mod/assign/gradingtable.php
|
assign_grading_table.get_gradebook_data_for_user
|
private function get_gradebook_data_for_user($userid) {
if (isset($this->gradinginfo->items[0]) && $this->gradinginfo->items[0]->grades[$userid]) {
return $this->gradinginfo->items[0]->grades[$userid];
}
return false;
}
|
php
|
private function get_gradebook_data_for_user($userid) {
if (isset($this->gradinginfo->items[0]) && $this->gradinginfo->items[0]->grades[$userid]) {
return $this->gradinginfo->items[0]->grades[$userid];
}
return false;
}
|
[
"private",
"function",
"get_gradebook_data_for_user",
"(",
"$",
"userid",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"gradinginfo",
"->",
"items",
"[",
"0",
"]",
")",
"&&",
"$",
"this",
"->",
"gradinginfo",
"->",
"items",
"[",
"0",
"]",
"->",
"grades",
"[",
"$",
"userid",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"gradinginfo",
"->",
"items",
"[",
"0",
"]",
"->",
"grades",
"[",
"$",
"userid",
"]",
";",
"}",
"return",
"false",
";",
"}"
] |
Return a users grades from the listing of all grade data for this assignment.
@param int $userid
@return mixed stdClass or false
|
[
"Return",
"a",
"users",
"grades",
"from",
"the",
"listing",
"of",
"all",
"grade",
"data",
"for",
"this",
"assignment",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/gradingtable.php#L883-L888
|
218,895
|
moodle/moodle
|
mod/assign/gradingtable.php
|
assign_grading_table.get_column_data
|
public function get_column_data($columnname) {
$this->setup();
$this->currpage = 0;
$this->query_db($this->tablemaxrows);
$result = array();
foreach ($this->rawdata as $row) {
$result[] = $row->$columnname;
}
return $result;
}
|
php
|
public function get_column_data($columnname) {
$this->setup();
$this->currpage = 0;
$this->query_db($this->tablemaxrows);
$result = array();
foreach ($this->rawdata as $row) {
$result[] = $row->$columnname;
}
return $result;
}
|
[
"public",
"function",
"get_column_data",
"(",
"$",
"columnname",
")",
"{",
"$",
"this",
"->",
"setup",
"(",
")",
";",
"$",
"this",
"->",
"currpage",
"=",
"0",
";",
"$",
"this",
"->",
"query_db",
"(",
"$",
"this",
"->",
"tablemaxrows",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"rawdata",
"as",
"$",
"row",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"row",
"->",
"$",
"columnname",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Using the current filtering and sorting - load all rows and return a single column from them.
@param string $columnname The name of the raw column data
@return array of data
|
[
"Using",
"the",
"current",
"filtering",
"and",
"sorting",
"-",
"load",
"all",
"rows",
"and",
"return",
"a",
"single",
"column",
"from",
"them",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/gradingtable.php#L1516-L1525
|
218,896
|
moodle/moodle
|
mod/assign/gradingtable.php
|
assign_grading_table.get_sort_columns
|
public function get_sort_columns() {
$result = parent::get_sort_columns();
$assignment = $this->assignment->get_instance();
if (empty($assignment->blindmarking)) {
$result = array_merge($result, array('userid' => SORT_ASC));
} else {
$result = array_merge($result, [
'COALESCE(s.timecreated, ' . time() . ')' => SORT_ASC,
'COALESCE(s.id, ' . PHP_INT_MAX . ')' => SORT_ASC,
'um.id' => SORT_ASC,
]);
}
return $result;
}
|
php
|
public function get_sort_columns() {
$result = parent::get_sort_columns();
$assignment = $this->assignment->get_instance();
if (empty($assignment->blindmarking)) {
$result = array_merge($result, array('userid' => SORT_ASC));
} else {
$result = array_merge($result, [
'COALESCE(s.timecreated, ' . time() . ')' => SORT_ASC,
'COALESCE(s.id, ' . PHP_INT_MAX . ')' => SORT_ASC,
'um.id' => SORT_ASC,
]);
}
return $result;
}
|
[
"public",
"function",
"get_sort_columns",
"(",
")",
"{",
"$",
"result",
"=",
"parent",
"::",
"get_sort_columns",
"(",
")",
";",
"$",
"assignment",
"=",
"$",
"this",
"->",
"assignment",
"->",
"get_instance",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"assignment",
"->",
"blindmarking",
")",
")",
"{",
"$",
"result",
"=",
"array_merge",
"(",
"$",
"result",
",",
"array",
"(",
"'userid'",
"=>",
"SORT_ASC",
")",
")",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"array_merge",
"(",
"$",
"result",
",",
"[",
"'COALESCE(s.timecreated, '",
".",
"time",
"(",
")",
".",
"')'",
"=>",
"SORT_ASC",
",",
"'COALESCE(s.id, '",
".",
"PHP_INT_MAX",
".",
"')'",
"=>",
"SORT_ASC",
",",
"'um.id'",
"=>",
"SORT_ASC",
",",
"]",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Always return a valid sort - even if the userid column is missing.
@return array column name => SORT_... constant.
|
[
"Always",
"return",
"a",
"valid",
"sort",
"-",
"even",
"if",
"the",
"userid",
"column",
"is",
"missing",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/gradingtable.php#L1587-L1601
|
218,897
|
moodle/moodle
|
mod/assign/gradingtable.php
|
assign_grading_table.show_hide_link
|
protected function show_hide_link($column, $index) {
if ($index > 0 || !$this->hasgrade) {
return parent::show_hide_link($column, $index);
}
return '';
}
|
php
|
protected function show_hide_link($column, $index) {
if ($index > 0 || !$this->hasgrade) {
return parent::show_hide_link($column, $index);
}
return '';
}
|
[
"protected",
"function",
"show_hide_link",
"(",
"$",
"column",
",",
"$",
"index",
")",
"{",
"if",
"(",
"$",
"index",
">",
"0",
"||",
"!",
"$",
"this",
"->",
"hasgrade",
")",
"{",
"return",
"parent",
"::",
"show_hide_link",
"(",
"$",
"column",
",",
"$",
"index",
")",
";",
"}",
"return",
"''",
";",
"}"
] |
Override the table show_hide_link to not show for select column.
@param string $column the column name, index into various names.
@param int $index numerical index of the column.
@return string HTML fragment.
|
[
"Override",
"the",
"table",
"show_hide_link",
"to",
"not",
"show",
"for",
"select",
"column",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/gradingtable.php#L1610-L1615
|
218,898
|
moodle/moodle
|
lib/htmlpurifier/HTMLPurifier/TokenFactory.php
|
HTMLPurifier_TokenFactory.createStart
|
public function createStart($name, $attr = array())
{
$p = clone $this->p_start;
$p->__construct($name, $attr);
return $p;
}
|
php
|
public function createStart($name, $attr = array())
{
$p = clone $this->p_start;
$p->__construct($name, $attr);
return $p;
}
|
[
"public",
"function",
"createStart",
"(",
"$",
"name",
",",
"$",
"attr",
"=",
"array",
"(",
")",
")",
"{",
"$",
"p",
"=",
"clone",
"$",
"this",
"->",
"p_start",
";",
"$",
"p",
"->",
"__construct",
"(",
"$",
"name",
",",
"$",
"attr",
")",
";",
"return",
"$",
"p",
";",
"}"
] |
Creates a HTMLPurifier_Token_Start.
@param string $name Tag name
@param array $attr Associative array of attributes
@return HTMLPurifier_Token_Start Generated HTMLPurifier_Token_Start
|
[
"Creates",
"a",
"HTMLPurifier_Token_Start",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/TokenFactory.php#L61-L66
|
218,899
|
moodle/moodle
|
lib/htmlpurifier/HTMLPurifier/TokenFactory.php
|
HTMLPurifier_TokenFactory.createEmpty
|
public function createEmpty($name, $attr = array())
{
$p = clone $this->p_empty;
$p->__construct($name, $attr);
return $p;
}
|
php
|
public function createEmpty($name, $attr = array())
{
$p = clone $this->p_empty;
$p->__construct($name, $attr);
return $p;
}
|
[
"public",
"function",
"createEmpty",
"(",
"$",
"name",
",",
"$",
"attr",
"=",
"array",
"(",
")",
")",
"{",
"$",
"p",
"=",
"clone",
"$",
"this",
"->",
"p_empty",
";",
"$",
"p",
"->",
"__construct",
"(",
"$",
"name",
",",
"$",
"attr",
")",
";",
"return",
"$",
"p",
";",
"}"
] |
Creates a HTMLPurifier_Token_Empty.
@param string $name Tag name
@param array $attr Associative array of attributes
@return HTMLPurifier_Token_Empty Generated HTMLPurifier_Token_Empty
|
[
"Creates",
"a",
"HTMLPurifier_Token_Empty",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/TokenFactory.php#L86-L91
|
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.