id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
214,300
moodle/moodle
grade/report/singleview/classes/local/ui/feedback.php
feedback.set
public function set($value) { $finalgrade = false; $trimmed = trim($value); if (empty($trimmed)) { $feedback = null; } else { $feedback = $value; } $this->grade->grade_item->update_final_grade( $this->grade->userid, $finalgrade, 'singleview', $feedback, FORMAT_MOODLE ); }
php
public function set($value) { $finalgrade = false; $trimmed = trim($value); if (empty($trimmed)) { $feedback = null; } else { $feedback = $value; } $this->grade->grade_item->update_final_grade( $this->grade->userid, $finalgrade, 'singleview', $feedback, FORMAT_MOODLE ); }
[ "public", "function", "set", "(", "$", "value", ")", "{", "$", "finalgrade", "=", "false", ";", "$", "trimmed", "=", "trim", "(", "$", "value", ")", ";", "if", "(", "empty", "(", "$", "trimmed", ")", ")", "{", "$", "feedback", "=", "null", ";", "}", "else", "{", "$", "feedback", "=", "$", "value", ";", "}", "$", "this", "->", "grade", "->", "grade_item", "->", "update_final_grade", "(", "$", "this", "->", "grade", "->", "userid", ",", "$", "finalgrade", ",", "'singleview'", ",", "$", "feedback", ",", "FORMAT_MOODLE", ")", ";", "}" ]
Update the value for this input. @param string $value The new feedback value. @return string Any error message
[ "Update", "the", "value", "for", "this", "input", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/ui/feedback.php#L108-L121
214,301
moodle/moodle
mod/feedback/classes/structure.php
mod_feedback_structure.get_items
public function get_items($hasvalueonly = false) { global $DB; if ($this->allitems === null) { if ($this->templateid) { $this->allitems = $DB->get_records('feedback_item', ['template' => $this->templateid], 'position'); } else { $this->allitems = $DB->get_records('feedback_item', ['feedback' => $this->feedback->id], 'position'); } $idx = 1; foreach ($this->allitems as $id => $item) { $this->allitems[$id]->itemnr = $item->hasvalue ? ($idx++) : null; } } if ($hasvalueonly && $this->allitems) { return array_filter($this->allitems, function($item) { return $item->hasvalue; }); } return $this->allitems; }
php
public function get_items($hasvalueonly = false) { global $DB; if ($this->allitems === null) { if ($this->templateid) { $this->allitems = $DB->get_records('feedback_item', ['template' => $this->templateid], 'position'); } else { $this->allitems = $DB->get_records('feedback_item', ['feedback' => $this->feedback->id], 'position'); } $idx = 1; foreach ($this->allitems as $id => $item) { $this->allitems[$id]->itemnr = $item->hasvalue ? ($idx++) : null; } } if ($hasvalueonly && $this->allitems) { return array_filter($this->allitems, function($item) { return $item->hasvalue; }); } return $this->allitems; }
[ "public", "function", "get_items", "(", "$", "hasvalueonly", "=", "false", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "this", "->", "allitems", "===", "null", ")", "{", "if", "(", "$", "this", "->", "templateid", ")", "{", "$", "this", "->", "allitems", "=", "$", "DB", "->", "get_records", "(", "'feedback_item'", ",", "[", "'template'", "=>", "$", "this", "->", "templateid", "]", ",", "'position'", ")", ";", "}", "else", "{", "$", "this", "->", "allitems", "=", "$", "DB", "->", "get_records", "(", "'feedback_item'", ",", "[", "'feedback'", "=>", "$", "this", "->", "feedback", "->", "id", "]", ",", "'position'", ")", ";", "}", "$", "idx", "=", "1", ";", "foreach", "(", "$", "this", "->", "allitems", "as", "$", "id", "=>", "$", "item", ")", "{", "$", "this", "->", "allitems", "[", "$", "id", "]", "->", "itemnr", "=", "$", "item", "->", "hasvalue", "?", "(", "$", "idx", "++", ")", ":", "null", ";", "}", "}", "if", "(", "$", "hasvalueonly", "&&", "$", "this", "->", "allitems", ")", "{", "return", "array_filter", "(", "$", "this", "->", "allitems", ",", "function", "(", "$", "item", ")", "{", "return", "$", "item", "->", "hasvalue", ";", "}", ")", ";", "}", "return", "$", "this", "->", "allitems", ";", "}" ]
Get all items in this feedback or this template @param bool $hasvalueonly only count items with a value. @return array of objects from feedback_item with an additional attribute 'itemnr'
[ "Get", "all", "items", "in", "this", "feedback", "or", "this", "template" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/structure.php#L146-L165
214,302
moodle/moodle
mod/feedback/classes/structure.php
mod_feedback_structure.is_empty
public function is_empty() { $items = $this->get_items(); $displayeditems = array_filter($items, function($item) { return $item->typ !== 'pagebreak'; }); return !$displayeditems; }
php
public function is_empty() { $items = $this->get_items(); $displayeditems = array_filter($items, function($item) { return $item->typ !== 'pagebreak'; }); return !$displayeditems; }
[ "public", "function", "is_empty", "(", ")", "{", "$", "items", "=", "$", "this", "->", "get_items", "(", ")", ";", "$", "displayeditems", "=", "array_filter", "(", "$", "items", ",", "function", "(", "$", "item", ")", "{", "return", "$", "item", "->", "typ", "!==", "'pagebreak'", ";", "}", ")", ";", "return", "!", "$", "displayeditems", ";", "}" ]
Is the items list empty? @return bool
[ "Is", "the", "items", "list", "empty?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/structure.php#L171-L177
214,303
moodle/moodle
mod/feedback/classes/structure.php
mod_feedback_structure.page_after_submit
public function page_after_submit() { global $CFG; require_once($CFG->libdir . '/filelib.php'); $pageaftersubmit = $this->get_feedback()->page_after_submit; if (empty($pageaftersubmit)) { return null; } $pageaftersubmitformat = $this->get_feedback()->page_after_submitformat; $context = context_module::instance($this->get_cm()->id); $output = file_rewrite_pluginfile_urls($pageaftersubmit, 'pluginfile.php', $context->id, 'mod_feedback', 'page_after_submit', 0); return format_text($output, $pageaftersubmitformat, array('overflowdiv' => true)); }
php
public function page_after_submit() { global $CFG; require_once($CFG->libdir . '/filelib.php'); $pageaftersubmit = $this->get_feedback()->page_after_submit; if (empty($pageaftersubmit)) { return null; } $pageaftersubmitformat = $this->get_feedback()->page_after_submitformat; $context = context_module::instance($this->get_cm()->id); $output = file_rewrite_pluginfile_urls($pageaftersubmit, 'pluginfile.php', $context->id, 'mod_feedback', 'page_after_submit', 0); return format_text($output, $pageaftersubmitformat, array('overflowdiv' => true)); }
[ "public", "function", "page_after_submit", "(", ")", "{", "global", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/filelib.php'", ")", ";", "$", "pageaftersubmit", "=", "$", "this", "->", "get_feedback", "(", ")", "->", "page_after_submit", ";", "if", "(", "empty", "(", "$", "pageaftersubmit", ")", ")", "{", "return", "null", ";", "}", "$", "pageaftersubmitformat", "=", "$", "this", "->", "get_feedback", "(", ")", "->", "page_after_submitformat", ";", "$", "context", "=", "context_module", "::", "instance", "(", "$", "this", "->", "get_cm", "(", ")", "->", "id", ")", ";", "$", "output", "=", "file_rewrite_pluginfile_urls", "(", "$", "pageaftersubmit", ",", "'pluginfile.php'", ",", "$", "context", "->", "id", ",", "'mod_feedback'", ",", "'page_after_submit'", ",", "0", ")", ";", "return", "format_text", "(", "$", "output", ",", "$", "pageaftersubmitformat", ",", "array", "(", "'overflowdiv'", "=>", "true", ")", ")", ";", "}" ]
Returns the formatted text of the page after submit or null if it is not set @return string|null
[ "Returns", "the", "formatted", "text", "of", "the", "page", "after", "submit", "or", "null", "if", "it", "is", "not", "set" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/structure.php#L192-L207
214,304
moodle/moodle
mod/feedback/classes/structure.php
mod_feedback_structure.can_view_analysis
public function can_view_analysis() { global $USER; $context = context_module::instance($this->cm->id); if (has_capability('mod/feedback:viewreports', $context, $this->userid)) { return true; } if (intval($this->get_feedback()->publish_stats) != 1 || !has_capability('mod/feedback:viewanalysepage', $context, $this->userid)) { return false; } if ((!isloggedin() && $USER->id == $this->userid) || isguestuser($this->userid)) { // There is no tracking for the guests, assume that they can view analysis if condition above is satisfied. return $this->feedback->course == SITEID; } return $this->is_already_submitted(true); }
php
public function can_view_analysis() { global $USER; $context = context_module::instance($this->cm->id); if (has_capability('mod/feedback:viewreports', $context, $this->userid)) { return true; } if (intval($this->get_feedback()->publish_stats) != 1 || !has_capability('mod/feedback:viewanalysepage', $context, $this->userid)) { return false; } if ((!isloggedin() && $USER->id == $this->userid) || isguestuser($this->userid)) { // There is no tracking for the guests, assume that they can view analysis if condition above is satisfied. return $this->feedback->course == SITEID; } return $this->is_already_submitted(true); }
[ "public", "function", "can_view_analysis", "(", ")", "{", "global", "$", "USER", ";", "$", "context", "=", "context_module", "::", "instance", "(", "$", "this", "->", "cm", "->", "id", ")", ";", "if", "(", "has_capability", "(", "'mod/feedback:viewreports'", ",", "$", "context", ",", "$", "this", "->", "userid", ")", ")", "{", "return", "true", ";", "}", "if", "(", "intval", "(", "$", "this", "->", "get_feedback", "(", ")", "->", "publish_stats", ")", "!=", "1", "||", "!", "has_capability", "(", "'mod/feedback:viewanalysepage'", ",", "$", "context", ",", "$", "this", "->", "userid", ")", ")", "{", "return", "false", ";", "}", "if", "(", "(", "!", "isloggedin", "(", ")", "&&", "$", "USER", "->", "id", "==", "$", "this", "->", "userid", ")", "||", "isguestuser", "(", "$", "this", "->", "userid", ")", ")", "{", "// There is no tracking for the guests, assume that they can view analysis if condition above is satisfied.", "return", "$", "this", "->", "feedback", "->", "course", "==", "SITEID", ";", "}", "return", "$", "this", "->", "is_already_submitted", "(", "true", ")", ";", "}" ]
Checks if current user is able to view feedback on this course. @return bool
[ "Checks", "if", "current", "user", "is", "able", "to", "view", "feedback", "on", "this", "course", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/structure.php#L214-L233
214,305
moodle/moodle
mod/feedback/classes/structure.php
mod_feedback_structure.is_already_submitted
public function is_already_submitted($anycourseid = false) { global $DB, $USER; if ((!isloggedin() && $USER->id == $this->userid) || isguestuser($this->userid)) { return false; } $params = array('userid' => $this->userid, 'feedback' => $this->feedback->id); if (!$anycourseid && $this->courseid) { $params['courseid'] = $this->courseid; } return $DB->record_exists('feedback_completed', $params); }
php
public function is_already_submitted($anycourseid = false) { global $DB, $USER; if ((!isloggedin() && $USER->id == $this->userid) || isguestuser($this->userid)) { return false; } $params = array('userid' => $this->userid, 'feedback' => $this->feedback->id); if (!$anycourseid && $this->courseid) { $params['courseid'] = $this->courseid; } return $DB->record_exists('feedback_completed', $params); }
[ "public", "function", "is_already_submitted", "(", "$", "anycourseid", "=", "false", ")", "{", "global", "$", "DB", ",", "$", "USER", ";", "if", "(", "(", "!", "isloggedin", "(", ")", "&&", "$", "USER", "->", "id", "==", "$", "this", "->", "userid", ")", "||", "isguestuser", "(", "$", "this", "->", "userid", ")", ")", "{", "return", "false", ";", "}", "$", "params", "=", "array", "(", "'userid'", "=>", "$", "this", "->", "userid", ",", "'feedback'", "=>", "$", "this", "->", "feedback", "->", "id", ")", ";", "if", "(", "!", "$", "anycourseid", "&&", "$", "this", "->", "courseid", ")", "{", "$", "params", "[", "'courseid'", "]", "=", "$", "this", "->", "courseid", ";", "}", "return", "$", "DB", "->", "record_exists", "(", "'feedback_completed'", ",", "$", "params", ")", ";", "}" ]
check for multiple_submit = false. if the feedback is global so the courseid must be given @param bool $anycourseid if true checks if this feedback was submitted in any course, otherwise checks $this->courseid . Applicable to frontpage feedbacks only @return bool true if the feedback already is submitted otherwise false
[ "check", "for", "multiple_submit", "=", "false", ".", "if", "the", "feedback", "is", "global", "so", "the", "courseid", "must", "be", "given" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/structure.php#L243-L255
214,306
moodle/moodle
mod/feedback/classes/structure.php
mod_feedback_structure.check_course_is_mapped
public function check_course_is_mapped() { global $DB; if ($this->feedback->course != SITEID) { return true; } if ($DB->get_records('feedback_sitecourse_map', array('feedbackid' => $this->feedback->id))) { $params = array('feedbackid' => $this->feedback->id, 'courseid' => $this->courseid); if (!$DB->get_record('feedback_sitecourse_map', $params)) { return false; } } // No mapping means any course is mapped. return true; }
php
public function check_course_is_mapped() { global $DB; if ($this->feedback->course != SITEID) { return true; } if ($DB->get_records('feedback_sitecourse_map', array('feedbackid' => $this->feedback->id))) { $params = array('feedbackid' => $this->feedback->id, 'courseid' => $this->courseid); if (!$DB->get_record('feedback_sitecourse_map', $params)) { return false; } } // No mapping means any course is mapped. return true; }
[ "public", "function", "check_course_is_mapped", "(", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "this", "->", "feedback", "->", "course", "!=", "SITEID", ")", "{", "return", "true", ";", "}", "if", "(", "$", "DB", "->", "get_records", "(", "'feedback_sitecourse_map'", ",", "array", "(", "'feedbackid'", "=>", "$", "this", "->", "feedback", "->", "id", ")", ")", ")", "{", "$", "params", "=", "array", "(", "'feedbackid'", "=>", "$", "this", "->", "feedback", "->", "id", ",", "'courseid'", "=>", "$", "this", "->", "courseid", ")", ";", "if", "(", "!", "$", "DB", "->", "get_record", "(", "'feedback_sitecourse_map'", ",", "$", "params", ")", ")", "{", "return", "false", ";", "}", "}", "// No mapping means any course is mapped.", "return", "true", ";", "}" ]
Check whether the feedback is mapped to the given courseid.
[ "Check", "whether", "the", "feedback", "is", "mapped", "to", "the", "given", "courseid", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/structure.php#L260-L273
214,307
moodle/moodle
mod/feedback/classes/structure.php
mod_feedback_structure.shuffle_anonym_responses
public function shuffle_anonym_responses() { global $DB; $params = array('feedback' => $this->feedback->id, 'random_response' => 0, 'anonymous_response' => FEEDBACK_ANONYMOUS_YES); if ($DB->count_records('feedback_completed', $params, 'random_response')) { // Get all of the anonymous records, go through them and assign a response id. unset($params['random_response']); $feedbackcompleteds = $DB->get_records('feedback_completed', $params, 'id'); shuffle($feedbackcompleteds); $num = 1; foreach ($feedbackcompleteds as $compl) { $compl->random_response = $num++; $DB->update_record('feedback_completed', $compl); } } }
php
public function shuffle_anonym_responses() { global $DB; $params = array('feedback' => $this->feedback->id, 'random_response' => 0, 'anonymous_response' => FEEDBACK_ANONYMOUS_YES); if ($DB->count_records('feedback_completed', $params, 'random_response')) { // Get all of the anonymous records, go through them and assign a response id. unset($params['random_response']); $feedbackcompleteds = $DB->get_records('feedback_completed', $params, 'id'); shuffle($feedbackcompleteds); $num = 1; foreach ($feedbackcompleteds as $compl) { $compl->random_response = $num++; $DB->update_record('feedback_completed', $compl); } } }
[ "public", "function", "shuffle_anonym_responses", "(", ")", "{", "global", "$", "DB", ";", "$", "params", "=", "array", "(", "'feedback'", "=>", "$", "this", "->", "feedback", "->", "id", ",", "'random_response'", "=>", "0", ",", "'anonymous_response'", "=>", "FEEDBACK_ANONYMOUS_YES", ")", ";", "if", "(", "$", "DB", "->", "count_records", "(", "'feedback_completed'", ",", "$", "params", ",", "'random_response'", ")", ")", "{", "// Get all of the anonymous records, go through them and assign a response id.", "unset", "(", "$", "params", "[", "'random_response'", "]", ")", ";", "$", "feedbackcompleteds", "=", "$", "DB", "->", "get_records", "(", "'feedback_completed'", ",", "$", "params", ",", "'id'", ")", ";", "shuffle", "(", "$", "feedbackcompleteds", ")", ";", "$", "num", "=", "1", ";", "foreach", "(", "$", "feedbackcompleteds", "as", "$", "compl", ")", "{", "$", "compl", "->", "random_response", "=", "$", "num", "++", ";", "$", "DB", "->", "update_record", "(", "'feedback_completed'", ",", "$", "compl", ")", ";", "}", "}", "}" ]
If there are any new responses to the anonymous feedback, re-shuffle all responses and assign response number to each of them.
[ "If", "there", "are", "any", "new", "responses", "to", "the", "anonymous", "feedback", "re", "-", "shuffle", "all", "responses", "and", "assign", "response", "number", "to", "each", "of", "them", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/structure.php#L279-L296
214,308
moodle/moodle
mod/feedback/classes/structure.php
mod_feedback_structure.get_completed_courses
public function get_completed_courses() { global $DB; if ($this->get_feedback()->course != SITEID) { return []; } if ($this->allcourses !== null) { return $this->allcourses; } $courseselect = "SELECT fbc.courseid FROM {feedback_completed} fbc WHERE fbc.feedback = :feedbackid"; $ctxselect = context_helper::get_preload_record_columns_sql('ctx'); $sql = 'SELECT c.id, c.shortname, c.fullname, c.idnumber, c.visible, '. $ctxselect. ' FROM {course} c JOIN {context} ctx ON c.id = ctx.instanceid AND ctx.contextlevel = :contextcourse WHERE c.id IN ('. $courseselect.') ORDER BY c.sortorder'; $list = $DB->get_records_sql($sql, ['contextcourse' => CONTEXT_COURSE, 'feedbackid' => $this->get_feedback()->id]); $this->allcourses = array(); foreach ($list as $course) { context_helper::preload_from_record($course); if (!$course->visible && !has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id), $this->userid)) { // Do not return courses that current user can not see. continue; } $label = get_course_display_name_for_list($course); $this->allcourses[$course->id] = $label; } return $this->allcourses; }
php
public function get_completed_courses() { global $DB; if ($this->get_feedback()->course != SITEID) { return []; } if ($this->allcourses !== null) { return $this->allcourses; } $courseselect = "SELECT fbc.courseid FROM {feedback_completed} fbc WHERE fbc.feedback = :feedbackid"; $ctxselect = context_helper::get_preload_record_columns_sql('ctx'); $sql = 'SELECT c.id, c.shortname, c.fullname, c.idnumber, c.visible, '. $ctxselect. ' FROM {course} c JOIN {context} ctx ON c.id = ctx.instanceid AND ctx.contextlevel = :contextcourse WHERE c.id IN ('. $courseselect.') ORDER BY c.sortorder'; $list = $DB->get_records_sql($sql, ['contextcourse' => CONTEXT_COURSE, 'feedbackid' => $this->get_feedback()->id]); $this->allcourses = array(); foreach ($list as $course) { context_helper::preload_from_record($course); if (!$course->visible && !has_capability('moodle/course:viewhiddencourses', context_course::instance($course->id), $this->userid)) { // Do not return courses that current user can not see. continue; } $label = get_course_display_name_for_list($course); $this->allcourses[$course->id] = $label; } return $this->allcourses; }
[ "public", "function", "get_completed_courses", "(", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "this", "->", "get_feedback", "(", ")", "->", "course", "!=", "SITEID", ")", "{", "return", "[", "]", ";", "}", "if", "(", "$", "this", "->", "allcourses", "!==", "null", ")", "{", "return", "$", "this", "->", "allcourses", ";", "}", "$", "courseselect", "=", "\"SELECT fbc.courseid\n FROM {feedback_completed} fbc\n WHERE fbc.feedback = :feedbackid\"", ";", "$", "ctxselect", "=", "context_helper", "::", "get_preload_record_columns_sql", "(", "'ctx'", ")", ";", "$", "sql", "=", "'SELECT c.id, c.shortname, c.fullname, c.idnumber, c.visible, '", ".", "$", "ctxselect", ".", "'\n FROM {course} c\n JOIN {context} ctx ON c.id = ctx.instanceid AND ctx.contextlevel = :contextcourse\n WHERE c.id IN ('", ".", "$", "courseselect", ".", "') ORDER BY c.sortorder'", ";", "$", "list", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "[", "'contextcourse'", "=>", "CONTEXT_COURSE", ",", "'feedbackid'", "=>", "$", "this", "->", "get_feedback", "(", ")", "->", "id", "]", ")", ";", "$", "this", "->", "allcourses", "=", "array", "(", ")", ";", "foreach", "(", "$", "list", "as", "$", "course", ")", "{", "context_helper", "::", "preload_from_record", "(", "$", "course", ")", ";", "if", "(", "!", "$", "course", "->", "visible", "&&", "!", "has_capability", "(", "'moodle/course:viewhiddencourses'", ",", "context_course", "::", "instance", "(", "$", "course", "->", "id", ")", ",", "$", "this", "->", "userid", ")", ")", "{", "// Do not return courses that current user can not see.", "continue", ";", "}", "$", "label", "=", "get_course_display_name_for_list", "(", "$", "course", ")", ";", "$", "this", "->", "allcourses", "[", "$", "course", "->", "id", "]", "=", "$", "label", ";", "}", "return", "$", "this", "->", "allcourses", ";", "}" ]
For the frontpage feedback returns the list of courses with at least one completed feedback @return array id=>name pairs of courses
[ "For", "the", "frontpage", "feedback", "returns", "the", "list", "of", "courses", "with", "at", "least", "one", "completed", "feedback" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/feedback/classes/structure.php#L331-L366
214,309
moodle/moodle
lib/adodb/drivers/adodb-ibase.inc.php
ADODB_ibase._Execute
function _Execute($sql,$inputarr=false) { global $ADODB_COUNTRECS; if ($this->_logsql) { $savecrecs = $ADODB_COUNTRECS; $ADODB_COUNTRECS = true; // force countrecs $ret = ADOConnection::_Execute($sql,$inputarr); $ADODB_COUNTRECS = $savecrecs; } else { $ret = ADOConnection::_Execute($sql,$inputarr); } return $ret; }
php
function _Execute($sql,$inputarr=false) { global $ADODB_COUNTRECS; if ($this->_logsql) { $savecrecs = $ADODB_COUNTRECS; $ADODB_COUNTRECS = true; // force countrecs $ret = ADOConnection::_Execute($sql,$inputarr); $ADODB_COUNTRECS = $savecrecs; } else { $ret = ADOConnection::_Execute($sql,$inputarr); } return $ret; }
[ "function", "_Execute", "(", "$", "sql", ",", "$", "inputarr", "=", "false", ")", "{", "global", "$", "ADODB_COUNTRECS", ";", "if", "(", "$", "this", "->", "_logsql", ")", "{", "$", "savecrecs", "=", "$", "ADODB_COUNTRECS", ";", "$", "ADODB_COUNTRECS", "=", "true", ";", "// force countrecs", "$", "ret", "=", "ADOConnection", "::", "_Execute", "(", "$", "sql", ",", "$", "inputarr", ")", ";", "$", "ADODB_COUNTRECS", "=", "$", "savecrecs", ";", "}", "else", "{", "$", "ret", "=", "ADOConnection", "::", "_Execute", "(", "$", "sql", ",", "$", "inputarr", ")", ";", "}", "return", "$", "ret", ";", "}" ]
it appears that ibase extension cannot support multiple concurrent queryid's
[ "it", "appears", "that", "ibase", "extension", "cannot", "support", "multiple", "concurrent", "queryid", "s" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/drivers/adodb-ibase.inc.php#L177-L190
214,310
moodle/moodle
lib/adodb/drivers/adodb-ibase.inc.php
ADODB_ibase._ConvertFieldType
function _ConvertFieldType(&$fld, $ftype, $flen, $fscale, $fsubtype, $fprecision, $dialect3) { $fscale = abs($fscale); $fld->max_length = $flen; $fld->scale = null; switch($ftype){ case 7: case 8: if ($dialect3) { switch($fsubtype){ case 0: $fld->type = ($ftype == 7 ? 'smallint' : 'integer'); break; case 1: $fld->type = 'numeric'; $fld->max_length = $fprecision; $fld->scale = $fscale; break; case 2: $fld->type = 'decimal'; $fld->max_length = $fprecision; $fld->scale = $fscale; break; } // switch } else { if ($fscale !=0) { $fld->type = 'decimal'; $fld->scale = $fscale; $fld->max_length = ($ftype == 7 ? 4 : 9); } else { $fld->type = ($ftype == 7 ? 'smallint' : 'integer'); } } break; case 16: if ($dialect3) { switch($fsubtype){ case 0: $fld->type = 'decimal'; $fld->max_length = 18; $fld->scale = 0; break; case 1: $fld->type = 'numeric'; $fld->max_length = $fprecision; $fld->scale = $fscale; break; case 2: $fld->type = 'decimal'; $fld->max_length = $fprecision; $fld->scale = $fscale; break; } // switch } break; case 10: $fld->type = 'float'; break; case 14: $fld->type = 'char'; break; case 27: if ($fscale !=0) { $fld->type = 'decimal'; $fld->max_length = 15; $fld->scale = 5; } else { $fld->type = 'double'; } break; case 35: if ($dialect3) { $fld->type = 'timestamp'; } else { $fld->type = 'date'; } break; case 12: $fld->type = 'date'; break; case 13: $fld->type = 'time'; break; case 37: $fld->type = 'varchar'; break; case 40: $fld->type = 'cstring'; break; case 261: $fld->type = 'blob'; $fld->max_length = -1; break; } // switch }
php
function _ConvertFieldType(&$fld, $ftype, $flen, $fscale, $fsubtype, $fprecision, $dialect3) { $fscale = abs($fscale); $fld->max_length = $flen; $fld->scale = null; switch($ftype){ case 7: case 8: if ($dialect3) { switch($fsubtype){ case 0: $fld->type = ($ftype == 7 ? 'smallint' : 'integer'); break; case 1: $fld->type = 'numeric'; $fld->max_length = $fprecision; $fld->scale = $fscale; break; case 2: $fld->type = 'decimal'; $fld->max_length = $fprecision; $fld->scale = $fscale; break; } // switch } else { if ($fscale !=0) { $fld->type = 'decimal'; $fld->scale = $fscale; $fld->max_length = ($ftype == 7 ? 4 : 9); } else { $fld->type = ($ftype == 7 ? 'smallint' : 'integer'); } } break; case 16: if ($dialect3) { switch($fsubtype){ case 0: $fld->type = 'decimal'; $fld->max_length = 18; $fld->scale = 0; break; case 1: $fld->type = 'numeric'; $fld->max_length = $fprecision; $fld->scale = $fscale; break; case 2: $fld->type = 'decimal'; $fld->max_length = $fprecision; $fld->scale = $fscale; break; } // switch } break; case 10: $fld->type = 'float'; break; case 14: $fld->type = 'char'; break; case 27: if ($fscale !=0) { $fld->type = 'decimal'; $fld->max_length = 15; $fld->scale = 5; } else { $fld->type = 'double'; } break; case 35: if ($dialect3) { $fld->type = 'timestamp'; } else { $fld->type = 'date'; } break; case 12: $fld->type = 'date'; break; case 13: $fld->type = 'time'; break; case 37: $fld->type = 'varchar'; break; case 40: $fld->type = 'cstring'; break; case 261: $fld->type = 'blob'; $fld->max_length = -1; break; } // switch }
[ "function", "_ConvertFieldType", "(", "&", "$", "fld", ",", "$", "ftype", ",", "$", "flen", ",", "$", "fscale", ",", "$", "fsubtype", ",", "$", "fprecision", ",", "$", "dialect3", ")", "{", "$", "fscale", "=", "abs", "(", "$", "fscale", ")", ";", "$", "fld", "->", "max_length", "=", "$", "flen", ";", "$", "fld", "->", "scale", "=", "null", ";", "switch", "(", "$", "ftype", ")", "{", "case", "7", ":", "case", "8", ":", "if", "(", "$", "dialect3", ")", "{", "switch", "(", "$", "fsubtype", ")", "{", "case", "0", ":", "$", "fld", "->", "type", "=", "(", "$", "ftype", "==", "7", "?", "'smallint'", ":", "'integer'", ")", ";", "break", ";", "case", "1", ":", "$", "fld", "->", "type", "=", "'numeric'", ";", "$", "fld", "->", "max_length", "=", "$", "fprecision", ";", "$", "fld", "->", "scale", "=", "$", "fscale", ";", "break", ";", "case", "2", ":", "$", "fld", "->", "type", "=", "'decimal'", ";", "$", "fld", "->", "max_length", "=", "$", "fprecision", ";", "$", "fld", "->", "scale", "=", "$", "fscale", ";", "break", ";", "}", "// switch", "}", "else", "{", "if", "(", "$", "fscale", "!=", "0", ")", "{", "$", "fld", "->", "type", "=", "'decimal'", ";", "$", "fld", "->", "scale", "=", "$", "fscale", ";", "$", "fld", "->", "max_length", "=", "(", "$", "ftype", "==", "7", "?", "4", ":", "9", ")", ";", "}", "else", "{", "$", "fld", "->", "type", "=", "(", "$", "ftype", "==", "7", "?", "'smallint'", ":", "'integer'", ")", ";", "}", "}", "break", ";", "case", "16", ":", "if", "(", "$", "dialect3", ")", "{", "switch", "(", "$", "fsubtype", ")", "{", "case", "0", ":", "$", "fld", "->", "type", "=", "'decimal'", ";", "$", "fld", "->", "max_length", "=", "18", ";", "$", "fld", "->", "scale", "=", "0", ";", "break", ";", "case", "1", ":", "$", "fld", "->", "type", "=", "'numeric'", ";", "$", "fld", "->", "max_length", "=", "$", "fprecision", ";", "$", "fld", "->", "scale", "=", "$", "fscale", ";", "break", ";", "case", "2", ":", "$", "fld", "->", "type", "=", "'decimal'", ";", "$", "fld", "->", "max_length", "=", "$", "fprecision", ";", "$", "fld", "->", "scale", "=", "$", "fscale", ";", "break", ";", "}", "// switch", "}", "break", ";", "case", "10", ":", "$", "fld", "->", "type", "=", "'float'", ";", "break", ";", "case", "14", ":", "$", "fld", "->", "type", "=", "'char'", ";", "break", ";", "case", "27", ":", "if", "(", "$", "fscale", "!=", "0", ")", "{", "$", "fld", "->", "type", "=", "'decimal'", ";", "$", "fld", "->", "max_length", "=", "15", ";", "$", "fld", "->", "scale", "=", "5", ";", "}", "else", "{", "$", "fld", "->", "type", "=", "'double'", ";", "}", "break", ";", "case", "35", ":", "if", "(", "$", "dialect3", ")", "{", "$", "fld", "->", "type", "=", "'timestamp'", ";", "}", "else", "{", "$", "fld", "->", "type", "=", "'date'", ";", "}", "break", ";", "case", "12", ":", "$", "fld", "->", "type", "=", "'date'", ";", "break", ";", "case", "13", ":", "$", "fld", "->", "type", "=", "'time'", ";", "break", ";", "case", "37", ":", "$", "fld", "->", "type", "=", "'varchar'", ";", "break", ";", "case", "40", ":", "$", "fld", "->", "type", "=", "'cstring'", ";", "break", ";", "case", "261", ":", "$", "fld", "->", "type", "=", "'blob'", ";", "$", "fld", "->", "max_length", "=", "-", "1", ";", "break", ";", "}", "// switch", "}" ]
OPN STUFF start
[ "OPN", "STUFF", "start" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/drivers/adodb-ibase.inc.php#L412-L506
214,311
moodle/moodle
lib/adodb/drivers/adodb-ibase.inc.php
ADODB_ibase.MetaColumns
function MetaColumns($table, $normalize=true) { global $ADODB_FETCH_MODE; $save = $ADODB_FETCH_MODE; $ADODB_FETCH_MODE = ADODB_FETCH_NUM; $rs = $this->Execute(sprintf($this->metaColumnsSQL,strtoupper($table))); $ADODB_FETCH_MODE = $save; $false = false; if ($rs === false) { return $false; } $retarr = array(); //OPN STUFF start $dialect3 = ($this->dialect==3 ? true : false); //OPN STUFF end while (!$rs->EOF) { //print_r($rs->fields); $fld = new ADOFieldObject(); $fld->name = trim($rs->fields[0]); //OPN STUFF start $this->_ConvertFieldType($fld, $rs->fields[7], $rs->fields[3], $rs->fields[4], $rs->fields[5], $rs->fields[6], $dialect3); if (isset($rs->fields[1]) && $rs->fields[1]) { $fld->not_null = true; } if (isset($rs->fields[2])) { $fld->has_default = true; $d = substr($rs->fields[2],strlen('default ')); switch ($fld->type) { case 'smallint': case 'integer': $fld->default_value = (int) $d; break; case 'char': case 'blob': case 'text': case 'varchar': $fld->default_value = (string) substr($d,1,strlen($d)-2); break; case 'double': case 'float': $fld->default_value = (float) $d; break; default: $fld->default_value = $d; break; } // case 35:$tt = 'TIMESTAMP'; break; } if ((isset($rs->fields[5])) && ($fld->type == 'blob')) { $fld->sub_type = $rs->fields[5]; } else { $fld->sub_type = null; } //OPN STUFF end if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld; else $retarr[strtoupper($fld->name)] = $fld; $rs->MoveNext(); } $rs->Close(); if ( empty($retarr)) return $false; else return $retarr; }
php
function MetaColumns($table, $normalize=true) { global $ADODB_FETCH_MODE; $save = $ADODB_FETCH_MODE; $ADODB_FETCH_MODE = ADODB_FETCH_NUM; $rs = $this->Execute(sprintf($this->metaColumnsSQL,strtoupper($table))); $ADODB_FETCH_MODE = $save; $false = false; if ($rs === false) { return $false; } $retarr = array(); //OPN STUFF start $dialect3 = ($this->dialect==3 ? true : false); //OPN STUFF end while (!$rs->EOF) { //print_r($rs->fields); $fld = new ADOFieldObject(); $fld->name = trim($rs->fields[0]); //OPN STUFF start $this->_ConvertFieldType($fld, $rs->fields[7], $rs->fields[3], $rs->fields[4], $rs->fields[5], $rs->fields[6], $dialect3); if (isset($rs->fields[1]) && $rs->fields[1]) { $fld->not_null = true; } if (isset($rs->fields[2])) { $fld->has_default = true; $d = substr($rs->fields[2],strlen('default ')); switch ($fld->type) { case 'smallint': case 'integer': $fld->default_value = (int) $d; break; case 'char': case 'blob': case 'text': case 'varchar': $fld->default_value = (string) substr($d,1,strlen($d)-2); break; case 'double': case 'float': $fld->default_value = (float) $d; break; default: $fld->default_value = $d; break; } // case 35:$tt = 'TIMESTAMP'; break; } if ((isset($rs->fields[5])) && ($fld->type == 'blob')) { $fld->sub_type = $rs->fields[5]; } else { $fld->sub_type = null; } //OPN STUFF end if ($ADODB_FETCH_MODE == ADODB_FETCH_NUM) $retarr[] = $fld; else $retarr[strtoupper($fld->name)] = $fld; $rs->MoveNext(); } $rs->Close(); if ( empty($retarr)) return $false; else return $retarr; }
[ "function", "MetaColumns", "(", "$", "table", ",", "$", "normalize", "=", "true", ")", "{", "global", "$", "ADODB_FETCH_MODE", ";", "$", "save", "=", "$", "ADODB_FETCH_MODE", ";", "$", "ADODB_FETCH_MODE", "=", "ADODB_FETCH_NUM", ";", "$", "rs", "=", "$", "this", "->", "Execute", "(", "sprintf", "(", "$", "this", "->", "metaColumnsSQL", ",", "strtoupper", "(", "$", "table", ")", ")", ")", ";", "$", "ADODB_FETCH_MODE", "=", "$", "save", ";", "$", "false", "=", "false", ";", "if", "(", "$", "rs", "===", "false", ")", "{", "return", "$", "false", ";", "}", "$", "retarr", "=", "array", "(", ")", ";", "//OPN STUFF start", "$", "dialect3", "=", "(", "$", "this", "->", "dialect", "==", "3", "?", "true", ":", "false", ")", ";", "//OPN STUFF end", "while", "(", "!", "$", "rs", "->", "EOF", ")", "{", "//print_r($rs->fields);", "$", "fld", "=", "new", "ADOFieldObject", "(", ")", ";", "$", "fld", "->", "name", "=", "trim", "(", "$", "rs", "->", "fields", "[", "0", "]", ")", ";", "//OPN STUFF start", "$", "this", "->", "_ConvertFieldType", "(", "$", "fld", ",", "$", "rs", "->", "fields", "[", "7", "]", ",", "$", "rs", "->", "fields", "[", "3", "]", ",", "$", "rs", "->", "fields", "[", "4", "]", ",", "$", "rs", "->", "fields", "[", "5", "]", ",", "$", "rs", "->", "fields", "[", "6", "]", ",", "$", "dialect3", ")", ";", "if", "(", "isset", "(", "$", "rs", "->", "fields", "[", "1", "]", ")", "&&", "$", "rs", "->", "fields", "[", "1", "]", ")", "{", "$", "fld", "->", "not_null", "=", "true", ";", "}", "if", "(", "isset", "(", "$", "rs", "->", "fields", "[", "2", "]", ")", ")", "{", "$", "fld", "->", "has_default", "=", "true", ";", "$", "d", "=", "substr", "(", "$", "rs", "->", "fields", "[", "2", "]", ",", "strlen", "(", "'default '", ")", ")", ";", "switch", "(", "$", "fld", "->", "type", ")", "{", "case", "'smallint'", ":", "case", "'integer'", ":", "$", "fld", "->", "default_value", "=", "(", "int", ")", "$", "d", ";", "break", ";", "case", "'char'", ":", "case", "'blob'", ":", "case", "'text'", ":", "case", "'varchar'", ":", "$", "fld", "->", "default_value", "=", "(", "string", ")", "substr", "(", "$", "d", ",", "1", ",", "strlen", "(", "$", "d", ")", "-", "2", ")", ";", "break", ";", "case", "'double'", ":", "case", "'float'", ":", "$", "fld", "->", "default_value", "=", "(", "float", ")", "$", "d", ";", "break", ";", "default", ":", "$", "fld", "->", "default_value", "=", "$", "d", ";", "break", ";", "}", "//\tcase 35:$tt = 'TIMESTAMP'; break;", "}", "if", "(", "(", "isset", "(", "$", "rs", "->", "fields", "[", "5", "]", ")", ")", "&&", "(", "$", "fld", "->", "type", "==", "'blob'", ")", ")", "{", "$", "fld", "->", "sub_type", "=", "$", "rs", "->", "fields", "[", "5", "]", ";", "}", "else", "{", "$", "fld", "->", "sub_type", "=", "null", ";", "}", "//OPN STUFF end", "if", "(", "$", "ADODB_FETCH_MODE", "==", "ADODB_FETCH_NUM", ")", "$", "retarr", "[", "]", "=", "$", "fld", ";", "else", "$", "retarr", "[", "strtoupper", "(", "$", "fld", "->", "name", ")", "]", "=", "$", "fld", ";", "$", "rs", "->", "MoveNext", "(", ")", ";", "}", "$", "rs", "->", "Close", "(", ")", ";", "if", "(", "empty", "(", "$", "retarr", ")", ")", "return", "$", "false", ";", "else", "return", "$", "retarr", ";", "}" ]
returns array of ADOFieldObjects for current table
[ "returns", "array", "of", "ADOFieldObjects", "for", "current", "table" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/drivers/adodb-ibase.inc.php#L510-L569
214,312
moodle/moodle
lib/adodb/drivers/adodb-ibase.inc.php
ADODB_ibase._BlobDecode_old
function _BlobDecode_old( $blob ) { $blobid = ibase_blob_open($this->_connectionID, $blob ); $realblob = ibase_blob_get( $blobid,$this->maxblobsize); // 2nd param is max size of blob -- Kevin Boillet <kevinboillet@yahoo.fr> while($string = ibase_blob_get($blobid, 8192)){ $realblob .= $string; } ibase_blob_close( $blobid ); return( $realblob ); }
php
function _BlobDecode_old( $blob ) { $blobid = ibase_blob_open($this->_connectionID, $blob ); $realblob = ibase_blob_get( $blobid,$this->maxblobsize); // 2nd param is max size of blob -- Kevin Boillet <kevinboillet@yahoo.fr> while($string = ibase_blob_get($blobid, 8192)){ $realblob .= $string; } ibase_blob_close( $blobid ); return( $realblob ); }
[ "function", "_BlobDecode_old", "(", "$", "blob", ")", "{", "$", "blobid", "=", "ibase_blob_open", "(", "$", "this", "->", "_connectionID", ",", "$", "blob", ")", ";", "$", "realblob", "=", "ibase_blob_get", "(", "$", "blobid", ",", "$", "this", "->", "maxblobsize", ")", ";", "// 2nd param is max size of blob -- Kevin Boillet <kevinboillet@yahoo.fr>", "while", "(", "$", "string", "=", "ibase_blob_get", "(", "$", "blobid", ",", "8192", ")", ")", "{", "$", "realblob", ".=", "$", "string", ";", "}", "ibase_blob_close", "(", "$", "blobid", ")", ";", "return", "(", "$", "realblob", ")", ";", "}" ]
still used to auto-decode all blob's
[ "still", "used", "to", "auto", "-", "decode", "all", "blob", "s" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/drivers/adodb-ibase.inc.php#L590-L600
214,313
moodle/moodle
lib/adodb/drivers/adodb-ibase.inc.php
ADODB_ibase.SQLDate
function SQLDate($fmt, $col=false) { if (!$col) $col = $this->sysDate; $s = ''; $len = strlen($fmt); for ($i=0; $i < $len; $i++) { if ($s) $s .= '||'; $ch = $fmt[$i]; switch($ch) { case 'Y': case 'y': $s .= "extract(year from $col)"; break; case 'M': case 'm': $s .= "extract(month from $col)"; break; case 'Q': case 'q': $s .= "cast(((extract(month from $col)+2) / 3) as integer)"; break; case 'D': case 'd': $s .= "(extract(day from $col))"; break; case 'H': case 'h': $s .= "(extract(hour from $col))"; break; case 'I': case 'i': $s .= "(extract(minute from $col))"; break; case 'S': case 's': $s .= "CAST((extract(second from $col)) AS INTEGER)"; break; default: if ($ch == '\\') { $i++; $ch = substr($fmt,$i,1); } $s .= $this->qstr($ch); break; } } return $s; }
php
function SQLDate($fmt, $col=false) { if (!$col) $col = $this->sysDate; $s = ''; $len = strlen($fmt); for ($i=0; $i < $len; $i++) { if ($s) $s .= '||'; $ch = $fmt[$i]; switch($ch) { case 'Y': case 'y': $s .= "extract(year from $col)"; break; case 'M': case 'm': $s .= "extract(month from $col)"; break; case 'Q': case 'q': $s .= "cast(((extract(month from $col)+2) / 3) as integer)"; break; case 'D': case 'd': $s .= "(extract(day from $col))"; break; case 'H': case 'h': $s .= "(extract(hour from $col))"; break; case 'I': case 'i': $s .= "(extract(minute from $col))"; break; case 'S': case 's': $s .= "CAST((extract(second from $col)) AS INTEGER)"; break; default: if ($ch == '\\') { $i++; $ch = substr($fmt,$i,1); } $s .= $this->qstr($ch); break; } } return $s; }
[ "function", "SQLDate", "(", "$", "fmt", ",", "$", "col", "=", "false", ")", "{", "if", "(", "!", "$", "col", ")", "$", "col", "=", "$", "this", "->", "sysDate", ";", "$", "s", "=", "''", ";", "$", "len", "=", "strlen", "(", "$", "fmt", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "len", ";", "$", "i", "++", ")", "{", "if", "(", "$", "s", ")", "$", "s", ".=", "'||'", ";", "$", "ch", "=", "$", "fmt", "[", "$", "i", "]", ";", "switch", "(", "$", "ch", ")", "{", "case", "'Y'", ":", "case", "'y'", ":", "$", "s", ".=", "\"extract(year from $col)\"", ";", "break", ";", "case", "'M'", ":", "case", "'m'", ":", "$", "s", ".=", "\"extract(month from $col)\"", ";", "break", ";", "case", "'Q'", ":", "case", "'q'", ":", "$", "s", ".=", "\"cast(((extract(month from $col)+2) / 3) as integer)\"", ";", "break", ";", "case", "'D'", ":", "case", "'d'", ":", "$", "s", ".=", "\"(extract(day from $col))\"", ";", "break", ";", "case", "'H'", ":", "case", "'h'", ":", "$", "s", ".=", "\"(extract(hour from $col))\"", ";", "break", ";", "case", "'I'", ":", "case", "'i'", ":", "$", "s", ".=", "\"(extract(minute from $col))\"", ";", "break", ";", "case", "'S'", ":", "case", "'s'", ":", "$", "s", ".=", "\"CAST((extract(second from $col)) AS INTEGER)\"", ";", "break", ";", "default", ":", "if", "(", "$", "ch", "==", "'\\\\'", ")", "{", "$", "i", "++", ";", "$", "ch", "=", "substr", "(", "$", "fmt", ",", "$", "i", ",", "1", ")", ";", "}", "$", "s", ".=", "$", "this", "->", "qstr", "(", "$", "ch", ")", ";", "break", ";", "}", "}", "return", "$", "s", ";", "}" ]
problem - does not zero-fill the day and month yet
[ "problem", "-", "does", "not", "zero", "-", "fill", "the", "day", "and", "month", "yet" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/drivers/adodb-ibase.inc.php#L701-L750
214,314
moodle/moodle
user/profile/field/datetime/define.class.php
profile_define_datetime.define_form_specific
public function define_form_specific($form) { // Get the current calendar in use - see MDL-18375. $calendartype = \core_calendar\type_factory::get_calendar_instance(); // Create variables to store start and end. list($year, $month, $day) = explode('_', date('Y_m_d')); $currentdate = $calendartype->convert_from_gregorian($year, $month, $day); $currentyear = $currentdate['year']; $arryears = $calendartype->get_years(); // Add elements. $form->addElement('select', 'param1', get_string('startyear', 'profilefield_datetime'), $arryears); $form->setType('param1', PARAM_INT); $form->setDefault('param1', $currentyear); $form->addElement('select', 'param2', get_string('endyear', 'profilefield_datetime'), $arryears); $form->setType('param2', PARAM_INT); $form->setDefault('param2', $currentyear); $form->addElement('checkbox', 'param3', get_string('wanttime', 'profilefield_datetime')); $form->setType('param3', PARAM_INT); $form->addElement('hidden', 'startday', '1'); $form->setType('startday', PARAM_INT); $form->addElement('hidden', 'startmonth', '1'); $form->setType('startmonth', PARAM_INT); $form->addElement('hidden', 'startyear', '1'); $form->setType('startyear', PARAM_INT); $form->addElement('hidden', 'endday', '1'); $form->setType('endday', PARAM_INT); $form->addElement('hidden', 'endmonth', '1'); $form->setType('endmonth', PARAM_INT); $form->addElement('hidden', 'endyear', '1'); $form->setType('endyear', PARAM_INT); $form->addElement('hidden', 'defaultdata', '0'); $form->setType('defaultdata', PARAM_INT); }
php
public function define_form_specific($form) { // Get the current calendar in use - see MDL-18375. $calendartype = \core_calendar\type_factory::get_calendar_instance(); // Create variables to store start and end. list($year, $month, $day) = explode('_', date('Y_m_d')); $currentdate = $calendartype->convert_from_gregorian($year, $month, $day); $currentyear = $currentdate['year']; $arryears = $calendartype->get_years(); // Add elements. $form->addElement('select', 'param1', get_string('startyear', 'profilefield_datetime'), $arryears); $form->setType('param1', PARAM_INT); $form->setDefault('param1', $currentyear); $form->addElement('select', 'param2', get_string('endyear', 'profilefield_datetime'), $arryears); $form->setType('param2', PARAM_INT); $form->setDefault('param2', $currentyear); $form->addElement('checkbox', 'param3', get_string('wanttime', 'profilefield_datetime')); $form->setType('param3', PARAM_INT); $form->addElement('hidden', 'startday', '1'); $form->setType('startday', PARAM_INT); $form->addElement('hidden', 'startmonth', '1'); $form->setType('startmonth', PARAM_INT); $form->addElement('hidden', 'startyear', '1'); $form->setType('startyear', PARAM_INT); $form->addElement('hidden', 'endday', '1'); $form->setType('endday', PARAM_INT); $form->addElement('hidden', 'endmonth', '1'); $form->setType('endmonth', PARAM_INT); $form->addElement('hidden', 'endyear', '1'); $form->setType('endyear', PARAM_INT); $form->addElement('hidden', 'defaultdata', '0'); $form->setType('defaultdata', PARAM_INT); }
[ "public", "function", "define_form_specific", "(", "$", "form", ")", "{", "// Get the current calendar in use - see MDL-18375.", "$", "calendartype", "=", "\\", "core_calendar", "\\", "type_factory", "::", "get_calendar_instance", "(", ")", ";", "// Create variables to store start and end.", "list", "(", "$", "year", ",", "$", "month", ",", "$", "day", ")", "=", "explode", "(", "'_'", ",", "date", "(", "'Y_m_d'", ")", ")", ";", "$", "currentdate", "=", "$", "calendartype", "->", "convert_from_gregorian", "(", "$", "year", ",", "$", "month", ",", "$", "day", ")", ";", "$", "currentyear", "=", "$", "currentdate", "[", "'year'", "]", ";", "$", "arryears", "=", "$", "calendartype", "->", "get_years", "(", ")", ";", "// Add elements.", "$", "form", "->", "addElement", "(", "'select'", ",", "'param1'", ",", "get_string", "(", "'startyear'", ",", "'profilefield_datetime'", ")", ",", "$", "arryears", ")", ";", "$", "form", "->", "setType", "(", "'param1'", ",", "PARAM_INT", ")", ";", "$", "form", "->", "setDefault", "(", "'param1'", ",", "$", "currentyear", ")", ";", "$", "form", "->", "addElement", "(", "'select'", ",", "'param2'", ",", "get_string", "(", "'endyear'", ",", "'profilefield_datetime'", ")", ",", "$", "arryears", ")", ";", "$", "form", "->", "setType", "(", "'param2'", ",", "PARAM_INT", ")", ";", "$", "form", "->", "setDefault", "(", "'param2'", ",", "$", "currentyear", ")", ";", "$", "form", "->", "addElement", "(", "'checkbox'", ",", "'param3'", ",", "get_string", "(", "'wanttime'", ",", "'profilefield_datetime'", ")", ")", ";", "$", "form", "->", "setType", "(", "'param3'", ",", "PARAM_INT", ")", ";", "$", "form", "->", "addElement", "(", "'hidden'", ",", "'startday'", ",", "'1'", ")", ";", "$", "form", "->", "setType", "(", "'startday'", ",", "PARAM_INT", ")", ";", "$", "form", "->", "addElement", "(", "'hidden'", ",", "'startmonth'", ",", "'1'", ")", ";", "$", "form", "->", "setType", "(", "'startmonth'", ",", "PARAM_INT", ")", ";", "$", "form", "->", "addElement", "(", "'hidden'", ",", "'startyear'", ",", "'1'", ")", ";", "$", "form", "->", "setType", "(", "'startyear'", ",", "PARAM_INT", ")", ";", "$", "form", "->", "addElement", "(", "'hidden'", ",", "'endday'", ",", "'1'", ")", ";", "$", "form", "->", "setType", "(", "'endday'", ",", "PARAM_INT", ")", ";", "$", "form", "->", "addElement", "(", "'hidden'", ",", "'endmonth'", ",", "'1'", ")", ";", "$", "form", "->", "setType", "(", "'endmonth'", ",", "PARAM_INT", ")", ";", "$", "form", "->", "addElement", "(", "'hidden'", ",", "'endyear'", ",", "'1'", ")", ";", "$", "form", "->", "setType", "(", "'endyear'", ",", "PARAM_INT", ")", ";", "$", "form", "->", "addElement", "(", "'hidden'", ",", "'defaultdata'", ",", "'0'", ")", ";", "$", "form", "->", "setType", "(", "'defaultdata'", ",", "PARAM_INT", ")", ";", "}" ]
Define the setting for a datetime custom field. @param moodleform $form the user form
[ "Define", "the", "setting", "for", "a", "datetime", "custom", "field", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/profile/field/datetime/define.class.php#L38-L75
214,315
moodle/moodle
user/profile/field/datetime/define.class.php
profile_define_datetime.define_validate_specific
public function define_validate_specific($data, $files) { $errors = array(); // Make sure the start year is not greater than the end year. if ($data->param1 > $data->param2) { $errors['param1'] = get_string('startyearafterend', 'profilefield_datetime'); } return $errors; }
php
public function define_validate_specific($data, $files) { $errors = array(); // Make sure the start year is not greater than the end year. if ($data->param1 > $data->param2) { $errors['param1'] = get_string('startyearafterend', 'profilefield_datetime'); } return $errors; }
[ "public", "function", "define_validate_specific", "(", "$", "data", ",", "$", "files", ")", "{", "$", "errors", "=", "array", "(", ")", ";", "// Make sure the start year is not greater than the end year.", "if", "(", "$", "data", "->", "param1", ">", "$", "data", "->", "param2", ")", "{", "$", "errors", "[", "'param1'", "]", "=", "get_string", "(", "'startyearafterend'", ",", "'profilefield_datetime'", ")", ";", "}", "return", "$", "errors", ";", "}" ]
Validate the data from the profile field form. @param stdClass $data from the add/edit profile field form @param array $files @return array associative array of error messages
[ "Validate", "the", "data", "from", "the", "profile", "field", "form", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/profile/field/datetime/define.class.php#L84-L93
214,316
moodle/moodle
user/profile/field/datetime/define.class.php
profile_define_datetime.define_after_data
public function define_after_data(&$mform) { global $DB; // If we are adding a new profile field then the dates have already been set // by setDefault to the correct dates in the used calendar system. We only want // to execute the rest of the code when we have the years in the DB saved in // Gregorian that need converting to the date for this user. $id = required_param('id', PARAM_INT); if ($id === 0) { return; } // Get the field data from the DB. $field = $DB->get_record('user_info_field', array('id' => $id), 'param1, param2', MUST_EXIST); // Get the current calendar in use - see MDL-18375. $calendartype = \core_calendar\type_factory::get_calendar_instance(); // An array to store form values. $values = array(); // The start and end year will be set as a Gregorian year in the DB. We want // convert these to the equivalent year in the current calendar type being used. $startdate = $calendartype->convert_from_gregorian($field->param1, 1, 1); $values['startday'] = $startdate['day']; $values['startmonth'] = $startdate['month']; $values['startyear'] = $startdate['year']; $values['param1'] = $startdate['year']; $stopdate = $calendartype->convert_from_gregorian($field->param2, 1, 1); $values['endday'] = $stopdate['day']; $values['endmonth'] = $stopdate['month']; $values['endyear'] = $stopdate['year']; $values['param2'] = $stopdate['year']; // Set the values. foreach ($values as $key => $value) { $param = $mform->getElement($key); $param->setValue($value); } }
php
public function define_after_data(&$mform) { global $DB; // If we are adding a new profile field then the dates have already been set // by setDefault to the correct dates in the used calendar system. We only want // to execute the rest of the code when we have the years in the DB saved in // Gregorian that need converting to the date for this user. $id = required_param('id', PARAM_INT); if ($id === 0) { return; } // Get the field data from the DB. $field = $DB->get_record('user_info_field', array('id' => $id), 'param1, param2', MUST_EXIST); // Get the current calendar in use - see MDL-18375. $calendartype = \core_calendar\type_factory::get_calendar_instance(); // An array to store form values. $values = array(); // The start and end year will be set as a Gregorian year in the DB. We want // convert these to the equivalent year in the current calendar type being used. $startdate = $calendartype->convert_from_gregorian($field->param1, 1, 1); $values['startday'] = $startdate['day']; $values['startmonth'] = $startdate['month']; $values['startyear'] = $startdate['year']; $values['param1'] = $startdate['year']; $stopdate = $calendartype->convert_from_gregorian($field->param2, 1, 1); $values['endday'] = $stopdate['day']; $values['endmonth'] = $stopdate['month']; $values['endyear'] = $stopdate['year']; $values['param2'] = $stopdate['year']; // Set the values. foreach ($values as $key => $value) { $param = $mform->getElement($key); $param->setValue($value); } }
[ "public", "function", "define_after_data", "(", "&", "$", "mform", ")", "{", "global", "$", "DB", ";", "// If we are adding a new profile field then the dates have already been set", "// by setDefault to the correct dates in the used calendar system. We only want", "// to execute the rest of the code when we have the years in the DB saved in", "// Gregorian that need converting to the date for this user.", "$", "id", "=", "required_param", "(", "'id'", ",", "PARAM_INT", ")", ";", "if", "(", "$", "id", "===", "0", ")", "{", "return", ";", "}", "// Get the field data from the DB.", "$", "field", "=", "$", "DB", "->", "get_record", "(", "'user_info_field'", ",", "array", "(", "'id'", "=>", "$", "id", ")", ",", "'param1, param2'", ",", "MUST_EXIST", ")", ";", "// Get the current calendar in use - see MDL-18375.", "$", "calendartype", "=", "\\", "core_calendar", "\\", "type_factory", "::", "get_calendar_instance", "(", ")", ";", "// An array to store form values.", "$", "values", "=", "array", "(", ")", ";", "// The start and end year will be set as a Gregorian year in the DB. We want", "// convert these to the equivalent year in the current calendar type being used.", "$", "startdate", "=", "$", "calendartype", "->", "convert_from_gregorian", "(", "$", "field", "->", "param1", ",", "1", ",", "1", ")", ";", "$", "values", "[", "'startday'", "]", "=", "$", "startdate", "[", "'day'", "]", ";", "$", "values", "[", "'startmonth'", "]", "=", "$", "startdate", "[", "'month'", "]", ";", "$", "values", "[", "'startyear'", "]", "=", "$", "startdate", "[", "'year'", "]", ";", "$", "values", "[", "'param1'", "]", "=", "$", "startdate", "[", "'year'", "]", ";", "$", "stopdate", "=", "$", "calendartype", "->", "convert_from_gregorian", "(", "$", "field", "->", "param2", ",", "1", ",", "1", ")", ";", "$", "values", "[", "'endday'", "]", "=", "$", "stopdate", "[", "'day'", "]", ";", "$", "values", "[", "'endmonth'", "]", "=", "$", "stopdate", "[", "'month'", "]", ";", "$", "values", "[", "'endyear'", "]", "=", "$", "stopdate", "[", "'year'", "]", ";", "$", "values", "[", "'param2'", "]", "=", "$", "stopdate", "[", "'year'", "]", ";", "// Set the values.", "foreach", "(", "$", "values", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "param", "=", "$", "mform", "->", "getElement", "(", "$", "key", ")", ";", "$", "param", "->", "setValue", "(", "$", "value", ")", ";", "}", "}" ]
Alter form based on submitted or existing data. @param moodleform $mform
[ "Alter", "form", "based", "on", "submitted", "or", "existing", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/profile/field/datetime/define.class.php#L100-L140
214,317
moodle/moodle
user/profile/field/datetime/define.class.php
profile_define_datetime.define_save_preprocess
public function define_save_preprocess($data) { // Get the current calendar in use - see MDL-18375. $calendartype = \core_calendar\type_factory::get_calendar_instance(); // Check if the start year was changed, if it was then convert from the start of that year. if ($data->param1 != $data->startyear) { $startdate = $calendartype->convert_to_gregorian($data->param1, 1, 1); } else { $startdate = $calendartype->convert_to_gregorian($data->param1, $data->startmonth, $data->startday); } // Check if the end year was changed, if it was then convert from the start of that year. if ($data->param2 != $data->endyear) { $stopdate = $calendartype->convert_to_gregorian($data->param2, 1, 1); } else { $stopdate = $calendartype->convert_to_gregorian($data->param2, $data->endmonth, $data->endday); } $data->param1 = $startdate['year']; $data->param2 = $stopdate['year']; if (empty($data->param3)) { $data->param3 = null; } // No valid value in the default data column needed. $data->defaultdata = '0'; return $data; }
php
public function define_save_preprocess($data) { // Get the current calendar in use - see MDL-18375. $calendartype = \core_calendar\type_factory::get_calendar_instance(); // Check if the start year was changed, if it was then convert from the start of that year. if ($data->param1 != $data->startyear) { $startdate = $calendartype->convert_to_gregorian($data->param1, 1, 1); } else { $startdate = $calendartype->convert_to_gregorian($data->param1, $data->startmonth, $data->startday); } // Check if the end year was changed, if it was then convert from the start of that year. if ($data->param2 != $data->endyear) { $stopdate = $calendartype->convert_to_gregorian($data->param2, 1, 1); } else { $stopdate = $calendartype->convert_to_gregorian($data->param2, $data->endmonth, $data->endday); } $data->param1 = $startdate['year']; $data->param2 = $stopdate['year']; if (empty($data->param3)) { $data->param3 = null; } // No valid value in the default data column needed. $data->defaultdata = '0'; return $data; }
[ "public", "function", "define_save_preprocess", "(", "$", "data", ")", "{", "// Get the current calendar in use - see MDL-18375.", "$", "calendartype", "=", "\\", "core_calendar", "\\", "type_factory", "::", "get_calendar_instance", "(", ")", ";", "// Check if the start year was changed, if it was then convert from the start of that year.", "if", "(", "$", "data", "->", "param1", "!=", "$", "data", "->", "startyear", ")", "{", "$", "startdate", "=", "$", "calendartype", "->", "convert_to_gregorian", "(", "$", "data", "->", "param1", ",", "1", ",", "1", ")", ";", "}", "else", "{", "$", "startdate", "=", "$", "calendartype", "->", "convert_to_gregorian", "(", "$", "data", "->", "param1", ",", "$", "data", "->", "startmonth", ",", "$", "data", "->", "startday", ")", ";", "}", "// Check if the end year was changed, if it was then convert from the start of that year.", "if", "(", "$", "data", "->", "param2", "!=", "$", "data", "->", "endyear", ")", "{", "$", "stopdate", "=", "$", "calendartype", "->", "convert_to_gregorian", "(", "$", "data", "->", "param2", ",", "1", ",", "1", ")", ";", "}", "else", "{", "$", "stopdate", "=", "$", "calendartype", "->", "convert_to_gregorian", "(", "$", "data", "->", "param2", ",", "$", "data", "->", "endmonth", ",", "$", "data", "->", "endday", ")", ";", "}", "$", "data", "->", "param1", "=", "$", "startdate", "[", "'year'", "]", ";", "$", "data", "->", "param2", "=", "$", "stopdate", "[", "'year'", "]", ";", "if", "(", "empty", "(", "$", "data", "->", "param3", ")", ")", "{", "$", "data", "->", "param3", "=", "null", ";", "}", "// No valid value in the default data column needed.", "$", "data", "->", "defaultdata", "=", "'0'", ";", "return", "$", "data", ";", "}" ]
Preprocess data from the profile field form before it is saved. @param stdClass $data from the add/edit profile field form @return stdClass processed data object
[ "Preprocess", "data", "from", "the", "profile", "field", "form", "before", "it", "is", "saved", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/profile/field/datetime/define.class.php#L149-L178
214,318
moodle/moodle
lib/htmlpurifier/HTMLPurifier/Zipper.php
HTMLPurifier_Zipper.next
public function next($t) { if ($t !== NULL) array_push($this->front, $t); return empty($this->back) ? NULL : array_pop($this->back); }
php
public function next($t) { if ($t !== NULL) array_push($this->front, $t); return empty($this->back) ? NULL : array_pop($this->back); }
[ "public", "function", "next", "(", "$", "t", ")", "{", "if", "(", "$", "t", "!==", "NULL", ")", "array_push", "(", "$", "this", "->", "front", ",", "$", "t", ")", ";", "return", "empty", "(", "$", "this", "->", "back", ")", "?", "NULL", ":", "array_pop", "(", "$", "this", "->", "back", ")", ";", "}" ]
Move hole to the next element. @param $t Element to fill hole with @return Original contents of new hole.
[ "Move", "hole", "to", "the", "next", "element", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Zipper.php#L61-L64
214,319
moodle/moodle
lib/htmlpurifier/HTMLPurifier/Zipper.php
HTMLPurifier_Zipper.advance
public function advance($t, $n) { for ($i = 0; $i < $n; $i++) { $t = $this->next($t); } return $t; }
php
public function advance($t, $n) { for ($i = 0; $i < $n; $i++) { $t = $this->next($t); } return $t; }
[ "public", "function", "advance", "(", "$", "t", ",", "$", "n", ")", "{", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "n", ";", "$", "i", "++", ")", "{", "$", "t", "=", "$", "this", "->", "next", "(", "$", "t", ")", ";", "}", "return", "$", "t", ";", "}" ]
Iterated hole advancement. @param $t Element to fill hole with @param $i How many forward to advance hole @return Original contents of new hole, i away
[ "Iterated", "hole", "advancement", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Zipper.php#L72-L77
214,320
moodle/moodle
message/output/email/classes/event_observers.php
event_observers.message_viewed
public static function message_viewed(\core\event\message_viewed $event) { global $DB; $userid = $event->userid; $messageid = $event->other['messageid']; $DB->delete_records('message_email_messages', ['useridto' => $userid, 'messageid' => $messageid]); }
php
public static function message_viewed(\core\event\message_viewed $event) { global $DB; $userid = $event->userid; $messageid = $event->other['messageid']; $DB->delete_records('message_email_messages', ['useridto' => $userid, 'messageid' => $messageid]); }
[ "public", "static", "function", "message_viewed", "(", "\\", "core", "\\", "event", "\\", "message_viewed", "$", "event", ")", "{", "global", "$", "DB", ";", "$", "userid", "=", "$", "event", "->", "userid", ";", "$", "messageid", "=", "$", "event", "->", "other", "[", "'messageid'", "]", ";", "$", "DB", "->", "delete_records", "(", "'message_email_messages'", ",", "[", "'useridto'", "=>", "$", "userid", ",", "'messageid'", "=>", "$", "messageid", "]", ")", ";", "}" ]
Message viewed event handler. @param \core\event\message_viewed $event The message viewed event.
[ "Message", "viewed", "event", "handler", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/output/email/classes/event_observers.php#L43-L50
214,321
moodle/moodle
course/format/weeks/backup/moodle2/restore_format_weeks_plugin.class.php
restore_format_weeks_plugin.update_automatic_end_date
protected function update_automatic_end_date($enddate) { global $DB; // At this stage the 'course_format_options' table will already have a value set for this option as it is // part of the course format and the default will have been set. // Get the current course format option. $params = array( 'courseid' => $this->step->get_task()->get_courseid(), 'format' => 'weeks', 'sectionid' => 0, 'name' => 'automaticenddate' ); $cfoid = $DB->get_field('course_format_options', 'id', $params); $update = new stdClass(); $update->id = $cfoid; if (empty($enddate)) { $update->value = 1; $DB->update_record('course_format_options', $update); // Now, let's update the course end date. format_weeks::update_end_date($this->step->get_task()->get_courseid()); } else { $update->value = 0; $DB->update_record('course_format_options', $update); // The end date may have been changed by observers during restore, ensure we set it back to what was in the backup. $DB->set_field('course', 'enddate', $enddate, array('id' => $this->step->get_task()->get_courseid())); } }
php
protected function update_automatic_end_date($enddate) { global $DB; // At this stage the 'course_format_options' table will already have a value set for this option as it is // part of the course format and the default will have been set. // Get the current course format option. $params = array( 'courseid' => $this->step->get_task()->get_courseid(), 'format' => 'weeks', 'sectionid' => 0, 'name' => 'automaticenddate' ); $cfoid = $DB->get_field('course_format_options', 'id', $params); $update = new stdClass(); $update->id = $cfoid; if (empty($enddate)) { $update->value = 1; $DB->update_record('course_format_options', $update); // Now, let's update the course end date. format_weeks::update_end_date($this->step->get_task()->get_courseid()); } else { $update->value = 0; $DB->update_record('course_format_options', $update); // The end date may have been changed by observers during restore, ensure we set it back to what was in the backup. $DB->set_field('course', 'enddate', $enddate, array('id' => $this->step->get_task()->get_courseid())); } }
[ "protected", "function", "update_automatic_end_date", "(", "$", "enddate", ")", "{", "global", "$", "DB", ";", "// At this stage the 'course_format_options' table will already have a value set for this option as it is", "// part of the course format and the default will have been set.", "// Get the current course format option.", "$", "params", "=", "array", "(", "'courseid'", "=>", "$", "this", "->", "step", "->", "get_task", "(", ")", "->", "get_courseid", "(", ")", ",", "'format'", "=>", "'weeks'", ",", "'sectionid'", "=>", "0", ",", "'name'", "=>", "'automaticenddate'", ")", ";", "$", "cfoid", "=", "$", "DB", "->", "get_field", "(", "'course_format_options'", ",", "'id'", ",", "$", "params", ")", ";", "$", "update", "=", "new", "stdClass", "(", ")", ";", "$", "update", "->", "id", "=", "$", "cfoid", ";", "if", "(", "empty", "(", "$", "enddate", ")", ")", "{", "$", "update", "->", "value", "=", "1", ";", "$", "DB", "->", "update_record", "(", "'course_format_options'", ",", "$", "update", ")", ";", "// Now, let's update the course end date.", "format_weeks", "::", "update_end_date", "(", "$", "this", "->", "step", "->", "get_task", "(", ")", "->", "get_courseid", "(", ")", ")", ";", "}", "else", "{", "$", "update", "->", "value", "=", "0", ";", "$", "DB", "->", "update_record", "(", "'course_format_options'", ",", "$", "update", ")", ";", "// The end date may have been changed by observers during restore, ensure we set it back to what was in the backup.", "$", "DB", "->", "set_field", "(", "'course'", ",", "'enddate'", ",", "$", "enddate", ",", "array", "(", "'id'", "=>", "$", "this", "->", "step", "->", "get_task", "(", ")", "->", "get_courseid", "(", ")", ")", ")", ";", "}", "}" ]
Handles setting the automatic end date for a restored course. @param int $enddate The end date in the backup file.
[ "Handles", "setting", "the", "automatic", "end", "date", "for", "a", "restored", "course", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/weeks/backup/moodle2/restore_format_weeks_plugin.class.php#L60-L89
214,322
moodle/moodle
course/format/weeks/backup/moodle2/restore_format_weeks_plugin.class.php
restore_format_weeks_plugin.update_course_sections_visibility
protected function update_course_sections_visibility($numsections) { global $DB; $backupinfo = $this->step->get_task()->get_info(); foreach ($backupinfo->sections as $key => $section) { // For each section from the backup file check if it was restored and if was "orphaned" in the original // course and mark it as hidden. This will leave all activities in it visible and available just as it was // in the original course. // Exception is when we restore with merging and the course already had a section with this section number, // in this case we don't modify the visibility. if ($this->step->get_task()->get_setting_value($key . '_included')) { $sectionnum = (int)$section->title; if ($sectionnum > $numsections && $sectionnum > $this->originalnumsections) { $DB->execute("UPDATE {course_sections} SET visible = 0 WHERE course = ? AND section = ?", [$this->step->get_task()->get_courseid(), $sectionnum]); } } } }
php
protected function update_course_sections_visibility($numsections) { global $DB; $backupinfo = $this->step->get_task()->get_info(); foreach ($backupinfo->sections as $key => $section) { // For each section from the backup file check if it was restored and if was "orphaned" in the original // course and mark it as hidden. This will leave all activities in it visible and available just as it was // in the original course. // Exception is when we restore with merging and the course already had a section with this section number, // in this case we don't modify the visibility. if ($this->step->get_task()->get_setting_value($key . '_included')) { $sectionnum = (int)$section->title; if ($sectionnum > $numsections && $sectionnum > $this->originalnumsections) { $DB->execute("UPDATE {course_sections} SET visible = 0 WHERE course = ? AND section = ?", [$this->step->get_task()->get_courseid(), $sectionnum]); } } } }
[ "protected", "function", "update_course_sections_visibility", "(", "$", "numsections", ")", "{", "global", "$", "DB", ";", "$", "backupinfo", "=", "$", "this", "->", "step", "->", "get_task", "(", ")", "->", "get_info", "(", ")", ";", "foreach", "(", "$", "backupinfo", "->", "sections", "as", "$", "key", "=>", "$", "section", ")", "{", "// For each section from the backup file check if it was restored and if was \"orphaned\" in the original", "// course and mark it as hidden. This will leave all activities in it visible and available just as it was", "// in the original course.", "// Exception is when we restore with merging and the course already had a section with this section number,", "// in this case we don't modify the visibility.", "if", "(", "$", "this", "->", "step", "->", "get_task", "(", ")", "->", "get_setting_value", "(", "$", "key", ".", "'_included'", ")", ")", "{", "$", "sectionnum", "=", "(", "int", ")", "$", "section", "->", "title", ";", "if", "(", "$", "sectionnum", ">", "$", "numsections", "&&", "$", "sectionnum", ">", "$", "this", "->", "originalnumsections", ")", "{", "$", "DB", "->", "execute", "(", "\"UPDATE {course_sections} SET visible = 0 WHERE course = ? AND section = ?\"", ",", "[", "$", "this", "->", "step", "->", "get_task", "(", ")", "->", "get_courseid", "(", ")", ",", "$", "sectionnum", "]", ")", ";", "}", "}", "}", "}" ]
Handles updating the visibility of sections in the restored course. @param int $numsections The number of sections in the restored course.
[ "Handles", "updating", "the", "visibility", "of", "sections", "in", "the", "restored", "course", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/weeks/backup/moodle2/restore_format_weeks_plugin.class.php#L96-L114
214,323
moodle/moodle
course/format/weeks/backup/moodle2/restore_format_weeks_plugin.class.php
restore_format_weeks_plugin.define_course_plugin_structure
public function define_course_plugin_structure() { global $DB; // Since this method is executed before the restore we can do some pre-checks here. // In case of merging backup into existing course find the current number of sections. $target = $this->step->get_task()->get_target(); if (($target == backup::TARGET_CURRENT_ADDING || $target == backup::TARGET_EXISTING_ADDING) && $this->is_pre_33_backup()) { $maxsection = $DB->get_field_sql( 'SELECT max(section) FROM {course_sections} WHERE course = ?', [$this->step->get_task()->get_courseid()]); $this->originalnumsections = (int)$maxsection; } // Dummy path element is needed in order for after_restore_course() to be called. return [new restore_path_element('dummy_course', $this->get_pathfor('/dummycourse'))]; }
php
public function define_course_plugin_structure() { global $DB; // Since this method is executed before the restore we can do some pre-checks here. // In case of merging backup into existing course find the current number of sections. $target = $this->step->get_task()->get_target(); if (($target == backup::TARGET_CURRENT_ADDING || $target == backup::TARGET_EXISTING_ADDING) && $this->is_pre_33_backup()) { $maxsection = $DB->get_field_sql( 'SELECT max(section) FROM {course_sections} WHERE course = ?', [$this->step->get_task()->get_courseid()]); $this->originalnumsections = (int)$maxsection; } // Dummy path element is needed in order for after_restore_course() to be called. return [new restore_path_element('dummy_course', $this->get_pathfor('/dummycourse'))]; }
[ "public", "function", "define_course_plugin_structure", "(", ")", "{", "global", "$", "DB", ";", "// Since this method is executed before the restore we can do some pre-checks here.", "// In case of merging backup into existing course find the current number of sections.", "$", "target", "=", "$", "this", "->", "step", "->", "get_task", "(", ")", "->", "get_target", "(", ")", ";", "if", "(", "(", "$", "target", "==", "backup", "::", "TARGET_CURRENT_ADDING", "||", "$", "target", "==", "backup", "::", "TARGET_EXISTING_ADDING", ")", "&&", "$", "this", "->", "is_pre_33_backup", "(", ")", ")", "{", "$", "maxsection", "=", "$", "DB", "->", "get_field_sql", "(", "'SELECT max(section) FROM {course_sections} WHERE course = ?'", ",", "[", "$", "this", "->", "step", "->", "get_task", "(", ")", "->", "get_courseid", "(", ")", "]", ")", ";", "$", "this", "->", "originalnumsections", "=", "(", "int", ")", "$", "maxsection", ";", "}", "// Dummy path element is needed in order for after_restore_course() to be called.", "return", "[", "new", "restore_path_element", "(", "'dummy_course'", ",", "$", "this", "->", "get_pathfor", "(", "'/dummycourse'", ")", ")", "]", ";", "}" ]
Creates a dummy path element in order to be able to execute code after restore @return restore_path_element[]
[ "Creates", "a", "dummy", "path", "element", "in", "order", "to", "be", "able", "to", "execute", "code", "after", "restore" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/weeks/backup/moodle2/restore_format_weeks_plugin.class.php#L121-L137
214,324
moodle/moodle
backup/util/xml/output/file_xml_output.class.php
file_xml_output.init
protected function init() { if (!file_exists(dirname($this->fullpath))) { throw new xml_output_exception('directory_not_exists', dirname($this->fullpath)); } if (file_exists($this->fullpath)) { throw new xml_output_exception('file_already_exists', $this->fullpath); } if (!is_writable(dirname($this->fullpath))) { throw new xml_output_exception('directory_not_writable', dirname($this->fullpath)); } // Open the OS file for writing if (! $this->fhandle = fopen($this->fullpath, 'w')) { throw new xml_output_exception('error_opening_file'); } }
php
protected function init() { if (!file_exists(dirname($this->fullpath))) { throw new xml_output_exception('directory_not_exists', dirname($this->fullpath)); } if (file_exists($this->fullpath)) { throw new xml_output_exception('file_already_exists', $this->fullpath); } if (!is_writable(dirname($this->fullpath))) { throw new xml_output_exception('directory_not_writable', dirname($this->fullpath)); } // Open the OS file for writing if (! $this->fhandle = fopen($this->fullpath, 'w')) { throw new xml_output_exception('error_opening_file'); } }
[ "protected", "function", "init", "(", ")", "{", "if", "(", "!", "file_exists", "(", "dirname", "(", "$", "this", "->", "fullpath", ")", ")", ")", "{", "throw", "new", "xml_output_exception", "(", "'directory_not_exists'", ",", "dirname", "(", "$", "this", "->", "fullpath", ")", ")", ";", "}", "if", "(", "file_exists", "(", "$", "this", "->", "fullpath", ")", ")", "{", "throw", "new", "xml_output_exception", "(", "'file_already_exists'", ",", "$", "this", "->", "fullpath", ")", ";", "}", "if", "(", "!", "is_writable", "(", "dirname", "(", "$", "this", "->", "fullpath", ")", ")", ")", "{", "throw", "new", "xml_output_exception", "(", "'directory_not_writable'", ",", "dirname", "(", "$", "this", "->", "fullpath", ")", ")", ";", "}", "// Open the OS file for writing", "if", "(", "!", "$", "this", "->", "fhandle", "=", "fopen", "(", "$", "this", "->", "fullpath", ",", "'w'", ")", ")", "{", "throw", "new", "xml_output_exception", "(", "'error_opening_file'", ")", ";", "}", "}" ]
Private API starts here
[ "Private", "API", "starts", "here" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/xml/output/file_xml_output.class.php#L44-L58
214,325
moodle/moodle
backup/util/ui/restore_ui_stage.class.php
restore_ui_independent_stage.get_progress_reporter
public function get_progress_reporter() { if (!$this->progressreporter) { $this->progressreporter = new \core\progress\none(); } return $this->progressreporter; }
php
public function get_progress_reporter() { if (!$this->progressreporter) { $this->progressreporter = new \core\progress\none(); } return $this->progressreporter; }
[ "public", "function", "get_progress_reporter", "(", ")", "{", "if", "(", "!", "$", "this", "->", "progressreporter", ")", "{", "$", "this", "->", "progressreporter", "=", "new", "\\", "core", "\\", "progress", "\\", "none", "(", ")", ";", "}", "return", "$", "this", "->", "progressreporter", ";", "}" ]
Gets the progress reporter object in use for this restore UI stage. IMPORTANT: This progress reporter is used only for UI progress that is outside the restore controller. The restore controller has its own progress reporter which is used for progress during the main restore. Use the restore controller's progress reporter to report progress during a restore operation, not this one. This extra reporter is necessary because on some restore UI screens, there are long-running tasks even though there is no restore controller in use. There is a similar function in restore_ui. but that class is not used on some stages. @return \core\progress\none
[ "Gets", "the", "progress", "reporter", "object", "in", "use", "for", "this", "restore", "UI", "stage", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/restore_ui_stage.class.php#L149-L154
214,326
moodle/moodle
backup/util/ui/restore_ui_stage.class.php
restore_ui_stage_confirm.process
public function process() { $backuptempdir = make_backup_temp_directory(''); if ($this->filename) { $archivepath = $backuptempdir . '/' . $this->filename; if (!file_exists($archivepath)) { throw new restore_ui_exception('invalidrestorefile'); } $outcome = $this->extract_file_to_dir($archivepath); if ($outcome) { fulldelete($archivepath); } } else { $fs = get_file_storage(); $storedfile = $fs->get_file_by_hash($this->pathnamehash); if (!$storedfile || $storedfile->get_contenthash() !== $this->contenthash) { throw new restore_ui_exception('invalidrestorefile'); } $outcome = $this->extract_file_to_dir($storedfile); } return $outcome; }
php
public function process() { $backuptempdir = make_backup_temp_directory(''); if ($this->filename) { $archivepath = $backuptempdir . '/' . $this->filename; if (!file_exists($archivepath)) { throw new restore_ui_exception('invalidrestorefile'); } $outcome = $this->extract_file_to_dir($archivepath); if ($outcome) { fulldelete($archivepath); } } else { $fs = get_file_storage(); $storedfile = $fs->get_file_by_hash($this->pathnamehash); if (!$storedfile || $storedfile->get_contenthash() !== $this->contenthash) { throw new restore_ui_exception('invalidrestorefile'); } $outcome = $this->extract_file_to_dir($storedfile); } return $outcome; }
[ "public", "function", "process", "(", ")", "{", "$", "backuptempdir", "=", "make_backup_temp_directory", "(", "''", ")", ";", "if", "(", "$", "this", "->", "filename", ")", "{", "$", "archivepath", "=", "$", "backuptempdir", ".", "'/'", ".", "$", "this", "->", "filename", ";", "if", "(", "!", "file_exists", "(", "$", "archivepath", ")", ")", "{", "throw", "new", "restore_ui_exception", "(", "'invalidrestorefile'", ")", ";", "}", "$", "outcome", "=", "$", "this", "->", "extract_file_to_dir", "(", "$", "archivepath", ")", ";", "if", "(", "$", "outcome", ")", "{", "fulldelete", "(", "$", "archivepath", ")", ";", "}", "}", "else", "{", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "storedfile", "=", "$", "fs", "->", "get_file_by_hash", "(", "$", "this", "->", "pathnamehash", ")", ";", "if", "(", "!", "$", "storedfile", "||", "$", "storedfile", "->", "get_contenthash", "(", ")", "!==", "$", "this", "->", "contenthash", ")", "{", "throw", "new", "restore_ui_exception", "(", "'invalidrestorefile'", ")", ";", "}", "$", "outcome", "=", "$", "this", "->", "extract_file_to_dir", "(", "$", "storedfile", ")", ";", "}", "return", "$", "outcome", ";", "}" ]
Processes this restore stage @return bool @throws restore_ui_exception
[ "Processes", "this", "restore", "stage" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/restore_ui_stage.class.php#L290-L310
214,327
moodle/moodle
backup/util/ui/restore_ui_stage.class.php
restore_ui_stage_confirm.extract_file_to_dir
protected function extract_file_to_dir($source) { global $USER; $this->filepath = restore_controller::get_tempdir_name($this->contextid, $USER->id); $backuptempdir = make_backup_temp_directory('', false); $fb = get_file_packer('application/vnd.moodle.backup'); $result = $fb->extract_to_pathname($source, $backuptempdir . '/' . $this->filepath . '/', null, $this); // If any progress happened, end it. if ($this->startedprogress) { $this->get_progress_reporter()->end_progress(); } return $result; }
php
protected function extract_file_to_dir($source) { global $USER; $this->filepath = restore_controller::get_tempdir_name($this->contextid, $USER->id); $backuptempdir = make_backup_temp_directory('', false); $fb = get_file_packer('application/vnd.moodle.backup'); $result = $fb->extract_to_pathname($source, $backuptempdir . '/' . $this->filepath . '/', null, $this); // If any progress happened, end it. if ($this->startedprogress) { $this->get_progress_reporter()->end_progress(); } return $result; }
[ "protected", "function", "extract_file_to_dir", "(", "$", "source", ")", "{", "global", "$", "USER", ";", "$", "this", "->", "filepath", "=", "restore_controller", "::", "get_tempdir_name", "(", "$", "this", "->", "contextid", ",", "$", "USER", "->", "id", ")", ";", "$", "backuptempdir", "=", "make_backup_temp_directory", "(", "''", ",", "false", ")", ";", "$", "fb", "=", "get_file_packer", "(", "'application/vnd.moodle.backup'", ")", ";", "$", "result", "=", "$", "fb", "->", "extract_to_pathname", "(", "$", "source", ",", "$", "backuptempdir", ".", "'/'", ".", "$", "this", "->", "filepath", ".", "'/'", ",", "null", ",", "$", "this", ")", ";", "// If any progress happened, end it.", "if", "(", "$", "this", "->", "startedprogress", ")", "{", "$", "this", "->", "get_progress_reporter", "(", ")", "->", "end_progress", "(", ")", ";", "}", "return", "$", "result", ";", "}" ]
Extracts the file. @param string|stored_file $source Archive file to extract @return bool
[ "Extracts", "the", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/restore_ui_stage.class.php#L318-L333
214,328
moodle/moodle
backup/util/ui/restore_ui_stage.class.php
restore_ui_stage_confirm.display
public function display(core_backup_renderer $renderer) { $prevstageurl = new moodle_url('/backup/restorefile.php', array('contextid' => $this->contextid)); $nextstageurl = new moodle_url('/backup/restore.php', array( 'contextid' => $this->contextid, 'filepath' => $this->filepath, 'stage' => restore_ui::STAGE_DESTINATION)); $format = backup_general_helper::detect_backup_format($this->filepath); if ($format === backup::FORMAT_UNKNOWN) { // Unknown format - we can't do anything here. return $renderer->backup_details_unknown($prevstageurl); } else if ($format !== backup::FORMAT_MOODLE) { // Non-standard format to be converted. $details = array('format' => $format, 'type' => backup::TYPE_1COURSE); // todo type to be returned by a converter return $renderer->backup_details_nonstandard($nextstageurl, $details); } else { // Standard MBZ backup, let us get information from it and display. $this->details = backup_general_helper::get_backup_information($this->filepath); return $renderer->backup_details($this->details, $nextstageurl); } }
php
public function display(core_backup_renderer $renderer) { $prevstageurl = new moodle_url('/backup/restorefile.php', array('contextid' => $this->contextid)); $nextstageurl = new moodle_url('/backup/restore.php', array( 'contextid' => $this->contextid, 'filepath' => $this->filepath, 'stage' => restore_ui::STAGE_DESTINATION)); $format = backup_general_helper::detect_backup_format($this->filepath); if ($format === backup::FORMAT_UNKNOWN) { // Unknown format - we can't do anything here. return $renderer->backup_details_unknown($prevstageurl); } else if ($format !== backup::FORMAT_MOODLE) { // Non-standard format to be converted. $details = array('format' => $format, 'type' => backup::TYPE_1COURSE); // todo type to be returned by a converter return $renderer->backup_details_nonstandard($nextstageurl, $details); } else { // Standard MBZ backup, let us get information from it and display. $this->details = backup_general_helper::get_backup_information($this->filepath); return $renderer->backup_details($this->details, $nextstageurl); } }
[ "public", "function", "display", "(", "core_backup_renderer", "$", "renderer", ")", "{", "$", "prevstageurl", "=", "new", "moodle_url", "(", "'/backup/restorefile.php'", ",", "array", "(", "'contextid'", "=>", "$", "this", "->", "contextid", ")", ")", ";", "$", "nextstageurl", "=", "new", "moodle_url", "(", "'/backup/restore.php'", ",", "array", "(", "'contextid'", "=>", "$", "this", "->", "contextid", ",", "'filepath'", "=>", "$", "this", "->", "filepath", ",", "'stage'", "=>", "restore_ui", "::", "STAGE_DESTINATION", ")", ")", ";", "$", "format", "=", "backup_general_helper", "::", "detect_backup_format", "(", "$", "this", "->", "filepath", ")", ";", "if", "(", "$", "format", "===", "backup", "::", "FORMAT_UNKNOWN", ")", "{", "// Unknown format - we can't do anything here.", "return", "$", "renderer", "->", "backup_details_unknown", "(", "$", "prevstageurl", ")", ";", "}", "else", "if", "(", "$", "format", "!==", "backup", "::", "FORMAT_MOODLE", ")", "{", "// Non-standard format to be converted.", "$", "details", "=", "array", "(", "'format'", "=>", "$", "format", ",", "'type'", "=>", "backup", "::", "TYPE_1COURSE", ")", ";", "// todo type to be returned by a converter", "return", "$", "renderer", "->", "backup_details_nonstandard", "(", "$", "nextstageurl", ",", "$", "details", ")", ";", "}", "else", "{", "// Standard MBZ backup, let us get information from it and display.", "$", "this", "->", "details", "=", "backup_general_helper", "::", "get_backup_information", "(", "$", "this", "->", "filepath", ")", ";", "return", "$", "renderer", "->", "backup_details", "(", "$", "this", "->", "details", ",", "$", "nextstageurl", ")", ";", "}", "}" ]
Renders the confirmation stage screen @param core_backup_renderer $renderer renderer instance to use @return string HTML code
[ "Renders", "the", "confirmation", "stage", "screen" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/restore_ui_stage.class.php#L362-L386
214,329
moodle/moodle
backup/util/ui/restore_ui_stage.class.php
restore_ui_stage_destination.process
public function process() { global $DB; $filepathdir = make_backup_temp_directory($this->filepath, false); if (!file_exists($filepathdir) || !is_dir($filepathdir)) { throw new restore_ui_exception('invalidrestorepath'); } if (optional_param('searchcourses', false, PARAM_BOOL)) { return false; } $this->target = optional_param('target', backup::TARGET_NEW_COURSE, PARAM_INT); $targetid = optional_param('targetid', null, PARAM_INT); if (!is_null($this->target) && !is_null($targetid) && confirm_sesskey()) { if ($this->target == backup::TARGET_NEW_COURSE) { list($fullname, $shortname) = restore_dbops::calculate_course_names(0, get_string('restoringcourse', 'backup'), get_string('restoringcourseshortname', 'backup')); $this->courseid = restore_dbops::create_new_course($fullname, $shortname, $targetid); } else { $this->courseid = $targetid; } return ($DB->record_exists('course', array('id' => $this->courseid))); } return false; }
php
public function process() { global $DB; $filepathdir = make_backup_temp_directory($this->filepath, false); if (!file_exists($filepathdir) || !is_dir($filepathdir)) { throw new restore_ui_exception('invalidrestorepath'); } if (optional_param('searchcourses', false, PARAM_BOOL)) { return false; } $this->target = optional_param('target', backup::TARGET_NEW_COURSE, PARAM_INT); $targetid = optional_param('targetid', null, PARAM_INT); if (!is_null($this->target) && !is_null($targetid) && confirm_sesskey()) { if ($this->target == backup::TARGET_NEW_COURSE) { list($fullname, $shortname) = restore_dbops::calculate_course_names(0, get_string('restoringcourse', 'backup'), get_string('restoringcourseshortname', 'backup')); $this->courseid = restore_dbops::create_new_course($fullname, $shortname, $targetid); } else { $this->courseid = $targetid; } return ($DB->record_exists('course', array('id' => $this->courseid))); } return false; }
[ "public", "function", "process", "(", ")", "{", "global", "$", "DB", ";", "$", "filepathdir", "=", "make_backup_temp_directory", "(", "$", "this", "->", "filepath", ",", "false", ")", ";", "if", "(", "!", "file_exists", "(", "$", "filepathdir", ")", "||", "!", "is_dir", "(", "$", "filepathdir", ")", ")", "{", "throw", "new", "restore_ui_exception", "(", "'invalidrestorepath'", ")", ";", "}", "if", "(", "optional_param", "(", "'searchcourses'", ",", "false", ",", "PARAM_BOOL", ")", ")", "{", "return", "false", ";", "}", "$", "this", "->", "target", "=", "optional_param", "(", "'target'", ",", "backup", "::", "TARGET_NEW_COURSE", ",", "PARAM_INT", ")", ";", "$", "targetid", "=", "optional_param", "(", "'targetid'", ",", "null", ",", "PARAM_INT", ")", ";", "if", "(", "!", "is_null", "(", "$", "this", "->", "target", ")", "&&", "!", "is_null", "(", "$", "targetid", ")", "&&", "confirm_sesskey", "(", ")", ")", "{", "if", "(", "$", "this", "->", "target", "==", "backup", "::", "TARGET_NEW_COURSE", ")", "{", "list", "(", "$", "fullname", ",", "$", "shortname", ")", "=", "restore_dbops", "::", "calculate_course_names", "(", "0", ",", "get_string", "(", "'restoringcourse'", ",", "'backup'", ")", ",", "get_string", "(", "'restoringcourseshortname'", ",", "'backup'", ")", ")", ";", "$", "this", "->", "courseid", "=", "restore_dbops", "::", "create_new_course", "(", "$", "fullname", ",", "$", "shortname", ",", "$", "targetid", ")", ";", "}", "else", "{", "$", "this", "->", "courseid", "=", "$", "targetid", ";", "}", "return", "(", "$", "DB", "->", "record_exists", "(", "'course'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "courseid", ")", ")", ")", ";", "}", "return", "false", ";", "}" ]
Processes the destination stage. @return bool @throws coding_exception @throws restore_ui_exception
[ "Processes", "the", "destination", "stage", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/restore_ui_stage.class.php#L476-L497
214,330
moodle/moodle
backup/util/ui/restore_ui_stage.class.php
restore_ui_stage_destination.display
public function display(core_backup_renderer $renderer) { $format = backup_general_helper::detect_backup_format($this->filepath); if ($format === backup::FORMAT_MOODLE) { // Standard Moodle 2 format, let use get the type of the backup. $details = backup_general_helper::get_backup_information($this->filepath); if ($details->type === backup::TYPE_1COURSE) { $wholecourse = true; } else { $wholecourse = false; } } else { // Non-standard format to be converted. We assume it contains the // whole course for now. However, in the future there might be a callback // to the installed converters. $wholecourse = true; } $nextstageurl = new moodle_url('/backup/restore.php', array( 'contextid' => $this->contextid, 'filepath' => $this->filepath, 'stage' => restore_ui::STAGE_SETTINGS)); $context = context::instance_by_id($this->contextid); if ($context->contextlevel == CONTEXT_COURSE and has_capability('moodle/restore:restorecourse', $context)) { $currentcourse = $context->instanceid; } else { $currentcourse = false; } return $renderer->course_selector($nextstageurl, $wholecourse, $this->categorysearch, $this->coursesearch, $currentcourse); }
php
public function display(core_backup_renderer $renderer) { $format = backup_general_helper::detect_backup_format($this->filepath); if ($format === backup::FORMAT_MOODLE) { // Standard Moodle 2 format, let use get the type of the backup. $details = backup_general_helper::get_backup_information($this->filepath); if ($details->type === backup::TYPE_1COURSE) { $wholecourse = true; } else { $wholecourse = false; } } else { // Non-standard format to be converted. We assume it contains the // whole course for now. However, in the future there might be a callback // to the installed converters. $wholecourse = true; } $nextstageurl = new moodle_url('/backup/restore.php', array( 'contextid' => $this->contextid, 'filepath' => $this->filepath, 'stage' => restore_ui::STAGE_SETTINGS)); $context = context::instance_by_id($this->contextid); if ($context->contextlevel == CONTEXT_COURSE and has_capability('moodle/restore:restorecourse', $context)) { $currentcourse = $context->instanceid; } else { $currentcourse = false; } return $renderer->course_selector($nextstageurl, $wholecourse, $this->categorysearch, $this->coursesearch, $currentcourse); }
[ "public", "function", "display", "(", "core_backup_renderer", "$", "renderer", ")", "{", "$", "format", "=", "backup_general_helper", "::", "detect_backup_format", "(", "$", "this", "->", "filepath", ")", ";", "if", "(", "$", "format", "===", "backup", "::", "FORMAT_MOODLE", ")", "{", "// Standard Moodle 2 format, let use get the type of the backup.", "$", "details", "=", "backup_general_helper", "::", "get_backup_information", "(", "$", "this", "->", "filepath", ")", ";", "if", "(", "$", "details", "->", "type", "===", "backup", "::", "TYPE_1COURSE", ")", "{", "$", "wholecourse", "=", "true", ";", "}", "else", "{", "$", "wholecourse", "=", "false", ";", "}", "}", "else", "{", "// Non-standard format to be converted. We assume it contains the", "// whole course for now. However, in the future there might be a callback", "// to the installed converters.", "$", "wholecourse", "=", "true", ";", "}", "$", "nextstageurl", "=", "new", "moodle_url", "(", "'/backup/restore.php'", ",", "array", "(", "'contextid'", "=>", "$", "this", "->", "contextid", ",", "'filepath'", "=>", "$", "this", "->", "filepath", ",", "'stage'", "=>", "restore_ui", "::", "STAGE_SETTINGS", ")", ")", ";", "$", "context", "=", "context", "::", "instance_by_id", "(", "$", "this", "->", "contextid", ")", ";", "if", "(", "$", "context", "->", "contextlevel", "==", "CONTEXT_COURSE", "and", "has_capability", "(", "'moodle/restore:restorecourse'", ",", "$", "context", ")", ")", "{", "$", "currentcourse", "=", "$", "context", "->", "instanceid", ";", "}", "else", "{", "$", "currentcourse", "=", "false", ";", "}", "return", "$", "renderer", "->", "course_selector", "(", "$", "nextstageurl", ",", "$", "wholecourse", ",", "$", "this", "->", "categorysearch", ",", "$", "this", "->", "coursesearch", ",", "$", "currentcourse", ")", ";", "}" ]
Renders the destination stage screen @param core_backup_renderer $renderer renderer instance to use @return string HTML code
[ "Renders", "the", "destination", "stage", "screen" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/restore_ui_stage.class.php#L505-L538
214,331
moodle/moodle
backup/util/ui/restore_ui_stage.class.php
restore_ui_stage_settings.process
public function process(base_moodleform $form = null) { $form = $this->initialise_stage_form(); if ($form->is_cancelled()) { $this->ui->cancel_process(); } $data = $form->get_data(); if ($data && confirm_sesskey()) { $tasks = $this->ui->get_tasks(); $changes = 0; foreach ($tasks as &$task) { // We are only interesting in the backup root task for this stage. if ($task instanceof restore_root_task || $task instanceof restore_course_task) { // Get all settings into a var so we can iterate by reference. $settings = $task->get_settings(); foreach ($settings as &$setting) { $name = $setting->get_ui_name(); if (isset($data->$name) && $data->$name != $setting->get_value()) { $setting->set_value($data->$name); $changes++; } else if (!isset($data->$name) && $setting->get_ui_type() == backup_setting::UI_HTML_CHECKBOX && $setting->get_value()) { $setting->set_value(0); $changes++; } } } } // Return the number of changes the user made. return $changes; } else { return false; } }
php
public function process(base_moodleform $form = null) { $form = $this->initialise_stage_form(); if ($form->is_cancelled()) { $this->ui->cancel_process(); } $data = $form->get_data(); if ($data && confirm_sesskey()) { $tasks = $this->ui->get_tasks(); $changes = 0; foreach ($tasks as &$task) { // We are only interesting in the backup root task for this stage. if ($task instanceof restore_root_task || $task instanceof restore_course_task) { // Get all settings into a var so we can iterate by reference. $settings = $task->get_settings(); foreach ($settings as &$setting) { $name = $setting->get_ui_name(); if (isset($data->$name) && $data->$name != $setting->get_value()) { $setting->set_value($data->$name); $changes++; } else if (!isset($data->$name) && $setting->get_ui_type() == backup_setting::UI_HTML_CHECKBOX && $setting->get_value()) { $setting->set_value(0); $changes++; } } } } // Return the number of changes the user made. return $changes; } else { return false; } }
[ "public", "function", "process", "(", "base_moodleform", "$", "form", "=", "null", ")", "{", "$", "form", "=", "$", "this", "->", "initialise_stage_form", "(", ")", ";", "if", "(", "$", "form", "->", "is_cancelled", "(", ")", ")", "{", "$", "this", "->", "ui", "->", "cancel_process", "(", ")", ";", "}", "$", "data", "=", "$", "form", "->", "get_data", "(", ")", ";", "if", "(", "$", "data", "&&", "confirm_sesskey", "(", ")", ")", "{", "$", "tasks", "=", "$", "this", "->", "ui", "->", "get_tasks", "(", ")", ";", "$", "changes", "=", "0", ";", "foreach", "(", "$", "tasks", "as", "&", "$", "task", ")", "{", "// We are only interesting in the backup root task for this stage.", "if", "(", "$", "task", "instanceof", "restore_root_task", "||", "$", "task", "instanceof", "restore_course_task", ")", "{", "// Get all settings into a var so we can iterate by reference.", "$", "settings", "=", "$", "task", "->", "get_settings", "(", ")", ";", "foreach", "(", "$", "settings", "as", "&", "$", "setting", ")", "{", "$", "name", "=", "$", "setting", "->", "get_ui_name", "(", ")", ";", "if", "(", "isset", "(", "$", "data", "->", "$", "name", ")", "&&", "$", "data", "->", "$", "name", "!=", "$", "setting", "->", "get_value", "(", ")", ")", "{", "$", "setting", "->", "set_value", "(", "$", "data", "->", "$", "name", ")", ";", "$", "changes", "++", ";", "}", "else", "if", "(", "!", "isset", "(", "$", "data", "->", "$", "name", ")", "&&", "$", "setting", "->", "get_ui_type", "(", ")", "==", "backup_setting", "::", "UI_HTML_CHECKBOX", "&&", "$", "setting", "->", "get_value", "(", ")", ")", "{", "$", "setting", "->", "set_value", "(", "0", ")", ";", "$", "changes", "++", ";", "}", "}", "}", "}", "// Return the number of changes the user made.", "return", "$", "changes", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Process the settings stage. @param base_moodleform $form @return bool|int
[ "Process", "the", "settings", "stage", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/restore_ui_stage.class.php#L610-L643
214,332
moodle/moodle
backup/util/ui/restore_ui_stage.class.php
restore_ui_stage_settings.initialise_stage_form
protected function initialise_stage_form() { global $PAGE; if ($this->stageform === null) { $form = new restore_settings_form($this, $PAGE->url); // Store as a variable so we can iterate by reference. $tasks = $this->ui->get_tasks(); $headingprinted = false; // Iterate all tasks by reference. foreach ($tasks as &$task) { // For the initial stage we are only interested in the root settings. if ($task instanceof restore_root_task) { if (!$headingprinted) { $form->add_heading('rootsettings', get_string('restorerootsettings', 'backup')); $headingprinted = true; } $settings = $task->get_settings(); // First add all settings except the filename setting. foreach ($settings as &$setting) { if ($setting->get_name() == 'filename') { continue; } $form->add_setting($setting, $task); } // Then add all dependencies. foreach ($settings as &$setting) { if ($setting->get_name() == 'filename') { continue; } $form->add_dependencies($setting); } } } $this->stageform = $form; } // Return the form. return $this->stageform; }
php
protected function initialise_stage_form() { global $PAGE; if ($this->stageform === null) { $form = new restore_settings_form($this, $PAGE->url); // Store as a variable so we can iterate by reference. $tasks = $this->ui->get_tasks(); $headingprinted = false; // Iterate all tasks by reference. foreach ($tasks as &$task) { // For the initial stage we are only interested in the root settings. if ($task instanceof restore_root_task) { if (!$headingprinted) { $form->add_heading('rootsettings', get_string('restorerootsettings', 'backup')); $headingprinted = true; } $settings = $task->get_settings(); // First add all settings except the filename setting. foreach ($settings as &$setting) { if ($setting->get_name() == 'filename') { continue; } $form->add_setting($setting, $task); } // Then add all dependencies. foreach ($settings as &$setting) { if ($setting->get_name() == 'filename') { continue; } $form->add_dependencies($setting); } } } $this->stageform = $form; } // Return the form. return $this->stageform; }
[ "protected", "function", "initialise_stage_form", "(", ")", "{", "global", "$", "PAGE", ";", "if", "(", "$", "this", "->", "stageform", "===", "null", ")", "{", "$", "form", "=", "new", "restore_settings_form", "(", "$", "this", ",", "$", "PAGE", "->", "url", ")", ";", "// Store as a variable so we can iterate by reference.", "$", "tasks", "=", "$", "this", "->", "ui", "->", "get_tasks", "(", ")", ";", "$", "headingprinted", "=", "false", ";", "// Iterate all tasks by reference.", "foreach", "(", "$", "tasks", "as", "&", "$", "task", ")", "{", "// For the initial stage we are only interested in the root settings.", "if", "(", "$", "task", "instanceof", "restore_root_task", ")", "{", "if", "(", "!", "$", "headingprinted", ")", "{", "$", "form", "->", "add_heading", "(", "'rootsettings'", ",", "get_string", "(", "'restorerootsettings'", ",", "'backup'", ")", ")", ";", "$", "headingprinted", "=", "true", ";", "}", "$", "settings", "=", "$", "task", "->", "get_settings", "(", ")", ";", "// First add all settings except the filename setting.", "foreach", "(", "$", "settings", "as", "&", "$", "setting", ")", "{", "if", "(", "$", "setting", "->", "get_name", "(", ")", "==", "'filename'", ")", "{", "continue", ";", "}", "$", "form", "->", "add_setting", "(", "$", "setting", ",", "$", "task", ")", ";", "}", "// Then add all dependencies.", "foreach", "(", "$", "settings", "as", "&", "$", "setting", ")", "{", "if", "(", "$", "setting", "->", "get_name", "(", ")", "==", "'filename'", ")", "{", "continue", ";", "}", "$", "form", "->", "add_dependencies", "(", "$", "setting", ")", ";", "}", "}", "}", "$", "this", "->", "stageform", "=", "$", "form", ";", "}", "// Return the form.", "return", "$", "this", "->", "stageform", ";", "}" ]
Initialise the stage form. @return backup_moodleform|base_moodleform|restore_settings_form @throws coding_exception
[ "Initialise", "the", "stage", "form", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/restore_ui_stage.class.php#L651-L687
214,333
moodle/moodle
backup/util/ui/restore_ui_stage.class.php
restore_ui_stage_review.process
public function process(base_moodleform $form = null) { $form = $this->initialise_stage_form(); // Check it hasn't been cancelled. if ($form->is_cancelled()) { $this->ui->cancel_process(); } $data = $form->get_data(); if ($data && confirm_sesskey()) { return 0; } else { return false; } }
php
public function process(base_moodleform $form = null) { $form = $this->initialise_stage_form(); // Check it hasn't been cancelled. if ($form->is_cancelled()) { $this->ui->cancel_process(); } $data = $form->get_data(); if ($data && confirm_sesskey()) { return 0; } else { return false; } }
[ "public", "function", "process", "(", "base_moodleform", "$", "form", "=", "null", ")", "{", "$", "form", "=", "$", "this", "->", "initialise_stage_form", "(", ")", ";", "// Check it hasn't been cancelled.", "if", "(", "$", "form", "->", "is_cancelled", "(", ")", ")", "{", "$", "this", "->", "ui", "->", "cancel_process", "(", ")", ";", "}", "$", "data", "=", "$", "form", "->", "get_data", "(", ")", ";", "if", "(", "$", "data", "&&", "confirm_sesskey", "(", ")", ")", "{", "return", "0", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Processes the confirmation stage @param base_moodleform $form @return int The number of changes the user made
[ "Processes", "the", "confirmation", "stage" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/restore_ui_stage.class.php#L870-L883
214,334
moodle/moodle
backup/util/ui/restore_ui_stage.class.php
restore_ui_stage_process.process
public function process(base_moodleform $form = null) { if (optional_param('cancel', false, PARAM_BOOL)) { redirect(new moodle_url('/course/view.php', array('id' => $this->get_ui()->get_controller()->get_courseid()))); } // First decide whether a substage is needed. $rc = $this->ui->get_controller(); if ($rc->get_status() == backup::STATUS_SETTING_UI) { $rc->finish_ui(); } if ($rc->get_status() == backup::STATUS_NEED_PRECHECK) { if (!$rc->precheck_executed()) { $rc->execute_precheck(true); } $results = $rc->get_precheck_results(); if (!empty($results)) { $this->substage = self::SUBSTAGE_PRECHECKS; } } $substage = optional_param('substage', null, PARAM_INT); if (empty($this->substage) && !empty($substage)) { $this->substage = $substage; // Now check whether that substage has already been submit. if ($this->substage == self::SUBSTAGE_PRECHECKS && optional_param('sesskey', null, PARAM_RAW) == sesskey()) { $info = $rc->get_info(); if (!empty($info->role_mappings->mappings)) { foreach ($info->role_mappings->mappings as $key => &$mapping) { $mapping->targetroleid = optional_param('mapping'.$key, $mapping->targetroleid, PARAM_INT); } $info->role_mappings->modified = true; } // We've processed the substage now setting it back to none so we // can move to the next stage. $this->substage = self::SUBSTAGE_NONE; } } return empty($this->substage); }
php
public function process(base_moodleform $form = null) { if (optional_param('cancel', false, PARAM_BOOL)) { redirect(new moodle_url('/course/view.php', array('id' => $this->get_ui()->get_controller()->get_courseid()))); } // First decide whether a substage is needed. $rc = $this->ui->get_controller(); if ($rc->get_status() == backup::STATUS_SETTING_UI) { $rc->finish_ui(); } if ($rc->get_status() == backup::STATUS_NEED_PRECHECK) { if (!$rc->precheck_executed()) { $rc->execute_precheck(true); } $results = $rc->get_precheck_results(); if (!empty($results)) { $this->substage = self::SUBSTAGE_PRECHECKS; } } $substage = optional_param('substage', null, PARAM_INT); if (empty($this->substage) && !empty($substage)) { $this->substage = $substage; // Now check whether that substage has already been submit. if ($this->substage == self::SUBSTAGE_PRECHECKS && optional_param('sesskey', null, PARAM_RAW) == sesskey()) { $info = $rc->get_info(); if (!empty($info->role_mappings->mappings)) { foreach ($info->role_mappings->mappings as $key => &$mapping) { $mapping->targetroleid = optional_param('mapping'.$key, $mapping->targetroleid, PARAM_INT); } $info->role_mappings->modified = true; } // We've processed the substage now setting it back to none so we // can move to the next stage. $this->substage = self::SUBSTAGE_NONE; } } return empty($this->substage); }
[ "public", "function", "process", "(", "base_moodleform", "$", "form", "=", "null", ")", "{", "if", "(", "optional_param", "(", "'cancel'", ",", "false", ",", "PARAM_BOOL", ")", ")", "{", "redirect", "(", "new", "moodle_url", "(", "'/course/view.php'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "get_ui", "(", ")", "->", "get_controller", "(", ")", "->", "get_courseid", "(", ")", ")", ")", ")", ";", "}", "// First decide whether a substage is needed.", "$", "rc", "=", "$", "this", "->", "ui", "->", "get_controller", "(", ")", ";", "if", "(", "$", "rc", "->", "get_status", "(", ")", "==", "backup", "::", "STATUS_SETTING_UI", ")", "{", "$", "rc", "->", "finish_ui", "(", ")", ";", "}", "if", "(", "$", "rc", "->", "get_status", "(", ")", "==", "backup", "::", "STATUS_NEED_PRECHECK", ")", "{", "if", "(", "!", "$", "rc", "->", "precheck_executed", "(", ")", ")", "{", "$", "rc", "->", "execute_precheck", "(", "true", ")", ";", "}", "$", "results", "=", "$", "rc", "->", "get_precheck_results", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "results", ")", ")", "{", "$", "this", "->", "substage", "=", "self", "::", "SUBSTAGE_PRECHECKS", ";", "}", "}", "$", "substage", "=", "optional_param", "(", "'substage'", ",", "null", ",", "PARAM_INT", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "substage", ")", "&&", "!", "empty", "(", "$", "substage", ")", ")", "{", "$", "this", "->", "substage", "=", "$", "substage", ";", "// Now check whether that substage has already been submit.", "if", "(", "$", "this", "->", "substage", "==", "self", "::", "SUBSTAGE_PRECHECKS", "&&", "optional_param", "(", "'sesskey'", ",", "null", ",", "PARAM_RAW", ")", "==", "sesskey", "(", ")", ")", "{", "$", "info", "=", "$", "rc", "->", "get_info", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "info", "->", "role_mappings", "->", "mappings", ")", ")", "{", "foreach", "(", "$", "info", "->", "role_mappings", "->", "mappings", "as", "$", "key", "=>", "&", "$", "mapping", ")", "{", "$", "mapping", "->", "targetroleid", "=", "optional_param", "(", "'mapping'", ".", "$", "key", ",", "$", "mapping", "->", "targetroleid", ",", "PARAM_INT", ")", ";", "}", "$", "info", "->", "role_mappings", "->", "modified", "=", "true", ";", "}", "// We've processed the substage now setting it back to none so we", "// can move to the next stage.", "$", "this", "->", "substage", "=", "self", "::", "SUBSTAGE_NONE", ";", "}", "}", "return", "empty", "(", "$", "this", "->", "substage", ")", ";", "}" ]
Processes the final stage. In this case it checks to see if there is a sub stage that we need to display before execution, if there is we gear up to display the subpage, otherwise we return true which will lead to execution of the restore and the loading of the completed stage. @param base_moodleform $form
[ "Processes", "the", "final", "stage", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/restore_ui_stage.class.php#L980-L1019
214,335
moodle/moodle
backup/util/ui/restore_ui_stage.class.php
restore_ui_stage_process.display
public function display(core_backup_renderer $renderer) { global $PAGE; $html = ''; $haserrors = false; $url = new moodle_url($PAGE->url, array( 'restore' => $this->get_uniqueid(), 'stage' => restore_ui::STAGE_PROCESS, 'substage' => $this->substage, 'sesskey' => sesskey())); $html .= html_writer::start_tag('form', array( 'action' => $url->out_omit_querystring(), 'class' => 'backup-restore', 'enctype' => 'application/x-www-form-urlencoded', // Enforce compatibility with our max_input_vars hack. 'method' => 'post')); foreach ($url->params() as $name => $value) { $html .= html_writer::empty_tag('input', array( 'type' => 'hidden', 'name' => $name, 'value' => $value)); } switch ($this->substage) { case self::SUBSTAGE_PRECHECKS : $results = $this->ui->get_controller()->get_precheck_results(); $info = $this->ui->get_controller()->get_info(); $haserrors = (!empty($results['errors'])); $html .= $renderer->precheck_notices($results); if (!empty($info->role_mappings->mappings)) { $context = context_course::instance($this->ui->get_controller()->get_courseid()); $assignableroles = get_assignable_roles($context, ROLENAME_ALIAS, false); // Get current role mappings. $currentroles = role_fix_names(get_all_roles(), $context); // Get backup role mappings. $rolemappings = $info->role_mappings->mappings; array_map(function($rolemapping) use ($currentroles) { foreach ($currentroles as $role) { // Find matching archetype to determine the backup's shortname for label display. if ($rolemapping->archetype == $role->archetype) { $rolemapping->name = $rolemapping->shortname; break; } } if ($rolemapping->name == null) { $rolemapping->name = get_string('undefinedrolemapping', 'backup', $rolemapping->archetype); } }, $rolemappings); $html .= $renderer->role_mappings($rolemappings, $assignableroles); } break; default: throw new restore_ui_exception('backup_ui_must_execute_first'); } $html .= $renderer->substage_buttons($haserrors); $html .= html_writer::end_tag('form'); return $html; }
php
public function display(core_backup_renderer $renderer) { global $PAGE; $html = ''; $haserrors = false; $url = new moodle_url($PAGE->url, array( 'restore' => $this->get_uniqueid(), 'stage' => restore_ui::STAGE_PROCESS, 'substage' => $this->substage, 'sesskey' => sesskey())); $html .= html_writer::start_tag('form', array( 'action' => $url->out_omit_querystring(), 'class' => 'backup-restore', 'enctype' => 'application/x-www-form-urlencoded', // Enforce compatibility with our max_input_vars hack. 'method' => 'post')); foreach ($url->params() as $name => $value) { $html .= html_writer::empty_tag('input', array( 'type' => 'hidden', 'name' => $name, 'value' => $value)); } switch ($this->substage) { case self::SUBSTAGE_PRECHECKS : $results = $this->ui->get_controller()->get_precheck_results(); $info = $this->ui->get_controller()->get_info(); $haserrors = (!empty($results['errors'])); $html .= $renderer->precheck_notices($results); if (!empty($info->role_mappings->mappings)) { $context = context_course::instance($this->ui->get_controller()->get_courseid()); $assignableroles = get_assignable_roles($context, ROLENAME_ALIAS, false); // Get current role mappings. $currentroles = role_fix_names(get_all_roles(), $context); // Get backup role mappings. $rolemappings = $info->role_mappings->mappings; array_map(function($rolemapping) use ($currentroles) { foreach ($currentroles as $role) { // Find matching archetype to determine the backup's shortname for label display. if ($rolemapping->archetype == $role->archetype) { $rolemapping->name = $rolemapping->shortname; break; } } if ($rolemapping->name == null) { $rolemapping->name = get_string('undefinedrolemapping', 'backup', $rolemapping->archetype); } }, $rolemappings); $html .= $renderer->role_mappings($rolemappings, $assignableroles); } break; default: throw new restore_ui_exception('backup_ui_must_execute_first'); } $html .= $renderer->substage_buttons($haserrors); $html .= html_writer::end_tag('form'); return $html; }
[ "public", "function", "display", "(", "core_backup_renderer", "$", "renderer", ")", "{", "global", "$", "PAGE", ";", "$", "html", "=", "''", ";", "$", "haserrors", "=", "false", ";", "$", "url", "=", "new", "moodle_url", "(", "$", "PAGE", "->", "url", ",", "array", "(", "'restore'", "=>", "$", "this", "->", "get_uniqueid", "(", ")", ",", "'stage'", "=>", "restore_ui", "::", "STAGE_PROCESS", ",", "'substage'", "=>", "$", "this", "->", "substage", ",", "'sesskey'", "=>", "sesskey", "(", ")", ")", ")", ";", "$", "html", ".=", "html_writer", "::", "start_tag", "(", "'form'", ",", "array", "(", "'action'", "=>", "$", "url", "->", "out_omit_querystring", "(", ")", ",", "'class'", "=>", "'backup-restore'", ",", "'enctype'", "=>", "'application/x-www-form-urlencoded'", ",", "// Enforce compatibility with our max_input_vars hack.", "'method'", "=>", "'post'", ")", ")", ";", "foreach", "(", "$", "url", "->", "params", "(", ")", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "html", ".=", "html_writer", "::", "empty_tag", "(", "'input'", ",", "array", "(", "'type'", "=>", "'hidden'", ",", "'name'", "=>", "$", "name", ",", "'value'", "=>", "$", "value", ")", ")", ";", "}", "switch", "(", "$", "this", "->", "substage", ")", "{", "case", "self", "::", "SUBSTAGE_PRECHECKS", ":", "$", "results", "=", "$", "this", "->", "ui", "->", "get_controller", "(", ")", "->", "get_precheck_results", "(", ")", ";", "$", "info", "=", "$", "this", "->", "ui", "->", "get_controller", "(", ")", "->", "get_info", "(", ")", ";", "$", "haserrors", "=", "(", "!", "empty", "(", "$", "results", "[", "'errors'", "]", ")", ")", ";", "$", "html", ".=", "$", "renderer", "->", "precheck_notices", "(", "$", "results", ")", ";", "if", "(", "!", "empty", "(", "$", "info", "->", "role_mappings", "->", "mappings", ")", ")", "{", "$", "context", "=", "context_course", "::", "instance", "(", "$", "this", "->", "ui", "->", "get_controller", "(", ")", "->", "get_courseid", "(", ")", ")", ";", "$", "assignableroles", "=", "get_assignable_roles", "(", "$", "context", ",", "ROLENAME_ALIAS", ",", "false", ")", ";", "// Get current role mappings.", "$", "currentroles", "=", "role_fix_names", "(", "get_all_roles", "(", ")", ",", "$", "context", ")", ";", "// Get backup role mappings.", "$", "rolemappings", "=", "$", "info", "->", "role_mappings", "->", "mappings", ";", "array_map", "(", "function", "(", "$", "rolemapping", ")", "use", "(", "$", "currentroles", ")", "{", "foreach", "(", "$", "currentroles", "as", "$", "role", ")", "{", "// Find matching archetype to determine the backup's shortname for label display.", "if", "(", "$", "rolemapping", "->", "archetype", "==", "$", "role", "->", "archetype", ")", "{", "$", "rolemapping", "->", "name", "=", "$", "rolemapping", "->", "shortname", ";", "break", ";", "}", "}", "if", "(", "$", "rolemapping", "->", "name", "==", "null", ")", "{", "$", "rolemapping", "->", "name", "=", "get_string", "(", "'undefinedrolemapping'", ",", "'backup'", ",", "$", "rolemapping", "->", "archetype", ")", ";", "}", "}", ",", "$", "rolemappings", ")", ";", "$", "html", ".=", "$", "renderer", "->", "role_mappings", "(", "$", "rolemappings", ",", "$", "assignableroles", ")", ";", "}", "break", ";", "default", ":", "throw", "new", "restore_ui_exception", "(", "'backup_ui_must_execute_first'", ")", ";", "}", "$", "html", ".=", "$", "renderer", "->", "substage_buttons", "(", "$", "haserrors", ")", ";", "$", "html", ".=", "html_writer", "::", "end_tag", "(", "'form'", ")", ";", "return", "$", "html", ";", "}" ]
Renders the process stage screen @throws restore_ui_exception @param core_backup_renderer $renderer renderer instance to use @return string HTML code
[ "Renders", "the", "process", "stage", "screen" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/restore_ui_stage.class.php#L1034-L1093
214,336
moodle/moodle
lib/classes/update/checker.php
checker.fetch
public function fetch() { $response = $this->get_response(); $this->validate_response($response); $this->store_response($response); // We need to reset plugin manager's caches - the currently existing // singleton is not aware of eventually available updates we just fetched. \core_plugin_manager::reset_caches(); }
php
public function fetch() { $response = $this->get_response(); $this->validate_response($response); $this->store_response($response); // We need to reset plugin manager's caches - the currently existing // singleton is not aware of eventually available updates we just fetched. \core_plugin_manager::reset_caches(); }
[ "public", "function", "fetch", "(", ")", "{", "$", "response", "=", "$", "this", "->", "get_response", "(", ")", ";", "$", "this", "->", "validate_response", "(", "$", "response", ")", ";", "$", "this", "->", "store_response", "(", "$", "response", ")", ";", "// We need to reset plugin manager's caches - the currently existing", "// singleton is not aware of eventually available updates we just fetched.", "\\", "core_plugin_manager", "::", "reset_caches", "(", ")", ";", "}" ]
Fetches the available update status from the remote site @throws checker_exception
[ "Fetches", "the", "available", "update", "status", "from", "the", "remote", "site" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/checker.php#L122-L131
214,337
moodle/moodle
lib/classes/update/checker.php
checker.get_update_info
public function get_update_info($component, array $options = array()) { if (!isset($options['minmaturity'])) { $options['minmaturity'] = 0; } if (!isset($options['notifybuilds'])) { $options['notifybuilds'] = false; } if ($component === 'core') { $this->load_current_environment(); } $this->restore_response(); if (empty($this->recentresponse['updates'][$component])) { return null; } $updates = array(); foreach ($this->recentresponse['updates'][$component] as $info) { $update = new info($component, $info); if (isset($update->maturity) and ($update->maturity < $options['minmaturity'])) { continue; } if ($component === 'core') { if ($update->version <= $this->currentversion) { continue; } if (empty($options['notifybuilds']) and $this->is_same_release($update->release)) { continue; } } $updates[] = $update; } if (empty($updates)) { return null; } return $updates; }
php
public function get_update_info($component, array $options = array()) { if (!isset($options['minmaturity'])) { $options['minmaturity'] = 0; } if (!isset($options['notifybuilds'])) { $options['notifybuilds'] = false; } if ($component === 'core') { $this->load_current_environment(); } $this->restore_response(); if (empty($this->recentresponse['updates'][$component])) { return null; } $updates = array(); foreach ($this->recentresponse['updates'][$component] as $info) { $update = new info($component, $info); if (isset($update->maturity) and ($update->maturity < $options['minmaturity'])) { continue; } if ($component === 'core') { if ($update->version <= $this->currentversion) { continue; } if (empty($options['notifybuilds']) and $this->is_same_release($update->release)) { continue; } } $updates[] = $update; } if (empty($updates)) { return null; } return $updates; }
[ "public", "function", "get_update_info", "(", "$", "component", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "options", "[", "'minmaturity'", "]", ")", ")", "{", "$", "options", "[", "'minmaturity'", "]", "=", "0", ";", "}", "if", "(", "!", "isset", "(", "$", "options", "[", "'notifybuilds'", "]", ")", ")", "{", "$", "options", "[", "'notifybuilds'", "]", "=", "false", ";", "}", "if", "(", "$", "component", "===", "'core'", ")", "{", "$", "this", "->", "load_current_environment", "(", ")", ";", "}", "$", "this", "->", "restore_response", "(", ")", ";", "if", "(", "empty", "(", "$", "this", "->", "recentresponse", "[", "'updates'", "]", "[", "$", "component", "]", ")", ")", "{", "return", "null", ";", "}", "$", "updates", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "recentresponse", "[", "'updates'", "]", "[", "$", "component", "]", "as", "$", "info", ")", "{", "$", "update", "=", "new", "info", "(", "$", "component", ",", "$", "info", ")", ";", "if", "(", "isset", "(", "$", "update", "->", "maturity", ")", "and", "(", "$", "update", "->", "maturity", "<", "$", "options", "[", "'minmaturity'", "]", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "component", "===", "'core'", ")", "{", "if", "(", "$", "update", "->", "version", "<=", "$", "this", "->", "currentversion", ")", "{", "continue", ";", "}", "if", "(", "empty", "(", "$", "options", "[", "'notifybuilds'", "]", ")", "and", "$", "this", "->", "is_same_release", "(", "$", "update", "->", "release", ")", ")", "{", "continue", ";", "}", "}", "$", "updates", "[", "]", "=", "$", "update", ";", "}", "if", "(", "empty", "(", "$", "updates", ")", ")", "{", "return", "null", ";", "}", "return", "$", "updates", ";", "}" ]
Returns the available update information for the given component This method returns null if the most recent response does not contain any information about it. The returned structure is an array of available updates for the given component. Each update info is an object with at least one property called 'version'. Other possible properties are 'release', 'maturity', 'url' and 'downloadurl'. For the 'core' component, the method returns real updates only (those with higher version). For all other components, the list of all known remote updates is returned and the caller (usually the {@link core_plugin_manager}) is supposed to make the actual comparison of versions. @param string $component frankenstyle @param array $options with supported keys 'minmaturity' and/or 'notifybuilds' @return null|array null or array of \core\update\info objects
[ "Returns", "the", "available", "update", "information", "for", "the", "given", "component" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/checker.php#L149-L191
214,338
moodle/moodle
lib/classes/update/checker.php
checker.cron
public function cron() { global $CFG; if (!$this->enabled() or !$this->cron_autocheck_enabled()) { $this->cron_mtrace('Automatic check for available updates not enabled, skipping.'); return; } $now = $this->cron_current_timestamp(); if ($this->cron_has_fresh_fetch($now)) { $this->cron_mtrace('Recently fetched info about available updates is still fresh enough, skipping.'); return; } if ($this->cron_has_outdated_fetch($now)) { $this->cron_mtrace('Outdated or missing info about available updates, forced fetching ... ', ''); $this->cron_execute(); return; } $offset = $this->cron_execution_offset(); $start = mktime(1, 0, 0, date('n', $now), date('j', $now), date('Y', $now)); // 01:00 AM today local time if ($now > $start + $offset) { $this->cron_mtrace('Regular daily check for available updates ... ', ''); $this->cron_execute(); return; } }
php
public function cron() { global $CFG; if (!$this->enabled() or !$this->cron_autocheck_enabled()) { $this->cron_mtrace('Automatic check for available updates not enabled, skipping.'); return; } $now = $this->cron_current_timestamp(); if ($this->cron_has_fresh_fetch($now)) { $this->cron_mtrace('Recently fetched info about available updates is still fresh enough, skipping.'); return; } if ($this->cron_has_outdated_fetch($now)) { $this->cron_mtrace('Outdated or missing info about available updates, forced fetching ... ', ''); $this->cron_execute(); return; } $offset = $this->cron_execution_offset(); $start = mktime(1, 0, 0, date('n', $now), date('j', $now), date('Y', $now)); // 01:00 AM today local time if ($now > $start + $offset) { $this->cron_mtrace('Regular daily check for available updates ... ', ''); $this->cron_execute(); return; } }
[ "public", "function", "cron", "(", ")", "{", "global", "$", "CFG", ";", "if", "(", "!", "$", "this", "->", "enabled", "(", ")", "or", "!", "$", "this", "->", "cron_autocheck_enabled", "(", ")", ")", "{", "$", "this", "->", "cron_mtrace", "(", "'Automatic check for available updates not enabled, skipping.'", ")", ";", "return", ";", "}", "$", "now", "=", "$", "this", "->", "cron_current_timestamp", "(", ")", ";", "if", "(", "$", "this", "->", "cron_has_fresh_fetch", "(", "$", "now", ")", ")", "{", "$", "this", "->", "cron_mtrace", "(", "'Recently fetched info about available updates is still fresh enough, skipping.'", ")", ";", "return", ";", "}", "if", "(", "$", "this", "->", "cron_has_outdated_fetch", "(", "$", "now", ")", ")", "{", "$", "this", "->", "cron_mtrace", "(", "'Outdated or missing info about available updates, forced fetching ... '", ",", "''", ")", ";", "$", "this", "->", "cron_execute", "(", ")", ";", "return", ";", "}", "$", "offset", "=", "$", "this", "->", "cron_execution_offset", "(", ")", ";", "$", "start", "=", "mktime", "(", "1", ",", "0", ",", "0", ",", "date", "(", "'n'", ",", "$", "now", ")", ",", "date", "(", "'j'", ",", "$", "now", ")", ",", "date", "(", "'Y'", ",", "$", "now", ")", ")", ";", "// 01:00 AM today local time", "if", "(", "$", "now", ">", "$", "start", "+", "$", "offset", ")", "{", "$", "this", "->", "cron_mtrace", "(", "'Regular daily check for available updates ... '", ",", "''", ")", ";", "$", "this", "->", "cron_execute", "(", ")", ";", "return", ";", "}", "}" ]
The method being run via cron.php
[ "The", "method", "being", "run", "via", "cron", ".", "php" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/checker.php#L196-L224
214,339
moodle/moodle
lib/classes/update/checker.php
checker.get_response
protected function get_response() { global $CFG; require_once($CFG->libdir.'/filelib.php'); $curl = new \curl(array('proxy' => true)); $response = $curl->post($this->prepare_request_url(), $this->prepare_request_params(), $this->prepare_request_options()); $curlerrno = $curl->get_errno(); if (!empty($curlerrno)) { throw new checker_exception('err_response_curl', 'cURL error '.$curlerrno.': '.$curl->error); } $curlinfo = $curl->get_info(); if ($curlinfo['http_code'] != 200) { throw new checker_exception('err_response_http_code', $curlinfo['http_code']); } return $response; }
php
protected function get_response() { global $CFG; require_once($CFG->libdir.'/filelib.php'); $curl = new \curl(array('proxy' => true)); $response = $curl->post($this->prepare_request_url(), $this->prepare_request_params(), $this->prepare_request_options()); $curlerrno = $curl->get_errno(); if (!empty($curlerrno)) { throw new checker_exception('err_response_curl', 'cURL error '.$curlerrno.': '.$curl->error); } $curlinfo = $curl->get_info(); if ($curlinfo['http_code'] != 200) { throw new checker_exception('err_response_http_code', $curlinfo['http_code']); } return $response; }
[ "protected", "function", "get_response", "(", ")", "{", "global", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/filelib.php'", ")", ";", "$", "curl", "=", "new", "\\", "curl", "(", "array", "(", "'proxy'", "=>", "true", ")", ")", ";", "$", "response", "=", "$", "curl", "->", "post", "(", "$", "this", "->", "prepare_request_url", "(", ")", ",", "$", "this", "->", "prepare_request_params", "(", ")", ",", "$", "this", "->", "prepare_request_options", "(", ")", ")", ";", "$", "curlerrno", "=", "$", "curl", "->", "get_errno", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "curlerrno", ")", ")", "{", "throw", "new", "checker_exception", "(", "'err_response_curl'", ",", "'cURL error '", ".", "$", "curlerrno", ".", "': '", ".", "$", "curl", "->", "error", ")", ";", "}", "$", "curlinfo", "=", "$", "curl", "->", "get_info", "(", ")", ";", "if", "(", "$", "curlinfo", "[", "'http_code'", "]", "!=", "200", ")", "{", "throw", "new", "checker_exception", "(", "'err_response_http_code'", ",", "$", "curlinfo", "[", "'http_code'", "]", ")", ";", "}", "return", "$", "response", ";", "}" ]
Makes cURL request to get data from the remote site @return string raw request result @throws checker_exception
[ "Makes", "cURL", "request", "to", "get", "data", "from", "the", "remote", "site" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/checker.php#L234-L249
214,340
moodle/moodle
lib/classes/update/checker.php
checker.validate_response
protected function validate_response($response) { $response = $this->decode_response($response); if (empty($response)) { throw new checker_exception('err_response_empty'); } if (empty($response['status']) or $response['status'] !== 'OK') { throw new checker_exception('err_response_status', $response['status']); } if (empty($response['apiver']) or $response['apiver'] !== '1.3') { throw new checker_exception('err_response_format_version', $response['apiver']); } if (empty($response['forbranch']) or $response['forbranch'] !== moodle_major_version(true)) { throw new checker_exception('err_response_target_version', $response['forbranch']); } }
php
protected function validate_response($response) { $response = $this->decode_response($response); if (empty($response)) { throw new checker_exception('err_response_empty'); } if (empty($response['status']) or $response['status'] !== 'OK') { throw new checker_exception('err_response_status', $response['status']); } if (empty($response['apiver']) or $response['apiver'] !== '1.3') { throw new checker_exception('err_response_format_version', $response['apiver']); } if (empty($response['forbranch']) or $response['forbranch'] !== moodle_major_version(true)) { throw new checker_exception('err_response_target_version', $response['forbranch']); } }
[ "protected", "function", "validate_response", "(", "$", "response", ")", "{", "$", "response", "=", "$", "this", "->", "decode_response", "(", "$", "response", ")", ";", "if", "(", "empty", "(", "$", "response", ")", ")", "{", "throw", "new", "checker_exception", "(", "'err_response_empty'", ")", ";", "}", "if", "(", "empty", "(", "$", "response", "[", "'status'", "]", ")", "or", "$", "response", "[", "'status'", "]", "!==", "'OK'", ")", "{", "throw", "new", "checker_exception", "(", "'err_response_status'", ",", "$", "response", "[", "'status'", "]", ")", ";", "}", "if", "(", "empty", "(", "$", "response", "[", "'apiver'", "]", ")", "or", "$", "response", "[", "'apiver'", "]", "!==", "'1.3'", ")", "{", "throw", "new", "checker_exception", "(", "'err_response_format_version'", ",", "$", "response", "[", "'apiver'", "]", ")", ";", "}", "if", "(", "empty", "(", "$", "response", "[", "'forbranch'", "]", ")", "or", "$", "response", "[", "'forbranch'", "]", "!==", "moodle_major_version", "(", "true", ")", ")", "{", "throw", "new", "checker_exception", "(", "'err_response_target_version'", ",", "$", "response", "[", "'forbranch'", "]", ")", ";", "}", "}" ]
Makes sure the response is valid, has correct API format etc. @param string $response raw response as returned by the {@link self::get_response()} @throws checker_exception
[ "Makes", "sure", "the", "response", "is", "valid", "has", "correct", "API", "format", "etc", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/checker.php#L257-L276
214,341
moodle/moodle
lib/classes/update/checker.php
checker.store_response
protected function store_response($response) { set_config('recentfetch', time(), 'core_plugin'); set_config('recentresponse', $response, 'core_plugin'); if (defined('CACHE_DISABLE_ALL') and CACHE_DISABLE_ALL) { // Very nasty hack to work around cache coherency issues on admin/index.php?cache=0 page, // we definitely need to keep caches in sync when writing into DB at all times! \cache_helper::purge_all(true); } $this->restore_response(true); }
php
protected function store_response($response) { set_config('recentfetch', time(), 'core_plugin'); set_config('recentresponse', $response, 'core_plugin'); if (defined('CACHE_DISABLE_ALL') and CACHE_DISABLE_ALL) { // Very nasty hack to work around cache coherency issues on admin/index.php?cache=0 page, // we definitely need to keep caches in sync when writing into DB at all times! \cache_helper::purge_all(true); } $this->restore_response(true); }
[ "protected", "function", "store_response", "(", "$", "response", ")", "{", "set_config", "(", "'recentfetch'", ",", "time", "(", ")", ",", "'core_plugin'", ")", ";", "set_config", "(", "'recentresponse'", ",", "$", "response", ",", "'core_plugin'", ")", ";", "if", "(", "defined", "(", "'CACHE_DISABLE_ALL'", ")", "and", "CACHE_DISABLE_ALL", ")", "{", "// Very nasty hack to work around cache coherency issues on admin/index.php?cache=0 page,", "// we definitely need to keep caches in sync when writing into DB at all times!", "\\", "cache_helper", "::", "purge_all", "(", "true", ")", ";", "}", "$", "this", "->", "restore_response", "(", "true", ")", ";", "}" ]
Stores the valid fetched response for later usage This implementation uses the config_plugins table as the permanent storage. @param string $response raw valid data returned by {@link self::get_response()}
[ "Stores", "the", "valid", "fetched", "response", "for", "later", "usage" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/checker.php#L295-L307
214,342
moodle/moodle
lib/classes/update/checker.php
checker.restore_response
protected function restore_response($forcereload = false) { if (!$forcereload and !is_null($this->recentresponse)) { // We already have it, nothing to do. return; } $config = get_config('core_plugin'); if (!empty($config->recentresponse) and !empty($config->recentfetch)) { try { $this->validate_response($config->recentresponse); $this->recentfetch = $config->recentfetch; $this->recentresponse = $this->decode_response($config->recentresponse); } catch (checker_exception $e) { // The server response is not valid. Behave as if no data were fetched yet. // This may happen when the most recent update info (cached locally) has been // fetched with the previous branch of Moodle (like during an upgrade from 2.x // to 2.y) or when the API of the response has changed. $this->recentresponse = array(); } } else { $this->recentresponse = array(); } }
php
protected function restore_response($forcereload = false) { if (!$forcereload and !is_null($this->recentresponse)) { // We already have it, nothing to do. return; } $config = get_config('core_plugin'); if (!empty($config->recentresponse) and !empty($config->recentfetch)) { try { $this->validate_response($config->recentresponse); $this->recentfetch = $config->recentfetch; $this->recentresponse = $this->decode_response($config->recentresponse); } catch (checker_exception $e) { // The server response is not valid. Behave as if no data were fetched yet. // This may happen when the most recent update info (cached locally) has been // fetched with the previous branch of Moodle (like during an upgrade from 2.x // to 2.y) or when the API of the response has changed. $this->recentresponse = array(); } } else { $this->recentresponse = array(); } }
[ "protected", "function", "restore_response", "(", "$", "forcereload", "=", "false", ")", "{", "if", "(", "!", "$", "forcereload", "and", "!", "is_null", "(", "$", "this", "->", "recentresponse", ")", ")", "{", "// We already have it, nothing to do.", "return", ";", "}", "$", "config", "=", "get_config", "(", "'core_plugin'", ")", ";", "if", "(", "!", "empty", "(", "$", "config", "->", "recentresponse", ")", "and", "!", "empty", "(", "$", "config", "->", "recentfetch", ")", ")", "{", "try", "{", "$", "this", "->", "validate_response", "(", "$", "config", "->", "recentresponse", ")", ";", "$", "this", "->", "recentfetch", "=", "$", "config", "->", "recentfetch", ";", "$", "this", "->", "recentresponse", "=", "$", "this", "->", "decode_response", "(", "$", "config", "->", "recentresponse", ")", ";", "}", "catch", "(", "checker_exception", "$", "e", ")", "{", "// The server response is not valid. Behave as if no data were fetched yet.", "// This may happen when the most recent update info (cached locally) has been", "// fetched with the previous branch of Moodle (like during an upgrade from 2.x", "// to 2.y) or when the API of the response has changed.", "$", "this", "->", "recentresponse", "=", "array", "(", ")", ";", "}", "}", "else", "{", "$", "this", "->", "recentresponse", "=", "array", "(", ")", ";", "}", "}" ]
Loads the most recent raw response record we have fetched After this method is called, $this->recentresponse is set to an array. If the array is empty, then either no data have been fetched yet or the fetched data do not have expected format (and thence they are ignored and a debugging message is displayed). This implementation uses the config_plugins table as the permanent storage. @param bool $forcereload reload even if it was already loaded
[ "Loads", "the", "most", "recent", "raw", "response", "record", "we", "have", "fetched" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/checker.php#L321-L346
214,343
moodle/moodle
lib/classes/update/checker.php
checker.load_current_environment
protected function load_current_environment($forcereload=false) { global $CFG; if (!is_null($this->currentversion) and !$forcereload) { // Nothing to do. return; } $version = null; $release = null; require($CFG->dirroot.'/version.php'); $this->currentversion = $version; $this->currentrelease = $release; $this->currentbranch = moodle_major_version(true); $pluginman = \core_plugin_manager::instance(); foreach ($pluginman->get_plugins() as $type => $plugins) { foreach ($plugins as $plugin) { if (!$plugin->is_standard()) { $this->currentplugins[$plugin->component] = $plugin->versiondisk; } } } }
php
protected function load_current_environment($forcereload=false) { global $CFG; if (!is_null($this->currentversion) and !$forcereload) { // Nothing to do. return; } $version = null; $release = null; require($CFG->dirroot.'/version.php'); $this->currentversion = $version; $this->currentrelease = $release; $this->currentbranch = moodle_major_version(true); $pluginman = \core_plugin_manager::instance(); foreach ($pluginman->get_plugins() as $type => $plugins) { foreach ($plugins as $plugin) { if (!$plugin->is_standard()) { $this->currentplugins[$plugin->component] = $plugin->versiondisk; } } } }
[ "protected", "function", "load_current_environment", "(", "$", "forcereload", "=", "false", ")", "{", "global", "$", "CFG", ";", "if", "(", "!", "is_null", "(", "$", "this", "->", "currentversion", ")", "and", "!", "$", "forcereload", ")", "{", "// Nothing to do.", "return", ";", "}", "$", "version", "=", "null", ";", "$", "release", "=", "null", ";", "require", "(", "$", "CFG", "->", "dirroot", ".", "'/version.php'", ")", ";", "$", "this", "->", "currentversion", "=", "$", "version", ";", "$", "this", "->", "currentrelease", "=", "$", "release", ";", "$", "this", "->", "currentbranch", "=", "moodle_major_version", "(", "true", ")", ";", "$", "pluginman", "=", "\\", "core_plugin_manager", "::", "instance", "(", ")", ";", "foreach", "(", "$", "pluginman", "->", "get_plugins", "(", ")", "as", "$", "type", "=>", "$", "plugins", ")", "{", "foreach", "(", "$", "plugins", "as", "$", "plugin", ")", "{", "if", "(", "!", "$", "plugin", "->", "is_standard", "(", ")", ")", "{", "$", "this", "->", "currentplugins", "[", "$", "plugin", "->", "component", "]", "=", "$", "plugin", "->", "versiondisk", ";", "}", "}", "}", "}" ]
Sets the properties currentversion, currentrelease, currentbranch and currentplugins @param bool $forcereload
[ "Sets", "the", "properties", "currentversion", "currentrelease", "currentbranch", "and", "currentplugins" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/checker.php#L425-L449
214,344
moodle/moodle
lib/classes/update/checker.php
checker.prepare_request_params
protected function prepare_request_params() { global $CFG; $this->load_current_environment(); $this->restore_response(); $params = array(); $params['format'] = 'json'; if (isset($this->recentresponse['ticket'])) { $params['ticket'] = $this->recentresponse['ticket']; } if (isset($this->currentversion)) { $params['version'] = $this->currentversion; } else { throw new coding_exception('Main Moodle version must be already known here'); } if (isset($this->currentbranch)) { $params['branch'] = $this->currentbranch; } else { throw new coding_exception('Moodle release must be already known here'); } $plugins = array(); foreach ($this->currentplugins as $plugin => $version) { $plugins[] = $plugin.'@'.$version; } if (!empty($plugins)) { $params['plugins'] = implode(',', $plugins); } return $params; }
php
protected function prepare_request_params() { global $CFG; $this->load_current_environment(); $this->restore_response(); $params = array(); $params['format'] = 'json'; if (isset($this->recentresponse['ticket'])) { $params['ticket'] = $this->recentresponse['ticket']; } if (isset($this->currentversion)) { $params['version'] = $this->currentversion; } else { throw new coding_exception('Main Moodle version must be already known here'); } if (isset($this->currentbranch)) { $params['branch'] = $this->currentbranch; } else { throw new coding_exception('Moodle release must be already known here'); } $plugins = array(); foreach ($this->currentplugins as $plugin => $version) { $plugins[] = $plugin.'@'.$version; } if (!empty($plugins)) { $params['plugins'] = implode(',', $plugins); } return $params; }
[ "protected", "function", "prepare_request_params", "(", ")", "{", "global", "$", "CFG", ";", "$", "this", "->", "load_current_environment", "(", ")", ";", "$", "this", "->", "restore_response", "(", ")", ";", "$", "params", "=", "array", "(", ")", ";", "$", "params", "[", "'format'", "]", "=", "'json'", ";", "if", "(", "isset", "(", "$", "this", "->", "recentresponse", "[", "'ticket'", "]", ")", ")", "{", "$", "params", "[", "'ticket'", "]", "=", "$", "this", "->", "recentresponse", "[", "'ticket'", "]", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "currentversion", ")", ")", "{", "$", "params", "[", "'version'", "]", "=", "$", "this", "->", "currentversion", ";", "}", "else", "{", "throw", "new", "coding_exception", "(", "'Main Moodle version must be already known here'", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "currentbranch", ")", ")", "{", "$", "params", "[", "'branch'", "]", "=", "$", "this", "->", "currentbranch", ";", "}", "else", "{", "throw", "new", "coding_exception", "(", "'Moodle release must be already known here'", ")", ";", "}", "$", "plugins", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "currentplugins", "as", "$", "plugin", "=>", "$", "version", ")", "{", "$", "plugins", "[", "]", "=", "$", "plugin", ".", "'@'", ".", "$", "version", ";", "}", "if", "(", "!", "empty", "(", "$", "plugins", ")", ")", "{", "$", "params", "[", "'plugins'", "]", "=", "implode", "(", "','", ",", "$", "plugins", ")", ";", "}", "return", "$", "params", ";", "}" ]
Returns the list of HTTP params to be sent to the updates provider URL @return array of (string)param => (string)value
[ "Returns", "the", "list", "of", "HTTP", "params", "to", "be", "sent", "to", "the", "updates", "provider", "URL" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/checker.php#L456-L490
214,345
moodle/moodle
lib/classes/update/checker.php
checker.cron_has_fresh_fetch
protected function cron_has_fresh_fetch($now) { $recent = $this->get_last_timefetched(); if (empty($recent)) { return false; } if ($now < $recent) { $this->cron_mtrace('The most recent fetch is reported to be in the future, this is weird!'); return true; } if ($now - $recent > 24 * HOURSECS) { return false; } return true; }
php
protected function cron_has_fresh_fetch($now) { $recent = $this->get_last_timefetched(); if (empty($recent)) { return false; } if ($now < $recent) { $this->cron_mtrace('The most recent fetch is reported to be in the future, this is weird!'); return true; } if ($now - $recent > 24 * HOURSECS) { return false; } return true; }
[ "protected", "function", "cron_has_fresh_fetch", "(", "$", "now", ")", "{", "$", "recent", "=", "$", "this", "->", "get_last_timefetched", "(", ")", ";", "if", "(", "empty", "(", "$", "recent", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "now", "<", "$", "recent", ")", "{", "$", "this", "->", "cron_mtrace", "(", "'The most recent fetch is reported to be in the future, this is weird!'", ")", ";", "return", "true", ";", "}", "if", "(", "$", "now", "-", "$", "recent", ">", "24", "*", "HOURSECS", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Decide if the recently fetched data are still fresh enough @param int $now current timestamp @return bool true if no need to re-fetch, false otherwise
[ "Decide", "if", "the", "recently", "fetched", "data", "are", "still", "fresh", "enough" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/checker.php#L547-L564
214,346
moodle/moodle
lib/classes/update/checker.php
checker.cron_execution_offset
protected function cron_execution_offset() { global $CFG; if (empty($CFG->updatecronoffset)) { set_config('updatecronoffset', rand(1, 5 * HOURSECS)); } return $CFG->updatecronoffset; }
php
protected function cron_execution_offset() { global $CFG; if (empty($CFG->updatecronoffset)) { set_config('updatecronoffset', rand(1, 5 * HOURSECS)); } return $CFG->updatecronoffset; }
[ "protected", "function", "cron_execution_offset", "(", ")", "{", "global", "$", "CFG", ";", "if", "(", "empty", "(", "$", "CFG", "->", "updatecronoffset", ")", ")", "{", "set_config", "(", "'updatecronoffset'", ",", "rand", "(", "1", ",", "5", "*", "HOURSECS", ")", ")", ";", "}", "return", "$", "CFG", "->", "updatecronoffset", ";", "}" ]
Returns the cron execution offset for this site The main {@link self::cron()} is supposed to run every night in some random time between 01:00 and 06:00 AM (local time). The exact moment is defined by so called execution offset, that is the amount of time after 01:00 AM. The offset value is initially generated randomly and then used consistently at the site. This way, the regular checks against the download.moodle.org server are spread in time. @return int the offset number of seconds from range 1 sec to 5 hours
[ "Returns", "the", "cron", "execution", "offset", "for", "this", "site" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/checker.php#L602-L610
214,347
moodle/moodle
lib/classes/update/checker.php
checker.cron_execute
protected function cron_execute() { try { $this->restore_response(); $previous = $this->recentresponse; $this->fetch(); $this->restore_response(true); $current = $this->recentresponse; $changes = $this->compare_responses($previous, $current); $notifications = $this->cron_notifications($changes); $this->cron_notify($notifications); $this->cron_mtrace('done'); } catch (checker_exception $e) { $this->cron_mtrace('FAILED!'); } }
php
protected function cron_execute() { try { $this->restore_response(); $previous = $this->recentresponse; $this->fetch(); $this->restore_response(true); $current = $this->recentresponse; $changes = $this->compare_responses($previous, $current); $notifications = $this->cron_notifications($changes); $this->cron_notify($notifications); $this->cron_mtrace('done'); } catch (checker_exception $e) { $this->cron_mtrace('FAILED!'); } }
[ "protected", "function", "cron_execute", "(", ")", "{", "try", "{", "$", "this", "->", "restore_response", "(", ")", ";", "$", "previous", "=", "$", "this", "->", "recentresponse", ";", "$", "this", "->", "fetch", "(", ")", ";", "$", "this", "->", "restore_response", "(", "true", ")", ";", "$", "current", "=", "$", "this", "->", "recentresponse", ";", "$", "changes", "=", "$", "this", "->", "compare_responses", "(", "$", "previous", ",", "$", "current", ")", ";", "$", "notifications", "=", "$", "this", "->", "cron_notifications", "(", "$", "changes", ")", ";", "$", "this", "->", "cron_notify", "(", "$", "notifications", ")", ";", "$", "this", "->", "cron_mtrace", "(", "'done'", ")", ";", "}", "catch", "(", "checker_exception", "$", "e", ")", "{", "$", "this", "->", "cron_mtrace", "(", "'FAILED!'", ")", ";", "}", "}" ]
Fetch available updates info and eventually send notification to site admins
[ "Fetch", "available", "updates", "info", "and", "eventually", "send", "notification", "to", "site", "admins" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/checker.php#L615-L630
214,348
moodle/moodle
lib/classes/update/checker.php
checker.cron_notifications
protected function cron_notifications(array $changes) { global $CFG; if (empty($changes)) { return array(); } $notifications = array(); $pluginman = \core_plugin_manager::instance(); $plugins = $pluginman->get_plugins(); foreach ($changes as $component => $componentchanges) { if (empty($componentchanges)) { continue; } $componentupdates = $this->get_update_info($component, array('minmaturity' => $CFG->updateminmaturity, 'notifybuilds' => $CFG->updatenotifybuilds)); if (empty($componentupdates)) { continue; } // Notify only about those $componentchanges that are present in $componentupdates // to respect the preferences. foreach ($componentchanges as $componentchange) { foreach ($componentupdates as $componentupdate) { if ($componentupdate->version == $componentchange['version']) { if ($component == 'core') { // In case of 'core', we already know that the $componentupdate // is a real update with higher version ({@see self::get_update_info()}). // We just perform additional check for the release property as there // can be two Moodle releases having the same version (e.g. 2.4.0 and 2.5dev shortly // after the release). We can do that because we have the release info // always available for the core. if ((string)$componentupdate->release === (string)$componentchange['release']) { $notifications[] = $componentupdate; } } else { // Use the core_plugin_manager to check if the detected $componentchange // is a real update with higher version. That is, the $componentchange // is present in the array of {@link \core\update\info} objects // returned by the plugin's available_updates() method. list($plugintype, $pluginname) = core_component::normalize_component($component); if (!empty($plugins[$plugintype][$pluginname])) { $availableupdates = $plugins[$plugintype][$pluginname]->available_updates(); if (!empty($availableupdates)) { foreach ($availableupdates as $availableupdate) { if ($availableupdate->version == $componentchange['version']) { $notifications[] = $componentupdate; } } } } } } } } } return $notifications; }
php
protected function cron_notifications(array $changes) { global $CFG; if (empty($changes)) { return array(); } $notifications = array(); $pluginman = \core_plugin_manager::instance(); $plugins = $pluginman->get_plugins(); foreach ($changes as $component => $componentchanges) { if (empty($componentchanges)) { continue; } $componentupdates = $this->get_update_info($component, array('minmaturity' => $CFG->updateminmaturity, 'notifybuilds' => $CFG->updatenotifybuilds)); if (empty($componentupdates)) { continue; } // Notify only about those $componentchanges that are present in $componentupdates // to respect the preferences. foreach ($componentchanges as $componentchange) { foreach ($componentupdates as $componentupdate) { if ($componentupdate->version == $componentchange['version']) { if ($component == 'core') { // In case of 'core', we already know that the $componentupdate // is a real update with higher version ({@see self::get_update_info()}). // We just perform additional check for the release property as there // can be two Moodle releases having the same version (e.g. 2.4.0 and 2.5dev shortly // after the release). We can do that because we have the release info // always available for the core. if ((string)$componentupdate->release === (string)$componentchange['release']) { $notifications[] = $componentupdate; } } else { // Use the core_plugin_manager to check if the detected $componentchange // is a real update with higher version. That is, the $componentchange // is present in the array of {@link \core\update\info} objects // returned by the plugin's available_updates() method. list($plugintype, $pluginname) = core_component::normalize_component($component); if (!empty($plugins[$plugintype][$pluginname])) { $availableupdates = $plugins[$plugintype][$pluginname]->available_updates(); if (!empty($availableupdates)) { foreach ($availableupdates as $availableupdate) { if ($availableupdate->version == $componentchange['version']) { $notifications[] = $componentupdate; } } } } } } } } } return $notifications; }
[ "protected", "function", "cron_notifications", "(", "array", "$", "changes", ")", "{", "global", "$", "CFG", ";", "if", "(", "empty", "(", "$", "changes", ")", ")", "{", "return", "array", "(", ")", ";", "}", "$", "notifications", "=", "array", "(", ")", ";", "$", "pluginman", "=", "\\", "core_plugin_manager", "::", "instance", "(", ")", ";", "$", "plugins", "=", "$", "pluginman", "->", "get_plugins", "(", ")", ";", "foreach", "(", "$", "changes", "as", "$", "component", "=>", "$", "componentchanges", ")", "{", "if", "(", "empty", "(", "$", "componentchanges", ")", ")", "{", "continue", ";", "}", "$", "componentupdates", "=", "$", "this", "->", "get_update_info", "(", "$", "component", ",", "array", "(", "'minmaturity'", "=>", "$", "CFG", "->", "updateminmaturity", ",", "'notifybuilds'", "=>", "$", "CFG", "->", "updatenotifybuilds", ")", ")", ";", "if", "(", "empty", "(", "$", "componentupdates", ")", ")", "{", "continue", ";", "}", "// Notify only about those $componentchanges that are present in $componentupdates", "// to respect the preferences.", "foreach", "(", "$", "componentchanges", "as", "$", "componentchange", ")", "{", "foreach", "(", "$", "componentupdates", "as", "$", "componentupdate", ")", "{", "if", "(", "$", "componentupdate", "->", "version", "==", "$", "componentchange", "[", "'version'", "]", ")", "{", "if", "(", "$", "component", "==", "'core'", ")", "{", "// In case of 'core', we already know that the $componentupdate", "// is a real update with higher version ({@see self::get_update_info()}).", "// We just perform additional check for the release property as there", "// can be two Moodle releases having the same version (e.g. 2.4.0 and 2.5dev shortly", "// after the release). We can do that because we have the release info", "// always available for the core.", "if", "(", "(", "string", ")", "$", "componentupdate", "->", "release", "===", "(", "string", ")", "$", "componentchange", "[", "'release'", "]", ")", "{", "$", "notifications", "[", "]", "=", "$", "componentupdate", ";", "}", "}", "else", "{", "// Use the core_plugin_manager to check if the detected $componentchange", "// is a real update with higher version. That is, the $componentchange", "// is present in the array of {@link \\core\\update\\info} objects", "// returned by the plugin's available_updates() method.", "list", "(", "$", "plugintype", ",", "$", "pluginname", ")", "=", "core_component", "::", "normalize_component", "(", "$", "component", ")", ";", "if", "(", "!", "empty", "(", "$", "plugins", "[", "$", "plugintype", "]", "[", "$", "pluginname", "]", ")", ")", "{", "$", "availableupdates", "=", "$", "plugins", "[", "$", "plugintype", "]", "[", "$", "pluginname", "]", "->", "available_updates", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "availableupdates", ")", ")", "{", "foreach", "(", "$", "availableupdates", "as", "$", "availableupdate", ")", "{", "if", "(", "$", "availableupdate", "->", "version", "==", "$", "componentchange", "[", "'version'", "]", ")", "{", "$", "notifications", "[", "]", "=", "$", "componentupdate", ";", "}", "}", "}", "}", "}", "}", "}", "}", "}", "return", "$", "notifications", ";", "}" ]
Given the list of changes in available updates, pick those to send to site admins @param array $changes as returned by {@link self::compare_responses()} @return array of \core\update\info objects to send to site admins
[ "Given", "the", "list", "of", "changes", "in", "available", "updates", "pick", "those", "to", "send", "to", "site", "admins" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/checker.php#L638-L696
214,349
moodle/moodle
lib/classes/update/checker.php
checker.is_same_release
protected function is_same_release($remote, $local=null) { if (is_null($local)) { $this->load_current_environment(); $local = $this->currentrelease; } $pattern = '/^([0-9\.\+]+)([^(]*)/'; preg_match($pattern, $remote, $remotematches); preg_match($pattern, $local, $localmatches); $remotematches[1] = str_replace('+', '', $remotematches[1]); $localmatches[1] = str_replace('+', '', $localmatches[1]); if ($remotematches[1] === $localmatches[1] and rtrim($remotematches[2]) === rtrim($localmatches[2])) { return true; } else { return false; } }
php
protected function is_same_release($remote, $local=null) { if (is_null($local)) { $this->load_current_environment(); $local = $this->currentrelease; } $pattern = '/^([0-9\.\+]+)([^(]*)/'; preg_match($pattern, $remote, $remotematches); preg_match($pattern, $local, $localmatches); $remotematches[1] = str_replace('+', '', $remotematches[1]); $localmatches[1] = str_replace('+', '', $localmatches[1]); if ($remotematches[1] === $localmatches[1] and rtrim($remotematches[2]) === rtrim($localmatches[2])) { return true; } else { return false; } }
[ "protected", "function", "is_same_release", "(", "$", "remote", ",", "$", "local", "=", "null", ")", "{", "if", "(", "is_null", "(", "$", "local", ")", ")", "{", "$", "this", "->", "load_current_environment", "(", ")", ";", "$", "local", "=", "$", "this", "->", "currentrelease", ";", "}", "$", "pattern", "=", "'/^([0-9\\.\\+]+)([^(]*)/'", ";", "preg_match", "(", "$", "pattern", ",", "$", "remote", ",", "$", "remotematches", ")", ";", "preg_match", "(", "$", "pattern", ",", "$", "local", ",", "$", "localmatches", ")", ";", "$", "remotematches", "[", "1", "]", "=", "str_replace", "(", "'+'", ",", "''", ",", "$", "remotematches", "[", "1", "]", ")", ";", "$", "localmatches", "[", "1", "]", "=", "str_replace", "(", "'+'", ",", "''", ",", "$", "localmatches", "[", "1", "]", ")", ";", "if", "(", "$", "remotematches", "[", "1", "]", "===", "$", "localmatches", "[", "1", "]", "and", "rtrim", "(", "$", "remotematches", "[", "2", "]", ")", "===", "rtrim", "(", "$", "localmatches", "[", "2", "]", ")", ")", "{", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}" ]
Compare two release labels and decide if they are the same @param string $remote release info of the available update @param null|string $local release info of the local code, defaults to $release defined in version.php @return boolean true if the releases declare the same minor+major version
[ "Compare", "two", "release", "labels", "and", "decide", "if", "they", "are", "the", "same" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/update/checker.php#L824-L844
214,350
moodle/moodle
calendar/classes/external/footer_options_exporter.php
footer_options_exporter.get_manage_subscriptions_button
protected function get_manage_subscriptions_button() { if (calendar_user_can_add_event($this->calendar->course)) { $managesubscriptionurl = new moodle_url('/calendar/managesubscriptions.php', $this->get_link_params()); return new \single_button($managesubscriptionurl, get_string('managesubscriptions', 'calendar'), 'get'); } }
php
protected function get_manage_subscriptions_button() { if (calendar_user_can_add_event($this->calendar->course)) { $managesubscriptionurl = new moodle_url('/calendar/managesubscriptions.php', $this->get_link_params()); return new \single_button($managesubscriptionurl, get_string('managesubscriptions', 'calendar'), 'get'); } }
[ "protected", "function", "get_manage_subscriptions_button", "(", ")", "{", "if", "(", "calendar_user_can_add_event", "(", "$", "this", "->", "calendar", "->", "course", ")", ")", "{", "$", "managesubscriptionurl", "=", "new", "moodle_url", "(", "'/calendar/managesubscriptions.php'", ",", "$", "this", "->", "get_link_params", "(", ")", ")", ";", "return", "new", "\\", "single_button", "(", "$", "managesubscriptionurl", ",", "get_string", "(", "'managesubscriptions'", ",", "'calendar'", ")", ",", "'get'", ")", ";", "}", "}" ]
Get manage subscription button. @return string The manage subscription button html.
[ "Get", "manage", "subscription", "button", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/external/footer_options_exporter.php#L84-L90
214,351
moodle/moodle
calendar/classes/external/footer_options_exporter.php
footer_options_exporter.get_link_params
protected function get_link_params() { $params = []; if (SITEID !== $this->calendar->course->id) { $params['course'] = $this->calendar->course->id; } else if (null !== $this->calendar->categoryid && $this->calendar->categoryid > 0) { $params['category'] = $this->calendar->categoryid; } else { $params['course'] = SITEID; } return $params; }
php
protected function get_link_params() { $params = []; if (SITEID !== $this->calendar->course->id) { $params['course'] = $this->calendar->course->id; } else if (null !== $this->calendar->categoryid && $this->calendar->categoryid > 0) { $params['category'] = $this->calendar->categoryid; } else { $params['course'] = SITEID; } return $params; }
[ "protected", "function", "get_link_params", "(", ")", "{", "$", "params", "=", "[", "]", ";", "if", "(", "SITEID", "!==", "$", "this", "->", "calendar", "->", "course", "->", "id", ")", "{", "$", "params", "[", "'course'", "]", "=", "$", "this", "->", "calendar", "->", "course", "->", "id", ";", "}", "else", "if", "(", "null", "!==", "$", "this", "->", "calendar", "->", "categoryid", "&&", "$", "this", "->", "calendar", "->", "categoryid", ">", "0", ")", "{", "$", "params", "[", "'category'", "]", "=", "$", "this", "->", "calendar", "->", "categoryid", ";", "}", "else", "{", "$", "params", "[", "'course'", "]", "=", "SITEID", ";", "}", "return", "$", "params", ";", "}" ]
Get the list of URL parameters for calendar links. @return array
[ "Get", "the", "list", "of", "URL", "parameters", "for", "calendar", "links", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/external/footer_options_exporter.php#L97-L108
214,352
moodle/moodle
cache/stores/mongodb/MongoDB/Operation/MapReduce.php
MapReduce.createCommand
private function createCommand(Server $server) { $cmd = [ 'mapReduce' => $this->collectionName, 'map' => $this->map, 'reduce' => $this->reduce, 'out' => $this->out, ]; foreach (['finalize', 'jsMode', 'limit', 'maxTimeMS', 'verbose'] as $option) { if (isset($this->options[$option])) { $cmd[$option] = $this->options[$option]; } } foreach (['collation', 'query', 'scope', 'sort'] as $option) { if (isset($this->options[$option])) { $cmd[$option] = (object) $this->options[$option]; } } if (isset($this->options['bypassDocumentValidation']) && \MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)) { $cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation']; } return new Command($cmd); }
php
private function createCommand(Server $server) { $cmd = [ 'mapReduce' => $this->collectionName, 'map' => $this->map, 'reduce' => $this->reduce, 'out' => $this->out, ]; foreach (['finalize', 'jsMode', 'limit', 'maxTimeMS', 'verbose'] as $option) { if (isset($this->options[$option])) { $cmd[$option] = $this->options[$option]; } } foreach (['collation', 'query', 'scope', 'sort'] as $option) { if (isset($this->options[$option])) { $cmd[$option] = (object) $this->options[$option]; } } if (isset($this->options['bypassDocumentValidation']) && \MongoDB\server_supports_feature($server, self::$wireVersionForDocumentLevelValidation)) { $cmd['bypassDocumentValidation'] = $this->options['bypassDocumentValidation']; } return new Command($cmd); }
[ "private", "function", "createCommand", "(", "Server", "$", "server", ")", "{", "$", "cmd", "=", "[", "'mapReduce'", "=>", "$", "this", "->", "collectionName", ",", "'map'", "=>", "$", "this", "->", "map", ",", "'reduce'", "=>", "$", "this", "->", "reduce", ",", "'out'", "=>", "$", "this", "->", "out", ",", "]", ";", "foreach", "(", "[", "'finalize'", ",", "'jsMode'", ",", "'limit'", ",", "'maxTimeMS'", ",", "'verbose'", "]", "as", "$", "option", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "$", "option", "]", ")", ")", "{", "$", "cmd", "[", "$", "option", "]", "=", "$", "this", "->", "options", "[", "$", "option", "]", ";", "}", "}", "foreach", "(", "[", "'collation'", ",", "'query'", ",", "'scope'", ",", "'sort'", "]", "as", "$", "option", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "$", "option", "]", ")", ")", "{", "$", "cmd", "[", "$", "option", "]", "=", "(", "object", ")", "$", "this", "->", "options", "[", "$", "option", "]", ";", "}", "}", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "'bypassDocumentValidation'", "]", ")", "&&", "\\", "MongoDB", "\\", "server_supports_feature", "(", "$", "server", ",", "self", "::", "$", "wireVersionForDocumentLevelValidation", ")", ")", "{", "$", "cmd", "[", "'bypassDocumentValidation'", "]", "=", "$", "this", "->", "options", "[", "'bypassDocumentValidation'", "]", ";", "}", "return", "new", "Command", "(", "$", "cmd", ")", ";", "}" ]
Create the mapReduce command. @param Server $server @return Command
[ "Create", "the", "mapReduce", "command", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/Operation/MapReduce.php#L273-L299
214,353
moodle/moodle
lib/mustache/src/Mustache/Compiler.php
Mustache_Compiler.compile
public function compile($source, array $tree, $name, $customEscape = false, $charset = 'UTF-8', $strictCallables = false, $entityFlags = ENT_COMPAT) { $this->pragmas = $this->defaultPragmas; $this->sections = array(); $this->blocks = array(); $this->source = $source; $this->indentNextLine = true; $this->customEscape = $customEscape; $this->entityFlags = $entityFlags; $this->charset = $charset; $this->strictCallables = $strictCallables; return $this->writeCode($tree, $name); }
php
public function compile($source, array $tree, $name, $customEscape = false, $charset = 'UTF-8', $strictCallables = false, $entityFlags = ENT_COMPAT) { $this->pragmas = $this->defaultPragmas; $this->sections = array(); $this->blocks = array(); $this->source = $source; $this->indentNextLine = true; $this->customEscape = $customEscape; $this->entityFlags = $entityFlags; $this->charset = $charset; $this->strictCallables = $strictCallables; return $this->writeCode($tree, $name); }
[ "public", "function", "compile", "(", "$", "source", ",", "array", "$", "tree", ",", "$", "name", ",", "$", "customEscape", "=", "false", ",", "$", "charset", "=", "'UTF-8'", ",", "$", "strictCallables", "=", "false", ",", "$", "entityFlags", "=", "ENT_COMPAT", ")", "{", "$", "this", "->", "pragmas", "=", "$", "this", "->", "defaultPragmas", ";", "$", "this", "->", "sections", "=", "array", "(", ")", ";", "$", "this", "->", "blocks", "=", "array", "(", ")", ";", "$", "this", "->", "source", "=", "$", "source", ";", "$", "this", "->", "indentNextLine", "=", "true", ";", "$", "this", "->", "customEscape", "=", "$", "customEscape", ";", "$", "this", "->", "entityFlags", "=", "$", "entityFlags", ";", "$", "this", "->", "charset", "=", "$", "charset", ";", "$", "this", "->", "strictCallables", "=", "$", "strictCallables", ";", "return", "$", "this", "->", "writeCode", "(", "$", "tree", ",", "$", "name", ")", ";", "}" ]
Compile a Mustache token parse tree into PHP source code. @param string $source Mustache Template source code @param string $tree Parse tree of Mustache tokens @param string $name Mustache Template class name @param bool $customEscape (default: false) @param string $charset (default: 'UTF-8') @param bool $strictCallables (default: false) @param int $entityFlags (default: ENT_COMPAT) @return string Generated PHP source code
[ "Compile", "a", "Mustache", "token", "parse", "tree", "into", "PHP", "source", "code", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Compiler.php#L43-L56
214,354
moodle/moodle
lib/mustache/src/Mustache/Compiler.php
Mustache_Compiler.writeCode
private function writeCode($tree, $name) { $code = $this->walk($tree); $sections = implode("\n", $this->sections); $blocks = implode("\n", $this->blocks); $klass = empty($this->sections) && empty($this->blocks) ? self::KLASS_NO_LAMBDAS : self::KLASS; $callable = $this->strictCallables ? $this->prepare(self::STRICT_CALLABLE) : ''; return sprintf($this->prepare($klass, 0, false, true), $name, $callable, $code, $sections, $blocks); }
php
private function writeCode($tree, $name) { $code = $this->walk($tree); $sections = implode("\n", $this->sections); $blocks = implode("\n", $this->blocks); $klass = empty($this->sections) && empty($this->blocks) ? self::KLASS_NO_LAMBDAS : self::KLASS; $callable = $this->strictCallables ? $this->prepare(self::STRICT_CALLABLE) : ''; return sprintf($this->prepare($klass, 0, false, true), $name, $callable, $code, $sections, $blocks); }
[ "private", "function", "writeCode", "(", "$", "tree", ",", "$", "name", ")", "{", "$", "code", "=", "$", "this", "->", "walk", "(", "$", "tree", ")", ";", "$", "sections", "=", "implode", "(", "\"\\n\"", ",", "$", "this", "->", "sections", ")", ";", "$", "blocks", "=", "implode", "(", "\"\\n\"", ",", "$", "this", "->", "blocks", ")", ";", "$", "klass", "=", "empty", "(", "$", "this", "->", "sections", ")", "&&", "empty", "(", "$", "this", "->", "blocks", ")", "?", "self", "::", "KLASS_NO_LAMBDAS", ":", "self", "::", "KLASS", ";", "$", "callable", "=", "$", "this", "->", "strictCallables", "?", "$", "this", "->", "prepare", "(", "self", "::", "STRICT_CALLABLE", ")", ":", "''", ";", "return", "sprintf", "(", "$", "this", "->", "prepare", "(", "$", "klass", ",", "0", ",", "false", ",", "true", ")", ",", "$", "name", ",", "$", "callable", ",", "$", "code", ",", "$", "sections", ",", "$", "blocks", ")", ";", "}" ]
Generate Mustache Template class PHP source. @param array $tree Parse tree of Mustache tokens @param string $name Mustache Template class name @return string Generated PHP source code
[ "Generate", "Mustache", "Template", "class", "PHP", "source", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Compiler.php#L225-L235
214,355
moodle/moodle
lib/mustache/src/Mustache/Compiler.php
Mustache_Compiler.blockVar
private function blockVar($nodes, $id, $start, $end, $otag, $ctag, $level) { $id = var_export($id, true); $else = $this->walk($nodes, $level); if ($else !== '') { $else = sprintf($this->prepare(self::BLOCK_VAR_ELSE, $level + 1, false, true), $else); } return sprintf($this->prepare(self::BLOCK_VAR, $level), $id, $else); }
php
private function blockVar($nodes, $id, $start, $end, $otag, $ctag, $level) { $id = var_export($id, true); $else = $this->walk($nodes, $level); if ($else !== '') { $else = sprintf($this->prepare(self::BLOCK_VAR_ELSE, $level + 1, false, true), $else); } return sprintf($this->prepare(self::BLOCK_VAR, $level), $id, $else); }
[ "private", "function", "blockVar", "(", "$", "nodes", ",", "$", "id", ",", "$", "start", ",", "$", "end", ",", "$", "otag", ",", "$", "ctag", ",", "$", "level", ")", "{", "$", "id", "=", "var_export", "(", "$", "id", ",", "true", ")", ";", "$", "else", "=", "$", "this", "->", "walk", "(", "$", "nodes", ",", "$", "level", ")", ";", "if", "(", "$", "else", "!==", "''", ")", "{", "$", "else", "=", "sprintf", "(", "$", "this", "->", "prepare", "(", "self", "::", "BLOCK_VAR_ELSE", ",", "$", "level", "+", "1", ",", "false", ",", "true", ")", ",", "$", "else", ")", ";", "}", "return", "sprintf", "(", "$", "this", "->", "prepare", "(", "self", "::", "BLOCK_VAR", ",", "$", "level", ")", ",", "$", "id", ",", "$", "else", ")", ";", "}" ]
Generate Mustache Template inheritance block variable PHP source. @param array $nodes Array of child tokens @param string $id Section name @param int $start Section start offset @param int $end Section end offset @param string $otag Current Mustache opening tag @param string $ctag Current Mustache closing tag @param int $level @return string Generated PHP source code
[ "Generate", "Mustache", "Template", "inheritance", "block", "variable", "PHP", "source", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Compiler.php#L259-L269
214,356
moodle/moodle
lib/mustache/src/Mustache/Compiler.php
Mustache_Compiler.blockArg
private function blockArg($nodes, $id, $start, $end, $otag, $ctag, $level) { $key = $this->block($nodes); $keystr = var_export($key, true); $id = var_export($id, true); return sprintf($this->prepare(self::BLOCK_ARG, $level), $id, $key); }
php
private function blockArg($nodes, $id, $start, $end, $otag, $ctag, $level) { $key = $this->block($nodes); $keystr = var_export($key, true); $id = var_export($id, true); return sprintf($this->prepare(self::BLOCK_ARG, $level), $id, $key); }
[ "private", "function", "blockArg", "(", "$", "nodes", ",", "$", "id", ",", "$", "start", ",", "$", "end", ",", "$", "otag", ",", "$", "ctag", ",", "$", "level", ")", "{", "$", "key", "=", "$", "this", "->", "block", "(", "$", "nodes", ")", ";", "$", "keystr", "=", "var_export", "(", "$", "key", ",", "true", ")", ";", "$", "id", "=", "var_export", "(", "$", "id", ",", "true", ")", ";", "return", "sprintf", "(", "$", "this", "->", "prepare", "(", "self", "::", "BLOCK_ARG", ",", "$", "level", ")", ",", "$", "id", ",", "$", "key", ")", ";", "}" ]
Generate Mustache Template inheritance block argument PHP source. @param array $nodes Array of child tokens @param string $id Section name @param int $start Section start offset @param int $end Section end offset @param string $otag Current Mustache opening tag @param string $ctag Current Mustache closing tag @param int $level @return string Generated PHP source code
[ "Generate", "Mustache", "Template", "inheritance", "block", "argument", "PHP", "source", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Compiler.php#L286-L293
214,357
moodle/moodle
lib/mustache/src/Mustache/Compiler.php
Mustache_Compiler.block
private function block($nodes) { $code = $this->walk($nodes, 0); $key = ucfirst(md5($code)); if (!isset($this->blocks[$key])) { $this->blocks[$key] = sprintf($this->prepare(self::BLOCK_FUNCTION, 0), $key, $code); } return $key; }
php
private function block($nodes) { $code = $this->walk($nodes, 0); $key = ucfirst(md5($code)); if (!isset($this->blocks[$key])) { $this->blocks[$key] = sprintf($this->prepare(self::BLOCK_FUNCTION, 0), $key, $code); } return $key; }
[ "private", "function", "block", "(", "$", "nodes", ")", "{", "$", "code", "=", "$", "this", "->", "walk", "(", "$", "nodes", ",", "0", ")", ";", "$", "key", "=", "ucfirst", "(", "md5", "(", "$", "code", ")", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "blocks", "[", "$", "key", "]", ")", ")", "{", "$", "this", "->", "blocks", "[", "$", "key", "]", "=", "sprintf", "(", "$", "this", "->", "prepare", "(", "self", "::", "BLOCK_FUNCTION", ",", "0", ")", ",", "$", "key", ",", "$", "code", ")", ";", "}", "return", "$", "key", ";", "}" ]
Generate Mustache Template inheritance block function PHP source. @param array $nodes Array of child tokens @return string key of new block function
[ "Generate", "Mustache", "Template", "inheritance", "block", "function", "PHP", "source", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Compiler.php#L311-L321
214,358
moodle/moodle
lib/mustache/src/Mustache/Compiler.php
Mustache_Compiler.section
private function section($nodes, $id, $filters, $start, $end, $otag, $ctag, $level) { $source = var_export(substr($this->source, $start, $end - $start), true); $callable = $this->getCallable(); if ($otag !== '{{' || $ctag !== '}}') { $delimTag = var_export(sprintf('{{= %s %s =}}', $otag, $ctag), true); $helper = sprintf('$this->lambdaHelper->withDelimiters(%s)', $delimTag); $delims = ', ' . $delimTag; } else { $helper = '$this->lambdaHelper'; $delims = ''; } $key = ucfirst(md5($delims . "\n" . $source)); if (!isset($this->sections[$key])) { $this->sections[$key] = sprintf($this->prepare(self::SECTION), $key, $callable, $source, $helper, $delims, $this->walk($nodes, 2)); } $method = $this->getFindMethod($id); $id = var_export($id, true); $filters = $this->getFilters($filters, $level); return sprintf($this->prepare(self::SECTION_CALL, $level), $id, $method, $id, $filters, $key); }
php
private function section($nodes, $id, $filters, $start, $end, $otag, $ctag, $level) { $source = var_export(substr($this->source, $start, $end - $start), true); $callable = $this->getCallable(); if ($otag !== '{{' || $ctag !== '}}') { $delimTag = var_export(sprintf('{{= %s %s =}}', $otag, $ctag), true); $helper = sprintf('$this->lambdaHelper->withDelimiters(%s)', $delimTag); $delims = ', ' . $delimTag; } else { $helper = '$this->lambdaHelper'; $delims = ''; } $key = ucfirst(md5($delims . "\n" . $source)); if (!isset($this->sections[$key])) { $this->sections[$key] = sprintf($this->prepare(self::SECTION), $key, $callable, $source, $helper, $delims, $this->walk($nodes, 2)); } $method = $this->getFindMethod($id); $id = var_export($id, true); $filters = $this->getFilters($filters, $level); return sprintf($this->prepare(self::SECTION_CALL, $level), $id, $method, $id, $filters, $key); }
[ "private", "function", "section", "(", "$", "nodes", ",", "$", "id", ",", "$", "filters", ",", "$", "start", ",", "$", "end", ",", "$", "otag", ",", "$", "ctag", ",", "$", "level", ")", "{", "$", "source", "=", "var_export", "(", "substr", "(", "$", "this", "->", "source", ",", "$", "start", ",", "$", "end", "-", "$", "start", ")", ",", "true", ")", ";", "$", "callable", "=", "$", "this", "->", "getCallable", "(", ")", ";", "if", "(", "$", "otag", "!==", "'{{'", "||", "$", "ctag", "!==", "'}}'", ")", "{", "$", "delimTag", "=", "var_export", "(", "sprintf", "(", "'{{= %s %s =}}'", ",", "$", "otag", ",", "$", "ctag", ")", ",", "true", ")", ";", "$", "helper", "=", "sprintf", "(", "'$this->lambdaHelper->withDelimiters(%s)'", ",", "$", "delimTag", ")", ";", "$", "delims", "=", "', '", ".", "$", "delimTag", ";", "}", "else", "{", "$", "helper", "=", "'$this->lambdaHelper'", ";", "$", "delims", "=", "''", ";", "}", "$", "key", "=", "ucfirst", "(", "md5", "(", "$", "delims", ".", "\"\\n\"", ".", "$", "source", ")", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "sections", "[", "$", "key", "]", ")", ")", "{", "$", "this", "->", "sections", "[", "$", "key", "]", "=", "sprintf", "(", "$", "this", "->", "prepare", "(", "self", "::", "SECTION", ")", ",", "$", "key", ",", "$", "callable", ",", "$", "source", ",", "$", "helper", ",", "$", "delims", ",", "$", "this", "->", "walk", "(", "$", "nodes", ",", "2", ")", ")", ";", "}", "$", "method", "=", "$", "this", "->", "getFindMethod", "(", "$", "id", ")", ";", "$", "id", "=", "var_export", "(", "$", "id", ",", "true", ")", ";", "$", "filters", "=", "$", "this", "->", "getFilters", "(", "$", "filters", ",", "$", "level", ")", ";", "return", "sprintf", "(", "$", "this", "->", "prepare", "(", "self", "::", "SECTION_CALL", ",", "$", "level", ")", ",", "$", "id", ",", "$", "method", ",", "$", "id", ",", "$", "filters", ",", "$", "key", ")", ";", "}" ]
Generate Mustache Template section PHP source. @param array $nodes Array of child tokens @param string $id Section name @param string[] $filters Array of filters @param int $start Section start offset @param int $end Section end offset @param string $otag Current Mustache opening tag @param string $ctag Current Mustache closing tag @param int $level @return string Generated section PHP source code
[ "Generate", "Mustache", "Template", "section", "PHP", "source", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Compiler.php#L371-L396
214,359
moodle/moodle
lib/mustache/src/Mustache/Compiler.php
Mustache_Compiler.invertedSection
private function invertedSection($nodes, $id, $filters, $level) { $method = $this->getFindMethod($id); $id = var_export($id, true); $filters = $this->getFilters($filters, $level); return sprintf($this->prepare(self::INVERTED_SECTION, $level), $id, $method, $id, $filters, $this->walk($nodes, $level)); }
php
private function invertedSection($nodes, $id, $filters, $level) { $method = $this->getFindMethod($id); $id = var_export($id, true); $filters = $this->getFilters($filters, $level); return sprintf($this->prepare(self::INVERTED_SECTION, $level), $id, $method, $id, $filters, $this->walk($nodes, $level)); }
[ "private", "function", "invertedSection", "(", "$", "nodes", ",", "$", "id", ",", "$", "filters", ",", "$", "level", ")", "{", "$", "method", "=", "$", "this", "->", "getFindMethod", "(", "$", "id", ")", ";", "$", "id", "=", "var_export", "(", "$", "id", ",", "true", ")", ";", "$", "filters", "=", "$", "this", "->", "getFilters", "(", "$", "filters", ",", "$", "level", ")", ";", "return", "sprintf", "(", "$", "this", "->", "prepare", "(", "self", "::", "INVERTED_SECTION", ",", "$", "level", ")", ",", "$", "id", ",", "$", "method", ",", "$", "id", ",", "$", "filters", ",", "$", "this", "->", "walk", "(", "$", "nodes", ",", "$", "level", ")", ")", ";", "}" ]
Generate Mustache Template inverted section PHP source. @param array $nodes Array of child tokens @param string $id Section name @param string[] $filters Array of filters @param int $level @return string Generated inverted section PHP source code
[ "Generate", "Mustache", "Template", "inverted", "section", "PHP", "source", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Compiler.php#L416-L423
214,360
moodle/moodle
lib/mustache/src/Mustache/Compiler.php
Mustache_Compiler.partial
private function partial($id, $indent, $level) { if ($indent !== '') { $indentParam = sprintf(self::PARTIAL_INDENT, var_export($indent, true)); } else { $indentParam = ''; } return sprintf( $this->prepare(self::PARTIAL, $level), var_export($id, true), $indentParam ); }
php
private function partial($id, $indent, $level) { if ($indent !== '') { $indentParam = sprintf(self::PARTIAL_INDENT, var_export($indent, true)); } else { $indentParam = ''; } return sprintf( $this->prepare(self::PARTIAL, $level), var_export($id, true), $indentParam ); }
[ "private", "function", "partial", "(", "$", "id", ",", "$", "indent", ",", "$", "level", ")", "{", "if", "(", "$", "indent", "!==", "''", ")", "{", "$", "indentParam", "=", "sprintf", "(", "self", "::", "PARTIAL_INDENT", ",", "var_export", "(", "$", "indent", ",", "true", ")", ")", ";", "}", "else", "{", "$", "indentParam", "=", "''", ";", "}", "return", "sprintf", "(", "$", "this", "->", "prepare", "(", "self", "::", "PARTIAL", ",", "$", "level", ")", ",", "var_export", "(", "$", "id", ",", "true", ")", ",", "$", "indentParam", ")", ";", "}" ]
Generate Mustache Template partial call PHP source. @param string $id Partial name @param string $indent Whitespace indent to apply to partial @param int $level @return string Generated partial call PHP source code
[ "Generate", "Mustache", "Template", "partial", "call", "PHP", "source", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Compiler.php#L441-L454
214,361
moodle/moodle
lib/mustache/src/Mustache/Compiler.php
Mustache_Compiler.parent
private function parent($id, $indent, array $children, $level) { $realChildren = array_filter($children, array(__CLASS__, 'onlyBlockArgs')); if (empty($realChildren)) { return sprintf($this->prepare(self::PARENT_NO_CONTEXT, $level), var_export($id, true)); } return sprintf( $this->prepare(self::PARENT, $level), var_export($id, true), $this->walk($realChildren, $level + 1) ); }
php
private function parent($id, $indent, array $children, $level) { $realChildren = array_filter($children, array(__CLASS__, 'onlyBlockArgs')); if (empty($realChildren)) { return sprintf($this->prepare(self::PARENT_NO_CONTEXT, $level), var_export($id, true)); } return sprintf( $this->prepare(self::PARENT, $level), var_export($id, true), $this->walk($realChildren, $level + 1) ); }
[ "private", "function", "parent", "(", "$", "id", ",", "$", "indent", ",", "array", "$", "children", ",", "$", "level", ")", "{", "$", "realChildren", "=", "array_filter", "(", "$", "children", ",", "array", "(", "__CLASS__", ",", "'onlyBlockArgs'", ")", ")", ";", "if", "(", "empty", "(", "$", "realChildren", ")", ")", "{", "return", "sprintf", "(", "$", "this", "->", "prepare", "(", "self", "::", "PARENT_NO_CONTEXT", ",", "$", "level", ")", ",", "var_export", "(", "$", "id", ",", "true", ")", ")", ";", "}", "return", "sprintf", "(", "$", "this", "->", "prepare", "(", "self", "::", "PARENT", ",", "$", "level", ")", ",", "var_export", "(", "$", "id", ",", "true", ")", ",", "$", "this", "->", "walk", "(", "$", "realChildren", ",", "$", "level", "+", "1", ")", ")", ";", "}" ]
Generate Mustache Template inheritance parent call PHP source. @param string $id Parent tag name @param string $indent Whitespace indent to apply to parent @param array $children Child nodes @param int $level @return string Generated PHP source code
[ "Generate", "Mustache", "Template", "inheritance", "parent", "call", "PHP", "source", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Compiler.php#L481-L494
214,362
moodle/moodle
lib/mustache/src/Mustache/Compiler.php
Mustache_Compiler.variable
private function variable($id, $filters, $escape, $level) { $method = $this->getFindMethod($id); $id = ($method !== 'last') ? var_export($id, true) : ''; $filters = $this->getFilters($filters, $level); $value = $escape ? $this->getEscape() : '$value'; return sprintf($this->prepare(self::VARIABLE, $level), $method, $id, $filters, $this->flushIndent(), $value); }
php
private function variable($id, $filters, $escape, $level) { $method = $this->getFindMethod($id); $id = ($method !== 'last') ? var_export($id, true) : ''; $filters = $this->getFilters($filters, $level); $value = $escape ? $this->getEscape() : '$value'; return sprintf($this->prepare(self::VARIABLE, $level), $method, $id, $filters, $this->flushIndent(), $value); }
[ "private", "function", "variable", "(", "$", "id", ",", "$", "filters", ",", "$", "escape", ",", "$", "level", ")", "{", "$", "method", "=", "$", "this", "->", "getFindMethod", "(", "$", "id", ")", ";", "$", "id", "=", "(", "$", "method", "!==", "'last'", ")", "?", "var_export", "(", "$", "id", ",", "true", ")", ":", "''", ";", "$", "filters", "=", "$", "this", "->", "getFilters", "(", "$", "filters", ",", "$", "level", ")", ";", "$", "value", "=", "$", "escape", "?", "$", "this", "->", "getEscape", "(", ")", ":", "'$value'", ";", "return", "sprintf", "(", "$", "this", "->", "prepare", "(", "self", "::", "VARIABLE", ",", "$", "level", ")", ",", "$", "method", ",", "$", "id", ",", "$", "filters", ",", "$", "this", "->", "flushIndent", "(", ")", ",", "$", "value", ")", ";", "}" ]
Generate Mustache Template variable interpolation PHP source. @param string $id Variable name @param string[] $filters Array of filters @param bool $escape Escape the variable value for output? @param int $level @return string Generated variable interpolation PHP source
[ "Generate", "Mustache", "Template", "variable", "interpolation", "PHP", "source", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Compiler.php#L523-L531
214,363
moodle/moodle
lib/mustache/src/Mustache/Compiler.php
Mustache_Compiler.getFilters
private function getFilters(array $filters, $level) { if (empty($filters)) { return ''; } $name = array_shift($filters); $method = $this->getFindMethod($name); $filter = ($method !== 'last') ? var_export($name, true) : ''; $callable = $this->getCallable('$filter'); $msg = var_export($name, true); return sprintf($this->prepare(self::FILTER, $level), $method, $filter, $callable, $msg, $this->getFilters($filters, $level)); }
php
private function getFilters(array $filters, $level) { if (empty($filters)) { return ''; } $name = array_shift($filters); $method = $this->getFindMethod($name); $filter = ($method !== 'last') ? var_export($name, true) : ''; $callable = $this->getCallable('$filter'); $msg = var_export($name, true); return sprintf($this->prepare(self::FILTER, $level), $method, $filter, $callable, $msg, $this->getFilters($filters, $level)); }
[ "private", "function", "getFilters", "(", "array", "$", "filters", ",", "$", "level", ")", "{", "if", "(", "empty", "(", "$", "filters", ")", ")", "{", "return", "''", ";", "}", "$", "name", "=", "array_shift", "(", "$", "filters", ")", ";", "$", "method", "=", "$", "this", "->", "getFindMethod", "(", "$", "name", ")", ";", "$", "filter", "=", "(", "$", "method", "!==", "'last'", ")", "?", "var_export", "(", "$", "name", ",", "true", ")", ":", "''", ";", "$", "callable", "=", "$", "this", "->", "getCallable", "(", "'$filter'", ")", ";", "$", "msg", "=", "var_export", "(", "$", "name", ",", "true", ")", ";", "return", "sprintf", "(", "$", "this", "->", "prepare", "(", "self", "::", "FILTER", ",", "$", "level", ")", ",", "$", "method", ",", "$", "filter", ",", "$", "callable", ",", "$", "msg", ",", "$", "this", "->", "getFilters", "(", "$", "filters", ",", "$", "level", ")", ")", ";", "}" ]
Generate Mustache Template variable filtering PHP source. @param string[] $filters Array of filters @param int $level @return string Generated filter PHP source
[ "Generate", "Mustache", "Template", "variable", "filtering", "PHP", "source", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Compiler.php#L549-L562
214,364
moodle/moodle
lib/mustache/src/Mustache/Compiler.php
Mustache_Compiler.text
private function text($text, $level) { $indentNextLine = (substr($text, -1) === "\n"); $code = sprintf($this->prepare(self::TEXT, $level), $this->flushIndent(), var_export($text, true)); $this->indentNextLine = $indentNextLine; return $code; }
php
private function text($text, $level) { $indentNextLine = (substr($text, -1) === "\n"); $code = sprintf($this->prepare(self::TEXT, $level), $this->flushIndent(), var_export($text, true)); $this->indentNextLine = $indentNextLine; return $code; }
[ "private", "function", "text", "(", "$", "text", ",", "$", "level", ")", "{", "$", "indentNextLine", "=", "(", "substr", "(", "$", "text", ",", "-", "1", ")", "===", "\"\\n\"", ")", ";", "$", "code", "=", "sprintf", "(", "$", "this", "->", "prepare", "(", "self", "::", "TEXT", ",", "$", "level", ")", ",", "$", "this", "->", "flushIndent", "(", ")", ",", "var_export", "(", "$", "text", ",", "true", ")", ")", ";", "$", "this", "->", "indentNextLine", "=", "$", "indentNextLine", ";", "return", "$", "code", ";", "}" ]
Generate Mustache Template output Buffer call PHP source. @param string $text @param int $level @return string Generated output Buffer call PHP source
[ "Generate", "Mustache", "Template", "output", "Buffer", "call", "PHP", "source", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Compiler.php#L575-L582
214,365
moodle/moodle
lib/mustache/src/Mustache/Compiler.php
Mustache_Compiler.prepare
private function prepare($text, $bonus = 0, $prependNewline = true, $appendNewline = false) { $text = ($prependNewline ? "\n" : '') . trim($text); if ($prependNewline) { $bonus++; } if ($appendNewline) { $text .= "\n"; } return preg_replace("/\n( {8})?/", "\n" . str_repeat(' ', $bonus * 4), $text); }
php
private function prepare($text, $bonus = 0, $prependNewline = true, $appendNewline = false) { $text = ($prependNewline ? "\n" : '') . trim($text); if ($prependNewline) { $bonus++; } if ($appendNewline) { $text .= "\n"; } return preg_replace("/\n( {8})?/", "\n" . str_repeat(' ', $bonus * 4), $text); }
[ "private", "function", "prepare", "(", "$", "text", ",", "$", "bonus", "=", "0", ",", "$", "prependNewline", "=", "true", ",", "$", "appendNewline", "=", "false", ")", "{", "$", "text", "=", "(", "$", "prependNewline", "?", "\"\\n\"", ":", "''", ")", ".", "trim", "(", "$", "text", ")", ";", "if", "(", "$", "prependNewline", ")", "{", "$", "bonus", "++", ";", "}", "if", "(", "$", "appendNewline", ")", "{", "$", "text", ".=", "\"\\n\"", ";", "}", "return", "preg_replace", "(", "\"/\\n( {8})?/\"", ",", "\"\\n\"", ".", "str_repeat", "(", "' '", ",", "$", "bonus", "*", "4", ")", ",", "$", "text", ")", ";", "}" ]
Prepare PHP source code snippet for output. @param string $text @param int $bonus Additional indent level (default: 0) @param bool $prependNewline Prepend a newline to the snippet? (default: true) @param bool $appendNewline Append a newline to the snippet? (default: false) @return string PHP source code snippet
[ "Prepare", "PHP", "source", "code", "snippet", "for", "output", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Compiler.php#L594-L605
214,366
moodle/moodle
lib/mustache/src/Mustache/Compiler.php
Mustache_Compiler.getEscape
private function getEscape($value = '$value') { if ($this->customEscape) { return sprintf(self::CUSTOM_ESCAPE, $value); } return sprintf(self::DEFAULT_ESCAPE, $value, var_export($this->entityFlags, true), var_export($this->charset, true)); }
php
private function getEscape($value = '$value') { if ($this->customEscape) { return sprintf(self::CUSTOM_ESCAPE, $value); } return sprintf(self::DEFAULT_ESCAPE, $value, var_export($this->entityFlags, true), var_export($this->charset, true)); }
[ "private", "function", "getEscape", "(", "$", "value", "=", "'$value'", ")", "{", "if", "(", "$", "this", "->", "customEscape", ")", "{", "return", "sprintf", "(", "self", "::", "CUSTOM_ESCAPE", ",", "$", "value", ")", ";", "}", "return", "sprintf", "(", "self", "::", "DEFAULT_ESCAPE", ",", "$", "value", ",", "var_export", "(", "$", "this", "->", "entityFlags", ",", "true", ")", ",", "var_export", "(", "$", "this", "->", "charset", ",", "true", ")", ")", ";", "}" ]
Get the current escaper. @param string $value (default: '$value') @return string Either a custom callback, or an inline call to `htmlspecialchars`
[ "Get", "the", "current", "escaper", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Compiler.php#L617-L624
214,367
moodle/moodle
lib/mustache/src/Mustache/Compiler.php
Mustache_Compiler.getCallable
private function getCallable($variable = '$value') { $tpl = $this->strictCallables ? self::STRICT_IS_CALLABLE : self::IS_CALLABLE; return sprintf($tpl, $variable, $variable); }
php
private function getCallable($variable = '$value') { $tpl = $this->strictCallables ? self::STRICT_IS_CALLABLE : self::IS_CALLABLE; return sprintf($tpl, $variable, $variable); }
[ "private", "function", "getCallable", "(", "$", "variable", "=", "'$value'", ")", "{", "$", "tpl", "=", "$", "this", "->", "strictCallables", "?", "self", "::", "STRICT_IS_CALLABLE", ":", "self", "::", "IS_CALLABLE", ";", "return", "sprintf", "(", "$", "tpl", ",", "$", "variable", ",", "$", "variable", ")", ";", "}" ]
Helper function to compile strict vs lax "is callable" logic. @param string $variable (default: '$value') @return string "is callable" logic
[ "Helper", "function", "to", "compile", "strict", "vs", "lax", "is", "callable", "logic", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Compiler.php#L668-L673
214,368
moodle/moodle
admin/tool/mobile/classes/external.php
external.get_config
public static function get_config($section = '') { $params = self::validate_parameters(self::get_config_parameters(), array('section' => $section)); $settings = api::get_config($params['section']); $result['settings'] = array(); foreach ($settings as $name => $value) { $result['settings'][] = array( 'name' => $name, 'value' => $value, ); } $result['warnings'] = array(); return $result; }
php
public static function get_config($section = '') { $params = self::validate_parameters(self::get_config_parameters(), array('section' => $section)); $settings = api::get_config($params['section']); $result['settings'] = array(); foreach ($settings as $name => $value) { $result['settings'][] = array( 'name' => $name, 'value' => $value, ); } $result['warnings'] = array(); return $result; }
[ "public", "static", "function", "get_config", "(", "$", "section", "=", "''", ")", "{", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_config_parameters", "(", ")", ",", "array", "(", "'section'", "=>", "$", "section", ")", ")", ";", "$", "settings", "=", "api", "::", "get_config", "(", "$", "params", "[", "'section'", "]", ")", ";", "$", "result", "[", "'settings'", "]", "=", "array", "(", ")", ";", "foreach", "(", "$", "settings", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "result", "[", "'settings'", "]", "[", "]", "=", "array", "(", "'name'", "=>", "$", "name", ",", "'value'", "=>", "$", "value", ",", ")", ";", "}", "$", "result", "[", "'warnings'", "]", "=", "array", "(", ")", ";", "return", "$", "result", ";", "}" ]
Returns a list of site settings, filtering by section. @param string $section settings section name @return array with the settings and warnings @since Moodle 3.2
[ "Returns", "a", "list", "of", "site", "settings", "filtering", "by", "section", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/mobile/classes/external.php#L208-L223
214,369
moodle/moodle
admin/tool/mobile/classes/external.php
external.get_autologin_key
public static function get_autologin_key($privatetoken) { global $CFG, $DB, $USER; $params = self::validate_parameters(self::get_autologin_key_parameters(), array('privatetoken' => $privatetoken)); $privatetoken = $params['privatetoken']; $context = context_system::instance(); // We must toletare these two exceptions: forcepasswordchangenotice and usernotfullysetup. try { self::validate_context($context); } catch (moodle_exception $e) { if ($e->errorcode != 'usernotfullysetup' && $e->errorcode != 'forcepasswordchangenotice') { // In case we receive a different exception, throw it. throw $e; } } // Only requests from the Moodle mobile or desktop app. This enhances security to avoid any type of XSS attack. // This code goes intentionally here and not inside the check_autologin_prerequisites() function because it // is used by other PHP scripts that can be opened in any browser. if (!\core_useragent::is_moodle_app()) { throw new moodle_exception('apprequired', 'tool_mobile'); } api::check_autologin_prerequisites($USER->id); if (isset($_GET['privatetoken']) or empty($privatetoken)) { throw new moodle_exception('invalidprivatetoken', 'tool_mobile'); } // Check the request counter, we must limit the number of times the privatetoken is sent. // Between each request 6 minutes are required. $last = get_user_preferences('tool_mobile_autologin_request_last', 0, $USER); // Check if we must reset the count. $timenow = time(); if ($timenow - $last < 6 * MINSECS) { throw new moodle_exception('autologinkeygenerationlockout', 'tool_mobile'); } set_user_preference('tool_mobile_autologin_request_last', $timenow, $USER); // We are expecting a privatetoken linked to the current token being used. // This WS is only valid when using mobile services via REST (this is intended). $currenttoken = required_param('wstoken', PARAM_ALPHANUM); $conditions = array( 'userid' => $USER->id, 'token' => $currenttoken, 'privatetoken' => $privatetoken, ); if (!$token = $DB->get_record('external_tokens', $conditions)) { throw new moodle_exception('invalidprivatetoken', 'tool_mobile'); } $result = array(); $result['key'] = api::get_autologin_key(); $autologinurl = new moodle_url("/$CFG->admin/tool/mobile/autologin.php"); $result['autologinurl'] = $autologinurl->out(false); $result['warnings'] = array(); return $result; }
php
public static function get_autologin_key($privatetoken) { global $CFG, $DB, $USER; $params = self::validate_parameters(self::get_autologin_key_parameters(), array('privatetoken' => $privatetoken)); $privatetoken = $params['privatetoken']; $context = context_system::instance(); // We must toletare these two exceptions: forcepasswordchangenotice and usernotfullysetup. try { self::validate_context($context); } catch (moodle_exception $e) { if ($e->errorcode != 'usernotfullysetup' && $e->errorcode != 'forcepasswordchangenotice') { // In case we receive a different exception, throw it. throw $e; } } // Only requests from the Moodle mobile or desktop app. This enhances security to avoid any type of XSS attack. // This code goes intentionally here and not inside the check_autologin_prerequisites() function because it // is used by other PHP scripts that can be opened in any browser. if (!\core_useragent::is_moodle_app()) { throw new moodle_exception('apprequired', 'tool_mobile'); } api::check_autologin_prerequisites($USER->id); if (isset($_GET['privatetoken']) or empty($privatetoken)) { throw new moodle_exception('invalidprivatetoken', 'tool_mobile'); } // Check the request counter, we must limit the number of times the privatetoken is sent. // Between each request 6 minutes are required. $last = get_user_preferences('tool_mobile_autologin_request_last', 0, $USER); // Check if we must reset the count. $timenow = time(); if ($timenow - $last < 6 * MINSECS) { throw new moodle_exception('autologinkeygenerationlockout', 'tool_mobile'); } set_user_preference('tool_mobile_autologin_request_last', $timenow, $USER); // We are expecting a privatetoken linked to the current token being used. // This WS is only valid when using mobile services via REST (this is intended). $currenttoken = required_param('wstoken', PARAM_ALPHANUM); $conditions = array( 'userid' => $USER->id, 'token' => $currenttoken, 'privatetoken' => $privatetoken, ); if (!$token = $DB->get_record('external_tokens', $conditions)) { throw new moodle_exception('invalidprivatetoken', 'tool_mobile'); } $result = array(); $result['key'] = api::get_autologin_key(); $autologinurl = new moodle_url("/$CFG->admin/tool/mobile/autologin.php"); $result['autologinurl'] = $autologinurl->out(false); $result['warnings'] = array(); return $result; }
[ "public", "static", "function", "get_autologin_key", "(", "$", "privatetoken", ")", "{", "global", "$", "CFG", ",", "$", "DB", ",", "$", "USER", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_autologin_key_parameters", "(", ")", ",", "array", "(", "'privatetoken'", "=>", "$", "privatetoken", ")", ")", ";", "$", "privatetoken", "=", "$", "params", "[", "'privatetoken'", "]", ";", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "// We must toletare these two exceptions: forcepasswordchangenotice and usernotfullysetup.", "try", "{", "self", "::", "validate_context", "(", "$", "context", ")", ";", "}", "catch", "(", "moodle_exception", "$", "e", ")", "{", "if", "(", "$", "e", "->", "errorcode", "!=", "'usernotfullysetup'", "&&", "$", "e", "->", "errorcode", "!=", "'forcepasswordchangenotice'", ")", "{", "// In case we receive a different exception, throw it.", "throw", "$", "e", ";", "}", "}", "// Only requests from the Moodle mobile or desktop app. This enhances security to avoid any type of XSS attack.", "// This code goes intentionally here and not inside the check_autologin_prerequisites() function because it", "// is used by other PHP scripts that can be opened in any browser.", "if", "(", "!", "\\", "core_useragent", "::", "is_moodle_app", "(", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'apprequired'", ",", "'tool_mobile'", ")", ";", "}", "api", "::", "check_autologin_prerequisites", "(", "$", "USER", "->", "id", ")", ";", "if", "(", "isset", "(", "$", "_GET", "[", "'privatetoken'", "]", ")", "or", "empty", "(", "$", "privatetoken", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'invalidprivatetoken'", ",", "'tool_mobile'", ")", ";", "}", "// Check the request counter, we must limit the number of times the privatetoken is sent.", "// Between each request 6 minutes are required.", "$", "last", "=", "get_user_preferences", "(", "'tool_mobile_autologin_request_last'", ",", "0", ",", "$", "USER", ")", ";", "// Check if we must reset the count.", "$", "timenow", "=", "time", "(", ")", ";", "if", "(", "$", "timenow", "-", "$", "last", "<", "6", "*", "MINSECS", ")", "{", "throw", "new", "moodle_exception", "(", "'autologinkeygenerationlockout'", ",", "'tool_mobile'", ")", ";", "}", "set_user_preference", "(", "'tool_mobile_autologin_request_last'", ",", "$", "timenow", ",", "$", "USER", ")", ";", "// We are expecting a privatetoken linked to the current token being used.", "// This WS is only valid when using mobile services via REST (this is intended).", "$", "currenttoken", "=", "required_param", "(", "'wstoken'", ",", "PARAM_ALPHANUM", ")", ";", "$", "conditions", "=", "array", "(", "'userid'", "=>", "$", "USER", "->", "id", ",", "'token'", "=>", "$", "currenttoken", ",", "'privatetoken'", "=>", "$", "privatetoken", ",", ")", ";", "if", "(", "!", "$", "token", "=", "$", "DB", "->", "get_record", "(", "'external_tokens'", ",", "$", "conditions", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'invalidprivatetoken'", ",", "'tool_mobile'", ")", ";", "}", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'key'", "]", "=", "api", "::", "get_autologin_key", "(", ")", ";", "$", "autologinurl", "=", "new", "moodle_url", "(", "\"/$CFG->admin/tool/mobile/autologin.php\"", ")", ";", "$", "result", "[", "'autologinurl'", "]", "=", "$", "autologinurl", "->", "out", "(", "false", ")", ";", "$", "result", "[", "'warnings'", "]", "=", "array", "(", ")", ";", "return", "$", "result", ";", "}" ]
Creates an auto-login key for the current user. Is created only in https sites and is restricted by time and ip address. Please note that it only works if the request comes from the Moodle mobile or desktop app. @param string $privatetoken the user private token for validating the request @return array with the settings and warnings @since Moodle 3.2
[ "Creates", "an", "auto", "-", "login", "key", "for", "the", "current", "user", ".", "Is", "created", "only", "in", "https", "sites", "and", "is", "restricted", "by", "time", "and", "ip", "address", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/mobile/classes/external.php#L271-L329
214,370
moodle/moodle
admin/tool/mobile/classes/external.php
external.get_content
public static function get_content($component, $method, $args = array()) { global $OUTPUT, $PAGE, $USER; $params = self::validate_parameters(self::get_content_parameters(), array( 'component' => $component, 'method' => $method, 'args' => $args ) ); // Reformat arguments into something less unwieldy. $arguments = array(); foreach ($params['args'] as $paramargument) { $arguments[$paramargument['name']] = $paramargument['value']; } // The component was validated via the PARAM_COMPONENT parameter type. $classname = '\\' . $params['component'] .'\output\mobile'; if (!method_exists($classname, $params['method'])) { throw new coding_exception("Missing method in $classname"); } $result = call_user_func_array(array($classname, $params['method']), array($arguments)); // Populate otherdata. $otherdata = array(); if (!empty($result['otherdata'])) { $result['otherdata'] = (array) $result['otherdata']; foreach ($result['otherdata'] as $name => $value) { $otherdata[] = array( 'name' => $name, 'value' => $value ); } } return array( 'templates' => !empty($result['templates']) ? $result['templates'] : array(), 'javascript' => !empty($result['javascript']) ? $result['javascript'] : '', 'otherdata' => $otherdata, 'files' => !empty($result['files']) ? $result['files'] : array(), 'restrict' => !empty($result['restrict']) ? $result['restrict'] : array(), ); }
php
public static function get_content($component, $method, $args = array()) { global $OUTPUT, $PAGE, $USER; $params = self::validate_parameters(self::get_content_parameters(), array( 'component' => $component, 'method' => $method, 'args' => $args ) ); // Reformat arguments into something less unwieldy. $arguments = array(); foreach ($params['args'] as $paramargument) { $arguments[$paramargument['name']] = $paramargument['value']; } // The component was validated via the PARAM_COMPONENT parameter type. $classname = '\\' . $params['component'] .'\output\mobile'; if (!method_exists($classname, $params['method'])) { throw new coding_exception("Missing method in $classname"); } $result = call_user_func_array(array($classname, $params['method']), array($arguments)); // Populate otherdata. $otherdata = array(); if (!empty($result['otherdata'])) { $result['otherdata'] = (array) $result['otherdata']; foreach ($result['otherdata'] as $name => $value) { $otherdata[] = array( 'name' => $name, 'value' => $value ); } } return array( 'templates' => !empty($result['templates']) ? $result['templates'] : array(), 'javascript' => !empty($result['javascript']) ? $result['javascript'] : '', 'otherdata' => $otherdata, 'files' => !empty($result['files']) ? $result['files'] : array(), 'restrict' => !empty($result['restrict']) ? $result['restrict'] : array(), ); }
[ "public", "static", "function", "get_content", "(", "$", "component", ",", "$", "method", ",", "$", "args", "=", "array", "(", ")", ")", "{", "global", "$", "OUTPUT", ",", "$", "PAGE", ",", "$", "USER", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_content_parameters", "(", ")", ",", "array", "(", "'component'", "=>", "$", "component", ",", "'method'", "=>", "$", "method", ",", "'args'", "=>", "$", "args", ")", ")", ";", "// Reformat arguments into something less unwieldy.", "$", "arguments", "=", "array", "(", ")", ";", "foreach", "(", "$", "params", "[", "'args'", "]", "as", "$", "paramargument", ")", "{", "$", "arguments", "[", "$", "paramargument", "[", "'name'", "]", "]", "=", "$", "paramargument", "[", "'value'", "]", ";", "}", "// The component was validated via the PARAM_COMPONENT parameter type.", "$", "classname", "=", "'\\\\'", ".", "$", "params", "[", "'component'", "]", ".", "'\\output\\mobile'", ";", "if", "(", "!", "method_exists", "(", "$", "classname", ",", "$", "params", "[", "'method'", "]", ")", ")", "{", "throw", "new", "coding_exception", "(", "\"Missing method in $classname\"", ")", ";", "}", "$", "result", "=", "call_user_func_array", "(", "array", "(", "$", "classname", ",", "$", "params", "[", "'method'", "]", ")", ",", "array", "(", "$", "arguments", ")", ")", ";", "// Populate otherdata.", "$", "otherdata", "=", "array", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "result", "[", "'otherdata'", "]", ")", ")", "{", "$", "result", "[", "'otherdata'", "]", "=", "(", "array", ")", "$", "result", "[", "'otherdata'", "]", ";", "foreach", "(", "$", "result", "[", "'otherdata'", "]", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "otherdata", "[", "]", "=", "array", "(", "'name'", "=>", "$", "name", ",", "'value'", "=>", "$", "value", ")", ";", "}", "}", "return", "array", "(", "'templates'", "=>", "!", "empty", "(", "$", "result", "[", "'templates'", "]", ")", "?", "$", "result", "[", "'templates'", "]", ":", "array", "(", ")", ",", "'javascript'", "=>", "!", "empty", "(", "$", "result", "[", "'javascript'", "]", ")", "?", "$", "result", "[", "'javascript'", "]", ":", "''", ",", "'otherdata'", "=>", "$", "otherdata", ",", "'files'", "=>", "!", "empty", "(", "$", "result", "[", "'files'", "]", ")", "?", "$", "result", "[", "'files'", "]", ":", "array", "(", ")", ",", "'restrict'", "=>", "!", "empty", "(", "$", "result", "[", "'restrict'", "]", ")", "?", "$", "result", "[", "'restrict'", "]", ":", "array", "(", ")", ",", ")", ";", "}" ]
Returns a piece of content to be displayed in the Mobile app, it usually returns a template, javascript and other structured data that will be used to render a view in the Mobile app.. Callbacks (placed in \$component\output\mobile) that are called by this web service are responsible for doing the appropriate security checks to access the information to be returned. @param string $component fame of the component. @param string $method function method name in class \$component\output\mobile. @param array $args optional arguments for the method. @return array HTML, JavaScript and other required data and information to create a view in the app. @since Moodle 3.5 @throws coding_exception
[ "Returns", "a", "piece", "of", "content", "to", "be", "displayed", "in", "the", "Mobile", "app", "it", "usually", "returns", "a", "template", "javascript", "and", "other", "structured", "data", "that", "will", "be", "used", "to", "render", "a", "view", "in", "the", "Mobile", "app", ".." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/mobile/classes/external.php#L384-L427
214,371
moodle/moodle
admin/tool/mobile/classes/external.php
external.call_external_functions
public static function call_external_functions($requests) { global $SESSION; $params = self::validate_parameters(self::call_external_functions_parameters(), ['requests' => $requests]); // We need to check if the functions being called are included in the service of the current token. // This function only works when using mobile services via REST (this is intended). $webservicemanager = new \webservice; $token = $webservicemanager->get_user_ws_token(required_param('wstoken', PARAM_ALPHANUM)); $settings = \external_settings::get_instance(); $defaultlang = current_language(); $responses = []; foreach ($params['requests'] as $request) { // Some external functions modify _GET or $_POST data, we need to restore the original data after each call. $originalget = fullclone($_GET); $originalpost = fullclone($_POST); // Set external settings and language. $settings->set_raw($request['settingraw']); $settings->set_filter($request['settingfilter']); $settings->set_fileurl($request['settingfileurl']); $settings->set_lang($request['settinglang']); $SESSION->lang = $request['settinglang'] ?: $defaultlang; // Parse arguments to an array, validation is done in external_api::call_external_function. $args = @json_decode($request['arguments'], true); if (!is_array($args)) { $args = []; } if ($webservicemanager->service_function_exists($request['function'], $token->externalserviceid)) { $response = external_api::call_external_function($request['function'], $args, false); } else { // Function not included in the service, return an access exception. $response = [ 'error' => true, 'exception' => [ 'errorcode' => 'accessexception', 'module' => 'webservice' ] ]; if (debugging('', DEBUG_DEVELOPER)) { $response['exception']['debuginfo'] = 'Access to the function is not allowed.'; } } if (isset($response['data'])) { $response['data'] = json_encode($response['data']); } if (isset($response['exception'])) { $response['exception'] = json_encode($response['exception']); } $responses[] = $response; // Restore original $_GET and $_POST. $_GET = $originalget; $_POST = $originalpost; if ($response['error']) { // Do not process the remaining requests. break; } } return ['responses' => $responses]; }
php
public static function call_external_functions($requests) { global $SESSION; $params = self::validate_parameters(self::call_external_functions_parameters(), ['requests' => $requests]); // We need to check if the functions being called are included in the service of the current token. // This function only works when using mobile services via REST (this is intended). $webservicemanager = new \webservice; $token = $webservicemanager->get_user_ws_token(required_param('wstoken', PARAM_ALPHANUM)); $settings = \external_settings::get_instance(); $defaultlang = current_language(); $responses = []; foreach ($params['requests'] as $request) { // Some external functions modify _GET or $_POST data, we need to restore the original data after each call. $originalget = fullclone($_GET); $originalpost = fullclone($_POST); // Set external settings and language. $settings->set_raw($request['settingraw']); $settings->set_filter($request['settingfilter']); $settings->set_fileurl($request['settingfileurl']); $settings->set_lang($request['settinglang']); $SESSION->lang = $request['settinglang'] ?: $defaultlang; // Parse arguments to an array, validation is done in external_api::call_external_function. $args = @json_decode($request['arguments'], true); if (!is_array($args)) { $args = []; } if ($webservicemanager->service_function_exists($request['function'], $token->externalserviceid)) { $response = external_api::call_external_function($request['function'], $args, false); } else { // Function not included in the service, return an access exception. $response = [ 'error' => true, 'exception' => [ 'errorcode' => 'accessexception', 'module' => 'webservice' ] ]; if (debugging('', DEBUG_DEVELOPER)) { $response['exception']['debuginfo'] = 'Access to the function is not allowed.'; } } if (isset($response['data'])) { $response['data'] = json_encode($response['data']); } if (isset($response['exception'])) { $response['exception'] = json_encode($response['exception']); } $responses[] = $response; // Restore original $_GET and $_POST. $_GET = $originalget; $_POST = $originalpost; if ($response['error']) { // Do not process the remaining requests. break; } } return ['responses' => $responses]; }
[ "public", "static", "function", "call_external_functions", "(", "$", "requests", ")", "{", "global", "$", "SESSION", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "call_external_functions_parameters", "(", ")", ",", "[", "'requests'", "=>", "$", "requests", "]", ")", ";", "// We need to check if the functions being called are included in the service of the current token.", "// This function only works when using mobile services via REST (this is intended).", "$", "webservicemanager", "=", "new", "\\", "webservice", ";", "$", "token", "=", "$", "webservicemanager", "->", "get_user_ws_token", "(", "required_param", "(", "'wstoken'", ",", "PARAM_ALPHANUM", ")", ")", ";", "$", "settings", "=", "\\", "external_settings", "::", "get_instance", "(", ")", ";", "$", "defaultlang", "=", "current_language", "(", ")", ";", "$", "responses", "=", "[", "]", ";", "foreach", "(", "$", "params", "[", "'requests'", "]", "as", "$", "request", ")", "{", "// Some external functions modify _GET or $_POST data, we need to restore the original data after each call.", "$", "originalget", "=", "fullclone", "(", "$", "_GET", ")", ";", "$", "originalpost", "=", "fullclone", "(", "$", "_POST", ")", ";", "// Set external settings and language.", "$", "settings", "->", "set_raw", "(", "$", "request", "[", "'settingraw'", "]", ")", ";", "$", "settings", "->", "set_filter", "(", "$", "request", "[", "'settingfilter'", "]", ")", ";", "$", "settings", "->", "set_fileurl", "(", "$", "request", "[", "'settingfileurl'", "]", ")", ";", "$", "settings", "->", "set_lang", "(", "$", "request", "[", "'settinglang'", "]", ")", ";", "$", "SESSION", "->", "lang", "=", "$", "request", "[", "'settinglang'", "]", "?", ":", "$", "defaultlang", ";", "// Parse arguments to an array, validation is done in external_api::call_external_function.", "$", "args", "=", "@", "json_decode", "(", "$", "request", "[", "'arguments'", "]", ",", "true", ")", ";", "if", "(", "!", "is_array", "(", "$", "args", ")", ")", "{", "$", "args", "=", "[", "]", ";", "}", "if", "(", "$", "webservicemanager", "->", "service_function_exists", "(", "$", "request", "[", "'function'", "]", ",", "$", "token", "->", "externalserviceid", ")", ")", "{", "$", "response", "=", "external_api", "::", "call_external_function", "(", "$", "request", "[", "'function'", "]", ",", "$", "args", ",", "false", ")", ";", "}", "else", "{", "// Function not included in the service, return an access exception.", "$", "response", "=", "[", "'error'", "=>", "true", ",", "'exception'", "=>", "[", "'errorcode'", "=>", "'accessexception'", ",", "'module'", "=>", "'webservice'", "]", "]", ";", "if", "(", "debugging", "(", "''", ",", "DEBUG_DEVELOPER", ")", ")", "{", "$", "response", "[", "'exception'", "]", "[", "'debuginfo'", "]", "=", "'Access to the function is not allowed.'", ";", "}", "}", "if", "(", "isset", "(", "$", "response", "[", "'data'", "]", ")", ")", "{", "$", "response", "[", "'data'", "]", "=", "json_encode", "(", "$", "response", "[", "'data'", "]", ")", ";", "}", "if", "(", "isset", "(", "$", "response", "[", "'exception'", "]", ")", ")", "{", "$", "response", "[", "'exception'", "]", "=", "json_encode", "(", "$", "response", "[", "'exception'", "]", ")", ";", "}", "$", "responses", "[", "]", "=", "$", "response", ";", "// Restore original $_GET and $_POST.", "$", "_GET", "=", "$", "originalget", ";", "$", "_POST", "=", "$", "originalpost", ";", "if", "(", "$", "response", "[", "'error'", "]", ")", "{", "// Do not process the remaining requests.", "break", ";", "}", "}", "return", "[", "'responses'", "=>", "$", "responses", "]", ";", "}" ]
Call multiple external functions and return all responses. @param array $requests List of requests. @return array Responses. @since Moodle 3.7
[ "Call", "multiple", "external", "functions", "and", "return", "all", "responses", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/mobile/classes/external.php#L501-L568
214,372
moodle/moodle
mod/quiz/report/default.php
quiz_default_report.get_current_group
public function get_current_group($cm, $course, $context) { $groupmode = groups_get_activity_groupmode($cm, $course); $currentgroup = groups_get_activity_group($cm, true); if ($groupmode == SEPARATEGROUPS && !$currentgroup && !has_capability('moodle/site:accessallgroups', $context)) { $currentgroup = self::NO_GROUPS_ALLOWED; } return $currentgroup; }
php
public function get_current_group($cm, $course, $context) { $groupmode = groups_get_activity_groupmode($cm, $course); $currentgroup = groups_get_activity_group($cm, true); if ($groupmode == SEPARATEGROUPS && !$currentgroup && !has_capability('moodle/site:accessallgroups', $context)) { $currentgroup = self::NO_GROUPS_ALLOWED; } return $currentgroup; }
[ "public", "function", "get_current_group", "(", "$", "cm", ",", "$", "course", ",", "$", "context", ")", "{", "$", "groupmode", "=", "groups_get_activity_groupmode", "(", "$", "cm", ",", "$", "course", ")", ";", "$", "currentgroup", "=", "groups_get_activity_group", "(", "$", "cm", ",", "true", ")", ";", "if", "(", "$", "groupmode", "==", "SEPARATEGROUPS", "&&", "!", "$", "currentgroup", "&&", "!", "has_capability", "(", "'moodle/site:accessallgroups'", ",", "$", "context", ")", ")", "{", "$", "currentgroup", "=", "self", "::", "NO_GROUPS_ALLOWED", ";", "}", "return", "$", "currentgroup", ";", "}" ]
Get the current group for the user user looking at the report. @param object $cm the course_module information. @param object $coures the course settings. @param context $context the quiz context. @return int the current group id, if applicable. 0 for all users, NO_GROUPS_ALLOWED if the user cannot see any group.
[ "Get", "the", "current", "group", "for", "the", "user", "user", "looking", "at", "the", "report", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/report/default.php#L83-L92
214,373
moodle/moodle
grade/import/csv/classes/output/renderer.php
gradeimport_csv_renderer.standard_upload_file_form
public function standard_upload_file_form($course, $mform) { $output = groups_print_course_menu($course, 'index.php?id=' . $course->id, true); $output .= html_writer::start_tag('div', array('class' => 'clearer')); $output .= html_writer::end_tag('div'); // Form. ob_start(); $mform->display(); $output .= ob_get_contents(); ob_end_clean(); return $output; }
php
public function standard_upload_file_form($course, $mform) { $output = groups_print_course_menu($course, 'index.php?id=' . $course->id, true); $output .= html_writer::start_tag('div', array('class' => 'clearer')); $output .= html_writer::end_tag('div'); // Form. ob_start(); $mform->display(); $output .= ob_get_contents(); ob_end_clean(); return $output; }
[ "public", "function", "standard_upload_file_form", "(", "$", "course", ",", "$", "mform", ")", "{", "$", "output", "=", "groups_print_course_menu", "(", "$", "course", ",", "'index.php?id='", ".", "$", "course", "->", "id", ",", "true", ")", ";", "$", "output", ".=", "html_writer", "::", "start_tag", "(", "'div'", ",", "array", "(", "'class'", "=>", "'clearer'", ")", ")", ";", "$", "output", ".=", "html_writer", "::", "end_tag", "(", "'div'", ")", ";", "// Form.", "ob_start", "(", ")", ";", "$", "mform", "->", "display", "(", ")", ";", "$", "output", ".=", "ob_get_contents", "(", ")", ";", "ob_end_clean", "(", ")", ";", "return", "$", "output", ";", "}" ]
A renderer for the standard upload file form. @param object $course The course we are doing all of this action in. @param object $mform The mform for uploading CSV files. @return string html to be displayed.
[ "A", "renderer", "for", "the", "standard", "upload", "file", "form", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/import/csv/classes/output/renderer.php#L43-L56
214,374
moodle/moodle
grade/import/csv/classes/output/renderer.php
gradeimport_csv_renderer.import_preview_page
public function import_preview_page($header, $data) { $html = $this->output->heading(get_string('importpreview', 'grades')); $table = new html_table(); $table->head = $header; $table->data = $data; $html .= html_writer::table($table); return $html; }
php
public function import_preview_page($header, $data) { $html = $this->output->heading(get_string('importpreview', 'grades')); $table = new html_table(); $table->head = $header; $table->data = $data; $html .= html_writer::table($table); return $html; }
[ "public", "function", "import_preview_page", "(", "$", "header", ",", "$", "data", ")", "{", "$", "html", "=", "$", "this", "->", "output", "->", "heading", "(", "get_string", "(", "'importpreview'", ",", "'grades'", ")", ")", ";", "$", "table", "=", "new", "html_table", "(", ")", ";", "$", "table", "->", "head", "=", "$", "header", ";", "$", "table", "->", "data", "=", "$", "data", ";", "$", "html", ".=", "html_writer", "::", "table", "(", "$", "table", ")", ";", "return", "$", "html", ";", "}" ]
A renderer for the CSV file preview. @param array $header Column headers from the CSV file. @param array $data The rest of the data from the CSV file. @return string html to be displayed.
[ "A", "renderer", "for", "the", "CSV", "file", "preview", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/import/csv/classes/output/renderer.php#L65-L75
214,375
moodle/moodle
grade/import/csv/classes/output/renderer.php
gradeimport_csv_renderer.errors
public function errors($errors) { $html = ''; foreach ($errors as $error) { $html .= $this->output->notification($error); } return $html; }
php
public function errors($errors) { $html = ''; foreach ($errors as $error) { $html .= $this->output->notification($error); } return $html; }
[ "public", "function", "errors", "(", "$", "errors", ")", "{", "$", "html", "=", "''", ";", "foreach", "(", "$", "errors", "as", "$", "error", ")", "{", "$", "html", ".=", "$", "this", "->", "output", "->", "notification", "(", "$", "error", ")", ";", "}", "return", "$", "html", ";", "}" ]
A renderer for errors generated trying to import the CSV file. @param array $errors Display import errors. @return string errors as html to be displayed.
[ "A", "renderer", "for", "errors", "generated", "trying", "to", "import", "the", "CSV", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/import/csv/classes/output/renderer.php#L83-L89
214,376
moodle/moodle
report/log/classes/renderer.php
report_log_renderer.render_report_log
protected function render_report_log(report_log_renderable $reportlog) { if (empty($reportlog->selectedlogreader)) { echo $this->output->notification(get_string('nologreaderenabled', 'report_log'), 'notifyproblem'); return; } if ($reportlog->showselectorform) { $this->report_selector_form($reportlog); } if ($reportlog->showreport) { $reportlog->tablelog->out($reportlog->perpage, true); } }
php
protected function render_report_log(report_log_renderable $reportlog) { if (empty($reportlog->selectedlogreader)) { echo $this->output->notification(get_string('nologreaderenabled', 'report_log'), 'notifyproblem'); return; } if ($reportlog->showselectorform) { $this->report_selector_form($reportlog); } if ($reportlog->showreport) { $reportlog->tablelog->out($reportlog->perpage, true); } }
[ "protected", "function", "render_report_log", "(", "report_log_renderable", "$", "reportlog", ")", "{", "if", "(", "empty", "(", "$", "reportlog", "->", "selectedlogreader", ")", ")", "{", "echo", "$", "this", "->", "output", "->", "notification", "(", "get_string", "(", "'nologreaderenabled'", ",", "'report_log'", ")", ",", "'notifyproblem'", ")", ";", "return", ";", "}", "if", "(", "$", "reportlog", "->", "showselectorform", ")", "{", "$", "this", "->", "report_selector_form", "(", "$", "reportlog", ")", ";", "}", "if", "(", "$", "reportlog", "->", "showreport", ")", "{", "$", "reportlog", "->", "tablelog", "->", "out", "(", "$", "reportlog", "->", "perpage", ",", "true", ")", ";", "}", "}" ]
Render log report page. @param report_log_renderable $reportlog object of report_log.
[ "Render", "log", "report", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/log/classes/renderer.php#L52-L64
214,377
moodle/moodle
course/classes/analytics/target/course_gradetopass.php
course_gradetopass.get_course_gradetopass
protected function get_course_gradetopass($courseid) { if (!isset($this->coursesgradetopass[$courseid])) { // Get course grade_item. $courseitem = \grade_item::fetch_course_item($courseid); $ci = array(); $ci['courseitemid'] = $courseitem->id; if ($courseitem->gradetype == GRADE_TYPE_VALUE && grade_floats_different($courseitem->gradepass, 0.0)) { $ci['gradetopass'] = $courseitem->gradepass; } else { $ci['gradetopass'] = null; } $this->coursesgradetopass[$courseid] = $ci; } return $this->coursesgradetopass[$courseid]; }
php
protected function get_course_gradetopass($courseid) { if (!isset($this->coursesgradetopass[$courseid])) { // Get course grade_item. $courseitem = \grade_item::fetch_course_item($courseid); $ci = array(); $ci['courseitemid'] = $courseitem->id; if ($courseitem->gradetype == GRADE_TYPE_VALUE && grade_floats_different($courseitem->gradepass, 0.0)) { $ci['gradetopass'] = $courseitem->gradepass; } else { $ci['gradetopass'] = null; } $this->coursesgradetopass[$courseid] = $ci; } return $this->coursesgradetopass[$courseid]; }
[ "protected", "function", "get_course_gradetopass", "(", "$", "courseid", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "coursesgradetopass", "[", "$", "courseid", "]", ")", ")", "{", "// Get course grade_item.", "$", "courseitem", "=", "\\", "grade_item", "::", "fetch_course_item", "(", "$", "courseid", ")", ";", "$", "ci", "=", "array", "(", ")", ";", "$", "ci", "[", "'courseitemid'", "]", "=", "$", "courseitem", "->", "id", ";", "if", "(", "$", "courseitem", "->", "gradetype", "==", "GRADE_TYPE_VALUE", "&&", "grade_floats_different", "(", "$", "courseitem", "->", "gradepass", ",", "0.0", ")", ")", "{", "$", "ci", "[", "'gradetopass'", "]", "=", "$", "courseitem", "->", "gradepass", ";", "}", "else", "{", "$", "ci", "[", "'gradetopass'", "]", "=", "null", ";", "}", "$", "this", "->", "coursesgradetopass", "[", "$", "courseid", "]", "=", "$", "ci", ";", "}", "return", "$", "this", "->", "coursesgradetopass", "[", "$", "courseid", "]", ";", "}" ]
Returns the grade to pass a course. Save the value in $coursesgradetopass array to prevent new accesses to the database. @param int $courseid The course id. @return array The courseitem id and the required grade to pass the course.
[ "Returns", "the", "grade", "to", "pass", "a", "course", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/analytics/target/course_gradetopass.php#L59-L76
214,378
moodle/moodle
course/classes/analytics/target/course_gradetopass.php
course_gradetopass.get_user_grade
protected function get_user_grade($courseitemid, $userid) { // If the user grade for this course is not available, get all the grades for the course. if (!isset($this->coursesgrades[$courseitemid])) { // Ony a course is cached to avoid high memory usage. unset($this->coursesgrades); $gg = new \grade_grade(null, false); $usersgrades = $gg->fetch_all(array('itemid' => $courseitemid)); if ($usersgrades) { foreach ($usersgrades as $ug) { $this->coursesgrades[$courseitemid][$ug->userid] = $ug->finalgrade; } } } if (!isset($this->coursesgrades[$courseitemid][$userid])) { $this->coursesgrades[$courseitemid][$userid] = null; } return $this->coursesgrades[$courseitemid][$userid]; }
php
protected function get_user_grade($courseitemid, $userid) { // If the user grade for this course is not available, get all the grades for the course. if (!isset($this->coursesgrades[$courseitemid])) { // Ony a course is cached to avoid high memory usage. unset($this->coursesgrades); $gg = new \grade_grade(null, false); $usersgrades = $gg->fetch_all(array('itemid' => $courseitemid)); if ($usersgrades) { foreach ($usersgrades as $ug) { $this->coursesgrades[$courseitemid][$ug->userid] = $ug->finalgrade; } } } if (!isset($this->coursesgrades[$courseitemid][$userid])) { $this->coursesgrades[$courseitemid][$userid] = null; } return $this->coursesgrades[$courseitemid][$userid]; }
[ "protected", "function", "get_user_grade", "(", "$", "courseitemid", ",", "$", "userid", ")", "{", "// If the user grade for this course is not available, get all the grades for the course.", "if", "(", "!", "isset", "(", "$", "this", "->", "coursesgrades", "[", "$", "courseitemid", "]", ")", ")", "{", "// Ony a course is cached to avoid high memory usage.", "unset", "(", "$", "this", "->", "coursesgrades", ")", ";", "$", "gg", "=", "new", "\\", "grade_grade", "(", "null", ",", "false", ")", ";", "$", "usersgrades", "=", "$", "gg", "->", "fetch_all", "(", "array", "(", "'itemid'", "=>", "$", "courseitemid", ")", ")", ";", "if", "(", "$", "usersgrades", ")", "{", "foreach", "(", "$", "usersgrades", "as", "$", "ug", ")", "{", "$", "this", "->", "coursesgrades", "[", "$", "courseitemid", "]", "[", "$", "ug", "->", "userid", "]", "=", "$", "ug", "->", "finalgrade", ";", "}", "}", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "coursesgrades", "[", "$", "courseitemid", "]", "[", "$", "userid", "]", ")", ")", "{", "$", "this", "->", "coursesgrades", "[", "$", "courseitemid", "]", "[", "$", "userid", "]", "=", "null", ";", "}", "return", "$", "this", "->", "coursesgrades", "[", "$", "courseitemid", "]", "[", "$", "userid", "]", ";", "}" ]
Returns the grade of a user in a course. Saves the grades of all course users in $coursesgrades array to prevent new accesses to the database. @param int $courseitemid The course item id. @param int $userid the user whose grade is requested. @return array The courseitem id and the required grade to pass the course.
[ "Returns", "the", "grade", "of", "a", "user", "in", "a", "course", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/analytics/target/course_gradetopass.php#L87-L107
214,379
moodle/moodle
course/classes/analytics/target/course_gradetopass.php
course_gradetopass.calculate_sample
protected function calculate_sample($sampleid, \core_analytics\analysable $course, $starttime = false, $endtime = false) { $userenrol = $this->retrieve('user_enrolments', $sampleid); // Get course grade to pass. $courseitem = $this->get_course_gradetopass($course->get_id()); // Get the user grade. $usergrade = $this->get_user_grade($courseitem['courseitemid'], $userenrol->userid); if ($usergrade >= $courseitem['gradetopass']) { return 0; } return 1; }
php
protected function calculate_sample($sampleid, \core_analytics\analysable $course, $starttime = false, $endtime = false) { $userenrol = $this->retrieve('user_enrolments', $sampleid); // Get course grade to pass. $courseitem = $this->get_course_gradetopass($course->get_id()); // Get the user grade. $usergrade = $this->get_user_grade($courseitem['courseitemid'], $userenrol->userid); if ($usergrade >= $courseitem['gradetopass']) { return 0; } return 1; }
[ "protected", "function", "calculate_sample", "(", "$", "sampleid", ",", "\\", "core_analytics", "\\", "analysable", "$", "course", ",", "$", "starttime", "=", "false", ",", "$", "endtime", "=", "false", ")", "{", "$", "userenrol", "=", "$", "this", "->", "retrieve", "(", "'user_enrolments'", ",", "$", "sampleid", ")", ";", "// Get course grade to pass.", "$", "courseitem", "=", "$", "this", "->", "get_course_gradetopass", "(", "$", "course", "->", "get_id", "(", ")", ")", ";", "// Get the user grade.", "$", "usergrade", "=", "$", "this", "->", "get_user_grade", "(", "$", "courseitem", "[", "'courseitemid'", "]", ",", "$", "userenrol", "->", "userid", ")", ";", "if", "(", "$", "usergrade", ">=", "$", "courseitem", "[", "'gradetopass'", "]", ")", "{", "return", "0", ";", "}", "return", "1", ";", "}" ]
The user's grade in the course sets the target value. @param int $sampleid @param \core_analytics\analysable $course @param int $starttime @param int $endtime @return float 0 -> course grade to pass achieved, 1 -> course grade to pass not achieved
[ "The", "user", "s", "grade", "in", "the", "course", "sets", "the", "target", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/analytics/target/course_gradetopass.php#L165-L180
214,380
moodle/moodle
admin/tool/dataprivacy/classes/contextlevel.php
contextlevel.get_record_by_contextlevel
public static function get_record_by_contextlevel($contextlevel, $exception = true) { global $DB; $cache = \cache::make('tool_dataprivacy', 'contextlevel'); if ($data = $cache->get($contextlevel)) { return new static(0, $data); } if (!$record = $DB->get_record(self::TABLE, array('contextlevel' => $contextlevel))) { if (!$exception) { return false; } else { throw new \dml_missing_record_exception(self::TABLE); } } return new static(0, $record); }
php
public static function get_record_by_contextlevel($contextlevel, $exception = true) { global $DB; $cache = \cache::make('tool_dataprivacy', 'contextlevel'); if ($data = $cache->get($contextlevel)) { return new static(0, $data); } if (!$record = $DB->get_record(self::TABLE, array('contextlevel' => $contextlevel))) { if (!$exception) { return false; } else { throw new \dml_missing_record_exception(self::TABLE); } } return new static(0, $record); }
[ "public", "static", "function", "get_record_by_contextlevel", "(", "$", "contextlevel", ",", "$", "exception", "=", "true", ")", "{", "global", "$", "DB", ";", "$", "cache", "=", "\\", "cache", "::", "make", "(", "'tool_dataprivacy'", ",", "'contextlevel'", ")", ";", "if", "(", "$", "data", "=", "$", "cache", "->", "get", "(", "$", "contextlevel", ")", ")", "{", "return", "new", "static", "(", "0", ",", "$", "data", ")", ";", "}", "if", "(", "!", "$", "record", "=", "$", "DB", "->", "get_record", "(", "self", "::", "TABLE", ",", "array", "(", "'contextlevel'", "=>", "$", "contextlevel", ")", ")", ")", "{", "if", "(", "!", "$", "exception", ")", "{", "return", "false", ";", "}", "else", "{", "throw", "new", "\\", "dml_missing_record_exception", "(", "self", "::", "TABLE", ")", ";", "}", "}", "return", "new", "static", "(", "0", ",", "$", "record", ")", ";", "}" ]
Returns an instance by contextlevel. @param mixed $contextlevel @param mixed $exception @return null
[ "Returns", "an", "instance", "by", "contextlevel", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/contextlevel.php#L69-L86
214,381
moodle/moodle
enrol/manual/lib.php
enrol_manual_plugin.get_manual_enrol_link
public function get_manual_enrol_link($instance) { $name = $this->get_name(); if ($instance->enrol !== $name) { throw new coding_exception('invalid enrol instance!'); } if (!enrol_is_enabled($name)) { return NULL; } $context = context_course::instance($instance->courseid, MUST_EXIST); if (!has_capability('enrol/manual:enrol', $context)) { // Note: manage capability not used here because it is used for editing // of existing enrolments which is not possible here. return NULL; } return new moodle_url('/enrol/manual/manage.php', array('enrolid'=>$instance->id, 'id'=>$instance->courseid)); }
php
public function get_manual_enrol_link($instance) { $name = $this->get_name(); if ($instance->enrol !== $name) { throw new coding_exception('invalid enrol instance!'); } if (!enrol_is_enabled($name)) { return NULL; } $context = context_course::instance($instance->courseid, MUST_EXIST); if (!has_capability('enrol/manual:enrol', $context)) { // Note: manage capability not used here because it is used for editing // of existing enrolments which is not possible here. return NULL; } return new moodle_url('/enrol/manual/manage.php', array('enrolid'=>$instance->id, 'id'=>$instance->courseid)); }
[ "public", "function", "get_manual_enrol_link", "(", "$", "instance", ")", "{", "$", "name", "=", "$", "this", "->", "get_name", "(", ")", ";", "if", "(", "$", "instance", "->", "enrol", "!==", "$", "name", ")", "{", "throw", "new", "coding_exception", "(", "'invalid enrol instance!'", ")", ";", "}", "if", "(", "!", "enrol_is_enabled", "(", "$", "name", ")", ")", "{", "return", "NULL", ";", "}", "$", "context", "=", "context_course", "::", "instance", "(", "$", "instance", "->", "courseid", ",", "MUST_EXIST", ")", ";", "if", "(", "!", "has_capability", "(", "'enrol/manual:enrol'", ",", "$", "context", ")", ")", "{", "// Note: manage capability not used here because it is used for editing", "// of existing enrolments which is not possible here.", "return", "NULL", ";", "}", "return", "new", "moodle_url", "(", "'/enrol/manual/manage.php'", ",", "array", "(", "'enrolid'", "=>", "$", "instance", "->", "id", ",", "'id'", "=>", "$", "instance", "->", "courseid", ")", ")", ";", "}" ]
Returns link to manual enrol UI if exists. Does the access control tests automatically. @param stdClass $instance @return moodle_url
[ "Returns", "link", "to", "manual", "enrol", "UI", "if", "exists", ".", "Does", "the", "access", "control", "tests", "automatically", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/manual/lib.php#L59-L78
214,382
moodle/moodle
enrol/manual/lib.php
enrol_manual_plugin.get_action_icons
public function get_action_icons(stdClass $instance) { global $OUTPUT; $context = context_course::instance($instance->courseid); $icons = array(); if (has_capability('enrol/manual:enrol', $context) or has_capability('enrol/manual:unenrol', $context)) { $managelink = new moodle_url("/enrol/manual/manage.php", array('enrolid'=>$instance->id)); $icons[] = $OUTPUT->action_icon($managelink, new pix_icon('t/enrolusers', get_string('enrolusers', 'enrol_manual'), 'core', array('class'=>'iconsmall'))); } $parenticons = parent::get_action_icons($instance); $icons = array_merge($icons, $parenticons); return $icons; }
php
public function get_action_icons(stdClass $instance) { global $OUTPUT; $context = context_course::instance($instance->courseid); $icons = array(); if (has_capability('enrol/manual:enrol', $context) or has_capability('enrol/manual:unenrol', $context)) { $managelink = new moodle_url("/enrol/manual/manage.php", array('enrolid'=>$instance->id)); $icons[] = $OUTPUT->action_icon($managelink, new pix_icon('t/enrolusers', get_string('enrolusers', 'enrol_manual'), 'core', array('class'=>'iconsmall'))); } $parenticons = parent::get_action_icons($instance); $icons = array_merge($icons, $parenticons); return $icons; }
[ "public", "function", "get_action_icons", "(", "stdClass", "$", "instance", ")", "{", "global", "$", "OUTPUT", ";", "$", "context", "=", "context_course", "::", "instance", "(", "$", "instance", "->", "courseid", ")", ";", "$", "icons", "=", "array", "(", ")", ";", "if", "(", "has_capability", "(", "'enrol/manual:enrol'", ",", "$", "context", ")", "or", "has_capability", "(", "'enrol/manual:unenrol'", ",", "$", "context", ")", ")", "{", "$", "managelink", "=", "new", "moodle_url", "(", "\"/enrol/manual/manage.php\"", ",", "array", "(", "'enrolid'", "=>", "$", "instance", "->", "id", ")", ")", ";", "$", "icons", "[", "]", "=", "$", "OUTPUT", "->", "action_icon", "(", "$", "managelink", ",", "new", "pix_icon", "(", "'t/enrolusers'", ",", "get_string", "(", "'enrolusers'", ",", "'enrol_manual'", ")", ",", "'core'", ",", "array", "(", "'class'", "=>", "'iconsmall'", ")", ")", ")", ";", "}", "$", "parenticons", "=", "parent", "::", "get_action_icons", "(", "$", "instance", ")", ";", "$", "icons", "=", "array_merge", "(", "$", "icons", ",", "$", "parenticons", ")", ";", "return", "$", "icons", ";", "}" ]
Returns edit icons for the page with list of instances. @param stdClass $instance @return array
[ "Returns", "edit", "icons", "for", "the", "page", "with", "list", "of", "instances", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/manual/lib.php#L107-L121
214,383
moodle/moodle
enrol/manual/lib.php
enrol_manual_plugin.get_manual_enrol_button
public function get_manual_enrol_button(course_enrolment_manager $manager) { global $CFG, $PAGE; require_once($CFG->dirroot.'/cohort/lib.php'); $instance = null; $instances = array(); foreach ($manager->get_enrolment_instances() as $tempinstance) { if ($tempinstance->enrol == 'manual') { if ($instance === null) { $instance = $tempinstance; } $instances[] = array('id' => $tempinstance->id, 'name' => $this->get_instance_name($tempinstance)); } } if (empty($instance)) { return false; } $link = $this->get_manual_enrol_link($instance); if (!$link) { return false; } $button = new enrol_user_button($link, get_string('enrolusers', 'enrol_manual'), 'get'); $button->class .= ' enrol_manual_plugin'; $context = context_course::instance($instance->courseid); $arguments = array('contextid' => $context->id); $PAGE->requires->js_call_amd('enrol_manual/quickenrolment', 'init', array($arguments)); return $button; }
php
public function get_manual_enrol_button(course_enrolment_manager $manager) { global $CFG, $PAGE; require_once($CFG->dirroot.'/cohort/lib.php'); $instance = null; $instances = array(); foreach ($manager->get_enrolment_instances() as $tempinstance) { if ($tempinstance->enrol == 'manual') { if ($instance === null) { $instance = $tempinstance; } $instances[] = array('id' => $tempinstance->id, 'name' => $this->get_instance_name($tempinstance)); } } if (empty($instance)) { return false; } $link = $this->get_manual_enrol_link($instance); if (!$link) { return false; } $button = new enrol_user_button($link, get_string('enrolusers', 'enrol_manual'), 'get'); $button->class .= ' enrol_manual_plugin'; $context = context_course::instance($instance->courseid); $arguments = array('contextid' => $context->id); $PAGE->requires->js_call_amd('enrol_manual/quickenrolment', 'init', array($arguments)); return $button; }
[ "public", "function", "get_manual_enrol_button", "(", "course_enrolment_manager", "$", "manager", ")", "{", "global", "$", "CFG", ",", "$", "PAGE", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/cohort/lib.php'", ")", ";", "$", "instance", "=", "null", ";", "$", "instances", "=", "array", "(", ")", ";", "foreach", "(", "$", "manager", "->", "get_enrolment_instances", "(", ")", "as", "$", "tempinstance", ")", "{", "if", "(", "$", "tempinstance", "->", "enrol", "==", "'manual'", ")", "{", "if", "(", "$", "instance", "===", "null", ")", "{", "$", "instance", "=", "$", "tempinstance", ";", "}", "$", "instances", "[", "]", "=", "array", "(", "'id'", "=>", "$", "tempinstance", "->", "id", ",", "'name'", "=>", "$", "this", "->", "get_instance_name", "(", "$", "tempinstance", ")", ")", ";", "}", "}", "if", "(", "empty", "(", "$", "instance", ")", ")", "{", "return", "false", ";", "}", "$", "link", "=", "$", "this", "->", "get_manual_enrol_link", "(", "$", "instance", ")", ";", "if", "(", "!", "$", "link", ")", "{", "return", "false", ";", "}", "$", "button", "=", "new", "enrol_user_button", "(", "$", "link", ",", "get_string", "(", "'enrolusers'", ",", "'enrol_manual'", ")", ",", "'get'", ")", ";", "$", "button", "->", "class", ".=", "' enrol_manual_plugin'", ";", "$", "context", "=", "context_course", "::", "instance", "(", "$", "instance", "->", "courseid", ")", ";", "$", "arguments", "=", "array", "(", "'contextid'", "=>", "$", "context", "->", "id", ")", ";", "$", "PAGE", "->", "requires", "->", "js_call_amd", "(", "'enrol_manual/quickenrolment'", ",", "'init'", ",", "array", "(", "$", "arguments", ")", ")", ";", "return", "$", "button", ";", "}" ]
Returns a button to manually enrol users through the manual enrolment plugin. By default the first manual enrolment plugin instance available in the course is used. If no manual enrolment instances exist within the course then false is returned. This function also adds a quickenrolment JS ui to the page so that users can be enrolled via AJAX. @param course_enrolment_manager $manager @return enrol_user_button
[ "Returns", "a", "button", "to", "manually", "enrol", "users", "through", "the", "manual", "enrolment", "plugin", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/manual/lib.php#L196-L228
214,384
moodle/moodle
enrol/manual/lib.php
enrol_manual_plugin.get_bulk_operations
public function get_bulk_operations(course_enrolment_manager $manager) { global $CFG; require_once($CFG->dirroot.'/enrol/manual/locallib.php'); $context = $manager->get_context(); $bulkoperations = array(); if (has_capability("enrol/manual:manage", $context)) { $bulkoperations['editselectedusers'] = new enrol_manual_editselectedusers_operation($manager, $this); } if (has_capability("enrol/manual:unenrol", $context)) { $bulkoperations['deleteselectedusers'] = new enrol_manual_deleteselectedusers_operation($manager, $this); } return $bulkoperations; }
php
public function get_bulk_operations(course_enrolment_manager $manager) { global $CFG; require_once($CFG->dirroot.'/enrol/manual/locallib.php'); $context = $manager->get_context(); $bulkoperations = array(); if (has_capability("enrol/manual:manage", $context)) { $bulkoperations['editselectedusers'] = new enrol_manual_editselectedusers_operation($manager, $this); } if (has_capability("enrol/manual:unenrol", $context)) { $bulkoperations['deleteselectedusers'] = new enrol_manual_deleteselectedusers_operation($manager, $this); } return $bulkoperations; }
[ "public", "function", "get_bulk_operations", "(", "course_enrolment_manager", "$", "manager", ")", "{", "global", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/enrol/manual/locallib.php'", ")", ";", "$", "context", "=", "$", "manager", "->", "get_context", "(", ")", ";", "$", "bulkoperations", "=", "array", "(", ")", ";", "if", "(", "has_capability", "(", "\"enrol/manual:manage\"", ",", "$", "context", ")", ")", "{", "$", "bulkoperations", "[", "'editselectedusers'", "]", "=", "new", "enrol_manual_editselectedusers_operation", "(", "$", "manager", ",", "$", "this", ")", ";", "}", "if", "(", "has_capability", "(", "\"enrol/manual:unenrol\"", ",", "$", "context", ")", ")", "{", "$", "bulkoperations", "[", "'deleteselectedusers'", "]", "=", "new", "enrol_manual_deleteselectedusers_operation", "(", "$", "manager", ",", "$", "this", ")", ";", "}", "return", "$", "bulkoperations", ";", "}" ]
The manual plugin has several bulk operations that can be performed. @param course_enrolment_manager $manager @return array
[ "The", "manual", "plugin", "has", "several", "bulk", "operations", "that", "can", "be", "performed", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/manual/lib.php#L359-L371
214,385
moodle/moodle
enrol/manual/lib.php
enrol_manual_plugin.enrol_cohort
public function enrol_cohort(stdClass $instance, $cohortid, $roleid = null, $timestart = 0, $timeend = 0, $status = null, $recovergrades = null) { global $DB; $context = context_course::instance($instance->courseid); list($esql, $params) = get_enrolled_sql($context); $sql = "SELECT cm.userid FROM {cohort_members} cm LEFT JOIN ($esql) u ON u.id = cm.userid ". "WHERE cm.cohortid = :cohortid AND u.id IS NULL"; $params['cohortid'] = $cohortid; $members = $DB->get_fieldset_sql($sql, $params); foreach ($members as $userid) { $this->enrol_user($instance, $userid, $roleid, $timestart, $timeend, $status, $recovergrades); } }
php
public function enrol_cohort(stdClass $instance, $cohortid, $roleid = null, $timestart = 0, $timeend = 0, $status = null, $recovergrades = null) { global $DB; $context = context_course::instance($instance->courseid); list($esql, $params) = get_enrolled_sql($context); $sql = "SELECT cm.userid FROM {cohort_members} cm LEFT JOIN ($esql) u ON u.id = cm.userid ". "WHERE cm.cohortid = :cohortid AND u.id IS NULL"; $params['cohortid'] = $cohortid; $members = $DB->get_fieldset_sql($sql, $params); foreach ($members as $userid) { $this->enrol_user($instance, $userid, $roleid, $timestart, $timeend, $status, $recovergrades); } }
[ "public", "function", "enrol_cohort", "(", "stdClass", "$", "instance", ",", "$", "cohortid", ",", "$", "roleid", "=", "null", ",", "$", "timestart", "=", "0", ",", "$", "timeend", "=", "0", ",", "$", "status", "=", "null", ",", "$", "recovergrades", "=", "null", ")", "{", "global", "$", "DB", ";", "$", "context", "=", "context_course", "::", "instance", "(", "$", "instance", "->", "courseid", ")", ";", "list", "(", "$", "esql", ",", "$", "params", ")", "=", "get_enrolled_sql", "(", "$", "context", ")", ";", "$", "sql", "=", "\"SELECT cm.userid FROM {cohort_members} cm LEFT JOIN ($esql) u ON u.id = cm.userid \"", ".", "\"WHERE cm.cohortid = :cohortid AND u.id IS NULL\"", ";", "$", "params", "[", "'cohortid'", "]", "=", "$", "cohortid", ";", "$", "members", "=", "$", "DB", "->", "get_fieldset_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "foreach", "(", "$", "members", "as", "$", "userid", ")", "{", "$", "this", "->", "enrol_user", "(", "$", "instance", ",", "$", "userid", ",", "$", "roleid", ",", "$", "timestart", ",", "$", "timeend", ",", "$", "status", ",", "$", "recovergrades", ")", ";", "}", "}" ]
Enrol all not enrolled cohort members into course via enrol instance. @param stdClass $instance @param int $cohortid @param int $roleid optional role id @param int $timestart 0 means unknown @param int $timeend 0 means forever @param int $status default to ENROL_USER_ACTIVE for new enrolments, no change by default in updates @param bool $recovergrades restore grade history
[ "Enrol", "all", "not", "enrolled", "cohort", "members", "into", "course", "via", "enrol", "instance", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/manual/lib.php#L506-L517
214,386
moodle/moodle
badges/criteria/award_criteria_cohort.php
award_criteria_cohort.validate
public function validate() { global $DB; $params = array_keys($this->params); $method = ($this->method == BADGE_CRITERIA_AGGREGATION_ALL); $singleparam = (count($params) == 1); foreach ($params as $param) { // Perform check if there only one parameter with any type of aggregation, // Or there are more than one parameter with aggregation ALL. if (($singleparam || $method) && !$DB->record_exists('cohort', array('id' => $param))) { return array(false, get_string('error:invalidparamcohort', 'badges')); } } return array(true, ''); }
php
public function validate() { global $DB; $params = array_keys($this->params); $method = ($this->method == BADGE_CRITERIA_AGGREGATION_ALL); $singleparam = (count($params) == 1); foreach ($params as $param) { // Perform check if there only one parameter with any type of aggregation, // Or there are more than one parameter with aggregation ALL. if (($singleparam || $method) && !$DB->record_exists('cohort', array('id' => $param))) { return array(false, get_string('error:invalidparamcohort', 'badges')); } } return array(true, ''); }
[ "public", "function", "validate", "(", ")", "{", "global", "$", "DB", ";", "$", "params", "=", "array_keys", "(", "$", "this", "->", "params", ")", ";", "$", "method", "=", "(", "$", "this", "->", "method", "==", "BADGE_CRITERIA_AGGREGATION_ALL", ")", ";", "$", "singleparam", "=", "(", "count", "(", "$", "params", ")", "==", "1", ")", ";", "foreach", "(", "$", "params", "as", "$", "param", ")", "{", "// Perform check if there only one parameter with any type of aggregation,", "// Or there are more than one parameter with aggregation ALL.", "if", "(", "(", "$", "singleparam", "||", "$", "method", ")", "&&", "!", "$", "DB", "->", "record_exists", "(", "'cohort'", ",", "array", "(", "'id'", "=>", "$", "param", ")", ")", ")", "{", "return", "array", "(", "false", ",", "get_string", "(", "'error:invalidparamcohort'", ",", "'badges'", ")", ")", ";", "}", "}", "return", "array", "(", "true", ",", "''", ")", ";", "}" ]
Checks criteria for any major problems. @return array A list containing status and an error message (if any).
[ "Checks", "criteria", "for", "any", "major", "problems", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/badges/criteria/award_criteria_cohort.php#L197-L212
214,387
moodle/moodle
group/classes/privacy/provider.php
provider.get_group_members_in_context
public static function get_group_members_in_context(userlist $userlist, string $component, int $itemid = 0) { $context = $userlist->get_context(); if (!$context instanceof \context_course) { return; } // Group members in the given context. $sql = "SELECT gm.userid FROM {groups_members} gm JOIN {groups} g ON gm.groupid = g.id WHERE g.courseid = :courseid AND gm.component = :component"; $params = [ 'courseid' => $context->instanceid, 'component' => $component ]; if ($itemid) { $sql .= ' AND gm.itemid = :itemid'; $params['itemid'] = $itemid; } $userlist->add_from_sql('userid', $sql, $params); // Get the users with some group conversation in this context. \core_message\privacy\provider::add_conversations_in_context($userlist, 'core_group', 'groups', $itemid); }
php
public static function get_group_members_in_context(userlist $userlist, string $component, int $itemid = 0) { $context = $userlist->get_context(); if (!$context instanceof \context_course) { return; } // Group members in the given context. $sql = "SELECT gm.userid FROM {groups_members} gm JOIN {groups} g ON gm.groupid = g.id WHERE g.courseid = :courseid AND gm.component = :component"; $params = [ 'courseid' => $context->instanceid, 'component' => $component ]; if ($itemid) { $sql .= ' AND gm.itemid = :itemid'; $params['itemid'] = $itemid; } $userlist->add_from_sql('userid', $sql, $params); // Get the users with some group conversation in this context. \core_message\privacy\provider::add_conversations_in_context($userlist, 'core_group', 'groups', $itemid); }
[ "public", "static", "function", "get_group_members_in_context", "(", "userlist", "$", "userlist", ",", "string", "$", "component", ",", "int", "$", "itemid", "=", "0", ")", "{", "$", "context", "=", "$", "userlist", "->", "get_context", "(", ")", ";", "if", "(", "!", "$", "context", "instanceof", "\\", "context_course", ")", "{", "return", ";", "}", "// Group members in the given context.", "$", "sql", "=", "\"SELECT gm.userid\n FROM {groups_members} gm\n JOIN {groups} g ON gm.groupid = g.id\n WHERE g.courseid = :courseid AND gm.component = :component\"", ";", "$", "params", "=", "[", "'courseid'", "=>", "$", "context", "->", "instanceid", ",", "'component'", "=>", "$", "component", "]", ";", "if", "(", "$", "itemid", ")", "{", "$", "sql", ".=", "' AND gm.itemid = :itemid'", ";", "$", "params", "[", "'itemid'", "]", "=", "$", "itemid", ";", "}", "$", "userlist", "->", "add_from_sql", "(", "'userid'", ",", "$", "sql", ",", "$", "params", ")", ";", "// Get the users with some group conversation in this context.", "\\", "core_message", "\\", "privacy", "\\", "provider", "::", "add_conversations_in_context", "(", "$", "userlist", ",", "'core_group'", ",", "'groups'", ",", "$", "itemid", ")", ";", "}" ]
Add the list of users who are members of some groups in the specified constraints. @param userlist $userlist The userlist to add the users to. @param string $component The component to check. @param int $itemid Optional itemid associated with component.
[ "Add", "the", "list", "of", "users", "who", "are", "members", "of", "some", "groups", "in", "the", "specified", "constraints", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/group/classes/privacy/provider.php#L229-L255
214,388
moodle/moodle
group/classes/privacy/provider.php
provider.get_contexts_for_group_member
public static function get_contexts_for_group_member(int $userid, string $component, int $itemid = 0) { $contextlist = new contextlist(); $sql = "SELECT ctx.id FROM {groups_members} gm JOIN {groups} g ON gm.groupid = g.id JOIN {context} ctx ON g.courseid = ctx.instanceid AND ctx.contextlevel = :contextcourse WHERE gm.userid = :userid AND gm.component = :component"; $params = [ 'contextcourse' => CONTEXT_COURSE, 'userid' => $userid, 'component' => $component ]; if ($itemid) { $sql .= ' AND gm.itemid = :itemid'; $params['itemid'] = $itemid; } $contextlist->add_from_sql($sql, $params); // Get the contexts where the userid has group conversations. \core_message\privacy\provider::add_contexts_for_conversations($contextlist, $userid, 'core_group', 'groups', $itemid); return $contextlist; }
php
public static function get_contexts_for_group_member(int $userid, string $component, int $itemid = 0) { $contextlist = new contextlist(); $sql = "SELECT ctx.id FROM {groups_members} gm JOIN {groups} g ON gm.groupid = g.id JOIN {context} ctx ON g.courseid = ctx.instanceid AND ctx.contextlevel = :contextcourse WHERE gm.userid = :userid AND gm.component = :component"; $params = [ 'contextcourse' => CONTEXT_COURSE, 'userid' => $userid, 'component' => $component ]; if ($itemid) { $sql .= ' AND gm.itemid = :itemid'; $params['itemid'] = $itemid; } $contextlist->add_from_sql($sql, $params); // Get the contexts where the userid has group conversations. \core_message\privacy\provider::add_contexts_for_conversations($contextlist, $userid, 'core_group', 'groups', $itemid); return $contextlist; }
[ "public", "static", "function", "get_contexts_for_group_member", "(", "int", "$", "userid", ",", "string", "$", "component", ",", "int", "$", "itemid", "=", "0", ")", "{", "$", "contextlist", "=", "new", "contextlist", "(", ")", ";", "$", "sql", "=", "\"SELECT ctx.id\n FROM {groups_members} gm\n JOIN {groups} g ON gm.groupid = g.id\n JOIN {context} ctx ON g.courseid = ctx.instanceid AND ctx.contextlevel = :contextcourse\n WHERE gm.userid = :userid AND gm.component = :component\"", ";", "$", "params", "=", "[", "'contextcourse'", "=>", "CONTEXT_COURSE", ",", "'userid'", "=>", "$", "userid", ",", "'component'", "=>", "$", "component", "]", ";", "if", "(", "$", "itemid", ")", "{", "$", "sql", ".=", "' AND gm.itemid = :itemid'", ";", "$", "params", "[", "'itemid'", "]", "=", "$", "itemid", ";", "}", "$", "contextlist", "->", "add_from_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "// Get the contexts where the userid has group conversations.", "\\", "core_message", "\\", "privacy", "\\", "provider", "::", "add_contexts_for_conversations", "(", "$", "contextlist", ",", "$", "userid", ",", "'core_group'", ",", "'groups'", ",", "$", "itemid", ")", ";", "return", "$", "contextlist", ";", "}" ]
Get the list of contexts that contain group membership for the specified user. @param int $userid The user to search. @param string $component The component to check. @param int $itemid Optional itemid associated with component. @return contextlist The contextlist containing the list of contexts.
[ "Get", "the", "list", "of", "contexts", "that", "contain", "group", "membership", "for", "the", "specified", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/group/classes/privacy/provider.php#L307-L333
214,389
moodle/moodle
admin/tool/xmldb/actions/XMLDBAction.class.php
XMLDBAction.init
function init() { $this->does_generate = ACTION_NONE; $this->title = strtolower(get_class($this)); $this->str = array(); $this->output = NULL; $this->errormsg = NULL; $this->subaction = NULL; $this->sesskey_protected = true; }
php
function init() { $this->does_generate = ACTION_NONE; $this->title = strtolower(get_class($this)); $this->str = array(); $this->output = NULL; $this->errormsg = NULL; $this->subaction = NULL; $this->sesskey_protected = true; }
[ "function", "init", "(", ")", "{", "$", "this", "->", "does_generate", "=", "ACTION_NONE", ";", "$", "this", "->", "title", "=", "strtolower", "(", "get_class", "(", "$", "this", ")", ")", ";", "$", "this", "->", "str", "=", "array", "(", ")", ";", "$", "this", "->", "output", "=", "NULL", ";", "$", "this", "->", "errormsg", "=", "NULL", ";", "$", "this", "->", "subaction", "=", "NULL", ";", "$", "this", "->", "sesskey_protected", "=", "true", ";", "}" ]
Init method, every subclass will have its own, always calling the parent one
[ "Init", "method", "every", "subclass", "will", "have", "its", "own", "always", "calling", "the", "parent", "one" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/xmldb/actions/XMLDBAction.class.php#L67-L75
214,390
moodle/moodle
admin/tool/xmldb/actions/XMLDBAction.class.php
XMLDBAction.loadStrings
function loadStrings($strings) { // Load some commonly used strings if (get_string_manager()->string_exists($this->title, 'tool_xmldb')) { $this->str['title'] = get_string($this->title, 'tool_xmldb'); } else { $this->str['title'] = $this->title; } // Now process the $strings array loading it in the $str atribute if ($strings) { foreach ($strings as $key => $module) { $this->str[$key] = get_string($key, $module); } } }
php
function loadStrings($strings) { // Load some commonly used strings if (get_string_manager()->string_exists($this->title, 'tool_xmldb')) { $this->str['title'] = get_string($this->title, 'tool_xmldb'); } else { $this->str['title'] = $this->title; } // Now process the $strings array loading it in the $str atribute if ($strings) { foreach ($strings as $key => $module) { $this->str[$key] = get_string($key, $module); } } }
[ "function", "loadStrings", "(", "$", "strings", ")", "{", "// Load some commonly used strings", "if", "(", "get_string_manager", "(", ")", "->", "string_exists", "(", "$", "this", "->", "title", ",", "'tool_xmldb'", ")", ")", "{", "$", "this", "->", "str", "[", "'title'", "]", "=", "get_string", "(", "$", "this", "->", "title", ",", "'tool_xmldb'", ")", ";", "}", "else", "{", "$", "this", "->", "str", "[", "'title'", "]", "=", "$", "this", "->", "title", ";", "}", "// Now process the $strings array loading it in the $str atribute", "if", "(", "$", "strings", ")", "{", "foreach", "(", "$", "strings", "as", "$", "key", "=>", "$", "module", ")", "{", "$", "this", "->", "str", "[", "$", "key", "]", "=", "get_string", "(", "$", "key", ",", "$", "module", ")", ";", "}", "}", "}" ]
loadStrings method, loads the required strings specified in the array parameter @param string[] $strings
[ "loadStrings", "method", "loads", "the", "required", "strings", "specified", "in", "the", "array", "parameter" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/xmldb/actions/XMLDBAction.class.php#L126-L140
214,391
moodle/moodle
admin/tool/xmldb/actions/XMLDBAction.class.php
XMLDBAction.invoke
function invoke() { global $SESSION; // Sesskey protection if ($this->sesskey_protected) { require_sesskey(); } // If we are used any dir, save it in the lastused session object // Some actions can use it to perform positioning if ($lastused = optional_param ('dir', NULL, PARAM_PATH)) { $SESSION->lastused = $lastused; } $this->postaction = optional_param ('postaction', NULL, PARAM_ALPHAEXT); // Avoid being recursive if ($this->title == $this->postaction) { $this->postaction = NULL; } }
php
function invoke() { global $SESSION; // Sesskey protection if ($this->sesskey_protected) { require_sesskey(); } // If we are used any dir, save it in the lastused session object // Some actions can use it to perform positioning if ($lastused = optional_param ('dir', NULL, PARAM_PATH)) { $SESSION->lastused = $lastused; } $this->postaction = optional_param ('postaction', NULL, PARAM_ALPHAEXT); // Avoid being recursive if ($this->title == $this->postaction) { $this->postaction = NULL; } }
[ "function", "invoke", "(", ")", "{", "global", "$", "SESSION", ";", "// Sesskey protection", "if", "(", "$", "this", "->", "sesskey_protected", ")", "{", "require_sesskey", "(", ")", ";", "}", "// If we are used any dir, save it in the lastused session object", "// Some actions can use it to perform positioning", "if", "(", "$", "lastused", "=", "optional_param", "(", "'dir'", ",", "NULL", ",", "PARAM_PATH", ")", ")", "{", "$", "SESSION", "->", "lastused", "=", "$", "lastused", ";", "}", "$", "this", "->", "postaction", "=", "optional_param", "(", "'postaction'", ",", "NULL", ",", "PARAM_ALPHAEXT", ")", ";", "// Avoid being recursive", "if", "(", "$", "this", "->", "title", "==", "$", "this", "->", "postaction", ")", "{", "$", "this", "->", "postaction", "=", "NULL", ";", "}", "}" ]
main invoke method, it sets the postaction attribute if possible and checks sesskey_protected if needed
[ "main", "invoke", "method", "it", "sets", "the", "postaction", "attribute", "if", "possible", "and", "checks", "sesskey_protected", "if", "needed" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/xmldb/actions/XMLDBAction.class.php#L146-L166
214,392
moodle/moodle
admin/tool/xmldb/actions/XMLDBAction.class.php
XMLDBAction.launch
function launch($action) { global $CFG; // Get the action path and invoke it $actionsroot = "$CFG->dirroot/$CFG->admin/tool/xmldb/actions"; $actionclass = $action . '.class.php'; $actionpath = "$actionsroot/$action/$actionclass"; // Load and invoke the proper action $result = false; if (file_exists($actionpath) && is_readable($actionpath)) { require_once($actionpath); if ($xmldb_action = new $action) { $result = $xmldb_action->invoke(); if ($result) { if ($xmldb_action->does_generate != ACTION_NONE && $xmldb_action->getOutput()) { $this->does_generate = $xmldb_action->does_generate; $this->title = $xmldb_action->title; $this->str = $xmldb_action->str; $this->output .= $xmldb_action->getOutput(); } } else { $this->errormsg = $xmldb_action->getError(); } } else { $this->errormsg = "Error: cannot instantiate class (actions/$action/$actionclass)"; } } else { $this->errormsg = "Error: wrong action specified ($action)"; } return $result; }
php
function launch($action) { global $CFG; // Get the action path and invoke it $actionsroot = "$CFG->dirroot/$CFG->admin/tool/xmldb/actions"; $actionclass = $action . '.class.php'; $actionpath = "$actionsroot/$action/$actionclass"; // Load and invoke the proper action $result = false; if (file_exists($actionpath) && is_readable($actionpath)) { require_once($actionpath); if ($xmldb_action = new $action) { $result = $xmldb_action->invoke(); if ($result) { if ($xmldb_action->does_generate != ACTION_NONE && $xmldb_action->getOutput()) { $this->does_generate = $xmldb_action->does_generate; $this->title = $xmldb_action->title; $this->str = $xmldb_action->str; $this->output .= $xmldb_action->getOutput(); } } else { $this->errormsg = $xmldb_action->getError(); } } else { $this->errormsg = "Error: cannot instantiate class (actions/$action/$actionclass)"; } } else { $this->errormsg = "Error: wrong action specified ($action)"; } return $result; }
[ "function", "launch", "(", "$", "action", ")", "{", "global", "$", "CFG", ";", "// Get the action path and invoke it", "$", "actionsroot", "=", "\"$CFG->dirroot/$CFG->admin/tool/xmldb/actions\"", ";", "$", "actionclass", "=", "$", "action", ".", "'.class.php'", ";", "$", "actionpath", "=", "\"$actionsroot/$action/$actionclass\"", ";", "// Load and invoke the proper action", "$", "result", "=", "false", ";", "if", "(", "file_exists", "(", "$", "actionpath", ")", "&&", "is_readable", "(", "$", "actionpath", ")", ")", "{", "require_once", "(", "$", "actionpath", ")", ";", "if", "(", "$", "xmldb_action", "=", "new", "$", "action", ")", "{", "$", "result", "=", "$", "xmldb_action", "->", "invoke", "(", ")", ";", "if", "(", "$", "result", ")", "{", "if", "(", "$", "xmldb_action", "->", "does_generate", "!=", "ACTION_NONE", "&&", "$", "xmldb_action", "->", "getOutput", "(", ")", ")", "{", "$", "this", "->", "does_generate", "=", "$", "xmldb_action", "->", "does_generate", ";", "$", "this", "->", "title", "=", "$", "xmldb_action", "->", "title", ";", "$", "this", "->", "str", "=", "$", "xmldb_action", "->", "str", ";", "$", "this", "->", "output", ".=", "$", "xmldb_action", "->", "getOutput", "(", ")", ";", "}", "}", "else", "{", "$", "this", "->", "errormsg", "=", "$", "xmldb_action", "->", "getError", "(", ")", ";", "}", "}", "else", "{", "$", "this", "->", "errormsg", "=", "\"Error: cannot instantiate class (actions/$action/$actionclass)\"", ";", "}", "}", "else", "{", "$", "this", "->", "errormsg", "=", "\"Error: wrong action specified ($action)\"", ";", "}", "return", "$", "result", ";", "}" ]
launch method, used to easily call invoke methods between actions @param string $action @return mixed
[ "launch", "method", "used", "to", "easily", "call", "invoke", "methods", "between", "actions" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/xmldb/actions/XMLDBAction.class.php#L173-L206
214,393
moodle/moodle
auth/oauth2/classes/output/renderer.php
renderer.linked_logins_table
public function linked_logins_table($linkedlogins) { global $CFG; $table = new html_table(); $table->head = [ get_string('issuer', 'auth_oauth2'), get_string('info', 'auth_oauth2'), get_string('edit'), ]; $table->attributes['class'] = 'admintable generaltable'; $data = []; $index = 0; foreach ($linkedlogins as $linkedlogin) { // Issuer. $issuerid = $linkedlogin->get('issuerid'); $issuer = \core\oauth2\api::get_issuer($issuerid); $issuercell = new html_table_cell(s($issuer->get('name'))); // Issuer. $username = $linkedlogin->get('username'); $email = $linkedlogin->get('email'); $usernamecell = new html_table_cell(s($email) . ', (' . s($username) . ')'); $links = ''; // Delete. $deleteparams = ['linkedloginid' => $linkedlogin->get('id'), 'action' => 'delete', 'sesskey' => sesskey()]; $deleteurl = new moodle_url('/auth/oauth2/linkedlogins.php', $deleteparams); $deletelink = html_writer::link($deleteurl, $this->pix_icon('t/delete', get_string('delete'))); $links .= ' ' . $deletelink; $editcell = new html_table_cell($links); $row = new html_table_row([ $issuercell, $usernamecell, $editcell, ]); $data[] = $row; $index++; } $table->data = $data; return html_writer::table($table); }
php
public function linked_logins_table($linkedlogins) { global $CFG; $table = new html_table(); $table->head = [ get_string('issuer', 'auth_oauth2'), get_string('info', 'auth_oauth2'), get_string('edit'), ]; $table->attributes['class'] = 'admintable generaltable'; $data = []; $index = 0; foreach ($linkedlogins as $linkedlogin) { // Issuer. $issuerid = $linkedlogin->get('issuerid'); $issuer = \core\oauth2\api::get_issuer($issuerid); $issuercell = new html_table_cell(s($issuer->get('name'))); // Issuer. $username = $linkedlogin->get('username'); $email = $linkedlogin->get('email'); $usernamecell = new html_table_cell(s($email) . ', (' . s($username) . ')'); $links = ''; // Delete. $deleteparams = ['linkedloginid' => $linkedlogin->get('id'), 'action' => 'delete', 'sesskey' => sesskey()]; $deleteurl = new moodle_url('/auth/oauth2/linkedlogins.php', $deleteparams); $deletelink = html_writer::link($deleteurl, $this->pix_icon('t/delete', get_string('delete'))); $links .= ' ' . $deletelink; $editcell = new html_table_cell($links); $row = new html_table_row([ $issuercell, $usernamecell, $editcell, ]); $data[] = $row; $index++; } $table->data = $data; return html_writer::table($table); }
[ "public", "function", "linked_logins_table", "(", "$", "linkedlogins", ")", "{", "global", "$", "CFG", ";", "$", "table", "=", "new", "html_table", "(", ")", ";", "$", "table", "->", "head", "=", "[", "get_string", "(", "'issuer'", ",", "'auth_oauth2'", ")", ",", "get_string", "(", "'info'", ",", "'auth_oauth2'", ")", ",", "get_string", "(", "'edit'", ")", ",", "]", ";", "$", "table", "->", "attributes", "[", "'class'", "]", "=", "'admintable generaltable'", ";", "$", "data", "=", "[", "]", ";", "$", "index", "=", "0", ";", "foreach", "(", "$", "linkedlogins", "as", "$", "linkedlogin", ")", "{", "// Issuer.", "$", "issuerid", "=", "$", "linkedlogin", "->", "get", "(", "'issuerid'", ")", ";", "$", "issuer", "=", "\\", "core", "\\", "oauth2", "\\", "api", "::", "get_issuer", "(", "$", "issuerid", ")", ";", "$", "issuercell", "=", "new", "html_table_cell", "(", "s", "(", "$", "issuer", "->", "get", "(", "'name'", ")", ")", ")", ";", "// Issuer.", "$", "username", "=", "$", "linkedlogin", "->", "get", "(", "'username'", ")", ";", "$", "email", "=", "$", "linkedlogin", "->", "get", "(", "'email'", ")", ";", "$", "usernamecell", "=", "new", "html_table_cell", "(", "s", "(", "$", "email", ")", ".", "', ('", ".", "s", "(", "$", "username", ")", ".", "')'", ")", ";", "$", "links", "=", "''", ";", "// Delete.", "$", "deleteparams", "=", "[", "'linkedloginid'", "=>", "$", "linkedlogin", "->", "get", "(", "'id'", ")", ",", "'action'", "=>", "'delete'", ",", "'sesskey'", "=>", "sesskey", "(", ")", "]", ";", "$", "deleteurl", "=", "new", "moodle_url", "(", "'/auth/oauth2/linkedlogins.php'", ",", "$", "deleteparams", ")", ";", "$", "deletelink", "=", "html_writer", "::", "link", "(", "$", "deleteurl", ",", "$", "this", "->", "pix_icon", "(", "'t/delete'", ",", "get_string", "(", "'delete'", ")", ")", ")", ";", "$", "links", ".=", "' '", ".", "$", "deletelink", ";", "$", "editcell", "=", "new", "html_table_cell", "(", "$", "links", ")", ";", "$", "row", "=", "new", "html_table_row", "(", "[", "$", "issuercell", ",", "$", "usernamecell", ",", "$", "editcell", ",", "]", ")", ";", "$", "data", "[", "]", "=", "$", "row", ";", "$", "index", "++", ";", "}", "$", "table", "->", "data", "=", "$", "data", ";", "return", "html_writer", "::", "table", "(", "$", "table", ")", ";", "}" ]
This function will render one beautiful table with all the linked_logins. @param \auth\oauth2\linked_login[] $linkedlogins - list of all linked logins. @return string HTML to output.
[ "This", "function", "will", "render", "one", "beautiful", "table", "with", "all", "the", "linked_logins", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/oauth2/classes/output/renderer.php#L49-L95
214,394
moodle/moodle
lib/adodb/adodb-pager.inc.php
ADODB_Pager.Render_First
function Render_First($anchor=true) { global $PHP_SELF; if ($anchor) { ?> <a href="<?php echo $PHP_SELF,'?',$this->id;?>_next_page=1"><?php echo $this->first;?></a> &nbsp; <?php } else { print "$this->first &nbsp; "; } }
php
function Render_First($anchor=true) { global $PHP_SELF; if ($anchor) { ?> <a href="<?php echo $PHP_SELF,'?',$this->id;?>_next_page=1"><?php echo $this->first;?></a> &nbsp; <?php } else { print "$this->first &nbsp; "; } }
[ "function", "Render_First", "(", "$", "anchor", "=", "true", ")", "{", "global", "$", "PHP_SELF", ";", "if", "(", "$", "anchor", ")", "{", "?>\n\t\t<a href=\"<?php", "echo", "$", "PHP_SELF", ",", "'?'", ",", "$", "this", "->", "id", ";", "?>_next_page=1\"><?php", "echo", "$", "this", "->", "first", ";", "?></a> &nbsp;\n\t<?php", "}", "else", "{", "print", "\"$this->first &nbsp; \"", ";", "}", "}" ]
Display link to first page
[ "Display", "link", "to", "first", "page" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-pager.inc.php#L85-L95
214,395
moodle/moodle
lib/adodb/adodb-pager.inc.php
ADODB_Pager.render_next
function render_next($anchor=true) { global $PHP_SELF; if ($anchor) { ?> <a href="<?php echo $PHP_SELF,'?',$this->id,'_next_page=',$this->rs->AbsolutePage() + 1 ?>"><?php echo $this->next;?></a> &nbsp; <?php } else { print "$this->next &nbsp; "; } }
php
function render_next($anchor=true) { global $PHP_SELF; if ($anchor) { ?> <a href="<?php echo $PHP_SELF,'?',$this->id,'_next_page=',$this->rs->AbsolutePage() + 1 ?>"><?php echo $this->next;?></a> &nbsp; <?php } else { print "$this->next &nbsp; "; } }
[ "function", "render_next", "(", "$", "anchor", "=", "true", ")", "{", "global", "$", "PHP_SELF", ";", "if", "(", "$", "anchor", ")", "{", "?>\n\t\t<a href=\"<?php", "echo", "$", "PHP_SELF", ",", "'?'", ",", "$", "this", "->", "id", ",", "'_next_page='", ",", "$", "this", "->", "rs", "->", "AbsolutePage", "(", ")", "+", "1", "?>\"><?php", "echo", "$", "this", "->", "next", ";", "?></a> &nbsp;\n\t\t<?php", "}", "else", "{", "print", "\"$this->next &nbsp; \"", ";", "}", "}" ]
Display link to next page
[ "Display", "link", "to", "next", "page" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-pager.inc.php#L99-L110
214,396
moodle/moodle
lib/adodb/adodb-pager.inc.php
ADODB_Pager.render_last
function render_last($anchor=true) { global $PHP_SELF; if (!$this->db->pageExecuteCountRows) return; if ($anchor) { ?> <a href="<?php echo $PHP_SELF,'?',$this->id,'_next_page=',$this->rs->LastPageNo() ?>"><?php echo $this->last;?></a> &nbsp; <?php } else { print "$this->last &nbsp; "; } }
php
function render_last($anchor=true) { global $PHP_SELF; if (!$this->db->pageExecuteCountRows) return; if ($anchor) { ?> <a href="<?php echo $PHP_SELF,'?',$this->id,'_next_page=',$this->rs->LastPageNo() ?>"><?php echo $this->last;?></a> &nbsp; <?php } else { print "$this->last &nbsp; "; } }
[ "function", "render_last", "(", "$", "anchor", "=", "true", ")", "{", "global", "$", "PHP_SELF", ";", "if", "(", "!", "$", "this", "->", "db", "->", "pageExecuteCountRows", ")", "return", ";", "if", "(", "$", "anchor", ")", "{", "?>\n\t\t\t<a href=\"<?php", "echo", "$", "PHP_SELF", ",", "'?'", ",", "$", "this", "->", "id", ",", "'_next_page='", ",", "$", "this", "->", "rs", "->", "LastPageNo", "(", ")", "?>\"><?php", "echo", "$", "this", "->", "last", ";", "?></a> &nbsp;\n\t\t<?php", "}", "else", "{", "print", "\"$this->last &nbsp; \"", ";", "}", "}" ]
last page counting.
[ "last", "page", "counting", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-pager.inc.php#L118-L131
214,397
moodle/moodle
lib/adodb/adodb-pager.inc.php
ADODB_Pager.render_pagelinks
function render_pagelinks() { global $PHP_SELF; $pages = $this->rs->LastPageNo(); $linksperpage = $this->linksPerPage ? $this->linksPerPage : $pages; for($i=1; $i <= $pages; $i+=$linksperpage) { if($this->rs->AbsolutePage() >= $i) { $start = $i; } } $numbers = ''; $end = $start+$linksperpage-1; $link = $this->id . "_next_page"; if($end > $pages) $end = $pages; if ($this->startLinks && $start > 1) { $pos = $start - 1; $numbers .= "<a href=$PHP_SELF?$link=$pos>$this->startLinks</a> "; } for($i=$start; $i <= $end; $i++) { if ($this->rs->AbsolutePage() == $i) $numbers .= "<font color=$this->linkSelectedColor><b>$i</b></font> "; else $numbers .= "<a href=$PHP_SELF?$link=$i>$i</a> "; } if ($this->moreLinks && $end < $pages) $numbers .= "<a href=$PHP_SELF?$link=$i>$this->moreLinks</a> "; print $numbers . ' &nbsp; '; }
php
function render_pagelinks() { global $PHP_SELF; $pages = $this->rs->LastPageNo(); $linksperpage = $this->linksPerPage ? $this->linksPerPage : $pages; for($i=1; $i <= $pages; $i+=$linksperpage) { if($this->rs->AbsolutePage() >= $i) { $start = $i; } } $numbers = ''; $end = $start+$linksperpage-1; $link = $this->id . "_next_page"; if($end > $pages) $end = $pages; if ($this->startLinks && $start > 1) { $pos = $start - 1; $numbers .= "<a href=$PHP_SELF?$link=$pos>$this->startLinks</a> "; } for($i=$start; $i <= $end; $i++) { if ($this->rs->AbsolutePage() == $i) $numbers .= "<font color=$this->linkSelectedColor><b>$i</b></font> "; else $numbers .= "<a href=$PHP_SELF?$link=$i>$i</a> "; } if ($this->moreLinks && $end < $pages) $numbers .= "<a href=$PHP_SELF?$link=$i>$this->moreLinks</a> "; print $numbers . ' &nbsp; '; }
[ "function", "render_pagelinks", "(", ")", "{", "global", "$", "PHP_SELF", ";", "$", "pages", "=", "$", "this", "->", "rs", "->", "LastPageNo", "(", ")", ";", "$", "linksperpage", "=", "$", "this", "->", "linksPerPage", "?", "$", "this", "->", "linksPerPage", ":", "$", "pages", ";", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<=", "$", "pages", ";", "$", "i", "+=", "$", "linksperpage", ")", "{", "if", "(", "$", "this", "->", "rs", "->", "AbsolutePage", "(", ")", ">=", "$", "i", ")", "{", "$", "start", "=", "$", "i", ";", "}", "}", "$", "numbers", "=", "''", ";", "$", "end", "=", "$", "start", "+", "$", "linksperpage", "-", "1", ";", "$", "link", "=", "$", "this", "->", "id", ".", "\"_next_page\"", ";", "if", "(", "$", "end", ">", "$", "pages", ")", "$", "end", "=", "$", "pages", ";", "if", "(", "$", "this", "->", "startLinks", "&&", "$", "start", ">", "1", ")", "{", "$", "pos", "=", "$", "start", "-", "1", ";", "$", "numbers", ".=", "\"<a href=$PHP_SELF?$link=$pos>$this->startLinks</a> \"", ";", "}", "for", "(", "$", "i", "=", "$", "start", ";", "$", "i", "<=", "$", "end", ";", "$", "i", "++", ")", "{", "if", "(", "$", "this", "->", "rs", "->", "AbsolutePage", "(", ")", "==", "$", "i", ")", "$", "numbers", ".=", "\"<font color=$this->linkSelectedColor><b>$i</b></font> \"", ";", "else", "$", "numbers", ".=", "\"<a href=$PHP_SELF?$link=$i>$i</a> \"", ";", "}", "if", "(", "$", "this", "->", "moreLinks", "&&", "$", "end", "<", "$", "pages", ")", "$", "numbers", ".=", "\"<a href=$PHP_SELF?$link=$i>$this->moreLinks</a> \"", ";", "print", "$", "numbers", ".", "' &nbsp; '", ";", "}" ]
original code by "Pablo Costa" <pablo@cbsp.com.br>
[ "original", "code", "by", "Pablo", "Costa", "<pablo" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-pager.inc.php#L135-L168
214,398
moodle/moodle
lib/adodb/adodb-pager.inc.php
ADODB_Pager.render_prev
function render_prev($anchor=true) { global $PHP_SELF; if ($anchor) { ?> <a href="<?php echo $PHP_SELF,'?',$this->id,'_next_page=',$this->rs->AbsolutePage() - 1 ?>"><?php echo $this->prev;?></a> &nbsp; <?php } else { print "$this->prev &nbsp; "; } }
php
function render_prev($anchor=true) { global $PHP_SELF; if ($anchor) { ?> <a href="<?php echo $PHP_SELF,'?',$this->id,'_next_page=',$this->rs->AbsolutePage() - 1 ?>"><?php echo $this->prev;?></a> &nbsp; <?php } else { print "$this->prev &nbsp; "; } }
[ "function", "render_prev", "(", "$", "anchor", "=", "true", ")", "{", "global", "$", "PHP_SELF", ";", "if", "(", "$", "anchor", ")", "{", "?>\n\t\t<a href=\"<?php", "echo", "$", "PHP_SELF", ",", "'?'", ",", "$", "this", "->", "id", ",", "'_next_page='", ",", "$", "this", "->", "rs", "->", "AbsolutePage", "(", ")", "-", "1", "?>\"><?php", "echo", "$", "this", "->", "prev", ";", "?></a> &nbsp;\n\t<?php", "}", "else", "{", "print", "\"$this->prev &nbsp; \"", ";", "}", "}" ]
Link to previous page
[ "Link", "to", "previous", "page" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-pager.inc.php#L170-L180
214,399
moodle/moodle
lib/adodb/adodb-pager.inc.php
ADODB_Pager.RenderGrid
function RenderGrid() { global $gSQLBlockRows; // used by rs2html to indicate how many rows to display include_once(ADODB_DIR.'/tohtml.inc.php'); ob_start(); $gSQLBlockRows = $this->rows; rs2html($this->rs,$this->gridAttributes,$this->gridHeader,$this->htmlSpecialChars); $s = ob_get_contents(); ob_end_clean(); return $s; }
php
function RenderGrid() { global $gSQLBlockRows; // used by rs2html to indicate how many rows to display include_once(ADODB_DIR.'/tohtml.inc.php'); ob_start(); $gSQLBlockRows = $this->rows; rs2html($this->rs,$this->gridAttributes,$this->gridHeader,$this->htmlSpecialChars); $s = ob_get_contents(); ob_end_clean(); return $s; }
[ "function", "RenderGrid", "(", ")", "{", "global", "$", "gSQLBlockRows", ";", "// used by rs2html to indicate how many rows to display", "include_once", "(", "ADODB_DIR", ".", "'/tohtml.inc.php'", ")", ";", "ob_start", "(", ")", ";", "$", "gSQLBlockRows", "=", "$", "this", "->", "rows", ";", "rs2html", "(", "$", "this", "->", "rs", ",", "$", "this", "->", "gridAttributes", ",", "$", "this", "->", "gridHeader", ",", "$", "this", "->", "htmlSpecialChars", ")", ";", "$", "s", "=", "ob_get_contents", "(", ")", ";", "ob_end_clean", "(", ")", ";", "return", "$", "s", ";", "}" ]
We use output buffering to keep code clean and readable.
[ "We", "use", "output", "buffering", "to", "keep", "code", "clean", "and", "readable", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-pager.inc.php#L187-L197