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
|
|---|---|---|---|---|---|---|---|---|---|---|---|
220,000
|
moodle/moodle
|
lib/classes/hub/publication.php
|
publication.unpublish
|
public static function unpublish($publication) {
global $DB;
// Unpublish the publication by web service.
api::unregister_courses($publication->hubcourseid);
// Delete the publication from the database.
$DB->delete_records('course_published', array('id' => $publication->id));
// Add confirmation message.
$course = get_course($publication->courseid);
$context = \context_course::instance($course->id);
$publication->courseshortname = format_string($course->shortname, true, ['context' => $context]);
$publication->hubname = 'Moodle.net';
\core\notification::add(get_string('courseunpublished', 'hub', $publication), \core\output\notification::NOTIFY_SUCCESS);
}
|
php
|
public static function unpublish($publication) {
global $DB;
// Unpublish the publication by web service.
api::unregister_courses($publication->hubcourseid);
// Delete the publication from the database.
$DB->delete_records('course_published', array('id' => $publication->id));
// Add confirmation message.
$course = get_course($publication->courseid);
$context = \context_course::instance($course->id);
$publication->courseshortname = format_string($course->shortname, true, ['context' => $context]);
$publication->hubname = 'Moodle.net';
\core\notification::add(get_string('courseunpublished', 'hub', $publication), \core\output\notification::NOTIFY_SUCCESS);
}
|
[
"public",
"static",
"function",
"unpublish",
"(",
"$",
"publication",
")",
"{",
"global",
"$",
"DB",
";",
"// Unpublish the publication by web service.",
"api",
"::",
"unregister_courses",
"(",
"$",
"publication",
"->",
"hubcourseid",
")",
";",
"// Delete the publication from the database.",
"$",
"DB",
"->",
"delete_records",
"(",
"'course_published'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"publication",
"->",
"id",
")",
")",
";",
"// Add confirmation message.",
"$",
"course",
"=",
"get_course",
"(",
"$",
"publication",
"->",
"courseid",
")",
";",
"$",
"context",
"=",
"\\",
"context_course",
"::",
"instance",
"(",
"$",
"course",
"->",
"id",
")",
";",
"$",
"publication",
"->",
"courseshortname",
"=",
"format_string",
"(",
"$",
"course",
"->",
"shortname",
",",
"true",
",",
"[",
"'context'",
"=>",
"$",
"context",
"]",
")",
";",
"$",
"publication",
"->",
"hubname",
"=",
"'Moodle.net'",
";",
"\\",
"core",
"\\",
"notification",
"::",
"add",
"(",
"get_string",
"(",
"'courseunpublished'",
",",
"'hub'",
",",
"$",
"publication",
")",
",",
"\\",
"core",
"\\",
"output",
"\\",
"notification",
"::",
"NOTIFY_SUCCESS",
")",
";",
"}"
] |
Unpublish a course
@param stdClass $publication
|
[
"Unpublish",
"a",
"course"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/hub/publication.php#L179-L193
|
220,001
|
moodle/moodle
|
lib/classes/hub/publication.php
|
publication.publish_course
|
public static function publish_course($courseinfo, $files) {
global $DB;
// Register course and get id of the course on moodle.net ($hubcourseid).
$courseid = $courseinfo->sitecourseid;
try {
$hubcourseid = api::register_course($courseinfo);
} catch (Exception $e) {
throw new moodle_exception('errorcoursepublish', 'hub',
new moodle_url('/course/view.php', array('id' => $courseid)), $e->getMessage());
}
// Insert/update publication record in the local DB.
$publication = $DB->get_record('course_published', array('hubcourseid' => $hubcourseid, 'huburl' => HUB_MOODLEORGHUBURL));
if ($publication) {
$DB->update_record('course_published', ['id' => $publication->id, 'timepublished' => time()]);
} else {
$publication = new stdClass();
$publication->huburl = HUB_MOODLEORGHUBURL;
$publication->courseid = $courseid;
$publication->hubcourseid = $hubcourseid;
$publication->enrollable = (int)$courseinfo->enrollable;
$publication->timepublished = time();
$publication->id = $DB->insert_record('course_published', $publication);
}
// Send screenshots.
if ($files) {
$screenshotnumber = $courseinfo->screenshots - count($files);
foreach ($files as $file) {
$screenshotnumber++;
api::add_screenshot($hubcourseid, $file, $screenshotnumber);
}
}
return $hubcourseid;
}
|
php
|
public static function publish_course($courseinfo, $files) {
global $DB;
// Register course and get id of the course on moodle.net ($hubcourseid).
$courseid = $courseinfo->sitecourseid;
try {
$hubcourseid = api::register_course($courseinfo);
} catch (Exception $e) {
throw new moodle_exception('errorcoursepublish', 'hub',
new moodle_url('/course/view.php', array('id' => $courseid)), $e->getMessage());
}
// Insert/update publication record in the local DB.
$publication = $DB->get_record('course_published', array('hubcourseid' => $hubcourseid, 'huburl' => HUB_MOODLEORGHUBURL));
if ($publication) {
$DB->update_record('course_published', ['id' => $publication->id, 'timepublished' => time()]);
} else {
$publication = new stdClass();
$publication->huburl = HUB_MOODLEORGHUBURL;
$publication->courseid = $courseid;
$publication->hubcourseid = $hubcourseid;
$publication->enrollable = (int)$courseinfo->enrollable;
$publication->timepublished = time();
$publication->id = $DB->insert_record('course_published', $publication);
}
// Send screenshots.
if ($files) {
$screenshotnumber = $courseinfo->screenshots - count($files);
foreach ($files as $file) {
$screenshotnumber++;
api::add_screenshot($hubcourseid, $file, $screenshotnumber);
}
}
return $hubcourseid;
}
|
[
"public",
"static",
"function",
"publish_course",
"(",
"$",
"courseinfo",
",",
"$",
"files",
")",
"{",
"global",
"$",
"DB",
";",
"// Register course and get id of the course on moodle.net ($hubcourseid).",
"$",
"courseid",
"=",
"$",
"courseinfo",
"->",
"sitecourseid",
";",
"try",
"{",
"$",
"hubcourseid",
"=",
"api",
"::",
"register_course",
"(",
"$",
"courseinfo",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'errorcoursepublish'",
",",
"'hub'",
",",
"new",
"moodle_url",
"(",
"'/course/view.php'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"courseid",
")",
")",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"// Insert/update publication record in the local DB.",
"$",
"publication",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'course_published'",
",",
"array",
"(",
"'hubcourseid'",
"=>",
"$",
"hubcourseid",
",",
"'huburl'",
"=>",
"HUB_MOODLEORGHUBURL",
")",
")",
";",
"if",
"(",
"$",
"publication",
")",
"{",
"$",
"DB",
"->",
"update_record",
"(",
"'course_published'",
",",
"[",
"'id'",
"=>",
"$",
"publication",
"->",
"id",
",",
"'timepublished'",
"=>",
"time",
"(",
")",
"]",
")",
";",
"}",
"else",
"{",
"$",
"publication",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"publication",
"->",
"huburl",
"=",
"HUB_MOODLEORGHUBURL",
";",
"$",
"publication",
"->",
"courseid",
"=",
"$",
"courseid",
";",
"$",
"publication",
"->",
"hubcourseid",
"=",
"$",
"hubcourseid",
";",
"$",
"publication",
"->",
"enrollable",
"=",
"(",
"int",
")",
"$",
"courseinfo",
"->",
"enrollable",
";",
"$",
"publication",
"->",
"timepublished",
"=",
"time",
"(",
")",
";",
"$",
"publication",
"->",
"id",
"=",
"$",
"DB",
"->",
"insert_record",
"(",
"'course_published'",
",",
"$",
"publication",
")",
";",
"}",
"// Send screenshots.",
"if",
"(",
"$",
"files",
")",
"{",
"$",
"screenshotnumber",
"=",
"$",
"courseinfo",
"->",
"screenshots",
"-",
"count",
"(",
"$",
"files",
")",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"screenshotnumber",
"++",
";",
"api",
"::",
"add_screenshot",
"(",
"$",
"hubcourseid",
",",
"$",
"file",
",",
"$",
"screenshotnumber",
")",
";",
"}",
"}",
"return",
"$",
"hubcourseid",
";",
"}"
] |
Publish a course
@param \stdClass $courseinfo
@param \stored_file[] $files
|
[
"Publish",
"a",
"course"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/hub/publication.php#L201-L238
|
220,002
|
moodle/moodle
|
lib/classes/hub/publication.php
|
publication.delete_all_publications
|
public static function delete_all_publications($advertised = true, $shared = true) {
global $DB;
if (!$advertised && !$shared) {
// Nothing to do.
return true;
}
$params = ['huburl' => HUB_MOODLEORGHUBURL];
if (!$advertised || !$shared) {
// Retrieve ONLY advertised or ONLY shared.
$params['enrollable'] = $advertised ? 1 : 0;
}
if (!$publications = $DB->get_records('course_published', $params)) {
// Nothing to unpublish.
return true;
}
foreach ($publications as $publication) {
$hubcourseids[] = $publication->hubcourseid;
}
api::unregister_courses($hubcourseids);
// Delete the published courses from local db.
$DB->delete_records('course_published', $params);
return true;
}
|
php
|
public static function delete_all_publications($advertised = true, $shared = true) {
global $DB;
if (!$advertised && !$shared) {
// Nothing to do.
return true;
}
$params = ['huburl' => HUB_MOODLEORGHUBURL];
if (!$advertised || !$shared) {
// Retrieve ONLY advertised or ONLY shared.
$params['enrollable'] = $advertised ? 1 : 0;
}
if (!$publications = $DB->get_records('course_published', $params)) {
// Nothing to unpublish.
return true;
}
foreach ($publications as $publication) {
$hubcourseids[] = $publication->hubcourseid;
}
api::unregister_courses($hubcourseids);
// Delete the published courses from local db.
$DB->delete_records('course_published', $params);
return true;
}
|
[
"public",
"static",
"function",
"delete_all_publications",
"(",
"$",
"advertised",
"=",
"true",
",",
"$",
"shared",
"=",
"true",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"!",
"$",
"advertised",
"&&",
"!",
"$",
"shared",
")",
"{",
"// Nothing to do.",
"return",
"true",
";",
"}",
"$",
"params",
"=",
"[",
"'huburl'",
"=>",
"HUB_MOODLEORGHUBURL",
"]",
";",
"if",
"(",
"!",
"$",
"advertised",
"||",
"!",
"$",
"shared",
")",
"{",
"// Retrieve ONLY advertised or ONLY shared.",
"$",
"params",
"[",
"'enrollable'",
"]",
"=",
"$",
"advertised",
"?",
"1",
":",
"0",
";",
"}",
"if",
"(",
"!",
"$",
"publications",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'course_published'",
",",
"$",
"params",
")",
")",
"{",
"// Nothing to unpublish.",
"return",
"true",
";",
"}",
"foreach",
"(",
"$",
"publications",
"as",
"$",
"publication",
")",
"{",
"$",
"hubcourseids",
"[",
"]",
"=",
"$",
"publication",
"->",
"hubcourseid",
";",
"}",
"api",
"::",
"unregister_courses",
"(",
"$",
"hubcourseids",
")",
";",
"// Delete the published courses from local db.",
"$",
"DB",
"->",
"delete_records",
"(",
"'course_published'",
",",
"$",
"params",
")",
";",
"return",
"true",
";",
"}"
] |
Delete all publications
@param int $advertised search for advertised courses
@param int $shared search for shared courses
@throws moodle_exception
|
[
"Delete",
"all",
"publications"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/hub/publication.php#L247-L275
|
220,003
|
moodle/moodle
|
lib/classes/hub/publication.php
|
publication.educational_level_options
|
public static function educational_level_options($any = false) {
$options = array();
if ($any) {
$options['all'] = get_string('any');
}
$options[self::HUB_EDULEVEL_PRIMARY] = get_string('edulevelprimary', 'hub');
$options[self::HUB_EDULEVEL_SECONDARY] = get_string('edulevelsecondary', 'hub');
$options[self::HUB_EDULEVEL_TERTIARY] = get_string('eduleveltertiary', 'hub');
$options[self::HUB_EDULEVEL_GOVERNMENT] = get_string('edulevelgovernment', 'hub');
$options[self::HUB_EDULEVEL_ASSOCIATION] = get_string('edulevelassociation', 'hub');
$options[self::HUB_EDULEVEL_CORPORATE] = get_string('edulevelcorporate', 'hub');
$options[self::HUB_EDULEVEL_OTHER] = get_string('edulevelother', 'hub');
return $options;
}
|
php
|
public static function educational_level_options($any = false) {
$options = array();
if ($any) {
$options['all'] = get_string('any');
}
$options[self::HUB_EDULEVEL_PRIMARY] = get_string('edulevelprimary', 'hub');
$options[self::HUB_EDULEVEL_SECONDARY] = get_string('edulevelsecondary', 'hub');
$options[self::HUB_EDULEVEL_TERTIARY] = get_string('eduleveltertiary', 'hub');
$options[self::HUB_EDULEVEL_GOVERNMENT] = get_string('edulevelgovernment', 'hub');
$options[self::HUB_EDULEVEL_ASSOCIATION] = get_string('edulevelassociation', 'hub');
$options[self::HUB_EDULEVEL_CORPORATE] = get_string('edulevelcorporate', 'hub');
$options[self::HUB_EDULEVEL_OTHER] = get_string('edulevelother', 'hub');
return $options;
}
|
[
"public",
"static",
"function",
"educational_level_options",
"(",
"$",
"any",
"=",
"false",
")",
"{",
"$",
"options",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"any",
")",
"{",
"$",
"options",
"[",
"'all'",
"]",
"=",
"get_string",
"(",
"'any'",
")",
";",
"}",
"$",
"options",
"[",
"self",
"::",
"HUB_EDULEVEL_PRIMARY",
"]",
"=",
"get_string",
"(",
"'edulevelprimary'",
",",
"'hub'",
")",
";",
"$",
"options",
"[",
"self",
"::",
"HUB_EDULEVEL_SECONDARY",
"]",
"=",
"get_string",
"(",
"'edulevelsecondary'",
",",
"'hub'",
")",
";",
"$",
"options",
"[",
"self",
"::",
"HUB_EDULEVEL_TERTIARY",
"]",
"=",
"get_string",
"(",
"'eduleveltertiary'",
",",
"'hub'",
")",
";",
"$",
"options",
"[",
"self",
"::",
"HUB_EDULEVEL_GOVERNMENT",
"]",
"=",
"get_string",
"(",
"'edulevelgovernment'",
",",
"'hub'",
")",
";",
"$",
"options",
"[",
"self",
"::",
"HUB_EDULEVEL_ASSOCIATION",
"]",
"=",
"get_string",
"(",
"'edulevelassociation'",
",",
"'hub'",
")",
";",
"$",
"options",
"[",
"self",
"::",
"HUB_EDULEVEL_CORPORATE",
"]",
"=",
"get_string",
"(",
"'edulevelcorporate'",
",",
"'hub'",
")",
";",
"$",
"options",
"[",
"self",
"::",
"HUB_EDULEVEL_OTHER",
"]",
"=",
"get_string",
"(",
"'edulevelother'",
",",
"'hub'",
")",
";",
"return",
"$",
"options",
";",
"}"
] |
List of available educational levels
@param bool $any add option for "Any" (for search forms)
@return array
|
[
"List",
"of",
"available",
"educational",
"levels"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/hub/publication.php#L293-L306
|
220,004
|
moodle/moodle
|
lib/classes/hub/publication.php
|
publication.audience_options
|
public static function audience_options($any = false) {
$options = array();
if ($any) {
$options['all'] = get_string('any');
}
$options[self::HUB_AUDIENCE_EDUCATORS] = get_string('audienceeducators', 'hub');
$options[self::HUB_AUDIENCE_STUDENTS] = get_string('audiencestudents', 'hub');
$options[self::HUB_AUDIENCE_ADMINS] = get_string('audienceadmins', 'hub');
return $options;
}
|
php
|
public static function audience_options($any = false) {
$options = array();
if ($any) {
$options['all'] = get_string('any');
}
$options[self::HUB_AUDIENCE_EDUCATORS] = get_string('audienceeducators', 'hub');
$options[self::HUB_AUDIENCE_STUDENTS] = get_string('audiencestudents', 'hub');
$options[self::HUB_AUDIENCE_ADMINS] = get_string('audienceadmins', 'hub');
return $options;
}
|
[
"public",
"static",
"function",
"audience_options",
"(",
"$",
"any",
"=",
"false",
")",
"{",
"$",
"options",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"any",
")",
"{",
"$",
"options",
"[",
"'all'",
"]",
"=",
"get_string",
"(",
"'any'",
")",
";",
"}",
"$",
"options",
"[",
"self",
"::",
"HUB_AUDIENCE_EDUCATORS",
"]",
"=",
"get_string",
"(",
"'audienceeducators'",
",",
"'hub'",
")",
";",
"$",
"options",
"[",
"self",
"::",
"HUB_AUDIENCE_STUDENTS",
"]",
"=",
"get_string",
"(",
"'audiencestudents'",
",",
"'hub'",
")",
";",
"$",
"options",
"[",
"self",
"::",
"HUB_AUDIENCE_ADMINS",
"]",
"=",
"get_string",
"(",
"'audienceadmins'",
",",
"'hub'",
")",
";",
"return",
"$",
"options",
";",
"}"
] |
List of available audience options
@param bool $any add option for "Any" (for search forms)
@return array
|
[
"List",
"of",
"available",
"audience",
"options"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/hub/publication.php#L314-L323
|
220,005
|
moodle/moodle
|
lib/classes/hub/publication.php
|
publication.search
|
public static function search($search, $downloadable, $options) {
try {
return api::get_courses($search, $downloadable, !$downloadable, $options);
} catch (moodle_exception $e) {
\core\notification::add(get_string('errorcourselisting', 'block_community', $e->getMessage()),
\core\output\notification::NOTIFY_ERROR);
return [[], 0];
}
}
|
php
|
public static function search($search, $downloadable, $options) {
try {
return api::get_courses($search, $downloadable, !$downloadable, $options);
} catch (moodle_exception $e) {
\core\notification::add(get_string('errorcourselisting', 'block_community', $e->getMessage()),
\core\output\notification::NOTIFY_ERROR);
return [[], 0];
}
}
|
[
"public",
"static",
"function",
"search",
"(",
"$",
"search",
",",
"$",
"downloadable",
",",
"$",
"options",
")",
"{",
"try",
"{",
"return",
"api",
"::",
"get_courses",
"(",
"$",
"search",
",",
"$",
"downloadable",
",",
"!",
"$",
"downloadable",
",",
"$",
"options",
")",
";",
"}",
"catch",
"(",
"moodle_exception",
"$",
"e",
")",
"{",
"\\",
"core",
"\\",
"notification",
"::",
"add",
"(",
"get_string",
"(",
"'errorcourselisting'",
",",
"'block_community'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
",",
"\\",
"core",
"\\",
"output",
"\\",
"notification",
"::",
"NOTIFY_ERROR",
")",
";",
"return",
"[",
"[",
"]",
",",
"0",
"]",
";",
"}",
"}"
] |
Search for courses
For the list of fields returned for each course see {@link communication::get_courses}
@param string $search search string
@param bool $downloadable true - return downloadable courses, false - return enrollable courses
@param array|\stdClass $options other options from the list of allowed options:
'ids', 'sitecourseids', 'coverage', 'licenceshortname', 'subject', 'audience',
'educationallevel', 'language', 'orderby', 'givememore', 'allsitecourses'
@return array of two elements: [$courses, $coursetotal]
|
[
"Search",
"for",
"courses"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/hub/publication.php#L337-L345
|
220,006
|
moodle/moodle
|
lib/classes/hub/publication.php
|
publication.get_published_course
|
public static function get_published_course($publication) {
try {
list($courses, $unused) = api::get_courses('', !$publication->enrollable,
$publication->enrollable, ['ids' => [$publication->hubcourseid], 'allsitecourses' => 1]);
return reset($courses);
} catch (\Exception $e) {
\core\notification::add(get_string('errorcourseinfo', 'hub', $e->getMessage()),
\core\output\notification::NOTIFY_ERROR);
}
return null;
}
|
php
|
public static function get_published_course($publication) {
try {
list($courses, $unused) = api::get_courses('', !$publication->enrollable,
$publication->enrollable, ['ids' => [$publication->hubcourseid], 'allsitecourses' => 1]);
return reset($courses);
} catch (\Exception $e) {
\core\notification::add(get_string('errorcourseinfo', 'hub', $e->getMessage()),
\core\output\notification::NOTIFY_ERROR);
}
return null;
}
|
[
"public",
"static",
"function",
"get_published_course",
"(",
"$",
"publication",
")",
"{",
"try",
"{",
"list",
"(",
"$",
"courses",
",",
"$",
"unused",
")",
"=",
"api",
"::",
"get_courses",
"(",
"''",
",",
"!",
"$",
"publication",
"->",
"enrollable",
",",
"$",
"publication",
"->",
"enrollable",
",",
"[",
"'ids'",
"=>",
"[",
"$",
"publication",
"->",
"hubcourseid",
"]",
",",
"'allsitecourses'",
"=>",
"1",
"]",
")",
";",
"return",
"reset",
"(",
"$",
"courses",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"\\",
"core",
"\\",
"notification",
"::",
"add",
"(",
"get_string",
"(",
"'errorcourseinfo'",
",",
"'hub'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
",",
"\\",
"core",
"\\",
"output",
"\\",
"notification",
"::",
"NOTIFY_ERROR",
")",
";",
"}",
"return",
"null",
";",
"}"
] |
Retrieves information about published course
For the list of fields returned for the course see {@link communication::get_courses}
@param stdClass $publication
@return array|null
|
[
"Retrieves",
"information",
"about",
"published",
"course"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/hub/publication.php#L355-L365
|
220,007
|
moodle/moodle
|
lib/classes/hub/publication.php
|
publication.download_course_backup
|
public static function download_course_backup($hubcourseid, $coursename) {
global $CFG, $USER;
require_once($CFG->libdir . "/filelib.php");
$backuptempdir = make_backup_temp_directory('');
$filename = md5(time() . '-' . $hubcourseid . '-'. $USER->id . '-'. random_string(20));
$path = $backuptempdir.'/'.$filename.".mbz";
api::download_course_backup($hubcourseid, $path);
$fs = get_file_storage();
$record = new stdClass();
$record->contextid = context_user::instance($USER->id)->id;
$record->component = 'user';
$record->filearea = 'private';
$record->itemid = 0;
$record->filename = urlencode($coursename).'_'.time().".mbz";
$record->filepath = '/downloaded_backup/';
if (!$fs->file_exists($record->contextid, $record->component,
$record->filearea, 0, $record->filepath, $record->filename)) {
$fs->create_file_from_pathname($record, $path);
}
return [$record->filepath . $record->filename, $filename];
}
|
php
|
public static function download_course_backup($hubcourseid, $coursename) {
global $CFG, $USER;
require_once($CFG->libdir . "/filelib.php");
$backuptempdir = make_backup_temp_directory('');
$filename = md5(time() . '-' . $hubcourseid . '-'. $USER->id . '-'. random_string(20));
$path = $backuptempdir.'/'.$filename.".mbz";
api::download_course_backup($hubcourseid, $path);
$fs = get_file_storage();
$record = new stdClass();
$record->contextid = context_user::instance($USER->id)->id;
$record->component = 'user';
$record->filearea = 'private';
$record->itemid = 0;
$record->filename = urlencode($coursename).'_'.time().".mbz";
$record->filepath = '/downloaded_backup/';
if (!$fs->file_exists($record->contextid, $record->component,
$record->filearea, 0, $record->filepath, $record->filename)) {
$fs->create_file_from_pathname($record, $path);
}
return [$record->filepath . $record->filename, $filename];
}
|
[
"public",
"static",
"function",
"download_course_backup",
"(",
"$",
"hubcourseid",
",",
"$",
"coursename",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"USER",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"libdir",
".",
"\"/filelib.php\"",
")",
";",
"$",
"backuptempdir",
"=",
"make_backup_temp_directory",
"(",
"''",
")",
";",
"$",
"filename",
"=",
"md5",
"(",
"time",
"(",
")",
".",
"'-'",
".",
"$",
"hubcourseid",
".",
"'-'",
".",
"$",
"USER",
"->",
"id",
".",
"'-'",
".",
"random_string",
"(",
"20",
")",
")",
";",
"$",
"path",
"=",
"$",
"backuptempdir",
".",
"'/'",
".",
"$",
"filename",
".",
"\".mbz\"",
";",
"api",
"::",
"download_course_backup",
"(",
"$",
"hubcourseid",
",",
"$",
"path",
")",
";",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"$",
"record",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"record",
"->",
"contextid",
"=",
"context_user",
"::",
"instance",
"(",
"$",
"USER",
"->",
"id",
")",
"->",
"id",
";",
"$",
"record",
"->",
"component",
"=",
"'user'",
";",
"$",
"record",
"->",
"filearea",
"=",
"'private'",
";",
"$",
"record",
"->",
"itemid",
"=",
"0",
";",
"$",
"record",
"->",
"filename",
"=",
"urlencode",
"(",
"$",
"coursename",
")",
".",
"'_'",
".",
"time",
"(",
")",
".",
"\".mbz\"",
";",
"$",
"record",
"->",
"filepath",
"=",
"'/downloaded_backup/'",
";",
"if",
"(",
"!",
"$",
"fs",
"->",
"file_exists",
"(",
"$",
"record",
"->",
"contextid",
",",
"$",
"record",
"->",
"component",
",",
"$",
"record",
"->",
"filearea",
",",
"0",
",",
"$",
"record",
"->",
"filepath",
",",
"$",
"record",
"->",
"filename",
")",
")",
"{",
"$",
"fs",
"->",
"create_file_from_pathname",
"(",
"$",
"record",
",",
"$",
"path",
")",
";",
"}",
"return",
"[",
"$",
"record",
"->",
"filepath",
".",
"$",
"record",
"->",
"filename",
",",
"$",
"filename",
"]",
";",
"}"
] |
Downloads course backup and stores it in the user private files
@param int $hubcourseid
@param string $coursename
@return array
|
[
"Downloads",
"course",
"backup",
"and",
"stores",
"it",
"in",
"the",
"user",
"private",
"files"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/hub/publication.php#L374-L398
|
220,008
|
moodle/moodle
|
mod/forum/classes/local/builders/exported_posts.php
|
exported_posts.build
|
public function build(
stdClass $user,
array $forums,
array $discussions,
array $posts
) : array {
// Format the forums and discussion to make them more easily accessed later.
$forums = array_reduce($forums, function($carry, $forum) {
$carry[$forum->get_id()] = $forum;
return $carry;
}, []);
$discussions = array_reduce($discussions, function($carry, $discussion) {
$carry[$discussion->get_id()] = $discussion;
return $carry;
}, []);
// Group the posts by discussion and forum so that we can load the resources in
// batches to improve performance.
$groupedposts = $this->group_posts_by_discussion($forums, $discussions, $posts);
// Load all of the resources we need in order to export the posts.
$authorsbyid = $this->get_authors_for_posts($posts);
$authorcontextids = $this->get_author_context_ids(array_keys($authorsbyid));
$attachmentsbypostid = $this->get_attachments_for_posts($groupedposts);
$groupsbycourseandauthorid = $this->get_author_groups_from_posts($groupedposts);
$tagsbypostid = $this->get_tags_from_posts($posts);
$ratingbypostid = $this->get_ratings_from_posts($user, $groupedposts);
$readreceiptcollectionbyforumid = $this->get_read_receipts_from_posts($user, $groupedposts);
$exportedposts = [];
// Export each set of posts per discussion because it's the largest chunks we can
// break them into due to constraints on capability checks.
foreach ($groupedposts as $grouping) {
[
'forum' => $forum,
'discussion' => $discussion,
'posts' => $groupedposts
] = $grouping;
$forumid = $forum->get_id();
$courseid = $forum->get_course_record()->id;
$postsexporter = $this->exporterfactory->get_posts_exporter(
$user,
$forum,
$discussion,
$groupedposts,
$authorsbyid,
$authorcontextids,
$attachmentsbypostid,
$groupsbycourseandauthorid[$courseid],
$readreceiptcollectionbyforumid[$forumid] ?? null,
$tagsbypostid,
$ratingbypostid,
true
);
['posts' => $exportedgroupedposts] = (array) $postsexporter->export($this->renderer);
$exportedposts = array_merge($exportedposts, $exportedgroupedposts);
}
if (count($forums) == 1 && count($discussions) == 1) {
// All of the posts belong to a single discussion in a single forum so
// the exported order will match the given $posts array.
return $exportedposts;
} else {
// Since we grouped the posts by discussion and forum the ordering of the
// exported posts may be different to the given $posts array so we should
// sort it back into the correct order for the caller.
return $this->sort_exported_posts($posts, $exportedposts);
}
}
|
php
|
public function build(
stdClass $user,
array $forums,
array $discussions,
array $posts
) : array {
// Format the forums and discussion to make them more easily accessed later.
$forums = array_reduce($forums, function($carry, $forum) {
$carry[$forum->get_id()] = $forum;
return $carry;
}, []);
$discussions = array_reduce($discussions, function($carry, $discussion) {
$carry[$discussion->get_id()] = $discussion;
return $carry;
}, []);
// Group the posts by discussion and forum so that we can load the resources in
// batches to improve performance.
$groupedposts = $this->group_posts_by_discussion($forums, $discussions, $posts);
// Load all of the resources we need in order to export the posts.
$authorsbyid = $this->get_authors_for_posts($posts);
$authorcontextids = $this->get_author_context_ids(array_keys($authorsbyid));
$attachmentsbypostid = $this->get_attachments_for_posts($groupedposts);
$groupsbycourseandauthorid = $this->get_author_groups_from_posts($groupedposts);
$tagsbypostid = $this->get_tags_from_posts($posts);
$ratingbypostid = $this->get_ratings_from_posts($user, $groupedposts);
$readreceiptcollectionbyforumid = $this->get_read_receipts_from_posts($user, $groupedposts);
$exportedposts = [];
// Export each set of posts per discussion because it's the largest chunks we can
// break them into due to constraints on capability checks.
foreach ($groupedposts as $grouping) {
[
'forum' => $forum,
'discussion' => $discussion,
'posts' => $groupedposts
] = $grouping;
$forumid = $forum->get_id();
$courseid = $forum->get_course_record()->id;
$postsexporter = $this->exporterfactory->get_posts_exporter(
$user,
$forum,
$discussion,
$groupedposts,
$authorsbyid,
$authorcontextids,
$attachmentsbypostid,
$groupsbycourseandauthorid[$courseid],
$readreceiptcollectionbyforumid[$forumid] ?? null,
$tagsbypostid,
$ratingbypostid,
true
);
['posts' => $exportedgroupedposts] = (array) $postsexporter->export($this->renderer);
$exportedposts = array_merge($exportedposts, $exportedgroupedposts);
}
if (count($forums) == 1 && count($discussions) == 1) {
// All of the posts belong to a single discussion in a single forum so
// the exported order will match the given $posts array.
return $exportedposts;
} else {
// Since we grouped the posts by discussion and forum the ordering of the
// exported posts may be different to the given $posts array so we should
// sort it back into the correct order for the caller.
return $this->sort_exported_posts($posts, $exportedposts);
}
}
|
[
"public",
"function",
"build",
"(",
"stdClass",
"$",
"user",
",",
"array",
"$",
"forums",
",",
"array",
"$",
"discussions",
",",
"array",
"$",
"posts",
")",
":",
"array",
"{",
"// Format the forums and discussion to make them more easily accessed later.",
"$",
"forums",
"=",
"array_reduce",
"(",
"$",
"forums",
",",
"function",
"(",
"$",
"carry",
",",
"$",
"forum",
")",
"{",
"$",
"carry",
"[",
"$",
"forum",
"->",
"get_id",
"(",
")",
"]",
"=",
"$",
"forum",
";",
"return",
"$",
"carry",
";",
"}",
",",
"[",
"]",
")",
";",
"$",
"discussions",
"=",
"array_reduce",
"(",
"$",
"discussions",
",",
"function",
"(",
"$",
"carry",
",",
"$",
"discussion",
")",
"{",
"$",
"carry",
"[",
"$",
"discussion",
"->",
"get_id",
"(",
")",
"]",
"=",
"$",
"discussion",
";",
"return",
"$",
"carry",
";",
"}",
",",
"[",
"]",
")",
";",
"// Group the posts by discussion and forum so that we can load the resources in",
"// batches to improve performance.",
"$",
"groupedposts",
"=",
"$",
"this",
"->",
"group_posts_by_discussion",
"(",
"$",
"forums",
",",
"$",
"discussions",
",",
"$",
"posts",
")",
";",
"// Load all of the resources we need in order to export the posts.",
"$",
"authorsbyid",
"=",
"$",
"this",
"->",
"get_authors_for_posts",
"(",
"$",
"posts",
")",
";",
"$",
"authorcontextids",
"=",
"$",
"this",
"->",
"get_author_context_ids",
"(",
"array_keys",
"(",
"$",
"authorsbyid",
")",
")",
";",
"$",
"attachmentsbypostid",
"=",
"$",
"this",
"->",
"get_attachments_for_posts",
"(",
"$",
"groupedposts",
")",
";",
"$",
"groupsbycourseandauthorid",
"=",
"$",
"this",
"->",
"get_author_groups_from_posts",
"(",
"$",
"groupedposts",
")",
";",
"$",
"tagsbypostid",
"=",
"$",
"this",
"->",
"get_tags_from_posts",
"(",
"$",
"posts",
")",
";",
"$",
"ratingbypostid",
"=",
"$",
"this",
"->",
"get_ratings_from_posts",
"(",
"$",
"user",
",",
"$",
"groupedposts",
")",
";",
"$",
"readreceiptcollectionbyforumid",
"=",
"$",
"this",
"->",
"get_read_receipts_from_posts",
"(",
"$",
"user",
",",
"$",
"groupedposts",
")",
";",
"$",
"exportedposts",
"=",
"[",
"]",
";",
"// Export each set of posts per discussion because it's the largest chunks we can",
"// break them into due to constraints on capability checks.",
"foreach",
"(",
"$",
"groupedposts",
"as",
"$",
"grouping",
")",
"{",
"[",
"'forum'",
"=>",
"$",
"forum",
",",
"'discussion'",
"=>",
"$",
"discussion",
",",
"'posts'",
"=>",
"$",
"groupedposts",
"]",
"=",
"$",
"grouping",
";",
"$",
"forumid",
"=",
"$",
"forum",
"->",
"get_id",
"(",
")",
";",
"$",
"courseid",
"=",
"$",
"forum",
"->",
"get_course_record",
"(",
")",
"->",
"id",
";",
"$",
"postsexporter",
"=",
"$",
"this",
"->",
"exporterfactory",
"->",
"get_posts_exporter",
"(",
"$",
"user",
",",
"$",
"forum",
",",
"$",
"discussion",
",",
"$",
"groupedposts",
",",
"$",
"authorsbyid",
",",
"$",
"authorcontextids",
",",
"$",
"attachmentsbypostid",
",",
"$",
"groupsbycourseandauthorid",
"[",
"$",
"courseid",
"]",
",",
"$",
"readreceiptcollectionbyforumid",
"[",
"$",
"forumid",
"]",
"??",
"null",
",",
"$",
"tagsbypostid",
",",
"$",
"ratingbypostid",
",",
"true",
")",
";",
"[",
"'posts'",
"=>",
"$",
"exportedgroupedposts",
"]",
"=",
"(",
"array",
")",
"$",
"postsexporter",
"->",
"export",
"(",
"$",
"this",
"->",
"renderer",
")",
";",
"$",
"exportedposts",
"=",
"array_merge",
"(",
"$",
"exportedposts",
",",
"$",
"exportedgroupedposts",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"forums",
")",
"==",
"1",
"&&",
"count",
"(",
"$",
"discussions",
")",
"==",
"1",
")",
"{",
"// All of the posts belong to a single discussion in a single forum so",
"// the exported order will match the given $posts array.",
"return",
"$",
"exportedposts",
";",
"}",
"else",
"{",
"// Since we grouped the posts by discussion and forum the ordering of the",
"// exported posts may be different to the given $posts array so we should",
"// sort it back into the correct order for the caller.",
"return",
"$",
"this",
"->",
"sort_exported_posts",
"(",
"$",
"posts",
",",
"$",
"exportedposts",
")",
";",
"}",
"}"
] |
Build the exported posts for a given set of forums, discussions, and posts.
This will typically be used for a list of posts in the same discussion/forum however
it does support exporting any arbitrary list of posts as long as the caller also provides
a unique list of all discussions for the list of posts and all forums for the list of discussions.
Increasing the number of different forums being processed will increase the processing time
due to processing multiple contexts (for things like capabilities, files, etc). The code attempts
to load the additional resources as efficiently as possible but there is no way around some of
the additional overhead.
Note: Some posts will be removed as part of the build process according to capabilities.
A one-to-one mapping should not be expected.
@param stdClass $user The user to export the posts for.
@param forum_entity[] $forums A list of all forums that each of the $discussions belong to
@param discussion_entity[] $discussions A list of all discussions that each of the $posts belong to
@param post_entity[] $posts The list of posts to export.
@return stdClass[] List of exported posts in the same order as the $posts array.
|
[
"Build",
"the",
"exported",
"posts",
"for",
"a",
"given",
"set",
"of",
"forums",
"discussions",
"and",
"posts",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/builders/exported_posts.php#L119-L187
|
220,009
|
moodle/moodle
|
mod/forum/classes/local/builders/exported_posts.php
|
exported_posts.group_posts_by_discussion
|
private function group_posts_by_discussion(array $forums, array $discussions, array $posts) : array {
return array_reduce($posts, function($carry, $post) use ($forums, $discussions) {
$discussionid = $post->get_discussion_id();
if (!isset($discussions[$discussionid])) {
throw new moodle_exception('Unable to find discussion with id ' . $discussionid);
}
if (isset($carry[$discussionid])) {
$carry[$discussionid]['posts'][] = $post;
} else {
$discussion = $discussions[$discussionid];
$forumid = $discussion->get_forum_id();
if (!isset($forums[$forumid])) {
throw new moodle_exception('Unable to find forum with id ' . $forumid);
}
$carry[$discussionid] = [
'forum' => $forums[$forumid],
'discussion' => $discussions[$discussionid],
'posts' => [$post]
];
}
return $carry;
}, []);
}
|
php
|
private function group_posts_by_discussion(array $forums, array $discussions, array $posts) : array {
return array_reduce($posts, function($carry, $post) use ($forums, $discussions) {
$discussionid = $post->get_discussion_id();
if (!isset($discussions[$discussionid])) {
throw new moodle_exception('Unable to find discussion with id ' . $discussionid);
}
if (isset($carry[$discussionid])) {
$carry[$discussionid]['posts'][] = $post;
} else {
$discussion = $discussions[$discussionid];
$forumid = $discussion->get_forum_id();
if (!isset($forums[$forumid])) {
throw new moodle_exception('Unable to find forum with id ' . $forumid);
}
$carry[$discussionid] = [
'forum' => $forums[$forumid],
'discussion' => $discussions[$discussionid],
'posts' => [$post]
];
}
return $carry;
}, []);
}
|
[
"private",
"function",
"group_posts_by_discussion",
"(",
"array",
"$",
"forums",
",",
"array",
"$",
"discussions",
",",
"array",
"$",
"posts",
")",
":",
"array",
"{",
"return",
"array_reduce",
"(",
"$",
"posts",
",",
"function",
"(",
"$",
"carry",
",",
"$",
"post",
")",
"use",
"(",
"$",
"forums",
",",
"$",
"discussions",
")",
"{",
"$",
"discussionid",
"=",
"$",
"post",
"->",
"get_discussion_id",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"discussions",
"[",
"$",
"discussionid",
"]",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'Unable to find discussion with id '",
".",
"$",
"discussionid",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"carry",
"[",
"$",
"discussionid",
"]",
")",
")",
"{",
"$",
"carry",
"[",
"$",
"discussionid",
"]",
"[",
"'posts'",
"]",
"[",
"]",
"=",
"$",
"post",
";",
"}",
"else",
"{",
"$",
"discussion",
"=",
"$",
"discussions",
"[",
"$",
"discussionid",
"]",
";",
"$",
"forumid",
"=",
"$",
"discussion",
"->",
"get_forum_id",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"forums",
"[",
"$",
"forumid",
"]",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'Unable to find forum with id '",
".",
"$",
"forumid",
")",
";",
"}",
"$",
"carry",
"[",
"$",
"discussionid",
"]",
"=",
"[",
"'forum'",
"=>",
"$",
"forums",
"[",
"$",
"forumid",
"]",
",",
"'discussion'",
"=>",
"$",
"discussions",
"[",
"$",
"discussionid",
"]",
",",
"'posts'",
"=>",
"[",
"$",
"post",
"]",
"]",
";",
"}",
"return",
"$",
"carry",
";",
"}",
",",
"[",
"]",
")",
";",
"}"
] |
Group the posts by which discussion they belong to in order for them to be processed
in chunks by the exporting.
Returns a list of groups where each group has a forum, discussion, and list of posts.
E.g.
[
[
'forum' => <forum_entity>,
'discussion' => <discussion_entity>,
'posts' => [
<post_entity in discussion>,
<post_entity in discussion>,
<post_entity in discussion>
]
]
]
@param forum_entity[] $forums A list of all forums that each of the $discussions belong to, indexed by id.
@param discussion_entity[] $discussions A list of all discussions that each of the $posts belong to, indexed by id.
@param post_entity[] $posts The list of posts to process.
@return array List of grouped posts. Each group has a discussion, forum, and posts.
|
[
"Group",
"the",
"posts",
"by",
"which",
"discussion",
"they",
"belong",
"to",
"in",
"order",
"for",
"them",
"to",
"be",
"processed",
"in",
"chunks",
"by",
"the",
"exporting",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/builders/exported_posts.php#L212-L238
|
220,010
|
moodle/moodle
|
mod/forum/classes/local/builders/exported_posts.php
|
exported_posts.get_attachments_for_posts
|
private function get_attachments_for_posts(array $groupedposts) : array {
$attachmentsbypostid = [];
$postattachmentvault = $this->vaultfactory->get_post_attachment_vault();
$postsbyforum = array_reduce($groupedposts, function($carry, $grouping) {
['forum' => $forum, 'posts' => $posts] = $grouping;
$forumid = $forum->get_id();
if (!isset($carry[$forumid])) {
$carry[$forumid] = [
'forum' => $forum,
'posts' => []
];
}
$carry[$forumid]['posts'] = array_merge($carry[$forumid]['posts'], $posts);
return $carry;
}, []);
foreach ($postsbyforum as $grouping) {
['forum' => $forum, 'posts' => $posts] = $grouping;
$attachments = $postattachmentvault->get_attachments_for_posts($forum->get_context(), $posts);
// Have to loop in order to maintain the correct indexes since they are numeric.
foreach ($attachments as $postid => $attachment) {
$attachmentsbypostid[$postid] = $attachment;
}
}
return $attachmentsbypostid;
}
|
php
|
private function get_attachments_for_posts(array $groupedposts) : array {
$attachmentsbypostid = [];
$postattachmentvault = $this->vaultfactory->get_post_attachment_vault();
$postsbyforum = array_reduce($groupedposts, function($carry, $grouping) {
['forum' => $forum, 'posts' => $posts] = $grouping;
$forumid = $forum->get_id();
if (!isset($carry[$forumid])) {
$carry[$forumid] = [
'forum' => $forum,
'posts' => []
];
}
$carry[$forumid]['posts'] = array_merge($carry[$forumid]['posts'], $posts);
return $carry;
}, []);
foreach ($postsbyforum as $grouping) {
['forum' => $forum, 'posts' => $posts] = $grouping;
$attachments = $postattachmentvault->get_attachments_for_posts($forum->get_context(), $posts);
// Have to loop in order to maintain the correct indexes since they are numeric.
foreach ($attachments as $postid => $attachment) {
$attachmentsbypostid[$postid] = $attachment;
}
}
return $attachmentsbypostid;
}
|
[
"private",
"function",
"get_attachments_for_posts",
"(",
"array",
"$",
"groupedposts",
")",
":",
"array",
"{",
"$",
"attachmentsbypostid",
"=",
"[",
"]",
";",
"$",
"postattachmentvault",
"=",
"$",
"this",
"->",
"vaultfactory",
"->",
"get_post_attachment_vault",
"(",
")",
";",
"$",
"postsbyforum",
"=",
"array_reduce",
"(",
"$",
"groupedposts",
",",
"function",
"(",
"$",
"carry",
",",
"$",
"grouping",
")",
"{",
"[",
"'forum'",
"=>",
"$",
"forum",
",",
"'posts'",
"=>",
"$",
"posts",
"]",
"=",
"$",
"grouping",
";",
"$",
"forumid",
"=",
"$",
"forum",
"->",
"get_id",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"carry",
"[",
"$",
"forumid",
"]",
")",
")",
"{",
"$",
"carry",
"[",
"$",
"forumid",
"]",
"=",
"[",
"'forum'",
"=>",
"$",
"forum",
",",
"'posts'",
"=>",
"[",
"]",
"]",
";",
"}",
"$",
"carry",
"[",
"$",
"forumid",
"]",
"[",
"'posts'",
"]",
"=",
"array_merge",
"(",
"$",
"carry",
"[",
"$",
"forumid",
"]",
"[",
"'posts'",
"]",
",",
"$",
"posts",
")",
";",
"return",
"$",
"carry",
";",
"}",
",",
"[",
"]",
")",
";",
"foreach",
"(",
"$",
"postsbyforum",
"as",
"$",
"grouping",
")",
"{",
"[",
"'forum'",
"=>",
"$",
"forum",
",",
"'posts'",
"=>",
"$",
"posts",
"]",
"=",
"$",
"grouping",
";",
"$",
"attachments",
"=",
"$",
"postattachmentvault",
"->",
"get_attachments_for_posts",
"(",
"$",
"forum",
"->",
"get_context",
"(",
")",
",",
"$",
"posts",
")",
";",
"// Have to loop in order to maintain the correct indexes since they are numeric.",
"foreach",
"(",
"$",
"attachments",
"as",
"$",
"postid",
"=>",
"$",
"attachment",
")",
"{",
"$",
"attachmentsbypostid",
"[",
"$",
"postid",
"]",
"=",
"$",
"attachment",
";",
"}",
"}",
"return",
"$",
"attachmentsbypostid",
";",
"}"
] |
Load the list of all attachments for the posts. The list of attachments will be
indexed by the post id.
@param array $groupedposts List of posts grouped by discussions.
@return stored_file[]
|
[
"Load",
"the",
"list",
"of",
"all",
"attachments",
"for",
"the",
"posts",
".",
"The",
"list",
"of",
"attachments",
"will",
"be",
"indexed",
"by",
"the",
"post",
"id",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/builders/exported_posts.php#L271-L300
|
220,011
|
moodle/moodle
|
mod/forum/classes/local/builders/exported_posts.php
|
exported_posts.get_author_groups_from_posts
|
private function get_author_groups_from_posts(array $groupedposts) : array {
$groupsbyauthorid = [];
$authoridsbycourseid = [];
// Get the unique list of author ids for each course in the grouped
// posts. Grouping by course is the largest grouping we can achieve.
foreach ($groupedposts as $grouping) {
['forum' => $forum, 'posts' => $posts] = $grouping;
$course = $forum->get_course_record();
$courseid = $course->id;
if (!isset($authoridsbycourseid[$courseid])) {
$coursemodule = $forum->get_course_module_record();
$authoridsbycourseid[$courseid] = [
'groupingid' => $coursemodule->groupingid,
'authorids' => []
];
}
$authorids = array_map(function($post) {
return $post->get_author_id();
}, $posts);
foreach ($authorids as $authorid) {
$authoridsbycourseid[$courseid]['authorids'][$authorid] = $authorid;
}
}
// Load each set of groups per course.
foreach ($authoridsbycourseid as $courseid => $values) {
['groupingid' => $groupingid, 'authorids' => $authorids] = $values;
$authorgroups = groups_get_all_groups(
$courseid,
array_keys($authorids),
$groupingid,
'g.*, gm.id, gm.groupid, gm.userid'
);
if (!isset($groupsbyauthorid[$courseid])) {
$groupsbyauthorid[$courseid] = [];
}
foreach ($authorgroups as $group) {
// Clean up data returned from groups_get_all_groups.
$userid = $group->userid;
$groupid = $group->groupid;
unset($group->userid);
unset($group->groupid);
$group->id = $groupid;
if (!isset($groupsbyauthorid[$courseid][$userid])) {
$groupsbyauthorid[$courseid][$userid] = [];
}
$groupsbyauthorid[$courseid][$userid][] = $group;
}
}
return $groupsbyauthorid;
}
|
php
|
private function get_author_groups_from_posts(array $groupedposts) : array {
$groupsbyauthorid = [];
$authoridsbycourseid = [];
// Get the unique list of author ids for each course in the grouped
// posts. Grouping by course is the largest grouping we can achieve.
foreach ($groupedposts as $grouping) {
['forum' => $forum, 'posts' => $posts] = $grouping;
$course = $forum->get_course_record();
$courseid = $course->id;
if (!isset($authoridsbycourseid[$courseid])) {
$coursemodule = $forum->get_course_module_record();
$authoridsbycourseid[$courseid] = [
'groupingid' => $coursemodule->groupingid,
'authorids' => []
];
}
$authorids = array_map(function($post) {
return $post->get_author_id();
}, $posts);
foreach ($authorids as $authorid) {
$authoridsbycourseid[$courseid]['authorids'][$authorid] = $authorid;
}
}
// Load each set of groups per course.
foreach ($authoridsbycourseid as $courseid => $values) {
['groupingid' => $groupingid, 'authorids' => $authorids] = $values;
$authorgroups = groups_get_all_groups(
$courseid,
array_keys($authorids),
$groupingid,
'g.*, gm.id, gm.groupid, gm.userid'
);
if (!isset($groupsbyauthorid[$courseid])) {
$groupsbyauthorid[$courseid] = [];
}
foreach ($authorgroups as $group) {
// Clean up data returned from groups_get_all_groups.
$userid = $group->userid;
$groupid = $group->groupid;
unset($group->userid);
unset($group->groupid);
$group->id = $groupid;
if (!isset($groupsbyauthorid[$courseid][$userid])) {
$groupsbyauthorid[$courseid][$userid] = [];
}
$groupsbyauthorid[$courseid][$userid][] = $group;
}
}
return $groupsbyauthorid;
}
|
[
"private",
"function",
"get_author_groups_from_posts",
"(",
"array",
"$",
"groupedposts",
")",
":",
"array",
"{",
"$",
"groupsbyauthorid",
"=",
"[",
"]",
";",
"$",
"authoridsbycourseid",
"=",
"[",
"]",
";",
"// Get the unique list of author ids for each course in the grouped",
"// posts. Grouping by course is the largest grouping we can achieve.",
"foreach",
"(",
"$",
"groupedposts",
"as",
"$",
"grouping",
")",
"{",
"[",
"'forum'",
"=>",
"$",
"forum",
",",
"'posts'",
"=>",
"$",
"posts",
"]",
"=",
"$",
"grouping",
";",
"$",
"course",
"=",
"$",
"forum",
"->",
"get_course_record",
"(",
")",
";",
"$",
"courseid",
"=",
"$",
"course",
"->",
"id",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"authoridsbycourseid",
"[",
"$",
"courseid",
"]",
")",
")",
"{",
"$",
"coursemodule",
"=",
"$",
"forum",
"->",
"get_course_module_record",
"(",
")",
";",
"$",
"authoridsbycourseid",
"[",
"$",
"courseid",
"]",
"=",
"[",
"'groupingid'",
"=>",
"$",
"coursemodule",
"->",
"groupingid",
",",
"'authorids'",
"=>",
"[",
"]",
"]",
";",
"}",
"$",
"authorids",
"=",
"array_map",
"(",
"function",
"(",
"$",
"post",
")",
"{",
"return",
"$",
"post",
"->",
"get_author_id",
"(",
")",
";",
"}",
",",
"$",
"posts",
")",
";",
"foreach",
"(",
"$",
"authorids",
"as",
"$",
"authorid",
")",
"{",
"$",
"authoridsbycourseid",
"[",
"$",
"courseid",
"]",
"[",
"'authorids'",
"]",
"[",
"$",
"authorid",
"]",
"=",
"$",
"authorid",
";",
"}",
"}",
"// Load each set of groups per course.",
"foreach",
"(",
"$",
"authoridsbycourseid",
"as",
"$",
"courseid",
"=>",
"$",
"values",
")",
"{",
"[",
"'groupingid'",
"=>",
"$",
"groupingid",
",",
"'authorids'",
"=>",
"$",
"authorids",
"]",
"=",
"$",
"values",
";",
"$",
"authorgroups",
"=",
"groups_get_all_groups",
"(",
"$",
"courseid",
",",
"array_keys",
"(",
"$",
"authorids",
")",
",",
"$",
"groupingid",
",",
"'g.*, gm.id, gm.groupid, gm.userid'",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"groupsbyauthorid",
"[",
"$",
"courseid",
"]",
")",
")",
"{",
"$",
"groupsbyauthorid",
"[",
"$",
"courseid",
"]",
"=",
"[",
"]",
";",
"}",
"foreach",
"(",
"$",
"authorgroups",
"as",
"$",
"group",
")",
"{",
"// Clean up data returned from groups_get_all_groups.",
"$",
"userid",
"=",
"$",
"group",
"->",
"userid",
";",
"$",
"groupid",
"=",
"$",
"group",
"->",
"groupid",
";",
"unset",
"(",
"$",
"group",
"->",
"userid",
")",
";",
"unset",
"(",
"$",
"group",
"->",
"groupid",
")",
";",
"$",
"group",
"->",
"id",
"=",
"$",
"groupid",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"groupsbyauthorid",
"[",
"$",
"courseid",
"]",
"[",
"$",
"userid",
"]",
")",
")",
"{",
"$",
"groupsbyauthorid",
"[",
"$",
"courseid",
"]",
"[",
"$",
"userid",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"groupsbyauthorid",
"[",
"$",
"courseid",
"]",
"[",
"$",
"userid",
"]",
"[",
"]",
"=",
"$",
"group",
";",
"}",
"}",
"return",
"$",
"groupsbyauthorid",
";",
"}"
] |
Get the groups for each author of the given posts.
The results are grouped by course and then author id because the groups are
contextually related to the course, e.g. a single author can be part of two different
sets of groups in two different courses.
@param array $groupedposts List of posts grouped by discussions.
@return array List of groups indexed by forum id and then author id.
|
[
"Get",
"the",
"groups",
"for",
"each",
"author",
"of",
"the",
"given",
"posts",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/builders/exported_posts.php#L312-L372
|
220,012
|
moodle/moodle
|
mod/forum/classes/local/builders/exported_posts.php
|
exported_posts.get_tags_from_posts
|
private function get_tags_from_posts(array $posts) : array {
$postids = array_map(function($post) {
return $post->get_id();
}, $posts);
return core_tag_tag::get_items_tags('mod_forum', 'forum_posts', $postids);
}
|
php
|
private function get_tags_from_posts(array $posts) : array {
$postids = array_map(function($post) {
return $post->get_id();
}, $posts);
return core_tag_tag::get_items_tags('mod_forum', 'forum_posts', $postids);
}
|
[
"private",
"function",
"get_tags_from_posts",
"(",
"array",
"$",
"posts",
")",
":",
"array",
"{",
"$",
"postids",
"=",
"array_map",
"(",
"function",
"(",
"$",
"post",
")",
"{",
"return",
"$",
"post",
"->",
"get_id",
"(",
")",
";",
"}",
",",
"$",
"posts",
")",
";",
"return",
"core_tag_tag",
"::",
"get_items_tags",
"(",
"'mod_forum'",
",",
"'forum_posts'",
",",
"$",
"postids",
")",
";",
"}"
] |
Get the list of tags for each of the posts. The tags will be returned in an
array indexed by the post id.
@param post_entity[] $posts The list of posts to load tags for.
@return array Sets of tags indexed by post id.
|
[
"Get",
"the",
"list",
"of",
"tags",
"for",
"each",
"of",
"the",
"posts",
".",
"The",
"tags",
"will",
"be",
"returned",
"in",
"an",
"array",
"indexed",
"by",
"the",
"post",
"id",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/builders/exported_posts.php#L381-L386
|
220,013
|
moodle/moodle
|
mod/forum/classes/local/builders/exported_posts.php
|
exported_posts.get_ratings_from_posts
|
private function get_ratings_from_posts(stdClass $user, array $groupedposts) {
$ratingsbypostid = [];
$postsdatamapper = $this->legacydatamapperfactory->get_post_data_mapper();
$postsbyforum = array_reduce($groupedposts, function($carry, $grouping) {
['forum' => $forum, 'posts' => $posts] = $grouping;
$forumid = $forum->get_id();
if (!isset($carry[$forumid])) {
$carry[$forumid] = [
'forum' => $forum,
'posts' => []
];
}
$carry[$forumid]['posts'] = array_merge($carry[$forumid]['posts'], $posts);
return $carry;
}, []);
foreach ($postsbyforum as $grouping) {
['forum' => $forum, 'posts' => $posts] = $grouping;
if (!$forum->has_rating_aggregate()) {
continue;
}
$items = $postsdatamapper->to_legacy_objects($posts);
$ratingoptions = (object) [
'context' => $forum->get_context(),
'component' => 'mod_forum',
'ratingarea' => 'post',
'items' => $items,
'aggregate' => $forum->get_rating_aggregate(),
'scaleid' => $forum->get_scale(),
'userid' => $user->id,
'assesstimestart' => $forum->get_assess_time_start(),
'assesstimefinish' => $forum->get_assess_time_finish()
];
$rm = $this->ratingmanager;
$items = $rm->get_ratings($ratingoptions);
foreach ($items as $item) {
$ratingsbypostid[$item->id] = empty($item->rating) ? null : $item->rating;
}
}
return $ratingsbypostid;
}
|
php
|
private function get_ratings_from_posts(stdClass $user, array $groupedposts) {
$ratingsbypostid = [];
$postsdatamapper = $this->legacydatamapperfactory->get_post_data_mapper();
$postsbyforum = array_reduce($groupedposts, function($carry, $grouping) {
['forum' => $forum, 'posts' => $posts] = $grouping;
$forumid = $forum->get_id();
if (!isset($carry[$forumid])) {
$carry[$forumid] = [
'forum' => $forum,
'posts' => []
];
}
$carry[$forumid]['posts'] = array_merge($carry[$forumid]['posts'], $posts);
return $carry;
}, []);
foreach ($postsbyforum as $grouping) {
['forum' => $forum, 'posts' => $posts] = $grouping;
if (!$forum->has_rating_aggregate()) {
continue;
}
$items = $postsdatamapper->to_legacy_objects($posts);
$ratingoptions = (object) [
'context' => $forum->get_context(),
'component' => 'mod_forum',
'ratingarea' => 'post',
'items' => $items,
'aggregate' => $forum->get_rating_aggregate(),
'scaleid' => $forum->get_scale(),
'userid' => $user->id,
'assesstimestart' => $forum->get_assess_time_start(),
'assesstimefinish' => $forum->get_assess_time_finish()
];
$rm = $this->ratingmanager;
$items = $rm->get_ratings($ratingoptions);
foreach ($items as $item) {
$ratingsbypostid[$item->id] = empty($item->rating) ? null : $item->rating;
}
}
return $ratingsbypostid;
}
|
[
"private",
"function",
"get_ratings_from_posts",
"(",
"stdClass",
"$",
"user",
",",
"array",
"$",
"groupedposts",
")",
"{",
"$",
"ratingsbypostid",
"=",
"[",
"]",
";",
"$",
"postsdatamapper",
"=",
"$",
"this",
"->",
"legacydatamapperfactory",
"->",
"get_post_data_mapper",
"(",
")",
";",
"$",
"postsbyforum",
"=",
"array_reduce",
"(",
"$",
"groupedposts",
",",
"function",
"(",
"$",
"carry",
",",
"$",
"grouping",
")",
"{",
"[",
"'forum'",
"=>",
"$",
"forum",
",",
"'posts'",
"=>",
"$",
"posts",
"]",
"=",
"$",
"grouping",
";",
"$",
"forumid",
"=",
"$",
"forum",
"->",
"get_id",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"carry",
"[",
"$",
"forumid",
"]",
")",
")",
"{",
"$",
"carry",
"[",
"$",
"forumid",
"]",
"=",
"[",
"'forum'",
"=>",
"$",
"forum",
",",
"'posts'",
"=>",
"[",
"]",
"]",
";",
"}",
"$",
"carry",
"[",
"$",
"forumid",
"]",
"[",
"'posts'",
"]",
"=",
"array_merge",
"(",
"$",
"carry",
"[",
"$",
"forumid",
"]",
"[",
"'posts'",
"]",
",",
"$",
"posts",
")",
";",
"return",
"$",
"carry",
";",
"}",
",",
"[",
"]",
")",
";",
"foreach",
"(",
"$",
"postsbyforum",
"as",
"$",
"grouping",
")",
"{",
"[",
"'forum'",
"=>",
"$",
"forum",
",",
"'posts'",
"=>",
"$",
"posts",
"]",
"=",
"$",
"grouping",
";",
"if",
"(",
"!",
"$",
"forum",
"->",
"has_rating_aggregate",
"(",
")",
")",
"{",
"continue",
";",
"}",
"$",
"items",
"=",
"$",
"postsdatamapper",
"->",
"to_legacy_objects",
"(",
"$",
"posts",
")",
";",
"$",
"ratingoptions",
"=",
"(",
"object",
")",
"[",
"'context'",
"=>",
"$",
"forum",
"->",
"get_context",
"(",
")",
",",
"'component'",
"=>",
"'mod_forum'",
",",
"'ratingarea'",
"=>",
"'post'",
",",
"'items'",
"=>",
"$",
"items",
",",
"'aggregate'",
"=>",
"$",
"forum",
"->",
"get_rating_aggregate",
"(",
")",
",",
"'scaleid'",
"=>",
"$",
"forum",
"->",
"get_scale",
"(",
")",
",",
"'userid'",
"=>",
"$",
"user",
"->",
"id",
",",
"'assesstimestart'",
"=>",
"$",
"forum",
"->",
"get_assess_time_start",
"(",
")",
",",
"'assesstimefinish'",
"=>",
"$",
"forum",
"->",
"get_assess_time_finish",
"(",
")",
"]",
";",
"$",
"rm",
"=",
"$",
"this",
"->",
"ratingmanager",
";",
"$",
"items",
"=",
"$",
"rm",
"->",
"get_ratings",
"(",
"$",
"ratingoptions",
")",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"item",
")",
"{",
"$",
"ratingsbypostid",
"[",
"$",
"item",
"->",
"id",
"]",
"=",
"empty",
"(",
"$",
"item",
"->",
"rating",
")",
"?",
"null",
":",
"$",
"item",
"->",
"rating",
";",
"}",
"}",
"return",
"$",
"ratingsbypostid",
";",
"}"
] |
Get the list of ratings for each post. The ratings are returned in an array
indexed by the post id.
@param stdClass $user The user viewing the ratings.
@param array $groupedposts List of posts grouped by discussions.
@return array Sets of ratings indexed by post id.
|
[
"Get",
"the",
"list",
"of",
"ratings",
"for",
"each",
"post",
".",
"The",
"ratings",
"are",
"returned",
"in",
"an",
"array",
"indexed",
"by",
"the",
"post",
"id",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/builders/exported_posts.php#L396-L443
|
220,014
|
moodle/moodle
|
mod/forum/classes/local/builders/exported_posts.php
|
exported_posts.get_read_receipts_from_posts
|
private function get_read_receipts_from_posts(stdClass $user, array $groupedposts) {
$forumdatamapper = $this->legacydatamapperfactory->get_forum_data_mapper();
$trackedforums = [];
$trackedpostids = [];
foreach ($groupedposts as $group) {
['forum' => $forum, 'posts' => $posts] = $group;
$forumid = $forum->get_id();
if (!isset($trackedforums[$forumid])) {
$forumrecord = $forumdatamapper->to_legacy_object($forum);
$trackedforums[$forumid] = forum_tp_is_tracked($forumrecord, $user);
}
if ($trackedforums[$forumid]) {
foreach ($posts as $post) {
$trackedpostids[] = $post->get_id();
}
}
}
if (empty($trackedpostids)) {
return [];
}
// We can just load a single receipt collection for all tracked posts.
$receiptvault = $this->vaultfactory->get_post_read_receipt_collection_vault();
$readreceiptcollection = $receiptvault->get_from_user_id_and_post_ids($user->id, $trackedpostids);
$receiptsbyforumid = [];
// Assign the collection to all forums that are tracked.
foreach ($trackedforums as $forumid => $tracked) {
if ($tracked) {
$receiptsbyforumid[$forumid] = $readreceiptcollection;
}
}
return $receiptsbyforumid;
}
|
php
|
private function get_read_receipts_from_posts(stdClass $user, array $groupedposts) {
$forumdatamapper = $this->legacydatamapperfactory->get_forum_data_mapper();
$trackedforums = [];
$trackedpostids = [];
foreach ($groupedposts as $group) {
['forum' => $forum, 'posts' => $posts] = $group;
$forumid = $forum->get_id();
if (!isset($trackedforums[$forumid])) {
$forumrecord = $forumdatamapper->to_legacy_object($forum);
$trackedforums[$forumid] = forum_tp_is_tracked($forumrecord, $user);
}
if ($trackedforums[$forumid]) {
foreach ($posts as $post) {
$trackedpostids[] = $post->get_id();
}
}
}
if (empty($trackedpostids)) {
return [];
}
// We can just load a single receipt collection for all tracked posts.
$receiptvault = $this->vaultfactory->get_post_read_receipt_collection_vault();
$readreceiptcollection = $receiptvault->get_from_user_id_and_post_ids($user->id, $trackedpostids);
$receiptsbyforumid = [];
// Assign the collection to all forums that are tracked.
foreach ($trackedforums as $forumid => $tracked) {
if ($tracked) {
$receiptsbyforumid[$forumid] = $readreceiptcollection;
}
}
return $receiptsbyforumid;
}
|
[
"private",
"function",
"get_read_receipts_from_posts",
"(",
"stdClass",
"$",
"user",
",",
"array",
"$",
"groupedposts",
")",
"{",
"$",
"forumdatamapper",
"=",
"$",
"this",
"->",
"legacydatamapperfactory",
"->",
"get_forum_data_mapper",
"(",
")",
";",
"$",
"trackedforums",
"=",
"[",
"]",
";",
"$",
"trackedpostids",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"groupedposts",
"as",
"$",
"group",
")",
"{",
"[",
"'forum'",
"=>",
"$",
"forum",
",",
"'posts'",
"=>",
"$",
"posts",
"]",
"=",
"$",
"group",
";",
"$",
"forumid",
"=",
"$",
"forum",
"->",
"get_id",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"trackedforums",
"[",
"$",
"forumid",
"]",
")",
")",
"{",
"$",
"forumrecord",
"=",
"$",
"forumdatamapper",
"->",
"to_legacy_object",
"(",
"$",
"forum",
")",
";",
"$",
"trackedforums",
"[",
"$",
"forumid",
"]",
"=",
"forum_tp_is_tracked",
"(",
"$",
"forumrecord",
",",
"$",
"user",
")",
";",
"}",
"if",
"(",
"$",
"trackedforums",
"[",
"$",
"forumid",
"]",
")",
"{",
"foreach",
"(",
"$",
"posts",
"as",
"$",
"post",
")",
"{",
"$",
"trackedpostids",
"[",
"]",
"=",
"$",
"post",
"->",
"get_id",
"(",
")",
";",
"}",
"}",
"}",
"if",
"(",
"empty",
"(",
"$",
"trackedpostids",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"// We can just load a single receipt collection for all tracked posts.",
"$",
"receiptvault",
"=",
"$",
"this",
"->",
"vaultfactory",
"->",
"get_post_read_receipt_collection_vault",
"(",
")",
";",
"$",
"readreceiptcollection",
"=",
"$",
"receiptvault",
"->",
"get_from_user_id_and_post_ids",
"(",
"$",
"user",
"->",
"id",
",",
"$",
"trackedpostids",
")",
";",
"$",
"receiptsbyforumid",
"=",
"[",
"]",
";",
"// Assign the collection to all forums that are tracked.",
"foreach",
"(",
"$",
"trackedforums",
"as",
"$",
"forumid",
"=>",
"$",
"tracked",
")",
"{",
"if",
"(",
"$",
"tracked",
")",
"{",
"$",
"receiptsbyforumid",
"[",
"$",
"forumid",
"]",
"=",
"$",
"readreceiptcollection",
";",
"}",
"}",
"return",
"$",
"receiptsbyforumid",
";",
"}"
] |
Get the read receipt collections for the given viewing user and each forum. The
receipt collections will only be loaded for posts in forums that the user is tracking.
The receipt collections are returned in an array indexed by the forum ids.
@param stdClass $user The user viewing the posts.
@param array $groupedposts List of posts grouped by discussions.
|
[
"Get",
"the",
"read",
"receipt",
"collections",
"for",
"the",
"given",
"viewing",
"user",
"and",
"each",
"forum",
".",
"The",
"receipt",
"collections",
"will",
"only",
"be",
"loaded",
"for",
"posts",
"in",
"forums",
"that",
"the",
"user",
"is",
"tracking",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/builders/exported_posts.php#L454-L492
|
220,015
|
moodle/moodle
|
mod/forum/classes/local/builders/exported_posts.php
|
exported_posts.sort_exported_posts
|
private function sort_exported_posts(array $posts, array $exportedposts) {
$postindexes = [];
foreach (array_values($posts) as $index => $post) {
$postindexes[$post->get_id()] = $index;
}
$sortedexportedposts = [];
foreach ($exportedposts as $exportedpost) {
$index = $postindexes[$exportedpost->id];
$sortedexportedposts[$index] = $exportedpost;
}
return $sortedexportedposts;
}
|
php
|
private function sort_exported_posts(array $posts, array $exportedposts) {
$postindexes = [];
foreach (array_values($posts) as $index => $post) {
$postindexes[$post->get_id()] = $index;
}
$sortedexportedposts = [];
foreach ($exportedposts as $exportedpost) {
$index = $postindexes[$exportedpost->id];
$sortedexportedposts[$index] = $exportedpost;
}
return $sortedexportedposts;
}
|
[
"private",
"function",
"sort_exported_posts",
"(",
"array",
"$",
"posts",
",",
"array",
"$",
"exportedposts",
")",
"{",
"$",
"postindexes",
"=",
"[",
"]",
";",
"foreach",
"(",
"array_values",
"(",
"$",
"posts",
")",
"as",
"$",
"index",
"=>",
"$",
"post",
")",
"{",
"$",
"postindexes",
"[",
"$",
"post",
"->",
"get_id",
"(",
")",
"]",
"=",
"$",
"index",
";",
"}",
"$",
"sortedexportedposts",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"exportedposts",
"as",
"$",
"exportedpost",
")",
"{",
"$",
"index",
"=",
"$",
"postindexes",
"[",
"$",
"exportedpost",
"->",
"id",
"]",
";",
"$",
"sortedexportedposts",
"[",
"$",
"index",
"]",
"=",
"$",
"exportedpost",
";",
"}",
"return",
"$",
"sortedexportedposts",
";",
"}"
] |
Sort the list of exported posts back into the same order as the given posts.
The ordering of the exported posts can often deviate from the given posts due
to the process of exporting them so we need to sort them back into the order
that the calling code expected.
@param post_entity[] $posts The posts in the expected order.
@param stdClass[] $exportedposts The list of exported posts in any order.
@return stdClass[] Sorted exported posts.
|
[
"Sort",
"the",
"list",
"of",
"exported",
"posts",
"back",
"into",
"the",
"same",
"order",
"as",
"the",
"given",
"posts",
".",
"The",
"ordering",
"of",
"the",
"exported",
"posts",
"can",
"often",
"deviate",
"from",
"the",
"given",
"posts",
"due",
"to",
"the",
"process",
"of",
"exporting",
"them",
"so",
"we",
"need",
"to",
"sort",
"them",
"back",
"into",
"the",
"order",
"that",
"the",
"calling",
"code",
"expected",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/builders/exported_posts.php#L504-L518
|
220,016
|
moodle/moodle
|
lib/phpexcel/PHPExcel/Reader/Excel5/Escher.php
|
PHPExcel_Reader_Excel5_Escher.readSplitMenuColors
|
private function readSplitMenuColors()
{
$length = PHPExcel_Reader_Excel5::getInt4d($this->data, $this->pos + 4);
$recordData = substr($this->data, $this->pos + 8, $length);
// move stream pointer to next record
$this->pos += 8 + $length;
}
|
php
|
private function readSplitMenuColors()
{
$length = PHPExcel_Reader_Excel5::getInt4d($this->data, $this->pos + 4);
$recordData = substr($this->data, $this->pos + 8, $length);
// move stream pointer to next record
$this->pos += 8 + $length;
}
|
[
"private",
"function",
"readSplitMenuColors",
"(",
")",
"{",
"$",
"length",
"=",
"PHPExcel_Reader_Excel5",
"::",
"getInt4d",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"this",
"->",
"pos",
"+",
"4",
")",
";",
"$",
"recordData",
"=",
"substr",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"this",
"->",
"pos",
"+",
"8",
",",
"$",
"length",
")",
";",
"// move stream pointer to next record",
"$",
"this",
"->",
"pos",
"+=",
"8",
"+",
"$",
"length",
";",
"}"
] |
Read SplitMenuColors record
|
[
"Read",
"SplitMenuColors",
"record"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Reader/Excel5/Escher.php#L426-L433
|
220,017
|
moodle/moodle
|
mod/workshop/form/accumulative/backup/moodle1/lib.php
|
moodle1_workshopform_accumulative_handler.get_new_scale_definition
|
private function get_new_scale_definition($oldscaleid) {
$data = array(
'userid' => 0, // restore will remap to the current user
'courseid' => 0, // global scale
'description' => '',
'descriptionformat' => FORMAT_HTML,
);
switch ($oldscaleid) {
case 0:
$data['name'] = get_string('scalename0', 'workshopform_accumulative');
$data['scale'] = implode(',', array(get_string('no'), get_string('yes')));
break;
case 1:
$data['name'] = get_string('scalename1', 'workshopform_accumulative');
$data['scale'] = implode(',', array(get_string('absent', 'workshopform_accumulative'),
get_string('present', 'workshopform_accumulative')));
break;
case 2:
$data['name'] = get_string('scalename2', 'workshopform_accumulative');
$data['scale'] = implode(',', array(get_string('incorrect', 'workshopform_accumulative'),
get_string('correct', 'workshopform_accumulative')));
break;
case 3:
$data['name'] = get_string('scalename3', 'workshopform_accumulative');
$data['scale'] = implode(',', array('* ' . get_string('poor', 'workshopform_accumulative'),
'**',
'*** ' . get_string('good', 'workshopform_accumulative')));
break;
case 4:
$data['name'] = get_string('scalename4', 'workshopform_accumulative');
$data['scale'] = implode(',', array('* ' . get_string('verypoor', 'workshopform_accumulative'),
'**',
'***',
'**** ' . get_string('excellent', 'workshopform_accumulative')));
break;
case 5:
$data['name'] = get_string('scalename5', 'workshopform_accumulative');
$data['scale'] = implode(',', array('* ' . get_string('verypoor', 'workshopform_accumulative'),
'**',
'***',
'****',
'***** ' . get_string('excellent', 'workshopform_accumulative')));
break;
case 6:
$data['name'] = get_string('scalename6', 'workshopform_accumulative');
$data['scale'] = implode(',', array('* ' . get_string('verypoor', 'workshopform_accumulative'),
'**',
'***',
'****',
'*****',
'******',
'******* ' . get_string('excellent', 'workshopform_accumulative')));
break;
}
return $data;
}
|
php
|
private function get_new_scale_definition($oldscaleid) {
$data = array(
'userid' => 0, // restore will remap to the current user
'courseid' => 0, // global scale
'description' => '',
'descriptionformat' => FORMAT_HTML,
);
switch ($oldscaleid) {
case 0:
$data['name'] = get_string('scalename0', 'workshopform_accumulative');
$data['scale'] = implode(',', array(get_string('no'), get_string('yes')));
break;
case 1:
$data['name'] = get_string('scalename1', 'workshopform_accumulative');
$data['scale'] = implode(',', array(get_string('absent', 'workshopform_accumulative'),
get_string('present', 'workshopform_accumulative')));
break;
case 2:
$data['name'] = get_string('scalename2', 'workshopform_accumulative');
$data['scale'] = implode(',', array(get_string('incorrect', 'workshopform_accumulative'),
get_string('correct', 'workshopform_accumulative')));
break;
case 3:
$data['name'] = get_string('scalename3', 'workshopform_accumulative');
$data['scale'] = implode(',', array('* ' . get_string('poor', 'workshopform_accumulative'),
'**',
'*** ' . get_string('good', 'workshopform_accumulative')));
break;
case 4:
$data['name'] = get_string('scalename4', 'workshopform_accumulative');
$data['scale'] = implode(',', array('* ' . get_string('verypoor', 'workshopform_accumulative'),
'**',
'***',
'**** ' . get_string('excellent', 'workshopform_accumulative')));
break;
case 5:
$data['name'] = get_string('scalename5', 'workshopform_accumulative');
$data['scale'] = implode(',', array('* ' . get_string('verypoor', 'workshopform_accumulative'),
'**',
'***',
'****',
'***** ' . get_string('excellent', 'workshopform_accumulative')));
break;
case 6:
$data['name'] = get_string('scalename6', 'workshopform_accumulative');
$data['scale'] = implode(',', array('* ' . get_string('verypoor', 'workshopform_accumulative'),
'**',
'***',
'****',
'*****',
'******',
'******* ' . get_string('excellent', 'workshopform_accumulative')));
break;
}
return $data;
}
|
[
"private",
"function",
"get_new_scale_definition",
"(",
"$",
"oldscaleid",
")",
"{",
"$",
"data",
"=",
"array",
"(",
"'userid'",
"=>",
"0",
",",
"// restore will remap to the current user",
"'courseid'",
"=>",
"0",
",",
"// global scale",
"'description'",
"=>",
"''",
",",
"'descriptionformat'",
"=>",
"FORMAT_HTML",
",",
")",
";",
"switch",
"(",
"$",
"oldscaleid",
")",
"{",
"case",
"0",
":",
"$",
"data",
"[",
"'name'",
"]",
"=",
"get_string",
"(",
"'scalename0'",
",",
"'workshopform_accumulative'",
")",
";",
"$",
"data",
"[",
"'scale'",
"]",
"=",
"implode",
"(",
"','",
",",
"array",
"(",
"get_string",
"(",
"'no'",
")",
",",
"get_string",
"(",
"'yes'",
")",
")",
")",
";",
"break",
";",
"case",
"1",
":",
"$",
"data",
"[",
"'name'",
"]",
"=",
"get_string",
"(",
"'scalename1'",
",",
"'workshopform_accumulative'",
")",
";",
"$",
"data",
"[",
"'scale'",
"]",
"=",
"implode",
"(",
"','",
",",
"array",
"(",
"get_string",
"(",
"'absent'",
",",
"'workshopform_accumulative'",
")",
",",
"get_string",
"(",
"'present'",
",",
"'workshopform_accumulative'",
")",
")",
")",
";",
"break",
";",
"case",
"2",
":",
"$",
"data",
"[",
"'name'",
"]",
"=",
"get_string",
"(",
"'scalename2'",
",",
"'workshopform_accumulative'",
")",
";",
"$",
"data",
"[",
"'scale'",
"]",
"=",
"implode",
"(",
"','",
",",
"array",
"(",
"get_string",
"(",
"'incorrect'",
",",
"'workshopform_accumulative'",
")",
",",
"get_string",
"(",
"'correct'",
",",
"'workshopform_accumulative'",
")",
")",
")",
";",
"break",
";",
"case",
"3",
":",
"$",
"data",
"[",
"'name'",
"]",
"=",
"get_string",
"(",
"'scalename3'",
",",
"'workshopform_accumulative'",
")",
";",
"$",
"data",
"[",
"'scale'",
"]",
"=",
"implode",
"(",
"','",
",",
"array",
"(",
"'* '",
".",
"get_string",
"(",
"'poor'",
",",
"'workshopform_accumulative'",
")",
",",
"'**'",
",",
"'*** '",
".",
"get_string",
"(",
"'good'",
",",
"'workshopform_accumulative'",
")",
")",
")",
";",
"break",
";",
"case",
"4",
":",
"$",
"data",
"[",
"'name'",
"]",
"=",
"get_string",
"(",
"'scalename4'",
",",
"'workshopform_accumulative'",
")",
";",
"$",
"data",
"[",
"'scale'",
"]",
"=",
"implode",
"(",
"','",
",",
"array",
"(",
"'* '",
".",
"get_string",
"(",
"'verypoor'",
",",
"'workshopform_accumulative'",
")",
",",
"'**'",
",",
"'***'",
",",
"'**** '",
".",
"get_string",
"(",
"'excellent'",
",",
"'workshopform_accumulative'",
")",
")",
")",
";",
"break",
";",
"case",
"5",
":",
"$",
"data",
"[",
"'name'",
"]",
"=",
"get_string",
"(",
"'scalename5'",
",",
"'workshopform_accumulative'",
")",
";",
"$",
"data",
"[",
"'scale'",
"]",
"=",
"implode",
"(",
"','",
",",
"array",
"(",
"'* '",
".",
"get_string",
"(",
"'verypoor'",
",",
"'workshopform_accumulative'",
")",
",",
"'**'",
",",
"'***'",
",",
"'****'",
",",
"'***** '",
".",
"get_string",
"(",
"'excellent'",
",",
"'workshopform_accumulative'",
")",
")",
")",
";",
"break",
";",
"case",
"6",
":",
"$",
"data",
"[",
"'name'",
"]",
"=",
"get_string",
"(",
"'scalename6'",
",",
"'workshopform_accumulative'",
")",
";",
"$",
"data",
"[",
"'scale'",
"]",
"=",
"implode",
"(",
"','",
",",
"array",
"(",
"'* '",
".",
"get_string",
"(",
"'verypoor'",
",",
"'workshopform_accumulative'",
")",
",",
"'**'",
",",
"'***'",
",",
"'****'",
",",
"'*****'",
",",
"'******'",
",",
"'******* '",
".",
"get_string",
"(",
"'excellent'",
",",
"'workshopform_accumulative'",
")",
")",
")",
";",
"break",
";",
"}",
"return",
"$",
"data",
";",
"}"
] |
Returns a definition of a legacy workshop scale
@see workshopform_accumulative_upgrade_scales
@param object $oldscaleid
@return array
|
[
"Returns",
"a",
"definition",
"of",
"a",
"legacy",
"workshop",
"scale"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/form/accumulative/backup/moodle1/lib.php#L111-L169
|
220,018
|
moodle/moodle
|
customfield/externallib.php
|
core_customfield_external.delete_field
|
public static function delete_field($id) {
$params = self::validate_parameters(self::delete_field_parameters(), ['id' => $id]);
$record = \core_customfield\field_controller::create($params['id']);
$handler = $record->get_handler();
if (!$handler->can_configure()) {
throw new moodle_exception('nopermissionconfigure', 'core_customfield');
}
$handler->delete_field_configuration($record);
}
|
php
|
public static function delete_field($id) {
$params = self::validate_parameters(self::delete_field_parameters(), ['id' => $id]);
$record = \core_customfield\field_controller::create($params['id']);
$handler = $record->get_handler();
if (!$handler->can_configure()) {
throw new moodle_exception('nopermissionconfigure', 'core_customfield');
}
$handler->delete_field_configuration($record);
}
|
[
"public",
"static",
"function",
"delete_field",
"(",
"$",
"id",
")",
"{",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"delete_field_parameters",
"(",
")",
",",
"[",
"'id'",
"=>",
"$",
"id",
"]",
")",
";",
"$",
"record",
"=",
"\\",
"core_customfield",
"\\",
"field_controller",
"::",
"create",
"(",
"$",
"params",
"[",
"'id'",
"]",
")",
";",
"$",
"handler",
"=",
"$",
"record",
"->",
"get_handler",
"(",
")",
";",
"if",
"(",
"!",
"$",
"handler",
"->",
"can_configure",
"(",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'nopermissionconfigure'",
",",
"'core_customfield'",
")",
";",
"}",
"$",
"handler",
"->",
"delete_field_configuration",
"(",
"$",
"record",
")",
";",
"}"
] |
Delete custom field function
@param int $id
|
[
"Delete",
"custom",
"field",
"function"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/externallib.php#L53-L62
|
220,019
|
moodle/moodle
|
customfield/externallib.php
|
core_customfield_external.reload_template_parameters
|
public static function reload_template_parameters() {
return new external_function_parameters(
array(
'component' => new external_value(PARAM_COMPONENT, 'component', VALUE_REQUIRED),
'area' => new external_value(PARAM_ALPHANUMEXT, 'area', VALUE_REQUIRED),
'itemid' => new external_value(PARAM_INT, 'itemid', VALUE_REQUIRED)
)
);
}
|
php
|
public static function reload_template_parameters() {
return new external_function_parameters(
array(
'component' => new external_value(PARAM_COMPONENT, 'component', VALUE_REQUIRED),
'area' => new external_value(PARAM_ALPHANUMEXT, 'area', VALUE_REQUIRED),
'itemid' => new external_value(PARAM_INT, 'itemid', VALUE_REQUIRED)
)
);
}
|
[
"public",
"static",
"function",
"reload_template_parameters",
"(",
")",
"{",
"return",
"new",
"external_function_parameters",
"(",
"array",
"(",
"'component'",
"=>",
"new",
"external_value",
"(",
"PARAM_COMPONENT",
",",
"'component'",
",",
"VALUE_REQUIRED",
")",
",",
"'area'",
"=>",
"new",
"external_value",
"(",
"PARAM_ALPHANUMEXT",
",",
"'area'",
",",
"VALUE_REQUIRED",
")",
",",
"'itemid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'itemid'",
",",
"VALUE_REQUIRED",
")",
")",
")",
";",
"}"
] |
Parameters for reload template function
@return external_function_parameters
|
[
"Parameters",
"for",
"reload",
"template",
"function"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/externallib.php#L75-L83
|
220,020
|
moodle/moodle
|
customfield/externallib.php
|
core_customfield_external.reload_template
|
public static function reload_template($component, $area, $itemid) {
global $PAGE;
$params = self::validate_parameters(self::reload_template_parameters(),
['component' => $component, 'area' => $area, 'itemid' => $itemid]);
$PAGE->set_context(context_system::instance());
$handler = \core_customfield\handler::get_handler($params['component'], $params['area'], $params['itemid']);
self::validate_context($handler->get_configuration_context());
if (!$handler->can_configure()) {
throw new moodle_exception('nopermissionconfigure', 'core_customfield');
}
$output = $PAGE->get_renderer('core_customfield');
$outputpage = new \core_customfield\output\management($handler);
return $outputpage->export_for_template($output);
}
|
php
|
public static function reload_template($component, $area, $itemid) {
global $PAGE;
$params = self::validate_parameters(self::reload_template_parameters(),
['component' => $component, 'area' => $area, 'itemid' => $itemid]);
$PAGE->set_context(context_system::instance());
$handler = \core_customfield\handler::get_handler($params['component'], $params['area'], $params['itemid']);
self::validate_context($handler->get_configuration_context());
if (!$handler->can_configure()) {
throw new moodle_exception('nopermissionconfigure', 'core_customfield');
}
$output = $PAGE->get_renderer('core_customfield');
$outputpage = new \core_customfield\output\management($handler);
return $outputpage->export_for_template($output);
}
|
[
"public",
"static",
"function",
"reload_template",
"(",
"$",
"component",
",",
"$",
"area",
",",
"$",
"itemid",
")",
"{",
"global",
"$",
"PAGE",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"reload_template_parameters",
"(",
")",
",",
"[",
"'component'",
"=>",
"$",
"component",
",",
"'area'",
"=>",
"$",
"area",
",",
"'itemid'",
"=>",
"$",
"itemid",
"]",
")",
";",
"$",
"PAGE",
"->",
"set_context",
"(",
"context_system",
"::",
"instance",
"(",
")",
")",
";",
"$",
"handler",
"=",
"\\",
"core_customfield",
"\\",
"handler",
"::",
"get_handler",
"(",
"$",
"params",
"[",
"'component'",
"]",
",",
"$",
"params",
"[",
"'area'",
"]",
",",
"$",
"params",
"[",
"'itemid'",
"]",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"handler",
"->",
"get_configuration_context",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"handler",
"->",
"can_configure",
"(",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'nopermissionconfigure'",
",",
"'core_customfield'",
")",
";",
"}",
"$",
"output",
"=",
"$",
"PAGE",
"->",
"get_renderer",
"(",
"'core_customfield'",
")",
";",
"$",
"outputpage",
"=",
"new",
"\\",
"core_customfield",
"\\",
"output",
"\\",
"management",
"(",
"$",
"handler",
")",
";",
"return",
"$",
"outputpage",
"->",
"export_for_template",
"(",
"$",
"output",
")",
";",
"}"
] |
Reload template function
@param string $component
@param string $area
@param int $itemid
@return array|object|stdClass
|
[
"Reload",
"template",
"function"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/externallib.php#L93-L108
|
220,021
|
moodle/moodle
|
customfield/externallib.php
|
core_customfield_external.reload_template_returns
|
public static function reload_template_returns() {
return new external_single_structure(
array(
'component' => new external_value(PARAM_COMPONENT, 'component'),
'area' => new external_value(PARAM_ALPHANUMEXT, 'area'),
'itemid' => new external_value(PARAM_INT, 'itemid'),
'usescategories' => new external_value(PARAM_INT, 'view has categories'),
'categories' => new external_multiple_structure(
new external_single_structure(
array(
'id' => new external_value(PARAM_INT, 'id'),
'nameeditable' => new external_value(PARAM_RAW, 'inplace editable name'),
'addfieldmenu' => new external_value(PARAM_RAW, 'addfieldmenu'),
'fields' => new external_multiple_structure(
new external_single_structure(
array(
'name' => new external_value(PARAM_NOTAGS, 'name'),
'shortname' => new external_value(PARAM_NOTAGS, 'shortname'),
'type' => new external_value(PARAM_NOTAGS, 'type'),
'editfieldurl' => new external_value(PARAM_URL, 'edit field url'),
'id' => new external_value(PARAM_INT, 'id'),
)
)
, '', VALUE_OPTIONAL),
)
)
),
)
);
}
|
php
|
public static function reload_template_returns() {
return new external_single_structure(
array(
'component' => new external_value(PARAM_COMPONENT, 'component'),
'area' => new external_value(PARAM_ALPHANUMEXT, 'area'),
'itemid' => new external_value(PARAM_INT, 'itemid'),
'usescategories' => new external_value(PARAM_INT, 'view has categories'),
'categories' => new external_multiple_structure(
new external_single_structure(
array(
'id' => new external_value(PARAM_INT, 'id'),
'nameeditable' => new external_value(PARAM_RAW, 'inplace editable name'),
'addfieldmenu' => new external_value(PARAM_RAW, 'addfieldmenu'),
'fields' => new external_multiple_structure(
new external_single_structure(
array(
'name' => new external_value(PARAM_NOTAGS, 'name'),
'shortname' => new external_value(PARAM_NOTAGS, 'shortname'),
'type' => new external_value(PARAM_NOTAGS, 'type'),
'editfieldurl' => new external_value(PARAM_URL, 'edit field url'),
'id' => new external_value(PARAM_INT, 'id'),
)
)
, '', VALUE_OPTIONAL),
)
)
),
)
);
}
|
[
"public",
"static",
"function",
"reload_template_returns",
"(",
")",
"{",
"return",
"new",
"external_single_structure",
"(",
"array",
"(",
"'component'",
"=>",
"new",
"external_value",
"(",
"PARAM_COMPONENT",
",",
"'component'",
")",
",",
"'area'",
"=>",
"new",
"external_value",
"(",
"PARAM_ALPHANUMEXT",
",",
"'area'",
")",
",",
"'itemid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'itemid'",
")",
",",
"'usescategories'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'view has categories'",
")",
",",
"'categories'",
"=>",
"new",
"external_multiple_structure",
"(",
"new",
"external_single_structure",
"(",
"array",
"(",
"'id'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'id'",
")",
",",
"'nameeditable'",
"=>",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'inplace editable name'",
")",
",",
"'addfieldmenu'",
"=>",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'addfieldmenu'",
")",
",",
"'fields'",
"=>",
"new",
"external_multiple_structure",
"(",
"new",
"external_single_structure",
"(",
"array",
"(",
"'name'",
"=>",
"new",
"external_value",
"(",
"PARAM_NOTAGS",
",",
"'name'",
")",
",",
"'shortname'",
"=>",
"new",
"external_value",
"(",
"PARAM_NOTAGS",
",",
"'shortname'",
")",
",",
"'type'",
"=>",
"new",
"external_value",
"(",
"PARAM_NOTAGS",
",",
"'type'",
")",
",",
"'editfieldurl'",
"=>",
"new",
"external_value",
"(",
"PARAM_URL",
",",
"'edit field url'",
")",
",",
"'id'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'id'",
")",
",",
")",
")",
",",
"''",
",",
"VALUE_OPTIONAL",
")",
",",
")",
")",
")",
",",
")",
")",
";",
"}"
] |
Ajax returns on reload template.
@return external_single_structure
|
[
"Ajax",
"returns",
"on",
"reload",
"template",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/externallib.php#L115-L144
|
220,022
|
moodle/moodle
|
customfield/externallib.php
|
core_customfield_external.delete_category
|
public static function delete_category($id) {
$category = core_customfield\category_controller::create($id);
$handler = $category->get_handler();
self::validate_context($handler->get_configuration_context());
if (!$handler->can_configure()) {
throw new moodle_exception('nopermissionconfigure', 'core_customfield');
}
$handler->delete_category($category);
}
|
php
|
public static function delete_category($id) {
$category = core_customfield\category_controller::create($id);
$handler = $category->get_handler();
self::validate_context($handler->get_configuration_context());
if (!$handler->can_configure()) {
throw new moodle_exception('nopermissionconfigure', 'core_customfield');
}
$handler->delete_category($category);
}
|
[
"public",
"static",
"function",
"delete_category",
"(",
"$",
"id",
")",
"{",
"$",
"category",
"=",
"core_customfield",
"\\",
"category_controller",
"::",
"create",
"(",
"$",
"id",
")",
";",
"$",
"handler",
"=",
"$",
"category",
"->",
"get_handler",
"(",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"handler",
"->",
"get_configuration_context",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"handler",
"->",
"can_configure",
"(",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'nopermissionconfigure'",
",",
"'core_customfield'",
")",
";",
"}",
"$",
"handler",
"->",
"delete_category",
"(",
"$",
"category",
")",
";",
"}"
] |
Delete category function
@param int $id
|
[
"Delete",
"category",
"function"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/externallib.php#L162-L170
|
220,023
|
moodle/moodle
|
customfield/externallib.php
|
core_customfield_external.create_category_parameters
|
public static function create_category_parameters() {
return new external_function_parameters(
array(
'component' => new external_value(PARAM_COMPONENT, 'component', VALUE_REQUIRED),
'area' => new external_value(PARAM_ALPHANUMEXT, 'area', VALUE_REQUIRED),
'itemid' => new external_value(PARAM_INT, 'itemid', VALUE_REQUIRED)
)
);
}
|
php
|
public static function create_category_parameters() {
return new external_function_parameters(
array(
'component' => new external_value(PARAM_COMPONENT, 'component', VALUE_REQUIRED),
'area' => new external_value(PARAM_ALPHANUMEXT, 'area', VALUE_REQUIRED),
'itemid' => new external_value(PARAM_INT, 'itemid', VALUE_REQUIRED)
)
);
}
|
[
"public",
"static",
"function",
"create_category_parameters",
"(",
")",
"{",
"return",
"new",
"external_function_parameters",
"(",
"array",
"(",
"'component'",
"=>",
"new",
"external_value",
"(",
"PARAM_COMPONENT",
",",
"'component'",
",",
"VALUE_REQUIRED",
")",
",",
"'area'",
"=>",
"new",
"external_value",
"(",
"PARAM_ALPHANUMEXT",
",",
"'area'",
",",
"VALUE_REQUIRED",
")",
",",
"'itemid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'itemid'",
",",
"VALUE_REQUIRED",
")",
")",
")",
";",
"}"
] |
Parameters for create category
@return external_function_parameters
|
[
"Parameters",
"for",
"create",
"category"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/externallib.php#L184-L192
|
220,024
|
moodle/moodle
|
customfield/externallib.php
|
core_customfield_external.create_category
|
public static function create_category($component, $area, $itemid) {
$params = self::validate_parameters(self::create_category_parameters(),
['component' => $component, 'area' => $area, 'itemid' => $itemid]);
$handler = \core_customfield\handler::get_handler($params['component'], $params['area'], $params['itemid']);
self::validate_context($handler->get_configuration_context());
if (!$handler->can_configure()) {
throw new moodle_exception('nopermissionconfigure', 'core_customfield');
}
return $handler->create_category();
}
|
php
|
public static function create_category($component, $area, $itemid) {
$params = self::validate_parameters(self::create_category_parameters(),
['component' => $component, 'area' => $area, 'itemid' => $itemid]);
$handler = \core_customfield\handler::get_handler($params['component'], $params['area'], $params['itemid']);
self::validate_context($handler->get_configuration_context());
if (!$handler->can_configure()) {
throw new moodle_exception('nopermissionconfigure', 'core_customfield');
}
return $handler->create_category();
}
|
[
"public",
"static",
"function",
"create_category",
"(",
"$",
"component",
",",
"$",
"area",
",",
"$",
"itemid",
")",
"{",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"create_category_parameters",
"(",
")",
",",
"[",
"'component'",
"=>",
"$",
"component",
",",
"'area'",
"=>",
"$",
"area",
",",
"'itemid'",
"=>",
"$",
"itemid",
"]",
")",
";",
"$",
"handler",
"=",
"\\",
"core_customfield",
"\\",
"handler",
"::",
"get_handler",
"(",
"$",
"params",
"[",
"'component'",
"]",
",",
"$",
"params",
"[",
"'area'",
"]",
",",
"$",
"params",
"[",
"'itemid'",
"]",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"handler",
"->",
"get_configuration_context",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"handler",
"->",
"can_configure",
"(",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'nopermissionconfigure'",
",",
"'core_customfield'",
")",
";",
"}",
"return",
"$",
"handler",
"->",
"create_category",
"(",
")",
";",
"}"
] |
Create category function
@param string $component
@param string $area
@param int $itemid
@return mixed
|
[
"Create",
"category",
"function"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/externallib.php#L202-L212
|
220,025
|
moodle/moodle
|
customfield/externallib.php
|
core_customfield_external.move_field_parameters
|
public static function move_field_parameters() {
return new external_function_parameters(
['id' => new external_value(PARAM_INT, 'Id of the field to move', VALUE_REQUIRED),
'categoryid' => new external_value(PARAM_INT, 'New parent category id', VALUE_REQUIRED),
'beforeid' => new external_value(PARAM_INT, 'Id of the field before which it needs to be moved',
VALUE_DEFAULT, 0)]
);
}
|
php
|
public static function move_field_parameters() {
return new external_function_parameters(
['id' => new external_value(PARAM_INT, 'Id of the field to move', VALUE_REQUIRED),
'categoryid' => new external_value(PARAM_INT, 'New parent category id', VALUE_REQUIRED),
'beforeid' => new external_value(PARAM_INT, 'Id of the field before which it needs to be moved',
VALUE_DEFAULT, 0)]
);
}
|
[
"public",
"static",
"function",
"move_field_parameters",
"(",
")",
"{",
"return",
"new",
"external_function_parameters",
"(",
"[",
"'id'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Id of the field to move'",
",",
"VALUE_REQUIRED",
")",
",",
"'categoryid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'New parent category id'",
",",
"VALUE_REQUIRED",
")",
",",
"'beforeid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Id of the field before which it needs to be moved'",
",",
"VALUE_DEFAULT",
",",
"0",
")",
"]",
")",
";",
"}"
] |
Parameters for move field.
@return external_function_parameters
|
[
"Parameters",
"for",
"move",
"field",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/externallib.php#L226-L233
|
220,026
|
moodle/moodle
|
customfield/externallib.php
|
core_customfield_external.move_category
|
public static function move_category(int $id, int $beforeid) {
$params = self::validate_parameters(self::move_category_parameters(),
['id' => $id, 'beforeid' => $beforeid]);
$category = core_customfield\category_controller::create($id);
$handler = $category->get_handler();
self::validate_context($handler->get_configuration_context());
if (!$handler->can_configure()) {
throw new moodle_exception('nopermissionconfigure', 'core_customfield');
}
$handler->move_category($category, $params['beforeid']);
}
|
php
|
public static function move_category(int $id, int $beforeid) {
$params = self::validate_parameters(self::move_category_parameters(),
['id' => $id, 'beforeid' => $beforeid]);
$category = core_customfield\category_controller::create($id);
$handler = $category->get_handler();
self::validate_context($handler->get_configuration_context());
if (!$handler->can_configure()) {
throw new moodle_exception('nopermissionconfigure', 'core_customfield');
}
$handler->move_category($category, $params['beforeid']);
}
|
[
"public",
"static",
"function",
"move_category",
"(",
"int",
"$",
"id",
",",
"int",
"$",
"beforeid",
")",
"{",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"move_category_parameters",
"(",
")",
",",
"[",
"'id'",
"=>",
"$",
"id",
",",
"'beforeid'",
"=>",
"$",
"beforeid",
"]",
")",
";",
"$",
"category",
"=",
"core_customfield",
"\\",
"category_controller",
"::",
"create",
"(",
"$",
"id",
")",
";",
"$",
"handler",
"=",
"$",
"category",
"->",
"get_handler",
"(",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"handler",
"->",
"get_configuration_context",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"handler",
"->",
"can_configure",
"(",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'nopermissionconfigure'",
",",
"'core_customfield'",
")",
";",
"}",
"$",
"handler",
"->",
"move_category",
"(",
"$",
"category",
",",
"$",
"params",
"[",
"'beforeid'",
"]",
")",
";",
"}"
] |
Reorder categories. Move category to the new position
@param int $id category id
@param int $beforeid
|
[
"Reorder",
"categories",
".",
"Move",
"category",
"to",
"the",
"new",
"position"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/externallib.php#L279-L289
|
220,027
|
moodle/moodle
|
grade/grading/form/rubric/lib.php
|
gradingform_rubric_controller.update_definition
|
public function update_definition(stdClass $newdefinition, $usermodified = null) {
$this->update_or_check_rubric($newdefinition, $usermodified, true);
if (isset($newdefinition->rubric['regrade']) && $newdefinition->rubric['regrade']) {
$this->mark_for_regrade();
}
}
|
php
|
public function update_definition(stdClass $newdefinition, $usermodified = null) {
$this->update_or_check_rubric($newdefinition, $usermodified, true);
if (isset($newdefinition->rubric['regrade']) && $newdefinition->rubric['regrade']) {
$this->mark_for_regrade();
}
}
|
[
"public",
"function",
"update_definition",
"(",
"stdClass",
"$",
"newdefinition",
",",
"$",
"usermodified",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"update_or_check_rubric",
"(",
"$",
"newdefinition",
",",
"$",
"usermodified",
",",
"true",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"newdefinition",
"->",
"rubric",
"[",
"'regrade'",
"]",
")",
"&&",
"$",
"newdefinition",
"->",
"rubric",
"[",
"'regrade'",
"]",
")",
"{",
"$",
"this",
"->",
"mark_for_regrade",
"(",
")",
";",
"}",
"}"
] |
Saves the rubric definition into the database
@see parent::update_definition()
@param stdClass $newdefinition rubric definition data as coming from gradingform_rubric_editrubric::get_data()
@param int|null $usermodified optional userid of the author of the definition, defaults to the current user
|
[
"Saves",
"the",
"rubric",
"definition",
"into",
"the",
"database"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/rubric/lib.php#L99-L104
|
220,028
|
moodle/moodle
|
grade/grading/form/rubric/lib.php
|
gradingform_rubric_controller.load_definition
|
protected function load_definition() {
global $DB;
$sql = "SELECT gd.*,
rc.id AS rcid, rc.sortorder AS rcsortorder, rc.description AS rcdescription, rc.descriptionformat AS rcdescriptionformat,
rl.id AS rlid, rl.score AS rlscore, rl.definition AS rldefinition, rl.definitionformat AS rldefinitionformat
FROM {grading_definitions} gd
LEFT JOIN {gradingform_rubric_criteria} rc ON (rc.definitionid = gd.id)
LEFT JOIN {gradingform_rubric_levels} rl ON (rl.criterionid = rc.id)
WHERE gd.areaid = :areaid AND gd.method = :method
ORDER BY rc.sortorder,rl.score";
$params = array('areaid' => $this->areaid, 'method' => $this->get_method_name());
$rs = $DB->get_recordset_sql($sql, $params);
$this->definition = false;
foreach ($rs as $record) {
// pick the common definition data
if ($this->definition === false) {
$this->definition = new stdClass();
foreach (array('id', 'name', 'description', 'descriptionformat', 'status', 'copiedfromid',
'timecreated', 'usercreated', 'timemodified', 'usermodified', 'timecopied', 'options') as $fieldname) {
$this->definition->$fieldname = $record->$fieldname;
}
$this->definition->rubric_criteria = array();
}
// pick the criterion data
if (!empty($record->rcid) and empty($this->definition->rubric_criteria[$record->rcid])) {
foreach (array('id', 'sortorder', 'description', 'descriptionformat') as $fieldname) {
$this->definition->rubric_criteria[$record->rcid][$fieldname] = $record->{'rc'.$fieldname};
}
$this->definition->rubric_criteria[$record->rcid]['levels'] = array();
}
// pick the level data
if (!empty($record->rlid)) {
foreach (array('id', 'score', 'definition', 'definitionformat') as $fieldname) {
$value = $record->{'rl'.$fieldname};
if ($fieldname == 'score') {
$value = (float)$value; // To prevent display like 1.00000
}
$this->definition->rubric_criteria[$record->rcid]['levels'][$record->rlid][$fieldname] = $value;
}
}
}
$rs->close();
$options = $this->get_options();
if (!$options['sortlevelsasc']) {
foreach (array_keys($this->definition->rubric_criteria) as $rcid) {
$this->definition->rubric_criteria[$rcid]['levels'] = array_reverse($this->definition->rubric_criteria[$rcid]['levels'], true);
}
}
}
|
php
|
protected function load_definition() {
global $DB;
$sql = "SELECT gd.*,
rc.id AS rcid, rc.sortorder AS rcsortorder, rc.description AS rcdescription, rc.descriptionformat AS rcdescriptionformat,
rl.id AS rlid, rl.score AS rlscore, rl.definition AS rldefinition, rl.definitionformat AS rldefinitionformat
FROM {grading_definitions} gd
LEFT JOIN {gradingform_rubric_criteria} rc ON (rc.definitionid = gd.id)
LEFT JOIN {gradingform_rubric_levels} rl ON (rl.criterionid = rc.id)
WHERE gd.areaid = :areaid AND gd.method = :method
ORDER BY rc.sortorder,rl.score";
$params = array('areaid' => $this->areaid, 'method' => $this->get_method_name());
$rs = $DB->get_recordset_sql($sql, $params);
$this->definition = false;
foreach ($rs as $record) {
// pick the common definition data
if ($this->definition === false) {
$this->definition = new stdClass();
foreach (array('id', 'name', 'description', 'descriptionformat', 'status', 'copiedfromid',
'timecreated', 'usercreated', 'timemodified', 'usermodified', 'timecopied', 'options') as $fieldname) {
$this->definition->$fieldname = $record->$fieldname;
}
$this->definition->rubric_criteria = array();
}
// pick the criterion data
if (!empty($record->rcid) and empty($this->definition->rubric_criteria[$record->rcid])) {
foreach (array('id', 'sortorder', 'description', 'descriptionformat') as $fieldname) {
$this->definition->rubric_criteria[$record->rcid][$fieldname] = $record->{'rc'.$fieldname};
}
$this->definition->rubric_criteria[$record->rcid]['levels'] = array();
}
// pick the level data
if (!empty($record->rlid)) {
foreach (array('id', 'score', 'definition', 'definitionformat') as $fieldname) {
$value = $record->{'rl'.$fieldname};
if ($fieldname == 'score') {
$value = (float)$value; // To prevent display like 1.00000
}
$this->definition->rubric_criteria[$record->rcid]['levels'][$record->rlid][$fieldname] = $value;
}
}
}
$rs->close();
$options = $this->get_options();
if (!$options['sortlevelsasc']) {
foreach (array_keys($this->definition->rubric_criteria) as $rcid) {
$this->definition->rubric_criteria[$rcid]['levels'] = array_reverse($this->definition->rubric_criteria[$rcid]['levels'], true);
}
}
}
|
[
"protected",
"function",
"load_definition",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"sql",
"=",
"\"SELECT gd.*,\n rc.id AS rcid, rc.sortorder AS rcsortorder, rc.description AS rcdescription, rc.descriptionformat AS rcdescriptionformat,\n rl.id AS rlid, rl.score AS rlscore, rl.definition AS rldefinition, rl.definitionformat AS rldefinitionformat\n FROM {grading_definitions} gd\n LEFT JOIN {gradingform_rubric_criteria} rc ON (rc.definitionid = gd.id)\n LEFT JOIN {gradingform_rubric_levels} rl ON (rl.criterionid = rc.id)\n WHERE gd.areaid = :areaid AND gd.method = :method\n ORDER BY rc.sortorder,rl.score\"",
";",
"$",
"params",
"=",
"array",
"(",
"'areaid'",
"=>",
"$",
"this",
"->",
"areaid",
",",
"'method'",
"=>",
"$",
"this",
"->",
"get_method_name",
"(",
")",
")",
";",
"$",
"rs",
"=",
"$",
"DB",
"->",
"get_recordset_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"definition",
"=",
"false",
";",
"foreach",
"(",
"$",
"rs",
"as",
"$",
"record",
")",
"{",
"// pick the common definition data",
"if",
"(",
"$",
"this",
"->",
"definition",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"definition",
"=",
"new",
"stdClass",
"(",
")",
";",
"foreach",
"(",
"array",
"(",
"'id'",
",",
"'name'",
",",
"'description'",
",",
"'descriptionformat'",
",",
"'status'",
",",
"'copiedfromid'",
",",
"'timecreated'",
",",
"'usercreated'",
",",
"'timemodified'",
",",
"'usermodified'",
",",
"'timecopied'",
",",
"'options'",
")",
"as",
"$",
"fieldname",
")",
"{",
"$",
"this",
"->",
"definition",
"->",
"$",
"fieldname",
"=",
"$",
"record",
"->",
"$",
"fieldname",
";",
"}",
"$",
"this",
"->",
"definition",
"->",
"rubric_criteria",
"=",
"array",
"(",
")",
";",
"}",
"// pick the criterion data",
"if",
"(",
"!",
"empty",
"(",
"$",
"record",
"->",
"rcid",
")",
"and",
"empty",
"(",
"$",
"this",
"->",
"definition",
"->",
"rubric_criteria",
"[",
"$",
"record",
"->",
"rcid",
"]",
")",
")",
"{",
"foreach",
"(",
"array",
"(",
"'id'",
",",
"'sortorder'",
",",
"'description'",
",",
"'descriptionformat'",
")",
"as",
"$",
"fieldname",
")",
"{",
"$",
"this",
"->",
"definition",
"->",
"rubric_criteria",
"[",
"$",
"record",
"->",
"rcid",
"]",
"[",
"$",
"fieldname",
"]",
"=",
"$",
"record",
"->",
"{",
"'rc'",
".",
"$",
"fieldname",
"}",
";",
"}",
"$",
"this",
"->",
"definition",
"->",
"rubric_criteria",
"[",
"$",
"record",
"->",
"rcid",
"]",
"[",
"'levels'",
"]",
"=",
"array",
"(",
")",
";",
"}",
"// pick the level data",
"if",
"(",
"!",
"empty",
"(",
"$",
"record",
"->",
"rlid",
")",
")",
"{",
"foreach",
"(",
"array",
"(",
"'id'",
",",
"'score'",
",",
"'definition'",
",",
"'definitionformat'",
")",
"as",
"$",
"fieldname",
")",
"{",
"$",
"value",
"=",
"$",
"record",
"->",
"{",
"'rl'",
".",
"$",
"fieldname",
"}",
";",
"if",
"(",
"$",
"fieldname",
"==",
"'score'",
")",
"{",
"$",
"value",
"=",
"(",
"float",
")",
"$",
"value",
";",
"// To prevent display like 1.00000",
"}",
"$",
"this",
"->",
"definition",
"->",
"rubric_criteria",
"[",
"$",
"record",
"->",
"rcid",
"]",
"[",
"'levels'",
"]",
"[",
"$",
"record",
"->",
"rlid",
"]",
"[",
"$",
"fieldname",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"$",
"rs",
"->",
"close",
"(",
")",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"get_options",
"(",
")",
";",
"if",
"(",
"!",
"$",
"options",
"[",
"'sortlevelsasc'",
"]",
")",
"{",
"foreach",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"definition",
"->",
"rubric_criteria",
")",
"as",
"$",
"rcid",
")",
"{",
"$",
"this",
"->",
"definition",
"->",
"rubric_criteria",
"[",
"$",
"rcid",
"]",
"[",
"'levels'",
"]",
"=",
"array_reverse",
"(",
"$",
"this",
"->",
"definition",
"->",
"rubric_criteria",
"[",
"$",
"rcid",
"]",
"[",
"'levels'",
"]",
",",
"true",
")",
";",
"}",
"}",
"}"
] |
Loads the rubric form definition if it exists
There is a new array called 'rubric_criteria' appended to the list of parent's definition properties.
|
[
"Loads",
"the",
"rubric",
"form",
"definition",
"if",
"it",
"exists"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/rubric/lib.php#L303-L352
|
220,029
|
moodle/moodle
|
grade/grading/form/rubric/lib.php
|
gradingform_rubric_controller.get_options
|
public function get_options() {
$options = self::get_default_options();
if (!empty($this->definition->options)) {
$thisoptions = json_decode($this->definition->options);
foreach ($thisoptions as $option => $value) {
$options[$option] = $value;
}
if (!array_key_exists('lockzeropoints', $thisoptions)) {
// Rubrics created before Moodle 3.2 don't have 'lockzeropoints' option. In this case they should not
// assume default value 1 but use "legacy" value 0.
$options['lockzeropoints'] = 0;
}
}
return $options;
}
|
php
|
public function get_options() {
$options = self::get_default_options();
if (!empty($this->definition->options)) {
$thisoptions = json_decode($this->definition->options);
foreach ($thisoptions as $option => $value) {
$options[$option] = $value;
}
if (!array_key_exists('lockzeropoints', $thisoptions)) {
// Rubrics created before Moodle 3.2 don't have 'lockzeropoints' option. In this case they should not
// assume default value 1 but use "legacy" value 0.
$options['lockzeropoints'] = 0;
}
}
return $options;
}
|
[
"public",
"function",
"get_options",
"(",
")",
"{",
"$",
"options",
"=",
"self",
"::",
"get_default_options",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"definition",
"->",
"options",
")",
")",
"{",
"$",
"thisoptions",
"=",
"json_decode",
"(",
"$",
"this",
"->",
"definition",
"->",
"options",
")",
";",
"foreach",
"(",
"$",
"thisoptions",
"as",
"$",
"option",
"=>",
"$",
"value",
")",
"{",
"$",
"options",
"[",
"$",
"option",
"]",
"=",
"$",
"value",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"'lockzeropoints'",
",",
"$",
"thisoptions",
")",
")",
"{",
"// Rubrics created before Moodle 3.2 don't have 'lockzeropoints' option. In this case they should not",
"// assume default value 1 but use \"legacy\" value 0.",
"$",
"options",
"[",
"'lockzeropoints'",
"]",
"=",
"0",
";",
"}",
"}",
"return",
"$",
"options",
";",
"}"
] |
Gets the options of this rubric definition, fills the missing options with default values
The only exception is 'lockzeropoints' - if other options are present in the json string but this
one is absent, this means that the rubric was created before Moodle 3.2 and the 0 value should be used.
@return array
|
[
"Gets",
"the",
"options",
"of",
"this",
"rubric",
"definition",
"fills",
"the",
"missing",
"options",
"with",
"default",
"values"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/rubric/lib.php#L382-L396
|
220,030
|
moodle/moodle
|
grade/grading/form/rubric/lib.php
|
gradingform_rubric_instance.clear_attempt
|
public function clear_attempt($data) {
global $DB;
foreach ($data['criteria'] as $criterionid => $record) {
$DB->delete_records('gradingform_rubric_fillings',
array('criterionid' => $criterionid, 'instanceid' => $this->get_id()));
}
}
|
php
|
public function clear_attempt($data) {
global $DB;
foreach ($data['criteria'] as $criterionid => $record) {
$DB->delete_records('gradingform_rubric_fillings',
array('criterionid' => $criterionid, 'instanceid' => $this->get_id()));
}
}
|
[
"public",
"function",
"clear_attempt",
"(",
"$",
"data",
")",
"{",
"global",
"$",
"DB",
";",
"foreach",
"(",
"$",
"data",
"[",
"'criteria'",
"]",
"as",
"$",
"criterionid",
"=>",
"$",
"record",
")",
"{",
"$",
"DB",
"->",
"delete_records",
"(",
"'gradingform_rubric_fillings'",
",",
"array",
"(",
"'criterionid'",
"=>",
"$",
"criterionid",
",",
"'instanceid'",
"=>",
"$",
"this",
"->",
"get_id",
"(",
")",
")",
")",
";",
"}",
"}"
] |
Removes the attempt from the gradingform_guide_fillings table
@param array $data the attempt data
|
[
"Removes",
"the",
"attempt",
"from",
"the",
"gradingform_guide_fillings",
"table"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/rubric/lib.php#L798-L805
|
220,031
|
moodle/moodle
|
grade/grading/form/rubric/lib.php
|
gradingform_rubric_instance.validate_grading_element
|
public function validate_grading_element($elementvalue) {
$criteria = $this->get_controller()->get_definition()->rubric_criteria;
if (!isset($elementvalue['criteria']) || !is_array($elementvalue['criteria']) || sizeof($elementvalue['criteria']) < sizeof($criteria)) {
return false;
}
foreach ($criteria as $id => $criterion) {
if (!isset($elementvalue['criteria'][$id]['levelid'])
|| !array_key_exists($elementvalue['criteria'][$id]['levelid'], $criterion['levels'])) {
return false;
}
}
return true;
}
|
php
|
public function validate_grading_element($elementvalue) {
$criteria = $this->get_controller()->get_definition()->rubric_criteria;
if (!isset($elementvalue['criteria']) || !is_array($elementvalue['criteria']) || sizeof($elementvalue['criteria']) < sizeof($criteria)) {
return false;
}
foreach ($criteria as $id => $criterion) {
if (!isset($elementvalue['criteria'][$id]['levelid'])
|| !array_key_exists($elementvalue['criteria'][$id]['levelid'], $criterion['levels'])) {
return false;
}
}
return true;
}
|
[
"public",
"function",
"validate_grading_element",
"(",
"$",
"elementvalue",
")",
"{",
"$",
"criteria",
"=",
"$",
"this",
"->",
"get_controller",
"(",
")",
"->",
"get_definition",
"(",
")",
"->",
"rubric_criteria",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"elementvalue",
"[",
"'criteria'",
"]",
")",
"||",
"!",
"is_array",
"(",
"$",
"elementvalue",
"[",
"'criteria'",
"]",
")",
"||",
"sizeof",
"(",
"$",
"elementvalue",
"[",
"'criteria'",
"]",
")",
"<",
"sizeof",
"(",
"$",
"criteria",
")",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"$",
"criteria",
"as",
"$",
"id",
"=>",
"$",
"criterion",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"elementvalue",
"[",
"'criteria'",
"]",
"[",
"$",
"id",
"]",
"[",
"'levelid'",
"]",
")",
"||",
"!",
"array_key_exists",
"(",
"$",
"elementvalue",
"[",
"'criteria'",
"]",
"[",
"$",
"id",
"]",
"[",
"'levelid'",
"]",
",",
"$",
"criterion",
"[",
"'levels'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] |
Validates that rubric is fully completed and contains valid grade on each criterion
@param array $elementvalue value of element as came in form submit
@return boolean true if the form data is validated and contains no errors
|
[
"Validates",
"that",
"rubric",
"is",
"fully",
"completed",
"and",
"contains",
"valid",
"grade",
"on",
"each",
"criterion"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/rubric/lib.php#L813-L825
|
220,032
|
moodle/moodle
|
grade/grading/form/rubric/lib.php
|
gradingform_rubric_instance.get_rubric_filling
|
public function get_rubric_filling($force = false) {
global $DB;
if ($this->rubric === null || $force) {
$records = $DB->get_records('gradingform_rubric_fillings', array('instanceid' => $this->get_id()));
$this->rubric = array('criteria' => array());
foreach ($records as $record) {
$this->rubric['criteria'][$record->criterionid] = (array)$record;
}
}
return $this->rubric;
}
|
php
|
public function get_rubric_filling($force = false) {
global $DB;
if ($this->rubric === null || $force) {
$records = $DB->get_records('gradingform_rubric_fillings', array('instanceid' => $this->get_id()));
$this->rubric = array('criteria' => array());
foreach ($records as $record) {
$this->rubric['criteria'][$record->criterionid] = (array)$record;
}
}
return $this->rubric;
}
|
[
"public",
"function",
"get_rubric_filling",
"(",
"$",
"force",
"=",
"false",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"$",
"this",
"->",
"rubric",
"===",
"null",
"||",
"$",
"force",
")",
"{",
"$",
"records",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'gradingform_rubric_fillings'",
",",
"array",
"(",
"'instanceid'",
"=>",
"$",
"this",
"->",
"get_id",
"(",
")",
")",
")",
";",
"$",
"this",
"->",
"rubric",
"=",
"array",
"(",
"'criteria'",
"=>",
"array",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"records",
"as",
"$",
"record",
")",
"{",
"$",
"this",
"->",
"rubric",
"[",
"'criteria'",
"]",
"[",
"$",
"record",
"->",
"criterionid",
"]",
"=",
"(",
"array",
")",
"$",
"record",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"rubric",
";",
"}"
] |
Retrieves from DB and returns the data how this rubric was filled
@param boolean $force whether to force DB query even if the data is cached
@return array
|
[
"Retrieves",
"from",
"DB",
"and",
"returns",
"the",
"data",
"how",
"this",
"rubric",
"was",
"filled"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/rubric/lib.php#L833-L843
|
220,033
|
moodle/moodle
|
completion/classes/manager.php
|
manager.get_completion_detail
|
private function get_completion_detail($mod) {
global $OUTPUT;
$strings = [];
switch ($mod->completion) {
case COMPLETION_TRACKING_NONE:
$strings['string'] = get_string('none');
break;
case COMPLETION_TRACKING_MANUAL:
$strings['string'] = get_string('manual', 'completion');
$strings['icon'] = $OUTPUT->pix_icon('i/completion-manual-y', get_string('completion_manual', 'completion'));
break;
case COMPLETION_TRACKING_AUTOMATIC:
$strings['string'] = get_string('withconditions', 'completion');
$strings['icon'] = $OUTPUT->pix_icon('i/completion-auto-y', get_string('completion_automatic', 'completion'));
break;
default:
$strings['string'] = get_string('none');
break;
}
// Get the descriptions for all the active completion rules for the module.
if ($ruledescriptions = $this->get_completion_active_rule_descriptions($mod)) {
foreach ($ruledescriptions as $ruledescription) {
$strings['string'] .= \html_writer::empty_tag('br') . $ruledescription;
}
}
return $strings;
}
|
php
|
private function get_completion_detail($mod) {
global $OUTPUT;
$strings = [];
switch ($mod->completion) {
case COMPLETION_TRACKING_NONE:
$strings['string'] = get_string('none');
break;
case COMPLETION_TRACKING_MANUAL:
$strings['string'] = get_string('manual', 'completion');
$strings['icon'] = $OUTPUT->pix_icon('i/completion-manual-y', get_string('completion_manual', 'completion'));
break;
case COMPLETION_TRACKING_AUTOMATIC:
$strings['string'] = get_string('withconditions', 'completion');
$strings['icon'] = $OUTPUT->pix_icon('i/completion-auto-y', get_string('completion_automatic', 'completion'));
break;
default:
$strings['string'] = get_string('none');
break;
}
// Get the descriptions for all the active completion rules for the module.
if ($ruledescriptions = $this->get_completion_active_rule_descriptions($mod)) {
foreach ($ruledescriptions as $ruledescription) {
$strings['string'] .= \html_writer::empty_tag('br') . $ruledescription;
}
}
return $strings;
}
|
[
"private",
"function",
"get_completion_detail",
"(",
"$",
"mod",
")",
"{",
"global",
"$",
"OUTPUT",
";",
"$",
"strings",
"=",
"[",
"]",
";",
"switch",
"(",
"$",
"mod",
"->",
"completion",
")",
"{",
"case",
"COMPLETION_TRACKING_NONE",
":",
"$",
"strings",
"[",
"'string'",
"]",
"=",
"get_string",
"(",
"'none'",
")",
";",
"break",
";",
"case",
"COMPLETION_TRACKING_MANUAL",
":",
"$",
"strings",
"[",
"'string'",
"]",
"=",
"get_string",
"(",
"'manual'",
",",
"'completion'",
")",
";",
"$",
"strings",
"[",
"'icon'",
"]",
"=",
"$",
"OUTPUT",
"->",
"pix_icon",
"(",
"'i/completion-manual-y'",
",",
"get_string",
"(",
"'completion_manual'",
",",
"'completion'",
")",
")",
";",
"break",
";",
"case",
"COMPLETION_TRACKING_AUTOMATIC",
":",
"$",
"strings",
"[",
"'string'",
"]",
"=",
"get_string",
"(",
"'withconditions'",
",",
"'completion'",
")",
";",
"$",
"strings",
"[",
"'icon'",
"]",
"=",
"$",
"OUTPUT",
"->",
"pix_icon",
"(",
"'i/completion-auto-y'",
",",
"get_string",
"(",
"'completion_automatic'",
",",
"'completion'",
")",
")",
";",
"break",
";",
"default",
":",
"$",
"strings",
"[",
"'string'",
"]",
"=",
"get_string",
"(",
"'none'",
")",
";",
"break",
";",
"}",
"// Get the descriptions for all the active completion rules for the module.",
"if",
"(",
"$",
"ruledescriptions",
"=",
"$",
"this",
"->",
"get_completion_active_rule_descriptions",
"(",
"$",
"mod",
")",
")",
"{",
"foreach",
"(",
"$",
"ruledescriptions",
"as",
"$",
"ruledescription",
")",
"{",
"$",
"strings",
"[",
"'string'",
"]",
".=",
"\\",
"html_writer",
"::",
"empty_tag",
"(",
"'br'",
")",
".",
"$",
"ruledescription",
";",
"}",
"}",
"return",
"$",
"strings",
";",
"}"
] |
Get completion information on the selected module or module type
@param cm_info|stdClass $mod either instance of cm_info (with 'customcompletionrules' in customdata) or
object with fields ->completion, ->completionview, ->completionexpected, ->completionusegrade
and ->customdata['customcompletionrules']
@return array
|
[
"Get",
"completion",
"information",
"on",
"the",
"selected",
"module",
"or",
"module",
"type"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/classes/manager.php#L129-L159
|
220,034
|
moodle/moodle
|
completion/classes/manager.php
|
manager.get_completion_active_rule_descriptions
|
protected function get_completion_active_rule_descriptions($moduledata) {
$activeruledescriptions = [];
if ($moduledata->completion == COMPLETION_TRACKING_AUTOMATIC) {
// Generate the description strings for the core conditional completion rules (if set).
if (!empty($moduledata->completionview)) {
$activeruledescriptions[] = get_string('completionview_desc', 'completion');
}
if ($moduledata instanceof cm_info && !is_null($moduledata->completiongradeitemnumber) ||
($moduledata instanceof stdClass && !empty($moduledata->completionusegrade))) {
$activeruledescriptions[] = get_string('completionusegrade_desc', 'completion');
}
// Now, ask the module to provide descriptions for its custom conditional completion rules.
if ($customruledescriptions = component_callback($moduledata->modname,
'get_completion_active_rule_descriptions', [$moduledata])) {
$activeruledescriptions = array_merge($activeruledescriptions, $customruledescriptions);
}
}
if ($moduledata->completion != COMPLETION_TRACKING_NONE) {
if (!empty($moduledata->completionexpected)) {
$activeruledescriptions[] = get_string('completionexpecteddesc', 'completion',
userdate($moduledata->completionexpected));
}
}
return $activeruledescriptions;
}
|
php
|
protected function get_completion_active_rule_descriptions($moduledata) {
$activeruledescriptions = [];
if ($moduledata->completion == COMPLETION_TRACKING_AUTOMATIC) {
// Generate the description strings for the core conditional completion rules (if set).
if (!empty($moduledata->completionview)) {
$activeruledescriptions[] = get_string('completionview_desc', 'completion');
}
if ($moduledata instanceof cm_info && !is_null($moduledata->completiongradeitemnumber) ||
($moduledata instanceof stdClass && !empty($moduledata->completionusegrade))) {
$activeruledescriptions[] = get_string('completionusegrade_desc', 'completion');
}
// Now, ask the module to provide descriptions for its custom conditional completion rules.
if ($customruledescriptions = component_callback($moduledata->modname,
'get_completion_active_rule_descriptions', [$moduledata])) {
$activeruledescriptions = array_merge($activeruledescriptions, $customruledescriptions);
}
}
if ($moduledata->completion != COMPLETION_TRACKING_NONE) {
if (!empty($moduledata->completionexpected)) {
$activeruledescriptions[] = get_string('completionexpecteddesc', 'completion',
userdate($moduledata->completionexpected));
}
}
return $activeruledescriptions;
}
|
[
"protected",
"function",
"get_completion_active_rule_descriptions",
"(",
"$",
"moduledata",
")",
"{",
"$",
"activeruledescriptions",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"moduledata",
"->",
"completion",
"==",
"COMPLETION_TRACKING_AUTOMATIC",
")",
"{",
"// Generate the description strings for the core conditional completion rules (if set).",
"if",
"(",
"!",
"empty",
"(",
"$",
"moduledata",
"->",
"completionview",
")",
")",
"{",
"$",
"activeruledescriptions",
"[",
"]",
"=",
"get_string",
"(",
"'completionview_desc'",
",",
"'completion'",
")",
";",
"}",
"if",
"(",
"$",
"moduledata",
"instanceof",
"cm_info",
"&&",
"!",
"is_null",
"(",
"$",
"moduledata",
"->",
"completiongradeitemnumber",
")",
"||",
"(",
"$",
"moduledata",
"instanceof",
"stdClass",
"&&",
"!",
"empty",
"(",
"$",
"moduledata",
"->",
"completionusegrade",
")",
")",
")",
"{",
"$",
"activeruledescriptions",
"[",
"]",
"=",
"get_string",
"(",
"'completionusegrade_desc'",
",",
"'completion'",
")",
";",
"}",
"// Now, ask the module to provide descriptions for its custom conditional completion rules.",
"if",
"(",
"$",
"customruledescriptions",
"=",
"component_callback",
"(",
"$",
"moduledata",
"->",
"modname",
",",
"'get_completion_active_rule_descriptions'",
",",
"[",
"$",
"moduledata",
"]",
")",
")",
"{",
"$",
"activeruledescriptions",
"=",
"array_merge",
"(",
"$",
"activeruledescriptions",
",",
"$",
"customruledescriptions",
")",
";",
"}",
"}",
"if",
"(",
"$",
"moduledata",
"->",
"completion",
"!=",
"COMPLETION_TRACKING_NONE",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"moduledata",
"->",
"completionexpected",
")",
")",
"{",
"$",
"activeruledescriptions",
"[",
"]",
"=",
"get_string",
"(",
"'completionexpecteddesc'",
",",
"'completion'",
",",
"userdate",
"(",
"$",
"moduledata",
"->",
"completionexpected",
")",
")",
";",
"}",
"}",
"return",
"$",
"activeruledescriptions",
";",
"}"
] |
Get the descriptions for all active conditional completion rules for the current module.
@param cm_info|stdClass $moduledata either instance of cm_info (with 'customcompletionrules' in customdata) or
object with fields ->completion, ->completionview, ->completionexpected, ->completionusegrade
and ->customdata['customcompletionrules']
@return array $activeruledescriptions an array of strings describing the active completion rules.
|
[
"Get",
"the",
"descriptions",
"for",
"all",
"active",
"conditional",
"completion",
"rules",
"for",
"the",
"current",
"module",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/classes/manager.php#L169-L197
|
220,035
|
moodle/moodle
|
completion/classes/manager.php
|
manager.get_activities_and_resources
|
public function get_activities_and_resources() {
global $DB, $OUTPUT, $CFG;
require_once($CFG->dirroot.'/course/lib.php');
// Get enabled activities and resources.
$modules = $DB->get_records('modules', ['visible' => 1], 'name ASC');
$data = new stdClass();
$data->courseid = $this->courseid;
$data->sesskey = sesskey();
$data->helpicon = $OUTPUT->help_icon('bulkcompletiontracking', 'core_completion');
// Add icon information.
$data->modules = array_values($modules);
$coursecontext = context_course::instance($this->courseid);
$canmanage = has_capability('moodle/course:manageactivities', $coursecontext);
$course = get_course($this->courseid);
foreach ($data->modules as $module) {
$module->icon = $OUTPUT->image_url('icon', $module->name)->out();
$module->formattedname = format_string(get_string('modulenameplural', 'mod_' . $module->name),
true, ['context' => $coursecontext]);
$module->canmanage = $canmanage && course_allowed_module($course, $module->name);
$defaults = self::get_default_completion($course, $module, false);
$defaults->modname = $module->name;
$module->completionstatus = $this->get_completion_detail($defaults);
}
return $data;
}
|
php
|
public function get_activities_and_resources() {
global $DB, $OUTPUT, $CFG;
require_once($CFG->dirroot.'/course/lib.php');
// Get enabled activities and resources.
$modules = $DB->get_records('modules', ['visible' => 1], 'name ASC');
$data = new stdClass();
$data->courseid = $this->courseid;
$data->sesskey = sesskey();
$data->helpicon = $OUTPUT->help_icon('bulkcompletiontracking', 'core_completion');
// Add icon information.
$data->modules = array_values($modules);
$coursecontext = context_course::instance($this->courseid);
$canmanage = has_capability('moodle/course:manageactivities', $coursecontext);
$course = get_course($this->courseid);
foreach ($data->modules as $module) {
$module->icon = $OUTPUT->image_url('icon', $module->name)->out();
$module->formattedname = format_string(get_string('modulenameplural', 'mod_' . $module->name),
true, ['context' => $coursecontext]);
$module->canmanage = $canmanage && course_allowed_module($course, $module->name);
$defaults = self::get_default_completion($course, $module, false);
$defaults->modname = $module->name;
$module->completionstatus = $this->get_completion_detail($defaults);
}
return $data;
}
|
[
"public",
"function",
"get_activities_and_resources",
"(",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"OUTPUT",
",",
"$",
"CFG",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/course/lib.php'",
")",
";",
"// Get enabled activities and resources.",
"$",
"modules",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'modules'",
",",
"[",
"'visible'",
"=>",
"1",
"]",
",",
"'name ASC'",
")",
";",
"$",
"data",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"data",
"->",
"courseid",
"=",
"$",
"this",
"->",
"courseid",
";",
"$",
"data",
"->",
"sesskey",
"=",
"sesskey",
"(",
")",
";",
"$",
"data",
"->",
"helpicon",
"=",
"$",
"OUTPUT",
"->",
"help_icon",
"(",
"'bulkcompletiontracking'",
",",
"'core_completion'",
")",
";",
"// Add icon information.",
"$",
"data",
"->",
"modules",
"=",
"array_values",
"(",
"$",
"modules",
")",
";",
"$",
"coursecontext",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"this",
"->",
"courseid",
")",
";",
"$",
"canmanage",
"=",
"has_capability",
"(",
"'moodle/course:manageactivities'",
",",
"$",
"coursecontext",
")",
";",
"$",
"course",
"=",
"get_course",
"(",
"$",
"this",
"->",
"courseid",
")",
";",
"foreach",
"(",
"$",
"data",
"->",
"modules",
"as",
"$",
"module",
")",
"{",
"$",
"module",
"->",
"icon",
"=",
"$",
"OUTPUT",
"->",
"image_url",
"(",
"'icon'",
",",
"$",
"module",
"->",
"name",
")",
"->",
"out",
"(",
")",
";",
"$",
"module",
"->",
"formattedname",
"=",
"format_string",
"(",
"get_string",
"(",
"'modulenameplural'",
",",
"'mod_'",
".",
"$",
"module",
"->",
"name",
")",
",",
"true",
",",
"[",
"'context'",
"=>",
"$",
"coursecontext",
"]",
")",
";",
"$",
"module",
"->",
"canmanage",
"=",
"$",
"canmanage",
"&&",
"course_allowed_module",
"(",
"$",
"course",
",",
"$",
"module",
"->",
"name",
")",
";",
"$",
"defaults",
"=",
"self",
"::",
"get_default_completion",
"(",
"$",
"course",
",",
"$",
"module",
",",
"false",
")",
";",
"$",
"defaults",
"->",
"modname",
"=",
"$",
"module",
"->",
"name",
";",
"$",
"module",
"->",
"completionstatus",
"=",
"$",
"this",
"->",
"get_completion_detail",
"(",
"$",
"defaults",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] |
Gets the course modules for the current course.
@return stdClass $data containing the modules
|
[
"Gets",
"the",
"course",
"modules",
"for",
"the",
"current",
"course",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/classes/manager.php#L204-L230
|
220,036
|
moodle/moodle
|
completion/classes/manager.php
|
manager.can_edit_bulk_completion
|
public static function can_edit_bulk_completion($courseorid, $cm = null) {
if ($cm) {
return $cm->uservisible && has_capability('moodle/course:manageactivities', $cm->context);
}
$coursecontext = context_course::instance(is_object($courseorid) ? $courseorid->id : $courseorid);
if (has_capability('moodle/course:manageactivities', $coursecontext)) {
return true;
}
$modinfo = get_fast_modinfo($courseorid);
foreach ($modinfo->cms as $mod) {
if ($mod->uservisible && has_capability('moodle/course:manageactivities', $mod->context)) {
return true;
}
}
return false;
}
|
php
|
public static function can_edit_bulk_completion($courseorid, $cm = null) {
if ($cm) {
return $cm->uservisible && has_capability('moodle/course:manageactivities', $cm->context);
}
$coursecontext = context_course::instance(is_object($courseorid) ? $courseorid->id : $courseorid);
if (has_capability('moodle/course:manageactivities', $coursecontext)) {
return true;
}
$modinfo = get_fast_modinfo($courseorid);
foreach ($modinfo->cms as $mod) {
if ($mod->uservisible && has_capability('moodle/course:manageactivities', $mod->context)) {
return true;
}
}
return false;
}
|
[
"public",
"static",
"function",
"can_edit_bulk_completion",
"(",
"$",
"courseorid",
",",
"$",
"cm",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"cm",
")",
"{",
"return",
"$",
"cm",
"->",
"uservisible",
"&&",
"has_capability",
"(",
"'moodle/course:manageactivities'",
",",
"$",
"cm",
"->",
"context",
")",
";",
"}",
"$",
"coursecontext",
"=",
"context_course",
"::",
"instance",
"(",
"is_object",
"(",
"$",
"courseorid",
")",
"?",
"$",
"courseorid",
"->",
"id",
":",
"$",
"courseorid",
")",
";",
"if",
"(",
"has_capability",
"(",
"'moodle/course:manageactivities'",
",",
"$",
"coursecontext",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"modinfo",
"=",
"get_fast_modinfo",
"(",
"$",
"courseorid",
")",
";",
"foreach",
"(",
"$",
"modinfo",
"->",
"cms",
"as",
"$",
"mod",
")",
"{",
"if",
"(",
"$",
"mod",
"->",
"uservisible",
"&&",
"has_capability",
"(",
"'moodle/course:manageactivities'",
",",
"$",
"mod",
"->",
"context",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] |
Checks if current user can edit activity completion
@param int|stdClass $courseorid
@param \cm_info|null $cm if specified capability for a given coursemodule will be check,
if not specified capability to edit at least one activity is checked.
|
[
"Checks",
"if",
"current",
"user",
"can",
"edit",
"activity",
"completion"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/classes/manager.php#L239-L254
|
220,037
|
moodle/moodle
|
completion/classes/manager.php
|
manager.get_available_completion_tabs
|
public static function get_available_completion_tabs($courseorid) {
$tabs = [];
$courseid = is_object($courseorid) ? $courseorid->id : $courseorid;
$coursecontext = context_course::instance($courseid);
if (has_capability('moodle/course:update', $coursecontext)) {
$tabs[] = new tabobject(
'completion',
new moodle_url('/course/completion.php', ['id' => $courseid]),
new lang_string('coursecompletion', 'completion')
);
}
if (has_capability('moodle/course:manageactivities', $coursecontext)) {
$tabs[] = new tabobject(
'defaultcompletion',
new moodle_url('/course/defaultcompletion.php', ['id' => $courseid]),
new lang_string('defaultcompletion', 'completion')
);
}
if (self::can_edit_bulk_completion($courseorid)) {
$tabs[] = new tabobject(
'bulkcompletion',
new moodle_url('/course/bulkcompletion.php', ['id' => $courseid]),
new lang_string('bulkactivitycompletion', 'completion')
);
}
return $tabs;
}
|
php
|
public static function get_available_completion_tabs($courseorid) {
$tabs = [];
$courseid = is_object($courseorid) ? $courseorid->id : $courseorid;
$coursecontext = context_course::instance($courseid);
if (has_capability('moodle/course:update', $coursecontext)) {
$tabs[] = new tabobject(
'completion',
new moodle_url('/course/completion.php', ['id' => $courseid]),
new lang_string('coursecompletion', 'completion')
);
}
if (has_capability('moodle/course:manageactivities', $coursecontext)) {
$tabs[] = new tabobject(
'defaultcompletion',
new moodle_url('/course/defaultcompletion.php', ['id' => $courseid]),
new lang_string('defaultcompletion', 'completion')
);
}
if (self::can_edit_bulk_completion($courseorid)) {
$tabs[] = new tabobject(
'bulkcompletion',
new moodle_url('/course/bulkcompletion.php', ['id' => $courseid]),
new lang_string('bulkactivitycompletion', 'completion')
);
}
return $tabs;
}
|
[
"public",
"static",
"function",
"get_available_completion_tabs",
"(",
"$",
"courseorid",
")",
"{",
"$",
"tabs",
"=",
"[",
"]",
";",
"$",
"courseid",
"=",
"is_object",
"(",
"$",
"courseorid",
")",
"?",
"$",
"courseorid",
"->",
"id",
":",
"$",
"courseorid",
";",
"$",
"coursecontext",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"courseid",
")",
";",
"if",
"(",
"has_capability",
"(",
"'moodle/course:update'",
",",
"$",
"coursecontext",
")",
")",
"{",
"$",
"tabs",
"[",
"]",
"=",
"new",
"tabobject",
"(",
"'completion'",
",",
"new",
"moodle_url",
"(",
"'/course/completion.php'",
",",
"[",
"'id'",
"=>",
"$",
"courseid",
"]",
")",
",",
"new",
"lang_string",
"(",
"'coursecompletion'",
",",
"'completion'",
")",
")",
";",
"}",
"if",
"(",
"has_capability",
"(",
"'moodle/course:manageactivities'",
",",
"$",
"coursecontext",
")",
")",
"{",
"$",
"tabs",
"[",
"]",
"=",
"new",
"tabobject",
"(",
"'defaultcompletion'",
",",
"new",
"moodle_url",
"(",
"'/course/defaultcompletion.php'",
",",
"[",
"'id'",
"=>",
"$",
"courseid",
"]",
")",
",",
"new",
"lang_string",
"(",
"'defaultcompletion'",
",",
"'completion'",
")",
")",
";",
"}",
"if",
"(",
"self",
"::",
"can_edit_bulk_completion",
"(",
"$",
"courseorid",
")",
")",
"{",
"$",
"tabs",
"[",
"]",
"=",
"new",
"tabobject",
"(",
"'bulkcompletion'",
",",
"new",
"moodle_url",
"(",
"'/course/bulkcompletion.php'",
",",
"[",
"'id'",
"=>",
"$",
"courseid",
"]",
")",
",",
"new",
"lang_string",
"(",
"'bulkactivitycompletion'",
",",
"'completion'",
")",
")",
";",
"}",
"return",
"$",
"tabs",
";",
"}"
] |
Gets the available completion tabs for the current course and user.
@param stdClass|int $courseorid the course object or id.
@return tabobject[]
|
[
"Gets",
"the",
"available",
"completion",
"tabs",
"for",
"the",
"current",
"course",
"and",
"user",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/classes/manager.php#L262-L293
|
220,038
|
moodle/moodle
|
completion/classes/manager.php
|
manager.apply_completion
|
public function apply_completion($data, $updateinstances) {
$updated = false;
$needreset = [];
$modinfo = get_fast_modinfo($this->courseid);
$cmids = $data->cmid;
$data = (array)$data;
unset($data['id']); // This is a course id, we don't want to confuse it with cmid or instance id.
unset($data['cmid']);
unset($data['submitbutton']);
foreach ($cmids as $cmid) {
$cm = $modinfo->get_cm($cmid);
if (self::can_edit_bulk_completion($this->courseid, $cm) && $this->apply_completion_cm($cm, $data, $updateinstances)) {
$updated = true;
if ($cm->completion != COMPLETION_TRACKING_MANUAL || $data['completion'] != COMPLETION_TRACKING_MANUAL) {
// If completion was changed we will need to reset it's state. Exception is when completion was and remains as manual.
$needreset[] = $cm->id;
}
}
// Update completion calendar events.
$completionexpected = ($data['completionexpected']) ? $data['completionexpected'] : null;
\core_completion\api::update_completion_date_event($cm->id, $cm->modname, $cm->instance, $completionexpected);
}
if ($updated) {
// Now that modules are fully updated, also update completion data if required.
// This will wipe all user completion data and recalculate it.
rebuild_course_cache($this->courseid, true);
$modinfo = get_fast_modinfo($this->courseid);
$completion = new \completion_info($modinfo->get_course());
foreach ($needreset as $cmid) {
$completion->reset_all_state($modinfo->get_cm($cmid));
}
// And notify the user of the result.
\core\notification::add(get_string('activitycompletionupdated', 'core_completion'), \core\notification::SUCCESS);
}
}
|
php
|
public function apply_completion($data, $updateinstances) {
$updated = false;
$needreset = [];
$modinfo = get_fast_modinfo($this->courseid);
$cmids = $data->cmid;
$data = (array)$data;
unset($data['id']); // This is a course id, we don't want to confuse it with cmid or instance id.
unset($data['cmid']);
unset($data['submitbutton']);
foreach ($cmids as $cmid) {
$cm = $modinfo->get_cm($cmid);
if (self::can_edit_bulk_completion($this->courseid, $cm) && $this->apply_completion_cm($cm, $data, $updateinstances)) {
$updated = true;
if ($cm->completion != COMPLETION_TRACKING_MANUAL || $data['completion'] != COMPLETION_TRACKING_MANUAL) {
// If completion was changed we will need to reset it's state. Exception is when completion was and remains as manual.
$needreset[] = $cm->id;
}
}
// Update completion calendar events.
$completionexpected = ($data['completionexpected']) ? $data['completionexpected'] : null;
\core_completion\api::update_completion_date_event($cm->id, $cm->modname, $cm->instance, $completionexpected);
}
if ($updated) {
// Now that modules are fully updated, also update completion data if required.
// This will wipe all user completion data and recalculate it.
rebuild_course_cache($this->courseid, true);
$modinfo = get_fast_modinfo($this->courseid);
$completion = new \completion_info($modinfo->get_course());
foreach ($needreset as $cmid) {
$completion->reset_all_state($modinfo->get_cm($cmid));
}
// And notify the user of the result.
\core\notification::add(get_string('activitycompletionupdated', 'core_completion'), \core\notification::SUCCESS);
}
}
|
[
"public",
"function",
"apply_completion",
"(",
"$",
"data",
",",
"$",
"updateinstances",
")",
"{",
"$",
"updated",
"=",
"false",
";",
"$",
"needreset",
"=",
"[",
"]",
";",
"$",
"modinfo",
"=",
"get_fast_modinfo",
"(",
"$",
"this",
"->",
"courseid",
")",
";",
"$",
"cmids",
"=",
"$",
"data",
"->",
"cmid",
";",
"$",
"data",
"=",
"(",
"array",
")",
"$",
"data",
";",
"unset",
"(",
"$",
"data",
"[",
"'id'",
"]",
")",
";",
"// This is a course id, we don't want to confuse it with cmid or instance id.",
"unset",
"(",
"$",
"data",
"[",
"'cmid'",
"]",
")",
";",
"unset",
"(",
"$",
"data",
"[",
"'submitbutton'",
"]",
")",
";",
"foreach",
"(",
"$",
"cmids",
"as",
"$",
"cmid",
")",
"{",
"$",
"cm",
"=",
"$",
"modinfo",
"->",
"get_cm",
"(",
"$",
"cmid",
")",
";",
"if",
"(",
"self",
"::",
"can_edit_bulk_completion",
"(",
"$",
"this",
"->",
"courseid",
",",
"$",
"cm",
")",
"&&",
"$",
"this",
"->",
"apply_completion_cm",
"(",
"$",
"cm",
",",
"$",
"data",
",",
"$",
"updateinstances",
")",
")",
"{",
"$",
"updated",
"=",
"true",
";",
"if",
"(",
"$",
"cm",
"->",
"completion",
"!=",
"COMPLETION_TRACKING_MANUAL",
"||",
"$",
"data",
"[",
"'completion'",
"]",
"!=",
"COMPLETION_TRACKING_MANUAL",
")",
"{",
"// If completion was changed we will need to reset it's state. Exception is when completion was and remains as manual.",
"$",
"needreset",
"[",
"]",
"=",
"$",
"cm",
"->",
"id",
";",
"}",
"}",
"// Update completion calendar events.",
"$",
"completionexpected",
"=",
"(",
"$",
"data",
"[",
"'completionexpected'",
"]",
")",
"?",
"$",
"data",
"[",
"'completionexpected'",
"]",
":",
"null",
";",
"\\",
"core_completion",
"\\",
"api",
"::",
"update_completion_date_event",
"(",
"$",
"cm",
"->",
"id",
",",
"$",
"cm",
"->",
"modname",
",",
"$",
"cm",
"->",
"instance",
",",
"$",
"completionexpected",
")",
";",
"}",
"if",
"(",
"$",
"updated",
")",
"{",
"// Now that modules are fully updated, also update completion data if required.",
"// This will wipe all user completion data and recalculate it.",
"rebuild_course_cache",
"(",
"$",
"this",
"->",
"courseid",
",",
"true",
")",
";",
"$",
"modinfo",
"=",
"get_fast_modinfo",
"(",
"$",
"this",
"->",
"courseid",
")",
";",
"$",
"completion",
"=",
"new",
"\\",
"completion_info",
"(",
"$",
"modinfo",
"->",
"get_course",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"needreset",
"as",
"$",
"cmid",
")",
"{",
"$",
"completion",
"->",
"reset_all_state",
"(",
"$",
"modinfo",
"->",
"get_cm",
"(",
"$",
"cmid",
")",
")",
";",
"}",
"// And notify the user of the result.",
"\\",
"core",
"\\",
"notification",
"::",
"add",
"(",
"get_string",
"(",
"'activitycompletionupdated'",
",",
"'core_completion'",
")",
",",
"\\",
"core",
"\\",
"notification",
"::",
"SUCCESS",
")",
";",
"}",
"}"
] |
Applies completion from the bulk edit form to all selected modules
@param stdClass $data data received from the core_completion_bulkedit_form
@param bool $updateinstances if we need to update the instance tables of the module (i.e. 'assign', 'forum', etc.) -
if no module-specific completion rules were added to the form, update of the module table is not needed.
|
[
"Applies",
"completion",
"from",
"the",
"bulk",
"edit",
"form",
"to",
"all",
"selected",
"modules"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/classes/manager.php#L302-L340
|
220,039
|
moodle/moodle
|
completion/classes/manager.php
|
manager.apply_completion_cm
|
protected function apply_completion_cm(\cm_info $cm, $data, $updateinstance) {
global $DB;
$defaults = ['completion' => COMPLETION_DISABLED, 'completionview' => COMPLETION_VIEW_NOT_REQUIRED,
'completionexpected' => 0, 'completiongradeitemnumber' => null];
$data += ['completion' => $cm->completion,
'completionexpected' => $cm->completionexpected,
'completionview' => $cm->completionview];
if ($cm->completion == $data['completion'] && $cm->completion == COMPLETION_TRACKING_NONE) {
// If old and new completion are both "none" - no changes are needed.
return false;
}
if ($cm->completion == $data['completion'] && $cm->completion == COMPLETION_TRACKING_NONE &&
$cm->completionexpected == $data['completionexpected']) {
// If old and new completion are both "manual" and completion expected date is not changed - no changes are needed.
return false;
}
if (array_key_exists('completionusegrade', $data)) {
// Convert the 'use grade' checkbox into a grade-item number: 0 if checked, null if not.
$data['completiongradeitemnumber'] = !empty($data['completionusegrade']) ? 0 : null;
unset($data['completionusegrade']);
} else {
$data['completiongradeitemnumber'] = $cm->completiongradeitemnumber;
}
// Update module instance table.
if ($updateinstance) {
$moddata = ['id' => $cm->instance, 'timemodified' => time()] + array_diff_key($data, $defaults);
$DB->update_record($cm->modname, $moddata);
}
// Update course modules table.
$cmdata = ['id' => $cm->id, 'timemodified' => time()] + array_intersect_key($data, $defaults);
$DB->update_record('course_modules', $cmdata);
\core\event\course_module_updated::create_from_cm($cm, $cm->context)->trigger();
// We need to reset completion data for this activity.
return true;
}
|
php
|
protected function apply_completion_cm(\cm_info $cm, $data, $updateinstance) {
global $DB;
$defaults = ['completion' => COMPLETION_DISABLED, 'completionview' => COMPLETION_VIEW_NOT_REQUIRED,
'completionexpected' => 0, 'completiongradeitemnumber' => null];
$data += ['completion' => $cm->completion,
'completionexpected' => $cm->completionexpected,
'completionview' => $cm->completionview];
if ($cm->completion == $data['completion'] && $cm->completion == COMPLETION_TRACKING_NONE) {
// If old and new completion are both "none" - no changes are needed.
return false;
}
if ($cm->completion == $data['completion'] && $cm->completion == COMPLETION_TRACKING_NONE &&
$cm->completionexpected == $data['completionexpected']) {
// If old and new completion are both "manual" and completion expected date is not changed - no changes are needed.
return false;
}
if (array_key_exists('completionusegrade', $data)) {
// Convert the 'use grade' checkbox into a grade-item number: 0 if checked, null if not.
$data['completiongradeitemnumber'] = !empty($data['completionusegrade']) ? 0 : null;
unset($data['completionusegrade']);
} else {
$data['completiongradeitemnumber'] = $cm->completiongradeitemnumber;
}
// Update module instance table.
if ($updateinstance) {
$moddata = ['id' => $cm->instance, 'timemodified' => time()] + array_diff_key($data, $defaults);
$DB->update_record($cm->modname, $moddata);
}
// Update course modules table.
$cmdata = ['id' => $cm->id, 'timemodified' => time()] + array_intersect_key($data, $defaults);
$DB->update_record('course_modules', $cmdata);
\core\event\course_module_updated::create_from_cm($cm, $cm->context)->trigger();
// We need to reset completion data for this activity.
return true;
}
|
[
"protected",
"function",
"apply_completion_cm",
"(",
"\\",
"cm_info",
"$",
"cm",
",",
"$",
"data",
",",
"$",
"updateinstance",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"defaults",
"=",
"[",
"'completion'",
"=>",
"COMPLETION_DISABLED",
",",
"'completionview'",
"=>",
"COMPLETION_VIEW_NOT_REQUIRED",
",",
"'completionexpected'",
"=>",
"0",
",",
"'completiongradeitemnumber'",
"=>",
"null",
"]",
";",
"$",
"data",
"+=",
"[",
"'completion'",
"=>",
"$",
"cm",
"->",
"completion",
",",
"'completionexpected'",
"=>",
"$",
"cm",
"->",
"completionexpected",
",",
"'completionview'",
"=>",
"$",
"cm",
"->",
"completionview",
"]",
";",
"if",
"(",
"$",
"cm",
"->",
"completion",
"==",
"$",
"data",
"[",
"'completion'",
"]",
"&&",
"$",
"cm",
"->",
"completion",
"==",
"COMPLETION_TRACKING_NONE",
")",
"{",
"// If old and new completion are both \"none\" - no changes are needed.",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"cm",
"->",
"completion",
"==",
"$",
"data",
"[",
"'completion'",
"]",
"&&",
"$",
"cm",
"->",
"completion",
"==",
"COMPLETION_TRACKING_NONE",
"&&",
"$",
"cm",
"->",
"completionexpected",
"==",
"$",
"data",
"[",
"'completionexpected'",
"]",
")",
"{",
"// If old and new completion are both \"manual\" and completion expected date is not changed - no changes are needed.",
"return",
"false",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"'completionusegrade'",
",",
"$",
"data",
")",
")",
"{",
"// Convert the 'use grade' checkbox into a grade-item number: 0 if checked, null if not.",
"$",
"data",
"[",
"'completiongradeitemnumber'",
"]",
"=",
"!",
"empty",
"(",
"$",
"data",
"[",
"'completionusegrade'",
"]",
")",
"?",
"0",
":",
"null",
";",
"unset",
"(",
"$",
"data",
"[",
"'completionusegrade'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"data",
"[",
"'completiongradeitemnumber'",
"]",
"=",
"$",
"cm",
"->",
"completiongradeitemnumber",
";",
"}",
"// Update module instance table.",
"if",
"(",
"$",
"updateinstance",
")",
"{",
"$",
"moddata",
"=",
"[",
"'id'",
"=>",
"$",
"cm",
"->",
"instance",
",",
"'timemodified'",
"=>",
"time",
"(",
")",
"]",
"+",
"array_diff_key",
"(",
"$",
"data",
",",
"$",
"defaults",
")",
";",
"$",
"DB",
"->",
"update_record",
"(",
"$",
"cm",
"->",
"modname",
",",
"$",
"moddata",
")",
";",
"}",
"// Update course modules table.",
"$",
"cmdata",
"=",
"[",
"'id'",
"=>",
"$",
"cm",
"->",
"id",
",",
"'timemodified'",
"=>",
"time",
"(",
")",
"]",
"+",
"array_intersect_key",
"(",
"$",
"data",
",",
"$",
"defaults",
")",
";",
"$",
"DB",
"->",
"update_record",
"(",
"'course_modules'",
",",
"$",
"cmdata",
")",
";",
"\\",
"core",
"\\",
"event",
"\\",
"course_module_updated",
"::",
"create_from_cm",
"(",
"$",
"cm",
",",
"$",
"cm",
"->",
"context",
")",
"->",
"trigger",
"(",
")",
";",
"// We need to reset completion data for this activity.",
"return",
"true",
";",
"}"
] |
Applies new completion rules to one course module
@param \cm_info $cm
@param array $data
@param bool $updateinstance if we need to update the instance table of the module (i.e. 'assign', 'forum', etc.) -
if no module-specific completion rules were added to the form, update of the module table is not needed.
@return bool if module was updated
|
[
"Applies",
"new",
"completion",
"rules",
"to",
"one",
"course",
"module"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/classes/manager.php#L351-L394
|
220,040
|
moodle/moodle
|
completion/classes/manager.php
|
manager.apply_default_completion
|
public function apply_default_completion($data, $updatecustomrules) {
global $DB;
$courseid = $data->id;
$coursecontext = context_course::instance($courseid);
if (!$modids = $data->modids) {
return;
}
$defaults = [
'completion' => COMPLETION_DISABLED,
'completionview' => COMPLETION_VIEW_NOT_REQUIRED,
'completionexpected' => 0,
'completionusegrade' => 0
];
$data = (array)$data;
if ($updatecustomrules) {
$customdata = array_diff_key($data, $defaults);
$data['customrules'] = $customdata ? json_encode($customdata) : null;
$defaults['customrules'] = null;
}
$data = array_intersect_key($data, $defaults);
// Get names of the affected modules.
list($modidssql, $params) = $DB->get_in_or_equal($modids);
$params[] = 1;
$modules = $DB->get_records_select_menu('modules', 'id ' . $modidssql . ' and visible = ?', $params, '', 'id, name');
// Get an associative array of [module_id => course_completion_defaults_id].
list($in, $params) = $DB->get_in_or_equal($modids);
$params[] = $courseid;
$defaultsids = $DB->get_records_select_menu('course_completion_defaults', 'module ' . $in . ' and course = ?', $params, '',
'module, id');
foreach ($modids as $modid) {
if (!array_key_exists($modid, $modules)) {
continue;
}
if (isset($defaultsids[$modid])) {
$DB->update_record('course_completion_defaults', $data + ['id' => $defaultsids[$modid]]);
} else {
$defaultsids[$modid] = $DB->insert_record('course_completion_defaults', $data + ['course' => $courseid,
'module' => $modid]);
}
// Trigger event.
\core\event\completion_defaults_updated::create([
'objectid' => $defaultsids[$modid],
'context' => $coursecontext,
'other' => ['modulename' => $modules[$modid]],
])->trigger();
}
// Add notification.
\core\notification::add(get_string('defaultcompletionupdated', 'completion'), \core\notification::SUCCESS);
}
|
php
|
public function apply_default_completion($data, $updatecustomrules) {
global $DB;
$courseid = $data->id;
$coursecontext = context_course::instance($courseid);
if (!$modids = $data->modids) {
return;
}
$defaults = [
'completion' => COMPLETION_DISABLED,
'completionview' => COMPLETION_VIEW_NOT_REQUIRED,
'completionexpected' => 0,
'completionusegrade' => 0
];
$data = (array)$data;
if ($updatecustomrules) {
$customdata = array_diff_key($data, $defaults);
$data['customrules'] = $customdata ? json_encode($customdata) : null;
$defaults['customrules'] = null;
}
$data = array_intersect_key($data, $defaults);
// Get names of the affected modules.
list($modidssql, $params) = $DB->get_in_or_equal($modids);
$params[] = 1;
$modules = $DB->get_records_select_menu('modules', 'id ' . $modidssql . ' and visible = ?', $params, '', 'id, name');
// Get an associative array of [module_id => course_completion_defaults_id].
list($in, $params) = $DB->get_in_or_equal($modids);
$params[] = $courseid;
$defaultsids = $DB->get_records_select_menu('course_completion_defaults', 'module ' . $in . ' and course = ?', $params, '',
'module, id');
foreach ($modids as $modid) {
if (!array_key_exists($modid, $modules)) {
continue;
}
if (isset($defaultsids[$modid])) {
$DB->update_record('course_completion_defaults', $data + ['id' => $defaultsids[$modid]]);
} else {
$defaultsids[$modid] = $DB->insert_record('course_completion_defaults', $data + ['course' => $courseid,
'module' => $modid]);
}
// Trigger event.
\core\event\completion_defaults_updated::create([
'objectid' => $defaultsids[$modid],
'context' => $coursecontext,
'other' => ['modulename' => $modules[$modid]],
])->trigger();
}
// Add notification.
\core\notification::add(get_string('defaultcompletionupdated', 'completion'), \core\notification::SUCCESS);
}
|
[
"public",
"function",
"apply_default_completion",
"(",
"$",
"data",
",",
"$",
"updatecustomrules",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"courseid",
"=",
"$",
"data",
"->",
"id",
";",
"$",
"coursecontext",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"courseid",
")",
";",
"if",
"(",
"!",
"$",
"modids",
"=",
"$",
"data",
"->",
"modids",
")",
"{",
"return",
";",
"}",
"$",
"defaults",
"=",
"[",
"'completion'",
"=>",
"COMPLETION_DISABLED",
",",
"'completionview'",
"=>",
"COMPLETION_VIEW_NOT_REQUIRED",
",",
"'completionexpected'",
"=>",
"0",
",",
"'completionusegrade'",
"=>",
"0",
"]",
";",
"$",
"data",
"=",
"(",
"array",
")",
"$",
"data",
";",
"if",
"(",
"$",
"updatecustomrules",
")",
"{",
"$",
"customdata",
"=",
"array_diff_key",
"(",
"$",
"data",
",",
"$",
"defaults",
")",
";",
"$",
"data",
"[",
"'customrules'",
"]",
"=",
"$",
"customdata",
"?",
"json_encode",
"(",
"$",
"customdata",
")",
":",
"null",
";",
"$",
"defaults",
"[",
"'customrules'",
"]",
"=",
"null",
";",
"}",
"$",
"data",
"=",
"array_intersect_key",
"(",
"$",
"data",
",",
"$",
"defaults",
")",
";",
"// Get names of the affected modules.",
"list",
"(",
"$",
"modidssql",
",",
"$",
"params",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"modids",
")",
";",
"$",
"params",
"[",
"]",
"=",
"1",
";",
"$",
"modules",
"=",
"$",
"DB",
"->",
"get_records_select_menu",
"(",
"'modules'",
",",
"'id '",
".",
"$",
"modidssql",
".",
"' and visible = ?'",
",",
"$",
"params",
",",
"''",
",",
"'id, name'",
")",
";",
"// Get an associative array of [module_id => course_completion_defaults_id].",
"list",
"(",
"$",
"in",
",",
"$",
"params",
")",
"=",
"$",
"DB",
"->",
"get_in_or_equal",
"(",
"$",
"modids",
")",
";",
"$",
"params",
"[",
"]",
"=",
"$",
"courseid",
";",
"$",
"defaultsids",
"=",
"$",
"DB",
"->",
"get_records_select_menu",
"(",
"'course_completion_defaults'",
",",
"'module '",
".",
"$",
"in",
".",
"' and course = ?'",
",",
"$",
"params",
",",
"''",
",",
"'module, id'",
")",
";",
"foreach",
"(",
"$",
"modids",
"as",
"$",
"modid",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"modid",
",",
"$",
"modules",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"defaultsids",
"[",
"$",
"modid",
"]",
")",
")",
"{",
"$",
"DB",
"->",
"update_record",
"(",
"'course_completion_defaults'",
",",
"$",
"data",
"+",
"[",
"'id'",
"=>",
"$",
"defaultsids",
"[",
"$",
"modid",
"]",
"]",
")",
";",
"}",
"else",
"{",
"$",
"defaultsids",
"[",
"$",
"modid",
"]",
"=",
"$",
"DB",
"->",
"insert_record",
"(",
"'course_completion_defaults'",
",",
"$",
"data",
"+",
"[",
"'course'",
"=>",
"$",
"courseid",
",",
"'module'",
"=>",
"$",
"modid",
"]",
")",
";",
"}",
"// Trigger event.",
"\\",
"core",
"\\",
"event",
"\\",
"completion_defaults_updated",
"::",
"create",
"(",
"[",
"'objectid'",
"=>",
"$",
"defaultsids",
"[",
"$",
"modid",
"]",
",",
"'context'",
"=>",
"$",
"coursecontext",
",",
"'other'",
"=>",
"[",
"'modulename'",
"=>",
"$",
"modules",
"[",
"$",
"modid",
"]",
"]",
",",
"]",
")",
"->",
"trigger",
"(",
")",
";",
"}",
"// Add notification.",
"\\",
"core",
"\\",
"notification",
"::",
"add",
"(",
"get_string",
"(",
"'defaultcompletionupdated'",
",",
"'completion'",
")",
",",
"\\",
"core",
"\\",
"notification",
"::",
"SUCCESS",
")",
";",
"}"
] |
Saves default completion from edit form to all selected module types
@param stdClass $data data received from the core_completion_bulkedit_form
@param bool $updatecustomrules if we need to update the custom rules of the module -
if no module-specific completion rules were added to the form, update of the module table is not needed.
|
[
"Saves",
"default",
"completion",
"from",
"edit",
"form",
"to",
"all",
"selected",
"module",
"types"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/classes/manager.php#L404-L459
|
220,041
|
moodle/moodle
|
completion/classes/manager.php
|
manager.get_default_completion
|
public static function get_default_completion($course, $module, $flatten = true) {
global $DB, $CFG;
if ($data = $DB->get_record('course_completion_defaults', ['course' => $course->id, 'module' => $module->id],
'completion, completionview, completionexpected, completionusegrade, customrules')) {
if ($data->customrules && ($customrules = @json_decode($data->customrules, true))) {
if ($flatten) {
foreach ($customrules as $key => $value) {
$data->$key = $value;
}
} else {
$data->customdata['customcompletionrules'] = $customrules;
}
}
unset($data->customrules);
} else {
$data = new stdClass();
$data->completion = COMPLETION_TRACKING_NONE;
if ($CFG->completiondefault) {
$completion = new \completion_info(get_fast_modinfo($course->id)->get_course());
if ($completion->is_enabled() && plugin_supports('mod', $module->name, FEATURE_MODEDIT_DEFAULT_COMPLETION, true)) {
$data->completion = COMPLETION_TRACKING_MANUAL;
$data->completionview = 1;
}
}
}
return $data;
}
|
php
|
public static function get_default_completion($course, $module, $flatten = true) {
global $DB, $CFG;
if ($data = $DB->get_record('course_completion_defaults', ['course' => $course->id, 'module' => $module->id],
'completion, completionview, completionexpected, completionusegrade, customrules')) {
if ($data->customrules && ($customrules = @json_decode($data->customrules, true))) {
if ($flatten) {
foreach ($customrules as $key => $value) {
$data->$key = $value;
}
} else {
$data->customdata['customcompletionrules'] = $customrules;
}
}
unset($data->customrules);
} else {
$data = new stdClass();
$data->completion = COMPLETION_TRACKING_NONE;
if ($CFG->completiondefault) {
$completion = new \completion_info(get_fast_modinfo($course->id)->get_course());
if ($completion->is_enabled() && plugin_supports('mod', $module->name, FEATURE_MODEDIT_DEFAULT_COMPLETION, true)) {
$data->completion = COMPLETION_TRACKING_MANUAL;
$data->completionview = 1;
}
}
}
return $data;
}
|
[
"public",
"static",
"function",
"get_default_completion",
"(",
"$",
"course",
",",
"$",
"module",
",",
"$",
"flatten",
"=",
"true",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"CFG",
";",
"if",
"(",
"$",
"data",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'course_completion_defaults'",
",",
"[",
"'course'",
"=>",
"$",
"course",
"->",
"id",
",",
"'module'",
"=>",
"$",
"module",
"->",
"id",
"]",
",",
"'completion, completionview, completionexpected, completionusegrade, customrules'",
")",
")",
"{",
"if",
"(",
"$",
"data",
"->",
"customrules",
"&&",
"(",
"$",
"customrules",
"=",
"@",
"json_decode",
"(",
"$",
"data",
"->",
"customrules",
",",
"true",
")",
")",
")",
"{",
"if",
"(",
"$",
"flatten",
")",
"{",
"foreach",
"(",
"$",
"customrules",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"data",
"->",
"$",
"key",
"=",
"$",
"value",
";",
"}",
"}",
"else",
"{",
"$",
"data",
"->",
"customdata",
"[",
"'customcompletionrules'",
"]",
"=",
"$",
"customrules",
";",
"}",
"}",
"unset",
"(",
"$",
"data",
"->",
"customrules",
")",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"data",
"->",
"completion",
"=",
"COMPLETION_TRACKING_NONE",
";",
"if",
"(",
"$",
"CFG",
"->",
"completiondefault",
")",
"{",
"$",
"completion",
"=",
"new",
"\\",
"completion_info",
"(",
"get_fast_modinfo",
"(",
"$",
"course",
"->",
"id",
")",
"->",
"get_course",
"(",
")",
")",
";",
"if",
"(",
"$",
"completion",
"->",
"is_enabled",
"(",
")",
"&&",
"plugin_supports",
"(",
"'mod'",
",",
"$",
"module",
"->",
"name",
",",
"FEATURE_MODEDIT_DEFAULT_COMPLETION",
",",
"true",
")",
")",
"{",
"$",
"data",
"->",
"completion",
"=",
"COMPLETION_TRACKING_MANUAL",
";",
"$",
"data",
"->",
"completionview",
"=",
"1",
";",
"}",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] |
Returns default completion rules for given module type in the given course
@param stdClass $course
@param stdClass $module
@param bool $flatten if true all module custom completion rules become properties of the same object,
otherwise they can be found as array in ->customdata['customcompletionrules']
@return stdClass
|
[
"Returns",
"default",
"completion",
"rules",
"for",
"given",
"module",
"type",
"in",
"the",
"given",
"course"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/classes/manager.php#L470-L496
|
220,042
|
moodle/moodle
|
mod/assign/feedback/comments/backup/moodle2/restore_assignfeedback_comments_subplugin.class.php
|
restore_assignfeedback_comments_subplugin.process_assignfeedback_comments_grade
|
public function process_assignfeedback_comments_grade($data) {
global $DB;
$data = (object)$data;
$data->assignment = $this->get_new_parentid('assign');
$oldgradeid = $data->grade;
// The mapping is set in the restore for the core assign activity
// when a grade node is processed.
$data->grade = $this->get_mappingid('grade', $data->grade);
$DB->insert_record('assignfeedback_comments', $data);
$this->add_related_files(
'assignfeedback_comments',
'feedback',
'grade',
null,
$oldgradeid
);
}
|
php
|
public function process_assignfeedback_comments_grade($data) {
global $DB;
$data = (object)$data;
$data->assignment = $this->get_new_parentid('assign');
$oldgradeid = $data->grade;
// The mapping is set in the restore for the core assign activity
// when a grade node is processed.
$data->grade = $this->get_mappingid('grade', $data->grade);
$DB->insert_record('assignfeedback_comments', $data);
$this->add_related_files(
'assignfeedback_comments',
'feedback',
'grade',
null,
$oldgradeid
);
}
|
[
"public",
"function",
"process_assignfeedback_comments_grade",
"(",
"$",
"data",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"data",
"=",
"(",
"object",
")",
"$",
"data",
";",
"$",
"data",
"->",
"assignment",
"=",
"$",
"this",
"->",
"get_new_parentid",
"(",
"'assign'",
")",
";",
"$",
"oldgradeid",
"=",
"$",
"data",
"->",
"grade",
";",
"// The mapping is set in the restore for the core assign activity",
"// when a grade node is processed.",
"$",
"data",
"->",
"grade",
"=",
"$",
"this",
"->",
"get_mappingid",
"(",
"'grade'",
",",
"$",
"data",
"->",
"grade",
")",
";",
"$",
"DB",
"->",
"insert_record",
"(",
"'assignfeedback_comments'",
",",
"$",
"data",
")",
";",
"$",
"this",
"->",
"add_related_files",
"(",
"'assignfeedback_comments'",
",",
"'feedback'",
",",
"'grade'",
",",
"null",
",",
"$",
"oldgradeid",
")",
";",
"}"
] |
Processes one feedback_comments element.
@param mixed $data
|
[
"Processes",
"one",
"feedback_comments",
"element",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/feedback/comments/backup/moodle2/restore_assignfeedback_comments_subplugin.class.php#L63-L82
|
220,043
|
moodle/moodle
|
auth/cas/CAS/CAS/ProxiedService/Http/Abstract.php
|
CAS_ProxiedService_Http_Abstract.setUrl
|
public function setUrl($url)
{
if ($this->hasBeenSent()) {
throw new CAS_OutOfSequenceException(
'Cannot set the URL, request already sent.'
);
}
if (!is_string($url)) {
throw new CAS_InvalidArgumentException('$url must be a string.');
}
$this->_url = $url;
}
|
php
|
public function setUrl($url)
{
if ($this->hasBeenSent()) {
throw new CAS_OutOfSequenceException(
'Cannot set the URL, request already sent.'
);
}
if (!is_string($url)) {
throw new CAS_InvalidArgumentException('$url must be a string.');
}
$this->_url = $url;
}
|
[
"public",
"function",
"setUrl",
"(",
"$",
"url",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasBeenSent",
"(",
")",
")",
"{",
"throw",
"new",
"CAS_OutOfSequenceException",
"(",
"'Cannot set the URL, request already sent.'",
")",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"url",
")",
")",
"{",
"throw",
"new",
"CAS_InvalidArgumentException",
"(",
"'$url must be a string.'",
")",
";",
"}",
"$",
"this",
"->",
"_url",
"=",
"$",
"url",
";",
"}"
] |
Set the URL of the Request
@param string $url url to set
@return void
@throws CAS_OutOfSequenceException If called after the Request has been sent.
|
[
"Set",
"the",
"URL",
"of",
"the",
"Request"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/ProxiedService/Http/Abstract.php#L108-L120
|
220,044
|
moodle/moodle
|
auth/cas/CAS/CAS/ProxiedService/Http/Abstract.php
|
CAS_ProxiedService_Http_Abstract.makeRequest
|
protected function makeRequest($url)
{
// Verify that we are not in a redirect loop
$this->_numRequests++;
if ($this->_numRequests > 4) {
$message = 'Exceeded the maximum number of redirects (3) in proxied service request.';
phpCAS::trace($message);
throw new CAS_ProxiedService_Exception($message);
}
// Create a new request.
$request = clone $this->requestHandler;
$request->setUrl($url);
// Add any cookies to the request.
$request->addCookies($this->_cookieJar->getCookies($url));
// Add any other parts of the request needed by concrete classes
$this->populateRequest($request);
// Perform the request.
phpCAS::trace('Performing proxied service request to \'' . $url . '\'');
if (!$request->send()) {
$message = 'Could not perform proxied service request to URL`'
. $url . '\'. ' . $request->getErrorMessage();
phpCAS::trace($message);
throw new CAS_ProxiedService_Exception($message);
}
// Store any cookies from the response;
$this->_cookieJar->storeCookies($url, $request->getResponseHeaders());
// Follow any redirects
if ($redirectUrl = $this->getRedirectUrl($request->getResponseHeaders())
) {
phpCAS::trace('Found redirect:' . $redirectUrl);
$this->makeRequest($redirectUrl);
} else {
$this->_responseHeaders = $request->getResponseHeaders();
$this->_responseBody = $request->getResponseBody();
$this->_responseStatusCode = $request->getResponseStatusCode();
}
}
|
php
|
protected function makeRequest($url)
{
// Verify that we are not in a redirect loop
$this->_numRequests++;
if ($this->_numRequests > 4) {
$message = 'Exceeded the maximum number of redirects (3) in proxied service request.';
phpCAS::trace($message);
throw new CAS_ProxiedService_Exception($message);
}
// Create a new request.
$request = clone $this->requestHandler;
$request->setUrl($url);
// Add any cookies to the request.
$request->addCookies($this->_cookieJar->getCookies($url));
// Add any other parts of the request needed by concrete classes
$this->populateRequest($request);
// Perform the request.
phpCAS::trace('Performing proxied service request to \'' . $url . '\'');
if (!$request->send()) {
$message = 'Could not perform proxied service request to URL`'
. $url . '\'. ' . $request->getErrorMessage();
phpCAS::trace($message);
throw new CAS_ProxiedService_Exception($message);
}
// Store any cookies from the response;
$this->_cookieJar->storeCookies($url, $request->getResponseHeaders());
// Follow any redirects
if ($redirectUrl = $this->getRedirectUrl($request->getResponseHeaders())
) {
phpCAS::trace('Found redirect:' . $redirectUrl);
$this->makeRequest($redirectUrl);
} else {
$this->_responseHeaders = $request->getResponseHeaders();
$this->_responseBody = $request->getResponseBody();
$this->_responseStatusCode = $request->getResponseStatusCode();
}
}
|
[
"protected",
"function",
"makeRequest",
"(",
"$",
"url",
")",
"{",
"// Verify that we are not in a redirect loop",
"$",
"this",
"->",
"_numRequests",
"++",
";",
"if",
"(",
"$",
"this",
"->",
"_numRequests",
">",
"4",
")",
"{",
"$",
"message",
"=",
"'Exceeded the maximum number of redirects (3) in proxied service request.'",
";",
"phpCAS",
"::",
"trace",
"(",
"$",
"message",
")",
";",
"throw",
"new",
"CAS_ProxiedService_Exception",
"(",
"$",
"message",
")",
";",
"}",
"// Create a new request.",
"$",
"request",
"=",
"clone",
"$",
"this",
"->",
"requestHandler",
";",
"$",
"request",
"->",
"setUrl",
"(",
"$",
"url",
")",
";",
"// Add any cookies to the request.",
"$",
"request",
"->",
"addCookies",
"(",
"$",
"this",
"->",
"_cookieJar",
"->",
"getCookies",
"(",
"$",
"url",
")",
")",
";",
"// Add any other parts of the request needed by concrete classes",
"$",
"this",
"->",
"populateRequest",
"(",
"$",
"request",
")",
";",
"// Perform the request.",
"phpCAS",
"::",
"trace",
"(",
"'Performing proxied service request to \\''",
".",
"$",
"url",
".",
"'\\''",
")",
";",
"if",
"(",
"!",
"$",
"request",
"->",
"send",
"(",
")",
")",
"{",
"$",
"message",
"=",
"'Could not perform proxied service request to URL`'",
".",
"$",
"url",
".",
"'\\'. '",
".",
"$",
"request",
"->",
"getErrorMessage",
"(",
")",
";",
"phpCAS",
"::",
"trace",
"(",
"$",
"message",
")",
";",
"throw",
"new",
"CAS_ProxiedService_Exception",
"(",
"$",
"message",
")",
";",
"}",
"// Store any cookies from the response;",
"$",
"this",
"->",
"_cookieJar",
"->",
"storeCookies",
"(",
"$",
"url",
",",
"$",
"request",
"->",
"getResponseHeaders",
"(",
")",
")",
";",
"// Follow any redirects",
"if",
"(",
"$",
"redirectUrl",
"=",
"$",
"this",
"->",
"getRedirectUrl",
"(",
"$",
"request",
"->",
"getResponseHeaders",
"(",
")",
")",
")",
"{",
"phpCAS",
"::",
"trace",
"(",
"'Found redirect:'",
".",
"$",
"redirectUrl",
")",
";",
"$",
"this",
"->",
"makeRequest",
"(",
"$",
"redirectUrl",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_responseHeaders",
"=",
"$",
"request",
"->",
"getResponseHeaders",
"(",
")",
";",
"$",
"this",
"->",
"_responseBody",
"=",
"$",
"request",
"->",
"getResponseBody",
"(",
")",
";",
"$",
"this",
"->",
"_responseStatusCode",
"=",
"$",
"request",
"->",
"getResponseStatusCode",
"(",
")",
";",
"}",
"}"
] |
Build and perform a request, following redirects
@param string $url url for the request
@return void
@throws CAS_ProxyTicketException If there is a proxy-ticket failure.
The code of the Exception will be one of:
PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE
PHPCAS_SERVICE_PT_BAD_SERVER_RESPONSE
PHPCAS_SERVICE_PT_FAILURE
@throws CAS_ProxiedService_Exception If there is a failure sending the
request to the target service.
|
[
"Build",
"and",
"perform",
"a",
"request",
"following",
"redirects"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/ProxiedService/Http/Abstract.php#L208-L251
|
220,045
|
moodle/moodle
|
auth/cas/CAS/CAS/ProxiedService/Http/Abstract.php
|
CAS_ProxiedService_Http_Abstract.getRedirectUrl
|
protected function getRedirectUrl(array $responseHeaders)
{
// Check for the redirect after authentication
foreach ($responseHeaders as $header) {
if ( preg_match('/^(Location:|URI:)\s*([^\s]+.*)$/', $header, $matches)
) {
return trim(array_pop($matches));
}
}
return null;
}
|
php
|
protected function getRedirectUrl(array $responseHeaders)
{
// Check for the redirect after authentication
foreach ($responseHeaders as $header) {
if ( preg_match('/^(Location:|URI:)\s*([^\s]+.*)$/', $header, $matches)
) {
return trim(array_pop($matches));
}
}
return null;
}
|
[
"protected",
"function",
"getRedirectUrl",
"(",
"array",
"$",
"responseHeaders",
")",
"{",
"// Check for the redirect after authentication",
"foreach",
"(",
"$",
"responseHeaders",
"as",
"$",
"header",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/^(Location:|URI:)\\s*([^\\s]+.*)$/'",
",",
"$",
"header",
",",
"$",
"matches",
")",
")",
"{",
"return",
"trim",
"(",
"array_pop",
"(",
"$",
"matches",
")",
")",
";",
"}",
"}",
"return",
"null",
";",
"}"
] |
Answer a redirect URL if a redirect header is found, otherwise null.
@param array $responseHeaders response header to extract a redirect from
@return string or null
|
[
"Answer",
"a",
"redirect",
"URL",
"if",
"a",
"redirect",
"header",
"is",
"found",
"otherwise",
"null",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/ProxiedService/Http/Abstract.php#L271-L281
|
220,046
|
moodle/moodle
|
lib/pagelib.php
|
moodle_page.magic_get_blockmanipulations
|
protected function magic_get_blockmanipulations() {
if (!right_to_left()) {
return false;
}
if (is_null($this->_theme)) {
$this->initialise_theme_and_output();
}
return $this->_theme->blockrtlmanipulations;
}
|
php
|
protected function magic_get_blockmanipulations() {
if (!right_to_left()) {
return false;
}
if (is_null($this->_theme)) {
$this->initialise_theme_and_output();
}
return $this->_theme->blockrtlmanipulations;
}
|
[
"protected",
"function",
"magic_get_blockmanipulations",
"(",
")",
"{",
"if",
"(",
"!",
"right_to_left",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"_theme",
")",
")",
"{",
"$",
"this",
"->",
"initialise_theme_and_output",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_theme",
"->",
"blockrtlmanipulations",
";",
"}"
] |
Returns an array of minipulations or false if there are none to make.
@since Moodle 2.5.1 2.6
@return bool|array
|
[
"Returns",
"an",
"array",
"of",
"minipulations",
"or",
"false",
"if",
"there",
"are",
"none",
"to",
"make",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pagelib.php#L688-L696
|
220,047
|
moodle/moodle
|
lib/pagelib.php
|
moodle_page.magic_get_navigation
|
protected function magic_get_navigation() {
if ($this->_navigation === null) {
$this->_navigation = new global_navigation($this);
}
return $this->_navigation;
}
|
php
|
protected function magic_get_navigation() {
if ($this->_navigation === null) {
$this->_navigation = new global_navigation($this);
}
return $this->_navigation;
}
|
[
"protected",
"function",
"magic_get_navigation",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_navigation",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_navigation",
"=",
"new",
"global_navigation",
"(",
"$",
"this",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_navigation",
";",
"}"
] |
Return the navigation object
@return global_navigation
|
[
"Return",
"the",
"navigation",
"object"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pagelib.php#L734-L739
|
220,048
|
moodle/moodle
|
lib/pagelib.php
|
moodle_page.magic_get_navbar
|
protected function magic_get_navbar() {
if ($this->_navbar === null) {
$this->_navbar = new navbar($this);
}
return $this->_navbar;
}
|
php
|
protected function magic_get_navbar() {
if ($this->_navbar === null) {
$this->_navbar = new navbar($this);
}
return $this->_navbar;
}
|
[
"protected",
"function",
"magic_get_navbar",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_navbar",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_navbar",
"=",
"new",
"navbar",
"(",
"$",
"this",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_navbar",
";",
"}"
] |
Return a navbar object
@return navbar
|
[
"Return",
"a",
"navbar",
"object"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pagelib.php#L745-L750
|
220,049
|
moodle/moodle
|
lib/pagelib.php
|
moodle_page.magic_get_settingsnav
|
protected function magic_get_settingsnav() {
if ($this->_settingsnav === null) {
$this->_settingsnav = new settings_navigation($this);
$this->_settingsnav->initialise();
}
return $this->_settingsnav;
}
|
php
|
protected function magic_get_settingsnav() {
if ($this->_settingsnav === null) {
$this->_settingsnav = new settings_navigation($this);
$this->_settingsnav->initialise();
}
return $this->_settingsnav;
}
|
[
"protected",
"function",
"magic_get_settingsnav",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_settingsnav",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_settingsnav",
"=",
"new",
"settings_navigation",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"_settingsnav",
"->",
"initialise",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_settingsnav",
";",
"}"
] |
Returns the settings navigation object
@return settings_navigation
|
[
"Returns",
"the",
"settings",
"navigation",
"object"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pagelib.php#L756-L762
|
220,050
|
moodle/moodle
|
lib/pagelib.php
|
moodle_page.magic_get_flatnav
|
protected function magic_get_flatnav() {
if ($this->_flatnav === null) {
$this->_flatnav = new flat_navigation($this);
$this->_flatnav->initialise();
}
return $this->_flatnav;
}
|
php
|
protected function magic_get_flatnav() {
if ($this->_flatnav === null) {
$this->_flatnav = new flat_navigation($this);
$this->_flatnav->initialise();
}
return $this->_flatnav;
}
|
[
"protected",
"function",
"magic_get_flatnav",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_flatnav",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_flatnav",
"=",
"new",
"flat_navigation",
"(",
"$",
"this",
")",
";",
"$",
"this",
"->",
"_flatnav",
"->",
"initialise",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_flatnav",
";",
"}"
] |
Returns the flat navigation object
@return flat_navigation
|
[
"Returns",
"the",
"flat",
"navigation",
"object"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pagelib.php#L768-L774
|
220,051
|
moodle/moodle
|
lib/pagelib.php
|
moodle_page.get_renderer
|
public function get_renderer($component, $subtype = null, $target = null) {
if ($this->pagelayout === 'maintenance') {
// If the page is using the maintenance layout then we're going to force target to maintenance.
// This leads to a special core renderer that is designed to block access to API's that are likely unavailable for this
// page layout.
$target = RENDERER_TARGET_MAINTENANCE;
}
return $this->magic_get_theme()->get_renderer($this, $component, $subtype, $target);
}
|
php
|
public function get_renderer($component, $subtype = null, $target = null) {
if ($this->pagelayout === 'maintenance') {
// If the page is using the maintenance layout then we're going to force target to maintenance.
// This leads to a special core renderer that is designed to block access to API's that are likely unavailable for this
// page layout.
$target = RENDERER_TARGET_MAINTENANCE;
}
return $this->magic_get_theme()->get_renderer($this, $component, $subtype, $target);
}
|
[
"public",
"function",
"get_renderer",
"(",
"$",
"component",
",",
"$",
"subtype",
"=",
"null",
",",
"$",
"target",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"pagelayout",
"===",
"'maintenance'",
")",
"{",
"// If the page is using the maintenance layout then we're going to force target to maintenance.",
"// This leads to a special core renderer that is designed to block access to API's that are likely unavailable for this",
"// page layout.",
"$",
"target",
"=",
"RENDERER_TARGET_MAINTENANCE",
";",
"}",
"return",
"$",
"this",
"->",
"magic_get_theme",
"(",
")",
"->",
"get_renderer",
"(",
"$",
"this",
",",
"$",
"component",
",",
"$",
"subtype",
",",
"$",
"target",
")",
";",
"}"
] |
Returns instance of page renderer
@param string $component name such as 'core', 'mod_forum' or 'qtype_multichoice'.
@param string $subtype optional subtype such as 'news' resulting to 'mod_forum_news'
@param string $target one of rendering target constants
@return renderer_base
|
[
"Returns",
"instance",
"of",
"page",
"renderer"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pagelib.php#L857-L865
|
220,052
|
moodle/moodle
|
lib/pagelib.php
|
moodle_page.has_navbar
|
public function has_navbar() {
if ($this->_navbar === null) {
$this->_navbar = new navbar($this);
}
return $this->_navbar->has_items();
}
|
php
|
public function has_navbar() {
if ($this->_navbar === null) {
$this->_navbar = new navbar($this);
}
return $this->_navbar->has_items();
}
|
[
"public",
"function",
"has_navbar",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_navbar",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_navbar",
"=",
"new",
"navbar",
"(",
"$",
"this",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_navbar",
"->",
"has_items",
"(",
")",
";",
"}"
] |
Checks to see if there are any items on the navbar object
@return bool true if there are, false if not
|
[
"Checks",
"to",
"see",
"if",
"there",
"are",
"any",
"items",
"on",
"the",
"navbar",
"object"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pagelib.php#L872-L877
|
220,053
|
moodle/moodle
|
lib/pagelib.php
|
moodle_page.end_collecting_javascript_requirements
|
public function end_collecting_javascript_requirements() {
if ($this->savedrequires === null) {
throw new coding_exception('JavaScript collection has not been started.');
}
$this->_requires = $this->savedrequires;
$this->savedrequires = null;
}
|
php
|
public function end_collecting_javascript_requirements() {
if ($this->savedrequires === null) {
throw new coding_exception('JavaScript collection has not been started.');
}
$this->_requires = $this->savedrequires;
$this->savedrequires = null;
}
|
[
"public",
"function",
"end_collecting_javascript_requirements",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"savedrequires",
"===",
"null",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'JavaScript collection has not been started.'",
")",
";",
"}",
"$",
"this",
"->",
"_requires",
"=",
"$",
"this",
"->",
"savedrequires",
";",
"$",
"this",
"->",
"savedrequires",
"=",
"null",
";",
"}"
] |
Switches back from collecting fragment JS requirement to the original requirement manager
|
[
"Switches",
"back",
"from",
"collecting",
"fragment",
"JS",
"requirement",
"to",
"the",
"original",
"requirement",
"manager"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pagelib.php#L906-L912
|
220,054
|
moodle/moodle
|
lib/pagelib.php
|
moodle_page.debug_summary
|
public function debug_summary() {
$summary = '';
$summary .= 'General type: ' . $this->pagelayout . '. ';
if (!during_initial_install()) {
$summary .= 'Context ' . $this->context->get_context_name() . ' (context id ' . $this->_context->id . '). ';
}
$summary .= 'Page type ' . $this->pagetype . '. ';
if ($this->subpage) {
$summary .= 'Sub-page ' . $this->subpage . '. ';
}
return $summary;
}
|
php
|
public function debug_summary() {
$summary = '';
$summary .= 'General type: ' . $this->pagelayout . '. ';
if (!during_initial_install()) {
$summary .= 'Context ' . $this->context->get_context_name() . ' (context id ' . $this->_context->id . '). ';
}
$summary .= 'Page type ' . $this->pagetype . '. ';
if ($this->subpage) {
$summary .= 'Sub-page ' . $this->subpage . '. ';
}
return $summary;
}
|
[
"public",
"function",
"debug_summary",
"(",
")",
"{",
"$",
"summary",
"=",
"''",
";",
"$",
"summary",
".=",
"'General type: '",
".",
"$",
"this",
"->",
"pagelayout",
".",
"'. '",
";",
"if",
"(",
"!",
"during_initial_install",
"(",
")",
")",
"{",
"$",
"summary",
".=",
"'Context '",
".",
"$",
"this",
"->",
"context",
"->",
"get_context_name",
"(",
")",
".",
"' (context id '",
".",
"$",
"this",
"->",
"_context",
"->",
"id",
".",
"'). '",
";",
"}",
"$",
"summary",
".=",
"'Page type '",
".",
"$",
"this",
"->",
"pagetype",
".",
"'. '",
";",
"if",
"(",
"$",
"this",
"->",
"subpage",
")",
"{",
"$",
"summary",
".=",
"'Sub-page '",
".",
"$",
"this",
"->",
"subpage",
".",
"'. '",
";",
"}",
"return",
"$",
"summary",
";",
"}"
] |
Get a description of this page. Normally displayed in the footer in developer debug mode.
@return string
|
[
"Get",
"a",
"description",
"of",
"this",
"page",
".",
"Normally",
"displayed",
"in",
"the",
"footer",
"in",
"developer",
"debug",
"mode",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pagelib.php#L945-L956
|
220,055
|
moodle/moodle
|
lib/pagelib.php
|
moodle_page.set_state
|
public function set_state($state) {
if ($state != $this->_state + 1 || $state > self::STATE_DONE) {
throw new coding_exception('Invalid state passed to moodle_page::set_state. We are in state ' .
$this->_state . ' and state ' . $state . ' was requested.');
}
if ($state == self::STATE_PRINTING_HEADER) {
$this->starting_output();
}
$this->_state = $state;
}
|
php
|
public function set_state($state) {
if ($state != $this->_state + 1 || $state > self::STATE_DONE) {
throw new coding_exception('Invalid state passed to moodle_page::set_state. We are in state ' .
$this->_state . ' and state ' . $state . ' was requested.');
}
if ($state == self::STATE_PRINTING_HEADER) {
$this->starting_output();
}
$this->_state = $state;
}
|
[
"public",
"function",
"set_state",
"(",
"$",
"state",
")",
"{",
"if",
"(",
"$",
"state",
"!=",
"$",
"this",
"->",
"_state",
"+",
"1",
"||",
"$",
"state",
">",
"self",
"::",
"STATE_DONE",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Invalid state passed to moodle_page::set_state. We are in state '",
".",
"$",
"this",
"->",
"_state",
".",
"' and state '",
".",
"$",
"state",
".",
"' was requested.'",
")",
";",
"}",
"if",
"(",
"$",
"state",
"==",
"self",
"::",
"STATE_PRINTING_HEADER",
")",
"{",
"$",
"this",
"->",
"starting_output",
"(",
")",
";",
"}",
"$",
"this",
"->",
"_state",
"=",
"$",
"state",
";",
"}"
] |
Set the state.
The state must be one of that STATE_... constants, and the state is only allowed to advance one step at a time.
@param int $state The new state.
@throws coding_exception
|
[
"Set",
"the",
"state",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pagelib.php#L968-L979
|
220,056
|
moodle/moodle
|
lib/pagelib.php
|
moodle_page.set_context
|
public function set_context($context) {
if ($context === null) {
// Extremely ugly hack which sets context to some value in order to prevent warnings,
// use only for core error handling!!!!
if (!$this->_context) {
$this->_context = context_system::instance();
}
return;
}
// Ideally we should set context only once.
if (isset($this->_context) && $context->id !== $this->_context->id) {
$current = $this->_context->contextlevel;
if ($current == CONTEXT_SYSTEM or $current == CONTEXT_COURSE) {
// Hmm - not ideal, but it might produce too many warnings due to the design of require_login.
} else if ($current == CONTEXT_MODULE and ($parentcontext = $context->get_parent_context()) and
$this->_context->id == $parentcontext->id) {
// Hmm - most probably somebody did require_login() and after that set the block context.
} else {
// We do not want devs to do weird switching of context levels on the fly because we might have used
// the context already such as in text filter in page title.
debugging("Coding problem: unsupported modification of PAGE->context from {$current} to {$context->contextlevel}");
}
}
$this->_context = $context;
}
|
php
|
public function set_context($context) {
if ($context === null) {
// Extremely ugly hack which sets context to some value in order to prevent warnings,
// use only for core error handling!!!!
if (!$this->_context) {
$this->_context = context_system::instance();
}
return;
}
// Ideally we should set context only once.
if (isset($this->_context) && $context->id !== $this->_context->id) {
$current = $this->_context->contextlevel;
if ($current == CONTEXT_SYSTEM or $current == CONTEXT_COURSE) {
// Hmm - not ideal, but it might produce too many warnings due to the design of require_login.
} else if ($current == CONTEXT_MODULE and ($parentcontext = $context->get_parent_context()) and
$this->_context->id == $parentcontext->id) {
// Hmm - most probably somebody did require_login() and after that set the block context.
} else {
// We do not want devs to do weird switching of context levels on the fly because we might have used
// the context already such as in text filter in page title.
debugging("Coding problem: unsupported modification of PAGE->context from {$current} to {$context->contextlevel}");
}
}
$this->_context = $context;
}
|
[
"public",
"function",
"set_context",
"(",
"$",
"context",
")",
"{",
"if",
"(",
"$",
"context",
"===",
"null",
")",
"{",
"// Extremely ugly hack which sets context to some value in order to prevent warnings,",
"// use only for core error handling!!!!",
"if",
"(",
"!",
"$",
"this",
"->",
"_context",
")",
"{",
"$",
"this",
"->",
"_context",
"=",
"context_system",
"::",
"instance",
"(",
")",
";",
"}",
"return",
";",
"}",
"// Ideally we should set context only once.",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_context",
")",
"&&",
"$",
"context",
"->",
"id",
"!==",
"$",
"this",
"->",
"_context",
"->",
"id",
")",
"{",
"$",
"current",
"=",
"$",
"this",
"->",
"_context",
"->",
"contextlevel",
";",
"if",
"(",
"$",
"current",
"==",
"CONTEXT_SYSTEM",
"or",
"$",
"current",
"==",
"CONTEXT_COURSE",
")",
"{",
"// Hmm - not ideal, but it might produce too many warnings due to the design of require_login.",
"}",
"else",
"if",
"(",
"$",
"current",
"==",
"CONTEXT_MODULE",
"and",
"(",
"$",
"parentcontext",
"=",
"$",
"context",
"->",
"get_parent_context",
"(",
")",
")",
"and",
"$",
"this",
"->",
"_context",
"->",
"id",
"==",
"$",
"parentcontext",
"->",
"id",
")",
"{",
"// Hmm - most probably somebody did require_login() and after that set the block context.",
"}",
"else",
"{",
"// We do not want devs to do weird switching of context levels on the fly because we might have used",
"// the context already such as in text filter in page title.",
"debugging",
"(",
"\"Coding problem: unsupported modification of PAGE->context from {$current} to {$context->contextlevel}\"",
")",
";",
"}",
"}",
"$",
"this",
"->",
"_context",
"=",
"$",
"context",
";",
"}"
] |
Set the main context to which this page belongs.
@param context $context a context object. You normally get this with context_xxxx::instance().
|
[
"Set",
"the",
"main",
"context",
"to",
"which",
"this",
"page",
"belongs",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pagelib.php#L1034-L1059
|
220,057
|
moodle/moodle
|
lib/pagelib.php
|
moodle_page.set_pagelayout
|
public function set_pagelayout($pagelayout) {
global $SESSION;
if (!empty($SESSION->forcepagelayout)) {
$this->_pagelayout = $SESSION->forcepagelayout;
} else {
// Uncomment this to debug theme pagelayout issues like missing blocks.
// if (!empty($this->_wherethemewasinitialised) && $pagelayout != $this->_pagelayout)
// debugging('Page layout has already been set and cannot be changed.', DEBUG_DEVELOPER);
$this->_pagelayout = $pagelayout;
}
}
|
php
|
public function set_pagelayout($pagelayout) {
global $SESSION;
if (!empty($SESSION->forcepagelayout)) {
$this->_pagelayout = $SESSION->forcepagelayout;
} else {
// Uncomment this to debug theme pagelayout issues like missing blocks.
// if (!empty($this->_wherethemewasinitialised) && $pagelayout != $this->_pagelayout)
// debugging('Page layout has already been set and cannot be changed.', DEBUG_DEVELOPER);
$this->_pagelayout = $pagelayout;
}
}
|
[
"public",
"function",
"set_pagelayout",
"(",
"$",
"pagelayout",
")",
"{",
"global",
"$",
"SESSION",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"SESSION",
"->",
"forcepagelayout",
")",
")",
"{",
"$",
"this",
"->",
"_pagelayout",
"=",
"$",
"SESSION",
"->",
"forcepagelayout",
";",
"}",
"else",
"{",
"// Uncomment this to debug theme pagelayout issues like missing blocks.",
"// if (!empty($this->_wherethemewasinitialised) && $pagelayout != $this->_pagelayout)",
"// debugging('Page layout has already been set and cannot be changed.', DEBUG_DEVELOPER);",
"$",
"this",
"->",
"_pagelayout",
"=",
"$",
"pagelayout",
";",
"}",
"}"
] |
Sets the layout to use for this page.
The page layout determines how the page will be displayed, things such as
block regions, content areas, etc are controlled by the layout.
The theme in use for the page will determine that the layout contains.
This properly defaults to 'base', so you only need to call this function if
you want something different. The exact range of supported layouts is specified
in the standard theme.
For an idea of the common page layouts see
{@link http://docs.moodle.org/dev/Themes_2.0#The_different_layouts_as_of_August_17th.2C_2010}
But please keep in mind that it may be (and normally is) out of date.
The only place to find an accurate up-to-date list of the page layouts
available for your version of Moodle is {@link theme/base/config.php}
@param string $pagelayout the page layout this is. For example 'popup', 'home'.
|
[
"Sets",
"the",
"layout",
"to",
"use",
"for",
"this",
"page",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pagelib.php#L1164-L1175
|
220,058
|
moodle/moodle
|
lib/pagelib.php
|
moodle_page.set_title
|
public function set_title($title) {
$title = format_string($title);
$title = strip_tags($title);
$title = str_replace('"', '"', $title);
$this->_title = $title;
}
|
php
|
public function set_title($title) {
$title = format_string($title);
$title = strip_tags($title);
$title = str_replace('"', '"', $title);
$this->_title = $title;
}
|
[
"public",
"function",
"set_title",
"(",
"$",
"title",
")",
"{",
"$",
"title",
"=",
"format_string",
"(",
"$",
"title",
")",
";",
"$",
"title",
"=",
"strip_tags",
"(",
"$",
"title",
")",
";",
"$",
"title",
"=",
"str_replace",
"(",
"'\"'",
",",
"'"'",
",",
"$",
"title",
")",
";",
"$",
"this",
"->",
"_title",
"=",
"$",
"title",
";",
"}"
] |
Sets the title for the page.
This is normally used within the title tag in the head of the page.
@param string $title the title that should go in the <head> section of the HTML of this page.
|
[
"Sets",
"the",
"title",
"for",
"the",
"page",
".",
"This",
"is",
"normally",
"used",
"within",
"the",
"title",
"tag",
"in",
"the",
"head",
"of",
"the",
"page",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pagelib.php#L1222-L1227
|
220,059
|
moodle/moodle
|
lib/pagelib.php
|
moodle_page.set_category_by_id
|
public function set_category_by_id($categoryid) {
global $SITE;
if (!is_null($this->_course)) {
throw new coding_exception('Course has already been set. You cannot change the category now.');
}
if (is_array($this->_categories)) {
throw new coding_exception('Course category has already been set. You cannot to change it now.');
}
$this->ensure_theme_not_set();
$this->set_course($SITE);
$this->load_category($categoryid);
$this->set_context(context_coursecat::instance($categoryid));
}
|
php
|
public function set_category_by_id($categoryid) {
global $SITE;
if (!is_null($this->_course)) {
throw new coding_exception('Course has already been set. You cannot change the category now.');
}
if (is_array($this->_categories)) {
throw new coding_exception('Course category has already been set. You cannot to change it now.');
}
$this->ensure_theme_not_set();
$this->set_course($SITE);
$this->load_category($categoryid);
$this->set_context(context_coursecat::instance($categoryid));
}
|
[
"public",
"function",
"set_category_by_id",
"(",
"$",
"categoryid",
")",
"{",
"global",
"$",
"SITE",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"_course",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Course has already been set. You cannot change the category now.'",
")",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"_categories",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Course category has already been set. You cannot to change it now.'",
")",
";",
"}",
"$",
"this",
"->",
"ensure_theme_not_set",
"(",
")",
";",
"$",
"this",
"->",
"set_course",
"(",
"$",
"SITE",
")",
";",
"$",
"this",
"->",
"load_category",
"(",
"$",
"categoryid",
")",
";",
"$",
"this",
"->",
"set_context",
"(",
"context_coursecat",
"::",
"instance",
"(",
"$",
"categoryid",
")",
")",
";",
"}"
] |
Set the course category this page belongs to manually.
This automatically sets $PAGE->course to be the site course. You cannot
use this method if you have already set $PAGE->course - in that case,
the category must be the one that the course belongs to. This also
automatically sets the page context to the category context.
@param int $categoryid The id of the category to set.
@throws coding_exception
|
[
"Set",
"the",
"course",
"category",
"this",
"page",
"belongs",
"to",
"manually",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pagelib.php#L1259-L1271
|
220,060
|
moodle/moodle
|
lib/pagelib.php
|
moodle_page.set_url
|
public function set_url($url, array $params = null) {
global $CFG;
if (is_string($url) && strpos($url, 'http') !== 0) {
if (strpos($url, '/') === 0) {
// Add the wwwroot to the relative url.
$url = $CFG->wwwroot . $url;
} else {
throw new coding_exception('Invalid parameter $url, has to be full url or in shortened form starting with /.');
}
}
$this->_url = new moodle_url($url, $params);
$fullurl = $this->_url->out_omit_querystring();
if (strpos($fullurl, "$CFG->wwwroot/") !== 0) {
debugging('Most probably incorrect set_page() url argument, it does not match the wwwroot!');
}
$shorturl = str_replace("$CFG->wwwroot/", '', $fullurl);
if (is_null($this->_pagetype)) {
$this->initialise_default_pagetype($shorturl);
}
}
|
php
|
public function set_url($url, array $params = null) {
global $CFG;
if (is_string($url) && strpos($url, 'http') !== 0) {
if (strpos($url, '/') === 0) {
// Add the wwwroot to the relative url.
$url = $CFG->wwwroot . $url;
} else {
throw new coding_exception('Invalid parameter $url, has to be full url or in shortened form starting with /.');
}
}
$this->_url = new moodle_url($url, $params);
$fullurl = $this->_url->out_omit_querystring();
if (strpos($fullurl, "$CFG->wwwroot/") !== 0) {
debugging('Most probably incorrect set_page() url argument, it does not match the wwwroot!');
}
$shorturl = str_replace("$CFG->wwwroot/", '', $fullurl);
if (is_null($this->_pagetype)) {
$this->initialise_default_pagetype($shorturl);
}
}
|
[
"public",
"function",
"set_url",
"(",
"$",
"url",
",",
"array",
"$",
"params",
"=",
"null",
")",
"{",
"global",
"$",
"CFG",
";",
"if",
"(",
"is_string",
"(",
"$",
"url",
")",
"&&",
"strpos",
"(",
"$",
"url",
",",
"'http'",
")",
"!==",
"0",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"url",
",",
"'/'",
")",
"===",
"0",
")",
"{",
"// Add the wwwroot to the relative url.",
"$",
"url",
"=",
"$",
"CFG",
"->",
"wwwroot",
".",
"$",
"url",
";",
"}",
"else",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Invalid parameter $url, has to be full url or in shortened form starting with /.'",
")",
";",
"}",
"}",
"$",
"this",
"->",
"_url",
"=",
"new",
"moodle_url",
"(",
"$",
"url",
",",
"$",
"params",
")",
";",
"$",
"fullurl",
"=",
"$",
"this",
"->",
"_url",
"->",
"out_omit_querystring",
"(",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"fullurl",
",",
"\"$CFG->wwwroot/\"",
")",
"!==",
"0",
")",
"{",
"debugging",
"(",
"'Most probably incorrect set_page() url argument, it does not match the wwwroot!'",
")",
";",
"}",
"$",
"shorturl",
"=",
"str_replace",
"(",
"\"$CFG->wwwroot/\"",
",",
"''",
",",
"$",
"fullurl",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"_pagetype",
")",
")",
"{",
"$",
"this",
"->",
"initialise_default_pagetype",
"(",
"$",
"shorturl",
")",
";",
"}",
"}"
] |
You should call this method from every page to set the URL that should be used to return to this page.
Used, for example, by the blocks editing UI to know where to return the
user after an action.
For example, course/view.php does:
$id = optional_param('id', 0, PARAM_INT);
$PAGE->set_url('/course/view.php', array('id' => $id));
@param moodle_url|string $url URL relative to $CFG->wwwroot or {@link moodle_url} instance
@param array $params parameters to add to the URL
@throws coding_exception
|
[
"You",
"should",
"call",
"this",
"method",
"from",
"every",
"page",
"to",
"set",
"the",
"URL",
"that",
"should",
"be",
"used",
"to",
"return",
"to",
"this",
"page",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pagelib.php#L1299-L1322
|
220,061
|
moodle/moodle
|
lib/pagelib.php
|
moodle_page.add_alternate_version
|
public function add_alternate_version($title, $url, $mimetype) {
if ($this->_state > self::STATE_BEFORE_HEADER) {
throw new coding_exception('Cannot call moodle_page::add_alternate_version after output has been started.');
}
$alt = new stdClass;
$alt->title = $title;
$alt->url = $url;
$this->_alternateversions[$mimetype] = $alt;
}
|
php
|
public function add_alternate_version($title, $url, $mimetype) {
if ($this->_state > self::STATE_BEFORE_HEADER) {
throw new coding_exception('Cannot call moodle_page::add_alternate_version after output has been started.');
}
$alt = new stdClass;
$alt->title = $title;
$alt->url = $url;
$this->_alternateversions[$mimetype] = $alt;
}
|
[
"public",
"function",
"add_alternate_version",
"(",
"$",
"title",
",",
"$",
"url",
",",
"$",
"mimetype",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_state",
">",
"self",
"::",
"STATE_BEFORE_HEADER",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Cannot call moodle_page::add_alternate_version after output has been started.'",
")",
";",
"}",
"$",
"alt",
"=",
"new",
"stdClass",
";",
"$",
"alt",
"->",
"title",
"=",
"$",
"title",
";",
"$",
"alt",
"->",
"url",
"=",
"$",
"url",
";",
"$",
"this",
"->",
"_alternateversions",
"[",
"$",
"mimetype",
"]",
"=",
"$",
"alt",
";",
"}"
] |
Sets an alternative version of this page.
There can be alternate versions of some pages (for example an RSS feed version).
Call this method for each alternative version available.
For each alternative version a link will be included in the <head> tag.
@param string $title The title to give the alternate version.
@param string|moodle_url $url The URL of the alternate version.
@param string $mimetype The mime-type of the alternate version.
@throws coding_exception
|
[
"Sets",
"an",
"alternative",
"version",
"of",
"this",
"page",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pagelib.php#L1352-L1360
|
220,062
|
moodle/moodle
|
lib/pagelib.php
|
moodle_page.set_other_editing_capability
|
public function set_other_editing_capability($capability) {
if (is_array($capability)) {
$this->_othereditingcaps = array_unique($this->_othereditingcaps + $capability);
} else {
$this->_othereditingcaps[] = $capability;
}
}
|
php
|
public function set_other_editing_capability($capability) {
if (is_array($capability)) {
$this->_othereditingcaps = array_unique($this->_othereditingcaps + $capability);
} else {
$this->_othereditingcaps[] = $capability;
}
}
|
[
"public",
"function",
"set_other_editing_capability",
"(",
"$",
"capability",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"capability",
")",
")",
"{",
"$",
"this",
"->",
"_othereditingcaps",
"=",
"array_unique",
"(",
"$",
"this",
"->",
"_othereditingcaps",
"+",
"$",
"capability",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_othereditingcaps",
"[",
"]",
"=",
"$",
"capability",
";",
"}",
"}"
] |
Some pages let you turn editing on for reasons other than editing blocks.
If that is the case, you can pass other capabilities that let the user
edit this page here.
@param string|array $capability either a capability, or an array of capabilities.
|
[
"Some",
"pages",
"let",
"you",
"turn",
"editing",
"on",
"for",
"reasons",
"other",
"than",
"editing",
"blocks",
".",
"If",
"that",
"is",
"the",
"case",
"you",
"can",
"pass",
"other",
"capabilities",
"that",
"let",
"the",
"user",
"edit",
"this",
"page",
"here",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pagelib.php#L1400-L1406
|
220,063
|
moodle/moodle
|
lib/pagelib.php
|
moodle_page.set_periodic_refresh_delay
|
public function set_periodic_refresh_delay($delay = null) {
if ($this->_state > self::STATE_BEFORE_HEADER) {
throw new coding_exception('You cannot set a periodic refresh delay after the header has been printed');
}
if ($delay === null) {
$this->_periodicrefreshdelay = null;
} else if (is_int($delay)) {
$this->_periodicrefreshdelay = $delay;
}
}
|
php
|
public function set_periodic_refresh_delay($delay = null) {
if ($this->_state > self::STATE_BEFORE_HEADER) {
throw new coding_exception('You cannot set a periodic refresh delay after the header has been printed');
}
if ($delay === null) {
$this->_periodicrefreshdelay = null;
} else if (is_int($delay)) {
$this->_periodicrefreshdelay = $delay;
}
}
|
[
"public",
"function",
"set_periodic_refresh_delay",
"(",
"$",
"delay",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_state",
">",
"self",
"::",
"STATE_BEFORE_HEADER",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'You cannot set a periodic refresh delay after the header has been printed'",
")",
";",
"}",
"if",
"(",
"$",
"delay",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_periodicrefreshdelay",
"=",
"null",
";",
"}",
"else",
"if",
"(",
"is_int",
"(",
"$",
"delay",
")",
")",
"{",
"$",
"this",
"->",
"_periodicrefreshdelay",
"=",
"$",
"delay",
";",
"}",
"}"
] |
Sets the page to periodically refresh
This function must be called before $OUTPUT->header has been called or
a coding exception will be thrown.
@param int $delay Sets the delay before refreshing the page, if set to null refresh is cancelled.
@throws coding_exception
|
[
"Sets",
"the",
"page",
"to",
"periodically",
"refresh"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pagelib.php#L1426-L1435
|
220,064
|
moodle/moodle
|
lib/pagelib.php
|
moodle_page.reload_theme
|
public function reload_theme() {
if (!is_null($this->_theme)) {
$this->_theme = theme_config::load($this->_theme->name);
}
}
|
php
|
public function reload_theme() {
if (!is_null($this->_theme)) {
$this->_theme = theme_config::load($this->_theme->name);
}
}
|
[
"public",
"function",
"reload_theme",
"(",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"_theme",
")",
")",
"{",
"$",
"this",
"->",
"_theme",
"=",
"theme_config",
"::",
"load",
"(",
"$",
"this",
"->",
"_theme",
"->",
"name",
")",
";",
"}",
"}"
] |
Reload theme settings.
This is used when we need to reset settings
because they are now double cached in theme.
|
[
"Reload",
"theme",
"settings",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pagelib.php#L1456-L1460
|
220,065
|
moodle/moodle
|
lib/pagelib.php
|
moodle_page.starting_output
|
protected function starting_output() {
global $CFG;
if (!during_initial_install()) {
$this->blocks->load_blocks();
if (empty($this->_block_actions_done)) {
$this->_block_actions_done = true;
if ($this->blocks->process_url_actions($this)) {
redirect($this->url->out(false));
}
}
$this->blocks->create_all_block_instances();
}
// If maintenance mode is on, change the page header.
if (!empty($CFG->maintenance_enabled)) {
$this->set_button('<a href="' . $CFG->wwwroot . '/' . $CFG->admin .
'/settings.php?section=maintenancemode">' . get_string('maintenancemode', 'admin') .
'</a> ' . $this->button);
$title = $this->title;
if ($title) {
$title .= ' - ';
}
$this->set_title($title . get_string('maintenancemode', 'admin'));
}
$this->initialise_standard_body_classes();
}
|
php
|
protected function starting_output() {
global $CFG;
if (!during_initial_install()) {
$this->blocks->load_blocks();
if (empty($this->_block_actions_done)) {
$this->_block_actions_done = true;
if ($this->blocks->process_url_actions($this)) {
redirect($this->url->out(false));
}
}
$this->blocks->create_all_block_instances();
}
// If maintenance mode is on, change the page header.
if (!empty($CFG->maintenance_enabled)) {
$this->set_button('<a href="' . $CFG->wwwroot . '/' . $CFG->admin .
'/settings.php?section=maintenancemode">' . get_string('maintenancemode', 'admin') .
'</a> ' . $this->button);
$title = $this->title;
if ($title) {
$title .= ' - ';
}
$this->set_title($title . get_string('maintenancemode', 'admin'));
}
$this->initialise_standard_body_classes();
}
|
[
"protected",
"function",
"starting_output",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"if",
"(",
"!",
"during_initial_install",
"(",
")",
")",
"{",
"$",
"this",
"->",
"blocks",
"->",
"load_blocks",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_block_actions_done",
")",
")",
"{",
"$",
"this",
"->",
"_block_actions_done",
"=",
"true",
";",
"if",
"(",
"$",
"this",
"->",
"blocks",
"->",
"process_url_actions",
"(",
"$",
"this",
")",
")",
"{",
"redirect",
"(",
"$",
"this",
"->",
"url",
"->",
"out",
"(",
"false",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"blocks",
"->",
"create_all_block_instances",
"(",
")",
";",
"}",
"// If maintenance mode is on, change the page header.",
"if",
"(",
"!",
"empty",
"(",
"$",
"CFG",
"->",
"maintenance_enabled",
")",
")",
"{",
"$",
"this",
"->",
"set_button",
"(",
"'<a href=\"'",
".",
"$",
"CFG",
"->",
"wwwroot",
".",
"'/'",
".",
"$",
"CFG",
"->",
"admin",
".",
"'/settings.php?section=maintenancemode\">'",
".",
"get_string",
"(",
"'maintenancemode'",
",",
"'admin'",
")",
".",
"'</a> '",
".",
"$",
"this",
"->",
"button",
")",
";",
"$",
"title",
"=",
"$",
"this",
"->",
"title",
";",
"if",
"(",
"$",
"title",
")",
"{",
"$",
"title",
".=",
"' - '",
";",
"}",
"$",
"this",
"->",
"set_title",
"(",
"$",
"title",
".",
"get_string",
"(",
"'maintenancemode'",
",",
"'admin'",
")",
")",
";",
"}",
"$",
"this",
"->",
"initialise_standard_body_classes",
"(",
")",
";",
"}"
] |
This method is called when the page first moves out of the STATE_BEFORE_HEADER
state. This is our last change to initialise things.
|
[
"This",
"method",
"is",
"called",
"when",
"the",
"page",
"first",
"moves",
"out",
"of",
"the",
"STATE_BEFORE_HEADER",
"state",
".",
"This",
"is",
"our",
"last",
"change",
"to",
"initialise",
"things",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pagelib.php#L1495-L1523
|
220,066
|
moodle/moodle
|
lib/pagelib.php
|
moodle_page.initialise_theme_and_output
|
public function initialise_theme_and_output() {
global $OUTPUT, $PAGE, $SITE, $CFG;
if (!empty($this->_wherethemewasinitialised)) {
return;
}
if (!during_initial_install()) {
// Detect PAGE->context mess.
$this->magic_get_context();
}
if (!$this->_course && !during_initial_install()) {
$this->set_course($SITE);
}
if (is_null($this->_theme)) {
$themename = $this->resolve_theme();
$this->_theme = theme_config::load($themename);
}
$this->_theme->setup_blocks($this->pagelayout, $this->blocks);
if ($this === $PAGE) {
$target = null;
if ($this->pagelayout === 'maintenance') {
// If the page is using the maintenance layout then we're going to force target to maintenance.
// This leads to a special core renderer that is designed to block access to API's that are likely unavailable for this
// page layout.
$target = RENDERER_TARGET_MAINTENANCE;
}
$OUTPUT = $this->get_renderer('core', null, $target);
}
if (!during_initial_install()) {
$filtermanager = filter_manager::instance();
$filtermanager->setup_page_for_globally_available_filters($this);
}
$this->_wherethemewasinitialised = debug_backtrace();
}
|
php
|
public function initialise_theme_and_output() {
global $OUTPUT, $PAGE, $SITE, $CFG;
if (!empty($this->_wherethemewasinitialised)) {
return;
}
if (!during_initial_install()) {
// Detect PAGE->context mess.
$this->magic_get_context();
}
if (!$this->_course && !during_initial_install()) {
$this->set_course($SITE);
}
if (is_null($this->_theme)) {
$themename = $this->resolve_theme();
$this->_theme = theme_config::load($themename);
}
$this->_theme->setup_blocks($this->pagelayout, $this->blocks);
if ($this === $PAGE) {
$target = null;
if ($this->pagelayout === 'maintenance') {
// If the page is using the maintenance layout then we're going to force target to maintenance.
// This leads to a special core renderer that is designed to block access to API's that are likely unavailable for this
// page layout.
$target = RENDERER_TARGET_MAINTENANCE;
}
$OUTPUT = $this->get_renderer('core', null, $target);
}
if (!during_initial_install()) {
$filtermanager = filter_manager::instance();
$filtermanager->setup_page_for_globally_available_filters($this);
}
$this->_wherethemewasinitialised = debug_backtrace();
}
|
[
"public",
"function",
"initialise_theme_and_output",
"(",
")",
"{",
"global",
"$",
"OUTPUT",
",",
"$",
"PAGE",
",",
"$",
"SITE",
",",
"$",
"CFG",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"_wherethemewasinitialised",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"during_initial_install",
"(",
")",
")",
"{",
"// Detect PAGE->context mess.",
"$",
"this",
"->",
"magic_get_context",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"_course",
"&&",
"!",
"during_initial_install",
"(",
")",
")",
"{",
"$",
"this",
"->",
"set_course",
"(",
"$",
"SITE",
")",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"_theme",
")",
")",
"{",
"$",
"themename",
"=",
"$",
"this",
"->",
"resolve_theme",
"(",
")",
";",
"$",
"this",
"->",
"_theme",
"=",
"theme_config",
"::",
"load",
"(",
"$",
"themename",
")",
";",
"}",
"$",
"this",
"->",
"_theme",
"->",
"setup_blocks",
"(",
"$",
"this",
"->",
"pagelayout",
",",
"$",
"this",
"->",
"blocks",
")",
";",
"if",
"(",
"$",
"this",
"===",
"$",
"PAGE",
")",
"{",
"$",
"target",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"pagelayout",
"===",
"'maintenance'",
")",
"{",
"// If the page is using the maintenance layout then we're going to force target to maintenance.",
"// This leads to a special core renderer that is designed to block access to API's that are likely unavailable for this",
"// page layout.",
"$",
"target",
"=",
"RENDERER_TARGET_MAINTENANCE",
";",
"}",
"$",
"OUTPUT",
"=",
"$",
"this",
"->",
"get_renderer",
"(",
"'core'",
",",
"null",
",",
"$",
"target",
")",
";",
"}",
"if",
"(",
"!",
"during_initial_install",
"(",
")",
")",
"{",
"$",
"filtermanager",
"=",
"filter_manager",
"::",
"instance",
"(",
")",
";",
"$",
"filtermanager",
"->",
"setup_page_for_globally_available_filters",
"(",
"$",
"this",
")",
";",
"}",
"$",
"this",
"->",
"_wherethemewasinitialised",
"=",
"debug_backtrace",
"(",
")",
";",
"}"
] |
Method for use by Moodle core to set up the theme. Do not
use this in your own code.
Make sure the right theme for this page is loaded. Tell our
blocks_manager about the theme block regions, and then, if
we are $PAGE, set up the global $OUTPUT.
@return void
|
[
"Method",
"for",
"use",
"by",
"Moodle",
"core",
"to",
"set",
"up",
"the",
"theme",
".",
"Do",
"not",
"use",
"this",
"in",
"your",
"own",
"code",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pagelib.php#L1535-L1575
|
220,067
|
moodle/moodle
|
lib/pagelib.php
|
moodle_page.resolve_theme
|
protected function resolve_theme() {
global $CFG, $USER, $SESSION;
if (empty($CFG->themeorder)) {
$themeorder = array('course', 'category', 'session', 'user', 'cohort', 'site');
} else {
$themeorder = $CFG->themeorder;
// Just in case, make sure we always use the site theme if nothing else matched.
$themeorder[] = 'site';
}
$mnetpeertheme = '';
if (isloggedin() and isset($CFG->mnet_localhost_id) and $USER->mnethostid != $CFG->mnet_localhost_id) {
require_once($CFG->dirroot.'/mnet/peer.php');
$mnetpeer = new mnet_peer();
$mnetpeer->set_id($USER->mnethostid);
if ($mnetpeer->force_theme == 1 && $mnetpeer->theme != '') {
$mnetpeertheme = $mnetpeer->theme;
}
}
$devicetheme = core_useragent::get_device_type_theme($this->devicetypeinuse);
// The user is using another device than default, and we have a theme for that, we should use it.
$hascustomdevicetheme = core_useragent::DEVICETYPE_DEFAULT != $this->devicetypeinuse && !empty($devicetheme);
foreach ($themeorder as $themetype) {
switch ($themetype) {
case 'course':
if (!empty($CFG->allowcoursethemes) && !empty($this->_course->theme) && !$hascustomdevicetheme) {
return $this->_course->theme;
}
break;
case 'category':
if (!empty($CFG->allowcategorythemes) && !$hascustomdevicetheme) {
$categories = $this->categories;
foreach ($categories as $category) {
if (!empty($category->theme)) {
return $category->theme;
}
}
}
break;
case 'session':
if (!empty($SESSION->theme)) {
return $SESSION->theme;
}
break;
case 'user':
if (!empty($CFG->allowuserthemes) && !empty($USER->theme) && !$hascustomdevicetheme) {
if ($mnetpeertheme) {
return $mnetpeertheme;
} else {
return $USER->theme;
}
}
break;
case 'cohort':
if (!empty($CFG->allowcohortthemes) && !empty($USER->cohorttheme) && !$hascustomdevicetheme) {
return $USER->cohorttheme;
}
break;
case 'site':
if ($mnetpeertheme) {
return $mnetpeertheme;
}
// First try for the device the user is using.
if (!empty($devicetheme)) {
return $devicetheme;
}
// Next try for the default device (as a fallback).
$devicetheme = core_useragent::get_device_type_theme(core_useragent::DEVICETYPE_DEFAULT);
if (!empty($devicetheme)) {
return $devicetheme;
}
// The default device theme isn't set up - use the overall default theme.
return theme_config::DEFAULT_THEME;
}
}
// We should most certainly have resolved a theme by now. Something has gone wrong.
debugging('Error resolving the theme to use for this page.', DEBUG_DEVELOPER);
return theme_config::DEFAULT_THEME;
}
|
php
|
protected function resolve_theme() {
global $CFG, $USER, $SESSION;
if (empty($CFG->themeorder)) {
$themeorder = array('course', 'category', 'session', 'user', 'cohort', 'site');
} else {
$themeorder = $CFG->themeorder;
// Just in case, make sure we always use the site theme if nothing else matched.
$themeorder[] = 'site';
}
$mnetpeertheme = '';
if (isloggedin() and isset($CFG->mnet_localhost_id) and $USER->mnethostid != $CFG->mnet_localhost_id) {
require_once($CFG->dirroot.'/mnet/peer.php');
$mnetpeer = new mnet_peer();
$mnetpeer->set_id($USER->mnethostid);
if ($mnetpeer->force_theme == 1 && $mnetpeer->theme != '') {
$mnetpeertheme = $mnetpeer->theme;
}
}
$devicetheme = core_useragent::get_device_type_theme($this->devicetypeinuse);
// The user is using another device than default, and we have a theme for that, we should use it.
$hascustomdevicetheme = core_useragent::DEVICETYPE_DEFAULT != $this->devicetypeinuse && !empty($devicetheme);
foreach ($themeorder as $themetype) {
switch ($themetype) {
case 'course':
if (!empty($CFG->allowcoursethemes) && !empty($this->_course->theme) && !$hascustomdevicetheme) {
return $this->_course->theme;
}
break;
case 'category':
if (!empty($CFG->allowcategorythemes) && !$hascustomdevicetheme) {
$categories = $this->categories;
foreach ($categories as $category) {
if (!empty($category->theme)) {
return $category->theme;
}
}
}
break;
case 'session':
if (!empty($SESSION->theme)) {
return $SESSION->theme;
}
break;
case 'user':
if (!empty($CFG->allowuserthemes) && !empty($USER->theme) && !$hascustomdevicetheme) {
if ($mnetpeertheme) {
return $mnetpeertheme;
} else {
return $USER->theme;
}
}
break;
case 'cohort':
if (!empty($CFG->allowcohortthemes) && !empty($USER->cohorttheme) && !$hascustomdevicetheme) {
return $USER->cohorttheme;
}
break;
case 'site':
if ($mnetpeertheme) {
return $mnetpeertheme;
}
// First try for the device the user is using.
if (!empty($devicetheme)) {
return $devicetheme;
}
// Next try for the default device (as a fallback).
$devicetheme = core_useragent::get_device_type_theme(core_useragent::DEVICETYPE_DEFAULT);
if (!empty($devicetheme)) {
return $devicetheme;
}
// The default device theme isn't set up - use the overall default theme.
return theme_config::DEFAULT_THEME;
}
}
// We should most certainly have resolved a theme by now. Something has gone wrong.
debugging('Error resolving the theme to use for this page.', DEBUG_DEVELOPER);
return theme_config::DEFAULT_THEME;
}
|
[
"protected",
"function",
"resolve_theme",
"(",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"USER",
",",
"$",
"SESSION",
";",
"if",
"(",
"empty",
"(",
"$",
"CFG",
"->",
"themeorder",
")",
")",
"{",
"$",
"themeorder",
"=",
"array",
"(",
"'course'",
",",
"'category'",
",",
"'session'",
",",
"'user'",
",",
"'cohort'",
",",
"'site'",
")",
";",
"}",
"else",
"{",
"$",
"themeorder",
"=",
"$",
"CFG",
"->",
"themeorder",
";",
"// Just in case, make sure we always use the site theme if nothing else matched.",
"$",
"themeorder",
"[",
"]",
"=",
"'site'",
";",
"}",
"$",
"mnetpeertheme",
"=",
"''",
";",
"if",
"(",
"isloggedin",
"(",
")",
"and",
"isset",
"(",
"$",
"CFG",
"->",
"mnet_localhost_id",
")",
"and",
"$",
"USER",
"->",
"mnethostid",
"!=",
"$",
"CFG",
"->",
"mnet_localhost_id",
")",
"{",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/mnet/peer.php'",
")",
";",
"$",
"mnetpeer",
"=",
"new",
"mnet_peer",
"(",
")",
";",
"$",
"mnetpeer",
"->",
"set_id",
"(",
"$",
"USER",
"->",
"mnethostid",
")",
";",
"if",
"(",
"$",
"mnetpeer",
"->",
"force_theme",
"==",
"1",
"&&",
"$",
"mnetpeer",
"->",
"theme",
"!=",
"''",
")",
"{",
"$",
"mnetpeertheme",
"=",
"$",
"mnetpeer",
"->",
"theme",
";",
"}",
"}",
"$",
"devicetheme",
"=",
"core_useragent",
"::",
"get_device_type_theme",
"(",
"$",
"this",
"->",
"devicetypeinuse",
")",
";",
"// The user is using another device than default, and we have a theme for that, we should use it.",
"$",
"hascustomdevicetheme",
"=",
"core_useragent",
"::",
"DEVICETYPE_DEFAULT",
"!=",
"$",
"this",
"->",
"devicetypeinuse",
"&&",
"!",
"empty",
"(",
"$",
"devicetheme",
")",
";",
"foreach",
"(",
"$",
"themeorder",
"as",
"$",
"themetype",
")",
"{",
"switch",
"(",
"$",
"themetype",
")",
"{",
"case",
"'course'",
":",
"if",
"(",
"!",
"empty",
"(",
"$",
"CFG",
"->",
"allowcoursethemes",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"_course",
"->",
"theme",
")",
"&&",
"!",
"$",
"hascustomdevicetheme",
")",
"{",
"return",
"$",
"this",
"->",
"_course",
"->",
"theme",
";",
"}",
"break",
";",
"case",
"'category'",
":",
"if",
"(",
"!",
"empty",
"(",
"$",
"CFG",
"->",
"allowcategorythemes",
")",
"&&",
"!",
"$",
"hascustomdevicetheme",
")",
"{",
"$",
"categories",
"=",
"$",
"this",
"->",
"categories",
";",
"foreach",
"(",
"$",
"categories",
"as",
"$",
"category",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"category",
"->",
"theme",
")",
")",
"{",
"return",
"$",
"category",
"->",
"theme",
";",
"}",
"}",
"}",
"break",
";",
"case",
"'session'",
":",
"if",
"(",
"!",
"empty",
"(",
"$",
"SESSION",
"->",
"theme",
")",
")",
"{",
"return",
"$",
"SESSION",
"->",
"theme",
";",
"}",
"break",
";",
"case",
"'user'",
":",
"if",
"(",
"!",
"empty",
"(",
"$",
"CFG",
"->",
"allowuserthemes",
")",
"&&",
"!",
"empty",
"(",
"$",
"USER",
"->",
"theme",
")",
"&&",
"!",
"$",
"hascustomdevicetheme",
")",
"{",
"if",
"(",
"$",
"mnetpeertheme",
")",
"{",
"return",
"$",
"mnetpeertheme",
";",
"}",
"else",
"{",
"return",
"$",
"USER",
"->",
"theme",
";",
"}",
"}",
"break",
";",
"case",
"'cohort'",
":",
"if",
"(",
"!",
"empty",
"(",
"$",
"CFG",
"->",
"allowcohortthemes",
")",
"&&",
"!",
"empty",
"(",
"$",
"USER",
"->",
"cohorttheme",
")",
"&&",
"!",
"$",
"hascustomdevicetheme",
")",
"{",
"return",
"$",
"USER",
"->",
"cohorttheme",
";",
"}",
"break",
";",
"case",
"'site'",
":",
"if",
"(",
"$",
"mnetpeertheme",
")",
"{",
"return",
"$",
"mnetpeertheme",
";",
"}",
"// First try for the device the user is using.",
"if",
"(",
"!",
"empty",
"(",
"$",
"devicetheme",
")",
")",
"{",
"return",
"$",
"devicetheme",
";",
"}",
"// Next try for the default device (as a fallback).",
"$",
"devicetheme",
"=",
"core_useragent",
"::",
"get_device_type_theme",
"(",
"core_useragent",
"::",
"DEVICETYPE_DEFAULT",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"devicetheme",
")",
")",
"{",
"return",
"$",
"devicetheme",
";",
"}",
"// The default device theme isn't set up - use the overall default theme.",
"return",
"theme_config",
"::",
"DEFAULT_THEME",
";",
"}",
"}",
"// We should most certainly have resolved a theme by now. Something has gone wrong.",
"debugging",
"(",
"'Error resolving the theme to use for this page.'",
",",
"DEBUG_DEVELOPER",
")",
";",
"return",
"theme_config",
"::",
"DEFAULT_THEME",
";",
"}"
] |
Work out the theme this page should use.
This depends on numerous $CFG settings, and the properties of this page.
@return string the name of the theme that should be used on this page.
|
[
"Work",
"out",
"the",
"theme",
"this",
"page",
"should",
"use",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pagelib.php#L1602-L1691
|
220,068
|
moodle/moodle
|
lib/pagelib.php
|
moodle_page.load_activity_record
|
protected function load_activity_record() {
global $DB;
if (is_null($this->_cm)) {
return;
}
$this->_module = $DB->get_record($this->_cm->modname, array('id' => $this->_cm->instance));
}
|
php
|
protected function load_activity_record() {
global $DB;
if (is_null($this->_cm)) {
return;
}
$this->_module = $DB->get_record($this->_cm->modname, array('id' => $this->_cm->instance));
}
|
[
"protected",
"function",
"load_activity_record",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"_cm",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"_module",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"$",
"this",
"->",
"_cm",
"->",
"modname",
",",
"array",
"(",
"'id'",
"=>",
"$",
"this",
"->",
"_cm",
"->",
"instance",
")",
")",
";",
"}"
] |
Loads the activity record for the current CM object associated with this
page.
This will load {@link moodle_page::$_module} with a row from the related
module table in the database.
For instance if {@link moodle_page::$_cm} is a forum then a row from the
forum table will be loaded.
|
[
"Loads",
"the",
"activity",
"record",
"for",
"the",
"current",
"CM",
"object",
"associated",
"with",
"this",
"page",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pagelib.php#L1832-L1838
|
220,069
|
moodle/moodle
|
lib/pagelib.php
|
moodle_page.ensure_category_loaded
|
protected function ensure_category_loaded() {
if (is_array($this->_categories)) {
return; // Already done.
}
if (is_null($this->_course)) {
throw new coding_exception('Attempt to get the course category for this page before the course was set.');
}
if ($this->_course->category == 0) {
$this->_categories = array();
} else {
$this->load_category($this->_course->category);
}
}
|
php
|
protected function ensure_category_loaded() {
if (is_array($this->_categories)) {
return; // Already done.
}
if (is_null($this->_course)) {
throw new coding_exception('Attempt to get the course category for this page before the course was set.');
}
if ($this->_course->category == 0) {
$this->_categories = array();
} else {
$this->load_category($this->_course->category);
}
}
|
[
"protected",
"function",
"ensure_category_loaded",
"(",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"_categories",
")",
")",
"{",
"return",
";",
"// Already done.",
"}",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"_course",
")",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Attempt to get the course category for this page before the course was set.'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_course",
"->",
"category",
"==",
"0",
")",
"{",
"$",
"this",
"->",
"_categories",
"=",
"array",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"load_category",
"(",
"$",
"this",
"->",
"_course",
"->",
"category",
")",
";",
"}",
"}"
] |
This function ensures that the category of the current course has been
loaded, and if not, the function loads it now.
@return void
@throws coding_exception
|
[
"This",
"function",
"ensures",
"that",
"the",
"category",
"of",
"the",
"current",
"course",
"has",
"been",
"loaded",
"and",
"if",
"not",
"the",
"function",
"loads",
"it",
"now",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pagelib.php#L1847-L1859
|
220,070
|
moodle/moodle
|
lib/pagelib.php
|
moodle_page.load_category
|
protected function load_category($categoryid) {
global $DB;
$category = $DB->get_record('course_categories', array('id' => $categoryid));
if (!$category) {
throw new moodle_exception('unknowncategory');
}
$this->_categories[$category->id] = $category;
$parentcategoryids = explode('/', trim($category->path, '/'));
array_pop($parentcategoryids);
foreach (array_reverse($parentcategoryids) as $catid) {
$this->_categories[$catid] = null;
}
}
|
php
|
protected function load_category($categoryid) {
global $DB;
$category = $DB->get_record('course_categories', array('id' => $categoryid));
if (!$category) {
throw new moodle_exception('unknowncategory');
}
$this->_categories[$category->id] = $category;
$parentcategoryids = explode('/', trim($category->path, '/'));
array_pop($parentcategoryids);
foreach (array_reverse($parentcategoryids) as $catid) {
$this->_categories[$catid] = null;
}
}
|
[
"protected",
"function",
"load_category",
"(",
"$",
"categoryid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"category",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'course_categories'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"categoryid",
")",
")",
";",
"if",
"(",
"!",
"$",
"category",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'unknowncategory'",
")",
";",
"}",
"$",
"this",
"->",
"_categories",
"[",
"$",
"category",
"->",
"id",
"]",
"=",
"$",
"category",
";",
"$",
"parentcategoryids",
"=",
"explode",
"(",
"'/'",
",",
"trim",
"(",
"$",
"category",
"->",
"path",
",",
"'/'",
")",
")",
";",
"array_pop",
"(",
"$",
"parentcategoryids",
")",
";",
"foreach",
"(",
"array_reverse",
"(",
"$",
"parentcategoryids",
")",
"as",
"$",
"catid",
")",
"{",
"$",
"this",
"->",
"_categories",
"[",
"$",
"catid",
"]",
"=",
"null",
";",
"}",
"}"
] |
Loads the requested category into the pages categories array.
@param int $categoryid
@throws moodle_exception
|
[
"Loads",
"the",
"requested",
"category",
"into",
"the",
"pages",
"categories",
"array",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pagelib.php#L1867-L1879
|
220,071
|
moodle/moodle
|
lib/pagelib.php
|
moodle_page.ensure_categories_loaded
|
protected function ensure_categories_loaded() {
global $DB;
$this->ensure_category_loaded();
if (!is_null(end($this->_categories))) {
return; // Already done.
}
$idstoload = array_keys($this->_categories);
array_shift($idstoload);
$categories = $DB->get_records_list('course_categories', 'id', $idstoload);
foreach ($idstoload as $catid) {
$this->_categories[$catid] = $categories[$catid];
}
}
|
php
|
protected function ensure_categories_loaded() {
global $DB;
$this->ensure_category_loaded();
if (!is_null(end($this->_categories))) {
return; // Already done.
}
$idstoload = array_keys($this->_categories);
array_shift($idstoload);
$categories = $DB->get_records_list('course_categories', 'id', $idstoload);
foreach ($idstoload as $catid) {
$this->_categories[$catid] = $categories[$catid];
}
}
|
[
"protected",
"function",
"ensure_categories_loaded",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"this",
"->",
"ensure_category_loaded",
"(",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"end",
"(",
"$",
"this",
"->",
"_categories",
")",
")",
")",
"{",
"return",
";",
"// Already done.",
"}",
"$",
"idstoload",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"_categories",
")",
";",
"array_shift",
"(",
"$",
"idstoload",
")",
";",
"$",
"categories",
"=",
"$",
"DB",
"->",
"get_records_list",
"(",
"'course_categories'",
",",
"'id'",
",",
"$",
"idstoload",
")",
";",
"foreach",
"(",
"$",
"idstoload",
"as",
"$",
"catid",
")",
"{",
"$",
"this",
"->",
"_categories",
"[",
"$",
"catid",
"]",
"=",
"$",
"categories",
"[",
"$",
"catid",
"]",
";",
"}",
"}"
] |
Ensures that the category the current course is within, as well as all of
its parent categories, have been loaded.
@return void
|
[
"Ensures",
"that",
"the",
"category",
"the",
"current",
"course",
"is",
"within",
"as",
"well",
"as",
"all",
"of",
"its",
"parent",
"categories",
"have",
"been",
"loaded",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pagelib.php#L1887-L1899
|
220,072
|
moodle/moodle
|
lib/pagelib.php
|
moodle_page.url_to_class_name
|
protected function url_to_class_name($url) {
$bits = parse_url($url);
$class = str_replace('.', '-', $bits['host']);
if (!empty($bits['port'])) {
$class .= '--' . $bits['port'];
}
if (!empty($bits['path'])) {
$path = trim($bits['path'], '/');
if ($path) {
$class .= '--' . str_replace('/', '-', $path);
}
}
return $class;
}
|
php
|
protected function url_to_class_name($url) {
$bits = parse_url($url);
$class = str_replace('.', '-', $bits['host']);
if (!empty($bits['port'])) {
$class .= '--' . $bits['port'];
}
if (!empty($bits['path'])) {
$path = trim($bits['path'], '/');
if ($path) {
$class .= '--' . str_replace('/', '-', $path);
}
}
return $class;
}
|
[
"protected",
"function",
"url_to_class_name",
"(",
"$",
"url",
")",
"{",
"$",
"bits",
"=",
"parse_url",
"(",
"$",
"url",
")",
";",
"$",
"class",
"=",
"str_replace",
"(",
"'.'",
",",
"'-'",
",",
"$",
"bits",
"[",
"'host'",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"bits",
"[",
"'port'",
"]",
")",
")",
"{",
"$",
"class",
".=",
"'--'",
".",
"$",
"bits",
"[",
"'port'",
"]",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"bits",
"[",
"'path'",
"]",
")",
")",
"{",
"$",
"path",
"=",
"trim",
"(",
"$",
"bits",
"[",
"'path'",
"]",
",",
"'/'",
")",
";",
"if",
"(",
"$",
"path",
")",
"{",
"$",
"class",
".=",
"'--'",
".",
"str_replace",
"(",
"'/'",
",",
"'-'",
",",
"$",
"path",
")",
";",
"}",
"}",
"return",
"$",
"class",
";",
"}"
] |
Converts the provided URL into a CSS class that be used within the page.
This is primarily used to add the wwwroot to the body tag as a CSS class.
@param string $url
@return string
|
[
"Converts",
"the",
"provided",
"URL",
"into",
"a",
"CSS",
"class",
"that",
"be",
"used",
"within",
"the",
"page",
".",
"This",
"is",
"primarily",
"used",
"to",
"add",
"the",
"wwwroot",
"to",
"the",
"body",
"tag",
"as",
"a",
"CSS",
"class",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pagelib.php#L1927-L1940
|
220,073
|
moodle/moodle
|
lib/pagelib.php
|
moodle_page.apply_theme_region_manipulations
|
public function apply_theme_region_manipulations($region) {
if ($this->blockmanipulations && isset($this->blockmanipulations[$region])) {
$regionwas = $region;
$regionnow = $this->blockmanipulations[$region];
if ($this->blocks->is_known_region($regionwas) && $this->blocks->is_known_region($regionnow)) {
// Both the before and after regions are known so we can swap them over.
return $regionnow;
}
// We didn't know about both, we won't swap them over.
return $regionwas;
}
return $region;
}
|
php
|
public function apply_theme_region_manipulations($region) {
if ($this->blockmanipulations && isset($this->blockmanipulations[$region])) {
$regionwas = $region;
$regionnow = $this->blockmanipulations[$region];
if ($this->blocks->is_known_region($regionwas) && $this->blocks->is_known_region($regionnow)) {
// Both the before and after regions are known so we can swap them over.
return $regionnow;
}
// We didn't know about both, we won't swap them over.
return $regionwas;
}
return $region;
}
|
[
"public",
"function",
"apply_theme_region_manipulations",
"(",
"$",
"region",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"blockmanipulations",
"&&",
"isset",
"(",
"$",
"this",
"->",
"blockmanipulations",
"[",
"$",
"region",
"]",
")",
")",
"{",
"$",
"regionwas",
"=",
"$",
"region",
";",
"$",
"regionnow",
"=",
"$",
"this",
"->",
"blockmanipulations",
"[",
"$",
"region",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"blocks",
"->",
"is_known_region",
"(",
"$",
"regionwas",
")",
"&&",
"$",
"this",
"->",
"blocks",
"->",
"is_known_region",
"(",
"$",
"regionnow",
")",
")",
"{",
"// Both the before and after regions are known so we can swap them over.",
"return",
"$",
"regionnow",
";",
"}",
"// We didn't know about both, we won't swap them over.",
"return",
"$",
"regionwas",
";",
"}",
"return",
"$",
"region",
";",
"}"
] |
Returns the block region having made any required theme manipulations.
@since Moodle 2.5.1 2.6
@param string $region
@return string
|
[
"Returns",
"the",
"block",
"region",
"having",
"made",
"any",
"required",
"theme",
"manipulations",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pagelib.php#L1998-L2010
|
220,074
|
moodle/moodle
|
lib/pagelib.php
|
moodle_page.add_report_nodes
|
public function add_report_nodes($userid, $nodeinfo) {
global $USER;
// Try to find the specific user node.
$newusernode = $this->navigation->find('user' . $userid, null);
$reportnode = null;
$navigationnodeerror =
'Could not find the navigation node requested. Please check that the node you are looking for exists.';
if ($userid != $USER->id) {
// Check that we have a valid node.
if (empty($newusernode)) {
// Throw an error if we ever reach here.
throw new coding_exception($navigationnodeerror);
}
// Add 'Reports' to the user node.
$reportnode = $newusernode->add(get_string('reports'));
} else {
// We are looking at our own profile.
$myprofilenode = $this->settingsnav->find('myprofile', null);
// Check that we do end up with a valid node.
if (empty($myprofilenode)) {
// Throw an error if we ever reach here.
throw new coding_exception($navigationnodeerror);
}
// Add 'Reports' to our node.
$reportnode = $myprofilenode->add(get_string('reports'));
}
// Finally add the report to the navigation tree.
$reportnode->add($nodeinfo['name'], $nodeinfo['url'], navigation_node::TYPE_COURSE);
}
|
php
|
public function add_report_nodes($userid, $nodeinfo) {
global $USER;
// Try to find the specific user node.
$newusernode = $this->navigation->find('user' . $userid, null);
$reportnode = null;
$navigationnodeerror =
'Could not find the navigation node requested. Please check that the node you are looking for exists.';
if ($userid != $USER->id) {
// Check that we have a valid node.
if (empty($newusernode)) {
// Throw an error if we ever reach here.
throw new coding_exception($navigationnodeerror);
}
// Add 'Reports' to the user node.
$reportnode = $newusernode->add(get_string('reports'));
} else {
// We are looking at our own profile.
$myprofilenode = $this->settingsnav->find('myprofile', null);
// Check that we do end up with a valid node.
if (empty($myprofilenode)) {
// Throw an error if we ever reach here.
throw new coding_exception($navigationnodeerror);
}
// Add 'Reports' to our node.
$reportnode = $myprofilenode->add(get_string('reports'));
}
// Finally add the report to the navigation tree.
$reportnode->add($nodeinfo['name'], $nodeinfo['url'], navigation_node::TYPE_COURSE);
}
|
[
"public",
"function",
"add_report_nodes",
"(",
"$",
"userid",
",",
"$",
"nodeinfo",
")",
"{",
"global",
"$",
"USER",
";",
"// Try to find the specific user node.",
"$",
"newusernode",
"=",
"$",
"this",
"->",
"navigation",
"->",
"find",
"(",
"'user'",
".",
"$",
"userid",
",",
"null",
")",
";",
"$",
"reportnode",
"=",
"null",
";",
"$",
"navigationnodeerror",
"=",
"'Could not find the navigation node requested. Please check that the node you are looking for exists.'",
";",
"if",
"(",
"$",
"userid",
"!=",
"$",
"USER",
"->",
"id",
")",
"{",
"// Check that we have a valid node.",
"if",
"(",
"empty",
"(",
"$",
"newusernode",
")",
")",
"{",
"// Throw an error if we ever reach here.",
"throw",
"new",
"coding_exception",
"(",
"$",
"navigationnodeerror",
")",
";",
"}",
"// Add 'Reports' to the user node.",
"$",
"reportnode",
"=",
"$",
"newusernode",
"->",
"add",
"(",
"get_string",
"(",
"'reports'",
")",
")",
";",
"}",
"else",
"{",
"// We are looking at our own profile.",
"$",
"myprofilenode",
"=",
"$",
"this",
"->",
"settingsnav",
"->",
"find",
"(",
"'myprofile'",
",",
"null",
")",
";",
"// Check that we do end up with a valid node.",
"if",
"(",
"empty",
"(",
"$",
"myprofilenode",
")",
")",
"{",
"// Throw an error if we ever reach here.",
"throw",
"new",
"coding_exception",
"(",
"$",
"navigationnodeerror",
")",
";",
"}",
"// Add 'Reports' to our node.",
"$",
"reportnode",
"=",
"$",
"myprofilenode",
"->",
"add",
"(",
"get_string",
"(",
"'reports'",
")",
")",
";",
"}",
"// Finally add the report to the navigation tree.",
"$",
"reportnode",
"->",
"add",
"(",
"$",
"nodeinfo",
"[",
"'name'",
"]",
",",
"$",
"nodeinfo",
"[",
"'url'",
"]",
",",
"navigation_node",
"::",
"TYPE_COURSE",
")",
";",
"}"
] |
Add a report node and a specific report to the navigation.
@param int $userid The user ID that we are looking to add this report node to.
@param array $nodeinfo Name and url of the final node that we are creating.
|
[
"Add",
"a",
"report",
"node",
"and",
"a",
"specific",
"report",
"to",
"the",
"navigation",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pagelib.php#L2018-L2046
|
220,075
|
moodle/moodle
|
lib/mustache/src/Mustache/Engine.php
|
Mustache_Engine.setPartials
|
public function setPartials(array $partials = array())
{
if (!isset($this->partialsLoader)) {
$this->partialsLoader = new Mustache_Loader_ArrayLoader();
}
if (!$this->partialsLoader instanceof Mustache_Loader_MutableLoader) {
throw new Mustache_Exception_RuntimeException('Unable to set partials on an immutable Mustache Loader instance');
}
$this->partialsLoader->setTemplates($partials);
}
|
php
|
public function setPartials(array $partials = array())
{
if (!isset($this->partialsLoader)) {
$this->partialsLoader = new Mustache_Loader_ArrayLoader();
}
if (!$this->partialsLoader instanceof Mustache_Loader_MutableLoader) {
throw new Mustache_Exception_RuntimeException('Unable to set partials on an immutable Mustache Loader instance');
}
$this->partialsLoader->setTemplates($partials);
}
|
[
"public",
"function",
"setPartials",
"(",
"array",
"$",
"partials",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"partialsLoader",
")",
")",
"{",
"$",
"this",
"->",
"partialsLoader",
"=",
"new",
"Mustache_Loader_ArrayLoader",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"partialsLoader",
"instanceof",
"Mustache_Loader_MutableLoader",
")",
"{",
"throw",
"new",
"Mustache_Exception_RuntimeException",
"(",
"'Unable to set partials on an immutable Mustache Loader instance'",
")",
";",
"}",
"$",
"this",
"->",
"partialsLoader",
"->",
"setTemplates",
"(",
"$",
"partials",
")",
";",
"}"
] |
Set partials for the current partials Loader instance.
@throws Mustache_Exception_RuntimeException If the current Loader instance is immutable
@param array $partials (default: array())
|
[
"Set",
"partials",
"for",
"the",
"current",
"partials",
"Loader",
"instance",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Engine.php#L340-L351
|
220,076
|
moodle/moodle
|
lib/mustache/src/Mustache/Engine.php
|
Mustache_Engine.setHelpers
|
public function setHelpers($helpers)
{
if (!is_array($helpers) && !$helpers instanceof Traversable) {
throw new Mustache_Exception_InvalidArgumentException('setHelpers expects an array of helpers');
}
$this->getHelpers()->clear();
foreach ($helpers as $name => $helper) {
$this->addHelper($name, $helper);
}
}
|
php
|
public function setHelpers($helpers)
{
if (!is_array($helpers) && !$helpers instanceof Traversable) {
throw new Mustache_Exception_InvalidArgumentException('setHelpers expects an array of helpers');
}
$this->getHelpers()->clear();
foreach ($helpers as $name => $helper) {
$this->addHelper($name, $helper);
}
}
|
[
"public",
"function",
"setHelpers",
"(",
"$",
"helpers",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"helpers",
")",
"&&",
"!",
"$",
"helpers",
"instanceof",
"Traversable",
")",
"{",
"throw",
"new",
"Mustache_Exception_InvalidArgumentException",
"(",
"'setHelpers expects an array of helpers'",
")",
";",
"}",
"$",
"this",
"->",
"getHelpers",
"(",
")",
"->",
"clear",
"(",
")",
";",
"foreach",
"(",
"$",
"helpers",
"as",
"$",
"name",
"=>",
"$",
"helper",
")",
"{",
"$",
"this",
"->",
"addHelper",
"(",
"$",
"name",
",",
"$",
"helper",
")",
";",
"}",
"}"
] |
Set an array of Mustache helpers.
An array of 'helpers'. Helpers can be global variables or objects, closures (e.g. for higher order sections), or
any other valid Mustache context value. They will be prepended to the context stack, so they will be available in
any template loaded by this Mustache instance.
@throws Mustache_Exception_InvalidArgumentException if $helpers is not an array or Traversable
@param array|Traversable $helpers
|
[
"Set",
"an",
"array",
"of",
"Mustache",
"helpers",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Engine.php#L364-L375
|
220,077
|
moodle/moodle
|
lib/mustache/src/Mustache/Engine.php
|
Mustache_Engine.setLogger
|
public function setLogger($logger = null)
{
if ($logger !== null && !($logger instanceof Mustache_Logger || is_a($logger, 'Psr\\Log\\LoggerInterface'))) {
throw new Mustache_Exception_InvalidArgumentException('Expected an instance of Mustache_Logger or Psr\\Log\\LoggerInterface.');
}
if ($this->getCache()->getLogger() === null) {
$this->getCache()->setLogger($logger);
}
$this->logger = $logger;
}
|
php
|
public function setLogger($logger = null)
{
if ($logger !== null && !($logger instanceof Mustache_Logger || is_a($logger, 'Psr\\Log\\LoggerInterface'))) {
throw new Mustache_Exception_InvalidArgumentException('Expected an instance of Mustache_Logger or Psr\\Log\\LoggerInterface.');
}
if ($this->getCache()->getLogger() === null) {
$this->getCache()->setLogger($logger);
}
$this->logger = $logger;
}
|
[
"public",
"function",
"setLogger",
"(",
"$",
"logger",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"logger",
"!==",
"null",
"&&",
"!",
"(",
"$",
"logger",
"instanceof",
"Mustache_Logger",
"||",
"is_a",
"(",
"$",
"logger",
",",
"'Psr\\\\Log\\\\LoggerInterface'",
")",
")",
")",
"{",
"throw",
"new",
"Mustache_Exception_InvalidArgumentException",
"(",
"'Expected an instance of Mustache_Logger or Psr\\\\Log\\\\LoggerInterface.'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"getCache",
"(",
")",
"->",
"getLogger",
"(",
")",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"getCache",
"(",
")",
"->",
"setLogger",
"(",
"$",
"logger",
")",
";",
"}",
"$",
"this",
"->",
"logger",
"=",
"$",
"logger",
";",
"}"
] |
Set the Mustache Logger instance.
@throws Mustache_Exception_InvalidArgumentException If logger is not an instance of Mustache_Logger or Psr\Log\LoggerInterface
@param Mustache_Logger|Psr\Log\LoggerInterface $logger
|
[
"Set",
"the",
"Mustache",
"Logger",
"instance",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Engine.php#L453-L464
|
220,078
|
moodle/moodle
|
lib/mustache/src/Mustache/Engine.php
|
Mustache_Engine.setCache
|
public function setCache(Mustache_Cache $cache)
{
if (isset($this->logger) && $cache->getLogger() === null) {
$cache->setLogger($this->getLogger());
}
$this->cache = $cache;
}
|
php
|
public function setCache(Mustache_Cache $cache)
{
if (isset($this->logger) && $cache->getLogger() === null) {
$cache->setLogger($this->getLogger());
}
$this->cache = $cache;
}
|
[
"public",
"function",
"setCache",
"(",
"Mustache_Cache",
"$",
"cache",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"logger",
")",
"&&",
"$",
"cache",
"->",
"getLogger",
"(",
")",
"===",
"null",
")",
"{",
"$",
"cache",
"->",
"setLogger",
"(",
"$",
"this",
"->",
"getLogger",
"(",
")",
")",
";",
"}",
"$",
"this",
"->",
"cache",
"=",
"$",
"cache",
";",
"}"
] |
Set the Mustache Cache instance.
@param Mustache_Cache $cache
|
[
"Set",
"the",
"Mustache",
"Cache",
"instance",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Engine.php#L559-L566
|
220,079
|
moodle/moodle
|
lib/mustache/src/Mustache/Engine.php
|
Mustache_Engine.getLambdaCache
|
protected function getLambdaCache()
{
if ($this->cacheLambdaTemplates) {
return $this->getCache();
}
if (!isset($this->lambdaCache)) {
$this->lambdaCache = new Mustache_Cache_NoopCache();
}
return $this->lambdaCache;
}
|
php
|
protected function getLambdaCache()
{
if ($this->cacheLambdaTemplates) {
return $this->getCache();
}
if (!isset($this->lambdaCache)) {
$this->lambdaCache = new Mustache_Cache_NoopCache();
}
return $this->lambdaCache;
}
|
[
"protected",
"function",
"getLambdaCache",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"cacheLambdaTemplates",
")",
"{",
"return",
"$",
"this",
"->",
"getCache",
"(",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"lambdaCache",
")",
")",
"{",
"$",
"this",
"->",
"lambdaCache",
"=",
"new",
"Mustache_Cache_NoopCache",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"lambdaCache",
";",
"}"
] |
Get the current Lambda Cache instance.
If 'cache_lambda_templates' is enabled, this is the default cache instance. Otherwise, it is a NoopCache.
@see Mustache_Engine::getCache
@return Mustache_Cache
|
[
"Get",
"the",
"current",
"Lambda",
"Cache",
"instance",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Engine.php#L593-L604
|
220,080
|
moodle/moodle
|
lib/mustache/src/Mustache/Engine.php
|
Mustache_Engine.getTemplateClassName
|
public function getTemplateClassName($source)
{
// For the most part, adding a new option here should do the trick.
//
// Pick a value here which is unique for each possible way the template
// could be compiled... but not necessarily unique per option value. See
// escape below, which only needs to differentiate between 'custom' and
// 'default' escapes.
//
// Keep this list in alphabetical order :)
$chunks = array(
'charset' => $this->charset,
'delimiters' => $this->delimiters ? $this->delimiters : '{{ }}',
'entityFlags' => $this->entityFlags,
'escape' => isset($this->escape) ? 'custom' : 'default',
'key' => ($source instanceof Mustache_Source) ? $source->getKey() : 'source',
'pragmas' => $this->getPragmas(),
'strictCallables' => $this->strictCallables,
'version' => self::VERSION,
);
$key = json_encode($chunks);
// Template Source instances have already provided their own source key. For strings, just include the whole
// source string in the md5 hash.
if (!$source instanceof Mustache_Source) {
$key .= "\n" . $source;
}
return $this->templateClassPrefix . md5($key);
}
|
php
|
public function getTemplateClassName($source)
{
// For the most part, adding a new option here should do the trick.
//
// Pick a value here which is unique for each possible way the template
// could be compiled... but not necessarily unique per option value. See
// escape below, which only needs to differentiate between 'custom' and
// 'default' escapes.
//
// Keep this list in alphabetical order :)
$chunks = array(
'charset' => $this->charset,
'delimiters' => $this->delimiters ? $this->delimiters : '{{ }}',
'entityFlags' => $this->entityFlags,
'escape' => isset($this->escape) ? 'custom' : 'default',
'key' => ($source instanceof Mustache_Source) ? $source->getKey() : 'source',
'pragmas' => $this->getPragmas(),
'strictCallables' => $this->strictCallables,
'version' => self::VERSION,
);
$key = json_encode($chunks);
// Template Source instances have already provided their own source key. For strings, just include the whole
// source string in the md5 hash.
if (!$source instanceof Mustache_Source) {
$key .= "\n" . $source;
}
return $this->templateClassPrefix . md5($key);
}
|
[
"public",
"function",
"getTemplateClassName",
"(",
"$",
"source",
")",
"{",
"// For the most part, adding a new option here should do the trick.",
"//",
"// Pick a value here which is unique for each possible way the template",
"// could be compiled... but not necessarily unique per option value. See",
"// escape below, which only needs to differentiate between 'custom' and",
"// 'default' escapes.",
"//",
"// Keep this list in alphabetical order :)",
"$",
"chunks",
"=",
"array",
"(",
"'charset'",
"=>",
"$",
"this",
"->",
"charset",
",",
"'delimiters'",
"=>",
"$",
"this",
"->",
"delimiters",
"?",
"$",
"this",
"->",
"delimiters",
":",
"'{{ }}'",
",",
"'entityFlags'",
"=>",
"$",
"this",
"->",
"entityFlags",
",",
"'escape'",
"=>",
"isset",
"(",
"$",
"this",
"->",
"escape",
")",
"?",
"'custom'",
":",
"'default'",
",",
"'key'",
"=>",
"(",
"$",
"source",
"instanceof",
"Mustache_Source",
")",
"?",
"$",
"source",
"->",
"getKey",
"(",
")",
":",
"'source'",
",",
"'pragmas'",
"=>",
"$",
"this",
"->",
"getPragmas",
"(",
")",
",",
"'strictCallables'",
"=>",
"$",
"this",
"->",
"strictCallables",
",",
"'version'",
"=>",
"self",
"::",
"VERSION",
",",
")",
";",
"$",
"key",
"=",
"json_encode",
"(",
"$",
"chunks",
")",
";",
"// Template Source instances have already provided their own source key. For strings, just include the whole",
"// source string in the md5 hash.",
"if",
"(",
"!",
"$",
"source",
"instanceof",
"Mustache_Source",
")",
"{",
"$",
"key",
".=",
"\"\\n\"",
".",
"$",
"source",
";",
"}",
"return",
"$",
"this",
"->",
"templateClassPrefix",
".",
"md5",
"(",
"$",
"key",
")",
";",
"}"
] |
Helper method to generate a Mustache template class.
This method must be updated any time options are added which make it so
the same template could be parsed and compiled multiple different ways.
@param string|Mustache_Source $source
@return string Mustache Template class name
|
[
"Helper",
"method",
"to",
"generate",
"a",
"Mustache",
"template",
"class",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Engine.php#L616-L646
|
220,081
|
moodle/moodle
|
lib/mustache/src/Mustache/Engine.php
|
Mustache_Engine.loadPartial
|
public function loadPartial($name)
{
try {
if (isset($this->partialsLoader)) {
$loader = $this->partialsLoader;
} elseif (isset($this->loader) && !$this->loader instanceof Mustache_Loader_StringLoader) {
$loader = $this->loader;
} else {
throw new Mustache_Exception_UnknownTemplateException($name);
}
return $this->loadSource($loader->load($name));
} catch (Mustache_Exception_UnknownTemplateException $e) {
// If the named partial cannot be found, log then return null.
$this->log(
Mustache_Logger::WARNING,
'Partial not found: "{name}"',
array('name' => $e->getTemplateName())
);
}
}
|
php
|
public function loadPartial($name)
{
try {
if (isset($this->partialsLoader)) {
$loader = $this->partialsLoader;
} elseif (isset($this->loader) && !$this->loader instanceof Mustache_Loader_StringLoader) {
$loader = $this->loader;
} else {
throw new Mustache_Exception_UnknownTemplateException($name);
}
return $this->loadSource($loader->load($name));
} catch (Mustache_Exception_UnknownTemplateException $e) {
// If the named partial cannot be found, log then return null.
$this->log(
Mustache_Logger::WARNING,
'Partial not found: "{name}"',
array('name' => $e->getTemplateName())
);
}
}
|
[
"public",
"function",
"loadPartial",
"(",
"$",
"name",
")",
"{",
"try",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"partialsLoader",
")",
")",
"{",
"$",
"loader",
"=",
"$",
"this",
"->",
"partialsLoader",
";",
"}",
"elseif",
"(",
"isset",
"(",
"$",
"this",
"->",
"loader",
")",
"&&",
"!",
"$",
"this",
"->",
"loader",
"instanceof",
"Mustache_Loader_StringLoader",
")",
"{",
"$",
"loader",
"=",
"$",
"this",
"->",
"loader",
";",
"}",
"else",
"{",
"throw",
"new",
"Mustache_Exception_UnknownTemplateException",
"(",
"$",
"name",
")",
";",
"}",
"return",
"$",
"this",
"->",
"loadSource",
"(",
"$",
"loader",
"->",
"load",
"(",
"$",
"name",
")",
")",
";",
"}",
"catch",
"(",
"Mustache_Exception_UnknownTemplateException",
"$",
"e",
")",
"{",
"// If the named partial cannot be found, log then return null.",
"$",
"this",
"->",
"log",
"(",
"Mustache_Logger",
"::",
"WARNING",
",",
"'Partial not found: \"{name}\"'",
",",
"array",
"(",
"'name'",
"=>",
"$",
"e",
"->",
"getTemplateName",
"(",
")",
")",
")",
";",
"}",
"}"
] |
Load a Mustache partial Template by name.
This is a helper method used internally by Template instances for loading partial templates. You can most likely
ignore it completely.
@param string $name
@return Mustache_Template
|
[
"Load",
"a",
"Mustache",
"partial",
"Template",
"by",
"name",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Engine.php#L670-L690
|
220,082
|
moodle/moodle
|
lib/mustache/src/Mustache/Engine.php
|
Mustache_Engine.loadLambda
|
public function loadLambda($source, $delims = null)
{
if ($delims !== null) {
$source = $delims . "\n" . $source;
}
return $this->loadSource($source, $this->getLambdaCache());
}
|
php
|
public function loadLambda($source, $delims = null)
{
if ($delims !== null) {
$source = $delims . "\n" . $source;
}
return $this->loadSource($source, $this->getLambdaCache());
}
|
[
"public",
"function",
"loadLambda",
"(",
"$",
"source",
",",
"$",
"delims",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"delims",
"!==",
"null",
")",
"{",
"$",
"source",
"=",
"$",
"delims",
".",
"\"\\n\"",
".",
"$",
"source",
";",
"}",
"return",
"$",
"this",
"->",
"loadSource",
"(",
"$",
"source",
",",
"$",
"this",
"->",
"getLambdaCache",
"(",
")",
")",
";",
"}"
] |
Load a Mustache lambda Template by source.
This is a helper method used by Template instances to generate subtemplates for Lambda sections. You can most
likely ignore it completely.
@param string $source
@param string $delims (default: null)
@return Mustache_Template
|
[
"Load",
"a",
"Mustache",
"lambda",
"Template",
"by",
"source",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Engine.php#L703-L710
|
220,083
|
moodle/moodle
|
lib/mustache/src/Mustache/Engine.php
|
Mustache_Engine.loadSource
|
private function loadSource($source, Mustache_Cache $cache = null)
{
$className = $this->getTemplateClassName($source);
if (!isset($this->templates[$className])) {
if ($cache === null) {
$cache = $this->getCache();
}
if (!class_exists($className, false)) {
if (!$cache->load($className)) {
$compiled = $this->compile($source);
$cache->cache($className, $compiled);
}
}
$this->log(
Mustache_Logger::DEBUG,
'Instantiating template: "{className}"',
array('className' => $className)
);
$this->templates[$className] = new $className($this);
}
return $this->templates[$className];
}
|
php
|
private function loadSource($source, Mustache_Cache $cache = null)
{
$className = $this->getTemplateClassName($source);
if (!isset($this->templates[$className])) {
if ($cache === null) {
$cache = $this->getCache();
}
if (!class_exists($className, false)) {
if (!$cache->load($className)) {
$compiled = $this->compile($source);
$cache->cache($className, $compiled);
}
}
$this->log(
Mustache_Logger::DEBUG,
'Instantiating template: "{className}"',
array('className' => $className)
);
$this->templates[$className] = new $className($this);
}
return $this->templates[$className];
}
|
[
"private",
"function",
"loadSource",
"(",
"$",
"source",
",",
"Mustache_Cache",
"$",
"cache",
"=",
"null",
")",
"{",
"$",
"className",
"=",
"$",
"this",
"->",
"getTemplateClassName",
"(",
"$",
"source",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"templates",
"[",
"$",
"className",
"]",
")",
")",
"{",
"if",
"(",
"$",
"cache",
"===",
"null",
")",
"{",
"$",
"cache",
"=",
"$",
"this",
"->",
"getCache",
"(",
")",
";",
"}",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
",",
"false",
")",
")",
"{",
"if",
"(",
"!",
"$",
"cache",
"->",
"load",
"(",
"$",
"className",
")",
")",
"{",
"$",
"compiled",
"=",
"$",
"this",
"->",
"compile",
"(",
"$",
"source",
")",
";",
"$",
"cache",
"->",
"cache",
"(",
"$",
"className",
",",
"$",
"compiled",
")",
";",
"}",
"}",
"$",
"this",
"->",
"log",
"(",
"Mustache_Logger",
"::",
"DEBUG",
",",
"'Instantiating template: \"{className}\"'",
",",
"array",
"(",
"'className'",
"=>",
"$",
"className",
")",
")",
";",
"$",
"this",
"->",
"templates",
"[",
"$",
"className",
"]",
"=",
"new",
"$",
"className",
"(",
"$",
"this",
")",
";",
"}",
"return",
"$",
"this",
"->",
"templates",
"[",
"$",
"className",
"]",
";",
"}"
] |
Instantiate and return a Mustache Template instance by source.
Optionally provide a Mustache_Cache instance. This is used internally by Mustache_Engine::loadLambda to respect
the 'cache_lambda_templates' configuration option.
@see Mustache_Engine::loadTemplate
@see Mustache_Engine::loadPartial
@see Mustache_Engine::loadLambda
@param string|Mustache_Source $source
@param Mustache_Cache $cache (default: null)
@return Mustache_Template
|
[
"Instantiate",
"and",
"return",
"a",
"Mustache",
"Template",
"instance",
"by",
"source",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Engine.php#L727-L753
|
220,084
|
moodle/moodle
|
lib/mustache/src/Mustache/Engine.php
|
Mustache_Engine.parse
|
private function parse($source)
{
$parser = $this->getParser();
$parser->setPragmas($this->getPragmas());
return $parser->parse($this->tokenize($source));
}
|
php
|
private function parse($source)
{
$parser = $this->getParser();
$parser->setPragmas($this->getPragmas());
return $parser->parse($this->tokenize($source));
}
|
[
"private",
"function",
"parse",
"(",
"$",
"source",
")",
"{",
"$",
"parser",
"=",
"$",
"this",
"->",
"getParser",
"(",
")",
";",
"$",
"parser",
"->",
"setPragmas",
"(",
"$",
"this",
"->",
"getPragmas",
"(",
")",
")",
";",
"return",
"$",
"parser",
"->",
"parse",
"(",
"$",
"this",
"->",
"tokenize",
"(",
"$",
"source",
")",
")",
";",
"}"
] |
Helper method to parse a Mustache template.
@see Mustache_Parser::parse
@param string $source
@return array Token tree
|
[
"Helper",
"method",
"to",
"parse",
"a",
"Mustache",
"template",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Engine.php#L778-L784
|
220,085
|
moodle/moodle
|
lib/mustache/src/Mustache/Engine.php
|
Mustache_Engine.compile
|
private function compile($source)
{
$name = $this->getTemplateClassName($source);
$this->log(
Mustache_Logger::INFO,
'Compiling template to "{className}" class',
array('className' => $name)
);
if ($source instanceof Mustache_Source) {
$source = $source->getSource();
}
$tree = $this->parse($source);
$compiler = $this->getCompiler();
$compiler->setPragmas($this->getPragmas());
return $compiler->compile($source, $tree, $name, isset($this->escape), $this->charset, $this->strictCallables, $this->entityFlags);
}
|
php
|
private function compile($source)
{
$name = $this->getTemplateClassName($source);
$this->log(
Mustache_Logger::INFO,
'Compiling template to "{className}" class',
array('className' => $name)
);
if ($source instanceof Mustache_Source) {
$source = $source->getSource();
}
$tree = $this->parse($source);
$compiler = $this->getCompiler();
$compiler->setPragmas($this->getPragmas());
return $compiler->compile($source, $tree, $name, isset($this->escape), $this->charset, $this->strictCallables, $this->entityFlags);
}
|
[
"private",
"function",
"compile",
"(",
"$",
"source",
")",
"{",
"$",
"name",
"=",
"$",
"this",
"->",
"getTemplateClassName",
"(",
"$",
"source",
")",
";",
"$",
"this",
"->",
"log",
"(",
"Mustache_Logger",
"::",
"INFO",
",",
"'Compiling template to \"{className}\" class'",
",",
"array",
"(",
"'className'",
"=>",
"$",
"name",
")",
")",
";",
"if",
"(",
"$",
"source",
"instanceof",
"Mustache_Source",
")",
"{",
"$",
"source",
"=",
"$",
"source",
"->",
"getSource",
"(",
")",
";",
"}",
"$",
"tree",
"=",
"$",
"this",
"->",
"parse",
"(",
"$",
"source",
")",
";",
"$",
"compiler",
"=",
"$",
"this",
"->",
"getCompiler",
"(",
")",
";",
"$",
"compiler",
"->",
"setPragmas",
"(",
"$",
"this",
"->",
"getPragmas",
"(",
")",
")",
";",
"return",
"$",
"compiler",
"->",
"compile",
"(",
"$",
"source",
",",
"$",
"tree",
",",
"$",
"name",
",",
"isset",
"(",
"$",
"this",
"->",
"escape",
")",
",",
"$",
"this",
"->",
"charset",
",",
"$",
"this",
"->",
"strictCallables",
",",
"$",
"this",
"->",
"entityFlags",
")",
";",
"}"
] |
Helper method to compile a Mustache template.
@see Mustache_Compiler::compile
@param string|Mustache_Source $source
@return string generated Mustache template class code
|
[
"Helper",
"method",
"to",
"compile",
"a",
"Mustache",
"template",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Engine.php#L795-L814
|
220,086
|
moodle/moodle
|
lib/mustache/src/Mustache/Engine.php
|
Mustache_Engine.log
|
private function log($level, $message, array $context = array())
{
if (isset($this->logger)) {
$this->logger->log($level, $message, $context);
}
}
|
php
|
private function log($level, $message, array $context = array())
{
if (isset($this->logger)) {
$this->logger->log($level, $message, $context);
}
}
|
[
"private",
"function",
"log",
"(",
"$",
"level",
",",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"logger",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"log",
"(",
"$",
"level",
",",
"$",
"message",
",",
"$",
"context",
")",
";",
"}",
"}"
] |
Add a log record if logging is enabled.
@param int $level The logging level
@param string $message The log message
@param array $context The log context
|
[
"Add",
"a",
"log",
"record",
"if",
"logging",
"is",
"enabled",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Engine.php#L823-L828
|
220,087
|
moodle/moodle
|
admin/tool/uploadcourse/classes/processor.php
|
tool_uploadcourse_processor.get_course
|
protected function get_course($data) {
$importoptions = array(
'candelete' => $this->allowdeletes,
'canrename' => $this->allowrenames,
'canreset' => $this->allowresets,
'reset' => $this->reset,
'restoredir' => $this->get_restore_content_dir(),
'shortnametemplate' => $this->shortnametemplate
);
return new tool_uploadcourse_course($this->mode, $this->updatemode, $data, $this->defaults, $importoptions);
}
|
php
|
protected function get_course($data) {
$importoptions = array(
'candelete' => $this->allowdeletes,
'canrename' => $this->allowrenames,
'canreset' => $this->allowresets,
'reset' => $this->reset,
'restoredir' => $this->get_restore_content_dir(),
'shortnametemplate' => $this->shortnametemplate
);
return new tool_uploadcourse_course($this->mode, $this->updatemode, $data, $this->defaults, $importoptions);
}
|
[
"protected",
"function",
"get_course",
"(",
"$",
"data",
")",
"{",
"$",
"importoptions",
"=",
"array",
"(",
"'candelete'",
"=>",
"$",
"this",
"->",
"allowdeletes",
",",
"'canrename'",
"=>",
"$",
"this",
"->",
"allowrenames",
",",
"'canreset'",
"=>",
"$",
"this",
"->",
"allowresets",
",",
"'reset'",
"=>",
"$",
"this",
"->",
"reset",
",",
"'restoredir'",
"=>",
"$",
"this",
"->",
"get_restore_content_dir",
"(",
")",
",",
"'shortnametemplate'",
"=>",
"$",
"this",
"->",
"shortnametemplate",
")",
";",
"return",
"new",
"tool_uploadcourse_course",
"(",
"$",
"this",
"->",
"mode",
",",
"$",
"this",
"->",
"updatemode",
",",
"$",
"data",
",",
"$",
"this",
"->",
"defaults",
",",
"$",
"importoptions",
")",
";",
"}"
] |
Return a course import object.
@param array $data data to import the course with.
@return tool_uploadcourse_course
|
[
"Return",
"a",
"course",
"import",
"object",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/uploadcourse/classes/processor.php#L238-L248
|
220,088
|
moodle/moodle
|
admin/tool/uploadcourse/classes/processor.php
|
tool_uploadcourse_processor.log_error
|
protected function log_error($errors) {
if (empty($errors)) {
return;
}
foreach ($errors as $code => $langstring) {
if (!isset($this->errors[$this->linenb])) {
$this->errors[$this->linenb] = array();
}
$this->errors[$this->linenb][$code] = $langstring;
}
}
|
php
|
protected function log_error($errors) {
if (empty($errors)) {
return;
}
foreach ($errors as $code => $langstring) {
if (!isset($this->errors[$this->linenb])) {
$this->errors[$this->linenb] = array();
}
$this->errors[$this->linenb][$code] = $langstring;
}
}
|
[
"protected",
"function",
"log_error",
"(",
"$",
"errors",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"errors",
")",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"errors",
"as",
"$",
"code",
"=>",
"$",
"langstring",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"errors",
"[",
"$",
"this",
"->",
"linenb",
"]",
")",
")",
"{",
"$",
"this",
"->",
"errors",
"[",
"$",
"this",
"->",
"linenb",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"this",
"->",
"errors",
"[",
"$",
"this",
"->",
"linenb",
"]",
"[",
"$",
"code",
"]",
"=",
"$",
"langstring",
";",
"}",
"}"
] |
Log errors on the current line.
@param array $errors array of errors
@return void
|
[
"Log",
"errors",
"on",
"the",
"current",
"line",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/uploadcourse/classes/processor.php#L284-L295
|
220,089
|
moodle/moodle
|
admin/tool/uploadcourse/classes/processor.php
|
tool_uploadcourse_processor.preview
|
public function preview($rows = 10, $tracker = null) {
if ($this->processstarted) {
throw new coding_exception('Process has already been started');
}
$this->processstarted = true;
if (empty($tracker)) {
$tracker = new tool_uploadcourse_tracker(tool_uploadcourse_tracker::NO_OUTPUT);
}
$tracker->start();
// We might need extra time and memory depending on the number of rows to preview.
core_php_time_limit::raise();
raise_memory_limit(MEMORY_EXTRA);
// Loop over the CSV lines.
$preview = array();
while (($line = $this->cir->next()) && $rows > $this->linenb) {
$this->linenb++;
$data = $this->parse_line($line);
$course = $this->get_course($data);
$result = $course->prepare();
if (!$result) {
$tracker->output($this->linenb, $result, $course->get_errors(), $data);
} else {
$tracker->output($this->linenb, $result, $course->get_statuses(), $data);
}
$row = $data;
$preview[$this->linenb] = $row;
}
$tracker->finish();
return $preview;
}
|
php
|
public function preview($rows = 10, $tracker = null) {
if ($this->processstarted) {
throw new coding_exception('Process has already been started');
}
$this->processstarted = true;
if (empty($tracker)) {
$tracker = new tool_uploadcourse_tracker(tool_uploadcourse_tracker::NO_OUTPUT);
}
$tracker->start();
// We might need extra time and memory depending on the number of rows to preview.
core_php_time_limit::raise();
raise_memory_limit(MEMORY_EXTRA);
// Loop over the CSV lines.
$preview = array();
while (($line = $this->cir->next()) && $rows > $this->linenb) {
$this->linenb++;
$data = $this->parse_line($line);
$course = $this->get_course($data);
$result = $course->prepare();
if (!$result) {
$tracker->output($this->linenb, $result, $course->get_errors(), $data);
} else {
$tracker->output($this->linenb, $result, $course->get_statuses(), $data);
}
$row = $data;
$preview[$this->linenb] = $row;
}
$tracker->finish();
return $preview;
}
|
[
"public",
"function",
"preview",
"(",
"$",
"rows",
"=",
"10",
",",
"$",
"tracker",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"processstarted",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"'Process has already been started'",
")",
";",
"}",
"$",
"this",
"->",
"processstarted",
"=",
"true",
";",
"if",
"(",
"empty",
"(",
"$",
"tracker",
")",
")",
"{",
"$",
"tracker",
"=",
"new",
"tool_uploadcourse_tracker",
"(",
"tool_uploadcourse_tracker",
"::",
"NO_OUTPUT",
")",
";",
"}",
"$",
"tracker",
"->",
"start",
"(",
")",
";",
"// We might need extra time and memory depending on the number of rows to preview.",
"core_php_time_limit",
"::",
"raise",
"(",
")",
";",
"raise_memory_limit",
"(",
"MEMORY_EXTRA",
")",
";",
"// Loop over the CSV lines.",
"$",
"preview",
"=",
"array",
"(",
")",
";",
"while",
"(",
"(",
"$",
"line",
"=",
"$",
"this",
"->",
"cir",
"->",
"next",
"(",
")",
")",
"&&",
"$",
"rows",
">",
"$",
"this",
"->",
"linenb",
")",
"{",
"$",
"this",
"->",
"linenb",
"++",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"parse_line",
"(",
"$",
"line",
")",
";",
"$",
"course",
"=",
"$",
"this",
"->",
"get_course",
"(",
"$",
"data",
")",
";",
"$",
"result",
"=",
"$",
"course",
"->",
"prepare",
"(",
")",
";",
"if",
"(",
"!",
"$",
"result",
")",
"{",
"$",
"tracker",
"->",
"output",
"(",
"$",
"this",
"->",
"linenb",
",",
"$",
"result",
",",
"$",
"course",
"->",
"get_errors",
"(",
")",
",",
"$",
"data",
")",
";",
"}",
"else",
"{",
"$",
"tracker",
"->",
"output",
"(",
"$",
"this",
"->",
"linenb",
",",
"$",
"result",
",",
"$",
"course",
"->",
"get_statuses",
"(",
")",
",",
"$",
"data",
")",
";",
"}",
"$",
"row",
"=",
"$",
"data",
";",
"$",
"preview",
"[",
"$",
"this",
"->",
"linenb",
"]",
"=",
"$",
"row",
";",
"}",
"$",
"tracker",
"->",
"finish",
"(",
")",
";",
"return",
"$",
"preview",
";",
"}"
] |
Return a preview of the import.
This only returns passed data, along with the errors.
@param integer $rows number of rows to preview.
@param object $tracker the output tracker to use.
@return array of preview data.
|
[
"Return",
"a",
"preview",
"of",
"the",
"import",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/uploadcourse/classes/processor.php#L326-L360
|
220,090
|
moodle/moodle
|
admin/tool/uploadcourse/classes/processor.php
|
tool_uploadcourse_processor.reset
|
public function reset() {
$this->processstarted = false;
$this->linenb = 0;
$this->cir->init();
$this->errors = array();
}
|
php
|
public function reset() {
$this->processstarted = false;
$this->linenb = 0;
$this->cir->init();
$this->errors = array();
}
|
[
"public",
"function",
"reset",
"(",
")",
"{",
"$",
"this",
"->",
"processstarted",
"=",
"false",
";",
"$",
"this",
"->",
"linenb",
"=",
"0",
";",
"$",
"this",
"->",
"cir",
"->",
"init",
"(",
")",
";",
"$",
"this",
"->",
"errors",
"=",
"array",
"(",
")",
";",
"}"
] |
Reset the current process.
@return void.
|
[
"Reset",
"the",
"current",
"process",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/uploadcourse/classes/processor.php#L367-L372
|
220,091
|
moodle/moodle
|
tag/classes/area.php
|
core_tag_area.get_areas
|
public static function get_areas($tagcollid = null, $enabledonly = false) {
global $DB;
$cache = cache::make('core', 'tags');
if (($itemtypes = $cache->get('tag_area')) === false) {
$colls = core_tag_collection::get_collections();
$defaultcoll = reset($colls);
$itemtypes = array();
$areas = $DB->get_records('tag_area', array(), 'component,itemtype');
foreach ($areas as $area) {
if ($colls[$area->tagcollid]->component) {
$area->locked = true;
}
$itemtypes[$area->itemtype][$area->component] = $area;
}
$cache->set('tag_area', $itemtypes);
}
if ($tagcollid || $enabledonly) {
$rv = array();
foreach ($itemtypes as $itemtype => $it) {
foreach ($it as $component => $v) {
if (($v->tagcollid == $tagcollid || !$tagcollid) && (!$enabledonly || $v->enabled)) {
$rv[$itemtype][$component] = $v;
}
}
}
return $rv;
}
return $itemtypes;
}
|
php
|
public static function get_areas($tagcollid = null, $enabledonly = false) {
global $DB;
$cache = cache::make('core', 'tags');
if (($itemtypes = $cache->get('tag_area')) === false) {
$colls = core_tag_collection::get_collections();
$defaultcoll = reset($colls);
$itemtypes = array();
$areas = $DB->get_records('tag_area', array(), 'component,itemtype');
foreach ($areas as $area) {
if ($colls[$area->tagcollid]->component) {
$area->locked = true;
}
$itemtypes[$area->itemtype][$area->component] = $area;
}
$cache->set('tag_area', $itemtypes);
}
if ($tagcollid || $enabledonly) {
$rv = array();
foreach ($itemtypes as $itemtype => $it) {
foreach ($it as $component => $v) {
if (($v->tagcollid == $tagcollid || !$tagcollid) && (!$enabledonly || $v->enabled)) {
$rv[$itemtype][$component] = $v;
}
}
}
return $rv;
}
return $itemtypes;
}
|
[
"public",
"static",
"function",
"get_areas",
"(",
"$",
"tagcollid",
"=",
"null",
",",
"$",
"enabledonly",
"=",
"false",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"cache",
"=",
"cache",
"::",
"make",
"(",
"'core'",
",",
"'tags'",
")",
";",
"if",
"(",
"(",
"$",
"itemtypes",
"=",
"$",
"cache",
"->",
"get",
"(",
"'tag_area'",
")",
")",
"===",
"false",
")",
"{",
"$",
"colls",
"=",
"core_tag_collection",
"::",
"get_collections",
"(",
")",
";",
"$",
"defaultcoll",
"=",
"reset",
"(",
"$",
"colls",
")",
";",
"$",
"itemtypes",
"=",
"array",
"(",
")",
";",
"$",
"areas",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'tag_area'",
",",
"array",
"(",
")",
",",
"'component,itemtype'",
")",
";",
"foreach",
"(",
"$",
"areas",
"as",
"$",
"area",
")",
"{",
"if",
"(",
"$",
"colls",
"[",
"$",
"area",
"->",
"tagcollid",
"]",
"->",
"component",
")",
"{",
"$",
"area",
"->",
"locked",
"=",
"true",
";",
"}",
"$",
"itemtypes",
"[",
"$",
"area",
"->",
"itemtype",
"]",
"[",
"$",
"area",
"->",
"component",
"]",
"=",
"$",
"area",
";",
"}",
"$",
"cache",
"->",
"set",
"(",
"'tag_area'",
",",
"$",
"itemtypes",
")",
";",
"}",
"if",
"(",
"$",
"tagcollid",
"||",
"$",
"enabledonly",
")",
"{",
"$",
"rv",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"itemtypes",
"as",
"$",
"itemtype",
"=>",
"$",
"it",
")",
"{",
"foreach",
"(",
"$",
"it",
"as",
"$",
"component",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"(",
"$",
"v",
"->",
"tagcollid",
"==",
"$",
"tagcollid",
"||",
"!",
"$",
"tagcollid",
")",
"&&",
"(",
"!",
"$",
"enabledonly",
"||",
"$",
"v",
"->",
"enabled",
")",
")",
"{",
"$",
"rv",
"[",
"$",
"itemtype",
"]",
"[",
"$",
"component",
"]",
"=",
"$",
"v",
";",
"}",
"}",
"}",
"return",
"$",
"rv",
";",
"}",
"return",
"$",
"itemtypes",
";",
"}"
] |
Returns the list of areas indexed by itemtype and component
@param int $tagcollid return only areas in this tag collection
@param bool $enabledonly return only enabled tag areas
@return array itemtype=>component=>tagarea object
|
[
"Returns",
"the",
"list",
"of",
"areas",
"indexed",
"by",
"itemtype",
"and",
"component"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/area.php#L43-L71
|
220,092
|
moodle/moodle
|
tag/classes/area.php
|
core_tag_area.get_by_id
|
public static function get_by_id($tagareaid) {
$tagareas = self::get_areas();
foreach ($tagareas as $itemtype => $it) {
foreach ($it as $component => $v) {
if ($v->id == $tagareaid) {
return $v;
}
}
}
return null;
}
|
php
|
public static function get_by_id($tagareaid) {
$tagareas = self::get_areas();
foreach ($tagareas as $itemtype => $it) {
foreach ($it as $component => $v) {
if ($v->id == $tagareaid) {
return $v;
}
}
}
return null;
}
|
[
"public",
"static",
"function",
"get_by_id",
"(",
"$",
"tagareaid",
")",
"{",
"$",
"tagareas",
"=",
"self",
"::",
"get_areas",
"(",
")",
";",
"foreach",
"(",
"$",
"tagareas",
"as",
"$",
"itemtype",
"=>",
"$",
"it",
")",
"{",
"foreach",
"(",
"$",
"it",
"as",
"$",
"component",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"$",
"v",
"->",
"id",
"==",
"$",
"tagareaid",
")",
"{",
"return",
"$",
"v",
";",
"}",
"}",
"}",
"return",
"null",
";",
"}"
] |
Retrieves info about one tag area
@param int $tagareaid
@return stdClass
|
[
"Retrieves",
"info",
"about",
"one",
"tag",
"area"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/area.php#L79-L89
|
220,093
|
moodle/moodle
|
tag/classes/area.php
|
core_tag_area.display_name
|
public static function display_name($component, $itemtype) {
$identifier = 'tagarea_' . clean_param($itemtype, PARAM_STRINGID);
if ($component === 'core') {
$component = 'tag';
}
return new lang_string($identifier, $component);
}
|
php
|
public static function display_name($component, $itemtype) {
$identifier = 'tagarea_' . clean_param($itemtype, PARAM_STRINGID);
if ($component === 'core') {
$component = 'tag';
}
return new lang_string($identifier, $component);
}
|
[
"public",
"static",
"function",
"display_name",
"(",
"$",
"component",
",",
"$",
"itemtype",
")",
"{",
"$",
"identifier",
"=",
"'tagarea_'",
".",
"clean_param",
"(",
"$",
"itemtype",
",",
"PARAM_STRINGID",
")",
";",
"if",
"(",
"$",
"component",
"===",
"'core'",
")",
"{",
"$",
"component",
"=",
"'tag'",
";",
"}",
"return",
"new",
"lang_string",
"(",
"$",
"identifier",
",",
"$",
"component",
")",
";",
"}"
] |
Returns the display name for this area
@param string $component
@param string $itemtype
@return lang_string
|
[
"Returns",
"the",
"display",
"name",
"for",
"this",
"area"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/area.php#L98-L104
|
220,094
|
moodle/moodle
|
tag/classes/area.php
|
core_tag_area.is_enabled
|
public static function is_enabled($component, $itemtype) {
global $CFG;
if (empty($CFG->usetags)) {
return false;
}
$itemtypes = self::get_areas();
if (isset($itemtypes[$itemtype][$component])) {
return $itemtypes[$itemtype][$component]->enabled ? true : false;
}
return null;
}
|
php
|
public static function is_enabled($component, $itemtype) {
global $CFG;
if (empty($CFG->usetags)) {
return false;
}
$itemtypes = self::get_areas();
if (isset($itemtypes[$itemtype][$component])) {
return $itemtypes[$itemtype][$component]->enabled ? true : false;
}
return null;
}
|
[
"public",
"static",
"function",
"is_enabled",
"(",
"$",
"component",
",",
"$",
"itemtype",
")",
"{",
"global",
"$",
"CFG",
";",
"if",
"(",
"empty",
"(",
"$",
"CFG",
"->",
"usetags",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"itemtypes",
"=",
"self",
"::",
"get_areas",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"itemtypes",
"[",
"$",
"itemtype",
"]",
"[",
"$",
"component",
"]",
")",
")",
"{",
"return",
"$",
"itemtypes",
"[",
"$",
"itemtype",
"]",
"[",
"$",
"component",
"]",
"->",
"enabled",
"?",
"true",
":",
"false",
";",
"}",
"return",
"null",
";",
"}"
] |
Returns whether the tag area is enabled
@param string $component component responsible for tagging
@param string $itemtype what is being tagged, for example, 'post', 'course', 'user', etc.
@return bool|null
|
[
"Returns",
"whether",
"the",
"tag",
"area",
"is",
"enabled"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/area.php#L113-L123
|
220,095
|
moodle/moodle
|
tag/classes/area.php
|
core_tag_area.allows_tagging_in_multiple_contexts
|
public static function allows_tagging_in_multiple_contexts($component, $itemtype) {
$itemtypes = self::get_areas();
if (isset($itemtypes[$itemtype][$component])) {
$config = $itemtypes[$itemtype][$component];
return isset($config->multiplecontexts) ? $config->multiplecontexts : false;
}
return false;
}
|
php
|
public static function allows_tagging_in_multiple_contexts($component, $itemtype) {
$itemtypes = self::get_areas();
if (isset($itemtypes[$itemtype][$component])) {
$config = $itemtypes[$itemtype][$component];
return isset($config->multiplecontexts) ? $config->multiplecontexts : false;
}
return false;
}
|
[
"public",
"static",
"function",
"allows_tagging_in_multiple_contexts",
"(",
"$",
"component",
",",
"$",
"itemtype",
")",
"{",
"$",
"itemtypes",
"=",
"self",
"::",
"get_areas",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"itemtypes",
"[",
"$",
"itemtype",
"]",
"[",
"$",
"component",
"]",
")",
")",
"{",
"$",
"config",
"=",
"$",
"itemtypes",
"[",
"$",
"itemtype",
"]",
"[",
"$",
"component",
"]",
";",
"return",
"isset",
"(",
"$",
"config",
"->",
"multiplecontexts",
")",
"?",
"$",
"config",
"->",
"multiplecontexts",
":",
"false",
";",
"}",
"return",
"false",
";",
"}"
] |
Checks if the tag area allows items to be tagged in multiple different contexts.
If true then it indicates that not all tag instance contexts must match the
context of the item they are tagging. If false then all tag instance should
match the context of the item they are tagging.
Example use case for multi-context tagging:
A question that exists in a course category context may be used by multiple
child courses. The question tag area can allow tag instances to be created in
multiple contexts which allows the tag API to tag the question at the course
category context and then seperately in each of the child course contexts.
@param string $component component responsible for tagging
@param string $itemtype what is being tagged, for example, 'post', 'course', 'user', etc.
@return bool
|
[
"Checks",
"if",
"the",
"tag",
"area",
"allows",
"items",
"to",
"be",
"tagged",
"in",
"multiple",
"different",
"contexts",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/area.php#L142-L149
|
220,096
|
moodle/moodle
|
tag/classes/area.php
|
core_tag_area.get_collection
|
public static function get_collection($component, $itemtype) {
$itemtypes = self::get_areas();
if (array_key_exists($itemtype, $itemtypes)) {
if (!array_key_exists($component, $itemtypes[$itemtype])) {
$component = key($itemtypes[$itemtype]);
}
return $itemtypes[$itemtype][$component]->tagcollid;
}
return core_tag_collection::get_default();
}
|
php
|
public static function get_collection($component, $itemtype) {
$itemtypes = self::get_areas();
if (array_key_exists($itemtype, $itemtypes)) {
if (!array_key_exists($component, $itemtypes[$itemtype])) {
$component = key($itemtypes[$itemtype]);
}
return $itemtypes[$itemtype][$component]->tagcollid;
}
return core_tag_collection::get_default();
}
|
[
"public",
"static",
"function",
"get_collection",
"(",
"$",
"component",
",",
"$",
"itemtype",
")",
"{",
"$",
"itemtypes",
"=",
"self",
"::",
"get_areas",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"itemtype",
",",
"$",
"itemtypes",
")",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"component",
",",
"$",
"itemtypes",
"[",
"$",
"itemtype",
"]",
")",
")",
"{",
"$",
"component",
"=",
"key",
"(",
"$",
"itemtypes",
"[",
"$",
"itemtype",
"]",
")",
";",
"}",
"return",
"$",
"itemtypes",
"[",
"$",
"itemtype",
"]",
"[",
"$",
"component",
"]",
"->",
"tagcollid",
";",
"}",
"return",
"core_tag_collection",
"::",
"get_default",
"(",
")",
";",
"}"
] |
Returns the id of the tag collection that should be used for storing tags of this itemtype
@param string $component component responsible for tagging
@param string $itemtype what is being tagged, for example, 'post', 'course', 'user', etc.
@return int
|
[
"Returns",
"the",
"id",
"of",
"the",
"tag",
"collection",
"that",
"should",
"be",
"used",
"for",
"storing",
"tags",
"of",
"this",
"itemtype"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/area.php#L158-L167
|
220,097
|
moodle/moodle
|
tag/classes/area.php
|
core_tag_area.get_showstandard
|
public static function get_showstandard($component, $itemtype) {
$itemtypes = self::get_areas();
if (array_key_exists($itemtype, $itemtypes)) {
if (!array_key_exists($component, $itemtypes[$itemtype])) {
$component = key($itemtypes[$itemtype]);
}
return $itemtypes[$itemtype][$component]->showstandard;
}
return core_tag_tag::BOTH_STANDARD_AND_NOT;
}
|
php
|
public static function get_showstandard($component, $itemtype) {
$itemtypes = self::get_areas();
if (array_key_exists($itemtype, $itemtypes)) {
if (!array_key_exists($component, $itemtypes[$itemtype])) {
$component = key($itemtypes[$itemtype]);
}
return $itemtypes[$itemtype][$component]->showstandard;
}
return core_tag_tag::BOTH_STANDARD_AND_NOT;
}
|
[
"public",
"static",
"function",
"get_showstandard",
"(",
"$",
"component",
",",
"$",
"itemtype",
")",
"{",
"$",
"itemtypes",
"=",
"self",
"::",
"get_areas",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"itemtype",
",",
"$",
"itemtypes",
")",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"component",
",",
"$",
"itemtypes",
"[",
"$",
"itemtype",
"]",
")",
")",
"{",
"$",
"component",
"=",
"key",
"(",
"$",
"itemtypes",
"[",
"$",
"itemtype",
"]",
")",
";",
"}",
"return",
"$",
"itemtypes",
"[",
"$",
"itemtype",
"]",
"[",
"$",
"component",
"]",
"->",
"showstandard",
";",
"}",
"return",
"core_tag_tag",
"::",
"BOTH_STANDARD_AND_NOT",
";",
"}"
] |
Returns wether this tag area should display or not standard tags when user edits it.
@param string $component component responsible for tagging
@param string $itemtype what is being tagged, for example, 'post', 'course', 'user', etc.
@return int
|
[
"Returns",
"wether",
"this",
"tag",
"area",
"should",
"display",
"or",
"not",
"standard",
"tags",
"when",
"user",
"edits",
"it",
"."
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/area.php#L176-L185
|
220,098
|
moodle/moodle
|
tag/classes/area.php
|
core_tag_area.get_definitions_for_component
|
protected static function get_definitions_for_component($componentname) {
global $DB;
list($a, $b) = core_component::normalize_component($componentname);
$component = $b ? ($a . '_' . $b) : $a;
$sql = 'component = :component';
$params = array('component' => $component);
if ($component === 'core') {
$sql .= ' OR component LIKE :coreprefix';
$params['coreprefix'] = 'core_%';
}
$fields = $DB->sql_concat_join("':'", array('itemtype', 'component'));
$existingareas = $DB->get_records_sql(
"SELECT $fields AS returnkey, a.* FROM {tag_area} a WHERE $sql", $params);
$fields = $DB->sql_concat_join("':'", array('name', 'component'));
$existingcolls = $DB->get_records_sql(
"SELECT $fields AS returnkey, t.* FROM {tag_coll} t WHERE $sql", $params);
return array($existingareas, $existingcolls);
}
|
php
|
protected static function get_definitions_for_component($componentname) {
global $DB;
list($a, $b) = core_component::normalize_component($componentname);
$component = $b ? ($a . '_' . $b) : $a;
$sql = 'component = :component';
$params = array('component' => $component);
if ($component === 'core') {
$sql .= ' OR component LIKE :coreprefix';
$params['coreprefix'] = 'core_%';
}
$fields = $DB->sql_concat_join("':'", array('itemtype', 'component'));
$existingareas = $DB->get_records_sql(
"SELECT $fields AS returnkey, a.* FROM {tag_area} a WHERE $sql", $params);
$fields = $DB->sql_concat_join("':'", array('name', 'component'));
$existingcolls = $DB->get_records_sql(
"SELECT $fields AS returnkey, t.* FROM {tag_coll} t WHERE $sql", $params);
return array($existingareas, $existingcolls);
}
|
[
"protected",
"static",
"function",
"get_definitions_for_component",
"(",
"$",
"componentname",
")",
"{",
"global",
"$",
"DB",
";",
"list",
"(",
"$",
"a",
",",
"$",
"b",
")",
"=",
"core_component",
"::",
"normalize_component",
"(",
"$",
"componentname",
")",
";",
"$",
"component",
"=",
"$",
"b",
"?",
"(",
"$",
"a",
".",
"'_'",
".",
"$",
"b",
")",
":",
"$",
"a",
";",
"$",
"sql",
"=",
"'component = :component'",
";",
"$",
"params",
"=",
"array",
"(",
"'component'",
"=>",
"$",
"component",
")",
";",
"if",
"(",
"$",
"component",
"===",
"'core'",
")",
"{",
"$",
"sql",
".=",
"' OR component LIKE :coreprefix'",
";",
"$",
"params",
"[",
"'coreprefix'",
"]",
"=",
"'core_%'",
";",
"}",
"$",
"fields",
"=",
"$",
"DB",
"->",
"sql_concat_join",
"(",
"\"':'\"",
",",
"array",
"(",
"'itemtype'",
",",
"'component'",
")",
")",
";",
"$",
"existingareas",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"\"SELECT $fields AS returnkey, a.* FROM {tag_area} a WHERE $sql\"",
",",
"$",
"params",
")",
";",
"$",
"fields",
"=",
"$",
"DB",
"->",
"sql_concat_join",
"(",
"\"':'\"",
",",
"array",
"(",
"'name'",
",",
"'component'",
")",
")",
";",
"$",
"existingcolls",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"\"SELECT $fields AS returnkey, t.* FROM {tag_coll} t WHERE $sql\"",
",",
"$",
"params",
")",
";",
"return",
"array",
"(",
"$",
"existingareas",
",",
"$",
"existingcolls",
")",
";",
"}"
] |
Returns all tag areas and collections that are currently cached in DB for this component
@param string $componentname
@return array first element is the list of areas and the second list of collections
|
[
"Returns",
"all",
"tag",
"areas",
"and",
"collections",
"that",
"are",
"currently",
"cached",
"in",
"DB",
"for",
"this",
"component"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/area.php#L193-L211
|
220,099
|
moodle/moodle
|
tag/classes/area.php
|
core_tag_area.delete
|
protected static function delete($record) {
global $DB;
core_tag_tag::delete_instances($record->component, $record->itemtype);
$DB->delete_records('tag_area',
array('itemtype' => $record->itemtype,
'component' => $record->component));
// Reset cache.
cache::make('core', 'tags')->delete('tag_area');
}
|
php
|
protected static function delete($record) {
global $DB;
core_tag_tag::delete_instances($record->component, $record->itemtype);
$DB->delete_records('tag_area',
array('itemtype' => $record->itemtype,
'component' => $record->component));
// Reset cache.
cache::make('core', 'tags')->delete('tag_area');
}
|
[
"protected",
"static",
"function",
"delete",
"(",
"$",
"record",
")",
"{",
"global",
"$",
"DB",
";",
"core_tag_tag",
"::",
"delete_instances",
"(",
"$",
"record",
"->",
"component",
",",
"$",
"record",
"->",
"itemtype",
")",
";",
"$",
"DB",
"->",
"delete_records",
"(",
"'tag_area'",
",",
"array",
"(",
"'itemtype'",
"=>",
"$",
"record",
"->",
"itemtype",
",",
"'component'",
"=>",
"$",
"record",
"->",
"component",
")",
")",
";",
"// Reset cache.",
"cache",
"::",
"make",
"(",
"'core'",
",",
"'tags'",
")",
"->",
"delete",
"(",
"'tag_area'",
")",
";",
"}"
] |
Completely delete a tag area and all instances inside it
@param stdClass $record
|
[
"Completely",
"delete",
"a",
"tag",
"area",
"and",
"all",
"instances",
"inside",
"it"
] |
a411b499b98afc9901c24a9466c7e322946a04aa
|
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/area.php#L218-L229
|
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.