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
213,100
moodle/moodle
mod/workshop/classes/privacy/provider.php
provider.export_assessment_forms
protected static function export_assessment_forms(\stdClass $user, \context $context, array $subcontext, int $assessmentid) { foreach (\workshop::available_strategies_list() as $strategy => $title) { $providername = '\workshopform_'.$strategy.'\privacy\provider'; if (is_subclass_of($providername, '\mod_workshop\privacy\workshopform_provider')) { component_class_callback($providername, 'export_assessment_form', [ $user, $context, array_merge($subcontext, [get_string('assessmentform', 'mod_workshop'), $title]), $assessmentid, ] ); } else { debugging('Missing class '.$providername.' implementing workshopform_provider interface', DEBUG_DEVELOPER); } } }
php
protected static function export_assessment_forms(\stdClass $user, \context $context, array $subcontext, int $assessmentid) { foreach (\workshop::available_strategies_list() as $strategy => $title) { $providername = '\workshopform_'.$strategy.'\privacy\provider'; if (is_subclass_of($providername, '\mod_workshop\privacy\workshopform_provider')) { component_class_callback($providername, 'export_assessment_form', [ $user, $context, array_merge($subcontext, [get_string('assessmentform', 'mod_workshop'), $title]), $assessmentid, ] ); } else { debugging('Missing class '.$providername.' implementing workshopform_provider interface', DEBUG_DEVELOPER); } } }
[ "protected", "static", "function", "export_assessment_forms", "(", "\\", "stdClass", "$", "user", ",", "\\", "context", "$", "context", ",", "array", "$", "subcontext", ",", "int", "$", "assessmentid", ")", "{", "foreach", "(", "\\", "workshop", "::", "available_strategies_list", "(", ")", "as", "$", "strategy", "=>", "$", "title", ")", "{", "$", "providername", "=", "'\\workshopform_'", ".", "$", "strategy", ".", "'\\privacy\\provider'", ";", "if", "(", "is_subclass_of", "(", "$", "providername", ",", "'\\mod_workshop\\privacy\\workshopform_provider'", ")", ")", "{", "component_class_callback", "(", "$", "providername", ",", "'export_assessment_form'", ",", "[", "$", "user", ",", "$", "context", ",", "array_merge", "(", "$", "subcontext", ",", "[", "get_string", "(", "'assessmentform'", ",", "'mod_workshop'", ")", ",", "$", "title", "]", ")", ",", "$", "assessmentid", ",", "]", ")", ";", "}", "else", "{", "debugging", "(", "'Missing class '", ".", "$", "providername", ".", "' implementing workshopform_provider interface'", ",", "DEBUG_DEVELOPER", ")", ";", "}", "}", "}" ]
Export the grading strategy data related to the particular assessment. @param stdClass $user User we are exporting for @param context $context Workshop activity content @param array $subcontext Subcontext path of the assessment @param int $assessmentid ID of the exported assessment
[ "Export", "the", "grading", "strategy", "data", "related", "to", "the", "particular", "assessment", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/classes/privacy/provider.php#L546-L565
213,101
moodle/moodle
mod/workshop/classes/privacy/provider.php
provider.delete_data_for_all_users_in_context
public static function delete_data_for_all_users_in_context(\context $context) { global $CFG, $DB; require_once($CFG->libdir.'/gradelib.php'); if ($context->contextlevel != CONTEXT_MODULE) { return; } $cm = get_coursemodule_from_id('workshop', $context->instanceid, 0, false, IGNORE_MISSING); if (!$cm) { // Probably some kind of expired context. return; } $workshop = $DB->get_record('workshop', ['id' => $cm->instance], 'id, course', MUST_EXIST); $submissions = $DB->get_records('workshop_submissions', ['workshopid' => $workshop->id], '', 'id'); $assessments = $DB->get_records_list('workshop_assessments', 'submissionid', array_keys($submissions), '', 'id'); $DB->delete_records('workshop_aggregations', ['workshopid' => $workshop->id]); $DB->delete_records_list('workshop_grades', 'assessmentid', array_keys($assessments)); $DB->delete_records_list('workshop_assessments', 'id', array_keys($assessments)); $DB->delete_records_list('workshop_submissions', 'id', array_keys($submissions)); $fs = get_file_storage(); $fs->delete_area_files($context->id, 'mod_workshop', 'submission_content'); $fs->delete_area_files($context->id, 'mod_workshop', 'submission_attachment'); $fs->delete_area_files($context->id, 'mod_workshop', 'overallfeedback_content'); $fs->delete_area_files($context->id, 'mod_workshop', 'overallfeedback_attachment'); grade_update('mod/workshop', $workshop->course, 'mod', 'workshop', $workshop->id, 0, null, ['reset' => true]); grade_update('mod/workshop', $workshop->course, 'mod', 'workshop', $workshop->id, 1, null, ['reset' => true]); \core_plagiarism\privacy\provider::delete_plagiarism_for_context($context); }
php
public static function delete_data_for_all_users_in_context(\context $context) { global $CFG, $DB; require_once($CFG->libdir.'/gradelib.php'); if ($context->contextlevel != CONTEXT_MODULE) { return; } $cm = get_coursemodule_from_id('workshop', $context->instanceid, 0, false, IGNORE_MISSING); if (!$cm) { // Probably some kind of expired context. return; } $workshop = $DB->get_record('workshop', ['id' => $cm->instance], 'id, course', MUST_EXIST); $submissions = $DB->get_records('workshop_submissions', ['workshopid' => $workshop->id], '', 'id'); $assessments = $DB->get_records_list('workshop_assessments', 'submissionid', array_keys($submissions), '', 'id'); $DB->delete_records('workshop_aggregations', ['workshopid' => $workshop->id]); $DB->delete_records_list('workshop_grades', 'assessmentid', array_keys($assessments)); $DB->delete_records_list('workshop_assessments', 'id', array_keys($assessments)); $DB->delete_records_list('workshop_submissions', 'id', array_keys($submissions)); $fs = get_file_storage(); $fs->delete_area_files($context->id, 'mod_workshop', 'submission_content'); $fs->delete_area_files($context->id, 'mod_workshop', 'submission_attachment'); $fs->delete_area_files($context->id, 'mod_workshop', 'overallfeedback_content'); $fs->delete_area_files($context->id, 'mod_workshop', 'overallfeedback_attachment'); grade_update('mod/workshop', $workshop->course, 'mod', 'workshop', $workshop->id, 0, null, ['reset' => true]); grade_update('mod/workshop', $workshop->course, 'mod', 'workshop', $workshop->id, 1, null, ['reset' => true]); \core_plagiarism\privacy\provider::delete_plagiarism_for_context($context); }
[ "public", "static", "function", "delete_data_for_all_users_in_context", "(", "\\", "context", "$", "context", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/gradelib.php'", ")", ";", "if", "(", "$", "context", "->", "contextlevel", "!=", "CONTEXT_MODULE", ")", "{", "return", ";", "}", "$", "cm", "=", "get_coursemodule_from_id", "(", "'workshop'", ",", "$", "context", "->", "instanceid", ",", "0", ",", "false", ",", "IGNORE_MISSING", ")", ";", "if", "(", "!", "$", "cm", ")", "{", "// Probably some kind of expired context.", "return", ";", "}", "$", "workshop", "=", "$", "DB", "->", "get_record", "(", "'workshop'", ",", "[", "'id'", "=>", "$", "cm", "->", "instance", "]", ",", "'id, course'", ",", "MUST_EXIST", ")", ";", "$", "submissions", "=", "$", "DB", "->", "get_records", "(", "'workshop_submissions'", ",", "[", "'workshopid'", "=>", "$", "workshop", "->", "id", "]", ",", "''", ",", "'id'", ")", ";", "$", "assessments", "=", "$", "DB", "->", "get_records_list", "(", "'workshop_assessments'", ",", "'submissionid'", ",", "array_keys", "(", "$", "submissions", ")", ",", "''", ",", "'id'", ")", ";", "$", "DB", "->", "delete_records", "(", "'workshop_aggregations'", ",", "[", "'workshopid'", "=>", "$", "workshop", "->", "id", "]", ")", ";", "$", "DB", "->", "delete_records_list", "(", "'workshop_grades'", ",", "'assessmentid'", ",", "array_keys", "(", "$", "assessments", ")", ")", ";", "$", "DB", "->", "delete_records_list", "(", "'workshop_assessments'", ",", "'id'", ",", "array_keys", "(", "$", "assessments", ")", ")", ";", "$", "DB", "->", "delete_records_list", "(", "'workshop_submissions'", ",", "'id'", ",", "array_keys", "(", "$", "submissions", ")", ")", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "fs", "->", "delete_area_files", "(", "$", "context", "->", "id", ",", "'mod_workshop'", ",", "'submission_content'", ")", ";", "$", "fs", "->", "delete_area_files", "(", "$", "context", "->", "id", ",", "'mod_workshop'", ",", "'submission_attachment'", ")", ";", "$", "fs", "->", "delete_area_files", "(", "$", "context", "->", "id", ",", "'mod_workshop'", ",", "'overallfeedback_content'", ")", ";", "$", "fs", "->", "delete_area_files", "(", "$", "context", "->", "id", ",", "'mod_workshop'", ",", "'overallfeedback_attachment'", ")", ";", "grade_update", "(", "'mod/workshop'", ",", "$", "workshop", "->", "course", ",", "'mod'", ",", "'workshop'", ",", "$", "workshop", "->", "id", ",", "0", ",", "null", ",", "[", "'reset'", "=>", "true", "]", ")", ";", "grade_update", "(", "'mod/workshop'", ",", "$", "workshop", "->", "course", ",", "'mod'", ",", "'workshop'", ",", "$", "workshop", "->", "id", ",", "1", ",", "null", ",", "[", "'reset'", "=>", "true", "]", ")", ";", "\\", "core_plagiarism", "\\", "privacy", "\\", "provider", "::", "delete_plagiarism_for_context", "(", "$", "context", ")", ";", "}" ]
Delete personal data for all users in the context. @param context $context Context to delete personal data from.
[ "Delete", "personal", "data", "for", "all", "users", "in", "the", "context", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/classes/privacy/provider.php#L572-L607
213,102
moodle/moodle
auth/cas/CAS/CAS/Request/CurlMultiRequest.php
CAS_Request_CurlMultiRequest.addRequest
public function addRequest (CAS_Request_RequestInterface $request) { if ($this->_sent) { throw new CAS_OutOfSequenceException( 'Request has already been sent cannot '.__METHOD__ ); } if (!$request instanceof CAS_Request_CurlRequest) { throw new CAS_InvalidArgumentException( 'As a CAS_Request_CurlMultiRequest, I can only work with CAS_Request_CurlRequest objects.' ); } $this->_requests[] = $request; }
php
public function addRequest (CAS_Request_RequestInterface $request) { if ($this->_sent) { throw new CAS_OutOfSequenceException( 'Request has already been sent cannot '.__METHOD__ ); } if (!$request instanceof CAS_Request_CurlRequest) { throw new CAS_InvalidArgumentException( 'As a CAS_Request_CurlMultiRequest, I can only work with CAS_Request_CurlRequest objects.' ); } $this->_requests[] = $request; }
[ "public", "function", "addRequest", "(", "CAS_Request_RequestInterface", "$", "request", ")", "{", "if", "(", "$", "this", "->", "_sent", ")", "{", "throw", "new", "CAS_OutOfSequenceException", "(", "'Request has already been sent cannot '", ".", "__METHOD__", ")", ";", "}", "if", "(", "!", "$", "request", "instanceof", "CAS_Request_CurlRequest", ")", "{", "throw", "new", "CAS_InvalidArgumentException", "(", "'As a CAS_Request_CurlMultiRequest, I can only work with CAS_Request_CurlRequest objects.'", ")", ";", "}", "$", "this", "->", "_requests", "[", "]", "=", "$", "request", ";", "}" ]
Add a new Request to this batch. Note, implementations will likely restrict requests to their own concrete class hierarchy. @param CAS_Request_RequestInterface $request reqest to add @return void @throws CAS_OutOfSequenceException If called after the Request has been sent. @throws CAS_InvalidArgumentException If passed a Request of the wrong implmentation.
[ "Add", "a", "new", "Request", "to", "this", "batch", ".", "Note", "implementations", "will", "likely", "restrict", "requests", "to", "their", "own", "concrete", "class", "hierarchy", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Request/CurlMultiRequest.php#L64-L78
213,103
moodle/moodle
auth/cas/CAS/CAS/Request/CurlMultiRequest.php
CAS_Request_CurlMultiRequest.send
public function send () { if ($this->_sent) { throw new CAS_OutOfSequenceException( 'Request has already been sent cannot send again.' ); } if (!count($this->_requests)) { throw new CAS_OutOfSequenceException( 'At least one request must be added via addRequest() before the multi-request can be sent.' ); } $this->_sent = true; // Initialize our handles and configure all requests. $handles = array(); $multiHandle = curl_multi_init(); foreach ($this->_requests as $i => $request) { $handle = $request->initAndConfigure(); curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); $handles[$i] = $handle; curl_multi_add_handle($multiHandle, $handle); } // Execute the requests in parallel. do { curl_multi_exec($multiHandle, $running); } while ($running > 0); // Populate all of the responses or errors back into the request objects. foreach ($this->_requests as $i => $request) { $buf = curl_multi_getcontent($handles[$i]); $request->_storeResponseBody($buf); curl_multi_remove_handle($multiHandle, $handles[$i]); curl_close($handles[$i]); } curl_multi_close($multiHandle); }
php
public function send () { if ($this->_sent) { throw new CAS_OutOfSequenceException( 'Request has already been sent cannot send again.' ); } if (!count($this->_requests)) { throw new CAS_OutOfSequenceException( 'At least one request must be added via addRequest() before the multi-request can be sent.' ); } $this->_sent = true; // Initialize our handles and configure all requests. $handles = array(); $multiHandle = curl_multi_init(); foreach ($this->_requests as $i => $request) { $handle = $request->initAndConfigure(); curl_setopt($handle, CURLOPT_RETURNTRANSFER, true); $handles[$i] = $handle; curl_multi_add_handle($multiHandle, $handle); } // Execute the requests in parallel. do { curl_multi_exec($multiHandle, $running); } while ($running > 0); // Populate all of the responses or errors back into the request objects. foreach ($this->_requests as $i => $request) { $buf = curl_multi_getcontent($handles[$i]); $request->_storeResponseBody($buf); curl_multi_remove_handle($multiHandle, $handles[$i]); curl_close($handles[$i]); } curl_multi_close($multiHandle); }
[ "public", "function", "send", "(", ")", "{", "if", "(", "$", "this", "->", "_sent", ")", "{", "throw", "new", "CAS_OutOfSequenceException", "(", "'Request has already been sent cannot send again.'", ")", ";", "}", "if", "(", "!", "count", "(", "$", "this", "->", "_requests", ")", ")", "{", "throw", "new", "CAS_OutOfSequenceException", "(", "'At least one request must be added via addRequest() before the multi-request can be sent.'", ")", ";", "}", "$", "this", "->", "_sent", "=", "true", ";", "// Initialize our handles and configure all requests.", "$", "handles", "=", "array", "(", ")", ";", "$", "multiHandle", "=", "curl_multi_init", "(", ")", ";", "foreach", "(", "$", "this", "->", "_requests", "as", "$", "i", "=>", "$", "request", ")", "{", "$", "handle", "=", "$", "request", "->", "initAndConfigure", "(", ")", ";", "curl_setopt", "(", "$", "handle", ",", "CURLOPT_RETURNTRANSFER", ",", "true", ")", ";", "$", "handles", "[", "$", "i", "]", "=", "$", "handle", ";", "curl_multi_add_handle", "(", "$", "multiHandle", ",", "$", "handle", ")", ";", "}", "// Execute the requests in parallel.", "do", "{", "curl_multi_exec", "(", "$", "multiHandle", ",", "$", "running", ")", ";", "}", "while", "(", "$", "running", ">", "0", ")", ";", "// Populate all of the responses or errors back into the request objects.", "foreach", "(", "$", "this", "->", "_requests", "as", "$", "i", "=>", "$", "request", ")", "{", "$", "buf", "=", "curl_multi_getcontent", "(", "$", "handles", "[", "$", "i", "]", ")", ";", "$", "request", "->", "_storeResponseBody", "(", "$", "buf", ")", ";", "curl_multi_remove_handle", "(", "$", "multiHandle", ",", "$", "handles", "[", "$", "i", "]", ")", ";", "curl_close", "(", "$", "handles", "[", "$", "i", "]", ")", ";", "}", "curl_multi_close", "(", "$", "multiHandle", ")", ";", "}" ]
Perform the request. After sending, all requests will have their responses poulated. @return bool TRUE on success, FALSE on failure. @throws CAS_OutOfSequenceException If called multiple times.
[ "Perform", "the", "request", ".", "After", "sending", "all", "requests", "will", "have", "their", "responses", "poulated", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/cas/CAS/CAS/Request/CurlMultiRequest.php#L106-L145
213,104
moodle/moodle
blog/locallib.php
blog_entry.get_attachments
public function get_attachments() { global $CFG; require_once($CFG->libdir.'/filelib.php'); $syscontext = context_system::instance(); $fs = get_file_storage(); $files = $fs->get_area_files($syscontext->id, 'blog', 'attachment', $this->id); // Adding a blog_entry_attachment for each non-directory file. $attachments = array(); foreach ($files as $file) { if ($file->is_directory()) { continue; } $attachments[] = new blog_entry_attachment($file, $this->id); } return $attachments; }
php
public function get_attachments() { global $CFG; require_once($CFG->libdir.'/filelib.php'); $syscontext = context_system::instance(); $fs = get_file_storage(); $files = $fs->get_area_files($syscontext->id, 'blog', 'attachment', $this->id); // Adding a blog_entry_attachment for each non-directory file. $attachments = array(); foreach ($files as $file) { if ($file->is_directory()) { continue; } $attachments[] = new blog_entry_attachment($file, $this->id); } return $attachments; }
[ "public", "function", "get_attachments", "(", ")", "{", "global", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/filelib.php'", ")", ";", "$", "syscontext", "=", "context_system", "::", "instance", "(", ")", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "files", "=", "$", "fs", "->", "get_area_files", "(", "$", "syscontext", "->", "id", ",", "'blog'", ",", "'attachment'", ",", "$", "this", "->", "id", ")", ";", "// Adding a blog_entry_attachment for each non-directory file.", "$", "attachments", "=", "array", "(", ")", ";", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "if", "(", "$", "file", "->", "is_directory", "(", ")", ")", "{", "continue", ";", "}", "$", "attachments", "[", "]", "=", "new", "blog_entry_attachment", "(", "$", "file", ",", "$", "this", "->", "id", ")", ";", "}", "return", "$", "attachments", ";", "}" ]
Gets the entry attachments list @return array List of blog_entry_attachment instances
[ "Gets", "the", "entry", "attachments", "list" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blog/locallib.php#L209-L230
213,105
moodle/moodle
blog/locallib.php
blog_entry.edit
public function edit($params=array(), $form=null, $summaryoptions=array(), $attachmentoptions=array()) { global $CFG, $DB; $sitecontext = context_system::instance(); $entry = $this; $this->form = $form; foreach ($params as $var => $val) { $entry->$var = $val; } $entry = file_postupdate_standard_editor($entry, 'summary', $summaryoptions, $sitecontext, 'blog', 'post', $entry->id); $entry = file_postupdate_standard_filemanager($entry, 'attachment', $attachmentoptions, $sitecontext, 'blog', 'attachment', $entry->id); if (!empty($CFG->useblogassociations)) { $entry->add_associations(); } $entry->lastmodified = time(); // Update record. $DB->update_record('post', $entry); core_tag_tag::set_item_tags('core', 'post', $entry->id, context_user::instance($this->userid), $entry->tags); $event = \core\event\blog_entry_updated::create(array( 'objectid' => $entry->id, 'relateduserid' => $entry->userid )); $event->set_blog_entry($entry); $event->trigger(); }
php
public function edit($params=array(), $form=null, $summaryoptions=array(), $attachmentoptions=array()) { global $CFG, $DB; $sitecontext = context_system::instance(); $entry = $this; $this->form = $form; foreach ($params as $var => $val) { $entry->$var = $val; } $entry = file_postupdate_standard_editor($entry, 'summary', $summaryoptions, $sitecontext, 'blog', 'post', $entry->id); $entry = file_postupdate_standard_filemanager($entry, 'attachment', $attachmentoptions, $sitecontext, 'blog', 'attachment', $entry->id); if (!empty($CFG->useblogassociations)) { $entry->add_associations(); } $entry->lastmodified = time(); // Update record. $DB->update_record('post', $entry); core_tag_tag::set_item_tags('core', 'post', $entry->id, context_user::instance($this->userid), $entry->tags); $event = \core\event\blog_entry_updated::create(array( 'objectid' => $entry->id, 'relateduserid' => $entry->userid )); $event->set_blog_entry($entry); $event->trigger(); }
[ "public", "function", "edit", "(", "$", "params", "=", "array", "(", ")", ",", "$", "form", "=", "null", ",", "$", "summaryoptions", "=", "array", "(", ")", ",", "$", "attachmentoptions", "=", "array", "(", ")", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "$", "sitecontext", "=", "context_system", "::", "instance", "(", ")", ";", "$", "entry", "=", "$", "this", ";", "$", "this", "->", "form", "=", "$", "form", ";", "foreach", "(", "$", "params", "as", "$", "var", "=>", "$", "val", ")", "{", "$", "entry", "->", "$", "var", "=", "$", "val", ";", "}", "$", "entry", "=", "file_postupdate_standard_editor", "(", "$", "entry", ",", "'summary'", ",", "$", "summaryoptions", ",", "$", "sitecontext", ",", "'blog'", ",", "'post'", ",", "$", "entry", "->", "id", ")", ";", "$", "entry", "=", "file_postupdate_standard_filemanager", "(", "$", "entry", ",", "'attachment'", ",", "$", "attachmentoptions", ",", "$", "sitecontext", ",", "'blog'", ",", "'attachment'", ",", "$", "entry", "->", "id", ")", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "useblogassociations", ")", ")", "{", "$", "entry", "->", "add_associations", "(", ")", ";", "}", "$", "entry", "->", "lastmodified", "=", "time", "(", ")", ";", "// Update record.", "$", "DB", "->", "update_record", "(", "'post'", ",", "$", "entry", ")", ";", "core_tag_tag", "::", "set_item_tags", "(", "'core'", ",", "'post'", ",", "$", "entry", "->", "id", ",", "context_user", "::", "instance", "(", "$", "this", "->", "userid", ")", ",", "$", "entry", "->", "tags", ")", ";", "$", "event", "=", "\\", "core", "\\", "event", "\\", "blog_entry_updated", "::", "create", "(", "array", "(", "'objectid'", "=>", "$", "entry", "->", "id", ",", "'relateduserid'", "=>", "$", "entry", "->", "userid", ")", ")", ";", "$", "event", "->", "set_blog_entry", "(", "$", "entry", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "}" ]
Updates this entry in the database. Access control checks must be done by calling code. @param array $params Entry parameters. @param moodleform $form Used for attachments. @param array $summaryoptions Summary options. @param array $attachmentoptions Attachment options. @return void
[ "Updates", "this", "entry", "in", "the", "database", ".", "Access", "control", "checks", "must", "be", "done", "by", "calling", "code", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blog/locallib.php#L284-L320
213,106
moodle/moodle
blog/locallib.php
blog_entry.delete
public function delete() { global $DB; $this->delete_attachments(); $this->remove_associations(); // Get record to pass onto the event. $record = $DB->get_record('post', array('id' => $this->id)); $DB->delete_records('post', array('id' => $this->id)); core_tag_tag::remove_all_item_tags('core', 'post', $this->id); $event = \core\event\blog_entry_deleted::create(array( 'objectid' => $this->id, 'relateduserid' => $this->userid )); $event->add_record_snapshot("post", $record); $event->set_blog_entry($this); $event->trigger(); }
php
public function delete() { global $DB; $this->delete_attachments(); $this->remove_associations(); // Get record to pass onto the event. $record = $DB->get_record('post', array('id' => $this->id)); $DB->delete_records('post', array('id' => $this->id)); core_tag_tag::remove_all_item_tags('core', 'post', $this->id); $event = \core\event\blog_entry_deleted::create(array( 'objectid' => $this->id, 'relateduserid' => $this->userid )); $event->add_record_snapshot("post", $record); $event->set_blog_entry($this); $event->trigger(); }
[ "public", "function", "delete", "(", ")", "{", "global", "$", "DB", ";", "$", "this", "->", "delete_attachments", "(", ")", ";", "$", "this", "->", "remove_associations", "(", ")", ";", "// Get record to pass onto the event.", "$", "record", "=", "$", "DB", "->", "get_record", "(", "'post'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "id", ")", ")", ";", "$", "DB", "->", "delete_records", "(", "'post'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "id", ")", ")", ";", "core_tag_tag", "::", "remove_all_item_tags", "(", "'core'", ",", "'post'", ",", "$", "this", "->", "id", ")", ";", "$", "event", "=", "\\", "core", "\\", "event", "\\", "blog_entry_deleted", "::", "create", "(", "array", "(", "'objectid'", "=>", "$", "this", "->", "id", ",", "'relateduserid'", "=>", "$", "this", "->", "userid", ")", ")", ";", "$", "event", "->", "add_record_snapshot", "(", "\"post\"", ",", "$", "record", ")", ";", "$", "event", "->", "set_blog_entry", "(", "$", "this", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "}" ]
Deletes this entry from the database. Access control checks must be done by calling code. @return void
[ "Deletes", "this", "entry", "from", "the", "database", ".", "Access", "control", "checks", "must", "be", "done", "by", "calling", "code", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blog/locallib.php#L327-L345
213,107
moodle/moodle
blog/locallib.php
blog_entry.add_associations
public function add_associations($unused = null) { if ($unused !== null) { debugging('Illegal argument used in blog_entry->add_associations()', DEBUG_DEVELOPER); } $this->remove_associations(); if (!empty($this->courseassoc)) { $this->add_association($this->courseassoc); } if (!empty($this->modassoc)) { $this->add_association($this->modassoc); } }
php
public function add_associations($unused = null) { if ($unused !== null) { debugging('Illegal argument used in blog_entry->add_associations()', DEBUG_DEVELOPER); } $this->remove_associations(); if (!empty($this->courseassoc)) { $this->add_association($this->courseassoc); } if (!empty($this->modassoc)) { $this->add_association($this->modassoc); } }
[ "public", "function", "add_associations", "(", "$", "unused", "=", "null", ")", "{", "if", "(", "$", "unused", "!==", "null", ")", "{", "debugging", "(", "'Illegal argument used in blog_entry->add_associations()'", ",", "DEBUG_DEVELOPER", ")", ";", "}", "$", "this", "->", "remove_associations", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "courseassoc", ")", ")", "{", "$", "this", "->", "add_association", "(", "$", "this", "->", "courseassoc", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "modassoc", ")", ")", "{", "$", "this", "->", "add_association", "(", "$", "this", "->", "modassoc", ")", ";", "}", "}" ]
Function to add all context associations to an entry. @param string $unused This does nothing, do not use it.
[ "Function", "to", "add", "all", "context", "associations", "to", "an", "entry", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blog/locallib.php#L352-L367
213,108
moodle/moodle
blog/locallib.php
blog_entry.add_association
public function add_association($contextid, $unused = null) { global $DB; if ($unused !== null) { debugging('Illegal argument used in blog_entry->add_association()', DEBUG_DEVELOPER); } $assocobject = new StdClass; $assocobject->contextid = $contextid; $assocobject->blogid = $this->id; $id = $DB->insert_record('blog_association', $assocobject); // Trigger an association created event. $context = context::instance_by_id($contextid); $eventparam = array( 'objectid' => $id, 'other' => array('associateid' => $context->instanceid, 'subject' => $this->subject, 'blogid' => $this->id), 'relateduserid' => $this->userid ); if ($context->contextlevel == CONTEXT_COURSE) { $eventparam['other']['associatetype'] = 'course'; } else if ($context->contextlevel == CONTEXT_MODULE) { $eventparam['other']['associatetype'] = 'coursemodule'; } $event = \core\event\blog_association_created::create($eventparam); $event->trigger(); }
php
public function add_association($contextid, $unused = null) { global $DB; if ($unused !== null) { debugging('Illegal argument used in blog_entry->add_association()', DEBUG_DEVELOPER); } $assocobject = new StdClass; $assocobject->contextid = $contextid; $assocobject->blogid = $this->id; $id = $DB->insert_record('blog_association', $assocobject); // Trigger an association created event. $context = context::instance_by_id($contextid); $eventparam = array( 'objectid' => $id, 'other' => array('associateid' => $context->instanceid, 'subject' => $this->subject, 'blogid' => $this->id), 'relateduserid' => $this->userid ); if ($context->contextlevel == CONTEXT_COURSE) { $eventparam['other']['associatetype'] = 'course'; } else if ($context->contextlevel == CONTEXT_MODULE) { $eventparam['other']['associatetype'] = 'coursemodule'; } $event = \core\event\blog_association_created::create($eventparam); $event->trigger(); }
[ "public", "function", "add_association", "(", "$", "contextid", ",", "$", "unused", "=", "null", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "unused", "!==", "null", ")", "{", "debugging", "(", "'Illegal argument used in blog_entry->add_association()'", ",", "DEBUG_DEVELOPER", ")", ";", "}", "$", "assocobject", "=", "new", "StdClass", ";", "$", "assocobject", "->", "contextid", "=", "$", "contextid", ";", "$", "assocobject", "->", "blogid", "=", "$", "this", "->", "id", ";", "$", "id", "=", "$", "DB", "->", "insert_record", "(", "'blog_association'", ",", "$", "assocobject", ")", ";", "// Trigger an association created event.", "$", "context", "=", "context", "::", "instance_by_id", "(", "$", "contextid", ")", ";", "$", "eventparam", "=", "array", "(", "'objectid'", "=>", "$", "id", ",", "'other'", "=>", "array", "(", "'associateid'", "=>", "$", "context", "->", "instanceid", ",", "'subject'", "=>", "$", "this", "->", "subject", ",", "'blogid'", "=>", "$", "this", "->", "id", ")", ",", "'relateduserid'", "=>", "$", "this", "->", "userid", ")", ";", "if", "(", "$", "context", "->", "contextlevel", "==", "CONTEXT_COURSE", ")", "{", "$", "eventparam", "[", "'other'", "]", "[", "'associatetype'", "]", "=", "'course'", ";", "}", "else", "if", "(", "$", "context", "->", "contextlevel", "==", "CONTEXT_MODULE", ")", "{", "$", "eventparam", "[", "'other'", "]", "[", "'associatetype'", "]", "=", "'coursemodule'", ";", "}", "$", "event", "=", "\\", "core", "\\", "event", "\\", "blog_association_created", "::", "create", "(", "$", "eventparam", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "}" ]
Add a single association for a blog entry @param int $contextid - id of context to associate with the blog entry. @param string $unused This does nothing, do not use it.
[ "Add", "a", "single", "association", "for", "a", "blog", "entry" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blog/locallib.php#L375-L402
213,109
moodle/moodle
blog/locallib.php
blog_entry.remove_associations
public function remove_associations() { global $DB; $associations = $DB->get_records('blog_association', array('blogid' => $this->id)); foreach ($associations as $association) { // Trigger an association deleted event. $context = context::instance_by_id($association->contextid); $eventparam = array( 'objectid' => $this->id, 'other' => array('subject' => $this->subject, 'blogid' => $this->id), 'relateduserid' => $this->userid ); $event = \core\event\blog_association_deleted::create($eventparam); $event->add_record_snapshot('blog_association', $association); $event->trigger(); // Now remove the association. $DB->delete_records('blog_association', array('id' => $association->id)); } }
php
public function remove_associations() { global $DB; $associations = $DB->get_records('blog_association', array('blogid' => $this->id)); foreach ($associations as $association) { // Trigger an association deleted event. $context = context::instance_by_id($association->contextid); $eventparam = array( 'objectid' => $this->id, 'other' => array('subject' => $this->subject, 'blogid' => $this->id), 'relateduserid' => $this->userid ); $event = \core\event\blog_association_deleted::create($eventparam); $event->add_record_snapshot('blog_association', $association); $event->trigger(); // Now remove the association. $DB->delete_records('blog_association', array('id' => $association->id)); } }
[ "public", "function", "remove_associations", "(", ")", "{", "global", "$", "DB", ";", "$", "associations", "=", "$", "DB", "->", "get_records", "(", "'blog_association'", ",", "array", "(", "'blogid'", "=>", "$", "this", "->", "id", ")", ")", ";", "foreach", "(", "$", "associations", "as", "$", "association", ")", "{", "// Trigger an association deleted event.", "$", "context", "=", "context", "::", "instance_by_id", "(", "$", "association", "->", "contextid", ")", ";", "$", "eventparam", "=", "array", "(", "'objectid'", "=>", "$", "this", "->", "id", ",", "'other'", "=>", "array", "(", "'subject'", "=>", "$", "this", "->", "subject", ",", "'blogid'", "=>", "$", "this", "->", "id", ")", ",", "'relateduserid'", "=>", "$", "this", "->", "userid", ")", ";", "$", "event", "=", "\\", "core", "\\", "event", "\\", "blog_association_deleted", "::", "create", "(", "$", "eventparam", ")", ";", "$", "event", "->", "add_record_snapshot", "(", "'blog_association'", ",", "$", "association", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "// Now remove the association.", "$", "DB", "->", "delete_records", "(", "'blog_association'", ",", "array", "(", "'id'", "=>", "$", "association", "->", "id", ")", ")", ";", "}", "}" ]
remove all associations for a blog entry @return void
[ "remove", "all", "associations", "for", "a", "blog", "entry" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blog/locallib.php#L409-L429
213,110
moodle/moodle
blog/locallib.php
blog_entry.delete_attachments
public function delete_attachments() { $fs = get_file_storage(); $fs->delete_area_files(SYSCONTEXTID, 'blog', 'attachment', $this->id); $fs->delete_area_files(SYSCONTEXTID, 'blog', 'post', $this->id); }
php
public function delete_attachments() { $fs = get_file_storage(); $fs->delete_area_files(SYSCONTEXTID, 'blog', 'attachment', $this->id); $fs->delete_area_files(SYSCONTEXTID, 'blog', 'post', $this->id); }
[ "public", "function", "delete_attachments", "(", ")", "{", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "fs", "->", "delete_area_files", "(", "SYSCONTEXTID", ",", "'blog'", ",", "'attachment'", ",", "$", "this", "->", "id", ")", ";", "$", "fs", "->", "delete_area_files", "(", "SYSCONTEXTID", ",", "'blog'", ",", "'post'", ",", "$", "this", "->", "id", ")", ";", "}" ]
Deletes all the user files in the attachments area for an entry @return void
[ "Deletes", "all", "the", "user", "files", "in", "the", "attachments", "area", "for", "an", "entry" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blog/locallib.php#L436-L440
213,111
moodle/moodle
blog/locallib.php
blog_entry.get_applicable_publish_states
public static function get_applicable_publish_states() { global $CFG; $options = array(); // Everyone gets draft access. if ($CFG->bloglevel >= BLOG_USER_LEVEL) { $options['draft'] = get_string('publishtonoone', 'blog'); } if ($CFG->bloglevel > BLOG_USER_LEVEL) { $options['site'] = get_string('publishtosite', 'blog'); } if ($CFG->bloglevel >= BLOG_GLOBAL_LEVEL) { $options['public'] = get_string('publishtoworld', 'blog'); } return $options; }
php
public static function get_applicable_publish_states() { global $CFG; $options = array(); // Everyone gets draft access. if ($CFG->bloglevel >= BLOG_USER_LEVEL) { $options['draft'] = get_string('publishtonoone', 'blog'); } if ($CFG->bloglevel > BLOG_USER_LEVEL) { $options['site'] = get_string('publishtosite', 'blog'); } if ($CFG->bloglevel >= BLOG_GLOBAL_LEVEL) { $options['public'] = get_string('publishtoworld', 'blog'); } return $options; }
[ "public", "static", "function", "get_applicable_publish_states", "(", ")", "{", "global", "$", "CFG", ";", "$", "options", "=", "array", "(", ")", ";", "// Everyone gets draft access.", "if", "(", "$", "CFG", "->", "bloglevel", ">=", "BLOG_USER_LEVEL", ")", "{", "$", "options", "[", "'draft'", "]", "=", "get_string", "(", "'publishtonoone'", ",", "'blog'", ")", ";", "}", "if", "(", "$", "CFG", "->", "bloglevel", ">", "BLOG_USER_LEVEL", ")", "{", "$", "options", "[", "'site'", "]", "=", "get_string", "(", "'publishtosite'", ",", "'blog'", ")", ";", "}", "if", "(", "$", "CFG", "->", "bloglevel", ">=", "BLOG_GLOBAL_LEVEL", ")", "{", "$", "options", "[", "'public'", "]", "=", "get_string", "(", "'publishtoworld'", ",", "'blog'", ")", ";", "}", "return", "$", "options", ";", "}" ]
Use this function to retrieve a list of publish states available for the currently logged in user. @return array This function returns an array ideal for sending to moodles' choose_from_menu function.
[ "Use", "this", "function", "to", "retrieve", "a", "list", "of", "publish", "states", "available", "for", "the", "currently", "logged", "in", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blog/locallib.php#L534-L552
213,112
moodle/moodle
blog/locallib.php
blog_listing.get_entries
public function get_entries($start=0, $limit=10) { global $DB; if ($this->entries === null) { if ($sqlarray = $this->get_entry_fetch_sql(false, 'created DESC')) { $this->entries = $DB->get_records_sql($sqlarray['sql'], $sqlarray['params'], $start, $limit); if (!$start && count($this->entries) < $limit) { $this->totalentries = count($this->entries); } } else { return false; } } return $this->entries; }
php
public function get_entries($start=0, $limit=10) { global $DB; if ($this->entries === null) { if ($sqlarray = $this->get_entry_fetch_sql(false, 'created DESC')) { $this->entries = $DB->get_records_sql($sqlarray['sql'], $sqlarray['params'], $start, $limit); if (!$start && count($this->entries) < $limit) { $this->totalentries = count($this->entries); } } else { return false; } } return $this->entries; }
[ "public", "function", "get_entries", "(", "$", "start", "=", "0", ",", "$", "limit", "=", "10", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "this", "->", "entries", "===", "null", ")", "{", "if", "(", "$", "sqlarray", "=", "$", "this", "->", "get_entry_fetch_sql", "(", "false", ",", "'created DESC'", ")", ")", "{", "$", "this", "->", "entries", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sqlarray", "[", "'sql'", "]", ",", "$", "sqlarray", "[", "'params'", "]", ",", "$", "start", ",", "$", "limit", ")", ";", "if", "(", "!", "$", "start", "&&", "count", "(", "$", "this", "->", "entries", ")", "<", "$", "limit", ")", "{", "$", "this", "->", "totalentries", "=", "count", "(", "$", "this", "->", "entries", ")", ";", "}", "}", "else", "{", "return", "false", ";", "}", "}", "return", "$", "this", "->", "entries", ";", "}" ]
Fetches the array of blog entries. @return array
[ "Fetches", "the", "array", "of", "blog", "entries", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blog/locallib.php#L609-L624
213,113
moodle/moodle
blog/locallib.php
blog_listing.count_entries
public function count_entries() { global $DB; if ($this->totalentries === null) { if ($sqlarray = $this->get_entry_fetch_sql(true)) { $this->totalentries = $DB->count_records_sql($sqlarray['sql'], $sqlarray['params']); } else { $this->totalentries = 0; } } return $this->totalentries; }
php
public function count_entries() { global $DB; if ($this->totalentries === null) { if ($sqlarray = $this->get_entry_fetch_sql(true)) { $this->totalentries = $DB->count_records_sql($sqlarray['sql'], $sqlarray['params']); } else { $this->totalentries = 0; } } return $this->totalentries; }
[ "public", "function", "count_entries", "(", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "this", "->", "totalentries", "===", "null", ")", "{", "if", "(", "$", "sqlarray", "=", "$", "this", "->", "get_entry_fetch_sql", "(", "true", ")", ")", "{", "$", "this", "->", "totalentries", "=", "$", "DB", "->", "count_records_sql", "(", "$", "sqlarray", "[", "'sql'", "]", ",", "$", "sqlarray", "[", "'params'", "]", ")", ";", "}", "else", "{", "$", "this", "->", "totalentries", "=", "0", ";", "}", "}", "return", "$", "this", "->", "totalentries", ";", "}" ]
Finds total number of blog entries @return int
[ "Finds", "total", "number", "of", "blog", "entries" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blog/locallib.php#L631-L641
213,114
moodle/moodle
blog/locallib.php
blog_listing.print_entries
public function print_entries() { global $CFG, $USER, $DB, $OUTPUT, $PAGE; $sitecontext = context_system::instance(); // Blog renderer. $output = $PAGE->get_renderer('blog'); $page = optional_param('blogpage', 0, PARAM_INT); $limit = optional_param('limit', get_user_preferences('blogpagesize', 10), PARAM_INT); $start = $page * $limit; $morelink = '<br />&nbsp;&nbsp;'; $entries = $this->get_entries($start, $limit); $totalentries = $this->count_entries(); $pagingbar = new paging_bar($totalentries, $page, $limit, $this->get_baseurl()); $pagingbar->pagevar = 'blogpage'; $blogheaders = blog_get_headers(); echo $OUTPUT->render($pagingbar); if (has_capability('moodle/blog:create', $sitecontext)) { // The user's blog is enabled and they are viewing their own blog. $userid = optional_param('userid', null, PARAM_INT); if (empty($userid) || (!empty($userid) && $userid == $USER->id)) { $courseid = optional_param('courseid', null, PARAM_INT); $modid = optional_param('modid', null, PARAM_INT); $addurl = new moodle_url("$CFG->wwwroot/blog/edit.php"); $urlparams = array('action' => 'add', 'userid' => $userid, 'courseid' => $courseid, 'groupid' => optional_param('groupid', null, PARAM_INT), 'modid' => $modid, 'tagid' => optional_param('tagid', null, PARAM_INT), 'tag' => optional_param('tag', null, PARAM_INT), 'search' => optional_param('search', null, PARAM_INT)); $urlparams = array_filter($urlparams); $addurl->params($urlparams); $addlink = '<div class="addbloglink">'; $addlink .= '<a href="'.$addurl->out().'">'. $blogheaders['stradd'].'</a>'; $addlink .= '</div>'; echo $addlink; } } if ($entries) { $count = 0; foreach ($entries as $entry) { $blogentry = new blog_entry(null, $entry); // Get the required blog entry data to render it. $blogentry->prepare_render(); echo $output->render($blogentry); $count++; } echo $OUTPUT->render($pagingbar); if (!$count) { print '<br /><div style="text-align:center">'. get_string('noentriesyet', 'blog') .'</div><br />'; } print $morelink.'<br />'."\n"; return; } }
php
public function print_entries() { global $CFG, $USER, $DB, $OUTPUT, $PAGE; $sitecontext = context_system::instance(); // Blog renderer. $output = $PAGE->get_renderer('blog'); $page = optional_param('blogpage', 0, PARAM_INT); $limit = optional_param('limit', get_user_preferences('blogpagesize', 10), PARAM_INT); $start = $page * $limit; $morelink = '<br />&nbsp;&nbsp;'; $entries = $this->get_entries($start, $limit); $totalentries = $this->count_entries(); $pagingbar = new paging_bar($totalentries, $page, $limit, $this->get_baseurl()); $pagingbar->pagevar = 'blogpage'; $blogheaders = blog_get_headers(); echo $OUTPUT->render($pagingbar); if (has_capability('moodle/blog:create', $sitecontext)) { // The user's blog is enabled and they are viewing their own blog. $userid = optional_param('userid', null, PARAM_INT); if (empty($userid) || (!empty($userid) && $userid == $USER->id)) { $courseid = optional_param('courseid', null, PARAM_INT); $modid = optional_param('modid', null, PARAM_INT); $addurl = new moodle_url("$CFG->wwwroot/blog/edit.php"); $urlparams = array('action' => 'add', 'userid' => $userid, 'courseid' => $courseid, 'groupid' => optional_param('groupid', null, PARAM_INT), 'modid' => $modid, 'tagid' => optional_param('tagid', null, PARAM_INT), 'tag' => optional_param('tag', null, PARAM_INT), 'search' => optional_param('search', null, PARAM_INT)); $urlparams = array_filter($urlparams); $addurl->params($urlparams); $addlink = '<div class="addbloglink">'; $addlink .= '<a href="'.$addurl->out().'">'. $blogheaders['stradd'].'</a>'; $addlink .= '</div>'; echo $addlink; } } if ($entries) { $count = 0; foreach ($entries as $entry) { $blogentry = new blog_entry(null, $entry); // Get the required blog entry data to render it. $blogentry->prepare_render(); echo $output->render($blogentry); $count++; } echo $OUTPUT->render($pagingbar); if (!$count) { print '<br /><div style="text-align:center">'. get_string('noentriesyet', 'blog') .'</div><br />'; } print $morelink.'<br />'."\n"; return; } }
[ "public", "function", "print_entries", "(", ")", "{", "global", "$", "CFG", ",", "$", "USER", ",", "$", "DB", ",", "$", "OUTPUT", ",", "$", "PAGE", ";", "$", "sitecontext", "=", "context_system", "::", "instance", "(", ")", ";", "// Blog renderer.", "$", "output", "=", "$", "PAGE", "->", "get_renderer", "(", "'blog'", ")", ";", "$", "page", "=", "optional_param", "(", "'blogpage'", ",", "0", ",", "PARAM_INT", ")", ";", "$", "limit", "=", "optional_param", "(", "'limit'", ",", "get_user_preferences", "(", "'blogpagesize'", ",", "10", ")", ",", "PARAM_INT", ")", ";", "$", "start", "=", "$", "page", "*", "$", "limit", ";", "$", "morelink", "=", "'<br />&nbsp;&nbsp;'", ";", "$", "entries", "=", "$", "this", "->", "get_entries", "(", "$", "start", ",", "$", "limit", ")", ";", "$", "totalentries", "=", "$", "this", "->", "count_entries", "(", ")", ";", "$", "pagingbar", "=", "new", "paging_bar", "(", "$", "totalentries", ",", "$", "page", ",", "$", "limit", ",", "$", "this", "->", "get_baseurl", "(", ")", ")", ";", "$", "pagingbar", "->", "pagevar", "=", "'blogpage'", ";", "$", "blogheaders", "=", "blog_get_headers", "(", ")", ";", "echo", "$", "OUTPUT", "->", "render", "(", "$", "pagingbar", ")", ";", "if", "(", "has_capability", "(", "'moodle/blog:create'", ",", "$", "sitecontext", ")", ")", "{", "// The user's blog is enabled and they are viewing their own blog.", "$", "userid", "=", "optional_param", "(", "'userid'", ",", "null", ",", "PARAM_INT", ")", ";", "if", "(", "empty", "(", "$", "userid", ")", "||", "(", "!", "empty", "(", "$", "userid", ")", "&&", "$", "userid", "==", "$", "USER", "->", "id", ")", ")", "{", "$", "courseid", "=", "optional_param", "(", "'courseid'", ",", "null", ",", "PARAM_INT", ")", ";", "$", "modid", "=", "optional_param", "(", "'modid'", ",", "null", ",", "PARAM_INT", ")", ";", "$", "addurl", "=", "new", "moodle_url", "(", "\"$CFG->wwwroot/blog/edit.php\"", ")", ";", "$", "urlparams", "=", "array", "(", "'action'", "=>", "'add'", ",", "'userid'", "=>", "$", "userid", ",", "'courseid'", "=>", "$", "courseid", ",", "'groupid'", "=>", "optional_param", "(", "'groupid'", ",", "null", ",", "PARAM_INT", ")", ",", "'modid'", "=>", "$", "modid", ",", "'tagid'", "=>", "optional_param", "(", "'tagid'", ",", "null", ",", "PARAM_INT", ")", ",", "'tag'", "=>", "optional_param", "(", "'tag'", ",", "null", ",", "PARAM_INT", ")", ",", "'search'", "=>", "optional_param", "(", "'search'", ",", "null", ",", "PARAM_INT", ")", ")", ";", "$", "urlparams", "=", "array_filter", "(", "$", "urlparams", ")", ";", "$", "addurl", "->", "params", "(", "$", "urlparams", ")", ";", "$", "addlink", "=", "'<div class=\"addbloglink\">'", ";", "$", "addlink", ".=", "'<a href=\"'", ".", "$", "addurl", "->", "out", "(", ")", ".", "'\">'", ".", "$", "blogheaders", "[", "'stradd'", "]", ".", "'</a>'", ";", "$", "addlink", ".=", "'</div>'", ";", "echo", "$", "addlink", ";", "}", "}", "if", "(", "$", "entries", ")", "{", "$", "count", "=", "0", ";", "foreach", "(", "$", "entries", "as", "$", "entry", ")", "{", "$", "blogentry", "=", "new", "blog_entry", "(", "null", ",", "$", "entry", ")", ";", "// Get the required blog entry data to render it.", "$", "blogentry", "->", "prepare_render", "(", ")", ";", "echo", "$", "output", "->", "render", "(", "$", "blogentry", ")", ";", "$", "count", "++", ";", "}", "echo", "$", "OUTPUT", "->", "render", "(", "$", "pagingbar", ")", ";", "if", "(", "!", "$", "count", ")", "{", "print", "'<br /><div style=\"text-align:center\">'", ".", "get_string", "(", "'noentriesyet'", ",", "'blog'", ")", ".", "'</div><br />'", ";", "}", "print", "$", "morelink", ".", "'<br />'", ".", "\"\\n\"", ";", "return", ";", "}", "}" ]
Outputs all the blog entries aggregated by this blog listing. @return void
[ "Outputs", "all", "the", "blog", "entries", "aggregated", "by", "this", "blog", "listing", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blog/locallib.php#L718-L789
213,115
moodle/moodle
filter/emoticon/filter.php
filter_emoticon.filter
public function filter($text, array $options = array()) { if (!isset($options['originalformat'])) { // if the format is not specified, we are probably called by {@see format_string()} // in that case, it would be dangerous to replace text with the image because it could // be stripped. therefore, we do nothing return $text; } if (in_array($options['originalformat'], explode(',', get_config('filter_emoticon', 'formats')))) { return $this->replace_emoticons($text); } return $text; }
php
public function filter($text, array $options = array()) { if (!isset($options['originalformat'])) { // if the format is not specified, we are probably called by {@see format_string()} // in that case, it would be dangerous to replace text with the image because it could // be stripped. therefore, we do nothing return $text; } if (in_array($options['originalformat'], explode(',', get_config('filter_emoticon', 'formats')))) { return $this->replace_emoticons($text); } return $text; }
[ "public", "function", "filter", "(", "$", "text", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "if", "(", "!", "isset", "(", "$", "options", "[", "'originalformat'", "]", ")", ")", "{", "// if the format is not specified, we are probably called by {@see format_string()}", "// in that case, it would be dangerous to replace text with the image because it could", "// be stripped. therefore, we do nothing", "return", "$", "text", ";", "}", "if", "(", "in_array", "(", "$", "options", "[", "'originalformat'", "]", ",", "explode", "(", "','", ",", "get_config", "(", "'filter_emoticon'", ",", "'formats'", ")", ")", ")", ")", "{", "return", "$", "this", "->", "replace_emoticons", "(", "$", "text", ")", ";", "}", "return", "$", "text", ";", "}" ]
Apply the filter to the text @see filter_manager::apply_filter_chain() @param string $text to be processed by the text @param array $options filter options @return string text after processing
[ "Apply", "the", "filter", "to", "the", "text" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/filter/emoticon/filter.php#L59-L71
213,116
moodle/moodle
filter/emoticon/filter.php
filter_emoticon.replace_emoticons
protected function replace_emoticons($text) { global $CFG, $OUTPUT, $PAGE; $lang = current_language(); $theme = $PAGE->theme->name; if (!isset(self::$emoticontexts[$lang][$theme]) or !isset(self::$emoticonimgs[$lang][$theme])) { // prepare internal caches $manager = get_emoticon_manager(); $emoticons = $manager->get_emoticons(); self::$emoticontexts[$lang][$theme] = array(); self::$emoticonimgs[$lang][$theme] = array(); foreach ($emoticons as $emoticon) { self::$emoticontexts[$lang][$theme][] = $emoticon->text; self::$emoticonimgs[$lang][$theme][] = $OUTPUT->render($manager->prepare_renderable_emoticon($emoticon)); } unset($emoticons); } if (empty(self::$emoticontexts[$lang][$theme])) { // No emoticons defined, nothing to process here. return $text; } // Detect all zones that we should not handle (including the nested tags). $processing = preg_split('/(<\/?(?:span|script)[^>]*>)/is', $text, 0, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); // Initialize the results. $resulthtml = ""; $exclude = 0; // Define the patterns that mark the start of the forbidden zones. $excludepattern = array('/^<script/is', '/^<span[^>]+class="nolink[^"]*"/is'); // Loop through the fragments. foreach ($processing as $fragment) { // If we are not ignoring, we MUST test if we should. if ($exclude == 0) { foreach ($excludepattern as $exp) { if (preg_match($exp, $fragment)) { $exclude = $exclude + 1; break; } } } if ($exclude > 0) { // If we are ignoring the fragment, then we must check if we may have reached the end of the zone. if (strpos($fragment, '</span') !== false || strpos($fragment, '</script') !== false) { $exclude -= 1; // This is needed because of a double increment at the first element. if ($exclude == 1) { $exclude -= 1; } } else if (strpos($fragment, '<span') !== false || strpos($fragment, '<script') !== false) { // If we find a nested tag we increase the exclusion level. $exclude = $exclude + 1; } } else if (strpos($fragment, '<span') === false || strpos($fragment, '</span') === false) { // This is the meat of the code - this is run every time. // This code only runs for fragments that are not ignored (including the tags themselves). $fragment = str_replace(self::$emoticontexts[$lang][$theme], self::$emoticonimgs[$lang][$theme], $fragment); } $resulthtml .= $fragment; } return $resulthtml; }
php
protected function replace_emoticons($text) { global $CFG, $OUTPUT, $PAGE; $lang = current_language(); $theme = $PAGE->theme->name; if (!isset(self::$emoticontexts[$lang][$theme]) or !isset(self::$emoticonimgs[$lang][$theme])) { // prepare internal caches $manager = get_emoticon_manager(); $emoticons = $manager->get_emoticons(); self::$emoticontexts[$lang][$theme] = array(); self::$emoticonimgs[$lang][$theme] = array(); foreach ($emoticons as $emoticon) { self::$emoticontexts[$lang][$theme][] = $emoticon->text; self::$emoticonimgs[$lang][$theme][] = $OUTPUT->render($manager->prepare_renderable_emoticon($emoticon)); } unset($emoticons); } if (empty(self::$emoticontexts[$lang][$theme])) { // No emoticons defined, nothing to process here. return $text; } // Detect all zones that we should not handle (including the nested tags). $processing = preg_split('/(<\/?(?:span|script)[^>]*>)/is', $text, 0, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); // Initialize the results. $resulthtml = ""; $exclude = 0; // Define the patterns that mark the start of the forbidden zones. $excludepattern = array('/^<script/is', '/^<span[^>]+class="nolink[^"]*"/is'); // Loop through the fragments. foreach ($processing as $fragment) { // If we are not ignoring, we MUST test if we should. if ($exclude == 0) { foreach ($excludepattern as $exp) { if (preg_match($exp, $fragment)) { $exclude = $exclude + 1; break; } } } if ($exclude > 0) { // If we are ignoring the fragment, then we must check if we may have reached the end of the zone. if (strpos($fragment, '</span') !== false || strpos($fragment, '</script') !== false) { $exclude -= 1; // This is needed because of a double increment at the first element. if ($exclude == 1) { $exclude -= 1; } } else if (strpos($fragment, '<span') !== false || strpos($fragment, '<script') !== false) { // If we find a nested tag we increase the exclusion level. $exclude = $exclude + 1; } } else if (strpos($fragment, '<span') === false || strpos($fragment, '</span') === false) { // This is the meat of the code - this is run every time. // This code only runs for fragments that are not ignored (including the tags themselves). $fragment = str_replace(self::$emoticontexts[$lang][$theme], self::$emoticonimgs[$lang][$theme], $fragment); } $resulthtml .= $fragment; } return $resulthtml; }
[ "protected", "function", "replace_emoticons", "(", "$", "text", ")", "{", "global", "$", "CFG", ",", "$", "OUTPUT", ",", "$", "PAGE", ";", "$", "lang", "=", "current_language", "(", ")", ";", "$", "theme", "=", "$", "PAGE", "->", "theme", "->", "name", ";", "if", "(", "!", "isset", "(", "self", "::", "$", "emoticontexts", "[", "$", "lang", "]", "[", "$", "theme", "]", ")", "or", "!", "isset", "(", "self", "::", "$", "emoticonimgs", "[", "$", "lang", "]", "[", "$", "theme", "]", ")", ")", "{", "// prepare internal caches", "$", "manager", "=", "get_emoticon_manager", "(", ")", ";", "$", "emoticons", "=", "$", "manager", "->", "get_emoticons", "(", ")", ";", "self", "::", "$", "emoticontexts", "[", "$", "lang", "]", "[", "$", "theme", "]", "=", "array", "(", ")", ";", "self", "::", "$", "emoticonimgs", "[", "$", "lang", "]", "[", "$", "theme", "]", "=", "array", "(", ")", ";", "foreach", "(", "$", "emoticons", "as", "$", "emoticon", ")", "{", "self", "::", "$", "emoticontexts", "[", "$", "lang", "]", "[", "$", "theme", "]", "[", "]", "=", "$", "emoticon", "->", "text", ";", "self", "::", "$", "emoticonimgs", "[", "$", "lang", "]", "[", "$", "theme", "]", "[", "]", "=", "$", "OUTPUT", "->", "render", "(", "$", "manager", "->", "prepare_renderable_emoticon", "(", "$", "emoticon", ")", ")", ";", "}", "unset", "(", "$", "emoticons", ")", ";", "}", "if", "(", "empty", "(", "self", "::", "$", "emoticontexts", "[", "$", "lang", "]", "[", "$", "theme", "]", ")", ")", "{", "// No emoticons defined, nothing to process here.", "return", "$", "text", ";", "}", "// Detect all zones that we should not handle (including the nested tags).", "$", "processing", "=", "preg_split", "(", "'/(<\\/?(?:span|script)[^>]*>)/is'", ",", "$", "text", ",", "0", ",", "PREG_SPLIT_DELIM_CAPTURE", "|", "PREG_SPLIT_NO_EMPTY", ")", ";", "// Initialize the results.", "$", "resulthtml", "=", "\"\"", ";", "$", "exclude", "=", "0", ";", "// Define the patterns that mark the start of the forbidden zones.", "$", "excludepattern", "=", "array", "(", "'/^<script/is'", ",", "'/^<span[^>]+class=\"nolink[^\"]*\"/is'", ")", ";", "// Loop through the fragments.", "foreach", "(", "$", "processing", "as", "$", "fragment", ")", "{", "// If we are not ignoring, we MUST test if we should.", "if", "(", "$", "exclude", "==", "0", ")", "{", "foreach", "(", "$", "excludepattern", "as", "$", "exp", ")", "{", "if", "(", "preg_match", "(", "$", "exp", ",", "$", "fragment", ")", ")", "{", "$", "exclude", "=", "$", "exclude", "+", "1", ";", "break", ";", "}", "}", "}", "if", "(", "$", "exclude", ">", "0", ")", "{", "// If we are ignoring the fragment, then we must check if we may have reached the end of the zone.", "if", "(", "strpos", "(", "$", "fragment", ",", "'</span'", ")", "!==", "false", "||", "strpos", "(", "$", "fragment", ",", "'</script'", ")", "!==", "false", ")", "{", "$", "exclude", "-=", "1", ";", "// This is needed because of a double increment at the first element.", "if", "(", "$", "exclude", "==", "1", ")", "{", "$", "exclude", "-=", "1", ";", "}", "}", "else", "if", "(", "strpos", "(", "$", "fragment", ",", "'<span'", ")", "!==", "false", "||", "strpos", "(", "$", "fragment", ",", "'<script'", ")", "!==", "false", ")", "{", "// If we find a nested tag we increase the exclusion level.", "$", "exclude", "=", "$", "exclude", "+", "1", ";", "}", "}", "else", "if", "(", "strpos", "(", "$", "fragment", ",", "'<span'", ")", "===", "false", "||", "strpos", "(", "$", "fragment", ",", "'</span'", ")", "===", "false", ")", "{", "// This is the meat of the code - this is run every time.", "// This code only runs for fragments that are not ignored (including the tags themselves).", "$", "fragment", "=", "str_replace", "(", "self", "::", "$", "emoticontexts", "[", "$", "lang", "]", "[", "$", "theme", "]", ",", "self", "::", "$", "emoticonimgs", "[", "$", "lang", "]", "[", "$", "theme", "]", ",", "$", "fragment", ")", ";", "}", "$", "resulthtml", ".=", "$", "fragment", ";", "}", "return", "$", "resulthtml", ";", "}" ]
Replace emoticons found in the text with their images @param string $text to modify @return string the modified result
[ "Replace", "emoticons", "found", "in", "the", "text", "with", "their", "images" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/filter/emoticon/filter.php#L83-L149
213,117
moodle/moodle
admin/tool/uploadcourse/classes/base_form.php
tool_uploadcourse_base_form.add_import_options
public function add_import_options() { $mform = $this->_form; // Upload settings and file. $mform->addElement('header', 'importoptionshdr', get_string('importoptions', 'tool_uploadcourse')); $mform->setExpanded('importoptionshdr', true); $choices = array( tool_uploadcourse_processor::MODE_CREATE_NEW => get_string('createnew', 'tool_uploadcourse'), tool_uploadcourse_processor::MODE_CREATE_ALL => get_string('createall', 'tool_uploadcourse'), tool_uploadcourse_processor::MODE_CREATE_OR_UPDATE => get_string('createorupdate', 'tool_uploadcourse'), tool_uploadcourse_processor::MODE_UPDATE_ONLY => get_string('updateonly', 'tool_uploadcourse') ); $mform->addElement('select', 'options[mode]', get_string('mode', 'tool_uploadcourse'), $choices); $mform->addHelpButton('options[mode]', 'mode', 'tool_uploadcourse'); $choices = array( tool_uploadcourse_processor::UPDATE_NOTHING => get_string('nochanges', 'tool_uploadcourse'), tool_uploadcourse_processor::UPDATE_ALL_WITH_DATA_ONLY => get_string('updatewithdataonly', 'tool_uploadcourse'), tool_uploadcourse_processor::UPDATE_ALL_WITH_DATA_OR_DEFAUTLS => get_string('updatewithdataordefaults', 'tool_uploadcourse'), tool_uploadcourse_processor::UPDATE_MISSING_WITH_DATA_OR_DEFAUTLS => get_string('updatemissing', 'tool_uploadcourse') ); $mform->addElement('select', 'options[updatemode]', get_string('updatemode', 'tool_uploadcourse'), $choices); $mform->setDefault('options[updatemode]', tool_uploadcourse_processor::UPDATE_NOTHING); $mform->hideIf('options[updatemode]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_NEW); $mform->hideIf('options[updatemode]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_ALL); $mform->addHelpButton('options[updatemode]', 'updatemode', 'tool_uploadcourse'); $mform->addElement('selectyesno', 'options[allowdeletes]', get_string('allowdeletes', 'tool_uploadcourse')); $mform->setDefault('options[allowdeletes]', 0); $mform->hideIf('options[allowdeletes]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_NEW); $mform->hideIf('options[allowdeletes]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_ALL); $mform->addHelpButton('options[allowdeletes]', 'allowdeletes', 'tool_uploadcourse'); $mform->addElement('selectyesno', 'options[allowrenames]', get_string('allowrenames', 'tool_uploadcourse')); $mform->setDefault('options[allowrenames]', 0); $mform->hideIf('options[allowrenames]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_NEW); $mform->hideIf('options[allowrenames]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_ALL); $mform->addHelpButton('options[allowrenames]', 'allowrenames', 'tool_uploadcourse'); $mform->addElement('selectyesno', 'options[allowresets]', get_string('allowresets', 'tool_uploadcourse')); $mform->setDefault('options[allowresets]', 0); $mform->hideIf('options[allowresets]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_NEW); $mform->hideIf('options[allowresets]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_ALL); $mform->addHelpButton('options[allowresets]', 'allowresets', 'tool_uploadcourse'); }
php
public function add_import_options() { $mform = $this->_form; // Upload settings and file. $mform->addElement('header', 'importoptionshdr', get_string('importoptions', 'tool_uploadcourse')); $mform->setExpanded('importoptionshdr', true); $choices = array( tool_uploadcourse_processor::MODE_CREATE_NEW => get_string('createnew', 'tool_uploadcourse'), tool_uploadcourse_processor::MODE_CREATE_ALL => get_string('createall', 'tool_uploadcourse'), tool_uploadcourse_processor::MODE_CREATE_OR_UPDATE => get_string('createorupdate', 'tool_uploadcourse'), tool_uploadcourse_processor::MODE_UPDATE_ONLY => get_string('updateonly', 'tool_uploadcourse') ); $mform->addElement('select', 'options[mode]', get_string('mode', 'tool_uploadcourse'), $choices); $mform->addHelpButton('options[mode]', 'mode', 'tool_uploadcourse'); $choices = array( tool_uploadcourse_processor::UPDATE_NOTHING => get_string('nochanges', 'tool_uploadcourse'), tool_uploadcourse_processor::UPDATE_ALL_WITH_DATA_ONLY => get_string('updatewithdataonly', 'tool_uploadcourse'), tool_uploadcourse_processor::UPDATE_ALL_WITH_DATA_OR_DEFAUTLS => get_string('updatewithdataordefaults', 'tool_uploadcourse'), tool_uploadcourse_processor::UPDATE_MISSING_WITH_DATA_OR_DEFAUTLS => get_string('updatemissing', 'tool_uploadcourse') ); $mform->addElement('select', 'options[updatemode]', get_string('updatemode', 'tool_uploadcourse'), $choices); $mform->setDefault('options[updatemode]', tool_uploadcourse_processor::UPDATE_NOTHING); $mform->hideIf('options[updatemode]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_NEW); $mform->hideIf('options[updatemode]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_ALL); $mform->addHelpButton('options[updatemode]', 'updatemode', 'tool_uploadcourse'); $mform->addElement('selectyesno', 'options[allowdeletes]', get_string('allowdeletes', 'tool_uploadcourse')); $mform->setDefault('options[allowdeletes]', 0); $mform->hideIf('options[allowdeletes]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_NEW); $mform->hideIf('options[allowdeletes]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_ALL); $mform->addHelpButton('options[allowdeletes]', 'allowdeletes', 'tool_uploadcourse'); $mform->addElement('selectyesno', 'options[allowrenames]', get_string('allowrenames', 'tool_uploadcourse')); $mform->setDefault('options[allowrenames]', 0); $mform->hideIf('options[allowrenames]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_NEW); $mform->hideIf('options[allowrenames]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_ALL); $mform->addHelpButton('options[allowrenames]', 'allowrenames', 'tool_uploadcourse'); $mform->addElement('selectyesno', 'options[allowresets]', get_string('allowresets', 'tool_uploadcourse')); $mform->setDefault('options[allowresets]', 0); $mform->hideIf('options[allowresets]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_NEW); $mform->hideIf('options[allowresets]', 'options[mode]', 'eq', tool_uploadcourse_processor::MODE_CREATE_ALL); $mform->addHelpButton('options[allowresets]', 'allowresets', 'tool_uploadcourse'); }
[ "public", "function", "add_import_options", "(", ")", "{", "$", "mform", "=", "$", "this", "->", "_form", ";", "// Upload settings and file.", "$", "mform", "->", "addElement", "(", "'header'", ",", "'importoptionshdr'", ",", "get_string", "(", "'importoptions'", ",", "'tool_uploadcourse'", ")", ")", ";", "$", "mform", "->", "setExpanded", "(", "'importoptionshdr'", ",", "true", ")", ";", "$", "choices", "=", "array", "(", "tool_uploadcourse_processor", "::", "MODE_CREATE_NEW", "=>", "get_string", "(", "'createnew'", ",", "'tool_uploadcourse'", ")", ",", "tool_uploadcourse_processor", "::", "MODE_CREATE_ALL", "=>", "get_string", "(", "'createall'", ",", "'tool_uploadcourse'", ")", ",", "tool_uploadcourse_processor", "::", "MODE_CREATE_OR_UPDATE", "=>", "get_string", "(", "'createorupdate'", ",", "'tool_uploadcourse'", ")", ",", "tool_uploadcourse_processor", "::", "MODE_UPDATE_ONLY", "=>", "get_string", "(", "'updateonly'", ",", "'tool_uploadcourse'", ")", ")", ";", "$", "mform", "->", "addElement", "(", "'select'", ",", "'options[mode]'", ",", "get_string", "(", "'mode'", ",", "'tool_uploadcourse'", ")", ",", "$", "choices", ")", ";", "$", "mform", "->", "addHelpButton", "(", "'options[mode]'", ",", "'mode'", ",", "'tool_uploadcourse'", ")", ";", "$", "choices", "=", "array", "(", "tool_uploadcourse_processor", "::", "UPDATE_NOTHING", "=>", "get_string", "(", "'nochanges'", ",", "'tool_uploadcourse'", ")", ",", "tool_uploadcourse_processor", "::", "UPDATE_ALL_WITH_DATA_ONLY", "=>", "get_string", "(", "'updatewithdataonly'", ",", "'tool_uploadcourse'", ")", ",", "tool_uploadcourse_processor", "::", "UPDATE_ALL_WITH_DATA_OR_DEFAUTLS", "=>", "get_string", "(", "'updatewithdataordefaults'", ",", "'tool_uploadcourse'", ")", ",", "tool_uploadcourse_processor", "::", "UPDATE_MISSING_WITH_DATA_OR_DEFAUTLS", "=>", "get_string", "(", "'updatemissing'", ",", "'tool_uploadcourse'", ")", ")", ";", "$", "mform", "->", "addElement", "(", "'select'", ",", "'options[updatemode]'", ",", "get_string", "(", "'updatemode'", ",", "'tool_uploadcourse'", ")", ",", "$", "choices", ")", ";", "$", "mform", "->", "setDefault", "(", "'options[updatemode]'", ",", "tool_uploadcourse_processor", "::", "UPDATE_NOTHING", ")", ";", "$", "mform", "->", "hideIf", "(", "'options[updatemode]'", ",", "'options[mode]'", ",", "'eq'", ",", "tool_uploadcourse_processor", "::", "MODE_CREATE_NEW", ")", ";", "$", "mform", "->", "hideIf", "(", "'options[updatemode]'", ",", "'options[mode]'", ",", "'eq'", ",", "tool_uploadcourse_processor", "::", "MODE_CREATE_ALL", ")", ";", "$", "mform", "->", "addHelpButton", "(", "'options[updatemode]'", ",", "'updatemode'", ",", "'tool_uploadcourse'", ")", ";", "$", "mform", "->", "addElement", "(", "'selectyesno'", ",", "'options[allowdeletes]'", ",", "get_string", "(", "'allowdeletes'", ",", "'tool_uploadcourse'", ")", ")", ";", "$", "mform", "->", "setDefault", "(", "'options[allowdeletes]'", ",", "0", ")", ";", "$", "mform", "->", "hideIf", "(", "'options[allowdeletes]'", ",", "'options[mode]'", ",", "'eq'", ",", "tool_uploadcourse_processor", "::", "MODE_CREATE_NEW", ")", ";", "$", "mform", "->", "hideIf", "(", "'options[allowdeletes]'", ",", "'options[mode]'", ",", "'eq'", ",", "tool_uploadcourse_processor", "::", "MODE_CREATE_ALL", ")", ";", "$", "mform", "->", "addHelpButton", "(", "'options[allowdeletes]'", ",", "'allowdeletes'", ",", "'tool_uploadcourse'", ")", ";", "$", "mform", "->", "addElement", "(", "'selectyesno'", ",", "'options[allowrenames]'", ",", "get_string", "(", "'allowrenames'", ",", "'tool_uploadcourse'", ")", ")", ";", "$", "mform", "->", "setDefault", "(", "'options[allowrenames]'", ",", "0", ")", ";", "$", "mform", "->", "hideIf", "(", "'options[allowrenames]'", ",", "'options[mode]'", ",", "'eq'", ",", "tool_uploadcourse_processor", "::", "MODE_CREATE_NEW", ")", ";", "$", "mform", "->", "hideIf", "(", "'options[allowrenames]'", ",", "'options[mode]'", ",", "'eq'", ",", "tool_uploadcourse_processor", "::", "MODE_CREATE_ALL", ")", ";", "$", "mform", "->", "addHelpButton", "(", "'options[allowrenames]'", ",", "'allowrenames'", ",", "'tool_uploadcourse'", ")", ";", "$", "mform", "->", "addElement", "(", "'selectyesno'", ",", "'options[allowresets]'", ",", "get_string", "(", "'allowresets'", ",", "'tool_uploadcourse'", ")", ")", ";", "$", "mform", "->", "setDefault", "(", "'options[allowresets]'", ",", "0", ")", ";", "$", "mform", "->", "hideIf", "(", "'options[allowresets]'", ",", "'options[mode]'", ",", "'eq'", ",", "tool_uploadcourse_processor", "::", "MODE_CREATE_NEW", ")", ";", "$", "mform", "->", "hideIf", "(", "'options[allowresets]'", ",", "'options[mode]'", ",", "'eq'", ",", "tool_uploadcourse_processor", "::", "MODE_CREATE_ALL", ")", ";", "$", "mform", "->", "addHelpButton", "(", "'options[allowresets]'", ",", "'allowresets'", ",", "'tool_uploadcourse'", ")", ";", "}" ]
Adds the import settings part. @return void
[ "Adds", "the", "import", "settings", "part", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/uploadcourse/classes/base_form.php#L50-L96
213,118
moodle/moodle
auth/oauth2/classes/privacy/provider.php
provider.export_user_data
public static function export_user_data(approved_contextlist $contextlist) { global $DB; // Export oauth2 linked accounts. $context = \context_user::instance($contextlist->get_user()->id); $sql = "SELECT ll.id, ll.username, ll.email, ll.timecreated, ll.timemodified, oi.name as issuername FROM {auth_oauth2_linked_login} ll JOIN {oauth2_issuer} oi ON oi.id = ll.issuerid WHERE ll.userid = :userid"; if ($oauth2accounts = $DB->get_records_sql($sql, ['userid' => $contextlist->get_user()->id])) { foreach ($oauth2accounts as $oauth2account) { $data = (object)[ 'timecreated' => transform::datetime($oauth2account->timecreated), 'timemodified' => transform::datetime($oauth2account->timemodified), 'issuerid' => $oauth2account->issuername, 'username' => $oauth2account->username, 'email' => $oauth2account->email ]; writer::with_context($context)->export_data([ get_string('privacy:metadata:auth_oauth2', 'auth_oauth2'), $oauth2account->issuername ], $data); } } }
php
public static function export_user_data(approved_contextlist $contextlist) { global $DB; // Export oauth2 linked accounts. $context = \context_user::instance($contextlist->get_user()->id); $sql = "SELECT ll.id, ll.username, ll.email, ll.timecreated, ll.timemodified, oi.name as issuername FROM {auth_oauth2_linked_login} ll JOIN {oauth2_issuer} oi ON oi.id = ll.issuerid WHERE ll.userid = :userid"; if ($oauth2accounts = $DB->get_records_sql($sql, ['userid' => $contextlist->get_user()->id])) { foreach ($oauth2accounts as $oauth2account) { $data = (object)[ 'timecreated' => transform::datetime($oauth2account->timecreated), 'timemodified' => transform::datetime($oauth2account->timemodified), 'issuerid' => $oauth2account->issuername, 'username' => $oauth2account->username, 'email' => $oauth2account->email ]; writer::with_context($context)->export_data([ get_string('privacy:metadata:auth_oauth2', 'auth_oauth2'), $oauth2account->issuername ], $data); } } }
[ "public", "static", "function", "export_user_data", "(", "approved_contextlist", "$", "contextlist", ")", "{", "global", "$", "DB", ";", "// Export oauth2 linked accounts.", "$", "context", "=", "\\", "context_user", "::", "instance", "(", "$", "contextlist", "->", "get_user", "(", ")", "->", "id", ")", ";", "$", "sql", "=", "\"SELECT ll.id, ll.username, ll.email, ll.timecreated, ll.timemodified, oi.name as issuername\n FROM {auth_oauth2_linked_login} ll JOIN {oauth2_issuer} oi ON oi.id = ll.issuerid\n WHERE ll.userid = :userid\"", ";", "if", "(", "$", "oauth2accounts", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "[", "'userid'", "=>", "$", "contextlist", "->", "get_user", "(", ")", "->", "id", "]", ")", ")", "{", "foreach", "(", "$", "oauth2accounts", "as", "$", "oauth2account", ")", "{", "$", "data", "=", "(", "object", ")", "[", "'timecreated'", "=>", "transform", "::", "datetime", "(", "$", "oauth2account", "->", "timecreated", ")", ",", "'timemodified'", "=>", "transform", "::", "datetime", "(", "$", "oauth2account", "->", "timemodified", ")", ",", "'issuerid'", "=>", "$", "oauth2account", "->", "issuername", ",", "'username'", "=>", "$", "oauth2account", "->", "username", ",", "'email'", "=>", "$", "oauth2account", "->", "email", "]", ";", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_data", "(", "[", "get_string", "(", "'privacy:metadata:auth_oauth2'", ",", "'auth_oauth2'", ")", ",", "$", "oauth2account", "->", "issuername", "]", ",", "$", "data", ")", ";", "}", "}", "}" ]
Export all oauth2 information for the list of contexts and this user. @param approved_contextlist $contextlist The list of approved contexts for a user.
[ "Export", "all", "oauth2", "information", "for", "the", "list", "of", "contexts", "and", "this", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/oauth2/classes/privacy/provider.php#L114-L137
213,119
moodle/moodle
grade/report/singleview/classes/local/screen/tablelike.php
tablelike.format_definition
public function format_definition($line, $grade) { foreach ($this->definition() as $i => $field) { // Table tab index. $tab = ($i * $this->total) + $this->index; $classname = '\\gradereport_singleview\\local\\ui\\' . $field; $html = new $classname($grade, $tab); if ($field == 'finalgrade' and !empty($this->structure)) { $html .= $this->structure->get_grade_analysis_icon($grade); } // Singleview users without proper permissions should be presented // disabled checkboxes for the Exclude grade attribute. if ($field == 'exclude' && !has_capability('moodle/grade:manage', $this->context)){ $html->disabled = true; } $line[] = $html; } return $line; }
php
public function format_definition($line, $grade) { foreach ($this->definition() as $i => $field) { // Table tab index. $tab = ($i * $this->total) + $this->index; $classname = '\\gradereport_singleview\\local\\ui\\' . $field; $html = new $classname($grade, $tab); if ($field == 'finalgrade' and !empty($this->structure)) { $html .= $this->structure->get_grade_analysis_icon($grade); } // Singleview users without proper permissions should be presented // disabled checkboxes for the Exclude grade attribute. if ($field == 'exclude' && !has_capability('moodle/grade:manage', $this->context)){ $html->disabled = true; } $line[] = $html; } return $line; }
[ "public", "function", "format_definition", "(", "$", "line", ",", "$", "grade", ")", "{", "foreach", "(", "$", "this", "->", "definition", "(", ")", "as", "$", "i", "=>", "$", "field", ")", "{", "// Table tab index.", "$", "tab", "=", "(", "$", "i", "*", "$", "this", "->", "total", ")", "+", "$", "this", "->", "index", ";", "$", "classname", "=", "'\\\\gradereport_singleview\\\\local\\\\ui\\\\'", ".", "$", "field", ";", "$", "html", "=", "new", "$", "classname", "(", "$", "grade", ",", "$", "tab", ")", ";", "if", "(", "$", "field", "==", "'finalgrade'", "and", "!", "empty", "(", "$", "this", "->", "structure", ")", ")", "{", "$", "html", ".=", "$", "this", "->", "structure", "->", "get_grade_analysis_icon", "(", "$", "grade", ")", ";", "}", "// Singleview users without proper permissions should be presented", "// disabled checkboxes for the Exclude grade attribute.", "if", "(", "$", "field", "==", "'exclude'", "&&", "!", "has_capability", "(", "'moodle/grade:manage'", ",", "$", "this", "->", "context", ")", ")", "{", "$", "html", "->", "disabled", "=", "true", ";", "}", "$", "line", "[", "]", "=", "$", "html", ";", "}", "return", "$", "line", ";", "}" ]
Get a element to generate the HTML for this table row @param array $line This is a list of lines in the table (modified) @param grade_grade $grade The grade. @return string
[ "Get", "a", "element", "to", "generate", "the", "HTML", "for", "this", "table", "row" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/screen/tablelike.php#L133-L153
213,120
moodle/moodle
grade/report/singleview/classes/local/screen/tablelike.php
tablelike.html
public function html() { global $OUTPUT; if (!empty($this->initerrors)) { $warnings = ''; foreach ($this->initerrors as $mesg) { $warnings .= $OUTPUT->notification($mesg); } return $warnings; } $table = new html_table(); $table->head = $this->headers(); $summary = $this->summary(); if (!empty($summary)) { $table->summary = $summary; } // To be used for extra formatting. $this->index = 0; $this->total = count($this->items); foreach ($this->items as $item) { if ($this->index >= ($this->perpage * $this->page) && $this->index < ($this->perpage * ($this->page + 1))) { $table->data[] = $this->format_line($item); } $this->index++; } $underlying = get_class($this); $data = new stdClass(); $data->table = $table; $data->instance = $this; $buttonattr = array('class' => 'singleview_buttons submit'); $buttonhtml = implode(' ', $this->buttons()); $buttons = html_writer::tag('div', $buttonhtml, $buttonattr); $selectview = new select($this->courseid, $this->itemid, $this->groupid); $sessionvalidation = html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())); $html = $selectview->html(); $html .= html_writer::tag('form', $buttons . html_writer::table($table) . $this->bulk_insert() . $buttons . $sessionvalidation, array('method' => 'POST') ); $html .= $selectview->html(); return $html; }
php
public function html() { global $OUTPUT; if (!empty($this->initerrors)) { $warnings = ''; foreach ($this->initerrors as $mesg) { $warnings .= $OUTPUT->notification($mesg); } return $warnings; } $table = new html_table(); $table->head = $this->headers(); $summary = $this->summary(); if (!empty($summary)) { $table->summary = $summary; } // To be used for extra formatting. $this->index = 0; $this->total = count($this->items); foreach ($this->items as $item) { if ($this->index >= ($this->perpage * $this->page) && $this->index < ($this->perpage * ($this->page + 1))) { $table->data[] = $this->format_line($item); } $this->index++; } $underlying = get_class($this); $data = new stdClass(); $data->table = $table; $data->instance = $this; $buttonattr = array('class' => 'singleview_buttons submit'); $buttonhtml = implode(' ', $this->buttons()); $buttons = html_writer::tag('div', $buttonhtml, $buttonattr); $selectview = new select($this->courseid, $this->itemid, $this->groupid); $sessionvalidation = html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey())); $html = $selectview->html(); $html .= html_writer::tag('form', $buttons . html_writer::table($table) . $this->bulk_insert() . $buttons . $sessionvalidation, array('method' => 'POST') ); $html .= $selectview->html(); return $html; }
[ "public", "function", "html", "(", ")", "{", "global", "$", "OUTPUT", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "initerrors", ")", ")", "{", "$", "warnings", "=", "''", ";", "foreach", "(", "$", "this", "->", "initerrors", "as", "$", "mesg", ")", "{", "$", "warnings", ".=", "$", "OUTPUT", "->", "notification", "(", "$", "mesg", ")", ";", "}", "return", "$", "warnings", ";", "}", "$", "table", "=", "new", "html_table", "(", ")", ";", "$", "table", "->", "head", "=", "$", "this", "->", "headers", "(", ")", ";", "$", "summary", "=", "$", "this", "->", "summary", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "summary", ")", ")", "{", "$", "table", "->", "summary", "=", "$", "summary", ";", "}", "// To be used for extra formatting.", "$", "this", "->", "index", "=", "0", ";", "$", "this", "->", "total", "=", "count", "(", "$", "this", "->", "items", ")", ";", "foreach", "(", "$", "this", "->", "items", "as", "$", "item", ")", "{", "if", "(", "$", "this", "->", "index", ">=", "(", "$", "this", "->", "perpage", "*", "$", "this", "->", "page", ")", "&&", "$", "this", "->", "index", "<", "(", "$", "this", "->", "perpage", "*", "(", "$", "this", "->", "page", "+", "1", ")", ")", ")", "{", "$", "table", "->", "data", "[", "]", "=", "$", "this", "->", "format_line", "(", "$", "item", ")", ";", "}", "$", "this", "->", "index", "++", ";", "}", "$", "underlying", "=", "get_class", "(", "$", "this", ")", ";", "$", "data", "=", "new", "stdClass", "(", ")", ";", "$", "data", "->", "table", "=", "$", "table", ";", "$", "data", "->", "instance", "=", "$", "this", ";", "$", "buttonattr", "=", "array", "(", "'class'", "=>", "'singleview_buttons submit'", ")", ";", "$", "buttonhtml", "=", "implode", "(", "' '", ",", "$", "this", "->", "buttons", "(", ")", ")", ";", "$", "buttons", "=", "html_writer", "::", "tag", "(", "'div'", ",", "$", "buttonhtml", ",", "$", "buttonattr", ")", ";", "$", "selectview", "=", "new", "select", "(", "$", "this", "->", "courseid", ",", "$", "this", "->", "itemid", ",", "$", "this", "->", "groupid", ")", ";", "$", "sessionvalidation", "=", "html_writer", "::", "empty_tag", "(", "'input'", ",", "array", "(", "'type'", "=>", "'hidden'", ",", "'name'", "=>", "'sesskey'", ",", "'value'", "=>", "sesskey", "(", ")", ")", ")", ";", "$", "html", "=", "$", "selectview", "->", "html", "(", ")", ";", "$", "html", ".=", "html_writer", "::", "tag", "(", "'form'", ",", "$", "buttons", ".", "html_writer", "::", "table", "(", "$", "table", ")", ".", "$", "this", "->", "bulk_insert", "(", ")", ".", "$", "buttons", ".", "$", "sessionvalidation", ",", "array", "(", "'method'", "=>", "'POST'", ")", ")", ";", "$", "html", ".=", "$", "selectview", "->", "html", "(", ")", ";", "return", "$", "html", ";", "}" ]
Get the HTML for the whole table @return string
[ "Get", "the", "HTML", "for", "the", "whole", "table" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/screen/tablelike.php#L159-L212
213,121
moodle/moodle
report/loglive/classes/renderable.php
report_loglive_renderable.setup_table_ajax
protected function setup_table_ajax() { $filter = $this->setup_filters(); $this->tablelog = new report_loglive_table_log_ajax('report_loglive', $filter); $this->tablelog->define_baseurl($this->url); }
php
protected function setup_table_ajax() { $filter = $this->setup_filters(); $this->tablelog = new report_loglive_table_log_ajax('report_loglive', $filter); $this->tablelog->define_baseurl($this->url); }
[ "protected", "function", "setup_table_ajax", "(", ")", "{", "$", "filter", "=", "$", "this", "->", "setup_filters", "(", ")", ";", "$", "this", "->", "tablelog", "=", "new", "report_loglive_table_log_ajax", "(", "'report_loglive'", ",", "$", "filter", ")", ";", "$", "this", "->", "tablelog", "->", "define_baseurl", "(", "$", "this", "->", "url", ")", ";", "}" ]
Setup table log for ajax output.
[ "Setup", "table", "log", "for", "ajax", "output", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/loglive/classes/renderable.php#L159-L163
213,122
moodle/moodle
report/loglive/classes/renderable.php
report_loglive_renderable.set_refresh_rate
protected function set_refresh_rate() { if (defined('BEHAT_SITE_RUNNING')) { // Hack for behat tests. $this->refresh = 5; } else { if (defined('REPORT_LOGLIVE_REFRESH')) { // Backward compatibility. $this->refresh = REPORT_LOGLIVE_REFERESH; } else { // Default. $this->refresh = 60; } } }
php
protected function set_refresh_rate() { if (defined('BEHAT_SITE_RUNNING')) { // Hack for behat tests. $this->refresh = 5; } else { if (defined('REPORT_LOGLIVE_REFRESH')) { // Backward compatibility. $this->refresh = REPORT_LOGLIVE_REFERESH; } else { // Default. $this->refresh = 60; } } }
[ "protected", "function", "set_refresh_rate", "(", ")", "{", "if", "(", "defined", "(", "'BEHAT_SITE_RUNNING'", ")", ")", "{", "// Hack for behat tests.", "$", "this", "->", "refresh", "=", "5", ";", "}", "else", "{", "if", "(", "defined", "(", "'REPORT_LOGLIVE_REFRESH'", ")", ")", "{", "// Backward compatibility.", "$", "this", "->", "refresh", "=", "REPORT_LOGLIVE_REFERESH", ";", "}", "else", "{", "// Default.", "$", "this", "->", "refresh", "=", "60", ";", "}", "}", "}" ]
Set refresh rate of the live updates.
[ "Set", "refresh", "rate", "of", "the", "live", "updates", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/loglive/classes/renderable.php#L191-L204
213,123
moodle/moodle
report/loglive/classes/renderable.php
report_loglive_renderable.get_table
public function get_table($ajax = false) { if (empty($this->tablelog)) { if ($ajax) { $this->setup_table_ajax(); } else { $this->setup_table(); } } return $this->tablelog; }
php
public function get_table($ajax = false) { if (empty($this->tablelog)) { if ($ajax) { $this->setup_table_ajax(); } else { $this->setup_table(); } } return $this->tablelog; }
[ "public", "function", "get_table", "(", "$", "ajax", "=", "false", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "tablelog", ")", ")", "{", "if", "(", "$", "ajax", ")", "{", "$", "this", "->", "setup_table_ajax", "(", ")", ";", "}", "else", "{", "$", "this", "->", "setup_table", "(", ")", ";", "}", "}", "return", "$", "this", "->", "tablelog", ";", "}" ]
Setup table and return it. @param bool $ajax If set to true report_loglive_table_log_ajax is set instead of report_loglive_table_log. @return report_loglive_table_log|report_loglive_table_log_ajax table object
[ "Setup", "table", "and", "return", "it", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/loglive/classes/renderable.php#L220-L229
213,124
moodle/moodle
mod/assign/backup/moodle2/restore_assign_stepslib.php
restore_assign_activity_structure_step.define_structure
protected function define_structure() { $paths = array(); // To know if we are including userinfo. $userinfo = $this->get_setting_value('userinfo'); // Define each element separated. $paths[] = new restore_path_element('assign', '/activity/assign'); if ($userinfo) { $submission = new restore_path_element('assign_submission', '/activity/assign/submissions/submission'); $paths[] = $submission; $this->add_subplugin_structure('assignsubmission', $submission); $grade = new restore_path_element('assign_grade', '/activity/assign/grades/grade'); $paths[] = $grade; $this->add_subplugin_structure('assignfeedback', $grade); $userflag = new restore_path_element('assign_userflag', '/activity/assign/userflags/userflag'); $paths[] = $userflag; } $paths[] = new restore_path_element('assign_override', '/activity/assign/overrides/override'); $paths[] = new restore_path_element('assign_plugin_config', '/activity/assign/plugin_configs/plugin_config'); return $this->prepare_activity_structure($paths); }
php
protected function define_structure() { $paths = array(); // To know if we are including userinfo. $userinfo = $this->get_setting_value('userinfo'); // Define each element separated. $paths[] = new restore_path_element('assign', '/activity/assign'); if ($userinfo) { $submission = new restore_path_element('assign_submission', '/activity/assign/submissions/submission'); $paths[] = $submission; $this->add_subplugin_structure('assignsubmission', $submission); $grade = new restore_path_element('assign_grade', '/activity/assign/grades/grade'); $paths[] = $grade; $this->add_subplugin_structure('assignfeedback', $grade); $userflag = new restore_path_element('assign_userflag', '/activity/assign/userflags/userflag'); $paths[] = $userflag; } $paths[] = new restore_path_element('assign_override', '/activity/assign/overrides/override'); $paths[] = new restore_path_element('assign_plugin_config', '/activity/assign/plugin_configs/plugin_config'); return $this->prepare_activity_structure($paths); }
[ "protected", "function", "define_structure", "(", ")", "{", "$", "paths", "=", "array", "(", ")", ";", "// To know if we are including userinfo.", "$", "userinfo", "=", "$", "this", "->", "get_setting_value", "(", "'userinfo'", ")", ";", "// Define each element separated.", "$", "paths", "[", "]", "=", "new", "restore_path_element", "(", "'assign'", ",", "'/activity/assign'", ")", ";", "if", "(", "$", "userinfo", ")", "{", "$", "submission", "=", "new", "restore_path_element", "(", "'assign_submission'", ",", "'/activity/assign/submissions/submission'", ")", ";", "$", "paths", "[", "]", "=", "$", "submission", ";", "$", "this", "->", "add_subplugin_structure", "(", "'assignsubmission'", ",", "$", "submission", ")", ";", "$", "grade", "=", "new", "restore_path_element", "(", "'assign_grade'", ",", "'/activity/assign/grades/grade'", ")", ";", "$", "paths", "[", "]", "=", "$", "grade", ";", "$", "this", "->", "add_subplugin_structure", "(", "'assignfeedback'", ",", "$", "grade", ")", ";", "$", "userflag", "=", "new", "restore_path_element", "(", "'assign_userflag'", ",", "'/activity/assign/userflags/userflag'", ")", ";", "$", "paths", "[", "]", "=", "$", "userflag", ";", "}", "$", "paths", "[", "]", "=", "new", "restore_path_element", "(", "'assign_override'", ",", "'/activity/assign/overrides/override'", ")", ";", "$", "paths", "[", "]", "=", "new", "restore_path_element", "(", "'assign_plugin_config'", ",", "'/activity/assign/plugin_configs/plugin_config'", ")", ";", "return", "$", "this", "->", "prepare_activity_structure", "(", "$", "paths", ")", ";", "}" ]
Define the structure of the restore workflow. @return restore_path_element $structure
[ "Define", "the", "structure", "of", "the", "restore", "workflow", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/backup/moodle2/restore_assign_stepslib.php#L49-L75
213,125
moodle/moodle
mod/assign/backup/moodle2/restore_assign_stepslib.php
restore_assign_activity_structure_step.process_assign
protected function process_assign($data) { global $DB; $data = (object)$data; $oldid = $data->id; $data->course = $this->get_courseid(); // Any changes to the list of dates that needs to be rolled should be same during course restore and course reset. // See MDL-9367. $data->allowsubmissionsfromdate = $this->apply_date_offset($data->allowsubmissionsfromdate); $data->duedate = $this->apply_date_offset($data->duedate); // If this is a team submission, but there is no group info we need to flag that the submission // information should not be included. It should not be restored. $groupinfo = $this->task->get_setting_value('groups'); if ($data->teamsubmission && !$groupinfo) { $this->includesubmission = false; } // Reset revealidentities if blindmarking with no user data (MDL-43796). $userinfo = $this->get_setting_value('userinfo'); if (!$userinfo && $data->blindmarking) { $data->revealidentities = 0; } if (!empty($data->teamsubmissiongroupingid)) { $data->teamsubmissiongroupingid = $this->get_mappingid('grouping', $data->teamsubmissiongroupingid); } else { $data->teamsubmissiongroupingid = 0; } if (!isset($data->cutoffdate)) { $data->cutoffdate = 0; } if (!isset($data->gradingduedate)) { $data->gradingduedate = 0; } else { $data->gradingduedate = $this->apply_date_offset($data->gradingduedate); } if (!isset($data->markingworkflow)) { $data->markingworkflow = 0; } if (!isset($data->markingallocation)) { $data->markingallocation = 0; } if (!isset($data->preventsubmissionnotingroup)) { $data->preventsubmissionnotingroup = 0; } if (!empty($data->preventlatesubmissions)) { $data->cutoffdate = $data->duedate; } else { $data->cutoffdate = $this->apply_date_offset($data->cutoffdate); } if ($data->grade < 0) { // Scale found, get mapping. $data->grade = -($this->get_mappingid('scale', abs($data->grade))); } $newitemid = $DB->insert_record('assign', $data); $this->apply_activity_instance($newitemid); }
php
protected function process_assign($data) { global $DB; $data = (object)$data; $oldid = $data->id; $data->course = $this->get_courseid(); // Any changes to the list of dates that needs to be rolled should be same during course restore and course reset. // See MDL-9367. $data->allowsubmissionsfromdate = $this->apply_date_offset($data->allowsubmissionsfromdate); $data->duedate = $this->apply_date_offset($data->duedate); // If this is a team submission, but there is no group info we need to flag that the submission // information should not be included. It should not be restored. $groupinfo = $this->task->get_setting_value('groups'); if ($data->teamsubmission && !$groupinfo) { $this->includesubmission = false; } // Reset revealidentities if blindmarking with no user data (MDL-43796). $userinfo = $this->get_setting_value('userinfo'); if (!$userinfo && $data->blindmarking) { $data->revealidentities = 0; } if (!empty($data->teamsubmissiongroupingid)) { $data->teamsubmissiongroupingid = $this->get_mappingid('grouping', $data->teamsubmissiongroupingid); } else { $data->teamsubmissiongroupingid = 0; } if (!isset($data->cutoffdate)) { $data->cutoffdate = 0; } if (!isset($data->gradingduedate)) { $data->gradingduedate = 0; } else { $data->gradingduedate = $this->apply_date_offset($data->gradingduedate); } if (!isset($data->markingworkflow)) { $data->markingworkflow = 0; } if (!isset($data->markingallocation)) { $data->markingallocation = 0; } if (!isset($data->preventsubmissionnotingroup)) { $data->preventsubmissionnotingroup = 0; } if (!empty($data->preventlatesubmissions)) { $data->cutoffdate = $data->duedate; } else { $data->cutoffdate = $this->apply_date_offset($data->cutoffdate); } if ($data->grade < 0) { // Scale found, get mapping. $data->grade = -($this->get_mappingid('scale', abs($data->grade))); } $newitemid = $DB->insert_record('assign', $data); $this->apply_activity_instance($newitemid); }
[ "protected", "function", "process_assign", "(", "$", "data", ")", "{", "global", "$", "DB", ";", "$", "data", "=", "(", "object", ")", "$", "data", ";", "$", "oldid", "=", "$", "data", "->", "id", ";", "$", "data", "->", "course", "=", "$", "this", "->", "get_courseid", "(", ")", ";", "// Any changes to the list of dates that needs to be rolled should be same during course restore and course reset.", "// See MDL-9367.", "$", "data", "->", "allowsubmissionsfromdate", "=", "$", "this", "->", "apply_date_offset", "(", "$", "data", "->", "allowsubmissionsfromdate", ")", ";", "$", "data", "->", "duedate", "=", "$", "this", "->", "apply_date_offset", "(", "$", "data", "->", "duedate", ")", ";", "// If this is a team submission, but there is no group info we need to flag that the submission", "// information should not be included. It should not be restored.", "$", "groupinfo", "=", "$", "this", "->", "task", "->", "get_setting_value", "(", "'groups'", ")", ";", "if", "(", "$", "data", "->", "teamsubmission", "&&", "!", "$", "groupinfo", ")", "{", "$", "this", "->", "includesubmission", "=", "false", ";", "}", "// Reset revealidentities if blindmarking with no user data (MDL-43796).", "$", "userinfo", "=", "$", "this", "->", "get_setting_value", "(", "'userinfo'", ")", ";", "if", "(", "!", "$", "userinfo", "&&", "$", "data", "->", "blindmarking", ")", "{", "$", "data", "->", "revealidentities", "=", "0", ";", "}", "if", "(", "!", "empty", "(", "$", "data", "->", "teamsubmissiongroupingid", ")", ")", "{", "$", "data", "->", "teamsubmissiongroupingid", "=", "$", "this", "->", "get_mappingid", "(", "'grouping'", ",", "$", "data", "->", "teamsubmissiongroupingid", ")", ";", "}", "else", "{", "$", "data", "->", "teamsubmissiongroupingid", "=", "0", ";", "}", "if", "(", "!", "isset", "(", "$", "data", "->", "cutoffdate", ")", ")", "{", "$", "data", "->", "cutoffdate", "=", "0", ";", "}", "if", "(", "!", "isset", "(", "$", "data", "->", "gradingduedate", ")", ")", "{", "$", "data", "->", "gradingduedate", "=", "0", ";", "}", "else", "{", "$", "data", "->", "gradingduedate", "=", "$", "this", "->", "apply_date_offset", "(", "$", "data", "->", "gradingduedate", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "data", "->", "markingworkflow", ")", ")", "{", "$", "data", "->", "markingworkflow", "=", "0", ";", "}", "if", "(", "!", "isset", "(", "$", "data", "->", "markingallocation", ")", ")", "{", "$", "data", "->", "markingallocation", "=", "0", ";", "}", "if", "(", "!", "isset", "(", "$", "data", "->", "preventsubmissionnotingroup", ")", ")", "{", "$", "data", "->", "preventsubmissionnotingroup", "=", "0", ";", "}", "if", "(", "!", "empty", "(", "$", "data", "->", "preventlatesubmissions", ")", ")", "{", "$", "data", "->", "cutoffdate", "=", "$", "data", "->", "duedate", ";", "}", "else", "{", "$", "data", "->", "cutoffdate", "=", "$", "this", "->", "apply_date_offset", "(", "$", "data", "->", "cutoffdate", ")", ";", "}", "if", "(", "$", "data", "->", "grade", "<", "0", ")", "{", "// Scale found, get mapping.", "$", "data", "->", "grade", "=", "-", "(", "$", "this", "->", "get_mappingid", "(", "'scale'", ",", "abs", "(", "$", "data", "->", "grade", ")", ")", ")", ";", "}", "$", "newitemid", "=", "$", "DB", "->", "insert_record", "(", "'assign'", ",", "$", "data", ")", ";", "$", "this", "->", "apply_activity_instance", "(", "$", "newitemid", ")", ";", "}" ]
Process an assign restore. @param object $data The data in object form @return void
[ "Process", "an", "assign", "restore", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/backup/moodle2/restore_assign_stepslib.php#L83-L146
213,126
moodle/moodle
mod/assign/backup/moodle2/restore_assign_stepslib.php
restore_assign_activity_structure_step.process_assign_userflag
protected function process_assign_userflag($data) { global $DB; $data = (object)$data; $oldid = $data->id; $data->assignment = $this->get_new_parentid('assign'); $data->userid = $this->get_mappingid('user', $data->userid); if (!empty($data->allocatedmarker)) { $data->allocatedmarker = $this->get_mappingid('user', $data->allocatedmarker); } if (!empty($data->extensionduedate)) { $data->extensionduedate = $this->apply_date_offset($data->extensionduedate); } else { $data->extensionduedate = 0; } // Flags mailed and locked need no translation on restore. $newitemid = $DB->insert_record('assign_user_flags', $data); }
php
protected function process_assign_userflag($data) { global $DB; $data = (object)$data; $oldid = $data->id; $data->assignment = $this->get_new_parentid('assign'); $data->userid = $this->get_mappingid('user', $data->userid); if (!empty($data->allocatedmarker)) { $data->allocatedmarker = $this->get_mappingid('user', $data->allocatedmarker); } if (!empty($data->extensionduedate)) { $data->extensionduedate = $this->apply_date_offset($data->extensionduedate); } else { $data->extensionduedate = 0; } // Flags mailed and locked need no translation on restore. $newitemid = $DB->insert_record('assign_user_flags', $data); }
[ "protected", "function", "process_assign_userflag", "(", "$", "data", ")", "{", "global", "$", "DB", ";", "$", "data", "=", "(", "object", ")", "$", "data", ";", "$", "oldid", "=", "$", "data", "->", "id", ";", "$", "data", "->", "assignment", "=", "$", "this", "->", "get_new_parentid", "(", "'assign'", ")", ";", "$", "data", "->", "userid", "=", "$", "this", "->", "get_mappingid", "(", "'user'", ",", "$", "data", "->", "userid", ")", ";", "if", "(", "!", "empty", "(", "$", "data", "->", "allocatedmarker", ")", ")", "{", "$", "data", "->", "allocatedmarker", "=", "$", "this", "->", "get_mappingid", "(", "'user'", ",", "$", "data", "->", "allocatedmarker", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "data", "->", "extensionduedate", ")", ")", "{", "$", "data", "->", "extensionduedate", "=", "$", "this", "->", "apply_date_offset", "(", "$", "data", "->", "extensionduedate", ")", ";", "}", "else", "{", "$", "data", "->", "extensionduedate", "=", "0", ";", "}", "// Flags mailed and locked need no translation on restore.", "$", "newitemid", "=", "$", "DB", "->", "insert_record", "(", "'assign_user_flags'", ",", "$", "data", ")", ";", "}" ]
Process a user_flags restore @param object $data The data in object form @return void
[ "Process", "a", "user_flags", "restore" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/backup/moodle2/restore_assign_stepslib.php#L194-L214
213,127
moodle/moodle
mod/assign/backup/moodle2/restore_assign_stepslib.php
restore_assign_activity_structure_step.process_assign_grade
protected function process_assign_grade($data) { global $DB; $data = (object)$data; $oldid = $data->id; $data->assignment = $this->get_new_parentid('assign'); $data->userid = $this->get_mappingid('user', $data->userid); $data->grader = $this->get_mappingid('user', $data->grader); // Handle flags restore to a different table (for upgrade from old backups). if (!empty($data->extensionduedate) || !empty($data->mailed) || !empty($data->locked)) { $flags = new stdClass(); $flags->assignment = $this->get_new_parentid('assign'); if (!empty($data->extensionduedate)) { $flags->extensionduedate = $this->apply_date_offset($data->extensionduedate); } if (!empty($data->mailed)) { $flags->mailed = $data->mailed; } if (!empty($data->locked)) { $flags->locked = $data->locked; } $flags->userid = $this->get_mappingid('user', $data->userid); $DB->insert_record('assign_user_flags', $flags); } // Fix null grades that were rescaled. if ($data->grade < 0 && $data->grade != ASSIGN_GRADE_NOT_SET) { $data->grade = ASSIGN_GRADE_NOT_SET; } $newitemid = $DB->insert_record('assign_grades', $data); // Note - the old contextid is required in order to be able to restore files stored in // sub plugin file areas attached to the gradeid. $this->set_mapping('grade', $oldid, $newitemid, false, null, $this->task->get_old_contextid()); $this->set_mapping(restore_gradingform_plugin::itemid_mapping('submissions'), $oldid, $newitemid); }
php
protected function process_assign_grade($data) { global $DB; $data = (object)$data; $oldid = $data->id; $data->assignment = $this->get_new_parentid('assign'); $data->userid = $this->get_mappingid('user', $data->userid); $data->grader = $this->get_mappingid('user', $data->grader); // Handle flags restore to a different table (for upgrade from old backups). if (!empty($data->extensionduedate) || !empty($data->mailed) || !empty($data->locked)) { $flags = new stdClass(); $flags->assignment = $this->get_new_parentid('assign'); if (!empty($data->extensionduedate)) { $flags->extensionduedate = $this->apply_date_offset($data->extensionduedate); } if (!empty($data->mailed)) { $flags->mailed = $data->mailed; } if (!empty($data->locked)) { $flags->locked = $data->locked; } $flags->userid = $this->get_mappingid('user', $data->userid); $DB->insert_record('assign_user_flags', $flags); } // Fix null grades that were rescaled. if ($data->grade < 0 && $data->grade != ASSIGN_GRADE_NOT_SET) { $data->grade = ASSIGN_GRADE_NOT_SET; } $newitemid = $DB->insert_record('assign_grades', $data); // Note - the old contextid is required in order to be able to restore files stored in // sub plugin file areas attached to the gradeid. $this->set_mapping('grade', $oldid, $newitemid, false, null, $this->task->get_old_contextid()); $this->set_mapping(restore_gradingform_plugin::itemid_mapping('submissions'), $oldid, $newitemid); }
[ "protected", "function", "process_assign_grade", "(", "$", "data", ")", "{", "global", "$", "DB", ";", "$", "data", "=", "(", "object", ")", "$", "data", ";", "$", "oldid", "=", "$", "data", "->", "id", ";", "$", "data", "->", "assignment", "=", "$", "this", "->", "get_new_parentid", "(", "'assign'", ")", ";", "$", "data", "->", "userid", "=", "$", "this", "->", "get_mappingid", "(", "'user'", ",", "$", "data", "->", "userid", ")", ";", "$", "data", "->", "grader", "=", "$", "this", "->", "get_mappingid", "(", "'user'", ",", "$", "data", "->", "grader", ")", ";", "// Handle flags restore to a different table (for upgrade from old backups).", "if", "(", "!", "empty", "(", "$", "data", "->", "extensionduedate", ")", "||", "!", "empty", "(", "$", "data", "->", "mailed", ")", "||", "!", "empty", "(", "$", "data", "->", "locked", ")", ")", "{", "$", "flags", "=", "new", "stdClass", "(", ")", ";", "$", "flags", "->", "assignment", "=", "$", "this", "->", "get_new_parentid", "(", "'assign'", ")", ";", "if", "(", "!", "empty", "(", "$", "data", "->", "extensionduedate", ")", ")", "{", "$", "flags", "->", "extensionduedate", "=", "$", "this", "->", "apply_date_offset", "(", "$", "data", "->", "extensionduedate", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "data", "->", "mailed", ")", ")", "{", "$", "flags", "->", "mailed", "=", "$", "data", "->", "mailed", ";", "}", "if", "(", "!", "empty", "(", "$", "data", "->", "locked", ")", ")", "{", "$", "flags", "->", "locked", "=", "$", "data", "->", "locked", ";", "}", "$", "flags", "->", "userid", "=", "$", "this", "->", "get_mappingid", "(", "'user'", ",", "$", "data", "->", "userid", ")", ";", "$", "DB", "->", "insert_record", "(", "'assign_user_flags'", ",", "$", "flags", ")", ";", "}", "// Fix null grades that were rescaled.", "if", "(", "$", "data", "->", "grade", "<", "0", "&&", "$", "data", "->", "grade", "!=", "ASSIGN_GRADE_NOT_SET", ")", "{", "$", "data", "->", "grade", "=", "ASSIGN_GRADE_NOT_SET", ";", "}", "$", "newitemid", "=", "$", "DB", "->", "insert_record", "(", "'assign_grades'", ",", "$", "data", ")", ";", "// Note - the old contextid is required in order to be able to restore files stored in", "// sub plugin file areas attached to the gradeid.", "$", "this", "->", "set_mapping", "(", "'grade'", ",", "$", "oldid", ",", "$", "newitemid", ",", "false", ",", "null", ",", "$", "this", "->", "task", "->", "get_old_contextid", "(", ")", ")", ";", "$", "this", "->", "set_mapping", "(", "restore_gradingform_plugin", "::", "itemid_mapping", "(", "'submissions'", ")", ",", "$", "oldid", ",", "$", "newitemid", ")", ";", "}" ]
Process a grade restore @param object $data The data in object form @return void
[ "Process", "a", "grade", "restore" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/backup/moodle2/restore_assign_stepslib.php#L221-L260
213,128
moodle/moodle
mod/assign/backup/moodle2/restore_assign_stepslib.php
restore_assign_activity_structure_step.process_assign_plugin_config
protected function process_assign_plugin_config($data) { global $DB; $data = (object)$data; $oldid = $data->id; $data->assignment = $this->get_new_parentid('assign'); $newitemid = $DB->insert_record('assign_plugin_config', $data); }
php
protected function process_assign_plugin_config($data) { global $DB; $data = (object)$data; $oldid = $data->id; $data->assignment = $this->get_new_parentid('assign'); $newitemid = $DB->insert_record('assign_plugin_config', $data); }
[ "protected", "function", "process_assign_plugin_config", "(", "$", "data", ")", "{", "global", "$", "DB", ";", "$", "data", "=", "(", "object", ")", "$", "data", ";", "$", "oldid", "=", "$", "data", "->", "id", ";", "$", "data", "->", "assignment", "=", "$", "this", "->", "get_new_parentid", "(", "'assign'", ")", ";", "$", "newitemid", "=", "$", "DB", "->", "insert_record", "(", "'assign_plugin_config'", ",", "$", "data", ")", ";", "}" ]
Process a plugin-config restore @param object $data The data in object form @return void
[ "Process", "a", "plugin", "-", "config", "restore" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/backup/moodle2/restore_assign_stepslib.php#L267-L276
213,129
moodle/moodle
mod/assign/backup/moodle2/restore_assign_stepslib.php
restore_assign_activity_structure_step.add_plugin_config_files
protected function add_plugin_config_files($subtype) { $dummyassign = new assign(null, null, null); $plugins = $dummyassign->load_plugins($subtype); foreach ($plugins as $plugin) { $component = $plugin->get_subtype() . '_' . $plugin->get_type(); $areas = $plugin->get_config_file_areas(); foreach ($areas as $area) { $this->add_related_files($component, $area, null); } } }
php
protected function add_plugin_config_files($subtype) { $dummyassign = new assign(null, null, null); $plugins = $dummyassign->load_plugins($subtype); foreach ($plugins as $plugin) { $component = $plugin->get_subtype() . '_' . $plugin->get_type(); $areas = $plugin->get_config_file_areas(); foreach ($areas as $area) { $this->add_related_files($component, $area, null); } } }
[ "protected", "function", "add_plugin_config_files", "(", "$", "subtype", ")", "{", "$", "dummyassign", "=", "new", "assign", "(", "null", ",", "null", ",", "null", ")", ";", "$", "plugins", "=", "$", "dummyassign", "->", "load_plugins", "(", "$", "subtype", ")", ";", "foreach", "(", "$", "plugins", "as", "$", "plugin", ")", "{", "$", "component", "=", "$", "plugin", "->", "get_subtype", "(", ")", ".", "'_'", ".", "$", "plugin", "->", "get_type", "(", ")", ";", "$", "areas", "=", "$", "plugin", "->", "get_config_file_areas", "(", ")", ";", "foreach", "(", "$", "areas", "as", "$", "area", ")", "{", "$", "this", "->", "add_related_files", "(", "$", "component", ",", "$", "area", ",", "null", ")", ";", "}", "}", "}" ]
Restore files from plugin configuration @param string $subtype the plugin type to handle @return void
[ "Restore", "files", "from", "plugin", "configuration" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/backup/moodle2/restore_assign_stepslib.php#L364-L374
213,130
moodle/moodle
mod/assign/backup/moodle2/restore_assign_stepslib.php
restore_assign_activity_structure_step.process_assign_override
protected function process_assign_override($data) { global $DB; $data = (object)$data; $oldid = $data->id; // Based on userinfo, we'll restore user overides or no. $userinfo = $this->get_setting_value('userinfo'); // Skip user overrides if we are not restoring userinfo. if (!$userinfo && !is_null($data->userid)) { return; } // Skip group overrides if we are not restoring groupinfo. $groupinfo = $this->get_setting_value('groups'); if (!$groupinfo && !is_null($data->groupid)) { return; } $data->assignid = $this->get_new_parentid('assign'); if (!is_null($data->userid)) { $data->userid = $this->get_mappingid('user', $data->userid); } if (!is_null($data->groupid)) { $data->groupid = $this->get_mappingid('group', $data->groupid); } $data->allowsubmissionsfromdate = $this->apply_date_offset($data->allowsubmissionsfromdate); $data->duedate = $this->apply_date_offset($data->duedate); $data->cutoffdate = $this->apply_date_offset($data->cutoffdate); $newitemid = $DB->insert_record('assign_overrides', $data); // Add mapping, restore of logs needs it. $this->set_mapping('assign_override', $oldid, $newitemid); }
php
protected function process_assign_override($data) { global $DB; $data = (object)$data; $oldid = $data->id; // Based on userinfo, we'll restore user overides or no. $userinfo = $this->get_setting_value('userinfo'); // Skip user overrides if we are not restoring userinfo. if (!$userinfo && !is_null($data->userid)) { return; } // Skip group overrides if we are not restoring groupinfo. $groupinfo = $this->get_setting_value('groups'); if (!$groupinfo && !is_null($data->groupid)) { return; } $data->assignid = $this->get_new_parentid('assign'); if (!is_null($data->userid)) { $data->userid = $this->get_mappingid('user', $data->userid); } if (!is_null($data->groupid)) { $data->groupid = $this->get_mappingid('group', $data->groupid); } $data->allowsubmissionsfromdate = $this->apply_date_offset($data->allowsubmissionsfromdate); $data->duedate = $this->apply_date_offset($data->duedate); $data->cutoffdate = $this->apply_date_offset($data->cutoffdate); $newitemid = $DB->insert_record('assign_overrides', $data); // Add mapping, restore of logs needs it. $this->set_mapping('assign_override', $oldid, $newitemid); }
[ "protected", "function", "process_assign_override", "(", "$", "data", ")", "{", "global", "$", "DB", ";", "$", "data", "=", "(", "object", ")", "$", "data", ";", "$", "oldid", "=", "$", "data", "->", "id", ";", "// Based on userinfo, we'll restore user overides or no.", "$", "userinfo", "=", "$", "this", "->", "get_setting_value", "(", "'userinfo'", ")", ";", "// Skip user overrides if we are not restoring userinfo.", "if", "(", "!", "$", "userinfo", "&&", "!", "is_null", "(", "$", "data", "->", "userid", ")", ")", "{", "return", ";", "}", "// Skip group overrides if we are not restoring groupinfo.", "$", "groupinfo", "=", "$", "this", "->", "get_setting_value", "(", "'groups'", ")", ";", "if", "(", "!", "$", "groupinfo", "&&", "!", "is_null", "(", "$", "data", "->", "groupid", ")", ")", "{", "return", ";", "}", "$", "data", "->", "assignid", "=", "$", "this", "->", "get_new_parentid", "(", "'assign'", ")", ";", "if", "(", "!", "is_null", "(", "$", "data", "->", "userid", ")", ")", "{", "$", "data", "->", "userid", "=", "$", "this", "->", "get_mappingid", "(", "'user'", ",", "$", "data", "->", "userid", ")", ";", "}", "if", "(", "!", "is_null", "(", "$", "data", "->", "groupid", ")", ")", "{", "$", "data", "->", "groupid", "=", "$", "this", "->", "get_mappingid", "(", "'group'", ",", "$", "data", "->", "groupid", ")", ";", "}", "$", "data", "->", "allowsubmissionsfromdate", "=", "$", "this", "->", "apply_date_offset", "(", "$", "data", "->", "allowsubmissionsfromdate", ")", ";", "$", "data", "->", "duedate", "=", "$", "this", "->", "apply_date_offset", "(", "$", "data", "->", "duedate", ")", ";", "$", "data", "->", "cutoffdate", "=", "$", "this", "->", "apply_date_offset", "(", "$", "data", "->", "cutoffdate", ")", ";", "$", "newitemid", "=", "$", "DB", "->", "insert_record", "(", "'assign_overrides'", ",", "$", "data", ")", ";", "// Add mapping, restore of logs needs it.", "$", "this", "->", "set_mapping", "(", "'assign_override'", ",", "$", "oldid", ",", "$", "newitemid", ")", ";", "}" ]
Process a assign override restore @param object $data The data in object form @return void
[ "Process", "a", "assign", "override", "restore" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/backup/moodle2/restore_assign_stepslib.php#L381-L418
213,131
moodle/moodle
mod/assign/backup/moodle2/restore_assign_stepslib.php
restore_assign_activity_structure_step.after_execute
protected function after_execute() { $this->add_related_files('mod_assign', 'intro', null); $this->add_related_files('mod_assign', 'introattachment', null); $this->add_plugin_config_files('assignsubmission'); $this->add_plugin_config_files('assignfeedback'); $this->set_latest_submission_field(); }
php
protected function after_execute() { $this->add_related_files('mod_assign', 'intro', null); $this->add_related_files('mod_assign', 'introattachment', null); $this->add_plugin_config_files('assignsubmission'); $this->add_plugin_config_files('assignfeedback'); $this->set_latest_submission_field(); }
[ "protected", "function", "after_execute", "(", ")", "{", "$", "this", "->", "add_related_files", "(", "'mod_assign'", ",", "'intro'", ",", "null", ")", ";", "$", "this", "->", "add_related_files", "(", "'mod_assign'", ",", "'introattachment'", ",", "null", ")", ";", "$", "this", "->", "add_plugin_config_files", "(", "'assignsubmission'", ")", ";", "$", "this", "->", "add_plugin_config_files", "(", "'assignfeedback'", ")", ";", "$", "this", "->", "set_latest_submission_field", "(", ")", ";", "}" ]
Once the database tables have been fully restored, restore the files @return void
[ "Once", "the", "database", "tables", "have", "been", "fully", "restored", "restore", "the", "files" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/backup/moodle2/restore_assign_stepslib.php#L424-L432
213,132
moodle/moodle
admin/tool/lp/classes/page_helper.php
page_helper.setup_for_course
public static function setup_for_course(moodle_url $url, $course, $subtitle = '') { global $PAGE; $context = context_course::instance($course->id); $PAGE->set_course($course); if (!empty($subtitle)) { $title = $subtitle; } else { $title = get_string('coursecompetencies', 'tool_lp'); } $returnurl = new moodle_url('/admin/tool/lp/coursecompetencies.php', array('courseid' => $course->id)); $heading = $context->get_context_name(); $PAGE->set_pagelayout('incourse'); $PAGE->set_url($url); $PAGE->set_title($title); $PAGE->set_heading($heading); if (!empty($subtitle)) { $PAGE->navbar->add(get_string('coursecompetencies', 'tool_lp'), $returnurl); // We're in a sub page without a specific template. $PAGE->navbar->add($subtitle, $url); } return array($title, $subtitle, $returnurl); }
php
public static function setup_for_course(moodle_url $url, $course, $subtitle = '') { global $PAGE; $context = context_course::instance($course->id); $PAGE->set_course($course); if (!empty($subtitle)) { $title = $subtitle; } else { $title = get_string('coursecompetencies', 'tool_lp'); } $returnurl = new moodle_url('/admin/tool/lp/coursecompetencies.php', array('courseid' => $course->id)); $heading = $context->get_context_name(); $PAGE->set_pagelayout('incourse'); $PAGE->set_url($url); $PAGE->set_title($title); $PAGE->set_heading($heading); if (!empty($subtitle)) { $PAGE->navbar->add(get_string('coursecompetencies', 'tool_lp'), $returnurl); // We're in a sub page without a specific template. $PAGE->navbar->add($subtitle, $url); } return array($title, $subtitle, $returnurl); }
[ "public", "static", "function", "setup_for_course", "(", "moodle_url", "$", "url", ",", "$", "course", ",", "$", "subtitle", "=", "''", ")", "{", "global", "$", "PAGE", ";", "$", "context", "=", "context_course", "::", "instance", "(", "$", "course", "->", "id", ")", ";", "$", "PAGE", "->", "set_course", "(", "$", "course", ")", ";", "if", "(", "!", "empty", "(", "$", "subtitle", ")", ")", "{", "$", "title", "=", "$", "subtitle", ";", "}", "else", "{", "$", "title", "=", "get_string", "(", "'coursecompetencies'", ",", "'tool_lp'", ")", ";", "}", "$", "returnurl", "=", "new", "moodle_url", "(", "'/admin/tool/lp/coursecompetencies.php'", ",", "array", "(", "'courseid'", "=>", "$", "course", "->", "id", ")", ")", ";", "$", "heading", "=", "$", "context", "->", "get_context_name", "(", ")", ";", "$", "PAGE", "->", "set_pagelayout", "(", "'incourse'", ")", ";", "$", "PAGE", "->", "set_url", "(", "$", "url", ")", ";", "$", "PAGE", "->", "set_title", "(", "$", "title", ")", ";", "$", "PAGE", "->", "set_heading", "(", "$", "heading", ")", ";", "if", "(", "!", "empty", "(", "$", "subtitle", ")", ")", "{", "$", "PAGE", "->", "navbar", "->", "add", "(", "get_string", "(", "'coursecompetencies'", ",", "'tool_lp'", ")", ",", "$", "returnurl", ")", ";", "// We're in a sub page without a specific template.", "$", "PAGE", "->", "navbar", "->", "add", "(", "$", "subtitle", ",", "$", "url", ")", ";", "}", "return", "array", "(", "$", "title", ",", "$", "subtitle", ",", "$", "returnurl", ")", ";", "}" ]
Set-up a course page. Example: list($title, $subtitle) = page_helper::setup_for_course($pagecontextid, $url, $course, $pagetitle); echo $OUTPUT->heading($title); echo $OUTPUT->heading($subtitle, 3); @param moodle_url $url The current page. @param stdClass $course The course. @param string $subtitle The title of the subpage, if any. @return array With the following: - Page title - Page sub title - Return URL (course competencies page)
[ "Set", "-", "up", "a", "course", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lp/classes/page_helper.php#L62-L90
213,133
moodle/moodle
admin/tool/lp/classes/page_helper.php
page_helper.setup_for_template
public static function setup_for_template($pagecontextid, moodle_url $url, $template = null, $subtitle = '', $returntype = null) { global $PAGE, $SITE; $pagecontext = context::instance_by_id($pagecontextid); $context = $pagecontext; if (!empty($template)) { $context = $template->get_context(); } $templatesurl = new moodle_url('/admin/tool/lp/learningplans.php', array('pagecontextid' => $pagecontextid)); $templateurl = null; if ($template) { $templateurl = new moodle_url('/admin/tool/lp/templatecompetencies.php', [ 'templateid' => $template->get('id'), 'pagecontextid' => $pagecontextid ]); } $returnurl = $templatesurl; if ($returntype != 'templates' && $templateurl) { $returnurl = $templateurl; } $PAGE->navigation->override_active_url($templatesurl); $PAGE->set_context($pagecontext); if (!empty($template)) { $title = format_string($template->get('shortname'), true, array('context' => $context)); } else { $title = get_string('templates', 'tool_lp'); } if ($pagecontext->contextlevel == CONTEXT_SYSTEM) { $heading = $SITE->fullname; } else if ($pagecontext->contextlevel == CONTEXT_COURSECAT) { $heading = $pagecontext->get_context_name(); } else { throw new coding_exception('Unexpected context!'); } $PAGE->set_pagelayout('admin'); $PAGE->set_url($url); $PAGE->set_title($title); $PAGE->set_heading($heading); if (!empty($template)) { $PAGE->navbar->add($title, $templateurl); if (!empty($subtitle)) { $PAGE->navbar->add($subtitle, $url); } } else if (!empty($subtitle)) { // We're in a sub page without a specific template. $PAGE->navbar->add($subtitle, $url); } return array($title, $subtitle, $returnurl); }
php
public static function setup_for_template($pagecontextid, moodle_url $url, $template = null, $subtitle = '', $returntype = null) { global $PAGE, $SITE; $pagecontext = context::instance_by_id($pagecontextid); $context = $pagecontext; if (!empty($template)) { $context = $template->get_context(); } $templatesurl = new moodle_url('/admin/tool/lp/learningplans.php', array('pagecontextid' => $pagecontextid)); $templateurl = null; if ($template) { $templateurl = new moodle_url('/admin/tool/lp/templatecompetencies.php', [ 'templateid' => $template->get('id'), 'pagecontextid' => $pagecontextid ]); } $returnurl = $templatesurl; if ($returntype != 'templates' && $templateurl) { $returnurl = $templateurl; } $PAGE->navigation->override_active_url($templatesurl); $PAGE->set_context($pagecontext); if (!empty($template)) { $title = format_string($template->get('shortname'), true, array('context' => $context)); } else { $title = get_string('templates', 'tool_lp'); } if ($pagecontext->contextlevel == CONTEXT_SYSTEM) { $heading = $SITE->fullname; } else if ($pagecontext->contextlevel == CONTEXT_COURSECAT) { $heading = $pagecontext->get_context_name(); } else { throw new coding_exception('Unexpected context!'); } $PAGE->set_pagelayout('admin'); $PAGE->set_url($url); $PAGE->set_title($title); $PAGE->set_heading($heading); if (!empty($template)) { $PAGE->navbar->add($title, $templateurl); if (!empty($subtitle)) { $PAGE->navbar->add($subtitle, $url); } } else if (!empty($subtitle)) { // We're in a sub page without a specific template. $PAGE->navbar->add($subtitle, $url); } return array($title, $subtitle, $returnurl); }
[ "public", "static", "function", "setup_for_template", "(", "$", "pagecontextid", ",", "moodle_url", "$", "url", ",", "$", "template", "=", "null", ",", "$", "subtitle", "=", "''", ",", "$", "returntype", "=", "null", ")", "{", "global", "$", "PAGE", ",", "$", "SITE", ";", "$", "pagecontext", "=", "context", "::", "instance_by_id", "(", "$", "pagecontextid", ")", ";", "$", "context", "=", "$", "pagecontext", ";", "if", "(", "!", "empty", "(", "$", "template", ")", ")", "{", "$", "context", "=", "$", "template", "->", "get_context", "(", ")", ";", "}", "$", "templatesurl", "=", "new", "moodle_url", "(", "'/admin/tool/lp/learningplans.php'", ",", "array", "(", "'pagecontextid'", "=>", "$", "pagecontextid", ")", ")", ";", "$", "templateurl", "=", "null", ";", "if", "(", "$", "template", ")", "{", "$", "templateurl", "=", "new", "moodle_url", "(", "'/admin/tool/lp/templatecompetencies.php'", ",", "[", "'templateid'", "=>", "$", "template", "->", "get", "(", "'id'", ")", ",", "'pagecontextid'", "=>", "$", "pagecontextid", "]", ")", ";", "}", "$", "returnurl", "=", "$", "templatesurl", ";", "if", "(", "$", "returntype", "!=", "'templates'", "&&", "$", "templateurl", ")", "{", "$", "returnurl", "=", "$", "templateurl", ";", "}", "$", "PAGE", "->", "navigation", "->", "override_active_url", "(", "$", "templatesurl", ")", ";", "$", "PAGE", "->", "set_context", "(", "$", "pagecontext", ")", ";", "if", "(", "!", "empty", "(", "$", "template", ")", ")", "{", "$", "title", "=", "format_string", "(", "$", "template", "->", "get", "(", "'shortname'", ")", ",", "true", ",", "array", "(", "'context'", "=>", "$", "context", ")", ")", ";", "}", "else", "{", "$", "title", "=", "get_string", "(", "'templates'", ",", "'tool_lp'", ")", ";", "}", "if", "(", "$", "pagecontext", "->", "contextlevel", "==", "CONTEXT_SYSTEM", ")", "{", "$", "heading", "=", "$", "SITE", "->", "fullname", ";", "}", "else", "if", "(", "$", "pagecontext", "->", "contextlevel", "==", "CONTEXT_COURSECAT", ")", "{", "$", "heading", "=", "$", "pagecontext", "->", "get_context_name", "(", ")", ";", "}", "else", "{", "throw", "new", "coding_exception", "(", "'Unexpected context!'", ")", ";", "}", "$", "PAGE", "->", "set_pagelayout", "(", "'admin'", ")", ";", "$", "PAGE", "->", "set_url", "(", "$", "url", ")", ";", "$", "PAGE", "->", "set_title", "(", "$", "title", ")", ";", "$", "PAGE", "->", "set_heading", "(", "$", "heading", ")", ";", "if", "(", "!", "empty", "(", "$", "template", ")", ")", "{", "$", "PAGE", "->", "navbar", "->", "add", "(", "$", "title", ",", "$", "templateurl", ")", ";", "if", "(", "!", "empty", "(", "$", "subtitle", ")", ")", "{", "$", "PAGE", "->", "navbar", "->", "add", "(", "$", "subtitle", ",", "$", "url", ")", ";", "}", "}", "else", "if", "(", "!", "empty", "(", "$", "subtitle", ")", ")", "{", "// We're in a sub page without a specific template.", "$", "PAGE", "->", "navbar", "->", "add", "(", "$", "subtitle", ",", "$", "url", ")", ";", "}", "return", "array", "(", "$", "title", ",", "$", "subtitle", ",", "$", "returnurl", ")", ";", "}" ]
Set-up a template page. Example: list($title, $subtitle) = page_helper::setup_for_template($pagecontextid, $url, $template, $pagetitle); echo $OUTPUT->heading($title); echo $OUTPUT->heading($subtitle, 3); @param int $pagecontextid The page context ID. @param moodle_url $url The current page. @param \core_competency\template $template The template, if any. @param string $subtitle The title of the subpage, if any. @param string $returntype The desired return page. @return array With the following: - Page title - Page sub title - Return URL
[ "Set", "-", "up", "a", "template", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lp/classes/page_helper.php#L110-L168
213,134
moodle/moodle
admin/tool/lp/classes/page_helper.php
page_helper.setup_for_plan
public static function setup_for_plan($userid, moodle_url $url, $plan = null, $subtitle = '', $returntype = null) { global $PAGE, $USER; // Check that the user is a valid user. $user = core_user::get_user($userid); if (!$user || !core_user::is_real_user($userid)) { throw new \moodle_exception('invaliduser', 'error'); } $context = context_user::instance($user->id); $plansurl = new moodle_url('/admin/tool/lp/plans.php', array('userid' => $userid)); $planurl = null; if ($plan) { $planurl = new moodle_url('/admin/tool/lp/plan.php', array('id' => $plan->get('id'))); } $returnurl = $plansurl; if ($returntype != 'plans' && $planurl) { $returnurl = $planurl; } $PAGE->navigation->override_active_url($plansurl); $PAGE->set_context($context); // If not his own plan, we want to extend the navigation for the user. $iscurrentuser = ($USER->id == $user->id); if (!$iscurrentuser) { $PAGE->navigation->extend_for_user($user); $PAGE->navigation->set_userid_for_parent_checks($user->id); } if (!empty($plan)) { $title = format_string($plan->get('name'), true, array('context' => $context)); } else { $title = get_string('learningplans', 'tool_lp'); } $PAGE->set_pagelayout('standard'); $PAGE->set_url($url); $PAGE->set_title($title); $PAGE->set_heading($title); if (!empty($plan)) { $PAGE->navbar->add($title, $planurl); if (!empty($subtitle)) { $PAGE->navbar->add($subtitle, $url); } } else if (!empty($subtitle)) { // We're in a sub page without a specific plan. $PAGE->navbar->add($subtitle, $url); } return array($title, $subtitle, $returnurl); }
php
public static function setup_for_plan($userid, moodle_url $url, $plan = null, $subtitle = '', $returntype = null) { global $PAGE, $USER; // Check that the user is a valid user. $user = core_user::get_user($userid); if (!$user || !core_user::is_real_user($userid)) { throw new \moodle_exception('invaliduser', 'error'); } $context = context_user::instance($user->id); $plansurl = new moodle_url('/admin/tool/lp/plans.php', array('userid' => $userid)); $planurl = null; if ($plan) { $planurl = new moodle_url('/admin/tool/lp/plan.php', array('id' => $plan->get('id'))); } $returnurl = $plansurl; if ($returntype != 'plans' && $planurl) { $returnurl = $planurl; } $PAGE->navigation->override_active_url($plansurl); $PAGE->set_context($context); // If not his own plan, we want to extend the navigation for the user. $iscurrentuser = ($USER->id == $user->id); if (!$iscurrentuser) { $PAGE->navigation->extend_for_user($user); $PAGE->navigation->set_userid_for_parent_checks($user->id); } if (!empty($plan)) { $title = format_string($plan->get('name'), true, array('context' => $context)); } else { $title = get_string('learningplans', 'tool_lp'); } $PAGE->set_pagelayout('standard'); $PAGE->set_url($url); $PAGE->set_title($title); $PAGE->set_heading($title); if (!empty($plan)) { $PAGE->navbar->add($title, $planurl); if (!empty($subtitle)) { $PAGE->navbar->add($subtitle, $url); } } else if (!empty($subtitle)) { // We're in a sub page without a specific plan. $PAGE->navbar->add($subtitle, $url); } return array($title, $subtitle, $returnurl); }
[ "public", "static", "function", "setup_for_plan", "(", "$", "userid", ",", "moodle_url", "$", "url", ",", "$", "plan", "=", "null", ",", "$", "subtitle", "=", "''", ",", "$", "returntype", "=", "null", ")", "{", "global", "$", "PAGE", ",", "$", "USER", ";", "// Check that the user is a valid user.", "$", "user", "=", "core_user", "::", "get_user", "(", "$", "userid", ")", ";", "if", "(", "!", "$", "user", "||", "!", "core_user", "::", "is_real_user", "(", "$", "userid", ")", ")", "{", "throw", "new", "\\", "moodle_exception", "(", "'invaliduser'", ",", "'error'", ")", ";", "}", "$", "context", "=", "context_user", "::", "instance", "(", "$", "user", "->", "id", ")", ";", "$", "plansurl", "=", "new", "moodle_url", "(", "'/admin/tool/lp/plans.php'", ",", "array", "(", "'userid'", "=>", "$", "userid", ")", ")", ";", "$", "planurl", "=", "null", ";", "if", "(", "$", "plan", ")", "{", "$", "planurl", "=", "new", "moodle_url", "(", "'/admin/tool/lp/plan.php'", ",", "array", "(", "'id'", "=>", "$", "plan", "->", "get", "(", "'id'", ")", ")", ")", ";", "}", "$", "returnurl", "=", "$", "plansurl", ";", "if", "(", "$", "returntype", "!=", "'plans'", "&&", "$", "planurl", ")", "{", "$", "returnurl", "=", "$", "planurl", ";", "}", "$", "PAGE", "->", "navigation", "->", "override_active_url", "(", "$", "plansurl", ")", ";", "$", "PAGE", "->", "set_context", "(", "$", "context", ")", ";", "// If not his own plan, we want to extend the navigation for the user.", "$", "iscurrentuser", "=", "(", "$", "USER", "->", "id", "==", "$", "user", "->", "id", ")", ";", "if", "(", "!", "$", "iscurrentuser", ")", "{", "$", "PAGE", "->", "navigation", "->", "extend_for_user", "(", "$", "user", ")", ";", "$", "PAGE", "->", "navigation", "->", "set_userid_for_parent_checks", "(", "$", "user", "->", "id", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "plan", ")", ")", "{", "$", "title", "=", "format_string", "(", "$", "plan", "->", "get", "(", "'name'", ")", ",", "true", ",", "array", "(", "'context'", "=>", "$", "context", ")", ")", ";", "}", "else", "{", "$", "title", "=", "get_string", "(", "'learningplans'", ",", "'tool_lp'", ")", ";", "}", "$", "PAGE", "->", "set_pagelayout", "(", "'standard'", ")", ";", "$", "PAGE", "->", "set_url", "(", "$", "url", ")", ";", "$", "PAGE", "->", "set_title", "(", "$", "title", ")", ";", "$", "PAGE", "->", "set_heading", "(", "$", "title", ")", ";", "if", "(", "!", "empty", "(", "$", "plan", ")", ")", "{", "$", "PAGE", "->", "navbar", "->", "add", "(", "$", "title", ",", "$", "planurl", ")", ";", "if", "(", "!", "empty", "(", "$", "subtitle", ")", ")", "{", "$", "PAGE", "->", "navbar", "->", "add", "(", "$", "subtitle", ",", "$", "url", ")", ";", "}", "}", "else", "if", "(", "!", "empty", "(", "$", "subtitle", ")", ")", "{", "// We're in a sub page without a specific plan.", "$", "PAGE", "->", "navbar", "->", "add", "(", "$", "subtitle", ",", "$", "url", ")", ";", "}", "return", "array", "(", "$", "title", ",", "$", "subtitle", ",", "$", "returnurl", ")", ";", "}" ]
Set-up a plan page. Example: list($title, $subtitle) = page_helper::setup_for_plan($url, $template, $pagetitle); echo $OUTPUT->heading($title); echo $OUTPUT->heading($subtitle, 3); @param int $userid The user ID. @param moodle_url $url The current page. @param \core_competency\plan $plan The plan, if any. @param string $subtitle The title of the subpage, if any. @param string $returntype The desired return page. @return array With the following: - Page title - Page sub title - Return URL (main plan page)
[ "Set", "-", "up", "a", "plan", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lp/classes/page_helper.php#L188-L242
213,135
moodle/moodle
admin/tool/lp/classes/page_helper.php
page_helper.setup_for_framework
public static function setup_for_framework($id, $pagecontextid, $framework = null, $returntype = null) { global $PAGE; // We keep the original context in the URLs, so that we remain in the same context. $url = new moodle_url("/admin/tool/lp/editcompetencyframework.php", array('id' => $id, 'pagecontextid' => $pagecontextid)); if ($returntype) { $url->param('return', $returntype); } $frameworksurl = new moodle_url('/admin/tool/lp/competencyframeworks.php', array('pagecontextid' => $pagecontextid)); $PAGE->navigation->override_active_url($frameworksurl); $title = get_string('competencies', 'core_competency'); if (empty($id)) { $pagetitle = get_string('competencyframeworks', 'tool_lp'); $pagesubtitle = get_string('addnewcompetencyframework', 'tool_lp'); $url->remove_params(array('id')); $PAGE->navbar->add($pagesubtitle, $url); } else { $pagetitle = $framework->get('shortname'); $pagesubtitle = get_string('editcompetencyframework', 'tool_lp'); if ($returntype == 'competencies') { $frameworksurl = new moodle_url('/admin/tool/lp/competencies.php', array( 'pagecontextid' => $pagecontextid, 'competencyframeworkid' => $id )); } else { $frameworksurl->param('competencyframeworkid', $id); } $PAGE->navbar->add($pagetitle, $frameworksurl); $PAGE->navbar->add($pagesubtitle, $url); } $PAGE->set_context(context::instance_by_id($pagecontextid)); $PAGE->set_pagelayout('admin'); $PAGE->set_url($url); $PAGE->set_title($title); $PAGE->set_heading($title); return array($pagetitle, $pagesubtitle, $url, $frameworksurl); }
php
public static function setup_for_framework($id, $pagecontextid, $framework = null, $returntype = null) { global $PAGE; // We keep the original context in the URLs, so that we remain in the same context. $url = new moodle_url("/admin/tool/lp/editcompetencyframework.php", array('id' => $id, 'pagecontextid' => $pagecontextid)); if ($returntype) { $url->param('return', $returntype); } $frameworksurl = new moodle_url('/admin/tool/lp/competencyframeworks.php', array('pagecontextid' => $pagecontextid)); $PAGE->navigation->override_active_url($frameworksurl); $title = get_string('competencies', 'core_competency'); if (empty($id)) { $pagetitle = get_string('competencyframeworks', 'tool_lp'); $pagesubtitle = get_string('addnewcompetencyframework', 'tool_lp'); $url->remove_params(array('id')); $PAGE->navbar->add($pagesubtitle, $url); } else { $pagetitle = $framework->get('shortname'); $pagesubtitle = get_string('editcompetencyframework', 'tool_lp'); if ($returntype == 'competencies') { $frameworksurl = new moodle_url('/admin/tool/lp/competencies.php', array( 'pagecontextid' => $pagecontextid, 'competencyframeworkid' => $id )); } else { $frameworksurl->param('competencyframeworkid', $id); } $PAGE->navbar->add($pagetitle, $frameworksurl); $PAGE->navbar->add($pagesubtitle, $url); } $PAGE->set_context(context::instance_by_id($pagecontextid)); $PAGE->set_pagelayout('admin'); $PAGE->set_url($url); $PAGE->set_title($title); $PAGE->set_heading($title); return array($pagetitle, $pagesubtitle, $url, $frameworksurl); }
[ "public", "static", "function", "setup_for_framework", "(", "$", "id", ",", "$", "pagecontextid", ",", "$", "framework", "=", "null", ",", "$", "returntype", "=", "null", ")", "{", "global", "$", "PAGE", ";", "// We keep the original context in the URLs, so that we remain in the same context.", "$", "url", "=", "new", "moodle_url", "(", "\"/admin/tool/lp/editcompetencyframework.php\"", ",", "array", "(", "'id'", "=>", "$", "id", ",", "'pagecontextid'", "=>", "$", "pagecontextid", ")", ")", ";", "if", "(", "$", "returntype", ")", "{", "$", "url", "->", "param", "(", "'return'", ",", "$", "returntype", ")", ";", "}", "$", "frameworksurl", "=", "new", "moodle_url", "(", "'/admin/tool/lp/competencyframeworks.php'", ",", "array", "(", "'pagecontextid'", "=>", "$", "pagecontextid", ")", ")", ";", "$", "PAGE", "->", "navigation", "->", "override_active_url", "(", "$", "frameworksurl", ")", ";", "$", "title", "=", "get_string", "(", "'competencies'", ",", "'core_competency'", ")", ";", "if", "(", "empty", "(", "$", "id", ")", ")", "{", "$", "pagetitle", "=", "get_string", "(", "'competencyframeworks'", ",", "'tool_lp'", ")", ";", "$", "pagesubtitle", "=", "get_string", "(", "'addnewcompetencyframework'", ",", "'tool_lp'", ")", ";", "$", "url", "->", "remove_params", "(", "array", "(", "'id'", ")", ")", ";", "$", "PAGE", "->", "navbar", "->", "add", "(", "$", "pagesubtitle", ",", "$", "url", ")", ";", "}", "else", "{", "$", "pagetitle", "=", "$", "framework", "->", "get", "(", "'shortname'", ")", ";", "$", "pagesubtitle", "=", "get_string", "(", "'editcompetencyframework'", ",", "'tool_lp'", ")", ";", "if", "(", "$", "returntype", "==", "'competencies'", ")", "{", "$", "frameworksurl", "=", "new", "moodle_url", "(", "'/admin/tool/lp/competencies.php'", ",", "array", "(", "'pagecontextid'", "=>", "$", "pagecontextid", ",", "'competencyframeworkid'", "=>", "$", "id", ")", ")", ";", "}", "else", "{", "$", "frameworksurl", "->", "param", "(", "'competencyframeworkid'", ",", "$", "id", ")", ";", "}", "$", "PAGE", "->", "navbar", "->", "add", "(", "$", "pagetitle", ",", "$", "frameworksurl", ")", ";", "$", "PAGE", "->", "navbar", "->", "add", "(", "$", "pagesubtitle", ",", "$", "url", ")", ";", "}", "$", "PAGE", "->", "set_context", "(", "context", "::", "instance_by_id", "(", "$", "pagecontextid", ")", ")", ";", "$", "PAGE", "->", "set_pagelayout", "(", "'admin'", ")", ";", "$", "PAGE", "->", "set_url", "(", "$", "url", ")", ";", "$", "PAGE", "->", "set_title", "(", "$", "title", ")", ";", "$", "PAGE", "->", "set_heading", "(", "$", "title", ")", ";", "return", "array", "(", "$", "pagetitle", ",", "$", "pagesubtitle", ",", "$", "url", ",", "$", "frameworksurl", ")", ";", "}" ]
Set-up a framework page. Example: list($pagetitle, $pagesubtitle, $url, $frameworksurl) = page_helper::setup_for_framework($id, $pagecontextid); echo $OUTPUT->heading($pagetitle); echo $OUTPUT->heading($pagesubtitle, 3); @param int $id The framework ID. @param int $pagecontextid The page context ID. @param \core_competency\competency_framework $framework The framework. @param string $returntype The desired return page. @return array With the following: - Page title - Page sub title - Page URL - Page framework URL
[ "Set", "-", "up", "a", "framework", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lp/classes/page_helper.php#L336-L376
213,136
moodle/moodle
admin/tool/lp/classes/page_helper.php
page_helper.setup_for_competency
public static function setup_for_competency($pagecontextid, moodle_url $url, $framework, $competency = null, $parent = null) { global $PAGE, $SITE; // Set page context. $pagecontext = context::instance_by_id($pagecontextid); $PAGE->set_context($pagecontext); // Set page heading. if ($pagecontext->contextlevel == CONTEXT_SYSTEM) { $heading = $SITE->fullname; } else if ($pagecontext->contextlevel == CONTEXT_COURSECAT) { $heading = $pagecontext->get_context_name(); } else { throw new coding_exception('Unexpected context!'); } $PAGE->set_heading($heading); // Set override active url. $frameworksurl = new moodle_url('/admin/tool/lp/competencyframeworks.php', ['pagecontextid' => $pagecontextid]); $PAGE->navigation->override_active_url($frameworksurl); // Set return url. $returnurloptions = [ 'competencyframeworkid' => $framework->get('id'), 'pagecontextid' => $pagecontextid ]; $returnurl = new moodle_url('/admin/tool/lp/competencies.php', $returnurloptions); $PAGE->navbar->add($framework->get('shortname'), $returnurl); // Set page layout. $PAGE->set_pagelayout('admin'); if (empty($competency)) { // Add mode. $title = format_string($framework->get('shortname'), true, ['context' => $pagecontext]); // Set the sub-title for add mode. $level = $parent ? $parent->get_level() + 1 : 1; $subtitle = get_string('taxonomy_add_' . $framework->get_taxonomy($level), 'tool_lp'); } else { // Edit mode. $title = format_string($competency->get('shortname'), true, ['context' => $competency->get_context()]); // Add competency name to breadcrumbs, if available. $PAGE->navbar->add($title); // Set the sub-title for edit mode. $subtitle = get_string('taxonomy_edit_' . $framework->get_taxonomy($competency->get_level()), 'tool_lp'); } // Set page title. $PAGE->set_title($title); // Set page url. $PAGE->set_url($url); // Add editing mode link to breadcrumbs, if available. if (!empty($subtitle)) { $PAGE->navbar->add($subtitle, $url); } return [$title, $subtitle, $returnurl]; }
php
public static function setup_for_competency($pagecontextid, moodle_url $url, $framework, $competency = null, $parent = null) { global $PAGE, $SITE; // Set page context. $pagecontext = context::instance_by_id($pagecontextid); $PAGE->set_context($pagecontext); // Set page heading. if ($pagecontext->contextlevel == CONTEXT_SYSTEM) { $heading = $SITE->fullname; } else if ($pagecontext->contextlevel == CONTEXT_COURSECAT) { $heading = $pagecontext->get_context_name(); } else { throw new coding_exception('Unexpected context!'); } $PAGE->set_heading($heading); // Set override active url. $frameworksurl = new moodle_url('/admin/tool/lp/competencyframeworks.php', ['pagecontextid' => $pagecontextid]); $PAGE->navigation->override_active_url($frameworksurl); // Set return url. $returnurloptions = [ 'competencyframeworkid' => $framework->get('id'), 'pagecontextid' => $pagecontextid ]; $returnurl = new moodle_url('/admin/tool/lp/competencies.php', $returnurloptions); $PAGE->navbar->add($framework->get('shortname'), $returnurl); // Set page layout. $PAGE->set_pagelayout('admin'); if (empty($competency)) { // Add mode. $title = format_string($framework->get('shortname'), true, ['context' => $pagecontext]); // Set the sub-title for add mode. $level = $parent ? $parent->get_level() + 1 : 1; $subtitle = get_string('taxonomy_add_' . $framework->get_taxonomy($level), 'tool_lp'); } else { // Edit mode. $title = format_string($competency->get('shortname'), true, ['context' => $competency->get_context()]); // Add competency name to breadcrumbs, if available. $PAGE->navbar->add($title); // Set the sub-title for edit mode. $subtitle = get_string('taxonomy_edit_' . $framework->get_taxonomy($competency->get_level()), 'tool_lp'); } // Set page title. $PAGE->set_title($title); // Set page url. $PAGE->set_url($url); // Add editing mode link to breadcrumbs, if available. if (!empty($subtitle)) { $PAGE->navbar->add($subtitle, $url); } return [$title, $subtitle, $returnurl]; }
[ "public", "static", "function", "setup_for_competency", "(", "$", "pagecontextid", ",", "moodle_url", "$", "url", ",", "$", "framework", ",", "$", "competency", "=", "null", ",", "$", "parent", "=", "null", ")", "{", "global", "$", "PAGE", ",", "$", "SITE", ";", "// Set page context.", "$", "pagecontext", "=", "context", "::", "instance_by_id", "(", "$", "pagecontextid", ")", ";", "$", "PAGE", "->", "set_context", "(", "$", "pagecontext", ")", ";", "// Set page heading.", "if", "(", "$", "pagecontext", "->", "contextlevel", "==", "CONTEXT_SYSTEM", ")", "{", "$", "heading", "=", "$", "SITE", "->", "fullname", ";", "}", "else", "if", "(", "$", "pagecontext", "->", "contextlevel", "==", "CONTEXT_COURSECAT", ")", "{", "$", "heading", "=", "$", "pagecontext", "->", "get_context_name", "(", ")", ";", "}", "else", "{", "throw", "new", "coding_exception", "(", "'Unexpected context!'", ")", ";", "}", "$", "PAGE", "->", "set_heading", "(", "$", "heading", ")", ";", "// Set override active url.", "$", "frameworksurl", "=", "new", "moodle_url", "(", "'/admin/tool/lp/competencyframeworks.php'", ",", "[", "'pagecontextid'", "=>", "$", "pagecontextid", "]", ")", ";", "$", "PAGE", "->", "navigation", "->", "override_active_url", "(", "$", "frameworksurl", ")", ";", "// Set return url.", "$", "returnurloptions", "=", "[", "'competencyframeworkid'", "=>", "$", "framework", "->", "get", "(", "'id'", ")", ",", "'pagecontextid'", "=>", "$", "pagecontextid", "]", ";", "$", "returnurl", "=", "new", "moodle_url", "(", "'/admin/tool/lp/competencies.php'", ",", "$", "returnurloptions", ")", ";", "$", "PAGE", "->", "navbar", "->", "add", "(", "$", "framework", "->", "get", "(", "'shortname'", ")", ",", "$", "returnurl", ")", ";", "// Set page layout.", "$", "PAGE", "->", "set_pagelayout", "(", "'admin'", ")", ";", "if", "(", "empty", "(", "$", "competency", ")", ")", "{", "// Add mode.", "$", "title", "=", "format_string", "(", "$", "framework", "->", "get", "(", "'shortname'", ")", ",", "true", ",", "[", "'context'", "=>", "$", "pagecontext", "]", ")", ";", "// Set the sub-title for add mode.", "$", "level", "=", "$", "parent", "?", "$", "parent", "->", "get_level", "(", ")", "+", "1", ":", "1", ";", "$", "subtitle", "=", "get_string", "(", "'taxonomy_add_'", ".", "$", "framework", "->", "get_taxonomy", "(", "$", "level", ")", ",", "'tool_lp'", ")", ";", "}", "else", "{", "// Edit mode.", "$", "title", "=", "format_string", "(", "$", "competency", "->", "get", "(", "'shortname'", ")", ",", "true", ",", "[", "'context'", "=>", "$", "competency", "->", "get_context", "(", ")", "]", ")", ";", "// Add competency name to breadcrumbs, if available.", "$", "PAGE", "->", "navbar", "->", "add", "(", "$", "title", ")", ";", "// Set the sub-title for edit mode.", "$", "subtitle", "=", "get_string", "(", "'taxonomy_edit_'", ".", "$", "framework", "->", "get_taxonomy", "(", "$", "competency", "->", "get_level", "(", ")", ")", ",", "'tool_lp'", ")", ";", "}", "// Set page title.", "$", "PAGE", "->", "set_title", "(", "$", "title", ")", ";", "// Set page url.", "$", "PAGE", "->", "set_url", "(", "$", "url", ")", ";", "// Add editing mode link to breadcrumbs, if available.", "if", "(", "!", "empty", "(", "$", "subtitle", ")", ")", "{", "$", "PAGE", "->", "navbar", "->", "add", "(", "$", "subtitle", ",", "$", "url", ")", ";", "}", "return", "[", "$", "title", ",", "$", "subtitle", ",", "$", "returnurl", "]", ";", "}" ]
Set-up a competency page. Example: list($title, $subtitle) = page_helper::setup_for_competency($pagecontextid, $url, $competency, $pagetitle); echo $OUTPUT->heading($title); echo $OUTPUT->heading($subtitle, 3); @param int $pagecontextid The page context ID. @param moodle_url $url The current page. @param \core_competency\competency_framework $framework The competency framework. @param \core_competency\competency $competency The competency, if any. @param \core_competency\competency $parent The parent competency, if any. @return array With the following: - Page title - Page sub title - Return URL (main competencies page) @throws coding_exception
[ "Set", "-", "up", "a", "competency", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lp/classes/page_helper.php#L397-L460
213,137
moodle/moodle
lib/classes/task/database_logger.php
database_logger.store_log_for_task
public static function store_log_for_task(task_base $task, string $logpath, bool $failed, int $dbreads, int $dbwrites, float $timestart, float $timeend) { global $DB; // Write this log to the database. $logdata = (object) [ 'type' => is_a($task, scheduled_task::class) ? self::TYPE_SCHEDULED : self::TYPE_ADHOC, 'component' => $task->get_component(), 'classname' => get_class($task), 'userid' => 0, 'timestart' => $timestart, 'timeend' => $timeend, 'dbreads' => $dbreads, 'dbwrites' => $dbwrites, 'result' => (int) $failed, 'output' => file_get_contents($logpath), ]; if (is_a($task, adhoc_task::class) && $userid = $task->get_userid()) { $logdata->userid = $userid; } $logdata->id = $DB->insert_record('task_log', $logdata); }
php
public static function store_log_for_task(task_base $task, string $logpath, bool $failed, int $dbreads, int $dbwrites, float $timestart, float $timeend) { global $DB; // Write this log to the database. $logdata = (object) [ 'type' => is_a($task, scheduled_task::class) ? self::TYPE_SCHEDULED : self::TYPE_ADHOC, 'component' => $task->get_component(), 'classname' => get_class($task), 'userid' => 0, 'timestart' => $timestart, 'timeend' => $timeend, 'dbreads' => $dbreads, 'dbwrites' => $dbwrites, 'result' => (int) $failed, 'output' => file_get_contents($logpath), ]; if (is_a($task, adhoc_task::class) && $userid = $task->get_userid()) { $logdata->userid = $userid; } $logdata->id = $DB->insert_record('task_log', $logdata); }
[ "public", "static", "function", "store_log_for_task", "(", "task_base", "$", "task", ",", "string", "$", "logpath", ",", "bool", "$", "failed", ",", "int", "$", "dbreads", ",", "int", "$", "dbwrites", ",", "float", "$", "timestart", ",", "float", "$", "timeend", ")", "{", "global", "$", "DB", ";", "// Write this log to the database.", "$", "logdata", "=", "(", "object", ")", "[", "'type'", "=>", "is_a", "(", "$", "task", ",", "scheduled_task", "::", "class", ")", "?", "self", "::", "TYPE_SCHEDULED", ":", "self", "::", "TYPE_ADHOC", ",", "'component'", "=>", "$", "task", "->", "get_component", "(", ")", ",", "'classname'", "=>", "get_class", "(", "$", "task", ")", ",", "'userid'", "=>", "0", ",", "'timestart'", "=>", "$", "timestart", ",", "'timeend'", "=>", "$", "timeend", ",", "'dbreads'", "=>", "$", "dbreads", ",", "'dbwrites'", "=>", "$", "dbwrites", ",", "'result'", "=>", "(", "int", ")", "$", "failed", ",", "'output'", "=>", "file_get_contents", "(", "$", "logpath", ")", ",", "]", ";", "if", "(", "is_a", "(", "$", "task", ",", "adhoc_task", "::", "class", ")", "&&", "$", "userid", "=", "$", "task", "->", "get_userid", "(", ")", ")", "{", "$", "logdata", "->", "userid", "=", "$", "userid", ";", "}", "$", "logdata", "->", "id", "=", "$", "DB", "->", "insert_record", "(", "'task_log'", ",", "$", "logdata", ")", ";", "}" ]
Store the log for the specified task. @param task_base $task The task that the log belongs to. @param string $logpath The path to the log on disk @param bool $failed Whether the task failed @param int $dbreads The number of DB reads @param int $dbwrites The number of DB writes @param float $timestart The start time of the task @param float $timeend The end time of the task
[ "Store", "the", "log", "for", "the", "specified", "task", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/task/database_logger.php#L62-L85
213,138
moodle/moodle
lib/classes/task/database_logger.php
database_logger.cleanup
public static function cleanup() { global $CFG, $DB; // Delete logs older than the retention period. $params = [ 'retentionperiod' => time() - $CFG->task_logretention, ]; $logids = $DB->get_fieldset_select('task_log', 'id', 'timestart < :retentionperiod', $params); self::delete_task_logs($logids); // Delete logs to retain a minimum number of logs. $sql = "SELECT classname FROM {task_log} GROUP BY classname HAVING COUNT(classname) > :retaincount"; $params = [ 'retaincount' => $CFG->task_logretainruns, ]; $classes = $DB->get_fieldset_sql($sql, $params); foreach ($classes as $classname) { $notinsql = ""; $params = [ 'classname' => $classname, ]; $retaincount = (int) $CFG->task_logretainruns; if ($retaincount) { $keeplogs = $DB->get_records('task_log', [ 'classname' => $classname, ], 'timestart DESC', 'id', 0, $retaincount); if ($keeplogs) { list($notinsql, $params) = $DB->get_in_or_equal(array_keys($keeplogs), SQL_PARAMS_NAMED, 'p', false); $params['classname'] = $classname; $notinsql = " AND id {$notinsql}"; } } $logids = $DB->get_fieldset_select('task_log', 'id', "classname = :classname {$notinsql}", $params); self::delete_task_logs($logids); } }
php
public static function cleanup() { global $CFG, $DB; // Delete logs older than the retention period. $params = [ 'retentionperiod' => time() - $CFG->task_logretention, ]; $logids = $DB->get_fieldset_select('task_log', 'id', 'timestart < :retentionperiod', $params); self::delete_task_logs($logids); // Delete logs to retain a minimum number of logs. $sql = "SELECT classname FROM {task_log} GROUP BY classname HAVING COUNT(classname) > :retaincount"; $params = [ 'retaincount' => $CFG->task_logretainruns, ]; $classes = $DB->get_fieldset_sql($sql, $params); foreach ($classes as $classname) { $notinsql = ""; $params = [ 'classname' => $classname, ]; $retaincount = (int) $CFG->task_logretainruns; if ($retaincount) { $keeplogs = $DB->get_records('task_log', [ 'classname' => $classname, ], 'timestart DESC', 'id', 0, $retaincount); if ($keeplogs) { list($notinsql, $params) = $DB->get_in_or_equal(array_keys($keeplogs), SQL_PARAMS_NAMED, 'p', false); $params['classname'] = $classname; $notinsql = " AND id {$notinsql}"; } } $logids = $DB->get_fieldset_select('task_log', 'id', "classname = :classname {$notinsql}", $params); self::delete_task_logs($logids); } }
[ "public", "static", "function", "cleanup", "(", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "// Delete logs older than the retention period.", "$", "params", "=", "[", "'retentionperiod'", "=>", "time", "(", ")", "-", "$", "CFG", "->", "task_logretention", ",", "]", ";", "$", "logids", "=", "$", "DB", "->", "get_fieldset_select", "(", "'task_log'", ",", "'id'", ",", "'timestart < :retentionperiod'", ",", "$", "params", ")", ";", "self", "::", "delete_task_logs", "(", "$", "logids", ")", ";", "// Delete logs to retain a minimum number of logs.", "$", "sql", "=", "\"SELECT classname FROM {task_log} GROUP BY classname HAVING COUNT(classname) > :retaincount\"", ";", "$", "params", "=", "[", "'retaincount'", "=>", "$", "CFG", "->", "task_logretainruns", ",", "]", ";", "$", "classes", "=", "$", "DB", "->", "get_fieldset_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "foreach", "(", "$", "classes", "as", "$", "classname", ")", "{", "$", "notinsql", "=", "\"\"", ";", "$", "params", "=", "[", "'classname'", "=>", "$", "classname", ",", "]", ";", "$", "retaincount", "=", "(", "int", ")", "$", "CFG", "->", "task_logretainruns", ";", "if", "(", "$", "retaincount", ")", "{", "$", "keeplogs", "=", "$", "DB", "->", "get_records", "(", "'task_log'", ",", "[", "'classname'", "=>", "$", "classname", ",", "]", ",", "'timestart DESC'", ",", "'id'", ",", "0", ",", "$", "retaincount", ")", ";", "if", "(", "$", "keeplogs", ")", "{", "list", "(", "$", "notinsql", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "array_keys", "(", "$", "keeplogs", ")", ",", "SQL_PARAMS_NAMED", ",", "'p'", ",", "false", ")", ";", "$", "params", "[", "'classname'", "]", "=", "$", "classname", ";", "$", "notinsql", "=", "\" AND id {$notinsql}\"", ";", "}", "}", "$", "logids", "=", "$", "DB", "->", "get_fieldset_select", "(", "'task_log'", ",", "'id'", ",", "\"classname = :classname {$notinsql}\"", ",", "$", "params", ")", ";", "self", "::", "delete_task_logs", "(", "$", "logids", ")", ";", "}", "}" ]
Cleanup old task logs.
[ "Cleanup", "old", "task", "logs", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/task/database_logger.php#L113-L152
213,139
moodle/moodle
lib/phpexcel/PHPExcel/Shared/Font.php
PHPExcel_Shared_Font.getTextWidthPixelsExact
public static function getTextWidthPixelsExact($text, PHPExcel_Style_Font $font, $rotation = 0) { if (!function_exists('imagettfbbox')) { throw new PHPExcel_Exception('GD library needs to be enabled'); } // font size should really be supplied in pixels in GD2, // but since GD2 seems to assume 72dpi, pixels and points are the same $fontFile = self::getTrueTypeFontFileFromFont($font); $textBox = imagettfbbox($font->getSize(), $rotation, $fontFile, $text); // Get corners positions $lowerLeftCornerX = $textBox[0]; // $lowerLeftCornerY = $textBox[1]; $lowerRightCornerX = $textBox[2]; // $lowerRightCornerY = $textBox[3]; $upperRightCornerX = $textBox[4]; // $upperRightCornerY = $textBox[5]; $upperLeftCornerX = $textBox[6]; // $upperLeftCornerY = $textBox[7]; // Consider the rotation when calculating the width $textWidth = max($lowerRightCornerX - $upperLeftCornerX, $upperRightCornerX - $lowerLeftCornerX); return $textWidth; }
php
public static function getTextWidthPixelsExact($text, PHPExcel_Style_Font $font, $rotation = 0) { if (!function_exists('imagettfbbox')) { throw new PHPExcel_Exception('GD library needs to be enabled'); } // font size should really be supplied in pixels in GD2, // but since GD2 seems to assume 72dpi, pixels and points are the same $fontFile = self::getTrueTypeFontFileFromFont($font); $textBox = imagettfbbox($font->getSize(), $rotation, $fontFile, $text); // Get corners positions $lowerLeftCornerX = $textBox[0]; // $lowerLeftCornerY = $textBox[1]; $lowerRightCornerX = $textBox[2]; // $lowerRightCornerY = $textBox[3]; $upperRightCornerX = $textBox[4]; // $upperRightCornerY = $textBox[5]; $upperLeftCornerX = $textBox[6]; // $upperLeftCornerY = $textBox[7]; // Consider the rotation when calculating the width $textWidth = max($lowerRightCornerX - $upperLeftCornerX, $upperRightCornerX - $lowerLeftCornerX); return $textWidth; }
[ "public", "static", "function", "getTextWidthPixelsExact", "(", "$", "text", ",", "PHPExcel_Style_Font", "$", "font", ",", "$", "rotation", "=", "0", ")", "{", "if", "(", "!", "function_exists", "(", "'imagettfbbox'", ")", ")", "{", "throw", "new", "PHPExcel_Exception", "(", "'GD library needs to be enabled'", ")", ";", "}", "// font size should really be supplied in pixels in GD2,", "// but since GD2 seems to assume 72dpi, pixels and points are the same", "$", "fontFile", "=", "self", "::", "getTrueTypeFontFileFromFont", "(", "$", "font", ")", ";", "$", "textBox", "=", "imagettfbbox", "(", "$", "font", "->", "getSize", "(", ")", ",", "$", "rotation", ",", "$", "fontFile", ",", "$", "text", ")", ";", "// Get corners positions", "$", "lowerLeftCornerX", "=", "$", "textBox", "[", "0", "]", ";", "// $lowerLeftCornerY = $textBox[1];", "$", "lowerRightCornerX", "=", "$", "textBox", "[", "2", "]", ";", "// $lowerRightCornerY = $textBox[3];", "$", "upperRightCornerX", "=", "$", "textBox", "[", "4", "]", ";", "// $upperRightCornerY = $textBox[5];", "$", "upperLeftCornerX", "=", "$", "textBox", "[", "6", "]", ";", "// $upperLeftCornerY = $textBox[7];", "// Consider the rotation when calculating the width", "$", "textWidth", "=", "max", "(", "$", "lowerRightCornerX", "-", "$", "upperLeftCornerX", ",", "$", "upperRightCornerX", "-", "$", "lowerLeftCornerX", ")", ";", "return", "$", "textWidth", ";", "}" ]
Get GD text width in pixels for a string of text in a certain font at a certain rotation angle @param string $text @param PHPExcel_Style_Font @param int $rotation @return int @throws PHPExcel_Exception
[ "Get", "GD", "text", "width", "in", "pixels", "for", "a", "string", "of", "text", "in", "a", "certain", "font", "at", "a", "certain", "rotation", "angle" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Shared/Font.php#L305-L330
213,140
moodle/moodle
lib/phpexcel/PHPExcel/Shared/Font.php
PHPExcel_Shared_Font.getTextWidthPixelsApprox
public static function getTextWidthPixelsApprox($columnText, PHPExcel_Style_Font $font = null, $rotation = 0) { $fontName = $font->getName(); $fontSize = $font->getSize(); // Calculate column width in pixels. We assume fixed glyph width. Result varies with font name and size. switch ($fontName) { case 'Calibri': // value 8.26 was found via interpolation by inspecting real Excel files with Calibri 11 font. $columnWidth = (int) (8.26 * PHPExcel_Shared_String::CountCharacters($columnText)); $columnWidth = $columnWidth * $fontSize / 11; // extrapolate from font size break; case 'Arial': // value 7 was found via interpolation by inspecting real Excel files with Arial 10 font. // $columnWidth = (int) (7 * PHPExcel_Shared_String::CountCharacters($columnText)); // value 8 was set because of experience in different exports at Arial 10 font. $columnWidth = (int) (8 * PHPExcel_Shared_String::CountCharacters($columnText)); $columnWidth = $columnWidth * $fontSize / 10; // extrapolate from font size break; case 'Verdana': // value 8 was found via interpolation by inspecting real Excel files with Verdana 10 font. $columnWidth = (int) (8 * PHPExcel_Shared_String::CountCharacters($columnText)); $columnWidth = $columnWidth * $fontSize / 10; // extrapolate from font size break; default: // just assume Calibri $columnWidth = (int) (8.26 * PHPExcel_Shared_String::CountCharacters($columnText)); $columnWidth = $columnWidth * $fontSize / 11; // extrapolate from font size break; } // Calculate approximate rotated column width if ($rotation !== 0) { if ($rotation == -165) { // stacked text $columnWidth = 4; // approximation } else { // rotated text $columnWidth = $columnWidth * cos(deg2rad($rotation)) + $fontSize * abs(sin(deg2rad($rotation))) / 5; // approximation } } // pixel width is an integer return (int) $columnWidth; }
php
public static function getTextWidthPixelsApprox($columnText, PHPExcel_Style_Font $font = null, $rotation = 0) { $fontName = $font->getName(); $fontSize = $font->getSize(); // Calculate column width in pixels. We assume fixed glyph width. Result varies with font name and size. switch ($fontName) { case 'Calibri': // value 8.26 was found via interpolation by inspecting real Excel files with Calibri 11 font. $columnWidth = (int) (8.26 * PHPExcel_Shared_String::CountCharacters($columnText)); $columnWidth = $columnWidth * $fontSize / 11; // extrapolate from font size break; case 'Arial': // value 7 was found via interpolation by inspecting real Excel files with Arial 10 font. // $columnWidth = (int) (7 * PHPExcel_Shared_String::CountCharacters($columnText)); // value 8 was set because of experience in different exports at Arial 10 font. $columnWidth = (int) (8 * PHPExcel_Shared_String::CountCharacters($columnText)); $columnWidth = $columnWidth * $fontSize / 10; // extrapolate from font size break; case 'Verdana': // value 8 was found via interpolation by inspecting real Excel files with Verdana 10 font. $columnWidth = (int) (8 * PHPExcel_Shared_String::CountCharacters($columnText)); $columnWidth = $columnWidth * $fontSize / 10; // extrapolate from font size break; default: // just assume Calibri $columnWidth = (int) (8.26 * PHPExcel_Shared_String::CountCharacters($columnText)); $columnWidth = $columnWidth * $fontSize / 11; // extrapolate from font size break; } // Calculate approximate rotated column width if ($rotation !== 0) { if ($rotation == -165) { // stacked text $columnWidth = 4; // approximation } else { // rotated text $columnWidth = $columnWidth * cos(deg2rad($rotation)) + $fontSize * abs(sin(deg2rad($rotation))) / 5; // approximation } } // pixel width is an integer return (int) $columnWidth; }
[ "public", "static", "function", "getTextWidthPixelsApprox", "(", "$", "columnText", ",", "PHPExcel_Style_Font", "$", "font", "=", "null", ",", "$", "rotation", "=", "0", ")", "{", "$", "fontName", "=", "$", "font", "->", "getName", "(", ")", ";", "$", "fontSize", "=", "$", "font", "->", "getSize", "(", ")", ";", "// Calculate column width in pixels. We assume fixed glyph width. Result varies with font name and size.", "switch", "(", "$", "fontName", ")", "{", "case", "'Calibri'", ":", "// value 8.26 was found via interpolation by inspecting real Excel files with Calibri 11 font.", "$", "columnWidth", "=", "(", "int", ")", "(", "8.26", "*", "PHPExcel_Shared_String", "::", "CountCharacters", "(", "$", "columnText", ")", ")", ";", "$", "columnWidth", "=", "$", "columnWidth", "*", "$", "fontSize", "/", "11", ";", "// extrapolate from font size", "break", ";", "case", "'Arial'", ":", "// value 7 was found via interpolation by inspecting real Excel files with Arial 10 font.", "// $columnWidth = (int) (7 * PHPExcel_Shared_String::CountCharacters($columnText));", "// value 8 was set because of experience in different exports at Arial 10 font.", "$", "columnWidth", "=", "(", "int", ")", "(", "8", "*", "PHPExcel_Shared_String", "::", "CountCharacters", "(", "$", "columnText", ")", ")", ";", "$", "columnWidth", "=", "$", "columnWidth", "*", "$", "fontSize", "/", "10", ";", "// extrapolate from font size", "break", ";", "case", "'Verdana'", ":", "// value 8 was found via interpolation by inspecting real Excel files with Verdana 10 font.", "$", "columnWidth", "=", "(", "int", ")", "(", "8", "*", "PHPExcel_Shared_String", "::", "CountCharacters", "(", "$", "columnText", ")", ")", ";", "$", "columnWidth", "=", "$", "columnWidth", "*", "$", "fontSize", "/", "10", ";", "// extrapolate from font size", "break", ";", "default", ":", "// just assume Calibri", "$", "columnWidth", "=", "(", "int", ")", "(", "8.26", "*", "PHPExcel_Shared_String", "::", "CountCharacters", "(", "$", "columnText", ")", ")", ";", "$", "columnWidth", "=", "$", "columnWidth", "*", "$", "fontSize", "/", "11", ";", "// extrapolate from font size", "break", ";", "}", "// Calculate approximate rotated column width", "if", "(", "$", "rotation", "!==", "0", ")", "{", "if", "(", "$", "rotation", "==", "-", "165", ")", "{", "// stacked text", "$", "columnWidth", "=", "4", ";", "// approximation", "}", "else", "{", "// rotated text", "$", "columnWidth", "=", "$", "columnWidth", "*", "cos", "(", "deg2rad", "(", "$", "rotation", ")", ")", "+", "$", "fontSize", "*", "abs", "(", "sin", "(", "deg2rad", "(", "$", "rotation", ")", ")", ")", "/", "5", ";", "// approximation", "}", "}", "// pixel width is an integer", "return", "(", "int", ")", "$", "columnWidth", ";", "}" ]
Get approximate width in pixels for a string of text in a certain font at a certain rotation angle @param string $columnText @param PHPExcel_Style_Font $font @param int $rotation @return int Text width in pixels (no padding added)
[ "Get", "approximate", "width", "in", "pixels", "for", "a", "string", "of", "text", "in", "a", "certain", "font", "at", "a", "certain", "rotation", "angle" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Shared/Font.php#L340-L388
213,141
moodle/moodle
lib/phpexcel/PHPExcel/Shared/Font.php
PHPExcel_Shared_Font.getCharsetFromFontName
public static function getCharsetFromFontName($name) { switch ($name) { // Add more cases. Check FONT records in real Excel files. case 'EucrosiaUPC': return self::CHARSET_ANSI_THAI; case 'Wingdings': return self::CHARSET_SYMBOL; case 'Wingdings 2': return self::CHARSET_SYMBOL; case 'Wingdings 3': return self::CHARSET_SYMBOL; default: return self::CHARSET_ANSI_LATIN; } }
php
public static function getCharsetFromFontName($name) { switch ($name) { // Add more cases. Check FONT records in real Excel files. case 'EucrosiaUPC': return self::CHARSET_ANSI_THAI; case 'Wingdings': return self::CHARSET_SYMBOL; case 'Wingdings 2': return self::CHARSET_SYMBOL; case 'Wingdings 3': return self::CHARSET_SYMBOL; default: return self::CHARSET_ANSI_LATIN; } }
[ "public", "static", "function", "getCharsetFromFontName", "(", "$", "name", ")", "{", "switch", "(", "$", "name", ")", "{", "// Add more cases. Check FONT records in real Excel files.", "case", "'EucrosiaUPC'", ":", "return", "self", "::", "CHARSET_ANSI_THAI", ";", "case", "'Wingdings'", ":", "return", "self", "::", "CHARSET_SYMBOL", ";", "case", "'Wingdings 2'", ":", "return", "self", "::", "CHARSET_SYMBOL", ";", "case", "'Wingdings 3'", ":", "return", "self", "::", "CHARSET_SYMBOL", ";", "default", ":", "return", "self", "::", "CHARSET_ANSI_LATIN", ";", "}", "}" ]
Returns the associated charset for the font name. @param string $name Font name @return int Character set code
[ "Returns", "the", "associated", "charset", "for", "the", "font", "name", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Shared/Font.php#L541-L556
213,142
moodle/moodle
lib/phpexcel/PHPExcel/Shared/Font.php
PHPExcel_Shared_Font.getDefaultRowHeightByFont
public static function getDefaultRowHeightByFont(PHPExcel_Style_Font $font) { switch ($font->getName()) { case 'Arial': switch ($font->getSize()) { case 10: // inspection of Arial 10 workbook says 12.75pt ~17px $rowHeight = 12.75; break; case 9: // inspection of Arial 9 workbook says 12.00pt ~16px $rowHeight = 12; break; case 8: // inspection of Arial 8 workbook says 11.25pt ~15px $rowHeight = 11.25; break; case 7: // inspection of Arial 7 workbook says 9.00pt ~12px $rowHeight = 9; break; case 6: case 5: // inspection of Arial 5,6 workbook says 8.25pt ~11px $rowHeight = 8.25; break; case 4: // inspection of Arial 4 workbook says 6.75pt ~9px $rowHeight = 6.75; break; case 3: // inspection of Arial 3 workbook says 6.00pt ~8px $rowHeight = 6; break; case 2: case 1: // inspection of Arial 1,2 workbook says 5.25pt ~7px $rowHeight = 5.25; break; default: // use Arial 10 workbook as an approximation, extrapolation $rowHeight = 12.75 * $font->getSize() / 10; break; } break; case 'Calibri': switch ($font->getSize()) { case 11: // inspection of Calibri 11 workbook says 15.00pt ~20px $rowHeight = 15; break; case 10: // inspection of Calibri 10 workbook says 12.75pt ~17px $rowHeight = 12.75; break; case 9: // inspection of Calibri 9 workbook says 12.00pt ~16px $rowHeight = 12; break; case 8: // inspection of Calibri 8 workbook says 11.25pt ~15px $rowHeight = 11.25; break; case 7: // inspection of Calibri 7 workbook says 9.00pt ~12px $rowHeight = 9; break; case 6: case 5: // inspection of Calibri 5,6 workbook says 8.25pt ~11px $rowHeight = 8.25; break; case 4: // inspection of Calibri 4 workbook says 6.75pt ~9px $rowHeight = 6.75; break; case 3: // inspection of Calibri 3 workbook says 6.00pt ~8px $rowHeight = 6.00; break; case 2: case 1: // inspection of Calibri 1,2 workbook says 5.25pt ~7px $rowHeight = 5.25; break; default: // use Calibri 11 workbook as an approximation, extrapolation $rowHeight = 15 * $font->getSize() / 11; break; } break; case 'Verdana': switch ($font->getSize()) { case 10: // inspection of Verdana 10 workbook says 12.75pt ~17px $rowHeight = 12.75; break; case 9: // inspection of Verdana 9 workbook says 11.25pt ~15px $rowHeight = 11.25; break; case 8: // inspection of Verdana 8 workbook says 10.50pt ~14px $rowHeight = 10.50; break; case 7: // inspection of Verdana 7 workbook says 9.00pt ~12px $rowHeight = 9.00; break; case 6: case 5: // inspection of Verdana 5,6 workbook says 8.25pt ~11px $rowHeight = 8.25; break; case 4: // inspection of Verdana 4 workbook says 6.75pt ~9px $rowHeight = 6.75; break; case 3: // inspection of Verdana 3 workbook says 6.00pt ~8px $rowHeight = 6; break; case 2: case 1: // inspection of Verdana 1,2 workbook says 5.25pt ~7px $rowHeight = 5.25; break; default: // use Verdana 10 workbook as an approximation, extrapolation $rowHeight = 12.75 * $font->getSize() / 10; break; } break; default: // just use Calibri as an approximation $rowHeight = 15 * $font->getSize() / 11; break; } return $rowHeight; }
php
public static function getDefaultRowHeightByFont(PHPExcel_Style_Font $font) { switch ($font->getName()) { case 'Arial': switch ($font->getSize()) { case 10: // inspection of Arial 10 workbook says 12.75pt ~17px $rowHeight = 12.75; break; case 9: // inspection of Arial 9 workbook says 12.00pt ~16px $rowHeight = 12; break; case 8: // inspection of Arial 8 workbook says 11.25pt ~15px $rowHeight = 11.25; break; case 7: // inspection of Arial 7 workbook says 9.00pt ~12px $rowHeight = 9; break; case 6: case 5: // inspection of Arial 5,6 workbook says 8.25pt ~11px $rowHeight = 8.25; break; case 4: // inspection of Arial 4 workbook says 6.75pt ~9px $rowHeight = 6.75; break; case 3: // inspection of Arial 3 workbook says 6.00pt ~8px $rowHeight = 6; break; case 2: case 1: // inspection of Arial 1,2 workbook says 5.25pt ~7px $rowHeight = 5.25; break; default: // use Arial 10 workbook as an approximation, extrapolation $rowHeight = 12.75 * $font->getSize() / 10; break; } break; case 'Calibri': switch ($font->getSize()) { case 11: // inspection of Calibri 11 workbook says 15.00pt ~20px $rowHeight = 15; break; case 10: // inspection of Calibri 10 workbook says 12.75pt ~17px $rowHeight = 12.75; break; case 9: // inspection of Calibri 9 workbook says 12.00pt ~16px $rowHeight = 12; break; case 8: // inspection of Calibri 8 workbook says 11.25pt ~15px $rowHeight = 11.25; break; case 7: // inspection of Calibri 7 workbook says 9.00pt ~12px $rowHeight = 9; break; case 6: case 5: // inspection of Calibri 5,6 workbook says 8.25pt ~11px $rowHeight = 8.25; break; case 4: // inspection of Calibri 4 workbook says 6.75pt ~9px $rowHeight = 6.75; break; case 3: // inspection of Calibri 3 workbook says 6.00pt ~8px $rowHeight = 6.00; break; case 2: case 1: // inspection of Calibri 1,2 workbook says 5.25pt ~7px $rowHeight = 5.25; break; default: // use Calibri 11 workbook as an approximation, extrapolation $rowHeight = 15 * $font->getSize() / 11; break; } break; case 'Verdana': switch ($font->getSize()) { case 10: // inspection of Verdana 10 workbook says 12.75pt ~17px $rowHeight = 12.75; break; case 9: // inspection of Verdana 9 workbook says 11.25pt ~15px $rowHeight = 11.25; break; case 8: // inspection of Verdana 8 workbook says 10.50pt ~14px $rowHeight = 10.50; break; case 7: // inspection of Verdana 7 workbook says 9.00pt ~12px $rowHeight = 9.00; break; case 6: case 5: // inspection of Verdana 5,6 workbook says 8.25pt ~11px $rowHeight = 8.25; break; case 4: // inspection of Verdana 4 workbook says 6.75pt ~9px $rowHeight = 6.75; break; case 3: // inspection of Verdana 3 workbook says 6.00pt ~8px $rowHeight = 6; break; case 2: case 1: // inspection of Verdana 1,2 workbook says 5.25pt ~7px $rowHeight = 5.25; break; default: // use Verdana 10 workbook as an approximation, extrapolation $rowHeight = 12.75 * $font->getSize() / 10; break; } break; default: // just use Calibri as an approximation $rowHeight = 15 * $font->getSize() / 11; break; } return $rowHeight; }
[ "public", "static", "function", "getDefaultRowHeightByFont", "(", "PHPExcel_Style_Font", "$", "font", ")", "{", "switch", "(", "$", "font", "->", "getName", "(", ")", ")", "{", "case", "'Arial'", ":", "switch", "(", "$", "font", "->", "getSize", "(", ")", ")", "{", "case", "10", ":", "// inspection of Arial 10 workbook says 12.75pt ~17px", "$", "rowHeight", "=", "12.75", ";", "break", ";", "case", "9", ":", "// inspection of Arial 9 workbook says 12.00pt ~16px", "$", "rowHeight", "=", "12", ";", "break", ";", "case", "8", ":", "// inspection of Arial 8 workbook says 11.25pt ~15px", "$", "rowHeight", "=", "11.25", ";", "break", ";", "case", "7", ":", "// inspection of Arial 7 workbook says 9.00pt ~12px", "$", "rowHeight", "=", "9", ";", "break", ";", "case", "6", ":", "case", "5", ":", "// inspection of Arial 5,6 workbook says 8.25pt ~11px", "$", "rowHeight", "=", "8.25", ";", "break", ";", "case", "4", ":", "// inspection of Arial 4 workbook says 6.75pt ~9px", "$", "rowHeight", "=", "6.75", ";", "break", ";", "case", "3", ":", "// inspection of Arial 3 workbook says 6.00pt ~8px", "$", "rowHeight", "=", "6", ";", "break", ";", "case", "2", ":", "case", "1", ":", "// inspection of Arial 1,2 workbook says 5.25pt ~7px", "$", "rowHeight", "=", "5.25", ";", "break", ";", "default", ":", "// use Arial 10 workbook as an approximation, extrapolation", "$", "rowHeight", "=", "12.75", "*", "$", "font", "->", "getSize", "(", ")", "/", "10", ";", "break", ";", "}", "break", ";", "case", "'Calibri'", ":", "switch", "(", "$", "font", "->", "getSize", "(", ")", ")", "{", "case", "11", ":", "// inspection of Calibri 11 workbook says 15.00pt ~20px", "$", "rowHeight", "=", "15", ";", "break", ";", "case", "10", ":", "// inspection of Calibri 10 workbook says 12.75pt ~17px", "$", "rowHeight", "=", "12.75", ";", "break", ";", "case", "9", ":", "// inspection of Calibri 9 workbook says 12.00pt ~16px", "$", "rowHeight", "=", "12", ";", "break", ";", "case", "8", ":", "// inspection of Calibri 8 workbook says 11.25pt ~15px", "$", "rowHeight", "=", "11.25", ";", "break", ";", "case", "7", ":", "// inspection of Calibri 7 workbook says 9.00pt ~12px", "$", "rowHeight", "=", "9", ";", "break", ";", "case", "6", ":", "case", "5", ":", "// inspection of Calibri 5,6 workbook says 8.25pt ~11px", "$", "rowHeight", "=", "8.25", ";", "break", ";", "case", "4", ":", "// inspection of Calibri 4 workbook says 6.75pt ~9px", "$", "rowHeight", "=", "6.75", ";", "break", ";", "case", "3", ":", "// inspection of Calibri 3 workbook says 6.00pt ~8px", "$", "rowHeight", "=", "6.00", ";", "break", ";", "case", "2", ":", "case", "1", ":", "// inspection of Calibri 1,2 workbook says 5.25pt ~7px", "$", "rowHeight", "=", "5.25", ";", "break", ";", "default", ":", "// use Calibri 11 workbook as an approximation, extrapolation", "$", "rowHeight", "=", "15", "*", "$", "font", "->", "getSize", "(", ")", "/", "11", ";", "break", ";", "}", "break", ";", "case", "'Verdana'", ":", "switch", "(", "$", "font", "->", "getSize", "(", ")", ")", "{", "case", "10", ":", "// inspection of Verdana 10 workbook says 12.75pt ~17px", "$", "rowHeight", "=", "12.75", ";", "break", ";", "case", "9", ":", "// inspection of Verdana 9 workbook says 11.25pt ~15px", "$", "rowHeight", "=", "11.25", ";", "break", ";", "case", "8", ":", "// inspection of Verdana 8 workbook says 10.50pt ~14px", "$", "rowHeight", "=", "10.50", ";", "break", ";", "case", "7", ":", "// inspection of Verdana 7 workbook says 9.00pt ~12px", "$", "rowHeight", "=", "9.00", ";", "break", ";", "case", "6", ":", "case", "5", ":", "// inspection of Verdana 5,6 workbook says 8.25pt ~11px", "$", "rowHeight", "=", "8.25", ";", "break", ";", "case", "4", ":", "// inspection of Verdana 4 workbook says 6.75pt ~9px", "$", "rowHeight", "=", "6.75", ";", "break", ";", "case", "3", ":", "// inspection of Verdana 3 workbook says 6.00pt ~8px", "$", "rowHeight", "=", "6", ";", "break", ";", "case", "2", ":", "case", "1", ":", "// inspection of Verdana 1,2 workbook says 5.25pt ~7px", "$", "rowHeight", "=", "5.25", ";", "break", ";", "default", ":", "// use Verdana 10 workbook as an approximation, extrapolation", "$", "rowHeight", "=", "12.75", "*", "$", "font", "->", "getSize", "(", ")", "/", "10", ";", "break", ";", "}", "break", ";", "default", ":", "// just use Calibri as an approximation", "$", "rowHeight", "=", "15", "*", "$", "font", "->", "getSize", "(", ")", "/", "11", ";", "break", ";", "}", "return", "$", "rowHeight", ";", "}" ]
Get the effective row height for rows without a row dimension or rows with height -1 For example, for Calibri 11 this is 15 points @param PHPExcel_Style_Font $font The workbooks default font @return float Row height in points
[ "Get", "the", "effective", "row", "height", "for", "rows", "without", "a", "row", "dimension", "or", "rows", "with", "height", "-", "1", "For", "example", "for", "Calibri", "11", "this", "is", "15", "points" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Shared/Font.php#L598-L740
213,143
moodle/moodle
question/type/calculatedmulti/backup/moodle2/restore_qtype_calculatedmulti_plugin.class.php
restore_qtype_calculatedmulti_plugin.recode_legacy_state_answer
public function recode_legacy_state_answer($state) { $answer = $state->answer; $result = ''; // Datasetxx-yy:zz format. if (preg_match('~^dataset([0-9]+)-(.*)$~', $answer, $matches)) { $itemid = $matches[1]; $subanswer = $matches[2]; // Delegate subanswer recode to multichoice qtype, faking one question_states record. $substate = new stdClass(); $substate->answer = $subanswer; $newanswer = $this->step->restore_recode_legacy_answer($substate, 'multichoice'); $result = 'dataset' . $itemid . '-' . $newanswer; } return $result ? $result : $answer; }
php
public function recode_legacy_state_answer($state) { $answer = $state->answer; $result = ''; // Datasetxx-yy:zz format. if (preg_match('~^dataset([0-9]+)-(.*)$~', $answer, $matches)) { $itemid = $matches[1]; $subanswer = $matches[2]; // Delegate subanswer recode to multichoice qtype, faking one question_states record. $substate = new stdClass(); $substate->answer = $subanswer; $newanswer = $this->step->restore_recode_legacy_answer($substate, 'multichoice'); $result = 'dataset' . $itemid . '-' . $newanswer; } return $result ? $result : $answer; }
[ "public", "function", "recode_legacy_state_answer", "(", "$", "state", ")", "{", "$", "answer", "=", "$", "state", "->", "answer", ";", "$", "result", "=", "''", ";", "// Datasetxx-yy:zz format.", "if", "(", "preg_match", "(", "'~^dataset([0-9]+)-(.*)$~'", ",", "$", "answer", ",", "$", "matches", ")", ")", "{", "$", "itemid", "=", "$", "matches", "[", "1", "]", ";", "$", "subanswer", "=", "$", "matches", "[", "2", "]", ";", "// Delegate subanswer recode to multichoice qtype, faking one question_states record.", "$", "substate", "=", "new", "stdClass", "(", ")", ";", "$", "substate", "->", "answer", "=", "$", "subanswer", ";", "$", "newanswer", "=", "$", "this", "->", "step", "->", "restore_recode_legacy_answer", "(", "$", "substate", ",", "'multichoice'", ")", ";", "$", "result", "=", "'dataset'", ".", "$", "itemid", ".", "'-'", ".", "$", "newanswer", ";", "}", "return", "$", "result", "?", "$", "result", ":", "$", "answer", ";", "}" ]
Given one question_states record, return the answer recoded pointing to all the restored stuff for calculatedmulti questions answer format is datasetxx-yy:zz, where xx is the itemnumber in the dataset (doesn't need conversion), and both yy and zz are two (hypen speparated) lists of comma separated question_answers, the first to specify the order of the answers and the second to specify the responses. in fact, this qtype behaves exactly like the multichoice one, so we'll delegate recoding of those yy:zz to it
[ "Given", "one", "question_states", "record", "return", "the", "answer", "recoded", "pointing", "to", "all", "the", "restored", "stuff", "for", "calculatedmulti", "questions" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/calculatedmulti/backup/moodle2/restore_qtype_calculatedmulti_plugin.class.php#L57-L71
213,144
moodle/moodle
cache/classes/definition.php
cache_definition.load_adhoc
public static function load_adhoc($mode, $component, $area, array $options = array()) { $id = 'adhoc/'.$component.'_'.$area; $definition = array( 'mode' => $mode, 'component' => $component, 'area' => $area, ); if (!empty($options['simplekeys'])) { $definition['simplekeys'] = $options['simplekeys']; } if (!empty($options['simpledata'])) { $definition['simpledata'] = $options['simpledata']; } if (!empty($options['persistent'])) { // Ahhh this is the legacy persistent option. $definition['staticacceleration'] = (bool)$options['persistent']; } if (!empty($options['staticacceleration'])) { $definition['staticacceleration'] = (bool)$options['staticacceleration']; } if (!empty($options['staticaccelerationsize'])) { $definition['staticaccelerationsize'] = (int)$options['staticaccelerationsize']; } if (!empty($options['overrideclass'])) { $definition['overrideclass'] = $options['overrideclass']; } if (!empty($options['sharingoptions'])) { $definition['sharingoptions'] = $options['sharingoptions']; } return self::load($id, $definition, null); }
php
public static function load_adhoc($mode, $component, $area, array $options = array()) { $id = 'adhoc/'.$component.'_'.$area; $definition = array( 'mode' => $mode, 'component' => $component, 'area' => $area, ); if (!empty($options['simplekeys'])) { $definition['simplekeys'] = $options['simplekeys']; } if (!empty($options['simpledata'])) { $definition['simpledata'] = $options['simpledata']; } if (!empty($options['persistent'])) { // Ahhh this is the legacy persistent option. $definition['staticacceleration'] = (bool)$options['persistent']; } if (!empty($options['staticacceleration'])) { $definition['staticacceleration'] = (bool)$options['staticacceleration']; } if (!empty($options['staticaccelerationsize'])) { $definition['staticaccelerationsize'] = (int)$options['staticaccelerationsize']; } if (!empty($options['overrideclass'])) { $definition['overrideclass'] = $options['overrideclass']; } if (!empty($options['sharingoptions'])) { $definition['sharingoptions'] = $options['sharingoptions']; } return self::load($id, $definition, null); }
[ "public", "static", "function", "load_adhoc", "(", "$", "mode", ",", "$", "component", ",", "$", "area", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "$", "id", "=", "'adhoc/'", ".", "$", "component", ".", "'_'", ".", "$", "area", ";", "$", "definition", "=", "array", "(", "'mode'", "=>", "$", "mode", ",", "'component'", "=>", "$", "component", ",", "'area'", "=>", "$", "area", ",", ")", ";", "if", "(", "!", "empty", "(", "$", "options", "[", "'simplekeys'", "]", ")", ")", "{", "$", "definition", "[", "'simplekeys'", "]", "=", "$", "options", "[", "'simplekeys'", "]", ";", "}", "if", "(", "!", "empty", "(", "$", "options", "[", "'simpledata'", "]", ")", ")", "{", "$", "definition", "[", "'simpledata'", "]", "=", "$", "options", "[", "'simpledata'", "]", ";", "}", "if", "(", "!", "empty", "(", "$", "options", "[", "'persistent'", "]", ")", ")", "{", "// Ahhh this is the legacy persistent option.", "$", "definition", "[", "'staticacceleration'", "]", "=", "(", "bool", ")", "$", "options", "[", "'persistent'", "]", ";", "}", "if", "(", "!", "empty", "(", "$", "options", "[", "'staticacceleration'", "]", ")", ")", "{", "$", "definition", "[", "'staticacceleration'", "]", "=", "(", "bool", ")", "$", "options", "[", "'staticacceleration'", "]", ";", "}", "if", "(", "!", "empty", "(", "$", "options", "[", "'staticaccelerationsize'", "]", ")", ")", "{", "$", "definition", "[", "'staticaccelerationsize'", "]", "=", "(", "int", ")", "$", "options", "[", "'staticaccelerationsize'", "]", ";", "}", "if", "(", "!", "empty", "(", "$", "options", "[", "'overrideclass'", "]", ")", ")", "{", "$", "definition", "[", "'overrideclass'", "]", "=", "$", "options", "[", "'overrideclass'", "]", ";", "}", "if", "(", "!", "empty", "(", "$", "options", "[", "'sharingoptions'", "]", ")", ")", "{", "$", "definition", "[", "'sharingoptions'", "]", "=", "$", "options", "[", "'sharingoptions'", "]", ";", "}", "return", "self", "::", "load", "(", "$", "id", ",", "$", "definition", ",", "null", ")", ";", "}" ]
Creates an ah-hoc cache definition given the required params. Please note that when using an adhoc definition you cannot set any of the optional params. This is because we cannot guarantee consistent access and we don't want to mislead people into thinking that. @param int $mode One of cache_store::MODE_* @param string $component The component this definition relates to. @param string $area The area this definition relates to. @param array $options An array of options, available options are: - simplekeys : Set to true if the keys you will use are a-zA-Z0-9_ - simpledata : Set to true if the type of the data you are going to store is scalar, or an array of scalar vars - overrideclass : The class to use as the loader. - staticacceleration : If set to true the cache will hold onto data passing through it. - staticaccelerationsize : Set it to an int to limit the size of the staticacceleration cache. @return cache_application|cache_session|cache_request
[ "Creates", "an", "ah", "-", "hoc", "cache", "definition", "given", "the", "required", "params", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/definition.php#L562-L592
213,145
moodle/moodle
cache/classes/definition.php
cache_definition.get_cache_class
public function get_cache_class() { if (!is_null($this->overrideclass)) { return $this->overrideclass; } return cache_helper::get_class_for_mode($this->mode); }
php
public function get_cache_class() { if (!is_null($this->overrideclass)) { return $this->overrideclass; } return cache_helper::get_class_for_mode($this->mode); }
[ "public", "function", "get_cache_class", "(", ")", "{", "if", "(", "!", "is_null", "(", "$", "this", "->", "overrideclass", ")", ")", "{", "return", "$", "this", "->", "overrideclass", ";", "}", "return", "cache_helper", "::", "get_class_for_mode", "(", "$", "this", "->", "mode", ")", ";", "}" ]
Returns the cache loader class that should be used for this definition. @return string
[ "Returns", "the", "cache", "loader", "class", "that", "should", "be", "used", "for", "this", "definition", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/definition.php#L598-L603
213,146
moodle/moodle
cache/classes/definition.php
cache_definition.get_name
public function get_name() { $identifier = 'cachedef_'.clean_param($this->area, PARAM_STRINGID); $component = $this->component; if ($component === 'core') { $component = 'cache'; } return new lang_string($identifier, $component); }
php
public function get_name() { $identifier = 'cachedef_'.clean_param($this->area, PARAM_STRINGID); $component = $this->component; if ($component === 'core') { $component = 'cache'; } return new lang_string($identifier, $component); }
[ "public", "function", "get_name", "(", ")", "{", "$", "identifier", "=", "'cachedef_'", ".", "clean_param", "(", "$", "this", "->", "area", ",", "PARAM_STRINGID", ")", ";", "$", "component", "=", "$", "this", "->", "component", ";", "if", "(", "$", "component", "===", "'core'", ")", "{", "$", "component", "=", "'cache'", ";", "}", "return", "new", "lang_string", "(", "$", "identifier", ",", "$", "component", ")", ";", "}" ]
Returns the name for this definition @return string
[ "Returns", "the", "name", "for", "this", "definition" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/definition.php#L617-L624
213,147
moodle/moodle
cache/classes/definition.php
cache_definition.set_identifiers
public function set_identifiers(array $identifiers = array()) { if ($this->identifiers !== null) { throw new coding_exception("You can only set identifiers on initial definition creation." . " Define a new cache to set different identifiers."); } if (!empty($identifiers) && !empty($this->invalidationevents)) { throw new coding_exception("You cannot use event invalidation and identifiers at the same time."); } foreach ($this->requireidentifiers as $identifier) { if (!isset($identifiers[$identifier])) { throw new coding_exception('Identifier required for cache has not been provided: '.$identifier); } } $this->identifiers = array(); foreach ($identifiers as $name => $value) { $this->identifiers[$name] = (string)$value; } // Reset the key prefix's they need updating now. $this->keyprefixsingle = null; $this->keyprefixmulti = null; return true; }
php
public function set_identifiers(array $identifiers = array()) { if ($this->identifiers !== null) { throw new coding_exception("You can only set identifiers on initial definition creation." . " Define a new cache to set different identifiers."); } if (!empty($identifiers) && !empty($this->invalidationevents)) { throw new coding_exception("You cannot use event invalidation and identifiers at the same time."); } foreach ($this->requireidentifiers as $identifier) { if (!isset($identifiers[$identifier])) { throw new coding_exception('Identifier required for cache has not been provided: '.$identifier); } } $this->identifiers = array(); foreach ($identifiers as $name => $value) { $this->identifiers[$name] = (string)$value; } // Reset the key prefix's they need updating now. $this->keyprefixsingle = null; $this->keyprefixmulti = null; return true; }
[ "public", "function", "set_identifiers", "(", "array", "$", "identifiers", "=", "array", "(", ")", ")", "{", "if", "(", "$", "this", "->", "identifiers", "!==", "null", ")", "{", "throw", "new", "coding_exception", "(", "\"You can only set identifiers on initial definition creation.\"", ".", "\" Define a new cache to set different identifiers.\"", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "identifiers", ")", "&&", "!", "empty", "(", "$", "this", "->", "invalidationevents", ")", ")", "{", "throw", "new", "coding_exception", "(", "\"You cannot use event invalidation and identifiers at the same time.\"", ")", ";", "}", "foreach", "(", "$", "this", "->", "requireidentifiers", "as", "$", "identifier", ")", "{", "if", "(", "!", "isset", "(", "$", "identifiers", "[", "$", "identifier", "]", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Identifier required for cache has not been provided: '", ".", "$", "identifier", ")", ";", "}", "}", "$", "this", "->", "identifiers", "=", "array", "(", ")", ";", "foreach", "(", "$", "identifiers", "as", "$", "name", "=>", "$", "value", ")", "{", "$", "this", "->", "identifiers", "[", "$", "name", "]", "=", "(", "string", ")", "$", "value", ";", "}", "// Reset the key prefix's they need updating now.", "$", "this", "->", "keyprefixsingle", "=", "null", ";", "$", "this", "->", "keyprefixmulti", "=", "null", ";", "return", "true", ";", "}" ]
Sets the identifiers for this definition, or updates them if they have already been set. @param array $identifiers @return bool false if no identifiers where changed, true otherwise. @throws coding_exception
[ "Sets", "the", "identifiers", "for", "this", "definition", "or", "updates", "them", "if", "they", "have", "already", "been", "set", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/definition.php#L790-L815
213,148
moodle/moodle
cache/classes/definition.php
cache_definition.get_requirements_bin
public function get_requirements_bin() { $requires = 0; if ($this->require_data_guarantee()) { $requires += cache_store::SUPPORTS_DATA_GUARANTEE; } if ($this->require_multiple_identifiers()) { $requires += cache_store::SUPPORTS_MULTIPLE_IDENTIFIERS; } if ($this->require_searchable()) { $requires += cache_store::IS_SEARCHABLE; } return $requires; }
php
public function get_requirements_bin() { $requires = 0; if ($this->require_data_guarantee()) { $requires += cache_store::SUPPORTS_DATA_GUARANTEE; } if ($this->require_multiple_identifiers()) { $requires += cache_store::SUPPORTS_MULTIPLE_IDENTIFIERS; } if ($this->require_searchable()) { $requires += cache_store::IS_SEARCHABLE; } return $requires; }
[ "public", "function", "get_requirements_bin", "(", ")", "{", "$", "requires", "=", "0", ";", "if", "(", "$", "this", "->", "require_data_guarantee", "(", ")", ")", "{", "$", "requires", "+=", "cache_store", "::", "SUPPORTS_DATA_GUARANTEE", ";", "}", "if", "(", "$", "this", "->", "require_multiple_identifiers", "(", ")", ")", "{", "$", "requires", "+=", "cache_store", "::", "SUPPORTS_MULTIPLE_IDENTIFIERS", ";", "}", "if", "(", "$", "this", "->", "require_searchable", "(", ")", ")", "{", "$", "requires", "+=", "cache_store", "::", "IS_SEARCHABLE", ";", "}", "return", "$", "requires", ";", "}" ]
Returns the requirements of this definition as a binary flag. @return int
[ "Returns", "the", "requirements", "of", "this", "definition", "as", "a", "binary", "flag", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/definition.php#L821-L833
213,149
moodle/moodle
cache/classes/definition.php
cache_definition.generate_single_key_prefix
public function generate_single_key_prefix() { if ($this->keyprefixsingle === null) { $this->keyprefixsingle = $this->mode.'/'.$this->component.'/'.$this->area; $this->keyprefixsingle .= '/'.$this->get_cache_identifier(); $identifiers = $this->get_identifiers(); if ($identifiers) { foreach ($identifiers as $key => $value) { $this->keyprefixsingle .= '/'.$key.'='.$value; } } $this->keyprefixsingle = md5($this->keyprefixsingle); } return $this->keyprefixsingle; }
php
public function generate_single_key_prefix() { if ($this->keyprefixsingle === null) { $this->keyprefixsingle = $this->mode.'/'.$this->component.'/'.$this->area; $this->keyprefixsingle .= '/'.$this->get_cache_identifier(); $identifiers = $this->get_identifiers(); if ($identifiers) { foreach ($identifiers as $key => $value) { $this->keyprefixsingle .= '/'.$key.'='.$value; } } $this->keyprefixsingle = md5($this->keyprefixsingle); } return $this->keyprefixsingle; }
[ "public", "function", "generate_single_key_prefix", "(", ")", "{", "if", "(", "$", "this", "->", "keyprefixsingle", "===", "null", ")", "{", "$", "this", "->", "keyprefixsingle", "=", "$", "this", "->", "mode", ".", "'/'", ".", "$", "this", "->", "component", ".", "'/'", ".", "$", "this", "->", "area", ";", "$", "this", "->", "keyprefixsingle", ".=", "'/'", ".", "$", "this", "->", "get_cache_identifier", "(", ")", ";", "$", "identifiers", "=", "$", "this", "->", "get_identifiers", "(", ")", ";", "if", "(", "$", "identifiers", ")", "{", "foreach", "(", "$", "identifiers", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "this", "->", "keyprefixsingle", ".=", "'/'", ".", "$", "key", ".", "'='", ".", "$", "value", ";", "}", "}", "$", "this", "->", "keyprefixsingle", "=", "md5", "(", "$", "this", "->", "keyprefixsingle", ")", ";", "}", "return", "$", "this", "->", "keyprefixsingle", ";", "}" ]
Generates a single key prefix for this definition @return string
[ "Generates", "a", "single", "key", "prefix", "for", "this", "definition" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/definition.php#L897-L910
213,150
moodle/moodle
cache/classes/definition.php
cache_definition.generate_multi_key_parts
public function generate_multi_key_parts() { if ($this->keyprefixmulti === null) { $this->keyprefixmulti = array( 'mode' => $this->mode, 'component' => $this->component, 'area' => $this->area, 'siteidentifier' => $this->get_cache_identifier() ); if (isset($this->identifiers) && !empty($this->identifiers)) { $identifiers = array(); foreach ($this->identifiers as $key => $value) { $identifiers[] = htmlentities($key, ENT_QUOTES, 'UTF-8').'='.htmlentities($value, ENT_QUOTES, 'UTF-8'); } $this->keyprefixmulti['identifiers'] = join('&', $identifiers); } } return $this->keyprefixmulti; }
php
public function generate_multi_key_parts() { if ($this->keyprefixmulti === null) { $this->keyprefixmulti = array( 'mode' => $this->mode, 'component' => $this->component, 'area' => $this->area, 'siteidentifier' => $this->get_cache_identifier() ); if (isset($this->identifiers) && !empty($this->identifiers)) { $identifiers = array(); foreach ($this->identifiers as $key => $value) { $identifiers[] = htmlentities($key, ENT_QUOTES, 'UTF-8').'='.htmlentities($value, ENT_QUOTES, 'UTF-8'); } $this->keyprefixmulti['identifiers'] = join('&', $identifiers); } } return $this->keyprefixmulti; }
[ "public", "function", "generate_multi_key_parts", "(", ")", "{", "if", "(", "$", "this", "->", "keyprefixmulti", "===", "null", ")", "{", "$", "this", "->", "keyprefixmulti", "=", "array", "(", "'mode'", "=>", "$", "this", "->", "mode", ",", "'component'", "=>", "$", "this", "->", "component", ",", "'area'", "=>", "$", "this", "->", "area", ",", "'siteidentifier'", "=>", "$", "this", "->", "get_cache_identifier", "(", ")", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "identifiers", ")", "&&", "!", "empty", "(", "$", "this", "->", "identifiers", ")", ")", "{", "$", "identifiers", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "identifiers", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "identifiers", "[", "]", "=", "htmlentities", "(", "$", "key", ",", "ENT_QUOTES", ",", "'UTF-8'", ")", ".", "'='", ".", "htmlentities", "(", "$", "value", ",", "ENT_QUOTES", ",", "'UTF-8'", ")", ";", "}", "$", "this", "->", "keyprefixmulti", "[", "'identifiers'", "]", "=", "join", "(", "'&'", ",", "$", "identifiers", ")", ";", "}", "}", "return", "$", "this", "->", "keyprefixmulti", ";", "}" ]
Generates a multi key prefix for this definition @return array
[ "Generates", "a", "multi", "key", "prefix", "for", "this", "definition" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/definition.php#L917-L934
213,151
moodle/moodle
cache/classes/definition.php
cache_definition.get_cache_identifier
protected function get_cache_identifier() { $identifiers = array(); if ($this->selectedsharingoption & self::SHARING_ALL) { // Nothing to do here. } else { if ($this->selectedsharingoption & self::SHARING_SITEID) { $identifiers[] = cache_helper::get_site_identifier(); } if ($this->selectedsharingoption & self::SHARING_VERSION) { $identifiers[] = cache_helper::get_site_version(); } if ($this->selectedsharingoption & self::SHARING_INPUT && !empty($this->userinputsharingkey)) { $identifiers[] = $this->userinputsharingkey; } } return join('/', $identifiers); }
php
protected function get_cache_identifier() { $identifiers = array(); if ($this->selectedsharingoption & self::SHARING_ALL) { // Nothing to do here. } else { if ($this->selectedsharingoption & self::SHARING_SITEID) { $identifiers[] = cache_helper::get_site_identifier(); } if ($this->selectedsharingoption & self::SHARING_VERSION) { $identifiers[] = cache_helper::get_site_version(); } if ($this->selectedsharingoption & self::SHARING_INPUT && !empty($this->userinputsharingkey)) { $identifiers[] = $this->userinputsharingkey; } } return join('/', $identifiers); }
[ "protected", "function", "get_cache_identifier", "(", ")", "{", "$", "identifiers", "=", "array", "(", ")", ";", "if", "(", "$", "this", "->", "selectedsharingoption", "&", "self", "::", "SHARING_ALL", ")", "{", "// Nothing to do here.", "}", "else", "{", "if", "(", "$", "this", "->", "selectedsharingoption", "&", "self", "::", "SHARING_SITEID", ")", "{", "$", "identifiers", "[", "]", "=", "cache_helper", "::", "get_site_identifier", "(", ")", ";", "}", "if", "(", "$", "this", "->", "selectedsharingoption", "&", "self", "::", "SHARING_VERSION", ")", "{", "$", "identifiers", "[", "]", "=", "cache_helper", "::", "get_site_version", "(", ")", ";", "}", "if", "(", "$", "this", "->", "selectedsharingoption", "&", "self", "::", "SHARING_INPUT", "&&", "!", "empty", "(", "$", "this", "->", "userinputsharingkey", ")", ")", "{", "$", "identifiers", "[", "]", "=", "$", "this", "->", "userinputsharingkey", ";", "}", "}", "return", "join", "(", "'/'", ",", "$", "identifiers", ")", ";", "}" ]
Returns a cache identification string. @return string A string to be used as part of keys.
[ "Returns", "a", "cache", "identification", "string", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/classes/definition.php#L969-L985
213,152
moodle/moodle
blocks/navigation/block_navigation.php
block_navigation.get_required_javascript
function get_required_javascript() { parent::get_required_javascript(); $arguments = array( 'instanceid' => $this->instance->id ); $this->page->requires->string_for_js('viewallcourses', 'moodle'); $this->page->requires->js_call_amd('block_navigation/navblock', 'init', $arguments); }
php
function get_required_javascript() { parent::get_required_javascript(); $arguments = array( 'instanceid' => $this->instance->id ); $this->page->requires->string_for_js('viewallcourses', 'moodle'); $this->page->requires->js_call_amd('block_navigation/navblock', 'init', $arguments); }
[ "function", "get_required_javascript", "(", ")", "{", "parent", "::", "get_required_javascript", "(", ")", ";", "$", "arguments", "=", "array", "(", "'instanceid'", "=>", "$", "this", "->", "instance", "->", "id", ")", ";", "$", "this", "->", "page", "->", "requires", "->", "string_for_js", "(", "'viewallcourses'", ",", "'moodle'", ")", ";", "$", "this", "->", "page", "->", "requires", "->", "js_call_amd", "(", "'block_navigation/navblock'", ",", "'init'", ",", "$", "arguments", ")", ";", "}" ]
Gets Javascript that may be required for navigation
[ "Gets", "Javascript", "that", "may", "be", "required", "for", "navigation" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/navigation/block_navigation.php#L109-L116
213,153
moodle/moodle
blocks/navigation/block_navigation.php
block_navigation.html_attributes
public function html_attributes() { $attributes = parent::html_attributes(); if (!empty($this->config->enablehoverexpansion) && $this->config->enablehoverexpansion == 'yes') { $attributes['class'] .= ' block_js_expansion'; } return $attributes; }
php
public function html_attributes() { $attributes = parent::html_attributes(); if (!empty($this->config->enablehoverexpansion) && $this->config->enablehoverexpansion == 'yes') { $attributes['class'] .= ' block_js_expansion'; } return $attributes; }
[ "public", "function", "html_attributes", "(", ")", "{", "$", "attributes", "=", "parent", "::", "html_attributes", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "config", "->", "enablehoverexpansion", ")", "&&", "$", "this", "->", "config", "->", "enablehoverexpansion", "==", "'yes'", ")", "{", "$", "attributes", "[", "'class'", "]", ".=", "' block_js_expansion'", ";", "}", "return", "$", "attributes", ";", "}" ]
Returns the attributes to set for this block This function returns an array of HTML attributes for this block including the defaults. {@link block_tree::html_attributes()} is used to get the default arguments and then we check whether the user has enabled hover expansion and add the appropriate hover class if it has. @return array An array of HTML attributes
[ "Returns", "the", "attributes", "to", "set", "for", "this", "block" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/navigation/block_navigation.php#L232-L238
213,154
moodle/moodle
blocks/navigation/block_navigation.php
block_navigation.trim
public function trim(navigation_node $node, $mode=1, $long=50, $short=25, $recurse=true) { switch ($mode) { case self::TRIM_RIGHT : if (core_text::strlen($node->text)>($long+3)) { // Truncate the text to $long characters $node->text = $this->trim_right($node->text, $long); } if (is_string($node->shorttext) && core_text::strlen($node->shorttext)>($short+3)) { // Truncate the shorttext $node->shorttext = $this->trim_right($node->shorttext, $short); } break; case self::TRIM_LEFT : if (core_text::strlen($node->text)>($long+3)) { // Truncate the text to $long characters $node->text = $this->trim_left($node->text, $long); } if (is_string($node->shorttext) && core_text::strlen($node->shorttext)>($short+3)) { // Truncate the shorttext $node->shorttext = $this->trim_left($node->shorttext, $short); } break; case self::TRIM_CENTER : if (core_text::strlen($node->text)>($long+3)) { // Truncate the text to $long characters $node->text = $this->trim_center($node->text, $long); } if (is_string($node->shorttext) && core_text::strlen($node->shorttext)>($short+3)) { // Truncate the shorttext $node->shorttext = $this->trim_center($node->shorttext, $short); } break; } if ($recurse && $node->children->count()) { foreach ($node->children as &$child) { $this->trim($child, $mode, $long, $short, true); } } }
php
public function trim(navigation_node $node, $mode=1, $long=50, $short=25, $recurse=true) { switch ($mode) { case self::TRIM_RIGHT : if (core_text::strlen($node->text)>($long+3)) { // Truncate the text to $long characters $node->text = $this->trim_right($node->text, $long); } if (is_string($node->shorttext) && core_text::strlen($node->shorttext)>($short+3)) { // Truncate the shorttext $node->shorttext = $this->trim_right($node->shorttext, $short); } break; case self::TRIM_LEFT : if (core_text::strlen($node->text)>($long+3)) { // Truncate the text to $long characters $node->text = $this->trim_left($node->text, $long); } if (is_string($node->shorttext) && core_text::strlen($node->shorttext)>($short+3)) { // Truncate the shorttext $node->shorttext = $this->trim_left($node->shorttext, $short); } break; case self::TRIM_CENTER : if (core_text::strlen($node->text)>($long+3)) { // Truncate the text to $long characters $node->text = $this->trim_center($node->text, $long); } if (is_string($node->shorttext) && core_text::strlen($node->shorttext)>($short+3)) { // Truncate the shorttext $node->shorttext = $this->trim_center($node->shorttext, $short); } break; } if ($recurse && $node->children->count()) { foreach ($node->children as &$child) { $this->trim($child, $mode, $long, $short, true); } } }
[ "public", "function", "trim", "(", "navigation_node", "$", "node", ",", "$", "mode", "=", "1", ",", "$", "long", "=", "50", ",", "$", "short", "=", "25", ",", "$", "recurse", "=", "true", ")", "{", "switch", "(", "$", "mode", ")", "{", "case", "self", "::", "TRIM_RIGHT", ":", "if", "(", "core_text", "::", "strlen", "(", "$", "node", "->", "text", ")", ">", "(", "$", "long", "+", "3", ")", ")", "{", "// Truncate the text to $long characters", "$", "node", "->", "text", "=", "$", "this", "->", "trim_right", "(", "$", "node", "->", "text", ",", "$", "long", ")", ";", "}", "if", "(", "is_string", "(", "$", "node", "->", "shorttext", ")", "&&", "core_text", "::", "strlen", "(", "$", "node", "->", "shorttext", ")", ">", "(", "$", "short", "+", "3", ")", ")", "{", "// Truncate the shorttext", "$", "node", "->", "shorttext", "=", "$", "this", "->", "trim_right", "(", "$", "node", "->", "shorttext", ",", "$", "short", ")", ";", "}", "break", ";", "case", "self", "::", "TRIM_LEFT", ":", "if", "(", "core_text", "::", "strlen", "(", "$", "node", "->", "text", ")", ">", "(", "$", "long", "+", "3", ")", ")", "{", "// Truncate the text to $long characters", "$", "node", "->", "text", "=", "$", "this", "->", "trim_left", "(", "$", "node", "->", "text", ",", "$", "long", ")", ";", "}", "if", "(", "is_string", "(", "$", "node", "->", "shorttext", ")", "&&", "core_text", "::", "strlen", "(", "$", "node", "->", "shorttext", ")", ">", "(", "$", "short", "+", "3", ")", ")", "{", "// Truncate the shorttext", "$", "node", "->", "shorttext", "=", "$", "this", "->", "trim_left", "(", "$", "node", "->", "shorttext", ",", "$", "short", ")", ";", "}", "break", ";", "case", "self", "::", "TRIM_CENTER", ":", "if", "(", "core_text", "::", "strlen", "(", "$", "node", "->", "text", ")", ">", "(", "$", "long", "+", "3", ")", ")", "{", "// Truncate the text to $long characters", "$", "node", "->", "text", "=", "$", "this", "->", "trim_center", "(", "$", "node", "->", "text", ",", "$", "long", ")", ";", "}", "if", "(", "is_string", "(", "$", "node", "->", "shorttext", ")", "&&", "core_text", "::", "strlen", "(", "$", "node", "->", "shorttext", ")", ">", "(", "$", "short", "+", "3", ")", ")", "{", "// Truncate the shorttext", "$", "node", "->", "shorttext", "=", "$", "this", "->", "trim_center", "(", "$", "node", "->", "shorttext", ",", "$", "short", ")", ";", "}", "break", ";", "}", "if", "(", "$", "recurse", "&&", "$", "node", "->", "children", "->", "count", "(", ")", ")", "{", "foreach", "(", "$", "node", "->", "children", "as", "&", "$", "child", ")", "{", "$", "this", "->", "trim", "(", "$", "child", ",", "$", "mode", ",", "$", "long", ",", "$", "short", ",", "true", ")", ";", "}", "}", "}" ]
Trims the text and shorttext properties of this node and optionally all of its children. @param navigation_node $node @param int $mode One of navigation_node::TRIM_* @param int $long The length to trim text to @param int $short The length to trim shorttext to @param bool $recurse Recurse all children
[ "Trims", "the", "text", "and", "shorttext", "properties", "of", "this", "node", "and", "optionally", "all", "of", "its", "children", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/navigation/block_navigation.php#L250-L288
213,155
moodle/moodle
blocks/navigation/block_navigation.php
block_navigation.trim_left
protected function trim_left($string, $length) { return '...'.core_text::substr($string, core_text::strlen($string)-$length, $length); }
php
protected function trim_left($string, $length) { return '...'.core_text::substr($string, core_text::strlen($string)-$length, $length); }
[ "protected", "function", "trim_left", "(", "$", "string", ",", "$", "length", ")", "{", "return", "'...'", ".", "core_text", "::", "substr", "(", "$", "string", ",", "core_text", "::", "strlen", "(", "$", "string", ")", "-", "$", "length", ",", "$", "length", ")", ";", "}" ]
Truncate a string from the left @param string $string The string to truncate @param int $length The length to truncate to @return string The truncated string
[ "Truncate", "a", "string", "from", "the", "left" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/navigation/block_navigation.php#L295-L297
213,156
moodle/moodle
blocks/navigation/block_navigation.php
block_navigation.trim_center
protected function trim_center($string, $length) { $trimlength = ceil($length/2); $start = core_text::substr($string, 0, $trimlength); $end = core_text::substr($string, core_text::strlen($string)-$trimlength); $string = $start.'...'.$end; return $string; }
php
protected function trim_center($string, $length) { $trimlength = ceil($length/2); $start = core_text::substr($string, 0, $trimlength); $end = core_text::substr($string, core_text::strlen($string)-$trimlength); $string = $start.'...'.$end; return $string; }
[ "protected", "function", "trim_center", "(", "$", "string", ",", "$", "length", ")", "{", "$", "trimlength", "=", "ceil", "(", "$", "length", "/", "2", ")", ";", "$", "start", "=", "core_text", "::", "substr", "(", "$", "string", ",", "0", ",", "$", "trimlength", ")", ";", "$", "end", "=", "core_text", "::", "substr", "(", "$", "string", ",", "core_text", "::", "strlen", "(", "$", "string", ")", "-", "$", "trimlength", ")", ";", "$", "string", "=", "$", "start", ".", "'...'", ".", "$", "end", ";", "return", "$", "string", ";", "}" ]
Truncate a string in the center @param string $string The string to truncate @param int $length The length to truncate to @return string The truncated string
[ "Truncate", "a", "string", "in", "the", "center" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/navigation/block_navigation.php#L313-L319
213,157
moodle/moodle
lib/horde/framework/Horde/Imap/Client/Fetch/Results.php
Horde_Imap_Client_Fetch_Results.get
public function get($key) { if (!isset($this->_data[$key])) { $this->_data[$key] = new $this->_obClass(); } return $this->_data[$key]; }
php
public function get($key) { if (!isset($this->_data[$key])) { $this->_data[$key] = new $this->_obClass(); } return $this->_data[$key]; }
[ "public", "function", "get", "(", "$", "key", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_data", "[", "$", "key", "]", ")", ")", "{", "$", "this", "->", "_data", "[", "$", "key", "]", "=", "new", "$", "this", "->", "_obClass", "(", ")", ";", "}", "return", "$", "this", "->", "_data", "[", "$", "key", "]", ";", "}" ]
Return a fetch object, creating and storing an empty object in the results set if it doesn't currently exist. @param string $key The key to retrieve. @return Horde_Imap_Client_Data_Fetch The fetch object.
[ "Return", "a", "fetch", "object", "creating", "and", "storing", "an", "empty", "object", "in", "the", "results", "set", "if", "it", "doesn", "t", "currently", "exist", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Fetch/Results.php#L87-L94
213,158
moodle/moodle
lib/xmldb/xmldb_object.php
xmldb_object.findObjectInArray
public function findObjectInArray($objectname, $arr) { foreach ($arr as $i => $object) { if ($objectname == $object->getName()) { return $i; } } return null; }
php
public function findObjectInArray($objectname, $arr) { foreach ($arr as $i => $object) { if ($objectname == $object->getName()) { return $i; } } return null; }
[ "public", "function", "findObjectInArray", "(", "$", "objectname", ",", "$", "arr", ")", "{", "foreach", "(", "$", "arr", "as", "$", "i", "=>", "$", "object", ")", "{", "if", "(", "$", "objectname", "==", "$", "object", "->", "getName", "(", ")", ")", "{", "return", "$", "i", ";", "}", "}", "return", "null", ";", "}" ]
Returns the position of one object in the array. @param string $objectname @param array $arr @return mixed
[ "Returns", "the", "position", "of", "one", "object", "in", "the", "array", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/xmldb/xmldb_object.php#L316-L323
213,159
moodle/moodle
lib/xmldb/xmldb_object.php
xmldb_object.comma2array
public function comma2array($string) { $foundquotes = array(); $foundconcats = array(); // Extract all the concat elements from the string preg_match_all("/(CONCAT\(.*?\))/is", $string, $matches); foreach (array_unique($matches[0]) as $key=>$value) { $foundconcats['<#'.$key.'#>'] = $value; } if (!empty($foundconcats)) { $string = str_replace($foundconcats,array_keys($foundconcats),$string); } // Extract all the quoted elements from the string (skipping // backslashed quotes that are part of the content. preg_match_all("/(''|'.*?[^\\\\]')/is", $string, $matches); foreach (array_unique($matches[0]) as $key=>$value) { $foundquotes['<%'.$key.'%>'] = $value; } if (!empty($foundquotes)) { $string = str_replace($foundquotes,array_keys($foundquotes),$string); } // Explode safely the string $arr = explode (',', $string); // Put the concat and quoted elements back again, trimming every element if ($arr) { foreach ($arr as $key => $element) { // Clear some spaces $element = trim($element); // Replace the quoted elements if exists if (!empty($foundquotes)) { $element = str_replace(array_keys($foundquotes), $foundquotes, $element); } // Replace the concat elements if exists if (!empty($foundconcats)) { $element = str_replace(array_keys($foundconcats), $foundconcats, $element); } // Delete any backslash used for quotes. XMLDB stuff will add them before insert $arr[$key] = str_replace("\\'", "'", $element); } } return $arr; }
php
public function comma2array($string) { $foundquotes = array(); $foundconcats = array(); // Extract all the concat elements from the string preg_match_all("/(CONCAT\(.*?\))/is", $string, $matches); foreach (array_unique($matches[0]) as $key=>$value) { $foundconcats['<#'.$key.'#>'] = $value; } if (!empty($foundconcats)) { $string = str_replace($foundconcats,array_keys($foundconcats),$string); } // Extract all the quoted elements from the string (skipping // backslashed quotes that are part of the content. preg_match_all("/(''|'.*?[^\\\\]')/is", $string, $matches); foreach (array_unique($matches[0]) as $key=>$value) { $foundquotes['<%'.$key.'%>'] = $value; } if (!empty($foundquotes)) { $string = str_replace($foundquotes,array_keys($foundquotes),$string); } // Explode safely the string $arr = explode (',', $string); // Put the concat and quoted elements back again, trimming every element if ($arr) { foreach ($arr as $key => $element) { // Clear some spaces $element = trim($element); // Replace the quoted elements if exists if (!empty($foundquotes)) { $element = str_replace(array_keys($foundquotes), $foundquotes, $element); } // Replace the concat elements if exists if (!empty($foundconcats)) { $element = str_replace(array_keys($foundconcats), $foundconcats, $element); } // Delete any backslash used for quotes. XMLDB stuff will add them before insert $arr[$key] = str_replace("\\'", "'", $element); } } return $arr; }
[ "public", "function", "comma2array", "(", "$", "string", ")", "{", "$", "foundquotes", "=", "array", "(", ")", ";", "$", "foundconcats", "=", "array", "(", ")", ";", "// Extract all the concat elements from the string", "preg_match_all", "(", "\"/(CONCAT\\(.*?\\))/is\"", ",", "$", "string", ",", "$", "matches", ")", ";", "foreach", "(", "array_unique", "(", "$", "matches", "[", "0", "]", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "foundconcats", "[", "'<#'", ".", "$", "key", ".", "'#>'", "]", "=", "$", "value", ";", "}", "if", "(", "!", "empty", "(", "$", "foundconcats", ")", ")", "{", "$", "string", "=", "str_replace", "(", "$", "foundconcats", ",", "array_keys", "(", "$", "foundconcats", ")", ",", "$", "string", ")", ";", "}", "// Extract all the quoted elements from the string (skipping", "// backslashed quotes that are part of the content.", "preg_match_all", "(", "\"/(''|'.*?[^\\\\\\\\]')/is\"", ",", "$", "string", ",", "$", "matches", ")", ";", "foreach", "(", "array_unique", "(", "$", "matches", "[", "0", "]", ")", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "foundquotes", "[", "'<%'", ".", "$", "key", ".", "'%>'", "]", "=", "$", "value", ";", "}", "if", "(", "!", "empty", "(", "$", "foundquotes", ")", ")", "{", "$", "string", "=", "str_replace", "(", "$", "foundquotes", ",", "array_keys", "(", "$", "foundquotes", ")", ",", "$", "string", ")", ";", "}", "// Explode safely the string", "$", "arr", "=", "explode", "(", "','", ",", "$", "string", ")", ";", "// Put the concat and quoted elements back again, trimming every element", "if", "(", "$", "arr", ")", "{", "foreach", "(", "$", "arr", "as", "$", "key", "=>", "$", "element", ")", "{", "// Clear some spaces", "$", "element", "=", "trim", "(", "$", "element", ")", ";", "// Replace the quoted elements if exists", "if", "(", "!", "empty", "(", "$", "foundquotes", ")", ")", "{", "$", "element", "=", "str_replace", "(", "array_keys", "(", "$", "foundquotes", ")", ",", "$", "foundquotes", ",", "$", "element", ")", ";", "}", "// Replace the concat elements if exists", "if", "(", "!", "empty", "(", "$", "foundconcats", ")", ")", "{", "$", "element", "=", "str_replace", "(", "array_keys", "(", "$", "foundconcats", ")", ",", "$", "foundconcats", ",", "$", "element", ")", ";", "}", "// Delete any backslash used for quotes. XMLDB stuff will add them before insert", "$", "arr", "[", "$", "key", "]", "=", "str_replace", "(", "\"\\\\'\"", ",", "\"'\"", ",", "$", "element", ")", ";", "}", "}", "return", "$", "arr", ";", "}" ]
Returns one array of elements from one comma separated string, supporting quoted strings containing commas and concat function calls @param string $string @return array
[ "Returns", "one", "array", "of", "elements", "from", "one", "comma", "separated", "string", "supporting", "quoted", "strings", "containing", "commas", "and", "concat", "function", "calls" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/xmldb/xmldb_object.php#L362-L408
213,160
moodle/moodle
mod/forum/classes/local/builders/exported_discussion.php
exported_discussion.build
public function build( stdClass $user, forum_entity $forum, discussion_entity $discussion ) : array { $favouriteids = []; if ($this->is_favourited($discussion, $forum->get_context(), $user)) { $favouriteids[] = $discussion->get_id(); } $groupsbyid = $this->get_groups_available_in_forum($forum); $discussionexporter = $this->exporterfactory->get_discussion_exporter( $user, $forum, $discussion, $groupsbyid, $favouriteids ); return (array) $discussionexporter->export($this->renderer); }
php
public function build( stdClass $user, forum_entity $forum, discussion_entity $discussion ) : array { $favouriteids = []; if ($this->is_favourited($discussion, $forum->get_context(), $user)) { $favouriteids[] = $discussion->get_id(); } $groupsbyid = $this->get_groups_available_in_forum($forum); $discussionexporter = $this->exporterfactory->get_discussion_exporter( $user, $forum, $discussion, $groupsbyid, $favouriteids ); return (array) $discussionexporter->export($this->renderer); }
[ "public", "function", "build", "(", "stdClass", "$", "user", ",", "forum_entity", "$", "forum", ",", "discussion_entity", "$", "discussion", ")", ":", "array", "{", "$", "favouriteids", "=", "[", "]", ";", "if", "(", "$", "this", "->", "is_favourited", "(", "$", "discussion", ",", "$", "forum", "->", "get_context", "(", ")", ",", "$", "user", ")", ")", "{", "$", "favouriteids", "[", "]", "=", "$", "discussion", "->", "get_id", "(", ")", ";", "}", "$", "groupsbyid", "=", "$", "this", "->", "get_groups_available_in_forum", "(", "$", "forum", ")", ";", "$", "discussionexporter", "=", "$", "this", "->", "exporterfactory", "->", "get_discussion_exporter", "(", "$", "user", ",", "$", "forum", ",", "$", "discussion", ",", "$", "groupsbyid", ",", "$", "favouriteids", ")", ";", "return", "(", "array", ")", "$", "discussionexporter", "->", "export", "(", "$", "this", "->", "renderer", ")", ";", "}" ]
Build any additional variables for the exported discussion for a given set of discussions. This will typically be used for a list of discussions in the same forum. @param stdClass $user The user to export the posts for. @param forum_entity $forum The forum that each of the $discussions belong to @param discussion_entity $discussion A list of all discussions that each of the $posts belong to @return stdClass[] List of exported posts in the same order as the $posts array.
[ "Build", "any", "additional", "variables", "for", "the", "exported", "discussion", "for", "a", "given", "set", "of", "discussions", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/builders/exported_discussion.php#L104-L121
213,161
moodle/moodle
mod/forum/classes/local/builders/exported_discussion.php
exported_discussion.is_favourited
public function is_favourited(discussion_entity $discussion, \context_module $forumcontext, \stdClass $user) { if (!isloggedin()) { return false; } $usercontext = \context_user::instance($user->id); $ufservice = \core_favourites\service_factory::get_service_for_user_context($usercontext); return $ufservice->favourite_exists('mod_forum', 'discussions', $discussion->get_id(), $forumcontext); }
php
public function is_favourited(discussion_entity $discussion, \context_module $forumcontext, \stdClass $user) { if (!isloggedin()) { return false; } $usercontext = \context_user::instance($user->id); $ufservice = \core_favourites\service_factory::get_service_for_user_context($usercontext); return $ufservice->favourite_exists('mod_forum', 'discussions', $discussion->get_id(), $forumcontext); }
[ "public", "function", "is_favourited", "(", "discussion_entity", "$", "discussion", ",", "\\", "context_module", "$", "forumcontext", ",", "\\", "stdClass", "$", "user", ")", "{", "if", "(", "!", "isloggedin", "(", ")", ")", "{", "return", "false", ";", "}", "$", "usercontext", "=", "\\", "context_user", "::", "instance", "(", "$", "user", "->", "id", ")", ";", "$", "ufservice", "=", "\\", "core_favourites", "\\", "service_factory", "::", "get_service_for_user_context", "(", "$", "usercontext", ")", ";", "return", "$", "ufservice", "->", "favourite_exists", "(", "'mod_forum'", ",", "'discussions'", ",", "$", "discussion", "->", "get_id", "(", ")", ",", "$", "forumcontext", ")", ";", "}" ]
Check whether the provided discussion has been favourited by the user. @param discussion_entity $discussion The discussion record @param \context_module $forumcontext Forum context @param \stdClass $user The user to check the favourite against @return bool Whether or not the user has favourited the discussion
[ "Check", "whether", "the", "provided", "discussion", "has", "been", "favourited", "by", "the", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/builders/exported_discussion.php#L144-L152
213,162
moodle/moodle
lib/adodb/adodb-memcache.lib.inc.php
ADODB_Cache_MemCache.connect
function connect(&$err) { if (!function_exists('memcache_pconnect')) { $err = 'Memcache module PECL extension not found!'; return false; } $memcache = new MemCache; if (!is_array($this->hosts)) $this->hosts = array($this->hosts); $failcnt = 0; foreach($this->hosts as $host) { if (!@$memcache->addServer($host,$this->port,true)) { $failcnt += 1; } } if ($failcnt == sizeof($this->hosts)) { $err = 'Can\'t connect to any memcache server'; return false; } $this->_connected = true; $this->_memcache = $memcache; return true; }
php
function connect(&$err) { if (!function_exists('memcache_pconnect')) { $err = 'Memcache module PECL extension not found!'; return false; } $memcache = new MemCache; if (!is_array($this->hosts)) $this->hosts = array($this->hosts); $failcnt = 0; foreach($this->hosts as $host) { if (!@$memcache->addServer($host,$this->port,true)) { $failcnt += 1; } } if ($failcnt == sizeof($this->hosts)) { $err = 'Can\'t connect to any memcache server'; return false; } $this->_connected = true; $this->_memcache = $memcache; return true; }
[ "function", "connect", "(", "&", "$", "err", ")", "{", "if", "(", "!", "function_exists", "(", "'memcache_pconnect'", ")", ")", "{", "$", "err", "=", "'Memcache module PECL extension not found!'", ";", "return", "false", ";", "}", "$", "memcache", "=", "new", "MemCache", ";", "if", "(", "!", "is_array", "(", "$", "this", "->", "hosts", ")", ")", "$", "this", "->", "hosts", "=", "array", "(", "$", "this", "->", "hosts", ")", ";", "$", "failcnt", "=", "0", ";", "foreach", "(", "$", "this", "->", "hosts", "as", "$", "host", ")", "{", "if", "(", "!", "@", "$", "memcache", "->", "addServer", "(", "$", "host", ",", "$", "this", "->", "port", ",", "true", ")", ")", "{", "$", "failcnt", "+=", "1", ";", "}", "}", "if", "(", "$", "failcnt", "==", "sizeof", "(", "$", "this", "->", "hosts", ")", ")", "{", "$", "err", "=", "'Can\\'t connect to any memcache server'", ";", "return", "false", ";", "}", "$", "this", "->", "_connected", "=", "true", ";", "$", "this", "->", "_memcache", "=", "$", "memcache", ";", "return", "true", ";", "}" ]
implement as lazy connection. The connection only occurs on CacheExecute call
[ "implement", "as", "lazy", "connection", ".", "The", "connection", "only", "occurs", "on", "CacheExecute", "call" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-memcache.lib.inc.php#L61-L85
213,163
moodle/moodle
lib/adodb/adodb-memcache.lib.inc.php
ADODB_Cache_MemCache.writecache
function writecache($filename, $contents, $debug, $secs2cache) { if (!$this->_connected) { $err = ''; if (!$this->connect($err) && $debug) ADOConnection::outp($err); } if (!$this->_memcache) return false; if (!$this->_memcache->set($filename, $contents, $this->compress ? MEMCACHE_COMPRESSED : 0, $secs2cache)) { if ($debug) ADOConnection::outp(" Failed to save data at the memcached server!<br>\n"); return false; } return true; }
php
function writecache($filename, $contents, $debug, $secs2cache) { if (!$this->_connected) { $err = ''; if (!$this->connect($err) && $debug) ADOConnection::outp($err); } if (!$this->_memcache) return false; if (!$this->_memcache->set($filename, $contents, $this->compress ? MEMCACHE_COMPRESSED : 0, $secs2cache)) { if ($debug) ADOConnection::outp(" Failed to save data at the memcached server!<br>\n"); return false; } return true; }
[ "function", "writecache", "(", "$", "filename", ",", "$", "contents", ",", "$", "debug", ",", "$", "secs2cache", ")", "{", "if", "(", "!", "$", "this", "->", "_connected", ")", "{", "$", "err", "=", "''", ";", "if", "(", "!", "$", "this", "->", "connect", "(", "$", "err", ")", "&&", "$", "debug", ")", "ADOConnection", "::", "outp", "(", "$", "err", ")", ";", "}", "if", "(", "!", "$", "this", "->", "_memcache", ")", "return", "false", ";", "if", "(", "!", "$", "this", "->", "_memcache", "->", "set", "(", "$", "filename", ",", "$", "contents", ",", "$", "this", "->", "compress", "?", "MEMCACHE_COMPRESSED", ":", "0", ",", "$", "secs2cache", ")", ")", "{", "if", "(", "$", "debug", ")", "ADOConnection", "::", "outp", "(", "\" Failed to save data at the memcached server!<br>\\n\"", ")", ";", "return", "false", ";", "}", "return", "true", ";", "}" ]
returns true or false. true if successful save
[ "returns", "true", "or", "false", ".", "true", "if", "successful", "save" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-memcache.lib.inc.php#L88-L102
213,164
moodle/moodle
lib/adodb/adodb-memcache.lib.inc.php
ADODB_Cache_MemCache.readcache
function readcache($filename, &$err, $secs2cache, $rsClass) { $false = false; if (!$this->_connected) $this->connect($err); if (!$this->_memcache) return $false; $rs = $this->_memcache->get($filename); if (!$rs) { $err = 'Item with such key doesn\'t exists on the memcached server.'; return $false; } // hack, should actually use _csv2rs $rs = explode("\n", $rs); unset($rs[0]); $rs = join("\n", $rs); $rs = unserialize($rs); if (! is_object($rs)) { $err = 'Unable to unserialize $rs'; return $false; } if ($rs->timeCreated == 0) return $rs; // apparently have been reports that timeCreated was set to 0 somewhere $tdiff = intval($rs->timeCreated+$secs2cache - time()); if ($tdiff <= 2) { switch($tdiff) { case 2: if ((rand() & 15) == 0) { $err = "Timeout 2"; return $false; } break; case 1: if ((rand() & 3) == 0) { $err = "Timeout 1"; return $false; } break; default: $err = "Timeout 0"; return $false; } } return $rs; }
php
function readcache($filename, &$err, $secs2cache, $rsClass) { $false = false; if (!$this->_connected) $this->connect($err); if (!$this->_memcache) return $false; $rs = $this->_memcache->get($filename); if (!$rs) { $err = 'Item with such key doesn\'t exists on the memcached server.'; return $false; } // hack, should actually use _csv2rs $rs = explode("\n", $rs); unset($rs[0]); $rs = join("\n", $rs); $rs = unserialize($rs); if (! is_object($rs)) { $err = 'Unable to unserialize $rs'; return $false; } if ($rs->timeCreated == 0) return $rs; // apparently have been reports that timeCreated was set to 0 somewhere $tdiff = intval($rs->timeCreated+$secs2cache - time()); if ($tdiff <= 2) { switch($tdiff) { case 2: if ((rand() & 15) == 0) { $err = "Timeout 2"; return $false; } break; case 1: if ((rand() & 3) == 0) { $err = "Timeout 1"; return $false; } break; default: $err = "Timeout 0"; return $false; } } return $rs; }
[ "function", "readcache", "(", "$", "filename", ",", "&", "$", "err", ",", "$", "secs2cache", ",", "$", "rsClass", ")", "{", "$", "false", "=", "false", ";", "if", "(", "!", "$", "this", "->", "_connected", ")", "$", "this", "->", "connect", "(", "$", "err", ")", ";", "if", "(", "!", "$", "this", "->", "_memcache", ")", "return", "$", "false", ";", "$", "rs", "=", "$", "this", "->", "_memcache", "->", "get", "(", "$", "filename", ")", ";", "if", "(", "!", "$", "rs", ")", "{", "$", "err", "=", "'Item with such key doesn\\'t exists on the memcached server.'", ";", "return", "$", "false", ";", "}", "// hack, should actually use _csv2rs", "$", "rs", "=", "explode", "(", "\"\\n\"", ",", "$", "rs", ")", ";", "unset", "(", "$", "rs", "[", "0", "]", ")", ";", "$", "rs", "=", "join", "(", "\"\\n\"", ",", "$", "rs", ")", ";", "$", "rs", "=", "unserialize", "(", "$", "rs", ")", ";", "if", "(", "!", "is_object", "(", "$", "rs", ")", ")", "{", "$", "err", "=", "'Unable to unserialize $rs'", ";", "return", "$", "false", ";", "}", "if", "(", "$", "rs", "->", "timeCreated", "==", "0", ")", "return", "$", "rs", ";", "// apparently have been reports that timeCreated was set to 0 somewhere", "$", "tdiff", "=", "intval", "(", "$", "rs", "->", "timeCreated", "+", "$", "secs2cache", "-", "time", "(", ")", ")", ";", "if", "(", "$", "tdiff", "<=", "2", ")", "{", "switch", "(", "$", "tdiff", ")", "{", "case", "2", ":", "if", "(", "(", "rand", "(", ")", "&", "15", ")", "==", "0", ")", "{", "$", "err", "=", "\"Timeout 2\"", ";", "return", "$", "false", ";", "}", "break", ";", "case", "1", ":", "if", "(", "(", "rand", "(", ")", "&", "3", ")", "==", "0", ")", "{", "$", "err", "=", "\"Timeout 1\"", ";", "return", "$", "false", ";", "}", "break", ";", "default", ":", "$", "err", "=", "\"Timeout 0\"", ";", "return", "$", "false", ";", "}", "}", "return", "$", "rs", ";", "}" ]
returns a recordset
[ "returns", "a", "recordset" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-memcache.lib.inc.php#L105-L149
213,165
moodle/moodle
user/classes/output/myprofile/tree.php
tree.add_node
public function add_node(node $node) { $name = $node->name; if (isset($this->nodes[$name])) { throw new \coding_exception("Node name $name already used"); } $this->nodes[$node->name] = $node; }
php
public function add_node(node $node) { $name = $node->name; if (isset($this->nodes[$name])) { throw new \coding_exception("Node name $name already used"); } $this->nodes[$node->name] = $node; }
[ "public", "function", "add_node", "(", "node", "$", "node", ")", "{", "$", "name", "=", "$", "node", "->", "name", ";", "if", "(", "isset", "(", "$", "this", "->", "nodes", "[", "$", "name", "]", ")", ")", "{", "throw", "new", "\\", "coding_exception", "(", "\"Node name $name already used\"", ")", ";", "}", "$", "this", "->", "nodes", "[", "$", "node", "->", "name", "]", "=", "$", "node", ";", "}" ]
Add a node to the tree. @param node $node node object. @throws \coding_exception
[ "Add", "a", "node", "to", "the", "tree", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/classes/output/myprofile/tree.php#L59-L65
213,166
moodle/moodle
user/classes/output/myprofile/tree.php
tree.add_category
public function add_category(category $cat) { $name = $cat->name; if (isset($this->categories[$name])) { throw new \coding_exception("Category name $name already used"); } $this->categories[$cat->name] = $cat; }
php
public function add_category(category $cat) { $name = $cat->name; if (isset($this->categories[$name])) { throw new \coding_exception("Category name $name already used"); } $this->categories[$cat->name] = $cat; }
[ "public", "function", "add_category", "(", "category", "$", "cat", ")", "{", "$", "name", "=", "$", "cat", "->", "name", ";", "if", "(", "isset", "(", "$", "this", "->", "categories", "[", "$", "name", "]", ")", ")", "{", "throw", "new", "\\", "coding_exception", "(", "\"Category name $name already used\"", ")", ";", "}", "$", "this", "->", "categories", "[", "$", "cat", "->", "name", "]", "=", "$", "cat", ";", "}" ]
Add a category to the tree. @param category $cat category object. @throws \coding_exception
[ "Add", "a", "category", "to", "the", "tree", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/classes/output/myprofile/tree.php#L74-L80
213,167
moodle/moodle
user/classes/output/myprofile/tree.php
tree.sort_categories
public function sort_categories() { $this->attach_nodes_to_categories(); $tempcategories = array(); foreach ($this->categories as $category) { $after = $category->after; if ($after == null) { // Can go anywhere in the tree. $category->sort_nodes(); $tempcategories = array_merge($tempcategories, array($category->name => $category), $this->find_categories_after($category)); } } if (count($tempcategories) !== count($this->categories)) { // Orphan categories found. throw new \coding_exception('Some of the categories specified contains invalid \'after\' property'); } $this->categories = $tempcategories; }
php
public function sort_categories() { $this->attach_nodes_to_categories(); $tempcategories = array(); foreach ($this->categories as $category) { $after = $category->after; if ($after == null) { // Can go anywhere in the tree. $category->sort_nodes(); $tempcategories = array_merge($tempcategories, array($category->name => $category), $this->find_categories_after($category)); } } if (count($tempcategories) !== count($this->categories)) { // Orphan categories found. throw new \coding_exception('Some of the categories specified contains invalid \'after\' property'); } $this->categories = $tempcategories; }
[ "public", "function", "sort_categories", "(", ")", "{", "$", "this", "->", "attach_nodes_to_categories", "(", ")", ";", "$", "tempcategories", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "categories", "as", "$", "category", ")", "{", "$", "after", "=", "$", "category", "->", "after", ";", "if", "(", "$", "after", "==", "null", ")", "{", "// Can go anywhere in the tree.", "$", "category", "->", "sort_nodes", "(", ")", ";", "$", "tempcategories", "=", "array_merge", "(", "$", "tempcategories", ",", "array", "(", "$", "category", "->", "name", "=>", "$", "category", ")", ",", "$", "this", "->", "find_categories_after", "(", "$", "category", ")", ")", ";", "}", "}", "if", "(", "count", "(", "$", "tempcategories", ")", "!==", "count", "(", "$", "this", "->", "categories", ")", ")", "{", "// Orphan categories found.", "throw", "new", "\\", "coding_exception", "(", "'Some of the categories specified contains invalid \\'after\\' property'", ")", ";", "}", "$", "this", "->", "categories", "=", "$", "tempcategories", ";", "}" ]
Sort categories and nodes. Builds the tree structure that would be displayed to the user. @throws \coding_exception
[ "Sort", "categories", "and", "nodes", ".", "Builds", "the", "tree", "structure", "that", "would", "be", "displayed", "to", "the", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/classes/output/myprofile/tree.php#L87-L104
213,168
moodle/moodle
user/classes/output/myprofile/tree.php
tree.attach_nodes_to_categories
protected function attach_nodes_to_categories() { foreach ($this->nodes as $node) { $parentcat = $node->parentcat; if (!isset($this->categories[$parentcat])) { throw new \coding_exception("Category $parentcat doesn't exist"); } else { $this->categories[$parentcat]->add_node($node); } } }
php
protected function attach_nodes_to_categories() { foreach ($this->nodes as $node) { $parentcat = $node->parentcat; if (!isset($this->categories[$parentcat])) { throw new \coding_exception("Category $parentcat doesn't exist"); } else { $this->categories[$parentcat]->add_node($node); } } }
[ "protected", "function", "attach_nodes_to_categories", "(", ")", "{", "foreach", "(", "$", "this", "->", "nodes", "as", "$", "node", ")", "{", "$", "parentcat", "=", "$", "node", "->", "parentcat", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "categories", "[", "$", "parentcat", "]", ")", ")", "{", "throw", "new", "\\", "coding_exception", "(", "\"Category $parentcat doesn't exist\"", ")", ";", "}", "else", "{", "$", "this", "->", "categories", "[", "$", "parentcat", "]", "->", "add_node", "(", "$", "node", ")", ";", "}", "}", "}" ]
Attach various nodes to their respective categories. @throws \coding_exception
[ "Attach", "various", "nodes", "to", "their", "respective", "categories", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/classes/output/myprofile/tree.php#L111-L120
213,169
moodle/moodle
user/classes/output/myprofile/tree.php
tree.find_categories_after
protected function find_categories_after($category) { $return = array(); $categoryarray = $this->categories; foreach ($categoryarray as $categoryelement) { if ($categoryelement->after == $category->name) { // Find all categories that comes after this category as well. $categoryelement->sort_nodes(); $return = array_merge($return, array($categoryelement->name => $categoryelement), $this->find_categories_after($categoryelement)); } } return $return; }
php
protected function find_categories_after($category) { $return = array(); $categoryarray = $this->categories; foreach ($categoryarray as $categoryelement) { if ($categoryelement->after == $category->name) { // Find all categories that comes after this category as well. $categoryelement->sort_nodes(); $return = array_merge($return, array($categoryelement->name => $categoryelement), $this->find_categories_after($categoryelement)); } } return $return; }
[ "protected", "function", "find_categories_after", "(", "$", "category", ")", "{", "$", "return", "=", "array", "(", ")", ";", "$", "categoryarray", "=", "$", "this", "->", "categories", ";", "foreach", "(", "$", "categoryarray", "as", "$", "categoryelement", ")", "{", "if", "(", "$", "categoryelement", "->", "after", "==", "$", "category", "->", "name", ")", "{", "// Find all categories that comes after this category as well.", "$", "categoryelement", "->", "sort_nodes", "(", ")", ";", "$", "return", "=", "array_merge", "(", "$", "return", ",", "array", "(", "$", "categoryelement", "->", "name", "=>", "$", "categoryelement", ")", ",", "$", "this", "->", "find_categories_after", "(", "$", "categoryelement", ")", ")", ";", "}", "}", "return", "$", "return", ";", "}" ]
Find all category nodes that should be displayed after a given a category node. @param category $category category object @return category[] array of category objects @throws \coding_exception
[ "Find", "all", "category", "nodes", "that", "should", "be", "displayed", "after", "a", "given", "a", "category", "node", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/classes/output/myprofile/tree.php#L130-L142
213,170
moodle/moodle
lib/filebrowser/file_info_context_coursecat.php
file_info_context_coursecat.get_courses
protected function get_courses($hiddencats) { global $DB, $CFG; require_once($CFG->libdir.'/modinfolib.php'); $params = array('category' => $this->category->id, 'contextlevel' => CONTEXT_COURSE); $sql = 'c.category = :category'; foreach ($hiddencats as $category) { $catcontext = context_coursecat::instance($category->id); $sql .= ' OR ' . $DB->sql_like('ctx.path', ':path' . $category->id); $params['path' . $category->id] = $catcontext->path . '/%'; } // Let's retrieve only minimum number of fields from course table - // what is needed to check access or call get_fast_modinfo(). $coursefields = array_merge(['id', 'visible'], course_modinfo::$cachedfields); $fields = 'c.' . join(',c.', $coursefields) . ', ' . context_helper::get_preload_record_columns_sql('ctx'); return $DB->get_records_sql('SELECT ' . $fields . ' FROM {course} c JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel) WHERE ('.$sql.') ORDER BY c.sortorder', $params); }
php
protected function get_courses($hiddencats) { global $DB, $CFG; require_once($CFG->libdir.'/modinfolib.php'); $params = array('category' => $this->category->id, 'contextlevel' => CONTEXT_COURSE); $sql = 'c.category = :category'; foreach ($hiddencats as $category) { $catcontext = context_coursecat::instance($category->id); $sql .= ' OR ' . $DB->sql_like('ctx.path', ':path' . $category->id); $params['path' . $category->id] = $catcontext->path . '/%'; } // Let's retrieve only minimum number of fields from course table - // what is needed to check access or call get_fast_modinfo(). $coursefields = array_merge(['id', 'visible'], course_modinfo::$cachedfields); $fields = 'c.' . join(',c.', $coursefields) . ', ' . context_helper::get_preload_record_columns_sql('ctx'); return $DB->get_records_sql('SELECT ' . $fields . ' FROM {course} c JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel) WHERE ('.$sql.') ORDER BY c.sortorder', $params); }
[ "protected", "function", "get_courses", "(", "$", "hiddencats", ")", "{", "global", "$", "DB", ",", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/modinfolib.php'", ")", ";", "$", "params", "=", "array", "(", "'category'", "=>", "$", "this", "->", "category", "->", "id", ",", "'contextlevel'", "=>", "CONTEXT_COURSE", ")", ";", "$", "sql", "=", "'c.category = :category'", ";", "foreach", "(", "$", "hiddencats", "as", "$", "category", ")", "{", "$", "catcontext", "=", "context_coursecat", "::", "instance", "(", "$", "category", "->", "id", ")", ";", "$", "sql", ".=", "' OR '", ".", "$", "DB", "->", "sql_like", "(", "'ctx.path'", ",", "':path'", ".", "$", "category", "->", "id", ")", ";", "$", "params", "[", "'path'", ".", "$", "category", "->", "id", "]", "=", "$", "catcontext", "->", "path", ".", "'/%'", ";", "}", "// Let's retrieve only minimum number of fields from course table -", "// what is needed to check access or call get_fast_modinfo().", "$", "coursefields", "=", "array_merge", "(", "[", "'id'", ",", "'visible'", "]", ",", "course_modinfo", "::", "$", "cachedfields", ")", ";", "$", "fields", "=", "'c.'", ".", "join", "(", "',c.'", ",", "$", "coursefields", ")", ".", "', '", ".", "context_helper", "::", "get_preload_record_columns_sql", "(", "'ctx'", ")", ";", "return", "$", "DB", "->", "get_records_sql", "(", "'SELECT '", ".", "$", "fields", ".", "' FROM {course} c\n JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)\n WHERE ('", ".", "$", "sql", ".", "') ORDER BY c.sortorder'", ",", "$", "params", ")", ";", "}" ]
List of courses in this category and in hidden subcategories @param array $hiddencats list of categories that are hidden from current user and returned by {@link get_categories()} @return array list of courses
[ "List", "of", "courses", "in", "this", "category", "and", "in", "hidden", "subcategories" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filebrowser/file_info_context_coursecat.php#L191-L212
213,171
moodle/moodle
lib/filebrowser/file_info_context_coursecat.php
file_info_context_coursecat.get_categories
protected function get_categories() { global $DB; $fields = 'c.*, ' . context_helper::get_preload_record_columns_sql('ctx'); $coursecats = $DB->get_records_sql('SELECT ' . $fields . ' FROM {course_categories} c LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel) WHERE c.parent = :parent ORDER BY c.sortorder', array('parent' => $this->category->id, 'contextlevel' => CONTEXT_COURSECAT)); $hiddencats = []; foreach ($coursecats as $id => &$category) { context_helper::preload_from_record($category); if (!core_course_category::can_view_category($category)) { $hiddencats[$id] = $coursecats[$id]; unset($coursecats[$id]); } } return [$coursecats, $hiddencats]; }
php
protected function get_categories() { global $DB; $fields = 'c.*, ' . context_helper::get_preload_record_columns_sql('ctx'); $coursecats = $DB->get_records_sql('SELECT ' . $fields . ' FROM {course_categories} c LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel) WHERE c.parent = :parent ORDER BY c.sortorder', array('parent' => $this->category->id, 'contextlevel' => CONTEXT_COURSECAT)); $hiddencats = []; foreach ($coursecats as $id => &$category) { context_helper::preload_from_record($category); if (!core_course_category::can_view_category($category)) { $hiddencats[$id] = $coursecats[$id]; unset($coursecats[$id]); } } return [$coursecats, $hiddencats]; }
[ "protected", "function", "get_categories", "(", ")", "{", "global", "$", "DB", ";", "$", "fields", "=", "'c.*, '", ".", "context_helper", "::", "get_preload_record_columns_sql", "(", "'ctx'", ")", ";", "$", "coursecats", "=", "$", "DB", "->", "get_records_sql", "(", "'SELECT '", ".", "$", "fields", ".", "' FROM {course_categories} c\n LEFT JOIN {context} ctx ON (ctx.instanceid = c.id AND ctx.contextlevel = :contextlevel)\n WHERE c.parent = :parent ORDER BY c.sortorder'", ",", "array", "(", "'parent'", "=>", "$", "this", "->", "category", "->", "id", ",", "'contextlevel'", "=>", "CONTEXT_COURSECAT", ")", ")", ";", "$", "hiddencats", "=", "[", "]", ";", "foreach", "(", "$", "coursecats", "as", "$", "id", "=>", "&", "$", "category", ")", "{", "context_helper", "::", "preload_from_record", "(", "$", "category", ")", ";", "if", "(", "!", "core_course_category", "::", "can_view_category", "(", "$", "category", ")", ")", "{", "$", "hiddencats", "[", "$", "id", "]", "=", "$", "coursecats", "[", "$", "id", "]", ";", "unset", "(", "$", "coursecats", "[", "$", "id", "]", ")", ";", "}", "}", "return", "[", "$", "coursecats", ",", "$", "hiddencats", "]", ";", "}" ]
Finds accessible and non-accessible direct subcategories @return array [$coursecats, $hiddencats] - child categories that are visible to the current user and not visible
[ "Finds", "accessible", "and", "non", "-", "accessible", "direct", "subcategories" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filebrowser/file_info_context_coursecat.php#L219-L237
213,172
moodle/moodle
lib/filebrowser/file_info_context_coursecat.php
file_info_context_coursecat.get_child_course
protected function get_child_course($course) { context_helper::preload_from_record($course); $context = context_course::instance($course->id); $child = new file_info_context_course($this->browser, $context, $course); return $child->get_file_info(null, null, null, null, null); }
php
protected function get_child_course($course) { context_helper::preload_from_record($course); $context = context_course::instance($course->id); $child = new file_info_context_course($this->browser, $context, $course); return $child->get_file_info(null, null, null, null, null); }
[ "protected", "function", "get_child_course", "(", "$", "course", ")", "{", "context_helper", "::", "preload_from_record", "(", "$", "course", ")", ";", "$", "context", "=", "context_course", "::", "instance", "(", "$", "course", "->", "id", ")", ";", "$", "child", "=", "new", "file_info_context_course", "(", "$", "this", "->", "browser", ",", "$", "context", ",", "$", "course", ")", ";", "return", "$", "child", "->", "get_file_info", "(", "null", ",", "null", ",", "null", ",", "null", ",", "null", ")", ";", "}" ]
Returns the file info element for a given course or null if course is not accessible @param stdClass $course may contain context fields for preloading @return file_info_context_course|null
[ "Returns", "the", "file", "info", "element", "for", "a", "given", "course", "or", "null", "if", "course", "is", "not", "accessible" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filebrowser/file_info_context_coursecat.php#L245-L250
213,173
moodle/moodle
lib/google/src/Google/Client.php
Google_Client.verifySignedJwt
public function verifySignedJwt($id_token, $cert_location, $audience, $issuer, $max_expiry = null) { $auth = new Google_Auth_OAuth2($this); $certs = $auth->retrieveCertsFromLocation($cert_location); return $auth->verifySignedJwtWithCerts($id_token, $certs, $audience, $issuer, $max_expiry); }
php
public function verifySignedJwt($id_token, $cert_location, $audience, $issuer, $max_expiry = null) { $auth = new Google_Auth_OAuth2($this); $certs = $auth->retrieveCertsFromLocation($cert_location); return $auth->verifySignedJwtWithCerts($id_token, $certs, $audience, $issuer, $max_expiry); }
[ "public", "function", "verifySignedJwt", "(", "$", "id_token", ",", "$", "cert_location", ",", "$", "audience", ",", "$", "issuer", ",", "$", "max_expiry", "=", "null", ")", "{", "$", "auth", "=", "new", "Google_Auth_OAuth2", "(", "$", "this", ")", ";", "$", "certs", "=", "$", "auth", "->", "retrieveCertsFromLocation", "(", "$", "cert_location", ")", ";", "return", "$", "auth", "->", "verifySignedJwtWithCerts", "(", "$", "id_token", ",", "$", "certs", ",", "$", "audience", ",", "$", "issuer", ",", "$", "max_expiry", ")", ";", "}" ]
Verify a JWT that was signed with your own certificates. @param $id_token string The JWT token @param $cert_location array of certificates @param $audience string the expected consumer of the token @param $issuer string the expected issuer, defaults to Google @param [$max_expiry] the max lifetime of a token, defaults to MAX_TOKEN_LIFETIME_SECS @return mixed token information if valid, false if not
[ "Verify", "a", "JWT", "that", "was", "signed", "with", "your", "own", "certificates", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/google/src/Google/Client.php#L495-L500
213,174
moodle/moodle
admin/tool/analytics/classes/output/renderer.php
renderer.render_evaluate_results
public function render_evaluate_results($results, $logs = array()) { global $OUTPUT; $output = ''; foreach ($results as $timesplittingid => $result) { if (!CLI_SCRIPT) { $output .= $OUTPUT->box_start('generalbox mb-3'); } // Check that the array key is a string, not all results depend on time splitting methods (e.g. general errors). if (!is_numeric($timesplittingid)) { $timesplitting = \core_analytics\manager::get_time_splitting($timesplittingid); $langstrdata = (object)array('name' => $timesplitting->get_name(), 'id' => $timesplittingid); if (CLI_SCRIPT) { $output .= $OUTPUT->heading(get_string('getpredictionsresultscli', 'tool_analytics', $langstrdata), 3); } else { $output .= $OUTPUT->heading(get_string('getpredictionsresults', 'tool_analytics', $langstrdata), 3); } } if ($result->status == 0) { $output .= $OUTPUT->notification(get_string('goodmodel', 'tool_analytics'), \core\output\notification::NOTIFY_SUCCESS); } else if ($result->status === \core_analytics\model::NO_DATASET) { $output .= $OUTPUT->notification(get_string('nodatatoevaluate', 'tool_analytics'), \core\output\notification::NOTIFY_WARNING); } if (isset($result->score)) { // Score. $output .= $OUTPUT->heading(get_string('accuracy', 'tool_analytics') . ': ' . round(floatval($result->score), 4) * 100 . '%', 4); } if (!empty($result->info)) { foreach ($result->info as $message) { $output .= $OUTPUT->notification($message, \core\output\notification::NOTIFY_WARNING); } } if (!CLI_SCRIPT) { $output .= $OUTPUT->box_end(); } } // Info logged during evaluation. if (!empty($logs) && debugging()) { $output .= $OUTPUT->heading(get_string('extrainfo', 'tool_analytics'), 3); foreach ($logs as $log) { $output .= $OUTPUT->notification($log, \core\output\notification::NOTIFY_WARNING); } } if (!CLI_SCRIPT) { $output .= $OUTPUT->single_button(new \moodle_url('/admin/tool/analytics/index.php'), get_string('continue'), 'get'); } return $output; }
php
public function render_evaluate_results($results, $logs = array()) { global $OUTPUT; $output = ''; foreach ($results as $timesplittingid => $result) { if (!CLI_SCRIPT) { $output .= $OUTPUT->box_start('generalbox mb-3'); } // Check that the array key is a string, not all results depend on time splitting methods (e.g. general errors). if (!is_numeric($timesplittingid)) { $timesplitting = \core_analytics\manager::get_time_splitting($timesplittingid); $langstrdata = (object)array('name' => $timesplitting->get_name(), 'id' => $timesplittingid); if (CLI_SCRIPT) { $output .= $OUTPUT->heading(get_string('getpredictionsresultscli', 'tool_analytics', $langstrdata), 3); } else { $output .= $OUTPUT->heading(get_string('getpredictionsresults', 'tool_analytics', $langstrdata), 3); } } if ($result->status == 0) { $output .= $OUTPUT->notification(get_string('goodmodel', 'tool_analytics'), \core\output\notification::NOTIFY_SUCCESS); } else if ($result->status === \core_analytics\model::NO_DATASET) { $output .= $OUTPUT->notification(get_string('nodatatoevaluate', 'tool_analytics'), \core\output\notification::NOTIFY_WARNING); } if (isset($result->score)) { // Score. $output .= $OUTPUT->heading(get_string('accuracy', 'tool_analytics') . ': ' . round(floatval($result->score), 4) * 100 . '%', 4); } if (!empty($result->info)) { foreach ($result->info as $message) { $output .= $OUTPUT->notification($message, \core\output\notification::NOTIFY_WARNING); } } if (!CLI_SCRIPT) { $output .= $OUTPUT->box_end(); } } // Info logged during evaluation. if (!empty($logs) && debugging()) { $output .= $OUTPUT->heading(get_string('extrainfo', 'tool_analytics'), 3); foreach ($logs as $log) { $output .= $OUTPUT->notification($log, \core\output\notification::NOTIFY_WARNING); } } if (!CLI_SCRIPT) { $output .= $OUTPUT->single_button(new \moodle_url('/admin/tool/analytics/index.php'), get_string('continue'), 'get'); } return $output; }
[ "public", "function", "render_evaluate_results", "(", "$", "results", ",", "$", "logs", "=", "array", "(", ")", ")", "{", "global", "$", "OUTPUT", ";", "$", "output", "=", "''", ";", "foreach", "(", "$", "results", "as", "$", "timesplittingid", "=>", "$", "result", ")", "{", "if", "(", "!", "CLI_SCRIPT", ")", "{", "$", "output", ".=", "$", "OUTPUT", "->", "box_start", "(", "'generalbox mb-3'", ")", ";", "}", "// Check that the array key is a string, not all results depend on time splitting methods (e.g. general errors).", "if", "(", "!", "is_numeric", "(", "$", "timesplittingid", ")", ")", "{", "$", "timesplitting", "=", "\\", "core_analytics", "\\", "manager", "::", "get_time_splitting", "(", "$", "timesplittingid", ")", ";", "$", "langstrdata", "=", "(", "object", ")", "array", "(", "'name'", "=>", "$", "timesplitting", "->", "get_name", "(", ")", ",", "'id'", "=>", "$", "timesplittingid", ")", ";", "if", "(", "CLI_SCRIPT", ")", "{", "$", "output", ".=", "$", "OUTPUT", "->", "heading", "(", "get_string", "(", "'getpredictionsresultscli'", ",", "'tool_analytics'", ",", "$", "langstrdata", ")", ",", "3", ")", ";", "}", "else", "{", "$", "output", ".=", "$", "OUTPUT", "->", "heading", "(", "get_string", "(", "'getpredictionsresults'", ",", "'tool_analytics'", ",", "$", "langstrdata", ")", ",", "3", ")", ";", "}", "}", "if", "(", "$", "result", "->", "status", "==", "0", ")", "{", "$", "output", ".=", "$", "OUTPUT", "->", "notification", "(", "get_string", "(", "'goodmodel'", ",", "'tool_analytics'", ")", ",", "\\", "core", "\\", "output", "\\", "notification", "::", "NOTIFY_SUCCESS", ")", ";", "}", "else", "if", "(", "$", "result", "->", "status", "===", "\\", "core_analytics", "\\", "model", "::", "NO_DATASET", ")", "{", "$", "output", ".=", "$", "OUTPUT", "->", "notification", "(", "get_string", "(", "'nodatatoevaluate'", ",", "'tool_analytics'", ")", ",", "\\", "core", "\\", "output", "\\", "notification", "::", "NOTIFY_WARNING", ")", ";", "}", "if", "(", "isset", "(", "$", "result", "->", "score", ")", ")", "{", "// Score.", "$", "output", ".=", "$", "OUTPUT", "->", "heading", "(", "get_string", "(", "'accuracy'", ",", "'tool_analytics'", ")", ".", "': '", ".", "round", "(", "floatval", "(", "$", "result", "->", "score", ")", ",", "4", ")", "*", "100", ".", "'%'", ",", "4", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "result", "->", "info", ")", ")", "{", "foreach", "(", "$", "result", "->", "info", "as", "$", "message", ")", "{", "$", "output", ".=", "$", "OUTPUT", "->", "notification", "(", "$", "message", ",", "\\", "core", "\\", "output", "\\", "notification", "::", "NOTIFY_WARNING", ")", ";", "}", "}", "if", "(", "!", "CLI_SCRIPT", ")", "{", "$", "output", ".=", "$", "OUTPUT", "->", "box_end", "(", ")", ";", "}", "}", "// Info logged during evaluation.", "if", "(", "!", "empty", "(", "$", "logs", ")", "&&", "debugging", "(", ")", ")", "{", "$", "output", ".=", "$", "OUTPUT", "->", "heading", "(", "get_string", "(", "'extrainfo'", ",", "'tool_analytics'", ")", ",", "3", ")", ";", "foreach", "(", "$", "logs", "as", "$", "log", ")", "{", "$", "output", ".=", "$", "OUTPUT", "->", "notification", "(", "$", "log", ",", "\\", "core", "\\", "output", "\\", "notification", "::", "NOTIFY_WARNING", ")", ";", "}", "}", "if", "(", "!", "CLI_SCRIPT", ")", "{", "$", "output", ".=", "$", "OUTPUT", "->", "single_button", "(", "new", "\\", "moodle_url", "(", "'/admin/tool/analytics/index.php'", ")", ",", "get_string", "(", "'continue'", ")", ",", "'get'", ")", ";", "}", "return", "$", "output", ";", "}" ]
Web interface evaluate results. @param \stdClass[] $results @param string[] $logs @return string HTML
[ "Web", "interface", "evaluate", "results", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/analytics/classes/output/renderer.php#L76-L137
213,175
moodle/moodle
lib/horde/framework/Horde/Mime/Magic.php
Horde_Mime_Magic._getMimeExtensionMap
protected static function _getMimeExtensionMap() { if (is_null(self::$_map)) { require __DIR__ . '/mime.mapping.php'; self::$_map = $mime_extension_map; } return self::$_map; }
php
protected static function _getMimeExtensionMap() { if (is_null(self::$_map)) { require __DIR__ . '/mime.mapping.php'; self::$_map = $mime_extension_map; } return self::$_map; }
[ "protected", "static", "function", "_getMimeExtensionMap", "(", ")", "{", "if", "(", "is_null", "(", "self", "::", "$", "_map", ")", ")", "{", "require", "__DIR__", ".", "'/mime.mapping.php'", ";", "self", "::", "$", "_map", "=", "$", "mime_extension_map", ";", "}", "return", "self", "::", "$", "_map", ";", "}" ]
Returns a copy of the MIME extension map. @return array The MIME extension map.
[ "Returns", "a", "copy", "of", "the", "MIME", "extension", "map", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Magic.php#L38-L46
213,176
moodle/moodle
lib/horde/framework/Horde/Mime/Magic.php
Horde_Mime_Magic.extToMime
public static function extToMime($ext) { if (empty($ext)) { return 'application/octet-stream'; } $ext = Horde_String::lower($ext); $map = self::_getMimeExtensionMap(); $pos = 0; while (!isset($map[$ext])) { if (($pos = strpos($ext, '.')) === false) { break; } $ext = substr($ext, $pos + 1); } return isset($map[$ext]) ? $map[$ext] : 'x-extension/' . $ext; }
php
public static function extToMime($ext) { if (empty($ext)) { return 'application/octet-stream'; } $ext = Horde_String::lower($ext); $map = self::_getMimeExtensionMap(); $pos = 0; while (!isset($map[$ext])) { if (($pos = strpos($ext, '.')) === false) { break; } $ext = substr($ext, $pos + 1); } return isset($map[$ext]) ? $map[$ext] : 'x-extension/' . $ext; }
[ "public", "static", "function", "extToMime", "(", "$", "ext", ")", "{", "if", "(", "empty", "(", "$", "ext", ")", ")", "{", "return", "'application/octet-stream'", ";", "}", "$", "ext", "=", "Horde_String", "::", "lower", "(", "$", "ext", ")", ";", "$", "map", "=", "self", "::", "_getMimeExtensionMap", "(", ")", ";", "$", "pos", "=", "0", ";", "while", "(", "!", "isset", "(", "$", "map", "[", "$", "ext", "]", ")", ")", "{", "if", "(", "(", "$", "pos", "=", "strpos", "(", "$", "ext", ",", "'.'", ")", ")", "===", "false", ")", "{", "break", ";", "}", "$", "ext", "=", "substr", "(", "$", "ext", ",", "$", "pos", "+", "1", ")", ";", "}", "return", "isset", "(", "$", "map", "[", "$", "ext", "]", ")", "?", "$", "map", "[", "$", "ext", "]", ":", "'x-extension/'", ".", "$", "ext", ";", "}" ]
Attempt to convert a file extension to a MIME type, based on the global Horde and application specific config files. If we cannot map the file extension to a specific type, then we fall back to a custom MIME handler 'x-extension/$ext', which can be used as a normal MIME type internally throughout Horde. @param string $ext The file extension to be mapped to a MIME type. @return string The MIME type of the file extension.
[ "Attempt", "to", "convert", "a", "file", "extension", "to", "a", "MIME", "type", "based", "on", "the", "global", "Horde", "and", "application", "specific", "config", "files", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Magic.php#L60-L80
213,177
moodle/moodle
lib/horde/framework/Horde/Mime/Magic.php
Horde_Mime_Magic.filenameToMime
public static function filenameToMime($filename, $unknown = true) { $pos = strlen($filename) + 1; $type = ''; $map = self::_getMimeExtensionMap(); for ($i = 0; $i <= $map['__MAXPERIOD__']; ++$i) { $npos = strrpos(substr($filename, 0, $pos - 1), '.'); if ($npos === false) { break; } $pos = $npos + 1; } $type = ($pos === false) ? '' : self::extToMime(substr($filename, $pos)); return (empty($type) || (!$unknown && (strpos($type, 'x-extension') !== false))) ? 'application/octet-stream' : $type; }
php
public static function filenameToMime($filename, $unknown = true) { $pos = strlen($filename) + 1; $type = ''; $map = self::_getMimeExtensionMap(); for ($i = 0; $i <= $map['__MAXPERIOD__']; ++$i) { $npos = strrpos(substr($filename, 0, $pos - 1), '.'); if ($npos === false) { break; } $pos = $npos + 1; } $type = ($pos === false) ? '' : self::extToMime(substr($filename, $pos)); return (empty($type) || (!$unknown && (strpos($type, 'x-extension') !== false))) ? 'application/octet-stream' : $type; }
[ "public", "static", "function", "filenameToMime", "(", "$", "filename", ",", "$", "unknown", "=", "true", ")", "{", "$", "pos", "=", "strlen", "(", "$", "filename", ")", "+", "1", ";", "$", "type", "=", "''", ";", "$", "map", "=", "self", "::", "_getMimeExtensionMap", "(", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<=", "$", "map", "[", "'__MAXPERIOD__'", "]", ";", "++", "$", "i", ")", "{", "$", "npos", "=", "strrpos", "(", "substr", "(", "$", "filename", ",", "0", ",", "$", "pos", "-", "1", ")", ",", "'.'", ")", ";", "if", "(", "$", "npos", "===", "false", ")", "{", "break", ";", "}", "$", "pos", "=", "$", "npos", "+", "1", ";", "}", "$", "type", "=", "(", "$", "pos", "===", "false", ")", "?", "''", ":", "self", "::", "extToMime", "(", "substr", "(", "$", "filename", ",", "$", "pos", ")", ")", ";", "return", "(", "empty", "(", "$", "type", ")", "||", "(", "!", "$", "unknown", "&&", "(", "strpos", "(", "$", "type", ",", "'x-extension'", ")", "!==", "false", ")", ")", ")", "?", "'application/octet-stream'", ":", "$", "type", ";", "}" ]
Attempt to convert a filename to a MIME type, based on the global Horde and application specific config files. @param string $filename The filename to be mapped to a MIME type. @param boolean $unknown How should unknown extensions be handled? If true, will return 'x-extension/*' types. If false, will return 'application/octet-stream'. @return string The MIME type of the filename.
[ "Attempt", "to", "convert", "a", "filename", "to", "a", "MIME", "type", "based", "on", "the", "global", "Horde", "and", "application", "specific", "config", "files", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Magic.php#L93-L112
213,178
moodle/moodle
lib/horde/framework/Horde/Mime/Magic.php
Horde_Mime_Magic.mimeToExt
public static function mimeToExt($type) { if (empty($type)) { return false; } if (($key = array_search($type, self::_getMimeExtensionMap())) === false) { list($major, $minor) = explode('/', $type); if ($major == 'x-extension') { return $minor; } if (strpos($minor, 'x-') === 0) { return substr($minor, 2); } return false; } return $key; }
php
public static function mimeToExt($type) { if (empty($type)) { return false; } if (($key = array_search($type, self::_getMimeExtensionMap())) === false) { list($major, $minor) = explode('/', $type); if ($major == 'x-extension') { return $minor; } if (strpos($minor, 'x-') === 0) { return substr($minor, 2); } return false; } return $key; }
[ "public", "static", "function", "mimeToExt", "(", "$", "type", ")", "{", "if", "(", "empty", "(", "$", "type", ")", ")", "{", "return", "false", ";", "}", "if", "(", "(", "$", "key", "=", "array_search", "(", "$", "type", ",", "self", "::", "_getMimeExtensionMap", "(", ")", ")", ")", "===", "false", ")", "{", "list", "(", "$", "major", ",", "$", "minor", ")", "=", "explode", "(", "'/'", ",", "$", "type", ")", ";", "if", "(", "$", "major", "==", "'x-extension'", ")", "{", "return", "$", "minor", ";", "}", "if", "(", "strpos", "(", "$", "minor", ",", "'x-'", ")", "===", "0", ")", "{", "return", "substr", "(", "$", "minor", ",", "2", ")", ";", "}", "return", "false", ";", "}", "return", "$", "key", ";", "}" ]
Attempt to convert a MIME type to a file extension, based on the global Horde and application specific config files. If we cannot map the type to a file extension, we return false. @param string $type The MIME type to be mapped to a file extension. @return string The file extension of the MIME type.
[ "Attempt", "to", "convert", "a", "MIME", "type", "to", "a", "file", "extension", "based", "on", "the", "global", "Horde", "and", "application", "specific", "config", "files", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Magic.php#L124-L142
213,179
moodle/moodle
lib/horde/framework/Horde/Mime/Magic.php
Horde_Mime_Magic.analyzeFile
public static function analyzeFile($path, $magic_db = null, $opts = array()) { if (Horde_Util::extensionExists('fileinfo')) { $res = empty($magic_db) ? finfo_open(FILEINFO_MIME) : finfo_open(FILEINFO_MIME, $magic_db); if ($res) { $type = trim(finfo_file($res, $path)); finfo_close($res); /* Remove any additional information. */ if (empty($opts['nostrip'])) { foreach (array(';', ',', '\\0') as $separator) { if (($pos = strpos($type, $separator)) !== false) { $type = rtrim(substr($type, 0, $pos)); } } if (preg_match('|^[a-z0-9]+/[.-a-z0-9]+$|i', $type)) { return $type; } } else { return $type; } } } return false; }
php
public static function analyzeFile($path, $magic_db = null, $opts = array()) { if (Horde_Util::extensionExists('fileinfo')) { $res = empty($magic_db) ? finfo_open(FILEINFO_MIME) : finfo_open(FILEINFO_MIME, $magic_db); if ($res) { $type = trim(finfo_file($res, $path)); finfo_close($res); /* Remove any additional information. */ if (empty($opts['nostrip'])) { foreach (array(';', ',', '\\0') as $separator) { if (($pos = strpos($type, $separator)) !== false) { $type = rtrim(substr($type, 0, $pos)); } } if (preg_match('|^[a-z0-9]+/[.-a-z0-9]+$|i', $type)) { return $type; } } else { return $type; } } } return false; }
[ "public", "static", "function", "analyzeFile", "(", "$", "path", ",", "$", "magic_db", "=", "null", ",", "$", "opts", "=", "array", "(", ")", ")", "{", "if", "(", "Horde_Util", "::", "extensionExists", "(", "'fileinfo'", ")", ")", "{", "$", "res", "=", "empty", "(", "$", "magic_db", ")", "?", "finfo_open", "(", "FILEINFO_MIME", ")", ":", "finfo_open", "(", "FILEINFO_MIME", ",", "$", "magic_db", ")", ";", "if", "(", "$", "res", ")", "{", "$", "type", "=", "trim", "(", "finfo_file", "(", "$", "res", ",", "$", "path", ")", ")", ";", "finfo_close", "(", "$", "res", ")", ";", "/* Remove any additional information. */", "if", "(", "empty", "(", "$", "opts", "[", "'nostrip'", "]", ")", ")", "{", "foreach", "(", "array", "(", "';'", ",", "','", ",", "'\\\\0'", ")", "as", "$", "separator", ")", "{", "if", "(", "(", "$", "pos", "=", "strpos", "(", "$", "type", ",", "$", "separator", ")", ")", "!==", "false", ")", "{", "$", "type", "=", "rtrim", "(", "substr", "(", "$", "type", ",", "0", ",", "$", "pos", ")", ")", ";", "}", "}", "if", "(", "preg_match", "(", "'|^[a-z0-9]+/[.-a-z0-9]+$|i'", ",", "$", "type", ")", ")", "{", "return", "$", "type", ";", "}", "}", "else", "{", "return", "$", "type", ";", "}", "}", "}", "return", "false", ";", "}" ]
Attempt to determine the MIME type of an unknown file. @param string $path The path to the file to analyze. @param string $magic_db Path to the mime magic database. @param array $opts Additional options: - nostrip: (boolean) Don't strip parameter information from MIME type string. DEFAULT: false @return mixed The MIME type of the file. Returns false if the file type can not be determined.
[ "Attempt", "to", "determine", "the", "MIME", "type", "of", "an", "unknown", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Magic.php#L157-L187
213,180
moodle/moodle
lib/horde/framework/Horde/Mime/Magic.php
Horde_Mime_Magic.analyzeData
public static function analyzeData($data, $magic_db = null, $opts = array()) { /* If the PHP Mimetype extension is available, use that. */ if (Horde_Util::extensionExists('fileinfo')) { $res = empty($magic_db) ? @finfo_open(FILEINFO_MIME) : @finfo_open(FILEINFO_MIME, $magic_db); if (!$res) { return false; } $type = trim(finfo_buffer($res, $data)); finfo_close($res); /* Remove any additional information. */ if (empty($opts['nostrip'])) { if (($pos = strpos($type, ';')) !== false) { $type = rtrim(substr($type, 0, $pos)); } if (($pos = strpos($type, ',')) !== false) { $type = rtrim(substr($type, 0, $pos)); } } return $type; } return false; }
php
public static function analyzeData($data, $magic_db = null, $opts = array()) { /* If the PHP Mimetype extension is available, use that. */ if (Horde_Util::extensionExists('fileinfo')) { $res = empty($magic_db) ? @finfo_open(FILEINFO_MIME) : @finfo_open(FILEINFO_MIME, $magic_db); if (!$res) { return false; } $type = trim(finfo_buffer($res, $data)); finfo_close($res); /* Remove any additional information. */ if (empty($opts['nostrip'])) { if (($pos = strpos($type, ';')) !== false) { $type = rtrim(substr($type, 0, $pos)); } if (($pos = strpos($type, ',')) !== false) { $type = rtrim(substr($type, 0, $pos)); } } return $type; } return false; }
[ "public", "static", "function", "analyzeData", "(", "$", "data", ",", "$", "magic_db", "=", "null", ",", "$", "opts", "=", "array", "(", ")", ")", "{", "/* If the PHP Mimetype extension is available, use that. */", "if", "(", "Horde_Util", "::", "extensionExists", "(", "'fileinfo'", ")", ")", "{", "$", "res", "=", "empty", "(", "$", "magic_db", ")", "?", "@", "finfo_open", "(", "FILEINFO_MIME", ")", ":", "@", "finfo_open", "(", "FILEINFO_MIME", ",", "$", "magic_db", ")", ";", "if", "(", "!", "$", "res", ")", "{", "return", "false", ";", "}", "$", "type", "=", "trim", "(", "finfo_buffer", "(", "$", "res", ",", "$", "data", ")", ")", ";", "finfo_close", "(", "$", "res", ")", ";", "/* Remove any additional information. */", "if", "(", "empty", "(", "$", "opts", "[", "'nostrip'", "]", ")", ")", "{", "if", "(", "(", "$", "pos", "=", "strpos", "(", "$", "type", ",", "';'", ")", ")", "!==", "false", ")", "{", "$", "type", "=", "rtrim", "(", "substr", "(", "$", "type", ",", "0", ",", "$", "pos", ")", ")", ";", "}", "if", "(", "(", "$", "pos", "=", "strpos", "(", "$", "type", ",", "','", ")", ")", "!==", "false", ")", "{", "$", "type", "=", "rtrim", "(", "substr", "(", "$", "type", ",", "0", ",", "$", "pos", ")", ")", ";", "}", "}", "return", "$", "type", ";", "}", "return", "false", ";", "}" ]
Attempt to determine the MIME type of an unknown byte stream. @param string $data The file data to analyze. @param string $magic_db Path to the mime magic database. @param array $opts Additional options: - nostrip: (boolean) Don't strip parameter information from MIME type string. DEFAULT: false @return mixed The MIME type of the file. Returns false if the file type can not be determined.
[ "Attempt", "to", "determine", "the", "MIME", "type", "of", "an", "unknown", "byte", "stream", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Mime/Magic.php#L202-L233
213,181
moodle/moodle
lib/adodb/adodb-active-recordx.inc.php
ADODB_Active_Table.updateColsCount
function updateColsCount() { $this->_colsCount = sizeof($this->flds); foreach($this->_belongsTo as $foreignTable) $this->_colsCount += sizeof($foreignTable->TableInfo()->flds); foreach($this->_hasMany as $foreignTable) $this->_colsCount += sizeof($foreignTable->TableInfo()->flds); }
php
function updateColsCount() { $this->_colsCount = sizeof($this->flds); foreach($this->_belongsTo as $foreignTable) $this->_colsCount += sizeof($foreignTable->TableInfo()->flds); foreach($this->_hasMany as $foreignTable) $this->_colsCount += sizeof($foreignTable->TableInfo()->flds); }
[ "function", "updateColsCount", "(", ")", "{", "$", "this", "->", "_colsCount", "=", "sizeof", "(", "$", "this", "->", "flds", ")", ";", "foreach", "(", "$", "this", "->", "_belongsTo", "as", "$", "foreignTable", ")", "$", "this", "->", "_colsCount", "+=", "sizeof", "(", "$", "foreignTable", "->", "TableInfo", "(", ")", "->", "flds", ")", ";", "foreach", "(", "$", "this", "->", "_hasMany", "as", "$", "foreignTable", ")", "$", "this", "->", "_colsCount", "+=", "sizeof", "(", "$", "foreignTable", "->", "TableInfo", "(", ")", "->", "flds", ")", ";", "}" ]
total columns count, including relations
[ "total", "columns", "count", "including", "relations" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-active-recordx.inc.php#L54-L61
213,182
moodle/moodle
lib/adodb/adodb-active-recordx.inc.php
ADODB_Active_Record.Error
function Error($err,$fn) { global $_ADODB_ACTIVE_DBS; $fn = get_class($this).'::'.$fn; $this->_lasterr = $fn.': '.$err; if ($this->_dbat < 0) { $db = false; } else { $activedb = $_ADODB_ACTIVE_DBS[$this->_dbat]; $db = $activedb->db; } if (function_exists('adodb_throw')) { if (!$db) { adodb_throw('ADOdb_Active_Record', $fn, -1, $err, 0, 0, false); } else { adodb_throw($db->databaseType, $fn, -1, $err, 0, 0, $db); } } else { if (!$db || $db->debug) { ADOConnection::outp($this->_lasterr); } } }
php
function Error($err,$fn) { global $_ADODB_ACTIVE_DBS; $fn = get_class($this).'::'.$fn; $this->_lasterr = $fn.': '.$err; if ($this->_dbat < 0) { $db = false; } else { $activedb = $_ADODB_ACTIVE_DBS[$this->_dbat]; $db = $activedb->db; } if (function_exists('adodb_throw')) { if (!$db) { adodb_throw('ADOdb_Active_Record', $fn, -1, $err, 0, 0, false); } else { adodb_throw($db->databaseType, $fn, -1, $err, 0, 0, $db); } } else { if (!$db || $db->debug) { ADOConnection::outp($this->_lasterr); } } }
[ "function", "Error", "(", "$", "err", ",", "$", "fn", ")", "{", "global", "$", "_ADODB_ACTIVE_DBS", ";", "$", "fn", "=", "get_class", "(", "$", "this", ")", ".", "'::'", ".", "$", "fn", ";", "$", "this", "->", "_lasterr", "=", "$", "fn", ".", "': '", ".", "$", "err", ";", "if", "(", "$", "this", "->", "_dbat", "<", "0", ")", "{", "$", "db", "=", "false", ";", "}", "else", "{", "$", "activedb", "=", "$", "_ADODB_ACTIVE_DBS", "[", "$", "this", "->", "_dbat", "]", ";", "$", "db", "=", "$", "activedb", "->", "db", ";", "}", "if", "(", "function_exists", "(", "'adodb_throw'", ")", ")", "{", "if", "(", "!", "$", "db", ")", "{", "adodb_throw", "(", "'ADOdb_Active_Record'", ",", "$", "fn", ",", "-", "1", ",", "$", "err", ",", "0", ",", "0", ",", "false", ")", ";", "}", "else", "{", "adodb_throw", "(", "$", "db", "->", "databaseType", ",", "$", "fn", ",", "-", "1", ",", "$", "err", ",", "0", ",", "0", ",", "$", "db", ")", ";", "}", "}", "else", "{", "if", "(", "!", "$", "db", "||", "$", "db", "->", "debug", ")", "{", "ADOConnection", "::", "outp", "(", "$", "this", "->", "_lasterr", ")", ";", "}", "}", "}" ]
error handler for both PHP4+5.
[ "error", "handler", "for", "both", "PHP4", "+", "5", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-active-recordx.inc.php#L575-L603
213,183
moodle/moodle
lib/adodb/adodb-active-recordx.inc.php
ADODB_Active_Record.ErrorMsg
function ErrorMsg() { if (!function_exists('adodb_throw')) { if ($this->_dbat < 0) { $db = false; } else { $db = $this->DB(); } // last error could be database error too if ($db && $db->ErrorMsg()) { return $db->ErrorMsg(); } } return $this->_lasterr; }
php
function ErrorMsg() { if (!function_exists('adodb_throw')) { if ($this->_dbat < 0) { $db = false; } else { $db = $this->DB(); } // last error could be database error too if ($db && $db->ErrorMsg()) { return $db->ErrorMsg(); } } return $this->_lasterr; }
[ "function", "ErrorMsg", "(", ")", "{", "if", "(", "!", "function_exists", "(", "'adodb_throw'", ")", ")", "{", "if", "(", "$", "this", "->", "_dbat", "<", "0", ")", "{", "$", "db", "=", "false", ";", "}", "else", "{", "$", "db", "=", "$", "this", "->", "DB", "(", ")", ";", "}", "// last error could be database error too", "if", "(", "$", "db", "&&", "$", "db", "->", "ErrorMsg", "(", ")", ")", "{", "return", "$", "db", "->", "ErrorMsg", "(", ")", ";", "}", "}", "return", "$", "this", "->", "_lasterr", ";", "}" ]
return last error message
[ "return", "last", "error", "message" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-active-recordx.inc.php#L606-L622
213,184
moodle/moodle
lib/adodb/adodb-active-recordx.inc.php
ADODB_Active_Record.DB
function DB() { global $_ADODB_ACTIVE_DBS; if ($this->_dbat < 0) { $false = false; $this->Error("No database connection set: use ADOdb_Active_Record::SetDatabaseAdaptor(\$db)", "DB"); return $false; } $activedb = $_ADODB_ACTIVE_DBS[$this->_dbat]; $db = $activedb->db; return $db; }
php
function DB() { global $_ADODB_ACTIVE_DBS; if ($this->_dbat < 0) { $false = false; $this->Error("No database connection set: use ADOdb_Active_Record::SetDatabaseAdaptor(\$db)", "DB"); return $false; } $activedb = $_ADODB_ACTIVE_DBS[$this->_dbat]; $db = $activedb->db; return $db; }
[ "function", "DB", "(", ")", "{", "global", "$", "_ADODB_ACTIVE_DBS", ";", "if", "(", "$", "this", "->", "_dbat", "<", "0", ")", "{", "$", "false", "=", "false", ";", "$", "this", "->", "Error", "(", "\"No database connection set: use ADOdb_Active_Record::SetDatabaseAdaptor(\\$db)\"", ",", "\"DB\"", ")", ";", "return", "$", "false", ";", "}", "$", "activedb", "=", "$", "_ADODB_ACTIVE_DBS", "[", "$", "this", "->", "_dbat", "]", ";", "$", "db", "=", "$", "activedb", "->", "db", ";", "return", "$", "db", ";", "}" ]
retrieve ADOConnection from _ADODB_Active_DBs
[ "retrieve", "ADOConnection", "from", "_ADODB_Active_DBs" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-active-recordx.inc.php#L636-L648
213,185
moodle/moodle
lib/adodb/adodb-active-recordx.inc.php
ADODB_Active_Record.LastInsertID
function LastInsertID(&$db,$fieldname) { if ($db->hasInsertID) { $val = $db->Insert_ID($this->_table,$fieldname); } else { $val = false; } if (is_null($val) || $val === false) { // this might not work reliably in multi-user environment return $db->GetOne("select max(".$fieldname.") from ".$this->_table); } return $val; }
php
function LastInsertID(&$db,$fieldname) { if ($db->hasInsertID) { $val = $db->Insert_ID($this->_table,$fieldname); } else { $val = false; } if (is_null($val) || $val === false) { // this might not work reliably in multi-user environment return $db->GetOne("select max(".$fieldname.") from ".$this->_table); } return $val; }
[ "function", "LastInsertID", "(", "&", "$", "db", ",", "$", "fieldname", ")", "{", "if", "(", "$", "db", "->", "hasInsertID", ")", "{", "$", "val", "=", "$", "db", "->", "Insert_ID", "(", "$", "this", "->", "_table", ",", "$", "fieldname", ")", ";", "}", "else", "{", "$", "val", "=", "false", ";", "}", "if", "(", "is_null", "(", "$", "val", ")", "||", "$", "val", "===", "false", ")", "{", "// this might not work reliably in multi-user environment", "return", "$", "db", "->", "GetOne", "(", "\"select max(\"", ".", "$", "fieldname", ".", "\") from \"", ".", "$", "this", "->", "_table", ")", ";", "}", "return", "$", "val", ";", "}" ]
get last inserted id for INSERT
[ "get", "last", "inserted", "id", "for", "INSERT" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/adodb-active-recordx.inc.php#L753-L767
213,186
moodle/moodle
analytics/classes/calculable.php
calculable.get_time_range_weeks_number
protected function get_time_range_weeks_number($starttime, $endtime) { if ($endtime <= $starttime) { throw new \coding_exception('End time timestamp should be greater than start time.'); } $starttimedt = new \DateTime(); $starttimedt->setTimestamp($starttime); $starttimedt->setTimezone(new \DateTimeZone('UTC')); $endtimedt = new \DateTime(); $endtimedt->setTimestamp($endtime); $endtimedt->setTimezone(new \DateTimeZone('UTC')); $diff = $endtimedt->getTimestamp() - $starttimedt->getTimestamp(); return $diff / WEEKSECS; }
php
protected function get_time_range_weeks_number($starttime, $endtime) { if ($endtime <= $starttime) { throw new \coding_exception('End time timestamp should be greater than start time.'); } $starttimedt = new \DateTime(); $starttimedt->setTimestamp($starttime); $starttimedt->setTimezone(new \DateTimeZone('UTC')); $endtimedt = new \DateTime(); $endtimedt->setTimestamp($endtime); $endtimedt->setTimezone(new \DateTimeZone('UTC')); $diff = $endtimedt->getTimestamp() - $starttimedt->getTimestamp(); return $diff / WEEKSECS; }
[ "protected", "function", "get_time_range_weeks_number", "(", "$", "starttime", ",", "$", "endtime", ")", "{", "if", "(", "$", "endtime", "<=", "$", "starttime", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'End time timestamp should be greater than start time.'", ")", ";", "}", "$", "starttimedt", "=", "new", "\\", "DateTime", "(", ")", ";", "$", "starttimedt", "->", "setTimestamp", "(", "$", "starttime", ")", ";", "$", "starttimedt", "->", "setTimezone", "(", "new", "\\", "DateTimeZone", "(", "'UTC'", ")", ")", ";", "$", "endtimedt", "=", "new", "\\", "DateTime", "(", ")", ";", "$", "endtimedt", "->", "setTimestamp", "(", "$", "endtime", ")", ";", "$", "endtimedt", "->", "setTimezone", "(", "new", "\\", "DateTimeZone", "(", "'UTC'", ")", ")", ";", "$", "diff", "=", "$", "endtimedt", "->", "getTimestamp", "(", ")", "-", "$", "starttimedt", "->", "getTimestamp", "(", ")", ";", "return", "$", "diff", "/", "WEEKSECS", ";", "}" ]
Returns the number of weeks a time range contains. Useful for calculations that depend on the time range duration. Note that it returns a float, rounding the float may lead to inaccurate results. @param int $starttime @param int $endtime @return float
[ "Returns", "the", "number", "of", "weeks", "a", "time", "range", "contains", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/calculable.php#L156-L170
213,187
moodle/moodle
analytics/classes/calculable.php
calculable.classify_value
protected function classify_value($value, $ranges) { // To automatically return calculated values from min to max values. $rangeweight = (static::get_max_value() - static::get_min_value()) / (count($ranges) - 1); foreach ($ranges as $key => $range) { $match = false; if (count($range) != 2) { throw new \coding_exception('classify_value() $ranges array param should contain 2 items, the predicate ' . 'e.g. greater (gt), lower or equal (le)... and the value.'); } list($predicate, $rangevalue) = $range; switch ($predicate) { case 'eq': if ($value == $rangevalue) { $match = true; } break; case 'ne': if ($value != $rangevalue) { $match = true; } break; case 'lt': if ($value < $rangevalue) { $match = true; } break; case 'le': if ($value <= $rangevalue) { $match = true; } break; case 'gt': if ($value > $rangevalue) { $match = true; } break; case 'ge': if ($value >= $rangevalue) { $match = true; } break; default: throw new \coding_exception('Unrecognised predicate ' . $predicate . '. Please use eq, ne, lt, le, ge or gt.'); } // Calculate and return a linear calculated value for the provided value. if ($match) { return round(static::get_min_value() + ($rangeweight * $key), 2); } } throw new \coding_exception('The provided value "' . $value . '" can not be fit into any of the provided ranges, you ' . 'should provide ranges for all possible values.'); }
php
protected function classify_value($value, $ranges) { // To automatically return calculated values from min to max values. $rangeweight = (static::get_max_value() - static::get_min_value()) / (count($ranges) - 1); foreach ($ranges as $key => $range) { $match = false; if (count($range) != 2) { throw new \coding_exception('classify_value() $ranges array param should contain 2 items, the predicate ' . 'e.g. greater (gt), lower or equal (le)... and the value.'); } list($predicate, $rangevalue) = $range; switch ($predicate) { case 'eq': if ($value == $rangevalue) { $match = true; } break; case 'ne': if ($value != $rangevalue) { $match = true; } break; case 'lt': if ($value < $rangevalue) { $match = true; } break; case 'le': if ($value <= $rangevalue) { $match = true; } break; case 'gt': if ($value > $rangevalue) { $match = true; } break; case 'ge': if ($value >= $rangevalue) { $match = true; } break; default: throw new \coding_exception('Unrecognised predicate ' . $predicate . '. Please use eq, ne, lt, le, ge or gt.'); } // Calculate and return a linear calculated value for the provided value. if ($match) { return round(static::get_min_value() + ($rangeweight * $key), 2); } } throw new \coding_exception('The provided value "' . $value . '" can not be fit into any of the provided ranges, you ' . 'should provide ranges for all possible values.'); }
[ "protected", "function", "classify_value", "(", "$", "value", ",", "$", "ranges", ")", "{", "// To automatically return calculated values from min to max values.", "$", "rangeweight", "=", "(", "static", "::", "get_max_value", "(", ")", "-", "static", "::", "get_min_value", "(", ")", ")", "/", "(", "count", "(", "$", "ranges", ")", "-", "1", ")", ";", "foreach", "(", "$", "ranges", "as", "$", "key", "=>", "$", "range", ")", "{", "$", "match", "=", "false", ";", "if", "(", "count", "(", "$", "range", ")", "!=", "2", ")", "{", "throw", "new", "\\", "coding_exception", "(", "'classify_value() $ranges array param should contain 2 items, the predicate '", ".", "'e.g. greater (gt), lower or equal (le)... and the value.'", ")", ";", "}", "list", "(", "$", "predicate", ",", "$", "rangevalue", ")", "=", "$", "range", ";", "switch", "(", "$", "predicate", ")", "{", "case", "'eq'", ":", "if", "(", "$", "value", "==", "$", "rangevalue", ")", "{", "$", "match", "=", "true", ";", "}", "break", ";", "case", "'ne'", ":", "if", "(", "$", "value", "!=", "$", "rangevalue", ")", "{", "$", "match", "=", "true", ";", "}", "break", ";", "case", "'lt'", ":", "if", "(", "$", "value", "<", "$", "rangevalue", ")", "{", "$", "match", "=", "true", ";", "}", "break", ";", "case", "'le'", ":", "if", "(", "$", "value", "<=", "$", "rangevalue", ")", "{", "$", "match", "=", "true", ";", "}", "break", ";", "case", "'gt'", ":", "if", "(", "$", "value", ">", "$", "rangevalue", ")", "{", "$", "match", "=", "true", ";", "}", "break", ";", "case", "'ge'", ":", "if", "(", "$", "value", ">=", "$", "rangevalue", ")", "{", "$", "match", "=", "true", ";", "}", "break", ";", "default", ":", "throw", "new", "\\", "coding_exception", "(", "'Unrecognised predicate '", ".", "$", "predicate", ".", "'. Please use eq, ne, lt, le, ge or gt.'", ")", ";", "}", "// Calculate and return a linear calculated value for the provided value.", "if", "(", "$", "match", ")", "{", "return", "round", "(", "static", "::", "get_min_value", "(", ")", "+", "(", "$", "rangeweight", "*", "$", "key", ")", ",", "2", ")", ";", "}", "}", "throw", "new", "\\", "coding_exception", "(", "'The provided value \"'", ".", "$", "value", ".", "'\" can not be fit into any of the provided ranges, you '", ".", "'should provide ranges for all possible values.'", ")", ";", "}" ]
Classifies the provided value into the provided range according to the ranges predicates. Use: - eq as 'equal' - ne as 'not equal' - lt as 'lower than' - le as 'lower or equal than' - gt as 'greater than' - ge as 'greater or equal than' @throws \coding_exception @param int|float $value @param array $ranges e.g. [ ['lt', 20], ['ge', 20] ] @return float
[ "Classifies", "the", "provided", "value", "into", "the", "provided", "range", "according", "to", "the", "ranges", "predicates", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/calculable.php#L198-L257
213,188
moodle/moodle
analytics/classes/calculable.php
calculable.array_merge_recursive_keep_keys
private function array_merge_recursive_keep_keys() { $arrays = func_get_args(); $base = array_shift($arrays); foreach ($arrays as $array) { reset($base); foreach ($array as $key => $value) { if (is_array($value) && !empty($base[$key]) && is_array($base[$key])) { $base[$key] = $this->array_merge_recursive_keep_keys($base[$key], $value); } else { if (isset($base[$key]) && is_int($key)) { $key++; } $base[$key] = $value; } } } return $base; }
php
private function array_merge_recursive_keep_keys() { $arrays = func_get_args(); $base = array_shift($arrays); foreach ($arrays as $array) { reset($base); foreach ($array as $key => $value) { if (is_array($value) && !empty($base[$key]) && is_array($base[$key])) { $base[$key] = $this->array_merge_recursive_keep_keys($base[$key], $value); } else { if (isset($base[$key]) && is_int($key)) { $key++; } $base[$key] = $value; } } } return $base; }
[ "private", "function", "array_merge_recursive_keep_keys", "(", ")", "{", "$", "arrays", "=", "func_get_args", "(", ")", ";", "$", "base", "=", "array_shift", "(", "$", "arrays", ")", ";", "foreach", "(", "$", "arrays", "as", "$", "array", ")", "{", "reset", "(", "$", "base", ")", ";", "foreach", "(", "$", "array", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", "&&", "!", "empty", "(", "$", "base", "[", "$", "key", "]", ")", "&&", "is_array", "(", "$", "base", "[", "$", "key", "]", ")", ")", "{", "$", "base", "[", "$", "key", "]", "=", "$", "this", "->", "array_merge_recursive_keep_keys", "(", "$", "base", "[", "$", "key", "]", ",", "$", "value", ")", ";", "}", "else", "{", "if", "(", "isset", "(", "$", "base", "[", "$", "key", "]", ")", "&&", "is_int", "(", "$", "key", ")", ")", "{", "$", "key", "++", ";", "}", "$", "base", "[", "$", "key", "]", "=", "$", "value", ";", "}", "}", "}", "return", "$", "base", ";", "}" ]
Merges arrays recursively keeping the same keys the original arrays have. @link http://php.net/manual/es/function.array-merge-recursive.php#114818 @return array
[ "Merges", "arrays", "recursively", "keeping", "the", "same", "keys", "the", "original", "arrays", "have", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/analytics/classes/calculable.php#L265-L284
213,189
moodle/moodle
mod/data/field/file/field.class.php
data_field_file.notemptyfield
function notemptyfield($value, $name) { global $USER; $names = explode('_', $name); if ($names[2] == 'file') { $usercontext = context_user::instance($USER->id); $fs = get_file_storage(); $files = $fs->get_area_files($usercontext->id, 'user', 'draft', $value); return count($files) >= 2; } return false; }
php
function notemptyfield($value, $name) { global $USER; $names = explode('_', $name); if ($names[2] == 'file') { $usercontext = context_user::instance($USER->id); $fs = get_file_storage(); $files = $fs->get_area_files($usercontext->id, 'user', 'draft', $value); return count($files) >= 2; } return false; }
[ "function", "notemptyfield", "(", "$", "value", ",", "$", "name", ")", "{", "global", "$", "USER", ";", "$", "names", "=", "explode", "(", "'_'", ",", "$", "name", ")", ";", "if", "(", "$", "names", "[", "2", "]", "==", "'file'", ")", "{", "$", "usercontext", "=", "context_user", "::", "instance", "(", "$", "USER", "->", "id", ")", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "files", "=", "$", "fs", "->", "get_area_files", "(", "$", "usercontext", "->", "id", ",", "'user'", ",", "'draft'", ",", "$", "value", ")", ";", "return", "count", "(", "$", "files", ")", ">=", "2", ";", "}", "return", "false", ";", "}" ]
Custom notempty function @param string $value @param string $name @return bool
[ "Custom", "notempty", "function" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/field/file/field.class.php#L197-L208
213,190
moodle/moodle
admin/tool/log/store/legacy/classes/privacy/provider.php
provider.delete_data_for_userlist
public static function delete_data_for_userlist(\core_privacy\local\request\approved_userlist $userlist) { global $DB; list($sql, $params) = static::get_sql_where_from_contexts([$userlist->get_context()]); if (empty($sql)) { return; } list($usersql, $userparams) = $DB->get_in_or_equal($userlist->get_userids(), SQL_PARAMS_NAMED); $params = array_merge($params, $userparams); $DB->delete_records_select('log', "$sql AND userid $usersql", $params); }
php
public static function delete_data_for_userlist(\core_privacy\local\request\approved_userlist $userlist) { global $DB; list($sql, $params) = static::get_sql_where_from_contexts([$userlist->get_context()]); if (empty($sql)) { return; } list($usersql, $userparams) = $DB->get_in_or_equal($userlist->get_userids(), SQL_PARAMS_NAMED); $params = array_merge($params, $userparams); $DB->delete_records_select('log', "$sql AND userid $usersql", $params); }
[ "public", "static", "function", "delete_data_for_userlist", "(", "\\", "core_privacy", "\\", "local", "\\", "request", "\\", "approved_userlist", "$", "userlist", ")", "{", "global", "$", "DB", ";", "list", "(", "$", "sql", ",", "$", "params", ")", "=", "static", "::", "get_sql_where_from_contexts", "(", "[", "$", "userlist", "->", "get_context", "(", ")", "]", ")", ";", "if", "(", "empty", "(", "$", "sql", ")", ")", "{", "return", ";", "}", "list", "(", "$", "usersql", ",", "$", "userparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "userlist", "->", "get_userids", "(", ")", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "params", "=", "array_merge", "(", "$", "params", ",", "$", "userparams", ")", ";", "$", "DB", "->", "delete_records_select", "(", "'log'", ",", "\"$sql AND userid $usersql\"", ",", "$", "params", ")", ";", "}" ]
Delete all data for a list of users in the specified context. @param \core_privacy\local\request\approved_userlist $userlist The specific context and users to delete data for. @return void
[ "Delete", "all", "data", "for", "a", "list", "of", "users", "in", "the", "specified", "context", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/log/store/legacy/classes/privacy/provider.php#L195-L204
213,191
moodle/moodle
admin/tool/log/store/legacy/classes/privacy/provider.php
provider.get_sql_where_from_contexts
protected static function get_sql_where_from_contexts(array $contexts) { global $DB; $sorted = array_reduce($contexts, function ($carry, $context) { $level = $context->contextlevel; if ($level == CONTEXT_MODULE || $level == CONTEXT_COURSE) { $carry[$level][] = $context->instanceid; } else if ($level == CONTEXT_SYSTEM) { $carry[$level] = $context->id; } return $carry; }, [ CONTEXT_COURSE => [], CONTEXT_MODULE => [], CONTEXT_SYSTEM => null, ]); $sqls = []; $params = []; if (!empty($sorted[CONTEXT_MODULE])) { list($insql, $inparams) = $DB->get_in_or_equal($sorted[CONTEXT_MODULE], SQL_PARAMS_NAMED); $sqls[] = "cmid $insql"; $params = array_merge($params, $inparams); } if (!empty($sorted[CONTEXT_COURSE])) { list($insql, $inparams) = $DB->get_in_or_equal($sorted[CONTEXT_COURSE], SQL_PARAMS_NAMED); $sqls[] = "cmid = 0 AND course $insql"; $params = array_merge($params, $inparams); } if (!empty($sorted[CONTEXT_SYSTEM])) { $sqls[] = "course <= 0"; } if (empty($sqls)) { return [null, null]; } return ['((' . implode(') OR (', $sqls) . '))', $params]; }
php
protected static function get_sql_where_from_contexts(array $contexts) { global $DB; $sorted = array_reduce($contexts, function ($carry, $context) { $level = $context->contextlevel; if ($level == CONTEXT_MODULE || $level == CONTEXT_COURSE) { $carry[$level][] = $context->instanceid; } else if ($level == CONTEXT_SYSTEM) { $carry[$level] = $context->id; } return $carry; }, [ CONTEXT_COURSE => [], CONTEXT_MODULE => [], CONTEXT_SYSTEM => null, ]); $sqls = []; $params = []; if (!empty($sorted[CONTEXT_MODULE])) { list($insql, $inparams) = $DB->get_in_or_equal($sorted[CONTEXT_MODULE], SQL_PARAMS_NAMED); $sqls[] = "cmid $insql"; $params = array_merge($params, $inparams); } if (!empty($sorted[CONTEXT_COURSE])) { list($insql, $inparams) = $DB->get_in_or_equal($sorted[CONTEXT_COURSE], SQL_PARAMS_NAMED); $sqls[] = "cmid = 0 AND course $insql"; $params = array_merge($params, $inparams); } if (!empty($sorted[CONTEXT_SYSTEM])) { $sqls[] = "course <= 0"; } if (empty($sqls)) { return [null, null]; } return ['((' . implode(') OR (', $sqls) . '))', $params]; }
[ "protected", "static", "function", "get_sql_where_from_contexts", "(", "array", "$", "contexts", ")", "{", "global", "$", "DB", ";", "$", "sorted", "=", "array_reduce", "(", "$", "contexts", ",", "function", "(", "$", "carry", ",", "$", "context", ")", "{", "$", "level", "=", "$", "context", "->", "contextlevel", ";", "if", "(", "$", "level", "==", "CONTEXT_MODULE", "||", "$", "level", "==", "CONTEXT_COURSE", ")", "{", "$", "carry", "[", "$", "level", "]", "[", "]", "=", "$", "context", "->", "instanceid", ";", "}", "else", "if", "(", "$", "level", "==", "CONTEXT_SYSTEM", ")", "{", "$", "carry", "[", "$", "level", "]", "=", "$", "context", "->", "id", ";", "}", "return", "$", "carry", ";", "}", ",", "[", "CONTEXT_COURSE", "=>", "[", "]", ",", "CONTEXT_MODULE", "=>", "[", "]", ",", "CONTEXT_SYSTEM", "=>", "null", ",", "]", ")", ";", "$", "sqls", "=", "[", "]", ";", "$", "params", "=", "[", "]", ";", "if", "(", "!", "empty", "(", "$", "sorted", "[", "CONTEXT_MODULE", "]", ")", ")", "{", "list", "(", "$", "insql", ",", "$", "inparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "sorted", "[", "CONTEXT_MODULE", "]", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "sqls", "[", "]", "=", "\"cmid $insql\"", ";", "$", "params", "=", "array_merge", "(", "$", "params", ",", "$", "inparams", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "sorted", "[", "CONTEXT_COURSE", "]", ")", ")", "{", "list", "(", "$", "insql", ",", "$", "inparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "sorted", "[", "CONTEXT_COURSE", "]", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "sqls", "[", "]", "=", "\"cmid = 0 AND course $insql\"", ";", "$", "params", "=", "array_merge", "(", "$", "params", ",", "$", "inparams", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "sorted", "[", "CONTEXT_SYSTEM", "]", ")", ")", "{", "$", "sqls", "[", "]", "=", "\"course <= 0\"", ";", "}", "if", "(", "empty", "(", "$", "sqls", ")", ")", "{", "return", "[", "null", ",", "null", "]", ";", "}", "return", "[", "'(('", ".", "implode", "(", "') OR ('", ",", "$", "sqls", ")", ".", "'))'", ",", "$", "params", "]", ";", "}" ]
Get an SQL where statement from a list of contexts. @param array $contexts The contexts. @return array [$sql, $params]
[ "Get", "an", "SQL", "where", "statement", "from", "a", "list", "of", "contexts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/log/store/legacy/classes/privacy/provider.php#L212-L254
213,192
moodle/moodle
admin/tool/xmldb/actions/view_xml/view_xml.class.php
view_xml.init
function init() { parent::init(); // Set own core attributes $this->can_subaction = ACTION_NONE; //$this->can_subaction = ACTION_HAVE_SUBACTIONS; // Set own custom attributes $this->sesskey_protected = false; // This action doesn't need sesskey protection // Get needed strings $this->loadStrings(array( // 'key' => 'module', )); }
php
function init() { parent::init(); // Set own core attributes $this->can_subaction = ACTION_NONE; //$this->can_subaction = ACTION_HAVE_SUBACTIONS; // Set own custom attributes $this->sesskey_protected = false; // This action doesn't need sesskey protection // Get needed strings $this->loadStrings(array( // 'key' => 'module', )); }
[ "function", "init", "(", ")", "{", "parent", "::", "init", "(", ")", ";", "// Set own core attributes", "$", "this", "->", "can_subaction", "=", "ACTION_NONE", ";", "//$this->can_subaction = ACTION_HAVE_SUBACTIONS;", "// Set own custom attributes", "$", "this", "->", "sesskey_protected", "=", "false", ";", "// This action doesn't need sesskey protection", "// Get needed strings", "$", "this", "->", "loadStrings", "(", "array", "(", "// 'key' => 'module',", ")", ")", ";", "}" ]
Init method, every subclass will have its own
[ "Init", "method", "every", "subclass", "will", "have", "its", "own" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/xmldb/actions/view_xml/view_xml.class.php#L35-L48
213,193
moodle/moodle
report/loglive/classes/renderer.php
report_loglive_renderer.render_report_loglive
protected function render_report_loglive(report_loglive_renderable $reportloglive) { if (empty($reportloglive->selectedlogreader)) { return $this->output->notification(get_string('nologreaderenabled', 'report_loglive'), 'notifyproblem'); } $table = $reportloglive->get_table(); return $this->render_table($table, $reportloglive->perpage); }
php
protected function render_report_loglive(report_loglive_renderable $reportloglive) { if (empty($reportloglive->selectedlogreader)) { return $this->output->notification(get_string('nologreaderenabled', 'report_loglive'), 'notifyproblem'); } $table = $reportloglive->get_table(); return $this->render_table($table, $reportloglive->perpage); }
[ "protected", "function", "render_report_loglive", "(", "report_loglive_renderable", "$", "reportloglive", ")", "{", "if", "(", "empty", "(", "$", "reportloglive", "->", "selectedlogreader", ")", ")", "{", "return", "$", "this", "->", "output", "->", "notification", "(", "get_string", "(", "'nologreaderenabled'", ",", "'report_loglive'", ")", ",", "'notifyproblem'", ")", ";", "}", "$", "table", "=", "$", "reportloglive", "->", "get_table", "(", ")", ";", "return", "$", "this", "->", "render_table", "(", "$", "table", ",", "$", "reportloglive", "->", "perpage", ")", ";", "}" ]
Return html to render the loglive page.. @param report_loglive_renderable $reportloglive object of report_log. @return string html used to render the page;
[ "Return", "html", "to", "render", "the", "loglive", "page", ".." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/report/loglive/classes/renderer.php#L56-L63
213,194
moodle/moodle
lib/minify/matthiasmullie-minify/src/CSS.php
CSS.moveImportsToTop
protected function moveImportsToTop($content) { if (preg_match_all('/@import[^;]+;/', $content, $matches)) { // remove from content foreach ($matches[0] as $import) { $content = str_replace($import, '', $content); } // add to top $content = implode('', $matches[0]).$content; } return $content; }
php
protected function moveImportsToTop($content) { if (preg_match_all('/@import[^;]+;/', $content, $matches)) { // remove from content foreach ($matches[0] as $import) { $content = str_replace($import, '', $content); } // add to top $content = implode('', $matches[0]).$content; } return $content; }
[ "protected", "function", "moveImportsToTop", "(", "$", "content", ")", "{", "if", "(", "preg_match_all", "(", "'/@import[^;]+;/'", ",", "$", "content", ",", "$", "matches", ")", ")", "{", "// remove from content", "foreach", "(", "$", "matches", "[", "0", "]", "as", "$", "import", ")", "{", "$", "content", "=", "str_replace", "(", "$", "import", ",", "''", ",", "$", "content", ")", ";", "}", "// add to top", "$", "content", "=", "implode", "(", "''", ",", "$", "matches", "[", "0", "]", ")", ".", "$", "content", ";", "}", "return", "$", "content", ";", "}" ]
Move any import statements to the top. @param string $content Nearly finished CSS content @return string
[ "Move", "any", "import", "statements", "to", "the", "top", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/minify/matthiasmullie-minify/src/CSS.php#L77-L90
213,195
moodle/moodle
lib/minify/matthiasmullie-minify/src/CSS.php
CSS.combineImports
protected function combineImports($source, $content, $parents) { $importRegexes = array( // @import url(xxx) '/ # import statement @import # whitespace \s+ # open url() url\( # (optional) open path enclosure (?P<quotes>["\']?) # fetch path (?P<path>.+?) # (optional) close path enclosure (?P=quotes) # close url() \) # (optional) trailing whitespace \s* # (optional) media statement(s) (?P<media>[^;]*) # (optional) trailing whitespace \s* # (optional) closing semi-colon ;? /ix', // @import 'xxx' '/ # import statement @import # whitespace \s+ # open path enclosure (?P<quotes>["\']) # fetch path (?P<path>.+?) # close path enclosure (?P=quotes) # (optional) trailing whitespace \s* # (optional) media statement(s) (?P<media>[^;]*) # (optional) trailing whitespace \s* # (optional) closing semi-colon ;? /ix', ); // find all relative imports in css $matches = array(); foreach ($importRegexes as $importRegex) { if (preg_match_all($importRegex, $content, $regexMatches, PREG_SET_ORDER)) { $matches = array_merge($matches, $regexMatches); } } $search = array(); $replace = array(); // loop the matches foreach ($matches as $match) { // get the path for the file that will be imported $importPath = dirname($source).'/'.$match['path']; // only replace the import with the content if we can grab the // content of the file if (!$this->canImportByPath($match['path']) || !$this->canImportFile($importPath)) { continue; } // check if current file was not imported previously in the same // import chain. if (in_array($importPath, $parents)) { throw new FileImportException('Failed to import file "'.$importPath.'": circular reference detected.'); } // grab referenced file & minify it (which may include importing // yet other @import statements recursively) $minifier = new static($importPath); $importContent = $minifier->execute($source, $parents); // check if this is only valid for certain media if (!empty($match['media'])) { $importContent = '@media '.$match['media'].'{'.$importContent.'}'; } // add to replacement array $search[] = $match[0]; $replace[] = $importContent; } // replace the import statements return str_replace($search, $replace, $content); }
php
protected function combineImports($source, $content, $parents) { $importRegexes = array( // @import url(xxx) '/ # import statement @import # whitespace \s+ # open url() url\( # (optional) open path enclosure (?P<quotes>["\']?) # fetch path (?P<path>.+?) # (optional) close path enclosure (?P=quotes) # close url() \) # (optional) trailing whitespace \s* # (optional) media statement(s) (?P<media>[^;]*) # (optional) trailing whitespace \s* # (optional) closing semi-colon ;? /ix', // @import 'xxx' '/ # import statement @import # whitespace \s+ # open path enclosure (?P<quotes>["\']) # fetch path (?P<path>.+?) # close path enclosure (?P=quotes) # (optional) trailing whitespace \s* # (optional) media statement(s) (?P<media>[^;]*) # (optional) trailing whitespace \s* # (optional) closing semi-colon ;? /ix', ); // find all relative imports in css $matches = array(); foreach ($importRegexes as $importRegex) { if (preg_match_all($importRegex, $content, $regexMatches, PREG_SET_ORDER)) { $matches = array_merge($matches, $regexMatches); } } $search = array(); $replace = array(); // loop the matches foreach ($matches as $match) { // get the path for the file that will be imported $importPath = dirname($source).'/'.$match['path']; // only replace the import with the content if we can grab the // content of the file if (!$this->canImportByPath($match['path']) || !$this->canImportFile($importPath)) { continue; } // check if current file was not imported previously in the same // import chain. if (in_array($importPath, $parents)) { throw new FileImportException('Failed to import file "'.$importPath.'": circular reference detected.'); } // grab referenced file & minify it (which may include importing // yet other @import statements recursively) $minifier = new static($importPath); $importContent = $minifier->execute($source, $parents); // check if this is only valid for certain media if (!empty($match['media'])) { $importContent = '@media '.$match['media'].'{'.$importContent.'}'; } // add to replacement array $search[] = $match[0]; $replace[] = $importContent; } // replace the import statements return str_replace($search, $replace, $content); }
[ "protected", "function", "combineImports", "(", "$", "source", ",", "$", "content", ",", "$", "parents", ")", "{", "$", "importRegexes", "=", "array", "(", "// @import url(xxx)", "'/\n # import statement\n @import\n\n # whitespace\n \\s+\n\n # open url()\n url\\(\n\n # (optional) open path enclosure\n (?P<quotes>[\"\\']?)\n\n # fetch path\n (?P<path>.+?)\n\n # (optional) close path enclosure\n (?P=quotes)\n\n # close url()\n \\)\n\n # (optional) trailing whitespace\n \\s*\n\n # (optional) media statement(s)\n (?P<media>[^;]*)\n\n # (optional) trailing whitespace\n \\s*\n\n # (optional) closing semi-colon\n ;?\n\n /ix'", ",", "// @import 'xxx'", "'/\n\n # import statement\n @import\n\n # whitespace\n \\s+\n\n # open path enclosure\n (?P<quotes>[\"\\'])\n\n # fetch path\n (?P<path>.+?)\n\n # close path enclosure\n (?P=quotes)\n\n # (optional) trailing whitespace\n \\s*\n\n # (optional) media statement(s)\n (?P<media>[^;]*)\n\n # (optional) trailing whitespace\n \\s*\n\n # (optional) closing semi-colon\n ;?\n\n /ix'", ",", ")", ";", "// find all relative imports in css", "$", "matches", "=", "array", "(", ")", ";", "foreach", "(", "$", "importRegexes", "as", "$", "importRegex", ")", "{", "if", "(", "preg_match_all", "(", "$", "importRegex", ",", "$", "content", ",", "$", "regexMatches", ",", "PREG_SET_ORDER", ")", ")", "{", "$", "matches", "=", "array_merge", "(", "$", "matches", ",", "$", "regexMatches", ")", ";", "}", "}", "$", "search", "=", "array", "(", ")", ";", "$", "replace", "=", "array", "(", ")", ";", "// loop the matches", "foreach", "(", "$", "matches", "as", "$", "match", ")", "{", "// get the path for the file that will be imported", "$", "importPath", "=", "dirname", "(", "$", "source", ")", ".", "'/'", ".", "$", "match", "[", "'path'", "]", ";", "// only replace the import with the content if we can grab the", "// content of the file", "if", "(", "!", "$", "this", "->", "canImportByPath", "(", "$", "match", "[", "'path'", "]", ")", "||", "!", "$", "this", "->", "canImportFile", "(", "$", "importPath", ")", ")", "{", "continue", ";", "}", "// check if current file was not imported previously in the same", "// import chain.", "if", "(", "in_array", "(", "$", "importPath", ",", "$", "parents", ")", ")", "{", "throw", "new", "FileImportException", "(", "'Failed to import file \"'", ".", "$", "importPath", ".", "'\": circular reference detected.'", ")", ";", "}", "// grab referenced file & minify it (which may include importing", "// yet other @import statements recursively)", "$", "minifier", "=", "new", "static", "(", "$", "importPath", ")", ";", "$", "importContent", "=", "$", "minifier", "->", "execute", "(", "$", "source", ",", "$", "parents", ")", ";", "// check if this is only valid for certain media", "if", "(", "!", "empty", "(", "$", "match", "[", "'media'", "]", ")", ")", "{", "$", "importContent", "=", "'@media '", ".", "$", "match", "[", "'media'", "]", ".", "'{'", ".", "$", "importContent", ".", "'}'", ";", "}", "// add to replacement array", "$", "search", "[", "]", "=", "$", "match", "[", "0", "]", ";", "$", "replace", "[", "]", "=", "$", "importContent", ";", "}", "// replace the import statements", "return", "str_replace", "(", "$", "search", ",", "$", "replace", ",", "$", "content", ")", ";", "}" ]
Combine CSS from import statements. @import's will be loaded and their content merged into the original file, to save HTTP requests. @param string $source The file to combine imports for @param string $content The CSS content to combine imports for @param string[] $parents Parent paths, for circular reference checks @return string @throws FileImportException
[ "Combine", "CSS", "from", "import", "statements", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/minify/matthiasmullie-minify/src/CSS.php#L106-L224
213,196
moodle/moodle
lib/minify/matthiasmullie-minify/src/CSS.php
CSS.importFiles
protected function importFiles($source, $content) { $regex = '/url\((["\']?)(.+?)\\1\)/i'; if ($this->importExtensions && preg_match_all($regex, $content, $matches, PREG_SET_ORDER)) { $search = array(); $replace = array(); // loop the matches foreach ($matches as $match) { $extension = substr(strrchr($match[2], '.'), 1); if ($extension && !array_key_exists($extension, $this->importExtensions)) { continue; } // get the path for the file that will be imported $path = $match[2]; $path = dirname($source).'/'.$path; // only replace the import with the content if we're able to get // the content of the file, and it's relatively small if ($this->canImportFile($path) && $this->canImportBySize($path)) { // grab content && base64-ize $importContent = $this->load($path); $importContent = base64_encode($importContent); // build replacement $search[] = $match[0]; $replace[] = 'url('.$this->importExtensions[$extension].';base64,'.$importContent.')'; } } // replace the import statements $content = str_replace($search, $replace, $content); } return $content; }
php
protected function importFiles($source, $content) { $regex = '/url\((["\']?)(.+?)\\1\)/i'; if ($this->importExtensions && preg_match_all($regex, $content, $matches, PREG_SET_ORDER)) { $search = array(); $replace = array(); // loop the matches foreach ($matches as $match) { $extension = substr(strrchr($match[2], '.'), 1); if ($extension && !array_key_exists($extension, $this->importExtensions)) { continue; } // get the path for the file that will be imported $path = $match[2]; $path = dirname($source).'/'.$path; // only replace the import with the content if we're able to get // the content of the file, and it's relatively small if ($this->canImportFile($path) && $this->canImportBySize($path)) { // grab content && base64-ize $importContent = $this->load($path); $importContent = base64_encode($importContent); // build replacement $search[] = $match[0]; $replace[] = 'url('.$this->importExtensions[$extension].';base64,'.$importContent.')'; } } // replace the import statements $content = str_replace($search, $replace, $content); } return $content; }
[ "protected", "function", "importFiles", "(", "$", "source", ",", "$", "content", ")", "{", "$", "regex", "=", "'/url\\(([\"\\']?)(.+?)\\\\1\\)/i'", ";", "if", "(", "$", "this", "->", "importExtensions", "&&", "preg_match_all", "(", "$", "regex", ",", "$", "content", ",", "$", "matches", ",", "PREG_SET_ORDER", ")", ")", "{", "$", "search", "=", "array", "(", ")", ";", "$", "replace", "=", "array", "(", ")", ";", "// loop the matches", "foreach", "(", "$", "matches", "as", "$", "match", ")", "{", "$", "extension", "=", "substr", "(", "strrchr", "(", "$", "match", "[", "2", "]", ",", "'.'", ")", ",", "1", ")", ";", "if", "(", "$", "extension", "&&", "!", "array_key_exists", "(", "$", "extension", ",", "$", "this", "->", "importExtensions", ")", ")", "{", "continue", ";", "}", "// get the path for the file that will be imported", "$", "path", "=", "$", "match", "[", "2", "]", ";", "$", "path", "=", "dirname", "(", "$", "source", ")", ".", "'/'", ".", "$", "path", ";", "// only replace the import with the content if we're able to get", "// the content of the file, and it's relatively small", "if", "(", "$", "this", "->", "canImportFile", "(", "$", "path", ")", "&&", "$", "this", "->", "canImportBySize", "(", "$", "path", ")", ")", "{", "// grab content && base64-ize", "$", "importContent", "=", "$", "this", "->", "load", "(", "$", "path", ")", ";", "$", "importContent", "=", "base64_encode", "(", "$", "importContent", ")", ";", "// build replacement", "$", "search", "[", "]", "=", "$", "match", "[", "0", "]", ";", "$", "replace", "[", "]", "=", "'url('", ".", "$", "this", "->", "importExtensions", "[", "$", "extension", "]", ".", "';base64,'", ".", "$", "importContent", ".", "')'", ";", "}", "}", "// replace the import statements", "$", "content", "=", "str_replace", "(", "$", "search", ",", "$", "replace", ",", "$", "content", ")", ";", "}", "return", "$", "content", ";", "}" ]
Import files into the CSS, base64-ized. @url(image.jpg) images will be loaded and their content merged into the original file, to save HTTP requests. @param string $source The file to import files for @param string $content The CSS content to import files for @return string
[ "Import", "files", "into", "the", "CSS", "base64", "-", "ized", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/minify/matthiasmullie-minify/src/CSS.php#L237-L273
213,197
moodle/moodle
lib/minify/matthiasmullie-minify/src/CSS.php
CSS.execute
public function execute($path = null, $parents = array()) { $content = ''; // loop CSS data (raw data and files) foreach ($this->data as $source => $css) { /* * Let's first take out strings & comments, since we can't just * remove whitespace anywhere. If whitespace occurs inside a string, * we should leave it alone. E.g.: * p { content: "a test" } */ $this->extractStrings(); $this->stripComments(); $css = $this->replace($css); $css = $this->stripWhitespace($css); $css = $this->shortenHex($css); $css = $this->shortenZeroes($css); $css = $this->shortenFontWeights($css); $css = $this->stripEmptyTags($css); // restore the string we've extracted earlier $css = $this->restoreExtractedData($css); $source = is_int($source) ? '' : $source; $parents = $source ? array_merge($parents, array($source)) : $parents; $css = $this->combineImports($source, $css, $parents); $css = $this->importFiles($source, $css); /* * If we'll save to a new path, we'll have to fix the relative paths * to be relative no longer to the source file, but to the new path. * If we don't write to a file, fall back to same path so no * conversion happens (because we still want it to go through most * of the move code, which also addresses url() & @import syntax...) */ $converter = $this->getPathConverter($source, $path ?: $source); $css = $this->move($converter, $css); // combine css $content .= $css; } $content = $this->moveImportsToTop($content); return $content; }
php
public function execute($path = null, $parents = array()) { $content = ''; // loop CSS data (raw data and files) foreach ($this->data as $source => $css) { /* * Let's first take out strings & comments, since we can't just * remove whitespace anywhere. If whitespace occurs inside a string, * we should leave it alone. E.g.: * p { content: "a test" } */ $this->extractStrings(); $this->stripComments(); $css = $this->replace($css); $css = $this->stripWhitespace($css); $css = $this->shortenHex($css); $css = $this->shortenZeroes($css); $css = $this->shortenFontWeights($css); $css = $this->stripEmptyTags($css); // restore the string we've extracted earlier $css = $this->restoreExtractedData($css); $source = is_int($source) ? '' : $source; $parents = $source ? array_merge($parents, array($source)) : $parents; $css = $this->combineImports($source, $css, $parents); $css = $this->importFiles($source, $css); /* * If we'll save to a new path, we'll have to fix the relative paths * to be relative no longer to the source file, but to the new path. * If we don't write to a file, fall back to same path so no * conversion happens (because we still want it to go through most * of the move code, which also addresses url() & @import syntax...) */ $converter = $this->getPathConverter($source, $path ?: $source); $css = $this->move($converter, $css); // combine css $content .= $css; } $content = $this->moveImportsToTop($content); return $content; }
[ "public", "function", "execute", "(", "$", "path", "=", "null", ",", "$", "parents", "=", "array", "(", ")", ")", "{", "$", "content", "=", "''", ";", "// loop CSS data (raw data and files)", "foreach", "(", "$", "this", "->", "data", "as", "$", "source", "=>", "$", "css", ")", "{", "/*\n * Let's first take out strings & comments, since we can't just\n * remove whitespace anywhere. If whitespace occurs inside a string,\n * we should leave it alone. E.g.:\n * p { content: \"a test\" }\n */", "$", "this", "->", "extractStrings", "(", ")", ";", "$", "this", "->", "stripComments", "(", ")", ";", "$", "css", "=", "$", "this", "->", "replace", "(", "$", "css", ")", ";", "$", "css", "=", "$", "this", "->", "stripWhitespace", "(", "$", "css", ")", ";", "$", "css", "=", "$", "this", "->", "shortenHex", "(", "$", "css", ")", ";", "$", "css", "=", "$", "this", "->", "shortenZeroes", "(", "$", "css", ")", ";", "$", "css", "=", "$", "this", "->", "shortenFontWeights", "(", "$", "css", ")", ";", "$", "css", "=", "$", "this", "->", "stripEmptyTags", "(", "$", "css", ")", ";", "// restore the string we've extracted earlier", "$", "css", "=", "$", "this", "->", "restoreExtractedData", "(", "$", "css", ")", ";", "$", "source", "=", "is_int", "(", "$", "source", ")", "?", "''", ":", "$", "source", ";", "$", "parents", "=", "$", "source", "?", "array_merge", "(", "$", "parents", ",", "array", "(", "$", "source", ")", ")", ":", "$", "parents", ";", "$", "css", "=", "$", "this", "->", "combineImports", "(", "$", "source", ",", "$", "css", ",", "$", "parents", ")", ";", "$", "css", "=", "$", "this", "->", "importFiles", "(", "$", "source", ",", "$", "css", ")", ";", "/*\n * If we'll save to a new path, we'll have to fix the relative paths\n * to be relative no longer to the source file, but to the new path.\n * If we don't write to a file, fall back to same path so no\n * conversion happens (because we still want it to go through most\n * of the move code, which also addresses url() & @import syntax...)\n */", "$", "converter", "=", "$", "this", "->", "getPathConverter", "(", "$", "source", ",", "$", "path", "?", ":", "$", "source", ")", ";", "$", "css", "=", "$", "this", "->", "move", "(", "$", "converter", ",", "$", "css", ")", ";", "// combine css", "$", "content", ".=", "$", "css", ";", "}", "$", "content", "=", "$", "this", "->", "moveImportsToTop", "(", "$", "content", ")", ";", "return", "$", "content", ";", "}" ]
Minify the data. Perform CSS optimizations. @param string[optional] $path Path to write the data to @param string[] $parents Parent paths, for circular reference checks @return string The minified data
[ "Minify", "the", "data", ".", "Perform", "CSS", "optimizations", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/minify/matthiasmullie-minify/src/CSS.php#L284-L331
213,198
moodle/moodle
lib/minify/matthiasmullie-minify/src/CSS.php
CSS.shortenFontWeights
protected function shortenFontWeights($content) { $weights = array( 'normal' => 400, 'bold' => 700, ); $callback = function ($match) use ($weights) { return $match[1].$weights[$match[2]]; }; return preg_replace_callback('/(font-weight\s*:\s*)('.implode('|', array_keys($weights)).')(?=[;}])/', $callback, $content); }
php
protected function shortenFontWeights($content) { $weights = array( 'normal' => 400, 'bold' => 700, ); $callback = function ($match) use ($weights) { return $match[1].$weights[$match[2]]; }; return preg_replace_callback('/(font-weight\s*:\s*)('.implode('|', array_keys($weights)).')(?=[;}])/', $callback, $content); }
[ "protected", "function", "shortenFontWeights", "(", "$", "content", ")", "{", "$", "weights", "=", "array", "(", "'normal'", "=>", "400", ",", "'bold'", "=>", "700", ",", ")", ";", "$", "callback", "=", "function", "(", "$", "match", ")", "use", "(", "$", "weights", ")", "{", "return", "$", "match", "[", "1", "]", ".", "$", "weights", "[", "$", "match", "[", "2", "]", "]", ";", "}", ";", "return", "preg_replace_callback", "(", "'/(font-weight\\s*:\\s*)('", ".", "implode", "(", "'|'", ",", "array_keys", "(", "$", "weights", ")", ")", ".", "')(?=[;}])/'", ",", "$", "callback", ",", "$", "content", ")", ";", "}" ]
Shorten CSS font weights. @param string $content The CSS content to shorten the font weights for @return string
[ "Shorten", "CSS", "font", "weights", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/minify/matthiasmullie-minify/src/CSS.php#L523-L535
213,199
moodle/moodle
mod/wiki/parser/markups/creole.php
creole_parser.escape_token_string
private function escape_token_string(&$text, $token) { $text = str_replace("~".$token, $this->protect($token), $text); }
php
private function escape_token_string(&$text, $token) { $text = str_replace("~".$token, $this->protect($token), $text); }
[ "private", "function", "escape_token_string", "(", "&", "$", "text", ",", "$", "token", ")", "{", "$", "text", "=", "str_replace", "(", "\"~\"", ".", "$", "token", ",", "$", "this", "->", "protect", "(", "$", "token", ")", ",", "$", "text", ")", ";", "}" ]
Escape token when it is "negated"
[ "Escape", "token", "when", "it", "is", "negated" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/wiki/parser/markups/creole.php#L168-L170