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,300
|
moodle/moodle
|
lib/excellib.class.php
|
MoodleExcelWorkbook.close
|
public function close() {
global $CFG;
foreach ($this->objPHPExcel->getAllSheets() as $sheet){
$sheet->setSelectedCells('A1');
}
$this->objPHPExcel->setActiveSheetIndex(0);
$filename = preg_replace('/\.xlsx?$/i', '', $this->filename);
$mimetype = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
$filename = $filename.'.xlsx';
if (is_https()) { // HTTPS sites - watch out for IE! KB812935 and KB316431.
header('Cache-Control: max-age=10');
header('Expires: '. gmdate('D, d M Y H:i:s', 0) .' GMT');
header('Pragma: ');
} else { //normal http - prevent caching at all cost
header('Cache-Control: private, must-revalidate, pre-check=0, post-check=0, max-age=0');
header('Expires: '. gmdate('D, d M Y H:i:s', 0) .' GMT');
header('Pragma: no-cache');
}
if (core_useragent::is_ie() || core_useragent::is_edge()) {
$filename = rawurlencode($filename);
} else {
$filename = s($filename);
}
header('Content-Type: '.$mimetype);
header('Content-Disposition: attachment;filename="'.$filename.'"');
$objWriter = PHPExcel_IOFactory::createWriter($this->objPHPExcel, $this->type);
$objWriter->save('php://output');
}
|
php
|
public function close() {
global $CFG;
foreach ($this->objPHPExcel->getAllSheets() as $sheet){
$sheet->setSelectedCells('A1');
}
$this->objPHPExcel->setActiveSheetIndex(0);
$filename = preg_replace('/\.xlsx?$/i', '', $this->filename);
$mimetype = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
$filename = $filename.'.xlsx';
if (is_https()) { // HTTPS sites - watch out for IE! KB812935 and KB316431.
header('Cache-Control: max-age=10');
header('Expires: '. gmdate('D, d M Y H:i:s', 0) .' GMT');
header('Pragma: ');
} else { //normal http - prevent caching at all cost
header('Cache-Control: private, must-revalidate, pre-check=0, post-check=0, max-age=0');
header('Expires: '. gmdate('D, d M Y H:i:s', 0) .' GMT');
header('Pragma: no-cache');
}
if (core_useragent::is_ie() || core_useragent::is_edge()) {
$filename = rawurlencode($filename);
} else {
$filename = s($filename);
}
header('Content-Type: '.$mimetype);
header('Content-Disposition: attachment;filename="'.$filename.'"');
$objWriter = PHPExcel_IOFactory::createWriter($this->objPHPExcel, $this->type);
$objWriter->save('php://output');
}
|
[
"public",
"function",
"close",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"foreach",
"(",
"$",
"this",
"->",
"objPHPExcel",
"->",
"getAllSheets",
"(",
")",
"as",
"$",
"sheet",
")",
"{",
"$",
"sheet",
"->",
"setSelectedCells",
"(",
"'A1'",
")",
";",
"}",
"$",
"this",
"->",
"objPHPExcel",
"->",
"setActiveSheetIndex",
"(",
"0",
")",
";",
"$",
"filename",
"=",
"preg_replace",
"(",
"'/\\.xlsx?$/i'",
",",
"''",
",",
"$",
"this",
"->",
"filename",
")",
";",
"$",
"mimetype",
"=",
"'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'",
";",
"$",
"filename",
"=",
"$",
"filename",
".",
"'.xlsx'",
";",
"if",
"(",
"is_https",
"(",
")",
")",
"{",
"// HTTPS sites - watch out for IE! KB812935 and KB316431.",
"header",
"(",
"'Cache-Control: max-age=10'",
")",
";",
"header",
"(",
"'Expires: '",
".",
"gmdate",
"(",
"'D, d M Y H:i:s'",
",",
"0",
")",
".",
"' GMT'",
")",
";",
"header",
"(",
"'Pragma: '",
")",
";",
"}",
"else",
"{",
"//normal http - prevent caching at all cost",
"header",
"(",
"'Cache-Control: private, must-revalidate, pre-check=0, post-check=0, max-age=0'",
")",
";",
"header",
"(",
"'Expires: '",
".",
"gmdate",
"(",
"'D, d M Y H:i:s'",
",",
"0",
")",
".",
"' GMT'",
")",
";",
"header",
"(",
"'Pragma: no-cache'",
")",
";",
"}",
"if",
"(",
"core_useragent",
"::",
"is_ie",
"(",
")",
"||",
"core_useragent",
"::",
"is_edge",
"(",
")",
")",
"{",
"$",
"filename",
"=",
"rawurlencode",
"(",
"$",
"filename",
")",
";",
"}",
"else",
"{",
"$",
"filename",
"=",
"s",
"(",
"$",
"filename",
")",
";",
"}",
"header",
"(",
"'Content-Type: '",
".",
"$",
"mimetype",
")",
";",
"header",
"(",
"'Content-Disposition: attachment;filename=\"'",
".",
"$",
"filename",
".",
"'\"'",
")",
";",
"$",
"objWriter",
"=",
"PHPExcel_IOFactory",
"::",
"createWriter",
"(",
"$",
"this",
"->",
"objPHPExcel",
",",
"$",
"this",
"->",
"type",
")",
";",
"$",
"objWriter",
"->",
"save",
"(",
"'php://output'",
")",
";",
"}"
] |
Close the Moodle Workbook
|
[
"Close",
"the",
"Moodle",
"Workbook"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/excellib.class.php#L96-L130
|
218,301
|
moodle/moodle
|
lib/excellib.class.php
|
MoodleExcelWorksheet.insert_bitmap
|
public function insert_bitmap($row, $col, $bitmap, $x = 0, $y = 0, $scale_x = 1, $scale_y = 1) {
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setPath($bitmap);
$objDrawing->setCoordinates(PHPExcel_Cell::stringFromColumnIndex($col) . ($row+1));
$objDrawing->setOffsetX($x);
$objDrawing->setOffsetY($y);
$objDrawing->setWorksheet($this->worksheet);
if ($scale_x != 1) {
$objDrawing->setResizeProportional(false);
$objDrawing->getWidth($objDrawing->getWidth()*$scale_x);
}
if ($scale_y != 1) {
$objDrawing->setResizeProportional(false);
$objDrawing->setHeight($objDrawing->getHeight()*$scale_y);
}
}
|
php
|
public function insert_bitmap($row, $col, $bitmap, $x = 0, $y = 0, $scale_x = 1, $scale_y = 1) {
$objDrawing = new PHPExcel_Worksheet_Drawing();
$objDrawing->setPath($bitmap);
$objDrawing->setCoordinates(PHPExcel_Cell::stringFromColumnIndex($col) . ($row+1));
$objDrawing->setOffsetX($x);
$objDrawing->setOffsetY($y);
$objDrawing->setWorksheet($this->worksheet);
if ($scale_x != 1) {
$objDrawing->setResizeProportional(false);
$objDrawing->getWidth($objDrawing->getWidth()*$scale_x);
}
if ($scale_y != 1) {
$objDrawing->setResizeProportional(false);
$objDrawing->setHeight($objDrawing->getHeight()*$scale_y);
}
}
|
[
"public",
"function",
"insert_bitmap",
"(",
"$",
"row",
",",
"$",
"col",
",",
"$",
"bitmap",
",",
"$",
"x",
"=",
"0",
",",
"$",
"y",
"=",
"0",
",",
"$",
"scale_x",
"=",
"1",
",",
"$",
"scale_y",
"=",
"1",
")",
"{",
"$",
"objDrawing",
"=",
"new",
"PHPExcel_Worksheet_Drawing",
"(",
")",
";",
"$",
"objDrawing",
"->",
"setPath",
"(",
"$",
"bitmap",
")",
";",
"$",
"objDrawing",
"->",
"setCoordinates",
"(",
"PHPExcel_Cell",
"::",
"stringFromColumnIndex",
"(",
"$",
"col",
")",
".",
"(",
"$",
"row",
"+",
"1",
")",
")",
";",
"$",
"objDrawing",
"->",
"setOffsetX",
"(",
"$",
"x",
")",
";",
"$",
"objDrawing",
"->",
"setOffsetY",
"(",
"$",
"y",
")",
";",
"$",
"objDrawing",
"->",
"setWorksheet",
"(",
"$",
"this",
"->",
"worksheet",
")",
";",
"if",
"(",
"$",
"scale_x",
"!=",
"1",
")",
"{",
"$",
"objDrawing",
"->",
"setResizeProportional",
"(",
"false",
")",
";",
"$",
"objDrawing",
"->",
"getWidth",
"(",
"$",
"objDrawing",
"->",
"getWidth",
"(",
")",
"*",
"$",
"scale_x",
")",
";",
"}",
"if",
"(",
"$",
"scale_y",
"!=",
"1",
")",
"{",
"$",
"objDrawing",
"->",
"setResizeProportional",
"(",
"false",
")",
";",
"$",
"objDrawing",
"->",
"setHeight",
"(",
"$",
"objDrawing",
"->",
"getHeight",
"(",
")",
"*",
"$",
"scale_y",
")",
";",
"}",
"}"
] |
Insert an image in a worksheet.
@param integer $row The row we are going to insert the bitmap into
@param integer $col The column we are going to insert the bitmap into
@param string $bitmap The bitmap filename
@param integer $x The horizontal position (offset) of the image inside the cell.
@param integer $y The vertical position (offset) of the image inside the cell.
@param integer $scale_x The horizontal scale
@param integer $scale_y The vertical scale
|
[
"Insert",
"an",
"image",
"in",
"a",
"worksheet",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/excellib.class.php#L384-L399
|
218,302
|
moodle/moodle
|
lib/excellib.class.php
|
MoodleExcelFormat.set_bg_color
|
public function set_bg_color($color) {
if (!isset($this->format['fill']['type'])) {
$this->format['fill']['type'] = PHPExcel_Style_Fill::FILL_SOLID;
}
$this->format['fill']['color']['rgb'] = $this->parse_color($color);
}
|
php
|
public function set_bg_color($color) {
if (!isset($this->format['fill']['type'])) {
$this->format['fill']['type'] = PHPExcel_Style_Fill::FILL_SOLID;
}
$this->format['fill']['color']['rgb'] = $this->parse_color($color);
}
|
[
"public",
"function",
"set_bg_color",
"(",
"$",
"color",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"format",
"[",
"'fill'",
"]",
"[",
"'type'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"format",
"[",
"'fill'",
"]",
"[",
"'type'",
"]",
"=",
"PHPExcel_Style_Fill",
"::",
"FILL_SOLID",
";",
"}",
"$",
"this",
"->",
"format",
"[",
"'fill'",
"]",
"[",
"'color'",
"]",
"[",
"'rgb'",
"]",
"=",
"$",
"this",
"->",
"parse_color",
"(",
"$",
"color",
")",
";",
"}"
] |
Set background color of the cell.
@param mixed $color either a string (like 'blue'), or an integer (range is [8...63])
|
[
"Set",
"background",
"color",
"of",
"the",
"cell",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/excellib.class.php#L658-L663
|
218,303
|
moodle/moodle
|
lib/excellib.class.php
|
MoodleExcelFormat.set_h_align
|
public function set_h_align($location) {
switch ($location) {
case 'left':
$this->format['alignment']['horizontal'] = PHPExcel_Style_Alignment::HORIZONTAL_LEFT;
break;
case 'center':
case 'centre':
$this->format['alignment']['horizontal'] = PHPExcel_Style_Alignment::HORIZONTAL_CENTER;
break;
case 'right':
$this->format['alignment']['horizontal'] = PHPExcel_Style_Alignment::HORIZONTAL_RIGHT;
break;
case 'justify':
$this->format['alignment']['horizontal'] = PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY;
break;
default:
$this->format['alignment']['horizontal'] = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL;
}
}
|
php
|
public function set_h_align($location) {
switch ($location) {
case 'left':
$this->format['alignment']['horizontal'] = PHPExcel_Style_Alignment::HORIZONTAL_LEFT;
break;
case 'center':
case 'centre':
$this->format['alignment']['horizontal'] = PHPExcel_Style_Alignment::HORIZONTAL_CENTER;
break;
case 'right':
$this->format['alignment']['horizontal'] = PHPExcel_Style_Alignment::HORIZONTAL_RIGHT;
break;
case 'justify':
$this->format['alignment']['horizontal'] = PHPExcel_Style_Alignment::HORIZONTAL_JUSTIFY;
break;
default:
$this->format['alignment']['horizontal'] = PHPExcel_Style_Alignment::HORIZONTAL_GENERAL;
}
}
|
[
"public",
"function",
"set_h_align",
"(",
"$",
"location",
")",
"{",
"switch",
"(",
"$",
"location",
")",
"{",
"case",
"'left'",
":",
"$",
"this",
"->",
"format",
"[",
"'alignment'",
"]",
"[",
"'horizontal'",
"]",
"=",
"PHPExcel_Style_Alignment",
"::",
"HORIZONTAL_LEFT",
";",
"break",
";",
"case",
"'center'",
":",
"case",
"'centre'",
":",
"$",
"this",
"->",
"format",
"[",
"'alignment'",
"]",
"[",
"'horizontal'",
"]",
"=",
"PHPExcel_Style_Alignment",
"::",
"HORIZONTAL_CENTER",
";",
"break",
";",
"case",
"'right'",
":",
"$",
"this",
"->",
"format",
"[",
"'alignment'",
"]",
"[",
"'horizontal'",
"]",
"=",
"PHPExcel_Style_Alignment",
"::",
"HORIZONTAL_RIGHT",
";",
"break",
";",
"case",
"'justify'",
":",
"$",
"this",
"->",
"format",
"[",
"'alignment'",
"]",
"[",
"'horizontal'",
"]",
"=",
"PHPExcel_Style_Alignment",
"::",
"HORIZONTAL_JUSTIFY",
";",
"break",
";",
"default",
":",
"$",
"this",
"->",
"format",
"[",
"'alignment'",
"]",
"[",
"'horizontal'",
"]",
"=",
"PHPExcel_Style_Alignment",
"::",
"HORIZONTAL_GENERAL",
";",
"}",
"}"
] |
Set the cell horizontal alignment of the format.
@param string $location alignment for the cell ('left', 'right', 'justify', etc...)
|
[
"Set",
"the",
"cell",
"horizontal",
"alignment",
"of",
"the",
"format",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/excellib.class.php#L708-L726
|
218,304
|
moodle/moodle
|
lib/excellib.class.php
|
MoodleExcelFormat.set_v_align
|
public function set_v_align($location) {
switch ($location) {
case 'top':
$this->format['alignment']['vertical'] = PHPExcel_Style_Alignment::VERTICAL_TOP;
break;
case 'vcentre':
case 'vcenter':
case 'centre':
case 'center':
$this->format['alignment']['vertical'] = PHPExcel_Style_Alignment::VERTICAL_CENTER;
break;
case 'vjustify':
case 'justify':
$this->format['alignment']['vertical'] = PHPExcel_Style_Alignment::VERTICAL_JUSTIFY;
break;
default:
$this->format['alignment']['vertical'] = PHPExcel_Style_Alignment::VERTICAL_BOTTOM;
}
}
|
php
|
public function set_v_align($location) {
switch ($location) {
case 'top':
$this->format['alignment']['vertical'] = PHPExcel_Style_Alignment::VERTICAL_TOP;
break;
case 'vcentre':
case 'vcenter':
case 'centre':
case 'center':
$this->format['alignment']['vertical'] = PHPExcel_Style_Alignment::VERTICAL_CENTER;
break;
case 'vjustify':
case 'justify':
$this->format['alignment']['vertical'] = PHPExcel_Style_Alignment::VERTICAL_JUSTIFY;
break;
default:
$this->format['alignment']['vertical'] = PHPExcel_Style_Alignment::VERTICAL_BOTTOM;
}
}
|
[
"public",
"function",
"set_v_align",
"(",
"$",
"location",
")",
"{",
"switch",
"(",
"$",
"location",
")",
"{",
"case",
"'top'",
":",
"$",
"this",
"->",
"format",
"[",
"'alignment'",
"]",
"[",
"'vertical'",
"]",
"=",
"PHPExcel_Style_Alignment",
"::",
"VERTICAL_TOP",
";",
"break",
";",
"case",
"'vcentre'",
":",
"case",
"'vcenter'",
":",
"case",
"'centre'",
":",
"case",
"'center'",
":",
"$",
"this",
"->",
"format",
"[",
"'alignment'",
"]",
"[",
"'vertical'",
"]",
"=",
"PHPExcel_Style_Alignment",
"::",
"VERTICAL_CENTER",
";",
"break",
";",
"case",
"'vjustify'",
":",
"case",
"'justify'",
":",
"$",
"this",
"->",
"format",
"[",
"'alignment'",
"]",
"[",
"'vertical'",
"]",
"=",
"PHPExcel_Style_Alignment",
"::",
"VERTICAL_JUSTIFY",
";",
"break",
";",
"default",
":",
"$",
"this",
"->",
"format",
"[",
"'alignment'",
"]",
"[",
"'vertical'",
"]",
"=",
"PHPExcel_Style_Alignment",
"::",
"VERTICAL_BOTTOM",
";",
"}",
"}"
] |
Set the cell vertical alignment of the format.
@param string $location alignment for the cell ('top', 'bottom', 'center', 'justify')
|
[
"Set",
"the",
"cell",
"vertical",
"alignment",
"of",
"the",
"format",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/excellib.class.php#L733-L751
|
218,305
|
moodle/moodle
|
lib/excellib.class.php
|
MoodleExcelFormat.set_top
|
public function set_top($style) {
if ($style == 1) {
$this->format['borders']['top']['style'] = PHPExcel_Style_Border::BORDER_THIN;
} else if ($style == 2) {
$this->format['borders']['top']['style'] = PHPExcel_Style_Border::BORDER_THICK;
} else {
$this->format['borders']['top']['style'] = PHPExcel_Style_Border::BORDER_NONE;
}
}
|
php
|
public function set_top($style) {
if ($style == 1) {
$this->format['borders']['top']['style'] = PHPExcel_Style_Border::BORDER_THIN;
} else if ($style == 2) {
$this->format['borders']['top']['style'] = PHPExcel_Style_Border::BORDER_THICK;
} else {
$this->format['borders']['top']['style'] = PHPExcel_Style_Border::BORDER_NONE;
}
}
|
[
"public",
"function",
"set_top",
"(",
"$",
"style",
")",
"{",
"if",
"(",
"$",
"style",
"==",
"1",
")",
"{",
"$",
"this",
"->",
"format",
"[",
"'borders'",
"]",
"[",
"'top'",
"]",
"[",
"'style'",
"]",
"=",
"PHPExcel_Style_Border",
"::",
"BORDER_THIN",
";",
"}",
"else",
"if",
"(",
"$",
"style",
"==",
"2",
")",
"{",
"$",
"this",
"->",
"format",
"[",
"'borders'",
"]",
"[",
"'top'",
"]",
"[",
"'style'",
"]",
"=",
"PHPExcel_Style_Border",
"::",
"BORDER_THICK",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"format",
"[",
"'borders'",
"]",
"[",
"'top'",
"]",
"[",
"'style'",
"]",
"=",
"PHPExcel_Style_Border",
"::",
"BORDER_NONE",
";",
"}",
"}"
] |
Set the top border of the format.
@param integer $style style for the cell. 1 => thin, 2 => thick
|
[
"Set",
"the",
"top",
"border",
"of",
"the",
"format",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/excellib.class.php#L758-L766
|
218,306
|
moodle/moodle
|
lib/excellib.class.php
|
MoodleExcelFormat.set_bottom
|
public function set_bottom($style) {
if ($style == 1) {
$this->format['borders']['bottom']['style'] = PHPExcel_Style_Border::BORDER_THIN;
} else if ($style == 2) {
$this->format['borders']['bottom']['style'] = PHPExcel_Style_Border::BORDER_THICK;
} else {
$this->format['borders']['bottom']['style'] = PHPExcel_Style_Border::BORDER_NONE;
}
}
|
php
|
public function set_bottom($style) {
if ($style == 1) {
$this->format['borders']['bottom']['style'] = PHPExcel_Style_Border::BORDER_THIN;
} else if ($style == 2) {
$this->format['borders']['bottom']['style'] = PHPExcel_Style_Border::BORDER_THICK;
} else {
$this->format['borders']['bottom']['style'] = PHPExcel_Style_Border::BORDER_NONE;
}
}
|
[
"public",
"function",
"set_bottom",
"(",
"$",
"style",
")",
"{",
"if",
"(",
"$",
"style",
"==",
"1",
")",
"{",
"$",
"this",
"->",
"format",
"[",
"'borders'",
"]",
"[",
"'bottom'",
"]",
"[",
"'style'",
"]",
"=",
"PHPExcel_Style_Border",
"::",
"BORDER_THIN",
";",
"}",
"else",
"if",
"(",
"$",
"style",
"==",
"2",
")",
"{",
"$",
"this",
"->",
"format",
"[",
"'borders'",
"]",
"[",
"'bottom'",
"]",
"[",
"'style'",
"]",
"=",
"PHPExcel_Style_Border",
"::",
"BORDER_THICK",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"format",
"[",
"'borders'",
"]",
"[",
"'bottom'",
"]",
"[",
"'style'",
"]",
"=",
"PHPExcel_Style_Border",
"::",
"BORDER_NONE",
";",
"}",
"}"
] |
Set the bottom border of the format.
@param integer $style style for the cell. 1 => thin, 2 => thick
|
[
"Set",
"the",
"bottom",
"border",
"of",
"the",
"format",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/excellib.class.php#L773-L781
|
218,307
|
moodle/moodle
|
lib/excellib.class.php
|
MoodleExcelFormat.set_left
|
public function set_left($style) {
if ($style == 1) {
$this->format['borders']['left']['style'] = PHPExcel_Style_Border::BORDER_THIN;
} else if ($style == 2) {
$this->format['borders']['left']['style'] = PHPExcel_Style_Border::BORDER_THICK;
} else {
$this->format['borders']['left']['style'] = PHPExcel_Style_Border::BORDER_NONE;
}
}
|
php
|
public function set_left($style) {
if ($style == 1) {
$this->format['borders']['left']['style'] = PHPExcel_Style_Border::BORDER_THIN;
} else if ($style == 2) {
$this->format['borders']['left']['style'] = PHPExcel_Style_Border::BORDER_THICK;
} else {
$this->format['borders']['left']['style'] = PHPExcel_Style_Border::BORDER_NONE;
}
}
|
[
"public",
"function",
"set_left",
"(",
"$",
"style",
")",
"{",
"if",
"(",
"$",
"style",
"==",
"1",
")",
"{",
"$",
"this",
"->",
"format",
"[",
"'borders'",
"]",
"[",
"'left'",
"]",
"[",
"'style'",
"]",
"=",
"PHPExcel_Style_Border",
"::",
"BORDER_THIN",
";",
"}",
"else",
"if",
"(",
"$",
"style",
"==",
"2",
")",
"{",
"$",
"this",
"->",
"format",
"[",
"'borders'",
"]",
"[",
"'left'",
"]",
"[",
"'style'",
"]",
"=",
"PHPExcel_Style_Border",
"::",
"BORDER_THICK",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"format",
"[",
"'borders'",
"]",
"[",
"'left'",
"]",
"[",
"'style'",
"]",
"=",
"PHPExcel_Style_Border",
"::",
"BORDER_NONE",
";",
"}",
"}"
] |
Set the left border of the format.
@param integer $style style for the cell. 1 => thin, 2 => thick
|
[
"Set",
"the",
"left",
"border",
"of",
"the",
"format",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/excellib.class.php#L788-L796
|
218,308
|
moodle/moodle
|
lib/excellib.class.php
|
MoodleExcelFormat.set_right
|
public function set_right($style) {
if ($style == 1) {
$this->format['borders']['right']['style'] = PHPExcel_Style_Border::BORDER_THIN;
} else if ($style == 2) {
$this->format['borders']['right']['style'] = PHPExcel_Style_Border::BORDER_THICK;
} else {
$this->format['borders']['right']['style'] = PHPExcel_Style_Border::BORDER_NONE;
}
}
|
php
|
public function set_right($style) {
if ($style == 1) {
$this->format['borders']['right']['style'] = PHPExcel_Style_Border::BORDER_THIN;
} else if ($style == 2) {
$this->format['borders']['right']['style'] = PHPExcel_Style_Border::BORDER_THICK;
} else {
$this->format['borders']['right']['style'] = PHPExcel_Style_Border::BORDER_NONE;
}
}
|
[
"public",
"function",
"set_right",
"(",
"$",
"style",
")",
"{",
"if",
"(",
"$",
"style",
"==",
"1",
")",
"{",
"$",
"this",
"->",
"format",
"[",
"'borders'",
"]",
"[",
"'right'",
"]",
"[",
"'style'",
"]",
"=",
"PHPExcel_Style_Border",
"::",
"BORDER_THIN",
";",
"}",
"else",
"if",
"(",
"$",
"style",
"==",
"2",
")",
"{",
"$",
"this",
"->",
"format",
"[",
"'borders'",
"]",
"[",
"'right'",
"]",
"[",
"'style'",
"]",
"=",
"PHPExcel_Style_Border",
"::",
"BORDER_THICK",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"format",
"[",
"'borders'",
"]",
"[",
"'right'",
"]",
"[",
"'style'",
"]",
"=",
"PHPExcel_Style_Border",
"::",
"BORDER_NONE",
";",
"}",
"}"
] |
Set the right border of the format.
@param integer $style style for the cell. 1 => thin, 2 => thick
|
[
"Set",
"the",
"right",
"border",
"of",
"the",
"format",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/excellib.class.php#L803-L811
|
218,309
|
moodle/moodle
|
calendar/classes/local/api.php
|
api.get_events
|
public static function get_events(
$timestartfrom = null,
$timestartto = null,
$timesortfrom = null,
$timesortto = null,
$timestartaftereventid = null,
$timesortaftereventid = null,
$limitnum = 20,
$type = null,
array $usersfilter = null,
array $groupsfilter = null,
array $coursesfilter = null,
array $categoriesfilter = null,
$withduration = true,
$ignorehidden = true,
callable $filter = null
) {
global $USER;
$vault = \core_calendar\local\event\container::get_event_vault();
$timestartafterevent = null;
$timesortafterevent = null;
if ($timestartaftereventid && $event = $vault->get_event_by_id($timestartaftereventid)) {
$timestartafterevent = $event;
}
if ($timesortaftereventid && $event = $vault->get_event_by_id($timesortaftereventid)) {
$timesortafterevent = $event;
}
return $vault->get_events(
$timestartfrom,
$timestartto,
$timesortfrom,
$timesortto,
$timestartafterevent,
$timesortafterevent,
$limitnum,
$type,
$usersfilter,
$groupsfilter,
$coursesfilter,
$categoriesfilter,
$withduration,
$ignorehidden,
$filter
);
}
|
php
|
public static function get_events(
$timestartfrom = null,
$timestartto = null,
$timesortfrom = null,
$timesortto = null,
$timestartaftereventid = null,
$timesortaftereventid = null,
$limitnum = 20,
$type = null,
array $usersfilter = null,
array $groupsfilter = null,
array $coursesfilter = null,
array $categoriesfilter = null,
$withduration = true,
$ignorehidden = true,
callable $filter = null
) {
global $USER;
$vault = \core_calendar\local\event\container::get_event_vault();
$timestartafterevent = null;
$timesortafterevent = null;
if ($timestartaftereventid && $event = $vault->get_event_by_id($timestartaftereventid)) {
$timestartafterevent = $event;
}
if ($timesortaftereventid && $event = $vault->get_event_by_id($timesortaftereventid)) {
$timesortafterevent = $event;
}
return $vault->get_events(
$timestartfrom,
$timestartto,
$timesortfrom,
$timesortto,
$timestartafterevent,
$timesortafterevent,
$limitnum,
$type,
$usersfilter,
$groupsfilter,
$coursesfilter,
$categoriesfilter,
$withduration,
$ignorehidden,
$filter
);
}
|
[
"public",
"static",
"function",
"get_events",
"(",
"$",
"timestartfrom",
"=",
"null",
",",
"$",
"timestartto",
"=",
"null",
",",
"$",
"timesortfrom",
"=",
"null",
",",
"$",
"timesortto",
"=",
"null",
",",
"$",
"timestartaftereventid",
"=",
"null",
",",
"$",
"timesortaftereventid",
"=",
"null",
",",
"$",
"limitnum",
"=",
"20",
",",
"$",
"type",
"=",
"null",
",",
"array",
"$",
"usersfilter",
"=",
"null",
",",
"array",
"$",
"groupsfilter",
"=",
"null",
",",
"array",
"$",
"coursesfilter",
"=",
"null",
",",
"array",
"$",
"categoriesfilter",
"=",
"null",
",",
"$",
"withduration",
"=",
"true",
",",
"$",
"ignorehidden",
"=",
"true",
",",
"callable",
"$",
"filter",
"=",
"null",
")",
"{",
"global",
"$",
"USER",
";",
"$",
"vault",
"=",
"\\",
"core_calendar",
"\\",
"local",
"\\",
"event",
"\\",
"container",
"::",
"get_event_vault",
"(",
")",
";",
"$",
"timestartafterevent",
"=",
"null",
";",
"$",
"timesortafterevent",
"=",
"null",
";",
"if",
"(",
"$",
"timestartaftereventid",
"&&",
"$",
"event",
"=",
"$",
"vault",
"->",
"get_event_by_id",
"(",
"$",
"timestartaftereventid",
")",
")",
"{",
"$",
"timestartafterevent",
"=",
"$",
"event",
";",
"}",
"if",
"(",
"$",
"timesortaftereventid",
"&&",
"$",
"event",
"=",
"$",
"vault",
"->",
"get_event_by_id",
"(",
"$",
"timesortaftereventid",
")",
")",
"{",
"$",
"timesortafterevent",
"=",
"$",
"event",
";",
"}",
"return",
"$",
"vault",
"->",
"get_events",
"(",
"$",
"timestartfrom",
",",
"$",
"timestartto",
",",
"$",
"timesortfrom",
",",
"$",
"timesortto",
",",
"$",
"timestartafterevent",
",",
"$",
"timesortafterevent",
",",
"$",
"limitnum",
",",
"$",
"type",
",",
"$",
"usersfilter",
",",
"$",
"groupsfilter",
",",
"$",
"coursesfilter",
",",
"$",
"categoriesfilter",
",",
"$",
"withduration",
",",
"$",
"ignorehidden",
",",
"$",
"filter",
")",
";",
"}"
] |
Get all events restricted by various parameters, taking in to account user and group overrides.
@param int|null $timestartfrom Events with timestart from this value (inclusive).
@param int|null $timestartto Events with timestart until this value (inclusive).
@param int|null $timesortfrom Events with timesort from this value (inclusive).
@param int|null $timesortto Events with timesort until this value (inclusive).
@param int|null $timestartaftereventid Restrict the events in the timestart range to ones after this ID.
@param int|null $timesortaftereventid Restrict the events in the timesort range to ones after this ID.
@param int $limitnum Return at most this number of events.
@param int|null $type Return only events of this type.
@param array|null $usersfilter Return only events for these users.
@param array|null $groupsfilter Return only events for these groups.
@param array|null $coursesfilter Return only events for these courses.
@param bool $withduration If true return only events starting within specified
timestart otherwise return in progress events as well.
@param bool $ignorehidden If true don't return hidden events.
@return \core_calendar\local\event\entities\event_interface[] Array of event_interfaces.
|
[
"Get",
"all",
"events",
"restricted",
"by",
"various",
"parameters",
"taking",
"in",
"to",
"account",
"user",
"and",
"group",
"overrides",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/local/api.php#L62-L111
|
218,310
|
moodle/moodle
|
calendar/classes/local/api.php
|
api.get_action_events_by_timesort
|
public static function get_action_events_by_timesort(
$timesortfrom = null,
$timesortto = null,
$aftereventid = null,
$limitnum = 20,
$limittononsuspendedevents = false,
?\stdClass $user = null
) {
global $USER;
if (!$user) {
$user = $USER;
}
if (is_null($timesortfrom) && is_null($timesortto)) {
throw new \moodle_exception("Must provide a timesort to and/or from value");
}
if ($limitnum < 1 || $limitnum > 50) {
throw new \moodle_exception("Limit must be between 1 and 50 (inclusive)");
}
\core_calendar\local\event\container::set_requesting_user($user->id);
$vault = \core_calendar\local\event\container::get_event_vault();
$afterevent = null;
if ($aftereventid && $event = $vault->get_event_by_id($aftereventid)) {
$afterevent = $event;
}
return $vault->get_action_events_by_timesort($user, $timesortfrom, $timesortto, $afterevent, $limitnum,
$limittononsuspendedevents);
}
|
php
|
public static function get_action_events_by_timesort(
$timesortfrom = null,
$timesortto = null,
$aftereventid = null,
$limitnum = 20,
$limittononsuspendedevents = false,
?\stdClass $user = null
) {
global $USER;
if (!$user) {
$user = $USER;
}
if (is_null($timesortfrom) && is_null($timesortto)) {
throw new \moodle_exception("Must provide a timesort to and/or from value");
}
if ($limitnum < 1 || $limitnum > 50) {
throw new \moodle_exception("Limit must be between 1 and 50 (inclusive)");
}
\core_calendar\local\event\container::set_requesting_user($user->id);
$vault = \core_calendar\local\event\container::get_event_vault();
$afterevent = null;
if ($aftereventid && $event = $vault->get_event_by_id($aftereventid)) {
$afterevent = $event;
}
return $vault->get_action_events_by_timesort($user, $timesortfrom, $timesortto, $afterevent, $limitnum,
$limittononsuspendedevents);
}
|
[
"public",
"static",
"function",
"get_action_events_by_timesort",
"(",
"$",
"timesortfrom",
"=",
"null",
",",
"$",
"timesortto",
"=",
"null",
",",
"$",
"aftereventid",
"=",
"null",
",",
"$",
"limitnum",
"=",
"20",
",",
"$",
"limittononsuspendedevents",
"=",
"false",
",",
"?",
"\\",
"stdClass",
"$",
"user",
"=",
"null",
")",
"{",
"global",
"$",
"USER",
";",
"if",
"(",
"!",
"$",
"user",
")",
"{",
"$",
"user",
"=",
"$",
"USER",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"timesortfrom",
")",
"&&",
"is_null",
"(",
"$",
"timesortto",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"\"Must provide a timesort to and/or from value\"",
")",
";",
"}",
"if",
"(",
"$",
"limitnum",
"<",
"1",
"||",
"$",
"limitnum",
">",
"50",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"\"Limit must be between 1 and 50 (inclusive)\"",
")",
";",
"}",
"\\",
"core_calendar",
"\\",
"local",
"\\",
"event",
"\\",
"container",
"::",
"set_requesting_user",
"(",
"$",
"user",
"->",
"id",
")",
";",
"$",
"vault",
"=",
"\\",
"core_calendar",
"\\",
"local",
"\\",
"event",
"\\",
"container",
"::",
"get_event_vault",
"(",
")",
";",
"$",
"afterevent",
"=",
"null",
";",
"if",
"(",
"$",
"aftereventid",
"&&",
"$",
"event",
"=",
"$",
"vault",
"->",
"get_event_by_id",
"(",
"$",
"aftereventid",
")",
")",
"{",
"$",
"afterevent",
"=",
"$",
"event",
";",
"}",
"return",
"$",
"vault",
"->",
"get_action_events_by_timesort",
"(",
"$",
"user",
",",
"$",
"timesortfrom",
",",
"$",
"timesortto",
",",
"$",
"afterevent",
",",
"$",
"limitnum",
",",
"$",
"limittononsuspendedevents",
")",
";",
"}"
] |
Get a list of action events for the logged in user by the given
timesort values.
@param int|null $timesortfrom The start timesort value (inclusive)
@param int|null $timesortto The end timesort value (inclusive)
@param int|null $aftereventid Only return events after this one
@param int $limitnum Limit results to this amount (between 1 and 50)
@param bool $lmittononsuspendedevents Limit course events to courses the user is active in (not suspended).
@param \stdClass|null $user The user id or false for $USER
@return array A list of action_event_interface objects
@throws \moodle_exception
|
[
"Get",
"a",
"list",
"of",
"action",
"events",
"for",
"the",
"logged",
"in",
"user",
"by",
"the",
"given",
"timesort",
"values",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/local/api.php#L126-L158
|
218,311
|
moodle/moodle
|
calendar/classes/local/api.php
|
api.get_action_events_by_course
|
public static function get_action_events_by_course(
$course,
$timesortfrom = null,
$timesortto = null,
$aftereventid = null,
$limitnum = 20
) {
global $USER;
if ($limitnum < 1 || $limitnum > 50) {
throw new limit_invalid_parameter_exception(
"Limit must be between 1 and 50 (inclusive)");
}
$vault = \core_calendar\local\event\container::get_event_vault();
$afterevent = null;
if ($aftereventid && $event = $vault->get_event_by_id($aftereventid)) {
$afterevent = $event;
}
return $vault->get_action_events_by_course(
$USER, $course, $timesortfrom, $timesortto, $afterevent, $limitnum);
}
|
php
|
public static function get_action_events_by_course(
$course,
$timesortfrom = null,
$timesortto = null,
$aftereventid = null,
$limitnum = 20
) {
global $USER;
if ($limitnum < 1 || $limitnum > 50) {
throw new limit_invalid_parameter_exception(
"Limit must be between 1 and 50 (inclusive)");
}
$vault = \core_calendar\local\event\container::get_event_vault();
$afterevent = null;
if ($aftereventid && $event = $vault->get_event_by_id($aftereventid)) {
$afterevent = $event;
}
return $vault->get_action_events_by_course(
$USER, $course, $timesortfrom, $timesortto, $afterevent, $limitnum);
}
|
[
"public",
"static",
"function",
"get_action_events_by_course",
"(",
"$",
"course",
",",
"$",
"timesortfrom",
"=",
"null",
",",
"$",
"timesortto",
"=",
"null",
",",
"$",
"aftereventid",
"=",
"null",
",",
"$",
"limitnum",
"=",
"20",
")",
"{",
"global",
"$",
"USER",
";",
"if",
"(",
"$",
"limitnum",
"<",
"1",
"||",
"$",
"limitnum",
">",
"50",
")",
"{",
"throw",
"new",
"limit_invalid_parameter_exception",
"(",
"\"Limit must be between 1 and 50 (inclusive)\"",
")",
";",
"}",
"$",
"vault",
"=",
"\\",
"core_calendar",
"\\",
"local",
"\\",
"event",
"\\",
"container",
"::",
"get_event_vault",
"(",
")",
";",
"$",
"afterevent",
"=",
"null",
";",
"if",
"(",
"$",
"aftereventid",
"&&",
"$",
"event",
"=",
"$",
"vault",
"->",
"get_event_by_id",
"(",
"$",
"aftereventid",
")",
")",
"{",
"$",
"afterevent",
"=",
"$",
"event",
";",
"}",
"return",
"$",
"vault",
"->",
"get_action_events_by_course",
"(",
"$",
"USER",
",",
"$",
"course",
",",
"$",
"timesortfrom",
",",
"$",
"timesortto",
",",
"$",
"afterevent",
",",
"$",
"limitnum",
")",
";",
"}"
] |
Get a list of action events for the logged in user by the given
course and timesort values.
@param \stdClass $course The course the events must belong to
@param int|null $timesortfrom The start timesort value (inclusive)
@param int|null $timesortto The end timesort value (inclusive)
@param int|null $aftereventid Only return events after this one
@param int $limitnum Limit results to this amount (between 1 and 50)
@return array A list of action_event_interface objects
@throws limit_invalid_parameter_exception
|
[
"Get",
"a",
"list",
"of",
"action",
"events",
"for",
"the",
"logged",
"in",
"user",
"by",
"the",
"given",
"course",
"and",
"timesort",
"values",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/local/api.php#L172-L195
|
218,312
|
moodle/moodle
|
calendar/classes/local/api.php
|
api.get_action_events_by_courses
|
public static function get_action_events_by_courses(
$courses = [],
$timesortfrom = null,
$timesortto = null,
$limitnum = 20
) {
$return = [];
foreach ($courses as $course) {
$return[$course->id] = self::get_action_events_by_course(
$course,
$timesortfrom,
$timesortto,
null,
$limitnum
);
}
return $return;
}
|
php
|
public static function get_action_events_by_courses(
$courses = [],
$timesortfrom = null,
$timesortto = null,
$limitnum = 20
) {
$return = [];
foreach ($courses as $course) {
$return[$course->id] = self::get_action_events_by_course(
$course,
$timesortfrom,
$timesortto,
null,
$limitnum
);
}
return $return;
}
|
[
"public",
"static",
"function",
"get_action_events_by_courses",
"(",
"$",
"courses",
"=",
"[",
"]",
",",
"$",
"timesortfrom",
"=",
"null",
",",
"$",
"timesortto",
"=",
"null",
",",
"$",
"limitnum",
"=",
"20",
")",
"{",
"$",
"return",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"courses",
"as",
"$",
"course",
")",
"{",
"$",
"return",
"[",
"$",
"course",
"->",
"id",
"]",
"=",
"self",
"::",
"get_action_events_by_course",
"(",
"$",
"course",
",",
"$",
"timesortfrom",
",",
"$",
"timesortto",
",",
"null",
",",
"$",
"limitnum",
")",
";",
"}",
"return",
"$",
"return",
";",
"}"
] |
Get a list of action events for the logged in user by the given
courses and timesort values.
The limit number applies per course, not for the result set as a whole.
E.g. Requesting 3 courses with a limit of 10 will result in up to 30
events being returned (up to 10 per course).
@param array $courses The courses the events must belong to
@param int|null $timesortfrom The start timesort value (inclusive)
@param int|null $timesortto The end timesort value (inclusive)
@param int $limitnum Limit results per course to this amount (between 1 and 50)
@return array A list of action_event_interface objects indexed by course id
|
[
"Get",
"a",
"list",
"of",
"action",
"events",
"for",
"the",
"logged",
"in",
"user",
"by",
"the",
"given",
"courses",
"and",
"timesort",
"values",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/local/api.php#L211-L230
|
218,313
|
moodle/moodle
|
calendar/classes/local/api.php
|
api.update_event_start_day
|
public static function update_event_start_day(
event_interface $event,
\DateTimeInterface $startdate
) {
global $DB;
$mapper = container::get_event_mapper();
$legacyevent = $mapper->from_event_to_legacy_event($event);
$hascoursemodule = !empty($event->get_course_module());
$moduleinstance = null;
$starttime = $event->get_times()->get_start_time()->setDate(
$startdate->format('Y'),
$startdate->format('n'),
$startdate->format('j')
);
$starttimestamp = $starttime->getTimestamp();
if ($hascoursemodule) {
$moduleinstance = $DB->get_record(
$event->get_course_module()->get('modname'),
['id' => $event->get_course_module()->get('instance')],
'*',
MUST_EXIST
);
// If there is a timestart range callback implemented then we can
// use the values returned from the valid timestart range to apply
// some default validation on the event's timestart value to ensure
// that it falls within the specified range.
list($min, $max) = component_callback(
'mod_' . $event->get_course_module()->get('modname'),
'core_calendar_get_valid_event_timestart_range',
[$legacyevent, $moduleinstance],
[false, false]
);
} else if ($legacyevent->courseid != 0 && $legacyevent->courseid != SITEID && $legacyevent->groupid == 0) {
// This is a course event.
list($min, $max) = component_callback(
'core_course',
'core_calendar_get_valid_event_timestart_range',
[$legacyevent, $event->get_course()->get_proxied_instance()],
[0, 0]
);
} else {
$min = $max = 0;
}
// If the callback returns false for either value it means that
// there is no valid time start range.
if ($min === false || $max === false) {
throw new \moodle_exception('The start day of this event can not be modified');
}
if ($min && $starttimestamp < $min[0]) {
throw new \moodle_exception($min[1]);
}
if ($max && $starttimestamp > $max[0]) {
throw new \moodle_exception($max[1]);
}
// This function does our capability checks.
$legacyevent->update((object) ['timestart' => $starttime->getTimestamp()]);
// Check that the user is allowed to manually edit calendar events before
// calling the event updated callback. The manual flag causes the code to
// check the user has the capabilities to modify the modules.
//
// We don't want to call the event update callback if the user isn't allowed
// to modify course modules because depending on the callback it can make
// some changes that would be considered security issues, such as updating the
// due date for an assignment.
if ($hascoursemodule && calendar_edit_event_allowed($legacyevent, true)) {
// If this event is from an activity then we need to call
// the activity callback to let it know that the event it
// created has been modified so it needs to update accordingly.
component_callback(
'mod_' . $event->get_course_module()->get('modname'),
'core_calendar_event_timestart_updated',
[$legacyevent, $moduleinstance]
);
}
return $mapper->from_legacy_event_to_event($legacyevent);
}
|
php
|
public static function update_event_start_day(
event_interface $event,
\DateTimeInterface $startdate
) {
global $DB;
$mapper = container::get_event_mapper();
$legacyevent = $mapper->from_event_to_legacy_event($event);
$hascoursemodule = !empty($event->get_course_module());
$moduleinstance = null;
$starttime = $event->get_times()->get_start_time()->setDate(
$startdate->format('Y'),
$startdate->format('n'),
$startdate->format('j')
);
$starttimestamp = $starttime->getTimestamp();
if ($hascoursemodule) {
$moduleinstance = $DB->get_record(
$event->get_course_module()->get('modname'),
['id' => $event->get_course_module()->get('instance')],
'*',
MUST_EXIST
);
// If there is a timestart range callback implemented then we can
// use the values returned from the valid timestart range to apply
// some default validation on the event's timestart value to ensure
// that it falls within the specified range.
list($min, $max) = component_callback(
'mod_' . $event->get_course_module()->get('modname'),
'core_calendar_get_valid_event_timestart_range',
[$legacyevent, $moduleinstance],
[false, false]
);
} else if ($legacyevent->courseid != 0 && $legacyevent->courseid != SITEID && $legacyevent->groupid == 0) {
// This is a course event.
list($min, $max) = component_callback(
'core_course',
'core_calendar_get_valid_event_timestart_range',
[$legacyevent, $event->get_course()->get_proxied_instance()],
[0, 0]
);
} else {
$min = $max = 0;
}
// If the callback returns false for either value it means that
// there is no valid time start range.
if ($min === false || $max === false) {
throw new \moodle_exception('The start day of this event can not be modified');
}
if ($min && $starttimestamp < $min[0]) {
throw new \moodle_exception($min[1]);
}
if ($max && $starttimestamp > $max[0]) {
throw new \moodle_exception($max[1]);
}
// This function does our capability checks.
$legacyevent->update((object) ['timestart' => $starttime->getTimestamp()]);
// Check that the user is allowed to manually edit calendar events before
// calling the event updated callback. The manual flag causes the code to
// check the user has the capabilities to modify the modules.
//
// We don't want to call the event update callback if the user isn't allowed
// to modify course modules because depending on the callback it can make
// some changes that would be considered security issues, such as updating the
// due date for an assignment.
if ($hascoursemodule && calendar_edit_event_allowed($legacyevent, true)) {
// If this event is from an activity then we need to call
// the activity callback to let it know that the event it
// created has been modified so it needs to update accordingly.
component_callback(
'mod_' . $event->get_course_module()->get('modname'),
'core_calendar_event_timestart_updated',
[$legacyevent, $moduleinstance]
);
}
return $mapper->from_legacy_event_to_event($legacyevent);
}
|
[
"public",
"static",
"function",
"update_event_start_day",
"(",
"event_interface",
"$",
"event",
",",
"\\",
"DateTimeInterface",
"$",
"startdate",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"mapper",
"=",
"container",
"::",
"get_event_mapper",
"(",
")",
";",
"$",
"legacyevent",
"=",
"$",
"mapper",
"->",
"from_event_to_legacy_event",
"(",
"$",
"event",
")",
";",
"$",
"hascoursemodule",
"=",
"!",
"empty",
"(",
"$",
"event",
"->",
"get_course_module",
"(",
")",
")",
";",
"$",
"moduleinstance",
"=",
"null",
";",
"$",
"starttime",
"=",
"$",
"event",
"->",
"get_times",
"(",
")",
"->",
"get_start_time",
"(",
")",
"->",
"setDate",
"(",
"$",
"startdate",
"->",
"format",
"(",
"'Y'",
")",
",",
"$",
"startdate",
"->",
"format",
"(",
"'n'",
")",
",",
"$",
"startdate",
"->",
"format",
"(",
"'j'",
")",
")",
";",
"$",
"starttimestamp",
"=",
"$",
"starttime",
"->",
"getTimestamp",
"(",
")",
";",
"if",
"(",
"$",
"hascoursemodule",
")",
"{",
"$",
"moduleinstance",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"$",
"event",
"->",
"get_course_module",
"(",
")",
"->",
"get",
"(",
"'modname'",
")",
",",
"[",
"'id'",
"=>",
"$",
"event",
"->",
"get_course_module",
"(",
")",
"->",
"get",
"(",
"'instance'",
")",
"]",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"// If there is a timestart range callback implemented then we can",
"// use the values returned from the valid timestart range to apply",
"// some default validation on the event's timestart value to ensure",
"// that it falls within the specified range.",
"list",
"(",
"$",
"min",
",",
"$",
"max",
")",
"=",
"component_callback",
"(",
"'mod_'",
".",
"$",
"event",
"->",
"get_course_module",
"(",
")",
"->",
"get",
"(",
"'modname'",
")",
",",
"'core_calendar_get_valid_event_timestart_range'",
",",
"[",
"$",
"legacyevent",
",",
"$",
"moduleinstance",
"]",
",",
"[",
"false",
",",
"false",
"]",
")",
";",
"}",
"else",
"if",
"(",
"$",
"legacyevent",
"->",
"courseid",
"!=",
"0",
"&&",
"$",
"legacyevent",
"->",
"courseid",
"!=",
"SITEID",
"&&",
"$",
"legacyevent",
"->",
"groupid",
"==",
"0",
")",
"{",
"// This is a course event.",
"list",
"(",
"$",
"min",
",",
"$",
"max",
")",
"=",
"component_callback",
"(",
"'core_course'",
",",
"'core_calendar_get_valid_event_timestart_range'",
",",
"[",
"$",
"legacyevent",
",",
"$",
"event",
"->",
"get_course",
"(",
")",
"->",
"get_proxied_instance",
"(",
")",
"]",
",",
"[",
"0",
",",
"0",
"]",
")",
";",
"}",
"else",
"{",
"$",
"min",
"=",
"$",
"max",
"=",
"0",
";",
"}",
"// If the callback returns false for either value it means that",
"// there is no valid time start range.",
"if",
"(",
"$",
"min",
"===",
"false",
"||",
"$",
"max",
"===",
"false",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'The start day of this event can not be modified'",
")",
";",
"}",
"if",
"(",
"$",
"min",
"&&",
"$",
"starttimestamp",
"<",
"$",
"min",
"[",
"0",
"]",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"$",
"min",
"[",
"1",
"]",
")",
";",
"}",
"if",
"(",
"$",
"max",
"&&",
"$",
"starttimestamp",
">",
"$",
"max",
"[",
"0",
"]",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"$",
"max",
"[",
"1",
"]",
")",
";",
"}",
"// This function does our capability checks.",
"$",
"legacyevent",
"->",
"update",
"(",
"(",
"object",
")",
"[",
"'timestart'",
"=>",
"$",
"starttime",
"->",
"getTimestamp",
"(",
")",
"]",
")",
";",
"// Check that the user is allowed to manually edit calendar events before",
"// calling the event updated callback. The manual flag causes the code to",
"// check the user has the capabilities to modify the modules.",
"//",
"// We don't want to call the event update callback if the user isn't allowed",
"// to modify course modules because depending on the callback it can make",
"// some changes that would be considered security issues, such as updating the",
"// due date for an assignment.",
"if",
"(",
"$",
"hascoursemodule",
"&&",
"calendar_edit_event_allowed",
"(",
"$",
"legacyevent",
",",
"true",
")",
")",
"{",
"// If this event is from an activity then we need to call",
"// the activity callback to let it know that the event it",
"// created has been modified so it needs to update accordingly.",
"component_callback",
"(",
"'mod_'",
".",
"$",
"event",
"->",
"get_course_module",
"(",
")",
"->",
"get",
"(",
"'modname'",
")",
",",
"'core_calendar_event_timestart_updated'",
",",
"[",
"$",
"legacyevent",
",",
"$",
"moduleinstance",
"]",
")",
";",
"}",
"return",
"$",
"mapper",
"->",
"from_legacy_event_to_event",
"(",
"$",
"legacyevent",
")",
";",
"}"
] |
Change the start day for an event. Only the date will be
modified, the time of day for the event will be left as is.
@param event_interface $event The existing event to modify
@param DateTimeInterface $startdate The new date to use for the start day
@return event_interface The new event with updated start date
|
[
"Change",
"the",
"start",
"day",
"for",
"an",
"event",
".",
"Only",
"the",
"date",
"will",
"be",
"modified",
"the",
"time",
"of",
"day",
"for",
"the",
"event",
"will",
"be",
"left",
"as",
"is",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/local/api.php#L240-L324
|
218,314
|
moodle/moodle
|
lib/userkey/classes/privacy/provider.php
|
provider.get_user_contexts_with_script
|
public static function get_user_contexts_with_script(userlist $userlist, \context $context, string $script,
int $instance = null) {
if (!$context instanceof \context_user) {
return;
}
$params = [
'userid' => $context->instanceid,
'script' => $script
];
$whereinstance = '';
if (!empty($instance)) {
$params['instance'] = $instance;
$whereinstance = ' AND k.instance = :instance';
}
$sql = "SELECT k.userid
FROM {user_private_key} k
WHERE k.script = :script
AND k.userid = :userid
{$whereinstance}";
$userlist->add_from_sql('userid', $sql, $params);
}
|
php
|
public static function get_user_contexts_with_script(userlist $userlist, \context $context, string $script,
int $instance = null) {
if (!$context instanceof \context_user) {
return;
}
$params = [
'userid' => $context->instanceid,
'script' => $script
];
$whereinstance = '';
if (!empty($instance)) {
$params['instance'] = $instance;
$whereinstance = ' AND k.instance = :instance';
}
$sql = "SELECT k.userid
FROM {user_private_key} k
WHERE k.script = :script
AND k.userid = :userid
{$whereinstance}";
$userlist->add_from_sql('userid', $sql, $params);
}
|
[
"public",
"static",
"function",
"get_user_contexts_with_script",
"(",
"userlist",
"$",
"userlist",
",",
"\\",
"context",
"$",
"context",
",",
"string",
"$",
"script",
",",
"int",
"$",
"instance",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"context",
"instanceof",
"\\",
"context_user",
")",
"{",
"return",
";",
"}",
"$",
"params",
"=",
"[",
"'userid'",
"=>",
"$",
"context",
"->",
"instanceid",
",",
"'script'",
"=>",
"$",
"script",
"]",
";",
"$",
"whereinstance",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"instance",
")",
")",
"{",
"$",
"params",
"[",
"'instance'",
"]",
"=",
"$",
"instance",
";",
"$",
"whereinstance",
"=",
"' AND k.instance = :instance'",
";",
"}",
"$",
"sql",
"=",
"\"SELECT k.userid\n FROM {user_private_key} k\n WHERE k.script = :script\n AND k.userid = :userid\n {$whereinstance}\"",
";",
"$",
"userlist",
"->",
"add_from_sql",
"(",
"'userid'",
",",
"$",
"sql",
",",
"$",
"params",
")",
";",
"}"
] |
Get the list of users within a specific context for this system.
@param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination.
@param context $context The context.
@param string $script The unique target identifier.
@param int $instance The instance ID.
|
[
"Get",
"the",
"list",
"of",
"users",
"within",
"a",
"specific",
"context",
"for",
"this",
"system",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/userkey/classes/privacy/provider.php#L76-L101
|
218,315
|
moodle/moodle
|
lib/userkey/classes/privacy/provider.php
|
provider.delete_userkeys
|
public static function delete_userkeys(string $script, $userid = null, $instance = null) {
global $DB;
$searchparams = [
'script' => $script,
];
if (null !== $userid) {
$searchparams['userid'] = $userid;
}
if (null !== $instance) {
$searchparams['instance'] = $instance;
}
$DB->delete_records('user_private_key', $searchparams);
}
|
php
|
public static function delete_userkeys(string $script, $userid = null, $instance = null) {
global $DB;
$searchparams = [
'script' => $script,
];
if (null !== $userid) {
$searchparams['userid'] = $userid;
}
if (null !== $instance) {
$searchparams['instance'] = $instance;
}
$DB->delete_records('user_private_key', $searchparams);
}
|
[
"public",
"static",
"function",
"delete_userkeys",
"(",
"string",
"$",
"script",
",",
"$",
"userid",
"=",
"null",
",",
"$",
"instance",
"=",
"null",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"searchparams",
"=",
"[",
"'script'",
"=>",
"$",
"script",
",",
"]",
";",
"if",
"(",
"null",
"!==",
"$",
"userid",
")",
"{",
"$",
"searchparams",
"[",
"'userid'",
"]",
"=",
"$",
"userid",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"instance",
")",
"{",
"$",
"searchparams",
"[",
"'instance'",
"]",
"=",
"$",
"instance",
";",
"}",
"$",
"DB",
"->",
"delete_records",
"(",
"'user_private_key'",
",",
"$",
"searchparams",
")",
";",
"}"
] |
Deletes all userkeys for a script.
@param string $script The owner of the data (usually a component name).
@param int $userid The owner of the data.
@param int $instance The instance owner of the data.
|
[
"Deletes",
"all",
"userkeys",
"for",
"a",
"script",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/userkey/classes/privacy/provider.php#L153-L169
|
218,316
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Shared/String.php
|
PHPExcel_Shared_String.SanitizeUTF8
|
public static function SanitizeUTF8($value)
{
if (self::getIsIconvEnabled()) {
$value = @iconv('UTF-8', 'UTF-8', $value);
return $value;
}
if (self::getIsMbstringEnabled()) {
$value = mb_convert_encoding($value, 'UTF-8', 'UTF-8');
return $value;
}
// else, no conversion
return $value;
}
|
php
|
public static function SanitizeUTF8($value)
{
if (self::getIsIconvEnabled()) {
$value = @iconv('UTF-8', 'UTF-8', $value);
return $value;
}
if (self::getIsMbstringEnabled()) {
$value = mb_convert_encoding($value, 'UTF-8', 'UTF-8');
return $value;
}
// else, no conversion
return $value;
}
|
[
"public",
"static",
"function",
"SanitizeUTF8",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"self",
"::",
"getIsIconvEnabled",
"(",
")",
")",
"{",
"$",
"value",
"=",
"@",
"iconv",
"(",
"'UTF-8'",
",",
"'UTF-8'",
",",
"$",
"value",
")",
";",
"return",
"$",
"value",
";",
"}",
"if",
"(",
"self",
"::",
"getIsMbstringEnabled",
"(",
")",
")",
"{",
"$",
"value",
"=",
"mb_convert_encoding",
"(",
"$",
"value",
",",
"'UTF-8'",
",",
"'UTF-8'",
")",
";",
"return",
"$",
"value",
";",
"}",
"// else, no conversion",
"return",
"$",
"value",
";",
"}"
] |
Try to sanitize UTF8, stripping invalid byte sequences. Not perfect. Does not surrogate characters.
@param string $value
@return string
|
[
"Try",
"to",
"sanitize",
"UTF8",
"stripping",
"invalid",
"byte",
"sequences",
".",
"Not",
"perfect",
".",
"Does",
"not",
"surrogate",
"characters",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Shared/String.php#L376-L390
|
218,317
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Shared/String.php
|
PHPExcel_Shared_String.Substring
|
public static function Substring($pValue = '', $pStart = 0, $pLength = 0)
{
if (self::getIsMbstringEnabled()) {
return mb_substr($pValue, $pStart, $pLength, 'UTF-8');
}
if (self::getIsIconvEnabled()) {
return iconv_substr($pValue, $pStart, $pLength, 'UTF-8');
}
// else substr
return substr($pValue, $pStart, $pLength);
}
|
php
|
public static function Substring($pValue = '', $pStart = 0, $pLength = 0)
{
if (self::getIsMbstringEnabled()) {
return mb_substr($pValue, $pStart, $pLength, 'UTF-8');
}
if (self::getIsIconvEnabled()) {
return iconv_substr($pValue, $pStart, $pLength, 'UTF-8');
}
// else substr
return substr($pValue, $pStart, $pLength);
}
|
[
"public",
"static",
"function",
"Substring",
"(",
"$",
"pValue",
"=",
"''",
",",
"$",
"pStart",
"=",
"0",
",",
"$",
"pLength",
"=",
"0",
")",
"{",
"if",
"(",
"self",
"::",
"getIsMbstringEnabled",
"(",
")",
")",
"{",
"return",
"mb_substr",
"(",
"$",
"pValue",
",",
"$",
"pStart",
",",
"$",
"pLength",
",",
"'UTF-8'",
")",
";",
"}",
"if",
"(",
"self",
"::",
"getIsIconvEnabled",
"(",
")",
")",
"{",
"return",
"iconv_substr",
"(",
"$",
"pValue",
",",
"$",
"pStart",
",",
"$",
"pLength",
",",
"'UTF-8'",
")",
";",
"}",
"// else substr",
"return",
"substr",
"(",
"$",
"pValue",
",",
"$",
"pStart",
",",
"$",
"pLength",
")",
";",
"}"
] |
Get a substring of a UTF-8 encoded string. First try mbstring, then iconv, finally strlen
@param string $pValue UTF-8 encoded string
@param int $pStart Start offset
@param int $pLength Maximum number of characters in substring
@return string
|
[
"Get",
"a",
"substring",
"of",
"a",
"UTF",
"-",
"8",
"encoded",
"string",
".",
"First",
"try",
"mbstring",
"then",
"iconv",
"finally",
"strlen"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Shared/String.php#L578-L590
|
218,318
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Shared/String.php
|
PHPExcel_Shared_String.StrCaseReverse
|
public static function StrCaseReverse($pValue = '')
{
if (self::getIsMbstringEnabled()) {
$characters = self::mb_str_split($pValue);
foreach ($characters as &$character) {
if (self::mb_is_upper($character)) {
$character = mb_strtolower($character, 'UTF-8');
} else {
$character = mb_strtoupper($character, 'UTF-8');
}
}
return implode('', $characters);
}
return strtolower($pValue) ^ strtoupper($pValue) ^ $pValue;
}
|
php
|
public static function StrCaseReverse($pValue = '')
{
if (self::getIsMbstringEnabled()) {
$characters = self::mb_str_split($pValue);
foreach ($characters as &$character) {
if (self::mb_is_upper($character)) {
$character = mb_strtolower($character, 'UTF-8');
} else {
$character = mb_strtoupper($character, 'UTF-8');
}
}
return implode('', $characters);
}
return strtolower($pValue) ^ strtoupper($pValue) ^ $pValue;
}
|
[
"public",
"static",
"function",
"StrCaseReverse",
"(",
"$",
"pValue",
"=",
"''",
")",
"{",
"if",
"(",
"self",
"::",
"getIsMbstringEnabled",
"(",
")",
")",
"{",
"$",
"characters",
"=",
"self",
"::",
"mb_str_split",
"(",
"$",
"pValue",
")",
";",
"foreach",
"(",
"$",
"characters",
"as",
"&",
"$",
"character",
")",
"{",
"if",
"(",
"self",
"::",
"mb_is_upper",
"(",
"$",
"character",
")",
")",
"{",
"$",
"character",
"=",
"mb_strtolower",
"(",
"$",
"character",
",",
"'UTF-8'",
")",
";",
"}",
"else",
"{",
"$",
"character",
"=",
"mb_strtoupper",
"(",
"$",
"character",
",",
"'UTF-8'",
")",
";",
"}",
"}",
"return",
"implode",
"(",
"''",
",",
"$",
"characters",
")",
";",
"}",
"return",
"strtolower",
"(",
"$",
"pValue",
")",
"^",
"strtoupper",
"(",
"$",
"pValue",
")",
"^",
"$",
"pValue",
";",
"}"
] |
Reverse the case of a string, so that all uppercase characters become lowercase
and all lowercase characters become uppercase
@param string $pValue UTF-8 encoded string
@return string
|
[
"Reverse",
"the",
"case",
"of",
"a",
"string",
"so",
"that",
"all",
"uppercase",
"characters",
"become",
"lowercase",
"and",
"all",
"lowercase",
"characters",
"become",
"uppercase"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Shared/String.php#L654-L668
|
218,319
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Shared/String.php
|
PHPExcel_Shared_String.convertToNumberIfFraction
|
public static function convertToNumberIfFraction(&$operand)
{
if (preg_match('/^'.self::STRING_REGEXP_FRACTION.'$/i', $operand, $match)) {
$sign = ($match[1] == '-') ? '-' : '+';
$fractionFormula = '='.$sign.$match[2].$sign.$match[3];
$operand = PHPExcel_Calculation::getInstance()->_calculateFormulaValue($fractionFormula);
return true;
}
return false;
}
|
php
|
public static function convertToNumberIfFraction(&$operand)
{
if (preg_match('/^'.self::STRING_REGEXP_FRACTION.'$/i', $operand, $match)) {
$sign = ($match[1] == '-') ? '-' : '+';
$fractionFormula = '='.$sign.$match[2].$sign.$match[3];
$operand = PHPExcel_Calculation::getInstance()->_calculateFormulaValue($fractionFormula);
return true;
}
return false;
}
|
[
"public",
"static",
"function",
"convertToNumberIfFraction",
"(",
"&",
"$",
"operand",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/^'",
".",
"self",
"::",
"STRING_REGEXP_FRACTION",
".",
"'$/i'",
",",
"$",
"operand",
",",
"$",
"match",
")",
")",
"{",
"$",
"sign",
"=",
"(",
"$",
"match",
"[",
"1",
"]",
"==",
"'-'",
")",
"?",
"'-'",
":",
"'+'",
";",
"$",
"fractionFormula",
"=",
"'='",
".",
"$",
"sign",
".",
"$",
"match",
"[",
"2",
"]",
".",
"$",
"sign",
".",
"$",
"match",
"[",
"3",
"]",
";",
"$",
"operand",
"=",
"PHPExcel_Calculation",
"::",
"getInstance",
"(",
")",
"->",
"_calculateFormulaValue",
"(",
"$",
"fractionFormula",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] |
Identify whether a string contains a fractional numeric value,
and convert it to a numeric if it is
@param string &$operand string value to test
@return boolean
|
[
"Identify",
"whether",
"a",
"string",
"contains",
"a",
"fractional",
"numeric",
"value",
"and",
"convert",
"it",
"to",
"a",
"numeric",
"if",
"it",
"is"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Shared/String.php#L677-L686
|
218,320
|
moodle/moodle
|
mod/data/field/textarea/field.class.php
|
data_field_textarea.get_options
|
private function get_options() {
if (!isset($this->field->param5)) {
$this->field->param5 = 0;
}
$options = array();
$options['trusttext'] = false;
$options['forcehttps'] = false;
$options['subdirs'] = false;
$options['maxfiles'] = -1;
$options['context'] = $this->context;
$options['maxbytes'] = $this->field->param5;
$options['changeformat'] = 0;
$options['noclean'] = false;
return $options;
}
|
php
|
private function get_options() {
if (!isset($this->field->param5)) {
$this->field->param5 = 0;
}
$options = array();
$options['trusttext'] = false;
$options['forcehttps'] = false;
$options['subdirs'] = false;
$options['maxfiles'] = -1;
$options['context'] = $this->context;
$options['maxbytes'] = $this->field->param5;
$options['changeformat'] = 0;
$options['noclean'] = false;
return $options;
}
|
[
"private",
"function",
"get_options",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"field",
"->",
"param5",
")",
")",
"{",
"$",
"this",
"->",
"field",
"->",
"param5",
"=",
"0",
";",
"}",
"$",
"options",
"=",
"array",
"(",
")",
";",
"$",
"options",
"[",
"'trusttext'",
"]",
"=",
"false",
";",
"$",
"options",
"[",
"'forcehttps'",
"]",
"=",
"false",
";",
"$",
"options",
"[",
"'subdirs'",
"]",
"=",
"false",
";",
"$",
"options",
"[",
"'maxfiles'",
"]",
"=",
"-",
"1",
";",
"$",
"options",
"[",
"'context'",
"]",
"=",
"$",
"this",
"->",
"context",
";",
"$",
"options",
"[",
"'maxbytes'",
"]",
"=",
"$",
"this",
"->",
"field",
"->",
"param5",
";",
"$",
"options",
"[",
"'changeformat'",
"]",
"=",
"0",
";",
"$",
"options",
"[",
"'noclean'",
"]",
"=",
"false",
";",
"return",
"$",
"options",
";",
"}"
] |
Returns options for embedded files
@return array
|
[
"Returns",
"options",
"for",
"embedded",
"files"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/field/textarea/field.class.php#L42-L56
|
218,321
|
moodle/moodle
|
mod/data/field/textarea/field.class.php
|
data_field_textarea.display_browse_field
|
function display_browse_field($recordid, $template) {
global $DB;
if ($content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid))) {
if (isset($content->content)) {
$options = new stdClass();
if ($this->field->param1 == '1') { // We are autolinking this field, so disable linking within us
$options->filter = false;
}
$options->para = false;
$str = file_rewrite_pluginfile_urls($content->content, 'pluginfile.php', $this->context->id, 'mod_data', 'content', $content->id, $this->get_options());
$str = format_text($str, $content->content1, $options);
} else {
$str = '';
}
return $str;
}
return false;
}
|
php
|
function display_browse_field($recordid, $template) {
global $DB;
if ($content = $DB->get_record('data_content', array('fieldid' => $this->field->id, 'recordid' => $recordid))) {
if (isset($content->content)) {
$options = new stdClass();
if ($this->field->param1 == '1') { // We are autolinking this field, so disable linking within us
$options->filter = false;
}
$options->para = false;
$str = file_rewrite_pluginfile_urls($content->content, 'pluginfile.php', $this->context->id, 'mod_data', 'content', $content->id, $this->get_options());
$str = format_text($str, $content->content1, $options);
} else {
$str = '';
}
return $str;
}
return false;
}
|
[
"function",
"display_browse_field",
"(",
"$",
"recordid",
",",
"$",
"template",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"$",
"content",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'data_content'",
",",
"array",
"(",
"'fieldid'",
"=>",
"$",
"this",
"->",
"field",
"->",
"id",
",",
"'recordid'",
"=>",
"$",
"recordid",
")",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"content",
"->",
"content",
")",
")",
"{",
"$",
"options",
"=",
"new",
"stdClass",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"field",
"->",
"param1",
"==",
"'1'",
")",
"{",
"// We are autolinking this field, so disable linking within us",
"$",
"options",
"->",
"filter",
"=",
"false",
";",
"}",
"$",
"options",
"->",
"para",
"=",
"false",
";",
"$",
"str",
"=",
"file_rewrite_pluginfile_urls",
"(",
"$",
"content",
"->",
"content",
",",
"'pluginfile.php'",
",",
"$",
"this",
"->",
"context",
"->",
"id",
",",
"'mod_data'",
",",
"'content'",
",",
"$",
"content",
"->",
"id",
",",
"$",
"this",
"->",
"get_options",
"(",
")",
")",
";",
"$",
"str",
"=",
"format_text",
"(",
"$",
"str",
",",
"$",
"content",
"->",
"content1",
",",
"$",
"options",
")",
";",
"}",
"else",
"{",
"$",
"str",
"=",
"''",
";",
"}",
"return",
"$",
"str",
";",
"}",
"return",
"false",
";",
"}"
] |
Display the content of the field in browse mode
@param int $recordid
@param object $template
@return bool|string
|
[
"Display",
"the",
"content",
"of",
"the",
"field",
"in",
"browse",
"mode"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/field/textarea/field.class.php#L242-L260
|
218,322
|
moodle/moodle
|
course/classes/output/course_module_name.php
|
course_module_name.update
|
public static function update($itemid, $newvalue) {
$context = context_module::instance($itemid);
// Check access.
\external_api::validate_context($context);
require_capability('moodle/course:manageactivities', $context);
// Update value.
set_coursemodule_name($itemid, $newvalue);
$coursemodulerecord = get_coursemodule_from_id('', $itemid, 0, false, MUST_EXIST);
// Return instance.
$cm = get_fast_modinfo($coursemodulerecord->course)->get_cm($itemid);
return new static($cm, true);
}
|
php
|
public static function update($itemid, $newvalue) {
$context = context_module::instance($itemid);
// Check access.
\external_api::validate_context($context);
require_capability('moodle/course:manageactivities', $context);
// Update value.
set_coursemodule_name($itemid, $newvalue);
$coursemodulerecord = get_coursemodule_from_id('', $itemid, 0, false, MUST_EXIST);
// Return instance.
$cm = get_fast_modinfo($coursemodulerecord->course)->get_cm($itemid);
return new static($cm, true);
}
|
[
"public",
"static",
"function",
"update",
"(",
"$",
"itemid",
",",
"$",
"newvalue",
")",
"{",
"$",
"context",
"=",
"context_module",
"::",
"instance",
"(",
"$",
"itemid",
")",
";",
"// Check access.",
"\\",
"external_api",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"require_capability",
"(",
"'moodle/course:manageactivities'",
",",
"$",
"context",
")",
";",
"// Update value.",
"set_coursemodule_name",
"(",
"$",
"itemid",
",",
"$",
"newvalue",
")",
";",
"$",
"coursemodulerecord",
"=",
"get_coursemodule_from_id",
"(",
"''",
",",
"$",
"itemid",
",",
"0",
",",
"false",
",",
"MUST_EXIST",
")",
";",
"// Return instance.",
"$",
"cm",
"=",
"get_fast_modinfo",
"(",
"$",
"coursemodulerecord",
"->",
"course",
")",
"->",
"get_cm",
"(",
"$",
"itemid",
")",
";",
"return",
"new",
"static",
"(",
"$",
"cm",
",",
"true",
")",
";",
"}"
] |
Updates course module name
@param int $itemid course module id
@param string $newvalue new name
@return static
|
[
"Updates",
"course",
"module",
"name"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/output/course_module_name.php#L88-L99
|
218,323
|
moodle/moodle
|
lib/classes/output/mustache_template_source_loader.php
|
mustache_template_source_loader.load
|
public function load(
string $component,
string $name,
string $themename,
bool $includecomments = false
) : string {
// Get the template source from the callback.
$source = ($this->gettemplatesource)($component, $name, $themename);
// Remove comments from template.
if (!$includecomments) {
$source = $this->strip_template_comments($source);
}
return $source;
}
|
php
|
public function load(
string $component,
string $name,
string $themename,
bool $includecomments = false
) : string {
// Get the template source from the callback.
$source = ($this->gettemplatesource)($component, $name, $themename);
// Remove comments from template.
if (!$includecomments) {
$source = $this->strip_template_comments($source);
}
return $source;
}
|
[
"public",
"function",
"load",
"(",
"string",
"$",
"component",
",",
"string",
"$",
"name",
",",
"string",
"$",
"themename",
",",
"bool",
"$",
"includecomments",
"=",
"false",
")",
":",
"string",
"{",
"// Get the template source from the callback.",
"$",
"source",
"=",
"(",
"$",
"this",
"->",
"gettemplatesource",
")",
"(",
"$",
"component",
",",
"$",
"name",
",",
"$",
"themename",
")",
";",
"// Remove comments from template.",
"if",
"(",
"!",
"$",
"includecomments",
")",
"{",
"$",
"source",
"=",
"$",
"this",
"->",
"strip_template_comments",
"(",
"$",
"source",
")",
";",
"}",
"return",
"$",
"source",
";",
"}"
] |
Load the template source from the component and template name.
@param string $component The moodle component (e.g. core_message)
@param string $name The template name (e.g. message_drawer)
@param string $themename The theme to load the template for (e.g. boost)
@param bool $includecomments If the comments should be stripped from the source before returning
@return string The template source
|
[
"Load",
"the",
"template",
"source",
"from",
"the",
"component",
"and",
"template",
"name",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/output/mustache_template_source_loader.php#L85-L100
|
218,324
|
moodle/moodle
|
lib/classes/output/mustache_template_source_loader.php
|
mustache_template_source_loader.scan_template_source_for_dependencies
|
protected function scan_template_source_for_dependencies(string $source) : array {
$tokenizer = new Mustache_Tokenizer();
$tokens = $tokenizer->scan($source);
$templates = [];
$strings = [];
$addtodependencies = function($dependencies, $component, $id) {
$id = trim($id);
$component = trim($component);
if (!isset($dependencies[$component])) {
// Initialise the component if we haven't seen it before.
$dependencies[$component] = [];
}
// Add this id to the list of dependencies.
array_push($dependencies[$component], $id);
return $dependencies;
};
foreach ($tokens as $index => $token) {
$type = $token['type'];
$name = isset($token['name']) ? $token['name'] : null;
if ($name) {
switch ($type) {
case Mustache_Tokenizer::T_PARTIAL:
list($component, $id) = explode('/', $name);
$templates = $addtodependencies($templates, $component, $id);
break;
case Mustache_Tokenizer::T_PARENT:
list($component, $id) = explode('/', $name);
$templates = $addtodependencies($templates, $component, $id);
break;
case Mustache_Tokenizer::T_SECTION:
if ($name == 'str') {
// The token that containts the string identifiers (key and component) should
// immediately follow the #str token.
$identifiertoken = isset($tokens[$index + 1]) ? $tokens[$index + 1] : null;
if ($identifiertoken) {
// The string identifier is the key and component comma separated.
$identifierstring = $identifiertoken['value'];
$parts = explode(',', $identifierstring);
$id = $parts[0];
// Default to 'core' for the component, if not specified.
$component = isset($parts[1]) ? $parts[1] : 'core';
$strings = $addtodependencies($strings, $component, $id);
}
}
break;
}
}
}
return [
'templates' => $templates,
'strings' => $strings
];
}
|
php
|
protected function scan_template_source_for_dependencies(string $source) : array {
$tokenizer = new Mustache_Tokenizer();
$tokens = $tokenizer->scan($source);
$templates = [];
$strings = [];
$addtodependencies = function($dependencies, $component, $id) {
$id = trim($id);
$component = trim($component);
if (!isset($dependencies[$component])) {
// Initialise the component if we haven't seen it before.
$dependencies[$component] = [];
}
// Add this id to the list of dependencies.
array_push($dependencies[$component], $id);
return $dependencies;
};
foreach ($tokens as $index => $token) {
$type = $token['type'];
$name = isset($token['name']) ? $token['name'] : null;
if ($name) {
switch ($type) {
case Mustache_Tokenizer::T_PARTIAL:
list($component, $id) = explode('/', $name);
$templates = $addtodependencies($templates, $component, $id);
break;
case Mustache_Tokenizer::T_PARENT:
list($component, $id) = explode('/', $name);
$templates = $addtodependencies($templates, $component, $id);
break;
case Mustache_Tokenizer::T_SECTION:
if ($name == 'str') {
// The token that containts the string identifiers (key and component) should
// immediately follow the #str token.
$identifiertoken = isset($tokens[$index + 1]) ? $tokens[$index + 1] : null;
if ($identifiertoken) {
// The string identifier is the key and component comma separated.
$identifierstring = $identifiertoken['value'];
$parts = explode(',', $identifierstring);
$id = $parts[0];
// Default to 'core' for the component, if not specified.
$component = isset($parts[1]) ? $parts[1] : 'core';
$strings = $addtodependencies($strings, $component, $id);
}
}
break;
}
}
}
return [
'templates' => $templates,
'strings' => $strings
];
}
|
[
"protected",
"function",
"scan_template_source_for_dependencies",
"(",
"string",
"$",
"source",
")",
":",
"array",
"{",
"$",
"tokenizer",
"=",
"new",
"Mustache_Tokenizer",
"(",
")",
";",
"$",
"tokens",
"=",
"$",
"tokenizer",
"->",
"scan",
"(",
"$",
"source",
")",
";",
"$",
"templates",
"=",
"[",
"]",
";",
"$",
"strings",
"=",
"[",
"]",
";",
"$",
"addtodependencies",
"=",
"function",
"(",
"$",
"dependencies",
",",
"$",
"component",
",",
"$",
"id",
")",
"{",
"$",
"id",
"=",
"trim",
"(",
"$",
"id",
")",
";",
"$",
"component",
"=",
"trim",
"(",
"$",
"component",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"dependencies",
"[",
"$",
"component",
"]",
")",
")",
"{",
"// Initialise the component if we haven't seen it before.",
"$",
"dependencies",
"[",
"$",
"component",
"]",
"=",
"[",
"]",
";",
"}",
"// Add this id to the list of dependencies.",
"array_push",
"(",
"$",
"dependencies",
"[",
"$",
"component",
"]",
",",
"$",
"id",
")",
";",
"return",
"$",
"dependencies",
";",
"}",
";",
"foreach",
"(",
"$",
"tokens",
"as",
"$",
"index",
"=>",
"$",
"token",
")",
"{",
"$",
"type",
"=",
"$",
"token",
"[",
"'type'",
"]",
";",
"$",
"name",
"=",
"isset",
"(",
"$",
"token",
"[",
"'name'",
"]",
")",
"?",
"$",
"token",
"[",
"'name'",
"]",
":",
"null",
";",
"if",
"(",
"$",
"name",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"Mustache_Tokenizer",
"::",
"T_PARTIAL",
":",
"list",
"(",
"$",
"component",
",",
"$",
"id",
")",
"=",
"explode",
"(",
"'/'",
",",
"$",
"name",
")",
";",
"$",
"templates",
"=",
"$",
"addtodependencies",
"(",
"$",
"templates",
",",
"$",
"component",
",",
"$",
"id",
")",
";",
"break",
";",
"case",
"Mustache_Tokenizer",
"::",
"T_PARENT",
":",
"list",
"(",
"$",
"component",
",",
"$",
"id",
")",
"=",
"explode",
"(",
"'/'",
",",
"$",
"name",
")",
";",
"$",
"templates",
"=",
"$",
"addtodependencies",
"(",
"$",
"templates",
",",
"$",
"component",
",",
"$",
"id",
")",
";",
"break",
";",
"case",
"Mustache_Tokenizer",
"::",
"T_SECTION",
":",
"if",
"(",
"$",
"name",
"==",
"'str'",
")",
"{",
"// The token that containts the string identifiers (key and component) should",
"// immediately follow the #str token.",
"$",
"identifiertoken",
"=",
"isset",
"(",
"$",
"tokens",
"[",
"$",
"index",
"+",
"1",
"]",
")",
"?",
"$",
"tokens",
"[",
"$",
"index",
"+",
"1",
"]",
":",
"null",
";",
"if",
"(",
"$",
"identifiertoken",
")",
"{",
"// The string identifier is the key and component comma separated.",
"$",
"identifierstring",
"=",
"$",
"identifiertoken",
"[",
"'value'",
"]",
";",
"$",
"parts",
"=",
"explode",
"(",
"','",
",",
"$",
"identifierstring",
")",
";",
"$",
"id",
"=",
"$",
"parts",
"[",
"0",
"]",
";",
"// Default to 'core' for the component, if not specified.",
"$",
"component",
"=",
"isset",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
"?",
"$",
"parts",
"[",
"1",
"]",
":",
"'core'",
";",
"$",
"strings",
"=",
"$",
"addtodependencies",
"(",
"$",
"strings",
",",
"$",
"component",
",",
"$",
"id",
")",
";",
"}",
"}",
"break",
";",
"}",
"}",
"}",
"return",
"[",
"'templates'",
"=>",
"$",
"templates",
",",
"'strings'",
"=>",
"$",
"strings",
"]",
";",
"}"
] |
Scan over a template source string and return a list of dependencies it requires.
At the moment the list will only include other templates and strings.
The return format is an array indexed with the dependency type (e.g. templates / strings) then
the component (e.g. core_message) with it's value being an array of the items required
in that component.
For example:
If we have a template foo that includes 2 templates, bar and baz, and also 2 strings
'home' and 'help' from the core component then the return value would look like:
[
'templates' => [
'core' => ['foo', 'bar', 'baz']
],
'strings' => [
'core' => ['home', 'help']
]
]
@param string $source The template source
@return array
|
[
"Scan",
"over",
"a",
"template",
"source",
"string",
"and",
"return",
"a",
"list",
"of",
"dependencies",
"it",
"requires",
".",
"At",
"the",
"moment",
"the",
"list",
"will",
"only",
"include",
"other",
"templates",
"and",
"strings",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/output/mustache_template_source_loader.php#L284-L343
|
218,325
|
moodle/moodle
|
lib/htmlpurifier/HTMLPurifier/Queue.php
|
HTMLPurifier_Queue.shift
|
public function shift() {
if (empty($this->output)) {
$this->output = array_reverse($this->input);
$this->input = array();
}
if (empty($this->output)) {
return NULL;
}
return array_pop($this->output);
}
|
php
|
public function shift() {
if (empty($this->output)) {
$this->output = array_reverse($this->input);
$this->input = array();
}
if (empty($this->output)) {
return NULL;
}
return array_pop($this->output);
}
|
[
"public",
"function",
"shift",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"output",
")",
")",
"{",
"$",
"this",
"->",
"output",
"=",
"array_reverse",
"(",
"$",
"this",
"->",
"input",
")",
";",
"$",
"this",
"->",
"input",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"output",
")",
")",
"{",
"return",
"NULL",
";",
"}",
"return",
"array_pop",
"(",
"$",
"this",
"->",
"output",
")",
";",
"}"
] |
Shifts an element off the front of the queue.
|
[
"Shifts",
"an",
"element",
"off",
"the",
"front",
"of",
"the",
"queue",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Queue.php#L32-L41
|
218,326
|
moodle/moodle
|
lib/mlbackend/php/phpml/src/Phpml/Classification/Linear/Perceptron.php
|
Perceptron.runTraining
|
protected function runTraining(array $samples, array $targets)
{
// The cost function is the sum of squares
$callback = function ($weights, $sample, $target) {
$this->weights = $weights;
$prediction = $this->outputClass($sample);
$gradient = $prediction - $target;
$error = $gradient**2;
return [$error, $gradient];
};
$this->runGradientDescent($samples, $targets, $callback);
}
|
php
|
protected function runTraining(array $samples, array $targets)
{
// The cost function is the sum of squares
$callback = function ($weights, $sample, $target) {
$this->weights = $weights;
$prediction = $this->outputClass($sample);
$gradient = $prediction - $target;
$error = $gradient**2;
return [$error, $gradient];
};
$this->runGradientDescent($samples, $targets, $callback);
}
|
[
"protected",
"function",
"runTraining",
"(",
"array",
"$",
"samples",
",",
"array",
"$",
"targets",
")",
"{",
"// The cost function is the sum of squares",
"$",
"callback",
"=",
"function",
"(",
"$",
"weights",
",",
"$",
"sample",
",",
"$",
"target",
")",
"{",
"$",
"this",
"->",
"weights",
"=",
"$",
"weights",
";",
"$",
"prediction",
"=",
"$",
"this",
"->",
"outputClass",
"(",
"$",
"sample",
")",
";",
"$",
"gradient",
"=",
"$",
"prediction",
"-",
"$",
"target",
";",
"$",
"error",
"=",
"$",
"gradient",
"**",
"2",
";",
"return",
"[",
"$",
"error",
",",
"$",
"gradient",
"]",
";",
"}",
";",
"$",
"this",
"->",
"runGradientDescent",
"(",
"$",
"samples",
",",
"$",
"targets",
",",
"$",
"callback",
")",
";",
"}"
] |
Trains the perceptron model with Stochastic Gradient Descent optimization
to get the correct set of weights
@param array $samples
@param array $targets
|
[
"Trains",
"the",
"perceptron",
"model",
"with",
"Stochastic",
"Gradient",
"Descent",
"optimization",
"to",
"get",
"the",
"correct",
"set",
"of",
"weights"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mlbackend/php/phpml/src/Phpml/Classification/Linear/Perceptron.php#L170-L184
|
218,327
|
moodle/moodle
|
lib/mlbackend/php/phpml/src/Phpml/Classification/Linear/Perceptron.php
|
Perceptron.runGradientDescent
|
protected function runGradientDescent(array $samples, array $targets, \Closure $gradientFunc, bool $isBatch = false)
{
$class = $isBatch ? GD::class : StochasticGD::class;
if (empty($this->optimizer)) {
$this->optimizer = (new $class($this->featureCount))
->setLearningRate($this->learningRate)
->setMaxIterations($this->maxIterations)
->setChangeThreshold(1e-6)
->setEarlyStop($this->enableEarlyStop);
}
$this->weights = $this->optimizer->runOptimization($samples, $targets, $gradientFunc);
$this->costValues = $this->optimizer->getCostValues();
}
|
php
|
protected function runGradientDescent(array $samples, array $targets, \Closure $gradientFunc, bool $isBatch = false)
{
$class = $isBatch ? GD::class : StochasticGD::class;
if (empty($this->optimizer)) {
$this->optimizer = (new $class($this->featureCount))
->setLearningRate($this->learningRate)
->setMaxIterations($this->maxIterations)
->setChangeThreshold(1e-6)
->setEarlyStop($this->enableEarlyStop);
}
$this->weights = $this->optimizer->runOptimization($samples, $targets, $gradientFunc);
$this->costValues = $this->optimizer->getCostValues();
}
|
[
"protected",
"function",
"runGradientDescent",
"(",
"array",
"$",
"samples",
",",
"array",
"$",
"targets",
",",
"\\",
"Closure",
"$",
"gradientFunc",
",",
"bool",
"$",
"isBatch",
"=",
"false",
")",
"{",
"$",
"class",
"=",
"$",
"isBatch",
"?",
"GD",
"::",
"class",
":",
"StochasticGD",
"::",
"class",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"optimizer",
")",
")",
"{",
"$",
"this",
"->",
"optimizer",
"=",
"(",
"new",
"$",
"class",
"(",
"$",
"this",
"->",
"featureCount",
")",
")",
"->",
"setLearningRate",
"(",
"$",
"this",
"->",
"learningRate",
")",
"->",
"setMaxIterations",
"(",
"$",
"this",
"->",
"maxIterations",
")",
"->",
"setChangeThreshold",
"(",
"1e-6",
")",
"->",
"setEarlyStop",
"(",
"$",
"this",
"->",
"enableEarlyStop",
")",
";",
"}",
"$",
"this",
"->",
"weights",
"=",
"$",
"this",
"->",
"optimizer",
"->",
"runOptimization",
"(",
"$",
"samples",
",",
"$",
"targets",
",",
"$",
"gradientFunc",
")",
";",
"$",
"this",
"->",
"costValues",
"=",
"$",
"this",
"->",
"optimizer",
"->",
"getCostValues",
"(",
")",
";",
"}"
] |
Executes a Gradient Descent algorithm for
the given cost function
@param array $samples
@param array $targets
@param \Closure $gradientFunc
@param bool $isBatch
|
[
"Executes",
"a",
"Gradient",
"Descent",
"algorithm",
"for",
"the",
"given",
"cost",
"function"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mlbackend/php/phpml/src/Phpml/Classification/Linear/Perceptron.php#L195-L209
|
218,328
|
moodle/moodle
|
lib/mlbackend/php/phpml/src/Phpml/Classification/Linear/Perceptron.php
|
Perceptron.checkNormalizedSample
|
protected function checkNormalizedSample(array $sample)
{
if ($this->normalizer) {
$samples = [$sample];
$this->normalizer->transform($samples);
$sample = $samples[0];
}
return $sample;
}
|
php
|
protected function checkNormalizedSample(array $sample)
{
if ($this->normalizer) {
$samples = [$sample];
$this->normalizer->transform($samples);
$sample = $samples[0];
}
return $sample;
}
|
[
"protected",
"function",
"checkNormalizedSample",
"(",
"array",
"$",
"sample",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"normalizer",
")",
"{",
"$",
"samples",
"=",
"[",
"$",
"sample",
"]",
";",
"$",
"this",
"->",
"normalizer",
"->",
"transform",
"(",
"$",
"samples",
")",
";",
"$",
"sample",
"=",
"$",
"samples",
"[",
"0",
"]",
";",
"}",
"return",
"$",
"sample",
";",
"}"
] |
Checks if the sample should be normalized and if so, returns the
normalized sample
@param array $sample
@return array
|
[
"Checks",
"if",
"the",
"sample",
"should",
"be",
"normalized",
"and",
"if",
"so",
"returns",
"the",
"normalized",
"sample"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mlbackend/php/phpml/src/Phpml/Classification/Linear/Perceptron.php#L219-L228
|
218,329
|
moodle/moodle
|
mod/quiz/locallib.php
|
mod_quiz_display_options.make_from_quiz
|
public static function make_from_quiz($quiz, $when) {
$options = new self();
$options->attempt = self::extract($quiz->reviewattempt, $when, true, false);
$options->correctness = self::extract($quiz->reviewcorrectness, $when);
$options->marks = self::extract($quiz->reviewmarks, $when,
self::MARK_AND_MAX, self::MAX_ONLY);
$options->feedback = self::extract($quiz->reviewspecificfeedback, $when);
$options->generalfeedback = self::extract($quiz->reviewgeneralfeedback, $when);
$options->rightanswer = self::extract($quiz->reviewrightanswer, $when);
$options->overallfeedback = self::extract($quiz->reviewoverallfeedback, $when);
$options->numpartscorrect = $options->feedback;
$options->manualcomment = $options->feedback;
if ($quiz->questiondecimalpoints != -1) {
$options->markdp = $quiz->questiondecimalpoints;
} else {
$options->markdp = $quiz->decimalpoints;
}
return $options;
}
|
php
|
public static function make_from_quiz($quiz, $when) {
$options = new self();
$options->attempt = self::extract($quiz->reviewattempt, $when, true, false);
$options->correctness = self::extract($quiz->reviewcorrectness, $when);
$options->marks = self::extract($quiz->reviewmarks, $when,
self::MARK_AND_MAX, self::MAX_ONLY);
$options->feedback = self::extract($quiz->reviewspecificfeedback, $when);
$options->generalfeedback = self::extract($quiz->reviewgeneralfeedback, $when);
$options->rightanswer = self::extract($quiz->reviewrightanswer, $when);
$options->overallfeedback = self::extract($quiz->reviewoverallfeedback, $when);
$options->numpartscorrect = $options->feedback;
$options->manualcomment = $options->feedback;
if ($quiz->questiondecimalpoints != -1) {
$options->markdp = $quiz->questiondecimalpoints;
} else {
$options->markdp = $quiz->decimalpoints;
}
return $options;
}
|
[
"public",
"static",
"function",
"make_from_quiz",
"(",
"$",
"quiz",
",",
"$",
"when",
")",
"{",
"$",
"options",
"=",
"new",
"self",
"(",
")",
";",
"$",
"options",
"->",
"attempt",
"=",
"self",
"::",
"extract",
"(",
"$",
"quiz",
"->",
"reviewattempt",
",",
"$",
"when",
",",
"true",
",",
"false",
")",
";",
"$",
"options",
"->",
"correctness",
"=",
"self",
"::",
"extract",
"(",
"$",
"quiz",
"->",
"reviewcorrectness",
",",
"$",
"when",
")",
";",
"$",
"options",
"->",
"marks",
"=",
"self",
"::",
"extract",
"(",
"$",
"quiz",
"->",
"reviewmarks",
",",
"$",
"when",
",",
"self",
"::",
"MARK_AND_MAX",
",",
"self",
"::",
"MAX_ONLY",
")",
";",
"$",
"options",
"->",
"feedback",
"=",
"self",
"::",
"extract",
"(",
"$",
"quiz",
"->",
"reviewspecificfeedback",
",",
"$",
"when",
")",
";",
"$",
"options",
"->",
"generalfeedback",
"=",
"self",
"::",
"extract",
"(",
"$",
"quiz",
"->",
"reviewgeneralfeedback",
",",
"$",
"when",
")",
";",
"$",
"options",
"->",
"rightanswer",
"=",
"self",
"::",
"extract",
"(",
"$",
"quiz",
"->",
"reviewrightanswer",
",",
"$",
"when",
")",
";",
"$",
"options",
"->",
"overallfeedback",
"=",
"self",
"::",
"extract",
"(",
"$",
"quiz",
"->",
"reviewoverallfeedback",
",",
"$",
"when",
")",
";",
"$",
"options",
"->",
"numpartscorrect",
"=",
"$",
"options",
"->",
"feedback",
";",
"$",
"options",
"->",
"manualcomment",
"=",
"$",
"options",
"->",
"feedback",
";",
"if",
"(",
"$",
"quiz",
"->",
"questiondecimalpoints",
"!=",
"-",
"1",
")",
"{",
"$",
"options",
"->",
"markdp",
"=",
"$",
"quiz",
"->",
"questiondecimalpoints",
";",
"}",
"else",
"{",
"$",
"options",
"->",
"markdp",
"=",
"$",
"quiz",
"->",
"decimalpoints",
";",
"}",
"return",
"$",
"options",
";",
"}"
] |
Set up the various options from the quiz settings, and a time constant.
@param object $quiz the quiz settings.
@param int $one of the {@link DURING}, {@link IMMEDIATELY_AFTER},
{@link LATER_WHILE_OPEN} or {@link AFTER_CLOSE} constants.
@return mod_quiz_display_options set up appropriately.
|
[
"Set",
"up",
"the",
"various",
"options",
"from",
"the",
"quiz",
"settings",
"and",
"a",
"time",
"constant",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/locallib.php#L1949-L1971
|
218,330
|
moodle/moodle
|
calendar/classes/external/events_related_objects_cache.php
|
events_related_objects_cache.get_course
|
public function get_course(event_interface $event) {
if (is_null($this->courses)) {
$this->load_courses();
}
if ($course = $event->get_course()) {
$courseid = $course->get('id');
return isset($this->courses[$courseid]) ? $this->courses[$courseid] : null;
} else {
return null;
}
}
|
php
|
public function get_course(event_interface $event) {
if (is_null($this->courses)) {
$this->load_courses();
}
if ($course = $event->get_course()) {
$courseid = $course->get('id');
return isset($this->courses[$courseid]) ? $this->courses[$courseid] : null;
} else {
return null;
}
}
|
[
"public",
"function",
"get_course",
"(",
"event_interface",
"$",
"event",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"courses",
")",
")",
"{",
"$",
"this",
"->",
"load_courses",
"(",
")",
";",
"}",
"if",
"(",
"$",
"course",
"=",
"$",
"event",
"->",
"get_course",
"(",
")",
")",
"{",
"$",
"courseid",
"=",
"$",
"course",
"->",
"get",
"(",
"'id'",
")",
";",
"return",
"isset",
"(",
"$",
"this",
"->",
"courses",
"[",
"$",
"courseid",
"]",
")",
"?",
"$",
"this",
"->",
"courses",
"[",
"$",
"courseid",
"]",
":",
"null",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] |
Get the related course object for a given event.
@param event_interface $event The event object.
@return stdClass|null
|
[
"Get",
"the",
"related",
"course",
"object",
"for",
"a",
"given",
"event",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/external/events_related_objects_cache.php#L95-L106
|
218,331
|
moodle/moodle
|
calendar/classes/external/events_related_objects_cache.php
|
events_related_objects_cache.get_context
|
public function get_context(event_interface $event) {
global $USER;
$courseid = $event->get_course() ? $event->get_course()->get('id') : null;
$groupid = $event->get_group() ? $event->get_group()->get('id') : null;
$userid = $event->get_user() ? $event->get_user()->get('id') : null;
$moduleid = $event->get_course_module() ? $event->get_course_module()->get('id') : null;
if (!empty($courseid)) {
return \context_course::instance($event->get_course()->get('id'));
} else if (!empty($groupid)) {
$group = $this->get_group($event);
return \context_course::instance($group->courseid);
} else if (!empty($userid) && $userid == $USER->id) {
return \context_user::instance($userid);
} else if (!empty($userid) && $userid != $USER->id && $moduleid && $moduleid > 0) {
$cm = $this->get_course_module($event);
return \context_course::instance($cm->course);
} else {
return \context_user::instance($userid);
}
}
|
php
|
public function get_context(event_interface $event) {
global $USER;
$courseid = $event->get_course() ? $event->get_course()->get('id') : null;
$groupid = $event->get_group() ? $event->get_group()->get('id') : null;
$userid = $event->get_user() ? $event->get_user()->get('id') : null;
$moduleid = $event->get_course_module() ? $event->get_course_module()->get('id') : null;
if (!empty($courseid)) {
return \context_course::instance($event->get_course()->get('id'));
} else if (!empty($groupid)) {
$group = $this->get_group($event);
return \context_course::instance($group->courseid);
} else if (!empty($userid) && $userid == $USER->id) {
return \context_user::instance($userid);
} else if (!empty($userid) && $userid != $USER->id && $moduleid && $moduleid > 0) {
$cm = $this->get_course_module($event);
return \context_course::instance($cm->course);
} else {
return \context_user::instance($userid);
}
}
|
[
"public",
"function",
"get_context",
"(",
"event_interface",
"$",
"event",
")",
"{",
"global",
"$",
"USER",
";",
"$",
"courseid",
"=",
"$",
"event",
"->",
"get_course",
"(",
")",
"?",
"$",
"event",
"->",
"get_course",
"(",
")",
"->",
"get",
"(",
"'id'",
")",
":",
"null",
";",
"$",
"groupid",
"=",
"$",
"event",
"->",
"get_group",
"(",
")",
"?",
"$",
"event",
"->",
"get_group",
"(",
")",
"->",
"get",
"(",
"'id'",
")",
":",
"null",
";",
"$",
"userid",
"=",
"$",
"event",
"->",
"get_user",
"(",
")",
"?",
"$",
"event",
"->",
"get_user",
"(",
")",
"->",
"get",
"(",
"'id'",
")",
":",
"null",
";",
"$",
"moduleid",
"=",
"$",
"event",
"->",
"get_course_module",
"(",
")",
"?",
"$",
"event",
"->",
"get_course_module",
"(",
")",
"->",
"get",
"(",
"'id'",
")",
":",
"null",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"courseid",
")",
")",
"{",
"return",
"\\",
"context_course",
"::",
"instance",
"(",
"$",
"event",
"->",
"get_course",
"(",
")",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"}",
"else",
"if",
"(",
"!",
"empty",
"(",
"$",
"groupid",
")",
")",
"{",
"$",
"group",
"=",
"$",
"this",
"->",
"get_group",
"(",
"$",
"event",
")",
";",
"return",
"\\",
"context_course",
"::",
"instance",
"(",
"$",
"group",
"->",
"courseid",
")",
";",
"}",
"else",
"if",
"(",
"!",
"empty",
"(",
"$",
"userid",
")",
"&&",
"$",
"userid",
"==",
"$",
"USER",
"->",
"id",
")",
"{",
"return",
"\\",
"context_user",
"::",
"instance",
"(",
"$",
"userid",
")",
";",
"}",
"else",
"if",
"(",
"!",
"empty",
"(",
"$",
"userid",
")",
"&&",
"$",
"userid",
"!=",
"$",
"USER",
"->",
"id",
"&&",
"$",
"moduleid",
"&&",
"$",
"moduleid",
">",
"0",
")",
"{",
"$",
"cm",
"=",
"$",
"this",
"->",
"get_course_module",
"(",
"$",
"event",
")",
";",
"return",
"\\",
"context_course",
"::",
"instance",
"(",
"$",
"cm",
"->",
"course",
")",
";",
"}",
"else",
"{",
"return",
"\\",
"context_user",
"::",
"instance",
"(",
"$",
"userid",
")",
";",
"}",
"}"
] |
Get the related context for a given event.
@param event_interface $event The event object.
@return context|null
|
[
"Get",
"the",
"related",
"context",
"for",
"a",
"given",
"event",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/external/events_related_objects_cache.php#L114-L135
|
218,332
|
moodle/moodle
|
calendar/classes/external/events_related_objects_cache.php
|
events_related_objects_cache.get_group
|
public function get_group(event_interface $event) {
if (is_null($this->groups)) {
$this->load_groups();
}
if ($group = $event->get_group()) {
$groupid = $group->get('id');
return isset($this->groups[$groupid]) ? $this->groups[$groupid] : null;
} else {
return null;
}
}
|
php
|
public function get_group(event_interface $event) {
if (is_null($this->groups)) {
$this->load_groups();
}
if ($group = $event->get_group()) {
$groupid = $group->get('id');
return isset($this->groups[$groupid]) ? $this->groups[$groupid] : null;
} else {
return null;
}
}
|
[
"public",
"function",
"get_group",
"(",
"event_interface",
"$",
"event",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"groups",
")",
")",
"{",
"$",
"this",
"->",
"load_groups",
"(",
")",
";",
"}",
"if",
"(",
"$",
"group",
"=",
"$",
"event",
"->",
"get_group",
"(",
")",
")",
"{",
"$",
"groupid",
"=",
"$",
"group",
"->",
"get",
"(",
"'id'",
")",
";",
"return",
"isset",
"(",
"$",
"this",
"->",
"groups",
"[",
"$",
"groupid",
"]",
")",
"?",
"$",
"this",
"->",
"groups",
"[",
"$",
"groupid",
"]",
":",
"null",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] |
Get the related group object for a given event.
@param event_interface $event The event object.
@return stdClass|null
|
[
"Get",
"the",
"related",
"group",
"object",
"for",
"a",
"given",
"event",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/external/events_related_objects_cache.php#L143-L154
|
218,333
|
moodle/moodle
|
calendar/classes/external/events_related_objects_cache.php
|
events_related_objects_cache.get_course_module
|
public function get_course_module(event_interface $event) {
if (!$event->get_course_module()) {
return null;
}
$id = $event->get_course_module()->get('id');
$name = $event->get_course_module()->get('modname');
$key = $name . '_' . $id;
if (!isset($this->coursemodules[$key])) {
$this->coursemodules[$key] = get_coursemodule_from_instance($name, $id, 0, false, MUST_EXIST);
}
return $this->coursemodules[$key];
}
|
php
|
public function get_course_module(event_interface $event) {
if (!$event->get_course_module()) {
return null;
}
$id = $event->get_course_module()->get('id');
$name = $event->get_course_module()->get('modname');
$key = $name . '_' . $id;
if (!isset($this->coursemodules[$key])) {
$this->coursemodules[$key] = get_coursemodule_from_instance($name, $id, 0, false, MUST_EXIST);
}
return $this->coursemodules[$key];
}
|
[
"public",
"function",
"get_course_module",
"(",
"event_interface",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"$",
"event",
"->",
"get_course_module",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"id",
"=",
"$",
"event",
"->",
"get_course_module",
"(",
")",
"->",
"get",
"(",
"'id'",
")",
";",
"$",
"name",
"=",
"$",
"event",
"->",
"get_course_module",
"(",
")",
"->",
"get",
"(",
"'modname'",
")",
";",
"$",
"key",
"=",
"$",
"name",
".",
"'_'",
".",
"$",
"id",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"coursemodules",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"this",
"->",
"coursemodules",
"[",
"$",
"key",
"]",
"=",
"get_coursemodule_from_instance",
"(",
"$",
"name",
",",
"$",
"id",
",",
"0",
",",
"false",
",",
"MUST_EXIST",
")",
";",
"}",
"return",
"$",
"this",
"->",
"coursemodules",
"[",
"$",
"key",
"]",
";",
"}"
] |
Get the related course module for a given event.
@param event_interface $event The event object.
@return stdClass|null
|
[
"Get",
"the",
"related",
"course",
"module",
"for",
"a",
"given",
"event",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/external/events_related_objects_cache.php#L162-L176
|
218,334
|
moodle/moodle
|
calendar/classes/external/events_related_objects_cache.php
|
events_related_objects_cache.get_module_instance
|
public function get_module_instance(event_interface $event) {
if (!$event->get_course_module()) {
return null;
}
if (is_null($this->moduleinstances)) {
$this->load_module_instances();
}
$id = $event->get_course_module()->get('instance');
$name = $event->get_course_module()->get('modname');
if (isset($this->moduleinstances[$name])) {
if (isset($this->moduleinstances[$name][$id])) {
return $this->moduleinstances[$name][$id];
}
}
return null;
}
|
php
|
public function get_module_instance(event_interface $event) {
if (!$event->get_course_module()) {
return null;
}
if (is_null($this->moduleinstances)) {
$this->load_module_instances();
}
$id = $event->get_course_module()->get('instance');
$name = $event->get_course_module()->get('modname');
if (isset($this->moduleinstances[$name])) {
if (isset($this->moduleinstances[$name][$id])) {
return $this->moduleinstances[$name][$id];
}
}
return null;
}
|
[
"public",
"function",
"get_module_instance",
"(",
"event_interface",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"$",
"event",
"->",
"get_course_module",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"moduleinstances",
")",
")",
"{",
"$",
"this",
"->",
"load_module_instances",
"(",
")",
";",
"}",
"$",
"id",
"=",
"$",
"event",
"->",
"get_course_module",
"(",
")",
"->",
"get",
"(",
"'instance'",
")",
";",
"$",
"name",
"=",
"$",
"event",
"->",
"get_course_module",
"(",
")",
"->",
"get",
"(",
"'modname'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"moduleinstances",
"[",
"$",
"name",
"]",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"moduleinstances",
"[",
"$",
"name",
"]",
"[",
"$",
"id",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"moduleinstances",
"[",
"$",
"name",
"]",
"[",
"$",
"id",
"]",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Get the related module instance for a given event.
@param event_interface $event The event object.
@return stdClass|null
|
[
"Get",
"the",
"related",
"module",
"instance",
"for",
"a",
"given",
"event",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/external/events_related_objects_cache.php#L184-L203
|
218,335
|
moodle/moodle
|
calendar/classes/external/events_related_objects_cache.php
|
events_related_objects_cache.load_courses
|
protected function load_courses() {
global $DB;
$courseids = [];
foreach ($this->events as $event) {
if ($course = $event->get_course()) {
$id = $course->get('id');
$courseids[$id] = true;
}
}
if (empty($courseids)) {
$this->courses = [];
return;
}
list($idsql, $params) = $DB->get_in_or_equal(array_keys($courseids));
$sql = "SELECT * FROM {course} WHERE id {$idsql}";
$this->courses = $DB->get_records_sql($sql, $params);
}
|
php
|
protected function load_courses() {
global $DB;
$courseids = [];
foreach ($this->events as $event) {
if ($course = $event->get_course()) {
$id = $course->get('id');
$courseids[$id] = true;
}
}
if (empty($courseids)) {
$this->courses = [];
return;
}
list($idsql, $params) = $DB->get_in_or_equal(array_keys($courseids));
$sql = "SELECT * FROM {course} WHERE id {$idsql}";
$this->courses = $DB->get_records_sql($sql, $params);
}
|
[
"protected",
"function",
"load_courses",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"courseids",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"events",
"as",
"$",
"event",
")",
"{",
"if",
"(",
"$",
"course",
"=",
"$",
"event",
"->",
"get_course",
"(",
")",
")",
"{",
"$",
"id",
"=",
"$",
"course",
"->",
"get",
"(",
"'id'",
")",
";",
"$",
"courseids",
"[",
"$",
"id",
"]",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"courseids",
")",
")",
"{",
"$",
"this",
"->",
"courses",
"=",
"[",
"]",
";",
"return",
";",
"}",
"list",
"(",
"$",
"idsql",
",",
"$",
"params",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"array_keys",
"(",
"$",
"courseids",
")",
")",
";",
"$",
"sql",
"=",
"\"SELECT * FROM {course} WHERE id {$idsql}\"",
";",
"$",
"this",
"->",
"courses",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"}"
] |
Load the list of all of the distinct courses required for the
list of provided events and save the result in memory.
|
[
"Load",
"the",
"list",
"of",
"all",
"of",
"the",
"distinct",
"courses",
"required",
"for",
"the",
"list",
"of",
"provided",
"events",
"and",
"save",
"the",
"result",
"in",
"memory",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/external/events_related_objects_cache.php#L209-L229
|
218,336
|
moodle/moodle
|
calendar/classes/external/events_related_objects_cache.php
|
events_related_objects_cache.load_groups
|
protected function load_groups() {
global $DB;
$groupids = [];
foreach ($this->events as $event) {
if ($group = $event->get_group()) {
$id = $group->get('id');
$groupids[$id] = true;
}
}
if (empty($groupids)) {
$this->groups = [];
return;
}
list($idsql, $params) = $DB->get_in_or_equal(array_keys($groupids));
$sql = "SELECT * FROM {groups} WHERE id {$idsql}";
$this->groups = $DB->get_records_sql($sql, $params);
}
|
php
|
protected function load_groups() {
global $DB;
$groupids = [];
foreach ($this->events as $event) {
if ($group = $event->get_group()) {
$id = $group->get('id');
$groupids[$id] = true;
}
}
if (empty($groupids)) {
$this->groups = [];
return;
}
list($idsql, $params) = $DB->get_in_or_equal(array_keys($groupids));
$sql = "SELECT * FROM {groups} WHERE id {$idsql}";
$this->groups = $DB->get_records_sql($sql, $params);
}
|
[
"protected",
"function",
"load_groups",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"groupids",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"events",
"as",
"$",
"event",
")",
"{",
"if",
"(",
"$",
"group",
"=",
"$",
"event",
"->",
"get_group",
"(",
")",
")",
"{",
"$",
"id",
"=",
"$",
"group",
"->",
"get",
"(",
"'id'",
")",
";",
"$",
"groupids",
"[",
"$",
"id",
"]",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"groupids",
")",
")",
"{",
"$",
"this",
"->",
"groups",
"=",
"[",
"]",
";",
"return",
";",
"}",
"list",
"(",
"$",
"idsql",
",",
"$",
"params",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"array_keys",
"(",
"$",
"groupids",
")",
")",
";",
"$",
"sql",
"=",
"\"SELECT * FROM {groups} WHERE id {$idsql}\"",
";",
"$",
"this",
"->",
"groups",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"}"
] |
Load the list of all of the distinct groups required for the
list of provided events and save the result in memory.
|
[
"Load",
"the",
"list",
"of",
"all",
"of",
"the",
"distinct",
"groups",
"required",
"for",
"the",
"list",
"of",
"provided",
"events",
"and",
"save",
"the",
"result",
"in",
"memory",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/external/events_related_objects_cache.php#L235-L255
|
218,337
|
moodle/moodle
|
calendar/classes/external/events_related_objects_cache.php
|
events_related_objects_cache.load_module_instances
|
protected function load_module_instances() {
global $DB;
$this->moduleinstances = [];
$modulestoload = [];
foreach ($this->events as $event) {
if ($module = $event->get_course_module()) {
$id = $module->get('instance');
$name = $module->get('modname');
$ids = isset($modulestoload[$name]) ? $modulestoload[$name] : [];
$ids[$id] = true;
$modulestoload[$name] = $ids;
}
}
if (empty($modulestoload)) {
return;
}
foreach ($modulestoload as $modulename => $ids) {
list($idsql, $params) = $DB->get_in_or_equal(array_keys($ids));
$sql = "SELECT * FROM {" . $modulename . "} WHERE id {$idsql}";
$this->moduleinstances[$modulename] = $DB->get_records_sql($sql, $params);
}
}
|
php
|
protected function load_module_instances() {
global $DB;
$this->moduleinstances = [];
$modulestoload = [];
foreach ($this->events as $event) {
if ($module = $event->get_course_module()) {
$id = $module->get('instance');
$name = $module->get('modname');
$ids = isset($modulestoload[$name]) ? $modulestoload[$name] : [];
$ids[$id] = true;
$modulestoload[$name] = $ids;
}
}
if (empty($modulestoload)) {
return;
}
foreach ($modulestoload as $modulename => $ids) {
list($idsql, $params) = $DB->get_in_or_equal(array_keys($ids));
$sql = "SELECT * FROM {" . $modulename . "} WHERE id {$idsql}";
$this->moduleinstances[$modulename] = $DB->get_records_sql($sql, $params);
}
}
|
[
"protected",
"function",
"load_module_instances",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"this",
"->",
"moduleinstances",
"=",
"[",
"]",
";",
"$",
"modulestoload",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"events",
"as",
"$",
"event",
")",
"{",
"if",
"(",
"$",
"module",
"=",
"$",
"event",
"->",
"get_course_module",
"(",
")",
")",
"{",
"$",
"id",
"=",
"$",
"module",
"->",
"get",
"(",
"'instance'",
")",
";",
"$",
"name",
"=",
"$",
"module",
"->",
"get",
"(",
"'modname'",
")",
";",
"$",
"ids",
"=",
"isset",
"(",
"$",
"modulestoload",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"modulestoload",
"[",
"$",
"name",
"]",
":",
"[",
"]",
";",
"$",
"ids",
"[",
"$",
"id",
"]",
"=",
"true",
";",
"$",
"modulestoload",
"[",
"$",
"name",
"]",
"=",
"$",
"ids",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"modulestoload",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"modulestoload",
"as",
"$",
"modulename",
"=>",
"$",
"ids",
")",
"{",
"list",
"(",
"$",
"idsql",
",",
"$",
"params",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"array_keys",
"(",
"$",
"ids",
")",
")",
";",
"$",
"sql",
"=",
"\"SELECT * FROM {\"",
".",
"$",
"modulename",
".",
"\"} WHERE id {$idsql}\"",
";",
"$",
"this",
"->",
"moduleinstances",
"[",
"$",
"modulename",
"]",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"}",
"}"
] |
Load the list of all of the distinct module instances required for the
list of provided events and save the result in memory.
|
[
"Load",
"the",
"list",
"of",
"all",
"of",
"the",
"distinct",
"module",
"instances",
"required",
"for",
"the",
"list",
"of",
"provided",
"events",
"and",
"save",
"the",
"result",
"in",
"memory",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/external/events_related_objects_cache.php#L261-L286
|
218,338
|
moodle/moodle
|
lib/mlbackend/php/classes/processor.php
|
processor.train_classification
|
public function train_classification($uniqueid, \stored_file $dataset, $outputdir) {
$modelfilepath = $this->get_model_filepath($outputdir);
$modelmanager = new ModelManager();
if (file_exists($modelfilepath)) {
$classifier = $modelmanager->restoreFromFile($modelfilepath);
} else {
$classifier = new \Phpml\Classification\Linear\LogisticRegression(self::TRAIN_ITERATIONS, Normalizer::NORM_L2);
}
$fh = $dataset->get_content_file_handle();
// The first lines are var names and the second one values.
$metadata = $this->extract_metadata($fh);
// Skip headers.
fgets($fh);
$samples = array();
$targets = array();
while (($data = fgetcsv($fh)) !== false) {
$sampledata = array_map('floatval', $data);
$samples[] = array_slice($sampledata, 0, $metadata['nfeatures']);
$targets[] = intval($data[$metadata['nfeatures']]);
$nsamples = count($samples);
if ($nsamples === self::BATCH_SIZE) {
// Training it batches to avoid running out of memory.
$classifier->partialTrain($samples, $targets, array(0, 1));
$samples = array();
$targets = array();
}
if (empty($morethan1sample) && $nsamples > 1) {
$morethan1sample = true;
}
}
fclose($fh);
if (empty($morethan1sample)) {
$resultobj = new \stdClass();
$resultobj->status = \core_analytics\model::NO_DATASET;
$resultobj->info = array();
return $resultobj;
}
// Train the remaining samples.
if ($samples) {
$classifier->partialTrain($samples, $targets, array(0, 1));
}
$resultobj = new \stdClass();
$resultobj->status = \core_analytics\model::OK;
$resultobj->info = array();
// Store the trained model.
$modelmanager->saveToFile($classifier, $modelfilepath);
return $resultobj;
}
|
php
|
public function train_classification($uniqueid, \stored_file $dataset, $outputdir) {
$modelfilepath = $this->get_model_filepath($outputdir);
$modelmanager = new ModelManager();
if (file_exists($modelfilepath)) {
$classifier = $modelmanager->restoreFromFile($modelfilepath);
} else {
$classifier = new \Phpml\Classification\Linear\LogisticRegression(self::TRAIN_ITERATIONS, Normalizer::NORM_L2);
}
$fh = $dataset->get_content_file_handle();
// The first lines are var names and the second one values.
$metadata = $this->extract_metadata($fh);
// Skip headers.
fgets($fh);
$samples = array();
$targets = array();
while (($data = fgetcsv($fh)) !== false) {
$sampledata = array_map('floatval', $data);
$samples[] = array_slice($sampledata, 0, $metadata['nfeatures']);
$targets[] = intval($data[$metadata['nfeatures']]);
$nsamples = count($samples);
if ($nsamples === self::BATCH_SIZE) {
// Training it batches to avoid running out of memory.
$classifier->partialTrain($samples, $targets, array(0, 1));
$samples = array();
$targets = array();
}
if (empty($morethan1sample) && $nsamples > 1) {
$morethan1sample = true;
}
}
fclose($fh);
if (empty($morethan1sample)) {
$resultobj = new \stdClass();
$resultobj->status = \core_analytics\model::NO_DATASET;
$resultobj->info = array();
return $resultobj;
}
// Train the remaining samples.
if ($samples) {
$classifier->partialTrain($samples, $targets, array(0, 1));
}
$resultobj = new \stdClass();
$resultobj->status = \core_analytics\model::OK;
$resultobj->info = array();
// Store the trained model.
$modelmanager->saveToFile($classifier, $modelfilepath);
return $resultobj;
}
|
[
"public",
"function",
"train_classification",
"(",
"$",
"uniqueid",
",",
"\\",
"stored_file",
"$",
"dataset",
",",
"$",
"outputdir",
")",
"{",
"$",
"modelfilepath",
"=",
"$",
"this",
"->",
"get_model_filepath",
"(",
"$",
"outputdir",
")",
";",
"$",
"modelmanager",
"=",
"new",
"ModelManager",
"(",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"modelfilepath",
")",
")",
"{",
"$",
"classifier",
"=",
"$",
"modelmanager",
"->",
"restoreFromFile",
"(",
"$",
"modelfilepath",
")",
";",
"}",
"else",
"{",
"$",
"classifier",
"=",
"new",
"\\",
"Phpml",
"\\",
"Classification",
"\\",
"Linear",
"\\",
"LogisticRegression",
"(",
"self",
"::",
"TRAIN_ITERATIONS",
",",
"Normalizer",
"::",
"NORM_L2",
")",
";",
"}",
"$",
"fh",
"=",
"$",
"dataset",
"->",
"get_content_file_handle",
"(",
")",
";",
"// The first lines are var names and the second one values.",
"$",
"metadata",
"=",
"$",
"this",
"->",
"extract_metadata",
"(",
"$",
"fh",
")",
";",
"// Skip headers.",
"fgets",
"(",
"$",
"fh",
")",
";",
"$",
"samples",
"=",
"array",
"(",
")",
";",
"$",
"targets",
"=",
"array",
"(",
")",
";",
"while",
"(",
"(",
"$",
"data",
"=",
"fgetcsv",
"(",
"$",
"fh",
")",
")",
"!==",
"false",
")",
"{",
"$",
"sampledata",
"=",
"array_map",
"(",
"'floatval'",
",",
"$",
"data",
")",
";",
"$",
"samples",
"[",
"]",
"=",
"array_slice",
"(",
"$",
"sampledata",
",",
"0",
",",
"$",
"metadata",
"[",
"'nfeatures'",
"]",
")",
";",
"$",
"targets",
"[",
"]",
"=",
"intval",
"(",
"$",
"data",
"[",
"$",
"metadata",
"[",
"'nfeatures'",
"]",
"]",
")",
";",
"$",
"nsamples",
"=",
"count",
"(",
"$",
"samples",
")",
";",
"if",
"(",
"$",
"nsamples",
"===",
"self",
"::",
"BATCH_SIZE",
")",
"{",
"// Training it batches to avoid running out of memory.",
"$",
"classifier",
"->",
"partialTrain",
"(",
"$",
"samples",
",",
"$",
"targets",
",",
"array",
"(",
"0",
",",
"1",
")",
")",
";",
"$",
"samples",
"=",
"array",
"(",
")",
";",
"$",
"targets",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"morethan1sample",
")",
"&&",
"$",
"nsamples",
">",
"1",
")",
"{",
"$",
"morethan1sample",
"=",
"true",
";",
"}",
"}",
"fclose",
"(",
"$",
"fh",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"morethan1sample",
")",
")",
"{",
"$",
"resultobj",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"resultobj",
"->",
"status",
"=",
"\\",
"core_analytics",
"\\",
"model",
"::",
"NO_DATASET",
";",
"$",
"resultobj",
"->",
"info",
"=",
"array",
"(",
")",
";",
"return",
"$",
"resultobj",
";",
"}",
"// Train the remaining samples.",
"if",
"(",
"$",
"samples",
")",
"{",
"$",
"classifier",
"->",
"partialTrain",
"(",
"$",
"samples",
",",
"$",
"targets",
",",
"array",
"(",
"0",
",",
"1",
")",
")",
";",
"}",
"$",
"resultobj",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"resultobj",
"->",
"status",
"=",
"\\",
"core_analytics",
"\\",
"model",
"::",
"OK",
";",
"$",
"resultobj",
"->",
"info",
"=",
"array",
"(",
")",
";",
"// Store the trained model.",
"$",
"modelmanager",
"->",
"saveToFile",
"(",
"$",
"classifier",
",",
"$",
"modelfilepath",
")",
";",
"return",
"$",
"resultobj",
";",
"}"
] |
Train this processor classification model using the provided supervised learning dataset.
@param string $uniqueid
@param \stored_file $dataset
@param string $outputdir
@return \stdClass
|
[
"Train",
"this",
"processor",
"classification",
"model",
"using",
"the",
"provided",
"supervised",
"learning",
"dataset",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mlbackend/php/classes/processor.php#L104-L165
|
218,339
|
moodle/moodle
|
lib/mlbackend/php/classes/processor.php
|
processor.get_evaluation_result_object
|
protected function get_evaluation_result_object(\stored_file $dataset, $phis, $maxdeviation) {
// Average phi of all evaluations as final score.
if (count($phis) === 1) {
$avgphi = reset($phis);
} else {
$avgphi = \Phpml\Math\Statistic\Mean::arithmetic($phis);
}
// Standard deviation should ideally be calculated against the area under the curve.
if (count($phis) === 1) {
$modeldev = 0;
} else {
$modeldev = \Phpml\Math\Statistic\StandardDeviation::population($phis);
}
// Let's fill the results object.
$resultobj = new \stdClass();
// Zero is ok, now we add other bits if something is not right.
$resultobj->status = \core_analytics\model::OK;
$resultobj->info = array();
// Convert phi to a standard score (from -1 to 1 to a value between 0 and 1).
$resultobj->score = ($avgphi + 1) / 2;
// If each iteration results varied too much we need more data to confirm that this is a valid model.
if ($modeldev > $maxdeviation) {
$resultobj->status = $resultobj->status + \core_analytics\model::NOT_ENOUGH_DATA;
$a = new \stdClass();
$a->deviation = $modeldev;
$a->accepteddeviation = $maxdeviation;
$resultobj->info[] = get_string('errornotenoughdatadev', 'mlbackend_php', $a);
}
if ($resultobj->score < \core_analytics\model::MIN_SCORE) {
$resultobj->status = $resultobj->status + \core_analytics\model::LOW_SCORE;
$a = new \stdClass();
$a->score = $resultobj->score;
$a->minscore = \core_analytics\model::MIN_SCORE;
$resultobj->info[] = get_string('errorlowscore', 'mlbackend_php', $a);
}
if ($this->limitedsize === true) {
$resultobj->info[] = get_string('datasetsizelimited', 'mlbackend_php', display_size($dataset->get_filesize()));
}
return $resultobj;
}
|
php
|
protected function get_evaluation_result_object(\stored_file $dataset, $phis, $maxdeviation) {
// Average phi of all evaluations as final score.
if (count($phis) === 1) {
$avgphi = reset($phis);
} else {
$avgphi = \Phpml\Math\Statistic\Mean::arithmetic($phis);
}
// Standard deviation should ideally be calculated against the area under the curve.
if (count($phis) === 1) {
$modeldev = 0;
} else {
$modeldev = \Phpml\Math\Statistic\StandardDeviation::population($phis);
}
// Let's fill the results object.
$resultobj = new \stdClass();
// Zero is ok, now we add other bits if something is not right.
$resultobj->status = \core_analytics\model::OK;
$resultobj->info = array();
// Convert phi to a standard score (from -1 to 1 to a value between 0 and 1).
$resultobj->score = ($avgphi + 1) / 2;
// If each iteration results varied too much we need more data to confirm that this is a valid model.
if ($modeldev > $maxdeviation) {
$resultobj->status = $resultobj->status + \core_analytics\model::NOT_ENOUGH_DATA;
$a = new \stdClass();
$a->deviation = $modeldev;
$a->accepteddeviation = $maxdeviation;
$resultobj->info[] = get_string('errornotenoughdatadev', 'mlbackend_php', $a);
}
if ($resultobj->score < \core_analytics\model::MIN_SCORE) {
$resultobj->status = $resultobj->status + \core_analytics\model::LOW_SCORE;
$a = new \stdClass();
$a->score = $resultobj->score;
$a->minscore = \core_analytics\model::MIN_SCORE;
$resultobj->info[] = get_string('errorlowscore', 'mlbackend_php', $a);
}
if ($this->limitedsize === true) {
$resultobj->info[] = get_string('datasetsizelimited', 'mlbackend_php', display_size($dataset->get_filesize()));
}
return $resultobj;
}
|
[
"protected",
"function",
"get_evaluation_result_object",
"(",
"\\",
"stored_file",
"$",
"dataset",
",",
"$",
"phis",
",",
"$",
"maxdeviation",
")",
"{",
"// Average phi of all evaluations as final score.",
"if",
"(",
"count",
"(",
"$",
"phis",
")",
"===",
"1",
")",
"{",
"$",
"avgphi",
"=",
"reset",
"(",
"$",
"phis",
")",
";",
"}",
"else",
"{",
"$",
"avgphi",
"=",
"\\",
"Phpml",
"\\",
"Math",
"\\",
"Statistic",
"\\",
"Mean",
"::",
"arithmetic",
"(",
"$",
"phis",
")",
";",
"}",
"// Standard deviation should ideally be calculated against the area under the curve.",
"if",
"(",
"count",
"(",
"$",
"phis",
")",
"===",
"1",
")",
"{",
"$",
"modeldev",
"=",
"0",
";",
"}",
"else",
"{",
"$",
"modeldev",
"=",
"\\",
"Phpml",
"\\",
"Math",
"\\",
"Statistic",
"\\",
"StandardDeviation",
"::",
"population",
"(",
"$",
"phis",
")",
";",
"}",
"// Let's fill the results object.",
"$",
"resultobj",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"// Zero is ok, now we add other bits if something is not right.",
"$",
"resultobj",
"->",
"status",
"=",
"\\",
"core_analytics",
"\\",
"model",
"::",
"OK",
";",
"$",
"resultobj",
"->",
"info",
"=",
"array",
"(",
")",
";",
"// Convert phi to a standard score (from -1 to 1 to a value between 0 and 1).",
"$",
"resultobj",
"->",
"score",
"=",
"(",
"$",
"avgphi",
"+",
"1",
")",
"/",
"2",
";",
"// If each iteration results varied too much we need more data to confirm that this is a valid model.",
"if",
"(",
"$",
"modeldev",
">",
"$",
"maxdeviation",
")",
"{",
"$",
"resultobj",
"->",
"status",
"=",
"$",
"resultobj",
"->",
"status",
"+",
"\\",
"core_analytics",
"\\",
"model",
"::",
"NOT_ENOUGH_DATA",
";",
"$",
"a",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"a",
"->",
"deviation",
"=",
"$",
"modeldev",
";",
"$",
"a",
"->",
"accepteddeviation",
"=",
"$",
"maxdeviation",
";",
"$",
"resultobj",
"->",
"info",
"[",
"]",
"=",
"get_string",
"(",
"'errornotenoughdatadev'",
",",
"'mlbackend_php'",
",",
"$",
"a",
")",
";",
"}",
"if",
"(",
"$",
"resultobj",
"->",
"score",
"<",
"\\",
"core_analytics",
"\\",
"model",
"::",
"MIN_SCORE",
")",
"{",
"$",
"resultobj",
"->",
"status",
"=",
"$",
"resultobj",
"->",
"status",
"+",
"\\",
"core_analytics",
"\\",
"model",
"::",
"LOW_SCORE",
";",
"$",
"a",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"a",
"->",
"score",
"=",
"$",
"resultobj",
"->",
"score",
";",
"$",
"a",
"->",
"minscore",
"=",
"\\",
"core_analytics",
"\\",
"model",
"::",
"MIN_SCORE",
";",
"$",
"resultobj",
"->",
"info",
"[",
"]",
"=",
"get_string",
"(",
"'errorlowscore'",
",",
"'mlbackend_php'",
",",
"$",
"a",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"limitedsize",
"===",
"true",
")",
"{",
"$",
"resultobj",
"->",
"info",
"[",
"]",
"=",
"get_string",
"(",
"'datasetsizelimited'",
",",
"'mlbackend_php'",
",",
"display_size",
"(",
"$",
"dataset",
"->",
"get_filesize",
"(",
")",
")",
")",
";",
"}",
"return",
"$",
"resultobj",
";",
"}"
] |
Returns the results objects from all evaluations.
@param \stored_file $dataset
@param array $phis
@param float $maxdeviation
@return \stdClass
|
[
"Returns",
"the",
"results",
"objects",
"from",
"all",
"evaluations",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mlbackend/php/classes/processor.php#L343-L391
|
218,340
|
moodle/moodle
|
lib/mlbackend/php/classes/processor.php
|
processor.load_classifier
|
protected function load_classifier($outputdir) {
$modelfilepath = $this->get_model_filepath($outputdir);
if (!file_exists($modelfilepath)) {
throw new \moodle_exception('errorcantloadmodel', 'mlbackend_php', '', $modelfilepath);
}
$modelmanager = new ModelManager();
return $modelmanager->restoreFromFile($modelfilepath);
}
|
php
|
protected function load_classifier($outputdir) {
$modelfilepath = $this->get_model_filepath($outputdir);
if (!file_exists($modelfilepath)) {
throw new \moodle_exception('errorcantloadmodel', 'mlbackend_php', '', $modelfilepath);
}
$modelmanager = new ModelManager();
return $modelmanager->restoreFromFile($modelfilepath);
}
|
[
"protected",
"function",
"load_classifier",
"(",
"$",
"outputdir",
")",
"{",
"$",
"modelfilepath",
"=",
"$",
"this",
"->",
"get_model_filepath",
"(",
"$",
"outputdir",
")",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"modelfilepath",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'errorcantloadmodel'",
",",
"'mlbackend_php'",
",",
"''",
",",
"$",
"modelfilepath",
")",
";",
"}",
"$",
"modelmanager",
"=",
"new",
"ModelManager",
"(",
")",
";",
"return",
"$",
"modelmanager",
"->",
"restoreFromFile",
"(",
"$",
"modelfilepath",
")",
";",
"}"
] |
Loads the pre-trained classifier.
@throws \moodle_exception
@param string $outputdir
@return \Phpml\Classification\Linear\LogisticRegression
|
[
"Loads",
"the",
"pre",
"-",
"trained",
"classifier",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mlbackend/php/classes/processor.php#L400-L409
|
218,341
|
moodle/moodle
|
lib/mlbackend/php/classes/processor.php
|
processor.get_phi
|
protected function get_phi($testlabels, $predictedlabels) {
// Binary here only as well.
$matrix = \Phpml\Metric\ConfusionMatrix::compute($testlabels, $predictedlabels, array(0, 1));
$tptn = $matrix[0][0] * $matrix[1][1];
$fpfn = $matrix[1][0] * $matrix[0][1];
$tpfp = $matrix[0][0] + $matrix[1][0];
$tpfn = $matrix[0][0] + $matrix[0][1];
$tnfp = $matrix[1][1] + $matrix[1][0];
$tnfn = $matrix[1][1] + $matrix[0][1];
if ($tpfp === 0 || $tpfn === 0 || $tnfp === 0 || $tnfn === 0) {
$phi = 0;
} else {
$phi = ( $tptn - $fpfn ) / sqrt( $tpfp * $tpfn * $tnfp * $tnfn);
}
return $phi;
}
|
php
|
protected function get_phi($testlabels, $predictedlabels) {
// Binary here only as well.
$matrix = \Phpml\Metric\ConfusionMatrix::compute($testlabels, $predictedlabels, array(0, 1));
$tptn = $matrix[0][0] * $matrix[1][1];
$fpfn = $matrix[1][0] * $matrix[0][1];
$tpfp = $matrix[0][0] + $matrix[1][0];
$tpfn = $matrix[0][0] + $matrix[0][1];
$tnfp = $matrix[1][1] + $matrix[1][0];
$tnfn = $matrix[1][1] + $matrix[0][1];
if ($tpfp === 0 || $tpfn === 0 || $tnfp === 0 || $tnfn === 0) {
$phi = 0;
} else {
$phi = ( $tptn - $fpfn ) / sqrt( $tpfp * $tpfn * $tnfp * $tnfn);
}
return $phi;
}
|
[
"protected",
"function",
"get_phi",
"(",
"$",
"testlabels",
",",
"$",
"predictedlabels",
")",
"{",
"// Binary here only as well.",
"$",
"matrix",
"=",
"\\",
"Phpml",
"\\",
"Metric",
"\\",
"ConfusionMatrix",
"::",
"compute",
"(",
"$",
"testlabels",
",",
"$",
"predictedlabels",
",",
"array",
"(",
"0",
",",
"1",
")",
")",
";",
"$",
"tptn",
"=",
"$",
"matrix",
"[",
"0",
"]",
"[",
"0",
"]",
"*",
"$",
"matrix",
"[",
"1",
"]",
"[",
"1",
"]",
";",
"$",
"fpfn",
"=",
"$",
"matrix",
"[",
"1",
"]",
"[",
"0",
"]",
"*",
"$",
"matrix",
"[",
"0",
"]",
"[",
"1",
"]",
";",
"$",
"tpfp",
"=",
"$",
"matrix",
"[",
"0",
"]",
"[",
"0",
"]",
"+",
"$",
"matrix",
"[",
"1",
"]",
"[",
"0",
"]",
";",
"$",
"tpfn",
"=",
"$",
"matrix",
"[",
"0",
"]",
"[",
"0",
"]",
"+",
"$",
"matrix",
"[",
"0",
"]",
"[",
"1",
"]",
";",
"$",
"tnfp",
"=",
"$",
"matrix",
"[",
"1",
"]",
"[",
"1",
"]",
"+",
"$",
"matrix",
"[",
"1",
"]",
"[",
"0",
"]",
";",
"$",
"tnfn",
"=",
"$",
"matrix",
"[",
"1",
"]",
"[",
"1",
"]",
"+",
"$",
"matrix",
"[",
"0",
"]",
"[",
"1",
"]",
";",
"if",
"(",
"$",
"tpfp",
"===",
"0",
"||",
"$",
"tpfn",
"===",
"0",
"||",
"$",
"tnfp",
"===",
"0",
"||",
"$",
"tnfn",
"===",
"0",
")",
"{",
"$",
"phi",
"=",
"0",
";",
"}",
"else",
"{",
"$",
"phi",
"=",
"(",
"$",
"tptn",
"-",
"$",
"fpfn",
")",
"/",
"sqrt",
"(",
"$",
"tpfp",
"*",
"$",
"tpfn",
"*",
"$",
"tnfp",
"*",
"$",
"tnfn",
")",
";",
"}",
"return",
"$",
"phi",
";",
"}"
] |
Returns the Phi correlation coefficient.
@param array $testlabels
@param array $predictedlabels
@return float
|
[
"Returns",
"the",
"Phi",
"correlation",
"coefficient",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mlbackend/php/classes/processor.php#L532-L550
|
218,342
|
moodle/moodle
|
lib/xmldb/xmldb_file.php
|
xmldb_file.loadXMLStructure
|
public function loadXMLStructure() {
if ($this->fileExists()) {
// Let's validate the XML file
if (!$this->validateXMLStructure()) {
return false;
}
$contents = file_get_contents($this->path);
if (strpos($contents, '<STATEMENTS>')) {
//delete the removed STATEMENTS section, it would not validate
$contents = preg_replace('|<STATEMENTS>.*</STATEMENTS>|s', '', $contents);
debugging('STATEMENTS section is not supported any more, please use db/install.php or db/log.php');
}
// File exists, so let's process it
// Load everything to a big array
$xmlarr = xmlize($contents);
// Convert array to xmldb structure
$this->xmldb_structure = $this->arr2xmldb_structure($xmlarr);
// Analyze results
if ($this->xmldb_structure->isLoaded()) {
$this->loaded = true;
return true;
} else {
return false;
}
}
return true;
}
|
php
|
public function loadXMLStructure() {
if ($this->fileExists()) {
// Let's validate the XML file
if (!$this->validateXMLStructure()) {
return false;
}
$contents = file_get_contents($this->path);
if (strpos($contents, '<STATEMENTS>')) {
//delete the removed STATEMENTS section, it would not validate
$contents = preg_replace('|<STATEMENTS>.*</STATEMENTS>|s', '', $contents);
debugging('STATEMENTS section is not supported any more, please use db/install.php or db/log.php');
}
// File exists, so let's process it
// Load everything to a big array
$xmlarr = xmlize($contents);
// Convert array to xmldb structure
$this->xmldb_structure = $this->arr2xmldb_structure($xmlarr);
// Analyze results
if ($this->xmldb_structure->isLoaded()) {
$this->loaded = true;
return true;
} else {
return false;
}
}
return true;
}
|
[
"public",
"function",
"loadXMLStructure",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"fileExists",
"(",
")",
")",
"{",
"// Let's validate the XML file",
"if",
"(",
"!",
"$",
"this",
"->",
"validateXMLStructure",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"contents",
"=",
"file_get_contents",
"(",
"$",
"this",
"->",
"path",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"contents",
",",
"'<STATEMENTS>'",
")",
")",
"{",
"//delete the removed STATEMENTS section, it would not validate",
"$",
"contents",
"=",
"preg_replace",
"(",
"'|<STATEMENTS>.*</STATEMENTS>|s'",
",",
"''",
",",
"$",
"contents",
")",
";",
"debugging",
"(",
"'STATEMENTS section is not supported any more, please use db/install.php or db/log.php'",
")",
";",
"}",
"// File exists, so let's process it",
"// Load everything to a big array",
"$",
"xmlarr",
"=",
"xmlize",
"(",
"$",
"contents",
")",
";",
"// Convert array to xmldb structure",
"$",
"this",
"->",
"xmldb_structure",
"=",
"$",
"this",
"->",
"arr2xmldb_structure",
"(",
"$",
"xmlarr",
")",
";",
"// Analyze results",
"if",
"(",
"$",
"this",
"->",
"xmldb_structure",
"->",
"isLoaded",
"(",
")",
")",
"{",
"$",
"this",
"->",
"loaded",
"=",
"true",
";",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Load and the XMLDB structure from file
@return true
|
[
"Load",
"and",
"the",
"XMLDB",
"structure",
"from",
"file"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/xmldb/xmldb_file.php#L137-L163
|
218,343
|
moodle/moodle
|
lib/xmldb/xmldb_file.php
|
xmldb_file.arr2xmldb_structure
|
public function arr2xmldb_structure ($xmlarr) {
$structure = new xmldb_structure($this->path);
$structure->arr2xmldb_structure($xmlarr);
return $structure;
}
|
php
|
public function arr2xmldb_structure ($xmlarr) {
$structure = new xmldb_structure($this->path);
$structure->arr2xmldb_structure($xmlarr);
return $structure;
}
|
[
"public",
"function",
"arr2xmldb_structure",
"(",
"$",
"xmlarr",
")",
"{",
"$",
"structure",
"=",
"new",
"xmldb_structure",
"(",
"$",
"this",
"->",
"path",
")",
";",
"$",
"structure",
"->",
"arr2xmldb_structure",
"(",
"$",
"xmlarr",
")",
";",
"return",
"$",
"structure",
";",
"}"
] |
This function takes an xmlized array and put it into one xmldb_structure
@param array $xmlarr
@return xmldb_structure
|
[
"This",
"function",
"takes",
"an",
"xmlized",
"array",
"and",
"put",
"it",
"into",
"one",
"xmldb_structure"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/xmldb/xmldb_file.php#L170-L174
|
218,344
|
moodle/moodle
|
lib/xmldb/xmldb_file.php
|
xmldb_file.saveXMLFile
|
public function saveXMLFile() {
$structure = $this->getStructure();
$result = file_put_contents($this->path, $structure->xmlOutput());
return $result;
}
|
php
|
public function saveXMLFile() {
$structure = $this->getStructure();
$result = file_put_contents($this->path, $structure->xmlOutput());
return $result;
}
|
[
"public",
"function",
"saveXMLFile",
"(",
")",
"{",
"$",
"structure",
"=",
"$",
"this",
"->",
"getStructure",
"(",
")",
";",
"$",
"result",
"=",
"file_put_contents",
"(",
"$",
"this",
"->",
"path",
",",
"$",
"structure",
"->",
"xmlOutput",
"(",
")",
")",
";",
"return",
"$",
"result",
";",
"}"
] |
This function saves the whole xmldb_structure to its file
@return int|bool false on failure, number of written bytes on success
|
[
"This",
"function",
"saves",
"the",
"whole",
"xmldb_structure",
"to",
"its",
"file"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/xmldb/xmldb_file.php#L196-L203
|
218,345
|
moodle/moodle
|
lib/editor/tinymce/plugins/managefiles/lib.php
|
tinymce_managefiles.update_init_params
|
protected function update_init_params(array &$params, context $context,
array $options = null) {
global $USER;
if (!isloggedin() or isguestuser()) {
// Must be a real user to manage any files.
return;
}
if (!isset($options['maxfiles']) or $options['maxfiles'] == 0) {
// No files allowed - easy, do not load anything.
return;
}
// Add parameters for filemanager
$params['managefiles'] = array('usercontext' => context_user::instance($USER->id)->id);
foreach (array('itemid', 'context', 'areamaxbytes', 'maxbytes', 'subdirs', 'return_types') as $key) {
if (isset($options[$key])) {
if ($key === 'context' && is_object($options[$key])) {
// Just context id is enough
$params['managefiles'][$key] = $options[$key]->id;
} else {
$params['managefiles'][$key] = $options[$key];
}
}
}
if ($row = $this->find_button($params, 'moodlemedia')) {
// Add button after 'moodlemedia' button.
$this->add_button_after($params, $row, 'managefiles', 'moodlemedia');
} else if ($row = $this->find_button($params, 'image')) {
// If 'moodlemedia' is not found add after 'image'.
$this->add_button_after($params, $row, 'managefiles', 'image');
} else {
// OTherwise add button in the end of the last row.
$this->add_button_after($params, $this->count_button_rows($params), 'managefiles');
}
// Add JS file, which uses default name.
$this->add_js_plugin($params);
}
|
php
|
protected function update_init_params(array &$params, context $context,
array $options = null) {
global $USER;
if (!isloggedin() or isguestuser()) {
// Must be a real user to manage any files.
return;
}
if (!isset($options['maxfiles']) or $options['maxfiles'] == 0) {
// No files allowed - easy, do not load anything.
return;
}
// Add parameters for filemanager
$params['managefiles'] = array('usercontext' => context_user::instance($USER->id)->id);
foreach (array('itemid', 'context', 'areamaxbytes', 'maxbytes', 'subdirs', 'return_types') as $key) {
if (isset($options[$key])) {
if ($key === 'context' && is_object($options[$key])) {
// Just context id is enough
$params['managefiles'][$key] = $options[$key]->id;
} else {
$params['managefiles'][$key] = $options[$key];
}
}
}
if ($row = $this->find_button($params, 'moodlemedia')) {
// Add button after 'moodlemedia' button.
$this->add_button_after($params, $row, 'managefiles', 'moodlemedia');
} else if ($row = $this->find_button($params, 'image')) {
// If 'moodlemedia' is not found add after 'image'.
$this->add_button_after($params, $row, 'managefiles', 'image');
} else {
// OTherwise add button in the end of the last row.
$this->add_button_after($params, $this->count_button_rows($params), 'managefiles');
}
// Add JS file, which uses default name.
$this->add_js_plugin($params);
}
|
[
"protected",
"function",
"update_init_params",
"(",
"array",
"&",
"$",
"params",
",",
"context",
"$",
"context",
",",
"array",
"$",
"options",
"=",
"null",
")",
"{",
"global",
"$",
"USER",
";",
"if",
"(",
"!",
"isloggedin",
"(",
")",
"or",
"isguestuser",
"(",
")",
")",
"{",
"// Must be a real user to manage any files.",
"return",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"options",
"[",
"'maxfiles'",
"]",
")",
"or",
"$",
"options",
"[",
"'maxfiles'",
"]",
"==",
"0",
")",
"{",
"// No files allowed - easy, do not load anything.",
"return",
";",
"}",
"// Add parameters for filemanager",
"$",
"params",
"[",
"'managefiles'",
"]",
"=",
"array",
"(",
"'usercontext'",
"=>",
"context_user",
"::",
"instance",
"(",
"$",
"USER",
"->",
"id",
")",
"->",
"id",
")",
";",
"foreach",
"(",
"array",
"(",
"'itemid'",
",",
"'context'",
",",
"'areamaxbytes'",
",",
"'maxbytes'",
",",
"'subdirs'",
",",
"'return_types'",
")",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"$",
"key",
"]",
")",
")",
"{",
"if",
"(",
"$",
"key",
"===",
"'context'",
"&&",
"is_object",
"(",
"$",
"options",
"[",
"$",
"key",
"]",
")",
")",
"{",
"// Just context id is enough",
"$",
"params",
"[",
"'managefiles'",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"options",
"[",
"$",
"key",
"]",
"->",
"id",
";",
"}",
"else",
"{",
"$",
"params",
"[",
"'managefiles'",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"options",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"row",
"=",
"$",
"this",
"->",
"find_button",
"(",
"$",
"params",
",",
"'moodlemedia'",
")",
")",
"{",
"// Add button after 'moodlemedia' button.",
"$",
"this",
"->",
"add_button_after",
"(",
"$",
"params",
",",
"$",
"row",
",",
"'managefiles'",
",",
"'moodlemedia'",
")",
";",
"}",
"else",
"if",
"(",
"$",
"row",
"=",
"$",
"this",
"->",
"find_button",
"(",
"$",
"params",
",",
"'image'",
")",
")",
"{",
"// If 'moodlemedia' is not found add after 'image'.",
"$",
"this",
"->",
"add_button_after",
"(",
"$",
"params",
",",
"$",
"row",
",",
"'managefiles'",
",",
"'image'",
")",
";",
"}",
"else",
"{",
"// OTherwise add button in the end of the last row.",
"$",
"this",
"->",
"add_button_after",
"(",
"$",
"params",
",",
"$",
"this",
"->",
"count_button_rows",
"(",
"$",
"params",
")",
",",
"'managefiles'",
")",
";",
"}",
"// Add JS file, which uses default name.",
"$",
"this",
"->",
"add_js_plugin",
"(",
"$",
"params",
")",
";",
"}"
] |
Adjusts TinyMCE init parameters for tinymce_managefiles
Adds file area restrictions parameters and actual 'managefiles' button
@param array $params TinyMCE init parameters array
@param context $context Context where editor is being shown
@param array $options Options for this editor
|
[
"Adjusts",
"TinyMCE",
"init",
"parameters",
"for",
"tinymce_managefiles"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/editor/tinymce/plugins/managefiles/lib.php#L39-L78
|
218,346
|
moodle/moodle
|
mod/wiki/parser/utils.php
|
parser_utils.wiki_parser_link_callback
|
public static function wiki_parser_link_callback($link, $options) {
$l = urlencode($link);
if(!empty($options['anchor'])) {
$l .= "#".urlencode($options['anchor']);
}
return array('content' => $link, 'url' => "http://".$l);
}
|
php
|
public static function wiki_parser_link_callback($link, $options) {
$l = urlencode($link);
if(!empty($options['anchor'])) {
$l .= "#".urlencode($options['anchor']);
}
return array('content' => $link, 'url' => "http://".$l);
}
|
[
"public",
"static",
"function",
"wiki_parser_link_callback",
"(",
"$",
"link",
",",
"$",
"options",
")",
"{",
"$",
"l",
"=",
"urlencode",
"(",
"$",
"link",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"options",
"[",
"'anchor'",
"]",
")",
")",
"{",
"$",
"l",
".=",
"\"#\"",
".",
"urlencode",
"(",
"$",
"options",
"[",
"'anchor'",
"]",
")",
";",
"}",
"return",
"array",
"(",
"'content'",
"=>",
"$",
"link",
",",
"'url'",
"=>",
"\"http://\"",
".",
"$",
"l",
")",
";",
"}"
] |
Default link generator
|
[
"Default",
"link",
"generator"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/parser/utils.php#L28-L34
|
218,347
|
moodle/moodle
|
mod/wiki/parser/utils.php
|
parser_utils.wiki_parser_table_callback
|
public static function wiki_parser_table_callback($table) {
$html = "";
$headers = $table[0];
$columncount = count($headers);
$headerhtml = "";
foreach($headers as $h) {
$text = trim($h[1]);
if($h[0] == 'header') {
$headerhtml .= "\n".parser_utils::h('th', $text)."\n";
$hasheaders = true;
}
else if($h[0] == 'normal'){
$headerhtml .= "\n".parser_utils::h("td", $text)."\n";
}
}
$headerhtml = "\n".parser_utils::h('tr', $headerhtml)."\n";
$bodyhtml = "";
if(isset($hasheaders)) {
$html = "\n".parser_utils::h('thead', $headerhtml)."\n";
}
else {
$bodyhtml .= $headerhtml;
}
array_shift($table);
foreach($table as $row) {
$htmlrow = "";
for($i = 0; $i < $columncount; $i++) {
$text = "";
if(!isset($row[$i])) {
$htmlrow .= "\n".parser_utils::h('td', $text)."\n";
}
else {
$text = trim($row[$i][1]);
if($row[$i][0] == 'header') {
$htmlrow .= "\n".parser_utils::h('th', $text)."\n";
}
else if($row[$i][0] == 'normal'){
$htmlrow .= "\n".parser_utils::h('td', $text)."\n";
}
}
}
$bodyhtml .= "\n".parser_utils::h('tr', $htmlrow)."\n";
}
$html .= "\n".parser_utils::h('tbody', $bodyhtml)."\n";
return "\n".parser_utils::h('table', $html)."\n";
}
|
php
|
public static function wiki_parser_table_callback($table) {
$html = "";
$headers = $table[0];
$columncount = count($headers);
$headerhtml = "";
foreach($headers as $h) {
$text = trim($h[1]);
if($h[0] == 'header') {
$headerhtml .= "\n".parser_utils::h('th', $text)."\n";
$hasheaders = true;
}
else if($h[0] == 'normal'){
$headerhtml .= "\n".parser_utils::h("td", $text)."\n";
}
}
$headerhtml = "\n".parser_utils::h('tr', $headerhtml)."\n";
$bodyhtml = "";
if(isset($hasheaders)) {
$html = "\n".parser_utils::h('thead', $headerhtml)."\n";
}
else {
$bodyhtml .= $headerhtml;
}
array_shift($table);
foreach($table as $row) {
$htmlrow = "";
for($i = 0; $i < $columncount; $i++) {
$text = "";
if(!isset($row[$i])) {
$htmlrow .= "\n".parser_utils::h('td', $text)."\n";
}
else {
$text = trim($row[$i][1]);
if($row[$i][0] == 'header') {
$htmlrow .= "\n".parser_utils::h('th', $text)."\n";
}
else if($row[$i][0] == 'normal'){
$htmlrow .= "\n".parser_utils::h('td', $text)."\n";
}
}
}
$bodyhtml .= "\n".parser_utils::h('tr', $htmlrow)."\n";
}
$html .= "\n".parser_utils::h('tbody', $bodyhtml)."\n";
return "\n".parser_utils::h('table', $html)."\n";
}
|
[
"public",
"static",
"function",
"wiki_parser_table_callback",
"(",
"$",
"table",
")",
"{",
"$",
"html",
"=",
"\"\"",
";",
"$",
"headers",
"=",
"$",
"table",
"[",
"0",
"]",
";",
"$",
"columncount",
"=",
"count",
"(",
"$",
"headers",
")",
";",
"$",
"headerhtml",
"=",
"\"\"",
";",
"foreach",
"(",
"$",
"headers",
"as",
"$",
"h",
")",
"{",
"$",
"text",
"=",
"trim",
"(",
"$",
"h",
"[",
"1",
"]",
")",
";",
"if",
"(",
"$",
"h",
"[",
"0",
"]",
"==",
"'header'",
")",
"{",
"$",
"headerhtml",
".=",
"\"\\n\"",
".",
"parser_utils",
"::",
"h",
"(",
"'th'",
",",
"$",
"text",
")",
".",
"\"\\n\"",
";",
"$",
"hasheaders",
"=",
"true",
";",
"}",
"else",
"if",
"(",
"$",
"h",
"[",
"0",
"]",
"==",
"'normal'",
")",
"{",
"$",
"headerhtml",
".=",
"\"\\n\"",
".",
"parser_utils",
"::",
"h",
"(",
"\"td\"",
",",
"$",
"text",
")",
".",
"\"\\n\"",
";",
"}",
"}",
"$",
"headerhtml",
"=",
"\"\\n\"",
".",
"parser_utils",
"::",
"h",
"(",
"'tr'",
",",
"$",
"headerhtml",
")",
".",
"\"\\n\"",
";",
"$",
"bodyhtml",
"=",
"\"\"",
";",
"if",
"(",
"isset",
"(",
"$",
"hasheaders",
")",
")",
"{",
"$",
"html",
"=",
"\"\\n\"",
".",
"parser_utils",
"::",
"h",
"(",
"'thead'",
",",
"$",
"headerhtml",
")",
".",
"\"\\n\"",
";",
"}",
"else",
"{",
"$",
"bodyhtml",
".=",
"$",
"headerhtml",
";",
"}",
"array_shift",
"(",
"$",
"table",
")",
";",
"foreach",
"(",
"$",
"table",
"as",
"$",
"row",
")",
"{",
"$",
"htmlrow",
"=",
"\"\"",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"columncount",
";",
"$",
"i",
"++",
")",
"{",
"$",
"text",
"=",
"\"\"",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"row",
"[",
"$",
"i",
"]",
")",
")",
"{",
"$",
"htmlrow",
".=",
"\"\\n\"",
".",
"parser_utils",
"::",
"h",
"(",
"'td'",
",",
"$",
"text",
")",
".",
"\"\\n\"",
";",
"}",
"else",
"{",
"$",
"text",
"=",
"trim",
"(",
"$",
"row",
"[",
"$",
"i",
"]",
"[",
"1",
"]",
")",
";",
"if",
"(",
"$",
"row",
"[",
"$",
"i",
"]",
"[",
"0",
"]",
"==",
"'header'",
")",
"{",
"$",
"htmlrow",
".=",
"\"\\n\"",
".",
"parser_utils",
"::",
"h",
"(",
"'th'",
",",
"$",
"text",
")",
".",
"\"\\n\"",
";",
"}",
"else",
"if",
"(",
"$",
"row",
"[",
"$",
"i",
"]",
"[",
"0",
"]",
"==",
"'normal'",
")",
"{",
"$",
"htmlrow",
".=",
"\"\\n\"",
".",
"parser_utils",
"::",
"h",
"(",
"'td'",
",",
"$",
"text",
")",
".",
"\"\\n\"",
";",
"}",
"}",
"}",
"$",
"bodyhtml",
".=",
"\"\\n\"",
".",
"parser_utils",
"::",
"h",
"(",
"'tr'",
",",
"$",
"htmlrow",
")",
".",
"\"\\n\"",
";",
"}",
"$",
"html",
".=",
"\"\\n\"",
".",
"parser_utils",
"::",
"h",
"(",
"'tbody'",
",",
"$",
"bodyhtml",
")",
".",
"\"\\n\"",
";",
"return",
"\"\\n\"",
".",
"parser_utils",
"::",
"h",
"(",
"'table'",
",",
"$",
"html",
")",
".",
"\"\\n\"",
";",
"}"
] |
Default table generator
|
[
"Default",
"table",
"generator"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/parser/utils.php#L41-L88
|
218,348
|
moodle/moodle
|
mod/forum/classes/task/send_user_notifications.php
|
send_user_notifications.get_post_author
|
protected function get_post_author($userid, $course, $forum, $cm, $context) {
if (!isset($this->users[$userid])) {
// This user no longer exists.
return false;
}
$user = $this->users[$userid];
if (!isset($user->groups)) {
// Initialise the groups list.
$user->groups = [];
}
if (!isset($user->groups[$forum->id])) {
$user->groups[$forum->id] = groups_get_all_groups($course->id, $user->id, $cm->groupingid);
}
// Clone the user object to prevent leaks between messages.
return (object) (array) $user;
}
|
php
|
protected function get_post_author($userid, $course, $forum, $cm, $context) {
if (!isset($this->users[$userid])) {
// This user no longer exists.
return false;
}
$user = $this->users[$userid];
if (!isset($user->groups)) {
// Initialise the groups list.
$user->groups = [];
}
if (!isset($user->groups[$forum->id])) {
$user->groups[$forum->id] = groups_get_all_groups($course->id, $user->id, $cm->groupingid);
}
// Clone the user object to prevent leaks between messages.
return (object) (array) $user;
}
|
[
"protected",
"function",
"get_post_author",
"(",
"$",
"userid",
",",
"$",
"course",
",",
"$",
"forum",
",",
"$",
"cm",
",",
"$",
"context",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"users",
"[",
"$",
"userid",
"]",
")",
")",
"{",
"// This user no longer exists.",
"return",
"false",
";",
"}",
"$",
"user",
"=",
"$",
"this",
"->",
"users",
"[",
"$",
"userid",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"user",
"->",
"groups",
")",
")",
"{",
"// Initialise the groups list.",
"$",
"user",
"->",
"groups",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"user",
"->",
"groups",
"[",
"$",
"forum",
"->",
"id",
"]",
")",
")",
"{",
"$",
"user",
"->",
"groups",
"[",
"$",
"forum",
"->",
"id",
"]",
"=",
"groups_get_all_groups",
"(",
"$",
"course",
"->",
"id",
",",
"$",
"user",
"->",
"id",
",",
"$",
"cm",
"->",
"groupingid",
")",
";",
"}",
"// Clone the user object to prevent leaks between messages.",
"return",
"(",
"object",
")",
"(",
"array",
")",
"$",
"user",
";",
"}"
] |
Fetch and initialise the post author.
@param int $userid The id of the user to fetch
@param \stdClass $course
@param \stdClass $forum
@param \stdClass $cm
@param \context $context
@return \stdClass
|
[
"Fetch",
"and",
"initialise",
"the",
"post",
"author",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/task/send_user_notifications.php#L381-L400
|
218,349
|
moodle/moodle
|
mod/forum/classes/task/send_user_notifications.php
|
send_user_notifications.get_message_headers
|
protected function get_message_headers($course, $forum, $discussion, $post, $a, $message) {
$cleanforumname = str_replace('"', "'", strip_tags(format_string($forum->name)));
$viewurl = new \moodle_url('/mod/forum/view.php', ['f' => $forum->id]);
$headers = [
// Headers to make emails easier to track.
'List-Id: "' . $cleanforumname . '" ' . generate_email_messageid('moodleforum' . $forum->id),
'List-Help: ' . $viewurl->out(),
'Message-ID: ' . forum_get_email_message_id($post->id, $this->recipient->id),
'X-Course-Id: ' . $course->id,
'X-Course-Name: '. format_string($course->fullname, true),
// Headers to help prevent auto-responders.
'Precedence: Bulk',
'X-Auto-Response-Suppress: All',
'Auto-Submitted: auto-generated',
'List-Unsubscribe: <' . $message->get_unsubscribediscussionlink() . '>',
];
$rootid = forum_get_email_message_id($discussion->firstpost, $this->recipient->id);
if ($post->parent) {
// This post is a reply, so add reply header (RFC 2822).
$parentid = forum_get_email_message_id($post->parent, $this->recipient->id);
$headers[] = "In-Reply-To: $parentid";
// If the post is deeply nested we also reference the parent message id and
// the root message id (if different) to aid threading when parts of the email
// conversation have been deleted (RFC1036).
if ($post->parent != $discussion->firstpost) {
$headers[] = "References: $rootid $parentid";
} else {
$headers[] = "References: $parentid";
}
}
// MS Outlook / Office uses poorly documented and non standard headers, including
// Thread-Topic which overrides the Subject and shouldn't contain Re: or Fwd: etc.
$aclone = (object) (array) $a;
$aclone->subject = $discussion->name;
$threadtopic = html_to_text(get_string('postmailsubject', 'forum', $aclone), 0);
$headers[] = "Thread-Topic: $threadtopic";
$headers[] = "Thread-Index: " . substr($rootid, 1, 28);
return $headers;
}
|
php
|
protected function get_message_headers($course, $forum, $discussion, $post, $a, $message) {
$cleanforumname = str_replace('"', "'", strip_tags(format_string($forum->name)));
$viewurl = new \moodle_url('/mod/forum/view.php', ['f' => $forum->id]);
$headers = [
// Headers to make emails easier to track.
'List-Id: "' . $cleanforumname . '" ' . generate_email_messageid('moodleforum' . $forum->id),
'List-Help: ' . $viewurl->out(),
'Message-ID: ' . forum_get_email_message_id($post->id, $this->recipient->id),
'X-Course-Id: ' . $course->id,
'X-Course-Name: '. format_string($course->fullname, true),
// Headers to help prevent auto-responders.
'Precedence: Bulk',
'X-Auto-Response-Suppress: All',
'Auto-Submitted: auto-generated',
'List-Unsubscribe: <' . $message->get_unsubscribediscussionlink() . '>',
];
$rootid = forum_get_email_message_id($discussion->firstpost, $this->recipient->id);
if ($post->parent) {
// This post is a reply, so add reply header (RFC 2822).
$parentid = forum_get_email_message_id($post->parent, $this->recipient->id);
$headers[] = "In-Reply-To: $parentid";
// If the post is deeply nested we also reference the parent message id and
// the root message id (if different) to aid threading when parts of the email
// conversation have been deleted (RFC1036).
if ($post->parent != $discussion->firstpost) {
$headers[] = "References: $rootid $parentid";
} else {
$headers[] = "References: $parentid";
}
}
// MS Outlook / Office uses poorly documented and non standard headers, including
// Thread-Topic which overrides the Subject and shouldn't contain Re: or Fwd: etc.
$aclone = (object) (array) $a;
$aclone->subject = $discussion->name;
$threadtopic = html_to_text(get_string('postmailsubject', 'forum', $aclone), 0);
$headers[] = "Thread-Topic: $threadtopic";
$headers[] = "Thread-Index: " . substr($rootid, 1, 28);
return $headers;
}
|
[
"protected",
"function",
"get_message_headers",
"(",
"$",
"course",
",",
"$",
"forum",
",",
"$",
"discussion",
",",
"$",
"post",
",",
"$",
"a",
",",
"$",
"message",
")",
"{",
"$",
"cleanforumname",
"=",
"str_replace",
"(",
"'\"'",
",",
"\"'\"",
",",
"strip_tags",
"(",
"format_string",
"(",
"$",
"forum",
"->",
"name",
")",
")",
")",
";",
"$",
"viewurl",
"=",
"new",
"\\",
"moodle_url",
"(",
"'/mod/forum/view.php'",
",",
"[",
"'f'",
"=>",
"$",
"forum",
"->",
"id",
"]",
")",
";",
"$",
"headers",
"=",
"[",
"// Headers to make emails easier to track.",
"'List-Id: \"'",
".",
"$",
"cleanforumname",
".",
"'\" '",
".",
"generate_email_messageid",
"(",
"'moodleforum'",
".",
"$",
"forum",
"->",
"id",
")",
",",
"'List-Help: '",
".",
"$",
"viewurl",
"->",
"out",
"(",
")",
",",
"'Message-ID: '",
".",
"forum_get_email_message_id",
"(",
"$",
"post",
"->",
"id",
",",
"$",
"this",
"->",
"recipient",
"->",
"id",
")",
",",
"'X-Course-Id: '",
".",
"$",
"course",
"->",
"id",
",",
"'X-Course-Name: '",
".",
"format_string",
"(",
"$",
"course",
"->",
"fullname",
",",
"true",
")",
",",
"// Headers to help prevent auto-responders.",
"'Precedence: Bulk'",
",",
"'X-Auto-Response-Suppress: All'",
",",
"'Auto-Submitted: auto-generated'",
",",
"'List-Unsubscribe: <'",
".",
"$",
"message",
"->",
"get_unsubscribediscussionlink",
"(",
")",
".",
"'>'",
",",
"]",
";",
"$",
"rootid",
"=",
"forum_get_email_message_id",
"(",
"$",
"discussion",
"->",
"firstpost",
",",
"$",
"this",
"->",
"recipient",
"->",
"id",
")",
";",
"if",
"(",
"$",
"post",
"->",
"parent",
")",
"{",
"// This post is a reply, so add reply header (RFC 2822).",
"$",
"parentid",
"=",
"forum_get_email_message_id",
"(",
"$",
"post",
"->",
"parent",
",",
"$",
"this",
"->",
"recipient",
"->",
"id",
")",
";",
"$",
"headers",
"[",
"]",
"=",
"\"In-Reply-To: $parentid\"",
";",
"// If the post is deeply nested we also reference the parent message id and",
"// the root message id (if different) to aid threading when parts of the email",
"// conversation have been deleted (RFC1036).",
"if",
"(",
"$",
"post",
"->",
"parent",
"!=",
"$",
"discussion",
"->",
"firstpost",
")",
"{",
"$",
"headers",
"[",
"]",
"=",
"\"References: $rootid $parentid\"",
";",
"}",
"else",
"{",
"$",
"headers",
"[",
"]",
"=",
"\"References: $parentid\"",
";",
"}",
"}",
"// MS Outlook / Office uses poorly documented and non standard headers, including",
"// Thread-Topic which overrides the Subject and shouldn't contain Re: or Fwd: etc.",
"$",
"aclone",
"=",
"(",
"object",
")",
"(",
"array",
")",
"$",
"a",
";",
"$",
"aclone",
"->",
"subject",
"=",
"$",
"discussion",
"->",
"name",
";",
"$",
"threadtopic",
"=",
"html_to_text",
"(",
"get_string",
"(",
"'postmailsubject'",
",",
"'forum'",
",",
"$",
"aclone",
")",
",",
"0",
")",
";",
"$",
"headers",
"[",
"]",
"=",
"\"Thread-Topic: $threadtopic\"",
";",
"$",
"headers",
"[",
"]",
"=",
"\"Thread-Index: \"",
".",
"substr",
"(",
"$",
"rootid",
",",
"1",
",",
"28",
")",
";",
"return",
"$",
"headers",
";",
"}"
] |
Get the list of message headers.
@param \stdClass $course
@param \stdClass $forum
@param \stdClass $discussion
@param \stdClass $post
@param \stdClass $a The list of strings for this post
@param \core\message\message $message The message to be sent
@return \stdClass
|
[
"Get",
"the",
"list",
"of",
"message",
"headers",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/task/send_user_notifications.php#L431-L476
|
218,350
|
moodle/moodle
|
mod/forum/classes/task/send_user_notifications.php
|
send_user_notifications.get_reply_address
|
protected function get_reply_address($course, $forum, $discussion, $post, $cm, $context) {
if ($this->can_post($course, $forum, $discussion, $post, $cm, $context)) {
// Generate a reply-to address from using the Inbound Message handler.
$this->inboundmanager->set_data($post->id);
return $this->inboundmanager->generate($this->recipient->id);
}
// TODO Check if we can return a string.
// This will be controlled by the event.
return null;
}
|
php
|
protected function get_reply_address($course, $forum, $discussion, $post, $cm, $context) {
if ($this->can_post($course, $forum, $discussion, $post, $cm, $context)) {
// Generate a reply-to address from using the Inbound Message handler.
$this->inboundmanager->set_data($post->id);
return $this->inboundmanager->generate($this->recipient->id);
}
// TODO Check if we can return a string.
// This will be controlled by the event.
return null;
}
|
[
"protected",
"function",
"get_reply_address",
"(",
"$",
"course",
",",
"$",
"forum",
",",
"$",
"discussion",
",",
"$",
"post",
",",
"$",
"cm",
",",
"$",
"context",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"can_post",
"(",
"$",
"course",
",",
"$",
"forum",
",",
"$",
"discussion",
",",
"$",
"post",
",",
"$",
"cm",
",",
"$",
"context",
")",
")",
"{",
"// Generate a reply-to address from using the Inbound Message handler.",
"$",
"this",
"->",
"inboundmanager",
"->",
"set_data",
"(",
"$",
"post",
"->",
"id",
")",
";",
"return",
"$",
"this",
"->",
"inboundmanager",
"->",
"generate",
"(",
"$",
"this",
"->",
"recipient",
"->",
"id",
")",
";",
"}",
"// TODO Check if we can return a string.",
"// This will be controlled by the event.",
"return",
"null",
";",
"}"
] |
Get a no-reply address for this user to reply to the current post.
@param \stdClass $course
@param \stdClass $forum
@param \stdClass $discussion
@param \stdClass $post
@param \stdClass $cm
@param \context $context
@return string
|
[
"Get",
"a",
"no",
"-",
"reply",
"address",
"for",
"this",
"user",
"to",
"reply",
"to",
"the",
"current",
"post",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/task/send_user_notifications.php#L489-L499
|
218,351
|
moodle/moodle
|
mod/forum/classes/task/send_user_notifications.php
|
send_user_notifications.can_post
|
protected function can_post($course, $forum, $discussion, $post, $cm, $context) {
if (!isset($this->canpostto[$discussion->id])) {
$this->canpostto[$discussion->id] = forum_user_can_post($forum, $discussion, $this->recipient, $cm, $course, $context);
}
return $this->canpostto[$discussion->id];
}
|
php
|
protected function can_post($course, $forum, $discussion, $post, $cm, $context) {
if (!isset($this->canpostto[$discussion->id])) {
$this->canpostto[$discussion->id] = forum_user_can_post($forum, $discussion, $this->recipient, $cm, $course, $context);
}
return $this->canpostto[$discussion->id];
}
|
[
"protected",
"function",
"can_post",
"(",
"$",
"course",
",",
"$",
"forum",
",",
"$",
"discussion",
",",
"$",
"post",
",",
"$",
"cm",
",",
"$",
"context",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"canpostto",
"[",
"$",
"discussion",
"->",
"id",
"]",
")",
")",
"{",
"$",
"this",
"->",
"canpostto",
"[",
"$",
"discussion",
"->",
"id",
"]",
"=",
"forum_user_can_post",
"(",
"$",
"forum",
",",
"$",
"discussion",
",",
"$",
"this",
"->",
"recipient",
",",
"$",
"cm",
",",
"$",
"course",
",",
"$",
"context",
")",
";",
"}",
"return",
"$",
"this",
"->",
"canpostto",
"[",
"$",
"discussion",
"->",
"id",
"]",
";",
"}"
] |
Check whether the user can post.
@param \stdClass $course
@param \stdClass $forum
@param \stdClass $discussion
@param \stdClass $post
@param \stdClass $cm
@param \context $context
@return bool
|
[
"Check",
"whether",
"the",
"user",
"can",
"post",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/task/send_user_notifications.php#L512-L517
|
218,352
|
moodle/moodle
|
mod/forum/classes/task/send_user_notifications.php
|
send_user_notifications.can_view_fullnames
|
protected function can_view_fullnames($course, $forum, $discussion, $post, $cm, $context) {
if (!isset($this->viewfullnames[$forum->id])) {
$this->viewfullnames[$forum->id] = has_capability('moodle/site:viewfullnames', $context, $this->recipient->id);
}
return $this->viewfullnames[$forum->id];
}
|
php
|
protected function can_view_fullnames($course, $forum, $discussion, $post, $cm, $context) {
if (!isset($this->viewfullnames[$forum->id])) {
$this->viewfullnames[$forum->id] = has_capability('moodle/site:viewfullnames', $context, $this->recipient->id);
}
return $this->viewfullnames[$forum->id];
}
|
[
"protected",
"function",
"can_view_fullnames",
"(",
"$",
"course",
",",
"$",
"forum",
",",
"$",
"discussion",
",",
"$",
"post",
",",
"$",
"cm",
",",
"$",
"context",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"viewfullnames",
"[",
"$",
"forum",
"->",
"id",
"]",
")",
")",
"{",
"$",
"this",
"->",
"viewfullnames",
"[",
"$",
"forum",
"->",
"id",
"]",
"=",
"has_capability",
"(",
"'moodle/site:viewfullnames'",
",",
"$",
"context",
",",
"$",
"this",
"->",
"recipient",
"->",
"id",
")",
";",
"}",
"return",
"$",
"this",
"->",
"viewfullnames",
"[",
"$",
"forum",
"->",
"id",
"]",
";",
"}"
] |
Check whether the user can view full names of other users.
@param \stdClass $course
@param \stdClass $forum
@param \stdClass $discussion
@param \stdClass $post
@param \stdClass $cm
@param \context $context
@return bool
|
[
"Check",
"whether",
"the",
"user",
"can",
"view",
"full",
"names",
"of",
"other",
"users",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/task/send_user_notifications.php#L530-L536
|
218,353
|
moodle/moodle
|
mod/forum/classes/task/send_user_notifications.php
|
send_user_notifications.minimise_user_record
|
protected function minimise_user_record(\stdClass $user) {
// We store large amount of users in one huge array, make sure we do not store info there we do not actually
// need in mail generation code or messaging.
unset($user->institution);
unset($user->department);
unset($user->address);
unset($user->city);
unset($user->url);
unset($user->currentlogin);
unset($user->description);
unset($user->descriptionformat);
}
|
php
|
protected function minimise_user_record(\stdClass $user) {
// We store large amount of users in one huge array, make sure we do not store info there we do not actually
// need in mail generation code or messaging.
unset($user->institution);
unset($user->department);
unset($user->address);
unset($user->city);
unset($user->url);
unset($user->currentlogin);
unset($user->description);
unset($user->descriptionformat);
}
|
[
"protected",
"function",
"minimise_user_record",
"(",
"\\",
"stdClass",
"$",
"user",
")",
"{",
"// We store large amount of users in one huge array, make sure we do not store info there we do not actually",
"// need in mail generation code or messaging.",
"unset",
"(",
"$",
"user",
"->",
"institution",
")",
";",
"unset",
"(",
"$",
"user",
"->",
"department",
")",
";",
"unset",
"(",
"$",
"user",
"->",
"address",
")",
";",
"unset",
"(",
"$",
"user",
"->",
"city",
")",
";",
"unset",
"(",
"$",
"user",
"->",
"url",
")",
";",
"unset",
"(",
"$",
"user",
"->",
"currentlogin",
")",
";",
"unset",
"(",
"$",
"user",
"->",
"description",
")",
";",
"unset",
"(",
"$",
"user",
"->",
"descriptionformat",
")",
";",
"}"
] |
Removes properties from user record that are not necessary for sending post notifications.
@param \stdClass $user
|
[
"Removes",
"properties",
"from",
"user",
"record",
"that",
"are",
"not",
"necessary",
"for",
"sending",
"post",
"notifications",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/task/send_user_notifications.php#L543-L554
|
218,354
|
moodle/moodle
|
privacy/classes/local/sitepolicy/handler.php
|
handler.signup_form
|
public static function signup_form($mform) {
if ($url = static::get_embed_url()) {
$mform->addElement('header', 'policyagreement', get_string('policyagreement'), '');
$mform->setExpanded('policyagreement');
$mform->addElement('static', 'policylink', '', '<a href="' . $url .
'" onclick="this.target=\'_blank\'">' . get_string('policyagreementclick') . '</a>');
$mform->addElement('checkbox', 'policyagreed', get_string('policyaccept'));
$mform->addRule('policyagreed', get_string('policyagree'), 'required', null, 'client');
}
}
|
php
|
public static function signup_form($mform) {
if ($url = static::get_embed_url()) {
$mform->addElement('header', 'policyagreement', get_string('policyagreement'), '');
$mform->setExpanded('policyagreement');
$mform->addElement('static', 'policylink', '', '<a href="' . $url .
'" onclick="this.target=\'_blank\'">' . get_string('policyagreementclick') . '</a>');
$mform->addElement('checkbox', 'policyagreed', get_string('policyaccept'));
$mform->addRule('policyagreed', get_string('policyagree'), 'required', null, 'client');
}
}
|
[
"public",
"static",
"function",
"signup_form",
"(",
"$",
"mform",
")",
"{",
"if",
"(",
"$",
"url",
"=",
"static",
"::",
"get_embed_url",
"(",
")",
")",
"{",
"$",
"mform",
"->",
"addElement",
"(",
"'header'",
",",
"'policyagreement'",
",",
"get_string",
"(",
"'policyagreement'",
")",
",",
"''",
")",
";",
"$",
"mform",
"->",
"setExpanded",
"(",
"'policyagreement'",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'static'",
",",
"'policylink'",
",",
"''",
",",
"'<a href=\"'",
".",
"$",
"url",
".",
"'\" onclick=\"this.target=\\'_blank\\'\">'",
".",
"get_string",
"(",
"'policyagreementclick'",
")",
".",
"'</a>'",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'checkbox'",
",",
"'policyagreed'",
",",
"get_string",
"(",
"'policyaccept'",
")",
")",
";",
"$",
"mform",
"->",
"addRule",
"(",
"'policyagreed'",
",",
"get_string",
"(",
"'policyagree'",
")",
",",
"'required'",
",",
"null",
",",
"'client'",
")",
";",
"}",
"}"
] |
Adds "Agree to site policy" checkbox to the signup form.
Sitepolicy handlers can override the simple checkbox with their own controls.
@param \MoodleQuickForm $mform
|
[
"Adds",
"Agree",
"to",
"site",
"policy",
"checkbox",
"to",
"the",
"signup",
"form",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/sitepolicy/handler.php#L103-L112
|
218,355
|
moodle/moodle
|
mod/workshop/mod_form.php
|
mod_workshop_mod_form.data_preprocessing
|
public function data_preprocessing(&$data) {
if ($this->current->instance) {
// editing an existing workshop - let us prepare the added editor elements (intro done automatically)
$draftitemid = file_get_submitted_draft_itemid('instructauthors');
$data['instructauthorseditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id,
'mod_workshop', 'instructauthors', 0,
workshop::instruction_editors_options($this->context),
$data['instructauthors']);
$data['instructauthorseditor']['format'] = $data['instructauthorsformat'];
$data['instructauthorseditor']['itemid'] = $draftitemid;
$draftitemid = file_get_submitted_draft_itemid('instructreviewers');
$data['instructreviewerseditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id,
'mod_workshop', 'instructreviewers', 0,
workshop::instruction_editors_options($this->context),
$data['instructreviewers']);
$data['instructreviewerseditor']['format'] = $data['instructreviewersformat'];
$data['instructreviewerseditor']['itemid'] = $draftitemid;
$draftitemid = file_get_submitted_draft_itemid('conclusion');
$data['conclusioneditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id,
'mod_workshop', 'conclusion', 0,
workshop::instruction_editors_options($this->context),
$data['conclusion']);
$data['conclusioneditor']['format'] = $data['conclusionformat'];
$data['conclusioneditor']['itemid'] = $draftitemid;
// Set submission type checkboxes.
foreach (['submissiontypetext', 'submissiontypefile'] as $type) {
$data[$type . 'available'] = 1;
$data[$type . 'required'] = 0;
if ($data[$type] == WORKSHOP_SUBMISSION_TYPE_DISABLED) {
$data[$type . 'available'] = 0;
} else if ($data[$type] == WORKSHOP_SUBMISSION_TYPE_REQUIRED) {
$data[$type . 'required'] = 1;
}
}
} else {
// adding a new workshop instance
$draftitemid = file_get_submitted_draft_itemid('instructauthors');
file_prepare_draft_area($draftitemid, null, 'mod_workshop', 'instructauthors', 0); // no context yet, itemid not used
$data['instructauthorseditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid);
$draftitemid = file_get_submitted_draft_itemid('instructreviewers');
file_prepare_draft_area($draftitemid, null, 'mod_workshop', 'instructreviewers', 0); // no context yet, itemid not used
$data['instructreviewerseditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid);
$draftitemid = file_get_submitted_draft_itemid('conclusion');
file_prepare_draft_area($draftitemid, null, 'mod_workshop', 'conclusion', 0); // no context yet, itemid not used
$data['conclusioneditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid);
}
}
|
php
|
public function data_preprocessing(&$data) {
if ($this->current->instance) {
// editing an existing workshop - let us prepare the added editor elements (intro done automatically)
$draftitemid = file_get_submitted_draft_itemid('instructauthors');
$data['instructauthorseditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id,
'mod_workshop', 'instructauthors', 0,
workshop::instruction_editors_options($this->context),
$data['instructauthors']);
$data['instructauthorseditor']['format'] = $data['instructauthorsformat'];
$data['instructauthorseditor']['itemid'] = $draftitemid;
$draftitemid = file_get_submitted_draft_itemid('instructreviewers');
$data['instructreviewerseditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id,
'mod_workshop', 'instructreviewers', 0,
workshop::instruction_editors_options($this->context),
$data['instructreviewers']);
$data['instructreviewerseditor']['format'] = $data['instructreviewersformat'];
$data['instructreviewerseditor']['itemid'] = $draftitemid;
$draftitemid = file_get_submitted_draft_itemid('conclusion');
$data['conclusioneditor']['text'] = file_prepare_draft_area($draftitemid, $this->context->id,
'mod_workshop', 'conclusion', 0,
workshop::instruction_editors_options($this->context),
$data['conclusion']);
$data['conclusioneditor']['format'] = $data['conclusionformat'];
$data['conclusioneditor']['itemid'] = $draftitemid;
// Set submission type checkboxes.
foreach (['submissiontypetext', 'submissiontypefile'] as $type) {
$data[$type . 'available'] = 1;
$data[$type . 'required'] = 0;
if ($data[$type] == WORKSHOP_SUBMISSION_TYPE_DISABLED) {
$data[$type . 'available'] = 0;
} else if ($data[$type] == WORKSHOP_SUBMISSION_TYPE_REQUIRED) {
$data[$type . 'required'] = 1;
}
}
} else {
// adding a new workshop instance
$draftitemid = file_get_submitted_draft_itemid('instructauthors');
file_prepare_draft_area($draftitemid, null, 'mod_workshop', 'instructauthors', 0); // no context yet, itemid not used
$data['instructauthorseditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid);
$draftitemid = file_get_submitted_draft_itemid('instructreviewers');
file_prepare_draft_area($draftitemid, null, 'mod_workshop', 'instructreviewers', 0); // no context yet, itemid not used
$data['instructreviewerseditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid);
$draftitemid = file_get_submitted_draft_itemid('conclusion');
file_prepare_draft_area($draftitemid, null, 'mod_workshop', 'conclusion', 0); // no context yet, itemid not used
$data['conclusioneditor'] = array('text' => '', 'format' => editors_get_preferred_format(), 'itemid' => $draftitemid);
}
}
|
[
"public",
"function",
"data_preprocessing",
"(",
"&",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"current",
"->",
"instance",
")",
"{",
"// editing an existing workshop - let us prepare the added editor elements (intro done automatically)",
"$",
"draftitemid",
"=",
"file_get_submitted_draft_itemid",
"(",
"'instructauthors'",
")",
";",
"$",
"data",
"[",
"'instructauthorseditor'",
"]",
"[",
"'text'",
"]",
"=",
"file_prepare_draft_area",
"(",
"$",
"draftitemid",
",",
"$",
"this",
"->",
"context",
"->",
"id",
",",
"'mod_workshop'",
",",
"'instructauthors'",
",",
"0",
",",
"workshop",
"::",
"instruction_editors_options",
"(",
"$",
"this",
"->",
"context",
")",
",",
"$",
"data",
"[",
"'instructauthors'",
"]",
")",
";",
"$",
"data",
"[",
"'instructauthorseditor'",
"]",
"[",
"'format'",
"]",
"=",
"$",
"data",
"[",
"'instructauthorsformat'",
"]",
";",
"$",
"data",
"[",
"'instructauthorseditor'",
"]",
"[",
"'itemid'",
"]",
"=",
"$",
"draftitemid",
";",
"$",
"draftitemid",
"=",
"file_get_submitted_draft_itemid",
"(",
"'instructreviewers'",
")",
";",
"$",
"data",
"[",
"'instructreviewerseditor'",
"]",
"[",
"'text'",
"]",
"=",
"file_prepare_draft_area",
"(",
"$",
"draftitemid",
",",
"$",
"this",
"->",
"context",
"->",
"id",
",",
"'mod_workshop'",
",",
"'instructreviewers'",
",",
"0",
",",
"workshop",
"::",
"instruction_editors_options",
"(",
"$",
"this",
"->",
"context",
")",
",",
"$",
"data",
"[",
"'instructreviewers'",
"]",
")",
";",
"$",
"data",
"[",
"'instructreviewerseditor'",
"]",
"[",
"'format'",
"]",
"=",
"$",
"data",
"[",
"'instructreviewersformat'",
"]",
";",
"$",
"data",
"[",
"'instructreviewerseditor'",
"]",
"[",
"'itemid'",
"]",
"=",
"$",
"draftitemid",
";",
"$",
"draftitemid",
"=",
"file_get_submitted_draft_itemid",
"(",
"'conclusion'",
")",
";",
"$",
"data",
"[",
"'conclusioneditor'",
"]",
"[",
"'text'",
"]",
"=",
"file_prepare_draft_area",
"(",
"$",
"draftitemid",
",",
"$",
"this",
"->",
"context",
"->",
"id",
",",
"'mod_workshop'",
",",
"'conclusion'",
",",
"0",
",",
"workshop",
"::",
"instruction_editors_options",
"(",
"$",
"this",
"->",
"context",
")",
",",
"$",
"data",
"[",
"'conclusion'",
"]",
")",
";",
"$",
"data",
"[",
"'conclusioneditor'",
"]",
"[",
"'format'",
"]",
"=",
"$",
"data",
"[",
"'conclusionformat'",
"]",
";",
"$",
"data",
"[",
"'conclusioneditor'",
"]",
"[",
"'itemid'",
"]",
"=",
"$",
"draftitemid",
";",
"// Set submission type checkboxes.",
"foreach",
"(",
"[",
"'submissiontypetext'",
",",
"'submissiontypefile'",
"]",
"as",
"$",
"type",
")",
"{",
"$",
"data",
"[",
"$",
"type",
".",
"'available'",
"]",
"=",
"1",
";",
"$",
"data",
"[",
"$",
"type",
".",
"'required'",
"]",
"=",
"0",
";",
"if",
"(",
"$",
"data",
"[",
"$",
"type",
"]",
"==",
"WORKSHOP_SUBMISSION_TYPE_DISABLED",
")",
"{",
"$",
"data",
"[",
"$",
"type",
".",
"'available'",
"]",
"=",
"0",
";",
"}",
"else",
"if",
"(",
"$",
"data",
"[",
"$",
"type",
"]",
"==",
"WORKSHOP_SUBMISSION_TYPE_REQUIRED",
")",
"{",
"$",
"data",
"[",
"$",
"type",
".",
"'required'",
"]",
"=",
"1",
";",
"}",
"}",
"}",
"else",
"{",
"// adding a new workshop instance",
"$",
"draftitemid",
"=",
"file_get_submitted_draft_itemid",
"(",
"'instructauthors'",
")",
";",
"file_prepare_draft_area",
"(",
"$",
"draftitemid",
",",
"null",
",",
"'mod_workshop'",
",",
"'instructauthors'",
",",
"0",
")",
";",
"// no context yet, itemid not used",
"$",
"data",
"[",
"'instructauthorseditor'",
"]",
"=",
"array",
"(",
"'text'",
"=>",
"''",
",",
"'format'",
"=>",
"editors_get_preferred_format",
"(",
")",
",",
"'itemid'",
"=>",
"$",
"draftitemid",
")",
";",
"$",
"draftitemid",
"=",
"file_get_submitted_draft_itemid",
"(",
"'instructreviewers'",
")",
";",
"file_prepare_draft_area",
"(",
"$",
"draftitemid",
",",
"null",
",",
"'mod_workshop'",
",",
"'instructreviewers'",
",",
"0",
")",
";",
"// no context yet, itemid not used",
"$",
"data",
"[",
"'instructreviewerseditor'",
"]",
"=",
"array",
"(",
"'text'",
"=>",
"''",
",",
"'format'",
"=>",
"editors_get_preferred_format",
"(",
")",
",",
"'itemid'",
"=>",
"$",
"draftitemid",
")",
";",
"$",
"draftitemid",
"=",
"file_get_submitted_draft_itemid",
"(",
"'conclusion'",
")",
";",
"file_prepare_draft_area",
"(",
"$",
"draftitemid",
",",
"null",
",",
"'mod_workshop'",
",",
"'conclusion'",
",",
"0",
")",
";",
"// no context yet, itemid not used",
"$",
"data",
"[",
"'conclusioneditor'",
"]",
"=",
"array",
"(",
"'text'",
"=>",
"''",
",",
"'format'",
"=>",
"editors_get_preferred_format",
"(",
")",
",",
"'itemid'",
"=>",
"$",
"draftitemid",
")",
";",
"}",
"}"
] |
Prepares the form before data are set
Additional wysiwyg editor are prepared here, the introeditor is prepared automatically by core.
Grade items are set here because the core modedit supports single grade item only.
@param array $data to be set
@return void
|
[
"Prepares",
"the",
"form",
"before",
"data",
"are",
"set"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/mod_form.php#L275-L325
|
218,356
|
moodle/moodle
|
mod/workshop/mod_form.php
|
mod_workshop_mod_form.data_postprocessing
|
public function data_postprocessing($data) {
parent::data_postprocessing($data);
foreach (['text', 'file'] as $type) {
$field = 'submissiontype' . $type;
$available = $field . 'available';
$required = $field . 'required';
if ($data->$required) {
$data->$field = WORKSHOP_SUBMISSION_TYPE_REQUIRED;
} else if ($data->$available) {
$data->$field = WORKSHOP_SUBMISSION_TYPE_AVAILABLE;
} else {
$data->$field = WORKSHOP_SUBMISSION_TYPE_DISABLED;
}
unset($data->$available);
unset($data->$required);
}
}
|
php
|
public function data_postprocessing($data) {
parent::data_postprocessing($data);
foreach (['text', 'file'] as $type) {
$field = 'submissiontype' . $type;
$available = $field . 'available';
$required = $field . 'required';
if ($data->$required) {
$data->$field = WORKSHOP_SUBMISSION_TYPE_REQUIRED;
} else if ($data->$available) {
$data->$field = WORKSHOP_SUBMISSION_TYPE_AVAILABLE;
} else {
$data->$field = WORKSHOP_SUBMISSION_TYPE_DISABLED;
}
unset($data->$available);
unset($data->$required);
}
}
|
[
"public",
"function",
"data_postprocessing",
"(",
"$",
"data",
")",
"{",
"parent",
"::",
"data_postprocessing",
"(",
"$",
"data",
")",
";",
"foreach",
"(",
"[",
"'text'",
",",
"'file'",
"]",
"as",
"$",
"type",
")",
"{",
"$",
"field",
"=",
"'submissiontype'",
".",
"$",
"type",
";",
"$",
"available",
"=",
"$",
"field",
".",
"'available'",
";",
"$",
"required",
"=",
"$",
"field",
".",
"'required'",
";",
"if",
"(",
"$",
"data",
"->",
"$",
"required",
")",
"{",
"$",
"data",
"->",
"$",
"field",
"=",
"WORKSHOP_SUBMISSION_TYPE_REQUIRED",
";",
"}",
"else",
"if",
"(",
"$",
"data",
"->",
"$",
"available",
")",
"{",
"$",
"data",
"->",
"$",
"field",
"=",
"WORKSHOP_SUBMISSION_TYPE_AVAILABLE",
";",
"}",
"else",
"{",
"$",
"data",
"->",
"$",
"field",
"=",
"WORKSHOP_SUBMISSION_TYPE_DISABLED",
";",
"}",
"unset",
"(",
"$",
"data",
"->",
"$",
"available",
")",
";",
"unset",
"(",
"$",
"data",
"->",
"$",
"required",
")",
";",
"}",
"}"
] |
Combine submission type checkboxes into integer values for the database.
@param stdClass $data The submitted form data.
|
[
"Combine",
"submission",
"type",
"checkboxes",
"into",
"integer",
"values",
"for",
"the",
"database",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/mod_form.php#L332-L349
|
218,357
|
moodle/moodle
|
mod/workshop/mod_form.php
|
mod_workshop_mod_form.definition_after_data
|
public function definition_after_data() {
$mform =& $this->_form;
if ($id = $mform->getElementValue('update')) {
$instance = $mform->getElementValue('instance');
$gradeitems = grade_item::fetch_all(array(
'itemtype' => 'mod',
'itemmodule' => 'workshop',
'iteminstance' => $instance,
'courseid' => $this->course->id));
if (!empty($gradeitems)) {
foreach ($gradeitems as $gradeitem) {
// here comes really crappy way how to set the value of the fields
// gradecategory and gradinggradecategory - grrr QuickForms
$decimalpoints = $gradeitem->get_decimals();
if ($gradeitem->itemnumber == 0) {
$mform->setDefault('submissiongradepass', format_float($gradeitem->gradepass, $decimalpoints));
$group = $mform->getElement('submissiongradegroup');
$elements = $group->getElements();
foreach ($elements as $element) {
if ($element->getName() == 'gradecategory') {
$element->setValue($gradeitem->categoryid);
}
}
} else if ($gradeitem->itemnumber == 1) {
$mform->setDefault('gradinggradepass', format_float($gradeitem->gradepass, $decimalpoints));
$group = $mform->getElement('gradinggradegroup');
$elements = $group->getElements();
foreach ($elements as $element) {
if ($element->getName() == 'gradinggradecategory') {
$element->setValue($gradeitem->categoryid);
}
}
}
}
}
}
$typevalues = $mform->getElementValue('submissiontypes');
foreach (['submissiontypetext', 'submissiontypefile'] as $type) {
// Don't leave a disabled "required" checkbox checked.
if (!$typevalues[$type . 'available']) {
$mform->setDefault($type . 'required', 0);
}
}
parent::definition_after_data();
}
|
php
|
public function definition_after_data() {
$mform =& $this->_form;
if ($id = $mform->getElementValue('update')) {
$instance = $mform->getElementValue('instance');
$gradeitems = grade_item::fetch_all(array(
'itemtype' => 'mod',
'itemmodule' => 'workshop',
'iteminstance' => $instance,
'courseid' => $this->course->id));
if (!empty($gradeitems)) {
foreach ($gradeitems as $gradeitem) {
// here comes really crappy way how to set the value of the fields
// gradecategory and gradinggradecategory - grrr QuickForms
$decimalpoints = $gradeitem->get_decimals();
if ($gradeitem->itemnumber == 0) {
$mform->setDefault('submissiongradepass', format_float($gradeitem->gradepass, $decimalpoints));
$group = $mform->getElement('submissiongradegroup');
$elements = $group->getElements();
foreach ($elements as $element) {
if ($element->getName() == 'gradecategory') {
$element->setValue($gradeitem->categoryid);
}
}
} else if ($gradeitem->itemnumber == 1) {
$mform->setDefault('gradinggradepass', format_float($gradeitem->gradepass, $decimalpoints));
$group = $mform->getElement('gradinggradegroup');
$elements = $group->getElements();
foreach ($elements as $element) {
if ($element->getName() == 'gradinggradecategory') {
$element->setValue($gradeitem->categoryid);
}
}
}
}
}
}
$typevalues = $mform->getElementValue('submissiontypes');
foreach (['submissiontypetext', 'submissiontypefile'] as $type) {
// Don't leave a disabled "required" checkbox checked.
if (!$typevalues[$type . 'available']) {
$mform->setDefault($type . 'required', 0);
}
}
parent::definition_after_data();
}
|
[
"public",
"function",
"definition_after_data",
"(",
")",
"{",
"$",
"mform",
"=",
"&",
"$",
"this",
"->",
"_form",
";",
"if",
"(",
"$",
"id",
"=",
"$",
"mform",
"->",
"getElementValue",
"(",
"'update'",
")",
")",
"{",
"$",
"instance",
"=",
"$",
"mform",
"->",
"getElementValue",
"(",
"'instance'",
")",
";",
"$",
"gradeitems",
"=",
"grade_item",
"::",
"fetch_all",
"(",
"array",
"(",
"'itemtype'",
"=>",
"'mod'",
",",
"'itemmodule'",
"=>",
"'workshop'",
",",
"'iteminstance'",
"=>",
"$",
"instance",
",",
"'courseid'",
"=>",
"$",
"this",
"->",
"course",
"->",
"id",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"gradeitems",
")",
")",
"{",
"foreach",
"(",
"$",
"gradeitems",
"as",
"$",
"gradeitem",
")",
"{",
"// here comes really crappy way how to set the value of the fields",
"// gradecategory and gradinggradecategory - grrr QuickForms",
"$",
"decimalpoints",
"=",
"$",
"gradeitem",
"->",
"get_decimals",
"(",
")",
";",
"if",
"(",
"$",
"gradeitem",
"->",
"itemnumber",
"==",
"0",
")",
"{",
"$",
"mform",
"->",
"setDefault",
"(",
"'submissiongradepass'",
",",
"format_float",
"(",
"$",
"gradeitem",
"->",
"gradepass",
",",
"$",
"decimalpoints",
")",
")",
";",
"$",
"group",
"=",
"$",
"mform",
"->",
"getElement",
"(",
"'submissiongradegroup'",
")",
";",
"$",
"elements",
"=",
"$",
"group",
"->",
"getElements",
"(",
")",
";",
"foreach",
"(",
"$",
"elements",
"as",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"element",
"->",
"getName",
"(",
")",
"==",
"'gradecategory'",
")",
"{",
"$",
"element",
"->",
"setValue",
"(",
"$",
"gradeitem",
"->",
"categoryid",
")",
";",
"}",
"}",
"}",
"else",
"if",
"(",
"$",
"gradeitem",
"->",
"itemnumber",
"==",
"1",
")",
"{",
"$",
"mform",
"->",
"setDefault",
"(",
"'gradinggradepass'",
",",
"format_float",
"(",
"$",
"gradeitem",
"->",
"gradepass",
",",
"$",
"decimalpoints",
")",
")",
";",
"$",
"group",
"=",
"$",
"mform",
"->",
"getElement",
"(",
"'gradinggradegroup'",
")",
";",
"$",
"elements",
"=",
"$",
"group",
"->",
"getElements",
"(",
")",
";",
"foreach",
"(",
"$",
"elements",
"as",
"$",
"element",
")",
"{",
"if",
"(",
"$",
"element",
"->",
"getName",
"(",
")",
"==",
"'gradinggradecategory'",
")",
"{",
"$",
"element",
"->",
"setValue",
"(",
"$",
"gradeitem",
"->",
"categoryid",
")",
";",
"}",
"}",
"}",
"}",
"}",
"}",
"$",
"typevalues",
"=",
"$",
"mform",
"->",
"getElementValue",
"(",
"'submissiontypes'",
")",
";",
"foreach",
"(",
"[",
"'submissiontypetext'",
",",
"'submissiontypefile'",
"]",
"as",
"$",
"type",
")",
"{",
"// Don't leave a disabled \"required\" checkbox checked.",
"if",
"(",
"!",
"$",
"typevalues",
"[",
"$",
"type",
".",
"'available'",
"]",
")",
"{",
"$",
"mform",
"->",
"setDefault",
"(",
"$",
"type",
".",
"'required'",
",",
"0",
")",
";",
"}",
"}",
"parent",
"::",
"definition_after_data",
"(",
")",
";",
"}"
] |
Set the grade item categories when editing an instance
|
[
"Set",
"the",
"grade",
"item",
"categories",
"when",
"editing",
"an",
"instance"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/mod_form.php#L354-L403
|
218,358
|
moodle/moodle
|
mod/workshop/mod_form.php
|
mod_workshop_mod_form.validation
|
public function validation($data, $files) {
$errors = parent::validation($data, $files);
// check the phases borders are valid
if ($data['submissionstart'] > 0 and $data['submissionend'] > 0 and $data['submissionstart'] >= $data['submissionend']) {
$errors['submissionend'] = get_string('submissionendbeforestart', 'mod_workshop');
}
if ($data['assessmentstart'] > 0 and $data['assessmentend'] > 0 and $data['assessmentstart'] >= $data['assessmentend']) {
$errors['assessmentend'] = get_string('assessmentendbeforestart', 'mod_workshop');
}
// check the phases do not overlap
if (max($data['submissionstart'], $data['submissionend']) > 0 and max($data['assessmentstart'], $data['assessmentend']) > 0) {
$phasesubmissionend = max($data['submissionstart'], $data['submissionend']);
$phaseassessmentstart = min($data['assessmentstart'], $data['assessmentend']);
if ($phaseassessmentstart == 0) {
$phaseassessmentstart = max($data['assessmentstart'], $data['assessmentend']);
}
if ($phasesubmissionend > 0 and $phaseassessmentstart > 0 and $phaseassessmentstart < $phasesubmissionend) {
foreach (array('submissionend', 'submissionstart', 'assessmentstart', 'assessmentend') as $f) {
if ($data[$f] > 0) {
$errors[$f] = get_string('phasesoverlap', 'mod_workshop');
break;
}
}
}
}
// Check that the submission grade pass is a valid number.
if (!empty($data['submissiongradepass'])) {
$submissiongradefloat = unformat_float($data['submissiongradepass'], true);
if ($submissiongradefloat === false) {
$errors['submissiongradepass'] = get_string('err_numeric', 'form');
} else {
if ($submissiongradefloat > $data['grade']) {
$errors['submissiongradepass'] = get_string('gradepassgreaterthangrade', 'grades', $data['grade']);
}
}
}
// Check that the grade pass is a valid number.
if (!empty($data['gradinggradepass'])) {
$gradepassfloat = unformat_float($data['gradinggradepass'], true);
if ($gradepassfloat === false) {
$errors['gradinggradepass'] = get_string('err_numeric', 'form');
} else {
if ($gradepassfloat > $data['gradinggrade']) {
$errors['gradinggradepass'] = get_string('gradepassgreaterthangrade', 'grades', $data['gradinggrade']);
}
}
}
if (!$data['submissiontypetextavailable'] && !$data['submissiontypefileavailable']) {
// One submission type must be available.
$errors['submissiontypes'] = get_string('nosubmissiontype', 'workshop');
}
return $errors;
}
|
php
|
public function validation($data, $files) {
$errors = parent::validation($data, $files);
// check the phases borders are valid
if ($data['submissionstart'] > 0 and $data['submissionend'] > 0 and $data['submissionstart'] >= $data['submissionend']) {
$errors['submissionend'] = get_string('submissionendbeforestart', 'mod_workshop');
}
if ($data['assessmentstart'] > 0 and $data['assessmentend'] > 0 and $data['assessmentstart'] >= $data['assessmentend']) {
$errors['assessmentend'] = get_string('assessmentendbeforestart', 'mod_workshop');
}
// check the phases do not overlap
if (max($data['submissionstart'], $data['submissionend']) > 0 and max($data['assessmentstart'], $data['assessmentend']) > 0) {
$phasesubmissionend = max($data['submissionstart'], $data['submissionend']);
$phaseassessmentstart = min($data['assessmentstart'], $data['assessmentend']);
if ($phaseassessmentstart == 0) {
$phaseassessmentstart = max($data['assessmentstart'], $data['assessmentend']);
}
if ($phasesubmissionend > 0 and $phaseassessmentstart > 0 and $phaseassessmentstart < $phasesubmissionend) {
foreach (array('submissionend', 'submissionstart', 'assessmentstart', 'assessmentend') as $f) {
if ($data[$f] > 0) {
$errors[$f] = get_string('phasesoverlap', 'mod_workshop');
break;
}
}
}
}
// Check that the submission grade pass is a valid number.
if (!empty($data['submissiongradepass'])) {
$submissiongradefloat = unformat_float($data['submissiongradepass'], true);
if ($submissiongradefloat === false) {
$errors['submissiongradepass'] = get_string('err_numeric', 'form');
} else {
if ($submissiongradefloat > $data['grade']) {
$errors['submissiongradepass'] = get_string('gradepassgreaterthangrade', 'grades', $data['grade']);
}
}
}
// Check that the grade pass is a valid number.
if (!empty($data['gradinggradepass'])) {
$gradepassfloat = unformat_float($data['gradinggradepass'], true);
if ($gradepassfloat === false) {
$errors['gradinggradepass'] = get_string('err_numeric', 'form');
} else {
if ($gradepassfloat > $data['gradinggrade']) {
$errors['gradinggradepass'] = get_string('gradepassgreaterthangrade', 'grades', $data['gradinggrade']);
}
}
}
if (!$data['submissiontypetextavailable'] && !$data['submissiontypefileavailable']) {
// One submission type must be available.
$errors['submissiontypes'] = get_string('nosubmissiontype', 'workshop');
}
return $errors;
}
|
[
"public",
"function",
"validation",
"(",
"$",
"data",
",",
"$",
"files",
")",
"{",
"$",
"errors",
"=",
"parent",
"::",
"validation",
"(",
"$",
"data",
",",
"$",
"files",
")",
";",
"// check the phases borders are valid",
"if",
"(",
"$",
"data",
"[",
"'submissionstart'",
"]",
">",
"0",
"and",
"$",
"data",
"[",
"'submissionend'",
"]",
">",
"0",
"and",
"$",
"data",
"[",
"'submissionstart'",
"]",
">=",
"$",
"data",
"[",
"'submissionend'",
"]",
")",
"{",
"$",
"errors",
"[",
"'submissionend'",
"]",
"=",
"get_string",
"(",
"'submissionendbeforestart'",
",",
"'mod_workshop'",
")",
";",
"}",
"if",
"(",
"$",
"data",
"[",
"'assessmentstart'",
"]",
">",
"0",
"and",
"$",
"data",
"[",
"'assessmentend'",
"]",
">",
"0",
"and",
"$",
"data",
"[",
"'assessmentstart'",
"]",
">=",
"$",
"data",
"[",
"'assessmentend'",
"]",
")",
"{",
"$",
"errors",
"[",
"'assessmentend'",
"]",
"=",
"get_string",
"(",
"'assessmentendbeforestart'",
",",
"'mod_workshop'",
")",
";",
"}",
"// check the phases do not overlap",
"if",
"(",
"max",
"(",
"$",
"data",
"[",
"'submissionstart'",
"]",
",",
"$",
"data",
"[",
"'submissionend'",
"]",
")",
">",
"0",
"and",
"max",
"(",
"$",
"data",
"[",
"'assessmentstart'",
"]",
",",
"$",
"data",
"[",
"'assessmentend'",
"]",
")",
">",
"0",
")",
"{",
"$",
"phasesubmissionend",
"=",
"max",
"(",
"$",
"data",
"[",
"'submissionstart'",
"]",
",",
"$",
"data",
"[",
"'submissionend'",
"]",
")",
";",
"$",
"phaseassessmentstart",
"=",
"min",
"(",
"$",
"data",
"[",
"'assessmentstart'",
"]",
",",
"$",
"data",
"[",
"'assessmentend'",
"]",
")",
";",
"if",
"(",
"$",
"phaseassessmentstart",
"==",
"0",
")",
"{",
"$",
"phaseassessmentstart",
"=",
"max",
"(",
"$",
"data",
"[",
"'assessmentstart'",
"]",
",",
"$",
"data",
"[",
"'assessmentend'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"phasesubmissionend",
">",
"0",
"and",
"$",
"phaseassessmentstart",
">",
"0",
"and",
"$",
"phaseassessmentstart",
"<",
"$",
"phasesubmissionend",
")",
"{",
"foreach",
"(",
"array",
"(",
"'submissionend'",
",",
"'submissionstart'",
",",
"'assessmentstart'",
",",
"'assessmentend'",
")",
"as",
"$",
"f",
")",
"{",
"if",
"(",
"$",
"data",
"[",
"$",
"f",
"]",
">",
"0",
")",
"{",
"$",
"errors",
"[",
"$",
"f",
"]",
"=",
"get_string",
"(",
"'phasesoverlap'",
",",
"'mod_workshop'",
")",
";",
"break",
";",
"}",
"}",
"}",
"}",
"// Check that the submission grade pass is a valid number.",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"'submissiongradepass'",
"]",
")",
")",
"{",
"$",
"submissiongradefloat",
"=",
"unformat_float",
"(",
"$",
"data",
"[",
"'submissiongradepass'",
"]",
",",
"true",
")",
";",
"if",
"(",
"$",
"submissiongradefloat",
"===",
"false",
")",
"{",
"$",
"errors",
"[",
"'submissiongradepass'",
"]",
"=",
"get_string",
"(",
"'err_numeric'",
",",
"'form'",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"submissiongradefloat",
">",
"$",
"data",
"[",
"'grade'",
"]",
")",
"{",
"$",
"errors",
"[",
"'submissiongradepass'",
"]",
"=",
"get_string",
"(",
"'gradepassgreaterthangrade'",
",",
"'grades'",
",",
"$",
"data",
"[",
"'grade'",
"]",
")",
";",
"}",
"}",
"}",
"// Check that the grade pass is a valid number.",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"[",
"'gradinggradepass'",
"]",
")",
")",
"{",
"$",
"gradepassfloat",
"=",
"unformat_float",
"(",
"$",
"data",
"[",
"'gradinggradepass'",
"]",
",",
"true",
")",
";",
"if",
"(",
"$",
"gradepassfloat",
"===",
"false",
")",
"{",
"$",
"errors",
"[",
"'gradinggradepass'",
"]",
"=",
"get_string",
"(",
"'err_numeric'",
",",
"'form'",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"gradepassfloat",
">",
"$",
"data",
"[",
"'gradinggrade'",
"]",
")",
"{",
"$",
"errors",
"[",
"'gradinggradepass'",
"]",
"=",
"get_string",
"(",
"'gradepassgreaterthangrade'",
",",
"'grades'",
",",
"$",
"data",
"[",
"'gradinggrade'",
"]",
")",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"$",
"data",
"[",
"'submissiontypetextavailable'",
"]",
"&&",
"!",
"$",
"data",
"[",
"'submissiontypefileavailable'",
"]",
")",
"{",
"// One submission type must be available.",
"$",
"errors",
"[",
"'submissiontypes'",
"]",
"=",
"get_string",
"(",
"'nosubmissiontype'",
",",
"'workshop'",
")",
";",
"}",
"return",
"$",
"errors",
";",
"}"
] |
Validates the form input
@param array $data submitted data
@param array $files submitted files
@return array eventual errors indexed by the field name
|
[
"Validates",
"the",
"form",
"input"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/mod_form.php#L412-L470
|
218,359
|
moodle/moodle
|
mod/forum/classes/local/exporters/forum.php
|
forum.get_forum_record
|
private function get_forum_record() : stdClass {
$forumdbdatamapper = $this->related['legacydatamapperfactory']->get_forum_data_mapper();
return $forumdbdatamapper->to_legacy_object($this->forum);
}
|
php
|
private function get_forum_record() : stdClass {
$forumdbdatamapper = $this->related['legacydatamapperfactory']->get_forum_data_mapper();
return $forumdbdatamapper->to_legacy_object($this->forum);
}
|
[
"private",
"function",
"get_forum_record",
"(",
")",
":",
"stdClass",
"{",
"$",
"forumdbdatamapper",
"=",
"$",
"this",
"->",
"related",
"[",
"'legacydatamapperfactory'",
"]",
"->",
"get_forum_data_mapper",
"(",
")",
";",
"return",
"$",
"forumdbdatamapper",
"->",
"to_legacy_object",
"(",
"$",
"this",
"->",
"forum",
")",
";",
"}"
] |
Get the legacy forum record for this forum.
@return stdClass
|
[
"Get",
"the",
"legacy",
"forum",
"record",
"for",
"this",
"forum",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/exporters/forum.php#L165-L168
|
218,360
|
moodle/moodle
|
admin/tool/policy/classes/privacy/provider.php
|
provider.export_policy_agreements_for_context
|
protected static function export_policy_agreements_for_context(\context_user $context) {
global $DB;
$sysctx = \context_system::instance();
$fs = get_file_storage();
$agreementsql = "
SELECT
a.id AS agreementid, a.userid, a.timemodified, a.note, a.status,
a.policyversionid AS versionid, a.usermodified, a.timecreated,
v.id, v.archived, v.name, v.revision,
v.summary, v.summaryformat,
v.content, v.contentformat,
p.currentversionid
FROM {tool_policy_acceptances} a
JOIN {tool_policy_versions} v ON v.id = a.policyversionid
JOIN {tool_policy} p ON v.policyid = p.id
WHERE a.userid = :userid OR a.usermodified = :usermodified";
// Fetch all agreements related to this user.
$agreements = $DB->get_recordset_sql($agreementsql, [
'userid' => $context->instanceid,
'usermodified' => $context->instanceid,
]);
$basecontext = [
get_string('privacyandpolicies', 'admin'),
get_string('useracceptances', 'tool_policy'),
];
foreach ($agreements as $agreement) {
$subcontext = array_merge($basecontext, [get_string('policynamedversion', 'tool_policy', $agreement)]);
$summary = writer::with_context($context)->rewrite_pluginfile_urls(
$subcontext,
'tool_policy',
'policydocumentsummary',
$agreement->versionid,
$agreement->summary
);
$content = writer::with_context($context)->rewrite_pluginfile_urls(
$subcontext,
'tool_policy',
'policydocumentcontent',
$agreement->versionid,
$agreement->content
);
$agreementcontent = (object) [
'name' => $agreement->name,
'revision' => $agreement->revision,
'isactive' => transform::yesno($agreement->versionid == $agreement->currentversionid),
'isagreed' => transform::yesno($agreement->status),
'agreedby' => transform::user($agreement->usermodified),
'timecreated' => transform::datetime($agreement->timecreated),
'timemodified' => transform::datetime($agreement->timemodified),
'note' => $agreement->note,
'summary' => format_text($summary, $agreement->summaryformat),
'content' => format_text($content, $agreement->contentformat),
];
writer::with_context($context)->export_data($subcontext, $agreementcontent);
// Manually export the files as they reside in the system context so we can't use
// the write's helper methods.
foreach ($fs->get_area_files($sysctx->id, 'tool_policy', 'policydocumentsummary', $agreement->versionid) as $file) {
writer::with_context($context)->export_file($subcontext, $file);
}
foreach ($fs->get_area_files($sysctx->id, 'tool_policy', 'policydocumentcontent', $agreement->versionid) as $file) {
writer::with_context($context)->export_file($subcontext, $file);
}
}
$agreements->close();
}
|
php
|
protected static function export_policy_agreements_for_context(\context_user $context) {
global $DB;
$sysctx = \context_system::instance();
$fs = get_file_storage();
$agreementsql = "
SELECT
a.id AS agreementid, a.userid, a.timemodified, a.note, a.status,
a.policyversionid AS versionid, a.usermodified, a.timecreated,
v.id, v.archived, v.name, v.revision,
v.summary, v.summaryformat,
v.content, v.contentformat,
p.currentversionid
FROM {tool_policy_acceptances} a
JOIN {tool_policy_versions} v ON v.id = a.policyversionid
JOIN {tool_policy} p ON v.policyid = p.id
WHERE a.userid = :userid OR a.usermodified = :usermodified";
// Fetch all agreements related to this user.
$agreements = $DB->get_recordset_sql($agreementsql, [
'userid' => $context->instanceid,
'usermodified' => $context->instanceid,
]);
$basecontext = [
get_string('privacyandpolicies', 'admin'),
get_string('useracceptances', 'tool_policy'),
];
foreach ($agreements as $agreement) {
$subcontext = array_merge($basecontext, [get_string('policynamedversion', 'tool_policy', $agreement)]);
$summary = writer::with_context($context)->rewrite_pluginfile_urls(
$subcontext,
'tool_policy',
'policydocumentsummary',
$agreement->versionid,
$agreement->summary
);
$content = writer::with_context($context)->rewrite_pluginfile_urls(
$subcontext,
'tool_policy',
'policydocumentcontent',
$agreement->versionid,
$agreement->content
);
$agreementcontent = (object) [
'name' => $agreement->name,
'revision' => $agreement->revision,
'isactive' => transform::yesno($agreement->versionid == $agreement->currentversionid),
'isagreed' => transform::yesno($agreement->status),
'agreedby' => transform::user($agreement->usermodified),
'timecreated' => transform::datetime($agreement->timecreated),
'timemodified' => transform::datetime($agreement->timemodified),
'note' => $agreement->note,
'summary' => format_text($summary, $agreement->summaryformat),
'content' => format_text($content, $agreement->contentformat),
];
writer::with_context($context)->export_data($subcontext, $agreementcontent);
// Manually export the files as they reside in the system context so we can't use
// the write's helper methods.
foreach ($fs->get_area_files($sysctx->id, 'tool_policy', 'policydocumentsummary', $agreement->versionid) as $file) {
writer::with_context($context)->export_file($subcontext, $file);
}
foreach ($fs->get_area_files($sysctx->id, 'tool_policy', 'policydocumentcontent', $agreement->versionid) as $file) {
writer::with_context($context)->export_file($subcontext, $file);
}
}
$agreements->close();
}
|
[
"protected",
"static",
"function",
"export_policy_agreements_for_context",
"(",
"\\",
"context_user",
"$",
"context",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"sysctx",
"=",
"\\",
"context_system",
"::",
"instance",
"(",
")",
";",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"$",
"agreementsql",
"=",
"\"\n SELECT\n a.id AS agreementid, a.userid, a.timemodified, a.note, a.status,\n a.policyversionid AS versionid, a.usermodified, a.timecreated,\n v.id, v.archived, v.name, v.revision,\n v.summary, v.summaryformat,\n v.content, v.contentformat,\n p.currentversionid\n FROM {tool_policy_acceptances} a\n JOIN {tool_policy_versions} v ON v.id = a.policyversionid\n JOIN {tool_policy} p ON v.policyid = p.id\n WHERE a.userid = :userid OR a.usermodified = :usermodified\"",
";",
"// Fetch all agreements related to this user.",
"$",
"agreements",
"=",
"$",
"DB",
"->",
"get_recordset_sql",
"(",
"$",
"agreementsql",
",",
"[",
"'userid'",
"=>",
"$",
"context",
"->",
"instanceid",
",",
"'usermodified'",
"=>",
"$",
"context",
"->",
"instanceid",
",",
"]",
")",
";",
"$",
"basecontext",
"=",
"[",
"get_string",
"(",
"'privacyandpolicies'",
",",
"'admin'",
")",
",",
"get_string",
"(",
"'useracceptances'",
",",
"'tool_policy'",
")",
",",
"]",
";",
"foreach",
"(",
"$",
"agreements",
"as",
"$",
"agreement",
")",
"{",
"$",
"subcontext",
"=",
"array_merge",
"(",
"$",
"basecontext",
",",
"[",
"get_string",
"(",
"'policynamedversion'",
",",
"'tool_policy'",
",",
"$",
"agreement",
")",
"]",
")",
";",
"$",
"summary",
"=",
"writer",
"::",
"with_context",
"(",
"$",
"context",
")",
"->",
"rewrite_pluginfile_urls",
"(",
"$",
"subcontext",
",",
"'tool_policy'",
",",
"'policydocumentsummary'",
",",
"$",
"agreement",
"->",
"versionid",
",",
"$",
"agreement",
"->",
"summary",
")",
";",
"$",
"content",
"=",
"writer",
"::",
"with_context",
"(",
"$",
"context",
")",
"->",
"rewrite_pluginfile_urls",
"(",
"$",
"subcontext",
",",
"'tool_policy'",
",",
"'policydocumentcontent'",
",",
"$",
"agreement",
"->",
"versionid",
",",
"$",
"agreement",
"->",
"content",
")",
";",
"$",
"agreementcontent",
"=",
"(",
"object",
")",
"[",
"'name'",
"=>",
"$",
"agreement",
"->",
"name",
",",
"'revision'",
"=>",
"$",
"agreement",
"->",
"revision",
",",
"'isactive'",
"=>",
"transform",
"::",
"yesno",
"(",
"$",
"agreement",
"->",
"versionid",
"==",
"$",
"agreement",
"->",
"currentversionid",
")",
",",
"'isagreed'",
"=>",
"transform",
"::",
"yesno",
"(",
"$",
"agreement",
"->",
"status",
")",
",",
"'agreedby'",
"=>",
"transform",
"::",
"user",
"(",
"$",
"agreement",
"->",
"usermodified",
")",
",",
"'timecreated'",
"=>",
"transform",
"::",
"datetime",
"(",
"$",
"agreement",
"->",
"timecreated",
")",
",",
"'timemodified'",
"=>",
"transform",
"::",
"datetime",
"(",
"$",
"agreement",
"->",
"timemodified",
")",
",",
"'note'",
"=>",
"$",
"agreement",
"->",
"note",
",",
"'summary'",
"=>",
"format_text",
"(",
"$",
"summary",
",",
"$",
"agreement",
"->",
"summaryformat",
")",
",",
"'content'",
"=>",
"format_text",
"(",
"$",
"content",
",",
"$",
"agreement",
"->",
"contentformat",
")",
",",
"]",
";",
"writer",
"::",
"with_context",
"(",
"$",
"context",
")",
"->",
"export_data",
"(",
"$",
"subcontext",
",",
"$",
"agreementcontent",
")",
";",
"// Manually export the files as they reside in the system context so we can't use",
"// the write's helper methods.",
"foreach",
"(",
"$",
"fs",
"->",
"get_area_files",
"(",
"$",
"sysctx",
"->",
"id",
",",
"'tool_policy'",
",",
"'policydocumentsummary'",
",",
"$",
"agreement",
"->",
"versionid",
")",
"as",
"$",
"file",
")",
"{",
"writer",
"::",
"with_context",
"(",
"$",
"context",
")",
"->",
"export_file",
"(",
"$",
"subcontext",
",",
"$",
"file",
")",
";",
"}",
"foreach",
"(",
"$",
"fs",
"->",
"get_area_files",
"(",
"$",
"sysctx",
"->",
"id",
",",
"'tool_policy'",
",",
"'policydocumentcontent'",
",",
"$",
"agreement",
"->",
"versionid",
")",
"as",
"$",
"file",
")",
"{",
"writer",
"::",
"with_context",
"(",
"$",
"context",
")",
"->",
"export_file",
"(",
"$",
"subcontext",
",",
"$",
"file",
")",
";",
"}",
"}",
"$",
"agreements",
"->",
"close",
"(",
")",
";",
"}"
] |
Export all policy agreements relating to the specified user context.
@param \context_user $context The context to export
|
[
"Export",
"all",
"policy",
"agreements",
"relating",
"to",
"the",
"specified",
"user",
"context",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/privacy/provider.php#L223-L293
|
218,361
|
moodle/moodle
|
admin/tool/policy/classes/privacy/provider.php
|
provider.export_authored_policies
|
protected static function export_authored_policies(\stdClass $user) {
global $DB;
// Authored policies are exported against the system.
$context = \context_system::instance();
$basecontext = [
get_string('policydocuments', 'tool_policy'),
];
$sql = "SELECT v.id,
v.name,
v.revision,
v.summary,
v.content,
v.archived,
v.usermodified,
v.timecreated,
v.timemodified,
p.currentversionid
FROM {tool_policy_versions} v
JOIN {tool_policy} p ON p.id = v.policyid
WHERE v.usermodified = :userid";
$versions = $DB->get_recordset_sql($sql, ['userid' => $user->id]);
foreach ($versions as $version) {
$subcontext = array_merge($basecontext, [get_string('policynamedversion', 'tool_policy', $version)]);
$versioncontent = (object) [
'name' => $version->name,
'revision' => $version->revision,
'summary' => writer::with_context($context)->rewrite_pluginfile_urls(
$subcontext,
'tool_policy',
'policydocumentsummary',
$version->id,
$version->summary
),
'content' => writer::with_context($context)->rewrite_pluginfile_urls(
$subcontext,
'tool_policy',
'policydocumentcontent',
$version->id,
$version->content
),
'isactive' => transform::yesno($version->id == $version->currentversionid),
'isarchived' => transform::yesno($version->archived),
'createdbyme' => transform::yesno($version->usermodified == $user->id),
'timecreated' => transform::datetime($version->timecreated),
'timemodified' => transform::datetime($version->timemodified),
];
writer::with_context($context)
->export_data($subcontext, $versioncontent)
->export_area_files($subcontext, 'tool_policy', 'policydocumentsummary', $version->id)
->export_area_files($subcontext, 'tool_policy', 'policydocumentcontent', $version->id);
}
$versions->close();
}
|
php
|
protected static function export_authored_policies(\stdClass $user) {
global $DB;
// Authored policies are exported against the system.
$context = \context_system::instance();
$basecontext = [
get_string('policydocuments', 'tool_policy'),
];
$sql = "SELECT v.id,
v.name,
v.revision,
v.summary,
v.content,
v.archived,
v.usermodified,
v.timecreated,
v.timemodified,
p.currentversionid
FROM {tool_policy_versions} v
JOIN {tool_policy} p ON p.id = v.policyid
WHERE v.usermodified = :userid";
$versions = $DB->get_recordset_sql($sql, ['userid' => $user->id]);
foreach ($versions as $version) {
$subcontext = array_merge($basecontext, [get_string('policynamedversion', 'tool_policy', $version)]);
$versioncontent = (object) [
'name' => $version->name,
'revision' => $version->revision,
'summary' => writer::with_context($context)->rewrite_pluginfile_urls(
$subcontext,
'tool_policy',
'policydocumentsummary',
$version->id,
$version->summary
),
'content' => writer::with_context($context)->rewrite_pluginfile_urls(
$subcontext,
'tool_policy',
'policydocumentcontent',
$version->id,
$version->content
),
'isactive' => transform::yesno($version->id == $version->currentversionid),
'isarchived' => transform::yesno($version->archived),
'createdbyme' => transform::yesno($version->usermodified == $user->id),
'timecreated' => transform::datetime($version->timecreated),
'timemodified' => transform::datetime($version->timemodified),
];
writer::with_context($context)
->export_data($subcontext, $versioncontent)
->export_area_files($subcontext, 'tool_policy', 'policydocumentsummary', $version->id)
->export_area_files($subcontext, 'tool_policy', 'policydocumentcontent', $version->id);
}
$versions->close();
}
|
[
"protected",
"static",
"function",
"export_authored_policies",
"(",
"\\",
"stdClass",
"$",
"user",
")",
"{",
"global",
"$",
"DB",
";",
"// Authored policies are exported against the system.",
"$",
"context",
"=",
"\\",
"context_system",
"::",
"instance",
"(",
")",
";",
"$",
"basecontext",
"=",
"[",
"get_string",
"(",
"'policydocuments'",
",",
"'tool_policy'",
")",
",",
"]",
";",
"$",
"sql",
"=",
"\"SELECT v.id,\n v.name,\n v.revision,\n v.summary,\n v.content,\n v.archived,\n v.usermodified,\n v.timecreated,\n v.timemodified,\n p.currentversionid\n FROM {tool_policy_versions} v\n JOIN {tool_policy} p ON p.id = v.policyid\n WHERE v.usermodified = :userid\"",
";",
"$",
"versions",
"=",
"$",
"DB",
"->",
"get_recordset_sql",
"(",
"$",
"sql",
",",
"[",
"'userid'",
"=>",
"$",
"user",
"->",
"id",
"]",
")",
";",
"foreach",
"(",
"$",
"versions",
"as",
"$",
"version",
")",
"{",
"$",
"subcontext",
"=",
"array_merge",
"(",
"$",
"basecontext",
",",
"[",
"get_string",
"(",
"'policynamedversion'",
",",
"'tool_policy'",
",",
"$",
"version",
")",
"]",
")",
";",
"$",
"versioncontent",
"=",
"(",
"object",
")",
"[",
"'name'",
"=>",
"$",
"version",
"->",
"name",
",",
"'revision'",
"=>",
"$",
"version",
"->",
"revision",
",",
"'summary'",
"=>",
"writer",
"::",
"with_context",
"(",
"$",
"context",
")",
"->",
"rewrite_pluginfile_urls",
"(",
"$",
"subcontext",
",",
"'tool_policy'",
",",
"'policydocumentsummary'",
",",
"$",
"version",
"->",
"id",
",",
"$",
"version",
"->",
"summary",
")",
",",
"'content'",
"=>",
"writer",
"::",
"with_context",
"(",
"$",
"context",
")",
"->",
"rewrite_pluginfile_urls",
"(",
"$",
"subcontext",
",",
"'tool_policy'",
",",
"'policydocumentcontent'",
",",
"$",
"version",
"->",
"id",
",",
"$",
"version",
"->",
"content",
")",
",",
"'isactive'",
"=>",
"transform",
"::",
"yesno",
"(",
"$",
"version",
"->",
"id",
"==",
"$",
"version",
"->",
"currentversionid",
")",
",",
"'isarchived'",
"=>",
"transform",
"::",
"yesno",
"(",
"$",
"version",
"->",
"archived",
")",
",",
"'createdbyme'",
"=>",
"transform",
"::",
"yesno",
"(",
"$",
"version",
"->",
"usermodified",
"==",
"$",
"user",
"->",
"id",
")",
",",
"'timecreated'",
"=>",
"transform",
"::",
"datetime",
"(",
"$",
"version",
"->",
"timecreated",
")",
",",
"'timemodified'",
"=>",
"transform",
"::",
"datetime",
"(",
"$",
"version",
"->",
"timemodified",
")",
",",
"]",
";",
"writer",
"::",
"with_context",
"(",
"$",
"context",
")",
"->",
"export_data",
"(",
"$",
"subcontext",
",",
"$",
"versioncontent",
")",
"->",
"export_area_files",
"(",
"$",
"subcontext",
",",
"'tool_policy'",
",",
"'policydocumentsummary'",
",",
"$",
"version",
"->",
"id",
")",
"->",
"export_area_files",
"(",
"$",
"subcontext",
",",
"'tool_policy'",
",",
"'policydocumentcontent'",
",",
"$",
"version",
"->",
"id",
")",
";",
"}",
"$",
"versions",
"->",
"close",
"(",
")",
";",
"}"
] |
Export all policy agreements that the user authored.
@param stdClass $user The user who has created the policies to export.
|
[
"Export",
"all",
"policy",
"agreements",
"that",
"the",
"user",
"authored",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/privacy/provider.php#L300-L355
|
218,362
|
moodle/moodle
|
admin/tool/dbtransfer/database_transfer_form.php
|
database_transfer_form.definition
|
protected function definition() {
global $CFG;
$mform = $this->_form;
$mform->addElement('header', 'database', get_string('targetdatabase', 'tool_dbtransfer'));
$drivers = tool_dbtransfer_get_drivers();
$drivers = array_reverse($drivers, true);
$drivers[''] = get_string('choosedots');
$drivers = array_reverse($drivers, true);
$mform->addElement('select', 'driver', get_string('dbtype', 'install'), $drivers);
$mform->setType('driver', PARAM_RAW);
$mform->addElement('text', 'dbhost', get_string('databasehost', 'install'));
$mform->setType('dbhost', PARAM_HOST);
$mform->addElement('text', 'dbname', get_string('databasename', 'install'));
$mform->setType('dbname', PARAM_ALPHANUMEXT);
$mform->addElement('text', 'dbuser', get_string('databaseuser', 'install'));
$mform->setType('dbuser', PARAM_ALPHANUMEXT);
$mform->addElement('passwordunmask', 'dbpass', get_string('databasepass', 'install'));
$mform->setType('dbpass', PARAM_RAW);
$mform->addElement('text', 'prefix', get_string('dbprefix', 'install'));
$mform->setType('prefix', PARAM_ALPHANUMEXT);
$mform->addElement('text', 'dbport', get_string('dbport', 'install'));
$mform->setType('dbport', PARAM_INT);
if ($CFG->ostype !== 'WINDOWS') {
$mform->addElement('text', 'dbsocket', get_string('databasesocket', 'install'));
} else {
$mform->addElement('hidden', 'dbsocket');
}
$mform->setType('dbsocket', PARAM_RAW);
$mform->addRule('driver', get_string('required'), 'required', null);
$mform->addRule('dbhost', get_string('required'), 'required', null);
$mform->addRule('dbname', get_string('required'), 'required', null);
$mform->addRule('dbuser', get_string('required'), 'required', null);
$mform->addRule('dbpass', get_string('required'), 'required', null);
if (!isset($drivers['mysqli/native'])) {
$mform->addRule('prefix', get_string('required'), 'required', null);
}
$mform->addElement('header', 'database', get_string('options', 'tool_dbtransfer'));
$mform->addElement('advcheckbox', 'enablemaintenance', get_string('enablemaintenance', 'tool_dbtransfer'));
$mform->setType('enablemaintenance', PARAM_BOOL);
$mform->addHelpButton('enablemaintenance', 'enablemaintenance', 'tool_dbtransfer');
$this->add_action_buttons(false, get_string('transferdata', 'tool_dbtransfer'));
}
|
php
|
protected function definition() {
global $CFG;
$mform = $this->_form;
$mform->addElement('header', 'database', get_string('targetdatabase', 'tool_dbtransfer'));
$drivers = tool_dbtransfer_get_drivers();
$drivers = array_reverse($drivers, true);
$drivers[''] = get_string('choosedots');
$drivers = array_reverse($drivers, true);
$mform->addElement('select', 'driver', get_string('dbtype', 'install'), $drivers);
$mform->setType('driver', PARAM_RAW);
$mform->addElement('text', 'dbhost', get_string('databasehost', 'install'));
$mform->setType('dbhost', PARAM_HOST);
$mform->addElement('text', 'dbname', get_string('databasename', 'install'));
$mform->setType('dbname', PARAM_ALPHANUMEXT);
$mform->addElement('text', 'dbuser', get_string('databaseuser', 'install'));
$mform->setType('dbuser', PARAM_ALPHANUMEXT);
$mform->addElement('passwordunmask', 'dbpass', get_string('databasepass', 'install'));
$mform->setType('dbpass', PARAM_RAW);
$mform->addElement('text', 'prefix', get_string('dbprefix', 'install'));
$mform->setType('prefix', PARAM_ALPHANUMEXT);
$mform->addElement('text', 'dbport', get_string('dbport', 'install'));
$mform->setType('dbport', PARAM_INT);
if ($CFG->ostype !== 'WINDOWS') {
$mform->addElement('text', 'dbsocket', get_string('databasesocket', 'install'));
} else {
$mform->addElement('hidden', 'dbsocket');
}
$mform->setType('dbsocket', PARAM_RAW);
$mform->addRule('driver', get_string('required'), 'required', null);
$mform->addRule('dbhost', get_string('required'), 'required', null);
$mform->addRule('dbname', get_string('required'), 'required', null);
$mform->addRule('dbuser', get_string('required'), 'required', null);
$mform->addRule('dbpass', get_string('required'), 'required', null);
if (!isset($drivers['mysqli/native'])) {
$mform->addRule('prefix', get_string('required'), 'required', null);
}
$mform->addElement('header', 'database', get_string('options', 'tool_dbtransfer'));
$mform->addElement('advcheckbox', 'enablemaintenance', get_string('enablemaintenance', 'tool_dbtransfer'));
$mform->setType('enablemaintenance', PARAM_BOOL);
$mform->addHelpButton('enablemaintenance', 'enablemaintenance', 'tool_dbtransfer');
$this->add_action_buttons(false, get_string('transferdata', 'tool_dbtransfer'));
}
|
[
"protected",
"function",
"definition",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"mform",
"=",
"$",
"this",
"->",
"_form",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'header'",
",",
"'database'",
",",
"get_string",
"(",
"'targetdatabase'",
",",
"'tool_dbtransfer'",
")",
")",
";",
"$",
"drivers",
"=",
"tool_dbtransfer_get_drivers",
"(",
")",
";",
"$",
"drivers",
"=",
"array_reverse",
"(",
"$",
"drivers",
",",
"true",
")",
";",
"$",
"drivers",
"[",
"''",
"]",
"=",
"get_string",
"(",
"'choosedots'",
")",
";",
"$",
"drivers",
"=",
"array_reverse",
"(",
"$",
"drivers",
",",
"true",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'select'",
",",
"'driver'",
",",
"get_string",
"(",
"'dbtype'",
",",
"'install'",
")",
",",
"$",
"drivers",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'driver'",
",",
"PARAM_RAW",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'text'",
",",
"'dbhost'",
",",
"get_string",
"(",
"'databasehost'",
",",
"'install'",
")",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'dbhost'",
",",
"PARAM_HOST",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'text'",
",",
"'dbname'",
",",
"get_string",
"(",
"'databasename'",
",",
"'install'",
")",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'dbname'",
",",
"PARAM_ALPHANUMEXT",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'text'",
",",
"'dbuser'",
",",
"get_string",
"(",
"'databaseuser'",
",",
"'install'",
")",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'dbuser'",
",",
"PARAM_ALPHANUMEXT",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'passwordunmask'",
",",
"'dbpass'",
",",
"get_string",
"(",
"'databasepass'",
",",
"'install'",
")",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'dbpass'",
",",
"PARAM_RAW",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'text'",
",",
"'prefix'",
",",
"get_string",
"(",
"'dbprefix'",
",",
"'install'",
")",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'prefix'",
",",
"PARAM_ALPHANUMEXT",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'text'",
",",
"'dbport'",
",",
"get_string",
"(",
"'dbport'",
",",
"'install'",
")",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'dbport'",
",",
"PARAM_INT",
")",
";",
"if",
"(",
"$",
"CFG",
"->",
"ostype",
"!==",
"'WINDOWS'",
")",
"{",
"$",
"mform",
"->",
"addElement",
"(",
"'text'",
",",
"'dbsocket'",
",",
"get_string",
"(",
"'databasesocket'",
",",
"'install'",
")",
")",
";",
"}",
"else",
"{",
"$",
"mform",
"->",
"addElement",
"(",
"'hidden'",
",",
"'dbsocket'",
")",
";",
"}",
"$",
"mform",
"->",
"setType",
"(",
"'dbsocket'",
",",
"PARAM_RAW",
")",
";",
"$",
"mform",
"->",
"addRule",
"(",
"'driver'",
",",
"get_string",
"(",
"'required'",
")",
",",
"'required'",
",",
"null",
")",
";",
"$",
"mform",
"->",
"addRule",
"(",
"'dbhost'",
",",
"get_string",
"(",
"'required'",
")",
",",
"'required'",
",",
"null",
")",
";",
"$",
"mform",
"->",
"addRule",
"(",
"'dbname'",
",",
"get_string",
"(",
"'required'",
")",
",",
"'required'",
",",
"null",
")",
";",
"$",
"mform",
"->",
"addRule",
"(",
"'dbuser'",
",",
"get_string",
"(",
"'required'",
")",
",",
"'required'",
",",
"null",
")",
";",
"$",
"mform",
"->",
"addRule",
"(",
"'dbpass'",
",",
"get_string",
"(",
"'required'",
")",
",",
"'required'",
",",
"null",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"drivers",
"[",
"'mysqli/native'",
"]",
")",
")",
"{",
"$",
"mform",
"->",
"addRule",
"(",
"'prefix'",
",",
"get_string",
"(",
"'required'",
")",
",",
"'required'",
",",
"null",
")",
";",
"}",
"$",
"mform",
"->",
"addElement",
"(",
"'header'",
",",
"'database'",
",",
"get_string",
"(",
"'options'",
",",
"'tool_dbtransfer'",
")",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'advcheckbox'",
",",
"'enablemaintenance'",
",",
"get_string",
"(",
"'enablemaintenance'",
",",
"'tool_dbtransfer'",
")",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'enablemaintenance'",
",",
"PARAM_BOOL",
")",
";",
"$",
"mform",
"->",
"addHelpButton",
"(",
"'enablemaintenance'",
",",
"'enablemaintenance'",
",",
"'tool_dbtransfer'",
")",
";",
"$",
"this",
"->",
"add_action_buttons",
"(",
"false",
",",
"get_string",
"(",
"'transferdata'",
",",
"'tool_dbtransfer'",
")",
")",
";",
"}"
] |
Define transfer form.
|
[
"Define",
"transfer",
"form",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dbtransfer/database_transfer_form.php#L42-L98
|
218,363
|
moodle/moodle
|
lib/htmlpurifier/HTMLPurifier/AttrDef.php
|
HTMLPurifier_AttrDef.expandCSSEscape
|
protected function expandCSSEscape($string)
{
// flexibly parse it
$ret = '';
for ($i = 0, $c = strlen($string); $i < $c; $i++) {
if ($string[$i] === '\\') {
$i++;
if ($i >= $c) {
$ret .= '\\';
break;
}
if (ctype_xdigit($string[$i])) {
$code = $string[$i];
for ($a = 1, $i++; $i < $c && $a < 6; $i++, $a++) {
if (!ctype_xdigit($string[$i])) {
break;
}
$code .= $string[$i];
}
// We have to be extremely careful when adding
// new characters, to make sure we're not breaking
// the encoding.
$char = HTMLPurifier_Encoder::unichr(hexdec($code));
if (HTMLPurifier_Encoder::cleanUTF8($char) === '') {
continue;
}
$ret .= $char;
if ($i < $c && trim($string[$i]) !== '') {
$i--;
}
continue;
}
if ($string[$i] === "\n") {
continue;
}
}
$ret .= $string[$i];
}
return $ret;
}
|
php
|
protected function expandCSSEscape($string)
{
// flexibly parse it
$ret = '';
for ($i = 0, $c = strlen($string); $i < $c; $i++) {
if ($string[$i] === '\\') {
$i++;
if ($i >= $c) {
$ret .= '\\';
break;
}
if (ctype_xdigit($string[$i])) {
$code = $string[$i];
for ($a = 1, $i++; $i < $c && $a < 6; $i++, $a++) {
if (!ctype_xdigit($string[$i])) {
break;
}
$code .= $string[$i];
}
// We have to be extremely careful when adding
// new characters, to make sure we're not breaking
// the encoding.
$char = HTMLPurifier_Encoder::unichr(hexdec($code));
if (HTMLPurifier_Encoder::cleanUTF8($char) === '') {
continue;
}
$ret .= $char;
if ($i < $c && trim($string[$i]) !== '') {
$i--;
}
continue;
}
if ($string[$i] === "\n") {
continue;
}
}
$ret .= $string[$i];
}
return $ret;
}
|
[
"protected",
"function",
"expandCSSEscape",
"(",
"$",
"string",
")",
"{",
"// flexibly parse it",
"$",
"ret",
"=",
"''",
";",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"c",
"=",
"strlen",
"(",
"$",
"string",
")",
";",
"$",
"i",
"<",
"$",
"c",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"string",
"[",
"$",
"i",
"]",
"===",
"'\\\\'",
")",
"{",
"$",
"i",
"++",
";",
"if",
"(",
"$",
"i",
">=",
"$",
"c",
")",
"{",
"$",
"ret",
".=",
"'\\\\'",
";",
"break",
";",
"}",
"if",
"(",
"ctype_xdigit",
"(",
"$",
"string",
"[",
"$",
"i",
"]",
")",
")",
"{",
"$",
"code",
"=",
"$",
"string",
"[",
"$",
"i",
"]",
";",
"for",
"(",
"$",
"a",
"=",
"1",
",",
"$",
"i",
"++",
";",
"$",
"i",
"<",
"$",
"c",
"&&",
"$",
"a",
"<",
"6",
";",
"$",
"i",
"++",
",",
"$",
"a",
"++",
")",
"{",
"if",
"(",
"!",
"ctype_xdigit",
"(",
"$",
"string",
"[",
"$",
"i",
"]",
")",
")",
"{",
"break",
";",
"}",
"$",
"code",
".=",
"$",
"string",
"[",
"$",
"i",
"]",
";",
"}",
"// We have to be extremely careful when adding",
"// new characters, to make sure we're not breaking",
"// the encoding.",
"$",
"char",
"=",
"HTMLPurifier_Encoder",
"::",
"unichr",
"(",
"hexdec",
"(",
"$",
"code",
")",
")",
";",
"if",
"(",
"HTMLPurifier_Encoder",
"::",
"cleanUTF8",
"(",
"$",
"char",
")",
"===",
"''",
")",
"{",
"continue",
";",
"}",
"$",
"ret",
".=",
"$",
"char",
";",
"if",
"(",
"$",
"i",
"<",
"$",
"c",
"&&",
"trim",
"(",
"$",
"string",
"[",
"$",
"i",
"]",
")",
"!==",
"''",
")",
"{",
"$",
"i",
"--",
";",
"}",
"continue",
";",
"}",
"if",
"(",
"$",
"string",
"[",
"$",
"i",
"]",
"===",
"\"\\n\"",
")",
"{",
"continue",
";",
"}",
"}",
"$",
"ret",
".=",
"$",
"string",
"[",
"$",
"i",
"]",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] |
Parses a possibly escaped CSS string and returns the "pure"
version of it.
|
[
"Parses",
"a",
"possibly",
"escaped",
"CSS",
"string",
"and",
"returns",
"the",
"pure",
"version",
"of",
"it",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/AttrDef.php#L102-L141
|
218,364
|
moodle/moodle
|
lib/adodb/drivers/adodb-ads.inc.php
|
ADODB_ads.ServerInfo
|
function ServerInfo()
{
if (!empty($this->host) && ADODB_PHPVER >= 0x4300) {
$stmt = $this->Prepare('EXECUTE PROCEDURE sp_mgGetInstallInfo()');
$res = $this->Execute($stmt);
if(!$res)
print $this->ErrorMsg();
else{
$ret["version"]= $res->fields[3];
$ret["description"]="Advantage Database Server";
return $ret;
}
}
else {
return ADOConnection::ServerInfo();
}
}
|
php
|
function ServerInfo()
{
if (!empty($this->host) && ADODB_PHPVER >= 0x4300) {
$stmt = $this->Prepare('EXECUTE PROCEDURE sp_mgGetInstallInfo()');
$res = $this->Execute($stmt);
if(!$res)
print $this->ErrorMsg();
else{
$ret["version"]= $res->fields[3];
$ret["description"]="Advantage Database Server";
return $ret;
}
}
else {
return ADOConnection::ServerInfo();
}
}
|
[
"function",
"ServerInfo",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"host",
")",
"&&",
"ADODB_PHPVER",
">=",
"0x4300",
")",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"Prepare",
"(",
"'EXECUTE PROCEDURE sp_mgGetInstallInfo()'",
")",
";",
"$",
"res",
"=",
"$",
"this",
"->",
"Execute",
"(",
"$",
"stmt",
")",
";",
"if",
"(",
"!",
"$",
"res",
")",
"print",
"$",
"this",
"->",
"ErrorMsg",
"(",
")",
";",
"else",
"{",
"$",
"ret",
"[",
"\"version\"",
"]",
"=",
"$",
"res",
"->",
"fields",
"[",
"3",
"]",
";",
"$",
"ret",
"[",
"\"description\"",
"]",
"=",
"\"Advantage Database Server\"",
";",
"return",
"$",
"ret",
";",
"}",
"}",
"else",
"{",
"return",
"ADOConnection",
"::",
"ServerInfo",
"(",
")",
";",
"}",
"}"
] |
returns the Server version and Description
|
[
"returns",
"the",
"Server",
"version",
"and",
"Description"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/drivers/adodb-ads.inc.php#L118-L135
|
218,365
|
moodle/moodle
|
lib/adodb/drivers/adodb-ads.inc.php
|
ADODB_ads.GenID
|
function GenID($seqname = 'adodbseq', $start = 1)
{
$go = $this->Execute("select * from $seqname");
if (!$go){
$res = $this->Execute("CREATE TABLE $seqname ( ID autoinc( 1 ) ) IN DATABASE");
if(!res){
print $this->ErrorMsg();
return false;
}
}
$res = $this->Execute("INSERT INTO $seqname VALUES( DEFAULT )");
if(!$res){
print $this->ErrorMsg();
return false;
}
else{
$gen = $this->Execute("SELECT LastAutoInc( STATEMENT ) FROM system.iota");
$ret = $gen->fields[0];
return $ret;
}
}
|
php
|
function GenID($seqname = 'adodbseq', $start = 1)
{
$go = $this->Execute("select * from $seqname");
if (!$go){
$res = $this->Execute("CREATE TABLE $seqname ( ID autoinc( 1 ) ) IN DATABASE");
if(!res){
print $this->ErrorMsg();
return false;
}
}
$res = $this->Execute("INSERT INTO $seqname VALUES( DEFAULT )");
if(!$res){
print $this->ErrorMsg();
return false;
}
else{
$gen = $this->Execute("SELECT LastAutoInc( STATEMENT ) FROM system.iota");
$ret = $gen->fields[0];
return $ret;
}
}
|
[
"function",
"GenID",
"(",
"$",
"seqname",
"=",
"'adodbseq'",
",",
"$",
"start",
"=",
"1",
")",
"{",
"$",
"go",
"=",
"$",
"this",
"->",
"Execute",
"(",
"\"select * from $seqname\"",
")",
";",
"if",
"(",
"!",
"$",
"go",
")",
"{",
"$",
"res",
"=",
"$",
"this",
"->",
"Execute",
"(",
"\"CREATE TABLE $seqname ( ID autoinc( 1 ) ) IN DATABASE\"",
")",
";",
"if",
"(",
"!",
"res",
")",
"{",
"print",
"$",
"this",
"->",
"ErrorMsg",
"(",
")",
";",
"return",
"false",
";",
"}",
"}",
"$",
"res",
"=",
"$",
"this",
"->",
"Execute",
"(",
"\"INSERT INTO $seqname VALUES( DEFAULT )\"",
")",
";",
"if",
"(",
"!",
"$",
"res",
")",
"{",
"print",
"$",
"this",
"->",
"ErrorMsg",
"(",
")",
";",
"return",
"false",
";",
"}",
"else",
"{",
"$",
"gen",
"=",
"$",
"this",
"->",
"Execute",
"(",
"\"SELECT LastAutoInc( STATEMENT ) FROM system.iota\"",
")",
";",
"$",
"ret",
"=",
"$",
"gen",
"->",
"fields",
"[",
"0",
"]",
";",
"return",
"$",
"ret",
";",
"}",
"}"
] |
and gets the ID number of the last inserted record.
|
[
"and",
"gets",
"the",
"ID",
"number",
"of",
"the",
"last",
"inserted",
"record",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/drivers/adodb-ads.inc.php#L167-L188
|
218,366
|
moodle/moodle
|
lib/adodb/drivers/adodb-ads.inc.php
|
ADODB_ads.&
|
function &MetaTables($ttype = false, $showSchema = false, $mask = false)
{
$recordSet1 = $this->Execute("select * from system.tables");
if(!$recordSet1){
print $this->ErrorMsg();
return false;
}
$recordSet2 = $this->Execute("select * from system.views");
if(!$recordSet2){
print $this->ErrorMsg();
return false;
}
$i=0;
while (!$recordSet1->EOF){
$arr["$i"] = $recordSet1->fields[0];
$recordSet1->MoveNext();
$i=$i+1;
}
if($ttype=='FALSE'){
while (!$recordSet2->EOF){
$arr["$i"] = $recordSet2->fields[0];
$recordSet2->MoveNext();
$i=$i+1;
}
return $arr;
}
elseif($ttype=='VIEWS'){
while (!$recordSet2->EOF){
$arrV["$i"] = $recordSet2->fields[0];
$recordSet2->MoveNext();
$i=$i+1;
}
return $arrV;
}
else{
return $arr;
}
}
|
php
|
function &MetaTables($ttype = false, $showSchema = false, $mask = false)
{
$recordSet1 = $this->Execute("select * from system.tables");
if(!$recordSet1){
print $this->ErrorMsg();
return false;
}
$recordSet2 = $this->Execute("select * from system.views");
if(!$recordSet2){
print $this->ErrorMsg();
return false;
}
$i=0;
while (!$recordSet1->EOF){
$arr["$i"] = $recordSet1->fields[0];
$recordSet1->MoveNext();
$i=$i+1;
}
if($ttype=='FALSE'){
while (!$recordSet2->EOF){
$arr["$i"] = $recordSet2->fields[0];
$recordSet2->MoveNext();
$i=$i+1;
}
return $arr;
}
elseif($ttype=='VIEWS'){
while (!$recordSet2->EOF){
$arrV["$i"] = $recordSet2->fields[0];
$recordSet2->MoveNext();
$i=$i+1;
}
return $arrV;
}
else{
return $arr;
}
}
|
[
"function",
"&",
"MetaTables",
"(",
"$",
"ttype",
"=",
"false",
",",
"$",
"showSchema",
"=",
"false",
",",
"$",
"mask",
"=",
"false",
")",
"{",
"$",
"recordSet1",
"=",
"$",
"this",
"->",
"Execute",
"(",
"\"select * from system.tables\"",
")",
";",
"if",
"(",
"!",
"$",
"recordSet1",
")",
"{",
"print",
"$",
"this",
"->",
"ErrorMsg",
"(",
")",
";",
"return",
"false",
";",
"}",
"$",
"recordSet2",
"=",
"$",
"this",
"->",
"Execute",
"(",
"\"select * from system.views\"",
")",
";",
"if",
"(",
"!",
"$",
"recordSet2",
")",
"{",
"print",
"$",
"this",
"->",
"ErrorMsg",
"(",
")",
";",
"return",
"false",
";",
"}",
"$",
"i",
"=",
"0",
";",
"while",
"(",
"!",
"$",
"recordSet1",
"->",
"EOF",
")",
"{",
"$",
"arr",
"[",
"\"$i\"",
"]",
"=",
"$",
"recordSet1",
"->",
"fields",
"[",
"0",
"]",
";",
"$",
"recordSet1",
"->",
"MoveNext",
"(",
")",
";",
"$",
"i",
"=",
"$",
"i",
"+",
"1",
";",
"}",
"if",
"(",
"$",
"ttype",
"==",
"'FALSE'",
")",
"{",
"while",
"(",
"!",
"$",
"recordSet2",
"->",
"EOF",
")",
"{",
"$",
"arr",
"[",
"\"$i\"",
"]",
"=",
"$",
"recordSet2",
"->",
"fields",
"[",
"0",
"]",
";",
"$",
"recordSet2",
"->",
"MoveNext",
"(",
")",
";",
"$",
"i",
"=",
"$",
"i",
"+",
"1",
";",
"}",
"return",
"$",
"arr",
";",
"}",
"elseif",
"(",
"$",
"ttype",
"==",
"'VIEWS'",
")",
"{",
"while",
"(",
"!",
"$",
"recordSet2",
"->",
"EOF",
")",
"{",
"$",
"arrV",
"[",
"\"$i\"",
"]",
"=",
"$",
"recordSet2",
"->",
"fields",
"[",
"0",
"]",
";",
"$",
"recordSet2",
"->",
"MoveNext",
"(",
")",
";",
"$",
"i",
"=",
"$",
"i",
"+",
"1",
";",
"}",
"return",
"$",
"arrV",
";",
"}",
"else",
"{",
"return",
"$",
"arr",
";",
"}",
"}"
] |
tables by default on succesfull execustion.
|
[
"tables",
"by",
"default",
"on",
"succesfull",
"execustion",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/drivers/adodb-ads.inc.php#L257-L295
|
218,367
|
moodle/moodle
|
lib/adodb/drivers/adodb-ads.inc.php
|
ADODB_ads.&
|
function &MetaColumnNames($table, $numIndexes = false, $useattnum = false)
{
$recordSet = $this->Execute("select name from system.columns where parent='$table'");
if(!$recordSet){
print $this->ErrorMsg();
return false;
}
else{
$i=0;
while (!$recordSet->EOF){
$arr["FIELD$i"] = $recordSet->fields[0];
$recordSet->MoveNext();
$i=$i+1;
}
return $arr;
}
}
|
php
|
function &MetaColumnNames($table, $numIndexes = false, $useattnum = false)
{
$recordSet = $this->Execute("select name from system.columns where parent='$table'");
if(!$recordSet){
print $this->ErrorMsg();
return false;
}
else{
$i=0;
while (!$recordSet->EOF){
$arr["FIELD$i"] = $recordSet->fields[0];
$recordSet->MoveNext();
$i=$i+1;
}
return $arr;
}
}
|
[
"function",
"&",
"MetaColumnNames",
"(",
"$",
"table",
",",
"$",
"numIndexes",
"=",
"false",
",",
"$",
"useattnum",
"=",
"false",
")",
"{",
"$",
"recordSet",
"=",
"$",
"this",
"->",
"Execute",
"(",
"\"select name from system.columns where parent='$table'\"",
")",
";",
"if",
"(",
"!",
"$",
"recordSet",
")",
"{",
"print",
"$",
"this",
"->",
"ErrorMsg",
"(",
")",
";",
"return",
"false",
";",
"}",
"else",
"{",
"$",
"i",
"=",
"0",
";",
"while",
"(",
"!",
"$",
"recordSet",
"->",
"EOF",
")",
"{",
"$",
"arr",
"[",
"\"FIELD$i\"",
"]",
"=",
"$",
"recordSet",
"->",
"fields",
"[",
"0",
"]",
";",
"$",
"recordSet",
"->",
"MoveNext",
"(",
")",
";",
"$",
"i",
"=",
"$",
"i",
"+",
"1",
";",
"}",
"return",
"$",
"arr",
";",
"}",
"}"
] |
Returns an array of columns names for a given table
|
[
"Returns",
"an",
"array",
"of",
"columns",
"names",
"for",
"a",
"given",
"table"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/drivers/adodb-ads.inc.php#L489-L505
|
218,368
|
moodle/moodle
|
lib/horde/framework/Horde/Util.php
|
Horde_Util.nonInputVar
|
public static function nonInputVar($varname, $default = null)
{
return (isset($_GET[$varname]) || isset($_POST[$varname]) || isset($_COOKIE[$varname]))
? $default
: (isset($GLOBALS[$varname]) ? $GLOBALS[$varname] : $default);
}
|
php
|
public static function nonInputVar($varname, $default = null)
{
return (isset($_GET[$varname]) || isset($_POST[$varname]) || isset($_COOKIE[$varname]))
? $default
: (isset($GLOBALS[$varname]) ? $GLOBALS[$varname] : $default);
}
|
[
"public",
"static",
"function",
"nonInputVar",
"(",
"$",
"varname",
",",
"$",
"default",
"=",
"null",
")",
"{",
"return",
"(",
"isset",
"(",
"$",
"_GET",
"[",
"$",
"varname",
"]",
")",
"||",
"isset",
"(",
"$",
"_POST",
"[",
"$",
"varname",
"]",
")",
"||",
"isset",
"(",
"$",
"_COOKIE",
"[",
"$",
"varname",
"]",
")",
")",
"?",
"$",
"default",
":",
"(",
"isset",
"(",
"$",
"GLOBALS",
"[",
"$",
"varname",
"]",
")",
"?",
"$",
"GLOBALS",
"[",
"$",
"varname",
"]",
":",
"$",
"default",
")",
";",
"}"
] |
Checks to see if a value has been set by the script and not by GET,
POST, or cookie input. The value being checked MUST be in the global
scope.
@param string $varname The variable name to check.
@param mixed $default Default value if the variable isn't present
or was specified by the user. Defaults to null.
@return mixed $default if the var is in user input or not present,
the variable value otherwise.
|
[
"Checks",
"to",
"see",
"if",
"a",
"value",
"has",
"been",
"set",
"by",
"the",
"script",
"and",
"not",
"by",
"GET",
"POST",
"or",
"cookie",
"input",
".",
"The",
"value",
"being",
"checked",
"MUST",
"be",
"in",
"the",
"global",
"scope",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Util.php#L76-L81
|
218,369
|
moodle/moodle
|
lib/horde/framework/Horde/Util.php
|
Horde_Util.formInput
|
public static function formInput($append_session = 0)
{
return (($append_session == 1) || !isset($_COOKIE[session_name()]))
? '<input type="hidden" name="' . htmlspecialchars(session_name()) . '" value="' . htmlspecialchars(session_id()) . "\" />\n"
: '';
}
|
php
|
public static function formInput($append_session = 0)
{
return (($append_session == 1) || !isset($_COOKIE[session_name()]))
? '<input type="hidden" name="' . htmlspecialchars(session_name()) . '" value="' . htmlspecialchars(session_id()) . "\" />\n"
: '';
}
|
[
"public",
"static",
"function",
"formInput",
"(",
"$",
"append_session",
"=",
"0",
")",
"{",
"return",
"(",
"(",
"$",
"append_session",
"==",
"1",
")",
"||",
"!",
"isset",
"(",
"$",
"_COOKIE",
"[",
"session_name",
"(",
")",
"]",
")",
")",
"?",
"'<input type=\"hidden\" name=\"'",
".",
"htmlspecialchars",
"(",
"session_name",
"(",
")",
")",
".",
"'\" value=\"'",
".",
"htmlspecialchars",
"(",
"session_id",
"(",
")",
")",
".",
"\"\\\" />\\n\"",
":",
"''",
";",
"}"
] |
Returns a hidden form input containing the session name and id.
@param boolean $append_session 0 = only if needed, 1 = always.
@return string The hidden form input, if needed/requested.
|
[
"Returns",
"a",
"hidden",
"form",
"input",
"containing",
"the",
"session",
"name",
"and",
"id",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Util.php#L90-L95
|
218,370
|
moodle/moodle
|
lib/horde/framework/Horde/Util.php
|
Horde_Util.createTempDir
|
public static function createTempDir($delete = true, $temp_dir = null)
{
if (is_null($temp_dir)) {
$temp_dir = sys_get_temp_dir();
}
if (empty($temp_dir)) {
return false;
}
/* Get the first 8 characters of a random string to use as a temporary
directory name. */
do {
$new_dir = $temp_dir . '/' . substr(base_convert(uniqid(mt_rand()), 10, 36), 0, 8);
} while (file_exists($new_dir));
$old_umask = umask(0000);
if (!mkdir($new_dir, 0700)) {
$new_dir = false;
} elseif ($delete) {
self::deleteAtShutdown($new_dir);
}
umask($old_umask);
return $new_dir;
}
|
php
|
public static function createTempDir($delete = true, $temp_dir = null)
{
if (is_null($temp_dir)) {
$temp_dir = sys_get_temp_dir();
}
if (empty($temp_dir)) {
return false;
}
/* Get the first 8 characters of a random string to use as a temporary
directory name. */
do {
$new_dir = $temp_dir . '/' . substr(base_convert(uniqid(mt_rand()), 10, 36), 0, 8);
} while (file_exists($new_dir));
$old_umask = umask(0000);
if (!mkdir($new_dir, 0700)) {
$new_dir = false;
} elseif ($delete) {
self::deleteAtShutdown($new_dir);
}
umask($old_umask);
return $new_dir;
}
|
[
"public",
"static",
"function",
"createTempDir",
"(",
"$",
"delete",
"=",
"true",
",",
"$",
"temp_dir",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"temp_dir",
")",
")",
"{",
"$",
"temp_dir",
"=",
"sys_get_temp_dir",
"(",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"temp_dir",
")",
")",
"{",
"return",
"false",
";",
"}",
"/* Get the first 8 characters of a random string to use as a temporary\n directory name. */",
"do",
"{",
"$",
"new_dir",
"=",
"$",
"temp_dir",
".",
"'/'",
".",
"substr",
"(",
"base_convert",
"(",
"uniqid",
"(",
"mt_rand",
"(",
")",
")",
",",
"10",
",",
"36",
")",
",",
"0",
",",
"8",
")",
";",
"}",
"while",
"(",
"file_exists",
"(",
"$",
"new_dir",
")",
")",
";",
"$",
"old_umask",
"=",
"umask",
"(",
"0000",
")",
";",
"if",
"(",
"!",
"mkdir",
"(",
"$",
"new_dir",
",",
"0700",
")",
")",
"{",
"$",
"new_dir",
"=",
"false",
";",
"}",
"elseif",
"(",
"$",
"delete",
")",
"{",
"self",
"::",
"deleteAtShutdown",
"(",
"$",
"new_dir",
")",
";",
"}",
"umask",
"(",
"$",
"old_umask",
")",
";",
"return",
"$",
"new_dir",
";",
"}"
] |
Creates a temporary directory in the system's temporary directory.
@param boolean $delete Delete the temporary directory at the end of
the request?
@param string $temp_dir Use this temporary directory as the directory
where the temporary directory will be created.
@return string The pathname to the new temporary directory.
Returns false if directory not created.
|
[
"Creates",
"a",
"temporary",
"directory",
"in",
"the",
"system",
"s",
"temporary",
"directory",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Util.php#L294-L319
|
218,371
|
moodle/moodle
|
lib/horde/framework/Horde/Util.php
|
Horde_Util.deleteAtShutdown
|
public static function deleteAtShutdown($filename, $register = true,
$secure = false)
{
/* Initialization of variables and shutdown functions. */
if (!self::$_shutdownreg) {
register_shutdown_function(array(__CLASS__, 'shutdown'));
self::$_shutdownreg = true;
}
$ptr = &self::$_shutdowndata;
if ($register) {
$ptr['paths'][$filename] = true;
if ($secure) {
$ptr['secure'][$filename] = true;
}
} else {
unset($ptr['paths'][$filename], $ptr['secure'][$filename]);
}
}
|
php
|
public static function deleteAtShutdown($filename, $register = true,
$secure = false)
{
/* Initialization of variables and shutdown functions. */
if (!self::$_shutdownreg) {
register_shutdown_function(array(__CLASS__, 'shutdown'));
self::$_shutdownreg = true;
}
$ptr = &self::$_shutdowndata;
if ($register) {
$ptr['paths'][$filename] = true;
if ($secure) {
$ptr['secure'][$filename] = true;
}
} else {
unset($ptr['paths'][$filename], $ptr['secure'][$filename]);
}
}
|
[
"public",
"static",
"function",
"deleteAtShutdown",
"(",
"$",
"filename",
",",
"$",
"register",
"=",
"true",
",",
"$",
"secure",
"=",
"false",
")",
"{",
"/* Initialization of variables and shutdown functions. */",
"if",
"(",
"!",
"self",
"::",
"$",
"_shutdownreg",
")",
"{",
"register_shutdown_function",
"(",
"array",
"(",
"__CLASS__",
",",
"'shutdown'",
")",
")",
";",
"self",
"::",
"$",
"_shutdownreg",
"=",
"true",
";",
"}",
"$",
"ptr",
"=",
"&",
"self",
"::",
"$",
"_shutdowndata",
";",
"if",
"(",
"$",
"register",
")",
"{",
"$",
"ptr",
"[",
"'paths'",
"]",
"[",
"$",
"filename",
"]",
"=",
"true",
";",
"if",
"(",
"$",
"secure",
")",
"{",
"$",
"ptr",
"[",
"'secure'",
"]",
"[",
"$",
"filename",
"]",
"=",
"true",
";",
"}",
"}",
"else",
"{",
"unset",
"(",
"$",
"ptr",
"[",
"'paths'",
"]",
"[",
"$",
"filename",
"]",
",",
"$",
"ptr",
"[",
"'secure'",
"]",
"[",
"$",
"filename",
"]",
")",
";",
"}",
"}"
] |
Removes given elements at request shutdown.
If called with a filename will delete that file at request shutdown; if
called with a directory will remove that directory and all files in that
directory at request shutdown.
If called with no arguments, return all elements to be deleted (this
should only be done by Horde_Util::_deleteAtShutdown()).
The first time it is called, it initializes the array and registers
Horde_Util::_deleteAtShutdown() as a shutdown function - no need to do
so manually.
The second parameter allows the unregistering of previously registered
elements.
@param string $filename The filename to be deleted at the end of the
request.
@param boolean $register If true, then register the element for
deletion, otherwise, unregister it.
@param boolean $secure If deleting file, should we securely delete
the file?
|
[
"Removes",
"given",
"elements",
"at",
"request",
"shutdown",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Util.php#L388-L406
|
218,372
|
moodle/moodle
|
lib/horde/framework/Horde/Util.php
|
Horde_Util.shutdown
|
public static function shutdown()
{
$ptr = &self::$_shutdowndata;
foreach (array_keys($ptr['paths']) as $val) {
if (@is_file($val)) {
self::_secureDelete($val);
continue;
}
try {
$it = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($val),
RecursiveIteratorIterator::CHILD_FIRST
);
} catch (UnexpectedValueException $e) {
continue;
}
while ($it->valid()) {
if (!$it->isDot()) {
if ($it->isDir()) {
@rmdir($it->key());
} elseif ($it->isFile()) {
self::_secureDelete($it->key());
} else {
@unlink($it->key());
}
}
$it->next();
}
@rmdir($val);
}
}
|
php
|
public static function shutdown()
{
$ptr = &self::$_shutdowndata;
foreach (array_keys($ptr['paths']) as $val) {
if (@is_file($val)) {
self::_secureDelete($val);
continue;
}
try {
$it = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($val),
RecursiveIteratorIterator::CHILD_FIRST
);
} catch (UnexpectedValueException $e) {
continue;
}
while ($it->valid()) {
if (!$it->isDot()) {
if ($it->isDir()) {
@rmdir($it->key());
} elseif ($it->isFile()) {
self::_secureDelete($it->key());
} else {
@unlink($it->key());
}
}
$it->next();
}
@rmdir($val);
}
}
|
[
"public",
"static",
"function",
"shutdown",
"(",
")",
"{",
"$",
"ptr",
"=",
"&",
"self",
"::",
"$",
"_shutdowndata",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"ptr",
"[",
"'paths'",
"]",
")",
"as",
"$",
"val",
")",
"{",
"if",
"(",
"@",
"is_file",
"(",
"$",
"val",
")",
")",
"{",
"self",
"::",
"_secureDelete",
"(",
"$",
"val",
")",
";",
"continue",
";",
"}",
"try",
"{",
"$",
"it",
"=",
"new",
"RecursiveIteratorIterator",
"(",
"new",
"RecursiveDirectoryIterator",
"(",
"$",
"val",
")",
",",
"RecursiveIteratorIterator",
"::",
"CHILD_FIRST",
")",
";",
"}",
"catch",
"(",
"UnexpectedValueException",
"$",
"e",
")",
"{",
"continue",
";",
"}",
"while",
"(",
"$",
"it",
"->",
"valid",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"it",
"->",
"isDot",
"(",
")",
")",
"{",
"if",
"(",
"$",
"it",
"->",
"isDir",
"(",
")",
")",
"{",
"@",
"rmdir",
"(",
"$",
"it",
"->",
"key",
"(",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"it",
"->",
"isFile",
"(",
")",
")",
"{",
"self",
"::",
"_secureDelete",
"(",
"$",
"it",
"->",
"key",
"(",
")",
")",
";",
"}",
"else",
"{",
"@",
"unlink",
"(",
"$",
"it",
"->",
"key",
"(",
")",
")",
";",
"}",
"}",
"$",
"it",
"->",
"next",
"(",
")",
";",
"}",
"@",
"rmdir",
"(",
"$",
"val",
")",
";",
"}",
"}"
] |
Deletes registered files at request shutdown.
This function should never be called manually; it is registered as a
shutdown function by Horde_Util::deleteAtShutdown() and called
automatically at the end of the request.
Contains code from gpg_functions.php.
Copyright 2002-2003 Braverock Ventures
|
[
"Deletes",
"registered",
"files",
"at",
"request",
"shutdown",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Util.php#L418-L452
|
218,373
|
moodle/moodle
|
lib/horde/framework/Horde/Util.php
|
Horde_Util._secureDelete
|
protected static function _secureDelete($file)
{
if (isset($ptr['secure'][$file])) {
$filesize = filesize($file);
$fp = fopen($file, 'r+');
foreach (self::$patterns as $pattern) {
$pattern = substr(str_repeat($pattern, floor($filesize / strlen($pattern)) + 1), 0, $filesize);
fwrite($fp, $pattern);
fseek($fp, 0);
}
fclose($fp);
}
@unlink($file);
}
|
php
|
protected static function _secureDelete($file)
{
if (isset($ptr['secure'][$file])) {
$filesize = filesize($file);
$fp = fopen($file, 'r+');
foreach (self::$patterns as $pattern) {
$pattern = substr(str_repeat($pattern, floor($filesize / strlen($pattern)) + 1), 0, $filesize);
fwrite($fp, $pattern);
fseek($fp, 0);
}
fclose($fp);
}
@unlink($file);
}
|
[
"protected",
"static",
"function",
"_secureDelete",
"(",
"$",
"file",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"ptr",
"[",
"'secure'",
"]",
"[",
"$",
"file",
"]",
")",
")",
"{",
"$",
"filesize",
"=",
"filesize",
"(",
"$",
"file",
")",
";",
"$",
"fp",
"=",
"fopen",
"(",
"$",
"file",
",",
"'r+'",
")",
";",
"foreach",
"(",
"self",
"::",
"$",
"patterns",
"as",
"$",
"pattern",
")",
"{",
"$",
"pattern",
"=",
"substr",
"(",
"str_repeat",
"(",
"$",
"pattern",
",",
"floor",
"(",
"$",
"filesize",
"/",
"strlen",
"(",
"$",
"pattern",
")",
")",
"+",
"1",
")",
",",
"0",
",",
"$",
"filesize",
")",
";",
"fwrite",
"(",
"$",
"fp",
",",
"$",
"pattern",
")",
";",
"fseek",
"(",
"$",
"fp",
",",
"0",
")",
";",
"}",
"fclose",
"(",
"$",
"fp",
")",
";",
"}",
"@",
"unlink",
"(",
"$",
"file",
")",
";",
"}"
] |
Securely delete the file by overwriting the data with a random
string.
@param string $file Filename.
|
[
"Securely",
"delete",
"the",
"file",
"by",
"overwriting",
"the",
"data",
"with",
"a",
"random",
"string",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Util.php#L460-L474
|
218,374
|
moodle/moodle
|
lib/horde/framework/Horde/Util.php
|
Horde_Util.loadExtension
|
public static function loadExtension($ext)
{
/* If $ext is already loaded, our work is done. */
if (self::extensionExists($ext)) {
return true;
}
/* See if we can call dl() at all, by the current ini settings.
* dl() has been removed in some PHP 5.3 SAPIs. */
if ((ini_get('enable_dl') != 1) ||
(ini_get('safe_mode') == 1) ||
!function_exists('dl')) {
return false;
}
if (!strncasecmp(PHP_OS, 'WIN', 3)) {
$suffix = 'dll';
} else {
switch (PHP_OS) {
case 'HP-UX':
$suffix = 'sl';
break;
case 'AIX':
$suffix = 'a';
break;
case 'OSX':
$suffix = 'bundle';
break;
default:
$suffix = 'so';
}
}
return dl($ext . '.' . $suffix) || dl('php_' . $ext . '.' . $suffix);
}
|
php
|
public static function loadExtension($ext)
{
/* If $ext is already loaded, our work is done. */
if (self::extensionExists($ext)) {
return true;
}
/* See if we can call dl() at all, by the current ini settings.
* dl() has been removed in some PHP 5.3 SAPIs. */
if ((ini_get('enable_dl') != 1) ||
(ini_get('safe_mode') == 1) ||
!function_exists('dl')) {
return false;
}
if (!strncasecmp(PHP_OS, 'WIN', 3)) {
$suffix = 'dll';
} else {
switch (PHP_OS) {
case 'HP-UX':
$suffix = 'sl';
break;
case 'AIX':
$suffix = 'a';
break;
case 'OSX':
$suffix = 'bundle';
break;
default:
$suffix = 'so';
}
}
return dl($ext . '.' . $suffix) || dl('php_' . $ext . '.' . $suffix);
}
|
[
"public",
"static",
"function",
"loadExtension",
"(",
"$",
"ext",
")",
"{",
"/* If $ext is already loaded, our work is done. */",
"if",
"(",
"self",
"::",
"extensionExists",
"(",
"$",
"ext",
")",
")",
"{",
"return",
"true",
";",
"}",
"/* See if we can call dl() at all, by the current ini settings.\n * dl() has been removed in some PHP 5.3 SAPIs. */",
"if",
"(",
"(",
"ini_get",
"(",
"'enable_dl'",
")",
"!=",
"1",
")",
"||",
"(",
"ini_get",
"(",
"'safe_mode'",
")",
"==",
"1",
")",
"||",
"!",
"function_exists",
"(",
"'dl'",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"strncasecmp",
"(",
"PHP_OS",
",",
"'WIN'",
",",
"3",
")",
")",
"{",
"$",
"suffix",
"=",
"'dll'",
";",
"}",
"else",
"{",
"switch",
"(",
"PHP_OS",
")",
"{",
"case",
"'HP-UX'",
":",
"$",
"suffix",
"=",
"'sl'",
";",
"break",
";",
"case",
"'AIX'",
":",
"$",
"suffix",
"=",
"'a'",
";",
"break",
";",
"case",
"'OSX'",
":",
"$",
"suffix",
"=",
"'bundle'",
";",
"break",
";",
"default",
":",
"$",
"suffix",
"=",
"'so'",
";",
"}",
"}",
"return",
"dl",
"(",
"$",
"ext",
".",
"'.'",
".",
"$",
"suffix",
")",
"||",
"dl",
"(",
"'php_'",
".",
"$",
"ext",
".",
"'.'",
".",
"$",
"suffix",
")",
";",
"}"
] |
Tries to load a PHP extension, behaving correctly for all operating
systems.
@param string $ext The extension to load.
@return boolean True if the extension is now loaded, false if not.
True can mean that the extension was already loaded,
OR was loaded dynamically.
|
[
"Tries",
"to",
"load",
"a",
"PHP",
"extension",
"behaving",
"correctly",
"for",
"all",
"operating",
"systems",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Util.php#L502-L539
|
218,375
|
moodle/moodle
|
lib/horde/framework/Horde/Util.php
|
Horde_Util.getPathInfo
|
public static function getPathInfo()
{
if (isset($_SERVER['PATH_INFO']) &&
(strpos($_SERVER['SERVER_SOFTWARE'], 'lighttpd') === false)) {
return $_SERVER['PATH_INFO'];
} elseif (isset($_SERVER['REQUEST_URI']) &&
isset($_SERVER['SCRIPT_NAME'])) {
$search = Horde_String::common($_SERVER['SCRIPT_NAME'], $_SERVER['REQUEST_URI']);
if (substr($search, -1) == '/') {
$search = substr($search, 0, -1);
}
$search = array($search);
if (!empty($_SERVER['QUERY_STRING'])) {
// We can't use QUERY_STRING directly because URL rewriting
// might add more parameters to the query string than those
// from the request URI.
$url = parse_url($_SERVER['REQUEST_URI']);
if (!empty($url['query'])) {
$search[] = '?' . $url['query'];
}
}
$path = str_replace($search, '', $_SERVER['REQUEST_URI']);
if ($path == '/') {
$path = '';
}
return $path;
}
return '';
}
|
php
|
public static function getPathInfo()
{
if (isset($_SERVER['PATH_INFO']) &&
(strpos($_SERVER['SERVER_SOFTWARE'], 'lighttpd') === false)) {
return $_SERVER['PATH_INFO'];
} elseif (isset($_SERVER['REQUEST_URI']) &&
isset($_SERVER['SCRIPT_NAME'])) {
$search = Horde_String::common($_SERVER['SCRIPT_NAME'], $_SERVER['REQUEST_URI']);
if (substr($search, -1) == '/') {
$search = substr($search, 0, -1);
}
$search = array($search);
if (!empty($_SERVER['QUERY_STRING'])) {
// We can't use QUERY_STRING directly because URL rewriting
// might add more parameters to the query string than those
// from the request URI.
$url = parse_url($_SERVER['REQUEST_URI']);
if (!empty($url['query'])) {
$search[] = '?' . $url['query'];
}
}
$path = str_replace($search, '', $_SERVER['REQUEST_URI']);
if ($path == '/') {
$path = '';
}
return $path;
}
return '';
}
|
[
"public",
"static",
"function",
"getPathInfo",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'PATH_INFO'",
"]",
")",
"&&",
"(",
"strpos",
"(",
"$",
"_SERVER",
"[",
"'SERVER_SOFTWARE'",
"]",
",",
"'lighttpd'",
")",
"===",
"false",
")",
")",
"{",
"return",
"$",
"_SERVER",
"[",
"'PATH_INFO'",
"]",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
")",
"&&",
"isset",
"(",
"$",
"_SERVER",
"[",
"'SCRIPT_NAME'",
"]",
")",
")",
"{",
"$",
"search",
"=",
"Horde_String",
"::",
"common",
"(",
"$",
"_SERVER",
"[",
"'SCRIPT_NAME'",
"]",
",",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"search",
",",
"-",
"1",
")",
"==",
"'/'",
")",
"{",
"$",
"search",
"=",
"substr",
"(",
"$",
"search",
",",
"0",
",",
"-",
"1",
")",
";",
"}",
"$",
"search",
"=",
"array",
"(",
"$",
"search",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'QUERY_STRING'",
"]",
")",
")",
"{",
"// We can't use QUERY_STRING directly because URL rewriting",
"// might add more parameters to the query string than those",
"// from the request URI.",
"$",
"url",
"=",
"parse_url",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"url",
"[",
"'query'",
"]",
")",
")",
"{",
"$",
"search",
"[",
"]",
"=",
"'?'",
".",
"$",
"url",
"[",
"'query'",
"]",
";",
"}",
"}",
"$",
"path",
"=",
"str_replace",
"(",
"$",
"search",
",",
"''",
",",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
")",
";",
"if",
"(",
"$",
"path",
"==",
"'/'",
")",
"{",
"$",
"path",
"=",
"''",
";",
"}",
"return",
"$",
"path",
";",
"}",
"return",
"''",
";",
"}"
] |
Utility function to obtain PATH_INFO information.
@return string The PATH_INFO string.
|
[
"Utility",
"function",
"to",
"obtain",
"PATH_INFO",
"information",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Util.php#L546-L575
|
218,376
|
moodle/moodle
|
mod/workshop/eval/best/backup/moodle2/restore_workshopeval_best_subplugin.class.php
|
restore_workshopeval_best_subplugin.process_workshopeval_best_setting
|
public function process_workshopeval_best_setting($data) {
global $DB;
$data = (object)$data;
$data->workshopid = $this->get_new_parentid('workshop');
$DB->insert_record('workshopeval_best_settings', $data);
}
|
php
|
public function process_workshopeval_best_setting($data) {
global $DB;
$data = (object)$data;
$data->workshopid = $this->get_new_parentid('workshop');
$DB->insert_record('workshopeval_best_settings', $data);
}
|
[
"public",
"function",
"process_workshopeval_best_setting",
"(",
"$",
"data",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"data",
"=",
"(",
"object",
")",
"$",
"data",
";",
"$",
"data",
"->",
"workshopid",
"=",
"$",
"this",
"->",
"get_new_parentid",
"(",
"'workshop'",
")",
";",
"$",
"DB",
"->",
"insert_record",
"(",
"'workshopeval_best_settings'",
",",
"$",
"data",
")",
";",
"}"
] |
Processes one workshopeval_best_settings element
|
[
"Processes",
"one",
"workshopeval_best_settings",
"element"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/eval/best/backup/moodle2/restore_workshopeval_best_subplugin.class.php#L56-L62
|
218,377
|
moodle/moodle
|
question/type/randomsamatch/question.php
|
qtype_randomsamatch_question.find_right_answer
|
public function find_right_answer($wrappedquestion) {
// We only take into account *one* (the first) correct answer.
while ($answer = array_shift($wrappedquestion->answers)) {
if (!question_state::graded_state_for_fraction(
$answer->fraction)->is_incorrect()) {
// Store this answer as a choice, only if this is a new one.
$key = array_search($answer->answer, $this->choices);
if ($key === false) {
$key = $answer->id;
$this->choices[$key] = $answer->answer;
}
return $key;
}
}
// We should never get there.
throw new coding_exception('shortanswerquestionwithoutrightanswer', $wrappedquestion->id);
}
|
php
|
public function find_right_answer($wrappedquestion) {
// We only take into account *one* (the first) correct answer.
while ($answer = array_shift($wrappedquestion->answers)) {
if (!question_state::graded_state_for_fraction(
$answer->fraction)->is_incorrect()) {
// Store this answer as a choice, only if this is a new one.
$key = array_search($answer->answer, $this->choices);
if ($key === false) {
$key = $answer->id;
$this->choices[$key] = $answer->answer;
}
return $key;
}
}
// We should never get there.
throw new coding_exception('shortanswerquestionwithoutrightanswer', $wrappedquestion->id);
}
|
[
"public",
"function",
"find_right_answer",
"(",
"$",
"wrappedquestion",
")",
"{",
"// We only take into account *one* (the first) correct answer.",
"while",
"(",
"$",
"answer",
"=",
"array_shift",
"(",
"$",
"wrappedquestion",
"->",
"answers",
")",
")",
"{",
"if",
"(",
"!",
"question_state",
"::",
"graded_state_for_fraction",
"(",
"$",
"answer",
"->",
"fraction",
")",
"->",
"is_incorrect",
"(",
")",
")",
"{",
"// Store this answer as a choice, only if this is a new one.",
"$",
"key",
"=",
"array_search",
"(",
"$",
"answer",
"->",
"answer",
",",
"$",
"this",
"->",
"choices",
")",
";",
"if",
"(",
"$",
"key",
"===",
"false",
")",
"{",
"$",
"key",
"=",
"$",
"answer",
"->",
"id",
";",
"$",
"this",
"->",
"choices",
"[",
"$",
"key",
"]",
"=",
"$",
"answer",
"->",
"answer",
";",
"}",
"return",
"$",
"key",
";",
"}",
"}",
"// We should never get there.",
"throw",
"new",
"coding_exception",
"(",
"'shortanswerquestionwithoutrightanswer'",
",",
"$",
"wrappedquestion",
"->",
"id",
")",
";",
"}"
] |
Find the corresponding choice id of the first correct answer of a shortanswer question.
choice is added to the randomsamatch question if it doesn't already exist.
@param object $wrappedquestion short answer question.
@return int correct choice id.
|
[
"Find",
"the",
"corresponding",
"choice",
"id",
"of",
"the",
"first",
"correct",
"answer",
"of",
"a",
"shortanswer",
"question",
".",
"choice",
"is",
"added",
"to",
"the",
"randomsamatch",
"question",
"if",
"it",
"doesn",
"t",
"already",
"exist",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/randomsamatch/question.php#L70-L87
|
218,378
|
moodle/moodle
|
question/type/randomsamatch/question.php
|
qtype_randomsamatch_question_loader.load_questions
|
public function load_questions() {
if ($this->choose > count($this->availablequestions)) {
throw new coding_exception('notenoughtshortanswerquestions');
}
$questionids = draw_rand_array($this->availablequestions, $this->choose);
$questions = array();
foreach ($questionids as $questionid) {
$questions[] = question_bank::load_question($questionid);
}
return $questions;
}
|
php
|
public function load_questions() {
if ($this->choose > count($this->availablequestions)) {
throw new coding_exception('notenoughtshortanswerquestions');
}
$questionids = draw_rand_array($this->availablequestions, $this->choose);
$questions = array();
foreach ($questionids as $questionid) {
$questions[] = question_bank::load_question($questionid);
}
return $questions;
}
|
[
"public",
"function",
"load_questions",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"choose",
">",
"count",
"(",
"$",
"this",
"->",
"availablequestions",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'notenoughtshortanswerquestions'",
")",
";",
"}",
"$",
"questionids",
"=",
"draw_rand_array",
"(",
"$",
"this",
"->",
"availablequestions",
",",
"$",
"this",
"->",
"choose",
")",
";",
"$",
"questions",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"questionids",
"as",
"$",
"questionid",
")",
"{",
"$",
"questions",
"[",
"]",
"=",
"question_bank",
"::",
"load_question",
"(",
"$",
"questionid",
")",
";",
"}",
"return",
"$",
"questions",
";",
"}"
] |
Choose and load the desired number of questions.
@return array of short answer questions.
|
[
"Choose",
"and",
"load",
"the",
"desired",
"number",
"of",
"questions",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/randomsamatch/question.php#L128-L139
|
218,379
|
moodle/moodle
|
lib/classes/shutdown_manager.php
|
core_shutdown_manager.initialize
|
public static function initialize() {
if (self::$registered) {
debugging('Shutdown manager is already initialised!');
}
self::$registered = true;
register_shutdown_function(array('core_shutdown_manager', 'shutdown_handler'));
// Signal handlers should only be used when dealing with a CLI script.
// In the case of PHP called in a web server the server is the owning process and should handle the signal chain
// properly itself.
// The 'pcntl' extension is optional and not available on Windows.
if (CLI_SCRIPT && extension_loaded('pcntl') && function_exists('pcntl_async_signals')) {
// We capture and handle SIGINT (Ctrl+C) and SIGTERM (termination requested).
pcntl_async_signals(true);
pcntl_signal(SIGINT, ['core_shutdown_manager', 'signal_handler']);
pcntl_signal(SIGTERM, ['core_shutdown_manager', 'signal_handler']);
}
}
|
php
|
public static function initialize() {
if (self::$registered) {
debugging('Shutdown manager is already initialised!');
}
self::$registered = true;
register_shutdown_function(array('core_shutdown_manager', 'shutdown_handler'));
// Signal handlers should only be used when dealing with a CLI script.
// In the case of PHP called in a web server the server is the owning process and should handle the signal chain
// properly itself.
// The 'pcntl' extension is optional and not available on Windows.
if (CLI_SCRIPT && extension_loaded('pcntl') && function_exists('pcntl_async_signals')) {
// We capture and handle SIGINT (Ctrl+C) and SIGTERM (termination requested).
pcntl_async_signals(true);
pcntl_signal(SIGINT, ['core_shutdown_manager', 'signal_handler']);
pcntl_signal(SIGTERM, ['core_shutdown_manager', 'signal_handler']);
}
}
|
[
"public",
"static",
"function",
"initialize",
"(",
")",
"{",
"if",
"(",
"self",
"::",
"$",
"registered",
")",
"{",
"debugging",
"(",
"'Shutdown manager is already initialised!'",
")",
";",
"}",
"self",
"::",
"$",
"registered",
"=",
"true",
";",
"register_shutdown_function",
"(",
"array",
"(",
"'core_shutdown_manager'",
",",
"'shutdown_handler'",
")",
")",
";",
"// Signal handlers should only be used when dealing with a CLI script.",
"// In the case of PHP called in a web server the server is the owning process and should handle the signal chain",
"// properly itself.",
"// The 'pcntl' extension is optional and not available on Windows.",
"if",
"(",
"CLI_SCRIPT",
"&&",
"extension_loaded",
"(",
"'pcntl'",
")",
"&&",
"function_exists",
"(",
"'pcntl_async_signals'",
")",
")",
"{",
"// We capture and handle SIGINT (Ctrl+C) and SIGTERM (termination requested).",
"pcntl_async_signals",
"(",
"true",
")",
";",
"pcntl_signal",
"(",
"SIGINT",
",",
"[",
"'core_shutdown_manager'",
",",
"'signal_handler'",
"]",
")",
";",
"pcntl_signal",
"(",
"SIGTERM",
",",
"[",
"'core_shutdown_manager'",
",",
"'signal_handler'",
"]",
")",
";",
"}",
"}"
] |
Register self as main shutdown handler.
@private to be called from lib/setup.php only!
|
[
"Register",
"self",
"as",
"main",
"shutdown",
"handler",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/shutdown_manager.php#L45-L62
|
218,380
|
moodle/moodle
|
lib/classes/shutdown_manager.php
|
core_shutdown_manager.signal_handler
|
public static function signal_handler($signo) {
// Note: There is no need to manually call the shutdown handler.
// The fact that we are calling exit() in this script means that the standard shutdown handling is performed
// anyway.
switch ($signo) {
case SIGTERM:
// Replicate native behaviour.
echo "Terminated: {$signo}\n";
// The standard exit code for SIGTERM is 143.
$exitcode = 143;
break;
case SIGINT:
// Replicate native behaviour.
echo "\n";
// The standard exit code for SIGINT (Ctrl+C) is 130.
$exitcode = 130;
break;
default:
// The signal handler was called with a signal it was not expecting.
// We should exit and complain.
echo "Warning: \core_shutdown_manager::signal_handler() was called with an unexpected signal ({$signo}).\n";
$exitcode = 1;
}
exit ($exitcode);
}
|
php
|
public static function signal_handler($signo) {
// Note: There is no need to manually call the shutdown handler.
// The fact that we are calling exit() in this script means that the standard shutdown handling is performed
// anyway.
switch ($signo) {
case SIGTERM:
// Replicate native behaviour.
echo "Terminated: {$signo}\n";
// The standard exit code for SIGTERM is 143.
$exitcode = 143;
break;
case SIGINT:
// Replicate native behaviour.
echo "\n";
// The standard exit code for SIGINT (Ctrl+C) is 130.
$exitcode = 130;
break;
default:
// The signal handler was called with a signal it was not expecting.
// We should exit and complain.
echo "Warning: \core_shutdown_manager::signal_handler() was called with an unexpected signal ({$signo}).\n";
$exitcode = 1;
}
exit ($exitcode);
}
|
[
"public",
"static",
"function",
"signal_handler",
"(",
"$",
"signo",
")",
"{",
"// Note: There is no need to manually call the shutdown handler.",
"// The fact that we are calling exit() in this script means that the standard shutdown handling is performed",
"// anyway.",
"switch",
"(",
"$",
"signo",
")",
"{",
"case",
"SIGTERM",
":",
"// Replicate native behaviour.",
"echo",
"\"Terminated: {$signo}\\n\"",
";",
"// The standard exit code for SIGTERM is 143.",
"$",
"exitcode",
"=",
"143",
";",
"break",
";",
"case",
"SIGINT",
":",
"// Replicate native behaviour.",
"echo",
"\"\\n\"",
";",
"// The standard exit code for SIGINT (Ctrl+C) is 130.",
"$",
"exitcode",
"=",
"130",
";",
"break",
";",
"default",
":",
"// The signal handler was called with a signal it was not expecting.",
"// We should exit and complain.",
"echo",
"\"Warning: \\core_shutdown_manager::signal_handler() was called with an unexpected signal ({$signo}).\\n\"",
";",
"$",
"exitcode",
"=",
"1",
";",
"}",
"exit",
"(",
"$",
"exitcode",
")",
";",
"}"
] |
Signal handler for SIGINT, and SIGTERM.
@param int $signo The signal being handled
|
[
"Signal",
"handler",
"for",
"SIGINT",
"and",
"SIGTERM",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/shutdown_manager.php#L69-L96
|
218,381
|
moodle/moodle
|
lib/classes/shutdown_manager.php
|
core_shutdown_manager.request_shutdown
|
protected static function request_shutdown() {
global $CFG;
// Help apache server if possible.
$apachereleasemem = false;
if (function_exists('apache_child_terminate') && function_exists('memory_get_usage') && ini_get_bool('child_terminate')) {
$limit = (empty($CFG->apachemaxmem) ? 64*1024*1024 : $CFG->apachemaxmem); // 64MB default.
if (memory_get_usage() > get_real_size($limit)) {
$apachereleasemem = $limit;
@apache_child_terminate();
}
}
// Deal with perf logging.
if (defined('MDL_PERF') || (!empty($CFG->perfdebug) and $CFG->perfdebug > 7)) {
if ($apachereleasemem) {
error_log('Mem usage over '.$apachereleasemem.': marking Apache child for reaping.');
}
if (defined('MDL_PERFTOLOG')) {
$perf = get_performance_info();
error_log("PERF: " . $perf['txt']);
}
if (defined('MDL_PERFINC')) {
$inc = get_included_files();
$ts = 0;
foreach ($inc as $f) {
if (preg_match(':^/:', $f)) {
$fs = filesize($f);
$ts += $fs;
$hfs = display_size($fs);
error_log(substr($f, strlen($CFG->dirroot)) . " size: $fs ($hfs)", null, null, 0);
} else {
error_log($f , null, null, 0);
}
}
if ($ts > 0 ) {
$hts = display_size($ts);
error_log("Total size of files included: $ts ($hts)");
}
}
}
}
|
php
|
protected static function request_shutdown() {
global $CFG;
// Help apache server if possible.
$apachereleasemem = false;
if (function_exists('apache_child_terminate') && function_exists('memory_get_usage') && ini_get_bool('child_terminate')) {
$limit = (empty($CFG->apachemaxmem) ? 64*1024*1024 : $CFG->apachemaxmem); // 64MB default.
if (memory_get_usage() > get_real_size($limit)) {
$apachereleasemem = $limit;
@apache_child_terminate();
}
}
// Deal with perf logging.
if (defined('MDL_PERF') || (!empty($CFG->perfdebug) and $CFG->perfdebug > 7)) {
if ($apachereleasemem) {
error_log('Mem usage over '.$apachereleasemem.': marking Apache child for reaping.');
}
if (defined('MDL_PERFTOLOG')) {
$perf = get_performance_info();
error_log("PERF: " . $perf['txt']);
}
if (defined('MDL_PERFINC')) {
$inc = get_included_files();
$ts = 0;
foreach ($inc as $f) {
if (preg_match(':^/:', $f)) {
$fs = filesize($f);
$ts += $fs;
$hfs = display_size($fs);
error_log(substr($f, strlen($CFG->dirroot)) . " size: $fs ($hfs)", null, null, 0);
} else {
error_log($f , null, null, 0);
}
}
if ($ts > 0 ) {
$hts = display_size($ts);
error_log("Total size of files included: $ts ($hts)");
}
}
}
}
|
[
"protected",
"static",
"function",
"request_shutdown",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"// Help apache server if possible.",
"$",
"apachereleasemem",
"=",
"false",
";",
"if",
"(",
"function_exists",
"(",
"'apache_child_terminate'",
")",
"&&",
"function_exists",
"(",
"'memory_get_usage'",
")",
"&&",
"ini_get_bool",
"(",
"'child_terminate'",
")",
")",
"{",
"$",
"limit",
"=",
"(",
"empty",
"(",
"$",
"CFG",
"->",
"apachemaxmem",
")",
"?",
"64",
"*",
"1024",
"*",
"1024",
":",
"$",
"CFG",
"->",
"apachemaxmem",
")",
";",
"// 64MB default.",
"if",
"(",
"memory_get_usage",
"(",
")",
">",
"get_real_size",
"(",
"$",
"limit",
")",
")",
"{",
"$",
"apachereleasemem",
"=",
"$",
"limit",
";",
"@",
"apache_child_terminate",
"(",
")",
";",
"}",
"}",
"// Deal with perf logging.",
"if",
"(",
"defined",
"(",
"'MDL_PERF'",
")",
"||",
"(",
"!",
"empty",
"(",
"$",
"CFG",
"->",
"perfdebug",
")",
"and",
"$",
"CFG",
"->",
"perfdebug",
">",
"7",
")",
")",
"{",
"if",
"(",
"$",
"apachereleasemem",
")",
"{",
"error_log",
"(",
"'Mem usage over '",
".",
"$",
"apachereleasemem",
".",
"': marking Apache child for reaping.'",
")",
";",
"}",
"if",
"(",
"defined",
"(",
"'MDL_PERFTOLOG'",
")",
")",
"{",
"$",
"perf",
"=",
"get_performance_info",
"(",
")",
";",
"error_log",
"(",
"\"PERF: \"",
".",
"$",
"perf",
"[",
"'txt'",
"]",
")",
";",
"}",
"if",
"(",
"defined",
"(",
"'MDL_PERFINC'",
")",
")",
"{",
"$",
"inc",
"=",
"get_included_files",
"(",
")",
";",
"$",
"ts",
"=",
"0",
";",
"foreach",
"(",
"$",
"inc",
"as",
"$",
"f",
")",
"{",
"if",
"(",
"preg_match",
"(",
"':^/:'",
",",
"$",
"f",
")",
")",
"{",
"$",
"fs",
"=",
"filesize",
"(",
"$",
"f",
")",
";",
"$",
"ts",
"+=",
"$",
"fs",
";",
"$",
"hfs",
"=",
"display_size",
"(",
"$",
"fs",
")",
";",
"error_log",
"(",
"substr",
"(",
"$",
"f",
",",
"strlen",
"(",
"$",
"CFG",
"->",
"dirroot",
")",
")",
".",
"\" size: $fs ($hfs)\"",
",",
"null",
",",
"null",
",",
"0",
")",
";",
"}",
"else",
"{",
"error_log",
"(",
"$",
"f",
",",
"null",
",",
"null",
",",
"0",
")",
";",
"}",
"}",
"if",
"(",
"$",
"ts",
">",
"0",
")",
"{",
"$",
"hts",
"=",
"display_size",
"(",
"$",
"ts",
")",
";",
"error_log",
"(",
"\"Total size of files included: $ts ($hts)\"",
")",
";",
"}",
"}",
"}",
"}"
] |
Standard shutdown sequence.
|
[
"Standard",
"shutdown",
"sequence",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/shutdown_manager.php#L166-L207
|
218,382
|
moodle/moodle
|
lib/form/defaultcustom.php
|
MoodleQuickForm_defaultcustom._createElements
|
public function _createElements() {
if (!$this->has_customize_switch()) {
$element = $this->createFormElement('hidden', 'customize', 1);
} else {
$element = $this->createFormElement('advcheckbox', 'customize', '', $this->_options['customlabel']);
}
$this->_elements[] = $element;
if ($this->_options['type'] === 'text') {
$element = $this->createFormElement($this->_options['type'], 'value',
get_string('newvaluefor', 'form', $this->getLabel()), $this->getAttributes());
$element->setHiddenLabel(true);
} else if ($this->_options['type'] === 'date_selector') {
$element = $this->createFormElement($this->_options['type'], 'value', '', $this->_options,
$this->getAttributes());
} else if ($this->_options['type'] === 'date_time_selector') {
$element = $this->createFormElement($this->_options['type'], 'value', '', $this->_options,
$this->getAttributes());
}
$this->_elements[] = $element;
}
|
php
|
public function _createElements() {
if (!$this->has_customize_switch()) {
$element = $this->createFormElement('hidden', 'customize', 1);
} else {
$element = $this->createFormElement('advcheckbox', 'customize', '', $this->_options['customlabel']);
}
$this->_elements[] = $element;
if ($this->_options['type'] === 'text') {
$element = $this->createFormElement($this->_options['type'], 'value',
get_string('newvaluefor', 'form', $this->getLabel()), $this->getAttributes());
$element->setHiddenLabel(true);
} else if ($this->_options['type'] === 'date_selector') {
$element = $this->createFormElement($this->_options['type'], 'value', '', $this->_options,
$this->getAttributes());
} else if ($this->_options['type'] === 'date_time_selector') {
$element = $this->createFormElement($this->_options['type'], 'value', '', $this->_options,
$this->getAttributes());
}
$this->_elements[] = $element;
}
|
[
"public",
"function",
"_createElements",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"has_customize_switch",
"(",
")",
")",
"{",
"$",
"element",
"=",
"$",
"this",
"->",
"createFormElement",
"(",
"'hidden'",
",",
"'customize'",
",",
"1",
")",
";",
"}",
"else",
"{",
"$",
"element",
"=",
"$",
"this",
"->",
"createFormElement",
"(",
"'advcheckbox'",
",",
"'customize'",
",",
"''",
",",
"$",
"this",
"->",
"_options",
"[",
"'customlabel'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"_elements",
"[",
"]",
"=",
"$",
"element",
";",
"if",
"(",
"$",
"this",
"->",
"_options",
"[",
"'type'",
"]",
"===",
"'text'",
")",
"{",
"$",
"element",
"=",
"$",
"this",
"->",
"createFormElement",
"(",
"$",
"this",
"->",
"_options",
"[",
"'type'",
"]",
",",
"'value'",
",",
"get_string",
"(",
"'newvaluefor'",
",",
"'form'",
",",
"$",
"this",
"->",
"getLabel",
"(",
")",
")",
",",
"$",
"this",
"->",
"getAttributes",
"(",
")",
")",
";",
"$",
"element",
"->",
"setHiddenLabel",
"(",
"true",
")",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"_options",
"[",
"'type'",
"]",
"===",
"'date_selector'",
")",
"{",
"$",
"element",
"=",
"$",
"this",
"->",
"createFormElement",
"(",
"$",
"this",
"->",
"_options",
"[",
"'type'",
"]",
",",
"'value'",
",",
"''",
",",
"$",
"this",
"->",
"_options",
",",
"$",
"this",
"->",
"getAttributes",
"(",
")",
")",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"_options",
"[",
"'type'",
"]",
"===",
"'date_time_selector'",
")",
"{",
"$",
"element",
"=",
"$",
"this",
"->",
"createFormElement",
"(",
"$",
"this",
"->",
"_options",
"[",
"'type'",
"]",
",",
"'value'",
",",
"''",
",",
"$",
"this",
"->",
"_options",
",",
"$",
"this",
"->",
"getAttributes",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"_elements",
"[",
"]",
"=",
"$",
"element",
";",
"}"
] |
This will create all elements in the group
|
[
"This",
"will",
"create",
"all",
"elements",
"in",
"the",
"group"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/defaultcustom.php#L127-L147
|
218,383
|
moodle/moodle
|
lib/form/defaultcustom.php
|
MoodleQuickForm_defaultcustom.exportValue
|
public function exportValue(&$submitvalues, $assoc = false) {
$valuearray = array();
foreach ($this->_elements as $element) {
$thisexport = $element->exportValue($submitvalues[$this->getName()], true);
if ($thisexport != null) {
$valuearray += $thisexport;
}
}
if (empty($valuearray['customize'])) {
return $this->_prepareValue(false, $assoc);
}
return array_key_exists('value', $valuearray) ? $this->_prepareValue($valuearray['value'], $assoc) : [];
}
|
php
|
public function exportValue(&$submitvalues, $assoc = false) {
$valuearray = array();
foreach ($this->_elements as $element) {
$thisexport = $element->exportValue($submitvalues[$this->getName()], true);
if ($thisexport != null) {
$valuearray += $thisexport;
}
}
if (empty($valuearray['customize'])) {
return $this->_prepareValue(false, $assoc);
}
return array_key_exists('value', $valuearray) ? $this->_prepareValue($valuearray['value'], $assoc) : [];
}
|
[
"public",
"function",
"exportValue",
"(",
"&",
"$",
"submitvalues",
",",
"$",
"assoc",
"=",
"false",
")",
"{",
"$",
"valuearray",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"_elements",
"as",
"$",
"element",
")",
"{",
"$",
"thisexport",
"=",
"$",
"element",
"->",
"exportValue",
"(",
"$",
"submitvalues",
"[",
"$",
"this",
"->",
"getName",
"(",
")",
"]",
",",
"true",
")",
";",
"if",
"(",
"$",
"thisexport",
"!=",
"null",
")",
"{",
"$",
"valuearray",
"+=",
"$",
"thisexport",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"valuearray",
"[",
"'customize'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_prepareValue",
"(",
"false",
",",
"$",
"assoc",
")",
";",
"}",
"return",
"array_key_exists",
"(",
"'value'",
",",
"$",
"valuearray",
")",
"?",
"$",
"this",
"->",
"_prepareValue",
"(",
"$",
"valuearray",
"[",
"'value'",
"]",
",",
"$",
"assoc",
")",
":",
"[",
"]",
";",
"}"
] |
Output a value. Give it the name of the group. In case of "default" return false.
@param array $submitvalues values submitted.
@param bool $assoc specifies if returned array is associative
@return array
|
[
"Output",
"a",
"value",
".",
"Give",
"it",
"the",
"name",
"of",
"the",
"group",
".",
"In",
"case",
"of",
"default",
"return",
"false",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/defaultcustom.php#L266-L278
|
218,384
|
moodle/moodle
|
mod/assign/feedback/file/locallib.php
|
assign_feedback_file.is_feedback_modified
|
public function is_feedback_modified(stdClass $grade, stdClass $data) {
global $USER;
$filekey = null;
$draftareainfo = null;
foreach ($data as $key => $value) {
if (strpos($key, 'files_') === 0 && strpos($key, '_filemanager')) {
$filekey = $key;
}
}
if (isset($filekey)) {
$draftareainfo = file_get_draft_area_info($data->$filekey);
$filecount = $this->count_files($grade->id, ASSIGNFEEDBACK_FILE_FILEAREA);
if ($filecount != $draftareainfo['filecount']) {
return true;
} else {
// We need to check that the files in the draft area are the same as in the file area.
$usercontext = context_user::instance($USER->id);
$fs = get_file_storage();
$draftfiles = $fs->get_area_files($usercontext->id, 'user', 'draft', $data->$filekey, 'id', true);
$files = $fs->get_area_files($this->assignment->get_context()->id,
'assignfeedback_file',
ASSIGNFEEDBACK_FILE_FILEAREA,
$grade->id,
'id',
false);
foreach ($files as $key => $file) {
// Flag for recording if we have a matching file.
$matchflag = false;
foreach ($draftfiles as $draftkey => $draftfile) {
if (!$file->is_directory()) {
// File name is the same, but it could be a different file with the same name.
if ($draftfile->get_filename() == $file->get_filename()) {
// If the file name is the same but the content hash is different, or
// The file path for the file has changed, then we have a modification.
if ($draftfile->get_contenthash() != $file->get_contenthash() ||
$draftfile->get_filepath() != $file->get_filepath()) {
return true;
}
// These files match. Check the next file.
$matchflag = true;
// We have a match on the file name so we can move to the next file and not
// proceed through the other draftfiles.
break;
}
}
}
// If the file does not match then there has been a modification.
if (!$matchflag) {
return true;
}
}
}
}
return false;
}
|
php
|
public function is_feedback_modified(stdClass $grade, stdClass $data) {
global $USER;
$filekey = null;
$draftareainfo = null;
foreach ($data as $key => $value) {
if (strpos($key, 'files_') === 0 && strpos($key, '_filemanager')) {
$filekey = $key;
}
}
if (isset($filekey)) {
$draftareainfo = file_get_draft_area_info($data->$filekey);
$filecount = $this->count_files($grade->id, ASSIGNFEEDBACK_FILE_FILEAREA);
if ($filecount != $draftareainfo['filecount']) {
return true;
} else {
// We need to check that the files in the draft area are the same as in the file area.
$usercontext = context_user::instance($USER->id);
$fs = get_file_storage();
$draftfiles = $fs->get_area_files($usercontext->id, 'user', 'draft', $data->$filekey, 'id', true);
$files = $fs->get_area_files($this->assignment->get_context()->id,
'assignfeedback_file',
ASSIGNFEEDBACK_FILE_FILEAREA,
$grade->id,
'id',
false);
foreach ($files as $key => $file) {
// Flag for recording if we have a matching file.
$matchflag = false;
foreach ($draftfiles as $draftkey => $draftfile) {
if (!$file->is_directory()) {
// File name is the same, but it could be a different file with the same name.
if ($draftfile->get_filename() == $file->get_filename()) {
// If the file name is the same but the content hash is different, or
// The file path for the file has changed, then we have a modification.
if ($draftfile->get_contenthash() != $file->get_contenthash() ||
$draftfile->get_filepath() != $file->get_filepath()) {
return true;
}
// These files match. Check the next file.
$matchflag = true;
// We have a match on the file name so we can move to the next file and not
// proceed through the other draftfiles.
break;
}
}
}
// If the file does not match then there has been a modification.
if (!$matchflag) {
return true;
}
}
}
}
return false;
}
|
[
"public",
"function",
"is_feedback_modified",
"(",
"stdClass",
"$",
"grade",
",",
"stdClass",
"$",
"data",
")",
"{",
"global",
"$",
"USER",
";",
"$",
"filekey",
"=",
"null",
";",
"$",
"draftareainfo",
"=",
"null",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"key",
",",
"'files_'",
")",
"===",
"0",
"&&",
"strpos",
"(",
"$",
"key",
",",
"'_filemanager'",
")",
")",
"{",
"$",
"filekey",
"=",
"$",
"key",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"filekey",
")",
")",
"{",
"$",
"draftareainfo",
"=",
"file_get_draft_area_info",
"(",
"$",
"data",
"->",
"$",
"filekey",
")",
";",
"$",
"filecount",
"=",
"$",
"this",
"->",
"count_files",
"(",
"$",
"grade",
"->",
"id",
",",
"ASSIGNFEEDBACK_FILE_FILEAREA",
")",
";",
"if",
"(",
"$",
"filecount",
"!=",
"$",
"draftareainfo",
"[",
"'filecount'",
"]",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"// We need to check that the files in the draft area are the same as in the file area.",
"$",
"usercontext",
"=",
"context_user",
"::",
"instance",
"(",
"$",
"USER",
"->",
"id",
")",
";",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"$",
"draftfiles",
"=",
"$",
"fs",
"->",
"get_area_files",
"(",
"$",
"usercontext",
"->",
"id",
",",
"'user'",
",",
"'draft'",
",",
"$",
"data",
"->",
"$",
"filekey",
",",
"'id'",
",",
"true",
")",
";",
"$",
"files",
"=",
"$",
"fs",
"->",
"get_area_files",
"(",
"$",
"this",
"->",
"assignment",
"->",
"get_context",
"(",
")",
"->",
"id",
",",
"'assignfeedback_file'",
",",
"ASSIGNFEEDBACK_FILE_FILEAREA",
",",
"$",
"grade",
"->",
"id",
",",
"'id'",
",",
"false",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"key",
"=>",
"$",
"file",
")",
"{",
"// Flag for recording if we have a matching file.",
"$",
"matchflag",
"=",
"false",
";",
"foreach",
"(",
"$",
"draftfiles",
"as",
"$",
"draftkey",
"=>",
"$",
"draftfile",
")",
"{",
"if",
"(",
"!",
"$",
"file",
"->",
"is_directory",
"(",
")",
")",
"{",
"// File name is the same, but it could be a different file with the same name.",
"if",
"(",
"$",
"draftfile",
"->",
"get_filename",
"(",
")",
"==",
"$",
"file",
"->",
"get_filename",
"(",
")",
")",
"{",
"// If the file name is the same but the content hash is different, or",
"// The file path for the file has changed, then we have a modification.",
"if",
"(",
"$",
"draftfile",
"->",
"get_contenthash",
"(",
")",
"!=",
"$",
"file",
"->",
"get_contenthash",
"(",
")",
"||",
"$",
"draftfile",
"->",
"get_filepath",
"(",
")",
"!=",
"$",
"file",
"->",
"get_filepath",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"// These files match. Check the next file.",
"$",
"matchflag",
"=",
"true",
";",
"// We have a match on the file name so we can move to the next file and not",
"// proceed through the other draftfiles.",
"break",
";",
"}",
"}",
"}",
"// If the file does not match then there has been a modification.",
"if",
"(",
"!",
"$",
"matchflag",
")",
"{",
"return",
"true",
";",
"}",
"}",
"}",
"}",
"return",
"false",
";",
"}"
] |
Has the feedback file been modified?
@param stdClass $grade Grade object.
@param stdClass $data Form data.
@return boolean True if the file area has been modified, else false.
|
[
"Has",
"the",
"feedback",
"file",
"been",
"modified?"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/file/locallib.php#L87-L142
|
218,385
|
moodle/moodle
|
mod/assign/feedback/file/locallib.php
|
assign_feedback_file.copy_area_files
|
private function copy_area_files(file_storage $fs,
$fromcontextid,
$fromcomponent,
$fromfilearea,
$fromitemid,
$tocontextid,
$tocomponent,
$tofilearea,
$toitemid) {
$newfilerecord = new stdClass();
$newfilerecord->contextid = $tocontextid;
$newfilerecord->component = $tocomponent;
$newfilerecord->filearea = $tofilearea;
$newfilerecord->itemid = $toitemid;
if ($files = $fs->get_area_files($fromcontextid, $fromcomponent, $fromfilearea, $fromitemid)) {
foreach ($files as $file) {
if ($file->is_directory() and $file->get_filepath() === '/') {
// We need a way to mark the age of each draft area.
// By not copying the root dir we force it to be created
// automatically with current timestamp.
continue;
}
$existingfile = $fs->get_file(
$newfilerecord->contextid,
$newfilerecord->component,
$newfilerecord->filearea,
$newfilerecord->itemid,
$file->get_filepath(),
$file->get_filename()
);
if ($existingfile) {
// If the file already exists, remove it so it can be updated.
$existingfile->delete();
}
$newfile = $fs->create_file_from_storedfile($newfilerecord, $file);
}
}
return true;
}
|
php
|
private function copy_area_files(file_storage $fs,
$fromcontextid,
$fromcomponent,
$fromfilearea,
$fromitemid,
$tocontextid,
$tocomponent,
$tofilearea,
$toitemid) {
$newfilerecord = new stdClass();
$newfilerecord->contextid = $tocontextid;
$newfilerecord->component = $tocomponent;
$newfilerecord->filearea = $tofilearea;
$newfilerecord->itemid = $toitemid;
if ($files = $fs->get_area_files($fromcontextid, $fromcomponent, $fromfilearea, $fromitemid)) {
foreach ($files as $file) {
if ($file->is_directory() and $file->get_filepath() === '/') {
// We need a way to mark the age of each draft area.
// By not copying the root dir we force it to be created
// automatically with current timestamp.
continue;
}
$existingfile = $fs->get_file(
$newfilerecord->contextid,
$newfilerecord->component,
$newfilerecord->filearea,
$newfilerecord->itemid,
$file->get_filepath(),
$file->get_filename()
);
if ($existingfile) {
// If the file already exists, remove it so it can be updated.
$existingfile->delete();
}
$newfile = $fs->create_file_from_storedfile($newfilerecord, $file);
}
}
return true;
}
|
[
"private",
"function",
"copy_area_files",
"(",
"file_storage",
"$",
"fs",
",",
"$",
"fromcontextid",
",",
"$",
"fromcomponent",
",",
"$",
"fromfilearea",
",",
"$",
"fromitemid",
",",
"$",
"tocontextid",
",",
"$",
"tocomponent",
",",
"$",
"tofilearea",
",",
"$",
"toitemid",
")",
"{",
"$",
"newfilerecord",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"newfilerecord",
"->",
"contextid",
"=",
"$",
"tocontextid",
";",
"$",
"newfilerecord",
"->",
"component",
"=",
"$",
"tocomponent",
";",
"$",
"newfilerecord",
"->",
"filearea",
"=",
"$",
"tofilearea",
";",
"$",
"newfilerecord",
"->",
"itemid",
"=",
"$",
"toitemid",
";",
"if",
"(",
"$",
"files",
"=",
"$",
"fs",
"->",
"get_area_files",
"(",
"$",
"fromcontextid",
",",
"$",
"fromcomponent",
",",
"$",
"fromfilearea",
",",
"$",
"fromitemid",
")",
")",
"{",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"file",
"->",
"is_directory",
"(",
")",
"and",
"$",
"file",
"->",
"get_filepath",
"(",
")",
"===",
"'/'",
")",
"{",
"// We need a way to mark the age of each draft area.",
"// By not copying the root dir we force it to be created",
"// automatically with current timestamp.",
"continue",
";",
"}",
"$",
"existingfile",
"=",
"$",
"fs",
"->",
"get_file",
"(",
"$",
"newfilerecord",
"->",
"contextid",
",",
"$",
"newfilerecord",
"->",
"component",
",",
"$",
"newfilerecord",
"->",
"filearea",
",",
"$",
"newfilerecord",
"->",
"itemid",
",",
"$",
"file",
"->",
"get_filepath",
"(",
")",
",",
"$",
"file",
"->",
"get_filename",
"(",
")",
")",
";",
"if",
"(",
"$",
"existingfile",
")",
"{",
"// If the file already exists, remove it so it can be updated.",
"$",
"existingfile",
"->",
"delete",
"(",
")",
";",
"}",
"$",
"newfile",
"=",
"$",
"fs",
"->",
"create_file_from_storedfile",
"(",
"$",
"newfilerecord",
",",
"$",
"file",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Copy all the files from one file area to another.
@param file_storage $fs - The source context id
@param int $fromcontextid - The source context id
@param string $fromcomponent - The source component
@param string $fromfilearea - The source filearea
@param int $fromitemid - The source item id
@param int $tocontextid - The destination context id
@param string $tocomponent - The destination component
@param string $tofilearea - The destination filearea
@param int $toitemid - The destination item id
@return boolean
|
[
"Copy",
"all",
"the",
"files",
"from",
"one",
"file",
"area",
"to",
"another",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/file/locallib.php#L158-L200
|
218,386
|
moodle/moodle
|
mod/assign/feedback/file/locallib.php
|
assign_feedback_file.get_form_elements_for_user
|
public function get_form_elements_for_user($grade, MoodleQuickForm $mform, stdClass $data, $userid) {
$fileoptions = $this->get_file_options();
$gradeid = $grade ? $grade->id : 0;
$elementname = 'files_' . $userid;
$data = file_prepare_standard_filemanager($data,
$elementname,
$fileoptions,
$this->assignment->get_context(),
'assignfeedback_file',
ASSIGNFEEDBACK_FILE_FILEAREA,
$gradeid);
$mform->addElement('filemanager', $elementname . '_filemanager', $this->get_name(), null, $fileoptions);
return true;
}
|
php
|
public function get_form_elements_for_user($grade, MoodleQuickForm $mform, stdClass $data, $userid) {
$fileoptions = $this->get_file_options();
$gradeid = $grade ? $grade->id : 0;
$elementname = 'files_' . $userid;
$data = file_prepare_standard_filemanager($data,
$elementname,
$fileoptions,
$this->assignment->get_context(),
'assignfeedback_file',
ASSIGNFEEDBACK_FILE_FILEAREA,
$gradeid);
$mform->addElement('filemanager', $elementname . '_filemanager', $this->get_name(), null, $fileoptions);
return true;
}
|
[
"public",
"function",
"get_form_elements_for_user",
"(",
"$",
"grade",
",",
"MoodleQuickForm",
"$",
"mform",
",",
"stdClass",
"$",
"data",
",",
"$",
"userid",
")",
"{",
"$",
"fileoptions",
"=",
"$",
"this",
"->",
"get_file_options",
"(",
")",
";",
"$",
"gradeid",
"=",
"$",
"grade",
"?",
"$",
"grade",
"->",
"id",
":",
"0",
";",
"$",
"elementname",
"=",
"'files_'",
".",
"$",
"userid",
";",
"$",
"data",
"=",
"file_prepare_standard_filemanager",
"(",
"$",
"data",
",",
"$",
"elementname",
",",
"$",
"fileoptions",
",",
"$",
"this",
"->",
"assignment",
"->",
"get_context",
"(",
")",
",",
"'assignfeedback_file'",
",",
"ASSIGNFEEDBACK_FILE_FILEAREA",
",",
"$",
"gradeid",
")",
";",
"$",
"mform",
"->",
"addElement",
"(",
"'filemanager'",
",",
"$",
"elementname",
".",
"'_filemanager'",
",",
"$",
"this",
"->",
"get_name",
"(",
")",
",",
"null",
",",
"$",
"fileoptions",
")",
";",
"return",
"true",
";",
"}"
] |
Get form elements for grading form.
@param stdClass $grade
@param MoodleQuickForm $mform
@param stdClass $data
@param int $userid The userid we are currently grading
@return bool true if elements were added to the form
|
[
"Get",
"form",
"elements",
"for",
"grading",
"form",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/file/locallib.php#L211-L227
|
218,387
|
moodle/moodle
|
mod/assign/feedback/file/locallib.php
|
assign_feedback_file.update_file_count
|
public function update_file_count($grade) {
global $DB;
$filefeedback = $this->get_file_feedback($grade->id);
if ($filefeedback) {
$filefeedback->numfiles = $this->count_files($grade->id, ASSIGNFEEDBACK_FILE_FILEAREA);
return $DB->update_record('assignfeedback_file', $filefeedback);
} else {
$filefeedback = new stdClass();
$filefeedback->numfiles = $this->count_files($grade->id, ASSIGNFEEDBACK_FILE_FILEAREA);
$filefeedback->grade = $grade->id;
$filefeedback->assignment = $this->assignment->get_instance()->id;
return $DB->insert_record('assignfeedback_file', $filefeedback) > 0;
}
}
|
php
|
public function update_file_count($grade) {
global $DB;
$filefeedback = $this->get_file_feedback($grade->id);
if ($filefeedback) {
$filefeedback->numfiles = $this->count_files($grade->id, ASSIGNFEEDBACK_FILE_FILEAREA);
return $DB->update_record('assignfeedback_file', $filefeedback);
} else {
$filefeedback = new stdClass();
$filefeedback->numfiles = $this->count_files($grade->id, ASSIGNFEEDBACK_FILE_FILEAREA);
$filefeedback->grade = $grade->id;
$filefeedback->assignment = $this->assignment->get_instance()->id;
return $DB->insert_record('assignfeedback_file', $filefeedback) > 0;
}
}
|
[
"public",
"function",
"update_file_count",
"(",
"$",
"grade",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"filefeedback",
"=",
"$",
"this",
"->",
"get_file_feedback",
"(",
"$",
"grade",
"->",
"id",
")",
";",
"if",
"(",
"$",
"filefeedback",
")",
"{",
"$",
"filefeedback",
"->",
"numfiles",
"=",
"$",
"this",
"->",
"count_files",
"(",
"$",
"grade",
"->",
"id",
",",
"ASSIGNFEEDBACK_FILE_FILEAREA",
")",
";",
"return",
"$",
"DB",
"->",
"update_record",
"(",
"'assignfeedback_file'",
",",
"$",
"filefeedback",
")",
";",
"}",
"else",
"{",
"$",
"filefeedback",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"filefeedback",
"->",
"numfiles",
"=",
"$",
"this",
"->",
"count_files",
"(",
"$",
"grade",
"->",
"id",
",",
"ASSIGNFEEDBACK_FILE_FILEAREA",
")",
";",
"$",
"filefeedback",
"->",
"grade",
"=",
"$",
"grade",
"->",
"id",
";",
"$",
"filefeedback",
"->",
"assignment",
"=",
"$",
"this",
"->",
"assignment",
"->",
"get_instance",
"(",
")",
"->",
"id",
";",
"return",
"$",
"DB",
"->",
"insert_record",
"(",
"'assignfeedback_file'",
",",
"$",
"filefeedback",
")",
">",
"0",
";",
"}",
"}"
] |
Update the number of files in the file area.
@param stdClass $grade The grade record
@return bool - true if the value was saved
|
[
"Update",
"the",
"number",
"of",
"files",
"in",
"the",
"file",
"area",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/file/locallib.php#L255-L269
|
218,388
|
moodle/moodle
|
mod/assign/feedback/file/locallib.php
|
assign_feedback_file.save
|
public function save(stdClass $grade, stdClass $data) {
$fileoptions = $this->get_file_options();
// The element name may have been for a different user.
foreach ($data as $key => $value) {
if (strpos($key, 'files_') === 0 && strpos($key, '_filemanager')) {
$elementname = substr($key, 0, strpos($key, '_filemanager'));
}
}
$data = file_postupdate_standard_filemanager($data,
$elementname,
$fileoptions,
$this->assignment->get_context(),
'assignfeedback_file',
ASSIGNFEEDBACK_FILE_FILEAREA,
$grade->id);
return $this->update_file_count($grade);
}
|
php
|
public function save(stdClass $grade, stdClass $data) {
$fileoptions = $this->get_file_options();
// The element name may have been for a different user.
foreach ($data as $key => $value) {
if (strpos($key, 'files_') === 0 && strpos($key, '_filemanager')) {
$elementname = substr($key, 0, strpos($key, '_filemanager'));
}
}
$data = file_postupdate_standard_filemanager($data,
$elementname,
$fileoptions,
$this->assignment->get_context(),
'assignfeedback_file',
ASSIGNFEEDBACK_FILE_FILEAREA,
$grade->id);
return $this->update_file_count($grade);
}
|
[
"public",
"function",
"save",
"(",
"stdClass",
"$",
"grade",
",",
"stdClass",
"$",
"data",
")",
"{",
"$",
"fileoptions",
"=",
"$",
"this",
"->",
"get_file_options",
"(",
")",
";",
"// The element name may have been for a different user.",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"key",
",",
"'files_'",
")",
"===",
"0",
"&&",
"strpos",
"(",
"$",
"key",
",",
"'_filemanager'",
")",
")",
"{",
"$",
"elementname",
"=",
"substr",
"(",
"$",
"key",
",",
"0",
",",
"strpos",
"(",
"$",
"key",
",",
"'_filemanager'",
")",
")",
";",
"}",
"}",
"$",
"data",
"=",
"file_postupdate_standard_filemanager",
"(",
"$",
"data",
",",
"$",
"elementname",
",",
"$",
"fileoptions",
",",
"$",
"this",
"->",
"assignment",
"->",
"get_context",
"(",
")",
",",
"'assignfeedback_file'",
",",
"ASSIGNFEEDBACK_FILE_FILEAREA",
",",
"$",
"grade",
"->",
"id",
")",
";",
"return",
"$",
"this",
"->",
"update_file_count",
"(",
"$",
"grade",
")",
";",
"}"
] |
Save the feedback files.
@param stdClass $grade
@param stdClass $data
@return bool
|
[
"Save",
"the",
"feedback",
"files",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/file/locallib.php#L278-L297
|
218,389
|
moodle/moodle
|
mod/assign/feedback/file/locallib.php
|
assign_feedback_file.upgrade
|
public function upgrade(context $oldcontext,
stdClass $oldassignment,
stdClass $oldsubmission,
stdClass $grade,
& $log) {
global $DB;
// Now copy the area files.
$this->assignment->copy_area_files_for_upgrade($oldcontext->id,
'mod_assignment',
'response',
$oldsubmission->id,
$this->assignment->get_context()->id,
'assignfeedback_file',
ASSIGNFEEDBACK_FILE_FILEAREA,
$grade->id);
// Now count them!
$filefeedback = new stdClass();
$filefeedback->numfiles = $this->count_files($grade->id, ASSIGNFEEDBACK_FILE_FILEAREA);
$filefeedback->grade = $grade->id;
$filefeedback->assignment = $this->assignment->get_instance()->id;
if (!$DB->insert_record('assignfeedback_file', $filefeedback) > 0) {
$log .= get_string('couldnotconvertgrade', 'mod_assign', $grade->userid);
return false;
}
return true;
}
|
php
|
public function upgrade(context $oldcontext,
stdClass $oldassignment,
stdClass $oldsubmission,
stdClass $grade,
& $log) {
global $DB;
// Now copy the area files.
$this->assignment->copy_area_files_for_upgrade($oldcontext->id,
'mod_assignment',
'response',
$oldsubmission->id,
$this->assignment->get_context()->id,
'assignfeedback_file',
ASSIGNFEEDBACK_FILE_FILEAREA,
$grade->id);
// Now count them!
$filefeedback = new stdClass();
$filefeedback->numfiles = $this->count_files($grade->id, ASSIGNFEEDBACK_FILE_FILEAREA);
$filefeedback->grade = $grade->id;
$filefeedback->assignment = $this->assignment->get_instance()->id;
if (!$DB->insert_record('assignfeedback_file', $filefeedback) > 0) {
$log .= get_string('couldnotconvertgrade', 'mod_assign', $grade->userid);
return false;
}
return true;
}
|
[
"public",
"function",
"upgrade",
"(",
"context",
"$",
"oldcontext",
",",
"stdClass",
"$",
"oldassignment",
",",
"stdClass",
"$",
"oldsubmission",
",",
"stdClass",
"$",
"grade",
",",
"&",
"$",
"log",
")",
"{",
"global",
"$",
"DB",
";",
"// Now copy the area files.",
"$",
"this",
"->",
"assignment",
"->",
"copy_area_files_for_upgrade",
"(",
"$",
"oldcontext",
"->",
"id",
",",
"'mod_assignment'",
",",
"'response'",
",",
"$",
"oldsubmission",
"->",
"id",
",",
"$",
"this",
"->",
"assignment",
"->",
"get_context",
"(",
")",
"->",
"id",
",",
"'assignfeedback_file'",
",",
"ASSIGNFEEDBACK_FILE_FILEAREA",
",",
"$",
"grade",
"->",
"id",
")",
";",
"// Now count them!",
"$",
"filefeedback",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"filefeedback",
"->",
"numfiles",
"=",
"$",
"this",
"->",
"count_files",
"(",
"$",
"grade",
"->",
"id",
",",
"ASSIGNFEEDBACK_FILE_FILEAREA",
")",
";",
"$",
"filefeedback",
"->",
"grade",
"=",
"$",
"grade",
"->",
"id",
";",
"$",
"filefeedback",
"->",
"assignment",
"=",
"$",
"this",
"->",
"assignment",
"->",
"get_instance",
"(",
")",
"->",
"id",
";",
"if",
"(",
"!",
"$",
"DB",
"->",
"insert_record",
"(",
"'assignfeedback_file'",
",",
"$",
"filefeedback",
")",
">",
"0",
")",
"{",
"$",
"log",
".=",
"get_string",
"(",
"'couldnotconvertgrade'",
",",
"'mod_assign'",
",",
"$",
"grade",
"->",
"userid",
")",
";",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Upgrade the feedback from the old assignment to the new one.
@param context $oldcontext - the database for the old assignment context
@param stdClass $oldassignment The data record for the old assignment
@param stdClass $oldsubmission The data record for the old submission
@param stdClass $grade The data record for the new grade
@param string $log Record upgrade messages in the log
@return bool true or false - false will trigger a rollback
|
[
"Upgrade",
"the",
"feedback",
"from",
"the",
"old",
"assignment",
"to",
"the",
"new",
"one",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/file/locallib.php#L404-L431
|
218,390
|
moodle/moodle
|
mod/assign/feedback/file/locallib.php
|
assign_feedback_file.view_page
|
public function view_page($action) {
if ($action == 'uploadfiles') {
$users = required_param('selectedusers', PARAM_SEQUENCE);
return $this->view_batch_upload_files(explode(',', $users));
}
if ($action == 'uploadzip') {
return $this->view_upload_zip();
}
return '';
}
|
php
|
public function view_page($action) {
if ($action == 'uploadfiles') {
$users = required_param('selectedusers', PARAM_SEQUENCE);
return $this->view_batch_upload_files(explode(',', $users));
}
if ($action == 'uploadzip') {
return $this->view_upload_zip();
}
return '';
}
|
[
"public",
"function",
"view_page",
"(",
"$",
"action",
")",
"{",
"if",
"(",
"$",
"action",
"==",
"'uploadfiles'",
")",
"{",
"$",
"users",
"=",
"required_param",
"(",
"'selectedusers'",
",",
"PARAM_SEQUENCE",
")",
";",
"return",
"$",
"this",
"->",
"view_batch_upload_files",
"(",
"explode",
"(",
"','",
",",
"$",
"users",
")",
")",
";",
"}",
"if",
"(",
"$",
"action",
"==",
"'uploadzip'",
")",
"{",
"return",
"$",
"this",
"->",
"view_upload_zip",
"(",
")",
";",
"}",
"return",
"''",
";",
"}"
] |
Called by the assignment module when someone chooses something from the
grading navigation or batch operations list.
@param string $action - The page to view
@return string - The html response
|
[
"Called",
"by",
"the",
"assignment",
"module",
"when",
"someone",
"chooses",
"something",
"from",
"the",
"grading",
"navigation",
"or",
"batch",
"operations",
"list",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/file/locallib.php#L668-L678
|
218,391
|
moodle/moodle
|
lib/classes/antivirus/scanner.php
|
scanner.get_config
|
public function get_config($property) {
if (property_exists($this->config, $property)) {
return $this->config->$property;
}
throw new \coding_exception('Config property "' . $property . '" doesn\'t exist');
}
|
php
|
public function get_config($property) {
if (property_exists($this->config, $property)) {
return $this->config->$property;
}
throw new \coding_exception('Config property "' . $property . '" doesn\'t exist');
}
|
[
"public",
"function",
"get_config",
"(",
"$",
"property",
")",
"{",
"if",
"(",
"property_exists",
"(",
"$",
"this",
"->",
"config",
",",
"$",
"property",
")",
")",
"{",
"return",
"$",
"this",
"->",
"config",
"->",
"$",
"property",
";",
"}",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Config property \"'",
".",
"$",
"property",
".",
"'\" doesn\\'t exist'",
")",
";",
"}"
] |
Config get method.
@param string $property config property to get.
@return mixed
@throws \coding_exception
|
[
"Config",
"get",
"method",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/antivirus/scanner.php#L70-L75
|
218,392
|
moodle/moodle
|
lib/classes/antivirus/scanner.php
|
scanner.message_admins
|
public function message_admins($notice) {
$site = get_site();
$subject = get_string('emailsubject', 'antivirus', format_string($site->fullname));
$admins = get_admins();
foreach ($admins as $admin) {
$eventdata = new \core\message\message();
$eventdata->courseid = SITEID;
$eventdata->component = 'moodle';
$eventdata->name = 'errors';
$eventdata->userfrom = get_admin();
$eventdata->userto = $admin;
$eventdata->subject = $subject;
$eventdata->fullmessage = $notice;
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = '';
$eventdata->smallmessage = '';
message_send($eventdata);
}
}
|
php
|
public function message_admins($notice) {
$site = get_site();
$subject = get_string('emailsubject', 'antivirus', format_string($site->fullname));
$admins = get_admins();
foreach ($admins as $admin) {
$eventdata = new \core\message\message();
$eventdata->courseid = SITEID;
$eventdata->component = 'moodle';
$eventdata->name = 'errors';
$eventdata->userfrom = get_admin();
$eventdata->userto = $admin;
$eventdata->subject = $subject;
$eventdata->fullmessage = $notice;
$eventdata->fullmessageformat = FORMAT_PLAIN;
$eventdata->fullmessagehtml = '';
$eventdata->smallmessage = '';
message_send($eventdata);
}
}
|
[
"public",
"function",
"message_admins",
"(",
"$",
"notice",
")",
"{",
"$",
"site",
"=",
"get_site",
"(",
")",
";",
"$",
"subject",
"=",
"get_string",
"(",
"'emailsubject'",
",",
"'antivirus'",
",",
"format_string",
"(",
"$",
"site",
"->",
"fullname",
")",
")",
";",
"$",
"admins",
"=",
"get_admins",
"(",
")",
";",
"foreach",
"(",
"$",
"admins",
"as",
"$",
"admin",
")",
"{",
"$",
"eventdata",
"=",
"new",
"\\",
"core",
"\\",
"message",
"\\",
"message",
"(",
")",
";",
"$",
"eventdata",
"->",
"courseid",
"=",
"SITEID",
";",
"$",
"eventdata",
"->",
"component",
"=",
"'moodle'",
";",
"$",
"eventdata",
"->",
"name",
"=",
"'errors'",
";",
"$",
"eventdata",
"->",
"userfrom",
"=",
"get_admin",
"(",
")",
";",
"$",
"eventdata",
"->",
"userto",
"=",
"$",
"admin",
";",
"$",
"eventdata",
"->",
"subject",
"=",
"$",
"subject",
";",
"$",
"eventdata",
"->",
"fullmessage",
"=",
"$",
"notice",
";",
"$",
"eventdata",
"->",
"fullmessageformat",
"=",
"FORMAT_PLAIN",
";",
"$",
"eventdata",
"->",
"fullmessagehtml",
"=",
"''",
";",
"$",
"eventdata",
"->",
"smallmessage",
"=",
"''",
";",
"message_send",
"(",
"$",
"eventdata",
")",
";",
"}",
"}"
] |
Email admins about antivirus scan outcomes.
@param string $notice The body of the email to be sent.
@return void
|
[
"Email",
"admins",
"about",
"antivirus",
"scan",
"outcomes",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/antivirus/scanner.php#L138-L158
|
218,393
|
moodle/moodle
|
cache/classes/helper.php
|
cache_helper.get_class_for_mode
|
public static function get_class_for_mode($mode) {
switch ($mode) {
case cache_store::MODE_APPLICATION :
return 'cache_application';
case cache_store::MODE_REQUEST :
return 'cache_request';
case cache_store::MODE_SESSION :
return 'cache_session';
}
throw new coding_exception('Unknown cache mode passed. Must be one of cache_store::MODE_*');
}
|
php
|
public static function get_class_for_mode($mode) {
switch ($mode) {
case cache_store::MODE_APPLICATION :
return 'cache_application';
case cache_store::MODE_REQUEST :
return 'cache_request';
case cache_store::MODE_SESSION :
return 'cache_session';
}
throw new coding_exception('Unknown cache mode passed. Must be one of cache_store::MODE_*');
}
|
[
"public",
"static",
"function",
"get_class_for_mode",
"(",
"$",
"mode",
")",
"{",
"switch",
"(",
"$",
"mode",
")",
"{",
"case",
"cache_store",
"::",
"MODE_APPLICATION",
":",
"return",
"'cache_application'",
";",
"case",
"cache_store",
"::",
"MODE_REQUEST",
":",
"return",
"'cache_request'",
";",
"case",
"cache_store",
"::",
"MODE_SESSION",
":",
"return",
"'cache_session'",
";",
"}",
"throw",
"new",
"coding_exception",
"(",
"'Unknown cache mode passed. Must be one of cache_store::MODE_*'",
")",
";",
"}"
] |
Returns the class for use as a cache loader for the given mode.
@param int $mode One of cache_store::MODE_
@return string
@throws coding_exception
|
[
"Returns",
"the",
"class",
"for",
"use",
"as",
"a",
"cache",
"loader",
"for",
"the",
"given",
"mode",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/helper.php#L117-L127
|
218,394
|
moodle/moodle
|
cache/classes/helper.php
|
cache_helper.get_cache_stores
|
public static function get_cache_stores(cache_definition $definition) {
$instance = cache_config::instance();
$stores = $instance->get_stores_for_definition($definition);
$stores = self::initialise_cachestore_instances($stores, $definition);
return $stores;
}
|
php
|
public static function get_cache_stores(cache_definition $definition) {
$instance = cache_config::instance();
$stores = $instance->get_stores_for_definition($definition);
$stores = self::initialise_cachestore_instances($stores, $definition);
return $stores;
}
|
[
"public",
"static",
"function",
"get_cache_stores",
"(",
"cache_definition",
"$",
"definition",
")",
"{",
"$",
"instance",
"=",
"cache_config",
"::",
"instance",
"(",
")",
";",
"$",
"stores",
"=",
"$",
"instance",
"->",
"get_stores_for_definition",
"(",
"$",
"definition",
")",
";",
"$",
"stores",
"=",
"self",
"::",
"initialise_cachestore_instances",
"(",
"$",
"stores",
",",
"$",
"definition",
")",
";",
"return",
"$",
"stores",
";",
"}"
] |
Returns the cache stores to be used with the given definition.
@param cache_definition $definition
@return array
|
[
"Returns",
"the",
"cache",
"stores",
"to",
"be",
"used",
"with",
"the",
"given",
"definition",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/helper.php#L134-L139
|
218,395
|
moodle/moodle
|
cache/classes/helper.php
|
cache_helper.initialise_cachestore_instances
|
protected static function initialise_cachestore_instances(array $stores, cache_definition $definition) {
$return = array();
$factory = cache_factory::instance();
foreach ($stores as $name => $details) {
$store = $factory->create_store_from_config($name, $details, $definition);
if ($store !== false) {
$return[] = $store;
}
}
return $return;
}
|
php
|
protected static function initialise_cachestore_instances(array $stores, cache_definition $definition) {
$return = array();
$factory = cache_factory::instance();
foreach ($stores as $name => $details) {
$store = $factory->create_store_from_config($name, $details, $definition);
if ($store !== false) {
$return[] = $store;
}
}
return $return;
}
|
[
"protected",
"static",
"function",
"initialise_cachestore_instances",
"(",
"array",
"$",
"stores",
",",
"cache_definition",
"$",
"definition",
")",
"{",
"$",
"return",
"=",
"array",
"(",
")",
";",
"$",
"factory",
"=",
"cache_factory",
"::",
"instance",
"(",
")",
";",
"foreach",
"(",
"$",
"stores",
"as",
"$",
"name",
"=>",
"$",
"details",
")",
"{",
"$",
"store",
"=",
"$",
"factory",
"->",
"create_store_from_config",
"(",
"$",
"name",
",",
"$",
"details",
",",
"$",
"definition",
")",
";",
"if",
"(",
"$",
"store",
"!==",
"false",
")",
"{",
"$",
"return",
"[",
"]",
"=",
"$",
"store",
";",
"}",
"}",
"return",
"$",
"return",
";",
"}"
] |
Internal function for initialising an array of stores against a given cache definition.
@param array $stores
@param cache_definition $definition
@return cache_store[]
|
[
"Internal",
"function",
"for",
"initialising",
"an",
"array",
"of",
"stores",
"against",
"a",
"given",
"cache",
"definition",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/helper.php#L148-L158
|
218,396
|
moodle/moodle
|
cache/classes/helper.php
|
cache_helper.get_cachelock_for_store
|
public static function get_cachelock_for_store(cache_store $store) {
$instance = cache_config::instance();
$lockconf = $instance->get_lock_for_store($store->my_name());
$factory = cache_factory::instance();
return $factory->create_lock_instance($lockconf);
}
|
php
|
public static function get_cachelock_for_store(cache_store $store) {
$instance = cache_config::instance();
$lockconf = $instance->get_lock_for_store($store->my_name());
$factory = cache_factory::instance();
return $factory->create_lock_instance($lockconf);
}
|
[
"public",
"static",
"function",
"get_cachelock_for_store",
"(",
"cache_store",
"$",
"store",
")",
"{",
"$",
"instance",
"=",
"cache_config",
"::",
"instance",
"(",
")",
";",
"$",
"lockconf",
"=",
"$",
"instance",
"->",
"get_lock_for_store",
"(",
"$",
"store",
"->",
"my_name",
"(",
")",
")",
";",
"$",
"factory",
"=",
"cache_factory",
"::",
"instance",
"(",
")",
";",
"return",
"$",
"factory",
"->",
"create_lock_instance",
"(",
"$",
"lockconf",
")",
";",
"}"
] |
Returns a cache_lock instance suitable for use with the store.
@param cache_store $store
@return cache_lock_interface
|
[
"Returns",
"a",
"cache_lock",
"instance",
"suitable",
"for",
"use",
"with",
"the",
"store",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/helper.php#L166-L171
|
218,397
|
moodle/moodle
|
cache/classes/helper.php
|
cache_helper.early_get_cache_plugins
|
public static function early_get_cache_plugins() {
global $CFG;
$result = array();
$ignored = array('CVS', '_vti_cnf', 'simpletest', 'db', 'yui', 'tests');
$fulldir = $CFG->dirroot.'/cache/stores';
$items = new DirectoryIterator($fulldir);
foreach ($items as $item) {
if ($item->isDot() or !$item->isDir()) {
continue;
}
$pluginname = $item->getFilename();
if (in_array($pluginname, $ignored)) {
continue;
}
if (!is_valid_plugin_name($pluginname)) {
// Better ignore plugins with problematic names here.
continue;
}
$result[$pluginname] = $fulldir.'/'.$pluginname;
unset($item);
}
unset($items);
return $result;
}
|
php
|
public static function early_get_cache_plugins() {
global $CFG;
$result = array();
$ignored = array('CVS', '_vti_cnf', 'simpletest', 'db', 'yui', 'tests');
$fulldir = $CFG->dirroot.'/cache/stores';
$items = new DirectoryIterator($fulldir);
foreach ($items as $item) {
if ($item->isDot() or !$item->isDir()) {
continue;
}
$pluginname = $item->getFilename();
if (in_array($pluginname, $ignored)) {
continue;
}
if (!is_valid_plugin_name($pluginname)) {
// Better ignore plugins with problematic names here.
continue;
}
$result[$pluginname] = $fulldir.'/'.$pluginname;
unset($item);
}
unset($items);
return $result;
}
|
[
"public",
"static",
"function",
"early_get_cache_plugins",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"ignored",
"=",
"array",
"(",
"'CVS'",
",",
"'_vti_cnf'",
",",
"'simpletest'",
",",
"'db'",
",",
"'yui'",
",",
"'tests'",
")",
";",
"$",
"fulldir",
"=",
"$",
"CFG",
"->",
"dirroot",
".",
"'/cache/stores'",
";",
"$",
"items",
"=",
"new",
"DirectoryIterator",
"(",
"$",
"fulldir",
")",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"$",
"item",
"->",
"isDot",
"(",
")",
"or",
"!",
"$",
"item",
"->",
"isDir",
"(",
")",
")",
"{",
"continue",
";",
"}",
"$",
"pluginname",
"=",
"$",
"item",
"->",
"getFilename",
"(",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"pluginname",
",",
"$",
"ignored",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"is_valid_plugin_name",
"(",
"$",
"pluginname",
")",
")",
"{",
"// Better ignore plugins with problematic names here.",
"continue",
";",
"}",
"$",
"result",
"[",
"$",
"pluginname",
"]",
"=",
"$",
"fulldir",
".",
"'/'",
".",
"$",
"pluginname",
";",
"unset",
"(",
"$",
"item",
")",
";",
"}",
"unset",
"(",
"$",
"items",
")",
";",
"return",
"$",
"result",
";",
"}"
] |
Returns an array of plugins without using core methods.
This function explicitly does NOT use core functions as it will in some circumstances be called before Moodle has
finished initialising. This happens when loading configuration for instance.
@return string
|
[
"Returns",
"an",
"array",
"of",
"plugins",
"without",
"using",
"core",
"methods",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/helper.php#L181-L204
|
218,398
|
moodle/moodle
|
cache/classes/helper.php
|
cache_helper.invalidate_by_definition
|
public static function invalidate_by_definition($component, $area, array $identifiers = array(), $keys = array()) {
$cache = cache::make($component, $area, $identifiers);
if (is_array($keys)) {
$cache->delete_many($keys);
} else if (is_scalar($keys)) {
$cache->delete($keys);
} else {
throw new coding_exception('cache_helper::invalidate_by_definition only accepts $keys as array, or scalar.');
}
return true;
}
|
php
|
public static function invalidate_by_definition($component, $area, array $identifiers = array(), $keys = array()) {
$cache = cache::make($component, $area, $identifiers);
if (is_array($keys)) {
$cache->delete_many($keys);
} else if (is_scalar($keys)) {
$cache->delete($keys);
} else {
throw new coding_exception('cache_helper::invalidate_by_definition only accepts $keys as array, or scalar.');
}
return true;
}
|
[
"public",
"static",
"function",
"invalidate_by_definition",
"(",
"$",
"component",
",",
"$",
"area",
",",
"array",
"$",
"identifiers",
"=",
"array",
"(",
")",
",",
"$",
"keys",
"=",
"array",
"(",
")",
")",
"{",
"$",
"cache",
"=",
"cache",
"::",
"make",
"(",
"$",
"component",
",",
"$",
"area",
",",
"$",
"identifiers",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"keys",
")",
")",
"{",
"$",
"cache",
"->",
"delete_many",
"(",
"$",
"keys",
")",
";",
"}",
"else",
"if",
"(",
"is_scalar",
"(",
"$",
"keys",
")",
")",
"{",
"$",
"cache",
"->",
"delete",
"(",
"$",
"keys",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"coding_exception",
"(",
"'cache_helper::invalidate_by_definition only accepts $keys as array, or scalar.'",
")",
";",
"}",
"return",
"true",
";",
"}"
] |
Invalidates a given set of keys from a given definition.
@todo Invalidating by definition should also add to the event cache so that sessions can be invalidated (when required).
@param string $component
@param string $area
@param array $identifiers
@param array $keys
@return boolean
|
[
"Invalidates",
"a",
"given",
"set",
"of",
"keys",
"from",
"a",
"given",
"definition",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/helper.php#L217-L227
|
218,399
|
moodle/moodle
|
cache/classes/helper.php
|
cache_helper.invalidate_by_event
|
public static function invalidate_by_event($event, array $keys) {
$instance = cache_config::instance();
$invalidationeventset = false;
$factory = cache_factory::instance();
$inuse = $factory->get_caches_in_use();
$purgetoken = null;
foreach ($instance->get_definitions() as $name => $definitionarr) {
$definition = cache_definition::load($name, $definitionarr);
if ($definition->invalidates_on_event($event)) {
// First up check if there is a cache loader for this definition already.
// If there is we need to invalidate the keys from there.
$definitionkey = $definition->get_component().'/'.$definition->get_area();
if (isset($inuse[$definitionkey])) {
$inuse[$definitionkey]->delete_many($keys);
}
// We should only log events for application and session caches.
// Request caches shouldn't have events as all data is lost at the end of the request.
// Events should only be logged once of course and likely several definitions are watching so we
// track its logging with $invalidationeventset.
$logevent = ($invalidationeventset === false && $definition->get_mode() !== cache_store::MODE_REQUEST);
if ($logevent) {
// Get the event invalidation cache.
$cache = cache::make('core', 'eventinvalidation');
// Get any existing invalidated keys for this cache.
$data = $cache->get($event);
if ($data === false) {
// There are none.
$data = array();
}
// Add our keys to them with the current cache timestamp.
if (null === $purgetoken) {
$purgetoken = cache::get_purge_token(true);
}
foreach ($keys as $key) {
$data[$key] = $purgetoken;
}
// Set that data back to the cache.
$cache->set($event, $data);
// This only needs to occur once.
$invalidationeventset = true;
}
}
}
}
|
php
|
public static function invalidate_by_event($event, array $keys) {
$instance = cache_config::instance();
$invalidationeventset = false;
$factory = cache_factory::instance();
$inuse = $factory->get_caches_in_use();
$purgetoken = null;
foreach ($instance->get_definitions() as $name => $definitionarr) {
$definition = cache_definition::load($name, $definitionarr);
if ($definition->invalidates_on_event($event)) {
// First up check if there is a cache loader for this definition already.
// If there is we need to invalidate the keys from there.
$definitionkey = $definition->get_component().'/'.$definition->get_area();
if (isset($inuse[$definitionkey])) {
$inuse[$definitionkey]->delete_many($keys);
}
// We should only log events for application and session caches.
// Request caches shouldn't have events as all data is lost at the end of the request.
// Events should only be logged once of course and likely several definitions are watching so we
// track its logging with $invalidationeventset.
$logevent = ($invalidationeventset === false && $definition->get_mode() !== cache_store::MODE_REQUEST);
if ($logevent) {
// Get the event invalidation cache.
$cache = cache::make('core', 'eventinvalidation');
// Get any existing invalidated keys for this cache.
$data = $cache->get($event);
if ($data === false) {
// There are none.
$data = array();
}
// Add our keys to them with the current cache timestamp.
if (null === $purgetoken) {
$purgetoken = cache::get_purge_token(true);
}
foreach ($keys as $key) {
$data[$key] = $purgetoken;
}
// Set that data back to the cache.
$cache->set($event, $data);
// This only needs to occur once.
$invalidationeventset = true;
}
}
}
}
|
[
"public",
"static",
"function",
"invalidate_by_event",
"(",
"$",
"event",
",",
"array",
"$",
"keys",
")",
"{",
"$",
"instance",
"=",
"cache_config",
"::",
"instance",
"(",
")",
";",
"$",
"invalidationeventset",
"=",
"false",
";",
"$",
"factory",
"=",
"cache_factory",
"::",
"instance",
"(",
")",
";",
"$",
"inuse",
"=",
"$",
"factory",
"->",
"get_caches_in_use",
"(",
")",
";",
"$",
"purgetoken",
"=",
"null",
";",
"foreach",
"(",
"$",
"instance",
"->",
"get_definitions",
"(",
")",
"as",
"$",
"name",
"=>",
"$",
"definitionarr",
")",
"{",
"$",
"definition",
"=",
"cache_definition",
"::",
"load",
"(",
"$",
"name",
",",
"$",
"definitionarr",
")",
";",
"if",
"(",
"$",
"definition",
"->",
"invalidates_on_event",
"(",
"$",
"event",
")",
")",
"{",
"// First up check if there is a cache loader for this definition already.",
"// If there is we need to invalidate the keys from there.",
"$",
"definitionkey",
"=",
"$",
"definition",
"->",
"get_component",
"(",
")",
".",
"'/'",
".",
"$",
"definition",
"->",
"get_area",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"inuse",
"[",
"$",
"definitionkey",
"]",
")",
")",
"{",
"$",
"inuse",
"[",
"$",
"definitionkey",
"]",
"->",
"delete_many",
"(",
"$",
"keys",
")",
";",
"}",
"// We should only log events for application and session caches.",
"// Request caches shouldn't have events as all data is lost at the end of the request.",
"// Events should only be logged once of course and likely several definitions are watching so we",
"// track its logging with $invalidationeventset.",
"$",
"logevent",
"=",
"(",
"$",
"invalidationeventset",
"===",
"false",
"&&",
"$",
"definition",
"->",
"get_mode",
"(",
")",
"!==",
"cache_store",
"::",
"MODE_REQUEST",
")",
";",
"if",
"(",
"$",
"logevent",
")",
"{",
"// Get the event invalidation cache.",
"$",
"cache",
"=",
"cache",
"::",
"make",
"(",
"'core'",
",",
"'eventinvalidation'",
")",
";",
"// Get any existing invalidated keys for this cache.",
"$",
"data",
"=",
"$",
"cache",
"->",
"get",
"(",
"$",
"event",
")",
";",
"if",
"(",
"$",
"data",
"===",
"false",
")",
"{",
"// There are none.",
"$",
"data",
"=",
"array",
"(",
")",
";",
"}",
"// Add our keys to them with the current cache timestamp.",
"if",
"(",
"null",
"===",
"$",
"purgetoken",
")",
"{",
"$",
"purgetoken",
"=",
"cache",
"::",
"get_purge_token",
"(",
"true",
")",
";",
"}",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"$",
"purgetoken",
";",
"}",
"// Set that data back to the cache.",
"$",
"cache",
"->",
"set",
"(",
"$",
"event",
",",
"$",
"data",
")",
";",
"// This only needs to occur once.",
"$",
"invalidationeventset",
"=",
"true",
";",
"}",
"}",
"}",
"}"
] |
Invalidates a given set of keys by means of an event.
Events cannot determine what identifiers might need to be cleared. Event based purge and invalidation
are only supported on caches without identifiers.
@param string $event
@param array $keys
|
[
"Invalidates",
"a",
"given",
"set",
"of",
"keys",
"by",
"means",
"of",
"an",
"event",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/helper.php#L238-L283
|
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.