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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
214,000 | moodle/moodle | grade/import/csv/classes/load_data.php | gradeimport_csv_load_data.check_user_exists | protected function check_user_exists($value, $userfields) {
global $DB;
$user = null;
$errorkey = false;
// The user may use the incorrect field to match the user. This could result in an exception.
try {
$field = $userfields['field'];
// Fields that can be queried in a case-insensitive manner.
$caseinsensitivefields = [
'email',
'username',
];
// Build query predicate.
if (in_array($field, $caseinsensitivefields)) {
// Case-insensitive.
$select = $DB->sql_equal($field, ':' . $field, false);
} else {
// Exact-value.
$select = "{$field} = :{$field}";
}
// Make sure the record exists and that there's only one matching record found.
$user = $DB->get_record_select('user', $select, array($userfields['field'] => $value), '*', MUST_EXIST);
} catch (dml_missing_record_exception $missingex) {
$errorkey = 'usermappingerror';
} catch (dml_multiple_records_exception $multiex) {
$errorkey = 'usermappingerrormultipleusersfound';
}
// Field may be fine, but no records were returned.
if ($errorkey) {
$usermappingerrorobj = new stdClass();
$usermappingerrorobj->field = $userfields['label'];
$usermappingerrorobj->value = $value;
$this->cleanup_import(get_string($errorkey, 'grades', $usermappingerrorobj));
unset($usermappingerrorobj);
return null;
}
return $user->id;
} | php | protected function check_user_exists($value, $userfields) {
global $DB;
$user = null;
$errorkey = false;
// The user may use the incorrect field to match the user. This could result in an exception.
try {
$field = $userfields['field'];
// Fields that can be queried in a case-insensitive manner.
$caseinsensitivefields = [
'email',
'username',
];
// Build query predicate.
if (in_array($field, $caseinsensitivefields)) {
// Case-insensitive.
$select = $DB->sql_equal($field, ':' . $field, false);
} else {
// Exact-value.
$select = "{$field} = :{$field}";
}
// Make sure the record exists and that there's only one matching record found.
$user = $DB->get_record_select('user', $select, array($userfields['field'] => $value), '*', MUST_EXIST);
} catch (dml_missing_record_exception $missingex) {
$errorkey = 'usermappingerror';
} catch (dml_multiple_records_exception $multiex) {
$errorkey = 'usermappingerrormultipleusersfound';
}
// Field may be fine, but no records were returned.
if ($errorkey) {
$usermappingerrorobj = new stdClass();
$usermappingerrorobj->field = $userfields['label'];
$usermappingerrorobj->value = $value;
$this->cleanup_import(get_string($errorkey, 'grades', $usermappingerrorobj));
unset($usermappingerrorobj);
return null;
}
return $user->id;
} | [
"protected",
"function",
"check_user_exists",
"(",
"$",
"value",
",",
"$",
"userfields",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"user",
"=",
"null",
";",
"$",
"errorkey",
"=",
"false",
";",
"// The user may use the incorrect field to match the user. This could result in an exception.",
"try",
"{",
"$",
"field",
"=",
"$",
"userfields",
"[",
"'field'",
"]",
";",
"// Fields that can be queried in a case-insensitive manner.",
"$",
"caseinsensitivefields",
"=",
"[",
"'email'",
",",
"'username'",
",",
"]",
";",
"// Build query predicate.",
"if",
"(",
"in_array",
"(",
"$",
"field",
",",
"$",
"caseinsensitivefields",
")",
")",
"{",
"// Case-insensitive.",
"$",
"select",
"=",
"$",
"DB",
"->",
"sql_equal",
"(",
"$",
"field",
",",
"':'",
".",
"$",
"field",
",",
"false",
")",
";",
"}",
"else",
"{",
"// Exact-value.",
"$",
"select",
"=",
"\"{$field} = :{$field}\"",
";",
"}",
"// Make sure the record exists and that there's only one matching record found.",
"$",
"user",
"=",
"$",
"DB",
"->",
"get_record_select",
"(",
"'user'",
",",
"$",
"select",
",",
"array",
"(",
"$",
"userfields",
"[",
"'field'",
"]",
"=>",
"$",
"value",
")",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"}",
"catch",
"(",
"dml_missing_record_exception",
"$",
"missingex",
")",
"{",
"$",
"errorkey",
"=",
"'usermappingerror'",
";",
"}",
"catch",
"(",
"dml_multiple_records_exception",
"$",
"multiex",
")",
"{",
"$",
"errorkey",
"=",
"'usermappingerrormultipleusersfound'",
";",
"}",
"// Field may be fine, but no records were returned.",
"if",
"(",
"$",
"errorkey",
")",
"{",
"$",
"usermappingerrorobj",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"usermappingerrorobj",
"->",
"field",
"=",
"$",
"userfields",
"[",
"'label'",
"]",
";",
"$",
"usermappingerrorobj",
"->",
"value",
"=",
"$",
"value",
";",
"$",
"this",
"->",
"cleanup_import",
"(",
"get_string",
"(",
"$",
"errorkey",
",",
"'grades'",
",",
"$",
"usermappingerrorobj",
")",
")",
";",
"unset",
"(",
"$",
"usermappingerrorobj",
")",
";",
"return",
"null",
";",
"}",
"return",
"$",
"user",
"->",
"id",
";",
"}"
] | Check that the user is in the system.
@param string $value The value, from the csv file, being mapped to identify the user.
@param array $userfields Contains the field and label being mapped from.
@return int Returns the user ID if it exists, otherwise null. | [
"Check",
"that",
"the",
"user",
"is",
"in",
"the",
"system",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/import/csv/classes/load_data.php#L221-L260 |
214,001 | moodle/moodle | grade/import/csv/classes/load_data.php | gradeimport_csv_load_data.create_feedback | protected function create_feedback($courseid, $itemid, $value) {
// Case of an id, only maps id of a grade_item.
// This was idnumber.
if (!new grade_item(array('id' => $itemid, 'courseid' => $courseid))) {
// Supplied bad mapping, should not be possible since user
// had to pick mapping.
$this->cleanup_import(get_string('importfailed', 'grades'));
return null;
}
// The itemid is the id of the grade item.
$feedback = new stdClass();
$feedback->itemid = $itemid;
$feedback->feedback = $value;
return $feedback;
} | php | protected function create_feedback($courseid, $itemid, $value) {
// Case of an id, only maps id of a grade_item.
// This was idnumber.
if (!new grade_item(array('id' => $itemid, 'courseid' => $courseid))) {
// Supplied bad mapping, should not be possible since user
// had to pick mapping.
$this->cleanup_import(get_string('importfailed', 'grades'));
return null;
}
// The itemid is the id of the grade item.
$feedback = new stdClass();
$feedback->itemid = $itemid;
$feedback->feedback = $value;
return $feedback;
} | [
"protected",
"function",
"create_feedback",
"(",
"$",
"courseid",
",",
"$",
"itemid",
",",
"$",
"value",
")",
"{",
"// Case of an id, only maps id of a grade_item.",
"// This was idnumber.",
"if",
"(",
"!",
"new",
"grade_item",
"(",
"array",
"(",
"'id'",
"=>",
"$",
"itemid",
",",
"'courseid'",
"=>",
"$",
"courseid",
")",
")",
")",
"{",
"// Supplied bad mapping, should not be possible since user",
"// had to pick mapping.",
"$",
"this",
"->",
"cleanup_import",
"(",
"get_string",
"(",
"'importfailed'",
",",
"'grades'",
")",
")",
";",
"return",
"null",
";",
"}",
"// The itemid is the id of the grade item.",
"$",
"feedback",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"feedback",
"->",
"itemid",
"=",
"$",
"itemid",
";",
"$",
"feedback",
"->",
"feedback",
"=",
"$",
"value",
";",
"return",
"$",
"feedback",
";",
"}"
] | Check to see if the feedback matches a grade item.
@param int $courseid The course ID.
@param int $itemid The ID of the grade item that the feedback relates to.
@param string $value The actual feedback being imported.
@return object Creates a feedback object with the item ID and the feedback value. | [
"Check",
"to",
"see",
"if",
"the",
"feedback",
"matches",
"a",
"grade",
"item",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/import/csv/classes/load_data.php#L270-L285 |
214,002 | moodle/moodle | grade/import/csv/classes/load_data.php | gradeimport_csv_load_data.update_grade_item | protected function update_grade_item($courseid, $map, $key, $verbosescales, $value) {
// Case of an id, only maps id of a grade_item.
// This was idnumber.
if (!$gradeitem = new grade_item(array('id' => $map[$key], 'courseid' => $courseid))) {
// Supplied bad mapping, should not be possible since user
// had to pick mapping.
$this->cleanup_import(get_string('importfailed', 'grades'));
return null;
}
// Check if grade item is locked if so, abort.
if ($gradeitem->is_locked()) {
$this->cleanup_import(get_string('gradeitemlocked', 'grades'));
return null;
}
$newgrade = new stdClass();
$newgrade->itemid = $gradeitem->id;
if ($gradeitem->gradetype == GRADE_TYPE_SCALE and $verbosescales) {
if ($value === '' or $value == '-') {
$value = null; // No grade.
} else {
$scale = $gradeitem->load_scale();
$scales = explode(',', $scale->scale);
$scales = array_map('trim', $scales); // Hack - trim whitespace around scale options.
array_unshift($scales, '-'); // Scales start at key 1.
$key = array_search($value, $scales);
if ($key === false) {
$this->cleanup_import(get_string('badgrade', 'grades'));
return null;
}
$value = $key;
}
$newgrade->finalgrade = $value;
} else {
if ($value === '' or $value == '-') {
$value = null; // No grade.
} else {
// If the value has a local decimal or can correctly be unformatted, do it.
$validvalue = unformat_float($value, true);
if ($validvalue !== false) {
$value = $validvalue;
} else {
// Non numeric grade value supplied, possibly mapped wrong column.
$this->cleanup_import(get_string('badgrade', 'grades'));
return null;
}
}
$newgrade->finalgrade = $value;
}
$this->newgrades[] = $newgrade;
return $this->newgrades;
} | php | protected function update_grade_item($courseid, $map, $key, $verbosescales, $value) {
// Case of an id, only maps id of a grade_item.
// This was idnumber.
if (!$gradeitem = new grade_item(array('id' => $map[$key], 'courseid' => $courseid))) {
// Supplied bad mapping, should not be possible since user
// had to pick mapping.
$this->cleanup_import(get_string('importfailed', 'grades'));
return null;
}
// Check if grade item is locked if so, abort.
if ($gradeitem->is_locked()) {
$this->cleanup_import(get_string('gradeitemlocked', 'grades'));
return null;
}
$newgrade = new stdClass();
$newgrade->itemid = $gradeitem->id;
if ($gradeitem->gradetype == GRADE_TYPE_SCALE and $verbosescales) {
if ($value === '' or $value == '-') {
$value = null; // No grade.
} else {
$scale = $gradeitem->load_scale();
$scales = explode(',', $scale->scale);
$scales = array_map('trim', $scales); // Hack - trim whitespace around scale options.
array_unshift($scales, '-'); // Scales start at key 1.
$key = array_search($value, $scales);
if ($key === false) {
$this->cleanup_import(get_string('badgrade', 'grades'));
return null;
}
$value = $key;
}
$newgrade->finalgrade = $value;
} else {
if ($value === '' or $value == '-') {
$value = null; // No grade.
} else {
// If the value has a local decimal or can correctly be unformatted, do it.
$validvalue = unformat_float($value, true);
if ($validvalue !== false) {
$value = $validvalue;
} else {
// Non numeric grade value supplied, possibly mapped wrong column.
$this->cleanup_import(get_string('badgrade', 'grades'));
return null;
}
}
$newgrade->finalgrade = $value;
}
$this->newgrades[] = $newgrade;
return $this->newgrades;
} | [
"protected",
"function",
"update_grade_item",
"(",
"$",
"courseid",
",",
"$",
"map",
",",
"$",
"key",
",",
"$",
"verbosescales",
",",
"$",
"value",
")",
"{",
"// Case of an id, only maps id of a grade_item.",
"// This was idnumber.",
"if",
"(",
"!",
"$",
"gradeitem",
"=",
"new",
"grade_item",
"(",
"array",
"(",
"'id'",
"=>",
"$",
"map",
"[",
"$",
"key",
"]",
",",
"'courseid'",
"=>",
"$",
"courseid",
")",
")",
")",
"{",
"// Supplied bad mapping, should not be possible since user",
"// had to pick mapping.",
"$",
"this",
"->",
"cleanup_import",
"(",
"get_string",
"(",
"'importfailed'",
",",
"'grades'",
")",
")",
";",
"return",
"null",
";",
"}",
"// Check if grade item is locked if so, abort.",
"if",
"(",
"$",
"gradeitem",
"->",
"is_locked",
"(",
")",
")",
"{",
"$",
"this",
"->",
"cleanup_import",
"(",
"get_string",
"(",
"'gradeitemlocked'",
",",
"'grades'",
")",
")",
";",
"return",
"null",
";",
"}",
"$",
"newgrade",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"newgrade",
"->",
"itemid",
"=",
"$",
"gradeitem",
"->",
"id",
";",
"if",
"(",
"$",
"gradeitem",
"->",
"gradetype",
"==",
"GRADE_TYPE_SCALE",
"and",
"$",
"verbosescales",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"''",
"or",
"$",
"value",
"==",
"'-'",
")",
"{",
"$",
"value",
"=",
"null",
";",
"// No grade.",
"}",
"else",
"{",
"$",
"scale",
"=",
"$",
"gradeitem",
"->",
"load_scale",
"(",
")",
";",
"$",
"scales",
"=",
"explode",
"(",
"','",
",",
"$",
"scale",
"->",
"scale",
")",
";",
"$",
"scales",
"=",
"array_map",
"(",
"'trim'",
",",
"$",
"scales",
")",
";",
"// Hack - trim whitespace around scale options.",
"array_unshift",
"(",
"$",
"scales",
",",
"'-'",
")",
";",
"// Scales start at key 1.",
"$",
"key",
"=",
"array_search",
"(",
"$",
"value",
",",
"$",
"scales",
")",
";",
"if",
"(",
"$",
"key",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"cleanup_import",
"(",
"get_string",
"(",
"'badgrade'",
",",
"'grades'",
")",
")",
";",
"return",
"null",
";",
"}",
"$",
"value",
"=",
"$",
"key",
";",
"}",
"$",
"newgrade",
"->",
"finalgrade",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"value",
"===",
"''",
"or",
"$",
"value",
"==",
"'-'",
")",
"{",
"$",
"value",
"=",
"null",
";",
"// No grade.",
"}",
"else",
"{",
"// If the value has a local decimal or can correctly be unformatted, do it.",
"$",
"validvalue",
"=",
"unformat_float",
"(",
"$",
"value",
",",
"true",
")",
";",
"if",
"(",
"$",
"validvalue",
"!==",
"false",
")",
"{",
"$",
"value",
"=",
"$",
"validvalue",
";",
"}",
"else",
"{",
"// Non numeric grade value supplied, possibly mapped wrong column.",
"$",
"this",
"->",
"cleanup_import",
"(",
"get_string",
"(",
"'badgrade'",
",",
"'grades'",
")",
")",
";",
"return",
"null",
";",
"}",
"}",
"$",
"newgrade",
"->",
"finalgrade",
"=",
"$",
"value",
";",
"}",
"$",
"this",
"->",
"newgrades",
"[",
"]",
"=",
"$",
"newgrade",
";",
"return",
"$",
"this",
"->",
"newgrades",
";",
"}"
] | This updates existing grade items.
@param int $courseid The course ID.
@param array $map Mapping information provided by the user.
@param int $key The line that we are currently working on.
@param bool $verbosescales Form setting for grading with scales.
@param string $value The grade value.
@return array grades to be updated. | [
"This",
"updates",
"existing",
"grade",
"items",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/import/csv/classes/load_data.php#L297-L349 |
214,003 | moodle/moodle | grade/import/csv/classes/load_data.php | gradeimport_csv_load_data.cleanup_import | protected function cleanup_import($notification) {
$this->status = false;
import_cleanup($this->importcode);
$this->gradebookerrors[] = $notification;
} | php | protected function cleanup_import($notification) {
$this->status = false;
import_cleanup($this->importcode);
$this->gradebookerrors[] = $notification;
} | [
"protected",
"function",
"cleanup_import",
"(",
"$",
"notification",
")",
"{",
"$",
"this",
"->",
"status",
"=",
"false",
";",
"import_cleanup",
"(",
"$",
"this",
"->",
"importcode",
")",
";",
"$",
"this",
"->",
"gradebookerrors",
"[",
"]",
"=",
"$",
"notification",
";",
"}"
] | Clean up failed CSV grade import. Clears the temp table for inserting grades.
@param string $notification The error message to display from the unsuccessful grade import. | [
"Clean",
"up",
"failed",
"CSV",
"grade",
"import",
".",
"Clears",
"the",
"temp",
"table",
"for",
"inserting",
"grades",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/import/csv/classes/load_data.php#L356-L360 |
214,004 | moodle/moodle | grade/import/csv/classes/load_data.php | gradeimport_csv_load_data.map_user_data_with_value | protected function map_user_data_with_value($mappingidentifier, $value, $header, $map, $key, $courseid, $feedbackgradeid,
$verbosescales) {
// Fields that the user can be mapped from.
$userfields = array(
'userid' => array(
'field' => 'id',
'label' => 'id',
),
'useridnumber' => array(
'field' => 'idnumber',
'label' => 'idnumber',
),
'useremail' => array(
'field' => 'email',
'label' => 'email address',
),
'username' => array(
'field' => 'username',
'label' => 'username',
),
);
switch ($mappingidentifier) {
case 'userid':
case 'useridnumber':
case 'useremail':
case 'username':
// Skip invalid row with blank user field.
if (!empty($value)) {
$this->studentid = $this->check_user_exists($value, $userfields[$mappingidentifier]);
}
break;
case 'new':
$this->import_new_grade_item($header, $key, $value);
break;
case 'feedback':
if ($feedbackgradeid) {
$feedback = $this->create_feedback($courseid, $feedbackgradeid, $value);
if (isset($feedback)) {
$this->newfeedbacks[] = $feedback;
}
}
break;
default:
// Existing grade items.
if (!empty($map[$key])) {
$this->newgrades = $this->update_grade_item($courseid, $map, $key, $verbosescales, $value,
$mappingidentifier);
}
// Otherwise, we ignore this column altogether because user has chosen
// to ignore them (e.g. institution, address etc).
break;
}
} | php | protected function map_user_data_with_value($mappingidentifier, $value, $header, $map, $key, $courseid, $feedbackgradeid,
$verbosescales) {
// Fields that the user can be mapped from.
$userfields = array(
'userid' => array(
'field' => 'id',
'label' => 'id',
),
'useridnumber' => array(
'field' => 'idnumber',
'label' => 'idnumber',
),
'useremail' => array(
'field' => 'email',
'label' => 'email address',
),
'username' => array(
'field' => 'username',
'label' => 'username',
),
);
switch ($mappingidentifier) {
case 'userid':
case 'useridnumber':
case 'useremail':
case 'username':
// Skip invalid row with blank user field.
if (!empty($value)) {
$this->studentid = $this->check_user_exists($value, $userfields[$mappingidentifier]);
}
break;
case 'new':
$this->import_new_grade_item($header, $key, $value);
break;
case 'feedback':
if ($feedbackgradeid) {
$feedback = $this->create_feedback($courseid, $feedbackgradeid, $value);
if (isset($feedback)) {
$this->newfeedbacks[] = $feedback;
}
}
break;
default:
// Existing grade items.
if (!empty($map[$key])) {
$this->newgrades = $this->update_grade_item($courseid, $map, $key, $verbosescales, $value,
$mappingidentifier);
}
// Otherwise, we ignore this column altogether because user has chosen
// to ignore them (e.g. institution, address etc).
break;
}
} | [
"protected",
"function",
"map_user_data_with_value",
"(",
"$",
"mappingidentifier",
",",
"$",
"value",
",",
"$",
"header",
",",
"$",
"map",
",",
"$",
"key",
",",
"$",
"courseid",
",",
"$",
"feedbackgradeid",
",",
"$",
"verbosescales",
")",
"{",
"// Fields that the user can be mapped from.",
"$",
"userfields",
"=",
"array",
"(",
"'userid'",
"=>",
"array",
"(",
"'field'",
"=>",
"'id'",
",",
"'label'",
"=>",
"'id'",
",",
")",
",",
"'useridnumber'",
"=>",
"array",
"(",
"'field'",
"=>",
"'idnumber'",
",",
"'label'",
"=>",
"'idnumber'",
",",
")",
",",
"'useremail'",
"=>",
"array",
"(",
"'field'",
"=>",
"'email'",
",",
"'label'",
"=>",
"'email address'",
",",
")",
",",
"'username'",
"=>",
"array",
"(",
"'field'",
"=>",
"'username'",
",",
"'label'",
"=>",
"'username'",
",",
")",
",",
")",
";",
"switch",
"(",
"$",
"mappingidentifier",
")",
"{",
"case",
"'userid'",
":",
"case",
"'useridnumber'",
":",
"case",
"'useremail'",
":",
"case",
"'username'",
":",
"// Skip invalid row with blank user field.",
"if",
"(",
"!",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"$",
"this",
"->",
"studentid",
"=",
"$",
"this",
"->",
"check_user_exists",
"(",
"$",
"value",
",",
"$",
"userfields",
"[",
"$",
"mappingidentifier",
"]",
")",
";",
"}",
"break",
";",
"case",
"'new'",
":",
"$",
"this",
"->",
"import_new_grade_item",
"(",
"$",
"header",
",",
"$",
"key",
",",
"$",
"value",
")",
";",
"break",
";",
"case",
"'feedback'",
":",
"if",
"(",
"$",
"feedbackgradeid",
")",
"{",
"$",
"feedback",
"=",
"$",
"this",
"->",
"create_feedback",
"(",
"$",
"courseid",
",",
"$",
"feedbackgradeid",
",",
"$",
"value",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"feedback",
")",
")",
"{",
"$",
"this",
"->",
"newfeedbacks",
"[",
"]",
"=",
"$",
"feedback",
";",
"}",
"}",
"break",
";",
"default",
":",
"// Existing grade items.",
"if",
"(",
"!",
"empty",
"(",
"$",
"map",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"this",
"->",
"newgrades",
"=",
"$",
"this",
"->",
"update_grade_item",
"(",
"$",
"courseid",
",",
"$",
"map",
",",
"$",
"key",
",",
"$",
"verbosescales",
",",
"$",
"value",
",",
"$",
"mappingidentifier",
")",
";",
"}",
"// Otherwise, we ignore this column altogether because user has chosen",
"// to ignore them (e.g. institution, address etc).",
"break",
";",
"}",
"}"
] | Check user mapping.
@param string $mappingidentifier The user field that we are matching together.
@param string $value The value we are checking / importing.
@param array $header The column headers of the csv file.
@param array $map Mapping information provided by the user.
@param int $key Current row identifier.
@param int $courseid The course ID.
@param int $feedbackgradeid The ID of the grade item that the feedback relates to.
@param bool $verbosescales Form setting for grading with scales. | [
"Check",
"user",
"mapping",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/import/csv/classes/load_data.php#L374-L428 |
214,005 | moodle/moodle | admin/tool/uploaduser/locallib.php | uu_progress_tracker.start | public function start() {
$ci = 0;
echo '<table id="uuresults" class="generaltable boxaligncenter flexible-wrap" summary="'.get_string('uploadusersresult', 'tool_uploaduser').'">';
echo '<tr class="heading r0">';
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('status').'</th>';
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('uucsvline', 'tool_uploaduser').'</th>';
echo '<th class="header c'.$ci++.'" scope="col">ID</th>';
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('username').'</th>';
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('firstname').'</th>';
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('lastname').'</th>';
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('email').'</th>';
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('password').'</th>';
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('authentication').'</th>';
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('enrolments', 'enrol').'</th>';
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('suspended', 'auth').'</th>';
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('delete').'</th>';
echo '</tr>';
$this->_row = null;
} | php | public function start() {
$ci = 0;
echo '<table id="uuresults" class="generaltable boxaligncenter flexible-wrap" summary="'.get_string('uploadusersresult', 'tool_uploaduser').'">';
echo '<tr class="heading r0">';
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('status').'</th>';
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('uucsvline', 'tool_uploaduser').'</th>';
echo '<th class="header c'.$ci++.'" scope="col">ID</th>';
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('username').'</th>';
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('firstname').'</th>';
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('lastname').'</th>';
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('email').'</th>';
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('password').'</th>';
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('authentication').'</th>';
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('enrolments', 'enrol').'</th>';
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('suspended', 'auth').'</th>';
echo '<th class="header c'.$ci++.'" scope="col">'.get_string('delete').'</th>';
echo '</tr>';
$this->_row = null;
} | [
"public",
"function",
"start",
"(",
")",
"{",
"$",
"ci",
"=",
"0",
";",
"echo",
"'<table id=\"uuresults\" class=\"generaltable boxaligncenter flexible-wrap\" summary=\"'",
".",
"get_string",
"(",
"'uploadusersresult'",
",",
"'tool_uploaduser'",
")",
".",
"'\">'",
";",
"echo",
"'<tr class=\"heading r0\">'",
";",
"echo",
"'<th class=\"header c'",
".",
"$",
"ci",
"++",
".",
"'\" scope=\"col\">'",
".",
"get_string",
"(",
"'status'",
")",
".",
"'</th>'",
";",
"echo",
"'<th class=\"header c'",
".",
"$",
"ci",
"++",
".",
"'\" scope=\"col\">'",
".",
"get_string",
"(",
"'uucsvline'",
",",
"'tool_uploaduser'",
")",
".",
"'</th>'",
";",
"echo",
"'<th class=\"header c'",
".",
"$",
"ci",
"++",
".",
"'\" scope=\"col\">ID</th>'",
";",
"echo",
"'<th class=\"header c'",
".",
"$",
"ci",
"++",
".",
"'\" scope=\"col\">'",
".",
"get_string",
"(",
"'username'",
")",
".",
"'</th>'",
";",
"echo",
"'<th class=\"header c'",
".",
"$",
"ci",
"++",
".",
"'\" scope=\"col\">'",
".",
"get_string",
"(",
"'firstname'",
")",
".",
"'</th>'",
";",
"echo",
"'<th class=\"header c'",
".",
"$",
"ci",
"++",
".",
"'\" scope=\"col\">'",
".",
"get_string",
"(",
"'lastname'",
")",
".",
"'</th>'",
";",
"echo",
"'<th class=\"header c'",
".",
"$",
"ci",
"++",
".",
"'\" scope=\"col\">'",
".",
"get_string",
"(",
"'email'",
")",
".",
"'</th>'",
";",
"echo",
"'<th class=\"header c'",
".",
"$",
"ci",
"++",
".",
"'\" scope=\"col\">'",
".",
"get_string",
"(",
"'password'",
")",
".",
"'</th>'",
";",
"echo",
"'<th class=\"header c'",
".",
"$",
"ci",
"++",
".",
"'\" scope=\"col\">'",
".",
"get_string",
"(",
"'authentication'",
")",
".",
"'</th>'",
";",
"echo",
"'<th class=\"header c'",
".",
"$",
"ci",
"++",
".",
"'\" scope=\"col\">'",
".",
"get_string",
"(",
"'enrolments'",
",",
"'enrol'",
")",
".",
"'</th>'",
";",
"echo",
"'<th class=\"header c'",
".",
"$",
"ci",
"++",
".",
"'\" scope=\"col\">'",
".",
"get_string",
"(",
"'suspended'",
",",
"'auth'",
")",
".",
"'</th>'",
";",
"echo",
"'<th class=\"header c'",
".",
"$",
"ci",
"++",
".",
"'\" scope=\"col\">'",
".",
"get_string",
"(",
"'delete'",
")",
".",
"'</th>'",
";",
"echo",
"'</tr>'",
";",
"$",
"this",
"->",
"_row",
"=",
"null",
";",
"}"
] | Print table header.
@return void | [
"Print",
"table",
"header",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/uploaduser/locallib.php#L65-L83 |
214,006 | moodle/moodle | admin/tool/uploaduser/locallib.php | uu_progress_tracker.flush | public function flush() {
if (empty($this->_row) or empty($this->_row['line']['normal'])) {
// Nothing to print - each line has to have at least number
$this->_row = array();
foreach ($this->columns as $col) {
$this->_row[$col] = array('normal'=>'', 'info'=>'', 'warning'=>'', 'error'=>'');
}
return;
}
$ci = 0;
$ri = 1;
echo '<tr class="r'.$ri.'">';
foreach ($this->_row as $key=>$field) {
foreach ($field as $type=>$content) {
if ($field[$type] !== '') {
$field[$type] = '<span class="uu'.$type.'">'.$field[$type].'</span>';
} else {
unset($field[$type]);
}
}
echo '<td class="cell c'.$ci++.'">';
if (!empty($field)) {
echo implode('<br />', $field);
} else {
echo ' ';
}
echo '</td>';
}
echo '</tr>';
foreach ($this->columns as $col) {
$this->_row[$col] = array('normal'=>'', 'info'=>'', 'warning'=>'', 'error'=>'');
}
} | php | public function flush() {
if (empty($this->_row) or empty($this->_row['line']['normal'])) {
// Nothing to print - each line has to have at least number
$this->_row = array();
foreach ($this->columns as $col) {
$this->_row[$col] = array('normal'=>'', 'info'=>'', 'warning'=>'', 'error'=>'');
}
return;
}
$ci = 0;
$ri = 1;
echo '<tr class="r'.$ri.'">';
foreach ($this->_row as $key=>$field) {
foreach ($field as $type=>$content) {
if ($field[$type] !== '') {
$field[$type] = '<span class="uu'.$type.'">'.$field[$type].'</span>';
} else {
unset($field[$type]);
}
}
echo '<td class="cell c'.$ci++.'">';
if (!empty($field)) {
echo implode('<br />', $field);
} else {
echo ' ';
}
echo '</td>';
}
echo '</tr>';
foreach ($this->columns as $col) {
$this->_row[$col] = array('normal'=>'', 'info'=>'', 'warning'=>'', 'error'=>'');
}
} | [
"public",
"function",
"flush",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_row",
")",
"or",
"empty",
"(",
"$",
"this",
"->",
"_row",
"[",
"'line'",
"]",
"[",
"'normal'",
"]",
")",
")",
"{",
"// Nothing to print - each line has to have at least number",
"$",
"this",
"->",
"_row",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"columns",
"as",
"$",
"col",
")",
"{",
"$",
"this",
"->",
"_row",
"[",
"$",
"col",
"]",
"=",
"array",
"(",
"'normal'",
"=>",
"''",
",",
"'info'",
"=>",
"''",
",",
"'warning'",
"=>",
"''",
",",
"'error'",
"=>",
"''",
")",
";",
"}",
"return",
";",
"}",
"$",
"ci",
"=",
"0",
";",
"$",
"ri",
"=",
"1",
";",
"echo",
"'<tr class=\"r'",
".",
"$",
"ri",
".",
"'\">'",
";",
"foreach",
"(",
"$",
"this",
"->",
"_row",
"as",
"$",
"key",
"=>",
"$",
"field",
")",
"{",
"foreach",
"(",
"$",
"field",
"as",
"$",
"type",
"=>",
"$",
"content",
")",
"{",
"if",
"(",
"$",
"field",
"[",
"$",
"type",
"]",
"!==",
"''",
")",
"{",
"$",
"field",
"[",
"$",
"type",
"]",
"=",
"'<span class=\"uu'",
".",
"$",
"type",
".",
"'\">'",
".",
"$",
"field",
"[",
"$",
"type",
"]",
".",
"'</span>'",
";",
"}",
"else",
"{",
"unset",
"(",
"$",
"field",
"[",
"$",
"type",
"]",
")",
";",
"}",
"}",
"echo",
"'<td class=\"cell c'",
".",
"$",
"ci",
"++",
".",
"'\">'",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"field",
")",
")",
"{",
"echo",
"implode",
"(",
"'<br />'",
",",
"$",
"field",
")",
";",
"}",
"else",
"{",
"echo",
"' '",
";",
"}",
"echo",
"'</td>'",
";",
"}",
"echo",
"'</tr>'",
";",
"foreach",
"(",
"$",
"this",
"->",
"columns",
"as",
"$",
"col",
")",
"{",
"$",
"this",
"->",
"_row",
"[",
"$",
"col",
"]",
"=",
"array",
"(",
"'normal'",
"=>",
"''",
",",
"'info'",
"=>",
"''",
",",
"'warning'",
"=>",
"''",
",",
"'error'",
"=>",
"''",
")",
";",
"}",
"}"
] | Flush previous line and start a new one.
@return void | [
"Flush",
"previous",
"line",
"and",
"start",
"a",
"new",
"one",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/uploaduser/locallib.php#L89-L121 |
214,007 | moodle/moodle | admin/tool/uploaduser/locallib.php | uu_progress_tracker.track | public function track($col, $msg, $level = 'normal', $merge = true) {
if (empty($this->_row)) {
$this->flush(); //init arrays
}
if (!in_array($col, $this->columns)) {
debugging('Incorrect column:'.$col);
return;
}
if ($merge) {
if ($this->_row[$col][$level] != '') {
$this->_row[$col][$level] .='<br />';
}
$this->_row[$col][$level] .= $msg;
} else {
$this->_row[$col][$level] = $msg;
}
} | php | public function track($col, $msg, $level = 'normal', $merge = true) {
if (empty($this->_row)) {
$this->flush(); //init arrays
}
if (!in_array($col, $this->columns)) {
debugging('Incorrect column:'.$col);
return;
}
if ($merge) {
if ($this->_row[$col][$level] != '') {
$this->_row[$col][$level] .='<br />';
}
$this->_row[$col][$level] .= $msg;
} else {
$this->_row[$col][$level] = $msg;
}
} | [
"public",
"function",
"track",
"(",
"$",
"col",
",",
"$",
"msg",
",",
"$",
"level",
"=",
"'normal'",
",",
"$",
"merge",
"=",
"true",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_row",
")",
")",
"{",
"$",
"this",
"->",
"flush",
"(",
")",
";",
"//init arrays",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"col",
",",
"$",
"this",
"->",
"columns",
")",
")",
"{",
"debugging",
"(",
"'Incorrect column:'",
".",
"$",
"col",
")",
";",
"return",
";",
"}",
"if",
"(",
"$",
"merge",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_row",
"[",
"$",
"col",
"]",
"[",
"$",
"level",
"]",
"!=",
"''",
")",
"{",
"$",
"this",
"->",
"_row",
"[",
"$",
"col",
"]",
"[",
"$",
"level",
"]",
".=",
"'<br />'",
";",
"}",
"$",
"this",
"->",
"_row",
"[",
"$",
"col",
"]",
"[",
"$",
"level",
"]",
".=",
"$",
"msg",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_row",
"[",
"$",
"col",
"]",
"[",
"$",
"level",
"]",
"=",
"$",
"msg",
";",
"}",
"}"
] | Add tracking info
@param string $col name of column
@param string $msg message
@param string $level 'normal', 'warning' or 'error'
@param bool $merge true means add as new line, false means override all previous text of the same type
@return void | [
"Add",
"tracking",
"info"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/uploaduser/locallib.php#L131-L147 |
214,008 | moodle/moodle | question/format/blackboard_six/format.php | qformat_blackboard_six.get_filecontent | public function get_filecontent($path) {
$fullpath = $this->tempdir . '/' . $path;
if (is_file($fullpath) && is_readable($fullpath)) {
return file_get_contents($fullpath);
}
return false;
} | php | public function get_filecontent($path) {
$fullpath = $this->tempdir . '/' . $path;
if (is_file($fullpath) && is_readable($fullpath)) {
return file_get_contents($fullpath);
}
return false;
} | [
"public",
"function",
"get_filecontent",
"(",
"$",
"path",
")",
"{",
"$",
"fullpath",
"=",
"$",
"this",
"->",
"tempdir",
".",
"'/'",
".",
"$",
"path",
";",
"if",
"(",
"is_file",
"(",
"$",
"fullpath",
")",
"&&",
"is_readable",
"(",
"$",
"fullpath",
")",
")",
"{",
"return",
"file_get_contents",
"(",
"$",
"fullpath",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Return the content of a file given by its path in the tempdir directory.
@param string $path path to the file inside tempdir
@return mixed contents array or false on failure | [
"Return",
"the",
"content",
"of",
"a",
"file",
"given",
"by",
"its",
"path",
"in",
"the",
"tempdir",
"directory",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/format/blackboard_six/format.php#L67-L73 |
214,009 | moodle/moodle | lib/simplepie/library/SimplePie/Cache.php | SimplePie_Cache.parse_URL | public static function parse_URL($url)
{
$params = parse_url($url);
$params['extras'] = array();
if (isset($params['query']))
{
parse_str($params['query'], $params['extras']);
}
return $params;
} | php | public static function parse_URL($url)
{
$params = parse_url($url);
$params['extras'] = array();
if (isset($params['query']))
{
parse_str($params['query'], $params['extras']);
}
return $params;
} | [
"public",
"static",
"function",
"parse_URL",
"(",
"$",
"url",
")",
"{",
"$",
"params",
"=",
"parse_url",
"(",
"$",
"url",
")",
";",
"$",
"params",
"[",
"'extras'",
"]",
"=",
"array",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'query'",
"]",
")",
")",
"{",
"parse_str",
"(",
"$",
"params",
"[",
"'query'",
"]",
",",
"$",
"params",
"[",
"'extras'",
"]",
")",
";",
"}",
"return",
"$",
"params",
";",
"}"
] | Parse a URL into an array
@param string $url
@return array | [
"Parse",
"a",
"URL",
"into",
"an",
"array"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/Cache.php#L124-L133 |
214,010 | moodle/moodle | admin/tool/usertours/classes/output/tour.php | tour.export_for_template | public function export_for_template(\renderer_base $output) {
$result = (object) [
'name' => $this->tour->get_tour_key(),
'steps' => [],
];
foreach ($this->tour->get_steps() as $step) {
$result->steps[] = (new step($step))->export_for_template($output);
}
return $result;
} | php | public function export_for_template(\renderer_base $output) {
$result = (object) [
'name' => $this->tour->get_tour_key(),
'steps' => [],
];
foreach ($this->tour->get_steps() as $step) {
$result->steps[] = (new step($step))->export_for_template($output);
}
return $result;
} | [
"public",
"function",
"export_for_template",
"(",
"\\",
"renderer_base",
"$",
"output",
")",
"{",
"$",
"result",
"=",
"(",
"object",
")",
"[",
"'name'",
"=>",
"$",
"this",
"->",
"tour",
"->",
"get_tour_key",
"(",
")",
",",
"'steps'",
"=>",
"[",
"]",
",",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"tour",
"->",
"get_steps",
"(",
")",
"as",
"$",
"step",
")",
"{",
"$",
"result",
"->",
"steps",
"[",
"]",
"=",
"(",
"new",
"step",
"(",
"$",
"step",
")",
")",
"->",
"export_for_template",
"(",
"$",
"output",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Prepare the data for export.
@param \renderer_base $output The output renderable.
@return object | [
"Prepare",
"the",
"data",
"for",
"export",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/output/tour.php#L59-L70 |
214,011 | moodle/moodle | lib/horde/framework/Horde/Stream/Wrapper/String.php | Horde_Stream_Wrapper_String.getStream | public static function getStream(&$string)
{
if (!self::$_id) {
stream_wrapper_register(self::WRAPPER_NAME, __CLASS__);
}
/* Needed to keep reference. */
$ob = new stdClass;
$ob->string = &$string;
return fopen(
self::WRAPPER_NAME . '://' . ++self::$_id,
'wb',
false,
stream_context_create(array(
self::WRAPPER_NAME => array(
'string' => $ob
)
))
);
} | php | public static function getStream(&$string)
{
if (!self::$_id) {
stream_wrapper_register(self::WRAPPER_NAME, __CLASS__);
}
/* Needed to keep reference. */
$ob = new stdClass;
$ob->string = &$string;
return fopen(
self::WRAPPER_NAME . '://' . ++self::$_id,
'wb',
false,
stream_context_create(array(
self::WRAPPER_NAME => array(
'string' => $ob
)
))
);
} | [
"public",
"static",
"function",
"getStream",
"(",
"&",
"$",
"string",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"_id",
")",
"{",
"stream_wrapper_register",
"(",
"self",
"::",
"WRAPPER_NAME",
",",
"__CLASS__",
")",
";",
"}",
"/* Needed to keep reference. */",
"$",
"ob",
"=",
"new",
"stdClass",
";",
"$",
"ob",
"->",
"string",
"=",
"&",
"$",
"string",
";",
"return",
"fopen",
"(",
"self",
"::",
"WRAPPER_NAME",
".",
"'://'",
".",
"++",
"self",
"::",
"$",
"_id",
",",
"'wb'",
",",
"false",
",",
"stream_context_create",
"(",
"array",
"(",
"self",
"::",
"WRAPPER_NAME",
"=>",
"array",
"(",
"'string'",
"=>",
"$",
"ob",
")",
")",
")",
")",
";",
"}"
] | Create a stream from a PHP string.
@since 2.1.0
@param string &$string A PHP string variable.
@return resource A PHP stream pointing to the variable. | [
"Create",
"a",
"stream",
"from",
"a",
"PHP",
"string",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Stream/Wrapper/String.php#L66-L86 |
214,012 | moodle/moodle | lib/google/src/Google/Http/REST.php | Google_Http_REST.doExecute | public static function doExecute(Google_Client $client, Google_Http_Request $req)
{
$httpRequest = $client->getIo()->makeRequest($req);
$httpRequest->setExpectedClass($req->getExpectedClass());
return self::decodeHttpResponse($httpRequest, $client);
} | php | public static function doExecute(Google_Client $client, Google_Http_Request $req)
{
$httpRequest = $client->getIo()->makeRequest($req);
$httpRequest->setExpectedClass($req->getExpectedClass());
return self::decodeHttpResponse($httpRequest, $client);
} | [
"public",
"static",
"function",
"doExecute",
"(",
"Google_Client",
"$",
"client",
",",
"Google_Http_Request",
"$",
"req",
")",
"{",
"$",
"httpRequest",
"=",
"$",
"client",
"->",
"getIo",
"(",
")",
"->",
"makeRequest",
"(",
"$",
"req",
")",
";",
"$",
"httpRequest",
"->",
"setExpectedClass",
"(",
"$",
"req",
"->",
"getExpectedClass",
"(",
")",
")",
";",
"return",
"self",
"::",
"decodeHttpResponse",
"(",
"$",
"httpRequest",
",",
"$",
"client",
")",
";",
"}"
] | Executes a Google_Http_Request
@param Google_Client $client
@param Google_Http_Request $req
@return array decoded result
@throws Google_Service_Exception on server side error (ie: not authenticated,
invalid or malformed post body, invalid url) | [
"Executes",
"a",
"Google_Http_Request"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/google/src/Google/Http/REST.php#L58-L63 |
214,013 | moodle/moodle | lib/classes/event/competency_user_competency_viewed_in_course.php | competency_user_competency_viewed_in_course.create_from_user_competency_viewed_in_course | public static function create_from_user_competency_viewed_in_course(user_competency_course $usercompetencycourse) {
if (!$usercompetencycourse->get('id')) {
throw new \coding_exception('The user competency course ID must be set.');
}
$params = array(
'objectid' => $usercompetencycourse->get('id'),
'relateduserid' => $usercompetencycourse->get('userid'),
'other' => array(
'competencyid' => $usercompetencycourse->get('competencyid')
)
);
$coursecontext = context_course::instance($usercompetencycourse->get('courseid'));
$params['contextid'] = $coursecontext->id;
$params['courseid'] = $usercompetencycourse->get('courseid');
$event = static::create($params);
$event->add_record_snapshot(user_competency_course::TABLE, $usercompetencycourse->to_record());
return $event;
} | php | public static function create_from_user_competency_viewed_in_course(user_competency_course $usercompetencycourse) {
if (!$usercompetencycourse->get('id')) {
throw new \coding_exception('The user competency course ID must be set.');
}
$params = array(
'objectid' => $usercompetencycourse->get('id'),
'relateduserid' => $usercompetencycourse->get('userid'),
'other' => array(
'competencyid' => $usercompetencycourse->get('competencyid')
)
);
$coursecontext = context_course::instance($usercompetencycourse->get('courseid'));
$params['contextid'] = $coursecontext->id;
$params['courseid'] = $usercompetencycourse->get('courseid');
$event = static::create($params);
$event->add_record_snapshot(user_competency_course::TABLE, $usercompetencycourse->to_record());
return $event;
} | [
"public",
"static",
"function",
"create_from_user_competency_viewed_in_course",
"(",
"user_competency_course",
"$",
"usercompetencycourse",
")",
"{",
"if",
"(",
"!",
"$",
"usercompetencycourse",
"->",
"get",
"(",
"'id'",
")",
")",
"{",
"throw",
"new",
"\\",
"coding_exception",
"(",
"'The user competency course ID must be set.'",
")",
";",
"}",
"$",
"params",
"=",
"array",
"(",
"'objectid'",
"=>",
"$",
"usercompetencycourse",
"->",
"get",
"(",
"'id'",
")",
",",
"'relateduserid'",
"=>",
"$",
"usercompetencycourse",
"->",
"get",
"(",
"'userid'",
")",
",",
"'other'",
"=>",
"array",
"(",
"'competencyid'",
"=>",
"$",
"usercompetencycourse",
"->",
"get",
"(",
"'competencyid'",
")",
")",
")",
";",
"$",
"coursecontext",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"usercompetencycourse",
"->",
"get",
"(",
"'courseid'",
")",
")",
";",
"$",
"params",
"[",
"'contextid'",
"]",
"=",
"$",
"coursecontext",
"->",
"id",
";",
"$",
"params",
"[",
"'courseid'",
"]",
"=",
"$",
"usercompetencycourse",
"->",
"get",
"(",
"'courseid'",
")",
";",
"$",
"event",
"=",
"static",
"::",
"create",
"(",
"$",
"params",
")",
";",
"$",
"event",
"->",
"add_record_snapshot",
"(",
"user_competency_course",
"::",
"TABLE",
",",
"$",
"usercompetencycourse",
"->",
"to_record",
"(",
")",
")",
";",
"return",
"$",
"event",
";",
"}"
] | Convenience method to instantiate the event in course.
@param user_competency_course $usercompetencycourse The user competency for the course.
@return self | [
"Convenience",
"method",
"to",
"instantiate",
"the",
"event",
"in",
"course",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/event/competency_user_competency_viewed_in_course.php#L54-L72 |
214,014 | moodle/moodle | completion/data_object.php | data_object.load_optional_fields | public function load_optional_fields() {
global $DB;
foreach ($this->optional_fields as $field=>$default) {
if (property_exists($this, $field)) {
continue;
}
if (empty($this->id)) {
$this->$field = $default;
} else {
$this->$field = $DB->get_field($this->table, $field, array('id', $this->id));
}
}
} | php | public function load_optional_fields() {
global $DB;
foreach ($this->optional_fields as $field=>$default) {
if (property_exists($this, $field)) {
continue;
}
if (empty($this->id)) {
$this->$field = $default;
} else {
$this->$field = $DB->get_field($this->table, $field, array('id', $this->id));
}
}
} | [
"public",
"function",
"load_optional_fields",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"foreach",
"(",
"$",
"this",
"->",
"optional_fields",
"as",
"$",
"field",
"=>",
"$",
"default",
")",
"{",
"if",
"(",
"property_exists",
"(",
"$",
"this",
",",
"$",
"field",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"id",
")",
")",
"{",
"$",
"this",
"->",
"$",
"field",
"=",
"$",
"default",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"$",
"field",
"=",
"$",
"DB",
"->",
"get_field",
"(",
"$",
"this",
"->",
"table",
",",
"$",
"field",
",",
"array",
"(",
"'id'",
",",
"$",
"this",
"->",
"id",
")",
")",
";",
"}",
"}",
"}"
] | Makes sure all the optional fields are loaded.
If id present (==instance exists in db) fetches data from db.
Defaults are used for new instances. | [
"Makes",
"sure",
"all",
"the",
"optional",
"fields",
"are",
"loaded",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/data_object.php#L138-L150 |
214,015 | moodle/moodle | completion/data_object.php | data_object.fetch_helper | protected static function fetch_helper($table, $classname, $params) {
if ($instances = self::fetch_all_helper($table, $classname, $params)) {
if (count($instances) > 1) {
// we should not tolerate any errors here - problems might appear later
print_error('morethanonerecordinfetch','debug');
}
return reset($instances);
} else {
return false;
}
} | php | protected static function fetch_helper($table, $classname, $params) {
if ($instances = self::fetch_all_helper($table, $classname, $params)) {
if (count($instances) > 1) {
// we should not tolerate any errors here - problems might appear later
print_error('morethanonerecordinfetch','debug');
}
return reset($instances);
} else {
return false;
}
} | [
"protected",
"static",
"function",
"fetch_helper",
"(",
"$",
"table",
",",
"$",
"classname",
",",
"$",
"params",
")",
"{",
"if",
"(",
"$",
"instances",
"=",
"self",
"::",
"fetch_all_helper",
"(",
"$",
"table",
",",
"$",
"classname",
",",
"$",
"params",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"instances",
")",
">",
"1",
")",
"{",
"// we should not tolerate any errors here - problems might appear later",
"print_error",
"(",
"'morethanonerecordinfetch'",
",",
"'debug'",
")",
";",
"}",
"return",
"reset",
"(",
"$",
"instances",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Factory method - uses the parameters to retrieve matching instance from the DB.
@final
@param string $table The table name to fetch from
@param string $classname The class that you want the result instantiated as
@param array $params Any params required to select the desired row
@return object Instance of $classname or false. | [
"Factory",
"method",
"-",
"uses",
"the",
"parameters",
"to",
"retrieve",
"matching",
"instance",
"from",
"the",
"DB",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/data_object.php#L187-L197 |
214,016 | moodle/moodle | completion/data_object.php | data_object.fetch_all_helper | public static function fetch_all_helper($table, $classname, $params) {
$instance = new $classname();
$classvars = (array)$instance;
$params = (array)$params;
$wheresql = array();
$dbparams = array();
foreach ($params as $var=>$value) {
if (!in_array($var, $instance->required_fields) and !array_key_exists($var, $instance->optional_fields)) {
continue;
}
if (is_null($value)) {
$wheresql[] = " $var IS NULL ";
} else {
$wheresql[] = " $var = ? ";
$dbparams[] = $value;
}
}
if (empty($wheresql)) {
$wheresql = '';
} else {
$wheresql = implode("AND", $wheresql);
}
global $DB;
if ($datas = $DB->get_records_select($table, $wheresql, $dbparams)) {
$result = array();
foreach($datas as $data) {
$instance = new $classname();
self::set_properties($instance, $data);
$result[$instance->id] = $instance;
}
return $result;
} else {
return false;
}
} | php | public static function fetch_all_helper($table, $classname, $params) {
$instance = new $classname();
$classvars = (array)$instance;
$params = (array)$params;
$wheresql = array();
$dbparams = array();
foreach ($params as $var=>$value) {
if (!in_array($var, $instance->required_fields) and !array_key_exists($var, $instance->optional_fields)) {
continue;
}
if (is_null($value)) {
$wheresql[] = " $var IS NULL ";
} else {
$wheresql[] = " $var = ? ";
$dbparams[] = $value;
}
}
if (empty($wheresql)) {
$wheresql = '';
} else {
$wheresql = implode("AND", $wheresql);
}
global $DB;
if ($datas = $DB->get_records_select($table, $wheresql, $dbparams)) {
$result = array();
foreach($datas as $data) {
$instance = new $classname();
self::set_properties($instance, $data);
$result[$instance->id] = $instance;
}
return $result;
} else {
return false;
}
} | [
"public",
"static",
"function",
"fetch_all_helper",
"(",
"$",
"table",
",",
"$",
"classname",
",",
"$",
"params",
")",
"{",
"$",
"instance",
"=",
"new",
"$",
"classname",
"(",
")",
";",
"$",
"classvars",
"=",
"(",
"array",
")",
"$",
"instance",
";",
"$",
"params",
"=",
"(",
"array",
")",
"$",
"params",
";",
"$",
"wheresql",
"=",
"array",
"(",
")",
";",
"$",
"dbparams",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"var",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"var",
",",
"$",
"instance",
"->",
"required_fields",
")",
"and",
"!",
"array_key_exists",
"(",
"$",
"var",
",",
"$",
"instance",
"->",
"optional_fields",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"value",
")",
")",
"{",
"$",
"wheresql",
"[",
"]",
"=",
"\" $var IS NULL \"",
";",
"}",
"else",
"{",
"$",
"wheresql",
"[",
"]",
"=",
"\" $var = ? \"",
";",
"$",
"dbparams",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"wheresql",
")",
")",
"{",
"$",
"wheresql",
"=",
"''",
";",
"}",
"else",
"{",
"$",
"wheresql",
"=",
"implode",
"(",
"\"AND\"",
",",
"$",
"wheresql",
")",
";",
"}",
"global",
"$",
"DB",
";",
"if",
"(",
"$",
"datas",
"=",
"$",
"DB",
"->",
"get_records_select",
"(",
"$",
"table",
",",
"$",
"wheresql",
",",
"$",
"dbparams",
")",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"datas",
"as",
"$",
"data",
")",
"{",
"$",
"instance",
"=",
"new",
"$",
"classname",
"(",
")",
";",
"self",
"::",
"set_properties",
"(",
"$",
"instance",
",",
"$",
"data",
")",
";",
"$",
"result",
"[",
"$",
"instance",
"->",
"id",
"]",
"=",
"$",
"instance",
";",
"}",
"return",
"$",
"result",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Factory method - uses the parameters to retrieve all matching instances from the DB.
@final
@param string $table The table name to fetch from
@param string $classname The class that you want the result instantiated as
@param array $params Any params required to select the desired row
@return mixed array of object instances or false if not found | [
"Factory",
"method",
"-",
"uses",
"the",
"parameters",
"to",
"retrieve",
"all",
"matching",
"instances",
"from",
"the",
"DB",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/data_object.php#L208-L250 |
214,017 | moodle/moodle | completion/data_object.php | data_object.get_record_data | public function get_record_data() {
$data = new stdClass();
foreach ($this as $var=>$value) {
if (in_array($var, $this->required_fields) or array_key_exists($var, $this->optional_fields)) {
if (is_object($value) or is_array($value)) {
debugging("Incorrect property '$var' found when inserting data object");
} else {
$data->$var = $value;
}
}
}
return $data;
} | php | public function get_record_data() {
$data = new stdClass();
foreach ($this as $var=>$value) {
if (in_array($var, $this->required_fields) or array_key_exists($var, $this->optional_fields)) {
if (is_object($value) or is_array($value)) {
debugging("Incorrect property '$var' found when inserting data object");
} else {
$data->$var = $value;
}
}
}
return $data;
} | [
"public",
"function",
"get_record_data",
"(",
")",
"{",
"$",
"data",
"=",
"new",
"stdClass",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"as",
"$",
"var",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"var",
",",
"$",
"this",
"->",
"required_fields",
")",
"or",
"array_key_exists",
"(",
"$",
"var",
",",
"$",
"this",
"->",
"optional_fields",
")",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"value",
")",
"or",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"debugging",
"(",
"\"Incorrect property '$var' found when inserting data object\"",
")",
";",
"}",
"else",
"{",
"$",
"data",
"->",
"$",
"var",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | Returns object with fields and values that are defined in database
@return stdClass | [
"Returns",
"object",
"with",
"fields",
"and",
"values",
"that",
"are",
"defined",
"in",
"database"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/data_object.php#L302-L315 |
214,018 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_handlers_factory.get_plugin_handlers | protected static function get_plugin_handlers($type, moodle1_converter $converter) {
global $CFG;
$handlers = array();
$plugins = core_component::get_plugin_list($type);
foreach ($plugins as $name => $dir) {
$handlerfile = $dir . '/backup/moodle1/lib.php';
$handlerclass = "moodle1_{$type}_{$name}_handler";
if (file_exists($handlerfile)) {
require_once($handlerfile);
} elseif ($type == 'block') {
$handlerclass = "moodle1_block_generic_handler";
} else {
continue;
}
if (!class_exists($handlerclass)) {
throw new moodle1_convert_exception('missing_handler_class', $handlerclass);
}
$handlers[] = new $handlerclass($converter, $type, $name);
}
return $handlers;
} | php | protected static function get_plugin_handlers($type, moodle1_converter $converter) {
global $CFG;
$handlers = array();
$plugins = core_component::get_plugin_list($type);
foreach ($plugins as $name => $dir) {
$handlerfile = $dir . '/backup/moodle1/lib.php';
$handlerclass = "moodle1_{$type}_{$name}_handler";
if (file_exists($handlerfile)) {
require_once($handlerfile);
} elseif ($type == 'block') {
$handlerclass = "moodle1_block_generic_handler";
} else {
continue;
}
if (!class_exists($handlerclass)) {
throw new moodle1_convert_exception('missing_handler_class', $handlerclass);
}
$handlers[] = new $handlerclass($converter, $type, $name);
}
return $handlers;
} | [
"protected",
"static",
"function",
"get_plugin_handlers",
"(",
"$",
"type",
",",
"moodle1_converter",
"$",
"converter",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"handlers",
"=",
"array",
"(",
")",
";",
"$",
"plugins",
"=",
"core_component",
"::",
"get_plugin_list",
"(",
"$",
"type",
")",
";",
"foreach",
"(",
"$",
"plugins",
"as",
"$",
"name",
"=>",
"$",
"dir",
")",
"{",
"$",
"handlerfile",
"=",
"$",
"dir",
".",
"'/backup/moodle1/lib.php'",
";",
"$",
"handlerclass",
"=",
"\"moodle1_{$type}_{$name}_handler\"",
";",
"if",
"(",
"file_exists",
"(",
"$",
"handlerfile",
")",
")",
"{",
"require_once",
"(",
"$",
"handlerfile",
")",
";",
"}",
"elseif",
"(",
"$",
"type",
"==",
"'block'",
")",
"{",
"$",
"handlerclass",
"=",
"\"moodle1_block_generic_handler\"",
";",
"}",
"else",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"handlerclass",
")",
")",
"{",
"throw",
"new",
"moodle1_convert_exception",
"(",
"'missing_handler_class'",
",",
"$",
"handlerclass",
")",
";",
"}",
"$",
"handlers",
"[",
"]",
"=",
"new",
"$",
"handlerclass",
"(",
"$",
"converter",
",",
"$",
"type",
",",
"$",
"name",
")",
";",
"}",
"return",
"$",
"handlers",
";",
"}"
] | Runs through all plugins of a specific type and instantiates their handlers
@todo ask mod's subplugins
@param string $type the plugin type
@param moodle1_converter $converter the converter requesting the handler
@throws moodle1_convert_exception
@return array of {@link moodle1_handler} instances | [
"Runs",
"through",
"all",
"plugins",
"of",
"a",
"specific",
"type",
"and",
"instantiates",
"their",
"handlers"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L83-L105 |
214,019 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_xml_handler.close_xml_writer | protected function close_xml_writer() {
if ($this->xmlwriter instanceof xml_writer) {
$this->xmlwriter->stop();
}
unset($this->xmlwriter);
$this->xmlwriter = null;
$this->xmlfilename = null;
} | php | protected function close_xml_writer() {
if ($this->xmlwriter instanceof xml_writer) {
$this->xmlwriter->stop();
}
unset($this->xmlwriter);
$this->xmlwriter = null;
$this->xmlfilename = null;
} | [
"protected",
"function",
"close_xml_writer",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"xmlwriter",
"instanceof",
"xml_writer",
")",
"{",
"$",
"this",
"->",
"xmlwriter",
"->",
"stop",
"(",
")",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"xmlwriter",
")",
";",
"$",
"this",
"->",
"xmlwriter",
"=",
"null",
";",
"$",
"this",
"->",
"xmlfilename",
"=",
"null",
";",
"}"
] | Close the XML writer
At the moment, the caller must close all tags before calling
@return void | [
"Close",
"the",
"XML",
"writer"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L189-L196 |
214,020 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_xml_handler.write_xml | protected function write_xml($element, array $data, array $attribs = array(), $parent = '/') {
if (!$this->has_xml_writer()) {
throw new moodle1_convert_exception('write_xml_without_writer');
}
$mypath = $parent . $element;
$myattribs = array();
// detect properties that should be rendered as element's attributes instead of children
foreach ($data as $name => $value) {
if (!is_array($value)) {
if (in_array($mypath . '/' . $name, $attribs)) {
$myattribs[$name] = $value;
unset($data[$name]);
}
}
}
// reorder the $data so that all sub-branches are at the end (needed by our parser)
$leaves = array();
$branches = array();
foreach ($data as $name => $value) {
if (is_array($value)) {
$branches[$name] = $value;
} else {
$leaves[$name] = $value;
}
}
$data = array_merge($leaves, $branches);
$this->xmlwriter->begin_tag($element, $myattribs);
foreach ($data as $name => $value) {
if (is_array($value)) {
// recursively call self
$this->write_xml($name, $value, $attribs, $mypath.'/');
} else {
$this->xmlwriter->full_tag($name, $value);
}
}
$this->xmlwriter->end_tag($element);
} | php | protected function write_xml($element, array $data, array $attribs = array(), $parent = '/') {
if (!$this->has_xml_writer()) {
throw new moodle1_convert_exception('write_xml_without_writer');
}
$mypath = $parent . $element;
$myattribs = array();
// detect properties that should be rendered as element's attributes instead of children
foreach ($data as $name => $value) {
if (!is_array($value)) {
if (in_array($mypath . '/' . $name, $attribs)) {
$myattribs[$name] = $value;
unset($data[$name]);
}
}
}
// reorder the $data so that all sub-branches are at the end (needed by our parser)
$leaves = array();
$branches = array();
foreach ($data as $name => $value) {
if (is_array($value)) {
$branches[$name] = $value;
} else {
$leaves[$name] = $value;
}
}
$data = array_merge($leaves, $branches);
$this->xmlwriter->begin_tag($element, $myattribs);
foreach ($data as $name => $value) {
if (is_array($value)) {
// recursively call self
$this->write_xml($name, $value, $attribs, $mypath.'/');
} else {
$this->xmlwriter->full_tag($name, $value);
}
}
$this->xmlwriter->end_tag($element);
} | [
"protected",
"function",
"write_xml",
"(",
"$",
"element",
",",
"array",
"$",
"data",
",",
"array",
"$",
"attribs",
"=",
"array",
"(",
")",
",",
"$",
"parent",
"=",
"'/'",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"has_xml_writer",
"(",
")",
")",
"{",
"throw",
"new",
"moodle1_convert_exception",
"(",
"'write_xml_without_writer'",
")",
";",
"}",
"$",
"mypath",
"=",
"$",
"parent",
".",
"$",
"element",
";",
"$",
"myattribs",
"=",
"array",
"(",
")",
";",
"// detect properties that should be rendered as element's attributes instead of children",
"foreach",
"(",
"$",
"data",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"mypath",
".",
"'/'",
".",
"$",
"name",
",",
"$",
"attribs",
")",
")",
"{",
"$",
"myattribs",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"unset",
"(",
"$",
"data",
"[",
"$",
"name",
"]",
")",
";",
"}",
"}",
"}",
"// reorder the $data so that all sub-branches are at the end (needed by our parser)",
"$",
"leaves",
"=",
"array",
"(",
")",
";",
"$",
"branches",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"branches",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"else",
"{",
"$",
"leaves",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"$",
"data",
"=",
"array_merge",
"(",
"$",
"leaves",
",",
"$",
"branches",
")",
";",
"$",
"this",
"->",
"xmlwriter",
"->",
"begin_tag",
"(",
"$",
"element",
",",
"$",
"myattribs",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"// recursively call self",
"$",
"this",
"->",
"write_xml",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"attribs",
",",
"$",
"mypath",
".",
"'/'",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"xmlwriter",
"->",
"full_tag",
"(",
"$",
"name",
",",
"$",
"value",
")",
";",
"}",
"}",
"$",
"this",
"->",
"xmlwriter",
"->",
"end_tag",
"(",
"$",
"element",
")",
";",
"}"
] | Writes the given XML tree data into the currently opened file
@param string $element the name of the root element of the tree
@param array $data the associative array of data to write
@param array $attribs list of additional fields written as attributes instead of nested elements
@param string $parent used internally during the recursion, do not set yourself | [
"Writes",
"the",
"given",
"XML",
"tree",
"data",
"into",
"the",
"currently",
"opened",
"file"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L220-L263 |
214,021 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_xml_handler.make_sure_xml_exists | protected function make_sure_xml_exists($filename, $rootelement = false, $content = array()) {
$existed = file_exists($this->converter->get_workdir_path().'/'.$filename);
if ($existed) {
return true;
}
if ($rootelement !== false) {
$this->open_xml_writer($filename);
$this->write_xml($rootelement, $content);
$this->close_xml_writer();
}
return false;
} | php | protected function make_sure_xml_exists($filename, $rootelement = false, $content = array()) {
$existed = file_exists($this->converter->get_workdir_path().'/'.$filename);
if ($existed) {
return true;
}
if ($rootelement !== false) {
$this->open_xml_writer($filename);
$this->write_xml($rootelement, $content);
$this->close_xml_writer();
}
return false;
} | [
"protected",
"function",
"make_sure_xml_exists",
"(",
"$",
"filename",
",",
"$",
"rootelement",
"=",
"false",
",",
"$",
"content",
"=",
"array",
"(",
")",
")",
"{",
"$",
"existed",
"=",
"file_exists",
"(",
"$",
"this",
"->",
"converter",
"->",
"get_workdir_path",
"(",
")",
".",
"'/'",
".",
"$",
"filename",
")",
";",
"if",
"(",
"$",
"existed",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"rootelement",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"open_xml_writer",
"(",
"$",
"filename",
")",
";",
"$",
"this",
"->",
"write_xml",
"(",
"$",
"rootelement",
",",
"$",
"content",
")",
";",
"$",
"this",
"->",
"close_xml_writer",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Makes sure that a new XML file exists, or creates it itself
This is here so we can check that all XML files that the restore process relies on have
been created by an executed handler. If the file is not found, this method can create it
using the given $rootelement as an empty root container in the file.
@param string $filename relative file name like 'course/course.xml'
@param string|bool $rootelement root element to use, false to not create the file
@param array $content content of the root element
@return bool true is the file existed, false if it did not | [
"Makes",
"sure",
"that",
"a",
"new",
"XML",
"file",
"exists",
"or",
"creates",
"it",
"itself"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L277-L292 |
214,022 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_files_handler.migrate_course_files | protected function migrate_course_files() {
$ids = array();
$fileman = $this->converter->get_file_manager($this->converter->get_contextid(CONTEXT_COURSE), 'course', 'legacy');
$this->converter->set_stash('course_files_ids', array());
if (file_exists($this->converter->get_tempdir_path().'/course_files')) {
$ids = $fileman->migrate_directory('course_files');
$this->converter->set_stash('course_files_ids', $ids);
}
$this->log('course files migrated', backup::LOG_INFO, count($ids));
} | php | protected function migrate_course_files() {
$ids = array();
$fileman = $this->converter->get_file_manager($this->converter->get_contextid(CONTEXT_COURSE), 'course', 'legacy');
$this->converter->set_stash('course_files_ids', array());
if (file_exists($this->converter->get_tempdir_path().'/course_files')) {
$ids = $fileman->migrate_directory('course_files');
$this->converter->set_stash('course_files_ids', $ids);
}
$this->log('course files migrated', backup::LOG_INFO, count($ids));
} | [
"protected",
"function",
"migrate_course_files",
"(",
")",
"{",
"$",
"ids",
"=",
"array",
"(",
")",
";",
"$",
"fileman",
"=",
"$",
"this",
"->",
"converter",
"->",
"get_file_manager",
"(",
"$",
"this",
"->",
"converter",
"->",
"get_contextid",
"(",
"CONTEXT_COURSE",
")",
",",
"'course'",
",",
"'legacy'",
")",
";",
"$",
"this",
"->",
"converter",
"->",
"set_stash",
"(",
"'course_files_ids'",
",",
"array",
"(",
")",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"this",
"->",
"converter",
"->",
"get_tempdir_path",
"(",
")",
".",
"'/course_files'",
")",
")",
"{",
"$",
"ids",
"=",
"$",
"fileman",
"->",
"migrate_directory",
"(",
"'course_files'",
")",
";",
"$",
"this",
"->",
"converter",
"->",
"set_stash",
"(",
"'course_files_ids'",
",",
"$",
"ids",
")",
";",
"}",
"$",
"this",
"->",
"log",
"(",
"'course files migrated'",
",",
"backup",
"::",
"LOG_INFO",
",",
"count",
"(",
"$",
"ids",
")",
")",
";",
"}"
] | Migrates course_files in the converter workdir | [
"Migrates",
"course_files",
"in",
"the",
"converter",
"workdir"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L573-L582 |
214,023 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_course_outline_handler.on_course_modules_end | public function on_course_modules_end() {
foreach ($this->converter->get_stash('modnameslist') as $modname) {
$modinfo = $this->converter->get_stash('modinfo_'.$modname);
foreach ($modinfo['instances'] as $modinstanceid => $modinstance) {
$cminfo = $this->converter->get_stash('cminfo_'.$modname, $modinstanceid);
$directory = 'activities/'.$modname.'_'.$cminfo['id'];
// write module.xml
$this->open_xml_writer($directory.'/module.xml');
$this->write_xml('module', $cminfo, array('/module/id', '/module/version'));
$this->close_xml_writer();
// write grades.xml
$this->open_xml_writer($directory.'/grades.xml');
$this->xmlwriter->begin_tag('activity_gradebook');
$gradeitems = $this->converter->get_stash_or_default('gradebook_modgradeitem_'.$modname, $modinstanceid, array());
if (!empty($gradeitems)) {
$this->xmlwriter->begin_tag('grade_items');
foreach ($gradeitems as $gradeitem) {
$this->write_xml('grade_item', $gradeitem, array('/grade_item/id'));
}
$this->xmlwriter->end_tag('grade_items');
}
$this->write_xml('grade_letters', array()); // no grade_letters in module context in Moodle 1.9
$this->xmlwriter->end_tag('activity_gradebook');
$this->close_xml_writer();
// todo: write proper roles.xml, for now we just make sure the file is present
$this->make_sure_xml_exists($directory.'/roles.xml', 'roles');
}
}
} | php | public function on_course_modules_end() {
foreach ($this->converter->get_stash('modnameslist') as $modname) {
$modinfo = $this->converter->get_stash('modinfo_'.$modname);
foreach ($modinfo['instances'] as $modinstanceid => $modinstance) {
$cminfo = $this->converter->get_stash('cminfo_'.$modname, $modinstanceid);
$directory = 'activities/'.$modname.'_'.$cminfo['id'];
// write module.xml
$this->open_xml_writer($directory.'/module.xml');
$this->write_xml('module', $cminfo, array('/module/id', '/module/version'));
$this->close_xml_writer();
// write grades.xml
$this->open_xml_writer($directory.'/grades.xml');
$this->xmlwriter->begin_tag('activity_gradebook');
$gradeitems = $this->converter->get_stash_or_default('gradebook_modgradeitem_'.$modname, $modinstanceid, array());
if (!empty($gradeitems)) {
$this->xmlwriter->begin_tag('grade_items');
foreach ($gradeitems as $gradeitem) {
$this->write_xml('grade_item', $gradeitem, array('/grade_item/id'));
}
$this->xmlwriter->end_tag('grade_items');
}
$this->write_xml('grade_letters', array()); // no grade_letters in module context in Moodle 1.9
$this->xmlwriter->end_tag('activity_gradebook');
$this->close_xml_writer();
// todo: write proper roles.xml, for now we just make sure the file is present
$this->make_sure_xml_exists($directory.'/roles.xml', 'roles');
}
}
} | [
"public",
"function",
"on_course_modules_end",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"converter",
"->",
"get_stash",
"(",
"'modnameslist'",
")",
"as",
"$",
"modname",
")",
"{",
"$",
"modinfo",
"=",
"$",
"this",
"->",
"converter",
"->",
"get_stash",
"(",
"'modinfo_'",
".",
"$",
"modname",
")",
";",
"foreach",
"(",
"$",
"modinfo",
"[",
"'instances'",
"]",
"as",
"$",
"modinstanceid",
"=>",
"$",
"modinstance",
")",
"{",
"$",
"cminfo",
"=",
"$",
"this",
"->",
"converter",
"->",
"get_stash",
"(",
"'cminfo_'",
".",
"$",
"modname",
",",
"$",
"modinstanceid",
")",
";",
"$",
"directory",
"=",
"'activities/'",
".",
"$",
"modname",
".",
"'_'",
".",
"$",
"cminfo",
"[",
"'id'",
"]",
";",
"// write module.xml",
"$",
"this",
"->",
"open_xml_writer",
"(",
"$",
"directory",
".",
"'/module.xml'",
")",
";",
"$",
"this",
"->",
"write_xml",
"(",
"'module'",
",",
"$",
"cminfo",
",",
"array",
"(",
"'/module/id'",
",",
"'/module/version'",
")",
")",
";",
"$",
"this",
"->",
"close_xml_writer",
"(",
")",
";",
"// write grades.xml",
"$",
"this",
"->",
"open_xml_writer",
"(",
"$",
"directory",
".",
"'/grades.xml'",
")",
";",
"$",
"this",
"->",
"xmlwriter",
"->",
"begin_tag",
"(",
"'activity_gradebook'",
")",
";",
"$",
"gradeitems",
"=",
"$",
"this",
"->",
"converter",
"->",
"get_stash_or_default",
"(",
"'gradebook_modgradeitem_'",
".",
"$",
"modname",
",",
"$",
"modinstanceid",
",",
"array",
"(",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"gradeitems",
")",
")",
"{",
"$",
"this",
"->",
"xmlwriter",
"->",
"begin_tag",
"(",
"'grade_items'",
")",
";",
"foreach",
"(",
"$",
"gradeitems",
"as",
"$",
"gradeitem",
")",
"{",
"$",
"this",
"->",
"write_xml",
"(",
"'grade_item'",
",",
"$",
"gradeitem",
",",
"array",
"(",
"'/grade_item/id'",
")",
")",
";",
"}",
"$",
"this",
"->",
"xmlwriter",
"->",
"end_tag",
"(",
"'grade_items'",
")",
";",
"}",
"$",
"this",
"->",
"write_xml",
"(",
"'grade_letters'",
",",
"array",
"(",
")",
")",
";",
"// no grade_letters in module context in Moodle 1.9",
"$",
"this",
"->",
"xmlwriter",
"->",
"end_tag",
"(",
"'activity_gradebook'",
")",
";",
"$",
"this",
"->",
"close_xml_writer",
"(",
")",
";",
"// todo: write proper roles.xml, for now we just make sure the file is present",
"$",
"this",
"->",
"make_sure_xml_exists",
"(",
"$",
"directory",
".",
"'/roles.xml'",
",",
"'roles'",
")",
";",
"}",
"}",
"}"
] | Writes the information collected by mod handlers | [
"Writes",
"the",
"information",
"collected",
"by",
"mod",
"handlers"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L924-L956 |
214,024 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_roles_definition_handler.process_roles_role | public function process_roles_role($data) {
if (!$this->has_xml_writer()) {
$this->open_xml_writer('roles.xml');
$this->xmlwriter->begin_tag('roles_definition');
}
if (!isset($data['nameincourse'])) {
$data['nameincourse'] = null;
}
$this->write_xml('role', $data, array('role/id'));
} | php | public function process_roles_role($data) {
if (!$this->has_xml_writer()) {
$this->open_xml_writer('roles.xml');
$this->xmlwriter->begin_tag('roles_definition');
}
if (!isset($data['nameincourse'])) {
$data['nameincourse'] = null;
}
$this->write_xml('role', $data, array('role/id'));
} | [
"public",
"function",
"process_roles_role",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"has_xml_writer",
"(",
")",
")",
"{",
"$",
"this",
"->",
"open_xml_writer",
"(",
"'roles.xml'",
")",
";",
"$",
"this",
"->",
"xmlwriter",
"->",
"begin_tag",
"(",
"'roles_definition'",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"'nameincourse'",
"]",
")",
")",
"{",
"$",
"data",
"[",
"'nameincourse'",
"]",
"=",
"null",
";",
"}",
"$",
"this",
"->",
"write_xml",
"(",
"'role'",
",",
"$",
"data",
",",
"array",
"(",
"'role/id'",
")",
")",
";",
"}"
] | If there are any roles defined in moodle.xml, convert them to roles.xml | [
"If",
"there",
"are",
"any",
"roles",
"defined",
"in",
"moodle",
".",
"xml",
"convert",
"them",
"to",
"roles",
".",
"xml"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L987-L997 |
214,025 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_roles_definition_handler.on_roles_end | public function on_roles_end() {
if (!$this->has_xml_writer()) {
// no roles defined in moodle.xml so {link self::process_roles_role()}
// was never executed
$this->open_xml_writer('roles.xml');
$this->write_xml('roles_definition', array());
} else {
// some roles were dumped into the file, let us close their wrapper now
$this->xmlwriter->end_tag('roles_definition');
}
$this->close_xml_writer();
} | php | public function on_roles_end() {
if (!$this->has_xml_writer()) {
// no roles defined in moodle.xml so {link self::process_roles_role()}
// was never executed
$this->open_xml_writer('roles.xml');
$this->write_xml('roles_definition', array());
} else {
// some roles were dumped into the file, let us close their wrapper now
$this->xmlwriter->end_tag('roles_definition');
}
$this->close_xml_writer();
} | [
"public",
"function",
"on_roles_end",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"has_xml_writer",
"(",
")",
")",
"{",
"// no roles defined in moodle.xml so {link self::process_roles_role()}",
"// was never executed",
"$",
"this",
"->",
"open_xml_writer",
"(",
"'roles.xml'",
")",
";",
"$",
"this",
"->",
"write_xml",
"(",
"'roles_definition'",
",",
"array",
"(",
")",
")",
";",
"}",
"else",
"{",
"// some roles were dumped into the file, let us close their wrapper now",
"$",
"this",
"->",
"xmlwriter",
"->",
"end_tag",
"(",
"'roles_definition'",
")",
";",
"}",
"$",
"this",
"->",
"close_xml_writer",
"(",
")",
";",
"}"
] | Finishes writing roles.xml | [
"Finishes",
"writing",
"roles",
".",
"xml"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L1002-L1015 |
214,026 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_question_bank_handler.get_paths | public function get_paths() {
$paths = array(
new convert_path('question_categories', '/MOODLE_BACKUP/COURSE/QUESTION_CATEGORIES'),
new convert_path(
'question_category', '/MOODLE_BACKUP/COURSE/QUESTION_CATEGORIES/QUESTION_CATEGORY',
array(
'newfields' => array(
'infoformat' => 0
)
)),
new convert_path('question_category_context', '/MOODLE_BACKUP/COURSE/QUESTION_CATEGORIES/QUESTION_CATEGORY/CONTEXT'),
new convert_path('questions', '/MOODLE_BACKUP/COURSE/QUESTION_CATEGORIES/QUESTION_CATEGORY/QUESTIONS'),
// the question element must be grouped so we can re-dispatch it to the qtype handler as a whole
new convert_path('question', '/MOODLE_BACKUP/COURSE/QUESTION_CATEGORIES/QUESTION_CATEGORY/QUESTIONS/QUESTION', array(), true),
);
// annotate all question subpaths required by the qtypes subplugins
$subpaths = array();
foreach ($this->get_qtype_handler('*') as $qtypehandler) {
foreach ($qtypehandler->get_question_subpaths() as $subpath) {
$subpaths[$subpath] = true;
}
}
foreach (array_keys($subpaths) as $subpath) {
$name = 'subquestion_'.strtolower(str_replace('/', '_', $subpath));
$path = '/MOODLE_BACKUP/COURSE/QUESTION_CATEGORIES/QUESTION_CATEGORY/QUESTIONS/QUESTION/'.$subpath;
$paths[] = new convert_path($name, $path);
}
return $paths;
} | php | public function get_paths() {
$paths = array(
new convert_path('question_categories', '/MOODLE_BACKUP/COURSE/QUESTION_CATEGORIES'),
new convert_path(
'question_category', '/MOODLE_BACKUP/COURSE/QUESTION_CATEGORIES/QUESTION_CATEGORY',
array(
'newfields' => array(
'infoformat' => 0
)
)),
new convert_path('question_category_context', '/MOODLE_BACKUP/COURSE/QUESTION_CATEGORIES/QUESTION_CATEGORY/CONTEXT'),
new convert_path('questions', '/MOODLE_BACKUP/COURSE/QUESTION_CATEGORIES/QUESTION_CATEGORY/QUESTIONS'),
// the question element must be grouped so we can re-dispatch it to the qtype handler as a whole
new convert_path('question', '/MOODLE_BACKUP/COURSE/QUESTION_CATEGORIES/QUESTION_CATEGORY/QUESTIONS/QUESTION', array(), true),
);
// annotate all question subpaths required by the qtypes subplugins
$subpaths = array();
foreach ($this->get_qtype_handler('*') as $qtypehandler) {
foreach ($qtypehandler->get_question_subpaths() as $subpath) {
$subpaths[$subpath] = true;
}
}
foreach (array_keys($subpaths) as $subpath) {
$name = 'subquestion_'.strtolower(str_replace('/', '_', $subpath));
$path = '/MOODLE_BACKUP/COURSE/QUESTION_CATEGORIES/QUESTION_CATEGORY/QUESTIONS/QUESTION/'.$subpath;
$paths[] = new convert_path($name, $path);
}
return $paths;
} | [
"public",
"function",
"get_paths",
"(",
")",
"{",
"$",
"paths",
"=",
"array",
"(",
"new",
"convert_path",
"(",
"'question_categories'",
",",
"'/MOODLE_BACKUP/COURSE/QUESTION_CATEGORIES'",
")",
",",
"new",
"convert_path",
"(",
"'question_category'",
",",
"'/MOODLE_BACKUP/COURSE/QUESTION_CATEGORIES/QUESTION_CATEGORY'",
",",
"array",
"(",
"'newfields'",
"=>",
"array",
"(",
"'infoformat'",
"=>",
"0",
")",
")",
")",
",",
"new",
"convert_path",
"(",
"'question_category_context'",
",",
"'/MOODLE_BACKUP/COURSE/QUESTION_CATEGORIES/QUESTION_CATEGORY/CONTEXT'",
")",
",",
"new",
"convert_path",
"(",
"'questions'",
",",
"'/MOODLE_BACKUP/COURSE/QUESTION_CATEGORIES/QUESTION_CATEGORY/QUESTIONS'",
")",
",",
"// the question element must be grouped so we can re-dispatch it to the qtype handler as a whole",
"new",
"convert_path",
"(",
"'question'",
",",
"'/MOODLE_BACKUP/COURSE/QUESTION_CATEGORIES/QUESTION_CATEGORY/QUESTIONS/QUESTION'",
",",
"array",
"(",
")",
",",
"true",
")",
",",
")",
";",
"// annotate all question subpaths required by the qtypes subplugins",
"$",
"subpaths",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"get_qtype_handler",
"(",
"'*'",
")",
"as",
"$",
"qtypehandler",
")",
"{",
"foreach",
"(",
"$",
"qtypehandler",
"->",
"get_question_subpaths",
"(",
")",
"as",
"$",
"subpath",
")",
"{",
"$",
"subpaths",
"[",
"$",
"subpath",
"]",
"=",
"true",
";",
"}",
"}",
"foreach",
"(",
"array_keys",
"(",
"$",
"subpaths",
")",
"as",
"$",
"subpath",
")",
"{",
"$",
"name",
"=",
"'subquestion_'",
".",
"strtolower",
"(",
"str_replace",
"(",
"'/'",
",",
"'_'",
",",
"$",
"subpath",
")",
")",
";",
"$",
"path",
"=",
"'/MOODLE_BACKUP/COURSE/QUESTION_CATEGORIES/QUESTION_CATEGORY/QUESTIONS/QUESTION/'",
".",
"$",
"subpath",
";",
"$",
"paths",
"[",
"]",
"=",
"new",
"convert_path",
"(",
"$",
"name",
",",
"$",
"path",
")",
";",
"}",
"return",
"$",
"paths",
";",
"}"
] | Registers path that are not qtype-specific | [
"Registers",
"path",
"that",
"are",
"not",
"qtype",
"-",
"specific"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L1063-L1094 |
214,027 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_question_bank_handler.on_question_categories_start | public function on_question_categories_start() {
$this->open_xml_writer('questions.xml');
$this->xmlwriter->begin_tag('question_categories');
if (is_null($this->fileman)) {
$this->fileman = $this->converter->get_file_manager();
}
} | php | public function on_question_categories_start() {
$this->open_xml_writer('questions.xml');
$this->xmlwriter->begin_tag('question_categories');
if (is_null($this->fileman)) {
$this->fileman = $this->converter->get_file_manager();
}
} | [
"public",
"function",
"on_question_categories_start",
"(",
")",
"{",
"$",
"this",
"->",
"open_xml_writer",
"(",
"'questions.xml'",
")",
";",
"$",
"this",
"->",
"xmlwriter",
"->",
"begin_tag",
"(",
"'question_categories'",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"fileman",
")",
")",
"{",
"$",
"this",
"->",
"fileman",
"=",
"$",
"this",
"->",
"converter",
"->",
"get_file_manager",
"(",
")",
";",
"}",
"}"
] | Starts writing questions.xml and prepares the file manager instance | [
"Starts",
"writing",
"questions",
".",
"xml",
"and",
"prepares",
"the",
"file",
"manager",
"instance"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L1099-L1105 |
214,028 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_question_bank_handler.on_question_category_start | public function on_question_category_start() {
$this->currentcategory = array();
$this->currentcategoryraw = array();
$this->currentcategorywritten = false;
$this->questionswrapperwritten = false;
} | php | public function on_question_category_start() {
$this->currentcategory = array();
$this->currentcategoryraw = array();
$this->currentcategorywritten = false;
$this->questionswrapperwritten = false;
} | [
"public",
"function",
"on_question_category_start",
"(",
")",
"{",
"$",
"this",
"->",
"currentcategory",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"currentcategoryraw",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"currentcategorywritten",
"=",
"false",
";",
"$",
"this",
"->",
"questionswrapperwritten",
"=",
"false",
";",
"}"
] | Initializes the current category cache | [
"Initializes",
"the",
"current",
"category",
"cache"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L1110-L1115 |
214,029 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_question_bank_handler.process_question_category | public function process_question_category($data, $raw) {
$this->currentcategory = array_merge($this->currentcategory, $data);
$this->currentcategoryraw = array_merge($this->currentcategoryraw, $raw);
} | php | public function process_question_category($data, $raw) {
$this->currentcategory = array_merge($this->currentcategory, $data);
$this->currentcategoryraw = array_merge($this->currentcategoryraw, $raw);
} | [
"public",
"function",
"process_question_category",
"(",
"$",
"data",
",",
"$",
"raw",
")",
"{",
"$",
"this",
"->",
"currentcategory",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"currentcategory",
",",
"$",
"data",
")",
";",
"$",
"this",
"->",
"currentcategoryraw",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"currentcategoryraw",
",",
"$",
"raw",
")",
";",
"}"
] | Populates the current question category data
Bacuse of the known subpath-in-the-middle problem (CONTEXT in this case), this is actually
called twice for both halves of the data. We merge them here into the currentcategory array. | [
"Populates",
"the",
"current",
"question",
"category",
"data"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L1123-L1126 |
214,030 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_question_bank_handler.process_question_category_context | public function process_question_category_context($data) {
switch ($data['level']) {
case 'module':
$this->currentcategory['contextid'] = $this->converter->get_contextid(CONTEXT_MODULE, $data['instance']);
$this->currentcategory['contextlevel'] = CONTEXT_MODULE;
$this->currentcategory['contextinstanceid'] = $data['instance'];
break;
case 'course':
$originalcourseinfo = $this->converter->get_stash('original_course_info');
$originalcourseid = $originalcourseinfo['original_course_id'];
$this->currentcategory['contextid'] = $this->converter->get_contextid(CONTEXT_COURSE);
$this->currentcategory['contextlevel'] = CONTEXT_COURSE;
$this->currentcategory['contextinstanceid'] = $originalcourseid;
break;
case 'coursecategory':
// this is a bit hacky. the source moodle.xml defines COURSECATEGORYLEVEL as a distance
// of the course category (1 = parent category, 2 = grand-parent category etc). We pretend
// that this level*10 is the id of that category and create an artifical contextid for it
$this->currentcategory['contextid'] = $this->converter->get_contextid(CONTEXT_COURSECAT, $data['coursecategorylevel'] * 10);
$this->currentcategory['contextlevel'] = CONTEXT_COURSECAT;
$this->currentcategory['contextinstanceid'] = $data['coursecategorylevel'] * 10;
break;
case 'system':
$this->currentcategory['contextid'] = $this->converter->get_contextid(CONTEXT_SYSTEM);
$this->currentcategory['contextlevel'] = CONTEXT_SYSTEM;
$this->currentcategory['contextinstanceid'] = 0;
break;
}
} | php | public function process_question_category_context($data) {
switch ($data['level']) {
case 'module':
$this->currentcategory['contextid'] = $this->converter->get_contextid(CONTEXT_MODULE, $data['instance']);
$this->currentcategory['contextlevel'] = CONTEXT_MODULE;
$this->currentcategory['contextinstanceid'] = $data['instance'];
break;
case 'course':
$originalcourseinfo = $this->converter->get_stash('original_course_info');
$originalcourseid = $originalcourseinfo['original_course_id'];
$this->currentcategory['contextid'] = $this->converter->get_contextid(CONTEXT_COURSE);
$this->currentcategory['contextlevel'] = CONTEXT_COURSE;
$this->currentcategory['contextinstanceid'] = $originalcourseid;
break;
case 'coursecategory':
// this is a bit hacky. the source moodle.xml defines COURSECATEGORYLEVEL as a distance
// of the course category (1 = parent category, 2 = grand-parent category etc). We pretend
// that this level*10 is the id of that category and create an artifical contextid for it
$this->currentcategory['contextid'] = $this->converter->get_contextid(CONTEXT_COURSECAT, $data['coursecategorylevel'] * 10);
$this->currentcategory['contextlevel'] = CONTEXT_COURSECAT;
$this->currentcategory['contextinstanceid'] = $data['coursecategorylevel'] * 10;
break;
case 'system':
$this->currentcategory['contextid'] = $this->converter->get_contextid(CONTEXT_SYSTEM);
$this->currentcategory['contextlevel'] = CONTEXT_SYSTEM;
$this->currentcategory['contextinstanceid'] = 0;
break;
}
} | [
"public",
"function",
"process_question_category_context",
"(",
"$",
"data",
")",
"{",
"switch",
"(",
"$",
"data",
"[",
"'level'",
"]",
")",
"{",
"case",
"'module'",
":",
"$",
"this",
"->",
"currentcategory",
"[",
"'contextid'",
"]",
"=",
"$",
"this",
"->",
"converter",
"->",
"get_contextid",
"(",
"CONTEXT_MODULE",
",",
"$",
"data",
"[",
"'instance'",
"]",
")",
";",
"$",
"this",
"->",
"currentcategory",
"[",
"'contextlevel'",
"]",
"=",
"CONTEXT_MODULE",
";",
"$",
"this",
"->",
"currentcategory",
"[",
"'contextinstanceid'",
"]",
"=",
"$",
"data",
"[",
"'instance'",
"]",
";",
"break",
";",
"case",
"'course'",
":",
"$",
"originalcourseinfo",
"=",
"$",
"this",
"->",
"converter",
"->",
"get_stash",
"(",
"'original_course_info'",
")",
";",
"$",
"originalcourseid",
"=",
"$",
"originalcourseinfo",
"[",
"'original_course_id'",
"]",
";",
"$",
"this",
"->",
"currentcategory",
"[",
"'contextid'",
"]",
"=",
"$",
"this",
"->",
"converter",
"->",
"get_contextid",
"(",
"CONTEXT_COURSE",
")",
";",
"$",
"this",
"->",
"currentcategory",
"[",
"'contextlevel'",
"]",
"=",
"CONTEXT_COURSE",
";",
"$",
"this",
"->",
"currentcategory",
"[",
"'contextinstanceid'",
"]",
"=",
"$",
"originalcourseid",
";",
"break",
";",
"case",
"'coursecategory'",
":",
"// this is a bit hacky. the source moodle.xml defines COURSECATEGORYLEVEL as a distance",
"// of the course category (1 = parent category, 2 = grand-parent category etc). We pretend",
"// that this level*10 is the id of that category and create an artifical contextid for it",
"$",
"this",
"->",
"currentcategory",
"[",
"'contextid'",
"]",
"=",
"$",
"this",
"->",
"converter",
"->",
"get_contextid",
"(",
"CONTEXT_COURSECAT",
",",
"$",
"data",
"[",
"'coursecategorylevel'",
"]",
"*",
"10",
")",
";",
"$",
"this",
"->",
"currentcategory",
"[",
"'contextlevel'",
"]",
"=",
"CONTEXT_COURSECAT",
";",
"$",
"this",
"->",
"currentcategory",
"[",
"'contextinstanceid'",
"]",
"=",
"$",
"data",
"[",
"'coursecategorylevel'",
"]",
"*",
"10",
";",
"break",
";",
"case",
"'system'",
":",
"$",
"this",
"->",
"currentcategory",
"[",
"'contextid'",
"]",
"=",
"$",
"this",
"->",
"converter",
"->",
"get_contextid",
"(",
"CONTEXT_SYSTEM",
")",
";",
"$",
"this",
"->",
"currentcategory",
"[",
"'contextlevel'",
"]",
"=",
"CONTEXT_SYSTEM",
";",
"$",
"this",
"->",
"currentcategory",
"[",
"'contextinstanceid'",
"]",
"=",
"0",
";",
"break",
";",
"}",
"}"
] | Inject the context related information into the current category | [
"Inject",
"the",
"context",
"related",
"information",
"into",
"the",
"current",
"category"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L1131-L1160 |
214,031 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_question_bank_handler.get_qtype_handler | protected function get_qtype_handler($qtype) {
if (is_null($this->qtypehandlers)) {
// initialize the list of qtype handler instances
$this->qtypehandlers = array();
foreach (core_component::get_plugin_list('qtype') as $qtypename => $qtypelocation) {
$filename = $qtypelocation.'/backup/moodle1/lib.php';
if (file_exists($filename)) {
$classname = 'moodle1_qtype_'.$qtypename.'_handler';
require_once($filename);
if (!class_exists($classname)) {
throw new moodle1_convert_exception('missing_handler_class', $classname);
}
$this->log('registering handler', backup::LOG_DEBUG, $classname, 2);
$this->qtypehandlers[$qtypename] = new $classname($this, $qtypename);
}
}
}
if ($qtype === '*') {
return $this->qtypehandlers;
} else if (isset($this->qtypehandlers[$qtype])) {
return $this->qtypehandlers[$qtype];
} else {
return false;
}
} | php | protected function get_qtype_handler($qtype) {
if (is_null($this->qtypehandlers)) {
// initialize the list of qtype handler instances
$this->qtypehandlers = array();
foreach (core_component::get_plugin_list('qtype') as $qtypename => $qtypelocation) {
$filename = $qtypelocation.'/backup/moodle1/lib.php';
if (file_exists($filename)) {
$classname = 'moodle1_qtype_'.$qtypename.'_handler';
require_once($filename);
if (!class_exists($classname)) {
throw new moodle1_convert_exception('missing_handler_class', $classname);
}
$this->log('registering handler', backup::LOG_DEBUG, $classname, 2);
$this->qtypehandlers[$qtypename] = new $classname($this, $qtypename);
}
}
}
if ($qtype === '*') {
return $this->qtypehandlers;
} else if (isset($this->qtypehandlers[$qtype])) {
return $this->qtypehandlers[$qtype];
} else {
return false;
}
} | [
"protected",
"function",
"get_qtype_handler",
"(",
"$",
"qtype",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"qtypehandlers",
")",
")",
"{",
"// initialize the list of qtype handler instances",
"$",
"this",
"->",
"qtypehandlers",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"core_component",
"::",
"get_plugin_list",
"(",
"'qtype'",
")",
"as",
"$",
"qtypename",
"=>",
"$",
"qtypelocation",
")",
"{",
"$",
"filename",
"=",
"$",
"qtypelocation",
".",
"'/backup/moodle1/lib.php'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"filename",
")",
")",
"{",
"$",
"classname",
"=",
"'moodle1_qtype_'",
".",
"$",
"qtypename",
".",
"'_handler'",
";",
"require_once",
"(",
"$",
"filename",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"classname",
")",
")",
"{",
"throw",
"new",
"moodle1_convert_exception",
"(",
"'missing_handler_class'",
",",
"$",
"classname",
")",
";",
"}",
"$",
"this",
"->",
"log",
"(",
"'registering handler'",
",",
"backup",
"::",
"LOG_DEBUG",
",",
"$",
"classname",
",",
"2",
")",
";",
"$",
"this",
"->",
"qtypehandlers",
"[",
"$",
"qtypename",
"]",
"=",
"new",
"$",
"classname",
"(",
"$",
"this",
",",
"$",
"qtypename",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"qtype",
"===",
"'*'",
")",
"{",
"return",
"$",
"this",
"->",
"qtypehandlers",
";",
"}",
"else",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"qtypehandlers",
"[",
"$",
"qtype",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"qtypehandlers",
"[",
"$",
"qtype",
"]",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Provides access to the qtype handlers
Returns either list of all qtype handler instances (if passed '*') or a particular handler
for the given qtype or false if the qtype is not supported.
@throws moodle1_convert_exception
@param string $qtype the name of the question type or '*' for returning all
@return array|moodle1_qtype_handler|bool | [
"Provides",
"access",
"to",
"the",
"qtype",
"handlers"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L1334-L1362 |
214,032 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_scales_handler.on_scales_start | public function on_scales_start() {
$syscontextid = $this->converter->get_contextid(CONTEXT_SYSTEM);
$this->fileman = $this->converter->get_file_manager($syscontextid, 'grade', 'scale');
} | php | public function on_scales_start() {
$syscontextid = $this->converter->get_contextid(CONTEXT_SYSTEM);
$this->fileman = $this->converter->get_file_manager($syscontextid, 'grade', 'scale');
} | [
"public",
"function",
"on_scales_start",
"(",
")",
"{",
"$",
"syscontextid",
"=",
"$",
"this",
"->",
"converter",
"->",
"get_contextid",
"(",
"CONTEXT_SYSTEM",
")",
";",
"$",
"this",
"->",
"fileman",
"=",
"$",
"this",
"->",
"converter",
"->",
"get_file_manager",
"(",
"$",
"syscontextid",
",",
"'grade'",
",",
"'scale'",
")",
";",
"}"
] | Prepare the file manager for the files embedded in the scale description field | [
"Prepare",
"the",
"file",
"manager",
"for",
"the",
"files",
"embedded",
"in",
"the",
"scale",
"description",
"field"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L1397-L1400 |
214,033 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_outcomes_handler.on_gradebook_grade_outcomes_start | public function on_gradebook_grade_outcomes_start() {
$syscontextid = $this->converter->get_contextid(CONTEXT_SYSTEM);
$this->fileman = $this->converter->get_file_manager($syscontextid, 'grade', 'outcome');
$this->open_xml_writer('outcomes.xml');
$this->xmlwriter->begin_tag('outcomes_definition');
} | php | public function on_gradebook_grade_outcomes_start() {
$syscontextid = $this->converter->get_contextid(CONTEXT_SYSTEM);
$this->fileman = $this->converter->get_file_manager($syscontextid, 'grade', 'outcome');
$this->open_xml_writer('outcomes.xml');
$this->xmlwriter->begin_tag('outcomes_definition');
} | [
"public",
"function",
"on_gradebook_grade_outcomes_start",
"(",
")",
"{",
"$",
"syscontextid",
"=",
"$",
"this",
"->",
"converter",
"->",
"get_contextid",
"(",
"CONTEXT_SYSTEM",
")",
";",
"$",
"this",
"->",
"fileman",
"=",
"$",
"this",
"->",
"converter",
"->",
"get_file_manager",
"(",
"$",
"syscontextid",
",",
"'grade'",
",",
"'outcome'",
")",
";",
"$",
"this",
"->",
"open_xml_writer",
"(",
"'outcomes.xml'",
")",
";",
"$",
"this",
"->",
"xmlwriter",
"->",
"begin_tag",
"(",
"'outcomes_definition'",
")",
";",
"}"
] | Prepares the file manager and starts writing outcomes.xml | [
"Prepares",
"the",
"file",
"manager",
"and",
"starts",
"writing",
"outcomes",
".",
"xml"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L1456-L1463 |
214,034 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_outcomes_handler.process_gradebook_grade_outcome | public function process_gradebook_grade_outcome(array $data, array $raw) {
global $CFG;
// replay the upgrade step 2009110400
if ($CFG->texteditors !== 'textarea') {
$data['description'] = text_to_html($data['description'], false, false, true);
$data['descriptionformat'] = FORMAT_HTML;
}
// convert course files embedded into the outcome description field
$this->fileman->itemid = $data['id'];
$data['description'] = moodle1_converter::migrate_referenced_files($data['description'], $this->fileman);
// write the outcome data
$this->write_xml('outcome', $data, array('/outcome/id'));
return $data;
} | php | public function process_gradebook_grade_outcome(array $data, array $raw) {
global $CFG;
// replay the upgrade step 2009110400
if ($CFG->texteditors !== 'textarea') {
$data['description'] = text_to_html($data['description'], false, false, true);
$data['descriptionformat'] = FORMAT_HTML;
}
// convert course files embedded into the outcome description field
$this->fileman->itemid = $data['id'];
$data['description'] = moodle1_converter::migrate_referenced_files($data['description'], $this->fileman);
// write the outcome data
$this->write_xml('outcome', $data, array('/outcome/id'));
return $data;
} | [
"public",
"function",
"process_gradebook_grade_outcome",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"raw",
")",
"{",
"global",
"$",
"CFG",
";",
"// replay the upgrade step 2009110400",
"if",
"(",
"$",
"CFG",
"->",
"texteditors",
"!==",
"'textarea'",
")",
"{",
"$",
"data",
"[",
"'description'",
"]",
"=",
"text_to_html",
"(",
"$",
"data",
"[",
"'description'",
"]",
",",
"false",
",",
"false",
",",
"true",
")",
";",
"$",
"data",
"[",
"'descriptionformat'",
"]",
"=",
"FORMAT_HTML",
";",
"}",
"// convert course files embedded into the outcome description field",
"$",
"this",
"->",
"fileman",
"->",
"itemid",
"=",
"$",
"data",
"[",
"'id'",
"]",
";",
"$",
"data",
"[",
"'description'",
"]",
"=",
"moodle1_converter",
"::",
"migrate_referenced_files",
"(",
"$",
"data",
"[",
"'description'",
"]",
",",
"$",
"this",
"->",
"fileman",
")",
";",
"// write the outcome data",
"$",
"this",
"->",
"write_xml",
"(",
"'outcome'",
",",
"$",
"data",
",",
"array",
"(",
"'/outcome/id'",
")",
")",
";",
"return",
"$",
"data",
";",
"}"
] | Processes GRADE_OUTCOME tags progressively | [
"Processes",
"GRADE_OUTCOME",
"tags",
"progressively"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L1468-L1485 |
214,035 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_gradebook_handler.process_gradebook_grade_category | public function process_gradebook_grade_category(array $data, array $raw) {
$this->categoryparent[$data['id']] = $data['parent'];
$this->converter->set_stash('gradebook_gradecategory', $data, $data['id']);
} | php | public function process_gradebook_grade_category(array $data, array $raw) {
$this->categoryparent[$data['id']] = $data['parent'];
$this->converter->set_stash('gradebook_gradecategory', $data, $data['id']);
} | [
"public",
"function",
"process_gradebook_grade_category",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"raw",
")",
"{",
"$",
"this",
"->",
"categoryparent",
"[",
"$",
"data",
"[",
"'id'",
"]",
"]",
"=",
"$",
"data",
"[",
"'parent'",
"]",
";",
"$",
"this",
"->",
"converter",
"->",
"set_stash",
"(",
"'gradebook_gradecategory'",
",",
"$",
"data",
",",
"$",
"data",
"[",
"'id'",
"]",
")",
";",
"}"
] | Processes one GRADE_CATEGORY data | [
"Processes",
"one",
"GRADE_CATEGORY",
"data"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L1549-L1552 |
214,036 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_gradebook_handler.process_gradebook_grade_item | public function process_gradebook_grade_item(array $data, array $raw) {
// here we use get_nextid() to get a nondecreasing sequence
$data['sortorder'] = $this->converter->get_nextid();
if ($data['itemtype'] === 'mod') {
return $this->process_mod_grade_item($data, $raw);
} else if (in_array($data['itemtype'], array('manual', 'course', 'category'))) {
return $this->process_nonmod_grade_item($data, $raw);
} else {
$this->log('unsupported grade_item type', backup::LOG_ERROR, $data['itemtype']);
}
} | php | public function process_gradebook_grade_item(array $data, array $raw) {
// here we use get_nextid() to get a nondecreasing sequence
$data['sortorder'] = $this->converter->get_nextid();
if ($data['itemtype'] === 'mod') {
return $this->process_mod_grade_item($data, $raw);
} else if (in_array($data['itemtype'], array('manual', 'course', 'category'))) {
return $this->process_nonmod_grade_item($data, $raw);
} else {
$this->log('unsupported grade_item type', backup::LOG_ERROR, $data['itemtype']);
}
} | [
"public",
"function",
"process_gradebook_grade_item",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"raw",
")",
"{",
"// here we use get_nextid() to get a nondecreasing sequence",
"$",
"data",
"[",
"'sortorder'",
"]",
"=",
"$",
"this",
"->",
"converter",
"->",
"get_nextid",
"(",
")",
";",
"if",
"(",
"$",
"data",
"[",
"'itemtype'",
"]",
"===",
"'mod'",
")",
"{",
"return",
"$",
"this",
"->",
"process_mod_grade_item",
"(",
"$",
"data",
",",
"$",
"raw",
")",
";",
"}",
"else",
"if",
"(",
"in_array",
"(",
"$",
"data",
"[",
"'itemtype'",
"]",
",",
"array",
"(",
"'manual'",
",",
"'course'",
",",
"'category'",
")",
")",
")",
"{",
"return",
"$",
"this",
"->",
"process_nonmod_grade_item",
"(",
"$",
"data",
",",
"$",
"raw",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"log",
"(",
"'unsupported grade_item type'",
",",
"backup",
"::",
"LOG_ERROR",
",",
"$",
"data",
"[",
"'itemtype'",
"]",
")",
";",
"}",
"}"
] | Processes one GRADE_ITEM data | [
"Processes",
"one",
"GRADE_ITEM",
"data"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L1557-L1571 |
214,037 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_gradebook_handler.process_mod_grade_item | protected function process_mod_grade_item(array $data, array $raw) {
$stashname = 'gradebook_modgradeitem_'.$data['itemmodule'];
$stashitemid = $data['iteminstance'];
$gradeitems = $this->converter->get_stash_or_default($stashname, $stashitemid, array());
// typically there will be single item with itemnumber 0
$gradeitems[$data['itemnumber']] = $data;
$this->converter->set_stash($stashname, $gradeitems, $stashitemid);
return $data;
} | php | protected function process_mod_grade_item(array $data, array $raw) {
$stashname = 'gradebook_modgradeitem_'.$data['itemmodule'];
$stashitemid = $data['iteminstance'];
$gradeitems = $this->converter->get_stash_or_default($stashname, $stashitemid, array());
// typically there will be single item with itemnumber 0
$gradeitems[$data['itemnumber']] = $data;
$this->converter->set_stash($stashname, $gradeitems, $stashitemid);
return $data;
} | [
"protected",
"function",
"process_mod_grade_item",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"raw",
")",
"{",
"$",
"stashname",
"=",
"'gradebook_modgradeitem_'",
".",
"$",
"data",
"[",
"'itemmodule'",
"]",
";",
"$",
"stashitemid",
"=",
"$",
"data",
"[",
"'iteminstance'",
"]",
";",
"$",
"gradeitems",
"=",
"$",
"this",
"->",
"converter",
"->",
"get_stash_or_default",
"(",
"$",
"stashname",
",",
"$",
"stashitemid",
",",
"array",
"(",
")",
")",
";",
"// typically there will be single item with itemnumber 0",
"$",
"gradeitems",
"[",
"$",
"data",
"[",
"'itemnumber'",
"]",
"]",
"=",
"$",
"data",
";",
"$",
"this",
"->",
"converter",
"->",
"set_stash",
"(",
"$",
"stashname",
",",
"$",
"gradeitems",
",",
"$",
"stashitemid",
")",
";",
"return",
"$",
"data",
";",
"}"
] | Processes one GRADE_ITEM of the type 'mod' | [
"Processes",
"one",
"GRADE_ITEM",
"of",
"the",
"type",
"mod"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L1576-L1588 |
214,038 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_gradebook_handler.process_nonmod_grade_item | protected function process_nonmod_grade_item(array $data, array $raw) {
$stashname = 'gradebook_nonmodgradeitem';
$stashitemid = $data['id'];
$this->converter->set_stash($stashname, $data, $stashitemid);
return $data;
} | php | protected function process_nonmod_grade_item(array $data, array $raw) {
$stashname = 'gradebook_nonmodgradeitem';
$stashitemid = $data['id'];
$this->converter->set_stash($stashname, $data, $stashitemid);
return $data;
} | [
"protected",
"function",
"process_nonmod_grade_item",
"(",
"array",
"$",
"data",
",",
"array",
"$",
"raw",
")",
"{",
"$",
"stashname",
"=",
"'gradebook_nonmodgradeitem'",
";",
"$",
"stashitemid",
"=",
"$",
"data",
"[",
"'id'",
"]",
";",
"$",
"this",
"->",
"converter",
"->",
"set_stash",
"(",
"$",
"stashname",
",",
"$",
"data",
",",
"$",
"stashitemid",
")",
";",
"return",
"$",
"data",
";",
"}"
] | Processes one GRADE_ITEM of te type 'manual' or 'course' or 'category' | [
"Processes",
"one",
"GRADE_ITEM",
"of",
"te",
"type",
"manual",
"or",
"course",
"or",
"category"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L1593-L1600 |
214,039 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_gradebook_handler.on_gradebook_end | public function on_gradebook_end() {
$this->open_xml_writer('gradebook.xml');
$this->xmlwriter->begin_tag('gradebook');
$this->write_grade_categories();
$this->write_grade_items();
$this->write_grade_letters();
$this->xmlwriter->end_tag('gradebook');
$this->close_xml_writer();
} | php | public function on_gradebook_end() {
$this->open_xml_writer('gradebook.xml');
$this->xmlwriter->begin_tag('gradebook');
$this->write_grade_categories();
$this->write_grade_items();
$this->write_grade_letters();
$this->xmlwriter->end_tag('gradebook');
$this->close_xml_writer();
} | [
"public",
"function",
"on_gradebook_end",
"(",
")",
"{",
"$",
"this",
"->",
"open_xml_writer",
"(",
"'gradebook.xml'",
")",
";",
"$",
"this",
"->",
"xmlwriter",
"->",
"begin_tag",
"(",
"'gradebook'",
")",
";",
"$",
"this",
"->",
"write_grade_categories",
"(",
")",
";",
"$",
"this",
"->",
"write_grade_items",
"(",
")",
";",
"$",
"this",
"->",
"write_grade_letters",
"(",
")",
";",
"$",
"this",
"->",
"xmlwriter",
"->",
"end_tag",
"(",
"'gradebook'",
")",
";",
"$",
"this",
"->",
"close_xml_writer",
"(",
")",
";",
"}"
] | Writes the collected information into gradebook.xml | [
"Writes",
"the",
"collected",
"information",
"into",
"gradebook",
".",
"xml"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L1611-L1620 |
214,040 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_gradebook_handler.calculate_category_path | protected function calculate_category_path($categoryid) {
if (!array_key_exists($categoryid, $this->categoryparent)) {
throw new moodle1_convert_exception('gradebook_unknown_categoryid', null, $categoryid);
}
$path = array($categoryid);
$parent = $this->categoryparent[$categoryid];
while (!is_null($parent)) {
array_unshift($path, $parent);
$parent = $this->categoryparent[$parent];
if (in_array($parent, $path)) {
throw new moodle1_convert_exception('circular_reference_in_categories_tree');
}
}
return $path;
} | php | protected function calculate_category_path($categoryid) {
if (!array_key_exists($categoryid, $this->categoryparent)) {
throw new moodle1_convert_exception('gradebook_unknown_categoryid', null, $categoryid);
}
$path = array($categoryid);
$parent = $this->categoryparent[$categoryid];
while (!is_null($parent)) {
array_unshift($path, $parent);
$parent = $this->categoryparent[$parent];
if (in_array($parent, $path)) {
throw new moodle1_convert_exception('circular_reference_in_categories_tree');
}
}
return $path;
} | [
"protected",
"function",
"calculate_category_path",
"(",
"$",
"categoryid",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"categoryid",
",",
"$",
"this",
"->",
"categoryparent",
")",
")",
"{",
"throw",
"new",
"moodle1_convert_exception",
"(",
"'gradebook_unknown_categoryid'",
",",
"null",
",",
"$",
"categoryid",
")",
";",
"}",
"$",
"path",
"=",
"array",
"(",
"$",
"categoryid",
")",
";",
"$",
"parent",
"=",
"$",
"this",
"->",
"categoryparent",
"[",
"$",
"categoryid",
"]",
";",
"while",
"(",
"!",
"is_null",
"(",
"$",
"parent",
")",
")",
"{",
"array_unshift",
"(",
"$",
"path",
",",
"$",
"parent",
")",
";",
"$",
"parent",
"=",
"$",
"this",
"->",
"categoryparent",
"[",
"$",
"parent",
"]",
";",
"if",
"(",
"in_array",
"(",
"$",
"parent",
",",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"moodle1_convert_exception",
"(",
"'circular_reference_in_categories_tree'",
")",
";",
"}",
"}",
"return",
"$",
"path",
";",
"}"
] | Calculates the path to the grade_category
Moodle 1.9 backup does not store the grade_category's depth and path. This method is used
to repopulate this information using the $this->categoryparent values.
@param int $categoryid
@return array of ids including the categoryid | [
"Calculates",
"the",
"path",
"to",
"the",
"grade_category"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L1647-L1664 |
214,041 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_qtype_handler.write_answers | protected function write_answers(array $answers, $qtype) {
$this->xmlwriter->begin_tag('answers');
foreach ($answers as $elementname => $elements) {
foreach ($elements as $element) {
$answer = $this->convert_answer($element, $qtype);
// Migrate images in answertext.
if ($answer['answerformat'] == FORMAT_HTML) {
$answer['answertext'] = $this->migrate_files($answer['answertext'], 'question', 'answer', $answer['id']);
}
// Migrate images in feedback.
if ($answer['feedbackformat'] == FORMAT_HTML) {
$answer['feedback'] = $this->migrate_files($answer['feedback'], 'question', 'answerfeedback', $answer['id']);
}
$this->write_xml('answer', $answer, array('/answer/id'));
}
}
$this->xmlwriter->end_tag('answers');
} | php | protected function write_answers(array $answers, $qtype) {
$this->xmlwriter->begin_tag('answers');
foreach ($answers as $elementname => $elements) {
foreach ($elements as $element) {
$answer = $this->convert_answer($element, $qtype);
// Migrate images in answertext.
if ($answer['answerformat'] == FORMAT_HTML) {
$answer['answertext'] = $this->migrate_files($answer['answertext'], 'question', 'answer', $answer['id']);
}
// Migrate images in feedback.
if ($answer['feedbackformat'] == FORMAT_HTML) {
$answer['feedback'] = $this->migrate_files($answer['feedback'], 'question', 'answerfeedback', $answer['id']);
}
$this->write_xml('answer', $answer, array('/answer/id'));
}
}
$this->xmlwriter->end_tag('answers');
} | [
"protected",
"function",
"write_answers",
"(",
"array",
"$",
"answers",
",",
"$",
"qtype",
")",
"{",
"$",
"this",
"->",
"xmlwriter",
"->",
"begin_tag",
"(",
"'answers'",
")",
";",
"foreach",
"(",
"$",
"answers",
"as",
"$",
"elementname",
"=>",
"$",
"elements",
")",
"{",
"foreach",
"(",
"$",
"elements",
"as",
"$",
"element",
")",
"{",
"$",
"answer",
"=",
"$",
"this",
"->",
"convert_answer",
"(",
"$",
"element",
",",
"$",
"qtype",
")",
";",
"// Migrate images in answertext.",
"if",
"(",
"$",
"answer",
"[",
"'answerformat'",
"]",
"==",
"FORMAT_HTML",
")",
"{",
"$",
"answer",
"[",
"'answertext'",
"]",
"=",
"$",
"this",
"->",
"migrate_files",
"(",
"$",
"answer",
"[",
"'answertext'",
"]",
",",
"'question'",
",",
"'answer'",
",",
"$",
"answer",
"[",
"'id'",
"]",
")",
";",
"}",
"// Migrate images in feedback.",
"if",
"(",
"$",
"answer",
"[",
"'feedbackformat'",
"]",
"==",
"FORMAT_HTML",
")",
"{",
"$",
"answer",
"[",
"'feedback'",
"]",
"=",
"$",
"this",
"->",
"migrate_files",
"(",
"$",
"answer",
"[",
"'feedback'",
"]",
",",
"'question'",
",",
"'answerfeedback'",
",",
"$",
"answer",
"[",
"'id'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"write_xml",
"(",
"'answer'",
",",
"$",
"answer",
",",
"array",
"(",
"'/answer/id'",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"xmlwriter",
"->",
"end_tag",
"(",
"'answers'",
")",
";",
"}"
] | Converts the answers and writes them into the questions.xml
The structure "answers" is used by several qtypes. It contains data from {question_answers} table.
@param array $answers as parsed by the grouped parser in moodle.xml
@param string $qtype containing the answers | [
"Converts",
"the",
"answers",
"and",
"writes",
"them",
"into",
"the",
"questions",
".",
"xml"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L1763-L1781 |
214,042 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_qtype_handler.migrate_files | protected function migrate_files($text, $component, $filearea, $itemid) {
$context = $this->qbankhandler->get_current_category_context();
$fileman = $this->qbankhandler->get_file_manager();
$fileman->contextid = $context['contextid'];
$fileman->component = $component;
$fileman->filearea = $filearea;
$fileman->itemid = $itemid;
$text = moodle1_converter::migrate_referenced_files($text, $fileman);
return $text;
} | php | protected function migrate_files($text, $component, $filearea, $itemid) {
$context = $this->qbankhandler->get_current_category_context();
$fileman = $this->qbankhandler->get_file_manager();
$fileman->contextid = $context['contextid'];
$fileman->component = $component;
$fileman->filearea = $filearea;
$fileman->itemid = $itemid;
$text = moodle1_converter::migrate_referenced_files($text, $fileman);
return $text;
} | [
"protected",
"function",
"migrate_files",
"(",
"$",
"text",
",",
"$",
"component",
",",
"$",
"filearea",
",",
"$",
"itemid",
")",
"{",
"$",
"context",
"=",
"$",
"this",
"->",
"qbankhandler",
"->",
"get_current_category_context",
"(",
")",
";",
"$",
"fileman",
"=",
"$",
"this",
"->",
"qbankhandler",
"->",
"get_file_manager",
"(",
")",
";",
"$",
"fileman",
"->",
"contextid",
"=",
"$",
"context",
"[",
"'contextid'",
"]",
";",
"$",
"fileman",
"->",
"component",
"=",
"$",
"component",
";",
"$",
"fileman",
"->",
"filearea",
"=",
"$",
"filearea",
";",
"$",
"fileman",
"->",
"itemid",
"=",
"$",
"itemid",
";",
"$",
"text",
"=",
"moodle1_converter",
"::",
"migrate_referenced_files",
"(",
"$",
"text",
",",
"$",
"fileman",
")",
";",
"return",
"$",
"text",
";",
"}"
] | Migrate files belonging to one qtype plugin text field.
@param array $text the html fragment containing references to files
@param string $component the component for restored files
@param string $filearea the file area for restored files
@param int $itemid the itemid for restored files
@return string the text for this field, after files references have been processed | [
"Migrate",
"files",
"belonging",
"to",
"one",
"qtype",
"plugin",
"text",
"field",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L1793-L1802 |
214,043 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_qtype_handler.write_numerical_units | protected function write_numerical_units(array $numericalunits) {
$this->xmlwriter->begin_tag('numerical_units');
foreach ($numericalunits as $elementname => $elements) {
foreach ($elements as $element) {
$element['id'] = $this->converter->get_nextid();
$this->write_xml('numerical_unit', $element, array('/numerical_unit/id'));
}
}
$this->xmlwriter->end_tag('numerical_units');
} | php | protected function write_numerical_units(array $numericalunits) {
$this->xmlwriter->begin_tag('numerical_units');
foreach ($numericalunits as $elementname => $elements) {
foreach ($elements as $element) {
$element['id'] = $this->converter->get_nextid();
$this->write_xml('numerical_unit', $element, array('/numerical_unit/id'));
}
}
$this->xmlwriter->end_tag('numerical_units');
} | [
"protected",
"function",
"write_numerical_units",
"(",
"array",
"$",
"numericalunits",
")",
"{",
"$",
"this",
"->",
"xmlwriter",
"->",
"begin_tag",
"(",
"'numerical_units'",
")",
";",
"foreach",
"(",
"$",
"numericalunits",
"as",
"$",
"elementname",
"=>",
"$",
"elements",
")",
"{",
"foreach",
"(",
"$",
"elements",
"as",
"$",
"element",
")",
"{",
"$",
"element",
"[",
"'id'",
"]",
"=",
"$",
"this",
"->",
"converter",
"->",
"get_nextid",
"(",
")",
";",
"$",
"this",
"->",
"write_xml",
"(",
"'numerical_unit'",
",",
"$",
"element",
",",
"array",
"(",
"'/numerical_unit/id'",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"xmlwriter",
"->",
"end_tag",
"(",
"'numerical_units'",
")",
";",
"}"
] | Writes the grouped numerical_units structure
@param array $numericalunits | [
"Writes",
"the",
"grouped",
"numerical_units",
"structure"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L1809-L1819 |
214,044 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_qtype_handler.write_numerical_options | protected function write_numerical_options(array $numericaloption) {
$this->xmlwriter->begin_tag('numerical_options');
if (!empty($numericaloption)) {
$this->write_xml('numerical_option', $numericaloption, array('/numerical_option/id'));
}
$this->xmlwriter->end_tag('numerical_options');
} | php | protected function write_numerical_options(array $numericaloption) {
$this->xmlwriter->begin_tag('numerical_options');
if (!empty($numericaloption)) {
$this->write_xml('numerical_option', $numericaloption, array('/numerical_option/id'));
}
$this->xmlwriter->end_tag('numerical_options');
} | [
"protected",
"function",
"write_numerical_options",
"(",
"array",
"$",
"numericaloption",
")",
"{",
"$",
"this",
"->",
"xmlwriter",
"->",
"begin_tag",
"(",
"'numerical_options'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"numericaloption",
")",
")",
"{",
"$",
"this",
"->",
"write_xml",
"(",
"'numerical_option'",
",",
"$",
"numericaloption",
",",
"array",
"(",
"'/numerical_option/id'",
")",
")",
";",
"}",
"$",
"this",
"->",
"xmlwriter",
"->",
"end_tag",
"(",
"'numerical_options'",
")",
";",
"}"
] | Writes the numerical_options structure
@see get_default_numerical_options()
@param array $numericaloption | [
"Writes",
"the",
"numerical_options",
"structure"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L1827-L1834 |
214,045 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_qtype_handler.get_default_numerical_options | protected function get_default_numerical_options($oldquestiontextformat, $units) {
global $CFG;
// replay the upgrade step 2009100100 - new table
$options = array(
'id' => $this->converter->get_nextid(),
'instructions' => null,
'instructionsformat' => 0,
'showunits' => 0,
'unitsleft' => 0,
'unitgradingtype' => 0,
'unitpenalty' => 0.1
);
// replay the upgrade step 2009100101
if ($CFG->texteditors !== 'textarea' and $oldquestiontextformat == FORMAT_MOODLE) {
$options['instructionsformat'] = FORMAT_HTML;
} else {
$options['instructionsformat'] = $oldquestiontextformat;
}
// Set a good default, depending on whether there are any units defined.
if (empty($units)) {
$options['showunits'] = 3;
}
return $options;
} | php | protected function get_default_numerical_options($oldquestiontextformat, $units) {
global $CFG;
// replay the upgrade step 2009100100 - new table
$options = array(
'id' => $this->converter->get_nextid(),
'instructions' => null,
'instructionsformat' => 0,
'showunits' => 0,
'unitsleft' => 0,
'unitgradingtype' => 0,
'unitpenalty' => 0.1
);
// replay the upgrade step 2009100101
if ($CFG->texteditors !== 'textarea' and $oldquestiontextformat == FORMAT_MOODLE) {
$options['instructionsformat'] = FORMAT_HTML;
} else {
$options['instructionsformat'] = $oldquestiontextformat;
}
// Set a good default, depending on whether there are any units defined.
if (empty($units)) {
$options['showunits'] = 3;
}
return $options;
} | [
"protected",
"function",
"get_default_numerical_options",
"(",
"$",
"oldquestiontextformat",
",",
"$",
"units",
")",
"{",
"global",
"$",
"CFG",
";",
"// replay the upgrade step 2009100100 - new table",
"$",
"options",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"converter",
"->",
"get_nextid",
"(",
")",
",",
"'instructions'",
"=>",
"null",
",",
"'instructionsformat'",
"=>",
"0",
",",
"'showunits'",
"=>",
"0",
",",
"'unitsleft'",
"=>",
"0",
",",
"'unitgradingtype'",
"=>",
"0",
",",
"'unitpenalty'",
"=>",
"0.1",
")",
";",
"// replay the upgrade step 2009100101",
"if",
"(",
"$",
"CFG",
"->",
"texteditors",
"!==",
"'textarea'",
"and",
"$",
"oldquestiontextformat",
"==",
"FORMAT_MOODLE",
")",
"{",
"$",
"options",
"[",
"'instructionsformat'",
"]",
"=",
"FORMAT_HTML",
";",
"}",
"else",
"{",
"$",
"options",
"[",
"'instructionsformat'",
"]",
"=",
"$",
"oldquestiontextformat",
";",
"}",
"// Set a good default, depending on whether there are any units defined.",
"if",
"(",
"empty",
"(",
"$",
"units",
")",
")",
"{",
"$",
"options",
"[",
"'showunits'",
"]",
"=",
"3",
";",
"}",
"return",
"$",
"options",
";",
"}"
] | Returns default numerical_option structure
This structure is not present in moodle.xml, we create a new artificial one here.
@see write_numerical_options()
@param int $oldquestiontextformat
@return array | [
"Returns",
"default",
"numerical_option",
"structure"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L1845-L1872 |
214,046 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_qtype_handler.write_dataset_definitions | protected function write_dataset_definitions(array $datasetdefinitions) {
$this->xmlwriter->begin_tag('dataset_definitions');
foreach ($datasetdefinitions as $datasetdefinition) {
$this->xmlwriter->begin_tag('dataset_definition', array('id' => $this->converter->get_nextid()));
foreach (array('category', 'name', 'type', 'options', 'itemcount') as $element) {
$this->xmlwriter->full_tag($element, $datasetdefinition[$element]);
}
$this->xmlwriter->begin_tag('dataset_items');
if (!empty($datasetdefinition['dataset_items']['dataset_item'])) {
foreach ($datasetdefinition['dataset_items']['dataset_item'] as $datasetitem) {
$datasetitem['id'] = $this->converter->get_nextid();
$this->write_xml('dataset_item', $datasetitem, array('/dataset_item/id'));
}
}
$this->xmlwriter->end_tag('dataset_items');
$this->xmlwriter->end_tag('dataset_definition');
}
$this->xmlwriter->end_tag('dataset_definitions');
} | php | protected function write_dataset_definitions(array $datasetdefinitions) {
$this->xmlwriter->begin_tag('dataset_definitions');
foreach ($datasetdefinitions as $datasetdefinition) {
$this->xmlwriter->begin_tag('dataset_definition', array('id' => $this->converter->get_nextid()));
foreach (array('category', 'name', 'type', 'options', 'itemcount') as $element) {
$this->xmlwriter->full_tag($element, $datasetdefinition[$element]);
}
$this->xmlwriter->begin_tag('dataset_items');
if (!empty($datasetdefinition['dataset_items']['dataset_item'])) {
foreach ($datasetdefinition['dataset_items']['dataset_item'] as $datasetitem) {
$datasetitem['id'] = $this->converter->get_nextid();
$this->write_xml('dataset_item', $datasetitem, array('/dataset_item/id'));
}
}
$this->xmlwriter->end_tag('dataset_items');
$this->xmlwriter->end_tag('dataset_definition');
}
$this->xmlwriter->end_tag('dataset_definitions');
} | [
"protected",
"function",
"write_dataset_definitions",
"(",
"array",
"$",
"datasetdefinitions",
")",
"{",
"$",
"this",
"->",
"xmlwriter",
"->",
"begin_tag",
"(",
"'dataset_definitions'",
")",
";",
"foreach",
"(",
"$",
"datasetdefinitions",
"as",
"$",
"datasetdefinition",
")",
"{",
"$",
"this",
"->",
"xmlwriter",
"->",
"begin_tag",
"(",
"'dataset_definition'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"converter",
"->",
"get_nextid",
"(",
")",
")",
")",
";",
"foreach",
"(",
"array",
"(",
"'category'",
",",
"'name'",
",",
"'type'",
",",
"'options'",
",",
"'itemcount'",
")",
"as",
"$",
"element",
")",
"{",
"$",
"this",
"->",
"xmlwriter",
"->",
"full_tag",
"(",
"$",
"element",
",",
"$",
"datasetdefinition",
"[",
"$",
"element",
"]",
")",
";",
"}",
"$",
"this",
"->",
"xmlwriter",
"->",
"begin_tag",
"(",
"'dataset_items'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"datasetdefinition",
"[",
"'dataset_items'",
"]",
"[",
"'dataset_item'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"datasetdefinition",
"[",
"'dataset_items'",
"]",
"[",
"'dataset_item'",
"]",
"as",
"$",
"datasetitem",
")",
"{",
"$",
"datasetitem",
"[",
"'id'",
"]",
"=",
"$",
"this",
"->",
"converter",
"->",
"get_nextid",
"(",
")",
";",
"$",
"this",
"->",
"write_xml",
"(",
"'dataset_item'",
",",
"$",
"datasetitem",
",",
"array",
"(",
"'/dataset_item/id'",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"xmlwriter",
"->",
"end_tag",
"(",
"'dataset_items'",
")",
";",
"$",
"this",
"->",
"xmlwriter",
"->",
"end_tag",
"(",
"'dataset_definition'",
")",
";",
"}",
"$",
"this",
"->",
"xmlwriter",
"->",
"end_tag",
"(",
"'dataset_definitions'",
")",
";",
"}"
] | Writes the dataset_definitions structure
@param array $datasetdefinitions array of dataset_definition structures | [
"Writes",
"the",
"dataset_definitions",
"structure"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L1879-L1898 |
214,047 | moodle/moodle | backup/converter/moodle1/handlerlib.php | moodle1_mod_handler.get_cminfo | protected function get_cminfo($instance, $modname = null) {
if (is_null($modname)) {
$modname = $this->pluginname;
}
return $this->converter->get_stash('cminfo_'.$modname, $instance);
} | php | protected function get_cminfo($instance, $modname = null) {
if (is_null($modname)) {
$modname = $this->pluginname;
}
return $this->converter->get_stash('cminfo_'.$modname, $instance);
} | [
"protected",
"function",
"get_cminfo",
"(",
"$",
"instance",
",",
"$",
"modname",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"modname",
")",
")",
"{",
"$",
"modname",
"=",
"$",
"this",
"->",
"pluginname",
";",
"}",
"return",
"$",
"this",
"->",
"converter",
"->",
"get_stash",
"(",
"'cminfo_'",
".",
"$",
"modname",
",",
"$",
"instance",
")",
";",
"}"
] | Returns course module information for the given instance id
The information for this instance id has been stashed by
{@link moodle1_course_outline_handler::process_course_module()}
@param int $instance the module instance id
@param string $modname the module type, defaults to $this->pluginname
@return int | [
"Returns",
"course",
"module",
"information",
"for",
"the",
"given",
"instance",
"id"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/converter/moodle1/handlerlib.php#L2005-L2011 |
214,048 | moodle/moodle | blocks/rss_client/classes/task/refreshfeeds.php | refreshfeeds.execute | public function execute() {
global $CFG, $DB;
require_once("{$CFG->libdir}/simplepie/moodle_simplepie.php");
// We are going to measure execution times.
$starttime = microtime();
$starttimesec = time();
// Fetch all site feeds.
$rs = $DB->get_recordset('block_rss_client');
$counter = 0;
mtrace('');
foreach ($rs as $rec) {
mtrace(' ' . $rec->url . ' ', '');
// Skip feed if it failed recently.
if ($starttimesec < $rec->skipuntil) {
mtrace('skipping until ' . userdate($rec->skipuntil));
continue;
}
$feed = $this->fetch_feed($rec->url);
if ($feed->error()) {
// Skip this feed (for an ever-increasing time if it keeps failing).
$rec->skiptime = $this->calculate_skiptime($rec->skiptime);
$rec->skipuntil = time() + $rec->skiptime;
$DB->update_record('block_rss_client', $rec);
mtrace("Error: could not load/find the RSS feed - skipping for {$rec->skiptime} seconds.");
} else {
mtrace ('ok');
// It worked this time, so reset the skiptime.
if ($rec->skiptime > 0) {
$rec->skiptime = 0;
$rec->skipuntil = 0;
$DB->update_record('block_rss_client', $rec);
}
// Only increase the counter when a feed is sucesfully refreshed.
$counter ++;
}
}
$rs->close();
// Show times.
mtrace($counter . ' feeds refreshed (took ' . microtime_diff($starttime, microtime()) . ' seconds)');
} | php | public function execute() {
global $CFG, $DB;
require_once("{$CFG->libdir}/simplepie/moodle_simplepie.php");
// We are going to measure execution times.
$starttime = microtime();
$starttimesec = time();
// Fetch all site feeds.
$rs = $DB->get_recordset('block_rss_client');
$counter = 0;
mtrace('');
foreach ($rs as $rec) {
mtrace(' ' . $rec->url . ' ', '');
// Skip feed if it failed recently.
if ($starttimesec < $rec->skipuntil) {
mtrace('skipping until ' . userdate($rec->skipuntil));
continue;
}
$feed = $this->fetch_feed($rec->url);
if ($feed->error()) {
// Skip this feed (for an ever-increasing time if it keeps failing).
$rec->skiptime = $this->calculate_skiptime($rec->skiptime);
$rec->skipuntil = time() + $rec->skiptime;
$DB->update_record('block_rss_client', $rec);
mtrace("Error: could not load/find the RSS feed - skipping for {$rec->skiptime} seconds.");
} else {
mtrace ('ok');
// It worked this time, so reset the skiptime.
if ($rec->skiptime > 0) {
$rec->skiptime = 0;
$rec->skipuntil = 0;
$DB->update_record('block_rss_client', $rec);
}
// Only increase the counter when a feed is sucesfully refreshed.
$counter ++;
}
}
$rs->close();
// Show times.
mtrace($counter . ' feeds refreshed (took ' . microtime_diff($starttime, microtime()) . ' seconds)');
} | [
"public",
"function",
"execute",
"(",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
";",
"require_once",
"(",
"\"{$CFG->libdir}/simplepie/moodle_simplepie.php\"",
")",
";",
"// We are going to measure execution times.",
"$",
"starttime",
"=",
"microtime",
"(",
")",
";",
"$",
"starttimesec",
"=",
"time",
"(",
")",
";",
"// Fetch all site feeds.",
"$",
"rs",
"=",
"$",
"DB",
"->",
"get_recordset",
"(",
"'block_rss_client'",
")",
";",
"$",
"counter",
"=",
"0",
";",
"mtrace",
"(",
"''",
")",
";",
"foreach",
"(",
"$",
"rs",
"as",
"$",
"rec",
")",
"{",
"mtrace",
"(",
"' '",
".",
"$",
"rec",
"->",
"url",
".",
"' '",
",",
"''",
")",
";",
"// Skip feed if it failed recently.",
"if",
"(",
"$",
"starttimesec",
"<",
"$",
"rec",
"->",
"skipuntil",
")",
"{",
"mtrace",
"(",
"'skipping until '",
".",
"userdate",
"(",
"$",
"rec",
"->",
"skipuntil",
")",
")",
";",
"continue",
";",
"}",
"$",
"feed",
"=",
"$",
"this",
"->",
"fetch_feed",
"(",
"$",
"rec",
"->",
"url",
")",
";",
"if",
"(",
"$",
"feed",
"->",
"error",
"(",
")",
")",
"{",
"// Skip this feed (for an ever-increasing time if it keeps failing).",
"$",
"rec",
"->",
"skiptime",
"=",
"$",
"this",
"->",
"calculate_skiptime",
"(",
"$",
"rec",
"->",
"skiptime",
")",
";",
"$",
"rec",
"->",
"skipuntil",
"=",
"time",
"(",
")",
"+",
"$",
"rec",
"->",
"skiptime",
";",
"$",
"DB",
"->",
"update_record",
"(",
"'block_rss_client'",
",",
"$",
"rec",
")",
";",
"mtrace",
"(",
"\"Error: could not load/find the RSS feed - skipping for {$rec->skiptime} seconds.\"",
")",
";",
"}",
"else",
"{",
"mtrace",
"(",
"'ok'",
")",
";",
"// It worked this time, so reset the skiptime.",
"if",
"(",
"$",
"rec",
"->",
"skiptime",
">",
"0",
")",
"{",
"$",
"rec",
"->",
"skiptime",
"=",
"0",
";",
"$",
"rec",
"->",
"skipuntil",
"=",
"0",
";",
"$",
"DB",
"->",
"update_record",
"(",
"'block_rss_client'",
",",
"$",
"rec",
")",
";",
"}",
"// Only increase the counter when a feed is sucesfully refreshed.",
"$",
"counter",
"++",
";",
"}",
"}",
"$",
"rs",
"->",
"close",
"(",
")",
";",
"// Show times.",
"mtrace",
"(",
"$",
"counter",
".",
"' feeds refreshed (took '",
".",
"microtime_diff",
"(",
"$",
"starttime",
",",
"microtime",
"(",
")",
")",
".",
"' seconds)'",
")",
";",
"}"
] | This task goes through all the feeds. If the feed has a skipuntil value
that is less than the current time cron will attempt to retrieve it
with the cache duration set to 0 in order to force the retrieval of
the item and refresh the cache.
If a feed fails then the skipuntil time of that feed is set to be
later than the next expected task time. The amount of time will
increase each time the fetch fails until the maximum is reached.
If a feed that has been failing is successfully retrieved it will
go back to being handled as though it had never failed.
Task should therefore process requests for permanently broken RSS
feeds infrequently, and temporarily unavailable feeds will be tried
less often until they become available again. | [
"This",
"task",
"goes",
"through",
"all",
"the",
"feeds",
".",
"If",
"the",
"feed",
"has",
"a",
"skipuntil",
"value",
"that",
"is",
"less",
"than",
"the",
"current",
"time",
"cron",
"will",
"attempt",
"to",
"retrieve",
"it",
"with",
"the",
"cache",
"duration",
"set",
"to",
"0",
"in",
"order",
"to",
"force",
"the",
"retrieval",
"of",
"the",
"item",
"and",
"refresh",
"the",
"cache",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/rss_client/classes/task/refreshfeeds.php#L69-L114 |
214,049 | moodle/moodle | blocks/rss_client/classes/task/refreshfeeds.php | refreshfeeds.fetch_feed | protected function fetch_feed(string $url) : \moodle_simplepie {
// Fetch the rss feed, using standard simplepie caching so feeds will be renewed only if cache has expired.
\core_php_time_limit::raise(60);
$feed = new \moodle_simplepie();
// Set timeout for longer than normal to be agressive at fetching feeds if possible..
$feed->set_timeout(40);
$feed->set_cache_duration(0);
$feed->set_feed_url($url);
$feed->init();
return $feed;
} | php | protected function fetch_feed(string $url) : \moodle_simplepie {
// Fetch the rss feed, using standard simplepie caching so feeds will be renewed only if cache has expired.
\core_php_time_limit::raise(60);
$feed = new \moodle_simplepie();
// Set timeout for longer than normal to be agressive at fetching feeds if possible..
$feed->set_timeout(40);
$feed->set_cache_duration(0);
$feed->set_feed_url($url);
$feed->init();
return $feed;
} | [
"protected",
"function",
"fetch_feed",
"(",
"string",
"$",
"url",
")",
":",
"\\",
"moodle_simplepie",
"{",
"// Fetch the rss feed, using standard simplepie caching so feeds will be renewed only if cache has expired.",
"\\",
"core_php_time_limit",
"::",
"raise",
"(",
"60",
")",
";",
"$",
"feed",
"=",
"new",
"\\",
"moodle_simplepie",
"(",
")",
";",
"// Set timeout for longer than normal to be agressive at fetching feeds if possible..",
"$",
"feed",
"->",
"set_timeout",
"(",
"40",
")",
";",
"$",
"feed",
"->",
"set_cache_duration",
"(",
"0",
")",
";",
"$",
"feed",
"->",
"set_feed_url",
"(",
"$",
"url",
")",
";",
"$",
"feed",
"->",
"init",
"(",
")",
";",
"return",
"$",
"feed",
";",
"}"
] | Fetch a feed for the specified URL.
@param string $url The URL to fetch
@return \moodle_simplepie | [
"Fetch",
"a",
"feed",
"for",
"the",
"specified",
"URL",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/rss_client/classes/task/refreshfeeds.php#L122-L135 |
214,050 | moodle/moodle | blocks/rss_client/classes/task/refreshfeeds.php | refreshfeeds.calculate_skiptime | protected function calculate_skiptime(int $currentskip) : int {
// If the feed has never failed, then the initial skiptime will be 0. We use a default of 5 minutes in this case.
// If the feed has previously failed then we double that time.
$newskiptime = max(MINSECS * 5, ($currentskip * 2));
// Max out at the CLIENT_MAX_SKIPTIME.
return min($newskiptime, self::CLIENT_MAX_SKIPTIME);
} | php | protected function calculate_skiptime(int $currentskip) : int {
// If the feed has never failed, then the initial skiptime will be 0. We use a default of 5 minutes in this case.
// If the feed has previously failed then we double that time.
$newskiptime = max(MINSECS * 5, ($currentskip * 2));
// Max out at the CLIENT_MAX_SKIPTIME.
return min($newskiptime, self::CLIENT_MAX_SKIPTIME);
} | [
"protected",
"function",
"calculate_skiptime",
"(",
"int",
"$",
"currentskip",
")",
":",
"int",
"{",
"// If the feed has never failed, then the initial skiptime will be 0. We use a default of 5 minutes in this case.",
"// If the feed has previously failed then we double that time.",
"$",
"newskiptime",
"=",
"max",
"(",
"MINSECS",
"*",
"5",
",",
"(",
"$",
"currentskip",
"*",
"2",
")",
")",
";",
"// Max out at the CLIENT_MAX_SKIPTIME.",
"return",
"min",
"(",
"$",
"newskiptime",
",",
"self",
"::",
"CLIENT_MAX_SKIPTIME",
")",
";",
"}"
] | Calculates a new skip time for a record based on the current skip time.
@param int $currentskip The current skip time of a record.
@return int The newly calculated skip time. | [
"Calculates",
"a",
"new",
"skip",
"time",
"for",
"a",
"record",
"based",
"on",
"the",
"current",
"skip",
"time",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/rss_client/classes/task/refreshfeeds.php#L143-L150 |
214,051 | moodle/moodle | calendar/externallib.php | core_calendar_external.delete_calendar_events | public static function delete_calendar_events($events) {
global $DB;
// Parameter validation.
$params = self::validate_parameters(self:: delete_calendar_events_parameters(), array('events' => $events));
$transaction = $DB->start_delegated_transaction();
foreach ($params['events'] as $event) {
$eventobj = calendar_event::load($event['eventid']);
// Let's check if the user is allowed to delete an event.
if (!calendar_delete_event_allowed($eventobj)) {
throw new moodle_exception('nopermissions', 'error', '', get_string('deleteevent', 'calendar'));
}
// Time to do the magic.
$eventobj->delete($event['repeat']);
}
// Everything done smoothly, let's commit.
$transaction->allow_commit();
return null;
} | php | public static function delete_calendar_events($events) {
global $DB;
// Parameter validation.
$params = self::validate_parameters(self:: delete_calendar_events_parameters(), array('events' => $events));
$transaction = $DB->start_delegated_transaction();
foreach ($params['events'] as $event) {
$eventobj = calendar_event::load($event['eventid']);
// Let's check if the user is allowed to delete an event.
if (!calendar_delete_event_allowed($eventobj)) {
throw new moodle_exception('nopermissions', 'error', '', get_string('deleteevent', 'calendar'));
}
// Time to do the magic.
$eventobj->delete($event['repeat']);
}
// Everything done smoothly, let's commit.
$transaction->allow_commit();
return null;
} | [
"public",
"static",
"function",
"delete_calendar_events",
"(",
"$",
"events",
")",
"{",
"global",
"$",
"DB",
";",
"// Parameter validation.",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"delete_calendar_events_parameters",
"(",
")",
",",
"array",
"(",
"'events'",
"=>",
"$",
"events",
")",
")",
";",
"$",
"transaction",
"=",
"$",
"DB",
"->",
"start_delegated_transaction",
"(",
")",
";",
"foreach",
"(",
"$",
"params",
"[",
"'events'",
"]",
"as",
"$",
"event",
")",
"{",
"$",
"eventobj",
"=",
"calendar_event",
"::",
"load",
"(",
"$",
"event",
"[",
"'eventid'",
"]",
")",
";",
"// Let's check if the user is allowed to delete an event.",
"if",
"(",
"!",
"calendar_delete_event_allowed",
"(",
"$",
"eventobj",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'nopermissions'",
",",
"'error'",
",",
"''",
",",
"get_string",
"(",
"'deleteevent'",
",",
"'calendar'",
")",
")",
";",
"}",
"// Time to do the magic.",
"$",
"eventobj",
"->",
"delete",
"(",
"$",
"event",
"[",
"'repeat'",
"]",
")",
";",
"}",
"// Everything done smoothly, let's commit.",
"$",
"transaction",
"->",
"allow_commit",
"(",
")",
";",
"return",
"null",
";",
"}"
] | Delete Calendar events
@param array $eventids A list of event ids with repeat flag to delete
@return null
@since Moodle 2.5 | [
"Delete",
"Calendar",
"events"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/externallib.php#L82-L105 |
214,052 | moodle/moodle | calendar/externallib.php | core_calendar_external.get_calendar_action_events_by_timesort | public static function get_calendar_action_events_by_timesort($timesortfrom = 0, $timesortto = null,
$aftereventid = 0, $limitnum = 20, $limittononsuspendedevents = false,
$userid = null) {
global $PAGE, $USER;
$params = self::validate_parameters(
self::get_calendar_action_events_by_timesort_parameters(),
[
'timesortfrom' => $timesortfrom,
'timesortto' => $timesortto,
'aftereventid' => $aftereventid,
'limitnum' => $limitnum,
'limittononsuspendedevents' => $limittononsuspendedevents,
'userid' => $userid,
]
);
if ($params['userid']) {
$user = \core_user::get_user($params['userid']);
} else {
$user = $USER;
}
$context = \context_user::instance($user->id);
self::validate_context($context);
if (empty($params['aftereventid'])) {
$params['aftereventid'] = null;
}
$renderer = $PAGE->get_renderer('core_calendar');
$events = local_api::get_action_events_by_timesort(
$params['timesortfrom'],
$params['timesortto'],
$params['aftereventid'],
$params['limitnum'],
$params['limittononsuspendedevents'],
$user
);
$exportercache = new events_related_objects_cache($events);
$exporter = new events_exporter($events, ['cache' => $exportercache]);
return $exporter->export($renderer);
} | php | public static function get_calendar_action_events_by_timesort($timesortfrom = 0, $timesortto = null,
$aftereventid = 0, $limitnum = 20, $limittononsuspendedevents = false,
$userid = null) {
global $PAGE, $USER;
$params = self::validate_parameters(
self::get_calendar_action_events_by_timesort_parameters(),
[
'timesortfrom' => $timesortfrom,
'timesortto' => $timesortto,
'aftereventid' => $aftereventid,
'limitnum' => $limitnum,
'limittononsuspendedevents' => $limittononsuspendedevents,
'userid' => $userid,
]
);
if ($params['userid']) {
$user = \core_user::get_user($params['userid']);
} else {
$user = $USER;
}
$context = \context_user::instance($user->id);
self::validate_context($context);
if (empty($params['aftereventid'])) {
$params['aftereventid'] = null;
}
$renderer = $PAGE->get_renderer('core_calendar');
$events = local_api::get_action_events_by_timesort(
$params['timesortfrom'],
$params['timesortto'],
$params['aftereventid'],
$params['limitnum'],
$params['limittononsuspendedevents'],
$user
);
$exportercache = new events_related_objects_cache($events);
$exporter = new events_exporter($events, ['cache' => $exportercache]);
return $exporter->export($renderer);
} | [
"public",
"static",
"function",
"get_calendar_action_events_by_timesort",
"(",
"$",
"timesortfrom",
"=",
"0",
",",
"$",
"timesortto",
"=",
"null",
",",
"$",
"aftereventid",
"=",
"0",
",",
"$",
"limitnum",
"=",
"20",
",",
"$",
"limittononsuspendedevents",
"=",
"false",
",",
"$",
"userid",
"=",
"null",
")",
"{",
"global",
"$",
"PAGE",
",",
"$",
"USER",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_calendar_action_events_by_timesort_parameters",
"(",
")",
",",
"[",
"'timesortfrom'",
"=>",
"$",
"timesortfrom",
",",
"'timesortto'",
"=>",
"$",
"timesortto",
",",
"'aftereventid'",
"=>",
"$",
"aftereventid",
",",
"'limitnum'",
"=>",
"$",
"limitnum",
",",
"'limittononsuspendedevents'",
"=>",
"$",
"limittononsuspendedevents",
",",
"'userid'",
"=>",
"$",
"userid",
",",
"]",
")",
";",
"if",
"(",
"$",
"params",
"[",
"'userid'",
"]",
")",
"{",
"$",
"user",
"=",
"\\",
"core_user",
"::",
"get_user",
"(",
"$",
"params",
"[",
"'userid'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"user",
"=",
"$",
"USER",
";",
"}",
"$",
"context",
"=",
"\\",
"context_user",
"::",
"instance",
"(",
"$",
"user",
"->",
"id",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"params",
"[",
"'aftereventid'",
"]",
")",
")",
"{",
"$",
"params",
"[",
"'aftereventid'",
"]",
"=",
"null",
";",
"}",
"$",
"renderer",
"=",
"$",
"PAGE",
"->",
"get_renderer",
"(",
"'core_calendar'",
")",
";",
"$",
"events",
"=",
"local_api",
"::",
"get_action_events_by_timesort",
"(",
"$",
"params",
"[",
"'timesortfrom'",
"]",
",",
"$",
"params",
"[",
"'timesortto'",
"]",
",",
"$",
"params",
"[",
"'aftereventid'",
"]",
",",
"$",
"params",
"[",
"'limitnum'",
"]",
",",
"$",
"params",
"[",
"'limittononsuspendedevents'",
"]",
",",
"$",
"user",
")",
";",
"$",
"exportercache",
"=",
"new",
"events_related_objects_cache",
"(",
"$",
"events",
")",
";",
"$",
"exporter",
"=",
"new",
"events_exporter",
"(",
"$",
"events",
",",
"[",
"'cache'",
"=>",
"$",
"exportercache",
"]",
")",
";",
"return",
"$",
"exporter",
"->",
"export",
"(",
"$",
"renderer",
")",
";",
"}"
] | Get calendar action events based on the timesort value.
@since Moodle 3.3
@param null|int $timesortfrom Events after this time (inclusive)
@param null|int $timesortto Events before this time (inclusive)
@param null|int $aftereventid Get events with ids greater than this one
@param int $limitnum Limit the number of results to this value
@param null|int $userid The user id
@return array | [
"Get",
"calendar",
"action",
"events",
"based",
"on",
"the",
"timesort",
"value",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/externallib.php#L425-L468 |
214,053 | moodle/moodle | calendar/externallib.php | core_calendar_external.get_calendar_action_events_by_course | public static function get_calendar_action_events_by_course(
$courseid, $timesortfrom = null, $timesortto = null, $aftereventid = 0, $limitnum = 20) {
global $PAGE, $USER;
$user = null;
$params = self::validate_parameters(
self::get_calendar_action_events_by_course_parameters(),
[
'courseid' => $courseid,
'timesortfrom' => $timesortfrom,
'timesortto' => $timesortto,
'aftereventid' => $aftereventid,
'limitnum' => $limitnum,
]
);
$context = \context_user::instance($USER->id);
self::validate_context($context);
if (empty($params['aftereventid'])) {
$params['aftereventid'] = null;
}
$courses = enrol_get_my_courses('*', null, 0, [$courseid]);
$courses = array_values($courses);
if (empty($courses)) {
return [];
}
$course = $courses[0];
$renderer = $PAGE->get_renderer('core_calendar');
$events = local_api::get_action_events_by_course(
$course,
$params['timesortfrom'],
$params['timesortto'],
$params['aftereventid'],
$params['limitnum']
);
$exportercache = new events_related_objects_cache($events, $courses);
$exporter = new events_exporter($events, ['cache' => $exportercache]);
return $exporter->export($renderer);
} | php | public static function get_calendar_action_events_by_course(
$courseid, $timesortfrom = null, $timesortto = null, $aftereventid = 0, $limitnum = 20) {
global $PAGE, $USER;
$user = null;
$params = self::validate_parameters(
self::get_calendar_action_events_by_course_parameters(),
[
'courseid' => $courseid,
'timesortfrom' => $timesortfrom,
'timesortto' => $timesortto,
'aftereventid' => $aftereventid,
'limitnum' => $limitnum,
]
);
$context = \context_user::instance($USER->id);
self::validate_context($context);
if (empty($params['aftereventid'])) {
$params['aftereventid'] = null;
}
$courses = enrol_get_my_courses('*', null, 0, [$courseid]);
$courses = array_values($courses);
if (empty($courses)) {
return [];
}
$course = $courses[0];
$renderer = $PAGE->get_renderer('core_calendar');
$events = local_api::get_action_events_by_course(
$course,
$params['timesortfrom'],
$params['timesortto'],
$params['aftereventid'],
$params['limitnum']
);
$exportercache = new events_related_objects_cache($events, $courses);
$exporter = new events_exporter($events, ['cache' => $exportercache]);
return $exporter->export($renderer);
} | [
"public",
"static",
"function",
"get_calendar_action_events_by_course",
"(",
"$",
"courseid",
",",
"$",
"timesortfrom",
"=",
"null",
",",
"$",
"timesortto",
"=",
"null",
",",
"$",
"aftereventid",
"=",
"0",
",",
"$",
"limitnum",
"=",
"20",
")",
"{",
"global",
"$",
"PAGE",
",",
"$",
"USER",
";",
"$",
"user",
"=",
"null",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_calendar_action_events_by_course_parameters",
"(",
")",
",",
"[",
"'courseid'",
"=>",
"$",
"courseid",
",",
"'timesortfrom'",
"=>",
"$",
"timesortfrom",
",",
"'timesortto'",
"=>",
"$",
"timesortto",
",",
"'aftereventid'",
"=>",
"$",
"aftereventid",
",",
"'limitnum'",
"=>",
"$",
"limitnum",
",",
"]",
")",
";",
"$",
"context",
"=",
"\\",
"context_user",
"::",
"instance",
"(",
"$",
"USER",
"->",
"id",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"params",
"[",
"'aftereventid'",
"]",
")",
")",
"{",
"$",
"params",
"[",
"'aftereventid'",
"]",
"=",
"null",
";",
"}",
"$",
"courses",
"=",
"enrol_get_my_courses",
"(",
"'*'",
",",
"null",
",",
"0",
",",
"[",
"$",
"courseid",
"]",
")",
";",
"$",
"courses",
"=",
"array_values",
"(",
"$",
"courses",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"courses",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"course",
"=",
"$",
"courses",
"[",
"0",
"]",
";",
"$",
"renderer",
"=",
"$",
"PAGE",
"->",
"get_renderer",
"(",
"'core_calendar'",
")",
";",
"$",
"events",
"=",
"local_api",
"::",
"get_action_events_by_course",
"(",
"$",
"course",
",",
"$",
"params",
"[",
"'timesortfrom'",
"]",
",",
"$",
"params",
"[",
"'timesortto'",
"]",
",",
"$",
"params",
"[",
"'aftereventid'",
"]",
",",
"$",
"params",
"[",
"'limitnum'",
"]",
")",
";",
"$",
"exportercache",
"=",
"new",
"events_related_objects_cache",
"(",
"$",
"events",
",",
"$",
"courses",
")",
";",
"$",
"exporter",
"=",
"new",
"events_exporter",
"(",
"$",
"events",
",",
"[",
"'cache'",
"=>",
"$",
"exportercache",
"]",
")",
";",
"return",
"$",
"exporter",
"->",
"export",
"(",
"$",
"renderer",
")",
";",
"}"
] | Get calendar action events for the given course.
@since Moodle 3.3
@param int $courseid Only events in this course
@param null|int $timesortfrom Events after this time (inclusive)
@param null|int $timesortto Events before this time (inclusive)
@param null|int $aftereventid Get events with ids greater than this one
@param int $limitnum Limit the number of results to this value
@return array | [
"Get",
"calendar",
"action",
"events",
"for",
"the",
"given",
"course",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/externallib.php#L508-L552 |
214,054 | moodle/moodle | calendar/externallib.php | core_calendar_external.get_calendar_action_events_by_courses | public static function get_calendar_action_events_by_courses(
array $courseids, $timesortfrom = null, $timesortto = null, $limitnum = 10) {
global $PAGE, $USER;
$user = null;
$params = self::validate_parameters(
self::get_calendar_action_events_by_courses_parameters(),
[
'courseids' => $courseids,
'timesortfrom' => $timesortfrom,
'timesortto' => $timesortto,
'limitnum' => $limitnum,
]
);
$context = \context_user::instance($USER->id);
self::validate_context($context);
if (empty($params['courseids'])) {
return ['groupedbycourse' => []];
}
$renderer = $PAGE->get_renderer('core_calendar');
$courses = enrol_get_my_courses('*', null, 0, $params['courseids']);
$courses = array_values($courses);
if (empty($courses)) {
return ['groupedbycourse' => []];
}
$events = local_api::get_action_events_by_courses(
$courses,
$params['timesortfrom'],
$params['timesortto'],
$params['limitnum']
);
if (empty($events)) {
return ['groupedbycourse' => []];
}
$exportercache = new events_related_objects_cache($events, $courses);
$exporter = new events_grouped_by_course_exporter($events, ['cache' => $exportercache]);
return $exporter->export($renderer);
} | php | public static function get_calendar_action_events_by_courses(
array $courseids, $timesortfrom = null, $timesortto = null, $limitnum = 10) {
global $PAGE, $USER;
$user = null;
$params = self::validate_parameters(
self::get_calendar_action_events_by_courses_parameters(),
[
'courseids' => $courseids,
'timesortfrom' => $timesortfrom,
'timesortto' => $timesortto,
'limitnum' => $limitnum,
]
);
$context = \context_user::instance($USER->id);
self::validate_context($context);
if (empty($params['courseids'])) {
return ['groupedbycourse' => []];
}
$renderer = $PAGE->get_renderer('core_calendar');
$courses = enrol_get_my_courses('*', null, 0, $params['courseids']);
$courses = array_values($courses);
if (empty($courses)) {
return ['groupedbycourse' => []];
}
$events = local_api::get_action_events_by_courses(
$courses,
$params['timesortfrom'],
$params['timesortto'],
$params['limitnum']
);
if (empty($events)) {
return ['groupedbycourse' => []];
}
$exportercache = new events_related_objects_cache($events, $courses);
$exporter = new events_grouped_by_course_exporter($events, ['cache' => $exportercache]);
return $exporter->export($renderer);
} | [
"public",
"static",
"function",
"get_calendar_action_events_by_courses",
"(",
"array",
"$",
"courseids",
",",
"$",
"timesortfrom",
"=",
"null",
",",
"$",
"timesortto",
"=",
"null",
",",
"$",
"limitnum",
"=",
"10",
")",
"{",
"global",
"$",
"PAGE",
",",
"$",
"USER",
";",
"$",
"user",
"=",
"null",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_calendar_action_events_by_courses_parameters",
"(",
")",
",",
"[",
"'courseids'",
"=>",
"$",
"courseids",
",",
"'timesortfrom'",
"=>",
"$",
"timesortfrom",
",",
"'timesortto'",
"=>",
"$",
"timesortto",
",",
"'limitnum'",
"=>",
"$",
"limitnum",
",",
"]",
")",
";",
"$",
"context",
"=",
"\\",
"context_user",
"::",
"instance",
"(",
"$",
"USER",
"->",
"id",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"params",
"[",
"'courseids'",
"]",
")",
")",
"{",
"return",
"[",
"'groupedbycourse'",
"=>",
"[",
"]",
"]",
";",
"}",
"$",
"renderer",
"=",
"$",
"PAGE",
"->",
"get_renderer",
"(",
"'core_calendar'",
")",
";",
"$",
"courses",
"=",
"enrol_get_my_courses",
"(",
"'*'",
",",
"null",
",",
"0",
",",
"$",
"params",
"[",
"'courseids'",
"]",
")",
";",
"$",
"courses",
"=",
"array_values",
"(",
"$",
"courses",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"courses",
")",
")",
"{",
"return",
"[",
"'groupedbycourse'",
"=>",
"[",
"]",
"]",
";",
"}",
"$",
"events",
"=",
"local_api",
"::",
"get_action_events_by_courses",
"(",
"$",
"courses",
",",
"$",
"params",
"[",
"'timesortfrom'",
"]",
",",
"$",
"params",
"[",
"'timesortto'",
"]",
",",
"$",
"params",
"[",
"'limitnum'",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"events",
")",
")",
"{",
"return",
"[",
"'groupedbycourse'",
"=>",
"[",
"]",
"]",
";",
"}",
"$",
"exportercache",
"=",
"new",
"events_related_objects_cache",
"(",
"$",
"events",
",",
"$",
"courses",
")",
";",
"$",
"exporter",
"=",
"new",
"events_grouped_by_course_exporter",
"(",
"$",
"events",
",",
"[",
"'cache'",
"=>",
"$",
"exportercache",
"]",
")",
";",
"return",
"$",
"exporter",
"->",
"export",
"(",
"$",
"renderer",
")",
";",
"}"
] | Get calendar action events for a given list of courses.
@since Moodle 3.3
@param array $courseids Only include events for these courses
@param null|int $timesortfrom Events after this time (inclusive)
@param null|int $timesortto Events before this time (inclusive)
@param int $limitnum Limit the number of results per course to this value
@return array | [
"Get",
"calendar",
"action",
"events",
"for",
"a",
"given",
"list",
"of",
"courses",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/externallib.php#L591-L636 |
214,055 | moodle/moodle | calendar/externallib.php | core_calendar_external.create_calendar_events | public static function create_calendar_events($events) {
global $DB, $USER;
// Parameter validation.
$params = self::validate_parameters(self::create_calendar_events_parameters(), array('events' => $events));
$transaction = $DB->start_delegated_transaction();
$return = array();
$warnings = array();
foreach ($params['events'] as $event) {
// Let us set some defaults.
$event['userid'] = $USER->id;
$event['modulename'] = '';
$event['instance'] = 0;
$event['subscriptionid'] = null;
$event['uuid']= '';
$event['format'] = external_validate_format($event['format']);
if ($event['repeats'] > 0) {
$event['repeat'] = 1;
} else {
$event['repeat'] = 0;
}
$eventobj = new calendar_event($event);
// Let's check if the user is allowed to delete an event.
if (!calendar_add_event_allowed($eventobj)) {
$warnings [] = array('item' => $event['name'], 'warningcode' => 'nopermissions', 'message' => 'you do not have permissions to create this event');
continue;
}
// Let's create the event.
$var = $eventobj->create($event);
$var = (array)$var->properties();
if ($event['repeat']) {
$children = $DB->get_records('event', array('repeatid' => $var['id']));
foreach ($children as $child) {
$return[] = (array) $child;
}
} else {
$return[] = $var;
}
}
// Everything done smoothly, let's commit.
$transaction->allow_commit();
return array('events' => $return, 'warnings' => $warnings);
} | php | public static function create_calendar_events($events) {
global $DB, $USER;
// Parameter validation.
$params = self::validate_parameters(self::create_calendar_events_parameters(), array('events' => $events));
$transaction = $DB->start_delegated_transaction();
$return = array();
$warnings = array();
foreach ($params['events'] as $event) {
// Let us set some defaults.
$event['userid'] = $USER->id;
$event['modulename'] = '';
$event['instance'] = 0;
$event['subscriptionid'] = null;
$event['uuid']= '';
$event['format'] = external_validate_format($event['format']);
if ($event['repeats'] > 0) {
$event['repeat'] = 1;
} else {
$event['repeat'] = 0;
}
$eventobj = new calendar_event($event);
// Let's check if the user is allowed to delete an event.
if (!calendar_add_event_allowed($eventobj)) {
$warnings [] = array('item' => $event['name'], 'warningcode' => 'nopermissions', 'message' => 'you do not have permissions to create this event');
continue;
}
// Let's create the event.
$var = $eventobj->create($event);
$var = (array)$var->properties();
if ($event['repeat']) {
$children = $DB->get_records('event', array('repeatid' => $var['id']));
foreach ($children as $child) {
$return[] = (array) $child;
}
} else {
$return[] = $var;
}
}
// Everything done smoothly, let's commit.
$transaction->allow_commit();
return array('events' => $return, 'warnings' => $warnings);
} | [
"public",
"static",
"function",
"create_calendar_events",
"(",
"$",
"events",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"USER",
";",
"// Parameter validation.",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"create_calendar_events_parameters",
"(",
")",
",",
"array",
"(",
"'events'",
"=>",
"$",
"events",
")",
")",
";",
"$",
"transaction",
"=",
"$",
"DB",
"->",
"start_delegated_transaction",
"(",
")",
";",
"$",
"return",
"=",
"array",
"(",
")",
";",
"$",
"warnings",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"params",
"[",
"'events'",
"]",
"as",
"$",
"event",
")",
"{",
"// Let us set some defaults.",
"$",
"event",
"[",
"'userid'",
"]",
"=",
"$",
"USER",
"->",
"id",
";",
"$",
"event",
"[",
"'modulename'",
"]",
"=",
"''",
";",
"$",
"event",
"[",
"'instance'",
"]",
"=",
"0",
";",
"$",
"event",
"[",
"'subscriptionid'",
"]",
"=",
"null",
";",
"$",
"event",
"[",
"'uuid'",
"]",
"=",
"''",
";",
"$",
"event",
"[",
"'format'",
"]",
"=",
"external_validate_format",
"(",
"$",
"event",
"[",
"'format'",
"]",
")",
";",
"if",
"(",
"$",
"event",
"[",
"'repeats'",
"]",
">",
"0",
")",
"{",
"$",
"event",
"[",
"'repeat'",
"]",
"=",
"1",
";",
"}",
"else",
"{",
"$",
"event",
"[",
"'repeat'",
"]",
"=",
"0",
";",
"}",
"$",
"eventobj",
"=",
"new",
"calendar_event",
"(",
"$",
"event",
")",
";",
"// Let's check if the user is allowed to delete an event.",
"if",
"(",
"!",
"calendar_add_event_allowed",
"(",
"$",
"eventobj",
")",
")",
"{",
"$",
"warnings",
"[",
"]",
"=",
"array",
"(",
"'item'",
"=>",
"$",
"event",
"[",
"'name'",
"]",
",",
"'warningcode'",
"=>",
"'nopermissions'",
",",
"'message'",
"=>",
"'you do not have permissions to create this event'",
")",
";",
"continue",
";",
"}",
"// Let's create the event.",
"$",
"var",
"=",
"$",
"eventobj",
"->",
"create",
"(",
"$",
"event",
")",
";",
"$",
"var",
"=",
"(",
"array",
")",
"$",
"var",
"->",
"properties",
"(",
")",
";",
"if",
"(",
"$",
"event",
"[",
"'repeat'",
"]",
")",
"{",
"$",
"children",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'event'",
",",
"array",
"(",
"'repeatid'",
"=>",
"$",
"var",
"[",
"'id'",
"]",
")",
")",
";",
"foreach",
"(",
"$",
"children",
"as",
"$",
"child",
")",
"{",
"$",
"return",
"[",
"]",
"=",
"(",
"array",
")",
"$",
"child",
";",
"}",
"}",
"else",
"{",
"$",
"return",
"[",
"]",
"=",
"$",
"var",
";",
"}",
"}",
"// Everything done smoothly, let's commit.",
"$",
"transaction",
"->",
"allow_commit",
"(",
")",
";",
"return",
"array",
"(",
"'events'",
"=>",
"$",
"return",
",",
"'warnings'",
"=>",
"$",
"warnings",
")",
";",
"}"
] | Delete Calendar events.
@param array $events A list of events to create.
@return array array of events created.
@since Moodle 2.5
@throws moodle_exception if user doesnt have the permission to create events. | [
"Delete",
"Calendar",
"events",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/externallib.php#L686-L734 |
214,056 | moodle/moodle | calendar/externallib.php | core_calendar_external.get_calendar_event_by_id | public static function get_calendar_event_by_id($eventid) {
global $PAGE, $USER;
$params = self::validate_parameters(self::get_calendar_event_by_id_parameters(), ['eventid' => $eventid]);
$context = \context_user::instance($USER->id);
self::validate_context($context);
$warnings = array();
$legacyevent = calendar_event::load($eventid);
// Must check we can see this event.
if (!calendar_view_event_allowed($legacyevent)) {
// We can't return a warning in this case because the event is not optional.
// We don't know the context for the event and it's not worth loading it.
$syscontext = context_system::instance();
throw new \required_capability_exception($syscontext, 'moodle/course:view', 'nopermission', '');
}
$legacyevent->count_repeats();
$eventmapper = event_container::get_event_mapper();
$event = $eventmapper->from_legacy_event_to_event($legacyevent);
$cache = new events_related_objects_cache([$event]);
$relatedobjects = [
'context' => $cache->get_context($event),
'course' => $cache->get_course($event),
];
$exporter = new event_exporter($event, $relatedobjects);
$renderer = $PAGE->get_renderer('core_calendar');
return array('event' => $exporter->export($renderer), 'warnings' => $warnings);
} | php | public static function get_calendar_event_by_id($eventid) {
global $PAGE, $USER;
$params = self::validate_parameters(self::get_calendar_event_by_id_parameters(), ['eventid' => $eventid]);
$context = \context_user::instance($USER->id);
self::validate_context($context);
$warnings = array();
$legacyevent = calendar_event::load($eventid);
// Must check we can see this event.
if (!calendar_view_event_allowed($legacyevent)) {
// We can't return a warning in this case because the event is not optional.
// We don't know the context for the event and it's not worth loading it.
$syscontext = context_system::instance();
throw new \required_capability_exception($syscontext, 'moodle/course:view', 'nopermission', '');
}
$legacyevent->count_repeats();
$eventmapper = event_container::get_event_mapper();
$event = $eventmapper->from_legacy_event_to_event($legacyevent);
$cache = new events_related_objects_cache([$event]);
$relatedobjects = [
'context' => $cache->get_context($event),
'course' => $cache->get_course($event),
];
$exporter = new event_exporter($event, $relatedobjects);
$renderer = $PAGE->get_renderer('core_calendar');
return array('event' => $exporter->export($renderer), 'warnings' => $warnings);
} | [
"public",
"static",
"function",
"get_calendar_event_by_id",
"(",
"$",
"eventid",
")",
"{",
"global",
"$",
"PAGE",
",",
"$",
"USER",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_calendar_event_by_id_parameters",
"(",
")",
",",
"[",
"'eventid'",
"=>",
"$",
"eventid",
"]",
")",
";",
"$",
"context",
"=",
"\\",
"context_user",
"::",
"instance",
"(",
"$",
"USER",
"->",
"id",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"$",
"warnings",
"=",
"array",
"(",
")",
";",
"$",
"legacyevent",
"=",
"calendar_event",
"::",
"load",
"(",
"$",
"eventid",
")",
";",
"// Must check we can see this event.",
"if",
"(",
"!",
"calendar_view_event_allowed",
"(",
"$",
"legacyevent",
")",
")",
"{",
"// We can't return a warning in this case because the event is not optional.",
"// We don't know the context for the event and it's not worth loading it.",
"$",
"syscontext",
"=",
"context_system",
"::",
"instance",
"(",
")",
";",
"throw",
"new",
"\\",
"required_capability_exception",
"(",
"$",
"syscontext",
",",
"'moodle/course:view'",
",",
"'nopermission'",
",",
"''",
")",
";",
"}",
"$",
"legacyevent",
"->",
"count_repeats",
"(",
")",
";",
"$",
"eventmapper",
"=",
"event_container",
"::",
"get_event_mapper",
"(",
")",
";",
"$",
"event",
"=",
"$",
"eventmapper",
"->",
"from_legacy_event_to_event",
"(",
"$",
"legacyevent",
")",
";",
"$",
"cache",
"=",
"new",
"events_related_objects_cache",
"(",
"[",
"$",
"event",
"]",
")",
";",
"$",
"relatedobjects",
"=",
"[",
"'context'",
"=>",
"$",
"cache",
"->",
"get_context",
"(",
"$",
"event",
")",
",",
"'course'",
"=>",
"$",
"cache",
"->",
"get_course",
"(",
"$",
"event",
")",
",",
"]",
";",
"$",
"exporter",
"=",
"new",
"event_exporter",
"(",
"$",
"event",
",",
"$",
"relatedobjects",
")",
";",
"$",
"renderer",
"=",
"$",
"PAGE",
"->",
"get_renderer",
"(",
"'core_calendar'",
")",
";",
"return",
"array",
"(",
"'event'",
"=>",
"$",
"exporter",
"->",
"export",
"(",
"$",
"renderer",
")",
",",
"'warnings'",
"=>",
"$",
"warnings",
")",
";",
"}"
] | Get calendar event by id.
@param int $eventid The calendar event id to be retrieved.
@return array Array of event details | [
"Get",
"calendar",
"event",
"by",
"id",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/externallib.php#L791-L824 |
214,057 | moodle/moodle | calendar/externallib.php | core_calendar_external.get_calendar_day_view | public static function get_calendar_day_view($year, $month, $day, $courseid, $categoryid) {
global $DB, $USER, $PAGE;
// Parameter validation.
$params = self::validate_parameters(self::get_calendar_day_view_parameters(), [
'year' => $year,
'month' => $month,
'day' => $day,
'courseid' => $courseid,
'categoryid' => $categoryid,
]);
$context = \context_user::instance($USER->id);
self::validate_context($context);
$type = \core_calendar\type_factory::get_calendar_instance();
$time = $type->convert_to_timestamp($params['year'], $params['month'], $params['day']);
$calendar = \calendar_information::create($time, $params['courseid'], $params['categoryid']);
self::validate_context($calendar->context);
list($data, $template) = calendar_get_view($calendar, 'day');
return $data;
} | php | public static function get_calendar_day_view($year, $month, $day, $courseid, $categoryid) {
global $DB, $USER, $PAGE;
// Parameter validation.
$params = self::validate_parameters(self::get_calendar_day_view_parameters(), [
'year' => $year,
'month' => $month,
'day' => $day,
'courseid' => $courseid,
'categoryid' => $categoryid,
]);
$context = \context_user::instance($USER->id);
self::validate_context($context);
$type = \core_calendar\type_factory::get_calendar_instance();
$time = $type->convert_to_timestamp($params['year'], $params['month'], $params['day']);
$calendar = \calendar_information::create($time, $params['courseid'], $params['categoryid']);
self::validate_context($calendar->context);
list($data, $template) = calendar_get_view($calendar, 'day');
return $data;
} | [
"public",
"static",
"function",
"get_calendar_day_view",
"(",
"$",
"year",
",",
"$",
"month",
",",
"$",
"day",
",",
"$",
"courseid",
",",
"$",
"categoryid",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"USER",
",",
"$",
"PAGE",
";",
"// Parameter validation.",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_calendar_day_view_parameters",
"(",
")",
",",
"[",
"'year'",
"=>",
"$",
"year",
",",
"'month'",
"=>",
"$",
"month",
",",
"'day'",
"=>",
"$",
"day",
",",
"'courseid'",
"=>",
"$",
"courseid",
",",
"'categoryid'",
"=>",
"$",
"categoryid",
",",
"]",
")",
";",
"$",
"context",
"=",
"\\",
"context_user",
"::",
"instance",
"(",
"$",
"USER",
"->",
"id",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"$",
"type",
"=",
"\\",
"core_calendar",
"\\",
"type_factory",
"::",
"get_calendar_instance",
"(",
")",
";",
"$",
"time",
"=",
"$",
"type",
"->",
"convert_to_timestamp",
"(",
"$",
"params",
"[",
"'year'",
"]",
",",
"$",
"params",
"[",
"'month'",
"]",
",",
"$",
"params",
"[",
"'day'",
"]",
")",
";",
"$",
"calendar",
"=",
"\\",
"calendar_information",
"::",
"create",
"(",
"$",
"time",
",",
"$",
"params",
"[",
"'courseid'",
"]",
",",
"$",
"params",
"[",
"'categoryid'",
"]",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"calendar",
"->",
"context",
")",
";",
"list",
"(",
"$",
"data",
",",
"$",
"template",
")",
"=",
"calendar_get_view",
"(",
"$",
"calendar",
",",
"'day'",
")",
";",
"return",
"$",
"data",
";",
"}"
] | Get data for the daily calendar view.
@param int $year The year to be shown
@param int $month The month to be shown
@param int $day The day to be shown
@param int $courseid The course to be included
@return array | [
"Get",
"data",
"for",
"the",
"daily",
"calendar",
"view",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/externallib.php#L1064-L1088 |
214,058 | moodle/moodle | calendar/externallib.php | core_calendar_external.update_event_start_day | public static function update_event_start_day($eventid, $daytimestamp) {
global $USER, $PAGE;
// Parameter validation.
$params = self::validate_parameters(self::update_event_start_day_parameters(), [
'eventid' => $eventid,
'daytimestamp' => $daytimestamp,
]);
$vault = event_container::get_event_vault();
$mapper = event_container::get_event_mapper();
$event = $vault->get_event_by_id($eventid);
if (!$event) {
throw new \moodle_exception('Unable to find event with id ' . $eventid);
}
$legacyevent = $mapper->from_event_to_legacy_event($event);
if (!calendar_edit_event_allowed($legacyevent, true)) {
print_error('nopermissiontoupdatecalendar');
}
self::validate_context($legacyevent->context);
$newdate = usergetdate($daytimestamp);
$startdatestring = implode('-', [$newdate['year'], $newdate['mon'], $newdate['mday']]);
$startdate = new DateTimeImmutable($startdatestring);
$event = local_api::update_event_start_day($event, $startdate);
$cache = new events_related_objects_cache([$event]);
$relatedobjects = [
'context' => $cache->get_context($event),
'course' => $cache->get_course($event),
];
$exporter = new event_exporter($event, $relatedobjects);
$renderer = $PAGE->get_renderer('core_calendar');
return array('event' => $exporter->export($renderer));
} | php | public static function update_event_start_day($eventid, $daytimestamp) {
global $USER, $PAGE;
// Parameter validation.
$params = self::validate_parameters(self::update_event_start_day_parameters(), [
'eventid' => $eventid,
'daytimestamp' => $daytimestamp,
]);
$vault = event_container::get_event_vault();
$mapper = event_container::get_event_mapper();
$event = $vault->get_event_by_id($eventid);
if (!$event) {
throw new \moodle_exception('Unable to find event with id ' . $eventid);
}
$legacyevent = $mapper->from_event_to_legacy_event($event);
if (!calendar_edit_event_allowed($legacyevent, true)) {
print_error('nopermissiontoupdatecalendar');
}
self::validate_context($legacyevent->context);
$newdate = usergetdate($daytimestamp);
$startdatestring = implode('-', [$newdate['year'], $newdate['mon'], $newdate['mday']]);
$startdate = new DateTimeImmutable($startdatestring);
$event = local_api::update_event_start_day($event, $startdate);
$cache = new events_related_objects_cache([$event]);
$relatedobjects = [
'context' => $cache->get_context($event),
'course' => $cache->get_course($event),
];
$exporter = new event_exporter($event, $relatedobjects);
$renderer = $PAGE->get_renderer('core_calendar');
return array('event' => $exporter->export($renderer));
} | [
"public",
"static",
"function",
"update_event_start_day",
"(",
"$",
"eventid",
",",
"$",
"daytimestamp",
")",
"{",
"global",
"$",
"USER",
",",
"$",
"PAGE",
";",
"// Parameter validation.",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"update_event_start_day_parameters",
"(",
")",
",",
"[",
"'eventid'",
"=>",
"$",
"eventid",
",",
"'daytimestamp'",
"=>",
"$",
"daytimestamp",
",",
"]",
")",
";",
"$",
"vault",
"=",
"event_container",
"::",
"get_event_vault",
"(",
")",
";",
"$",
"mapper",
"=",
"event_container",
"::",
"get_event_mapper",
"(",
")",
";",
"$",
"event",
"=",
"$",
"vault",
"->",
"get_event_by_id",
"(",
"$",
"eventid",
")",
";",
"if",
"(",
"!",
"$",
"event",
")",
"{",
"throw",
"new",
"\\",
"moodle_exception",
"(",
"'Unable to find event with id '",
".",
"$",
"eventid",
")",
";",
"}",
"$",
"legacyevent",
"=",
"$",
"mapper",
"->",
"from_event_to_legacy_event",
"(",
"$",
"event",
")",
";",
"if",
"(",
"!",
"calendar_edit_event_allowed",
"(",
"$",
"legacyevent",
",",
"true",
")",
")",
"{",
"print_error",
"(",
"'nopermissiontoupdatecalendar'",
")",
";",
"}",
"self",
"::",
"validate_context",
"(",
"$",
"legacyevent",
"->",
"context",
")",
";",
"$",
"newdate",
"=",
"usergetdate",
"(",
"$",
"daytimestamp",
")",
";",
"$",
"startdatestring",
"=",
"implode",
"(",
"'-'",
",",
"[",
"$",
"newdate",
"[",
"'year'",
"]",
",",
"$",
"newdate",
"[",
"'mon'",
"]",
",",
"$",
"newdate",
"[",
"'mday'",
"]",
"]",
")",
";",
"$",
"startdate",
"=",
"new",
"DateTimeImmutable",
"(",
"$",
"startdatestring",
")",
";",
"$",
"event",
"=",
"local_api",
"::",
"update_event_start_day",
"(",
"$",
"event",
",",
"$",
"startdate",
")",
";",
"$",
"cache",
"=",
"new",
"events_related_objects_cache",
"(",
"[",
"$",
"event",
"]",
")",
";",
"$",
"relatedobjects",
"=",
"[",
"'context'",
"=>",
"$",
"cache",
"->",
"get_context",
"(",
"$",
"event",
")",
",",
"'course'",
"=>",
"$",
"cache",
"->",
"get_course",
"(",
"$",
"event",
")",
",",
"]",
";",
"$",
"exporter",
"=",
"new",
"event_exporter",
"(",
"$",
"event",
",",
"$",
"relatedobjects",
")",
";",
"$",
"renderer",
"=",
"$",
"PAGE",
"->",
"get_renderer",
"(",
"'core_calendar'",
")",
";",
"return",
"array",
"(",
"'event'",
"=>",
"$",
"exporter",
"->",
"export",
"(",
"$",
"renderer",
")",
")",
";",
"}"
] | Change the start day for the given calendar event to the day that
corresponds with the provided timestamp.
The timestamp only needs to be anytime within the desired day as only
the date data is extracted from it.
The event's original time of day is maintained, only the date is shifted.
@param int $eventid Id of event to be updated
@param int $daytimestamp Timestamp for the new start day
@return array | [
"Change",
"the",
"start",
"day",
"for",
"the",
"given",
"calendar",
"event",
"to",
"the",
"day",
"that",
"corresponds",
"with",
"the",
"provided",
"timestamp",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/externallib.php#L1144-L1182 |
214,059 | moodle/moodle | calendar/externallib.php | core_calendar_external.get_calendar_access_information | public static function get_calendar_access_information($courseid = 0) {
$params = self::validate_parameters(self::get_calendar_access_information_parameters(), ['courseid' => $courseid]);
if (empty($params['courseid']) || $params['courseid'] == SITEID) {
$context = \context_system::instance();
} else {
$context = \context_course::instance($params['courseid']);
}
self::validate_context($context);
return [
'canmanageentries' => has_capability('moodle/calendar:manageentries', $context),
'canmanageownentries' => has_capability('moodle/calendar:manageownentries', $context),
'canmanagegroupentries' => has_capability('moodle/calendar:managegroupentries', $context),
'warnings' => [],
];
} | php | public static function get_calendar_access_information($courseid = 0) {
$params = self::validate_parameters(self::get_calendar_access_information_parameters(), ['courseid' => $courseid]);
if (empty($params['courseid']) || $params['courseid'] == SITEID) {
$context = \context_system::instance();
} else {
$context = \context_course::instance($params['courseid']);
}
self::validate_context($context);
return [
'canmanageentries' => has_capability('moodle/calendar:manageentries', $context),
'canmanageownentries' => has_capability('moodle/calendar:manageownentries', $context),
'canmanagegroupentries' => has_capability('moodle/calendar:managegroupentries', $context),
'warnings' => [],
];
} | [
"public",
"static",
"function",
"get_calendar_access_information",
"(",
"$",
"courseid",
"=",
"0",
")",
"{",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_calendar_access_information_parameters",
"(",
")",
",",
"[",
"'courseid'",
"=>",
"$",
"courseid",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"params",
"[",
"'courseid'",
"]",
")",
"||",
"$",
"params",
"[",
"'courseid'",
"]",
"==",
"SITEID",
")",
"{",
"$",
"context",
"=",
"\\",
"context_system",
"::",
"instance",
"(",
")",
";",
"}",
"else",
"{",
"$",
"context",
"=",
"\\",
"context_course",
"::",
"instance",
"(",
"$",
"params",
"[",
"'courseid'",
"]",
")",
";",
"}",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"return",
"[",
"'canmanageentries'",
"=>",
"has_capability",
"(",
"'moodle/calendar:manageentries'",
",",
"$",
"context",
")",
",",
"'canmanageownentries'",
"=>",
"has_capability",
"(",
"'moodle/calendar:manageownentries'",
",",
"$",
"context",
")",
",",
"'canmanagegroupentries'",
"=>",
"has_capability",
"(",
"'moodle/calendar:managegroupentries'",
",",
"$",
"context",
")",
",",
"'warnings'",
"=>",
"[",
"]",
",",
"]",
";",
"}"
] | Convenience function to retrieve some permissions information for the given course calendar.
@param int $courseid Course to check, empty for site.
@return array The access information
@throws moodle_exception
@since Moodle 3.7 | [
"Convenience",
"function",
"to",
"retrieve",
"some",
"permissions",
"information",
"for",
"the",
"given",
"course",
"calendar",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/externallib.php#L1271-L1289 |
214,060 | moodle/moodle | calendar/externallib.php | core_calendar_external.get_allowed_event_types | public static function get_allowed_event_types($courseid = 0) {
$params = self::validate_parameters(self::get_allowed_event_types_parameters(), ['courseid' => $courseid]);
if (empty($params['courseid']) || $params['courseid'] == SITEID) {
$context = \context_system::instance();
} else {
$context = \context_course::instance($params['courseid']);
}
self::validate_context($context);
$allowedeventtypes = array_filter(calendar_get_allowed_event_types($params['courseid']));
return [
'allowedeventtypes' => array_keys($allowedeventtypes),
'warnings' => [],
];
} | php | public static function get_allowed_event_types($courseid = 0) {
$params = self::validate_parameters(self::get_allowed_event_types_parameters(), ['courseid' => $courseid]);
if (empty($params['courseid']) || $params['courseid'] == SITEID) {
$context = \context_system::instance();
} else {
$context = \context_course::instance($params['courseid']);
}
self::validate_context($context);
$allowedeventtypes = array_filter(calendar_get_allowed_event_types($params['courseid']));
return [
'allowedeventtypes' => array_keys($allowedeventtypes),
'warnings' => [],
];
} | [
"public",
"static",
"function",
"get_allowed_event_types",
"(",
"$",
"courseid",
"=",
"0",
")",
"{",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_allowed_event_types_parameters",
"(",
")",
",",
"[",
"'courseid'",
"=>",
"$",
"courseid",
"]",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"params",
"[",
"'courseid'",
"]",
")",
"||",
"$",
"params",
"[",
"'courseid'",
"]",
"==",
"SITEID",
")",
"{",
"$",
"context",
"=",
"\\",
"context_system",
"::",
"instance",
"(",
")",
";",
"}",
"else",
"{",
"$",
"context",
"=",
"\\",
"context_course",
"::",
"instance",
"(",
"$",
"params",
"[",
"'courseid'",
"]",
")",
";",
"}",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"$",
"allowedeventtypes",
"=",
"array_filter",
"(",
"calendar_get_allowed_event_types",
"(",
"$",
"params",
"[",
"'courseid'",
"]",
")",
")",
";",
"return",
"[",
"'allowedeventtypes'",
"=>",
"array_keys",
"(",
"$",
"allowedeventtypes",
")",
",",
"'warnings'",
"=>",
"[",
"]",
",",
"]",
";",
"}"
] | Get the type of events a user can create in the given course.
@param int $courseid Course to check, empty for site.
@return array The types allowed
@throws moodle_exception
@since Moodle 3.7 | [
"Get",
"the",
"type",
"of",
"events",
"a",
"user",
"can",
"create",
"in",
"the",
"given",
"course",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/externallib.php#L1331-L1349 |
214,061 | moodle/moodle | mod/assign/feedback/editpdf/classes/comments_quick_list.php | comments_quick_list.get_comments | public static function get_comments() {
global $DB, $USER;
$comments = array();
$records = $DB->get_records('assignfeedback_editpdf_quick', array('userid'=>$USER->id));
return $records;
} | php | public static function get_comments() {
global $DB, $USER;
$comments = array();
$records = $DB->get_records('assignfeedback_editpdf_quick', array('userid'=>$USER->id));
return $records;
} | [
"public",
"static",
"function",
"get_comments",
"(",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"USER",
";",
"$",
"comments",
"=",
"array",
"(",
")",
";",
"$",
"records",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'assignfeedback_editpdf_quick'",
",",
"array",
"(",
"'userid'",
"=>",
"$",
"USER",
"->",
"id",
")",
")",
";",
"return",
"$",
"records",
";",
"}"
] | Get all comments for the current user.
@return array(comment) | [
"Get",
"all",
"comments",
"for",
"the",
"current",
"user",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/comments_quick_list.php#L41-L48 |
214,062 | moodle/moodle | mod/assign/feedback/editpdf/classes/comments_quick_list.php | comments_quick_list.add_comment | public static function add_comment($commenttext, $width, $colour) {
global $DB, $USER;
$comment = new \stdClass();
$comment->userid = $USER->id;
$comment->rawtext = $commenttext;
$comment->width = $width;
$comment->colour = $colour;
$comment->id = $DB->insert_record('assignfeedback_editpdf_quick', $comment);
return $comment;
} | php | public static function add_comment($commenttext, $width, $colour) {
global $DB, $USER;
$comment = new \stdClass();
$comment->userid = $USER->id;
$comment->rawtext = $commenttext;
$comment->width = $width;
$comment->colour = $colour;
$comment->id = $DB->insert_record('assignfeedback_editpdf_quick', $comment);
return $comment;
} | [
"public",
"static",
"function",
"add_comment",
"(",
"$",
"commenttext",
",",
"$",
"width",
",",
"$",
"colour",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"USER",
";",
"$",
"comment",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"comment",
"->",
"userid",
"=",
"$",
"USER",
"->",
"id",
";",
"$",
"comment",
"->",
"rawtext",
"=",
"$",
"commenttext",
";",
"$",
"comment",
"->",
"width",
"=",
"$",
"width",
";",
"$",
"comment",
"->",
"colour",
"=",
"$",
"colour",
";",
"$",
"comment",
"->",
"id",
"=",
"$",
"DB",
"->",
"insert_record",
"(",
"'assignfeedback_editpdf_quick'",
",",
"$",
"comment",
")",
";",
"return",
"$",
"comment",
";",
"}"
] | Add a comment to the quick list.
@param string $commenttext
@param int $width
@param string $colour
@return stdClass - the comment record (with new id set) | [
"Add",
"a",
"comment",
"to",
"the",
"quick",
"list",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/editpdf/classes/comments_quick_list.php#L57-L68 |
214,063 | moodle/moodle | lib/horde/framework/Horde/Imap/Client/Base/Mailbox.php | Horde_Imap_Client_Base_Mailbox.getStatus | public function getStatus($entry)
{
if (isset($this->_status[$entry])) {
return $this->_status[$entry];
}
switch ($entry) {
case Horde_Imap_Client::STATUS_FLAGS:
case Horde_Imap_Client::STATUS_SYNCFLAGUIDS:
case Horde_Imap_Client::STATUS_SYNCVANISHED:
return array();
case Horde_Imap_Client::STATUS_FIRSTUNSEEN:
/* If we know there are no messages in the current mailbox, we
* know there are no unseen messages. */
return empty($this->_status[Horde_Imap_Client::STATUS_MESSAGES])
? false
: null;
case Horde_Imap_Client::STATUS_RECENT_TOTAL:
case Horde_Imap_Client::STATUS_SYNCMODSEQ:
return 0;
case Horde_Imap_Client::STATUS_PERMFLAGS:
/* If PERMFLAGS is not returned by server, must assume that all
* flags can be changed permanently (RFC 3501 [6.3.1]). */
$flags = isset($this->_status[Horde_Imap_Client::STATUS_FLAGS])
? $this->_status[Horde_Imap_Client::STATUS_FLAGS]
: array();
$flags[] = "\\*";
return $flags;
case Horde_Imap_Client::STATUS_UIDNOTSTICKY:
/* In the absence of explicit uidnotsticky identification, assume
* that UIDs are sticky. */
return false;
case Horde_Imap_Client::STATUS_UNSEEN:
/* If we know there are no messages in the current mailbox, we
* know there are no unseen messages . */
return empty($this->_status[Horde_Imap_Client::STATUS_MESSAGES])
? 0
: null;
default:
return null;
}
} | php | public function getStatus($entry)
{
if (isset($this->_status[$entry])) {
return $this->_status[$entry];
}
switch ($entry) {
case Horde_Imap_Client::STATUS_FLAGS:
case Horde_Imap_Client::STATUS_SYNCFLAGUIDS:
case Horde_Imap_Client::STATUS_SYNCVANISHED:
return array();
case Horde_Imap_Client::STATUS_FIRSTUNSEEN:
/* If we know there are no messages in the current mailbox, we
* know there are no unseen messages. */
return empty($this->_status[Horde_Imap_Client::STATUS_MESSAGES])
? false
: null;
case Horde_Imap_Client::STATUS_RECENT_TOTAL:
case Horde_Imap_Client::STATUS_SYNCMODSEQ:
return 0;
case Horde_Imap_Client::STATUS_PERMFLAGS:
/* If PERMFLAGS is not returned by server, must assume that all
* flags can be changed permanently (RFC 3501 [6.3.1]). */
$flags = isset($this->_status[Horde_Imap_Client::STATUS_FLAGS])
? $this->_status[Horde_Imap_Client::STATUS_FLAGS]
: array();
$flags[] = "\\*";
return $flags;
case Horde_Imap_Client::STATUS_UIDNOTSTICKY:
/* In the absence of explicit uidnotsticky identification, assume
* that UIDs are sticky. */
return false;
case Horde_Imap_Client::STATUS_UNSEEN:
/* If we know there are no messages in the current mailbox, we
* know there are no unseen messages . */
return empty($this->_status[Horde_Imap_Client::STATUS_MESSAGES])
? 0
: null;
default:
return null;
}
} | [
"public",
"function",
"getStatus",
"(",
"$",
"entry",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_status",
"[",
"$",
"entry",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_status",
"[",
"$",
"entry",
"]",
";",
"}",
"switch",
"(",
"$",
"entry",
")",
"{",
"case",
"Horde_Imap_Client",
"::",
"STATUS_FLAGS",
":",
"case",
"Horde_Imap_Client",
"::",
"STATUS_SYNCFLAGUIDS",
":",
"case",
"Horde_Imap_Client",
"::",
"STATUS_SYNCVANISHED",
":",
"return",
"array",
"(",
")",
";",
"case",
"Horde_Imap_Client",
"::",
"STATUS_FIRSTUNSEEN",
":",
"/* If we know there are no messages in the current mailbox, we\n * know there are no unseen messages. */",
"return",
"empty",
"(",
"$",
"this",
"->",
"_status",
"[",
"Horde_Imap_Client",
"::",
"STATUS_MESSAGES",
"]",
")",
"?",
"false",
":",
"null",
";",
"case",
"Horde_Imap_Client",
"::",
"STATUS_RECENT_TOTAL",
":",
"case",
"Horde_Imap_Client",
"::",
"STATUS_SYNCMODSEQ",
":",
"return",
"0",
";",
"case",
"Horde_Imap_Client",
"::",
"STATUS_PERMFLAGS",
":",
"/* If PERMFLAGS is not returned by server, must assume that all\n * flags can be changed permanently (RFC 3501 [6.3.1]). */",
"$",
"flags",
"=",
"isset",
"(",
"$",
"this",
"->",
"_status",
"[",
"Horde_Imap_Client",
"::",
"STATUS_FLAGS",
"]",
")",
"?",
"$",
"this",
"->",
"_status",
"[",
"Horde_Imap_Client",
"::",
"STATUS_FLAGS",
"]",
":",
"array",
"(",
")",
";",
"$",
"flags",
"[",
"]",
"=",
"\"\\\\*\"",
";",
"return",
"$",
"flags",
";",
"case",
"Horde_Imap_Client",
"::",
"STATUS_UIDNOTSTICKY",
":",
"/* In the absence of explicit uidnotsticky identification, assume\n * that UIDs are sticky. */",
"return",
"false",
";",
"case",
"Horde_Imap_Client",
"::",
"STATUS_UNSEEN",
":",
"/* If we know there are no messages in the current mailbox, we\n * know there are no unseen messages . */",
"return",
"empty",
"(",
"$",
"this",
"->",
"_status",
"[",
"Horde_Imap_Client",
"::",
"STATUS_MESSAGES",
"]",
")",
"?",
"0",
":",
"null",
";",
"default",
":",
"return",
"null",
";",
"}",
"}"
] | Get status information for the mailbox.
@param integer $entry STATUS_* constant.
@return mixed Status information. | [
"Get",
"status",
"information",
"for",
"the",
"mailbox",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Base/Mailbox.php#L74-L121 |
214,064 | moodle/moodle | lib/horde/framework/Horde/Imap/Client/Base/Mailbox.php | Horde_Imap_Client_Base_Mailbox.setStatus | public function setStatus($entry, $value)
{
switch ($entry) {
case Horde_Imap_Client::STATUS_FIRSTUNSEEN:
case Horde_Imap_Client::STATUS_HIGHESTMODSEQ:
case Horde_Imap_Client::STATUS_MESSAGES:
case Horde_Imap_Client::STATUS_UNSEEN:
case Horde_Imap_Client::STATUS_UIDNEXT:
case Horde_Imap_Client::STATUS_UIDVALIDITY:
$value = intval($value);
break;
case Horde_Imap_Client::STATUS_RECENT:
/* Keep track of RECENT_TOTAL information. */
$this->_status[Horde_Imap_Client::STATUS_RECENT_TOTAL] = isset($this->_status[Horde_Imap_Client::STATUS_RECENT_TOTAL])
? ($this->_status[Horde_Imap_Client::STATUS_RECENT_TOTAL] + $value)
: intval($value);
break;
case Horde_Imap_Client::STATUS_SYNCMODSEQ:
/* This is only set once per access. */
if (isset($this->_status[$entry])) {
return;
}
$value = intval($value);
break;
case Horde_Imap_Client::STATUS_SYNCFLAGUIDS:
case Horde_Imap_Client::STATUS_SYNCVANISHED:
if (!isset($this->_status[$entry])) {
$this->_status[$entry] = array();
}
$this->_status[$entry] = array_merge($this->_status[$entry], $value);
return;
}
$this->_status[$entry] = $value;
} | php | public function setStatus($entry, $value)
{
switch ($entry) {
case Horde_Imap_Client::STATUS_FIRSTUNSEEN:
case Horde_Imap_Client::STATUS_HIGHESTMODSEQ:
case Horde_Imap_Client::STATUS_MESSAGES:
case Horde_Imap_Client::STATUS_UNSEEN:
case Horde_Imap_Client::STATUS_UIDNEXT:
case Horde_Imap_Client::STATUS_UIDVALIDITY:
$value = intval($value);
break;
case Horde_Imap_Client::STATUS_RECENT:
/* Keep track of RECENT_TOTAL information. */
$this->_status[Horde_Imap_Client::STATUS_RECENT_TOTAL] = isset($this->_status[Horde_Imap_Client::STATUS_RECENT_TOTAL])
? ($this->_status[Horde_Imap_Client::STATUS_RECENT_TOTAL] + $value)
: intval($value);
break;
case Horde_Imap_Client::STATUS_SYNCMODSEQ:
/* This is only set once per access. */
if (isset($this->_status[$entry])) {
return;
}
$value = intval($value);
break;
case Horde_Imap_Client::STATUS_SYNCFLAGUIDS:
case Horde_Imap_Client::STATUS_SYNCVANISHED:
if (!isset($this->_status[$entry])) {
$this->_status[$entry] = array();
}
$this->_status[$entry] = array_merge($this->_status[$entry], $value);
return;
}
$this->_status[$entry] = $value;
} | [
"public",
"function",
"setStatus",
"(",
"$",
"entry",
",",
"$",
"value",
")",
"{",
"switch",
"(",
"$",
"entry",
")",
"{",
"case",
"Horde_Imap_Client",
"::",
"STATUS_FIRSTUNSEEN",
":",
"case",
"Horde_Imap_Client",
"::",
"STATUS_HIGHESTMODSEQ",
":",
"case",
"Horde_Imap_Client",
"::",
"STATUS_MESSAGES",
":",
"case",
"Horde_Imap_Client",
"::",
"STATUS_UNSEEN",
":",
"case",
"Horde_Imap_Client",
"::",
"STATUS_UIDNEXT",
":",
"case",
"Horde_Imap_Client",
"::",
"STATUS_UIDVALIDITY",
":",
"$",
"value",
"=",
"intval",
"(",
"$",
"value",
")",
";",
"break",
";",
"case",
"Horde_Imap_Client",
"::",
"STATUS_RECENT",
":",
"/* Keep track of RECENT_TOTAL information. */",
"$",
"this",
"->",
"_status",
"[",
"Horde_Imap_Client",
"::",
"STATUS_RECENT_TOTAL",
"]",
"=",
"isset",
"(",
"$",
"this",
"->",
"_status",
"[",
"Horde_Imap_Client",
"::",
"STATUS_RECENT_TOTAL",
"]",
")",
"?",
"(",
"$",
"this",
"->",
"_status",
"[",
"Horde_Imap_Client",
"::",
"STATUS_RECENT_TOTAL",
"]",
"+",
"$",
"value",
")",
":",
"intval",
"(",
"$",
"value",
")",
";",
"break",
";",
"case",
"Horde_Imap_Client",
"::",
"STATUS_SYNCMODSEQ",
":",
"/* This is only set once per access. */",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_status",
"[",
"$",
"entry",
"]",
")",
")",
"{",
"return",
";",
"}",
"$",
"value",
"=",
"intval",
"(",
"$",
"value",
")",
";",
"break",
";",
"case",
"Horde_Imap_Client",
"::",
"STATUS_SYNCFLAGUIDS",
":",
"case",
"Horde_Imap_Client",
"::",
"STATUS_SYNCVANISHED",
":",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_status",
"[",
"$",
"entry",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_status",
"[",
"$",
"entry",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"this",
"->",
"_status",
"[",
"$",
"entry",
"]",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"_status",
"[",
"$",
"entry",
"]",
",",
"$",
"value",
")",
";",
"return",
";",
"}",
"$",
"this",
"->",
"_status",
"[",
"$",
"entry",
"]",
"=",
"$",
"value",
";",
"}"
] | Set status information for the mailbox.
@param integer $entry STATUS_* constant.
@param mixed $value Status information. | [
"Set",
"status",
"information",
"for",
"the",
"mailbox",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Base/Mailbox.php#L129-L166 |
214,065 | moodle/moodle | lib/horde/framework/Horde/Imap/Client/Base/Mailbox.php | Horde_Imap_Client_Base_Mailbox.reset | public function reset()
{
$keep = array(
Horde_Imap_Client::STATUS_SYNCFLAGUIDS,
Horde_Imap_Client::STATUS_SYNCMODSEQ,
Horde_Imap_Client::STATUS_SYNCVANISHED
);
foreach (array_diff(array_keys($this->_status), $keep) as $val) {
unset($this->_status[$val]);
}
$this->map = new Horde_Imap_Client_Ids_Map();
$this->open = $this->sync = false;
} | php | public function reset()
{
$keep = array(
Horde_Imap_Client::STATUS_SYNCFLAGUIDS,
Horde_Imap_Client::STATUS_SYNCMODSEQ,
Horde_Imap_Client::STATUS_SYNCVANISHED
);
foreach (array_diff(array_keys($this->_status), $keep) as $val) {
unset($this->_status[$val]);
}
$this->map = new Horde_Imap_Client_Ids_Map();
$this->open = $this->sync = false;
} | [
"public",
"function",
"reset",
"(",
")",
"{",
"$",
"keep",
"=",
"array",
"(",
"Horde_Imap_Client",
"::",
"STATUS_SYNCFLAGUIDS",
",",
"Horde_Imap_Client",
"::",
"STATUS_SYNCMODSEQ",
",",
"Horde_Imap_Client",
"::",
"STATUS_SYNCVANISHED",
")",
";",
"foreach",
"(",
"array_diff",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"_status",
")",
",",
"$",
"keep",
")",
"as",
"$",
"val",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"_status",
"[",
"$",
"val",
"]",
")",
";",
"}",
"$",
"this",
"->",
"map",
"=",
"new",
"Horde_Imap_Client_Ids_Map",
"(",
")",
";",
"$",
"this",
"->",
"open",
"=",
"$",
"this",
"->",
"sync",
"=",
"false",
";",
"}"
] | Reset the mailbox information. | [
"Reset",
"the",
"mailbox",
"information",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Base/Mailbox.php#L171-L185 |
214,066 | moodle/moodle | lib/ltiprovider/src/ToolProvider/User.php | User.getResourceLink | public function getResourceLink()
{
if (is_null($this->resourceLink) && !is_null($this->resourceLinkId)) {
$this->resourceLink = ResourceLink::fromRecordId($this->resourceLinkId, $this->getDataConnector());
}
return $this->resourceLink;
} | php | public function getResourceLink()
{
if (is_null($this->resourceLink) && !is_null($this->resourceLinkId)) {
$this->resourceLink = ResourceLink::fromRecordId($this->resourceLinkId, $this->getDataConnector());
}
return $this->resourceLink;
} | [
"public",
"function",
"getResourceLink",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"resourceLink",
")",
"&&",
"!",
"is_null",
"(",
"$",
"this",
"->",
"resourceLinkId",
")",
")",
"{",
"$",
"this",
"->",
"resourceLink",
"=",
"ResourceLink",
"::",
"fromRecordId",
"(",
"$",
"this",
"->",
"resourceLinkId",
",",
"$",
"this",
"->",
"getDataConnector",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"resourceLink",
";",
"}"
] | Get resource link.
@return ResourceLink Resource link object | [
"Get",
"resource",
"link",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ltiprovider/src/ToolProvider/User.php#L188-L197 |
214,067 | moodle/moodle | lib/ltiprovider/src/ToolProvider/User.php | User.fromResourceLink | public static function fromResourceLink($resourceLink, $ltiUserId)
{
$user = new User();
$user->resourceLink = $resourceLink;
if (!is_null($resourceLink)) {
$user->resourceLinkId = $resourceLink->getRecordId();
$user->dataConnector = $resourceLink->getDataConnector();
}
$user->ltiUserId = $ltiUserId;
if (!empty($ltiUserId)) {
$user->load();
}
return $user;
} | php | public static function fromResourceLink($resourceLink, $ltiUserId)
{
$user = new User();
$user->resourceLink = $resourceLink;
if (!is_null($resourceLink)) {
$user->resourceLinkId = $resourceLink->getRecordId();
$user->dataConnector = $resourceLink->getDataConnector();
}
$user->ltiUserId = $ltiUserId;
if (!empty($ltiUserId)) {
$user->load();
}
return $user;
} | [
"public",
"static",
"function",
"fromResourceLink",
"(",
"$",
"resourceLink",
",",
"$",
"ltiUserId",
")",
"{",
"$",
"user",
"=",
"new",
"User",
"(",
")",
";",
"$",
"user",
"->",
"resourceLink",
"=",
"$",
"resourceLink",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"resourceLink",
")",
")",
"{",
"$",
"user",
"->",
"resourceLinkId",
"=",
"$",
"resourceLink",
"->",
"getRecordId",
"(",
")",
";",
"$",
"user",
"->",
"dataConnector",
"=",
"$",
"resourceLink",
"->",
"getDataConnector",
"(",
")",
";",
"}",
"$",
"user",
"->",
"ltiUserId",
"=",
"$",
"ltiUserId",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"ltiUserId",
")",
")",
"{",
"$",
"user",
"->",
"load",
"(",
")",
";",
"}",
"return",
"$",
"user",
";",
"}"
] | Class constructor from resource link.
@param ResourceLink $resourceLink Resource_Link object
@param string $ltiUserId User ID value
@return User | [
"Class",
"constructor",
"from",
"resource",
"link",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ltiprovider/src/ToolProvider/User.php#L413-L429 |
214,068 | moodle/moodle | lib/ltiprovider/src/ToolProvider/User.php | User.hasRole | private function hasRole($role) {
if (substr($role, 0, 4) !== 'urn:')
{
$role = 'urn:lti:role:ims/lis/' . $role;
}
return in_array($role, $this->roles);
} | php | private function hasRole($role) {
if (substr($role, 0, 4) !== 'urn:')
{
$role = 'urn:lti:role:ims/lis/' . $role;
}
return in_array($role, $this->roles);
} | [
"private",
"function",
"hasRole",
"(",
"$",
"role",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"role",
",",
"0",
",",
"4",
")",
"!==",
"'urn:'",
")",
"{",
"$",
"role",
"=",
"'urn:lti:role:ims/lis/'",
".",
"$",
"role",
";",
"}",
"return",
"in_array",
"(",
"$",
"role",
",",
"$",
"this",
"->",
"roles",
")",
";",
"}"
] | Check whether the user has a specified role name.
@param string $role Name of role
@return boolean True if the user has the specified role | [
"Check",
"whether",
"the",
"user",
"has",
"a",
"specified",
"role",
"name",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/ltiprovider/src/ToolProvider/User.php#L442-L451 |
214,069 | moodle/moodle | lib/horde/framework/Horde/Support/ConsistentHash.php | Horde_Support_ConsistentHash.addNodes | public function addNodes($nodes, $weight = 1)
{
foreach ($nodes as $node) {
$this->_nodes[] = array('n' => $node, 'w' => $weight);
$this->_nodeCount++;
$nodeIndex = $this->_nodeCount - 1;
$nodeString = serialize($node);
$numberOfReplicas = (int)($weight * $this->_numberOfReplicas);
for ($i = 0; $i < $numberOfReplicas; $i++) {
$this->_circle[$this->hash($nodeString . $i)] = $nodeIndex;
}
}
$this->_updateCircle();
} | php | public function addNodes($nodes, $weight = 1)
{
foreach ($nodes as $node) {
$this->_nodes[] = array('n' => $node, 'w' => $weight);
$this->_nodeCount++;
$nodeIndex = $this->_nodeCount - 1;
$nodeString = serialize($node);
$numberOfReplicas = (int)($weight * $this->_numberOfReplicas);
for ($i = 0; $i < $numberOfReplicas; $i++) {
$this->_circle[$this->hash($nodeString . $i)] = $nodeIndex;
}
}
$this->_updateCircle();
} | [
"public",
"function",
"addNodes",
"(",
"$",
"nodes",
",",
"$",
"weight",
"=",
"1",
")",
"{",
"foreach",
"(",
"$",
"nodes",
"as",
"$",
"node",
")",
"{",
"$",
"this",
"->",
"_nodes",
"[",
"]",
"=",
"array",
"(",
"'n'",
"=>",
"$",
"node",
",",
"'w'",
"=>",
"$",
"weight",
")",
";",
"$",
"this",
"->",
"_nodeCount",
"++",
";",
"$",
"nodeIndex",
"=",
"$",
"this",
"->",
"_nodeCount",
"-",
"1",
";",
"$",
"nodeString",
"=",
"serialize",
"(",
"$",
"node",
")",
";",
"$",
"numberOfReplicas",
"=",
"(",
"int",
")",
"(",
"$",
"weight",
"*",
"$",
"this",
"->",
"_numberOfReplicas",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"numberOfReplicas",
";",
"$",
"i",
"++",
")",
"{",
"$",
"this",
"->",
"_circle",
"[",
"$",
"this",
"->",
"hash",
"(",
"$",
"nodeString",
".",
"$",
"i",
")",
"]",
"=",
"$",
"nodeIndex",
";",
"}",
"}",
"$",
"this",
"->",
"_updateCircle",
"(",
")",
";",
"}"
] | Add multiple nodes to the hash with the same weight.
@param array $nodes An array of nodes.
@param integer $weight The weight to add the nodes with. | [
"Add",
"multiple",
"nodes",
"to",
"the",
"hash",
"with",
"the",
"same",
"weight",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Support/ConsistentHash.php#L166-L182 |
214,070 | moodle/moodle | lib/horde/framework/Horde/Support/ConsistentHash.php | Horde_Support_ConsistentHash._updateCircle | protected function _updateCircle()
{
// Sort the circle
ksort($this->_circle);
// Now that the hashes are sorted, generate numeric indices into the
// circle.
$this->_pointMap = array_keys($this->_circle);
$this->_pointCount = count($this->_pointMap);
} | php | protected function _updateCircle()
{
// Sort the circle
ksort($this->_circle);
// Now that the hashes are sorted, generate numeric indices into the
// circle.
$this->_pointMap = array_keys($this->_circle);
$this->_pointCount = count($this->_pointMap);
} | [
"protected",
"function",
"_updateCircle",
"(",
")",
"{",
"// Sort the circle",
"ksort",
"(",
"$",
"this",
"->",
"_circle",
")",
";",
"// Now that the hashes are sorted, generate numeric indices into the",
"// circle.",
"$",
"this",
"->",
"_pointMap",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"_circle",
")",
";",
"$",
"this",
"->",
"_pointCount",
"=",
"count",
"(",
"$",
"this",
"->",
"_pointMap",
")",
";",
"}"
] | Maintain the circle and arrays of points. | [
"Maintain",
"the",
"circle",
"and",
"arrays",
"of",
"points",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Support/ConsistentHash.php#L233-L242 |
214,071 | moodle/moodle | blocks/tag_youtube/block_tag_youtube.php | block_tag_youtube.fetch_request | public function fetch_request($request) {
throw new coding_exception('Sorry, this function has been deprecated in Moodle 2.8.8, 2.9.2 and 3.0. Use block_tag_youtube::get_service instead.');
$c = new curl(array('cache' => true, 'module_cache'=>'tag_youtube'));
$c->setopt(array('CURLOPT_TIMEOUT' => 3, 'CURLOPT_CONNECTTIMEOUT' => 3));
$response = $c->get($request);
$xml = new SimpleXMLElement($response);
return $this->render_video_list($xml);
} | php | public function fetch_request($request) {
throw new coding_exception('Sorry, this function has been deprecated in Moodle 2.8.8, 2.9.2 and 3.0. Use block_tag_youtube::get_service instead.');
$c = new curl(array('cache' => true, 'module_cache'=>'tag_youtube'));
$c->setopt(array('CURLOPT_TIMEOUT' => 3, 'CURLOPT_CONNECTTIMEOUT' => 3));
$response = $c->get($request);
$xml = new SimpleXMLElement($response);
return $this->render_video_list($xml);
} | [
"public",
"function",
"fetch_request",
"(",
"$",
"request",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Sorry, this function has been deprecated in Moodle 2.8.8, 2.9.2 and 3.0. Use block_tag_youtube::get_service instead.'",
")",
";",
"$",
"c",
"=",
"new",
"curl",
"(",
"array",
"(",
"'cache'",
"=>",
"true",
",",
"'module_cache'",
"=>",
"'tag_youtube'",
")",
")",
";",
"$",
"c",
"->",
"setopt",
"(",
"array",
"(",
"'CURLOPT_TIMEOUT'",
"=>",
"3",
",",
"'CURLOPT_CONNECTTIMEOUT'",
"=>",
"3",
")",
")",
";",
"$",
"response",
"=",
"$",
"c",
"->",
"get",
"(",
"$",
"request",
")",
";",
"$",
"xml",
"=",
"new",
"SimpleXMLElement",
"(",
"$",
"response",
")",
";",
"return",
"$",
"this",
"->",
"render_video_list",
"(",
"$",
"xml",
")",
";",
"}"
] | Sends a request to fetch data.
@see block_tag_youtube::service
@deprecated since Moodle 2.8.8, 2.9.2 and 3.0 MDL-49085 - please do not use this function any more.
@param string $request
@throws coding_exception | [
"Sends",
"a",
"request",
"to",
"fetch",
"data",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/tag_youtube/block_tag_youtube.php#L217-L227 |
214,072 | moodle/moodle | blocks/tag_youtube/block_tag_youtube.php | block_tag_youtube.get_error_message | protected function get_error_message($message = null) {
global $OUTPUT;
if (empty($message)) {
$message = get_string('apierror', 'block_tag_youtube');
}
return $OUTPUT->notification($message);
} | php | protected function get_error_message($message = null) {
global $OUTPUT;
if (empty($message)) {
$message = get_string('apierror', 'block_tag_youtube');
}
return $OUTPUT->notification($message);
} | [
"protected",
"function",
"get_error_message",
"(",
"$",
"message",
"=",
"null",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"if",
"(",
"empty",
"(",
"$",
"message",
")",
")",
"{",
"$",
"message",
"=",
"get_string",
"(",
"'apierror'",
",",
"'block_tag_youtube'",
")",
";",
"}",
"return",
"$",
"OUTPUT",
"->",
"notification",
"(",
"$",
"message",
")",
";",
"}"
] | Returns an error message.
Useful when the block is not properly set or something goes wrong.
@param string $message The message to display.
@return string HTML | [
"Returns",
"an",
"error",
"message",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/tag_youtube/block_tag_youtube.php#L249-L256 |
214,073 | moodle/moodle | blocks/tag_youtube/block_tag_youtube.php | block_tag_youtube.get_service | protected function get_service() {
global $CFG;
if (!$apikey = get_config('block_tag_youtube', 'apikey')) {
return false;
}
// Wrapped in an if in case we call different get_videos_* multiple times.
if (!isset($this->service)) {
require_once($CFG->libdir . '/google/lib.php');
$client = get_google_client();
$client->setDeveloperKey($apikey);
$client->setScopes(array(Google_Service_YouTube::YOUTUBE_READONLY));
$this->service = new Google_Service_YouTube($client);
}
return $this->service;
} | php | protected function get_service() {
global $CFG;
if (!$apikey = get_config('block_tag_youtube', 'apikey')) {
return false;
}
// Wrapped in an if in case we call different get_videos_* multiple times.
if (!isset($this->service)) {
require_once($CFG->libdir . '/google/lib.php');
$client = get_google_client();
$client->setDeveloperKey($apikey);
$client->setScopes(array(Google_Service_YouTube::YOUTUBE_READONLY));
$this->service = new Google_Service_YouTube($client);
}
return $this->service;
} | [
"protected",
"function",
"get_service",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"if",
"(",
"!",
"$",
"apikey",
"=",
"get_config",
"(",
"'block_tag_youtube'",
",",
"'apikey'",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Wrapped in an if in case we call different get_videos_* multiple times.",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"service",
")",
")",
"{",
"require_once",
"(",
"$",
"CFG",
"->",
"libdir",
".",
"'/google/lib.php'",
")",
";",
"$",
"client",
"=",
"get_google_client",
"(",
")",
";",
"$",
"client",
"->",
"setDeveloperKey",
"(",
"$",
"apikey",
")",
";",
"$",
"client",
"->",
"setScopes",
"(",
"array",
"(",
"Google_Service_YouTube",
"::",
"YOUTUBE_READONLY",
")",
")",
";",
"$",
"this",
"->",
"service",
"=",
"new",
"Google_Service_YouTube",
"(",
"$",
"client",
")",
";",
"}",
"return",
"$",
"this",
"->",
"service",
";",
"}"
] | Gets the youtube service object.
@return Google_Service_YouTube | [
"Gets",
"the",
"youtube",
"service",
"object",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/tag_youtube/block_tag_youtube.php#L263-L280 |
214,074 | moodle/moodle | blocks/tag_youtube/block_tag_youtube.php | block_tag_youtube.render_items | protected function render_items($videosdata) {
if (!$videosdata || empty($videosdata->items)) {
if (!empty($videosdata->error)) {
debugging('Error fetching data from youtube: ' . $videosdata->error->message, DEBUG_DEVELOPER);
}
return '';
}
// If we reach that point we already know that the API key is set.
$service = $this->get_service();
$text = html_writer::start_tag('ul', array('class' => 'yt-video-entry unlist img-text'));
foreach ($videosdata->items as $video) {
// Link to the video included in the playlist if listing a playlist.
if (!empty($video->snippet->resourceId)) {
$id = $video->snippet->resourceId->videoId;
$playlist = '&list=' . $video->snippet->playlistId;
} else {
$id = $video->id->videoId;
$playlist = '';
}
$thumbnail = $video->snippet->getThumbnails()->getDefault();
$url = 'http://www.youtube.com/watch?v=' . $id . $playlist;
$videodetails = $service->videos->listVideos('id,contentDetails', array('id' => $id));
if ($videodetails && !empty($videodetails->items)) {
// We fetch by id so we just use the first one.
$details = $videodetails->items[0];
$start = new DateTime('@0');
$start->add(new DateInterval($details->contentDetails->duration));
$seconds = $start->format('U');
}
$text .= html_writer::start_tag('li');
$imgattrs = array('class' => 'youtube-thumb', 'src' => $thumbnail->url, 'alt' => $video->snippet->title);
$thumbhtml = html_writer::empty_tag('img', $imgattrs);
$link = html_writer::tag('a', $thumbhtml, array('href' => $url));
$text .= html_writer::tag('div', $link, array('class' => 'clearfix'));
$text .= html_writer::tag('span', html_writer::tag('a', $video->snippet->title, array('href' => $url)));
if (!empty($seconds)) {
$text .= html_writer::tag('div', format_time($seconds));
}
$text .= html_writer::end_tag('li');
}
$text .= html_writer::end_tag('ul');
return $text;
} | php | protected function render_items($videosdata) {
if (!$videosdata || empty($videosdata->items)) {
if (!empty($videosdata->error)) {
debugging('Error fetching data from youtube: ' . $videosdata->error->message, DEBUG_DEVELOPER);
}
return '';
}
// If we reach that point we already know that the API key is set.
$service = $this->get_service();
$text = html_writer::start_tag('ul', array('class' => 'yt-video-entry unlist img-text'));
foreach ($videosdata->items as $video) {
// Link to the video included in the playlist if listing a playlist.
if (!empty($video->snippet->resourceId)) {
$id = $video->snippet->resourceId->videoId;
$playlist = '&list=' . $video->snippet->playlistId;
} else {
$id = $video->id->videoId;
$playlist = '';
}
$thumbnail = $video->snippet->getThumbnails()->getDefault();
$url = 'http://www.youtube.com/watch?v=' . $id . $playlist;
$videodetails = $service->videos->listVideos('id,contentDetails', array('id' => $id));
if ($videodetails && !empty($videodetails->items)) {
// We fetch by id so we just use the first one.
$details = $videodetails->items[0];
$start = new DateTime('@0');
$start->add(new DateInterval($details->contentDetails->duration));
$seconds = $start->format('U');
}
$text .= html_writer::start_tag('li');
$imgattrs = array('class' => 'youtube-thumb', 'src' => $thumbnail->url, 'alt' => $video->snippet->title);
$thumbhtml = html_writer::empty_tag('img', $imgattrs);
$link = html_writer::tag('a', $thumbhtml, array('href' => $url));
$text .= html_writer::tag('div', $link, array('class' => 'clearfix'));
$text .= html_writer::tag('span', html_writer::tag('a', $video->snippet->title, array('href' => $url)));
if (!empty($seconds)) {
$text .= html_writer::tag('div', format_time($seconds));
}
$text .= html_writer::end_tag('li');
}
$text .= html_writer::end_tag('ul');
return $text;
} | [
"protected",
"function",
"render_items",
"(",
"$",
"videosdata",
")",
"{",
"if",
"(",
"!",
"$",
"videosdata",
"||",
"empty",
"(",
"$",
"videosdata",
"->",
"items",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"videosdata",
"->",
"error",
")",
")",
"{",
"debugging",
"(",
"'Error fetching data from youtube: '",
".",
"$",
"videosdata",
"->",
"error",
"->",
"message",
",",
"DEBUG_DEVELOPER",
")",
";",
"}",
"return",
"''",
";",
"}",
"// If we reach that point we already know that the API key is set.",
"$",
"service",
"=",
"$",
"this",
"->",
"get_service",
"(",
")",
";",
"$",
"text",
"=",
"html_writer",
"::",
"start_tag",
"(",
"'ul'",
",",
"array",
"(",
"'class'",
"=>",
"'yt-video-entry unlist img-text'",
")",
")",
";",
"foreach",
"(",
"$",
"videosdata",
"->",
"items",
"as",
"$",
"video",
")",
"{",
"// Link to the video included in the playlist if listing a playlist.",
"if",
"(",
"!",
"empty",
"(",
"$",
"video",
"->",
"snippet",
"->",
"resourceId",
")",
")",
"{",
"$",
"id",
"=",
"$",
"video",
"->",
"snippet",
"->",
"resourceId",
"->",
"videoId",
";",
"$",
"playlist",
"=",
"'&list='",
".",
"$",
"video",
"->",
"snippet",
"->",
"playlistId",
";",
"}",
"else",
"{",
"$",
"id",
"=",
"$",
"video",
"->",
"id",
"->",
"videoId",
";",
"$",
"playlist",
"=",
"''",
";",
"}",
"$",
"thumbnail",
"=",
"$",
"video",
"->",
"snippet",
"->",
"getThumbnails",
"(",
")",
"->",
"getDefault",
"(",
")",
";",
"$",
"url",
"=",
"'http://www.youtube.com/watch?v='",
".",
"$",
"id",
".",
"$",
"playlist",
";",
"$",
"videodetails",
"=",
"$",
"service",
"->",
"videos",
"->",
"listVideos",
"(",
"'id,contentDetails'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"id",
")",
")",
";",
"if",
"(",
"$",
"videodetails",
"&&",
"!",
"empty",
"(",
"$",
"videodetails",
"->",
"items",
")",
")",
"{",
"// We fetch by id so we just use the first one.",
"$",
"details",
"=",
"$",
"videodetails",
"->",
"items",
"[",
"0",
"]",
";",
"$",
"start",
"=",
"new",
"DateTime",
"(",
"'@0'",
")",
";",
"$",
"start",
"->",
"add",
"(",
"new",
"DateInterval",
"(",
"$",
"details",
"->",
"contentDetails",
"->",
"duration",
")",
")",
";",
"$",
"seconds",
"=",
"$",
"start",
"->",
"format",
"(",
"'U'",
")",
";",
"}",
"$",
"text",
".=",
"html_writer",
"::",
"start_tag",
"(",
"'li'",
")",
";",
"$",
"imgattrs",
"=",
"array",
"(",
"'class'",
"=>",
"'youtube-thumb'",
",",
"'src'",
"=>",
"$",
"thumbnail",
"->",
"url",
",",
"'alt'",
"=>",
"$",
"video",
"->",
"snippet",
"->",
"title",
")",
";",
"$",
"thumbhtml",
"=",
"html_writer",
"::",
"empty_tag",
"(",
"'img'",
",",
"$",
"imgattrs",
")",
";",
"$",
"link",
"=",
"html_writer",
"::",
"tag",
"(",
"'a'",
",",
"$",
"thumbhtml",
",",
"array",
"(",
"'href'",
"=>",
"$",
"url",
")",
")",
";",
"$",
"text",
".=",
"html_writer",
"::",
"tag",
"(",
"'div'",
",",
"$",
"link",
",",
"array",
"(",
"'class'",
"=>",
"'clearfix'",
")",
")",
";",
"$",
"text",
".=",
"html_writer",
"::",
"tag",
"(",
"'span'",
",",
"html_writer",
"::",
"tag",
"(",
"'a'",
",",
"$",
"video",
"->",
"snippet",
"->",
"title",
",",
"array",
"(",
"'href'",
"=>",
"$",
"url",
")",
")",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"seconds",
")",
")",
"{",
"$",
"text",
".=",
"html_writer",
"::",
"tag",
"(",
"'div'",
",",
"format_time",
"(",
"$",
"seconds",
")",
")",
";",
"}",
"$",
"text",
".=",
"html_writer",
"::",
"end_tag",
"(",
"'li'",
")",
";",
"}",
"$",
"text",
".=",
"html_writer",
"::",
"end_tag",
"(",
"'ul'",
")",
";",
"return",
"$",
"text",
";",
"}"
] | Renders the list of items.
@param array $videosdata
@return string HTML | [
"Renders",
"the",
"list",
"of",
"items",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/tag_youtube/block_tag_youtube.php#L288-L342 |
214,075 | moodle/moodle | competency/classes/template_competency.php | template_competency.count_templates | public static function count_templates($competencyid, $onlyvisible) {
global $DB;
$sql = 'SELECT COUNT(tpl.id)
FROM {' . self::TABLE . '} tplcomp
JOIN {' . template::TABLE . '} tpl
ON tplcomp.templateid = tpl.id
WHERE tplcomp.competencyid = ? ';
$params = array($competencyid);
if ($onlyvisible) {
$sql .= ' AND tpl.visible = ?';
$params[] = 1;
}
$results = $DB->count_records_sql($sql, $params);
return $results;
} | php | public static function count_templates($competencyid, $onlyvisible) {
global $DB;
$sql = 'SELECT COUNT(tpl.id)
FROM {' . self::TABLE . '} tplcomp
JOIN {' . template::TABLE . '} tpl
ON tplcomp.templateid = tpl.id
WHERE tplcomp.competencyid = ? ';
$params = array($competencyid);
if ($onlyvisible) {
$sql .= ' AND tpl.visible = ?';
$params[] = 1;
}
$results = $DB->count_records_sql($sql, $params);
return $results;
} | [
"public",
"static",
"function",
"count_templates",
"(",
"$",
"competencyid",
",",
"$",
"onlyvisible",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"sql",
"=",
"'SELECT COUNT(tpl.id)\n FROM {'",
".",
"self",
"::",
"TABLE",
".",
"'} tplcomp\n JOIN {'",
".",
"template",
"::",
"TABLE",
".",
"'} tpl\n ON tplcomp.templateid = tpl.id\n WHERE tplcomp.competencyid = ? '",
";",
"$",
"params",
"=",
"array",
"(",
"$",
"competencyid",
")",
";",
"if",
"(",
"$",
"onlyvisible",
")",
"{",
"$",
"sql",
".=",
"' AND tpl.visible = ?'",
";",
"$",
"params",
"[",
"]",
"=",
"1",
";",
"}",
"$",
"results",
"=",
"$",
"DB",
"->",
"count_records_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"return",
"$",
"results",
";",
"}"
] | Count the templates using a competency.
@param int $competencyid The competency id
@param bool $onlyvisible If true, only count visible templates using this competency.
@return int | [
"Count",
"the",
"templates",
"using",
"a",
"competency",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/template_competency.php#L68-L86 |
214,076 | moodle/moodle | competency/classes/template_competency.php | template_competency.list_templates | public static function list_templates($competencyid, $onlyvisible) {
global $DB;
$sql = 'SELECT tpl.*
FROM {' . template::TABLE . '} tpl
JOIN {' . self::TABLE . '} tplcomp
ON tplcomp.templateid = tpl.id
WHERE tplcomp.competencyid = ? ';
$params = array($competencyid);
if ($onlyvisible) {
$sql .= ' AND tpl.visible = ?';
$params[] = 1;
}
$sql .= ' ORDER BY tpl.id ASC';
$results = $DB->get_records_sql($sql, $params);
$instances = array();
foreach ($results as $result) {
array_push($instances, new template(0, $result));
}
return $instances;
} | php | public static function list_templates($competencyid, $onlyvisible) {
global $DB;
$sql = 'SELECT tpl.*
FROM {' . template::TABLE . '} tpl
JOIN {' . self::TABLE . '} tplcomp
ON tplcomp.templateid = tpl.id
WHERE tplcomp.competencyid = ? ';
$params = array($competencyid);
if ($onlyvisible) {
$sql .= ' AND tpl.visible = ?';
$params[] = 1;
}
$sql .= ' ORDER BY tpl.id ASC';
$results = $DB->get_records_sql($sql, $params);
$instances = array();
foreach ($results as $result) {
array_push($instances, new template(0, $result));
}
return $instances;
} | [
"public",
"static",
"function",
"list_templates",
"(",
"$",
"competencyid",
",",
"$",
"onlyvisible",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"sql",
"=",
"'SELECT tpl.*\n FROM {'",
".",
"template",
"::",
"TABLE",
".",
"'} tpl\n JOIN {'",
".",
"self",
"::",
"TABLE",
".",
"'} tplcomp\n ON tplcomp.templateid = tpl.id\n WHERE tplcomp.competencyid = ? '",
";",
"$",
"params",
"=",
"array",
"(",
"$",
"competencyid",
")",
";",
"if",
"(",
"$",
"onlyvisible",
")",
"{",
"$",
"sql",
".=",
"' AND tpl.visible = ?'",
";",
"$",
"params",
"[",
"]",
"=",
"1",
";",
"}",
"$",
"sql",
".=",
"' ORDER BY tpl.id ASC'",
";",
"$",
"results",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"$",
"instances",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"results",
"as",
"$",
"result",
")",
"{",
"array_push",
"(",
"$",
"instances",
",",
"new",
"template",
"(",
"0",
",",
"$",
"result",
")",
")",
";",
"}",
"return",
"$",
"instances",
";",
"}"
] | List the templates using a competency.
@param int $competencyid The competency id
@param bool $onlyvisible If true, only count visible templates using this competency.
@return array[competency] | [
"List",
"the",
"templates",
"using",
"a",
"competency",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/template_competency.php#L95-L120 |
214,077 | moodle/moodle | competency/classes/template_competency.php | template_competency.count_competencies_with_no_courses | public static function count_competencies_with_no_courses($templateid) {
global $DB;
$sql = 'SELECT COUNT(comp.id)
FROM {' . self::TABLE . '} tplcomp
JOIN {' . competency::TABLE . '} comp
ON tplcomp.competencyid = comp.id
LEFT JOIN {' . course_competency::TABLE . '} crscomp
ON crscomp.competencyid = comp.id
WHERE tplcomp.templateid = ? AND crscomp.id IS NULL';
$params = array($templateid);
$results = $DB->count_records_sql($sql, $params);
return $results;
} | php | public static function count_competencies_with_no_courses($templateid) {
global $DB;
$sql = 'SELECT COUNT(comp.id)
FROM {' . self::TABLE . '} tplcomp
JOIN {' . competency::TABLE . '} comp
ON tplcomp.competencyid = comp.id
LEFT JOIN {' . course_competency::TABLE . '} crscomp
ON crscomp.competencyid = comp.id
WHERE tplcomp.templateid = ? AND crscomp.id IS NULL';
$params = array($templateid);
$results = $DB->count_records_sql($sql, $params);
return $results;
} | [
"public",
"static",
"function",
"count_competencies_with_no_courses",
"(",
"$",
"templateid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"sql",
"=",
"'SELECT COUNT(comp.id)\n FROM {'",
".",
"self",
"::",
"TABLE",
".",
"'} tplcomp\n JOIN {'",
".",
"competency",
"::",
"TABLE",
".",
"'} comp\n ON tplcomp.competencyid = comp.id\n LEFT JOIN {'",
".",
"course_competency",
"::",
"TABLE",
".",
"'} crscomp\n ON crscomp.competencyid = comp.id\n WHERE tplcomp.templateid = ? AND crscomp.id IS NULL'",
";",
"$",
"params",
"=",
"array",
"(",
"$",
"templateid",
")",
";",
"$",
"results",
"=",
"$",
"DB",
"->",
"count_records_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"return",
"$",
"results",
";",
"}"
] | Count the competencies in a template with no links to courses.
@param int $templateid The template id
@return int | [
"Count",
"the",
"competencies",
"in",
"a",
"template",
"with",
"no",
"links",
"to",
"courses",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/template_competency.php#L149-L164 |
214,078 | moodle/moodle | competency/classes/template_competency.php | template_competency.list_competencies | public static function list_competencies($templateid) {
global $DB;
$sql = 'SELECT comp.*
FROM {' . competency::TABLE . '} comp
JOIN {' . self::TABLE . '} tplcomp
ON tplcomp.competencyid = comp.id
WHERE tplcomp.templateid = ?
ORDER BY tplcomp.sortorder ASC,
tplcomp.id ASC';
$params = array($templateid);
$results = $DB->get_records_sql($sql, $params);
$instances = array();
foreach ($results as $result) {
array_push($instances, new competency(0, $result));
}
return $instances;
} | php | public static function list_competencies($templateid) {
global $DB;
$sql = 'SELECT comp.*
FROM {' . competency::TABLE . '} comp
JOIN {' . self::TABLE . '} tplcomp
ON tplcomp.competencyid = comp.id
WHERE tplcomp.templateid = ?
ORDER BY tplcomp.sortorder ASC,
tplcomp.id ASC';
$params = array($templateid);
$results = $DB->get_records_sql($sql, $params);
$instances = array();
foreach ($results as $result) {
array_push($instances, new competency(0, $result));
}
return $instances;
} | [
"public",
"static",
"function",
"list_competencies",
"(",
"$",
"templateid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"sql",
"=",
"'SELECT comp.*\n FROM {'",
".",
"competency",
"::",
"TABLE",
".",
"'} comp\n JOIN {'",
".",
"self",
"::",
"TABLE",
".",
"'} tplcomp\n ON tplcomp.competencyid = comp.id\n WHERE tplcomp.templateid = ?\n ORDER BY tplcomp.sortorder ASC,\n tplcomp.id ASC'",
";",
"$",
"params",
"=",
"array",
"(",
"$",
"templateid",
")",
";",
"$",
"results",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"$",
"instances",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"results",
"as",
"$",
"result",
")",
"{",
"array_push",
"(",
"$",
"instances",
",",
"new",
"competency",
"(",
"0",
",",
"$",
"result",
")",
")",
";",
"}",
"return",
"$",
"instances",
";",
"}"
] | List the competencies in this template.
@param int $templateid The template id
@return array[competency] | [
"List",
"the",
"competencies",
"in",
"this",
"template",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/template_competency.php#L197-L217 |
214,079 | moodle/moodle | admin/tool/policy/classes/event/acceptance_base.php | acceptance_base.create_from_record | public static function create_from_record($record) {
$event = static::create([
'objectid' => $record->id,
'relateduserid' => $record->userid,
'context' => \context_user::instance($record->userid),
'other' => [
'policyversionid' => $record->policyversionid,
'note' => $record->note,
'status' => $record->status,
],
]);
$event->add_record_snapshot($event->objecttable, $record);
return $event;
} | php | public static function create_from_record($record) {
$event = static::create([
'objectid' => $record->id,
'relateduserid' => $record->userid,
'context' => \context_user::instance($record->userid),
'other' => [
'policyversionid' => $record->policyversionid,
'note' => $record->note,
'status' => $record->status,
],
]);
$event->add_record_snapshot($event->objecttable, $record);
return $event;
} | [
"public",
"static",
"function",
"create_from_record",
"(",
"$",
"record",
")",
"{",
"$",
"event",
"=",
"static",
"::",
"create",
"(",
"[",
"'objectid'",
"=>",
"$",
"record",
"->",
"id",
",",
"'relateduserid'",
"=>",
"$",
"record",
"->",
"userid",
",",
"'context'",
"=>",
"\\",
"context_user",
"::",
"instance",
"(",
"$",
"record",
"->",
"userid",
")",
",",
"'other'",
"=>",
"[",
"'policyversionid'",
"=>",
"$",
"record",
"->",
"policyversionid",
",",
"'note'",
"=>",
"$",
"record",
"->",
"note",
",",
"'status'",
"=>",
"$",
"record",
"->",
"status",
",",
"]",
",",
"]",
")",
";",
"$",
"event",
"->",
"add_record_snapshot",
"(",
"$",
"event",
"->",
"objecttable",
",",
"$",
"record",
")",
";",
"return",
"$",
"event",
";",
"}"
] | Create event from record.
@param stdClass $record
@return acceptance_created | [
"Create",
"event",
"from",
"record",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/event/acceptance_base.php#L54-L67 |
214,080 | moodle/moodle | lib/google/src/Google/Http/CacheParser.php | Google_Http_CacheParser.isRequestCacheable | public static function isRequestCacheable(Google_Http_Request $resp)
{
$method = $resp->getRequestMethod();
if (! in_array($method, self::$CACHEABLE_HTTP_METHODS)) {
return false;
}
// Don't cache authorized requests/responses.
// [rfc2616-14.8] When a shared cache receives a request containing an
// Authorization field, it MUST NOT return the corresponding response
// as a reply to any other request...
if ($resp->getRequestHeader("authorization")) {
return false;
}
return true;
} | php | public static function isRequestCacheable(Google_Http_Request $resp)
{
$method = $resp->getRequestMethod();
if (! in_array($method, self::$CACHEABLE_HTTP_METHODS)) {
return false;
}
// Don't cache authorized requests/responses.
// [rfc2616-14.8] When a shared cache receives a request containing an
// Authorization field, it MUST NOT return the corresponding response
// as a reply to any other request...
if ($resp->getRequestHeader("authorization")) {
return false;
}
return true;
} | [
"public",
"static",
"function",
"isRequestCacheable",
"(",
"Google_Http_Request",
"$",
"resp",
")",
"{",
"$",
"method",
"=",
"$",
"resp",
"->",
"getRequestMethod",
"(",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"method",
",",
"self",
"::",
"$",
"CACHEABLE_HTTP_METHODS",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Don't cache authorized requests/responses.",
"// [rfc2616-14.8] When a shared cache receives a request containing an",
"// Authorization field, it MUST NOT return the corresponding response",
"// as a reply to any other request...",
"if",
"(",
"$",
"resp",
"->",
"getRequestHeader",
"(",
"\"authorization\"",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Check if an HTTP request can be cached by a private local cache.
@static
@param Google_Http_Request $resp
@return bool True if the request is cacheable.
False if the request is uncacheable. | [
"Check",
"if",
"an",
"HTTP",
"request",
"can",
"be",
"cached",
"by",
"a",
"private",
"local",
"cache",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/google/src/Google/Http/CacheParser.php#L39-L55 |
214,081 | moodle/moodle | lib/google/src/Google/Http/CacheParser.php | Google_Http_CacheParser.isResponseCacheable | public static function isResponseCacheable(Google_Http_Request $resp)
{
// First, check if the HTTP request was cacheable before inspecting the
// HTTP response.
if (false == self::isRequestCacheable($resp)) {
return false;
}
$code = $resp->getResponseHttpCode();
if (! in_array($code, self::$CACHEABLE_STATUS_CODES)) {
return false;
}
// The resource is uncacheable if the resource is already expired and
// the resource doesn't have an ETag for revalidation.
$etag = $resp->getResponseHeader("etag");
if (self::isExpired($resp) && $etag == false) {
return false;
}
// [rfc2616-14.9.2] If [no-store is] sent in a response, a cache MUST NOT
// store any part of either this response or the request that elicited it.
$cacheControl = $resp->getParsedCacheControl();
if (isset($cacheControl['no-store'])) {
return false;
}
// Pragma: no-cache is an http request directive, but is occasionally
// used as a response header incorrectly.
$pragma = $resp->getResponseHeader('pragma');
if ($pragma == 'no-cache' || strpos($pragma, 'no-cache') !== false) {
return false;
}
// [rfc2616-14.44] Vary: * is extremely difficult to cache. "It implies that
// a cache cannot determine from the request headers of a subsequent request
// whether this response is the appropriate representation."
// Given this, we deem responses with the Vary header as uncacheable.
$vary = $resp->getResponseHeader('vary');
if ($vary) {
return false;
}
return true;
} | php | public static function isResponseCacheable(Google_Http_Request $resp)
{
// First, check if the HTTP request was cacheable before inspecting the
// HTTP response.
if (false == self::isRequestCacheable($resp)) {
return false;
}
$code = $resp->getResponseHttpCode();
if (! in_array($code, self::$CACHEABLE_STATUS_CODES)) {
return false;
}
// The resource is uncacheable if the resource is already expired and
// the resource doesn't have an ETag for revalidation.
$etag = $resp->getResponseHeader("etag");
if (self::isExpired($resp) && $etag == false) {
return false;
}
// [rfc2616-14.9.2] If [no-store is] sent in a response, a cache MUST NOT
// store any part of either this response or the request that elicited it.
$cacheControl = $resp->getParsedCacheControl();
if (isset($cacheControl['no-store'])) {
return false;
}
// Pragma: no-cache is an http request directive, but is occasionally
// used as a response header incorrectly.
$pragma = $resp->getResponseHeader('pragma');
if ($pragma == 'no-cache' || strpos($pragma, 'no-cache') !== false) {
return false;
}
// [rfc2616-14.44] Vary: * is extremely difficult to cache. "It implies that
// a cache cannot determine from the request headers of a subsequent request
// whether this response is the appropriate representation."
// Given this, we deem responses with the Vary header as uncacheable.
$vary = $resp->getResponseHeader('vary');
if ($vary) {
return false;
}
return true;
} | [
"public",
"static",
"function",
"isResponseCacheable",
"(",
"Google_Http_Request",
"$",
"resp",
")",
"{",
"// First, check if the HTTP request was cacheable before inspecting the",
"// HTTP response.",
"if",
"(",
"false",
"==",
"self",
"::",
"isRequestCacheable",
"(",
"$",
"resp",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"code",
"=",
"$",
"resp",
"->",
"getResponseHttpCode",
"(",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"code",
",",
"self",
"::",
"$",
"CACHEABLE_STATUS_CODES",
")",
")",
"{",
"return",
"false",
";",
"}",
"// The resource is uncacheable if the resource is already expired and",
"// the resource doesn't have an ETag for revalidation.",
"$",
"etag",
"=",
"$",
"resp",
"->",
"getResponseHeader",
"(",
"\"etag\"",
")",
";",
"if",
"(",
"self",
"::",
"isExpired",
"(",
"$",
"resp",
")",
"&&",
"$",
"etag",
"==",
"false",
")",
"{",
"return",
"false",
";",
"}",
"// [rfc2616-14.9.2] If [no-store is] sent in a response, a cache MUST NOT",
"// store any part of either this response or the request that elicited it.",
"$",
"cacheControl",
"=",
"$",
"resp",
"->",
"getParsedCacheControl",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"cacheControl",
"[",
"'no-store'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Pragma: no-cache is an http request directive, but is occasionally",
"// used as a response header incorrectly.",
"$",
"pragma",
"=",
"$",
"resp",
"->",
"getResponseHeader",
"(",
"'pragma'",
")",
";",
"if",
"(",
"$",
"pragma",
"==",
"'no-cache'",
"||",
"strpos",
"(",
"$",
"pragma",
",",
"'no-cache'",
")",
"!==",
"false",
")",
"{",
"return",
"false",
";",
"}",
"// [rfc2616-14.44] Vary: * is extremely difficult to cache. \"It implies that",
"// a cache cannot determine from the request headers of a subsequent request",
"// whether this response is the appropriate representation.\"",
"// Given this, we deem responses with the Vary header as uncacheable.",
"$",
"vary",
"=",
"$",
"resp",
"->",
"getResponseHeader",
"(",
"'vary'",
")",
";",
"if",
"(",
"$",
"vary",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Check if an HTTP response can be cached by a private local cache.
@static
@param Google_Http_Request $resp
@return bool True if the response is cacheable.
False if the response is un-cacheable. | [
"Check",
"if",
"an",
"HTTP",
"response",
"can",
"be",
"cached",
"by",
"a",
"private",
"local",
"cache",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/google/src/Google/Http/CacheParser.php#L65-L109 |
214,082 | moodle/moodle | search/classes/base_activity.php | base_activity.get_document_recordset | public function get_document_recordset($modifiedfrom = 0, \context $context = null) {
global $DB;
list ($contextjoin, $contextparams) = $this->get_context_restriction_sql(
$context, $this->get_module_name(), 'modtable');
if ($contextjoin === null) {
return null;
}
return $DB->get_recordset_sql('SELECT modtable.* FROM {' . $this->get_module_name() .
'} modtable ' . $contextjoin . ' WHERE modtable.' . static::MODIFIED_FIELD_NAME .
' >= ? ORDER BY modtable.' . static::MODIFIED_FIELD_NAME . ' ASC',
array_merge($contextparams, [$modifiedfrom]));
} | php | public function get_document_recordset($modifiedfrom = 0, \context $context = null) {
global $DB;
list ($contextjoin, $contextparams) = $this->get_context_restriction_sql(
$context, $this->get_module_name(), 'modtable');
if ($contextjoin === null) {
return null;
}
return $DB->get_recordset_sql('SELECT modtable.* FROM {' . $this->get_module_name() .
'} modtable ' . $contextjoin . ' WHERE modtable.' . static::MODIFIED_FIELD_NAME .
' >= ? ORDER BY modtable.' . static::MODIFIED_FIELD_NAME . ' ASC',
array_merge($contextparams, [$modifiedfrom]));
} | [
"public",
"function",
"get_document_recordset",
"(",
"$",
"modifiedfrom",
"=",
"0",
",",
"\\",
"context",
"$",
"context",
"=",
"null",
")",
"{",
"global",
"$",
"DB",
";",
"list",
"(",
"$",
"contextjoin",
",",
"$",
"contextparams",
")",
"=",
"$",
"this",
"->",
"get_context_restriction_sql",
"(",
"$",
"context",
",",
"$",
"this",
"->",
"get_module_name",
"(",
")",
",",
"'modtable'",
")",
";",
"if",
"(",
"$",
"contextjoin",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"DB",
"->",
"get_recordset_sql",
"(",
"'SELECT modtable.* FROM {'",
".",
"$",
"this",
"->",
"get_module_name",
"(",
")",
".",
"'} modtable '",
".",
"$",
"contextjoin",
".",
"' WHERE modtable.'",
".",
"static",
"::",
"MODIFIED_FIELD_NAME",
".",
"' >= ? ORDER BY modtable.'",
".",
"static",
"::",
"MODIFIED_FIELD_NAME",
".",
"' ASC'",
",",
"array_merge",
"(",
"$",
"contextparams",
",",
"[",
"$",
"modifiedfrom",
"]",
")",
")",
";",
"}"
] | Returns recordset containing all activities within the given context.
@param \context|null $context Context
@param int $modifiedfrom Return only records modified after this date
@return \moodle_recordset|null Recordset, or null if no possible activities in given context | [
"Returns",
"recordset",
"containing",
"all",
"activities",
"within",
"the",
"given",
"context",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/base_activity.php#L64-L75 |
214,083 | moodle/moodle | search/classes/base_activity.php | base_activity.get_context_url | public function get_context_url(\core_search\document $doc) {
$cminfo = $this->get_cm($this->get_module_name(), strval($doc->get('itemid')), $doc->get('courseid'));
return new \moodle_url('/mod/' . $this->get_module_name() . '/view.php', array('id' => $cminfo->id));
} | php | public function get_context_url(\core_search\document $doc) {
$cminfo = $this->get_cm($this->get_module_name(), strval($doc->get('itemid')), $doc->get('courseid'));
return new \moodle_url('/mod/' . $this->get_module_name() . '/view.php', array('id' => $cminfo->id));
} | [
"public",
"function",
"get_context_url",
"(",
"\\",
"core_search",
"\\",
"document",
"$",
"doc",
")",
"{",
"$",
"cminfo",
"=",
"$",
"this",
"->",
"get_cm",
"(",
"$",
"this",
"->",
"get_module_name",
"(",
")",
",",
"strval",
"(",
"$",
"doc",
"->",
"get",
"(",
"'itemid'",
")",
")",
",",
"$",
"doc",
"->",
"get",
"(",
"'courseid'",
")",
")",
";",
"return",
"new",
"\\",
"moodle_url",
"(",
"'/mod/'",
".",
"$",
"this",
"->",
"get_module_name",
"(",
")",
".",
"'/view.php'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"cminfo",
"->",
"id",
")",
")",
";",
"}"
] | Link to the module instance.
@param \core_search\document $doc
@return \moodle_url | [
"Link",
"to",
"the",
"module",
"instance",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/base_activity.php#L170-L173 |
214,084 | moodle/moodle | search/classes/base_activity.php | base_activity.get_activity | protected function get_activity($instanceid) {
global $DB;
if (empty($this->activitiesdata[$this->get_module_name()][$instanceid])) {
$this->activitiesdata[$this->get_module_name()][$instanceid] = $DB->get_record($this->get_module_name(),
array('id' => $instanceid), '*', MUST_EXIST);
}
return $this->activitiesdata[$this->get_module_name()][$instanceid];
} | php | protected function get_activity($instanceid) {
global $DB;
if (empty($this->activitiesdata[$this->get_module_name()][$instanceid])) {
$this->activitiesdata[$this->get_module_name()][$instanceid] = $DB->get_record($this->get_module_name(),
array('id' => $instanceid), '*', MUST_EXIST);
}
return $this->activitiesdata[$this->get_module_name()][$instanceid];
} | [
"protected",
"function",
"get_activity",
"(",
"$",
"instanceid",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"activitiesdata",
"[",
"$",
"this",
"->",
"get_module_name",
"(",
")",
"]",
"[",
"$",
"instanceid",
"]",
")",
")",
"{",
"$",
"this",
"->",
"activitiesdata",
"[",
"$",
"this",
"->",
"get_module_name",
"(",
")",
"]",
"[",
"$",
"instanceid",
"]",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"$",
"this",
"->",
"get_module_name",
"(",
")",
",",
"array",
"(",
"'id'",
"=>",
"$",
"instanceid",
")",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"}",
"return",
"$",
"this",
"->",
"activitiesdata",
"[",
"$",
"this",
"->",
"get_module_name",
"(",
")",
"]",
"[",
"$",
"instanceid",
"]",
";",
"}"
] | Returns an activity instance. Internally uses the class component to know which activity module should be retrieved.
@param int $instanceid
@return stdClass | [
"Returns",
"an",
"activity",
"instance",
".",
"Internally",
"uses",
"the",
"class",
"component",
"to",
"know",
"which",
"activity",
"module",
"should",
"be",
"retrieved",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/classes/base_activity.php#L181-L190 |
214,085 | moodle/moodle | mod/data/classes/event/record_updated.php | record_updated.get_legacy_logdata | public function get_legacy_logdata() {
return array($this->courseid, 'data', 'update', 'view.php?d=' . $this->other['dataid'] . '&rid=' . $this->objectid,
$this->other['dataid'], $this->contextinstanceid);
} | php | public function get_legacy_logdata() {
return array($this->courseid, 'data', 'update', 'view.php?d=' . $this->other['dataid'] . '&rid=' . $this->objectid,
$this->other['dataid'], $this->contextinstanceid);
} | [
"public",
"function",
"get_legacy_logdata",
"(",
")",
"{",
"return",
"array",
"(",
"$",
"this",
"->",
"courseid",
",",
"'data'",
",",
"'update'",
",",
"'view.php?d='",
".",
"$",
"this",
"->",
"other",
"[",
"'dataid'",
"]",
".",
"'&rid='",
".",
"$",
"this",
"->",
"objectid",
",",
"$",
"this",
"->",
"other",
"[",
"'dataid'",
"]",
",",
"$",
"this",
"->",
"contextinstanceid",
")",
";",
"}"
] | Get the legacy event log data.
@return array | [
"Get",
"the",
"legacy",
"event",
"log",
"data",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/classes/event/record_updated.php#L89-L92 |
214,086 | moodle/moodle | lib/classes/plugininfo/repository.php | repository.is_uninstall_allowed | public function is_uninstall_allowed() {
if ($this->name === 'upload' || $this->name === 'coursefiles' || $this->name === 'user' || $this->name === 'recent') {
return false;
} else {
return true;
}
} | php | public function is_uninstall_allowed() {
if ($this->name === 'upload' || $this->name === 'coursefiles' || $this->name === 'user' || $this->name === 'recent') {
return false;
} else {
return true;
}
} | [
"public",
"function",
"is_uninstall_allowed",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"name",
"===",
"'upload'",
"||",
"$",
"this",
"->",
"name",
"===",
"'coursefiles'",
"||",
"$",
"this",
"->",
"name",
"===",
"'user'",
"||",
"$",
"this",
"->",
"name",
"===",
"'recent'",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"return",
"true",
";",
"}",
"}"
] | Defines if there should be a way to uninstall the plugin via the administration UI.
@return boolean | [
"Defines",
"if",
"there",
"should",
"be",
"a",
"way",
"to",
"uninstall",
"the",
"plugin",
"via",
"the",
"administration",
"UI",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/plugininfo/repository.php#L75-L81 |
214,087 | moodle/moodle | lib/classes/plugininfo/repository.php | repository.uninstall_cleanup | public function uninstall_cleanup() {
global $CFG;
require_once($CFG->dirroot.'/repository/lib.php');
$repo = \repository::get_type_by_typename($this->name);
if ($repo) {
$repo->delete(true);
}
parent::uninstall_cleanup();
} | php | public function uninstall_cleanup() {
global $CFG;
require_once($CFG->dirroot.'/repository/lib.php');
$repo = \repository::get_type_by_typename($this->name);
if ($repo) {
$repo->delete(true);
}
parent::uninstall_cleanup();
} | [
"public",
"function",
"uninstall_cleanup",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/repository/lib.php'",
")",
";",
"$",
"repo",
"=",
"\\",
"repository",
"::",
"get_type_by_typename",
"(",
"$",
"this",
"->",
"name",
")",
";",
"if",
"(",
"$",
"repo",
")",
"{",
"$",
"repo",
"->",
"delete",
"(",
"true",
")",
";",
"}",
"parent",
"::",
"uninstall_cleanup",
"(",
")",
";",
"}"
] | Pre-uninstall hook.
This is intended for disabling of plugin, some DB table purging, etc.
Converts all linked files to standard files when repository is removed
and cleans up all records in the DB for that repository. | [
"Pre",
"-",
"uninstall",
"hook",
".",
"This",
"is",
"intended",
"for",
"disabling",
"of",
"plugin",
"some",
"DB",
"table",
"purging",
"etc",
".",
"Converts",
"all",
"linked",
"files",
"to",
"standard",
"files",
"when",
"repository",
"is",
"removed",
"and",
"cleans",
"up",
"all",
"records",
"in",
"the",
"DB",
"for",
"that",
"repository",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/plugininfo/repository.php#L89-L99 |
214,088 | moodle/moodle | enrol/lti/ims-blti/blti.php | BLTI.decodeBase64 | function decodeBase64($info) {
$keysNoEncode = array("lti_version", "lti_message_type", "tool_consumer_instance_description", "tool_consumer_instance_guid", "oauth_consumer_key", "custom_lti_message_encoded_base64", "oauth_nonce", "oauth_version", "oauth_callback", "oauth_timestamp", "basiclti_submit", "oauth_signature_method", "ext_ims_lis_memberships_id", "ext_ims_lis_memberships_url");
foreach ($info as $key => $item){
if (!in_array($key, $keysNoEncode))
$info[$key] = base64_decode($item);
}
return $info;
} | php | function decodeBase64($info) {
$keysNoEncode = array("lti_version", "lti_message_type", "tool_consumer_instance_description", "tool_consumer_instance_guid", "oauth_consumer_key", "custom_lti_message_encoded_base64", "oauth_nonce", "oauth_version", "oauth_callback", "oauth_timestamp", "basiclti_submit", "oauth_signature_method", "ext_ims_lis_memberships_id", "ext_ims_lis_memberships_url");
foreach ($info as $key => $item){
if (!in_array($key, $keysNoEncode))
$info[$key] = base64_decode($item);
}
return $info;
} | [
"function",
"decodeBase64",
"(",
"$",
"info",
")",
"{",
"$",
"keysNoEncode",
"=",
"array",
"(",
"\"lti_version\"",
",",
"\"lti_message_type\"",
",",
"\"tool_consumer_instance_description\"",
",",
"\"tool_consumer_instance_guid\"",
",",
"\"oauth_consumer_key\"",
",",
"\"custom_lti_message_encoded_base64\"",
",",
"\"oauth_nonce\"",
",",
"\"oauth_version\"",
",",
"\"oauth_callback\"",
",",
"\"oauth_timestamp\"",
",",
"\"basiclti_submit\"",
",",
"\"oauth_signature_method\"",
",",
"\"ext_ims_lis_memberships_id\"",
",",
"\"ext_ims_lis_memberships_url\"",
")",
";",
"foreach",
"(",
"$",
"info",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"key",
",",
"$",
"keysNoEncode",
")",
")",
"$",
"info",
"[",
"$",
"key",
"]",
"=",
"base64_decode",
"(",
"$",
"item",
")",
";",
"}",
"return",
"$",
"info",
";",
"}"
] | Data submitter are in base64 then we have to decode
@author Antoni Bertran (antoni@tresipunt.com)
@param $info array
@date 20120801 | [
"Data",
"submitter",
"are",
"in",
"base64",
"then",
"we",
"have",
"to",
"decode"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/lti/ims-blti/blti.php#L267-L274 |
214,089 | moodle/moodle | mod/forum/classes/post_form.php | mod_forum_post_form.attachment_options | public static function attachment_options($forum) {
global $COURSE, $PAGE, $CFG;
$maxbytes = get_user_max_upload_file_size($PAGE->context, $CFG->maxbytes, $COURSE->maxbytes, $forum->maxbytes);
return array(
'subdirs' => 0,
'maxbytes' => $maxbytes,
'maxfiles' => $forum->maxattachments,
'accepted_types' => '*',
'return_types' => FILE_INTERNAL | FILE_CONTROLLED_LINK
);
} | php | public static function attachment_options($forum) {
global $COURSE, $PAGE, $CFG;
$maxbytes = get_user_max_upload_file_size($PAGE->context, $CFG->maxbytes, $COURSE->maxbytes, $forum->maxbytes);
return array(
'subdirs' => 0,
'maxbytes' => $maxbytes,
'maxfiles' => $forum->maxattachments,
'accepted_types' => '*',
'return_types' => FILE_INTERNAL | FILE_CONTROLLED_LINK
);
} | [
"public",
"static",
"function",
"attachment_options",
"(",
"$",
"forum",
")",
"{",
"global",
"$",
"COURSE",
",",
"$",
"PAGE",
",",
"$",
"CFG",
";",
"$",
"maxbytes",
"=",
"get_user_max_upload_file_size",
"(",
"$",
"PAGE",
"->",
"context",
",",
"$",
"CFG",
"->",
"maxbytes",
",",
"$",
"COURSE",
"->",
"maxbytes",
",",
"$",
"forum",
"->",
"maxbytes",
")",
";",
"return",
"array",
"(",
"'subdirs'",
"=>",
"0",
",",
"'maxbytes'",
"=>",
"$",
"maxbytes",
",",
"'maxfiles'",
"=>",
"$",
"forum",
"->",
"maxattachments",
",",
"'accepted_types'",
"=>",
"'*'",
",",
"'return_types'",
"=>",
"FILE_INTERNAL",
"|",
"FILE_CONTROLLED_LINK",
")",
";",
"}"
] | Returns the options array to use in filemanager for forum attachments
@param stdClass $forum
@return array | [
"Returns",
"the",
"options",
"array",
"to",
"use",
"in",
"filemanager",
"for",
"forum",
"attachments"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/post_form.php#L45-L55 |
214,090 | moodle/moodle | mod/forum/classes/post_form.php | mod_forum_post_form.editor_options | public static function editor_options(context_module $context, $postid) {
global $COURSE, $PAGE, $CFG;
// TODO: add max files and max size support
$maxbytes = get_user_max_upload_file_size($PAGE->context, $CFG->maxbytes, $COURSE->maxbytes);
return array(
'maxfiles' => EDITOR_UNLIMITED_FILES,
'maxbytes' => $maxbytes,
'trusttext'=> true,
'return_types'=> FILE_INTERNAL | FILE_EXTERNAL,
'subdirs' => file_area_contains_subdirs($context, 'mod_forum', 'post', $postid)
);
} | php | public static function editor_options(context_module $context, $postid) {
global $COURSE, $PAGE, $CFG;
// TODO: add max files and max size support
$maxbytes = get_user_max_upload_file_size($PAGE->context, $CFG->maxbytes, $COURSE->maxbytes);
return array(
'maxfiles' => EDITOR_UNLIMITED_FILES,
'maxbytes' => $maxbytes,
'trusttext'=> true,
'return_types'=> FILE_INTERNAL | FILE_EXTERNAL,
'subdirs' => file_area_contains_subdirs($context, 'mod_forum', 'post', $postid)
);
} | [
"public",
"static",
"function",
"editor_options",
"(",
"context_module",
"$",
"context",
",",
"$",
"postid",
")",
"{",
"global",
"$",
"COURSE",
",",
"$",
"PAGE",
",",
"$",
"CFG",
";",
"// TODO: add max files and max size support",
"$",
"maxbytes",
"=",
"get_user_max_upload_file_size",
"(",
"$",
"PAGE",
"->",
"context",
",",
"$",
"CFG",
"->",
"maxbytes",
",",
"$",
"COURSE",
"->",
"maxbytes",
")",
";",
"return",
"array",
"(",
"'maxfiles'",
"=>",
"EDITOR_UNLIMITED_FILES",
",",
"'maxbytes'",
"=>",
"$",
"maxbytes",
",",
"'trusttext'",
"=>",
"true",
",",
"'return_types'",
"=>",
"FILE_INTERNAL",
"|",
"FILE_EXTERNAL",
",",
"'subdirs'",
"=>",
"file_area_contains_subdirs",
"(",
"$",
"context",
",",
"'mod_forum'",
",",
"'post'",
",",
"$",
"postid",
")",
")",
";",
"}"
] | Returns the options array to use in forum text editor
@param context_module $context
@param int $postid post id, use null when adding new post
@return array | [
"Returns",
"the",
"options",
"array",
"to",
"use",
"in",
"forum",
"text",
"editor"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/post_form.php#L64-L75 |
214,091 | moodle/moodle | admin/roles/classes/preset.php | core_role_preset.send_export_xml | public static function send_export_xml($roleid) {
global $CFG, $DB;
require_once($CFG->libdir . '/filelib.php');
$role = $DB->get_record('role', array('id'=>$roleid), '*', MUST_EXIST);
if ($role->shortname) {
$filename = $role->shortname.'.xml';
} else {
$filename = 'role.xml';
}
$xml = self::get_export_xml($roleid);
send_file($xml, $filename, 0, false, true, true);
die();
} | php | public static function send_export_xml($roleid) {
global $CFG, $DB;
require_once($CFG->libdir . '/filelib.php');
$role = $DB->get_record('role', array('id'=>$roleid), '*', MUST_EXIST);
if ($role->shortname) {
$filename = $role->shortname.'.xml';
} else {
$filename = 'role.xml';
}
$xml = self::get_export_xml($roleid);
send_file($xml, $filename, 0, false, true, true);
die();
} | [
"public",
"static",
"function",
"send_export_xml",
"(",
"$",
"roleid",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"libdir",
".",
"'/filelib.php'",
")",
";",
"$",
"role",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'role'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"roleid",
")",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"if",
"(",
"$",
"role",
"->",
"shortname",
")",
"{",
"$",
"filename",
"=",
"$",
"role",
"->",
"shortname",
".",
"'.xml'",
";",
"}",
"else",
"{",
"$",
"filename",
"=",
"'role.xml'",
";",
"}",
"$",
"xml",
"=",
"self",
"::",
"get_export_xml",
"(",
"$",
"roleid",
")",
";",
"send_file",
"(",
"$",
"xml",
",",
"$",
"filename",
",",
"0",
",",
"false",
",",
"true",
",",
"true",
")",
";",
"die",
"(",
")",
";",
"}"
] | Send role export xml file to browser.
@param int $roleid
@return void does not return, send the file to output | [
"Send",
"role",
"export",
"xml",
"file",
"to",
"browser",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/roles/classes/preset.php#L42-L56 |
214,092 | moodle/moodle | admin/roles/classes/preset.php | core_role_preset.is_valid_preset | public static function is_valid_preset($xml) {
$dom = new DOMDocument();
if (!$dom->loadXML($xml)) {
return false;
} else {
$val = @$dom->schemaValidate(__DIR__.'/../role_schema.xml');
if (!$val) {
return false;
}
}
return true;
} | php | public static function is_valid_preset($xml) {
$dom = new DOMDocument();
if (!$dom->loadXML($xml)) {
return false;
} else {
$val = @$dom->schemaValidate(__DIR__.'/../role_schema.xml');
if (!$val) {
return false;
}
}
return true;
} | [
"public",
"static",
"function",
"is_valid_preset",
"(",
"$",
"xml",
")",
"{",
"$",
"dom",
"=",
"new",
"DOMDocument",
"(",
")",
";",
"if",
"(",
"!",
"$",
"dom",
"->",
"loadXML",
"(",
"$",
"xml",
")",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"$",
"val",
"=",
"@",
"$",
"dom",
"->",
"schemaValidate",
"(",
"__DIR__",
".",
"'/../role_schema.xml'",
")",
";",
"if",
"(",
"!",
"$",
"val",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Is this XML valid role preset?
@param string $xml
@return bool | [
"Is",
"this",
"XML",
"valid",
"role",
"preset?"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/roles/classes/preset.php#L141-L152 |
214,093 | moodle/moodle | lib/php-css-parser/Rule/Rule.php | Rule.addValue | public function addValue($mValue, $sType = ' ') {
if (!is_array($mValue)) {
$mValue = array($mValue);
}
if (!$this->mValue instanceof RuleValueList || $this->mValue->getListSeparator() !== $sType) {
$mCurrentValue = $this->mValue;
$this->mValue = new RuleValueList($sType, $this->iLineNo);
if ($mCurrentValue) {
$this->mValue->addListComponent($mCurrentValue);
}
}
foreach ($mValue as $mValueItem) {
$this->mValue->addListComponent($mValueItem);
}
} | php | public function addValue($mValue, $sType = ' ') {
if (!is_array($mValue)) {
$mValue = array($mValue);
}
if (!$this->mValue instanceof RuleValueList || $this->mValue->getListSeparator() !== $sType) {
$mCurrentValue = $this->mValue;
$this->mValue = new RuleValueList($sType, $this->iLineNo);
if ($mCurrentValue) {
$this->mValue->addListComponent($mCurrentValue);
}
}
foreach ($mValue as $mValueItem) {
$this->mValue->addListComponent($mValueItem);
}
} | [
"public",
"function",
"addValue",
"(",
"$",
"mValue",
",",
"$",
"sType",
"=",
"' '",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"mValue",
")",
")",
"{",
"$",
"mValue",
"=",
"array",
"(",
"$",
"mValue",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"mValue",
"instanceof",
"RuleValueList",
"||",
"$",
"this",
"->",
"mValue",
"->",
"getListSeparator",
"(",
")",
"!==",
"$",
"sType",
")",
"{",
"$",
"mCurrentValue",
"=",
"$",
"this",
"->",
"mValue",
";",
"$",
"this",
"->",
"mValue",
"=",
"new",
"RuleValueList",
"(",
"$",
"sType",
",",
"$",
"this",
"->",
"iLineNo",
")",
";",
"if",
"(",
"$",
"mCurrentValue",
")",
"{",
"$",
"this",
"->",
"mValue",
"->",
"addListComponent",
"(",
"$",
"mCurrentValue",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"mValue",
"as",
"$",
"mValueItem",
")",
"{",
"$",
"this",
"->",
"mValue",
"->",
"addListComponent",
"(",
"$",
"mValueItem",
")",
";",
"}",
"}"
] | Adds a value to the existing value. Value will be appended if a RuleValueList exists of the given type. Otherwise, the existing value will be wrapped by one. | [
"Adds",
"a",
"value",
"to",
"the",
"existing",
"value",
".",
"Value",
"will",
"be",
"appended",
"if",
"a",
"RuleValueList",
"exists",
"of",
"the",
"given",
"type",
".",
"Otherwise",
"the",
"existing",
"value",
"will",
"be",
"wrapped",
"by",
"one",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/php-css-parser/Rule/Rule.php#L119-L133 |
214,094 | moodle/moodle | admin/tool/mobile/classes/api.php | api.get_autologin_key | public static function get_autologin_key() {
global $USER;
// Delete previous keys.
delete_user_key('tool_mobile', $USER->id);
// Create a new key.
$iprestriction = getremoteaddr();
$validuntil = time() + self::LOGIN_KEY_TTL;
return create_user_key('tool_mobile', $USER->id, null, $iprestriction, $validuntil);
} | php | public static function get_autologin_key() {
global $USER;
// Delete previous keys.
delete_user_key('tool_mobile', $USER->id);
// Create a new key.
$iprestriction = getremoteaddr();
$validuntil = time() + self::LOGIN_KEY_TTL;
return create_user_key('tool_mobile', $USER->id, null, $iprestriction, $validuntil);
} | [
"public",
"static",
"function",
"get_autologin_key",
"(",
")",
"{",
"global",
"$",
"USER",
";",
"// Delete previous keys.",
"delete_user_key",
"(",
"'tool_mobile'",
",",
"$",
"USER",
"->",
"id",
")",
";",
"// Create a new key.",
"$",
"iprestriction",
"=",
"getremoteaddr",
"(",
")",
";",
"$",
"validuntil",
"=",
"time",
"(",
")",
"+",
"self",
"::",
"LOGIN_KEY_TTL",
";",
"return",
"create_user_key",
"(",
"'tool_mobile'",
",",
"$",
"USER",
"->",
"id",
",",
"null",
",",
"$",
"iprestriction",
",",
"$",
"validuntil",
")",
";",
"}"
] | Creates an auto-login key for the current user, this key is restricted by time and ip address.
@return string the key
@since Moodle 3.2 | [
"Creates",
"an",
"auto",
"-",
"login",
"key",
"for",
"the",
"current",
"user",
"this",
"key",
"is",
"restricted",
"by",
"time",
"and",
"ip",
"address",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/mobile/classes/api.php#L324-L333 |
214,095 | moodle/moodle | admin/tool/mobile/classes/api.php | api.get_potential_config_issues | public static function get_potential_config_issues() {
global $CFG;
require_once($CFG->dirroot . "/lib/filelib.php");
require_once($CFG->dirroot . '/message/lib.php');
$warnings = array();
$curl = new curl();
// Return certificate information and verify the certificate.
$curl->setopt(array('CURLOPT_CERTINFO' => 1, 'CURLOPT_SSL_VERIFYPEER' => true));
$httpswwwroot = str_replace('http:', 'https:', $CFG->wwwroot); // Force https url.
// Check https using a page not redirecting or returning exceptions.
$curl->head($httpswwwroot . "/$CFG->admin/tool/mobile/mobile.webmanifest.php");
$info = $curl->get_info();
// First of all, check the server certificate (if any).
if (empty($info['http_code']) or ($info['http_code'] >= 400)) {
$warnings[] = ['nohttpsformobilewarning', 'admin'];
} else {
// Check the certificate is not self-signed or has an untrusted-root.
// This may be weak in some scenarios (when the curl SSL verifier is outdated).
if (empty($info['certinfo'])) {
$warnings[] = ['selfsignedoruntrustedcertificatewarning', 'tool_mobile'];
} else {
$timenow = time();
$expectedissuer = null;
foreach ($info['certinfo'] as $cert) {
// Check if the signature algorithm is weak (Android won't work with SHA-1).
if ($cert['Signature Algorithm'] == 'sha1WithRSAEncryption' || $cert['Signature Algorithm'] == 'sha1WithRSA') {
$warnings[] = ['insecurealgorithmwarning', 'tool_mobile'];
}
// Check certificate start date.
if (strtotime($cert['Start date']) > $timenow) {
$warnings[] = ['invalidcertificatestartdatewarning', 'tool_mobile'];
}
// Check certificate end date.
if (strtotime($cert['Expire date']) < $timenow) {
$warnings[] = ['invalidcertificateexpiredatewarning', 'tool_mobile'];
}
// Check the chain.
if ($expectedissuer !== null) {
if ($expectedissuer !== $cert['Subject'] || $cert['Subject'] === $cert['Issuer']) {
$warnings[] = ['invalidcertificatechainwarning', 'tool_mobile'];
}
}
$expectedissuer = $cert['Issuer'];
}
}
}
// Now check typical configuration problems.
if ((int) $CFG->userquota === PHP_INT_MAX) {
// In old Moodle version was a text so was possible to have numeric values > PHP_INT_MAX.
$warnings[] = ['invaliduserquotawarning', 'tool_mobile'];
}
// Check ADOdb debug enabled.
if (get_config('auth_db', 'debugauthdb') || get_config('enrol_database', 'debugdb')) {
$warnings[] = ['adodbdebugwarning', 'tool_mobile'];
}
// Check display errors on.
if (!empty($CFG->debugdisplay)) {
$warnings[] = ['displayerrorswarning', 'tool_mobile'];
}
// Check mobile notifications.
$processors = get_message_processors();
$enabled = false;
foreach ($processors as $processor => $status) {
if ($processor == 'airnotifier' && $status->enabled) {
$enabled = true;
}
}
if (!$enabled) {
$warnings[] = ['mobilenotificationsdisabledwarning', 'tool_mobile'];
}
return $warnings;
} | php | public static function get_potential_config_issues() {
global $CFG;
require_once($CFG->dirroot . "/lib/filelib.php");
require_once($CFG->dirroot . '/message/lib.php');
$warnings = array();
$curl = new curl();
// Return certificate information and verify the certificate.
$curl->setopt(array('CURLOPT_CERTINFO' => 1, 'CURLOPT_SSL_VERIFYPEER' => true));
$httpswwwroot = str_replace('http:', 'https:', $CFG->wwwroot); // Force https url.
// Check https using a page not redirecting or returning exceptions.
$curl->head($httpswwwroot . "/$CFG->admin/tool/mobile/mobile.webmanifest.php");
$info = $curl->get_info();
// First of all, check the server certificate (if any).
if (empty($info['http_code']) or ($info['http_code'] >= 400)) {
$warnings[] = ['nohttpsformobilewarning', 'admin'];
} else {
// Check the certificate is not self-signed or has an untrusted-root.
// This may be weak in some scenarios (when the curl SSL verifier is outdated).
if (empty($info['certinfo'])) {
$warnings[] = ['selfsignedoruntrustedcertificatewarning', 'tool_mobile'];
} else {
$timenow = time();
$expectedissuer = null;
foreach ($info['certinfo'] as $cert) {
// Check if the signature algorithm is weak (Android won't work with SHA-1).
if ($cert['Signature Algorithm'] == 'sha1WithRSAEncryption' || $cert['Signature Algorithm'] == 'sha1WithRSA') {
$warnings[] = ['insecurealgorithmwarning', 'tool_mobile'];
}
// Check certificate start date.
if (strtotime($cert['Start date']) > $timenow) {
$warnings[] = ['invalidcertificatestartdatewarning', 'tool_mobile'];
}
// Check certificate end date.
if (strtotime($cert['Expire date']) < $timenow) {
$warnings[] = ['invalidcertificateexpiredatewarning', 'tool_mobile'];
}
// Check the chain.
if ($expectedissuer !== null) {
if ($expectedissuer !== $cert['Subject'] || $cert['Subject'] === $cert['Issuer']) {
$warnings[] = ['invalidcertificatechainwarning', 'tool_mobile'];
}
}
$expectedissuer = $cert['Issuer'];
}
}
}
// Now check typical configuration problems.
if ((int) $CFG->userquota === PHP_INT_MAX) {
// In old Moodle version was a text so was possible to have numeric values > PHP_INT_MAX.
$warnings[] = ['invaliduserquotawarning', 'tool_mobile'];
}
// Check ADOdb debug enabled.
if (get_config('auth_db', 'debugauthdb') || get_config('enrol_database', 'debugdb')) {
$warnings[] = ['adodbdebugwarning', 'tool_mobile'];
}
// Check display errors on.
if (!empty($CFG->debugdisplay)) {
$warnings[] = ['displayerrorswarning', 'tool_mobile'];
}
// Check mobile notifications.
$processors = get_message_processors();
$enabled = false;
foreach ($processors as $processor => $status) {
if ($processor == 'airnotifier' && $status->enabled) {
$enabled = true;
}
}
if (!$enabled) {
$warnings[] = ['mobilenotificationsdisabledwarning', 'tool_mobile'];
}
return $warnings;
} | [
"public",
"static",
"function",
"get_potential_config_issues",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"\"/lib/filelib.php\"",
")",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/message/lib.php'",
")",
";",
"$",
"warnings",
"=",
"array",
"(",
")",
";",
"$",
"curl",
"=",
"new",
"curl",
"(",
")",
";",
"// Return certificate information and verify the certificate.",
"$",
"curl",
"->",
"setopt",
"(",
"array",
"(",
"'CURLOPT_CERTINFO'",
"=>",
"1",
",",
"'CURLOPT_SSL_VERIFYPEER'",
"=>",
"true",
")",
")",
";",
"$",
"httpswwwroot",
"=",
"str_replace",
"(",
"'http:'",
",",
"'https:'",
",",
"$",
"CFG",
"->",
"wwwroot",
")",
";",
"// Force https url.",
"// Check https using a page not redirecting or returning exceptions.",
"$",
"curl",
"->",
"head",
"(",
"$",
"httpswwwroot",
".",
"\"/$CFG->admin/tool/mobile/mobile.webmanifest.php\"",
")",
";",
"$",
"info",
"=",
"$",
"curl",
"->",
"get_info",
"(",
")",
";",
"// First of all, check the server certificate (if any).",
"if",
"(",
"empty",
"(",
"$",
"info",
"[",
"'http_code'",
"]",
")",
"or",
"(",
"$",
"info",
"[",
"'http_code'",
"]",
">=",
"400",
")",
")",
"{",
"$",
"warnings",
"[",
"]",
"=",
"[",
"'nohttpsformobilewarning'",
",",
"'admin'",
"]",
";",
"}",
"else",
"{",
"// Check the certificate is not self-signed or has an untrusted-root.",
"// This may be weak in some scenarios (when the curl SSL verifier is outdated).",
"if",
"(",
"empty",
"(",
"$",
"info",
"[",
"'certinfo'",
"]",
")",
")",
"{",
"$",
"warnings",
"[",
"]",
"=",
"[",
"'selfsignedoruntrustedcertificatewarning'",
",",
"'tool_mobile'",
"]",
";",
"}",
"else",
"{",
"$",
"timenow",
"=",
"time",
"(",
")",
";",
"$",
"expectedissuer",
"=",
"null",
";",
"foreach",
"(",
"$",
"info",
"[",
"'certinfo'",
"]",
"as",
"$",
"cert",
")",
"{",
"// Check if the signature algorithm is weak (Android won't work with SHA-1).",
"if",
"(",
"$",
"cert",
"[",
"'Signature Algorithm'",
"]",
"==",
"'sha1WithRSAEncryption'",
"||",
"$",
"cert",
"[",
"'Signature Algorithm'",
"]",
"==",
"'sha1WithRSA'",
")",
"{",
"$",
"warnings",
"[",
"]",
"=",
"[",
"'insecurealgorithmwarning'",
",",
"'tool_mobile'",
"]",
";",
"}",
"// Check certificate start date.",
"if",
"(",
"strtotime",
"(",
"$",
"cert",
"[",
"'Start date'",
"]",
")",
">",
"$",
"timenow",
")",
"{",
"$",
"warnings",
"[",
"]",
"=",
"[",
"'invalidcertificatestartdatewarning'",
",",
"'tool_mobile'",
"]",
";",
"}",
"// Check certificate end date.",
"if",
"(",
"strtotime",
"(",
"$",
"cert",
"[",
"'Expire date'",
"]",
")",
"<",
"$",
"timenow",
")",
"{",
"$",
"warnings",
"[",
"]",
"=",
"[",
"'invalidcertificateexpiredatewarning'",
",",
"'tool_mobile'",
"]",
";",
"}",
"// Check the chain.",
"if",
"(",
"$",
"expectedissuer",
"!==",
"null",
")",
"{",
"if",
"(",
"$",
"expectedissuer",
"!==",
"$",
"cert",
"[",
"'Subject'",
"]",
"||",
"$",
"cert",
"[",
"'Subject'",
"]",
"===",
"$",
"cert",
"[",
"'Issuer'",
"]",
")",
"{",
"$",
"warnings",
"[",
"]",
"=",
"[",
"'invalidcertificatechainwarning'",
",",
"'tool_mobile'",
"]",
";",
"}",
"}",
"$",
"expectedissuer",
"=",
"$",
"cert",
"[",
"'Issuer'",
"]",
";",
"}",
"}",
"}",
"// Now check typical configuration problems.",
"if",
"(",
"(",
"int",
")",
"$",
"CFG",
"->",
"userquota",
"===",
"PHP_INT_MAX",
")",
"{",
"// In old Moodle version was a text so was possible to have numeric values > PHP_INT_MAX.",
"$",
"warnings",
"[",
"]",
"=",
"[",
"'invaliduserquotawarning'",
",",
"'tool_mobile'",
"]",
";",
"}",
"// Check ADOdb debug enabled.",
"if",
"(",
"get_config",
"(",
"'auth_db'",
",",
"'debugauthdb'",
")",
"||",
"get_config",
"(",
"'enrol_database'",
",",
"'debugdb'",
")",
")",
"{",
"$",
"warnings",
"[",
"]",
"=",
"[",
"'adodbdebugwarning'",
",",
"'tool_mobile'",
"]",
";",
"}",
"// Check display errors on.",
"if",
"(",
"!",
"empty",
"(",
"$",
"CFG",
"->",
"debugdisplay",
")",
")",
"{",
"$",
"warnings",
"[",
"]",
"=",
"[",
"'displayerrorswarning'",
",",
"'tool_mobile'",
"]",
";",
"}",
"// Check mobile notifications.",
"$",
"processors",
"=",
"get_message_processors",
"(",
")",
";",
"$",
"enabled",
"=",
"false",
";",
"foreach",
"(",
"$",
"processors",
"as",
"$",
"processor",
"=>",
"$",
"status",
")",
"{",
"if",
"(",
"$",
"processor",
"==",
"'airnotifier'",
"&&",
"$",
"status",
"->",
"enabled",
")",
"{",
"$",
"enabled",
"=",
"true",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"enabled",
")",
"{",
"$",
"warnings",
"[",
"]",
"=",
"[",
"'mobilenotificationsdisabledwarning'",
",",
"'tool_mobile'",
"]",
";",
"}",
"return",
"$",
"warnings",
";",
"}"
] | This function check the current site for potential configuration issues that may prevent the mobile app to work.
@return array list of potential issues
@since Moodle 3.4 | [
"This",
"function",
"check",
"the",
"current",
"site",
"for",
"potential",
"configuration",
"issues",
"that",
"may",
"prevent",
"the",
"mobile",
"app",
"to",
"work",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/mobile/classes/api.php#L479-L554 |
214,096 | moodle/moodle | grade/report/singleview/classes/local/ui/checkbox_attribute.php | checkbox_attribute.html | public function html() {
$attributes = array(
'type' => 'checkbox',
'name' => $this->name,
'value' => 1,
'id' => $this->name
);
// UCSB fixed user should not be able to override locked grade.
if ( $this->locked) {
$attributes['disabled'] = 'DISABLED';
}
$hidden = array(
'type' => 'hidden',
'name' => 'old' . $this->name
);
if ($this->ischecked) {
$attributes['checked'] = 'CHECKED';
$hidden['value'] = 1;
}
$type = "override";
if (preg_match("/^exclude/", $this->name)) {
$type = "exclude";
}
return (
html_writer::tag('label',
get_string($type . 'for', 'gradereport_singleview', $this->label),
array('for' => $this->name, 'class' => 'accesshide')) .
html_writer::empty_tag('input', $attributes) .
html_writer::empty_tag('input', $hidden)
);
} | php | public function html() {
$attributes = array(
'type' => 'checkbox',
'name' => $this->name,
'value' => 1,
'id' => $this->name
);
// UCSB fixed user should not be able to override locked grade.
if ( $this->locked) {
$attributes['disabled'] = 'DISABLED';
}
$hidden = array(
'type' => 'hidden',
'name' => 'old' . $this->name
);
if ($this->ischecked) {
$attributes['checked'] = 'CHECKED';
$hidden['value'] = 1;
}
$type = "override";
if (preg_match("/^exclude/", $this->name)) {
$type = "exclude";
}
return (
html_writer::tag('label',
get_string($type . 'for', 'gradereport_singleview', $this->label),
array('for' => $this->name, 'class' => 'accesshide')) .
html_writer::empty_tag('input', $attributes) .
html_writer::empty_tag('input', $hidden)
);
} | [
"public",
"function",
"html",
"(",
")",
"{",
"$",
"attributes",
"=",
"array",
"(",
"'type'",
"=>",
"'checkbox'",
",",
"'name'",
"=>",
"$",
"this",
"->",
"name",
",",
"'value'",
"=>",
"1",
",",
"'id'",
"=>",
"$",
"this",
"->",
"name",
")",
";",
"// UCSB fixed user should not be able to override locked grade.",
"if",
"(",
"$",
"this",
"->",
"locked",
")",
"{",
"$",
"attributes",
"[",
"'disabled'",
"]",
"=",
"'DISABLED'",
";",
"}",
"$",
"hidden",
"=",
"array",
"(",
"'type'",
"=>",
"'hidden'",
",",
"'name'",
"=>",
"'old'",
".",
"$",
"this",
"->",
"name",
")",
";",
"if",
"(",
"$",
"this",
"->",
"ischecked",
")",
"{",
"$",
"attributes",
"[",
"'checked'",
"]",
"=",
"'CHECKED'",
";",
"$",
"hidden",
"[",
"'value'",
"]",
"=",
"1",
";",
"}",
"$",
"type",
"=",
"\"override\"",
";",
"if",
"(",
"preg_match",
"(",
"\"/^exclude/\"",
",",
"$",
"this",
"->",
"name",
")",
")",
"{",
"$",
"type",
"=",
"\"exclude\"",
";",
"}",
"return",
"(",
"html_writer",
"::",
"tag",
"(",
"'label'",
",",
"get_string",
"(",
"$",
"type",
".",
"'for'",
",",
"'gradereport_singleview'",
",",
"$",
"this",
"->",
"label",
")",
",",
"array",
"(",
"'for'",
"=>",
"$",
"this",
"->",
"name",
",",
"'class'",
"=>",
"'accesshide'",
")",
")",
".",
"html_writer",
"::",
"empty_tag",
"(",
"'input'",
",",
"$",
"attributes",
")",
".",
"html_writer",
"::",
"empty_tag",
"(",
"'input'",
",",
"$",
"hidden",
")",
")",
";",
"}"
] | Generate the HTML
@return string | [
"Generate",
"the",
"HTML"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/ui/checkbox_attribute.php#L69-L105 |
214,097 | moodle/moodle | course/format/topics/backup/moodle2/restore_format_topics_plugin.class.php | restore_format_topics_plugin.need_restore_numsections | protected function need_restore_numsections() {
$backupinfo = $this->step->get_task()->get_info();
$backuprelease = $backupinfo->backup_release;
return version_compare($backuprelease, '3.3', 'lt');
} | php | protected function need_restore_numsections() {
$backupinfo = $this->step->get_task()->get_info();
$backuprelease = $backupinfo->backup_release;
return version_compare($backuprelease, '3.3', 'lt');
} | [
"protected",
"function",
"need_restore_numsections",
"(",
")",
"{",
"$",
"backupinfo",
"=",
"$",
"this",
"->",
"step",
"->",
"get_task",
"(",
")",
"->",
"get_info",
"(",
")",
";",
"$",
"backuprelease",
"=",
"$",
"backupinfo",
"->",
"backup_release",
";",
"return",
"version_compare",
"(",
"$",
"backuprelease",
",",
"'3.3'",
",",
"'lt'",
")",
";",
"}"
] | Checks if backup file was made on Moodle before 3.3 and we should respect the 'numsections'
and potential "orphaned" sections in the end of the course.
@return bool | [
"Checks",
"if",
"backup",
"file",
"was",
"made",
"on",
"Moodle",
"before",
"3",
".",
"3",
"and",
"we",
"should",
"respect",
"the",
"numsections",
"and",
"potential",
"orphaned",
"sections",
"in",
"the",
"end",
"of",
"the",
"course",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/topics/backup/moodle2/restore_format_topics_plugin.class.php#L49-L53 |
214,098 | moodle/moodle | auth/oauth2/classes/auth.php | auth.user_login | public function user_login($username, $password) {
$cached = $this->get_static_user_info();
if (empty($cached)) {
// This means we were called as part of a normal login flow - without using oauth.
return false;
}
$verifyusername = $cached['username'];
if ($verifyusername == $username) {
return true;
}
return false;
} | php | public function user_login($username, $password) {
$cached = $this->get_static_user_info();
if (empty($cached)) {
// This means we were called as part of a normal login flow - without using oauth.
return false;
}
$verifyusername = $cached['username'];
if ($verifyusername == $username) {
return true;
}
return false;
} | [
"public",
"function",
"user_login",
"(",
"$",
"username",
",",
"$",
"password",
")",
"{",
"$",
"cached",
"=",
"$",
"this",
"->",
"get_static_user_info",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"cached",
")",
")",
"{",
"// This means we were called as part of a normal login flow - without using oauth.",
"return",
"false",
";",
"}",
"$",
"verifyusername",
"=",
"$",
"cached",
"[",
"'username'",
"]",
";",
"if",
"(",
"$",
"verifyusername",
"==",
"$",
"username",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Returns true if the username and password work or don't exist and false
if the user exists and the password is wrong.
@param string $username The username
@param string $password The password
@return bool Authentication success or failure. | [
"Returns",
"true",
"if",
"the",
"username",
"and",
"password",
"work",
"or",
"don",
"t",
"exist",
"and",
"false",
"if",
"the",
"user",
"exists",
"and",
"the",
"password",
"is",
"wrong",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/oauth2/classes/auth.php#L75-L86 |
214,099 | moodle/moodle | auth/oauth2/classes/auth.php | auth.get_userinfo | public function get_userinfo($username) {
$cached = $this->get_static_user_info();
if (!empty($cached) && $cached['username'] == $username) {
return $cached;
}
return false;
} | php | public function get_userinfo($username) {
$cached = $this->get_static_user_info();
if (!empty($cached) && $cached['username'] == $username) {
return $cached;
}
return false;
} | [
"public",
"function",
"get_userinfo",
"(",
"$",
"username",
")",
"{",
"$",
"cached",
"=",
"$",
"this",
"->",
"get_static_user_info",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"cached",
")",
"&&",
"$",
"cached",
"[",
"'username'",
"]",
"==",
"$",
"username",
")",
"{",
"return",
"$",
"cached",
";",
"}",
"return",
"false",
";",
"}"
] | Return the userinfo from the oauth handshake. Will only be valid
for the logged in user.
@param string $username | [
"Return",
"the",
"userinfo",
"from",
"the",
"oauth",
"handshake",
".",
"Will",
"only",
"be",
"valid",
"for",
"the",
"logged",
"in",
"user",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/oauth2/classes/auth.php#L160-L166 |
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.