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
212,200
moodle/moodle
admin/tool/installaddon/renderer.php
tool_installaddon_renderer.remote_request_permcheck_page
public function remote_request_permcheck_page(stdClass $data, $plugintypepath, moodle_url $continueurl, moodle_url $cancelurl) { $data->typepath = $plugintypepath; $out = $this->output->header(); $out .= $this->output->heading(get_string('installfromrepo', 'tool_installaddon')); $out .= $this->output->confirm(get_string('remoterequestpermcheck', 'tool_installaddon', $data), $continueurl, $cancelurl); $out .= $this->output->footer(); return $out; }
php
public function remote_request_permcheck_page(stdClass $data, $plugintypepath, moodle_url $continueurl, moodle_url $cancelurl) { $data->typepath = $plugintypepath; $out = $this->output->header(); $out .= $this->output->heading(get_string('installfromrepo', 'tool_installaddon')); $out .= $this->output->confirm(get_string('remoterequestpermcheck', 'tool_installaddon', $data), $continueurl, $cancelurl); $out .= $this->output->footer(); return $out; }
[ "public", "function", "remote_request_permcheck_page", "(", "stdClass", "$", "data", ",", "$", "plugintypepath", ",", "moodle_url", "$", "continueurl", ",", "moodle_url", "$", "cancelurl", ")", "{", "$", "data", "->", "typepath", "=", "$", "plugintypepath", ";", "$", "out", "=", "$", "this", "->", "output", "->", "header", "(", ")", ";", "$", "out", ".=", "$", "this", "->", "output", "->", "heading", "(", "get_string", "(", "'installfromrepo'", ",", "'tool_installaddon'", ")", ")", ";", "$", "out", ".=", "$", "this", "->", "output", "->", "confirm", "(", "get_string", "(", "'remoterequestpermcheck'", ",", "'tool_installaddon'", ",", "$", "data", ")", ",", "$", "continueurl", ",", "$", "cancelurl", ")", ";", "$", "out", ".=", "$", "this", "->", "output", "->", "footer", "(", ")", ";", "return", "$", "out", ";", "}" ]
Inform the user that the target plugin type location is not writable. @param stdClass $data decoded request data @param string $plugintypepath full path to the plugin type location @param moodle_url $continueurl to repeat the write permission check @param moodle_url $cancelurl to cancel the installation @return string
[ "Inform", "the", "user", "that", "the", "target", "plugin", "type", "location", "is", "not", "writable", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/installaddon/renderer.php#L160-L170
212,201
moodle/moodle
admin/tool/installaddon/renderer.php
tool_installaddon_renderer.index_page_repository
protected function index_page_repository() { $url = $this->installer->get_addons_repository_url(); $out = $this->box( $this->output->single_button($url, get_string('installfromrepo', 'tool_installaddon'), 'get'). $this->output->help_icon('installfromrepo', 'tool_installaddon'), 'generalbox', 'installfromrepobox' ); return $out; }
php
protected function index_page_repository() { $url = $this->installer->get_addons_repository_url(); $out = $this->box( $this->output->single_button($url, get_string('installfromrepo', 'tool_installaddon'), 'get'). $this->output->help_icon('installfromrepo', 'tool_installaddon'), 'generalbox', 'installfromrepobox' ); return $out; }
[ "protected", "function", "index_page_repository", "(", ")", "{", "$", "url", "=", "$", "this", "->", "installer", "->", "get_addons_repository_url", "(", ")", ";", "$", "out", "=", "$", "this", "->", "box", "(", "$", "this", "->", "output", "->", "single_button", "(", "$", "url", ",", "get_string", "(", "'installfromrepo'", ",", "'tool_installaddon'", ")", ",", "'get'", ")", ".", "$", "this", "->", "output", "->", "help_icon", "(", "'installfromrepo'", ",", "'tool_installaddon'", ")", ",", "'generalbox'", ",", "'installfromrepobox'", ")", ";", "return", "$", "out", ";", "}" ]
Renders the widget for browsing the add-on repository @return string
[ "Renders", "the", "widget", "for", "browsing", "the", "add", "-", "on", "repository" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/installaddon/renderer.php#L206-L217
212,202
moodle/moodle
admin/tool/installaddon/renderer.php
tool_installaddon_renderer.index_page_upload
protected function index_page_upload() { $form = $this->installer->get_installfromzip_form(); ob_start(); $form->display(); $out = ob_get_clean(); $out = $this->box($out, 'generalbox', 'installfromzipbox'); return $out; }
php
protected function index_page_upload() { $form = $this->installer->get_installfromzip_form(); ob_start(); $form->display(); $out = ob_get_clean(); $out = $this->box($out, 'generalbox', 'installfromzipbox'); return $out; }
[ "protected", "function", "index_page_upload", "(", ")", "{", "$", "form", "=", "$", "this", "->", "installer", "->", "get_installfromzip_form", "(", ")", ";", "ob_start", "(", ")", ";", "$", "form", "->", "display", "(", ")", ";", "$", "out", "=", "ob_get_clean", "(", ")", ";", "$", "out", "=", "$", "this", "->", "box", "(", "$", "out", ",", "'generalbox'", ",", "'installfromzipbox'", ")", ";", "return", "$", "out", ";", "}" ]
Renders the widget for uploading the add-on ZIP package @return string
[ "Renders", "the", "widget", "for", "uploading", "the", "add", "-", "on", "ZIP", "package" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/installaddon/renderer.php#L224-L235
212,203
moodle/moodle
completion/classes/privacy/provider.php
provider.get_course_completion_join_sql
public static function get_course_completion_join_sql(int $userid, string $prefix, string $joinfield) : array { $cccalias = "{$prefix}_ccc"; // Course completion criteria. $cmcalias = "{$prefix}_cmc"; // Course modules completion. $ccccalias = "{$prefix}_cccc"; // Course completion criteria completion. $join = "JOIN {course_completion_criteria} {$cccalias} ON {$joinfield} = {$cccalias}.course LEFT JOIN {course_modules_completion} {$cmcalias} ON {$cccalias}.moduleinstance = {$cmcalias}.coursemoduleid AND {$cmcalias}.userid = :{$prefix}_moduleuserid LEFT JOIN {course_completion_crit_compl} {$ccccalias} ON {$ccccalias}.criteriaid = {$cccalias}.id AND {$ccccalias}.userid = :{$prefix}_courseuserid"; $where = "{$cmcalias}.id IS NOT NULL OR {$ccccalias}.id IS NOT NULL"; $params = ["{$prefix}_moduleuserid" => $userid, "{$prefix}_courseuserid" => $userid]; return [$join, $where, $params]; }
php
public static function get_course_completion_join_sql(int $userid, string $prefix, string $joinfield) : array { $cccalias = "{$prefix}_ccc"; // Course completion criteria. $cmcalias = "{$prefix}_cmc"; // Course modules completion. $ccccalias = "{$prefix}_cccc"; // Course completion criteria completion. $join = "JOIN {course_completion_criteria} {$cccalias} ON {$joinfield} = {$cccalias}.course LEFT JOIN {course_modules_completion} {$cmcalias} ON {$cccalias}.moduleinstance = {$cmcalias}.coursemoduleid AND {$cmcalias}.userid = :{$prefix}_moduleuserid LEFT JOIN {course_completion_crit_compl} {$ccccalias} ON {$ccccalias}.criteriaid = {$cccalias}.id AND {$ccccalias}.userid = :{$prefix}_courseuserid"; $where = "{$cmcalias}.id IS NOT NULL OR {$ccccalias}.id IS NOT NULL"; $params = ["{$prefix}_moduleuserid" => $userid, "{$prefix}_courseuserid" => $userid]; return [$join, $where, $params]; }
[ "public", "static", "function", "get_course_completion_join_sql", "(", "int", "$", "userid", ",", "string", "$", "prefix", ",", "string", "$", "joinfield", ")", ":", "array", "{", "$", "cccalias", "=", "\"{$prefix}_ccc\"", ";", "// Course completion criteria.", "$", "cmcalias", "=", "\"{$prefix}_cmc\"", ";", "// Course modules completion.", "$", "ccccalias", "=", "\"{$prefix}_cccc\"", ";", "// Course completion criteria completion.", "$", "join", "=", "\"JOIN {course_completion_criteria} {$cccalias} ON {$joinfield} = {$cccalias}.course\n LEFT JOIN {course_modules_completion} {$cmcalias} ON {$cccalias}.moduleinstance = {$cmcalias}.coursemoduleid\n AND {$cmcalias}.userid = :{$prefix}_moduleuserid\n LEFT JOIN {course_completion_crit_compl} {$ccccalias} ON {$ccccalias}.criteriaid = {$cccalias}.id\n AND {$ccccalias}.userid = :{$prefix}_courseuserid\"", ";", "$", "where", "=", "\"{$cmcalias}.id IS NOT NULL OR {$ccccalias}.id IS NOT NULL\"", ";", "$", "params", "=", "[", "\"{$prefix}_moduleuserid\"", "=>", "$", "userid", ",", "\"{$prefix}_courseuserid\"", "=>", "$", "userid", "]", ";", "return", "[", "$", "join", ",", "$", "where", ",", "$", "params", "]", ";", "}" ]
Get join sql to retrieve courses the user is in. @param int $userid The user ID @param string $prefix A unique prefix for these joins. @param string $joinfield A field to join these tables to. Joins to course ID. @return array The join, where, and params for this join.
[ "Get", "join", "sql", "to", "retrieve", "courses", "the", "user", "is", "in", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/classes/privacy/provider.php#L91-L105
212,204
moodle/moodle
completion/classes/privacy/provider.php
provider.get_activity_completion_info
public static function get_activity_completion_info(\stdClass $user, \stdClass $course, $cm) : \stdClass { $completioninfo = new \completion_info($course); $completion = $completioninfo->is_enabled($cm); return ($completion != COMPLETION_TRACKING_NONE) ? $completioninfo->get_data($cm, true, $user->id) : new \stdClass(); }
php
public static function get_activity_completion_info(\stdClass $user, \stdClass $course, $cm) : \stdClass { $completioninfo = new \completion_info($course); $completion = $completioninfo->is_enabled($cm); return ($completion != COMPLETION_TRACKING_NONE) ? $completioninfo->get_data($cm, true, $user->id) : new \stdClass(); }
[ "public", "static", "function", "get_activity_completion_info", "(", "\\", "stdClass", "$", "user", ",", "\\", "stdClass", "$", "course", ",", "$", "cm", ")", ":", "\\", "stdClass", "{", "$", "completioninfo", "=", "new", "\\", "completion_info", "(", "$", "course", ")", ";", "$", "completion", "=", "$", "completioninfo", "->", "is_enabled", "(", "$", "cm", ")", ";", "return", "(", "$", "completion", "!=", "COMPLETION_TRACKING_NONE", ")", "?", "$", "completioninfo", "->", "get_data", "(", "$", "cm", ",", "true", ",", "$", "user", "->", "id", ")", ":", "new", "\\", "stdClass", "(", ")", ";", "}" ]
Returns activity completion information about a user. @param \stdClass $user The user to return information about. @param \stdClass $course The course the user is in. @param \stdClass $cm Course module information. @return \stdClass Activity completion information.
[ "Returns", "activity", "completion", "information", "about", "a", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/classes/privacy/provider.php#L146-L150
212,205
moodle/moodle
completion/classes/privacy/provider.php
provider.get_course_completion_info
public static function get_course_completion_info(\stdClass $user, \stdClass $course) : array { $completioninfo = new \completion_info($course); $completion = $completioninfo->is_enabled(); if ($completion != COMPLETION_ENABLED) { return []; } $coursecomplete = $completioninfo->is_course_complete($user->id); if ($coursecomplete) { $status = get_string('complete'); } else { $criteriacomplete = $completioninfo->count_course_user_data($user->id); $ccompletion = new \completion_completion(['userid' => $user->id, 'course' => $course->id]); if (!$criteriacomplete && !$ccompletion->timestarted) { $status = get_string('notyetstarted', 'completion'); } else { $status = get_string('inprogress', 'completion'); } } $completions = $completioninfo->get_completions($user->id); $overall = get_string('nocriteriaset', 'completion'); if (!empty($completions)) { if ($completioninfo->get_aggregation_method() == COMPLETION_AGGREGATION_ALL) { $overall = get_string('criteriarequiredall', 'completion'); } else { $overall = get_string('criteriarequiredany', 'completion'); } } $coursecompletiondata = [ 'status' => $status, 'required' => $overall, ]; $coursecompletiondata['criteria'] = array_map(function($completion) use ($completioninfo) { $criteria = $completion->get_criteria(); $aggregation = $completioninfo->get_aggregation_method($criteria->criteriatype); $required = ($aggregation == COMPLETION_AGGREGATION_ALL) ? get_string('all', 'completion') : get_string('any', 'completion'); $data = [ 'required' => $required, 'completed' => transform::yesno($completion->is_complete()), 'timecompleted' => isset($completion->timecompleted) ? transform::datetime($completion->timecompleted) : '' ]; $details = $criteria->get_details($completion); $data = array_merge($data, $details); return $data; }, $completions); return $coursecompletiondata; }
php
public static function get_course_completion_info(\stdClass $user, \stdClass $course) : array { $completioninfo = new \completion_info($course); $completion = $completioninfo->is_enabled(); if ($completion != COMPLETION_ENABLED) { return []; } $coursecomplete = $completioninfo->is_course_complete($user->id); if ($coursecomplete) { $status = get_string('complete'); } else { $criteriacomplete = $completioninfo->count_course_user_data($user->id); $ccompletion = new \completion_completion(['userid' => $user->id, 'course' => $course->id]); if (!$criteriacomplete && !$ccompletion->timestarted) { $status = get_string('notyetstarted', 'completion'); } else { $status = get_string('inprogress', 'completion'); } } $completions = $completioninfo->get_completions($user->id); $overall = get_string('nocriteriaset', 'completion'); if (!empty($completions)) { if ($completioninfo->get_aggregation_method() == COMPLETION_AGGREGATION_ALL) { $overall = get_string('criteriarequiredall', 'completion'); } else { $overall = get_string('criteriarequiredany', 'completion'); } } $coursecompletiondata = [ 'status' => $status, 'required' => $overall, ]; $coursecompletiondata['criteria'] = array_map(function($completion) use ($completioninfo) { $criteria = $completion->get_criteria(); $aggregation = $completioninfo->get_aggregation_method($criteria->criteriatype); $required = ($aggregation == COMPLETION_AGGREGATION_ALL) ? get_string('all', 'completion') : get_string('any', 'completion'); $data = [ 'required' => $required, 'completed' => transform::yesno($completion->is_complete()), 'timecompleted' => isset($completion->timecompleted) ? transform::datetime($completion->timecompleted) : '' ]; $details = $criteria->get_details($completion); $data = array_merge($data, $details); return $data; }, $completions); return $coursecompletiondata; }
[ "public", "static", "function", "get_course_completion_info", "(", "\\", "stdClass", "$", "user", ",", "\\", "stdClass", "$", "course", ")", ":", "array", "{", "$", "completioninfo", "=", "new", "\\", "completion_info", "(", "$", "course", ")", ";", "$", "completion", "=", "$", "completioninfo", "->", "is_enabled", "(", ")", ";", "if", "(", "$", "completion", "!=", "COMPLETION_ENABLED", ")", "{", "return", "[", "]", ";", "}", "$", "coursecomplete", "=", "$", "completioninfo", "->", "is_course_complete", "(", "$", "user", "->", "id", ")", ";", "if", "(", "$", "coursecomplete", ")", "{", "$", "status", "=", "get_string", "(", "'complete'", ")", ";", "}", "else", "{", "$", "criteriacomplete", "=", "$", "completioninfo", "->", "count_course_user_data", "(", "$", "user", "->", "id", ")", ";", "$", "ccompletion", "=", "new", "\\", "completion_completion", "(", "[", "'userid'", "=>", "$", "user", "->", "id", ",", "'course'", "=>", "$", "course", "->", "id", "]", ")", ";", "if", "(", "!", "$", "criteriacomplete", "&&", "!", "$", "ccompletion", "->", "timestarted", ")", "{", "$", "status", "=", "get_string", "(", "'notyetstarted'", ",", "'completion'", ")", ";", "}", "else", "{", "$", "status", "=", "get_string", "(", "'inprogress'", ",", "'completion'", ")", ";", "}", "}", "$", "completions", "=", "$", "completioninfo", "->", "get_completions", "(", "$", "user", "->", "id", ")", ";", "$", "overall", "=", "get_string", "(", "'nocriteriaset'", ",", "'completion'", ")", ";", "if", "(", "!", "empty", "(", "$", "completions", ")", ")", "{", "if", "(", "$", "completioninfo", "->", "get_aggregation_method", "(", ")", "==", "COMPLETION_AGGREGATION_ALL", ")", "{", "$", "overall", "=", "get_string", "(", "'criteriarequiredall'", ",", "'completion'", ")", ";", "}", "else", "{", "$", "overall", "=", "get_string", "(", "'criteriarequiredany'", ",", "'completion'", ")", ";", "}", "}", "$", "coursecompletiondata", "=", "[", "'status'", "=>", "$", "status", ",", "'required'", "=>", "$", "overall", ",", "]", ";", "$", "coursecompletiondata", "[", "'criteria'", "]", "=", "array_map", "(", "function", "(", "$", "completion", ")", "use", "(", "$", "completioninfo", ")", "{", "$", "criteria", "=", "$", "completion", "->", "get_criteria", "(", ")", ";", "$", "aggregation", "=", "$", "completioninfo", "->", "get_aggregation_method", "(", "$", "criteria", "->", "criteriatype", ")", ";", "$", "required", "=", "(", "$", "aggregation", "==", "COMPLETION_AGGREGATION_ALL", ")", "?", "get_string", "(", "'all'", ",", "'completion'", ")", ":", "get_string", "(", "'any'", ",", "'completion'", ")", ";", "$", "data", "=", "[", "'required'", "=>", "$", "required", ",", "'completed'", "=>", "transform", "::", "yesno", "(", "$", "completion", "->", "is_complete", "(", ")", ")", ",", "'timecompleted'", "=>", "isset", "(", "$", "completion", "->", "timecompleted", ")", "?", "transform", "::", "datetime", "(", "$", "completion", "->", "timecompleted", ")", ":", "''", "]", ";", "$", "details", "=", "$", "criteria", "->", "get_details", "(", "$", "completion", ")", ";", "$", "data", "=", "array_merge", "(", "$", "data", ",", "$", "details", ")", ";", "return", "$", "data", ";", "}", ",", "$", "completions", ")", ";", "return", "$", "coursecompletiondata", ";", "}" ]
Returns course completion information for a user. @param \stdClass $user The user that we are getting completion information for. @param \stdClass $course The course we are interested in. @return \stdClass Course completion information.
[ "Returns", "course", "completion", "information", "for", "a", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/classes/privacy/provider.php#L159-L212
212,206
moodle/moodle
completion/classes/privacy/provider.php
provider.delete_completion
public static function delete_completion(\stdClass $user = null, int $courseid = null, int $cmid = null) { global $DB; if (isset($cmid)) { $params = (isset($user)) ? ['userid' => $user->id, 'coursemoduleid' => $cmid] : ['coursemoduleid' => $cmid]; // Only delete the record for course modules completion. $DB->delete_records('course_modules_completion', $params); return; } if (isset($courseid)) { $usersql = isset($user) ? 'AND cmc.userid = :userid' : ''; $params = isset($user) ? ['course' => $courseid, 'userid' => $user->id] : ['course' => $courseid]; // Find records relating to course modules. $sql = "SELECT cmc.id FROM {course_completion_criteria} ccc JOIN {course_modules_completion} cmc ON ccc.moduleinstance = cmc.coursemoduleid WHERE ccc.course = :course $usersql"; $recordids = $DB->get_records_sql($sql, $params); $ids = array_keys($recordids); if (!empty($ids)) { list($deletesql, $deleteparams) = $DB->get_in_or_equal($ids); $deletesql = 'id ' . $deletesql; $DB->delete_records_select('course_modules_completion', $deletesql, $deleteparams); } $DB->delete_records('course_completion_crit_compl', $params); $DB->delete_records('course_completions', $params); } }
php
public static function delete_completion(\stdClass $user = null, int $courseid = null, int $cmid = null) { global $DB; if (isset($cmid)) { $params = (isset($user)) ? ['userid' => $user->id, 'coursemoduleid' => $cmid] : ['coursemoduleid' => $cmid]; // Only delete the record for course modules completion. $DB->delete_records('course_modules_completion', $params); return; } if (isset($courseid)) { $usersql = isset($user) ? 'AND cmc.userid = :userid' : ''; $params = isset($user) ? ['course' => $courseid, 'userid' => $user->id] : ['course' => $courseid]; // Find records relating to course modules. $sql = "SELECT cmc.id FROM {course_completion_criteria} ccc JOIN {course_modules_completion} cmc ON ccc.moduleinstance = cmc.coursemoduleid WHERE ccc.course = :course $usersql"; $recordids = $DB->get_records_sql($sql, $params); $ids = array_keys($recordids); if (!empty($ids)) { list($deletesql, $deleteparams) = $DB->get_in_or_equal($ids); $deletesql = 'id ' . $deletesql; $DB->delete_records_select('course_modules_completion', $deletesql, $deleteparams); } $DB->delete_records('course_completion_crit_compl', $params); $DB->delete_records('course_completions', $params); } }
[ "public", "static", "function", "delete_completion", "(", "\\", "stdClass", "$", "user", "=", "null", ",", "int", "$", "courseid", "=", "null", ",", "int", "$", "cmid", "=", "null", ")", "{", "global", "$", "DB", ";", "if", "(", "isset", "(", "$", "cmid", ")", ")", "{", "$", "params", "=", "(", "isset", "(", "$", "user", ")", ")", "?", "[", "'userid'", "=>", "$", "user", "->", "id", ",", "'coursemoduleid'", "=>", "$", "cmid", "]", ":", "[", "'coursemoduleid'", "=>", "$", "cmid", "]", ";", "// Only delete the record for course modules completion.", "$", "DB", "->", "delete_records", "(", "'course_modules_completion'", ",", "$", "params", ")", ";", "return", ";", "}", "if", "(", "isset", "(", "$", "courseid", ")", ")", "{", "$", "usersql", "=", "isset", "(", "$", "user", ")", "?", "'AND cmc.userid = :userid'", ":", "''", ";", "$", "params", "=", "isset", "(", "$", "user", ")", "?", "[", "'course'", "=>", "$", "courseid", ",", "'userid'", "=>", "$", "user", "->", "id", "]", ":", "[", "'course'", "=>", "$", "courseid", "]", ";", "// Find records relating to course modules.", "$", "sql", "=", "\"SELECT cmc.id\n FROM {course_completion_criteria} ccc\n JOIN {course_modules_completion} cmc ON ccc.moduleinstance = cmc.coursemoduleid\n WHERE ccc.course = :course $usersql\"", ";", "$", "recordids", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "$", "ids", "=", "array_keys", "(", "$", "recordids", ")", ";", "if", "(", "!", "empty", "(", "$", "ids", ")", ")", "{", "list", "(", "$", "deletesql", ",", "$", "deleteparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "ids", ")", ";", "$", "deletesql", "=", "'id '", ".", "$", "deletesql", ";", "$", "DB", "->", "delete_records_select", "(", "'course_modules_completion'", ",", "$", "deletesql", ",", "$", "deleteparams", ")", ";", "}", "$", "DB", "->", "delete_records", "(", "'course_completion_crit_compl'", ",", "$", "params", ")", ";", "$", "DB", "->", "delete_records", "(", "'course_completions'", ",", "$", "params", ")", ";", "}", "}" ]
Delete completion information for users. @param \stdClass $user The user. If provided will delete completion information for just this user. Else all users. @param int $courseid The course id. Provide this if you want course completion and activity completion deleted. @param int $cmid The course module id. Provide this if you only want activity completion deleted.
[ "Delete", "completion", "information", "for", "users", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/classes/privacy/provider.php#L221-L251
212,207
moodle/moodle
completion/classes/privacy/provider.php
provider.delete_completion_by_approved_userlist
public static function delete_completion_by_approved_userlist(approved_userlist $userlist, int $courseid = null, int $cmid = null) { global $DB; $userids = $userlist->get_userids(); if (empty($userids)) { return; } list($useridsql, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED); if (isset($cmid)) { $params['coursemoduleid'] = $cmid; // Only delete the record for course modules completion. $sql = "coursemoduleid = :coursemoduleid AND userid {$useridsql}"; $DB->delete_records_select('course_modules_completion', $sql, $params); return; } if (isset($courseid)) { $params['course'] = $courseid; // Find records relating to course modules. $sql = "SELECT cmc.id FROM {course_completion_criteria} ccc JOIN {course_modules_completion} cmc ON ccc.moduleinstance = cmc.coursemoduleid WHERE ccc.course = :course AND cmc.userid {$useridsql}"; $recordids = $DB->get_records_sql($sql, $params); $ids = array_keys($recordids); if (!empty($ids)) { list($deletesql, $deleteparams) = $DB->get_in_or_equal($ids); $deletesql = 'id ' . $deletesql; $DB->delete_records_select('course_modules_completion', $deletesql, $deleteparams); } $sql = "course = :course AND userid {$useridsql}"; $DB->delete_records_select('course_completion_crit_compl', $sql, $params); $DB->delete_records_select('course_completions', $sql, $params); } }
php
public static function delete_completion_by_approved_userlist(approved_userlist $userlist, int $courseid = null, int $cmid = null) { global $DB; $userids = $userlist->get_userids(); if (empty($userids)) { return; } list($useridsql, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED); if (isset($cmid)) { $params['coursemoduleid'] = $cmid; // Only delete the record for course modules completion. $sql = "coursemoduleid = :coursemoduleid AND userid {$useridsql}"; $DB->delete_records_select('course_modules_completion', $sql, $params); return; } if (isset($courseid)) { $params['course'] = $courseid; // Find records relating to course modules. $sql = "SELECT cmc.id FROM {course_completion_criteria} ccc JOIN {course_modules_completion} cmc ON ccc.moduleinstance = cmc.coursemoduleid WHERE ccc.course = :course AND cmc.userid {$useridsql}"; $recordids = $DB->get_records_sql($sql, $params); $ids = array_keys($recordids); if (!empty($ids)) { list($deletesql, $deleteparams) = $DB->get_in_or_equal($ids); $deletesql = 'id ' . $deletesql; $DB->delete_records_select('course_modules_completion', $deletesql, $deleteparams); } $sql = "course = :course AND userid {$useridsql}"; $DB->delete_records_select('course_completion_crit_compl', $sql, $params); $DB->delete_records_select('course_completions', $sql, $params); } }
[ "public", "static", "function", "delete_completion_by_approved_userlist", "(", "approved_userlist", "$", "userlist", ",", "int", "$", "courseid", "=", "null", ",", "int", "$", "cmid", "=", "null", ")", "{", "global", "$", "DB", ";", "$", "userids", "=", "$", "userlist", "->", "get_userids", "(", ")", ";", "if", "(", "empty", "(", "$", "userids", ")", ")", "{", "return", ";", "}", "list", "(", "$", "useridsql", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "userids", ",", "SQL_PARAMS_NAMED", ")", ";", "if", "(", "isset", "(", "$", "cmid", ")", ")", "{", "$", "params", "[", "'coursemoduleid'", "]", "=", "$", "cmid", ";", "// Only delete the record for course modules completion.", "$", "sql", "=", "\"coursemoduleid = :coursemoduleid AND userid {$useridsql}\"", ";", "$", "DB", "->", "delete_records_select", "(", "'course_modules_completion'", ",", "$", "sql", ",", "$", "params", ")", ";", "return", ";", "}", "if", "(", "isset", "(", "$", "courseid", ")", ")", "{", "$", "params", "[", "'course'", "]", "=", "$", "courseid", ";", "// Find records relating to course modules.", "$", "sql", "=", "\"SELECT cmc.id\n FROM {course_completion_criteria} ccc\n JOIN {course_modules_completion} cmc ON ccc.moduleinstance = cmc.coursemoduleid\n WHERE ccc.course = :course AND cmc.userid {$useridsql}\"", ";", "$", "recordids", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "$", "ids", "=", "array_keys", "(", "$", "recordids", ")", ";", "if", "(", "!", "empty", "(", "$", "ids", ")", ")", "{", "list", "(", "$", "deletesql", ",", "$", "deleteparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "ids", ")", ";", "$", "deletesql", "=", "'id '", ".", "$", "deletesql", ";", "$", "DB", "->", "delete_records_select", "(", "'course_modules_completion'", ",", "$", "deletesql", ",", "$", "deleteparams", ")", ";", "}", "$", "sql", "=", "\"course = :course AND userid {$useridsql}\"", ";", "$", "DB", "->", "delete_records_select", "(", "'course_completion_crit_compl'", ",", "$", "sql", ",", "$", "params", ")", ";", "$", "DB", "->", "delete_records_select", "(", "'course_completions'", ",", "$", "sql", ",", "$", "params", ")", ";", "}", "}" ]
Delete completion information for users within an approved userlist. @param approved_userlist $userlist The approved userlist of users to delete completion information for. @param int $courseid The course id. Provide this if you want course completion and activity completion deleted. @param int $cmid The course module id. Provide this if you only want activity completion deleted.
[ "Delete", "completion", "information", "for", "users", "within", "an", "approved", "userlist", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/completion/classes/privacy/provider.php#L260-L299
212,208
moodle/moodle
lib/simplepie/library/SimplePie/HTTP/Parser.php
SimplePie_HTTP_Parser.is_linear_whitespace
protected function is_linear_whitespace() { return (bool) ($this->data[$this->position] === "\x09" || $this->data[$this->position] === "\x20" || ($this->data[$this->position] === "\x0A" && isset($this->data[$this->position + 1]) && ($this->data[$this->position + 1] === "\x09" || $this->data[$this->position + 1] === "\x20"))); }
php
protected function is_linear_whitespace() { return (bool) ($this->data[$this->position] === "\x09" || $this->data[$this->position] === "\x20" || ($this->data[$this->position] === "\x0A" && isset($this->data[$this->position + 1]) && ($this->data[$this->position + 1] === "\x09" || $this->data[$this->position + 1] === "\x20"))); }
[ "protected", "function", "is_linear_whitespace", "(", ")", "{", "return", "(", "bool", ")", "(", "$", "this", "->", "data", "[", "$", "this", "->", "position", "]", "===", "\"\\x09\"", "||", "$", "this", "->", "data", "[", "$", "this", "->", "position", "]", "===", "\"\\x20\"", "||", "(", "$", "this", "->", "data", "[", "$", "this", "->", "position", "]", "===", "\"\\x0A\"", "&&", "isset", "(", "$", "this", "->", "data", "[", "$", "this", "->", "position", "+", "1", "]", ")", "&&", "(", "$", "this", "->", "data", "[", "$", "this", "->", "position", "+", "1", "]", "===", "\"\\x09\"", "||", "$", "this", "->", "data", "[", "$", "this", "->", "position", "+", "1", "]", "===", "\"\\x20\"", ")", ")", ")", ";", "}" ]
See if the next character is LWS @return bool true if the next character is LWS, false if not
[ "See", "if", "the", "next", "character", "is", "LWS" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/HTTP/Parser.php#L184-L191
212,209
moodle/moodle
lib/simplepie/library/SimplePie/HTTP/Parser.php
SimplePie_HTTP_Parser.http_version
protected function http_version() { if (strpos($this->data, "\x0A") !== false && strtoupper(substr($this->data, 0, 5)) === 'HTTP/') { $len = strspn($this->data, '0123456789.', 5); $this->http_version = substr($this->data, 5, $len); $this->position += 5 + $len; if (substr_count($this->http_version, '.') <= 1) { $this->http_version = (float) $this->http_version; $this->position += strspn($this->data, "\x09\x20", $this->position); $this->state = 'status'; } else { $this->state = false; } } else { $this->state = false; } }
php
protected function http_version() { if (strpos($this->data, "\x0A") !== false && strtoupper(substr($this->data, 0, 5)) === 'HTTP/') { $len = strspn($this->data, '0123456789.', 5); $this->http_version = substr($this->data, 5, $len); $this->position += 5 + $len; if (substr_count($this->http_version, '.') <= 1) { $this->http_version = (float) $this->http_version; $this->position += strspn($this->data, "\x09\x20", $this->position); $this->state = 'status'; } else { $this->state = false; } } else { $this->state = false; } }
[ "protected", "function", "http_version", "(", ")", "{", "if", "(", "strpos", "(", "$", "this", "->", "data", ",", "\"\\x0A\"", ")", "!==", "false", "&&", "strtoupper", "(", "substr", "(", "$", "this", "->", "data", ",", "0", ",", "5", ")", ")", "===", "'HTTP/'", ")", "{", "$", "len", "=", "strspn", "(", "$", "this", "->", "data", ",", "'0123456789.'", ",", "5", ")", ";", "$", "this", "->", "http_version", "=", "substr", "(", "$", "this", "->", "data", ",", "5", ",", "$", "len", ")", ";", "$", "this", "->", "position", "+=", "5", "+", "$", "len", ";", "if", "(", "substr_count", "(", "$", "this", "->", "http_version", ",", "'.'", ")", "<=", "1", ")", "{", "$", "this", "->", "http_version", "=", "(", "float", ")", "$", "this", "->", "http_version", ";", "$", "this", "->", "position", "+=", "strspn", "(", "$", "this", "->", "data", ",", "\"\\x09\\x20\"", ",", "$", "this", "->", "position", ")", ";", "$", "this", "->", "state", "=", "'status'", ";", "}", "else", "{", "$", "this", "->", "state", "=", "false", ";", "}", "}", "else", "{", "$", "this", "->", "state", "=", "false", ";", "}", "}" ]
Parse the HTTP version
[ "Parse", "the", "HTTP", "version" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/HTTP/Parser.php#L196-L218
212,210
moodle/moodle
lib/simplepie/library/SimplePie/HTTP/Parser.php
SimplePie_HTTP_Parser.status
protected function status() { if ($len = strspn($this->data, '0123456789', $this->position)) { $this->status_code = (int) substr($this->data, $this->position, $len); $this->position += $len; $this->state = 'reason'; } else { $this->state = false; } }
php
protected function status() { if ($len = strspn($this->data, '0123456789', $this->position)) { $this->status_code = (int) substr($this->data, $this->position, $len); $this->position += $len; $this->state = 'reason'; } else { $this->state = false; } }
[ "protected", "function", "status", "(", ")", "{", "if", "(", "$", "len", "=", "strspn", "(", "$", "this", "->", "data", ",", "'0123456789'", ",", "$", "this", "->", "position", ")", ")", "{", "$", "this", "->", "status_code", "=", "(", "int", ")", "substr", "(", "$", "this", "->", "data", ",", "$", "this", "->", "position", ",", "$", "len", ")", ";", "$", "this", "->", "position", "+=", "$", "len", ";", "$", "this", "->", "state", "=", "'reason'", ";", "}", "else", "{", "$", "this", "->", "state", "=", "false", ";", "}", "}" ]
Parse the status code
[ "Parse", "the", "status", "code" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/HTTP/Parser.php#L223-L235
212,211
moodle/moodle
lib/simplepie/library/SimplePie/HTTP/Parser.php
SimplePie_HTTP_Parser.reason
protected function reason() { $len = strcspn($this->data, "\x0A", $this->position); $this->reason = trim(substr($this->data, $this->position, $len), "\x09\x0D\x20"); $this->position += $len + 1; $this->state = 'new_line'; }
php
protected function reason() { $len = strcspn($this->data, "\x0A", $this->position); $this->reason = trim(substr($this->data, $this->position, $len), "\x09\x0D\x20"); $this->position += $len + 1; $this->state = 'new_line'; }
[ "protected", "function", "reason", "(", ")", "{", "$", "len", "=", "strcspn", "(", "$", "this", "->", "data", ",", "\"\\x0A\"", ",", "$", "this", "->", "position", ")", ";", "$", "this", "->", "reason", "=", "trim", "(", "substr", "(", "$", "this", "->", "data", ",", "$", "this", "->", "position", ",", "$", "len", ")", ",", "\"\\x09\\x0D\\x20\"", ")", ";", "$", "this", "->", "position", "+=", "$", "len", "+", "1", ";", "$", "this", "->", "state", "=", "'new_line'", ";", "}" ]
Parse the reason phrase
[ "Parse", "the", "reason", "phrase" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/HTTP/Parser.php#L240-L246
212,212
moodle/moodle
lib/simplepie/library/SimplePie/HTTP/Parser.php
SimplePie_HTTP_Parser.new_line
protected function new_line() { $this->value = trim($this->value, "\x0D\x20"); if ($this->name !== '' && $this->value !== '') { $this->name = strtolower($this->name); // We should only use the last Content-Type header. c.f. issue #1 if (isset($this->headers[$this->name]) && $this->name !== 'content-type') { $this->headers[$this->name] .= ', ' . $this->value; } else { $this->headers[$this->name] = $this->value; } } $this->name = ''; $this->value = ''; if (substr($this->data[$this->position], 0, 2) === "\x0D\x0A") { $this->position += 2; $this->state = 'body'; } elseif ($this->data[$this->position] === "\x0A") { $this->position++; $this->state = 'body'; } else { $this->state = 'name'; } }
php
protected function new_line() { $this->value = trim($this->value, "\x0D\x20"); if ($this->name !== '' && $this->value !== '') { $this->name = strtolower($this->name); // We should only use the last Content-Type header. c.f. issue #1 if (isset($this->headers[$this->name]) && $this->name !== 'content-type') { $this->headers[$this->name] .= ', ' . $this->value; } else { $this->headers[$this->name] = $this->value; } } $this->name = ''; $this->value = ''; if (substr($this->data[$this->position], 0, 2) === "\x0D\x0A") { $this->position += 2; $this->state = 'body'; } elseif ($this->data[$this->position] === "\x0A") { $this->position++; $this->state = 'body'; } else { $this->state = 'name'; } }
[ "protected", "function", "new_line", "(", ")", "{", "$", "this", "->", "value", "=", "trim", "(", "$", "this", "->", "value", ",", "\"\\x0D\\x20\"", ")", ";", "if", "(", "$", "this", "->", "name", "!==", "''", "&&", "$", "this", "->", "value", "!==", "''", ")", "{", "$", "this", "->", "name", "=", "strtolower", "(", "$", "this", "->", "name", ")", ";", "// We should only use the last Content-Type header. c.f. issue #1", "if", "(", "isset", "(", "$", "this", "->", "headers", "[", "$", "this", "->", "name", "]", ")", "&&", "$", "this", "->", "name", "!==", "'content-type'", ")", "{", "$", "this", "->", "headers", "[", "$", "this", "->", "name", "]", ".=", "', '", ".", "$", "this", "->", "value", ";", "}", "else", "{", "$", "this", "->", "headers", "[", "$", "this", "->", "name", "]", "=", "$", "this", "->", "value", ";", "}", "}", "$", "this", "->", "name", "=", "''", ";", "$", "this", "->", "value", "=", "''", ";", "if", "(", "substr", "(", "$", "this", "->", "data", "[", "$", "this", "->", "position", "]", ",", "0", ",", "2", ")", "===", "\"\\x0D\\x0A\"", ")", "{", "$", "this", "->", "position", "+=", "2", ";", "$", "this", "->", "state", "=", "'body'", ";", "}", "elseif", "(", "$", "this", "->", "data", "[", "$", "this", "->", "position", "]", "===", "\"\\x0A\"", ")", "{", "$", "this", "->", "position", "++", ";", "$", "this", "->", "state", "=", "'body'", ";", "}", "else", "{", "$", "this", "->", "state", "=", "'name'", ";", "}", "}" ]
Deal with a new line, shifting data around as needed
[ "Deal", "with", "a", "new", "line", "shifting", "data", "around", "as", "needed" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/HTTP/Parser.php#L251-L283
212,213
moodle/moodle
lib/simplepie/library/SimplePie/HTTP/Parser.php
SimplePie_HTTP_Parser.name
protected function name() { $len = strcspn($this->data, "\x0A:", $this->position); if (isset($this->data[$this->position + $len])) { if ($this->data[$this->position + $len] === "\x0A") { $this->position += $len; $this->state = 'new_line'; } else { $this->name = substr($this->data, $this->position, $len); $this->position += $len + 1; $this->state = 'value'; } } else { $this->state = false; } }
php
protected function name() { $len = strcspn($this->data, "\x0A:", $this->position); if (isset($this->data[$this->position + $len])) { if ($this->data[$this->position + $len] === "\x0A") { $this->position += $len; $this->state = 'new_line'; } else { $this->name = substr($this->data, $this->position, $len); $this->position += $len + 1; $this->state = 'value'; } } else { $this->state = false; } }
[ "protected", "function", "name", "(", ")", "{", "$", "len", "=", "strcspn", "(", "$", "this", "->", "data", ",", "\"\\x0A:\"", ",", "$", "this", "->", "position", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "data", "[", "$", "this", "->", "position", "+", "$", "len", "]", ")", ")", "{", "if", "(", "$", "this", "->", "data", "[", "$", "this", "->", "position", "+", "$", "len", "]", "===", "\"\\x0A\"", ")", "{", "$", "this", "->", "position", "+=", "$", "len", ";", "$", "this", "->", "state", "=", "'new_line'", ";", "}", "else", "{", "$", "this", "->", "name", "=", "substr", "(", "$", "this", "->", "data", ",", "$", "this", "->", "position", ",", "$", "len", ")", ";", "$", "this", "->", "position", "+=", "$", "len", "+", "1", ";", "$", "this", "->", "state", "=", "'value'", ";", "}", "}", "else", "{", "$", "this", "->", "state", "=", "false", ";", "}", "}" ]
Parse a header name
[ "Parse", "a", "header", "name" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/HTTP/Parser.php#L288-L309
212,214
moodle/moodle
lib/simplepie/library/SimplePie/HTTP/Parser.php
SimplePie_HTTP_Parser.linear_whitespace
protected function linear_whitespace() { do { if (substr($this->data, $this->position, 2) === "\x0D\x0A") { $this->position += 2; } elseif ($this->data[$this->position] === "\x0A") { $this->position++; } $this->position += strspn($this->data, "\x09\x20", $this->position); } while ($this->has_data() && $this->is_linear_whitespace()); $this->value .= "\x20"; }
php
protected function linear_whitespace() { do { if (substr($this->data, $this->position, 2) === "\x0D\x0A") { $this->position += 2; } elseif ($this->data[$this->position] === "\x0A") { $this->position++; } $this->position += strspn($this->data, "\x09\x20", $this->position); } while ($this->has_data() && $this->is_linear_whitespace()); $this->value .= "\x20"; }
[ "protected", "function", "linear_whitespace", "(", ")", "{", "do", "{", "if", "(", "substr", "(", "$", "this", "->", "data", ",", "$", "this", "->", "position", ",", "2", ")", "===", "\"\\x0D\\x0A\"", ")", "{", "$", "this", "->", "position", "+=", "2", ";", "}", "elseif", "(", "$", "this", "->", "data", "[", "$", "this", "->", "position", "]", "===", "\"\\x0A\"", ")", "{", "$", "this", "->", "position", "++", ";", "}", "$", "this", "->", "position", "+=", "strspn", "(", "$", "this", "->", "data", ",", "\"\\x09\\x20\"", ",", "$", "this", "->", "position", ")", ";", "}", "while", "(", "$", "this", "->", "has_data", "(", ")", "&&", "$", "this", "->", "is_linear_whitespace", "(", ")", ")", ";", "$", "this", "->", "value", ".=", "\"\\x20\"", ";", "}" ]
Parse LWS, replacing consecutive LWS characters with a single space
[ "Parse", "LWS", "replacing", "consecutive", "LWS", "characters", "with", "a", "single", "space" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/HTTP/Parser.php#L314-L329
212,215
moodle/moodle
lib/simplepie/library/SimplePie/HTTP/Parser.php
SimplePie_HTTP_Parser.value
protected function value() { if ($this->is_linear_whitespace()) { $this->linear_whitespace(); } else { switch ($this->data[$this->position]) { case '"': // Workaround for ETags: we have to include the quotes as // part of the tag. if (strtolower($this->name) === 'etag') { $this->value .= '"'; $this->position++; $this->state = 'value_char'; break; } $this->position++; $this->state = 'quote'; break; case "\x0A": $this->position++; $this->state = 'new_line'; break; default: $this->state = 'value_char'; break; } } }
php
protected function value() { if ($this->is_linear_whitespace()) { $this->linear_whitespace(); } else { switch ($this->data[$this->position]) { case '"': // Workaround for ETags: we have to include the quotes as // part of the tag. if (strtolower($this->name) === 'etag') { $this->value .= '"'; $this->position++; $this->state = 'value_char'; break; } $this->position++; $this->state = 'quote'; break; case "\x0A": $this->position++; $this->state = 'new_line'; break; default: $this->state = 'value_char'; break; } } }
[ "protected", "function", "value", "(", ")", "{", "if", "(", "$", "this", "->", "is_linear_whitespace", "(", ")", ")", "{", "$", "this", "->", "linear_whitespace", "(", ")", ";", "}", "else", "{", "switch", "(", "$", "this", "->", "data", "[", "$", "this", "->", "position", "]", ")", "{", "case", "'\"'", ":", "// Workaround for ETags: we have to include the quotes as", "// part of the tag.", "if", "(", "strtolower", "(", "$", "this", "->", "name", ")", "===", "'etag'", ")", "{", "$", "this", "->", "value", ".=", "'\"'", ";", "$", "this", "->", "position", "++", ";", "$", "this", "->", "state", "=", "'value_char'", ";", "break", ";", "}", "$", "this", "->", "position", "++", ";", "$", "this", "->", "state", "=", "'quote'", ";", "break", ";", "case", "\"\\x0A\"", ":", "$", "this", "->", "position", "++", ";", "$", "this", "->", "state", "=", "'new_line'", ";", "break", ";", "default", ":", "$", "this", "->", "state", "=", "'value_char'", ";", "break", ";", "}", "}", "}" ]
See what state to move to while within non-quoted header values
[ "See", "what", "state", "to", "move", "to", "while", "within", "non", "-", "quoted", "header", "values" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/HTTP/Parser.php#L334-L368
212,216
moodle/moodle
lib/simplepie/library/SimplePie/HTTP/Parser.php
SimplePie_HTTP_Parser.value_char
protected function value_char() { $len = strcspn($this->data, "\x09\x20\x0A\"", $this->position); $this->value .= substr($this->data, $this->position, $len); $this->position += $len; $this->state = 'value'; }
php
protected function value_char() { $len = strcspn($this->data, "\x09\x20\x0A\"", $this->position); $this->value .= substr($this->data, $this->position, $len); $this->position += $len; $this->state = 'value'; }
[ "protected", "function", "value_char", "(", ")", "{", "$", "len", "=", "strcspn", "(", "$", "this", "->", "data", ",", "\"\\x09\\x20\\x0A\\\"\"", ",", "$", "this", "->", "position", ")", ";", "$", "this", "->", "value", ".=", "substr", "(", "$", "this", "->", "data", ",", "$", "this", "->", "position", ",", "$", "len", ")", ";", "$", "this", "->", "position", "+=", "$", "len", ";", "$", "this", "->", "state", "=", "'value'", ";", "}" ]
Parse a header value while outside quotes
[ "Parse", "a", "header", "value", "while", "outside", "quotes" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/HTTP/Parser.php#L373-L379
212,217
moodle/moodle
lib/simplepie/library/SimplePie/HTTP/Parser.php
SimplePie_HTTP_Parser.quote
protected function quote() { if ($this->is_linear_whitespace()) { $this->linear_whitespace(); } else { switch ($this->data[$this->position]) { case '"': $this->position++; $this->state = 'value'; break; case "\x0A": $this->position++; $this->state = 'new_line'; break; case '\\': $this->position++; $this->state = 'quote_escaped'; break; default: $this->state = 'quote_char'; break; } } }
php
protected function quote() { if ($this->is_linear_whitespace()) { $this->linear_whitespace(); } else { switch ($this->data[$this->position]) { case '"': $this->position++; $this->state = 'value'; break; case "\x0A": $this->position++; $this->state = 'new_line'; break; case '\\': $this->position++; $this->state = 'quote_escaped'; break; default: $this->state = 'quote_char'; break; } } }
[ "protected", "function", "quote", "(", ")", "{", "if", "(", "$", "this", "->", "is_linear_whitespace", "(", ")", ")", "{", "$", "this", "->", "linear_whitespace", "(", ")", ";", "}", "else", "{", "switch", "(", "$", "this", "->", "data", "[", "$", "this", "->", "position", "]", ")", "{", "case", "'\"'", ":", "$", "this", "->", "position", "++", ";", "$", "this", "->", "state", "=", "'value'", ";", "break", ";", "case", "\"\\x0A\"", ":", "$", "this", "->", "position", "++", ";", "$", "this", "->", "state", "=", "'new_line'", ";", "break", ";", "case", "'\\\\'", ":", "$", "this", "->", "position", "++", ";", "$", "this", "->", "state", "=", "'quote_escaped'", ";", "break", ";", "default", ":", "$", "this", "->", "state", "=", "'quote_char'", ";", "break", ";", "}", "}", "}" ]
See what state to move to while within quoted header values
[ "See", "what", "state", "to", "move", "to", "while", "within", "quoted", "header", "values" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/HTTP/Parser.php#L384-L414
212,218
moodle/moodle
lib/simplepie/library/SimplePie/HTTP/Parser.php
SimplePie_HTTP_Parser.quote_escaped
protected function quote_escaped() { $this->value .= $this->data[$this->position]; $this->position++; $this->state = 'quote'; }
php
protected function quote_escaped() { $this->value .= $this->data[$this->position]; $this->position++; $this->state = 'quote'; }
[ "protected", "function", "quote_escaped", "(", ")", "{", "$", "this", "->", "value", ".=", "$", "this", "->", "data", "[", "$", "this", "->", "position", "]", ";", "$", "this", "->", "position", "++", ";", "$", "this", "->", "state", "=", "'quote'", ";", "}" ]
Parse an escaped character within quotes
[ "Parse", "an", "escaped", "character", "within", "quotes" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/HTTP/Parser.php#L430-L435
212,219
moodle/moodle
lib/simplepie/library/SimplePie/HTTP/Parser.php
SimplePie_HTTP_Parser.body
protected function body() { $this->body = substr($this->data, $this->position); if (!empty($this->headers['transfer-encoding'])) { unset($this->headers['transfer-encoding']); $this->state = 'chunked'; } else { $this->state = 'emit'; } }
php
protected function body() { $this->body = substr($this->data, $this->position); if (!empty($this->headers['transfer-encoding'])) { unset($this->headers['transfer-encoding']); $this->state = 'chunked'; } else { $this->state = 'emit'; } }
[ "protected", "function", "body", "(", ")", "{", "$", "this", "->", "body", "=", "substr", "(", "$", "this", "->", "data", ",", "$", "this", "->", "position", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "headers", "[", "'transfer-encoding'", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "headers", "[", "'transfer-encoding'", "]", ")", ";", "$", "this", "->", "state", "=", "'chunked'", ";", "}", "else", "{", "$", "this", "->", "state", "=", "'emit'", ";", "}", "}" ]
Parse the body
[ "Parse", "the", "body" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/simplepie/library/SimplePie/HTTP/Parser.php#L440-L452
212,220
moodle/moodle
cache/stores/mongodb/MongoDB/UpdateResult.php
UpdateResult.getUpsertedId
public function getUpsertedId() { if ($this->isAcknowledged) { foreach ($this->writeResult->getUpsertedIds() as $id) { return $id; } return null; } throw BadMethodCallException::unacknowledgedWriteResultAccess(__METHOD__); }
php
public function getUpsertedId() { if ($this->isAcknowledged) { foreach ($this->writeResult->getUpsertedIds() as $id) { return $id; } return null; } throw BadMethodCallException::unacknowledgedWriteResultAccess(__METHOD__); }
[ "public", "function", "getUpsertedId", "(", ")", "{", "if", "(", "$", "this", "->", "isAcknowledged", ")", "{", "foreach", "(", "$", "this", "->", "writeResult", "->", "getUpsertedIds", "(", ")", "as", "$", "id", ")", "{", "return", "$", "id", ";", "}", "return", "null", ";", "}", "throw", "BadMethodCallException", "::", "unacknowledgedWriteResultAccess", "(", "__METHOD__", ")", ";", "}" ]
Return the ID of the document inserted by an upsert operation. If the document had an ID prior to upserting (i.e. the server did not need to generate an ID), this will contain its "_id". Any server-generated ID will be a MongoDB\BSON\ObjectId instance. This value is undefined (i.e. null) if an upsert did not take place. This method should only be called if the write was acknowledged. @see UpdateResult::isAcknowledged() @return mixed|null @throws BadMethodCallException is the write result is unacknowledged
[ "Return", "the", "ID", "of", "the", "document", "inserted", "by", "an", "upsert", "operation", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/UpdateResult.php#L114-L125
212,221
moodle/moodle
auth/classes/digital_consent.php
digital_consent.is_minor
public static function is_minor($age, $country) { global $CFG; $ageconsentmap = $CFG->agedigitalconsentmap; $agedigitalconsentmap = self::parse_age_digital_consent_map($ageconsentmap); return array_key_exists($country, $agedigitalconsentmap) ? $age < $agedigitalconsentmap[$country] : $age < $agedigitalconsentmap['*']; }
php
public static function is_minor($age, $country) { global $CFG; $ageconsentmap = $CFG->agedigitalconsentmap; $agedigitalconsentmap = self::parse_age_digital_consent_map($ageconsentmap); return array_key_exists($country, $agedigitalconsentmap) ? $age < $agedigitalconsentmap[$country] : $age < $agedigitalconsentmap['*']; }
[ "public", "static", "function", "is_minor", "(", "$", "age", ",", "$", "country", ")", "{", "global", "$", "CFG", ";", "$", "ageconsentmap", "=", "$", "CFG", "->", "agedigitalconsentmap", ";", "$", "agedigitalconsentmap", "=", "self", "::", "parse_age_digital_consent_map", "(", "$", "ageconsentmap", ")", ";", "return", "array_key_exists", "(", "$", "country", ",", "$", "agedigitalconsentmap", ")", "?", "$", "age", "<", "$", "agedigitalconsentmap", "[", "$", "country", "]", ":", "$", "age", "<", "$", "agedigitalconsentmap", "[", "'*'", "]", ";", "}" ]
Checks if a user is a digital minor. @param int $age @param string $country The country code (ISO 3166-2) @return bool
[ "Checks", "if", "a", "user", "is", "a", "digital", "minor", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/classes/digital_consent.php#L55-L63
212,222
moodle/moodle
auth/classes/digital_consent.php
digital_consent.parse_age_digital_consent_map
public static function parse_age_digital_consent_map($ageconsentmap) { $ageconsentmapparsed = array(); $countries = get_string_manager()->get_list_of_countries(true); $isdefaultvaluepresent = false; $lines = preg_split('/\r|\n/', $ageconsentmap, -1, PREG_SPLIT_NO_EMPTY); foreach ($lines as $line) { $arr = explode(",", $line); // Handle if there is more or less than one comma separator. if (count($arr) != 2) { throw new \moodle_exception('agedigitalconsentmapinvalidcomma', 'error', '', $line); } $country = trim($arr[0]); $age = trim($arr[1]); // Check if default. if ($country == "*") { $isdefaultvaluepresent = true; } // Handle if the presented value for country is not valid. if ($country !== "*" && !array_key_exists($country, $countries)) { throw new \moodle_exception('agedigitalconsentmapinvalidcountry', 'error', '', $country); } // Handle if the presented value for age is not valid. if (!is_numeric($age)) { throw new \moodle_exception('agedigitalconsentmapinvalidage', 'error', '', $age); } $ageconsentmapparsed[$country] = $age; } // Handle if a default value does not exist. if (!$isdefaultvaluepresent) { throw new \moodle_exception('agedigitalconsentmapinvaliddefault'); } return $ageconsentmapparsed; }
php
public static function parse_age_digital_consent_map($ageconsentmap) { $ageconsentmapparsed = array(); $countries = get_string_manager()->get_list_of_countries(true); $isdefaultvaluepresent = false; $lines = preg_split('/\r|\n/', $ageconsentmap, -1, PREG_SPLIT_NO_EMPTY); foreach ($lines as $line) { $arr = explode(",", $line); // Handle if there is more or less than one comma separator. if (count($arr) != 2) { throw new \moodle_exception('agedigitalconsentmapinvalidcomma', 'error', '', $line); } $country = trim($arr[0]); $age = trim($arr[1]); // Check if default. if ($country == "*") { $isdefaultvaluepresent = true; } // Handle if the presented value for country is not valid. if ($country !== "*" && !array_key_exists($country, $countries)) { throw new \moodle_exception('agedigitalconsentmapinvalidcountry', 'error', '', $country); } // Handle if the presented value for age is not valid. if (!is_numeric($age)) { throw new \moodle_exception('agedigitalconsentmapinvalidage', 'error', '', $age); } $ageconsentmapparsed[$country] = $age; } // Handle if a default value does not exist. if (!$isdefaultvaluepresent) { throw new \moodle_exception('agedigitalconsentmapinvaliddefault'); } return $ageconsentmapparsed; }
[ "public", "static", "function", "parse_age_digital_consent_map", "(", "$", "ageconsentmap", ")", "{", "$", "ageconsentmapparsed", "=", "array", "(", ")", ";", "$", "countries", "=", "get_string_manager", "(", ")", "->", "get_list_of_countries", "(", "true", ")", ";", "$", "isdefaultvaluepresent", "=", "false", ";", "$", "lines", "=", "preg_split", "(", "'/\\r|\\n/'", ",", "$", "ageconsentmap", ",", "-", "1", ",", "PREG_SPLIT_NO_EMPTY", ")", ";", "foreach", "(", "$", "lines", "as", "$", "line", ")", "{", "$", "arr", "=", "explode", "(", "\",\"", ",", "$", "line", ")", ";", "// Handle if there is more or less than one comma separator.", "if", "(", "count", "(", "$", "arr", ")", "!=", "2", ")", "{", "throw", "new", "\\", "moodle_exception", "(", "'agedigitalconsentmapinvalidcomma'", ",", "'error'", ",", "''", ",", "$", "line", ")", ";", "}", "$", "country", "=", "trim", "(", "$", "arr", "[", "0", "]", ")", ";", "$", "age", "=", "trim", "(", "$", "arr", "[", "1", "]", ")", ";", "// Check if default.", "if", "(", "$", "country", "==", "\"*\"", ")", "{", "$", "isdefaultvaluepresent", "=", "true", ";", "}", "// Handle if the presented value for country is not valid.", "if", "(", "$", "country", "!==", "\"*\"", "&&", "!", "array_key_exists", "(", "$", "country", ",", "$", "countries", ")", ")", "{", "throw", "new", "\\", "moodle_exception", "(", "'agedigitalconsentmapinvalidcountry'", ",", "'error'", ",", "''", ",", "$", "country", ")", ";", "}", "// Handle if the presented value for age is not valid.", "if", "(", "!", "is_numeric", "(", "$", "age", ")", ")", "{", "throw", "new", "\\", "moodle_exception", "(", "'agedigitalconsentmapinvalidage'", ",", "'error'", ",", "''", ",", "$", "age", ")", ";", "}", "$", "ageconsentmapparsed", "[", "$", "country", "]", "=", "$", "age", ";", "}", "// Handle if a default value does not exist.", "if", "(", "!", "$", "isdefaultvaluepresent", ")", "{", "throw", "new", "\\", "moodle_exception", "(", "'agedigitalconsentmapinvaliddefault'", ")", ";", "}", "return", "$", "ageconsentmapparsed", ";", "}" ]
Parse the agedigitalconsentmap setting into an array. @param string $ageconsentmap The value of the agedigitalconsentmap setting @return array $ageconsentmapparsed
[ "Parse", "the", "agedigitalconsentmap", "setting", "into", "an", "array", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/classes/digital_consent.php#L71-L105
212,223
moodle/moodle
webservice/classes/token_table.php
token_table.col_operation
public function col_operation($data) { $tokenpageurl = new \moodle_url( "/admin/webservice/tokens.php", [ "sesskey" => sesskey(), "action" => "delete", "tokenid" => $data->id ] ); return \html_writer::link($tokenpageurl, get_string("delete")); }
php
public function col_operation($data) { $tokenpageurl = new \moodle_url( "/admin/webservice/tokens.php", [ "sesskey" => sesskey(), "action" => "delete", "tokenid" => $data->id ] ); return \html_writer::link($tokenpageurl, get_string("delete")); }
[ "public", "function", "col_operation", "(", "$", "data", ")", "{", "$", "tokenpageurl", "=", "new", "\\", "moodle_url", "(", "\"/admin/webservice/tokens.php\"", ",", "[", "\"sesskey\"", "=>", "sesskey", "(", ")", ",", "\"action\"", "=>", "\"delete\"", ",", "\"tokenid\"", "=>", "$", "data", "->", "id", "]", ")", ";", "return", "\\", "html_writer", "::", "link", "(", "$", "tokenpageurl", ",", "get_string", "(", "\"delete\"", ")", ")", ";", "}" ]
Generate the operation column. @param \stdClass $data Data for the current row @return string Content for the column
[ "Generate", "the", "operation", "column", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/webservice/classes/token_table.php#L98-L108
212,224
moodle/moodle
webservice/classes/token_table.php
token_table.col_creatorlastname
public function col_creatorlastname($data) { // We have loaded all the name fields for the creator, with the 'creator' prefix. // So just remove the prefix and make up a user object. $user = []; foreach ($data as $key => $value) { if (strpos($key, 'creator') !== false) { $newkey = str_replace('creator', '', $key); $user[$newkey] = $value; } } $creatorprofileurl = new \moodle_url('/user/profile.php', ['id' => $data->creatorid]); return \html_writer::link($creatorprofileurl, fullname((object)$user)); }
php
public function col_creatorlastname($data) { // We have loaded all the name fields for the creator, with the 'creator' prefix. // So just remove the prefix and make up a user object. $user = []; foreach ($data as $key => $value) { if (strpos($key, 'creator') !== false) { $newkey = str_replace('creator', '', $key); $user[$newkey] = $value; } } $creatorprofileurl = new \moodle_url('/user/profile.php', ['id' => $data->creatorid]); return \html_writer::link($creatorprofileurl, fullname((object)$user)); }
[ "public", "function", "col_creatorlastname", "(", "$", "data", ")", "{", "// We have loaded all the name fields for the creator, with the 'creator' prefix.", "// So just remove the prefix and make up a user object.", "$", "user", "=", "[", "]", ";", "foreach", "(", "$", "data", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "strpos", "(", "$", "key", ",", "'creator'", ")", "!==", "false", ")", "{", "$", "newkey", "=", "str_replace", "(", "'creator'", ",", "''", ",", "$", "key", ")", ";", "$", "user", "[", "$", "newkey", "]", "=", "$", "value", ";", "}", "}", "$", "creatorprofileurl", "=", "new", "\\", "moodle_url", "(", "'/user/profile.php'", ",", "[", "'id'", "=>", "$", "data", "->", "creatorid", "]", ")", ";", "return", "\\", "html_writer", "::", "link", "(", "$", "creatorprofileurl", ",", "fullname", "(", "(", "object", ")", "$", "user", ")", ")", ";", "}" ]
Generate the creator column. @param \stdClass $data @return string
[ "Generate", "the", "creator", "column", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/webservice/classes/token_table.php#L174-L187
212,225
moodle/moodle
mod/lti/classes/local/ltiservice/resource_base.php
resource_base.get_endpoint
public function get_endpoint() { $this->parse_template(); $url = $this->get_service()->get_service_path() . $this->get_template(); foreach ($this->params as $key => $value) { $url = str_replace('{' . $key . '}', $value, $url); } $toolproxy = $this->get_service()->get_tool_proxy(); if (!empty($toolproxy)) { $url = str_replace('{tool_proxy_id}', $toolproxy->guid, $url); } return $url; }
php
public function get_endpoint() { $this->parse_template(); $url = $this->get_service()->get_service_path() . $this->get_template(); foreach ($this->params as $key => $value) { $url = str_replace('{' . $key . '}', $value, $url); } $toolproxy = $this->get_service()->get_tool_proxy(); if (!empty($toolproxy)) { $url = str_replace('{tool_proxy_id}', $toolproxy->guid, $url); } return $url; }
[ "public", "function", "get_endpoint", "(", ")", "{", "$", "this", "->", "parse_template", "(", ")", ";", "$", "url", "=", "$", "this", "->", "get_service", "(", ")", "->", "get_service_path", "(", ")", ".", "$", "this", "->", "get_template", "(", ")", ";", "foreach", "(", "$", "this", "->", "params", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "url", "=", "str_replace", "(", "'{'", ".", "$", "key", ".", "'}'", ",", "$", "value", ",", "$", "url", ")", ";", "}", "$", "toolproxy", "=", "$", "this", "->", "get_service", "(", ")", "->", "get_tool_proxy", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "toolproxy", ")", ")", "{", "$", "url", "=", "str_replace", "(", "'{tool_proxy_id}'", ",", "$", "toolproxy", "->", "guid", ",", "$", "url", ")", ";", "}", "return", "$", "url", ";", "}" ]
Get the resource fully qualified endpoint. @return string
[ "Get", "the", "resource", "fully", "qualified", "endpoint", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lti/classes/local/ltiservice/resource_base.php#L184-L198
212,226
moodle/moodle
mod/lti/classes/local/ltiservice/resource_base.php
resource_base.parse_template
protected function parse_template() { if (empty($this->params)) { $this->params = array(); if (isset($_SERVER['PATH_INFO']) && !empty($_SERVER['PATH_INFO'])) { $path = explode('/', $_SERVER['PATH_INFO']); $parts = explode('/', $this->get_template()); for ($i = 0; $i < count($parts); $i++) { if ((substr($parts[$i], 0, 1) == '{') && (substr($parts[$i], -1) == '}')) { $value = ''; if ($i < count($path)) { $value = $path[$i]; } $this->params[substr($parts[$i], 1, -1)] = $value; } } } } return $this->params; }
php
protected function parse_template() { if (empty($this->params)) { $this->params = array(); if (isset($_SERVER['PATH_INFO']) && !empty($_SERVER['PATH_INFO'])) { $path = explode('/', $_SERVER['PATH_INFO']); $parts = explode('/', $this->get_template()); for ($i = 0; $i < count($parts); $i++) { if ((substr($parts[$i], 0, 1) == '{') && (substr($parts[$i], -1) == '}')) { $value = ''; if ($i < count($path)) { $value = $path[$i]; } $this->params[substr($parts[$i], 1, -1)] = $value; } } } } return $this->params; }
[ "protected", "function", "parse_template", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "params", ")", ")", "{", "$", "this", "->", "params", "=", "array", "(", ")", ";", "if", "(", "isset", "(", "$", "_SERVER", "[", "'PATH_INFO'", "]", ")", "&&", "!", "empty", "(", "$", "_SERVER", "[", "'PATH_INFO'", "]", ")", ")", "{", "$", "path", "=", "explode", "(", "'/'", ",", "$", "_SERVER", "[", "'PATH_INFO'", "]", ")", ";", "$", "parts", "=", "explode", "(", "'/'", ",", "$", "this", "->", "get_template", "(", ")", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "parts", ")", ";", "$", "i", "++", ")", "{", "if", "(", "(", "substr", "(", "$", "parts", "[", "$", "i", "]", ",", "0", ",", "1", ")", "==", "'{'", ")", "&&", "(", "substr", "(", "$", "parts", "[", "$", "i", "]", ",", "-", "1", ")", "==", "'}'", ")", ")", "{", "$", "value", "=", "''", ";", "if", "(", "$", "i", "<", "count", "(", "$", "path", ")", ")", "{", "$", "value", "=", "$", "path", "[", "$", "i", "]", ";", "}", "$", "this", "->", "params", "[", "substr", "(", "$", "parts", "[", "$", "i", "]", ",", "1", ",", "-", "1", ")", "]", "=", "$", "value", ";", "}", "}", "}", "}", "return", "$", "this", "->", "params", ";", "}" ]
Parse the template for variables. @return array
[ "Parse", "the", "template", "for", "variables", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/lti/classes/local/ltiservice/resource_base.php#L303-L324
212,227
moodle/moodle
lib/classes/task/clean_up_deleted_search_area_task.php
clean_up_deleted_search_area_task.execute
public function execute() { $areaid = $this->get_custom_data(); try { \core_search\manager::clean_up_non_existing_area($areaid); } catch (\core_search\engine_exception $e) { mtrace('Search is not configured. Skip deleting index for search area ' . $areaid); } }
php
public function execute() { $areaid = $this->get_custom_data(); try { \core_search\manager::clean_up_non_existing_area($areaid); } catch (\core_search\engine_exception $e) { mtrace('Search is not configured. Skip deleting index for search area ' . $areaid); } }
[ "public", "function", "execute", "(", ")", "{", "$", "areaid", "=", "$", "this", "->", "get_custom_data", "(", ")", ";", "try", "{", "\\", "core_search", "\\", "manager", "::", "clean_up_non_existing_area", "(", "$", "areaid", ")", ";", "}", "catch", "(", "\\", "core_search", "\\", "engine_exception", "$", "e", ")", "{", "mtrace", "(", "'Search is not configured. Skip deleting index for search area '", ".", "$", "areaid", ")", ";", "}", "}" ]
Run the task to clean up deleted search are data.
[ "Run", "the", "task", "to", "clean", "up", "deleted", "search", "are", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/task/clean_up_deleted_search_area_task.php#L44-L52
212,228
moodle/moodle
lib/blocklib.php
block_manager.get_regions
public function get_regions() { if (is_null($this->defaultregion)) { $this->page->initialise_theme_and_output(); } return array_keys($this->regions); }
php
public function get_regions() { if (is_null($this->defaultregion)) { $this->page->initialise_theme_and_output(); } return array_keys($this->regions); }
[ "public", "function", "get_regions", "(", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "defaultregion", ")", ")", "{", "$", "this", "->", "page", "->", "initialise_theme_and_output", "(", ")", ";", "}", "return", "array_keys", "(", "$", "this", "->", "regions", ")", ";", "}" ]
Get an array of all region names on this page where a block may appear @return array the internal names of the regions on this page where block may appear.
[ "Get", "an", "array", "of", "all", "region", "names", "on", "this", "page", "where", "a", "block", "may", "appear" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/blocklib.php#L177-L182
212,229
moodle/moodle
lib/blocklib.php
block_manager.get_addable_blocks
public function get_addable_blocks() { $this->check_is_loaded(); if (!is_null($this->addableblocks)) { return $this->addableblocks; } // Lazy load. $this->addableblocks = array(); $allblocks = blocks_get_record(); if (empty($allblocks)) { return $this->addableblocks; } $unaddableblocks = self::get_undeletable_block_types(); $requiredbythemeblocks = $this->get_required_by_theme_block_types(); $pageformat = $this->page->pagetype; foreach($allblocks as $block) { if (!$bi = block_instance($block->name)) { continue; } if ($block->visible && !in_array($block->name, $unaddableblocks) && !in_array($block->name, $requiredbythemeblocks) && ($bi->instance_allow_multiple() || !$this->is_block_present($block->name)) && blocks_name_allowed_in_format($block->name, $pageformat) && $bi->user_can_addto($this->page)) { $block->title = $bi->get_title(); $this->addableblocks[$block->name] = $block; } } core_collator::asort_objects_by_property($this->addableblocks, 'title'); return $this->addableblocks; }
php
public function get_addable_blocks() { $this->check_is_loaded(); if (!is_null($this->addableblocks)) { return $this->addableblocks; } // Lazy load. $this->addableblocks = array(); $allblocks = blocks_get_record(); if (empty($allblocks)) { return $this->addableblocks; } $unaddableblocks = self::get_undeletable_block_types(); $requiredbythemeblocks = $this->get_required_by_theme_block_types(); $pageformat = $this->page->pagetype; foreach($allblocks as $block) { if (!$bi = block_instance($block->name)) { continue; } if ($block->visible && !in_array($block->name, $unaddableblocks) && !in_array($block->name, $requiredbythemeblocks) && ($bi->instance_allow_multiple() || !$this->is_block_present($block->name)) && blocks_name_allowed_in_format($block->name, $pageformat) && $bi->user_can_addto($this->page)) { $block->title = $bi->get_title(); $this->addableblocks[$block->name] = $block; } } core_collator::asort_objects_by_property($this->addableblocks, 'title'); return $this->addableblocks; }
[ "public", "function", "get_addable_blocks", "(", ")", "{", "$", "this", "->", "check_is_loaded", "(", ")", ";", "if", "(", "!", "is_null", "(", "$", "this", "->", "addableblocks", ")", ")", "{", "return", "$", "this", "->", "addableblocks", ";", "}", "// Lazy load.", "$", "this", "->", "addableblocks", "=", "array", "(", ")", ";", "$", "allblocks", "=", "blocks_get_record", "(", ")", ";", "if", "(", "empty", "(", "$", "allblocks", ")", ")", "{", "return", "$", "this", "->", "addableblocks", ";", "}", "$", "unaddableblocks", "=", "self", "::", "get_undeletable_block_types", "(", ")", ";", "$", "requiredbythemeblocks", "=", "$", "this", "->", "get_required_by_theme_block_types", "(", ")", ";", "$", "pageformat", "=", "$", "this", "->", "page", "->", "pagetype", ";", "foreach", "(", "$", "allblocks", "as", "$", "block", ")", "{", "if", "(", "!", "$", "bi", "=", "block_instance", "(", "$", "block", "->", "name", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "block", "->", "visible", "&&", "!", "in_array", "(", "$", "block", "->", "name", ",", "$", "unaddableblocks", ")", "&&", "!", "in_array", "(", "$", "block", "->", "name", ",", "$", "requiredbythemeblocks", ")", "&&", "(", "$", "bi", "->", "instance_allow_multiple", "(", ")", "||", "!", "$", "this", "->", "is_block_present", "(", "$", "block", "->", "name", ")", ")", "&&", "blocks_name_allowed_in_format", "(", "$", "block", "->", "name", ",", "$", "pageformat", ")", "&&", "$", "bi", "->", "user_can_addto", "(", "$", "this", "->", "page", ")", ")", "{", "$", "block", "->", "title", "=", "$", "bi", "->", "get_title", "(", ")", ";", "$", "this", "->", "addableblocks", "[", "$", "block", "->", "name", "]", "=", "$", "block", ";", "}", "}", "core_collator", "::", "asort_objects_by_property", "(", "$", "this", "->", "addableblocks", ",", "'title'", ")", ";", "return", "$", "this", "->", "addableblocks", ";", "}" ]
The list of block types that may be added to this page. @return array block name => record from block table.
[ "The", "list", "of", "block", "types", "that", "may", "be", "added", "to", "this", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/blocklib.php#L202-L236
212,230
moodle/moodle
lib/blocklib.php
block_manager.is_block_present
public function is_block_present($blockname) { if (empty($this->blockinstances)) { return false; } $requiredbythemeblocks = $this->get_required_by_theme_block_types(); foreach ($this->blockinstances as $region) { foreach ($region as $instance) { if (empty($instance->instance->blockname)) { continue; } if ($instance->instance->blockname == $blockname) { if ($instance->instance->requiredbytheme) { if (!in_array($blockname, $requiredbythemeblocks)) { continue; } } return true; } } } return false; }
php
public function is_block_present($blockname) { if (empty($this->blockinstances)) { return false; } $requiredbythemeblocks = $this->get_required_by_theme_block_types(); foreach ($this->blockinstances as $region) { foreach ($region as $instance) { if (empty($instance->instance->blockname)) { continue; } if ($instance->instance->blockname == $blockname) { if ($instance->instance->requiredbytheme) { if (!in_array($blockname, $requiredbythemeblocks)) { continue; } } return true; } } } return false; }
[ "public", "function", "is_block_present", "(", "$", "blockname", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "blockinstances", ")", ")", "{", "return", "false", ";", "}", "$", "requiredbythemeblocks", "=", "$", "this", "->", "get_required_by_theme_block_types", "(", ")", ";", "foreach", "(", "$", "this", "->", "blockinstances", "as", "$", "region", ")", "{", "foreach", "(", "$", "region", "as", "$", "instance", ")", "{", "if", "(", "empty", "(", "$", "instance", "->", "instance", "->", "blockname", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "instance", "->", "instance", "->", "blockname", "==", "$", "blockname", ")", "{", "if", "(", "$", "instance", "->", "instance", "->", "requiredbytheme", ")", "{", "if", "(", "!", "in_array", "(", "$", "blockname", ",", "$", "requiredbythemeblocks", ")", ")", "{", "continue", ";", "}", "}", "return", "true", ";", "}", "}", "}", "return", "false", ";", "}" ]
Given a block name, find out of any of them are currently present in the page @param string $blockname - the basic name of a block (eg "navigation") @return boolean - is there one of these blocks in the current page?
[ "Given", "a", "block", "name", "find", "out", "of", "any", "of", "them", "are", "currently", "present", "in", "the", "page" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/blocklib.php#L244-L266
212,231
moodle/moodle
lib/blocklib.php
block_manager.is_known_block_type
public function is_known_block_type($blockname, $includeinvisible = false) { $blocks = $this->get_installed_blocks(); foreach ($blocks as $block) { if ($block->name == $blockname && ($includeinvisible || $block->visible)) { return true; } } return false; }
php
public function is_known_block_type($blockname, $includeinvisible = false) { $blocks = $this->get_installed_blocks(); foreach ($blocks as $block) { if ($block->name == $blockname && ($includeinvisible || $block->visible)) { return true; } } return false; }
[ "public", "function", "is_known_block_type", "(", "$", "blockname", ",", "$", "includeinvisible", "=", "false", ")", "{", "$", "blocks", "=", "$", "this", "->", "get_installed_blocks", "(", ")", ";", "foreach", "(", "$", "blocks", "as", "$", "block", ")", "{", "if", "(", "$", "block", "->", "name", "==", "$", "blockname", "&&", "(", "$", "includeinvisible", "||", "$", "block", "->", "visible", ")", ")", "{", "return", "true", ";", "}", "}", "return", "false", ";", "}" ]
Find out if a block type is known by the system @param string $blockname the name of the type of block. @param boolean $includeinvisible if false (default) only check 'visible' blocks, that is, blocks enabled by the admin. @return boolean true if this block in installed.
[ "Find", "out", "if", "a", "block", "type", "is", "known", "by", "the", "system" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/blocklib.php#L275-L283
212,232
moodle/moodle
lib/blocklib.php
block_manager.get_blocks_for_region
public function get_blocks_for_region($region) { $this->check_is_loaded(); $this->ensure_instances_exist($region); return $this->blockinstances[$region]; }
php
public function get_blocks_for_region($region) { $this->check_is_loaded(); $this->ensure_instances_exist($region); return $this->blockinstances[$region]; }
[ "public", "function", "get_blocks_for_region", "(", "$", "region", ")", "{", "$", "this", "->", "check_is_loaded", "(", ")", ";", "$", "this", "->", "ensure_instances_exist", "(", "$", "region", ")", ";", "return", "$", "this", "->", "blockinstances", "[", "$", "region", "]", ";", "}" ]
Get an array of all blocks within a given region @param string $region a block region that exists on this page. @return array of block instances.
[ "Get", "an", "array", "of", "all", "blocks", "within", "a", "given", "region" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/blocklib.php#L304-L308
212,233
moodle/moodle
lib/blocklib.php
block_manager.get_content_for_region
public function get_content_for_region($region, $output) { $this->check_is_loaded(); $this->ensure_content_created($region, $output); return $this->visibleblockcontent[$region]; }
php
public function get_content_for_region($region, $output) { $this->check_is_loaded(); $this->ensure_content_created($region, $output); return $this->visibleblockcontent[$region]; }
[ "public", "function", "get_content_for_region", "(", "$", "region", ",", "$", "output", ")", "{", "$", "this", "->", "check_is_loaded", "(", ")", ";", "$", "this", "->", "ensure_content_created", "(", "$", "region", ",", "$", "output", ")", ";", "return", "$", "this", "->", "visibleblockcontent", "[", "$", "region", "]", ";", "}" ]
Returns an array of block content objects that exist in a region @param string $region a block region that exists on this page. @return array of block block_contents objects for all the blocks in a region.
[ "Returns", "an", "array", "of", "block", "content", "objects", "that", "exist", "in", "a", "region" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/blocklib.php#L316-L320
212,234
moodle/moodle
lib/blocklib.php
block_manager.get_content_for_all_regions
public function get_content_for_all_regions($output) { $contents = array(); $this->check_is_loaded(); foreach ($this->regions as $region => $val) { $this->ensure_content_created($region, $output); $contents[$region] = $this->visibleblockcontent[$region]; } return $contents; }
php
public function get_content_for_all_regions($output) { $contents = array(); $this->check_is_loaded(); foreach ($this->regions as $region => $val) { $this->ensure_content_created($region, $output); $contents[$region] = $this->visibleblockcontent[$region]; } return $contents; }
[ "public", "function", "get_content_for_all_regions", "(", "$", "output", ")", "{", "$", "contents", "=", "array", "(", ")", ";", "$", "this", "->", "check_is_loaded", "(", ")", ";", "foreach", "(", "$", "this", "->", "regions", "as", "$", "region", "=>", "$", "val", ")", "{", "$", "this", "->", "ensure_content_created", "(", "$", "region", ",", "$", "output", ")", ";", "$", "contents", "[", "$", "region", "]", "=", "$", "this", "->", "visibleblockcontent", "[", "$", "region", "]", ";", "}", "return", "$", "contents", ";", "}" ]
Returns an array of block content objects for all the existings regions @param renderer_base $output the rendered to use @return array of block block_contents objects for all the blocks in all regions. @since Moodle 3.3
[ "Returns", "an", "array", "of", "block", "content", "objects", "for", "all", "the", "existings", "regions" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/blocklib.php#L329-L338
212,235
moodle/moodle
lib/blocklib.php
block_manager.get_move_target_url
protected function get_move_target_url($region, $weight) { return new moodle_url($this->page->url, array('bui_moveid' => $this->movingblock, 'bui_newregion' => $region, 'bui_newweight' => $weight, 'sesskey' => sesskey())); }
php
protected function get_move_target_url($region, $weight) { return new moodle_url($this->page->url, array('bui_moveid' => $this->movingblock, 'bui_newregion' => $region, 'bui_newweight' => $weight, 'sesskey' => sesskey())); }
[ "protected", "function", "get_move_target_url", "(", "$", "region", ",", "$", "weight", ")", "{", "return", "new", "moodle_url", "(", "$", "this", "->", "page", "->", "url", ",", "array", "(", "'bui_moveid'", "=>", "$", "this", "->", "movingblock", ",", "'bui_newregion'", "=>", "$", "region", ",", "'bui_newweight'", "=>", "$", "weight", ",", "'sesskey'", "=>", "sesskey", "(", ")", ")", ")", ";", "}" ]
Helper method used by get_content_for_region. @param string $region region name @param float $weight weight. May be fractional, since you may want to move a block between ones with weight 2 and 3, say ($weight would be 2.5). @return string URL for moving block $this->movingblock to this position.
[ "Helper", "method", "used", "by", "get_content_for_region", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/blocklib.php#L347-L350
212,236
moodle/moodle
lib/blocklib.php
block_manager.get_installed_blocks
public function get_installed_blocks() { global $DB; if (is_null($this->allblocks)) { $this->allblocks = $DB->get_records('block'); } return $this->allblocks; }
php
public function get_installed_blocks() { global $DB; if (is_null($this->allblocks)) { $this->allblocks = $DB->get_records('block'); } return $this->allblocks; }
[ "public", "function", "get_installed_blocks", "(", ")", "{", "global", "$", "DB", ";", "if", "(", "is_null", "(", "$", "this", "->", "allblocks", ")", ")", "{", "$", "this", "->", "allblocks", "=", "$", "DB", "->", "get_records", "(", "'block'", ")", ";", "}", "return", "$", "this", "->", "allblocks", ";", "}" ]
Get an array of all of the installed blocks. @return array contents of the block table.
[ "Get", "an", "array", "of", "all", "of", "the", "installed", "blocks", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/blocklib.php#L390-L396
212,237
moodle/moodle
lib/blocklib.php
block_manager.protect_block
public static function protect_block($blockidorname) { global $DB; $syscontext = context_system::instance(); require_capability('moodle/site:config', $syscontext); $block = false; if (is_int($blockidorname)) { $block = $DB->get_record('block', array('id' => $blockidorname), 'id, name', MUST_EXIST); } else { $block = $DB->get_record('block', array('name' => $blockidorname), 'id, name', MUST_EXIST); } $undeletableblocktypes = self::get_undeletable_block_types(); if (!in_array($block->name, $undeletableblocktypes)) { $undeletableblocktypes[] = $block->name; set_config('undeletableblocktypes', implode(',', $undeletableblocktypes)); add_to_config_log('block_protect', "0", "1", $block->name); } }
php
public static function protect_block($blockidorname) { global $DB; $syscontext = context_system::instance(); require_capability('moodle/site:config', $syscontext); $block = false; if (is_int($blockidorname)) { $block = $DB->get_record('block', array('id' => $blockidorname), 'id, name', MUST_EXIST); } else { $block = $DB->get_record('block', array('name' => $blockidorname), 'id, name', MUST_EXIST); } $undeletableblocktypes = self::get_undeletable_block_types(); if (!in_array($block->name, $undeletableblocktypes)) { $undeletableblocktypes[] = $block->name; set_config('undeletableblocktypes', implode(',', $undeletableblocktypes)); add_to_config_log('block_protect', "0", "1", $block->name); } }
[ "public", "static", "function", "protect_block", "(", "$", "blockidorname", ")", "{", "global", "$", "DB", ";", "$", "syscontext", "=", "context_system", "::", "instance", "(", ")", ";", "require_capability", "(", "'moodle/site:config'", ",", "$", "syscontext", ")", ";", "$", "block", "=", "false", ";", "if", "(", "is_int", "(", "$", "blockidorname", ")", ")", "{", "$", "block", "=", "$", "DB", "->", "get_record", "(", "'block'", ",", "array", "(", "'id'", "=>", "$", "blockidorname", ")", ",", "'id, name'", ",", "MUST_EXIST", ")", ";", "}", "else", "{", "$", "block", "=", "$", "DB", "->", "get_record", "(", "'block'", ",", "array", "(", "'name'", "=>", "$", "blockidorname", ")", ",", "'id, name'", ",", "MUST_EXIST", ")", ";", "}", "$", "undeletableblocktypes", "=", "self", "::", "get_undeletable_block_types", "(", ")", ";", "if", "(", "!", "in_array", "(", "$", "block", "->", "name", ",", "$", "undeletableblocktypes", ")", ")", "{", "$", "undeletableblocktypes", "[", "]", "=", "$", "block", "->", "name", ";", "set_config", "(", "'undeletableblocktypes'", ",", "implode", "(", "','", ",", "$", "undeletableblocktypes", ")", ")", ";", "add_to_config_log", "(", "'block_protect'", ",", "\"0\"", ",", "\"1\"", ",", "$", "block", "->", "name", ")", ";", "}", "}" ]
Make this block type undeletable and unaddable. @param mixed $blockidorname string or int
[ "Make", "this", "block", "type", "undeletable", "and", "unaddable", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/blocklib.php#L423-L442
212,238
moodle/moodle
lib/blocklib.php
block_manager.get_undeletable_block_types
public static function get_undeletable_block_types() { global $CFG; $undeletableblocks = false; if (isset($CFG->undeletableblocktypes)) { $undeletableblocks = $CFG->undeletableblocktypes; } if (empty($undeletableblocks)) { return array(); } else if (is_string($undeletableblocks)) { return explode(',', $undeletableblocks); } else { return $undeletableblocks; } }
php
public static function get_undeletable_block_types() { global $CFG; $undeletableblocks = false; if (isset($CFG->undeletableblocktypes)) { $undeletableblocks = $CFG->undeletableblocktypes; } if (empty($undeletableblocks)) { return array(); } else if (is_string($undeletableblocks)) { return explode(',', $undeletableblocks); } else { return $undeletableblocks; } }
[ "public", "static", "function", "get_undeletable_block_types", "(", ")", "{", "global", "$", "CFG", ";", "$", "undeletableblocks", "=", "false", ";", "if", "(", "isset", "(", "$", "CFG", "->", "undeletableblocktypes", ")", ")", "{", "$", "undeletableblocks", "=", "$", "CFG", "->", "undeletableblocktypes", ";", "}", "if", "(", "empty", "(", "$", "undeletableblocks", ")", ")", "{", "return", "array", "(", ")", ";", "}", "else", "if", "(", "is_string", "(", "$", "undeletableblocks", ")", ")", "{", "return", "explode", "(", "','", ",", "$", "undeletableblocks", ")", ";", "}", "else", "{", "return", "$", "undeletableblocks", ";", "}", "}" ]
Get the list of "protected" blocks via admin block manager ui. @return array names of block types that cannot be added or deleted. E.g. array('navigation','settings').
[ "Get", "the", "list", "of", "protected", "blocks", "via", "admin", "block", "manager", "ui", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/blocklib.php#L476-L490
212,239
moodle/moodle
lib/blocklib.php
block_manager.add_region
public function add_region($region, $custom = true) { global $SESSION; $this->check_not_yet_loaded(); if ($custom) { if (array_key_exists($region, $this->regions)) { // This here is EXACTLY why we should not be adding block regions into a page. It should // ALWAYS be done in a theme layout. debugging('A custom region conflicts with a block region in the theme.', DEBUG_DEVELOPER); } // We need to register this custom region against the page type being used. // This allows us to check, when performing block actions, that unrecognised regions can be worked with. $type = $this->page->pagetype; if (!isset($SESSION->custom_block_regions)) { $SESSION->custom_block_regions = array($type => array($region)); } else if (!isset($SESSION->custom_block_regions[$type])) { $SESSION->custom_block_regions[$type] = array($region); } else if (!in_array($region, $SESSION->custom_block_regions[$type])) { $SESSION->custom_block_regions[$type][] = $region; } } $this->regions[$region] = 1; // Checking the actual property instead of calling get_default_region as it ends up in a recursive call. if (empty($this->defaultregion)) { $this->set_default_region($region); } }
php
public function add_region($region, $custom = true) { global $SESSION; $this->check_not_yet_loaded(); if ($custom) { if (array_key_exists($region, $this->regions)) { // This here is EXACTLY why we should not be adding block regions into a page. It should // ALWAYS be done in a theme layout. debugging('A custom region conflicts with a block region in the theme.', DEBUG_DEVELOPER); } // We need to register this custom region against the page type being used. // This allows us to check, when performing block actions, that unrecognised regions can be worked with. $type = $this->page->pagetype; if (!isset($SESSION->custom_block_regions)) { $SESSION->custom_block_regions = array($type => array($region)); } else if (!isset($SESSION->custom_block_regions[$type])) { $SESSION->custom_block_regions[$type] = array($region); } else if (!in_array($region, $SESSION->custom_block_regions[$type])) { $SESSION->custom_block_regions[$type][] = $region; } } $this->regions[$region] = 1; // Checking the actual property instead of calling get_default_region as it ends up in a recursive call. if (empty($this->defaultregion)) { $this->set_default_region($region); } }
[ "public", "function", "add_region", "(", "$", "region", ",", "$", "custom", "=", "true", ")", "{", "global", "$", "SESSION", ";", "$", "this", "->", "check_not_yet_loaded", "(", ")", ";", "if", "(", "$", "custom", ")", "{", "if", "(", "array_key_exists", "(", "$", "region", ",", "$", "this", "->", "regions", ")", ")", "{", "// This here is EXACTLY why we should not be adding block regions into a page. It should", "// ALWAYS be done in a theme layout.", "debugging", "(", "'A custom region conflicts with a block region in the theme.'", ",", "DEBUG_DEVELOPER", ")", ";", "}", "// We need to register this custom region against the page type being used.", "// This allows us to check, when performing block actions, that unrecognised regions can be worked with.", "$", "type", "=", "$", "this", "->", "page", "->", "pagetype", ";", "if", "(", "!", "isset", "(", "$", "SESSION", "->", "custom_block_regions", ")", ")", "{", "$", "SESSION", "->", "custom_block_regions", "=", "array", "(", "$", "type", "=>", "array", "(", "$", "region", ")", ")", ";", "}", "else", "if", "(", "!", "isset", "(", "$", "SESSION", "->", "custom_block_regions", "[", "$", "type", "]", ")", ")", "{", "$", "SESSION", "->", "custom_block_regions", "[", "$", "type", "]", "=", "array", "(", "$", "region", ")", ";", "}", "else", "if", "(", "!", "in_array", "(", "$", "region", ",", "$", "SESSION", "->", "custom_block_regions", "[", "$", "type", "]", ")", ")", "{", "$", "SESSION", "->", "custom_block_regions", "[", "$", "type", "]", "[", "]", "=", "$", "region", ";", "}", "}", "$", "this", "->", "regions", "[", "$", "region", "]", "=", "1", ";", "// Checking the actual property instead of calling get_default_region as it ends up in a recursive call.", "if", "(", "empty", "(", "$", "this", "->", "defaultregion", ")", ")", "{", "$", "this", "->", "set_default_region", "(", "$", "region", ")", ";", "}", "}" ]
Add a region to a page @param string $region add a named region where blocks may appear on the current page. This is an internal name, like 'side-pre', not a string to display in the UI. @param bool $custom True if this is a custom block region, being added by the page rather than the theme layout.
[ "Add", "a", "region", "to", "a", "page" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/blocklib.php#L501-L527
212,240
moodle/moodle
lib/blocklib.php
block_manager.add_custom_regions_for_pagetype
public function add_custom_regions_for_pagetype($pagetype) { global $SESSION; if (isset($SESSION->custom_block_regions[$pagetype])) { foreach ($SESSION->custom_block_regions[$pagetype] as $customregion) { $this->add_region($customregion, false); } } }
php
public function add_custom_regions_for_pagetype($pagetype) { global $SESSION; if (isset($SESSION->custom_block_regions[$pagetype])) { foreach ($SESSION->custom_block_regions[$pagetype] as $customregion) { $this->add_region($customregion, false); } } }
[ "public", "function", "add_custom_regions_for_pagetype", "(", "$", "pagetype", ")", "{", "global", "$", "SESSION", ";", "if", "(", "isset", "(", "$", "SESSION", "->", "custom_block_regions", "[", "$", "pagetype", "]", ")", ")", "{", "foreach", "(", "$", "SESSION", "->", "custom_block_regions", "[", "$", "pagetype", "]", "as", "$", "customregion", ")", "{", "$", "this", "->", "add_region", "(", "$", "customregion", ",", "false", ")", ";", "}", "}", "}" ]
Finds custom block regions associated with a page type and registers them with this block manager. @param string $pagetype
[ "Finds", "custom", "block", "regions", "associated", "with", "a", "page", "type", "and", "registers", "them", "with", "this", "block", "manager", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/blocklib.php#L546-L553
212,241
moodle/moodle
lib/blocklib.php
block_manager.set_default_region
public function set_default_region($defaultregion) { $this->check_not_yet_loaded(); if ($defaultregion) { $this->check_region_is_known($defaultregion); } $this->defaultregion = $defaultregion; }
php
public function set_default_region($defaultregion) { $this->check_not_yet_loaded(); if ($defaultregion) { $this->check_region_is_known($defaultregion); } $this->defaultregion = $defaultregion; }
[ "public", "function", "set_default_region", "(", "$", "defaultregion", ")", "{", "$", "this", "->", "check_not_yet_loaded", "(", ")", ";", "if", "(", "$", "defaultregion", ")", "{", "$", "this", "->", "check_region_is_known", "(", "$", "defaultregion", ")", ";", "}", "$", "this", "->", "defaultregion", "=", "$", "defaultregion", ";", "}" ]
Set the default region for new blocks on the page @param string $defaultregion the internal names of the region where new blocks should be added by default, and where any blocks from an unrecognised region are shown.
[ "Set", "the", "default", "region", "for", "new", "blocks", "on", "the", "page" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/blocklib.php#L562-L568
212,242
moodle/moodle
lib/blocklib.php
block_manager.add_fake_block
public function add_fake_block($bc, $region) { $this->page->initialise_theme_and_output(); if (!$this->is_known_region($region)) { $region = $this->get_default_region(); } if (array_key_exists($region, $this->visibleblockcontent)) { throw new coding_exception('block_manager has already prepared the blocks in region ' . $region . 'for output. It is too late to add a fake block.'); } if (!isset($bc->attributes['data-block'])) { $bc->attributes['data-block'] = '_fake'; } $bc->attributes['class'] .= ' block_fake'; $this->extracontent[$region][] = $bc; }
php
public function add_fake_block($bc, $region) { $this->page->initialise_theme_and_output(); if (!$this->is_known_region($region)) { $region = $this->get_default_region(); } if (array_key_exists($region, $this->visibleblockcontent)) { throw new coding_exception('block_manager has already prepared the blocks in region ' . $region . 'for output. It is too late to add a fake block.'); } if (!isset($bc->attributes['data-block'])) { $bc->attributes['data-block'] = '_fake'; } $bc->attributes['class'] .= ' block_fake'; $this->extracontent[$region][] = $bc; }
[ "public", "function", "add_fake_block", "(", "$", "bc", ",", "$", "region", ")", "{", "$", "this", "->", "page", "->", "initialise_theme_and_output", "(", ")", ";", "if", "(", "!", "$", "this", "->", "is_known_region", "(", "$", "region", ")", ")", "{", "$", "region", "=", "$", "this", "->", "get_default_region", "(", ")", ";", "}", "if", "(", "array_key_exists", "(", "$", "region", ",", "$", "this", "->", "visibleblockcontent", ")", ")", "{", "throw", "new", "coding_exception", "(", "'block_manager has already prepared the blocks in region '", ".", "$", "region", ".", "'for output. It is too late to add a fake block.'", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "bc", "->", "attributes", "[", "'data-block'", "]", ")", ")", "{", "$", "bc", "->", "attributes", "[", "'data-block'", "]", "=", "'_fake'", ";", "}", "$", "bc", "->", "attributes", "[", "'class'", "]", ".=", "' block_fake'", ";", "$", "this", "->", "extracontent", "[", "$", "region", "]", "[", "]", "=", "$", "bc", ";", "}" ]
Add something that looks like a block, but which isn't an actual block_instance, to this page. @param block_contents $bc the content of the block-like thing. @param string $region a block region that exists on this page.
[ "Add", "something", "that", "looks", "like", "a", "block", "but", "which", "isn", "t", "an", "actual", "block_instance", "to", "this", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/blocklib.php#L577-L591
212,243
moodle/moodle
lib/blocklib.php
block_manager.reposition_block
public function reposition_block($blockinstanceid, $newregion, $newweight) { global $DB; $this->check_region_is_known($newregion); $inst = $this->find_instance($blockinstanceid); $bi = $inst->instance; if ($bi->weight == $bi->defaultweight && $bi->region == $bi->defaultregion && !$bi->showinsubcontexts && strpos($bi->pagetypepattern, '*') === false && (!$this->page->subpage || $bi->subpagepattern)) { // Set default position $newbi = new stdClass; $newbi->id = $bi->id; $newbi->defaultregion = $newregion; $newbi->defaultweight = $newweight; $newbi->timemodified = time(); $DB->update_record('block_instances', $newbi); if ($bi->blockpositionid) { $bp = new stdClass; $bp->id = $bi->blockpositionid; $bp->region = $newregion; $bp->weight = $newweight; $DB->update_record('block_positions', $bp); } } else { // Just set position on this page. $bp = new stdClass; $bp->region = $newregion; $bp->weight = $newweight; if ($bi->blockpositionid) { $bp->id = $bi->blockpositionid; $DB->update_record('block_positions', $bp); } else { $bp->blockinstanceid = $bi->id; $bp->contextid = $this->page->context->id; $bp->pagetype = $this->page->pagetype; if ($this->page->subpage) { $bp->subpage = $this->page->subpage; } else { $bp->subpage = ''; } $bp->visible = $bi->visible; $DB->insert_record('block_positions', $bp); } } }
php
public function reposition_block($blockinstanceid, $newregion, $newweight) { global $DB; $this->check_region_is_known($newregion); $inst = $this->find_instance($blockinstanceid); $bi = $inst->instance; if ($bi->weight == $bi->defaultweight && $bi->region == $bi->defaultregion && !$bi->showinsubcontexts && strpos($bi->pagetypepattern, '*') === false && (!$this->page->subpage || $bi->subpagepattern)) { // Set default position $newbi = new stdClass; $newbi->id = $bi->id; $newbi->defaultregion = $newregion; $newbi->defaultweight = $newweight; $newbi->timemodified = time(); $DB->update_record('block_instances', $newbi); if ($bi->blockpositionid) { $bp = new stdClass; $bp->id = $bi->blockpositionid; $bp->region = $newregion; $bp->weight = $newweight; $DB->update_record('block_positions', $bp); } } else { // Just set position on this page. $bp = new stdClass; $bp->region = $newregion; $bp->weight = $newweight; if ($bi->blockpositionid) { $bp->id = $bi->blockpositionid; $DB->update_record('block_positions', $bp); } else { $bp->blockinstanceid = $bi->id; $bp->contextid = $this->page->context->id; $bp->pagetype = $this->page->pagetype; if ($this->page->subpage) { $bp->subpage = $this->page->subpage; } else { $bp->subpage = ''; } $bp->visible = $bi->visible; $DB->insert_record('block_positions', $bp); } } }
[ "public", "function", "reposition_block", "(", "$", "blockinstanceid", ",", "$", "newregion", ",", "$", "newweight", ")", "{", "global", "$", "DB", ";", "$", "this", "->", "check_region_is_known", "(", "$", "newregion", ")", ";", "$", "inst", "=", "$", "this", "->", "find_instance", "(", "$", "blockinstanceid", ")", ";", "$", "bi", "=", "$", "inst", "->", "instance", ";", "if", "(", "$", "bi", "->", "weight", "==", "$", "bi", "->", "defaultweight", "&&", "$", "bi", "->", "region", "==", "$", "bi", "->", "defaultregion", "&&", "!", "$", "bi", "->", "showinsubcontexts", "&&", "strpos", "(", "$", "bi", "->", "pagetypepattern", ",", "'*'", ")", "===", "false", "&&", "(", "!", "$", "this", "->", "page", "->", "subpage", "||", "$", "bi", "->", "subpagepattern", ")", ")", "{", "// Set default position", "$", "newbi", "=", "new", "stdClass", ";", "$", "newbi", "->", "id", "=", "$", "bi", "->", "id", ";", "$", "newbi", "->", "defaultregion", "=", "$", "newregion", ";", "$", "newbi", "->", "defaultweight", "=", "$", "newweight", ";", "$", "newbi", "->", "timemodified", "=", "time", "(", ")", ";", "$", "DB", "->", "update_record", "(", "'block_instances'", ",", "$", "newbi", ")", ";", "if", "(", "$", "bi", "->", "blockpositionid", ")", "{", "$", "bp", "=", "new", "stdClass", ";", "$", "bp", "->", "id", "=", "$", "bi", "->", "blockpositionid", ";", "$", "bp", "->", "region", "=", "$", "newregion", ";", "$", "bp", "->", "weight", "=", "$", "newweight", ";", "$", "DB", "->", "update_record", "(", "'block_positions'", ",", "$", "bp", ")", ";", "}", "}", "else", "{", "// Just set position on this page.", "$", "bp", "=", "new", "stdClass", ";", "$", "bp", "->", "region", "=", "$", "newregion", ";", "$", "bp", "->", "weight", "=", "$", "newweight", ";", "if", "(", "$", "bi", "->", "blockpositionid", ")", "{", "$", "bp", "->", "id", "=", "$", "bi", "->", "blockpositionid", ";", "$", "DB", "->", "update_record", "(", "'block_positions'", ",", "$", "bp", ")", ";", "}", "else", "{", "$", "bp", "->", "blockinstanceid", "=", "$", "bi", "->", "id", ";", "$", "bp", "->", "contextid", "=", "$", "this", "->", "page", "->", "context", "->", "id", ";", "$", "bp", "->", "pagetype", "=", "$", "this", "->", "page", "->", "pagetype", ";", "if", "(", "$", "this", "->", "page", "->", "subpage", ")", "{", "$", "bp", "->", "subpage", "=", "$", "this", "->", "page", "->", "subpage", ";", "}", "else", "{", "$", "bp", "->", "subpage", "=", "''", ";", "}", "$", "bp", "->", "visible", "=", "$", "bi", "->", "visible", ";", "$", "DB", "->", "insert_record", "(", "'block_positions'", ",", "$", "bp", ")", ";", "}", "}", "}" ]
Move a block to a new position on this page. If this block cannot appear on any other pages, then we change defaultposition/weight in the block_instances table. Otherwise we just set the position on this page. @param $blockinstanceid the block instance id. @param $newregion the new region name. @param $newweight the new weight.
[ "Move", "a", "block", "to", "a", "new", "position", "on", "this", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/blocklib.php#L908-L958
212,244
moodle/moodle
lib/blocklib.php
block_manager.find_instance
public function find_instance($instanceid) { foreach ($this->regions as $region => $notused) { $this->ensure_instances_exist($region); foreach($this->blockinstances[$region] as $instance) { if ($instance->instance->id == $instanceid) { return $instance; } } } throw new block_not_on_page_exception($instanceid, $this->page); }
php
public function find_instance($instanceid) { foreach ($this->regions as $region => $notused) { $this->ensure_instances_exist($region); foreach($this->blockinstances[$region] as $instance) { if ($instance->instance->id == $instanceid) { return $instance; } } } throw new block_not_on_page_exception($instanceid, $this->page); }
[ "public", "function", "find_instance", "(", "$", "instanceid", ")", "{", "foreach", "(", "$", "this", "->", "regions", "as", "$", "region", "=>", "$", "notused", ")", "{", "$", "this", "->", "ensure_instances_exist", "(", "$", "region", ")", ";", "foreach", "(", "$", "this", "->", "blockinstances", "[", "$", "region", "]", "as", "$", "instance", ")", "{", "if", "(", "$", "instance", "->", "instance", "->", "id", "==", "$", "instanceid", ")", "{", "return", "$", "instance", ";", "}", "}", "}", "throw", "new", "block_not_on_page_exception", "(", "$", "instanceid", ",", "$", "this", "->", "page", ")", ";", "}" ]
Find a given block by its instance id @param integer $instanceid @return block_base
[ "Find", "a", "given", "block", "by", "its", "instance", "id" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/blocklib.php#L966-L976
212,245
moodle/moodle
lib/blocklib.php
block_manager.check_known_block_type
protected function check_known_block_type($blockname, $includeinvisible = false) { if (!$this->is_known_block_type($blockname, $includeinvisible)) { if ($this->is_known_block_type($blockname, true)) { throw new coding_exception('Unknown block type ' . $blockname); } else { throw new coding_exception('Block type ' . $blockname . ' has been disabled by the administrator.'); } } }
php
protected function check_known_block_type($blockname, $includeinvisible = false) { if (!$this->is_known_block_type($blockname, $includeinvisible)) { if ($this->is_known_block_type($blockname, true)) { throw new coding_exception('Unknown block type ' . $blockname); } else { throw new coding_exception('Block type ' . $blockname . ' has been disabled by the administrator.'); } } }
[ "protected", "function", "check_known_block_type", "(", "$", "blockname", ",", "$", "includeinvisible", "=", "false", ")", "{", "if", "(", "!", "$", "this", "->", "is_known_block_type", "(", "$", "blockname", ",", "$", "includeinvisible", ")", ")", "{", "if", "(", "$", "this", "->", "is_known_block_type", "(", "$", "blockname", ",", "true", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Unknown block type '", ".", "$", "blockname", ")", ";", "}", "else", "{", "throw", "new", "coding_exception", "(", "'Block type '", ".", "$", "blockname", ".", "' has been disabled by the administrator.'", ")", ";", "}", "}", "}" ]
Check if a block type is known and usable @param string $blockname The block type name to search for @param bool $includeinvisible Include disabled block types in the initial pass @return void Coding Exception thrown if unknown or not enabled
[ "Check", "if", "a", "block", "type", "is", "known", "and", "usable" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/blocklib.php#L1011-L1019
212,246
moodle/moodle
lib/blocklib.php
block_manager.prepare_per_region_arrays
protected function prepare_per_region_arrays() { $result = array(); foreach ($this->regions as $region => $notused) { $result[$region] = array(); } return $result; }
php
protected function prepare_per_region_arrays() { $result = array(); foreach ($this->regions as $region => $notused) { $result[$region] = array(); } return $result; }
[ "protected", "function", "prepare_per_region_arrays", "(", ")", "{", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "regions", "as", "$", "region", "=>", "$", "notused", ")", "{", "$", "result", "[", "$", "region", "]", "=", "array", "(", ")", ";", "}", "return", "$", "result", ";", "}" ]
Returns an array of region names as keys and nested arrays for values @return array an array where the array keys are the region names, and the array values are empty arrays.
[ "Returns", "an", "array", "of", "region", "names", "as", "keys", "and", "nested", "arrays", "for", "values" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/blocklib.php#L1039-L1045
212,247
moodle/moodle
lib/blocklib.php
block_manager.create_block_instances
protected function create_block_instances($birecords) { $results = array(); foreach ($birecords as $record) { if ($blockobject = block_instance($record->blockname, $record, $this->page)) { $results[] = $blockobject; } } return $results; }
php
protected function create_block_instances($birecords) { $results = array(); foreach ($birecords as $record) { if ($blockobject = block_instance($record->blockname, $record, $this->page)) { $results[] = $blockobject; } } return $results; }
[ "protected", "function", "create_block_instances", "(", "$", "birecords", ")", "{", "$", "results", "=", "array", "(", ")", ";", "foreach", "(", "$", "birecords", "as", "$", "record", ")", "{", "if", "(", "$", "blockobject", "=", "block_instance", "(", "$", "record", "->", "blockname", ",", "$", "record", ",", "$", "this", "->", "page", ")", ")", "{", "$", "results", "[", "]", "=", "$", "blockobject", ";", "}", "}", "return", "$", "results", ";", "}" ]
Create a set of new block instance from a record array @param array $birecords An array of block instance records @return array An array of instantiated block_instance objects
[ "Create", "a", "set", "of", "new", "block", "instance", "from", "a", "record", "array" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/blocklib.php#L1053-L1061
212,248
moodle/moodle
lib/blocklib.php
block_manager.create_block_contents
protected function create_block_contents($instances, $output, $region) { $results = array(); $lastweight = 0; $lastblock = 0; if ($this->movingblock) { $first = reset($instances); if ($first) { $lastweight = $first->instance->weight - 2; } } foreach ($instances as $instance) { $content = $instance->get_content_for_output($output); if (empty($content)) { continue; } if ($this->movingblock && $lastweight != $instance->instance->weight && $content->blockinstanceid != $this->movingblock && $lastblock != $this->movingblock) { $results[] = new block_move_target($this->get_move_target_url($region, ($lastweight + $instance->instance->weight)/2)); } if ($content->blockinstanceid == $this->movingblock) { $content->add_class('beingmoved'); $content->annotation .= get_string('movingthisblockcancel', 'block', html_writer::link($this->page->url, get_string('cancel'))); } $results[] = $content; $lastweight = $instance->instance->weight; $lastblock = $instance->instance->id; } if ($this->movingblock && $lastblock != $this->movingblock) { $results[] = new block_move_target($this->get_move_target_url($region, $lastweight + 1)); } return $results; }
php
protected function create_block_contents($instances, $output, $region) { $results = array(); $lastweight = 0; $lastblock = 0; if ($this->movingblock) { $first = reset($instances); if ($first) { $lastweight = $first->instance->weight - 2; } } foreach ($instances as $instance) { $content = $instance->get_content_for_output($output); if (empty($content)) { continue; } if ($this->movingblock && $lastweight != $instance->instance->weight && $content->blockinstanceid != $this->movingblock && $lastblock != $this->movingblock) { $results[] = new block_move_target($this->get_move_target_url($region, ($lastweight + $instance->instance->weight)/2)); } if ($content->blockinstanceid == $this->movingblock) { $content->add_class('beingmoved'); $content->annotation .= get_string('movingthisblockcancel', 'block', html_writer::link($this->page->url, get_string('cancel'))); } $results[] = $content; $lastweight = $instance->instance->weight; $lastblock = $instance->instance->id; } if ($this->movingblock && $lastblock != $this->movingblock) { $results[] = new block_move_target($this->get_move_target_url($region, $lastweight + 1)); } return $results; }
[ "protected", "function", "create_block_contents", "(", "$", "instances", ",", "$", "output", ",", "$", "region", ")", "{", "$", "results", "=", "array", "(", ")", ";", "$", "lastweight", "=", "0", ";", "$", "lastblock", "=", "0", ";", "if", "(", "$", "this", "->", "movingblock", ")", "{", "$", "first", "=", "reset", "(", "$", "instances", ")", ";", "if", "(", "$", "first", ")", "{", "$", "lastweight", "=", "$", "first", "->", "instance", "->", "weight", "-", "2", ";", "}", "}", "foreach", "(", "$", "instances", "as", "$", "instance", ")", "{", "$", "content", "=", "$", "instance", "->", "get_content_for_output", "(", "$", "output", ")", ";", "if", "(", "empty", "(", "$", "content", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "this", "->", "movingblock", "&&", "$", "lastweight", "!=", "$", "instance", "->", "instance", "->", "weight", "&&", "$", "content", "->", "blockinstanceid", "!=", "$", "this", "->", "movingblock", "&&", "$", "lastblock", "!=", "$", "this", "->", "movingblock", ")", "{", "$", "results", "[", "]", "=", "new", "block_move_target", "(", "$", "this", "->", "get_move_target_url", "(", "$", "region", ",", "(", "$", "lastweight", "+", "$", "instance", "->", "instance", "->", "weight", ")", "/", "2", ")", ")", ";", "}", "if", "(", "$", "content", "->", "blockinstanceid", "==", "$", "this", "->", "movingblock", ")", "{", "$", "content", "->", "add_class", "(", "'beingmoved'", ")", ";", "$", "content", "->", "annotation", ".=", "get_string", "(", "'movingthisblockcancel'", ",", "'block'", ",", "html_writer", "::", "link", "(", "$", "this", "->", "page", "->", "url", ",", "get_string", "(", "'cancel'", ")", ")", ")", ";", "}", "$", "results", "[", "]", "=", "$", "content", ";", "$", "lastweight", "=", "$", "instance", "->", "instance", "->", "weight", ";", "$", "lastblock", "=", "$", "instance", "->", "instance", "->", "id", ";", "}", "if", "(", "$", "this", "->", "movingblock", "&&", "$", "lastblock", "!=", "$", "this", "->", "movingblock", ")", "{", "$", "results", "[", "]", "=", "new", "block_move_target", "(", "$", "this", "->", "get_move_target_url", "(", "$", "region", ",", "$", "lastweight", "+", "1", ")", ")", ";", "}", "return", "$", "results", ";", "}" ]
Return an array of content objects from a set of block instances @param array $instances An array of block instances @param renderer_base The renderer to use. @param string $region the region name. @return array An array of block_content (and possibly block_move_target) objects.
[ "Return", "an", "array", "of", "content", "objects", "from", "a", "set", "of", "block", "instances" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/blocklib.php#L1168-L1206
212,249
moodle/moodle
lib/blocklib.php
block_manager.ensure_instances_exist
protected function ensure_instances_exist($region) { $this->check_region_is_known($region); if (!array_key_exists($region, $this->blockinstances)) { $this->blockinstances[$region] = $this->create_block_instances($this->birecordsbyregion[$region]); } }
php
protected function ensure_instances_exist($region) { $this->check_region_is_known($region); if (!array_key_exists($region, $this->blockinstances)) { $this->blockinstances[$region] = $this->create_block_instances($this->birecordsbyregion[$region]); } }
[ "protected", "function", "ensure_instances_exist", "(", "$", "region", ")", "{", "$", "this", "->", "check_region_is_known", "(", "$", "region", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "region", ",", "$", "this", "->", "blockinstances", ")", ")", "{", "$", "this", "->", "blockinstances", "[", "$", "region", "]", "=", "$", "this", "->", "create_block_instances", "(", "$", "this", "->", "birecordsbyregion", "[", "$", "region", "]", ")", ";", "}", "}" ]
Ensure block instances exist for a given region @param string $region Check for bi's with the instance with this name
[ "Ensure", "block", "instances", "exist", "for", "a", "given", "region" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/blocklib.php#L1213-L1219
212,250
moodle/moodle
lib/blocklib.php
block_manager.ensure_content_created
public function ensure_content_created($region, $output) { $this->ensure_instances_exist($region); if (!array_key_exists($region, $this->visibleblockcontent)) { $contents = array(); if (array_key_exists($region, $this->extracontent)) { $contents = $this->extracontent[$region]; } $contents = array_merge($contents, $this->create_block_contents($this->blockinstances[$region], $output, $region)); if (($region == $this->defaultregion) && (!isset($this->page->theme->addblockposition) || $this->page->theme->addblockposition == BLOCK_ADDBLOCK_POSITION_DEFAULT)) { $addblockui = block_add_block_ui($this->page, $output); if ($addblockui) { $contents[] = $addblockui; } } $this->visibleblockcontent[$region] = $contents; } }
php
public function ensure_content_created($region, $output) { $this->ensure_instances_exist($region); if (!array_key_exists($region, $this->visibleblockcontent)) { $contents = array(); if (array_key_exists($region, $this->extracontent)) { $contents = $this->extracontent[$region]; } $contents = array_merge($contents, $this->create_block_contents($this->blockinstances[$region], $output, $region)); if (($region == $this->defaultregion) && (!isset($this->page->theme->addblockposition) || $this->page->theme->addblockposition == BLOCK_ADDBLOCK_POSITION_DEFAULT)) { $addblockui = block_add_block_ui($this->page, $output); if ($addblockui) { $contents[] = $addblockui; } } $this->visibleblockcontent[$region] = $contents; } }
[ "public", "function", "ensure_content_created", "(", "$", "region", ",", "$", "output", ")", "{", "$", "this", "->", "ensure_instances_exist", "(", "$", "region", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "region", ",", "$", "this", "->", "visibleblockcontent", ")", ")", "{", "$", "contents", "=", "array", "(", ")", ";", "if", "(", "array_key_exists", "(", "$", "region", ",", "$", "this", "->", "extracontent", ")", ")", "{", "$", "contents", "=", "$", "this", "->", "extracontent", "[", "$", "region", "]", ";", "}", "$", "contents", "=", "array_merge", "(", "$", "contents", ",", "$", "this", "->", "create_block_contents", "(", "$", "this", "->", "blockinstances", "[", "$", "region", "]", ",", "$", "output", ",", "$", "region", ")", ")", ";", "if", "(", "(", "$", "region", "==", "$", "this", "->", "defaultregion", ")", "&&", "(", "!", "isset", "(", "$", "this", "->", "page", "->", "theme", "->", "addblockposition", ")", "||", "$", "this", "->", "page", "->", "theme", "->", "addblockposition", "==", "BLOCK_ADDBLOCK_POSITION_DEFAULT", ")", ")", "{", "$", "addblockui", "=", "block_add_block_ui", "(", "$", "this", "->", "page", ",", "$", "output", ")", ";", "if", "(", "$", "addblockui", ")", "{", "$", "contents", "[", "]", "=", "$", "addblockui", ";", "}", "}", "$", "this", "->", "visibleblockcontent", "[", "$", "region", "]", "=", "$", "contents", ";", "}", "}" ]
Ensure that there is some content within the given region @param string $region The name of the region to check
[ "Ensure", "that", "there", "is", "some", "content", "within", "the", "given", "region" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/blocklib.php#L1226-L1243
212,251
moodle/moodle
lib/blocklib.php
block_manager.process_url_actions
public function process_url_actions() { if (!$this->page->user_is_editing()) { return false; } return $this->process_url_add() || $this->process_url_delete() || $this->process_url_show_hide() || $this->process_url_edit() || $this->process_url_move(); }
php
public function process_url_actions() { if (!$this->page->user_is_editing()) { return false; } return $this->process_url_add() || $this->process_url_delete() || $this->process_url_show_hide() || $this->process_url_edit() || $this->process_url_move(); }
[ "public", "function", "process_url_actions", "(", ")", "{", "if", "(", "!", "$", "this", "->", "page", "->", "user_is_editing", "(", ")", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "process_url_add", "(", ")", "||", "$", "this", "->", "process_url_delete", "(", ")", "||", "$", "this", "->", "process_url_show_hide", "(", ")", "||", "$", "this", "->", "process_url_edit", "(", ")", "||", "$", "this", "->", "process_url_move", "(", ")", ";", "}" ]
Process any block actions that were specified in the URL. @return boolean true if anything was done. False if not.
[ "Process", "any", "block", "actions", "that", "were", "specified", "in", "the", "URL", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/blocklib.php#L1394-L1401
212,252
moodle/moodle
lib/blocklib.php
block_manager.process_url_show_hide
public function process_url_show_hide() { if ($blockid = optional_param('bui_hideid', null, PARAM_INT)) { $newvisibility = 0; } else if ($blockid = optional_param('bui_showid', null, PARAM_INT)) { $newvisibility = 1; } else { return false; } require_sesskey(); $block = $this->page->blocks->find_instance($blockid); if (!$this->page->user_can_edit_blocks()) { throw new moodle_exception('nopermissions', '', $this->page->url->out(), get_string('hideshowblocks')); } else if (!$block->instance_can_be_hidden()) { return false; } blocks_set_visibility($block->instance, $this->page, $newvisibility); // If the page URL was a guses, it will contain the bui_... param, so we must make sure it is not there. $this->page->ensure_param_not_in_url('bui_hideid'); $this->page->ensure_param_not_in_url('bui_showid'); return true; }
php
public function process_url_show_hide() { if ($blockid = optional_param('bui_hideid', null, PARAM_INT)) { $newvisibility = 0; } else if ($blockid = optional_param('bui_showid', null, PARAM_INT)) { $newvisibility = 1; } else { return false; } require_sesskey(); $block = $this->page->blocks->find_instance($blockid); if (!$this->page->user_can_edit_blocks()) { throw new moodle_exception('nopermissions', '', $this->page->url->out(), get_string('hideshowblocks')); } else if (!$block->instance_can_be_hidden()) { return false; } blocks_set_visibility($block->instance, $this->page, $newvisibility); // If the page URL was a guses, it will contain the bui_... param, so we must make sure it is not there. $this->page->ensure_param_not_in_url('bui_hideid'); $this->page->ensure_param_not_in_url('bui_showid'); return true; }
[ "public", "function", "process_url_show_hide", "(", ")", "{", "if", "(", "$", "blockid", "=", "optional_param", "(", "'bui_hideid'", ",", "null", ",", "PARAM_INT", ")", ")", "{", "$", "newvisibility", "=", "0", ";", "}", "else", "if", "(", "$", "blockid", "=", "optional_param", "(", "'bui_showid'", ",", "null", ",", "PARAM_INT", ")", ")", "{", "$", "newvisibility", "=", "1", ";", "}", "else", "{", "return", "false", ";", "}", "require_sesskey", "(", ")", ";", "$", "block", "=", "$", "this", "->", "page", "->", "blocks", "->", "find_instance", "(", "$", "blockid", ")", ";", "if", "(", "!", "$", "this", "->", "page", "->", "user_can_edit_blocks", "(", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'nopermissions'", ",", "''", ",", "$", "this", "->", "page", "->", "url", "->", "out", "(", ")", ",", "get_string", "(", "'hideshowblocks'", ")", ")", ";", "}", "else", "if", "(", "!", "$", "block", "->", "instance_can_be_hidden", "(", ")", ")", "{", "return", "false", ";", "}", "blocks_set_visibility", "(", "$", "block", "->", "instance", ",", "$", "this", "->", "page", ",", "$", "newvisibility", ")", ";", "// If the page URL was a guses, it will contain the bui_... param, so we must make sure it is not there.", "$", "this", "->", "page", "->", "ensure_param_not_in_url", "(", "'bui_hideid'", ")", ";", "$", "this", "->", "page", "->", "ensure_param_not_in_url", "(", "'bui_showid'", ")", ";", "return", "true", ";", "}" ]
Handle showing or hiding a block. @return boolean true if anything was done. False if not.
[ "Handle", "showing", "or", "hiding", "a", "block", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/blocklib.php#L1572-L1598
212,253
moodle/moodle
admin/tool/lpmigrate/classes/framework_processor.php
framework_processor.process_mapping
protected function process_mapping() { $this->mappings = $this->mapper->get_mappings(); $this->fromids = $this->mapper->get_all_from(); }
php
protected function process_mapping() { $this->mappings = $this->mapper->get_mappings(); $this->fromids = $this->mapper->get_all_from(); }
[ "protected", "function", "process_mapping", "(", ")", "{", "$", "this", "->", "mappings", "=", "$", "this", "->", "mapper", "->", "get_mappings", "(", ")", ";", "$", "this", "->", "fromids", "=", "$", "this", "->", "mapper", "->", "get_all_from", "(", ")", ";", "}" ]
Process the mapping. @return void
[ "Process", "the", "mapping", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lpmigrate/classes/framework_processor.php#L117-L120
212,254
moodle/moodle
admin/tool/lpmigrate/classes/framework_processor.php
framework_processor.find_coursescompetencies
protected function find_coursescompetencies() { global $DB; $this->progress->start_progress(get_string('findingcoursecompetencies', 'tool_lpmigrate'), 3); $this->progress->increment_progress(); $joins = array(); $conditions = array(); $params = array(); // Limit to mapped objects. list($insql, $inparams) = $DB->get_in_or_equal($this->fromids, SQL_PARAMS_NAMED); $conditions[] = "c.id $insql"; $params += $inparams; // Restriction on course IDs. if (!empty($this->allowedcourses)) { list($insql, $inparams) = $DB->get_in_or_equal($this->allowedcourses, SQL_PARAMS_NAMED); $conditions[] = "cc.courseid $insql"; $params += $inparams; } if (!empty($this->disallowedcourses)) { list($insql, $inparams) = $DB->get_in_or_equal($this->disallowedcourses, SQL_PARAMS_NAMED, 'param', false); $conditions[] = "cc.courseid $insql"; $params += $inparams; } // Restriction on start date. if (!empty($this->coursestartdatefrom)) { $joins[] = "JOIN {course} co ON co.id = cc.courseid"; $conditions[] = "co.startdate >= :startdate"; $params += array('startdate' => $this->coursestartdatefrom); } // Find the courses. $ccs = array(); $ccsoutcomes = array(); $joins = implode(' ', $joins); $conditions = implode(' AND ', $conditions); $sql = "SELECT cc.id, cc.courseid, cc.competencyid, cc.ruleoutcome FROM {" . course_competency::TABLE . "} cc JOIN {" . competency::TABLE . "} c ON c.id = cc.competencyid $joins WHERE $conditions ORDER BY cc.sortorder, cc.id"; $records = $DB->get_recordset_sql($sql, $params); $this->progress->increment_progress(); foreach ($records as $record) { if (!isset($ccs[$record->courseid])) { $ccs[$record->courseid] = array(); $ccsoutcomes[$record->courseid] = array(); } $ccs[$record->courseid][] = $record->competencyid; $ccsoutcomes[$record->courseid][$record->competencyid] = $record->ruleoutcome; } $records->close(); $this->coursescompetencies = $ccs; $this->coursescompetenciesoutcomes = $ccsoutcomes; $this->coursesfound = $ccs; $this->progress->increment_progress(); $this->progress->end_progress(); }
php
protected function find_coursescompetencies() { global $DB; $this->progress->start_progress(get_string('findingcoursecompetencies', 'tool_lpmigrate'), 3); $this->progress->increment_progress(); $joins = array(); $conditions = array(); $params = array(); // Limit to mapped objects. list($insql, $inparams) = $DB->get_in_or_equal($this->fromids, SQL_PARAMS_NAMED); $conditions[] = "c.id $insql"; $params += $inparams; // Restriction on course IDs. if (!empty($this->allowedcourses)) { list($insql, $inparams) = $DB->get_in_or_equal($this->allowedcourses, SQL_PARAMS_NAMED); $conditions[] = "cc.courseid $insql"; $params += $inparams; } if (!empty($this->disallowedcourses)) { list($insql, $inparams) = $DB->get_in_or_equal($this->disallowedcourses, SQL_PARAMS_NAMED, 'param', false); $conditions[] = "cc.courseid $insql"; $params += $inparams; } // Restriction on start date. if (!empty($this->coursestartdatefrom)) { $joins[] = "JOIN {course} co ON co.id = cc.courseid"; $conditions[] = "co.startdate >= :startdate"; $params += array('startdate' => $this->coursestartdatefrom); } // Find the courses. $ccs = array(); $ccsoutcomes = array(); $joins = implode(' ', $joins); $conditions = implode(' AND ', $conditions); $sql = "SELECT cc.id, cc.courseid, cc.competencyid, cc.ruleoutcome FROM {" . course_competency::TABLE . "} cc JOIN {" . competency::TABLE . "} c ON c.id = cc.competencyid $joins WHERE $conditions ORDER BY cc.sortorder, cc.id"; $records = $DB->get_recordset_sql($sql, $params); $this->progress->increment_progress(); foreach ($records as $record) { if (!isset($ccs[$record->courseid])) { $ccs[$record->courseid] = array(); $ccsoutcomes[$record->courseid] = array(); } $ccs[$record->courseid][] = $record->competencyid; $ccsoutcomes[$record->courseid][$record->competencyid] = $record->ruleoutcome; } $records->close(); $this->coursescompetencies = $ccs; $this->coursescompetenciesoutcomes = $ccsoutcomes; $this->coursesfound = $ccs; $this->progress->increment_progress(); $this->progress->end_progress(); }
[ "protected", "function", "find_coursescompetencies", "(", ")", "{", "global", "$", "DB", ";", "$", "this", "->", "progress", "->", "start_progress", "(", "get_string", "(", "'findingcoursecompetencies'", ",", "'tool_lpmigrate'", ")", ",", "3", ")", ";", "$", "this", "->", "progress", "->", "increment_progress", "(", ")", ";", "$", "joins", "=", "array", "(", ")", ";", "$", "conditions", "=", "array", "(", ")", ";", "$", "params", "=", "array", "(", ")", ";", "// Limit to mapped objects.", "list", "(", "$", "insql", ",", "$", "inparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "this", "->", "fromids", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "conditions", "[", "]", "=", "\"c.id $insql\"", ";", "$", "params", "+=", "$", "inparams", ";", "// Restriction on course IDs.", "if", "(", "!", "empty", "(", "$", "this", "->", "allowedcourses", ")", ")", "{", "list", "(", "$", "insql", ",", "$", "inparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "this", "->", "allowedcourses", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "conditions", "[", "]", "=", "\"cc.courseid $insql\"", ";", "$", "params", "+=", "$", "inparams", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "disallowedcourses", ")", ")", "{", "list", "(", "$", "insql", ",", "$", "inparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "this", "->", "disallowedcourses", ",", "SQL_PARAMS_NAMED", ",", "'param'", ",", "false", ")", ";", "$", "conditions", "[", "]", "=", "\"cc.courseid $insql\"", ";", "$", "params", "+=", "$", "inparams", ";", "}", "// Restriction on start date.", "if", "(", "!", "empty", "(", "$", "this", "->", "coursestartdatefrom", ")", ")", "{", "$", "joins", "[", "]", "=", "\"JOIN {course} co\n ON co.id = cc.courseid\"", ";", "$", "conditions", "[", "]", "=", "\"co.startdate >= :startdate\"", ";", "$", "params", "+=", "array", "(", "'startdate'", "=>", "$", "this", "->", "coursestartdatefrom", ")", ";", "}", "// Find the courses.", "$", "ccs", "=", "array", "(", ")", ";", "$", "ccsoutcomes", "=", "array", "(", ")", ";", "$", "joins", "=", "implode", "(", "' '", ",", "$", "joins", ")", ";", "$", "conditions", "=", "implode", "(", "' AND '", ",", "$", "conditions", ")", ";", "$", "sql", "=", "\"SELECT cc.id, cc.courseid, cc.competencyid, cc.ruleoutcome\n FROM {\"", ".", "course_competency", "::", "TABLE", ".", "\"} cc\n JOIN {\"", ".", "competency", "::", "TABLE", ".", "\"} c\n ON c.id = cc.competencyid\n $joins\n WHERE $conditions\n ORDER BY cc.sortorder, cc.id\"", ";", "$", "records", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "$", "this", "->", "progress", "->", "increment_progress", "(", ")", ";", "foreach", "(", "$", "records", "as", "$", "record", ")", "{", "if", "(", "!", "isset", "(", "$", "ccs", "[", "$", "record", "->", "courseid", "]", ")", ")", "{", "$", "ccs", "[", "$", "record", "->", "courseid", "]", "=", "array", "(", ")", ";", "$", "ccsoutcomes", "[", "$", "record", "->", "courseid", "]", "=", "array", "(", ")", ";", "}", "$", "ccs", "[", "$", "record", "->", "courseid", "]", "[", "]", "=", "$", "record", "->", "competencyid", ";", "$", "ccsoutcomes", "[", "$", "record", "->", "courseid", "]", "[", "$", "record", "->", "competencyid", "]", "=", "$", "record", "->", "ruleoutcome", ";", "}", "$", "records", "->", "close", "(", ")", ";", "$", "this", "->", "coursescompetencies", "=", "$", "ccs", ";", "$", "this", "->", "coursescompetenciesoutcomes", "=", "$", "ccsoutcomes", ";", "$", "this", "->", "coursesfound", "=", "$", "ccs", ";", "$", "this", "->", "progress", "->", "increment_progress", "(", ")", ";", "$", "this", "->", "progress", "->", "end_progress", "(", ")", ";", "}" ]
Identifies what courses and their competencies to work with. @return void
[ "Identifies", "what", "courses", "and", "their", "competencies", "to", "work", "with", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lpmigrate/classes/framework_processor.php#L126-L192
212,255
moodle/moodle
admin/tool/lpmigrate/classes/framework_processor.php
framework_processor.find_modulecompetencies
protected function find_modulecompetencies() { global $DB; if (empty($this->coursescompetencies)) { return; } $this->progress->start_progress(get_string('findingmodulecompetencies', 'tool_lpmigrate'), 3); $this->progress->increment_progress(); // Limit to mapped objects. list($inidsql, $inidparams) = $DB->get_in_or_equal($this->fromids, SQL_PARAMS_NAMED); // Limit to known courses. list($incoursesql, $incourseparams) = $DB->get_in_or_equal(array_keys($this->coursescompetencies), SQL_PARAMS_NAMED); $sql = "SELECT mc.id, cm.course AS courseid, mc.cmid, mc.competencyid, mc.ruleoutcome FROM {" . course_module_competency::TABLE . "} mc JOIN {course_modules} cm ON cm.id = mc.cmid AND cm.course $incoursesql JOIN {" . competency::TABLE . "} c ON c.id = mc.competencyid WHERE c.id $inidsql ORDER BY mc.sortorder, mc.id"; $params = $inidparams + $incourseparams; $records = $DB->get_recordset_sql($sql, $params); $this->progress->increment_progress(); $cmsfound = array(); $cmcs = array(); $cmcsoutcomes = array(); foreach ($records as $record) { if (!isset($cmcs[$record->courseid])) { $cmcs[$record->courseid] = array(); $cmcsoutcomes[$record->courseid] = array(); } if (!isset($cmcs[$record->courseid][$record->cmid])) { $cmcs[$record->courseid][$record->cmid] = array(); $cmcsoutcomes[$record->courseid][$record->cmid] = array(); } $cmcs[$record->courseid][$record->cmid][] = $record->competencyid; $cmcsoutcomes[$record->courseid][$record->cmid][$record->competencyid] = $record->ruleoutcome; $cmsfound[$record->cmid] = true; } $records->close(); $this->modulecompetencies = $cmcs; $this->modulecompetenciesoutcomes = $cmcsoutcomes; $this->cmsfound = $cmsfound; $this->progress->increment_progress(); $this->progress->end_progress(); }
php
protected function find_modulecompetencies() { global $DB; if (empty($this->coursescompetencies)) { return; } $this->progress->start_progress(get_string('findingmodulecompetencies', 'tool_lpmigrate'), 3); $this->progress->increment_progress(); // Limit to mapped objects. list($inidsql, $inidparams) = $DB->get_in_or_equal($this->fromids, SQL_PARAMS_NAMED); // Limit to known courses. list($incoursesql, $incourseparams) = $DB->get_in_or_equal(array_keys($this->coursescompetencies), SQL_PARAMS_NAMED); $sql = "SELECT mc.id, cm.course AS courseid, mc.cmid, mc.competencyid, mc.ruleoutcome FROM {" . course_module_competency::TABLE . "} mc JOIN {course_modules} cm ON cm.id = mc.cmid AND cm.course $incoursesql JOIN {" . competency::TABLE . "} c ON c.id = mc.competencyid WHERE c.id $inidsql ORDER BY mc.sortorder, mc.id"; $params = $inidparams + $incourseparams; $records = $DB->get_recordset_sql($sql, $params); $this->progress->increment_progress(); $cmsfound = array(); $cmcs = array(); $cmcsoutcomes = array(); foreach ($records as $record) { if (!isset($cmcs[$record->courseid])) { $cmcs[$record->courseid] = array(); $cmcsoutcomes[$record->courseid] = array(); } if (!isset($cmcs[$record->courseid][$record->cmid])) { $cmcs[$record->courseid][$record->cmid] = array(); $cmcsoutcomes[$record->courseid][$record->cmid] = array(); } $cmcs[$record->courseid][$record->cmid][] = $record->competencyid; $cmcsoutcomes[$record->courseid][$record->cmid][$record->competencyid] = $record->ruleoutcome; $cmsfound[$record->cmid] = true; } $records->close(); $this->modulecompetencies = $cmcs; $this->modulecompetenciesoutcomes = $cmcsoutcomes; $this->cmsfound = $cmsfound; $this->progress->increment_progress(); $this->progress->end_progress(); }
[ "protected", "function", "find_modulecompetencies", "(", ")", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "this", "->", "coursescompetencies", ")", ")", "{", "return", ";", "}", "$", "this", "->", "progress", "->", "start_progress", "(", "get_string", "(", "'findingmodulecompetencies'", ",", "'tool_lpmigrate'", ")", ",", "3", ")", ";", "$", "this", "->", "progress", "->", "increment_progress", "(", ")", ";", "// Limit to mapped objects.", "list", "(", "$", "inidsql", ",", "$", "inidparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "this", "->", "fromids", ",", "SQL_PARAMS_NAMED", ")", ";", "// Limit to known courses.", "list", "(", "$", "incoursesql", ",", "$", "incourseparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "array_keys", "(", "$", "this", "->", "coursescompetencies", ")", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "sql", "=", "\"SELECT mc.id, cm.course AS courseid, mc.cmid, mc.competencyid, mc.ruleoutcome\n FROM {\"", ".", "course_module_competency", "::", "TABLE", ".", "\"} mc\n JOIN {course_modules} cm\n ON cm.id = mc.cmid\n AND cm.course $incoursesql\n JOIN {\"", ".", "competency", "::", "TABLE", ".", "\"} c\n ON c.id = mc.competencyid\n WHERE c.id $inidsql\n ORDER BY mc.sortorder, mc.id\"", ";", "$", "params", "=", "$", "inidparams", "+", "$", "incourseparams", ";", "$", "records", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "$", "this", "->", "progress", "->", "increment_progress", "(", ")", ";", "$", "cmsfound", "=", "array", "(", ")", ";", "$", "cmcs", "=", "array", "(", ")", ";", "$", "cmcsoutcomes", "=", "array", "(", ")", ";", "foreach", "(", "$", "records", "as", "$", "record", ")", "{", "if", "(", "!", "isset", "(", "$", "cmcs", "[", "$", "record", "->", "courseid", "]", ")", ")", "{", "$", "cmcs", "[", "$", "record", "->", "courseid", "]", "=", "array", "(", ")", ";", "$", "cmcsoutcomes", "[", "$", "record", "->", "courseid", "]", "=", "array", "(", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "cmcs", "[", "$", "record", "->", "courseid", "]", "[", "$", "record", "->", "cmid", "]", ")", ")", "{", "$", "cmcs", "[", "$", "record", "->", "courseid", "]", "[", "$", "record", "->", "cmid", "]", "=", "array", "(", ")", ";", "$", "cmcsoutcomes", "[", "$", "record", "->", "courseid", "]", "[", "$", "record", "->", "cmid", "]", "=", "array", "(", ")", ";", "}", "$", "cmcs", "[", "$", "record", "->", "courseid", "]", "[", "$", "record", "->", "cmid", "]", "[", "]", "=", "$", "record", "->", "competencyid", ";", "$", "cmcsoutcomes", "[", "$", "record", "->", "courseid", "]", "[", "$", "record", "->", "cmid", "]", "[", "$", "record", "->", "competencyid", "]", "=", "$", "record", "->", "ruleoutcome", ";", "$", "cmsfound", "[", "$", "record", "->", "cmid", "]", "=", "true", ";", "}", "$", "records", "->", "close", "(", ")", ";", "$", "this", "->", "modulecompetencies", "=", "$", "cmcs", ";", "$", "this", "->", "modulecompetenciesoutcomes", "=", "$", "cmcsoutcomes", ";", "$", "this", "->", "cmsfound", "=", "$", "cmsfound", ";", "$", "this", "->", "progress", "->", "increment_progress", "(", ")", ";", "$", "this", "->", "progress", "->", "end_progress", "(", ")", ";", "}" ]
Identifies what course modules and their competencies to work with. @return void
[ "Identifies", "what", "course", "modules", "and", "their", "competencies", "to", "work", "with", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lpmigrate/classes/framework_processor.php#L198-L250
212,256
moodle/moodle
admin/tool/lpmigrate/classes/framework_processor.php
framework_processor.log_warning
protected function log_warning($courseid, $competencyid, $cmid, $message) { $this->warnings[] = array( 'courseid' => $courseid, 'competencyid' => $competencyid, 'cmid' => $cmid, 'message' => $message ); }
php
protected function log_warning($courseid, $competencyid, $cmid, $message) { $this->warnings[] = array( 'courseid' => $courseid, 'competencyid' => $competencyid, 'cmid' => $cmid, 'message' => $message ); }
[ "protected", "function", "log_warning", "(", "$", "courseid", ",", "$", "competencyid", ",", "$", "cmid", ",", "$", "message", ")", "{", "$", "this", "->", "warnings", "[", "]", "=", "array", "(", "'courseid'", "=>", "$", "courseid", ",", "'competencyid'", "=>", "$", "competencyid", ",", "'cmid'", "=>", "$", "cmid", ",", "'message'", "=>", "$", "message", ")", ";", "}" ]
Log a warning. @param int $courseid The course ID. @param int $competencyid The competency ID. @param int $cmid The CM ID. @param string $message The warning message. @return void
[ "Log", "a", "warning", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lpmigrate/classes/framework_processor.php#L392-L399
212,257
moodle/moodle
admin/tool/lpmigrate/classes/framework_processor.php
framework_processor.proceed
public function proceed() { if ($this->has_run()) { throw new coding_exception('The processor has already run.'); } else if (!$this->mapper->has_mappings()) { throw new coding_exception('Mapping was not set.'); } $this->proceeded = true; $this->process_mapping(); $this->find_coursescompetencies(); $this->find_modulecompetencies(); $this->process_courses(); }
php
public function proceed() { if ($this->has_run()) { throw new coding_exception('The processor has already run.'); } else if (!$this->mapper->has_mappings()) { throw new coding_exception('Mapping was not set.'); } $this->proceeded = true; $this->process_mapping(); $this->find_coursescompetencies(); $this->find_modulecompetencies(); $this->process_courses(); }
[ "public", "function", "proceed", "(", ")", "{", "if", "(", "$", "this", "->", "has_run", "(", ")", ")", "{", "throw", "new", "coding_exception", "(", "'The processor has already run.'", ")", ";", "}", "else", "if", "(", "!", "$", "this", "->", "mapper", "->", "has_mappings", "(", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Mapping was not set.'", ")", ";", "}", "$", "this", "->", "proceeded", "=", "true", ";", "$", "this", "->", "process_mapping", "(", ")", ";", "$", "this", "->", "find_coursescompetencies", "(", ")", ";", "$", "this", "->", "find_modulecompetencies", "(", ")", ";", "$", "this", "->", "process_courses", "(", ")", ";", "}" ]
Execute the whole task. @return void
[ "Execute", "the", "whole", "task", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lpmigrate/classes/framework_processor.php#L405-L417
212,258
moodle/moodle
lib/behat/classes/util.php
behat_util.drop_site
public static function drop_site() { if (!defined('BEHAT_UTIL')) { throw new coding_exception('This method can be only used by Behat CLI tool'); } self::reset_dataroot(); self::drop_database(true); self::drop_dataroot(); }
php
public static function drop_site() { if (!defined('BEHAT_UTIL')) { throw new coding_exception('This method can be only used by Behat CLI tool'); } self::reset_dataroot(); self::drop_database(true); self::drop_dataroot(); }
[ "public", "static", "function", "drop_site", "(", ")", "{", "if", "(", "!", "defined", "(", "'BEHAT_UTIL'", ")", ")", "{", "throw", "new", "coding_exception", "(", "'This method can be only used by Behat CLI tool'", ")", ";", "}", "self", "::", "reset_dataroot", "(", ")", ";", "self", "::", "drop_database", "(", "true", ")", ";", "self", "::", "drop_dataroot", "(", ")", ";", "}" ]
Drops dataroot and remove test database tables @throws coding_exception @return void
[ "Drops", "dataroot", "and", "remove", "test", "database", "tables" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/util.php#L135-L144
212,259
moodle/moodle
lib/behat/classes/util.php
behat_util.drop_dataroot
public static function drop_dataroot() { global $CFG; // As behat directory is now created under default $CFG->behat_dataroot_parent, so remove the whole dir. if ($CFG->behat_dataroot !== $CFG->behat_dataroot_parent) { remove_dir($CFG->behat_dataroot, false); } else { // It should never come here. throw new moodle_exception("Behat dataroot should not be same as parent behat data root."); } }
php
public static function drop_dataroot() { global $CFG; // As behat directory is now created under default $CFG->behat_dataroot_parent, so remove the whole dir. if ($CFG->behat_dataroot !== $CFG->behat_dataroot_parent) { remove_dir($CFG->behat_dataroot, false); } else { // It should never come here. throw new moodle_exception("Behat dataroot should not be same as parent behat data root."); } }
[ "public", "static", "function", "drop_dataroot", "(", ")", "{", "global", "$", "CFG", ";", "// As behat directory is now created under default $CFG->behat_dataroot_parent, so remove the whole dir.", "if", "(", "$", "CFG", "->", "behat_dataroot", "!==", "$", "CFG", "->", "behat_dataroot_parent", ")", "{", "remove_dir", "(", "$", "CFG", "->", "behat_dataroot", ",", "false", ")", ";", "}", "else", "{", "// It should never come here.", "throw", "new", "moodle_exception", "(", "\"Behat dataroot should not be same as parent behat data root.\"", ")", ";", "}", "}" ]
Delete files and directories under dataroot.
[ "Delete", "files", "and", "directories", "under", "dataroot", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/classes/util.php#L149-L159
212,260
moodle/moodle
enrol/paypal/lib.php
enrol_paypal_plugin.get_roleid_options
protected function get_roleid_options($instance, $context) { if ($instance->id) { $roles = get_default_enrol_roles($context, $instance->roleid); } else { $roles = get_default_enrol_roles($context, $this->get_config('roleid')); } return $roles; }
php
protected function get_roleid_options($instance, $context) { if ($instance->id) { $roles = get_default_enrol_roles($context, $instance->roleid); } else { $roles = get_default_enrol_roles($context, $this->get_config('roleid')); } return $roles; }
[ "protected", "function", "get_roleid_options", "(", "$", "instance", ",", "$", "context", ")", "{", "if", "(", "$", "instance", "->", "id", ")", "{", "$", "roles", "=", "get_default_enrol_roles", "(", "$", "context", ",", "$", "instance", "->", "roleid", ")", ";", "}", "else", "{", "$", "roles", "=", "get_default_enrol_roles", "(", "$", "context", ",", "$", "this", "->", "get_config", "(", "'roleid'", ")", ")", ";", "}", "return", "$", "roles", ";", "}" ]
Return an array of valid options for the roleid. @param stdClass $instance @param context $context @return array
[ "Return", "an", "array", "of", "valid", "options", "for", "the", "roleid", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/paypal/lib.php#L291-L298
212,261
moodle/moodle
analytics/classes/local/time_splitting/base.php
base.set_analysable
public function set_analysable(\core_analytics\analysable $analysable) { $this->analysable = $analysable; $this->ranges = $this->define_ranges(); $this->validate_ranges(); }
php
public function set_analysable(\core_analytics\analysable $analysable) { $this->analysable = $analysable; $this->ranges = $this->define_ranges(); $this->validate_ranges(); }
[ "public", "function", "set_analysable", "(", "\\", "core_analytics", "\\", "analysable", "$", "analysable", ")", "{", "$", "this", "->", "analysable", "=", "$", "analysable", ";", "$", "this", "->", "ranges", "=", "$", "this", "->", "define_ranges", "(", ")", ";", "$", "this", "->", "validate_ranges", "(", ")", ";", "}" ]
Assigns the analysable and updates the time ranges according to the analysable start and end dates. @param \core_analytics\analysable $analysable @return void
[ "Assigns", "the", "analysable", "and", "updates", "the", "time", "ranges", "according", "to", "the", "analysable", "start", "and", "end", "dates", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/time_splitting/base.php#L97-L101
212,262
moodle/moodle
analytics/classes/local/time_splitting/base.php
base.ready_to_train
public function ready_to_train($range) { $now = time(); if ($range['time'] <= $now && $range['end'] <= $now) { return true; } return false; }
php
public function ready_to_train($range) { $now = time(); if ($range['time'] <= $now && $range['end'] <= $now) { return true; } return false; }
[ "public", "function", "ready_to_train", "(", "$", "range", ")", "{", "$", "now", "=", "time", "(", ")", ";", "if", "(", "$", "range", "[", "'time'", "]", "<=", "$", "now", "&&", "$", "range", "[", "'end'", "]", "<=", "$", "now", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Should we use this time range for training? @param array $range @return bool
[ "Should", "we", "use", "this", "time", "range", "for", "training?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/time_splitting/base.php#L141-L147
212,263
moodle/moodle
analytics/classes/local/time_splitting/base.php
base.get_most_recent_prediction_range
public function get_most_recent_prediction_range() { $ranges = $this->get_all_ranges(); // Opposite order as we are interested in the last range that can be used for prediction. krsort($ranges); // We already provided the analysable to the time splitting method, there is no need to feed it back. foreach ($ranges as $rangeindex => $range) { if ($this->ready_to_predict($range)) { // We need to maintain the same indexes. return array($rangeindex => $range); } } return array(); }
php
public function get_most_recent_prediction_range() { $ranges = $this->get_all_ranges(); // Opposite order as we are interested in the last range that can be used for prediction. krsort($ranges); // We already provided the analysable to the time splitting method, there is no need to feed it back. foreach ($ranges as $rangeindex => $range) { if ($this->ready_to_predict($range)) { // We need to maintain the same indexes. return array($rangeindex => $range); } } return array(); }
[ "public", "function", "get_most_recent_prediction_range", "(", ")", "{", "$", "ranges", "=", "$", "this", "->", "get_all_ranges", "(", ")", ";", "// Opposite order as we are interested in the last range that can be used for prediction.", "krsort", "(", "$", "ranges", ")", ";", "// We already provided the analysable to the time splitting method, there is no need to feed it back.", "foreach", "(", "$", "ranges", "as", "$", "rangeindex", "=>", "$", "range", ")", "{", "if", "(", "$", "this", "->", "ready_to_predict", "(", "$", "range", ")", ")", "{", "// We need to maintain the same indexes.", "return", "array", "(", "$", "rangeindex", "=>", "$", "range", ")", ";", "}", "}", "return", "array", "(", ")", ";", "}" ]
Returns the most recent range that can be used to predict. This method is only called when calculating predictions. @return array
[ "Returns", "the", "most", "recent", "range", "that", "can", "be", "used", "to", "predict", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/time_splitting/base.php#L187-L203
212,264
moodle/moodle
analytics/classes/local/time_splitting/base.php
base.get_range_by_index
public function get_range_by_index($rangeindex) { if (!isset($this->ranges[$rangeindex])) { return false; } return $this->ranges[$rangeindex]; }
php
public function get_range_by_index($rangeindex) { if (!isset($this->ranges[$rangeindex])) { return false; } return $this->ranges[$rangeindex]; }
[ "public", "function", "get_range_by_index", "(", "$", "rangeindex", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "ranges", "[", "$", "rangeindex", "]", ")", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "ranges", "[", "$", "rangeindex", "]", ";", "}" ]
Returns range data by its index. @param int $rangeindex @return array|false Range data or false if the index is not part of the existing ranges.
[ "Returns", "range", "data", "by", "its", "index", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/time_splitting/base.php#L211-L216
212,265
moodle/moodle
analytics/classes/local/time_splitting/base.php
base.validate_ranges
protected function validate_ranges() { foreach ($this->ranges as $key => $range) { if (!isset($this->ranges[$key]['start']) || !isset($this->ranges[$key]['end']) || !isset($this->ranges[$key]['time'])) { throw new \coding_exception($this->get_id() . ' time splitting method "' . $key . '" range is not fully defined. We need a start timestamp and an end timestamp.'); } } }
php
protected function validate_ranges() { foreach ($this->ranges as $key => $range) { if (!isset($this->ranges[$key]['start']) || !isset($this->ranges[$key]['end']) || !isset($this->ranges[$key]['time'])) { throw new \coding_exception($this->get_id() . ' time splitting method "' . $key . '" range is not fully defined. We need a start timestamp and an end timestamp.'); } } }
[ "protected", "function", "validate_ranges", "(", ")", "{", "foreach", "(", "$", "this", "->", "ranges", "as", "$", "key", "=>", "$", "range", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "ranges", "[", "$", "key", "]", "[", "'start'", "]", ")", "||", "!", "isset", "(", "$", "this", "->", "ranges", "[", "$", "key", "]", "[", "'end'", "]", ")", "||", "!", "isset", "(", "$", "this", "->", "ranges", "[", "$", "key", "]", "[", "'time'", "]", ")", ")", "{", "throw", "new", "\\", "coding_exception", "(", "$", "this", "->", "get_id", "(", ")", ".", "' time splitting method \"'", ".", "$", "key", ".", "'\" range is not fully defined. We need a start timestamp and an end timestamp.'", ")", ";", "}", "}", "}" ]
Validates the time splitting method ranges. @throws \coding_exception @return void
[ "Validates", "the", "time", "splitting", "method", "ranges", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/local/time_splitting/base.php#L293-L301
212,266
moodle/moodle
report/completion/classes/event/user_report_viewed.php
user_report_viewed.validate_data
protected function validate_data() { parent::validate_data(); if ($this->contextlevel != CONTEXT_COURSE) { throw new \coding_exception('Context level must be CONTEXT_COURSE.'); } if (!isset($this->relateduserid)) { throw new \coding_exception('The \'relateduserid\' must be set.'); } }
php
protected function validate_data() { parent::validate_data(); if ($this->contextlevel != CONTEXT_COURSE) { throw new \coding_exception('Context level must be CONTEXT_COURSE.'); } if (!isset($this->relateduserid)) { throw new \coding_exception('The \'relateduserid\' must be set.'); } }
[ "protected", "function", "validate_data", "(", ")", "{", "parent", "::", "validate_data", "(", ")", ";", "if", "(", "$", "this", "->", "contextlevel", "!=", "CONTEXT_COURSE", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'Context level must be CONTEXT_COURSE.'", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "relateduserid", ")", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'The \\'relateduserid\\' must be set.'", ")", ";", "}", "}" ]
custom validations. @throws \coding_exception when validation fails. @return void
[ "custom", "validations", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/completion/classes/event/user_report_viewed.php#L92-L101
212,267
moodle/moodle
mod/workshop/allocation/lib.php
workshop_allocation_result.set_status
public function set_status($status, $message = null) { $this->status = $status; $this->message = is_null($message) ? $this->message : $message; $this->timeend = time(); }
php
public function set_status($status, $message = null) { $this->status = $status; $this->message = is_null($message) ? $this->message : $message; $this->timeend = time(); }
[ "public", "function", "set_status", "(", "$", "status", ",", "$", "message", "=", "null", ")", "{", "$", "this", "->", "status", "=", "$", "status", ";", "$", "this", "->", "message", "=", "is_null", "(", "$", "message", ")", "?", "$", "this", "->", "message", ":", "$", "message", ";", "$", "this", "->", "timeend", "=", "time", "(", ")", ";", "}" ]
Sets the result status of the allocation @param int $status the status code, eg {@link self::STATUS_OK} @param string $message optional status message
[ "Sets", "the", "result", "status", "of", "the", "allocation" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/allocation/lib.php#L119-L123
212,268
moodle/moodle
mod/workshop/allocation/lib.php
workshop_allocation_result.log
public function log($message, $type = 'ok', $indent = 0) { $log = new stdClass(); $log->message = $message; $log->type = $type; $log->indent = $indent; $this->logs[] = $log; }
php
public function log($message, $type = 'ok', $indent = 0) { $log = new stdClass(); $log->message = $message; $log->type = $type; $log->indent = $indent; $this->logs[] = $log; }
[ "public", "function", "log", "(", "$", "message", ",", "$", "type", "=", "'ok'", ",", "$", "indent", "=", "0", ")", "{", "$", "log", "=", "new", "stdClass", "(", ")", ";", "$", "log", "->", "message", "=", "$", "message", ";", "$", "log", "->", "type", "=", "$", "type", ";", "$", "log", "->", "indent", "=", "$", "indent", ";", "$", "this", "->", "logs", "[", "]", "=", "$", "log", ";", "}" ]
Appends a new message to the log The available levels are ok - success, eg. new allocation was created info - informational message error - error message, eg. no more peers available debug - debugging info @param string $message message text to display @param string $type the type of the message @param int $indent eventual indentation level (the message is related to the previous one with the lower indent)
[ "Appends", "a", "new", "message", "to", "the", "log" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/allocation/lib.php#L159-L166
212,269
moodle/moodle
lib/formslib.php
moodleform.focus
function focus($name=NULL) { $form =& $this->_form; $elkeys = array_keys($form->_elementIndex); $error = false; if (isset($form->_errors) && 0 != count($form->_errors)){ $errorkeys = array_keys($form->_errors); $elkeys = array_intersect($elkeys, $errorkeys); $error = true; } if ($error or empty($name)) { $names = array(); while (empty($names) and !empty($elkeys)) { $el = array_shift($elkeys); $names = $form->_getElNamesRecursive($el); } if (!empty($names)) { $name = array_shift($names); } } $focus = ''; if (!empty($name)) { $focus = 'forms[\''.$form->getAttribute('id').'\'].elements[\''.$name.'\']'; } return $focus; }
php
function focus($name=NULL) { $form =& $this->_form; $elkeys = array_keys($form->_elementIndex); $error = false; if (isset($form->_errors) && 0 != count($form->_errors)){ $errorkeys = array_keys($form->_errors); $elkeys = array_intersect($elkeys, $errorkeys); $error = true; } if ($error or empty($name)) { $names = array(); while (empty($names) and !empty($elkeys)) { $el = array_shift($elkeys); $names = $form->_getElNamesRecursive($el); } if (!empty($names)) { $name = array_shift($names); } } $focus = ''; if (!empty($name)) { $focus = 'forms[\''.$form->getAttribute('id').'\'].elements[\''.$name.'\']'; } return $focus; }
[ "function", "focus", "(", "$", "name", "=", "NULL", ")", "{", "$", "form", "=", "&", "$", "this", "->", "_form", ";", "$", "elkeys", "=", "array_keys", "(", "$", "form", "->", "_elementIndex", ")", ";", "$", "error", "=", "false", ";", "if", "(", "isset", "(", "$", "form", "->", "_errors", ")", "&&", "0", "!=", "count", "(", "$", "form", "->", "_errors", ")", ")", "{", "$", "errorkeys", "=", "array_keys", "(", "$", "form", "->", "_errors", ")", ";", "$", "elkeys", "=", "array_intersect", "(", "$", "elkeys", ",", "$", "errorkeys", ")", ";", "$", "error", "=", "true", ";", "}", "if", "(", "$", "error", "or", "empty", "(", "$", "name", ")", ")", "{", "$", "names", "=", "array", "(", ")", ";", "while", "(", "empty", "(", "$", "names", ")", "and", "!", "empty", "(", "$", "elkeys", ")", ")", "{", "$", "el", "=", "array_shift", "(", "$", "elkeys", ")", ";", "$", "names", "=", "$", "form", "->", "_getElNamesRecursive", "(", "$", "el", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "names", ")", ")", "{", "$", "name", "=", "array_shift", "(", "$", "names", ")", ";", "}", "}", "$", "focus", "=", "''", ";", "if", "(", "!", "empty", "(", "$", "name", ")", ")", "{", "$", "focus", "=", "'forms[\\''", ".", "$", "form", "->", "getAttribute", "(", "'id'", ")", ".", "'\\'].elements[\\''", ".", "$", "name", ".", "'\\']'", ";", "}", "return", "$", "focus", ";", "}" ]
To autofocus on first form element or first element with error. @param string $name if this is set then the focus is forced to a field with this name @return string javascript to select form element with first error or first element if no errors. Use this as a parameter when calling print_header
[ "To", "autofocus", "on", "first", "form", "element", "or", "first", "element", "with", "error", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/formslib.php#L255-L282
212,270
moodle/moodle
lib/formslib.php
moodleform._process_submission
function _process_submission($method) { $submission = array(); if (!empty($this->_ajaxformdata)) { $submission = $this->_ajaxformdata; } else if ($method == 'post') { if (!empty($_POST)) { $submission = $_POST; } } else { $submission = $_GET; merge_query_params($submission, $_POST); // Emulate handling of parameters in xxxx_param(). } // following trick is needed to enable proper sesskey checks when using GET forms // the _qf__.$this->_formname serves as a marker that form was actually submitted if (array_key_exists('_qf__'.$this->_formname, $submission) and $submission['_qf__'.$this->_formname] == 1) { if (!confirm_sesskey()) { print_error('invalidsesskey'); } $files = $_FILES; } else { $submission = array(); $files = array(); } $this->detectMissingSetType(); $this->_form->updateSubmission($submission, $files); }
php
function _process_submission($method) { $submission = array(); if (!empty($this->_ajaxformdata)) { $submission = $this->_ajaxformdata; } else if ($method == 'post') { if (!empty($_POST)) { $submission = $_POST; } } else { $submission = $_GET; merge_query_params($submission, $_POST); // Emulate handling of parameters in xxxx_param(). } // following trick is needed to enable proper sesskey checks when using GET forms // the _qf__.$this->_formname serves as a marker that form was actually submitted if (array_key_exists('_qf__'.$this->_formname, $submission) and $submission['_qf__'.$this->_formname] == 1) { if (!confirm_sesskey()) { print_error('invalidsesskey'); } $files = $_FILES; } else { $submission = array(); $files = array(); } $this->detectMissingSetType(); $this->_form->updateSubmission($submission, $files); }
[ "function", "_process_submission", "(", "$", "method", ")", "{", "$", "submission", "=", "array", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "_ajaxformdata", ")", ")", "{", "$", "submission", "=", "$", "this", "->", "_ajaxformdata", ";", "}", "else", "if", "(", "$", "method", "==", "'post'", ")", "{", "if", "(", "!", "empty", "(", "$", "_POST", ")", ")", "{", "$", "submission", "=", "$", "_POST", ";", "}", "}", "else", "{", "$", "submission", "=", "$", "_GET", ";", "merge_query_params", "(", "$", "submission", ",", "$", "_POST", ")", ";", "// Emulate handling of parameters in xxxx_param().", "}", "// following trick is needed to enable proper sesskey checks when using GET forms", "// the _qf__.$this->_formname serves as a marker that form was actually submitted", "if", "(", "array_key_exists", "(", "'_qf__'", ".", "$", "this", "->", "_formname", ",", "$", "submission", ")", "and", "$", "submission", "[", "'_qf__'", ".", "$", "this", "->", "_formname", "]", "==", "1", ")", "{", "if", "(", "!", "confirm_sesskey", "(", ")", ")", "{", "print_error", "(", "'invalidsesskey'", ")", ";", "}", "$", "files", "=", "$", "_FILES", ";", "}", "else", "{", "$", "submission", "=", "array", "(", ")", ";", "$", "files", "=", "array", "(", ")", ";", "}", "$", "this", "->", "detectMissingSetType", "(", ")", ";", "$", "this", "->", "_form", "->", "updateSubmission", "(", "$", "submission", ",", "$", "files", ")", ";", "}" ]
Internal method. Alters submitted data to be suitable for quickforms processing. Must be called when the form is fully set up. @param string $method name of the method which alters submitted data
[ "Internal", "method", ".", "Alters", "submitted", "data", "to", "be", "suitable", "for", "quickforms", "processing", ".", "Must", "be", "called", "when", "the", "form", "is", "fully", "set", "up", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/formslib.php#L290-L317
212,271
moodle/moodle
lib/formslib.php
moodleform._validate_files
function _validate_files(&$files) { global $CFG, $COURSE; $files = array(); if (empty($_FILES)) { // we do not need to do any checks because no files were submitted // note: server side rules do not work for files - use custom verification in validate() instead return true; } $errors = array(); $filenames = array(); // now check that we really want each file foreach ($_FILES as $elname=>$file) { $required = $this->_form->isElementRequired($elname); if ($file['error'] == 4 and $file['size'] == 0) { if ($required) { $errors[$elname] = get_string('required'); } unset($_FILES[$elname]); continue; } if (!empty($file['error'])) { $errors[$elname] = file_get_upload_error($file['error']); unset($_FILES[$elname]); continue; } if (!is_uploaded_file($file['tmp_name'])) { // TODO: improve error message $errors[$elname] = get_string('error'); unset($_FILES[$elname]); continue; } if (!$this->_form->elementExists($elname) or !$this->_form->getElementType($elname)=='file') { // hmm, this file was not requested unset($_FILES[$elname]); continue; } // NOTE: the viruses are scanned in file picker, no need to deal with them here. $filename = clean_param($_FILES[$elname]['name'], PARAM_FILE); if ($filename === '') { // TODO: improve error message - wrong chars $errors[$elname] = get_string('error'); unset($_FILES[$elname]); continue; } if (in_array($filename, $filenames)) { // TODO: improve error message - duplicate name $errors[$elname] = get_string('error'); unset($_FILES[$elname]); continue; } $filenames[] = $filename; $_FILES[$elname]['name'] = $filename; $files[$elname] = $_FILES[$elname]['tmp_name']; } // return errors if found if (count($errors) == 0){ return true; } else { $files = array(); return $errors; } }
php
function _validate_files(&$files) { global $CFG, $COURSE; $files = array(); if (empty($_FILES)) { // we do not need to do any checks because no files were submitted // note: server side rules do not work for files - use custom verification in validate() instead return true; } $errors = array(); $filenames = array(); // now check that we really want each file foreach ($_FILES as $elname=>$file) { $required = $this->_form->isElementRequired($elname); if ($file['error'] == 4 and $file['size'] == 0) { if ($required) { $errors[$elname] = get_string('required'); } unset($_FILES[$elname]); continue; } if (!empty($file['error'])) { $errors[$elname] = file_get_upload_error($file['error']); unset($_FILES[$elname]); continue; } if (!is_uploaded_file($file['tmp_name'])) { // TODO: improve error message $errors[$elname] = get_string('error'); unset($_FILES[$elname]); continue; } if (!$this->_form->elementExists($elname) or !$this->_form->getElementType($elname)=='file') { // hmm, this file was not requested unset($_FILES[$elname]); continue; } // NOTE: the viruses are scanned in file picker, no need to deal with them here. $filename = clean_param($_FILES[$elname]['name'], PARAM_FILE); if ($filename === '') { // TODO: improve error message - wrong chars $errors[$elname] = get_string('error'); unset($_FILES[$elname]); continue; } if (in_array($filename, $filenames)) { // TODO: improve error message - duplicate name $errors[$elname] = get_string('error'); unset($_FILES[$elname]); continue; } $filenames[] = $filename; $_FILES[$elname]['name'] = $filename; $files[$elname] = $_FILES[$elname]['tmp_name']; } // return errors if found if (count($errors) == 0){ return true; } else { $files = array(); return $errors; } }
[ "function", "_validate_files", "(", "&", "$", "files", ")", "{", "global", "$", "CFG", ",", "$", "COURSE", ";", "$", "files", "=", "array", "(", ")", ";", "if", "(", "empty", "(", "$", "_FILES", ")", ")", "{", "// we do not need to do any checks because no files were submitted", "// note: server side rules do not work for files - use custom verification in validate() instead", "return", "true", ";", "}", "$", "errors", "=", "array", "(", ")", ";", "$", "filenames", "=", "array", "(", ")", ";", "// now check that we really want each file", "foreach", "(", "$", "_FILES", "as", "$", "elname", "=>", "$", "file", ")", "{", "$", "required", "=", "$", "this", "->", "_form", "->", "isElementRequired", "(", "$", "elname", ")", ";", "if", "(", "$", "file", "[", "'error'", "]", "==", "4", "and", "$", "file", "[", "'size'", "]", "==", "0", ")", "{", "if", "(", "$", "required", ")", "{", "$", "errors", "[", "$", "elname", "]", "=", "get_string", "(", "'required'", ")", ";", "}", "unset", "(", "$", "_FILES", "[", "$", "elname", "]", ")", ";", "continue", ";", "}", "if", "(", "!", "empty", "(", "$", "file", "[", "'error'", "]", ")", ")", "{", "$", "errors", "[", "$", "elname", "]", "=", "file_get_upload_error", "(", "$", "file", "[", "'error'", "]", ")", ";", "unset", "(", "$", "_FILES", "[", "$", "elname", "]", ")", ";", "continue", ";", "}", "if", "(", "!", "is_uploaded_file", "(", "$", "file", "[", "'tmp_name'", "]", ")", ")", "{", "// TODO: improve error message", "$", "errors", "[", "$", "elname", "]", "=", "get_string", "(", "'error'", ")", ";", "unset", "(", "$", "_FILES", "[", "$", "elname", "]", ")", ";", "continue", ";", "}", "if", "(", "!", "$", "this", "->", "_form", "->", "elementExists", "(", "$", "elname", ")", "or", "!", "$", "this", "->", "_form", "->", "getElementType", "(", "$", "elname", ")", "==", "'file'", ")", "{", "// hmm, this file was not requested", "unset", "(", "$", "_FILES", "[", "$", "elname", "]", ")", ";", "continue", ";", "}", "// NOTE: the viruses are scanned in file picker, no need to deal with them here.", "$", "filename", "=", "clean_param", "(", "$", "_FILES", "[", "$", "elname", "]", "[", "'name'", "]", ",", "PARAM_FILE", ")", ";", "if", "(", "$", "filename", "===", "''", ")", "{", "// TODO: improve error message - wrong chars", "$", "errors", "[", "$", "elname", "]", "=", "get_string", "(", "'error'", ")", ";", "unset", "(", "$", "_FILES", "[", "$", "elname", "]", ")", ";", "continue", ";", "}", "if", "(", "in_array", "(", "$", "filename", ",", "$", "filenames", ")", ")", "{", "// TODO: improve error message - duplicate name", "$", "errors", "[", "$", "elname", "]", "=", "get_string", "(", "'error'", ")", ";", "unset", "(", "$", "_FILES", "[", "$", "elname", "]", ")", ";", "continue", ";", "}", "$", "filenames", "[", "]", "=", "$", "filename", ";", "$", "_FILES", "[", "$", "elname", "]", "[", "'name'", "]", "=", "$", "filename", ";", "$", "files", "[", "$", "elname", "]", "=", "$", "_FILES", "[", "$", "elname", "]", "[", "'tmp_name'", "]", ";", "}", "// return errors if found", "if", "(", "count", "(", "$", "errors", ")", "==", "0", ")", "{", "return", "true", ";", "}", "else", "{", "$", "files", "=", "array", "(", ")", ";", "return", "$", "errors", ";", "}", "}" ]
Internal method. Validates all old-style deprecated uploaded files. The new way is to upload files via repository api. @param array $files list of files to be validated @return bool|array Success or an array of errors
[ "Internal", "method", ".", "Validates", "all", "old", "-", "style", "deprecated", "uploaded", "files", ".", "The", "new", "way", "is", "to", "upload", "files", "via", "repository", "api", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/formslib.php#L335-L409
212,272
moodle/moodle
lib/formslib.php
moodleform.validate_draft_files
protected function validate_draft_files() { global $USER; $mform =& $this->_form; $errors = array(); //Go through all the required elements and make sure you hit filepicker or //filemanager element. foreach ($mform->_rules as $elementname => $rules) { $elementtype = $mform->getElementType($elementname); //If element is of type filepicker then do validation if (($elementtype == 'filepicker') || ($elementtype == 'filemanager')){ //Check if rule defined is required rule foreach ($rules as $rule) { if ($rule['type'] == 'required') { $draftid = (int)$mform->getSubmitValue($elementname); $fs = get_file_storage(); $context = context_user::instance($USER->id); if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) { $errors[$elementname] = $rule['message']; } } } } } // Check all the filemanager elements to make sure they do not have too many // files in them. foreach ($mform->_elements as $element) { if ($element->_type == 'filemanager') { $maxfiles = $element->getMaxfiles(); if ($maxfiles > 0) { $draftid = (int)$element->getValue(); $fs = get_file_storage(); $context = context_user::instance($USER->id); $files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, '', false); if (count($files) > $maxfiles) { $errors[$element->getName()] = get_string('err_maxfiles', 'form', $maxfiles); } } } } if (empty($errors)) { return true; } else { return $errors; } }
php
protected function validate_draft_files() { global $USER; $mform =& $this->_form; $errors = array(); //Go through all the required elements and make sure you hit filepicker or //filemanager element. foreach ($mform->_rules as $elementname => $rules) { $elementtype = $mform->getElementType($elementname); //If element is of type filepicker then do validation if (($elementtype == 'filepicker') || ($elementtype == 'filemanager')){ //Check if rule defined is required rule foreach ($rules as $rule) { if ($rule['type'] == 'required') { $draftid = (int)$mform->getSubmitValue($elementname); $fs = get_file_storage(); $context = context_user::instance($USER->id); if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) { $errors[$elementname] = $rule['message']; } } } } } // Check all the filemanager elements to make sure they do not have too many // files in them. foreach ($mform->_elements as $element) { if ($element->_type == 'filemanager') { $maxfiles = $element->getMaxfiles(); if ($maxfiles > 0) { $draftid = (int)$element->getValue(); $fs = get_file_storage(); $context = context_user::instance($USER->id); $files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, '', false); if (count($files) > $maxfiles) { $errors[$element->getName()] = get_string('err_maxfiles', 'form', $maxfiles); } } } } if (empty($errors)) { return true; } else { return $errors; } }
[ "protected", "function", "validate_draft_files", "(", ")", "{", "global", "$", "USER", ";", "$", "mform", "=", "&", "$", "this", "->", "_form", ";", "$", "errors", "=", "array", "(", ")", ";", "//Go through all the required elements and make sure you hit filepicker or", "//filemanager element.", "foreach", "(", "$", "mform", "->", "_rules", "as", "$", "elementname", "=>", "$", "rules", ")", "{", "$", "elementtype", "=", "$", "mform", "->", "getElementType", "(", "$", "elementname", ")", ";", "//If element is of type filepicker then do validation", "if", "(", "(", "$", "elementtype", "==", "'filepicker'", ")", "||", "(", "$", "elementtype", "==", "'filemanager'", ")", ")", "{", "//Check if rule defined is required rule", "foreach", "(", "$", "rules", "as", "$", "rule", ")", "{", "if", "(", "$", "rule", "[", "'type'", "]", "==", "'required'", ")", "{", "$", "draftid", "=", "(", "int", ")", "$", "mform", "->", "getSubmitValue", "(", "$", "elementname", ")", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "context", "=", "context_user", "::", "instance", "(", "$", "USER", "->", "id", ")", ";", "if", "(", "!", "$", "files", "=", "$", "fs", "->", "get_area_files", "(", "$", "context", "->", "id", ",", "'user'", ",", "'draft'", ",", "$", "draftid", ",", "'id DESC'", ",", "false", ")", ")", "{", "$", "errors", "[", "$", "elementname", "]", "=", "$", "rule", "[", "'message'", "]", ";", "}", "}", "}", "}", "}", "// Check all the filemanager elements to make sure they do not have too many", "// files in them.", "foreach", "(", "$", "mform", "->", "_elements", "as", "$", "element", ")", "{", "if", "(", "$", "element", "->", "_type", "==", "'filemanager'", ")", "{", "$", "maxfiles", "=", "$", "element", "->", "getMaxfiles", "(", ")", ";", "if", "(", "$", "maxfiles", ">", "0", ")", "{", "$", "draftid", "=", "(", "int", ")", "$", "element", "->", "getValue", "(", ")", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "context", "=", "context_user", "::", "instance", "(", "$", "USER", "->", "id", ")", ";", "$", "files", "=", "$", "fs", "->", "get_area_files", "(", "$", "context", "->", "id", ",", "'user'", ",", "'draft'", ",", "$", "draftid", ",", "''", ",", "false", ")", ";", "if", "(", "count", "(", "$", "files", ")", ">", "$", "maxfiles", ")", "{", "$", "errors", "[", "$", "element", "->", "getName", "(", ")", "]", "=", "get_string", "(", "'err_maxfiles'", ",", "'form'", ",", "$", "maxfiles", ")", ";", "}", "}", "}", "}", "if", "(", "empty", "(", "$", "errors", ")", ")", "{", "return", "true", ";", "}", "else", "{", "return", "$", "errors", ";", "}", "}" ]
Internal method. Validates filepicker and filemanager files if they are set as required fields. Also, sets the error message if encountered one. @return bool|array with errors
[ "Internal", "method", ".", "Validates", "filepicker", "and", "filemanager", "files", "if", "they", "are", "set", "as", "required", "fields", ".", "Also", "sets", "the", "error", "message", "if", "encountered", "one", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/formslib.php#L417-L462
212,273
moodle/moodle
lib/formslib.php
moodleform.no_submit_button_pressed
function no_submit_button_pressed(){ static $nosubmit = null; // one check is enough if (!is_null($nosubmit)){ return $nosubmit; } $mform =& $this->_form; $nosubmit = false; if (!$this->is_submitted()){ return false; } foreach ($mform->_noSubmitButtons as $nosubmitbutton){ if (optional_param($nosubmitbutton, 0, PARAM_RAW)){ $nosubmit = true; break; } } return $nosubmit; }
php
function no_submit_button_pressed(){ static $nosubmit = null; // one check is enough if (!is_null($nosubmit)){ return $nosubmit; } $mform =& $this->_form; $nosubmit = false; if (!$this->is_submitted()){ return false; } foreach ($mform->_noSubmitButtons as $nosubmitbutton){ if (optional_param($nosubmitbutton, 0, PARAM_RAW)){ $nosubmit = true; break; } } return $nosubmit; }
[ "function", "no_submit_button_pressed", "(", ")", "{", "static", "$", "nosubmit", "=", "null", ";", "// one check is enough", "if", "(", "!", "is_null", "(", "$", "nosubmit", ")", ")", "{", "return", "$", "nosubmit", ";", "}", "$", "mform", "=", "&", "$", "this", "->", "_form", ";", "$", "nosubmit", "=", "false", ";", "if", "(", "!", "$", "this", "->", "is_submitted", "(", ")", ")", "{", "return", "false", ";", "}", "foreach", "(", "$", "mform", "->", "_noSubmitButtons", "as", "$", "nosubmitbutton", ")", "{", "if", "(", "optional_param", "(", "$", "nosubmitbutton", ",", "0", ",", "PARAM_RAW", ")", ")", "{", "$", "nosubmit", "=", "true", ";", "break", ";", "}", "}", "return", "$", "nosubmit", ";", "}" ]
Checks if button pressed is not for submitting the form @staticvar bool $nosubmit keeps track of no submit button @return bool
[ "Checks", "if", "button", "pressed", "is", "not", "for", "submitting", "the", "form" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/formslib.php#L495-L512
212,274
moodle/moodle
lib/formslib.php
moodleform.is_cancelled
function is_cancelled(){ $mform =& $this->_form; if ($mform->isSubmitted()){ foreach ($mform->_cancelButtons as $cancelbutton){ if (optional_param($cancelbutton, 0, PARAM_RAW)){ return true; } } } return false; }
php
function is_cancelled(){ $mform =& $this->_form; if ($mform->isSubmitted()){ foreach ($mform->_cancelButtons as $cancelbutton){ if (optional_param($cancelbutton, 0, PARAM_RAW)){ return true; } } } return false; }
[ "function", "is_cancelled", "(", ")", "{", "$", "mform", "=", "&", "$", "this", "->", "_form", ";", "if", "(", "$", "mform", "->", "isSubmitted", "(", ")", ")", "{", "foreach", "(", "$", "mform", "->", "_cancelButtons", "as", "$", "cancelbutton", ")", "{", "if", "(", "optional_param", "(", "$", "cancelbutton", ",", "0", ",", "PARAM_RAW", ")", ")", "{", "return", "true", ";", "}", "}", "}", "return", "false", ";", "}" ]
Return true if a cancel button has been pressed resulting in the form being submitted. @return bool true if a cancel button has been pressed
[ "Return", "true", "if", "a", "cancel", "button", "has", "been", "pressed", "resulting", "in", "the", "form", "being", "submitted", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/formslib.php#L615-L625
212,275
moodle/moodle
lib/formslib.php
moodleform.get_new_filename
function get_new_filename($elname=null) { global $USER; if (!$this->is_submitted() or !$this->is_validated()) { return false; } if (is_null($elname)) { if (empty($_FILES)) { return false; } reset($_FILES); $elname = key($_FILES); } if (empty($elname)) { return false; } $element = $this->_form->getElement($elname); if ($element instanceof MoodleQuickForm_filepicker || $element instanceof MoodleQuickForm_filemanager) { $values = $this->_form->exportValues($elname); if (empty($values[$elname])) { return false; } $draftid = $values[$elname]; $fs = get_file_storage(); $context = context_user::instance($USER->id); if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) { return false; } $file = reset($files); return $file->get_filename(); } if (!isset($_FILES[$elname])) { return false; } return $_FILES[$elname]['name']; }
php
function get_new_filename($elname=null) { global $USER; if (!$this->is_submitted() or !$this->is_validated()) { return false; } if (is_null($elname)) { if (empty($_FILES)) { return false; } reset($_FILES); $elname = key($_FILES); } if (empty($elname)) { return false; } $element = $this->_form->getElement($elname); if ($element instanceof MoodleQuickForm_filepicker || $element instanceof MoodleQuickForm_filemanager) { $values = $this->_form->exportValues($elname); if (empty($values[$elname])) { return false; } $draftid = $values[$elname]; $fs = get_file_storage(); $context = context_user::instance($USER->id); if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) { return false; } $file = reset($files); return $file->get_filename(); } if (!isset($_FILES[$elname])) { return false; } return $_FILES[$elname]['name']; }
[ "function", "get_new_filename", "(", "$", "elname", "=", "null", ")", "{", "global", "$", "USER", ";", "if", "(", "!", "$", "this", "->", "is_submitted", "(", ")", "or", "!", "$", "this", "->", "is_validated", "(", ")", ")", "{", "return", "false", ";", "}", "if", "(", "is_null", "(", "$", "elname", ")", ")", "{", "if", "(", "empty", "(", "$", "_FILES", ")", ")", "{", "return", "false", ";", "}", "reset", "(", "$", "_FILES", ")", ";", "$", "elname", "=", "key", "(", "$", "_FILES", ")", ";", "}", "if", "(", "empty", "(", "$", "elname", ")", ")", "{", "return", "false", ";", "}", "$", "element", "=", "$", "this", "->", "_form", "->", "getElement", "(", "$", "elname", ")", ";", "if", "(", "$", "element", "instanceof", "MoodleQuickForm_filepicker", "||", "$", "element", "instanceof", "MoodleQuickForm_filemanager", ")", "{", "$", "values", "=", "$", "this", "->", "_form", "->", "exportValues", "(", "$", "elname", ")", ";", "if", "(", "empty", "(", "$", "values", "[", "$", "elname", "]", ")", ")", "{", "return", "false", ";", "}", "$", "draftid", "=", "$", "values", "[", "$", "elname", "]", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "context", "=", "context_user", "::", "instance", "(", "$", "USER", "->", "id", ")", ";", "if", "(", "!", "$", "files", "=", "$", "fs", "->", "get_area_files", "(", "$", "context", "->", "id", ",", "'user'", ",", "'draft'", ",", "$", "draftid", ",", "'id DESC'", ",", "false", ")", ")", "{", "return", "false", ";", "}", "$", "file", "=", "reset", "(", "$", "files", ")", ";", "return", "$", "file", "->", "get_filename", "(", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "_FILES", "[", "$", "elname", "]", ")", ")", "{", "return", "false", ";", "}", "return", "$", "_FILES", "[", "$", "elname", "]", "[", "'name'", "]", ";", "}" ]
Returns name of uploaded file. @param string $elname first element if null @return string|bool false in case of failure, string if ok
[ "Returns", "name", "of", "uploaded", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/formslib.php#L696-L737
212,276
moodle/moodle
lib/formslib.php
moodleform.save_file
function save_file($elname, $pathname, $override=false) { global $USER; if (!$this->is_submitted() or !$this->is_validated()) { return false; } if (file_exists($pathname)) { if ($override) { if (!@unlink($pathname)) { return false; } } else { return false; } } $element = $this->_form->getElement($elname); if ($element instanceof MoodleQuickForm_filepicker || $element instanceof MoodleQuickForm_filemanager) { $values = $this->_form->exportValues($elname); if (empty($values[$elname])) { return false; } $draftid = $values[$elname]; $fs = get_file_storage(); $context = context_user::instance($USER->id); if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) { return false; } $file = reset($files); return $file->copy_content_to($pathname); } else if (isset($_FILES[$elname])) { return copy($_FILES[$elname]['tmp_name'], $pathname); } return false; }
php
function save_file($elname, $pathname, $override=false) { global $USER; if (!$this->is_submitted() or !$this->is_validated()) { return false; } if (file_exists($pathname)) { if ($override) { if (!@unlink($pathname)) { return false; } } else { return false; } } $element = $this->_form->getElement($elname); if ($element instanceof MoodleQuickForm_filepicker || $element instanceof MoodleQuickForm_filemanager) { $values = $this->_form->exportValues($elname); if (empty($values[$elname])) { return false; } $draftid = $values[$elname]; $fs = get_file_storage(); $context = context_user::instance($USER->id); if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) { return false; } $file = reset($files); return $file->copy_content_to($pathname); } else if (isset($_FILES[$elname])) { return copy($_FILES[$elname]['tmp_name'], $pathname); } return false; }
[ "function", "save_file", "(", "$", "elname", ",", "$", "pathname", ",", "$", "override", "=", "false", ")", "{", "global", "$", "USER", ";", "if", "(", "!", "$", "this", "->", "is_submitted", "(", ")", "or", "!", "$", "this", "->", "is_validated", "(", ")", ")", "{", "return", "false", ";", "}", "if", "(", "file_exists", "(", "$", "pathname", ")", ")", "{", "if", "(", "$", "override", ")", "{", "if", "(", "!", "@", "unlink", "(", "$", "pathname", ")", ")", "{", "return", "false", ";", "}", "}", "else", "{", "return", "false", ";", "}", "}", "$", "element", "=", "$", "this", "->", "_form", "->", "getElement", "(", "$", "elname", ")", ";", "if", "(", "$", "element", "instanceof", "MoodleQuickForm_filepicker", "||", "$", "element", "instanceof", "MoodleQuickForm_filemanager", ")", "{", "$", "values", "=", "$", "this", "->", "_form", "->", "exportValues", "(", "$", "elname", ")", ";", "if", "(", "empty", "(", "$", "values", "[", "$", "elname", "]", ")", ")", "{", "return", "false", ";", "}", "$", "draftid", "=", "$", "values", "[", "$", "elname", "]", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "context", "=", "context_user", "::", "instance", "(", "$", "USER", "->", "id", ")", ";", "if", "(", "!", "$", "files", "=", "$", "fs", "->", "get_area_files", "(", "$", "context", "->", "id", ",", "'user'", ",", "'draft'", ",", "$", "draftid", ",", "'id DESC'", ",", "false", ")", ")", "{", "return", "false", ";", "}", "$", "file", "=", "reset", "(", "$", "files", ")", ";", "return", "$", "file", "->", "copy_content_to", "(", "$", "pathname", ")", ";", "}", "else", "if", "(", "isset", "(", "$", "_FILES", "[", "$", "elname", "]", ")", ")", "{", "return", "copy", "(", "$", "_FILES", "[", "$", "elname", "]", "[", "'tmp_name'", "]", ",", "$", "pathname", ")", ";", "}", "return", "false", ";", "}" ]
Save file to standard filesystem @param string $elname name of element @param string $pathname full path name of file @param bool $override override file if exists @return bool success
[ "Save", "file", "to", "standard", "filesystem" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/formslib.php#L747-L785
212,277
moodle/moodle
lib/formslib.php
moodleform.save_temp_file
function save_temp_file($elname) { if (!$this->get_new_filename($elname)) { return false; } if (!$dir = make_temp_directory('forms')) { return false; } if (!$tempfile = tempnam($dir, 'tempup_')) { return false; } if (!$this->save_file($elname, $tempfile, true)) { // something went wrong @unlink($tempfile); return false; } return $tempfile; }
php
function save_temp_file($elname) { if (!$this->get_new_filename($elname)) { return false; } if (!$dir = make_temp_directory('forms')) { return false; } if (!$tempfile = tempnam($dir, 'tempup_')) { return false; } if (!$this->save_file($elname, $tempfile, true)) { // something went wrong @unlink($tempfile); return false; } return $tempfile; }
[ "function", "save_temp_file", "(", "$", "elname", ")", "{", "if", "(", "!", "$", "this", "->", "get_new_filename", "(", "$", "elname", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "$", "dir", "=", "make_temp_directory", "(", "'forms'", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "$", "tempfile", "=", "tempnam", "(", "$", "dir", ",", "'tempup_'", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "$", "this", "->", "save_file", "(", "$", "elname", ",", "$", "tempfile", ",", "true", ")", ")", "{", "// something went wrong", "@", "unlink", "(", "$", "tempfile", ")", ";", "return", "false", ";", "}", "return", "$", "tempfile", ";", "}" ]
Returns a temporary file, do not forget to delete after not needed any more. @param string $elname name of the elmenet @return string|bool either string or false
[ "Returns", "a", "temporary", "file", "do", "not", "forget", "to", "delete", "after", "not", "needed", "any", "more", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/formslib.php#L793-L810
212,278
moodle/moodle
lib/formslib.php
moodleform.get_draft_files
protected function get_draft_files($elname) { global $USER; if (!$this->is_submitted()) { return false; } $element = $this->_form->getElement($elname); if ($element instanceof MoodleQuickForm_filepicker || $element instanceof MoodleQuickForm_filemanager) { $values = $this->_form->exportValues($elname); if (empty($values[$elname])) { return false; } $draftid = $values[$elname]; $fs = get_file_storage(); $context = context_user::instance($USER->id); if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) { return null; } return $files; } return null; }
php
protected function get_draft_files($elname) { global $USER; if (!$this->is_submitted()) { return false; } $element = $this->_form->getElement($elname); if ($element instanceof MoodleQuickForm_filepicker || $element instanceof MoodleQuickForm_filemanager) { $values = $this->_form->exportValues($elname); if (empty($values[$elname])) { return false; } $draftid = $values[$elname]; $fs = get_file_storage(); $context = context_user::instance($USER->id); if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) { return null; } return $files; } return null; }
[ "protected", "function", "get_draft_files", "(", "$", "elname", ")", "{", "global", "$", "USER", ";", "if", "(", "!", "$", "this", "->", "is_submitted", "(", ")", ")", "{", "return", "false", ";", "}", "$", "element", "=", "$", "this", "->", "_form", "->", "getElement", "(", "$", "elname", ")", ";", "if", "(", "$", "element", "instanceof", "MoodleQuickForm_filepicker", "||", "$", "element", "instanceof", "MoodleQuickForm_filemanager", ")", "{", "$", "values", "=", "$", "this", "->", "_form", "->", "exportValues", "(", "$", "elname", ")", ";", "if", "(", "empty", "(", "$", "values", "[", "$", "elname", "]", ")", ")", "{", "return", "false", ";", "}", "$", "draftid", "=", "$", "values", "[", "$", "elname", "]", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "context", "=", "context_user", "::", "instance", "(", "$", "USER", "->", "id", ")", ";", "if", "(", "!", "$", "files", "=", "$", "fs", "->", "get_area_files", "(", "$", "context", "->", "id", ",", "'user'", ",", "'draft'", ",", "$", "draftid", ",", "'id DESC'", ",", "false", ")", ")", "{", "return", "null", ";", "}", "return", "$", "files", ";", "}", "return", "null", ";", "}" ]
Get draft files of a form element This is a protected method which will be used only inside moodleforms @param string $elname name of element @return array|bool|null
[ "Get", "draft", "files", "of", "a", "form", "element", "This", "is", "a", "protected", "method", "which", "will", "be", "used", "only", "inside", "moodleforms" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/formslib.php#L819-L842
212,279
moodle/moodle
lib/formslib.php
moodleform.save_stored_file
function save_stored_file($elname, $newcontextid, $newcomponent, $newfilearea, $newitemid, $newfilepath='/', $newfilename=null, $overwrite=false, $newuserid=null) { global $USER; if (!$this->is_submitted() or !$this->is_validated()) { return false; } if (empty($newuserid)) { $newuserid = $USER->id; } $element = $this->_form->getElement($elname); $fs = get_file_storage(); if ($element instanceof MoodleQuickForm_filepicker) { $values = $this->_form->exportValues($elname); if (empty($values[$elname])) { return false; } $draftid = $values[$elname]; $context = context_user::instance($USER->id); if (!$files = $fs->get_area_files($context->id, 'user' ,'draft', $draftid, 'id DESC', false)) { return false; } $file = reset($files); if (is_null($newfilename)) { $newfilename = $file->get_filename(); } if ($overwrite) { if ($oldfile = $fs->get_file($newcontextid, $newcomponent, $newfilearea, $newitemid, $newfilepath, $newfilename)) { if (!$oldfile->delete()) { return false; } } } $file_record = array('contextid'=>$newcontextid, 'component'=>$newcomponent, 'filearea'=>$newfilearea, 'itemid'=>$newitemid, 'filepath'=>$newfilepath, 'filename'=>$newfilename, 'userid'=>$newuserid); return $fs->create_file_from_storedfile($file_record, $file); } else if (isset($_FILES[$elname])) { $filename = is_null($newfilename) ? $_FILES[$elname]['name'] : $newfilename; if ($overwrite) { if ($oldfile = $fs->get_file($newcontextid, $newcomponent, $newfilearea, $newitemid, $newfilepath, $newfilename)) { if (!$oldfile->delete()) { return false; } } } $file_record = array('contextid'=>$newcontextid, 'component'=>$newcomponent, 'filearea'=>$newfilearea, 'itemid'=>$newitemid, 'filepath'=>$newfilepath, 'filename'=>$newfilename, 'userid'=>$newuserid); return $fs->create_file_from_pathname($file_record, $_FILES[$elname]['tmp_name']); } return false; }
php
function save_stored_file($elname, $newcontextid, $newcomponent, $newfilearea, $newitemid, $newfilepath='/', $newfilename=null, $overwrite=false, $newuserid=null) { global $USER; if (!$this->is_submitted() or !$this->is_validated()) { return false; } if (empty($newuserid)) { $newuserid = $USER->id; } $element = $this->_form->getElement($elname); $fs = get_file_storage(); if ($element instanceof MoodleQuickForm_filepicker) { $values = $this->_form->exportValues($elname); if (empty($values[$elname])) { return false; } $draftid = $values[$elname]; $context = context_user::instance($USER->id); if (!$files = $fs->get_area_files($context->id, 'user' ,'draft', $draftid, 'id DESC', false)) { return false; } $file = reset($files); if (is_null($newfilename)) { $newfilename = $file->get_filename(); } if ($overwrite) { if ($oldfile = $fs->get_file($newcontextid, $newcomponent, $newfilearea, $newitemid, $newfilepath, $newfilename)) { if (!$oldfile->delete()) { return false; } } } $file_record = array('contextid'=>$newcontextid, 'component'=>$newcomponent, 'filearea'=>$newfilearea, 'itemid'=>$newitemid, 'filepath'=>$newfilepath, 'filename'=>$newfilename, 'userid'=>$newuserid); return $fs->create_file_from_storedfile($file_record, $file); } else if (isset($_FILES[$elname])) { $filename = is_null($newfilename) ? $_FILES[$elname]['name'] : $newfilename; if ($overwrite) { if ($oldfile = $fs->get_file($newcontextid, $newcomponent, $newfilearea, $newitemid, $newfilepath, $newfilename)) { if (!$oldfile->delete()) { return false; } } } $file_record = array('contextid'=>$newcontextid, 'component'=>$newcomponent, 'filearea'=>$newfilearea, 'itemid'=>$newitemid, 'filepath'=>$newfilepath, 'filename'=>$newfilename, 'userid'=>$newuserid); return $fs->create_file_from_pathname($file_record, $_FILES[$elname]['tmp_name']); } return false; }
[ "function", "save_stored_file", "(", "$", "elname", ",", "$", "newcontextid", ",", "$", "newcomponent", ",", "$", "newfilearea", ",", "$", "newitemid", ",", "$", "newfilepath", "=", "'/'", ",", "$", "newfilename", "=", "null", ",", "$", "overwrite", "=", "false", ",", "$", "newuserid", "=", "null", ")", "{", "global", "$", "USER", ";", "if", "(", "!", "$", "this", "->", "is_submitted", "(", ")", "or", "!", "$", "this", "->", "is_validated", "(", ")", ")", "{", "return", "false", ";", "}", "if", "(", "empty", "(", "$", "newuserid", ")", ")", "{", "$", "newuserid", "=", "$", "USER", "->", "id", ";", "}", "$", "element", "=", "$", "this", "->", "_form", "->", "getElement", "(", "$", "elname", ")", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "if", "(", "$", "element", "instanceof", "MoodleQuickForm_filepicker", ")", "{", "$", "values", "=", "$", "this", "->", "_form", "->", "exportValues", "(", "$", "elname", ")", ";", "if", "(", "empty", "(", "$", "values", "[", "$", "elname", "]", ")", ")", "{", "return", "false", ";", "}", "$", "draftid", "=", "$", "values", "[", "$", "elname", "]", ";", "$", "context", "=", "context_user", "::", "instance", "(", "$", "USER", "->", "id", ")", ";", "if", "(", "!", "$", "files", "=", "$", "fs", "->", "get_area_files", "(", "$", "context", "->", "id", ",", "'user'", ",", "'draft'", ",", "$", "draftid", ",", "'id DESC'", ",", "false", ")", ")", "{", "return", "false", ";", "}", "$", "file", "=", "reset", "(", "$", "files", ")", ";", "if", "(", "is_null", "(", "$", "newfilename", ")", ")", "{", "$", "newfilename", "=", "$", "file", "->", "get_filename", "(", ")", ";", "}", "if", "(", "$", "overwrite", ")", "{", "if", "(", "$", "oldfile", "=", "$", "fs", "->", "get_file", "(", "$", "newcontextid", ",", "$", "newcomponent", ",", "$", "newfilearea", ",", "$", "newitemid", ",", "$", "newfilepath", ",", "$", "newfilename", ")", ")", "{", "if", "(", "!", "$", "oldfile", "->", "delete", "(", ")", ")", "{", "return", "false", ";", "}", "}", "}", "$", "file_record", "=", "array", "(", "'contextid'", "=>", "$", "newcontextid", ",", "'component'", "=>", "$", "newcomponent", ",", "'filearea'", "=>", "$", "newfilearea", ",", "'itemid'", "=>", "$", "newitemid", ",", "'filepath'", "=>", "$", "newfilepath", ",", "'filename'", "=>", "$", "newfilename", ",", "'userid'", "=>", "$", "newuserid", ")", ";", "return", "$", "fs", "->", "create_file_from_storedfile", "(", "$", "file_record", ",", "$", "file", ")", ";", "}", "else", "if", "(", "isset", "(", "$", "_FILES", "[", "$", "elname", "]", ")", ")", "{", "$", "filename", "=", "is_null", "(", "$", "newfilename", ")", "?", "$", "_FILES", "[", "$", "elname", "]", "[", "'name'", "]", ":", "$", "newfilename", ";", "if", "(", "$", "overwrite", ")", "{", "if", "(", "$", "oldfile", "=", "$", "fs", "->", "get_file", "(", "$", "newcontextid", ",", "$", "newcomponent", ",", "$", "newfilearea", ",", "$", "newitemid", ",", "$", "newfilepath", ",", "$", "newfilename", ")", ")", "{", "if", "(", "!", "$", "oldfile", "->", "delete", "(", ")", ")", "{", "return", "false", ";", "}", "}", "}", "$", "file_record", "=", "array", "(", "'contextid'", "=>", "$", "newcontextid", ",", "'component'", "=>", "$", "newcomponent", ",", "'filearea'", "=>", "$", "newfilearea", ",", "'itemid'", "=>", "$", "newitemid", ",", "'filepath'", "=>", "$", "newfilepath", ",", "'filename'", "=>", "$", "newfilename", ",", "'userid'", "=>", "$", "newuserid", ")", ";", "return", "$", "fs", "->", "create_file_from_pathname", "(", "$", "file_record", ",", "$", "_FILES", "[", "$", "elname", "]", "[", "'tmp_name'", "]", ")", ";", "}", "return", "false", ";", "}" ]
Save file to local filesystem pool @param string $elname name of element @param int $newcontextid id of context @param string $newcomponent name of the component @param string $newfilearea name of file area @param int $newitemid item id @param string $newfilepath path of file where it get stored @param string $newfilename use specified filename, if not specified name of uploaded file used @param bool $overwrite overwrite file if exists @param int $newuserid new userid if required @return mixed stored_file object or false if error; may throw exception if duplicate found
[ "Save", "file", "to", "local", "filesystem", "pool" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/formslib.php#L858-L917
212,280
moodle/moodle
lib/formslib.php
moodleform.get_file_content
function get_file_content($elname) { global $USER; if (!$this->is_submitted() or !$this->is_validated()) { return false; } $element = $this->_form->getElement($elname); if ($element instanceof MoodleQuickForm_filepicker || $element instanceof MoodleQuickForm_filemanager) { $values = $this->_form->exportValues($elname); if (empty($values[$elname])) { return false; } $draftid = $values[$elname]; $fs = get_file_storage(); $context = context_user::instance($USER->id); if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) { return false; } $file = reset($files); return $file->get_content(); } else if (isset($_FILES[$elname])) { return file_get_contents($_FILES[$elname]['tmp_name']); } return false; }
php
function get_file_content($elname) { global $USER; if (!$this->is_submitted() or !$this->is_validated()) { return false; } $element = $this->_form->getElement($elname); if ($element instanceof MoodleQuickForm_filepicker || $element instanceof MoodleQuickForm_filemanager) { $values = $this->_form->exportValues($elname); if (empty($values[$elname])) { return false; } $draftid = $values[$elname]; $fs = get_file_storage(); $context = context_user::instance($USER->id); if (!$files = $fs->get_area_files($context->id, 'user', 'draft', $draftid, 'id DESC', false)) { return false; } $file = reset($files); return $file->get_content(); } else if (isset($_FILES[$elname])) { return file_get_contents($_FILES[$elname]['tmp_name']); } return false; }
[ "function", "get_file_content", "(", "$", "elname", ")", "{", "global", "$", "USER", ";", "if", "(", "!", "$", "this", "->", "is_submitted", "(", ")", "or", "!", "$", "this", "->", "is_validated", "(", ")", ")", "{", "return", "false", ";", "}", "$", "element", "=", "$", "this", "->", "_form", "->", "getElement", "(", "$", "elname", ")", ";", "if", "(", "$", "element", "instanceof", "MoodleQuickForm_filepicker", "||", "$", "element", "instanceof", "MoodleQuickForm_filemanager", ")", "{", "$", "values", "=", "$", "this", "->", "_form", "->", "exportValues", "(", "$", "elname", ")", ";", "if", "(", "empty", "(", "$", "values", "[", "$", "elname", "]", ")", ")", "{", "return", "false", ";", "}", "$", "draftid", "=", "$", "values", "[", "$", "elname", "]", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "context", "=", "context_user", "::", "instance", "(", "$", "USER", "->", "id", ")", ";", "if", "(", "!", "$", "files", "=", "$", "fs", "->", "get_area_files", "(", "$", "context", "->", "id", ",", "'user'", ",", "'draft'", ",", "$", "draftid", ",", "'id DESC'", ",", "false", ")", ")", "{", "return", "false", ";", "}", "$", "file", "=", "reset", "(", "$", "files", ")", ";", "return", "$", "file", "->", "get_content", "(", ")", ";", "}", "else", "if", "(", "isset", "(", "$", "_FILES", "[", "$", "elname", "]", ")", ")", "{", "return", "file_get_contents", "(", "$", "_FILES", "[", "$", "elname", "]", "[", "'tmp_name'", "]", ")", ";", "}", "return", "false", ";", "}" ]
Get content of uploaded file. @param string $elname name of file upload element @return string|bool false in case of failure, string if ok
[ "Get", "content", "of", "uploaded", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/formslib.php#L925-L954
212,281
moodle/moodle
lib/formslib.php
moodleform.mock_submit
public static function mock_submit($simulatedsubmitteddata, $simulatedsubmittedfiles = array(), $method = 'post', $formidentifier = null) { $_FILES = $simulatedsubmittedfiles; if ($formidentifier === null) { $formidentifier = get_called_class(); $formidentifier = str_replace('\\', '_', $formidentifier); // See MDL-56233 for more information. } $simulatedsubmitteddata['_qf__'.$formidentifier] = 1; $simulatedsubmitteddata['sesskey'] = sesskey(); if (strtolower($method) === 'get') { $_GET = $simulatedsubmitteddata; } else { $_POST = $simulatedsubmitteddata; } }
php
public static function mock_submit($simulatedsubmitteddata, $simulatedsubmittedfiles = array(), $method = 'post', $formidentifier = null) { $_FILES = $simulatedsubmittedfiles; if ($formidentifier === null) { $formidentifier = get_called_class(); $formidentifier = str_replace('\\', '_', $formidentifier); // See MDL-56233 for more information. } $simulatedsubmitteddata['_qf__'.$formidentifier] = 1; $simulatedsubmitteddata['sesskey'] = sesskey(); if (strtolower($method) === 'get') { $_GET = $simulatedsubmitteddata; } else { $_POST = $simulatedsubmitteddata; } }
[ "public", "static", "function", "mock_submit", "(", "$", "simulatedsubmitteddata", ",", "$", "simulatedsubmittedfiles", "=", "array", "(", ")", ",", "$", "method", "=", "'post'", ",", "$", "formidentifier", "=", "null", ")", "{", "$", "_FILES", "=", "$", "simulatedsubmittedfiles", ";", "if", "(", "$", "formidentifier", "===", "null", ")", "{", "$", "formidentifier", "=", "get_called_class", "(", ")", ";", "$", "formidentifier", "=", "str_replace", "(", "'\\\\'", ",", "'_'", ",", "$", "formidentifier", ")", ";", "// See MDL-56233 for more information.", "}", "$", "simulatedsubmitteddata", "[", "'_qf__'", ".", "$", "formidentifier", "]", "=", "1", ";", "$", "simulatedsubmitteddata", "[", "'sesskey'", "]", "=", "sesskey", "(", ")", ";", "if", "(", "strtolower", "(", "$", "method", ")", "===", "'get'", ")", "{", "$", "_GET", "=", "$", "simulatedsubmitteddata", ";", "}", "else", "{", "$", "_POST", "=", "$", "simulatedsubmitteddata", ";", "}", "}" ]
Used by tests to simulate submitted form data submission from the user. For form fields where no data is submitted the default for that field as set by set_data or setDefault will be passed to get_data. This method sets $_POST or $_GET and $_FILES with the data supplied. Our unit test code empties all these global arrays after each test. @param array $simulatedsubmitteddata An associative array of form values (same format as $_POST). @param array $simulatedsubmittedfiles An associative array of files uploaded (same format as $_FILES). Can be omitted. @param string $method 'post' or 'get', defaults to 'post'. @param null $formidentifier the default is to use the class name for this class but you may need to provide a different value here for some forms that are used more than once on the same page.
[ "Used", "by", "tests", "to", "simulate", "submitted", "form", "data", "submission", "from", "the", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/formslib.php#L1390-L1404
212,282
moodle/moodle
lib/formslib.php
moodleform.mock_generate_submit_keys
public static function mock_generate_submit_keys($data = []) { if (!defined('PHPUNIT_TEST') || !PHPUNIT_TEST) { throw new \moodle_exception("This function can only be used for unit testing."); } $formidentifier = get_called_class(); $formidentifier = str_replace('\\', '_', $formidentifier); // See MDL-56233 for more information. $data['sesskey'] = sesskey(); $data['_qf__' . $formidentifier] = 1; return $data; }
php
public static function mock_generate_submit_keys($data = []) { if (!defined('PHPUNIT_TEST') || !PHPUNIT_TEST) { throw new \moodle_exception("This function can only be used for unit testing."); } $formidentifier = get_called_class(); $formidentifier = str_replace('\\', '_', $formidentifier); // See MDL-56233 for more information. $data['sesskey'] = sesskey(); $data['_qf__' . $formidentifier] = 1; return $data; }
[ "public", "static", "function", "mock_generate_submit_keys", "(", "$", "data", "=", "[", "]", ")", "{", "if", "(", "!", "defined", "(", "'PHPUNIT_TEST'", ")", "||", "!", "PHPUNIT_TEST", ")", "{", "throw", "new", "\\", "moodle_exception", "(", "\"This function can only be used for unit testing.\"", ")", ";", "}", "$", "formidentifier", "=", "get_called_class", "(", ")", ";", "$", "formidentifier", "=", "str_replace", "(", "'\\\\'", ",", "'_'", ",", "$", "formidentifier", ")", ";", "// See MDL-56233 for more information.", "$", "data", "[", "'sesskey'", "]", "=", "sesskey", "(", ")", ";", "$", "data", "[", "'_qf__'", ".", "$", "formidentifier", "]", "=", "1", ";", "return", "$", "data", ";", "}" ]
Used by tests to generate valid submit keys for moodle forms that are submitted with ajax data. @throws \moodle_exception If called outside unit test environment @param array $data Existing form data you wish to add the keys to. @return array
[ "Used", "by", "tests", "to", "generate", "valid", "submit", "keys", "for", "moodle", "forms", "that", "are", "submitted", "with", "ajax", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/formslib.php#L1414-L1425
212,283
moodle/moodle
lib/formslib.php
MoodleQuickForm.setExpanded
function setExpanded($headername, $expanded = true, $ignoreuserstate = false) { if (empty($headername)) { return; } $element = $this->getElement($headername); if ($element->getType() != 'header') { debugging('Cannot use setExpanded on non-header elements', DEBUG_DEVELOPER); return; } if (!$headerid = $element->getAttribute('id')) { $element->_generateId(); $headerid = $element->getAttribute('id'); } if ($this->getElementType('mform_isexpanded_' . $headerid) === false) { // See if the form has been submitted already. $formexpanded = optional_param('mform_isexpanded_' . $headerid, -1, PARAM_INT); if (!$ignoreuserstate && $formexpanded != -1) { // Override expanded state with the form variable. $expanded = $formexpanded; } // Create the form element for storing expanded state. $this->addElement('hidden', 'mform_isexpanded_' . $headerid); $this->setType('mform_isexpanded_' . $headerid, PARAM_INT); $this->setConstant('mform_isexpanded_' . $headerid, (int) $expanded); } $this->_collapsibleElements[$headername] = !$expanded; }
php
function setExpanded($headername, $expanded = true, $ignoreuserstate = false) { if (empty($headername)) { return; } $element = $this->getElement($headername); if ($element->getType() != 'header') { debugging('Cannot use setExpanded on non-header elements', DEBUG_DEVELOPER); return; } if (!$headerid = $element->getAttribute('id')) { $element->_generateId(); $headerid = $element->getAttribute('id'); } if ($this->getElementType('mform_isexpanded_' . $headerid) === false) { // See if the form has been submitted already. $formexpanded = optional_param('mform_isexpanded_' . $headerid, -1, PARAM_INT); if (!$ignoreuserstate && $formexpanded != -1) { // Override expanded state with the form variable. $expanded = $formexpanded; } // Create the form element for storing expanded state. $this->addElement('hidden', 'mform_isexpanded_' . $headerid); $this->setType('mform_isexpanded_' . $headerid, PARAM_INT); $this->setConstant('mform_isexpanded_' . $headerid, (int) $expanded); } $this->_collapsibleElements[$headername] = !$expanded; }
[ "function", "setExpanded", "(", "$", "headername", ",", "$", "expanded", "=", "true", ",", "$", "ignoreuserstate", "=", "false", ")", "{", "if", "(", "empty", "(", "$", "headername", ")", ")", "{", "return", ";", "}", "$", "element", "=", "$", "this", "->", "getElement", "(", "$", "headername", ")", ";", "if", "(", "$", "element", "->", "getType", "(", ")", "!=", "'header'", ")", "{", "debugging", "(", "'Cannot use setExpanded on non-header elements'", ",", "DEBUG_DEVELOPER", ")", ";", "return", ";", "}", "if", "(", "!", "$", "headerid", "=", "$", "element", "->", "getAttribute", "(", "'id'", ")", ")", "{", "$", "element", "->", "_generateId", "(", ")", ";", "$", "headerid", "=", "$", "element", "->", "getAttribute", "(", "'id'", ")", ";", "}", "if", "(", "$", "this", "->", "getElementType", "(", "'mform_isexpanded_'", ".", "$", "headerid", ")", "===", "false", ")", "{", "// See if the form has been submitted already.", "$", "formexpanded", "=", "optional_param", "(", "'mform_isexpanded_'", ".", "$", "headerid", ",", "-", "1", ",", "PARAM_INT", ")", ";", "if", "(", "!", "$", "ignoreuserstate", "&&", "$", "formexpanded", "!=", "-", "1", ")", "{", "// Override expanded state with the form variable.", "$", "expanded", "=", "$", "formexpanded", ";", "}", "// Create the form element for storing expanded state.", "$", "this", "->", "addElement", "(", "'hidden'", ",", "'mform_isexpanded_'", ".", "$", "headerid", ")", ";", "$", "this", "->", "setType", "(", "'mform_isexpanded_'", ".", "$", "headerid", ",", "PARAM_INT", ")", ";", "$", "this", "->", "setConstant", "(", "'mform_isexpanded_'", ".", "$", "headerid", ",", "(", "int", ")", "$", "expanded", ")", ";", "}", "$", "this", "->", "_collapsibleElements", "[", "$", "headername", "]", "=", "!", "$", "expanded", ";", "}" ]
Use this method to indicate that the fieldset should be shown as expanded. The method is applicable to header elements only. @param string $headername header element name @param boolean $expanded default true sets the element to expanded. False makes the element collapsed. @param boolean $ignoreuserstate override the state regardless of the state it was on when the form was submitted. @return void
[ "Use", "this", "method", "to", "indicate", "that", "the", "fieldset", "should", "be", "shown", "as", "expanded", ".", "The", "method", "is", "applicable", "to", "header", "elements", "only", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/formslib.php#L1605-L1631
212,284
moodle/moodle
lib/formslib.php
MoodleQuickForm.setType
function setType($elementname, $paramtype) { $this->_types[$elementname] = $paramtype; // This will not always get it right, but it should be accurate in most cases. // When inaccurate use setForceLtr(). if (!is_rtl_compatible($paramtype) && $this->elementExists($elementname) && ($element =& $this->getElement($elementname)) && method_exists($element, 'set_force_ltr')) { $element->set_force_ltr(true); } }
php
function setType($elementname, $paramtype) { $this->_types[$elementname] = $paramtype; // This will not always get it right, but it should be accurate in most cases. // When inaccurate use setForceLtr(). if (!is_rtl_compatible($paramtype) && $this->elementExists($elementname) && ($element =& $this->getElement($elementname)) && method_exists($element, 'set_force_ltr')) { $element->set_force_ltr(true); } }
[ "function", "setType", "(", "$", "elementname", ",", "$", "paramtype", ")", "{", "$", "this", "->", "_types", "[", "$", "elementname", "]", "=", "$", "paramtype", ";", "// This will not always get it right, but it should be accurate in most cases.", "// When inaccurate use setForceLtr().", "if", "(", "!", "is_rtl_compatible", "(", "$", "paramtype", ")", "&&", "$", "this", "->", "elementExists", "(", "$", "elementname", ")", "&&", "(", "$", "element", "=", "&", "$", "this", "->", "getElement", "(", "$", "elementname", ")", ")", "&&", "method_exists", "(", "$", "element", ",", "'set_force_ltr'", ")", ")", "{", "$", "element", "->", "set_force_ltr", "(", "true", ")", ";", "}", "}" ]
Should be used for all elements of a form except for select, radio and checkboxes which clean their own data. @param string $elementname @param int $paramtype defines type of data contained in element. Use the constants PARAM_*. {@link lib/moodlelib.php} for defined parameter types
[ "Should", "be", "used", "for", "all", "elements", "of", "a", "form", "except", "for", "select", "radio", "and", "checkboxes", "which", "clean", "their", "own", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/formslib.php#L1851-L1863
212,285
moodle/moodle
lib/formslib.php
MoodleQuickForm.setTypes
function setTypes($paramtypes) { foreach ($paramtypes as $elementname => $paramtype) { $this->setType($elementname, $paramtype); } }
php
function setTypes($paramtypes) { foreach ($paramtypes as $elementname => $paramtype) { $this->setType($elementname, $paramtype); } }
[ "function", "setTypes", "(", "$", "paramtypes", ")", "{", "foreach", "(", "$", "paramtypes", "as", "$", "elementname", "=>", "$", "paramtype", ")", "{", "$", "this", "->", "setType", "(", "$", "elementname", ",", "$", "paramtype", ")", ";", "}", "}" ]
This can be used to set several types at once. @param array $paramtypes types of parameters. @see MoodleQuickForm::setType
[ "This", "can", "be", "used", "to", "set", "several", "types", "at", "once", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/formslib.php#L1871-L1875
212,286
moodle/moodle
lib/formslib.php
MoodleQuickForm.updateSubmission
function updateSubmission($submission, $files) { $this->_flagSubmitted = false; if (empty($submission)) { $this->_submitValues = array(); } else { foreach ($submission as $key => $s) { $type = $this->getCleanType($key, $s); $submission[$key] = $this->getCleanedValue($s, $type); } $this->_submitValues = $submission; $this->_flagSubmitted = true; } if (empty($files)) { $this->_submitFiles = array(); } else { $this->_submitFiles = $files; $this->_flagSubmitted = true; } // need to tell all elements that they need to update their value attribute. foreach (array_keys($this->_elements) as $key) { $this->_elements[$key]->onQuickFormEvent('updateValue', null, $this); } }
php
function updateSubmission($submission, $files) { $this->_flagSubmitted = false; if (empty($submission)) { $this->_submitValues = array(); } else { foreach ($submission as $key => $s) { $type = $this->getCleanType($key, $s); $submission[$key] = $this->getCleanedValue($s, $type); } $this->_submitValues = $submission; $this->_flagSubmitted = true; } if (empty($files)) { $this->_submitFiles = array(); } else { $this->_submitFiles = $files; $this->_flagSubmitted = true; } // need to tell all elements that they need to update their value attribute. foreach (array_keys($this->_elements) as $key) { $this->_elements[$key]->onQuickFormEvent('updateValue', null, $this); } }
[ "function", "updateSubmission", "(", "$", "submission", ",", "$", "files", ")", "{", "$", "this", "->", "_flagSubmitted", "=", "false", ";", "if", "(", "empty", "(", "$", "submission", ")", ")", "{", "$", "this", "->", "_submitValues", "=", "array", "(", ")", ";", "}", "else", "{", "foreach", "(", "$", "submission", "as", "$", "key", "=>", "$", "s", ")", "{", "$", "type", "=", "$", "this", "->", "getCleanType", "(", "$", "key", ",", "$", "s", ")", ";", "$", "submission", "[", "$", "key", "]", "=", "$", "this", "->", "getCleanedValue", "(", "$", "s", ",", "$", "type", ")", ";", "}", "$", "this", "->", "_submitValues", "=", "$", "submission", ";", "$", "this", "->", "_flagSubmitted", "=", "true", ";", "}", "if", "(", "empty", "(", "$", "files", ")", ")", "{", "$", "this", "->", "_submitFiles", "=", "array", "(", ")", ";", "}", "else", "{", "$", "this", "->", "_submitFiles", "=", "$", "files", ";", "$", "this", "->", "_flagSubmitted", "=", "true", ";", "}", "// need to tell all elements that they need to update their value attribute.", "foreach", "(", "array_keys", "(", "$", "this", "->", "_elements", ")", "as", "$", "key", ")", "{", "$", "this", "->", "_elements", "[", "$", "key", "]", "->", "onQuickFormEvent", "(", "'updateValue'", ",", "null", ",", "$", "this", ")", ";", "}", "}" ]
Updates submitted values @param array $submission submitted values @param array $files list of files
[ "Updates", "submitted", "values" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/formslib.php#L1958-L1983
212,287
moodle/moodle
lib/formslib.php
MoodleQuickForm.addHelpButton
function addHelpButton($elementname, $identifier, $component = 'moodle', $linktext = '', $suppresscheck = false) { global $OUTPUT; if (array_key_exists($elementname, $this->_elementIndex)) { $element = $this->_elements[$this->_elementIndex[$elementname]]; $element->_helpbutton = $OUTPUT->help_icon($identifier, $component, $linktext); } else if (!$suppresscheck) { debugging(get_string('nonexistentformelements', 'form', $elementname)); } }
php
function addHelpButton($elementname, $identifier, $component = 'moodle', $linktext = '', $suppresscheck = false) { global $OUTPUT; if (array_key_exists($elementname, $this->_elementIndex)) { $element = $this->_elements[$this->_elementIndex[$elementname]]; $element->_helpbutton = $OUTPUT->help_icon($identifier, $component, $linktext); } else if (!$suppresscheck) { debugging(get_string('nonexistentformelements', 'form', $elementname)); } }
[ "function", "addHelpButton", "(", "$", "elementname", ",", "$", "identifier", ",", "$", "component", "=", "'moodle'", ",", "$", "linktext", "=", "''", ",", "$", "suppresscheck", "=", "false", ")", "{", "global", "$", "OUTPUT", ";", "if", "(", "array_key_exists", "(", "$", "elementname", ",", "$", "this", "->", "_elementIndex", ")", ")", "{", "$", "element", "=", "$", "this", "->", "_elements", "[", "$", "this", "->", "_elementIndex", "[", "$", "elementname", "]", "]", ";", "$", "element", "->", "_helpbutton", "=", "$", "OUTPUT", "->", "help_icon", "(", "$", "identifier", ",", "$", "component", ",", "$", "linktext", ")", ";", "}", "else", "if", "(", "!", "$", "suppresscheck", ")", "{", "debugging", "(", "get_string", "(", "'nonexistentformelements'", ",", "'form'", ",", "$", "elementname", ")", ")", ";", "}", "}" ]
Add a help button to element, only one button per element is allowed. This is new, simplified and preferable method of setting a help icon on form elements. It uses the new $OUTPUT->help_icon(). Typically, you will provide the same identifier and the component as you have used for the label of the element. The string identifier with the _help suffix added is then used as the help string. There has to be two strings defined: 1/ get_string($identifier, $component) - the title of the help page 2/ get_string($identifier.'_help', $component) - the actual help page text @since Moodle 2.0 @param string $elementname name of the element to add the item to @param string $identifier help string identifier without _help suffix @param string $component component name to look the help string in @param string $linktext optional text to display next to the icon @param bool $suppresscheck set to true if the element may not exist
[ "Add", "a", "help", "button", "to", "element", "only", "one", "button", "per", "element", "is", "allowed", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/formslib.php#L2037-L2045
212,288
moodle/moodle
lib/formslib.php
MoodleQuickForm.exportValues
function exportValues($elementList = null){ $unfiltered = array(); if (null === $elementList) { // iterate over all elements, calling their exportValue() methods foreach (array_keys($this->_elements) as $key) { if ($this->_elements[$key]->isFrozen() && !$this->_elements[$key]->_persistantFreeze) { $varname = $this->_elements[$key]->_attributes['name']; $value = ''; // If we have a default value then export it. if (isset($this->_defaultValues[$varname])) { $value = $this->prepare_fixed_value($varname, $this->_defaultValues[$varname]); } } else { $value = $this->_elements[$key]->exportValue($this->_submitValues, true); } if (is_array($value)) { // This shit throws a bogus warning in PHP 4.3.x $unfiltered = HTML_QuickForm::arrayMerge($unfiltered, $value); } } } else { if (!is_array($elementList)) { $elementList = array_map('trim', explode(',', $elementList)); } foreach ($elementList as $elementName) { $value = $this->exportValue($elementName); if (@PEAR::isError($value)) { return $value; } //oh, stock QuickFOrm was returning array of arrays! $unfiltered = HTML_QuickForm::arrayMerge($unfiltered, $value); } } if (is_array($this->_constantValues)) { $unfiltered = HTML_QuickForm::arrayMerge($unfiltered, $this->_constantValues); } return $unfiltered; }
php
function exportValues($elementList = null){ $unfiltered = array(); if (null === $elementList) { // iterate over all elements, calling their exportValue() methods foreach (array_keys($this->_elements) as $key) { if ($this->_elements[$key]->isFrozen() && !$this->_elements[$key]->_persistantFreeze) { $varname = $this->_elements[$key]->_attributes['name']; $value = ''; // If we have a default value then export it. if (isset($this->_defaultValues[$varname])) { $value = $this->prepare_fixed_value($varname, $this->_defaultValues[$varname]); } } else { $value = $this->_elements[$key]->exportValue($this->_submitValues, true); } if (is_array($value)) { // This shit throws a bogus warning in PHP 4.3.x $unfiltered = HTML_QuickForm::arrayMerge($unfiltered, $value); } } } else { if (!is_array($elementList)) { $elementList = array_map('trim', explode(',', $elementList)); } foreach ($elementList as $elementName) { $value = $this->exportValue($elementName); if (@PEAR::isError($value)) { return $value; } //oh, stock QuickFOrm was returning array of arrays! $unfiltered = HTML_QuickForm::arrayMerge($unfiltered, $value); } } if (is_array($this->_constantValues)) { $unfiltered = HTML_QuickForm::arrayMerge($unfiltered, $this->_constantValues); } return $unfiltered; }
[ "function", "exportValues", "(", "$", "elementList", "=", "null", ")", "{", "$", "unfiltered", "=", "array", "(", ")", ";", "if", "(", "null", "===", "$", "elementList", ")", "{", "// iterate over all elements, calling their exportValue() methods", "foreach", "(", "array_keys", "(", "$", "this", "->", "_elements", ")", "as", "$", "key", ")", "{", "if", "(", "$", "this", "->", "_elements", "[", "$", "key", "]", "->", "isFrozen", "(", ")", "&&", "!", "$", "this", "->", "_elements", "[", "$", "key", "]", "->", "_persistantFreeze", ")", "{", "$", "varname", "=", "$", "this", "->", "_elements", "[", "$", "key", "]", "->", "_attributes", "[", "'name'", "]", ";", "$", "value", "=", "''", ";", "// If we have a default value then export it.", "if", "(", "isset", "(", "$", "this", "->", "_defaultValues", "[", "$", "varname", "]", ")", ")", "{", "$", "value", "=", "$", "this", "->", "prepare_fixed_value", "(", "$", "varname", ",", "$", "this", "->", "_defaultValues", "[", "$", "varname", "]", ")", ";", "}", "}", "else", "{", "$", "value", "=", "$", "this", "->", "_elements", "[", "$", "key", "]", "->", "exportValue", "(", "$", "this", "->", "_submitValues", ",", "true", ")", ";", "}", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "// This shit throws a bogus warning in PHP 4.3.x", "$", "unfiltered", "=", "HTML_QuickForm", "::", "arrayMerge", "(", "$", "unfiltered", ",", "$", "value", ")", ";", "}", "}", "}", "else", "{", "if", "(", "!", "is_array", "(", "$", "elementList", ")", ")", "{", "$", "elementList", "=", "array_map", "(", "'trim'", ",", "explode", "(", "','", ",", "$", "elementList", ")", ")", ";", "}", "foreach", "(", "$", "elementList", "as", "$", "elementName", ")", "{", "$", "value", "=", "$", "this", "->", "exportValue", "(", "$", "elementName", ")", ";", "if", "(", "@", "PEAR", "::", "isError", "(", "$", "value", ")", ")", "{", "return", "$", "value", ";", "}", "//oh, stock QuickFOrm was returning array of arrays!", "$", "unfiltered", "=", "HTML_QuickForm", "::", "arrayMerge", "(", "$", "unfiltered", ",", "$", "value", ")", ";", "}", "}", "if", "(", "is_array", "(", "$", "this", "->", "_constantValues", ")", ")", "{", "$", "unfiltered", "=", "HTML_QuickForm", "::", "arrayMerge", "(", "$", "unfiltered", ",", "$", "this", "->", "_constantValues", ")", ";", "}", "return", "$", "unfiltered", ";", "}" ]
export submitted values @param string $elementList list of elements in form @return array
[ "export", "submitted", "values" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/formslib.php#L2066-L2105
212,289
moodle/moodle
lib/formslib.php
MoodleQuickForm._setDefaultRuleMessages
function _setDefaultRuleMessages(){ foreach ($this->_rules as $field => $rulesarr){ foreach ($rulesarr as $key => $rule){ if ($rule['message']===null){ $a=new stdClass(); $a->format=$rule['format']; $str=get_string('err_'.$rule['type'], 'form', $a); if (strpos($str, '[[')!==0){ $this->_rules[$field][$key]['message']=$str; } } } } }
php
function _setDefaultRuleMessages(){ foreach ($this->_rules as $field => $rulesarr){ foreach ($rulesarr as $key => $rule){ if ($rule['message']===null){ $a=new stdClass(); $a->format=$rule['format']; $str=get_string('err_'.$rule['type'], 'form', $a); if (strpos($str, '[[')!==0){ $this->_rules[$field][$key]['message']=$str; } } } } }
[ "function", "_setDefaultRuleMessages", "(", ")", "{", "foreach", "(", "$", "this", "->", "_rules", "as", "$", "field", "=>", "$", "rulesarr", ")", "{", "foreach", "(", "$", "rulesarr", "as", "$", "key", "=>", "$", "rule", ")", "{", "if", "(", "$", "rule", "[", "'message'", "]", "===", "null", ")", "{", "$", "a", "=", "new", "stdClass", "(", ")", ";", "$", "a", "->", "format", "=", "$", "rule", "[", "'format'", "]", ";", "$", "str", "=", "get_string", "(", "'err_'", ".", "$", "rule", "[", "'type'", "]", ",", "'form'", ",", "$", "a", ")", ";", "if", "(", "strpos", "(", "$", "str", ",", "'[['", ")", "!==", "0", ")", "{", "$", "this", "->", "_rules", "[", "$", "field", "]", "[", "$", "key", "]", "[", "'message'", "]", "=", "$", "str", ";", "}", "}", "}", "}", "}" ]
Sets default error message
[ "Sets", "default", "error", "message" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/formslib.php#L2474-L2487
212,290
moodle/moodle
lib/formslib.php
MoodleQuickForm.getLockOptionObject
function getLockOptionObject(){ $result = array(); foreach ($this->_dependencies as $dependentOn => $conditions){ $result[$dependentOn] = array(); foreach ($conditions as $condition=>$values) { $result[$dependentOn][$condition] = array(); foreach ($values as $value=>$dependents) { $result[$dependentOn][$condition][$value][self::DEP_DISABLE] = array(); foreach ($dependents as $dependent) { $elements = $this->_getElNamesRecursive($dependent); if (empty($elements)) { // probably element inside of some group $elements = array($dependent); } foreach($elements as $element) { if ($element == $dependentOn) { continue; } $result[$dependentOn][$condition][$value][self::DEP_DISABLE][] = $element; } } } } } foreach ($this->_hideifs as $dependenton => $conditions) { if (!isset($result[$dependenton])) { $result[$dependenton] = array(); } foreach ($conditions as $condition => $values) { if (!isset($result[$dependenton][$condition])) { $result[$dependenton][$condition] = array(); } foreach ($values as $value => $dependents) { $result[$dependenton][$condition][$value][self::DEP_HIDE] = array(); foreach ($dependents as $dependent) { $elements = $this->_getElNamesRecursive($dependent); if (!in_array($dependent, $elements)) { // Always want to hide the main element, even if it contains sub-elements as well. $elements[] = $dependent; } foreach ($elements as $element) { if ($element == $dependenton) { continue; } $result[$dependenton][$condition][$value][self::DEP_HIDE][] = $element; } } } } } return array($this->getAttribute('id'), $result); }
php
function getLockOptionObject(){ $result = array(); foreach ($this->_dependencies as $dependentOn => $conditions){ $result[$dependentOn] = array(); foreach ($conditions as $condition=>$values) { $result[$dependentOn][$condition] = array(); foreach ($values as $value=>$dependents) { $result[$dependentOn][$condition][$value][self::DEP_DISABLE] = array(); foreach ($dependents as $dependent) { $elements = $this->_getElNamesRecursive($dependent); if (empty($elements)) { // probably element inside of some group $elements = array($dependent); } foreach($elements as $element) { if ($element == $dependentOn) { continue; } $result[$dependentOn][$condition][$value][self::DEP_DISABLE][] = $element; } } } } } foreach ($this->_hideifs as $dependenton => $conditions) { if (!isset($result[$dependenton])) { $result[$dependenton] = array(); } foreach ($conditions as $condition => $values) { if (!isset($result[$dependenton][$condition])) { $result[$dependenton][$condition] = array(); } foreach ($values as $value => $dependents) { $result[$dependenton][$condition][$value][self::DEP_HIDE] = array(); foreach ($dependents as $dependent) { $elements = $this->_getElNamesRecursive($dependent); if (!in_array($dependent, $elements)) { // Always want to hide the main element, even if it contains sub-elements as well. $elements[] = $dependent; } foreach ($elements as $element) { if ($element == $dependenton) { continue; } $result[$dependenton][$condition][$value][self::DEP_HIDE][] = $element; } } } } } return array($this->getAttribute('id'), $result); }
[ "function", "getLockOptionObject", "(", ")", "{", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "_dependencies", "as", "$", "dependentOn", "=>", "$", "conditions", ")", "{", "$", "result", "[", "$", "dependentOn", "]", "=", "array", "(", ")", ";", "foreach", "(", "$", "conditions", "as", "$", "condition", "=>", "$", "values", ")", "{", "$", "result", "[", "$", "dependentOn", "]", "[", "$", "condition", "]", "=", "array", "(", ")", ";", "foreach", "(", "$", "values", "as", "$", "value", "=>", "$", "dependents", ")", "{", "$", "result", "[", "$", "dependentOn", "]", "[", "$", "condition", "]", "[", "$", "value", "]", "[", "self", "::", "DEP_DISABLE", "]", "=", "array", "(", ")", ";", "foreach", "(", "$", "dependents", "as", "$", "dependent", ")", "{", "$", "elements", "=", "$", "this", "->", "_getElNamesRecursive", "(", "$", "dependent", ")", ";", "if", "(", "empty", "(", "$", "elements", ")", ")", "{", "// probably element inside of some group", "$", "elements", "=", "array", "(", "$", "dependent", ")", ";", "}", "foreach", "(", "$", "elements", "as", "$", "element", ")", "{", "if", "(", "$", "element", "==", "$", "dependentOn", ")", "{", "continue", ";", "}", "$", "result", "[", "$", "dependentOn", "]", "[", "$", "condition", "]", "[", "$", "value", "]", "[", "self", "::", "DEP_DISABLE", "]", "[", "]", "=", "$", "element", ";", "}", "}", "}", "}", "}", "foreach", "(", "$", "this", "->", "_hideifs", "as", "$", "dependenton", "=>", "$", "conditions", ")", "{", "if", "(", "!", "isset", "(", "$", "result", "[", "$", "dependenton", "]", ")", ")", "{", "$", "result", "[", "$", "dependenton", "]", "=", "array", "(", ")", ";", "}", "foreach", "(", "$", "conditions", "as", "$", "condition", "=>", "$", "values", ")", "{", "if", "(", "!", "isset", "(", "$", "result", "[", "$", "dependenton", "]", "[", "$", "condition", "]", ")", ")", "{", "$", "result", "[", "$", "dependenton", "]", "[", "$", "condition", "]", "=", "array", "(", ")", ";", "}", "foreach", "(", "$", "values", "as", "$", "value", "=>", "$", "dependents", ")", "{", "$", "result", "[", "$", "dependenton", "]", "[", "$", "condition", "]", "[", "$", "value", "]", "[", "self", "::", "DEP_HIDE", "]", "=", "array", "(", ")", ";", "foreach", "(", "$", "dependents", "as", "$", "dependent", ")", "{", "$", "elements", "=", "$", "this", "->", "_getElNamesRecursive", "(", "$", "dependent", ")", ";", "if", "(", "!", "in_array", "(", "$", "dependent", ",", "$", "elements", ")", ")", "{", "// Always want to hide the main element, even if it contains sub-elements as well.", "$", "elements", "[", "]", "=", "$", "dependent", ";", "}", "foreach", "(", "$", "elements", "as", "$", "element", ")", "{", "if", "(", "$", "element", "==", "$", "dependenton", ")", "{", "continue", ";", "}", "$", "result", "[", "$", "dependenton", "]", "[", "$", "condition", "]", "[", "$", "value", "]", "[", "self", "::", "DEP_HIDE", "]", "[", "]", "=", "$", "element", ";", "}", "}", "}", "}", "}", "return", "array", "(", "$", "this", "->", "getAttribute", "(", "'id'", ")", ",", "$", "result", ")", ";", "}" ]
Get list of attributes which have dependencies @return array
[ "Get", "list", "of", "attributes", "which", "have", "dependencies" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/formslib.php#L2494-L2545
212,291
moodle/moodle
lib/formslib.php
MoodleQuickForm._getElNamesRecursive
function _getElNamesRecursive($element) { if (is_string($element)) { if (!$this->elementExists($element)) { return array(); } $element = $this->getElement($element); } if (is_a($element, 'HTML_QuickForm_group')) { $elsInGroup = $element->getElements(); $elNames = array(); foreach ($elsInGroup as $elInGroup){ if (is_a($elInGroup, 'HTML_QuickForm_group')) { // Groups nested in groups: append the group name to the element and then change it back. // We will be appending group name again in MoodleQuickForm_group::export_for_template(). $oldname = $elInGroup->getName(); if ($element->_appendName) { $elInGroup->setName($element->getName() . '[' . $oldname . ']'); } $elNames = array_merge($elNames, $this->_getElNamesRecursive($elInGroup)); $elInGroup->setName($oldname); } else { $elNames[] = $element->getElementName($elInGroup->getName()); } } } else if (is_a($element, 'HTML_QuickForm_header')) { return array(); } else if (is_a($element, 'HTML_QuickForm_hidden')) { return array(); } else if (method_exists($element, 'getPrivateName') && !($element instanceof HTML_QuickForm_advcheckbox)) { // The advcheckbox element implements a method called getPrivateName, // but in a way that is not compatible with the generic API, so we // have to explicitly exclude it. return array($element->getPrivateName()); } else { $elNames = array($element->getName()); } return $elNames; }
php
function _getElNamesRecursive($element) { if (is_string($element)) { if (!$this->elementExists($element)) { return array(); } $element = $this->getElement($element); } if (is_a($element, 'HTML_QuickForm_group')) { $elsInGroup = $element->getElements(); $elNames = array(); foreach ($elsInGroup as $elInGroup){ if (is_a($elInGroup, 'HTML_QuickForm_group')) { // Groups nested in groups: append the group name to the element and then change it back. // We will be appending group name again in MoodleQuickForm_group::export_for_template(). $oldname = $elInGroup->getName(); if ($element->_appendName) { $elInGroup->setName($element->getName() . '[' . $oldname . ']'); } $elNames = array_merge($elNames, $this->_getElNamesRecursive($elInGroup)); $elInGroup->setName($oldname); } else { $elNames[] = $element->getElementName($elInGroup->getName()); } } } else if (is_a($element, 'HTML_QuickForm_header')) { return array(); } else if (is_a($element, 'HTML_QuickForm_hidden')) { return array(); } else if (method_exists($element, 'getPrivateName') && !($element instanceof HTML_QuickForm_advcheckbox)) { // The advcheckbox element implements a method called getPrivateName, // but in a way that is not compatible with the generic API, so we // have to explicitly exclude it. return array($element->getPrivateName()); } else { $elNames = array($element->getName()); } return $elNames; }
[ "function", "_getElNamesRecursive", "(", "$", "element", ")", "{", "if", "(", "is_string", "(", "$", "element", ")", ")", "{", "if", "(", "!", "$", "this", "->", "elementExists", "(", "$", "element", ")", ")", "{", "return", "array", "(", ")", ";", "}", "$", "element", "=", "$", "this", "->", "getElement", "(", "$", "element", ")", ";", "}", "if", "(", "is_a", "(", "$", "element", ",", "'HTML_QuickForm_group'", ")", ")", "{", "$", "elsInGroup", "=", "$", "element", "->", "getElements", "(", ")", ";", "$", "elNames", "=", "array", "(", ")", ";", "foreach", "(", "$", "elsInGroup", "as", "$", "elInGroup", ")", "{", "if", "(", "is_a", "(", "$", "elInGroup", ",", "'HTML_QuickForm_group'", ")", ")", "{", "// Groups nested in groups: append the group name to the element and then change it back.", "// We will be appending group name again in MoodleQuickForm_group::export_for_template().", "$", "oldname", "=", "$", "elInGroup", "->", "getName", "(", ")", ";", "if", "(", "$", "element", "->", "_appendName", ")", "{", "$", "elInGroup", "->", "setName", "(", "$", "element", "->", "getName", "(", ")", ".", "'['", ".", "$", "oldname", ".", "']'", ")", ";", "}", "$", "elNames", "=", "array_merge", "(", "$", "elNames", ",", "$", "this", "->", "_getElNamesRecursive", "(", "$", "elInGroup", ")", ")", ";", "$", "elInGroup", "->", "setName", "(", "$", "oldname", ")", ";", "}", "else", "{", "$", "elNames", "[", "]", "=", "$", "element", "->", "getElementName", "(", "$", "elInGroup", "->", "getName", "(", ")", ")", ";", "}", "}", "}", "else", "if", "(", "is_a", "(", "$", "element", ",", "'HTML_QuickForm_header'", ")", ")", "{", "return", "array", "(", ")", ";", "}", "else", "if", "(", "is_a", "(", "$", "element", ",", "'HTML_QuickForm_hidden'", ")", ")", "{", "return", "array", "(", ")", ";", "}", "else", "if", "(", "method_exists", "(", "$", "element", ",", "'getPrivateName'", ")", "&&", "!", "(", "$", "element", "instanceof", "HTML_QuickForm_advcheckbox", ")", ")", "{", "// The advcheckbox element implements a method called getPrivateName,", "// but in a way that is not compatible with the generic API, so we", "// have to explicitly exclude it.", "return", "array", "(", "$", "element", "->", "getPrivateName", "(", ")", ")", ";", "}", "else", "{", "$", "elNames", "=", "array", "(", "$", "element", "->", "getName", "(", ")", ")", ";", "}", "return", "$", "elNames", ";", "}" ]
Get names of element or elements in a group. @param HTML_QuickForm_group|element $element element group or element object @return array
[ "Get", "names", "of", "element", "or", "elements", "in", "a", "group", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/formslib.php#L2553-L2597
212,292
moodle/moodle
lib/formslib.php
MoodleQuickForm_Renderer.startForm
function startForm(&$form){ global $PAGE; $this->_reqHTML = $form->getReqHTML(); $this->_elementTemplates = str_replace('{req}', $this->_reqHTML, $this->_elementTemplates); $this->_advancedHTML = $form->getAdvancedHTML(); $this->_collapseButtons = ''; $formid = $form->getAttribute('id'); parent::startForm($form); if ($form->isFrozen()){ $this->_formTemplate = "\n<div id=\"$formid\" class=\"mform frozen\">\n{collapsebtns}\n{content}\n</div>"; } else { $this->_formTemplate = "\n<form{attributes}>\n\t<div style=\"display: none;\">{hidden}</div>\n{collapsebtns}\n{content}\n</form>"; $this->_hiddenHtml .= $form->_pageparams; } if ($form->is_form_change_checker_enabled()) { $PAGE->requires->yui_module('moodle-core-formchangechecker', 'M.core_formchangechecker.init', array(array( 'formid' => $formid )) ); $PAGE->requires->string_for_js('changesmadereallygoaway', 'moodle'); } if (!empty($this->_collapsibleElements)) { if (count($this->_collapsibleElements) > 1) { $this->_collapseButtons = $this->_collapseButtonsTemplate; $this->_collapseButtons = str_replace('{strexpandall}', get_string('expandall'), $this->_collapseButtons); $PAGE->requires->strings_for_js(array('collapseall', 'expandall'), 'moodle'); } $PAGE->requires->yui_module('moodle-form-shortforms', 'M.form.shortforms', array(array('formid' => $formid))); } if (!empty($this->_advancedElements)){ $PAGE->requires->js_call_amd('core_form/showadvanced', 'init', [$formid]); } }
php
function startForm(&$form){ global $PAGE; $this->_reqHTML = $form->getReqHTML(); $this->_elementTemplates = str_replace('{req}', $this->_reqHTML, $this->_elementTemplates); $this->_advancedHTML = $form->getAdvancedHTML(); $this->_collapseButtons = ''; $formid = $form->getAttribute('id'); parent::startForm($form); if ($form->isFrozen()){ $this->_formTemplate = "\n<div id=\"$formid\" class=\"mform frozen\">\n{collapsebtns}\n{content}\n</div>"; } else { $this->_formTemplate = "\n<form{attributes}>\n\t<div style=\"display: none;\">{hidden}</div>\n{collapsebtns}\n{content}\n</form>"; $this->_hiddenHtml .= $form->_pageparams; } if ($form->is_form_change_checker_enabled()) { $PAGE->requires->yui_module('moodle-core-formchangechecker', 'M.core_formchangechecker.init', array(array( 'formid' => $formid )) ); $PAGE->requires->string_for_js('changesmadereallygoaway', 'moodle'); } if (!empty($this->_collapsibleElements)) { if (count($this->_collapsibleElements) > 1) { $this->_collapseButtons = $this->_collapseButtonsTemplate; $this->_collapseButtons = str_replace('{strexpandall}', get_string('expandall'), $this->_collapseButtons); $PAGE->requires->strings_for_js(array('collapseall', 'expandall'), 'moodle'); } $PAGE->requires->yui_module('moodle-form-shortforms', 'M.form.shortforms', array(array('formid' => $formid))); } if (!empty($this->_advancedElements)){ $PAGE->requires->js_call_amd('core_form/showadvanced', 'init', [$formid]); } }
[ "function", "startForm", "(", "&", "$", "form", ")", "{", "global", "$", "PAGE", ";", "$", "this", "->", "_reqHTML", "=", "$", "form", "->", "getReqHTML", "(", ")", ";", "$", "this", "->", "_elementTemplates", "=", "str_replace", "(", "'{req}'", ",", "$", "this", "->", "_reqHTML", ",", "$", "this", "->", "_elementTemplates", ")", ";", "$", "this", "->", "_advancedHTML", "=", "$", "form", "->", "getAdvancedHTML", "(", ")", ";", "$", "this", "->", "_collapseButtons", "=", "''", ";", "$", "formid", "=", "$", "form", "->", "getAttribute", "(", "'id'", ")", ";", "parent", "::", "startForm", "(", "$", "form", ")", ";", "if", "(", "$", "form", "->", "isFrozen", "(", ")", ")", "{", "$", "this", "->", "_formTemplate", "=", "\"\\n<div id=\\\"$formid\\\" class=\\\"mform frozen\\\">\\n{collapsebtns}\\n{content}\\n</div>\"", ";", "}", "else", "{", "$", "this", "->", "_formTemplate", "=", "\"\\n<form{attributes}>\\n\\t<div style=\\\"display: none;\\\">{hidden}</div>\\n{collapsebtns}\\n{content}\\n</form>\"", ";", "$", "this", "->", "_hiddenHtml", ".=", "$", "form", "->", "_pageparams", ";", "}", "if", "(", "$", "form", "->", "is_form_change_checker_enabled", "(", ")", ")", "{", "$", "PAGE", "->", "requires", "->", "yui_module", "(", "'moodle-core-formchangechecker'", ",", "'M.core_formchangechecker.init'", ",", "array", "(", "array", "(", "'formid'", "=>", "$", "formid", ")", ")", ")", ";", "$", "PAGE", "->", "requires", "->", "string_for_js", "(", "'changesmadereallygoaway'", ",", "'moodle'", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "_collapsibleElements", ")", ")", "{", "if", "(", "count", "(", "$", "this", "->", "_collapsibleElements", ")", ">", "1", ")", "{", "$", "this", "->", "_collapseButtons", "=", "$", "this", "->", "_collapseButtonsTemplate", ";", "$", "this", "->", "_collapseButtons", "=", "str_replace", "(", "'{strexpandall}'", ",", "get_string", "(", "'expandall'", ")", ",", "$", "this", "->", "_collapseButtons", ")", ";", "$", "PAGE", "->", "requires", "->", "strings_for_js", "(", "array", "(", "'collapseall'", ",", "'expandall'", ")", ",", "'moodle'", ")", ";", "}", "$", "PAGE", "->", "requires", "->", "yui_module", "(", "'moodle-form-shortforms'", ",", "'M.form.shortforms'", ",", "array", "(", "array", "(", "'formid'", "=>", "$", "formid", ")", ")", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "_advancedElements", ")", ")", "{", "$", "PAGE", "->", "requires", "->", "js_call_amd", "(", "'core_form/showadvanced'", ",", "'init'", ",", "[", "$", "formid", "]", ")", ";", "}", "}" ]
What to do when starting the form @param MoodleQuickForm $form reference of the form
[ "What", "to", "do", "when", "starting", "the", "form" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/formslib.php#L2912-L2947
212,293
moodle/moodle
lib/formslib.php
MoodleQuickForm_Rule_Required.validate
function validate($value, $options = null) { global $CFG; if (is_array($value) && array_key_exists('text', $value)) { $value = $value['text']; } if (is_array($value)) { // nasty guess - there has to be something in the array, hopefully nobody invents arrays in arrays $value = implode('', $value); } $stripvalues = array( '#</?(?!img|canvas|hr).*?>#im', // all tags except img, canvas and hr '#(\xc2\xa0|\s|&nbsp;)#', // Any whitespaces actually. ); if (!empty($CFG->strictformsrequired)) { $value = preg_replace($stripvalues, '', (string)$value); } if ((string)$value == '') { return false; } return true; }
php
function validate($value, $options = null) { global $CFG; if (is_array($value) && array_key_exists('text', $value)) { $value = $value['text']; } if (is_array($value)) { // nasty guess - there has to be something in the array, hopefully nobody invents arrays in arrays $value = implode('', $value); } $stripvalues = array( '#</?(?!img|canvas|hr).*?>#im', // all tags except img, canvas and hr '#(\xc2\xa0|\s|&nbsp;)#', // Any whitespaces actually. ); if (!empty($CFG->strictformsrequired)) { $value = preg_replace($stripvalues, '', (string)$value); } if ((string)$value == '') { return false; } return true; }
[ "function", "validate", "(", "$", "value", ",", "$", "options", "=", "null", ")", "{", "global", "$", "CFG", ";", "if", "(", "is_array", "(", "$", "value", ")", "&&", "array_key_exists", "(", "'text'", ",", "$", "value", ")", ")", "{", "$", "value", "=", "$", "value", "[", "'text'", "]", ";", "}", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "// nasty guess - there has to be something in the array, hopefully nobody invents arrays in arrays", "$", "value", "=", "implode", "(", "''", ",", "$", "value", ")", ";", "}", "$", "stripvalues", "=", "array", "(", "'#</?(?!img|canvas|hr).*?>#im'", ",", "// all tags except img, canvas and hr", "'#(\\xc2\\xa0|\\s|&nbsp;)#'", ",", "// Any whitespaces actually.", ")", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "strictformsrequired", ")", ")", "{", "$", "value", "=", "preg_replace", "(", "$", "stripvalues", ",", "''", ",", "(", "string", ")", "$", "value", ")", ";", "}", "if", "(", "(", "string", ")", "$", "value", "==", "''", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Checks if an element is not empty. This is a server-side validation, it works for both text fields and editor fields @param string $value Value to check @param int|string|array $options Not used yet @return bool true if value is not empty
[ "Checks", "if", "an", "element", "is", "not", "empty", ".", "This", "is", "a", "server", "-", "side", "validation", "it", "works", "for", "both", "text", "fields", "and", "editor", "fields" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/formslib.php#L3191-L3211
212,294
moodle/moodle
lib/formslib.php
MoodleQuickForm_Rule_Required.getValidationScript
function getValidationScript($format = null) { global $CFG; if (!empty($CFG->strictformsrequired)) { if (!empty($format) && $format == FORMAT_HTML) { return array('', "{jsVar}.replace(/(<(?!img|hr|canvas)[^>]*>)|&nbsp;|\s+/ig, '') == ''"); } else { return array('', "{jsVar}.replace(/^\s+$/g, '') == ''"); } } else { return array('', "{jsVar} == ''"); } }
php
function getValidationScript($format = null) { global $CFG; if (!empty($CFG->strictformsrequired)) { if (!empty($format) && $format == FORMAT_HTML) { return array('', "{jsVar}.replace(/(<(?!img|hr|canvas)[^>]*>)|&nbsp;|\s+/ig, '') == ''"); } else { return array('', "{jsVar}.replace(/^\s+$/g, '') == ''"); } } else { return array('', "{jsVar} == ''"); } }
[ "function", "getValidationScript", "(", "$", "format", "=", "null", ")", "{", "global", "$", "CFG", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "strictformsrequired", ")", ")", "{", "if", "(", "!", "empty", "(", "$", "format", ")", "&&", "$", "format", "==", "FORMAT_HTML", ")", "{", "return", "array", "(", "''", ",", "\"{jsVar}.replace(/(<(?!img|hr|canvas)[^>]*>)|&nbsp;|\\s+/ig, '') == ''\"", ")", ";", "}", "else", "{", "return", "array", "(", "''", ",", "\"{jsVar}.replace(/^\\s+$/g, '') == ''\"", ")", ";", "}", "}", "else", "{", "return", "array", "(", "''", ",", "\"{jsVar} == ''\"", ")", ";", "}", "}" ]
This function returns Javascript code used to build client-side validation. It checks if an element is not empty. @param int $format format of data which needs to be validated. @return array
[ "This", "function", "returns", "Javascript", "code", "used", "to", "build", "client", "-", "side", "validation", ".", "It", "checks", "if", "an", "element", "is", "not", "empty", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/formslib.php#L3220-L3231
212,295
moodle/moodle
lib/phpexcel/PHPExcel/Writer/OpenDocument/Content.php
PHPExcel_Writer_OpenDocument_Content.writeRows
private function writeRows(PHPExcel_Shared_XMLWriter $objWriter, PHPExcel_Worksheet $sheet) { $number_rows_repeated = self::NUMBER_ROWS_REPEATED_MAX; $span_row = 0; $rows = $sheet->getRowIterator(); while ($rows->valid()) { $number_rows_repeated--; $row = $rows->current(); if ($row->getCellIterator()->valid()) { if ($span_row) { $objWriter->startElement('table:table-row'); if ($span_row > 1) { $objWriter->writeAttribute('table:number-rows-repeated', $span_row); } $objWriter->startElement('table:table-cell'); $objWriter->writeAttribute('table:number-columns-repeated', self::NUMBER_COLS_REPEATED_MAX); $objWriter->endElement(); $objWriter->endElement(); $span_row = 0; } $objWriter->startElement('table:table-row'); $this->writeCells($objWriter, $row); $objWriter->endElement(); } else { $span_row++; } $rows->next(); } }
php
private function writeRows(PHPExcel_Shared_XMLWriter $objWriter, PHPExcel_Worksheet $sheet) { $number_rows_repeated = self::NUMBER_ROWS_REPEATED_MAX; $span_row = 0; $rows = $sheet->getRowIterator(); while ($rows->valid()) { $number_rows_repeated--; $row = $rows->current(); if ($row->getCellIterator()->valid()) { if ($span_row) { $objWriter->startElement('table:table-row'); if ($span_row > 1) { $objWriter->writeAttribute('table:number-rows-repeated', $span_row); } $objWriter->startElement('table:table-cell'); $objWriter->writeAttribute('table:number-columns-repeated', self::NUMBER_COLS_REPEATED_MAX); $objWriter->endElement(); $objWriter->endElement(); $span_row = 0; } $objWriter->startElement('table:table-row'); $this->writeCells($objWriter, $row); $objWriter->endElement(); } else { $span_row++; } $rows->next(); } }
[ "private", "function", "writeRows", "(", "PHPExcel_Shared_XMLWriter", "$", "objWriter", ",", "PHPExcel_Worksheet", "$", "sheet", ")", "{", "$", "number_rows_repeated", "=", "self", "::", "NUMBER_ROWS_REPEATED_MAX", ";", "$", "span_row", "=", "0", ";", "$", "rows", "=", "$", "sheet", "->", "getRowIterator", "(", ")", ";", "while", "(", "$", "rows", "->", "valid", "(", ")", ")", "{", "$", "number_rows_repeated", "--", ";", "$", "row", "=", "$", "rows", "->", "current", "(", ")", ";", "if", "(", "$", "row", "->", "getCellIterator", "(", ")", "->", "valid", "(", ")", ")", "{", "if", "(", "$", "span_row", ")", "{", "$", "objWriter", "->", "startElement", "(", "'table:table-row'", ")", ";", "if", "(", "$", "span_row", ">", "1", ")", "{", "$", "objWriter", "->", "writeAttribute", "(", "'table:number-rows-repeated'", ",", "$", "span_row", ")", ";", "}", "$", "objWriter", "->", "startElement", "(", "'table:table-cell'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'table:number-columns-repeated'", ",", "self", "::", "NUMBER_COLS_REPEATED_MAX", ")", ";", "$", "objWriter", "->", "endElement", "(", ")", ";", "$", "objWriter", "->", "endElement", "(", ")", ";", "$", "span_row", "=", "0", ";", "}", "$", "objWriter", "->", "startElement", "(", "'table:table-row'", ")", ";", "$", "this", "->", "writeCells", "(", "$", "objWriter", ",", "$", "row", ")", ";", "$", "objWriter", "->", "endElement", "(", ")", ";", "}", "else", "{", "$", "span_row", "++", ";", "}", "$", "rows", "->", "next", "(", ")", ";", "}", "}" ]
Write rows of the specified sheet @param PHPExcel_Shared_XMLWriter $objWriter @param PHPExcel_Worksheet $sheet
[ "Write", "rows", "of", "the", "specified", "sheet" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Writer/OpenDocument/Content.php#L146-L174
212,296
moodle/moodle
lib/phpexcel/PHPExcel/Writer/OpenDocument/Content.php
PHPExcel_Writer_OpenDocument_Content.writeCells
private function writeCells(PHPExcel_Shared_XMLWriter $objWriter, PHPExcel_Worksheet_Row $row) { $number_cols_repeated = self::NUMBER_COLS_REPEATED_MAX; $prev_column = -1; $cells = $row->getCellIterator(); while ($cells->valid()) { $cell = $cells->current(); $column = PHPExcel_Cell::columnIndexFromString($cell->getColumn()) - 1; $this->writeCellSpan($objWriter, $column, $prev_column); $objWriter->startElement('table:table-cell'); switch ($cell->getDataType()) { case PHPExcel_Cell_DataType::TYPE_BOOL: $objWriter->writeAttribute('office:value-type', 'boolean'); $objWriter->writeAttribute('office:value', $cell->getValue()); $objWriter->writeElement('text:p', $cell->getValue()); break; case PHPExcel_Cell_DataType::TYPE_ERROR: throw new PHPExcel_Writer_Exception('Writing of error not implemented yet.'); break; case PHPExcel_Cell_DataType::TYPE_FORMULA: try { $formula_value = $cell->getCalculatedValue(); } catch (Exception $e) { $formula_value = $cell->getValue(); } $objWriter->writeAttribute('table:formula', 'of:' . $cell->getValue()); if (is_numeric($formula_value)) { $objWriter->writeAttribute('office:value-type', 'float'); } else { $objWriter->writeAttribute('office:value-type', 'string'); } $objWriter->writeAttribute('office:value', $formula_value); $objWriter->writeElement('text:p', $formula_value); break; case PHPExcel_Cell_DataType::TYPE_INLINE: throw new PHPExcel_Writer_Exception('Writing of inline not implemented yet.'); break; case PHPExcel_Cell_DataType::TYPE_NUMERIC: $objWriter->writeAttribute('office:value-type', 'float'); $objWriter->writeAttribute('office:value', $cell->getValue()); $objWriter->writeElement('text:p', $cell->getValue()); break; case PHPExcel_Cell_DataType::TYPE_STRING: $objWriter->writeAttribute('office:value-type', 'string'); $objWriter->writeElement('text:p', $cell->getValue()); break; } PHPExcel_Writer_OpenDocument_Cell_Comment::write($objWriter, $cell); $objWriter->endElement(); $prev_column = $column; $cells->next(); } $number_cols_repeated = $number_cols_repeated - $prev_column - 1; if ($number_cols_repeated > 0) { if ($number_cols_repeated > 1) { $objWriter->startElement('table:table-cell'); $objWriter->writeAttribute('table:number-columns-repeated', $number_cols_repeated); $objWriter->endElement(); } else { $objWriter->writeElement('table:table-cell'); } } }
php
private function writeCells(PHPExcel_Shared_XMLWriter $objWriter, PHPExcel_Worksheet_Row $row) { $number_cols_repeated = self::NUMBER_COLS_REPEATED_MAX; $prev_column = -1; $cells = $row->getCellIterator(); while ($cells->valid()) { $cell = $cells->current(); $column = PHPExcel_Cell::columnIndexFromString($cell->getColumn()) - 1; $this->writeCellSpan($objWriter, $column, $prev_column); $objWriter->startElement('table:table-cell'); switch ($cell->getDataType()) { case PHPExcel_Cell_DataType::TYPE_BOOL: $objWriter->writeAttribute('office:value-type', 'boolean'); $objWriter->writeAttribute('office:value', $cell->getValue()); $objWriter->writeElement('text:p', $cell->getValue()); break; case PHPExcel_Cell_DataType::TYPE_ERROR: throw new PHPExcel_Writer_Exception('Writing of error not implemented yet.'); break; case PHPExcel_Cell_DataType::TYPE_FORMULA: try { $formula_value = $cell->getCalculatedValue(); } catch (Exception $e) { $formula_value = $cell->getValue(); } $objWriter->writeAttribute('table:formula', 'of:' . $cell->getValue()); if (is_numeric($formula_value)) { $objWriter->writeAttribute('office:value-type', 'float'); } else { $objWriter->writeAttribute('office:value-type', 'string'); } $objWriter->writeAttribute('office:value', $formula_value); $objWriter->writeElement('text:p', $formula_value); break; case PHPExcel_Cell_DataType::TYPE_INLINE: throw new PHPExcel_Writer_Exception('Writing of inline not implemented yet.'); break; case PHPExcel_Cell_DataType::TYPE_NUMERIC: $objWriter->writeAttribute('office:value-type', 'float'); $objWriter->writeAttribute('office:value', $cell->getValue()); $objWriter->writeElement('text:p', $cell->getValue()); break; case PHPExcel_Cell_DataType::TYPE_STRING: $objWriter->writeAttribute('office:value-type', 'string'); $objWriter->writeElement('text:p', $cell->getValue()); break; } PHPExcel_Writer_OpenDocument_Cell_Comment::write($objWriter, $cell); $objWriter->endElement(); $prev_column = $column; $cells->next(); } $number_cols_repeated = $number_cols_repeated - $prev_column - 1; if ($number_cols_repeated > 0) { if ($number_cols_repeated > 1) { $objWriter->startElement('table:table-cell'); $objWriter->writeAttribute('table:number-columns-repeated', $number_cols_repeated); $objWriter->endElement(); } else { $objWriter->writeElement('table:table-cell'); } } }
[ "private", "function", "writeCells", "(", "PHPExcel_Shared_XMLWriter", "$", "objWriter", ",", "PHPExcel_Worksheet_Row", "$", "row", ")", "{", "$", "number_cols_repeated", "=", "self", "::", "NUMBER_COLS_REPEATED_MAX", ";", "$", "prev_column", "=", "-", "1", ";", "$", "cells", "=", "$", "row", "->", "getCellIterator", "(", ")", ";", "while", "(", "$", "cells", "->", "valid", "(", ")", ")", "{", "$", "cell", "=", "$", "cells", "->", "current", "(", ")", ";", "$", "column", "=", "PHPExcel_Cell", "::", "columnIndexFromString", "(", "$", "cell", "->", "getColumn", "(", ")", ")", "-", "1", ";", "$", "this", "->", "writeCellSpan", "(", "$", "objWriter", ",", "$", "column", ",", "$", "prev_column", ")", ";", "$", "objWriter", "->", "startElement", "(", "'table:table-cell'", ")", ";", "switch", "(", "$", "cell", "->", "getDataType", "(", ")", ")", "{", "case", "PHPExcel_Cell_DataType", "::", "TYPE_BOOL", ":", "$", "objWriter", "->", "writeAttribute", "(", "'office:value-type'", ",", "'boolean'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'office:value'", ",", "$", "cell", "->", "getValue", "(", ")", ")", ";", "$", "objWriter", "->", "writeElement", "(", "'text:p'", ",", "$", "cell", "->", "getValue", "(", ")", ")", ";", "break", ";", "case", "PHPExcel_Cell_DataType", "::", "TYPE_ERROR", ":", "throw", "new", "PHPExcel_Writer_Exception", "(", "'Writing of error not implemented yet.'", ")", ";", "break", ";", "case", "PHPExcel_Cell_DataType", "::", "TYPE_FORMULA", ":", "try", "{", "$", "formula_value", "=", "$", "cell", "->", "getCalculatedValue", "(", ")", ";", "}", "catch", "(", "Exception", "$", "e", ")", "{", "$", "formula_value", "=", "$", "cell", "->", "getValue", "(", ")", ";", "}", "$", "objWriter", "->", "writeAttribute", "(", "'table:formula'", ",", "'of:'", ".", "$", "cell", "->", "getValue", "(", ")", ")", ";", "if", "(", "is_numeric", "(", "$", "formula_value", ")", ")", "{", "$", "objWriter", "->", "writeAttribute", "(", "'office:value-type'", ",", "'float'", ")", ";", "}", "else", "{", "$", "objWriter", "->", "writeAttribute", "(", "'office:value-type'", ",", "'string'", ")", ";", "}", "$", "objWriter", "->", "writeAttribute", "(", "'office:value'", ",", "$", "formula_value", ")", ";", "$", "objWriter", "->", "writeElement", "(", "'text:p'", ",", "$", "formula_value", ")", ";", "break", ";", "case", "PHPExcel_Cell_DataType", "::", "TYPE_INLINE", ":", "throw", "new", "PHPExcel_Writer_Exception", "(", "'Writing of inline not implemented yet.'", ")", ";", "break", ";", "case", "PHPExcel_Cell_DataType", "::", "TYPE_NUMERIC", ":", "$", "objWriter", "->", "writeAttribute", "(", "'office:value-type'", ",", "'float'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'office:value'", ",", "$", "cell", "->", "getValue", "(", ")", ")", ";", "$", "objWriter", "->", "writeElement", "(", "'text:p'", ",", "$", "cell", "->", "getValue", "(", ")", ")", ";", "break", ";", "case", "PHPExcel_Cell_DataType", "::", "TYPE_STRING", ":", "$", "objWriter", "->", "writeAttribute", "(", "'office:value-type'", ",", "'string'", ")", ";", "$", "objWriter", "->", "writeElement", "(", "'text:p'", ",", "$", "cell", "->", "getValue", "(", ")", ")", ";", "break", ";", "}", "PHPExcel_Writer_OpenDocument_Cell_Comment", "::", "write", "(", "$", "objWriter", ",", "$", "cell", ")", ";", "$", "objWriter", "->", "endElement", "(", ")", ";", "$", "prev_column", "=", "$", "column", ";", "$", "cells", "->", "next", "(", ")", ";", "}", "$", "number_cols_repeated", "=", "$", "number_cols_repeated", "-", "$", "prev_column", "-", "1", ";", "if", "(", "$", "number_cols_repeated", ">", "0", ")", "{", "if", "(", "$", "number_cols_repeated", ">", "1", ")", "{", "$", "objWriter", "->", "startElement", "(", "'table:table-cell'", ")", ";", "$", "objWriter", "->", "writeAttribute", "(", "'table:number-columns-repeated'", ",", "$", "number_cols_repeated", ")", ";", "$", "objWriter", "->", "endElement", "(", ")", ";", "}", "else", "{", "$", "objWriter", "->", "writeElement", "(", "'table:table-cell'", ")", ";", "}", "}", "}" ]
Write cells of the specified row @param PHPExcel_Shared_XMLWriter $objWriter @param PHPExcel_Worksheet_Row $row @throws PHPExcel_Writer_Exception
[ "Write", "cells", "of", "the", "specified", "row" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Writer/OpenDocument/Content.php#L183-L252
212,297
moodle/moodle
lib/htmlpurifier/HTMLPurifier/ElementDef.php
HTMLPurifier_ElementDef.create
public static function create($content_model, $content_model_type, $attr) { $def = new HTMLPurifier_ElementDef(); $def->content_model = $content_model; $def->content_model_type = $content_model_type; $def->attr = $attr; return $def; }
php
public static function create($content_model, $content_model_type, $attr) { $def = new HTMLPurifier_ElementDef(); $def->content_model = $content_model; $def->content_model_type = $content_model_type; $def->attr = $attr; return $def; }
[ "public", "static", "function", "create", "(", "$", "content_model", ",", "$", "content_model_type", ",", "$", "attr", ")", "{", "$", "def", "=", "new", "HTMLPurifier_ElementDef", "(", ")", ";", "$", "def", "->", "content_model", "=", "$", "content_model", ";", "$", "def", "->", "content_model_type", "=", "$", "content_model_type", ";", "$", "def", "->", "attr", "=", "$", "attr", ";", "return", "$", "def", ";", "}" ]
Low-level factory constructor for creating new standalone element defs
[ "Low", "-", "level", "factory", "constructor", "for", "creating", "new", "standalone", "element", "defs" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/ElementDef.php#L138-L145
212,298
moodle/moodle
lib/htmlpurifier/HTMLPurifier/ElementDef.php
HTMLPurifier_ElementDef.mergeIn
public function mergeIn($def) { // later keys takes precedence foreach ($def->attr as $k => $v) { if ($k === 0) { // merge in the includes // sorry, no way to override an include foreach ($v as $v2) { $this->attr[0][] = $v2; } continue; } if ($v === false) { if (isset($this->attr[$k])) { unset($this->attr[$k]); } continue; } $this->attr[$k] = $v; } $this->_mergeAssocArray($this->excludes, $def->excludes); $this->attr_transform_pre = array_merge($this->attr_transform_pre, $def->attr_transform_pre); $this->attr_transform_post = array_merge($this->attr_transform_post, $def->attr_transform_post); if (!empty($def->content_model)) { $this->content_model = str_replace("#SUPER", $this->content_model, $def->content_model); $this->child = false; } if (!empty($def->content_model_type)) { $this->content_model_type = $def->content_model_type; $this->child = false; } if (!is_null($def->child)) { $this->child = $def->child; } if (!is_null($def->formatting)) { $this->formatting = $def->formatting; } if ($def->descendants_are_inline) { $this->descendants_are_inline = $def->descendants_are_inline; } }
php
public function mergeIn($def) { // later keys takes precedence foreach ($def->attr as $k => $v) { if ($k === 0) { // merge in the includes // sorry, no way to override an include foreach ($v as $v2) { $this->attr[0][] = $v2; } continue; } if ($v === false) { if (isset($this->attr[$k])) { unset($this->attr[$k]); } continue; } $this->attr[$k] = $v; } $this->_mergeAssocArray($this->excludes, $def->excludes); $this->attr_transform_pre = array_merge($this->attr_transform_pre, $def->attr_transform_pre); $this->attr_transform_post = array_merge($this->attr_transform_post, $def->attr_transform_post); if (!empty($def->content_model)) { $this->content_model = str_replace("#SUPER", $this->content_model, $def->content_model); $this->child = false; } if (!empty($def->content_model_type)) { $this->content_model_type = $def->content_model_type; $this->child = false; } if (!is_null($def->child)) { $this->child = $def->child; } if (!is_null($def->formatting)) { $this->formatting = $def->formatting; } if ($def->descendants_are_inline) { $this->descendants_are_inline = $def->descendants_are_inline; } }
[ "public", "function", "mergeIn", "(", "$", "def", ")", "{", "// later keys takes precedence", "foreach", "(", "$", "def", "->", "attr", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "$", "k", "===", "0", ")", "{", "// merge in the includes", "// sorry, no way to override an include", "foreach", "(", "$", "v", "as", "$", "v2", ")", "{", "$", "this", "->", "attr", "[", "0", "]", "[", "]", "=", "$", "v2", ";", "}", "continue", ";", "}", "if", "(", "$", "v", "===", "false", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "attr", "[", "$", "k", "]", ")", ")", "{", "unset", "(", "$", "this", "->", "attr", "[", "$", "k", "]", ")", ";", "}", "continue", ";", "}", "$", "this", "->", "attr", "[", "$", "k", "]", "=", "$", "v", ";", "}", "$", "this", "->", "_mergeAssocArray", "(", "$", "this", "->", "excludes", ",", "$", "def", "->", "excludes", ")", ";", "$", "this", "->", "attr_transform_pre", "=", "array_merge", "(", "$", "this", "->", "attr_transform_pre", ",", "$", "def", "->", "attr_transform_pre", ")", ";", "$", "this", "->", "attr_transform_post", "=", "array_merge", "(", "$", "this", "->", "attr_transform_post", ",", "$", "def", "->", "attr_transform_post", ")", ";", "if", "(", "!", "empty", "(", "$", "def", "->", "content_model", ")", ")", "{", "$", "this", "->", "content_model", "=", "str_replace", "(", "\"#SUPER\"", ",", "$", "this", "->", "content_model", ",", "$", "def", "->", "content_model", ")", ";", "$", "this", "->", "child", "=", "false", ";", "}", "if", "(", "!", "empty", "(", "$", "def", "->", "content_model_type", ")", ")", "{", "$", "this", "->", "content_model_type", "=", "$", "def", "->", "content_model_type", ";", "$", "this", "->", "child", "=", "false", ";", "}", "if", "(", "!", "is_null", "(", "$", "def", "->", "child", ")", ")", "{", "$", "this", "->", "child", "=", "$", "def", "->", "child", ";", "}", "if", "(", "!", "is_null", "(", "$", "def", "->", "formatting", ")", ")", "{", "$", "this", "->", "formatting", "=", "$", "def", "->", "formatting", ";", "}", "if", "(", "$", "def", "->", "descendants_are_inline", ")", "{", "$", "this", "->", "descendants_are_inline", "=", "$", "def", "->", "descendants_are_inline", ";", "}", "}" ]
Merges the values of another element definition into this one. Values from the new element def take precedence if a value is not mergeable. @param HTMLPurifier_ElementDef $def
[ "Merges", "the", "values", "of", "another", "element", "definition", "into", "this", "one", ".", "Values", "from", "the", "new", "element", "def", "take", "precedence", "if", "a", "value", "is", "not", "mergeable", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/ElementDef.php#L153-L195
212,299
moodle/moodle
lib/htmlpurifier/HTMLPurifier/ElementDef.php
HTMLPurifier_ElementDef._mergeAssocArray
private function _mergeAssocArray(&$a1, $a2) { foreach ($a2 as $k => $v) { if ($v === false) { if (isset($a1[$k])) { unset($a1[$k]); } continue; } $a1[$k] = $v; } }
php
private function _mergeAssocArray(&$a1, $a2) { foreach ($a2 as $k => $v) { if ($v === false) { if (isset($a1[$k])) { unset($a1[$k]); } continue; } $a1[$k] = $v; } }
[ "private", "function", "_mergeAssocArray", "(", "&", "$", "a1", ",", "$", "a2", ")", "{", "foreach", "(", "$", "a2", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "$", "v", "===", "false", ")", "{", "if", "(", "isset", "(", "$", "a1", "[", "$", "k", "]", ")", ")", "{", "unset", "(", "$", "a1", "[", "$", "k", "]", ")", ";", "}", "continue", ";", "}", "$", "a1", "[", "$", "k", "]", "=", "$", "v", ";", "}", "}" ]
Merges one array into another, removes values which equal false @param $a1 Array by reference that is merged into @param $a2 Array that merges into $a1
[ "Merges", "one", "array", "into", "another", "removes", "values", "which", "equal", "false" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/ElementDef.php#L202-L213