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
216,100
moodle/moodle
search/engine/solr/classes/engine.php
engine.standarize_solr_obj
public function standarize_solr_obj(\SolrObject $obj) { $properties = $obj->getPropertyNames(); $docdata = array(); foreach($properties as $name) { // http://php.net/manual/en/solrobject.getpropertynames.php#98018. $name = trim($name); $docdata[$name] = $obj->offsetGet($name); } return $docdata; }
php
public function standarize_solr_obj(\SolrObject $obj) { $properties = $obj->getPropertyNames(); $docdata = array(); foreach($properties as $name) { // http://php.net/manual/en/solrobject.getpropertynames.php#98018. $name = trim($name); $docdata[$name] = $obj->offsetGet($name); } return $docdata; }
[ "public", "function", "standarize_solr_obj", "(", "\\", "SolrObject", "$", "obj", ")", "{", "$", "properties", "=", "$", "obj", "->", "getPropertyNames", "(", ")", ";", "$", "docdata", "=", "array", "(", ")", ";", "foreach", "(", "$", "properties", "as", "$", "name", ")", "{", "// http://php.net/manual/en/solrobject.getpropertynames.php#98018.", "$", "name", "=", "trim", "(", "$", "name", ")", ";", "$", "docdata", "[", "$", "name", "]", "=", "$", "obj", "->", "offsetGet", "(", "$", "name", ")", ";", "}", "return", "$", "docdata", ";", "}" ]
Returns a standard php array from a \SolrObject instance. @param \SolrObject $obj @return array The returned document as an array.
[ "Returns", "a", "standard", "php", "array", "from", "a", "\\", "SolrObject", "instance", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/engine/solr/classes/engine.php#L717-L727
216,101
moodle/moodle
search/engine/solr/classes/engine.php
engine.add_solr_document
protected function add_solr_document($doc) { $solrdoc = new \SolrInputDocument(); foreach ($doc as $field => $value) { $solrdoc->addField($field, $value); } try { $result = $this->get_search_client()->addDocument($solrdoc, true, static::AUTOCOMMIT_WITHIN); return true; } catch (\SolrClientException $e) { debugging('Solr client error adding document with id ' . $doc['id'] . ': ' . $e->getMessage(), DEBUG_DEVELOPER); } catch (\SolrServerException $e) { // We only use the first line of the message, as it's a fully java stacktrace behind it. $msg = strtok($e->getMessage(), "\n"); debugging('Solr server error adding document with id ' . $doc['id'] . ': ' . $msg, DEBUG_DEVELOPER); } return false; }
php
protected function add_solr_document($doc) { $solrdoc = new \SolrInputDocument(); foreach ($doc as $field => $value) { $solrdoc->addField($field, $value); } try { $result = $this->get_search_client()->addDocument($solrdoc, true, static::AUTOCOMMIT_WITHIN); return true; } catch (\SolrClientException $e) { debugging('Solr client error adding document with id ' . $doc['id'] . ': ' . $e->getMessage(), DEBUG_DEVELOPER); } catch (\SolrServerException $e) { // We only use the first line of the message, as it's a fully java stacktrace behind it. $msg = strtok($e->getMessage(), "\n"); debugging('Solr server error adding document with id ' . $doc['id'] . ': ' . $msg, DEBUG_DEVELOPER); } return false; }
[ "protected", "function", "add_solr_document", "(", "$", "doc", ")", "{", "$", "solrdoc", "=", "new", "\\", "SolrInputDocument", "(", ")", ";", "foreach", "(", "$", "doc", "as", "$", "field", "=>", "$", "value", ")", "{", "$", "solrdoc", "->", "addField", "(", "$", "field", ",", "$", "value", ")", ";", "}", "try", "{", "$", "result", "=", "$", "this", "->", "get_search_client", "(", ")", "->", "addDocument", "(", "$", "solrdoc", ",", "true", ",", "static", "::", "AUTOCOMMIT_WITHIN", ")", ";", "return", "true", ";", "}", "catch", "(", "\\", "SolrClientException", "$", "e", ")", "{", "debugging", "(", "'Solr client error adding document with id '", ".", "$", "doc", "[", "'id'", "]", ".", "': '", ".", "$", "e", "->", "getMessage", "(", ")", ",", "DEBUG_DEVELOPER", ")", ";", "}", "catch", "(", "\\", "SolrServerException", "$", "e", ")", "{", "// We only use the first line of the message, as it's a fully java stacktrace behind it.", "$", "msg", "=", "strtok", "(", "$", "e", "->", "getMessage", "(", ")", ",", "\"\\n\"", ")", ";", "debugging", "(", "'Solr server error adding document with id '", ".", "$", "doc", "[", "'id'", "]", ".", "': '", ".", "$", "msg", ",", "DEBUG_DEVELOPER", ")", ";", "}", "return", "false", ";", "}" ]
Adds a text document to the search engine. @param array $doc @return bool
[ "Adds", "a", "text", "document", "to", "the", "search", "engine", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/engine/solr/classes/engine.php#L759-L777
216,102
moodle/moodle
search/engine/solr/classes/engine.php
engine.process_document_files
protected function process_document_files($document) { if (!$this->file_indexing_enabled()) { return; } // Maximum rows to process at a time. $rows = 500; // Get the attached files. $files = $document->get_files(); // If this isn't a new document, we need to check the exiting indexed files. if (!$document->get_is_new()) { // We do this progressively, so we can handle lots of files cleanly. list($numfound, $indexedfiles) = $this->get_indexed_files($document, 0, $rows); $count = 0; $idstodelete = array(); do { // Go through each indexed file. We want to not index any stored and unchanged ones, delete any missing ones. foreach ($indexedfiles as $indexedfile) { $fileid = $indexedfile->solr_fileid; if (isset($files[$fileid])) { // Check for changes that would mean we need to re-index the file. If so, just leave in $files. // Filelib does not guarantee time modified is updated, so we will check important values. if ($indexedfile->modified != $files[$fileid]->get_timemodified()) { continue; } if (strcmp($indexedfile->title, $files[$fileid]->get_filename()) !== 0) { continue; } if ($indexedfile->solr_filecontenthash != $files[$fileid]->get_contenthash()) { continue; } if ($indexedfile->solr_fileindexstatus == document::INDEXED_FILE_FALSE && $this->file_is_indexable($files[$fileid])) { // This means that the last time we indexed this file, filtering blocked it. // Current settings say it is indexable, so we will allow it to be indexed. continue; } // If the file is already indexed, we can just remove it from the files array and skip it. unset($files[$fileid]); } else { // This means we have found a file that is no longer attached, so we need to delete from the index. // We do it later, since this is progressive, and it could reorder results. $idstodelete[] = $indexedfile->id; } } $count += $rows; if ($count < $numfound) { // If we haven't hit the total count yet, fetch the next batch. list($numfound, $indexedfiles) = $this->get_indexed_files($document, $count, $rows); } } while ($count < $numfound); // Delete files that are no longer attached. foreach ($idstodelete as $id) { // We directly delete the item using the client, as the engine delete_by_id won't work on file docs. $this->get_search_client()->deleteById($id); } } // Now we can actually index all the remaining files. foreach ($files as $file) { $this->add_stored_file($document, $file); } }
php
protected function process_document_files($document) { if (!$this->file_indexing_enabled()) { return; } // Maximum rows to process at a time. $rows = 500; // Get the attached files. $files = $document->get_files(); // If this isn't a new document, we need to check the exiting indexed files. if (!$document->get_is_new()) { // We do this progressively, so we can handle lots of files cleanly. list($numfound, $indexedfiles) = $this->get_indexed_files($document, 0, $rows); $count = 0; $idstodelete = array(); do { // Go through each indexed file. We want to not index any stored and unchanged ones, delete any missing ones. foreach ($indexedfiles as $indexedfile) { $fileid = $indexedfile->solr_fileid; if (isset($files[$fileid])) { // Check for changes that would mean we need to re-index the file. If so, just leave in $files. // Filelib does not guarantee time modified is updated, so we will check important values. if ($indexedfile->modified != $files[$fileid]->get_timemodified()) { continue; } if (strcmp($indexedfile->title, $files[$fileid]->get_filename()) !== 0) { continue; } if ($indexedfile->solr_filecontenthash != $files[$fileid]->get_contenthash()) { continue; } if ($indexedfile->solr_fileindexstatus == document::INDEXED_FILE_FALSE && $this->file_is_indexable($files[$fileid])) { // This means that the last time we indexed this file, filtering blocked it. // Current settings say it is indexable, so we will allow it to be indexed. continue; } // If the file is already indexed, we can just remove it from the files array and skip it. unset($files[$fileid]); } else { // This means we have found a file that is no longer attached, so we need to delete from the index. // We do it later, since this is progressive, and it could reorder results. $idstodelete[] = $indexedfile->id; } } $count += $rows; if ($count < $numfound) { // If we haven't hit the total count yet, fetch the next batch. list($numfound, $indexedfiles) = $this->get_indexed_files($document, $count, $rows); } } while ($count < $numfound); // Delete files that are no longer attached. foreach ($idstodelete as $id) { // We directly delete the item using the client, as the engine delete_by_id won't work on file docs. $this->get_search_client()->deleteById($id); } } // Now we can actually index all the remaining files. foreach ($files as $file) { $this->add_stored_file($document, $file); } }
[ "protected", "function", "process_document_files", "(", "$", "document", ")", "{", "if", "(", "!", "$", "this", "->", "file_indexing_enabled", "(", ")", ")", "{", "return", ";", "}", "// Maximum rows to process at a time.", "$", "rows", "=", "500", ";", "// Get the attached files.", "$", "files", "=", "$", "document", "->", "get_files", "(", ")", ";", "// If this isn't a new document, we need to check the exiting indexed files.", "if", "(", "!", "$", "document", "->", "get_is_new", "(", ")", ")", "{", "// We do this progressively, so we can handle lots of files cleanly.", "list", "(", "$", "numfound", ",", "$", "indexedfiles", ")", "=", "$", "this", "->", "get_indexed_files", "(", "$", "document", ",", "0", ",", "$", "rows", ")", ";", "$", "count", "=", "0", ";", "$", "idstodelete", "=", "array", "(", ")", ";", "do", "{", "// Go through each indexed file. We want to not index any stored and unchanged ones, delete any missing ones.", "foreach", "(", "$", "indexedfiles", "as", "$", "indexedfile", ")", "{", "$", "fileid", "=", "$", "indexedfile", "->", "solr_fileid", ";", "if", "(", "isset", "(", "$", "files", "[", "$", "fileid", "]", ")", ")", "{", "// Check for changes that would mean we need to re-index the file. If so, just leave in $files.", "// Filelib does not guarantee time modified is updated, so we will check important values.", "if", "(", "$", "indexedfile", "->", "modified", "!=", "$", "files", "[", "$", "fileid", "]", "->", "get_timemodified", "(", ")", ")", "{", "continue", ";", "}", "if", "(", "strcmp", "(", "$", "indexedfile", "->", "title", ",", "$", "files", "[", "$", "fileid", "]", "->", "get_filename", "(", ")", ")", "!==", "0", ")", "{", "continue", ";", "}", "if", "(", "$", "indexedfile", "->", "solr_filecontenthash", "!=", "$", "files", "[", "$", "fileid", "]", "->", "get_contenthash", "(", ")", ")", "{", "continue", ";", "}", "if", "(", "$", "indexedfile", "->", "solr_fileindexstatus", "==", "document", "::", "INDEXED_FILE_FALSE", "&&", "$", "this", "->", "file_is_indexable", "(", "$", "files", "[", "$", "fileid", "]", ")", ")", "{", "// This means that the last time we indexed this file, filtering blocked it.", "// Current settings say it is indexable, so we will allow it to be indexed.", "continue", ";", "}", "// If the file is already indexed, we can just remove it from the files array and skip it.", "unset", "(", "$", "files", "[", "$", "fileid", "]", ")", ";", "}", "else", "{", "// This means we have found a file that is no longer attached, so we need to delete from the index.", "// We do it later, since this is progressive, and it could reorder results.", "$", "idstodelete", "[", "]", "=", "$", "indexedfile", "->", "id", ";", "}", "}", "$", "count", "+=", "$", "rows", ";", "if", "(", "$", "count", "<", "$", "numfound", ")", "{", "// If we haven't hit the total count yet, fetch the next batch.", "list", "(", "$", "numfound", ",", "$", "indexedfiles", ")", "=", "$", "this", "->", "get_indexed_files", "(", "$", "document", ",", "$", "count", ",", "$", "rows", ")", ";", "}", "}", "while", "(", "$", "count", "<", "$", "numfound", ")", ";", "// Delete files that are no longer attached.", "foreach", "(", "$", "idstodelete", "as", "$", "id", ")", "{", "// We directly delete the item using the client, as the engine delete_by_id won't work on file docs.", "$", "this", "->", "get_search_client", "(", ")", "->", "deleteById", "(", "$", "id", ")", ";", "}", "}", "// Now we can actually index all the remaining files.", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "$", "this", "->", "add_stored_file", "(", "$", "document", ",", "$", "file", ")", ";", "}", "}" ]
Index files attached to the docuemnt, ensuring the index matches the current document files. For documents that aren't known to be new, we check the index for existing files. - New files we will add. - Existing and unchanged files we will skip. - File that are in the index but not on the document will be deleted from the index. - Files that have changed will be re-indexed. @param document $document
[ "Index", "files", "attached", "to", "the", "docuemnt", "ensuring", "the", "index", "matches", "the", "current", "document", "files", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/engine/solr/classes/engine.php#L790-L860
216,103
moodle/moodle
search/engine/solr/classes/engine.php
engine.get_indexed_files
protected function get_indexed_files($document, $start = 0, $rows = 500) { // Build a custom query that will get any document files that are in our solr_filegroupingid. $query = new \SolrQuery(); // We want to get all file records tied to a document. // For efficiency, we are building our own, stripped down, query. $query->setQuery('*'); $query->setRows($rows); $query->setStart($start); // We want a consistent sorting. $query->addSortField('id'); // We only want the bare minimum of fields. $query->addField('id'); $query->addField('modified'); $query->addField('title'); $query->addField('solr_fileid'); $query->addField('solr_filecontenthash'); $query->addField('solr_fileindexstatus'); $query->addFilterQuery('{!cache=false}solr_filegroupingid:(' . $document->get('id') . ')'); $query->addFilterQuery('type:' . \core_search\manager::TYPE_FILE); $response = $this->get_query_response($query); if (empty($response->response->numFound)) { return array(0, array()); } return array($response->response->numFound, $this->convert_file_results($response)); }
php
protected function get_indexed_files($document, $start = 0, $rows = 500) { // Build a custom query that will get any document files that are in our solr_filegroupingid. $query = new \SolrQuery(); // We want to get all file records tied to a document. // For efficiency, we are building our own, stripped down, query. $query->setQuery('*'); $query->setRows($rows); $query->setStart($start); // We want a consistent sorting. $query->addSortField('id'); // We only want the bare minimum of fields. $query->addField('id'); $query->addField('modified'); $query->addField('title'); $query->addField('solr_fileid'); $query->addField('solr_filecontenthash'); $query->addField('solr_fileindexstatus'); $query->addFilterQuery('{!cache=false}solr_filegroupingid:(' . $document->get('id') . ')'); $query->addFilterQuery('type:' . \core_search\manager::TYPE_FILE); $response = $this->get_query_response($query); if (empty($response->response->numFound)) { return array(0, array()); } return array($response->response->numFound, $this->convert_file_results($response)); }
[ "protected", "function", "get_indexed_files", "(", "$", "document", ",", "$", "start", "=", "0", ",", "$", "rows", "=", "500", ")", "{", "// Build a custom query that will get any document files that are in our solr_filegroupingid.", "$", "query", "=", "new", "\\", "SolrQuery", "(", ")", ";", "// We want to get all file records tied to a document.", "// For efficiency, we are building our own, stripped down, query.", "$", "query", "->", "setQuery", "(", "'*'", ")", ";", "$", "query", "->", "setRows", "(", "$", "rows", ")", ";", "$", "query", "->", "setStart", "(", "$", "start", ")", ";", "// We want a consistent sorting.", "$", "query", "->", "addSortField", "(", "'id'", ")", ";", "// We only want the bare minimum of fields.", "$", "query", "->", "addField", "(", "'id'", ")", ";", "$", "query", "->", "addField", "(", "'modified'", ")", ";", "$", "query", "->", "addField", "(", "'title'", ")", ";", "$", "query", "->", "addField", "(", "'solr_fileid'", ")", ";", "$", "query", "->", "addField", "(", "'solr_filecontenthash'", ")", ";", "$", "query", "->", "addField", "(", "'solr_fileindexstatus'", ")", ";", "$", "query", "->", "addFilterQuery", "(", "'{!cache=false}solr_filegroupingid:('", ".", "$", "document", "->", "get", "(", "'id'", ")", ".", "')'", ")", ";", "$", "query", "->", "addFilterQuery", "(", "'type:'", ".", "\\", "core_search", "\\", "manager", "::", "TYPE_FILE", ")", ";", "$", "response", "=", "$", "this", "->", "get_query_response", "(", "$", "query", ")", ";", "if", "(", "empty", "(", "$", "response", "->", "response", "->", "numFound", ")", ")", "{", "return", "array", "(", "0", ",", "array", "(", ")", ")", ";", "}", "return", "array", "(", "$", "response", "->", "response", "->", "numFound", ",", "$", "this", "->", "convert_file_results", "(", "$", "response", ")", ")", ";", "}" ]
Get the currently indexed files for a particular document, returns the total count, and a subset of files. @param document $document @param int $start The row to start the results on. Zero indexed. @param int $rows The number of rows to fetch @return array A two element array, the first is the total number of availble results, the second is an array of documents for the current request.
[ "Get", "the", "currently", "indexed", "files", "for", "a", "particular", "document", "returns", "the", "total", "count", "and", "a", "subset", "of", "files", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/engine/solr/classes/engine.php#L871-L900
216,104
moodle/moodle
search/engine/solr/classes/engine.php
engine.convert_file_results
protected function convert_file_results($responsedoc) { if (!$docs = $responsedoc->response->docs) { return array(); } $out = array(); foreach ($docs as $doc) { // Copy the bare minimim needed info. $result = new \stdClass(); $result->id = $doc->id; $result->modified = document::import_time_from_engine($doc->modified); $result->title = $doc->title; $result->solr_fileid = $doc->solr_fileid; $result->solr_filecontenthash = $doc->solr_filecontenthash; $result->solr_fileindexstatus = $doc->solr_fileindexstatus; $out[] = $result; } return $out; }
php
protected function convert_file_results($responsedoc) { if (!$docs = $responsedoc->response->docs) { return array(); } $out = array(); foreach ($docs as $doc) { // Copy the bare minimim needed info. $result = new \stdClass(); $result->id = $doc->id; $result->modified = document::import_time_from_engine($doc->modified); $result->title = $doc->title; $result->solr_fileid = $doc->solr_fileid; $result->solr_filecontenthash = $doc->solr_filecontenthash; $result->solr_fileindexstatus = $doc->solr_fileindexstatus; $out[] = $result; } return $out; }
[ "protected", "function", "convert_file_results", "(", "$", "responsedoc", ")", "{", "if", "(", "!", "$", "docs", "=", "$", "responsedoc", "->", "response", "->", "docs", ")", "{", "return", "array", "(", ")", ";", "}", "$", "out", "=", "array", "(", ")", ";", "foreach", "(", "$", "docs", "as", "$", "doc", ")", "{", "// Copy the bare minimim needed info.", "$", "result", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "result", "->", "id", "=", "$", "doc", "->", "id", ";", "$", "result", "->", "modified", "=", "document", "::", "import_time_from_engine", "(", "$", "doc", "->", "modified", ")", ";", "$", "result", "->", "title", "=", "$", "doc", "->", "title", ";", "$", "result", "->", "solr_fileid", "=", "$", "doc", "->", "solr_fileid", ";", "$", "result", "->", "solr_filecontenthash", "=", "$", "doc", "->", "solr_filecontenthash", ";", "$", "result", "->", "solr_fileindexstatus", "=", "$", "doc", "->", "solr_fileindexstatus", ";", "$", "out", "[", "]", "=", "$", "result", ";", "}", "return", "$", "out", ";", "}" ]
A very lightweight handler for getting information about already indexed files from a Solr response. @param SolrObject $responsedoc A Solr response document @return stdClass[] An array of objects that contain the basic information for file processing.
[ "A", "very", "lightweight", "handler", "for", "getting", "information", "about", "already", "indexed", "files", "from", "a", "Solr", "response", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/engine/solr/classes/engine.php#L908-L928
216,105
moodle/moodle
search/engine/solr/classes/engine.php
engine.file_is_indexable
protected function file_is_indexable($file) { if (!empty($this->config->maxindexfilekb) && ($file->get_filesize() > ($this->config->maxindexfilekb * 1024))) { // The file is too big to index. return false; } $mime = $file->get_mimetype(); if ($mime == 'application/vnd.moodle.backup') { // We don't index Moodle backup files. There is nothing usefully indexable in them. return false; } return true; }
php
protected function file_is_indexable($file) { if (!empty($this->config->maxindexfilekb) && ($file->get_filesize() > ($this->config->maxindexfilekb * 1024))) { // The file is too big to index. return false; } $mime = $file->get_mimetype(); if ($mime == 'application/vnd.moodle.backup') { // We don't index Moodle backup files. There is nothing usefully indexable in them. return false; } return true; }
[ "protected", "function", "file_is_indexable", "(", "$", "file", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "config", "->", "maxindexfilekb", ")", "&&", "(", "$", "file", "->", "get_filesize", "(", ")", ">", "(", "$", "this", "->", "config", "->", "maxindexfilekb", "*", "1024", ")", ")", ")", "{", "// The file is too big to index.", "return", "false", ";", "}", "$", "mime", "=", "$", "file", "->", "get_mimetype", "(", ")", ";", "if", "(", "$", "mime", "==", "'application/vnd.moodle.backup'", ")", "{", "// We don't index Moodle backup files. There is nothing usefully indexable in them.", "return", "false", ";", "}", "return", "true", ";", "}" ]
Checks to see if a passed file is indexable. @param \stored_file $file The file to check @return bool True if the file can be indexed
[ "Checks", "to", "see", "if", "a", "passed", "file", "is", "indexable", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/engine/solr/classes/engine.php#L1045-L1059
216,106
moodle/moodle
search/engine/solr/classes/engine.php
engine.is_server_ready
public function is_server_ready() { $configured = $this->is_server_configured(); if ($configured !== true) { return $configured; } // As part of the above we have already checked that we can contact the server. For pages // where performance is important, we skip doing a full schema check as well. if ($this->should_skip_schema_check()) { return true; } // Update schema if required/possible. $schemalatest = $this->check_latest_schema(); if ($schemalatest !== true) { return $schemalatest; } // Check that the schema is already set up. try { $schema = new \search_solr\schema(); $schema->validate_setup(); } catch (\moodle_exception $e) { return $e->getMessage(); } return true; }
php
public function is_server_ready() { $configured = $this->is_server_configured(); if ($configured !== true) { return $configured; } // As part of the above we have already checked that we can contact the server. For pages // where performance is important, we skip doing a full schema check as well. if ($this->should_skip_schema_check()) { return true; } // Update schema if required/possible. $schemalatest = $this->check_latest_schema(); if ($schemalatest !== true) { return $schemalatest; } // Check that the schema is already set up. try { $schema = new \search_solr\schema(); $schema->validate_setup(); } catch (\moodle_exception $e) { return $e->getMessage(); } return true; }
[ "public", "function", "is_server_ready", "(", ")", "{", "$", "configured", "=", "$", "this", "->", "is_server_configured", "(", ")", ";", "if", "(", "$", "configured", "!==", "true", ")", "{", "return", "$", "configured", ";", "}", "// As part of the above we have already checked that we can contact the server. For pages", "// where performance is important, we skip doing a full schema check as well.", "if", "(", "$", "this", "->", "should_skip_schema_check", "(", ")", ")", "{", "return", "true", ";", "}", "// Update schema if required/possible.", "$", "schemalatest", "=", "$", "this", "->", "check_latest_schema", "(", ")", ";", "if", "(", "$", "schemalatest", "!==", "true", ")", "{", "return", "$", "schemalatest", ";", "}", "// Check that the schema is already set up.", "try", "{", "$", "schema", "=", "new", "\\", "search_solr", "\\", "schema", "(", ")", ";", "$", "schema", "->", "validate_setup", "(", ")", ";", "}", "catch", "(", "\\", "moodle_exception", "$", "e", ")", "{", "return", "$", "e", "->", "getMessage", "(", ")", ";", "}", "return", "true", ";", "}" ]
Pings the Solr server using search_solr config @return true|string Returns true if all good or an error string.
[ "Pings", "the", "Solr", "server", "using", "search_solr", "config" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/engine/solr/classes/engine.php#L1136-L1164
216,107
moodle/moodle
search/engine/solr/classes/engine.php
engine.is_server_configured
public function is_server_configured() { if (empty($this->config->server_hostname) || empty($this->config->indexname)) { return 'No solr configuration found'; } if (!$client = $this->get_search_client(false)) { return get_string('engineserverstatus', 'search'); } try { if ($this->get_solr_major_version() < 4) { // Minimum solr 4.0. return get_string('minimumsolr4', 'search_solr'); } } catch (\SolrClientException $ex) { debugging('Solr client error: ' . html_to_text($ex->getMessage()), DEBUG_DEVELOPER); return get_string('engineserverstatus', 'search'); } catch (\SolrServerException $ex) { debugging('Solr server error: ' . html_to_text($ex->getMessage()), DEBUG_DEVELOPER); return get_string('engineserverstatus', 'search'); } return true; }
php
public function is_server_configured() { if (empty($this->config->server_hostname) || empty($this->config->indexname)) { return 'No solr configuration found'; } if (!$client = $this->get_search_client(false)) { return get_string('engineserverstatus', 'search'); } try { if ($this->get_solr_major_version() < 4) { // Minimum solr 4.0. return get_string('minimumsolr4', 'search_solr'); } } catch (\SolrClientException $ex) { debugging('Solr client error: ' . html_to_text($ex->getMessage()), DEBUG_DEVELOPER); return get_string('engineserverstatus', 'search'); } catch (\SolrServerException $ex) { debugging('Solr server error: ' . html_to_text($ex->getMessage()), DEBUG_DEVELOPER); return get_string('engineserverstatus', 'search'); } return true; }
[ "public", "function", "is_server_configured", "(", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "config", "->", "server_hostname", ")", "||", "empty", "(", "$", "this", "->", "config", "->", "indexname", ")", ")", "{", "return", "'No solr configuration found'", ";", "}", "if", "(", "!", "$", "client", "=", "$", "this", "->", "get_search_client", "(", "false", ")", ")", "{", "return", "get_string", "(", "'engineserverstatus'", ",", "'search'", ")", ";", "}", "try", "{", "if", "(", "$", "this", "->", "get_solr_major_version", "(", ")", "<", "4", ")", "{", "// Minimum solr 4.0.", "return", "get_string", "(", "'minimumsolr4'", ",", "'search_solr'", ")", ";", "}", "}", "catch", "(", "\\", "SolrClientException", "$", "ex", ")", "{", "debugging", "(", "'Solr client error: '", ".", "html_to_text", "(", "$", "ex", "->", "getMessage", "(", ")", ")", ",", "DEBUG_DEVELOPER", ")", ";", "return", "get_string", "(", "'engineserverstatus'", ",", "'search'", ")", ";", "}", "catch", "(", "\\", "SolrServerException", "$", "ex", ")", "{", "debugging", "(", "'Solr server error: '", ".", "html_to_text", "(", "$", "ex", "->", "getMessage", "(", ")", ")", ",", "DEBUG_DEVELOPER", ")", ";", "return", "get_string", "(", "'engineserverstatus'", ",", "'search'", ")", ";", "}", "return", "true", ";", "}" ]
Is the solr server properly configured?. @return true|string Returns true if all good or an error string.
[ "Is", "the", "solr", "server", "properly", "configured?", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/engine/solr/classes/engine.php#L1171-L1195
216,108
moodle/moodle
search/engine/solr/classes/engine.php
engine.get_solr_major_version
public function get_solr_major_version() { if ($this->solrmajorversion !== null) { return $this->solrmajorversion; } // We should really ping first the server to see if the specified indexname is valid but // we want to minimise solr server requests as they are expensive. system() emits a warning // if it can not connect to the configured index in the configured server. $systemdata = @$this->get_search_client()->system(); $solrversion = $systemdata->getResponse()->offsetGet('lucene')->offsetGet('solr-spec-version'); $this->solrmajorversion = intval(substr($solrversion, 0, strpos($solrversion, '.'))); return $this->solrmajorversion; }
php
public function get_solr_major_version() { if ($this->solrmajorversion !== null) { return $this->solrmajorversion; } // We should really ping first the server to see if the specified indexname is valid but // we want to minimise solr server requests as they are expensive. system() emits a warning // if it can not connect to the configured index in the configured server. $systemdata = @$this->get_search_client()->system(); $solrversion = $systemdata->getResponse()->offsetGet('lucene')->offsetGet('solr-spec-version'); $this->solrmajorversion = intval(substr($solrversion, 0, strpos($solrversion, '.'))); return $this->solrmajorversion; }
[ "public", "function", "get_solr_major_version", "(", ")", "{", "if", "(", "$", "this", "->", "solrmajorversion", "!==", "null", ")", "{", "return", "$", "this", "->", "solrmajorversion", ";", "}", "// We should really ping first the server to see if the specified indexname is valid but", "// we want to minimise solr server requests as they are expensive. system() emits a warning", "// if it can not connect to the configured index in the configured server.", "$", "systemdata", "=", "@", "$", "this", "->", "get_search_client", "(", ")", "->", "system", "(", ")", ";", "$", "solrversion", "=", "$", "systemdata", "->", "getResponse", "(", ")", "->", "offsetGet", "(", "'lucene'", ")", "->", "offsetGet", "(", "'solr-spec-version'", ")", ";", "$", "this", "->", "solrmajorversion", "=", "intval", "(", "substr", "(", "$", "solrversion", ",", "0", ",", "strpos", "(", "$", "solrversion", ",", "'.'", ")", ")", ")", ";", "return", "$", "this", "->", "solrmajorversion", ";", "}" ]
Returns the solr server major version. @return int
[ "Returns", "the", "solr", "server", "major", "version", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/engine/solr/classes/engine.php#L1202-L1215
216,109
moodle/moodle
search/engine/solr/classes/engine.php
engine.get_search_client
protected function get_search_client($triggerexception = true) { global $CFG; // Type comparison as it is set to false if not available. if ($this->client !== null) { return $this->client; } $options = array( 'hostname' => $this->config->server_hostname, 'path' => '/solr/' . $this->config->indexname, 'login' => !empty($this->config->server_username) ? $this->config->server_username : '', 'password' => !empty($this->config->server_password) ? $this->config->server_password : '', 'port' => !empty($this->config->server_port) ? $this->config->server_port : '', 'secure' => !empty($this->config->secure) ? true : false, 'ssl_cert' => !empty($this->config->ssl_cert) ? $this->config->ssl_cert : '', 'ssl_key' => !empty($this->config->ssl_key) ? $this->config->ssl_key : '', 'ssl_keypassword' => !empty($this->config->ssl_keypassword) ? $this->config->ssl_keypassword : '', 'ssl_cainfo' => !empty($this->config->ssl_cainfo) ? $this->config->ssl_cainfo : '', 'ssl_capath' => !empty($this->config->ssl_capath) ? $this->config->ssl_capath : '', 'timeout' => !empty($this->config->server_timeout) ? $this->config->server_timeout : '30' ); if ($CFG->proxyhost && !is_proxybypass('http://' . $this->config->server_hostname . '/')) { $options['proxy_host'] = $CFG->proxyhost; if (!empty($CFG->proxyport)) { $options['proxy_port'] = $CFG->proxyport; } if (!empty($CFG->proxyuser) && !empty($CFG->proxypassword)) { $options['proxy_login'] = $CFG->proxyuser; $options['proxy_password'] = $CFG->proxypassword; } } if (!class_exists('\SolrClient')) { throw new \core_search\engine_exception('enginenotinstalled', 'search', '', 'solr'); } $client = new \SolrClient($options); if ($client === false && $triggerexception) { throw new \core_search\engine_exception('engineserverstatus', 'search'); } if ($this->cacheclient) { $this->client = $client; } return $client; }
php
protected function get_search_client($triggerexception = true) { global $CFG; // Type comparison as it is set to false if not available. if ($this->client !== null) { return $this->client; } $options = array( 'hostname' => $this->config->server_hostname, 'path' => '/solr/' . $this->config->indexname, 'login' => !empty($this->config->server_username) ? $this->config->server_username : '', 'password' => !empty($this->config->server_password) ? $this->config->server_password : '', 'port' => !empty($this->config->server_port) ? $this->config->server_port : '', 'secure' => !empty($this->config->secure) ? true : false, 'ssl_cert' => !empty($this->config->ssl_cert) ? $this->config->ssl_cert : '', 'ssl_key' => !empty($this->config->ssl_key) ? $this->config->ssl_key : '', 'ssl_keypassword' => !empty($this->config->ssl_keypassword) ? $this->config->ssl_keypassword : '', 'ssl_cainfo' => !empty($this->config->ssl_cainfo) ? $this->config->ssl_cainfo : '', 'ssl_capath' => !empty($this->config->ssl_capath) ? $this->config->ssl_capath : '', 'timeout' => !empty($this->config->server_timeout) ? $this->config->server_timeout : '30' ); if ($CFG->proxyhost && !is_proxybypass('http://' . $this->config->server_hostname . '/')) { $options['proxy_host'] = $CFG->proxyhost; if (!empty($CFG->proxyport)) { $options['proxy_port'] = $CFG->proxyport; } if (!empty($CFG->proxyuser) && !empty($CFG->proxypassword)) { $options['proxy_login'] = $CFG->proxyuser; $options['proxy_password'] = $CFG->proxypassword; } } if (!class_exists('\SolrClient')) { throw new \core_search\engine_exception('enginenotinstalled', 'search', '', 'solr'); } $client = new \SolrClient($options); if ($client === false && $triggerexception) { throw new \core_search\engine_exception('engineserverstatus', 'search'); } if ($this->cacheclient) { $this->client = $client; } return $client; }
[ "protected", "function", "get_search_client", "(", "$", "triggerexception", "=", "true", ")", "{", "global", "$", "CFG", ";", "// Type comparison as it is set to false if not available.", "if", "(", "$", "this", "->", "client", "!==", "null", ")", "{", "return", "$", "this", "->", "client", ";", "}", "$", "options", "=", "array", "(", "'hostname'", "=>", "$", "this", "->", "config", "->", "server_hostname", ",", "'path'", "=>", "'/solr/'", ".", "$", "this", "->", "config", "->", "indexname", ",", "'login'", "=>", "!", "empty", "(", "$", "this", "->", "config", "->", "server_username", ")", "?", "$", "this", "->", "config", "->", "server_username", ":", "''", ",", "'password'", "=>", "!", "empty", "(", "$", "this", "->", "config", "->", "server_password", ")", "?", "$", "this", "->", "config", "->", "server_password", ":", "''", ",", "'port'", "=>", "!", "empty", "(", "$", "this", "->", "config", "->", "server_port", ")", "?", "$", "this", "->", "config", "->", "server_port", ":", "''", ",", "'secure'", "=>", "!", "empty", "(", "$", "this", "->", "config", "->", "secure", ")", "?", "true", ":", "false", ",", "'ssl_cert'", "=>", "!", "empty", "(", "$", "this", "->", "config", "->", "ssl_cert", ")", "?", "$", "this", "->", "config", "->", "ssl_cert", ":", "''", ",", "'ssl_key'", "=>", "!", "empty", "(", "$", "this", "->", "config", "->", "ssl_key", ")", "?", "$", "this", "->", "config", "->", "ssl_key", ":", "''", ",", "'ssl_keypassword'", "=>", "!", "empty", "(", "$", "this", "->", "config", "->", "ssl_keypassword", ")", "?", "$", "this", "->", "config", "->", "ssl_keypassword", ":", "''", ",", "'ssl_cainfo'", "=>", "!", "empty", "(", "$", "this", "->", "config", "->", "ssl_cainfo", ")", "?", "$", "this", "->", "config", "->", "ssl_cainfo", ":", "''", ",", "'ssl_capath'", "=>", "!", "empty", "(", "$", "this", "->", "config", "->", "ssl_capath", ")", "?", "$", "this", "->", "config", "->", "ssl_capath", ":", "''", ",", "'timeout'", "=>", "!", "empty", "(", "$", "this", "->", "config", "->", "server_timeout", ")", "?", "$", "this", "->", "config", "->", "server_timeout", ":", "'30'", ")", ";", "if", "(", "$", "CFG", "->", "proxyhost", "&&", "!", "is_proxybypass", "(", "'http://'", ".", "$", "this", "->", "config", "->", "server_hostname", ".", "'/'", ")", ")", "{", "$", "options", "[", "'proxy_host'", "]", "=", "$", "CFG", "->", "proxyhost", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "proxyport", ")", ")", "{", "$", "options", "[", "'proxy_port'", "]", "=", "$", "CFG", "->", "proxyport", ";", "}", "if", "(", "!", "empty", "(", "$", "CFG", "->", "proxyuser", ")", "&&", "!", "empty", "(", "$", "CFG", "->", "proxypassword", ")", ")", "{", "$", "options", "[", "'proxy_login'", "]", "=", "$", "CFG", "->", "proxyuser", ";", "$", "options", "[", "'proxy_password'", "]", "=", "$", "CFG", "->", "proxypassword", ";", "}", "}", "if", "(", "!", "class_exists", "(", "'\\SolrClient'", ")", ")", "{", "throw", "new", "\\", "core_search", "\\", "engine_exception", "(", "'enginenotinstalled'", ",", "'search'", ",", "''", ",", "'solr'", ")", ";", "}", "$", "client", "=", "new", "\\", "SolrClient", "(", "$", "options", ")", ";", "if", "(", "$", "client", "===", "false", "&&", "$", "triggerexception", ")", "{", "throw", "new", "\\", "core_search", "\\", "engine_exception", "(", "'engineserverstatus'", ",", "'search'", ")", ";", "}", "if", "(", "$", "this", "->", "cacheclient", ")", "{", "$", "this", "->", "client", "=", "$", "client", ";", "}", "return", "$", "client", ";", "}" ]
Returns the solr client instance. We don't reuse SolrClient if we are on libcurl 7.35.0, due to a bug in that version of curl. @throws \core_search\engine_exception @param bool $triggerexception @return \SolrClient
[ "Returns", "the", "solr", "client", "instance", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/engine/solr/classes/engine.php#L1235-L1284
216,110
moodle/moodle
search/engine/solr/classes/engine.php
engine.get_curl_object
public function get_curl_object() { if (!is_null($this->curl)) { return $this->curl; } // Connection to Solr is allowed to use 'localhost' and other potentially blocked hosts/ports. $this->curl = new \curl(['ignoresecurity' => true]); $options = array(); // Build the SSL options. Based on pecl-solr and general testing. if (!empty($this->config->secure)) { if (!empty($this->config->ssl_cert)) { $options['CURLOPT_SSLCERT'] = $this->config->ssl_cert; $options['CURLOPT_SSLCERTTYPE'] = 'PEM'; } if (!empty($this->config->ssl_key)) { $options['CURLOPT_SSLKEY'] = $this->config->ssl_key; $options['CURLOPT_SSLKEYTYPE'] = 'PEM'; } if (!empty($this->config->ssl_keypassword)) { $options['CURLOPT_KEYPASSWD'] = $this->config->ssl_keypassword; } if (!empty($this->config->ssl_cainfo)) { $options['CURLOPT_CAINFO'] = $this->config->ssl_cainfo; } if (!empty($this->config->ssl_capath)) { $options['CURLOPT_CAPATH'] = $this->config->ssl_capath; } } // Set timeout as for Solr client. $options['CURLOPT_TIMEOUT'] = !empty($this->config->server_timeout) ? $this->config->server_timeout : '30'; $this->curl->setopt($options); if (!empty($this->config->server_username) && !empty($this->config->server_password)) { $authorization = $this->config->server_username . ':' . $this->config->server_password; $this->curl->setHeader('Authorization: Basic ' . base64_encode($authorization)); } return $this->curl; }
php
public function get_curl_object() { if (!is_null($this->curl)) { return $this->curl; } // Connection to Solr is allowed to use 'localhost' and other potentially blocked hosts/ports. $this->curl = new \curl(['ignoresecurity' => true]); $options = array(); // Build the SSL options. Based on pecl-solr and general testing. if (!empty($this->config->secure)) { if (!empty($this->config->ssl_cert)) { $options['CURLOPT_SSLCERT'] = $this->config->ssl_cert; $options['CURLOPT_SSLCERTTYPE'] = 'PEM'; } if (!empty($this->config->ssl_key)) { $options['CURLOPT_SSLKEY'] = $this->config->ssl_key; $options['CURLOPT_SSLKEYTYPE'] = 'PEM'; } if (!empty($this->config->ssl_keypassword)) { $options['CURLOPT_KEYPASSWD'] = $this->config->ssl_keypassword; } if (!empty($this->config->ssl_cainfo)) { $options['CURLOPT_CAINFO'] = $this->config->ssl_cainfo; } if (!empty($this->config->ssl_capath)) { $options['CURLOPT_CAPATH'] = $this->config->ssl_capath; } } // Set timeout as for Solr client. $options['CURLOPT_TIMEOUT'] = !empty($this->config->server_timeout) ? $this->config->server_timeout : '30'; $this->curl->setopt($options); if (!empty($this->config->server_username) && !empty($this->config->server_password)) { $authorization = $this->config->server_username . ':' . $this->config->server_password; $this->curl->setHeader('Authorization: Basic ' . base64_encode($authorization)); } return $this->curl; }
[ "public", "function", "get_curl_object", "(", ")", "{", "if", "(", "!", "is_null", "(", "$", "this", "->", "curl", ")", ")", "{", "return", "$", "this", "->", "curl", ";", "}", "// Connection to Solr is allowed to use 'localhost' and other potentially blocked hosts/ports.", "$", "this", "->", "curl", "=", "new", "\\", "curl", "(", "[", "'ignoresecurity'", "=>", "true", "]", ")", ";", "$", "options", "=", "array", "(", ")", ";", "// Build the SSL options. Based on pecl-solr and general testing.", "if", "(", "!", "empty", "(", "$", "this", "->", "config", "->", "secure", ")", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "config", "->", "ssl_cert", ")", ")", "{", "$", "options", "[", "'CURLOPT_SSLCERT'", "]", "=", "$", "this", "->", "config", "->", "ssl_cert", ";", "$", "options", "[", "'CURLOPT_SSLCERTTYPE'", "]", "=", "'PEM'", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "config", "->", "ssl_key", ")", ")", "{", "$", "options", "[", "'CURLOPT_SSLKEY'", "]", "=", "$", "this", "->", "config", "->", "ssl_key", ";", "$", "options", "[", "'CURLOPT_SSLKEYTYPE'", "]", "=", "'PEM'", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "config", "->", "ssl_keypassword", ")", ")", "{", "$", "options", "[", "'CURLOPT_KEYPASSWD'", "]", "=", "$", "this", "->", "config", "->", "ssl_keypassword", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "config", "->", "ssl_cainfo", ")", ")", "{", "$", "options", "[", "'CURLOPT_CAINFO'", "]", "=", "$", "this", "->", "config", "->", "ssl_cainfo", ";", "}", "if", "(", "!", "empty", "(", "$", "this", "->", "config", "->", "ssl_capath", ")", ")", "{", "$", "options", "[", "'CURLOPT_CAPATH'", "]", "=", "$", "this", "->", "config", "->", "ssl_capath", ";", "}", "}", "// Set timeout as for Solr client.", "$", "options", "[", "'CURLOPT_TIMEOUT'", "]", "=", "!", "empty", "(", "$", "this", "->", "config", "->", "server_timeout", ")", "?", "$", "this", "->", "config", "->", "server_timeout", ":", "'30'", ";", "$", "this", "->", "curl", "->", "setopt", "(", "$", "options", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "config", "->", "server_username", ")", "&&", "!", "empty", "(", "$", "this", "->", "config", "->", "server_password", ")", ")", "{", "$", "authorization", "=", "$", "this", "->", "config", "->", "server_username", ".", "':'", ".", "$", "this", "->", "config", "->", "server_password", ";", "$", "this", "->", "curl", "->", "setHeader", "(", "'Authorization: Basic '", ".", "base64_encode", "(", "$", "authorization", ")", ")", ";", "}", "return", "$", "this", "->", "curl", ";", "}" ]
Returns a curl object for conntecting to solr. @return \curl
[ "Returns", "a", "curl", "object", "for", "conntecting", "to", "solr", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/engine/solr/classes/engine.php#L1291-L1336
216,111
moodle/moodle
search/engine/solr/classes/engine.php
engine.get_connection_url
public function get_connection_url($path) { // Must use the proper protocol, or SSL will fail. $protocol = !empty($this->config->secure) ? 'https' : 'http'; $url = $protocol . '://' . rtrim($this->config->server_hostname, '/'); if (!empty($this->config->server_port)) { $url .= ':' . $this->config->server_port; } $url .= '/solr/' . $this->config->indexname . '/' . ltrim($path, '/'); return new \moodle_url($url); }
php
public function get_connection_url($path) { // Must use the proper protocol, or SSL will fail. $protocol = !empty($this->config->secure) ? 'https' : 'http'; $url = $protocol . '://' . rtrim($this->config->server_hostname, '/'); if (!empty($this->config->server_port)) { $url .= ':' . $this->config->server_port; } $url .= '/solr/' . $this->config->indexname . '/' . ltrim($path, '/'); return new \moodle_url($url); }
[ "public", "function", "get_connection_url", "(", "$", "path", ")", "{", "// Must use the proper protocol, or SSL will fail.", "$", "protocol", "=", "!", "empty", "(", "$", "this", "->", "config", "->", "secure", ")", "?", "'https'", ":", "'http'", ";", "$", "url", "=", "$", "protocol", ".", "'://'", ".", "rtrim", "(", "$", "this", "->", "config", "->", "server_hostname", ",", "'/'", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "config", "->", "server_port", ")", ")", "{", "$", "url", ".=", "':'", ".", "$", "this", "->", "config", "->", "server_port", ";", "}", "$", "url", ".=", "'/solr/'", ".", "$", "this", "->", "config", "->", "indexname", ".", "'/'", ".", "ltrim", "(", "$", "path", ",", "'/'", ")", ";", "return", "new", "\\", "moodle_url", "(", "$", "url", ")", ";", "}" ]
Return a Moodle url object for the server connection. @param string $path The solr path to append. @return \moodle_url
[ "Return", "a", "Moodle", "url", "object", "for", "the", "server", "connection", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/engine/solr/classes/engine.php#L1344-L1354
216,112
moodle/moodle
search/engine/solr/classes/engine.php
engine.get_supported_orders
public function get_supported_orders(\context $context) { $orders = parent::get_supported_orders($context); // If not within a course, no other kind of sorting supported. $coursecontext = $context->get_course_context(false); if ($coursecontext) { // Within a course or activity/block, support sort by location. $orders['location'] = get_string('order_location', 'search', $context->get_context_name()); } return $orders; }
php
public function get_supported_orders(\context $context) { $orders = parent::get_supported_orders($context); // If not within a course, no other kind of sorting supported. $coursecontext = $context->get_course_context(false); if ($coursecontext) { // Within a course or activity/block, support sort by location. $orders['location'] = get_string('order_location', 'search', $context->get_context_name()); } return $orders; }
[ "public", "function", "get_supported_orders", "(", "\\", "context", "$", "context", ")", "{", "$", "orders", "=", "parent", "::", "get_supported_orders", "(", "$", "context", ")", ";", "// If not within a course, no other kind of sorting supported.", "$", "coursecontext", "=", "$", "context", "->", "get_course_context", "(", "false", ")", ";", "if", "(", "$", "coursecontext", ")", "{", "// Within a course or activity/block, support sort by location.", "$", "orders", "[", "'location'", "]", "=", "get_string", "(", "'order_location'", ",", "'search'", ",", "$", "context", "->", "get_context_name", "(", ")", ")", ";", "}", "return", "$", "orders", ";", "}" ]
Solr supports sort by location within course contexts or below. @param \context $context Context that the user requested search from @return array Array from order name => display text
[ "Solr", "supports", "sort", "by", "location", "within", "course", "contexts", "or", "below", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/engine/solr/classes/engine.php#L1398-L1410
216,113
moodle/moodle
badges/criteria/award_criteria_competency.php
award_criteria_competency.has_records_for_competencies
public static function has_records_for_competencies($competencyids) { global $DB; list($insql, $params) = $DB->get_in_or_equal($competencyids, SQL_PARAMS_NAMED); $sql = "SELECT DISTINCT bc.badgeid FROM {badge_criteria} bc JOIN {badge_criteria_param} bcp ON bc.id = bcp.critid WHERE bc.criteriatype = :criteriatype AND value $insql"; $params['criteriatype'] = BADGE_CRITERIA_TYPE_COMPETENCY; return self::record_exists_sql($sql, $params); }
php
public static function has_records_for_competencies($competencyids) { global $DB; list($insql, $params) = $DB->get_in_or_equal($competencyids, SQL_PARAMS_NAMED); $sql = "SELECT DISTINCT bc.badgeid FROM {badge_criteria} bc JOIN {badge_criteria_param} bcp ON bc.id = bcp.critid WHERE bc.criteriatype = :criteriatype AND value $insql"; $params['criteriatype'] = BADGE_CRITERIA_TYPE_COMPETENCY; return self::record_exists_sql($sql, $params); }
[ "public", "static", "function", "has_records_for_competencies", "(", "$", "competencyids", ")", "{", "global", "$", "DB", ";", "list", "(", "$", "insql", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "competencyids", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "sql", "=", "\"SELECT DISTINCT bc.badgeid\n FROM {badge_criteria} bc\n JOIN {badge_criteria_param} bcp ON bc.id = bcp.critid\n WHERE bc.criteriatype = :criteriatype AND value $insql\"", ";", "$", "params", "[", "'criteriatype'", "]", "=", "BADGE_CRITERIA_TYPE_COMPETENCY", ";", "return", "self", "::", "record_exists_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "}" ]
Check if any badge has records for competencies. @param array $competencyids Array of competencies ids. @return boolean Return true if competencies were found in any badge.
[ "Check", "if", "any", "badge", "has", "records", "for", "competencies", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/badges/criteria/award_criteria_competency.php#L272-L282
216,114
moodle/moodle
tag/classes/index_builder.php
core_tag_index_builder.prepare_sql_courses
protected function prepare_sql_courses() { global $DB; if (!preg_match('/\\%COURSEFILTER\\%/', $this->sql)) { return; } $this->init_course_access(); $unaccessiblecourses = array_filter($this->courseaccess, function($item) { return !$item; }); $idx = 0; while (preg_match('/^([^\\0]*?)\\%COURSEFILTER\\%([^\\0]*)$/', $this->sql, $matches)) { list($sql, $params) = $DB->get_in_or_equal(array_keys($unaccessiblecourses), SQL_PARAMS_NAMED, 'ca_'.($idx++).'_', false, 0); $this->sql = $matches[1].' '.$sql.' '.$matches[2]; $this->params += $params; } }
php
protected function prepare_sql_courses() { global $DB; if (!preg_match('/\\%COURSEFILTER\\%/', $this->sql)) { return; } $this->init_course_access(); $unaccessiblecourses = array_filter($this->courseaccess, function($item) { return !$item; }); $idx = 0; while (preg_match('/^([^\\0]*?)\\%COURSEFILTER\\%([^\\0]*)$/', $this->sql, $matches)) { list($sql, $params) = $DB->get_in_or_equal(array_keys($unaccessiblecourses), SQL_PARAMS_NAMED, 'ca_'.($idx++).'_', false, 0); $this->sql = $matches[1].' '.$sql.' '.$matches[2]; $this->params += $params; } }
[ "protected", "function", "prepare_sql_courses", "(", ")", "{", "global", "$", "DB", ";", "if", "(", "!", "preg_match", "(", "'/\\\\%COURSEFILTER\\\\%/'", ",", "$", "this", "->", "sql", ")", ")", "{", "return", ";", "}", "$", "this", "->", "init_course_access", "(", ")", ";", "$", "unaccessiblecourses", "=", "array_filter", "(", "$", "this", "->", "courseaccess", ",", "function", "(", "$", "item", ")", "{", "return", "!", "$", "item", ";", "}", ")", ";", "$", "idx", "=", "0", ";", "while", "(", "preg_match", "(", "'/^([^\\\\0]*?)\\\\%COURSEFILTER\\\\%([^\\\\0]*)$/'", ",", "$", "this", "->", "sql", ",", "$", "matches", ")", ")", "{", "list", "(", "$", "sql", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "array_keys", "(", "$", "unaccessiblecourses", ")", ",", "SQL_PARAMS_NAMED", ",", "'ca_'", ".", "(", "$", "idx", "++", ")", ".", "'_'", ",", "false", ",", "0", ")", ";", "$", "this", "->", "sql", "=", "$", "matches", "[", "1", "]", ".", "' '", ".", "$", "sql", ".", "' '", ".", "$", "matches", "[", "2", "]", ";", "$", "this", "->", "params", "+=", "$", "params", ";", "}", "}" ]
Substitute %COURSEFILTER% with an expression filtering out courses where current user does not have access
[ "Substitute", "%COURSEFILTER%", "with", "an", "expression", "filtering", "out", "courses", "where", "current", "user", "does", "not", "have", "access" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/index_builder.php#L134-L150
216,115
moodle/moodle
tag/classes/index_builder.php
core_tag_index_builder.prepare_sql_items
protected function prepare_sql_items() { global $DB; if (!preg_match('/\\%ITEMFILTER\\%/', $this->sql)) { return; } $this->init_items_access(); $unaccessibleitems = array_filter($this->accessibleitems, function($item) { return !$item; }); $idx = 0; while (preg_match('/^([^\\0]*?)\\%ITEMFILTER\\%([^\\0]*)$/', $this->sql, $matches)) { list($sql, $params) = $DB->get_in_or_equal(array_keys($unaccessibleitems), SQL_PARAMS_NAMED, 'ia_'.($idx++).'_', false, 0); $this->sql = $matches[1].' '.$sql.' '.$matches[2]; $this->params += $params; } }
php
protected function prepare_sql_items() { global $DB; if (!preg_match('/\\%ITEMFILTER\\%/', $this->sql)) { return; } $this->init_items_access(); $unaccessibleitems = array_filter($this->accessibleitems, function($item) { return !$item; }); $idx = 0; while (preg_match('/^([^\\0]*?)\\%ITEMFILTER\\%([^\\0]*)$/', $this->sql, $matches)) { list($sql, $params) = $DB->get_in_or_equal(array_keys($unaccessibleitems), SQL_PARAMS_NAMED, 'ia_'.($idx++).'_', false, 0); $this->sql = $matches[1].' '.$sql.' '.$matches[2]; $this->params += $params; } }
[ "protected", "function", "prepare_sql_items", "(", ")", "{", "global", "$", "DB", ";", "if", "(", "!", "preg_match", "(", "'/\\\\%ITEMFILTER\\\\%/'", ",", "$", "this", "->", "sql", ")", ")", "{", "return", ";", "}", "$", "this", "->", "init_items_access", "(", ")", ";", "$", "unaccessibleitems", "=", "array_filter", "(", "$", "this", "->", "accessibleitems", ",", "function", "(", "$", "item", ")", "{", "return", "!", "$", "item", ";", "}", ")", ";", "$", "idx", "=", "0", ";", "while", "(", "preg_match", "(", "'/^([^\\\\0]*?)\\\\%ITEMFILTER\\\\%([^\\\\0]*)$/'", ",", "$", "this", "->", "sql", ",", "$", "matches", ")", ")", "{", "list", "(", "$", "sql", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "array_keys", "(", "$", "unaccessibleitems", ")", ",", "SQL_PARAMS_NAMED", ",", "'ia_'", ".", "(", "$", "idx", "++", ")", ".", "'_'", ",", "false", ",", "0", ")", ";", "$", "this", "->", "sql", "=", "$", "matches", "[", "1", "]", ".", "' '", ".", "$", "sql", ".", "' '", ".", "$", "matches", "[", "2", "]", ";", "$", "this", "->", "params", "+=", "$", "params", ";", "}", "}" ]
Substitute %ITEMFILTER% with an expression filtering out items where current user does not have access
[ "Substitute", "%ITEMFILTER%", "with", "an", "expression", "filtering", "out", "items", "where", "current", "user", "does", "not", "have", "access" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/index_builder.php#L155-L171
216,116
moodle/moodle
tag/classes/index_builder.php
core_tag_index_builder.get_items
public function get_items() { global $DB, $CFG; if (is_siteadmin()) { $this->sql = preg_replace('/\\%COURSEFILTER\\%/', '<>0', $this->sql); $this->sql = preg_replace('/\\%ITEMFILTER\\%/', '<>0', $this->sql); return $DB->get_records_sql($this->sql, $this->params, $this->from, $this->limit); } if ($CFG->debugdeveloper && $this->has_item_that_needs_access_check()) { debugging('Caller must ensure that has_item_that_needs_access_check() does not return anything ' . 'before calling get_items(). The item list may be incomplete', DEBUG_DEVELOPER); } $this->retrieve_items(); $this->save_caches(); $idx = 0; $items = array(); foreach ($this->itemkeys as $id) { if (!array_key_exists($id, $this->accessibleitems) || !$this->accessibleitems[$id]) { continue; } if ($idx >= $this->from) { $items[$id] = $this->items[$id]; } $idx++; if ($idx >= $this->from + $this->limit) { break; } } return $items; }
php
public function get_items() { global $DB, $CFG; if (is_siteadmin()) { $this->sql = preg_replace('/\\%COURSEFILTER\\%/', '<>0', $this->sql); $this->sql = preg_replace('/\\%ITEMFILTER\\%/', '<>0', $this->sql); return $DB->get_records_sql($this->sql, $this->params, $this->from, $this->limit); } if ($CFG->debugdeveloper && $this->has_item_that_needs_access_check()) { debugging('Caller must ensure that has_item_that_needs_access_check() does not return anything ' . 'before calling get_items(). The item list may be incomplete', DEBUG_DEVELOPER); } $this->retrieve_items(); $this->save_caches(); $idx = 0; $items = array(); foreach ($this->itemkeys as $id) { if (!array_key_exists($id, $this->accessibleitems) || !$this->accessibleitems[$id]) { continue; } if ($idx >= $this->from) { $items[$id] = $this->items[$id]; } $idx++; if ($idx >= $this->from + $this->limit) { break; } } return $items; }
[ "public", "function", "get_items", "(", ")", "{", "global", "$", "DB", ",", "$", "CFG", ";", "if", "(", "is_siteadmin", "(", ")", ")", "{", "$", "this", "->", "sql", "=", "preg_replace", "(", "'/\\\\%COURSEFILTER\\\\%/'", ",", "'<>0'", ",", "$", "this", "->", "sql", ")", ";", "$", "this", "->", "sql", "=", "preg_replace", "(", "'/\\\\%ITEMFILTER\\\\%/'", ",", "'<>0'", ",", "$", "this", "->", "sql", ")", ";", "return", "$", "DB", "->", "get_records_sql", "(", "$", "this", "->", "sql", ",", "$", "this", "->", "params", ",", "$", "this", "->", "from", ",", "$", "this", "->", "limit", ")", ";", "}", "if", "(", "$", "CFG", "->", "debugdeveloper", "&&", "$", "this", "->", "has_item_that_needs_access_check", "(", ")", ")", "{", "debugging", "(", "'Caller must ensure that has_item_that_needs_access_check() does not return anything '", ".", "'before calling get_items(). The item list may be incomplete'", ",", "DEBUG_DEVELOPER", ")", ";", "}", "$", "this", "->", "retrieve_items", "(", ")", ";", "$", "this", "->", "save_caches", "(", ")", ";", "$", "idx", "=", "0", ";", "$", "items", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "itemkeys", "as", "$", "id", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "id", ",", "$", "this", "->", "accessibleitems", ")", "||", "!", "$", "this", "->", "accessibleitems", "[", "$", "id", "]", ")", "{", "continue", ";", "}", "if", "(", "$", "idx", ">=", "$", "this", "->", "from", ")", "{", "$", "items", "[", "$", "id", "]", "=", "$", "this", "->", "items", "[", "$", "id", "]", ";", "}", "$", "idx", "++", ";", "if", "(", "$", "idx", ">=", "$", "this", "->", "from", "+", "$", "this", "->", "limit", ")", "{", "break", ";", "}", "}", "return", "$", "items", ";", "}" ]
Returns the filtered records from SQL query result. This function can only be executed after $builder->has_item_that_needs_access_check() returns null @return array
[ "Returns", "the", "filtered", "records", "from", "SQL", "query", "result", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/index_builder.php#L202-L230
216,117
moodle/moodle
tag/classes/index_builder.php
core_tag_index_builder.has_item_that_needs_access_check
public function has_item_that_needs_access_check() { if (is_siteadmin()) { return null; } $this->retrieve_items(); $counter = 0; // Counter for accessible items. foreach ($this->itemkeys as $id) { if (!array_key_exists($id, $this->accessibleitems)) { return (object)(array)$this->items[$id]; } $counter += $this->accessibleitems[$id] ? 1 : 0; if ($counter >= $this->from + $this->limit) { // We found enough accessible items fot get_items() method, do not look any further. return null; } } return null; }
php
public function has_item_that_needs_access_check() { if (is_siteadmin()) { return null; } $this->retrieve_items(); $counter = 0; // Counter for accessible items. foreach ($this->itemkeys as $id) { if (!array_key_exists($id, $this->accessibleitems)) { return (object)(array)$this->items[$id]; } $counter += $this->accessibleitems[$id] ? 1 : 0; if ($counter >= $this->from + $this->limit) { // We found enough accessible items fot get_items() method, do not look any further. return null; } } return null; }
[ "public", "function", "has_item_that_needs_access_check", "(", ")", "{", "if", "(", "is_siteadmin", "(", ")", ")", "{", "return", "null", ";", "}", "$", "this", "->", "retrieve_items", "(", ")", ";", "$", "counter", "=", "0", ";", "// Counter for accessible items.", "foreach", "(", "$", "this", "->", "itemkeys", "as", "$", "id", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "id", ",", "$", "this", "->", "accessibleitems", ")", ")", "{", "return", "(", "object", ")", "(", "array", ")", "$", "this", "->", "items", "[", "$", "id", "]", ";", "}", "$", "counter", "+=", "$", "this", "->", "accessibleitems", "[", "$", "id", "]", "?", "1", ":", "0", ";", "if", "(", "$", "counter", ">=", "$", "this", "->", "from", "+", "$", "this", "->", "limit", ")", "{", "// We found enough accessible items fot get_items() method, do not look any further.", "return", "null", ";", "}", "}", "return", "null", ";", "}" ]
Returns the first row from the SQL result that we don't know whether it is accessible by user or not. This will return null when we have necessary number of accessible items to return in {@link get_items()} After analyzing you may decide to mark not only this record but all similar as accessible or not accessible. For example, if you already call get_fast_modinfo() to check this item's accessibility, why not mark all items in the same course as accessible or not accessible. Helpful methods: {@link set_accessible()} and {@link walk()} @return null|object
[ "Returns", "the", "first", "row", "from", "the", "SQL", "result", "that", "we", "don", "t", "know", "whether", "it", "is", "accessible", "by", "user", "or", "not", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/index_builder.php#L245-L262
216,118
moodle/moodle
tag/classes/index_builder.php
core_tag_index_builder.init_items_access
protected function init_items_access() { if ($this->accessibleitems === null) { $this->accessibleitems = cache::make('core', 'tagindexbuilder')->get($this->component.'__'.$this->itemtype) ?: []; } }
php
protected function init_items_access() { if ($this->accessibleitems === null) { $this->accessibleitems = cache::make('core', 'tagindexbuilder')->get($this->component.'__'.$this->itemtype) ?: []; } }
[ "protected", "function", "init_items_access", "(", ")", "{", "if", "(", "$", "this", "->", "accessibleitems", "===", "null", ")", "{", "$", "this", "->", "accessibleitems", "=", "cache", "::", "make", "(", "'core'", ",", "'tagindexbuilder'", ")", "->", "get", "(", "$", "this", "->", "component", ".", "'__'", ".", "$", "this", "->", "itemtype", ")", "?", ":", "[", "]", ";", "}", "}" ]
Ensures that we read the items access from the cache.
[ "Ensures", "that", "we", "read", "the", "items", "access", "from", "the", "cache", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/index_builder.php#L329-L333
216,119
moodle/moodle
tag/classes/index_builder.php
core_tag_index_builder.can_access_course
public function can_access_course($courseid) { $this->init_course_access(); if (!array_key_exists($courseid, $this->courseaccess)) { $this->courseaccess[$courseid] = can_access_course($this->get_course($courseid)) ? 1 : 0; $this->cachechangedcourse = true; } return $this->courseaccess[$courseid]; }
php
public function can_access_course($courseid) { $this->init_course_access(); if (!array_key_exists($courseid, $this->courseaccess)) { $this->courseaccess[$courseid] = can_access_course($this->get_course($courseid)) ? 1 : 0; $this->cachechangedcourse = true; } return $this->courseaccess[$courseid]; }
[ "public", "function", "can_access_course", "(", "$", "courseid", ")", "{", "$", "this", "->", "init_course_access", "(", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "courseid", ",", "$", "this", "->", "courseaccess", ")", ")", "{", "$", "this", "->", "courseaccess", "[", "$", "courseid", "]", "=", "can_access_course", "(", "$", "this", "->", "get_course", "(", "$", "courseid", ")", ")", "?", "1", ":", "0", ";", "$", "this", "->", "cachechangedcourse", "=", "true", ";", "}", "return", "$", "this", "->", "courseaccess", "[", "$", "courseid", "]", ";", "}" ]
Checks if current user has access to the course This method calls global function {@link can_access_course} and caches results @param int $courseid @return bool
[ "Checks", "if", "current", "user", "has", "access", "to", "the", "course" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/index_builder.php#L343-L350
216,120
moodle/moodle
search/engine/simpledb/classes/engine.php
engine.get_simple_query
protected function get_simple_query($q) { global $DB; $sql = '(' . $DB->sql_like('title', '?', false, false) . ' OR ' . $DB->sql_like('content', '?', false, false) . ' OR ' . $DB->sql_like('description1', '?', false, false) . ' OR ' . $DB->sql_like('description2', '?', false, false) . ')'; $params = array( '%' . $q . '%', '%' . $q . '%', '%' . $q . '%', '%' . $q . '%' ); return array($sql, $params); }
php
protected function get_simple_query($q) { global $DB; $sql = '(' . $DB->sql_like('title', '?', false, false) . ' OR ' . $DB->sql_like('content', '?', false, false) . ' OR ' . $DB->sql_like('description1', '?', false, false) . ' OR ' . $DB->sql_like('description2', '?', false, false) . ')'; $params = array( '%' . $q . '%', '%' . $q . '%', '%' . $q . '%', '%' . $q . '%' ); return array($sql, $params); }
[ "protected", "function", "get_simple_query", "(", "$", "q", ")", "{", "global", "$", "DB", ";", "$", "sql", "=", "'('", ".", "$", "DB", "->", "sql_like", "(", "'title'", ",", "'?'", ",", "false", ",", "false", ")", ".", "' OR '", ".", "$", "DB", "->", "sql_like", "(", "'content'", ",", "'?'", ",", "false", ",", "false", ")", ".", "' OR '", ".", "$", "DB", "->", "sql_like", "(", "'description1'", ",", "'?'", ",", "false", ",", "false", ")", ".", "' OR '", ".", "$", "DB", "->", "sql_like", "(", "'description2'", ",", "'?'", ",", "false", ",", "false", ")", ".", "')'", ";", "$", "params", "=", "array", "(", "'%'", ".", "$", "q", ".", "'%'", ",", "'%'", ".", "$", "q", ".", "'%'", ",", "'%'", ".", "$", "q", ".", "'%'", ",", "'%'", ".", "$", "q", ".", "'%'", ")", ";", "return", "array", "(", "$", "sql", ",", "$", "params", ")", ";", "}" ]
Returns the default query for db engines. @param string $q The query string @return array SQL string and params list
[ "Returns", "the", "default", "query", "for", "db", "engines", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/engine/simpledb/classes/engine.php#L340-L356
216,121
moodle/moodle
mod/assign/backup/moodle2/backup_assign_stepslib.php
backup_assign_activity_structure_step.annotate_plugin_config_files
protected function annotate_plugin_config_files(backup_nested_element $assign, $subtype) { $dummyassign = new assign(null, null, null); $plugins = $dummyassign->load_plugins($subtype); foreach ($plugins as $plugin) { $component = $plugin->get_subtype() . '_' . $plugin->get_type(); $areas = $plugin->get_config_file_areas(); foreach ($areas as $area) { $assign->annotate_files($component, $area, null); } } }
php
protected function annotate_plugin_config_files(backup_nested_element $assign, $subtype) { $dummyassign = new assign(null, null, null); $plugins = $dummyassign->load_plugins($subtype); foreach ($plugins as $plugin) { $component = $plugin->get_subtype() . '_' . $plugin->get_type(); $areas = $plugin->get_config_file_areas(); foreach ($areas as $area) { $assign->annotate_files($component, $area, null); } } }
[ "protected", "function", "annotate_plugin_config_files", "(", "backup_nested_element", "$", "assign", ",", "$", "subtype", ")", "{", "$", "dummyassign", "=", "new", "assign", "(", "null", ",", "null", ",", "null", ")", ";", "$", "plugins", "=", "$", "dummyassign", "->", "load_plugins", "(", "$", "subtype", ")", ";", "foreach", "(", "$", "plugins", "as", "$", "plugin", ")", "{", "$", "component", "=", "$", "plugin", "->", "get_subtype", "(", ")", ".", "'_'", ".", "$", "plugin", "->", "get_type", "(", ")", ";", "$", "areas", "=", "$", "plugin", "->", "get_config_file_areas", "(", ")", ";", "foreach", "(", "$", "areas", "as", "$", "area", ")", "{", "$", "assign", "->", "annotate_files", "(", "$", "component", ",", "$", "area", ",", "null", ")", ";", "}", "}", "}" ]
Annotate files from plugin configuration @param backup_nested_element $assign the backup structure of the activity @param string $subtype the plugin type to handle @return void
[ "Annotate", "files", "from", "plugin", "configuration" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/backup/moodle2/backup_assign_stepslib.php#L44-L54
216,122
moodle/moodle
lib/horde/framework/Horde/Support/Guid.php
Horde_Support_Guid.generate
public function generate(array $opts = array()) { $this->_guid = date('YmdHis') . '.' . (isset($opts['prefix']) ? $opts['prefix'] . '.' : '') . strval(new Horde_Support_Randomid()) . '@' . (isset($opts['server']) ? $opts['server'] : (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost')); }
php
public function generate(array $opts = array()) { $this->_guid = date('YmdHis') . '.' . (isset($opts['prefix']) ? $opts['prefix'] . '.' : '') . strval(new Horde_Support_Randomid()) . '@' . (isset($opts['server']) ? $opts['server'] : (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost')); }
[ "public", "function", "generate", "(", "array", "$", "opts", "=", "array", "(", ")", ")", "{", "$", "this", "->", "_guid", "=", "date", "(", "'YmdHis'", ")", ".", "'.'", ".", "(", "isset", "(", "$", "opts", "[", "'prefix'", "]", ")", "?", "$", "opts", "[", "'prefix'", "]", ".", "'.'", ":", "''", ")", ".", "strval", "(", "new", "Horde_Support_Randomid", "(", ")", ")", ".", "'@'", ".", "(", "isset", "(", "$", "opts", "[", "'server'", "]", ")", "?", "$", "opts", "[", "'server'", "]", ":", "(", "isset", "(", "$", "_SERVER", "[", "'SERVER_NAME'", "]", ")", "?", "$", "_SERVER", "[", "'SERVER_NAME'", "]", ":", "'localhost'", ")", ")", ";", "}" ]
Generates a GUID. @param array $opts Additional options: <pre> 'prefix' - (string) A prefix to add between the date string and the random string. DEFAULT: NONE 'server' - (string) The server name. DEFAULT: $_SERVER['SERVER_NAME'] (or 'localhost') </pre>
[ "Generates", "a", "GUID", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Support/Guid.php#L53-L61
216,123
moodle/moodle
lib/typo3/class.t3lib_l10n_locales.php
t3lib_l10n_Locales.initialize
public static function initialize() { /** @var $instance t3lib_l10n_Locales */ $instance = t3lib_div::makeInstance('t3lib_l10n_Locales'); $instance->isoMapping = array_flip($instance->isoReverseMapping); // Allow user-defined locales if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['user']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['user'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['user'] as $locale => $name) { if (!isset($instance->languages[$locale])) { $instance->languages[$locale] = $name; } } } // Initializes the locale dependencies with TYPO3 supported locales $instance->localeDependencies = array(); foreach ($instance->languages as $locale => $name) { if (strlen($locale) == 5) { $instance->localeDependencies[$locale] = array(substr($locale, 0, 2)); } } // Merge user-provided locale dependencies if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['dependencies']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['dependencies'])) { $instance->localeDependencies = t3lib_div::array_merge_recursive_overrule($instance->localeDependencies, $GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['dependencies']); } /** * @deprecated since TYPO3 4.6, will be removed in TYPO3 6.0 */ $instance->locales = array_keys($instance->languages); /** * @deprecated since TYPO3 4.6, will be removed in TYPO3 6.0 */ define('TYPO3_languages', implode('|', $instance->getLocales())); }
php
public static function initialize() { /** @var $instance t3lib_l10n_Locales */ $instance = t3lib_div::makeInstance('t3lib_l10n_Locales'); $instance->isoMapping = array_flip($instance->isoReverseMapping); // Allow user-defined locales if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['user']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['user'])) { foreach ($GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['user'] as $locale => $name) { if (!isset($instance->languages[$locale])) { $instance->languages[$locale] = $name; } } } // Initializes the locale dependencies with TYPO3 supported locales $instance->localeDependencies = array(); foreach ($instance->languages as $locale => $name) { if (strlen($locale) == 5) { $instance->localeDependencies[$locale] = array(substr($locale, 0, 2)); } } // Merge user-provided locale dependencies if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['dependencies']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['dependencies'])) { $instance->localeDependencies = t3lib_div::array_merge_recursive_overrule($instance->localeDependencies, $GLOBALS['TYPO3_CONF_VARS']['SYS']['localization']['locales']['dependencies']); } /** * @deprecated since TYPO3 4.6, will be removed in TYPO3 6.0 */ $instance->locales = array_keys($instance->languages); /** * @deprecated since TYPO3 4.6, will be removed in TYPO3 6.0 */ define('TYPO3_languages', implode('|', $instance->getLocales())); }
[ "public", "static", "function", "initialize", "(", ")", "{", "/** @var $instance t3lib_l10n_Locales */", "$", "instance", "=", "t3lib_div", "::", "makeInstance", "(", "'t3lib_l10n_Locales'", ")", ";", "$", "instance", "->", "isoMapping", "=", "array_flip", "(", "$", "instance", "->", "isoReverseMapping", ")", ";", "// Allow user-defined locales", "if", "(", "isset", "(", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SYS'", "]", "[", "'localization'", "]", "[", "'locales'", "]", "[", "'user'", "]", ")", "&&", "is_array", "(", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SYS'", "]", "[", "'localization'", "]", "[", "'locales'", "]", "[", "'user'", "]", ")", ")", "{", "foreach", "(", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SYS'", "]", "[", "'localization'", "]", "[", "'locales'", "]", "[", "'user'", "]", "as", "$", "locale", "=>", "$", "name", ")", "{", "if", "(", "!", "isset", "(", "$", "instance", "->", "languages", "[", "$", "locale", "]", ")", ")", "{", "$", "instance", "->", "languages", "[", "$", "locale", "]", "=", "$", "name", ";", "}", "}", "}", "// Initializes the locale dependencies with TYPO3 supported locales", "$", "instance", "->", "localeDependencies", "=", "array", "(", ")", ";", "foreach", "(", "$", "instance", "->", "languages", "as", "$", "locale", "=>", "$", "name", ")", "{", "if", "(", "strlen", "(", "$", "locale", ")", "==", "5", ")", "{", "$", "instance", "->", "localeDependencies", "[", "$", "locale", "]", "=", "array", "(", "substr", "(", "$", "locale", ",", "0", ",", "2", ")", ")", ";", "}", "}", "// Merge user-provided locale dependencies", "if", "(", "isset", "(", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SYS'", "]", "[", "'localization'", "]", "[", "'locales'", "]", "[", "'dependencies'", "]", ")", "&&", "is_array", "(", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SYS'", "]", "[", "'localization'", "]", "[", "'locales'", "]", "[", "'dependencies'", "]", ")", ")", "{", "$", "instance", "->", "localeDependencies", "=", "t3lib_div", "::", "array_merge_recursive_overrule", "(", "$", "instance", "->", "localeDependencies", ",", "$", "GLOBALS", "[", "'TYPO3_CONF_VARS'", "]", "[", "'SYS'", "]", "[", "'localization'", "]", "[", "'locales'", "]", "[", "'dependencies'", "]", ")", ";", "}", "/**\n\t\t * @deprecated since TYPO3 4.6, will be removed in TYPO3 6.0\n\t\t */", "$", "instance", "->", "locales", "=", "array_keys", "(", "$", "instance", "->", "languages", ")", ";", "/**\n\t\t * @deprecated since TYPO3 4.6, will be removed in TYPO3 6.0\n\t\t */", "define", "(", "'TYPO3_languages'", ",", "implode", "(", "'|'", ",", "$", "instance", "->", "getLocales", "(", ")", ")", ")", ";", "}" ]
Initializes the languages. @static @return void
[ "Initializes", "the", "languages", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_l10n_locales.php#L153-L188
216,124
moodle/moodle
lib/typo3/class.t3lib_l10n_locales.php
t3lib_l10n_Locales.getLocaleDependencies
public function getLocaleDependencies($locale) { $dependencies = array(); if (isset($this->localeDependencies[$locale])) { $dependencies = $this->localeDependencies[$locale]; // Search for dependencies recursively $localeDependencies = $dependencies; foreach ($localeDependencies as $dependency) { if (isset($this->localeDependencies[$dependency])) { $dependencies = array_merge($dependencies, $this->getLocaleDependencies($dependency)); } } } return $dependencies; }
php
public function getLocaleDependencies($locale) { $dependencies = array(); if (isset($this->localeDependencies[$locale])) { $dependencies = $this->localeDependencies[$locale]; // Search for dependencies recursively $localeDependencies = $dependencies; foreach ($localeDependencies as $dependency) { if (isset($this->localeDependencies[$dependency])) { $dependencies = array_merge($dependencies, $this->getLocaleDependencies($dependency)); } } } return $dependencies; }
[ "public", "function", "getLocaleDependencies", "(", "$", "locale", ")", "{", "$", "dependencies", "=", "array", "(", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "localeDependencies", "[", "$", "locale", "]", ")", ")", "{", "$", "dependencies", "=", "$", "this", "->", "localeDependencies", "[", "$", "locale", "]", ";", "// Search for dependencies recursively", "$", "localeDependencies", "=", "$", "dependencies", ";", "foreach", "(", "$", "localeDependencies", "as", "$", "dependency", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "localeDependencies", "[", "$", "dependency", "]", ")", ")", "{", "$", "dependencies", "=", "array_merge", "(", "$", "dependencies", ",", "$", "this", "->", "getLocaleDependencies", "(", "$", "dependency", ")", ")", ";", "}", "}", "}", "return", "$", "dependencies", ";", "}" ]
Returns the dependencies of a given locale, if any. @param string $locale @return array
[ "Returns", "the", "dependencies", "of", "a", "given", "locale", "if", "any", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_l10n_locales.php#L233-L247
216,125
moodle/moodle
lib/typo3/class.t3lib_l10n_locales.php
t3lib_l10n_Locales.getTerLocaleDependencies
public function getTerLocaleDependencies($locale) { $terLocale = isset($this->isoMapping[$locale]) ? $this->isoMapping[$locale] : $locale; return $this->convertToTerLocales($this->getLocaleDependencies($terLocale)); }
php
public function getTerLocaleDependencies($locale) { $terLocale = isset($this->isoMapping[$locale]) ? $this->isoMapping[$locale] : $locale; return $this->convertToTerLocales($this->getLocaleDependencies($terLocale)); }
[ "public", "function", "getTerLocaleDependencies", "(", "$", "locale", ")", "{", "$", "terLocale", "=", "isset", "(", "$", "this", "->", "isoMapping", "[", "$", "locale", "]", ")", "?", "$", "this", "->", "isoMapping", "[", "$", "locale", "]", ":", "$", "locale", ";", "return", "$", "this", "->", "convertToTerLocales", "(", "$", "this", "->", "getLocaleDependencies", "(", "$", "terLocale", ")", ")", ";", "}" ]
Returns the dependencies of a given locale using TER compatible locale codes. @param string $locale @return array @deprecated since TYPO3 4.6
[ "Returns", "the", "dependencies", "of", "a", "given", "locale", "using", "TER", "compatible", "locale", "codes", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_l10n_locales.php#L256-L261
216,126
moodle/moodle
lib/typo3/class.t3lib_l10n_locales.php
t3lib_l10n_Locales.convertToTerLocales
protected function convertToTerLocales(array $locales) { $terLocales = array(); foreach ($locales as $locale) { $terLocales[] = isset($this->isoReverseMapping[$locale]) ? $this->isoReverseMapping[$locale] : $locale; } return $terLocales; }
php
protected function convertToTerLocales(array $locales) { $terLocales = array(); foreach ($locales as $locale) { $terLocales[] = isset($this->isoReverseMapping[$locale]) ? $this->isoReverseMapping[$locale] : $locale; } return $terLocales; }
[ "protected", "function", "convertToTerLocales", "(", "array", "$", "locales", ")", "{", "$", "terLocales", "=", "array", "(", ")", ";", "foreach", "(", "$", "locales", "as", "$", "locale", ")", "{", "$", "terLocales", "[", "]", "=", "isset", "(", "$", "this", "->", "isoReverseMapping", "[", "$", "locale", "]", ")", "?", "$", "this", "->", "isoReverseMapping", "[", "$", "locale", "]", ":", "$", "locale", ";", "}", "return", "$", "terLocales", ";", "}" ]
Converts an array of ISO locale codes into their TER equivalent. @param array $locales @return array @deprecated since TYPO3 4.6
[ "Converts", "an", "array", "of", "ISO", "locale", "codes", "into", "their", "TER", "equivalent", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/typo3/class.t3lib_l10n_locales.php#L270-L276
216,127
moodle/moodle
mod/workshop/form/numerrors/backup/moodle2/restore_workshopform_numerrors_subplugin.class.php
restore_workshopform_numerrors_subplugin.process_workshopform_numerrors_map
public function process_workshopform_numerrors_map($data) { global $DB; $data = (object)$data; $data->workshopid = $this->get_new_parentid('workshop'); $DB->insert_record('workshopform_numerrors_map', $data); }
php
public function process_workshopform_numerrors_map($data) { global $DB; $data = (object)$data; $data->workshopid = $this->get_new_parentid('workshop'); $DB->insert_record('workshopform_numerrors_map', $data); }
[ "public", "function", "process_workshopform_numerrors_map", "(", "$", "data", ")", "{", "global", "$", "DB", ";", "$", "data", "=", "(", "object", ")", "$", "data", ";", "$", "data", "->", "workshopid", "=", "$", "this", "->", "get_new_parentid", "(", "'workshop'", ")", ";", "$", "DB", "->", "insert_record", "(", "'workshopform_numerrors_map'", ",", "$", "data", ")", ";", "}" ]
Processes the workshopform_numerrors_map element
[ "Processes", "the", "workshopform_numerrors_map", "element" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/form/numerrors/backup/moodle2/restore_workshopform_numerrors_subplugin.class.php#L103-L109
216,128
moodle/moodle
mod/workshop/form/numerrors/backup/moodle2/restore_workshopform_numerrors_subplugin.class.php
restore_workshopform_numerrors_subplugin.process_dimension_grades_structure
private function process_dimension_grades_structure($elementname, $data) { global $DB; $data = (object)$data; $oldid = $data->id; $data->assessmentid = $this->get_new_parentid($elementname); $data->strategy = 'numerrors'; $data->dimensionid = $this->get_mappingid($this->get_namefor('dimension'), $data->dimensionid); $DB->insert_record('workshop_grades', $data); }
php
private function process_dimension_grades_structure($elementname, $data) { global $DB; $data = (object)$data; $oldid = $data->id; $data->assessmentid = $this->get_new_parentid($elementname); $data->strategy = 'numerrors'; $data->dimensionid = $this->get_mappingid($this->get_namefor('dimension'), $data->dimensionid); $DB->insert_record('workshop_grades', $data); }
[ "private", "function", "process_dimension_grades_structure", "(", "$", "elementname", ",", "$", "data", ")", "{", "global", "$", "DB", ";", "$", "data", "=", "(", "object", ")", "$", "data", ";", "$", "oldid", "=", "$", "data", "->", "id", ";", "$", "data", "->", "assessmentid", "=", "$", "this", "->", "get_new_parentid", "(", "$", "elementname", ")", ";", "$", "data", "->", "strategy", "=", "'numerrors'", ";", "$", "data", "->", "dimensionid", "=", "$", "this", "->", "get_mappingid", "(", "$", "this", "->", "get_namefor", "(", "'dimension'", ")", ",", "$", "data", "->", "dimensionid", ")", ";", "$", "DB", "->", "insert_record", "(", "'workshop_grades'", ",", "$", "data", ")", ";", "}" ]
Process the dimension grades linked with the given type of assessment Populates the workshop_grades table with new records mapped to the restored instances of assessments. @param mixed $elementname the name of the assessment element @param array $data parsed xml data
[ "Process", "the", "dimension", "grades", "linked", "with", "the", "given", "type", "of", "assessment" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/form/numerrors/backup/moodle2/restore_workshopform_numerrors_subplugin.class.php#L163-L174
216,129
moodle/moodle
lib/tcpdf/include/tcpdf_filters.php
TCPDF_FILTERS.decodeFilter
public static function decodeFilter($filter, $data) { switch ($filter) { case 'ASCIIHexDecode': { return self::decodeFilterASCIIHexDecode($data); break; } case 'ASCII85Decode': { return self::decodeFilterASCII85Decode($data); break; } case 'LZWDecode': { return self::decodeFilterLZWDecode($data); break; } case 'FlateDecode': { return self::decodeFilterFlateDecode($data); break; } case 'RunLengthDecode': { return self::decodeFilterRunLengthDecode($data); break; } case 'CCITTFaxDecode': { return self::decodeFilterCCITTFaxDecode($data); break; } case 'JBIG2Decode': { return self::decodeFilterJBIG2Decode($data); break; } case 'DCTDecode': { return self::decodeFilterDCTDecode($data); break; } case 'JPXDecode': { return self::decodeFilterJPXDecode($data); break; } case 'Crypt': { return self::decodeFilterCrypt($data); break; } default: { return self::decodeFilterStandard($data); break; } } }
php
public static function decodeFilter($filter, $data) { switch ($filter) { case 'ASCIIHexDecode': { return self::decodeFilterASCIIHexDecode($data); break; } case 'ASCII85Decode': { return self::decodeFilterASCII85Decode($data); break; } case 'LZWDecode': { return self::decodeFilterLZWDecode($data); break; } case 'FlateDecode': { return self::decodeFilterFlateDecode($data); break; } case 'RunLengthDecode': { return self::decodeFilterRunLengthDecode($data); break; } case 'CCITTFaxDecode': { return self::decodeFilterCCITTFaxDecode($data); break; } case 'JBIG2Decode': { return self::decodeFilterJBIG2Decode($data); break; } case 'DCTDecode': { return self::decodeFilterDCTDecode($data); break; } case 'JPXDecode': { return self::decodeFilterJPXDecode($data); break; } case 'Crypt': { return self::decodeFilterCrypt($data); break; } default: { return self::decodeFilterStandard($data); break; } } }
[ "public", "static", "function", "decodeFilter", "(", "$", "filter", ",", "$", "data", ")", "{", "switch", "(", "$", "filter", ")", "{", "case", "'ASCIIHexDecode'", ":", "{", "return", "self", "::", "decodeFilterASCIIHexDecode", "(", "$", "data", ")", ";", "break", ";", "}", "case", "'ASCII85Decode'", ":", "{", "return", "self", "::", "decodeFilterASCII85Decode", "(", "$", "data", ")", ";", "break", ";", "}", "case", "'LZWDecode'", ":", "{", "return", "self", "::", "decodeFilterLZWDecode", "(", "$", "data", ")", ";", "break", ";", "}", "case", "'FlateDecode'", ":", "{", "return", "self", "::", "decodeFilterFlateDecode", "(", "$", "data", ")", ";", "break", ";", "}", "case", "'RunLengthDecode'", ":", "{", "return", "self", "::", "decodeFilterRunLengthDecode", "(", "$", "data", ")", ";", "break", ";", "}", "case", "'CCITTFaxDecode'", ":", "{", "return", "self", "::", "decodeFilterCCITTFaxDecode", "(", "$", "data", ")", ";", "break", ";", "}", "case", "'JBIG2Decode'", ":", "{", "return", "self", "::", "decodeFilterJBIG2Decode", "(", "$", "data", ")", ";", "break", ";", "}", "case", "'DCTDecode'", ":", "{", "return", "self", "::", "decodeFilterDCTDecode", "(", "$", "data", ")", ";", "break", ";", "}", "case", "'JPXDecode'", ":", "{", "return", "self", "::", "decodeFilterJPXDecode", "(", "$", "data", ")", ";", "break", ";", "}", "case", "'Crypt'", ":", "{", "return", "self", "::", "decodeFilterCrypt", "(", "$", "data", ")", ";", "break", ";", "}", "default", ":", "{", "return", "self", "::", "decodeFilterStandard", "(", "$", "data", ")", ";", "break", ";", "}", "}", "}" ]
Decode data using the specified filter type. @param $filter (string) Filter name. @param $data (string) Data to decode. @return Decoded data string. @since 1.0.000 (2011-05-23) @public static
[ "Decode", "data", "using", "the", "specified", "filter", "type", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/tcpdf/include/tcpdf_filters.php#L79-L126
216,130
moodle/moodle
lib/tcpdf/include/tcpdf_filters.php
TCPDF_FILTERS.decodeFilterASCII85Decode
public static function decodeFilterASCII85Decode($data) { // initialize string to return $decoded = ''; // all white-space characters shall be ignored $data = preg_replace('/[\s]/', '', $data); // remove start sequence 2-character sequence <~ (3Ch)(7Eh) if (strpos($data, '<~') !== false) { // remove EOD and extra data (if any) $data = substr($data, 2); } // check for EOD: 2-character sequence ~> (7Eh)(3Eh) $eod = strpos($data, '~>'); if ($eod !== false) { // remove EOD and extra data (if any) $data = substr($data, 0, $eod); } // data length $data_length = strlen($data); // check for invalid characters if (preg_match('/[^\x21-\x75,\x74]/', $data) > 0) { self::Error('decodeFilterASCII85Decode: invalid code'); } // z sequence $zseq = chr(0).chr(0).chr(0).chr(0); // position inside a group of 4 bytes (0-3) $group_pos = 0; $tuple = 0; $pow85 = array((85*85*85*85), (85*85*85), (85*85), 85, 1); $last_pos = ($data_length - 1); // for each byte for ($i = 0; $i < $data_length; ++$i) { // get char value $char = ord($data[$i]); if ($char == 122) { // 'z' if ($group_pos == 0) { $decoded .= $zseq; } else { self::Error('decodeFilterASCII85Decode: invalid code'); } } else { // the value represented by a group of 5 characters should never be greater than 2^32 - 1 $tuple += (($char - 33) * $pow85[$group_pos]); if ($group_pos == 4) { $decoded .= chr($tuple >> 24).chr($tuple >> 16).chr($tuple >> 8).chr($tuple); $tuple = 0; $group_pos = 0; } else { ++$group_pos; } } } if ($group_pos > 1) { $tuple += $pow85[($group_pos - 1)]; } // last tuple (if any) switch ($group_pos) { case 4: { $decoded .= chr($tuple >> 24).chr($tuple >> 16).chr($tuple >> 8); break; } case 3: { $decoded .= chr($tuple >> 24).chr($tuple >> 16); break; } case 2: { $decoded .= chr($tuple >> 24); break; } case 1: { self::Error('decodeFilterASCII85Decode: invalid code'); break; } } return $decoded; }
php
public static function decodeFilterASCII85Decode($data) { // initialize string to return $decoded = ''; // all white-space characters shall be ignored $data = preg_replace('/[\s]/', '', $data); // remove start sequence 2-character sequence <~ (3Ch)(7Eh) if (strpos($data, '<~') !== false) { // remove EOD and extra data (if any) $data = substr($data, 2); } // check for EOD: 2-character sequence ~> (7Eh)(3Eh) $eod = strpos($data, '~>'); if ($eod !== false) { // remove EOD and extra data (if any) $data = substr($data, 0, $eod); } // data length $data_length = strlen($data); // check for invalid characters if (preg_match('/[^\x21-\x75,\x74]/', $data) > 0) { self::Error('decodeFilterASCII85Decode: invalid code'); } // z sequence $zseq = chr(0).chr(0).chr(0).chr(0); // position inside a group of 4 bytes (0-3) $group_pos = 0; $tuple = 0; $pow85 = array((85*85*85*85), (85*85*85), (85*85), 85, 1); $last_pos = ($data_length - 1); // for each byte for ($i = 0; $i < $data_length; ++$i) { // get char value $char = ord($data[$i]); if ($char == 122) { // 'z' if ($group_pos == 0) { $decoded .= $zseq; } else { self::Error('decodeFilterASCII85Decode: invalid code'); } } else { // the value represented by a group of 5 characters should never be greater than 2^32 - 1 $tuple += (($char - 33) * $pow85[$group_pos]); if ($group_pos == 4) { $decoded .= chr($tuple >> 24).chr($tuple >> 16).chr($tuple >> 8).chr($tuple); $tuple = 0; $group_pos = 0; } else { ++$group_pos; } } } if ($group_pos > 1) { $tuple += $pow85[($group_pos - 1)]; } // last tuple (if any) switch ($group_pos) { case 4: { $decoded .= chr($tuple >> 24).chr($tuple >> 16).chr($tuple >> 8); break; } case 3: { $decoded .= chr($tuple >> 24).chr($tuple >> 16); break; } case 2: { $decoded .= chr($tuple >> 24); break; } case 1: { self::Error('decodeFilterASCII85Decode: invalid code'); break; } } return $decoded; }
[ "public", "static", "function", "decodeFilterASCII85Decode", "(", "$", "data", ")", "{", "// initialize string to return", "$", "decoded", "=", "''", ";", "// all white-space characters shall be ignored", "$", "data", "=", "preg_replace", "(", "'/[\\s]/'", ",", "''", ",", "$", "data", ")", ";", "// remove start sequence 2-character sequence <~ (3Ch)(7Eh)", "if", "(", "strpos", "(", "$", "data", ",", "'<~'", ")", "!==", "false", ")", "{", "// remove EOD and extra data (if any)", "$", "data", "=", "substr", "(", "$", "data", ",", "2", ")", ";", "}", "// check for EOD: 2-character sequence ~> (7Eh)(3Eh)", "$", "eod", "=", "strpos", "(", "$", "data", ",", "'~>'", ")", ";", "if", "(", "$", "eod", "!==", "false", ")", "{", "// remove EOD and extra data (if any)", "$", "data", "=", "substr", "(", "$", "data", ",", "0", ",", "$", "eod", ")", ";", "}", "// data length", "$", "data_length", "=", "strlen", "(", "$", "data", ")", ";", "// check for invalid characters", "if", "(", "preg_match", "(", "'/[^\\x21-\\x75,\\x74]/'", ",", "$", "data", ")", ">", "0", ")", "{", "self", "::", "Error", "(", "'decodeFilterASCII85Decode: invalid code'", ")", ";", "}", "// z sequence", "$", "zseq", "=", "chr", "(", "0", ")", ".", "chr", "(", "0", ")", ".", "chr", "(", "0", ")", ".", "chr", "(", "0", ")", ";", "// position inside a group of 4 bytes (0-3)", "$", "group_pos", "=", "0", ";", "$", "tuple", "=", "0", ";", "$", "pow85", "=", "array", "(", "(", "85", "*", "85", "*", "85", "*", "85", ")", ",", "(", "85", "*", "85", "*", "85", ")", ",", "(", "85", "*", "85", ")", ",", "85", ",", "1", ")", ";", "$", "last_pos", "=", "(", "$", "data_length", "-", "1", ")", ";", "// for each byte", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "data_length", ";", "++", "$", "i", ")", "{", "// get char value", "$", "char", "=", "ord", "(", "$", "data", "[", "$", "i", "]", ")", ";", "if", "(", "$", "char", "==", "122", ")", "{", "// 'z'", "if", "(", "$", "group_pos", "==", "0", ")", "{", "$", "decoded", ".=", "$", "zseq", ";", "}", "else", "{", "self", "::", "Error", "(", "'decodeFilterASCII85Decode: invalid code'", ")", ";", "}", "}", "else", "{", "// the value represented by a group of 5 characters should never be greater than 2^32 - 1", "$", "tuple", "+=", "(", "(", "$", "char", "-", "33", ")", "*", "$", "pow85", "[", "$", "group_pos", "]", ")", ";", "if", "(", "$", "group_pos", "==", "4", ")", "{", "$", "decoded", ".=", "chr", "(", "$", "tuple", ">>", "24", ")", ".", "chr", "(", "$", "tuple", ">>", "16", ")", ".", "chr", "(", "$", "tuple", ">>", "8", ")", ".", "chr", "(", "$", "tuple", ")", ";", "$", "tuple", "=", "0", ";", "$", "group_pos", "=", "0", ";", "}", "else", "{", "++", "$", "group_pos", ";", "}", "}", "}", "if", "(", "$", "group_pos", ">", "1", ")", "{", "$", "tuple", "+=", "$", "pow85", "[", "(", "$", "group_pos", "-", "1", ")", "]", ";", "}", "// last tuple (if any)", "switch", "(", "$", "group_pos", ")", "{", "case", "4", ":", "{", "$", "decoded", ".=", "chr", "(", "$", "tuple", ">>", "24", ")", ".", "chr", "(", "$", "tuple", ">>", "16", ")", ".", "chr", "(", "$", "tuple", ">>", "8", ")", ";", "break", ";", "}", "case", "3", ":", "{", "$", "decoded", ".=", "chr", "(", "$", "tuple", ">>", "24", ")", ".", "chr", "(", "$", "tuple", ">>", "16", ")", ";", "break", ";", "}", "case", "2", ":", "{", "$", "decoded", ".=", "chr", "(", "$", "tuple", ">>", "24", ")", ";", "break", ";", "}", "case", "1", ":", "{", "self", "::", "Error", "(", "'decodeFilterASCII85Decode: invalid code'", ")", ";", "break", ";", "}", "}", "return", "$", "decoded", ";", "}" ]
ASCII85Decode Decodes data encoded in an ASCII base-85 representation, reproducing the original binary data. @param $data (string) Data to decode. @return Decoded data string. @since 1.0.000 (2011-05-23) @public static
[ "ASCII85Decode", "Decodes", "data", "encoded", "in", "an", "ASCII", "base", "-", "85", "representation", "reproducing", "the", "original", "binary", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/tcpdf/include/tcpdf_filters.php#L190-L264
216,131
moodle/moodle
course/classes/task/course_delete_modules.php
course_delete_modules.execute
public function execute() { global $CFG; require_once($CFG->dirroot. '/course/lib.php'); // Set the proper user. if ($this->get_custom_data()->userid !== $this->get_custom_data()->realuserid) { $realuser = \core_user::get_user($this->get_custom_data()->realuserid, '*', MUST_EXIST); cron_setup_user($realuser); \core\session\manager::loginas($this->get_custom_data()->userid, \context_system::instance(), false); } else { $user = \core_user::get_user($this->get_custom_data()->userid, '*', MUST_EXIST); cron_setup_user($user); } $cms = $this->get_custom_data()->cms; foreach ($cms as $cm) { try { course_delete_module($cm->id); } catch (\Exception $e) { throw new \coding_exception("The course module {$cm->id} could not be deleted. {$e->getTraceAsString()}"); } } }
php
public function execute() { global $CFG; require_once($CFG->dirroot. '/course/lib.php'); // Set the proper user. if ($this->get_custom_data()->userid !== $this->get_custom_data()->realuserid) { $realuser = \core_user::get_user($this->get_custom_data()->realuserid, '*', MUST_EXIST); cron_setup_user($realuser); \core\session\manager::loginas($this->get_custom_data()->userid, \context_system::instance(), false); } else { $user = \core_user::get_user($this->get_custom_data()->userid, '*', MUST_EXIST); cron_setup_user($user); } $cms = $this->get_custom_data()->cms; foreach ($cms as $cm) { try { course_delete_module($cm->id); } catch (\Exception $e) { throw new \coding_exception("The course module {$cm->id} could not be deleted. {$e->getTraceAsString()}"); } } }
[ "public", "function", "execute", "(", ")", "{", "global", "$", "CFG", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/course/lib.php'", ")", ";", "// Set the proper user.", "if", "(", "$", "this", "->", "get_custom_data", "(", ")", "->", "userid", "!==", "$", "this", "->", "get_custom_data", "(", ")", "->", "realuserid", ")", "{", "$", "realuser", "=", "\\", "core_user", "::", "get_user", "(", "$", "this", "->", "get_custom_data", "(", ")", "->", "realuserid", ",", "'*'", ",", "MUST_EXIST", ")", ";", "cron_setup_user", "(", "$", "realuser", ")", ";", "\\", "core", "\\", "session", "\\", "manager", "::", "loginas", "(", "$", "this", "->", "get_custom_data", "(", ")", "->", "userid", ",", "\\", "context_system", "::", "instance", "(", ")", ",", "false", ")", ";", "}", "else", "{", "$", "user", "=", "\\", "core_user", "::", "get_user", "(", "$", "this", "->", "get_custom_data", "(", ")", "->", "userid", ",", "'*'", ",", "MUST_EXIST", ")", ";", "cron_setup_user", "(", "$", "user", ")", ";", "}", "$", "cms", "=", "$", "this", "->", "get_custom_data", "(", ")", "->", "cms", ";", "foreach", "(", "$", "cms", "as", "$", "cm", ")", "{", "try", "{", "course_delete_module", "(", "$", "cm", "->", "id", ")", ";", "}", "catch", "(", "\\", "Exception", "$", "e", ")", "{", "throw", "new", "\\", "coding_exception", "(", "\"The course module {$cm->id} could not be deleted. {$e->getTraceAsString()}\"", ")", ";", "}", "}", "}" ]
Run the deletion task. @throws \coding_exception if the module could not be removed.
[ "Run", "the", "deletion", "task", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/task/course_delete_modules.php#L49-L71
216,132
moodle/moodle
lib/listlib.php
moodle_list.to_html
public function to_html($indent=0, $extraargs=array()) { if (count($this->items)) { $tabs = str_repeat("\t", $indent); $first = true; $itemiter = 1; $lastitem = ''; $html = ''; foreach ($this->items as $item) { $last = (count($this->items) == $itemiter); if ($this->editable) { $item->set_icon_html($first, $last, $lastitem); } if ($itemhtml = $item->to_html($indent+1, $extraargs)) { $html .= "$tabs\t<li".((!empty($item->attributes))?(' '.$item->attributes):'').">"; $html .= $itemhtml; $html .= "</li>\n"; } $first = false; $lastitem = $item; $itemiter++; } } else { $html = ''; } if ($html) { //if there are list items to display then wrap them in ul / ol tag. $tabs = str_repeat("\t", $indent); $html = $tabs.'<'.$this->type.((!empty($this->attributes))?(' '.$this->attributes):'').">\n".$html; $html .= $tabs."</".$this->type.">\n"; } else { $html =''; } return $html; }
php
public function to_html($indent=0, $extraargs=array()) { if (count($this->items)) { $tabs = str_repeat("\t", $indent); $first = true; $itemiter = 1; $lastitem = ''; $html = ''; foreach ($this->items as $item) { $last = (count($this->items) == $itemiter); if ($this->editable) { $item->set_icon_html($first, $last, $lastitem); } if ($itemhtml = $item->to_html($indent+1, $extraargs)) { $html .= "$tabs\t<li".((!empty($item->attributes))?(' '.$item->attributes):'').">"; $html .= $itemhtml; $html .= "</li>\n"; } $first = false; $lastitem = $item; $itemiter++; } } else { $html = ''; } if ($html) { //if there are list items to display then wrap them in ul / ol tag. $tabs = str_repeat("\t", $indent); $html = $tabs.'<'.$this->type.((!empty($this->attributes))?(' '.$this->attributes):'').">\n".$html; $html .= $tabs."</".$this->type.">\n"; } else { $html =''; } return $html; }
[ "public", "function", "to_html", "(", "$", "indent", "=", "0", ",", "$", "extraargs", "=", "array", "(", ")", ")", "{", "if", "(", "count", "(", "$", "this", "->", "items", ")", ")", "{", "$", "tabs", "=", "str_repeat", "(", "\"\\t\"", ",", "$", "indent", ")", ";", "$", "first", "=", "true", ";", "$", "itemiter", "=", "1", ";", "$", "lastitem", "=", "''", ";", "$", "html", "=", "''", ";", "foreach", "(", "$", "this", "->", "items", "as", "$", "item", ")", "{", "$", "last", "=", "(", "count", "(", "$", "this", "->", "items", ")", "==", "$", "itemiter", ")", ";", "if", "(", "$", "this", "->", "editable", ")", "{", "$", "item", "->", "set_icon_html", "(", "$", "first", ",", "$", "last", ",", "$", "lastitem", ")", ";", "}", "if", "(", "$", "itemhtml", "=", "$", "item", "->", "to_html", "(", "$", "indent", "+", "1", ",", "$", "extraargs", ")", ")", "{", "$", "html", ".=", "\"$tabs\\t<li\"", ".", "(", "(", "!", "empty", "(", "$", "item", "->", "attributes", ")", ")", "?", "(", "' '", ".", "$", "item", "->", "attributes", ")", ":", "''", ")", ".", "\">\"", ";", "$", "html", ".=", "$", "itemhtml", ";", "$", "html", ".=", "\"</li>\\n\"", ";", "}", "$", "first", "=", "false", ";", "$", "lastitem", "=", "$", "item", ";", "$", "itemiter", "++", ";", "}", "}", "else", "{", "$", "html", "=", "''", ";", "}", "if", "(", "$", "html", ")", "{", "//if there are list items to display then wrap them in ul / ol tag.", "$", "tabs", "=", "str_repeat", "(", "\"\\t\"", ",", "$", "indent", ")", ";", "$", "html", "=", "$", "tabs", ".", "'<'", ".", "$", "this", "->", "type", ".", "(", "(", "!", "empty", "(", "$", "this", "->", "attributes", ")", ")", "?", "(", "' '", ".", "$", "this", "->", "attributes", ")", ":", "''", ")", ".", "\">\\n\"", ".", "$", "html", ";", "$", "html", ".=", "$", "tabs", ".", "\"</\"", ".", "$", "this", "->", "type", ".", "\">\\n\"", ";", "}", "else", "{", "$", "html", "=", "''", ";", "}", "return", "$", "html", ";", "}" ]
Returns html string. @param integer $indent depth of indentation.
[ "Returns", "html", "string", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/listlib.php#L115-L148
216,133
moodle/moodle
lib/listlib.php
moodle_list.find_item
public function find_item($id, $suppresserror = false) { if (isset($this->items)) { foreach ($this->items as $key => $child) { if ($child->id == $id) { return $this->items[$key]; } } foreach (array_keys($this->items) as $key) { $thischild = $this->items[$key]; $ref = $thischild->children->find_item($id, true);//error always reported at top level if ($ref !== null) { return $ref; } } } if (!$suppresserror) { print_error('listnoitem'); } return null; }
php
public function find_item($id, $suppresserror = false) { if (isset($this->items)) { foreach ($this->items as $key => $child) { if ($child->id == $id) { return $this->items[$key]; } } foreach (array_keys($this->items) as $key) { $thischild = $this->items[$key]; $ref = $thischild->children->find_item($id, true);//error always reported at top level if ($ref !== null) { return $ref; } } } if (!$suppresserror) { print_error('listnoitem'); } return null; }
[ "public", "function", "find_item", "(", "$", "id", ",", "$", "suppresserror", "=", "false", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "items", ")", ")", "{", "foreach", "(", "$", "this", "->", "items", "as", "$", "key", "=>", "$", "child", ")", "{", "if", "(", "$", "child", "->", "id", "==", "$", "id", ")", "{", "return", "$", "this", "->", "items", "[", "$", "key", "]", ";", "}", "}", "foreach", "(", "array_keys", "(", "$", "this", "->", "items", ")", "as", "$", "key", ")", "{", "$", "thischild", "=", "$", "this", "->", "items", "[", "$", "key", "]", ";", "$", "ref", "=", "$", "thischild", "->", "children", "->", "find_item", "(", "$", "id", ",", "true", ")", ";", "//error always reported at top level", "if", "(", "$", "ref", "!==", "null", ")", "{", "return", "$", "ref", ";", "}", "}", "}", "if", "(", "!", "$", "suppresserror", ")", "{", "print_error", "(", "'listnoitem'", ")", ";", "}", "return", "null", ";", "}" ]
Recurse down the tree and find an item by it's id. @param integer $id @param boolean $suppresserror error if not item found? @return list_item *copy* or null if item is not found
[ "Recurse", "down", "the", "tree", "and", "find", "an", "item", "by", "it", "s", "id", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/listlib.php#L157-L177
216,134
moodle/moodle
lib/listlib.php
moodle_list.list_from_records
public function list_from_records($paged = false, $offset = 0) { $this->paged = $paged; $this->offset = $offset; $this->get_records(); $records = $this->records; $page = $this->page; if (!empty($page)) { $this->firstitem = ($page - 1) * $this->itemsperpage; $this->lastitem = $this->firstitem + $this->itemsperpage - 1; } $itemiter = $offset; //make a simple array which is easier to search $this->childparent = array(); foreach ($records as $record) { $this->childparent[$record->id] = $record->parent; } //create top level list items and they're responsible for creating their children foreach ($records as $record) { if (array_key_exists($record->parent, $this->childparent)) { // This record is a child of another record, so it will be dealt // with by a call to list_item::create_children, not here. continue; } $inpage = $itemiter >= $this->firstitem && $itemiter <= $this->lastitem; // Make list item for top level for all items // we need the info about the top level items for reordering peers. if ($this->parentitem !== null) { $newattributes = $this->parentitem->attributes; } else { $newattributes = ''; } $this->items[$itemiter] = new $this->listitemclassname($record, $this, $newattributes, $inpage); if ($inpage) { $this->items[$itemiter]->create_children($records, $this->childparent, $record->id); } else { // Don't recurse down the tree for items that are not on this page $this->paged = true; } $itemiter++; } return array($this->paged, $itemiter); }
php
public function list_from_records($paged = false, $offset = 0) { $this->paged = $paged; $this->offset = $offset; $this->get_records(); $records = $this->records; $page = $this->page; if (!empty($page)) { $this->firstitem = ($page - 1) * $this->itemsperpage; $this->lastitem = $this->firstitem + $this->itemsperpage - 1; } $itemiter = $offset; //make a simple array which is easier to search $this->childparent = array(); foreach ($records as $record) { $this->childparent[$record->id] = $record->parent; } //create top level list items and they're responsible for creating their children foreach ($records as $record) { if (array_key_exists($record->parent, $this->childparent)) { // This record is a child of another record, so it will be dealt // with by a call to list_item::create_children, not here. continue; } $inpage = $itemiter >= $this->firstitem && $itemiter <= $this->lastitem; // Make list item for top level for all items // we need the info about the top level items for reordering peers. if ($this->parentitem !== null) { $newattributes = $this->parentitem->attributes; } else { $newattributes = ''; } $this->items[$itemiter] = new $this->listitemclassname($record, $this, $newattributes, $inpage); if ($inpage) { $this->items[$itemiter]->create_children($records, $this->childparent, $record->id); } else { // Don't recurse down the tree for items that are not on this page $this->paged = true; } $itemiter++; } return array($this->paged, $itemiter); }
[ "public", "function", "list_from_records", "(", "$", "paged", "=", "false", ",", "$", "offset", "=", "0", ")", "{", "$", "this", "->", "paged", "=", "$", "paged", ";", "$", "this", "->", "offset", "=", "$", "offset", ";", "$", "this", "->", "get_records", "(", ")", ";", "$", "records", "=", "$", "this", "->", "records", ";", "$", "page", "=", "$", "this", "->", "page", ";", "if", "(", "!", "empty", "(", "$", "page", ")", ")", "{", "$", "this", "->", "firstitem", "=", "(", "$", "page", "-", "1", ")", "*", "$", "this", "->", "itemsperpage", ";", "$", "this", "->", "lastitem", "=", "$", "this", "->", "firstitem", "+", "$", "this", "->", "itemsperpage", "-", "1", ";", "}", "$", "itemiter", "=", "$", "offset", ";", "//make a simple array which is easier to search", "$", "this", "->", "childparent", "=", "array", "(", ")", ";", "foreach", "(", "$", "records", "as", "$", "record", ")", "{", "$", "this", "->", "childparent", "[", "$", "record", "->", "id", "]", "=", "$", "record", "->", "parent", ";", "}", "//create top level list items and they're responsible for creating their children", "foreach", "(", "$", "records", "as", "$", "record", ")", "{", "if", "(", "array_key_exists", "(", "$", "record", "->", "parent", ",", "$", "this", "->", "childparent", ")", ")", "{", "// This record is a child of another record, so it will be dealt", "// with by a call to list_item::create_children, not here.", "continue", ";", "}", "$", "inpage", "=", "$", "itemiter", ">=", "$", "this", "->", "firstitem", "&&", "$", "itemiter", "<=", "$", "this", "->", "lastitem", ";", "// Make list item for top level for all items", "// we need the info about the top level items for reordering peers.", "if", "(", "$", "this", "->", "parentitem", "!==", "null", ")", "{", "$", "newattributes", "=", "$", "this", "->", "parentitem", "->", "attributes", ";", "}", "else", "{", "$", "newattributes", "=", "''", ";", "}", "$", "this", "->", "items", "[", "$", "itemiter", "]", "=", "new", "$", "this", "->", "listitemclassname", "(", "$", "record", ",", "$", "this", ",", "$", "newattributes", ",", "$", "inpage", ")", ";", "if", "(", "$", "inpage", ")", "{", "$", "this", "->", "items", "[", "$", "itemiter", "]", "->", "create_children", "(", "$", "records", ",", "$", "this", "->", "childparent", ",", "$", "record", "->", "id", ")", ";", "}", "else", "{", "// Don't recurse down the tree for items that are not on this page", "$", "this", "->", "paged", "=", "true", ";", "}", "$", "itemiter", "++", ";", "}", "return", "array", "(", "$", "this", "->", "paged", ",", "$", "itemiter", ")", ";", "}" ]
Produces a hierarchical tree of list items from a flat array of records. 'parent' field is expected to point to a parent record. records are already sorted. If the parent field doesn't point to another record in the array then this is a top level list @param integer $offset how many list toplevel items are there in lists before this one @return array(boolean, integer) whether there is more than one page, $offset + how many toplevel items where there in this list.
[ "Produces", "a", "hierarchical", "tree", "of", "list", "items", "from", "a", "flat", "array", "of", "records", ".", "parent", "field", "is", "expected", "to", "point", "to", "a", "parent", "record", ".", "records", "are", "already", "sorted", ".", "If", "the", "parent", "field", "doesn", "t", "point", "to", "another", "record", "in", "the", "array", "then", "this", "is", "a", "top", "level", "list" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/listlib.php#L198-L245
216,135
moodle/moodle
lib/listlib.php
moodle_list.display_page_numbers
public function display_page_numbers() { $html = ''; $topcount = count($this->items); $this->pagecount = (integer) ceil(($topcount + $this->offset)/ QUESTION_PAGE_LENGTH ); if (!empty($this->page) && ($this->paged)) { $html = "<div class=\"paging\">".get_string('page').":\n"; foreach (range(1,$this->pagecount) as $currentpage) { if ($this->page == $currentpage) { $html .= " $currentpage \n"; } else { $html .= "<a href=\"".$this->pageurl->out(true, array($this->pageparamname => $currentpage))."\">"; $html .= " $currentpage </a>\n"; } } $html .= "</div>"; } return $html; }
php
public function display_page_numbers() { $html = ''; $topcount = count($this->items); $this->pagecount = (integer) ceil(($topcount + $this->offset)/ QUESTION_PAGE_LENGTH ); if (!empty($this->page) && ($this->paged)) { $html = "<div class=\"paging\">".get_string('page').":\n"; foreach (range(1,$this->pagecount) as $currentpage) { if ($this->page == $currentpage) { $html .= " $currentpage \n"; } else { $html .= "<a href=\"".$this->pageurl->out(true, array($this->pageparamname => $currentpage))."\">"; $html .= " $currentpage </a>\n"; } } $html .= "</div>"; } return $html; }
[ "public", "function", "display_page_numbers", "(", ")", "{", "$", "html", "=", "''", ";", "$", "topcount", "=", "count", "(", "$", "this", "->", "items", ")", ";", "$", "this", "->", "pagecount", "=", "(", "integer", ")", "ceil", "(", "(", "$", "topcount", "+", "$", "this", "->", "offset", ")", "/", "QUESTION_PAGE_LENGTH", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "page", ")", "&&", "(", "$", "this", "->", "paged", ")", ")", "{", "$", "html", "=", "\"<div class=\\\"paging\\\">\"", ".", "get_string", "(", "'page'", ")", ".", "\":\\n\"", ";", "foreach", "(", "range", "(", "1", ",", "$", "this", "->", "pagecount", ")", "as", "$", "currentpage", ")", "{", "if", "(", "$", "this", "->", "page", "==", "$", "currentpage", ")", "{", "$", "html", ".=", "\" $currentpage \\n\"", ";", "}", "else", "{", "$", "html", ".=", "\"<a href=\\\"\"", ".", "$", "this", "->", "pageurl", "->", "out", "(", "true", ",", "array", "(", "$", "this", "->", "pageparamname", "=>", "$", "currentpage", ")", ")", ".", "\"\\\">\"", ";", "$", "html", ".=", "\" $currentpage </a>\\n\"", ";", "}", "}", "$", "html", ".=", "\"</div>\"", ";", "}", "return", "$", "html", ";", "}" ]
display list of page numbers for navigation
[ "display", "list", "of", "page", "numbers", "for", "navigation" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/listlib.php#L255-L273
216,136
moodle/moodle
lib/listlib.php
moodle_list.get_items_peers
public function get_items_peers($itemid) { $itemref = $this->find_item($itemid); $peerids = $itemref->parentlist->get_child_ids(); return $peerids; }
php
public function get_items_peers($itemid) { $itemref = $this->find_item($itemid); $peerids = $itemref->parentlist->get_child_ids(); return $peerids; }
[ "public", "function", "get_items_peers", "(", "$", "itemid", ")", "{", "$", "itemref", "=", "$", "this", "->", "find_item", "(", "$", "itemid", ")", ";", "$", "peerids", "=", "$", "itemref", "->", "parentlist", "->", "get_child_ids", "(", ")", ";", "return", "$", "peerids", ";", "}" ]
Returns an array of ids of peers of an item. @param int itemid - if given, restrict records to those with this parent id. @return array peer ids
[ "Returns", "an", "array", "of", "ids", "of", "peers", "of", "an", "item", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/listlib.php#L281-L285
216,137
moodle/moodle
lib/listlib.php
moodle_list.get_child_ids
public function get_child_ids() { $childids = array(); foreach ($this->items as $child) { $childids[] = $child->id; } return $childids; }
php
public function get_child_ids() { $childids = array(); foreach ($this->items as $child) { $childids[] = $child->id; } return $childids; }
[ "public", "function", "get_child_ids", "(", ")", "{", "$", "childids", "=", "array", "(", ")", ";", "foreach", "(", "$", "this", "->", "items", "as", "$", "child", ")", "{", "$", "childids", "[", "]", "=", "$", "child", "->", "id", ";", "}", "return", "$", "childids", ";", "}" ]
Returns an array of ids of child items. @return array peer ids
[ "Returns", "an", "array", "of", "ids", "of", "child", "items", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/listlib.php#L292-L298
216,138
moodle/moodle
lib/listlib.php
moodle_list.move_item_up_down
public function move_item_up_down($direction, $id) { $peers = $this->get_items_peers($id); $itemkey = array_search($id, $peers); switch ($direction) { case 'down' : if (isset($peers[$itemkey+1])) { $olditem = $peers[$itemkey+1]; $peers[$itemkey+1] = $id; $peers[$itemkey] = $olditem; } else { print_error('listcantmoveup'); } break; case 'up' : if (isset($peers[$itemkey-1])) { $olditem = $peers[$itemkey-1]; $peers[$itemkey-1] = $id; $peers[$itemkey] = $olditem; } else { print_error('listcantmovedown'); } break; } $this->reorder_peers($peers); }
php
public function move_item_up_down($direction, $id) { $peers = $this->get_items_peers($id); $itemkey = array_search($id, $peers); switch ($direction) { case 'down' : if (isset($peers[$itemkey+1])) { $olditem = $peers[$itemkey+1]; $peers[$itemkey+1] = $id; $peers[$itemkey] = $olditem; } else { print_error('listcantmoveup'); } break; case 'up' : if (isset($peers[$itemkey-1])) { $olditem = $peers[$itemkey-1]; $peers[$itemkey-1] = $id; $peers[$itemkey] = $olditem; } else { print_error('listcantmovedown'); } break; } $this->reorder_peers($peers); }
[ "public", "function", "move_item_up_down", "(", "$", "direction", ",", "$", "id", ")", "{", "$", "peers", "=", "$", "this", "->", "get_items_peers", "(", "$", "id", ")", ";", "$", "itemkey", "=", "array_search", "(", "$", "id", ",", "$", "peers", ")", ";", "switch", "(", "$", "direction", ")", "{", "case", "'down'", ":", "if", "(", "isset", "(", "$", "peers", "[", "$", "itemkey", "+", "1", "]", ")", ")", "{", "$", "olditem", "=", "$", "peers", "[", "$", "itemkey", "+", "1", "]", ";", "$", "peers", "[", "$", "itemkey", "+", "1", "]", "=", "$", "id", ";", "$", "peers", "[", "$", "itemkey", "]", "=", "$", "olditem", ";", "}", "else", "{", "print_error", "(", "'listcantmoveup'", ")", ";", "}", "break", ";", "case", "'up'", ":", "if", "(", "isset", "(", "$", "peers", "[", "$", "itemkey", "-", "1", "]", ")", ")", "{", "$", "olditem", "=", "$", "peers", "[", "$", "itemkey", "-", "1", "]", ";", "$", "peers", "[", "$", "itemkey", "-", "1", "]", "=", "$", "id", ";", "$", "peers", "[", "$", "itemkey", "]", "=", "$", "olditem", ";", "}", "else", "{", "print_error", "(", "'listcantmovedown'", ")", ";", "}", "break", ";", "}", "$", "this", "->", "reorder_peers", "(", "$", "peers", ")", ";", "}" ]
Move a record up or down @param string $direction up / down @param integer $id
[ "Move", "a", "record", "up", "or", "down" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/listlib.php#L317-L342
216,139
moodle/moodle
lib/listlib.php
moodle_list.move_item_left
public function move_item_left($id) { global $DB; $item = $this->find_item($id); if (!isset($item->parentlist->parentitem->parentlist)) { print_error('listcantmoveleft'); } else { $newpeers = $this->get_items_peers($item->parentlist->parentitem->id); if (isset($item->parentlist->parentitem->parentlist->parentitem)) { $newparent = $item->parentlist->parentitem->parentlist->parentitem->id; } else { $newparent = $this->get_top_level_parent_id($item); } $DB->set_field($this->table, "parent", $newparent, array("id"=>$item->id)); $oldparentkey = array_search($item->parentlist->parentitem->id, $newpeers); $neworder = array_merge(array_slice($newpeers, 0, $oldparentkey+1), array($item->id), array_slice($newpeers, $oldparentkey+1)); $this->reorder_peers($neworder); } return $item->parentlist->parentitem; }
php
public function move_item_left($id) { global $DB; $item = $this->find_item($id); if (!isset($item->parentlist->parentitem->parentlist)) { print_error('listcantmoveleft'); } else { $newpeers = $this->get_items_peers($item->parentlist->parentitem->id); if (isset($item->parentlist->parentitem->parentlist->parentitem)) { $newparent = $item->parentlist->parentitem->parentlist->parentitem->id; } else { $newparent = $this->get_top_level_parent_id($item); } $DB->set_field($this->table, "parent", $newparent, array("id"=>$item->id)); $oldparentkey = array_search($item->parentlist->parentitem->id, $newpeers); $neworder = array_merge(array_slice($newpeers, 0, $oldparentkey+1), array($item->id), array_slice($newpeers, $oldparentkey+1)); $this->reorder_peers($neworder); } return $item->parentlist->parentitem; }
[ "public", "function", "move_item_left", "(", "$", "id", ")", "{", "global", "$", "DB", ";", "$", "item", "=", "$", "this", "->", "find_item", "(", "$", "id", ")", ";", "if", "(", "!", "isset", "(", "$", "item", "->", "parentlist", "->", "parentitem", "->", "parentlist", ")", ")", "{", "print_error", "(", "'listcantmoveleft'", ")", ";", "}", "else", "{", "$", "newpeers", "=", "$", "this", "->", "get_items_peers", "(", "$", "item", "->", "parentlist", "->", "parentitem", "->", "id", ")", ";", "if", "(", "isset", "(", "$", "item", "->", "parentlist", "->", "parentitem", "->", "parentlist", "->", "parentitem", ")", ")", "{", "$", "newparent", "=", "$", "item", "->", "parentlist", "->", "parentitem", "->", "parentlist", "->", "parentitem", "->", "id", ";", "}", "else", "{", "$", "newparent", "=", "$", "this", "->", "get_top_level_parent_id", "(", "$", "item", ")", ";", "}", "$", "DB", "->", "set_field", "(", "$", "this", "->", "table", ",", "\"parent\"", ",", "$", "newparent", ",", "array", "(", "\"id\"", "=>", "$", "item", "->", "id", ")", ")", ";", "$", "oldparentkey", "=", "array_search", "(", "$", "item", "->", "parentlist", "->", "parentitem", "->", "id", ",", "$", "newpeers", ")", ";", "$", "neworder", "=", "array_merge", "(", "array_slice", "(", "$", "newpeers", ",", "0", ",", "$", "oldparentkey", "+", "1", ")", ",", "array", "(", "$", "item", "->", "id", ")", ",", "array_slice", "(", "$", "newpeers", ",", "$", "oldparentkey", "+", "1", ")", ")", ";", "$", "this", "->", "reorder_peers", "(", "$", "neworder", ")", ";", "}", "return", "$", "item", "->", "parentlist", "->", "parentitem", ";", "}" ]
Moves the item one step up in the tree. @param int $id an item index. @return list_item the item that used to be the parent of the item moved.
[ "Moves", "the", "item", "one", "step", "up", "in", "the", "tree", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/listlib.php#L357-L376
216,140
moodle/moodle
lib/listlib.php
list_item.item_html
public function item_html($extraargs = array()) { if (is_string($this->item)) { $html = $this->item; } elseif (is_object($this->item)) { //for debug purposes only. You should create a sub class to //properly handle the record $html = join(', ', (array)$this->item); } return $html; }
php
public function item_html($extraargs = array()) { if (is_string($this->item)) { $html = $this->item; } elseif (is_object($this->item)) { //for debug purposes only. You should create a sub class to //properly handle the record $html = join(', ', (array)$this->item); } return $html; }
[ "public", "function", "item_html", "(", "$", "extraargs", "=", "array", "(", ")", ")", "{", "if", "(", "is_string", "(", "$", "this", "->", "item", ")", ")", "{", "$", "html", "=", "$", "this", "->", "item", ";", "}", "elseif", "(", "is_object", "(", "$", "this", "->", "item", ")", ")", "{", "//for debug purposes only. You should create a sub class to", "//properly handle the record", "$", "html", "=", "join", "(", "', '", ",", "(", "array", ")", "$", "this", "->", "item", ")", ";", "}", "return", "$", "html", ";", "}" ]
Output the html just for this item. Called by to_html which adds html for children.
[ "Output", "the", "html", "just", "for", "this", "item", ".", "Called", "by", "to_html", "which", "adds", "html", "for", "children", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/listlib.php#L525-L534
216,141
moodle/moodle
mod/quiz/classes/group_observers.php
group_observers.group_member_removed
public static function group_member_removed($event) { if (!empty(self::$resetinprogress)) { // We will take care of that once the course reset ends. return; } quiz_update_open_attempts(array('userid' => $event->relateduserid, 'groupid' => $event->objectid)); }
php
public static function group_member_removed($event) { if (!empty(self::$resetinprogress)) { // We will take care of that once the course reset ends. return; } quiz_update_open_attempts(array('userid' => $event->relateduserid, 'groupid' => $event->objectid)); }
[ "public", "static", "function", "group_member_removed", "(", "$", "event", ")", "{", "if", "(", "!", "empty", "(", "self", "::", "$", "resetinprogress", ")", ")", "{", "// We will take care of that once the course reset ends.", "return", ";", "}", "quiz_update_open_attempts", "(", "array", "(", "'userid'", "=>", "$", "event", "->", "relateduserid", ",", "'groupid'", "=>", "$", "event", "->", "objectid", ")", ")", ";", "}" ]
A group member was deleted. @param \core\event\base $event The event. @return void
[ "A", "group", "member", "was", "deleted", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/classes/group_observers.php#L105-L111
216,142
moodle/moodle
lib/classes/output/icon_system.php
icon_system.remap_icon_name
public final function remap_icon_name($iconname, $component) { if ($this->map === null) { $this->map = $this->get_icon_name_map(); } if ($component == null || $component == 'moodle') { $component = 'core'; } else if ($component != 'theme') { $component = \core_component::normalize_componentname($component); } if (isset($this->map[$component . ':' . $iconname])) { return $this->map[$component . ':' . $iconname]; } return false; }
php
public final function remap_icon_name($iconname, $component) { if ($this->map === null) { $this->map = $this->get_icon_name_map(); } if ($component == null || $component == 'moodle') { $component = 'core'; } else if ($component != 'theme') { $component = \core_component::normalize_componentname($component); } if (isset($this->map[$component . ':' . $iconname])) { return $this->map[$component . ':' . $iconname]; } return false; }
[ "public", "final", "function", "remap_icon_name", "(", "$", "iconname", ",", "$", "component", ")", "{", "if", "(", "$", "this", "->", "map", "===", "null", ")", "{", "$", "this", "->", "map", "=", "$", "this", "->", "get_icon_name_map", "(", ")", ";", "}", "if", "(", "$", "component", "==", "null", "||", "$", "component", "==", "'moodle'", ")", "{", "$", "component", "=", "'core'", ";", "}", "else", "if", "(", "$", "component", "!=", "'theme'", ")", "{", "$", "component", "=", "\\", "core_component", "::", "normalize_componentname", "(", "$", "component", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "map", "[", "$", "component", ".", "':'", ".", "$", "iconname", "]", ")", ")", "{", "return", "$", "this", "->", "map", "[", "$", "component", ".", "':'", ".", "$", "iconname", "]", ";", "}", "return", "false", ";", "}" ]
Overridable function to map the icon name to something else. Default is to do no mapping. Map is cached in the singleton.
[ "Overridable", "function", "to", "map", "the", "icon", "name", "to", "something", "else", ".", "Default", "is", "to", "do", "no", "mapping", ".", "Map", "is", "cached", "in", "the", "singleton", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/output/icon_system.php#L133-L147
216,143
moodle/moodle
lib/horde/framework/Horde/Stream/Wrapper/Combine.php
Horde_Stream_Wrapper_Combine.getStream
public static function getStream($data) { if (!self::$_id) { stream_wrapper_register(self::WRAPPER_NAME, __CLASS__); } return fopen( self::WRAPPER_NAME . '://' . ++self::$_id, 'wb', false, stream_context_create(array( self::WRAPPER_NAME => array( 'data' => $data ) )) ); }
php
public static function getStream($data) { if (!self::$_id) { stream_wrapper_register(self::WRAPPER_NAME, __CLASS__); } return fopen( self::WRAPPER_NAME . '://' . ++self::$_id, 'wb', false, stream_context_create(array( self::WRAPPER_NAME => array( 'data' => $data ) )) ); }
[ "public", "static", "function", "getStream", "(", "$", "data", ")", "{", "if", "(", "!", "self", "::", "$", "_id", ")", "{", "stream_wrapper_register", "(", "self", "::", "WRAPPER_NAME", ",", "__CLASS__", ")", ";", "}", "return", "fopen", "(", "self", "::", "WRAPPER_NAME", ".", "'://'", ".", "++", "self", "::", "$", "_id", ",", "'wb'", ",", "false", ",", "stream_context_create", "(", "array", "(", "self", "::", "WRAPPER_NAME", "=>", "array", "(", "'data'", "=>", "$", "data", ")", ")", ")", ")", ";", "}" ]
Create a stream from multiple data sources. @since 2.1.0 @param array $data An array of strings and/or streams to combine into a single stream. @return resource A PHP stream.
[ "Create", "a", "stream", "from", "multiple", "data", "sources", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Stream/Wrapper/Combine.php#L88-L104
216,144
moodle/moodle
lib/horde/framework/Horde/Imap/Client/Auth/DigestMD5.php
Horde_Imap_Client_Auth_DigestMD5._parseChallenge
protected function _parseChallenge($challenge) { $tokens = array( 'maxbuf' => 65536, 'realm' => '' ); preg_match_all('/([a-z-]+)=("[^"]+(?<!\\\)"|[^,]+)/i', $challenge, $matches, PREG_SET_ORDER); foreach ($matches as $val) { $tokens[$val[1]] = trim($val[2], '"'); } // Required directives. if (!isset($tokens['nonce']) || !isset($tokens['algorithm'])) { throw new Horde_Imap_Client_Exception( Horde_Imap_Client_Translation::r("Authentication failure."), Horde_Imap_Client_Exception::SERVER_CONNECT ); } return $tokens; }
php
protected function _parseChallenge($challenge) { $tokens = array( 'maxbuf' => 65536, 'realm' => '' ); preg_match_all('/([a-z-]+)=("[^"]+(?<!\\\)"|[^,]+)/i', $challenge, $matches, PREG_SET_ORDER); foreach ($matches as $val) { $tokens[$val[1]] = trim($val[2], '"'); } // Required directives. if (!isset($tokens['nonce']) || !isset($tokens['algorithm'])) { throw new Horde_Imap_Client_Exception( Horde_Imap_Client_Translation::r("Authentication failure."), Horde_Imap_Client_Exception::SERVER_CONNECT ); } return $tokens; }
[ "protected", "function", "_parseChallenge", "(", "$", "challenge", ")", "{", "$", "tokens", "=", "array", "(", "'maxbuf'", "=>", "65536", ",", "'realm'", "=>", "''", ")", ";", "preg_match_all", "(", "'/([a-z-]+)=(\"[^\"]+(?<!\\\\\\)\"|[^,]+)/i'", ",", "$", "challenge", ",", "$", "matches", ",", "PREG_SET_ORDER", ")", ";", "foreach", "(", "$", "matches", "as", "$", "val", ")", "{", "$", "tokens", "[", "$", "val", "[", "1", "]", "]", "=", "trim", "(", "$", "val", "[", "2", "]", ",", "'\"'", ")", ";", "}", "// Required directives.", "if", "(", "!", "isset", "(", "$", "tokens", "[", "'nonce'", "]", ")", "||", "!", "isset", "(", "$", "tokens", "[", "'algorithm'", "]", ")", ")", "{", "throw", "new", "Horde_Imap_Client_Exception", "(", "Horde_Imap_Client_Translation", "::", "r", "(", "\"Authentication failure.\"", ")", ",", "Horde_Imap_Client_Exception", "::", "SERVER_CONNECT", ")", ";", "}", "return", "$", "tokens", ";", "}" ]
Parses and verifies the digest challenge. @param string $challenge The digest challenge @return array The parsed challenge as an array with directives as keys. @throws Horde_Imap_Client_Exception
[ "Parses", "and", "verifies", "the", "digest", "challenge", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Auth/DigestMD5.php#L142-L164
216,145
moodle/moodle
badges/classes/privacy/provider.php
provider.delete_user_data
protected static function delete_user_data($userid) { global $DB; // Delete the stuff. $DB->delete_records('badge_manual_award', ['recipientid' => $userid]); $DB->delete_records('badge_criteria_met', ['userid' => $userid]); $DB->delete_records('badge_issued', ['userid' => $userid]); // Delete the backpacks and related stuff. $backpackids = $DB->get_fieldset_select('badge_backpack', 'id', 'userid = :userid', ['userid' => $userid]); if (!empty($backpackids)) { list($insql, $inparams) = $DB->get_in_or_equal($backpackids, SQL_PARAMS_NAMED); $DB->delete_records_select('badge_external', "backpackid $insql", $inparams); $DB->delete_records_select('badge_backpack', "id $insql", $inparams); } }
php
protected static function delete_user_data($userid) { global $DB; // Delete the stuff. $DB->delete_records('badge_manual_award', ['recipientid' => $userid]); $DB->delete_records('badge_criteria_met', ['userid' => $userid]); $DB->delete_records('badge_issued', ['userid' => $userid]); // Delete the backpacks and related stuff. $backpackids = $DB->get_fieldset_select('badge_backpack', 'id', 'userid = :userid', ['userid' => $userid]); if (!empty($backpackids)) { list($insql, $inparams) = $DB->get_in_or_equal($backpackids, SQL_PARAMS_NAMED); $DB->delete_records_select('badge_external', "backpackid $insql", $inparams); $DB->delete_records_select('badge_backpack', "id $insql", $inparams); } }
[ "protected", "static", "function", "delete_user_data", "(", "$", "userid", ")", "{", "global", "$", "DB", ";", "// Delete the stuff.", "$", "DB", "->", "delete_records", "(", "'badge_manual_award'", ",", "[", "'recipientid'", "=>", "$", "userid", "]", ")", ";", "$", "DB", "->", "delete_records", "(", "'badge_criteria_met'", ",", "[", "'userid'", "=>", "$", "userid", "]", ")", ";", "$", "DB", "->", "delete_records", "(", "'badge_issued'", ",", "[", "'userid'", "=>", "$", "userid", "]", ")", ";", "// Delete the backpacks and related stuff.", "$", "backpackids", "=", "$", "DB", "->", "get_fieldset_select", "(", "'badge_backpack'", ",", "'id'", ",", "'userid = :userid'", ",", "[", "'userid'", "=>", "$", "userid", "]", ")", ";", "if", "(", "!", "empty", "(", "$", "backpackids", ")", ")", "{", "list", "(", "$", "insql", ",", "$", "inparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "backpackids", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "DB", "->", "delete_records_select", "(", "'badge_external'", ",", "\"backpackid $insql\"", ",", "$", "inparams", ")", ";", "$", "DB", "->", "delete_records_select", "(", "'badge_backpack'", ",", "\"id $insql\"", ",", "$", "inparams", ")", ";", "}", "}" ]
Delete all the data for a user. @param int $userid The user ID. @return void
[ "Delete", "all", "the", "data", "for", "a", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/badges/classes/privacy/provider.php#L645-L660
216,146
moodle/moodle
admin/tool/dataprivacy/classes/form/context_instance.php
context_instance.add_purpose_category
protected function add_purpose_category($contextlevel = false) { $mform = $this->_form; $addcategorytext = $this->get_add_element_content(get_string('addcategory', 'tool_dataprivacy')); $categoryselect = $mform->createElement('select', 'categoryid', null, $this->_customdata['categories']); $addcategory = $mform->createElement('button', 'addcategory', $addcategorytext, ['data-add-element' => 'category']); $mform->addElement('group', 'categorygroup', get_string('category', 'tool_dataprivacy'), [$categoryselect, $addcategory], null, false); $mform->addHelpButton('categorygroup', 'category', 'tool_dataprivacy'); $mform->setType('categoryid', PARAM_INT); $mform->setDefault('categoryid', 0); $addpurposetext = $this->get_add_element_content(get_string('addpurpose', 'tool_dataprivacy')); $purposeselect = $mform->createElement('select', 'purposeid', null, $this->_customdata['purposes']); $addpurpose = $mform->createElement('button', 'addpurpose', $addpurposetext, ['data-add-element' => 'purpose']); $mform->addElement('group', 'purposegroup', get_string('purpose', 'tool_dataprivacy'), [$purposeselect, $addpurpose], null, false); $mform->addHelpButton('purposegroup', 'purpose', 'tool_dataprivacy'); $mform->setType('purposeid', PARAM_INT); $mform->setDefault('purposeid', 0); if (!empty($this->_customdata['currentretentionperiod'])) { $mform->addElement('static', 'retention_current', get_string('retentionperiod', 'tool_dataprivacy'), $this->_customdata['currentretentionperiod']); $mform->addHelpButton('retention_current', 'retentionperiod', 'tool_dataprivacy'); } }
php
protected function add_purpose_category($contextlevel = false) { $mform = $this->_form; $addcategorytext = $this->get_add_element_content(get_string('addcategory', 'tool_dataprivacy')); $categoryselect = $mform->createElement('select', 'categoryid', null, $this->_customdata['categories']); $addcategory = $mform->createElement('button', 'addcategory', $addcategorytext, ['data-add-element' => 'category']); $mform->addElement('group', 'categorygroup', get_string('category', 'tool_dataprivacy'), [$categoryselect, $addcategory], null, false); $mform->addHelpButton('categorygroup', 'category', 'tool_dataprivacy'); $mform->setType('categoryid', PARAM_INT); $mform->setDefault('categoryid', 0); $addpurposetext = $this->get_add_element_content(get_string('addpurpose', 'tool_dataprivacy')); $purposeselect = $mform->createElement('select', 'purposeid', null, $this->_customdata['purposes']); $addpurpose = $mform->createElement('button', 'addpurpose', $addpurposetext, ['data-add-element' => 'purpose']); $mform->addElement('group', 'purposegroup', get_string('purpose', 'tool_dataprivacy'), [$purposeselect, $addpurpose], null, false); $mform->addHelpButton('purposegroup', 'purpose', 'tool_dataprivacy'); $mform->setType('purposeid', PARAM_INT); $mform->setDefault('purposeid', 0); if (!empty($this->_customdata['currentretentionperiod'])) { $mform->addElement('static', 'retention_current', get_string('retentionperiod', 'tool_dataprivacy'), $this->_customdata['currentretentionperiod']); $mform->addHelpButton('retention_current', 'retentionperiod', 'tool_dataprivacy'); } }
[ "protected", "function", "add_purpose_category", "(", "$", "contextlevel", "=", "false", ")", "{", "$", "mform", "=", "$", "this", "->", "_form", ";", "$", "addcategorytext", "=", "$", "this", "->", "get_add_element_content", "(", "get_string", "(", "'addcategory'", ",", "'tool_dataprivacy'", ")", ")", ";", "$", "categoryselect", "=", "$", "mform", "->", "createElement", "(", "'select'", ",", "'categoryid'", ",", "null", ",", "$", "this", "->", "_customdata", "[", "'categories'", "]", ")", ";", "$", "addcategory", "=", "$", "mform", "->", "createElement", "(", "'button'", ",", "'addcategory'", ",", "$", "addcategorytext", ",", "[", "'data-add-element'", "=>", "'category'", "]", ")", ";", "$", "mform", "->", "addElement", "(", "'group'", ",", "'categorygroup'", ",", "get_string", "(", "'category'", ",", "'tool_dataprivacy'", ")", ",", "[", "$", "categoryselect", ",", "$", "addcategory", "]", ",", "null", ",", "false", ")", ";", "$", "mform", "->", "addHelpButton", "(", "'categorygroup'", ",", "'category'", ",", "'tool_dataprivacy'", ")", ";", "$", "mform", "->", "setType", "(", "'categoryid'", ",", "PARAM_INT", ")", ";", "$", "mform", "->", "setDefault", "(", "'categoryid'", ",", "0", ")", ";", "$", "addpurposetext", "=", "$", "this", "->", "get_add_element_content", "(", "get_string", "(", "'addpurpose'", ",", "'tool_dataprivacy'", ")", ")", ";", "$", "purposeselect", "=", "$", "mform", "->", "createElement", "(", "'select'", ",", "'purposeid'", ",", "null", ",", "$", "this", "->", "_customdata", "[", "'purposes'", "]", ")", ";", "$", "addpurpose", "=", "$", "mform", "->", "createElement", "(", "'button'", ",", "'addpurpose'", ",", "$", "addpurposetext", ",", "[", "'data-add-element'", "=>", "'purpose'", "]", ")", ";", "$", "mform", "->", "addElement", "(", "'group'", ",", "'purposegroup'", ",", "get_string", "(", "'purpose'", ",", "'tool_dataprivacy'", ")", ",", "[", "$", "purposeselect", ",", "$", "addpurpose", "]", ",", "null", ",", "false", ")", ";", "$", "mform", "->", "addHelpButton", "(", "'purposegroup'", ",", "'purpose'", ",", "'tool_dataprivacy'", ")", ";", "$", "mform", "->", "setType", "(", "'purposeid'", ",", "PARAM_INT", ")", ";", "$", "mform", "->", "setDefault", "(", "'purposeid'", ",", "0", ")", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "_customdata", "[", "'currentretentionperiod'", "]", ")", ")", "{", "$", "mform", "->", "addElement", "(", "'static'", ",", "'retention_current'", ",", "get_string", "(", "'retentionperiod'", ",", "'tool_dataprivacy'", ")", ",", "$", "this", "->", "_customdata", "[", "'currentretentionperiod'", "]", ")", ";", "$", "mform", "->", "addHelpButton", "(", "'retention_current'", ",", "'retentionperiod'", ",", "'tool_dataprivacy'", ")", ";", "}", "}" ]
Adds purpose and category selectors. @param int $contextlevel Apply this context level defaults. False for no defaults. @return null
[ "Adds", "purpose", "and", "category", "selectors", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/form/context_instance.php#L75-L102
216,147
moodle/moodle
admin/tool/dataprivacy/classes/form/context_instance.php
context_instance.get_add_element_content
private function get_add_element_content($label) { global $PAGE, $OUTPUT; $bs4 = false; $theme = $PAGE->theme; if ($theme->name === 'boost') { $bs4 = true; } else { foreach ($theme->parents as $basetheme) { if ($basetheme === 'boost') { $bs4 = true; } } } if (!$bs4) { return $label; } return $OUTPUT->pix_icon('e/insert', $label); }
php
private function get_add_element_content($label) { global $PAGE, $OUTPUT; $bs4 = false; $theme = $PAGE->theme; if ($theme->name === 'boost') { $bs4 = true; } else { foreach ($theme->parents as $basetheme) { if ($basetheme === 'boost') { $bs4 = true; } } } if (!$bs4) { return $label; } return $OUTPUT->pix_icon('e/insert', $label); }
[ "private", "function", "get_add_element_content", "(", "$", "label", ")", "{", "global", "$", "PAGE", ",", "$", "OUTPUT", ";", "$", "bs4", "=", "false", ";", "$", "theme", "=", "$", "PAGE", "->", "theme", ";", "if", "(", "$", "theme", "->", "name", "===", "'boost'", ")", "{", "$", "bs4", "=", "true", ";", "}", "else", "{", "foreach", "(", "$", "theme", "->", "parents", "as", "$", "basetheme", ")", "{", "if", "(", "$", "basetheme", "===", "'boost'", ")", "{", "$", "bs4", "=", "true", ";", "}", "}", "}", "if", "(", "!", "$", "bs4", ")", "{", "return", "$", "label", ";", "}", "return", "$", "OUTPUT", "->", "pix_icon", "(", "'e/insert'", ",", "$", "label", ")", ";", "}" ]
Returns the 'add' label. It depends on the theme in use. @param string $label @return \renderable|string
[ "Returns", "the", "add", "label", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/form/context_instance.php#L112-L132
216,148
moodle/moodle
admin/tool/dataprivacy/classes/form/context_instance.php
context_instance.get_context_instance_customdata
public static function get_context_instance_customdata(\context $context) { $persistent = \tool_dataprivacy\context_instance::get_record_by_contextid($context->id, false); if (!$persistent) { $persistent = new \tool_dataprivacy\context_instance(); $persistent->set('contextid', $context->id); } $purposes = []; foreach (api::get_purposes() as $purpose) { $purposes[$purpose->get('id')] = $purpose; } $purposeoptions = \tool_dataprivacy\output\data_registry_page::purpose_options($purposes); $categoryoptions = \tool_dataprivacy\output\data_registry_page::category_options(api::get_categories()); $customdata = [ 'context' => $context, 'subjectscope' => data_registry::get_subject_scope($context), 'contextname' => $context->get_context_name(), 'persistent' => $persistent, 'purposes' => $purposeoptions, 'categories' => $categoryoptions, ]; $effectivepurpose = api::get_effective_context_purpose($context); if ($effectivepurpose) { $customdata['currentretentionperiod'] = self::get_retention_display_text($effectivepurpose, $context->contextlevel, $context); $customdata['purposeretentionperiods'] = []; foreach (array_keys($purposeoptions) as $optionvalue) { if (isset($purposes[$optionvalue])) { $purpose = $purposes[$optionvalue]; } else { // Get the effective purpose if $optionvalue would be the selected value. $purpose = api::get_effective_context_purpose($context, $optionvalue); } $retentionperiod = self::get_retention_display_text( $purpose, $context->contextlevel, $context ); $customdata['purposeretentionperiods'][$optionvalue] = $retentionperiod; } } return $customdata; }
php
public static function get_context_instance_customdata(\context $context) { $persistent = \tool_dataprivacy\context_instance::get_record_by_contextid($context->id, false); if (!$persistent) { $persistent = new \tool_dataprivacy\context_instance(); $persistent->set('contextid', $context->id); } $purposes = []; foreach (api::get_purposes() as $purpose) { $purposes[$purpose->get('id')] = $purpose; } $purposeoptions = \tool_dataprivacy\output\data_registry_page::purpose_options($purposes); $categoryoptions = \tool_dataprivacy\output\data_registry_page::category_options(api::get_categories()); $customdata = [ 'context' => $context, 'subjectscope' => data_registry::get_subject_scope($context), 'contextname' => $context->get_context_name(), 'persistent' => $persistent, 'purposes' => $purposeoptions, 'categories' => $categoryoptions, ]; $effectivepurpose = api::get_effective_context_purpose($context); if ($effectivepurpose) { $customdata['currentretentionperiod'] = self::get_retention_display_text($effectivepurpose, $context->contextlevel, $context); $customdata['purposeretentionperiods'] = []; foreach (array_keys($purposeoptions) as $optionvalue) { if (isset($purposes[$optionvalue])) { $purpose = $purposes[$optionvalue]; } else { // Get the effective purpose if $optionvalue would be the selected value. $purpose = api::get_effective_context_purpose($context, $optionvalue); } $retentionperiod = self::get_retention_display_text( $purpose, $context->contextlevel, $context ); $customdata['purposeretentionperiods'][$optionvalue] = $retentionperiod; } } return $customdata; }
[ "public", "static", "function", "get_context_instance_customdata", "(", "\\", "context", "$", "context", ")", "{", "$", "persistent", "=", "\\", "tool_dataprivacy", "\\", "context_instance", "::", "get_record_by_contextid", "(", "$", "context", "->", "id", ",", "false", ")", ";", "if", "(", "!", "$", "persistent", ")", "{", "$", "persistent", "=", "new", "\\", "tool_dataprivacy", "\\", "context_instance", "(", ")", ";", "$", "persistent", "->", "set", "(", "'contextid'", ",", "$", "context", "->", "id", ")", ";", "}", "$", "purposes", "=", "[", "]", ";", "foreach", "(", "api", "::", "get_purposes", "(", ")", "as", "$", "purpose", ")", "{", "$", "purposes", "[", "$", "purpose", "->", "get", "(", "'id'", ")", "]", "=", "$", "purpose", ";", "}", "$", "purposeoptions", "=", "\\", "tool_dataprivacy", "\\", "output", "\\", "data_registry_page", "::", "purpose_options", "(", "$", "purposes", ")", ";", "$", "categoryoptions", "=", "\\", "tool_dataprivacy", "\\", "output", "\\", "data_registry_page", "::", "category_options", "(", "api", "::", "get_categories", "(", ")", ")", ";", "$", "customdata", "=", "[", "'context'", "=>", "$", "context", ",", "'subjectscope'", "=>", "data_registry", "::", "get_subject_scope", "(", "$", "context", ")", ",", "'contextname'", "=>", "$", "context", "->", "get_context_name", "(", ")", ",", "'persistent'", "=>", "$", "persistent", ",", "'purposes'", "=>", "$", "purposeoptions", ",", "'categories'", "=>", "$", "categoryoptions", ",", "]", ";", "$", "effectivepurpose", "=", "api", "::", "get_effective_context_purpose", "(", "$", "context", ")", ";", "if", "(", "$", "effectivepurpose", ")", "{", "$", "customdata", "[", "'currentretentionperiod'", "]", "=", "self", "::", "get_retention_display_text", "(", "$", "effectivepurpose", ",", "$", "context", "->", "contextlevel", ",", "$", "context", ")", ";", "$", "customdata", "[", "'purposeretentionperiods'", "]", "=", "[", "]", ";", "foreach", "(", "array_keys", "(", "$", "purposeoptions", ")", "as", "$", "optionvalue", ")", "{", "if", "(", "isset", "(", "$", "purposes", "[", "$", "optionvalue", "]", ")", ")", "{", "$", "purpose", "=", "$", "purposes", "[", "$", "optionvalue", "]", ";", "}", "else", "{", "// Get the effective purpose if $optionvalue would be the selected value.", "$", "purpose", "=", "api", "::", "get_effective_context_purpose", "(", "$", "context", ",", "$", "optionvalue", ")", ";", "}", "$", "retentionperiod", "=", "self", "::", "get_retention_display_text", "(", "$", "purpose", ",", "$", "context", "->", "contextlevel", ",", "$", "context", ")", ";", "$", "customdata", "[", "'purposeretentionperiods'", "]", "[", "$", "optionvalue", "]", "=", "$", "retentionperiod", ";", "}", "}", "return", "$", "customdata", ";", "}" ]
Returns the customdata array for the provided context instance. @param \context $context @return array
[ "Returns", "the", "customdata", "array", "for", "the", "provided", "context", "instance", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/form/context_instance.php#L140-L190
216,149
moodle/moodle
admin/tool/dataprivacy/classes/form/context_instance.php
context_instance.get_retention_display_text
protected static function get_retention_display_text(purpose $effectivepurpose, $retentioncontextlevel, \context $context) { global $PAGE; $renderer = $PAGE->get_renderer('tool_dataprivacy'); $exporter = new \tool_dataprivacy\external\purpose_exporter($effectivepurpose, ['context' => $context]); $exportedpurpose = $exporter->export($renderer); switch ($retentioncontextlevel) { case CONTEXT_COURSE: case CONTEXT_MODULE: case CONTEXT_BLOCK: $str = get_string('effectiveretentionperiodcourse', 'tool_dataprivacy', $exportedpurpose->formattedretentionperiod); break; case CONTEXT_USER: $str = get_string('effectiveretentionperioduser', 'tool_dataprivacy', $exportedpurpose->formattedretentionperiod); break; default: $str = $exportedpurpose->formattedretentionperiod; } return $str; }
php
protected static function get_retention_display_text(purpose $effectivepurpose, $retentioncontextlevel, \context $context) { global $PAGE; $renderer = $PAGE->get_renderer('tool_dataprivacy'); $exporter = new \tool_dataprivacy\external\purpose_exporter($effectivepurpose, ['context' => $context]); $exportedpurpose = $exporter->export($renderer); switch ($retentioncontextlevel) { case CONTEXT_COURSE: case CONTEXT_MODULE: case CONTEXT_BLOCK: $str = get_string('effectiveretentionperiodcourse', 'tool_dataprivacy', $exportedpurpose->formattedretentionperiod); break; case CONTEXT_USER: $str = get_string('effectiveretentionperioduser', 'tool_dataprivacy', $exportedpurpose->formattedretentionperiod); break; default: $str = $exportedpurpose->formattedretentionperiod; } return $str; }
[ "protected", "static", "function", "get_retention_display_text", "(", "purpose", "$", "effectivepurpose", ",", "$", "retentioncontextlevel", ",", "\\", "context", "$", "context", ")", "{", "global", "$", "PAGE", ";", "$", "renderer", "=", "$", "PAGE", "->", "get_renderer", "(", "'tool_dataprivacy'", ")", ";", "$", "exporter", "=", "new", "\\", "tool_dataprivacy", "\\", "external", "\\", "purpose_exporter", "(", "$", "effectivepurpose", ",", "[", "'context'", "=>", "$", "context", "]", ")", ";", "$", "exportedpurpose", "=", "$", "exporter", "->", "export", "(", "$", "renderer", ")", ";", "switch", "(", "$", "retentioncontextlevel", ")", "{", "case", "CONTEXT_COURSE", ":", "case", "CONTEXT_MODULE", ":", "case", "CONTEXT_BLOCK", ":", "$", "str", "=", "get_string", "(", "'effectiveretentionperiodcourse'", ",", "'tool_dataprivacy'", ",", "$", "exportedpurpose", "->", "formattedretentionperiod", ")", ";", "break", ";", "case", "CONTEXT_USER", ":", "$", "str", "=", "get_string", "(", "'effectiveretentionperioduser'", ",", "'tool_dataprivacy'", ",", "$", "exportedpurpose", "->", "formattedretentionperiod", ")", ";", "break", ";", "default", ":", "$", "str", "=", "$", "exportedpurpose", "->", "formattedretentionperiod", ";", "}", "return", "$", "str", ";", "}" ]
Returns the purpose display text. @param purpose $effectivepurpose @param int $retentioncontextlevel @param \context $context The context, just for displaying (filters) purposes. @return string
[ "Returns", "the", "purpose", "display", "text", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/dataprivacy/classes/form/context_instance.php#L200-L224
216,150
moodle/moodle
course/format/formatlegacy.php
format_legacy.supports_ajax
public function supports_ajax() { // set up default values $ajaxsupport = parent::supports_ajax(); // get the information from the course format library $featurefunction = 'callback_'.$this->format.'_ajax_support'; if (function_exists($featurefunction)) { $formatsupport = $featurefunction(); if (isset($formatsupport->capable)) { $ajaxsupport->capable = $formatsupport->capable; } } return $ajaxsupport; }
php
public function supports_ajax() { // set up default values $ajaxsupport = parent::supports_ajax(); // get the information from the course format library $featurefunction = 'callback_'.$this->format.'_ajax_support'; if (function_exists($featurefunction)) { $formatsupport = $featurefunction(); if (isset($formatsupport->capable)) { $ajaxsupport->capable = $formatsupport->capable; } } return $ajaxsupport; }
[ "public", "function", "supports_ajax", "(", ")", "{", "// set up default values", "$", "ajaxsupport", "=", "parent", "::", "supports_ajax", "(", ")", ";", "// get the information from the course format library", "$", "featurefunction", "=", "'callback_'", ".", "$", "this", "->", "format", ".", "'_ajax_support'", ";", "if", "(", "function_exists", "(", "$", "featurefunction", ")", ")", "{", "$", "formatsupport", "=", "$", "featurefunction", "(", ")", ";", "if", "(", "isset", "(", "$", "formatsupport", "->", "capable", ")", ")", "{", "$", "ajaxsupport", "->", "capable", "=", "$", "formatsupport", "->", "capable", ";", "}", "}", "return", "$", "ajaxsupport", ";", "}" ]
Returns the information about the ajax support in the given source format This function calls function callback_FORMATNAME_ajax_support() if it exists The returned object's property (boolean)capable indicates that the course format supports Moodle course ajax features. @return stdClass
[ "Returns", "the", "information", "about", "the", "ajax", "support", "in", "the", "given", "source", "format" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/formatlegacy.php#L153-L166
216,151
moodle/moodle
message/externallib.php
core_message_external.send_messages_to_conversation
public static function send_messages_to_conversation(int $conversationid, array $messages = []) { global $CFG, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } // Ensure the current user is allowed to run this function. $context = context_system::instance(); self::validate_context($context); $params = self::validate_parameters(self::send_messages_to_conversation_parameters(), [ 'conversationid' => $conversationid, 'messages' => $messages ]); $messages = []; foreach ($params['messages'] as $message) { $createdmessage = \core_message\api::send_message_to_conversation($USER->id, $params['conversationid'], $message['text'], $message['textformat']); $createdmessage->text = message_format_message_text((object) [ 'smallmessage' => $createdmessage->text, 'fullmessageformat' => external_validate_format($message['textformat']), 'fullmessagetrust' => $createdmessage->fullmessagetrust ]); $messages[] = $createdmessage; } return $messages; }
php
public static function send_messages_to_conversation(int $conversationid, array $messages = []) { global $CFG, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } // Ensure the current user is allowed to run this function. $context = context_system::instance(); self::validate_context($context); $params = self::validate_parameters(self::send_messages_to_conversation_parameters(), [ 'conversationid' => $conversationid, 'messages' => $messages ]); $messages = []; foreach ($params['messages'] as $message) { $createdmessage = \core_message\api::send_message_to_conversation($USER->id, $params['conversationid'], $message['text'], $message['textformat']); $createdmessage->text = message_format_message_text((object) [ 'smallmessage' => $createdmessage->text, 'fullmessageformat' => external_validate_format($message['textformat']), 'fullmessagetrust' => $createdmessage->fullmessagetrust ]); $messages[] = $createdmessage; } return $messages; }
[ "public", "static", "function", "send_messages_to_conversation", "(", "int", "$", "conversationid", ",", "array", "$", "messages", "=", "[", "]", ")", "{", "global", "$", "CFG", ",", "$", "USER", ";", "// Check if messaging is enabled.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "// Ensure the current user is allowed to run this function.", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "send_messages_to_conversation_parameters", "(", ")", ",", "[", "'conversationid'", "=>", "$", "conversationid", ",", "'messages'", "=>", "$", "messages", "]", ")", ";", "$", "messages", "=", "[", "]", ";", "foreach", "(", "$", "params", "[", "'messages'", "]", "as", "$", "message", ")", "{", "$", "createdmessage", "=", "\\", "core_message", "\\", "api", "::", "send_message_to_conversation", "(", "$", "USER", "->", "id", ",", "$", "params", "[", "'conversationid'", "]", ",", "$", "message", "[", "'text'", "]", ",", "$", "message", "[", "'textformat'", "]", ")", ";", "$", "createdmessage", "->", "text", "=", "message_format_message_text", "(", "(", "object", ")", "[", "'smallmessage'", "=>", "$", "createdmessage", "->", "text", ",", "'fullmessageformat'", "=>", "external_validate_format", "(", "$", "message", "[", "'textformat'", "]", ")", ",", "'fullmessagetrust'", "=>", "$", "createdmessage", "->", "fullmessagetrust", "]", ")", ";", "$", "messages", "[", "]", "=", "$", "createdmessage", ";", "}", "return", "$", "messages", ";", "}" ]
Send messages from the current USER to a conversation. This conversation may be any type of conversation, individual or group. @param int $conversationid the id of the conversation to which the messages will be sent. @param array $messages An array of message to send. @return array the array of messages which were sent (created). @since Moodle 3.6
[ "Send", "messages", "from", "the", "current", "USER", "to", "a", "conversation", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L74-L104
216,152
moodle/moodle
message/externallib.php
core_message_external.create_contacts
public static function create_contacts($userids, $userid = 0) { global $CFG, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } if (empty($userid)) { $userid = $USER->id; } // Validate context. $context = context_system::instance(); self::validate_context($context); $params = array('userids' => $userids, 'userid' => $userid); $params = self::validate_parameters(self::create_contacts_parameters(), $params); $capability = 'moodle/site:manageallmessaging'; if (($USER->id != $params['userid']) && !has_capability($capability, $context)) { throw new required_capability_exception($context, $capability, 'nopermissions', ''); } $warnings = array(); foreach ($params['userids'] as $id) { if (!message_add_contact($id, 0, $params['userid'])) { $warnings[] = array( 'item' => 'user', 'itemid' => $id, 'warningcode' => 'contactnotcreated', 'message' => 'The contact could not be created' ); } } return $warnings; }
php
public static function create_contacts($userids, $userid = 0) { global $CFG, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } if (empty($userid)) { $userid = $USER->id; } // Validate context. $context = context_system::instance(); self::validate_context($context); $params = array('userids' => $userids, 'userid' => $userid); $params = self::validate_parameters(self::create_contacts_parameters(), $params); $capability = 'moodle/site:manageallmessaging'; if (($USER->id != $params['userid']) && !has_capability($capability, $context)) { throw new required_capability_exception($context, $capability, 'nopermissions', ''); } $warnings = array(); foreach ($params['userids'] as $id) { if (!message_add_contact($id, 0, $params['userid'])) { $warnings[] = array( 'item' => 'user', 'itemid' => $id, 'warningcode' => 'contactnotcreated', 'message' => 'The contact could not be created' ); } } return $warnings; }
[ "public", "static", "function", "create_contacts", "(", "$", "userids", ",", "$", "userid", "=", "0", ")", "{", "global", "$", "CFG", ",", "$", "USER", ";", "// Check if messaging is enabled.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "if", "(", "empty", "(", "$", "userid", ")", ")", "{", "$", "userid", "=", "$", "USER", "->", "id", ";", "}", "// Validate context.", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "params", "=", "array", "(", "'userids'", "=>", "$", "userids", ",", "'userid'", "=>", "$", "userid", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "create_contacts_parameters", "(", ")", ",", "$", "params", ")", ";", "$", "capability", "=", "'moodle/site:manageallmessaging'", ";", "if", "(", "(", "$", "USER", "->", "id", "!=", "$", "params", "[", "'userid'", "]", ")", "&&", "!", "has_capability", "(", "$", "capability", ",", "$", "context", ")", ")", "{", "throw", "new", "required_capability_exception", "(", "$", "context", ",", "$", "capability", ",", "'nopermissions'", ",", "''", ")", ";", "}", "$", "warnings", "=", "array", "(", ")", ";", "foreach", "(", "$", "params", "[", "'userids'", "]", "as", "$", "id", ")", "{", "if", "(", "!", "message_add_contact", "(", "$", "id", ",", "0", ",", "$", "params", "[", "'userid'", "]", ")", ")", "{", "$", "warnings", "[", "]", "=", "array", "(", "'item'", "=>", "'user'", ",", "'itemid'", "=>", "$", "id", ",", "'warningcode'", "=>", "'contactnotcreated'", ",", "'message'", "=>", "'The contact could not be created'", ")", ";", "}", "}", "return", "$", "warnings", ";", "}" ]
Create contacts. @deprecated since Moodle 3.6 @param array $userids array of user IDs. @param int $userid The id of the user we are creating the contacts for @return external_description @since Moodle 2.5
[ "Create", "contacts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L294-L330
216,153
moodle/moodle
message/externallib.php
core_message_external.delete_contacts
public static function delete_contacts($userids, $userid = 0) { global $CFG, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } if (empty($userid)) { $userid = $USER->id; } // Validate context. $context = context_system::instance(); self::validate_context($context); $params = array('userids' => $userids, 'userid' => $userid); $params = self::validate_parameters(self::delete_contacts_parameters(), $params); $capability = 'moodle/site:manageallmessaging'; if (($USER->id != $params['userid']) && !has_capability($capability, $context)) { throw new required_capability_exception($context, $capability, 'nopermissions', ''); } foreach ($params['userids'] as $id) { \core_message\api::remove_contact($params['userid'], $id); } return null; }
php
public static function delete_contacts($userids, $userid = 0) { global $CFG, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } if (empty($userid)) { $userid = $USER->id; } // Validate context. $context = context_system::instance(); self::validate_context($context); $params = array('userids' => $userids, 'userid' => $userid); $params = self::validate_parameters(self::delete_contacts_parameters(), $params); $capability = 'moodle/site:manageallmessaging'; if (($USER->id != $params['userid']) && !has_capability($capability, $context)) { throw new required_capability_exception($context, $capability, 'nopermissions', ''); } foreach ($params['userids'] as $id) { \core_message\api::remove_contact($params['userid'], $id); } return null; }
[ "public", "static", "function", "delete_contacts", "(", "$", "userids", ",", "$", "userid", "=", "0", ")", "{", "global", "$", "CFG", ",", "$", "USER", ";", "// Check if messaging is enabled.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "if", "(", "empty", "(", "$", "userid", ")", ")", "{", "$", "userid", "=", "$", "USER", "->", "id", ";", "}", "// Validate context.", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "params", "=", "array", "(", "'userids'", "=>", "$", "userids", ",", "'userid'", "=>", "$", "userid", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "delete_contacts_parameters", "(", ")", ",", "$", "params", ")", ";", "$", "capability", "=", "'moodle/site:manageallmessaging'", ";", "if", "(", "(", "$", "USER", "->", "id", "!=", "$", "params", "[", "'userid'", "]", ")", "&&", "!", "has_capability", "(", "$", "capability", ",", "$", "context", ")", ")", "{", "throw", "new", "required_capability_exception", "(", "$", "context", ",", "$", "capability", ",", "'nopermissions'", ",", "''", ")", ";", "}", "foreach", "(", "$", "params", "[", "'userids'", "]", "as", "$", "id", ")", "{", "\\", "core_message", "\\", "api", "::", "remove_contact", "(", "$", "params", "[", "'userid'", "]", ",", "$", "id", ")", ";", "}", "return", "null", ";", "}" ]
Delete contacts. @param array $userids array of user IDs. @param int $userid The id of the user we are deleting the contacts for @return null @since Moodle 2.5
[ "Delete", "contacts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L379-L408
216,154
moodle/moodle
message/externallib.php
core_message_external.mute_conversations
public static function mute_conversations(int $userid, array $conversationids) { global $CFG, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } // Validate context. $context = context_system::instance(); self::validate_context($context); $params = ['userid' => $userid, 'conversationids' => $conversationids]; $params = self::validate_parameters(self::mute_conversations_parameters(), $params); $capability = 'moodle/site:manageallmessaging'; if (($USER->id != $params['userid']) && !has_capability($capability, $context)) { throw new required_capability_exception($context, $capability, 'nopermissions', ''); } foreach ($params['conversationids'] as $conversationid) { if (!\core_message\api::is_conversation_muted($params['userid'], $conversationid)) { \core_message\api::mute_conversation($params['userid'], $conversationid); } } return []; }
php
public static function mute_conversations(int $userid, array $conversationids) { global $CFG, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } // Validate context. $context = context_system::instance(); self::validate_context($context); $params = ['userid' => $userid, 'conversationids' => $conversationids]; $params = self::validate_parameters(self::mute_conversations_parameters(), $params); $capability = 'moodle/site:manageallmessaging'; if (($USER->id != $params['userid']) && !has_capability($capability, $context)) { throw new required_capability_exception($context, $capability, 'nopermissions', ''); } foreach ($params['conversationids'] as $conversationid) { if (!\core_message\api::is_conversation_muted($params['userid'], $conversationid)) { \core_message\api::mute_conversation($params['userid'], $conversationid); } } return []; }
[ "public", "static", "function", "mute_conversations", "(", "int", "$", "userid", ",", "array", "$", "conversationids", ")", "{", "global", "$", "CFG", ",", "$", "USER", ";", "// Check if messaging is enabled.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "// Validate context.", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "params", "=", "[", "'userid'", "=>", "$", "userid", ",", "'conversationids'", "=>", "$", "conversationids", "]", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "mute_conversations_parameters", "(", ")", ",", "$", "params", ")", ";", "$", "capability", "=", "'moodle/site:manageallmessaging'", ";", "if", "(", "(", "$", "USER", "->", "id", "!=", "$", "params", "[", "'userid'", "]", ")", "&&", "!", "has_capability", "(", "$", "capability", ",", "$", "context", ")", ")", "{", "throw", "new", "required_capability_exception", "(", "$", "context", ",", "$", "capability", ",", "'nopermissions'", ",", "''", ")", ";", "}", "foreach", "(", "$", "params", "[", "'conversationids'", "]", "as", "$", "conversationid", ")", "{", "if", "(", "!", "\\", "core_message", "\\", "api", "::", "is_conversation_muted", "(", "$", "params", "[", "'userid'", "]", ",", "$", "conversationid", ")", ")", "{", "\\", "core_message", "\\", "api", "::", "mute_conversation", "(", "$", "params", "[", "'userid'", "]", ",", "$", "conversationid", ")", ";", "}", "}", "return", "[", "]", ";", "}" ]
Mutes conversations. @param int $userid The id of the user who is blocking @param array $conversationids The list of conversations being muted @return external_description
[ "Mutes", "conversations", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L443-L470
216,155
moodle/moodle
message/externallib.php
core_message_external.unmute_conversations
public static function unmute_conversations(int $userid, array $conversationids) { global $CFG, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } // Validate context. $context = context_system::instance(); self::validate_context($context); $params = ['userid' => $userid, 'conversationids' => $conversationids]; $params = self::validate_parameters(self::unmute_conversations_parameters(), $params); $capability = 'moodle/site:manageallmessaging'; if (($USER->id != $params['userid']) && !has_capability($capability, $context)) { throw new required_capability_exception($context, $capability, 'nopermissions', ''); } foreach ($params['conversationids'] as $conversationid) { \core_message\api::unmute_conversation($params['userid'], $conversationid); } return []; }
php
public static function unmute_conversations(int $userid, array $conversationids) { global $CFG, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } // Validate context. $context = context_system::instance(); self::validate_context($context); $params = ['userid' => $userid, 'conversationids' => $conversationids]; $params = self::validate_parameters(self::unmute_conversations_parameters(), $params); $capability = 'moodle/site:manageallmessaging'; if (($USER->id != $params['userid']) && !has_capability($capability, $context)) { throw new required_capability_exception($context, $capability, 'nopermissions', ''); } foreach ($params['conversationids'] as $conversationid) { \core_message\api::unmute_conversation($params['userid'], $conversationid); } return []; }
[ "public", "static", "function", "unmute_conversations", "(", "int", "$", "userid", ",", "array", "$", "conversationids", ")", "{", "global", "$", "CFG", ",", "$", "USER", ";", "// Check if messaging is enabled.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "// Validate context.", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "params", "=", "[", "'userid'", "=>", "$", "userid", ",", "'conversationids'", "=>", "$", "conversationids", "]", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "unmute_conversations_parameters", "(", ")", ",", "$", "params", ")", ";", "$", "capability", "=", "'moodle/site:manageallmessaging'", ";", "if", "(", "(", "$", "USER", "->", "id", "!=", "$", "params", "[", "'userid'", "]", ")", "&&", "!", "has_capability", "(", "$", "capability", ",", "$", "context", ")", ")", "{", "throw", "new", "required_capability_exception", "(", "$", "context", ",", "$", "capability", ",", "'nopermissions'", ",", "''", ")", ";", "}", "foreach", "(", "$", "params", "[", "'conversationids'", "]", "as", "$", "conversationid", ")", "{", "\\", "core_message", "\\", "api", "::", "unmute_conversation", "(", "$", "params", "[", "'userid'", "]", ",", "$", "conversationid", ")", ";", "}", "return", "[", "]", ";", "}" ]
Unmute conversations. @param int $userid The id of the user who is unblocking @param array $conversationids The list of conversations being muted
[ "Unmute", "conversations", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L503-L528
216,156
moodle/moodle
message/externallib.php
core_message_external.block_contacts
public static function block_contacts($userids, $userid = 0) { global $CFG, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } if (empty($userid)) { $userid = $USER->id; } // Validate context. $context = context_system::instance(); self::validate_context($context); $params = array('userids' => $userids, 'userid' => $userid); $params = self::validate_parameters(self::block_contacts_parameters(), $params); $capability = 'moodle/site:manageallmessaging'; if (($USER->id != $params['userid']) && !has_capability($capability, $context)) { throw new required_capability_exception($context, $capability, 'nopermissions', ''); } $warnings = array(); foreach ($params['userids'] as $id) { if (!message_block_contact($id, $params['userid'])) { $warnings[] = array( 'item' => 'user', 'itemid' => $id, 'warningcode' => 'contactnotblocked', 'message' => 'The contact could not be blocked' ); } } return $warnings; }
php
public static function block_contacts($userids, $userid = 0) { global $CFG, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } if (empty($userid)) { $userid = $USER->id; } // Validate context. $context = context_system::instance(); self::validate_context($context); $params = array('userids' => $userids, 'userid' => $userid); $params = self::validate_parameters(self::block_contacts_parameters(), $params); $capability = 'moodle/site:manageallmessaging'; if (($USER->id != $params['userid']) && !has_capability($capability, $context)) { throw new required_capability_exception($context, $capability, 'nopermissions', ''); } $warnings = array(); foreach ($params['userids'] as $id) { if (!message_block_contact($id, $params['userid'])) { $warnings[] = array( 'item' => 'user', 'itemid' => $id, 'warningcode' => 'contactnotblocked', 'message' => 'The contact could not be blocked' ); } } return $warnings; }
[ "public", "static", "function", "block_contacts", "(", "$", "userids", ",", "$", "userid", "=", "0", ")", "{", "global", "$", "CFG", ",", "$", "USER", ";", "// Check if messaging is enabled.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "if", "(", "empty", "(", "$", "userid", ")", ")", "{", "$", "userid", "=", "$", "USER", "->", "id", ";", "}", "// Validate context.", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "params", "=", "array", "(", "'userids'", "=>", "$", "userids", ",", "'userid'", "=>", "$", "userid", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "block_contacts_parameters", "(", ")", ",", "$", "params", ")", ";", "$", "capability", "=", "'moodle/site:manageallmessaging'", ";", "if", "(", "(", "$", "USER", "->", "id", "!=", "$", "params", "[", "'userid'", "]", ")", "&&", "!", "has_capability", "(", "$", "capability", ",", "$", "context", ")", ")", "{", "throw", "new", "required_capability_exception", "(", "$", "context", ",", "$", "capability", ",", "'nopermissions'", ",", "''", ")", ";", "}", "$", "warnings", "=", "array", "(", ")", ";", "foreach", "(", "$", "params", "[", "'userids'", "]", "as", "$", "id", ")", "{", "if", "(", "!", "message_block_contact", "(", "$", "id", ",", "$", "params", "[", "'userid'", "]", ")", ")", "{", "$", "warnings", "[", "]", "=", "array", "(", "'item'", "=>", "'user'", ",", "'itemid'", "=>", "$", "id", ",", "'warningcode'", "=>", "'contactnotblocked'", ",", "'message'", "=>", "'The contact could not be blocked'", ")", ";", "}", "}", "return", "$", "warnings", ";", "}" ]
Block contacts. @deprecated since Moodle 3.6 @param array $userids array of user IDs. @param int $userid The id of the user we are blocking the contacts for @return external_description @since Moodle 2.5
[ "Block", "contacts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L679-L715
216,157
moodle/moodle
message/externallib.php
core_message_external.unblock_contacts
public static function unblock_contacts($userids, $userid = 0) { global $CFG, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } if (empty($userid)) { $userid = $USER->id; } // Validate context. $context = context_system::instance(); self::validate_context($context); $params = array('userids' => $userids, 'userid' => $userid); $params = self::validate_parameters(self::unblock_contacts_parameters(), $params); $capability = 'moodle/site:manageallmessaging'; if (($USER->id != $params['userid']) && !has_capability($capability, $context)) { throw new required_capability_exception($context, $capability, 'nopermissions', ''); } foreach ($params['userids'] as $id) { message_unblock_contact($id, $params['userid']); } return null; }
php
public static function unblock_contacts($userids, $userid = 0) { global $CFG, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } if (empty($userid)) { $userid = $USER->id; } // Validate context. $context = context_system::instance(); self::validate_context($context); $params = array('userids' => $userids, 'userid' => $userid); $params = self::validate_parameters(self::unblock_contacts_parameters(), $params); $capability = 'moodle/site:manageallmessaging'; if (($USER->id != $params['userid']) && !has_capability($capability, $context)) { throw new required_capability_exception($context, $capability, 'nopermissions', ''); } foreach ($params['userids'] as $id) { message_unblock_contact($id, $params['userid']); } return null; }
[ "public", "static", "function", "unblock_contacts", "(", "$", "userids", ",", "$", "userid", "=", "0", ")", "{", "global", "$", "CFG", ",", "$", "USER", ";", "// Check if messaging is enabled.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "if", "(", "empty", "(", "$", "userid", ")", ")", "{", "$", "userid", "=", "$", "USER", "->", "id", ";", "}", "// Validate context.", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "params", "=", "array", "(", "'userids'", "=>", "$", "userids", ",", "'userid'", "=>", "$", "userid", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "unblock_contacts_parameters", "(", ")", ",", "$", "params", ")", ";", "$", "capability", "=", "'moodle/site:manageallmessaging'", ";", "if", "(", "(", "$", "USER", "->", "id", "!=", "$", "params", "[", "'userid'", "]", ")", "&&", "!", "has_capability", "(", "$", "capability", ",", "$", "context", ")", ")", "{", "throw", "new", "required_capability_exception", "(", "$", "context", ",", "$", "capability", ",", "'nopermissions'", ",", "''", ")", ";", "}", "foreach", "(", "$", "params", "[", "'userids'", "]", "as", "$", "id", ")", "{", "message_unblock_contact", "(", "$", "id", ",", "$", "params", "[", "'userid'", "]", ")", ";", "}", "return", "null", ";", "}" ]
Unblock contacts. @param array $userids array of user IDs. @param int $userid The id of the user we are unblocking the contacts for @return null @since Moodle 2.5
[ "Unblock", "contacts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L765-L794
216,158
moodle/moodle
message/externallib.php
core_message_external.get_contact_requests_parameters
public static function get_contact_requests_parameters() { return new external_function_parameters( [ 'userid' => new external_value(PARAM_INT, 'The id of the user we want the requests for'), 'limitfrom' => new external_value(PARAM_INT, 'Limit from', VALUE_DEFAULT, 0), 'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0) ] ); }
php
public static function get_contact_requests_parameters() { return new external_function_parameters( [ 'userid' => new external_value(PARAM_INT, 'The id of the user we want the requests for'), 'limitfrom' => new external_value(PARAM_INT, 'Limit from', VALUE_DEFAULT, 0), 'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0) ] ); }
[ "public", "static", "function", "get_contact_requests_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "[", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The id of the user we want the requests for'", ")", ",", "'limitfrom'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Limit from'", ",", "VALUE_DEFAULT", ",", "0", ")", ",", "'limitnum'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Limit number'", ",", "VALUE_DEFAULT", ",", "0", ")", "]", ")", ";", "}" ]
Returns contact requests parameters description. @return external_function_parameters
[ "Returns", "contact", "requests", "parameters", "description", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L821-L829
216,159
moodle/moodle
message/externallib.php
core_message_external.get_conversation_members_parameters
public static function get_conversation_members_parameters() { return new external_function_parameters( [ 'userid' => new external_value(PARAM_INT, 'The id of the user we are performing this action on behalf of'), 'conversationid' => new external_value(PARAM_INT, 'The id of the conversation'), 'includecontactrequests' => new external_value(PARAM_BOOL, 'Do we want to include contact requests?', VALUE_DEFAULT, false), 'includeprivacyinfo' => new external_value(PARAM_BOOL, 'Do we want to include privacy info?', VALUE_DEFAULT, false), 'limitfrom' => new external_value(PARAM_INT, 'Limit from', VALUE_DEFAULT, 0), 'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0) ] ); }
php
public static function get_conversation_members_parameters() { return new external_function_parameters( [ 'userid' => new external_value(PARAM_INT, 'The id of the user we are performing this action on behalf of'), 'conversationid' => new external_value(PARAM_INT, 'The id of the conversation'), 'includecontactrequests' => new external_value(PARAM_BOOL, 'Do we want to include contact requests?', VALUE_DEFAULT, false), 'includeprivacyinfo' => new external_value(PARAM_BOOL, 'Do we want to include privacy info?', VALUE_DEFAULT, false), 'limitfrom' => new external_value(PARAM_INT, 'Limit from', VALUE_DEFAULT, 0), 'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0) ] ); }
[ "public", "static", "function", "get_conversation_members_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "[", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The id of the user we are performing this action on behalf of'", ")", ",", "'conversationid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The id of the conversation'", ")", ",", "'includecontactrequests'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Do we want to include contact requests?'", ",", "VALUE_DEFAULT", ",", "false", ")", ",", "'includeprivacyinfo'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Do we want to include privacy info?'", ",", "VALUE_DEFAULT", ",", "false", ")", ",", "'limitfrom'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Limit from'", ",", "VALUE_DEFAULT", ",", "0", ")", ",", "'limitnum'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Limit number'", ",", "VALUE_DEFAULT", ",", "0", ")", "]", ")", ";", "}" ]
Returns get conversation members parameters description. @return external_function_parameters
[ "Returns", "get", "conversation", "members", "parameters", "description", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L940-L953
216,160
moodle/moodle
message/externallib.php
core_message_external.create_contact_request
public static function create_contact_request(int $userid, int $requesteduserid) { global $CFG, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } // Validate context. $context = context_system::instance(); self::validate_context($context); $params = ['userid' => $userid, 'requesteduserid' => $requesteduserid]; $params = self::validate_parameters(self::create_contact_request_parameters(), $params); $capability = 'moodle/site:manageallmessaging'; if (($USER->id != $params['userid']) && !has_capability($capability, $context)) { throw new required_capability_exception($context, $capability, 'nopermissions', ''); } $result = [ 'warnings' => [] ]; if (!\core_message\api::can_create_contact($params['userid'], $params['requesteduserid'])) { $result['warnings'][] = [ 'item' => 'user', 'itemid' => $params['requesteduserid'], 'warningcode' => 'cannotcreatecontactrequest', 'message' => 'You are unable to create a contact request for this user' ]; } else { if ($requests = \core_message\api::get_contact_requests_between_users($params['userid'], $params['requesteduserid'])) { // There should only ever be one but just in case there are multiple then we can return the first. $result['request'] = array_shift($requests); } else { $result['request'] = \core_message\api::create_contact_request($params['userid'], $params['requesteduserid']); } } return $result; }
php
public static function create_contact_request(int $userid, int $requesteduserid) { global $CFG, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } // Validate context. $context = context_system::instance(); self::validate_context($context); $params = ['userid' => $userid, 'requesteduserid' => $requesteduserid]; $params = self::validate_parameters(self::create_contact_request_parameters(), $params); $capability = 'moodle/site:manageallmessaging'; if (($USER->id != $params['userid']) && !has_capability($capability, $context)) { throw new required_capability_exception($context, $capability, 'nopermissions', ''); } $result = [ 'warnings' => [] ]; if (!\core_message\api::can_create_contact($params['userid'], $params['requesteduserid'])) { $result['warnings'][] = [ 'item' => 'user', 'itemid' => $params['requesteduserid'], 'warningcode' => 'cannotcreatecontactrequest', 'message' => 'You are unable to create a contact request for this user' ]; } else { if ($requests = \core_message\api::get_contact_requests_between_users($params['userid'], $params['requesteduserid'])) { // There should only ever be one but just in case there are multiple then we can return the first. $result['request'] = array_shift($requests); } else { $result['request'] = \core_message\api::create_contact_request($params['userid'], $params['requesteduserid']); } } return $result; }
[ "public", "static", "function", "create_contact_request", "(", "int", "$", "userid", ",", "int", "$", "requesteduserid", ")", "{", "global", "$", "CFG", ",", "$", "USER", ";", "// Check if messaging is enabled.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "// Validate context.", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "params", "=", "[", "'userid'", "=>", "$", "userid", ",", "'requesteduserid'", "=>", "$", "requesteduserid", "]", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "create_contact_request_parameters", "(", ")", ",", "$", "params", ")", ";", "$", "capability", "=", "'moodle/site:manageallmessaging'", ";", "if", "(", "(", "$", "USER", "->", "id", "!=", "$", "params", "[", "'userid'", "]", ")", "&&", "!", "has_capability", "(", "$", "capability", ",", "$", "context", ")", ")", "{", "throw", "new", "required_capability_exception", "(", "$", "context", ",", "$", "capability", ",", "'nopermissions'", ",", "''", ")", ";", "}", "$", "result", "=", "[", "'warnings'", "=>", "[", "]", "]", ";", "if", "(", "!", "\\", "core_message", "\\", "api", "::", "can_create_contact", "(", "$", "params", "[", "'userid'", "]", ",", "$", "params", "[", "'requesteduserid'", "]", ")", ")", "{", "$", "result", "[", "'warnings'", "]", "[", "]", "=", "[", "'item'", "=>", "'user'", ",", "'itemid'", "=>", "$", "params", "[", "'requesteduserid'", "]", ",", "'warningcode'", "=>", "'cannotcreatecontactrequest'", ",", "'message'", "=>", "'You are unable to create a contact request for this user'", "]", ";", "}", "else", "{", "if", "(", "$", "requests", "=", "\\", "core_message", "\\", "api", "::", "get_contact_requests_between_users", "(", "$", "params", "[", "'userid'", "]", ",", "$", "params", "[", "'requesteduserid'", "]", ")", ")", "{", "// There should only ever be one but just in case there are multiple then we can return the first.", "$", "result", "[", "'request'", "]", "=", "array_shift", "(", "$", "requests", ")", ";", "}", "else", "{", "$", "result", "[", "'request'", "]", "=", "\\", "core_message", "\\", "api", "::", "create_contact_request", "(", "$", "params", "[", "'userid'", "]", ",", "$", "params", "[", "'requesteduserid'", "]", ")", ";", "}", "}", "return", "$", "result", ";", "}" ]
Creates a contact request. @param int $userid The id of the user who is creating the contact request @param int $requesteduserid The id of the user being requested
[ "Creates", "a", "contact", "request", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L1034-L1075
216,161
moodle/moodle
message/externallib.php
core_message_external.create_contact_request_returns
public static function create_contact_request_returns() { return new external_single_structure( array( 'request' => new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'Message id'), 'userid' => new external_value(PARAM_INT, 'User from id'), 'requesteduserid' => new external_value(PARAM_INT, 'User to id'), 'timecreated' => new external_value(PARAM_INT, 'Time created'), ), 'request record', VALUE_OPTIONAL ), 'warnings' => new external_warnings() ) ); }
php
public static function create_contact_request_returns() { return new external_single_structure( array( 'request' => new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'Message id'), 'userid' => new external_value(PARAM_INT, 'User from id'), 'requesteduserid' => new external_value(PARAM_INT, 'User to id'), 'timecreated' => new external_value(PARAM_INT, 'Time created'), ), 'request record', VALUE_OPTIONAL ), 'warnings' => new external_warnings() ) ); }
[ "public", "static", "function", "create_contact_request_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'request'", "=>", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Message id'", ")", ",", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'User from id'", ")", ",", "'requesteduserid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'User to id'", ")", ",", "'timecreated'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Time created'", ")", ",", ")", ",", "'request record'", ",", "VALUE_OPTIONAL", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ")", ")", ";", "}" ]
Creates a contact request return description. @return external_description
[ "Creates", "a", "contact", "request", "return", "description", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L1082-L1098
216,162
moodle/moodle
message/externallib.php
core_message_external.get_messagearea_contact_structure
private static function get_messagearea_contact_structure() { return new external_single_structure( array( 'userid' => new external_value(PARAM_INT, 'The user\'s id'), 'fullname' => new external_value(PARAM_NOTAGS, 'The user\'s name'), 'profileimageurl' => new external_value(PARAM_URL, 'User picture URL'), 'profileimageurlsmall' => new external_value(PARAM_URL, 'Small user picture URL'), 'ismessaging' => new external_value(PARAM_BOOL, 'If we are messaging the user'), 'sentfromcurrentuser' => new external_value(PARAM_BOOL, 'Was the last message sent from the current user?'), 'lastmessage' => new external_value(PARAM_NOTAGS, 'The user\'s last message'), 'lastmessagedate' => new external_value(PARAM_INT, 'Timestamp for last message', VALUE_DEFAULT, null), 'messageid' => new external_value(PARAM_INT, 'The unique search message id', VALUE_DEFAULT, null), 'showonlinestatus' => new external_value(PARAM_BOOL, 'Show the user\'s online status?'), 'isonline' => new external_value(PARAM_BOOL, 'The user\'s online status'), 'isread' => new external_value(PARAM_BOOL, 'If the user has read the message'), 'isblocked' => new external_value(PARAM_BOOL, 'If the user has been blocked'), 'unreadcount' => new external_value(PARAM_INT, 'The number of unread messages in this conversation', VALUE_DEFAULT, null), 'conversationid' => new external_value(PARAM_INT, 'The id of the conversation', VALUE_DEFAULT, null), ) ); }
php
private static function get_messagearea_contact_structure() { return new external_single_structure( array( 'userid' => new external_value(PARAM_INT, 'The user\'s id'), 'fullname' => new external_value(PARAM_NOTAGS, 'The user\'s name'), 'profileimageurl' => new external_value(PARAM_URL, 'User picture URL'), 'profileimageurlsmall' => new external_value(PARAM_URL, 'Small user picture URL'), 'ismessaging' => new external_value(PARAM_BOOL, 'If we are messaging the user'), 'sentfromcurrentuser' => new external_value(PARAM_BOOL, 'Was the last message sent from the current user?'), 'lastmessage' => new external_value(PARAM_NOTAGS, 'The user\'s last message'), 'lastmessagedate' => new external_value(PARAM_INT, 'Timestamp for last message', VALUE_DEFAULT, null), 'messageid' => new external_value(PARAM_INT, 'The unique search message id', VALUE_DEFAULT, null), 'showonlinestatus' => new external_value(PARAM_BOOL, 'Show the user\'s online status?'), 'isonline' => new external_value(PARAM_BOOL, 'The user\'s online status'), 'isread' => new external_value(PARAM_BOOL, 'If the user has read the message'), 'isblocked' => new external_value(PARAM_BOOL, 'If the user has been blocked'), 'unreadcount' => new external_value(PARAM_INT, 'The number of unread messages in this conversation', VALUE_DEFAULT, null), 'conversationid' => new external_value(PARAM_INT, 'The id of the conversation', VALUE_DEFAULT, null), ) ); }
[ "private", "static", "function", "get_messagearea_contact_structure", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The user\\'s id'", ")", ",", "'fullname'", "=>", "new", "external_value", "(", "PARAM_NOTAGS", ",", "'The user\\'s name'", ")", ",", "'profileimageurl'", "=>", "new", "external_value", "(", "PARAM_URL", ",", "'User picture URL'", ")", ",", "'profileimageurlsmall'", "=>", "new", "external_value", "(", "PARAM_URL", ",", "'Small user picture URL'", ")", ",", "'ismessaging'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'If we are messaging the user'", ")", ",", "'sentfromcurrentuser'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Was the last message sent from the current user?'", ")", ",", "'lastmessage'", "=>", "new", "external_value", "(", "PARAM_NOTAGS", ",", "'The user\\'s last message'", ")", ",", "'lastmessagedate'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Timestamp for last message'", ",", "VALUE_DEFAULT", ",", "null", ")", ",", "'messageid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The unique search message id'", ",", "VALUE_DEFAULT", ",", "null", ")", ",", "'showonlinestatus'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Show the user\\'s online status?'", ")", ",", "'isonline'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'The user\\'s online status'", ")", ",", "'isread'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'If the user has read the message'", ")", ",", "'isblocked'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'If the user has been blocked'", ")", ",", "'unreadcount'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The number of unread messages in this conversation'", ",", "VALUE_DEFAULT", ",", "null", ")", ",", "'conversationid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The id of the conversation'", ",", "VALUE_DEFAULT", ",", "null", ")", ",", ")", ")", ";", "}" ]
Return the structure of a message area contact. @return external_single_structure @since Moodle 3.2
[ "Return", "the", "structure", "of", "a", "message", "area", "contact", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L1214-L1235
216,163
moodle/moodle
message/externallib.php
core_message_external.get_conversation_structure
private static function get_conversation_structure() { return new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'The conversation id'), 'name' => new external_value(PARAM_TEXT, 'The conversation name, if set', VALUE_DEFAULT, null), 'subname' => new external_value(PARAM_TEXT, 'A subtitle for the conversation name, if set', VALUE_DEFAULT, null), 'imageurl' => new external_value(PARAM_URL, 'A link to the conversation picture, if set', VALUE_DEFAULT, null), 'type' => new external_value(PARAM_INT, 'The type of the conversation (1=individual,2=group,3=self)'), 'membercount' => new external_value(PARAM_INT, 'Total number of conversation members'), 'ismuted' => new external_value(PARAM_BOOL, 'If the user muted this conversation'), 'isfavourite' => new external_value(PARAM_BOOL, 'If the user marked this conversation as a favourite'), 'isread' => new external_value(PARAM_BOOL, 'If the user has read all messages in the conversation'), 'unreadcount' => new external_value(PARAM_INT, 'The number of unread messages in this conversation', VALUE_DEFAULT, null), 'members' => new external_multiple_structure( self::get_conversation_member_structure() ), 'messages' => new external_multiple_structure( self::get_conversation_message_structure() ), ) ); }
php
private static function get_conversation_structure() { return new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'The conversation id'), 'name' => new external_value(PARAM_TEXT, 'The conversation name, if set', VALUE_DEFAULT, null), 'subname' => new external_value(PARAM_TEXT, 'A subtitle for the conversation name, if set', VALUE_DEFAULT, null), 'imageurl' => new external_value(PARAM_URL, 'A link to the conversation picture, if set', VALUE_DEFAULT, null), 'type' => new external_value(PARAM_INT, 'The type of the conversation (1=individual,2=group,3=self)'), 'membercount' => new external_value(PARAM_INT, 'Total number of conversation members'), 'ismuted' => new external_value(PARAM_BOOL, 'If the user muted this conversation'), 'isfavourite' => new external_value(PARAM_BOOL, 'If the user marked this conversation as a favourite'), 'isread' => new external_value(PARAM_BOOL, 'If the user has read all messages in the conversation'), 'unreadcount' => new external_value(PARAM_INT, 'The number of unread messages in this conversation', VALUE_DEFAULT, null), 'members' => new external_multiple_structure( self::get_conversation_member_structure() ), 'messages' => new external_multiple_structure( self::get_conversation_message_structure() ), ) ); }
[ "private", "static", "function", "get_conversation_structure", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The conversation id'", ")", ",", "'name'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'The conversation name, if set'", ",", "VALUE_DEFAULT", ",", "null", ")", ",", "'subname'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'A subtitle for the conversation name, if set'", ",", "VALUE_DEFAULT", ",", "null", ")", ",", "'imageurl'", "=>", "new", "external_value", "(", "PARAM_URL", ",", "'A link to the conversation picture, if set'", ",", "VALUE_DEFAULT", ",", "null", ")", ",", "'type'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The type of the conversation (1=individual,2=group,3=self)'", ")", ",", "'membercount'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Total number of conversation members'", ")", ",", "'ismuted'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'If the user muted this conversation'", ")", ",", "'isfavourite'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'If the user marked this conversation as a favourite'", ")", ",", "'isread'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'If the user has read all messages in the conversation'", ")", ",", "'unreadcount'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The number of unread messages in this conversation'", ",", "VALUE_DEFAULT", ",", "null", ")", ",", "'members'", "=>", "new", "external_multiple_structure", "(", "self", "::", "get_conversation_member_structure", "(", ")", ")", ",", "'messages'", "=>", "new", "external_multiple_structure", "(", "self", "::", "get_conversation_message_structure", "(", ")", ")", ",", ")", ")", ";", "}" ]
Return the structure of a conversation. @return external_single_structure @since Moodle 3.6
[ "Return", "the", "structure", "of", "a", "conversation", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L1243-L1265
216,164
moodle/moodle
message/externallib.php
core_message_external.get_conversation_member_structure
private static function get_conversation_member_structure() { $result = [ 'id' => new external_value(PARAM_INT, 'The user id'), 'fullname' => new external_value(PARAM_NOTAGS, 'The user\'s name'), 'profileurl' => new external_value(PARAM_URL, 'The link to the user\'s profile page'), 'profileimageurl' => new external_value(PARAM_URL, 'User picture URL'), 'profileimageurlsmall' => new external_value(PARAM_URL, 'Small user picture URL'), 'isonline' => new external_value(PARAM_BOOL, 'The user\'s online status'), 'showonlinestatus' => new external_value(PARAM_BOOL, 'Show the user\'s online status?'), 'isblocked' => new external_value(PARAM_BOOL, 'If the user has been blocked'), 'iscontact' => new external_value(PARAM_BOOL, 'Is the user a contact?'), 'isdeleted' => new external_value(PARAM_BOOL, 'Is the user deleted?'), 'canmessage' => new external_value(PARAM_BOOL, 'If the user can be messaged'), 'requirescontact' => new external_value(PARAM_BOOL, 'If the user requires to be contacts'), ]; $result['contactrequests'] = new external_multiple_structure( new external_single_structure( [ 'id' => new external_value(PARAM_INT, 'The id of the contact request'), 'userid' => new external_value(PARAM_INT, 'The id of the user who created the contact request'), 'requesteduserid' => new external_value(PARAM_INT, 'The id of the user confirming the request'), 'timecreated' => new external_value(PARAM_INT, 'The timecreated timestamp for the contact request'), ] ), 'The contact requests', VALUE_OPTIONAL ); $result['conversations'] = new external_multiple_structure(new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'Conversations id'), 'type' => new external_value(PARAM_INT, 'Conversation type: private or public'), 'name' => new external_value(PARAM_TEXT, 'Multilang compatible conversation name'. VALUE_OPTIONAL), 'timecreated' => new external_value(PARAM_INT, 'The timecreated timestamp for the conversation'), ), 'information about conversation', VALUE_OPTIONAL), 'Conversations between users', VALUE_OPTIONAL ); return new external_single_structure( $result ); }
php
private static function get_conversation_member_structure() { $result = [ 'id' => new external_value(PARAM_INT, 'The user id'), 'fullname' => new external_value(PARAM_NOTAGS, 'The user\'s name'), 'profileurl' => new external_value(PARAM_URL, 'The link to the user\'s profile page'), 'profileimageurl' => new external_value(PARAM_URL, 'User picture URL'), 'profileimageurlsmall' => new external_value(PARAM_URL, 'Small user picture URL'), 'isonline' => new external_value(PARAM_BOOL, 'The user\'s online status'), 'showonlinestatus' => new external_value(PARAM_BOOL, 'Show the user\'s online status?'), 'isblocked' => new external_value(PARAM_BOOL, 'If the user has been blocked'), 'iscontact' => new external_value(PARAM_BOOL, 'Is the user a contact?'), 'isdeleted' => new external_value(PARAM_BOOL, 'Is the user deleted?'), 'canmessage' => new external_value(PARAM_BOOL, 'If the user can be messaged'), 'requirescontact' => new external_value(PARAM_BOOL, 'If the user requires to be contacts'), ]; $result['contactrequests'] = new external_multiple_structure( new external_single_structure( [ 'id' => new external_value(PARAM_INT, 'The id of the contact request'), 'userid' => new external_value(PARAM_INT, 'The id of the user who created the contact request'), 'requesteduserid' => new external_value(PARAM_INT, 'The id of the user confirming the request'), 'timecreated' => new external_value(PARAM_INT, 'The timecreated timestamp for the contact request'), ] ), 'The contact requests', VALUE_OPTIONAL ); $result['conversations'] = new external_multiple_structure(new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'Conversations id'), 'type' => new external_value(PARAM_INT, 'Conversation type: private or public'), 'name' => new external_value(PARAM_TEXT, 'Multilang compatible conversation name'. VALUE_OPTIONAL), 'timecreated' => new external_value(PARAM_INT, 'The timecreated timestamp for the conversation'), ), 'information about conversation', VALUE_OPTIONAL), 'Conversations between users', VALUE_OPTIONAL ); return new external_single_structure( $result ); }
[ "private", "static", "function", "get_conversation_member_structure", "(", ")", "{", "$", "result", "=", "[", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The user id'", ")", ",", "'fullname'", "=>", "new", "external_value", "(", "PARAM_NOTAGS", ",", "'The user\\'s name'", ")", ",", "'profileurl'", "=>", "new", "external_value", "(", "PARAM_URL", ",", "'The link to the user\\'s profile page'", ")", ",", "'profileimageurl'", "=>", "new", "external_value", "(", "PARAM_URL", ",", "'User picture URL'", ")", ",", "'profileimageurlsmall'", "=>", "new", "external_value", "(", "PARAM_URL", ",", "'Small user picture URL'", ")", ",", "'isonline'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'The user\\'s online status'", ")", ",", "'showonlinestatus'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Show the user\\'s online status?'", ")", ",", "'isblocked'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'If the user has been blocked'", ")", ",", "'iscontact'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Is the user a contact?'", ")", ",", "'isdeleted'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Is the user deleted?'", ")", ",", "'canmessage'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'If the user can be messaged'", ")", ",", "'requirescontact'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'If the user requires to be contacts'", ")", ",", "]", ";", "$", "result", "[", "'contactrequests'", "]", "=", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "[", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The id of the contact request'", ")", ",", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The id of the user who created the contact request'", ")", ",", "'requesteduserid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The id of the user confirming the request'", ")", ",", "'timecreated'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The timecreated timestamp for the contact request'", ")", ",", "]", ")", ",", "'The contact requests'", ",", "VALUE_OPTIONAL", ")", ";", "$", "result", "[", "'conversations'", "]", "=", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Conversations id'", ")", ",", "'type'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Conversation type: private or public'", ")", ",", "'name'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'Multilang compatible conversation name'", ".", "VALUE_OPTIONAL", ")", ",", "'timecreated'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The timecreated timestamp for the conversation'", ")", ",", ")", ",", "'information about conversation'", ",", "VALUE_OPTIONAL", ")", ",", "'Conversations between users'", ",", "VALUE_OPTIONAL", ")", ";", "return", "new", "external_single_structure", "(", "$", "result", ")", ";", "}" ]
Return the structure of a conversation member. @return external_single_structure @since Moodle 3.6
[ "Return", "the", "structure", "of", "a", "conversation", "member", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L1273-L1313
216,165
moodle/moodle
message/externallib.php
core_message_external.data_for_messagearea_search_users_in_course_parameters
public static function data_for_messagearea_search_users_in_course_parameters() { return new external_function_parameters( array( 'userid' => new external_value(PARAM_INT, 'The id of the user who is performing the search'), 'courseid' => new external_value(PARAM_INT, 'The id of the course'), 'search' => new external_value(PARAM_RAW, 'The string being searched'), 'limitfrom' => new external_value(PARAM_INT, 'Limit from', VALUE_DEFAULT, 0), 'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0) ) ); }
php
public static function data_for_messagearea_search_users_in_course_parameters() { return new external_function_parameters( array( 'userid' => new external_value(PARAM_INT, 'The id of the user who is performing the search'), 'courseid' => new external_value(PARAM_INT, 'The id of the course'), 'search' => new external_value(PARAM_RAW, 'The string being searched'), 'limitfrom' => new external_value(PARAM_INT, 'Limit from', VALUE_DEFAULT, 0), 'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0) ) ); }
[ "public", "static", "function", "data_for_messagearea_search_users_in_course_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The id of the user who is performing the search'", ")", ",", "'courseid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The id of the course'", ")", ",", "'search'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'The string being searched'", ")", ",", "'limitfrom'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Limit from'", ",", "VALUE_DEFAULT", ",", "0", ")", ",", "'limitnum'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Limit number'", ",", "VALUE_DEFAULT", ",", "0", ")", ")", ")", ";", "}" ]
Get messagearea search users in course parameters. @deprecated since 3.6 @return external_function_parameters @since 3.2
[ "Get", "messagearea", "search", "users", "in", "course", "parameters", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L1363-L1373
216,166
moodle/moodle
message/externallib.php
core_message_external.data_for_messagearea_search_users_in_course
public static function data_for_messagearea_search_users_in_course($userid, $courseid, $search, $limitfrom = 0, $limitnum = 0) { global $CFG, $PAGE, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $systemcontext = context_system::instance(); $params = array( 'userid' => $userid, 'courseid' => $courseid, 'search' => $search, 'limitfrom' => $limitfrom, 'limitnum' => $limitnum ); $params = self::validate_parameters(self::data_for_messagearea_search_users_in_course_parameters(), $params); self::validate_context($systemcontext); if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } $users = \core_message\api::search_users_in_course( $params['userid'], $params['courseid'], $params['search'], $params['limitfrom'], $params['limitnum'] ); $results = new \core_message\output\messagearea\user_search_results($users); $renderer = $PAGE->get_renderer('core_message'); return $results->export_for_template($renderer); }
php
public static function data_for_messagearea_search_users_in_course($userid, $courseid, $search, $limitfrom = 0, $limitnum = 0) { global $CFG, $PAGE, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $systemcontext = context_system::instance(); $params = array( 'userid' => $userid, 'courseid' => $courseid, 'search' => $search, 'limitfrom' => $limitfrom, 'limitnum' => $limitnum ); $params = self::validate_parameters(self::data_for_messagearea_search_users_in_course_parameters(), $params); self::validate_context($systemcontext); if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } $users = \core_message\api::search_users_in_course( $params['userid'], $params['courseid'], $params['search'], $params['limitfrom'], $params['limitnum'] ); $results = new \core_message\output\messagearea\user_search_results($users); $renderer = $PAGE->get_renderer('core_message'); return $results->export_for_template($renderer); }
[ "public", "static", "function", "data_for_messagearea_search_users_in_course", "(", "$", "userid", ",", "$", "courseid", ",", "$", "search", ",", "$", "limitfrom", "=", "0", ",", "$", "limitnum", "=", "0", ")", "{", "global", "$", "CFG", ",", "$", "PAGE", ",", "$", "USER", ";", "// Check if messaging is enabled.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "$", "systemcontext", "=", "context_system", "::", "instance", "(", ")", ";", "$", "params", "=", "array", "(", "'userid'", "=>", "$", "userid", ",", "'courseid'", "=>", "$", "courseid", ",", "'search'", "=>", "$", "search", ",", "'limitfrom'", "=>", "$", "limitfrom", ",", "'limitnum'", "=>", "$", "limitnum", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "data_for_messagearea_search_users_in_course_parameters", "(", ")", ",", "$", "params", ")", ";", "self", "::", "validate_context", "(", "$", "systemcontext", ")", ";", "if", "(", "(", "$", "USER", "->", "id", "!=", "$", "params", "[", "'userid'", "]", ")", "&&", "!", "has_capability", "(", "'moodle/site:readallmessages'", ",", "$", "systemcontext", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'You do not have permission to perform this action.'", ")", ";", "}", "$", "users", "=", "\\", "core_message", "\\", "api", "::", "search_users_in_course", "(", "$", "params", "[", "'userid'", "]", ",", "$", "params", "[", "'courseid'", "]", ",", "$", "params", "[", "'search'", "]", ",", "$", "params", "[", "'limitfrom'", "]", ",", "$", "params", "[", "'limitnum'", "]", ")", ";", "$", "results", "=", "new", "\\", "core_message", "\\", "output", "\\", "messagearea", "\\", "user_search_results", "(", "$", "users", ")", ";", "$", "renderer", "=", "$", "PAGE", "->", "get_renderer", "(", "'core_message'", ")", ";", "return", "$", "results", "->", "export_for_template", "(", "$", "renderer", ")", ";", "}" ]
Get messagearea search users in course results. @deprecated since 3.6 @param int $userid The id of the user who is performing the search @param int $courseid The id of the course @param string $search The string being searched @param int $limitfrom @param int $limitnum @return stdClass @throws moodle_exception @since 3.2
[ "Get", "messagearea", "search", "users", "in", "course", "results", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L1389-L1425
216,167
moodle/moodle
message/externallib.php
core_message_external.data_for_messagearea_search_users
public static function data_for_messagearea_search_users($userid, $search, $limitnum = 0) { global $CFG, $PAGE, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $systemcontext = context_system::instance(); $params = array( 'userid' => $userid, 'search' => $search, 'limitnum' => $limitnum ); $params = self::validate_parameters(self::data_for_messagearea_search_users_parameters(), $params); self::validate_context($systemcontext); if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } list($contacts, $courses, $noncontacts) = \core_message\api::search_users( $params['userid'], $params['search'], $params['limitnum'] ); $search = new \core_message\output\messagearea\user_search_results($contacts, $courses, $noncontacts); $renderer = $PAGE->get_renderer('core_message'); return $search->export_for_template($renderer); }
php
public static function data_for_messagearea_search_users($userid, $search, $limitnum = 0) { global $CFG, $PAGE, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $systemcontext = context_system::instance(); $params = array( 'userid' => $userid, 'search' => $search, 'limitnum' => $limitnum ); $params = self::validate_parameters(self::data_for_messagearea_search_users_parameters(), $params); self::validate_context($systemcontext); if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } list($contacts, $courses, $noncontacts) = \core_message\api::search_users( $params['userid'], $params['search'], $params['limitnum'] ); $search = new \core_message\output\messagearea\user_search_results($contacts, $courses, $noncontacts); $renderer = $PAGE->get_renderer('core_message'); return $search->export_for_template($renderer); }
[ "public", "static", "function", "data_for_messagearea_search_users", "(", "$", "userid", ",", "$", "search", ",", "$", "limitnum", "=", "0", ")", "{", "global", "$", "CFG", ",", "$", "PAGE", ",", "$", "USER", ";", "// Check if messaging is enabled.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "$", "systemcontext", "=", "context_system", "::", "instance", "(", ")", ";", "$", "params", "=", "array", "(", "'userid'", "=>", "$", "userid", ",", "'search'", "=>", "$", "search", ",", "'limitnum'", "=>", "$", "limitnum", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "data_for_messagearea_search_users_parameters", "(", ")", ",", "$", "params", ")", ";", "self", "::", "validate_context", "(", "$", "systemcontext", ")", ";", "if", "(", "(", "$", "USER", "->", "id", "!=", "$", "params", "[", "'userid'", "]", ")", "&&", "!", "has_capability", "(", "'moodle/site:readallmessages'", ",", "$", "systemcontext", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'You do not have permission to perform this action.'", ")", ";", "}", "list", "(", "$", "contacts", ",", "$", "courses", ",", "$", "noncontacts", ")", "=", "\\", "core_message", "\\", "api", "::", "search_users", "(", "$", "params", "[", "'userid'", "]", ",", "$", "params", "[", "'search'", "]", ",", "$", "params", "[", "'limitnum'", "]", ")", ";", "$", "search", "=", "new", "\\", "core_message", "\\", "output", "\\", "messagearea", "\\", "user_search_results", "(", "$", "contacts", ",", "$", "courses", ",", "$", "noncontacts", ")", ";", "$", "renderer", "=", "$", "PAGE", "->", "get_renderer", "(", "'core_message'", ")", ";", "return", "$", "search", "->", "export_for_template", "(", "$", "renderer", ")", ";", "}" ]
Get messagearea search users results. @deprecated since 3.6 @param int $userid The id of the user who is performing the search @param string $search The string being searched @param int $limitnum @return stdClass @throws moodle_exception @since 3.2
[ "Get", "messagearea", "search", "users", "results", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L1484-L1516
216,168
moodle/moodle
message/externallib.php
core_message_external.data_for_messagearea_search_users_returns
public static function data_for_messagearea_search_users_returns() { return new external_single_structure( array( 'contacts' => new external_multiple_structure( self::get_messagearea_contact_structure() ), 'courses' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'The course id'), 'shortname' => new external_value(PARAM_TEXT, 'The course shortname'), 'fullname' => new external_value(PARAM_TEXT, 'The course fullname'), ) ) ), 'noncontacts' => new external_multiple_structure( self::get_messagearea_contact_structure() ) ) ); }
php
public static function data_for_messagearea_search_users_returns() { return new external_single_structure( array( 'contacts' => new external_multiple_structure( self::get_messagearea_contact_structure() ), 'courses' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'The course id'), 'shortname' => new external_value(PARAM_TEXT, 'The course shortname'), 'fullname' => new external_value(PARAM_TEXT, 'The course fullname'), ) ) ), 'noncontacts' => new external_multiple_structure( self::get_messagearea_contact_structure() ) ) ); }
[ "public", "static", "function", "data_for_messagearea_search_users_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'contacts'", "=>", "new", "external_multiple_structure", "(", "self", "::", "get_messagearea_contact_structure", "(", ")", ")", ",", "'courses'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The course id'", ")", ",", "'shortname'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'The course shortname'", ")", ",", "'fullname'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'The course fullname'", ")", ",", ")", ")", ")", ",", "'noncontacts'", "=>", "new", "external_multiple_structure", "(", "self", "::", "get_messagearea_contact_structure", "(", ")", ")", ")", ")", ";", "}" ]
Get messagearea search users returns. @deprecated since 3.6 @return external_single_structure @since 3.2
[ "Get", "messagearea", "search", "users", "returns", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L1526-L1546
216,169
moodle/moodle
message/externallib.php
core_message_external.message_search_users_parameters
public static function message_search_users_parameters() { return new external_function_parameters( array( 'userid' => new external_value(PARAM_INT, 'The id of the user who is performing the search'), 'search' => new external_value(PARAM_RAW, 'The string being searched'), 'limitfrom' => new external_value(PARAM_INT, 'Limit from', VALUE_DEFAULT, 0), 'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0), ) ); }
php
public static function message_search_users_parameters() { return new external_function_parameters( array( 'userid' => new external_value(PARAM_INT, 'The id of the user who is performing the search'), 'search' => new external_value(PARAM_RAW, 'The string being searched'), 'limitfrom' => new external_value(PARAM_INT, 'Limit from', VALUE_DEFAULT, 0), 'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0), ) ); }
[ "public", "static", "function", "message_search_users_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The id of the user who is performing the search'", ")", ",", "'search'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'The string being searched'", ")", ",", "'limitfrom'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Limit from'", ",", "VALUE_DEFAULT", ",", "0", ")", ",", "'limitnum'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Limit number'", ",", "VALUE_DEFAULT", ",", "0", ")", ",", ")", ")", ";", "}" ]
Get messagearea message search users parameters. @return external_function_parameters @since 3.6
[ "Get", "messagearea", "message", "search", "users", "parameters", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L1563-L1572
216,170
moodle/moodle
message/externallib.php
core_message_external.message_search_users
public static function message_search_users($userid, $search, $limitfrom = 0, $limitnum = 0) { global $USER; $systemcontext = context_system::instance(); $params = array( 'userid' => $userid, 'search' => $search, 'limitfrom' => $limitfrom, 'limitnum' => $limitnum ); $params = self::validate_parameters(self::message_search_users_parameters(), $params); self::validate_context($systemcontext); if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } list($contacts, $noncontacts) = \core_message\api::message_search_users( $params['userid'], $params['search'], $params['limitfrom'], $params['limitnum']); return array('contacts' => $contacts, 'noncontacts' => $noncontacts); }
php
public static function message_search_users($userid, $search, $limitfrom = 0, $limitnum = 0) { global $USER; $systemcontext = context_system::instance(); $params = array( 'userid' => $userid, 'search' => $search, 'limitfrom' => $limitfrom, 'limitnum' => $limitnum ); $params = self::validate_parameters(self::message_search_users_parameters(), $params); self::validate_context($systemcontext); if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } list($contacts, $noncontacts) = \core_message\api::message_search_users( $params['userid'], $params['search'], $params['limitfrom'], $params['limitnum']); return array('contacts' => $contacts, 'noncontacts' => $noncontacts); }
[ "public", "static", "function", "message_search_users", "(", "$", "userid", ",", "$", "search", ",", "$", "limitfrom", "=", "0", ",", "$", "limitnum", "=", "0", ")", "{", "global", "$", "USER", ";", "$", "systemcontext", "=", "context_system", "::", "instance", "(", ")", ";", "$", "params", "=", "array", "(", "'userid'", "=>", "$", "userid", ",", "'search'", "=>", "$", "search", ",", "'limitfrom'", "=>", "$", "limitfrom", ",", "'limitnum'", "=>", "$", "limitnum", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "message_search_users_parameters", "(", ")", ",", "$", "params", ")", ";", "self", "::", "validate_context", "(", "$", "systemcontext", ")", ";", "if", "(", "(", "$", "USER", "->", "id", "!=", "$", "params", "[", "'userid'", "]", ")", "&&", "!", "has_capability", "(", "'moodle/site:readallmessages'", ",", "$", "systemcontext", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'You do not have permission to perform this action.'", ")", ";", "}", "list", "(", "$", "contacts", ",", "$", "noncontacts", ")", "=", "\\", "core_message", "\\", "api", "::", "message_search_users", "(", "$", "params", "[", "'userid'", "]", ",", "$", "params", "[", "'search'", "]", ",", "$", "params", "[", "'limitfrom'", "]", ",", "$", "params", "[", "'limitnum'", "]", ")", ";", "return", "array", "(", "'contacts'", "=>", "$", "contacts", ",", "'noncontacts'", "=>", "$", "noncontacts", ")", ";", "}" ]
Get search users results. @param int $userid The id of the user who is performing the search @param string $search The string being searched @param int $limitfrom @param int $limitnum @return array @throws moodle_exception @since 3.6
[ "Get", "search", "users", "results", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L1585-L1610
216,171
moodle/moodle
message/externallib.php
core_message_external.data_for_messagearea_search_messages_parameters
public static function data_for_messagearea_search_messages_parameters() { return new external_function_parameters( array( 'userid' => new external_value(PARAM_INT, 'The id of the user who is performing the search'), 'search' => new external_value(PARAM_RAW, 'The string being searched'), 'limitfrom' => new external_value(PARAM_INT, 'Limit from', VALUE_DEFAULT, 0), 'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0) ) ); }
php
public static function data_for_messagearea_search_messages_parameters() { return new external_function_parameters( array( 'userid' => new external_value(PARAM_INT, 'The id of the user who is performing the search'), 'search' => new external_value(PARAM_RAW, 'The string being searched'), 'limitfrom' => new external_value(PARAM_INT, 'Limit from', VALUE_DEFAULT, 0), 'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0) ) ); }
[ "public", "static", "function", "data_for_messagearea_search_messages_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The id of the user who is performing the search'", ")", ",", "'search'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'The string being searched'", ")", ",", "'limitfrom'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Limit from'", ",", "VALUE_DEFAULT", ",", "0", ")", ",", "'limitnum'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Limit number'", ",", "VALUE_DEFAULT", ",", "0", ")", ")", ")", ";", "}" ]
Get messagearea search messages parameters. @return external_function_parameters @since 3.2
[ "Get", "messagearea", "search", "messages", "parameters", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L1637-L1646
216,172
moodle/moodle
message/externallib.php
core_message_external.data_for_messagearea_search_messages
public static function data_for_messagearea_search_messages($userid, $search, $limitfrom = 0, $limitnum = 0) { global $CFG, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $systemcontext = context_system::instance(); $params = array( 'userid' => $userid, 'search' => $search, 'limitfrom' => $limitfrom, 'limitnum' => $limitnum ); $params = self::validate_parameters(self::data_for_messagearea_search_messages_parameters(), $params); self::validate_context($systemcontext); if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } $messages = \core_message\api::search_messages( $params['userid'], $params['search'], $params['limitfrom'], $params['limitnum'] ); $data = new \stdClass(); $data->contacts = []; foreach ($messages as $message) { $contact = new \stdClass(); $contact->userid = $message->userid; $contact->fullname = $message->fullname; $contact->profileimageurl = $message->profileimageurl; $contact->profileimageurlsmall = $message->profileimageurlsmall; $contact->messageid = $message->messageid; $contact->ismessaging = $message->ismessaging; $contact->sentfromcurrentuser = false; if ($message->lastmessage) { if ($message->userid !== $message->useridfrom) { $contact->sentfromcurrentuser = true; } $contact->lastmessage = shorten_text($message->lastmessage, 60); } else { $contact->lastmessage = null; } $contact->lastmessagedate = $message->lastmessagedate; $contact->showonlinestatus = is_null($message->isonline) ? false : true; $contact->isonline = $message->isonline; $contact->isblocked = $message->isblocked; $contact->isread = $message->isread; $contact->unreadcount = $message->unreadcount; $contact->conversationid = $message->conversationid; $data->contacts[] = $contact; } return $data; }
php
public static function data_for_messagearea_search_messages($userid, $search, $limitfrom = 0, $limitnum = 0) { global $CFG, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $systemcontext = context_system::instance(); $params = array( 'userid' => $userid, 'search' => $search, 'limitfrom' => $limitfrom, 'limitnum' => $limitnum ); $params = self::validate_parameters(self::data_for_messagearea_search_messages_parameters(), $params); self::validate_context($systemcontext); if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } $messages = \core_message\api::search_messages( $params['userid'], $params['search'], $params['limitfrom'], $params['limitnum'] ); $data = new \stdClass(); $data->contacts = []; foreach ($messages as $message) { $contact = new \stdClass(); $contact->userid = $message->userid; $contact->fullname = $message->fullname; $contact->profileimageurl = $message->profileimageurl; $contact->profileimageurlsmall = $message->profileimageurlsmall; $contact->messageid = $message->messageid; $contact->ismessaging = $message->ismessaging; $contact->sentfromcurrentuser = false; if ($message->lastmessage) { if ($message->userid !== $message->useridfrom) { $contact->sentfromcurrentuser = true; } $contact->lastmessage = shorten_text($message->lastmessage, 60); } else { $contact->lastmessage = null; } $contact->lastmessagedate = $message->lastmessagedate; $contact->showonlinestatus = is_null($message->isonline) ? false : true; $contact->isonline = $message->isonline; $contact->isblocked = $message->isblocked; $contact->isread = $message->isread; $contact->unreadcount = $message->unreadcount; $contact->conversationid = $message->conversationid; $data->contacts[] = $contact; } return $data; }
[ "public", "static", "function", "data_for_messagearea_search_messages", "(", "$", "userid", ",", "$", "search", ",", "$", "limitfrom", "=", "0", ",", "$", "limitnum", "=", "0", ")", "{", "global", "$", "CFG", ",", "$", "USER", ";", "// Check if messaging is enabled.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "$", "systemcontext", "=", "context_system", "::", "instance", "(", ")", ";", "$", "params", "=", "array", "(", "'userid'", "=>", "$", "userid", ",", "'search'", "=>", "$", "search", ",", "'limitfrom'", "=>", "$", "limitfrom", ",", "'limitnum'", "=>", "$", "limitnum", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "data_for_messagearea_search_messages_parameters", "(", ")", ",", "$", "params", ")", ";", "self", "::", "validate_context", "(", "$", "systemcontext", ")", ";", "if", "(", "(", "$", "USER", "->", "id", "!=", "$", "params", "[", "'userid'", "]", ")", "&&", "!", "has_capability", "(", "'moodle/site:readallmessages'", ",", "$", "systemcontext", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'You do not have permission to perform this action.'", ")", ";", "}", "$", "messages", "=", "\\", "core_message", "\\", "api", "::", "search_messages", "(", "$", "params", "[", "'userid'", "]", ",", "$", "params", "[", "'search'", "]", ",", "$", "params", "[", "'limitfrom'", "]", ",", "$", "params", "[", "'limitnum'", "]", ")", ";", "$", "data", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "data", "->", "contacts", "=", "[", "]", ";", "foreach", "(", "$", "messages", "as", "$", "message", ")", "{", "$", "contact", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "contact", "->", "userid", "=", "$", "message", "->", "userid", ";", "$", "contact", "->", "fullname", "=", "$", "message", "->", "fullname", ";", "$", "contact", "->", "profileimageurl", "=", "$", "message", "->", "profileimageurl", ";", "$", "contact", "->", "profileimageurlsmall", "=", "$", "message", "->", "profileimageurlsmall", ";", "$", "contact", "->", "messageid", "=", "$", "message", "->", "messageid", ";", "$", "contact", "->", "ismessaging", "=", "$", "message", "->", "ismessaging", ";", "$", "contact", "->", "sentfromcurrentuser", "=", "false", ";", "if", "(", "$", "message", "->", "lastmessage", ")", "{", "if", "(", "$", "message", "->", "userid", "!==", "$", "message", "->", "useridfrom", ")", "{", "$", "contact", "->", "sentfromcurrentuser", "=", "true", ";", "}", "$", "contact", "->", "lastmessage", "=", "shorten_text", "(", "$", "message", "->", "lastmessage", ",", "60", ")", ";", "}", "else", "{", "$", "contact", "->", "lastmessage", "=", "null", ";", "}", "$", "contact", "->", "lastmessagedate", "=", "$", "message", "->", "lastmessagedate", ";", "$", "contact", "->", "showonlinestatus", "=", "is_null", "(", "$", "message", "->", "isonline", ")", "?", "false", ":", "true", ";", "$", "contact", "->", "isonline", "=", "$", "message", "->", "isonline", ";", "$", "contact", "->", "isblocked", "=", "$", "message", "->", "isblocked", ";", "$", "contact", "->", "isread", "=", "$", "message", "->", "isread", ";", "$", "contact", "->", "unreadcount", "=", "$", "message", "->", "unreadcount", ";", "$", "contact", "->", "conversationid", "=", "$", "message", "->", "conversationid", ";", "$", "data", "->", "contacts", "[", "]", "=", "$", "contact", ";", "}", "return", "$", "data", ";", "}" ]
Get messagearea search messages results. @param int $userid The id of the user who is performing the search @param string $search The string being searched @param int $limitfrom @param int $limitnum @return stdClass @throws moodle_exception @since 3.2
[ "Get", "messagearea", "search", "messages", "results", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L1659-L1721
216,173
moodle/moodle
message/externallib.php
core_message_external.get_conversations_parameters
public static function get_conversations_parameters() { return new external_function_parameters( array( 'userid' => new external_value(PARAM_INT, 'The id of the user who we are viewing conversations for'), 'limitfrom' => new external_value(PARAM_INT, 'The offset to start at', VALUE_DEFAULT, 0), 'limitnum' => new external_value(PARAM_INT, 'Limit number of conversations to this', VALUE_DEFAULT, 0), 'type' => new external_value(PARAM_INT, 'Filter by type', VALUE_DEFAULT, null), 'favourites' => new external_value(PARAM_BOOL, 'Whether to restrict the results to contain NO favourite conversations (false), ONLY favourite conversation (true), or ignore any restriction altogether (null)', VALUE_DEFAULT, null), 'mergeself' => new external_value(PARAM_BOOL, 'Whether to include self-conversations (true) or ONLY private conversations (false) when private conversations are requested.', VALUE_DEFAULT, false), ) ); }
php
public static function get_conversations_parameters() { return new external_function_parameters( array( 'userid' => new external_value(PARAM_INT, 'The id of the user who we are viewing conversations for'), 'limitfrom' => new external_value(PARAM_INT, 'The offset to start at', VALUE_DEFAULT, 0), 'limitnum' => new external_value(PARAM_INT, 'Limit number of conversations to this', VALUE_DEFAULT, 0), 'type' => new external_value(PARAM_INT, 'Filter by type', VALUE_DEFAULT, null), 'favourites' => new external_value(PARAM_BOOL, 'Whether to restrict the results to contain NO favourite conversations (false), ONLY favourite conversation (true), or ignore any restriction altogether (null)', VALUE_DEFAULT, null), 'mergeself' => new external_value(PARAM_BOOL, 'Whether to include self-conversations (true) or ONLY private conversations (false) when private conversations are requested.', VALUE_DEFAULT, false), ) ); }
[ "public", "static", "function", "get_conversations_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The id of the user who we are viewing conversations for'", ")", ",", "'limitfrom'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The offset to start at'", ",", "VALUE_DEFAULT", ",", "0", ")", ",", "'limitnum'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Limit number of conversations to this'", ",", "VALUE_DEFAULT", ",", "0", ")", ",", "'type'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Filter by type'", ",", "VALUE_DEFAULT", ",", "null", ")", ",", "'favourites'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Whether to restrict the results to contain NO favourite\n conversations (false), ONLY favourite conversation (true), or ignore any restriction altogether (null)'", ",", "VALUE_DEFAULT", ",", "null", ")", ",", "'mergeself'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Whether to include self-conversations (true) or ONLY private\n conversations (false) when private conversations are requested.'", ",", "VALUE_DEFAULT", ",", "false", ")", ",", ")", ")", ";", "}" ]
Get conversations parameters. @return external_function_parameters @since 3.6
[ "Get", "conversations", "parameters", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L1745-L1760
216,174
moodle/moodle
message/externallib.php
core_message_external.get_conversations
public static function get_conversations($userid, $limitfrom = 0, $limitnum = 0, int $type = null, bool $favourites = null, bool $mergeself = false) { global $CFG, $USER; // All the standard BL checks. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $params = array( 'userid' => $userid, 'limitfrom' => $limitfrom, 'limitnum' => $limitnum, 'type' => $type, 'favourites' => $favourites, 'mergeself' => $mergeself ); $params = self::validate_parameters(self::get_conversations_parameters(), $params); $systemcontext = context_system::instance(); self::validate_context($systemcontext); if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } $conversations = \core_message\api::get_conversations( $params['userid'], $params['limitfrom'], $params['limitnum'], $params['type'], $params['favourites'], $params['mergeself'] ); return (object) ['conversations' => $conversations]; }
php
public static function get_conversations($userid, $limitfrom = 0, $limitnum = 0, int $type = null, bool $favourites = null, bool $mergeself = false) { global $CFG, $USER; // All the standard BL checks. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $params = array( 'userid' => $userid, 'limitfrom' => $limitfrom, 'limitnum' => $limitnum, 'type' => $type, 'favourites' => $favourites, 'mergeself' => $mergeself ); $params = self::validate_parameters(self::get_conversations_parameters(), $params); $systemcontext = context_system::instance(); self::validate_context($systemcontext); if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } $conversations = \core_message\api::get_conversations( $params['userid'], $params['limitfrom'], $params['limitnum'], $params['type'], $params['favourites'], $params['mergeself'] ); return (object) ['conversations' => $conversations]; }
[ "public", "static", "function", "get_conversations", "(", "$", "userid", ",", "$", "limitfrom", "=", "0", ",", "$", "limitnum", "=", "0", ",", "int", "$", "type", "=", "null", ",", "bool", "$", "favourites", "=", "null", ",", "bool", "$", "mergeself", "=", "false", ")", "{", "global", "$", "CFG", ",", "$", "USER", ";", "// All the standard BL checks.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "$", "params", "=", "array", "(", "'userid'", "=>", "$", "userid", ",", "'limitfrom'", "=>", "$", "limitfrom", ",", "'limitnum'", "=>", "$", "limitnum", ",", "'type'", "=>", "$", "type", ",", "'favourites'", "=>", "$", "favourites", ",", "'mergeself'", "=>", "$", "mergeself", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_conversations_parameters", "(", ")", ",", "$", "params", ")", ";", "$", "systemcontext", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "systemcontext", ")", ";", "if", "(", "(", "$", "USER", "->", "id", "!=", "$", "params", "[", "'userid'", "]", ")", "&&", "!", "has_capability", "(", "'moodle/site:readallmessages'", ",", "$", "systemcontext", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'You do not have permission to perform this action.'", ")", ";", "}", "$", "conversations", "=", "\\", "core_message", "\\", "api", "::", "get_conversations", "(", "$", "params", "[", "'userid'", "]", ",", "$", "params", "[", "'limitfrom'", "]", ",", "$", "params", "[", "'limitnum'", "]", ",", "$", "params", "[", "'type'", "]", ",", "$", "params", "[", "'favourites'", "]", ",", "$", "params", "[", "'mergeself'", "]", ")", ";", "return", "(", "object", ")", "[", "'conversations'", "=>", "$", "conversations", "]", ";", "}" ]
Get the list of conversations for the user. @param int $userid The id of the user who is performing the search @param int $limitfrom @param int $limitnum @param int|null $type @param bool|null $favourites @param bool $mergeself whether to include self-conversations (true) or ONLY private conversations (false) when private conversations are requested. @return stdClass @throws \moodle_exception if the messaging feature is disabled on the site. @since 3.2
[ "Get", "the", "list", "of", "conversations", "for", "the", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L1776-L1812
216,175
moodle/moodle
message/externallib.php
core_message_external.get_conversation_between_users
public static function get_conversation_between_users( int $userid, int $otheruserid, bool $includecontactrequests = false, bool $includeprivacyinfo = false, int $memberlimit = 0, int $memberoffset = 0, int $messagelimit = 0, int $messageoffset = 0, bool $newestmessagesfirst = true ) { global $CFG, $DB, $USER; // All the standard BL checks. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $params = [ 'userid' => $userid, 'otheruserid' => $otheruserid, 'includecontactrequests' => $includecontactrequests, 'includeprivacyinfo' => $includeprivacyinfo, 'memberlimit' => $memberlimit, 'memberoffset' => $memberoffset, 'messagelimit' => $messagelimit, 'messageoffset' => $messageoffset, 'newestmessagesfirst' => $newestmessagesfirst ]; self::validate_parameters(self::get_conversation_between_users_parameters(), $params); $systemcontext = context_system::instance(); self::validate_context($systemcontext); $conversationid = \core_message\api::get_conversation_between_users([$params['userid'], $params['otheruserid']]); $conversation = null; if ($conversationid) { $conversation = \core_message\api::get_conversation( $params['userid'], $conversationid, $params['includecontactrequests'], $params['includeprivacyinfo'], $params['memberlimit'], $params['memberoffset'], $params['messagelimit'], $params['messageoffset'], $params['newestmessagesfirst'] ); } if ($conversation) { return $conversation; } else { // We have to throw an exception here because the external functions annoyingly // don't accept null to be returned for a single structure. throw new \moodle_exception('errorconversationdoesnotexist', 'message'); } }
php
public static function get_conversation_between_users( int $userid, int $otheruserid, bool $includecontactrequests = false, bool $includeprivacyinfo = false, int $memberlimit = 0, int $memberoffset = 0, int $messagelimit = 0, int $messageoffset = 0, bool $newestmessagesfirst = true ) { global $CFG, $DB, $USER; // All the standard BL checks. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $params = [ 'userid' => $userid, 'otheruserid' => $otheruserid, 'includecontactrequests' => $includecontactrequests, 'includeprivacyinfo' => $includeprivacyinfo, 'memberlimit' => $memberlimit, 'memberoffset' => $memberoffset, 'messagelimit' => $messagelimit, 'messageoffset' => $messageoffset, 'newestmessagesfirst' => $newestmessagesfirst ]; self::validate_parameters(self::get_conversation_between_users_parameters(), $params); $systemcontext = context_system::instance(); self::validate_context($systemcontext); $conversationid = \core_message\api::get_conversation_between_users([$params['userid'], $params['otheruserid']]); $conversation = null; if ($conversationid) { $conversation = \core_message\api::get_conversation( $params['userid'], $conversationid, $params['includecontactrequests'], $params['includeprivacyinfo'], $params['memberlimit'], $params['memberoffset'], $params['messagelimit'], $params['messageoffset'], $params['newestmessagesfirst'] ); } if ($conversation) { return $conversation; } else { // We have to throw an exception here because the external functions annoyingly // don't accept null to be returned for a single structure. throw new \moodle_exception('errorconversationdoesnotexist', 'message'); } }
[ "public", "static", "function", "get_conversation_between_users", "(", "int", "$", "userid", ",", "int", "$", "otheruserid", ",", "bool", "$", "includecontactrequests", "=", "false", ",", "bool", "$", "includeprivacyinfo", "=", "false", ",", "int", "$", "memberlimit", "=", "0", ",", "int", "$", "memberoffset", "=", "0", ",", "int", "$", "messagelimit", "=", "0", ",", "int", "$", "messageoffset", "=", "0", ",", "bool", "$", "newestmessagesfirst", "=", "true", ")", "{", "global", "$", "CFG", ",", "$", "DB", ",", "$", "USER", ";", "// All the standard BL checks.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "$", "params", "=", "[", "'userid'", "=>", "$", "userid", ",", "'otheruserid'", "=>", "$", "otheruserid", ",", "'includecontactrequests'", "=>", "$", "includecontactrequests", ",", "'includeprivacyinfo'", "=>", "$", "includeprivacyinfo", ",", "'memberlimit'", "=>", "$", "memberlimit", ",", "'memberoffset'", "=>", "$", "memberoffset", ",", "'messagelimit'", "=>", "$", "messagelimit", ",", "'messageoffset'", "=>", "$", "messageoffset", ",", "'newestmessagesfirst'", "=>", "$", "newestmessagesfirst", "]", ";", "self", "::", "validate_parameters", "(", "self", "::", "get_conversation_between_users_parameters", "(", ")", ",", "$", "params", ")", ";", "$", "systemcontext", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "systemcontext", ")", ";", "$", "conversationid", "=", "\\", "core_message", "\\", "api", "::", "get_conversation_between_users", "(", "[", "$", "params", "[", "'userid'", "]", ",", "$", "params", "[", "'otheruserid'", "]", "]", ")", ";", "$", "conversation", "=", "null", ";", "if", "(", "$", "conversationid", ")", "{", "$", "conversation", "=", "\\", "core_message", "\\", "api", "::", "get_conversation", "(", "$", "params", "[", "'userid'", "]", ",", "$", "conversationid", ",", "$", "params", "[", "'includecontactrequests'", "]", ",", "$", "params", "[", "'includeprivacyinfo'", "]", ",", "$", "params", "[", "'memberlimit'", "]", ",", "$", "params", "[", "'memberoffset'", "]", ",", "$", "params", "[", "'messagelimit'", "]", ",", "$", "params", "[", "'messageoffset'", "]", ",", "$", "params", "[", "'newestmessagesfirst'", "]", ")", ";", "}", "if", "(", "$", "conversation", ")", "{", "return", "$", "conversation", ";", "}", "else", "{", "// We have to throw an exception here because the external functions annoyingly", "// don't accept null to be returned for a single structure.", "throw", "new", "\\", "moodle_exception", "(", "'errorconversationdoesnotexist'", ",", "'message'", ")", ";", "}", "}" ]
Get a single conversation between users. @param int $userid The user id to get the conversation for @param int $otheruserid The other user id @param bool $includecontactrequests Should contact requests be included between members @param bool $includeprivacyinfo Should privacy info be included between members @param int $memberlimit Limit number of members to load @param int $memberoffset Offset members by this amount @param int $messagelimit Limit number of messages to load @param int $messageoffset Offset the messages @param bool $newestmessagesfirst Order messages by newest first @return stdClass @throws \moodle_exception if the messaging feature is disabled on the site.
[ "Get", "a", "single", "conversation", "between", "users", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L1966-L2024
216,176
moodle/moodle
message/externallib.php
core_message_external.get_self_conversation_parameters
public static function get_self_conversation_parameters() { return new external_function_parameters( array( 'userid' => new external_value(PARAM_INT, 'The id of the user who we are viewing self-conversations for'), 'messagelimit' => new external_value(PARAM_INT, 'Limit for number of messages', VALUE_DEFAULT, 100), 'messageoffset' => new external_value(PARAM_INT, 'Offset for messages list', VALUE_DEFAULT, 0), 'newestmessagesfirst' => new external_value(PARAM_BOOL, 'Order messages by newest first', VALUE_DEFAULT, true) ) ); }
php
public static function get_self_conversation_parameters() { return new external_function_parameters( array( 'userid' => new external_value(PARAM_INT, 'The id of the user who we are viewing self-conversations for'), 'messagelimit' => new external_value(PARAM_INT, 'Limit for number of messages', VALUE_DEFAULT, 100), 'messageoffset' => new external_value(PARAM_INT, 'Offset for messages list', VALUE_DEFAULT, 0), 'newestmessagesfirst' => new external_value(PARAM_BOOL, 'Order messages by newest first', VALUE_DEFAULT, true) ) ); }
[ "public", "static", "function", "get_self_conversation_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The id of the user who we are viewing self-conversations for'", ")", ",", "'messagelimit'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Limit for number of messages'", ",", "VALUE_DEFAULT", ",", "100", ")", ",", "'messageoffset'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Offset for messages list'", ",", "VALUE_DEFAULT", ",", "0", ")", ",", "'newestmessagesfirst'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Order messages by newest first'", ",", "VALUE_DEFAULT", ",", "true", ")", ")", ")", ";", "}" ]
Get self-conversation parameters. @return external_function_parameters
[ "Get", "self", "-", "conversation", "parameters", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L2040-L2049
216,177
moodle/moodle
message/externallib.php
core_message_external.get_self_conversation
public static function get_self_conversation( int $userid, int $messagelimit = 0, int $messageoffset = 0, bool $newestmessagesfirst = true ) { global $CFG; // All the standard BL checks. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $params = [ 'userid' => $userid, 'messagelimit' => $messagelimit, 'messageoffset' => $messageoffset, 'newestmessagesfirst' => $newestmessagesfirst ]; self::validate_parameters(self::get_self_conversation_parameters(), $params); $systemcontext = context_system::instance(); self::validate_context($systemcontext); $conversation = \core_message\api::get_self_conversation($params['userid']); if ($conversation) { $conversation = \core_message\api::get_conversation( $params['userid'], $conversation->id, false, false, 0, 0, $params['messagelimit'], $params['messageoffset'], $params['newestmessagesfirst'] ); } if ($conversation) { return $conversation; } else { // We have to throw an exception here because the external functions annoyingly // don't accept null to be returned for a single structure. throw new \moodle_exception('errorconversationdoesnotexist', 'message'); } }
php
public static function get_self_conversation( int $userid, int $messagelimit = 0, int $messageoffset = 0, bool $newestmessagesfirst = true ) { global $CFG; // All the standard BL checks. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $params = [ 'userid' => $userid, 'messagelimit' => $messagelimit, 'messageoffset' => $messageoffset, 'newestmessagesfirst' => $newestmessagesfirst ]; self::validate_parameters(self::get_self_conversation_parameters(), $params); $systemcontext = context_system::instance(); self::validate_context($systemcontext); $conversation = \core_message\api::get_self_conversation($params['userid']); if ($conversation) { $conversation = \core_message\api::get_conversation( $params['userid'], $conversation->id, false, false, 0, 0, $params['messagelimit'], $params['messageoffset'], $params['newestmessagesfirst'] ); } if ($conversation) { return $conversation; } else { // We have to throw an exception here because the external functions annoyingly // don't accept null to be returned for a single structure. throw new \moodle_exception('errorconversationdoesnotexist', 'message'); } }
[ "public", "static", "function", "get_self_conversation", "(", "int", "$", "userid", ",", "int", "$", "messagelimit", "=", "0", ",", "int", "$", "messageoffset", "=", "0", ",", "bool", "$", "newestmessagesfirst", "=", "true", ")", "{", "global", "$", "CFG", ";", "// All the standard BL checks.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "$", "params", "=", "[", "'userid'", "=>", "$", "userid", ",", "'messagelimit'", "=>", "$", "messagelimit", ",", "'messageoffset'", "=>", "$", "messageoffset", ",", "'newestmessagesfirst'", "=>", "$", "newestmessagesfirst", "]", ";", "self", "::", "validate_parameters", "(", "self", "::", "get_self_conversation_parameters", "(", ")", ",", "$", "params", ")", ";", "$", "systemcontext", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "systemcontext", ")", ";", "$", "conversation", "=", "\\", "core_message", "\\", "api", "::", "get_self_conversation", "(", "$", "params", "[", "'userid'", "]", ")", ";", "if", "(", "$", "conversation", ")", "{", "$", "conversation", "=", "\\", "core_message", "\\", "api", "::", "get_conversation", "(", "$", "params", "[", "'userid'", "]", ",", "$", "conversation", "->", "id", ",", "false", ",", "false", ",", "0", ",", "0", ",", "$", "params", "[", "'messagelimit'", "]", ",", "$", "params", "[", "'messageoffset'", "]", ",", "$", "params", "[", "'newestmessagesfirst'", "]", ")", ";", "}", "if", "(", "$", "conversation", ")", "{", "return", "$", "conversation", ";", "}", "else", "{", "// We have to throw an exception here because the external functions annoyingly", "// don't accept null to be returned for a single structure.", "throw", "new", "\\", "moodle_exception", "(", "'errorconversationdoesnotexist'", ",", "'message'", ")", ";", "}", "}" ]
Get a single self-conversation. @param int $userid The user id to get the self-conversation for @param int $messagelimit Limit number of messages to load @param int $messageoffset Offset the messages @param bool $newestmessagesfirst Order messages by newest first @return stdClass @throws \moodle_exception if the messaging feature is disabled on the site. @since Moodle 3.7
[ "Get", "a", "single", "self", "-", "conversation", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L2062-L2109
216,178
moodle/moodle
message/externallib.php
core_message_external.data_for_messagearea_conversations_parameters
public static function data_for_messagearea_conversations_parameters() { return new external_function_parameters( array( 'userid' => new external_value(PARAM_INT, 'The id of the user who we are viewing conversations for'), 'limitfrom' => new external_value(PARAM_INT, 'Limit from', VALUE_DEFAULT, 0), 'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0) ) ); }
php
public static function data_for_messagearea_conversations_parameters() { return new external_function_parameters( array( 'userid' => new external_value(PARAM_INT, 'The id of the user who we are viewing conversations for'), 'limitfrom' => new external_value(PARAM_INT, 'Limit from', VALUE_DEFAULT, 0), 'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0) ) ); }
[ "public", "static", "function", "data_for_messagearea_conversations_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The id of the user who we are viewing conversations for'", ")", ",", "'limitfrom'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Limit from'", ",", "VALUE_DEFAULT", ",", "0", ")", ",", "'limitnum'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Limit number'", ",", "VALUE_DEFAULT", ",", "0", ")", ")", ")", ";", "}" ]
The messagearea conversations parameters. @deprecated since 3.6 @return external_function_parameters @since 3.2
[ "The", "messagearea", "conversations", "parameters", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L2127-L2135
216,179
moodle/moodle
message/externallib.php
core_message_external.data_for_messagearea_conversations
public static function data_for_messagearea_conversations($userid, $limitfrom = 0, $limitnum = 0) { global $CFG, $PAGE, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $systemcontext = context_system::instance(); $params = array( 'userid' => $userid, 'limitfrom' => $limitfrom, 'limitnum' => $limitnum ); $params = self::validate_parameters(self::data_for_messagearea_conversations_parameters(), $params); self::validate_context($systemcontext); if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } $conversations = \core_message\api::get_conversations($params['userid'], $params['limitfrom'], $params['limitnum']); // Format the conversations in the legacy style, as the get_conversations method has since been changed. $conversations = \core_message\helper::get_conversations_legacy_formatter($conversations); $conversations = new \core_message\output\messagearea\contacts(null, $conversations); $renderer = $PAGE->get_renderer('core_message'); return $conversations->export_for_template($renderer); }
php
public static function data_for_messagearea_conversations($userid, $limitfrom = 0, $limitnum = 0) { global $CFG, $PAGE, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $systemcontext = context_system::instance(); $params = array( 'userid' => $userid, 'limitfrom' => $limitfrom, 'limitnum' => $limitnum ); $params = self::validate_parameters(self::data_for_messagearea_conversations_parameters(), $params); self::validate_context($systemcontext); if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } $conversations = \core_message\api::get_conversations($params['userid'], $params['limitfrom'], $params['limitnum']); // Format the conversations in the legacy style, as the get_conversations method has since been changed. $conversations = \core_message\helper::get_conversations_legacy_formatter($conversations); $conversations = new \core_message\output\messagearea\contacts(null, $conversations); $renderer = $PAGE->get_renderer('core_message'); return $conversations->export_for_template($renderer); }
[ "public", "static", "function", "data_for_messagearea_conversations", "(", "$", "userid", ",", "$", "limitfrom", "=", "0", ",", "$", "limitnum", "=", "0", ")", "{", "global", "$", "CFG", ",", "$", "PAGE", ",", "$", "USER", ";", "// Check if messaging is enabled.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "$", "systemcontext", "=", "context_system", "::", "instance", "(", ")", ";", "$", "params", "=", "array", "(", "'userid'", "=>", "$", "userid", ",", "'limitfrom'", "=>", "$", "limitfrom", ",", "'limitnum'", "=>", "$", "limitnum", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "data_for_messagearea_conversations_parameters", "(", ")", ",", "$", "params", ")", ";", "self", "::", "validate_context", "(", "$", "systemcontext", ")", ";", "if", "(", "(", "$", "USER", "->", "id", "!=", "$", "params", "[", "'userid'", "]", ")", "&&", "!", "has_capability", "(", "'moodle/site:readallmessages'", ",", "$", "systemcontext", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'You do not have permission to perform this action.'", ")", ";", "}", "$", "conversations", "=", "\\", "core_message", "\\", "api", "::", "get_conversations", "(", "$", "params", "[", "'userid'", "]", ",", "$", "params", "[", "'limitfrom'", "]", ",", "$", "params", "[", "'limitnum'", "]", ")", ";", "// Format the conversations in the legacy style, as the get_conversations method has since been changed.", "$", "conversations", "=", "\\", "core_message", "\\", "helper", "::", "get_conversations_legacy_formatter", "(", "$", "conversations", ")", ";", "$", "conversations", "=", "new", "\\", "core_message", "\\", "output", "\\", "messagearea", "\\", "contacts", "(", "null", ",", "$", "conversations", ")", ";", "$", "renderer", "=", "$", "PAGE", "->", "get_renderer", "(", "'core_message'", ")", ";", "return", "$", "conversations", "->", "export_for_template", "(", "$", "renderer", ")", ";", "}" ]
Get messagearea conversations. NOTE FOR FINAL DEPRECATION: When removing this method, please also consider removal of get_conversations_legacy_formatter() from the \core_message\helper class. This helper method was used solely to format the new get_conversations() return data into the old format used here, and in message/index.php. If we no longer need either of these, then that method can be removed. @deprecated since 3.6 @param int $userid The id of the user who we are viewing conversations for @param int $limitfrom @param int $limitnum @return stdClass @throws moodle_exception @since 3.2
[ "Get", "messagearea", "conversations", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L2154-L2185
216,180
moodle/moodle
message/externallib.php
core_message_external.data_for_messagearea_contacts
public static function data_for_messagearea_contacts($userid, $limitfrom = 0, $limitnum = 0) { global $CFG, $PAGE, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $systemcontext = context_system::instance(); $params = array( 'userid' => $userid, 'limitfrom' => $limitfrom, 'limitnum' => $limitnum ); $params = self::validate_parameters(self::data_for_messagearea_contacts_parameters(), $params); self::validate_context($systemcontext); if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } $contacts = \core_message\api::get_contacts($params['userid'], $params['limitfrom'], $params['limitnum']); $contacts = new \core_message\output\messagearea\contacts(null, $contacts); $renderer = $PAGE->get_renderer('core_message'); return $contacts->export_for_template($renderer); }
php
public static function data_for_messagearea_contacts($userid, $limitfrom = 0, $limitnum = 0) { global $CFG, $PAGE, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $systemcontext = context_system::instance(); $params = array( 'userid' => $userid, 'limitfrom' => $limitfrom, 'limitnum' => $limitnum ); $params = self::validate_parameters(self::data_for_messagearea_contacts_parameters(), $params); self::validate_context($systemcontext); if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } $contacts = \core_message\api::get_contacts($params['userid'], $params['limitfrom'], $params['limitnum']); $contacts = new \core_message\output\messagearea\contacts(null, $contacts); $renderer = $PAGE->get_renderer('core_message'); return $contacts->export_for_template($renderer); }
[ "public", "static", "function", "data_for_messagearea_contacts", "(", "$", "userid", ",", "$", "limitfrom", "=", "0", ",", "$", "limitnum", "=", "0", ")", "{", "global", "$", "CFG", ",", "$", "PAGE", ",", "$", "USER", ";", "// Check if messaging is enabled.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "$", "systemcontext", "=", "context_system", "::", "instance", "(", ")", ";", "$", "params", "=", "array", "(", "'userid'", "=>", "$", "userid", ",", "'limitfrom'", "=>", "$", "limitfrom", ",", "'limitnum'", "=>", "$", "limitnum", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "data_for_messagearea_contacts_parameters", "(", ")", ",", "$", "params", ")", ";", "self", "::", "validate_context", "(", "$", "systemcontext", ")", ";", "if", "(", "(", "$", "USER", "->", "id", "!=", "$", "params", "[", "'userid'", "]", ")", "&&", "!", "has_capability", "(", "'moodle/site:readallmessages'", ",", "$", "systemcontext", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'You do not have permission to perform this action.'", ")", ";", "}", "$", "contacts", "=", "\\", "core_message", "\\", "api", "::", "get_contacts", "(", "$", "params", "[", "'userid'", "]", ",", "$", "params", "[", "'limitfrom'", "]", ",", "$", "params", "[", "'limitnum'", "]", ")", ";", "$", "contacts", "=", "new", "\\", "core_message", "\\", "output", "\\", "messagearea", "\\", "contacts", "(", "null", ",", "$", "contacts", ")", ";", "$", "renderer", "=", "$", "PAGE", "->", "get_renderer", "(", "'core_message'", ")", ";", "return", "$", "contacts", "->", "export_for_template", "(", "$", "renderer", ")", ";", "}" ]
Get messagearea contacts parameters. @deprecated since 3.6 @param int $userid The id of the user who we are viewing conversations for @param int $limitfrom @param int $limitnum @return stdClass @throws moodle_exception @since 3.2
[ "Get", "messagearea", "contacts", "parameters", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L2235-L2262
216,181
moodle/moodle
message/externallib.php
core_message_external.data_for_messagearea_messages_parameters
public static function data_for_messagearea_messages_parameters() { return new external_function_parameters( array( 'currentuserid' => new external_value(PARAM_INT, 'The current user\'s id'), 'otheruserid' => new external_value(PARAM_INT, 'The other user\'s id'), 'limitfrom' => new external_value(PARAM_INT, 'Limit from', VALUE_DEFAULT, 0), 'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0), 'newest' => new external_value(PARAM_BOOL, 'Newest first?', VALUE_DEFAULT, false), 'timefrom' => new external_value(PARAM_INT, 'The timestamp from which the messages were created', VALUE_DEFAULT, 0), ) ); }
php
public static function data_for_messagearea_messages_parameters() { return new external_function_parameters( array( 'currentuserid' => new external_value(PARAM_INT, 'The current user\'s id'), 'otheruserid' => new external_value(PARAM_INT, 'The other user\'s id'), 'limitfrom' => new external_value(PARAM_INT, 'Limit from', VALUE_DEFAULT, 0), 'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0), 'newest' => new external_value(PARAM_BOOL, 'Newest first?', VALUE_DEFAULT, false), 'timefrom' => new external_value(PARAM_INT, 'The timestamp from which the messages were created', VALUE_DEFAULT, 0), ) ); }
[ "public", "static", "function", "data_for_messagearea_messages_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'currentuserid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The current user\\'s id'", ")", ",", "'otheruserid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The other user\\'s id'", ")", ",", "'limitfrom'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Limit from'", ",", "VALUE_DEFAULT", ",", "0", ")", ",", "'limitnum'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Limit number'", ",", "VALUE_DEFAULT", ",", "0", ")", ",", "'newest'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Newest first?'", ",", "VALUE_DEFAULT", ",", "false", ")", ",", "'timefrom'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The timestamp from which the messages were created'", ",", "VALUE_DEFAULT", ",", "0", ")", ",", ")", ")", ";", "}" ]
The messagearea messages parameters. @deprecated since 3.6 @return external_function_parameters @since 3.2
[ "The", "messagearea", "messages", "parameters", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L2291-L2303
216,182
moodle/moodle
message/externallib.php
core_message_external.data_for_messagearea_messages
public static function data_for_messagearea_messages($currentuserid, $otheruserid, $limitfrom = 0, $limitnum = 0, $newest = false, $timefrom = 0) { global $CFG, $PAGE, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $systemcontext = context_system::instance(); $params = array( 'currentuserid' => $currentuserid, 'otheruserid' => $otheruserid, 'limitfrom' => $limitfrom, 'limitnum' => $limitnum, 'newest' => $newest, 'timefrom' => $timefrom, ); $params = self::validate_parameters(self::data_for_messagearea_messages_parameters(), $params); self::validate_context($systemcontext); if (($USER->id != $params['currentuserid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } if ($params['newest']) { $sort = 'timecreated DESC'; } else { $sort = 'timecreated ASC'; } // We need to enforce a one second delay on messages to avoid race conditions of current // messages still being sent. // // There is a chance that we could request messages before the current time's // second has elapsed and while other messages are being sent in that same second. In which // case those messages will be lost. // // Instead we ignore the current time in the result set to ensure that second is allowed to finish. if (!empty($params['timefrom'])) { $timeto = time() - 1; } else { $timeto = 0; } // No requesting messages from the current time, as stated above. if ($params['timefrom'] == time()) { $messages = []; } else { $messages = \core_message\api::get_messages($params['currentuserid'], $params['otheruserid'], $params['limitfrom'], $params['limitnum'], $sort, $params['timefrom'], $timeto); } $messages = new \core_message\output\messagearea\messages($params['currentuserid'], $params['otheruserid'], $messages); $renderer = $PAGE->get_renderer('core_message'); return $messages->export_for_template($renderer); }
php
public static function data_for_messagearea_messages($currentuserid, $otheruserid, $limitfrom = 0, $limitnum = 0, $newest = false, $timefrom = 0) { global $CFG, $PAGE, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $systemcontext = context_system::instance(); $params = array( 'currentuserid' => $currentuserid, 'otheruserid' => $otheruserid, 'limitfrom' => $limitfrom, 'limitnum' => $limitnum, 'newest' => $newest, 'timefrom' => $timefrom, ); $params = self::validate_parameters(self::data_for_messagearea_messages_parameters(), $params); self::validate_context($systemcontext); if (($USER->id != $params['currentuserid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } if ($params['newest']) { $sort = 'timecreated DESC'; } else { $sort = 'timecreated ASC'; } // We need to enforce a one second delay on messages to avoid race conditions of current // messages still being sent. // // There is a chance that we could request messages before the current time's // second has elapsed and while other messages are being sent in that same second. In which // case those messages will be lost. // // Instead we ignore the current time in the result set to ensure that second is allowed to finish. if (!empty($params['timefrom'])) { $timeto = time() - 1; } else { $timeto = 0; } // No requesting messages from the current time, as stated above. if ($params['timefrom'] == time()) { $messages = []; } else { $messages = \core_message\api::get_messages($params['currentuserid'], $params['otheruserid'], $params['limitfrom'], $params['limitnum'], $sort, $params['timefrom'], $timeto); } $messages = new \core_message\output\messagearea\messages($params['currentuserid'], $params['otheruserid'], $messages); $renderer = $PAGE->get_renderer('core_message'); return $messages->export_for_template($renderer); }
[ "public", "static", "function", "data_for_messagearea_messages", "(", "$", "currentuserid", ",", "$", "otheruserid", ",", "$", "limitfrom", "=", "0", ",", "$", "limitnum", "=", "0", ",", "$", "newest", "=", "false", ",", "$", "timefrom", "=", "0", ")", "{", "global", "$", "CFG", ",", "$", "PAGE", ",", "$", "USER", ";", "// Check if messaging is enabled.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "$", "systemcontext", "=", "context_system", "::", "instance", "(", ")", ";", "$", "params", "=", "array", "(", "'currentuserid'", "=>", "$", "currentuserid", ",", "'otheruserid'", "=>", "$", "otheruserid", ",", "'limitfrom'", "=>", "$", "limitfrom", ",", "'limitnum'", "=>", "$", "limitnum", ",", "'newest'", "=>", "$", "newest", ",", "'timefrom'", "=>", "$", "timefrom", ",", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "data_for_messagearea_messages_parameters", "(", ")", ",", "$", "params", ")", ";", "self", "::", "validate_context", "(", "$", "systemcontext", ")", ";", "if", "(", "(", "$", "USER", "->", "id", "!=", "$", "params", "[", "'currentuserid'", "]", ")", "&&", "!", "has_capability", "(", "'moodle/site:readallmessages'", ",", "$", "systemcontext", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'You do not have permission to perform this action.'", ")", ";", "}", "if", "(", "$", "params", "[", "'newest'", "]", ")", "{", "$", "sort", "=", "'timecreated DESC'", ";", "}", "else", "{", "$", "sort", "=", "'timecreated ASC'", ";", "}", "// We need to enforce a one second delay on messages to avoid race conditions of current", "// messages still being sent.", "//", "// There is a chance that we could request messages before the current time's", "// second has elapsed and while other messages are being sent in that same second. In which", "// case those messages will be lost.", "//", "// Instead we ignore the current time in the result set to ensure that second is allowed to finish.", "if", "(", "!", "empty", "(", "$", "params", "[", "'timefrom'", "]", ")", ")", "{", "$", "timeto", "=", "time", "(", ")", "-", "1", ";", "}", "else", "{", "$", "timeto", "=", "0", ";", "}", "// No requesting messages from the current time, as stated above.", "if", "(", "$", "params", "[", "'timefrom'", "]", "==", "time", "(", ")", ")", "{", "$", "messages", "=", "[", "]", ";", "}", "else", "{", "$", "messages", "=", "\\", "core_message", "\\", "api", "::", "get_messages", "(", "$", "params", "[", "'currentuserid'", "]", ",", "$", "params", "[", "'otheruserid'", "]", ",", "$", "params", "[", "'limitfrom'", "]", ",", "$", "params", "[", "'limitnum'", "]", ",", "$", "sort", ",", "$", "params", "[", "'timefrom'", "]", ",", "$", "timeto", ")", ";", "}", "$", "messages", "=", "new", "\\", "core_message", "\\", "output", "\\", "messagearea", "\\", "messages", "(", "$", "params", "[", "'currentuserid'", "]", ",", "$", "params", "[", "'otheruserid'", "]", ",", "$", "messages", ")", ";", "$", "renderer", "=", "$", "PAGE", "->", "get_renderer", "(", "'core_message'", ")", ";", "return", "$", "messages", "->", "export_for_template", "(", "$", "renderer", ")", ";", "}" ]
Get messagearea messages. @deprecated since 3.6 @param int $currentuserid The current user's id @param int $otheruserid The other user's id @param int $limitfrom @param int $limitnum @param boolean $newest @return stdClass @throws moodle_exception @since 3.2
[ "Get", "messagearea", "messages", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L2318-L2376
216,183
moodle/moodle
message/externallib.php
core_message_external.get_conversation_messages_parameters
public static function get_conversation_messages_parameters() { return new external_function_parameters( array( 'currentuserid' => new external_value(PARAM_INT, 'The current user\'s id'), 'convid' => new external_value(PARAM_INT, 'The conversation id'), 'limitfrom' => new external_value(PARAM_INT, 'Limit from', VALUE_DEFAULT, 0), 'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0), 'newest' => new external_value(PARAM_BOOL, 'Newest first?', VALUE_DEFAULT, false), 'timefrom' => new external_value(PARAM_INT, 'The timestamp from which the messages were created', VALUE_DEFAULT, 0), ) ); }
php
public static function get_conversation_messages_parameters() { return new external_function_parameters( array( 'currentuserid' => new external_value(PARAM_INT, 'The current user\'s id'), 'convid' => new external_value(PARAM_INT, 'The conversation id'), 'limitfrom' => new external_value(PARAM_INT, 'Limit from', VALUE_DEFAULT, 0), 'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0), 'newest' => new external_value(PARAM_BOOL, 'Newest first?', VALUE_DEFAULT, false), 'timefrom' => new external_value(PARAM_INT, 'The timestamp from which the messages were created', VALUE_DEFAULT, 0), ) ); }
[ "public", "static", "function", "get_conversation_messages_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'currentuserid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The current user\\'s id'", ")", ",", "'convid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The conversation id'", ")", ",", "'limitfrom'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Limit from'", ",", "VALUE_DEFAULT", ",", "0", ")", ",", "'limitnum'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Limit number'", ",", "VALUE_DEFAULT", ",", "0", ")", ",", "'newest'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Newest first?'", ",", "VALUE_DEFAULT", ",", "false", ")", ",", "'timefrom'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The timestamp from which the messages were created'", ",", "VALUE_DEFAULT", ",", "0", ")", ",", ")", ")", ";", "}" ]
The conversation messages parameters. @return external_function_parameters @since 3.6
[ "The", "conversation", "messages", "parameters", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L2418-L2430
216,184
moodle/moodle
message/externallib.php
core_message_external.get_conversation_messages
public static function get_conversation_messages(int $currentuserid, int $convid, int $limitfrom = 0, int $limitnum = 0, bool $newest = false, int $timefrom = 0) { global $CFG, $PAGE, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $systemcontext = context_system::instance(); $params = array( 'currentuserid' => $currentuserid, 'convid' => $convid, 'limitfrom' => $limitfrom, 'limitnum' => $limitnum, 'newest' => $newest, 'timefrom' => $timefrom, ); $params = self::validate_parameters(self::get_conversation_messages_parameters(), $params); self::validate_context($systemcontext); if (($USER->id != $params['currentuserid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } $sort = $newest ? 'timecreated DESC' : 'timecreated ASC'; // We need to enforce a one second delay on messages to avoid race conditions of current // messages still being sent. // // There is a chance that we could request messages before the current time's // second has elapsed and while other messages are being sent in that same second. In which // case those messages will be lost. // // Instead we ignore the current time in the result set to ensure that second is allowed to finish. $timeto = empty($params['timefrom']) ? 0 : time() - 1; // No requesting messages from the current time, as stated above. if ($params['timefrom'] == time()) { $messages = []; } else { $messages = \core_message\api::get_conversation_messages( $params['currentuserid'], $params['convid'], $params['limitfrom'], $params['limitnum'], $sort, $params['timefrom'], $timeto); } return $messages; }
php
public static function get_conversation_messages(int $currentuserid, int $convid, int $limitfrom = 0, int $limitnum = 0, bool $newest = false, int $timefrom = 0) { global $CFG, $PAGE, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $systemcontext = context_system::instance(); $params = array( 'currentuserid' => $currentuserid, 'convid' => $convid, 'limitfrom' => $limitfrom, 'limitnum' => $limitnum, 'newest' => $newest, 'timefrom' => $timefrom, ); $params = self::validate_parameters(self::get_conversation_messages_parameters(), $params); self::validate_context($systemcontext); if (($USER->id != $params['currentuserid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } $sort = $newest ? 'timecreated DESC' : 'timecreated ASC'; // We need to enforce a one second delay on messages to avoid race conditions of current // messages still being sent. // // There is a chance that we could request messages before the current time's // second has elapsed and while other messages are being sent in that same second. In which // case those messages will be lost. // // Instead we ignore the current time in the result set to ensure that second is allowed to finish. $timeto = empty($params['timefrom']) ? 0 : time() - 1; // No requesting messages from the current time, as stated above. if ($params['timefrom'] == time()) { $messages = []; } else { $messages = \core_message\api::get_conversation_messages( $params['currentuserid'], $params['convid'], $params['limitfrom'], $params['limitnum'], $sort, $params['timefrom'], $timeto); } return $messages; }
[ "public", "static", "function", "get_conversation_messages", "(", "int", "$", "currentuserid", ",", "int", "$", "convid", ",", "int", "$", "limitfrom", "=", "0", ",", "int", "$", "limitnum", "=", "0", ",", "bool", "$", "newest", "=", "false", ",", "int", "$", "timefrom", "=", "0", ")", "{", "global", "$", "CFG", ",", "$", "PAGE", ",", "$", "USER", ";", "// Check if messaging is enabled.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "$", "systemcontext", "=", "context_system", "::", "instance", "(", ")", ";", "$", "params", "=", "array", "(", "'currentuserid'", "=>", "$", "currentuserid", ",", "'convid'", "=>", "$", "convid", ",", "'limitfrom'", "=>", "$", "limitfrom", ",", "'limitnum'", "=>", "$", "limitnum", ",", "'newest'", "=>", "$", "newest", ",", "'timefrom'", "=>", "$", "timefrom", ",", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_conversation_messages_parameters", "(", ")", ",", "$", "params", ")", ";", "self", "::", "validate_context", "(", "$", "systemcontext", ")", ";", "if", "(", "(", "$", "USER", "->", "id", "!=", "$", "params", "[", "'currentuserid'", "]", ")", "&&", "!", "has_capability", "(", "'moodle/site:readallmessages'", ",", "$", "systemcontext", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'You do not have permission to perform this action.'", ")", ";", "}", "$", "sort", "=", "$", "newest", "?", "'timecreated DESC'", ":", "'timecreated ASC'", ";", "// We need to enforce a one second delay on messages to avoid race conditions of current", "// messages still being sent.", "//", "// There is a chance that we could request messages before the current time's", "// second has elapsed and while other messages are being sent in that same second. In which", "// case those messages will be lost.", "//", "// Instead we ignore the current time in the result set to ensure that second is allowed to finish.", "$", "timeto", "=", "empty", "(", "$", "params", "[", "'timefrom'", "]", ")", "?", "0", ":", "time", "(", ")", "-", "1", ";", "// No requesting messages from the current time, as stated above.", "if", "(", "$", "params", "[", "'timefrom'", "]", "==", "time", "(", ")", ")", "{", "$", "messages", "=", "[", "]", ";", "}", "else", "{", "$", "messages", "=", "\\", "core_message", "\\", "api", "::", "get_conversation_messages", "(", "$", "params", "[", "'currentuserid'", "]", ",", "$", "params", "[", "'convid'", "]", ",", "$", "params", "[", "'limitfrom'", "]", ",", "$", "params", "[", "'limitnum'", "]", ",", "$", "sort", ",", "$", "params", "[", "'timefrom'", "]", ",", "$", "timeto", ")", ";", "}", "return", "$", "messages", ";", "}" ]
Get conversation messages. @param int $currentuserid The current user's id. @param int $convid The conversation id. @param int $limitfrom Return a subset of records, starting at this point (optional). @param int $limitnum Return a subset comprising this many records in total (optional, required if $limitfrom is set). @param bool $newest True for getting first newest messages, false otherwise. @param int $timefrom The time from the conversation messages to get. @return stdClass The messages and members who have sent some of these messages. @throws moodle_exception @since 3.6
[ "Get", "conversation", "messages", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L2445-L2498
216,185
moodle/moodle
message/externallib.php
core_message_external.get_user_contacts_parameters
public static function get_user_contacts_parameters() { return new external_function_parameters( array( 'userid' => new external_value(PARAM_INT, 'The id of the user who we retrieving the contacts for'), 'limitfrom' => new external_value(PARAM_INT, 'Limit from', VALUE_DEFAULT, 0), 'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0) ) ); }
php
public static function get_user_contacts_parameters() { return new external_function_parameters( array( 'userid' => new external_value(PARAM_INT, 'The id of the user who we retrieving the contacts for'), 'limitfrom' => new external_value(PARAM_INT, 'Limit from', VALUE_DEFAULT, 0), 'limitnum' => new external_value(PARAM_INT, 'Limit number', VALUE_DEFAULT, 0) ) ); }
[ "public", "static", "function", "get_user_contacts_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The id of the user who we retrieving the contacts for'", ")", ",", "'limitfrom'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Limit from'", ",", "VALUE_DEFAULT", ",", "0", ")", ",", "'limitnum'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Limit number'", ",", "VALUE_DEFAULT", ",", "0", ")", ")", ")", ";", "}" ]
The user contacts return parameters. @return external_function_parameters
[ "The", "user", "contacts", "return", "parameters", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L2525-L2533
216,186
moodle/moodle
message/externallib.php
core_message_external.get_user_contacts
public static function get_user_contacts(int $userid, int $limitfrom = 0, int $limitnum = 0) { global $CFG, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $systemcontext = context_system::instance(); $params = array( 'userid' => $userid, 'limitfrom' => $limitfrom, 'limitnum' => $limitnum ); $params = self::validate_parameters(self::get_user_contacts_parameters(), $params); self::validate_context($systemcontext); if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } return \core_message\api::get_user_contacts($params['userid'], $params['limitfrom'], $params['limitnum']); }
php
public static function get_user_contacts(int $userid, int $limitfrom = 0, int $limitnum = 0) { global $CFG, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $systemcontext = context_system::instance(); $params = array( 'userid' => $userid, 'limitfrom' => $limitfrom, 'limitnum' => $limitnum ); $params = self::validate_parameters(self::get_user_contacts_parameters(), $params); self::validate_context($systemcontext); if (($USER->id != $params['userid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } return \core_message\api::get_user_contacts($params['userid'], $params['limitfrom'], $params['limitnum']); }
[ "public", "static", "function", "get_user_contacts", "(", "int", "$", "userid", ",", "int", "$", "limitfrom", "=", "0", ",", "int", "$", "limitnum", "=", "0", ")", "{", "global", "$", "CFG", ",", "$", "USER", ";", "// Check if messaging is enabled.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "$", "systemcontext", "=", "context_system", "::", "instance", "(", ")", ";", "$", "params", "=", "array", "(", "'userid'", "=>", "$", "userid", ",", "'limitfrom'", "=>", "$", "limitfrom", ",", "'limitnum'", "=>", "$", "limitnum", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_user_contacts_parameters", "(", ")", ",", "$", "params", ")", ";", "self", "::", "validate_context", "(", "$", "systemcontext", ")", ";", "if", "(", "(", "$", "USER", "->", "id", "!=", "$", "params", "[", "'userid'", "]", ")", "&&", "!", "has_capability", "(", "'moodle/site:readallmessages'", ",", "$", "systemcontext", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'You do not have permission to perform this action.'", ")", ";", "}", "return", "\\", "core_message", "\\", "api", "::", "get_user_contacts", "(", "$", "params", "[", "'userid'", "]", ",", "$", "params", "[", "'limitfrom'", "]", ",", "$", "params", "[", "'limitnum'", "]", ")", ";", "}" ]
Get user contacts. @param int $userid The id of the user who we are viewing conversations for @param int $limitfrom @param int $limitnum @return array @throws moodle_exception
[ "Get", "user", "contacts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L2544-L2567
216,187
moodle/moodle
message/externallib.php
core_message_external.data_for_messagearea_get_most_recent_message
public static function data_for_messagearea_get_most_recent_message($currentuserid, $otheruserid) { global $CFG, $PAGE, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $systemcontext = context_system::instance(); $params = array( 'currentuserid' => $currentuserid, 'otheruserid' => $otheruserid ); $params = self::validate_parameters(self::data_for_messagearea_get_most_recent_message_parameters(), $params); self::validate_context($systemcontext); if (($USER->id != $params['currentuserid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } $message = \core_message\api::get_most_recent_message($params['currentuserid'], $params['otheruserid']); $message = new \core_message\output\messagearea\message($message); $renderer = $PAGE->get_renderer('core_message'); return $message->export_for_template($renderer); }
php
public static function data_for_messagearea_get_most_recent_message($currentuserid, $otheruserid) { global $CFG, $PAGE, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $systemcontext = context_system::instance(); $params = array( 'currentuserid' => $currentuserid, 'otheruserid' => $otheruserid ); $params = self::validate_parameters(self::data_for_messagearea_get_most_recent_message_parameters(), $params); self::validate_context($systemcontext); if (($USER->id != $params['currentuserid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } $message = \core_message\api::get_most_recent_message($params['currentuserid'], $params['otheruserid']); $message = new \core_message\output\messagearea\message($message); $renderer = $PAGE->get_renderer('core_message'); return $message->export_for_template($renderer); }
[ "public", "static", "function", "data_for_messagearea_get_most_recent_message", "(", "$", "currentuserid", ",", "$", "otheruserid", ")", "{", "global", "$", "CFG", ",", "$", "PAGE", ",", "$", "USER", ";", "// Check if messaging is enabled.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "$", "systemcontext", "=", "context_system", "::", "instance", "(", ")", ";", "$", "params", "=", "array", "(", "'currentuserid'", "=>", "$", "currentuserid", ",", "'otheruserid'", "=>", "$", "otheruserid", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "data_for_messagearea_get_most_recent_message_parameters", "(", ")", ",", "$", "params", ")", ";", "self", "::", "validate_context", "(", "$", "systemcontext", ")", ";", "if", "(", "(", "$", "USER", "->", "id", "!=", "$", "params", "[", "'currentuserid'", "]", ")", "&&", "!", "has_capability", "(", "'moodle/site:readallmessages'", ",", "$", "systemcontext", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'You do not have permission to perform this action.'", ")", ";", "}", "$", "message", "=", "\\", "core_message", "\\", "api", "::", "get_most_recent_message", "(", "$", "params", "[", "'currentuserid'", "]", ",", "$", "params", "[", "'otheruserid'", "]", ")", ";", "$", "message", "=", "new", "\\", "core_message", "\\", "output", "\\", "messagearea", "\\", "message", "(", "$", "message", ")", ";", "$", "renderer", "=", "$", "PAGE", "->", "get_renderer", "(", "'core_message'", ")", ";", "return", "$", "message", "->", "export_for_template", "(", "$", "renderer", ")", ";", "}" ]
Get the most recent message in a conversation. @deprecated since 3.6 @param int $currentuserid The current user's id @param int $otheruserid The other user's id @return stdClass @throws moodle_exception @since 3.2
[ "Get", "the", "most", "recent", "message", "in", "a", "conversation", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L2606-L2632
216,188
moodle/moodle
message/externallib.php
core_message_external.data_for_messagearea_get_profile
public static function data_for_messagearea_get_profile($currentuserid, $otheruserid) { global $CFG, $PAGE, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $systemcontext = context_system::instance(); $params = array( 'currentuserid' => $currentuserid, 'otheruserid' => $otheruserid ); $params = self::validate_parameters(self::data_for_messagearea_get_profile_parameters(), $params); self::validate_context($systemcontext); if (($USER->id != $params['currentuserid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } $profile = \core_message\api::get_profile($params['currentuserid'], $params['otheruserid']); $profile = new \core_message\output\messagearea\profile($profile); $renderer = $PAGE->get_renderer('core_message'); return $profile->export_for_template($renderer); }
php
public static function data_for_messagearea_get_profile($currentuserid, $otheruserid) { global $CFG, $PAGE, $USER; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $systemcontext = context_system::instance(); $params = array( 'currentuserid' => $currentuserid, 'otheruserid' => $otheruserid ); $params = self::validate_parameters(self::data_for_messagearea_get_profile_parameters(), $params); self::validate_context($systemcontext); if (($USER->id != $params['currentuserid']) && !has_capability('moodle/site:readallmessages', $systemcontext)) { throw new moodle_exception('You do not have permission to perform this action.'); } $profile = \core_message\api::get_profile($params['currentuserid'], $params['otheruserid']); $profile = new \core_message\output\messagearea\profile($profile); $renderer = $PAGE->get_renderer('core_message'); return $profile->export_for_template($renderer); }
[ "public", "static", "function", "data_for_messagearea_get_profile", "(", "$", "currentuserid", ",", "$", "otheruserid", ")", "{", "global", "$", "CFG", ",", "$", "PAGE", ",", "$", "USER", ";", "// Check if messaging is enabled.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "$", "systemcontext", "=", "context_system", "::", "instance", "(", ")", ";", "$", "params", "=", "array", "(", "'currentuserid'", "=>", "$", "currentuserid", ",", "'otheruserid'", "=>", "$", "otheruserid", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "data_for_messagearea_get_profile_parameters", "(", ")", ",", "$", "params", ")", ";", "self", "::", "validate_context", "(", "$", "systemcontext", ")", ";", "if", "(", "(", "$", "USER", "->", "id", "!=", "$", "params", "[", "'currentuserid'", "]", ")", "&&", "!", "has_capability", "(", "'moodle/site:readallmessages'", ",", "$", "systemcontext", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'You do not have permission to perform this action.'", ")", ";", "}", "$", "profile", "=", "\\", "core_message", "\\", "api", "::", "get_profile", "(", "$", "params", "[", "'currentuserid'", "]", ",", "$", "params", "[", "'otheruserid'", "]", ")", ";", "$", "profile", "=", "new", "\\", "core_message", "\\", "output", "\\", "messagearea", "\\", "profile", "(", "$", "profile", ")", ";", "$", "renderer", "=", "$", "PAGE", "->", "get_renderer", "(", "'core_message'", ")", ";", "return", "$", "profile", "->", "export_for_template", "(", "$", "renderer", ")", ";", "}" ]
Get the profile information for a contact. @deprecated since 3.6 @param int $currentuserid The current user's id @param int $otheruserid The id of the user whose profile we are viewing @return stdClass @throws moodle_exception @since 3.2
[ "Get", "the", "profile", "information", "for", "a", "contact", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L2680-L2706
216,189
moodle/moodle
message/externallib.php
core_message_external.data_for_messagearea_get_profile_returns
public static function data_for_messagearea_get_profile_returns() { return new external_single_structure( array( 'userid' => new external_value(PARAM_INT, 'The id of the user whose profile we are viewing'), 'email' => new external_value(core_user::get_property_type('email'), 'An email address'), 'country' => new external_value(PARAM_TEXT, 'Home country of the user'), 'city' => new external_value(core_user::get_property_type('city'), 'Home city of the user'), 'fullname' => new external_value(PARAM_NOTAGS, 'The user\'s name'), 'profileimageurl' => new external_value(PARAM_URL, 'User picture URL'), 'profileimageurlsmall' => new external_value(PARAM_URL, 'Small user picture URL'), 'showonlinestatus' => new external_value(PARAM_BOOL, 'Show the user\'s online status?'), 'isonline' => new external_value(PARAM_BOOL, 'The user\'s online status'), 'isblocked' => new external_value(PARAM_BOOL, 'Is the user blocked?'), 'iscontact' => new external_value(PARAM_BOOL, 'Is the user a contact?') ) ); }
php
public static function data_for_messagearea_get_profile_returns() { return new external_single_structure( array( 'userid' => new external_value(PARAM_INT, 'The id of the user whose profile we are viewing'), 'email' => new external_value(core_user::get_property_type('email'), 'An email address'), 'country' => new external_value(PARAM_TEXT, 'Home country of the user'), 'city' => new external_value(core_user::get_property_type('city'), 'Home city of the user'), 'fullname' => new external_value(PARAM_NOTAGS, 'The user\'s name'), 'profileimageurl' => new external_value(PARAM_URL, 'User picture URL'), 'profileimageurlsmall' => new external_value(PARAM_URL, 'Small user picture URL'), 'showonlinestatus' => new external_value(PARAM_BOOL, 'Show the user\'s online status?'), 'isonline' => new external_value(PARAM_BOOL, 'The user\'s online status'), 'isblocked' => new external_value(PARAM_BOOL, 'Is the user blocked?'), 'iscontact' => new external_value(PARAM_BOOL, 'Is the user a contact?') ) ); }
[ "public", "static", "function", "data_for_messagearea_get_profile_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'userid'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'The id of the user whose profile we are viewing'", ")", ",", "'email'", "=>", "new", "external_value", "(", "core_user", "::", "get_property_type", "(", "'email'", ")", ",", "'An email address'", ")", ",", "'country'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'Home country of the user'", ")", ",", "'city'", "=>", "new", "external_value", "(", "core_user", "::", "get_property_type", "(", "'city'", ")", ",", "'Home city of the user'", ")", ",", "'fullname'", "=>", "new", "external_value", "(", "PARAM_NOTAGS", ",", "'The user\\'s name'", ")", ",", "'profileimageurl'", "=>", "new", "external_value", "(", "PARAM_URL", ",", "'User picture URL'", ")", ",", "'profileimageurlsmall'", "=>", "new", "external_value", "(", "PARAM_URL", ",", "'Small user picture URL'", ")", ",", "'showonlinestatus'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Show the user\\'s online status?'", ")", ",", "'isonline'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'The user\\'s online status'", ")", ",", "'isblocked'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Is the user blocked?'", ")", ",", "'iscontact'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'Is the user a contact?'", ")", ")", ")", ";", "}" ]
The get profile return structure. @deprecated since 3.6 @return external_single_structure @since 3.2
[ "The", "get", "profile", "return", "structure", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L2715-L2731
216,190
moodle/moodle
message/externallib.php
core_message_external.get_contacts_returns
public static function get_contacts_returns() { return new external_single_structure( array( 'online' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'User ID'), 'fullname' => new external_value(PARAM_NOTAGS, 'User full name'), 'profileimageurl' => new external_value(PARAM_URL, 'User picture URL', VALUE_OPTIONAL), 'profileimageurlsmall' => new external_value(PARAM_URL, 'Small user picture URL', VALUE_OPTIONAL), 'unread' => new external_value(PARAM_INT, 'Unread message count') ) ), 'List of online contacts' ), 'offline' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'User ID'), 'fullname' => new external_value(PARAM_NOTAGS, 'User full name'), 'profileimageurl' => new external_value(PARAM_URL, 'User picture URL', VALUE_OPTIONAL), 'profileimageurlsmall' => new external_value(PARAM_URL, 'Small user picture URL', VALUE_OPTIONAL), 'unread' => new external_value(PARAM_INT, 'Unread message count') ) ), 'List of offline contacts' ), 'strangers' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'User ID'), 'fullname' => new external_value(PARAM_NOTAGS, 'User full name'), 'profileimageurl' => new external_value(PARAM_URL, 'User picture URL', VALUE_OPTIONAL), 'profileimageurlsmall' => new external_value(PARAM_URL, 'Small user picture URL', VALUE_OPTIONAL), 'unread' => new external_value(PARAM_INT, 'Unread message count') ) ), 'List of users that are not in the user\'s contact list but have sent a message' ) ) ); }
php
public static function get_contacts_returns() { return new external_single_structure( array( 'online' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'User ID'), 'fullname' => new external_value(PARAM_NOTAGS, 'User full name'), 'profileimageurl' => new external_value(PARAM_URL, 'User picture URL', VALUE_OPTIONAL), 'profileimageurlsmall' => new external_value(PARAM_URL, 'Small user picture URL', VALUE_OPTIONAL), 'unread' => new external_value(PARAM_INT, 'Unread message count') ) ), 'List of online contacts' ), 'offline' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'User ID'), 'fullname' => new external_value(PARAM_NOTAGS, 'User full name'), 'profileimageurl' => new external_value(PARAM_URL, 'User picture URL', VALUE_OPTIONAL), 'profileimageurlsmall' => new external_value(PARAM_URL, 'Small user picture URL', VALUE_OPTIONAL), 'unread' => new external_value(PARAM_INT, 'Unread message count') ) ), 'List of offline contacts' ), 'strangers' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'User ID'), 'fullname' => new external_value(PARAM_NOTAGS, 'User full name'), 'profileimageurl' => new external_value(PARAM_URL, 'User picture URL', VALUE_OPTIONAL), 'profileimageurlsmall' => new external_value(PARAM_URL, 'Small user picture URL', VALUE_OPTIONAL), 'unread' => new external_value(PARAM_INT, 'Unread message count') ) ), 'List of users that are not in the user\'s contact list but have sent a message' ) ) ); }
[ "public", "static", "function", "get_contacts_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'online'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'User ID'", ")", ",", "'fullname'", "=>", "new", "external_value", "(", "PARAM_NOTAGS", ",", "'User full name'", ")", ",", "'profileimageurl'", "=>", "new", "external_value", "(", "PARAM_URL", ",", "'User picture URL'", ",", "VALUE_OPTIONAL", ")", ",", "'profileimageurlsmall'", "=>", "new", "external_value", "(", "PARAM_URL", ",", "'Small user picture URL'", ",", "VALUE_OPTIONAL", ")", ",", "'unread'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Unread message count'", ")", ")", ")", ",", "'List of online contacts'", ")", ",", "'offline'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'User ID'", ")", ",", "'fullname'", "=>", "new", "external_value", "(", "PARAM_NOTAGS", ",", "'User full name'", ")", ",", "'profileimageurl'", "=>", "new", "external_value", "(", "PARAM_URL", ",", "'User picture URL'", ",", "VALUE_OPTIONAL", ")", ",", "'profileimageurlsmall'", "=>", "new", "external_value", "(", "PARAM_URL", ",", "'Small user picture URL'", ",", "VALUE_OPTIONAL", ")", ",", "'unread'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Unread message count'", ")", ")", ")", ",", "'List of offline contacts'", ")", ",", "'strangers'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'User ID'", ")", ",", "'fullname'", "=>", "new", "external_value", "(", "PARAM_NOTAGS", ",", "'User full name'", ")", ",", "'profileimageurl'", "=>", "new", "external_value", "(", "PARAM_URL", ",", "'User picture URL'", ",", "VALUE_OPTIONAL", ")", ",", "'profileimageurlsmall'", "=>", "new", "external_value", "(", "PARAM_URL", ",", "'Small user picture URL'", ",", "VALUE_OPTIONAL", ")", ",", "'unread'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Unread message count'", ")", ")", ")", ",", "'List of users that are not in the user\\'s contact list but have sent a message'", ")", ")", ")", ";", "}" ]
Get contacts return description. @deprecated since 3.6 @return external_description @since Moodle 2.5
[ "Get", "contacts", "return", "description", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L2842-L2883
216,191
moodle/moodle
message/externallib.php
core_message_external.search_contacts
public static function search_contacts($searchtext, $onlymycourses = false) { global $CFG, $USER, $PAGE; require_once($CFG->dirroot . '/user/lib.php'); // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } require_once($CFG->libdir . '/enrollib.php'); $params = array('searchtext' => $searchtext, 'onlymycourses' => $onlymycourses); $params = self::validate_parameters(self::search_contacts_parameters(), $params); // Extra validation, we do not allow empty queries. if ($params['searchtext'] === '') { throw new moodle_exception('querystringcannotbeempty'); } $courseids = array(); if ($params['onlymycourses']) { $mycourses = enrol_get_my_courses(array('id')); foreach ($mycourses as $mycourse) { $courseids[] = $mycourse->id; } } else { $courseids[] = SITEID; } // Retrieving the users matching the query. $users = message_search_users($courseids, $params['searchtext']); $results = array(); foreach ($users as $user) { $results[$user->id] = $user; } // Reorganising information. foreach ($results as &$user) { $newuser = array( 'id' => $user->id, 'fullname' => fullname($user) ); // Avoid undefined property notice as phone not specified. $user->phone1 = null; $user->phone2 = null; $userpicture = new user_picture($user); $userpicture->size = 1; // Size f1. $newuser['profileimageurl'] = $userpicture->get_url($PAGE)->out(false); $userpicture->size = 0; // Size f2. $newuser['profileimageurlsmall'] = $userpicture->get_url($PAGE)->out(false); $user = $newuser; } return $results; }
php
public static function search_contacts($searchtext, $onlymycourses = false) { global $CFG, $USER, $PAGE; require_once($CFG->dirroot . '/user/lib.php'); // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } require_once($CFG->libdir . '/enrollib.php'); $params = array('searchtext' => $searchtext, 'onlymycourses' => $onlymycourses); $params = self::validate_parameters(self::search_contacts_parameters(), $params); // Extra validation, we do not allow empty queries. if ($params['searchtext'] === '') { throw new moodle_exception('querystringcannotbeempty'); } $courseids = array(); if ($params['onlymycourses']) { $mycourses = enrol_get_my_courses(array('id')); foreach ($mycourses as $mycourse) { $courseids[] = $mycourse->id; } } else { $courseids[] = SITEID; } // Retrieving the users matching the query. $users = message_search_users($courseids, $params['searchtext']); $results = array(); foreach ($users as $user) { $results[$user->id] = $user; } // Reorganising information. foreach ($results as &$user) { $newuser = array( 'id' => $user->id, 'fullname' => fullname($user) ); // Avoid undefined property notice as phone not specified. $user->phone1 = null; $user->phone2 = null; $userpicture = new user_picture($user); $userpicture->size = 1; // Size f1. $newuser['profileimageurl'] = $userpicture->get_url($PAGE)->out(false); $userpicture->size = 0; // Size f2. $newuser['profileimageurlsmall'] = $userpicture->get_url($PAGE)->out(false); $user = $newuser; } return $results; }
[ "public", "static", "function", "search_contacts", "(", "$", "searchtext", ",", "$", "onlymycourses", "=", "false", ")", "{", "global", "$", "CFG", ",", "$", "USER", ",", "$", "PAGE", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/user/lib.php'", ")", ";", "// Check if messaging is enabled.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/enrollib.php'", ")", ";", "$", "params", "=", "array", "(", "'searchtext'", "=>", "$", "searchtext", ",", "'onlymycourses'", "=>", "$", "onlymycourses", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "search_contacts_parameters", "(", ")", ",", "$", "params", ")", ";", "// Extra validation, we do not allow empty queries.", "if", "(", "$", "params", "[", "'searchtext'", "]", "===", "''", ")", "{", "throw", "new", "moodle_exception", "(", "'querystringcannotbeempty'", ")", ";", "}", "$", "courseids", "=", "array", "(", ")", ";", "if", "(", "$", "params", "[", "'onlymycourses'", "]", ")", "{", "$", "mycourses", "=", "enrol_get_my_courses", "(", "array", "(", "'id'", ")", ")", ";", "foreach", "(", "$", "mycourses", "as", "$", "mycourse", ")", "{", "$", "courseids", "[", "]", "=", "$", "mycourse", "->", "id", ";", "}", "}", "else", "{", "$", "courseids", "[", "]", "=", "SITEID", ";", "}", "// Retrieving the users matching the query.", "$", "users", "=", "message_search_users", "(", "$", "courseids", ",", "$", "params", "[", "'searchtext'", "]", ")", ";", "$", "results", "=", "array", "(", ")", ";", "foreach", "(", "$", "users", "as", "$", "user", ")", "{", "$", "results", "[", "$", "user", "->", "id", "]", "=", "$", "user", ";", "}", "// Reorganising information.", "foreach", "(", "$", "results", "as", "&", "$", "user", ")", "{", "$", "newuser", "=", "array", "(", "'id'", "=>", "$", "user", "->", "id", ",", "'fullname'", "=>", "fullname", "(", "$", "user", ")", ")", ";", "// Avoid undefined property notice as phone not specified.", "$", "user", "->", "phone1", "=", "null", ";", "$", "user", "->", "phone2", "=", "null", ";", "$", "userpicture", "=", "new", "user_picture", "(", "$", "user", ")", ";", "$", "userpicture", "->", "size", "=", "1", ";", "// Size f1.", "$", "newuser", "[", "'profileimageurl'", "]", "=", "$", "userpicture", "->", "get_url", "(", "$", "PAGE", ")", "->", "out", "(", "false", ")", ";", "$", "userpicture", "->", "size", "=", "0", ";", "// Size f2.", "$", "newuser", "[", "'profileimageurlsmall'", "]", "=", "$", "userpicture", "->", "get_url", "(", "$", "PAGE", ")", "->", "out", "(", "false", ")", ";", "$", "user", "=", "$", "newuser", ";", "}", "return", "$", "results", ";", "}" ]
Search contacts. @param string $searchtext query string. @param bool $onlymycourses limit the search to the user's courses only. @return external_description @since Moodle 2.5
[ "Search", "contacts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L2918-L2975
216,192
moodle/moodle
message/externallib.php
core_message_external.search_contacts_returns
public static function search_contacts_returns() { return new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'User ID'), 'fullname' => new external_value(PARAM_NOTAGS, 'User full name'), 'profileimageurl' => new external_value(PARAM_URL, 'User picture URL', VALUE_OPTIONAL), 'profileimageurlsmall' => new external_value(PARAM_URL, 'Small user picture URL', VALUE_OPTIONAL) ) ), 'List of contacts' ); }
php
public static function search_contacts_returns() { return new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'User ID'), 'fullname' => new external_value(PARAM_NOTAGS, 'User full name'), 'profileimageurl' => new external_value(PARAM_URL, 'User picture URL', VALUE_OPTIONAL), 'profileimageurlsmall' => new external_value(PARAM_URL, 'Small user picture URL', VALUE_OPTIONAL) ) ), 'List of contacts' ); }
[ "public", "static", "function", "search_contacts_returns", "(", ")", "{", "return", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'User ID'", ")", ",", "'fullname'", "=>", "new", "external_value", "(", "PARAM_NOTAGS", ",", "'User full name'", ")", ",", "'profileimageurl'", "=>", "new", "external_value", "(", "PARAM_URL", ",", "'User picture URL'", ",", "VALUE_OPTIONAL", ")", ",", "'profileimageurlsmall'", "=>", "new", "external_value", "(", "PARAM_URL", ",", "'Small user picture URL'", ",", "VALUE_OPTIONAL", ")", ")", ")", ",", "'List of contacts'", ")", ";", "}" ]
Search contacts return description. @return external_description @since Moodle 2.5
[ "Search", "contacts", "return", "description", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L2983-L2995
216,193
moodle/moodle
message/externallib.php
core_message_external.get_messages_parameters
public static function get_messages_parameters() { return new external_function_parameters( array( 'useridto' => new external_value(PARAM_INT, 'the user id who received the message, 0 for any user', VALUE_REQUIRED), 'useridfrom' => new external_value( PARAM_INT, 'the user id who send the message, 0 for any user. -10 or -20 for no-reply or support user', VALUE_DEFAULT, 0), 'type' => new external_value( PARAM_ALPHA, 'type of message to return, expected values are: notifications, conversations and both', VALUE_DEFAULT, 'both'), 'read' => new external_value(PARAM_BOOL, 'true for getting read messages, false for unread', VALUE_DEFAULT, true), 'newestfirst' => new external_value( PARAM_BOOL, 'true for ordering by newest first, false for oldest first', VALUE_DEFAULT, true), 'limitfrom' => new external_value(PARAM_INT, 'limit from', VALUE_DEFAULT, 0), 'limitnum' => new external_value(PARAM_INT, 'limit number', VALUE_DEFAULT, 0) ) ); }
php
public static function get_messages_parameters() { return new external_function_parameters( array( 'useridto' => new external_value(PARAM_INT, 'the user id who received the message, 0 for any user', VALUE_REQUIRED), 'useridfrom' => new external_value( PARAM_INT, 'the user id who send the message, 0 for any user. -10 or -20 for no-reply or support user', VALUE_DEFAULT, 0), 'type' => new external_value( PARAM_ALPHA, 'type of message to return, expected values are: notifications, conversations and both', VALUE_DEFAULT, 'both'), 'read' => new external_value(PARAM_BOOL, 'true for getting read messages, false for unread', VALUE_DEFAULT, true), 'newestfirst' => new external_value( PARAM_BOOL, 'true for ordering by newest first, false for oldest first', VALUE_DEFAULT, true), 'limitfrom' => new external_value(PARAM_INT, 'limit from', VALUE_DEFAULT, 0), 'limitnum' => new external_value(PARAM_INT, 'limit number', VALUE_DEFAULT, 0) ) ); }
[ "public", "static", "function", "get_messages_parameters", "(", ")", "{", "return", "new", "external_function_parameters", "(", "array", "(", "'useridto'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'the user id who received the message, 0 for any user'", ",", "VALUE_REQUIRED", ")", ",", "'useridfrom'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'the user id who send the message, 0 for any user. -10 or -20 for no-reply or support user'", ",", "VALUE_DEFAULT", ",", "0", ")", ",", "'type'", "=>", "new", "external_value", "(", "PARAM_ALPHA", ",", "'type of message to return, expected values are: notifications, conversations and both'", ",", "VALUE_DEFAULT", ",", "'both'", ")", ",", "'read'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'true for getting read messages, false for unread'", ",", "VALUE_DEFAULT", ",", "true", ")", ",", "'newestfirst'", "=>", "new", "external_value", "(", "PARAM_BOOL", ",", "'true for ordering by newest first, false for oldest first'", ",", "VALUE_DEFAULT", ",", "true", ")", ",", "'limitfrom'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'limit from'", ",", "VALUE_DEFAULT", ",", "0", ")", ",", "'limitnum'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'limit number'", ",", "VALUE_DEFAULT", ",", "0", ")", ")", ")", ";", "}" ]
Get messages parameters description. @return external_function_parameters @since 2.8
[ "Get", "messages", "parameters", "description", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L3003-L3021
216,194
moodle/moodle
message/externallib.php
core_message_external.get_messages_returns
public static function get_messages_returns() { return new external_single_structure( array( 'messages' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'Message id'), 'useridfrom' => new external_value(PARAM_INT, 'User from id'), 'useridto' => new external_value(PARAM_INT, 'User to id'), 'subject' => new external_value(PARAM_TEXT, 'The message subject'), 'text' => new external_value(PARAM_RAW, 'The message text formated'), 'fullmessage' => new external_value(PARAM_RAW, 'The message'), 'fullmessageformat' => new external_format_value('fullmessage'), 'fullmessagehtml' => new external_value(PARAM_RAW, 'The message in html'), 'smallmessage' => new external_value(PARAM_RAW, 'The shorten message'), 'notification' => new external_value(PARAM_INT, 'Is a notification?'), 'contexturl' => new external_value(PARAM_RAW, 'Context URL'), 'contexturlname' => new external_value(PARAM_TEXT, 'Context URL link name'), 'timecreated' => new external_value(PARAM_INT, 'Time created'), 'timeread' => new external_value(PARAM_INT, 'Time read'), 'usertofullname' => new external_value(PARAM_TEXT, 'User to full name'), 'userfromfullname' => new external_value(PARAM_TEXT, 'User from full name'), 'component' => new external_value(PARAM_TEXT, 'The component that generated the notification', VALUE_OPTIONAL), 'eventtype' => new external_value(PARAM_TEXT, 'The type of notification', VALUE_OPTIONAL), 'customdata' => new external_value(PARAM_RAW, 'Custom data to be passed to the message processor. The data here is serialised using json_encode().', VALUE_OPTIONAL), ), 'message' ) ), 'warnings' => new external_warnings() ) ); }
php
public static function get_messages_returns() { return new external_single_structure( array( 'messages' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'Message id'), 'useridfrom' => new external_value(PARAM_INT, 'User from id'), 'useridto' => new external_value(PARAM_INT, 'User to id'), 'subject' => new external_value(PARAM_TEXT, 'The message subject'), 'text' => new external_value(PARAM_RAW, 'The message text formated'), 'fullmessage' => new external_value(PARAM_RAW, 'The message'), 'fullmessageformat' => new external_format_value('fullmessage'), 'fullmessagehtml' => new external_value(PARAM_RAW, 'The message in html'), 'smallmessage' => new external_value(PARAM_RAW, 'The shorten message'), 'notification' => new external_value(PARAM_INT, 'Is a notification?'), 'contexturl' => new external_value(PARAM_RAW, 'Context URL'), 'contexturlname' => new external_value(PARAM_TEXT, 'Context URL link name'), 'timecreated' => new external_value(PARAM_INT, 'Time created'), 'timeread' => new external_value(PARAM_INT, 'Time read'), 'usertofullname' => new external_value(PARAM_TEXT, 'User to full name'), 'userfromfullname' => new external_value(PARAM_TEXT, 'User from full name'), 'component' => new external_value(PARAM_TEXT, 'The component that generated the notification', VALUE_OPTIONAL), 'eventtype' => new external_value(PARAM_TEXT, 'The type of notification', VALUE_OPTIONAL), 'customdata' => new external_value(PARAM_RAW, 'Custom data to be passed to the message processor. The data here is serialised using json_encode().', VALUE_OPTIONAL), ), 'message' ) ), 'warnings' => new external_warnings() ) ); }
[ "public", "static", "function", "get_messages_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'messages'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Message id'", ")", ",", "'useridfrom'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'User from id'", ")", ",", "'useridto'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'User to id'", ")", ",", "'subject'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'The message subject'", ")", ",", "'text'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'The message text formated'", ")", ",", "'fullmessage'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'The message'", ")", ",", "'fullmessageformat'", "=>", "new", "external_format_value", "(", "'fullmessage'", ")", ",", "'fullmessagehtml'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'The message in html'", ")", ",", "'smallmessage'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'The shorten message'", ")", ",", "'notification'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Is a notification?'", ")", ",", "'contexturl'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Context URL'", ")", ",", "'contexturlname'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'Context URL link name'", ")", ",", "'timecreated'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Time created'", ")", ",", "'timeread'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'Time read'", ")", ",", "'usertofullname'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'User to full name'", ")", ",", "'userfromfullname'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'User from full name'", ")", ",", "'component'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'The component that generated the notification'", ",", "VALUE_OPTIONAL", ")", ",", "'eventtype'", "=>", "new", "external_value", "(", "PARAM_TEXT", ",", "'The type of notification'", ",", "VALUE_OPTIONAL", ")", ",", "'customdata'", "=>", "new", "external_value", "(", "PARAM_RAW", ",", "'Custom data to be passed to the message processor.\n The data here is serialised using json_encode().'", ",", "VALUE_OPTIONAL", ")", ",", ")", ",", "'message'", ")", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ")", ")", ";", "}" ]
Get messages return description. @return external_single_structure @since 2.8
[ "Get", "messages", "return", "description", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L3190-L3223
216,195
moodle/moodle
message/externallib.php
core_message_external.mark_all_notifications_as_read
public static function mark_all_notifications_as_read($useridto, $useridfrom) { global $USER; $params = self::validate_parameters( self::mark_all_notifications_as_read_parameters(), array( 'useridto' => $useridto, 'useridfrom' => $useridfrom, ) ); $context = context_system::instance(); self::validate_context($context); $useridto = $params['useridto']; $useridfrom = $params['useridfrom']; if (!empty($useridto)) { if (core_user::is_real_user($useridto)) { $userto = core_user::get_user($useridto, '*', MUST_EXIST); } else { throw new moodle_exception('invaliduser'); } } if (!empty($useridfrom)) { // We use get_user here because the from user can be the noreply or support user. $userfrom = core_user::get_user($useridfrom, '*', MUST_EXIST); } // Check if the current user is the sender/receiver or just a privileged user. if ($useridto != $USER->id and $useridfrom != $USER->id and // The deleteanymessage cap seems more reasonable here than readallmessages. !has_capability('moodle/site:deleteanymessage', $context)) { throw new moodle_exception('accessdenied', 'admin'); } \core_message\api::mark_all_notifications_as_read($useridto, $useridfrom); return true; }
php
public static function mark_all_notifications_as_read($useridto, $useridfrom) { global $USER; $params = self::validate_parameters( self::mark_all_notifications_as_read_parameters(), array( 'useridto' => $useridto, 'useridfrom' => $useridfrom, ) ); $context = context_system::instance(); self::validate_context($context); $useridto = $params['useridto']; $useridfrom = $params['useridfrom']; if (!empty($useridto)) { if (core_user::is_real_user($useridto)) { $userto = core_user::get_user($useridto, '*', MUST_EXIST); } else { throw new moodle_exception('invaliduser'); } } if (!empty($useridfrom)) { // We use get_user here because the from user can be the noreply or support user. $userfrom = core_user::get_user($useridfrom, '*', MUST_EXIST); } // Check if the current user is the sender/receiver or just a privileged user. if ($useridto != $USER->id and $useridfrom != $USER->id and // The deleteanymessage cap seems more reasonable here than readallmessages. !has_capability('moodle/site:deleteanymessage', $context)) { throw new moodle_exception('accessdenied', 'admin'); } \core_message\api::mark_all_notifications_as_read($useridto, $useridfrom); return true; }
[ "public", "static", "function", "mark_all_notifications_as_read", "(", "$", "useridto", ",", "$", "useridfrom", ")", "{", "global", "$", "USER", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "mark_all_notifications_as_read_parameters", "(", ")", ",", "array", "(", "'useridto'", "=>", "$", "useridto", ",", "'useridfrom'", "=>", "$", "useridfrom", ",", ")", ")", ";", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "useridto", "=", "$", "params", "[", "'useridto'", "]", ";", "$", "useridfrom", "=", "$", "params", "[", "'useridfrom'", "]", ";", "if", "(", "!", "empty", "(", "$", "useridto", ")", ")", "{", "if", "(", "core_user", "::", "is_real_user", "(", "$", "useridto", ")", ")", "{", "$", "userto", "=", "core_user", "::", "get_user", "(", "$", "useridto", ",", "'*'", ",", "MUST_EXIST", ")", ";", "}", "else", "{", "throw", "new", "moodle_exception", "(", "'invaliduser'", ")", ";", "}", "}", "if", "(", "!", "empty", "(", "$", "useridfrom", ")", ")", "{", "// We use get_user here because the from user can be the noreply or support user.", "$", "userfrom", "=", "core_user", "::", "get_user", "(", "$", "useridfrom", ",", "'*'", ",", "MUST_EXIST", ")", ";", "}", "// Check if the current user is the sender/receiver or just a privileged user.", "if", "(", "$", "useridto", "!=", "$", "USER", "->", "id", "and", "$", "useridfrom", "!=", "$", "USER", "->", "id", "and", "// The deleteanymessage cap seems more reasonable here than readallmessages.", "!", "has_capability", "(", "'moodle/site:deleteanymessage'", ",", "$", "context", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'accessdenied'", ",", "'admin'", ")", ";", "}", "\\", "core_message", "\\", "api", "::", "mark_all_notifications_as_read", "(", "$", "useridto", ",", "$", "useridfrom", ")", ";", "return", "true", ";", "}" ]
Mark all notifications as read function. @since 3.2 @throws invalid_parameter_exception @throws moodle_exception @param int $useridto the user id who received the message @param int $useridfrom the user id who send the message. -10 or -20 for no-reply or support user @return external_description
[ "Mark", "all", "notifications", "as", "read", "function", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L3252-L3292
216,196
moodle/moodle
message/externallib.php
core_message_external.get_unread_conversations_count
public static function get_unread_conversations_count($useridto) { global $USER, $CFG; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $params = self::validate_parameters( self::get_unread_conversations_count_parameters(), array('useridto' => $useridto) ); $context = context_system::instance(); self::validate_context($context); $useridto = $params['useridto']; if (!empty($useridto)) { if (core_user::is_real_user($useridto)) { $userto = core_user::get_user($useridto, '*', MUST_EXIST); } else { throw new moodle_exception('invaliduser'); } } else { $useridto = $USER->id; } // Check if the current user is the receiver or just a privileged user. if ($useridto != $USER->id and !has_capability('moodle/site:readallmessages', $context)) { throw new moodle_exception('accessdenied', 'admin'); } return \core_message\api::count_unread_conversations($userto); }
php
public static function get_unread_conversations_count($useridto) { global $USER, $CFG; // Check if messaging is enabled. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $params = self::validate_parameters( self::get_unread_conversations_count_parameters(), array('useridto' => $useridto) ); $context = context_system::instance(); self::validate_context($context); $useridto = $params['useridto']; if (!empty($useridto)) { if (core_user::is_real_user($useridto)) { $userto = core_user::get_user($useridto, '*', MUST_EXIST); } else { throw new moodle_exception('invaliduser'); } } else { $useridto = $USER->id; } // Check if the current user is the receiver or just a privileged user. if ($useridto != $USER->id and !has_capability('moodle/site:readallmessages', $context)) { throw new moodle_exception('accessdenied', 'admin'); } return \core_message\api::count_unread_conversations($userto); }
[ "public", "static", "function", "get_unread_conversations_count", "(", "$", "useridto", ")", "{", "global", "$", "USER", ",", "$", "CFG", ";", "// Check if messaging is enabled.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_unread_conversations_count_parameters", "(", ")", ",", "array", "(", "'useridto'", "=>", "$", "useridto", ")", ")", ";", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "useridto", "=", "$", "params", "[", "'useridto'", "]", ";", "if", "(", "!", "empty", "(", "$", "useridto", ")", ")", "{", "if", "(", "core_user", "::", "is_real_user", "(", "$", "useridto", ")", ")", "{", "$", "userto", "=", "core_user", "::", "get_user", "(", "$", "useridto", ",", "'*'", ",", "MUST_EXIST", ")", ";", "}", "else", "{", "throw", "new", "moodle_exception", "(", "'invaliduser'", ")", ";", "}", "}", "else", "{", "$", "useridto", "=", "$", "USER", "->", "id", ";", "}", "// Check if the current user is the receiver or just a privileged user.", "if", "(", "$", "useridto", "!=", "$", "USER", "->", "id", "and", "!", "has_capability", "(", "'moodle/site:readallmessages'", ",", "$", "context", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'accessdenied'", ",", "'admin'", ")", ";", "}", "return", "\\", "core_message", "\\", "api", "::", "count_unread_conversations", "(", "$", "userto", ")", ";", "}" ]
Get unread messages count function. @since 3.2 @throws invalid_parameter_exception @throws moodle_exception @param int $useridto the user id who received the message @return external_description
[ "Get", "unread", "messages", "count", "function", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L3327-L3361
216,197
moodle/moodle
message/externallib.php
core_message_external.get_blocked_users
public static function get_blocked_users($userid) { global $CFG, $USER, $PAGE; // Warnings array, it can be empty at the end but is mandatory. $warnings = array(); // Validate params. $params = array( 'userid' => $userid ); $params = self::validate_parameters(self::get_blocked_users_parameters(), $params); $userid = $params['userid']; // Validate context. $context = context_system::instance(); self::validate_context($context); // Check if private messaging between users is allowed. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $user = core_user::get_user($userid, '*', MUST_EXIST); core_user::require_active_user($user); // Check if we have permissions for retrieve the information. $capability = 'moodle/site:manageallmessaging'; if (($USER->id != $userid) && !has_capability($capability, $context)) { throw new required_capability_exception($context, $capability, 'nopermissions', ''); } // Now, we can get safely all the blocked users. $users = \core_message\api::get_blocked_users($user->id); $blockedusers = array(); foreach ($users as $user) { $newuser = array( 'id' => $user->id, 'fullname' => fullname($user), ); $userpicture = new user_picture($user); $userpicture->size = 1; // Size f1. $newuser['profileimageurl'] = $userpicture->get_url($PAGE)->out(false); $blockedusers[] = $newuser; } $results = array( 'users' => $blockedusers, 'warnings' => $warnings ); return $results; }
php
public static function get_blocked_users($userid) { global $CFG, $USER, $PAGE; // Warnings array, it can be empty at the end but is mandatory. $warnings = array(); // Validate params. $params = array( 'userid' => $userid ); $params = self::validate_parameters(self::get_blocked_users_parameters(), $params); $userid = $params['userid']; // Validate context. $context = context_system::instance(); self::validate_context($context); // Check if private messaging between users is allowed. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } $user = core_user::get_user($userid, '*', MUST_EXIST); core_user::require_active_user($user); // Check if we have permissions for retrieve the information. $capability = 'moodle/site:manageallmessaging'; if (($USER->id != $userid) && !has_capability($capability, $context)) { throw new required_capability_exception($context, $capability, 'nopermissions', ''); } // Now, we can get safely all the blocked users. $users = \core_message\api::get_blocked_users($user->id); $blockedusers = array(); foreach ($users as $user) { $newuser = array( 'id' => $user->id, 'fullname' => fullname($user), ); $userpicture = new user_picture($user); $userpicture->size = 1; // Size f1. $newuser['profileimageurl'] = $userpicture->get_url($PAGE)->out(false); $blockedusers[] = $newuser; } $results = array( 'users' => $blockedusers, 'warnings' => $warnings ); return $results; }
[ "public", "static", "function", "get_blocked_users", "(", "$", "userid", ")", "{", "global", "$", "CFG", ",", "$", "USER", ",", "$", "PAGE", ";", "// Warnings array, it can be empty at the end but is mandatory.", "$", "warnings", "=", "array", "(", ")", ";", "// Validate params.", "$", "params", "=", "array", "(", "'userid'", "=>", "$", "userid", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_blocked_users_parameters", "(", ")", ",", "$", "params", ")", ";", "$", "userid", "=", "$", "params", "[", "'userid'", "]", ";", "// Validate context.", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "// Check if private messaging between users is allowed.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "$", "user", "=", "core_user", "::", "get_user", "(", "$", "userid", ",", "'*'", ",", "MUST_EXIST", ")", ";", "core_user", "::", "require_active_user", "(", "$", "user", ")", ";", "// Check if we have permissions for retrieve the information.", "$", "capability", "=", "'moodle/site:manageallmessaging'", ";", "if", "(", "(", "$", "USER", "->", "id", "!=", "$", "userid", ")", "&&", "!", "has_capability", "(", "$", "capability", ",", "$", "context", ")", ")", "{", "throw", "new", "required_capability_exception", "(", "$", "context", ",", "$", "capability", ",", "'nopermissions'", ",", "''", ")", ";", "}", "// Now, we can get safely all the blocked users.", "$", "users", "=", "\\", "core_message", "\\", "api", "::", "get_blocked_users", "(", "$", "user", "->", "id", ")", ";", "$", "blockedusers", "=", "array", "(", ")", ";", "foreach", "(", "$", "users", "as", "$", "user", ")", "{", "$", "newuser", "=", "array", "(", "'id'", "=>", "$", "user", "->", "id", ",", "'fullname'", "=>", "fullname", "(", "$", "user", ")", ",", ")", ";", "$", "userpicture", "=", "new", "user_picture", "(", "$", "user", ")", ";", "$", "userpicture", "->", "size", "=", "1", ";", "// Size f1.", "$", "newuser", "[", "'profileimageurl'", "]", "=", "$", "userpicture", "->", "get_url", "(", "$", "PAGE", ")", "->", "out", "(", "false", ")", ";", "$", "blockedusers", "[", "]", "=", "$", "newuser", ";", "}", "$", "results", "=", "array", "(", "'users'", "=>", "$", "blockedusers", ",", "'warnings'", "=>", "$", "warnings", ")", ";", "return", "$", "results", ";", "}" ]
Retrieve a list of users blocked @param int $userid the user whose blocked users we want to retrieve @return external_description @since 2.9
[ "Retrieve", "a", "list", "of", "users", "blocked" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L3396-L3449
216,198
moodle/moodle
message/externallib.php
core_message_external.get_blocked_users_returns
public static function get_blocked_users_returns() { return new external_single_structure( array( 'users' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'User ID'), 'fullname' => new external_value(PARAM_NOTAGS, 'User full name'), 'profileimageurl' => new external_value(PARAM_URL, 'User picture URL', VALUE_OPTIONAL) ) ), 'List of blocked users' ), 'warnings' => new external_warnings() ) ); }
php
public static function get_blocked_users_returns() { return new external_single_structure( array( 'users' => new external_multiple_structure( new external_single_structure( array( 'id' => new external_value(PARAM_INT, 'User ID'), 'fullname' => new external_value(PARAM_NOTAGS, 'User full name'), 'profileimageurl' => new external_value(PARAM_URL, 'User picture URL', VALUE_OPTIONAL) ) ), 'List of blocked users' ), 'warnings' => new external_warnings() ) ); }
[ "public", "static", "function", "get_blocked_users_returns", "(", ")", "{", "return", "new", "external_single_structure", "(", "array", "(", "'users'", "=>", "new", "external_multiple_structure", "(", "new", "external_single_structure", "(", "array", "(", "'id'", "=>", "new", "external_value", "(", "PARAM_INT", ",", "'User ID'", ")", ",", "'fullname'", "=>", "new", "external_value", "(", "PARAM_NOTAGS", ",", "'User full name'", ")", ",", "'profileimageurl'", "=>", "new", "external_value", "(", "PARAM_URL", ",", "'User picture URL'", ",", "VALUE_OPTIONAL", ")", ")", ")", ",", "'List of blocked users'", ")", ",", "'warnings'", "=>", "new", "external_warnings", "(", ")", ")", ")", ";", "}" ]
Get blocked users return description. @return external_single_structure @since 2.9
[ "Get", "blocked", "users", "return", "description", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L3457-L3473
216,199
moodle/moodle
message/externallib.php
core_message_external.mark_message_read
public static function mark_message_read($messageid, $timeread) { global $CFG, $DB, $USER; // Check if private messaging between users is allowed. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } // Warnings array, it can be empty at the end but is mandatory. $warnings = array(); // Validate params. $params = array( 'messageid' => $messageid, 'timeread' => $timeread ); $params = self::validate_parameters(self::mark_message_read_parameters(), $params); if (empty($params['timeread'])) { $timeread = time(); } else { $timeread = $params['timeread']; } // Validate context. $context = context_system::instance(); self::validate_context($context); $sql = "SELECT m.*, mcm.userid as useridto FROM {messages} m INNER JOIN {message_conversations} mc ON m.conversationid = mc.id INNER JOIN {message_conversation_members} mcm ON mcm.conversationid = mc.id LEFT JOIN {message_user_actions} mua ON (mua.messageid = m.id AND mua.userid = ? AND mua.action = ?) WHERE mua.id is NULL AND mcm.userid != m.useridfrom AND m.id = ?"; $messageparams = []; $messageparams[] = $USER->id; $messageparams[] = \core_message\api::MESSAGE_ACTION_READ; $messageparams[] = $params['messageid']; $message = $DB->get_record_sql($sql, $messageparams, MUST_EXIST); if ($message->useridto != $USER->id) { throw new invalid_parameter_exception('Invalid messageid, you don\'t have permissions to mark this message as read'); } \core_message\api::mark_message_as_read($USER->id, $message, $timeread); $results = array( 'messageid' => $message->id, 'warnings' => $warnings ); return $results; }
php
public static function mark_message_read($messageid, $timeread) { global $CFG, $DB, $USER; // Check if private messaging between users is allowed. if (empty($CFG->messaging)) { throw new moodle_exception('disabled', 'message'); } // Warnings array, it can be empty at the end but is mandatory. $warnings = array(); // Validate params. $params = array( 'messageid' => $messageid, 'timeread' => $timeread ); $params = self::validate_parameters(self::mark_message_read_parameters(), $params); if (empty($params['timeread'])) { $timeread = time(); } else { $timeread = $params['timeread']; } // Validate context. $context = context_system::instance(); self::validate_context($context); $sql = "SELECT m.*, mcm.userid as useridto FROM {messages} m INNER JOIN {message_conversations} mc ON m.conversationid = mc.id INNER JOIN {message_conversation_members} mcm ON mcm.conversationid = mc.id LEFT JOIN {message_user_actions} mua ON (mua.messageid = m.id AND mua.userid = ? AND mua.action = ?) WHERE mua.id is NULL AND mcm.userid != m.useridfrom AND m.id = ?"; $messageparams = []; $messageparams[] = $USER->id; $messageparams[] = \core_message\api::MESSAGE_ACTION_READ; $messageparams[] = $params['messageid']; $message = $DB->get_record_sql($sql, $messageparams, MUST_EXIST); if ($message->useridto != $USER->id) { throw new invalid_parameter_exception('Invalid messageid, you don\'t have permissions to mark this message as read'); } \core_message\api::mark_message_as_read($USER->id, $message, $timeread); $results = array( 'messageid' => $message->id, 'warnings' => $warnings ); return $results; }
[ "public", "static", "function", "mark_message_read", "(", "$", "messageid", ",", "$", "timeread", ")", "{", "global", "$", "CFG", ",", "$", "DB", ",", "$", "USER", ";", "// Check if private messaging between users is allowed.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'disabled'", ",", "'message'", ")", ";", "}", "// Warnings array, it can be empty at the end but is mandatory.", "$", "warnings", "=", "array", "(", ")", ";", "// Validate params.", "$", "params", "=", "array", "(", "'messageid'", "=>", "$", "messageid", ",", "'timeread'", "=>", "$", "timeread", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "mark_message_read_parameters", "(", ")", ",", "$", "params", ")", ";", "if", "(", "empty", "(", "$", "params", "[", "'timeread'", "]", ")", ")", "{", "$", "timeread", "=", "time", "(", ")", ";", "}", "else", "{", "$", "timeread", "=", "$", "params", "[", "'timeread'", "]", ";", "}", "// Validate context.", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "$", "sql", "=", "\"SELECT m.*, mcm.userid as useridto\n FROM {messages} m\n INNER JOIN {message_conversations} mc\n ON m.conversationid = mc.id\n INNER JOIN {message_conversation_members} mcm\n ON mcm.conversationid = mc.id\n LEFT JOIN {message_user_actions} mua\n ON (mua.messageid = m.id AND mua.userid = ? AND mua.action = ?)\n WHERE mua.id is NULL\n AND mcm.userid != m.useridfrom\n AND m.id = ?\"", ";", "$", "messageparams", "=", "[", "]", ";", "$", "messageparams", "[", "]", "=", "$", "USER", "->", "id", ";", "$", "messageparams", "[", "]", "=", "\\", "core_message", "\\", "api", "::", "MESSAGE_ACTION_READ", ";", "$", "messageparams", "[", "]", "=", "$", "params", "[", "'messageid'", "]", ";", "$", "message", "=", "$", "DB", "->", "get_record_sql", "(", "$", "sql", ",", "$", "messageparams", ",", "MUST_EXIST", ")", ";", "if", "(", "$", "message", "->", "useridto", "!=", "$", "USER", "->", "id", ")", "{", "throw", "new", "invalid_parameter_exception", "(", "'Invalid messageid, you don\\'t have permissions to mark this message as read'", ")", ";", "}", "\\", "core_message", "\\", "api", "::", "mark_message_as_read", "(", "$", "USER", "->", "id", ",", "$", "message", ",", "$", "timeread", ")", ";", "$", "results", "=", "array", "(", "'messageid'", "=>", "$", "message", "->", "id", ",", "'warnings'", "=>", "$", "warnings", ")", ";", "return", "$", "results", ";", "}" ]
Mark a single message as read, trigger message_viewed event @param int $messageid id of the message (in the message table) @param int $timeread timestamp for when the message should be marked read @return external_description @throws invalid_parameter_exception @throws moodle_exception @since 2.9
[ "Mark", "a", "single", "message", "as", "read", "trigger", "message_viewed", "event" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/externallib.php#L3501-L3557