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
219,900
moodle/moodle
question/engine/datalib.php
question_engine_unit_of_work.save
public function save(question_engine_data_mapper $dm) { $dm->delete_steps(array_keys($this->stepsdeleted), $this->quba->get_owning_context()); // Initially an array of array of question_attempt_step_objects. // Built as a nested array for efficiency, then flattened. $stepdata = array(); foreach ($this->stepsmodified as $stepinfo) { list($step, $questionattemptid, $seq) = $stepinfo; $stepdata[] = $dm->update_question_attempt_step( $step, $questionattemptid, $seq, $this->quba->get_owning_context()); } foreach ($this->stepsadded as $stepinfo) { list($step, $questionattemptid, $seq) = $stepinfo; $stepdata[] = $dm->insert_question_attempt_step( $step, $questionattemptid, $seq, $this->quba->get_owning_context()); } foreach ($this->attemptsmodified as $qa) { $dm->update_question_attempt($qa); } foreach ($this->attemptsadded as $qa) { $stepdata[] = $dm->insert_question_attempt( $qa, $this->quba->get_owning_context()); } foreach ($this->metadataadded as $info) { $qa = reset($info); $stepdata[] = $dm->insert_question_attempt_metadata($qa, array_keys($info)); } foreach ($this->metadatamodified as $info) { $qa = reset($info); $stepdata[] = $dm->update_question_attempt_metadata($qa, array_keys($info)); } if ($this->modified) { $dm->update_questions_usage_by_activity($this->quba); } if ($stepdata) { $dm->insert_all_step_data(call_user_func_array('array_merge', $stepdata)); } $this->stepsdeleted = array(); $this->stepsmodified = array(); $this->stepsadded = array(); $this->attemptsdeleted = array(); $this->attemptsadded = array(); $this->attemptsmodified = array(); $this->modified = false; }
php
public function save(question_engine_data_mapper $dm) { $dm->delete_steps(array_keys($this->stepsdeleted), $this->quba->get_owning_context()); // Initially an array of array of question_attempt_step_objects. // Built as a nested array for efficiency, then flattened. $stepdata = array(); foreach ($this->stepsmodified as $stepinfo) { list($step, $questionattemptid, $seq) = $stepinfo; $stepdata[] = $dm->update_question_attempt_step( $step, $questionattemptid, $seq, $this->quba->get_owning_context()); } foreach ($this->stepsadded as $stepinfo) { list($step, $questionattemptid, $seq) = $stepinfo; $stepdata[] = $dm->insert_question_attempt_step( $step, $questionattemptid, $seq, $this->quba->get_owning_context()); } foreach ($this->attemptsmodified as $qa) { $dm->update_question_attempt($qa); } foreach ($this->attemptsadded as $qa) { $stepdata[] = $dm->insert_question_attempt( $qa, $this->quba->get_owning_context()); } foreach ($this->metadataadded as $info) { $qa = reset($info); $stepdata[] = $dm->insert_question_attempt_metadata($qa, array_keys($info)); } foreach ($this->metadatamodified as $info) { $qa = reset($info); $stepdata[] = $dm->update_question_attempt_metadata($qa, array_keys($info)); } if ($this->modified) { $dm->update_questions_usage_by_activity($this->quba); } if ($stepdata) { $dm->insert_all_step_data(call_user_func_array('array_merge', $stepdata)); } $this->stepsdeleted = array(); $this->stepsmodified = array(); $this->stepsadded = array(); $this->attemptsdeleted = array(); $this->attemptsadded = array(); $this->attemptsmodified = array(); $this->modified = false; }
[ "public", "function", "save", "(", "question_engine_data_mapper", "$", "dm", ")", "{", "$", "dm", "->", "delete_steps", "(", "array_keys", "(", "$", "this", "->", "stepsdeleted", ")", ",", "$", "this", "->", "quba", "->", "get_owning_context", "(", ")", ")", ";", "// Initially an array of array of question_attempt_step_objects.", "// Built as a nested array for efficiency, then flattened.", "$", "stepdata", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "stepsmodified", "as", "$", "stepinfo", ")", "{", "list", "(", "$", "step", ",", "$", "questionattemptid", ",", "$", "seq", ")", "=", "$", "stepinfo", ";", "$", "stepdata", "[", "]", "=", "$", "dm", "->", "update_question_attempt_step", "(", "$", "step", ",", "$", "questionattemptid", ",", "$", "seq", ",", "$", "this", "->", "quba", "->", "get_owning_context", "(", ")", ")", ";", "}", "foreach", "(", "$", "this", "->", "stepsadded", "as", "$", "stepinfo", ")", "{", "list", "(", "$", "step", ",", "$", "questionattemptid", ",", "$", "seq", ")", "=", "$", "stepinfo", ";", "$", "stepdata", "[", "]", "=", "$", "dm", "->", "insert_question_attempt_step", "(", "$", "step", ",", "$", "questionattemptid", ",", "$", "seq", ",", "$", "this", "->", "quba", "->", "get_owning_context", "(", ")", ")", ";", "}", "foreach", "(", "$", "this", "->", "attemptsmodified", "as", "$", "qa", ")", "{", "$", "dm", "->", "update_question_attempt", "(", "$", "qa", ")", ";", "}", "foreach", "(", "$", "this", "->", "attemptsadded", "as", "$", "qa", ")", "{", "$", "stepdata", "[", "]", "=", "$", "dm", "->", "insert_question_attempt", "(", "$", "qa", ",", "$", "this", "->", "quba", "->", "get_owning_context", "(", ")", ")", ";", "}", "foreach", "(", "$", "this", "->", "metadataadded", "as", "$", "info", ")", "{", "$", "qa", "=", "reset", "(", "$", "info", ")", ";", "$", "stepdata", "[", "]", "=", "$", "dm", "->", "insert_question_attempt_metadata", "(", "$", "qa", ",", "array_keys", "(", "$", "info", ")", ")", ";", "}", "foreach", "(", "$", "this", "->", "metadatamodified", "as", "$", "info", ")", "{", "$", "qa", "=", "reset", "(", "$", "info", ")", ";", "$", "stepdata", "[", "]", "=", "$", "dm", "->", "update_question_attempt_metadata", "(", "$", "qa", ",", "array_keys", "(", "$", "info", ")", ")", ";", "}", "if", "(", "$", "this", "->", "modified", ")", "{", "$", "dm", "->", "update_questions_usage_by_activity", "(", "$", "this", "->", "quba", ")", ";", "}", "if", "(", "$", "stepdata", ")", "{", "$", "dm", "->", "insert_all_step_data", "(", "call_user_func_array", "(", "'array_merge'", ",", "$", "stepdata", ")", ")", ";", "}", "$", "this", "->", "stepsdeleted", "=", "array", "(", ")", ";", "$", "this", "->", "stepsmodified", "=", "array", "(", ")", ";", "$", "this", "->", "stepsadded", "=", "array", "(", ")", ";", "$", "this", "->", "attemptsdeleted", "=", "array", "(", ")", ";", "$", "this", "->", "attemptsadded", "=", "array", "(", ")", ";", "$", "this", "->", "attemptsmodified", "=", "array", "(", ")", ";", "$", "this", "->", "modified", "=", "false", ";", "}" ]
Write all the changes we have recorded to the database. @param question_engine_data_mapper $dm the mapper to use to update the database.
[ "Write", "all", "the", "changes", "we", "have", "recorded", "to", "the", "database", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/datalib.php#L1540-L1593
219,901
moodle/moodle
question/engine/datalib.php
question_file_saver.save_files
public function save_files($itemid, $context) { file_save_draft_area_files($this->draftitemid, $context->id, $this->component, $this->filearea, $itemid); }
php
public function save_files($itemid, $context) { file_save_draft_area_files($this->draftitemid, $context->id, $this->component, $this->filearea, $itemid); }
[ "public", "function", "save_files", "(", "$", "itemid", ",", "$", "context", ")", "{", "file_save_draft_area_files", "(", "$", "this", "->", "draftitemid", ",", "$", "context", "->", "id", ",", "$", "this", "->", "component", ",", "$", "this", "->", "filearea", ",", "$", "itemid", ")", ";", "}" ]
Actually save the files. @param integer $itemid the item id for the file area to save into.
[ "Actually", "save", "the", "files", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/datalib.php#L1700-L1703
219,902
moodle/moodle
question/engine/datalib.php
question_file_saver.get_files
public function get_files() { global $USER; $fs = get_file_storage(); $usercontext = context_user::instance($USER->id); return $fs->get_area_files($usercontext->id, 'user', 'draft', $this->draftitemid, 'sortorder, filepath, filename', false); }
php
public function get_files() { global $USER; $fs = get_file_storage(); $usercontext = context_user::instance($USER->id); return $fs->get_area_files($usercontext->id, 'user', 'draft', $this->draftitemid, 'sortorder, filepath, filename', false); }
[ "public", "function", "get_files", "(", ")", "{", "global", "$", "USER", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "usercontext", "=", "context_user", "::", "instance", "(", "$", "USER", "->", "id", ")", ";", "return", "$", "fs", "->", "get_area_files", "(", "$", "usercontext", "->", "id", ",", "'user'", ",", "'draft'", ",", "$", "this", "->", "draftitemid", ",", "'sortorder, filepath, filename'", ",", "false", ")", ";", "}" ]
Get the files that were submitted. @return array of stored_files objects.
[ "Get", "the", "files", "that", "were", "submitted", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/engine/datalib.php#L1709-L1717
219,903
moodle/moodle
mod/forum/classes/search/post.php
post.get_document
public function get_document($record, $options = array()) { try { $cm = $this->get_cm('forum', $record->forumid, $record->courseid); $context = \context_module::instance($cm->id); } catch (\dml_missing_record_exception $ex) { // Notify it as we run here as admin, we should see everything. debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document, not all required data is available: ' . $ex->getMessage(), DEBUG_DEVELOPER); return false; } catch (\dml_exception $ex) { // Notify it as we run here as admin, we should see everything. debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document: ' . $ex->getMessage(), DEBUG_DEVELOPER); return false; } // Prepare associative array with data from DB. $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname); $doc->set('title', content_to_text($record->subject, false)); $doc->set('content', content_to_text($record->message, $record->messageformat)); $doc->set('contextid', $context->id); $doc->set('courseid', $record->courseid); $doc->set('userid', $record->userid); $doc->set('owneruserid', \core_search\manager::NO_OWNER_ID); $doc->set('modified', $record->modified); // Store group id if there is one. (0 and -1 both mean not restricted to group.) if ($record->groupid > 0) { $doc->set('groupid', $record->groupid); } // Check if this document should be considered new. if (isset($options['lastindexedtime']) && ($options['lastindexedtime'] < $record->created)) { // If the document was created after the last index time, it must be new. $doc->set_is_new(true); } return $doc; }
php
public function get_document($record, $options = array()) { try { $cm = $this->get_cm('forum', $record->forumid, $record->courseid); $context = \context_module::instance($cm->id); } catch (\dml_missing_record_exception $ex) { // Notify it as we run here as admin, we should see everything. debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document, not all required data is available: ' . $ex->getMessage(), DEBUG_DEVELOPER); return false; } catch (\dml_exception $ex) { // Notify it as we run here as admin, we should see everything. debugging('Error retrieving ' . $this->areaid . ' ' . $record->id . ' document: ' . $ex->getMessage(), DEBUG_DEVELOPER); return false; } // Prepare associative array with data from DB. $doc = \core_search\document_factory::instance($record->id, $this->componentname, $this->areaname); $doc->set('title', content_to_text($record->subject, false)); $doc->set('content', content_to_text($record->message, $record->messageformat)); $doc->set('contextid', $context->id); $doc->set('courseid', $record->courseid); $doc->set('userid', $record->userid); $doc->set('owneruserid', \core_search\manager::NO_OWNER_ID); $doc->set('modified', $record->modified); // Store group id if there is one. (0 and -1 both mean not restricted to group.) if ($record->groupid > 0) { $doc->set('groupid', $record->groupid); } // Check if this document should be considered new. if (isset($options['lastindexedtime']) && ($options['lastindexedtime'] < $record->created)) { // If the document was created after the last index time, it must be new. $doc->set_is_new(true); } return $doc; }
[ "public", "function", "get_document", "(", "$", "record", ",", "$", "options", "=", "array", "(", ")", ")", "{", "try", "{", "$", "cm", "=", "$", "this", "->", "get_cm", "(", "'forum'", ",", "$", "record", "->", "forumid", ",", "$", "record", "->", "courseid", ")", ";", "$", "context", "=", "\\", "context_module", "::", "instance", "(", "$", "cm", "->", "id", ")", ";", "}", "catch", "(", "\\", "dml_missing_record_exception", "$", "ex", ")", "{", "// Notify it as we run here as admin, we should see everything.", "debugging", "(", "'Error retrieving '", ".", "$", "this", "->", "areaid", ".", "' '", ".", "$", "record", "->", "id", ".", "' document, not all required data is available: '", ".", "$", "ex", "->", "getMessage", "(", ")", ",", "DEBUG_DEVELOPER", ")", ";", "return", "false", ";", "}", "catch", "(", "\\", "dml_exception", "$", "ex", ")", "{", "// Notify it as we run here as admin, we should see everything.", "debugging", "(", "'Error retrieving '", ".", "$", "this", "->", "areaid", ".", "' '", ".", "$", "record", "->", "id", ".", "' document: '", ".", "$", "ex", "->", "getMessage", "(", ")", ",", "DEBUG_DEVELOPER", ")", ";", "return", "false", ";", "}", "// Prepare associative array with data from DB.", "$", "doc", "=", "\\", "core_search", "\\", "document_factory", "::", "instance", "(", "$", "record", "->", "id", ",", "$", "this", "->", "componentname", ",", "$", "this", "->", "areaname", ")", ";", "$", "doc", "->", "set", "(", "'title'", ",", "content_to_text", "(", "$", "record", "->", "subject", ",", "false", ")", ")", ";", "$", "doc", "->", "set", "(", "'content'", ",", "content_to_text", "(", "$", "record", "->", "message", ",", "$", "record", "->", "messageformat", ")", ")", ";", "$", "doc", "->", "set", "(", "'contextid'", ",", "$", "context", "->", "id", ")", ";", "$", "doc", "->", "set", "(", "'courseid'", ",", "$", "record", "->", "courseid", ")", ";", "$", "doc", "->", "set", "(", "'userid'", ",", "$", "record", "->", "userid", ")", ";", "$", "doc", "->", "set", "(", "'owneruserid'", ",", "\\", "core_search", "\\", "manager", "::", "NO_OWNER_ID", ")", ";", "$", "doc", "->", "set", "(", "'modified'", ",", "$", "record", "->", "modified", ")", ";", "// Store group id if there is one. (0 and -1 both mean not restricted to group.)", "if", "(", "$", "record", "->", "groupid", ">", "0", ")", "{", "$", "doc", "->", "set", "(", "'groupid'", ",", "$", "record", "->", "groupid", ")", ";", "}", "// Check if this document should be considered new.", "if", "(", "isset", "(", "$", "options", "[", "'lastindexedtime'", "]", ")", "&&", "(", "$", "options", "[", "'lastindexedtime'", "]", "<", "$", "record", "->", "created", ")", ")", "{", "// If the document was created after the last index time, it must be new.", "$", "doc", "->", "set_is_new", "(", "true", ")", ";", "}", "return", "$", "doc", ";", "}" ]
Returns the document associated with this post id. @param stdClass $record Post info. @param array $options @return \core_search\document
[ "Returns", "the", "document", "associated", "with", "this", "post", "id", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/search/post.php#L87-L125
219,904
moodle/moodle
mod/forum/classes/search/post.php
post.attach_files
public function attach_files($document) { global $DB; $postid = $document->get('itemid'); try { $post = $this->get_post($postid); } catch (\dml_missing_record_exception $e) { unset($this->postsdata[$postid]); debugging('Could not get record to attach files to '.$document->get('id'), DEBUG_DEVELOPER); return; } // Because this is used during indexing, we don't want to cache posts. Would result in memory leak. unset($this->postsdata[$postid]); $cm = $this->get_cm($this->get_module_name(), $post->forum, $document->get('courseid')); $context = \context_module::instance($cm->id); $contextid = $context->id; $fileareas = $this->get_search_fileareas(); $component = $this->get_component_name(); // Get the files and attach them. foreach ($fileareas as $filearea) { $fs = get_file_storage(); $files = $fs->get_area_files($contextid, $component, $filearea, $postid, '', false); foreach ($files as $file) { $document->add_stored_file($file); } } }
php
public function attach_files($document) { global $DB; $postid = $document->get('itemid'); try { $post = $this->get_post($postid); } catch (\dml_missing_record_exception $e) { unset($this->postsdata[$postid]); debugging('Could not get record to attach files to '.$document->get('id'), DEBUG_DEVELOPER); return; } // Because this is used during indexing, we don't want to cache posts. Would result in memory leak. unset($this->postsdata[$postid]); $cm = $this->get_cm($this->get_module_name(), $post->forum, $document->get('courseid')); $context = \context_module::instance($cm->id); $contextid = $context->id; $fileareas = $this->get_search_fileareas(); $component = $this->get_component_name(); // Get the files and attach them. foreach ($fileareas as $filearea) { $fs = get_file_storage(); $files = $fs->get_area_files($contextid, $component, $filearea, $postid, '', false); foreach ($files as $file) { $document->add_stored_file($file); } } }
[ "public", "function", "attach_files", "(", "$", "document", ")", "{", "global", "$", "DB", ";", "$", "postid", "=", "$", "document", "->", "get", "(", "'itemid'", ")", ";", "try", "{", "$", "post", "=", "$", "this", "->", "get_post", "(", "$", "postid", ")", ";", "}", "catch", "(", "\\", "dml_missing_record_exception", "$", "e", ")", "{", "unset", "(", "$", "this", "->", "postsdata", "[", "$", "postid", "]", ")", ";", "debugging", "(", "'Could not get record to attach files to '", ".", "$", "document", "->", "get", "(", "'id'", ")", ",", "DEBUG_DEVELOPER", ")", ";", "return", ";", "}", "// Because this is used during indexing, we don't want to cache posts. Would result in memory leak.", "unset", "(", "$", "this", "->", "postsdata", "[", "$", "postid", "]", ")", ";", "$", "cm", "=", "$", "this", "->", "get_cm", "(", "$", "this", "->", "get_module_name", "(", ")", ",", "$", "post", "->", "forum", ",", "$", "document", "->", "get", "(", "'courseid'", ")", ")", ";", "$", "context", "=", "\\", "context_module", "::", "instance", "(", "$", "cm", "->", "id", ")", ";", "$", "contextid", "=", "$", "context", "->", "id", ";", "$", "fileareas", "=", "$", "this", "->", "get_search_fileareas", "(", ")", ";", "$", "component", "=", "$", "this", "->", "get_component_name", "(", ")", ";", "// Get the files and attach them.", "foreach", "(", "$", "fileareas", "as", "$", "filearea", ")", "{", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "files", "=", "$", "fs", "->", "get_area_files", "(", "$", "contextid", ",", "$", "component", ",", "$", "filearea", ",", "$", "postid", ",", "''", ",", "false", ")", ";", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "$", "document", "->", "add_stored_file", "(", "$", "file", ")", ";", "}", "}", "}" ]
Add the forum post attachments. @param document $document The current document @return null
[ "Add", "the", "forum", "post", "attachments", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/search/post.php#L157-L189
219,905
moodle/moodle
mod/forum/classes/search/post.php
post.get_doc_url
public function get_doc_url(\core_search\document $doc) { // The post is already in static cache, we fetch it in self::search_access. $post = $this->get_post($doc->get('itemid')); return new \moodle_url('/mod/forum/discuss.php', array('d' => $post->discussion)); }
php
public function get_doc_url(\core_search\document $doc) { // The post is already in static cache, we fetch it in self::search_access. $post = $this->get_post($doc->get('itemid')); return new \moodle_url('/mod/forum/discuss.php', array('d' => $post->discussion)); }
[ "public", "function", "get_doc_url", "(", "\\", "core_search", "\\", "document", "$", "doc", ")", "{", "// The post is already in static cache, we fetch it in self::search_access.", "$", "post", "=", "$", "this", "->", "get_post", "(", "$", "doc", "->", "get", "(", "'itemid'", ")", ")", ";", "return", "new", "\\", "moodle_url", "(", "'/mod/forum/discuss.php'", ",", "array", "(", "'d'", "=>", "$", "post", "->", "discussion", ")", ")", ";", "}" ]
Link to the forum post discussion @param \core_search\document $doc @return \moodle_url
[ "Link", "to", "the", "forum", "post", "discussion" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/search/post.php#L232-L236
219,906
moodle/moodle
mod/forum/classes/search/post.php
post.get_context_url
public function get_context_url(\core_search\document $doc) { $contextmodule = \context::instance_by_id($doc->get('contextid')); return new \moodle_url('/mod/forum/view.php', array('id' => $contextmodule->instanceid)); }
php
public function get_context_url(\core_search\document $doc) { $contextmodule = \context::instance_by_id($doc->get('contextid')); return new \moodle_url('/mod/forum/view.php', array('id' => $contextmodule->instanceid)); }
[ "public", "function", "get_context_url", "(", "\\", "core_search", "\\", "document", "$", "doc", ")", "{", "$", "contextmodule", "=", "\\", "context", "::", "instance_by_id", "(", "$", "doc", "->", "get", "(", "'contextid'", ")", ")", ";", "return", "new", "\\", "moodle_url", "(", "'/mod/forum/view.php'", ",", "array", "(", "'id'", "=>", "$", "contextmodule", "->", "instanceid", ")", ")", ";", "}" ]
Link to the forum. @param \core_search\document $doc @return \moodle_url
[ "Link", "to", "the", "forum", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/search/post.php#L244-L247
219,907
moodle/moodle
mod/forum/classes/search/post.php
post.get_post
protected function get_post($postid) { if (empty($this->postsdata[$postid])) { $this->postsdata[$postid] = forum_get_post_full($postid); if (!$this->postsdata[$postid]) { throw new \dml_missing_record_exception('forum_posts'); } } return $this->postsdata[$postid]; }
php
protected function get_post($postid) { if (empty($this->postsdata[$postid])) { $this->postsdata[$postid] = forum_get_post_full($postid); if (!$this->postsdata[$postid]) { throw new \dml_missing_record_exception('forum_posts'); } } return $this->postsdata[$postid]; }
[ "protected", "function", "get_post", "(", "$", "postid", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "postsdata", "[", "$", "postid", "]", ")", ")", "{", "$", "this", "->", "postsdata", "[", "$", "postid", "]", "=", "forum_get_post_full", "(", "$", "postid", ")", ";", "if", "(", "!", "$", "this", "->", "postsdata", "[", "$", "postid", "]", ")", "{", "throw", "new", "\\", "dml_missing_record_exception", "(", "'forum_posts'", ")", ";", "}", "}", "return", "$", "this", "->", "postsdata", "[", "$", "postid", "]", ";", "}" ]
Returns the specified forum post from its internal cache. @throws \dml_missing_record_exception @param int $postid @return stdClass
[ "Returns", "the", "specified", "forum", "post", "from", "its", "internal", "cache", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/search/post.php#L256-L264
219,908
moodle/moodle
mod/forum/classes/search/post.php
post.get_forum
protected function get_forum($forumid) { global $DB; if (empty($this->forumsdata[$forumid])) { $this->forumsdata[$forumid] = $DB->get_record('forum', array('id' => $forumid), '*', MUST_EXIST); } return $this->forumsdata[$forumid]; }
php
protected function get_forum($forumid) { global $DB; if (empty($this->forumsdata[$forumid])) { $this->forumsdata[$forumid] = $DB->get_record('forum', array('id' => $forumid), '*', MUST_EXIST); } return $this->forumsdata[$forumid]; }
[ "protected", "function", "get_forum", "(", "$", "forumid", ")", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "this", "->", "forumsdata", "[", "$", "forumid", "]", ")", ")", "{", "$", "this", "->", "forumsdata", "[", "$", "forumid", "]", "=", "$", "DB", "->", "get_record", "(", "'forum'", ",", "array", "(", "'id'", "=>", "$", "forumid", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "}", "return", "$", "this", "->", "forumsdata", "[", "$", "forumid", "]", ";", "}" ]
Returns the specified forum checking the internal cache. Store minimal information as this might grow. @throws \dml_exception @param int $forumid @return stdClass
[ "Returns", "the", "specified", "forum", "checking", "the", "internal", "cache", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/search/post.php#L275-L282
219,909
moodle/moodle
mod/forum/classes/search/post.php
post.get_discussion
protected function get_discussion($discussionid) { global $DB; if (empty($this->discussionsdata[$discussionid])) { $this->discussionsdata[$discussionid] = $DB->get_record('forum_discussions', array('id' => $discussionid), '*', MUST_EXIST); } return $this->discussionsdata[$discussionid]; }
php
protected function get_discussion($discussionid) { global $DB; if (empty($this->discussionsdata[$discussionid])) { $this->discussionsdata[$discussionid] = $DB->get_record('forum_discussions', array('id' => $discussionid), '*', MUST_EXIST); } return $this->discussionsdata[$discussionid]; }
[ "protected", "function", "get_discussion", "(", "$", "discussionid", ")", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "this", "->", "discussionsdata", "[", "$", "discussionid", "]", ")", ")", "{", "$", "this", "->", "discussionsdata", "[", "$", "discussionid", "]", "=", "$", "DB", "->", "get_record", "(", "'forum_discussions'", ",", "array", "(", "'id'", "=>", "$", "discussionid", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "}", "return", "$", "this", "->", "discussionsdata", "[", "$", "discussionid", "]", ";", "}" ]
Returns the discussion checking the internal cache. @throws \dml_missing_record_exception @param int $discussionid @return stdClass
[ "Returns", "the", "discussion", "checking", "the", "internal", "cache", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/search/post.php#L291-L299
219,910
moodle/moodle
mod/scorm/classes/external.php
mod_scorm_external.get_scorm_attempt_count_parameters
public static function get_scorm_attempt_count_parameters() { return new external_function_parameters( array( 'scormid' => new external_value(PARAM_INT, 'SCORM instance id'), 'userid' => new external_value(PARAM_INT, 'User id'), 'ignoremissingcompletion' => new external_value(PARAM_BOOL, 'Ignores attempts that haven\'t reported a grade/completion', VALUE_DEFAULT, false), ) ); }
php
public static function get_scorm_attempt_count_parameters() { return new external_function_parameters( array( 'scormid' => new external_value(PARAM_INT, 'SCORM instance id'), 'userid' => new external_value(PARAM_INT, 'User id'), 'ignoremissingcompletion' => new external_value(PARAM_BOOL, 'Ignores attempts that haven\'t reported a grade/completion', VALUE_DEFAULT, false), ) ); }
[ "public", "static", "function", "get_scorm_attempt_count_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'scormid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'SCORM instance id'", ")", ",", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'User id'", ")", ",", "'ignoremissingcompletion'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Ignores attempts that haven\\'t reported a grade/completion'", ",", "VALUE_DEFAULT", ",", "false", ")", ",", ")", ")", ";", "}" ]
Describes the parameters for get_scorm_attempt_count. @return external_function_parameters @since Moodle 3.0
[ "Describes", "the", "parameters", "for", "get_scorm_attempt_count", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/scorm/classes/external.php#L113-L123
219,911
moodle/moodle
mod/scorm/classes/external.php
mod_scorm_external.get_scorm_attempt_count
public static function get_scorm_attempt_count($scormid, $userid, $ignoremissingcompletion = false) { global $USER, $DB; $params = self::validate_parameters(self::get_scorm_attempt_count_parameters(), array('scormid' => $scormid, 'userid' => $userid, 'ignoremissingcompletion' => $ignoremissingcompletion)); $attempts = array(); $warnings = array(); $scorm = $DB->get_record('scorm', array('id' => $params['scormid']), '*', MUST_EXIST); $cm = get_coursemodule_from_instance('scorm', $scorm->id); $context = context_module::instance($cm->id); self::validate_context($context); $user = core_user::get_user($params['userid'], '*', MUST_EXIST); core_user::require_active_user($user); // Extra checks so only users with permissions can view other users attempts. if ($USER->id != $user->id) { require_capability('mod/scorm:viewreport', $context); } // If the SCORM is not open this function will throw exceptions. scorm_require_available($scorm); $attemptscount = scorm_get_attempt_count($user->id, $scorm, false, $params['ignoremissingcompletion']); $result = array(); $result['attemptscount'] = $attemptscount; $result['warnings'] = $warnings; return $result; }
php
public static function get_scorm_attempt_count($scormid, $userid, $ignoremissingcompletion = false) { global $USER, $DB; $params = self::validate_parameters(self::get_scorm_attempt_count_parameters(), array('scormid' => $scormid, 'userid' => $userid, 'ignoremissingcompletion' => $ignoremissingcompletion)); $attempts = array(); $warnings = array(); $scorm = $DB->get_record('scorm', array('id' => $params['scormid']), '*', MUST_EXIST); $cm = get_coursemodule_from_instance('scorm', $scorm->id); $context = context_module::instance($cm->id); self::validate_context($context); $user = core_user::get_user($params['userid'], '*', MUST_EXIST); core_user::require_active_user($user); // Extra checks so only users with permissions can view other users attempts. if ($USER->id != $user->id) { require_capability('mod/scorm:viewreport', $context); } // If the SCORM is not open this function will throw exceptions. scorm_require_available($scorm); $attemptscount = scorm_get_attempt_count($user->id, $scorm, false, $params['ignoremissingcompletion']); $result = array(); $result['attemptscount'] = $attemptscount; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "get_scorm_attempt_count", "(", "$", "scormid", ",", "$", "userid", ",", "$", "ignoremissingcompletion", "=", "false", ")", "{", "global", "$", "USER", ",", "$", "DB", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_scorm_attempt_count_parameters", "(", ")", ",", "array", "(", "'scormid'", "=>", "$", "scormid", ",", "'userid'", "=>", "$", "userid", ",", "'ignoremissingcompletion'", "=>", "$", "ignoremissingcompletion", ")", ")", ";", "$", "attempts", "=", "array", "(", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "$", "scorm", "=", "$", "DB", "->", "get_record", "(", "'scorm'", ",", "array", "(", "'id'", "=>", "$", "params", "[", "'scormid'", "]", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "$", "cm", "=", "get_coursemodule_from_instance", "(", "'scorm'", ",", "$", "scorm", "->", "id", ")", ";", "$", "context", "=", "context_module", "::", "instance", "(", "$", "cm", "->", "id", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "user", "=", "core_user", "::", "get_user", "(", "$", "params", "[", "'userid'", "]", ",", "'*'", ",", "MUST_EXIST", ")", ";", "core_user", "::", "require_active_user", "(", "$", "user", ")", ";", "// Extra checks so only users with permissions can view other users attempts.", "if", "(", "$", "USER", "->", "id", "!=", "$", "user", "->", "id", ")", "{", "require_capability", "(", "'mod/scorm:viewreport'", ",", "$", "context", ")", ";", "}", "// If the SCORM is not open this function will throw exceptions.", "scorm_require_available", "(", "$", "scorm", ")", ";", "$", "attemptscount", "=", "scorm_get_attempt_count", "(", "$", "user", "->", "id", ",", "$", "scorm", ",", "false", ",", "$", "params", "[", "'ignoremissingcompletion'", "]", ")", ";", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'attemptscount'", "]", "=", "$", "attemptscount", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Return the number of attempts done by a user in the given SCORM. @param int $scormid the scorm id @param int $userid the user id @param bool $ignoremissingcompletion ignores attempts that haven't reported a grade/completion @return array of warnings and the attempts count @since Moodle 3.0
[ "Return", "the", "number", "of", "attempts", "done", "by", "a", "user", "in", "the", "given", "SCORM", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/scorm/classes/external.php#L134-L167
219,912
moodle/moodle
mod/scorm/classes/external.php
mod_scorm_external.get_scorm_scoes
public static function get_scorm_scoes($scormid, $organization = '') { global $DB; $params = self::validate_parameters(self::get_scorm_scoes_parameters(), array('scormid' => $scormid, 'organization' => $organization)); $scoes = array(); $warnings = array(); $scorm = $DB->get_record('scorm', array('id' => $params['scormid']), '*', MUST_EXIST); $cm = get_coursemodule_from_instance('scorm', $scorm->id); $context = context_module::instance($cm->id); self::validate_context($context); // Check settings / permissions to view the SCORM. scorm_require_available($scorm, true, $context); if (!$scoes = scorm_get_scoes($scorm->id, $params['organization'])) { // Function scorm_get_scoes return false, not an empty array. $scoes = array(); } else { $scoreturnstructure = self::get_scorm_scoes_returns(); foreach ($scoes as $sco) { $extradata = array(); foreach ($sco as $element => $value) { // Check if the element is extra data (not a basic SCO element). if (!isset($scoreturnstructure->keys['scoes']->content->keys[$element])) { $extradata[] = array( 'element' => $element, 'value' => $value ); } } $sco->extradata = $extradata; } } $result = array(); $result['scoes'] = $scoes; $result['warnings'] = $warnings; return $result; }
php
public static function get_scorm_scoes($scormid, $organization = '') { global $DB; $params = self::validate_parameters(self::get_scorm_scoes_parameters(), array('scormid' => $scormid, 'organization' => $organization)); $scoes = array(); $warnings = array(); $scorm = $DB->get_record('scorm', array('id' => $params['scormid']), '*', MUST_EXIST); $cm = get_coursemodule_from_instance('scorm', $scorm->id); $context = context_module::instance($cm->id); self::validate_context($context); // Check settings / permissions to view the SCORM. scorm_require_available($scorm, true, $context); if (!$scoes = scorm_get_scoes($scorm->id, $params['organization'])) { // Function scorm_get_scoes return false, not an empty array. $scoes = array(); } else { $scoreturnstructure = self::get_scorm_scoes_returns(); foreach ($scoes as $sco) { $extradata = array(); foreach ($sco as $element => $value) { // Check if the element is extra data (not a basic SCO element). if (!isset($scoreturnstructure->keys['scoes']->content->keys[$element])) { $extradata[] = array( 'element' => $element, 'value' => $value ); } } $sco->extradata = $extradata; } } $result = array(); $result['scoes'] = $scoes; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "get_scorm_scoes", "(", "$", "scormid", ",", "$", "organization", "=", "''", ")", "{", "global", "$", "DB", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_scorm_scoes_parameters", "(", ")", ",", "array", "(", "'scormid'", "=>", "$", "scormid", ",", "'organization'", "=>", "$", "organization", ")", ")", ";", "$", "scoes", "=", "array", "(", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "$", "scorm", "=", "$", "DB", "->", "get_record", "(", "'scorm'", ",", "array", "(", "'id'", "=>", "$", "params", "[", "'scormid'", "]", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "$", "cm", "=", "get_coursemodule_from_instance", "(", "'scorm'", ",", "$", "scorm", "->", "id", ")", ";", "$", "context", "=", "context_module", "::", "instance", "(", "$", "cm", "->", "id", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "// Check settings / permissions to view the SCORM.", "scorm_require_available", "(", "$", "scorm", ",", "true", ",", "$", "context", ")", ";", "if", "(", "!", "$", "scoes", "=", "scorm_get_scoes", "(", "$", "scorm", "->", "id", ",", "$", "params", "[", "'organization'", "]", ")", ")", "{", "// Function scorm_get_scoes return false, not an empty array.", "$", "scoes", "=", "array", "(", ")", ";", "}", "else", "{", "$", "scoreturnstructure", "=", "self", "::", "get_scorm_scoes_returns", "(", ")", ";", "foreach", "(", "$", "scoes", "as", "$", "sco", ")", "{", "$", "extradata", "=", "array", "(", ")", ";", "foreach", "(", "$", "sco", "as", "$", "element", "=>", "$", "value", ")", "{", "// Check if the element is extra data (not a basic SCO element).", "if", "(", "!", "isset", "(", "$", "scoreturnstructure", "->", "keys", "[", "'scoes'", "]", "->", "content", "->", "keys", "[", "$", "element", "]", ")", ")", "{", "$", "extradata", "[", "]", "=", "array", "(", "'element'", "=>", "$", "element", ",", "'value'", "=>", "$", "value", ")", ";", "}", "}", "$", "sco", "->", "extradata", "=", "$", "extradata", ";", "}", "}", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'scoes'", "]", "=", "$", "scoes", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Returns a list containing all the scoes data related to the given scorm id @param int $scormid the scorm id @param string $organization the organization id @return array warnings and the scoes data @since Moodle 3.0
[ "Returns", "a", "list", "containing", "all", "the", "scoes", "data", "related", "to", "the", "given", "scorm", "id" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/scorm/classes/external.php#L208-L250
219,913
moodle/moodle
mod/scorm/classes/external.php
mod_scorm_external.get_scorm_scoes_returns
public static function get_scorm_scoes_returns() { return new external_single_structure( array( 'scoes' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'sco id'), 'scorm' => new external_value(PARAM_INT, 'scorm id'), 'manifest' => new external_value(PARAM_NOTAGS, 'manifest id'), 'organization' => new external_value(PARAM_NOTAGS, 'organization id'), 'parent' => new external_value(PARAM_NOTAGS, 'parent'), 'identifier' => new external_value(PARAM_NOTAGS, 'identifier'), 'launch' => new external_value(PARAM_NOTAGS, 'launch file'), 'scormtype' => new external_value(PARAM_ALPHA, 'scorm type (asset, sco)'), 'title' => new external_value(PARAM_NOTAGS, 'sco title'), 'sortorder' => new external_value(PARAM_INT, 'sort order'), 'extradata' => new external_multiple_structure( new external_single_structure( array( 'element' => new external_value(PARAM_RAW, 'element name'), 'value' => new external_value(PARAM_RAW, 'element value') ) ), 'Additional SCO data', VALUE_OPTIONAL ) ), 'SCORM SCO data' ) ), 'warnings' => new external_warnings(), ) ); }
php
public static function get_scorm_scoes_returns() { return new external_single_structure( array( 'scoes' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'sco id'), 'scorm' => new external_value(PARAM_INT, 'scorm id'), 'manifest' => new external_value(PARAM_NOTAGS, 'manifest id'), 'organization' => new external_value(PARAM_NOTAGS, 'organization id'), 'parent' => new external_value(PARAM_NOTAGS, 'parent'), 'identifier' => new external_value(PARAM_NOTAGS, 'identifier'), 'launch' => new external_value(PARAM_NOTAGS, 'launch file'), 'scormtype' => new external_value(PARAM_ALPHA, 'scorm type (asset, sco)'), 'title' => new external_value(PARAM_NOTAGS, 'sco title'), 'sortorder' => new external_value(PARAM_INT, 'sort order'), 'extradata' => new external_multiple_structure( new external_single_structure( array( 'element' => new external_value(PARAM_RAW, 'element name'), 'value' => new external_value(PARAM_RAW, 'element value') ) ), 'Additional SCO data', VALUE_OPTIONAL ) ), 'SCORM SCO data' ) ), 'warnings' => new external_warnings(), ) ); }
[ "public", "static", "function", "get_scorm_scoes_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'scoes'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'sco id'", ")", ",", "'scorm'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'scorm id'", ")", ",", "'manifest'", "=>", "new", "external_value", "(", "PARAM_NOTAGS", ",", "'manifest id'", ")", ",", "'organization'", "=>", "new", "external_value", "(", "PARAM_NOTAGS", ",", "'organization id'", ")", ",", "'parent'", "=>", "new", "external_value", "(", "PARAM_NOTAGS", ",", "'parent'", ")", ",", "'identifier'", "=>", "new", "external_value", "(", "PARAM_NOTAGS", ",", "'identifier'", ")", ",", "'launch'", "=>", "new", "external_value", "(", "PARAM_NOTAGS", ",", "'launch file'", ")", ",", "'scormtype'", "=>", "new", "external_value", "(", "PARAM_ALPHA", ",", "'scorm type (asset, sco)'", ")", ",", "'title'", "=>", "new", "external_value", "(", "PARAM_NOTAGS", ",", "'sco title'", ")", ",", "'sortorder'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'sort order'", ")", ",", "'extradata'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'element'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'element name'", ")", ",", "'value'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'element value'", ")", ")", ")", ",", "'Additional SCO data'", ",", "VALUE_OPTIONAL", ")", ")", ",", "'SCORM SCO data'", ")", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ",", ")", ")", ";", "}" ]
Describes the get_scorm_scoes return value. @return external_single_structure @since Moodle 3.0
[ "Describes", "the", "get_scorm_scoes", "return", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/scorm/classes/external.php#L258-L289
219,914
moodle/moodle
mod/scorm/classes/external.php
mod_scorm_external.get_scorm_user_data
public static function get_scorm_user_data($scormid, $attempt) { global $CFG, $DB; $params = self::validate_parameters(self::get_scorm_user_data_parameters(), array('scormid' => $scormid, 'attempt' => $attempt)); $data = array(); $warnings = array(); $scorm = $DB->get_record('scorm', array('id' => $params['scormid']), '*', MUST_EXIST); $cm = get_coursemodule_from_instance('scorm', $scorm->id); $context = context_module::instance($cm->id); self::validate_context($context); scorm_require_available($scorm, true, $context); $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); if (!file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php')) { $scorm->version = 'scorm_12'; } require_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php'); if ($scoes = scorm_get_scoes($scorm->id)) { $def = new stdClass(); $user = new stdClass(); foreach ($scoes as $sco) { $def->{$sco->id} = new stdClass(); $user->{$sco->id} = new stdClass(); // We force mode normal, this can be override by the client at any time. $def->{$sco->id} = get_scorm_default($user->{$sco->id}, $scorm, $sco->id, $params['attempt'], 'normal'); $userdata = array(); $defaultdata = array(); foreach ((array) $user->{$sco->id} as $key => $val) { $userdata[] = array( 'element' => $key, 'value' => $val ); } foreach ($def->{$sco->id} as $key => $val) { $defaultdata[] = array( 'element' => $key, 'value' => $val ); } $data[] = array( 'scoid' => $sco->id, 'userdata' => $userdata, 'defaultdata' => $defaultdata, ); } } $result = array(); $result['data'] = $data; $result['warnings'] = $warnings; return $result; }
php
public static function get_scorm_user_data($scormid, $attempt) { global $CFG, $DB; $params = self::validate_parameters(self::get_scorm_user_data_parameters(), array('scormid' => $scormid, 'attempt' => $attempt)); $data = array(); $warnings = array(); $scorm = $DB->get_record('scorm', array('id' => $params['scormid']), '*', MUST_EXIST); $cm = get_coursemodule_from_instance('scorm', $scorm->id); $context = context_module::instance($cm->id); self::validate_context($context); scorm_require_available($scorm, true, $context); $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); if (!file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php')) { $scorm->version = 'scorm_12'; } require_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php'); if ($scoes = scorm_get_scoes($scorm->id)) { $def = new stdClass(); $user = new stdClass(); foreach ($scoes as $sco) { $def->{$sco->id} = new stdClass(); $user->{$sco->id} = new stdClass(); // We force mode normal, this can be override by the client at any time. $def->{$sco->id} = get_scorm_default($user->{$sco->id}, $scorm, $sco->id, $params['attempt'], 'normal'); $userdata = array(); $defaultdata = array(); foreach ((array) $user->{$sco->id} as $key => $val) { $userdata[] = array( 'element' => $key, 'value' => $val ); } foreach ($def->{$sco->id} as $key => $val) { $defaultdata[] = array( 'element' => $key, 'value' => $val ); } $data[] = array( 'scoid' => $sco->id, 'userdata' => $userdata, 'defaultdata' => $defaultdata, ); } } $result = array(); $result['data'] = $data; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "get_scorm_user_data", "(", "$", "scormid", ",", "$", "attempt", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_scorm_user_data_parameters", "(", ")", ",", "array", "(", "'scormid'", "=>", "$", "scormid", ",", "'attempt'", "=>", "$", "attempt", ")", ")", ";", "$", "data", "=", "array", "(", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "$", "scorm", "=", "$", "DB", "->", "get_record", "(", "'scorm'", ",", "array", "(", "'id'", "=>", "$", "params", "[", "'scormid'", "]", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "$", "cm", "=", "get_coursemodule_from_instance", "(", "'scorm'", ",", "$", "scorm", "->", "id", ")", ";", "$", "context", "=", "context_module", "::", "instance", "(", "$", "cm", "->", "id", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "scorm_require_available", "(", "$", "scorm", ",", "true", ",", "$", "context", ")", ";", "$", "scorm", "->", "version", "=", "strtolower", "(", "clean_param", "(", "$", "scorm", "->", "version", ",", "PARAM_SAFEDIR", ")", ")", ";", "if", "(", "!", "file_exists", "(", "$", "CFG", "->", "dirroot", ".", "'/mod/scorm/datamodels/'", ".", "$", "scorm", "->", "version", ".", "'lib.php'", ")", ")", "{", "$", "scorm", "->", "version", "=", "'scorm_12'", ";", "}", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/mod/scorm/datamodels/'", ".", "$", "scorm", "->", "version", ".", "'lib.php'", ")", ";", "if", "(", "$", "scoes", "=", "scorm_get_scoes", "(", "$", "scorm", "->", "id", ")", ")", "{", "$", "def", "=", "new", "stdClass", "(", ")", ";", "$", "user", "=", "new", "stdClass", "(", ")", ";", "foreach", "(", "$", "scoes", "as", "$", "sco", ")", "{", "$", "def", "->", "{", "$", "sco", "->", "id", "}", "=", "new", "stdClass", "(", ")", ";", "$", "user", "->", "{", "$", "sco", "->", "id", "}", "=", "new", "stdClass", "(", ")", ";", "// We force mode normal, this can be override by the client at any time.", "$", "def", "->", "{", "$", "sco", "->", "id", "}", "=", "get_scorm_default", "(", "$", "user", "->", "{", "$", "sco", "->", "id", "}", ",", "$", "scorm", ",", "$", "sco", "->", "id", ",", "$", "params", "[", "'attempt'", "]", ",", "'normal'", ")", ";", "$", "userdata", "=", "array", "(", ")", ";", "$", "defaultdata", "=", "array", "(", ")", ";", "foreach", "(", "(", "array", ")", "$", "user", "->", "{", "$", "sco", "->", "id", "}", "as", "$", "key", "=>", "$", "val", ")", "{", "$", "userdata", "[", "]", "=", "array", "(", "'element'", "=>", "$", "key", ",", "'value'", "=>", "$", "val", ")", ";", "}", "foreach", "(", "$", "def", "->", "{", "$", "sco", "->", "id", "}", "as", "$", "key", "=>", "$", "val", ")", "{", "$", "defaultdata", "[", "]", "=", "array", "(", "'element'", "=>", "$", "key", ",", "'value'", "=>", "$", "val", ")", ";", "}", "$", "data", "[", "]", "=", "array", "(", "'scoid'", "=>", "$", "sco", "->", "id", ",", "'userdata'", "=>", "$", "userdata", ",", "'defaultdata'", "=>", "$", "defaultdata", ",", ")", ";", "}", "}", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'data'", "]", "=", "$", "data", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Retrieves user tracking and SCO data and default SCORM values @param int $scormid the scorm id @param int $attempt the attempt number @return array warnings and the scoes data @throws moodle_exception @since Moodle 3.0
[ "Retrieves", "user", "tracking", "and", "SCO", "data", "and", "default", "SCORM", "values" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/scorm/classes/external.php#L315-L376
219,915
moodle/moodle
mod/scorm/classes/external.php
mod_scorm_external.get_scorm_user_data_returns
public static function get_scorm_user_data_returns() { return new external_single_structure( array( 'data' => new external_multiple_structure( new external_single_structure( array( 'scoid' => new external_value(PARAM_INT, 'sco id'), 'userdata' => new external_multiple_structure( new external_single_structure( array( 'element' => new external_value(PARAM_RAW, 'element name'), 'value' => new external_value(PARAM_RAW, 'element value') ) ) ), 'defaultdata' => new external_multiple_structure( new external_single_structure( array( 'element' => new external_value(PARAM_RAW, 'element name'), 'value' => new external_value(PARAM_RAW, 'element value') ) ) ), ), 'SCO data' ) ), 'warnings' => new external_warnings(), ) ); }
php
public static function get_scorm_user_data_returns() { return new external_single_structure( array( 'data' => new external_multiple_structure( new external_single_structure( array( 'scoid' => new external_value(PARAM_INT, 'sco id'), 'userdata' => new external_multiple_structure( new external_single_structure( array( 'element' => new external_value(PARAM_RAW, 'element name'), 'value' => new external_value(PARAM_RAW, 'element value') ) ) ), 'defaultdata' => new external_multiple_structure( new external_single_structure( array( 'element' => new external_value(PARAM_RAW, 'element name'), 'value' => new external_value(PARAM_RAW, 'element value') ) ) ), ), 'SCO data' ) ), 'warnings' => new external_warnings(), ) ); }
[ "public", "static", "function", "get_scorm_user_data_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'data'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'scoid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'sco id'", ")", ",", "'userdata'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'element'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'element name'", ")", ",", "'value'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'element value'", ")", ")", ")", ")", ",", "'defaultdata'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'element'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'element name'", ")", ",", "'value'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'element value'", ")", ")", ")", ")", ",", ")", ",", "'SCO data'", ")", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ",", ")", ")", ";", "}" ]
Describes the get_scorm_user_data return value. @return external_single_structure @since Moodle 3.0
[ "Describes", "the", "get_scorm_user_data", "return", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/scorm/classes/external.php#L384-L414
219,916
moodle/moodle
mod/scorm/classes/external.php
mod_scorm_external.insert_scorm_tracks_parameters
public static function insert_scorm_tracks_parameters() { return new external_function_parameters( array( 'scoid' => new external_value(PARAM_INT, 'SCO id'), 'attempt' => new external_value(PARAM_INT, 'attempt number'), 'tracks' => new external_multiple_structure( new external_single_structure( array( 'element' => new external_value(PARAM_RAW, 'element name'), 'value' => new external_value(PARAM_RAW, 'element value') ) ) ), ) ); }
php
public static function insert_scorm_tracks_parameters() { return new external_function_parameters( array( 'scoid' => new external_value(PARAM_INT, 'SCO id'), 'attempt' => new external_value(PARAM_INT, 'attempt number'), 'tracks' => new external_multiple_structure( new external_single_structure( array( 'element' => new external_value(PARAM_RAW, 'element name'), 'value' => new external_value(PARAM_RAW, 'element value') ) ) ), ) ); }
[ "public", "static", "function", "insert_scorm_tracks_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'scoid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'SCO id'", ")", ",", "'attempt'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'attempt number'", ")", ",", "'tracks'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'element'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'element name'", ")", ",", "'value'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'element value'", ")", ")", ")", ")", ",", ")", ")", ";", "}" ]
Describes the parameters for insert_scorm_tracks. @return external_function_parameters @since Moodle 3.0
[ "Describes", "the", "parameters", "for", "insert_scorm_tracks", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/scorm/classes/external.php#L422-L437
219,917
moodle/moodle
mod/scorm/classes/external.php
mod_scorm_external.insert_scorm_tracks
public static function insert_scorm_tracks($scoid, $attempt, $tracks) { global $USER, $DB; $params = self::validate_parameters(self::insert_scorm_tracks_parameters(), array('scoid' => $scoid, 'attempt' => $attempt, 'tracks' => $tracks)); $trackids = array(); $warnings = array(); $sco = scorm_get_sco($params['scoid'], SCO_ONLY); if (!$sco) { throw new moodle_exception('cannotfindsco', 'scorm'); } $scorm = $DB->get_record('scorm', array('id' => $sco->scorm), '*', MUST_EXIST); $cm = get_coursemodule_from_instance('scorm', $scorm->id); $context = context_module::instance($cm->id); self::validate_context($context); // Check settings / permissions to view the SCORM. require_capability('mod/scorm:savetrack', $context); // Check settings / permissions to view the SCORM. scorm_require_available($scorm); foreach ($params['tracks'] as $track) { $element = $track['element']; $value = $track['value']; $trackid = scorm_insert_track($USER->id, $scorm->id, $sco->id, $params['attempt'], $element, $value, $scorm->forcecompleted); if ($trackid) { $trackids[] = $trackid; } else { $warnings[] = array( 'item' => 'scorm', 'itemid' => $scorm->id, 'warningcode' => 1, 'message' => 'Element: ' . $element . ' was not saved' ); } } $result = array(); $result['trackids'] = $trackids; $result['warnings'] = $warnings; return $result; }
php
public static function insert_scorm_tracks($scoid, $attempt, $tracks) { global $USER, $DB; $params = self::validate_parameters(self::insert_scorm_tracks_parameters(), array('scoid' => $scoid, 'attempt' => $attempt, 'tracks' => $tracks)); $trackids = array(); $warnings = array(); $sco = scorm_get_sco($params['scoid'], SCO_ONLY); if (!$sco) { throw new moodle_exception('cannotfindsco', 'scorm'); } $scorm = $DB->get_record('scorm', array('id' => $sco->scorm), '*', MUST_EXIST); $cm = get_coursemodule_from_instance('scorm', $scorm->id); $context = context_module::instance($cm->id); self::validate_context($context); // Check settings / permissions to view the SCORM. require_capability('mod/scorm:savetrack', $context); // Check settings / permissions to view the SCORM. scorm_require_available($scorm); foreach ($params['tracks'] as $track) { $element = $track['element']; $value = $track['value']; $trackid = scorm_insert_track($USER->id, $scorm->id, $sco->id, $params['attempt'], $element, $value, $scorm->forcecompleted); if ($trackid) { $trackids[] = $trackid; } else { $warnings[] = array( 'item' => 'scorm', 'itemid' => $scorm->id, 'warningcode' => 1, 'message' => 'Element: ' . $element . ' was not saved' ); } } $result = array(); $result['trackids'] = $trackids; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "insert_scorm_tracks", "(", "$", "scoid", ",", "$", "attempt", ",", "$", "tracks", ")", "{", "global", "$", "USER", ",", "$", "DB", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "insert_scorm_tracks_parameters", "(", ")", ",", "array", "(", "'scoid'", "=>", "$", "scoid", ",", "'attempt'", "=>", "$", "attempt", ",", "'tracks'", "=>", "$", "tracks", ")", ")", ";", "$", "trackids", "=", "array", "(", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "$", "sco", "=", "scorm_get_sco", "(", "$", "params", "[", "'scoid'", "]", ",", "SCO_ONLY", ")", ";", "if", "(", "!", "$", "sco", ")", "{", "throw", "new", "moodle_exception", "(", "'cannotfindsco'", ",", "'scorm'", ")", ";", "}", "$", "scorm", "=", "$", "DB", "->", "get_record", "(", "'scorm'", ",", "array", "(", "'id'", "=>", "$", "sco", "->", "scorm", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "$", "cm", "=", "get_coursemodule_from_instance", "(", "'scorm'", ",", "$", "scorm", "->", "id", ")", ";", "$", "context", "=", "context_module", "::", "instance", "(", "$", "cm", "->", "id", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "// Check settings / permissions to view the SCORM.", "require_capability", "(", "'mod/scorm:savetrack'", ",", "$", "context", ")", ";", "// Check settings / permissions to view the SCORM.", "scorm_require_available", "(", "$", "scorm", ")", ";", "foreach", "(", "$", "params", "[", "'tracks'", "]", "as", "$", "track", ")", "{", "$", "element", "=", "$", "track", "[", "'element'", "]", ";", "$", "value", "=", "$", "track", "[", "'value'", "]", ";", "$", "trackid", "=", "scorm_insert_track", "(", "$", "USER", "->", "id", ",", "$", "scorm", "->", "id", ",", "$", "sco", "->", "id", ",", "$", "params", "[", "'attempt'", "]", ",", "$", "element", ",", "$", "value", ",", "$", "scorm", "->", "forcecompleted", ")", ";", "if", "(", "$", "trackid", ")", "{", "$", "trackids", "[", "]", "=", "$", "trackid", ";", "}", "else", "{", "$", "warnings", "[", "]", "=", "array", "(", "'item'", "=>", "'scorm'", ",", "'itemid'", "=>", "$", "scorm", "->", "id", ",", "'warningcode'", "=>", "1", ",", "'message'", "=>", "'Element: '", ".", "$", "element", ".", "' was not saved'", ")", ";", "}", "}", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'trackids'", "]", "=", "$", "trackids", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Saves a SCORM tracking record. It will overwrite any existing tracking data for this attempt. Validation should be performed before running the function to ensure the user will not lose any existing attempt data. @param int $scoid the SCO id @param string $attempt the attempt number @param array $tracks the track records to be stored @return array warnings and the scoes data @throws moodle_exception @since Moodle 3.0
[ "Saves", "a", "SCORM", "tracking", "record", ".", "It", "will", "overwrite", "any", "existing", "tracking", "data", "for", "this", "attempt", ".", "Validation", "should", "be", "performed", "before", "running", "the", "function", "to", "ensure", "the", "user", "will", "not", "lose", "any", "existing", "attempt", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/scorm/classes/external.php#L451-L499
219,918
moodle/moodle
mod/scorm/classes/external.php
mod_scorm_external.get_scorm_sco_tracks
public static function get_scorm_sco_tracks($scoid, $userid, $attempt = 0) { global $USER, $DB; $params = self::validate_parameters(self::get_scorm_sco_tracks_parameters(), array('scoid' => $scoid, 'userid' => $userid, 'attempt' => $attempt)); $tracks = array(); $warnings = array(); $sco = scorm_get_sco($params['scoid'], SCO_ONLY); if (!$sco) { throw new moodle_exception('cannotfindsco', 'scorm'); } $scorm = $DB->get_record('scorm', array('id' => $sco->scorm), '*', MUST_EXIST); $cm = get_coursemodule_from_instance('scorm', $scorm->id); $context = context_module::instance($cm->id); self::validate_context($context); $user = core_user::get_user($params['userid'], '*', MUST_EXIST); core_user::require_active_user($user); // Extra checks so only users with permissions can view other users attempts. if ($USER->id != $user->id) { require_capability('mod/scorm:viewreport', $context); } scorm_require_available($scorm, true, $context); if (empty($params['attempt'])) { $params['attempt'] = scorm_get_last_attempt($scorm->id, $user->id); } $attempted = false; if ($scormtracks = scorm_get_tracks($sco->id, $params['userid'], $params['attempt'])) { // Check if attempted. if ($scormtracks->status != '') { $attempted = true; foreach ($scormtracks as $element => $value) { $tracks[] = array( 'element' => $element, 'value' => $value, ); } } } if (!$attempted) { $warnings[] = array( 'item' => 'attempt', 'itemid' => $params['attempt'], 'warningcode' => 'notattempted', 'message' => get_string('notattempted', 'scorm') ); } $result = array(); $result['data']['attempt'] = $params['attempt']; $result['data']['tracks'] = $tracks; $result['warnings'] = $warnings; return $result; }
php
public static function get_scorm_sco_tracks($scoid, $userid, $attempt = 0) { global $USER, $DB; $params = self::validate_parameters(self::get_scorm_sco_tracks_parameters(), array('scoid' => $scoid, 'userid' => $userid, 'attempt' => $attempt)); $tracks = array(); $warnings = array(); $sco = scorm_get_sco($params['scoid'], SCO_ONLY); if (!$sco) { throw new moodle_exception('cannotfindsco', 'scorm'); } $scorm = $DB->get_record('scorm', array('id' => $sco->scorm), '*', MUST_EXIST); $cm = get_coursemodule_from_instance('scorm', $scorm->id); $context = context_module::instance($cm->id); self::validate_context($context); $user = core_user::get_user($params['userid'], '*', MUST_EXIST); core_user::require_active_user($user); // Extra checks so only users with permissions can view other users attempts. if ($USER->id != $user->id) { require_capability('mod/scorm:viewreport', $context); } scorm_require_available($scorm, true, $context); if (empty($params['attempt'])) { $params['attempt'] = scorm_get_last_attempt($scorm->id, $user->id); } $attempted = false; if ($scormtracks = scorm_get_tracks($sco->id, $params['userid'], $params['attempt'])) { // Check if attempted. if ($scormtracks->status != '') { $attempted = true; foreach ($scormtracks as $element => $value) { $tracks[] = array( 'element' => $element, 'value' => $value, ); } } } if (!$attempted) { $warnings[] = array( 'item' => 'attempt', 'itemid' => $params['attempt'], 'warningcode' => 'notattempted', 'message' => get_string('notattempted', 'scorm') ); } $result = array(); $result['data']['attempt'] = $params['attempt']; $result['data']['tracks'] = $tracks; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "get_scorm_sco_tracks", "(", "$", "scoid", ",", "$", "userid", ",", "$", "attempt", "=", "0", ")", "{", "global", "$", "USER", ",", "$", "DB", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_scorm_sco_tracks_parameters", "(", ")", ",", "array", "(", "'scoid'", "=>", "$", "scoid", ",", "'userid'", "=>", "$", "userid", ",", "'attempt'", "=>", "$", "attempt", ")", ")", ";", "$", "tracks", "=", "array", "(", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "$", "sco", "=", "scorm_get_sco", "(", "$", "params", "[", "'scoid'", "]", ",", "SCO_ONLY", ")", ";", "if", "(", "!", "$", "sco", ")", "{", "throw", "new", "moodle_exception", "(", "'cannotfindsco'", ",", "'scorm'", ")", ";", "}", "$", "scorm", "=", "$", "DB", "->", "get_record", "(", "'scorm'", ",", "array", "(", "'id'", "=>", "$", "sco", "->", "scorm", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "$", "cm", "=", "get_coursemodule_from_instance", "(", "'scorm'", ",", "$", "scorm", "->", "id", ")", ";", "$", "context", "=", "context_module", "::", "instance", "(", "$", "cm", "->", "id", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "user", "=", "core_user", "::", "get_user", "(", "$", "params", "[", "'userid'", "]", ",", "'*'", ",", "MUST_EXIST", ")", ";", "core_user", "::", "require_active_user", "(", "$", "user", ")", ";", "// Extra checks so only users with permissions can view other users attempts.", "if", "(", "$", "USER", "->", "id", "!=", "$", "user", "->", "id", ")", "{", "require_capability", "(", "'mod/scorm:viewreport'", ",", "$", "context", ")", ";", "}", "scorm_require_available", "(", "$", "scorm", ",", "true", ",", "$", "context", ")", ";", "if", "(", "empty", "(", "$", "params", "[", "'attempt'", "]", ")", ")", "{", "$", "params", "[", "'attempt'", "]", "=", "scorm_get_last_attempt", "(", "$", "scorm", "->", "id", ",", "$", "user", "->", "id", ")", ";", "}", "$", "attempted", "=", "false", ";", "if", "(", "$", "scormtracks", "=", "scorm_get_tracks", "(", "$", "sco", "->", "id", ",", "$", "params", "[", "'userid'", "]", ",", "$", "params", "[", "'attempt'", "]", ")", ")", "{", "// Check if attempted.", "if", "(", "$", "scormtracks", "->", "status", "!=", "''", ")", "{", "$", "attempted", "=", "true", ";", "foreach", "(", "$", "scormtracks", "as", "$", "element", "=>", "$", "value", ")", "{", "$", "tracks", "[", "]", "=", "array", "(", "'element'", "=>", "$", "element", ",", "'value'", "=>", "$", "value", ",", ")", ";", "}", "}", "}", "if", "(", "!", "$", "attempted", ")", "{", "$", "warnings", "[", "]", "=", "array", "(", "'item'", "=>", "'attempt'", ",", "'itemid'", "=>", "$", "params", "[", "'attempt'", "]", ",", "'warningcode'", "=>", "'notattempted'", ",", "'message'", "=>", "get_string", "(", "'notattempted'", ",", "'scorm'", ")", ")", ";", "}", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'data'", "]", "[", "'attempt'", "]", "=", "$", "params", "[", "'attempt'", "]", ";", "$", "result", "[", "'data'", "]", "[", "'tracks'", "]", "=", "$", "tracks", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Retrieves SCO tracking data for the given user id and attempt number @param int $scoid the sco id @param int $userid the user id @param int $attempt the attempt number @return array warnings and the scoes data @since Moodle 3.0
[ "Retrieves", "SCO", "tracking", "data", "for", "the", "given", "user", "id", "and", "attempt", "number" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/scorm/classes/external.php#L542-L604
219,919
moodle/moodle
mod/scorm/classes/external.php
mod_scorm_external.get_scorm_sco_tracks_returns
public static function get_scorm_sco_tracks_returns() { return new external_single_structure( array( 'data' => new external_single_structure( array( 'attempt' => new external_value(PARAM_INT, 'Attempt number'), 'tracks' => new external_multiple_structure( new external_single_structure( array( 'element' => new external_value(PARAM_RAW, 'Element name'), 'value' => new external_value(PARAM_RAW, 'Element value') ), 'Tracks data' ) ), ), 'SCO data' ), 'warnings' => new external_warnings(), ) ); }
php
public static function get_scorm_sco_tracks_returns() { return new external_single_structure( array( 'data' => new external_single_structure( array( 'attempt' => new external_value(PARAM_INT, 'Attempt number'), 'tracks' => new external_multiple_structure( new external_single_structure( array( 'element' => new external_value(PARAM_RAW, 'Element name'), 'value' => new external_value(PARAM_RAW, 'Element value') ), 'Tracks data' ) ), ), 'SCO data' ), 'warnings' => new external_warnings(), ) ); }
[ "public", "static", "function", "get_scorm_sco_tracks_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'data'", "=>", "new", "external_single_structure", "(", "array", "(", "'attempt'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Attempt number'", ")", ",", "'tracks'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'element'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Element name'", ")", ",", "'value'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Element value'", ")", ")", ",", "'Tracks data'", ")", ")", ",", ")", ",", "'SCO data'", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ",", ")", ")", ";", "}" ]
Describes the get_scorm_sco_tracks return value. @return external_single_structure @since Moodle 3.0
[ "Describes", "the", "get_scorm_sco_tracks", "return", "value", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/scorm/classes/external.php#L612-L632
219,920
moodle/moodle
mod/scorm/classes/external.php
mod_scorm_external.get_scorm_access_information
public static function get_scorm_access_information($scormid) { global $DB; $params = self::validate_parameters(self::get_scorm_access_information_parameters(), array('scormid' => $scormid)); // Request and permission validation. $scorm = $DB->get_record('scorm', array('id' => $params['scormid']), '*', MUST_EXIST); list($course, $cm) = get_course_and_cm_from_instance($scorm, 'scorm'); $context = context_module::instance($cm->id); self::validate_context($context); $result = array(); // Return all the available capabilities. $capabilities = load_capability_def('mod_scorm'); foreach ($capabilities as $capname => $capdata) { // Get fields like cansubmit so it is consistent with the access_information function implemented in other modules. $field = 'can' . str_replace('mod/scorm:', '', $capname); $result[$field] = has_capability($capname, $context); } $result['warnings'] = array(); return $result; }
php
public static function get_scorm_access_information($scormid) { global $DB; $params = self::validate_parameters(self::get_scorm_access_information_parameters(), array('scormid' => $scormid)); // Request and permission validation. $scorm = $DB->get_record('scorm', array('id' => $params['scormid']), '*', MUST_EXIST); list($course, $cm) = get_course_and_cm_from_instance($scorm, 'scorm'); $context = context_module::instance($cm->id); self::validate_context($context); $result = array(); // Return all the available capabilities. $capabilities = load_capability_def('mod_scorm'); foreach ($capabilities as $capname => $capdata) { // Get fields like cansubmit so it is consistent with the access_information function implemented in other modules. $field = 'can' . str_replace('mod/scorm:', '', $capname); $result[$field] = has_capability($capname, $context); } $result['warnings'] = array(); return $result; }
[ "public", "static", "function", "get_scorm_access_information", "(", "$", "scormid", ")", "{", "global", "$", "DB", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_scorm_access_information_parameters", "(", ")", ",", "array", "(", "'scormid'", "=>", "$", "scormid", ")", ")", ";", "// Request and permission validation.", "$", "scorm", "=", "$", "DB", "->", "get_record", "(", "'scorm'", ",", "array", "(", "'id'", "=>", "$", "params", "[", "'scormid'", "]", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "list", "(", "$", "course", ",", "$", "cm", ")", "=", "get_course_and_cm_from_instance", "(", "$", "scorm", ",", "'scorm'", ")", ";", "$", "context", "=", "context_module", "::", "instance", "(", "$", "cm", "->", "id", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "result", "=", "array", "(", ")", ";", "// Return all the available capabilities.", "$", "capabilities", "=", "load_capability_def", "(", "'mod_scorm'", ")", ";", "foreach", "(", "$", "capabilities", "as", "$", "capname", "=>", "$", "capdata", ")", "{", "// Get fields like cansubmit so it is consistent with the access_information function implemented in other modules.", "$", "field", "=", "'can'", ".", "str_replace", "(", "'mod/scorm:'", ",", "''", ",", "$", "capname", ")", ";", "$", "result", "[", "$", "field", "]", "=", "has_capability", "(", "$", "capname", ",", "$", "context", ")", ";", "}", "$", "result", "[", "'warnings'", "]", "=", "array", "(", ")", ";", "return", "$", "result", ";", "}" ]
Return access information for a given scorm. @param int $scormid scorm instance id @return array of warnings and the access information @since Moodle 3.7 @throws moodle_exception
[ "Return", "access", "information", "for", "a", "given", "scorm", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/scorm/classes/external.php#L932-L955
219,921
moodle/moodle
admin/tool/lpmigrate/classes/framework_mapper.php
framework_mapper.automap
public function automap() { $map = array(); // Shallow copy. $collectionfrom = $this->get_collection_from(); $collectionto = $this->get_collection_to(); // Find mappings. foreach ($collectionfrom as $keyfrom => $compfrom) { foreach ($collectionto as $keyto => $compto) { if ($compfrom->get('idnumber') == $compto->get('idnumber')) { $map[$compfrom->get('id')] = $compto->get('id'); unset($collectionfrom[$keyfrom]); unset($collectionto[$keyto]); break; } } } $this->mappings = $map; }
php
public function automap() { $map = array(); // Shallow copy. $collectionfrom = $this->get_collection_from(); $collectionto = $this->get_collection_to(); // Find mappings. foreach ($collectionfrom as $keyfrom => $compfrom) { foreach ($collectionto as $keyto => $compto) { if ($compfrom->get('idnumber') == $compto->get('idnumber')) { $map[$compfrom->get('id')] = $compto->get('id'); unset($collectionfrom[$keyfrom]); unset($collectionto[$keyto]); break; } } } $this->mappings = $map; }
[ "public", "function", "automap", "(", ")", "{", "$", "map", "=", "array", "(", ")", ";", "// Shallow copy.", "$", "collectionfrom", "=", "$", "this", "->", "get_collection_from", "(", ")", ";", "$", "collectionto", "=", "$", "this", "->", "get_collection_to", "(", ")", ";", "// Find mappings.", "foreach", "(", "$", "collectionfrom", "as", "$", "keyfrom", "=>", "$", "compfrom", ")", "{", "foreach", "(", "$", "collectionto", "as", "$", "keyto", "=>", "$", "compto", ")", "{", "if", "(", "$", "compfrom", "->", "get", "(", "'idnumber'", ")", "==", "$", "compto", "->", "get", "(", "'idnumber'", ")", ")", "{", "$", "map", "[", "$", "compfrom", "->", "get", "(", "'id'", ")", "]", "=", "$", "compto", "->", "get", "(", "'id'", ")", ";", "unset", "(", "$", "collectionfrom", "[", "$", "keyfrom", "]", ")", ";", "unset", "(", "$", "collectionto", "[", "$", "keyto", "]", ")", ";", "break", ";", "}", "}", "}", "$", "this", "->", "mappings", "=", "$", "map", ";", "}" ]
Auto map the frameworks. @return void
[ "Auto", "map", "the", "frameworks", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lpmigrate/classes/framework_mapper.php#L73-L93
219,922
moodle/moodle
admin/tool/lpmigrate/classes/framework_mapper.php
framework_mapper.get_collection_from
protected function get_collection_from() { if ($this->collectionfrom === null) { $this->collectionfrom = api::search_competencies('', $this->from); } return $this->collectionfrom; }
php
protected function get_collection_from() { if ($this->collectionfrom === null) { $this->collectionfrom = api::search_competencies('', $this->from); } return $this->collectionfrom; }
[ "protected", "function", "get_collection_from", "(", ")", "{", "if", "(", "$", "this", "->", "collectionfrom", "===", "null", ")", "{", "$", "this", "->", "collectionfrom", "=", "api", "::", "search_competencies", "(", "''", ",", "$", "this", "->", "from", ")", ";", "}", "return", "$", "this", "->", "collectionfrom", ";", "}" ]
Get the collection at origin. @return array
[ "Get", "the", "collection", "at", "origin", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lpmigrate/classes/framework_mapper.php#L115-L120
219,923
moodle/moodle
admin/tool/lpmigrate/classes/framework_mapper.php
framework_mapper.get_collection_to
protected function get_collection_to() { if ($this->collectionto === null) { $this->collectionto = api::search_competencies('', $this->to); } return $this->collectionto; }
php
protected function get_collection_to() { if ($this->collectionto === null) { $this->collectionto = api::search_competencies('', $this->to); } return $this->collectionto; }
[ "protected", "function", "get_collection_to", "(", ")", "{", "if", "(", "$", "this", "->", "collectionto", "===", "null", ")", "{", "$", "this", "->", "collectionto", "=", "api", "::", "search_competencies", "(", "''", ",", "$", "this", "->", "to", ")", ";", "}", "return", "$", "this", "->", "collectionto", ";", "}" ]
Get the collection at destination. @return array
[ "Get", "the", "collection", "at", "destination", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/lpmigrate/classes/framework_mapper.php#L126-L131
219,924
moodle/moodle
lib/mustache/src/Mustache/Loader/InlineLoader.php
Mustache_Loader_InlineLoader.loadTemplates
protected function loadTemplates() { if ($this->templates === null) { $this->templates = array(); $data = file_get_contents($this->fileName, false, null, $this->offset); foreach (preg_split("/^@@(?= [\w\d\.]+$)/m", $data, -1) as $chunk) { if (trim($chunk)) { list($name, $content) = explode("\n", $chunk, 2); $this->templates[trim($name)] = trim($content); } } } }
php
protected function loadTemplates() { if ($this->templates === null) { $this->templates = array(); $data = file_get_contents($this->fileName, false, null, $this->offset); foreach (preg_split("/^@@(?= [\w\d\.]+$)/m", $data, -1) as $chunk) { if (trim($chunk)) { list($name, $content) = explode("\n", $chunk, 2); $this->templates[trim($name)] = trim($content); } } } }
[ "protected", "function", "loadTemplates", "(", ")", "{", "if", "(", "$", "this", "->", "templates", "===", "null", ")", "{", "$", "this", "->", "templates", "=", "array", "(", ")", ";", "$", "data", "=", "file_get_contents", "(", "$", "this", "->", "fileName", ",", "false", ",", "null", ",", "$", "this", "->", "offset", ")", ";", "foreach", "(", "preg_split", "(", "\"/^@@(?= [\\w\\d\\.]+$)/m\"", ",", "$", "data", ",", "-", "1", ")", "as", "$", "chunk", ")", "{", "if", "(", "trim", "(", "$", "chunk", ")", ")", "{", "list", "(", "$", "name", ",", "$", "content", ")", "=", "explode", "(", "\"\\n\"", ",", "$", "chunk", ",", "2", ")", ";", "$", "this", "->", "templates", "[", "trim", "(", "$", "name", ")", "]", "=", "trim", "(", "$", "content", ")", ";", "}", "}", "}", "}" ]
Parse and load templates from the end of a source file.
[ "Parse", "and", "load", "templates", "from", "the", "end", "of", "a", "source", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/mustache/src/Mustache/Loader/InlineLoader.php#L110-L122
219,925
moodle/moodle
auth/shibboleth/classes/helper.php
helper.logout_file_session
public static function logout_file_session($spsessionid) { global $CFG; if (!empty($CFG->session_file_save_path)) { $dir = $CFG->session_file_save_path; } else { $dir = $CFG->dataroot . '/sessions'; } if (is_dir($dir)) { if ($dh = opendir($dir)) { // Read all session files. while (($file = readdir($dh)) !== false) { // Check if it is a file. if (is_file($dir.'/'.$file)) { // Read session file data. $data = file($dir.'/'.$file); if (isset($data[0])) { $usersession = self::unserializesession($data[0]); // Check if we have found session that shall be deleted. if (isset($usersession['SESSION']) && isset($usersession['SESSION']->shibboleth_session_id)) { // If there is a match, delete file. if ($usersession['SESSION']->shibboleth_session_id == $spsessionid) { // Delete session file. if (!unlink($dir.'/'.$file)) { return new SoapFault('LogoutError', 'Could not delete Moodle session file.'); } } } } } } closedir($dh); } } }
php
public static function logout_file_session($spsessionid) { global $CFG; if (!empty($CFG->session_file_save_path)) { $dir = $CFG->session_file_save_path; } else { $dir = $CFG->dataroot . '/sessions'; } if (is_dir($dir)) { if ($dh = opendir($dir)) { // Read all session files. while (($file = readdir($dh)) !== false) { // Check if it is a file. if (is_file($dir.'/'.$file)) { // Read session file data. $data = file($dir.'/'.$file); if (isset($data[0])) { $usersession = self::unserializesession($data[0]); // Check if we have found session that shall be deleted. if (isset($usersession['SESSION']) && isset($usersession['SESSION']->shibboleth_session_id)) { // If there is a match, delete file. if ($usersession['SESSION']->shibboleth_session_id == $spsessionid) { // Delete session file. if (!unlink($dir.'/'.$file)) { return new SoapFault('LogoutError', 'Could not delete Moodle session file.'); } } } } } } closedir($dh); } } }
[ "public", "static", "function", "logout_file_session", "(", "$", "spsessionid", ")", "{", "global", "$", "CFG", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "session_file_save_path", ")", ")", "{", "$", "dir", "=", "$", "CFG", "->", "session_file_save_path", ";", "}", "else", "{", "$", "dir", "=", "$", "CFG", "->", "dataroot", ".", "'/sessions'", ";", "}", "if", "(", "is_dir", "(", "$", "dir", ")", ")", "{", "if", "(", "$", "dh", "=", "opendir", "(", "$", "dir", ")", ")", "{", "// Read all session files.", "while", "(", "(", "$", "file", "=", "readdir", "(", "$", "dh", ")", ")", "!==", "false", ")", "{", "// Check if it is a file.", "if", "(", "is_file", "(", "$", "dir", ".", "'/'", ".", "$", "file", ")", ")", "{", "// Read session file data.", "$", "data", "=", "file", "(", "$", "dir", ".", "'/'", ".", "$", "file", ")", ";", "if", "(", "isset", "(", "$", "data", "[", "0", "]", ")", ")", "{", "$", "usersession", "=", "self", "::", "unserializesession", "(", "$", "data", "[", "0", "]", ")", ";", "// Check if we have found session that shall be deleted.", "if", "(", "isset", "(", "$", "usersession", "[", "'SESSION'", "]", ")", "&&", "isset", "(", "$", "usersession", "[", "'SESSION'", "]", "->", "shibboleth_session_id", ")", ")", "{", "// If there is a match, delete file.", "if", "(", "$", "usersession", "[", "'SESSION'", "]", "->", "shibboleth_session_id", "==", "$", "spsessionid", ")", "{", "// Delete session file.", "if", "(", "!", "unlink", "(", "$", "dir", ".", "'/'", ".", "$", "file", ")", ")", "{", "return", "new", "SoapFault", "(", "'LogoutError'", ",", "'Could not delete Moodle session file.'", ")", ";", "}", "}", "}", "}", "}", "}", "closedir", "(", "$", "dh", ")", ";", "}", "}", "}" ]
Delete session of user using file sessions. @param string $spsessionid SP-provided Shibboleth Session ID @return \SoapFault or void if everything was fine
[ "Delete", "session", "of", "user", "using", "file", "sessions", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/shibboleth/classes/helper.php#L44-L79
219,926
moodle/moodle
auth/shibboleth/classes/helper.php
helper.logout_db_session
public static function logout_db_session($spsessionid) { global $CFG, $DB; $sessions = $DB->get_records_sql( 'SELECT userid, sessdata FROM {sessions} WHERE timemodified > ?', array(time() - $CFG->sessiontimeout) ); foreach ($sessions as $session) { // Get user session from DB. if (session_decode(base64_decode($session->sessdata))) { if (isset($_SESSION['SESSION']) && isset($_SESSION['SESSION']->shibboleth_session_id)) { // If there is a match, kill the session. if ($_SESSION['SESSION']->shibboleth_session_id == trim($spsessionid)) { // Delete this user's sessions. \core\session\manager::kill_user_sessions($session->userid); } } } } }
php
public static function logout_db_session($spsessionid) { global $CFG, $DB; $sessions = $DB->get_records_sql( 'SELECT userid, sessdata FROM {sessions} WHERE timemodified > ?', array(time() - $CFG->sessiontimeout) ); foreach ($sessions as $session) { // Get user session from DB. if (session_decode(base64_decode($session->sessdata))) { if (isset($_SESSION['SESSION']) && isset($_SESSION['SESSION']->shibboleth_session_id)) { // If there is a match, kill the session. if ($_SESSION['SESSION']->shibboleth_session_id == trim($spsessionid)) { // Delete this user's sessions. \core\session\manager::kill_user_sessions($session->userid); } } } } }
[ "public", "static", "function", "logout_db_session", "(", "$", "spsessionid", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "$", "sessions", "=", "$", "DB", "->", "get_records_sql", "(", "'SELECT userid, sessdata FROM {sessions} WHERE timemodified > ?'", ",", "array", "(", "time", "(", ")", "-", "$", "CFG", "->", "sessiontimeout", ")", ")", ";", "foreach", "(", "$", "sessions", "as", "$", "session", ")", "{", "// Get user session from DB.", "if", "(", "session_decode", "(", "base64_decode", "(", "$", "session", "->", "sessdata", ")", ")", ")", "{", "if", "(", "isset", "(", "$", "_SESSION", "[", "'SESSION'", "]", ")", "&&", "isset", "(", "$", "_SESSION", "[", "'SESSION'", "]", "->", "shibboleth_session_id", ")", ")", "{", "// If there is a match, kill the session.", "if", "(", "$", "_SESSION", "[", "'SESSION'", "]", "->", "shibboleth_session_id", "==", "trim", "(", "$", "spsessionid", ")", ")", "{", "// Delete this user's sessions.", "\\", "core", "\\", "session", "\\", "manager", "::", "kill_user_sessions", "(", "$", "session", "->", "userid", ")", ";", "}", "}", "}", "}", "}" ]
Delete session of user using DB sessions. @param string $spsessionid SP-provided Shibboleth Session ID
[ "Delete", "session", "of", "user", "using", "DB", "sessions", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/shibboleth/classes/helper.php#L86-L106
219,927
moodle/moodle
auth/shibboleth/classes/helper.php
helper.unserializesession
private static function unserializesession($serializedstring) { $variables = array(); $a = preg_split("/(\w+)\|/", $serializedstring, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); $counta = count($a); for ($i = 0; $i < $counta; $i = $i + 2) { $variables[$a[$i]] = unserialize($a[$i + 1]); } return $variables; }
php
private static function unserializesession($serializedstring) { $variables = array(); $a = preg_split("/(\w+)\|/", $serializedstring, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); $counta = count($a); for ($i = 0; $i < $counta; $i = $i + 2) { $variables[$a[$i]] = unserialize($a[$i + 1]); } return $variables; }
[ "private", "static", "function", "unserializesession", "(", "$", "serializedstring", ")", "{", "$", "variables", "=", "array", "(", ")", ";", "$", "a", "=", "preg_split", "(", "\"/(\\w+)\\|/\"", ",", "$", "serializedstring", ",", "-", "1", ",", "PREG_SPLIT_NO_EMPTY", "|", "PREG_SPLIT_DELIM_CAPTURE", ")", ";", "$", "counta", "=", "count", "(", "$", "a", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "counta", ";", "$", "i", "=", "$", "i", "+", "2", ")", "{", "$", "variables", "[", "$", "a", "[", "$", "i", "]", "]", "=", "unserialize", "(", "$", "a", "[", "$", "i", "+", "1", "]", ")", ";", "}", "return", "$", "variables", ";", "}" ]
Unserialize a session string. @param string $serializedstring @return array
[ "Unserialize", "a", "session", "string", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/auth/shibboleth/classes/helper.php#L114-L122
219,928
moodle/moodle
backup/util/xml/output/xml_output.class.php
xml_output.write
public function write($content) { if (!$this->running) { throw new xml_output_exception('xml_output_not_started'); } $lenc = strlen($content); // Get length in bytes if ($lenc == 0) { // 0 length contents, nothing to do return; } // Buffer handling if available $tooutput = true; // By default, perform output if ($this->usebuffer) { // Buffer $this->currentbuffer .= $content; $this->currentbuffersize += $lenc; if ($this->currentbuffersize < $this->buffersize) { $tooutput = false; // Still within the buffer, don't output } else { $content = $this->currentbuffer; // Prepare for output $lenc = $this->currentbuffersize; $this->currentbuffer = ''; $this->currentbuffersize = 0; } } // Output if ($tooutput) { $this->send($content); // Efectively send the contents $this->sentbytes += $lenc; } }
php
public function write($content) { if (!$this->running) { throw new xml_output_exception('xml_output_not_started'); } $lenc = strlen($content); // Get length in bytes if ($lenc == 0) { // 0 length contents, nothing to do return; } // Buffer handling if available $tooutput = true; // By default, perform output if ($this->usebuffer) { // Buffer $this->currentbuffer .= $content; $this->currentbuffersize += $lenc; if ($this->currentbuffersize < $this->buffersize) { $tooutput = false; // Still within the buffer, don't output } else { $content = $this->currentbuffer; // Prepare for output $lenc = $this->currentbuffersize; $this->currentbuffer = ''; $this->currentbuffersize = 0; } } // Output if ($tooutput) { $this->send($content); // Efectively send the contents $this->sentbytes += $lenc; } }
[ "public", "function", "write", "(", "$", "content", ")", "{", "if", "(", "!", "$", "this", "->", "running", ")", "{", "throw", "new", "xml_output_exception", "(", "'xml_output_not_started'", ")", ";", "}", "$", "lenc", "=", "strlen", "(", "$", "content", ")", ";", "// Get length in bytes", "if", "(", "$", "lenc", "==", "0", ")", "{", "// 0 length contents, nothing to do", "return", ";", "}", "// Buffer handling if available", "$", "tooutput", "=", "true", ";", "// By default, perform output", "if", "(", "$", "this", "->", "usebuffer", ")", "{", "// Buffer", "$", "this", "->", "currentbuffer", ".=", "$", "content", ";", "$", "this", "->", "currentbuffersize", "+=", "$", "lenc", ";", "if", "(", "$", "this", "->", "currentbuffersize", "<", "$", "this", "->", "buffersize", ")", "{", "$", "tooutput", "=", "false", ";", "// Still within the buffer, don't output", "}", "else", "{", "$", "content", "=", "$", "this", "->", "currentbuffer", ";", "// Prepare for output", "$", "lenc", "=", "$", "this", "->", "currentbuffersize", ";", "$", "this", "->", "currentbuffer", "=", "''", ";", "$", "this", "->", "currentbuffersize", "=", "0", ";", "}", "}", "// Output", "if", "(", "$", "tooutput", ")", "{", "$", "this", "->", "send", "(", "$", "content", ")", ";", "// Efectively send the contents", "$", "this", "->", "sentbytes", "+=", "$", "lenc", ";", "}", "}" ]
Get contents from @xml_writer and buffer/output them
[ "Get", "contents", "from" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/xml/output/xml_output.class.php#L106-L133
219,929
moodle/moodle
repository/googledocs/lib.php
repository_googledocs.search
public function search($searchtext, $page = 0) { $path = $this->build_node_path('root', get_string('pluginname', 'repository_googledocs')); $str = get_string('searchfor', 'repository_googledocs', $searchtext); $path = $this->build_node_path('search', $str, $path); // Query the Drive. $q = "fullText contains '" . str_replace("'", "\'", $searchtext) . "'"; $q .= ' AND trashed = false'; $results = $this->query($q, $path); $ret = array(); $ret['dynload'] = true; $ret['path'] = $this->build_breadcrumb($path); $ret['list'] = $results; $ret['manage'] = 'https://drive.google.com/'; return $ret; }
php
public function search($searchtext, $page = 0) { $path = $this->build_node_path('root', get_string('pluginname', 'repository_googledocs')); $str = get_string('searchfor', 'repository_googledocs', $searchtext); $path = $this->build_node_path('search', $str, $path); // Query the Drive. $q = "fullText contains '" . str_replace("'", "\'", $searchtext) . "'"; $q .= ' AND trashed = false'; $results = $this->query($q, $path); $ret = array(); $ret['dynload'] = true; $ret['path'] = $this->build_breadcrumb($path); $ret['list'] = $results; $ret['manage'] = 'https://drive.google.com/'; return $ret; }
[ "public", "function", "search", "(", "$", "searchtext", ",", "$", "page", "=", "0", ")", "{", "$", "path", "=", "$", "this", "->", "build_node_path", "(", "'root'", ",", "get_string", "(", "'pluginname'", ",", "'repository_googledocs'", ")", ")", ";", "$", "str", "=", "get_string", "(", "'searchfor'", ",", "'repository_googledocs'", ",", "$", "searchtext", ")", ";", "$", "path", "=", "$", "this", "->", "build_node_path", "(", "'search'", ",", "$", "str", ",", "$", "path", ")", ";", "// Query the Drive.", "$", "q", "=", "\"fullText contains '\"", ".", "str_replace", "(", "\"'\"", ",", "\"\\'\"", ",", "$", "searchtext", ")", ".", "\"'\"", ";", "$", "q", ".=", "' AND trashed = false'", ";", "$", "results", "=", "$", "this", "->", "query", "(", "$", "q", ",", "$", "path", ")", ";", "$", "ret", "=", "array", "(", ")", ";", "$", "ret", "[", "'dynload'", "]", "=", "true", ";", "$", "ret", "[", "'path'", "]", "=", "$", "this", "->", "build_breadcrumb", "(", "$", "path", ")", ";", "$", "ret", "[", "'list'", "]", "=", "$", "results", ";", "$", "ret", "[", "'manage'", "]", "=", "'https://drive.google.com/'", ";", "return", "$", "ret", ";", "}" ]
Search throughout the Google Drive. @param string $searchtext text to search for. @param int $page search page. @return array of results.
[ "Search", "throughout", "the", "Google", "Drive", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/googledocs/lib.php#L278-L294
219,930
moodle/moodle
repository/googledocs/lib.php
repository_googledocs.supported_returntypes
public function supported_returntypes() { // We can only support references if the system account is connected. if (!empty($this->issuer) && $this->issuer->is_system_account_connected()) { $setting = get_config('googledocs', 'supportedreturntypes'); if ($setting == 'internal') { return FILE_INTERNAL; } else if ($setting == 'external') { return FILE_CONTROLLED_LINK; } else { return FILE_CONTROLLED_LINK | FILE_INTERNAL; } } else { return FILE_INTERNAL; } }
php
public function supported_returntypes() { // We can only support references if the system account is connected. if (!empty($this->issuer) && $this->issuer->is_system_account_connected()) { $setting = get_config('googledocs', 'supportedreturntypes'); if ($setting == 'internal') { return FILE_INTERNAL; } else if ($setting == 'external') { return FILE_CONTROLLED_LINK; } else { return FILE_CONTROLLED_LINK | FILE_INTERNAL; } } else { return FILE_INTERNAL; } }
[ "public", "function", "supported_returntypes", "(", ")", "{", "// We can only support references if the system account is connected.", "if", "(", "!", "empty", "(", "$", "this", "->", "issuer", ")", "&&", "$", "this", "->", "issuer", "->", "is_system_account_connected", "(", ")", ")", "{", "$", "setting", "=", "get_config", "(", "'googledocs'", ",", "'supportedreturntypes'", ")", ";", "if", "(", "$", "setting", "==", "'internal'", ")", "{", "return", "FILE_INTERNAL", ";", "}", "else", "if", "(", "$", "setting", "==", "'external'", ")", "{", "return", "FILE_CONTROLLED_LINK", ";", "}", "else", "{", "return", "FILE_CONTROLLED_LINK", "|", "FILE_INTERNAL", ";", "}", "}", "else", "{", "return", "FILE_INTERNAL", ";", "}", "}" ]
Tells how the file can be picked from this repository. @return int
[ "Tells", "how", "the", "file", "can", "be", "picked", "from", "this", "repository", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/googledocs/lib.php#L544-L558
219,931
moodle/moodle
repository/googledocs/lib.php
repository_googledocs.copy_file
protected function copy_file(\repository_googledocs\rest $client, $fileid, $name) { $fields = "id,name,mimeType,webContentLink,webViewLink,size,thumbnailLink,iconLink"; $params = [ 'fileid' => $fileid, 'fields' => $fields, ]; // Keep the original name (don't put copy at the end of it). $copyinfo = []; if (!empty($name)) { $copyinfo = [ 'name' => $name ]; } $fileinfo = $client->call('copy', $params, json_encode($copyinfo)); if (empty($fileinfo->id)) { $details = 'Cannot copy file:' . $fileid; throw new repository_exception('errorwhilecommunicatingwith', 'repository', '', $details); } return $fileinfo; }
php
protected function copy_file(\repository_googledocs\rest $client, $fileid, $name) { $fields = "id,name,mimeType,webContentLink,webViewLink,size,thumbnailLink,iconLink"; $params = [ 'fileid' => $fileid, 'fields' => $fields, ]; // Keep the original name (don't put copy at the end of it). $copyinfo = []; if (!empty($name)) { $copyinfo = [ 'name' => $name ]; } $fileinfo = $client->call('copy', $params, json_encode($copyinfo)); if (empty($fileinfo->id)) { $details = 'Cannot copy file:' . $fileid; throw new repository_exception('errorwhilecommunicatingwith', 'repository', '', $details); } return $fileinfo; }
[ "protected", "function", "copy_file", "(", "\\", "repository_googledocs", "\\", "rest", "$", "client", ",", "$", "fileid", ",", "$", "name", ")", "{", "$", "fields", "=", "\"id,name,mimeType,webContentLink,webViewLink,size,thumbnailLink,iconLink\"", ";", "$", "params", "=", "[", "'fileid'", "=>", "$", "fileid", ",", "'fields'", "=>", "$", "fields", ",", "]", ";", "// Keep the original name (don't put copy at the end of it).", "$", "copyinfo", "=", "[", "]", ";", "if", "(", "!", "empty", "(", "$", "name", ")", ")", "{", "$", "copyinfo", "=", "[", "'name'", "=>", "$", "name", "]", ";", "}", "$", "fileinfo", "=", "$", "client", "->", "call", "(", "'copy'", ",", "$", "params", ",", "json_encode", "(", "$", "copyinfo", ")", ")", ";", "if", "(", "empty", "(", "$", "fileinfo", "->", "id", ")", ")", "{", "$", "details", "=", "'Cannot copy file:'", ".", "$", "fileid", ";", "throw", "new", "repository_exception", "(", "'errorwhilecommunicatingwith'", ",", "'repository'", ",", "''", ",", "$", "details", ")", ";", "}", "return", "$", "fileinfo", ";", "}" ]
Copy a file and return the new file details. A side effect of the copy is that the owner will be the account authenticated with this oauth client. @param \repository_googledocs\rest $client Authenticated client. @param string $fileid The file we are copying. @param string $name The original filename (don't change it). @return stdClass file details.
[ "Copy", "a", "file", "and", "return", "the", "new", "file", "details", ".", "A", "side", "effect", "of", "the", "copy", "is", "that", "the", "owner", "will", "be", "the", "account", "authenticated", "with", "this", "oauth", "client", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/googledocs/lib.php#L751-L768
219,932
moodle/moodle
repository/googledocs/lib.php
repository_googledocs.add_writer_to_file
protected function add_writer_to_file(\repository_googledocs\rest $client, $fileid, $email) { $updateeditor = [ 'emailAddress' => $email, 'role' => 'writer', 'type' => 'user' ]; $params = ['fileid' => $fileid, 'sendNotificationEmail' => 'false']; $response = $client->call('create_permission', $params, json_encode($updateeditor)); if (empty($response->id)) { $details = 'Cannot add user ' . $email . ' as a writer for document: ' . $fileid; throw new repository_exception('errorwhilecommunicatingwith', 'repository', '', $details); } return true; }
php
protected function add_writer_to_file(\repository_googledocs\rest $client, $fileid, $email) { $updateeditor = [ 'emailAddress' => $email, 'role' => 'writer', 'type' => 'user' ]; $params = ['fileid' => $fileid, 'sendNotificationEmail' => 'false']; $response = $client->call('create_permission', $params, json_encode($updateeditor)); if (empty($response->id)) { $details = 'Cannot add user ' . $email . ' as a writer for document: ' . $fileid; throw new repository_exception('errorwhilecommunicatingwith', 'repository', '', $details); } return true; }
[ "protected", "function", "add_writer_to_file", "(", "\\", "repository_googledocs", "\\", "rest", "$", "client", ",", "$", "fileid", ",", "$", "email", ")", "{", "$", "updateeditor", "=", "[", "'emailAddress'", "=>", "$", "email", ",", "'role'", "=>", "'writer'", ",", "'type'", "=>", "'user'", "]", ";", "$", "params", "=", "[", "'fileid'", "=>", "$", "fileid", ",", "'sendNotificationEmail'", "=>", "'false'", "]", ";", "$", "response", "=", "$", "client", "->", "call", "(", "'create_permission'", ",", "$", "params", ",", "json_encode", "(", "$", "updateeditor", ")", ")", ";", "if", "(", "empty", "(", "$", "response", "->", "id", ")", ")", "{", "$", "details", "=", "'Cannot add user '", ".", "$", "email", ".", "' as a writer for document: '", ".", "$", "fileid", ";", "throw", "new", "repository_exception", "(", "'errorwhilecommunicatingwith'", ",", "'repository'", ",", "''", ",", "$", "details", ")", ";", "}", "return", "true", ";", "}" ]
Add a writer to the permissions on the file. @param \repository_googledocs\rest $client Authenticated client. @param string $fileid The file we are updating. @param string $email The email of the writer account to add. @return boolean
[ "Add", "a", "writer", "to", "the", "permissions", "on", "the", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/googledocs/lib.php#L807-L820
219,933
moodle/moodle
repository/googledocs/lib.php
repository_googledocs.move_file_from_root_to_folder
protected function move_file_from_root_to_folder(\repository_googledocs\rest $client, $fileid, $folderid) { // Set the parent. $params = [ 'fileid' => $fileid, 'addParents' => $folderid, 'removeParents' => 'root' ]; $response = $client->call('update', $params, ' '); if (empty($response->id)) { $details = 'Cannot move the file to a folder: ' . $fileid; throw new repository_exception('errorwhilecommunicatingwith', 'repository', '', $details); } return true; }
php
protected function move_file_from_root_to_folder(\repository_googledocs\rest $client, $fileid, $folderid) { // Set the parent. $params = [ 'fileid' => $fileid, 'addParents' => $folderid, 'removeParents' => 'root' ]; $response = $client->call('update', $params, ' '); if (empty($response->id)) { $details = 'Cannot move the file to a folder: ' . $fileid; throw new repository_exception('errorwhilecommunicatingwith', 'repository', '', $details); } return true; }
[ "protected", "function", "move_file_from_root_to_folder", "(", "\\", "repository_googledocs", "\\", "rest", "$", "client", ",", "$", "fileid", ",", "$", "folderid", ")", "{", "// Set the parent.", "$", "params", "=", "[", "'fileid'", "=>", "$", "fileid", ",", "'addParents'", "=>", "$", "folderid", ",", "'removeParents'", "=>", "'root'", "]", ";", "$", "response", "=", "$", "client", "->", "call", "(", "'update'", ",", "$", "params", ",", "' '", ")", ";", "if", "(", "empty", "(", "$", "response", "->", "id", ")", ")", "{", "$", "details", "=", "'Cannot move the file to a folder: '", ".", "$", "fileid", ";", "throw", "new", "repository_exception", "(", "'errorwhilecommunicatingwith'", ",", "'repository'", ",", "''", ",", "$", "details", ")", ";", "}", "return", "true", ";", "}" ]
Move from root to folder @param \repository_googledocs\rest $client Authenticated client. @param string $fileid The file we are updating. @param string $folderid The id of the folder we are moving to @return boolean
[ "Move", "from", "root", "to", "folder" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/googledocs/lib.php#L830-L841
219,934
moodle/moodle
repository/googledocs/lib.php
repository_googledocs.prevent_writers_from_sharing_file
protected function prevent_writers_from_sharing_file(\repository_googledocs\rest $client, $fileid) { // We don't want anyone but Moodle to change the sharing settings. $params = [ 'fileid' => $fileid ]; $update = [ 'writersCanShare' => false ]; $response = $client->call('update', $params, json_encode($update)); if (empty($response->id)) { $details = 'Cannot prevent writers from sharing document: ' . $fileid; throw new repository_exception('errorwhilecommunicatingwith', 'repository', '', $details); } return true; }
php
protected function prevent_writers_from_sharing_file(\repository_googledocs\rest $client, $fileid) { // We don't want anyone but Moodle to change the sharing settings. $params = [ 'fileid' => $fileid ]; $update = [ 'writersCanShare' => false ]; $response = $client->call('update', $params, json_encode($update)); if (empty($response->id)) { $details = 'Cannot prevent writers from sharing document: ' . $fileid; throw new repository_exception('errorwhilecommunicatingwith', 'repository', '', $details); } return true; }
[ "protected", "function", "prevent_writers_from_sharing_file", "(", "\\", "repository_googledocs", "\\", "rest", "$", "client", ",", "$", "fileid", ")", "{", "// We don't want anyone but Moodle to change the sharing settings.", "$", "params", "=", "[", "'fileid'", "=>", "$", "fileid", "]", ";", "$", "update", "=", "[", "'writersCanShare'", "=>", "false", "]", ";", "$", "response", "=", "$", "client", "->", "call", "(", "'update'", ",", "$", "params", ",", "json_encode", "(", "$", "update", ")", ")", ";", "if", "(", "empty", "(", "$", "response", "->", "id", ")", ")", "{", "$", "details", "=", "'Cannot prevent writers from sharing document: '", ".", "$", "fileid", ";", "throw", "new", "repository_exception", "(", "'errorwhilecommunicatingwith'", ",", "'repository'", ",", "''", ",", "$", "details", ")", ";", "}", "return", "true", ";", "}" ]
Prevent writers from sharing. @param \repository_googledocs\rest $client Authenticated client. @param string $fileid The file we are updating. @return boolean
[ "Prevent", "writers", "from", "sharing", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/googledocs/lib.php#L850-L864
219,935
moodle/moodle
login/signup_form.php
login_signup_form.validation
public function validation($data, $files) { $errors = parent::validation($data, $files); if (signup_captcha_enabled()) { $recaptchaelement = $this->_form->getElement('recaptcha_element'); if (!empty($this->_form->_submitValues['g-recaptcha-response'])) { $response = $this->_form->_submitValues['g-recaptcha-response']; if (!$recaptchaelement->verify($response)) { $errors['recaptcha_element'] = get_string('incorrectpleasetryagain', 'auth'); } } else { $errors['recaptcha_element'] = get_string('missingrecaptchachallengefield'); } } $errors += signup_validate_data($data, $files); return $errors; }
php
public function validation($data, $files) { $errors = parent::validation($data, $files); if (signup_captcha_enabled()) { $recaptchaelement = $this->_form->getElement('recaptcha_element'); if (!empty($this->_form->_submitValues['g-recaptcha-response'])) { $response = $this->_form->_submitValues['g-recaptcha-response']; if (!$recaptchaelement->verify($response)) { $errors['recaptcha_element'] = get_string('incorrectpleasetryagain', 'auth'); } } else { $errors['recaptcha_element'] = get_string('missingrecaptchachallengefield'); } } $errors += signup_validate_data($data, $files); return $errors; }
[ "public", "function", "validation", "(", "$", "data", ",", "$", "files", ")", "{", "$", "errors", "=", "parent", "::", "validation", "(", "$", "data", ",", "$", "files", ")", ";", "if", "(", "signup_captcha_enabled", "(", ")", ")", "{", "$", "recaptchaelement", "=", "$", "this", "->", "_form", "->", "getElement", "(", "'recaptcha_element'", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "_form", "->", "_submitValues", "[", "'g-recaptcha-response'", "]", ")", ")", "{", "$", "response", "=", "$", "this", "->", "_form", "->", "_submitValues", "[", "'g-recaptcha-response'", "]", ";", "if", "(", "!", "$", "recaptchaelement", "->", "verify", "(", "$", "response", ")", ")", "{", "$", "errors", "[", "'recaptcha_element'", "]", "=", "get_string", "(", "'incorrectpleasetryagain'", ",", "'auth'", ")", ";", "}", "}", "else", "{", "$", "errors", "[", "'recaptcha_element'", "]", "=", "get_string", "(", "'missingrecaptchachallengefield'", ")", ";", "}", "}", "$", "errors", "+=", "signup_validate_data", "(", "$", "data", ",", "$", "files", ")", ";", "return", "$", "errors", ";", "}" ]
Validate user supplied data on the signup form. @param array $data array of ("fieldname"=>value) of submitted data @param array $files array of uploaded files "element_name"=>tmp_file_path @return array of "element_name"=>"error_description" if there are errors, or an empty array if everything is OK (true allowed for backwards compatibility too).
[ "Validate", "user", "supplied", "data", "on", "the", "signup", "form", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/login/signup_form.php#L128-L146
219,936
moodle/moodle
question/type/questionbase.php
question_graded_automatically.check_combined_feedback_file_access
protected function check_combined_feedback_file_access($qa, $options, $filearea, $args = null) { $state = $qa->get_state(); if ($args === null) { debugging('You must pass $args as the fourth argument to check_combined_feedback_file_access.', DEBUG_DEVELOPER); $args = array($this->id); // Fake it for now, so the rest of this method works. } if (!$state->is_finished()) { $response = $qa->get_last_qt_data(); if (!$this->is_gradable_response($response)) { return false; } list($notused, $state) = $this->grade_response($response); } return $options->feedback && $state->get_feedback_class() . 'feedback' == $filearea && $args[0] == $this->id; }
php
protected function check_combined_feedback_file_access($qa, $options, $filearea, $args = null) { $state = $qa->get_state(); if ($args === null) { debugging('You must pass $args as the fourth argument to check_combined_feedback_file_access.', DEBUG_DEVELOPER); $args = array($this->id); // Fake it for now, so the rest of this method works. } if (!$state->is_finished()) { $response = $qa->get_last_qt_data(); if (!$this->is_gradable_response($response)) { return false; } list($notused, $state) = $this->grade_response($response); } return $options->feedback && $state->get_feedback_class() . 'feedback' == $filearea && $args[0] == $this->id; }
[ "protected", "function", "check_combined_feedback_file_access", "(", "$", "qa", ",", "$", "options", ",", "$", "filearea", ",", "$", "args", "=", "null", ")", "{", "$", "state", "=", "$", "qa", "->", "get_state", "(", ")", ";", "if", "(", "$", "args", "===", "null", ")", "{", "debugging", "(", "'You must pass $args as the fourth argument to check_combined_feedback_file_access.'", ",", "DEBUG_DEVELOPER", ")", ";", "$", "args", "=", "array", "(", "$", "this", "->", "id", ")", ";", "// Fake it for now, so the rest of this method works.", "}", "if", "(", "!", "$", "state", "->", "is_finished", "(", ")", ")", "{", "$", "response", "=", "$", "qa", "->", "get_last_qt_data", "(", ")", ";", "if", "(", "!", "$", "this", "->", "is_gradable_response", "(", "$", "response", ")", ")", "{", "return", "false", ";", "}", "list", "(", "$", "notused", ",", "$", "state", ")", "=", "$", "this", "->", "grade_response", "(", "$", "response", ")", ";", "}", "return", "$", "options", "->", "feedback", "&&", "$", "state", "->", "get_feedback_class", "(", ")", ".", "'feedback'", "==", "$", "filearea", "&&", "$", "args", "[", "0", "]", "==", "$", "this", "->", "id", ";", "}" ]
Check a request for access to a file belonging to a combined feedback field. @param question_attempt $qa the question attempt being displayed. @param question_display_options $options the options that control display of the question. @param string $filearea the name of the file area. @param array $args the remaining bits of the file path. @return bool whether access to the file should be allowed.
[ "Check", "a", "request", "for", "access", "to", "a", "file", "belonging", "to", "a", "combined", "feedback", "field", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/questionbase.php#L689-L708
219,937
moodle/moodle
question/type/questionbase.php
question_graded_automatically.check_hint_file_access
protected function check_hint_file_access($qa, $options, $args) { if (!$options->feedback) { return false; } $hint = $qa->get_applicable_hint(); $hintid = reset($args); // Itemid is hint id. return $hintid == $hint->id; }
php
protected function check_hint_file_access($qa, $options, $args) { if (!$options->feedback) { return false; } $hint = $qa->get_applicable_hint(); $hintid = reset($args); // Itemid is hint id. return $hintid == $hint->id; }
[ "protected", "function", "check_hint_file_access", "(", "$", "qa", ",", "$", "options", ",", "$", "args", ")", "{", "if", "(", "!", "$", "options", "->", "feedback", ")", "{", "return", "false", ";", "}", "$", "hint", "=", "$", "qa", "->", "get_applicable_hint", "(", ")", ";", "$", "hintid", "=", "reset", "(", "$", "args", ")", ";", "// Itemid is hint id.", "return", "$", "hintid", "==", "$", "hint", "->", "id", ";", "}" ]
Check a request for access to a file belonging to a hint. @param question_attempt $qa the question attempt being displayed. @param question_display_options $options the options that control display of the question. @param array $args the remaining bits of the file path. @return bool whether access to the file should be allowed.
[ "Check", "a", "request", "for", "access", "to", "a", "file", "belonging", "to", "a", "hint", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/questionbase.php#L717-L724
219,938
moodle/moodle
mod/forum/classes/local/renderers/posts.php
posts.render
public function render( stdClass $user, array $forums, array $discussions, array $posts ) : string { // Format the forums and discussion to make them more easily accessed later. $forums = array_reduce($forums, function($carry, $forum) { $carry[$forum->get_id()] = $forum; return $carry; }, []); $discussions = array_reduce($discussions, function($carry, $discussion) { $carry[$discussion->get_id()] = $discussion; return $carry; }, []); $exportedposts = $this->exportedpostsbuilder->build( $user, $forums, $discussions, $posts ); if ($this->postprocessfortemplate !== null) { // We've got some post processing to do! $exportedposts = ($this->postprocessfortemplate)($exportedposts, $forums, $discussions, $user); } return $this->renderer->render_from_template( $this->template, ['posts' => array_values($exportedposts)] ); }
php
public function render( stdClass $user, array $forums, array $discussions, array $posts ) : string { // Format the forums and discussion to make them more easily accessed later. $forums = array_reduce($forums, function($carry, $forum) { $carry[$forum->get_id()] = $forum; return $carry; }, []); $discussions = array_reduce($discussions, function($carry, $discussion) { $carry[$discussion->get_id()] = $discussion; return $carry; }, []); $exportedposts = $this->exportedpostsbuilder->build( $user, $forums, $discussions, $posts ); if ($this->postprocessfortemplate !== null) { // We've got some post processing to do! $exportedposts = ($this->postprocessfortemplate)($exportedposts, $forums, $discussions, $user); } return $this->renderer->render_from_template( $this->template, ['posts' => array_values($exportedposts)] ); }
[ "public", "function", "render", "(", "stdClass", "$", "user", ",", "array", "$", "forums", ",", "array", "$", "discussions", ",", "array", "$", "posts", ")", ":", "string", "{", "// Format the forums and discussion to make them more easily accessed later.", "$", "forums", "=", "array_reduce", "(", "$", "forums", ",", "function", "(", "$", "carry", ",", "$", "forum", ")", "{", "$", "carry", "[", "$", "forum", "->", "get_id", "(", ")", "]", "=", "$", "forum", ";", "return", "$", "carry", ";", "}", ",", "[", "]", ")", ";", "$", "discussions", "=", "array_reduce", "(", "$", "discussions", ",", "function", "(", "$", "carry", ",", "$", "discussion", ")", "{", "$", "carry", "[", "$", "discussion", "->", "get_id", "(", ")", "]", "=", "$", "discussion", ";", "return", "$", "carry", ";", "}", ",", "[", "]", ")", ";", "$", "exportedposts", "=", "$", "this", "->", "exportedpostsbuilder", "->", "build", "(", "$", "user", ",", "$", "forums", ",", "$", "discussions", ",", "$", "posts", ")", ";", "if", "(", "$", "this", "->", "postprocessfortemplate", "!==", "null", ")", "{", "// We've got some post processing to do!", "$", "exportedposts", "=", "(", "$", "this", "->", "postprocessfortemplate", ")", "(", "$", "exportedposts", ",", "$", "forums", ",", "$", "discussions", ",", "$", "user", ")", ";", "}", "return", "$", "this", "->", "renderer", "->", "render_from_template", "(", "$", "this", "->", "template", ",", "[", "'posts'", "=>", "array_values", "(", "$", "exportedposts", ")", "]", ")", ";", "}" ]
Render the given posts for the forums and discussions. @param stdClass $user The user viewing the posts @param forum_entity[] $forums A list of all forums for these posts @param discussion_entity[] $discussions A list of all discussions for these posts @param post_entity[] $posts The posts to render @return string
[ "Render", "the", "given", "posts", "for", "the", "forums", "and", "discussions", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/renderers/posts.php#L78-L110
219,939
moodle/moodle
lib/classes/event/competency_deleted.php
competency_deleted.create_multiple_from_competencyids
public static function create_multiple_from_competencyids($competencyids, $contextid) { $events = array(); foreach ($competencyids as $id) { $events[$id] = static::create(array( 'contextid' => $contextid, 'objectid' => $id )); } return $events; }
php
public static function create_multiple_from_competencyids($competencyids, $contextid) { $events = array(); foreach ($competencyids as $id) { $events[$id] = static::create(array( 'contextid' => $contextid, 'objectid' => $id )); } return $events; }
[ "public", "static", "function", "create_multiple_from_competencyids", "(", "$", "competencyids", ",", "$", "contextid", ")", "{", "$", "events", "=", "array", "(", ")", ";", "foreach", "(", "$", "competencyids", "as", "$", "id", ")", "{", "$", "events", "[", "$", "id", "]", "=", "static", "::", "create", "(", "array", "(", "'contextid'", "=>", "$", "contextid", ",", "'objectid'", "=>", "$", "id", ")", ")", ";", "}", "return", "$", "events", ";", "}" ]
Instantiate events from competency ids. @param array $competencyids Array of competency ids. @param int $contextid The context id. @return self[] Array of events.
[ "Instantiate", "events", "from", "competency", "ids", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/event/competency_deleted.php#L67-L76
219,940
moodle/moodle
blocks/rss_client/classes/output/block.php
block.export_for_template
public function export_for_template(\renderer_base $output) { $data = array('feeds' => array()); foreach ($this->feeds as $feed) { $data['feeds'][] = $feed->export_for_template($output); } return $data; }
php
public function export_for_template(\renderer_base $output) { $data = array('feeds' => array()); foreach ($this->feeds as $feed) { $data['feeds'][] = $feed->export_for_template($output); } return $data; }
[ "public", "function", "export_for_template", "(", "\\", "renderer_base", "$", "output", ")", "{", "$", "data", "=", "array", "(", "'feeds'", "=>", "array", "(", ")", ")", ";", "foreach", "(", "$", "this", "->", "feeds", "as", "$", "feed", ")", "{", "$", "data", "[", "'feeds'", "]", "[", "]", "=", "$", "feed", "->", "export_for_template", "(", "$", "output", ")", ";", "}", "return", "$", "data", ";", "}" ]
Prepare data for use in a template @param \renderer_base $output @return array
[ "Prepare", "data", "for", "use", "in", "a", "template" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/rss_client/classes/output/block.php#L62-L70
219,941
moodle/moodle
grade/report/singleview/classes/local/ui/dropdown_attribute.php
dropdown_attribute.html
public function html() { global $OUTPUT; $options = $this->options; $selected = $this->selected; $context = array( 'name' => $this->name, 'value' => $this->selected, 'tabindex' => 1, 'disabled' => !empty($this->isdisabled), 'options' => array_map(function($option) use ($options, $selected) { return [ 'name' => $options[$option], 'value' => $option, 'selected' => $selected == $option ]; }, array_keys($options)) ); return $OUTPUT->render_from_template('gradereport_singleview/dropdown_attribute', $context); }
php
public function html() { global $OUTPUT; $options = $this->options; $selected = $this->selected; $context = array( 'name' => $this->name, 'value' => $this->selected, 'tabindex' => 1, 'disabled' => !empty($this->isdisabled), 'options' => array_map(function($option) use ($options, $selected) { return [ 'name' => $options[$option], 'value' => $option, 'selected' => $selected == $option ]; }, array_keys($options)) ); return $OUTPUT->render_from_template('gradereport_singleview/dropdown_attribute', $context); }
[ "public", "function", "html", "(", ")", "{", "global", "$", "OUTPUT", ";", "$", "options", "=", "$", "this", "->", "options", ";", "$", "selected", "=", "$", "this", "->", "selected", ";", "$", "context", "=", "array", "(", "'name'", "=>", "$", "this", "->", "name", ",", "'value'", "=>", "$", "this", "->", "selected", ",", "'tabindex'", "=>", "1", ",", "'disabled'", "=>", "!", "empty", "(", "$", "this", "->", "isdisabled", ")", ",", "'options'", "=>", "array_map", "(", "function", "(", "$", "option", ")", "use", "(", "$", "options", ",", "$", "selected", ")", "{", "return", "[", "'name'", "=>", "$", "options", "[", "$", "option", "]", ",", "'value'", "=>", "$", "option", ",", "'selected'", "=>", "$", "selected", "==", "$", "option", "]", ";", "}", ",", "array_keys", "(", "$", "options", ")", ")", ")", ";", "return", "$", "OUTPUT", "->", "render_from_template", "(", "'gradereport_singleview/dropdown_attribute'", ",", "$", "context", ")", ";", "}" ]
Render this element as html. @return string
[ "Render", "this", "element", "as", "html", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/report/singleview/classes/local/ui/dropdown_attribute.php#L79-L100
219,942
moodle/moodle
admin/tool/langimport/classes/controller.php
controller.install_languagepacks
public function install_languagepacks($langs, $updating = false) { global $CFG; $this->installer->set_queue($langs); $results = $this->installer->run(); $updatedpacks = 0; foreach ($results as $langcode => $langstatus) { switch ($langstatus) { case \lang_installer::RESULT_DOWNLOADERROR: $a = new \stdClass(); $a->url = $this->installer->lang_pack_url($langcode); $a->dest = $CFG->dataroot.'/lang'; $this->errors[] = get_string('remotedownloaderror', 'error', $a); throw new \moodle_exception('remotedownloaderror', 'error', $a); break; case \lang_installer::RESULT_INSTALLED: $updatedpacks++; if ($updating) { event\langpack_updated::event_with_langcode($langcode)->trigger(); $this->info[] = get_string('langpackupdated', 'tool_langimport', $langcode); } else { $this->info[] = get_string('langpackinstalled', 'tool_langimport', $langcode); event\langpack_imported::event_with_langcode($langcode)->trigger(); } break; case \lang_installer::RESULT_UPTODATE: $this->info[] = get_string('langpackuptodate', 'tool_langimport', $langcode); break; } } return $updatedpacks; }
php
public function install_languagepacks($langs, $updating = false) { global $CFG; $this->installer->set_queue($langs); $results = $this->installer->run(); $updatedpacks = 0; foreach ($results as $langcode => $langstatus) { switch ($langstatus) { case \lang_installer::RESULT_DOWNLOADERROR: $a = new \stdClass(); $a->url = $this->installer->lang_pack_url($langcode); $a->dest = $CFG->dataroot.'/lang'; $this->errors[] = get_string('remotedownloaderror', 'error', $a); throw new \moodle_exception('remotedownloaderror', 'error', $a); break; case \lang_installer::RESULT_INSTALLED: $updatedpacks++; if ($updating) { event\langpack_updated::event_with_langcode($langcode)->trigger(); $this->info[] = get_string('langpackupdated', 'tool_langimport', $langcode); } else { $this->info[] = get_string('langpackinstalled', 'tool_langimport', $langcode); event\langpack_imported::event_with_langcode($langcode)->trigger(); } break; case \lang_installer::RESULT_UPTODATE: $this->info[] = get_string('langpackuptodate', 'tool_langimport', $langcode); break; } } return $updatedpacks; }
[ "public", "function", "install_languagepacks", "(", "$", "langs", ",", "$", "updating", "=", "false", ")", "{", "global", "$", "CFG", ";", "$", "this", "->", "installer", "->", "set_queue", "(", "$", "langs", ")", ";", "$", "results", "=", "$", "this", "->", "installer", "->", "run", "(", ")", ";", "$", "updatedpacks", "=", "0", ";", "foreach", "(", "$", "results", "as", "$", "langcode", "=>", "$", "langstatus", ")", "{", "switch", "(", "$", "langstatus", ")", "{", "case", "\\", "lang_installer", "::", "RESULT_DOWNLOADERROR", ":", "$", "a", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "a", "->", "url", "=", "$", "this", "->", "installer", "->", "lang_pack_url", "(", "$", "langcode", ")", ";", "$", "a", "->", "dest", "=", "$", "CFG", "->", "dataroot", ".", "'/lang'", ";", "$", "this", "->", "errors", "[", "]", "=", "get_string", "(", "'remotedownloaderror'", ",", "'error'", ",", "$", "a", ")", ";", "throw", "new", "\\", "moodle_exception", "(", "'remotedownloaderror'", ",", "'error'", ",", "$", "a", ")", ";", "break", ";", "case", "\\", "lang_installer", "::", "RESULT_INSTALLED", ":", "$", "updatedpacks", "++", ";", "if", "(", "$", "updating", ")", "{", "event", "\\", "langpack_updated", "::", "event_with_langcode", "(", "$", "langcode", ")", "->", "trigger", "(", ")", ";", "$", "this", "->", "info", "[", "]", "=", "get_string", "(", "'langpackupdated'", ",", "'tool_langimport'", ",", "$", "langcode", ")", ";", "}", "else", "{", "$", "this", "->", "info", "[", "]", "=", "get_string", "(", "'langpackinstalled'", ",", "'tool_langimport'", ",", "$", "langcode", ")", ";", "event", "\\", "langpack_imported", "::", "event_with_langcode", "(", "$", "langcode", ")", "->", "trigger", "(", ")", ";", "}", "break", ";", "case", "\\", "lang_installer", "::", "RESULT_UPTODATE", ":", "$", "this", "->", "info", "[", "]", "=", "get_string", "(", "'langpackuptodate'", ",", "'tool_langimport'", ",", "$", "langcode", ")", ";", "break", ";", "}", "}", "return", "$", "updatedpacks", ";", "}" ]
Install language packs provided @param string|array $langs array of langcodes or individual langcodes @param bool $updating true if updating the langpacks @return int false if an error encountered or @throws \moodle_exception when error is encountered installing langpack
[ "Install", "language", "packs", "provided" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/langimport/classes/controller.php#L70-L104
219,943
moodle/moodle
admin/tool/langimport/classes/controller.php
controller.uninstall_language
public function uninstall_language($lang) { global $CFG; $dest1 = $CFG->dataroot.'/lang/'.$lang; $dest2 = $CFG->dirroot.'/lang/'.$lang; $rm1 = false; $rm2 = false; if (file_exists($dest1)) { $rm1 = remove_dir($dest1); } if (file_exists($dest2)) { $rm2 = remove_dir($dest2); } if ($rm1 or $rm2) { $this->info[] = get_string('langpackremoved', 'tool_langimport', $lang); event\langpack_removed::event_with_langcode($lang)->trigger(); return true; } else { // Nothing deleted, possibly due to permission error. $this->errors[] = get_string('langpacknotremoved', 'tool_langimport', $lang); return false; } }
php
public function uninstall_language($lang) { global $CFG; $dest1 = $CFG->dataroot.'/lang/'.$lang; $dest2 = $CFG->dirroot.'/lang/'.$lang; $rm1 = false; $rm2 = false; if (file_exists($dest1)) { $rm1 = remove_dir($dest1); } if (file_exists($dest2)) { $rm2 = remove_dir($dest2); } if ($rm1 or $rm2) { $this->info[] = get_string('langpackremoved', 'tool_langimport', $lang); event\langpack_removed::event_with_langcode($lang)->trigger(); return true; } else { // Nothing deleted, possibly due to permission error. $this->errors[] = get_string('langpacknotremoved', 'tool_langimport', $lang); return false; } }
[ "public", "function", "uninstall_language", "(", "$", "lang", ")", "{", "global", "$", "CFG", ";", "$", "dest1", "=", "$", "CFG", "->", "dataroot", ".", "'/lang/'", ".", "$", "lang", ";", "$", "dest2", "=", "$", "CFG", "->", "dirroot", ".", "'/lang/'", ".", "$", "lang", ";", "$", "rm1", "=", "false", ";", "$", "rm2", "=", "false", ";", "if", "(", "file_exists", "(", "$", "dest1", ")", ")", "{", "$", "rm1", "=", "remove_dir", "(", "$", "dest1", ")", ";", "}", "if", "(", "file_exists", "(", "$", "dest2", ")", ")", "{", "$", "rm2", "=", "remove_dir", "(", "$", "dest2", ")", ";", "}", "if", "(", "$", "rm1", "or", "$", "rm2", ")", "{", "$", "this", "->", "info", "[", "]", "=", "get_string", "(", "'langpackremoved'", ",", "'tool_langimport'", ",", "$", "lang", ")", ";", "event", "\\", "langpack_removed", "::", "event_with_langcode", "(", "$", "lang", ")", "->", "trigger", "(", ")", ";", "return", "true", ";", "}", "else", "{", "// Nothing deleted, possibly due to permission error.", "$", "this", "->", "errors", "[", "]", "=", "get_string", "(", "'langpacknotremoved'", ",", "'tool_langimport'", ",", "$", "lang", ")", ";", "return", "false", ";", "}", "}" ]
Uninstall language pack @param string $lang language code @return bool true if language succesfull installed
[ "Uninstall", "language", "pack" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/langimport/classes/controller.php#L112-L134
219,944
moodle/moodle
admin/tool/langimport/classes/controller.php
controller.update_all_installed_languages
public function update_all_installed_languages() { global $CFG; if (!$availablelangs = $this->installer->get_remote_list_of_languages()) { $this->errors[] = get_string('cannotdownloadlanguageupdatelist', 'error'); return false; } $md5array = array(); // Convert to (string)langcode => (string)md5. foreach ($availablelangs as $alang) { $md5array[$alang[0]] = $alang[1]; } // Filter out unofficial packs. $currentlangs = array_keys(get_string_manager()->get_list_of_translations(true)); $updateablelangs = array(); foreach ($currentlangs as $clang) { if (!array_key_exists($clang, $md5array)) { $this->info[] = get_string('langpackupdateskipped', 'tool_langimport', $clang); continue; } $dest1 = $CFG->dataroot.'/lang/'.$clang; $dest2 = $CFG->dirroot.'/lang/'.$clang; if (file_exists($dest1.'/langconfig.php') || file_exists($dest2.'/langconfig.php')) { $updateablelangs[] = $clang; } } // Filter out packs that have the same md5 key. $neededlangs = array(); foreach ($updateablelangs as $ulang) { if (!$this->is_installed_lang($ulang, $md5array[$ulang])) { $neededlangs[] = $ulang; } } try { $updated = $this->install_languagepacks($neededlangs, true); } catch (\moodle_exception $e) { $this->errors[] = 'An exception occurred while installing language packs: ' . $e->getMessage(); return false; } if ($updated) { $this->info[] = get_string('langupdatecomplete', 'tool_langimport'); // The strings have been changed so we need to purge their cache to ensure users see the changes. get_string_manager()->reset_caches(); } else { $this->info[] = get_string('nolangupdateneeded', 'tool_langimport'); } return true; }
php
public function update_all_installed_languages() { global $CFG; if (!$availablelangs = $this->installer->get_remote_list_of_languages()) { $this->errors[] = get_string('cannotdownloadlanguageupdatelist', 'error'); return false; } $md5array = array(); // Convert to (string)langcode => (string)md5. foreach ($availablelangs as $alang) { $md5array[$alang[0]] = $alang[1]; } // Filter out unofficial packs. $currentlangs = array_keys(get_string_manager()->get_list_of_translations(true)); $updateablelangs = array(); foreach ($currentlangs as $clang) { if (!array_key_exists($clang, $md5array)) { $this->info[] = get_string('langpackupdateskipped', 'tool_langimport', $clang); continue; } $dest1 = $CFG->dataroot.'/lang/'.$clang; $dest2 = $CFG->dirroot.'/lang/'.$clang; if (file_exists($dest1.'/langconfig.php') || file_exists($dest2.'/langconfig.php')) { $updateablelangs[] = $clang; } } // Filter out packs that have the same md5 key. $neededlangs = array(); foreach ($updateablelangs as $ulang) { if (!$this->is_installed_lang($ulang, $md5array[$ulang])) { $neededlangs[] = $ulang; } } try { $updated = $this->install_languagepacks($neededlangs, true); } catch (\moodle_exception $e) { $this->errors[] = 'An exception occurred while installing language packs: ' . $e->getMessage(); return false; } if ($updated) { $this->info[] = get_string('langupdatecomplete', 'tool_langimport'); // The strings have been changed so we need to purge their cache to ensure users see the changes. get_string_manager()->reset_caches(); } else { $this->info[] = get_string('nolangupdateneeded', 'tool_langimport'); } return true; }
[ "public", "function", "update_all_installed_languages", "(", ")", "{", "global", "$", "CFG", ";", "if", "(", "!", "$", "availablelangs", "=", "$", "this", "->", "installer", "->", "get_remote_list_of_languages", "(", ")", ")", "{", "$", "this", "->", "errors", "[", "]", "=", "get_string", "(", "'cannotdownloadlanguageupdatelist'", ",", "'error'", ")", ";", "return", "false", ";", "}", "$", "md5array", "=", "array", "(", ")", ";", "// Convert to (string)langcode => (string)md5.", "foreach", "(", "$", "availablelangs", "as", "$", "alang", ")", "{", "$", "md5array", "[", "$", "alang", "[", "0", "]", "]", "=", "$", "alang", "[", "1", "]", ";", "}", "// Filter out unofficial packs.", "$", "currentlangs", "=", "array_keys", "(", "get_string_manager", "(", ")", "->", "get_list_of_translations", "(", "true", ")", ")", ";", "$", "updateablelangs", "=", "array", "(", ")", ";", "foreach", "(", "$", "currentlangs", "as", "$", "clang", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "clang", ",", "$", "md5array", ")", ")", "{", "$", "this", "->", "info", "[", "]", "=", "get_string", "(", "'langpackupdateskipped'", ",", "'tool_langimport'", ",", "$", "clang", ")", ";", "continue", ";", "}", "$", "dest1", "=", "$", "CFG", "->", "dataroot", ".", "'/lang/'", ".", "$", "clang", ";", "$", "dest2", "=", "$", "CFG", "->", "dirroot", ".", "'/lang/'", ".", "$", "clang", ";", "if", "(", "file_exists", "(", "$", "dest1", ".", "'/langconfig.php'", ")", "||", "file_exists", "(", "$", "dest2", ".", "'/langconfig.php'", ")", ")", "{", "$", "updateablelangs", "[", "]", "=", "$", "clang", ";", "}", "}", "// Filter out packs that have the same md5 key.", "$", "neededlangs", "=", "array", "(", ")", ";", "foreach", "(", "$", "updateablelangs", "as", "$", "ulang", ")", "{", "if", "(", "!", "$", "this", "->", "is_installed_lang", "(", "$", "ulang", ",", "$", "md5array", "[", "$", "ulang", "]", ")", ")", "{", "$", "neededlangs", "[", "]", "=", "$", "ulang", ";", "}", "}", "try", "{", "$", "updated", "=", "$", "this", "->", "install_languagepacks", "(", "$", "neededlangs", ",", "true", ")", ";", "}", "catch", "(", "\\", "moodle_exception", "$", "e", ")", "{", "$", "this", "->", "errors", "[", "]", "=", "'An exception occurred while installing language packs: '", ".", "$", "e", "->", "getMessage", "(", ")", ";", "return", "false", ";", "}", "if", "(", "$", "updated", ")", "{", "$", "this", "->", "info", "[", "]", "=", "get_string", "(", "'langupdatecomplete'", ",", "'tool_langimport'", ")", ";", "// The strings have been changed so we need to purge their cache to ensure users see the changes.", "get_string_manager", "(", ")", "->", "reset_caches", "(", ")", ";", "}", "else", "{", "$", "this", "->", "info", "[", "]", "=", "get_string", "(", "'nolangupdateneeded'", ",", "'tool_langimport'", ")", ";", "}", "return", "true", ";", "}" ]
Updated all install language packs with the latest found on servre @return bool true if languages succesfully updated.
[ "Updated", "all", "install", "language", "packs", "with", "the", "latest", "found", "on", "servre" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/langimport/classes/controller.php#L141-L194
219,945
moodle/moodle
admin/tool/langimport/classes/controller.php
controller.is_installed_lang
public function is_installed_lang($lang, $md5check) { global $CFG; $md5file = $CFG->dataroot.'/lang/'.$lang.'/'.$lang.'.md5'; if (file_exists($md5file)) { return (file_get_contents($md5file) == $md5check); } return false; }
php
public function is_installed_lang($lang, $md5check) { global $CFG; $md5file = $CFG->dataroot.'/lang/'.$lang.'/'.$lang.'.md5'; if (file_exists($md5file)) { return (file_get_contents($md5file) == $md5check); } return false; }
[ "public", "function", "is_installed_lang", "(", "$", "lang", ",", "$", "md5check", ")", "{", "global", "$", "CFG", ";", "$", "md5file", "=", "$", "CFG", "->", "dataroot", ".", "'/lang/'", ".", "$", "lang", ".", "'/'", ".", "$", "lang", ".", "'.md5'", ";", "if", "(", "file_exists", "(", "$", "md5file", ")", ")", "{", "return", "(", "file_get_contents", "(", "$", "md5file", ")", "==", "$", "md5check", ")", ";", "}", "return", "false", ";", "}" ]
checks the md5 of the zip file, grabbed from download.moodle.org, against the md5 of the local language file from last update @param string $lang language code @param string $md5check md5 to check @return bool true if installed
[ "checks", "the", "md5", "of", "the", "zip", "file", "grabbed", "from", "download", ".", "moodle", ".", "org", "against", "the", "md5", "of", "the", "local", "language", "file", "from", "last", "update" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/langimport/classes/controller.php#L203-L210
219,946
moodle/moodle
availability/condition/grade/classes/condition.php
condition.get_cached_grade_name
private static function get_cached_grade_name($courseid, $gradeitemid) { global $DB, $CFG; require_once($CFG->libdir . '/gradelib.php'); // Get all grade item names from cache, or using db query. $cache = \cache::make('availability_grade', 'items'); if (($cacheditems = $cache->get($courseid)) === false) { // We cache the whole items table not the name; the format_string // call for the name might depend on current user (e.g. multilang) // and this is a shared cache. $cacheditems = $DB->get_records('grade_items', array('courseid' => $courseid)); $cache->set($courseid, $cacheditems); } // Return name from cached item or a lang string. if (!array_key_exists($gradeitemid, $cacheditems)) { return get_string('missing', 'availability_grade'); } $gradeitemobj = $cacheditems[$gradeitemid]; $item = new \grade_item; \grade_object::set_properties($item, $gradeitemobj); return $item->get_name(); }
php
private static function get_cached_grade_name($courseid, $gradeitemid) { global $DB, $CFG; require_once($CFG->libdir . '/gradelib.php'); // Get all grade item names from cache, or using db query. $cache = \cache::make('availability_grade', 'items'); if (($cacheditems = $cache->get($courseid)) === false) { // We cache the whole items table not the name; the format_string // call for the name might depend on current user (e.g. multilang) // and this is a shared cache. $cacheditems = $DB->get_records('grade_items', array('courseid' => $courseid)); $cache->set($courseid, $cacheditems); } // Return name from cached item or a lang string. if (!array_key_exists($gradeitemid, $cacheditems)) { return get_string('missing', 'availability_grade'); } $gradeitemobj = $cacheditems[$gradeitemid]; $item = new \grade_item; \grade_object::set_properties($item, $gradeitemobj); return $item->get_name(); }
[ "private", "static", "function", "get_cached_grade_name", "(", "$", "courseid", ",", "$", "gradeitemid", ")", "{", "global", "$", "DB", ",", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/gradelib.php'", ")", ";", "// Get all grade item names from cache, or using db query.", "$", "cache", "=", "\\", "cache", "::", "make", "(", "'availability_grade'", ",", "'items'", ")", ";", "if", "(", "(", "$", "cacheditems", "=", "$", "cache", "->", "get", "(", "$", "courseid", ")", ")", "===", "false", ")", "{", "// We cache the whole items table not the name; the format_string", "// call for the name might depend on current user (e.g. multilang)", "// and this is a shared cache.", "$", "cacheditems", "=", "$", "DB", "->", "get_records", "(", "'grade_items'", ",", "array", "(", "'courseid'", "=>", "$", "courseid", ")", ")", ";", "$", "cache", "->", "set", "(", "$", "courseid", ",", "$", "cacheditems", ")", ";", "}", "// Return name from cached item or a lang string.", "if", "(", "!", "array_key_exists", "(", "$", "gradeitemid", ",", "$", "cacheditems", ")", ")", "{", "return", "get_string", "(", "'missing'", ",", "'availability_grade'", ")", ";", "}", "$", "gradeitemobj", "=", "$", "cacheditems", "[", "$", "gradeitemid", "]", ";", "$", "item", "=", "new", "\\", "grade_item", ";", "\\", "grade_object", "::", "set_properties", "(", "$", "item", ",", "$", "gradeitemobj", ")", ";", "return", "$", "item", "->", "get_name", "(", ")", ";", "}" ]
Obtains the name of a grade item, also checking that it exists. Uses a cache. The name returned is suitable for display. @param int $courseid Course id @param int $gradeitemid Grade item id @return string Grade name or empty string if no grade with that id
[ "Obtains", "the", "name", "of", "a", "grade", "item", "also", "checking", "that", "it", "exists", ".", "Uses", "a", "cache", ".", "The", "name", "returned", "is", "suitable", "for", "display", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/availability/condition/grade/classes/condition.php#L171-L193
219,947
moodle/moodle
availability/condition/grade/classes/condition.php
condition.get_cached_grade_score
protected static function get_cached_grade_score($gradeitemid, $courseid, $grabthelot=false, $userid=0) { global $USER, $DB; if (!$userid) { $userid = $USER->id; } $cache = \cache::make('availability_grade', 'scores'); if (($cachedgrades = $cache->get($userid)) === false) { $cachedgrades = array(); } if (!array_key_exists($gradeitemid, $cachedgrades)) { if ($grabthelot) { // Get all grades for the current course. $rs = $DB->get_recordset_sql(' SELECT gi.id,gg.finalgrade,gg.rawgrademin,gg.rawgrademax FROM {grade_items} gi LEFT JOIN {grade_grades} gg ON gi.id=gg.itemid AND gg.userid=? WHERE gi.courseid = ?', array($userid, $courseid)); foreach ($rs as $record) { // This function produces division by zero error warnings when rawgrademax and rawgrademin // are equal. Below change does not affect function behavior, just avoids the warning. if (is_null($record->finalgrade) || $record->rawgrademax == $record->rawgrademin) { // No grade = false. $cachedgrades[$record->id] = false; } else { // Otherwise convert grade to percentage. $cachedgrades[$record->id] = (($record->finalgrade - $record->rawgrademin) * 100) / ($record->rawgrademax - $record->rawgrademin); } } $rs->close(); // And if it's still not set, well it doesn't exist (eg // maybe the user set it as a condition, then deleted the // grade item) so we call it false. if (!array_key_exists($gradeitemid, $cachedgrades)) { $cachedgrades[$gradeitemid] = false; } } else { // Just get current grade. $record = $DB->get_record('grade_grades', array( 'userid' => $userid, 'itemid' => $gradeitemid)); // This function produces division by zero error warnings when rawgrademax and rawgrademin // are equal. Below change does not affect function behavior, just avoids the warning. if ($record && !is_null($record->finalgrade) && $record->rawgrademax != $record->rawgrademin) { $score = (($record->finalgrade - $record->rawgrademin) * 100) / ($record->rawgrademax - $record->rawgrademin); } else { // Treat the case where row exists but is null, same as // case where row doesn't exist. $score = false; } $cachedgrades[$gradeitemid] = $score; } $cache->set($userid, $cachedgrades); } return $cachedgrades[$gradeitemid]; }
php
protected static function get_cached_grade_score($gradeitemid, $courseid, $grabthelot=false, $userid=0) { global $USER, $DB; if (!$userid) { $userid = $USER->id; } $cache = \cache::make('availability_grade', 'scores'); if (($cachedgrades = $cache->get($userid)) === false) { $cachedgrades = array(); } if (!array_key_exists($gradeitemid, $cachedgrades)) { if ($grabthelot) { // Get all grades for the current course. $rs = $DB->get_recordset_sql(' SELECT gi.id,gg.finalgrade,gg.rawgrademin,gg.rawgrademax FROM {grade_items} gi LEFT JOIN {grade_grades} gg ON gi.id=gg.itemid AND gg.userid=? WHERE gi.courseid = ?', array($userid, $courseid)); foreach ($rs as $record) { // This function produces division by zero error warnings when rawgrademax and rawgrademin // are equal. Below change does not affect function behavior, just avoids the warning. if (is_null($record->finalgrade) || $record->rawgrademax == $record->rawgrademin) { // No grade = false. $cachedgrades[$record->id] = false; } else { // Otherwise convert grade to percentage. $cachedgrades[$record->id] = (($record->finalgrade - $record->rawgrademin) * 100) / ($record->rawgrademax - $record->rawgrademin); } } $rs->close(); // And if it's still not set, well it doesn't exist (eg // maybe the user set it as a condition, then deleted the // grade item) so we call it false. if (!array_key_exists($gradeitemid, $cachedgrades)) { $cachedgrades[$gradeitemid] = false; } } else { // Just get current grade. $record = $DB->get_record('grade_grades', array( 'userid' => $userid, 'itemid' => $gradeitemid)); // This function produces division by zero error warnings when rawgrademax and rawgrademin // are equal. Below change does not affect function behavior, just avoids the warning. if ($record && !is_null($record->finalgrade) && $record->rawgrademax != $record->rawgrademin) { $score = (($record->finalgrade - $record->rawgrademin) * 100) / ($record->rawgrademax - $record->rawgrademin); } else { // Treat the case where row exists but is null, same as // case where row doesn't exist. $score = false; } $cachedgrades[$gradeitemid] = $score; } $cache->set($userid, $cachedgrades); } return $cachedgrades[$gradeitemid]; }
[ "protected", "static", "function", "get_cached_grade_score", "(", "$", "gradeitemid", ",", "$", "courseid", ",", "$", "grabthelot", "=", "false", ",", "$", "userid", "=", "0", ")", "{", "global", "$", "USER", ",", "$", "DB", ";", "if", "(", "!", "$", "userid", ")", "{", "$", "userid", "=", "$", "USER", "->", "id", ";", "}", "$", "cache", "=", "\\", "cache", "::", "make", "(", "'availability_grade'", ",", "'scores'", ")", ";", "if", "(", "(", "$", "cachedgrades", "=", "$", "cache", "->", "get", "(", "$", "userid", ")", ")", "===", "false", ")", "{", "$", "cachedgrades", "=", "array", "(", ")", ";", "}", "if", "(", "!", "array_key_exists", "(", "$", "gradeitemid", ",", "$", "cachedgrades", ")", ")", "{", "if", "(", "$", "grabthelot", ")", "{", "// Get all grades for the current course.", "$", "rs", "=", "$", "DB", "->", "get_recordset_sql", "(", "'\n SELECT\n gi.id,gg.finalgrade,gg.rawgrademin,gg.rawgrademax\n FROM\n {grade_items} gi\n LEFT JOIN {grade_grades} gg ON gi.id=gg.itemid AND gg.userid=?\n WHERE\n gi.courseid = ?'", ",", "array", "(", "$", "userid", ",", "$", "courseid", ")", ")", ";", "foreach", "(", "$", "rs", "as", "$", "record", ")", "{", "// This function produces division by zero error warnings when rawgrademax and rawgrademin", "// are equal. Below change does not affect function behavior, just avoids the warning.", "if", "(", "is_null", "(", "$", "record", "->", "finalgrade", ")", "||", "$", "record", "->", "rawgrademax", "==", "$", "record", "->", "rawgrademin", ")", "{", "// No grade = false.", "$", "cachedgrades", "[", "$", "record", "->", "id", "]", "=", "false", ";", "}", "else", "{", "// Otherwise convert grade to percentage.", "$", "cachedgrades", "[", "$", "record", "->", "id", "]", "=", "(", "(", "$", "record", "->", "finalgrade", "-", "$", "record", "->", "rawgrademin", ")", "*", "100", ")", "/", "(", "$", "record", "->", "rawgrademax", "-", "$", "record", "->", "rawgrademin", ")", ";", "}", "}", "$", "rs", "->", "close", "(", ")", ";", "// And if it's still not set, well it doesn't exist (eg", "// maybe the user set it as a condition, then deleted the", "// grade item) so we call it false.", "if", "(", "!", "array_key_exists", "(", "$", "gradeitemid", ",", "$", "cachedgrades", ")", ")", "{", "$", "cachedgrades", "[", "$", "gradeitemid", "]", "=", "false", ";", "}", "}", "else", "{", "// Just get current grade.", "$", "record", "=", "$", "DB", "->", "get_record", "(", "'grade_grades'", ",", "array", "(", "'userid'", "=>", "$", "userid", ",", "'itemid'", "=>", "$", "gradeitemid", ")", ")", ";", "// This function produces division by zero error warnings when rawgrademax and rawgrademin", "// are equal. Below change does not affect function behavior, just avoids the warning.", "if", "(", "$", "record", "&&", "!", "is_null", "(", "$", "record", "->", "finalgrade", ")", "&&", "$", "record", "->", "rawgrademax", "!=", "$", "record", "->", "rawgrademin", ")", "{", "$", "score", "=", "(", "(", "$", "record", "->", "finalgrade", "-", "$", "record", "->", "rawgrademin", ")", "*", "100", ")", "/", "(", "$", "record", "->", "rawgrademax", "-", "$", "record", "->", "rawgrademin", ")", ";", "}", "else", "{", "// Treat the case where row exists but is null, same as", "// case where row doesn't exist.", "$", "score", "=", "false", ";", "}", "$", "cachedgrades", "[", "$", "gradeitemid", "]", "=", "$", "score", ";", "}", "$", "cache", "->", "set", "(", "$", "userid", ",", "$", "cachedgrades", ")", ";", "}", "return", "$", "cachedgrades", "[", "$", "gradeitemid", "]", ";", "}" ]
Obtains a grade score. Note that this score should not be displayed to the user, because gradebook rules might prohibit that. It may be a non-final score subject to adjustment later. @param int $gradeitemid Grade item ID we're interested in @param int $courseid Course id @param bool $grabthelot If true, grabs all scores for current user on this course, so that later ones come from cache @param int $userid Set if requesting grade for a different user (does not use cache) @return float Grade score as a percentage in range 0-100 (e.g. 100.0 or 37.21), or false if user does not have a grade yet
[ "Obtains", "a", "grade", "score", ".", "Note", "that", "this", "score", "should", "not", "be", "displayed", "to", "the", "user", "because", "gradebook", "rules", "might", "prohibit", "that", ".", "It", "may", "be", "a", "non", "-", "final", "score", "subject", "to", "adjustment", "later", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/availability/condition/grade/classes/condition.php#L209-L269
219,948
moodle/moodle
lib/pear/Auth/RADIUS.php
Auth_RADIUS.addServer
public function addServer($servername = 'localhost', $port = 0, $sharedSecret = 'testing123', $timeout = 3, $maxtries = 3) { $this->_servers[] = array($servername, $port, $sharedSecret, $timeout, $maxtries); }
php
public function addServer($servername = 'localhost', $port = 0, $sharedSecret = 'testing123', $timeout = 3, $maxtries = 3) { $this->_servers[] = array($servername, $port, $sharedSecret, $timeout, $maxtries); }
[ "public", "function", "addServer", "(", "$", "servername", "=", "'localhost'", ",", "$", "port", "=", "0", ",", "$", "sharedSecret", "=", "'testing123'", ",", "$", "timeout", "=", "3", ",", "$", "maxtries", "=", "3", ")", "{", "$", "this", "->", "_servers", "[", "]", "=", "array", "(", "$", "servername", ",", "$", "port", ",", "$", "sharedSecret", ",", "$", "timeout", ",", "$", "maxtries", ")", ";", "}" ]
Adds a RADIUS server to the list of servers for requests. At most 10 servers may be specified. When multiple servers are given, they are tried in round-robin fashion until a valid response is received @param string $servername Servername or IP-Address @param integer $port Portnumber @param string $sharedSecret Shared secret @param integer $timeout Timeout for each request @param integer $maxtries Max. retries for each request @return void
[ "Adds", "a", "RADIUS", "server", "to", "the", "list", "of", "servers", "for", "requests", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/Auth/RADIUS.php#L174-L177
219,949
moodle/moodle
lib/pear/Auth/RADIUS.php
Auth_RADIUS.putAttribute
public function putAttribute($attrib, $value, $type = null) { if ($type == null) { $type = gettype($value); } switch ($type) { case 'integer': case 'double': return radius_put_int($this->res, $attrib, $value); case 'addr': return radius_put_addr($this->res, $attrib, $value); case 'string': default: return radius_put_attr($this->res, $attrib, $value); } }
php
public function putAttribute($attrib, $value, $type = null) { if ($type == null) { $type = gettype($value); } switch ($type) { case 'integer': case 'double': return radius_put_int($this->res, $attrib, $value); case 'addr': return radius_put_addr($this->res, $attrib, $value); case 'string': default: return radius_put_attr($this->res, $attrib, $value); } }
[ "public", "function", "putAttribute", "(", "$", "attrib", ",", "$", "value", ",", "$", "type", "=", "null", ")", "{", "if", "(", "$", "type", "==", "null", ")", "{", "$", "type", "=", "gettype", "(", "$", "value", ")", ";", "}", "switch", "(", "$", "type", ")", "{", "case", "'integer'", ":", "case", "'double'", ":", "return", "radius_put_int", "(", "$", "this", "->", "res", ",", "$", "attrib", ",", "$", "value", ")", ";", "case", "'addr'", ":", "return", "radius_put_addr", "(", "$", "this", "->", "res", ",", "$", "attrib", ",", "$", "value", ")", ";", "case", "'string'", ":", "default", ":", "return", "radius_put_attr", "(", "$", "this", "->", "res", ",", "$", "attrib", ",", "$", "value", ")", ";", "}", "}" ]
Puts an attribute. @param integer $attrib Attribute-number @param mixed $port Attribute-value @param type $type Attribute-type @return bool true on success, false on error
[ "Puts", "an", "attribute", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/Auth/RADIUS.php#L208-L227
219,950
moodle/moodle
lib/pear/Auth/RADIUS.php
Auth_RADIUS.putVendorAttribute
public function putVendorAttribute($vendor, $attrib, $value, $type = null) { if ($type == null) { $type = gettype($value); } switch ($type) { case 'integer': case 'double': return radius_put_vendor_int($this->res, $vendor, $attrib, $value); case 'addr': return radius_put_vendor_addr($this->res, $vendor,$attrib, $value); case 'string': default: return radius_put_vendor_attr($this->res, $vendor, $attrib, $value); } }
php
public function putVendorAttribute($vendor, $attrib, $value, $type = null) { if ($type == null) { $type = gettype($value); } switch ($type) { case 'integer': case 'double': return radius_put_vendor_int($this->res, $vendor, $attrib, $value); case 'addr': return radius_put_vendor_addr($this->res, $vendor,$attrib, $value); case 'string': default: return radius_put_vendor_attr($this->res, $vendor, $attrib, $value); } }
[ "public", "function", "putVendorAttribute", "(", "$", "vendor", ",", "$", "attrib", ",", "$", "value", ",", "$", "type", "=", "null", ")", "{", "if", "(", "$", "type", "==", "null", ")", "{", "$", "type", "=", "gettype", "(", "$", "value", ")", ";", "}", "switch", "(", "$", "type", ")", "{", "case", "'integer'", ":", "case", "'double'", ":", "return", "radius_put_vendor_int", "(", "$", "this", "->", "res", ",", "$", "vendor", ",", "$", "attrib", ",", "$", "value", ")", ";", "case", "'addr'", ":", "return", "radius_put_vendor_addr", "(", "$", "this", "->", "res", ",", "$", "vendor", ",", "$", "attrib", ",", "$", "value", ")", ";", "case", "'string'", ":", "default", ":", "return", "radius_put_vendor_attr", "(", "$", "this", "->", "res", ",", "$", "vendor", ",", "$", "attrib", ",", "$", "value", ")", ";", "}", "}" ]
Puts a vendor-specific attribute. @param integer $vendor Vendor (MSoft, Cisco, ...) @param integer $attrib Attribute-number @param mixed $port Attribute-value @param type $type Attribute-type @return bool true on success, false on error
[ "Puts", "a", "vendor", "-", "specific", "attribute", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/Auth/RADIUS.php#L238-L258
219,951
moodle/moodle
lib/pear/Auth/RADIUS.php
Auth_RADIUS.putStandardAttributes
public function putStandardAttributes() { if (!$this->useStandardAttributes) { return; } if (isset($_SERVER)) { $var = $_SERVER; } else { $var = $GLOBALS['HTTP_SERVER_VARS']; } $this->putAttribute(RADIUS_NAS_IDENTIFIER, isset($var['HTTP_HOST']) ? $var['HTTP_HOST'] : 'localhost'); $this->putAttribute(RADIUS_NAS_PORT_TYPE, RADIUS_VIRTUAL); $this->putAttribute(RADIUS_SERVICE_TYPE, RADIUS_FRAMED); $this->putAttribute(RADIUS_FRAMED_PROTOCOL, RADIUS_PPP); $this->putAttribute(RADIUS_CALLING_STATION_ID, isset($var['REMOTE_HOST']) ? $var['REMOTE_HOST'] : '127.0.0.1'); }
php
public function putStandardAttributes() { if (!$this->useStandardAttributes) { return; } if (isset($_SERVER)) { $var = $_SERVER; } else { $var = $GLOBALS['HTTP_SERVER_VARS']; } $this->putAttribute(RADIUS_NAS_IDENTIFIER, isset($var['HTTP_HOST']) ? $var['HTTP_HOST'] : 'localhost'); $this->putAttribute(RADIUS_NAS_PORT_TYPE, RADIUS_VIRTUAL); $this->putAttribute(RADIUS_SERVICE_TYPE, RADIUS_FRAMED); $this->putAttribute(RADIUS_FRAMED_PROTOCOL, RADIUS_PPP); $this->putAttribute(RADIUS_CALLING_STATION_ID, isset($var['REMOTE_HOST']) ? $var['REMOTE_HOST'] : '127.0.0.1'); }
[ "public", "function", "putStandardAttributes", "(", ")", "{", "if", "(", "!", "$", "this", "->", "useStandardAttributes", ")", "{", "return", ";", "}", "if", "(", "isset", "(", "$", "_SERVER", ")", ")", "{", "$", "var", "=", "$", "_SERVER", ";", "}", "else", "{", "$", "var", "=", "$", "GLOBALS", "[", "'HTTP_SERVER_VARS'", "]", ";", "}", "$", "this", "->", "putAttribute", "(", "RADIUS_NAS_IDENTIFIER", ",", "isset", "(", "$", "var", "[", "'HTTP_HOST'", "]", ")", "?", "$", "var", "[", "'HTTP_HOST'", "]", ":", "'localhost'", ")", ";", "$", "this", "->", "putAttribute", "(", "RADIUS_NAS_PORT_TYPE", ",", "RADIUS_VIRTUAL", ")", ";", "$", "this", "->", "putAttribute", "(", "RADIUS_SERVICE_TYPE", ",", "RADIUS_FRAMED", ")", ";", "$", "this", "->", "putAttribute", "(", "RADIUS_FRAMED_PROTOCOL", ",", "RADIUS_PPP", ")", ";", "$", "this", "->", "putAttribute", "(", "RADIUS_CALLING_STATION_ID", ",", "isset", "(", "$", "var", "[", "'REMOTE_HOST'", "]", ")", "?", "$", "var", "[", "'REMOTE_HOST'", "]", ":", "'127.0.0.1'", ")", ";", "}" ]
Puts standard attributes.
[ "Puts", "standard", "attributes", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/Auth/RADIUS.php#L288-L305
219,952
moodle/moodle
lib/pear/Auth/RADIUS.php
Auth_RADIUS.putServer
public function putServer($servername, $port = 0, $sharedsecret = 'testing123', $timeout = 3, $maxtries = 3) { if (!radius_add_server($this->res, $servername, $port, $sharedsecret, $timeout, $maxtries)) { return false; } return true; }
php
public function putServer($servername, $port = 0, $sharedsecret = 'testing123', $timeout = 3, $maxtries = 3) { if (!radius_add_server($this->res, $servername, $port, $sharedsecret, $timeout, $maxtries)) { return false; } return true; }
[ "public", "function", "putServer", "(", "$", "servername", ",", "$", "port", "=", "0", ",", "$", "sharedsecret", "=", "'testing123'", ",", "$", "timeout", "=", "3", ",", "$", "maxtries", "=", "3", ")", "{", "if", "(", "!", "radius_add_server", "(", "$", "this", "->", "res", ",", "$", "servername", ",", "$", "port", ",", "$", "sharedsecret", ",", "$", "timeout", ",", "$", "maxtries", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Configures the radius library. @param string $servername Servername or IP-Address @param integer $port Portnumber @param string $sharedSecret Shared secret @param integer $timeout Timeout for each request @param integer $maxtries Max. retries for each request @return bool true on success, false on error @see addServer()
[ "Configures", "the", "radius", "library", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/Auth/RADIUS.php#L328-L334
219,953
moodle/moodle
lib/pear/Auth/RADIUS.php
Auth_RADIUS.start
public function start() { if (!$this->open()) { return false; } foreach ($this->_servers as $s) { // Servername, port, sharedsecret, timeout, retries if (!$this->putServer($s[0], $s[1], $s[2], $s[3], $s[4])) { return false; } } if (!empty($this->_configfile)) { if (!$this->putConfigfile($this->_configfile)) { return false; } } $this->createRequest(); $this->putStandardAttributes(); $this->putAuthAttributes(); return true; }
php
public function start() { if (!$this->open()) { return false; } foreach ($this->_servers as $s) { // Servername, port, sharedsecret, timeout, retries if (!$this->putServer($s[0], $s[1], $s[2], $s[3], $s[4])) { return false; } } if (!empty($this->_configfile)) { if (!$this->putConfigfile($this->_configfile)) { return false; } } $this->createRequest(); $this->putStandardAttributes(); $this->putAuthAttributes(); return true; }
[ "public", "function", "start", "(", ")", "{", "if", "(", "!", "$", "this", "->", "open", "(", ")", ")", "{", "return", "false", ";", "}", "foreach", "(", "$", "this", "->", "_servers", "as", "$", "s", ")", "{", "// Servername, port, sharedsecret, timeout, retries", "if", "(", "!", "$", "this", "->", "putServer", "(", "$", "s", "[", "0", "]", ",", "$", "s", "[", "1", "]", ",", "$", "s", "[", "2", "]", ",", "$", "s", "[", "3", "]", ",", "$", "s", "[", "4", "]", ")", ")", "{", "return", "false", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "_configfile", ")", ")", "{", "if", "(", "!", "$", "this", "->", "putConfigfile", "(", "$", "this", "->", "_configfile", ")", ")", "{", "return", "false", ";", "}", "}", "$", "this", "->", "createRequest", "(", ")", ";", "$", "this", "->", "putStandardAttributes", "(", ")", ";", "$", "this", "->", "putAuthAttributes", "(", ")", ";", "return", "true", ";", "}" ]
Initiates a RADIUS request. @return bool true on success, false on errors
[ "Initiates", "a", "RADIUS", "request", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/Auth/RADIUS.php#L355-L378
219,954
moodle/moodle
lib/pear/Auth/RADIUS.php
Auth_RADIUS.send
public function send() { $req = radius_send_request($this->res); if (!$req) { throw new Auth_RADIUS_Exception('Error sending request: ' . $this->getError()); } switch($req) { case RADIUS_ACCESS_ACCEPT: if (is_subclass_of($this, 'auth_radius_acct')) { throw new Auth_RADIUS_Exception('RADIUS_ACCESS_ACCEPT is unexpected for accounting'); } return true; case RADIUS_ACCESS_REJECT: return false; case RADIUS_ACCOUNTING_RESPONSE: if (is_subclass_of($this, 'auth_radius_pap')) { throw new Auth_RADIUS_Exception('RADIUS_ACCOUNTING_RESPONSE is unexpected for authentication'); } return true; default: throw new Auth_RADIUS_Exception("Unexpected return value: $req"); } }
php
public function send() { $req = radius_send_request($this->res); if (!$req) { throw new Auth_RADIUS_Exception('Error sending request: ' . $this->getError()); } switch($req) { case RADIUS_ACCESS_ACCEPT: if (is_subclass_of($this, 'auth_radius_acct')) { throw new Auth_RADIUS_Exception('RADIUS_ACCESS_ACCEPT is unexpected for accounting'); } return true; case RADIUS_ACCESS_REJECT: return false; case RADIUS_ACCOUNTING_RESPONSE: if (is_subclass_of($this, 'auth_radius_pap')) { throw new Auth_RADIUS_Exception('RADIUS_ACCOUNTING_RESPONSE is unexpected for authentication'); } return true; default: throw new Auth_RADIUS_Exception("Unexpected return value: $req"); } }
[ "public", "function", "send", "(", ")", "{", "$", "req", "=", "radius_send_request", "(", "$", "this", "->", "res", ")", ";", "if", "(", "!", "$", "req", ")", "{", "throw", "new", "Auth_RADIUS_Exception", "(", "'Error sending request: '", ".", "$", "this", "->", "getError", "(", ")", ")", ";", "}", "switch", "(", "$", "req", ")", "{", "case", "RADIUS_ACCESS_ACCEPT", ":", "if", "(", "is_subclass_of", "(", "$", "this", ",", "'auth_radius_acct'", ")", ")", "{", "throw", "new", "Auth_RADIUS_Exception", "(", "'RADIUS_ACCESS_ACCEPT is unexpected for accounting'", ")", ";", "}", "return", "true", ";", "case", "RADIUS_ACCESS_REJECT", ":", "return", "false", ";", "case", "RADIUS_ACCOUNTING_RESPONSE", ":", "if", "(", "is_subclass_of", "(", "$", "this", ",", "'auth_radius_pap'", ")", ")", "{", "throw", "new", "Auth_RADIUS_Exception", "(", "'RADIUS_ACCOUNTING_RESPONSE is unexpected for authentication'", ")", ";", "}", "return", "true", ";", "default", ":", "throw", "new", "Auth_RADIUS_Exception", "(", "\"Unexpected return value: $req\"", ")", ";", "}", "}" ]
Sends a prepared RADIUS request and waits for a response @return mixed true on success, false on reject, PEAR_Error on error
[ "Sends", "a", "prepared", "RADIUS", "request", "and", "waits", "for", "a", "response" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/Auth/RADIUS.php#L385-L412
219,955
moodle/moodle
lib/pear/Auth/RADIUS.php
Auth_RADIUS_PAP.putAuthAttributes
function putAuthAttributes() { if (isset($this->username)) { $this->putAttribute(RADIUS_USER_NAME, $this->username); } if (isset($this->password)) { $this->putAttribute(RADIUS_USER_PASSWORD, $this->password); } }
php
function putAuthAttributes() { if (isset($this->username)) { $this->putAttribute(RADIUS_USER_NAME, $this->username); } if (isset($this->password)) { $this->putAttribute(RADIUS_USER_PASSWORD, $this->password); } }
[ "function", "putAuthAttributes", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "username", ")", ")", "{", "$", "this", "->", "putAttribute", "(", "RADIUS_USER_NAME", ",", "$", "this", "->", "username", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "password", ")", ")", "{", "$", "this", "->", "putAttribute", "(", "RADIUS_USER_PASSWORD", ",", "$", "this", "->", "password", ")", ";", "}", "}" ]
Put authentication specific attributes @return void
[ "Put", "authentication", "specific", "attributes" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/Auth/RADIUS.php#L631-L639
219,956
moodle/moodle
lib/pear/Auth/RADIUS.php
Auth_RADIUS_CHAP_MD5.putAuthAttributes
function putAuthAttributes() { if (isset($this->username)) { $this->putAttribute(RADIUS_USER_NAME, $this->username); } if (isset($this->response)) { $response = pack('C', $this->chapid) . $this->response; $this->putAttribute(RADIUS_CHAP_PASSWORD, $response); } if (isset($this->challenge)) { $this->putAttribute(RADIUS_CHAP_CHALLENGE, $this->challenge); } }
php
function putAuthAttributes() { if (isset($this->username)) { $this->putAttribute(RADIUS_USER_NAME, $this->username); } if (isset($this->response)) { $response = pack('C', $this->chapid) . $this->response; $this->putAttribute(RADIUS_CHAP_PASSWORD, $response); } if (isset($this->challenge)) { $this->putAttribute(RADIUS_CHAP_CHALLENGE, $this->challenge); } }
[ "function", "putAuthAttributes", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "username", ")", ")", "{", "$", "this", "->", "putAttribute", "(", "RADIUS_USER_NAME", ",", "$", "this", "->", "username", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "response", ")", ")", "{", "$", "response", "=", "pack", "(", "'C'", ",", "$", "this", "->", "chapid", ")", ".", "$", "this", "->", "response", ";", "$", "this", "->", "putAttribute", "(", "RADIUS_CHAP_PASSWORD", ",", "$", "response", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "challenge", ")", ")", "{", "$", "this", "->", "putAttribute", "(", "RADIUS_CHAP_CHALLENGE", ",", "$", "this", "->", "challenge", ")", ";", "}", "}" ]
Put CHAP-MD5 specific attributes For authenticating using CHAP-MD5 via RADIUS you have to put the challenge and the response. The chapid is inserted in the first byte of the response. @return void
[ "Put", "CHAP", "-", "MD5", "specific", "attributes" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/Auth/RADIUS.php#L696-L708
219,957
moodle/moodle
lib/pear/Auth/RADIUS.php
Auth_RADIUS_MSCHAPv1.putAuthAttributes
function putAuthAttributes() { if (isset($this->username)) { $this->putAttribute(RADIUS_USER_NAME, $this->username); } if (isset($this->response) || isset($this->lmResponse)) { $lmResp = isset($this->lmResponse) ? $this->lmResponse : str_repeat ("\0", 24); $ntResp = isset($this->response) ? $this->response : str_repeat ("\0", 24); $resp = pack('CC', $this->chapid, $this->flags) . $lmResp . $ntResp; $this->putVendorAttribute(RADIUS_VENDOR_MICROSOFT, RADIUS_MICROSOFT_MS_CHAP_RESPONSE, $resp); } if (isset($this->challenge)) { $this->putVendorAttribute(RADIUS_VENDOR_MICROSOFT, RADIUS_MICROSOFT_MS_CHAP_CHALLENGE, $this->challenge); } }
php
function putAuthAttributes() { if (isset($this->username)) { $this->putAttribute(RADIUS_USER_NAME, $this->username); } if (isset($this->response) || isset($this->lmResponse)) { $lmResp = isset($this->lmResponse) ? $this->lmResponse : str_repeat ("\0", 24); $ntResp = isset($this->response) ? $this->response : str_repeat ("\0", 24); $resp = pack('CC', $this->chapid, $this->flags) . $lmResp . $ntResp; $this->putVendorAttribute(RADIUS_VENDOR_MICROSOFT, RADIUS_MICROSOFT_MS_CHAP_RESPONSE, $resp); } if (isset($this->challenge)) { $this->putVendorAttribute(RADIUS_VENDOR_MICROSOFT, RADIUS_MICROSOFT_MS_CHAP_CHALLENGE, $this->challenge); } }
[ "function", "putAuthAttributes", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "username", ")", ")", "{", "$", "this", "->", "putAttribute", "(", "RADIUS_USER_NAME", ",", "$", "this", "->", "username", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "response", ")", "||", "isset", "(", "$", "this", "->", "lmResponse", ")", ")", "{", "$", "lmResp", "=", "isset", "(", "$", "this", "->", "lmResponse", ")", "?", "$", "this", "->", "lmResponse", ":", "str_repeat", "(", "\"\\0\"", ",", "24", ")", ";", "$", "ntResp", "=", "isset", "(", "$", "this", "->", "response", ")", "?", "$", "this", "->", "response", ":", "str_repeat", "(", "\"\\0\"", ",", "24", ")", ";", "$", "resp", "=", "pack", "(", "'CC'", ",", "$", "this", "->", "chapid", ",", "$", "this", "->", "flags", ")", ".", "$", "lmResp", ".", "$", "ntResp", ";", "$", "this", "->", "putVendorAttribute", "(", "RADIUS_VENDOR_MICROSOFT", ",", "RADIUS_MICROSOFT_MS_CHAP_RESPONSE", ",", "$", "resp", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "challenge", ")", ")", "{", "$", "this", "->", "putVendorAttribute", "(", "RADIUS_VENDOR_MICROSOFT", ",", "RADIUS_MICROSOFT_MS_CHAP_CHALLENGE", ",", "$", "this", "->", "challenge", ")", ";", "}", "}" ]
Put MS-CHAPv1 specific attributes For authenticating using MS-CHAPv1 via RADIUS you have to put the challenge and the response. The response has this structure: struct rad_mschapvalue { u_char ident; u_char flags; u_char lm_response[24]; u_char response[24]; }; @return void
[ "Put", "MS", "-", "CHAPv1", "specific", "attributes" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/Auth/RADIUS.php#L761-L775
219,958
moodle/moodle
lib/pear/Auth/RADIUS.php
Auth_RADIUS_MSCHAPv2.putAuthAttributes
function putAuthAttributes() { if (isset($this->username)) { $this->putAttribute(RADIUS_USER_NAME, $this->username); } if (isset($this->response) && isset($this->peerChallenge)) { // Response: chapid, flags (1 = use NT Response), Peer challenge, reserved, Response $resp = pack('CCa16a8a24',$this->chapid , 1, $this->peerChallenge, str_repeat("\0", 8), $this->response); $this->putVendorAttribute(RADIUS_VENDOR_MICROSOFT, RADIUS_MICROSOFT_MS_CHAP2_RESPONSE, $resp); } if (isset($this->challenge)) { $this->putVendorAttribute(RADIUS_VENDOR_MICROSOFT, RADIUS_MICROSOFT_MS_CHAP_CHALLENGE, $this->challenge); } }
php
function putAuthAttributes() { if (isset($this->username)) { $this->putAttribute(RADIUS_USER_NAME, $this->username); } if (isset($this->response) && isset($this->peerChallenge)) { // Response: chapid, flags (1 = use NT Response), Peer challenge, reserved, Response $resp = pack('CCa16a8a24',$this->chapid , 1, $this->peerChallenge, str_repeat("\0", 8), $this->response); $this->putVendorAttribute(RADIUS_VENDOR_MICROSOFT, RADIUS_MICROSOFT_MS_CHAP2_RESPONSE, $resp); } if (isset($this->challenge)) { $this->putVendorAttribute(RADIUS_VENDOR_MICROSOFT, RADIUS_MICROSOFT_MS_CHAP_CHALLENGE, $this->challenge); } }
[ "function", "putAuthAttributes", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "username", ")", ")", "{", "$", "this", "->", "putAttribute", "(", "RADIUS_USER_NAME", ",", "$", "this", "->", "username", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "response", ")", "&&", "isset", "(", "$", "this", "->", "peerChallenge", ")", ")", "{", "// Response: chapid, flags (1 = use NT Response), Peer challenge, reserved, Response", "$", "resp", "=", "pack", "(", "'CCa16a8a24'", ",", "$", "this", "->", "chapid", ",", "1", ",", "$", "this", "->", "peerChallenge", ",", "str_repeat", "(", "\"\\0\"", ",", "8", ")", ",", "$", "this", "->", "response", ")", ";", "$", "this", "->", "putVendorAttribute", "(", "RADIUS_VENDOR_MICROSOFT", ",", "RADIUS_MICROSOFT_MS_CHAP2_RESPONSE", ",", "$", "resp", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "challenge", ")", ")", "{", "$", "this", "->", "putVendorAttribute", "(", "RADIUS_VENDOR_MICROSOFT", ",", "RADIUS_MICROSOFT_MS_CHAP_CHALLENGE", ",", "$", "this", "->", "challenge", ")", ";", "}", "}" ]
Put MS-CHAPv2 specific attributes For authenticating using MS-CHAPv1 via RADIUS you have to put the challenge and the response. The response has this structure: struct rad_mschapv2value { u_char ident; u_char flags; u_char pchallenge[16]; u_char reserved[8]; u_char response[24]; }; where pchallenge is the peer challenge. Like for MS-CHAPv1 we set the flags field to 1. @return void
[ "Put", "MS", "-", "CHAPv2", "specific", "attributes" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/Auth/RADIUS.php#L814-L827
219,959
moodle/moodle
lib/pear/Auth/RADIUS.php
Auth_RADIUS_Acct.putAuthAttributes
function putAuthAttributes() { $this->putAttribute(RADIUS_ACCT_SESSION_ID, $this->session_id); $this->putAttribute(RADIUS_ACCT_STATUS_TYPE, $this->status_type); if (isset($this->session_time) && $this->status_type == RADIUS_STOP) { $this->putAttribute(RADIUS_ACCT_SESSION_TIME, $this->session_time); } if (isset($this->authentic)) { $this->putAttribute(RADIUS_ACCT_AUTHENTIC, $this->authentic); } }
php
function putAuthAttributes() { $this->putAttribute(RADIUS_ACCT_SESSION_ID, $this->session_id); $this->putAttribute(RADIUS_ACCT_STATUS_TYPE, $this->status_type); if (isset($this->session_time) && $this->status_type == RADIUS_STOP) { $this->putAttribute(RADIUS_ACCT_SESSION_TIME, $this->session_time); } if (isset($this->authentic)) { $this->putAttribute(RADIUS_ACCT_AUTHENTIC, $this->authentic); } }
[ "function", "putAuthAttributes", "(", ")", "{", "$", "this", "->", "putAttribute", "(", "RADIUS_ACCT_SESSION_ID", ",", "$", "this", "->", "session_id", ")", ";", "$", "this", "->", "putAttribute", "(", "RADIUS_ACCT_STATUS_TYPE", ",", "$", "this", "->", "status_type", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "session_time", ")", "&&", "$", "this", "->", "status_type", "==", "RADIUS_STOP", ")", "{", "$", "this", "->", "putAttribute", "(", "RADIUS_ACCT_SESSION_TIME", ",", "$", "this", "->", "session_time", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "authentic", ")", ")", "{", "$", "this", "->", "putAttribute", "(", "RADIUS_ACCT_AUTHENTIC", ",", "$", "this", "->", "authentic", ")", ";", "}", "}" ]
Put attributes for accounting. Here we put some accounting values. There many more attributes for accounting, but for web-applications only certain attributes make sense. @return void
[ "Put", "attributes", "for", "accounting", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/Auth/RADIUS.php#L938-L949
219,960
moodle/moodle
calendar/classes/external/week_day_exporter.php
week_day_exporter.get_popover_title
protected function get_popover_title() { $title = null; $userdate = userdate($this->data[0], get_string('strftimedayshort')); if (count($this->related['events'])) { $title = get_string('eventsfor', 'calendar', $userdate); } else if ($this->data['istoday']) { $title = $userdate; } if ($this->data['istoday']) { $title = get_string('todayplustitle', 'calendar', $userdate); } return $title; }
php
protected function get_popover_title() { $title = null; $userdate = userdate($this->data[0], get_string('strftimedayshort')); if (count($this->related['events'])) { $title = get_string('eventsfor', 'calendar', $userdate); } else if ($this->data['istoday']) { $title = $userdate; } if ($this->data['istoday']) { $title = get_string('todayplustitle', 'calendar', $userdate); } return $title; }
[ "protected", "function", "get_popover_title", "(", ")", "{", "$", "title", "=", "null", ";", "$", "userdate", "=", "userdate", "(", "$", "this", "->", "data", "[", "0", "]", ",", "get_string", "(", "'strftimedayshort'", ")", ")", ";", "if", "(", "count", "(", "$", "this", "->", "related", "[", "'events'", "]", ")", ")", "{", "$", "title", "=", "get_string", "(", "'eventsfor'", ",", "'calendar'", ",", "$", "userdate", ")", ";", "}", "else", "if", "(", "$", "this", "->", "data", "[", "'istoday'", "]", ")", "{", "$", "title", "=", "$", "userdate", ";", "}", "if", "(", "$", "this", "->", "data", "[", "'istoday'", "]", ")", "{", "$", "title", "=", "get_string", "(", "'todayplustitle'", ",", "'calendar'", ",", "$", "userdate", ")", ";", "}", "return", "$", "title", ";", "}" ]
Get the title for this popover. @return string
[ "Get", "the", "title", "for", "this", "popover", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/external/week_day_exporter.php#L128-L143
219,961
moodle/moodle
admin/tool/log/classes/privacy/provider.php
provider.call_subplugins_method_with_args
protected static function call_subplugins_method_with_args($method, array $args = [], string $interface = null) { if (!isset($interface)) { $interface = \tool_log\local\privacy\logstore_provider::class; } \core_privacy\manager::plugintype_class_callback('logstore', $interface, $method, $args); }
php
protected static function call_subplugins_method_with_args($method, array $args = [], string $interface = null) { if (!isset($interface)) { $interface = \tool_log\local\privacy\logstore_provider::class; } \core_privacy\manager::plugintype_class_callback('logstore', $interface, $method, $args); }
[ "protected", "static", "function", "call_subplugins_method_with_args", "(", "$", "method", ",", "array", "$", "args", "=", "[", "]", ",", "string", "$", "interface", "=", "null", ")", "{", "if", "(", "!", "isset", "(", "$", "interface", ")", ")", "{", "$", "interface", "=", "\\", "tool_log", "\\", "local", "\\", "privacy", "\\", "logstore_provider", "::", "class", ";", "}", "\\", "core_privacy", "\\", "manager", "::", "plugintype_class_callback", "(", "'logstore'", ",", "$", "interface", ",", "$", "method", ",", "$", "args", ")", ";", "}" ]
Invoke the subplugins method with arguments. @param string $method The method name. @param array $args The arguments. @param string $interface The interface to use. By default uses the logstore_provider. @return void
[ "Invoke", "the", "subplugins", "method", "with", "arguments", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/log/classes/privacy/provider.php#L131-L136
219,962
moodle/moodle
lib/phpexcel/PHPExcel/Writer/OpenDocument.php
PHPExcel_Writer_OpenDocument.createZip
private function createZip($pFilename) { // Create new ZIP file and open it for writing $zipClass = PHPExcel_Settings::getZipClass(); $objZip = new $zipClass(); // Retrieve OVERWRITE and CREATE constants from the instantiated zip class // This method of accessing constant values from a dynamic class should work with all appropriate versions of PHP $ro = new ReflectionObject($objZip); $zipOverWrite = $ro->getConstant('OVERWRITE'); $zipCreate = $ro->getConstant('CREATE'); if (file_exists($pFilename)) { unlink($pFilename); } // Try opening the ZIP file if ($objZip->open($pFilename, $zipOverWrite) !== true) { if ($objZip->open($pFilename, $zipCreate) !== true) { throw new PHPExcel_Writer_Exception("Could not open $pFilename for writing."); } } return $objZip; }
php
private function createZip($pFilename) { // Create new ZIP file and open it for writing $zipClass = PHPExcel_Settings::getZipClass(); $objZip = new $zipClass(); // Retrieve OVERWRITE and CREATE constants from the instantiated zip class // This method of accessing constant values from a dynamic class should work with all appropriate versions of PHP $ro = new ReflectionObject($objZip); $zipOverWrite = $ro->getConstant('OVERWRITE'); $zipCreate = $ro->getConstant('CREATE'); if (file_exists($pFilename)) { unlink($pFilename); } // Try opening the ZIP file if ($objZip->open($pFilename, $zipOverWrite) !== true) { if ($objZip->open($pFilename, $zipCreate) !== true) { throw new PHPExcel_Writer_Exception("Could not open $pFilename for writing."); } } return $objZip; }
[ "private", "function", "createZip", "(", "$", "pFilename", ")", "{", "// Create new ZIP file and open it for writing", "$", "zipClass", "=", "PHPExcel_Settings", "::", "getZipClass", "(", ")", ";", "$", "objZip", "=", "new", "$", "zipClass", "(", ")", ";", "// Retrieve OVERWRITE and CREATE constants from the instantiated zip class", "// This method of accessing constant values from a dynamic class should work with all appropriate versions of PHP", "$", "ro", "=", "new", "ReflectionObject", "(", "$", "objZip", ")", ";", "$", "zipOverWrite", "=", "$", "ro", "->", "getConstant", "(", "'OVERWRITE'", ")", ";", "$", "zipCreate", "=", "$", "ro", "->", "getConstant", "(", "'CREATE'", ")", ";", "if", "(", "file_exists", "(", "$", "pFilename", ")", ")", "{", "unlink", "(", "$", "pFilename", ")", ";", "}", "// Try opening the ZIP file", "if", "(", "$", "objZip", "->", "open", "(", "$", "pFilename", ",", "$", "zipOverWrite", ")", "!==", "true", ")", "{", "if", "(", "$", "objZip", "->", "open", "(", "$", "pFilename", ",", "$", "zipCreate", ")", "!==", "true", ")", "{", "throw", "new", "PHPExcel_Writer_Exception", "(", "\"Could not open $pFilename for writing.\"", ")", ";", "}", "}", "return", "$", "objZip", ";", "}" ]
Create zip object @param string $pFilename @throws PHPExcel_Writer_Exception @return ZipArchive
[ "Create", "zip", "object" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Writer/OpenDocument.php#L138-L161
219,963
moodle/moodle
lib/horde/framework/Horde/Imap/Client/Ids/Pop3.php
Horde_Imap_Client_Ids_Pop3._toSequenceString
protected function _toSequenceString($sort = true) { /* $sort is ignored - see _sort(). */ /* Use space as delimiter as it is the only printable ASCII character * that is not allowed as part of the UID (RFC 1939 [7]). */ return implode(' ', count($this->_ids) > 25000 ? array_unique($this->_ids) : array_keys(array_flip($this->_ids))); }
php
protected function _toSequenceString($sort = true) { /* $sort is ignored - see _sort(). */ /* Use space as delimiter as it is the only printable ASCII character * that is not allowed as part of the UID (RFC 1939 [7]). */ return implode(' ', count($this->_ids) > 25000 ? array_unique($this->_ids) : array_keys(array_flip($this->_ids))); }
[ "protected", "function", "_toSequenceString", "(", "$", "sort", "=", "true", ")", "{", "/* $sort is ignored - see _sort(). */", "/* Use space as delimiter as it is the only printable ASCII character\n * that is not allowed as part of the UID (RFC 1939 [7]). */", "return", "implode", "(", "' '", ",", "count", "(", "$", "this", "->", "_ids", ")", ">", "25000", "?", "array_unique", "(", "$", "this", "->", "_ids", ")", ":", "array_keys", "(", "array_flip", "(", "$", "this", "->", "_ids", ")", ")", ")", ";", "}" ]
Create a POP3 message sequence string. Index Format: UID1[SPACE]UID2... @param boolean $sort Not used in this class. @return string The POP3 message sequence string.
[ "Create", "a", "POP3", "message", "sequence", "string", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Ids/Pop3.php#L43-L50
219,964
moodle/moodle
blocks/timeline/classes/output/main.php
main.get_filters_as_booleans
protected function get_filters_as_booleans() { $filters = [ BLOCK_TIMELINE_FILTER_BY_NONE => false, BLOCK_TIMELINE_FILTER_BY_OVERDUE => false, BLOCK_TIMELINE_FILTER_BY_7_DAYS => false, BLOCK_TIMELINE_FILTER_BY_30_DAYS => false, BLOCK_TIMELINE_FILTER_BY_3_MONTHS => false, BLOCK_TIMELINE_FILTER_BY_6_MONTHS => false ]; // Set the selected filter to true. $filters[$this->filter] = true; return $filters; }
php
protected function get_filters_as_booleans() { $filters = [ BLOCK_TIMELINE_FILTER_BY_NONE => false, BLOCK_TIMELINE_FILTER_BY_OVERDUE => false, BLOCK_TIMELINE_FILTER_BY_7_DAYS => false, BLOCK_TIMELINE_FILTER_BY_30_DAYS => false, BLOCK_TIMELINE_FILTER_BY_3_MONTHS => false, BLOCK_TIMELINE_FILTER_BY_6_MONTHS => false ]; // Set the selected filter to true. $filters[$this->filter] = true; return $filters; }
[ "protected", "function", "get_filters_as_booleans", "(", ")", "{", "$", "filters", "=", "[", "BLOCK_TIMELINE_FILTER_BY_NONE", "=>", "false", ",", "BLOCK_TIMELINE_FILTER_BY_OVERDUE", "=>", "false", ",", "BLOCK_TIMELINE_FILTER_BY_7_DAYS", "=>", "false", ",", "BLOCK_TIMELINE_FILTER_BY_30_DAYS", "=>", "false", ",", "BLOCK_TIMELINE_FILTER_BY_3_MONTHS", "=>", "false", ",", "BLOCK_TIMELINE_FILTER_BY_6_MONTHS", "=>", "false", "]", ";", "// Set the selected filter to true.", "$", "filters", "[", "$", "this", "->", "filter", "]", "=", "true", ";", "return", "$", "filters", ";", "}" ]
Test the available filters with the current user preference and return an array with bool flags corresponding to which is active @return array
[ "Test", "the", "available", "filters", "with", "the", "current", "user", "preference", "and", "return", "an", "array", "with", "bool", "flags", "corresponding", "to", "which", "is", "active" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/timeline/classes/output/main.php#L81-L95
219,965
moodle/moodle
lib/classes/oauth2/refresh_system_tokens_task.php
refresh_system_tokens_task.notify_admins
protected function notify_admins(\core\oauth2\issuer $issuer) { global $CFG; $admins = get_admins(); if (empty($admins)) { return; } foreach ($admins as $admin) { $strparams = ['siteurl' => $CFG->wwwroot, 'issuer' => $issuer->get('name')]; $long = get_string('oauthrefreshtokenexpired', 'core_admin', $strparams); $short = get_string('oauthrefreshtokenexpiredshort', 'core_admin', $strparams); $message = new \core\message\message(); $message->courseid = SITEID; $message->component = 'moodle'; $message->name = 'errors'; $message->userfrom = core_user::get_noreply_user(); $message->userto = $admin; $message->subject = $short; $message->fullmessage = $long; $message->fullmessageformat = FORMAT_PLAIN; $message->fullmessagehtml = $long; $message->smallmessage = $short; $message->notification = 1; message_send($message); } }
php
protected function notify_admins(\core\oauth2\issuer $issuer) { global $CFG; $admins = get_admins(); if (empty($admins)) { return; } foreach ($admins as $admin) { $strparams = ['siteurl' => $CFG->wwwroot, 'issuer' => $issuer->get('name')]; $long = get_string('oauthrefreshtokenexpired', 'core_admin', $strparams); $short = get_string('oauthrefreshtokenexpiredshort', 'core_admin', $strparams); $message = new \core\message\message(); $message->courseid = SITEID; $message->component = 'moodle'; $message->name = 'errors'; $message->userfrom = core_user::get_noreply_user(); $message->userto = $admin; $message->subject = $short; $message->fullmessage = $long; $message->fullmessageformat = FORMAT_PLAIN; $message->fullmessagehtml = $long; $message->smallmessage = $short; $message->notification = 1; message_send($message); } }
[ "protected", "function", "notify_admins", "(", "\\", "core", "\\", "oauth2", "\\", "issuer", "$", "issuer", ")", "{", "global", "$", "CFG", ";", "$", "admins", "=", "get_admins", "(", ")", ";", "if", "(", "empty", "(", "$", "admins", ")", ")", "{", "return", ";", "}", "foreach", "(", "$", "admins", "as", "$", "admin", ")", "{", "$", "strparams", "=", "[", "'siteurl'", "=>", "$", "CFG", "->", "wwwroot", ",", "'issuer'", "=>", "$", "issuer", "->", "get", "(", "'name'", ")", "]", ";", "$", "long", "=", "get_string", "(", "'oauthrefreshtokenexpired'", ",", "'core_admin'", ",", "$", "strparams", ")", ";", "$", "short", "=", "get_string", "(", "'oauthrefreshtokenexpiredshort'", ",", "'core_admin'", ",", "$", "strparams", ")", ";", "$", "message", "=", "new", "\\", "core", "\\", "message", "\\", "message", "(", ")", ";", "$", "message", "->", "courseid", "=", "SITEID", ";", "$", "message", "->", "component", "=", "'moodle'", ";", "$", "message", "->", "name", "=", "'errors'", ";", "$", "message", "->", "userfrom", "=", "core_user", "::", "get_noreply_user", "(", ")", ";", "$", "message", "->", "userto", "=", "$", "admin", ";", "$", "message", "->", "subject", "=", "$", "short", ";", "$", "message", "->", "fullmessage", "=", "$", "long", ";", "$", "message", "->", "fullmessageformat", "=", "FORMAT_PLAIN", ";", "$", "message", "->", "fullmessagehtml", "=", "$", "long", ";", "$", "message", "->", "smallmessage", "=", "$", "short", ";", "$", "message", "->", "notification", "=", "1", ";", "message_send", "(", "$", "message", ")", ";", "}", "}" ]
Notify admins when an OAuth refresh token expires. Should not happen if cron is running regularly. @param \core\oauth2\issuer $issuer
[ "Notify", "admins", "when", "an", "OAuth", "refresh", "token", "expires", ".", "Should", "not", "happen", "if", "cron", "is", "running", "regularly", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/oauth2/refresh_system_tokens_task.php#L54-L79
219,966
moodle/moodle
lib/form/filemanager.php
MoodleQuickForm_filemanager.setMaxbytes
function setMaxbytes($maxbytes) { global $CFG, $PAGE; $this->_options['maxbytes'] = get_user_max_upload_file_size($PAGE->context, $CFG->maxbytes, $maxbytes); }
php
function setMaxbytes($maxbytes) { global $CFG, $PAGE; $this->_options['maxbytes'] = get_user_max_upload_file_size($PAGE->context, $CFG->maxbytes, $maxbytes); }
[ "function", "setMaxbytes", "(", "$", "maxbytes", ")", "{", "global", "$", "CFG", ",", "$", "PAGE", ";", "$", "this", "->", "_options", "[", "'maxbytes'", "]", "=", "get_user_max_upload_file_size", "(", "$", "PAGE", "->", "context", ",", "$", "CFG", "->", "maxbytes", ",", "$", "maxbytes", ")", ";", "}" ]
Sets maximum file size which can be uploaded @param int $maxbytes file size
[ "Sets", "maximum", "file", "size", "which", "can", "be", "uploaded" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/filemanager.php#L165-L168
219,967
moodle/moodle
lib/form/filemanager.php
MoodleQuickForm_filemanager.toHtml
function toHtml() { global $CFG, $USER, $COURSE, $PAGE, $OUTPUT; require_once("$CFG->dirroot/repository/lib.php"); // security - never ever allow guest/not logged in user to upload anything or use this element! if (isguestuser() or !isloggedin()) { print_error('noguest'); } if ($this->_flagFrozen) { return $this->getFrozenHtml(); } $id = $this->_attributes['id']; $elname = $this->_attributes['name']; $subdirs = $this->_options['subdirs']; $maxbytes = $this->_options['maxbytes']; $draftitemid = $this->getValue(); $accepted_types = $this->_options['accepted_types']; if (empty($draftitemid)) { // no existing area info provided - let's use fresh new draft area require_once("$CFG->libdir/filelib.php"); $this->setValue(file_get_unused_draft_itemid()); $draftitemid = $this->getValue(); } $client_id = uniqid(); // filemanager options $options = new stdClass(); $options->mainfile = $this->_options['mainfile']; $options->maxbytes = $this->_options['maxbytes']; $options->maxfiles = $this->getMaxfiles(); $options->client_id = $client_id; $options->itemid = $draftitemid; $options->subdirs = $this->_options['subdirs']; $options->target = $id; $options->accepted_types = $accepted_types; $options->return_types = $this->_options['return_types']; $options->context = $PAGE->context; $options->areamaxbytes = $this->_options['areamaxbytes']; $html = $this->_getTabs(); $fm = new form_filemanager($options); $output = $PAGE->get_renderer('core', 'files'); $html .= $output->render($fm); $html .= html_writer::empty_tag('input', array('value' => $draftitemid, 'name' => $elname, 'type' => 'hidden', 'id' => $id)); if (!empty($options->accepted_types) && $options->accepted_types != '*') { $html .= html_writer::tag('p', get_string('filesofthesetypes', 'form')); $util = new \core_form\filetypes_util(); $filetypes = $options->accepted_types; $filetypedescriptions = $util->describe_file_types($filetypes); $html .= $OUTPUT->render_from_template('core_form/filetypes-descriptions', $filetypedescriptions); } return $html; }
php
function toHtml() { global $CFG, $USER, $COURSE, $PAGE, $OUTPUT; require_once("$CFG->dirroot/repository/lib.php"); // security - never ever allow guest/not logged in user to upload anything or use this element! if (isguestuser() or !isloggedin()) { print_error('noguest'); } if ($this->_flagFrozen) { return $this->getFrozenHtml(); } $id = $this->_attributes['id']; $elname = $this->_attributes['name']; $subdirs = $this->_options['subdirs']; $maxbytes = $this->_options['maxbytes']; $draftitemid = $this->getValue(); $accepted_types = $this->_options['accepted_types']; if (empty($draftitemid)) { // no existing area info provided - let's use fresh new draft area require_once("$CFG->libdir/filelib.php"); $this->setValue(file_get_unused_draft_itemid()); $draftitemid = $this->getValue(); } $client_id = uniqid(); // filemanager options $options = new stdClass(); $options->mainfile = $this->_options['mainfile']; $options->maxbytes = $this->_options['maxbytes']; $options->maxfiles = $this->getMaxfiles(); $options->client_id = $client_id; $options->itemid = $draftitemid; $options->subdirs = $this->_options['subdirs']; $options->target = $id; $options->accepted_types = $accepted_types; $options->return_types = $this->_options['return_types']; $options->context = $PAGE->context; $options->areamaxbytes = $this->_options['areamaxbytes']; $html = $this->_getTabs(); $fm = new form_filemanager($options); $output = $PAGE->get_renderer('core', 'files'); $html .= $output->render($fm); $html .= html_writer::empty_tag('input', array('value' => $draftitemid, 'name' => $elname, 'type' => 'hidden', 'id' => $id)); if (!empty($options->accepted_types) && $options->accepted_types != '*') { $html .= html_writer::tag('p', get_string('filesofthesetypes', 'form')); $util = new \core_form\filetypes_util(); $filetypes = $options->accepted_types; $filetypedescriptions = $util->describe_file_types($filetypes); $html .= $OUTPUT->render_from_template('core_form/filetypes-descriptions', $filetypedescriptions); } return $html; }
[ "function", "toHtml", "(", ")", "{", "global", "$", "CFG", ",", "$", "USER", ",", "$", "COURSE", ",", "$", "PAGE", ",", "$", "OUTPUT", ";", "require_once", "(", "\"$CFG->dirroot/repository/lib.php\"", ")", ";", "// security - never ever allow guest/not logged in user to upload anything or use this element!", "if", "(", "isguestuser", "(", ")", "or", "!", "isloggedin", "(", ")", ")", "{", "print_error", "(", "'noguest'", ")", ";", "}", "if", "(", "$", "this", "->", "_flagFrozen", ")", "{", "return", "$", "this", "->", "getFrozenHtml", "(", ")", ";", "}", "$", "id", "=", "$", "this", "->", "_attributes", "[", "'id'", "]", ";", "$", "elname", "=", "$", "this", "->", "_attributes", "[", "'name'", "]", ";", "$", "subdirs", "=", "$", "this", "->", "_options", "[", "'subdirs'", "]", ";", "$", "maxbytes", "=", "$", "this", "->", "_options", "[", "'maxbytes'", "]", ";", "$", "draftitemid", "=", "$", "this", "->", "getValue", "(", ")", ";", "$", "accepted_types", "=", "$", "this", "->", "_options", "[", "'accepted_types'", "]", ";", "if", "(", "empty", "(", "$", "draftitemid", ")", ")", "{", "// no existing area info provided - let's use fresh new draft area", "require_once", "(", "\"$CFG->libdir/filelib.php\"", ")", ";", "$", "this", "->", "setValue", "(", "file_get_unused_draft_itemid", "(", ")", ")", ";", "$", "draftitemid", "=", "$", "this", "->", "getValue", "(", ")", ";", "}", "$", "client_id", "=", "uniqid", "(", ")", ";", "// filemanager options", "$", "options", "=", "new", "stdClass", "(", ")", ";", "$", "options", "->", "mainfile", "=", "$", "this", "->", "_options", "[", "'mainfile'", "]", ";", "$", "options", "->", "maxbytes", "=", "$", "this", "->", "_options", "[", "'maxbytes'", "]", ";", "$", "options", "->", "maxfiles", "=", "$", "this", "->", "getMaxfiles", "(", ")", ";", "$", "options", "->", "client_id", "=", "$", "client_id", ";", "$", "options", "->", "itemid", "=", "$", "draftitemid", ";", "$", "options", "->", "subdirs", "=", "$", "this", "->", "_options", "[", "'subdirs'", "]", ";", "$", "options", "->", "target", "=", "$", "id", ";", "$", "options", "->", "accepted_types", "=", "$", "accepted_types", ";", "$", "options", "->", "return_types", "=", "$", "this", "->", "_options", "[", "'return_types'", "]", ";", "$", "options", "->", "context", "=", "$", "PAGE", "->", "context", ";", "$", "options", "->", "areamaxbytes", "=", "$", "this", "->", "_options", "[", "'areamaxbytes'", "]", ";", "$", "html", "=", "$", "this", "->", "_getTabs", "(", ")", ";", "$", "fm", "=", "new", "form_filemanager", "(", "$", "options", ")", ";", "$", "output", "=", "$", "PAGE", "->", "get_renderer", "(", "'core'", ",", "'files'", ")", ";", "$", "html", ".=", "$", "output", "->", "render", "(", "$", "fm", ")", ";", "$", "html", ".=", "html_writer", "::", "empty_tag", "(", "'input'", ",", "array", "(", "'value'", "=>", "$", "draftitemid", ",", "'name'", "=>", "$", "elname", ",", "'type'", "=>", "'hidden'", ",", "'id'", "=>", "$", "id", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "options", "->", "accepted_types", ")", "&&", "$", "options", "->", "accepted_types", "!=", "'*'", ")", "{", "$", "html", ".=", "html_writer", "::", "tag", "(", "'p'", ",", "get_string", "(", "'filesofthesetypes'", ",", "'form'", ")", ")", ";", "$", "util", "=", "new", "\\", "core_form", "\\", "filetypes_util", "(", ")", ";", "$", "filetypes", "=", "$", "options", "->", "accepted_types", ";", "$", "filetypedescriptions", "=", "$", "util", "->", "describe_file_types", "(", "$", "filetypes", ")", ";", "$", "html", ".=", "$", "OUTPUT", "->", "render_from_template", "(", "'core_form/filetypes-descriptions'", ",", "$", "filetypedescriptions", ")", ";", "}", "return", "$", "html", ";", "}" ]
Returns HTML for filemanager form element. @return string
[ "Returns", "HTML", "for", "filemanager", "form", "element", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/filemanager.php#L251-L310
219,968
moodle/moodle
lib/form/filemanager.php
MoodleQuickForm_filemanager.validateSubmitValue
public function validateSubmitValue($value) { if (empty($value)) { return; } $filetypesutil = new \core_form\filetypes_util(); $whitelist = $filetypesutil->normalize_file_types($this->_options['accepted_types']); if (empty($whitelist) || $whitelist === ['*']) { // Any file type is allowed, nothing to check here. return; } $draftfiles = file_get_all_files_in_draftarea($value); $wrongfiles = array(); if (empty($draftfiles)) { // No file uploaded, nothing to check here. return; } foreach ($draftfiles as $file) { if (!$filetypesutil->is_allowed_file_type($file->filename, $whitelist)) { $wrongfiles[] = $file->filename; } } if ($wrongfiles) { $a = array( 'whitelist' => implode(', ', $whitelist), 'wrongfiles' => implode(', ', $wrongfiles), ); return get_string('err_wrongfileextension', 'core_form', $a); } return; }
php
public function validateSubmitValue($value) { if (empty($value)) { return; } $filetypesutil = new \core_form\filetypes_util(); $whitelist = $filetypesutil->normalize_file_types($this->_options['accepted_types']); if (empty($whitelist) || $whitelist === ['*']) { // Any file type is allowed, nothing to check here. return; } $draftfiles = file_get_all_files_in_draftarea($value); $wrongfiles = array(); if (empty($draftfiles)) { // No file uploaded, nothing to check here. return; } foreach ($draftfiles as $file) { if (!$filetypesutil->is_allowed_file_type($file->filename, $whitelist)) { $wrongfiles[] = $file->filename; } } if ($wrongfiles) { $a = array( 'whitelist' => implode(', ', $whitelist), 'wrongfiles' => implode(', ', $wrongfiles), ); return get_string('err_wrongfileextension', 'core_form', $a); } return; }
[ "public", "function", "validateSubmitValue", "(", "$", "value", ")", "{", "if", "(", "empty", "(", "$", "value", ")", ")", "{", "return", ";", "}", "$", "filetypesutil", "=", "new", "\\", "core_form", "\\", "filetypes_util", "(", ")", ";", "$", "whitelist", "=", "$", "filetypesutil", "->", "normalize_file_types", "(", "$", "this", "->", "_options", "[", "'accepted_types'", "]", ")", ";", "if", "(", "empty", "(", "$", "whitelist", ")", "||", "$", "whitelist", "===", "[", "'*'", "]", ")", "{", "// Any file type is allowed, nothing to check here.", "return", ";", "}", "$", "draftfiles", "=", "file_get_all_files_in_draftarea", "(", "$", "value", ")", ";", "$", "wrongfiles", "=", "array", "(", ")", ";", "if", "(", "empty", "(", "$", "draftfiles", ")", ")", "{", "// No file uploaded, nothing to check here.", "return", ";", "}", "foreach", "(", "$", "draftfiles", "as", "$", "file", ")", "{", "if", "(", "!", "$", "filetypesutil", "->", "is_allowed_file_type", "(", "$", "file", "->", "filename", ",", "$", "whitelist", ")", ")", "{", "$", "wrongfiles", "[", "]", "=", "$", "file", "->", "filename", ";", "}", "}", "if", "(", "$", "wrongfiles", ")", "{", "$", "a", "=", "array", "(", "'whitelist'", "=>", "implode", "(", "', '", ",", "$", "whitelist", ")", ",", "'wrongfiles'", "=>", "implode", "(", "', '", ",", "$", "wrongfiles", ")", ",", ")", ";", "return", "get_string", "(", "'err_wrongfileextension'", ",", "'core_form'", ",", "$", "a", ")", ";", "}", "return", ";", "}" ]
Check that all files have the allowed type. @param int $value Draft item id with the uploaded files. @return string|null Validation error message or null.
[ "Check", "that", "all", "files", "have", "the", "allowed", "type", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/filemanager.php#L324-L361
219,969
moodle/moodle
lib/htmlpurifier/HTMLPurifier/Lexer/DOMLex.php
HTMLPurifier_Lexer_DOMLex.tokenizeDOM
protected function tokenizeDOM($node, &$tokens, $config) { $level = 0; $nodes = array($level => new HTMLPurifier_Queue(array($node))); $closingNodes = array(); do { while (!$nodes[$level]->isEmpty()) { $node = $nodes[$level]->shift(); // FIFO $collect = $level > 0 ? true : false; $needEndingTag = $this->createStartNode($node, $tokens, $collect, $config); if ($needEndingTag) { $closingNodes[$level][] = $node; } if ($node->childNodes && $node->childNodes->length) { $level++; $nodes[$level] = new HTMLPurifier_Queue(); foreach ($node->childNodes as $childNode) { $nodes[$level]->push($childNode); } } } $level--; if ($level && isset($closingNodes[$level])) { while ($node = array_pop($closingNodes[$level])) { $this->createEndNode($node, $tokens); } } } while ($level > 0); }
php
protected function tokenizeDOM($node, &$tokens, $config) { $level = 0; $nodes = array($level => new HTMLPurifier_Queue(array($node))); $closingNodes = array(); do { while (!$nodes[$level]->isEmpty()) { $node = $nodes[$level]->shift(); // FIFO $collect = $level > 0 ? true : false; $needEndingTag = $this->createStartNode($node, $tokens, $collect, $config); if ($needEndingTag) { $closingNodes[$level][] = $node; } if ($node->childNodes && $node->childNodes->length) { $level++; $nodes[$level] = new HTMLPurifier_Queue(); foreach ($node->childNodes as $childNode) { $nodes[$level]->push($childNode); } } } $level--; if ($level && isset($closingNodes[$level])) { while ($node = array_pop($closingNodes[$level])) { $this->createEndNode($node, $tokens); } } } while ($level > 0); }
[ "protected", "function", "tokenizeDOM", "(", "$", "node", ",", "&", "$", "tokens", ",", "$", "config", ")", "{", "$", "level", "=", "0", ";", "$", "nodes", "=", "array", "(", "$", "level", "=>", "new", "HTMLPurifier_Queue", "(", "array", "(", "$", "node", ")", ")", ")", ";", "$", "closingNodes", "=", "array", "(", ")", ";", "do", "{", "while", "(", "!", "$", "nodes", "[", "$", "level", "]", "->", "isEmpty", "(", ")", ")", "{", "$", "node", "=", "$", "nodes", "[", "$", "level", "]", "->", "shift", "(", ")", ";", "// FIFO", "$", "collect", "=", "$", "level", ">", "0", "?", "true", ":", "false", ";", "$", "needEndingTag", "=", "$", "this", "->", "createStartNode", "(", "$", "node", ",", "$", "tokens", ",", "$", "collect", ",", "$", "config", ")", ";", "if", "(", "$", "needEndingTag", ")", "{", "$", "closingNodes", "[", "$", "level", "]", "[", "]", "=", "$", "node", ";", "}", "if", "(", "$", "node", "->", "childNodes", "&&", "$", "node", "->", "childNodes", "->", "length", ")", "{", "$", "level", "++", ";", "$", "nodes", "[", "$", "level", "]", "=", "new", "HTMLPurifier_Queue", "(", ")", ";", "foreach", "(", "$", "node", "->", "childNodes", "as", "$", "childNode", ")", "{", "$", "nodes", "[", "$", "level", "]", "->", "push", "(", "$", "childNode", ")", ";", "}", "}", "}", "$", "level", "--", ";", "if", "(", "$", "level", "&&", "isset", "(", "$", "closingNodes", "[", "$", "level", "]", ")", ")", "{", "while", "(", "$", "node", "=", "array_pop", "(", "$", "closingNodes", "[", "$", "level", "]", ")", ")", "{", "$", "this", "->", "createEndNode", "(", "$", "node", ",", "$", "tokens", ")", ";", "}", "}", "}", "while", "(", "$", "level", ">", "0", ")", ";", "}" ]
Iterative function that tokenizes a node, putting it into an accumulator. To iterate is human, to recurse divine - L. Peter Deutsch @param DOMNode $node DOMNode to be tokenized. @param HTMLPurifier_Token[] $tokens Array-list of already tokenized tokens. @return HTMLPurifier_Token of node appended to previously passed tokens.
[ "Iterative", "function", "that", "tokenizes", "a", "node", "putting", "it", "into", "an", "accumulator", ".", "To", "iterate", "is", "human", "to", "recurse", "divine", "-", "L", ".", "Peter", "Deutsch" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Lexer/DOMLex.php#L99-L127
219,970
moodle/moodle
question/type/multianswer/backup/moodle1/lib.php
moodle1_qtype_multianswer_handler.process_question
public function process_question(array $data, array $raw) { // Convert and write the answers first. if (isset($data['answers'])) { $this->write_answers($data['answers'], $this->pluginname); } // Convert and write the multianswer extra fields. foreach ($data['multianswers'] as $multianswers) { foreach ($multianswers as $multianswer) { $this->write_xml('multianswer', $multianswer, array('/multianswer/id')); } } }
php
public function process_question(array $data, array $raw) { // Convert and write the answers first. if (isset($data['answers'])) { $this->write_answers($data['answers'], $this->pluginname); } // Convert and write the multianswer extra fields. foreach ($data['multianswers'] as $multianswers) { foreach ($multianswers as $multianswer) { $this->write_xml('multianswer', $multianswer, array('/multianswer/id')); } } }
[ "public", "function", "process_question", "(", "array", "$", "data", ",", "array", "$", "raw", ")", "{", "// Convert and write the answers first.", "if", "(", "isset", "(", "$", "data", "[", "'answers'", "]", ")", ")", "{", "$", "this", "->", "write_answers", "(", "$", "data", "[", "'answers'", "]", ",", "$", "this", "->", "pluginname", ")", ";", "}", "// Convert and write the multianswer extra fields.", "foreach", "(", "$", "data", "[", "'multianswers'", "]", "as", "$", "multianswers", ")", "{", "foreach", "(", "$", "multianswers", "as", "$", "multianswer", ")", "{", "$", "this", "->", "write_xml", "(", "'multianswer'", ",", "$", "multianswer", ",", "array", "(", "'/multianswer/id'", ")", ")", ";", "}", "}", "}" ]
Appends the multianswer specific information to the question Note that there is an upgrade step 2008050800 that is not replayed here as I suppose there was an error on restore and the backup file contains correct data. If I'm wrong on this assumption then the parent of the embedded questions could be fixed on conversion in theory (by using a temporary stash that keeps multianswer's id and its sequence) but the category fix would be tricky in XML.
[ "Appends", "the", "multianswer", "specific", "information", "to", "the", "question" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/multianswer/backup/moodle1/lib.php#L50-L63
219,971
moodle/moodle
lib/classes/collator.php
core_collator.ensure_collator_available
protected static function ensure_collator_available() { $locale = get_string('locale', 'langconfig'); if (is_null(self::$collator) || $locale != self::$locale) { self::$collator = false; self::$locale = $locale; if (class_exists('Collator', false)) { $collator = new Collator($locale); if (!empty($collator) && $collator instanceof Collator) { // Check for non fatal error messages. This has to be done immediately // after instantiation as any further calls to collation will cause // it to reset to 0 again (or another error code if one occurred) $errorcode = $collator->getErrorCode(); $errormessage = $collator->getErrorMessage(); // Check for an error code, 0 means no error occurred if ($errorcode !== 0) { // Get the actual locale being used, e.g. en, he, zh $localeinuse = $collator->getLocale(Locale::ACTUAL_LOCALE); // Check for the common fallback warning error codes. If any of the two // following errors occurred, there is normally little to worry about: // * U_USING_FALLBACK_WARNING (-128) indicates that a fall back locale was // used. For example, 'de_CH' was requested, but nothing was found // there, so 'de' was used. // * U_USING_DEFAULT_WARNING (-127) indicates that the default locale // data was used; neither the requested locale nor any of its fall // back locales could be found. For example, 'pt' was requested, but // UCA was used (Unicode Collation Algorithm http://unicode.org/reports/tr10/). // See http://www.icu-project.org/apiref/icu4c/classicu_1_1ResourceBundle.html if ($errorcode === -127 || $errorcode === -128) { // Check if the locale in use is UCA default one ('root') or // if it is anything like the locale we asked for if ($localeinuse !== 'root' && strpos($locale, $localeinuse) !== 0) { // The locale we asked for is completely different to the locale // we have received, let the user know via debugging debugging('Locale warning (not fatal) '.$errormessage.': '. 'Requested locale "'.$locale.'" not found, locale "'.$localeinuse.'" used instead. '. 'The most specific locale supported by ICU relatively to the requested locale is "'. $collator->getLocale(Locale::VALID_LOCALE).'".'); } else { // Nothing to do here, this is expected! // The Moodle locale setting isn't what the collator expected but // it is smart enough to match the first characters of our locale // to find the correct locale or to use UCA collation } } else { // We've received some other sort of non fatal warning - let the // user know about it via debugging. debugging('Problem with locale: '.$errormessage.'. '. 'Requested locale: "'.$locale.'", actual locale "'.$localeinuse.'". '. 'The most specific locale supported by ICU relatively to the requested locale is "'. $collator->getLocale(Locale::VALID_LOCALE).'".'); } } // Store the collator object now that we can be sure it is in a workable condition self::$collator = $collator; } else { // Fatal error while trying to instantiate the collator... something went wrong debugging('Error instantiating collator for locale: "' . $locale . '", with error [' . intl_get_error_code() . '] ' . intl_get_error_message($collator)); } } } return (self::$collator instanceof Collator); }
php
protected static function ensure_collator_available() { $locale = get_string('locale', 'langconfig'); if (is_null(self::$collator) || $locale != self::$locale) { self::$collator = false; self::$locale = $locale; if (class_exists('Collator', false)) { $collator = new Collator($locale); if (!empty($collator) && $collator instanceof Collator) { // Check for non fatal error messages. This has to be done immediately // after instantiation as any further calls to collation will cause // it to reset to 0 again (or another error code if one occurred) $errorcode = $collator->getErrorCode(); $errormessage = $collator->getErrorMessage(); // Check for an error code, 0 means no error occurred if ($errorcode !== 0) { // Get the actual locale being used, e.g. en, he, zh $localeinuse = $collator->getLocale(Locale::ACTUAL_LOCALE); // Check for the common fallback warning error codes. If any of the two // following errors occurred, there is normally little to worry about: // * U_USING_FALLBACK_WARNING (-128) indicates that a fall back locale was // used. For example, 'de_CH' was requested, but nothing was found // there, so 'de' was used. // * U_USING_DEFAULT_WARNING (-127) indicates that the default locale // data was used; neither the requested locale nor any of its fall // back locales could be found. For example, 'pt' was requested, but // UCA was used (Unicode Collation Algorithm http://unicode.org/reports/tr10/). // See http://www.icu-project.org/apiref/icu4c/classicu_1_1ResourceBundle.html if ($errorcode === -127 || $errorcode === -128) { // Check if the locale in use is UCA default one ('root') or // if it is anything like the locale we asked for if ($localeinuse !== 'root' && strpos($locale, $localeinuse) !== 0) { // The locale we asked for is completely different to the locale // we have received, let the user know via debugging debugging('Locale warning (not fatal) '.$errormessage.': '. 'Requested locale "'.$locale.'" not found, locale "'.$localeinuse.'" used instead. '. 'The most specific locale supported by ICU relatively to the requested locale is "'. $collator->getLocale(Locale::VALID_LOCALE).'".'); } else { // Nothing to do here, this is expected! // The Moodle locale setting isn't what the collator expected but // it is smart enough to match the first characters of our locale // to find the correct locale or to use UCA collation } } else { // We've received some other sort of non fatal warning - let the // user know about it via debugging. debugging('Problem with locale: '.$errormessage.'. '. 'Requested locale: "'.$locale.'", actual locale "'.$localeinuse.'". '. 'The most specific locale supported by ICU relatively to the requested locale is "'. $collator->getLocale(Locale::VALID_LOCALE).'".'); } } // Store the collator object now that we can be sure it is in a workable condition self::$collator = $collator; } else { // Fatal error while trying to instantiate the collator... something went wrong debugging('Error instantiating collator for locale: "' . $locale . '", with error [' . intl_get_error_code() . '] ' . intl_get_error_message($collator)); } } } return (self::$collator instanceof Collator); }
[ "protected", "static", "function", "ensure_collator_available", "(", ")", "{", "$", "locale", "=", "get_string", "(", "'locale'", ",", "'langconfig'", ")", ";", "if", "(", "is_null", "(", "self", "::", "$", "collator", ")", "||", "$", "locale", "!=", "self", "::", "$", "locale", ")", "{", "self", "::", "$", "collator", "=", "false", ";", "self", "::", "$", "locale", "=", "$", "locale", ";", "if", "(", "class_exists", "(", "'Collator'", ",", "false", ")", ")", "{", "$", "collator", "=", "new", "Collator", "(", "$", "locale", ")", ";", "if", "(", "!", "empty", "(", "$", "collator", ")", "&&", "$", "collator", "instanceof", "Collator", ")", "{", "// Check for non fatal error messages. This has to be done immediately", "// after instantiation as any further calls to collation will cause", "// it to reset to 0 again (or another error code if one occurred)", "$", "errorcode", "=", "$", "collator", "->", "getErrorCode", "(", ")", ";", "$", "errormessage", "=", "$", "collator", "->", "getErrorMessage", "(", ")", ";", "// Check for an error code, 0 means no error occurred", "if", "(", "$", "errorcode", "!==", "0", ")", "{", "// Get the actual locale being used, e.g. en, he, zh", "$", "localeinuse", "=", "$", "collator", "->", "getLocale", "(", "Locale", "::", "ACTUAL_LOCALE", ")", ";", "// Check for the common fallback warning error codes. If any of the two", "// following errors occurred, there is normally little to worry about:", "// * U_USING_FALLBACK_WARNING (-128) indicates that a fall back locale was", "// used. For example, 'de_CH' was requested, but nothing was found", "// there, so 'de' was used.", "// * U_USING_DEFAULT_WARNING (-127) indicates that the default locale", "// data was used; neither the requested locale nor any of its fall", "// back locales could be found. For example, 'pt' was requested, but", "// UCA was used (Unicode Collation Algorithm http://unicode.org/reports/tr10/).", "// See http://www.icu-project.org/apiref/icu4c/classicu_1_1ResourceBundle.html", "if", "(", "$", "errorcode", "===", "-", "127", "||", "$", "errorcode", "===", "-", "128", ")", "{", "// Check if the locale in use is UCA default one ('root') or", "// if it is anything like the locale we asked for", "if", "(", "$", "localeinuse", "!==", "'root'", "&&", "strpos", "(", "$", "locale", ",", "$", "localeinuse", ")", "!==", "0", ")", "{", "// The locale we asked for is completely different to the locale", "// we have received, let the user know via debugging", "debugging", "(", "'Locale warning (not fatal) '", ".", "$", "errormessage", ".", "': '", ".", "'Requested locale \"'", ".", "$", "locale", ".", "'\" not found, locale \"'", ".", "$", "localeinuse", ".", "'\" used instead. '", ".", "'The most specific locale supported by ICU relatively to the requested locale is \"'", ".", "$", "collator", "->", "getLocale", "(", "Locale", "::", "VALID_LOCALE", ")", ".", "'\".'", ")", ";", "}", "else", "{", "// Nothing to do here, this is expected!", "// The Moodle locale setting isn't what the collator expected but", "// it is smart enough to match the first characters of our locale", "// to find the correct locale or to use UCA collation", "}", "}", "else", "{", "// We've received some other sort of non fatal warning - let the", "// user know about it via debugging.", "debugging", "(", "'Problem with locale: '", ".", "$", "errormessage", ".", "'. '", ".", "'Requested locale: \"'", ".", "$", "locale", ".", "'\", actual locale \"'", ".", "$", "localeinuse", ".", "'\". '", ".", "'The most specific locale supported by ICU relatively to the requested locale is \"'", ".", "$", "collator", "->", "getLocale", "(", "Locale", "::", "VALID_LOCALE", ")", ".", "'\".'", ")", ";", "}", "}", "// Store the collator object now that we can be sure it is in a workable condition", "self", "::", "$", "collator", "=", "$", "collator", ";", "}", "else", "{", "// Fatal error while trying to instantiate the collator... something went wrong", "debugging", "(", "'Error instantiating collator for locale: \"'", ".", "$", "locale", ".", "'\", with error ['", ".", "intl_get_error_code", "(", ")", ".", "'] '", ".", "intl_get_error_message", "(", "$", "collator", ")", ")", ";", "}", "}", "}", "return", "(", "self", "::", "$", "collator", "instanceof", "Collator", ")", ";", "}" ]
Ensures that a collator is available and created @return bool Returns true if collation is available and ready
[ "Ensures", "that", "a", "collator", "is", "available", "and", "created" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/collator.php#L69-L131
219,972
moodle/moodle
lib/classes/collator.php
core_collator.restore_array
protected static function restore_array(array &$arr, array &$original) { foreach ($arr as $key => $ignored) { $arr[$key] = $original[$key]; } }
php
protected static function restore_array(array &$arr, array &$original) { foreach ($arr as $key => $ignored) { $arr[$key] = $original[$key]; } }
[ "protected", "static", "function", "restore_array", "(", "array", "&", "$", "arr", ",", "array", "&", "$", "original", ")", "{", "foreach", "(", "$", "arr", "as", "$", "key", "=>", "$", "ignored", ")", "{", "$", "arr", "[", "$", "key", "]", "=", "$", "original", "[", "$", "key", "]", ";", "}", "}" ]
Restore array contents keeping new keys. @static @param array $arr @param array $original @return void modifies $arr
[ "Restore", "array", "contents", "keeping", "new", "keys", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/collator.php#L140-L144
219,973
moodle/moodle
lib/classes/collator.php
core_collator.asort
public static function asort(array &$arr, $sortflag = core_collator::SORT_STRING) { if (empty($arr)) { // nothing to do return true; } $original = null; $casesensitive = (bool)($sortflag & core_collator::CASE_SENSITIVE); $sortflag = ($sortflag & ~core_collator::CASE_SENSITIVE); if ($sortflag != core_collator::SORT_NATURAL and $sortflag != core_collator::SORT_STRING) { $casesensitive = false; } if (self::ensure_collator_available()) { if ($sortflag == core_collator::SORT_NUMERIC) { $flag = Collator::SORT_NUMERIC; } else if ($sortflag == core_collator::SORT_REGULAR) { $flag = Collator::SORT_REGULAR; } else { $flag = Collator::SORT_STRING; } if ($sortflag == core_collator::SORT_NATURAL) { $original = $arr; if ($sortflag == core_collator::SORT_NATURAL) { foreach ($arr as $key => $value) { $arr[$key] = self::naturalise((string)$value); } } } if ($casesensitive) { self::$collator->setAttribute(Collator::CASE_FIRST, Collator::UPPER_FIRST); } else { self::$collator->setAttribute(Collator::CASE_FIRST, Collator::OFF); } $result = self::$collator->asort($arr, $flag); if ($original) { self::restore_array($arr, $original); } return $result; } // try some fallback that works at least for English if ($sortflag == core_collator::SORT_NUMERIC) { return asort($arr, SORT_NUMERIC); } else if ($sortflag == core_collator::SORT_REGULAR) { return asort($arr, SORT_REGULAR); } if (!$casesensitive) { $original = $arr; foreach ($arr as $key => $value) { $arr[$key] = core_text::strtolower($value); } } if ($sortflag == core_collator::SORT_NATURAL) { $result = natsort($arr); } else { $result = asort($arr, SORT_LOCALE_STRING); } if ($original) { self::restore_array($arr, $original); } return $result; }
php
public static function asort(array &$arr, $sortflag = core_collator::SORT_STRING) { if (empty($arr)) { // nothing to do return true; } $original = null; $casesensitive = (bool)($sortflag & core_collator::CASE_SENSITIVE); $sortflag = ($sortflag & ~core_collator::CASE_SENSITIVE); if ($sortflag != core_collator::SORT_NATURAL and $sortflag != core_collator::SORT_STRING) { $casesensitive = false; } if (self::ensure_collator_available()) { if ($sortflag == core_collator::SORT_NUMERIC) { $flag = Collator::SORT_NUMERIC; } else if ($sortflag == core_collator::SORT_REGULAR) { $flag = Collator::SORT_REGULAR; } else { $flag = Collator::SORT_STRING; } if ($sortflag == core_collator::SORT_NATURAL) { $original = $arr; if ($sortflag == core_collator::SORT_NATURAL) { foreach ($arr as $key => $value) { $arr[$key] = self::naturalise((string)$value); } } } if ($casesensitive) { self::$collator->setAttribute(Collator::CASE_FIRST, Collator::UPPER_FIRST); } else { self::$collator->setAttribute(Collator::CASE_FIRST, Collator::OFF); } $result = self::$collator->asort($arr, $flag); if ($original) { self::restore_array($arr, $original); } return $result; } // try some fallback that works at least for English if ($sortflag == core_collator::SORT_NUMERIC) { return asort($arr, SORT_NUMERIC); } else if ($sortflag == core_collator::SORT_REGULAR) { return asort($arr, SORT_REGULAR); } if (!$casesensitive) { $original = $arr; foreach ($arr as $key => $value) { $arr[$key] = core_text::strtolower($value); } } if ($sortflag == core_collator::SORT_NATURAL) { $result = natsort($arr); } else { $result = asort($arr, SORT_LOCALE_STRING); } if ($original) { self::restore_array($arr, $original); } return $result; }
[ "public", "static", "function", "asort", "(", "array", "&", "$", "arr", ",", "$", "sortflag", "=", "core_collator", "::", "SORT_STRING", ")", "{", "if", "(", "empty", "(", "$", "arr", ")", ")", "{", "// nothing to do", "return", "true", ";", "}", "$", "original", "=", "null", ";", "$", "casesensitive", "=", "(", "bool", ")", "(", "$", "sortflag", "&", "core_collator", "::", "CASE_SENSITIVE", ")", ";", "$", "sortflag", "=", "(", "$", "sortflag", "&", "~", "core_collator", "::", "CASE_SENSITIVE", ")", ";", "if", "(", "$", "sortflag", "!=", "core_collator", "::", "SORT_NATURAL", "and", "$", "sortflag", "!=", "core_collator", "::", "SORT_STRING", ")", "{", "$", "casesensitive", "=", "false", ";", "}", "if", "(", "self", "::", "ensure_collator_available", "(", ")", ")", "{", "if", "(", "$", "sortflag", "==", "core_collator", "::", "SORT_NUMERIC", ")", "{", "$", "flag", "=", "Collator", "::", "SORT_NUMERIC", ";", "}", "else", "if", "(", "$", "sortflag", "==", "core_collator", "::", "SORT_REGULAR", ")", "{", "$", "flag", "=", "Collator", "::", "SORT_REGULAR", ";", "}", "else", "{", "$", "flag", "=", "Collator", "::", "SORT_STRING", ";", "}", "if", "(", "$", "sortflag", "==", "core_collator", "::", "SORT_NATURAL", ")", "{", "$", "original", "=", "$", "arr", ";", "if", "(", "$", "sortflag", "==", "core_collator", "::", "SORT_NATURAL", ")", "{", "foreach", "(", "$", "arr", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "arr", "[", "$", "key", "]", "=", "self", "::", "naturalise", "(", "(", "string", ")", "$", "value", ")", ";", "}", "}", "}", "if", "(", "$", "casesensitive", ")", "{", "self", "::", "$", "collator", "->", "setAttribute", "(", "Collator", "::", "CASE_FIRST", ",", "Collator", "::", "UPPER_FIRST", ")", ";", "}", "else", "{", "self", "::", "$", "collator", "->", "setAttribute", "(", "Collator", "::", "CASE_FIRST", ",", "Collator", "::", "OFF", ")", ";", "}", "$", "result", "=", "self", "::", "$", "collator", "->", "asort", "(", "$", "arr", ",", "$", "flag", ")", ";", "if", "(", "$", "original", ")", "{", "self", "::", "restore_array", "(", "$", "arr", ",", "$", "original", ")", ";", "}", "return", "$", "result", ";", "}", "// try some fallback that works at least for English", "if", "(", "$", "sortflag", "==", "core_collator", "::", "SORT_NUMERIC", ")", "{", "return", "asort", "(", "$", "arr", ",", "SORT_NUMERIC", ")", ";", "}", "else", "if", "(", "$", "sortflag", "==", "core_collator", "::", "SORT_REGULAR", ")", "{", "return", "asort", "(", "$", "arr", ",", "SORT_REGULAR", ")", ";", "}", "if", "(", "!", "$", "casesensitive", ")", "{", "$", "original", "=", "$", "arr", ";", "foreach", "(", "$", "arr", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "arr", "[", "$", "key", "]", "=", "core_text", "::", "strtolower", "(", "$", "value", ")", ";", "}", "}", "if", "(", "$", "sortflag", "==", "core_collator", "::", "SORT_NATURAL", ")", "{", "$", "result", "=", "natsort", "(", "$", "arr", ")", ";", "}", "else", "{", "$", "result", "=", "asort", "(", "$", "arr", ",", "SORT_LOCALE_STRING", ")", ";", "}", "if", "(", "$", "original", ")", "{", "self", "::", "restore_array", "(", "$", "arr", ",", "$", "original", ")", ";", "}", "return", "$", "result", ";", "}" ]
Locale aware sorting, the key associations are kept, values are sorted alphabetically. @param array $arr array to be sorted (reference) @param int $sortflag One of core_collator::SORT_NUMERIC, core_collator::SORT_STRING, core_collator::SORT_NATURAL, core_collator::SORT_REGULAR optionally "|" core_collator::CASE_SENSITIVE @return bool True on success
[ "Locale", "aware", "sorting", "the", "key", "associations", "are", "kept", "values", "are", "sorted", "alphabetically", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/collator.php#L174-L247
219,974
moodle/moodle
lib/classes/collator.php
core_collator.asort_objects_by_property
public static function asort_objects_by_property(array &$objects, $property, $sortflag = core_collator::SORT_STRING) { $original = $objects; foreach ($objects as $key => $object) { $objects[$key] = $object->$property; } $result = self::asort($objects, $sortflag); self::restore_array($objects, $original); return $result; }
php
public static function asort_objects_by_property(array &$objects, $property, $sortflag = core_collator::SORT_STRING) { $original = $objects; foreach ($objects as $key => $object) { $objects[$key] = $object->$property; } $result = self::asort($objects, $sortflag); self::restore_array($objects, $original); return $result; }
[ "public", "static", "function", "asort_objects_by_property", "(", "array", "&", "$", "objects", ",", "$", "property", ",", "$", "sortflag", "=", "core_collator", "::", "SORT_STRING", ")", "{", "$", "original", "=", "$", "objects", ";", "foreach", "(", "$", "objects", "as", "$", "key", "=>", "$", "object", ")", "{", "$", "objects", "[", "$", "key", "]", "=", "$", "object", "->", "$", "property", ";", "}", "$", "result", "=", "self", "::", "asort", "(", "$", "objects", ",", "$", "sortflag", ")", ";", "self", "::", "restore_array", "(", "$", "objects", ",", "$", "original", ")", ";", "return", "$", "result", ";", "}" ]
Locale aware sort of objects by a property in common to all objects @param array $objects An array of objects to sort (handled by reference) @param string $property The property to use for comparison @param int $sortflag One of core_collator::SORT_NUMERIC, core_collator::SORT_STRING, core_collator::SORT_NATURAL, core_collator::SORT_REGULAR optionally "|" core_collator::CASE_SENSITIVE @return bool True on success
[ "Locale", "aware", "sort", "of", "objects", "by", "a", "property", "in", "common", "to", "all", "objects" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/collator.php#L258-L266
219,975
moodle/moodle
lib/classes/collator.php
core_collator.asort_objects_by_method
public static function asort_objects_by_method(array &$objects, $method, $sortflag = core_collator::SORT_STRING) { $original = $objects; foreach ($objects as $key => $object) { $objects[$key] = $object->{$method}(); } $result = self::asort($objects, $sortflag); self::restore_array($objects, $original); return $result; }
php
public static function asort_objects_by_method(array &$objects, $method, $sortflag = core_collator::SORT_STRING) { $original = $objects; foreach ($objects as $key => $object) { $objects[$key] = $object->{$method}(); } $result = self::asort($objects, $sortflag); self::restore_array($objects, $original); return $result; }
[ "public", "static", "function", "asort_objects_by_method", "(", "array", "&", "$", "objects", ",", "$", "method", ",", "$", "sortflag", "=", "core_collator", "::", "SORT_STRING", ")", "{", "$", "original", "=", "$", "objects", ";", "foreach", "(", "$", "objects", "as", "$", "key", "=>", "$", "object", ")", "{", "$", "objects", "[", "$", "key", "]", "=", "$", "object", "->", "{", "$", "method", "}", "(", ")", ";", "}", "$", "result", "=", "self", "::", "asort", "(", "$", "objects", ",", "$", "sortflag", ")", ";", "self", "::", "restore_array", "(", "$", "objects", ",", "$", "original", ")", ";", "return", "$", "result", ";", "}" ]
Locale aware sort of objects by a method in common to all objects @param array $objects An array of objects to sort (handled by reference) @param string $method The method to call to generate a value for comparison @param int $sortflag One of core_collator::SORT_NUMERIC, core_collator::SORT_STRING, core_collator::SORT_NATURAL, core_collator::SORT_REGULAR optionally "|" core_collator::CASE_SENSITIVE @return bool True on success
[ "Locale", "aware", "sort", "of", "objects", "by", "a", "method", "in", "common", "to", "all", "objects" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/collator.php#L277-L285
219,976
moodle/moodle
lib/classes/collator.php
core_collator.asort_array_of_arrays_by_key
public static function asort_array_of_arrays_by_key(array &$array, $key, $sortflag = core_collator::SORT_STRING) { $original = $array; foreach ($array as $initkey => $item) { $array[$initkey] = $item[$key]; } $result = self::asort($array, $sortflag); self::restore_array($array, $original); return $result; }
php
public static function asort_array_of_arrays_by_key(array &$array, $key, $sortflag = core_collator::SORT_STRING) { $original = $array; foreach ($array as $initkey => $item) { $array[$initkey] = $item[$key]; } $result = self::asort($array, $sortflag); self::restore_array($array, $original); return $result; }
[ "public", "static", "function", "asort_array_of_arrays_by_key", "(", "array", "&", "$", "array", ",", "$", "key", ",", "$", "sortflag", "=", "core_collator", "::", "SORT_STRING", ")", "{", "$", "original", "=", "$", "array", ";", "foreach", "(", "$", "array", "as", "$", "initkey", "=>", "$", "item", ")", "{", "$", "array", "[", "$", "initkey", "]", "=", "$", "item", "[", "$", "key", "]", ";", "}", "$", "result", "=", "self", "::", "asort", "(", "$", "array", ",", "$", "sortflag", ")", ";", "self", "::", "restore_array", "(", "$", "array", ",", "$", "original", ")", ";", "return", "$", "result", ";", "}" ]
Locale aware sort of array of arrays. Given an array like: $array = array( array('name' => 'bravo'), array('name' => 'charlie'), array('name' => 'alpha') ); If you call: core_collator::asort_array_of_arrays_by_key($array, 'name') You will be returned $array sorted by the name key of the subarrays. e.g. $array = array( array('name' => 'alpha'), array('name' => 'bravo'), array('name' => 'charlie') ); @param array $array An array of objects to sort (handled by reference) @param string $key The key to use for comparison @param int $sortflag One of core_collator::SORT_NUMERIC, core_collator::SORT_STRING, core_collator::SORT_NATURAL, core_collator::SORT_REGULAR optionally "|" core_collator::CASE_SENSITIVE @return bool True on success
[ "Locale", "aware", "sort", "of", "array", "of", "arrays", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/collator.php#L317-L325
219,977
moodle/moodle
lib/classes/collator.php
core_collator.ksort
public static function ksort(array &$arr, $sortflag = core_collator::SORT_STRING) { $keys = array_keys($arr); if (!self::asort($keys, $sortflag)) { return false; } // This is a bit slow, but we need to keep the references $original = $arr; $arr = array(); // Surprisingly this does not break references outside foreach ($keys as $key) { $arr[$key] = $original[$key]; } return true; }
php
public static function ksort(array &$arr, $sortflag = core_collator::SORT_STRING) { $keys = array_keys($arr); if (!self::asort($keys, $sortflag)) { return false; } // This is a bit slow, but we need to keep the references $original = $arr; $arr = array(); // Surprisingly this does not break references outside foreach ($keys as $key) { $arr[$key] = $original[$key]; } return true; }
[ "public", "static", "function", "ksort", "(", "array", "&", "$", "arr", ",", "$", "sortflag", "=", "core_collator", "::", "SORT_STRING", ")", "{", "$", "keys", "=", "array_keys", "(", "$", "arr", ")", ";", "if", "(", "!", "self", "::", "asort", "(", "$", "keys", ",", "$", "sortflag", ")", ")", "{", "return", "false", ";", "}", "// This is a bit slow, but we need to keep the references", "$", "original", "=", "$", "arr", ";", "$", "arr", "=", "array", "(", ")", ";", "// Surprisingly this does not break references outside", "foreach", "(", "$", "keys", "as", "$", "key", ")", "{", "$", "arr", "[", "$", "key", "]", "=", "$", "original", "[", "$", "key", "]", ";", "}", "return", "true", ";", "}" ]
Locale aware sorting, the key associations are kept, keys are sorted alphabetically. @param array $arr array to be sorted (reference) @param int $sortflag One of core_collator::SORT_NUMERIC, core_collator::SORT_STRING, core_collator::SORT_NATURAL, core_collator::SORT_REGULAR optionally "|" core_collator::CASE_SENSITIVE @return bool True on success
[ "Locale", "aware", "sorting", "the", "key", "associations", "are", "kept", "keys", "are", "sorted", "alphabetically", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/collator.php#L335-L348
219,978
moodle/moodle
admin/tool/usertours/classes/local/filter/category.php
category.check_contexts
private static function check_contexts(context $context, $values) { if ($context->contextlevel > CONTEXT_COURSECAT) { return self::check_contexts($context->get_parent_context(), $values); } else if ($context->contextlevel == CONTEXT_COURSECAT) { if (in_array($context->instanceid, $values)) { return true; } else { return self::check_contexts($context->get_parent_context(), $values); } } else { return false; } }
php
private static function check_contexts(context $context, $values) { if ($context->contextlevel > CONTEXT_COURSECAT) { return self::check_contexts($context->get_parent_context(), $values); } else if ($context->contextlevel == CONTEXT_COURSECAT) { if (in_array($context->instanceid, $values)) { return true; } else { return self::check_contexts($context->get_parent_context(), $values); } } else { return false; } }
[ "private", "static", "function", "check_contexts", "(", "context", "$", "context", ",", "$", "values", ")", "{", "if", "(", "$", "context", "->", "contextlevel", ">", "CONTEXT_COURSECAT", ")", "{", "return", "self", "::", "check_contexts", "(", "$", "context", "->", "get_parent_context", "(", ")", ",", "$", "values", ")", ";", "}", "else", "if", "(", "$", "context", "->", "contextlevel", "==", "CONTEXT_COURSECAT", ")", "{", "if", "(", "in_array", "(", "$", "context", "->", "instanceid", ",", "$", "values", ")", ")", "{", "return", "true", ";", "}", "else", "{", "return", "self", "::", "check_contexts", "(", "$", "context", "->", "get_parent_context", "(", ")", ",", "$", "values", ")", ";", "}", "}", "else", "{", "return", "false", ";", "}", "}" ]
Recursive function allows checking of parent categories. @param context $context @param array $values @return boolean
[ "Recursive", "function", "allows", "checking", "of", "parent", "categories", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/local/filter/category.php#L85-L97
219,979
moodle/moodle
lib/portfolio/plugin.php
portfolio_plugin_base.get_export_config
public final function get_export_config($key) { $allowed = array_merge( array('hidewait', 'wait', 'format', 'hideformat'), $this->get_allowed_export_config() ); if (!in_array($key, $allowed)) { $a = (object)array('property' => $key, 'class' => get_class($this)); throw new portfolio_export_exception($this->get('exporter'), 'invalidexportproperty', 'portfolio', null, $a); } if (!array_key_exists($key, $this->exportconfig)) { return null; } return $this->exportconfig[$key]; }
php
public final function get_export_config($key) { $allowed = array_merge( array('hidewait', 'wait', 'format', 'hideformat'), $this->get_allowed_export_config() ); if (!in_array($key, $allowed)) { $a = (object)array('property' => $key, 'class' => get_class($this)); throw new portfolio_export_exception($this->get('exporter'), 'invalidexportproperty', 'portfolio', null, $a); } if (!array_key_exists($key, $this->exportconfig)) { return null; } return $this->exportconfig[$key]; }
[ "public", "final", "function", "get_export_config", "(", "$", "key", ")", "{", "$", "allowed", "=", "array_merge", "(", "array", "(", "'hidewait'", ",", "'wait'", ",", "'format'", ",", "'hideformat'", ")", ",", "$", "this", "->", "get_allowed_export_config", "(", ")", ")", ";", "if", "(", "!", "in_array", "(", "$", "key", ",", "$", "allowed", ")", ")", "{", "$", "a", "=", "(", "object", ")", "array", "(", "'property'", "=>", "$", "key", ",", "'class'", "=>", "get_class", "(", "$", "this", ")", ")", ";", "throw", "new", "portfolio_export_exception", "(", "$", "this", "->", "get", "(", "'exporter'", ")", ",", "'invalidexportproperty'", ",", "'portfolio'", ",", "null", ",", "$", "a", ")", ";", "}", "if", "(", "!", "array_key_exists", "(", "$", "key", ",", "$", "this", "->", "exportconfig", ")", ")", "{", "return", "null", ";", "}", "return", "$", "this", "->", "exportconfig", "[", "$", "key", "]", ";", "}" ]
Gets an export time config value. Subclasses should not override this. @param string $key field to fetch @return null|string config value
[ "Gets", "an", "export", "time", "config", "value", ".", "Subclasses", "should", "not", "override", "this", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/plugin.php#L237-L250
219,980
moodle/moodle
lib/portfolio/plugin.php
portfolio_plugin_base.create_instance
public static function create_instance($plugin, $name, $config) { global $DB, $CFG; $new = (object)array( 'plugin' => $plugin, 'name' => $name, ); if (!portfolio_static_function($plugin, 'allows_multiple_instances')) { // check we don't have one already if ($DB->record_exists('portfolio_instance', array('plugin' => $plugin))) { throw new portfolio_exception('multipleinstancesdisallowed', 'portfolio', '', $plugin); } } $newid = $DB->insert_record('portfolio_instance', $new); require_once($CFG->dirroot . '/portfolio/' . $plugin . '/lib.php'); $classname = 'portfolio_plugin_' . $plugin; $obj = new $classname($newid); $obj->set_config($config); $obj->save(); return $obj; }
php
public static function create_instance($plugin, $name, $config) { global $DB, $CFG; $new = (object)array( 'plugin' => $plugin, 'name' => $name, ); if (!portfolio_static_function($plugin, 'allows_multiple_instances')) { // check we don't have one already if ($DB->record_exists('portfolio_instance', array('plugin' => $plugin))) { throw new portfolio_exception('multipleinstancesdisallowed', 'portfolio', '', $plugin); } } $newid = $DB->insert_record('portfolio_instance', $new); require_once($CFG->dirroot . '/portfolio/' . $plugin . '/lib.php'); $classname = 'portfolio_plugin_' . $plugin; $obj = new $classname($newid); $obj->set_config($config); $obj->save(); return $obj; }
[ "public", "static", "function", "create_instance", "(", "$", "plugin", ",", "$", "name", ",", "$", "config", ")", "{", "global", "$", "DB", ",", "$", "CFG", ";", "$", "new", "=", "(", "object", ")", "array", "(", "'plugin'", "=>", "$", "plugin", ",", "'name'", "=>", "$", "name", ",", ")", ";", "if", "(", "!", "portfolio_static_function", "(", "$", "plugin", ",", "'allows_multiple_instances'", ")", ")", "{", "// check we don't have one already", "if", "(", "$", "DB", "->", "record_exists", "(", "'portfolio_instance'", ",", "array", "(", "'plugin'", "=>", "$", "plugin", ")", ")", ")", "{", "throw", "new", "portfolio_exception", "(", "'multipleinstancesdisallowed'", ",", "'portfolio'", ",", "''", ",", "$", "plugin", ")", ";", "}", "}", "$", "newid", "=", "$", "DB", "->", "insert_record", "(", "'portfolio_instance'", ",", "$", "new", ")", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/portfolio/'", ".", "$", "plugin", ".", "'/lib.php'", ")", ";", "$", "classname", "=", "'portfolio_plugin_'", ".", "$", "plugin", ";", "$", "obj", "=", "new", "$", "classname", "(", "$", "newid", ")", ";", "$", "obj", "->", "set_config", "(", "$", "config", ")", ";", "$", "obj", "->", "save", "(", ")", ";", "return", "$", "obj", ";", "}" ]
This function creates a new instance of a plugin saves it in the database, saves the config and returns it. You shouldn't need to override it unless you're doing something really funky @param string $plugin portfolio plugin to create @param string $name name of new instance @param array $config what the admin config form returned @return object subclass of portfolio_plugin_base
[ "This", "function", "creates", "a", "new", "instance", "of", "a", "plugin", "saves", "it", "in", "the", "database", "saves", "the", "config", "and", "returns", "it", ".", "You", "shouldn", "t", "need", "to", "override", "it", "unless", "you", "re", "doing", "something", "really", "funky" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/plugin.php#L424-L443
219,981
moodle/moodle
lib/portfolio/plugin.php
portfolio_plugin_base.get_config
public final function get_config($key) { if (!in_array($key, $this->get_allowed_config())) { $a = (object)array('property' => $key, 'class' => get_class($this)); throw new portfolio_export_exception($this->get('exporter'), 'invalidconfigproperty', 'portfolio', null, $a); } if (isset($this->config->{$key})) { return $this->config->{$key}; } return null; }
php
public final function get_config($key) { if (!in_array($key, $this->get_allowed_config())) { $a = (object)array('property' => $key, 'class' => get_class($this)); throw new portfolio_export_exception($this->get('exporter'), 'invalidconfigproperty', 'portfolio', null, $a); } if (isset($this->config->{$key})) { return $this->config->{$key}; } return null; }
[ "public", "final", "function", "get_config", "(", "$", "key", ")", "{", "if", "(", "!", "in_array", "(", "$", "key", ",", "$", "this", "->", "get_allowed_config", "(", ")", ")", ")", "{", "$", "a", "=", "(", "object", ")", "array", "(", "'property'", "=>", "$", "key", ",", "'class'", "=>", "get_class", "(", "$", "this", ")", ")", ";", "throw", "new", "portfolio_export_exception", "(", "$", "this", "->", "get", "(", "'exporter'", ")", ",", "'invalidconfigproperty'", ",", "'portfolio'", ",", "null", ",", "$", "a", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "config", "->", "{", "$", "key", "}", ")", ")", "{", "return", "$", "this", "->", "config", "->", "{", "$", "key", "}", ";", "}", "return", "null", ";", "}" ]
Gets the value of a particular config item @param string $key key to fetch @return null|mixed the corresponding value
[ "Gets", "the", "value", "of", "a", "particular", "config", "item" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/plugin.php#L552-L561
219,982
moodle/moodle
lib/portfolio/plugin.php
portfolio_plugin_base.get_user_config
public final function get_user_config($key, $userid=0) { global $DB; if (empty($userid)) { $userid = $this->user->id; } if ($key != 'visible') { // handled by the parent class if (!in_array($key, $this->get_allowed_user_config())) { $a = (object)array('property' => $key, 'class' => get_class($this)); throw new portfolio_export_exception($this->get('exporter'), 'invaliduserproperty', 'portfolio', null, $a); } } if (!array_key_exists($userid, $this->userconfig)) { $this->userconfig[$userid] = (object)array_fill_keys(array_merge(array('visible'), $this->get_allowed_user_config()), null); foreach ($DB->get_records('portfolio_instance_user', array('instance' => $this->id, 'userid' => $userid)) as $config) { $this->userconfig[$userid]->{$config->name} = $config->value; } } if ($this->userconfig[$userid]->visible === null) { $this->set_user_config(array('visible' => 1), $userid); } return $this->userconfig[$userid]->{$key}; }
php
public final function get_user_config($key, $userid=0) { global $DB; if (empty($userid)) { $userid = $this->user->id; } if ($key != 'visible') { // handled by the parent class if (!in_array($key, $this->get_allowed_user_config())) { $a = (object)array('property' => $key, 'class' => get_class($this)); throw new portfolio_export_exception($this->get('exporter'), 'invaliduserproperty', 'portfolio', null, $a); } } if (!array_key_exists($userid, $this->userconfig)) { $this->userconfig[$userid] = (object)array_fill_keys(array_merge(array('visible'), $this->get_allowed_user_config()), null); foreach ($DB->get_records('portfolio_instance_user', array('instance' => $this->id, 'userid' => $userid)) as $config) { $this->userconfig[$userid]->{$config->name} = $config->value; } } if ($this->userconfig[$userid]->visible === null) { $this->set_user_config(array('visible' => 1), $userid); } return $this->userconfig[$userid]->{$key}; }
[ "public", "final", "function", "get_user_config", "(", "$", "key", ",", "$", "userid", "=", "0", ")", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "userid", ")", ")", "{", "$", "userid", "=", "$", "this", "->", "user", "->", "id", ";", "}", "if", "(", "$", "key", "!=", "'visible'", ")", "{", "// handled by the parent class", "if", "(", "!", "in_array", "(", "$", "key", ",", "$", "this", "->", "get_allowed_user_config", "(", ")", ")", ")", "{", "$", "a", "=", "(", "object", ")", "array", "(", "'property'", "=>", "$", "key", ",", "'class'", "=>", "get_class", "(", "$", "this", ")", ")", ";", "throw", "new", "portfolio_export_exception", "(", "$", "this", "->", "get", "(", "'exporter'", ")", ",", "'invaliduserproperty'", ",", "'portfolio'", ",", "null", ",", "$", "a", ")", ";", "}", "}", "if", "(", "!", "array_key_exists", "(", "$", "userid", ",", "$", "this", "->", "userconfig", ")", ")", "{", "$", "this", "->", "userconfig", "[", "$", "userid", "]", "=", "(", "object", ")", "array_fill_keys", "(", "array_merge", "(", "array", "(", "'visible'", ")", ",", "$", "this", "->", "get_allowed_user_config", "(", ")", ")", ",", "null", ")", ";", "foreach", "(", "$", "DB", "->", "get_records", "(", "'portfolio_instance_user'", ",", "array", "(", "'instance'", "=>", "$", "this", "->", "id", ",", "'userid'", "=>", "$", "userid", ")", ")", "as", "$", "config", ")", "{", "$", "this", "->", "userconfig", "[", "$", "userid", "]", "->", "{", "$", "config", "->", "name", "}", "=", "$", "config", "->", "value", ";", "}", "}", "if", "(", "$", "this", "->", "userconfig", "[", "$", "userid", "]", "->", "visible", "===", "null", ")", "{", "$", "this", "->", "set_user_config", "(", "array", "(", "'visible'", "=>", "1", ")", ",", "$", "userid", ")", ";", "}", "return", "$", "this", "->", "userconfig", "[", "$", "userid", "]", "->", "{", "$", "key", "}", ";", "}" ]
Get the value of a config item for a particular user. @param string $key key to fetch @param int $userid id of user (defaults to current) @return string the corresponding value
[ "Get", "the", "value", "of", "a", "config", "item", "for", "a", "particular", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/plugin.php#L571-L595
219,983
moodle/moodle
lib/portfolio/plugin.php
portfolio_plugin_base.set_user_config
public final function set_user_config($config, $userid=0) { global $DB; if (empty($userid)) { $userid = $this->user->id; } foreach ($config as $key => $value) { if ($key != 'visible' && !in_array($key, $this->get_allowed_user_config())) { $a = (object)array('property' => $key, 'class' => get_class($this)); throw new portfolio_export_exception($this->get('exporter'), 'invaliduserproperty', 'portfolio', null, $a); } if (!$existing = $DB->get_record('portfolio_instance_user', array('instance'=> $this->id, 'userid' => $userid, 'name' => $key))) { $DB->insert_record('portfolio_instance_user', (object)array( 'instance' => $this->id, 'name' => $key, 'value' => $value, 'userid' => $userid, )); } else if ($existing->value != $value) { $DB->set_field('portfolio_instance_user', 'value', $value, array('name' => $key, 'instance' => $this->id, 'userid' => $userid)); } $this->userconfig[$userid]->{$key} = $value; } }
php
public final function set_user_config($config, $userid=0) { global $DB; if (empty($userid)) { $userid = $this->user->id; } foreach ($config as $key => $value) { if ($key != 'visible' && !in_array($key, $this->get_allowed_user_config())) { $a = (object)array('property' => $key, 'class' => get_class($this)); throw new portfolio_export_exception($this->get('exporter'), 'invaliduserproperty', 'portfolio', null, $a); } if (!$existing = $DB->get_record('portfolio_instance_user', array('instance'=> $this->id, 'userid' => $userid, 'name' => $key))) { $DB->insert_record('portfolio_instance_user', (object)array( 'instance' => $this->id, 'name' => $key, 'value' => $value, 'userid' => $userid, )); } else if ($existing->value != $value) { $DB->set_field('portfolio_instance_user', 'value', $value, array('name' => $key, 'instance' => $this->id, 'userid' => $userid)); } $this->userconfig[$userid]->{$key} = $value; } }
[ "public", "final", "function", "set_user_config", "(", "$", "config", ",", "$", "userid", "=", "0", ")", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "userid", ")", ")", "{", "$", "userid", "=", "$", "this", "->", "user", "->", "id", ";", "}", "foreach", "(", "$", "config", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "$", "key", "!=", "'visible'", "&&", "!", "in_array", "(", "$", "key", ",", "$", "this", "->", "get_allowed_user_config", "(", ")", ")", ")", "{", "$", "a", "=", "(", "object", ")", "array", "(", "'property'", "=>", "$", "key", ",", "'class'", "=>", "get_class", "(", "$", "this", ")", ")", ";", "throw", "new", "portfolio_export_exception", "(", "$", "this", "->", "get", "(", "'exporter'", ")", ",", "'invaliduserproperty'", ",", "'portfolio'", ",", "null", ",", "$", "a", ")", ";", "}", "if", "(", "!", "$", "existing", "=", "$", "DB", "->", "get_record", "(", "'portfolio_instance_user'", ",", "array", "(", "'instance'", "=>", "$", "this", "->", "id", ",", "'userid'", "=>", "$", "userid", ",", "'name'", "=>", "$", "key", ")", ")", ")", "{", "$", "DB", "->", "insert_record", "(", "'portfolio_instance_user'", ",", "(", "object", ")", "array", "(", "'instance'", "=>", "$", "this", "->", "id", ",", "'name'", "=>", "$", "key", ",", "'value'", "=>", "$", "value", ",", "'userid'", "=>", "$", "userid", ",", ")", ")", ";", "}", "else", "if", "(", "$", "existing", "->", "value", "!=", "$", "value", ")", "{", "$", "DB", "->", "set_field", "(", "'portfolio_instance_user'", ",", "'value'", ",", "$", "value", ",", "array", "(", "'name'", "=>", "$", "key", ",", "'instance'", "=>", "$", "this", "->", "id", ",", "'userid'", "=>", "$", "userid", ")", ")", ";", "}", "$", "this", "->", "userconfig", "[", "$", "userid", "]", "->", "{", "$", "key", "}", "=", "$", "value", ";", "}", "}" ]
Sets config options for a given user. @param array $config array containing key/value pairs to set @param int $userid userid to set config for (defaults to current)
[ "Sets", "config", "options", "for", "a", "given", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/portfolio/plugin.php#L604-L629
219,984
moodle/moodle
lib/htmlpurifier/HTMLPurifier/HTMLModule.php
HTMLPurifier_HTMLModule.addElement
public function addElement($element, $type, $contents, $attr_includes = array(), $attr = array()) { $this->elements[] = $element; // parse content_model list($content_model_type, $content_model) = $this->parseContents($contents); // merge in attribute inclusions $this->mergeInAttrIncludes($attr, $attr_includes); // add element to content sets if ($type) { $this->addElementToContentSet($element, $type); } // create element $this->info[$element] = HTMLPurifier_ElementDef::create( $content_model, $content_model_type, $attr ); // literal object $contents means direct child manipulation if (!is_string($contents)) { $this->info[$element]->child = $contents; } return $this->info[$element]; }
php
public function addElement($element, $type, $contents, $attr_includes = array(), $attr = array()) { $this->elements[] = $element; // parse content_model list($content_model_type, $content_model) = $this->parseContents($contents); // merge in attribute inclusions $this->mergeInAttrIncludes($attr, $attr_includes); // add element to content sets if ($type) { $this->addElementToContentSet($element, $type); } // create element $this->info[$element] = HTMLPurifier_ElementDef::create( $content_model, $content_model_type, $attr ); // literal object $contents means direct child manipulation if (!is_string($contents)) { $this->info[$element]->child = $contents; } return $this->info[$element]; }
[ "public", "function", "addElement", "(", "$", "element", ",", "$", "type", ",", "$", "contents", ",", "$", "attr_includes", "=", "array", "(", ")", ",", "$", "attr", "=", "array", "(", ")", ")", "{", "$", "this", "->", "elements", "[", "]", "=", "$", "element", ";", "// parse content_model", "list", "(", "$", "content_model_type", ",", "$", "content_model", ")", "=", "$", "this", "->", "parseContents", "(", "$", "contents", ")", ";", "// merge in attribute inclusions", "$", "this", "->", "mergeInAttrIncludes", "(", "$", "attr", ",", "$", "attr_includes", ")", ";", "// add element to content sets", "if", "(", "$", "type", ")", "{", "$", "this", "->", "addElementToContentSet", "(", "$", "element", ",", "$", "type", ")", ";", "}", "// create element", "$", "this", "->", "info", "[", "$", "element", "]", "=", "HTMLPurifier_ElementDef", "::", "create", "(", "$", "content_model", ",", "$", "content_model_type", ",", "$", "attr", ")", ";", "// literal object $contents means direct child manipulation", "if", "(", "!", "is_string", "(", "$", "contents", ")", ")", "{", "$", "this", "->", "info", "[", "$", "element", "]", "->", "child", "=", "$", "contents", ";", "}", "return", "$", "this", "->", "info", "[", "$", "element", "]", ";", "}" ]
Convenience function that sets up a new element @param string $element Name of element to add @param string|bool $type What content set should element be registered to? Set as false to skip this step. @param string $contents Allowed children in form of: "$content_model_type: $content_model" @param array $attr_includes What attribute collections to register to element? @param array $attr What unique attributes does the element define? @see HTMLPurifier_ElementDef:: for in-depth descriptions of these parameters. @return HTMLPurifier_ElementDef Created element definition object, so you can set advanced parameters
[ "Convenience", "function", "that", "sets", "up", "a", "new", "element" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/HTMLModule.php#L144-L166
219,985
moodle/moodle
lib/htmlpurifier/HTMLPurifier/HTMLModule.php
HTMLPurifier_HTMLModule.addBlankElement
public function addBlankElement($element) { if (!isset($this->info[$element])) { $this->elements[] = $element; $this->info[$element] = new HTMLPurifier_ElementDef(); $this->info[$element]->standalone = false; } else { trigger_error("Definition for $element already exists in module, cannot redefine"); } return $this->info[$element]; }
php
public function addBlankElement($element) { if (!isset($this->info[$element])) { $this->elements[] = $element; $this->info[$element] = new HTMLPurifier_ElementDef(); $this->info[$element]->standalone = false; } else { trigger_error("Definition for $element already exists in module, cannot redefine"); } return $this->info[$element]; }
[ "public", "function", "addBlankElement", "(", "$", "element", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "info", "[", "$", "element", "]", ")", ")", "{", "$", "this", "->", "elements", "[", "]", "=", "$", "element", ";", "$", "this", "->", "info", "[", "$", "element", "]", "=", "new", "HTMLPurifier_ElementDef", "(", ")", ";", "$", "this", "->", "info", "[", "$", "element", "]", "->", "standalone", "=", "false", ";", "}", "else", "{", "trigger_error", "(", "\"Definition for $element already exists in module, cannot redefine\"", ")", ";", "}", "return", "$", "this", "->", "info", "[", "$", "element", "]", ";", "}" ]
Convenience function that creates a totally blank, non-standalone element. @param string $element Name of element to create @return HTMLPurifier_ElementDef Created element
[ "Convenience", "function", "that", "creates", "a", "totally", "blank", "non", "-", "standalone", "element", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/HTMLModule.php#L174-L184
219,986
moodle/moodle
lib/htmlpurifier/HTMLPurifier/HTMLModule.php
HTMLPurifier_HTMLModule.addElementToContentSet
public function addElementToContentSet($element, $type) { if (!isset($this->content_sets[$type])) { $this->content_sets[$type] = ''; } else { $this->content_sets[$type] .= ' | '; } $this->content_sets[$type] .= $element; }
php
public function addElementToContentSet($element, $type) { if (!isset($this->content_sets[$type])) { $this->content_sets[$type] = ''; } else { $this->content_sets[$type] .= ' | '; } $this->content_sets[$type] .= $element; }
[ "public", "function", "addElementToContentSet", "(", "$", "element", ",", "$", "type", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "content_sets", "[", "$", "type", "]", ")", ")", "{", "$", "this", "->", "content_sets", "[", "$", "type", "]", "=", "''", ";", "}", "else", "{", "$", "this", "->", "content_sets", "[", "$", "type", "]", ".=", "' | '", ";", "}", "$", "this", "->", "content_sets", "[", "$", "type", "]", ".=", "$", "element", ";", "}" ]
Convenience function that registers an element to a content set @param string $element Element to register @param string $type Name content set (warning: case sensitive, usually upper-case first letter)
[ "Convenience", "function", "that", "registers", "an", "element", "to", "a", "content", "set" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/HTMLModule.php#L192-L200
219,987
moodle/moodle
cache/stores/mongodb/MongoDB/Operation/CreateIndexes.php
CreateIndexes.executeCommand
private function executeCommand(Server $server) { $cmd = [ 'createIndexes' => $this->collectionName, 'indexes' => $this->indexes, ]; if (isset($this->options['maxTimeMS'])) { $cmd['maxTimeMS'] = $this->options['maxTimeMS']; } $server->executeWriteCommand($this->databaseName, new Command($cmd), $this->createOptions()); }
php
private function executeCommand(Server $server) { $cmd = [ 'createIndexes' => $this->collectionName, 'indexes' => $this->indexes, ]; if (isset($this->options['maxTimeMS'])) { $cmd['maxTimeMS'] = $this->options['maxTimeMS']; } $server->executeWriteCommand($this->databaseName, new Command($cmd), $this->createOptions()); }
[ "private", "function", "executeCommand", "(", "Server", "$", "server", ")", "{", "$", "cmd", "=", "[", "'createIndexes'", "=>", "$", "this", "->", "collectionName", ",", "'indexes'", "=>", "$", "this", "->", "indexes", ",", "]", ";", "if", "(", "isset", "(", "$", "this", "->", "options", "[", "'maxTimeMS'", "]", ")", ")", "{", "$", "cmd", "[", "'maxTimeMS'", "]", "=", "$", "this", "->", "options", "[", "'maxTimeMS'", "]", ";", "}", "$", "server", "->", "executeWriteCommand", "(", "$", "this", "->", "databaseName", ",", "new", "Command", "(", "$", "cmd", ")", ",", "$", "this", "->", "createOptions", "(", ")", ")", ";", "}" ]
Create one or more indexes for the collection using the createIndexes command. @param Server $server @throws DriverRuntimeException for other driver errors (e.g. connection errors)
[ "Create", "one", "or", "more", "indexes", "for", "the", "collection", "using", "the", "createIndexes", "command", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/Operation/CreateIndexes.php#L175-L187
219,988
moodle/moodle
lib/spout/src/Spout/Writer/ODS/Helper/FileSystemHelper.php
FileSystemHelper.createMetaInfoFolderAndFile
protected function createMetaInfoFolderAndFile() { $this->metaInfFolder = $this->createFolder($this->rootFolder, self::META_INF_FOLDER_NAME); $this->createManifestFile(); return $this; }
php
protected function createMetaInfoFolderAndFile() { $this->metaInfFolder = $this->createFolder($this->rootFolder, self::META_INF_FOLDER_NAME); $this->createManifestFile(); return $this; }
[ "protected", "function", "createMetaInfoFolderAndFile", "(", ")", "{", "$", "this", "->", "metaInfFolder", "=", "$", "this", "->", "createFolder", "(", "$", "this", "->", "rootFolder", ",", "self", "::", "META_INF_FOLDER_NAME", ")", ";", "$", "this", "->", "createManifestFile", "(", ")", ";", "return", "$", "this", ";", "}" ]
Creates the "META-INF" folder under the root folder as well as the "manifest.xml" file in it @return FileSystemHelper @throws \Box\Spout\Common\Exception\IOException If unable to create the folder or the "manifest.xml" file
[ "Creates", "the", "META", "-", "INF", "folder", "under", "the", "root", "folder", "as", "well", "as", "the", "manifest", ".", "xml", "file", "in", "it" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/ODS/Helper/FileSystemHelper.php#L88-L95
219,989
moodle/moodle
lib/spout/src/Spout/Writer/ODS/Helper/FileSystemHelper.php
FileSystemHelper.createSheetsContentTempFolder
protected function createSheetsContentTempFolder() { $this->sheetsContentTempFolder = $this->createFolder($this->rootFolder, self::SHEETS_CONTENT_TEMP_FOLDER_NAME); return $this; }
php
protected function createSheetsContentTempFolder() { $this->sheetsContentTempFolder = $this->createFolder($this->rootFolder, self::SHEETS_CONTENT_TEMP_FOLDER_NAME); return $this; }
[ "protected", "function", "createSheetsContentTempFolder", "(", ")", "{", "$", "this", "->", "sheetsContentTempFolder", "=", "$", "this", "->", "createFolder", "(", "$", "this", "->", "rootFolder", ",", "self", "::", "SHEETS_CONTENT_TEMP_FOLDER_NAME", ")", ";", "return", "$", "this", ";", "}" ]
Creates the temp folder where specific sheets content will be written to. This folder is not part of the final ODS file and is only used to be able to jump between sheets. @return FileSystemHelper @throws \Box\Spout\Common\Exception\IOException If unable to create the folder
[ "Creates", "the", "temp", "folder", "where", "specific", "sheets", "content", "will", "be", "written", "to", ".", "This", "folder", "is", "not", "part", "of", "the", "final", "ODS", "file", "and", "is", "only", "used", "to", "be", "able", "to", "jump", "between", "sheets", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/ODS/Helper/FileSystemHelper.php#L127-L131
219,990
moodle/moodle
lib/spout/src/Spout/Writer/ODS/Helper/FileSystemHelper.php
FileSystemHelper.createMetaFile
protected function createMetaFile() { $appName = self::APP_NAME; $createdDate = (new \DateTime())->format(\DateTime::W3C); $metaXmlFileContents = <<<EOD <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <office:document-meta office:version="1.2" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:xlink="http://www.w3.org/1999/xlink"> <office:meta> <dc:creator>$appName</dc:creator> <meta:creation-date>$createdDate</meta:creation-date> <dc:date>$createdDate</dc:date> </office:meta> </office:document-meta> EOD; $this->createFileWithContents($this->rootFolder, self::META_XML_FILE_NAME, $metaXmlFileContents); return $this; }
php
protected function createMetaFile() { $appName = self::APP_NAME; $createdDate = (new \DateTime())->format(\DateTime::W3C); $metaXmlFileContents = <<<EOD <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <office:document-meta office:version="1.2" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:xlink="http://www.w3.org/1999/xlink"> <office:meta> <dc:creator>$appName</dc:creator> <meta:creation-date>$createdDate</meta:creation-date> <dc:date>$createdDate</dc:date> </office:meta> </office:document-meta> EOD; $this->createFileWithContents($this->rootFolder, self::META_XML_FILE_NAME, $metaXmlFileContents); return $this; }
[ "protected", "function", "createMetaFile", "(", ")", "{", "$", "appName", "=", "self", "::", "APP_NAME", ";", "$", "createdDate", "=", "(", "new", "\\", "DateTime", "(", ")", ")", "->", "format", "(", "\\", "DateTime", "::", "W3C", ")", ";", "$", "metaXmlFileContents", "=", " <<<EOD\n<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<office:document-meta office:version=\"1.2\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:meta=\"urn:oasis:names:tc:opendocument:xmlns:meta:1.0\" xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n <office:meta>\n <dc:creator>$appName</dc:creator>\n <meta:creation-date>$createdDate</meta:creation-date>\n <dc:date>$createdDate</dc:date>\n </office:meta>\n</office:document-meta>\nEOD", ";", "$", "this", "->", "createFileWithContents", "(", "$", "this", "->", "rootFolder", ",", "self", "::", "META_XML_FILE_NAME", ",", "$", "metaXmlFileContents", ")", ";", "return", "$", "this", ";", "}" ]
Creates the "meta.xml" file under the root folder @return FileSystemHelper @throws \Box\Spout\Common\Exception\IOException If unable to create the file
[ "Creates", "the", "meta", ".", "xml", "file", "under", "the", "root", "folder" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/ODS/Helper/FileSystemHelper.php#L139-L158
219,991
moodle/moodle
lib/spout/src/Spout/Writer/ODS/Helper/FileSystemHelper.php
FileSystemHelper.createMimetypeFile
protected function createMimetypeFile() { $this->createFileWithContents($this->rootFolder, self::MIMETYPE_FILE_NAME, self::MIMETYPE); return $this; }
php
protected function createMimetypeFile() { $this->createFileWithContents($this->rootFolder, self::MIMETYPE_FILE_NAME, self::MIMETYPE); return $this; }
[ "protected", "function", "createMimetypeFile", "(", ")", "{", "$", "this", "->", "createFileWithContents", "(", "$", "this", "->", "rootFolder", ",", "self", "::", "MIMETYPE_FILE_NAME", ",", "self", "::", "MIMETYPE", ")", ";", "return", "$", "this", ";", "}" ]
Creates the "mimetype" file under the root folder @return FileSystemHelper @throws \Box\Spout\Common\Exception\IOException If unable to create the file
[ "Creates", "the", "mimetype", "file", "under", "the", "root", "folder" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/ODS/Helper/FileSystemHelper.php#L166-L170
219,992
moodle/moodle
lib/spout/src/Spout/Writer/ODS/Helper/FileSystemHelper.php
FileSystemHelper.createContentFile
public function createContentFile($worksheets, $styleHelper) { $contentXmlFileContents = <<<EOD <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <office:document-content office:version="1.2" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:msoxl="http://schemas.microsoft.com/office/excel/formula" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:xlink="http://www.w3.org/1999/xlink"> EOD; $contentXmlFileContents .= $styleHelper->getContentXmlFontFaceSectionContent(); $contentXmlFileContents .= $styleHelper->getContentXmlAutomaticStylesSectionContent(count($worksheets)); $contentXmlFileContents .= '<office:body><office:spreadsheet>'; $this->createFileWithContents($this->rootFolder, self::CONTENT_XML_FILE_NAME, $contentXmlFileContents); // Append sheets content to "content.xml" $contentXmlFilePath = $this->rootFolder . '/' . self::CONTENT_XML_FILE_NAME; $contentXmlHandle = fopen($contentXmlFilePath, 'a'); foreach ($worksheets as $worksheet) { // write the "<table:table>" node, with the final sheet's name fwrite($contentXmlHandle, $worksheet->getTableElementStartAsString()); $worksheetFilePath = $worksheet->getWorksheetFilePath(); $this->copyFileContentsToTarget($worksheetFilePath, $contentXmlHandle); fwrite($contentXmlHandle, '</table:table>'); } $contentXmlFileContents = '</office:spreadsheet></office:body></office:document-content>'; fwrite($contentXmlHandle, $contentXmlFileContents); fclose($contentXmlHandle); return $this; }
php
public function createContentFile($worksheets, $styleHelper) { $contentXmlFileContents = <<<EOD <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <office:document-content office:version="1.2" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:calcext="urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0" xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0" xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0" xmlns:msoxl="http://schemas.microsoft.com/office/excel/formula" xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0" xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0" xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0" xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0" xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0" xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0" xmlns:xlink="http://www.w3.org/1999/xlink"> EOD; $contentXmlFileContents .= $styleHelper->getContentXmlFontFaceSectionContent(); $contentXmlFileContents .= $styleHelper->getContentXmlAutomaticStylesSectionContent(count($worksheets)); $contentXmlFileContents .= '<office:body><office:spreadsheet>'; $this->createFileWithContents($this->rootFolder, self::CONTENT_XML_FILE_NAME, $contentXmlFileContents); // Append sheets content to "content.xml" $contentXmlFilePath = $this->rootFolder . '/' . self::CONTENT_XML_FILE_NAME; $contentXmlHandle = fopen($contentXmlFilePath, 'a'); foreach ($worksheets as $worksheet) { // write the "<table:table>" node, with the final sheet's name fwrite($contentXmlHandle, $worksheet->getTableElementStartAsString()); $worksheetFilePath = $worksheet->getWorksheetFilePath(); $this->copyFileContentsToTarget($worksheetFilePath, $contentXmlHandle); fwrite($contentXmlHandle, '</table:table>'); } $contentXmlFileContents = '</office:spreadsheet></office:body></office:document-content>'; fwrite($contentXmlHandle, $contentXmlFileContents); fclose($contentXmlHandle); return $this; }
[ "public", "function", "createContentFile", "(", "$", "worksheets", ",", "$", "styleHelper", ")", "{", "$", "contentXmlFileContents", "=", " <<<EOD\n<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<office:document-content office:version=\"1.2\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:calcext=\"urn:org:documentfoundation:names:experimental:calc:xmlns:calcext:1.0\" xmlns:draw=\"urn:oasis:names:tc:opendocument:xmlns:drawing:1.0\" xmlns:fo=\"urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0\" xmlns:msoxl=\"http://schemas.microsoft.com/office/excel/formula\" xmlns:number=\"urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0\" xmlns:office=\"urn:oasis:names:tc:opendocument:xmlns:office:1.0\" xmlns:style=\"urn:oasis:names:tc:opendocument:xmlns:style:1.0\" xmlns:svg=\"urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0\" xmlns:table=\"urn:oasis:names:tc:opendocument:xmlns:table:1.0\" xmlns:text=\"urn:oasis:names:tc:opendocument:xmlns:text:1.0\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\nEOD", ";", "$", "contentXmlFileContents", ".=", "$", "styleHelper", "->", "getContentXmlFontFaceSectionContent", "(", ")", ";", "$", "contentXmlFileContents", ".=", "$", "styleHelper", "->", "getContentXmlAutomaticStylesSectionContent", "(", "count", "(", "$", "worksheets", ")", ")", ";", "$", "contentXmlFileContents", ".=", "'<office:body><office:spreadsheet>'", ";", "$", "this", "->", "createFileWithContents", "(", "$", "this", "->", "rootFolder", ",", "self", "::", "CONTENT_XML_FILE_NAME", ",", "$", "contentXmlFileContents", ")", ";", "// Append sheets content to \"content.xml\"", "$", "contentXmlFilePath", "=", "$", "this", "->", "rootFolder", ".", "'/'", ".", "self", "::", "CONTENT_XML_FILE_NAME", ";", "$", "contentXmlHandle", "=", "fopen", "(", "$", "contentXmlFilePath", ",", "'a'", ")", ";", "foreach", "(", "$", "worksheets", "as", "$", "worksheet", ")", "{", "// write the \"<table:table>\" node, with the final sheet's name", "fwrite", "(", "$", "contentXmlHandle", ",", "$", "worksheet", "->", "getTableElementStartAsString", "(", ")", ")", ";", "$", "worksheetFilePath", "=", "$", "worksheet", "->", "getWorksheetFilePath", "(", ")", ";", "$", "this", "->", "copyFileContentsToTarget", "(", "$", "worksheetFilePath", ",", "$", "contentXmlHandle", ")", ";", "fwrite", "(", "$", "contentXmlHandle", ",", "'</table:table>'", ")", ";", "}", "$", "contentXmlFileContents", "=", "'</office:spreadsheet></office:body></office:document-content>'", ";", "fwrite", "(", "$", "contentXmlHandle", ",", "$", "contentXmlFileContents", ")", ";", "fclose", "(", "$", "contentXmlHandle", ")", ";", "return", "$", "this", ";", "}" ]
Creates the "content.xml" file under the root folder @param Worksheet[] $worksheets @param StyleHelper $styleHelper @return FileSystemHelper
[ "Creates", "the", "content", ".", "xml", "file", "under", "the", "root", "folder" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/ODS/Helper/FileSystemHelper.php#L179-L213
219,993
moodle/moodle
lib/spout/src/Spout/Writer/ODS/Helper/FileSystemHelper.php
FileSystemHelper.copyFileContentsToTarget
protected function copyFileContentsToTarget($sourceFilePath, $targetResource) { $sourceHandle = fopen($sourceFilePath, 'r'); stream_copy_to_stream($sourceHandle, $targetResource); fclose($sourceHandle); }
php
protected function copyFileContentsToTarget($sourceFilePath, $targetResource) { $sourceHandle = fopen($sourceFilePath, 'r'); stream_copy_to_stream($sourceHandle, $targetResource); fclose($sourceHandle); }
[ "protected", "function", "copyFileContentsToTarget", "(", "$", "sourceFilePath", ",", "$", "targetResource", ")", "{", "$", "sourceHandle", "=", "fopen", "(", "$", "sourceFilePath", ",", "'r'", ")", ";", "stream_copy_to_stream", "(", "$", "sourceHandle", ",", "$", "targetResource", ")", ";", "fclose", "(", "$", "sourceHandle", ")", ";", "}" ]
Streams the content of the file at the given path into the target resource. Depending on which mode the target resource was created with, it will truncate then copy or append the content to the target file. @param string $sourceFilePath Path of the file whose content will be copied @param resource $targetResource Target resource that will receive the content @return void
[ "Streams", "the", "content", "of", "the", "file", "at", "the", "given", "path", "into", "the", "target", "resource", ".", "Depending", "on", "which", "mode", "the", "target", "resource", "was", "created", "with", "it", "will", "truncate", "then", "copy", "or", "append", "the", "content", "to", "the", "target", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/ODS/Helper/FileSystemHelper.php#L224-L229
219,994
moodle/moodle
lib/spout/src/Spout/Writer/ODS/Helper/FileSystemHelper.php
FileSystemHelper.createStylesFile
public function createStylesFile($styleHelper, $numWorksheets) { $stylesXmlFileContents = $styleHelper->getStylesXMLFileContent($numWorksheets); $this->createFileWithContents($this->rootFolder, self::STYLES_XML_FILE_NAME, $stylesXmlFileContents); return $this; }
php
public function createStylesFile($styleHelper, $numWorksheets) { $stylesXmlFileContents = $styleHelper->getStylesXMLFileContent($numWorksheets); $this->createFileWithContents($this->rootFolder, self::STYLES_XML_FILE_NAME, $stylesXmlFileContents); return $this; }
[ "public", "function", "createStylesFile", "(", "$", "styleHelper", ",", "$", "numWorksheets", ")", "{", "$", "stylesXmlFileContents", "=", "$", "styleHelper", "->", "getStylesXMLFileContent", "(", "$", "numWorksheets", ")", ";", "$", "this", "->", "createFileWithContents", "(", "$", "this", "->", "rootFolder", ",", "self", "::", "STYLES_XML_FILE_NAME", ",", "$", "stylesXmlFileContents", ")", ";", "return", "$", "this", ";", "}" ]
Creates the "styles.xml" file under the root folder @param StyleHelper $styleHelper @param int $numWorksheets Number of created worksheets @return FileSystemHelper
[ "Creates", "the", "styles", ".", "xml", "file", "under", "the", "root", "folder" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/ODS/Helper/FileSystemHelper.php#L250-L256
219,995
moodle/moodle
admin/tool/generator/classes/make_course_form.php
tool_generator_make_course_form.definition
public function definition() { $mform = $this->_form; $mform->addElement('select', 'size', get_string('size', 'tool_generator'), tool_generator_course_backend::get_size_choices()); $mform->setDefault('size', tool_generator_course_backend::DEFAULT_SIZE); $mform->addElement('text', 'shortname', get_string('shortnamecourse')); $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client'); $mform->setType('shortname', PARAM_TEXT); $mform->addElement('text', 'fullname', get_string('fullnamecourse')); $mform->setType('fullname', PARAM_TEXT); $mform->addElement('editor', 'summary', get_string('coursesummary')); $mform->setType('summary', PARAM_RAW); $mform->addElement('submit', 'submit', get_string('createcourse', 'tool_generator')); }
php
public function definition() { $mform = $this->_form; $mform->addElement('select', 'size', get_string('size', 'tool_generator'), tool_generator_course_backend::get_size_choices()); $mform->setDefault('size', tool_generator_course_backend::DEFAULT_SIZE); $mform->addElement('text', 'shortname', get_string('shortnamecourse')); $mform->addRule('shortname', get_string('missingshortname'), 'required', null, 'client'); $mform->setType('shortname', PARAM_TEXT); $mform->addElement('text', 'fullname', get_string('fullnamecourse')); $mform->setType('fullname', PARAM_TEXT); $mform->addElement('editor', 'summary', get_string('coursesummary')); $mform->setType('summary', PARAM_RAW); $mform->addElement('submit', 'submit', get_string('createcourse', 'tool_generator')); }
[ "public", "function", "definition", "(", ")", "{", "$", "mform", "=", "$", "this", "->", "_form", ";", "$", "mform", "->", "addElement", "(", "'select'", ",", "'size'", ",", "get_string", "(", "'size'", ",", "'tool_generator'", ")", ",", "tool_generator_course_backend", "::", "get_size_choices", "(", ")", ")", ";", "$", "mform", "->", "setDefault", "(", "'size'", ",", "tool_generator_course_backend", "::", "DEFAULT_SIZE", ")", ";", "$", "mform", "->", "addElement", "(", "'text'", ",", "'shortname'", ",", "get_string", "(", "'shortnamecourse'", ")", ")", ";", "$", "mform", "->", "addRule", "(", "'shortname'", ",", "get_string", "(", "'missingshortname'", ")", ",", "'required'", ",", "null", ",", "'client'", ")", ";", "$", "mform", "->", "setType", "(", "'shortname'", ",", "PARAM_TEXT", ")", ";", "$", "mform", "->", "addElement", "(", "'text'", ",", "'fullname'", ",", "get_string", "(", "'fullnamecourse'", ")", ")", ";", "$", "mform", "->", "setType", "(", "'fullname'", ",", "PARAM_TEXT", ")", ";", "$", "mform", "->", "addElement", "(", "'editor'", ",", "'summary'", ",", "get_string", "(", "'coursesummary'", ")", ")", ";", "$", "mform", "->", "setType", "(", "'summary'", ",", "PARAM_RAW", ")", ";", "$", "mform", "->", "addElement", "(", "'submit'", ",", "'submit'", ",", "get_string", "(", "'createcourse'", ",", "'tool_generator'", ")", ")", ";", "}" ]
Course generation tool form definition. @return void
[ "Course", "generation", "tool", "form", "definition", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/generator/classes/make_course_form.php#L43-L61
219,996
moodle/moodle
lib/classes/hub/publication.php
publication.get_sorted_subjects
public static function get_sorted_subjects() { $subjects = get_string_manager()->load_component_strings('edufields', current_language()); // Sort the subjects. $return = []; asort($subjects); foreach ($subjects as $key => $option) { $keylength = strlen($key); if ($keylength == 12) { $return[$key] = $option; // We want only selectable categories. } } return $return; }
php
public static function get_sorted_subjects() { $subjects = get_string_manager()->load_component_strings('edufields', current_language()); // Sort the subjects. $return = []; asort($subjects); foreach ($subjects as $key => $option) { $keylength = strlen($key); if ($keylength == 12) { $return[$key] = $option; // We want only selectable categories. } } return $return; }
[ "public", "static", "function", "get_sorted_subjects", "(", ")", "{", "$", "subjects", "=", "get_string_manager", "(", ")", "->", "load_component_strings", "(", "'edufields'", ",", "current_language", "(", ")", ")", ";", "// Sort the subjects.", "$", "return", "=", "[", "]", ";", "asort", "(", "$", "subjects", ")", ";", "foreach", "(", "$", "subjects", "as", "$", "key", "=>", "$", "option", ")", "{", "$", "keylength", "=", "strlen", "(", "$", "key", ")", ";", "if", "(", "$", "keylength", "==", "12", ")", "{", "$", "return", "[", "$", "key", "]", "=", "$", "option", ";", "// We want only selectable categories.", "}", "}", "return", "$", "return", ";", "}" ]
Retrieve all the sorted course subjects @return array $subjects
[ "Retrieve", "all", "the", "sorted", "course", "subjects" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/hub/publication.php#L79-L92
219,997
moodle/moodle
lib/classes/hub/publication.php
publication.get_course_publications
public static function get_course_publications($courseid) { global $DB; $sql = 'SELECT cp.id, cp.status, cp.timechecked, cp.timepublished, rh.hubname, rh.huburl, cp.courseid, cp.enrollable, cp.hubcourseid FROM {course_published} cp, {registration_hubs} rh WHERE cp.huburl = rh.huburl and cp.courseid = :courseid and rh.huburl = :huburl ORDER BY cp.enrollable DESC, rh.hubname, cp.timepublished'; $params = array('courseid' => $courseid, 'huburl' => HUB_MOODLEORGHUBURL); $records = $DB->get_records_sql($sql, $params); // Add links for publications that are listed. foreach ($records as $id => $record) { if ($record->status) { $records[$id]->link = new moodle_url(HUB_MOODLEORGHUBURL, ['courseid' => $record->hubcourseid]); } } return $records; }
php
public static function get_course_publications($courseid) { global $DB; $sql = 'SELECT cp.id, cp.status, cp.timechecked, cp.timepublished, rh.hubname, rh.huburl, cp.courseid, cp.enrollable, cp.hubcourseid FROM {course_published} cp, {registration_hubs} rh WHERE cp.huburl = rh.huburl and cp.courseid = :courseid and rh.huburl = :huburl ORDER BY cp.enrollable DESC, rh.hubname, cp.timepublished'; $params = array('courseid' => $courseid, 'huburl' => HUB_MOODLEORGHUBURL); $records = $DB->get_records_sql($sql, $params); // Add links for publications that are listed. foreach ($records as $id => $record) { if ($record->status) { $records[$id]->link = new moodle_url(HUB_MOODLEORGHUBURL, ['courseid' => $record->hubcourseid]); } } return $records; }
[ "public", "static", "function", "get_course_publications", "(", "$", "courseid", ")", "{", "global", "$", "DB", ";", "$", "sql", "=", "'SELECT cp.id, cp.status, cp.timechecked, cp.timepublished, rh.hubname,\n rh.huburl, cp.courseid, cp.enrollable, cp.hubcourseid\n FROM {course_published} cp, {registration_hubs} rh\n WHERE cp.huburl = rh.huburl and cp.courseid = :courseid and rh.huburl = :huburl\n ORDER BY cp.enrollable DESC, rh.hubname, cp.timepublished'", ";", "$", "params", "=", "array", "(", "'courseid'", "=>", "$", "courseid", ",", "'huburl'", "=>", "HUB_MOODLEORGHUBURL", ")", ";", "$", "records", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "// Add links for publications that are listed.", "foreach", "(", "$", "records", "as", "$", "id", "=>", "$", "record", ")", "{", "if", "(", "$", "record", "->", "status", ")", "{", "$", "records", "[", "$", "id", "]", "->", "link", "=", "new", "moodle_url", "(", "HUB_MOODLEORGHUBURL", ",", "[", "'courseid'", "=>", "$", "record", "->", "hubcourseid", "]", ")", ";", "}", "}", "return", "$", "records", ";", "}" ]
Get all publication for a course @param int $courseid local course id @return array of publication
[ "Get", "all", "publication", "for", "a", "course" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/hub/publication.php#L100-L117
219,998
moodle/moodle
lib/classes/hub/publication.php
publication.get_publication
public static function get_publication($id, $courseid = 0, $strictness = IGNORE_MISSING) { global $DB; if (!$id && $strictness != MUST_EXIST) { return false; } $params = ['id' => $id, 'huburl' => HUB_MOODLEORGHUBURL]; if ($courseid) { $params['courseid'] = $courseid; } return $DB->get_record('course_published', $params, '*', $strictness); }
php
public static function get_publication($id, $courseid = 0, $strictness = IGNORE_MISSING) { global $DB; if (!$id && $strictness != MUST_EXIST) { return false; } $params = ['id' => $id, 'huburl' => HUB_MOODLEORGHUBURL]; if ($courseid) { $params['courseid'] = $courseid; } return $DB->get_record('course_published', $params, '*', $strictness); }
[ "public", "static", "function", "get_publication", "(", "$", "id", ",", "$", "courseid", "=", "0", ",", "$", "strictness", "=", "IGNORE_MISSING", ")", "{", "global", "$", "DB", ";", "if", "(", "!", "$", "id", "&&", "$", "strictness", "!=", "MUST_EXIST", ")", "{", "return", "false", ";", "}", "$", "params", "=", "[", "'id'", "=>", "$", "id", ",", "'huburl'", "=>", "HUB_MOODLEORGHUBURL", "]", ";", "if", "(", "$", "courseid", ")", "{", "$", "params", "[", "'courseid'", "]", "=", "$", "courseid", ";", "}", "return", "$", "DB", "->", "get_record", "(", "'course_published'", ",", "$", "params", ",", "'*'", ",", "$", "strictness", ")", ";", "}" ]
Load publication information from local db @param int $id @param int $courseid if specified publication will be checked that it is in the current course @param int $strictness @return stdClass
[ "Load", "publication", "information", "from", "local", "db" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/hub/publication.php#L127-L137
219,999
moodle/moodle
lib/classes/hub/publication.php
publication.request_status_update
public static function request_status_update() { global $DB; list($sitecourses, $coursetotal) = api::get_courses('', 1, 1, ['allsitecourses' => 1]); // Update status for all these course. foreach ($sitecourses as $sitecourse) { // Get the publication from the hub course id. $publication = $DB->get_record('course_published', ['hubcourseid' => $sitecourse['id']]); if (!empty($publication)) { $publication->status = $sitecourse['privacy']; $publication->timechecked = time(); self::update_publication($publication); } else { $msgparams = new stdClass(); $msgparams->id = $sitecourse['id']; $msgparams->hubname = html_writer::tag('a', 'Moodle.net', array('href' => HUB_MOODLEORGHUBURL)); \core\notification::add(get_string('detectednotexistingpublication', 'hub', $msgparams)); // TODO action? } } }
php
public static function request_status_update() { global $DB; list($sitecourses, $coursetotal) = api::get_courses('', 1, 1, ['allsitecourses' => 1]); // Update status for all these course. foreach ($sitecourses as $sitecourse) { // Get the publication from the hub course id. $publication = $DB->get_record('course_published', ['hubcourseid' => $sitecourse['id']]); if (!empty($publication)) { $publication->status = $sitecourse['privacy']; $publication->timechecked = time(); self::update_publication($publication); } else { $msgparams = new stdClass(); $msgparams->id = $sitecourse['id']; $msgparams->hubname = html_writer::tag('a', 'Moodle.net', array('href' => HUB_MOODLEORGHUBURL)); \core\notification::add(get_string('detectednotexistingpublication', 'hub', $msgparams)); // TODO action? } } }
[ "public", "static", "function", "request_status_update", "(", ")", "{", "global", "$", "DB", ";", "list", "(", "$", "sitecourses", ",", "$", "coursetotal", ")", "=", "api", "::", "get_courses", "(", "''", ",", "1", ",", "1", ",", "[", "'allsitecourses'", "=>", "1", "]", ")", ";", "// Update status for all these course.", "foreach", "(", "$", "sitecourses", "as", "$", "sitecourse", ")", "{", "// Get the publication from the hub course id.", "$", "publication", "=", "$", "DB", "->", "get_record", "(", "'course_published'", ",", "[", "'hubcourseid'", "=>", "$", "sitecourse", "[", "'id'", "]", "]", ")", ";", "if", "(", "!", "empty", "(", "$", "publication", ")", ")", "{", "$", "publication", "->", "status", "=", "$", "sitecourse", "[", "'privacy'", "]", ";", "$", "publication", "->", "timechecked", "=", "time", "(", ")", ";", "self", "::", "update_publication", "(", "$", "publication", ")", ";", "}", "else", "{", "$", "msgparams", "=", "new", "stdClass", "(", ")", ";", "$", "msgparams", "->", "id", "=", "$", "sitecourse", "[", "'id'", "]", ";", "$", "msgparams", "->", "hubname", "=", "html_writer", "::", "tag", "(", "'a'", ",", "'Moodle.net'", ",", "array", "(", "'href'", "=>", "HUB_MOODLEORGHUBURL", ")", ")", ";", "\\", "core", "\\", "notification", "::", "add", "(", "get_string", "(", "'detectednotexistingpublication'", ",", "'hub'", ",", "$", "msgparams", ")", ")", ";", "// TODO action?", "}", "}", "}" ]
Check all courses published from this site if they have been approved
[ "Check", "all", "courses", "published", "from", "this", "site", "if", "they", "have", "been", "approved" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/hub/publication.php#L151-L172