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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
211,900 | moodle/moodle | lib/phpexcel/PHPExcel/Shared/Drawing.php | PHPExcel_Shared_Drawing.pixelsToCellDimension | public static function pixelsToCellDimension($pValue = 0, PHPExcel_Style_Font $pDefaultFont)
{
// Font name and size
$name = $pDefaultFont->getName();
$size = $pDefaultFont->getSize();
if (isset(PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size])) {
// Exact width can be determined
$colWidth = $pValue * PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['width'] / PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['px'];
} else {
// We don't have data for this particular font and size, use approximation by
// extrapolating from Calibri 11
$colWidth = $pValue * 11 * PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['width'] / PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['px'] / $size;
}
return $colWidth;
} | php | public static function pixelsToCellDimension($pValue = 0, PHPExcel_Style_Font $pDefaultFont)
{
// Font name and size
$name = $pDefaultFont->getName();
$size = $pDefaultFont->getSize();
if (isset(PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size])) {
// Exact width can be determined
$colWidth = $pValue * PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['width'] / PHPExcel_Shared_Font::$defaultColumnWidths[$name][$size]['px'];
} else {
// We don't have data for this particular font and size, use approximation by
// extrapolating from Calibri 11
$colWidth = $pValue * 11 * PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['width'] / PHPExcel_Shared_Font::$defaultColumnWidths['Calibri'][11]['px'] / $size;
}
return $colWidth;
} | [
"public",
"static",
"function",
"pixelsToCellDimension",
"(",
"$",
"pValue",
"=",
"0",
",",
"PHPExcel_Style_Font",
"$",
"pDefaultFont",
")",
"{",
"// Font name and size",
"$",
"name",
"=",
"$",
"pDefaultFont",
"->",
"getName",
"(",
")",
";",
"$",
"size",
"=",
"$",
"pDefaultFont",
"->",
"getSize",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"PHPExcel_Shared_Font",
"::",
"$",
"defaultColumnWidths",
"[",
"$",
"name",
"]",
"[",
"$",
"size",
"]",
")",
")",
"{",
"// Exact width can be determined",
"$",
"colWidth",
"=",
"$",
"pValue",
"*",
"PHPExcel_Shared_Font",
"::",
"$",
"defaultColumnWidths",
"[",
"$",
"name",
"]",
"[",
"$",
"size",
"]",
"[",
"'width'",
"]",
"/",
"PHPExcel_Shared_Font",
"::",
"$",
"defaultColumnWidths",
"[",
"$",
"name",
"]",
"[",
"$",
"size",
"]",
"[",
"'px'",
"]",
";",
"}",
"else",
"{",
"// We don't have data for this particular font and size, use approximation by",
"// extrapolating from Calibri 11",
"$",
"colWidth",
"=",
"$",
"pValue",
"*",
"11",
"*",
"PHPExcel_Shared_Font",
"::",
"$",
"defaultColumnWidths",
"[",
"'Calibri'",
"]",
"[",
"11",
"]",
"[",
"'width'",
"]",
"/",
"PHPExcel_Shared_Font",
"::",
"$",
"defaultColumnWidths",
"[",
"'Calibri'",
"]",
"[",
"11",
"]",
"[",
"'px'",
"]",
"/",
"$",
"size",
";",
"}",
"return",
"$",
"colWidth",
";",
"}"
] | Convert pixels to column width. Exact algorithm not known.
By inspection of a real Excel file using Calibri 11, one finds 1000px ~ 142.85546875
This gives a conversion factor of 7. Also, we assume that pixels and font size are proportional.
@param int $pValue Value in pixels
@param PHPExcel_Style_Font $pDefaultFont Default font of the workbook
@return int Value in cell dimension | [
"Convert",
"pixels",
"to",
"column",
"width",
".",
"Exact",
"algorithm",
"not",
"known",
".",
"By",
"inspection",
"of",
"a",
"real",
"Excel",
"file",
"using",
"Calibri",
"11",
"one",
"finds",
"1000px",
"~",
"142",
".",
"85546875",
"This",
"gives",
"a",
"conversion",
"factor",
"of",
"7",
".",
"Also",
"we",
"assume",
"that",
"pixels",
"and",
"font",
"size",
"are",
"proportional",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Shared/Drawing.php#L73-L89 |
211,901 | moodle/moodle | completion/criteria/completion_criteria.php | completion_criteria.factory | public static function factory($params) {
global $CFG, $COMPLETION_CRITERIA_TYPES;
if (!isset($params['criteriatype']) || !isset($COMPLETION_CRITERIA_TYPES[$params['criteriatype']])) {
print_error('invalidcriteriatype', 'completion');
}
$class = 'completion_criteria_'.$COMPLETION_CRITERIA_TYPES[$params['criteriatype']];
require_once($CFG->dirroot.'/completion/criteria/'.$class.'.php');
return new $class($params, false);
} | php | public static function factory($params) {
global $CFG, $COMPLETION_CRITERIA_TYPES;
if (!isset($params['criteriatype']) || !isset($COMPLETION_CRITERIA_TYPES[$params['criteriatype']])) {
print_error('invalidcriteriatype', 'completion');
}
$class = 'completion_criteria_'.$COMPLETION_CRITERIA_TYPES[$params['criteriatype']];
require_once($CFG->dirroot.'/completion/criteria/'.$class.'.php');
return new $class($params, false);
} | [
"public",
"static",
"function",
"factory",
"(",
"$",
"params",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"COMPLETION_CRITERIA_TYPES",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"params",
"[",
"'criteriatype'",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"COMPLETION_CRITERIA_TYPES",
"[",
"$",
"params",
"[",
"'criteriatype'",
"]",
"]",
")",
")",
"{",
"print_error",
"(",
"'invalidcriteriatype'",
",",
"'completion'",
")",
";",
"}",
"$",
"class",
"=",
"'completion_criteria_'",
".",
"$",
"COMPLETION_CRITERIA_TYPES",
"[",
"$",
"params",
"[",
"'criteriatype'",
"]",
"]",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/completion/criteria/'",
".",
"$",
"class",
".",
"'.php'",
")",
";",
"return",
"new",
"$",
"class",
"(",
"$",
"params",
",",
"false",
")",
";",
"}"
] | Factory method for creating correct class object
@param array $params associative arrays varname=>value
@return completion_criteria | [
"Factory",
"method",
"for",
"creating",
"correct",
"class",
"object"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/criteria/completion_criteria.php#L169-L180 |
211,902 | moodle/moodle | completion/criteria/completion_criteria.php | completion_criteria.get_icon | public function get_icon($alt, array $attributes = null) {
global $COMPLETION_CRITERIA_TYPES;
$criteriatype = $COMPLETION_CRITERIA_TYPES[$this->criteriatype];
return new pix_icon('i/'.$criteriatype, $alt, 'moodle', $attributes);
} | php | public function get_icon($alt, array $attributes = null) {
global $COMPLETION_CRITERIA_TYPES;
$criteriatype = $COMPLETION_CRITERIA_TYPES[$this->criteriatype];
return new pix_icon('i/'.$criteriatype, $alt, 'moodle', $attributes);
} | [
"public",
"function",
"get_icon",
"(",
"$",
"alt",
",",
"array",
"$",
"attributes",
"=",
"null",
")",
"{",
"global",
"$",
"COMPLETION_CRITERIA_TYPES",
";",
"$",
"criteriatype",
"=",
"$",
"COMPLETION_CRITERIA_TYPES",
"[",
"$",
"this",
"->",
"criteriatype",
"]",
";",
"return",
"new",
"pix_icon",
"(",
"'i/'",
".",
"$",
"criteriatype",
",",
"$",
"alt",
",",
"'moodle'",
",",
"$",
"attributes",
")",
";",
"}"
] | Return pix_icon for display in reports.
@param string $alt The alt text to use for the icon
@param array $attributes html attributes
@return pix_icon | [
"Return",
"pix_icon",
"for",
"display",
"in",
"reports",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/criteria/completion_criteria.php#L244-L249 |
211,903 | moodle/moodle | blocks/timeline/classes/privacy/provider.php | provider.get_metadata | public static function get_metadata(collection $collection) : collection {
$collection->add_user_preference('block_timeline_user_sort_preference', 'privacy:metadata:timelinesortpreference');
$collection->add_user_preference('block_timeline_user_filter_preference', 'privacy:metadata:timelinefilterpreference');
$collection->add_user_preference('block_timeline_user_limit_preference', 'privacy:metadata:timelinelimitpreference');
return $collection;
} | php | public static function get_metadata(collection $collection) : collection {
$collection->add_user_preference('block_timeline_user_sort_preference', 'privacy:metadata:timelinesortpreference');
$collection->add_user_preference('block_timeline_user_filter_preference', 'privacy:metadata:timelinefilterpreference');
$collection->add_user_preference('block_timeline_user_limit_preference', 'privacy:metadata:timelinelimitpreference');
return $collection;
} | [
"public",
"static",
"function",
"get_metadata",
"(",
"collection",
"$",
"collection",
")",
":",
"collection",
"{",
"$",
"collection",
"->",
"add_user_preference",
"(",
"'block_timeline_user_sort_preference'",
",",
"'privacy:metadata:timelinesortpreference'",
")",
";",
"$",
"collection",
"->",
"add_user_preference",
"(",
"'block_timeline_user_filter_preference'",
",",
"'privacy:metadata:timelinefilterpreference'",
")",
";",
"$",
"collection",
"->",
"add_user_preference",
"(",
"'block_timeline_user_limit_preference'",
",",
"'privacy:metadata:timelinelimitpreference'",
")",
";",
"return",
"$",
"collection",
";",
"}"
] | Returns meta-data information about the myoverview block.
@param \core_privacy\local\metadata\collection $collection A collection of meta-data.
@return \core_privacy\local\metadata\collection Return the collection of meta-data. | [
"Returns",
"meta",
"-",
"data",
"information",
"about",
"the",
"myoverview",
"block",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/timeline/classes/privacy/provider.php#L44-L49 |
211,904 | moodle/moodle | lib/simplepie/library/SimplePie/Parse/Date.php | SimplePie_Parse_Date.parse | public function parse($date)
{
foreach ($this->user as $method)
{
if (($returned = call_user_func($method, $date)) !== false)
{
return $returned;
}
}
foreach ($this->built_in as $method)
{
if (($returned = call_user_func(array($this, $method), $date)) !== false)
{
return $returned;
}
}
return false;
} | php | public function parse($date)
{
foreach ($this->user as $method)
{
if (($returned = call_user_func($method, $date)) !== false)
{
return $returned;
}
}
foreach ($this->built_in as $method)
{
if (($returned = call_user_func(array($this, $method), $date)) !== false)
{
return $returned;
}
}
return false;
} | [
"public",
"function",
"parse",
"(",
"$",
"date",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"user",
"as",
"$",
"method",
")",
"{",
"if",
"(",
"(",
"$",
"returned",
"=",
"call_user_func",
"(",
"$",
"method",
",",
"$",
"date",
")",
")",
"!==",
"false",
")",
"{",
"return",
"$",
"returned",
";",
"}",
"}",
"foreach",
"(",
"$",
"this",
"->",
"built_in",
"as",
"$",
"method",
")",
"{",
"if",
"(",
"(",
"$",
"returned",
"=",
"call_user_func",
"(",
"array",
"(",
"$",
"this",
",",
"$",
"method",
")",
",",
"$",
"date",
")",
")",
"!==",
"false",
")",
"{",
"return",
"$",
"returned",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Parse a date
@final
@access public
@param string $date Date to parse
@return int Timestamp corresponding to date string, or false on failure | [
"Parse",
"a",
"date"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/Parse/Date.php#L590-L609 |
211,905 | moodle/moodle | lib/simplepie/library/SimplePie/Parse/Date.php | SimplePie_Parse_Date.date_rfc2822 | public function date_rfc2822($date)
{
static $pcre;
if (!$pcre)
{
$wsp = '[\x09\x20]';
$fws = '(?:' . $wsp . '+|' . $wsp . '*(?:\x0D\x0A' . $wsp . '+)+)';
$optional_fws = $fws . '?';
$day_name = $this->day_pcre;
$month = $this->month_pcre;
$day = '([0-9]{1,2})';
$hour = $minute = $second = '([0-9]{2})';
$year = '([0-9]{2,4})';
$num_zone = '([+\-])([0-9]{2})([0-9]{2})';
$character_zone = '([A-Z]{1,5})';
$zone = '(?:' . $num_zone . '|' . $character_zone . ')';
$pcre = '/(?:' . $optional_fws . $day_name . $optional_fws . ',)?' . $optional_fws . $day . $fws . $month . $fws . $year . $fws . $hour . $optional_fws . ':' . $optional_fws . $minute . '(?:' . $optional_fws . ':' . $optional_fws . $second . ')?' . $fws . $zone . '/i';
}
if (preg_match($pcre, $this->remove_rfc2822_comments($date), $match))
{
/*
Capturing subpatterns:
1: Day name
2: Day
3: Month
4: Year
5: Hour
6: Minute
7: Second
8: Timezone ±
9: Timezone hours
10: Timezone minutes
11: Alphabetic timezone
*/
// Find the month number
$month = $this->month[strtolower($match[3])];
// Numeric timezone
if ($match[8] !== '')
{
$timezone = $match[9] * 3600;
$timezone += $match[10] * 60;
if ($match[8] === '-')
{
$timezone = 0 - $timezone;
}
}
// Character timezone
elseif (isset($this->timezone[strtoupper($match[11])]))
{
$timezone = $this->timezone[strtoupper($match[11])];
}
// Assume everything else to be -0000
else
{
$timezone = 0;
}
// Deal with 2/3 digit years
if ($match[4] < 50)
{
$match[4] += 2000;
}
elseif ($match[4] < 1000)
{
$match[4] += 1900;
}
// Second is optional, if it is empty set it to zero
if ($match[7] !== '')
{
$second = $match[7];
}
else
{
$second = 0;
}
return gmmktime($match[5], $match[6], $second, $month, $match[2], $match[4]) - $timezone;
}
else
{
return false;
}
} | php | public function date_rfc2822($date)
{
static $pcre;
if (!$pcre)
{
$wsp = '[\x09\x20]';
$fws = '(?:' . $wsp . '+|' . $wsp . '*(?:\x0D\x0A' . $wsp . '+)+)';
$optional_fws = $fws . '?';
$day_name = $this->day_pcre;
$month = $this->month_pcre;
$day = '([0-9]{1,2})';
$hour = $minute = $second = '([0-9]{2})';
$year = '([0-9]{2,4})';
$num_zone = '([+\-])([0-9]{2})([0-9]{2})';
$character_zone = '([A-Z]{1,5})';
$zone = '(?:' . $num_zone . '|' . $character_zone . ')';
$pcre = '/(?:' . $optional_fws . $day_name . $optional_fws . ',)?' . $optional_fws . $day . $fws . $month . $fws . $year . $fws . $hour . $optional_fws . ':' . $optional_fws . $minute . '(?:' . $optional_fws . ':' . $optional_fws . $second . ')?' . $fws . $zone . '/i';
}
if (preg_match($pcre, $this->remove_rfc2822_comments($date), $match))
{
/*
Capturing subpatterns:
1: Day name
2: Day
3: Month
4: Year
5: Hour
6: Minute
7: Second
8: Timezone ±
9: Timezone hours
10: Timezone minutes
11: Alphabetic timezone
*/
// Find the month number
$month = $this->month[strtolower($match[3])];
// Numeric timezone
if ($match[8] !== '')
{
$timezone = $match[9] * 3600;
$timezone += $match[10] * 60;
if ($match[8] === '-')
{
$timezone = 0 - $timezone;
}
}
// Character timezone
elseif (isset($this->timezone[strtoupper($match[11])]))
{
$timezone = $this->timezone[strtoupper($match[11])];
}
// Assume everything else to be -0000
else
{
$timezone = 0;
}
// Deal with 2/3 digit years
if ($match[4] < 50)
{
$match[4] += 2000;
}
elseif ($match[4] < 1000)
{
$match[4] += 1900;
}
// Second is optional, if it is empty set it to zero
if ($match[7] !== '')
{
$second = $match[7];
}
else
{
$second = 0;
}
return gmmktime($match[5], $match[6], $second, $month, $match[2], $match[4]) - $timezone;
}
else
{
return false;
}
} | [
"public",
"function",
"date_rfc2822",
"(",
"$",
"date",
")",
"{",
"static",
"$",
"pcre",
";",
"if",
"(",
"!",
"$",
"pcre",
")",
"{",
"$",
"wsp",
"=",
"'[\\x09\\x20]'",
";",
"$",
"fws",
"=",
"'(?:'",
".",
"$",
"wsp",
".",
"'+|'",
".",
"$",
"wsp",
".",
"'*(?:\\x0D\\x0A'",
".",
"$",
"wsp",
".",
"'+)+)'",
";",
"$",
"optional_fws",
"=",
"$",
"fws",
".",
"'?'",
";",
"$",
"day_name",
"=",
"$",
"this",
"->",
"day_pcre",
";",
"$",
"month",
"=",
"$",
"this",
"->",
"month_pcre",
";",
"$",
"day",
"=",
"'([0-9]{1,2})'",
";",
"$",
"hour",
"=",
"$",
"minute",
"=",
"$",
"second",
"=",
"'([0-9]{2})'",
";",
"$",
"year",
"=",
"'([0-9]{2,4})'",
";",
"$",
"num_zone",
"=",
"'([+\\-])([0-9]{2})([0-9]{2})'",
";",
"$",
"character_zone",
"=",
"'([A-Z]{1,5})'",
";",
"$",
"zone",
"=",
"'(?:'",
".",
"$",
"num_zone",
".",
"'|'",
".",
"$",
"character_zone",
".",
"')'",
";",
"$",
"pcre",
"=",
"'/(?:'",
".",
"$",
"optional_fws",
".",
"$",
"day_name",
".",
"$",
"optional_fws",
".",
"',)?'",
".",
"$",
"optional_fws",
".",
"$",
"day",
".",
"$",
"fws",
".",
"$",
"month",
".",
"$",
"fws",
".",
"$",
"year",
".",
"$",
"fws",
".",
"$",
"hour",
".",
"$",
"optional_fws",
".",
"':'",
".",
"$",
"optional_fws",
".",
"$",
"minute",
".",
"'(?:'",
".",
"$",
"optional_fws",
".",
"':'",
".",
"$",
"optional_fws",
".",
"$",
"second",
".",
"')?'",
".",
"$",
"fws",
".",
"$",
"zone",
".",
"'/i'",
";",
"}",
"if",
"(",
"preg_match",
"(",
"$",
"pcre",
",",
"$",
"this",
"->",
"remove_rfc2822_comments",
"(",
"$",
"date",
")",
",",
"$",
"match",
")",
")",
"{",
"/*\n\t\t\tCapturing subpatterns:\n\t\t\t1: Day name\n\t\t\t2: Day\n\t\t\t3: Month\n\t\t\t4: Year\n\t\t\t5: Hour\n\t\t\t6: Minute\n\t\t\t7: Second\n\t\t\t8: Timezone ±\n\t\t\t9: Timezone hours\n\t\t\t10: Timezone minutes\n\t\t\t11: Alphabetic timezone\n\t\t\t*/",
"// Find the month number",
"$",
"month",
"=",
"$",
"this",
"->",
"month",
"[",
"strtolower",
"(",
"$",
"match",
"[",
"3",
"]",
")",
"]",
";",
"// Numeric timezone",
"if",
"(",
"$",
"match",
"[",
"8",
"]",
"!==",
"''",
")",
"{",
"$",
"timezone",
"=",
"$",
"match",
"[",
"9",
"]",
"*",
"3600",
";",
"$",
"timezone",
"+=",
"$",
"match",
"[",
"10",
"]",
"*",
"60",
";",
"if",
"(",
"$",
"match",
"[",
"8",
"]",
"===",
"'-'",
")",
"{",
"$",
"timezone",
"=",
"0",
"-",
"$",
"timezone",
";",
"}",
"}",
"// Character timezone",
"elseif",
"(",
"isset",
"(",
"$",
"this",
"->",
"timezone",
"[",
"strtoupper",
"(",
"$",
"match",
"[",
"11",
"]",
")",
"]",
")",
")",
"{",
"$",
"timezone",
"=",
"$",
"this",
"->",
"timezone",
"[",
"strtoupper",
"(",
"$",
"match",
"[",
"11",
"]",
")",
"]",
";",
"}",
"// Assume everything else to be -0000",
"else",
"{",
"$",
"timezone",
"=",
"0",
";",
"}",
"// Deal with 2/3 digit years",
"if",
"(",
"$",
"match",
"[",
"4",
"]",
"<",
"50",
")",
"{",
"$",
"match",
"[",
"4",
"]",
"+=",
"2000",
";",
"}",
"elseif",
"(",
"$",
"match",
"[",
"4",
"]",
"<",
"1000",
")",
"{",
"$",
"match",
"[",
"4",
"]",
"+=",
"1900",
";",
"}",
"// Second is optional, if it is empty set it to zero",
"if",
"(",
"$",
"match",
"[",
"7",
"]",
"!==",
"''",
")",
"{",
"$",
"second",
"=",
"$",
"match",
"[",
"7",
"]",
";",
"}",
"else",
"{",
"$",
"second",
"=",
"0",
";",
"}",
"return",
"gmmktime",
"(",
"$",
"match",
"[",
"5",
"]",
",",
"$",
"match",
"[",
"6",
"]",
",",
"$",
"second",
",",
"$",
"month",
",",
"$",
"match",
"[",
"2",
"]",
",",
"$",
"match",
"[",
"4",
"]",
")",
"-",
"$",
"timezone",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Parse RFC2822's date format
@access protected
@return int Timestamp | [
"Parse",
"RFC2822",
"s",
"date",
"format"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/Parse/Date.php#L770-L855 |
211,906 | moodle/moodle | lib/simplepie/library/SimplePie/Parse/Date.php | SimplePie_Parse_Date.date_rfc850 | public function date_rfc850($date)
{
static $pcre;
if (!$pcre)
{
$space = '[\x09\x20]+';
$day_name = $this->day_pcre;
$month = $this->month_pcre;
$day = '([0-9]{1,2})';
$year = $hour = $minute = $second = '([0-9]{2})';
$zone = '([A-Z]{1,5})';
$pcre = '/^' . $day_name . ',' . $space . $day . '-' . $month . '-' . $year . $space . $hour . ':' . $minute . ':' . $second . $space . $zone . '$/i';
}
if (preg_match($pcre, $date, $match))
{
/*
Capturing subpatterns:
1: Day name
2: Day
3: Month
4: Year
5: Hour
6: Minute
7: Second
8: Timezone
*/
// Month
$month = $this->month[strtolower($match[3])];
// Character timezone
if (isset($this->timezone[strtoupper($match[8])]))
{
$timezone = $this->timezone[strtoupper($match[8])];
}
// Assume everything else to be -0000
else
{
$timezone = 0;
}
// Deal with 2 digit year
if ($match[4] < 50)
{
$match[4] += 2000;
}
else
{
$match[4] += 1900;
}
return gmmktime($match[5], $match[6], $match[7], $month, $match[2], $match[4]) - $timezone;
}
else
{
return false;
}
} | php | public function date_rfc850($date)
{
static $pcre;
if (!$pcre)
{
$space = '[\x09\x20]+';
$day_name = $this->day_pcre;
$month = $this->month_pcre;
$day = '([0-9]{1,2})';
$year = $hour = $minute = $second = '([0-9]{2})';
$zone = '([A-Z]{1,5})';
$pcre = '/^' . $day_name . ',' . $space . $day . '-' . $month . '-' . $year . $space . $hour . ':' . $minute . ':' . $second . $space . $zone . '$/i';
}
if (preg_match($pcre, $date, $match))
{
/*
Capturing subpatterns:
1: Day name
2: Day
3: Month
4: Year
5: Hour
6: Minute
7: Second
8: Timezone
*/
// Month
$month = $this->month[strtolower($match[3])];
// Character timezone
if (isset($this->timezone[strtoupper($match[8])]))
{
$timezone = $this->timezone[strtoupper($match[8])];
}
// Assume everything else to be -0000
else
{
$timezone = 0;
}
// Deal with 2 digit year
if ($match[4] < 50)
{
$match[4] += 2000;
}
else
{
$match[4] += 1900;
}
return gmmktime($match[5], $match[6], $match[7], $month, $match[2], $match[4]) - $timezone;
}
else
{
return false;
}
} | [
"public",
"function",
"date_rfc850",
"(",
"$",
"date",
")",
"{",
"static",
"$",
"pcre",
";",
"if",
"(",
"!",
"$",
"pcre",
")",
"{",
"$",
"space",
"=",
"'[\\x09\\x20]+'",
";",
"$",
"day_name",
"=",
"$",
"this",
"->",
"day_pcre",
";",
"$",
"month",
"=",
"$",
"this",
"->",
"month_pcre",
";",
"$",
"day",
"=",
"'([0-9]{1,2})'",
";",
"$",
"year",
"=",
"$",
"hour",
"=",
"$",
"minute",
"=",
"$",
"second",
"=",
"'([0-9]{2})'",
";",
"$",
"zone",
"=",
"'([A-Z]{1,5})'",
";",
"$",
"pcre",
"=",
"'/^'",
".",
"$",
"day_name",
".",
"','",
".",
"$",
"space",
".",
"$",
"day",
".",
"'-'",
".",
"$",
"month",
".",
"'-'",
".",
"$",
"year",
".",
"$",
"space",
".",
"$",
"hour",
".",
"':'",
".",
"$",
"minute",
".",
"':'",
".",
"$",
"second",
".",
"$",
"space",
".",
"$",
"zone",
".",
"'$/i'",
";",
"}",
"if",
"(",
"preg_match",
"(",
"$",
"pcre",
",",
"$",
"date",
",",
"$",
"match",
")",
")",
"{",
"/*\n\t\t\tCapturing subpatterns:\n\t\t\t1: Day name\n\t\t\t2: Day\n\t\t\t3: Month\n\t\t\t4: Year\n\t\t\t5: Hour\n\t\t\t6: Minute\n\t\t\t7: Second\n\t\t\t8: Timezone\n\t\t\t*/",
"// Month",
"$",
"month",
"=",
"$",
"this",
"->",
"month",
"[",
"strtolower",
"(",
"$",
"match",
"[",
"3",
"]",
")",
"]",
";",
"// Character timezone",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"timezone",
"[",
"strtoupper",
"(",
"$",
"match",
"[",
"8",
"]",
")",
"]",
")",
")",
"{",
"$",
"timezone",
"=",
"$",
"this",
"->",
"timezone",
"[",
"strtoupper",
"(",
"$",
"match",
"[",
"8",
"]",
")",
"]",
";",
"}",
"// Assume everything else to be -0000",
"else",
"{",
"$",
"timezone",
"=",
"0",
";",
"}",
"// Deal with 2 digit year",
"if",
"(",
"$",
"match",
"[",
"4",
"]",
"<",
"50",
")",
"{",
"$",
"match",
"[",
"4",
"]",
"+=",
"2000",
";",
"}",
"else",
"{",
"$",
"match",
"[",
"4",
"]",
"+=",
"1900",
";",
"}",
"return",
"gmmktime",
"(",
"$",
"match",
"[",
"5",
"]",
",",
"$",
"match",
"[",
"6",
"]",
",",
"$",
"match",
"[",
"7",
"]",
",",
"$",
"month",
",",
"$",
"match",
"[",
"2",
"]",
",",
"$",
"match",
"[",
"4",
"]",
")",
"-",
"$",
"timezone",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Parse RFC850's date format
@access protected
@return int Timestamp | [
"Parse",
"RFC850",
"s",
"date",
"format"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/Parse/Date.php#L863-L920 |
211,907 | moodle/moodle | mod/data/mod_form.php | mod_data_mod_form.data_preprocessing | public function data_preprocessing(&$defaultvalues) {
parent::data_preprocessing($defaultvalues);
$defaultvalues['completionentriesenabled'] = !empty($defaultvalues['completionentries']) ? 1 : 0;
if (empty($defaultvalues['completionentries'])) {
$defaultvalues['completionentries'] = 1;
}
} | php | public function data_preprocessing(&$defaultvalues) {
parent::data_preprocessing($defaultvalues);
$defaultvalues['completionentriesenabled'] = !empty($defaultvalues['completionentries']) ? 1 : 0;
if (empty($defaultvalues['completionentries'])) {
$defaultvalues['completionentries'] = 1;
}
} | [
"public",
"function",
"data_preprocessing",
"(",
"&",
"$",
"defaultvalues",
")",
"{",
"parent",
"::",
"data_preprocessing",
"(",
"$",
"defaultvalues",
")",
";",
"$",
"defaultvalues",
"[",
"'completionentriesenabled'",
"]",
"=",
"!",
"empty",
"(",
"$",
"defaultvalues",
"[",
"'completionentries'",
"]",
")",
"?",
"1",
":",
"0",
";",
"if",
"(",
"empty",
"(",
"$",
"defaultvalues",
"[",
"'completionentries'",
"]",
")",
")",
"{",
"$",
"defaultvalues",
"[",
"'completionentries'",
"]",
"=",
"1",
";",
"}",
"}"
] | Set up the completion checkbox which is not part of standard data.
@param array $defaultvalues | [
"Set",
"up",
"the",
"completion",
"checkbox",
"which",
"is",
"not",
"part",
"of",
"standard",
"data",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/mod_form.php#L153-L159 |
211,908 | moodle/moodle | lib/classes/task/file_temp_cleanup_task.php | file_temp_cleanup_task.execute_on | protected function execute_on($tmpdir) {
global $CFG;
// Default to last weeks time.
$time = time() - ($CFG->tempdatafoldercleanup * 3600);
$dir = new \RecursiveDirectoryIterator($tmpdir);
// Show all child nodes prior to their parent.
$iter = new \RecursiveIteratorIterator($dir, \RecursiveIteratorIterator::CHILD_FIRST);
// An array of the full path (key) and date last modified.
$modifieddateobject = array();
// Get the time modified for each directory node. Nodes will be updated
// once a file is deleted, so we need a list of the original values.
for ($iter->rewind(); $iter->valid(); $iter->next()) {
$node = $iter->getRealPath();
if (!is_readable($node)) {
continue;
}
$modifieddateobject[$node] = $iter->getMTime();
}
// Now loop through again and remove old files and directories.
for ($iter->rewind(); $iter->valid(); $iter->next()) {
$node = $iter->getRealPath();
if (!is_readable($node)) {
continue;
}
// Check if file or directory is older than the given time.
if ($modifieddateobject[$node] < $time) {
if ($iter->isDir() && !$iter->isDot()) {
// Don't attempt to delete the directory if it isn't empty.
if (!glob($node. DIRECTORY_SEPARATOR . '*')) {
if (@rmdir($node) === false) {
mtrace("Failed removing directory '$node'.");
}
}
}
if ($iter->isFile()) {
if (@unlink($node) === false) {
mtrace("Failed removing file '$node'.");
}
}
} else {
// Return the time modified to the original date only for real files.
if ($iter->isDir() && !$iter->isDot()) {
touch($node, $modifieddateobject[$node]);
}
}
}
} | php | protected function execute_on($tmpdir) {
global $CFG;
// Default to last weeks time.
$time = time() - ($CFG->tempdatafoldercleanup * 3600);
$dir = new \RecursiveDirectoryIterator($tmpdir);
// Show all child nodes prior to their parent.
$iter = new \RecursiveIteratorIterator($dir, \RecursiveIteratorIterator::CHILD_FIRST);
// An array of the full path (key) and date last modified.
$modifieddateobject = array();
// Get the time modified for each directory node. Nodes will be updated
// once a file is deleted, so we need a list of the original values.
for ($iter->rewind(); $iter->valid(); $iter->next()) {
$node = $iter->getRealPath();
if (!is_readable($node)) {
continue;
}
$modifieddateobject[$node] = $iter->getMTime();
}
// Now loop through again and remove old files and directories.
for ($iter->rewind(); $iter->valid(); $iter->next()) {
$node = $iter->getRealPath();
if (!is_readable($node)) {
continue;
}
// Check if file or directory is older than the given time.
if ($modifieddateobject[$node] < $time) {
if ($iter->isDir() && !$iter->isDot()) {
// Don't attempt to delete the directory if it isn't empty.
if (!glob($node. DIRECTORY_SEPARATOR . '*')) {
if (@rmdir($node) === false) {
mtrace("Failed removing directory '$node'.");
}
}
}
if ($iter->isFile()) {
if (@unlink($node) === false) {
mtrace("Failed removing file '$node'.");
}
}
} else {
// Return the time modified to the original date only for real files.
if ($iter->isDir() && !$iter->isDot()) {
touch($node, $modifieddateobject[$node]);
}
}
}
} | [
"protected",
"function",
"execute_on",
"(",
"$",
"tmpdir",
")",
"{",
"global",
"$",
"CFG",
";",
"// Default to last weeks time.",
"$",
"time",
"=",
"time",
"(",
")",
"-",
"(",
"$",
"CFG",
"->",
"tempdatafoldercleanup",
"*",
"3600",
")",
";",
"$",
"dir",
"=",
"new",
"\\",
"RecursiveDirectoryIterator",
"(",
"$",
"tmpdir",
")",
";",
"// Show all child nodes prior to their parent.",
"$",
"iter",
"=",
"new",
"\\",
"RecursiveIteratorIterator",
"(",
"$",
"dir",
",",
"\\",
"RecursiveIteratorIterator",
"::",
"CHILD_FIRST",
")",
";",
"// An array of the full path (key) and date last modified.",
"$",
"modifieddateobject",
"=",
"array",
"(",
")",
";",
"// Get the time modified for each directory node. Nodes will be updated",
"// once a file is deleted, so we need a list of the original values.",
"for",
"(",
"$",
"iter",
"->",
"rewind",
"(",
")",
";",
"$",
"iter",
"->",
"valid",
"(",
")",
";",
"$",
"iter",
"->",
"next",
"(",
")",
")",
"{",
"$",
"node",
"=",
"$",
"iter",
"->",
"getRealPath",
"(",
")",
";",
"if",
"(",
"!",
"is_readable",
"(",
"$",
"node",
")",
")",
"{",
"continue",
";",
"}",
"$",
"modifieddateobject",
"[",
"$",
"node",
"]",
"=",
"$",
"iter",
"->",
"getMTime",
"(",
")",
";",
"}",
"// Now loop through again and remove old files and directories.",
"for",
"(",
"$",
"iter",
"->",
"rewind",
"(",
")",
";",
"$",
"iter",
"->",
"valid",
"(",
")",
";",
"$",
"iter",
"->",
"next",
"(",
")",
")",
"{",
"$",
"node",
"=",
"$",
"iter",
"->",
"getRealPath",
"(",
")",
";",
"if",
"(",
"!",
"is_readable",
"(",
"$",
"node",
")",
")",
"{",
"continue",
";",
"}",
"// Check if file or directory is older than the given time.",
"if",
"(",
"$",
"modifieddateobject",
"[",
"$",
"node",
"]",
"<",
"$",
"time",
")",
"{",
"if",
"(",
"$",
"iter",
"->",
"isDir",
"(",
")",
"&&",
"!",
"$",
"iter",
"->",
"isDot",
"(",
")",
")",
"{",
"// Don't attempt to delete the directory if it isn't empty.",
"if",
"(",
"!",
"glob",
"(",
"$",
"node",
".",
"DIRECTORY_SEPARATOR",
".",
"'*'",
")",
")",
"{",
"if",
"(",
"@",
"rmdir",
"(",
"$",
"node",
")",
"===",
"false",
")",
"{",
"mtrace",
"(",
"\"Failed removing directory '$node'.\"",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"iter",
"->",
"isFile",
"(",
")",
")",
"{",
"if",
"(",
"@",
"unlink",
"(",
"$",
"node",
")",
"===",
"false",
")",
"{",
"mtrace",
"(",
"\"Failed removing file '$node'.\"",
")",
";",
"}",
"}",
"}",
"else",
"{",
"// Return the time modified to the original date only for real files.",
"if",
"(",
"$",
"iter",
"->",
"isDir",
"(",
")",
"&&",
"!",
"$",
"iter",
"->",
"isDot",
"(",
")",
")",
"{",
"touch",
"(",
"$",
"node",
",",
"$",
"modifieddateobject",
"[",
"$",
"node",
"]",
")",
";",
"}",
"}",
"}",
"}"
] | Do the job, given the target directory.
@param string $tmpdir The directory hosting the candidate stale temp files. | [
"Do",
"the",
"job",
"given",
"the",
"target",
"directory",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/task/file_temp_cleanup_task.php#L45-L97 |
211,909 | moodle/moodle | repository/dropbox/classes/dropbox.php | dropbox.fetch_dropbox_data | protected function fetch_dropbox_data($endpoint, $data = []) {
$url = $this->get_api_endpoint($endpoint);
$this->cleanopt();
$this->resetHeader();
if ($data === null) {
// Some API endpoints explicitly expect a data submission of 'null'.
$options['CURLOPT_POSTFIELDS'] = 'null';
} else {
$options['CURLOPT_POSTFIELDS'] = json_encode($data);
}
$options['CURLOPT_POST'] = 1;
$this->setHeader('Content-Type: application/json');
$response = $this->request($url, $options);
$result = json_decode($response);
$this->check_and_handle_api_errors($result);
if ($this->has_additional_results($result)) {
// Any API endpoint returning 'has_more' will provide a cursor, and also have a matching endpoint suffixed
// with /continue which takes that cursor.
if (preg_match('_/continue$_', $endpoint) === 0) {
// Only add /continue if it is not already present.
$endpoint .= '/continue';
}
// Fetch the next page of results.
$additionaldata = $this->fetch_dropbox_data($endpoint, [
'cursor' => $result->cursor,
]);
// Merge the list of entries.
$result->entries = array_merge($result->entries, $additionaldata->entries);
}
if (isset($result->has_more)) {
// Unset the cursor and has_more flags.
unset($result->cursor);
unset($result->has_more);
}
return $result;
} | php | protected function fetch_dropbox_data($endpoint, $data = []) {
$url = $this->get_api_endpoint($endpoint);
$this->cleanopt();
$this->resetHeader();
if ($data === null) {
// Some API endpoints explicitly expect a data submission of 'null'.
$options['CURLOPT_POSTFIELDS'] = 'null';
} else {
$options['CURLOPT_POSTFIELDS'] = json_encode($data);
}
$options['CURLOPT_POST'] = 1;
$this->setHeader('Content-Type: application/json');
$response = $this->request($url, $options);
$result = json_decode($response);
$this->check_and_handle_api_errors($result);
if ($this->has_additional_results($result)) {
// Any API endpoint returning 'has_more' will provide a cursor, and also have a matching endpoint suffixed
// with /continue which takes that cursor.
if (preg_match('_/continue$_', $endpoint) === 0) {
// Only add /continue if it is not already present.
$endpoint .= '/continue';
}
// Fetch the next page of results.
$additionaldata = $this->fetch_dropbox_data($endpoint, [
'cursor' => $result->cursor,
]);
// Merge the list of entries.
$result->entries = array_merge($result->entries, $additionaldata->entries);
}
if (isset($result->has_more)) {
// Unset the cursor and has_more flags.
unset($result->cursor);
unset($result->has_more);
}
return $result;
} | [
"protected",
"function",
"fetch_dropbox_data",
"(",
"$",
"endpoint",
",",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"get_api_endpoint",
"(",
"$",
"endpoint",
")",
";",
"$",
"this",
"->",
"cleanopt",
"(",
")",
";",
"$",
"this",
"->",
"resetHeader",
"(",
")",
";",
"if",
"(",
"$",
"data",
"===",
"null",
")",
"{",
"// Some API endpoints explicitly expect a data submission of 'null'.",
"$",
"options",
"[",
"'CURLOPT_POSTFIELDS'",
"]",
"=",
"'null'",
";",
"}",
"else",
"{",
"$",
"options",
"[",
"'CURLOPT_POSTFIELDS'",
"]",
"=",
"json_encode",
"(",
"$",
"data",
")",
";",
"}",
"$",
"options",
"[",
"'CURLOPT_POST'",
"]",
"=",
"1",
";",
"$",
"this",
"->",
"setHeader",
"(",
"'Content-Type: application/json'",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"request",
"(",
"$",
"url",
",",
"$",
"options",
")",
";",
"$",
"result",
"=",
"json_decode",
"(",
"$",
"response",
")",
";",
"$",
"this",
"->",
"check_and_handle_api_errors",
"(",
"$",
"result",
")",
";",
"if",
"(",
"$",
"this",
"->",
"has_additional_results",
"(",
"$",
"result",
")",
")",
"{",
"// Any API endpoint returning 'has_more' will provide a cursor, and also have a matching endpoint suffixed",
"// with /continue which takes that cursor.",
"if",
"(",
"preg_match",
"(",
"'_/continue$_'",
",",
"$",
"endpoint",
")",
"===",
"0",
")",
"{",
"// Only add /continue if it is not already present.",
"$",
"endpoint",
".=",
"'/continue'",
";",
"}",
"// Fetch the next page of results.",
"$",
"additionaldata",
"=",
"$",
"this",
"->",
"fetch_dropbox_data",
"(",
"$",
"endpoint",
",",
"[",
"'cursor'",
"=>",
"$",
"result",
"->",
"cursor",
",",
"]",
")",
";",
"// Merge the list of entries.",
"$",
"result",
"->",
"entries",
"=",
"array_merge",
"(",
"$",
"result",
"->",
"entries",
",",
"$",
"additionaldata",
"->",
"entries",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"result",
"->",
"has_more",
")",
")",
"{",
"// Unset the cursor and has_more flags.",
"unset",
"(",
"$",
"result",
"->",
"cursor",
")",
";",
"unset",
"(",
"$",
"result",
"->",
"has_more",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Make an API call against the specified endpoint with supplied data.
@param string $endpoint The endpoint to be contacted
@param array $data Any data to pass to the endpoint
@return object Content decoded from the endpoint | [
"Make",
"an",
"API",
"call",
"against",
"the",
"specified",
"endpoint",
"with",
"supplied",
"data",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/dropbox/classes/dropbox.php#L97-L140 |
211,910 | moodle/moodle | repository/dropbox/classes/dropbox.php | dropbox.fetch_dropbox_content | protected function fetch_dropbox_content($endpoint, $data = []) {
$url = $this->get_content_endpoint($endpoint);
$this->cleanopt();
$this->resetHeader();
$options['CURLOPT_POST'] = 1;
$this->setHeader('Content-Type: ');
$this->setHeader('Dropbox-API-Arg: ' . json_encode($data));
$response = $this->request($url, $options);
$this->check_and_handle_api_errors($response);
return $response;
} | php | protected function fetch_dropbox_content($endpoint, $data = []) {
$url = $this->get_content_endpoint($endpoint);
$this->cleanopt();
$this->resetHeader();
$options['CURLOPT_POST'] = 1;
$this->setHeader('Content-Type: ');
$this->setHeader('Dropbox-API-Arg: ' . json_encode($data));
$response = $this->request($url, $options);
$this->check_and_handle_api_errors($response);
return $response;
} | [
"protected",
"function",
"fetch_dropbox_content",
"(",
"$",
"endpoint",
",",
"$",
"data",
"=",
"[",
"]",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"get_content_endpoint",
"(",
"$",
"endpoint",
")",
";",
"$",
"this",
"->",
"cleanopt",
"(",
")",
";",
"$",
"this",
"->",
"resetHeader",
"(",
")",
";",
"$",
"options",
"[",
"'CURLOPT_POST'",
"]",
"=",
"1",
";",
"$",
"this",
"->",
"setHeader",
"(",
"'Content-Type: '",
")",
";",
"$",
"this",
"->",
"setHeader",
"(",
"'Dropbox-API-Arg: '",
".",
"json_encode",
"(",
"$",
"data",
")",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"request",
"(",
"$",
"url",
",",
"$",
"options",
")",
";",
"$",
"this",
"->",
"check_and_handle_api_errors",
"(",
"$",
"response",
")",
";",
"return",
"$",
"response",
";",
"}"
] | Fetch content from the specified endpoint with the supplied data.
@param string $endpoint The endpoint to be contacted
@param array $data Any data to pass to the endpoint
@return string The returned data | [
"Fetch",
"content",
"from",
"the",
"specified",
"endpoint",
"with",
"the",
"supplied",
"data",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/dropbox/classes/dropbox.php#L159-L172 |
211,911 | moodle/moodle | repository/dropbox/classes/dropbox.php | dropbox.check_and_handle_api_errors | protected function check_and_handle_api_errors($data) {
if ($this->info['http_code'] == 200) {
// Dropbox only returns errors on non-200 response codes.
return;
}
switch($this->info['http_code']) {
case 400:
// Bad input parameter. Error message should indicate which one and why.
throw new \coding_exception('Invalid input parameter passed to DropBox API.');
break;
case 401:
// Bad or expired token. This can happen if the access token is expired or if the access token has been
// revoked by Dropbox or the user. To fix this, you should re-authenticate the user.
throw new authentication_exception('Authentication token expired');
break;
case 409:
// Endpoint-specific error. Look to the JSON response body for the specifics of the error.
throw new \coding_exception('Endpoint specific error: ' . $data->error_summary);
break;
case 429:
// Your app is making too many requests for the given user or team and is being rate limited. Your app
// should wait for the number of seconds specified in the "Retry-After" response header before trying
// again.
throw new rate_limit_exception();
break;
default:
break;
}
if ($this->info['http_code'] >= 500 && $this->info['http_code'] < 600) {
throw new \invalid_response_exception($this->info['http_code'] . ": " . $data);
}
} | php | protected function check_and_handle_api_errors($data) {
if ($this->info['http_code'] == 200) {
// Dropbox only returns errors on non-200 response codes.
return;
}
switch($this->info['http_code']) {
case 400:
// Bad input parameter. Error message should indicate which one and why.
throw new \coding_exception('Invalid input parameter passed to DropBox API.');
break;
case 401:
// Bad or expired token. This can happen if the access token is expired or if the access token has been
// revoked by Dropbox or the user. To fix this, you should re-authenticate the user.
throw new authentication_exception('Authentication token expired');
break;
case 409:
// Endpoint-specific error. Look to the JSON response body for the specifics of the error.
throw new \coding_exception('Endpoint specific error: ' . $data->error_summary);
break;
case 429:
// Your app is making too many requests for the given user or team and is being rate limited. Your app
// should wait for the number of seconds specified in the "Retry-After" response header before trying
// again.
throw new rate_limit_exception();
break;
default:
break;
}
if ($this->info['http_code'] >= 500 && $this->info['http_code'] < 600) {
throw new \invalid_response_exception($this->info['http_code'] . ": " . $data);
}
} | [
"protected",
"function",
"check_and_handle_api_errors",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"info",
"[",
"'http_code'",
"]",
"==",
"200",
")",
"{",
"// Dropbox only returns errors on non-200 response codes.",
"return",
";",
"}",
"switch",
"(",
"$",
"this",
"->",
"info",
"[",
"'http_code'",
"]",
")",
"{",
"case",
"400",
":",
"// Bad input parameter. Error message should indicate which one and why.",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Invalid input parameter passed to DropBox API.'",
")",
";",
"break",
";",
"case",
"401",
":",
"// Bad or expired token. This can happen if the access token is expired or if the access token has been",
"// revoked by Dropbox or the user. To fix this, you should re-authenticate the user.",
"throw",
"new",
"authentication_exception",
"(",
"'Authentication token expired'",
")",
";",
"break",
";",
"case",
"409",
":",
"// Endpoint-specific error. Look to the JSON response body for the specifics of the error.",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Endpoint specific error: '",
".",
"$",
"data",
"->",
"error_summary",
")",
";",
"break",
";",
"case",
"429",
":",
"// Your app is making too many requests for the given user or team and is being rate limited. Your app",
"// should wait for the number of seconds specified in the \"Retry-After\" response header before trying",
"// again.",
"throw",
"new",
"rate_limit_exception",
"(",
")",
";",
"break",
";",
"default",
":",
"break",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"info",
"[",
"'http_code'",
"]",
">=",
"500",
"&&",
"$",
"this",
"->",
"info",
"[",
"'http_code'",
"]",
"<",
"600",
")",
"{",
"throw",
"new",
"\\",
"invalid_response_exception",
"(",
"$",
"this",
"->",
"info",
"[",
"'http_code'",
"]",
".",
"\": \"",
".",
"$",
"data",
")",
";",
"}",
"}"
] | Check for an attempt to handle API errors.
This function attempts to deal with errors as per
https://www.dropbox.com/developers/documentation/http/documentation#error-handling.
@param mixed $data The returned content.
@throws moodle_exception | [
"Check",
"for",
"an",
"attempt",
"to",
"handle",
"API",
"errors",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/dropbox/classes/dropbox.php#L183-L216 |
211,912 | moodle/moodle | repository/dropbox/classes/dropbox.php | dropbox.get_file_share_info | public function get_file_share_info($id) {
// Attempt to fetch any existing shared link first.
$data = $this->fetch_dropbox_data('sharing/list_shared_links', [
'path' => $id,
]);
if (isset($data->links)) {
$link = reset($data->links);
if (isset($link->{".tag"}) && $link->{".tag"} === "file") {
return $this->normalize_file_share_info($link);
}
}
// No existing link available.
// Create a new one.
$link = $this->fetch_dropbox_data('sharing/create_shared_link_with_settings', [
'path' => $id,
'settings' => [
'requested_visibility' => 'public',
],
]);
if (isset($link->{".tag"}) && $link->{".tag"} === "file") {
return $this->normalize_file_share_info($link);
}
// Some kind of error we don't know how to handle at this stage.
return null;
} | php | public function get_file_share_info($id) {
// Attempt to fetch any existing shared link first.
$data = $this->fetch_dropbox_data('sharing/list_shared_links', [
'path' => $id,
]);
if (isset($data->links)) {
$link = reset($data->links);
if (isset($link->{".tag"}) && $link->{".tag"} === "file") {
return $this->normalize_file_share_info($link);
}
}
// No existing link available.
// Create a new one.
$link = $this->fetch_dropbox_data('sharing/create_shared_link_with_settings', [
'path' => $id,
'settings' => [
'requested_visibility' => 'public',
],
]);
if (isset($link->{".tag"}) && $link->{".tag"} === "file") {
return $this->normalize_file_share_info($link);
}
// Some kind of error we don't know how to handle at this stage.
return null;
} | [
"public",
"function",
"get_file_share_info",
"(",
"$",
"id",
")",
"{",
"// Attempt to fetch any existing shared link first.",
"$",
"data",
"=",
"$",
"this",
"->",
"fetch_dropbox_data",
"(",
"'sharing/list_shared_links'",
",",
"[",
"'path'",
"=>",
"$",
"id",
",",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"->",
"links",
")",
")",
"{",
"$",
"link",
"=",
"reset",
"(",
"$",
"data",
"->",
"links",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"link",
"->",
"{",
"\".tag\"",
"}",
")",
"&&",
"$",
"link",
"->",
"{",
"\".tag\"",
"}",
"===",
"\"file\"",
")",
"{",
"return",
"$",
"this",
"->",
"normalize_file_share_info",
"(",
"$",
"link",
")",
";",
"}",
"}",
"// No existing link available.",
"// Create a new one.",
"$",
"link",
"=",
"$",
"this",
"->",
"fetch_dropbox_data",
"(",
"'sharing/create_shared_link_with_settings'",
",",
"[",
"'path'",
"=>",
"$",
"id",
",",
"'settings'",
"=>",
"[",
"'requested_visibility'",
"=>",
"'public'",
",",
"]",
",",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"link",
"->",
"{",
"\".tag\"",
"}",
")",
"&&",
"$",
"link",
"->",
"{",
"\".tag\"",
"}",
"===",
"\"file\"",
")",
"{",
"return",
"$",
"this",
"->",
"normalize_file_share_info",
"(",
"$",
"link",
")",
";",
"}",
"// Some kind of error we don't know how to handle at this stage.",
"return",
"null",
";",
"}"
] | Fetch a valid public share link for the specified file.
@param string $id The file path or file id of the file to fetch information for.
@return object An object containing the id, path, size, and URL of the entry | [
"Fetch",
"a",
"valid",
"public",
"share",
"link",
"for",
"the",
"specified",
"file",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/dropbox/classes/dropbox.php#L303-L331 |
211,913 | moodle/moodle | lib/phpexcel/PHPExcel/Writer/Excel2007/Drawing.php | PHPExcel_Writer_Excel2007_Drawing.allDrawings | public function allDrawings(PHPExcel $pPHPExcel = null)
{
// Get an array of all drawings
$aDrawings = array();
// Loop through PHPExcel
$sheetCount = $pPHPExcel->getSheetCount();
for ($i = 0; $i < $sheetCount; ++$i) {
// Loop through images and add to array
$iterator = $pPHPExcel->getSheet($i)->getDrawingCollection()->getIterator();
while ($iterator->valid()) {
$aDrawings[] = $iterator->current();
$iterator->next();
}
}
return $aDrawings;
} | php | public function allDrawings(PHPExcel $pPHPExcel = null)
{
// Get an array of all drawings
$aDrawings = array();
// Loop through PHPExcel
$sheetCount = $pPHPExcel->getSheetCount();
for ($i = 0; $i < $sheetCount; ++$i) {
// Loop through images and add to array
$iterator = $pPHPExcel->getSheet($i)->getDrawingCollection()->getIterator();
while ($iterator->valid()) {
$aDrawings[] = $iterator->current();
$iterator->next();
}
}
return $aDrawings;
} | [
"public",
"function",
"allDrawings",
"(",
"PHPExcel",
"$",
"pPHPExcel",
"=",
"null",
")",
"{",
"// Get an array of all drawings",
"$",
"aDrawings",
"=",
"array",
"(",
")",
";",
"// Loop through PHPExcel",
"$",
"sheetCount",
"=",
"$",
"pPHPExcel",
"->",
"getSheetCount",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"sheetCount",
";",
"++",
"$",
"i",
")",
"{",
"// Loop through images and add to array",
"$",
"iterator",
"=",
"$",
"pPHPExcel",
"->",
"getSheet",
"(",
"$",
"i",
")",
"->",
"getDrawingCollection",
"(",
")",
"->",
"getIterator",
"(",
")",
";",
"while",
"(",
"$",
"iterator",
"->",
"valid",
"(",
")",
")",
"{",
"$",
"aDrawings",
"[",
"]",
"=",
"$",
"iterator",
"->",
"current",
"(",
")",
";",
"$",
"iterator",
"->",
"next",
"(",
")",
";",
"}",
"}",
"return",
"$",
"aDrawings",
";",
"}"
] | Get an array of all drawings
@param PHPExcel $pPHPExcel
@return PHPExcel_Worksheet_Drawing[] All drawings in PHPExcel
@throws PHPExcel_Writer_Exception | [
"Get",
"an",
"array",
"of",
"all",
"drawings"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Writer/Excel2007/Drawing.php#L570-L588 |
211,914 | moodle/moodle | mod/forum/classes/local/factories/builder.php | builder.get_exported_posts_builder | public function get_exported_posts_builder() : exported_posts_builder {
return new exported_posts_builder(
$this->rendererbase,
$this->legacydatamapperfactory,
$this->exporterfactory,
$this->vaultfactory,
$this->managerfactory->get_rating_manager()
);
} | php | public function get_exported_posts_builder() : exported_posts_builder {
return new exported_posts_builder(
$this->rendererbase,
$this->legacydatamapperfactory,
$this->exporterfactory,
$this->vaultfactory,
$this->managerfactory->get_rating_manager()
);
} | [
"public",
"function",
"get_exported_posts_builder",
"(",
")",
":",
"exported_posts_builder",
"{",
"return",
"new",
"exported_posts_builder",
"(",
"$",
"this",
"->",
"rendererbase",
",",
"$",
"this",
"->",
"legacydatamapperfactory",
",",
"$",
"this",
"->",
"exporterfactory",
",",
"$",
"this",
"->",
"vaultfactory",
",",
"$",
"this",
"->",
"managerfactory",
"->",
"get_rating_manager",
"(",
")",
")",
";",
"}"
] | Get an instance of the exported posts builder.
@return exported_posts_builder | [
"Get",
"an",
"instance",
"of",
"the",
"exported",
"posts",
"builder",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/builder.php#L88-L96 |
211,915 | moodle/moodle | mod/forum/classes/local/factories/builder.php | builder.get_exported_discussion_summaries_builder | public function get_exported_discussion_summaries_builder() : exported_discussion_summaries_builder {
return new exported_discussion_summaries_builder(
$this->rendererbase,
$this->legacydatamapperfactory,
$this->exporterfactory,
$this->vaultfactory,
$this->managerfactory
);
} | php | public function get_exported_discussion_summaries_builder() : exported_discussion_summaries_builder {
return new exported_discussion_summaries_builder(
$this->rendererbase,
$this->legacydatamapperfactory,
$this->exporterfactory,
$this->vaultfactory,
$this->managerfactory
);
} | [
"public",
"function",
"get_exported_discussion_summaries_builder",
"(",
")",
":",
"exported_discussion_summaries_builder",
"{",
"return",
"new",
"exported_discussion_summaries_builder",
"(",
"$",
"this",
"->",
"rendererbase",
",",
"$",
"this",
"->",
"legacydatamapperfactory",
",",
"$",
"this",
"->",
"exporterfactory",
",",
"$",
"this",
"->",
"vaultfactory",
",",
"$",
"this",
"->",
"managerfactory",
")",
";",
"}"
] | Get an instance of the exported discussion summaries builder.
@return exported_discussion_summaries_builder | [
"Get",
"an",
"instance",
"of",
"the",
"exported",
"discussion",
"summaries",
"builder",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/builder.php#L103-L111 |
211,916 | moodle/moodle | mod/forum/classes/local/factories/builder.php | builder.get_exported_discussion_builder | public function get_exported_discussion_builder() : exported_discussion_builder {
return new exported_discussion_builder(
$this->rendererbase,
$this->legacydatamapperfactory,
$this->exporterfactory,
$this->vaultfactory,
$this->managerfactory->get_rating_manager()
);
} | php | public function get_exported_discussion_builder() : exported_discussion_builder {
return new exported_discussion_builder(
$this->rendererbase,
$this->legacydatamapperfactory,
$this->exporterfactory,
$this->vaultfactory,
$this->managerfactory->get_rating_manager()
);
} | [
"public",
"function",
"get_exported_discussion_builder",
"(",
")",
":",
"exported_discussion_builder",
"{",
"return",
"new",
"exported_discussion_builder",
"(",
"$",
"this",
"->",
"rendererbase",
",",
"$",
"this",
"->",
"legacydatamapperfactory",
",",
"$",
"this",
"->",
"exporterfactory",
",",
"$",
"this",
"->",
"vaultfactory",
",",
"$",
"this",
"->",
"managerfactory",
"->",
"get_rating_manager",
"(",
")",
")",
";",
"}"
] | Get an instance of the exported discussion builder.
@return exported_discussion_summaries_builder | [
"Get",
"an",
"instance",
"of",
"the",
"exported",
"discussion",
"builder",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/builder.php#L118-L126 |
211,917 | moodle/moodle | lib/htmlpurifier/HTMLPurifier/EntityLookup.php | HTMLPurifier_EntityLookup.setup | public function setup($file = false)
{
if (!$file) {
$file = HTMLPURIFIER_PREFIX . '/HTMLPurifier/EntityLookup/entities.ser';
}
$this->table = unserialize(file_get_contents($file));
} | php | public function setup($file = false)
{
if (!$file) {
$file = HTMLPURIFIER_PREFIX . '/HTMLPurifier/EntityLookup/entities.ser';
}
$this->table = unserialize(file_get_contents($file));
} | [
"public",
"function",
"setup",
"(",
"$",
"file",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"file",
")",
"{",
"$",
"file",
"=",
"HTMLPURIFIER_PREFIX",
".",
"'/HTMLPurifier/EntityLookup/entities.ser'",
";",
"}",
"$",
"this",
"->",
"table",
"=",
"unserialize",
"(",
"file_get_contents",
"(",
"$",
"file",
")",
")",
";",
"}"
] | Sets up the entity lookup table from the serialized file contents.
@param bool $file
@note The serialized contents are versioned, but were generated
using the maintenance script generate_entity_file.php
@warning This is not in constructor to help enforce the Singleton | [
"Sets",
"up",
"the",
"entity",
"lookup",
"table",
"from",
"the",
"serialized",
"file",
"contents",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/EntityLookup.php#L21-L27 |
211,918 | moodle/moodle | admin/tool/usertours/classes/target.php | target.get_target_type | public static function get_target_type(step $step) {
if (!isset(self::$mapping[$step->get_targettype()])) {
throw new \moodle_exception('Unknown Target type');
}
$targettype = self::$mapping[$step->get_targettype()];
return "\\tool_usertours\\local\\target\\{$targettype}";
} | php | public static function get_target_type(step $step) {
if (!isset(self::$mapping[$step->get_targettype()])) {
throw new \moodle_exception('Unknown Target type');
}
$targettype = self::$mapping[$step->get_targettype()];
return "\\tool_usertours\\local\\target\\{$targettype}";
} | [
"public",
"static",
"function",
"get_target_type",
"(",
"step",
"$",
"step",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"mapping",
"[",
"$",
"step",
"->",
"get_targettype",
"(",
")",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'Unknown Target type'",
")",
";",
"}",
"$",
"targettype",
"=",
"self",
"::",
"$",
"mapping",
"[",
"$",
"step",
"->",
"get_targettype",
"(",
")",
"]",
";",
"return",
"\"\\\\tool_usertours\\\\local\\\\target\\\\{$targettype}\"",
";",
"}"
] | Return the instance of the class for this target.
@param step $step The step.
@return target The target instance. | [
"Return",
"the",
"instance",
"of",
"the",
"class",
"for",
"this",
"target",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/target.php#L78-L85 |
211,919 | moodle/moodle | admin/tool/monitor/classes/output/managesubs/renderer.php | renderer.render_rules_link | public function render_rules_link($ruleurl) {
echo \html_writer::start_div();
$a = \html_writer::link($ruleurl, get_string('managerules', 'tool_monitor'));
$link = \html_writer::tag('span', get_string('manageruleslink', 'tool_monitor', $a));
echo $link;
echo \html_writer::end_div();
} | php | public function render_rules_link($ruleurl) {
echo \html_writer::start_div();
$a = \html_writer::link($ruleurl, get_string('managerules', 'tool_monitor'));
$link = \html_writer::tag('span', get_string('manageruleslink', 'tool_monitor', $a));
echo $link;
echo \html_writer::end_div();
} | [
"public",
"function",
"render_rules_link",
"(",
"$",
"ruleurl",
")",
"{",
"echo",
"\\",
"html_writer",
"::",
"start_div",
"(",
")",
";",
"$",
"a",
"=",
"\\",
"html_writer",
"::",
"link",
"(",
"$",
"ruleurl",
",",
"get_string",
"(",
"'managerules'",
",",
"'tool_monitor'",
")",
")",
";",
"$",
"link",
"=",
"\\",
"html_writer",
"::",
"tag",
"(",
"'span'",
",",
"get_string",
"(",
"'manageruleslink'",
",",
"'tool_monitor'",
",",
"$",
"a",
")",
")",
";",
"echo",
"$",
"link",
";",
"echo",
"\\",
"html_writer",
"::",
"end_div",
"(",
")",
";",
"}"
] | Html to add a link to go to the rule manager page.
@param moodle_url $ruleurl The url of the rule manager page.
@return string html for the link to the rule manager page. | [
"Html",
"to",
"add",
"a",
"link",
"to",
"go",
"to",
"the",
"rule",
"manager",
"page",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/output/managesubs/renderer.php#L103-L109 |
211,920 | moodle/moodle | enrol/flatfile/classes/privacy/provider.php | provider.validate_contextlist_contexts | protected static function validate_contextlist_contexts(approved_contextlist $contextlist) {
return array_reduce($contextlist->get_contexts(), function($carry, $context) {
if ($context->contextlevel == CONTEXT_COURSE) {
$carry[] = $context;
}
return $carry;
}, []);
} | php | protected static function validate_contextlist_contexts(approved_contextlist $contextlist) {
return array_reduce($contextlist->get_contexts(), function($carry, $context) {
if ($context->contextlevel == CONTEXT_COURSE) {
$carry[] = $context;
}
return $carry;
}, []);
} | [
"protected",
"static",
"function",
"validate_contextlist_contexts",
"(",
"approved_contextlist",
"$",
"contextlist",
")",
"{",
"return",
"array_reduce",
"(",
"$",
"contextlist",
"->",
"get_contexts",
"(",
")",
",",
"function",
"(",
"$",
"carry",
",",
"$",
"context",
")",
"{",
"if",
"(",
"$",
"context",
"->",
"contextlevel",
"==",
"CONTEXT_COURSE",
")",
"{",
"$",
"carry",
"[",
"]",
"=",
"$",
"context",
";",
"}",
"return",
"$",
"carry",
";",
"}",
",",
"[",
"]",
")",
";",
"}"
] | Simple sanity check on the contextlist contexts, making sure they're of CONTEXT_COURSE contextlevel.
@param approved_contextlist $contextlist
@return array the array of contexts filtered to only include those of CONTEXT_COURSE contextlevel. | [
"Simple",
"sanity",
"check",
"on",
"the",
"contextlist",
"contexts",
"making",
"sure",
"they",
"re",
"of",
"CONTEXT_COURSE",
"contextlevel",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/flatfile/classes/privacy/provider.php#L221-L228 |
211,921 | moodle/moodle | mod/data/classes/search/entry.php | entry.get_doc_url | public function get_doc_url(\core_search\document $doc) {
$entry = $this->get_entry($doc->get('itemid'));
return new \moodle_url('/mod/data/view.php', array( 'd' => $entry->dataid, 'rid' => $entry->id ));
} | php | public function get_doc_url(\core_search\document $doc) {
$entry = $this->get_entry($doc->get('itemid'));
return new \moodle_url('/mod/data/view.php', array( 'd' => $entry->dataid, 'rid' => $entry->id ));
} | [
"public",
"function",
"get_doc_url",
"(",
"\\",
"core_search",
"\\",
"document",
"$",
"doc",
")",
"{",
"$",
"entry",
"=",
"$",
"this",
"->",
"get_entry",
"(",
"$",
"doc",
"->",
"get",
"(",
"'itemid'",
")",
")",
";",
"return",
"new",
"\\",
"moodle_url",
"(",
"'/mod/data/view.php'",
",",
"array",
"(",
"'d'",
"=>",
"$",
"entry",
"->",
"dataid",
",",
"'rid'",
"=>",
"$",
"entry",
"->",
"id",
")",
")",
";",
"}"
] | Link to database entry.
@param \core_search\document $doc
@return \moodle_url | [
"Link",
"to",
"database",
"entry",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/classes/search/entry.php#L194-L197 |
211,922 | moodle/moodle | mod/data/classes/search/entry.php | entry.get_context_url | public function get_context_url(\core_search\document $doc) {
$entry = $this->get_entry($doc->get('itemid'));
return new \moodle_url('/mod/data/view.php', array('d' => $entry->dataid));
} | php | public function get_context_url(\core_search\document $doc) {
$entry = $this->get_entry($doc->get('itemid'));
return new \moodle_url('/mod/data/view.php', array('d' => $entry->dataid));
} | [
"public",
"function",
"get_context_url",
"(",
"\\",
"core_search",
"\\",
"document",
"$",
"doc",
")",
"{",
"$",
"entry",
"=",
"$",
"this",
"->",
"get_entry",
"(",
"$",
"doc",
"->",
"get",
"(",
"'itemid'",
")",
")",
";",
"return",
"new",
"\\",
"moodle_url",
"(",
"'/mod/data/view.php'",
",",
"array",
"(",
"'d'",
"=>",
"$",
"entry",
"->",
"dataid",
")",
")",
";",
"}"
] | Link to the database activity.
@param \core_search\document $doc
@return \moodle_url | [
"Link",
"to",
"the",
"database",
"activity",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/classes/search/entry.php#L205-L208 |
211,923 | moodle/moodle | mod/data/classes/search/entry.php | entry.attach_files | public function attach_files($doc) {
global $DB;
$entryid = $doc->get('itemid');
try {
$entry = $this->get_entry($entryid);
} catch (\dml_missing_record_exception $e) {
debugging('Could not get record to attach files to '.$doc->get('id'), DEBUG_DEVELOPER);
return;
}
$cm = $this->get_cm('data', $entry->dataid, $doc->get('courseid'));
$context = \context_module::instance($cm->id);
// Get the files and attach them.
$fs = get_file_storage();
$files = $fs->get_area_files($context->id, 'mod_data', 'content', $entryid, 'filename', false);
foreach ($files as $file) {
$doc->add_stored_file($file);
}
} | php | public function attach_files($doc) {
global $DB;
$entryid = $doc->get('itemid');
try {
$entry = $this->get_entry($entryid);
} catch (\dml_missing_record_exception $e) {
debugging('Could not get record to attach files to '.$doc->get('id'), DEBUG_DEVELOPER);
return;
}
$cm = $this->get_cm('data', $entry->dataid, $doc->get('courseid'));
$context = \context_module::instance($cm->id);
// Get the files and attach them.
$fs = get_file_storage();
$files = $fs->get_area_files($context->id, 'mod_data', 'content', $entryid, 'filename', false);
foreach ($files as $file) {
$doc->add_stored_file($file);
}
} | [
"public",
"function",
"attach_files",
"(",
"$",
"doc",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"entryid",
"=",
"$",
"doc",
"->",
"get",
"(",
"'itemid'",
")",
";",
"try",
"{",
"$",
"entry",
"=",
"$",
"this",
"->",
"get_entry",
"(",
"$",
"entryid",
")",
";",
"}",
"catch",
"(",
"\\",
"dml_missing_record_exception",
"$",
"e",
")",
"{",
"debugging",
"(",
"'Could not get record to attach files to '",
".",
"$",
"doc",
"->",
"get",
"(",
"'id'",
")",
",",
"DEBUG_DEVELOPER",
")",
";",
"return",
";",
"}",
"$",
"cm",
"=",
"$",
"this",
"->",
"get_cm",
"(",
"'data'",
",",
"$",
"entry",
"->",
"dataid",
",",
"$",
"doc",
"->",
"get",
"(",
"'courseid'",
")",
")",
";",
"$",
"context",
"=",
"\\",
"context_module",
"::",
"instance",
"(",
"$",
"cm",
"->",
"id",
")",
";",
"// Get the files and attach them.",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"$",
"files",
"=",
"$",
"fs",
"->",
"get_area_files",
"(",
"$",
"context",
"->",
"id",
",",
"'mod_data'",
",",
"'content'",
",",
"$",
"entryid",
",",
"'filename'",
",",
"false",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"doc",
"->",
"add_stored_file",
"(",
"$",
"file",
")",
";",
"}",
"}"
] | Add the database entries attachments.
@param \core_search\document $doc
@return void | [
"Add",
"the",
"database",
"entries",
"attachments",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/classes/search/entry.php#L225-L246 |
211,924 | moodle/moodle | mod/data/classes/search/entry.php | entry.get_entry | protected function get_entry($entryid) {
global $DB;
if (empty($this->entriesdata[$entryid])) {
$this->entriesdata[$entryid] = $DB->get_record('data_records', array( 'id' => $entryid ), '*', MUST_EXIST);
}
return $this->entriesdata[$entryid];
} | php | protected function get_entry($entryid) {
global $DB;
if (empty($this->entriesdata[$entryid])) {
$this->entriesdata[$entryid] = $DB->get_record('data_records', array( 'id' => $entryid ), '*', MUST_EXIST);
}
return $this->entriesdata[$entryid];
} | [
"protected",
"function",
"get_entry",
"(",
"$",
"entryid",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"entriesdata",
"[",
"$",
"entryid",
"]",
")",
")",
"{",
"$",
"this",
"->",
"entriesdata",
"[",
"$",
"entryid",
"]",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'data_records'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"entryid",
")",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"}",
"return",
"$",
"this",
"->",
"entriesdata",
"[",
"$",
"entryid",
"]",
";",
"}"
] | Get database entry data
@throws \dml_exception
@param int $entryid
@return stdClass | [
"Get",
"database",
"entry",
"data"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/classes/search/entry.php#L255-L263 |
211,925 | moodle/moodle | mod/data/classes/search/entry.php | entry.get_field_class_name | protected function get_field_class_name($fieldtype) {
global $CFG;
$fieldtype = trim($fieldtype);
require_once($CFG->dirroot . '/mod/data/field/' . $fieldtype . '/field.class.php');
return 'data_field_' . $fieldtype;
} | php | protected function get_field_class_name($fieldtype) {
global $CFG;
$fieldtype = trim($fieldtype);
require_once($CFG->dirroot . '/mod/data/field/' . $fieldtype . '/field.class.php');
return 'data_field_' . $fieldtype;
} | [
"protected",
"function",
"get_field_class_name",
"(",
"$",
"fieldtype",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"fieldtype",
"=",
"trim",
"(",
"$",
"fieldtype",
")",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/mod/data/field/'",
".",
"$",
"fieldtype",
".",
"'/field.class.php'",
")",
";",
"return",
"'data_field_'",
".",
"$",
"fieldtype",
";",
"}"
] | Returns the class name for that field type and includes it.
@param string $fieldtype
@return string | [
"Returns",
"the",
"class",
"name",
"for",
"that",
"field",
"type",
"and",
"includes",
"it",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/classes/search/entry.php#L350-L356 |
211,926 | moodle/moodle | admin/tool/monitor/classes/notification_task.php | notification_task.generate_message | protected function generate_message($subscriptionid, \stdClass $eventobj) {
try {
$subscription = subscription_manager::get_subscription($subscriptionid);
} catch (\dml_exception $e) {
// Race condition, someone deleted the subscription.
return false;
}
$user = \core_user::get_user($subscription->userid);
if (empty($user)) {
// User doesn't exist. Should never happen, nothing to do return.
return false;
}
$context = \context_user::instance($user->id, IGNORE_MISSING);
if ($context === false) {
// User context doesn't exist. Should never happen, nothing to do return.
return false;
}
$template = $subscription->template;
$template = $this->replace_placeholders($template, $subscription, $eventobj, $context);
$htmlmessage = format_text($template, $subscription->templateformat, array('context' => $context));
$msgdata = new \core\message\message();
$msgdata->courseid = empty($subscription->courseid) ? SITEID : $subscription->courseid;
$msgdata->component = 'tool_monitor'; // Your component name.
$msgdata->name = 'notification'; // This is the message name from messages.php.
$msgdata->userfrom = \core_user::get_noreply_user();
$msgdata->userto = $user;
$msgdata->subject = $subscription->get_name($context);
$msgdata->fullmessage = html_to_text($htmlmessage);
$msgdata->fullmessageformat = FORMAT_PLAIN;
$msgdata->fullmessagehtml = $htmlmessage;
$msgdata->smallmessage = '';
$msgdata->notification = 1; // This is only set to 0 for personal messages between users.
return $msgdata;
} | php | protected function generate_message($subscriptionid, \stdClass $eventobj) {
try {
$subscription = subscription_manager::get_subscription($subscriptionid);
} catch (\dml_exception $e) {
// Race condition, someone deleted the subscription.
return false;
}
$user = \core_user::get_user($subscription->userid);
if (empty($user)) {
// User doesn't exist. Should never happen, nothing to do return.
return false;
}
$context = \context_user::instance($user->id, IGNORE_MISSING);
if ($context === false) {
// User context doesn't exist. Should never happen, nothing to do return.
return false;
}
$template = $subscription->template;
$template = $this->replace_placeholders($template, $subscription, $eventobj, $context);
$htmlmessage = format_text($template, $subscription->templateformat, array('context' => $context));
$msgdata = new \core\message\message();
$msgdata->courseid = empty($subscription->courseid) ? SITEID : $subscription->courseid;
$msgdata->component = 'tool_monitor'; // Your component name.
$msgdata->name = 'notification'; // This is the message name from messages.php.
$msgdata->userfrom = \core_user::get_noreply_user();
$msgdata->userto = $user;
$msgdata->subject = $subscription->get_name($context);
$msgdata->fullmessage = html_to_text($htmlmessage);
$msgdata->fullmessageformat = FORMAT_PLAIN;
$msgdata->fullmessagehtml = $htmlmessage;
$msgdata->smallmessage = '';
$msgdata->notification = 1; // This is only set to 0 for personal messages between users.
return $msgdata;
} | [
"protected",
"function",
"generate_message",
"(",
"$",
"subscriptionid",
",",
"\\",
"stdClass",
"$",
"eventobj",
")",
"{",
"try",
"{",
"$",
"subscription",
"=",
"subscription_manager",
"::",
"get_subscription",
"(",
"$",
"subscriptionid",
")",
";",
"}",
"catch",
"(",
"\\",
"dml_exception",
"$",
"e",
")",
"{",
"// Race condition, someone deleted the subscription.",
"return",
"false",
";",
"}",
"$",
"user",
"=",
"\\",
"core_user",
"::",
"get_user",
"(",
"$",
"subscription",
"->",
"userid",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"user",
")",
")",
"{",
"// User doesn't exist. Should never happen, nothing to do return.",
"return",
"false",
";",
"}",
"$",
"context",
"=",
"\\",
"context_user",
"::",
"instance",
"(",
"$",
"user",
"->",
"id",
",",
"IGNORE_MISSING",
")",
";",
"if",
"(",
"$",
"context",
"===",
"false",
")",
"{",
"// User context doesn't exist. Should never happen, nothing to do return.",
"return",
"false",
";",
"}",
"$",
"template",
"=",
"$",
"subscription",
"->",
"template",
";",
"$",
"template",
"=",
"$",
"this",
"->",
"replace_placeholders",
"(",
"$",
"template",
",",
"$",
"subscription",
",",
"$",
"eventobj",
",",
"$",
"context",
")",
";",
"$",
"htmlmessage",
"=",
"format_text",
"(",
"$",
"template",
",",
"$",
"subscription",
"->",
"templateformat",
",",
"array",
"(",
"'context'",
"=>",
"$",
"context",
")",
")",
";",
"$",
"msgdata",
"=",
"new",
"\\",
"core",
"\\",
"message",
"\\",
"message",
"(",
")",
";",
"$",
"msgdata",
"->",
"courseid",
"=",
"empty",
"(",
"$",
"subscription",
"->",
"courseid",
")",
"?",
"SITEID",
":",
"$",
"subscription",
"->",
"courseid",
";",
"$",
"msgdata",
"->",
"component",
"=",
"'tool_monitor'",
";",
"// Your component name.",
"$",
"msgdata",
"->",
"name",
"=",
"'notification'",
";",
"// This is the message name from messages.php.",
"$",
"msgdata",
"->",
"userfrom",
"=",
"\\",
"core_user",
"::",
"get_noreply_user",
"(",
")",
";",
"$",
"msgdata",
"->",
"userto",
"=",
"$",
"user",
";",
"$",
"msgdata",
"->",
"subject",
"=",
"$",
"subscription",
"->",
"get_name",
"(",
"$",
"context",
")",
";",
"$",
"msgdata",
"->",
"fullmessage",
"=",
"html_to_text",
"(",
"$",
"htmlmessage",
")",
";",
"$",
"msgdata",
"->",
"fullmessageformat",
"=",
"FORMAT_PLAIN",
";",
"$",
"msgdata",
"->",
"fullmessagehtml",
"=",
"$",
"htmlmessage",
";",
"$",
"msgdata",
"->",
"smallmessage",
"=",
"''",
";",
"$",
"msgdata",
"->",
"notification",
"=",
"1",
";",
"// This is only set to 0 for personal messages between users.",
"return",
"$",
"msgdata",
";",
"}"
] | Generates the message object for a give subscription and event.
@param int $subscriptionid Subscription instance
@param \stdClass $eventobj Event data
@return false|\stdClass message object | [
"Generates",
"the",
"message",
"object",
"for",
"a",
"give",
"subscription",
"and",
"event",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/notification_task.php#L64-L100 |
211,927 | moodle/moodle | admin/tool/monitor/classes/notification_task.php | notification_task.replace_placeholders | protected function replace_placeholders($template, subscription $subscription, $eventobj, $context) {
$template = str_replace('{link}', $eventobj->link, $template);
if ($eventobj->contextlevel == CONTEXT_MODULE && !empty($eventobj->contextinstanceid)
&& (strpos($template, '{modulelink}') !== false)) {
$cm = get_fast_modinfo($eventobj->courseid)->get_cm($eventobj->contextinstanceid);
$modulelink = $cm->url;
$template = str_replace('{modulelink}', $modulelink, $template);
}
$template = str_replace('{rulename}', $subscription->get_name($context), $template);
$template = str_replace('{description}', $subscription->get_description($context), $template);
$template = str_replace('{eventname}', $subscription->get_event_name(), $template);
return $template;
} | php | protected function replace_placeholders($template, subscription $subscription, $eventobj, $context) {
$template = str_replace('{link}', $eventobj->link, $template);
if ($eventobj->contextlevel == CONTEXT_MODULE && !empty($eventobj->contextinstanceid)
&& (strpos($template, '{modulelink}') !== false)) {
$cm = get_fast_modinfo($eventobj->courseid)->get_cm($eventobj->contextinstanceid);
$modulelink = $cm->url;
$template = str_replace('{modulelink}', $modulelink, $template);
}
$template = str_replace('{rulename}', $subscription->get_name($context), $template);
$template = str_replace('{description}', $subscription->get_description($context), $template);
$template = str_replace('{eventname}', $subscription->get_event_name(), $template);
return $template;
} | [
"protected",
"function",
"replace_placeholders",
"(",
"$",
"template",
",",
"subscription",
"$",
"subscription",
",",
"$",
"eventobj",
",",
"$",
"context",
")",
"{",
"$",
"template",
"=",
"str_replace",
"(",
"'{link}'",
",",
"$",
"eventobj",
"->",
"link",
",",
"$",
"template",
")",
";",
"if",
"(",
"$",
"eventobj",
"->",
"contextlevel",
"==",
"CONTEXT_MODULE",
"&&",
"!",
"empty",
"(",
"$",
"eventobj",
"->",
"contextinstanceid",
")",
"&&",
"(",
"strpos",
"(",
"$",
"template",
",",
"'{modulelink}'",
")",
"!==",
"false",
")",
")",
"{",
"$",
"cm",
"=",
"get_fast_modinfo",
"(",
"$",
"eventobj",
"->",
"courseid",
")",
"->",
"get_cm",
"(",
"$",
"eventobj",
"->",
"contextinstanceid",
")",
";",
"$",
"modulelink",
"=",
"$",
"cm",
"->",
"url",
";",
"$",
"template",
"=",
"str_replace",
"(",
"'{modulelink}'",
",",
"$",
"modulelink",
",",
"$",
"template",
")",
";",
"}",
"$",
"template",
"=",
"str_replace",
"(",
"'{rulename}'",
",",
"$",
"subscription",
"->",
"get_name",
"(",
"$",
"context",
")",
",",
"$",
"template",
")",
";",
"$",
"template",
"=",
"str_replace",
"(",
"'{description}'",
",",
"$",
"subscription",
"->",
"get_description",
"(",
"$",
"context",
")",
",",
"$",
"template",
")",
";",
"$",
"template",
"=",
"str_replace",
"(",
"'{eventname}'",
",",
"$",
"subscription",
"->",
"get_event_name",
"(",
")",
",",
"$",
"template",
")",
";",
"return",
"$",
"template",
";",
"}"
] | Replace place holders in the template with respective content.
@param string $template Message template.
@param subscription $subscription subscription instance
@param \stdclass $eventobj Event data
@param \context $context context object
@return mixed final template string. | [
"Replace",
"place",
"holders",
"in",
"the",
"template",
"with",
"respective",
"content",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/notification_task.php#L112-L125 |
211,928 | moodle/moodle | grade/report/singleview/classes/local/ui/override.php | override.is_disabled | public function is_disabled() {
$lockedgrade = $lockedgradeitem = 0;
if (!empty($this->grade->locked)) {
$lockedgrade = 1;
}
if (!empty($this->grade->grade_item->locked)) {
$lockedgradeitem = 1;
}
return ($lockedgrade || $lockedgradeitem);
} | php | public function is_disabled() {
$lockedgrade = $lockedgradeitem = 0;
if (!empty($this->grade->locked)) {
$lockedgrade = 1;
}
if (!empty($this->grade->grade_item->locked)) {
$lockedgradeitem = 1;
}
return ($lockedgrade || $lockedgradeitem);
} | [
"public",
"function",
"is_disabled",
"(",
")",
"{",
"$",
"lockedgrade",
"=",
"$",
"lockedgradeitem",
"=",
"0",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"grade",
"->",
"locked",
")",
")",
"{",
"$",
"lockedgrade",
"=",
"1",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"grade",
"->",
"grade_item",
"->",
"locked",
")",
")",
"{",
"$",
"lockedgradeitem",
"=",
"1",
";",
"}",
"return",
"(",
"$",
"lockedgrade",
"||",
"$",
"lockedgradeitem",
")",
";",
"}"
] | Is this input disabled
@return bool | [
"Is",
"this",
"input",
"disabled"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/ui/override.php#L55-L64 |
211,929 | moodle/moodle | grade/report/singleview/classes/local/ui/override.php | override.get_label | public function get_label() {
if (!isset($this->grade->label)) {
$this->grade->label = '';
}
return $this->grade->label;
} | php | public function get_label() {
if (!isset($this->grade->label)) {
$this->grade->label = '';
}
return $this->grade->label;
} | [
"public",
"function",
"get_label",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"grade",
"->",
"label",
")",
")",
"{",
"$",
"this",
"->",
"grade",
"->",
"label",
"=",
"''",
";",
"}",
"return",
"$",
"this",
"->",
"grade",
"->",
"label",
";",
"}"
] | Get the label for this form element.
@return string | [
"Get",
"the",
"label",
"for",
"this",
"form",
"element",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/ui/override.php#L71-L76 |
211,930 | moodle/moodle | grade/report/singleview/classes/local/ui/override.php | override.determine_format | public function determine_format() {
if (!$this->grade->grade_item->is_overridable_item()) {
return new empty_element();
}
return new checkbox_attribute(
$this->get_name(),
$this->get_label(),
$this->is_checked(),
$this->is_disabled()
);
} | php | public function determine_format() {
if (!$this->grade->grade_item->is_overridable_item()) {
return new empty_element();
}
return new checkbox_attribute(
$this->get_name(),
$this->get_label(),
$this->is_checked(),
$this->is_disabled()
);
} | [
"public",
"function",
"determine_format",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"grade",
"->",
"grade_item",
"->",
"is_overridable_item",
"(",
")",
")",
"{",
"return",
"new",
"empty_element",
"(",
")",
";",
"}",
"return",
"new",
"checkbox_attribute",
"(",
"$",
"this",
"->",
"get_name",
"(",
")",
",",
"$",
"this",
"->",
"get_label",
"(",
")",
",",
"$",
"this",
"->",
"is_checked",
"(",
")",
",",
"$",
"this",
"->",
"is_disabled",
"(",
")",
")",
";",
"}"
] | Generate the element for this form input.
@return element | [
"Generate",
"the",
"element",
"for",
"this",
"form",
"input",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/ui/override.php#L83-L93 |
211,931 | moodle/moodle | grade/report/singleview/classes/local/ui/override.php | override.set | public function set($value) {
if (empty($this->grade->id)) {
return false;
}
$state = $value == 0 ? false : true;
$this->grade->set_overridden($state);
$this->grade->grade_item->force_regrading();
return false;
} | php | public function set($value) {
if (empty($this->grade->id)) {
return false;
}
$state = $value == 0 ? false : true;
$this->grade->set_overridden($state);
$this->grade->grade_item->force_regrading();
return false;
} | [
"public",
"function",
"set",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"grade",
"->",
"id",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"state",
"=",
"$",
"value",
"==",
"0",
"?",
"false",
":",
"true",
";",
"$",
"this",
"->",
"grade",
"->",
"set_overridden",
"(",
"$",
"state",
")",
";",
"$",
"this",
"->",
"grade",
"->",
"grade_item",
"->",
"force_regrading",
"(",
")",
";",
"return",
"false",
";",
"}"
] | Save the modified value of this form element.
@param string $value The new value to set
@return mixed string|false Any error message | [
"Save",
"the",
"modified",
"value",
"of",
"this",
"form",
"element",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/ui/override.php#L101-L111 |
211,932 | moodle/moodle | blocks/edit_form.php | block_edit_form.is_editing_the_frontpage | public function is_editing_the_frontpage() {
// There are some conditions to check related to contexts.
$ctxconditions = $this->page->context->contextlevel == CONTEXT_COURSE &&
$this->page->context->instanceid == get_site()->id;
$issiteindex = (strpos($this->page->pagetype, 'site-index') === 0);
// So now we can be 100% sure if edition is happening at frontpage.
return ($ctxconditions && $issiteindex);
} | php | public function is_editing_the_frontpage() {
// There are some conditions to check related to contexts.
$ctxconditions = $this->page->context->contextlevel == CONTEXT_COURSE &&
$this->page->context->instanceid == get_site()->id;
$issiteindex = (strpos($this->page->pagetype, 'site-index') === 0);
// So now we can be 100% sure if edition is happening at frontpage.
return ($ctxconditions && $issiteindex);
} | [
"public",
"function",
"is_editing_the_frontpage",
"(",
")",
"{",
"// There are some conditions to check related to contexts.",
"$",
"ctxconditions",
"=",
"$",
"this",
"->",
"page",
"->",
"context",
"->",
"contextlevel",
"==",
"CONTEXT_COURSE",
"&&",
"$",
"this",
"->",
"page",
"->",
"context",
"->",
"instanceid",
"==",
"get_site",
"(",
")",
"->",
"id",
";",
"$",
"issiteindex",
"=",
"(",
"strpos",
"(",
"$",
"this",
"->",
"page",
"->",
"pagetype",
",",
"'site-index'",
")",
"===",
"0",
")",
";",
"// So now we can be 100% sure if edition is happening at frontpage.",
"return",
"(",
"$",
"ctxconditions",
"&&",
"$",
"issiteindex",
")",
";",
"}"
] | Returns true if the user is editing a frontpage.
@return bool | [
"Returns",
"true",
"if",
"the",
"user",
"is",
"editing",
"a",
"frontpage",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/edit_form.php#L242-L249 |
211,933 | moodle/moodle | enrol/database/lib.php | enrol_database_plugin.allow_unenrol_user | public function allow_unenrol_user(stdClass $instance, stdClass $ue) {
if ($ue->status == ENROL_USER_SUSPENDED) {
return true;
}
return false;
} | php | public function allow_unenrol_user(stdClass $instance, stdClass $ue) {
if ($ue->status == ENROL_USER_SUSPENDED) {
return true;
}
return false;
} | [
"public",
"function",
"allow_unenrol_user",
"(",
"stdClass",
"$",
"instance",
",",
"stdClass",
"$",
"ue",
")",
"{",
"if",
"(",
"$",
"ue",
"->",
"status",
"==",
"ENROL_USER_SUSPENDED",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Does this plugin allow manual unenrolment of a specific user?
Yes, but only if user suspended...
@param stdClass $instance course enrol instance
@param stdClass $ue record from user_enrolments table
@return bool - true means user with 'enrol/xxx:unenrol' may unenrol this user, false means nobody may touch this user enrolment | [
"Does",
"this",
"plugin",
"allow",
"manual",
"unenrolment",
"of",
"a",
"specific",
"user?",
"Yes",
"but",
"only",
"if",
"user",
"suspended",
"..."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/database/lib.php#L77-L83 |
211,934 | moodle/moodle | enrol/database/lib.php | enrol_database_plugin.db_init | protected function db_init() {
global $CFG;
require_once($CFG->libdir.'/adodb/adodb.inc.php');
// Connect to the external database (forcing new connection).
$extdb = ADONewConnection($this->get_config('dbtype'));
if ($this->get_config('debugdb')) {
$extdb->debug = true;
ob_start(); // Start output buffer to allow later use of the page headers.
}
// The dbtype my contain the new connection URL, so make sure we are not connected yet.
if (!$extdb->IsConnected()) {
$result = $extdb->Connect($this->get_config('dbhost'), $this->get_config('dbuser'), $this->get_config('dbpass'), $this->get_config('dbname'), true);
if (!$result) {
return null;
}
}
$extdb->SetFetchMode(ADODB_FETCH_ASSOC);
if ($this->get_config('dbsetupsql')) {
$extdb->Execute($this->get_config('dbsetupsql'));
}
return $extdb;
} | php | protected function db_init() {
global $CFG;
require_once($CFG->libdir.'/adodb/adodb.inc.php');
// Connect to the external database (forcing new connection).
$extdb = ADONewConnection($this->get_config('dbtype'));
if ($this->get_config('debugdb')) {
$extdb->debug = true;
ob_start(); // Start output buffer to allow later use of the page headers.
}
// The dbtype my contain the new connection URL, so make sure we are not connected yet.
if (!$extdb->IsConnected()) {
$result = $extdb->Connect($this->get_config('dbhost'), $this->get_config('dbuser'), $this->get_config('dbpass'), $this->get_config('dbname'), true);
if (!$result) {
return null;
}
}
$extdb->SetFetchMode(ADODB_FETCH_ASSOC);
if ($this->get_config('dbsetupsql')) {
$extdb->Execute($this->get_config('dbsetupsql'));
}
return $extdb;
} | [
"protected",
"function",
"db_init",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"libdir",
".",
"'/adodb/adodb.inc.php'",
")",
";",
"// Connect to the external database (forcing new connection).",
"$",
"extdb",
"=",
"ADONewConnection",
"(",
"$",
"this",
"->",
"get_config",
"(",
"'dbtype'",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"get_config",
"(",
"'debugdb'",
")",
")",
"{",
"$",
"extdb",
"->",
"debug",
"=",
"true",
";",
"ob_start",
"(",
")",
";",
"// Start output buffer to allow later use of the page headers.",
"}",
"// The dbtype my contain the new connection URL, so make sure we are not connected yet.",
"if",
"(",
"!",
"$",
"extdb",
"->",
"IsConnected",
"(",
")",
")",
"{",
"$",
"result",
"=",
"$",
"extdb",
"->",
"Connect",
"(",
"$",
"this",
"->",
"get_config",
"(",
"'dbhost'",
")",
",",
"$",
"this",
"->",
"get_config",
"(",
"'dbuser'",
")",
",",
"$",
"this",
"->",
"get_config",
"(",
"'dbpass'",
")",
",",
"$",
"this",
"->",
"get_config",
"(",
"'dbname'",
")",
",",
"true",
")",
";",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"return",
"null",
";",
"}",
"}",
"$",
"extdb",
"->",
"SetFetchMode",
"(",
"ADODB_FETCH_ASSOC",
")",
";",
"if",
"(",
"$",
"this",
"->",
"get_config",
"(",
"'dbsetupsql'",
")",
")",
"{",
"$",
"extdb",
"->",
"Execute",
"(",
"$",
"this",
"->",
"get_config",
"(",
"'dbsetupsql'",
")",
")",
";",
"}",
"return",
"$",
"extdb",
";",
"}"
] | Tries to make connection to the external database.
@return null|ADONewConnection | [
"Tries",
"to",
"make",
"connection",
"to",
"the",
"external",
"database",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/database/lib.php#L853-L878 |
211,935 | moodle/moodle | lib/portfolio/formats/leap2a/lib.php | portfolio_format_leap2a_writer.add_entry | public function add_entry(portfolio_format_leap2a_entry $entry) {
if (array_key_exists($entry->id, $this->entries)) {
if (!($entry instanceof portfolio_format_leap2a_file)) {
throw new portfolio_format_leap2a_exception('leap2a_entryalreadyexists', 'portfolio', '', $entry->id);
}
}
$this->entries[$entry->id] = $entry;
return $entry;
} | php | public function add_entry(portfolio_format_leap2a_entry $entry) {
if (array_key_exists($entry->id, $this->entries)) {
if (!($entry instanceof portfolio_format_leap2a_file)) {
throw new portfolio_format_leap2a_exception('leap2a_entryalreadyexists', 'portfolio', '', $entry->id);
}
}
$this->entries[$entry->id] = $entry;
return $entry;
} | [
"public",
"function",
"add_entry",
"(",
"portfolio_format_leap2a_entry",
"$",
"entry",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"entry",
"->",
"id",
",",
"$",
"this",
"->",
"entries",
")",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"entry",
"instanceof",
"portfolio_format_leap2a_file",
")",
")",
"{",
"throw",
"new",
"portfolio_format_leap2a_exception",
"(",
"'leap2a_entryalreadyexists'",
",",
"'portfolio'",
",",
"''",
",",
"$",
"entry",
"->",
"id",
")",
";",
"}",
"}",
"$",
"this",
"->",
"entries",
"[",
"$",
"entry",
"->",
"id",
"]",
"=",
"$",
"entry",
";",
"return",
"$",
"entry",
";",
"}"
] | Adds a entry to the feed ready to be exported
@param portfolio_format_leap2a_entry $entry new feed entry to add
@return portfolio_format_leap2a_entry | [
"Adds",
"a",
"entry",
"to",
"the",
"feed",
"ready",
"to",
"be",
"exported"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/formats/leap2a/lib.php#L111-L119 |
211,936 | moodle/moodle | lib/portfolio/formats/leap2a/lib.php | portfolio_format_leap2a_writer.make_selection | public function make_selection($selectionentry, $ids, $selectiontype) {
$selectionid = null;
if ($selectionentry instanceof portfolio_format_leap2a_entry) {
$selectionid = $selectionentry->id;
} else if (is_string($selectionentry)) {
$selectionid = $selectionentry;
}
if (!array_key_exists($selectionid, $this->entries)) {
throw new portfolio_format_leap2a_exception('leap2a_invalidentryid', 'portfolio', '', $selectionid);
}
foreach ($ids as $entryid) {
if (!array_key_exists($entryid, $this->entries)) {
throw new portfolio_format_leap2a_exception('leap2a_invalidentryid', 'portfolio', '', $entryid);
}
$this->entries[$selectionid]->add_link($entryid, 'has_part');
$this->entries[$entryid]->add_link($selectionid, 'is_part_of');
}
$this->entries[$selectionid]->add_category($selectiontype, 'selection_type');
if ($this->entries[$selectionid]->type != 'selection') {
debugging(get_string('leap2a_overwritingselection', 'portfolio', $this->entries[$selectionid]->type));
$this->entries[$selectionid]->type = 'selection';
}
} | php | public function make_selection($selectionentry, $ids, $selectiontype) {
$selectionid = null;
if ($selectionentry instanceof portfolio_format_leap2a_entry) {
$selectionid = $selectionentry->id;
} else if (is_string($selectionentry)) {
$selectionid = $selectionentry;
}
if (!array_key_exists($selectionid, $this->entries)) {
throw new portfolio_format_leap2a_exception('leap2a_invalidentryid', 'portfolio', '', $selectionid);
}
foreach ($ids as $entryid) {
if (!array_key_exists($entryid, $this->entries)) {
throw new portfolio_format_leap2a_exception('leap2a_invalidentryid', 'portfolio', '', $entryid);
}
$this->entries[$selectionid]->add_link($entryid, 'has_part');
$this->entries[$entryid]->add_link($selectionid, 'is_part_of');
}
$this->entries[$selectionid]->add_category($selectiontype, 'selection_type');
if ($this->entries[$selectionid]->type != 'selection') {
debugging(get_string('leap2a_overwritingselection', 'portfolio', $this->entries[$selectionid]->type));
$this->entries[$selectionid]->type = 'selection';
}
} | [
"public",
"function",
"make_selection",
"(",
"$",
"selectionentry",
",",
"$",
"ids",
",",
"$",
"selectiontype",
")",
"{",
"$",
"selectionid",
"=",
"null",
";",
"if",
"(",
"$",
"selectionentry",
"instanceof",
"portfolio_format_leap2a_entry",
")",
"{",
"$",
"selectionid",
"=",
"$",
"selectionentry",
"->",
"id",
";",
"}",
"else",
"if",
"(",
"is_string",
"(",
"$",
"selectionentry",
")",
")",
"{",
"$",
"selectionid",
"=",
"$",
"selectionentry",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"selectionid",
",",
"$",
"this",
"->",
"entries",
")",
")",
"{",
"throw",
"new",
"portfolio_format_leap2a_exception",
"(",
"'leap2a_invalidentryid'",
",",
"'portfolio'",
",",
"''",
",",
"$",
"selectionid",
")",
";",
"}",
"foreach",
"(",
"$",
"ids",
"as",
"$",
"entryid",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"entryid",
",",
"$",
"this",
"->",
"entries",
")",
")",
"{",
"throw",
"new",
"portfolio_format_leap2a_exception",
"(",
"'leap2a_invalidentryid'",
",",
"'portfolio'",
",",
"''",
",",
"$",
"entryid",
")",
";",
"}",
"$",
"this",
"->",
"entries",
"[",
"$",
"selectionid",
"]",
"->",
"add_link",
"(",
"$",
"entryid",
",",
"'has_part'",
")",
";",
"$",
"this",
"->",
"entries",
"[",
"$",
"entryid",
"]",
"->",
"add_link",
"(",
"$",
"selectionid",
",",
"'is_part_of'",
")",
";",
"}",
"$",
"this",
"->",
"entries",
"[",
"$",
"selectionid",
"]",
"->",
"add_category",
"(",
"$",
"selectiontype",
",",
"'selection_type'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"entries",
"[",
"$",
"selectionid",
"]",
"->",
"type",
"!=",
"'selection'",
")",
"{",
"debugging",
"(",
"get_string",
"(",
"'leap2a_overwritingselection'",
",",
"'portfolio'",
",",
"$",
"this",
"->",
"entries",
"[",
"$",
"selectionid",
"]",
"->",
"type",
")",
")",
";",
"$",
"this",
"->",
"entries",
"[",
"$",
"selectionid",
"]",
"->",
"type",
"=",
"'selection'",
";",
"}",
"}"
] | Select an entry that has previously been added into the feed
@param portfolio_format_leap2a_entry|string $selectionentry the entry to make a selection (id or entry object)
@param array $ids array of ids this selection includes
@param string $selectiontype for selection type, see: http://wiki.cetis.ac.uk/2009-03/LEAP2A_categories/selection_type | [
"Select",
"an",
"entry",
"that",
"has",
"previously",
"been",
"added",
"into",
"the",
"feed"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/formats/leap2a/lib.php#L128-L150 |
211,937 | moodle/moodle | lib/portfolio/formats/leap2a/lib.php | portfolio_format_leap2a_writer.link_files | public function link_files($entry, $files) {
foreach ($files as $file) {
$fileentry = new portfolio_format_leap2a_file($file->get_filename(), $file);
$this->add_entry($fileentry);
$entry->add_link($fileentry, 'related');
$fileentry->add_link($entry, 'related');
}
} | php | public function link_files($entry, $files) {
foreach ($files as $file) {
$fileentry = new portfolio_format_leap2a_file($file->get_filename(), $file);
$this->add_entry($fileentry);
$entry->add_link($fileentry, 'related');
$fileentry->add_link($entry, 'related');
}
} | [
"public",
"function",
"link_files",
"(",
"$",
"entry",
",",
"$",
"files",
")",
"{",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"fileentry",
"=",
"new",
"portfolio_format_leap2a_file",
"(",
"$",
"file",
"->",
"get_filename",
"(",
")",
",",
"$",
"file",
")",
";",
"$",
"this",
"->",
"add_entry",
"(",
"$",
"fileentry",
")",
";",
"$",
"entry",
"->",
"add_link",
"(",
"$",
"fileentry",
",",
"'related'",
")",
";",
"$",
"fileentry",
"->",
"add_link",
"(",
"$",
"entry",
",",
"'related'",
")",
";",
"}",
"}"
] | Helper function to link some stored_files into the feed and link them to a particular entry
@param portfolio_format_leap2a_entry $entry feed object
@param array $files array of stored_files to link | [
"Helper",
"function",
"to",
"link",
"some",
"stored_files",
"into",
"the",
"feed",
"and",
"link",
"them",
"to",
"a",
"particular",
"entry"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/formats/leap2a/lib.php#L158-L165 |
211,938 | moodle/moodle | lib/portfolio/formats/leap2a/lib.php | portfolio_format_leap2a_writer.validate | private function validate() {
foreach ($this->entries as $entry) {
// first call the entry's own validation method
// which will throw an exception if there's anything wrong
$entry->validate();
// now make sure that all links are in place
foreach ($entry->links as $linkedid => $rel) {
// the linked to entry exists
if (!array_key_exists($linkedid, $this->entries)) {
$a = (object)array('rel' => $rel->type, 'to' => $linkedid, 'from' => $entry->id);
throw new portfolio_format_leap2a_exception('leap2a_nonexistantlink', 'portfolio', '', $a);
}
// and contains a link back to us
if (!array_key_exists($entry->id, $this->entries[$linkedid]->links)) {
}
// we could later check that the reltypes were properly inverse, but nevermind for now.
}
}
} | php | private function validate() {
foreach ($this->entries as $entry) {
// first call the entry's own validation method
// which will throw an exception if there's anything wrong
$entry->validate();
// now make sure that all links are in place
foreach ($entry->links as $linkedid => $rel) {
// the linked to entry exists
if (!array_key_exists($linkedid, $this->entries)) {
$a = (object)array('rel' => $rel->type, 'to' => $linkedid, 'from' => $entry->id);
throw new portfolio_format_leap2a_exception('leap2a_nonexistantlink', 'portfolio', '', $a);
}
// and contains a link back to us
if (!array_key_exists($entry->id, $this->entries[$linkedid]->links)) {
}
// we could later check that the reltypes were properly inverse, but nevermind for now.
}
}
} | [
"private",
"function",
"validate",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"entries",
"as",
"$",
"entry",
")",
"{",
"// first call the entry's own validation method",
"// which will throw an exception if there's anything wrong",
"$",
"entry",
"->",
"validate",
"(",
")",
";",
"// now make sure that all links are in place",
"foreach",
"(",
"$",
"entry",
"->",
"links",
"as",
"$",
"linkedid",
"=>",
"$",
"rel",
")",
"{",
"// the linked to entry exists",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"linkedid",
",",
"$",
"this",
"->",
"entries",
")",
")",
"{",
"$",
"a",
"=",
"(",
"object",
")",
"array",
"(",
"'rel'",
"=>",
"$",
"rel",
"->",
"type",
",",
"'to'",
"=>",
"$",
"linkedid",
",",
"'from'",
"=>",
"$",
"entry",
"->",
"id",
")",
";",
"throw",
"new",
"portfolio_format_leap2a_exception",
"(",
"'leap2a_nonexistantlink'",
",",
"'portfolio'",
",",
"''",
",",
"$",
"a",
")",
";",
"}",
"// and contains a link back to us",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"entry",
"->",
"id",
",",
"$",
"this",
"->",
"entries",
"[",
"$",
"linkedid",
"]",
"->",
"links",
")",
")",
"{",
"}",
"// we could later check that the reltypes were properly inverse, but nevermind for now.",
"}",
"}",
"}"
] | Validate the feed and all entries | [
"Validate",
"the",
"feed",
"and",
"all",
"entries"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/formats/leap2a/lib.php#L170-L189 |
211,939 | moodle/moodle | lib/portfolio/formats/leap2a/lib.php | portfolio_format_leap2a_writer.to_xml | public function to_xml() {
$this->validate();
foreach ($this->entries as $entry) {
$entry->id = 'portfolio:' . $entry->id;
$this->feed->appendChild($entry->to_dom($this->dom, $this->user));
}
return $this->dom->saveXML();
} | php | public function to_xml() {
$this->validate();
foreach ($this->entries as $entry) {
$entry->id = 'portfolio:' . $entry->id;
$this->feed->appendChild($entry->to_dom($this->dom, $this->user));
}
return $this->dom->saveXML();
} | [
"public",
"function",
"to_xml",
"(",
")",
"{",
"$",
"this",
"->",
"validate",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"entries",
"as",
"$",
"entry",
")",
"{",
"$",
"entry",
"->",
"id",
"=",
"'portfolio:'",
".",
"$",
"entry",
"->",
"id",
";",
"$",
"this",
"->",
"feed",
"->",
"appendChild",
"(",
"$",
"entry",
"->",
"to_dom",
"(",
"$",
"this",
"->",
"dom",
",",
"$",
"this",
"->",
"user",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"dom",
"->",
"saveXML",
"(",
")",
";",
"}"
] | Return the entire feed as a string.
Then, it calls for validation
@return string feeds' content in xml | [
"Return",
"the",
"entire",
"feed",
"as",
"a",
"string",
".",
"Then",
"it",
"calls",
"for",
"validation"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/formats/leap2a/lib.php#L197-L204 |
211,940 | moodle/moodle | lib/portfolio/formats/leap2a/lib.php | portfolio_format_leap2a_entry.validate | public function validate() {
foreach ($this->requiredfields as $key) {
if (empty($this->{$key})) {
throw new portfolio_format_leap2a_exception('leap2a_missingfield', 'portfolio', '', $key);
}
}
if ($this->type == 'selection') {
if (count($this->links) == 0) {
throw new portfolio_format_leap2a_exception('leap2a_emptyselection', 'portfolio');
}
//TODO make sure we have a category with a scheme 'selection_type'
}
} | php | public function validate() {
foreach ($this->requiredfields as $key) {
if (empty($this->{$key})) {
throw new portfolio_format_leap2a_exception('leap2a_missingfield', 'portfolio', '', $key);
}
}
if ($this->type == 'selection') {
if (count($this->links) == 0) {
throw new portfolio_format_leap2a_exception('leap2a_emptyselection', 'portfolio');
}
//TODO make sure we have a category with a scheme 'selection_type'
}
} | [
"public",
"function",
"validate",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"requiredfields",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"{",
"$",
"key",
"}",
")",
")",
"{",
"throw",
"new",
"portfolio_format_leap2a_exception",
"(",
"'leap2a_missingfield'",
",",
"'portfolio'",
",",
"''",
",",
"$",
"key",
")",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"type",
"==",
"'selection'",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"links",
")",
"==",
"0",
")",
"{",
"throw",
"new",
"portfolio_format_leap2a_exception",
"(",
"'leap2a_emptyselection'",
",",
"'portfolio'",
")",
";",
"}",
"//TODO make sure we have a category with a scheme 'selection_type'",
"}",
"}"
] | Validate this entry.
At the moment this just makes sure required fields exist
but it could also check things against a list, for example
@todo MDL-31303 - add category with a scheme 'selection_type' | [
"Validate",
"this",
"entry",
".",
"At",
"the",
"moment",
"this",
"just",
"makes",
"sure",
"required",
"fields",
"exist",
"but",
"it",
"could",
"also",
"check",
"things",
"against",
"a",
"list",
"for",
"example"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/formats/leap2a/lib.php#L304-L316 |
211,941 | moodle/moodle | lib/portfolio/formats/leap2a/lib.php | portfolio_format_leap2a_file.add_extra_links | protected function add_extra_links($dom, $entry) {
$link = $dom->createElement('link');
$link->setAttribute('rel', 'enclosure');
$link->setAttribute('href', portfolio_format_leap2a::get_file_directory() . $this->referencedfile->get_filename());
$link->setAttribute('length', $this->referencedfile->get_filesize());
$link->setAttribute('type', $this->referencedfile->get_mimetype());
$entry->appendChild($link);
} | php | protected function add_extra_links($dom, $entry) {
$link = $dom->createElement('link');
$link->setAttribute('rel', 'enclosure');
$link->setAttribute('href', portfolio_format_leap2a::get_file_directory() . $this->referencedfile->get_filename());
$link->setAttribute('length', $this->referencedfile->get_filesize());
$link->setAttribute('type', $this->referencedfile->get_mimetype());
$entry->appendChild($link);
} | [
"protected",
"function",
"add_extra_links",
"(",
"$",
"dom",
",",
"$",
"entry",
")",
"{",
"$",
"link",
"=",
"$",
"dom",
"->",
"createElement",
"(",
"'link'",
")",
";",
"$",
"link",
"->",
"setAttribute",
"(",
"'rel'",
",",
"'enclosure'",
")",
";",
"$",
"link",
"->",
"setAttribute",
"(",
"'href'",
",",
"portfolio_format_leap2a",
"::",
"get_file_directory",
"(",
")",
".",
"$",
"this",
"->",
"referencedfile",
"->",
"get_filename",
"(",
")",
")",
";",
"$",
"link",
"->",
"setAttribute",
"(",
"'length'",
",",
"$",
"this",
"->",
"referencedfile",
"->",
"get_filesize",
"(",
")",
")",
";",
"$",
"link",
"->",
"setAttribute",
"(",
"'type'",
",",
"$",
"this",
"->",
"referencedfile",
"->",
"get_mimetype",
"(",
")",
")",
";",
"$",
"entry",
"->",
"appendChild",
"(",
"$",
"link",
")",
";",
"}"
] | Implement the hook to add extra links to attach the file in an enclosure
@param DomDocument $dom feed object
@param DomDocument $entry feed added link | [
"Implement",
"the",
"hook",
"to",
"add",
"extra",
"links",
"to",
"attach",
"the",
"file",
"in",
"an",
"enclosure"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/formats/leap2a/lib.php#L524-L531 |
211,942 | moodle/moodle | question/classes/statistics/responses/analysis_for_question_all_tries.php | analysis_for_question_all_tries.get_maximum_tries | public function get_maximum_tries() {
$max = 1;
foreach ($this->get_variant_nos() as $variantno) {
foreach ($this->get_subpart_ids($variantno) as $subpartid) {
$max = max($max, $this->get_analysis_for_subpart($variantno, $subpartid)->get_maximum_tries());
}
}
return $max;
} | php | public function get_maximum_tries() {
$max = 1;
foreach ($this->get_variant_nos() as $variantno) {
foreach ($this->get_subpart_ids($variantno) as $subpartid) {
$max = max($max, $this->get_analysis_for_subpart($variantno, $subpartid)->get_maximum_tries());
}
}
return $max;
} | [
"public",
"function",
"get_maximum_tries",
"(",
")",
"{",
"$",
"max",
"=",
"1",
";",
"foreach",
"(",
"$",
"this",
"->",
"get_variant_nos",
"(",
")",
"as",
"$",
"variantno",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"get_subpart_ids",
"(",
"$",
"variantno",
")",
"as",
"$",
"subpartid",
")",
"{",
"$",
"max",
"=",
"max",
"(",
"$",
"max",
",",
"$",
"this",
"->",
"get_analysis_for_subpart",
"(",
"$",
"variantno",
",",
"$",
"subpartid",
")",
"->",
"get_maximum_tries",
"(",
")",
")",
";",
"}",
"}",
"return",
"$",
"max",
";",
"}"
] | What is the highest number of tries at this question?
@return int try number | [
"What",
"is",
"the",
"highest",
"number",
"of",
"tries",
"at",
"this",
"question?"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/responses/analysis_for_question_all_tries.php#L74-L82 |
211,943 | moodle/moodle | mod/page/classes/external.php | mod_page_external.get_pages_by_courses | public static function get_pages_by_courses($courseids = array()) {
$warnings = array();
$returnedpages = array();
$params = array(
'courseids' => $courseids,
);
$params = self::validate_parameters(self::get_pages_by_courses_parameters(), $params);
$mycourses = array();
if (empty($params['courseids'])) {
$mycourses = enrol_get_my_courses();
$params['courseids'] = array_keys($mycourses);
}
// Ensure there are courseids to loop through.
if (!empty($params['courseids'])) {
list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses);
// Get the pages in this course, this function checks users visibility permissions.
// We can avoid then additional validate_context calls.
$pages = get_all_instances_in_courses("page", $courses);
foreach ($pages as $page) {
$context = context_module::instance($page->coursemodule);
// Entry to return.
$page->name = external_format_string($page->name, $context->id);
list($page->intro, $page->introformat) = external_format_text($page->intro,
$page->introformat, $context->id, 'mod_page', 'intro', null);
$page->introfiles = external_util::get_area_files($context->id, 'mod_page', 'intro', false, false);
$options = array('noclean' => true);
list($page->content, $page->contentformat) = external_format_text($page->content, $page->contentformat,
$context->id, 'mod_page', 'content', $page->revision, $options);
$page->contentfiles = external_util::get_area_files($context->id, 'mod_page', 'content');
$returnedpages[] = $page;
}
}
$result = array(
'pages' => $returnedpages,
'warnings' => $warnings
);
return $result;
} | php | public static function get_pages_by_courses($courseids = array()) {
$warnings = array();
$returnedpages = array();
$params = array(
'courseids' => $courseids,
);
$params = self::validate_parameters(self::get_pages_by_courses_parameters(), $params);
$mycourses = array();
if (empty($params['courseids'])) {
$mycourses = enrol_get_my_courses();
$params['courseids'] = array_keys($mycourses);
}
// Ensure there are courseids to loop through.
if (!empty($params['courseids'])) {
list($courses, $warnings) = external_util::validate_courses($params['courseids'], $mycourses);
// Get the pages in this course, this function checks users visibility permissions.
// We can avoid then additional validate_context calls.
$pages = get_all_instances_in_courses("page", $courses);
foreach ($pages as $page) {
$context = context_module::instance($page->coursemodule);
// Entry to return.
$page->name = external_format_string($page->name, $context->id);
list($page->intro, $page->introformat) = external_format_text($page->intro,
$page->introformat, $context->id, 'mod_page', 'intro', null);
$page->introfiles = external_util::get_area_files($context->id, 'mod_page', 'intro', false, false);
$options = array('noclean' => true);
list($page->content, $page->contentformat) = external_format_text($page->content, $page->contentformat,
$context->id, 'mod_page', 'content', $page->revision, $options);
$page->contentfiles = external_util::get_area_files($context->id, 'mod_page', 'content');
$returnedpages[] = $page;
}
}
$result = array(
'pages' => $returnedpages,
'warnings' => $warnings
);
return $result;
} | [
"public",
"static",
"function",
"get_pages_by_courses",
"(",
"$",
"courseids",
"=",
"array",
"(",
")",
")",
"{",
"$",
"warnings",
"=",
"array",
"(",
")",
";",
"$",
"returnedpages",
"=",
"array",
"(",
")",
";",
"$",
"params",
"=",
"array",
"(",
"'courseids'",
"=>",
"$",
"courseids",
",",
")",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_pages_by_courses_parameters",
"(",
")",
",",
"$",
"params",
")",
";",
"$",
"mycourses",
"=",
"array",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"params",
"[",
"'courseids'",
"]",
")",
")",
"{",
"$",
"mycourses",
"=",
"enrol_get_my_courses",
"(",
")",
";",
"$",
"params",
"[",
"'courseids'",
"]",
"=",
"array_keys",
"(",
"$",
"mycourses",
")",
";",
"}",
"// Ensure there are courseids to loop through.",
"if",
"(",
"!",
"empty",
"(",
"$",
"params",
"[",
"'courseids'",
"]",
")",
")",
"{",
"list",
"(",
"$",
"courses",
",",
"$",
"warnings",
")",
"=",
"external_util",
"::",
"validate_courses",
"(",
"$",
"params",
"[",
"'courseids'",
"]",
",",
"$",
"mycourses",
")",
";",
"// Get the pages in this course, this function checks users visibility permissions.",
"// We can avoid then additional validate_context calls.",
"$",
"pages",
"=",
"get_all_instances_in_courses",
"(",
"\"page\"",
",",
"$",
"courses",
")",
";",
"foreach",
"(",
"$",
"pages",
"as",
"$",
"page",
")",
"{",
"$",
"context",
"=",
"context_module",
"::",
"instance",
"(",
"$",
"page",
"->",
"coursemodule",
")",
";",
"// Entry to return.",
"$",
"page",
"->",
"name",
"=",
"external_format_string",
"(",
"$",
"page",
"->",
"name",
",",
"$",
"context",
"->",
"id",
")",
";",
"list",
"(",
"$",
"page",
"->",
"intro",
",",
"$",
"page",
"->",
"introformat",
")",
"=",
"external_format_text",
"(",
"$",
"page",
"->",
"intro",
",",
"$",
"page",
"->",
"introformat",
",",
"$",
"context",
"->",
"id",
",",
"'mod_page'",
",",
"'intro'",
",",
"null",
")",
";",
"$",
"page",
"->",
"introfiles",
"=",
"external_util",
"::",
"get_area_files",
"(",
"$",
"context",
"->",
"id",
",",
"'mod_page'",
",",
"'intro'",
",",
"false",
",",
"false",
")",
";",
"$",
"options",
"=",
"array",
"(",
"'noclean'",
"=>",
"true",
")",
";",
"list",
"(",
"$",
"page",
"->",
"content",
",",
"$",
"page",
"->",
"contentformat",
")",
"=",
"external_format_text",
"(",
"$",
"page",
"->",
"content",
",",
"$",
"page",
"->",
"contentformat",
",",
"$",
"context",
"->",
"id",
",",
"'mod_page'",
",",
"'content'",
",",
"$",
"page",
"->",
"revision",
",",
"$",
"options",
")",
";",
"$",
"page",
"->",
"contentfiles",
"=",
"external_util",
"::",
"get_area_files",
"(",
"$",
"context",
"->",
"id",
",",
"'mod_page'",
",",
"'content'",
")",
";",
"$",
"returnedpages",
"[",
"]",
"=",
"$",
"page",
";",
"}",
"}",
"$",
"result",
"=",
"array",
"(",
"'pages'",
"=>",
"$",
"returnedpages",
",",
"'warnings'",
"=>",
"$",
"warnings",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Returns a list of pages in a provided list of courses.
If no list is provided all pages that the user can view will be returned.
@param array $courseids course ids
@return array of warnings and pages
@since Moodle 3.3 | [
"Returns",
"a",
"list",
"of",
"pages",
"in",
"a",
"provided",
"list",
"of",
"courses",
".",
"If",
"no",
"list",
"is",
"provided",
"all",
"pages",
"that",
"the",
"user",
"can",
"view",
"will",
"be",
"returned",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/page/classes/external.php#L131-L178 |
211,944 | moodle/moodle | admin/tool/recyclebin/classes/task/cleanup_category_bin.php | cleanup_category_bin.execute | public function execute() {
global $DB;
// Check if the category bin is disabled or there is no expiry time.
$lifetime = get_config('tool_recyclebin', 'categorybinexpiry');
if (!\tool_recyclebin\category_bin::is_enabled() || $lifetime <= 0) {
return true;
}
// Get the items we can delete.
$items = $DB->get_recordset_select('tool_recyclebin_category', 'timecreated <= :timecreated',
array('timecreated' => time() - $lifetime));
foreach ($items as $item) {
mtrace("[tool_recyclebin] Deleting item '{$item->id}' from the category recycle bin ...");
$bin = new \tool_recyclebin\category_bin($item->categoryid);
$bin->delete_item($item);
}
$items->close();
return true;
} | php | public function execute() {
global $DB;
// Check if the category bin is disabled or there is no expiry time.
$lifetime = get_config('tool_recyclebin', 'categorybinexpiry');
if (!\tool_recyclebin\category_bin::is_enabled() || $lifetime <= 0) {
return true;
}
// Get the items we can delete.
$items = $DB->get_recordset_select('tool_recyclebin_category', 'timecreated <= :timecreated',
array('timecreated' => time() - $lifetime));
foreach ($items as $item) {
mtrace("[tool_recyclebin] Deleting item '{$item->id}' from the category recycle bin ...");
$bin = new \tool_recyclebin\category_bin($item->categoryid);
$bin->delete_item($item);
}
$items->close();
return true;
} | [
"public",
"function",
"execute",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"// Check if the category bin is disabled or there is no expiry time.",
"$",
"lifetime",
"=",
"get_config",
"(",
"'tool_recyclebin'",
",",
"'categorybinexpiry'",
")",
";",
"if",
"(",
"!",
"\\",
"tool_recyclebin",
"\\",
"category_bin",
"::",
"is_enabled",
"(",
")",
"||",
"$",
"lifetime",
"<=",
"0",
")",
"{",
"return",
"true",
";",
"}",
"// Get the items we can delete.",
"$",
"items",
"=",
"$",
"DB",
"->",
"get_recordset_select",
"(",
"'tool_recyclebin_category'",
",",
"'timecreated <= :timecreated'",
",",
"array",
"(",
"'timecreated'",
"=>",
"time",
"(",
")",
"-",
"$",
"lifetime",
")",
")",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"mtrace",
"(",
"\"[tool_recyclebin] Deleting item '{$item->id}' from the category recycle bin ...\"",
")",
";",
"$",
"bin",
"=",
"new",
"\\",
"tool_recyclebin",
"\\",
"category_bin",
"(",
"$",
"item",
"->",
"categoryid",
")",
";",
"$",
"bin",
"->",
"delete_item",
"(",
"$",
"item",
")",
";",
"}",
"$",
"items",
"->",
"close",
"(",
")",
";",
"return",
"true",
";",
"}"
] | Delete all expired items. | [
"Delete",
"all",
"expired",
"items",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/recyclebin/classes/task/cleanup_category_bin.php#L46-L66 |
211,945 | moodle/moodle | lib/scssphp/Parser.php | Parser.throwParseError | public function throwParseError($msg = 'parse error')
{
list($line, /* $column */) = $this->getSourcePosition($this->count);
$loc = empty($this->sourceName) ? "line: $line" : "$this->sourceName on line $line";
if ($this->peek("(.*?)(\n|$)", $m, $this->count)) {
throw new ParserException("$msg: failed at `$m[1]` $loc");
}
throw new ParserException("$msg: $loc");
} | php | public function throwParseError($msg = 'parse error')
{
list($line, /* $column */) = $this->getSourcePosition($this->count);
$loc = empty($this->sourceName) ? "line: $line" : "$this->sourceName on line $line";
if ($this->peek("(.*?)(\n|$)", $m, $this->count)) {
throw new ParserException("$msg: failed at `$m[1]` $loc");
}
throw new ParserException("$msg: $loc");
} | [
"public",
"function",
"throwParseError",
"(",
"$",
"msg",
"=",
"'parse error'",
")",
"{",
"list",
"(",
"$",
"line",
",",
"/* $column */",
")",
"=",
"$",
"this",
"->",
"getSourcePosition",
"(",
"$",
"this",
"->",
"count",
")",
";",
"$",
"loc",
"=",
"empty",
"(",
"$",
"this",
"->",
"sourceName",
")",
"?",
"\"line: $line\"",
":",
"\"$this->sourceName on line $line\"",
";",
"if",
"(",
"$",
"this",
"->",
"peek",
"(",
"\"(.*?)(\\n|$)\"",
",",
"$",
"m",
",",
"$",
"this",
"->",
"count",
")",
")",
"{",
"throw",
"new",
"ParserException",
"(",
"\"$msg: failed at `$m[1]` $loc\"",
")",
";",
"}",
"throw",
"new",
"ParserException",
"(",
"\"$msg: $loc\"",
")",
";",
"}"
] | Throw parser error
@api
@param string $msg
@throws \Leafo\ScssPhp\Exception\ParserException | [
"Throw",
"parser",
"error"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Parser.php#L121-L132 |
211,946 | moodle/moodle | lib/scssphp/Parser.php | Parser.parseValue | public function parseValue($buffer, &$out)
{
$this->count = 0;
$this->env = null;
$this->inParens = false;
$this->eatWhiteDefault = true;
$this->buffer = (string) $buffer;
$this->saveEncoding();
$list = $this->valueList($out);
$this->restoreEncoding();
return $list;
} | php | public function parseValue($buffer, &$out)
{
$this->count = 0;
$this->env = null;
$this->inParens = false;
$this->eatWhiteDefault = true;
$this->buffer = (string) $buffer;
$this->saveEncoding();
$list = $this->valueList($out);
$this->restoreEncoding();
return $list;
} | [
"public",
"function",
"parseValue",
"(",
"$",
"buffer",
",",
"&",
"$",
"out",
")",
"{",
"$",
"this",
"->",
"count",
"=",
"0",
";",
"$",
"this",
"->",
"env",
"=",
"null",
";",
"$",
"this",
"->",
"inParens",
"=",
"false",
";",
"$",
"this",
"->",
"eatWhiteDefault",
"=",
"true",
";",
"$",
"this",
"->",
"buffer",
"=",
"(",
"string",
")",
"$",
"buffer",
";",
"$",
"this",
"->",
"saveEncoding",
"(",
")",
";",
"$",
"list",
"=",
"$",
"this",
"->",
"valueList",
"(",
"$",
"out",
")",
";",
"$",
"this",
"->",
"restoreEncoding",
"(",
")",
";",
"return",
"$",
"list",
";",
"}"
] | Parse a value or value list
@api
@param string $buffer
@param string $out
@return boolean | [
"Parse",
"a",
"value",
"or",
"value",
"list"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Parser.php#L197-L212 |
211,947 | moodle/moodle | lib/scssphp/Parser.php | Parser.parseSelector | public function parseSelector($buffer, &$out)
{
$this->count = 0;
$this->env = null;
$this->inParens = false;
$this->eatWhiteDefault = true;
$this->buffer = (string) $buffer;
$this->saveEncoding();
$selector = $this->selectors($out);
$this->restoreEncoding();
return $selector;
} | php | public function parseSelector($buffer, &$out)
{
$this->count = 0;
$this->env = null;
$this->inParens = false;
$this->eatWhiteDefault = true;
$this->buffer = (string) $buffer;
$this->saveEncoding();
$selector = $this->selectors($out);
$this->restoreEncoding();
return $selector;
} | [
"public",
"function",
"parseSelector",
"(",
"$",
"buffer",
",",
"&",
"$",
"out",
")",
"{",
"$",
"this",
"->",
"count",
"=",
"0",
";",
"$",
"this",
"->",
"env",
"=",
"null",
";",
"$",
"this",
"->",
"inParens",
"=",
"false",
";",
"$",
"this",
"->",
"eatWhiteDefault",
"=",
"true",
";",
"$",
"this",
"->",
"buffer",
"=",
"(",
"string",
")",
"$",
"buffer",
";",
"$",
"this",
"->",
"saveEncoding",
"(",
")",
";",
"$",
"selector",
"=",
"$",
"this",
"->",
"selectors",
"(",
"$",
"out",
")",
";",
"$",
"this",
"->",
"restoreEncoding",
"(",
")",
";",
"return",
"$",
"selector",
";",
"}"
] | Parse a selector or selector list
@api
@param string $buffer
@param string $out
@return boolean | [
"Parse",
"a",
"selector",
"or",
"selector",
"list"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Parser.php#L224-L239 |
211,948 | moodle/moodle | lib/scssphp/Parser.php | Parser.peek | protected function peek($regex, &$out, $from = null)
{
if (! isset($from)) {
$from = $this->count;
}
$r = '/' . $regex . '/' . $this->patternModifiers;
$result = preg_match($r, $this->buffer, $out, null, $from);
return $result;
} | php | protected function peek($regex, &$out, $from = null)
{
if (! isset($from)) {
$from = $this->count;
}
$r = '/' . $regex . '/' . $this->patternModifiers;
$result = preg_match($r, $this->buffer, $out, null, $from);
return $result;
} | [
"protected",
"function",
"peek",
"(",
"$",
"regex",
",",
"&",
"$",
"out",
",",
"$",
"from",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"from",
")",
")",
"{",
"$",
"from",
"=",
"$",
"this",
"->",
"count",
";",
"}",
"$",
"r",
"=",
"'/'",
".",
"$",
"regex",
".",
"'/'",
".",
"$",
"this",
"->",
"patternModifiers",
";",
"$",
"result",
"=",
"preg_match",
"(",
"$",
"r",
",",
"$",
"this",
"->",
"buffer",
",",
"$",
"out",
",",
"null",
",",
"$",
"from",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Peek input stream
@param string $regex
@param array $out
@param integer $from
@return integer | [
"Peek",
"input",
"stream"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Parser.php#L787-L797 |
211,949 | moodle/moodle | lib/scssphp/Parser.php | Parser.matchString | protected function matchString(&$m, $delim)
{
$token = null;
$end = strlen($this->buffer);
// look for either ending delim, escape, or string interpolation
foreach (['#{', '\\', $delim] as $lookahead) {
$pos = strpos($this->buffer, $lookahead, $this->count);
if ($pos !== false && $pos < $end) {
$end = $pos;
$token = $lookahead;
}
}
if (! isset($token)) {
return false;
}
$match = substr($this->buffer, $this->count, $end - $this->count);
$m = [
$match . $token,
$match,
$token
];
$this->count = $end + strlen($token);
return true;
} | php | protected function matchString(&$m, $delim)
{
$token = null;
$end = strlen($this->buffer);
// look for either ending delim, escape, or string interpolation
foreach (['#{', '\\', $delim] as $lookahead) {
$pos = strpos($this->buffer, $lookahead, $this->count);
if ($pos !== false && $pos < $end) {
$end = $pos;
$token = $lookahead;
}
}
if (! isset($token)) {
return false;
}
$match = substr($this->buffer, $this->count, $end - $this->count);
$m = [
$match . $token,
$match,
$token
];
$this->count = $end + strlen($token);
return true;
} | [
"protected",
"function",
"matchString",
"(",
"&",
"$",
"m",
",",
"$",
"delim",
")",
"{",
"$",
"token",
"=",
"null",
";",
"$",
"end",
"=",
"strlen",
"(",
"$",
"this",
"->",
"buffer",
")",
";",
"// look for either ending delim, escape, or string interpolation",
"foreach",
"(",
"[",
"'#{'",
",",
"'\\\\'",
",",
"$",
"delim",
"]",
"as",
"$",
"lookahead",
")",
"{",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"this",
"->",
"buffer",
",",
"$",
"lookahead",
",",
"$",
"this",
"->",
"count",
")",
";",
"if",
"(",
"$",
"pos",
"!==",
"false",
"&&",
"$",
"pos",
"<",
"$",
"end",
")",
"{",
"$",
"end",
"=",
"$",
"pos",
";",
"$",
"token",
"=",
"$",
"lookahead",
";",
"}",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"token",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"match",
"=",
"substr",
"(",
"$",
"this",
"->",
"buffer",
",",
"$",
"this",
"->",
"count",
",",
"$",
"end",
"-",
"$",
"this",
"->",
"count",
")",
";",
"$",
"m",
"=",
"[",
"$",
"match",
".",
"$",
"token",
",",
"$",
"match",
",",
"$",
"token",
"]",
";",
"$",
"this",
"->",
"count",
"=",
"$",
"end",
"+",
"strlen",
"(",
"$",
"token",
")",
";",
"return",
"true",
";",
"}"
] | Match string looking for either ending delim, escape, or string interpolation
{@internal This is a workaround for preg_match's 250K string match limit. }}
@param array $m Matches (passed by reference)
@param string $delim Delimeter
@return boolean True if match; false otherwise | [
"Match",
"string",
"looking",
"for",
"either",
"ending",
"delim",
"escape",
"or",
"string",
"interpolation"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Parser.php#L827-L856 |
211,950 | moodle/moodle | lib/scssphp/Parser.php | Parser.literal | protected function literal($what, $eatWhitespace = null)
{
if (! isset($eatWhitespace)) {
$eatWhitespace = $this->eatWhiteDefault;
}
$len = strlen($what);
if (strcasecmp(substr($this->buffer, $this->count, $len), $what) === 0) {
$this->count += $len;
if ($eatWhitespace) {
$this->whitespace();
}
return true;
}
return false;
} | php | protected function literal($what, $eatWhitespace = null)
{
if (! isset($eatWhitespace)) {
$eatWhitespace = $this->eatWhiteDefault;
}
$len = strlen($what);
if (strcasecmp(substr($this->buffer, $this->count, $len), $what) === 0) {
$this->count += $len;
if ($eatWhitespace) {
$this->whitespace();
}
return true;
}
return false;
} | [
"protected",
"function",
"literal",
"(",
"$",
"what",
",",
"$",
"eatWhitespace",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"eatWhitespace",
")",
")",
"{",
"$",
"eatWhitespace",
"=",
"$",
"this",
"->",
"eatWhiteDefault",
";",
"}",
"$",
"len",
"=",
"strlen",
"(",
"$",
"what",
")",
";",
"if",
"(",
"strcasecmp",
"(",
"substr",
"(",
"$",
"this",
"->",
"buffer",
",",
"$",
"this",
"->",
"count",
",",
"$",
"len",
")",
",",
"$",
"what",
")",
"===",
"0",
")",
"{",
"$",
"this",
"->",
"count",
"+=",
"$",
"len",
";",
"if",
"(",
"$",
"eatWhitespace",
")",
"{",
"$",
"this",
"->",
"whitespace",
"(",
")",
";",
"}",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Match literal string
@param string $what
@param boolean $eatWhitespace
@return boolean | [
"Match",
"literal",
"string"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Parser.php#L896-L915 |
211,951 | moodle/moodle | lib/scssphp/Parser.php | Parser.whitespace | protected function whitespace()
{
$gotWhite = false;
while (preg_match(static::$whitePattern, $this->buffer, $m, null, $this->count)) {
if (isset($m[1]) && empty($this->commentsSeen[$this->count])) {
$this->appendComment([Type::T_COMMENT, $m[1]]);
$this->commentsSeen[$this->count] = true;
}
$this->count += strlen($m[0]);
$gotWhite = true;
}
return $gotWhite;
} | php | protected function whitespace()
{
$gotWhite = false;
while (preg_match(static::$whitePattern, $this->buffer, $m, null, $this->count)) {
if (isset($m[1]) && empty($this->commentsSeen[$this->count])) {
$this->appendComment([Type::T_COMMENT, $m[1]]);
$this->commentsSeen[$this->count] = true;
}
$this->count += strlen($m[0]);
$gotWhite = true;
}
return $gotWhite;
} | [
"protected",
"function",
"whitespace",
"(",
")",
"{",
"$",
"gotWhite",
"=",
"false",
";",
"while",
"(",
"preg_match",
"(",
"static",
"::",
"$",
"whitePattern",
",",
"$",
"this",
"->",
"buffer",
",",
"$",
"m",
",",
"null",
",",
"$",
"this",
"->",
"count",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"m",
"[",
"1",
"]",
")",
"&&",
"empty",
"(",
"$",
"this",
"->",
"commentsSeen",
"[",
"$",
"this",
"->",
"count",
"]",
")",
")",
"{",
"$",
"this",
"->",
"appendComment",
"(",
"[",
"Type",
"::",
"T_COMMENT",
",",
"$",
"m",
"[",
"1",
"]",
"]",
")",
";",
"$",
"this",
"->",
"commentsSeen",
"[",
"$",
"this",
"->",
"count",
"]",
"=",
"true",
";",
"}",
"$",
"this",
"->",
"count",
"+=",
"strlen",
"(",
"$",
"m",
"[",
"0",
"]",
")",
";",
"$",
"gotWhite",
"=",
"true",
";",
"}",
"return",
"$",
"gotWhite",
";",
"}"
] | Match some whitespace
@return boolean | [
"Match",
"some",
"whitespace"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Parser.php#L922-L938 |
211,952 | moodle/moodle | lib/scssphp/Parser.php | Parser.appendComment | protected function appendComment($comment)
{
$comment[1] = substr(preg_replace(['/^\s+/m', '/^(.)/m'], ['', ' \1'], $comment[1]), 1);
$this->env->comments[] = $comment;
} | php | protected function appendComment($comment)
{
$comment[1] = substr(preg_replace(['/^\s+/m', '/^(.)/m'], ['', ' \1'], $comment[1]), 1);
$this->env->comments[] = $comment;
} | [
"protected",
"function",
"appendComment",
"(",
"$",
"comment",
")",
"{",
"$",
"comment",
"[",
"1",
"]",
"=",
"substr",
"(",
"preg_replace",
"(",
"[",
"'/^\\s+/m'",
",",
"'/^(.)/m'",
"]",
",",
"[",
"''",
",",
"' \\1'",
"]",
",",
"$",
"comment",
"[",
"1",
"]",
")",
",",
"1",
")",
";",
"$",
"this",
"->",
"env",
"->",
"comments",
"[",
"]",
"=",
"$",
"comment",
";",
"}"
] | Append comment to current block
@param array $comment | [
"Append",
"comment",
"to",
"current",
"block"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Parser.php#L945-L950 |
211,953 | moodle/moodle | lib/scssphp/Parser.php | Parser.append | protected function append($statement, $pos = null)
{
if ($pos !== null) {
list($line, $column) = $this->getSourcePosition($pos);
$statement[static::SOURCE_LINE] = $line;
$statement[static::SOURCE_COLUMN] = $column;
$statement[static::SOURCE_INDEX] = $this->sourceIndex;
}
$this->env->children[] = $statement;
$comments = $this->env->comments;
if (count($comments)) {
$this->env->children = array_merge($this->env->children, $comments);
$this->env->comments = [];
}
} | php | protected function append($statement, $pos = null)
{
if ($pos !== null) {
list($line, $column) = $this->getSourcePosition($pos);
$statement[static::SOURCE_LINE] = $line;
$statement[static::SOURCE_COLUMN] = $column;
$statement[static::SOURCE_INDEX] = $this->sourceIndex;
}
$this->env->children[] = $statement;
$comments = $this->env->comments;
if (count($comments)) {
$this->env->children = array_merge($this->env->children, $comments);
$this->env->comments = [];
}
} | [
"protected",
"function",
"append",
"(",
"$",
"statement",
",",
"$",
"pos",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"pos",
"!==",
"null",
")",
"{",
"list",
"(",
"$",
"line",
",",
"$",
"column",
")",
"=",
"$",
"this",
"->",
"getSourcePosition",
"(",
"$",
"pos",
")",
";",
"$",
"statement",
"[",
"static",
"::",
"SOURCE_LINE",
"]",
"=",
"$",
"line",
";",
"$",
"statement",
"[",
"static",
"::",
"SOURCE_COLUMN",
"]",
"=",
"$",
"column",
";",
"$",
"statement",
"[",
"static",
"::",
"SOURCE_INDEX",
"]",
"=",
"$",
"this",
"->",
"sourceIndex",
";",
"}",
"$",
"this",
"->",
"env",
"->",
"children",
"[",
"]",
"=",
"$",
"statement",
";",
"$",
"comments",
"=",
"$",
"this",
"->",
"env",
"->",
"comments",
";",
"if",
"(",
"count",
"(",
"$",
"comments",
")",
")",
"{",
"$",
"this",
"->",
"env",
"->",
"children",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"env",
"->",
"children",
",",
"$",
"comments",
")",
";",
"$",
"this",
"->",
"env",
"->",
"comments",
"=",
"[",
"]",
";",
"}",
"}"
] | Append statement to current block
@param array $statement
@param integer $pos | [
"Append",
"statement",
"to",
"current",
"block"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Parser.php#L958-L976 |
211,954 | moodle/moodle | lib/scssphp/Parser.php | Parser.last | protected function last()
{
$i = count($this->env->children) - 1;
if (isset($this->env->children[$i])) {
return $this->env->children[$i];
}
} | php | protected function last()
{
$i = count($this->env->children) - 1;
if (isset($this->env->children[$i])) {
return $this->env->children[$i];
}
} | [
"protected",
"function",
"last",
"(",
")",
"{",
"$",
"i",
"=",
"count",
"(",
"$",
"this",
"->",
"env",
"->",
"children",
")",
"-",
"1",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"env",
"->",
"children",
"[",
"$",
"i",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"env",
"->",
"children",
"[",
"$",
"i",
"]",
";",
"}",
"}"
] | Returns last child was appended
@return array|null | [
"Returns",
"last",
"child",
"was",
"appended"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Parser.php#L983-L990 |
211,955 | moodle/moodle | lib/scssphp/Parser.php | Parser.expHelper | protected function expHelper($lhs, $minP)
{
$operators = static::$operatorPattern;
$ss = $this->seek();
$whiteBefore = isset($this->buffer[$this->count - 1]) &&
ctype_space($this->buffer[$this->count - 1]);
while ($this->match($operators, $m, false) && static::$precedence[$m[1]] >= $minP) {
$whiteAfter = isset($this->buffer[$this->count]) &&
ctype_space($this->buffer[$this->count]);
$varAfter = isset($this->buffer[$this->count]) &&
$this->buffer[$this->count] === '$';
$this->whitespace();
$op = $m[1];
// don't turn negative numbers into expressions
if ($op === '-' && $whiteBefore && ! $whiteAfter && ! $varAfter) {
break;
}
if (! $this->value($rhs)) {
break;
}
// peek and see if rhs belongs to next operator
if ($this->peek($operators, $next) && static::$precedence[$next[1]] > static::$precedence[$op]) {
$rhs = $this->expHelper($rhs, static::$precedence[$next[1]]);
}
$lhs = [Type::T_EXPRESSION, $op, $lhs, $rhs, $this->inParens, $whiteBefore, $whiteAfter];
$ss = $this->seek();
$whiteBefore = isset($this->buffer[$this->count - 1]) &&
ctype_space($this->buffer[$this->count - 1]);
}
$this->seek($ss);
return $lhs;
} | php | protected function expHelper($lhs, $minP)
{
$operators = static::$operatorPattern;
$ss = $this->seek();
$whiteBefore = isset($this->buffer[$this->count - 1]) &&
ctype_space($this->buffer[$this->count - 1]);
while ($this->match($operators, $m, false) && static::$precedence[$m[1]] >= $minP) {
$whiteAfter = isset($this->buffer[$this->count]) &&
ctype_space($this->buffer[$this->count]);
$varAfter = isset($this->buffer[$this->count]) &&
$this->buffer[$this->count] === '$';
$this->whitespace();
$op = $m[1];
// don't turn negative numbers into expressions
if ($op === '-' && $whiteBefore && ! $whiteAfter && ! $varAfter) {
break;
}
if (! $this->value($rhs)) {
break;
}
// peek and see if rhs belongs to next operator
if ($this->peek($operators, $next) && static::$precedence[$next[1]] > static::$precedence[$op]) {
$rhs = $this->expHelper($rhs, static::$precedence[$next[1]]);
}
$lhs = [Type::T_EXPRESSION, $op, $lhs, $rhs, $this->inParens, $whiteBefore, $whiteAfter];
$ss = $this->seek();
$whiteBefore = isset($this->buffer[$this->count - 1]) &&
ctype_space($this->buffer[$this->count - 1]);
}
$this->seek($ss);
return $lhs;
} | [
"protected",
"function",
"expHelper",
"(",
"$",
"lhs",
",",
"$",
"minP",
")",
"{",
"$",
"operators",
"=",
"static",
"::",
"$",
"operatorPattern",
";",
"$",
"ss",
"=",
"$",
"this",
"->",
"seek",
"(",
")",
";",
"$",
"whiteBefore",
"=",
"isset",
"(",
"$",
"this",
"->",
"buffer",
"[",
"$",
"this",
"->",
"count",
"-",
"1",
"]",
")",
"&&",
"ctype_space",
"(",
"$",
"this",
"->",
"buffer",
"[",
"$",
"this",
"->",
"count",
"-",
"1",
"]",
")",
";",
"while",
"(",
"$",
"this",
"->",
"match",
"(",
"$",
"operators",
",",
"$",
"m",
",",
"false",
")",
"&&",
"static",
"::",
"$",
"precedence",
"[",
"$",
"m",
"[",
"1",
"]",
"]",
">=",
"$",
"minP",
")",
"{",
"$",
"whiteAfter",
"=",
"isset",
"(",
"$",
"this",
"->",
"buffer",
"[",
"$",
"this",
"->",
"count",
"]",
")",
"&&",
"ctype_space",
"(",
"$",
"this",
"->",
"buffer",
"[",
"$",
"this",
"->",
"count",
"]",
")",
";",
"$",
"varAfter",
"=",
"isset",
"(",
"$",
"this",
"->",
"buffer",
"[",
"$",
"this",
"->",
"count",
"]",
")",
"&&",
"$",
"this",
"->",
"buffer",
"[",
"$",
"this",
"->",
"count",
"]",
"===",
"'$'",
";",
"$",
"this",
"->",
"whitespace",
"(",
")",
";",
"$",
"op",
"=",
"$",
"m",
"[",
"1",
"]",
";",
"// don't turn negative numbers into expressions",
"if",
"(",
"$",
"op",
"===",
"'-'",
"&&",
"$",
"whiteBefore",
"&&",
"!",
"$",
"whiteAfter",
"&&",
"!",
"$",
"varAfter",
")",
"{",
"break",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"value",
"(",
"$",
"rhs",
")",
")",
"{",
"break",
";",
"}",
"// peek and see if rhs belongs to next operator",
"if",
"(",
"$",
"this",
"->",
"peek",
"(",
"$",
"operators",
",",
"$",
"next",
")",
"&&",
"static",
"::",
"$",
"precedence",
"[",
"$",
"next",
"[",
"1",
"]",
"]",
">",
"static",
"::",
"$",
"precedence",
"[",
"$",
"op",
"]",
")",
"{",
"$",
"rhs",
"=",
"$",
"this",
"->",
"expHelper",
"(",
"$",
"rhs",
",",
"static",
"::",
"$",
"precedence",
"[",
"$",
"next",
"[",
"1",
"]",
"]",
")",
";",
"}",
"$",
"lhs",
"=",
"[",
"Type",
"::",
"T_EXPRESSION",
",",
"$",
"op",
",",
"$",
"lhs",
",",
"$",
"rhs",
",",
"$",
"this",
"->",
"inParens",
",",
"$",
"whiteBefore",
",",
"$",
"whiteAfter",
"]",
";",
"$",
"ss",
"=",
"$",
"this",
"->",
"seek",
"(",
")",
";",
"$",
"whiteBefore",
"=",
"isset",
"(",
"$",
"this",
"->",
"buffer",
"[",
"$",
"this",
"->",
"count",
"-",
"1",
"]",
")",
"&&",
"ctype_space",
"(",
"$",
"this",
"->",
"buffer",
"[",
"$",
"this",
"->",
"count",
"-",
"1",
"]",
")",
";",
"}",
"$",
"this",
"->",
"seek",
"(",
"$",
"ss",
")",
";",
"return",
"$",
"lhs",
";",
"}"
] | Parse left-hand side of subexpression
@param array $lhs
@param integer $minP
@return array | [
"Parse",
"left",
"-",
"hand",
"side",
"of",
"subexpression"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Parser.php#L1251-L1292 |
211,956 | moodle/moodle | lib/scssphp/Parser.php | Parser.parenValue | protected function parenValue(&$out)
{
$s = $this->seek();
$inParens = $this->inParens;
if ($this->literal('(')) {
if ($this->literal(')')) {
$out = [Type::T_LIST, '', []];
return true;
}
$this->inParens = true;
if ($this->expression($exp) && $this->literal(')')) {
$out = $exp;
$this->inParens = $inParens;
return true;
}
}
$this->inParens = $inParens;
$this->seek($s);
return false;
} | php | protected function parenValue(&$out)
{
$s = $this->seek();
$inParens = $this->inParens;
if ($this->literal('(')) {
if ($this->literal(')')) {
$out = [Type::T_LIST, '', []];
return true;
}
$this->inParens = true;
if ($this->expression($exp) && $this->literal(')')) {
$out = $exp;
$this->inParens = $inParens;
return true;
}
}
$this->inParens = $inParens;
$this->seek($s);
return false;
} | [
"protected",
"function",
"parenValue",
"(",
"&",
"$",
"out",
")",
"{",
"$",
"s",
"=",
"$",
"this",
"->",
"seek",
"(",
")",
";",
"$",
"inParens",
"=",
"$",
"this",
"->",
"inParens",
";",
"if",
"(",
"$",
"this",
"->",
"literal",
"(",
"'('",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"literal",
"(",
"')'",
")",
")",
"{",
"$",
"out",
"=",
"[",
"Type",
"::",
"T_LIST",
",",
"''",
",",
"[",
"]",
"]",
";",
"return",
"true",
";",
"}",
"$",
"this",
"->",
"inParens",
"=",
"true",
";",
"if",
"(",
"$",
"this",
"->",
"expression",
"(",
"$",
"exp",
")",
"&&",
"$",
"this",
"->",
"literal",
"(",
"')'",
")",
")",
"{",
"$",
"out",
"=",
"$",
"exp",
";",
"$",
"this",
"->",
"inParens",
"=",
"$",
"inParens",
";",
"return",
"true",
";",
"}",
"}",
"$",
"this",
"->",
"inParens",
"=",
"$",
"inParens",
";",
"$",
"this",
"->",
"seek",
"(",
"$",
"s",
")",
";",
"return",
"false",
";",
"}"
] | Parse parenthesized value
@param array $out
@return boolean | [
"Parse",
"parenthesized",
"value"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Parser.php#L1374-L1401 |
211,957 | moodle/moodle | lib/scssphp/Parser.php | Parser.selectors | protected function selectors(&$out)
{
$s = $this->seek();
$selectors = [];
while ($this->selector($sel)) {
$selectors[] = $sel;
if (! $this->literal(',')) {
break;
}
while ($this->literal(',')) {
; // ignore extra
}
}
if (count($selectors) === 0) {
$this->seek($s);
return false;
}
$out = $selectors;
return true;
} | php | protected function selectors(&$out)
{
$s = $this->seek();
$selectors = [];
while ($this->selector($sel)) {
$selectors[] = $sel;
if (! $this->literal(',')) {
break;
}
while ($this->literal(',')) {
; // ignore extra
}
}
if (count($selectors) === 0) {
$this->seek($s);
return false;
}
$out = $selectors;
return true;
} | [
"protected",
"function",
"selectors",
"(",
"&",
"$",
"out",
")",
"{",
"$",
"s",
"=",
"$",
"this",
"->",
"seek",
"(",
")",
";",
"$",
"selectors",
"=",
"[",
"]",
";",
"while",
"(",
"$",
"this",
"->",
"selector",
"(",
"$",
"sel",
")",
")",
"{",
"$",
"selectors",
"[",
"]",
"=",
"$",
"sel",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"literal",
"(",
"','",
")",
")",
"{",
"break",
";",
"}",
"while",
"(",
"$",
"this",
"->",
"literal",
"(",
"','",
")",
")",
"{",
";",
"// ignore extra",
"}",
"}",
"if",
"(",
"count",
"(",
"$",
"selectors",
")",
"===",
"0",
")",
"{",
"$",
"this",
"->",
"seek",
"(",
"$",
"s",
")",
";",
"return",
"false",
";",
"}",
"$",
"out",
"=",
"$",
"selectors",
";",
"return",
"true",
";",
"}"
] | Parse comma separated selector list
@param array $out
@return boolean | [
"Parse",
"comma",
"separated",
"selector",
"list"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Parser.php#L1976-L2002 |
211,958 | moodle/moodle | lib/scssphp/Parser.php | Parser.selector | protected function selector(&$out)
{
$selector = [];
for (;;) {
if ($this->match('[>+~]+', $m)) {
$selector[] = [$m[0]];
continue;
}
if ($this->selectorSingle($part)) {
$selector[] = $part;
$this->match('\s+', $m);
continue;
}
if ($this->match('\/[^\/]+\/', $m)) {
$selector[] = [$m[0]];
continue;
}
break;
}
if (count($selector) === 0) {
return false;
}
$out = $selector;
return true;
} | php | protected function selector(&$out)
{
$selector = [];
for (;;) {
if ($this->match('[>+~]+', $m)) {
$selector[] = [$m[0]];
continue;
}
if ($this->selectorSingle($part)) {
$selector[] = $part;
$this->match('\s+', $m);
continue;
}
if ($this->match('\/[^\/]+\/', $m)) {
$selector[] = [$m[0]];
continue;
}
break;
}
if (count($selector) === 0) {
return false;
}
$out = $selector;
return true;
} | [
"protected",
"function",
"selector",
"(",
"&",
"$",
"out",
")",
"{",
"$",
"selector",
"=",
"[",
"]",
";",
"for",
"(",
";",
";",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"match",
"(",
"'[>+~]+'",
",",
"$",
"m",
")",
")",
"{",
"$",
"selector",
"[",
"]",
"=",
"[",
"$",
"m",
"[",
"0",
"]",
"]",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"selectorSingle",
"(",
"$",
"part",
")",
")",
"{",
"$",
"selector",
"[",
"]",
"=",
"$",
"part",
";",
"$",
"this",
"->",
"match",
"(",
"'\\s+'",
",",
"$",
"m",
")",
";",
"continue",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"match",
"(",
"'\\/[^\\/]+\\/'",
",",
"$",
"m",
")",
")",
"{",
"$",
"selector",
"[",
"]",
"=",
"[",
"$",
"m",
"[",
"0",
"]",
"]",
";",
"continue",
";",
"}",
"break",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"selector",
")",
"===",
"0",
")",
"{",
"return",
"false",
";",
"}",
"$",
"out",
"=",
"$",
"selector",
";",
"return",
"true",
";",
"}"
] | Parse whitespace separated selector list
@param array $out
@return boolean | [
"Parse",
"whitespace",
"separated",
"selector",
"list"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Parser.php#L2011-L2041 |
211,959 | moodle/moodle | lib/scssphp/Parser.php | Parser.placeholder | protected function placeholder(&$placeholder)
{
if ($this->match(
$this->utf8
? '([\pL\w\-_]+|#[{][$][\pL\w\-_]+[}])'
: '([\w\-_]+|#[{][$][\w\-_]+[}])',
$m
)) {
$placeholder = $m[1];
return true;
}
return false;
} | php | protected function placeholder(&$placeholder)
{
if ($this->match(
$this->utf8
? '([\pL\w\-_]+|#[{][$][\pL\w\-_]+[}])'
: '([\w\-_]+|#[{][$][\w\-_]+[}])',
$m
)) {
$placeholder = $m[1];
return true;
}
return false;
} | [
"protected",
"function",
"placeholder",
"(",
"&",
"$",
"placeholder",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"match",
"(",
"$",
"this",
"->",
"utf8",
"?",
"'([\\pL\\w\\-_]+|#[{][$][\\pL\\w\\-_]+[}])'",
":",
"'([\\w\\-_]+|#[{][$][\\w\\-_]+[}])'",
",",
"$",
"m",
")",
")",
"{",
"$",
"placeholder",
"=",
"$",
"m",
"[",
"1",
"]",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Parse a placeholder
@param string $placeholder
@return boolean | [
"Parse",
"a",
"placeholder"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Parser.php#L2238-L2252 |
211,960 | moodle/moodle | lib/scssphp/Parser.php | Parser.url | protected function url(&$out)
{
if ($this->match('(url\(\s*(["\']?)([^)]+)\2\s*\))', $m)) {
$out = [Type::T_STRING, '', ['url(' . $m[2] . $m[3] . $m[2] . ')']];
return true;
}
return false;
} | php | protected function url(&$out)
{
if ($this->match('(url\(\s*(["\']?)([^)]+)\2\s*\))', $m)) {
$out = [Type::T_STRING, '', ['url(' . $m[2] . $m[3] . $m[2] . ')']];
return true;
}
return false;
} | [
"protected",
"function",
"url",
"(",
"&",
"$",
"out",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"match",
"(",
"'(url\\(\\s*([\"\\']?)([^)]+)\\2\\s*\\))'",
",",
"$",
"m",
")",
")",
"{",
"$",
"out",
"=",
"[",
"Type",
"::",
"T_STRING",
",",
"''",
",",
"[",
"'url('",
".",
"$",
"m",
"[",
"2",
"]",
".",
"$",
"m",
"[",
"3",
"]",
".",
"$",
"m",
"[",
"2",
"]",
".",
"')'",
"]",
"]",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Parse a url
@param array $out
@return boolean | [
"Parse",
"a",
"url"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Parser.php#L2261-L2270 |
211,961 | moodle/moodle | lib/scssphp/Parser.php | Parser.stripAssignmentFlags | protected function stripAssignmentFlags(&$value)
{
$flags = [];
for ($token = &$value; $token[0] === Type::T_LIST && ($s = count($token[2])); $token = &$lastNode) {
$lastNode = &$token[2][$s - 1];
while ($lastNode[0] === Type::T_KEYWORD && in_array($lastNode[1], ['!default', '!global'])) {
array_pop($token[2]);
$node = end($token[2]);
$token = $this->flattenList($token);
$flags[] = $lastNode[1];
$lastNode = $node;
}
}
return $flags;
} | php | protected function stripAssignmentFlags(&$value)
{
$flags = [];
for ($token = &$value; $token[0] === Type::T_LIST && ($s = count($token[2])); $token = &$lastNode) {
$lastNode = &$token[2][$s - 1];
while ($lastNode[0] === Type::T_KEYWORD && in_array($lastNode[1], ['!default', '!global'])) {
array_pop($token[2]);
$node = end($token[2]);
$token = $this->flattenList($token);
$flags[] = $lastNode[1];
$lastNode = $node;
}
}
return $flags;
} | [
"protected",
"function",
"stripAssignmentFlags",
"(",
"&",
"$",
"value",
")",
"{",
"$",
"flags",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"token",
"=",
"&",
"$",
"value",
";",
"$",
"token",
"[",
"0",
"]",
"===",
"Type",
"::",
"T_LIST",
"&&",
"(",
"$",
"s",
"=",
"count",
"(",
"$",
"token",
"[",
"2",
"]",
")",
")",
";",
"$",
"token",
"=",
"&",
"$",
"lastNode",
")",
"{",
"$",
"lastNode",
"=",
"&",
"$",
"token",
"[",
"2",
"]",
"[",
"$",
"s",
"-",
"1",
"]",
";",
"while",
"(",
"$",
"lastNode",
"[",
"0",
"]",
"===",
"Type",
"::",
"T_KEYWORD",
"&&",
"in_array",
"(",
"$",
"lastNode",
"[",
"1",
"]",
",",
"[",
"'!default'",
",",
"'!global'",
"]",
")",
")",
"{",
"array_pop",
"(",
"$",
"token",
"[",
"2",
"]",
")",
";",
"$",
"node",
"=",
"end",
"(",
"$",
"token",
"[",
"2",
"]",
")",
";",
"$",
"token",
"=",
"$",
"this",
"->",
"flattenList",
"(",
"$",
"token",
")",
";",
"$",
"flags",
"[",
"]",
"=",
"$",
"lastNode",
"[",
"1",
"]",
";",
"$",
"lastNode",
"=",
"$",
"node",
";",
"}",
"}",
"return",
"$",
"flags",
";",
"}"
] | Strip assignment flag from the list
@param array $value
@return array | [
"Strip",
"assignment",
"flag",
"from",
"the",
"list"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Parser.php#L2298-L2319 |
211,962 | moodle/moodle | lib/scssphp/Parser.php | Parser.stripOptionalFlag | protected function stripOptionalFlag(&$selectors)
{
$optional = false;
$selector = end($selectors);
$part = end($selector);
if ($part === ['!optional']) {
array_pop($selectors[count($selectors) - 1]);
$optional = true;
}
return $optional;
} | php | protected function stripOptionalFlag(&$selectors)
{
$optional = false;
$selector = end($selectors);
$part = end($selector);
if ($part === ['!optional']) {
array_pop($selectors[count($selectors) - 1]);
$optional = true;
}
return $optional;
} | [
"protected",
"function",
"stripOptionalFlag",
"(",
"&",
"$",
"selectors",
")",
"{",
"$",
"optional",
"=",
"false",
";",
"$",
"selector",
"=",
"end",
"(",
"$",
"selectors",
")",
";",
"$",
"part",
"=",
"end",
"(",
"$",
"selector",
")",
";",
"if",
"(",
"$",
"part",
"===",
"[",
"'!optional'",
"]",
")",
"{",
"array_pop",
"(",
"$",
"selectors",
"[",
"count",
"(",
"$",
"selectors",
")",
"-",
"1",
"]",
")",
";",
"$",
"optional",
"=",
"true",
";",
"}",
"return",
"$",
"optional",
";",
"}"
] | Strip optional flag from selector list
@param array $selectors
@return string | [
"Strip",
"optional",
"flag",
"from",
"selector",
"list"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Parser.php#L2328-L2342 |
211,963 | moodle/moodle | lib/scssphp/Parser.php | Parser.flattenList | protected function flattenList($value)
{
if ($value[0] === Type::T_LIST && count($value[2]) === 1) {
return $this->flattenList($value[2][0]);
}
return $value;
} | php | protected function flattenList($value)
{
if ($value[0] === Type::T_LIST && count($value[2]) === 1) {
return $this->flattenList($value[2][0]);
}
return $value;
} | [
"protected",
"function",
"flattenList",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"[",
"0",
"]",
"===",
"Type",
"::",
"T_LIST",
"&&",
"count",
"(",
"$",
"value",
"[",
"2",
"]",
")",
"===",
"1",
")",
"{",
"return",
"$",
"this",
"->",
"flattenList",
"(",
"$",
"value",
"[",
"2",
"]",
"[",
"0",
"]",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Turn list of length 1 into value type
@param array $value
@return array | [
"Turn",
"list",
"of",
"length",
"1",
"into",
"value",
"type"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Parser.php#L2351-L2358 |
211,964 | moodle/moodle | lib/scssphp/Parser.php | Parser.extractLineNumbers | private function extractLineNumbers($buffer)
{
$this->sourcePositions = [0 => 0];
$prev = 0;
while (($pos = strpos($buffer, "\n", $prev)) !== false) {
$this->sourcePositions[] = $pos;
$prev = $pos + 1;
}
$this->sourcePositions[] = strlen($buffer);
if (substr($buffer, -1) !== "\n") {
$this->sourcePositions[] = strlen($buffer) + 1;
}
} | php | private function extractLineNumbers($buffer)
{
$this->sourcePositions = [0 => 0];
$prev = 0;
while (($pos = strpos($buffer, "\n", $prev)) !== false) {
$this->sourcePositions[] = $pos;
$prev = $pos + 1;
}
$this->sourcePositions[] = strlen($buffer);
if (substr($buffer, -1) !== "\n") {
$this->sourcePositions[] = strlen($buffer) + 1;
}
} | [
"private",
"function",
"extractLineNumbers",
"(",
"$",
"buffer",
")",
"{",
"$",
"this",
"->",
"sourcePositions",
"=",
"[",
"0",
"=>",
"0",
"]",
";",
"$",
"prev",
"=",
"0",
";",
"while",
"(",
"(",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"buffer",
",",
"\"\\n\"",
",",
"$",
"prev",
")",
")",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"sourcePositions",
"[",
"]",
"=",
"$",
"pos",
";",
"$",
"prev",
"=",
"$",
"pos",
"+",
"1",
";",
"}",
"$",
"this",
"->",
"sourcePositions",
"[",
"]",
"=",
"strlen",
"(",
"$",
"buffer",
")",
";",
"if",
"(",
"substr",
"(",
"$",
"buffer",
",",
"-",
"1",
")",
"!==",
"\"\\n\"",
")",
"{",
"$",
"this",
"->",
"sourcePositions",
"[",
"]",
"=",
"strlen",
"(",
"$",
"buffer",
")",
"+",
"1",
";",
"}",
"}"
] | Extract line numbers from buffer
@param string $buffer | [
"Extract",
"line",
"numbers",
"from",
"buffer"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Parser.php#L2419-L2434 |
211,965 | moodle/moodle | lib/scssphp/Parser.php | Parser.saveEncoding | private function saveEncoding()
{
if (version_compare(PHP_VERSION, '7.2.0') >= 0) {
return;
}
$iniDirective = 'mbstring' . '.func_overload'; // deprecated in PHP 7.2
if (ini_get($iniDirective) & 2) {
$this->encoding = mb_internal_encoding();
mb_internal_encoding('iso-8859-1');
}
} | php | private function saveEncoding()
{
if (version_compare(PHP_VERSION, '7.2.0') >= 0) {
return;
}
$iniDirective = 'mbstring' . '.func_overload'; // deprecated in PHP 7.2
if (ini_get($iniDirective) & 2) {
$this->encoding = mb_internal_encoding();
mb_internal_encoding('iso-8859-1');
}
} | [
"private",
"function",
"saveEncoding",
"(",
")",
"{",
"if",
"(",
"version_compare",
"(",
"PHP_VERSION",
",",
"'7.2.0'",
")",
">=",
"0",
")",
"{",
"return",
";",
"}",
"$",
"iniDirective",
"=",
"'mbstring'",
".",
"'.func_overload'",
";",
"// deprecated in PHP 7.2",
"if",
"(",
"ini_get",
"(",
"$",
"iniDirective",
")",
"&",
"2",
")",
"{",
"$",
"this",
"->",
"encoding",
"=",
"mb_internal_encoding",
"(",
")",
";",
"mb_internal_encoding",
"(",
"'iso-8859-1'",
")",
";",
"}",
"}"
] | Save internal encoding | [
"Save",
"internal",
"encoding"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/scssphp/Parser.php#L2470-L2483 |
211,966 | moodle/moodle | question/classes/output/qbank_chooser.php | qbank_chooser.get | public static function get($course, $hiddenparams, array $allowedqtypes = null) {
$realqtypes = array();
$fakeqtypes = array();
foreach (question_bank::get_creatable_qtypes() as $qtypename => $qtype) {
if ($allowedqtypes && !in_array($qtypename, $allowedqtypes)) {
continue;
}
if ($qtype->is_real_question_type()) {
$realqtypes[] = $qtype;
} else {
$fakeqtypes[] = $qtype;
}
}
return new static($realqtypes, $fakeqtypes, $course, $hiddenparams, context_course::instance($course->id));
} | php | public static function get($course, $hiddenparams, array $allowedqtypes = null) {
$realqtypes = array();
$fakeqtypes = array();
foreach (question_bank::get_creatable_qtypes() as $qtypename => $qtype) {
if ($allowedqtypes && !in_array($qtypename, $allowedqtypes)) {
continue;
}
if ($qtype->is_real_question_type()) {
$realqtypes[] = $qtype;
} else {
$fakeqtypes[] = $qtype;
}
}
return new static($realqtypes, $fakeqtypes, $course, $hiddenparams, context_course::instance($course->id));
} | [
"public",
"static",
"function",
"get",
"(",
"$",
"course",
",",
"$",
"hiddenparams",
",",
"array",
"$",
"allowedqtypes",
"=",
"null",
")",
"{",
"$",
"realqtypes",
"=",
"array",
"(",
")",
";",
"$",
"fakeqtypes",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"question_bank",
"::",
"get_creatable_qtypes",
"(",
")",
"as",
"$",
"qtypename",
"=>",
"$",
"qtype",
")",
"{",
"if",
"(",
"$",
"allowedqtypes",
"&&",
"!",
"in_array",
"(",
"$",
"qtypename",
",",
"$",
"allowedqtypes",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"qtype",
"->",
"is_real_question_type",
"(",
")",
")",
"{",
"$",
"realqtypes",
"[",
"]",
"=",
"$",
"qtype",
";",
"}",
"else",
"{",
"$",
"fakeqtypes",
"[",
"]",
"=",
"$",
"qtype",
";",
"}",
"}",
"return",
"new",
"static",
"(",
"$",
"realqtypes",
",",
"$",
"fakeqtypes",
",",
"$",
"course",
",",
"$",
"hiddenparams",
",",
"context_course",
"::",
"instance",
"(",
"$",
"course",
"->",
"id",
")",
")",
";",
"}"
] | Get an instance of the question bank chooser.
@param stdClass $course The course.
@param array $hiddenparams Hidden parameters.
@param array|null $allowedqtypes Allowed question types.
@return qbank_chooser | [
"Get",
"an",
"instance",
"of",
"the",
"question",
"bank",
"chooser",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/output/qbank_chooser.php#L87-L103 |
211,967 | moodle/moodle | customfield/classes/api.php | api.get_instance_fields_data | public static function get_instance_fields_data(array $fields, int $instanceid, bool $adddefaults = true) : array {
return self::get_instances_fields_data($fields, [$instanceid], $adddefaults)[$instanceid];
} | php | public static function get_instance_fields_data(array $fields, int $instanceid, bool $adddefaults = true) : array {
return self::get_instances_fields_data($fields, [$instanceid], $adddefaults)[$instanceid];
} | [
"public",
"static",
"function",
"get_instance_fields_data",
"(",
"array",
"$",
"fields",
",",
"int",
"$",
"instanceid",
",",
"bool",
"$",
"adddefaults",
"=",
"true",
")",
":",
"array",
"{",
"return",
"self",
"::",
"get_instances_fields_data",
"(",
"$",
"fields",
",",
"[",
"$",
"instanceid",
"]",
",",
"$",
"adddefaults",
")",
"[",
"$",
"instanceid",
"]",
";",
"}"
] | For the given instance and list of fields fields retrieves data associated with them
@param field_controller[] $fields list of fields indexed by field id
@param int $instanceid
@param bool $adddefaults
@return data_controller[] array of data_controller objects indexed by fieldid. All fields are present,
some data_controller objects may have 'id', some not
If ($adddefaults): All fieldids are present, some data_controller objects may have 'id', some not.
If (!$adddefaults): Only fieldids with data are present, all data_controller objects have 'id'. | [
"For",
"the",
"given",
"instance",
"and",
"list",
"of",
"fields",
"fields",
"retrieves",
"data",
"associated",
"with",
"them"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/api.php#L57-L59 |
211,968 | moodle/moodle | customfield/classes/api.php | api.get_instances_fields_data | public static function get_instances_fields_data(array $fields, array $instanceids, bool $adddefaults = true) : array {
global $DB;
// Create the results array where instances and fields order is the same as in the input arrays.
$result = array_fill_keys($instanceids, array_fill_keys(array_keys($fields), null));
if (empty($instanceids) || empty($fields)) {
return $result;
}
// Retrieve all existing data.
list($sqlfields, $params) = $DB->get_in_or_equal(array_keys($fields), SQL_PARAMS_NAMED, 'fld');
list($sqlinstances, $iparams) = $DB->get_in_or_equal($instanceids, SQL_PARAMS_NAMED, 'ins');
$sql = "SELECT d.*
FROM {customfield_field} f
JOIN {customfield_data} d ON (f.id = d.fieldid AND d.instanceid {$sqlinstances})
WHERE f.id {$sqlfields}";
$fieldsdata = $DB->get_recordset_sql($sql, $params + $iparams);
foreach ($fieldsdata as $data) {
$result[$data->instanceid][$data->fieldid] = data_controller::create(0, $data, $fields[$data->fieldid]);
}
$fieldsdata->close();
if ($adddefaults) {
// Add default data where it was not retrieved.
foreach ($instanceids as $instanceid) {
foreach ($fields as $fieldid => $field) {
if ($result[$instanceid][$fieldid] === null) {
$result[$instanceid][$fieldid] =
data_controller::create(0, (object)['instanceid' => $instanceid], $field);
}
}
}
} else {
// Remove null-placeholders for data that was not retrieved.
foreach ($instanceids as $instanceid) {
$result[$instanceid] = array_filter($result[$instanceid]);
}
}
return $result;
} | php | public static function get_instances_fields_data(array $fields, array $instanceids, bool $adddefaults = true) : array {
global $DB;
// Create the results array where instances and fields order is the same as in the input arrays.
$result = array_fill_keys($instanceids, array_fill_keys(array_keys($fields), null));
if (empty($instanceids) || empty($fields)) {
return $result;
}
// Retrieve all existing data.
list($sqlfields, $params) = $DB->get_in_or_equal(array_keys($fields), SQL_PARAMS_NAMED, 'fld');
list($sqlinstances, $iparams) = $DB->get_in_or_equal($instanceids, SQL_PARAMS_NAMED, 'ins');
$sql = "SELECT d.*
FROM {customfield_field} f
JOIN {customfield_data} d ON (f.id = d.fieldid AND d.instanceid {$sqlinstances})
WHERE f.id {$sqlfields}";
$fieldsdata = $DB->get_recordset_sql($sql, $params + $iparams);
foreach ($fieldsdata as $data) {
$result[$data->instanceid][$data->fieldid] = data_controller::create(0, $data, $fields[$data->fieldid]);
}
$fieldsdata->close();
if ($adddefaults) {
// Add default data where it was not retrieved.
foreach ($instanceids as $instanceid) {
foreach ($fields as $fieldid => $field) {
if ($result[$instanceid][$fieldid] === null) {
$result[$instanceid][$fieldid] =
data_controller::create(0, (object)['instanceid' => $instanceid], $field);
}
}
}
} else {
// Remove null-placeholders for data that was not retrieved.
foreach ($instanceids as $instanceid) {
$result[$instanceid] = array_filter($result[$instanceid]);
}
}
return $result;
} | [
"public",
"static",
"function",
"get_instances_fields_data",
"(",
"array",
"$",
"fields",
",",
"array",
"$",
"instanceids",
",",
"bool",
"$",
"adddefaults",
"=",
"true",
")",
":",
"array",
"{",
"global",
"$",
"DB",
";",
"// Create the results array where instances and fields order is the same as in the input arrays.",
"$",
"result",
"=",
"array_fill_keys",
"(",
"$",
"instanceids",
",",
"array_fill_keys",
"(",
"array_keys",
"(",
"$",
"fields",
")",
",",
"null",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"instanceids",
")",
"||",
"empty",
"(",
"$",
"fields",
")",
")",
"{",
"return",
"$",
"result",
";",
"}",
"// Retrieve all existing data.",
"list",
"(",
"$",
"sqlfields",
",",
"$",
"params",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"array_keys",
"(",
"$",
"fields",
")",
",",
"SQL_PARAMS_NAMED",
",",
"'fld'",
")",
";",
"list",
"(",
"$",
"sqlinstances",
",",
"$",
"iparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"instanceids",
",",
"SQL_PARAMS_NAMED",
",",
"'ins'",
")",
";",
"$",
"sql",
"=",
"\"SELECT d.*\n FROM {customfield_field} f\n JOIN {customfield_data} d ON (f.id = d.fieldid AND d.instanceid {$sqlinstances})\n WHERE f.id {$sqlfields}\"",
";",
"$",
"fieldsdata",
"=",
"$",
"DB",
"->",
"get_recordset_sql",
"(",
"$",
"sql",
",",
"$",
"params",
"+",
"$",
"iparams",
")",
";",
"foreach",
"(",
"$",
"fieldsdata",
"as",
"$",
"data",
")",
"{",
"$",
"result",
"[",
"$",
"data",
"->",
"instanceid",
"]",
"[",
"$",
"data",
"->",
"fieldid",
"]",
"=",
"data_controller",
"::",
"create",
"(",
"0",
",",
"$",
"data",
",",
"$",
"fields",
"[",
"$",
"data",
"->",
"fieldid",
"]",
")",
";",
"}",
"$",
"fieldsdata",
"->",
"close",
"(",
")",
";",
"if",
"(",
"$",
"adddefaults",
")",
"{",
"// Add default data where it was not retrieved.",
"foreach",
"(",
"$",
"instanceids",
"as",
"$",
"instanceid",
")",
"{",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"fieldid",
"=>",
"$",
"field",
")",
"{",
"if",
"(",
"$",
"result",
"[",
"$",
"instanceid",
"]",
"[",
"$",
"fieldid",
"]",
"===",
"null",
")",
"{",
"$",
"result",
"[",
"$",
"instanceid",
"]",
"[",
"$",
"fieldid",
"]",
"=",
"data_controller",
"::",
"create",
"(",
"0",
",",
"(",
"object",
")",
"[",
"'instanceid'",
"=>",
"$",
"instanceid",
"]",
",",
"$",
"field",
")",
";",
"}",
"}",
"}",
"}",
"else",
"{",
"// Remove null-placeholders for data that was not retrieved.",
"foreach",
"(",
"$",
"instanceids",
"as",
"$",
"instanceid",
")",
"{",
"$",
"result",
"[",
"$",
"instanceid",
"]",
"=",
"array_filter",
"(",
"$",
"result",
"[",
"$",
"instanceid",
"]",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] | For given list of instances and fields retrieves data associated with them
@param field_controller[] $fields list of fields indexed by field id
@param int[] $instanceids
@param bool $adddefaults
@return data_controller[][] 2-dimension array, first index is instanceid, second index is fieldid.
If ($adddefaults): All instanceids and all fieldids are present, some data_controller objects may have 'id', some not.
If (!$adddefaults): All instanceids are present but only fieldids with data are present, all
data_controller objects have 'id'. | [
"For",
"given",
"list",
"of",
"instances",
"and",
"fields",
"retrieves",
"data",
"associated",
"with",
"them"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/api.php#L72-L113 |
211,969 | moodle/moodle | customfield/classes/api.php | api.get_available_field_types | public static function get_available_field_types() {
$fieldtypes = array();
$plugins = \core\plugininfo\customfield::get_enabled_plugins();
foreach ($plugins as $type => $unused) {
$fieldtypes[$type] = get_string('pluginname', 'customfield_' . $type);
}
asort($fieldtypes);
return $fieldtypes;
} | php | public static function get_available_field_types() {
$fieldtypes = array();
$plugins = \core\plugininfo\customfield::get_enabled_plugins();
foreach ($plugins as $type => $unused) {
$fieldtypes[$type] = get_string('pluginname', 'customfield_' . $type);
}
asort($fieldtypes);
return $fieldtypes;
} | [
"public",
"static",
"function",
"get_available_field_types",
"(",
")",
"{",
"$",
"fieldtypes",
"=",
"array",
"(",
")",
";",
"$",
"plugins",
"=",
"\\",
"core",
"\\",
"plugininfo",
"\\",
"customfield",
"::",
"get_enabled_plugins",
"(",
")",
";",
"foreach",
"(",
"$",
"plugins",
"as",
"$",
"type",
"=>",
"$",
"unused",
")",
"{",
"$",
"fieldtypes",
"[",
"$",
"type",
"]",
"=",
"get_string",
"(",
"'pluginname'",
",",
"'customfield_'",
".",
"$",
"type",
")",
";",
"}",
"asort",
"(",
"$",
"fieldtypes",
")",
";",
"return",
"$",
"fieldtypes",
";",
"}"
] | Retrieve a list of all available custom field types
@return array a list of the fieldtypes suitable to use in a select statement | [
"Retrieve",
"a",
"list",
"of",
"all",
"available",
"custom",
"field",
"types"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/api.php#L120-L130 |
211,970 | moodle/moodle | customfield/classes/api.php | api.save_field_configuration | public static function save_field_configuration(field_controller $field, \stdClass $formdata) {
foreach ($formdata as $key => $value) {
if ($key === 'configdata' && is_array($formdata->configdata)) {
$field->set($key, json_encode($value));
} else if ($key === 'id' || ($key === 'type' && $field->get('id'))) {
continue;
} else if (field::has_property($key)) {
$field->set($key, $value);
}
}
$isnewfield = empty($field->get('id'));
// Process files in description.
if (isset($formdata->description_editor)) {
if (!$field->get('id')) {
// We need 'id' field to store files used in description.
$field->save();
}
$data = (object) ['description_editor' => $formdata->description_editor];
$textoptions = $field->get_handler()->get_description_text_options();
$data = file_postupdate_standard_editor($data, 'description', $textoptions, $textoptions['context'],
'core_customfield', 'description', $field->get('id'));
$field->set('description', $data->description);
$field->set('descriptionformat', $data->descriptionformat);
}
// Save the field.
$field->save();
if ($isnewfield) {
// Move to the end of the category.
self::move_field($field, $field->get('categoryid'));
}
if ($isnewfield) {
field_created::create_from_object($field)->trigger();
} else {
field_updated::create_from_object($field)->trigger();
}
} | php | public static function save_field_configuration(field_controller $field, \stdClass $formdata) {
foreach ($formdata as $key => $value) {
if ($key === 'configdata' && is_array($formdata->configdata)) {
$field->set($key, json_encode($value));
} else if ($key === 'id' || ($key === 'type' && $field->get('id'))) {
continue;
} else if (field::has_property($key)) {
$field->set($key, $value);
}
}
$isnewfield = empty($field->get('id'));
// Process files in description.
if (isset($formdata->description_editor)) {
if (!$field->get('id')) {
// We need 'id' field to store files used in description.
$field->save();
}
$data = (object) ['description_editor' => $formdata->description_editor];
$textoptions = $field->get_handler()->get_description_text_options();
$data = file_postupdate_standard_editor($data, 'description', $textoptions, $textoptions['context'],
'core_customfield', 'description', $field->get('id'));
$field->set('description', $data->description);
$field->set('descriptionformat', $data->descriptionformat);
}
// Save the field.
$field->save();
if ($isnewfield) {
// Move to the end of the category.
self::move_field($field, $field->get('categoryid'));
}
if ($isnewfield) {
field_created::create_from_object($field)->trigger();
} else {
field_updated::create_from_object($field)->trigger();
}
} | [
"public",
"static",
"function",
"save_field_configuration",
"(",
"field_controller",
"$",
"field",
",",
"\\",
"stdClass",
"$",
"formdata",
")",
"{",
"foreach",
"(",
"$",
"formdata",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"key",
"===",
"'configdata'",
"&&",
"is_array",
"(",
"$",
"formdata",
"->",
"configdata",
")",
")",
"{",
"$",
"field",
"->",
"set",
"(",
"$",
"key",
",",
"json_encode",
"(",
"$",
"value",
")",
")",
";",
"}",
"else",
"if",
"(",
"$",
"key",
"===",
"'id'",
"||",
"(",
"$",
"key",
"===",
"'type'",
"&&",
"$",
"field",
"->",
"get",
"(",
"'id'",
")",
")",
")",
"{",
"continue",
";",
"}",
"else",
"if",
"(",
"field",
"::",
"has_property",
"(",
"$",
"key",
")",
")",
"{",
"$",
"field",
"->",
"set",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}",
"$",
"isnewfield",
"=",
"empty",
"(",
"$",
"field",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"// Process files in description.",
"if",
"(",
"isset",
"(",
"$",
"formdata",
"->",
"description_editor",
")",
")",
"{",
"if",
"(",
"!",
"$",
"field",
"->",
"get",
"(",
"'id'",
")",
")",
"{",
"// We need 'id' field to store files used in description.",
"$",
"field",
"->",
"save",
"(",
")",
";",
"}",
"$",
"data",
"=",
"(",
"object",
")",
"[",
"'description_editor'",
"=>",
"$",
"formdata",
"->",
"description_editor",
"]",
";",
"$",
"textoptions",
"=",
"$",
"field",
"->",
"get_handler",
"(",
")",
"->",
"get_description_text_options",
"(",
")",
";",
"$",
"data",
"=",
"file_postupdate_standard_editor",
"(",
"$",
"data",
",",
"'description'",
",",
"$",
"textoptions",
",",
"$",
"textoptions",
"[",
"'context'",
"]",
",",
"'core_customfield'",
",",
"'description'",
",",
"$",
"field",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"$",
"field",
"->",
"set",
"(",
"'description'",
",",
"$",
"data",
"->",
"description",
")",
";",
"$",
"field",
"->",
"set",
"(",
"'descriptionformat'",
",",
"$",
"data",
"->",
"descriptionformat",
")",
";",
"}",
"// Save the field.",
"$",
"field",
"->",
"save",
"(",
")",
";",
"if",
"(",
"$",
"isnewfield",
")",
"{",
"// Move to the end of the category.",
"self",
"::",
"move_field",
"(",
"$",
"field",
",",
"$",
"field",
"->",
"get",
"(",
"'categoryid'",
")",
")",
";",
"}",
"if",
"(",
"$",
"isnewfield",
")",
"{",
"field_created",
"::",
"create_from_object",
"(",
"$",
"field",
")",
"->",
"trigger",
"(",
")",
";",
"}",
"else",
"{",
"field_updated",
"::",
"create_from_object",
"(",
"$",
"field",
")",
"->",
"trigger",
"(",
")",
";",
"}",
"}"
] | Updates or creates a field with data that came from a form
@param field_controller $field
@param \stdClass $formdata | [
"Updates",
"or",
"creates",
"a",
"field",
"with",
"data",
"that",
"came",
"from",
"a",
"form"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/api.php#L138-L179 |
211,971 | moodle/moodle | customfield/classes/api.php | api.delete_field_configuration | public static function delete_field_configuration(field_controller $field) : bool {
$event = field_deleted::create_from_object($field);
get_file_storage()->delete_area_files($field->get_handler()->get_configuration_context()->id, 'core_customfield',
'description', $field->get('id'));
$result = $field->delete();
$event->trigger();
return $result;
} | php | public static function delete_field_configuration(field_controller $field) : bool {
$event = field_deleted::create_from_object($field);
get_file_storage()->delete_area_files($field->get_handler()->get_configuration_context()->id, 'core_customfield',
'description', $field->get('id'));
$result = $field->delete();
$event->trigger();
return $result;
} | [
"public",
"static",
"function",
"delete_field_configuration",
"(",
"field_controller",
"$",
"field",
")",
":",
"bool",
"{",
"$",
"event",
"=",
"field_deleted",
"::",
"create_from_object",
"(",
"$",
"field",
")",
";",
"get_file_storage",
"(",
")",
"->",
"delete_area_files",
"(",
"$",
"field",
"->",
"get_handler",
"(",
")",
"->",
"get_configuration_context",
"(",
")",
"->",
"id",
",",
"'core_customfield'",
",",
"'description'",
",",
"$",
"field",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"$",
"result",
"=",
"$",
"field",
"->",
"delete",
"(",
")",
";",
"$",
"event",
"->",
"trigger",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Delete a field
@param field_controller $field | [
"Delete",
"a",
"field"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/api.php#L233-L240 |
211,972 | moodle/moodle | customfield/classes/api.php | api.get_category_inplace_editable | public static function get_category_inplace_editable(category_controller $category, bool $editable = true) : inplace_editable {
return new inplace_editable('core_customfield',
'category',
$category->get('id'),
$editable,
$category->get_formatted_name(),
$category->get('name'),
get_string('editcategoryname', 'core_customfield'),
get_string('newvaluefor', 'core_form', format_string($category->get('name')))
);
} | php | public static function get_category_inplace_editable(category_controller $category, bool $editable = true) : inplace_editable {
return new inplace_editable('core_customfield',
'category',
$category->get('id'),
$editable,
$category->get_formatted_name(),
$category->get('name'),
get_string('editcategoryname', 'core_customfield'),
get_string('newvaluefor', 'core_form', format_string($category->get('name')))
);
} | [
"public",
"static",
"function",
"get_category_inplace_editable",
"(",
"category_controller",
"$",
"category",
",",
"bool",
"$",
"editable",
"=",
"true",
")",
":",
"inplace_editable",
"{",
"return",
"new",
"inplace_editable",
"(",
"'core_customfield'",
",",
"'category'",
",",
"$",
"category",
"->",
"get",
"(",
"'id'",
")",
",",
"$",
"editable",
",",
"$",
"category",
"->",
"get_formatted_name",
"(",
")",
",",
"$",
"category",
"->",
"get",
"(",
"'name'",
")",
",",
"get_string",
"(",
"'editcategoryname'",
",",
"'core_customfield'",
")",
",",
"get_string",
"(",
"'newvaluefor'",
",",
"'core_form'",
",",
"format_string",
"(",
"$",
"category",
"->",
"get",
"(",
"'name'",
")",
")",
")",
")",
";",
"}"
] | Returns an object for inplace editable
@param category_controller $category category that needs to be moved
@param bool $editable
@return inplace_editable | [
"Returns",
"an",
"object",
"for",
"inplace",
"editable"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/api.php#L249-L259 |
211,973 | moodle/moodle | customfield/classes/api.php | api.move_category | public static function move_category(category_controller $category, int $beforeid = 0) {
global $DB;
$records = $DB->get_records(category::TABLE, [
'component' => $category->get('component'),
'area' => $category->get('area'),
'itemid' => $category->get('itemid')
], 'sortorder, id', '*');
$id = $category->get('id');
$categoriesids = array_values(array_diff(array_keys($records), [$id]));
$idx = $beforeid ? array_search($beforeid, $categoriesids) : false;
if ($idx === false) {
// Set as the last category.
$categoriesids = array_merge($categoriesids, [$id]);
} else {
// Set before category with id $beforeid.
$categoriesids = array_merge(array_slice($categoriesids, 0, $idx), [$id], array_slice($categoriesids, $idx));
}
foreach (array_values($categoriesids) as $idx => $categoryid) {
// Use persistent class to update the sortorder for each category that needs updating.
if ($records[$categoryid]->sortorder != $idx) {
$c = ($categoryid == $id) ? $category : category_controller::create(0, $records[$categoryid]);
$c->set('sortorder', $idx);
$c->save();
}
}
} | php | public static function move_category(category_controller $category, int $beforeid = 0) {
global $DB;
$records = $DB->get_records(category::TABLE, [
'component' => $category->get('component'),
'area' => $category->get('area'),
'itemid' => $category->get('itemid')
], 'sortorder, id', '*');
$id = $category->get('id');
$categoriesids = array_values(array_diff(array_keys($records), [$id]));
$idx = $beforeid ? array_search($beforeid, $categoriesids) : false;
if ($idx === false) {
// Set as the last category.
$categoriesids = array_merge($categoriesids, [$id]);
} else {
// Set before category with id $beforeid.
$categoriesids = array_merge(array_slice($categoriesids, 0, $idx), [$id], array_slice($categoriesids, $idx));
}
foreach (array_values($categoriesids) as $idx => $categoryid) {
// Use persistent class to update the sortorder for each category that needs updating.
if ($records[$categoryid]->sortorder != $idx) {
$c = ($categoryid == $id) ? $category : category_controller::create(0, $records[$categoryid]);
$c->set('sortorder', $idx);
$c->save();
}
}
} | [
"public",
"static",
"function",
"move_category",
"(",
"category_controller",
"$",
"category",
",",
"int",
"$",
"beforeid",
"=",
"0",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"records",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"category",
"::",
"TABLE",
",",
"[",
"'component'",
"=>",
"$",
"category",
"->",
"get",
"(",
"'component'",
")",
",",
"'area'",
"=>",
"$",
"category",
"->",
"get",
"(",
"'area'",
")",
",",
"'itemid'",
"=>",
"$",
"category",
"->",
"get",
"(",
"'itemid'",
")",
"]",
",",
"'sortorder, id'",
",",
"'*'",
")",
";",
"$",
"id",
"=",
"$",
"category",
"->",
"get",
"(",
"'id'",
")",
";",
"$",
"categoriesids",
"=",
"array_values",
"(",
"array_diff",
"(",
"array_keys",
"(",
"$",
"records",
")",
",",
"[",
"$",
"id",
"]",
")",
")",
";",
"$",
"idx",
"=",
"$",
"beforeid",
"?",
"array_search",
"(",
"$",
"beforeid",
",",
"$",
"categoriesids",
")",
":",
"false",
";",
"if",
"(",
"$",
"idx",
"===",
"false",
")",
"{",
"// Set as the last category.",
"$",
"categoriesids",
"=",
"array_merge",
"(",
"$",
"categoriesids",
",",
"[",
"$",
"id",
"]",
")",
";",
"}",
"else",
"{",
"// Set before category with id $beforeid.",
"$",
"categoriesids",
"=",
"array_merge",
"(",
"array_slice",
"(",
"$",
"categoriesids",
",",
"0",
",",
"$",
"idx",
")",
",",
"[",
"$",
"id",
"]",
",",
"array_slice",
"(",
"$",
"categoriesids",
",",
"$",
"idx",
")",
")",
";",
"}",
"foreach",
"(",
"array_values",
"(",
"$",
"categoriesids",
")",
"as",
"$",
"idx",
"=>",
"$",
"categoryid",
")",
"{",
"// Use persistent class to update the sortorder for each category that needs updating.",
"if",
"(",
"$",
"records",
"[",
"$",
"categoryid",
"]",
"->",
"sortorder",
"!=",
"$",
"idx",
")",
"{",
"$",
"c",
"=",
"(",
"$",
"categoryid",
"==",
"$",
"id",
")",
"?",
"$",
"category",
":",
"category_controller",
"::",
"create",
"(",
"0",
",",
"$",
"records",
"[",
"$",
"categoryid",
"]",
")",
";",
"$",
"c",
"->",
"set",
"(",
"'sortorder'",
",",
"$",
"idx",
")",
";",
"$",
"c",
"->",
"save",
"(",
")",
";",
"}",
"}",
"}"
] | Reorder categories, move given category before another category
@param category_controller $category category that needs to be moved
@param int $beforeid id of the category this category needs to be moved before, 0 to move to the end | [
"Reorder",
"categories",
"move",
"given",
"category",
"before",
"another",
"category"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/api.php#L267-L294 |
211,974 | moodle/moodle | customfield/classes/api.php | api.save_category | public static function save_category(category_controller $category) {
$isnewcategory = empty($category->get('id'));
$category->save();
if ($isnewcategory) {
// Move to the end.
self::move_category($category);
category_created::create_from_object($category)->trigger();
} else {
category_updated::create_from_object($category)->trigger();
}
} | php | public static function save_category(category_controller $category) {
$isnewcategory = empty($category->get('id'));
$category->save();
if ($isnewcategory) {
// Move to the end.
self::move_category($category);
category_created::create_from_object($category)->trigger();
} else {
category_updated::create_from_object($category)->trigger();
}
} | [
"public",
"static",
"function",
"save_category",
"(",
"category_controller",
"$",
"category",
")",
"{",
"$",
"isnewcategory",
"=",
"empty",
"(",
"$",
"category",
"->",
"get",
"(",
"'id'",
")",
")",
";",
"$",
"category",
"->",
"save",
"(",
")",
";",
"if",
"(",
"$",
"isnewcategory",
")",
"{",
"// Move to the end.",
"self",
"::",
"move_category",
"(",
"$",
"category",
")",
";",
"category_created",
"::",
"create_from_object",
"(",
"$",
"category",
")",
"->",
"trigger",
"(",
")",
";",
"}",
"else",
"{",
"category_updated",
"::",
"create_from_object",
"(",
"$",
"category",
")",
"->",
"trigger",
"(",
")",
";",
"}",
"}"
] | Insert or update custom field category
@param category_controller $category | [
"Insert",
"or",
"update",
"custom",
"field",
"category"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/api.php#L301-L313 |
211,975 | moodle/moodle | customfield/classes/api.php | api.delete_category | public static function delete_category(category_controller $category) : bool {
$event = category_deleted::create_from_object($category);
// Delete all fields.
foreach ($category->get_fields() as $field) {
self::delete_field_configuration($field);
}
$result = $category->delete();
$event->trigger();
return $result;
} | php | public static function delete_category(category_controller $category) : bool {
$event = category_deleted::create_from_object($category);
// Delete all fields.
foreach ($category->get_fields() as $field) {
self::delete_field_configuration($field);
}
$result = $category->delete();
$event->trigger();
return $result;
} | [
"public",
"static",
"function",
"delete_category",
"(",
"category_controller",
"$",
"category",
")",
":",
"bool",
"{",
"$",
"event",
"=",
"category_deleted",
"::",
"create_from_object",
"(",
"$",
"category",
")",
";",
"// Delete all fields.",
"foreach",
"(",
"$",
"category",
"->",
"get_fields",
"(",
")",
"as",
"$",
"field",
")",
"{",
"self",
"::",
"delete_field_configuration",
"(",
"$",
"field",
")",
";",
"}",
"$",
"result",
"=",
"$",
"category",
"->",
"delete",
"(",
")",
";",
"$",
"event",
"->",
"trigger",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Delete a custom field category
@param category_controller $category
@return bool | [
"Delete",
"a",
"custom",
"field",
"category"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/api.php#L321-L332 |
211,976 | moodle/moodle | customfield/classes/api.php | api.get_categories_with_fields | public static function get_categories_with_fields(string $component, string $area, int $itemid) : array {
global $DB;
$categories = [];
$options = [
'component' => $component,
'area' => $area,
'itemid' => $itemid
];
$plugins = \core\plugininfo\customfield::get_enabled_plugins();
list($sqlfields, $params) = $DB->get_in_or_equal(array_keys($plugins), SQL_PARAMS_NAMED, 'param', true, null);
$fields = 'f.*, ' . join(', ', array_map(function($field) {
return "c.$field AS category_$field";
}, array_diff(array_keys(category::properties_definition()), ['usermodified', 'timemodified'])));
$sql = "SELECT $fields
FROM {customfield_category} c
LEFT JOIN {customfield_field} f ON c.id = f.categoryid AND f.type $sqlfields
WHERE c.component = :component AND c.area = :area AND c.itemid = :itemid
ORDER BY c.sortorder, f.sortorder";
$fieldsdata = $DB->get_recordset_sql($sql, $options + $params);
foreach ($fieldsdata as $data) {
if (!array_key_exists($data->category_id, $categories)) {
$categoryobj = new \stdClass();
foreach ($data as $key => $value) {
if (preg_match('/^category_(.*)$/', $key, $matches)) {
$categoryobj->{$matches[1]} = $value;
}
}
$category = category_controller::create(0, $categoryobj);
$categories[$categoryobj->id] = $category;
} else {
$category = $categories[$data->categoryid];
}
if ($data->id) {
$fieldobj = new \stdClass();
foreach ($data as $key => $value) {
if (!preg_match('/^category_/', $key)) {
$fieldobj->{$key} = $value;
}
}
$field = field_controller::create(0, $fieldobj, $category);
}
}
$fieldsdata->close();
return $categories;
} | php | public static function get_categories_with_fields(string $component, string $area, int $itemid) : array {
global $DB;
$categories = [];
$options = [
'component' => $component,
'area' => $area,
'itemid' => $itemid
];
$plugins = \core\plugininfo\customfield::get_enabled_plugins();
list($sqlfields, $params) = $DB->get_in_or_equal(array_keys($plugins), SQL_PARAMS_NAMED, 'param', true, null);
$fields = 'f.*, ' . join(', ', array_map(function($field) {
return "c.$field AS category_$field";
}, array_diff(array_keys(category::properties_definition()), ['usermodified', 'timemodified'])));
$sql = "SELECT $fields
FROM {customfield_category} c
LEFT JOIN {customfield_field} f ON c.id = f.categoryid AND f.type $sqlfields
WHERE c.component = :component AND c.area = :area AND c.itemid = :itemid
ORDER BY c.sortorder, f.sortorder";
$fieldsdata = $DB->get_recordset_sql($sql, $options + $params);
foreach ($fieldsdata as $data) {
if (!array_key_exists($data->category_id, $categories)) {
$categoryobj = new \stdClass();
foreach ($data as $key => $value) {
if (preg_match('/^category_(.*)$/', $key, $matches)) {
$categoryobj->{$matches[1]} = $value;
}
}
$category = category_controller::create(0, $categoryobj);
$categories[$categoryobj->id] = $category;
} else {
$category = $categories[$data->categoryid];
}
if ($data->id) {
$fieldobj = new \stdClass();
foreach ($data as $key => $value) {
if (!preg_match('/^category_/', $key)) {
$fieldobj->{$key} = $value;
}
}
$field = field_controller::create(0, $fieldobj, $category);
}
}
$fieldsdata->close();
return $categories;
} | [
"public",
"static",
"function",
"get_categories_with_fields",
"(",
"string",
"$",
"component",
",",
"string",
"$",
"area",
",",
"int",
"$",
"itemid",
")",
":",
"array",
"{",
"global",
"$",
"DB",
";",
"$",
"categories",
"=",
"[",
"]",
";",
"$",
"options",
"=",
"[",
"'component'",
"=>",
"$",
"component",
",",
"'area'",
"=>",
"$",
"area",
",",
"'itemid'",
"=>",
"$",
"itemid",
"]",
";",
"$",
"plugins",
"=",
"\\",
"core",
"\\",
"plugininfo",
"\\",
"customfield",
"::",
"get_enabled_plugins",
"(",
")",
";",
"list",
"(",
"$",
"sqlfields",
",",
"$",
"params",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"array_keys",
"(",
"$",
"plugins",
")",
",",
"SQL_PARAMS_NAMED",
",",
"'param'",
",",
"true",
",",
"null",
")",
";",
"$",
"fields",
"=",
"'f.*, '",
".",
"join",
"(",
"', '",
",",
"array_map",
"(",
"function",
"(",
"$",
"field",
")",
"{",
"return",
"\"c.$field AS category_$field\"",
";",
"}",
",",
"array_diff",
"(",
"array_keys",
"(",
"category",
"::",
"properties_definition",
"(",
")",
")",
",",
"[",
"'usermodified'",
",",
"'timemodified'",
"]",
")",
")",
")",
";",
"$",
"sql",
"=",
"\"SELECT $fields\n FROM {customfield_category} c\n LEFT JOIN {customfield_field} f ON c.id = f.categoryid AND f.type $sqlfields\n WHERE c.component = :component AND c.area = :area AND c.itemid = :itemid\n ORDER BY c.sortorder, f.sortorder\"",
";",
"$",
"fieldsdata",
"=",
"$",
"DB",
"->",
"get_recordset_sql",
"(",
"$",
"sql",
",",
"$",
"options",
"+",
"$",
"params",
")",
";",
"foreach",
"(",
"$",
"fieldsdata",
"as",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"data",
"->",
"category_id",
",",
"$",
"categories",
")",
")",
"{",
"$",
"categoryobj",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/^category_(.*)$/'",
",",
"$",
"key",
",",
"$",
"matches",
")",
")",
"{",
"$",
"categoryobj",
"->",
"{",
"$",
"matches",
"[",
"1",
"]",
"}",
"=",
"$",
"value",
";",
"}",
"}",
"$",
"category",
"=",
"category_controller",
"::",
"create",
"(",
"0",
",",
"$",
"categoryobj",
")",
";",
"$",
"categories",
"[",
"$",
"categoryobj",
"->",
"id",
"]",
"=",
"$",
"category",
";",
"}",
"else",
"{",
"$",
"category",
"=",
"$",
"categories",
"[",
"$",
"data",
"->",
"categoryid",
"]",
";",
"}",
"if",
"(",
"$",
"data",
"->",
"id",
")",
"{",
"$",
"fieldobj",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"'/^category_/'",
",",
"$",
"key",
")",
")",
"{",
"$",
"fieldobj",
"->",
"{",
"$",
"key",
"}",
"=",
"$",
"value",
";",
"}",
"}",
"$",
"field",
"=",
"field_controller",
"::",
"create",
"(",
"0",
",",
"$",
"fieldobj",
",",
"$",
"category",
")",
";",
"}",
"}",
"$",
"fieldsdata",
"->",
"close",
"(",
")",
";",
"return",
"$",
"categories",
";",
"}"
] | Returns a list of categories with their related fields.
@param string $component
@param string $area
@param int $itemid
@return category_controller[] | [
"Returns",
"a",
"list",
"of",
"categories",
"with",
"their",
"related",
"fields",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/api.php#L342-L392 |
211,977 | moodle/moodle | lib/htmlpurifier/HTMLPurifier/ConfigSchema/InterchangeBuilder.php | HTMLPurifier_ConfigSchema_InterchangeBuilder.build | public function build($interchange, $hash)
{
if (!$hash instanceof HTMLPurifier_StringHash) {
$hash = new HTMLPurifier_StringHash($hash);
}
if (!isset($hash['ID'])) {
throw new HTMLPurifier_ConfigSchema_Exception('Hash does not have any ID');
}
if (strpos($hash['ID'], '.') === false) {
if (count($hash) == 2 && isset($hash['DESCRIPTION'])) {
$hash->offsetGet('DESCRIPTION'); // prevent complaining
} else {
throw new HTMLPurifier_ConfigSchema_Exception('All directives must have a namespace');
}
} else {
$this->buildDirective($interchange, $hash);
}
$this->_findUnused($hash);
} | php | public function build($interchange, $hash)
{
if (!$hash instanceof HTMLPurifier_StringHash) {
$hash = new HTMLPurifier_StringHash($hash);
}
if (!isset($hash['ID'])) {
throw new HTMLPurifier_ConfigSchema_Exception('Hash does not have any ID');
}
if (strpos($hash['ID'], '.') === false) {
if (count($hash) == 2 && isset($hash['DESCRIPTION'])) {
$hash->offsetGet('DESCRIPTION'); // prevent complaining
} else {
throw new HTMLPurifier_ConfigSchema_Exception('All directives must have a namespace');
}
} else {
$this->buildDirective($interchange, $hash);
}
$this->_findUnused($hash);
} | [
"public",
"function",
"build",
"(",
"$",
"interchange",
",",
"$",
"hash",
")",
"{",
"if",
"(",
"!",
"$",
"hash",
"instanceof",
"HTMLPurifier_StringHash",
")",
"{",
"$",
"hash",
"=",
"new",
"HTMLPurifier_StringHash",
"(",
"$",
"hash",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"hash",
"[",
"'ID'",
"]",
")",
")",
"{",
"throw",
"new",
"HTMLPurifier_ConfigSchema_Exception",
"(",
"'Hash does not have any ID'",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"hash",
"[",
"'ID'",
"]",
",",
"'.'",
")",
"===",
"false",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"hash",
")",
"==",
"2",
"&&",
"isset",
"(",
"$",
"hash",
"[",
"'DESCRIPTION'",
"]",
")",
")",
"{",
"$",
"hash",
"->",
"offsetGet",
"(",
"'DESCRIPTION'",
")",
";",
"// prevent complaining",
"}",
"else",
"{",
"throw",
"new",
"HTMLPurifier_ConfigSchema_Exception",
"(",
"'All directives must have a namespace'",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"buildDirective",
"(",
"$",
"interchange",
",",
"$",
"hash",
")",
";",
"}",
"$",
"this",
"->",
"_findUnused",
"(",
"$",
"hash",
")",
";",
"}"
] | Builds an interchange object based on a hash.
@param HTMLPurifier_ConfigSchema_Interchange $interchange HTMLPurifier_ConfigSchema_Interchange object to build
@param HTMLPurifier_StringHash $hash source data
@throws HTMLPurifier_ConfigSchema_Exception | [
"Builds",
"an",
"interchange",
"object",
"based",
"on",
"a",
"hash",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/ConfigSchema/InterchangeBuilder.php#L82-L100 |
211,978 | moodle/moodle | lib/htmlpurifier/HTMLPurifier/ConfigSchema/InterchangeBuilder.php | HTMLPurifier_ConfigSchema_InterchangeBuilder._findUnused | protected function _findUnused($hash)
{
$accessed = $hash->getAccessed();
foreach ($hash as $k => $v) {
if (!isset($accessed[$k])) {
trigger_error("String hash key '$k' not used by builder", E_USER_NOTICE);
}
}
} | php | protected function _findUnused($hash)
{
$accessed = $hash->getAccessed();
foreach ($hash as $k => $v) {
if (!isset($accessed[$k])) {
trigger_error("String hash key '$k' not used by builder", E_USER_NOTICE);
}
}
} | [
"protected",
"function",
"_findUnused",
"(",
"$",
"hash",
")",
"{",
"$",
"accessed",
"=",
"$",
"hash",
"->",
"getAccessed",
"(",
")",
";",
"foreach",
"(",
"$",
"hash",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"accessed",
"[",
"$",
"k",
"]",
")",
")",
"{",
"trigger_error",
"(",
"\"String hash key '$k' not used by builder\"",
",",
"E_USER_NOTICE",
")",
";",
"}",
"}",
"}"
] | Triggers errors for any unused keys passed in the hash; such keys
may indicate typos, missing values, etc.
@param HTMLPurifier_StringHash $hash Hash to check. | [
"Triggers",
"errors",
"for",
"any",
"unused",
"keys",
"passed",
"in",
"the",
"hash",
";",
"such",
"keys",
"may",
"indicate",
"typos",
"missing",
"values",
"etc",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/ConfigSchema/InterchangeBuilder.php#L215-L223 |
211,979 | moodle/moodle | availability/condition/grouping/classes/frontend.php | frontend.get_all_groupings | protected function get_all_groupings($courseid) {
global $DB;
if ($courseid != $this->allgroupingscourseid) {
$this->allgroupings = $DB->get_records('groupings',
array('courseid' => $courseid), 'id, name');
$this->allgroupingscourseid = $courseid;
}
return $this->allgroupings;
} | php | protected function get_all_groupings($courseid) {
global $DB;
if ($courseid != $this->allgroupingscourseid) {
$this->allgroupings = $DB->get_records('groupings',
array('courseid' => $courseid), 'id, name');
$this->allgroupingscourseid = $courseid;
}
return $this->allgroupings;
} | [
"protected",
"function",
"get_all_groupings",
"(",
"$",
"courseid",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"$",
"courseid",
"!=",
"$",
"this",
"->",
"allgroupingscourseid",
")",
"{",
"$",
"this",
"->",
"allgroupings",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'groupings'",
",",
"array",
"(",
"'courseid'",
"=>",
"$",
"courseid",
")",
",",
"'id, name'",
")",
";",
"$",
"this",
"->",
"allgroupingscourseid",
"=",
"$",
"courseid",
";",
"}",
"return",
"$",
"this",
"->",
"allgroupings",
";",
"}"
] | Gets all the groupings on the course.
@param int $courseid Course id
@return array Array of grouping objects | [
"Gets",
"all",
"the",
"groupings",
"on",
"the",
"course",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/availability/condition/grouping/classes/frontend.php#L63-L71 |
211,980 | moodle/moodle | admin/tool/lp/classes/form/competency.php | competency.extra_validation | protected function extra_validation($data, $files, array &$errors) {
$newerrors = array();
// Move the error from scaleconfiguration to the form element scale ID.
if (isset($errors['scaleconfiguration']) && !isset($errors['scaleid'])) {
$newerrors['scaleid'] = $errors['scaleconfiguration'];
unset($errors['scaleconfiguration']);
}
return $newerrors;
} | php | protected function extra_validation($data, $files, array &$errors) {
$newerrors = array();
// Move the error from scaleconfiguration to the form element scale ID.
if (isset($errors['scaleconfiguration']) && !isset($errors['scaleid'])) {
$newerrors['scaleid'] = $errors['scaleconfiguration'];
unset($errors['scaleconfiguration']);
}
return $newerrors;
} | [
"protected",
"function",
"extra_validation",
"(",
"$",
"data",
",",
"$",
"files",
",",
"array",
"&",
"$",
"errors",
")",
"{",
"$",
"newerrors",
"=",
"array",
"(",
")",
";",
"// Move the error from scaleconfiguration to the form element scale ID.",
"if",
"(",
"isset",
"(",
"$",
"errors",
"[",
"'scaleconfiguration'",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"errors",
"[",
"'scaleid'",
"]",
")",
")",
"{",
"$",
"newerrors",
"[",
"'scaleid'",
"]",
"=",
"$",
"errors",
"[",
"'scaleconfiguration'",
"]",
";",
"unset",
"(",
"$",
"errors",
"[",
"'scaleconfiguration'",
"]",
")",
";",
"}",
"return",
"$",
"newerrors",
";",
"}"
] | Extra validation.
@param stdClass $data Data to validate.
@param array $files Array of files.
@param array $errors Currently reported errors.
@return array of additional errors, or overridden errors. | [
"Extra",
"validation",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lp/classes/form/competency.php#L161-L169 |
211,981 | moodle/moodle | lib/filestorage/tgz_packer.php | tgz_packer.is_tgz_file | public static function is_tgz_file($archivefile) {
if (is_a($archivefile, 'stored_file')) {
$fp = $archivefile->get_content_file_handle();
} else {
$fp = fopen($archivefile, 'rb');
}
$firstbytes = fread($fp, 2);
fclose($fp);
return ($firstbytes[0] == "\x1f" && $firstbytes[1] == "\x8b");
} | php | public static function is_tgz_file($archivefile) {
if (is_a($archivefile, 'stored_file')) {
$fp = $archivefile->get_content_file_handle();
} else {
$fp = fopen($archivefile, 'rb');
}
$firstbytes = fread($fp, 2);
fclose($fp);
return ($firstbytes[0] == "\x1f" && $firstbytes[1] == "\x8b");
} | [
"public",
"static",
"function",
"is_tgz_file",
"(",
"$",
"archivefile",
")",
"{",
"if",
"(",
"is_a",
"(",
"$",
"archivefile",
",",
"'stored_file'",
")",
")",
"{",
"$",
"fp",
"=",
"$",
"archivefile",
"->",
"get_content_file_handle",
"(",
")",
";",
"}",
"else",
"{",
"$",
"fp",
"=",
"fopen",
"(",
"$",
"archivefile",
",",
"'rb'",
")",
";",
"}",
"$",
"firstbytes",
"=",
"fread",
"(",
"$",
"fp",
",",
"2",
")",
";",
"fclose",
"(",
"$",
"fp",
")",
";",
"return",
"(",
"$",
"firstbytes",
"[",
"0",
"]",
"==",
"\"\\x1f\"",
"&&",
"$",
"firstbytes",
"[",
"1",
"]",
"==",
"\"\\x8b\"",
")",
";",
"}"
] | Checks whether a file appears to be a .tar.gz file.
@param string|stored_file $archivefile
@return bool True if file contains the gzip magic number | [
"Checks",
"whether",
"a",
"file",
"appears",
"to",
"be",
"a",
".",
"tar",
".",
"gz",
"file",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/tgz_packer.php#L711-L720 |
211,982 | moodle/moodle | lib/mathslib.php | calc_formula.localize | public static function localize($formula) {
$formula = str_replace('.', '$', $formula); // temp placeholder
$formula = str_replace(',', get_string('listsep', 'langconfig'), $formula);
$formula = str_replace('$', get_string('decsep', 'langconfig'), $formula);
return $formula;
} | php | public static function localize($formula) {
$formula = str_replace('.', '$', $formula); // temp placeholder
$formula = str_replace(',', get_string('listsep', 'langconfig'), $formula);
$formula = str_replace('$', get_string('decsep', 'langconfig'), $formula);
return $formula;
} | [
"public",
"static",
"function",
"localize",
"(",
"$",
"formula",
")",
"{",
"$",
"formula",
"=",
"str_replace",
"(",
"'.'",
",",
"'$'",
",",
"$",
"formula",
")",
";",
"// temp placeholder",
"$",
"formula",
"=",
"str_replace",
"(",
"','",
",",
"get_string",
"(",
"'listsep'",
",",
"'langconfig'",
")",
",",
"$",
"formula",
")",
";",
"$",
"formula",
"=",
"str_replace",
"(",
"'$'",
",",
"get_string",
"(",
"'decsep'",
",",
"'langconfig'",
")",
",",
"$",
"formula",
")",
";",
"return",
"$",
"formula",
";",
"}"
] | Similar to format_float, formats the numbers and list separators
according to locale specifics.
@param string $formula
@return string localised formula | [
"Similar",
"to",
"format_float",
"formats",
"the",
"numbers",
"and",
"list",
"separators",
"according",
"to",
"locale",
"specifics",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mathslib.php#L125-L130 |
211,983 | moodle/moodle | lib/mathslib.php | calc_formula.unlocalize | public static function unlocalize($formula) {
$formula = str_replace(get_string('decsep', 'langconfig'), '$', $formula);
$formula = str_replace(get_string('listsep', 'langconfig'), ',', $formula);
$formula = str_replace('$', '.', $formula); // temp placeholder
return $formula;
} | php | public static function unlocalize($formula) {
$formula = str_replace(get_string('decsep', 'langconfig'), '$', $formula);
$formula = str_replace(get_string('listsep', 'langconfig'), ',', $formula);
$formula = str_replace('$', '.', $formula); // temp placeholder
return $formula;
} | [
"public",
"static",
"function",
"unlocalize",
"(",
"$",
"formula",
")",
"{",
"$",
"formula",
"=",
"str_replace",
"(",
"get_string",
"(",
"'decsep'",
",",
"'langconfig'",
")",
",",
"'$'",
",",
"$",
"formula",
")",
";",
"$",
"formula",
"=",
"str_replace",
"(",
"get_string",
"(",
"'listsep'",
",",
"'langconfig'",
")",
",",
"','",
",",
"$",
"formula",
")",
";",
"$",
"formula",
"=",
"str_replace",
"(",
"'$'",
",",
"'.'",
",",
"$",
"formula",
")",
";",
"// temp placeholder",
"return",
"$",
"formula",
";",
"}"
] | Similar to unformat_float, converts floats and lists to PHP standards.
@param string $formula localised formula
@return string | [
"Similar",
"to",
"unformat_float",
"converts",
"floats",
"and",
"lists",
"to",
"PHP",
"standards",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mathslib.php#L137-L142 |
211,984 | moodle/moodle | backup/moodle2/backup_course_task.class.php | backup_course_task.encode_links_helper | static private function encode_links_helper($content, $name, $path) {
global $CFG;
// We want to convert both http and https links.
$root = $CFG->wwwroot;
$httpsroot = str_replace('http://', 'https://', $root);
$httproot = str_replace('https://', 'http://', $root);
$httpsbase = preg_quote($httpsroot . $path, '/');
$httpbase = preg_quote($httproot . $path, '/');
$return = preg_replace('/(' . $httpsbase . ')([0-9]+)/', '$@' . $name . '*$2@$', $content);
$return = preg_replace('/(' . $httpbase . ')([0-9]+)/', '$@' . $name . '*$2@$', $return);
return $return;
} | php | static private function encode_links_helper($content, $name, $path) {
global $CFG;
// We want to convert both http and https links.
$root = $CFG->wwwroot;
$httpsroot = str_replace('http://', 'https://', $root);
$httproot = str_replace('https://', 'http://', $root);
$httpsbase = preg_quote($httpsroot . $path, '/');
$httpbase = preg_quote($httproot . $path, '/');
$return = preg_replace('/(' . $httpsbase . ')([0-9]+)/', '$@' . $name . '*$2@$', $content);
$return = preg_replace('/(' . $httpbase . ')([0-9]+)/', '$@' . $name . '*$2@$', $return);
return $return;
} | [
"static",
"private",
"function",
"encode_links_helper",
"(",
"$",
"content",
",",
"$",
"name",
",",
"$",
"path",
")",
"{",
"global",
"$",
"CFG",
";",
"// We want to convert both http and https links.",
"$",
"root",
"=",
"$",
"CFG",
"->",
"wwwroot",
";",
"$",
"httpsroot",
"=",
"str_replace",
"(",
"'http://'",
",",
"'https://'",
",",
"$",
"root",
")",
";",
"$",
"httproot",
"=",
"str_replace",
"(",
"'https://'",
",",
"'http://'",
",",
"$",
"root",
")",
";",
"$",
"httpsbase",
"=",
"preg_quote",
"(",
"$",
"httpsroot",
".",
"$",
"path",
",",
"'/'",
")",
";",
"$",
"httpbase",
"=",
"preg_quote",
"(",
"$",
"httproot",
".",
"$",
"path",
",",
"'/'",
")",
";",
"$",
"return",
"=",
"preg_replace",
"(",
"'/('",
".",
"$",
"httpsbase",
".",
"')([0-9]+)/'",
",",
"'$@'",
".",
"$",
"name",
".",
"'*$2@$'",
",",
"$",
"content",
")",
";",
"$",
"return",
"=",
"preg_replace",
"(",
"'/('",
".",
"$",
"httpbase",
".",
"')([0-9]+)/'",
",",
"'$@'",
".",
"$",
"name",
".",
"'*$2@$'",
",",
"$",
"return",
")",
";",
"return",
"$",
"return",
";",
"}"
] | Helper method, used by encode_content_links.
@param string $content content in which to encode links.
@param string $name the name of this type of encoded link.
@param string $path the path that identifies this type of link, up
to the ?paramname= bit.
@return string content with one type of link encoded. | [
"Helper",
"method",
"used",
"by",
"encode_content_links",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/moodle2/backup_course_task.class.php#L175-L189 |
211,985 | moodle/moodle | mod/assignment/classes/privacy/provider.php | provider.has_marked_assignment_submissions | protected static function has_marked_assignment_submissions($assignmentid, $userid) {
global $DB;
$params = [
'assignment' => $assignmentid,
'teacher' => $userid
];
$sql = "SELECT count(s.id) as nomarked
FROM {assignment_submissions} s
WHERE s.assignment = :assignment
AND s.teacher = :teacher";
$results = $DB->get_record_sql($sql, $params);
return ($results->nomarked > 0) ? true : false;
} | php | protected static function has_marked_assignment_submissions($assignmentid, $userid) {
global $DB;
$params = [
'assignment' => $assignmentid,
'teacher' => $userid
];
$sql = "SELECT count(s.id) as nomarked
FROM {assignment_submissions} s
WHERE s.assignment = :assignment
AND s.teacher = :teacher";
$results = $DB->get_record_sql($sql, $params);
return ($results->nomarked > 0) ? true : false;
} | [
"protected",
"static",
"function",
"has_marked_assignment_submissions",
"(",
"$",
"assignmentid",
",",
"$",
"userid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"params",
"=",
"[",
"'assignment'",
"=>",
"$",
"assignmentid",
",",
"'teacher'",
"=>",
"$",
"userid",
"]",
";",
"$",
"sql",
"=",
"\"SELECT count(s.id) as nomarked\n FROM {assignment_submissions} s\n WHERE s.assignment = :assignment\n AND s.teacher = :teacher\"",
";",
"$",
"results",
"=",
"$",
"DB",
"->",
"get_record_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"return",
"(",
"$",
"results",
"->",
"nomarked",
">",
"0",
")",
"?",
"true",
":",
"false",
";",
"}"
] | Helper function to check if a user has marked assignment submissions for a given assignment.
@param int $assignmentid The assignment ID to check if user has marked associated submissions.
@param int $userid The user ID to check if user has marked associated submissions.
@return bool If user has marked associated submissions returns true, otherwise false.
@throws \dml_exception | [
"Helper",
"function",
"to",
"check",
"if",
"a",
"user",
"has",
"marked",
"assignment",
"submissions",
"for",
"a",
"given",
"assignment",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assignment/classes/privacy/provider.php#L345-L361 |
211,986 | moodle/moodle | mod/assignment/classes/privacy/provider.php | provider.get_assignment_by_context | protected static function get_assignment_by_context($context) {
global $DB;
$params = [
'modulename' => 'assignment',
'contextmodule' => CONTEXT_MODULE,
'contextid' => $context->id
];
$sql = "SELECT a.id,
a.name,
a.intro,
a.assignmenttype,
a.grade,
a.timedue,
a.timeavailable,
a.timemodified
FROM {assignment} a
JOIN {course_modules} cm ON a.id = cm.instance
JOIN {modules} m ON m.id = cm.module AND m.name = :modulename
JOIN {context} ctx ON ctx.instanceid = cm.id AND ctx.contextlevel = :contextmodule
WHERE ctx.id = :contextid";
return $DB->get_record_sql($sql, $params);
} | php | protected static function get_assignment_by_context($context) {
global $DB;
$params = [
'modulename' => 'assignment',
'contextmodule' => CONTEXT_MODULE,
'contextid' => $context->id
];
$sql = "SELECT a.id,
a.name,
a.intro,
a.assignmenttype,
a.grade,
a.timedue,
a.timeavailable,
a.timemodified
FROM {assignment} a
JOIN {course_modules} cm ON a.id = cm.instance
JOIN {modules} m ON m.id = cm.module AND m.name = :modulename
JOIN {context} ctx ON ctx.instanceid = cm.id AND ctx.contextlevel = :contextmodule
WHERE ctx.id = :contextid";
return $DB->get_record_sql($sql, $params);
} | [
"protected",
"static",
"function",
"get_assignment_by_context",
"(",
"$",
"context",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"params",
"=",
"[",
"'modulename'",
"=>",
"'assignment'",
",",
"'contextmodule'",
"=>",
"CONTEXT_MODULE",
",",
"'contextid'",
"=>",
"$",
"context",
"->",
"id",
"]",
";",
"$",
"sql",
"=",
"\"SELECT a.id,\n a.name,\n a.intro,\n a.assignmenttype,\n a.grade,\n a.timedue,\n a.timeavailable,\n a.timemodified\n FROM {assignment} a\n JOIN {course_modules} cm ON a.id = cm.instance\n JOIN {modules} m ON m.id = cm.module AND m.name = :modulename\n JOIN {context} ctx ON ctx.instanceid = cm.id AND ctx.contextlevel = :contextmodule\n WHERE ctx.id = :contextid\"",
";",
"return",
"$",
"DB",
"->",
"get_record_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"}"
] | Helper function to return assignment for a context module.
@param object $context The context module object to return the assignment record by.
@return mixed The assignment details or null record associated with the context module.
@throws \dml_exception | [
"Helper",
"function",
"to",
"return",
"assignment",
"for",
"a",
"context",
"module",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assignment/classes/privacy/provider.php#L370-L394 |
211,987 | moodle/moodle | mod/assignment/classes/privacy/provider.php | provider.get_assignment_output | protected static function get_assignment_output($assignmentdata) {
$assignment = (object) [
'name' => $assignmentdata->name,
'intro' => $assignmentdata->intro,
'assignmenttype' => $assignmentdata->assignmenttype,
'grade' => $assignmentdata->grade,
'timemodified' => transform::datetime($assignmentdata->timemodified)
];
if ($assignmentdata->timeavailable != 0) {
$assignment->timeavailable = transform::datetime($assignmentdata->timeavailable);
}
if ($assignmentdata->timedue != 0) {
$assignment->timedue = transform::datetime($assignmentdata->timedue);
}
return $assignment;
} | php | protected static function get_assignment_output($assignmentdata) {
$assignment = (object) [
'name' => $assignmentdata->name,
'intro' => $assignmentdata->intro,
'assignmenttype' => $assignmentdata->assignmenttype,
'grade' => $assignmentdata->grade,
'timemodified' => transform::datetime($assignmentdata->timemodified)
];
if ($assignmentdata->timeavailable != 0) {
$assignment->timeavailable = transform::datetime($assignmentdata->timeavailable);
}
if ($assignmentdata->timedue != 0) {
$assignment->timedue = transform::datetime($assignmentdata->timedue);
}
return $assignment;
} | [
"protected",
"static",
"function",
"get_assignment_output",
"(",
"$",
"assignmentdata",
")",
"{",
"$",
"assignment",
"=",
"(",
"object",
")",
"[",
"'name'",
"=>",
"$",
"assignmentdata",
"->",
"name",
",",
"'intro'",
"=>",
"$",
"assignmentdata",
"->",
"intro",
",",
"'assignmenttype'",
"=>",
"$",
"assignmentdata",
"->",
"assignmenttype",
",",
"'grade'",
"=>",
"$",
"assignmentdata",
"->",
"grade",
",",
"'timemodified'",
"=>",
"transform",
"::",
"datetime",
"(",
"$",
"assignmentdata",
"->",
"timemodified",
")",
"]",
";",
"if",
"(",
"$",
"assignmentdata",
"->",
"timeavailable",
"!=",
"0",
")",
"{",
"$",
"assignment",
"->",
"timeavailable",
"=",
"transform",
"::",
"datetime",
"(",
"$",
"assignmentdata",
"->",
"timeavailable",
")",
";",
"}",
"if",
"(",
"$",
"assignmentdata",
"->",
"timedue",
"!=",
"0",
")",
"{",
"$",
"assignment",
"->",
"timedue",
"=",
"transform",
"::",
"datetime",
"(",
"$",
"assignmentdata",
"->",
"timedue",
")",
";",
"}",
"return",
"$",
"assignment",
";",
"}"
] | Helper function generate assignment output object for exporting.
@param object $assignmentdata Object containing assignment data.
@return object Formatted assignment output object for exporting. | [
"Helper",
"function",
"generate",
"assignment",
"output",
"object",
"for",
"exporting",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assignment/classes/privacy/provider.php#L497-L515 |
211,988 | moodle/moodle | mod/assignment/classes/privacy/provider.php | provider.get_assignment_submission_output | protected static function get_assignment_submission_output($submissiondata) {
$submission = (object) [
'assignment' => $submissiondata->assignment,
'numfiles' => $submissiondata->numfiles,
'data1' => $submissiondata->data1,
'data2' => $submissiondata->data2,
'grade' => $submissiondata->grade,
'submissioncomment' => $submissiondata->submissioncomment,
'teacher' => transform::user($submissiondata->teacher)
];
if ($submissiondata->timecreated != 0) {
$submission->timecreated = transform::datetime($submissiondata->timecreated);
}
if ($submissiondata->timemarked != 0) {
$submission->timemarked = transform::datetime($submissiondata->timemarked);
}
if ($submissiondata->timemodified != 0) {
$submission->timemodified = transform::datetime($submissiondata->timemodified);
}
return $submission;
} | php | protected static function get_assignment_submission_output($submissiondata) {
$submission = (object) [
'assignment' => $submissiondata->assignment,
'numfiles' => $submissiondata->numfiles,
'data1' => $submissiondata->data1,
'data2' => $submissiondata->data2,
'grade' => $submissiondata->grade,
'submissioncomment' => $submissiondata->submissioncomment,
'teacher' => transform::user($submissiondata->teacher)
];
if ($submissiondata->timecreated != 0) {
$submission->timecreated = transform::datetime($submissiondata->timecreated);
}
if ($submissiondata->timemarked != 0) {
$submission->timemarked = transform::datetime($submissiondata->timemarked);
}
if ($submissiondata->timemodified != 0) {
$submission->timemodified = transform::datetime($submissiondata->timemodified);
}
return $submission;
} | [
"protected",
"static",
"function",
"get_assignment_submission_output",
"(",
"$",
"submissiondata",
")",
"{",
"$",
"submission",
"=",
"(",
"object",
")",
"[",
"'assignment'",
"=>",
"$",
"submissiondata",
"->",
"assignment",
",",
"'numfiles'",
"=>",
"$",
"submissiondata",
"->",
"numfiles",
",",
"'data1'",
"=>",
"$",
"submissiondata",
"->",
"data1",
",",
"'data2'",
"=>",
"$",
"submissiondata",
"->",
"data2",
",",
"'grade'",
"=>",
"$",
"submissiondata",
"->",
"grade",
",",
"'submissioncomment'",
"=>",
"$",
"submissiondata",
"->",
"submissioncomment",
",",
"'teacher'",
"=>",
"transform",
"::",
"user",
"(",
"$",
"submissiondata",
"->",
"teacher",
")",
"]",
";",
"if",
"(",
"$",
"submissiondata",
"->",
"timecreated",
"!=",
"0",
")",
"{",
"$",
"submission",
"->",
"timecreated",
"=",
"transform",
"::",
"datetime",
"(",
"$",
"submissiondata",
"->",
"timecreated",
")",
";",
"}",
"if",
"(",
"$",
"submissiondata",
"->",
"timemarked",
"!=",
"0",
")",
"{",
"$",
"submission",
"->",
"timemarked",
"=",
"transform",
"::",
"datetime",
"(",
"$",
"submissiondata",
"->",
"timemarked",
")",
";",
"}",
"if",
"(",
"$",
"submissiondata",
"->",
"timemodified",
"!=",
"0",
")",
"{",
"$",
"submission",
"->",
"timemodified",
"=",
"transform",
"::",
"datetime",
"(",
"$",
"submissiondata",
"->",
"timemodified",
")",
";",
"}",
"return",
"$",
"submission",
";",
"}"
] | Helper function generate assignment submission output object for exporting.
@param object $submissiondata Object containing assignment submission data.
@return object Formatted assignment submission output for exporting. | [
"Helper",
"function",
"generate",
"assignment",
"submission",
"output",
"object",
"for",
"exporting",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assignment/classes/privacy/provider.php#L523-L547 |
211,989 | moodle/moodle | admin/tool/policy/classes/external.php | external.get_policy_version | public static function get_policy_version($versionid, $behalfid = null) {
global $PAGE;
$result = [];
$warnings = [];
$params = external_api::validate_parameters(self::get_policy_version_parameters(), [
'versionid' => $versionid,
'behalfid' => $behalfid
]);
$versionid = $params['versionid'];
$behalfid = $params['behalfid'];
$context = context_system::instance();
$PAGE->set_context($context);
try {
// Validate if the user has access to the policy version.
$version = api::get_policy_version($versionid);
if (!api::can_user_view_policy_version($version, $behalfid)) {
$warnings[] = [
'item' => $versionid,
'warningcode' => 'errorusercantviewpolicyversion',
'message' => get_string('errorusercantviewpolicyversion', 'tool_policy')
];
} else if (!empty($version)) {
$version = api::get_policy_version($versionid);
$policy['name'] = $version->name;
$policy['versionid'] = $versionid;
list($policy['content'], $notusedformat) = external_format_text(
$version->content,
$version->contentformat,
SYSCONTEXTID,
'tool_policy',
'policydocumentcontent',
$version->id
);
$result['policy'] = $policy;
}
} catch (moodle_exception $e) {
$warnings[] = [
'item' => $versionid,
'warningcode' => 'errorpolicyversionnotfound',
'message' => get_string('errorpolicyversionnotfound', 'tool_policy')
];
}
return [
'result' => $result,
'warnings' => $warnings
];
} | php | public static function get_policy_version($versionid, $behalfid = null) {
global $PAGE;
$result = [];
$warnings = [];
$params = external_api::validate_parameters(self::get_policy_version_parameters(), [
'versionid' => $versionid,
'behalfid' => $behalfid
]);
$versionid = $params['versionid'];
$behalfid = $params['behalfid'];
$context = context_system::instance();
$PAGE->set_context($context);
try {
// Validate if the user has access to the policy version.
$version = api::get_policy_version($versionid);
if (!api::can_user_view_policy_version($version, $behalfid)) {
$warnings[] = [
'item' => $versionid,
'warningcode' => 'errorusercantviewpolicyversion',
'message' => get_string('errorusercantviewpolicyversion', 'tool_policy')
];
} else if (!empty($version)) {
$version = api::get_policy_version($versionid);
$policy['name'] = $version->name;
$policy['versionid'] = $versionid;
list($policy['content'], $notusedformat) = external_format_text(
$version->content,
$version->contentformat,
SYSCONTEXTID,
'tool_policy',
'policydocumentcontent',
$version->id
);
$result['policy'] = $policy;
}
} catch (moodle_exception $e) {
$warnings[] = [
'item' => $versionid,
'warningcode' => 'errorpolicyversionnotfound',
'message' => get_string('errorpolicyversionnotfound', 'tool_policy')
];
}
return [
'result' => $result,
'warnings' => $warnings
];
} | [
"public",
"static",
"function",
"get_policy_version",
"(",
"$",
"versionid",
",",
"$",
"behalfid",
"=",
"null",
")",
"{",
"global",
"$",
"PAGE",
";",
"$",
"result",
"=",
"[",
"]",
";",
"$",
"warnings",
"=",
"[",
"]",
";",
"$",
"params",
"=",
"external_api",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_policy_version_parameters",
"(",
")",
",",
"[",
"'versionid'",
"=>",
"$",
"versionid",
",",
"'behalfid'",
"=>",
"$",
"behalfid",
"]",
")",
";",
"$",
"versionid",
"=",
"$",
"params",
"[",
"'versionid'",
"]",
";",
"$",
"behalfid",
"=",
"$",
"params",
"[",
"'behalfid'",
"]",
";",
"$",
"context",
"=",
"context_system",
"::",
"instance",
"(",
")",
";",
"$",
"PAGE",
"->",
"set_context",
"(",
"$",
"context",
")",
";",
"try",
"{",
"// Validate if the user has access to the policy version.",
"$",
"version",
"=",
"api",
"::",
"get_policy_version",
"(",
"$",
"versionid",
")",
";",
"if",
"(",
"!",
"api",
"::",
"can_user_view_policy_version",
"(",
"$",
"version",
",",
"$",
"behalfid",
")",
")",
"{",
"$",
"warnings",
"[",
"]",
"=",
"[",
"'item'",
"=>",
"$",
"versionid",
",",
"'warningcode'",
"=>",
"'errorusercantviewpolicyversion'",
",",
"'message'",
"=>",
"get_string",
"(",
"'errorusercantviewpolicyversion'",
",",
"'tool_policy'",
")",
"]",
";",
"}",
"else",
"if",
"(",
"!",
"empty",
"(",
"$",
"version",
")",
")",
"{",
"$",
"version",
"=",
"api",
"::",
"get_policy_version",
"(",
"$",
"versionid",
")",
";",
"$",
"policy",
"[",
"'name'",
"]",
"=",
"$",
"version",
"->",
"name",
";",
"$",
"policy",
"[",
"'versionid'",
"]",
"=",
"$",
"versionid",
";",
"list",
"(",
"$",
"policy",
"[",
"'content'",
"]",
",",
"$",
"notusedformat",
")",
"=",
"external_format_text",
"(",
"$",
"version",
"->",
"content",
",",
"$",
"version",
"->",
"contentformat",
",",
"SYSCONTEXTID",
",",
"'tool_policy'",
",",
"'policydocumentcontent'",
",",
"$",
"version",
"->",
"id",
")",
";",
"$",
"result",
"[",
"'policy'",
"]",
"=",
"$",
"policy",
";",
"}",
"}",
"catch",
"(",
"moodle_exception",
"$",
"e",
")",
"{",
"$",
"warnings",
"[",
"]",
"=",
"[",
"'item'",
"=>",
"$",
"versionid",
",",
"'warningcode'",
"=>",
"'errorpolicyversionnotfound'",
",",
"'message'",
"=>",
"get_string",
"(",
"'errorpolicyversionnotfound'",
",",
"'tool_policy'",
")",
"]",
";",
"}",
"return",
"[",
"'result'",
"=>",
"$",
"result",
",",
"'warnings'",
"=>",
"$",
"warnings",
"]",
";",
"}"
] | Fetch the details of a policy version.
@param int $versionid The policy version ID.
@param int $behalfid The id of user on whose behalf the user is viewing the policy.
@return array
@throws coding_exception
@throws dml_exception
@throws invalid_parameter_exception
@throws restricted_context_exception
@throws moodle_exception | [
"Fetch",
"the",
"details",
"of",
"a",
"policy",
"version",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/external.php#L81-L131 |
211,990 | moodle/moodle | admin/tool/policy/classes/external.php | external.submit_accept_on_behalf | public static function submit_accept_on_behalf($jsonformdata) {
// We always must pass webservice params through validate_parameters.
$params = self::validate_parameters(self::submit_accept_on_behalf_parameters(),
['jsonformdata' => $jsonformdata]);
self::validate_context(context_system::instance());
$serialiseddata = json_decode($params['jsonformdata']);
$data = array();
parse_str($serialiseddata, $data);
// The last param is the ajax submitted data.
$mform = new accept_policy(null, $data, 'post', '', null, true, $data);
// Do the action.
$mform->process();
return true;
} | php | public static function submit_accept_on_behalf($jsonformdata) {
// We always must pass webservice params through validate_parameters.
$params = self::validate_parameters(self::submit_accept_on_behalf_parameters(),
['jsonformdata' => $jsonformdata]);
self::validate_context(context_system::instance());
$serialiseddata = json_decode($params['jsonformdata']);
$data = array();
parse_str($serialiseddata, $data);
// The last param is the ajax submitted data.
$mform = new accept_policy(null, $data, 'post', '', null, true, $data);
// Do the action.
$mform->process();
return true;
} | [
"public",
"static",
"function",
"submit_accept_on_behalf",
"(",
"$",
"jsonformdata",
")",
"{",
"// We always must pass webservice params through validate_parameters.",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"submit_accept_on_behalf_parameters",
"(",
")",
",",
"[",
"'jsonformdata'",
"=>",
"$",
"jsonformdata",
"]",
")",
";",
"self",
"::",
"validate_context",
"(",
"context_system",
"::",
"instance",
"(",
")",
")",
";",
"$",
"serialiseddata",
"=",
"json_decode",
"(",
"$",
"params",
"[",
"'jsonformdata'",
"]",
")",
";",
"$",
"data",
"=",
"array",
"(",
")",
";",
"parse_str",
"(",
"$",
"serialiseddata",
",",
"$",
"data",
")",
";",
"// The last param is the ajax submitted data.",
"$",
"mform",
"=",
"new",
"accept_policy",
"(",
"null",
",",
"$",
"data",
",",
"'post'",
",",
"''",
",",
"null",
",",
"true",
",",
"$",
"data",
")",
";",
"// Do the action.",
"$",
"mform",
"->",
"process",
"(",
")",
";",
"return",
"true",
";",
"}"
] | Submit the create group form.
@param string $jsonformdata The data from the form, encoded as a json array.
@return int new group id. | [
"Submit",
"the",
"create",
"group",
"form",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/external.php#L169-L188 |
211,991 | moodle/moodle | lib/htmlpurifier/HTMLPurifier/StringHashParser.php | HTMLPurifier_StringHashParser.parseFile | public function parseFile($file)
{
if (!file_exists($file)) {
return false;
}
$fh = fopen($file, 'r');
if (!$fh) {
return false;
}
$ret = $this->parseHandle($fh);
fclose($fh);
return $ret;
} | php | public function parseFile($file)
{
if (!file_exists($file)) {
return false;
}
$fh = fopen($file, 'r');
if (!$fh) {
return false;
}
$ret = $this->parseHandle($fh);
fclose($fh);
return $ret;
} | [
"public",
"function",
"parseFile",
"(",
"$",
"file",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"file",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"fh",
"=",
"fopen",
"(",
"$",
"file",
",",
"'r'",
")",
";",
"if",
"(",
"!",
"$",
"fh",
")",
"{",
"return",
"false",
";",
"}",
"$",
"ret",
"=",
"$",
"this",
"->",
"parseHandle",
"(",
"$",
"fh",
")",
";",
"fclose",
"(",
"$",
"fh",
")",
";",
"return",
"$",
"ret",
";",
"}"
] | Parses a file that contains a single string-hash.
@param string $file
@return array | [
"Parses",
"a",
"file",
"that",
"contains",
"a",
"single",
"string",
"-",
"hash",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/StringHashParser.php#L41-L53 |
211,992 | moodle/moodle | lib/htmlpurifier/HTMLPurifier/StringHashParser.php | HTMLPurifier_StringHashParser.parseHandle | protected function parseHandle($fh)
{
$state = false;
$single = false;
$ret = array();
do {
$line = fgets($fh);
if ($line === false) {
break;
}
$line = rtrim($line, "\n\r");
if (!$state && $line === '') {
continue;
}
if ($line === '----') {
break;
}
if (strncmp('--#', $line, 3) === 0) {
// Comment
continue;
} elseif (strncmp('--', $line, 2) === 0) {
// Multiline declaration
$state = trim($line, '- ');
if (!isset($ret[$state])) {
$ret[$state] = '';
}
continue;
} elseif (!$state) {
$single = true;
if (strpos($line, ':') !== false) {
// Single-line declaration
list($state, $line) = explode(':', $line, 2);
$line = trim($line);
} else {
// Use default declaration
$state = $this->default;
}
}
if ($single) {
$ret[$state] = $line;
$single = false;
$state = false;
} else {
$ret[$state] .= "$line\n";
}
} while (!feof($fh));
return $ret;
} | php | protected function parseHandle($fh)
{
$state = false;
$single = false;
$ret = array();
do {
$line = fgets($fh);
if ($line === false) {
break;
}
$line = rtrim($line, "\n\r");
if (!$state && $line === '') {
continue;
}
if ($line === '----') {
break;
}
if (strncmp('--#', $line, 3) === 0) {
// Comment
continue;
} elseif (strncmp('--', $line, 2) === 0) {
// Multiline declaration
$state = trim($line, '- ');
if (!isset($ret[$state])) {
$ret[$state] = '';
}
continue;
} elseif (!$state) {
$single = true;
if (strpos($line, ':') !== false) {
// Single-line declaration
list($state, $line) = explode(':', $line, 2);
$line = trim($line);
} else {
// Use default declaration
$state = $this->default;
}
}
if ($single) {
$ret[$state] = $line;
$single = false;
$state = false;
} else {
$ret[$state] .= "$line\n";
}
} while (!feof($fh));
return $ret;
} | [
"protected",
"function",
"parseHandle",
"(",
"$",
"fh",
")",
"{",
"$",
"state",
"=",
"false",
";",
"$",
"single",
"=",
"false",
";",
"$",
"ret",
"=",
"array",
"(",
")",
";",
"do",
"{",
"$",
"line",
"=",
"fgets",
"(",
"$",
"fh",
")",
";",
"if",
"(",
"$",
"line",
"===",
"false",
")",
"{",
"break",
";",
"}",
"$",
"line",
"=",
"rtrim",
"(",
"$",
"line",
",",
"\"\\n\\r\"",
")",
";",
"if",
"(",
"!",
"$",
"state",
"&&",
"$",
"line",
"===",
"''",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"line",
"===",
"'----'",
")",
"{",
"break",
";",
"}",
"if",
"(",
"strncmp",
"(",
"'--#'",
",",
"$",
"line",
",",
"3",
")",
"===",
"0",
")",
"{",
"// Comment",
"continue",
";",
"}",
"elseif",
"(",
"strncmp",
"(",
"'--'",
",",
"$",
"line",
",",
"2",
")",
"===",
"0",
")",
"{",
"// Multiline declaration",
"$",
"state",
"=",
"trim",
"(",
"$",
"line",
",",
"'- '",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"ret",
"[",
"$",
"state",
"]",
")",
")",
"{",
"$",
"ret",
"[",
"$",
"state",
"]",
"=",
"''",
";",
"}",
"continue",
";",
"}",
"elseif",
"(",
"!",
"$",
"state",
")",
"{",
"$",
"single",
"=",
"true",
";",
"if",
"(",
"strpos",
"(",
"$",
"line",
",",
"':'",
")",
"!==",
"false",
")",
"{",
"// Single-line declaration",
"list",
"(",
"$",
"state",
",",
"$",
"line",
")",
"=",
"explode",
"(",
"':'",
",",
"$",
"line",
",",
"2",
")",
";",
"$",
"line",
"=",
"trim",
"(",
"$",
"line",
")",
";",
"}",
"else",
"{",
"// Use default declaration",
"$",
"state",
"=",
"$",
"this",
"->",
"default",
";",
"}",
"}",
"if",
"(",
"$",
"single",
")",
"{",
"$",
"ret",
"[",
"$",
"state",
"]",
"=",
"$",
"line",
";",
"$",
"single",
"=",
"false",
";",
"$",
"state",
"=",
"false",
";",
"}",
"else",
"{",
"$",
"ret",
"[",
"$",
"state",
"]",
".=",
"\"$line\\n\"",
";",
"}",
"}",
"while",
"(",
"!",
"feof",
"(",
"$",
"fh",
")",
")",
";",
"return",
"$",
"ret",
";",
"}"
] | Internal parser that acepts a file handle.
@note While it's possible to simulate in-memory parsing by using
custom stream wrappers, if such a use-case arises we should
factor out the file handle into its own class.
@param resource $fh File handle with pointer at start of valid string-hash
block.
@return array | [
"Internal",
"parser",
"that",
"acepts",
"a",
"file",
"handle",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/StringHashParser.php#L86-L133 |
211,993 | moodle/moodle | lib/mustache/src/Mustache/Template.php | Mustache_Template.prepareContextStack | protected function prepareContextStack($context = null)
{
$stack = new Mustache_Context();
$helpers = $this->mustache->getHelpers();
if (!$helpers->isEmpty()) {
$stack->push($helpers);
}
if (!empty($context)) {
$stack->push($context);
}
return $stack;
} | php | protected function prepareContextStack($context = null)
{
$stack = new Mustache_Context();
$helpers = $this->mustache->getHelpers();
if (!$helpers->isEmpty()) {
$stack->push($helpers);
}
if (!empty($context)) {
$stack->push($context);
}
return $stack;
} | [
"protected",
"function",
"prepareContextStack",
"(",
"$",
"context",
"=",
"null",
")",
"{",
"$",
"stack",
"=",
"new",
"Mustache_Context",
"(",
")",
";",
"$",
"helpers",
"=",
"$",
"this",
"->",
"mustache",
"->",
"getHelpers",
"(",
")",
";",
"if",
"(",
"!",
"$",
"helpers",
"->",
"isEmpty",
"(",
")",
")",
"{",
"$",
"stack",
"->",
"push",
"(",
"$",
"helpers",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"context",
")",
")",
"{",
"$",
"stack",
"->",
"push",
"(",
"$",
"context",
")",
";",
"}",
"return",
"$",
"stack",
";",
"}"
] | Helper method to prepare the Context stack.
Adds the Mustache HelperCollection to the stack's top context frame if helpers are present.
@param mixed $context Optional first context frame (default: null)
@return Mustache_Context | [
"Helper",
"method",
"to",
"prepare",
"the",
"Context",
"stack",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Template.php#L144-L158 |
211,994 | moodle/moodle | lib/mustache/src/Mustache/Template.php | Mustache_Template.resolveValue | protected function resolveValue($value, Mustache_Context $context)
{
if (($this->strictCallables ? is_object($value) : !is_string($value)) && is_callable($value)) {
return $this->mustache
->loadLambda((string) call_user_func($value))
->renderInternal($context);
}
return $value;
} | php | protected function resolveValue($value, Mustache_Context $context)
{
if (($this->strictCallables ? is_object($value) : !is_string($value)) && is_callable($value)) {
return $this->mustache
->loadLambda((string) call_user_func($value))
->renderInternal($context);
}
return $value;
} | [
"protected",
"function",
"resolveValue",
"(",
"$",
"value",
",",
"Mustache_Context",
"$",
"context",
")",
"{",
"if",
"(",
"(",
"$",
"this",
"->",
"strictCallables",
"?",
"is_object",
"(",
"$",
"value",
")",
":",
"!",
"is_string",
"(",
"$",
"value",
")",
")",
"&&",
"is_callable",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"this",
"->",
"mustache",
"->",
"loadLambda",
"(",
"(",
"string",
")",
"call_user_func",
"(",
"$",
"value",
")",
")",
"->",
"renderInternal",
"(",
"$",
"context",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Resolve a context value.
Invoke the value if it is callable, otherwise return the value.
@param mixed $value
@param Mustache_Context $context
@return string | [
"Resolve",
"a",
"context",
"value",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Template.php#L170-L179 |
211,995 | moodle/moodle | user/profile/index_category_form.php | category_form.validation | public function validation($data, $files) {
global $CFG, $DB;
$errors = parent::validation($data, $files);
$data = (object)$data;
$duplicate = $DB->get_field('user_info_category', 'id', array('name' => $data->name));
// Check the name is unique.
if (!empty($data->id)) { // We are editing an existing record.
$olddata = $DB->get_record('user_info_category', array('id' => $data->id));
// Name has changed, new name in use, new name in use by another record.
$dupfound = (($olddata->name !== $data->name) && $duplicate && ($data->id != $duplicate));
} else { // New profile category.
$dupfound = $duplicate;
}
if ($dupfound ) {
$errors['name'] = get_string('profilecategorynamenotunique', 'admin');
}
return $errors;
} | php | public function validation($data, $files) {
global $CFG, $DB;
$errors = parent::validation($data, $files);
$data = (object)$data;
$duplicate = $DB->get_field('user_info_category', 'id', array('name' => $data->name));
// Check the name is unique.
if (!empty($data->id)) { // We are editing an existing record.
$olddata = $DB->get_record('user_info_category', array('id' => $data->id));
// Name has changed, new name in use, new name in use by another record.
$dupfound = (($olddata->name !== $data->name) && $duplicate && ($data->id != $duplicate));
} else { // New profile category.
$dupfound = $duplicate;
}
if ($dupfound ) {
$errors['name'] = get_string('profilecategorynamenotunique', 'admin');
}
return $errors;
} | [
"public",
"function",
"validation",
"(",
"$",
"data",
",",
"$",
"files",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
";",
"$",
"errors",
"=",
"parent",
"::",
"validation",
"(",
"$",
"data",
",",
"$",
"files",
")",
";",
"$",
"data",
"=",
"(",
"object",
")",
"$",
"data",
";",
"$",
"duplicate",
"=",
"$",
"DB",
"->",
"get_field",
"(",
"'user_info_category'",
",",
"'id'",
",",
"array",
"(",
"'name'",
"=>",
"$",
"data",
"->",
"name",
")",
")",
";",
"// Check the name is unique.",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"->",
"id",
")",
")",
"{",
"// We are editing an existing record.",
"$",
"olddata",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'user_info_category'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"data",
"->",
"id",
")",
")",
";",
"// Name has changed, new name in use, new name in use by another record.",
"$",
"dupfound",
"=",
"(",
"(",
"$",
"olddata",
"->",
"name",
"!==",
"$",
"data",
"->",
"name",
")",
"&&",
"$",
"duplicate",
"&&",
"(",
"$",
"data",
"->",
"id",
"!=",
"$",
"duplicate",
")",
")",
";",
"}",
"else",
"{",
"// New profile category.",
"$",
"dupfound",
"=",
"$",
"duplicate",
";",
"}",
"if",
"(",
"$",
"dupfound",
")",
"{",
"$",
"errors",
"[",
"'name'",
"]",
"=",
"get_string",
"(",
"'profilecategorynamenotunique'",
",",
"'admin'",
")",
";",
"}",
"return",
"$",
"errors",
";",
"}"
] | Perform some moodle validation.
@param array $data
@param array $files
@return array | [
"Perform",
"some",
"moodle",
"validation",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/profile/index_category_form.php#L70-L92 |
211,996 | moodle/moodle | lib/coursecatlib.php | coursecat_sortable_records.sort | public static function sort(array $records, array $fields) {
$records = new coursecat_sortable_records($records);
$records->sortfields = $fields;
$records->uasort(array($records, 'sort_by_many_fields'));
return $records->getArrayCopy();
} | php | public static function sort(array $records, array $fields) {
$records = new coursecat_sortable_records($records);
$records->sortfields = $fields;
$records->uasort(array($records, 'sort_by_many_fields'));
return $records->getArrayCopy();
} | [
"public",
"static",
"function",
"sort",
"(",
"array",
"$",
"records",
",",
"array",
"$",
"fields",
")",
"{",
"$",
"records",
"=",
"new",
"coursecat_sortable_records",
"(",
"$",
"records",
")",
";",
"$",
"records",
"->",
"sortfields",
"=",
"$",
"fields",
";",
"$",
"records",
"->",
"uasort",
"(",
"array",
"(",
"$",
"records",
",",
"'sort_by_many_fields'",
")",
")",
";",
"return",
"$",
"records",
"->",
"getArrayCopy",
"(",
")",
";",
"}"
] | Sorts this array using the given fields.
@param array $records
@param array $fields
@return array | [
"Sorts",
"this",
"array",
"using",
"the",
"given",
"fields",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/coursecatlib.php#L59-L64 |
211,997 | moodle/moodle | lib/coursecatlib.php | coursecat_sortable_records.sort_by_many_fields | public function sort_by_many_fields($a, $b) {
foreach ($this->sortfields as $field => $mult) {
// Nulls first.
if (is_null($a->$field) && !is_null($b->$field)) {
return -$mult;
}
if (is_null($b->$field) && !is_null($a->$field)) {
return $mult;
}
if (is_string($a->$field) || is_string($b->$field)) {
// String fields.
if ($cmp = strcoll($a->$field, $b->$field)) {
return $mult * $cmp;
}
} else {
// Int fields.
if ($a->$field > $b->$field) {
return $mult;
}
if ($a->$field < $b->$field) {
return -$mult;
}
}
}
return 0;
} | php | public function sort_by_many_fields($a, $b) {
foreach ($this->sortfields as $field => $mult) {
// Nulls first.
if (is_null($a->$field) && !is_null($b->$field)) {
return -$mult;
}
if (is_null($b->$field) && !is_null($a->$field)) {
return $mult;
}
if (is_string($a->$field) || is_string($b->$field)) {
// String fields.
if ($cmp = strcoll($a->$field, $b->$field)) {
return $mult * $cmp;
}
} else {
// Int fields.
if ($a->$field > $b->$field) {
return $mult;
}
if ($a->$field < $b->$field) {
return -$mult;
}
}
}
return 0;
} | [
"public",
"function",
"sort_by_many_fields",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"sortfields",
"as",
"$",
"field",
"=>",
"$",
"mult",
")",
"{",
"// Nulls first.",
"if",
"(",
"is_null",
"(",
"$",
"a",
"->",
"$",
"field",
")",
"&&",
"!",
"is_null",
"(",
"$",
"b",
"->",
"$",
"field",
")",
")",
"{",
"return",
"-",
"$",
"mult",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"b",
"->",
"$",
"field",
")",
"&&",
"!",
"is_null",
"(",
"$",
"a",
"->",
"$",
"field",
")",
")",
"{",
"return",
"$",
"mult",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"a",
"->",
"$",
"field",
")",
"||",
"is_string",
"(",
"$",
"b",
"->",
"$",
"field",
")",
")",
"{",
"// String fields.",
"if",
"(",
"$",
"cmp",
"=",
"strcoll",
"(",
"$",
"a",
"->",
"$",
"field",
",",
"$",
"b",
"->",
"$",
"field",
")",
")",
"{",
"return",
"$",
"mult",
"*",
"$",
"cmp",
";",
"}",
"}",
"else",
"{",
"// Int fields.",
"if",
"(",
"$",
"a",
"->",
"$",
"field",
">",
"$",
"b",
"->",
"$",
"field",
")",
"{",
"return",
"$",
"mult",
";",
"}",
"if",
"(",
"$",
"a",
"->",
"$",
"field",
"<",
"$",
"b",
"->",
"$",
"field",
")",
"{",
"return",
"-",
"$",
"mult",
";",
"}",
"}",
"}",
"return",
"0",
";",
"}"
] | Sorts the two records based upon many fields.
This method should not be called itself, please call $sort instead.
It has been marked as access private as such.
@access private
@param stdClass $a
@param stdClass $b
@return int | [
"Sorts",
"the",
"two",
"records",
"based",
"upon",
"many",
"fields",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/coursecatlib.php#L77-L103 |
211,998 | moodle/moodle | webservice/xmlrpc/lib.php | webservice_xmlrpc_client.encode_request | protected function encode_request($functionname, $params) {
$outputoptions = array(
'encoding' => 'utf-8',
'escaping' => 'markup',
);
// See MDL-53962 - needed for backwards compatibility on <= 3.0.
$params = array_values($params);
return xmlrpc_encode_request($functionname, $params, $outputoptions);
} | php | protected function encode_request($functionname, $params) {
$outputoptions = array(
'encoding' => 'utf-8',
'escaping' => 'markup',
);
// See MDL-53962 - needed for backwards compatibility on <= 3.0.
$params = array_values($params);
return xmlrpc_encode_request($functionname, $params, $outputoptions);
} | [
"protected",
"function",
"encode_request",
"(",
"$",
"functionname",
",",
"$",
"params",
")",
"{",
"$",
"outputoptions",
"=",
"array",
"(",
"'encoding'",
"=>",
"'utf-8'",
",",
"'escaping'",
"=>",
"'markup'",
",",
")",
";",
"// See MDL-53962 - needed for backwards compatibility on <= 3.0.",
"$",
"params",
"=",
"array_values",
"(",
"$",
"params",
")",
";",
"return",
"xmlrpc_encode_request",
"(",
"$",
"functionname",
",",
"$",
"params",
",",
"$",
"outputoptions",
")",
";",
"}"
] | Generates XML for a method request.
@param string $functionname Name of the method to call.
@param mixed $params Method parameters compatible with the method signature.
@return string | [
"Generates",
"XML",
"for",
"a",
"method",
"request",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/webservice/xmlrpc/lib.php#L107-L118 |
211,999 | moodle/moodle | webservice/xmlrpc/lib.php | webservice_xmlrpc_client.decode_response | protected function decode_response($response) {
// XMLRPC server in Moodle encodes response using function xmlrpc_encode_request() with method==null
// see {@link webservice_xmlrpc_server::prepare_response()} . We should use xmlrpc_decode_request() for decoding too.
$method = null;
$encoding = null;
if (preg_match('/^<\?xml version="1.0" encoding="([^"]*)"\?>/', $response, $matches)) {
// Sometimes xmlrpc_decode_request() fails to recognise encoding, let's help it.
$encoding = $matches[1];
}
$r = xmlrpc_decode_request($response, $method, $encoding);
return $r;
} | php | protected function decode_response($response) {
// XMLRPC server in Moodle encodes response using function xmlrpc_encode_request() with method==null
// see {@link webservice_xmlrpc_server::prepare_response()} . We should use xmlrpc_decode_request() for decoding too.
$method = null;
$encoding = null;
if (preg_match('/^<\?xml version="1.0" encoding="([^"]*)"\?>/', $response, $matches)) {
// Sometimes xmlrpc_decode_request() fails to recognise encoding, let's help it.
$encoding = $matches[1];
}
$r = xmlrpc_decode_request($response, $method, $encoding);
return $r;
} | [
"protected",
"function",
"decode_response",
"(",
"$",
"response",
")",
"{",
"// XMLRPC server in Moodle encodes response using function xmlrpc_encode_request() with method==null",
"// see {@link webservice_xmlrpc_server::prepare_response()} . We should use xmlrpc_decode_request() for decoding too.",
"$",
"method",
"=",
"null",
";",
"$",
"encoding",
"=",
"null",
";",
"if",
"(",
"preg_match",
"(",
"'/^<\\?xml version=\"1.0\" encoding=\"([^\"]*)\"\\?>/'",
",",
"$",
"response",
",",
"$",
"matches",
")",
")",
"{",
"// Sometimes xmlrpc_decode_request() fails to recognise encoding, let's help it.",
"$",
"encoding",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"$",
"r",
"=",
"xmlrpc_decode_request",
"(",
"$",
"response",
",",
"$",
"method",
",",
"$",
"encoding",
")",
";",
"return",
"$",
"r",
";",
"}"
] | Parses and decodes the response XML
@param string $response
@return array | [
"Parses",
"and",
"decodes",
"the",
"response",
"XML"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/webservice/xmlrpc/lib.php#L126-L137 |
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.