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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
219,400
|
moodle/moodle
|
lib/form/float.php
|
MoodleQuickForm_float.exportValue
|
public function exportValue(&$submitValues, $assoc = false) {
$value = $this->_findValue($submitValues);
if (null === $value) {
$value = $this->getValue();
} else if ($value) {
$value = unformat_float($value, true);
}
return $this->_prepareValue($value, $assoc);
}
|
php
|
public function exportValue(&$submitValues, $assoc = false) {
$value = $this->_findValue($submitValues);
if (null === $value) {
$value = $this->getValue();
} else if ($value) {
$value = unformat_float($value, true);
}
return $this->_prepareValue($value, $assoc);
}
|
[
"public",
"function",
"exportValue",
"(",
"&",
"$",
"submitValues",
",",
"$",
"assoc",
"=",
"false",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"_findValue",
"(",
"$",
"submitValues",
")",
";",
"if",
"(",
"null",
"===",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"getValue",
"(",
")",
";",
"}",
"else",
"if",
"(",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"unformat_float",
"(",
"$",
"value",
",",
"true",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_prepareValue",
"(",
"$",
"value",
",",
"$",
"assoc",
")",
";",
"}"
] |
Returns a 'safe' element's value.
@param array $submitValues array of submitted values to search
@param bool $assoc whether to return the value as associative array
@return mixed
|
[
"Returns",
"a",
"safe",
"element",
"s",
"value",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/float.php#L134-L142
|
219,401
|
moodle/moodle
|
lib/form/float.php
|
MoodleQuickForm_float.format_float
|
private function format_float($value) {
if (is_numeric($value)) {
if ($value > 0) {
$decimals = strlen($value) - strlen(floor($value)) - 1;
} else {
$decimals = strlen($value) - strlen(ceil($value)) - 1;
}
$value = format_float($value, $decimals);
}
return $value;
}
|
php
|
private function format_float($value) {
if (is_numeric($value)) {
if ($value > 0) {
$decimals = strlen($value) - strlen(floor($value)) - 1;
} else {
$decimals = strlen($value) - strlen(ceil($value)) - 1;
}
$value = format_float($value, $decimals);
}
return $value;
}
|
[
"private",
"function",
"format_float",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"$",
"value",
">",
"0",
")",
"{",
"$",
"decimals",
"=",
"strlen",
"(",
"$",
"value",
")",
"-",
"strlen",
"(",
"floor",
"(",
"$",
"value",
")",
")",
"-",
"1",
";",
"}",
"else",
"{",
"$",
"decimals",
"=",
"strlen",
"(",
"$",
"value",
")",
"-",
"strlen",
"(",
"ceil",
"(",
"$",
"value",
")",
")",
"-",
"1",
";",
"}",
"$",
"value",
"=",
"format_float",
"(",
"$",
"value",
",",
"$",
"decimals",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] |
Given a float, prints it nicely.
This function reserves the number of decimal places.
@param float|null $value The float number to format
@return string Localised float
|
[
"Given",
"a",
"float",
"prints",
"it",
"nicely",
".",
"This",
"function",
"reserves",
"the",
"number",
"of",
"decimal",
"places",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/float.php#L176-L186
|
219,402
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Writer/Excel2007/Workbook.php
|
PHPExcel_Writer_Excel2007_Workbook.writeDefinedNameForNamedRange
|
private function writeDefinedNameForNamedRange(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_NamedRange $pNamedRange)
{
// definedName for named range
$objWriter->startElement('definedName');
$objWriter->writeAttribute('name', $pNamedRange->getName());
if ($pNamedRange->getLocalOnly()) {
$objWriter->writeAttribute('localSheetId', $pNamedRange->getScope()->getParent()->getIndex($pNamedRange->getScope()));
}
// Create absolute coordinate and write as raw text
$range = PHPExcel_Cell::splitRange($pNamedRange->getRange());
for ($i = 0; $i < count($range); $i++) {
$range[$i][0] = '\'' . str_replace("'", "''", $pNamedRange->getWorksheet()->getTitle()) . '\'!' . PHPExcel_Cell::absoluteReference($range[$i][0]);
if (isset($range[$i][1])) {
$range[$i][1] = PHPExcel_Cell::absoluteReference($range[$i][1]);
}
}
$range = PHPExcel_Cell::buildRange($range);
$objWriter->writeRawData($range);
$objWriter->endElement();
}
|
php
|
private function writeDefinedNameForNamedRange(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_NamedRange $pNamedRange)
{
// definedName for named range
$objWriter->startElement('definedName');
$objWriter->writeAttribute('name', $pNamedRange->getName());
if ($pNamedRange->getLocalOnly()) {
$objWriter->writeAttribute('localSheetId', $pNamedRange->getScope()->getParent()->getIndex($pNamedRange->getScope()));
}
// Create absolute coordinate and write as raw text
$range = PHPExcel_Cell::splitRange($pNamedRange->getRange());
for ($i = 0; $i < count($range); $i++) {
$range[$i][0] = '\'' . str_replace("'", "''", $pNamedRange->getWorksheet()->getTitle()) . '\'!' . PHPExcel_Cell::absoluteReference($range[$i][0]);
if (isset($range[$i][1])) {
$range[$i][1] = PHPExcel_Cell::absoluteReference($range[$i][1]);
}
}
$range = PHPExcel_Cell::buildRange($range);
$objWriter->writeRawData($range);
$objWriter->endElement();
}
|
[
"private",
"function",
"writeDefinedNameForNamedRange",
"(",
"PHPExcel_Shared_XMLWriter",
"$",
"objWriter",
"=",
"null",
",",
"PHPExcel_NamedRange",
"$",
"pNamedRange",
")",
"{",
"// definedName for named range",
"$",
"objWriter",
"->",
"startElement",
"(",
"'definedName'",
")",
";",
"$",
"objWriter",
"->",
"writeAttribute",
"(",
"'name'",
",",
"$",
"pNamedRange",
"->",
"getName",
"(",
")",
")",
";",
"if",
"(",
"$",
"pNamedRange",
"->",
"getLocalOnly",
"(",
")",
")",
"{",
"$",
"objWriter",
"->",
"writeAttribute",
"(",
"'localSheetId'",
",",
"$",
"pNamedRange",
"->",
"getScope",
"(",
")",
"->",
"getParent",
"(",
")",
"->",
"getIndex",
"(",
"$",
"pNamedRange",
"->",
"getScope",
"(",
")",
")",
")",
";",
"}",
"// Create absolute coordinate and write as raw text",
"$",
"range",
"=",
"PHPExcel_Cell",
"::",
"splitRange",
"(",
"$",
"pNamedRange",
"->",
"getRange",
"(",
")",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"range",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"range",
"[",
"$",
"i",
"]",
"[",
"0",
"]",
"=",
"'\\''",
".",
"str_replace",
"(",
"\"'\"",
",",
"\"''\"",
",",
"$",
"pNamedRange",
"->",
"getWorksheet",
"(",
")",
"->",
"getTitle",
"(",
")",
")",
".",
"'\\'!'",
".",
"PHPExcel_Cell",
"::",
"absoluteReference",
"(",
"$",
"range",
"[",
"$",
"i",
"]",
"[",
"0",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"range",
"[",
"$",
"i",
"]",
"[",
"1",
"]",
")",
")",
"{",
"$",
"range",
"[",
"$",
"i",
"]",
"[",
"1",
"]",
"=",
"PHPExcel_Cell",
"::",
"absoluteReference",
"(",
"$",
"range",
"[",
"$",
"i",
"]",
"[",
"1",
"]",
")",
";",
"}",
"}",
"$",
"range",
"=",
"PHPExcel_Cell",
"::",
"buildRange",
"(",
"$",
"range",
")",
";",
"$",
"objWriter",
"->",
"writeRawData",
"(",
"$",
"range",
")",
";",
"$",
"objWriter",
"->",
"endElement",
"(",
")",
";",
"}"
] |
Write Defined Name for named range
@param PHPExcel_Shared_XMLWriter $objWriter XML Writer
@param PHPExcel_NamedRange $pNamedRange
@throws PHPExcel_Writer_Exception
|
[
"Write",
"Defined",
"Name",
"for",
"named",
"range"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Writer/Excel2007/Workbook.php#L311-L333
|
219,403
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Writer/Excel2007/Workbook.php
|
PHPExcel_Writer_Excel2007_Workbook.writeDefinedNameForAutofilter
|
private function writeDefinedNameForAutofilter(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null, $pSheetId = 0)
{
// definedName for autoFilter
$autoFilterRange = $pSheet->getAutoFilter()->getRange();
if (!empty($autoFilterRange)) {
$objWriter->startElement('definedName');
$objWriter->writeAttribute('name', '_xlnm._FilterDatabase');
$objWriter->writeAttribute('localSheetId', $pSheetId);
$objWriter->writeAttribute('hidden', '1');
// Create absolute coordinate and write as raw text
$range = PHPExcel_Cell::splitRange($autoFilterRange);
$range = $range[0];
// Strip any worksheet ref so we can make the cell ref absolute
if (strpos($range[0], '!') !== false) {
list($ws, $range[0]) = explode('!', $range[0]);
}
$range[0] = PHPExcel_Cell::absoluteCoordinate($range[0]);
$range[1] = PHPExcel_Cell::absoluteCoordinate($range[1]);
$range = implode(':', $range);
$objWriter->writeRawData('\'' . str_replace("'", "''", $pSheet->getTitle()) . '\'!' . $range);
$objWriter->endElement();
}
}
|
php
|
private function writeDefinedNameForAutofilter(PHPExcel_Shared_XMLWriter $objWriter = null, PHPExcel_Worksheet $pSheet = null, $pSheetId = 0)
{
// definedName for autoFilter
$autoFilterRange = $pSheet->getAutoFilter()->getRange();
if (!empty($autoFilterRange)) {
$objWriter->startElement('definedName');
$objWriter->writeAttribute('name', '_xlnm._FilterDatabase');
$objWriter->writeAttribute('localSheetId', $pSheetId);
$objWriter->writeAttribute('hidden', '1');
// Create absolute coordinate and write as raw text
$range = PHPExcel_Cell::splitRange($autoFilterRange);
$range = $range[0];
// Strip any worksheet ref so we can make the cell ref absolute
if (strpos($range[0], '!') !== false) {
list($ws, $range[0]) = explode('!', $range[0]);
}
$range[0] = PHPExcel_Cell::absoluteCoordinate($range[0]);
$range[1] = PHPExcel_Cell::absoluteCoordinate($range[1]);
$range = implode(':', $range);
$objWriter->writeRawData('\'' . str_replace("'", "''", $pSheet->getTitle()) . '\'!' . $range);
$objWriter->endElement();
}
}
|
[
"private",
"function",
"writeDefinedNameForAutofilter",
"(",
"PHPExcel_Shared_XMLWriter",
"$",
"objWriter",
"=",
"null",
",",
"PHPExcel_Worksheet",
"$",
"pSheet",
"=",
"null",
",",
"$",
"pSheetId",
"=",
"0",
")",
"{",
"// definedName for autoFilter",
"$",
"autoFilterRange",
"=",
"$",
"pSheet",
"->",
"getAutoFilter",
"(",
")",
"->",
"getRange",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"autoFilterRange",
")",
")",
"{",
"$",
"objWriter",
"->",
"startElement",
"(",
"'definedName'",
")",
";",
"$",
"objWriter",
"->",
"writeAttribute",
"(",
"'name'",
",",
"'_xlnm._FilterDatabase'",
")",
";",
"$",
"objWriter",
"->",
"writeAttribute",
"(",
"'localSheetId'",
",",
"$",
"pSheetId",
")",
";",
"$",
"objWriter",
"->",
"writeAttribute",
"(",
"'hidden'",
",",
"'1'",
")",
";",
"// Create absolute coordinate and write as raw text",
"$",
"range",
"=",
"PHPExcel_Cell",
"::",
"splitRange",
"(",
"$",
"autoFilterRange",
")",
";",
"$",
"range",
"=",
"$",
"range",
"[",
"0",
"]",
";",
"// Strip any worksheet ref so we can make the cell ref absolute",
"if",
"(",
"strpos",
"(",
"$",
"range",
"[",
"0",
"]",
",",
"'!'",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"ws",
",",
"$",
"range",
"[",
"0",
"]",
")",
"=",
"explode",
"(",
"'!'",
",",
"$",
"range",
"[",
"0",
"]",
")",
";",
"}",
"$",
"range",
"[",
"0",
"]",
"=",
"PHPExcel_Cell",
"::",
"absoluteCoordinate",
"(",
"$",
"range",
"[",
"0",
"]",
")",
";",
"$",
"range",
"[",
"1",
"]",
"=",
"PHPExcel_Cell",
"::",
"absoluteCoordinate",
"(",
"$",
"range",
"[",
"1",
"]",
")",
";",
"$",
"range",
"=",
"implode",
"(",
"':'",
",",
"$",
"range",
")",
";",
"$",
"objWriter",
"->",
"writeRawData",
"(",
"'\\''",
".",
"str_replace",
"(",
"\"'\"",
",",
"\"''\"",
",",
"$",
"pSheet",
"->",
"getTitle",
"(",
")",
")",
".",
"'\\'!'",
".",
"$",
"range",
")",
";",
"$",
"objWriter",
"->",
"endElement",
"(",
")",
";",
"}",
"}"
] |
Write Defined Name for autoFilter
@param PHPExcel_Shared_XMLWriter $objWriter XML Writer
@param PHPExcel_Worksheet $pSheet
@param int $pSheetId
@throws PHPExcel_Writer_Exception
|
[
"Write",
"Defined",
"Name",
"for",
"autoFilter"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Writer/Excel2007/Workbook.php#L343-L369
|
219,404
|
moodle/moodle
|
message/output/popup/externallib.php
|
message_popup_external.get_popup_notifications_parameters
|
public static function get_popup_notifications_parameters() {
return new external_function_parameters(
array(
'useridto' => new external_value(PARAM_INT, 'the user id who received the message, 0 for current user'),
'newestfirst' => new external_value(
PARAM_BOOL, 'true for ordering by newest first, false for oldest first',
VALUE_DEFAULT, true),
'limit' => new external_value(PARAM_INT, 'the number of results to return', VALUE_DEFAULT, 0),
'offset' => new external_value(PARAM_INT, 'offset the result set by a given amount', VALUE_DEFAULT, 0)
)
);
}
|
php
|
public static function get_popup_notifications_parameters() {
return new external_function_parameters(
array(
'useridto' => new external_value(PARAM_INT, 'the user id who received the message, 0 for current user'),
'newestfirst' => new external_value(
PARAM_BOOL, 'true for ordering by newest first, false for oldest first',
VALUE_DEFAULT, true),
'limit' => new external_value(PARAM_INT, 'the number of results to return', VALUE_DEFAULT, 0),
'offset' => new external_value(PARAM_INT, 'offset the result set by a given amount', VALUE_DEFAULT, 0)
)
);
}
|
[
"public",
"static",
"function",
"get_popup_notifications_parameters",
"(",
")",
"{",
"return",
"new",
"external_function_parameters",
"(",
"array",
"(",
"'useridto'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'the user id who received the message, 0 for current user'",
")",
",",
"'newestfirst'",
"=>",
"new",
"external_value",
"(",
"PARAM_BOOL",
",",
"'true for ordering by newest first, false for oldest first'",
",",
"VALUE_DEFAULT",
",",
"true",
")",
",",
"'limit'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'the number of results to return'",
",",
"VALUE_DEFAULT",
",",
"0",
")",
",",
"'offset'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'offset the result set by a given amount'",
",",
"VALUE_DEFAULT",
",",
"0",
")",
")",
")",
";",
"}"
] |
Get popup notifications parameters description.
@return external_function_parameters
@since 3.2
|
[
"Get",
"popup",
"notifications",
"parameters",
"description",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/output/popup/externallib.php#L47-L58
|
219,405
|
moodle/moodle
|
message/output/popup/externallib.php
|
message_popup_external.get_popup_notifications
|
public static function get_popup_notifications($useridto, $newestfirst, $limit, $offset) {
global $USER, $PAGE;
$params = self::validate_parameters(
self::get_popup_notifications_parameters(),
array(
'useridto' => $useridto,
'newestfirst' => $newestfirst,
'limit' => $limit,
'offset' => $offset,
)
);
$context = context_system::instance();
self::validate_context($context);
$useridto = $params['useridto'];
$newestfirst = $params['newestfirst'];
$limit = $params['limit'];
$offset = $params['offset'];
$issuperuser = has_capability('moodle/site:readallmessages', $context);
$renderer = $PAGE->get_renderer('core_message');
if (empty($useridto)) {
$useridto = $USER->id;
}
// Check if the current user is the sender/receiver or just a privileged user.
if ($useridto != $USER->id and !$issuperuser) {
throw new moodle_exception('accessdenied', 'admin');
}
if (!empty($useridto)) {
if (!core_user::is_real_user($useridto)) {
throw new moodle_exception('invaliduser');
}
}
$sort = $newestfirst ? 'DESC' : 'ASC';
$notifications = \message_popup\api::get_popup_notifications($useridto, $sort, $limit, $offset);
$notificationcontexts = [];
if ($notifications) {
foreach ($notifications as $notification) {
$notificationoutput = new \message_popup\output\popup_notification($notification);
$notificationcontext = $notificationoutput->export_for_template($renderer);
// Keep this for BC.
$notificationcontext->deleted = false;
$notificationcontexts[] = $notificationcontext;
}
}
return array(
'notifications' => $notificationcontexts,
'unreadcount' => \message_popup\api::count_unread_popup_notifications($useridto),
);
}
|
php
|
public static function get_popup_notifications($useridto, $newestfirst, $limit, $offset) {
global $USER, $PAGE;
$params = self::validate_parameters(
self::get_popup_notifications_parameters(),
array(
'useridto' => $useridto,
'newestfirst' => $newestfirst,
'limit' => $limit,
'offset' => $offset,
)
);
$context = context_system::instance();
self::validate_context($context);
$useridto = $params['useridto'];
$newestfirst = $params['newestfirst'];
$limit = $params['limit'];
$offset = $params['offset'];
$issuperuser = has_capability('moodle/site:readallmessages', $context);
$renderer = $PAGE->get_renderer('core_message');
if (empty($useridto)) {
$useridto = $USER->id;
}
// Check if the current user is the sender/receiver or just a privileged user.
if ($useridto != $USER->id and !$issuperuser) {
throw new moodle_exception('accessdenied', 'admin');
}
if (!empty($useridto)) {
if (!core_user::is_real_user($useridto)) {
throw new moodle_exception('invaliduser');
}
}
$sort = $newestfirst ? 'DESC' : 'ASC';
$notifications = \message_popup\api::get_popup_notifications($useridto, $sort, $limit, $offset);
$notificationcontexts = [];
if ($notifications) {
foreach ($notifications as $notification) {
$notificationoutput = new \message_popup\output\popup_notification($notification);
$notificationcontext = $notificationoutput->export_for_template($renderer);
// Keep this for BC.
$notificationcontext->deleted = false;
$notificationcontexts[] = $notificationcontext;
}
}
return array(
'notifications' => $notificationcontexts,
'unreadcount' => \message_popup\api::count_unread_popup_notifications($useridto),
);
}
|
[
"public",
"static",
"function",
"get_popup_notifications",
"(",
"$",
"useridto",
",",
"$",
"newestfirst",
",",
"$",
"limit",
",",
"$",
"offset",
")",
"{",
"global",
"$",
"USER",
",",
"$",
"PAGE",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_popup_notifications_parameters",
"(",
")",
",",
"array",
"(",
"'useridto'",
"=>",
"$",
"useridto",
",",
"'newestfirst'",
"=>",
"$",
"newestfirst",
",",
"'limit'",
"=>",
"$",
"limit",
",",
"'offset'",
"=>",
"$",
"offset",
",",
")",
")",
";",
"$",
"context",
"=",
"context_system",
"::",
"instance",
"(",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"$",
"useridto",
"=",
"$",
"params",
"[",
"'useridto'",
"]",
";",
"$",
"newestfirst",
"=",
"$",
"params",
"[",
"'newestfirst'",
"]",
";",
"$",
"limit",
"=",
"$",
"params",
"[",
"'limit'",
"]",
";",
"$",
"offset",
"=",
"$",
"params",
"[",
"'offset'",
"]",
";",
"$",
"issuperuser",
"=",
"has_capability",
"(",
"'moodle/site:readallmessages'",
",",
"$",
"context",
")",
";",
"$",
"renderer",
"=",
"$",
"PAGE",
"->",
"get_renderer",
"(",
"'core_message'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"useridto",
")",
")",
"{",
"$",
"useridto",
"=",
"$",
"USER",
"->",
"id",
";",
"}",
"// Check if the current user is the sender/receiver or just a privileged user.",
"if",
"(",
"$",
"useridto",
"!=",
"$",
"USER",
"->",
"id",
"and",
"!",
"$",
"issuperuser",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'accessdenied'",
",",
"'admin'",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"useridto",
")",
")",
"{",
"if",
"(",
"!",
"core_user",
"::",
"is_real_user",
"(",
"$",
"useridto",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'invaliduser'",
")",
";",
"}",
"}",
"$",
"sort",
"=",
"$",
"newestfirst",
"?",
"'DESC'",
":",
"'ASC'",
";",
"$",
"notifications",
"=",
"\\",
"message_popup",
"\\",
"api",
"::",
"get_popup_notifications",
"(",
"$",
"useridto",
",",
"$",
"sort",
",",
"$",
"limit",
",",
"$",
"offset",
")",
";",
"$",
"notificationcontexts",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"notifications",
")",
"{",
"foreach",
"(",
"$",
"notifications",
"as",
"$",
"notification",
")",
"{",
"$",
"notificationoutput",
"=",
"new",
"\\",
"message_popup",
"\\",
"output",
"\\",
"popup_notification",
"(",
"$",
"notification",
")",
";",
"$",
"notificationcontext",
"=",
"$",
"notificationoutput",
"->",
"export_for_template",
"(",
"$",
"renderer",
")",
";",
"// Keep this for BC.",
"$",
"notificationcontext",
"->",
"deleted",
"=",
"false",
";",
"$",
"notificationcontexts",
"[",
"]",
"=",
"$",
"notificationcontext",
";",
"}",
"}",
"return",
"array",
"(",
"'notifications'",
"=>",
"$",
"notificationcontexts",
",",
"'unreadcount'",
"=>",
"\\",
"message_popup",
"\\",
"api",
"::",
"count_unread_popup_notifications",
"(",
"$",
"useridto",
")",
",",
")",
";",
"}"
] |
Get notifications function.
@since 3.2
@throws invalid_parameter_exception
@throws moodle_exception
@param int $useridto the user id who received the message
@param bool $newestfirst true for ordering by newest first, false for oldest first
@param int $limit the number of results to return
@param int $offset offset the result set by a given amount
@return external_description
|
[
"Get",
"notifications",
"function",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/output/popup/externallib.php#L72-L131
|
219,406
|
moodle/moodle
|
message/output/popup/externallib.php
|
message_popup_external.get_popup_notifications_returns
|
public static function get_popup_notifications_returns() {
return new external_single_structure(
array(
'notifications' => new external_multiple_structure(
new external_single_structure(
array(
'id' => new external_value(PARAM_INT, 'Notification id (this is not guaranteed to be unique
within this result set)'),
'useridfrom' => new external_value(PARAM_INT, 'User from id'),
'useridto' => new external_value(PARAM_INT, 'User to id'),
'subject' => new external_value(PARAM_TEXT, 'The notification subject'),
'shortenedsubject' => new external_value(PARAM_TEXT, 'The notification subject shortened
with ellipsis'),
'text' => new external_value(PARAM_RAW, 'The message text formated'),
'fullmessage' => new external_value(PARAM_RAW, 'The message'),
'fullmessageformat' => new external_format_value('fullmessage'),
'fullmessagehtml' => new external_value(PARAM_RAW, 'The message in html'),
'smallmessage' => new external_value(PARAM_RAW, 'The shorten message'),
'contexturl' => new external_value(PARAM_RAW, 'Context URL'),
'contexturlname' => new external_value(PARAM_TEXT, 'Context URL link name'),
'timecreated' => new external_value(PARAM_INT, 'Time created'),
'timecreatedpretty' => new external_value(PARAM_TEXT, 'Time created in a pretty format'),
'timeread' => new external_value(PARAM_INT, 'Time read'),
'read' => new external_value(PARAM_BOOL, 'notification read status'),
'deleted' => new external_value(PARAM_BOOL, 'notification deletion status'),
'iconurl' => new external_value(PARAM_URL, 'URL for notification icon'),
'component' => new external_value(PARAM_TEXT, 'The component that generated the notification',
VALUE_OPTIONAL),
'eventtype' => new external_value(PARAM_TEXT, 'The type of notification', VALUE_OPTIONAL),
'customdata' => new external_value(PARAM_RAW, 'Custom data to be passed to the message processor.
The data here is serialised using json_encode().', VALUE_OPTIONAL),
), 'message'
)
),
'unreadcount' => new external_value(PARAM_INT, 'the number of unread message for the given user'),
)
);
}
|
php
|
public static function get_popup_notifications_returns() {
return new external_single_structure(
array(
'notifications' => new external_multiple_structure(
new external_single_structure(
array(
'id' => new external_value(PARAM_INT, 'Notification id (this is not guaranteed to be unique
within this result set)'),
'useridfrom' => new external_value(PARAM_INT, 'User from id'),
'useridto' => new external_value(PARAM_INT, 'User to id'),
'subject' => new external_value(PARAM_TEXT, 'The notification subject'),
'shortenedsubject' => new external_value(PARAM_TEXT, 'The notification subject shortened
with ellipsis'),
'text' => new external_value(PARAM_RAW, 'The message text formated'),
'fullmessage' => new external_value(PARAM_RAW, 'The message'),
'fullmessageformat' => new external_format_value('fullmessage'),
'fullmessagehtml' => new external_value(PARAM_RAW, 'The message in html'),
'smallmessage' => new external_value(PARAM_RAW, 'The shorten message'),
'contexturl' => new external_value(PARAM_RAW, 'Context URL'),
'contexturlname' => new external_value(PARAM_TEXT, 'Context URL link name'),
'timecreated' => new external_value(PARAM_INT, 'Time created'),
'timecreatedpretty' => new external_value(PARAM_TEXT, 'Time created in a pretty format'),
'timeread' => new external_value(PARAM_INT, 'Time read'),
'read' => new external_value(PARAM_BOOL, 'notification read status'),
'deleted' => new external_value(PARAM_BOOL, 'notification deletion status'),
'iconurl' => new external_value(PARAM_URL, 'URL for notification icon'),
'component' => new external_value(PARAM_TEXT, 'The component that generated the notification',
VALUE_OPTIONAL),
'eventtype' => new external_value(PARAM_TEXT, 'The type of notification', VALUE_OPTIONAL),
'customdata' => new external_value(PARAM_RAW, 'Custom data to be passed to the message processor.
The data here is serialised using json_encode().', VALUE_OPTIONAL),
), 'message'
)
),
'unreadcount' => new external_value(PARAM_INT, 'the number of unread message for the given user'),
)
);
}
|
[
"public",
"static",
"function",
"get_popup_notifications_returns",
"(",
")",
"{",
"return",
"new",
"external_single_structure",
"(",
"array",
"(",
"'notifications'",
"=>",
"new",
"external_multiple_structure",
"(",
"new",
"external_single_structure",
"(",
"array",
"(",
"'id'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Notification id (this is not guaranteed to be unique\n within this result set)'",
")",
",",
"'useridfrom'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'User from id'",
")",
",",
"'useridto'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'User to id'",
")",
",",
"'subject'",
"=>",
"new",
"external_value",
"(",
"PARAM_TEXT",
",",
"'The notification subject'",
")",
",",
"'shortenedsubject'",
"=>",
"new",
"external_value",
"(",
"PARAM_TEXT",
",",
"'The notification subject shortened\n with ellipsis'",
")",
",",
"'text'",
"=>",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'The message text formated'",
")",
",",
"'fullmessage'",
"=>",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'The message'",
")",
",",
"'fullmessageformat'",
"=>",
"new",
"external_format_value",
"(",
"'fullmessage'",
")",
",",
"'fullmessagehtml'",
"=>",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'The message in html'",
")",
",",
"'smallmessage'",
"=>",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'The shorten message'",
")",
",",
"'contexturl'",
"=>",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'Context URL'",
")",
",",
"'contexturlname'",
"=>",
"new",
"external_value",
"(",
"PARAM_TEXT",
",",
"'Context URL link name'",
")",
",",
"'timecreated'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Time created'",
")",
",",
"'timecreatedpretty'",
"=>",
"new",
"external_value",
"(",
"PARAM_TEXT",
",",
"'Time created in a pretty format'",
")",
",",
"'timeread'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Time read'",
")",
",",
"'read'",
"=>",
"new",
"external_value",
"(",
"PARAM_BOOL",
",",
"'notification read status'",
")",
",",
"'deleted'",
"=>",
"new",
"external_value",
"(",
"PARAM_BOOL",
",",
"'notification deletion status'",
")",
",",
"'iconurl'",
"=>",
"new",
"external_value",
"(",
"PARAM_URL",
",",
"'URL for notification icon'",
")",
",",
"'component'",
"=>",
"new",
"external_value",
"(",
"PARAM_TEXT",
",",
"'The component that generated the notification'",
",",
"VALUE_OPTIONAL",
")",
",",
"'eventtype'",
"=>",
"new",
"external_value",
"(",
"PARAM_TEXT",
",",
"'The type of notification'",
",",
"VALUE_OPTIONAL",
")",
",",
"'customdata'",
"=>",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'Custom data to be passed to the message processor.\n The data here is serialised using json_encode().'",
",",
"VALUE_OPTIONAL",
")",
",",
")",
",",
"'message'",
")",
")",
",",
"'unreadcount'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'the number of unread message for the given user'",
")",
",",
")",
")",
";",
"}"
] |
Get notifications return description.
@return external_single_structure
@since 3.2
|
[
"Get",
"notifications",
"return",
"description",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/output/popup/externallib.php#L139-L176
|
219,407
|
moodle/moodle
|
message/output/popup/externallib.php
|
message_popup_external.get_unread_popup_notification_count
|
public static function get_unread_popup_notification_count($useridto) {
global $USER;
$params = self::validate_parameters(
self::get_unread_popup_notification_count_parameters(),
array('useridto' => $useridto)
);
$context = context_system::instance();
self::validate_context($context);
$useridto = $params['useridto'];
if (!empty($useridto)) {
if (core_user::is_real_user($useridto)) {
$userto = core_user::get_user($useridto, '*', MUST_EXIST);
} else {
throw new moodle_exception('invaliduser');
}
}
// Check if the current user is the sender/receiver or just a privileged user.
if ($useridto != $USER->id and !has_capability('moodle/site:readallmessages', $context)) {
throw new moodle_exception('accessdenied', 'admin');
}
return \message_popup\api::count_unread_popup_notifications($useridto);
}
|
php
|
public static function get_unread_popup_notification_count($useridto) {
global $USER;
$params = self::validate_parameters(
self::get_unread_popup_notification_count_parameters(),
array('useridto' => $useridto)
);
$context = context_system::instance();
self::validate_context($context);
$useridto = $params['useridto'];
if (!empty($useridto)) {
if (core_user::is_real_user($useridto)) {
$userto = core_user::get_user($useridto, '*', MUST_EXIST);
} else {
throw new moodle_exception('invaliduser');
}
}
// Check if the current user is the sender/receiver or just a privileged user.
if ($useridto != $USER->id and !has_capability('moodle/site:readallmessages', $context)) {
throw new moodle_exception('accessdenied', 'admin');
}
return \message_popup\api::count_unread_popup_notifications($useridto);
}
|
[
"public",
"static",
"function",
"get_unread_popup_notification_count",
"(",
"$",
"useridto",
")",
"{",
"global",
"$",
"USER",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_unread_popup_notification_count_parameters",
"(",
")",
",",
"array",
"(",
"'useridto'",
"=>",
"$",
"useridto",
")",
")",
";",
"$",
"context",
"=",
"context_system",
"::",
"instance",
"(",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"$",
"useridto",
"=",
"$",
"params",
"[",
"'useridto'",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"useridto",
")",
")",
"{",
"if",
"(",
"core_user",
"::",
"is_real_user",
"(",
"$",
"useridto",
")",
")",
"{",
"$",
"userto",
"=",
"core_user",
"::",
"get_user",
"(",
"$",
"useridto",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'invaliduser'",
")",
";",
"}",
"}",
"// Check if the current user is the sender/receiver or just a privileged user.",
"if",
"(",
"$",
"useridto",
"!=",
"$",
"USER",
"->",
"id",
"and",
"!",
"has_capability",
"(",
"'moodle/site:readallmessages'",
",",
"$",
"context",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'accessdenied'",
",",
"'admin'",
")",
";",
"}",
"return",
"\\",
"message_popup",
"\\",
"api",
"::",
"count_unread_popup_notifications",
"(",
"$",
"useridto",
")",
";",
"}"
] |
Get unread notification count function.
@since 3.2
@throws invalid_parameter_exception
@throws moodle_exception
@param int $useridto the user id who received the message
@return external_description
|
[
"Get",
"unread",
"notification",
"count",
"function",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/output/popup/externallib.php#L201-L228
|
219,408
|
moodle/moodle
|
admin/tool/templatelibrary/classes/api.php
|
api.list_templates
|
public static function list_templates($component = '', $search = '', $themename = '') {
global $CFG, $PAGE;
if (empty($themename)) {
$themename = $PAGE->theme->name;
}
$themeconfig = \theme_config::load($themename);
$templatedirs = array();
$results = array();
if ($component !== '') {
// Just look at one component for templates.
$dirs = mustache_template_finder::get_template_directories_for_component($component, $themename);
$templatedirs[$component] = $dirs;
} else {
// Look at all the templates dirs for core.
$templatedirs['core'] = mustache_template_finder::get_template_directories_for_component('core', $themename);
// Look at all the templates dirs for subsystems.
$subsystems = core_component::get_core_subsystems();
foreach ($subsystems as $subsystem => $dir) {
if (empty($dir)) {
continue;
}
$dir .= '/templates';
if (is_dir($dir)) {
$dirs = mustache_template_finder::get_template_directories_for_component('core_' . $subsystem, $themename);
$templatedirs['core_' . $subsystem] = $dirs;
}
}
// Look at all the templates dirs for plugins.
$plugintypes = core_component::get_plugin_types();
foreach ($plugintypes as $type => $dir) {
$plugins = core_component::get_plugin_list_with_file($type, 'templates', false);
foreach ($plugins as $plugin => $dir) {
if ($type == 'theme' && $plugin != $themename && !in_array($plugin, $themeconfig->parents)) {
continue;
}
if (!empty($dir) && is_dir($dir)) {
$pluginname = $type . '_' . $plugin;
$dirs = mustache_template_finder::get_template_directories_for_component($pluginname, $themename);
$templatedirs[$pluginname] = $dirs;
}
}
}
}
foreach ($templatedirs as $templatecomponent => $dirs) {
foreach ($dirs as $dir) {
// List it.
$files = glob($dir . '/*.mustache');
foreach ($files as $file) {
$templatename = basename($file, '.mustache');
if ($search == '' || strpos($templatename, $search) !== false) {
$results[$templatecomponent . '/' . $templatename] = 1;
}
}
}
}
$results = array_keys($results);
sort($results);
return $results;
}
|
php
|
public static function list_templates($component = '', $search = '', $themename = '') {
global $CFG, $PAGE;
if (empty($themename)) {
$themename = $PAGE->theme->name;
}
$themeconfig = \theme_config::load($themename);
$templatedirs = array();
$results = array();
if ($component !== '') {
// Just look at one component for templates.
$dirs = mustache_template_finder::get_template_directories_for_component($component, $themename);
$templatedirs[$component] = $dirs;
} else {
// Look at all the templates dirs for core.
$templatedirs['core'] = mustache_template_finder::get_template_directories_for_component('core', $themename);
// Look at all the templates dirs for subsystems.
$subsystems = core_component::get_core_subsystems();
foreach ($subsystems as $subsystem => $dir) {
if (empty($dir)) {
continue;
}
$dir .= '/templates';
if (is_dir($dir)) {
$dirs = mustache_template_finder::get_template_directories_for_component('core_' . $subsystem, $themename);
$templatedirs['core_' . $subsystem] = $dirs;
}
}
// Look at all the templates dirs for plugins.
$plugintypes = core_component::get_plugin_types();
foreach ($plugintypes as $type => $dir) {
$plugins = core_component::get_plugin_list_with_file($type, 'templates', false);
foreach ($plugins as $plugin => $dir) {
if ($type == 'theme' && $plugin != $themename && !in_array($plugin, $themeconfig->parents)) {
continue;
}
if (!empty($dir) && is_dir($dir)) {
$pluginname = $type . '_' . $plugin;
$dirs = mustache_template_finder::get_template_directories_for_component($pluginname, $themename);
$templatedirs[$pluginname] = $dirs;
}
}
}
}
foreach ($templatedirs as $templatecomponent => $dirs) {
foreach ($dirs as $dir) {
// List it.
$files = glob($dir . '/*.mustache');
foreach ($files as $file) {
$templatename = basename($file, '.mustache');
if ($search == '' || strpos($templatename, $search) !== false) {
$results[$templatecomponent . '/' . $templatename] = 1;
}
}
}
}
$results = array_keys($results);
sort($results);
return $results;
}
|
[
"public",
"static",
"function",
"list_templates",
"(",
"$",
"component",
"=",
"''",
",",
"$",
"search",
"=",
"''",
",",
"$",
"themename",
"=",
"''",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"PAGE",
";",
"if",
"(",
"empty",
"(",
"$",
"themename",
")",
")",
"{",
"$",
"themename",
"=",
"$",
"PAGE",
"->",
"theme",
"->",
"name",
";",
"}",
"$",
"themeconfig",
"=",
"\\",
"theme_config",
"::",
"load",
"(",
"$",
"themename",
")",
";",
"$",
"templatedirs",
"=",
"array",
"(",
")",
";",
"$",
"results",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"component",
"!==",
"''",
")",
"{",
"// Just look at one component for templates.",
"$",
"dirs",
"=",
"mustache_template_finder",
"::",
"get_template_directories_for_component",
"(",
"$",
"component",
",",
"$",
"themename",
")",
";",
"$",
"templatedirs",
"[",
"$",
"component",
"]",
"=",
"$",
"dirs",
";",
"}",
"else",
"{",
"// Look at all the templates dirs for core.",
"$",
"templatedirs",
"[",
"'core'",
"]",
"=",
"mustache_template_finder",
"::",
"get_template_directories_for_component",
"(",
"'core'",
",",
"$",
"themename",
")",
";",
"// Look at all the templates dirs for subsystems.",
"$",
"subsystems",
"=",
"core_component",
"::",
"get_core_subsystems",
"(",
")",
";",
"foreach",
"(",
"$",
"subsystems",
"as",
"$",
"subsystem",
"=>",
"$",
"dir",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"dir",
")",
")",
"{",
"continue",
";",
"}",
"$",
"dir",
".=",
"'/templates'",
";",
"if",
"(",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"dirs",
"=",
"mustache_template_finder",
"::",
"get_template_directories_for_component",
"(",
"'core_'",
".",
"$",
"subsystem",
",",
"$",
"themename",
")",
";",
"$",
"templatedirs",
"[",
"'core_'",
".",
"$",
"subsystem",
"]",
"=",
"$",
"dirs",
";",
"}",
"}",
"// Look at all the templates dirs for plugins.",
"$",
"plugintypes",
"=",
"core_component",
"::",
"get_plugin_types",
"(",
")",
";",
"foreach",
"(",
"$",
"plugintypes",
"as",
"$",
"type",
"=>",
"$",
"dir",
")",
"{",
"$",
"plugins",
"=",
"core_component",
"::",
"get_plugin_list_with_file",
"(",
"$",
"type",
",",
"'templates'",
",",
"false",
")",
";",
"foreach",
"(",
"$",
"plugins",
"as",
"$",
"plugin",
"=>",
"$",
"dir",
")",
"{",
"if",
"(",
"$",
"type",
"==",
"'theme'",
"&&",
"$",
"plugin",
"!=",
"$",
"themename",
"&&",
"!",
"in_array",
"(",
"$",
"plugin",
",",
"$",
"themeconfig",
"->",
"parents",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"dir",
")",
"&&",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"pluginname",
"=",
"$",
"type",
".",
"'_'",
".",
"$",
"plugin",
";",
"$",
"dirs",
"=",
"mustache_template_finder",
"::",
"get_template_directories_for_component",
"(",
"$",
"pluginname",
",",
"$",
"themename",
")",
";",
"$",
"templatedirs",
"[",
"$",
"pluginname",
"]",
"=",
"$",
"dirs",
";",
"}",
"}",
"}",
"}",
"foreach",
"(",
"$",
"templatedirs",
"as",
"$",
"templatecomponent",
"=>",
"$",
"dirs",
")",
"{",
"foreach",
"(",
"$",
"dirs",
"as",
"$",
"dir",
")",
"{",
"// List it.",
"$",
"files",
"=",
"glob",
"(",
"$",
"dir",
".",
"'/*.mustache'",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"templatename",
"=",
"basename",
"(",
"$",
"file",
",",
"'.mustache'",
")",
";",
"if",
"(",
"$",
"search",
"==",
"''",
"||",
"strpos",
"(",
"$",
"templatename",
",",
"$",
"search",
")",
"!==",
"false",
")",
"{",
"$",
"results",
"[",
"$",
"templatecomponent",
".",
"'/'",
".",
"$",
"templatename",
"]",
"=",
"1",
";",
"}",
"}",
"}",
"}",
"$",
"results",
"=",
"array_keys",
"(",
"$",
"results",
")",
";",
"sort",
"(",
"$",
"results",
")",
";",
"return",
"$",
"results",
";",
"}"
] |
Return a list of details about installed templates.
@param string $component Filter the list to a single component.
@param string $search Search string to optionally filter the list of templates.
@param string $themename The name of the current theme.
@return array[string] Where each template is in the form "component/templatename".
|
[
"Return",
"a",
"list",
"of",
"details",
"about",
"installed",
"templates",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/templatelibrary/classes/api.php#L49-L116
|
219,409
|
moodle/moodle
|
blocks/tags/edit_form.php
|
block_tags_edit_form.add_collection_selector
|
protected function add_collection_selector($mform) {
$tagcolls = core_tag_collection::get_collections_menu(false, false, get_string('anycollection', 'block_tags'));
if (count($tagcolls) <= 1) {
return;
}
$tagcollssearchable = core_tag_collection::get_collections_menu(false, true);
$hasunsearchable = false;
foreach ($tagcolls as $id => $name) {
if ($id && !array_key_exists($id, $tagcollssearchable)) {
$hasunsearchable = true;
$tagcolls[$id] = $name . '*';
}
}
$mform->addElement('select', 'config_tagcoll', get_string('tagcollection', 'block_tags'), $tagcolls);
if ($hasunsearchable) {
$mform->addHelpButton('config_tagcoll', 'tagcollection', 'block_tags');
}
$mform->setDefault('config_tagcoll', 0);
}
|
php
|
protected function add_collection_selector($mform) {
$tagcolls = core_tag_collection::get_collections_menu(false, false, get_string('anycollection', 'block_tags'));
if (count($tagcolls) <= 1) {
return;
}
$tagcollssearchable = core_tag_collection::get_collections_menu(false, true);
$hasunsearchable = false;
foreach ($tagcolls as $id => $name) {
if ($id && !array_key_exists($id, $tagcollssearchable)) {
$hasunsearchable = true;
$tagcolls[$id] = $name . '*';
}
}
$mform->addElement('select', 'config_tagcoll', get_string('tagcollection', 'block_tags'), $tagcolls);
if ($hasunsearchable) {
$mform->addHelpButton('config_tagcoll', 'tagcollection', 'block_tags');
}
$mform->setDefault('config_tagcoll', 0);
}
|
[
"protected",
"function",
"add_collection_selector",
"(",
"$",
"mform",
")",
"{",
"$",
"tagcolls",
"=",
"core_tag_collection",
"::",
"get_collections_menu",
"(",
"false",
",",
"false",
",",
"get_string",
"(",
"'anycollection'",
",",
"'block_tags'",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"tagcolls",
")",
"<=",
"1",
")",
"{",
"return",
";",
"}",
"$",
"tagcollssearchable",
"=",
"core_tag_collection",
"::",
"get_collections_menu",
"(",
"false",
",",
"true",
")",
";",
"$",
"hasunsearchable",
"=",
"false",
";",
"foreach",
"(",
"$",
"tagcolls",
"as",
"$",
"id",
"=>",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"id",
"&&",
"!",
"array_key_exists",
"(",
"$",
"id",
",",
"$",
"tagcollssearchable",
")",
")",
"{",
"$",
"hasunsearchable",
"=",
"true",
";",
"$",
"tagcolls",
"[",
"$",
"id",
"]",
"=",
"$",
"name",
".",
"'*'",
";",
"}",
"}",
"$",
"mform",
"->",
"addElement",
"(",
"'select'",
",",
"'config_tagcoll'",
",",
"get_string",
"(",
"'tagcollection'",
",",
"'block_tags'",
")",
",",
"$",
"tagcolls",
")",
";",
"if",
"(",
"$",
"hasunsearchable",
")",
"{",
"$",
"mform",
"->",
"addHelpButton",
"(",
"'config_tagcoll'",
",",
"'tagcollection'",
",",
"'block_tags'",
")",
";",
"}",
"$",
"mform",
"->",
"setDefault",
"(",
"'config_tagcoll'",
",",
"0",
")",
";",
"}"
] |
Add the tag collection selector
@param object $mform the form being built.
|
[
"Add",
"the",
"tag",
"collection",
"selector"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/tags/edit_form.php#L79-L99
|
219,410
|
moodle/moodle
|
lib/classes/event/user_info_category_created.php
|
user_info_category_created.create_from_category
|
public static function create_from_category($category) {
$event = self::create(array(
'objectid' => $category->id,
'context' => \context_system::instance(),
'other' => array(
'name' => $category->name,
)
));
$event->add_record_snapshot('user_info_category', $category);
return $event;
}
|
php
|
public static function create_from_category($category) {
$event = self::create(array(
'objectid' => $category->id,
'context' => \context_system::instance(),
'other' => array(
'name' => $category->name,
)
));
$event->add_record_snapshot('user_info_category', $category);
return $event;
}
|
[
"public",
"static",
"function",
"create_from_category",
"(",
"$",
"category",
")",
"{",
"$",
"event",
"=",
"self",
"::",
"create",
"(",
"array",
"(",
"'objectid'",
"=>",
"$",
"category",
"->",
"id",
",",
"'context'",
"=>",
"\\",
"context_system",
"::",
"instance",
"(",
")",
",",
"'other'",
"=>",
"array",
"(",
"'name'",
"=>",
"$",
"category",
"->",
"name",
",",
")",
")",
")",
";",
"$",
"event",
"->",
"add_record_snapshot",
"(",
"'user_info_category'",
",",
"$",
"category",
")",
";",
"return",
"$",
"event",
";",
"}"
] |
Creates an event from a profile info category.
@since Moodle 3.4
@param \stdClass $category A sna[pshot of the created category.
@return \core\event\base
|
[
"Creates",
"an",
"event",
"from",
"a",
"profile",
"info",
"category",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/event/user_info_category_created.php#L61-L73
|
219,411
|
moodle/moodle
|
privacy/classes/local/request/userlist_collection.php
|
userlist_collection.add_userlist
|
public function add_userlist(userlist_base $userlist) : userlist_collection {
$component = $userlist->get_component();
if (isset($this->userlists[$component])) {
throw new \moodle_exception("A userlist has already been added for the '{$component}' component");
}
$this->userlists[$component] = $userlist;
return $this;
}
|
php
|
public function add_userlist(userlist_base $userlist) : userlist_collection {
$component = $userlist->get_component();
if (isset($this->userlists[$component])) {
throw new \moodle_exception("A userlist has already been added for the '{$component}' component");
}
$this->userlists[$component] = $userlist;
return $this;
}
|
[
"public",
"function",
"add_userlist",
"(",
"userlist_base",
"$",
"userlist",
")",
":",
"userlist_collection",
"{",
"$",
"component",
"=",
"$",
"userlist",
"->",
"get_component",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"userlists",
"[",
"$",
"component",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"\"A userlist has already been added for the '{$component}' component\"",
")",
";",
"}",
"$",
"this",
"->",
"userlists",
"[",
"$",
"component",
"]",
"=",
"$",
"userlist",
";",
"return",
"$",
"this",
";",
"}"
] |
Add a userlist to this collection.
@param userlist_base $userlist the userlist to export.
@return $this
|
[
"Add",
"a",
"userlist",
"to",
"this",
"collection",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/userlist_collection.php#L77-L86
|
219,412
|
moodle/moodle
|
privacy/classes/local/request/userlist_collection.php
|
userlist_collection.get_userlist_for_component
|
public function get_userlist_for_component(string $component) {
if (isset($this->userlists[$component])) {
return $this->userlists[$component];
}
return null;
}
|
php
|
public function get_userlist_for_component(string $component) {
if (isset($this->userlists[$component])) {
return $this->userlists[$component];
}
return null;
}
|
[
"public",
"function",
"get_userlist_for_component",
"(",
"string",
"$",
"component",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"userlists",
"[",
"$",
"component",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"userlists",
"[",
"$",
"component",
"]",
";",
"}",
"return",
"null",
";",
"}"
] |
Get the userlist for the specified component.
@param string $component the frankenstyle name of the component to fetch for.
@return userlist_base|null
|
[
"Get",
"the",
"userlist",
"for",
"the",
"specified",
"component",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/userlist_collection.php#L104-L110
|
219,413
|
moodle/moodle
|
question/classes/statistics/questions/all_calculated_for_qubaid_condition.php
|
all_calculated_for_qubaid_condition.initialise_for_subq
|
public function initialise_for_subq($step, $variant = null) {
$newsubqstat = new calculated_for_subquestion($step, $variant);
if ($variant === null) {
$this->subquestionstats[$step->questionid] = $newsubqstat;
} else {
$this->subquestionstats[$step->questionid]->variantstats[$variant] = $newsubqstat;
}
}
|
php
|
public function initialise_for_subq($step, $variant = null) {
$newsubqstat = new calculated_for_subquestion($step, $variant);
if ($variant === null) {
$this->subquestionstats[$step->questionid] = $newsubqstat;
} else {
$this->subquestionstats[$step->questionid]->variantstats[$variant] = $newsubqstat;
}
}
|
[
"public",
"function",
"initialise_for_subq",
"(",
"$",
"step",
",",
"$",
"variant",
"=",
"null",
")",
"{",
"$",
"newsubqstat",
"=",
"new",
"calculated_for_subquestion",
"(",
"$",
"step",
",",
"$",
"variant",
")",
";",
"if",
"(",
"$",
"variant",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"subquestionstats",
"[",
"$",
"step",
"->",
"questionid",
"]",
"=",
"$",
"newsubqstat",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"subquestionstats",
"[",
"$",
"step",
"->",
"questionid",
"]",
"->",
"variantstats",
"[",
"$",
"variant",
"]",
"=",
"$",
"newsubqstat",
";",
"}",
"}"
] |
Set up a calculated_for_subquestion instance ready to store a randomly selected question's stats.
@param object $step
@param int|null $variant Is this to keep track of a variant's stats? If so what is the variant, if not null.
|
[
"Set",
"up",
"a",
"calculated_for_subquestion",
"instance",
"ready",
"to",
"store",
"a",
"randomly",
"selected",
"question",
"s",
"stats",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/questions/all_calculated_for_qubaid_condition.php#L67-L74
|
219,414
|
moodle/moodle
|
question/classes/statistics/questions/all_calculated_for_qubaid_condition.php
|
all_calculated_for_qubaid_condition.initialise_for_slot
|
public function initialise_for_slot($slot, $question, $variant = null) {
$newqstat = new calculated($question, $slot, $variant);
if ($variant === null) {
$this->questionstats[$slot] = $newqstat;
} else {
$this->questionstats[$slot]->variantstats[$variant] = $newqstat;
}
}
|
php
|
public function initialise_for_slot($slot, $question, $variant = null) {
$newqstat = new calculated($question, $slot, $variant);
if ($variant === null) {
$this->questionstats[$slot] = $newqstat;
} else {
$this->questionstats[$slot]->variantstats[$variant] = $newqstat;
}
}
|
[
"public",
"function",
"initialise_for_slot",
"(",
"$",
"slot",
",",
"$",
"question",
",",
"$",
"variant",
"=",
"null",
")",
"{",
"$",
"newqstat",
"=",
"new",
"calculated",
"(",
"$",
"question",
",",
"$",
"slot",
",",
"$",
"variant",
")",
";",
"if",
"(",
"$",
"variant",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"questionstats",
"[",
"$",
"slot",
"]",
"=",
"$",
"newqstat",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"questionstats",
"[",
"$",
"slot",
"]",
"->",
"variantstats",
"[",
"$",
"variant",
"]",
"=",
"$",
"newqstat",
";",
"}",
"}"
] |
Set up a calculated instance ready to store a slot question's stats.
@param int $slot
@param object $question
@param int|null $variant Is this to keep track of a variant's stats? If so what is the variant, if not null.
|
[
"Set",
"up",
"a",
"calculated",
"instance",
"ready",
"to",
"store",
"a",
"slot",
"question",
"s",
"stats",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/questions/all_calculated_for_qubaid_condition.php#L83-L90
|
219,415
|
moodle/moodle
|
question/classes/statistics/questions/all_calculated_for_qubaid_condition.php
|
all_calculated_for_qubaid_condition.for_subq
|
public function for_subq($questionid, $variant = null) {
if ($variant === null) {
if (!isset($this->subquestionstats[$questionid])) {
throw new \coding_exception('Reference to unknown question id ' . $questionid);
} else {
return $this->subquestionstats[$questionid];
}
} else {
if (!isset($this->subquestionstats[$questionid]->variantstats[$variant])) {
throw new \coding_exception('Reference to unknown question id ' . $questionid .
' variant ' . $variant);
} else {
return $this->subquestionstats[$questionid]->variantstats[$variant];
}
}
}
|
php
|
public function for_subq($questionid, $variant = null) {
if ($variant === null) {
if (!isset($this->subquestionstats[$questionid])) {
throw new \coding_exception('Reference to unknown question id ' . $questionid);
} else {
return $this->subquestionstats[$questionid];
}
} else {
if (!isset($this->subquestionstats[$questionid]->variantstats[$variant])) {
throw new \coding_exception('Reference to unknown question id ' . $questionid .
' variant ' . $variant);
} else {
return $this->subquestionstats[$questionid]->variantstats[$variant];
}
}
}
|
[
"public",
"function",
"for_subq",
"(",
"$",
"questionid",
",",
"$",
"variant",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"variant",
"===",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"subquestionstats",
"[",
"$",
"questionid",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Reference to unknown question id '",
".",
"$",
"questionid",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"subquestionstats",
"[",
"$",
"questionid",
"]",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"subquestionstats",
"[",
"$",
"questionid",
"]",
"->",
"variantstats",
"[",
"$",
"variant",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Reference to unknown question id '",
".",
"$",
"questionid",
".",
"' variant '",
".",
"$",
"variant",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"subquestionstats",
"[",
"$",
"questionid",
"]",
"->",
"variantstats",
"[",
"$",
"variant",
"]",
";",
"}",
"}",
"}"
] |
Reference for a item stats instance for a questionid and optional variant no.
@param int $questionid The id of the sub question.
@param int|null $variant if not null then we want the object to store a variant of a sub-question's stats.
@return calculated|calculated_for_subquestion stats instance for a questionid and optional variant no.
Will be a calculated_for_subquestion if no variant specified.
@throws \coding_exception if there is an attempt to respond to a non-existant set of stats.
|
[
"Reference",
"for",
"a",
"item",
"stats",
"instance",
"for",
"a",
"questionid",
"and",
"optional",
"variant",
"no",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/questions/all_calculated_for_qubaid_condition.php#L116-L131
|
219,416
|
moodle/moodle
|
question/classes/statistics/questions/all_calculated_for_qubaid_condition.php
|
all_calculated_for_qubaid_condition.for_slot
|
public function for_slot($slot, $variant = null) {
if ($variant === null) {
if (!isset($this->questionstats[$slot])) {
throw new \coding_exception('Reference to unknown slot ' . $slot);
} else {
return $this->questionstats[$slot];
}
} else {
if (!isset($this->questionstats[$slot]->variantstats[$variant])) {
throw new \coding_exception('Reference to unknown slot ' . $slot . ' variant ' . $variant);
} else {
return $this->questionstats[$slot]->variantstats[$variant];
}
}
}
|
php
|
public function for_slot($slot, $variant = null) {
if ($variant === null) {
if (!isset($this->questionstats[$slot])) {
throw new \coding_exception('Reference to unknown slot ' . $slot);
} else {
return $this->questionstats[$slot];
}
} else {
if (!isset($this->questionstats[$slot]->variantstats[$variant])) {
throw new \coding_exception('Reference to unknown slot ' . $slot . ' variant ' . $variant);
} else {
return $this->questionstats[$slot]->variantstats[$variant];
}
}
}
|
[
"public",
"function",
"for_slot",
"(",
"$",
"slot",
",",
"$",
"variant",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"variant",
"===",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"questionstats",
"[",
"$",
"slot",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Reference to unknown slot '",
".",
"$",
"slot",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"questionstats",
"[",
"$",
"slot",
"]",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"questionstats",
"[",
"$",
"slot",
"]",
"->",
"variantstats",
"[",
"$",
"variant",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Reference to unknown slot '",
".",
"$",
"slot",
".",
"' variant '",
".",
"$",
"variant",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"questionstats",
"[",
"$",
"slot",
"]",
"->",
"variantstats",
"[",
"$",
"variant",
"]",
";",
"}",
"}",
"}"
] |
Get position stats instance for a slot and optional variant no.
@param int $slot The slot no.
@param int|null $variant if provided then we want the object which stores a variant of a position's stats.
@return calculated|calculated_for_subquestion An instance of the class storing the calculated position stats.
@throws \coding_exception if there is an attempt to respond to a non-existant set of stats.
|
[
"Get",
"position",
"stats",
"instance",
"for",
"a",
"slot",
"and",
"optional",
"variant",
"no",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/questions/all_calculated_for_qubaid_condition.php#L174-L188
|
219,417
|
moodle/moodle
|
question/classes/statistics/questions/all_calculated_for_qubaid_condition.php
|
all_calculated_for_qubaid_condition.get_last_calculated_time
|
public function get_last_calculated_time($qubaids) {
global $DB;
$timemodified = time() - self::TIME_TO_CACHE;
return $DB->get_field_select('question_statistics', 'timemodified', 'hashcode = ? AND timemodified > ?',
array($qubaids->get_hash_code(), $timemodified), IGNORE_MULTIPLE);
}
|
php
|
public function get_last_calculated_time($qubaids) {
global $DB;
$timemodified = time() - self::TIME_TO_CACHE;
return $DB->get_field_select('question_statistics', 'timemodified', 'hashcode = ? AND timemodified > ?',
array($qubaids->get_hash_code(), $timemodified), IGNORE_MULTIPLE);
}
|
[
"public",
"function",
"get_last_calculated_time",
"(",
"$",
"qubaids",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"timemodified",
"=",
"time",
"(",
")",
"-",
"self",
"::",
"TIME_TO_CACHE",
";",
"return",
"$",
"DB",
"->",
"get_field_select",
"(",
"'question_statistics'",
",",
"'timemodified'",
",",
"'hashcode = ? AND timemodified > ?'",
",",
"array",
"(",
"$",
"qubaids",
"->",
"get_hash_code",
"(",
")",
",",
"$",
"timemodified",
")",
",",
"IGNORE_MULTIPLE",
")",
";",
"}"
] |
Find time of non-expired statistics in the database.
@param \qubaid_condition $qubaids Which question usages to look for stats for?
@return int|bool Time of cached record that matches this qubaid_condition or false if non found.
|
[
"Find",
"time",
"of",
"non",
"-",
"expired",
"statistics",
"in",
"the",
"database",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/questions/all_calculated_for_qubaid_condition.php#L244-L250
|
219,418
|
moodle/moodle
|
question/classes/statistics/questions/all_calculated_for_qubaid_condition.php
|
all_calculated_for_qubaid_condition.cache
|
public function cache($qubaids) {
foreach ($this->get_all_slots() as $slot) {
$this->for_slot($slot)->cache($qubaids);
}
foreach ($this->get_all_subq_ids() as $subqid) {
$this->for_subq($subqid)->cache($qubaids);
}
}
|
php
|
public function cache($qubaids) {
foreach ($this->get_all_slots() as $slot) {
$this->for_slot($slot)->cache($qubaids);
}
foreach ($this->get_all_subq_ids() as $subqid) {
$this->for_subq($subqid)->cache($qubaids);
}
}
|
[
"public",
"function",
"cache",
"(",
"$",
"qubaids",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"get_all_slots",
"(",
")",
"as",
"$",
"slot",
")",
"{",
"$",
"this",
"->",
"for_slot",
"(",
"$",
"slot",
")",
"->",
"cache",
"(",
"$",
"qubaids",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"get_all_subq_ids",
"(",
")",
"as",
"$",
"subqid",
")",
"{",
"$",
"this",
"->",
"for_subq",
"(",
"$",
"subqid",
")",
"->",
"cache",
"(",
"$",
"qubaids",
")",
";",
"}",
"}"
] |
Save stats to db.
@param \qubaid_condition $qubaids Which question usages are we caching the stats of?
|
[
"Save",
"stats",
"to",
"db",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/questions/all_calculated_for_qubaid_condition.php#L257-L265
|
219,419
|
moodle/moodle
|
question/classes/statistics/questions/all_calculated_for_qubaid_condition.php
|
all_calculated_for_qubaid_condition.any_error_messages
|
public function any_error_messages() {
$errors = array();
foreach ($this->get_all_slots() as $slot) {
foreach ($this->for_slot($slot)->get_sub_question_ids() as $subqid) {
if ($this->for_subq($subqid)->differentweights) {
$name = $this->for_subq($subqid)->question->name;
$errors[] = get_string('erroritemappearsmorethanoncewithdifferentweight', 'question', $name);
}
}
}
return $errors;
}
|
php
|
public function any_error_messages() {
$errors = array();
foreach ($this->get_all_slots() as $slot) {
foreach ($this->for_slot($slot)->get_sub_question_ids() as $subqid) {
if ($this->for_subq($subqid)->differentweights) {
$name = $this->for_subq($subqid)->question->name;
$errors[] = get_string('erroritemappearsmorethanoncewithdifferentweight', 'question', $name);
}
}
}
return $errors;
}
|
[
"public",
"function",
"any_error_messages",
"(",
")",
"{",
"$",
"errors",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"get_all_slots",
"(",
")",
"as",
"$",
"slot",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"for_slot",
"(",
"$",
"slot",
")",
"->",
"get_sub_question_ids",
"(",
")",
"as",
"$",
"subqid",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"for_subq",
"(",
"$",
"subqid",
")",
"->",
"differentweights",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"for_subq",
"(",
"$",
"subqid",
")",
"->",
"question",
"->",
"name",
";",
"$",
"errors",
"[",
"]",
"=",
"get_string",
"(",
"'erroritemappearsmorethanoncewithdifferentweight'",
",",
"'question'",
",",
"$",
"name",
")",
";",
"}",
"}",
"}",
"return",
"$",
"errors",
";",
"}"
] |
Call after calculations to output any error messages.
@return string[] Array of strings describing error messages found during stats calculation.
|
[
"Call",
"after",
"calculations",
"to",
"output",
"any",
"error",
"messages",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/questions/all_calculated_for_qubaid_condition.php#L295-L306
|
219,420
|
moodle/moodle
|
question/classes/statistics/questions/all_calculated_for_qubaid_condition.php
|
all_calculated_for_qubaid_condition.make_new_subq_stat_for
|
protected function make_new_subq_stat_for($displaynumber, $slot, $subqid, $variant = null) {
$slotstat = fullclone($this->for_subq($subqid, $variant));
$slotstat->question->number = $this->for_slot($slot)->question->number;
$slotstat->subqdisplayorder = $displaynumber;
return $slotstat;
}
|
php
|
protected function make_new_subq_stat_for($displaynumber, $slot, $subqid, $variant = null) {
$slotstat = fullclone($this->for_subq($subqid, $variant));
$slotstat->question->number = $this->for_slot($slot)->question->number;
$slotstat->subqdisplayorder = $displaynumber;
return $slotstat;
}
|
[
"protected",
"function",
"make_new_subq_stat_for",
"(",
"$",
"displaynumber",
",",
"$",
"slot",
",",
"$",
"subqid",
",",
"$",
"variant",
"=",
"null",
")",
"{",
"$",
"slotstat",
"=",
"fullclone",
"(",
"$",
"this",
"->",
"for_subq",
"(",
"$",
"subqid",
",",
"$",
"variant",
")",
")",
";",
"$",
"slotstat",
"->",
"question",
"->",
"number",
"=",
"$",
"this",
"->",
"for_slot",
"(",
"$",
"slot",
")",
"->",
"question",
"->",
"number",
";",
"$",
"slotstat",
"->",
"subqdisplayorder",
"=",
"$",
"displaynumber",
";",
"return",
"$",
"slotstat",
";",
"}"
] |
We need a new object for display. Sub-question stats can appear more than once in different slots.
So we create a clone of the object and then we can set properties on the object that are per slot.
@param int $displaynumber The display number for this sub question.
@param int $slot The slot number.
@param int $subqid The sub question id.
@param null|int $variant The variant no.
@return calculated_for_subquestion The object for display.
|
[
"We",
"need",
"a",
"new",
"object",
"for",
"display",
".",
"Sub",
"-",
"question",
"stats",
"can",
"appear",
"more",
"than",
"once",
"in",
"different",
"slots",
".",
"So",
"we",
"create",
"a",
"clone",
"of",
"the",
"object",
"and",
"then",
"we",
"can",
"set",
"properties",
"on",
"the",
"object",
"that",
"are",
"per",
"slot",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/questions/all_calculated_for_qubaid_condition.php#L437-L442
|
219,421
|
moodle/moodle
|
question/classes/statistics/questions/all_calculated_for_qubaid_condition.php
|
all_calculated_for_qubaid_condition.make_new_calculated_question_summary_stat
|
protected function make_new_calculated_question_summary_stat($randomquestioncalculated, $subquestionstats) {
$question = $randomquestioncalculated->question;
$slot = $randomquestioncalculated->slot;
$calculatedsummary = new calculated_question_summary($question, $slot, $subquestionstats);
return $calculatedsummary;
}
|
php
|
protected function make_new_calculated_question_summary_stat($randomquestioncalculated, $subquestionstats) {
$question = $randomquestioncalculated->question;
$slot = $randomquestioncalculated->slot;
$calculatedsummary = new calculated_question_summary($question, $slot, $subquestionstats);
return $calculatedsummary;
}
|
[
"protected",
"function",
"make_new_calculated_question_summary_stat",
"(",
"$",
"randomquestioncalculated",
",",
"$",
"subquestionstats",
")",
"{",
"$",
"question",
"=",
"$",
"randomquestioncalculated",
"->",
"question",
";",
"$",
"slot",
"=",
"$",
"randomquestioncalculated",
"->",
"slot",
";",
"$",
"calculatedsummary",
"=",
"new",
"calculated_question_summary",
"(",
"$",
"question",
",",
"$",
"slot",
",",
"$",
"subquestionstats",
")",
";",
"return",
"$",
"calculatedsummary",
";",
"}"
] |
Create a summary calculated object for a calculated question. This is used as a placeholder
to indicate that a calculated question has sub questions or variations to show rather than listing each
subquestion or variation directly.
@param calculated $randomquestioncalculated The calculated instance for the random question slot.
@param calculated[] $subquestionstats The instances of the calculated stats of the questions that are being summarised.
@return calculated_question_summary
|
[
"Create",
"a",
"summary",
"calculated",
"object",
"for",
"a",
"calculated",
"question",
".",
"This",
"is",
"used",
"as",
"a",
"placeholder",
"to",
"indicate",
"that",
"a",
"calculated",
"question",
"has",
"sub",
"questions",
"or",
"variations",
"to",
"show",
"rather",
"than",
"listing",
"each",
"subquestion",
"or",
"variation",
"directly",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/classes/statistics/questions/all_calculated_for_qubaid_condition.php#L453-L459
|
219,422
|
moodle/moodle
|
mod/forum/classes/local/factories/legacy_data_mapper.php
|
legacy_data_mapper.get_legacy_data_mapper_for_vault
|
public function get_legacy_data_mapper_for_vault($entity) {
switch($entity) {
case 'forum':
return $this->get_forum_data_mapper();
case 'discussion':
return $this->get_discussion_data_mapper();
case 'post':
return $this->get_post_data_mapper();
case 'author':
return $this->get_author_data_mapper();
}
}
|
php
|
public function get_legacy_data_mapper_for_vault($entity) {
switch($entity) {
case 'forum':
return $this->get_forum_data_mapper();
case 'discussion':
return $this->get_discussion_data_mapper();
case 'post':
return $this->get_post_data_mapper();
case 'author':
return $this->get_author_data_mapper();
}
}
|
[
"public",
"function",
"get_legacy_data_mapper_for_vault",
"(",
"$",
"entity",
")",
"{",
"switch",
"(",
"$",
"entity",
")",
"{",
"case",
"'forum'",
":",
"return",
"$",
"this",
"->",
"get_forum_data_mapper",
"(",
")",
";",
"case",
"'discussion'",
":",
"return",
"$",
"this",
"->",
"get_discussion_data_mapper",
"(",
")",
";",
"case",
"'post'",
":",
"return",
"$",
"this",
"->",
"get_post_data_mapper",
"(",
")",
";",
"case",
"'author'",
":",
"return",
"$",
"this",
"->",
"get_author_data_mapper",
"(",
")",
";",
"}",
"}"
] |
Get the corresponding entity based on the supplied value
@param string $entity
@return author_data_mapper|discussion_data_mapper|forum_data_mapper|post_data_mapper
|
[
"Get",
"the",
"corresponding",
"entity",
"based",
"on",
"the",
"supplied",
"value"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/factories/legacy_data_mapper.php#L87-L98
|
219,423
|
moodle/moodle
|
admin/tool/dataprivacy/classes/metadata_registry.php
|
metadata_registry.format_metadata
|
protected function format_metadata($collection, $component, $internaldata) {
foreach ($collection as $collectioninfo) {
$privacyfields = $collectioninfo->get_privacy_fields();
$fields = '';
if (!empty($privacyfields)) {
$fields = array_map(function($key, $field) use ($component) {
return [
'field_name' => $key,
'field_summary' => get_string($field, $component)
];
}, array_keys($privacyfields), $privacyfields);
}
// Can the metadata types be located somewhere else besides core?
$items = explode('\\', get_class($collectioninfo));
$type = array_pop($items);
$typedata = [
'name' => $collectioninfo->get_name(),
'type' => $type,
'fields' => $fields,
'summary' => get_string($collectioninfo->get_summary(), $component)
];
if (strpos($type, 'subsystem_link') === 0 || strpos($type, 'plugintype_link') === 0) {
$typedata['link'] = true;
}
$internaldata['metadata'][] = $typedata;
}
return $internaldata;
}
|
php
|
protected function format_metadata($collection, $component, $internaldata) {
foreach ($collection as $collectioninfo) {
$privacyfields = $collectioninfo->get_privacy_fields();
$fields = '';
if (!empty($privacyfields)) {
$fields = array_map(function($key, $field) use ($component) {
return [
'field_name' => $key,
'field_summary' => get_string($field, $component)
];
}, array_keys($privacyfields), $privacyfields);
}
// Can the metadata types be located somewhere else besides core?
$items = explode('\\', get_class($collectioninfo));
$type = array_pop($items);
$typedata = [
'name' => $collectioninfo->get_name(),
'type' => $type,
'fields' => $fields,
'summary' => get_string($collectioninfo->get_summary(), $component)
];
if (strpos($type, 'subsystem_link') === 0 || strpos($type, 'plugintype_link') === 0) {
$typedata['link'] = true;
}
$internaldata['metadata'][] = $typedata;
}
return $internaldata;
}
|
[
"protected",
"function",
"format_metadata",
"(",
"$",
"collection",
",",
"$",
"component",
",",
"$",
"internaldata",
")",
"{",
"foreach",
"(",
"$",
"collection",
"as",
"$",
"collectioninfo",
")",
"{",
"$",
"privacyfields",
"=",
"$",
"collectioninfo",
"->",
"get_privacy_fields",
"(",
")",
";",
"$",
"fields",
"=",
"''",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"privacyfields",
")",
")",
"{",
"$",
"fields",
"=",
"array_map",
"(",
"function",
"(",
"$",
"key",
",",
"$",
"field",
")",
"use",
"(",
"$",
"component",
")",
"{",
"return",
"[",
"'field_name'",
"=>",
"$",
"key",
",",
"'field_summary'",
"=>",
"get_string",
"(",
"$",
"field",
",",
"$",
"component",
")",
"]",
";",
"}",
",",
"array_keys",
"(",
"$",
"privacyfields",
")",
",",
"$",
"privacyfields",
")",
";",
"}",
"// Can the metadata types be located somewhere else besides core?",
"$",
"items",
"=",
"explode",
"(",
"'\\\\'",
",",
"get_class",
"(",
"$",
"collectioninfo",
")",
")",
";",
"$",
"type",
"=",
"array_pop",
"(",
"$",
"items",
")",
";",
"$",
"typedata",
"=",
"[",
"'name'",
"=>",
"$",
"collectioninfo",
"->",
"get_name",
"(",
")",
",",
"'type'",
"=>",
"$",
"type",
",",
"'fields'",
"=>",
"$",
"fields",
",",
"'summary'",
"=>",
"get_string",
"(",
"$",
"collectioninfo",
"->",
"get_summary",
"(",
")",
",",
"$",
"component",
")",
"]",
";",
"if",
"(",
"strpos",
"(",
"$",
"type",
",",
"'subsystem_link'",
")",
"===",
"0",
"||",
"strpos",
"(",
"$",
"type",
",",
"'plugintype_link'",
")",
"===",
"0",
")",
"{",
"$",
"typedata",
"[",
"'link'",
"]",
"=",
"true",
";",
"}",
"$",
"internaldata",
"[",
"'metadata'",
"]",
"[",
"]",
"=",
"$",
"typedata",
";",
"}",
"return",
"$",
"internaldata",
";",
"}"
] |
Formats the metadata for use with a template.
@param array $collection The collection associated with the component that we want to expand and format.
@param string $component The component that we are dealing in
@param array $internaldata The array to add the formatted metadata to.
@return array The internal data array with the formatted metadata.
|
[
"Formats",
"the",
"metadata",
"for",
"use",
"with",
"a",
"template",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/metadata_registry.php#L122-L149
|
219,424
|
moodle/moodle
|
admin/tool/dataprivacy/classes/metadata_registry.php
|
metadata_registry.get_full_component_list
|
protected function get_full_component_list() {
global $CFG;
$list = \core_component::get_component_list();
$list['core']['core'] = "{$CFG->dirroot}/lib";
$formattedlist = [];
foreach ($list as $plugintype => $plugin) {
$formattedlist[] = ['plugin_type' => $plugintype, 'plugins' => array_keys($plugin)];
}
return $formattedlist;
}
|
php
|
protected function get_full_component_list() {
global $CFG;
$list = \core_component::get_component_list();
$list['core']['core'] = "{$CFG->dirroot}/lib";
$formattedlist = [];
foreach ($list as $plugintype => $plugin) {
$formattedlist[] = ['plugin_type' => $plugintype, 'plugins' => array_keys($plugin)];
}
return $formattedlist;
}
|
[
"protected",
"function",
"get_full_component_list",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"list",
"=",
"\\",
"core_component",
"::",
"get_component_list",
"(",
")",
";",
"$",
"list",
"[",
"'core'",
"]",
"[",
"'core'",
"]",
"=",
"\"{$CFG->dirroot}/lib\"",
";",
"$",
"formattedlist",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"list",
"as",
"$",
"plugintype",
"=>",
"$",
"plugin",
")",
"{",
"$",
"formattedlist",
"[",
"]",
"=",
"[",
"'plugin_type'",
"=>",
"$",
"plugintype",
",",
"'plugins'",
"=>",
"array_keys",
"(",
"$",
"plugin",
")",
"]",
";",
"}",
"return",
"$",
"formattedlist",
";",
"}"
] |
Return the full list of components.
@return array An array of plugin types which contain plugin data.
|
[
"Return",
"the",
"full",
"list",
"of",
"components",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/metadata_registry.php#L156-L167
|
219,425
|
moodle/moodle
|
admin/tool/dataprivacy/classes/metadata_registry.php
|
metadata_registry.get_contrib_list
|
protected function get_contrib_list() {
return array_map(function($plugins) {
return array_filter($plugins, function($plugindata) {
return !$plugindata->is_standard();
});
}, \core_plugin_manager::instance()->get_plugins());
}
|
php
|
protected function get_contrib_list() {
return array_map(function($plugins) {
return array_filter($plugins, function($plugindata) {
return !$plugindata->is_standard();
});
}, \core_plugin_manager::instance()->get_plugins());
}
|
[
"protected",
"function",
"get_contrib_list",
"(",
")",
"{",
"return",
"array_map",
"(",
"function",
"(",
"$",
"plugins",
")",
"{",
"return",
"array_filter",
"(",
"$",
"plugins",
",",
"function",
"(",
"$",
"plugindata",
")",
"{",
"return",
"!",
"$",
"plugindata",
"->",
"is_standard",
"(",
")",
";",
"}",
")",
";",
"}",
",",
"\\",
"core_plugin_manager",
"::",
"instance",
"(",
")",
"->",
"get_plugins",
"(",
")",
")",
";",
"}"
] |
Returns a list of contributed plugins installed on the system.
@return array A list of contributed plugins installed.
|
[
"Returns",
"a",
"list",
"of",
"contributed",
"plugins",
"installed",
"on",
"the",
"system",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/metadata_registry.php#L174-L180
|
219,426
|
moodle/moodle
|
lib/adodb/datadict/datadict-mysql.inc.php
|
ADODB2_mysql.MetaType
|
function MetaType($t,$len=-1,$fieldobj=false)
{
if (is_object($t)) {
$fieldobj = $t;
$t = $fieldobj->type;
$len = $fieldobj->max_length;
}
$is_serial = is_object($fieldobj) && $fieldobj->primary_key && $fieldobj->auto_increment;
$len = -1; // mysql max_length is not accurate
switch (strtoupper($t)) {
case 'STRING':
case 'CHAR':
case 'VARCHAR':
case 'TINYBLOB':
case 'TINYTEXT':
case 'ENUM':
case 'SET':
if ($len <= $this->blobSize) return 'C';
case 'TEXT':
case 'LONGTEXT':
case 'MEDIUMTEXT':
return 'X';
// php_mysql extension always returns 'blob' even if 'text'
// so we have to check whether binary...
case 'IMAGE':
case 'LONGBLOB':
case 'BLOB':
case 'MEDIUMBLOB':
return !empty($fieldobj->binary) ? 'B' : 'X';
case 'YEAR':
case 'DATE': return 'D';
case 'TIME':
case 'DATETIME':
case 'TIMESTAMP': return 'T';
case 'FLOAT':
case 'DOUBLE':
return 'F';
case 'INT':
case 'INTEGER': return $is_serial ? 'R' : 'I';
case 'TINYINT': return $is_serial ? 'R' : 'I1';
case 'SMALLINT': return $is_serial ? 'R' : 'I2';
case 'MEDIUMINT': return $is_serial ? 'R' : 'I4';
case 'BIGINT': return $is_serial ? 'R' : 'I8';
default: return 'N';
}
}
|
php
|
function MetaType($t,$len=-1,$fieldobj=false)
{
if (is_object($t)) {
$fieldobj = $t;
$t = $fieldobj->type;
$len = $fieldobj->max_length;
}
$is_serial = is_object($fieldobj) && $fieldobj->primary_key && $fieldobj->auto_increment;
$len = -1; // mysql max_length is not accurate
switch (strtoupper($t)) {
case 'STRING':
case 'CHAR':
case 'VARCHAR':
case 'TINYBLOB':
case 'TINYTEXT':
case 'ENUM':
case 'SET':
if ($len <= $this->blobSize) return 'C';
case 'TEXT':
case 'LONGTEXT':
case 'MEDIUMTEXT':
return 'X';
// php_mysql extension always returns 'blob' even if 'text'
// so we have to check whether binary...
case 'IMAGE':
case 'LONGBLOB':
case 'BLOB':
case 'MEDIUMBLOB':
return !empty($fieldobj->binary) ? 'B' : 'X';
case 'YEAR':
case 'DATE': return 'D';
case 'TIME':
case 'DATETIME':
case 'TIMESTAMP': return 'T';
case 'FLOAT':
case 'DOUBLE':
return 'F';
case 'INT':
case 'INTEGER': return $is_serial ? 'R' : 'I';
case 'TINYINT': return $is_serial ? 'R' : 'I1';
case 'SMALLINT': return $is_serial ? 'R' : 'I2';
case 'MEDIUMINT': return $is_serial ? 'R' : 'I4';
case 'BIGINT': return $is_serial ? 'R' : 'I8';
default: return 'N';
}
}
|
[
"function",
"MetaType",
"(",
"$",
"t",
",",
"$",
"len",
"=",
"-",
"1",
",",
"$",
"fieldobj",
"=",
"false",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"t",
")",
")",
"{",
"$",
"fieldobj",
"=",
"$",
"t",
";",
"$",
"t",
"=",
"$",
"fieldobj",
"->",
"type",
";",
"$",
"len",
"=",
"$",
"fieldobj",
"->",
"max_length",
";",
"}",
"$",
"is_serial",
"=",
"is_object",
"(",
"$",
"fieldobj",
")",
"&&",
"$",
"fieldobj",
"->",
"primary_key",
"&&",
"$",
"fieldobj",
"->",
"auto_increment",
";",
"$",
"len",
"=",
"-",
"1",
";",
"// mysql max_length is not accurate",
"switch",
"(",
"strtoupper",
"(",
"$",
"t",
")",
")",
"{",
"case",
"'STRING'",
":",
"case",
"'CHAR'",
":",
"case",
"'VARCHAR'",
":",
"case",
"'TINYBLOB'",
":",
"case",
"'TINYTEXT'",
":",
"case",
"'ENUM'",
":",
"case",
"'SET'",
":",
"if",
"(",
"$",
"len",
"<=",
"$",
"this",
"->",
"blobSize",
")",
"return",
"'C'",
";",
"case",
"'TEXT'",
":",
"case",
"'LONGTEXT'",
":",
"case",
"'MEDIUMTEXT'",
":",
"return",
"'X'",
";",
"// php_mysql extension always returns 'blob' even if 'text'",
"// so we have to check whether binary...",
"case",
"'IMAGE'",
":",
"case",
"'LONGBLOB'",
":",
"case",
"'BLOB'",
":",
"case",
"'MEDIUMBLOB'",
":",
"return",
"!",
"empty",
"(",
"$",
"fieldobj",
"->",
"binary",
")",
"?",
"'B'",
":",
"'X'",
";",
"case",
"'YEAR'",
":",
"case",
"'DATE'",
":",
"return",
"'D'",
";",
"case",
"'TIME'",
":",
"case",
"'DATETIME'",
":",
"case",
"'TIMESTAMP'",
":",
"return",
"'T'",
";",
"case",
"'FLOAT'",
":",
"case",
"'DOUBLE'",
":",
"return",
"'F'",
";",
"case",
"'INT'",
":",
"case",
"'INTEGER'",
":",
"return",
"$",
"is_serial",
"?",
"'R'",
":",
"'I'",
";",
"case",
"'TINYINT'",
":",
"return",
"$",
"is_serial",
"?",
"'R'",
":",
"'I1'",
";",
"case",
"'SMALLINT'",
":",
"return",
"$",
"is_serial",
"?",
"'R'",
":",
"'I2'",
";",
"case",
"'MEDIUMINT'",
":",
"return",
"$",
"is_serial",
"?",
"'R'",
":",
"'I4'",
";",
"case",
"'BIGINT'",
":",
"return",
"$",
"is_serial",
"?",
"'R'",
":",
"'I8'",
";",
"default",
":",
"return",
"'N'",
";",
"}",
"}"
] |
needs column-definition!
|
[
"needs",
"column",
"-",
"definition!"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/datadict/datadict-mysql.inc.php#L27-L79
|
219,427
|
moodle/moodle
|
auth/cas/CAS/CAS/ProxiedService/Http/Post.php
|
CAS_ProxiedService_Http_Post.populateRequest
|
protected function populateRequest (CAS_Request_RequestInterface $request)
{
if (empty($this->_contentType) && !empty($this->_body)) {
throw new CAS_ProxiedService_Exception(
"If you pass a POST body, you must specify a content type via "
.get_class($this).'->setContentType($contentType).'
);
}
$request->makePost();
if (!empty($this->_body)) {
$request->addHeader('Content-Type: '.$this->_contentType);
$request->addHeader('Content-Length: '.strlen($this->_body));
$request->setPostBody($this->_body);
}
}
|
php
|
protected function populateRequest (CAS_Request_RequestInterface $request)
{
if (empty($this->_contentType) && !empty($this->_body)) {
throw new CAS_ProxiedService_Exception(
"If you pass a POST body, you must specify a content type via "
.get_class($this).'->setContentType($contentType).'
);
}
$request->makePost();
if (!empty($this->_body)) {
$request->addHeader('Content-Type: '.$this->_contentType);
$request->addHeader('Content-Length: '.strlen($this->_body));
$request->setPostBody($this->_body);
}
}
|
[
"protected",
"function",
"populateRequest",
"(",
"CAS_Request_RequestInterface",
"$",
"request",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_contentType",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"_body",
")",
")",
"{",
"throw",
"new",
"CAS_ProxiedService_Exception",
"(",
"\"If you pass a POST body, you must specify a content type via \"",
".",
"get_class",
"(",
"$",
"this",
")",
".",
"'->setContentType($contentType).'",
")",
";",
"}",
"$",
"request",
"->",
"makePost",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_body",
")",
")",
"{",
"$",
"request",
"->",
"addHeader",
"(",
"'Content-Type: '",
".",
"$",
"this",
"->",
"_contentType",
")",
";",
"$",
"request",
"->",
"addHeader",
"(",
"'Content-Length: '",
".",
"strlen",
"(",
"$",
"this",
"->",
"_body",
")",
")",
";",
"$",
"request",
"->",
"setPostBody",
"(",
"$",
"this",
"->",
"_body",
")",
";",
"}",
"}"
] |
Add any other parts of the request needed by concrete classes
@param CAS_Request_RequestInterface $request request interface class
@return void
|
[
"Add",
"any",
"other",
"parts",
"of",
"the",
"request",
"needed",
"by",
"concrete",
"classes"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/ProxiedService/Http/Post.php#L133-L148
|
219,428
|
moodle/moodle
|
lib/editor/tinymce/classes/plugin.php
|
editor_tinymce_plugin.add_button_before
|
protected function add_button_before(array &$params, $row, $button,
$before = '', $alwaysadd = true) {
if ($button !== '|' && $this->find_button($params, $button)) {
return true;
}
$row = $this->fix_row($params, $row);
$field = 'theme_advanced_buttons' . $row;
$old = $params[$field];
// Empty = add at start.
if ($before === '') {
$params[$field] = $button . ',' . $old;
return true;
}
// Try to add before given plugin.
$params[$field] = preg_replace('~(,|^)(' . preg_quote($before) . ')(,|$)~',
'$1' . $button . ',$2$3', $old);
if ($params[$field] !== $old) {
return true;
}
// If always adding, recurse to add it empty.
if ($alwaysadd) {
return $this->add_button_before($params, $row, $button);
}
// Otherwise return false (failed to add).
return false;
}
|
php
|
protected function add_button_before(array &$params, $row, $button,
$before = '', $alwaysadd = true) {
if ($button !== '|' && $this->find_button($params, $button)) {
return true;
}
$row = $this->fix_row($params, $row);
$field = 'theme_advanced_buttons' . $row;
$old = $params[$field];
// Empty = add at start.
if ($before === '') {
$params[$field] = $button . ',' . $old;
return true;
}
// Try to add before given plugin.
$params[$field] = preg_replace('~(,|^)(' . preg_quote($before) . ')(,|$)~',
'$1' . $button . ',$2$3', $old);
if ($params[$field] !== $old) {
return true;
}
// If always adding, recurse to add it empty.
if ($alwaysadd) {
return $this->add_button_before($params, $row, $button);
}
// Otherwise return false (failed to add).
return false;
}
|
[
"protected",
"function",
"add_button_before",
"(",
"array",
"&",
"$",
"params",
",",
"$",
"row",
",",
"$",
"button",
",",
"$",
"before",
"=",
"''",
",",
"$",
"alwaysadd",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"button",
"!==",
"'|'",
"&&",
"$",
"this",
"->",
"find_button",
"(",
"$",
"params",
",",
"$",
"button",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"row",
"=",
"$",
"this",
"->",
"fix_row",
"(",
"$",
"params",
",",
"$",
"row",
")",
";",
"$",
"field",
"=",
"'theme_advanced_buttons'",
".",
"$",
"row",
";",
"$",
"old",
"=",
"$",
"params",
"[",
"$",
"field",
"]",
";",
"// Empty = add at start.",
"if",
"(",
"$",
"before",
"===",
"''",
")",
"{",
"$",
"params",
"[",
"$",
"field",
"]",
"=",
"$",
"button",
".",
"','",
".",
"$",
"old",
";",
"return",
"true",
";",
"}",
"// Try to add before given plugin.",
"$",
"params",
"[",
"$",
"field",
"]",
"=",
"preg_replace",
"(",
"'~(,|^)('",
".",
"preg_quote",
"(",
"$",
"before",
")",
".",
"')(,|$)~'",
",",
"'$1'",
".",
"$",
"button",
".",
"',$2$3'",
",",
"$",
"old",
")",
";",
"if",
"(",
"$",
"params",
"[",
"$",
"field",
"]",
"!==",
"$",
"old",
")",
"{",
"return",
"true",
";",
"}",
"// If always adding, recurse to add it empty.",
"if",
"(",
"$",
"alwaysadd",
")",
"{",
"return",
"$",
"this",
"->",
"add_button_before",
"(",
"$",
"params",
",",
"$",
"row",
",",
"$",
"button",
")",
";",
"}",
"// Otherwise return false (failed to add).",
"return",
"false",
";",
"}"
] |
Adds a button to the editor.
Specify the location of this button using the $before variable. If you
leave this blank, the button will be added at the start.
If you want to try different possible locations depending on existing
plugins you can set $alwaysadd to false and check the return value
to see if it succeeded.
Note: button will not be added if it is already present in any row
(separator is an exception).
The following example will add the button 'newbutton' before the
'existingbutton' if it exists or in the end of the last row otherwise:
<pre>
if ($row = $this->find_button($params, 'existingbutton')) {
$this->add_button_before($params, $row, 'newbutton', 'existingbutton');
} else {
$this->add_button_after($params, $this->count_button_rows($params), 'newbutton');
}
</pre>
@param array $params TinyMCE init parameters array
@param int $row Row to add button to (1 to 10)
@param string $button Identifier of button/plugin
@param string $before Adds button directly before the named plugin
@param bool $alwaysadd If specified $before string not found, add at start
@return bool True if added or button already exists (in any row)
|
[
"Adds",
"a",
"button",
"to",
"the",
"editor",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/editor/tinymce/classes/plugin.php#L230-L261
|
219,429
|
moodle/moodle
|
lib/editor/tinymce/classes/plugin.php
|
editor_tinymce_plugin.find_button
|
protected function find_button(array &$params, $button) {
foreach ($params as $key => $value) {
if (preg_match('/^theme_advanced_buttons(\d+)$/', $key, $matches) &&
strpos(','. $value. ',', ','. $button. ',') !== false) {
return (int)$matches[1];
}
}
return false;
}
|
php
|
protected function find_button(array &$params, $button) {
foreach ($params as $key => $value) {
if (preg_match('/^theme_advanced_buttons(\d+)$/', $key, $matches) &&
strpos(','. $value. ',', ','. $button. ',') !== false) {
return (int)$matches[1];
}
}
return false;
}
|
[
"protected",
"function",
"find_button",
"(",
"array",
"&",
"$",
"params",
",",
"$",
"button",
")",
"{",
"foreach",
"(",
"$",
"params",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/^theme_advanced_buttons(\\d+)$/'",
",",
"$",
"key",
",",
"$",
"matches",
")",
"&&",
"strpos",
"(",
"','",
".",
"$",
"value",
".",
"','",
",",
"','",
".",
"$",
"button",
".",
"','",
")",
"!==",
"false",
")",
"{",
"return",
"(",
"int",
")",
"$",
"matches",
"[",
"1",
"]",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Tests if button is already present.
@param array $params TinyMCE init parameters array
@param string $button button name
@return false|int false if button is not found, row number otherwise (row numbers start from 1)
|
[
"Tests",
"if",
"button",
"is",
"already",
"present",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/editor/tinymce/classes/plugin.php#L270-L278
|
219,430
|
moodle/moodle
|
lib/editor/tinymce/classes/plugin.php
|
editor_tinymce_plugin.fix_row
|
private function fix_row(array &$params, $row) {
if ($row <= 1) {
// Row 1 is always present.
return 1;
} else if (isset($params['theme_advanced_buttons' . $row])) {
return $row;
} else {
return $this->count_button_rows($params);
}
}
|
php
|
private function fix_row(array &$params, $row) {
if ($row <= 1) {
// Row 1 is always present.
return 1;
} else if (isset($params['theme_advanced_buttons' . $row])) {
return $row;
} else {
return $this->count_button_rows($params);
}
}
|
[
"private",
"function",
"fix_row",
"(",
"array",
"&",
"$",
"params",
",",
"$",
"row",
")",
"{",
"if",
"(",
"$",
"row",
"<=",
"1",
")",
"{",
"// Row 1 is always present.",
"return",
"1",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'theme_advanced_buttons'",
".",
"$",
"row",
"]",
")",
")",
"{",
"return",
"$",
"row",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"count_button_rows",
"(",
"$",
"params",
")",
";",
"}",
"}"
] |
Checks the row value is valid, fix if necessary.
@param array $params TinyMCE init parameters array
@param int $row Row to add button if exists
@return int requested row if exists, lower number if does not exist.
|
[
"Checks",
"the",
"row",
"value",
"is",
"valid",
"fix",
"if",
"necessary",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/editor/tinymce/classes/plugin.php#L287-L296
|
219,431
|
moodle/moodle
|
lib/editor/tinymce/classes/plugin.php
|
editor_tinymce_plugin.add_js_plugin
|
protected function add_js_plugin(&$params, $pluginname='', $jsfile='editor_plugin.js') {
global $CFG;
// Set default plugin name.
if ($pluginname === '') {
$pluginname = $this->plugin;
}
// Add plugin to list in params, so it doesn't try to load it again.
$params['plugins'] .= ',-' . $pluginname;
// Add special param that causes Moodle TinyMCE init to load the plugin.
if (!isset($params['moodle_init_plugins'])) {
$params['moodle_init_plugins'] = '';
} else {
$params['moodle_init_plugins'] .= ',';
}
// Get URL of main JS file and store in params.
$jsurl = $this->get_tinymce_file_url($jsfile, false);
$params['moodle_init_plugins'] .= $pluginname . ':' . $jsurl;
}
|
php
|
protected function add_js_plugin(&$params, $pluginname='', $jsfile='editor_plugin.js') {
global $CFG;
// Set default plugin name.
if ($pluginname === '') {
$pluginname = $this->plugin;
}
// Add plugin to list in params, so it doesn't try to load it again.
$params['plugins'] .= ',-' . $pluginname;
// Add special param that causes Moodle TinyMCE init to load the plugin.
if (!isset($params['moodle_init_plugins'])) {
$params['moodle_init_plugins'] = '';
} else {
$params['moodle_init_plugins'] .= ',';
}
// Get URL of main JS file and store in params.
$jsurl = $this->get_tinymce_file_url($jsfile, false);
$params['moodle_init_plugins'] .= $pluginname . ':' . $jsurl;
}
|
[
"protected",
"function",
"add_js_plugin",
"(",
"&",
"$",
"params",
",",
"$",
"pluginname",
"=",
"''",
",",
"$",
"jsfile",
"=",
"'editor_plugin.js'",
")",
"{",
"global",
"$",
"CFG",
";",
"// Set default plugin name.",
"if",
"(",
"$",
"pluginname",
"===",
"''",
")",
"{",
"$",
"pluginname",
"=",
"$",
"this",
"->",
"plugin",
";",
"}",
"// Add plugin to list in params, so it doesn't try to load it again.",
"$",
"params",
"[",
"'plugins'",
"]",
".=",
"',-'",
".",
"$",
"pluginname",
";",
"// Add special param that causes Moodle TinyMCE init to load the plugin.",
"if",
"(",
"!",
"isset",
"(",
"$",
"params",
"[",
"'moodle_init_plugins'",
"]",
")",
")",
"{",
"$",
"params",
"[",
"'moodle_init_plugins'",
"]",
"=",
"''",
";",
"}",
"else",
"{",
"$",
"params",
"[",
"'moodle_init_plugins'",
"]",
".=",
"','",
";",
"}",
"// Get URL of main JS file and store in params.",
"$",
"jsurl",
"=",
"$",
"this",
"->",
"get_tinymce_file_url",
"(",
"$",
"jsfile",
",",
"false",
")",
";",
"$",
"params",
"[",
"'moodle_init_plugins'",
"]",
".=",
"$",
"pluginname",
".",
"':'",
".",
"$",
"jsurl",
";",
"}"
] |
Adds a JavaScript plugin into TinyMCE. Note that adding a plugin does
not by itself add a button; you must do both.
If you leave $pluginname blank (default) it uses the folder name.
@param array $params TinyMCE init parameters array
@param string $pluginname Identifier for plugin within TinyMCE
@param string $jsfile Name of JS file (within plugin 'tinymce' directory)
|
[
"Adds",
"a",
"JavaScript",
"plugin",
"into",
"TinyMCE",
".",
"Note",
"that",
"adding",
"a",
"plugin",
"does",
"not",
"by",
"itself",
"add",
"a",
"button",
";",
"you",
"must",
"do",
"both",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/editor/tinymce/classes/plugin.php#L325-L346
|
219,432
|
moodle/moodle
|
lib/editor/tinymce/classes/plugin.php
|
editor_tinymce_plugin.get_version
|
protected function get_version() {
global $CFG;
$plugin = new stdClass;
require($CFG->dirroot . '/lib/editor/tinymce/plugins/' . $this->plugin . '/version.php');
return $plugin->version;
}
|
php
|
protected function get_version() {
global $CFG;
$plugin = new stdClass;
require($CFG->dirroot . '/lib/editor/tinymce/plugins/' . $this->plugin . '/version.php');
return $plugin->version;
}
|
[
"protected",
"function",
"get_version",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"plugin",
"=",
"new",
"stdClass",
";",
"require",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/lib/editor/tinymce/plugins/'",
".",
"$",
"this",
"->",
"plugin",
".",
"'/version.php'",
")",
";",
"return",
"$",
"plugin",
"->",
"version",
";",
"}"
] |
Obtains version number from version.php for this plugin.
@return string Version number
|
[
"Obtains",
"version",
"number",
"from",
"version",
".",
"php",
"for",
"this",
"plugin",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/editor/tinymce/classes/plugin.php#L394-L400
|
219,433
|
moodle/moodle
|
lib/editor/tinymce/classes/plugin.php
|
editor_tinymce_plugin.all_update_init_params
|
public static function all_update_init_params(array &$params,
context $context, array $options = null) {
global $CFG;
// Get list of plugin directories.
$plugins = core_component::get_plugin_list('tinymce');
// Get list of disabled subplugins.
$disabled = array();
if ($params['moodle_config']->disabledsubplugins) {
foreach (explode(',', $params['moodle_config']->disabledsubplugins) as $sp) {
$sp = trim($sp);
if ($sp !== '') {
$disabled[$sp] = $sp;
}
}
}
// Construct all the plugins.
$pluginobjects = array();
foreach ($plugins as $plugin => $dir) {
if (isset($disabled[$plugin])) {
continue;
}
require_once($dir . '/lib.php');
$classname = 'tinymce_' . $plugin;
$pluginobjects[] = new $classname($plugin);
}
// Sort plugins by sort order and name.
usort($pluginobjects, array('editor_tinymce_plugin', 'compare_plugins'));
// Run the function for each plugin.
foreach ($pluginobjects as $obj) {
$obj->update_init_params($params, $context, $options);
}
}
|
php
|
public static function all_update_init_params(array &$params,
context $context, array $options = null) {
global $CFG;
// Get list of plugin directories.
$plugins = core_component::get_plugin_list('tinymce');
// Get list of disabled subplugins.
$disabled = array();
if ($params['moodle_config']->disabledsubplugins) {
foreach (explode(',', $params['moodle_config']->disabledsubplugins) as $sp) {
$sp = trim($sp);
if ($sp !== '') {
$disabled[$sp] = $sp;
}
}
}
// Construct all the plugins.
$pluginobjects = array();
foreach ($plugins as $plugin => $dir) {
if (isset($disabled[$plugin])) {
continue;
}
require_once($dir . '/lib.php');
$classname = 'tinymce_' . $plugin;
$pluginobjects[] = new $classname($plugin);
}
// Sort plugins by sort order and name.
usort($pluginobjects, array('editor_tinymce_plugin', 'compare_plugins'));
// Run the function for each plugin.
foreach ($pluginobjects as $obj) {
$obj->update_init_params($params, $context, $options);
}
}
|
[
"public",
"static",
"function",
"all_update_init_params",
"(",
"array",
"&",
"$",
"params",
",",
"context",
"$",
"context",
",",
"array",
"$",
"options",
"=",
"null",
")",
"{",
"global",
"$",
"CFG",
";",
"// Get list of plugin directories.",
"$",
"plugins",
"=",
"core_component",
"::",
"get_plugin_list",
"(",
"'tinymce'",
")",
";",
"// Get list of disabled subplugins.",
"$",
"disabled",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"params",
"[",
"'moodle_config'",
"]",
"->",
"disabledsubplugins",
")",
"{",
"foreach",
"(",
"explode",
"(",
"','",
",",
"$",
"params",
"[",
"'moodle_config'",
"]",
"->",
"disabledsubplugins",
")",
"as",
"$",
"sp",
")",
"{",
"$",
"sp",
"=",
"trim",
"(",
"$",
"sp",
")",
";",
"if",
"(",
"$",
"sp",
"!==",
"''",
")",
"{",
"$",
"disabled",
"[",
"$",
"sp",
"]",
"=",
"$",
"sp",
";",
"}",
"}",
"}",
"// Construct all the plugins.",
"$",
"pluginobjects",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"plugins",
"as",
"$",
"plugin",
"=>",
"$",
"dir",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"disabled",
"[",
"$",
"plugin",
"]",
")",
")",
"{",
"continue",
";",
"}",
"require_once",
"(",
"$",
"dir",
".",
"'/lib.php'",
")",
";",
"$",
"classname",
"=",
"'tinymce_'",
".",
"$",
"plugin",
";",
"$",
"pluginobjects",
"[",
"]",
"=",
"new",
"$",
"classname",
"(",
"$",
"plugin",
")",
";",
"}",
"// Sort plugins by sort order and name.",
"usort",
"(",
"$",
"pluginobjects",
",",
"array",
"(",
"'editor_tinymce_plugin'",
",",
"'compare_plugins'",
")",
")",
";",
"// Run the function for each plugin.",
"foreach",
"(",
"$",
"pluginobjects",
"as",
"$",
"obj",
")",
"{",
"$",
"obj",
"->",
"update_init_params",
"(",
"$",
"params",
",",
"$",
"context",
",",
"$",
"options",
")",
";",
"}",
"}"
] |
Calls all available plugins to adjust the TinyMCE init parameters.
@param array $params TinyMCE init parameters array
@param context $context Context where editor is being shown
@param array $options Options for this editor
|
[
"Calls",
"all",
"available",
"plugins",
"to",
"adjust",
"the",
"TinyMCE",
"init",
"parameters",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/editor/tinymce/classes/plugin.php#L409-L445
|
219,434
|
moodle/moodle
|
lib/editor/tinymce/classes/plugin.php
|
editor_tinymce_plugin.get
|
public static function get($plugin) {
$dir = core_component::get_component_directory('tinymce_' . $plugin);
require_once($dir . '/lib.php');
$classname = 'tinymce_' . $plugin;
return new $classname($plugin);
}
|
php
|
public static function get($plugin) {
$dir = core_component::get_component_directory('tinymce_' . $plugin);
require_once($dir . '/lib.php');
$classname = 'tinymce_' . $plugin;
return new $classname($plugin);
}
|
[
"public",
"static",
"function",
"get",
"(",
"$",
"plugin",
")",
"{",
"$",
"dir",
"=",
"core_component",
"::",
"get_component_directory",
"(",
"'tinymce_'",
".",
"$",
"plugin",
")",
";",
"require_once",
"(",
"$",
"dir",
".",
"'/lib.php'",
")",
";",
"$",
"classname",
"=",
"'tinymce_'",
".",
"$",
"plugin",
";",
"return",
"new",
"$",
"classname",
"(",
"$",
"plugin",
")",
";",
"}"
] |
Gets a named plugin object. Will cause fatal error if plugin doesn't exist.
@param string $plugin Name of plugin e.g. 'moodleemoticon'
@return editor_tinymce_plugin Plugin object
|
[
"Gets",
"a",
"named",
"plugin",
"object",
".",
"Will",
"cause",
"fatal",
"error",
"if",
"plugin",
"doesn",
"t",
"exist",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/editor/tinymce/classes/plugin.php#L453-L458
|
219,435
|
moodle/moodle
|
lib/editor/tinymce/classes/plugin.php
|
editor_tinymce_plugin.compare_plugins
|
public static function compare_plugins(editor_tinymce_plugin $a, editor_tinymce_plugin $b) {
// Use sort order first.
$order = $a->get_sort_order() - $b->get_sort_order();
if ($order != 0) {
return $order;
}
// Then sort alphabetically.
return strcmp($a->plugin, $b->plugin);
}
|
php
|
public static function compare_plugins(editor_tinymce_plugin $a, editor_tinymce_plugin $b) {
// Use sort order first.
$order = $a->get_sort_order() - $b->get_sort_order();
if ($order != 0) {
return $order;
}
// Then sort alphabetically.
return strcmp($a->plugin, $b->plugin);
}
|
[
"public",
"static",
"function",
"compare_plugins",
"(",
"editor_tinymce_plugin",
"$",
"a",
",",
"editor_tinymce_plugin",
"$",
"b",
")",
"{",
"// Use sort order first.",
"$",
"order",
"=",
"$",
"a",
"->",
"get_sort_order",
"(",
")",
"-",
"$",
"b",
"->",
"get_sort_order",
"(",
")",
";",
"if",
"(",
"$",
"order",
"!=",
"0",
")",
"{",
"return",
"$",
"order",
";",
"}",
"// Then sort alphabetically.",
"return",
"strcmp",
"(",
"$",
"a",
"->",
"plugin",
",",
"$",
"b",
"->",
"plugin",
")",
";",
"}"
] |
Compares two plugins.
@param editor_tinymce_plugin $a
@param editor_tinymce_plugin $b
@return Negative number if $a is before $b
|
[
"Compares",
"two",
"plugins",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/editor/tinymce/classes/plugin.php#L466-L475
|
219,436
|
moodle/moodle
|
admin/tool/dataprivacy/classes/local/helper.php
|
helper.get_request_type_string
|
public static function get_request_type_string($requesttype) {
$types = self::get_request_types();
if (!isset($types[$requesttype])) {
throw new moodle_exception('errorinvalidrequesttype', 'tool_dataprivacy');
}
return $types[$requesttype];
}
|
php
|
public static function get_request_type_string($requesttype) {
$types = self::get_request_types();
if (!isset($types[$requesttype])) {
throw new moodle_exception('errorinvalidrequesttype', 'tool_dataprivacy');
}
return $types[$requesttype];
}
|
[
"public",
"static",
"function",
"get_request_type_string",
"(",
"$",
"requesttype",
")",
"{",
"$",
"types",
"=",
"self",
"::",
"get_request_types",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"types",
"[",
"$",
"requesttype",
"]",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'errorinvalidrequesttype'",
",",
"'tool_dataprivacy'",
")",
";",
"}",
"return",
"$",
"types",
"[",
"$",
"requesttype",
"]",
";",
"}"
] |
Retrieves the human-readable text value of a data request type.
@param int $requesttype The request type.
@return string
@throws coding_exception
@throws moodle_exception
|
[
"Retrieves",
"the",
"human",
"-",
"readable",
"text",
"value",
"of",
"a",
"data",
"request",
"type",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/local/helper.php#L65-L71
|
219,437
|
moodle/moodle
|
admin/tool/dataprivacy/classes/local/helper.php
|
helper.get_shortened_request_type_string
|
public static function get_shortened_request_type_string($requesttype) {
$types = self::get_request_types_short();
if (!isset($types[$requesttype])) {
throw new moodle_exception('errorinvalidrequesttype', 'tool_dataprivacy');
}
return $types[$requesttype];
}
|
php
|
public static function get_shortened_request_type_string($requesttype) {
$types = self::get_request_types_short();
if (!isset($types[$requesttype])) {
throw new moodle_exception('errorinvalidrequesttype', 'tool_dataprivacy');
}
return $types[$requesttype];
}
|
[
"public",
"static",
"function",
"get_shortened_request_type_string",
"(",
"$",
"requesttype",
")",
"{",
"$",
"types",
"=",
"self",
"::",
"get_request_types_short",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"types",
"[",
"$",
"requesttype",
"]",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'errorinvalidrequesttype'",
",",
"'tool_dataprivacy'",
")",
";",
"}",
"return",
"$",
"types",
"[",
"$",
"requesttype",
"]",
";",
"}"
] |
Retrieves the human-readable shortened text value of a data request type.
@param int $requesttype The request type.
@return string
@throws coding_exception
@throws moodle_exception
|
[
"Retrieves",
"the",
"human",
"-",
"readable",
"shortened",
"text",
"value",
"of",
"a",
"data",
"request",
"type",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/local/helper.php#L81-L87
|
219,438
|
moodle/moodle
|
admin/tool/dataprivacy/classes/local/helper.php
|
helper.get_request_types
|
public static function get_request_types() {
return [
api::DATAREQUEST_TYPE_EXPORT => get_string('requesttypeexport', 'tool_dataprivacy'),
api::DATAREQUEST_TYPE_DELETE => get_string('requesttypedelete', 'tool_dataprivacy'),
api::DATAREQUEST_TYPE_OTHERS => get_string('requesttypeothers', 'tool_dataprivacy'),
];
}
|
php
|
public static function get_request_types() {
return [
api::DATAREQUEST_TYPE_EXPORT => get_string('requesttypeexport', 'tool_dataprivacy'),
api::DATAREQUEST_TYPE_DELETE => get_string('requesttypedelete', 'tool_dataprivacy'),
api::DATAREQUEST_TYPE_OTHERS => get_string('requesttypeothers', 'tool_dataprivacy'),
];
}
|
[
"public",
"static",
"function",
"get_request_types",
"(",
")",
"{",
"return",
"[",
"api",
"::",
"DATAREQUEST_TYPE_EXPORT",
"=>",
"get_string",
"(",
"'requesttypeexport'",
",",
"'tool_dataprivacy'",
")",
",",
"api",
"::",
"DATAREQUEST_TYPE_DELETE",
"=>",
"get_string",
"(",
"'requesttypedelete'",
",",
"'tool_dataprivacy'",
")",
",",
"api",
"::",
"DATAREQUEST_TYPE_OTHERS",
"=>",
"get_string",
"(",
"'requesttypeothers'",
",",
"'tool_dataprivacy'",
")",
",",
"]",
";",
"}"
] |
Returns the key value-pairs of request type code and their string value.
@return array
|
[
"Returns",
"the",
"key",
"value",
"-",
"pairs",
"of",
"request",
"type",
"code",
"and",
"their",
"string",
"value",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/local/helper.php#L94-L100
|
219,439
|
moodle/moodle
|
admin/tool/dataprivacy/classes/local/helper.php
|
helper.get_request_types_short
|
public static function get_request_types_short() {
return [
api::DATAREQUEST_TYPE_EXPORT => get_string('requesttypeexportshort', 'tool_dataprivacy'),
api::DATAREQUEST_TYPE_DELETE => get_string('requesttypedeleteshort', 'tool_dataprivacy'),
api::DATAREQUEST_TYPE_OTHERS => get_string('requesttypeothersshort', 'tool_dataprivacy'),
];
}
|
php
|
public static function get_request_types_short() {
return [
api::DATAREQUEST_TYPE_EXPORT => get_string('requesttypeexportshort', 'tool_dataprivacy'),
api::DATAREQUEST_TYPE_DELETE => get_string('requesttypedeleteshort', 'tool_dataprivacy'),
api::DATAREQUEST_TYPE_OTHERS => get_string('requesttypeothersshort', 'tool_dataprivacy'),
];
}
|
[
"public",
"static",
"function",
"get_request_types_short",
"(",
")",
"{",
"return",
"[",
"api",
"::",
"DATAREQUEST_TYPE_EXPORT",
"=>",
"get_string",
"(",
"'requesttypeexportshort'",
",",
"'tool_dataprivacy'",
")",
",",
"api",
"::",
"DATAREQUEST_TYPE_DELETE",
"=>",
"get_string",
"(",
"'requesttypedeleteshort'",
",",
"'tool_dataprivacy'",
")",
",",
"api",
"::",
"DATAREQUEST_TYPE_OTHERS",
"=>",
"get_string",
"(",
"'requesttypeothersshort'",
",",
"'tool_dataprivacy'",
")",
",",
"]",
";",
"}"
] |
Returns the key value-pairs of request type code and their shortened string value.
@return array
|
[
"Returns",
"the",
"key",
"value",
"-",
"pairs",
"of",
"request",
"type",
"code",
"and",
"their",
"shortened",
"string",
"value",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/local/helper.php#L107-L113
|
219,440
|
moodle/moodle
|
admin/tool/dataprivacy/classes/local/helper.php
|
helper.get_request_status_string
|
public static function get_request_status_string($status) {
$statuses = self::get_request_statuses();
if (!isset($statuses[$status])) {
throw new moodle_exception('errorinvalidrequeststatus', 'tool_dataprivacy');
}
return $statuses[$status];
}
|
php
|
public static function get_request_status_string($status) {
$statuses = self::get_request_statuses();
if (!isset($statuses[$status])) {
throw new moodle_exception('errorinvalidrequeststatus', 'tool_dataprivacy');
}
return $statuses[$status];
}
|
[
"public",
"static",
"function",
"get_request_status_string",
"(",
"$",
"status",
")",
"{",
"$",
"statuses",
"=",
"self",
"::",
"get_request_statuses",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"statuses",
"[",
"$",
"status",
"]",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'errorinvalidrequeststatus'",
",",
"'tool_dataprivacy'",
")",
";",
"}",
"return",
"$",
"statuses",
"[",
"$",
"status",
"]",
";",
"}"
] |
Retrieves the human-readable value of a data request status.
@param int $status The request status.
@return string
@throws moodle_exception
|
[
"Retrieves",
"the",
"human",
"-",
"readable",
"value",
"of",
"a",
"data",
"request",
"status",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/local/helper.php#L122-L129
|
219,441
|
moodle/moodle
|
admin/tool/dataprivacy/classes/local/helper.php
|
helper.get_request_statuses
|
public static function get_request_statuses() {
return [
api::DATAREQUEST_STATUS_PENDING => get_string('statuspending', 'tool_dataprivacy'),
api::DATAREQUEST_STATUS_AWAITING_APPROVAL => get_string('statusawaitingapproval', 'tool_dataprivacy'),
api::DATAREQUEST_STATUS_APPROVED => get_string('statusapproved', 'tool_dataprivacy'),
api::DATAREQUEST_STATUS_PROCESSING => get_string('statusprocessing', 'tool_dataprivacy'),
api::DATAREQUEST_STATUS_COMPLETE => get_string('statuscomplete', 'tool_dataprivacy'),
api::DATAREQUEST_STATUS_DOWNLOAD_READY => get_string('statusready', 'tool_dataprivacy'),
api::DATAREQUEST_STATUS_EXPIRED => get_string('statusexpired', 'tool_dataprivacy'),
api::DATAREQUEST_STATUS_CANCELLED => get_string('statuscancelled', 'tool_dataprivacy'),
api::DATAREQUEST_STATUS_REJECTED => get_string('statusrejected', 'tool_dataprivacy'),
api::DATAREQUEST_STATUS_DELETED => get_string('statusdeleted', 'tool_dataprivacy'),
];
}
|
php
|
public static function get_request_statuses() {
return [
api::DATAREQUEST_STATUS_PENDING => get_string('statuspending', 'tool_dataprivacy'),
api::DATAREQUEST_STATUS_AWAITING_APPROVAL => get_string('statusawaitingapproval', 'tool_dataprivacy'),
api::DATAREQUEST_STATUS_APPROVED => get_string('statusapproved', 'tool_dataprivacy'),
api::DATAREQUEST_STATUS_PROCESSING => get_string('statusprocessing', 'tool_dataprivacy'),
api::DATAREQUEST_STATUS_COMPLETE => get_string('statuscomplete', 'tool_dataprivacy'),
api::DATAREQUEST_STATUS_DOWNLOAD_READY => get_string('statusready', 'tool_dataprivacy'),
api::DATAREQUEST_STATUS_EXPIRED => get_string('statusexpired', 'tool_dataprivacy'),
api::DATAREQUEST_STATUS_CANCELLED => get_string('statuscancelled', 'tool_dataprivacy'),
api::DATAREQUEST_STATUS_REJECTED => get_string('statusrejected', 'tool_dataprivacy'),
api::DATAREQUEST_STATUS_DELETED => get_string('statusdeleted', 'tool_dataprivacy'),
];
}
|
[
"public",
"static",
"function",
"get_request_statuses",
"(",
")",
"{",
"return",
"[",
"api",
"::",
"DATAREQUEST_STATUS_PENDING",
"=>",
"get_string",
"(",
"'statuspending'",
",",
"'tool_dataprivacy'",
")",
",",
"api",
"::",
"DATAREQUEST_STATUS_AWAITING_APPROVAL",
"=>",
"get_string",
"(",
"'statusawaitingapproval'",
",",
"'tool_dataprivacy'",
")",
",",
"api",
"::",
"DATAREQUEST_STATUS_APPROVED",
"=>",
"get_string",
"(",
"'statusapproved'",
",",
"'tool_dataprivacy'",
")",
",",
"api",
"::",
"DATAREQUEST_STATUS_PROCESSING",
"=>",
"get_string",
"(",
"'statusprocessing'",
",",
"'tool_dataprivacy'",
")",
",",
"api",
"::",
"DATAREQUEST_STATUS_COMPLETE",
"=>",
"get_string",
"(",
"'statuscomplete'",
",",
"'tool_dataprivacy'",
")",
",",
"api",
"::",
"DATAREQUEST_STATUS_DOWNLOAD_READY",
"=>",
"get_string",
"(",
"'statusready'",
",",
"'tool_dataprivacy'",
")",
",",
"api",
"::",
"DATAREQUEST_STATUS_EXPIRED",
"=>",
"get_string",
"(",
"'statusexpired'",
",",
"'tool_dataprivacy'",
")",
",",
"api",
"::",
"DATAREQUEST_STATUS_CANCELLED",
"=>",
"get_string",
"(",
"'statuscancelled'",
",",
"'tool_dataprivacy'",
")",
",",
"api",
"::",
"DATAREQUEST_STATUS_REJECTED",
"=>",
"get_string",
"(",
"'statusrejected'",
",",
"'tool_dataprivacy'",
")",
",",
"api",
"::",
"DATAREQUEST_STATUS_DELETED",
"=>",
"get_string",
"(",
"'statusdeleted'",
",",
"'tool_dataprivacy'",
")",
",",
"]",
";",
"}"
] |
Returns the key value-pairs of request status code and string value.
@return array
|
[
"Returns",
"the",
"key",
"value",
"-",
"pairs",
"of",
"request",
"status",
"code",
"and",
"string",
"value",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/local/helper.php#L136-L149
|
219,442
|
moodle/moodle
|
admin/tool/dataprivacy/classes/local/helper.php
|
helper.get_request_creation_method_string
|
public static function get_request_creation_method_string($creation) {
$creationmethods = self::get_request_creation_methods();
if (!isset($creationmethods[$creation])) {
throw new moodle_exception('errorinvalidrequestcreationmethod', 'tool_dataprivacy');
}
return $creationmethods[$creation];
}
|
php
|
public static function get_request_creation_method_string($creation) {
$creationmethods = self::get_request_creation_methods();
if (!isset($creationmethods[$creation])) {
throw new moodle_exception('errorinvalidrequestcreationmethod', 'tool_dataprivacy');
}
return $creationmethods[$creation];
}
|
[
"public",
"static",
"function",
"get_request_creation_method_string",
"(",
"$",
"creation",
")",
"{",
"$",
"creationmethods",
"=",
"self",
"::",
"get_request_creation_methods",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"creationmethods",
"[",
"$",
"creation",
"]",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'errorinvalidrequestcreationmethod'",
",",
"'tool_dataprivacy'",
")",
";",
"}",
"return",
"$",
"creationmethods",
"[",
"$",
"creation",
"]",
";",
"}"
] |
Retrieves the human-readable value of a data request creation method.
@param int $creation The request creation method.
@return string
@throws moodle_exception
|
[
"Retrieves",
"the",
"human",
"-",
"readable",
"value",
"of",
"a",
"data",
"request",
"creation",
"method",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/local/helper.php#L158-L165
|
219,443
|
moodle/moodle
|
admin/tool/dataprivacy/classes/local/helper.php
|
helper.get_children_of_user
|
public static function get_children_of_user($userid) {
global $DB;
// Get users that the user has role assignments to.
$allusernames = get_all_user_name_fields(true, 'u');
$sql = "SELECT u.id, $allusernames
FROM {role_assignments} ra, {context} c, {user} u
WHERE ra.userid = :userid
AND ra.contextid = c.id
AND c.instanceid = u.id
AND c.contextlevel = :contextlevel";
$params = [
'userid' => $userid,
'contextlevel' => CONTEXT_USER
];
// The final list of users that we will return.
$finalresults = [];
// Our prospective list of users.
if ($candidates = $DB->get_records_sql($sql, $params)) {
foreach ($candidates as $key => $child) {
$childcontext = \context_user::instance($child->id);
if (has_capability('tool/dataprivacy:makedatarequestsforchildren', $childcontext, $userid)) {
$finalresults[$key] = $child;
}
}
}
return $finalresults;
}
|
php
|
public static function get_children_of_user($userid) {
global $DB;
// Get users that the user has role assignments to.
$allusernames = get_all_user_name_fields(true, 'u');
$sql = "SELECT u.id, $allusernames
FROM {role_assignments} ra, {context} c, {user} u
WHERE ra.userid = :userid
AND ra.contextid = c.id
AND c.instanceid = u.id
AND c.contextlevel = :contextlevel";
$params = [
'userid' => $userid,
'contextlevel' => CONTEXT_USER
];
// The final list of users that we will return.
$finalresults = [];
// Our prospective list of users.
if ($candidates = $DB->get_records_sql($sql, $params)) {
foreach ($candidates as $key => $child) {
$childcontext = \context_user::instance($child->id);
if (has_capability('tool/dataprivacy:makedatarequestsforchildren', $childcontext, $userid)) {
$finalresults[$key] = $child;
}
}
}
return $finalresults;
}
|
[
"public",
"static",
"function",
"get_children_of_user",
"(",
"$",
"userid",
")",
"{",
"global",
"$",
"DB",
";",
"// Get users that the user has role assignments to.",
"$",
"allusernames",
"=",
"get_all_user_name_fields",
"(",
"true",
",",
"'u'",
")",
";",
"$",
"sql",
"=",
"\"SELECT u.id, $allusernames\n FROM {role_assignments} ra, {context} c, {user} u\n WHERE ra.userid = :userid\n AND ra.contextid = c.id\n AND c.instanceid = u.id\n AND c.contextlevel = :contextlevel\"",
";",
"$",
"params",
"=",
"[",
"'userid'",
"=>",
"$",
"userid",
",",
"'contextlevel'",
"=>",
"CONTEXT_USER",
"]",
";",
"// The final list of users that we will return.",
"$",
"finalresults",
"=",
"[",
"]",
";",
"// Our prospective list of users.",
"if",
"(",
"$",
"candidates",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
")",
"{",
"foreach",
"(",
"$",
"candidates",
"as",
"$",
"key",
"=>",
"$",
"child",
")",
"{",
"$",
"childcontext",
"=",
"\\",
"context_user",
"::",
"instance",
"(",
"$",
"child",
"->",
"id",
")",
";",
"if",
"(",
"has_capability",
"(",
"'tool/dataprivacy:makedatarequestsforchildren'",
",",
"$",
"childcontext",
",",
"$",
"userid",
")",
")",
"{",
"$",
"finalresults",
"[",
"$",
"key",
"]",
"=",
"$",
"child",
";",
"}",
"}",
"}",
"return",
"$",
"finalresults",
";",
"}"
] |
Get the users that a user can make data request for.
E.g. User having a parent role and has the 'tool/dataprivacy:makedatarequestsforchildren' capability.
@param int $userid The user's ID.
@return array
|
[
"Get",
"the",
"users",
"that",
"a",
"user",
"can",
"make",
"data",
"request",
"for",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/local/helper.php#L186-L215
|
219,444
|
moodle/moodle
|
admin/tool/dataprivacy/classes/local/helper.php
|
helper.get_request_filter_options
|
public static function get_request_filter_options() {
$filters = [
self::FILTER_TYPE => (object)[
'name' => get_string('requesttype', 'tool_dataprivacy'),
'options' => self::get_request_types_short()
],
self::FILTER_STATUS => (object)[
'name' => get_string('requeststatus', 'tool_dataprivacy'),
'options' => self::get_request_statuses()
],
self::FILTER_CREATION => (object)[
'name' => get_string('requestcreation', 'tool_dataprivacy'),
'options' => self::get_request_creation_methods()
],
];
$options = [];
foreach ($filters as $category => $filtercategory) {
foreach ($filtercategory->options as $key => $name) {
$option = (object)[
'category' => $filtercategory->name,
'name' => $name
];
$options["{$category}:{$key}"] = get_string('filteroption', 'tool_dataprivacy', $option);
}
}
return $options;
}
|
php
|
public static function get_request_filter_options() {
$filters = [
self::FILTER_TYPE => (object)[
'name' => get_string('requesttype', 'tool_dataprivacy'),
'options' => self::get_request_types_short()
],
self::FILTER_STATUS => (object)[
'name' => get_string('requeststatus', 'tool_dataprivacy'),
'options' => self::get_request_statuses()
],
self::FILTER_CREATION => (object)[
'name' => get_string('requestcreation', 'tool_dataprivacy'),
'options' => self::get_request_creation_methods()
],
];
$options = [];
foreach ($filters as $category => $filtercategory) {
foreach ($filtercategory->options as $key => $name) {
$option = (object)[
'category' => $filtercategory->name,
'name' => $name
];
$options["{$category}:{$key}"] = get_string('filteroption', 'tool_dataprivacy', $option);
}
}
return $options;
}
|
[
"public",
"static",
"function",
"get_request_filter_options",
"(",
")",
"{",
"$",
"filters",
"=",
"[",
"self",
"::",
"FILTER_TYPE",
"=>",
"(",
"object",
")",
"[",
"'name'",
"=>",
"get_string",
"(",
"'requesttype'",
",",
"'tool_dataprivacy'",
")",
",",
"'options'",
"=>",
"self",
"::",
"get_request_types_short",
"(",
")",
"]",
",",
"self",
"::",
"FILTER_STATUS",
"=>",
"(",
"object",
")",
"[",
"'name'",
"=>",
"get_string",
"(",
"'requeststatus'",
",",
"'tool_dataprivacy'",
")",
",",
"'options'",
"=>",
"self",
"::",
"get_request_statuses",
"(",
")",
"]",
",",
"self",
"::",
"FILTER_CREATION",
"=>",
"(",
"object",
")",
"[",
"'name'",
"=>",
"get_string",
"(",
"'requestcreation'",
",",
"'tool_dataprivacy'",
")",
",",
"'options'",
"=>",
"self",
"::",
"get_request_creation_methods",
"(",
")",
"]",
",",
"]",
";",
"$",
"options",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"filters",
"as",
"$",
"category",
"=>",
"$",
"filtercategory",
")",
"{",
"foreach",
"(",
"$",
"filtercategory",
"->",
"options",
"as",
"$",
"key",
"=>",
"$",
"name",
")",
"{",
"$",
"option",
"=",
"(",
"object",
")",
"[",
"'category'",
"=>",
"$",
"filtercategory",
"->",
"name",
",",
"'name'",
"=>",
"$",
"name",
"]",
";",
"$",
"options",
"[",
"\"{$category}:{$key}\"",
"]",
"=",
"get_string",
"(",
"'filteroption'",
",",
"'tool_dataprivacy'",
",",
"$",
"option",
")",
";",
"}",
"}",
"return",
"$",
"options",
";",
"}"
] |
Get options for the data requests filter.
@return array
@throws coding_exception
|
[
"Get",
"options",
"for",
"the",
"data",
"requests",
"filter",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/local/helper.php#L223-L249
|
219,445
|
moodle/moodle
|
mod/assignment/type/offline/backup/moodle2/backup_assignment_offline_subplugin.class.php
|
backup_assignment_offline_subplugin.define_assignment_subplugin_structure
|
protected function define_assignment_subplugin_structure() {
return false; // This subplugin backup is only one example. Skip it.
/**
* Any activity sublugins is always rooted by one backup_subplugin_element()
* Those elements have some unique characteristics:
* - They are, basically, backup_nested_elements
* - They cannot have attributes
* - They don't have XML representations (only their final/child elements have
* - They are able to specify one condition in order to decide if the subplugin
* must be processed or no (usually we'll put the "type" condition here, but some
* activities, may prefer not to use any condition, see workshop)
*/
/**
* Here we are defining the information that will be attached, within the "assignment" element
* when assignments of type "offline" are sent to backup, so we define the backup_subplugin_element
* as not having any final element (null) and with the condition of the '/assignment/assignmenttype'
* being 'offline' (that will be checked on execution)
*
* Note that, while, we allow direct "injection" of final_elements at the "assignment" level (without
* any nesting, we usually pass 'null', and later enclose the real subplugin information into deeper
* levels (get_recommended_name() and 'config' in the example below). That will make things
* on restore easier, as far as subplugin information will be clearly separated from module information.
*/
$subplugin = $this->get_subplugin_element(null, '/assignment/assignmenttype', 'offline');
/**
* Here we define the real structure the subplugin is going to generate - see note above. Obviously the
* example below hasn't sense at all, we are exporting the whole config table that is 100% unrelated
* with assignments. Take it as just one example. The only important bit is that it's highly recommended to
* use some exclusive name in the main nested element (something that won't conflict with other subplugins/parts).
* So we are using 'subplugin_assignment_offline_assignment' as name here (the type of the subplugin, the name of the
* subplugin and the name of the connection point). get_recommended_name() will help, in any case ;-)
*
* All the code below is 100% standard backup structure code, so you define the structure, the sources,
* annotations... whatever you need
*/
$assassoff = new backup_nested_element($this->get_recommended_name());
$config = new backup_nested_element('config', null, array('name', 'value'));
$subplugin->add_child($assassoff);
$assassoff->add_child($config);
$config->set_source_table('config', array('id' => '/assignment/id'));
return $subplugin; // And we return the root subplugin element
}
|
php
|
protected function define_assignment_subplugin_structure() {
return false; // This subplugin backup is only one example. Skip it.
/**
* Any activity sublugins is always rooted by one backup_subplugin_element()
* Those elements have some unique characteristics:
* - They are, basically, backup_nested_elements
* - They cannot have attributes
* - They don't have XML representations (only their final/child elements have
* - They are able to specify one condition in order to decide if the subplugin
* must be processed or no (usually we'll put the "type" condition here, but some
* activities, may prefer not to use any condition, see workshop)
*/
/**
* Here we are defining the information that will be attached, within the "assignment" element
* when assignments of type "offline" are sent to backup, so we define the backup_subplugin_element
* as not having any final element (null) and with the condition of the '/assignment/assignmenttype'
* being 'offline' (that will be checked on execution)
*
* Note that, while, we allow direct "injection" of final_elements at the "assignment" level (without
* any nesting, we usually pass 'null', and later enclose the real subplugin information into deeper
* levels (get_recommended_name() and 'config' in the example below). That will make things
* on restore easier, as far as subplugin information will be clearly separated from module information.
*/
$subplugin = $this->get_subplugin_element(null, '/assignment/assignmenttype', 'offline');
/**
* Here we define the real structure the subplugin is going to generate - see note above. Obviously the
* example below hasn't sense at all, we are exporting the whole config table that is 100% unrelated
* with assignments. Take it as just one example. The only important bit is that it's highly recommended to
* use some exclusive name in the main nested element (something that won't conflict with other subplugins/parts).
* So we are using 'subplugin_assignment_offline_assignment' as name here (the type of the subplugin, the name of the
* subplugin and the name of the connection point). get_recommended_name() will help, in any case ;-)
*
* All the code below is 100% standard backup structure code, so you define the structure, the sources,
* annotations... whatever you need
*/
$assassoff = new backup_nested_element($this->get_recommended_name());
$config = new backup_nested_element('config', null, array('name', 'value'));
$subplugin->add_child($assassoff);
$assassoff->add_child($config);
$config->set_source_table('config', array('id' => '/assignment/id'));
return $subplugin; // And we return the root subplugin element
}
|
[
"protected",
"function",
"define_assignment_subplugin_structure",
"(",
")",
"{",
"return",
"false",
";",
"// This subplugin backup is only one example. Skip it.",
"/**\n * Any activity sublugins is always rooted by one backup_subplugin_element()\n * Those elements have some unique characteristics:\n * - They are, basically, backup_nested_elements\n * - They cannot have attributes\n * - They don't have XML representations (only their final/child elements have\n * - They are able to specify one condition in order to decide if the subplugin\n * must be processed or no (usually we'll put the \"type\" condition here, but some\n * activities, may prefer not to use any condition, see workshop)\n */",
"/**\n * Here we are defining the information that will be attached, within the \"assignment\" element\n * when assignments of type \"offline\" are sent to backup, so we define the backup_subplugin_element\n * as not having any final element (null) and with the condition of the '/assignment/assignmenttype'\n * being 'offline' (that will be checked on execution)\n *\n * Note that, while, we allow direct \"injection\" of final_elements at the \"assignment\" level (without\n * any nesting, we usually pass 'null', and later enclose the real subplugin information into deeper\n * levels (get_recommended_name() and 'config' in the example below). That will make things\n * on restore easier, as far as subplugin information will be clearly separated from module information.\n */",
"$",
"subplugin",
"=",
"$",
"this",
"->",
"get_subplugin_element",
"(",
"null",
",",
"'/assignment/assignmenttype'",
",",
"'offline'",
")",
";",
"/**\n * Here we define the real structure the subplugin is going to generate - see note above. Obviously the\n * example below hasn't sense at all, we are exporting the whole config table that is 100% unrelated\n * with assignments. Take it as just one example. The only important bit is that it's highly recommended to\n * use some exclusive name in the main nested element (something that won't conflict with other subplugins/parts).\n * So we are using 'subplugin_assignment_offline_assignment' as name here (the type of the subplugin, the name of the\n * subplugin and the name of the connection point). get_recommended_name() will help, in any case ;-)\n *\n * All the code below is 100% standard backup structure code, so you define the structure, the sources,\n * annotations... whatever you need\n */",
"$",
"assassoff",
"=",
"new",
"backup_nested_element",
"(",
"$",
"this",
"->",
"get_recommended_name",
"(",
")",
")",
";",
"$",
"config",
"=",
"new",
"backup_nested_element",
"(",
"'config'",
",",
"null",
",",
"array",
"(",
"'name'",
",",
"'value'",
")",
")",
";",
"$",
"subplugin",
"->",
"add_child",
"(",
"$",
"assassoff",
")",
";",
"$",
"assassoff",
"->",
"add_child",
"(",
"$",
"config",
")",
";",
"$",
"config",
"->",
"set_source_table",
"(",
"'config'",
",",
"array",
"(",
"'id'",
"=>",
"'/assignment/id'",
")",
")",
";",
"return",
"$",
"subplugin",
";",
"// And we return the root subplugin element",
"}"
] |
Returns the subplugin information to attach at assignment element
|
[
"Returns",
"the",
"subplugin",
"information",
"to",
"attach",
"at",
"assignment",
"element"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assignment/type/offline/backup/moodle2/backup_assignment_offline_subplugin.class.php#L39-L87
|
219,446
|
moodle/moodle
|
mod/assignment/type/offline/backup/moodle2/backup_assignment_offline_subplugin.class.php
|
backup_assignment_offline_subplugin.define_submission_subplugin_structure
|
protected function define_submission_subplugin_structure() {
return false; // This subplugin backup is only one example. Skip it.
// remember this has not XML representation
$subplugin = $this->get_subplugin_element(null, '/assignment/assignmenttype', 'offline');
// type of the subplugin, name of the subplugin and name of the connection point (recommended)
$asssuboff = new backup_nested_element($this->get_recommended_name());
// Why 'submission_config' name? Because it must be unique in the hierarchy and we
// already are using 'config' above withing the same file
$config = new backup_nested_element('submission_config', null, array('name', 'value'));
$subplugin->add_child($asssuboff);
$asssuboff->add_child($config);
$config->set_source_table('config', array('id' => backup::VAR_PARENTID));
return $subplugin; // And we return the root subplugin element
}
|
php
|
protected function define_submission_subplugin_structure() {
return false; // This subplugin backup is only one example. Skip it.
// remember this has not XML representation
$subplugin = $this->get_subplugin_element(null, '/assignment/assignmenttype', 'offline');
// type of the subplugin, name of the subplugin and name of the connection point (recommended)
$asssuboff = new backup_nested_element($this->get_recommended_name());
// Why 'submission_config' name? Because it must be unique in the hierarchy and we
// already are using 'config' above withing the same file
$config = new backup_nested_element('submission_config', null, array('name', 'value'));
$subplugin->add_child($asssuboff);
$asssuboff->add_child($config);
$config->set_source_table('config', array('id' => backup::VAR_PARENTID));
return $subplugin; // And we return the root subplugin element
}
|
[
"protected",
"function",
"define_submission_subplugin_structure",
"(",
")",
"{",
"return",
"false",
";",
"// This subplugin backup is only one example. Skip it.",
"// remember this has not XML representation",
"$",
"subplugin",
"=",
"$",
"this",
"->",
"get_subplugin_element",
"(",
"null",
",",
"'/assignment/assignmenttype'",
",",
"'offline'",
")",
";",
"// type of the subplugin, name of the subplugin and name of the connection point (recommended)",
"$",
"asssuboff",
"=",
"new",
"backup_nested_element",
"(",
"$",
"this",
"->",
"get_recommended_name",
"(",
")",
")",
";",
"// Why 'submission_config' name? Because it must be unique in the hierarchy and we",
"// already are using 'config' above withing the same file",
"$",
"config",
"=",
"new",
"backup_nested_element",
"(",
"'submission_config'",
",",
"null",
",",
"array",
"(",
"'name'",
",",
"'value'",
")",
")",
";",
"$",
"subplugin",
"->",
"add_child",
"(",
"$",
"asssuboff",
")",
";",
"$",
"asssuboff",
"->",
"add_child",
"(",
"$",
"config",
")",
";",
"$",
"config",
"->",
"set_source_table",
"(",
"'config'",
",",
"array",
"(",
"'id'",
"=>",
"backup",
"::",
"VAR_PARENTID",
")",
")",
";",
"return",
"$",
"subplugin",
";",
"// And we return the root subplugin element",
"}"
] |
Returns the subplugin information to attach at submission element
|
[
"Returns",
"the",
"subplugin",
"information",
"to",
"attach",
"at",
"submission",
"element"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assignment/type/offline/backup/moodle2/backup_assignment_offline_subplugin.class.php#L92-L111
|
219,447
|
moodle/moodle
|
grade/report/singleview/classes/local/ui/text_attribute.php
|
text_attribute.html
|
public function html() {
global $OUTPUT;
$context = (object) [
'id' => $this->name,
'name' => $this->name,
'value' => $this->value,
'disabled' => $this->isdisabled,
];
$context->label = '';
if (preg_match("/^feedback/", $this->name)) {
$context->label = get_string('feedbackfor', 'gradereport_singleview', $this->label);
$context->tabindex = '2';
} else if (preg_match("/^finalgrade/", $this->name)) {
$context->label = get_string('gradefor', 'gradereport_singleview', $this->label);
$context->tabindex = '1';
}
return $OUTPUT->render_from_template('gradereport_singleview/text_attribute', $context);
}
|
php
|
public function html() {
global $OUTPUT;
$context = (object) [
'id' => $this->name,
'name' => $this->name,
'value' => $this->value,
'disabled' => $this->isdisabled,
];
$context->label = '';
if (preg_match("/^feedback/", $this->name)) {
$context->label = get_string('feedbackfor', 'gradereport_singleview', $this->label);
$context->tabindex = '2';
} else if (preg_match("/^finalgrade/", $this->name)) {
$context->label = get_string('gradefor', 'gradereport_singleview', $this->label);
$context->tabindex = '1';
}
return $OUTPUT->render_from_template('gradereport_singleview/text_attribute', $context);
}
|
[
"public",
"function",
"html",
"(",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"$",
"context",
"=",
"(",
"object",
")",
"[",
"'id'",
"=>",
"$",
"this",
"->",
"name",
",",
"'name'",
"=>",
"$",
"this",
"->",
"name",
",",
"'value'",
"=>",
"$",
"this",
"->",
"value",
",",
"'disabled'",
"=>",
"$",
"this",
"->",
"isdisabled",
",",
"]",
";",
"$",
"context",
"->",
"label",
"=",
"''",
";",
"if",
"(",
"preg_match",
"(",
"\"/^feedback/\"",
",",
"$",
"this",
"->",
"name",
")",
")",
"{",
"$",
"context",
"->",
"label",
"=",
"get_string",
"(",
"'feedbackfor'",
",",
"'gradereport_singleview'",
",",
"$",
"this",
"->",
"label",
")",
";",
"$",
"context",
"->",
"tabindex",
"=",
"'2'",
";",
"}",
"else",
"if",
"(",
"preg_match",
"(",
"\"/^finalgrade/\"",
",",
"$",
"this",
"->",
"name",
")",
")",
"{",
"$",
"context",
"->",
"label",
"=",
"get_string",
"(",
"'gradefor'",
",",
"'gradereport_singleview'",
",",
"$",
"this",
"->",
"label",
")",
";",
"$",
"context",
"->",
"tabindex",
"=",
"'1'",
";",
"}",
"return",
"$",
"OUTPUT",
"->",
"render_from_template",
"(",
"'gradereport_singleview/text_attribute'",
",",
"$",
"context",
")",
";",
"}"
] |
Render the html for this field.
@return string The HTML.
|
[
"Render",
"the",
"html",
"for",
"this",
"field",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/ui/text_attribute.php#L67-L87
|
219,448
|
moodle/moodle
|
cohort/externallib.php
|
core_cohort_external.create_cohorts
|
public static function create_cohorts($cohorts) {
global $CFG, $DB;
require_once("$CFG->dirroot/cohort/lib.php");
$params = self::validate_parameters(self::create_cohorts_parameters(), array('cohorts' => $cohorts));
$availablethemes = cohort_get_list_of_themes();
$transaction = $DB->start_delegated_transaction();
$syscontext = context_system::instance();
$cohortids = array();
foreach ($params['cohorts'] as $cohort) {
$cohort = (object)$cohort;
// Category type (context id).
$categorytype = $cohort->categorytype;
if (!in_array($categorytype['type'], array('idnumber', 'id', 'system'))) {
throw new invalid_parameter_exception('category type must be id, idnumber or system:' . $categorytype['type']);
}
if ($categorytype['type'] === 'system') {
$cohort->contextid = $syscontext->id;
} else if ($catid = $DB->get_field('course_categories', 'id', array($categorytype['type'] => $categorytype['value']))) {
$catcontext = context_coursecat::instance($catid);
$cohort->contextid = $catcontext->id;
} else {
throw new invalid_parameter_exception('category not exists: category '
.$categorytype['type'].' = '.$categorytype['value']);
}
// Make sure that the idnumber doesn't already exist.
if ($DB->record_exists('cohort', array('idnumber' => $cohort->idnumber))) {
throw new invalid_parameter_exception('record already exists: idnumber='.$cohort->idnumber);
}
$context = context::instance_by_id($cohort->contextid, MUST_EXIST);
if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) {
throw new invalid_parameter_exception('Invalid context');
}
self::validate_context($context);
require_capability('moodle/cohort:manage', $context);
// Make sure theme is valid.
if (isset($cohort->theme)) {
if (!empty($CFG->allowcohortthemes)) {
if (empty($availablethemes[$cohort->theme])) {
throw new moodle_exception('errorinvalidparam', 'webservice', '', 'theme');
}
}
}
// Validate format.
$cohort->descriptionformat = external_validate_format($cohort->descriptionformat);
$cohort->id = cohort_add_cohort($cohort);
list($cohort->description, $cohort->descriptionformat) =
external_format_text($cohort->description, $cohort->descriptionformat,
$context->id, 'cohort', 'description', $cohort->id);
$cohortids[] = (array)$cohort;
}
$transaction->allow_commit();
return $cohortids;
}
|
php
|
public static function create_cohorts($cohorts) {
global $CFG, $DB;
require_once("$CFG->dirroot/cohort/lib.php");
$params = self::validate_parameters(self::create_cohorts_parameters(), array('cohorts' => $cohorts));
$availablethemes = cohort_get_list_of_themes();
$transaction = $DB->start_delegated_transaction();
$syscontext = context_system::instance();
$cohortids = array();
foreach ($params['cohorts'] as $cohort) {
$cohort = (object)$cohort;
// Category type (context id).
$categorytype = $cohort->categorytype;
if (!in_array($categorytype['type'], array('idnumber', 'id', 'system'))) {
throw new invalid_parameter_exception('category type must be id, idnumber or system:' . $categorytype['type']);
}
if ($categorytype['type'] === 'system') {
$cohort->contextid = $syscontext->id;
} else if ($catid = $DB->get_field('course_categories', 'id', array($categorytype['type'] => $categorytype['value']))) {
$catcontext = context_coursecat::instance($catid);
$cohort->contextid = $catcontext->id;
} else {
throw new invalid_parameter_exception('category not exists: category '
.$categorytype['type'].' = '.$categorytype['value']);
}
// Make sure that the idnumber doesn't already exist.
if ($DB->record_exists('cohort', array('idnumber' => $cohort->idnumber))) {
throw new invalid_parameter_exception('record already exists: idnumber='.$cohort->idnumber);
}
$context = context::instance_by_id($cohort->contextid, MUST_EXIST);
if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) {
throw new invalid_parameter_exception('Invalid context');
}
self::validate_context($context);
require_capability('moodle/cohort:manage', $context);
// Make sure theme is valid.
if (isset($cohort->theme)) {
if (!empty($CFG->allowcohortthemes)) {
if (empty($availablethemes[$cohort->theme])) {
throw new moodle_exception('errorinvalidparam', 'webservice', '', 'theme');
}
}
}
// Validate format.
$cohort->descriptionformat = external_validate_format($cohort->descriptionformat);
$cohort->id = cohort_add_cohort($cohort);
list($cohort->description, $cohort->descriptionformat) =
external_format_text($cohort->description, $cohort->descriptionformat,
$context->id, 'cohort', 'description', $cohort->id);
$cohortids[] = (array)$cohort;
}
$transaction->allow_commit();
return $cohortids;
}
|
[
"public",
"static",
"function",
"create_cohorts",
"(",
"$",
"cohorts",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
";",
"require_once",
"(",
"\"$CFG->dirroot/cohort/lib.php\"",
")",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"create_cohorts_parameters",
"(",
")",
",",
"array",
"(",
"'cohorts'",
"=>",
"$",
"cohorts",
")",
")",
";",
"$",
"availablethemes",
"=",
"cohort_get_list_of_themes",
"(",
")",
";",
"$",
"transaction",
"=",
"$",
"DB",
"->",
"start_delegated_transaction",
"(",
")",
";",
"$",
"syscontext",
"=",
"context_system",
"::",
"instance",
"(",
")",
";",
"$",
"cohortids",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"params",
"[",
"'cohorts'",
"]",
"as",
"$",
"cohort",
")",
"{",
"$",
"cohort",
"=",
"(",
"object",
")",
"$",
"cohort",
";",
"// Category type (context id).",
"$",
"categorytype",
"=",
"$",
"cohort",
"->",
"categorytype",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"categorytype",
"[",
"'type'",
"]",
",",
"array",
"(",
"'idnumber'",
",",
"'id'",
",",
"'system'",
")",
")",
")",
"{",
"throw",
"new",
"invalid_parameter_exception",
"(",
"'category type must be id, idnumber or system:'",
".",
"$",
"categorytype",
"[",
"'type'",
"]",
")",
";",
"}",
"if",
"(",
"$",
"categorytype",
"[",
"'type'",
"]",
"===",
"'system'",
")",
"{",
"$",
"cohort",
"->",
"contextid",
"=",
"$",
"syscontext",
"->",
"id",
";",
"}",
"else",
"if",
"(",
"$",
"catid",
"=",
"$",
"DB",
"->",
"get_field",
"(",
"'course_categories'",
",",
"'id'",
",",
"array",
"(",
"$",
"categorytype",
"[",
"'type'",
"]",
"=>",
"$",
"categorytype",
"[",
"'value'",
"]",
")",
")",
")",
"{",
"$",
"catcontext",
"=",
"context_coursecat",
"::",
"instance",
"(",
"$",
"catid",
")",
";",
"$",
"cohort",
"->",
"contextid",
"=",
"$",
"catcontext",
"->",
"id",
";",
"}",
"else",
"{",
"throw",
"new",
"invalid_parameter_exception",
"(",
"'category not exists: category '",
".",
"$",
"categorytype",
"[",
"'type'",
"]",
".",
"' = '",
".",
"$",
"categorytype",
"[",
"'value'",
"]",
")",
";",
"}",
"// Make sure that the idnumber doesn't already exist.",
"if",
"(",
"$",
"DB",
"->",
"record_exists",
"(",
"'cohort'",
",",
"array",
"(",
"'idnumber'",
"=>",
"$",
"cohort",
"->",
"idnumber",
")",
")",
")",
"{",
"throw",
"new",
"invalid_parameter_exception",
"(",
"'record already exists: idnumber='",
".",
"$",
"cohort",
"->",
"idnumber",
")",
";",
"}",
"$",
"context",
"=",
"context",
"::",
"instance_by_id",
"(",
"$",
"cohort",
"->",
"contextid",
",",
"MUST_EXIST",
")",
";",
"if",
"(",
"$",
"context",
"->",
"contextlevel",
"!=",
"CONTEXT_COURSECAT",
"and",
"$",
"context",
"->",
"contextlevel",
"!=",
"CONTEXT_SYSTEM",
")",
"{",
"throw",
"new",
"invalid_parameter_exception",
"(",
"'Invalid context'",
")",
";",
"}",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"require_capability",
"(",
"'moodle/cohort:manage'",
",",
"$",
"context",
")",
";",
"// Make sure theme is valid.",
"if",
"(",
"isset",
"(",
"$",
"cohort",
"->",
"theme",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"CFG",
"->",
"allowcohortthemes",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"availablethemes",
"[",
"$",
"cohort",
"->",
"theme",
"]",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'errorinvalidparam'",
",",
"'webservice'",
",",
"''",
",",
"'theme'",
")",
";",
"}",
"}",
"}",
"// Validate format.",
"$",
"cohort",
"->",
"descriptionformat",
"=",
"external_validate_format",
"(",
"$",
"cohort",
"->",
"descriptionformat",
")",
";",
"$",
"cohort",
"->",
"id",
"=",
"cohort_add_cohort",
"(",
"$",
"cohort",
")",
";",
"list",
"(",
"$",
"cohort",
"->",
"description",
",",
"$",
"cohort",
"->",
"descriptionformat",
")",
"=",
"external_format_text",
"(",
"$",
"cohort",
"->",
"description",
",",
"$",
"cohort",
"->",
"descriptionformat",
",",
"$",
"context",
"->",
"id",
",",
"'cohort'",
",",
"'description'",
",",
"$",
"cohort",
"->",
"id",
")",
";",
"$",
"cohortids",
"[",
"]",
"=",
"(",
"array",
")",
"$",
"cohort",
";",
"}",
"$",
"transaction",
"->",
"allow_commit",
"(",
")",
";",
"return",
"$",
"cohortids",
";",
"}"
] |
Create one or more cohorts
@param array $cohorts An array of cohorts to create.
@return array An array of arrays
@since Moodle 2.5
|
[
"Create",
"one",
"or",
"more",
"cohorts"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cohort/externallib.php#L75-L137
|
219,449
|
moodle/moodle
|
cohort/externallib.php
|
core_cohort_external.get_cohorts
|
public static function get_cohorts($cohortids = array()) {
global $DB, $CFG;
$params = self::validate_parameters(self::get_cohorts_parameters(), array('cohortids' => $cohortids));
if (empty($cohortids)) {
$cohorts = $DB->get_records('cohort');
} else {
$cohorts = $DB->get_records_list('cohort', 'id', $params['cohortids']);
}
$cohortsinfo = array();
foreach ($cohorts as $cohort) {
// Now security checks.
$context = context::instance_by_id($cohort->contextid, MUST_EXIST);
if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) {
throw new invalid_parameter_exception('Invalid context');
}
self::validate_context($context);
if (!has_any_capability(array('moodle/cohort:manage', 'moodle/cohort:view'), $context)) {
throw new required_capability_exception($context, 'moodle/cohort:view', 'nopermissions', '');
}
// Only return theme when $CFG->allowcohortthemes is enabled.
if (!empty($cohort->theme) && empty($CFG->allowcohortthemes)) {
$cohort->theme = null;
}
list($cohort->description, $cohort->descriptionformat) =
external_format_text($cohort->description, $cohort->descriptionformat,
$context->id, 'cohort', 'description', $cohort->id);
$cohortsinfo[] = (array) $cohort;
}
return $cohortsinfo;
}
|
php
|
public static function get_cohorts($cohortids = array()) {
global $DB, $CFG;
$params = self::validate_parameters(self::get_cohorts_parameters(), array('cohortids' => $cohortids));
if (empty($cohortids)) {
$cohorts = $DB->get_records('cohort');
} else {
$cohorts = $DB->get_records_list('cohort', 'id', $params['cohortids']);
}
$cohortsinfo = array();
foreach ($cohorts as $cohort) {
// Now security checks.
$context = context::instance_by_id($cohort->contextid, MUST_EXIST);
if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) {
throw new invalid_parameter_exception('Invalid context');
}
self::validate_context($context);
if (!has_any_capability(array('moodle/cohort:manage', 'moodle/cohort:view'), $context)) {
throw new required_capability_exception($context, 'moodle/cohort:view', 'nopermissions', '');
}
// Only return theme when $CFG->allowcohortthemes is enabled.
if (!empty($cohort->theme) && empty($CFG->allowcohortthemes)) {
$cohort->theme = null;
}
list($cohort->description, $cohort->descriptionformat) =
external_format_text($cohort->description, $cohort->descriptionformat,
$context->id, 'cohort', 'description', $cohort->id);
$cohortsinfo[] = (array) $cohort;
}
return $cohortsinfo;
}
|
[
"public",
"static",
"function",
"get_cohorts",
"(",
"$",
"cohortids",
"=",
"array",
"(",
")",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"CFG",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_cohorts_parameters",
"(",
")",
",",
"array",
"(",
"'cohortids'",
"=>",
"$",
"cohortids",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"cohortids",
")",
")",
"{",
"$",
"cohorts",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'cohort'",
")",
";",
"}",
"else",
"{",
"$",
"cohorts",
"=",
"$",
"DB",
"->",
"get_records_list",
"(",
"'cohort'",
",",
"'id'",
",",
"$",
"params",
"[",
"'cohortids'",
"]",
")",
";",
"}",
"$",
"cohortsinfo",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"cohorts",
"as",
"$",
"cohort",
")",
"{",
"// Now security checks.",
"$",
"context",
"=",
"context",
"::",
"instance_by_id",
"(",
"$",
"cohort",
"->",
"contextid",
",",
"MUST_EXIST",
")",
";",
"if",
"(",
"$",
"context",
"->",
"contextlevel",
"!=",
"CONTEXT_COURSECAT",
"and",
"$",
"context",
"->",
"contextlevel",
"!=",
"CONTEXT_SYSTEM",
")",
"{",
"throw",
"new",
"invalid_parameter_exception",
"(",
"'Invalid context'",
")",
";",
"}",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"if",
"(",
"!",
"has_any_capability",
"(",
"array",
"(",
"'moodle/cohort:manage'",
",",
"'moodle/cohort:view'",
")",
",",
"$",
"context",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/cohort:view'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"// Only return theme when $CFG->allowcohortthemes is enabled.",
"if",
"(",
"!",
"empty",
"(",
"$",
"cohort",
"->",
"theme",
")",
"&&",
"empty",
"(",
"$",
"CFG",
"->",
"allowcohortthemes",
")",
")",
"{",
"$",
"cohort",
"->",
"theme",
"=",
"null",
";",
"}",
"list",
"(",
"$",
"cohort",
"->",
"description",
",",
"$",
"cohort",
"->",
"descriptionformat",
")",
"=",
"external_format_text",
"(",
"$",
"cohort",
"->",
"description",
",",
"$",
"cohort",
"->",
"descriptionformat",
",",
"$",
"context",
"->",
"id",
",",
"'cohort'",
",",
"'description'",
",",
"$",
"cohort",
"->",
"id",
")",
";",
"$",
"cohortsinfo",
"[",
"]",
"=",
"(",
"array",
")",
"$",
"cohort",
";",
"}",
"return",
"$",
"cohortsinfo",
";",
"}"
] |
Get cohorts definition specified by ids
@param array $cohortids array of cohort ids
@return array of cohort objects (id, courseid, name)
@since Moodle 2.5
|
[
"Get",
"cohorts",
"definition",
"specified",
"by",
"ids"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cohort/externallib.php#L241-L276
|
219,450
|
moodle/moodle
|
cohort/externallib.php
|
core_cohort_external.search_cohorts
|
public static function search_cohorts($query, $context, $includes = 'parents', $limitfrom = 0, $limitnum = 25) {
global $CFG;
require_once($CFG->dirroot . '/cohort/lib.php');
$params = self::validate_parameters(self::search_cohorts_parameters(), array(
'query' => $query,
'context' => $context,
'includes' => $includes,
'limitfrom' => $limitfrom,
'limitnum' => $limitnum,
));
$query = $params['query'];
$includes = $params['includes'];
$context = self::get_context_from_params($params['context']);
$limitfrom = $params['limitfrom'];
$limitnum = $params['limitnum'];
self::validate_context($context);
$manager = has_capability('moodle/cohort:manage', $context);
if (!$manager) {
require_capability('moodle/cohort:view', $context);
}
// TODO Make this more efficient.
if ($includes == 'self') {
$results = cohort_get_cohorts($context->id, $limitfrom, $limitnum, $query);
$results = $results['cohorts'];
} else if ($includes == 'parents') {
$results = cohort_get_cohorts($context->id, $limitfrom, $limitnum, $query);
$results = $results['cohorts'];
if (!$context instanceof context_system) {
$results = array_merge($results, cohort_get_available_cohorts($context, COHORT_ALL, $limitfrom, $limitnum, $query));
}
} else if ($includes == 'all') {
$results = cohort_get_all_cohorts($limitfrom, $limitnum, $query);
$results = $results['cohorts'];
} else {
throw new coding_exception('Invalid parameter value for \'includes\'.');
}
$cohorts = array();
foreach ($results as $key => $cohort) {
$cohortcontext = context::instance_by_id($cohort->contextid);
// Only return theme when $CFG->allowcohortthemes is enabled.
if (!empty($cohort->theme) && empty($CFG->allowcohortthemes)) {
$cohort->theme = null;
}
if (!isset($cohort->description)) {
$cohort->description = '';
}
if (!isset($cohort->descriptionformat)) {
$cohort->descriptionformat = FORMAT_PLAIN;
}
list($cohort->description, $cohort->descriptionformat) =
external_format_text($cohort->description, $cohort->descriptionformat,
$cohortcontext->id, 'cohort', 'description', $cohort->id);
$cohorts[$key] = $cohort;
}
return array('cohorts' => $cohorts);
}
|
php
|
public static function search_cohorts($query, $context, $includes = 'parents', $limitfrom = 0, $limitnum = 25) {
global $CFG;
require_once($CFG->dirroot . '/cohort/lib.php');
$params = self::validate_parameters(self::search_cohorts_parameters(), array(
'query' => $query,
'context' => $context,
'includes' => $includes,
'limitfrom' => $limitfrom,
'limitnum' => $limitnum,
));
$query = $params['query'];
$includes = $params['includes'];
$context = self::get_context_from_params($params['context']);
$limitfrom = $params['limitfrom'];
$limitnum = $params['limitnum'];
self::validate_context($context);
$manager = has_capability('moodle/cohort:manage', $context);
if (!$manager) {
require_capability('moodle/cohort:view', $context);
}
// TODO Make this more efficient.
if ($includes == 'self') {
$results = cohort_get_cohorts($context->id, $limitfrom, $limitnum, $query);
$results = $results['cohorts'];
} else if ($includes == 'parents') {
$results = cohort_get_cohorts($context->id, $limitfrom, $limitnum, $query);
$results = $results['cohorts'];
if (!$context instanceof context_system) {
$results = array_merge($results, cohort_get_available_cohorts($context, COHORT_ALL, $limitfrom, $limitnum, $query));
}
} else if ($includes == 'all') {
$results = cohort_get_all_cohorts($limitfrom, $limitnum, $query);
$results = $results['cohorts'];
} else {
throw new coding_exception('Invalid parameter value for \'includes\'.');
}
$cohorts = array();
foreach ($results as $key => $cohort) {
$cohortcontext = context::instance_by_id($cohort->contextid);
// Only return theme when $CFG->allowcohortthemes is enabled.
if (!empty($cohort->theme) && empty($CFG->allowcohortthemes)) {
$cohort->theme = null;
}
if (!isset($cohort->description)) {
$cohort->description = '';
}
if (!isset($cohort->descriptionformat)) {
$cohort->descriptionformat = FORMAT_PLAIN;
}
list($cohort->description, $cohort->descriptionformat) =
external_format_text($cohort->description, $cohort->descriptionformat,
$cohortcontext->id, 'cohort', 'description', $cohort->id);
$cohorts[$key] = $cohort;
}
return array('cohorts' => $cohorts);
}
|
[
"public",
"static",
"function",
"search_cohorts",
"(",
"$",
"query",
",",
"$",
"context",
",",
"$",
"includes",
"=",
"'parents'",
",",
"$",
"limitfrom",
"=",
"0",
",",
"$",
"limitnum",
"=",
"25",
")",
"{",
"global",
"$",
"CFG",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/cohort/lib.php'",
")",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"search_cohorts_parameters",
"(",
")",
",",
"array",
"(",
"'query'",
"=>",
"$",
"query",
",",
"'context'",
"=>",
"$",
"context",
",",
"'includes'",
"=>",
"$",
"includes",
",",
"'limitfrom'",
"=>",
"$",
"limitfrom",
",",
"'limitnum'",
"=>",
"$",
"limitnum",
",",
")",
")",
";",
"$",
"query",
"=",
"$",
"params",
"[",
"'query'",
"]",
";",
"$",
"includes",
"=",
"$",
"params",
"[",
"'includes'",
"]",
";",
"$",
"context",
"=",
"self",
"::",
"get_context_from_params",
"(",
"$",
"params",
"[",
"'context'",
"]",
")",
";",
"$",
"limitfrom",
"=",
"$",
"params",
"[",
"'limitfrom'",
"]",
";",
"$",
"limitnum",
"=",
"$",
"params",
"[",
"'limitnum'",
"]",
";",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"$",
"manager",
"=",
"has_capability",
"(",
"'moodle/cohort:manage'",
",",
"$",
"context",
")",
";",
"if",
"(",
"!",
"$",
"manager",
")",
"{",
"require_capability",
"(",
"'moodle/cohort:view'",
",",
"$",
"context",
")",
";",
"}",
"// TODO Make this more efficient.",
"if",
"(",
"$",
"includes",
"==",
"'self'",
")",
"{",
"$",
"results",
"=",
"cohort_get_cohorts",
"(",
"$",
"context",
"->",
"id",
",",
"$",
"limitfrom",
",",
"$",
"limitnum",
",",
"$",
"query",
")",
";",
"$",
"results",
"=",
"$",
"results",
"[",
"'cohorts'",
"]",
";",
"}",
"else",
"if",
"(",
"$",
"includes",
"==",
"'parents'",
")",
"{",
"$",
"results",
"=",
"cohort_get_cohorts",
"(",
"$",
"context",
"->",
"id",
",",
"$",
"limitfrom",
",",
"$",
"limitnum",
",",
"$",
"query",
")",
";",
"$",
"results",
"=",
"$",
"results",
"[",
"'cohorts'",
"]",
";",
"if",
"(",
"!",
"$",
"context",
"instanceof",
"context_system",
")",
"{",
"$",
"results",
"=",
"array_merge",
"(",
"$",
"results",
",",
"cohort_get_available_cohorts",
"(",
"$",
"context",
",",
"COHORT_ALL",
",",
"$",
"limitfrom",
",",
"$",
"limitnum",
",",
"$",
"query",
")",
")",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"includes",
"==",
"'all'",
")",
"{",
"$",
"results",
"=",
"cohort_get_all_cohorts",
"(",
"$",
"limitfrom",
",",
"$",
"limitnum",
",",
"$",
"query",
")",
";",
"$",
"results",
"=",
"$",
"results",
"[",
"'cohorts'",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Invalid parameter value for \\'includes\\'.'",
")",
";",
"}",
"$",
"cohorts",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"results",
"as",
"$",
"key",
"=>",
"$",
"cohort",
")",
"{",
"$",
"cohortcontext",
"=",
"context",
"::",
"instance_by_id",
"(",
"$",
"cohort",
"->",
"contextid",
")",
";",
"// Only return theme when $CFG->allowcohortthemes is enabled.",
"if",
"(",
"!",
"empty",
"(",
"$",
"cohort",
"->",
"theme",
")",
"&&",
"empty",
"(",
"$",
"CFG",
"->",
"allowcohortthemes",
")",
")",
"{",
"$",
"cohort",
"->",
"theme",
"=",
"null",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"cohort",
"->",
"description",
")",
")",
"{",
"$",
"cohort",
"->",
"description",
"=",
"''",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"cohort",
"->",
"descriptionformat",
")",
")",
"{",
"$",
"cohort",
"->",
"descriptionformat",
"=",
"FORMAT_PLAIN",
";",
"}",
"list",
"(",
"$",
"cohort",
"->",
"description",
",",
"$",
"cohort",
"->",
"descriptionformat",
")",
"=",
"external_format_text",
"(",
"$",
"cohort",
"->",
"description",
",",
"$",
"cohort",
"->",
"descriptionformat",
",",
"$",
"cohortcontext",
"->",
"id",
",",
"'cohort'",
",",
"'description'",
",",
"$",
"cohort",
"->",
"id",
")",
";",
"$",
"cohorts",
"[",
"$",
"key",
"]",
"=",
"$",
"cohort",
";",
"}",
"return",
"array",
"(",
"'cohorts'",
"=>",
"$",
"cohorts",
")",
";",
"}"
] |
Search cohorts.
@param string $query
@param array $context
@param string $includes
@param int $limitfrom
@param int $limitnum
@return array
|
[
"Search",
"cohorts",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cohort/externallib.php#L348-L413
|
219,451
|
moodle/moodle
|
cohort/externallib.php
|
core_cohort_external.delete_cohort_members
|
public static function delete_cohort_members($members) {
global $CFG, $DB;
require_once("$CFG->dirroot/cohort/lib.php");
// Validate parameters.
$params = self::validate_parameters(self::delete_cohort_members_parameters(), array('members' => $members));
$transaction = $DB->start_delegated_transaction();
foreach ($params['members'] as $member) {
$cohortid = $member['cohortid'];
$userid = $member['userid'];
$cohort = $DB->get_record('cohort', array('id' => $cohortid), '*', MUST_EXIST);
$user = $DB->get_record('user', array('id' => $userid, 'deleted' => 0, 'mnethostid' => $CFG->mnet_localhost_id),
'*', MUST_EXIST);
// Now security checks.
$context = context::instance_by_id($cohort->contextid, MUST_EXIST);
if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) {
throw new invalid_parameter_exception('Invalid context');
}
self::validate_context($context);
if (!has_any_capability(array('moodle/cohort:manage', 'moodle/cohort:assign'), $context)) {
throw new required_capability_exception($context, 'moodle/cohort:assign', 'nopermissions', '');
}
cohort_remove_member($cohort->id, $user->id);
}
$transaction->allow_commit();
}
|
php
|
public static function delete_cohort_members($members) {
global $CFG, $DB;
require_once("$CFG->dirroot/cohort/lib.php");
// Validate parameters.
$params = self::validate_parameters(self::delete_cohort_members_parameters(), array('members' => $members));
$transaction = $DB->start_delegated_transaction();
foreach ($params['members'] as $member) {
$cohortid = $member['cohortid'];
$userid = $member['userid'];
$cohort = $DB->get_record('cohort', array('id' => $cohortid), '*', MUST_EXIST);
$user = $DB->get_record('user', array('id' => $userid, 'deleted' => 0, 'mnethostid' => $CFG->mnet_localhost_id),
'*', MUST_EXIST);
// Now security checks.
$context = context::instance_by_id($cohort->contextid, MUST_EXIST);
if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) {
throw new invalid_parameter_exception('Invalid context');
}
self::validate_context($context);
if (!has_any_capability(array('moodle/cohort:manage', 'moodle/cohort:assign'), $context)) {
throw new required_capability_exception($context, 'moodle/cohort:assign', 'nopermissions', '');
}
cohort_remove_member($cohort->id, $user->id);
}
$transaction->allow_commit();
}
|
[
"public",
"static",
"function",
"delete_cohort_members",
"(",
"$",
"members",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
";",
"require_once",
"(",
"\"$CFG->dirroot/cohort/lib.php\"",
")",
";",
"// Validate parameters.",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"delete_cohort_members_parameters",
"(",
")",
",",
"array",
"(",
"'members'",
"=>",
"$",
"members",
")",
")",
";",
"$",
"transaction",
"=",
"$",
"DB",
"->",
"start_delegated_transaction",
"(",
")",
";",
"foreach",
"(",
"$",
"params",
"[",
"'members'",
"]",
"as",
"$",
"member",
")",
"{",
"$",
"cohortid",
"=",
"$",
"member",
"[",
"'cohortid'",
"]",
";",
"$",
"userid",
"=",
"$",
"member",
"[",
"'userid'",
"]",
";",
"$",
"cohort",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'cohort'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"cohortid",
")",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"$",
"user",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'user'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"userid",
",",
"'deleted'",
"=>",
"0",
",",
"'mnethostid'",
"=>",
"$",
"CFG",
"->",
"mnet_localhost_id",
")",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"// Now security checks.",
"$",
"context",
"=",
"context",
"::",
"instance_by_id",
"(",
"$",
"cohort",
"->",
"contextid",
",",
"MUST_EXIST",
")",
";",
"if",
"(",
"$",
"context",
"->",
"contextlevel",
"!=",
"CONTEXT_COURSECAT",
"and",
"$",
"context",
"->",
"contextlevel",
"!=",
"CONTEXT_SYSTEM",
")",
"{",
"throw",
"new",
"invalid_parameter_exception",
"(",
"'Invalid context'",
")",
";",
"}",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"if",
"(",
"!",
"has_any_capability",
"(",
"array",
"(",
"'moodle/cohort:manage'",
",",
"'moodle/cohort:assign'",
")",
",",
"$",
"context",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/cohort:assign'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"cohort_remove_member",
"(",
"$",
"cohort",
"->",
"id",
",",
"$",
"user",
"->",
"id",
")",
";",
"}",
"$",
"transaction",
"->",
"allow_commit",
"(",
")",
";",
"}"
] |
Delete cohort members
@param array $members of arrays with keys userid, cohortid
@since Moodle 2.5
|
[
"Delete",
"cohort",
"members"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cohort/externallib.php#L718-L748
|
219,452
|
moodle/moodle
|
cohort/externallib.php
|
core_cohort_external.get_cohort_members
|
public static function get_cohort_members($cohortids) {
global $DB;
$params = self::validate_parameters(self::get_cohort_members_parameters(), array('cohortids' => $cohortids));
$members = array();
foreach ($params['cohortids'] as $cohortid) {
// Validate params.
$cohort = $DB->get_record('cohort', array('id' => $cohortid), '*', MUST_EXIST);
// Now security checks.
$context = context::instance_by_id($cohort->contextid, MUST_EXIST);
if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) {
throw new invalid_parameter_exception('Invalid context');
}
self::validate_context($context);
if (!has_any_capability(array('moodle/cohort:manage', 'moodle/cohort:view'), $context)) {
throw new required_capability_exception($context, 'moodle/cohort:view', 'nopermissions', '');
}
$cohortmembers = $DB->get_records_sql("SELECT u.id FROM {user} u, {cohort_members} cm
WHERE u.id = cm.userid AND cm.cohortid = ?
ORDER BY lastname ASC, firstname ASC", array($cohort->id));
$members[] = array('cohortid' => $cohortid, 'userids' => array_keys($cohortmembers));
}
return $members;
}
|
php
|
public static function get_cohort_members($cohortids) {
global $DB;
$params = self::validate_parameters(self::get_cohort_members_parameters(), array('cohortids' => $cohortids));
$members = array();
foreach ($params['cohortids'] as $cohortid) {
// Validate params.
$cohort = $DB->get_record('cohort', array('id' => $cohortid), '*', MUST_EXIST);
// Now security checks.
$context = context::instance_by_id($cohort->contextid, MUST_EXIST);
if ($context->contextlevel != CONTEXT_COURSECAT and $context->contextlevel != CONTEXT_SYSTEM) {
throw new invalid_parameter_exception('Invalid context');
}
self::validate_context($context);
if (!has_any_capability(array('moodle/cohort:manage', 'moodle/cohort:view'), $context)) {
throw new required_capability_exception($context, 'moodle/cohort:view', 'nopermissions', '');
}
$cohortmembers = $DB->get_records_sql("SELECT u.id FROM {user} u, {cohort_members} cm
WHERE u.id = cm.userid AND cm.cohortid = ?
ORDER BY lastname ASC, firstname ASC", array($cohort->id));
$members[] = array('cohortid' => $cohortid, 'userids' => array_keys($cohortmembers));
}
return $members;
}
|
[
"public",
"static",
"function",
"get_cohort_members",
"(",
"$",
"cohortids",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_cohort_members_parameters",
"(",
")",
",",
"array",
"(",
"'cohortids'",
"=>",
"$",
"cohortids",
")",
")",
";",
"$",
"members",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"params",
"[",
"'cohortids'",
"]",
"as",
"$",
"cohortid",
")",
"{",
"// Validate params.",
"$",
"cohort",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'cohort'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"cohortid",
")",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"// Now security checks.",
"$",
"context",
"=",
"context",
"::",
"instance_by_id",
"(",
"$",
"cohort",
"->",
"contextid",
",",
"MUST_EXIST",
")",
";",
"if",
"(",
"$",
"context",
"->",
"contextlevel",
"!=",
"CONTEXT_COURSECAT",
"and",
"$",
"context",
"->",
"contextlevel",
"!=",
"CONTEXT_SYSTEM",
")",
"{",
"throw",
"new",
"invalid_parameter_exception",
"(",
"'Invalid context'",
")",
";",
"}",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"if",
"(",
"!",
"has_any_capability",
"(",
"array",
"(",
"'moodle/cohort:manage'",
",",
"'moodle/cohort:view'",
")",
",",
"$",
"context",
")",
")",
"{",
"throw",
"new",
"required_capability_exception",
"(",
"$",
"context",
",",
"'moodle/cohort:view'",
",",
"'nopermissions'",
",",
"''",
")",
";",
"}",
"$",
"cohortmembers",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"\"SELECT u.id FROM {user} u, {cohort_members} cm\n WHERE u.id = cm.userid AND cm.cohortid = ?\n ORDER BY lastname ASC, firstname ASC\"",
",",
"array",
"(",
"$",
"cohort",
"->",
"id",
")",
")",
";",
"$",
"members",
"[",
"]",
"=",
"array",
"(",
"'cohortid'",
"=>",
"$",
"cohortid",
",",
"'userids'",
"=>",
"array_keys",
"(",
"$",
"cohortmembers",
")",
")",
";",
"}",
"return",
"$",
"members",
";",
"}"
] |
Return all members for a cohort
@param array $cohortids array of cohort ids
@return array with cohort id keys containing arrays of user ids
@since Moodle 2.5
|
[
"Return",
"all",
"members",
"for",
"a",
"cohort"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cohort/externallib.php#L781-L806
|
219,453
|
moodle/moodle
|
course/classes/list_element.php
|
core_course_list_element.has_summary
|
public function has_summary() {
if (isset($this->record->hassummary)) {
return !empty($this->record->hassummary);
}
if (!isset($this->record->summary)) {
// We need to retrieve summary.
$this->__get('summary');
}
return !empty($this->record->summary);
}
|
php
|
public function has_summary() {
if (isset($this->record->hassummary)) {
return !empty($this->record->hassummary);
}
if (!isset($this->record->summary)) {
// We need to retrieve summary.
$this->__get('summary');
}
return !empty($this->record->summary);
}
|
[
"public",
"function",
"has_summary",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"record",
"->",
"hassummary",
")",
")",
"{",
"return",
"!",
"empty",
"(",
"$",
"this",
"->",
"record",
"->",
"hassummary",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"record",
"->",
"summary",
")",
")",
"{",
"// We need to retrieve summary.",
"$",
"this",
"->",
"__get",
"(",
"'summary'",
")",
";",
"}",
"return",
"!",
"empty",
"(",
"$",
"this",
"->",
"record",
"->",
"summary",
")",
";",
"}"
] |
Indicates if the course has non-empty summary field
@return bool
|
[
"Indicates",
"if",
"the",
"course",
"has",
"non",
"-",
"empty",
"summary",
"field"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/list_element.php#L110-L119
|
219,454
|
moodle/moodle
|
course/classes/list_element.php
|
core_course_list_element.has_course_contacts
|
public function has_course_contacts() {
if (!isset($this->record->managers)) {
$courses = array($this->id => &$this->record);
core_course_category::preload_course_contacts($courses);
}
return !empty($this->record->managers);
}
|
php
|
public function has_course_contacts() {
if (!isset($this->record->managers)) {
$courses = array($this->id => &$this->record);
core_course_category::preload_course_contacts($courses);
}
return !empty($this->record->managers);
}
|
[
"public",
"function",
"has_course_contacts",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"record",
"->",
"managers",
")",
")",
"{",
"$",
"courses",
"=",
"array",
"(",
"$",
"this",
"->",
"id",
"=>",
"&",
"$",
"this",
"->",
"record",
")",
";",
"core_course_category",
"::",
"preload_course_contacts",
"(",
"$",
"courses",
")",
";",
"}",
"return",
"!",
"empty",
"(",
"$",
"this",
"->",
"record",
"->",
"managers",
")",
";",
"}"
] |
Indicates if the course have course contacts to display
@return bool
|
[
"Indicates",
"if",
"the",
"course",
"have",
"course",
"contacts",
"to",
"display"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/list_element.php#L126-L132
|
219,455
|
moodle/moodle
|
course/classes/list_element.php
|
core_course_list_element.get_custom_fields
|
public function get_custom_fields() : array {
if (!isset($this->record->customfields)) {
$this->record->customfields = \core_course\customfield\course_handler::create()->get_instance_data($this->id);
}
return $this->record->customfields;
}
|
php
|
public function get_custom_fields() : array {
if (!isset($this->record->customfields)) {
$this->record->customfields = \core_course\customfield\course_handler::create()->get_instance_data($this->id);
}
return $this->record->customfields;
}
|
[
"public",
"function",
"get_custom_fields",
"(",
")",
":",
"array",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"record",
"->",
"customfields",
")",
")",
"{",
"$",
"this",
"->",
"record",
"->",
"customfields",
"=",
"\\",
"core_course",
"\\",
"customfield",
"\\",
"course_handler",
"::",
"create",
"(",
")",
"->",
"get_instance_data",
"(",
"$",
"this",
"->",
"id",
")",
";",
"}",
"return",
"$",
"this",
"->",
"record",
"->",
"customfields",
";",
"}"
] |
Returns custom fields data for this course
@return \core_customfield\data_controller[]
|
[
"Returns",
"custom",
"fields",
"data",
"for",
"this",
"course"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/list_element.php#L208-L213
|
219,456
|
moodle/moodle
|
course/classes/list_element.php
|
core_course_list_element.has_course_overviewfiles
|
public function has_course_overviewfiles() {
global $CFG;
if (empty($CFG->courseoverviewfileslimit)) {
return false;
}
$fs = get_file_storage();
$context = context_course::instance($this->id);
return !$fs->is_area_empty($context->id, 'course', 'overviewfiles');
}
|
php
|
public function has_course_overviewfiles() {
global $CFG;
if (empty($CFG->courseoverviewfileslimit)) {
return false;
}
$fs = get_file_storage();
$context = context_course::instance($this->id);
return !$fs->is_area_empty($context->id, 'course', 'overviewfiles');
}
|
[
"public",
"function",
"has_course_overviewfiles",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"if",
"(",
"empty",
"(",
"$",
"CFG",
"->",
"courseoverviewfileslimit",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"this",
"->",
"id",
")",
";",
"return",
"!",
"$",
"fs",
"->",
"is_area_empty",
"(",
"$",
"context",
"->",
"id",
",",
"'course'",
",",
"'overviewfiles'",
")",
";",
"}"
] |
Checks if course has any associated overview files
@return bool
|
[
"Checks",
"if",
"course",
"has",
"any",
"associated",
"overview",
"files"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/list_element.php#L230-L238
|
219,457
|
moodle/moodle
|
course/classes/list_element.php
|
core_course_list_element.get_course_overviewfiles
|
public function get_course_overviewfiles() {
global $CFG;
if (empty($CFG->courseoverviewfileslimit)) {
return array();
}
require_once($CFG->libdir. '/filestorage/file_storage.php');
require_once($CFG->dirroot. '/course/lib.php');
$fs = get_file_storage();
$context = context_course::instance($this->id);
$files = $fs->get_area_files($context->id, 'course', 'overviewfiles', false, 'filename', false);
if (count($files)) {
$overviewfilesoptions = course_overviewfiles_options($this->id);
$acceptedtypes = $overviewfilesoptions['accepted_types'];
if ($acceptedtypes !== '*') {
// Filter only files with allowed extensions.
require_once($CFG->libdir. '/filelib.php');
foreach ($files as $key => $file) {
if (!file_extension_in_typegroup($file->get_filename(), $acceptedtypes)) {
unset($files[$key]);
}
}
}
if (count($files) > $CFG->courseoverviewfileslimit) {
// Return no more than $CFG->courseoverviewfileslimit files.
$files = array_slice($files, 0, $CFG->courseoverviewfileslimit, true);
}
}
return $files;
}
|
php
|
public function get_course_overviewfiles() {
global $CFG;
if (empty($CFG->courseoverviewfileslimit)) {
return array();
}
require_once($CFG->libdir. '/filestorage/file_storage.php');
require_once($CFG->dirroot. '/course/lib.php');
$fs = get_file_storage();
$context = context_course::instance($this->id);
$files = $fs->get_area_files($context->id, 'course', 'overviewfiles', false, 'filename', false);
if (count($files)) {
$overviewfilesoptions = course_overviewfiles_options($this->id);
$acceptedtypes = $overviewfilesoptions['accepted_types'];
if ($acceptedtypes !== '*') {
// Filter only files with allowed extensions.
require_once($CFG->libdir. '/filelib.php');
foreach ($files as $key => $file) {
if (!file_extension_in_typegroup($file->get_filename(), $acceptedtypes)) {
unset($files[$key]);
}
}
}
if (count($files) > $CFG->courseoverviewfileslimit) {
// Return no more than $CFG->courseoverviewfileslimit files.
$files = array_slice($files, 0, $CFG->courseoverviewfileslimit, true);
}
}
return $files;
}
|
[
"public",
"function",
"get_course_overviewfiles",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"if",
"(",
"empty",
"(",
"$",
"CFG",
"->",
"courseoverviewfileslimit",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"require_once",
"(",
"$",
"CFG",
"->",
"libdir",
".",
"'/filestorage/file_storage.php'",
")",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/course/lib.php'",
")",
";",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"this",
"->",
"id",
")",
";",
"$",
"files",
"=",
"$",
"fs",
"->",
"get_area_files",
"(",
"$",
"context",
"->",
"id",
",",
"'course'",
",",
"'overviewfiles'",
",",
"false",
",",
"'filename'",
",",
"false",
")",
";",
"if",
"(",
"count",
"(",
"$",
"files",
")",
")",
"{",
"$",
"overviewfilesoptions",
"=",
"course_overviewfiles_options",
"(",
"$",
"this",
"->",
"id",
")",
";",
"$",
"acceptedtypes",
"=",
"$",
"overviewfilesoptions",
"[",
"'accepted_types'",
"]",
";",
"if",
"(",
"$",
"acceptedtypes",
"!==",
"'*'",
")",
"{",
"// Filter only files with allowed extensions.",
"require_once",
"(",
"$",
"CFG",
"->",
"libdir",
".",
"'/filelib.php'",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"key",
"=>",
"$",
"file",
")",
"{",
"if",
"(",
"!",
"file_extension_in_typegroup",
"(",
"$",
"file",
"->",
"get_filename",
"(",
")",
",",
"$",
"acceptedtypes",
")",
")",
"{",
"unset",
"(",
"$",
"files",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"}",
"if",
"(",
"count",
"(",
"$",
"files",
")",
">",
"$",
"CFG",
"->",
"courseoverviewfileslimit",
")",
"{",
"// Return no more than $CFG->courseoverviewfileslimit files.",
"$",
"files",
"=",
"array_slice",
"(",
"$",
"files",
",",
"0",
",",
"$",
"CFG",
"->",
"courseoverviewfileslimit",
",",
"true",
")",
";",
"}",
"}",
"return",
"$",
"files",
";",
"}"
] |
Returns all course overview files
@return array array of stored_file objects
|
[
"Returns",
"all",
"course",
"overview",
"files"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/list_element.php#L245-L273
|
219,458
|
moodle/moodle
|
course/classes/list_element.php
|
core_course_list_element.getIterator
|
public function getIterator() {
$ret = array('id' => $this->record->id);
foreach ($this->record as $property => $value) {
$ret[$property] = $value;
}
return new ArrayIterator($ret);
}
|
php
|
public function getIterator() {
$ret = array('id' => $this->record->id);
foreach ($this->record as $property => $value) {
$ret[$property] = $value;
}
return new ArrayIterator($ret);
}
|
[
"public",
"function",
"getIterator",
"(",
")",
"{",
"$",
"ret",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"record",
"->",
"id",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"record",
"as",
"$",
"property",
"=>",
"$",
"value",
")",
"{",
"$",
"ret",
"[",
"$",
"property",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"new",
"ArrayIterator",
"(",
"$",
"ret",
")",
";",
"}"
] |
Create an iterator because magic vars can't be seen by 'foreach'.
Exclude context fields
Implementing method from interface IteratorAggregate
@return ArrayIterator
|
[
"Create",
"an",
"iterator",
"because",
"magic",
"vars",
"can",
"t",
"be",
"seen",
"by",
"foreach",
".",
"Exclude",
"context",
"fields"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/list_element.php#L339-L345
|
219,459
|
moodle/moodle
|
course/classes/list_element.php
|
core_course_list_element.can_access
|
public function can_access() {
if ($this->canaccess === null) {
$this->canaccess = can_access_course($this->record);
}
return $this->canaccess;
}
|
php
|
public function can_access() {
if ($this->canaccess === null) {
$this->canaccess = can_access_course($this->record);
}
return $this->canaccess;
}
|
[
"public",
"function",
"can_access",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"canaccess",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"canaccess",
"=",
"can_access_course",
"(",
"$",
"this",
"->",
"record",
")",
";",
"}",
"return",
"$",
"this",
"->",
"canaccess",
";",
"}"
] |
Returns true if the current user can access this course.
@return bool
|
[
"Returns",
"true",
"if",
"the",
"current",
"user",
"can",
"access",
"this",
"course",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/list_element.php#L375-L380
|
219,460
|
moodle/moodle
|
lib/spout/src/Spout/Common/Helper/EncodingHelper.php
|
EncodingHelper.getBytesOffsetToSkipBOM
|
public function getBytesOffsetToSkipBOM($filePointer, $encoding)
{
$byteOffsetToSkipBom = 0;
if ($this->hasBOM($filePointer, $encoding)) {
$bomUsed = $this->supportedEncodingsWithBom[$encoding];
// we skip the N first bytes
$byteOffsetToSkipBom = strlen($bomUsed);
}
return $byteOffsetToSkipBom;
}
|
php
|
public function getBytesOffsetToSkipBOM($filePointer, $encoding)
{
$byteOffsetToSkipBom = 0;
if ($this->hasBOM($filePointer, $encoding)) {
$bomUsed = $this->supportedEncodingsWithBom[$encoding];
// we skip the N first bytes
$byteOffsetToSkipBom = strlen($bomUsed);
}
return $byteOffsetToSkipBom;
}
|
[
"public",
"function",
"getBytesOffsetToSkipBOM",
"(",
"$",
"filePointer",
",",
"$",
"encoding",
")",
"{",
"$",
"byteOffsetToSkipBom",
"=",
"0",
";",
"if",
"(",
"$",
"this",
"->",
"hasBOM",
"(",
"$",
"filePointer",
",",
"$",
"encoding",
")",
")",
"{",
"$",
"bomUsed",
"=",
"$",
"this",
"->",
"supportedEncodingsWithBom",
"[",
"$",
"encoding",
"]",
";",
"// we skip the N first bytes",
"$",
"byteOffsetToSkipBom",
"=",
"strlen",
"(",
"$",
"bomUsed",
")",
";",
"}",
"return",
"$",
"byteOffsetToSkipBom",
";",
"}"
] |
Returns the number of bytes to use as offset in order to skip the BOM.
@param resource $filePointer Pointer to the file to check
@param string $encoding Encoding of the file to check
@return int Bytes offset to apply to skip the BOM (0 means no BOM)
|
[
"Returns",
"the",
"number",
"of",
"bytes",
"to",
"use",
"as",
"offset",
"in",
"order",
"to",
"skip",
"the",
"BOM",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Common/Helper/EncodingHelper.php#L58-L70
|
219,461
|
moodle/moodle
|
lib/spout/src/Spout/Common/Helper/EncodingHelper.php
|
EncodingHelper.hasBOM
|
protected function hasBOM($filePointer, $encoding)
{
$hasBOM = false;
$this->globalFunctionsHelper->rewind($filePointer);
if (array_key_exists($encoding, $this->supportedEncodingsWithBom)) {
$potentialBom = $this->supportedEncodingsWithBom[$encoding];
$numBytesInBom = strlen($potentialBom);
$hasBOM = ($this->globalFunctionsHelper->fgets($filePointer, $numBytesInBom + 1) === $potentialBom);
}
return $hasBOM;
}
|
php
|
protected function hasBOM($filePointer, $encoding)
{
$hasBOM = false;
$this->globalFunctionsHelper->rewind($filePointer);
if (array_key_exists($encoding, $this->supportedEncodingsWithBom)) {
$potentialBom = $this->supportedEncodingsWithBom[$encoding];
$numBytesInBom = strlen($potentialBom);
$hasBOM = ($this->globalFunctionsHelper->fgets($filePointer, $numBytesInBom + 1) === $potentialBom);
}
return $hasBOM;
}
|
[
"protected",
"function",
"hasBOM",
"(",
"$",
"filePointer",
",",
"$",
"encoding",
")",
"{",
"$",
"hasBOM",
"=",
"false",
";",
"$",
"this",
"->",
"globalFunctionsHelper",
"->",
"rewind",
"(",
"$",
"filePointer",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"encoding",
",",
"$",
"this",
"->",
"supportedEncodingsWithBom",
")",
")",
"{",
"$",
"potentialBom",
"=",
"$",
"this",
"->",
"supportedEncodingsWithBom",
"[",
"$",
"encoding",
"]",
";",
"$",
"numBytesInBom",
"=",
"strlen",
"(",
"$",
"potentialBom",
")",
";",
"$",
"hasBOM",
"=",
"(",
"$",
"this",
"->",
"globalFunctionsHelper",
"->",
"fgets",
"(",
"$",
"filePointer",
",",
"$",
"numBytesInBom",
"+",
"1",
")",
"===",
"$",
"potentialBom",
")",
";",
"}",
"return",
"$",
"hasBOM",
";",
"}"
] |
Returns whether the file identified by the given pointer has a BOM.
@param resource $filePointer Pointer to the file to check
@param string $encoding Encoding of the file to check
@return bool TRUE if the file has a BOM, FALSE otherwise
|
[
"Returns",
"whether",
"the",
"file",
"identified",
"by",
"the",
"given",
"pointer",
"has",
"a",
"BOM",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Common/Helper/EncodingHelper.php#L79-L93
|
219,462
|
moodle/moodle
|
lib/spout/src/Spout/Common/Helper/EncodingHelper.php
|
EncodingHelper.attemptConversion
|
protected function attemptConversion($string, $sourceEncoding, $targetEncoding)
{
// if source and target encodings are the same, it's a no-op
if ($sourceEncoding === $targetEncoding) {
return $string;
}
$convertedString = null;
if ($this->canUseIconv()) {
$convertedString = $this->globalFunctionsHelper->iconv($string, $sourceEncoding, $targetEncoding);
} else if ($this->canUseMbString()) {
$convertedString = $this->globalFunctionsHelper->mb_convert_encoding($string, $sourceEncoding, $targetEncoding);
} else {
throw new EncodingConversionException("The conversion from $sourceEncoding to $targetEncoding is not supported. Please install \"iconv\" or \"PHP Intl\".");
}
if ($convertedString === false) {
throw new EncodingConversionException("The conversion from $sourceEncoding to $targetEncoding failed.");
}
return $convertedString;
}
|
php
|
protected function attemptConversion($string, $sourceEncoding, $targetEncoding)
{
// if source and target encodings are the same, it's a no-op
if ($sourceEncoding === $targetEncoding) {
return $string;
}
$convertedString = null;
if ($this->canUseIconv()) {
$convertedString = $this->globalFunctionsHelper->iconv($string, $sourceEncoding, $targetEncoding);
} else if ($this->canUseMbString()) {
$convertedString = $this->globalFunctionsHelper->mb_convert_encoding($string, $sourceEncoding, $targetEncoding);
} else {
throw new EncodingConversionException("The conversion from $sourceEncoding to $targetEncoding is not supported. Please install \"iconv\" or \"PHP Intl\".");
}
if ($convertedString === false) {
throw new EncodingConversionException("The conversion from $sourceEncoding to $targetEncoding failed.");
}
return $convertedString;
}
|
[
"protected",
"function",
"attemptConversion",
"(",
"$",
"string",
",",
"$",
"sourceEncoding",
",",
"$",
"targetEncoding",
")",
"{",
"// if source and target encodings are the same, it's a no-op",
"if",
"(",
"$",
"sourceEncoding",
"===",
"$",
"targetEncoding",
")",
"{",
"return",
"$",
"string",
";",
"}",
"$",
"convertedString",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"canUseIconv",
"(",
")",
")",
"{",
"$",
"convertedString",
"=",
"$",
"this",
"->",
"globalFunctionsHelper",
"->",
"iconv",
"(",
"$",
"string",
",",
"$",
"sourceEncoding",
",",
"$",
"targetEncoding",
")",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"canUseMbString",
"(",
")",
")",
"{",
"$",
"convertedString",
"=",
"$",
"this",
"->",
"globalFunctionsHelper",
"->",
"mb_convert_encoding",
"(",
"$",
"string",
",",
"$",
"sourceEncoding",
",",
"$",
"targetEncoding",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"EncodingConversionException",
"(",
"\"The conversion from $sourceEncoding to $targetEncoding is not supported. Please install \\\"iconv\\\" or \\\"PHP Intl\\\".\"",
")",
";",
"}",
"if",
"(",
"$",
"convertedString",
"===",
"false",
")",
"{",
"throw",
"new",
"EncodingConversionException",
"(",
"\"The conversion from $sourceEncoding to $targetEncoding failed.\"",
")",
";",
"}",
"return",
"$",
"convertedString",
";",
"}"
] |
Attempts to convert the given string to the given encoding.
Depending on what is installed on the server, we will try to iconv or mbstring.
@param string $string string to be converted
@param string $sourceEncoding The encoding used to encode the source string
@param string $targetEncoding The encoding the string should be re-encoded into
@return string The converted string, encoded with the given encoding
@throws \Box\Spout\Common\Exception\EncodingConversionException If conversion is not supported or if the conversion failed
|
[
"Attempts",
"to",
"convert",
"the",
"given",
"string",
"to",
"the",
"given",
"encoding",
".",
"Depending",
"on",
"what",
"is",
"installed",
"on",
"the",
"server",
"we",
"will",
"try",
"to",
"iconv",
"or",
"mbstring",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Common/Helper/EncodingHelper.php#L131-L153
|
219,463
|
moodle/moodle
|
mod/data/locallib.php
|
data_portfolio_caller.load_data
|
public function load_data() {
global $DB, $USER;
if (!$this->cm = get_coursemodule_from_id('data', $this->id)) {
throw new portfolio_caller_exception('invalidid', 'data');
}
if (!$this->data = $DB->get_record('data', array('id' => $this->cm->instance))) {
throw new portfolio_caller_exception('invalidid', 'data');
}
$fieldrecords = $DB->get_records('data_fields', array('dataid' => $this->cm->instance), 'id');
// populate objets for this databases fields
$this->fields = array();
foreach ($fieldrecords as $fieldrecord) {
$tmp = data_get_field($fieldrecord, $this->data);
$this->fields[] = $tmp;
$this->fieldtypes[] = $tmp->type;
}
$this->records = array();
if ($this->recordid) {
$tmp = $DB->get_record('data_records', array('id' => $this->recordid));
$tmp->content = $DB->get_records('data_content', array('recordid' => $this->recordid));
$this->records[] = $tmp;
} else {
$where = array('dataid' => $this->data->id);
if (!has_capability('mod/data:exportallentries', context_module::instance($this->cm->id))) {
$where['userid'] = $USER->id; // get them all in case, we'll unset ones that aren't ours later if necessary
}
$tmp = $DB->get_records('data_records', $where);
foreach ($tmp as $t) {
$t->content = $DB->get_records('data_content', array('recordid' => $t->id));
$this->records[] = $t;
}
$this->minecount = $DB->count_records('data_records', array('dataid' => $this->data->id, 'userid' => $USER->id));
}
if ($this->recordid) {
list($formats, $files) = self::formats($this->fields, $this->records[0]);
$this->set_file_and_format_data($files);
}
}
|
php
|
public function load_data() {
global $DB, $USER;
if (!$this->cm = get_coursemodule_from_id('data', $this->id)) {
throw new portfolio_caller_exception('invalidid', 'data');
}
if (!$this->data = $DB->get_record('data', array('id' => $this->cm->instance))) {
throw new portfolio_caller_exception('invalidid', 'data');
}
$fieldrecords = $DB->get_records('data_fields', array('dataid' => $this->cm->instance), 'id');
// populate objets for this databases fields
$this->fields = array();
foreach ($fieldrecords as $fieldrecord) {
$tmp = data_get_field($fieldrecord, $this->data);
$this->fields[] = $tmp;
$this->fieldtypes[] = $tmp->type;
}
$this->records = array();
if ($this->recordid) {
$tmp = $DB->get_record('data_records', array('id' => $this->recordid));
$tmp->content = $DB->get_records('data_content', array('recordid' => $this->recordid));
$this->records[] = $tmp;
} else {
$where = array('dataid' => $this->data->id);
if (!has_capability('mod/data:exportallentries', context_module::instance($this->cm->id))) {
$where['userid'] = $USER->id; // get them all in case, we'll unset ones that aren't ours later if necessary
}
$tmp = $DB->get_records('data_records', $where);
foreach ($tmp as $t) {
$t->content = $DB->get_records('data_content', array('recordid' => $t->id));
$this->records[] = $t;
}
$this->minecount = $DB->count_records('data_records', array('dataid' => $this->data->id, 'userid' => $USER->id));
}
if ($this->recordid) {
list($formats, $files) = self::formats($this->fields, $this->records[0]);
$this->set_file_and_format_data($files);
}
}
|
[
"public",
"function",
"load_data",
"(",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"USER",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"cm",
"=",
"get_coursemodule_from_id",
"(",
"'data'",
",",
"$",
"this",
"->",
"id",
")",
")",
"{",
"throw",
"new",
"portfolio_caller_exception",
"(",
"'invalidid'",
",",
"'data'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"data",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'data'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"cm",
"->",
"instance",
")",
")",
")",
"{",
"throw",
"new",
"portfolio_caller_exception",
"(",
"'invalidid'",
",",
"'data'",
")",
";",
"}",
"$",
"fieldrecords",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'data_fields'",
",",
"array",
"(",
"'dataid'",
"=>",
"$",
"this",
"->",
"cm",
"->",
"instance",
")",
",",
"'id'",
")",
";",
"// populate objets for this databases fields",
"$",
"this",
"->",
"fields",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"fieldrecords",
"as",
"$",
"fieldrecord",
")",
"{",
"$",
"tmp",
"=",
"data_get_field",
"(",
"$",
"fieldrecord",
",",
"$",
"this",
"->",
"data",
")",
";",
"$",
"this",
"->",
"fields",
"[",
"]",
"=",
"$",
"tmp",
";",
"$",
"this",
"->",
"fieldtypes",
"[",
"]",
"=",
"$",
"tmp",
"->",
"type",
";",
"}",
"$",
"this",
"->",
"records",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"recordid",
")",
"{",
"$",
"tmp",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'data_records'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"recordid",
")",
")",
";",
"$",
"tmp",
"->",
"content",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'data_content'",
",",
"array",
"(",
"'recordid'",
"=>",
"$",
"this",
"->",
"recordid",
")",
")",
";",
"$",
"this",
"->",
"records",
"[",
"]",
"=",
"$",
"tmp",
";",
"}",
"else",
"{",
"$",
"where",
"=",
"array",
"(",
"'dataid'",
"=>",
"$",
"this",
"->",
"data",
"->",
"id",
")",
";",
"if",
"(",
"!",
"has_capability",
"(",
"'mod/data:exportallentries'",
",",
"context_module",
"::",
"instance",
"(",
"$",
"this",
"->",
"cm",
"->",
"id",
")",
")",
")",
"{",
"$",
"where",
"[",
"'userid'",
"]",
"=",
"$",
"USER",
"->",
"id",
";",
"// get them all in case, we'll unset ones that aren't ours later if necessary",
"}",
"$",
"tmp",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'data_records'",
",",
"$",
"where",
")",
";",
"foreach",
"(",
"$",
"tmp",
"as",
"$",
"t",
")",
"{",
"$",
"t",
"->",
"content",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'data_content'",
",",
"array",
"(",
"'recordid'",
"=>",
"$",
"t",
"->",
"id",
")",
")",
";",
"$",
"this",
"->",
"records",
"[",
"]",
"=",
"$",
"t",
";",
"}",
"$",
"this",
"->",
"minecount",
"=",
"$",
"DB",
"->",
"count_records",
"(",
"'data_records'",
",",
"array",
"(",
"'dataid'",
"=>",
"$",
"this",
"->",
"data",
"->",
"id",
",",
"'userid'",
"=>",
"$",
"USER",
"->",
"id",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"recordid",
")",
"{",
"list",
"(",
"$",
"formats",
",",
"$",
"files",
")",
"=",
"self",
"::",
"formats",
"(",
"$",
"this",
"->",
"fields",
",",
"$",
"this",
"->",
"records",
"[",
"0",
"]",
")",
";",
"$",
"this",
"->",
"set_file_and_format_data",
"(",
"$",
"files",
")",
";",
"}",
"}"
] |
load up the data needed for the export
@global object $DB
|
[
"load",
"up",
"the",
"data",
"needed",
"for",
"the",
"export"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/locallib.php#L82-L121
|
219,464
|
moodle/moodle
|
mod/data/locallib.php
|
data_portfolio_caller.get_sha1
|
public function get_sha1() {
// in the case that we're exporting a subclass of 'file' and we have a singlefile,
// then we're not exporting any metadata, just the file by itself by mimetype.
if ($this->exporter->get('format') instanceof portfolio_format_file && $this->singlefile) {
return $this->get_sha1_file();
}
// otherwise we're exporting some sort of multipart content so use the data
$str = '';
foreach ($this->records as $record) {
foreach ($record as $data) {
if (is_array($data) || is_object($data)) {
$keys = array_keys($data);
$testkey = array_pop($keys);
if (is_array($data[$testkey]) || is_object($data[$testkey])) {
foreach ($data as $d) {
$str .= implode(',', (array)$d);
}
} else {
$str .= implode(',', (array)$data);
}
} else {
$str .= $data;
}
}
}
return sha1($str . ',' . $this->exporter->get('formatclass'));
}
|
php
|
public function get_sha1() {
// in the case that we're exporting a subclass of 'file' and we have a singlefile,
// then we're not exporting any metadata, just the file by itself by mimetype.
if ($this->exporter->get('format') instanceof portfolio_format_file && $this->singlefile) {
return $this->get_sha1_file();
}
// otherwise we're exporting some sort of multipart content so use the data
$str = '';
foreach ($this->records as $record) {
foreach ($record as $data) {
if (is_array($data) || is_object($data)) {
$keys = array_keys($data);
$testkey = array_pop($keys);
if (is_array($data[$testkey]) || is_object($data[$testkey])) {
foreach ($data as $d) {
$str .= implode(',', (array)$d);
}
} else {
$str .= implode(',', (array)$data);
}
} else {
$str .= $data;
}
}
}
return sha1($str . ',' . $this->exporter->get('formatclass'));
}
|
[
"public",
"function",
"get_sha1",
"(",
")",
"{",
"// in the case that we're exporting a subclass of 'file' and we have a singlefile,",
"// then we're not exporting any metadata, just the file by itself by mimetype.",
"if",
"(",
"$",
"this",
"->",
"exporter",
"->",
"get",
"(",
"'format'",
")",
"instanceof",
"portfolio_format_file",
"&&",
"$",
"this",
"->",
"singlefile",
")",
"{",
"return",
"$",
"this",
"->",
"get_sha1_file",
"(",
")",
";",
"}",
"// otherwise we're exporting some sort of multipart content so use the data",
"$",
"str",
"=",
"''",
";",
"foreach",
"(",
"$",
"this",
"->",
"records",
"as",
"$",
"record",
")",
"{",
"foreach",
"(",
"$",
"record",
"as",
"$",
"data",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
"||",
"is_object",
"(",
"$",
"data",
")",
")",
"{",
"$",
"keys",
"=",
"array_keys",
"(",
"$",
"data",
")",
";",
"$",
"testkey",
"=",
"array_pop",
"(",
"$",
"keys",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"data",
"[",
"$",
"testkey",
"]",
")",
"||",
"is_object",
"(",
"$",
"data",
"[",
"$",
"testkey",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"d",
")",
"{",
"$",
"str",
".=",
"implode",
"(",
"','",
",",
"(",
"array",
")",
"$",
"d",
")",
";",
"}",
"}",
"else",
"{",
"$",
"str",
".=",
"implode",
"(",
"','",
",",
"(",
"array",
")",
"$",
"data",
")",
";",
"}",
"}",
"else",
"{",
"$",
"str",
".=",
"$",
"data",
";",
"}",
"}",
"}",
"return",
"sha1",
"(",
"$",
"str",
".",
"','",
".",
"$",
"this",
"->",
"exporter",
"->",
"get",
"(",
"'formatclass'",
")",
")",
";",
"}"
] |
Calculate the shal1 of this export
Dependent on the export format.
@return string
|
[
"Calculate",
"the",
"shal1",
"of",
"this",
"export",
"Dependent",
"on",
"the",
"export",
"format",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/locallib.php#L144-L170
|
219,465
|
moodle/moodle
|
mod/data/locallib.php
|
data_portfolio_caller.check_permissions
|
public function check_permissions() {
if ($this->recordid) {
if (data_isowner($this->recordid)) {
return has_capability('mod/data:exportownentry', context_module::instance($this->cm->id));
}
return has_capability('mod/data:exportentry', context_module::instance($this->cm->id));
}
if ($this->has_export_config() && !$this->get_export_config('mineonly')) {
return has_capability('mod/data:exportallentries', context_module::instance($this->cm->id));
}
return has_capability('mod/data:exportownentry', context_module::instance($this->cm->id));
}
|
php
|
public function check_permissions() {
if ($this->recordid) {
if (data_isowner($this->recordid)) {
return has_capability('mod/data:exportownentry', context_module::instance($this->cm->id));
}
return has_capability('mod/data:exportentry', context_module::instance($this->cm->id));
}
if ($this->has_export_config() && !$this->get_export_config('mineonly')) {
return has_capability('mod/data:exportallentries', context_module::instance($this->cm->id));
}
return has_capability('mod/data:exportownentry', context_module::instance($this->cm->id));
}
|
[
"public",
"function",
"check_permissions",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"recordid",
")",
"{",
"if",
"(",
"data_isowner",
"(",
"$",
"this",
"->",
"recordid",
")",
")",
"{",
"return",
"has_capability",
"(",
"'mod/data:exportownentry'",
",",
"context_module",
"::",
"instance",
"(",
"$",
"this",
"->",
"cm",
"->",
"id",
")",
")",
";",
"}",
"return",
"has_capability",
"(",
"'mod/data:exportentry'",
",",
"context_module",
"::",
"instance",
"(",
"$",
"this",
"->",
"cm",
"->",
"id",
")",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"has_export_config",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"get_export_config",
"(",
"'mineonly'",
")",
")",
"{",
"return",
"has_capability",
"(",
"'mod/data:exportallentries'",
",",
"context_module",
"::",
"instance",
"(",
"$",
"this",
"->",
"cm",
"->",
"id",
")",
")",
";",
"}",
"return",
"has_capability",
"(",
"'mod/data:exportownentry'",
",",
"context_module",
"::",
"instance",
"(",
"$",
"this",
"->",
"cm",
"->",
"id",
")",
")",
";",
"}"
] |
Verify the user can still export this entry
@return bool
|
[
"Verify",
"the",
"user",
"can",
"still",
"export",
"this",
"entry"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/locallib.php#L243-L254
|
219,466
|
moodle/moodle
|
mod/data/locallib.php
|
data_portfolio_caller.exportentry
|
private function exportentry($record) {
// Replacing tags
$patterns = array();
$replacement = array();
$files = array();
// Then we generate strings to replace for normal tags
$format = $this->get('exporter')->get('format');
foreach ($this->fields as $field) {
$patterns[]='[['.$field->field->name.']]';
if (is_callable(array($field, 'get_file'))) {
if (!$file = $field->get_file($record->id)) {
$replacement[] = '';
continue; // probably left empty
}
$replacement[] = $format->file_output($file);
$this->get('exporter')->copy_existing_file($file);
$files[] = $file;
} else {
$replacement[] = $field->display_browse_field($record->id, 'singletemplate');
}
}
// Replacing special tags (##Edit##, ##Delete##, ##More##)
$patterns[]='##edit##';
$patterns[]='##delete##';
$patterns[]='##export##';
$patterns[]='##more##';
$patterns[]='##moreurl##';
$patterns[]='##user##';
$patterns[]='##approve##';
$patterns[]='##disapprove##';
$patterns[]='##comments##';
$patterns[] = '##timeadded##';
$patterns[] = '##timemodified##';
$replacement[] = '';
$replacement[] = '';
$replacement[] = '';
$replacement[] = '';
$replacement[] = '';
$replacement[] = '';
$replacement[] = '';
$replacement[] = '';
$replacement[] = '';
$replacement[] = userdate($record->timecreated);
$replacement[] = userdate($record->timemodified);
// actual replacement of the tags
return array(str_ireplace($patterns, $replacement, $this->data->singletemplate), $files);
}
|
php
|
private function exportentry($record) {
// Replacing tags
$patterns = array();
$replacement = array();
$files = array();
// Then we generate strings to replace for normal tags
$format = $this->get('exporter')->get('format');
foreach ($this->fields as $field) {
$patterns[]='[['.$field->field->name.']]';
if (is_callable(array($field, 'get_file'))) {
if (!$file = $field->get_file($record->id)) {
$replacement[] = '';
continue; // probably left empty
}
$replacement[] = $format->file_output($file);
$this->get('exporter')->copy_existing_file($file);
$files[] = $file;
} else {
$replacement[] = $field->display_browse_field($record->id, 'singletemplate');
}
}
// Replacing special tags (##Edit##, ##Delete##, ##More##)
$patterns[]='##edit##';
$patterns[]='##delete##';
$patterns[]='##export##';
$patterns[]='##more##';
$patterns[]='##moreurl##';
$patterns[]='##user##';
$patterns[]='##approve##';
$patterns[]='##disapprove##';
$patterns[]='##comments##';
$patterns[] = '##timeadded##';
$patterns[] = '##timemodified##';
$replacement[] = '';
$replacement[] = '';
$replacement[] = '';
$replacement[] = '';
$replacement[] = '';
$replacement[] = '';
$replacement[] = '';
$replacement[] = '';
$replacement[] = '';
$replacement[] = userdate($record->timecreated);
$replacement[] = userdate($record->timemodified);
// actual replacement of the tags
return array(str_ireplace($patterns, $replacement, $this->data->singletemplate), $files);
}
|
[
"private",
"function",
"exportentry",
"(",
"$",
"record",
")",
"{",
"// Replacing tags",
"$",
"patterns",
"=",
"array",
"(",
")",
";",
"$",
"replacement",
"=",
"array",
"(",
")",
";",
"$",
"files",
"=",
"array",
"(",
")",
";",
"// Then we generate strings to replace for normal tags",
"$",
"format",
"=",
"$",
"this",
"->",
"get",
"(",
"'exporter'",
")",
"->",
"get",
"(",
"'format'",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"fields",
"as",
"$",
"field",
")",
"{",
"$",
"patterns",
"[",
"]",
"=",
"'[['",
".",
"$",
"field",
"->",
"field",
"->",
"name",
".",
"']]'",
";",
"if",
"(",
"is_callable",
"(",
"array",
"(",
"$",
"field",
",",
"'get_file'",
")",
")",
")",
"{",
"if",
"(",
"!",
"$",
"file",
"=",
"$",
"field",
"->",
"get_file",
"(",
"$",
"record",
"->",
"id",
")",
")",
"{",
"$",
"replacement",
"[",
"]",
"=",
"''",
";",
"continue",
";",
"// probably left empty",
"}",
"$",
"replacement",
"[",
"]",
"=",
"$",
"format",
"->",
"file_output",
"(",
"$",
"file",
")",
";",
"$",
"this",
"->",
"get",
"(",
"'exporter'",
")",
"->",
"copy_existing_file",
"(",
"$",
"file",
")",
";",
"$",
"files",
"[",
"]",
"=",
"$",
"file",
";",
"}",
"else",
"{",
"$",
"replacement",
"[",
"]",
"=",
"$",
"field",
"->",
"display_browse_field",
"(",
"$",
"record",
"->",
"id",
",",
"'singletemplate'",
")",
";",
"}",
"}",
"// Replacing special tags (##Edit##, ##Delete##, ##More##)",
"$",
"patterns",
"[",
"]",
"=",
"'##edit##'",
";",
"$",
"patterns",
"[",
"]",
"=",
"'##delete##'",
";",
"$",
"patterns",
"[",
"]",
"=",
"'##export##'",
";",
"$",
"patterns",
"[",
"]",
"=",
"'##more##'",
";",
"$",
"patterns",
"[",
"]",
"=",
"'##moreurl##'",
";",
"$",
"patterns",
"[",
"]",
"=",
"'##user##'",
";",
"$",
"patterns",
"[",
"]",
"=",
"'##approve##'",
";",
"$",
"patterns",
"[",
"]",
"=",
"'##disapprove##'",
";",
"$",
"patterns",
"[",
"]",
"=",
"'##comments##'",
";",
"$",
"patterns",
"[",
"]",
"=",
"'##timeadded##'",
";",
"$",
"patterns",
"[",
"]",
"=",
"'##timemodified##'",
";",
"$",
"replacement",
"[",
"]",
"=",
"''",
";",
"$",
"replacement",
"[",
"]",
"=",
"''",
";",
"$",
"replacement",
"[",
"]",
"=",
"''",
";",
"$",
"replacement",
"[",
"]",
"=",
"''",
";",
"$",
"replacement",
"[",
"]",
"=",
"''",
";",
"$",
"replacement",
"[",
"]",
"=",
"''",
";",
"$",
"replacement",
"[",
"]",
"=",
"''",
";",
"$",
"replacement",
"[",
"]",
"=",
"''",
";",
"$",
"replacement",
"[",
"]",
"=",
"''",
";",
"$",
"replacement",
"[",
"]",
"=",
"userdate",
"(",
"$",
"record",
"->",
"timecreated",
")",
";",
"$",
"replacement",
"[",
"]",
"=",
"userdate",
"(",
"$",
"record",
"->",
"timemodified",
")",
";",
"// actual replacement of the tags",
"return",
"array",
"(",
"str_ireplace",
"(",
"$",
"patterns",
",",
"$",
"replacement",
",",
"$",
"this",
"->",
"data",
"->",
"singletemplate",
")",
",",
"$",
"files",
")",
";",
"}"
] |
Prepare a single entry for export, replacing all the content etc
@param stdclass $record the entry to export
@return array with key 0 = the html content, key 1 = array of attachments
|
[
"Prepare",
"a",
"single",
"entry",
"for",
"export",
"replacing",
"all",
"the",
"content",
"etc"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/locallib.php#L285-L334
|
219,467
|
moodle/moodle
|
mod/lti/classes/privacy/provider.php
|
provider.export_user_data_lti_submissions
|
protected static function export_user_data_lti_submissions(approved_contextlist $contextlist) {
global $DB;
// Filter out any contexts that are not related to modules.
$cmids = array_reduce($contextlist->get_contexts(), function($carry, $context) {
if ($context->contextlevel == CONTEXT_MODULE) {
$carry[] = $context->instanceid;
}
return $carry;
}, []);
if (empty($cmids)) {
return;
}
$user = $contextlist->get_user();
// Get all the LTI activities associated with the above course modules.
$ltiidstocmids = self::get_lti_ids_to_cmids_from_cmids($cmids);
$ltiids = array_keys($ltiidstocmids);
list($insql, $inparams) = $DB->get_in_or_equal($ltiids, SQL_PARAMS_NAMED);
$params = array_merge($inparams, ['userid' => $user->id]);
$recordset = $DB->get_recordset_select('lti_submission', "ltiid $insql AND userid = :userid", $params, 'dateupdated, id');
self::recordset_loop_and_export($recordset, 'ltiid', [], function($carry, $record) use ($user, $ltiidstocmids) {
$carry[] = [
'gradepercent' => $record->gradepercent,
'originalgrade' => $record->originalgrade,
'datesubmitted' => transform::datetime($record->datesubmitted),
'dateupdated' => transform::datetime($record->dateupdated)
];
return $carry;
}, function($ltiid, $data) use ($user, $ltiidstocmids) {
$context = \context_module::instance($ltiidstocmids[$ltiid]);
$contextdata = helper::get_context_data($context, $user);
$finaldata = (object) array_merge((array) $contextdata, ['submissions' => $data]);
helper::export_context_files($context, $user);
writer::with_context($context)->export_data([], $finaldata);
});
}
|
php
|
protected static function export_user_data_lti_submissions(approved_contextlist $contextlist) {
global $DB;
// Filter out any contexts that are not related to modules.
$cmids = array_reduce($contextlist->get_contexts(), function($carry, $context) {
if ($context->contextlevel == CONTEXT_MODULE) {
$carry[] = $context->instanceid;
}
return $carry;
}, []);
if (empty($cmids)) {
return;
}
$user = $contextlist->get_user();
// Get all the LTI activities associated with the above course modules.
$ltiidstocmids = self::get_lti_ids_to_cmids_from_cmids($cmids);
$ltiids = array_keys($ltiidstocmids);
list($insql, $inparams) = $DB->get_in_or_equal($ltiids, SQL_PARAMS_NAMED);
$params = array_merge($inparams, ['userid' => $user->id]);
$recordset = $DB->get_recordset_select('lti_submission', "ltiid $insql AND userid = :userid", $params, 'dateupdated, id');
self::recordset_loop_and_export($recordset, 'ltiid', [], function($carry, $record) use ($user, $ltiidstocmids) {
$carry[] = [
'gradepercent' => $record->gradepercent,
'originalgrade' => $record->originalgrade,
'datesubmitted' => transform::datetime($record->datesubmitted),
'dateupdated' => transform::datetime($record->dateupdated)
];
return $carry;
}, function($ltiid, $data) use ($user, $ltiidstocmids) {
$context = \context_module::instance($ltiidstocmids[$ltiid]);
$contextdata = helper::get_context_data($context, $user);
$finaldata = (object) array_merge((array) $contextdata, ['submissions' => $data]);
helper::export_context_files($context, $user);
writer::with_context($context)->export_data([], $finaldata);
});
}
|
[
"protected",
"static",
"function",
"export_user_data_lti_submissions",
"(",
"approved_contextlist",
"$",
"contextlist",
")",
"{",
"global",
"$",
"DB",
";",
"// Filter out any contexts that are not related to modules.",
"$",
"cmids",
"=",
"array_reduce",
"(",
"$",
"contextlist",
"->",
"get_contexts",
"(",
")",
",",
"function",
"(",
"$",
"carry",
",",
"$",
"context",
")",
"{",
"if",
"(",
"$",
"context",
"->",
"contextlevel",
"==",
"CONTEXT_MODULE",
")",
"{",
"$",
"carry",
"[",
"]",
"=",
"$",
"context",
"->",
"instanceid",
";",
"}",
"return",
"$",
"carry",
";",
"}",
",",
"[",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"cmids",
")",
")",
"{",
"return",
";",
"}",
"$",
"user",
"=",
"$",
"contextlist",
"->",
"get_user",
"(",
")",
";",
"// Get all the LTI activities associated with the above course modules.",
"$",
"ltiidstocmids",
"=",
"self",
"::",
"get_lti_ids_to_cmids_from_cmids",
"(",
"$",
"cmids",
")",
";",
"$",
"ltiids",
"=",
"array_keys",
"(",
"$",
"ltiidstocmids",
")",
";",
"list",
"(",
"$",
"insql",
",",
"$",
"inparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"ltiids",
",",
"SQL_PARAMS_NAMED",
")",
";",
"$",
"params",
"=",
"array_merge",
"(",
"$",
"inparams",
",",
"[",
"'userid'",
"=>",
"$",
"user",
"->",
"id",
"]",
")",
";",
"$",
"recordset",
"=",
"$",
"DB",
"->",
"get_recordset_select",
"(",
"'lti_submission'",
",",
"\"ltiid $insql AND userid = :userid\"",
",",
"$",
"params",
",",
"'dateupdated, id'",
")",
";",
"self",
"::",
"recordset_loop_and_export",
"(",
"$",
"recordset",
",",
"'ltiid'",
",",
"[",
"]",
",",
"function",
"(",
"$",
"carry",
",",
"$",
"record",
")",
"use",
"(",
"$",
"user",
",",
"$",
"ltiidstocmids",
")",
"{",
"$",
"carry",
"[",
"]",
"=",
"[",
"'gradepercent'",
"=>",
"$",
"record",
"->",
"gradepercent",
",",
"'originalgrade'",
"=>",
"$",
"record",
"->",
"originalgrade",
",",
"'datesubmitted'",
"=>",
"transform",
"::",
"datetime",
"(",
"$",
"record",
"->",
"datesubmitted",
")",
",",
"'dateupdated'",
"=>",
"transform",
"::",
"datetime",
"(",
"$",
"record",
"->",
"dateupdated",
")",
"]",
";",
"return",
"$",
"carry",
";",
"}",
",",
"function",
"(",
"$",
"ltiid",
",",
"$",
"data",
")",
"use",
"(",
"$",
"user",
",",
"$",
"ltiidstocmids",
")",
"{",
"$",
"context",
"=",
"\\",
"context_module",
"::",
"instance",
"(",
"$",
"ltiidstocmids",
"[",
"$",
"ltiid",
"]",
")",
";",
"$",
"contextdata",
"=",
"helper",
"::",
"get_context_data",
"(",
"$",
"context",
",",
"$",
"user",
")",
";",
"$",
"finaldata",
"=",
"(",
"object",
")",
"array_merge",
"(",
"(",
"array",
")",
"$",
"contextdata",
",",
"[",
"'submissions'",
"=>",
"$",
"data",
"]",
")",
";",
"helper",
"::",
"export_context_files",
"(",
"$",
"context",
",",
"$",
"user",
")",
";",
"writer",
"::",
"with_context",
"(",
"$",
"context",
")",
"->",
"export_data",
"(",
"[",
"]",
",",
"$",
"finaldata",
")",
";",
"}",
")",
";",
"}"
] |
Export personal data for the given approved_contextlist related to LTI submissions.
@param approved_contextlist $contextlist a list of contexts approved for export.
|
[
"Export",
"personal",
"data",
"for",
"the",
"given",
"approved_contextlist",
"related",
"to",
"LTI",
"submissions",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lti/classes/privacy/provider.php#L293-L332
|
219,468
|
moodle/moodle
|
mod/lti/classes/privacy/provider.php
|
provider.export_user_data_lti_types
|
protected static function export_user_data_lti_types(approved_contextlist $contextlist) {
global $DB;
// Filter out any contexts that are not related to courses.
$courseids = array_reduce($contextlist->get_contexts(), function($carry, $context) {
if ($context->contextlevel == CONTEXT_COURSE) {
$carry[] = $context->instanceid;
}
return $carry;
}, []);
if (empty($courseids)) {
return;
}
$user = $contextlist->get_user();
list($insql, $inparams) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED);
$params = array_merge($inparams, ['userid' => $user->id]);
$ltitypes = $DB->get_recordset_select('lti_types', "course $insql AND createdby = :userid", $params, 'timecreated ASC');
self::recordset_loop_and_export($ltitypes, 'course', [], function($carry, $record) {
$context = \context_course::instance($record->course);
$options = ['context' => $context];
$carry[] = [
'name' => format_string($record->name, true, $options),
'createdby' => transform::user($record->createdby),
'timecreated' => transform::datetime($record->timecreated),
'timemodified' => transform::datetime($record->timemodified)
];
return $carry;
}, function($courseid, $data) {
$context = \context_course::instance($courseid);
$finaldata = (object) ['lti_types' => $data];
writer::with_context($context)->export_data([], $finaldata);
});
}
|
php
|
protected static function export_user_data_lti_types(approved_contextlist $contextlist) {
global $DB;
// Filter out any contexts that are not related to courses.
$courseids = array_reduce($contextlist->get_contexts(), function($carry, $context) {
if ($context->contextlevel == CONTEXT_COURSE) {
$carry[] = $context->instanceid;
}
return $carry;
}, []);
if (empty($courseids)) {
return;
}
$user = $contextlist->get_user();
list($insql, $inparams) = $DB->get_in_or_equal($courseids, SQL_PARAMS_NAMED);
$params = array_merge($inparams, ['userid' => $user->id]);
$ltitypes = $DB->get_recordset_select('lti_types', "course $insql AND createdby = :userid", $params, 'timecreated ASC');
self::recordset_loop_and_export($ltitypes, 'course', [], function($carry, $record) {
$context = \context_course::instance($record->course);
$options = ['context' => $context];
$carry[] = [
'name' => format_string($record->name, true, $options),
'createdby' => transform::user($record->createdby),
'timecreated' => transform::datetime($record->timecreated),
'timemodified' => transform::datetime($record->timemodified)
];
return $carry;
}, function($courseid, $data) {
$context = \context_course::instance($courseid);
$finaldata = (object) ['lti_types' => $data];
writer::with_context($context)->export_data([], $finaldata);
});
}
|
[
"protected",
"static",
"function",
"export_user_data_lti_types",
"(",
"approved_contextlist",
"$",
"contextlist",
")",
"{",
"global",
"$",
"DB",
";",
"// Filter out any contexts that are not related to courses.",
"$",
"courseids",
"=",
"array_reduce",
"(",
"$",
"contextlist",
"->",
"get_contexts",
"(",
")",
",",
"function",
"(",
"$",
"carry",
",",
"$",
"context",
")",
"{",
"if",
"(",
"$",
"context",
"->",
"contextlevel",
"==",
"CONTEXT_COURSE",
")",
"{",
"$",
"carry",
"[",
"]",
"=",
"$",
"context",
"->",
"instanceid",
";",
"}",
"return",
"$",
"carry",
";",
"}",
",",
"[",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"courseids",
")",
")",
"{",
"return",
";",
"}",
"$",
"user",
"=",
"$",
"contextlist",
"->",
"get_user",
"(",
")",
";",
"list",
"(",
"$",
"insql",
",",
"$",
"inparams",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"courseids",
",",
"SQL_PARAMS_NAMED",
")",
";",
"$",
"params",
"=",
"array_merge",
"(",
"$",
"inparams",
",",
"[",
"'userid'",
"=>",
"$",
"user",
"->",
"id",
"]",
")",
";",
"$",
"ltitypes",
"=",
"$",
"DB",
"->",
"get_recordset_select",
"(",
"'lti_types'",
",",
"\"course $insql AND createdby = :userid\"",
",",
"$",
"params",
",",
"'timecreated ASC'",
")",
";",
"self",
"::",
"recordset_loop_and_export",
"(",
"$",
"ltitypes",
",",
"'course'",
",",
"[",
"]",
",",
"function",
"(",
"$",
"carry",
",",
"$",
"record",
")",
"{",
"$",
"context",
"=",
"\\",
"context_course",
"::",
"instance",
"(",
"$",
"record",
"->",
"course",
")",
";",
"$",
"options",
"=",
"[",
"'context'",
"=>",
"$",
"context",
"]",
";",
"$",
"carry",
"[",
"]",
"=",
"[",
"'name'",
"=>",
"format_string",
"(",
"$",
"record",
"->",
"name",
",",
"true",
",",
"$",
"options",
")",
",",
"'createdby'",
"=>",
"transform",
"::",
"user",
"(",
"$",
"record",
"->",
"createdby",
")",
",",
"'timecreated'",
"=>",
"transform",
"::",
"datetime",
"(",
"$",
"record",
"->",
"timecreated",
")",
",",
"'timemodified'",
"=>",
"transform",
"::",
"datetime",
"(",
"$",
"record",
"->",
"timemodified",
")",
"]",
";",
"return",
"$",
"carry",
";",
"}",
",",
"function",
"(",
"$",
"courseid",
",",
"$",
"data",
")",
"{",
"$",
"context",
"=",
"\\",
"context_course",
"::",
"instance",
"(",
"$",
"courseid",
")",
";",
"$",
"finaldata",
"=",
"(",
"object",
")",
"[",
"'lti_types'",
"=>",
"$",
"data",
"]",
";",
"writer",
"::",
"with_context",
"(",
"$",
"context",
")",
"->",
"export_data",
"(",
"[",
"]",
",",
"$",
"finaldata",
")",
";",
"}",
")",
";",
"}"
] |
Export personal data for the given approved_contextlist related to LTI types.
@param approved_contextlist $contextlist a list of contexts approved for export.
|
[
"Export",
"personal",
"data",
"for",
"the",
"given",
"approved_contextlist",
"related",
"to",
"LTI",
"types",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lti/classes/privacy/provider.php#L339-L374
|
219,469
|
moodle/moodle
|
mod/lti/classes/privacy/provider.php
|
provider.export_user_data_lti_tool_proxies
|
protected static function export_user_data_lti_tool_proxies(approved_contextlist $contextlist) {
global $DB;
// Filter out any contexts that are not related to system context.
$systemcontexts = array_filter($contextlist->get_contexts(), function($context) {
return $context->contextlevel == CONTEXT_SYSTEM;
});
if (empty($systemcontexts)) {
return;
}
$user = $contextlist->get_user();
$systemcontext = \context_system::instance();
$data = [];
$ltiproxies = $DB->get_recordset('lti_tool_proxies', ['createdby' => $user->id], 'timecreated ASC');
foreach ($ltiproxies as $ltiproxy) {
$data[] = [
'name' => format_string($ltiproxy->name, true, $systemcontext),
'createdby' => transform::user($ltiproxy->createdby),
'timecreated' => transform::datetime($ltiproxy->timecreated),
'timemodified' => transform::datetime($ltiproxy->timemodified)
];
}
$ltiproxies->close();
$finaldata = (object) ['lti_tool_proxies' => $data];
writer::with_context($systemcontext)->export_data([], $finaldata);
}
|
php
|
protected static function export_user_data_lti_tool_proxies(approved_contextlist $contextlist) {
global $DB;
// Filter out any contexts that are not related to system context.
$systemcontexts = array_filter($contextlist->get_contexts(), function($context) {
return $context->contextlevel == CONTEXT_SYSTEM;
});
if (empty($systemcontexts)) {
return;
}
$user = $contextlist->get_user();
$systemcontext = \context_system::instance();
$data = [];
$ltiproxies = $DB->get_recordset('lti_tool_proxies', ['createdby' => $user->id], 'timecreated ASC');
foreach ($ltiproxies as $ltiproxy) {
$data[] = [
'name' => format_string($ltiproxy->name, true, $systemcontext),
'createdby' => transform::user($ltiproxy->createdby),
'timecreated' => transform::datetime($ltiproxy->timecreated),
'timemodified' => transform::datetime($ltiproxy->timemodified)
];
}
$ltiproxies->close();
$finaldata = (object) ['lti_tool_proxies' => $data];
writer::with_context($systemcontext)->export_data([], $finaldata);
}
|
[
"protected",
"static",
"function",
"export_user_data_lti_tool_proxies",
"(",
"approved_contextlist",
"$",
"contextlist",
")",
"{",
"global",
"$",
"DB",
";",
"// Filter out any contexts that are not related to system context.",
"$",
"systemcontexts",
"=",
"array_filter",
"(",
"$",
"contextlist",
"->",
"get_contexts",
"(",
")",
",",
"function",
"(",
"$",
"context",
")",
"{",
"return",
"$",
"context",
"->",
"contextlevel",
"==",
"CONTEXT_SYSTEM",
";",
"}",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"systemcontexts",
")",
")",
"{",
"return",
";",
"}",
"$",
"user",
"=",
"$",
"contextlist",
"->",
"get_user",
"(",
")",
";",
"$",
"systemcontext",
"=",
"\\",
"context_system",
"::",
"instance",
"(",
")",
";",
"$",
"data",
"=",
"[",
"]",
";",
"$",
"ltiproxies",
"=",
"$",
"DB",
"->",
"get_recordset",
"(",
"'lti_tool_proxies'",
",",
"[",
"'createdby'",
"=>",
"$",
"user",
"->",
"id",
"]",
",",
"'timecreated ASC'",
")",
";",
"foreach",
"(",
"$",
"ltiproxies",
"as",
"$",
"ltiproxy",
")",
"{",
"$",
"data",
"[",
"]",
"=",
"[",
"'name'",
"=>",
"format_string",
"(",
"$",
"ltiproxy",
"->",
"name",
",",
"true",
",",
"$",
"systemcontext",
")",
",",
"'createdby'",
"=>",
"transform",
"::",
"user",
"(",
"$",
"ltiproxy",
"->",
"createdby",
")",
",",
"'timecreated'",
"=>",
"transform",
"::",
"datetime",
"(",
"$",
"ltiproxy",
"->",
"timecreated",
")",
",",
"'timemodified'",
"=>",
"transform",
"::",
"datetime",
"(",
"$",
"ltiproxy",
"->",
"timemodified",
")",
"]",
";",
"}",
"$",
"ltiproxies",
"->",
"close",
"(",
")",
";",
"$",
"finaldata",
"=",
"(",
"object",
")",
"[",
"'lti_tool_proxies'",
"=>",
"$",
"data",
"]",
";",
"writer",
"::",
"with_context",
"(",
"$",
"systemcontext",
")",
"->",
"export_data",
"(",
"[",
"]",
",",
"$",
"finaldata",
")",
";",
"}"
] |
Export personal data for the given approved_contextlist related to LTI tool proxies.
@param approved_contextlist $contextlist a list of contexts approved for export.
|
[
"Export",
"personal",
"data",
"for",
"the",
"given",
"approved_contextlist",
"related",
"to",
"LTI",
"tool",
"proxies",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lti/classes/privacy/provider.php#L381-L411
|
219,470
|
moodle/moodle
|
admin/tool/analytics/classes/output/restorable_models.php
|
restorable_models.export_for_template
|
public function export_for_template(\renderer_base $output) {
$components = [];
foreach ($this->models as $componentname => $modelslist) {
$component = [
'name' => $this->component_name($componentname),
'component' => $componentname,
'models' => [],
];
foreach ($modelslist as $definition) {
list($target, $indicators) = \core_analytics\manager::get_declared_target_and_indicators_instances($definition);
if (\core_analytics\model::exists($target, $indicators)) {
continue;
}
$targetnamelangstring = $target->get_name();
$model = [
'defid' => \core_analytics\manager::model_declaration_identifier($definition),
'targetname' => $targetnamelangstring,
'targetclass' => $definition['target'],
'indicatorsnum' => count($definition['indicators']),
'indicators' => [],
];
if (get_string_manager()->string_exists($targetnamelangstring->get_identifier().'_help',
$targetnamelangstring->get_component())) {
$helpicon = new \help_icon($targetnamelangstring->get_identifier(), $targetnamelangstring->get_component());
$model['targethelp'] = $helpicon->export_for_template($output);
}
foreach ($indicators as $indicator) {
$indicatornamelangstring = $indicator->get_name();
$indicatordata = [
'name' => $indicatornamelangstring,
'classname' => $indicator->get_id(),
];
if (get_string_manager()->string_exists($indicatornamelangstring->get_identifier().'_help',
$indicatornamelangstring->get_component())) {
$helpicon = new \help_icon($indicatornamelangstring->get_identifier(),
$indicatornamelangstring->get_component());
$indicatordata['indicatorhelp'] = $helpicon->export_for_template($output);
}
$model['indicators'][] = $indicatordata;
}
$component['models'][] = $model;
}
if (!empty($component['models'])) {
$components[] = $component;
}
}
$result = [
'hasdata' => !empty($components),
'components' => array_values($components),
'submiturl' => new \moodle_url('/admin/tool/analytics/restoredefault.php'),
'backurl' => new \moodle_url('/admin/tool/analytics/index.php'),
'sesskey' => sesskey(),
];
return $result;
}
|
php
|
public function export_for_template(\renderer_base $output) {
$components = [];
foreach ($this->models as $componentname => $modelslist) {
$component = [
'name' => $this->component_name($componentname),
'component' => $componentname,
'models' => [],
];
foreach ($modelslist as $definition) {
list($target, $indicators) = \core_analytics\manager::get_declared_target_and_indicators_instances($definition);
if (\core_analytics\model::exists($target, $indicators)) {
continue;
}
$targetnamelangstring = $target->get_name();
$model = [
'defid' => \core_analytics\manager::model_declaration_identifier($definition),
'targetname' => $targetnamelangstring,
'targetclass' => $definition['target'],
'indicatorsnum' => count($definition['indicators']),
'indicators' => [],
];
if (get_string_manager()->string_exists($targetnamelangstring->get_identifier().'_help',
$targetnamelangstring->get_component())) {
$helpicon = new \help_icon($targetnamelangstring->get_identifier(), $targetnamelangstring->get_component());
$model['targethelp'] = $helpicon->export_for_template($output);
}
foreach ($indicators as $indicator) {
$indicatornamelangstring = $indicator->get_name();
$indicatordata = [
'name' => $indicatornamelangstring,
'classname' => $indicator->get_id(),
];
if (get_string_manager()->string_exists($indicatornamelangstring->get_identifier().'_help',
$indicatornamelangstring->get_component())) {
$helpicon = new \help_icon($indicatornamelangstring->get_identifier(),
$indicatornamelangstring->get_component());
$indicatordata['indicatorhelp'] = $helpicon->export_for_template($output);
}
$model['indicators'][] = $indicatordata;
}
$component['models'][] = $model;
}
if (!empty($component['models'])) {
$components[] = $component;
}
}
$result = [
'hasdata' => !empty($components),
'components' => array_values($components),
'submiturl' => new \moodle_url('/admin/tool/analytics/restoredefault.php'),
'backurl' => new \moodle_url('/admin/tool/analytics/index.php'),
'sesskey' => sesskey(),
];
return $result;
}
|
[
"public",
"function",
"export_for_template",
"(",
"\\",
"renderer_base",
"$",
"output",
")",
"{",
"$",
"components",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"models",
"as",
"$",
"componentname",
"=>",
"$",
"modelslist",
")",
"{",
"$",
"component",
"=",
"[",
"'name'",
"=>",
"$",
"this",
"->",
"component_name",
"(",
"$",
"componentname",
")",
",",
"'component'",
"=>",
"$",
"componentname",
",",
"'models'",
"=>",
"[",
"]",
",",
"]",
";",
"foreach",
"(",
"$",
"modelslist",
"as",
"$",
"definition",
")",
"{",
"list",
"(",
"$",
"target",
",",
"$",
"indicators",
")",
"=",
"\\",
"core_analytics",
"\\",
"manager",
"::",
"get_declared_target_and_indicators_instances",
"(",
"$",
"definition",
")",
";",
"if",
"(",
"\\",
"core_analytics",
"\\",
"model",
"::",
"exists",
"(",
"$",
"target",
",",
"$",
"indicators",
")",
")",
"{",
"continue",
";",
"}",
"$",
"targetnamelangstring",
"=",
"$",
"target",
"->",
"get_name",
"(",
")",
";",
"$",
"model",
"=",
"[",
"'defid'",
"=>",
"\\",
"core_analytics",
"\\",
"manager",
"::",
"model_declaration_identifier",
"(",
"$",
"definition",
")",
",",
"'targetname'",
"=>",
"$",
"targetnamelangstring",
",",
"'targetclass'",
"=>",
"$",
"definition",
"[",
"'target'",
"]",
",",
"'indicatorsnum'",
"=>",
"count",
"(",
"$",
"definition",
"[",
"'indicators'",
"]",
")",
",",
"'indicators'",
"=>",
"[",
"]",
",",
"]",
";",
"if",
"(",
"get_string_manager",
"(",
")",
"->",
"string_exists",
"(",
"$",
"targetnamelangstring",
"->",
"get_identifier",
"(",
")",
".",
"'_help'",
",",
"$",
"targetnamelangstring",
"->",
"get_component",
"(",
")",
")",
")",
"{",
"$",
"helpicon",
"=",
"new",
"\\",
"help_icon",
"(",
"$",
"targetnamelangstring",
"->",
"get_identifier",
"(",
")",
",",
"$",
"targetnamelangstring",
"->",
"get_component",
"(",
")",
")",
";",
"$",
"model",
"[",
"'targethelp'",
"]",
"=",
"$",
"helpicon",
"->",
"export_for_template",
"(",
"$",
"output",
")",
";",
"}",
"foreach",
"(",
"$",
"indicators",
"as",
"$",
"indicator",
")",
"{",
"$",
"indicatornamelangstring",
"=",
"$",
"indicator",
"->",
"get_name",
"(",
")",
";",
"$",
"indicatordata",
"=",
"[",
"'name'",
"=>",
"$",
"indicatornamelangstring",
",",
"'classname'",
"=>",
"$",
"indicator",
"->",
"get_id",
"(",
")",
",",
"]",
";",
"if",
"(",
"get_string_manager",
"(",
")",
"->",
"string_exists",
"(",
"$",
"indicatornamelangstring",
"->",
"get_identifier",
"(",
")",
".",
"'_help'",
",",
"$",
"indicatornamelangstring",
"->",
"get_component",
"(",
")",
")",
")",
"{",
"$",
"helpicon",
"=",
"new",
"\\",
"help_icon",
"(",
"$",
"indicatornamelangstring",
"->",
"get_identifier",
"(",
")",
",",
"$",
"indicatornamelangstring",
"->",
"get_component",
"(",
")",
")",
";",
"$",
"indicatordata",
"[",
"'indicatorhelp'",
"]",
"=",
"$",
"helpicon",
"->",
"export_for_template",
"(",
"$",
"output",
")",
";",
"}",
"$",
"model",
"[",
"'indicators'",
"]",
"[",
"]",
"=",
"$",
"indicatordata",
";",
"}",
"$",
"component",
"[",
"'models'",
"]",
"[",
"]",
"=",
"$",
"model",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"component",
"[",
"'models'",
"]",
")",
")",
"{",
"$",
"components",
"[",
"]",
"=",
"$",
"component",
";",
"}",
"}",
"$",
"result",
"=",
"[",
"'hasdata'",
"=>",
"!",
"empty",
"(",
"$",
"components",
")",
",",
"'components'",
"=>",
"array_values",
"(",
"$",
"components",
")",
",",
"'submiturl'",
"=>",
"new",
"\\",
"moodle_url",
"(",
"'/admin/tool/analytics/restoredefault.php'",
")",
",",
"'backurl'",
"=>",
"new",
"\\",
"moodle_url",
"(",
"'/admin/tool/analytics/index.php'",
")",
",",
"'sesskey'",
"=>",
"sesskey",
"(",
")",
",",
"]",
";",
"return",
"$",
"result",
";",
"}"
] |
Export the list of models to be rendered.
@param renderer_base $output
@return string
|
[
"Export",
"the",
"list",
"of",
"models",
"to",
"be",
"rendered",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/analytics/classes/output/restorable_models.php#L57-L125
|
219,471
|
moodle/moodle
|
admin/tool/analytics/classes/output/restorable_models.php
|
restorable_models.component_name
|
protected function component_name(string $component): string {
if ($component === 'core' || strpos($component, 'core_')) {
return get_string('componentcore', 'tool_analytics');
} else {
return get_string('pluginname', $component);
}
}
|
php
|
protected function component_name(string $component): string {
if ($component === 'core' || strpos($component, 'core_')) {
return get_string('componentcore', 'tool_analytics');
} else {
return get_string('pluginname', $component);
}
}
|
[
"protected",
"function",
"component_name",
"(",
"string",
"$",
"component",
")",
":",
"string",
"{",
"if",
"(",
"$",
"component",
"===",
"'core'",
"||",
"strpos",
"(",
"$",
"component",
",",
"'core_'",
")",
")",
"{",
"return",
"get_string",
"(",
"'componentcore'",
",",
"'tool_analytics'",
")",
";",
"}",
"else",
"{",
"return",
"get_string",
"(",
"'pluginname'",
",",
"$",
"component",
")",
";",
"}",
"}"
] |
Return a human readable name for the given frankenstyle component.
@param string $component Frankenstyle component such as 'core', 'core_analytics' or 'mod_workshop'
@return string Human readable name of the component
|
[
"Return",
"a",
"human",
"readable",
"name",
"for",
"the",
"given",
"frankenstyle",
"component",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/analytics/classes/output/restorable_models.php#L133-L141
|
219,472
|
moodle/moodle
|
customfield/classes/data_controller.php
|
data_controller.create
|
public static function create(int $id, \stdClass $record = null, field_controller $field = null) : data_controller {
global $DB;
if ($id && $record) {
// This warning really should be in persistent as well.
debugging('Too many parameters, either id need to be specified or a record, but not both.',
DEBUG_DEVELOPER);
}
if ($id) {
$record = $DB->get_record(data::TABLE, array('id' => $id), '*', MUST_EXIST);
} else if (!$record) {
$record = new \stdClass();
}
if (!$field && empty($record->fieldid)) {
throw new \coding_exception('Not enough parameters to initialise data_controller - unknown field');
}
if (!$field) {
$field = field_controller::create($record->fieldid);
}
if (empty($record->fieldid)) {
$record->fieldid = $field->get('id');
}
if ($field->get('id') != $record->fieldid) {
throw new \coding_exception('Field id from the record does not match field from the parameter');
}
$type = $field->get('type');
$customfieldtype = "\\customfield_{$type}\\data_controller";
if (!class_exists($customfieldtype) || !is_subclass_of($customfieldtype, self::class)) {
throw new \moodle_exception('errorfieldtypenotfound', 'core_customfield', '', s($type));
}
$datacontroller = new $customfieldtype(0, $record);
$datacontroller->field = $field;
return $datacontroller;
}
|
php
|
public static function create(int $id, \stdClass $record = null, field_controller $field = null) : data_controller {
global $DB;
if ($id && $record) {
// This warning really should be in persistent as well.
debugging('Too many parameters, either id need to be specified or a record, but not both.',
DEBUG_DEVELOPER);
}
if ($id) {
$record = $DB->get_record(data::TABLE, array('id' => $id), '*', MUST_EXIST);
} else if (!$record) {
$record = new \stdClass();
}
if (!$field && empty($record->fieldid)) {
throw new \coding_exception('Not enough parameters to initialise data_controller - unknown field');
}
if (!$field) {
$field = field_controller::create($record->fieldid);
}
if (empty($record->fieldid)) {
$record->fieldid = $field->get('id');
}
if ($field->get('id') != $record->fieldid) {
throw new \coding_exception('Field id from the record does not match field from the parameter');
}
$type = $field->get('type');
$customfieldtype = "\\customfield_{$type}\\data_controller";
if (!class_exists($customfieldtype) || !is_subclass_of($customfieldtype, self::class)) {
throw new \moodle_exception('errorfieldtypenotfound', 'core_customfield', '', s($type));
}
$datacontroller = new $customfieldtype(0, $record);
$datacontroller->field = $field;
return $datacontroller;
}
|
[
"public",
"static",
"function",
"create",
"(",
"int",
"$",
"id",
",",
"\\",
"stdClass",
"$",
"record",
"=",
"null",
",",
"field_controller",
"$",
"field",
"=",
"null",
")",
":",
"data_controller",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"$",
"id",
"&&",
"$",
"record",
")",
"{",
"// This warning really should be in persistent as well.",
"debugging",
"(",
"'Too many parameters, either id need to be specified or a record, but not both.'",
",",
"DEBUG_DEVELOPER",
")",
";",
"}",
"if",
"(",
"$",
"id",
")",
"{",
"$",
"record",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"data",
"::",
"TABLE",
",",
"array",
"(",
"'id'",
"=>",
"$",
"id",
")",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"}",
"else",
"if",
"(",
"!",
"$",
"record",
")",
"{",
"$",
"record",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"field",
"&&",
"empty",
"(",
"$",
"record",
"->",
"fieldid",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Not enough parameters to initialise data_controller - unknown field'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"field",
")",
"{",
"$",
"field",
"=",
"field_controller",
"::",
"create",
"(",
"$",
"record",
"->",
"fieldid",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"record",
"->",
"fieldid",
")",
")",
"{",
"$",
"record",
"->",
"fieldid",
"=",
"$",
"field",
"->",
"get",
"(",
"'id'",
")",
";",
"}",
"if",
"(",
"$",
"field",
"->",
"get",
"(",
"'id'",
")",
"!=",
"$",
"record",
"->",
"fieldid",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'Field id from the record does not match field from the parameter'",
")",
";",
"}",
"$",
"type",
"=",
"$",
"field",
"->",
"get",
"(",
"'type'",
")",
";",
"$",
"customfieldtype",
"=",
"\"\\\\customfield_{$type}\\\\data_controller\"",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"customfieldtype",
")",
"||",
"!",
"is_subclass_of",
"(",
"$",
"customfieldtype",
",",
"self",
"::",
"class",
")",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'errorfieldtypenotfound'",
",",
"'core_customfield'",
",",
"''",
",",
"s",
"(",
"$",
"type",
")",
")",
";",
"}",
"$",
"datacontroller",
"=",
"new",
"$",
"customfieldtype",
"(",
"0",
",",
"$",
"record",
")",
";",
"$",
"datacontroller",
"->",
"field",
"=",
"$",
"field",
";",
"return",
"$",
"datacontroller",
";",
"}"
] |
Creates an instance of data_controller
Parameters $id, $record and $field can complement each other but not conflict.
If $id is not specified, fieldid must be present either in $record or in $field.
If $id is not specified, instanceid must be present in $record
No DB queries are performed if both $record and $field are specified.
@param int $id
@param \stdClass|null $record
@param field_controller|null $field
@return data_controller
@throws \coding_exception
@throws \moodle_exception
|
[
"Creates",
"an",
"instance",
"of",
"data_controller"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/data_controller.php#L85-L118
|
219,473
|
moodle/moodle
|
customfield/classes/data_controller.php
|
data_controller.is_empty
|
protected function is_empty($value) : bool {
if ($this->datafield() === 'value' || $this->datafield() === 'charvalue' || $this->datafield() === 'shortcharvalue') {
return '' . $value === '';
}
return empty($value);
}
|
php
|
protected function is_empty($value) : bool {
if ($this->datafield() === 'value' || $this->datafield() === 'charvalue' || $this->datafield() === 'shortcharvalue') {
return '' . $value === '';
}
return empty($value);
}
|
[
"protected",
"function",
"is_empty",
"(",
"$",
"value",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"this",
"->",
"datafield",
"(",
")",
"===",
"'value'",
"||",
"$",
"this",
"->",
"datafield",
"(",
")",
"===",
"'charvalue'",
"||",
"$",
"this",
"->",
"datafield",
"(",
")",
"===",
"'shortcharvalue'",
")",
"{",
"return",
"''",
".",
"$",
"value",
"===",
"''",
";",
"}",
"return",
"empty",
"(",
"$",
"value",
")",
";",
"}"
] |
Checks if the value is empty
@param mixed $value
@return bool
|
[
"Checks",
"if",
"the",
"value",
"is",
"empty"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/data_controller.php#L226-L231
|
219,474
|
moodle/moodle
|
customfield/classes/data_controller.php
|
data_controller.is_unique
|
protected function is_unique($value) : bool {
global $DB;
$datafield = $this->datafield();
$where = "fieldid = ? AND {$datafield} = ?";
$params = [$this->get_field()->get('id'), $value];
if ($this->get('id')) {
$where .= ' AND id <> ?';
$params[] = $this->get('id');
}
return !$DB->record_exists_select('customfield_data', $where, $params);
}
|
php
|
protected function is_unique($value) : bool {
global $DB;
$datafield = $this->datafield();
$where = "fieldid = ? AND {$datafield} = ?";
$params = [$this->get_field()->get('id'), $value];
if ($this->get('id')) {
$where .= ' AND id <> ?';
$params[] = $this->get('id');
}
return !$DB->record_exists_select('customfield_data', $where, $params);
}
|
[
"protected",
"function",
"is_unique",
"(",
"$",
"value",
")",
":",
"bool",
"{",
"global",
"$",
"DB",
";",
"$",
"datafield",
"=",
"$",
"this",
"->",
"datafield",
"(",
")",
";",
"$",
"where",
"=",
"\"fieldid = ? AND {$datafield} = ?\"",
";",
"$",
"params",
"=",
"[",
"$",
"this",
"->",
"get_field",
"(",
")",
"->",
"get",
"(",
"'id'",
")",
",",
"$",
"value",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
")",
"{",
"$",
"where",
".=",
"' AND id <> ?'",
";",
"$",
"params",
"[",
"]",
"=",
"$",
"this",
"->",
"get",
"(",
"'id'",
")",
";",
"}",
"return",
"!",
"$",
"DB",
"->",
"record_exists_select",
"(",
"'customfield_data'",
",",
"$",
"where",
",",
"$",
"params",
")",
";",
"}"
] |
Checks if the value is unique
@param mixed $value
@return bool
|
[
"Checks",
"if",
"the",
"value",
"is",
"unique"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/data_controller.php#L239-L249
|
219,475
|
moodle/moodle
|
customfield/classes/data_controller.php
|
data_controller.display
|
public function display() : string {
global $PAGE;
$output = $PAGE->get_renderer('core_customfield');
return $output->render(new field_data($this));
}
|
php
|
public function display() : string {
global $PAGE;
$output = $PAGE->get_renderer('core_customfield');
return $output->render(new field_data($this));
}
|
[
"public",
"function",
"display",
"(",
")",
":",
"string",
"{",
"global",
"$",
"PAGE",
";",
"$",
"output",
"=",
"$",
"PAGE",
"->",
"get_renderer",
"(",
"'core_customfield'",
")",
";",
"return",
"$",
"output",
"->",
"render",
"(",
"new",
"field_data",
"(",
"$",
"this",
")",
")",
";",
"}"
] |
Used by handlers to display data on various places.
@return string
|
[
"Used",
"by",
"handlers",
"to",
"display",
"data",
"on",
"various",
"places",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/data_controller.php#L284-L288
|
219,476
|
moodle/moodle
|
customfield/classes/data_controller.php
|
data_controller.get_context
|
public function get_context() : \context {
if ($this->get('contextid')) {
return \context::instance_by_id($this->get('contextid'));
} else if ($this->get('instanceid')) {
return $this->get_field()->get_handler()->get_instance_context($this->get('instanceid'));
} else {
// Context is not yet known (for example, entity is not yet created).
return \context_system::instance();
}
}
|
php
|
public function get_context() : \context {
if ($this->get('contextid')) {
return \context::instance_by_id($this->get('contextid'));
} else if ($this->get('instanceid')) {
return $this->get_field()->get_handler()->get_instance_context($this->get('instanceid'));
} else {
// Context is not yet known (for example, entity is not yet created).
return \context_system::instance();
}
}
|
[
"public",
"function",
"get_context",
"(",
")",
":",
"\\",
"context",
"{",
"if",
"(",
"$",
"this",
"->",
"get",
"(",
"'contextid'",
")",
")",
"{",
"return",
"\\",
"context",
"::",
"instance_by_id",
"(",
"$",
"this",
"->",
"get",
"(",
"'contextid'",
")",
")",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"get",
"(",
"'instanceid'",
")",
")",
"{",
"return",
"$",
"this",
"->",
"get_field",
"(",
")",
"->",
"get_handler",
"(",
")",
"->",
"get_instance_context",
"(",
"$",
"this",
"->",
"get",
"(",
"'instanceid'",
")",
")",
";",
"}",
"else",
"{",
"// Context is not yet known (for example, entity is not yet created).",
"return",
"\\",
"context_system",
"::",
"instance",
"(",
")",
";",
"}",
"}"
] |
Return the context of the field
@return \context
|
[
"Return",
"the",
"context",
"of",
"the",
"field"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/data_controller.php#L314-L323
|
219,477
|
moodle/moodle
|
customfield/classes/data_controller.php
|
data_controller.export_value
|
public function export_value() {
$value = $this->get_value();
if ($this->is_empty($value)) {
return null;
}
if ($this->datafield() === 'intvalue') {
return (int)$value;
} else if ($this->datafield() === 'decvalue') {
return (float)$value;
} else if ($this->datafield() === 'value') {
return format_text($value, $this->get('valueformat'), ['context' => $this->get_context()]);
} else {
return format_string($value, true, ['context' => $this->get_context()]);
}
}
|
php
|
public function export_value() {
$value = $this->get_value();
if ($this->is_empty($value)) {
return null;
}
if ($this->datafield() === 'intvalue') {
return (int)$value;
} else if ($this->datafield() === 'decvalue') {
return (float)$value;
} else if ($this->datafield() === 'value') {
return format_text($value, $this->get('valueformat'), ['context' => $this->get_context()]);
} else {
return format_string($value, true, ['context' => $this->get_context()]);
}
}
|
[
"public",
"function",
"export_value",
"(",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"get_value",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"is_empty",
"(",
"$",
"value",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"datafield",
"(",
")",
"===",
"'intvalue'",
")",
"{",
"return",
"(",
"int",
")",
"$",
"value",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"datafield",
"(",
")",
"===",
"'decvalue'",
")",
"{",
"return",
"(",
"float",
")",
"$",
"value",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"datafield",
"(",
")",
"===",
"'value'",
")",
"{",
"return",
"format_text",
"(",
"$",
"value",
",",
"$",
"this",
"->",
"get",
"(",
"'valueformat'",
")",
",",
"[",
"'context'",
"=>",
"$",
"this",
"->",
"get_context",
"(",
")",
"]",
")",
";",
"}",
"else",
"{",
"return",
"format_string",
"(",
"$",
"value",
",",
"true",
",",
"[",
"'context'",
"=>",
"$",
"this",
"->",
"get_context",
"(",
")",
"]",
")",
";",
"}",
"}"
] |
Returns value in a human-readable format or default value if data record is not present
This is the default implementation that most likely needs to be overridden
@return mixed|null value or null if empty
|
[
"Returns",
"value",
"in",
"a",
"human",
"-",
"readable",
"format",
"or",
"default",
"value",
"if",
"data",
"record",
"is",
"not",
"present"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/data_controller.php#L339-L355
|
219,478
|
moodle/moodle
|
availability/classes/info_module.php
|
info_module.is_user_visible
|
public static function is_user_visible($cmorid, $userid = 0, $checkcourse = true) {
global $USER, $DB, $CFG;
// Evaluate user id.
if (!$userid) {
$userid = $USER->id;
}
// If this happens to be already called with a cm_info for the right user
// then just return uservisible.
if (($cmorid instanceof \cm_info) && $cmorid->get_modinfo()->userid == $userid) {
return $cmorid->uservisible;
}
// If the $cmorid isn't an object or doesn't have required fields, load it.
if (is_object($cmorid) && isset($cmorid->course) && isset($cmorid->visible)) {
$cm = $cmorid;
} else {
if (is_object($cmorid)) {
$cmorid = $cmorid->id;
}
$cm = $DB->get_record('course_modules', array('id' => $cmorid));
if (!$cm) {
// In some error cases, the course module may not exist.
debugging('info_module::is_user_visible called with invalid cmid ' . $cmorid, DEBUG_DEVELOPER);
return false;
}
}
// If requested, check user can access the course.
if ($checkcourse) {
$coursecontext = \context_course::instance($cm->course);
if (!is_enrolled($coursecontext, $userid, '', true) &&
!has_capability('moodle/course:view', $coursecontext, $userid)) {
return false;
}
}
// If availability is disabled, then all we need to do is check the visible flag.
if (!$CFG->enableavailability && $cm->visible) {
return true;
}
// When availability is enabled, access can depend on 3 things:
// 1. $cm->visible
// 2. $cm->availability
// 3. $section->availability (for activity section and possibly for
// parent sections)
// As a result we cannot take short cuts any longer and must get
// standard modinfo.
$modinfo = get_fast_modinfo($cm->course, $userid);
$cms = $modinfo->get_cms();
if (!isset($cms[$cm->id])) {
// In some cases this might get called with a cmid that is no longer
// available, for example when a module is hidden at system level.
debugging('info_module::is_user_visible called with invalid cmid ' . $cm->id, DEBUG_DEVELOPER);
return false;
}
return $cms[$cm->id]->uservisible;
}
|
php
|
public static function is_user_visible($cmorid, $userid = 0, $checkcourse = true) {
global $USER, $DB, $CFG;
// Evaluate user id.
if (!$userid) {
$userid = $USER->id;
}
// If this happens to be already called with a cm_info for the right user
// then just return uservisible.
if (($cmorid instanceof \cm_info) && $cmorid->get_modinfo()->userid == $userid) {
return $cmorid->uservisible;
}
// If the $cmorid isn't an object or doesn't have required fields, load it.
if (is_object($cmorid) && isset($cmorid->course) && isset($cmorid->visible)) {
$cm = $cmorid;
} else {
if (is_object($cmorid)) {
$cmorid = $cmorid->id;
}
$cm = $DB->get_record('course_modules', array('id' => $cmorid));
if (!$cm) {
// In some error cases, the course module may not exist.
debugging('info_module::is_user_visible called with invalid cmid ' . $cmorid, DEBUG_DEVELOPER);
return false;
}
}
// If requested, check user can access the course.
if ($checkcourse) {
$coursecontext = \context_course::instance($cm->course);
if (!is_enrolled($coursecontext, $userid, '', true) &&
!has_capability('moodle/course:view', $coursecontext, $userid)) {
return false;
}
}
// If availability is disabled, then all we need to do is check the visible flag.
if (!$CFG->enableavailability && $cm->visible) {
return true;
}
// When availability is enabled, access can depend on 3 things:
// 1. $cm->visible
// 2. $cm->availability
// 3. $section->availability (for activity section and possibly for
// parent sections)
// As a result we cannot take short cuts any longer and must get
// standard modinfo.
$modinfo = get_fast_modinfo($cm->course, $userid);
$cms = $modinfo->get_cms();
if (!isset($cms[$cm->id])) {
// In some cases this might get called with a cmid that is no longer
// available, for example when a module is hidden at system level.
debugging('info_module::is_user_visible called with invalid cmid ' . $cm->id, DEBUG_DEVELOPER);
return false;
}
return $cms[$cm->id]->uservisible;
}
|
[
"public",
"static",
"function",
"is_user_visible",
"(",
"$",
"cmorid",
",",
"$",
"userid",
"=",
"0",
",",
"$",
"checkcourse",
"=",
"true",
")",
"{",
"global",
"$",
"USER",
",",
"$",
"DB",
",",
"$",
"CFG",
";",
"// Evaluate user id.",
"if",
"(",
"!",
"$",
"userid",
")",
"{",
"$",
"userid",
"=",
"$",
"USER",
"->",
"id",
";",
"}",
"// If this happens to be already called with a cm_info for the right user",
"// then just return uservisible.",
"if",
"(",
"(",
"$",
"cmorid",
"instanceof",
"\\",
"cm_info",
")",
"&&",
"$",
"cmorid",
"->",
"get_modinfo",
"(",
")",
"->",
"userid",
"==",
"$",
"userid",
")",
"{",
"return",
"$",
"cmorid",
"->",
"uservisible",
";",
"}",
"// If the $cmorid isn't an object or doesn't have required fields, load it.",
"if",
"(",
"is_object",
"(",
"$",
"cmorid",
")",
"&&",
"isset",
"(",
"$",
"cmorid",
"->",
"course",
")",
"&&",
"isset",
"(",
"$",
"cmorid",
"->",
"visible",
")",
")",
"{",
"$",
"cm",
"=",
"$",
"cmorid",
";",
"}",
"else",
"{",
"if",
"(",
"is_object",
"(",
"$",
"cmorid",
")",
")",
"{",
"$",
"cmorid",
"=",
"$",
"cmorid",
"->",
"id",
";",
"}",
"$",
"cm",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'course_modules'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"cmorid",
")",
")",
";",
"if",
"(",
"!",
"$",
"cm",
")",
"{",
"// In some error cases, the course module may not exist.",
"debugging",
"(",
"'info_module::is_user_visible called with invalid cmid '",
".",
"$",
"cmorid",
",",
"DEBUG_DEVELOPER",
")",
";",
"return",
"false",
";",
"}",
"}",
"// If requested, check user can access the course.",
"if",
"(",
"$",
"checkcourse",
")",
"{",
"$",
"coursecontext",
"=",
"\\",
"context_course",
"::",
"instance",
"(",
"$",
"cm",
"->",
"course",
")",
";",
"if",
"(",
"!",
"is_enrolled",
"(",
"$",
"coursecontext",
",",
"$",
"userid",
",",
"''",
",",
"true",
")",
"&&",
"!",
"has_capability",
"(",
"'moodle/course:view'",
",",
"$",
"coursecontext",
",",
"$",
"userid",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"// If availability is disabled, then all we need to do is check the visible flag.",
"if",
"(",
"!",
"$",
"CFG",
"->",
"enableavailability",
"&&",
"$",
"cm",
"->",
"visible",
")",
"{",
"return",
"true",
";",
"}",
"// When availability is enabled, access can depend on 3 things:",
"// 1. $cm->visible",
"// 2. $cm->availability",
"// 3. $section->availability (for activity section and possibly for",
"// parent sections)",
"// As a result we cannot take short cuts any longer and must get",
"// standard modinfo.",
"$",
"modinfo",
"=",
"get_fast_modinfo",
"(",
"$",
"cm",
"->",
"course",
",",
"$",
"userid",
")",
";",
"$",
"cms",
"=",
"$",
"modinfo",
"->",
"get_cms",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"cms",
"[",
"$",
"cm",
"->",
"id",
"]",
")",
")",
"{",
"// In some cases this might get called with a cmid that is no longer",
"// available, for example when a module is hidden at system level.",
"debugging",
"(",
"'info_module::is_user_visible called with invalid cmid '",
".",
"$",
"cm",
"->",
"id",
",",
"DEBUG_DEVELOPER",
")",
";",
"return",
"false",
";",
"}",
"return",
"$",
"cms",
"[",
"$",
"cm",
"->",
"id",
"]",
"->",
"uservisible",
";",
"}"
] |
Checks if an activity is visible to the given user.
Unlike other checks in the availability system, this check includes the
$cm->visible flag. It is equivalent to $cm->uservisible.
If you have already checked (or do not care whether) the user has access
to the course, you can set $checkcourse to false to save it checking
course access.
When checking for the current user, you should generally not call
this function. Instead, use get_fast_modinfo to get a cm_info object,
then simply check the $cm->uservisible flag. This function is intended
to obtain that information for a separate course-module object that
wasn't loaded with get_fast_modinfo, or for a different user.
This function has a performance cost unless the availability system is
disabled, and you supply a $cm object with necessary fields, and you
don't check course access.
@param int|\stdClass|\cm_info $cmorid Object or id representing activity
@param int $userid User id (0 = current user)
@param bool $checkcourse If true, checks whether the user has course access
@return bool True if the activity is visible to the specified user
@throws \moodle_exception If the cmid doesn't exist
|
[
"Checks",
"if",
"an",
"activity",
"is",
"visible",
"to",
"the",
"given",
"user",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/availability/classes/info_module.php#L166-L225
|
219,479
|
moodle/moodle
|
lib/portfoliolib.php
|
portfolio_add_button.set_callback_options
|
public function set_callback_options($class, array $argarray, $component) {
global $CFG;
// Require the base class first before any other files.
require_once($CFG->libdir . '/portfolio/caller.php');
// Include any potential callback files and check for errors.
portfolio_include_callback_file($component, $class);
// This will throw exceptions but should not actually do anything other than verify callbackargs.
$test = new $class($argarray);
unset($test);
$this->callbackcomponent = $component;
$this->callbackclass = $class;
$this->callbackargs = $argarray;
}
|
php
|
public function set_callback_options($class, array $argarray, $component) {
global $CFG;
// Require the base class first before any other files.
require_once($CFG->libdir . '/portfolio/caller.php');
// Include any potential callback files and check for errors.
portfolio_include_callback_file($component, $class);
// This will throw exceptions but should not actually do anything other than verify callbackargs.
$test = new $class($argarray);
unset($test);
$this->callbackcomponent = $component;
$this->callbackclass = $class;
$this->callbackargs = $argarray;
}
|
[
"public",
"function",
"set_callback_options",
"(",
"$",
"class",
",",
"array",
"$",
"argarray",
",",
"$",
"component",
")",
"{",
"global",
"$",
"CFG",
";",
"// Require the base class first before any other files.",
"require_once",
"(",
"$",
"CFG",
"->",
"libdir",
".",
"'/portfolio/caller.php'",
")",
";",
"// Include any potential callback files and check for errors.",
"portfolio_include_callback_file",
"(",
"$",
"component",
",",
"$",
"class",
")",
";",
"// This will throw exceptions but should not actually do anything other than verify callbackargs.",
"$",
"test",
"=",
"new",
"$",
"class",
"(",
"$",
"argarray",
")",
";",
"unset",
"(",
"$",
"test",
")",
";",
"$",
"this",
"->",
"callbackcomponent",
"=",
"$",
"component",
";",
"$",
"this",
"->",
"callbackclass",
"=",
"$",
"class",
";",
"$",
"this",
"->",
"callbackargs",
"=",
"$",
"argarray",
";",
"}"
] |
Function to set the callback options
@param string $class Name of the class containing the callback functions
activity components should ALWAYS use their name_portfolio_caller
other locations must use something unique
@param array $argarray This can be an array or hash of arguments to pass
back to the callback functions (passed by reference)
these MUST be primatives to be added as hidden form fields.
and the values get cleaned to PARAM_ALPHAEXT or PARAM_FLOAT or PARAM_PATH
@param string $component This is the name of the component in Moodle, eg 'mod_forum'
|
[
"Function",
"to",
"set",
"the",
"callback",
"options"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfoliolib.php#L153-L169
|
219,480
|
moodle/moodle
|
lib/portfoliolib.php
|
portfolio_add_button.set_format_by_file
|
public function set_format_by_file(stored_file $file, $extraformats=null) {
$this->file = $file;
$fileformat = portfolio_format_from_mimetype($file->get_mimetype());
if (is_string($extraformats)) {
$extraformats = array($extraformats);
} else if (!is_array($extraformats)) {
$extraformats = array();
}
$this->set_formats(array_merge(array($fileformat), $extraformats));
}
|
php
|
public function set_format_by_file(stored_file $file, $extraformats=null) {
$this->file = $file;
$fileformat = portfolio_format_from_mimetype($file->get_mimetype());
if (is_string($extraformats)) {
$extraformats = array($extraformats);
} else if (!is_array($extraformats)) {
$extraformats = array();
}
$this->set_formats(array_merge(array($fileformat), $extraformats));
}
|
[
"public",
"function",
"set_format_by_file",
"(",
"stored_file",
"$",
"file",
",",
"$",
"extraformats",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"file",
"=",
"$",
"file",
";",
"$",
"fileformat",
"=",
"portfolio_format_from_mimetype",
"(",
"$",
"file",
"->",
"get_mimetype",
"(",
")",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"extraformats",
")",
")",
"{",
"$",
"extraformats",
"=",
"array",
"(",
"$",
"extraformats",
")",
";",
"}",
"else",
"if",
"(",
"!",
"is_array",
"(",
"$",
"extraformats",
")",
")",
"{",
"$",
"extraformats",
"=",
"array",
"(",
")",
";",
"}",
"$",
"this",
"->",
"set_formats",
"(",
"array_merge",
"(",
"array",
"(",
"$",
"fileformat",
")",
",",
"$",
"extraformats",
")",
")",
";",
"}"
] |
If we already know we have exactly one file,
bypass set_formats and just pass the file
so we can detect the formats by mimetype.
@param stored_file $file file to set the format from
@param array $extraformats any additional formats other than by mimetype
eg leap2a etc
|
[
"If",
"we",
"already",
"know",
"we",
"have",
"exactly",
"one",
"file",
"bypass",
"set_formats",
"and",
"just",
"pass",
"the",
"file",
"so",
"we",
"can",
"detect",
"the",
"formats",
"by",
"mimetype",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfoliolib.php#L217-L226
|
219,481
|
moodle/moodle
|
lib/portfoliolib.php
|
portfolio_add_button.is_renderable
|
private function is_renderable() {
global $CFG;
if (empty($CFG->enableportfolios)) {
return false;
}
if (defined('PORTFOLIO_INTERNAL')) {
// something somewhere has detected a risk of this being called during inside the preparation
// eg forum_print_attachments
return false;
}
if (empty($this->instances) || count($this->instances) == 0) {
return false;
}
return true;
}
|
php
|
private function is_renderable() {
global $CFG;
if (empty($CFG->enableportfolios)) {
return false;
}
if (defined('PORTFOLIO_INTERNAL')) {
// something somewhere has detected a risk of this being called during inside the preparation
// eg forum_print_attachments
return false;
}
if (empty($this->instances) || count($this->instances) == 0) {
return false;
}
return true;
}
|
[
"private",
"function",
"is_renderable",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"if",
"(",
"empty",
"(",
"$",
"CFG",
"->",
"enableportfolios",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"defined",
"(",
"'PORTFOLIO_INTERNAL'",
")",
")",
"{",
"// something somewhere has detected a risk of this being called during inside the preparation",
"// eg forum_print_attachments",
"return",
"false",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"instances",
")",
"||",
"count",
"(",
"$",
"this",
"->",
"instances",
")",
"==",
"0",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] |
Perform some internal checks.
These are not errors, just situations
where it's not appropriate to add the button
@return bool
|
[
"Perform",
"some",
"internal",
"checks",
".",
"These",
"are",
"not",
"errors",
"just",
"situations",
"where",
"it",
"s",
"not",
"appropriate",
"to",
"add",
"the",
"button"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfoliolib.php#L391-L405
|
219,482
|
moodle/moodle
|
backup/util/xml/xml_writer.class.php
|
xml_writer.start
|
public function start() {
if ($this->running === true) {
throw new xml_writer_exception('xml_writer_already_started');
}
if ($this->running === false) {
throw new xml_writer_exception('xml_writer_already_stopped');
}
$this->output->start(); // Initialize whatever we need in output
if (!is_null($this->prologue)) { // Output prologue
$this->write($this->prologue);
} else {
$this->write($this->get_default_prologue());
}
$this->running = true;
}
|
php
|
public function start() {
if ($this->running === true) {
throw new xml_writer_exception('xml_writer_already_started');
}
if ($this->running === false) {
throw new xml_writer_exception('xml_writer_already_stopped');
}
$this->output->start(); // Initialize whatever we need in output
if (!is_null($this->prologue)) { // Output prologue
$this->write($this->prologue);
} else {
$this->write($this->get_default_prologue());
}
$this->running = true;
}
|
[
"public",
"function",
"start",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"running",
"===",
"true",
")",
"{",
"throw",
"new",
"xml_writer_exception",
"(",
"'xml_writer_already_started'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"running",
"===",
"false",
")",
"{",
"throw",
"new",
"xml_writer_exception",
"(",
"'xml_writer_already_stopped'",
")",
";",
"}",
"$",
"this",
"->",
"output",
"->",
"start",
"(",
")",
";",
"// Initialize whatever we need in output",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"prologue",
")",
")",
"{",
"// Output prologue",
"$",
"this",
"->",
"write",
"(",
"$",
"this",
"->",
"prologue",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"write",
"(",
"$",
"this",
"->",
"get_default_prologue",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"running",
"=",
"true",
";",
"}"
] |
Initializes the XML writer, preparing it to accept instructions, also
invoking the underlying @xml_output init method to be ready for operation
|
[
"Initializes",
"the",
"XML",
"writer",
"preparing",
"it",
"to",
"accept",
"instructions",
"also",
"invoking",
"the",
"underlying"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/xml/xml_writer.class.php#L85-L99
|
219,483
|
moodle/moodle
|
backup/util/xml/xml_writer.class.php
|
xml_writer.stop
|
public function stop() {
if (is_null($this->running)) {
throw new xml_writer_exception('xml_writer_not_started');
}
if ($this->running === false) {
throw new xml_writer_exception('xml_writer_already_stopped');
}
if ($this->level > 0) { // Cannot stop if not at level 0, remaining open tags
throw new xml_writer_exception('xml_writer_open_tags_remaining');
}
$this->output->stop();
$this->running = false;
}
|
php
|
public function stop() {
if (is_null($this->running)) {
throw new xml_writer_exception('xml_writer_not_started');
}
if ($this->running === false) {
throw new xml_writer_exception('xml_writer_already_stopped');
}
if ($this->level > 0) { // Cannot stop if not at level 0, remaining open tags
throw new xml_writer_exception('xml_writer_open_tags_remaining');
}
$this->output->stop();
$this->running = false;
}
|
[
"public",
"function",
"stop",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"running",
")",
")",
"{",
"throw",
"new",
"xml_writer_exception",
"(",
"'xml_writer_not_started'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"running",
"===",
"false",
")",
"{",
"throw",
"new",
"xml_writer_exception",
"(",
"'xml_writer_already_stopped'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"level",
">",
"0",
")",
"{",
"// Cannot stop if not at level 0, remaining open tags",
"throw",
"new",
"xml_writer_exception",
"(",
"'xml_writer_open_tags_remaining'",
")",
";",
"}",
"$",
"this",
"->",
"output",
"->",
"stop",
"(",
")",
";",
"$",
"this",
"->",
"running",
"=",
"false",
";",
"}"
] |
Finishes the XML writer, not accepting instructions any more, also
invoking the underlying @xml_output finish method to close/flush everything as needed
|
[
"Finishes",
"the",
"XML",
"writer",
"not",
"accepting",
"instructions",
"any",
"more",
"also",
"invoking",
"the",
"underlying"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/xml/xml_writer.class.php#L105-L117
|
219,484
|
moodle/moodle
|
backup/util/xml/xml_writer.class.php
|
xml_writer.end_tag
|
public function end_tag($tag) {
// TODO: check the tag name is valid
if ($this->level == 0) { // Nothing to end, already at level 0
throw new xml_writer_exception('xml_writer_end_tag_no_match');
}
$pre = $this->lastwastext ? '' : "\n" . str_repeat(' ', ($this->level - 1) * 2); // Indent
$tag = $this->casefolding ? strtoupper($tag) : $tag; // Follow casefolding
$lastopentag = array_pop($this->opentags);
if ($tag != $lastopentag) {
$a = new stdclass();
$a->lastopen = $lastopentag;
$a->tag = $tag;
throw new xml_writer_exception('xml_writer_end_tag_no_match', $a);
}
// Send to xml_output
$this->write($pre . '</' . $tag . '>');
$this->level--;
$this->lastwastext = false;
}
|
php
|
public function end_tag($tag) {
// TODO: check the tag name is valid
if ($this->level == 0) { // Nothing to end, already at level 0
throw new xml_writer_exception('xml_writer_end_tag_no_match');
}
$pre = $this->lastwastext ? '' : "\n" . str_repeat(' ', ($this->level - 1) * 2); // Indent
$tag = $this->casefolding ? strtoupper($tag) : $tag; // Follow casefolding
$lastopentag = array_pop($this->opentags);
if ($tag != $lastopentag) {
$a = new stdclass();
$a->lastopen = $lastopentag;
$a->tag = $tag;
throw new xml_writer_exception('xml_writer_end_tag_no_match', $a);
}
// Send to xml_output
$this->write($pre . '</' . $tag . '>');
$this->level--;
$this->lastwastext = false;
}
|
[
"public",
"function",
"end_tag",
"(",
"$",
"tag",
")",
"{",
"// TODO: check the tag name is valid",
"if",
"(",
"$",
"this",
"->",
"level",
"==",
"0",
")",
"{",
"// Nothing to end, already at level 0",
"throw",
"new",
"xml_writer_exception",
"(",
"'xml_writer_end_tag_no_match'",
")",
";",
"}",
"$",
"pre",
"=",
"$",
"this",
"->",
"lastwastext",
"?",
"''",
":",
"\"\\n\"",
".",
"str_repeat",
"(",
"' '",
",",
"(",
"$",
"this",
"->",
"level",
"-",
"1",
")",
"*",
"2",
")",
";",
"// Indent",
"$",
"tag",
"=",
"$",
"this",
"->",
"casefolding",
"?",
"strtoupper",
"(",
"$",
"tag",
")",
":",
"$",
"tag",
";",
"// Follow casefolding",
"$",
"lastopentag",
"=",
"array_pop",
"(",
"$",
"this",
"->",
"opentags",
")",
";",
"if",
"(",
"$",
"tag",
"!=",
"$",
"lastopentag",
")",
"{",
"$",
"a",
"=",
"new",
"stdclass",
"(",
")",
";",
"$",
"a",
"->",
"lastopen",
"=",
"$",
"lastopentag",
";",
"$",
"a",
"->",
"tag",
"=",
"$",
"tag",
";",
"throw",
"new",
"xml_writer_exception",
"(",
"'xml_writer_end_tag_no_match'",
",",
"$",
"a",
")",
";",
"}",
"// Send to xml_output",
"$",
"this",
"->",
"write",
"(",
"$",
"pre",
".",
"'</'",
".",
"$",
"tag",
".",
"'>'",
")",
";",
"$",
"this",
"->",
"level",
"--",
";",
"$",
"this",
"->",
"lastwastext",
"=",
"false",
";",
"}"
] |
Outputs one XML end tag
|
[
"Outputs",
"one",
"XML",
"end",
"tag"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/xml/xml_writer.class.php#L180-L204
|
219,485
|
moodle/moodle
|
backup/util/xml/xml_writer.class.php
|
xml_writer.text_content
|
protected function text_content($content) {
if (!is_null($this->contenttransformer)) { // Apply content transformation
$content = $this->contenttransformer->process($content);
}
return is_null($content) ? null : $this->xml_safe_text_content($content); // Safe UTF-8 and encode
}
|
php
|
protected function text_content($content) {
if (!is_null($this->contenttransformer)) { // Apply content transformation
$content = $this->contenttransformer->process($content);
}
return is_null($content) ? null : $this->xml_safe_text_content($content); // Safe UTF-8 and encode
}
|
[
"protected",
"function",
"text_content",
"(",
"$",
"content",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"contenttransformer",
")",
")",
"{",
"// Apply content transformation",
"$",
"content",
"=",
"$",
"this",
"->",
"contenttransformer",
"->",
"process",
"(",
"$",
"content",
")",
";",
"}",
"return",
"is_null",
"(",
"$",
"content",
")",
"?",
"null",
":",
"$",
"this",
"->",
"xml_safe_text_content",
"(",
"$",
"content",
")",
";",
"// Safe UTF-8 and encode",
"}"
] |
Returns text contents processed by the corresponding @xml_contenttransformer
|
[
"Returns",
"text",
"contents",
"processed",
"by",
"the",
"corresponding"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/xml/xml_writer.class.php#L271-L276
|
219,486
|
moodle/moodle
|
lib/classes/event/course_section_created.php
|
course_section_created.create_from_section
|
public static function create_from_section($section) {
$event = self::create([
'context' => \context_course::instance($section->course),
'objectid' => $section->id,
'other' => ['sectionnum' => $section->section]
]);
$event->add_record_snapshot('course_sections', $section);
return $event;
}
|
php
|
public static function create_from_section($section) {
$event = self::create([
'context' => \context_course::instance($section->course),
'objectid' => $section->id,
'other' => ['sectionnum' => $section->section]
]);
$event->add_record_snapshot('course_sections', $section);
return $event;
}
|
[
"public",
"static",
"function",
"create_from_section",
"(",
"$",
"section",
")",
"{",
"$",
"event",
"=",
"self",
"::",
"create",
"(",
"[",
"'context'",
"=>",
"\\",
"context_course",
"::",
"instance",
"(",
"$",
"section",
"->",
"course",
")",
",",
"'objectid'",
"=>",
"$",
"section",
"->",
"id",
",",
"'other'",
"=>",
"[",
"'sectionnum'",
"=>",
"$",
"section",
"->",
"section",
"]",
"]",
")",
";",
"$",
"event",
"->",
"add_record_snapshot",
"(",
"'course_sections'",
",",
"$",
"section",
")",
";",
"return",
"$",
"event",
";",
"}"
] |
Creates event from the section object
@param \stdClass $section
@return course_section_created
|
[
"Creates",
"event",
"from",
"the",
"section",
"object"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/event/course_section_created.php#L61-L69
|
219,487
|
moodle/moodle
|
lib/filestorage/mbz_packer.php
|
mbz_packer.get_packer_for_read_operation
|
protected function get_packer_for_read_operation($archivefile) {
global $CFG;
require_once($CFG->dirroot . '/lib/filestorage/tgz_packer.php');
if (tgz_packer::is_tgz_file($archivefile)) {
return get_file_packer('application/x-gzip');
} else {
return get_file_packer('application/zip');
}
}
|
php
|
protected function get_packer_for_read_operation($archivefile) {
global $CFG;
require_once($CFG->dirroot . '/lib/filestorage/tgz_packer.php');
if (tgz_packer::is_tgz_file($archivefile)) {
return get_file_packer('application/x-gzip');
} else {
return get_file_packer('application/zip');
}
}
|
[
"protected",
"function",
"get_packer_for_read_operation",
"(",
"$",
"archivefile",
")",
"{",
"global",
"$",
"CFG",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/lib/filestorage/tgz_packer.php'",
")",
";",
"if",
"(",
"tgz_packer",
"::",
"is_tgz_file",
"(",
"$",
"archivefile",
")",
")",
"{",
"return",
"get_file_packer",
"(",
"'application/x-gzip'",
")",
";",
"}",
"else",
"{",
"return",
"get_file_packer",
"(",
"'application/zip'",
")",
";",
"}",
"}"
] |
Selects appropriate packer for existing archive depending on file contents.
@param string|stored_file $archivefile full pathname of zip file or stored_file instance
@return file_packer Suitable packer
|
[
"Selects",
"appropriate",
"packer",
"for",
"existing",
"archive",
"depending",
"on",
"file",
"contents",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/mbz_packer.php#L165-L174
|
219,488
|
moodle/moodle
|
lib/lessphp/Visitor/processExtends.php
|
Less_Visitor_processExtends.HasMatches
|
private function HasMatches($extend, $haystackSelectorPath){
if( !$extend->selector->cacheable ){
return true;
}
$first_el = $extend->selector->_oelements[0];
foreach($haystackSelectorPath as $hackstackSelector){
if( !$hackstackSelector->cacheable ){
return true;
}
if( in_array($first_el, $hackstackSelector->_oelements) ){
return true;
}
}
return false;
}
|
php
|
private function HasMatches($extend, $haystackSelectorPath){
if( !$extend->selector->cacheable ){
return true;
}
$first_el = $extend->selector->_oelements[0];
foreach($haystackSelectorPath as $hackstackSelector){
if( !$hackstackSelector->cacheable ){
return true;
}
if( in_array($first_el, $hackstackSelector->_oelements) ){
return true;
}
}
return false;
}
|
[
"private",
"function",
"HasMatches",
"(",
"$",
"extend",
",",
"$",
"haystackSelectorPath",
")",
"{",
"if",
"(",
"!",
"$",
"extend",
"->",
"selector",
"->",
"cacheable",
")",
"{",
"return",
"true",
";",
"}",
"$",
"first_el",
"=",
"$",
"extend",
"->",
"selector",
"->",
"_oelements",
"[",
"0",
"]",
";",
"foreach",
"(",
"$",
"haystackSelectorPath",
"as",
"$",
"hackstackSelector",
")",
"{",
"if",
"(",
"!",
"$",
"hackstackSelector",
"->",
"cacheable",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"first_el",
",",
"$",
"hackstackSelector",
"->",
"_oelements",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Reduces Bootstrap 3.1 compile time from ~6.5s to ~5.6s
|
[
"Reduces",
"Bootstrap",
"3",
".",
"1",
"compile",
"time",
"from",
"~6",
".",
"5s",
"to",
"~5",
".",
"6s"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Visitor/processExtends.php#L259-L278
|
219,489
|
moodle/moodle
|
lib/spout/src/Spout/Writer/AbstractMultiSheetsWriter.php
|
AbstractMultiSheetsWriter.getSheets
|
public function getSheets()
{
$this->throwIfBookIsNotAvailable();
$externalSheets = [];
$worksheets = $this->getWorkbook()->getWorksheets();
/** @var Common\Internal\WorksheetInterface $worksheet */
foreach ($worksheets as $worksheet) {
$externalSheets[] = $worksheet->getExternalSheet();
}
return $externalSheets;
}
|
php
|
public function getSheets()
{
$this->throwIfBookIsNotAvailable();
$externalSheets = [];
$worksheets = $this->getWorkbook()->getWorksheets();
/** @var Common\Internal\WorksheetInterface $worksheet */
foreach ($worksheets as $worksheet) {
$externalSheets[] = $worksheet->getExternalSheet();
}
return $externalSheets;
}
|
[
"public",
"function",
"getSheets",
"(",
")",
"{",
"$",
"this",
"->",
"throwIfBookIsNotAvailable",
"(",
")",
";",
"$",
"externalSheets",
"=",
"[",
"]",
";",
"$",
"worksheets",
"=",
"$",
"this",
"->",
"getWorkbook",
"(",
")",
"->",
"getWorksheets",
"(",
")",
";",
"/** @var Common\\Internal\\WorksheetInterface $worksheet */",
"foreach",
"(",
"$",
"worksheets",
"as",
"$",
"worksheet",
")",
"{",
"$",
"externalSheets",
"[",
"]",
"=",
"$",
"worksheet",
"->",
"getExternalSheet",
"(",
")",
";",
"}",
"return",
"$",
"externalSheets",
";",
"}"
] |
Returns all the workbook's sheets
@api
@return Common\Sheet[] All the workbook's sheets
@throws \Box\Spout\Writer\Exception\WriterNotOpenedException If the writer has not been opened yet
|
[
"Returns",
"all",
"the",
"workbook",
"s",
"sheets"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/AbstractMultiSheetsWriter.php#L47-L60
|
219,490
|
moodle/moodle
|
calendar/classes/external/calendar_day_exporter.php
|
calendar_day_exporter.get_course_filter_selector
|
protected function get_course_filter_selector(renderer_base $output) {
$langstr = get_string('dayviewfor', 'calendar');
return $output->course_filter_selector($this->url, $langstr, $this->calendar->course->id);
}
|
php
|
protected function get_course_filter_selector(renderer_base $output) {
$langstr = get_string('dayviewfor', 'calendar');
return $output->course_filter_selector($this->url, $langstr, $this->calendar->course->id);
}
|
[
"protected",
"function",
"get_course_filter_selector",
"(",
"renderer_base",
"$",
"output",
")",
"{",
"$",
"langstr",
"=",
"get_string",
"(",
"'dayviewfor'",
",",
"'calendar'",
")",
";",
"return",
"$",
"output",
"->",
"course_filter_selector",
"(",
"$",
"this",
"->",
"url",
",",
"$",
"langstr",
",",
"$",
"this",
"->",
"calendar",
"->",
"course",
"->",
"id",
")",
";",
"}"
] |
Get the course filter selector.
@param renderer_base $output
@return string The html code for the course filter selector.
|
[
"Get",
"the",
"course",
"filter",
"selector",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/external/calendar_day_exporter.php#L242-L245
|
219,491
|
moodle/moodle
|
calendar/classes/external/calendar_day_exporter.php
|
calendar_day_exporter.get_previous_day_data
|
protected function get_previous_day_data() {
$type = $this->related['type'];
$time = $type->get_prev_day($this->calendar->time);
return $type->timestamp_to_date_array($time);
}
|
php
|
protected function get_previous_day_data() {
$type = $this->related['type'];
$time = $type->get_prev_day($this->calendar->time);
return $type->timestamp_to_date_array($time);
}
|
[
"protected",
"function",
"get_previous_day_data",
"(",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"related",
"[",
"'type'",
"]",
";",
"$",
"time",
"=",
"$",
"type",
"->",
"get_prev_day",
"(",
"$",
"this",
"->",
"calendar",
"->",
"time",
")",
";",
"return",
"$",
"type",
"->",
"timestamp_to_date_array",
"(",
"$",
"time",
")",
";",
"}"
] |
Get the previous day timestamp.
@return int The previous day timestamp.
|
[
"Get",
"the",
"previous",
"day",
"timestamp",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/external/calendar_day_exporter.php#L265-L270
|
219,492
|
moodle/moodle
|
calendar/classes/external/calendar_day_exporter.php
|
calendar_day_exporter.get_next_day_data
|
protected function get_next_day_data() {
$type = $this->related['type'];
$time = $type->get_next_day($this->calendar->time);
return $type->timestamp_to_date_array($time);
}
|
php
|
protected function get_next_day_data() {
$type = $this->related['type'];
$time = $type->get_next_day($this->calendar->time);
return $type->timestamp_to_date_array($time);
}
|
[
"protected",
"function",
"get_next_day_data",
"(",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"related",
"[",
"'type'",
"]",
";",
"$",
"time",
"=",
"$",
"type",
"->",
"get_next_day",
"(",
"$",
"this",
"->",
"calendar",
"->",
"time",
")",
";",
"return",
"$",
"type",
"->",
"timestamp_to_date_array",
"(",
"$",
"time",
")",
";",
"}"
] |
Get the next day timestamp.
@return int The next day timestamp.
|
[
"Get",
"the",
"next",
"day",
"timestamp",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/external/calendar_day_exporter.php#L277-L282
|
219,493
|
moodle/moodle
|
mod/wiki/parser/parser.php
|
generic_parser.process_block_rule
|
protected function process_block_rule($name, $block) {
$this->rulestack[] = array('callback' => method_exists($this, $name."_block_rule") ? $name."_block_rule" : null, 'rule' => $block);
$this->string = preg_replace_callback($block['expression'], array($this, 'block_callback'), $this->string);
array_pop($this->rulestack);
}
|
php
|
protected function process_block_rule($name, $block) {
$this->rulestack[] = array('callback' => method_exists($this, $name."_block_rule") ? $name."_block_rule" : null, 'rule' => $block);
$this->string = preg_replace_callback($block['expression'], array($this, 'block_callback'), $this->string);
array_pop($this->rulestack);
}
|
[
"protected",
"function",
"process_block_rule",
"(",
"$",
"name",
",",
"$",
"block",
")",
"{",
"$",
"this",
"->",
"rulestack",
"[",
"]",
"=",
"array",
"(",
"'callback'",
"=>",
"method_exists",
"(",
"$",
"this",
",",
"$",
"name",
".",
"\"_block_rule\"",
")",
"?",
"$",
"name",
".",
"\"_block_rule\"",
":",
"null",
",",
"'rule'",
"=>",
"$",
"block",
")",
";",
"$",
"this",
"->",
"string",
"=",
"preg_replace_callback",
"(",
"$",
"block",
"[",
"'expression'",
"]",
",",
"array",
"(",
"$",
"this",
",",
"'block_callback'",
")",
",",
"$",
"this",
"->",
"string",
")",
";",
"array_pop",
"(",
"$",
"this",
"->",
"rulestack",
")",
";",
"}"
] |
Block processing function & callbacks
|
[
"Block",
"processing",
"function",
"&",
"callbacks"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/parser/parser.php#L146-L152
|
219,494
|
moodle/moodle
|
mod/wiki/parser/parser.php
|
generic_parser.rules
|
protected final function rules(&$text, $rules = null) {
if($rules === null) {
$rules = array('except' => array());
}
else if(is_array($rules) && count($rules) > 1) {
$rules = array('only' => $rules);
}
if(isset($rules['only']) && is_array($rules['only'])) {
$rules = $rules['only'];
foreach($rules as $r) {
if(!empty($this->tagrules[$r])) {
$this->process_tag_rule($r, $this->tagrules[$r], $text);
}
}
}
else if(isset($rules['except']) && is_array($rules['except'])) {
$rules = $rules['except'];
foreach($this->tagrules as $r => $tr) {
if(!in_array($r, $rules)) {
$this->process_tag_rule($r, $tr, $text);
}
}
}
}
|
php
|
protected final function rules(&$text, $rules = null) {
if($rules === null) {
$rules = array('except' => array());
}
else if(is_array($rules) && count($rules) > 1) {
$rules = array('only' => $rules);
}
if(isset($rules['only']) && is_array($rules['only'])) {
$rules = $rules['only'];
foreach($rules as $r) {
if(!empty($this->tagrules[$r])) {
$this->process_tag_rule($r, $this->tagrules[$r], $text);
}
}
}
else if(isset($rules['except']) && is_array($rules['except'])) {
$rules = $rules['except'];
foreach($this->tagrules as $r => $tr) {
if(!in_array($r, $rules)) {
$this->process_tag_rule($r, $tr, $text);
}
}
}
}
|
[
"protected",
"final",
"function",
"rules",
"(",
"&",
"$",
"text",
",",
"$",
"rules",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"rules",
"===",
"null",
")",
"{",
"$",
"rules",
"=",
"array",
"(",
"'except'",
"=>",
"array",
"(",
")",
")",
";",
"}",
"else",
"if",
"(",
"is_array",
"(",
"$",
"rules",
")",
"&&",
"count",
"(",
"$",
"rules",
")",
">",
"1",
")",
"{",
"$",
"rules",
"=",
"array",
"(",
"'only'",
"=>",
"$",
"rules",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"rules",
"[",
"'only'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"rules",
"[",
"'only'",
"]",
")",
")",
"{",
"$",
"rules",
"=",
"$",
"rules",
"[",
"'only'",
"]",
";",
"foreach",
"(",
"$",
"rules",
"as",
"$",
"r",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"tagrules",
"[",
"$",
"r",
"]",
")",
")",
"{",
"$",
"this",
"->",
"process_tag_rule",
"(",
"$",
"r",
",",
"$",
"this",
"->",
"tagrules",
"[",
"$",
"r",
"]",
",",
"$",
"text",
")",
";",
"}",
"}",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"rules",
"[",
"'except'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"rules",
"[",
"'except'",
"]",
")",
")",
"{",
"$",
"rules",
"=",
"$",
"rules",
"[",
"'except'",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"tagrules",
"as",
"$",
"r",
"=>",
"$",
"tr",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"r",
",",
"$",
"rules",
")",
")",
"{",
"$",
"this",
"->",
"process_tag_rule",
"(",
"$",
"r",
",",
"$",
"tr",
",",
"$",
"text",
")",
";",
"}",
"}",
"}",
"}"
] |
Rules processing function & callback
|
[
"Rules",
"processing",
"function",
"&",
"callback"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/parser/parser.php#L184-L208
|
219,495
|
moodle/moodle
|
mod/wiki/parser/parser.php
|
generic_parser.initialize_nowiki_index
|
private function initialize_nowiki_index() {
$token = "\Q".$this->nowikitoken."\E";
$this->string = preg_replace_callback("/".$token."\d+".$token."/", array($this, "initialize_nowiki_index_callback"), $this->string);
}
|
php
|
private function initialize_nowiki_index() {
$token = "\Q".$this->nowikitoken."\E";
$this->string = preg_replace_callback("/".$token."\d+".$token."/", array($this, "initialize_nowiki_index_callback"), $this->string);
}
|
[
"private",
"function",
"initialize_nowiki_index",
"(",
")",
"{",
"$",
"token",
"=",
"\"\\Q\"",
".",
"$",
"this",
"->",
"nowikitoken",
".",
"\"\\E\"",
";",
"$",
"this",
"->",
"string",
"=",
"preg_replace_callback",
"(",
"\"/\"",
".",
"$",
"token",
".",
"\"\\d+\"",
".",
"$",
"token",
".",
"\"/\"",
",",
"array",
"(",
"$",
"this",
",",
"\"initialize_nowiki_index_callback\"",
")",
",",
"$",
"this",
"->",
"string",
")",
";",
"}"
] |
Special nowiki parser index
|
[
"Special",
"nowiki",
"parser",
"index"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/parser/parser.php#L244-L247
|
219,496
|
moodle/moodle
|
availability/condition/group/classes/condition.php
|
condition.include_after_restore
|
public function include_after_restore($restoreid, $courseid, \base_logger $logger,
$name, \base_task $task) {
return !$this->groupid || $task->get_setting_value('groups');
}
|
php
|
public function include_after_restore($restoreid, $courseid, \base_logger $logger,
$name, \base_task $task) {
return !$this->groupid || $task->get_setting_value('groups');
}
|
[
"public",
"function",
"include_after_restore",
"(",
"$",
"restoreid",
",",
"$",
"courseid",
",",
"\\",
"base_logger",
"$",
"logger",
",",
"$",
"name",
",",
"\\",
"base_task",
"$",
"task",
")",
"{",
"return",
"!",
"$",
"this",
"->",
"groupid",
"||",
"$",
"task",
"->",
"get_setting_value",
"(",
"'groups'",
")",
";",
"}"
] |
Include this condition only if we are including groups in restore, or
if it's a generic 'same activity' one.
@param int $restoreid The restore Id.
@param int $courseid The ID of the course.
@param base_logger $logger The logger being used.
@param string $name Name of item being restored.
@param base_task $task The task being performed.
@return Integer groupid
|
[
"Include",
"this",
"condition",
"only",
"if",
"we",
"are",
"including",
"groups",
"in",
"restore",
"or",
"if",
"it",
"s",
"a",
"generic",
"same",
"activity",
"one",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/availability/condition/group/classes/condition.php#L142-L145
|
219,497
|
moodle/moodle
|
question/format/xml/format.php
|
qformat_xml.trans_format
|
public function trans_format($name) {
$name = trim($name);
if ($name == 'moodle_auto_format') {
return FORMAT_MOODLE;
} else if ($name == 'html') {
return FORMAT_HTML;
} else if ($name == 'plain_text') {
return FORMAT_PLAIN;
} else if ($name == 'wiki_like') {
return FORMAT_WIKI;
} else if ($name == 'markdown') {
return FORMAT_MARKDOWN;
} else {
debugging("Unrecognised text format '{$name}' in the import file. Assuming 'html'.");
return FORMAT_HTML;
}
}
|
php
|
public function trans_format($name) {
$name = trim($name);
if ($name == 'moodle_auto_format') {
return FORMAT_MOODLE;
} else if ($name == 'html') {
return FORMAT_HTML;
} else if ($name == 'plain_text') {
return FORMAT_PLAIN;
} else if ($name == 'wiki_like') {
return FORMAT_WIKI;
} else if ($name == 'markdown') {
return FORMAT_MARKDOWN;
} else {
debugging("Unrecognised text format '{$name}' in the import file. Assuming 'html'.");
return FORMAT_HTML;
}
}
|
[
"public",
"function",
"trans_format",
"(",
"$",
"name",
")",
"{",
"$",
"name",
"=",
"trim",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"name",
"==",
"'moodle_auto_format'",
")",
"{",
"return",
"FORMAT_MOODLE",
";",
"}",
"else",
"if",
"(",
"$",
"name",
"==",
"'html'",
")",
"{",
"return",
"FORMAT_HTML",
";",
"}",
"else",
"if",
"(",
"$",
"name",
"==",
"'plain_text'",
")",
"{",
"return",
"FORMAT_PLAIN",
";",
"}",
"else",
"if",
"(",
"$",
"name",
"==",
"'wiki_like'",
")",
"{",
"return",
"FORMAT_WIKI",
";",
"}",
"else",
"if",
"(",
"$",
"name",
"==",
"'markdown'",
")",
"{",
"return",
"FORMAT_MARKDOWN",
";",
"}",
"else",
"{",
"debugging",
"(",
"\"Unrecognised text format '{$name}' in the import file. Assuming 'html'.\"",
")",
";",
"return",
"FORMAT_HTML",
";",
"}",
"}"
] |
Translate human readable format name
into internal Moodle code number
Note the reverse function is called get_format.
@param string name format name from xml file
@return int Moodle format code
|
[
"Translate",
"human",
"readable",
"format",
"name",
"into",
"internal",
"Moodle",
"code",
"number",
"Note",
"the",
"reverse",
"function",
"is",
"called",
"get_format",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/format/xml/format.php#L70-L87
|
219,498
|
moodle/moodle
|
question/format/xml/format.php
|
qformat_xml.getpath
|
public function getpath($xml, $path, $default, $istext=false, $error='') {
foreach ($path as $index) {
if (!isset($xml[$index])) {
if (!empty($error)) {
$this->error($error);
return false;
} else {
return $default;
}
}
$xml = $xml[$index];
}
if ($istext) {
if (!is_string($xml)) {
$this->error(get_string('invalidxml', 'qformat_xml'));
}
$xml = trim($xml);
}
return $xml;
}
|
php
|
public function getpath($xml, $path, $default, $istext=false, $error='') {
foreach ($path as $index) {
if (!isset($xml[$index])) {
if (!empty($error)) {
$this->error($error);
return false;
} else {
return $default;
}
}
$xml = $xml[$index];
}
if ($istext) {
if (!is_string($xml)) {
$this->error(get_string('invalidxml', 'qformat_xml'));
}
$xml = trim($xml);
}
return $xml;
}
|
[
"public",
"function",
"getpath",
"(",
"$",
"xml",
",",
"$",
"path",
",",
"$",
"default",
",",
"$",
"istext",
"=",
"false",
",",
"$",
"error",
"=",
"''",
")",
"{",
"foreach",
"(",
"$",
"path",
"as",
"$",
"index",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"xml",
"[",
"$",
"index",
"]",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"error",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"$",
"error",
")",
";",
"return",
"false",
";",
"}",
"else",
"{",
"return",
"$",
"default",
";",
"}",
"}",
"$",
"xml",
"=",
"$",
"xml",
"[",
"$",
"index",
"]",
";",
"}",
"if",
"(",
"$",
"istext",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"xml",
")",
")",
"{",
"$",
"this",
"->",
"error",
"(",
"get_string",
"(",
"'invalidxml'",
",",
"'qformat_xml'",
")",
")",
";",
"}",
"$",
"xml",
"=",
"trim",
"(",
"$",
"xml",
")",
";",
"}",
"return",
"$",
"xml",
";",
"}"
] |
return the value of a node, given a path to the node
if it doesn't exist return the default value
@param array xml data to read
@param array path path to node expressed as array
@param mixed default
@param bool istext process as text
@param string error if set value must exist, return false and issue message if not
@return mixed value
|
[
"return",
"the",
"value",
"of",
"a",
"node",
"given",
"a",
"path",
"to",
"the",
"node",
"if",
"it",
"doesn",
"t",
"exist",
"return",
"the",
"default",
"value"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/format/xml/format.php#L128-L150
|
219,499
|
moodle/moodle
|
question/format/xml/format.php
|
qformat_xml.import_answer
|
public function import_answer($answer, $withanswerfiles = false, $defaultformat = 'html') {
$ans = new stdClass();
if ($withanswerfiles) {
$ans->answer = $this->import_text_with_files($answer, array(), '', $defaultformat);
} else {
$ans->answer = array();
$ans->answer['text'] = $this->getpath($answer, array('#', 'text', 0, '#'), '', true);
$ans->answer['format'] = FORMAT_PLAIN;
}
$ans->feedback = $this->import_text_with_files($answer, array('#', 'feedback', 0), '', $defaultformat);
$ans->fraction = $this->getpath($answer, array('@', 'fraction'), 0) / 100;
return $ans;
}
|
php
|
public function import_answer($answer, $withanswerfiles = false, $defaultformat = 'html') {
$ans = new stdClass();
if ($withanswerfiles) {
$ans->answer = $this->import_text_with_files($answer, array(), '', $defaultformat);
} else {
$ans->answer = array();
$ans->answer['text'] = $this->getpath($answer, array('#', 'text', 0, '#'), '', true);
$ans->answer['format'] = FORMAT_PLAIN;
}
$ans->feedback = $this->import_text_with_files($answer, array('#', 'feedback', 0), '', $defaultformat);
$ans->fraction = $this->getpath($answer, array('@', 'fraction'), 0) / 100;
return $ans;
}
|
[
"public",
"function",
"import_answer",
"(",
"$",
"answer",
",",
"$",
"withanswerfiles",
"=",
"false",
",",
"$",
"defaultformat",
"=",
"'html'",
")",
"{",
"$",
"ans",
"=",
"new",
"stdClass",
"(",
")",
";",
"if",
"(",
"$",
"withanswerfiles",
")",
"{",
"$",
"ans",
"->",
"answer",
"=",
"$",
"this",
"->",
"import_text_with_files",
"(",
"$",
"answer",
",",
"array",
"(",
")",
",",
"''",
",",
"$",
"defaultformat",
")",
";",
"}",
"else",
"{",
"$",
"ans",
"->",
"answer",
"=",
"array",
"(",
")",
";",
"$",
"ans",
"->",
"answer",
"[",
"'text'",
"]",
"=",
"$",
"this",
"->",
"getpath",
"(",
"$",
"answer",
",",
"array",
"(",
"'#'",
",",
"'text'",
",",
"0",
",",
"'#'",
")",
",",
"''",
",",
"true",
")",
";",
"$",
"ans",
"->",
"answer",
"[",
"'format'",
"]",
"=",
"FORMAT_PLAIN",
";",
"}",
"$",
"ans",
"->",
"feedback",
"=",
"$",
"this",
"->",
"import_text_with_files",
"(",
"$",
"answer",
",",
"array",
"(",
"'#'",
",",
"'feedback'",
",",
"0",
")",
",",
"''",
",",
"$",
"defaultformat",
")",
";",
"$",
"ans",
"->",
"fraction",
"=",
"$",
"this",
"->",
"getpath",
"(",
"$",
"answer",
",",
"array",
"(",
"'@'",
",",
"'fraction'",
")",
",",
"0",
")",
"/",
"100",
";",
"return",
"$",
"ans",
";",
"}"
] |
Import the common parts of a single answer
@param array answer xml tree for single answer
@param bool $withanswerfiles if true, the answers are HTML (or $defaultformat)
and so may contain files, otherwise the answers are plain text.
@param array Default text format for the feedback, and the answers if $withanswerfiles
is true.
@return object answer object
|
[
"Import",
"the",
"common",
"parts",
"of",
"a",
"single",
"answer"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/format/xml/format.php#L275-L291
|
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.