id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
213,300
moodle/moodle
repository/s3/S3.php
S3.__parseCloudFrontDistributionConfig
private static function __parseCloudFrontDistributionConfig(&$node) { if (isset($node->DistributionConfig)) return self::__parseCloudFrontDistributionConfig($node->DistributionConfig); $dist = array(); if (isset($node->Id, $node->Status, $node->LastModifiedTime, $node->DomainName)) { $dist['id'] = (string)$node->Id; $dist['status'] = (string)$node->Status; $dist['time'] = strtotime((string)$node->LastModifiedTime); $dist['domain'] = (string)$node->DomainName; } if (isset($node->CallerReference)) $dist['callerReference'] = (string)$node->CallerReference; if (isset($node->Enabled)) $dist['enabled'] = (string)$node->Enabled == 'true' ? true : false; if (isset($node->S3Origin)) { if (isset($node->S3Origin->DNSName)) $dist['origin'] = (string)$node->S3Origin->DNSName; $dist['originAccessIdentity'] = isset($node->S3Origin->OriginAccessIdentity) ? (string)$node->S3Origin->OriginAccessIdentity : null; } $dist['defaultRootObject'] = isset($node->DefaultRootObject) ? (string)$node->DefaultRootObject : null; $dist['cnames'] = array(); if (isset($node->CNAME)) foreach ($node->CNAME as $cname) $dist['cnames'][(string)$cname] = (string)$cname; $dist['trustedSigners'] = array(); if (isset($node->TrustedSigners)) foreach ($node->TrustedSigners as $signer) { if (isset($signer->Self)) $dist['trustedSigners'][''] = 'Self'; elseif (isset($signer->KeyPairId)) $dist['trustedSigners'][(string)$signer->KeyPairId] = 'KeyPairId'; elseif (isset($signer->AwsAccountNumber)) $dist['trustedSigners'][(string)$signer->AwsAccountNumber] = 'AwsAccountNumber'; } $dist['comment'] = isset($node->Comment) ? (string)$node->Comment : null; return $dist; }
php
private static function __parseCloudFrontDistributionConfig(&$node) { if (isset($node->DistributionConfig)) return self::__parseCloudFrontDistributionConfig($node->DistributionConfig); $dist = array(); if (isset($node->Id, $node->Status, $node->LastModifiedTime, $node->DomainName)) { $dist['id'] = (string)$node->Id; $dist['status'] = (string)$node->Status; $dist['time'] = strtotime((string)$node->LastModifiedTime); $dist['domain'] = (string)$node->DomainName; } if (isset($node->CallerReference)) $dist['callerReference'] = (string)$node->CallerReference; if (isset($node->Enabled)) $dist['enabled'] = (string)$node->Enabled == 'true' ? true : false; if (isset($node->S3Origin)) { if (isset($node->S3Origin->DNSName)) $dist['origin'] = (string)$node->S3Origin->DNSName; $dist['originAccessIdentity'] = isset($node->S3Origin->OriginAccessIdentity) ? (string)$node->S3Origin->OriginAccessIdentity : null; } $dist['defaultRootObject'] = isset($node->DefaultRootObject) ? (string)$node->DefaultRootObject : null; $dist['cnames'] = array(); if (isset($node->CNAME)) foreach ($node->CNAME as $cname) $dist['cnames'][(string)$cname] = (string)$cname; $dist['trustedSigners'] = array(); if (isset($node->TrustedSigners)) foreach ($node->TrustedSigners as $signer) { if (isset($signer->Self)) $dist['trustedSigners'][''] = 'Self'; elseif (isset($signer->KeyPairId)) $dist['trustedSigners'][(string)$signer->KeyPairId] = 'KeyPairId'; elseif (isset($signer->AwsAccountNumber)) $dist['trustedSigners'][(string)$signer->AwsAccountNumber] = 'AwsAccountNumber'; } $dist['comment'] = isset($node->Comment) ? (string)$node->Comment : null; return $dist; }
[ "private", "static", "function", "__parseCloudFrontDistributionConfig", "(", "&", "$", "node", ")", "{", "if", "(", "isset", "(", "$", "node", "->", "DistributionConfig", ")", ")", "return", "self", "::", "__parseCloudFrontDistributionConfig", "(", "$", "node", "->", "DistributionConfig", ")", ";", "$", "dist", "=", "array", "(", ")", ";", "if", "(", "isset", "(", "$", "node", "->", "Id", ",", "$", "node", "->", "Status", ",", "$", "node", "->", "LastModifiedTime", ",", "$", "node", "->", "DomainName", ")", ")", "{", "$", "dist", "[", "'id'", "]", "=", "(", "string", ")", "$", "node", "->", "Id", ";", "$", "dist", "[", "'status'", "]", "=", "(", "string", ")", "$", "node", "->", "Status", ";", "$", "dist", "[", "'time'", "]", "=", "strtotime", "(", "(", "string", ")", "$", "node", "->", "LastModifiedTime", ")", ";", "$", "dist", "[", "'domain'", "]", "=", "(", "string", ")", "$", "node", "->", "DomainName", ";", "}", "if", "(", "isset", "(", "$", "node", "->", "CallerReference", ")", ")", "$", "dist", "[", "'callerReference'", "]", "=", "(", "string", ")", "$", "node", "->", "CallerReference", ";", "if", "(", "isset", "(", "$", "node", "->", "Enabled", ")", ")", "$", "dist", "[", "'enabled'", "]", "=", "(", "string", ")", "$", "node", "->", "Enabled", "==", "'true'", "?", "true", ":", "false", ";", "if", "(", "isset", "(", "$", "node", "->", "S3Origin", ")", ")", "{", "if", "(", "isset", "(", "$", "node", "->", "S3Origin", "->", "DNSName", ")", ")", "$", "dist", "[", "'origin'", "]", "=", "(", "string", ")", "$", "node", "->", "S3Origin", "->", "DNSName", ";", "$", "dist", "[", "'originAccessIdentity'", "]", "=", "isset", "(", "$", "node", "->", "S3Origin", "->", "OriginAccessIdentity", ")", "?", "(", "string", ")", "$", "node", "->", "S3Origin", "->", "OriginAccessIdentity", ":", "null", ";", "}", "$", "dist", "[", "'defaultRootObject'", "]", "=", "isset", "(", "$", "node", "->", "DefaultRootObject", ")", "?", "(", "string", ")", "$", "node", "->", "DefaultRootObject", ":", "null", ";", "$", "dist", "[", "'cnames'", "]", "=", "array", "(", ")", ";", "if", "(", "isset", "(", "$", "node", "->", "CNAME", ")", ")", "foreach", "(", "$", "node", "->", "CNAME", "as", "$", "cname", ")", "$", "dist", "[", "'cnames'", "]", "[", "(", "string", ")", "$", "cname", "]", "=", "(", "string", ")", "$", "cname", ";", "$", "dist", "[", "'trustedSigners'", "]", "=", "array", "(", ")", ";", "if", "(", "isset", "(", "$", "node", "->", "TrustedSigners", ")", ")", "foreach", "(", "$", "node", "->", "TrustedSigners", "as", "$", "signer", ")", "{", "if", "(", "isset", "(", "$", "signer", "->", "Self", ")", ")", "$", "dist", "[", "'trustedSigners'", "]", "[", "''", "]", "=", "'Self'", ";", "elseif", "(", "isset", "(", "$", "signer", "->", "KeyPairId", ")", ")", "$", "dist", "[", "'trustedSigners'", "]", "[", "(", "string", ")", "$", "signer", "->", "KeyPairId", "]", "=", "'KeyPairId'", ";", "elseif", "(", "isset", "(", "$", "signer", "->", "AwsAccountNumber", ")", ")", "$", "dist", "[", "'trustedSigners'", "]", "[", "(", "string", ")", "$", "signer", "->", "AwsAccountNumber", "]", "=", "'AwsAccountNumber'", ";", "}", "$", "dist", "[", "'comment'", "]", "=", "isset", "(", "$", "node", "->", "Comment", ")", "?", "(", "string", ")", "$", "node", "->", "Comment", ":", "null", ";", "return", "$", "dist", ";", "}" ]
Parse a CloudFront distribution config See http://docs.amazonwebservices.com/AmazonCloudFront/latest/APIReference/index.html?GetDistribution.html @internal Used to parse the CloudFront DistributionConfig node to an array @param object &$node DOMNode @return array
[ "Parse", "a", "CloudFront", "distribution", "config" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/s3/S3.php#L1730-L1780
213,301
moodle/moodle
repository/s3/S3.php
S3.__getCloudFrontResponse
private static function __getCloudFrontResponse(&$rest) { $rest->getResponse(); if ($rest->response->error === false && isset($rest->response->body) && is_string($rest->response->body) && substr($rest->response->body, 0, 5) == '<?xml') { $rest->response->body = simplexml_load_string($rest->response->body); // Grab CloudFront errors if (isset($rest->response->body->Error, $rest->response->body->Error->Code, $rest->response->body->Error->Message)) { $rest->response->error = array( 'code' => (string)$rest->response->body->Error->Code, 'message' => (string)$rest->response->body->Error->Message ); unset($rest->response->body); } } return $rest->response; }
php
private static function __getCloudFrontResponse(&$rest) { $rest->getResponse(); if ($rest->response->error === false && isset($rest->response->body) && is_string($rest->response->body) && substr($rest->response->body, 0, 5) == '<?xml') { $rest->response->body = simplexml_load_string($rest->response->body); // Grab CloudFront errors if (isset($rest->response->body->Error, $rest->response->body->Error->Code, $rest->response->body->Error->Message)) { $rest->response->error = array( 'code' => (string)$rest->response->body->Error->Code, 'message' => (string)$rest->response->body->Error->Message ); unset($rest->response->body); } } return $rest->response; }
[ "private", "static", "function", "__getCloudFrontResponse", "(", "&", "$", "rest", ")", "{", "$", "rest", "->", "getResponse", "(", ")", ";", "if", "(", "$", "rest", "->", "response", "->", "error", "===", "false", "&&", "isset", "(", "$", "rest", "->", "response", "->", "body", ")", "&&", "is_string", "(", "$", "rest", "->", "response", "->", "body", ")", "&&", "substr", "(", "$", "rest", "->", "response", "->", "body", ",", "0", ",", "5", ")", "==", "'<?xml'", ")", "{", "$", "rest", "->", "response", "->", "body", "=", "simplexml_load_string", "(", "$", "rest", "->", "response", "->", "body", ")", ";", "// Grab CloudFront errors", "if", "(", "isset", "(", "$", "rest", "->", "response", "->", "body", "->", "Error", ",", "$", "rest", "->", "response", "->", "body", "->", "Error", "->", "Code", ",", "$", "rest", "->", "response", "->", "body", "->", "Error", "->", "Message", ")", ")", "{", "$", "rest", "->", "response", "->", "error", "=", "array", "(", "'code'", "=>", "(", "string", ")", "$", "rest", "->", "response", "->", "body", "->", "Error", "->", "Code", ",", "'message'", "=>", "(", "string", ")", "$", "rest", "->", "response", "->", "body", "->", "Error", "->", "Message", ")", ";", "unset", "(", "$", "rest", "->", "response", "->", "body", ")", ";", "}", "}", "return", "$", "rest", "->", "response", ";", "}" ]
Grab CloudFront response @internal Used to parse the CloudFront S3Request::getResponse() output @param object &$rest S3Request instance @return object
[ "Grab", "CloudFront", "response" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/s3/S3.php#L1790-L1809
213,302
moodle/moodle
repository/s3/S3.php
S3.__getHash
private static function __getHash($string) { return base64_encode(extension_loaded('hash') ? hash_hmac('sha1', $string, self::$__secretKey, true) : pack('H*', sha1( (str_pad(self::$__secretKey, 64, chr(0x00)) ^ (str_repeat(chr(0x5c), 64))) . pack('H*', sha1((str_pad(self::$__secretKey, 64, chr(0x00)) ^ (str_repeat(chr(0x36), 64))) . $string))))); }
php
private static function __getHash($string) { return base64_encode(extension_loaded('hash') ? hash_hmac('sha1', $string, self::$__secretKey, true) : pack('H*', sha1( (str_pad(self::$__secretKey, 64, chr(0x00)) ^ (str_repeat(chr(0x5c), 64))) . pack('H*', sha1((str_pad(self::$__secretKey, 64, chr(0x00)) ^ (str_repeat(chr(0x36), 64))) . $string))))); }
[ "private", "static", "function", "__getHash", "(", "$", "string", ")", "{", "return", "base64_encode", "(", "extension_loaded", "(", "'hash'", ")", "?", "hash_hmac", "(", "'sha1'", ",", "$", "string", ",", "self", "::", "$", "__secretKey", ",", "true", ")", ":", "pack", "(", "'H*'", ",", "sha1", "(", "(", "str_pad", "(", "self", "::", "$", "__secretKey", ",", "64", ",", "chr", "(", "0x00", ")", ")", "^", "(", "str_repeat", "(", "chr", "(", "0x5c", ")", ",", "64", ")", ")", ")", ".", "pack", "(", "'H*'", ",", "sha1", "(", "(", "str_pad", "(", "self", "::", "$", "__secretKey", ",", "64", ",", "chr", "(", "0x00", ")", ")", "^", "(", "str_repeat", "(", "chr", "(", "0x36", ")", ",", "64", ")", ")", ")", ".", "$", "string", ")", ")", ")", ")", ")", ";", "}" ]
Creates a HMAC-SHA1 hash This uses the hash extension if loaded @internal Used by __getSignature() @param string $string String to sign @return string
[ "Creates", "a", "HMAC", "-", "SHA1", "hash" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/s3/S3.php#L1900-L1907
213,303
moodle/moodle
repository/s3/S3.php
S3Request.__sortMetaHeadersCmp
private function __sortMetaHeadersCmp($a, $b) { $lenA = strpos($a, ':'); $lenB = strpos($b, ':'); $minLen = min($lenA, $lenB); $ncmp = strncmp($a, $b, $minLen); if ($lenA == $lenB) return $ncmp; if (0 == $ncmp) return $lenA < $lenB ? -1 : 1; return $ncmp; }
php
private function __sortMetaHeadersCmp($a, $b) { $lenA = strpos($a, ':'); $lenB = strpos($b, ':'); $minLen = min($lenA, $lenB); $ncmp = strncmp($a, $b, $minLen); if ($lenA == $lenB) return $ncmp; if (0 == $ncmp) return $lenA < $lenB ? -1 : 1; return $ncmp; }
[ "private", "function", "__sortMetaHeadersCmp", "(", "$", "a", ",", "$", "b", ")", "{", "$", "lenA", "=", "strpos", "(", "$", "a", ",", "':'", ")", ";", "$", "lenB", "=", "strpos", "(", "$", "b", ",", "':'", ")", ";", "$", "minLen", "=", "min", "(", "$", "lenA", ",", "$", "lenB", ")", ";", "$", "ncmp", "=", "strncmp", "(", "$", "a", ",", "$", "b", ",", "$", "minLen", ")", ";", "if", "(", "$", "lenA", "==", "$", "lenB", ")", "return", "$", "ncmp", ";", "if", "(", "0", "==", "$", "ncmp", ")", "return", "$", "lenA", "<", "$", "lenB", "?", "-", "1", ":", "1", ";", "return", "$", "ncmp", ";", "}" ]
Sort compare for meta headers @internal Used to sort x-amz meta headers @param string $a String A @param string $b String B @return integer
[ "Sort", "compare", "for", "meta", "headers" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/s3/S3.php#L2285-L2294
213,304
moodle/moodle
repository/s3/S3.php
S3Request.__responseWriteCallback
private function __responseWriteCallback(&$curl, &$data) { if (in_array($this->response->code, array(200, 206)) && $this->fp !== false) return fwrite($this->fp, $data); else $this->response->body .= $data; return strlen($data); }
php
private function __responseWriteCallback(&$curl, &$data) { if (in_array($this->response->code, array(200, 206)) && $this->fp !== false) return fwrite($this->fp, $data); else $this->response->body .= $data; return strlen($data); }
[ "private", "function", "__responseWriteCallback", "(", "&", "$", "curl", ",", "&", "$", "data", ")", "{", "if", "(", "in_array", "(", "$", "this", "->", "response", "->", "code", ",", "array", "(", "200", ",", "206", ")", ")", "&&", "$", "this", "->", "fp", "!==", "false", ")", "return", "fwrite", "(", "$", "this", "->", "fp", ",", "$", "data", ")", ";", "else", "$", "this", "->", "response", "->", "body", ".=", "$", "data", ";", "return", "strlen", "(", "$", "data", ")", ";", "}" ]
CURL write callback @param resource &$curl CURL resource @param string &$data Data @return integer
[ "CURL", "write", "callback" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/s3/S3.php#L2303-L2310
213,305
moodle/moodle
repository/s3/S3.php
S3Request.__responseHeaderCallback
private function __responseHeaderCallback($curl, $data) { if (($strlen = strlen($data)) <= 2) return $strlen; if (substr($data, 0, 4) == 'HTTP') $this->response->code = (int)substr($data, 9, 3); else { $data = trim($data); if (strpos($data, ': ') === false) return $strlen; list($header, $value) = explode(': ', $data, 2); if ($header == 'Last-Modified') $this->response->headers['time'] = strtotime($value); elseif ($header == 'Date') $this->response->headers['date'] = strtotime($value); elseif ($header == 'Content-Length') $this->response->headers['size'] = (int)$value; elseif ($header == 'Content-Type') $this->response->headers['type'] = $value; elseif ($header == 'ETag') $this->response->headers['hash'] = $value{0} == '"' ? substr($value, 1, -1) : $value; elseif (preg_match('/^x-amz-meta-.*$/', $header)) $this->response->headers[$header] = $value; } return $strlen; }
php
private function __responseHeaderCallback($curl, $data) { if (($strlen = strlen($data)) <= 2) return $strlen; if (substr($data, 0, 4) == 'HTTP') $this->response->code = (int)substr($data, 9, 3); else { $data = trim($data); if (strpos($data, ': ') === false) return $strlen; list($header, $value) = explode(': ', $data, 2); if ($header == 'Last-Modified') $this->response->headers['time'] = strtotime($value); elseif ($header == 'Date') $this->response->headers['date'] = strtotime($value); elseif ($header == 'Content-Length') $this->response->headers['size'] = (int)$value; elseif ($header == 'Content-Type') $this->response->headers['type'] = $value; elseif ($header == 'ETag') $this->response->headers['hash'] = $value{0} == '"' ? substr($value, 1, -1) : $value; elseif (preg_match('/^x-amz-meta-.*$/', $header)) $this->response->headers[$header] = $value; } return $strlen; }
[ "private", "function", "__responseHeaderCallback", "(", "$", "curl", ",", "$", "data", ")", "{", "if", "(", "(", "$", "strlen", "=", "strlen", "(", "$", "data", ")", ")", "<=", "2", ")", "return", "$", "strlen", ";", "if", "(", "substr", "(", "$", "data", ",", "0", ",", "4", ")", "==", "'HTTP'", ")", "$", "this", "->", "response", "->", "code", "=", "(", "int", ")", "substr", "(", "$", "data", ",", "9", ",", "3", ")", ";", "else", "{", "$", "data", "=", "trim", "(", "$", "data", ")", ";", "if", "(", "strpos", "(", "$", "data", ",", "': '", ")", "===", "false", ")", "return", "$", "strlen", ";", "list", "(", "$", "header", ",", "$", "value", ")", "=", "explode", "(", "': '", ",", "$", "data", ",", "2", ")", ";", "if", "(", "$", "header", "==", "'Last-Modified'", ")", "$", "this", "->", "response", "->", "headers", "[", "'time'", "]", "=", "strtotime", "(", "$", "value", ")", ";", "elseif", "(", "$", "header", "==", "'Date'", ")", "$", "this", "->", "response", "->", "headers", "[", "'date'", "]", "=", "strtotime", "(", "$", "value", ")", ";", "elseif", "(", "$", "header", "==", "'Content-Length'", ")", "$", "this", "->", "response", "->", "headers", "[", "'size'", "]", "=", "(", "int", ")", "$", "value", ";", "elseif", "(", "$", "header", "==", "'Content-Type'", ")", "$", "this", "->", "response", "->", "headers", "[", "'type'", "]", "=", "$", "value", ";", "elseif", "(", "$", "header", "==", "'ETag'", ")", "$", "this", "->", "response", "->", "headers", "[", "'hash'", "]", "=", "$", "value", "{", "0", "}", "==", "'\"'", "?", "substr", "(", "$", "value", ",", "1", ",", "-", "1", ")", ":", "$", "value", ";", "elseif", "(", "preg_match", "(", "'/^x-amz-meta-.*$/'", ",", "$", "header", ")", ")", "$", "this", "->", "response", "->", "headers", "[", "$", "header", "]", "=", "$", "value", ";", "}", "return", "$", "strlen", ";", "}" ]
CURL header callback @param resource $curl CURL resource @param string $data Data @return integer
[ "CURL", "header", "callback" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/s3/S3.php#L2338-L2362
213,306
moodle/moodle
customfield/classes/event/field_created.php
field_created.create_from_object
public static function create_from_object(field_controller $field) : field_created { $eventparams = [ 'objectid' => $field->get('id'), 'context' => $field->get_handler()->get_configuration_context(), 'other' => [ 'shortname' => $field->get('shortname'), 'name' => $field->get('name') ] ]; $event = self::create($eventparams); $event->add_record_snapshot($event->objecttable, $field->to_record()); return $event; }
php
public static function create_from_object(field_controller $field) : field_created { $eventparams = [ 'objectid' => $field->get('id'), 'context' => $field->get_handler()->get_configuration_context(), 'other' => [ 'shortname' => $field->get('shortname'), 'name' => $field->get('name') ] ]; $event = self::create($eventparams); $event->add_record_snapshot($event->objecttable, $field->to_record()); return $event; }
[ "public", "static", "function", "create_from_object", "(", "field_controller", "$", "field", ")", ":", "field_created", "{", "$", "eventparams", "=", "[", "'objectid'", "=>", "$", "field", "->", "get", "(", "'id'", ")", ",", "'context'", "=>", "$", "field", "->", "get_handler", "(", ")", "->", "get_configuration_context", "(", ")", ",", "'other'", "=>", "[", "'shortname'", "=>", "$", "field", "->", "get", "(", "'shortname'", ")", ",", "'name'", "=>", "$", "field", "->", "get", "(", "'name'", ")", "]", "]", ";", "$", "event", "=", "self", "::", "create", "(", "$", "eventparams", ")", ";", "$", "event", "->", "add_record_snapshot", "(", "$", "event", "->", "objecttable", ",", "$", "field", "->", "to_record", "(", ")", ")", ";", "return", "$", "event", ";", "}" ]
Creates an instance from a field controller object @param field_controller $field @return field_created
[ "Creates", "an", "instance", "from", "a", "field", "controller", "object" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/customfield/classes/event/field_created.php#L56-L68
213,307
moodle/moodle
lib/filestorage/file_system.php
file_system.readfile
public function readfile(stored_file $file) { if ($this->is_file_readable_locally_by_storedfile($file, false)) { $path = $this->get_local_path_from_storedfile($file, false); } else { $path = $this->get_remote_path_from_storedfile($file); } readfile_allow_large($path, $file->get_filesize()); }
php
public function readfile(stored_file $file) { if ($this->is_file_readable_locally_by_storedfile($file, false)) { $path = $this->get_local_path_from_storedfile($file, false); } else { $path = $this->get_remote_path_from_storedfile($file); } readfile_allow_large($path, $file->get_filesize()); }
[ "public", "function", "readfile", "(", "stored_file", "$", "file", ")", "{", "if", "(", "$", "this", "->", "is_file_readable_locally_by_storedfile", "(", "$", "file", ",", "false", ")", ")", "{", "$", "path", "=", "$", "this", "->", "get_local_path_from_storedfile", "(", "$", "file", ",", "false", ")", ";", "}", "else", "{", "$", "path", "=", "$", "this", "->", "get_remote_path_from_storedfile", "(", "$", "file", ")", ";", "}", "readfile_allow_large", "(", "$", "path", ",", "$", "file", "->", "get_filesize", "(", ")", ")", ";", "}" ]
Output the content of the specified stored file. Note, this is different to get_content() as it uses the built-in php readfile function which is more efficient. @param stored_file $file The file to serve. @return void
[ "Output", "the", "content", "of", "the", "specified", "stored", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_system.php#L60-L67
213,308
moodle/moodle
lib/filestorage/file_system.php
file_system.get_local_path_from_storedfile
protected function get_local_path_from_storedfile(stored_file $file, $fetchifnotfound = false) { return $this->get_local_path_from_hash($file->get_contenthash(), $fetchifnotfound); }
php
protected function get_local_path_from_storedfile(stored_file $file, $fetchifnotfound = false) { return $this->get_local_path_from_hash($file->get_contenthash(), $fetchifnotfound); }
[ "protected", "function", "get_local_path_from_storedfile", "(", "stored_file", "$", "file", ",", "$", "fetchifnotfound", "=", "false", ")", "{", "return", "$", "this", "->", "get_local_path_from_hash", "(", "$", "file", "->", "get_contenthash", "(", ")", ",", "$", "fetchifnotfound", ")", ";", "}" ]
Get the full path on disk for the specified stored file. Note: This must return a consistent path for the file's contenthash and the path _will_ be in a standard local format. Streamable paths will not work. A local copy of the file _will_ be fetched if $fetchifnotfound is tree. The $fetchifnotfound allows you to determine the expected path of the file. @param stored_file $file The file to serve. @param bool $fetchifnotfound Whether to attempt to fetch from the remote path if not found. @return string full path to pool file with file content
[ "Get", "the", "full", "path", "on", "disk", "for", "the", "specified", "stored", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_system.php#L83-L85
213,309
moodle/moodle
lib/filestorage/file_system.php
file_system.is_file_readable_remotely_by_storedfile
public function is_file_readable_remotely_by_storedfile(stored_file $file) { if (!$file->get_filesize()) { // Files with empty size are either directories or empty. // We handle these virtually. return true; } $path = $this->get_remote_path_from_storedfile($file, false); if (is_readable($path)) { return true; } return false; }
php
public function is_file_readable_remotely_by_storedfile(stored_file $file) { if (!$file->get_filesize()) { // Files with empty size are either directories or empty. // We handle these virtually. return true; } $path = $this->get_remote_path_from_storedfile($file, false); if (is_readable($path)) { return true; } return false; }
[ "public", "function", "is_file_readable_remotely_by_storedfile", "(", "stored_file", "$", "file", ")", "{", "if", "(", "!", "$", "file", "->", "get_filesize", "(", ")", ")", "{", "// Files with empty size are either directories or empty.", "// We handle these virtually.", "return", "true", ";", "}", "$", "path", "=", "$", "this", "->", "get_remote_path_from_storedfile", "(", "$", "file", ",", "false", ")", ";", "if", "(", "is_readable", "(", "$", "path", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Determine whether the file is present on the local file system somewhere. @param stored_file $file The file to ensure is available. @return bool
[ "Determine", "whether", "the", "file", "is", "present", "on", "the", "local", "file", "system", "somewhere", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_system.php#L161-L174
213,310
moodle/moodle
lib/filestorage/file_system.php
file_system.is_file_readable_locally_by_hash
public function is_file_readable_locally_by_hash($contenthash, $fetchifnotfound = false) { if ($contenthash === file_storage::hash_from_string('')) { // Files with empty size are either directories or empty. // We handle these virtually. return true; } // This is called by file_storage::content_exists(), and in turn by the repository system. $path = $this->get_local_path_from_hash($contenthash, $fetchifnotfound); // Note - it is not possible to perform a content recovery safely from a hash alone. return is_readable($path); }
php
public function is_file_readable_locally_by_hash($contenthash, $fetchifnotfound = false) { if ($contenthash === file_storage::hash_from_string('')) { // Files with empty size are either directories or empty. // We handle these virtually. return true; } // This is called by file_storage::content_exists(), and in turn by the repository system. $path = $this->get_local_path_from_hash($contenthash, $fetchifnotfound); // Note - it is not possible to perform a content recovery safely from a hash alone. return is_readable($path); }
[ "public", "function", "is_file_readable_locally_by_hash", "(", "$", "contenthash", ",", "$", "fetchifnotfound", "=", "false", ")", "{", "if", "(", "$", "contenthash", "===", "file_storage", "::", "hash_from_string", "(", "''", ")", ")", "{", "// Files with empty size are either directories or empty.", "// We handle these virtually.", "return", "true", ";", "}", "// This is called by file_storage::content_exists(), and in turn by the repository system.", "$", "path", "=", "$", "this", "->", "get_local_path_from_hash", "(", "$", "contenthash", ",", "$", "fetchifnotfound", ")", ";", "// Note - it is not possible to perform a content recovery safely from a hash alone.", "return", "is_readable", "(", "$", "path", ")", ";", "}" ]
Determine whether the file is present on the file system somewhere given the contenthash. @param string $contenthash The contenthash of the file to check. @param bool $fetchifnotfound Whether to attempt to fetch from the remote path if not found. @return bool
[ "Determine", "whether", "the", "file", "is", "present", "on", "the", "file", "system", "somewhere", "given", "the", "contenthash", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_system.php#L184-L196
213,311
moodle/moodle
lib/filestorage/file_system.php
file_system.is_file_readable_remotely_by_hash
public function is_file_readable_remotely_by_hash($contenthash) { if ($contenthash === file_storage::hash_from_string('')) { // Files with empty size are either directories or empty. // We handle these virtually. return true; } $path = $this->get_remote_path_from_hash($contenthash, false); // Note - it is not possible to perform a content recovery safely from a hash alone. return is_readable($path); }
php
public function is_file_readable_remotely_by_hash($contenthash) { if ($contenthash === file_storage::hash_from_string('')) { // Files with empty size are either directories or empty. // We handle these virtually. return true; } $path = $this->get_remote_path_from_hash($contenthash, false); // Note - it is not possible to perform a content recovery safely from a hash alone. return is_readable($path); }
[ "public", "function", "is_file_readable_remotely_by_hash", "(", "$", "contenthash", ")", "{", "if", "(", "$", "contenthash", "===", "file_storage", "::", "hash_from_string", "(", "''", ")", ")", "{", "// Files with empty size are either directories or empty.", "// We handle these virtually.", "return", "true", ";", "}", "$", "path", "=", "$", "this", "->", "get_remote_path_from_hash", "(", "$", "contenthash", ",", "false", ")", ";", "// Note - it is not possible to perform a content recovery safely from a hash alone.", "return", "is_readable", "(", "$", "path", ")", ";", "}" ]
Determine whether the file is present locally on the file system somewhere given the contenthash. @param string $contenthash The contenthash of the file to check. @return bool
[ "Determine", "whether", "the", "file", "is", "present", "locally", "on", "the", "file", "system", "somewhere", "given", "the", "contenthash", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_system.php#L205-L216
213,312
moodle/moodle
lib/filestorage/file_system.php
file_system.is_file_removable
protected static function is_file_removable($contenthash) { global $DB; if ($contenthash === file_storage::hash_from_string('')) { // No need to delete files without content. return false; } // Note: This section is critical - in theory file could be reused at the same time, if this // happens we can still recover the file from trash. // Technically this is the responsibility of the file_storage API, but as this method is public, we go belt-and-braces. if ($DB->record_exists('files', array('contenthash' => $contenthash))) { // File content is still used. return false; } return true; }
php
protected static function is_file_removable($contenthash) { global $DB; if ($contenthash === file_storage::hash_from_string('')) { // No need to delete files without content. return false; } // Note: This section is critical - in theory file could be reused at the same time, if this // happens we can still recover the file from trash. // Technically this is the responsibility of the file_storage API, but as this method is public, we go belt-and-braces. if ($DB->record_exists('files', array('contenthash' => $contenthash))) { // File content is still used. return false; } return true; }
[ "protected", "static", "function", "is_file_removable", "(", "$", "contenthash", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "contenthash", "===", "file_storage", "::", "hash_from_string", "(", "''", ")", ")", "{", "// No need to delete files without content.", "return", "false", ";", "}", "// Note: This section is critical - in theory file could be reused at the same time, if this", "// happens we can still recover the file from trash.", "// Technically this is the responsibility of the file_storage API, but as this method is public, we go belt-and-braces.", "if", "(", "$", "DB", "->", "record_exists", "(", "'files'", ",", "array", "(", "'contenthash'", "=>", "$", "contenthash", ")", ")", ")", "{", "// File content is still used.", "return", "false", ";", "}", "return", "true", ";", "}" ]
Check whether a file is removable. This must be called prior to file removal. @param string $contenthash @return bool
[ "Check", "whether", "a", "file", "is", "removable", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_system.php#L247-L264
213,313
moodle/moodle
lib/filestorage/file_system.php
file_system.get_content
public function get_content(stored_file $file) { if (!$file->get_filesize()) { // Directories are empty. Empty files are not worth fetching. return ''; } $source = $this->get_remote_path_from_storedfile($file); return file_get_contents($source); }
php
public function get_content(stored_file $file) { if (!$file->get_filesize()) { // Directories are empty. Empty files are not worth fetching. return ''; } $source = $this->get_remote_path_from_storedfile($file); return file_get_contents($source); }
[ "public", "function", "get_content", "(", "stored_file", "$", "file", ")", "{", "if", "(", "!", "$", "file", "->", "get_filesize", "(", ")", ")", "{", "// Directories are empty. Empty files are not worth fetching.", "return", "''", ";", "}", "$", "source", "=", "$", "this", "->", "get_remote_path_from_storedfile", "(", "$", "file", ")", ";", "return", "file_get_contents", "(", "$", "source", ")", ";", "}" ]
Get the content of the specified stored file. Generally you will probably want to use readfile() to serve content, and where possible you should see if you can use get_content_file_handle and work with the file stream instead. @param stored_file $file The file to retrieve @return string The full file content
[ "Get", "the", "content", "of", "the", "specified", "stored", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_system.php#L276-L284
213,314
moodle/moodle
lib/filestorage/file_system.php
file_system.list_files
public function list_files($file, file_packer $packer) { $archivefile = $this->get_local_path_from_storedfile($file, true); return $packer->list_files($archivefile); }
php
public function list_files($file, file_packer $packer) { $archivefile = $this->get_local_path_from_storedfile($file, true); return $packer->list_files($archivefile); }
[ "public", "function", "list_files", "(", "$", "file", ",", "file_packer", "$", "packer", ")", "{", "$", "archivefile", "=", "$", "this", "->", "get_local_path_from_storedfile", "(", "$", "file", ",", "true", ")", ";", "return", "$", "packer", "->", "list_files", "(", "$", "archivefile", ")", ";", "}" ]
List contents of archive. @param stored_file $file The archive to inspect @param file_packer $packer file packer instance @return array of file infos
[ "List", "contents", "of", "archive", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_system.php#L293-L296
213,315
moodle/moodle
lib/filestorage/file_system.php
file_system.get_imageinfo
public function get_imageinfo(stored_file $file) { if (!$this->is_image_from_storedfile($file)) { return false; } // Whilst get_imageinfo_from_path can use remote paths, it must download the entire file first. // It is more efficient to use a local file when possible. return $this->get_imageinfo_from_path($this->get_local_path_from_storedfile($file, true)); }
php
public function get_imageinfo(stored_file $file) { if (!$this->is_image_from_storedfile($file)) { return false; } // Whilst get_imageinfo_from_path can use remote paths, it must download the entire file first. // It is more efficient to use a local file when possible. return $this->get_imageinfo_from_path($this->get_local_path_from_storedfile($file, true)); }
[ "public", "function", "get_imageinfo", "(", "stored_file", "$", "file", ")", "{", "if", "(", "!", "$", "this", "->", "is_image_from_storedfile", "(", "$", "file", ")", ")", "{", "return", "false", ";", "}", "// Whilst get_imageinfo_from_path can use remote paths, it must download the entire file first.", "// It is more efficient to use a local file when possible.", "return", "$", "this", "->", "get_imageinfo_from_path", "(", "$", "this", "->", "get_local_path_from_storedfile", "(", "$", "file", ",", "true", ")", ")", ";", "}" ]
Returns information about image. Information is determined from the file content @param stored_file $file The file to inspect @return mixed array with width, height and mimetype; false if not an image
[ "Returns", "information", "about", "image", ".", "Information", "is", "determined", "from", "the", "file", "content" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_system.php#L375-L383
213,316
moodle/moodle
lib/filestorage/file_system.php
file_system.is_image_from_storedfile
public function is_image_from_storedfile(stored_file $file) { if (!$file->get_filesize()) { // An empty file cannot be an image. return false; } $mimetype = $file->get_mimetype(); if (!preg_match('|^image/|', $mimetype)) { // The mimetype does not include image. return false; } // If it looks like an image, and it smells like an image, perhaps it's an image! return true; }
php
public function is_image_from_storedfile(stored_file $file) { if (!$file->get_filesize()) { // An empty file cannot be an image. return false; } $mimetype = $file->get_mimetype(); if (!preg_match('|^image/|', $mimetype)) { // The mimetype does not include image. return false; } // If it looks like an image, and it smells like an image, perhaps it's an image! return true; }
[ "public", "function", "is_image_from_storedfile", "(", "stored_file", "$", "file", ")", "{", "if", "(", "!", "$", "file", "->", "get_filesize", "(", ")", ")", "{", "// An empty file cannot be an image.", "return", "false", ";", "}", "$", "mimetype", "=", "$", "file", "->", "get_mimetype", "(", ")", ";", "if", "(", "!", "preg_match", "(", "'|^image/|'", ",", "$", "mimetype", ")", ")", "{", "// The mimetype does not include image.", "return", "false", ";", "}", "// If it looks like an image, and it smells like an image, perhaps it's an image!", "return", "true", ";", "}" ]
Attempt to determine whether the specified file is likely to be an image. Since this relies upon the mimetype stored in the files table, there may be times when this information is not 100% accurate. @param stored_file $file The file to check @return bool
[ "Attempt", "to", "determine", "whether", "the", "specified", "file", "is", "likely", "to", "be", "an", "image", ".", "Since", "this", "relies", "upon", "the", "mimetype", "stored", "in", "the", "files", "table", "there", "may", "be", "times", "when", "this", "information", "is", "not", "100%", "accurate", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_system.php#L394-L408
213,317
moodle/moodle
lib/filestorage/file_system.php
file_system.get_imageinfo_from_path
protected function get_imageinfo_from_path($path) { $imageinfo = getimagesize($path); $image = array( 'width' => $imageinfo[0], 'height' => $imageinfo[1], 'mimetype' => image_type_to_mime_type($imageinfo[2]), ); if (empty($image['width']) or empty($image['height']) or empty($image['mimetype'])) { // GD can not parse it, sorry. return false; } return $image; }
php
protected function get_imageinfo_from_path($path) { $imageinfo = getimagesize($path); $image = array( 'width' => $imageinfo[0], 'height' => $imageinfo[1], 'mimetype' => image_type_to_mime_type($imageinfo[2]), ); if (empty($image['width']) or empty($image['height']) or empty($image['mimetype'])) { // GD can not parse it, sorry. return false; } return $image; }
[ "protected", "function", "get_imageinfo_from_path", "(", "$", "path", ")", "{", "$", "imageinfo", "=", "getimagesize", "(", "$", "path", ")", ";", "$", "image", "=", "array", "(", "'width'", "=>", "$", "imageinfo", "[", "0", "]", ",", "'height'", "=>", "$", "imageinfo", "[", "1", "]", ",", "'mimetype'", "=>", "image_type_to_mime_type", "(", "$", "imageinfo", "[", "2", "]", ")", ",", ")", ";", "if", "(", "empty", "(", "$", "image", "[", "'width'", "]", ")", "or", "empty", "(", "$", "image", "[", "'height'", "]", ")", "or", "empty", "(", "$", "image", "[", "'mimetype'", "]", ")", ")", "{", "// GD can not parse it, sorry.", "return", "false", ";", "}", "return", "$", "image", ";", "}" ]
Returns image information relating to the specified path or URL. @param string $path The path to pass to getimagesize. @return array Containing width, height, and mimetype.
[ "Returns", "image", "information", "relating", "to", "the", "specified", "path", "or", "URL", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_system.php#L416-L429
213,318
moodle/moodle
lib/filestorage/file_system.php
file_system.validate_hash_and_file_size
protected function validate_hash_and_file_size($contenthash, $pathname) { global $CFG; if (!is_readable($pathname)) { throw new file_exception('storedfilecannotread', '', $pathname); } $filesize = filesize($pathname); if ($filesize === false) { throw new file_exception('storedfilecannotread', '', $pathname); } if (is_null($contenthash)) { $contenthash = file_storage::hash_from_path($pathname); } else if ($CFG->debugdeveloper) { $filehash = file_storage::hash_from_path($pathname); if ($filehash === false) { throw new file_exception('storedfilecannotread', '', $pathname); } if ($filehash !== $contenthash) { // Hopefully this never happens, if yes we need to fix calling code. debugging("Invalid contenthash submitted for file $pathname", DEBUG_DEVELOPER); $contenthash = $filehash; } } if ($contenthash === false) { throw new file_exception('storedfilecannotread', '', $pathname); } if ($filesize > 0 and $contenthash === file_storage::hash_from_string('')) { // Did the file change or is file_storage::hash_from_path() borked for this file? clearstatcache(); $contenthash = file_storage::hash_from_path($pathname); $filesize = filesize($pathname); if ($contenthash === false or $filesize === false) { throw new file_exception('storedfilecannotread', '', $pathname); } if ($filesize > 0 and $contenthash === file_storage::hash_from_string('')) { // This is very weird... throw new file_exception('storedfilecannotread', '', $pathname); } } return [$contenthash, $filesize]; }
php
protected function validate_hash_and_file_size($contenthash, $pathname) { global $CFG; if (!is_readable($pathname)) { throw new file_exception('storedfilecannotread', '', $pathname); } $filesize = filesize($pathname); if ($filesize === false) { throw new file_exception('storedfilecannotread', '', $pathname); } if (is_null($contenthash)) { $contenthash = file_storage::hash_from_path($pathname); } else if ($CFG->debugdeveloper) { $filehash = file_storage::hash_from_path($pathname); if ($filehash === false) { throw new file_exception('storedfilecannotread', '', $pathname); } if ($filehash !== $contenthash) { // Hopefully this never happens, if yes we need to fix calling code. debugging("Invalid contenthash submitted for file $pathname", DEBUG_DEVELOPER); $contenthash = $filehash; } } if ($contenthash === false) { throw new file_exception('storedfilecannotread', '', $pathname); } if ($filesize > 0 and $contenthash === file_storage::hash_from_string('')) { // Did the file change or is file_storage::hash_from_path() borked for this file? clearstatcache(); $contenthash = file_storage::hash_from_path($pathname); $filesize = filesize($pathname); if ($contenthash === false or $filesize === false) { throw new file_exception('storedfilecannotread', '', $pathname); } if ($filesize > 0 and $contenthash === file_storage::hash_from_string('')) { // This is very weird... throw new file_exception('storedfilecannotread', '', $pathname); } } return [$contenthash, $filesize]; }
[ "protected", "function", "validate_hash_and_file_size", "(", "$", "contenthash", ",", "$", "pathname", ")", "{", "global", "$", "CFG", ";", "if", "(", "!", "is_readable", "(", "$", "pathname", ")", ")", "{", "throw", "new", "file_exception", "(", "'storedfilecannotread'", ",", "''", ",", "$", "pathname", ")", ";", "}", "$", "filesize", "=", "filesize", "(", "$", "pathname", ")", ";", "if", "(", "$", "filesize", "===", "false", ")", "{", "throw", "new", "file_exception", "(", "'storedfilecannotread'", ",", "''", ",", "$", "pathname", ")", ";", "}", "if", "(", "is_null", "(", "$", "contenthash", ")", ")", "{", "$", "contenthash", "=", "file_storage", "::", "hash_from_path", "(", "$", "pathname", ")", ";", "}", "else", "if", "(", "$", "CFG", "->", "debugdeveloper", ")", "{", "$", "filehash", "=", "file_storage", "::", "hash_from_path", "(", "$", "pathname", ")", ";", "if", "(", "$", "filehash", "===", "false", ")", "{", "throw", "new", "file_exception", "(", "'storedfilecannotread'", ",", "''", ",", "$", "pathname", ")", ";", "}", "if", "(", "$", "filehash", "!==", "$", "contenthash", ")", "{", "// Hopefully this never happens, if yes we need to fix calling code.", "debugging", "(", "\"Invalid contenthash submitted for file $pathname\"", ",", "DEBUG_DEVELOPER", ")", ";", "$", "contenthash", "=", "$", "filehash", ";", "}", "}", "if", "(", "$", "contenthash", "===", "false", ")", "{", "throw", "new", "file_exception", "(", "'storedfilecannotread'", ",", "''", ",", "$", "pathname", ")", ";", "}", "if", "(", "$", "filesize", ">", "0", "and", "$", "contenthash", "===", "file_storage", "::", "hash_from_string", "(", "''", ")", ")", "{", "// Did the file change or is file_storage::hash_from_path() borked for this file?", "clearstatcache", "(", ")", ";", "$", "contenthash", "=", "file_storage", "::", "hash_from_path", "(", "$", "pathname", ")", ";", "$", "filesize", "=", "filesize", "(", "$", "pathname", ")", ";", "if", "(", "$", "contenthash", "===", "false", "or", "$", "filesize", "===", "false", ")", "{", "throw", "new", "file_exception", "(", "'storedfilecannotread'", ",", "''", ",", "$", "pathname", ")", ";", "}", "if", "(", "$", "filesize", ">", "0", "and", "$", "contenthash", "===", "file_storage", "::", "hash_from_string", "(", "''", ")", ")", "{", "// This is very weird...", "throw", "new", "file_exception", "(", "'storedfilecannotread'", ",", "''", ",", "$", "pathname", ")", ";", "}", "}", "return", "[", "$", "contenthash", ",", "$", "filesize", "]", ";", "}" ]
Validate that the content hash matches the content hash of the file on disk. @param string $contenthash The current content hash to validate @param string $pathname The path to the file on disk @return array The content hash (it might change) and file size
[ "Validate", "that", "the", "content", "hash", "matches", "the", "content", "hash", "of", "the", "file", "on", "disk", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_system.php#L453-L498
213,319
moodle/moodle
lib/filestorage/file_system.php
file_system.get_content_file_handle
public function get_content_file_handle(stored_file $file, $type = stored_file::FILE_HANDLE_FOPEN) { if ($type === stored_file::FILE_HANDLE_GZOPEN) { // Local file required for gzopen. $path = $this->get_local_path_from_storedfile($file, true); } else { $path = $this->get_remote_path_from_storedfile($file); } return self::get_file_handle_for_path($path, $type); }
php
public function get_content_file_handle(stored_file $file, $type = stored_file::FILE_HANDLE_FOPEN) { if ($type === stored_file::FILE_HANDLE_GZOPEN) { // Local file required for gzopen. $path = $this->get_local_path_from_storedfile($file, true); } else { $path = $this->get_remote_path_from_storedfile($file); } return self::get_file_handle_for_path($path, $type); }
[ "public", "function", "get_content_file_handle", "(", "stored_file", "$", "file", ",", "$", "type", "=", "stored_file", "::", "FILE_HANDLE_FOPEN", ")", "{", "if", "(", "$", "type", "===", "stored_file", "::", "FILE_HANDLE_GZOPEN", ")", "{", "// Local file required for gzopen.", "$", "path", "=", "$", "this", "->", "get_local_path_from_storedfile", "(", "$", "file", ",", "true", ")", ";", "}", "else", "{", "$", "path", "=", "$", "this", "->", "get_remote_path_from_storedfile", "(", "$", "file", ")", ";", "}", "return", "self", "::", "get_file_handle_for_path", "(", "$", "path", ",", "$", "type", ")", ";", "}" ]
Returns file handle - read only mode, no writing allowed into pool files! When you want to modify a file, create a new file and delete the old one. @param stored_file $file The file to retrieve a handle for @param int $type Type of file handle (FILE_HANDLE_xx constant) @return resource file handle
[ "Returns", "file", "handle", "-", "read", "only", "mode", "no", "writing", "allowed", "into", "pool", "files!" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_system.php#L534-L543
213,320
moodle/moodle
lib/filestorage/file_system.php
file_system.get_file_handle_for_path
protected static function get_file_handle_for_path($path, $type = stored_file::FILE_HANDLE_FOPEN) { switch ($type) { case stored_file::FILE_HANDLE_FOPEN: // Binary reading. return fopen($path, 'rb'); case stored_file::FILE_HANDLE_GZOPEN: // Binary reading of file in gz format. return gzopen($path, 'rb'); default: throw new coding_exception('Unexpected file handle type'); } }
php
protected static function get_file_handle_for_path($path, $type = stored_file::FILE_HANDLE_FOPEN) { switch ($type) { case stored_file::FILE_HANDLE_FOPEN: // Binary reading. return fopen($path, 'rb'); case stored_file::FILE_HANDLE_GZOPEN: // Binary reading of file in gz format. return gzopen($path, 'rb'); default: throw new coding_exception('Unexpected file handle type'); } }
[ "protected", "static", "function", "get_file_handle_for_path", "(", "$", "path", ",", "$", "type", "=", "stored_file", "::", "FILE_HANDLE_FOPEN", ")", "{", "switch", "(", "$", "type", ")", "{", "case", "stored_file", "::", "FILE_HANDLE_FOPEN", ":", "// Binary reading.", "return", "fopen", "(", "$", "path", ",", "'rb'", ")", ";", "case", "stored_file", "::", "FILE_HANDLE_GZOPEN", ":", "// Binary reading of file in gz format.", "return", "gzopen", "(", "$", "path", ",", "'rb'", ")", ";", "default", ":", "throw", "new", "coding_exception", "(", "'Unexpected file handle type'", ")", ";", "}", "}" ]
Return a file handle for the specified path. This abstraction should be used when overriding get_content_file_handle in a new file system. @param string $path The path to the file. This shoudl be any type of path that fopen and gzopen accept. @param int $type Type of file handle (FILE_HANDLE_xx constant) @return resource @throws coding_exception When an unexpected type of file handle is requested
[ "Return", "a", "file", "handle", "for", "the", "specified", "path", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/file_system.php#L555-L566
213,321
moodle/moodle
mod/workshop/allocation/manual/renderer.php
workshopallocation_manual_renderer.render_workshopallocation_manual_allocations
protected function render_workshopallocation_manual_allocations(workshopallocation_manual_allocations $data) { $this->workshop = $data->workshop; $allocations = $data->allocations; // array prepared array of all allocations data $userinfo = $data->userinfo; // names and pictures of all required users $authors = $data->authors; // array potential reviewees $reviewers = $data->reviewers; // array potential submission reviewers $hlauthorid = $data->hlauthorid; // int id of the author to highlight $hlreviewerid = $data->hlreviewerid; // int id of the reviewer to highlight $selfassessment = $data->selfassessment; // bool is the self-assessment allowed in this workshop? if (empty($allocations)) { return ''; } // convert user collections into drop down menus $authors = array_map('fullname', $authors); $reviewers = array_map('fullname', $reviewers); $table = new html_table(); $table->attributes['class'] = 'allocations'; $table->head = array(get_string('participantreviewedby', 'workshop'), get_string('participant', 'workshop'), get_string('participantrevierof', 'workshop')); $table->rowclasses = array(); $table->colclasses = array('reviewedby', 'peer', 'reviewerof'); $table->data = array(); foreach ($allocations as $allocation) { $row = array(); $row[] = $this->helper_reviewers_of_participant($allocation, $userinfo, $reviewers, $selfassessment); $row[] = $this->helper_participant($allocation, $userinfo); $row[] = $this->helper_reviewees_of_participant($allocation, $userinfo, $authors, $selfassessment); $thisrowclasses = array(); if ($allocation->userid == $hlauthorid) { $thisrowclasses[] = 'highlightreviewedby'; } if ($allocation->userid == $hlreviewerid) { $thisrowclasses[] = 'highlightreviewerof'; } $table->rowclasses[] = implode(' ', $thisrowclasses); $table->data[] = $row; } return $this->output->container(html_writer::table($table), 'manual-allocator'); }
php
protected function render_workshopallocation_manual_allocations(workshopallocation_manual_allocations $data) { $this->workshop = $data->workshop; $allocations = $data->allocations; // array prepared array of all allocations data $userinfo = $data->userinfo; // names and pictures of all required users $authors = $data->authors; // array potential reviewees $reviewers = $data->reviewers; // array potential submission reviewers $hlauthorid = $data->hlauthorid; // int id of the author to highlight $hlreviewerid = $data->hlreviewerid; // int id of the reviewer to highlight $selfassessment = $data->selfassessment; // bool is the self-assessment allowed in this workshop? if (empty($allocations)) { return ''; } // convert user collections into drop down menus $authors = array_map('fullname', $authors); $reviewers = array_map('fullname', $reviewers); $table = new html_table(); $table->attributes['class'] = 'allocations'; $table->head = array(get_string('participantreviewedby', 'workshop'), get_string('participant', 'workshop'), get_string('participantrevierof', 'workshop')); $table->rowclasses = array(); $table->colclasses = array('reviewedby', 'peer', 'reviewerof'); $table->data = array(); foreach ($allocations as $allocation) { $row = array(); $row[] = $this->helper_reviewers_of_participant($allocation, $userinfo, $reviewers, $selfassessment); $row[] = $this->helper_participant($allocation, $userinfo); $row[] = $this->helper_reviewees_of_participant($allocation, $userinfo, $authors, $selfassessment); $thisrowclasses = array(); if ($allocation->userid == $hlauthorid) { $thisrowclasses[] = 'highlightreviewedby'; } if ($allocation->userid == $hlreviewerid) { $thisrowclasses[] = 'highlightreviewerof'; } $table->rowclasses[] = implode(' ', $thisrowclasses); $table->data[] = $row; } return $this->output->container(html_writer::table($table), 'manual-allocator'); }
[ "protected", "function", "render_workshopallocation_manual_allocations", "(", "workshopallocation_manual_allocations", "$", "data", ")", "{", "$", "this", "->", "workshop", "=", "$", "data", "->", "workshop", ";", "$", "allocations", "=", "$", "data", "->", "allocations", ";", "// array prepared array of all allocations data", "$", "userinfo", "=", "$", "data", "->", "userinfo", ";", "// names and pictures of all required users", "$", "authors", "=", "$", "data", "->", "authors", ";", "// array potential reviewees", "$", "reviewers", "=", "$", "data", "->", "reviewers", ";", "// array potential submission reviewers", "$", "hlauthorid", "=", "$", "data", "->", "hlauthorid", ";", "// int id of the author to highlight", "$", "hlreviewerid", "=", "$", "data", "->", "hlreviewerid", ";", "// int id of the reviewer to highlight", "$", "selfassessment", "=", "$", "data", "->", "selfassessment", ";", "// bool is the self-assessment allowed in this workshop?", "if", "(", "empty", "(", "$", "allocations", ")", ")", "{", "return", "''", ";", "}", "// convert user collections into drop down menus", "$", "authors", "=", "array_map", "(", "'fullname'", ",", "$", "authors", ")", ";", "$", "reviewers", "=", "array_map", "(", "'fullname'", ",", "$", "reviewers", ")", ";", "$", "table", "=", "new", "html_table", "(", ")", ";", "$", "table", "->", "attributes", "[", "'class'", "]", "=", "'allocations'", ";", "$", "table", "->", "head", "=", "array", "(", "get_string", "(", "'participantreviewedby'", ",", "'workshop'", ")", ",", "get_string", "(", "'participant'", ",", "'workshop'", ")", ",", "get_string", "(", "'participantrevierof'", ",", "'workshop'", ")", ")", ";", "$", "table", "->", "rowclasses", "=", "array", "(", ")", ";", "$", "table", "->", "colclasses", "=", "array", "(", "'reviewedby'", ",", "'peer'", ",", "'reviewerof'", ")", ";", "$", "table", "->", "data", "=", "array", "(", ")", ";", "foreach", "(", "$", "allocations", "as", "$", "allocation", ")", "{", "$", "row", "=", "array", "(", ")", ";", "$", "row", "[", "]", "=", "$", "this", "->", "helper_reviewers_of_participant", "(", "$", "allocation", ",", "$", "userinfo", ",", "$", "reviewers", ",", "$", "selfassessment", ")", ";", "$", "row", "[", "]", "=", "$", "this", "->", "helper_participant", "(", "$", "allocation", ",", "$", "userinfo", ")", ";", "$", "row", "[", "]", "=", "$", "this", "->", "helper_reviewees_of_participant", "(", "$", "allocation", ",", "$", "userinfo", ",", "$", "authors", ",", "$", "selfassessment", ")", ";", "$", "thisrowclasses", "=", "array", "(", ")", ";", "if", "(", "$", "allocation", "->", "userid", "==", "$", "hlauthorid", ")", "{", "$", "thisrowclasses", "[", "]", "=", "'highlightreviewedby'", ";", "}", "if", "(", "$", "allocation", "->", "userid", "==", "$", "hlreviewerid", ")", "{", "$", "thisrowclasses", "[", "]", "=", "'highlightreviewerof'", ";", "}", "$", "table", "->", "rowclasses", "[", "]", "=", "implode", "(", "' '", ",", "$", "thisrowclasses", ")", ";", "$", "table", "->", "data", "[", "]", "=", "$", "row", ";", "}", "return", "$", "this", "->", "output", "->", "container", "(", "html_writer", "::", "table", "(", "$", "table", ")", ",", "'manual-allocator'", ")", ";", "}" ]
Display the table of all current allocations and widgets to modify them @param workshopallocation_manual_allocations $data to be displayed @return string html code
[ "Display", "the", "table", "of", "all", "current", "allocations", "and", "widgets", "to", "modify", "them" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/allocation/manual/renderer.php#L47-L92
213,322
moodle/moodle
mod/workshop/allocation/manual/renderer.php
workshopallocation_manual_renderer.helper_participant
protected function helper_participant(stdclass $allocation, array $userinfo) { $o = $this->output->user_picture($userinfo[$allocation->userid], array('courseid' => $this->page->course->id)); $o .= fullname($userinfo[$allocation->userid]); $o .= $this->output->container_start(array('submission')); if (is_null($allocation->submissionid)) { $o .= $this->output->container(get_string('nosubmissionfound', 'workshop'), 'info'); } else { $link = $this->workshop->submission_url($allocation->submissionid); $o .= $this->output->container(html_writer::link($link, format_string($allocation->submissiontitle)), 'title'); if (is_null($allocation->submissiongrade)) { $o .= $this->output->container(get_string('nogradeyet', 'workshop'), array('grade', 'missing')); } else { $o .= $this->output->container(get_string('alreadygraded', 'workshop'), array('grade', 'missing')); } } $o .= $this->output->container_end(); return $o; }
php
protected function helper_participant(stdclass $allocation, array $userinfo) { $o = $this->output->user_picture($userinfo[$allocation->userid], array('courseid' => $this->page->course->id)); $o .= fullname($userinfo[$allocation->userid]); $o .= $this->output->container_start(array('submission')); if (is_null($allocation->submissionid)) { $o .= $this->output->container(get_string('nosubmissionfound', 'workshop'), 'info'); } else { $link = $this->workshop->submission_url($allocation->submissionid); $o .= $this->output->container(html_writer::link($link, format_string($allocation->submissiontitle)), 'title'); if (is_null($allocation->submissiongrade)) { $o .= $this->output->container(get_string('nogradeyet', 'workshop'), array('grade', 'missing')); } else { $o .= $this->output->container(get_string('alreadygraded', 'workshop'), array('grade', 'missing')); } } $o .= $this->output->container_end(); return $o; }
[ "protected", "function", "helper_participant", "(", "stdclass", "$", "allocation", ",", "array", "$", "userinfo", ")", "{", "$", "o", "=", "$", "this", "->", "output", "->", "user_picture", "(", "$", "userinfo", "[", "$", "allocation", "->", "userid", "]", ",", "array", "(", "'courseid'", "=>", "$", "this", "->", "page", "->", "course", "->", "id", ")", ")", ";", "$", "o", ".=", "fullname", "(", "$", "userinfo", "[", "$", "allocation", "->", "userid", "]", ")", ";", "$", "o", ".=", "$", "this", "->", "output", "->", "container_start", "(", "array", "(", "'submission'", ")", ")", ";", "if", "(", "is_null", "(", "$", "allocation", "->", "submissionid", ")", ")", "{", "$", "o", ".=", "$", "this", "->", "output", "->", "container", "(", "get_string", "(", "'nosubmissionfound'", ",", "'workshop'", ")", ",", "'info'", ")", ";", "}", "else", "{", "$", "link", "=", "$", "this", "->", "workshop", "->", "submission_url", "(", "$", "allocation", "->", "submissionid", ")", ";", "$", "o", ".=", "$", "this", "->", "output", "->", "container", "(", "html_writer", "::", "link", "(", "$", "link", ",", "format_string", "(", "$", "allocation", "->", "submissiontitle", ")", ")", ",", "'title'", ")", ";", "if", "(", "is_null", "(", "$", "allocation", "->", "submissiongrade", ")", ")", "{", "$", "o", ".=", "$", "this", "->", "output", "->", "container", "(", "get_string", "(", "'nogradeyet'", ",", "'workshop'", ")", ",", "array", "(", "'grade'", ",", "'missing'", ")", ")", ";", "}", "else", "{", "$", "o", ".=", "$", "this", "->", "output", "->", "container", "(", "get_string", "(", "'alreadygraded'", ",", "'workshop'", ")", ",", "array", "(", "'grade'", ",", "'missing'", ")", ")", ";", "}", "}", "$", "o", ".=", "$", "this", "->", "output", "->", "container_end", "(", ")", ";", "return", "$", "o", ";", "}" ]
Returns information about the workshop participant @return string HTML code
[ "Returns", "information", "about", "the", "workshop", "participant" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/allocation/manual/renderer.php#L103-L120
213,323
moodle/moodle
mod/workshop/allocation/manual/renderer.php
workshopallocation_manual_renderer.helper_reviewers_of_participant
protected function helper_reviewers_of_participant(stdclass $allocation, array $userinfo, array $reviewers, $selfassessment) { $o = ''; if (is_null($allocation->submissionid)) { $o .= $this->output->container(get_string('nothingtoreview', 'workshop'), 'info'); } else { $exclude = array(); if (! $selfassessment) { $exclude[$allocation->userid] = true; } // todo add an option to exclude users without own submission $options = array_diff_key($reviewers, $exclude); if ($options) { $handler = new moodle_url($this->page->url, array('mode' => 'new', 'of' => $allocation->userid, 'sesskey' => sesskey())); $select = new single_select($handler, 'by', $options, '', array(''=>get_string('chooseuser', 'workshop')), 'addreviewof' . $allocation->userid); $select->set_label(get_string('addreviewer', 'workshopallocation_manual')); $o .= $this->output->render($select); } } $o .= html_writer::start_tag('ul', array()); foreach ($allocation->reviewedby as $reviewerid => $assessmentid) { $o .= html_writer::start_tag('li', array()); $o .= $this->output->user_picture($userinfo[$reviewerid], array('courseid' => $this->page->course->id, 'size' => 16)); $o .= fullname($userinfo[$reviewerid]); // delete icon $handler = new moodle_url($this->page->url, array('mode' => 'del', 'what' => $assessmentid, 'sesskey' => sesskey())); $o .= $this->helper_remove_allocation_icon($handler); $o .= html_writer::end_tag('li'); } $o .= html_writer::end_tag('ul'); return $o; }
php
protected function helper_reviewers_of_participant(stdclass $allocation, array $userinfo, array $reviewers, $selfassessment) { $o = ''; if (is_null($allocation->submissionid)) { $o .= $this->output->container(get_string('nothingtoreview', 'workshop'), 'info'); } else { $exclude = array(); if (! $selfassessment) { $exclude[$allocation->userid] = true; } // todo add an option to exclude users without own submission $options = array_diff_key($reviewers, $exclude); if ($options) { $handler = new moodle_url($this->page->url, array('mode' => 'new', 'of' => $allocation->userid, 'sesskey' => sesskey())); $select = new single_select($handler, 'by', $options, '', array(''=>get_string('chooseuser', 'workshop')), 'addreviewof' . $allocation->userid); $select->set_label(get_string('addreviewer', 'workshopallocation_manual')); $o .= $this->output->render($select); } } $o .= html_writer::start_tag('ul', array()); foreach ($allocation->reviewedby as $reviewerid => $assessmentid) { $o .= html_writer::start_tag('li', array()); $o .= $this->output->user_picture($userinfo[$reviewerid], array('courseid' => $this->page->course->id, 'size' => 16)); $o .= fullname($userinfo[$reviewerid]); // delete icon $handler = new moodle_url($this->page->url, array('mode' => 'del', 'what' => $assessmentid, 'sesskey' => sesskey())); $o .= $this->helper_remove_allocation_icon($handler); $o .= html_writer::end_tag('li'); } $o .= html_writer::end_tag('ul'); return $o; }
[ "protected", "function", "helper_reviewers_of_participant", "(", "stdclass", "$", "allocation", ",", "array", "$", "userinfo", ",", "array", "$", "reviewers", ",", "$", "selfassessment", ")", "{", "$", "o", "=", "''", ";", "if", "(", "is_null", "(", "$", "allocation", "->", "submissionid", ")", ")", "{", "$", "o", ".=", "$", "this", "->", "output", "->", "container", "(", "get_string", "(", "'nothingtoreview'", ",", "'workshop'", ")", ",", "'info'", ")", ";", "}", "else", "{", "$", "exclude", "=", "array", "(", ")", ";", "if", "(", "!", "$", "selfassessment", ")", "{", "$", "exclude", "[", "$", "allocation", "->", "userid", "]", "=", "true", ";", "}", "// todo add an option to exclude users without own submission", "$", "options", "=", "array_diff_key", "(", "$", "reviewers", ",", "$", "exclude", ")", ";", "if", "(", "$", "options", ")", "{", "$", "handler", "=", "new", "moodle_url", "(", "$", "this", "->", "page", "->", "url", ",", "array", "(", "'mode'", "=>", "'new'", ",", "'of'", "=>", "$", "allocation", "->", "userid", ",", "'sesskey'", "=>", "sesskey", "(", ")", ")", ")", ";", "$", "select", "=", "new", "single_select", "(", "$", "handler", ",", "'by'", ",", "$", "options", ",", "''", ",", "array", "(", "''", "=>", "get_string", "(", "'chooseuser'", ",", "'workshop'", ")", ")", ",", "'addreviewof'", ".", "$", "allocation", "->", "userid", ")", ";", "$", "select", "->", "set_label", "(", "get_string", "(", "'addreviewer'", ",", "'workshopallocation_manual'", ")", ")", ";", "$", "o", ".=", "$", "this", "->", "output", "->", "render", "(", "$", "select", ")", ";", "}", "}", "$", "o", ".=", "html_writer", "::", "start_tag", "(", "'ul'", ",", "array", "(", ")", ")", ";", "foreach", "(", "$", "allocation", "->", "reviewedby", "as", "$", "reviewerid", "=>", "$", "assessmentid", ")", "{", "$", "o", ".=", "html_writer", "::", "start_tag", "(", "'li'", ",", "array", "(", ")", ")", ";", "$", "o", ".=", "$", "this", "->", "output", "->", "user_picture", "(", "$", "userinfo", "[", "$", "reviewerid", "]", ",", "array", "(", "'courseid'", "=>", "$", "this", "->", "page", "->", "course", "->", "id", ",", "'size'", "=>", "16", ")", ")", ";", "$", "o", ".=", "fullname", "(", "$", "userinfo", "[", "$", "reviewerid", "]", ")", ";", "// delete icon", "$", "handler", "=", "new", "moodle_url", "(", "$", "this", "->", "page", "->", "url", ",", "array", "(", "'mode'", "=>", "'del'", ",", "'what'", "=>", "$", "assessmentid", ",", "'sesskey'", "=>", "sesskey", "(", ")", ")", ")", ";", "$", "o", ".=", "$", "this", "->", "helper_remove_allocation_icon", "(", "$", "handler", ")", ";", "$", "o", ".=", "html_writer", "::", "end_tag", "(", "'li'", ")", ";", "}", "$", "o", ".=", "html_writer", "::", "end_tag", "(", "'ul'", ")", ";", "return", "$", "o", ";", "}" ]
Returns information about the current reviewers of the given participant and a selector do add new one @return string html code
[ "Returns", "information", "about", "the", "current", "reviewers", "of", "the", "given", "participant", "and", "a", "selector", "do", "add", "new", "one" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/workshop/allocation/manual/renderer.php#L127-L159
213,324
moodle/moodle
lib/pear/HTML/QuickForm/Renderer/Array.php
HTML_QuickForm_Renderer_Array.renderElement
function renderElement(&$element, $required, $error) { $elAry = $this->_elementToArray($element, $required, $error); if (!empty($error)) { $this->_ary['errors'][$elAry['name']] = $error; } $this->_storeArray($elAry); }
php
function renderElement(&$element, $required, $error) { $elAry = $this->_elementToArray($element, $required, $error); if (!empty($error)) { $this->_ary['errors'][$elAry['name']] = $error; } $this->_storeArray($elAry); }
[ "function", "renderElement", "(", "&", "$", "element", ",", "$", "required", ",", "$", "error", ")", "{", "$", "elAry", "=", "$", "this", "->", "_elementToArray", "(", "$", "element", ",", "$", "required", ",", "$", "error", ")", ";", "if", "(", "!", "empty", "(", "$", "error", ")", ")", "{", "$", "this", "->", "_ary", "[", "'errors'", "]", "[", "$", "elAry", "[", "'name'", "]", "]", "=", "$", "error", ";", "}", "$", "this", "->", "_storeArray", "(", "$", "elAry", ")", ";", "}" ]
end func renderHeader
[ "end", "func", "renderHeader" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/Renderer/Array.php#L206-L213
213,325
moodle/moodle
lib/pear/HTML/QuickForm/Renderer/Array.php
HTML_QuickForm_Renderer_Array._elementToArray
function _elementToArray(&$element, $required, $error) { $ret = array( 'name' => $element->getName(), 'value' => $element->getValue(), 'type' => $element->getType(), 'frozen' => $element->isFrozen(), 'required' => $required, 'error' => $error ); // render label(s) $labels = $element->getLabel(); if (is_array($labels) && $this->_staticLabels) { foreach($labels as $key => $label) { $key = is_int($key)? $key + 1: $key; if (1 === $key) { $ret['label'] = $label; } else { $ret['label_' . $key] = $label; } } } else { $ret['label'] = $labels; } // set the style for the element if (isset($this->_elementStyles[$ret['name']])) { $ret['style'] = $this->_elementStyles[$ret['name']]; } if ('group' == $ret['type']) { $ret['separator'] = $element->_separator; $ret['elements'] = array(); } else { $ret['html'] = $element->toHtml(); } return $ret; }
php
function _elementToArray(&$element, $required, $error) { $ret = array( 'name' => $element->getName(), 'value' => $element->getValue(), 'type' => $element->getType(), 'frozen' => $element->isFrozen(), 'required' => $required, 'error' => $error ); // render label(s) $labels = $element->getLabel(); if (is_array($labels) && $this->_staticLabels) { foreach($labels as $key => $label) { $key = is_int($key)? $key + 1: $key; if (1 === $key) { $ret['label'] = $label; } else { $ret['label_' . $key] = $label; } } } else { $ret['label'] = $labels; } // set the style for the element if (isset($this->_elementStyles[$ret['name']])) { $ret['style'] = $this->_elementStyles[$ret['name']]; } if ('group' == $ret['type']) { $ret['separator'] = $element->_separator; $ret['elements'] = array(); } else { $ret['html'] = $element->toHtml(); } return $ret; }
[ "function", "_elementToArray", "(", "&", "$", "element", ",", "$", "required", ",", "$", "error", ")", "{", "$", "ret", "=", "array", "(", "'name'", "=>", "$", "element", "->", "getName", "(", ")", ",", "'value'", "=>", "$", "element", "->", "getValue", "(", ")", ",", "'type'", "=>", "$", "element", "->", "getType", "(", ")", ",", "'frozen'", "=>", "$", "element", "->", "isFrozen", "(", ")", ",", "'required'", "=>", "$", "required", ",", "'error'", "=>", "$", "error", ")", ";", "// render label(s)", "$", "labels", "=", "$", "element", "->", "getLabel", "(", ")", ";", "if", "(", "is_array", "(", "$", "labels", ")", "&&", "$", "this", "->", "_staticLabels", ")", "{", "foreach", "(", "$", "labels", "as", "$", "key", "=>", "$", "label", ")", "{", "$", "key", "=", "is_int", "(", "$", "key", ")", "?", "$", "key", "+", "1", ":", "$", "key", ";", "if", "(", "1", "===", "$", "key", ")", "{", "$", "ret", "[", "'label'", "]", "=", "$", "label", ";", "}", "else", "{", "$", "ret", "[", "'label_'", ".", "$", "key", "]", "=", "$", "label", ";", "}", "}", "}", "else", "{", "$", "ret", "[", "'label'", "]", "=", "$", "labels", ";", "}", "// set the style for the element", "if", "(", "isset", "(", "$", "this", "->", "_elementStyles", "[", "$", "ret", "[", "'name'", "]", "]", ")", ")", "{", "$", "ret", "[", "'style'", "]", "=", "$", "this", "->", "_elementStyles", "[", "$", "ret", "[", "'name'", "]", "]", ";", "}", "if", "(", "'group'", "==", "$", "ret", "[", "'type'", "]", ")", "{", "$", "ret", "[", "'separator'", "]", "=", "$", "element", "->", "_separator", ";", "$", "ret", "[", "'elements'", "]", "=", "array", "(", ")", ";", "}", "else", "{", "$", "ret", "[", "'html'", "]", "=", "$", "element", "->", "toHtml", "(", ")", ";", "}", "return", "$", "ret", ";", "}" ]
Creates an array representing an element @access private @param object An HTML_QuickForm_element object @param bool Whether an element is required @param string Error associated with the element @return array
[ "Creates", "an", "array", "representing", "an", "element" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/Renderer/Array.php#L251-L287
213,326
moodle/moodle
lib/pear/HTML/QuickForm/Renderer/Array.php
HTML_QuickForm_Renderer_Array._storeArray
function _storeArray($elAry) { // where should we put this element... if (is_array($this->_currentGroup) && ('group' != $elAry['type'])) { $this->_currentGroup['elements'][] = $elAry; } elseif (isset($this->_currentSection)) { $this->_ary['sections'][$this->_currentSection]['elements'][] = $elAry; } else { $this->_ary['elements'][] = $elAry; } }
php
function _storeArray($elAry) { // where should we put this element... if (is_array($this->_currentGroup) && ('group' != $elAry['type'])) { $this->_currentGroup['elements'][] = $elAry; } elseif (isset($this->_currentSection)) { $this->_ary['sections'][$this->_currentSection]['elements'][] = $elAry; } else { $this->_ary['elements'][] = $elAry; } }
[ "function", "_storeArray", "(", "$", "elAry", ")", "{", "// where should we put this element...", "if", "(", "is_array", "(", "$", "this", "->", "_currentGroup", ")", "&&", "(", "'group'", "!=", "$", "elAry", "[", "'type'", "]", ")", ")", "{", "$", "this", "->", "_currentGroup", "[", "'elements'", "]", "[", "]", "=", "$", "elAry", ";", "}", "elseif", "(", "isset", "(", "$", "this", "->", "_currentSection", ")", ")", "{", "$", "this", "->", "_ary", "[", "'sections'", "]", "[", "$", "this", "->", "_currentSection", "]", "[", "'elements'", "]", "[", "]", "=", "$", "elAry", ";", "}", "else", "{", "$", "this", "->", "_ary", "[", "'elements'", "]", "[", "]", "=", "$", "elAry", ";", "}", "}" ]
Stores an array representation of an element in the form array @access private @param array Array representation of an element @return void
[ "Stores", "an", "array", "representation", "of", "an", "element", "in", "the", "form", "array" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/Renderer/Array.php#L297-L307
213,327
moodle/moodle
lib/pear/HTML/QuickForm/Renderer/Array.php
HTML_QuickForm_Renderer_Array.setElementStyle
function setElementStyle($elementName, $styleName = null) { if (is_array($elementName)) { $this->_elementStyles = array_merge($this->_elementStyles, $elementName); } else { $this->_elementStyles[$elementName] = $styleName; } }
php
function setElementStyle($elementName, $styleName = null) { if (is_array($elementName)) { $this->_elementStyles = array_merge($this->_elementStyles, $elementName); } else { $this->_elementStyles[$elementName] = $styleName; } }
[ "function", "setElementStyle", "(", "$", "elementName", ",", "$", "styleName", "=", "null", ")", "{", "if", "(", "is_array", "(", "$", "elementName", ")", ")", "{", "$", "this", "->", "_elementStyles", "=", "array_merge", "(", "$", "this", "->", "_elementStyles", ",", "$", "elementName", ")", ";", "}", "else", "{", "$", "this", "->", "_elementStyles", "[", "$", "elementName", "]", "=", "$", "styleName", ";", "}", "}" ]
Sets a style to use for element rendering @param mixed element name or array ('element name' => 'style name') @param string style name if $elementName is not an array @access public @return void
[ "Sets", "a", "style", "to", "use", "for", "element", "rendering" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/Renderer/Array.php#L318-L325
213,328
moodle/moodle
lib/form/grading.php
MoodleQuickForm_grading.get_gradinginstance
public function get_gradinginstance() { if (is_array($this->gradingattributes) && array_key_exists('gradinginstance', $this->gradingattributes)) { return $this->gradingattributes['gradinginstance']; } else { return null; } }
php
public function get_gradinginstance() { if (is_array($this->gradingattributes) && array_key_exists('gradinginstance', $this->gradingattributes)) { return $this->gradingattributes['gradinginstance']; } else { return null; } }
[ "public", "function", "get_gradinginstance", "(", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "gradingattributes", ")", "&&", "array_key_exists", "(", "'gradinginstance'", ",", "$", "this", "->", "gradingattributes", ")", ")", "{", "return", "$", "this", "->", "gradingattributes", "[", "'gradinginstance'", "]", ";", "}", "else", "{", "return", "null", ";", "}", "}" ]
Helper function to retrieve gradingform_instance passed in element attributes @return gradingform_instance
[ "Helper", "function", "to", "retrieve", "gradingform_instance", "passed", "in", "element", "attributes" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/grading.php#L90-L96
213,329
moodle/moodle
lib/form/grading.php
MoodleQuickForm_grading.onQuickFormEvent
public function onQuickFormEvent($event, $arg, &$caller) { if ($event == 'createElement') { $attributes = $arg[2]; if (!is_array($attributes) || !array_key_exists('gradinginstance', $attributes) || !($attributes['gradinginstance'] instanceof gradingform_instance)) { throw new moodle_exception('exc_gradingformelement', 'grading'); } } $name = $this->getName(); if ($name && $caller->elementExists($name)) { $caller->addRule($name, $this->get_gradinginstance()->default_validation_error_message(), 'gradingvalidated', $this->gradingattributes); } return parent::onQuickFormEvent($event, $arg, $caller); }
php
public function onQuickFormEvent($event, $arg, &$caller) { if ($event == 'createElement') { $attributes = $arg[2]; if (!is_array($attributes) || !array_key_exists('gradinginstance', $attributes) || !($attributes['gradinginstance'] instanceof gradingform_instance)) { throw new moodle_exception('exc_gradingformelement', 'grading'); } } $name = $this->getName(); if ($name && $caller->elementExists($name)) { $caller->addRule($name, $this->get_gradinginstance()->default_validation_error_message(), 'gradingvalidated', $this->gradingattributes); } return parent::onQuickFormEvent($event, $arg, $caller); }
[ "public", "function", "onQuickFormEvent", "(", "$", "event", ",", "$", "arg", ",", "&", "$", "caller", ")", "{", "if", "(", "$", "event", "==", "'createElement'", ")", "{", "$", "attributes", "=", "$", "arg", "[", "2", "]", ";", "if", "(", "!", "is_array", "(", "$", "attributes", ")", "||", "!", "array_key_exists", "(", "'gradinginstance'", ",", "$", "attributes", ")", "||", "!", "(", "$", "attributes", "[", "'gradinginstance'", "]", "instanceof", "gradingform_instance", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'exc_gradingformelement'", ",", "'grading'", ")", ";", "}", "}", "$", "name", "=", "$", "this", "->", "getName", "(", ")", ";", "if", "(", "$", "name", "&&", "$", "caller", "->", "elementExists", "(", "$", "name", ")", ")", "{", "$", "caller", "->", "addRule", "(", "$", "name", ",", "$", "this", "->", "get_gradinginstance", "(", ")", "->", "default_validation_error_message", "(", ")", ",", "'gradingvalidated'", ",", "$", "this", "->", "gradingattributes", ")", ";", "}", "return", "parent", "::", "onQuickFormEvent", "(", "$", "event", ",", "$", "arg", ",", "$", "caller", ")", ";", "}" ]
Called by HTML_QuickForm whenever form event is made on this element. Adds necessary rules to the element and checks that coorenct instance of gradingform_instance is passed in attributes @param string $event Name of event @param mixed $arg event arguments @param object $caller calling object @return bool @throws moodle_exception
[ "Called", "by", "HTML_QuickForm", "whenever", "form", "event", "is", "made", "on", "this", "element", ".", "Adds", "necessary", "rules", "to", "the", "element", "and", "checks", "that", "coorenct", "instance", "of", "gradingform_instance", "is", "passed", "in", "attributes" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/grading.php#L138-L151
213,330
moodle/moodle
message/classes/api.php
api.search_messages
public static function search_messages($userid, $search, $limitfrom = 0, $limitnum = 0) { global $DB; // Get the user fields we want. $ufields = \user_picture::fields('u', array('lastaccess'), 'userfrom_id', 'userfrom_'); $ufields2 = \user_picture::fields('u2', array('lastaccess'), 'userto_id', 'userto_'); // Add the uniqueid column to make each row unique and avoid SQL errors. $uniqueidsql = $DB->sql_concat('m.id', "'_'", 'm.useridfrom', "'_'", 'mcm.userid'); $sql = "SELECT $uniqueidsql AS uniqueid, m.id, m.useridfrom, mcm.userid as useridto, m.subject, m.fullmessage, m.fullmessagehtml, m.fullmessageformat, m.smallmessage, m.conversationid, m.timecreated, 0 as isread, $ufields, mub.id as userfrom_blocked, $ufields2, mub2.id as userto_blocked FROM {messages} m INNER JOIN {user} u ON u.id = m.useridfrom INNER JOIN {message_conversations} mc ON mc.id = m.conversationid INNER JOIN {message_conversation_members} mcm ON mcm.conversationid = m.conversationid INNER JOIN {user} u2 ON u2.id = mcm.userid LEFT JOIN {message_users_blocked} mub ON (mub.blockeduserid = u.id AND mub.userid = ?) LEFT JOIN {message_users_blocked} mub2 ON (mub2.blockeduserid = u2.id AND mub2.userid = ?) LEFT JOIN {message_user_actions} mua ON (mua.messageid = m.id AND mua.userid = ? AND mua.action = ?) WHERE (m.useridfrom = ? OR mcm.userid = ?) AND (m.useridfrom != mcm.userid OR mc.type = ?) AND u.deleted = 0 AND u2.deleted = 0 AND mua.id is NULL AND " . $DB->sql_like('smallmessage', '?', false) . " ORDER BY timecreated DESC"; $params = array($userid, $userid, $userid, self::MESSAGE_ACTION_DELETED, $userid, $userid, self::MESSAGE_CONVERSATION_TYPE_SELF, '%' . $search . '%'); // Convert the messages into searchable contacts with their last message being the message that was searched. $conversations = array(); if ($messages = $DB->get_records_sql($sql, $params, $limitfrom, $limitnum)) { foreach ($messages as $message) { $prefix = 'userfrom_'; if ($userid == $message->useridfrom) { $prefix = 'userto_'; // If it from the user, then mark it as read, even if it wasn't by the receiver. $message->isread = true; } $blockedcol = $prefix . 'blocked'; $message->blocked = $message->$blockedcol ? 1 : 0; $message->messageid = $message->id; // To avoid duplicate messages, only add the message if it hasn't been added previously. if (!array_key_exists($message->messageid, $conversations)) { $conversations[$message->messageid] = helper::create_contact($message, $prefix); } } // Remove the messageid keys (to preserve the expected type). $conversations = array_values($conversations); } return $conversations; }
php
public static function search_messages($userid, $search, $limitfrom = 0, $limitnum = 0) { global $DB; // Get the user fields we want. $ufields = \user_picture::fields('u', array('lastaccess'), 'userfrom_id', 'userfrom_'); $ufields2 = \user_picture::fields('u2', array('lastaccess'), 'userto_id', 'userto_'); // Add the uniqueid column to make each row unique and avoid SQL errors. $uniqueidsql = $DB->sql_concat('m.id', "'_'", 'm.useridfrom', "'_'", 'mcm.userid'); $sql = "SELECT $uniqueidsql AS uniqueid, m.id, m.useridfrom, mcm.userid as useridto, m.subject, m.fullmessage, m.fullmessagehtml, m.fullmessageformat, m.smallmessage, m.conversationid, m.timecreated, 0 as isread, $ufields, mub.id as userfrom_blocked, $ufields2, mub2.id as userto_blocked FROM {messages} m INNER JOIN {user} u ON u.id = m.useridfrom INNER JOIN {message_conversations} mc ON mc.id = m.conversationid INNER JOIN {message_conversation_members} mcm ON mcm.conversationid = m.conversationid INNER JOIN {user} u2 ON u2.id = mcm.userid LEFT JOIN {message_users_blocked} mub ON (mub.blockeduserid = u.id AND mub.userid = ?) LEFT JOIN {message_users_blocked} mub2 ON (mub2.blockeduserid = u2.id AND mub2.userid = ?) LEFT JOIN {message_user_actions} mua ON (mua.messageid = m.id AND mua.userid = ? AND mua.action = ?) WHERE (m.useridfrom = ? OR mcm.userid = ?) AND (m.useridfrom != mcm.userid OR mc.type = ?) AND u.deleted = 0 AND u2.deleted = 0 AND mua.id is NULL AND " . $DB->sql_like('smallmessage', '?', false) . " ORDER BY timecreated DESC"; $params = array($userid, $userid, $userid, self::MESSAGE_ACTION_DELETED, $userid, $userid, self::MESSAGE_CONVERSATION_TYPE_SELF, '%' . $search . '%'); // Convert the messages into searchable contacts with their last message being the message that was searched. $conversations = array(); if ($messages = $DB->get_records_sql($sql, $params, $limitfrom, $limitnum)) { foreach ($messages as $message) { $prefix = 'userfrom_'; if ($userid == $message->useridfrom) { $prefix = 'userto_'; // If it from the user, then mark it as read, even if it wasn't by the receiver. $message->isread = true; } $blockedcol = $prefix . 'blocked'; $message->blocked = $message->$blockedcol ? 1 : 0; $message->messageid = $message->id; // To avoid duplicate messages, only add the message if it hasn't been added previously. if (!array_key_exists($message->messageid, $conversations)) { $conversations[$message->messageid] = helper::create_contact($message, $prefix); } } // Remove the messageid keys (to preserve the expected type). $conversations = array_values($conversations); } return $conversations; }
[ "public", "static", "function", "search_messages", "(", "$", "userid", ",", "$", "search", ",", "$", "limitfrom", "=", "0", ",", "$", "limitnum", "=", "0", ")", "{", "global", "$", "DB", ";", "// Get the user fields we want.", "$", "ufields", "=", "\\", "user_picture", "::", "fields", "(", "'u'", ",", "array", "(", "'lastaccess'", ")", ",", "'userfrom_id'", ",", "'userfrom_'", ")", ";", "$", "ufields2", "=", "\\", "user_picture", "::", "fields", "(", "'u2'", ",", "array", "(", "'lastaccess'", ")", ",", "'userto_id'", ",", "'userto_'", ")", ";", "// Add the uniqueid column to make each row unique and avoid SQL errors.", "$", "uniqueidsql", "=", "$", "DB", "->", "sql_concat", "(", "'m.id'", ",", "\"'_'\"", ",", "'m.useridfrom'", ",", "\"'_'\"", ",", "'mcm.userid'", ")", ";", "$", "sql", "=", "\"SELECT $uniqueidsql AS uniqueid, m.id, m.useridfrom, mcm.userid as useridto, m.subject, m.fullmessage,\n m.fullmessagehtml, m.fullmessageformat, m.smallmessage, m.conversationid, m.timecreated, 0 as isread,\n $ufields, mub.id as userfrom_blocked, $ufields2, mub2.id as userto_blocked\n FROM {messages} m\n INNER JOIN {user} u\n ON u.id = m.useridfrom\n INNER JOIN {message_conversations} mc\n ON mc.id = m.conversationid\n INNER JOIN {message_conversation_members} mcm\n ON mcm.conversationid = m.conversationid\n INNER JOIN {user} u2\n ON u2.id = mcm.userid\n LEFT JOIN {message_users_blocked} mub\n ON (mub.blockeduserid = u.id AND mub.userid = ?)\n LEFT JOIN {message_users_blocked} mub2\n ON (mub2.blockeduserid = u2.id AND mub2.userid = ?)\n LEFT JOIN {message_user_actions} mua\n ON (mua.messageid = m.id AND mua.userid = ? AND mua.action = ?)\n WHERE (m.useridfrom = ? OR mcm.userid = ?)\n AND (m.useridfrom != mcm.userid OR mc.type = ?)\n AND u.deleted = 0\n AND u2.deleted = 0\n AND mua.id is NULL\n AND \"", ".", "$", "DB", "->", "sql_like", "(", "'smallmessage'", ",", "'?'", ",", "false", ")", ".", "\"\n ORDER BY timecreated DESC\"", ";", "$", "params", "=", "array", "(", "$", "userid", ",", "$", "userid", ",", "$", "userid", ",", "self", "::", "MESSAGE_ACTION_DELETED", ",", "$", "userid", ",", "$", "userid", ",", "self", "::", "MESSAGE_CONVERSATION_TYPE_SELF", ",", "'%'", ".", "$", "search", ".", "'%'", ")", ";", "// Convert the messages into searchable contacts with their last message being the message that was searched.", "$", "conversations", "=", "array", "(", ")", ";", "if", "(", "$", "messages", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "$", "params", ",", "$", "limitfrom", ",", "$", "limitnum", ")", ")", "{", "foreach", "(", "$", "messages", "as", "$", "message", ")", "{", "$", "prefix", "=", "'userfrom_'", ";", "if", "(", "$", "userid", "==", "$", "message", "->", "useridfrom", ")", "{", "$", "prefix", "=", "'userto_'", ";", "// If it from the user, then mark it as read, even if it wasn't by the receiver.", "$", "message", "->", "isread", "=", "true", ";", "}", "$", "blockedcol", "=", "$", "prefix", ".", "'blocked'", ";", "$", "message", "->", "blocked", "=", "$", "message", "->", "$", "blockedcol", "?", "1", ":", "0", ";", "$", "message", "->", "messageid", "=", "$", "message", "->", "id", ";", "// To avoid duplicate messages, only add the message if it hasn't been added previously.", "if", "(", "!", "array_key_exists", "(", "$", "message", "->", "messageid", ",", "$", "conversations", ")", ")", "{", "$", "conversations", "[", "$", "message", "->", "messageid", "]", "=", "helper", "::", "create_contact", "(", "$", "message", ",", "$", "prefix", ")", ";", "}", "}", "// Remove the messageid keys (to preserve the expected type).", "$", "conversations", "=", "array_values", "(", "$", "conversations", ")", ";", "}", "return", "$", "conversations", ";", "}" ]
Handles searching for messages in the message area. @param int $userid The user id doing the searching @param string $search The string the user is searching @param int $limitfrom @param int $limitnum @return array
[ "Handles", "searching", "for", "messages", "in", "the", "message", "area", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L105-L167
213,331
moodle/moodle
message/classes/api.php
api.search_users_in_course
public static function search_users_in_course($userid, $courseid, $search, $limitfrom = 0, $limitnum = 0) { global $DB; // Get all the users in the course. list($esql, $params) = get_enrolled_sql(\context_course::instance($courseid), '', 0, true); $sql = "SELECT u.*, mub.id as isblocked FROM {user} u JOIN ($esql) je ON je.id = u.id LEFT JOIN {message_users_blocked} mub ON (mub.blockeduserid = u.id AND mub.userid = :userid) WHERE u.deleted = 0"; // Add more conditions. $fullname = $DB->sql_fullname(); $sql .= " AND u.id != :userid2 AND " . $DB->sql_like($fullname, ':search', false) . " ORDER BY " . $DB->sql_fullname(); $params = array_merge(array('userid' => $userid, 'userid2' => $userid, 'search' => '%' . $search . '%'), $params); // Convert all the user records into contacts. $contacts = array(); if ($users = $DB->get_records_sql($sql, $params, $limitfrom, $limitnum)) { foreach ($users as $user) { $user->blocked = $user->isblocked ? 1 : 0; $contacts[] = helper::create_contact($user); } } return $contacts; }
php
public static function search_users_in_course($userid, $courseid, $search, $limitfrom = 0, $limitnum = 0) { global $DB; // Get all the users in the course. list($esql, $params) = get_enrolled_sql(\context_course::instance($courseid), '', 0, true); $sql = "SELECT u.*, mub.id as isblocked FROM {user} u JOIN ($esql) je ON je.id = u.id LEFT JOIN {message_users_blocked} mub ON (mub.blockeduserid = u.id AND mub.userid = :userid) WHERE u.deleted = 0"; // Add more conditions. $fullname = $DB->sql_fullname(); $sql .= " AND u.id != :userid2 AND " . $DB->sql_like($fullname, ':search', false) . " ORDER BY " . $DB->sql_fullname(); $params = array_merge(array('userid' => $userid, 'userid2' => $userid, 'search' => '%' . $search . '%'), $params); // Convert all the user records into contacts. $contacts = array(); if ($users = $DB->get_records_sql($sql, $params, $limitfrom, $limitnum)) { foreach ($users as $user) { $user->blocked = $user->isblocked ? 1 : 0; $contacts[] = helper::create_contact($user); } } return $contacts; }
[ "public", "static", "function", "search_users_in_course", "(", "$", "userid", ",", "$", "courseid", ",", "$", "search", ",", "$", "limitfrom", "=", "0", ",", "$", "limitnum", "=", "0", ")", "{", "global", "$", "DB", ";", "// Get all the users in the course.", "list", "(", "$", "esql", ",", "$", "params", ")", "=", "get_enrolled_sql", "(", "\\", "context_course", "::", "instance", "(", "$", "courseid", ")", ",", "''", ",", "0", ",", "true", ")", ";", "$", "sql", "=", "\"SELECT u.*, mub.id as isblocked\n FROM {user} u\n JOIN ($esql) je\n ON je.id = u.id\n LEFT JOIN {message_users_blocked} mub\n ON (mub.blockeduserid = u.id AND mub.userid = :userid)\n WHERE u.deleted = 0\"", ";", "// Add more conditions.", "$", "fullname", "=", "$", "DB", "->", "sql_fullname", "(", ")", ";", "$", "sql", ".=", "\" AND u.id != :userid2\n AND \"", ".", "$", "DB", "->", "sql_like", "(", "$", "fullname", ",", "':search'", ",", "false", ")", ".", "\"\n ORDER BY \"", ".", "$", "DB", "->", "sql_fullname", "(", ")", ";", "$", "params", "=", "array_merge", "(", "array", "(", "'userid'", "=>", "$", "userid", ",", "'userid2'", "=>", "$", "userid", ",", "'search'", "=>", "'%'", ".", "$", "search", ".", "'%'", ")", ",", "$", "params", ")", ";", "// Convert all the user records into contacts.", "$", "contacts", "=", "array", "(", ")", ";", "if", "(", "$", "users", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "$", "params", ",", "$", "limitfrom", ",", "$", "limitnum", ")", ")", "{", "foreach", "(", "$", "users", "as", "$", "user", ")", "{", "$", "user", "->", "blocked", "=", "$", "user", "->", "isblocked", "?", "1", ":", "0", ";", "$", "contacts", "[", "]", "=", "helper", "::", "create_contact", "(", "$", "user", ")", ";", "}", "}", "return", "$", "contacts", ";", "}" ]
Handles searching for user in a particular course in the message area. TODO: This function should be removed once the related web service goes through final deprecation. The related web service is data_for_messagearea_search_users_in_course. Followup: MDL-63261 @param int $userid The user id doing the searching @param int $courseid The id of the course we are searching in @param string $search The string the user is searching @param int $limitfrom @param int $limitnum @return array
[ "Handles", "searching", "for", "user", "in", "a", "particular", "course", "in", "the", "message", "area", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L183-L212
213,332
moodle/moodle
message/classes/api.php
api.get_linked_conversation_extra_fields
protected static function get_linked_conversation_extra_fields(array $conversations) : array { global $DB, $PAGE; $renderer = $PAGE->get_renderer('core'); $linkedconversations = []; foreach ($conversations as $conversation) { if (!is_null($conversation->component) && !is_null($conversation->itemtype)) { $linkedconversations[$conversation->component][$conversation->itemtype][$conversation->id] = $conversation->itemid; } } if (empty($linkedconversations)) { return []; } // TODO: MDL-63814: Working out the subname for linked conversations should be done in a generic way. // Get the itemid, but only for course group linked conversation for now. $extrafields = []; if (!empty($linkeditems = $linkedconversations['core_group']['groups'])) { // Format: [conversationid => itemid]. // Get the name of the course to which the group belongs. list ($groupidsql, $groupidparams) = $DB->get_in_or_equal(array_values($linkeditems), SQL_PARAMS_NAMED, 'groupid'); $sql = "SELECT g.*, c.shortname as courseshortname FROM {groups} g JOIN {course} c ON g.courseid = c.id WHERE g.id $groupidsql"; $courseinfo = $DB->get_records_sql($sql, $groupidparams); foreach ($linkeditems as $convid => $groupid) { if (array_key_exists($groupid, $courseinfo)) { $group = $courseinfo[$groupid]; // Subname. $extrafields[$convid]['subname'] = format_string($courseinfo[$groupid]->courseshortname); // Imageurl. $extrafields[$convid]['imageurl'] = $renderer->image_url('g/g1')->out(false); // default image. if ($url = get_group_picture_url($group, $group->courseid, true)) { $extrafields[$convid]['imageurl'] = $url->out(false); } } } } return $extrafields; }
php
protected static function get_linked_conversation_extra_fields(array $conversations) : array { global $DB, $PAGE; $renderer = $PAGE->get_renderer('core'); $linkedconversations = []; foreach ($conversations as $conversation) { if (!is_null($conversation->component) && !is_null($conversation->itemtype)) { $linkedconversations[$conversation->component][$conversation->itemtype][$conversation->id] = $conversation->itemid; } } if (empty($linkedconversations)) { return []; } // TODO: MDL-63814: Working out the subname for linked conversations should be done in a generic way. // Get the itemid, but only for course group linked conversation for now. $extrafields = []; if (!empty($linkeditems = $linkedconversations['core_group']['groups'])) { // Format: [conversationid => itemid]. // Get the name of the course to which the group belongs. list ($groupidsql, $groupidparams) = $DB->get_in_or_equal(array_values($linkeditems), SQL_PARAMS_NAMED, 'groupid'); $sql = "SELECT g.*, c.shortname as courseshortname FROM {groups} g JOIN {course} c ON g.courseid = c.id WHERE g.id $groupidsql"; $courseinfo = $DB->get_records_sql($sql, $groupidparams); foreach ($linkeditems as $convid => $groupid) { if (array_key_exists($groupid, $courseinfo)) { $group = $courseinfo[$groupid]; // Subname. $extrafields[$convid]['subname'] = format_string($courseinfo[$groupid]->courseshortname); // Imageurl. $extrafields[$convid]['imageurl'] = $renderer->image_url('g/g1')->out(false); // default image. if ($url = get_group_picture_url($group, $group->courseid, true)) { $extrafields[$convid]['imageurl'] = $url->out(false); } } } } return $extrafields; }
[ "protected", "static", "function", "get_linked_conversation_extra_fields", "(", "array", "$", "conversations", ")", ":", "array", "{", "global", "$", "DB", ",", "$", "PAGE", ";", "$", "renderer", "=", "$", "PAGE", "->", "get_renderer", "(", "'core'", ")", ";", "$", "linkedconversations", "=", "[", "]", ";", "foreach", "(", "$", "conversations", "as", "$", "conversation", ")", "{", "if", "(", "!", "is_null", "(", "$", "conversation", "->", "component", ")", "&&", "!", "is_null", "(", "$", "conversation", "->", "itemtype", ")", ")", "{", "$", "linkedconversations", "[", "$", "conversation", "->", "component", "]", "[", "$", "conversation", "->", "itemtype", "]", "[", "$", "conversation", "->", "id", "]", "=", "$", "conversation", "->", "itemid", ";", "}", "}", "if", "(", "empty", "(", "$", "linkedconversations", ")", ")", "{", "return", "[", "]", ";", "}", "// TODO: MDL-63814: Working out the subname for linked conversations should be done in a generic way.", "// Get the itemid, but only for course group linked conversation for now.", "$", "extrafields", "=", "[", "]", ";", "if", "(", "!", "empty", "(", "$", "linkeditems", "=", "$", "linkedconversations", "[", "'core_group'", "]", "[", "'groups'", "]", ")", ")", "{", "// Format: [conversationid => itemid].", "// Get the name of the course to which the group belongs.", "list", "(", "$", "groupidsql", ",", "$", "groupidparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "array_values", "(", "$", "linkeditems", ")", ",", "SQL_PARAMS_NAMED", ",", "'groupid'", ")", ";", "$", "sql", "=", "\"SELECT g.*, c.shortname as courseshortname\n FROM {groups} g\n JOIN {course} c\n ON g.courseid = c.id\n WHERE g.id $groupidsql\"", ";", "$", "courseinfo", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "$", "groupidparams", ")", ";", "foreach", "(", "$", "linkeditems", "as", "$", "convid", "=>", "$", "groupid", ")", "{", "if", "(", "array_key_exists", "(", "$", "groupid", ",", "$", "courseinfo", ")", ")", "{", "$", "group", "=", "$", "courseinfo", "[", "$", "groupid", "]", ";", "// Subname.", "$", "extrafields", "[", "$", "convid", "]", "[", "'subname'", "]", "=", "format_string", "(", "$", "courseinfo", "[", "$", "groupid", "]", "->", "courseshortname", ")", ";", "// Imageurl.", "$", "extrafields", "[", "$", "convid", "]", "[", "'imageurl'", "]", "=", "$", "renderer", "->", "image_url", "(", "'g/g1'", ")", "->", "out", "(", "false", ")", ";", "// default image.", "if", "(", "$", "url", "=", "get_group_picture_url", "(", "$", "group", ",", "$", "group", "->", "courseid", ",", "true", ")", ")", "{", "$", "extrafields", "[", "$", "convid", "]", "[", "'imageurl'", "]", "=", "$", "url", "->", "out", "(", "false", ")", ";", "}", "}", "}", "}", "return", "$", "extrafields", ";", "}" ]
Gets extra fields, like image url and subname for any conversations linked to components. The subname is like a subtitle for the conversation, to compliment it's name. The imageurl is the location of the image for the conversation, as might be seen on a listing of conversations for a user. @param array $conversations a list of conversations records. @return array the array of subnames, index by conversation id. @throws \coding_exception @throws \dml_exception
[ "Gets", "extra", "fields", "like", "image", "url", "and", "subname", "for", "any", "conversations", "linked", "to", "components", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L448-L491
213,333
moodle/moodle
message/classes/api.php
api.get_conversations_between_users
public static function get_conversations_between_users(int $userid1, int $userid2, int $limitfrom = 0, int $limitnum = 20) : array { global $DB; if ($userid1 == $userid2) { return array(); } // Get all conversation where both user1 and user2 are members. // TODO: Add subname value. Waiting for definite table structure. $sql = "SELECT mc.id, mc.type, mc.name, mc.timecreated FROM {message_conversations} mc INNER JOIN {message_conversation_members} mcm1 ON mc.id = mcm1.conversationid INNER JOIN {message_conversation_members} mcm2 ON mc.id = mcm2.conversationid WHERE mcm1.userid = :userid1 AND mcm2.userid = :userid2 AND mc.enabled != 0 ORDER BY mc.timecreated DESC"; return $DB->get_records_sql($sql, array('userid1' => $userid1, 'userid2' => $userid2), $limitfrom, $limitnum); }
php
public static function get_conversations_between_users(int $userid1, int $userid2, int $limitfrom = 0, int $limitnum = 20) : array { global $DB; if ($userid1 == $userid2) { return array(); } // Get all conversation where both user1 and user2 are members. // TODO: Add subname value. Waiting for definite table structure. $sql = "SELECT mc.id, mc.type, mc.name, mc.timecreated FROM {message_conversations} mc INNER JOIN {message_conversation_members} mcm1 ON mc.id = mcm1.conversationid INNER JOIN {message_conversation_members} mcm2 ON mc.id = mcm2.conversationid WHERE mcm1.userid = :userid1 AND mcm2.userid = :userid2 AND mc.enabled != 0 ORDER BY mc.timecreated DESC"; return $DB->get_records_sql($sql, array('userid1' => $userid1, 'userid2' => $userid2), $limitfrom, $limitnum); }
[ "public", "static", "function", "get_conversations_between_users", "(", "int", "$", "userid1", ",", "int", "$", "userid2", ",", "int", "$", "limitfrom", "=", "0", ",", "int", "$", "limitnum", "=", "20", ")", ":", "array", "{", "global", "$", "DB", ";", "if", "(", "$", "userid1", "==", "$", "userid2", ")", "{", "return", "array", "(", ")", ";", "}", "// Get all conversation where both user1 and user2 are members.", "// TODO: Add subname value. Waiting for definite table structure.", "$", "sql", "=", "\"SELECT mc.id, mc.type, mc.name, mc.timecreated\n FROM {message_conversations} mc\n INNER JOIN {message_conversation_members} mcm1\n ON mc.id = mcm1.conversationid\n INNER JOIN {message_conversation_members} mcm2\n ON mc.id = mcm2.conversationid\n WHERE mcm1.userid = :userid1\n AND mcm2.userid = :userid2\n AND mc.enabled != 0\n ORDER BY mc.timecreated DESC\"", ";", "return", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "array", "(", "'userid1'", "=>", "$", "userid1", ",", "'userid2'", "=>", "$", "userid2", ")", ",", "$", "limitfrom", ",", "$", "limitnum", ")", ";", "}" ]
Returns all conversations between two users @param int $userid1 One of the user's id @param int $userid2 The other user's id @param int $limitfrom @param int $limitnum @return array @throws \dml_exception
[ "Returns", "all", "conversations", "between", "two", "users" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L846-L869
213,334
moodle/moodle
message/classes/api.php
api.set_favourite_conversation
public static function set_favourite_conversation(int $conversationid, int $userid) : favourite { global $DB; if (!self::is_user_in_conversation($userid, $conversationid)) { throw new \moodle_exception("Conversation doesn't exist or user is not a member"); } // Get the context for this conversation. $conversation = $DB->get_record('message_conversations', ['id' => $conversationid]); $userctx = \context_user::instance($userid); if (empty($conversation->contextid)) { // When the conversation hasn't any contextid value defined, the favourite will be added to the user context. $conversationctx = $userctx; } else { // If the contextid is defined, the favourite will be added there. $conversationctx = \context::instance_by_id($conversation->contextid); } $ufservice = \core_favourites\service_factory::get_service_for_user_context($userctx); if ($favourite = $ufservice->get_favourite('core_message', 'message_conversations', $conversationid, $conversationctx)) { return $favourite; } else { return $ufservice->create_favourite('core_message', 'message_conversations', $conversationid, $conversationctx); } }
php
public static function set_favourite_conversation(int $conversationid, int $userid) : favourite { global $DB; if (!self::is_user_in_conversation($userid, $conversationid)) { throw new \moodle_exception("Conversation doesn't exist or user is not a member"); } // Get the context for this conversation. $conversation = $DB->get_record('message_conversations', ['id' => $conversationid]); $userctx = \context_user::instance($userid); if (empty($conversation->contextid)) { // When the conversation hasn't any contextid value defined, the favourite will be added to the user context. $conversationctx = $userctx; } else { // If the contextid is defined, the favourite will be added there. $conversationctx = \context::instance_by_id($conversation->contextid); } $ufservice = \core_favourites\service_factory::get_service_for_user_context($userctx); if ($favourite = $ufservice->get_favourite('core_message', 'message_conversations', $conversationid, $conversationctx)) { return $favourite; } else { return $ufservice->create_favourite('core_message', 'message_conversations', $conversationid, $conversationctx); } }
[ "public", "static", "function", "set_favourite_conversation", "(", "int", "$", "conversationid", ",", "int", "$", "userid", ")", ":", "favourite", "{", "global", "$", "DB", ";", "if", "(", "!", "self", "::", "is_user_in_conversation", "(", "$", "userid", ",", "$", "conversationid", ")", ")", "{", "throw", "new", "\\", "moodle_exception", "(", "\"Conversation doesn't exist or user is not a member\"", ")", ";", "}", "// Get the context for this conversation.", "$", "conversation", "=", "$", "DB", "->", "get_record", "(", "'message_conversations'", ",", "[", "'id'", "=>", "$", "conversationid", "]", ")", ";", "$", "userctx", "=", "\\", "context_user", "::", "instance", "(", "$", "userid", ")", ";", "if", "(", "empty", "(", "$", "conversation", "->", "contextid", ")", ")", "{", "// When the conversation hasn't any contextid value defined, the favourite will be added to the user context.", "$", "conversationctx", "=", "$", "userctx", ";", "}", "else", "{", "// If the contextid is defined, the favourite will be added there.", "$", "conversationctx", "=", "\\", "context", "::", "instance_by_id", "(", "$", "conversation", "->", "contextid", ")", ";", "}", "$", "ufservice", "=", "\\", "core_favourites", "\\", "service_factory", "::", "get_service_for_user_context", "(", "$", "userctx", ")", ";", "if", "(", "$", "favourite", "=", "$", "ufservice", "->", "get_favourite", "(", "'core_message'", ",", "'message_conversations'", ",", "$", "conversationid", ",", "$", "conversationctx", ")", ")", "{", "return", "$", "favourite", ";", "}", "else", "{", "return", "$", "ufservice", "->", "create_favourite", "(", "'core_message'", ",", "'message_conversations'", ",", "$", "conversationid", ",", "$", "conversationctx", ")", ";", "}", "}" ]
Mark a conversation as a favourite for the given user. @param int $conversationid the id of the conversation to mark as a favourite. @param int $userid the id of the user to whom the favourite belongs. @return favourite the favourite object. @throws \moodle_exception if the user or conversation don't exist.
[ "Mark", "a", "conversation", "as", "a", "favourite", "for", "the", "given", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L1010-L1034
213,335
moodle/moodle
message/classes/api.php
api.unset_favourite_conversation
public static function unset_favourite_conversation(int $conversationid, int $userid) { global $DB; // Get the context for this conversation. $conversation = $DB->get_record('message_conversations', ['id' => $conversationid]); $userctx = \context_user::instance($userid); if (empty($conversation->contextid)) { // When the conversation hasn't any contextid value defined, the favourite will be added to the user context. $conversationctx = $userctx; } else { // If the contextid is defined, the favourite will be added there. $conversationctx = \context::instance_by_id($conversation->contextid); } $ufservice = \core_favourites\service_factory::get_service_for_user_context($userctx); $ufservice->delete_favourite('core_message', 'message_conversations', $conversationid, $conversationctx); }
php
public static function unset_favourite_conversation(int $conversationid, int $userid) { global $DB; // Get the context for this conversation. $conversation = $DB->get_record('message_conversations', ['id' => $conversationid]); $userctx = \context_user::instance($userid); if (empty($conversation->contextid)) { // When the conversation hasn't any contextid value defined, the favourite will be added to the user context. $conversationctx = $userctx; } else { // If the contextid is defined, the favourite will be added there. $conversationctx = \context::instance_by_id($conversation->contextid); } $ufservice = \core_favourites\service_factory::get_service_for_user_context($userctx); $ufservice->delete_favourite('core_message', 'message_conversations', $conversationid, $conversationctx); }
[ "public", "static", "function", "unset_favourite_conversation", "(", "int", "$", "conversationid", ",", "int", "$", "userid", ")", "{", "global", "$", "DB", ";", "// Get the context for this conversation.", "$", "conversation", "=", "$", "DB", "->", "get_record", "(", "'message_conversations'", ",", "[", "'id'", "=>", "$", "conversationid", "]", ")", ";", "$", "userctx", "=", "\\", "context_user", "::", "instance", "(", "$", "userid", ")", ";", "if", "(", "empty", "(", "$", "conversation", "->", "contextid", ")", ")", "{", "// When the conversation hasn't any contextid value defined, the favourite will be added to the user context.", "$", "conversationctx", "=", "$", "userctx", ";", "}", "else", "{", "// If the contextid is defined, the favourite will be added there.", "$", "conversationctx", "=", "\\", "context", "::", "instance_by_id", "(", "$", "conversation", "->", "contextid", ")", ";", "}", "$", "ufservice", "=", "\\", "core_favourites", "\\", "service_factory", "::", "get_service_for_user_context", "(", "$", "userctx", ")", ";", "$", "ufservice", "->", "delete_favourite", "(", "'core_message'", ",", "'message_conversations'", ",", "$", "conversationid", ",", "$", "conversationctx", ")", ";", "}" ]
Unset a conversation as a favourite for the given user. @param int $conversationid the id of the conversation to unset as a favourite. @param int $userid the id to whom the favourite belongs. @throws \moodle_exception if the favourite does not exist for the user.
[ "Unset", "a", "conversation", "as", "a", "favourite", "for", "the", "given", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L1043-L1059
213,336
moodle/moodle
message/classes/api.php
api.get_contacts
public static function get_contacts($userid, $limitfrom = 0, $limitnum = 0) { global $DB; $contactids = []; $sql = "SELECT mc.* FROM {message_contacts} mc WHERE mc.userid = ? OR mc.contactid = ? ORDER BY timecreated DESC"; if ($contacts = $DB->get_records_sql($sql, [$userid, $userid], $limitfrom, $limitnum)) { foreach ($contacts as $contact) { if ($userid == $contact->userid) { $contactids[] = $contact->contactid; } else { $contactids[] = $contact->userid; } } } if (!empty($contactids)) { list($insql, $inparams) = $DB->get_in_or_equal($contactids); $sql = "SELECT u.*, mub.id as isblocked FROM {user} u LEFT JOIN {message_users_blocked} mub ON u.id = mub.blockeduserid WHERE u.id $insql"; if ($contacts = $DB->get_records_sql($sql, $inparams)) { $arrcontacts = []; foreach ($contacts as $contact) { $contact->blocked = $contact->isblocked ? 1 : 0; $arrcontacts[] = helper::create_contact($contact); } return $arrcontacts; } } return []; }
php
public static function get_contacts($userid, $limitfrom = 0, $limitnum = 0) { global $DB; $contactids = []; $sql = "SELECT mc.* FROM {message_contacts} mc WHERE mc.userid = ? OR mc.contactid = ? ORDER BY timecreated DESC"; if ($contacts = $DB->get_records_sql($sql, [$userid, $userid], $limitfrom, $limitnum)) { foreach ($contacts as $contact) { if ($userid == $contact->userid) { $contactids[] = $contact->contactid; } else { $contactids[] = $contact->userid; } } } if (!empty($contactids)) { list($insql, $inparams) = $DB->get_in_or_equal($contactids); $sql = "SELECT u.*, mub.id as isblocked FROM {user} u LEFT JOIN {message_users_blocked} mub ON u.id = mub.blockeduserid WHERE u.id $insql"; if ($contacts = $DB->get_records_sql($sql, $inparams)) { $arrcontacts = []; foreach ($contacts as $contact) { $contact->blocked = $contact->isblocked ? 1 : 0; $arrcontacts[] = helper::create_contact($contact); } return $arrcontacts; } } return []; }
[ "public", "static", "function", "get_contacts", "(", "$", "userid", ",", "$", "limitfrom", "=", "0", ",", "$", "limitnum", "=", "0", ")", "{", "global", "$", "DB", ";", "$", "contactids", "=", "[", "]", ";", "$", "sql", "=", "\"SELECT mc.*\n FROM {message_contacts} mc\n WHERE mc.userid = ? OR mc.contactid = ?\n ORDER BY timecreated DESC\"", ";", "if", "(", "$", "contacts", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "[", "$", "userid", ",", "$", "userid", "]", ",", "$", "limitfrom", ",", "$", "limitnum", ")", ")", "{", "foreach", "(", "$", "contacts", "as", "$", "contact", ")", "{", "if", "(", "$", "userid", "==", "$", "contact", "->", "userid", ")", "{", "$", "contactids", "[", "]", "=", "$", "contact", "->", "contactid", ";", "}", "else", "{", "$", "contactids", "[", "]", "=", "$", "contact", "->", "userid", ";", "}", "}", "}", "if", "(", "!", "empty", "(", "$", "contactids", ")", ")", "{", "list", "(", "$", "insql", ",", "$", "inparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "contactids", ")", ";", "$", "sql", "=", "\"SELECT u.*, mub.id as isblocked\n FROM {user} u\n LEFT JOIN {message_users_blocked} mub\n ON u.id = mub.blockeduserid\n WHERE u.id $insql\"", ";", "if", "(", "$", "contacts", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "$", "inparams", ")", ")", "{", "$", "arrcontacts", "=", "[", "]", ";", "foreach", "(", "$", "contacts", "as", "$", "contact", ")", "{", "$", "contact", "->", "blocked", "=", "$", "contact", "->", "isblocked", "?", "1", ":", "0", ";", "$", "arrcontacts", "[", "]", "=", "helper", "::", "create_contact", "(", "$", "contact", ")", ";", "}", "return", "$", "arrcontacts", ";", "}", "}", "return", "[", "]", ";", "}" ]
Returns the contacts to display in the contacts area. TODO: This function should be removed once the related web service goes through final deprecation. The related web service is data_for_messagearea_contacts. Followup: MDL-63261 @param int $userid The user id @param int $limitfrom @param int $limitnum @return array
[ "Returns", "the", "contacts", "to", "display", "in", "the", "contacts", "area", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L1073-L1111
213,337
moodle/moodle
message/classes/api.php
api.get_user_contacts
public static function get_user_contacts(int $userid, int $limitfrom = 0, int $limitnum = 0) { global $DB; $sql = "SELECT * FROM {message_contacts} mc WHERE mc.userid = ? OR mc.contactid = ? ORDER BY timecreated DESC, id ASC"; if ($contacts = $DB->get_records_sql($sql, [$userid, $userid], $limitfrom, $limitnum)) { $userids = []; foreach ($contacts as $contact) { if ($contact->userid == $userid) { $userids[] = $contact->contactid; } else { $userids[] = $contact->userid; } } return helper::get_member_info($userid, $userids); } return []; }
php
public static function get_user_contacts(int $userid, int $limitfrom = 0, int $limitnum = 0) { global $DB; $sql = "SELECT * FROM {message_contacts} mc WHERE mc.userid = ? OR mc.contactid = ? ORDER BY timecreated DESC, id ASC"; if ($contacts = $DB->get_records_sql($sql, [$userid, $userid], $limitfrom, $limitnum)) { $userids = []; foreach ($contacts as $contact) { if ($contact->userid == $userid) { $userids[] = $contact->contactid; } else { $userids[] = $contact->userid; } } return helper::get_member_info($userid, $userids); } return []; }
[ "public", "static", "function", "get_user_contacts", "(", "int", "$", "userid", ",", "int", "$", "limitfrom", "=", "0", ",", "int", "$", "limitnum", "=", "0", ")", "{", "global", "$", "DB", ";", "$", "sql", "=", "\"SELECT *\n FROM {message_contacts} mc\n WHERE mc.userid = ? OR mc.contactid = ?\n ORDER BY timecreated DESC, id ASC\"", ";", "if", "(", "$", "contacts", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "[", "$", "userid", ",", "$", "userid", "]", ",", "$", "limitfrom", ",", "$", "limitnum", ")", ")", "{", "$", "userids", "=", "[", "]", ";", "foreach", "(", "$", "contacts", "as", "$", "contact", ")", "{", "if", "(", "$", "contact", "->", "userid", "==", "$", "userid", ")", "{", "$", "userids", "[", "]", "=", "$", "contact", "->", "contactid", ";", "}", "else", "{", "$", "userids", "[", "]", "=", "$", "contact", "->", "userid", ";", "}", "}", "return", "helper", "::", "get_member_info", "(", "$", "userid", ",", "$", "userids", ")", ";", "}", "return", "[", "]", ";", "}" ]
Get the contacts for a given user. @param int $userid @param int $limitfrom @param int $limitnum @return array An array of contacts
[ "Get", "the", "contacts", "for", "a", "given", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L1121-L1141
213,338
moodle/moodle
message/classes/api.php
api.count_contacts
public static function count_contacts(int $userid) : int { global $DB; $sql = "SELECT COUNT(id) FROM {message_contacts} WHERE userid = ? OR contactid = ?"; return $DB->count_records_sql($sql, [$userid, $userid]); }
php
public static function count_contacts(int $userid) : int { global $DB; $sql = "SELECT COUNT(id) FROM {message_contacts} WHERE userid = ? OR contactid = ?"; return $DB->count_records_sql($sql, [$userid, $userid]); }
[ "public", "static", "function", "count_contacts", "(", "int", "$", "userid", ")", ":", "int", "{", "global", "$", "DB", ";", "$", "sql", "=", "\"SELECT COUNT(id)\n FROM {message_contacts}\n WHERE userid = ? OR contactid = ?\"", ";", "return", "$", "DB", "->", "count_records_sql", "(", "$", "sql", ",", "[", "$", "userid", ",", "$", "userid", "]", ")", ";", "}" ]
Returns the contacts count. @param int $userid The user id @return array
[ "Returns", "the", "contacts", "count", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L1149-L1156
213,339
moodle/moodle
message/classes/api.php
api.get_non_contacts_with_unread_message_count
public static function get_non_contacts_with_unread_message_count($userid, $limitfrom = 0, $limitnum = 0) { global $DB; $userfields = \user_picture::fields('u', array('lastaccess')); $unreadcountssql = "SELECT $userfields, count(m.id) as messagecount FROM {user} u INNER JOIN {messages} m ON m.useridfrom = u.id INNER JOIN {message_conversation_members} mcm ON mcm.conversationid = m.conversationid LEFT JOIN {message_user_actions} mua ON (mua.messageid = m.id AND mua.userid = ? AND mua.action = ?) LEFT JOIN {message_contacts} mc ON (mc.userid = ? AND mc.contactid = u.id) LEFT JOIN {message_users_blocked} mub ON (mub.userid = ? AND mub.blockeduserid = u.id) WHERE mcm.userid = ? AND mcm.userid != m.useridfrom AND mua.id is NULL AND mub.id is NULL AND mc.id is NULL AND u.deleted = 0 GROUP BY $userfields"; return $DB->get_records_sql($unreadcountssql, [$userid, self::MESSAGE_ACTION_READ, $userid, $userid, $userid], $limitfrom, $limitnum); }
php
public static function get_non_contacts_with_unread_message_count($userid, $limitfrom = 0, $limitnum = 0) { global $DB; $userfields = \user_picture::fields('u', array('lastaccess')); $unreadcountssql = "SELECT $userfields, count(m.id) as messagecount FROM {user} u INNER JOIN {messages} m ON m.useridfrom = u.id INNER JOIN {message_conversation_members} mcm ON mcm.conversationid = m.conversationid LEFT JOIN {message_user_actions} mua ON (mua.messageid = m.id AND mua.userid = ? AND mua.action = ?) LEFT JOIN {message_contacts} mc ON (mc.userid = ? AND mc.contactid = u.id) LEFT JOIN {message_users_blocked} mub ON (mub.userid = ? AND mub.blockeduserid = u.id) WHERE mcm.userid = ? AND mcm.userid != m.useridfrom AND mua.id is NULL AND mub.id is NULL AND mc.id is NULL AND u.deleted = 0 GROUP BY $userfields"; return $DB->get_records_sql($unreadcountssql, [$userid, self::MESSAGE_ACTION_READ, $userid, $userid, $userid], $limitfrom, $limitnum); }
[ "public", "static", "function", "get_non_contacts_with_unread_message_count", "(", "$", "userid", ",", "$", "limitfrom", "=", "0", ",", "$", "limitnum", "=", "0", ")", "{", "global", "$", "DB", ";", "$", "userfields", "=", "\\", "user_picture", "::", "fields", "(", "'u'", ",", "array", "(", "'lastaccess'", ")", ")", ";", "$", "unreadcountssql", "=", "\"SELECT $userfields, count(m.id) as messagecount\n FROM {user} u\n INNER JOIN {messages} m\n ON m.useridfrom = u.id\n INNER JOIN {message_conversation_members} mcm\n ON mcm.conversationid = m.conversationid\n LEFT JOIN {message_user_actions} mua\n ON (mua.messageid = m.id AND mua.userid = ? AND mua.action = ?)\n LEFT JOIN {message_contacts} mc\n ON (mc.userid = ? AND mc.contactid = u.id)\n LEFT JOIN {message_users_blocked} mub\n ON (mub.userid = ? AND mub.blockeduserid = u.id)\n WHERE mcm.userid = ?\n AND mcm.userid != m.useridfrom\n AND mua.id is NULL\n AND mub.id is NULL\n AND mc.id is NULL\n AND u.deleted = 0\n GROUP BY $userfields\"", ";", "return", "$", "DB", "->", "get_records_sql", "(", "$", "unreadcountssql", ",", "[", "$", "userid", ",", "self", "::", "MESSAGE_ACTION_READ", ",", "$", "userid", ",", "$", "userid", ",", "$", "userid", "]", ",", "$", "limitfrom", ",", "$", "limitnum", ")", ";", "}" ]
Returns the an array of the users the given user is in a conversation with who are not a contact and the number of unread messages. @param int $userid The user id @param int $limitfrom @param int $limitnum @return array
[ "Returns", "the", "an", "array", "of", "the", "users", "the", "given", "user", "is", "in", "a", "conversation", "with", "who", "are", "not", "a", "contact", "and", "the", "number", "of", "unread", "messages", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L1203-L1229
213,340
moodle/moodle
message/classes/api.php
api.get_messages
public static function get_messages($userid, $otheruserid, $limitfrom = 0, $limitnum = 0, $sort = 'timecreated ASC', $timefrom = 0, $timeto = 0) { if (!empty($timefrom)) { // Get the conversation between userid and otheruserid. $userids = [$userid, $otheruserid]; if (!$conversationid = self::get_conversation_between_users($userids)) { // This method was always used for individual conversations. $conversation = self::create_conversation(self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL, $userids); $conversationid = $conversation->id; } // Check the cache to see if we even need to do a DB query. $cache = \cache::make('core', 'message_time_last_message_between_users'); $key = helper::get_last_message_time_created_cache_key($conversationid); $lastcreated = $cache->get($key); // The last known message time is earlier than the one being requested so we can // just return an empty result set rather than having to query the DB. if ($lastcreated && $lastcreated < $timefrom) { return []; } } $arrmessages = array(); if ($messages = helper::get_messages($userid, $otheruserid, 0, $limitfrom, $limitnum, $sort, $timefrom, $timeto)) { $arrmessages = helper::create_messages($userid, $messages); } return $arrmessages; }
php
public static function get_messages($userid, $otheruserid, $limitfrom = 0, $limitnum = 0, $sort = 'timecreated ASC', $timefrom = 0, $timeto = 0) { if (!empty($timefrom)) { // Get the conversation between userid and otheruserid. $userids = [$userid, $otheruserid]; if (!$conversationid = self::get_conversation_between_users($userids)) { // This method was always used for individual conversations. $conversation = self::create_conversation(self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL, $userids); $conversationid = $conversation->id; } // Check the cache to see if we even need to do a DB query. $cache = \cache::make('core', 'message_time_last_message_between_users'); $key = helper::get_last_message_time_created_cache_key($conversationid); $lastcreated = $cache->get($key); // The last known message time is earlier than the one being requested so we can // just return an empty result set rather than having to query the DB. if ($lastcreated && $lastcreated < $timefrom) { return []; } } $arrmessages = array(); if ($messages = helper::get_messages($userid, $otheruserid, 0, $limitfrom, $limitnum, $sort, $timefrom, $timeto)) { $arrmessages = helper::create_messages($userid, $messages); } return $arrmessages; }
[ "public", "static", "function", "get_messages", "(", "$", "userid", ",", "$", "otheruserid", ",", "$", "limitfrom", "=", "0", ",", "$", "limitnum", "=", "0", ",", "$", "sort", "=", "'timecreated ASC'", ",", "$", "timefrom", "=", "0", ",", "$", "timeto", "=", "0", ")", "{", "if", "(", "!", "empty", "(", "$", "timefrom", ")", ")", "{", "// Get the conversation between userid and otheruserid.", "$", "userids", "=", "[", "$", "userid", ",", "$", "otheruserid", "]", ";", "if", "(", "!", "$", "conversationid", "=", "self", "::", "get_conversation_between_users", "(", "$", "userids", ")", ")", "{", "// This method was always used for individual conversations.", "$", "conversation", "=", "self", "::", "create_conversation", "(", "self", "::", "MESSAGE_CONVERSATION_TYPE_INDIVIDUAL", ",", "$", "userids", ")", ";", "$", "conversationid", "=", "$", "conversation", "->", "id", ";", "}", "// Check the cache to see if we even need to do a DB query.", "$", "cache", "=", "\\", "cache", "::", "make", "(", "'core'", ",", "'message_time_last_message_between_users'", ")", ";", "$", "key", "=", "helper", "::", "get_last_message_time_created_cache_key", "(", "$", "conversationid", ")", ";", "$", "lastcreated", "=", "$", "cache", "->", "get", "(", "$", "key", ")", ";", "// The last known message time is earlier than the one being requested so we can", "// just return an empty result set rather than having to query the DB.", "if", "(", "$", "lastcreated", "&&", "$", "lastcreated", "<", "$", "timefrom", ")", "{", "return", "[", "]", ";", "}", "}", "$", "arrmessages", "=", "array", "(", ")", ";", "if", "(", "$", "messages", "=", "helper", "::", "get_messages", "(", "$", "userid", ",", "$", "otheruserid", ",", "0", ",", "$", "limitfrom", ",", "$", "limitnum", ",", "$", "sort", ",", "$", "timefrom", ",", "$", "timeto", ")", ")", "{", "$", "arrmessages", "=", "helper", "::", "create_messages", "(", "$", "userid", ",", "$", "messages", ")", ";", "}", "return", "$", "arrmessages", ";", "}" ]
Returns the messages to display in the message area. TODO: This function should be removed once the related web service goes through final deprecation. The related web service is data_for_messagearea_messages. Followup: MDL-63261 @param int $userid the current user @param int $otheruserid the other user @param int $limitfrom @param int $limitnum @param string $sort @param int $timefrom the time from the message being sent @param int $timeto the time up until the message being sent @return array
[ "Returns", "the", "messages", "to", "display", "in", "the", "message", "area", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L1247-L1278
213,341
moodle/moodle
message/classes/api.php
api.get_conversation_messages
public static function get_conversation_messages(int $userid, int $convid, int $limitfrom = 0, int $limitnum = 0, string $sort = 'timecreated ASC', int $timefrom = 0, int $timeto = 0) : array { if (!empty($timefrom)) { // Check the cache to see if we even need to do a DB query. $cache = \cache::make('core', 'message_time_last_message_between_users'); $key = helper::get_last_message_time_created_cache_key($convid); $lastcreated = $cache->get($key); // The last known message time is earlier than the one being requested so we can // just return an empty result set rather than having to query the DB. if ($lastcreated && $lastcreated < $timefrom) { return []; } } $messages = helper::get_conversation_messages($userid, $convid, 0, $limitfrom, $limitnum, $sort, $timefrom, $timeto); return helper::format_conversation_messages($userid, $convid, $messages); }
php
public static function get_conversation_messages(int $userid, int $convid, int $limitfrom = 0, int $limitnum = 0, string $sort = 'timecreated ASC', int $timefrom = 0, int $timeto = 0) : array { if (!empty($timefrom)) { // Check the cache to see if we even need to do a DB query. $cache = \cache::make('core', 'message_time_last_message_between_users'); $key = helper::get_last_message_time_created_cache_key($convid); $lastcreated = $cache->get($key); // The last known message time is earlier than the one being requested so we can // just return an empty result set rather than having to query the DB. if ($lastcreated && $lastcreated < $timefrom) { return []; } } $messages = helper::get_conversation_messages($userid, $convid, 0, $limitfrom, $limitnum, $sort, $timefrom, $timeto); return helper::format_conversation_messages($userid, $convid, $messages); }
[ "public", "static", "function", "get_conversation_messages", "(", "int", "$", "userid", ",", "int", "$", "convid", ",", "int", "$", "limitfrom", "=", "0", ",", "int", "$", "limitnum", "=", "0", ",", "string", "$", "sort", "=", "'timecreated ASC'", ",", "int", "$", "timefrom", "=", "0", ",", "int", "$", "timeto", "=", "0", ")", ":", "array", "{", "if", "(", "!", "empty", "(", "$", "timefrom", ")", ")", "{", "// Check the cache to see if we even need to do a DB query.", "$", "cache", "=", "\\", "cache", "::", "make", "(", "'core'", ",", "'message_time_last_message_between_users'", ")", ";", "$", "key", "=", "helper", "::", "get_last_message_time_created_cache_key", "(", "$", "convid", ")", ";", "$", "lastcreated", "=", "$", "cache", "->", "get", "(", "$", "key", ")", ";", "// The last known message time is earlier than the one being requested so we can", "// just return an empty result set rather than having to query the DB.", "if", "(", "$", "lastcreated", "&&", "$", "lastcreated", "<", "$", "timefrom", ")", "{", "return", "[", "]", ";", "}", "}", "$", "messages", "=", "helper", "::", "get_conversation_messages", "(", "$", "userid", ",", "$", "convid", ",", "0", ",", "$", "limitfrom", ",", "$", "limitnum", ",", "$", "sort", ",", "$", "timefrom", ",", "$", "timeto", ")", ";", "return", "helper", "::", "format_conversation_messages", "(", "$", "userid", ",", "$", "convid", ",", "$", "messages", ")", ";", "}" ]
Returns the messages for the defined conversation. @param int $userid The current user. @param int $convid The conversation where the messages belong. Could be an object or just the 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 string $sort The column name to order by including optionally direction. @param int $timefrom The time from the message being sent. @param int $timeto The time up until the message being sent. @return array of messages
[ "Returns", "the", "messages", "for", "the", "defined", "conversation", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L1292-L1310
213,342
moodle/moodle
message/classes/api.php
api.get_most_recent_message
public static function get_most_recent_message($userid, $otheruserid) { // We want two messages here so we get an accurate 'blocktime' value. if ($messages = helper::get_messages($userid, $otheruserid, 0, 0, 2, 'timecreated DESC')) { // Swap the order so we now have them in historical order. $messages = array_reverse($messages); $arrmessages = helper::create_messages($userid, $messages); return array_pop($arrmessages); } return null; }
php
public static function get_most_recent_message($userid, $otheruserid) { // We want two messages here so we get an accurate 'blocktime' value. if ($messages = helper::get_messages($userid, $otheruserid, 0, 0, 2, 'timecreated DESC')) { // Swap the order so we now have them in historical order. $messages = array_reverse($messages); $arrmessages = helper::create_messages($userid, $messages); return array_pop($arrmessages); } return null; }
[ "public", "static", "function", "get_most_recent_message", "(", "$", "userid", ",", "$", "otheruserid", ")", "{", "// We want two messages here so we get an accurate 'blocktime' value.", "if", "(", "$", "messages", "=", "helper", "::", "get_messages", "(", "$", "userid", ",", "$", "otheruserid", ",", "0", ",", "0", ",", "2", ",", "'timecreated DESC'", ")", ")", "{", "// Swap the order so we now have them in historical order.", "$", "messages", "=", "array_reverse", "(", "$", "messages", ")", ";", "$", "arrmessages", "=", "helper", "::", "create_messages", "(", "$", "userid", ",", "$", "messages", ")", ";", "return", "array_pop", "(", "$", "arrmessages", ")", ";", "}", "return", "null", ";", "}" ]
Returns the most recent message between two users. TODO: This function should be removed once the related web service goes through final deprecation. The related web service is data_for_messagearea_get_most_recent_message. Followup: MDL-63261 @param int $userid the current user @param int $otheruserid the other user @return \stdClass|null
[ "Returns", "the", "most", "recent", "message", "between", "two", "users", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L1323-L1333
213,343
moodle/moodle
message/classes/api.php
api.get_most_recent_conversation_message
public static function get_most_recent_conversation_message(int $convid, int $currentuserid = 0) { global $USER; if (empty($currentuserid)) { $currentuserid = $USER->id; } if ($messages = helper::get_conversation_messages($currentuserid, $convid, 0, 0, 1, 'timecreated DESC')) { $convmessages = helper::format_conversation_messages($currentuserid, $convid, $messages); return array_pop($convmessages['messages']); } return null; }
php
public static function get_most_recent_conversation_message(int $convid, int $currentuserid = 0) { global $USER; if (empty($currentuserid)) { $currentuserid = $USER->id; } if ($messages = helper::get_conversation_messages($currentuserid, $convid, 0, 0, 1, 'timecreated DESC')) { $convmessages = helper::format_conversation_messages($currentuserid, $convid, $messages); return array_pop($convmessages['messages']); } return null; }
[ "public", "static", "function", "get_most_recent_conversation_message", "(", "int", "$", "convid", ",", "int", "$", "currentuserid", "=", "0", ")", "{", "global", "$", "USER", ";", "if", "(", "empty", "(", "$", "currentuserid", ")", ")", "{", "$", "currentuserid", "=", "$", "USER", "->", "id", ";", "}", "if", "(", "$", "messages", "=", "helper", "::", "get_conversation_messages", "(", "$", "currentuserid", ",", "$", "convid", ",", "0", ",", "0", ",", "1", ",", "'timecreated DESC'", ")", ")", "{", "$", "convmessages", "=", "helper", "::", "format_conversation_messages", "(", "$", "currentuserid", ",", "$", "convid", ",", "$", "messages", ")", ";", "return", "array_pop", "(", "$", "convmessages", "[", "'messages'", "]", ")", ";", "}", "return", "null", ";", "}" ]
Returns the most recent message in a conversation. @param int $convid The conversation identifier. @param int $currentuserid The current user identifier. @return \stdClass|null The most recent message.
[ "Returns", "the", "most", "recent", "message", "in", "a", "conversation", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L1342-L1355
213,344
moodle/moodle
message/classes/api.php
api.get_profile
public static function get_profile($userid, $otheruserid) { global $CFG, $PAGE; require_once($CFG->dirroot . '/user/lib.php'); $user = \core_user::get_user($otheruserid, '*', MUST_EXIST); // Create the data we are going to pass to the renderable. $data = new \stdClass(); $data->userid = $otheruserid; $data->fullname = fullname($user); $data->city = ''; $data->country = ''; $data->email = ''; $data->isonline = null; // Get the user picture data - messaging has always shown these to the user. $userpicture = new \user_picture($user); $userpicture->size = 1; // Size f1. $data->profileimageurl = $userpicture->get_url($PAGE)->out(false); $userpicture->size = 0; // Size f2. $data->profileimageurlsmall = $userpicture->get_url($PAGE)->out(false); $userfields = user_get_user_details($user, null, array('city', 'country', 'email', 'lastaccess')); if ($userfields) { if (isset($userfields['city'])) { $data->city = $userfields['city']; } if (isset($userfields['country'])) { $data->country = $userfields['country']; } if (isset($userfields['email'])) { $data->email = $userfields['email']; } if (isset($userfields['lastaccess'])) { $data->isonline = helper::is_online($userfields['lastaccess']); } } $data->isblocked = self::is_blocked($userid, $otheruserid); $data->iscontact = self::is_contact($userid, $otheruserid); return $data; }
php
public static function get_profile($userid, $otheruserid) { global $CFG, $PAGE; require_once($CFG->dirroot . '/user/lib.php'); $user = \core_user::get_user($otheruserid, '*', MUST_EXIST); // Create the data we are going to pass to the renderable. $data = new \stdClass(); $data->userid = $otheruserid; $data->fullname = fullname($user); $data->city = ''; $data->country = ''; $data->email = ''; $data->isonline = null; // Get the user picture data - messaging has always shown these to the user. $userpicture = new \user_picture($user); $userpicture->size = 1; // Size f1. $data->profileimageurl = $userpicture->get_url($PAGE)->out(false); $userpicture->size = 0; // Size f2. $data->profileimageurlsmall = $userpicture->get_url($PAGE)->out(false); $userfields = user_get_user_details($user, null, array('city', 'country', 'email', 'lastaccess')); if ($userfields) { if (isset($userfields['city'])) { $data->city = $userfields['city']; } if (isset($userfields['country'])) { $data->country = $userfields['country']; } if (isset($userfields['email'])) { $data->email = $userfields['email']; } if (isset($userfields['lastaccess'])) { $data->isonline = helper::is_online($userfields['lastaccess']); } } $data->isblocked = self::is_blocked($userid, $otheruserid); $data->iscontact = self::is_contact($userid, $otheruserid); return $data; }
[ "public", "static", "function", "get_profile", "(", "$", "userid", ",", "$", "otheruserid", ")", "{", "global", "$", "CFG", ",", "$", "PAGE", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/user/lib.php'", ")", ";", "$", "user", "=", "\\", "core_user", "::", "get_user", "(", "$", "otheruserid", ",", "'*'", ",", "MUST_EXIST", ")", ";", "// Create the data we are going to pass to the renderable.", "$", "data", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "data", "->", "userid", "=", "$", "otheruserid", ";", "$", "data", "->", "fullname", "=", "fullname", "(", "$", "user", ")", ";", "$", "data", "->", "city", "=", "''", ";", "$", "data", "->", "country", "=", "''", ";", "$", "data", "->", "email", "=", "''", ";", "$", "data", "->", "isonline", "=", "null", ";", "// Get the user picture data - messaging has always shown these to the user.", "$", "userpicture", "=", "new", "\\", "user_picture", "(", "$", "user", ")", ";", "$", "userpicture", "->", "size", "=", "1", ";", "// Size f1.", "$", "data", "->", "profileimageurl", "=", "$", "userpicture", "->", "get_url", "(", "$", "PAGE", ")", "->", "out", "(", "false", ")", ";", "$", "userpicture", "->", "size", "=", "0", ";", "// Size f2.", "$", "data", "->", "profileimageurlsmall", "=", "$", "userpicture", "->", "get_url", "(", "$", "PAGE", ")", "->", "out", "(", "false", ")", ";", "$", "userfields", "=", "user_get_user_details", "(", "$", "user", ",", "null", ",", "array", "(", "'city'", ",", "'country'", ",", "'email'", ",", "'lastaccess'", ")", ")", ";", "if", "(", "$", "userfields", ")", "{", "if", "(", "isset", "(", "$", "userfields", "[", "'city'", "]", ")", ")", "{", "$", "data", "->", "city", "=", "$", "userfields", "[", "'city'", "]", ";", "}", "if", "(", "isset", "(", "$", "userfields", "[", "'country'", "]", ")", ")", "{", "$", "data", "->", "country", "=", "$", "userfields", "[", "'country'", "]", ";", "}", "if", "(", "isset", "(", "$", "userfields", "[", "'email'", "]", ")", ")", "{", "$", "data", "->", "email", "=", "$", "userfields", "[", "'email'", "]", ";", "}", "if", "(", "isset", "(", "$", "userfields", "[", "'lastaccess'", "]", ")", ")", "{", "$", "data", "->", "isonline", "=", "helper", "::", "is_online", "(", "$", "userfields", "[", "'lastaccess'", "]", ")", ";", "}", "}", "$", "data", "->", "isblocked", "=", "self", "::", "is_blocked", "(", "$", "userid", ",", "$", "otheruserid", ")", ";", "$", "data", "->", "iscontact", "=", "self", "::", "is_contact", "(", "$", "userid", ",", "$", "otheruserid", ")", ";", "return", "$", "data", ";", "}" ]
Returns the profile information for a contact for a user. TODO: This function should be removed once the related web service goes through final deprecation. The related web service is data_for_messagearea_get_profile. Followup: MDL-63261 @param int $userid The user id @param int $otheruserid The id of the user whose profile we want to view. @return \stdClass
[ "Returns", "the", "profile", "information", "for", "a", "contact", "for", "a", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L1368-L1410
213,345
moodle/moodle
message/classes/api.php
api.can_delete_conversation
public static function can_delete_conversation(int $userid, int $conversationid = null) : bool { global $USER; if (is_null($conversationid)) { debugging('\core_message\api::can_delete_conversation() now expects a \'conversationid\' to be passed.', DEBUG_DEVELOPER); return false; } $systemcontext = \context_system::instance(); if (has_capability('moodle/site:deleteanymessage', $systemcontext)) { return true; } if (!self::is_user_in_conversation($userid, $conversationid)) { return false; } if (has_capability('moodle/site:deleteownmessage', $systemcontext) && $USER->id == $userid) { return true; } return false; }
php
public static function can_delete_conversation(int $userid, int $conversationid = null) : bool { global $USER; if (is_null($conversationid)) { debugging('\core_message\api::can_delete_conversation() now expects a \'conversationid\' to be passed.', DEBUG_DEVELOPER); return false; } $systemcontext = \context_system::instance(); if (has_capability('moodle/site:deleteanymessage', $systemcontext)) { return true; } if (!self::is_user_in_conversation($userid, $conversationid)) { return false; } if (has_capability('moodle/site:deleteownmessage', $systemcontext) && $USER->id == $userid) { return true; } return false; }
[ "public", "static", "function", "can_delete_conversation", "(", "int", "$", "userid", ",", "int", "$", "conversationid", "=", "null", ")", ":", "bool", "{", "global", "$", "USER", ";", "if", "(", "is_null", "(", "$", "conversationid", ")", ")", "{", "debugging", "(", "'\\core_message\\api::can_delete_conversation() now expects a \\'conversationid\\' to be passed.'", ",", "DEBUG_DEVELOPER", ")", ";", "return", "false", ";", "}", "$", "systemcontext", "=", "\\", "context_system", "::", "instance", "(", ")", ";", "if", "(", "has_capability", "(", "'moodle/site:deleteanymessage'", ",", "$", "systemcontext", ")", ")", "{", "return", "true", ";", "}", "if", "(", "!", "self", "::", "is_user_in_conversation", "(", "$", "userid", ",", "$", "conversationid", ")", ")", "{", "return", "false", ";", "}", "if", "(", "has_capability", "(", "'moodle/site:deleteownmessage'", ",", "$", "systemcontext", ")", "&&", "$", "USER", "->", "id", "==", "$", "userid", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Checks if a user can delete messages they have either received or sent. @param int $userid The user id of who we want to delete the messages for (this may be done by the admin but will still seem as if it was by the user) @param int $conversationid The id of the conversation @return bool Returns true if a user can delete the conversation, false otherwise.
[ "Checks", "if", "a", "user", "can", "delete", "messages", "they", "have", "either", "received", "or", "sent", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L1420-L1445
213,346
moodle/moodle
message/classes/api.php
api.delete_conversation_by_id
public static function delete_conversation_by_id(int $userid, int $conversationid) { global $DB, $USER; // Get all messages belonging to this conversation that have not already been deleted by this user. $sql = "SELECT m.* FROM {messages} m INNER JOIN {message_conversations} mc ON m.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 mc.id = ? ORDER BY m.timecreated ASC"; $messages = $DB->get_records_sql($sql, [$userid, self::MESSAGE_ACTION_DELETED, $conversationid]); // Ok, mark these as deleted. foreach ($messages as $message) { $mua = new \stdClass(); $mua->userid = $userid; $mua->messageid = $message->id; $mua->action = self::MESSAGE_ACTION_DELETED; $mua->timecreated = time(); $mua->id = $DB->insert_record('message_user_actions', $mua); \core\event\message_deleted::create_from_ids($userid, $USER->id, $message->id, $mua->id)->trigger(); } }
php
public static function delete_conversation_by_id(int $userid, int $conversationid) { global $DB, $USER; // Get all messages belonging to this conversation that have not already been deleted by this user. $sql = "SELECT m.* FROM {messages} m INNER JOIN {message_conversations} mc ON m.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 mc.id = ? ORDER BY m.timecreated ASC"; $messages = $DB->get_records_sql($sql, [$userid, self::MESSAGE_ACTION_DELETED, $conversationid]); // Ok, mark these as deleted. foreach ($messages as $message) { $mua = new \stdClass(); $mua->userid = $userid; $mua->messageid = $message->id; $mua->action = self::MESSAGE_ACTION_DELETED; $mua->timecreated = time(); $mua->id = $DB->insert_record('message_user_actions', $mua); \core\event\message_deleted::create_from_ids($userid, $USER->id, $message->id, $mua->id)->trigger(); } }
[ "public", "static", "function", "delete_conversation_by_id", "(", "int", "$", "userid", ",", "int", "$", "conversationid", ")", "{", "global", "$", "DB", ",", "$", "USER", ";", "// Get all messages belonging to this conversation that have not already been deleted by this user.", "$", "sql", "=", "\"SELECT m.*\n FROM {messages} m\n INNER JOIN {message_conversations} mc\n ON m.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 mc.id = ?\n ORDER BY m.timecreated ASC\"", ";", "$", "messages", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "[", "$", "userid", ",", "self", "::", "MESSAGE_ACTION_DELETED", ",", "$", "conversationid", "]", ")", ";", "// Ok, mark these as deleted.", "foreach", "(", "$", "messages", "as", "$", "message", ")", "{", "$", "mua", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "mua", "->", "userid", "=", "$", "userid", ";", "$", "mua", "->", "messageid", "=", "$", "message", "->", "id", ";", "$", "mua", "->", "action", "=", "self", "::", "MESSAGE_ACTION_DELETED", ";", "$", "mua", "->", "timecreated", "=", "time", "(", ")", ";", "$", "mua", "->", "id", "=", "$", "DB", "->", "insert_record", "(", "'message_user_actions'", ",", "$", "mua", ")", ";", "\\", "core", "\\", "event", "\\", "message_deleted", "::", "create_from_ids", "(", "$", "userid", ",", "$", "USER", "->", "id", ",", "$", "message", "->", "id", ",", "$", "mua", "->", "id", ")", "->", "trigger", "(", ")", ";", "}", "}" ]
Deletes a conversation for a specified user. This function does not verify any permissions. @param int $userid The user id of who we want to delete the messages for (this may be done by the admin but will still seem as if it was by the user) @param int $conversationid The id of the other user in the conversation
[ "Deletes", "a", "conversation", "for", "a", "specified", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L1483-L1510
213,347
moodle/moodle
message/classes/api.php
api.can_mark_all_messages_as_read
public static function can_mark_all_messages_as_read(int $userid, int $conversationid) : bool { global $USER; $systemcontext = \context_system::instance(); if (has_capability('moodle/site:readallmessages', $systemcontext)) { return true; } if (!self::is_user_in_conversation($userid, $conversationid)) { return false; } if ($USER->id == $userid) { return true; } return false; }
php
public static function can_mark_all_messages_as_read(int $userid, int $conversationid) : bool { global $USER; $systemcontext = \context_system::instance(); if (has_capability('moodle/site:readallmessages', $systemcontext)) { return true; } if (!self::is_user_in_conversation($userid, $conversationid)) { return false; } if ($USER->id == $userid) { return true; } return false; }
[ "public", "static", "function", "can_mark_all_messages_as_read", "(", "int", "$", "userid", ",", "int", "$", "conversationid", ")", ":", "bool", "{", "global", "$", "USER", ";", "$", "systemcontext", "=", "\\", "context_system", "::", "instance", "(", ")", ";", "if", "(", "has_capability", "(", "'moodle/site:readallmessages'", ",", "$", "systemcontext", ")", ")", "{", "return", "true", ";", "}", "if", "(", "!", "self", "::", "is_user_in_conversation", "(", "$", "userid", ",", "$", "conversationid", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "USER", "->", "id", "==", "$", "userid", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Checks if a user can mark all messages as read. @param int $userid The user id of who we want to mark the messages for @param int $conversationid The id of the conversation @return bool true if user is permitted, false otherwise @since 3.6
[ "Checks", "if", "a", "user", "can", "mark", "all", "messages", "as", "read", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L1551-L1569
213,348
moodle/moodle
message/classes/api.php
api.mark_all_messages_as_read
public static function mark_all_messages_as_read($userid, $conversationid = null) { global $DB; $messagesql = "SELECT m.* FROM {messages} m INNER JOIN {message_conversations} mc ON mc.id = m.conversationid 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 = ? AND m.useridfrom != ?"; $messageparams = []; $messageparams[] = $userid; $messageparams[] = self::MESSAGE_ACTION_READ; $messageparams[] = $userid; $messageparams[] = $userid; if (!is_null($conversationid)) { $messagesql .= " AND mc.id = ?"; $messageparams[] = $conversationid; } $messages = $DB->get_recordset_sql($messagesql, $messageparams); foreach ($messages as $message) { self::mark_message_as_read($userid, $message); } $messages->close(); }
php
public static function mark_all_messages_as_read($userid, $conversationid = null) { global $DB; $messagesql = "SELECT m.* FROM {messages} m INNER JOIN {message_conversations} mc ON mc.id = m.conversationid 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 = ? AND m.useridfrom != ?"; $messageparams = []; $messageparams[] = $userid; $messageparams[] = self::MESSAGE_ACTION_READ; $messageparams[] = $userid; $messageparams[] = $userid; if (!is_null($conversationid)) { $messagesql .= " AND mc.id = ?"; $messageparams[] = $conversationid; } $messages = $DB->get_recordset_sql($messagesql, $messageparams); foreach ($messages as $message) { self::mark_message_as_read($userid, $message); } $messages->close(); }
[ "public", "static", "function", "mark_all_messages_as_read", "(", "$", "userid", ",", "$", "conversationid", "=", "null", ")", "{", "global", "$", "DB", ";", "$", "messagesql", "=", "\"SELECT m.*\n FROM {messages} m\n INNER JOIN {message_conversations} mc\n ON mc.id = m.conversationid\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 = ?\n AND m.useridfrom != ?\"", ";", "$", "messageparams", "=", "[", "]", ";", "$", "messageparams", "[", "]", "=", "$", "userid", ";", "$", "messageparams", "[", "]", "=", "self", "::", "MESSAGE_ACTION_READ", ";", "$", "messageparams", "[", "]", "=", "$", "userid", ";", "$", "messageparams", "[", "]", "=", "$", "userid", ";", "if", "(", "!", "is_null", "(", "$", "conversationid", ")", ")", "{", "$", "messagesql", ".=", "\" AND mc.id = ?\"", ";", "$", "messageparams", "[", "]", "=", "$", "conversationid", ";", "}", "$", "messages", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "messagesql", ",", "$", "messageparams", ")", ";", "foreach", "(", "$", "messages", "as", "$", "message", ")", "{", "self", "::", "mark_message_as_read", "(", "$", "userid", ",", "$", "message", ")", ";", "}", "$", "messages", "->", "close", "(", ")", ";", "}" ]
Marks all messages being sent to a user in a particular conversation. If $conversationdid is null then it marks all messages as read sent to $userid. @param int $userid @param int|null $conversationid The conversation the messages belong to mark as read, if null mark all
[ "Marks", "all", "messages", "being", "sent", "to", "a", "user", "in", "a", "particular", "conversation", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L1683-L1712
213,349
moodle/moodle
message/classes/api.php
api.mark_all_notifications_as_read
public static function mark_all_notifications_as_read($touserid, $fromuserid = null) { global $DB; $notificationsql = "SELECT n.* FROM {notifications} n WHERE useridto = ? AND timeread is NULL"; $notificationsparams = [$touserid]; if (!empty($fromuserid)) { $notificationsql .= " AND useridfrom = ?"; $notificationsparams[] = $fromuserid; } $notifications = $DB->get_recordset_sql($notificationsql, $notificationsparams); foreach ($notifications as $notification) { self::mark_notification_as_read($notification); } $notifications->close(); }
php
public static function mark_all_notifications_as_read($touserid, $fromuserid = null) { global $DB; $notificationsql = "SELECT n.* FROM {notifications} n WHERE useridto = ? AND timeread is NULL"; $notificationsparams = [$touserid]; if (!empty($fromuserid)) { $notificationsql .= " AND useridfrom = ?"; $notificationsparams[] = $fromuserid; } $notifications = $DB->get_recordset_sql($notificationsql, $notificationsparams); foreach ($notifications as $notification) { self::mark_notification_as_read($notification); } $notifications->close(); }
[ "public", "static", "function", "mark_all_notifications_as_read", "(", "$", "touserid", ",", "$", "fromuserid", "=", "null", ")", "{", "global", "$", "DB", ";", "$", "notificationsql", "=", "\"SELECT n.*\n FROM {notifications} n\n WHERE useridto = ?\n AND timeread is NULL\"", ";", "$", "notificationsparams", "=", "[", "$", "touserid", "]", ";", "if", "(", "!", "empty", "(", "$", "fromuserid", ")", ")", "{", "$", "notificationsql", ".=", "\" AND useridfrom = ?\"", ";", "$", "notificationsparams", "[", "]", "=", "$", "fromuserid", ";", "}", "$", "notifications", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "notificationsql", ",", "$", "notificationsparams", ")", ";", "foreach", "(", "$", "notifications", "as", "$", "notification", ")", "{", "self", "::", "mark_notification_as_read", "(", "$", "notification", ")", ";", "}", "$", "notifications", "->", "close", "(", ")", ";", "}" ]
Marks all notifications being sent from one user to another user as read. If the from user is null then it marks all notifications as read sent to the to user. @param int $touserid the id of the message recipient @param int|null $fromuserid the id of the message sender, null if all messages @return void
[ "Marks", "all", "notifications", "being", "sent", "from", "one", "user", "to", "another", "user", "as", "read", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L1723-L1741
213,350
moodle/moodle
message/classes/api.php
api.get_all_message_preferences
public static function get_all_message_preferences($processors, $providers, $user) { $preferences = helper::get_providers_preferences($providers, $user->id); $preferences->userdefaultemail = $user->email; // May be displayed by the email processor. // For every processors put its options on the form (need to get function from processor's lib.php). foreach ($processors as $processor) { $processor->object->load_data($preferences, $user->id); } // Load general messaging preferences. $preferences->blocknoncontacts = self::get_user_privacy_messaging_preference($user->id); $preferences->mailformat = $user->mailformat; $preferences->mailcharset = get_user_preferences('mailcharset', '', $user->id); return $preferences; }
php
public static function get_all_message_preferences($processors, $providers, $user) { $preferences = helper::get_providers_preferences($providers, $user->id); $preferences->userdefaultemail = $user->email; // May be displayed by the email processor. // For every processors put its options on the form (need to get function from processor's lib.php). foreach ($processors as $processor) { $processor->object->load_data($preferences, $user->id); } // Load general messaging preferences. $preferences->blocknoncontacts = self::get_user_privacy_messaging_preference($user->id); $preferences->mailformat = $user->mailformat; $preferences->mailcharset = get_user_preferences('mailcharset', '', $user->id); return $preferences; }
[ "public", "static", "function", "get_all_message_preferences", "(", "$", "processors", ",", "$", "providers", ",", "$", "user", ")", "{", "$", "preferences", "=", "helper", "::", "get_providers_preferences", "(", "$", "providers", ",", "$", "user", "->", "id", ")", ";", "$", "preferences", "->", "userdefaultemail", "=", "$", "user", "->", "email", ";", "// May be displayed by the email processor.", "// For every processors put its options on the form (need to get function from processor's lib.php).", "foreach", "(", "$", "processors", "as", "$", "processor", ")", "{", "$", "processor", "->", "object", "->", "load_data", "(", "$", "preferences", ",", "$", "user", "->", "id", ")", ";", "}", "// Load general messaging preferences.", "$", "preferences", "->", "blocknoncontacts", "=", "self", "::", "get_user_privacy_messaging_preference", "(", "$", "user", "->", "id", ")", ";", "$", "preferences", "->", "mailformat", "=", "$", "user", "->", "mailformat", ";", "$", "preferences", "->", "mailcharset", "=", "get_user_preferences", "(", "'mailcharset'", ",", "''", ",", "$", "user", "->", "id", ")", ";", "return", "$", "preferences", ";", "}" ]
Returns message preferences. @param array $processors @param array $providers @param \stdClass $user @return \stdClass @since 3.2
[ "Returns", "message", "preferences", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L1795-L1810
213,351
moodle/moodle
message/classes/api.php
api.count_blocked_users
public static function count_blocked_users($user = null) { global $USER, $DB; if (empty($user)) { $user = $USER; } $sql = "SELECT count(mub.id) FROM {message_users_blocked} mub WHERE mub.userid = :userid"; return $DB->count_records_sql($sql, array('userid' => $user->id)); }
php
public static function count_blocked_users($user = null) { global $USER, $DB; if (empty($user)) { $user = $USER; } $sql = "SELECT count(mub.id) FROM {message_users_blocked} mub WHERE mub.userid = :userid"; return $DB->count_records_sql($sql, array('userid' => $user->id)); }
[ "public", "static", "function", "count_blocked_users", "(", "$", "user", "=", "null", ")", "{", "global", "$", "USER", ",", "$", "DB", ";", "if", "(", "empty", "(", "$", "user", ")", ")", "{", "$", "user", "=", "$", "USER", ";", "}", "$", "sql", "=", "\"SELECT count(mub.id)\n FROM {message_users_blocked} mub\n WHERE mub.userid = :userid\"", ";", "return", "$", "DB", "->", "count_records_sql", "(", "$", "sql", ",", "array", "(", "'userid'", "=>", "$", "user", "->", "id", ")", ")", ";", "}" ]
Count the number of users blocked by a user. @param \stdClass $user The user object @return int the number of blocked users
[ "Count", "the", "number", "of", "users", "blocked", "by", "a", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L1818-L1829
213,352
moodle/moodle
message/classes/api.php
api.can_post_message
public static function can_post_message($recipient, $sender = null) { global $USER; if (is_null($sender)) { // The message is from the logged in user, unless otherwise specified. $sender = $USER; } $systemcontext = \context_system::instance(); if (!has_capability('moodle/site:sendmessage', $systemcontext, $sender)) { return false; } if (has_capability('moodle/site:readallmessages', $systemcontext, $sender->id)) { return true; } // Check if the recipient can be messaged by the sender. return (self::can_contact_user($recipient->id, $sender->id)); }
php
public static function can_post_message($recipient, $sender = null) { global $USER; if (is_null($sender)) { // The message is from the logged in user, unless otherwise specified. $sender = $USER; } $systemcontext = \context_system::instance(); if (!has_capability('moodle/site:sendmessage', $systemcontext, $sender)) { return false; } if (has_capability('moodle/site:readallmessages', $systemcontext, $sender->id)) { return true; } // Check if the recipient can be messaged by the sender. return (self::can_contact_user($recipient->id, $sender->id)); }
[ "public", "static", "function", "can_post_message", "(", "$", "recipient", ",", "$", "sender", "=", "null", ")", "{", "global", "$", "USER", ";", "if", "(", "is_null", "(", "$", "sender", ")", ")", "{", "// The message is from the logged in user, unless otherwise specified.", "$", "sender", "=", "$", "USER", ";", "}", "$", "systemcontext", "=", "\\", "context_system", "::", "instance", "(", ")", ";", "if", "(", "!", "has_capability", "(", "'moodle/site:sendmessage'", ",", "$", "systemcontext", ",", "$", "sender", ")", ")", "{", "return", "false", ";", "}", "if", "(", "has_capability", "(", "'moodle/site:readallmessages'", ",", "$", "systemcontext", ",", "$", "sender", "->", "id", ")", ")", "{", "return", "true", ";", "}", "// Check if the recipient can be messaged by the sender.", "return", "(", "self", "::", "can_contact_user", "(", "$", "recipient", "->", "id", ",", "$", "sender", "->", "id", ")", ")", ";", "}" ]
Determines if a user is permitted to send another user a private message. If no sender is provided then it defaults to the logged in user. @param \stdClass $recipient The user object. @param \stdClass|null $sender The user object. @return bool true if user is permitted, false otherwise.
[ "Determines", "if", "a", "user", "is", "permitted", "to", "send", "another", "user", "a", "private", "message", ".", "If", "no", "sender", "is", "provided", "then", "it", "defaults", "to", "the", "logged", "in", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L1839-L1858
213,353
moodle/moodle
message/classes/api.php
api.can_send_message_to_conversation
public static function can_send_message_to_conversation(int $userid, int $conversationid) : bool { global $DB; $systemcontext = \context_system::instance(); if (!has_capability('moodle/site:sendmessage', $systemcontext, $userid)) { return false; } if (!self::is_user_in_conversation($userid, $conversationid)) { return false; } // User can post messages and is in the conversation, but we need to check the conversation type to // know whether or not to check the user privacy settings via can_contact_user(). $conversation = $DB->get_record('message_conversations', ['id' => $conversationid], '*', MUST_EXIST); if ($conversation->type == self::MESSAGE_CONVERSATION_TYPE_GROUP || $conversation->type == self::MESSAGE_CONVERSATION_TYPE_SELF) { return true; } else if ($conversation->type == self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL) { // Get the other user in the conversation. $members = self::get_conversation_members($userid, $conversationid); $otheruser = array_filter($members, function($member) use($userid) { return $member->id != $userid; }); $otheruser = reset($otheruser); return self::can_contact_user($otheruser->id, $userid); } else { throw new \moodle_exception("Invalid conversation type '$conversation->type'."); } }
php
public static function can_send_message_to_conversation(int $userid, int $conversationid) : bool { global $DB; $systemcontext = \context_system::instance(); if (!has_capability('moodle/site:sendmessage', $systemcontext, $userid)) { return false; } if (!self::is_user_in_conversation($userid, $conversationid)) { return false; } // User can post messages and is in the conversation, but we need to check the conversation type to // know whether or not to check the user privacy settings via can_contact_user(). $conversation = $DB->get_record('message_conversations', ['id' => $conversationid], '*', MUST_EXIST); if ($conversation->type == self::MESSAGE_CONVERSATION_TYPE_GROUP || $conversation->type == self::MESSAGE_CONVERSATION_TYPE_SELF) { return true; } else if ($conversation->type == self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL) { // Get the other user in the conversation. $members = self::get_conversation_members($userid, $conversationid); $otheruser = array_filter($members, function($member) use($userid) { return $member->id != $userid; }); $otheruser = reset($otheruser); return self::can_contact_user($otheruser->id, $userid); } else { throw new \moodle_exception("Invalid conversation type '$conversation->type'."); } }
[ "public", "static", "function", "can_send_message_to_conversation", "(", "int", "$", "userid", ",", "int", "$", "conversationid", ")", ":", "bool", "{", "global", "$", "DB", ";", "$", "systemcontext", "=", "\\", "context_system", "::", "instance", "(", ")", ";", "if", "(", "!", "has_capability", "(", "'moodle/site:sendmessage'", ",", "$", "systemcontext", ",", "$", "userid", ")", ")", "{", "return", "false", ";", "}", "if", "(", "!", "self", "::", "is_user_in_conversation", "(", "$", "userid", ",", "$", "conversationid", ")", ")", "{", "return", "false", ";", "}", "// User can post messages and is in the conversation, but we need to check the conversation type to", "// know whether or not to check the user privacy settings via can_contact_user().", "$", "conversation", "=", "$", "DB", "->", "get_record", "(", "'message_conversations'", ",", "[", "'id'", "=>", "$", "conversationid", "]", ",", "'*'", ",", "MUST_EXIST", ")", ";", "if", "(", "$", "conversation", "->", "type", "==", "self", "::", "MESSAGE_CONVERSATION_TYPE_GROUP", "||", "$", "conversation", "->", "type", "==", "self", "::", "MESSAGE_CONVERSATION_TYPE_SELF", ")", "{", "return", "true", ";", "}", "else", "if", "(", "$", "conversation", "->", "type", "==", "self", "::", "MESSAGE_CONVERSATION_TYPE_INDIVIDUAL", ")", "{", "// Get the other user in the conversation.", "$", "members", "=", "self", "::", "get_conversation_members", "(", "$", "userid", ",", "$", "conversationid", ")", ";", "$", "otheruser", "=", "array_filter", "(", "$", "members", ",", "function", "(", "$", "member", ")", "use", "(", "$", "userid", ")", "{", "return", "$", "member", "->", "id", "!=", "$", "userid", ";", "}", ")", ";", "$", "otheruser", "=", "reset", "(", "$", "otheruser", ")", ";", "return", "self", "::", "can_contact_user", "(", "$", "otheruser", "->", "id", ",", "$", "userid", ")", ";", "}", "else", "{", "throw", "new", "\\", "moodle_exception", "(", "\"Invalid conversation type '$conversation->type'.\"", ")", ";", "}", "}" ]
Determines if a user is permitted to send a message to a given conversation. If no sender is provided then it defaults to the logged in user. @param int $userid the id of the user on which the checks will be applied. @param int $conversationid the id of the conversation we wish to check. @return bool true if the user can send a message to the conversation, false otherwise. @throws \moodle_exception
[ "Determines", "if", "a", "user", "is", "permitted", "to", "send", "a", "message", "to", "a", "given", "conversation", ".", "If", "no", "sender", "is", "provided", "then", "it", "defaults", "to", "the", "logged", "in", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L1869-L1899
213,354
moodle/moodle
message/classes/api.php
api.is_user_non_contact_blocked
public static function is_user_non_contact_blocked($recipient, $sender = null) { debugging('\core_message\api::is_user_non_contact_blocked() is deprecated', DEBUG_DEVELOPER); global $USER, $CFG; if (is_null($sender)) { // The message is from the logged in user, unless otherwise specified. $sender = $USER; } $privacypreference = self::get_user_privacy_messaging_preference($recipient->id); switch ($privacypreference) { case self::MESSAGE_PRIVACY_SITE: if (!empty($CFG->messagingallusers)) { // Users can be messaged without being contacts or members of the same course. break; } // When the $CFG->messagingallusers privacy setting is disabled, continue with the next // case, because MESSAGE_PRIVACY_SITE is replaced to MESSAGE_PRIVACY_COURSEMEMBER. case self::MESSAGE_PRIVACY_COURSEMEMBER: // Confirm the sender and the recipient are both members of the same course. if (enrol_sharing_course($recipient, $sender)) { // All good, the recipient and the sender are members of the same course. return false; } case self::MESSAGE_PRIVACY_ONLYCONTACTS: // True if they aren't contacts (they can't send a message because of the privacy settings), false otherwise. return !self::is_contact($sender->id, $recipient->id); } return false; }
php
public static function is_user_non_contact_blocked($recipient, $sender = null) { debugging('\core_message\api::is_user_non_contact_blocked() is deprecated', DEBUG_DEVELOPER); global $USER, $CFG; if (is_null($sender)) { // The message is from the logged in user, unless otherwise specified. $sender = $USER; } $privacypreference = self::get_user_privacy_messaging_preference($recipient->id); switch ($privacypreference) { case self::MESSAGE_PRIVACY_SITE: if (!empty($CFG->messagingallusers)) { // Users can be messaged without being contacts or members of the same course. break; } // When the $CFG->messagingallusers privacy setting is disabled, continue with the next // case, because MESSAGE_PRIVACY_SITE is replaced to MESSAGE_PRIVACY_COURSEMEMBER. case self::MESSAGE_PRIVACY_COURSEMEMBER: // Confirm the sender and the recipient are both members of the same course. if (enrol_sharing_course($recipient, $sender)) { // All good, the recipient and the sender are members of the same course. return false; } case self::MESSAGE_PRIVACY_ONLYCONTACTS: // True if they aren't contacts (they can't send a message because of the privacy settings), false otherwise. return !self::is_contact($sender->id, $recipient->id); } return false; }
[ "public", "static", "function", "is_user_non_contact_blocked", "(", "$", "recipient", ",", "$", "sender", "=", "null", ")", "{", "debugging", "(", "'\\core_message\\api::is_user_non_contact_blocked() is deprecated'", ",", "DEBUG_DEVELOPER", ")", ";", "global", "$", "USER", ",", "$", "CFG", ";", "if", "(", "is_null", "(", "$", "sender", ")", ")", "{", "// The message is from the logged in user, unless otherwise specified.", "$", "sender", "=", "$", "USER", ";", "}", "$", "privacypreference", "=", "self", "::", "get_user_privacy_messaging_preference", "(", "$", "recipient", "->", "id", ")", ";", "switch", "(", "$", "privacypreference", ")", "{", "case", "self", "::", "MESSAGE_PRIVACY_SITE", ":", "if", "(", "!", "empty", "(", "$", "CFG", "->", "messagingallusers", ")", ")", "{", "// Users can be messaged without being contacts or members of the same course.", "break", ";", "}", "// When the $CFG->messagingallusers privacy setting is disabled, continue with the next", "// case, because MESSAGE_PRIVACY_SITE is replaced to MESSAGE_PRIVACY_COURSEMEMBER.", "case", "self", "::", "MESSAGE_PRIVACY_COURSEMEMBER", ":", "// Confirm the sender and the recipient are both members of the same course.", "if", "(", "enrol_sharing_course", "(", "$", "recipient", ",", "$", "sender", ")", ")", "{", "// All good, the recipient and the sender are members of the same course.", "return", "false", ";", "}", "case", "self", "::", "MESSAGE_PRIVACY_ONLYCONTACTS", ":", "// True if they aren't contacts (they can't send a message because of the privacy settings), false otherwise.", "return", "!", "self", "::", "is_contact", "(", "$", "sender", "->", "id", ",", "$", "recipient", "->", "id", ")", ";", "}", "return", "false", ";", "}" ]
Checks if the recipient is allowing messages from users that aren't a contact. If not then it checks to make sure the sender is in the recipient's contacts. @deprecated since 3.6 @param \stdClass $recipient The user object. @param \stdClass|null $sender The user object. @return bool true if $sender is blocked, false otherwise.
[ "Checks", "if", "the", "recipient", "is", "allowing", "messages", "from", "users", "that", "aren", "t", "a", "contact", ".", "If", "not", "then", "it", "checks", "to", "make", "sure", "the", "sender", "is", "in", "the", "recipient", "s", "contacts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L2035-L2066
213,355
moodle/moodle
message/classes/api.php
api.is_user_blocked
public static function is_user_blocked($recipientid, $senderid = null) { debugging('\core_message\api::is_user_blocked is deprecated and should not be used.', DEBUG_DEVELOPER); global $USER; if (is_null($senderid)) { // The message is from the logged in user, unless otherwise specified. $senderid = $USER->id; } $systemcontext = \context_system::instance(); if (has_capability('moodle/site:readallmessages', $systemcontext, $senderid)) { return false; } if (self::is_blocked($recipientid, $senderid)) { return true; } return false; }
php
public static function is_user_blocked($recipientid, $senderid = null) { debugging('\core_message\api::is_user_blocked is deprecated and should not be used.', DEBUG_DEVELOPER); global $USER; if (is_null($senderid)) { // The message is from the logged in user, unless otherwise specified. $senderid = $USER->id; } $systemcontext = \context_system::instance(); if (has_capability('moodle/site:readallmessages', $systemcontext, $senderid)) { return false; } if (self::is_blocked($recipientid, $senderid)) { return true; } return false; }
[ "public", "static", "function", "is_user_blocked", "(", "$", "recipientid", ",", "$", "senderid", "=", "null", ")", "{", "debugging", "(", "'\\core_message\\api::is_user_blocked is deprecated and should not be used.'", ",", "DEBUG_DEVELOPER", ")", ";", "global", "$", "USER", ";", "if", "(", "is_null", "(", "$", "senderid", ")", ")", "{", "// The message is from the logged in user, unless otherwise specified.", "$", "senderid", "=", "$", "USER", "->", "id", ";", "}", "$", "systemcontext", "=", "\\", "context_system", "::", "instance", "(", ")", ";", "if", "(", "has_capability", "(", "'moodle/site:readallmessages'", ",", "$", "systemcontext", ",", "$", "senderid", ")", ")", "{", "return", "false", ";", "}", "if", "(", "self", "::", "is_blocked", "(", "$", "recipientid", ",", "$", "senderid", ")", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Checks if the recipient has specifically blocked the sending user. Note: This function will always return false if the sender has the readallmessages capability at the system context level. @deprecated since 3.6 @param int $recipientid User ID of the recipient. @param int $senderid User ID of the sender. @return bool true if $sender is blocked, false otherwise.
[ "Checks", "if", "the", "recipient", "has", "specifically", "blocked", "the", "sending", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L2079-L2100
213,356
moodle/moodle
message/classes/api.php
api.get_message_processor
public static function get_message_processor($name, $ready = false) { global $DB, $CFG; $processor = $DB->get_record('message_processors', array('name' => $name)); if (empty($processor)) { // Processor not found, return. return array(); } $processor = self::get_processed_processor_object($processor); if ($ready) { if ($processor->enabled && $processor->configured) { return $processor; } else { return array(); } } else { return $processor; } }
php
public static function get_message_processor($name, $ready = false) { global $DB, $CFG; $processor = $DB->get_record('message_processors', array('name' => $name)); if (empty($processor)) { // Processor not found, return. return array(); } $processor = self::get_processed_processor_object($processor); if ($ready) { if ($processor->enabled && $processor->configured) { return $processor; } else { return array(); } } else { return $processor; } }
[ "public", "static", "function", "get_message_processor", "(", "$", "name", ",", "$", "ready", "=", "false", ")", "{", "global", "$", "DB", ",", "$", "CFG", ";", "$", "processor", "=", "$", "DB", "->", "get_record", "(", "'message_processors'", ",", "array", "(", "'name'", "=>", "$", "name", ")", ")", ";", "if", "(", "empty", "(", "$", "processor", ")", ")", "{", "// Processor not found, return.", "return", "array", "(", ")", ";", "}", "$", "processor", "=", "self", "::", "get_processed_processor_object", "(", "$", "processor", ")", ";", "if", "(", "$", "ready", ")", "{", "if", "(", "$", "processor", "->", "enabled", "&&", "$", "processor", "->", "configured", ")", "{", "return", "$", "processor", ";", "}", "else", "{", "return", "array", "(", ")", ";", "}", "}", "else", "{", "return", "$", "processor", ";", "}", "}" ]
Get specified message processor, validate corresponding plugin existence and system configuration. @param string $name Name of the processor. @param bool $ready only return ready-to-use processors. @return mixed $processor if processor present else empty array. @since Moodle 3.2
[ "Get", "specified", "message", "processor", "validate", "corresponding", "plugin", "existence", "and", "system", "configuration", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L2111-L2130
213,357
moodle/moodle
message/classes/api.php
api.update_processor_status
public static function update_processor_status($processor, $enabled) { global $DB; $cache = \cache::make('core', 'message_processors_enabled'); $cache->delete($processor->name); return $DB->set_field('message_processors', 'enabled', $enabled, array('id' => $processor->id)); }
php
public static function update_processor_status($processor, $enabled) { global $DB; $cache = \cache::make('core', 'message_processors_enabled'); $cache->delete($processor->name); return $DB->set_field('message_processors', 'enabled', $enabled, array('id' => $processor->id)); }
[ "public", "static", "function", "update_processor_status", "(", "$", "processor", ",", "$", "enabled", ")", "{", "global", "$", "DB", ";", "$", "cache", "=", "\\", "cache", "::", "make", "(", "'core'", ",", "'message_processors_enabled'", ")", ";", "$", "cache", "->", "delete", "(", "$", "processor", "->", "name", ")", ";", "return", "$", "DB", "->", "set_field", "(", "'message_processors'", ",", "'enabled'", ",", "$", "enabled", ",", "array", "(", "'id'", "=>", "$", "processor", "->", "id", ")", ")", ";", "}" ]
Set status of a processor. @param \stdClass $processor processor record. @param 0|1 $enabled 0 or 1 to set the processor status. @return bool @since Moodle 3.2
[ "Set", "status", "of", "a", "processor", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L2165-L2170
213,358
moodle/moodle
message/classes/api.php
api.mark_message_as_read
public static function mark_message_as_read($userid, $message, $timeread = null) { global $DB; if (is_null($timeread)) { $timeread = time(); } $mua = new \stdClass(); $mua->userid = $userid; $mua->messageid = $message->id; $mua->action = self::MESSAGE_ACTION_READ; $mua->timecreated = $timeread; $mua->id = $DB->insert_record('message_user_actions', $mua); // Get the context for the user who received the message. $context = \context_user::instance($userid, IGNORE_MISSING); // If the user no longer exists the context value will be false, in this case use the system context. if ($context === false) { $context = \context_system::instance(); } // Trigger event for reading a message. $event = \core\event\message_viewed::create(array( 'objectid' => $mua->id, 'userid' => $userid, // Using the user who read the message as they are the ones performing the action. 'context' => $context, 'relateduserid' => $message->useridfrom, 'other' => array( 'messageid' => $message->id ) )); $event->trigger(); }
php
public static function mark_message_as_read($userid, $message, $timeread = null) { global $DB; if (is_null($timeread)) { $timeread = time(); } $mua = new \stdClass(); $mua->userid = $userid; $mua->messageid = $message->id; $mua->action = self::MESSAGE_ACTION_READ; $mua->timecreated = $timeread; $mua->id = $DB->insert_record('message_user_actions', $mua); // Get the context for the user who received the message. $context = \context_user::instance($userid, IGNORE_MISSING); // If the user no longer exists the context value will be false, in this case use the system context. if ($context === false) { $context = \context_system::instance(); } // Trigger event for reading a message. $event = \core\event\message_viewed::create(array( 'objectid' => $mua->id, 'userid' => $userid, // Using the user who read the message as they are the ones performing the action. 'context' => $context, 'relateduserid' => $message->useridfrom, 'other' => array( 'messageid' => $message->id ) )); $event->trigger(); }
[ "public", "static", "function", "mark_message_as_read", "(", "$", "userid", ",", "$", "message", ",", "$", "timeread", "=", "null", ")", "{", "global", "$", "DB", ";", "if", "(", "is_null", "(", "$", "timeread", ")", ")", "{", "$", "timeread", "=", "time", "(", ")", ";", "}", "$", "mua", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "mua", "->", "userid", "=", "$", "userid", ";", "$", "mua", "->", "messageid", "=", "$", "message", "->", "id", ";", "$", "mua", "->", "action", "=", "self", "::", "MESSAGE_ACTION_READ", ";", "$", "mua", "->", "timecreated", "=", "$", "timeread", ";", "$", "mua", "->", "id", "=", "$", "DB", "->", "insert_record", "(", "'message_user_actions'", ",", "$", "mua", ")", ";", "// Get the context for the user who received the message.", "$", "context", "=", "\\", "context_user", "::", "instance", "(", "$", "userid", ",", "IGNORE_MISSING", ")", ";", "// If the user no longer exists the context value will be false, in this case use the system context.", "if", "(", "$", "context", "===", "false", ")", "{", "$", "context", "=", "\\", "context_system", "::", "instance", "(", ")", ";", "}", "// Trigger event for reading a message.", "$", "event", "=", "\\", "core", "\\", "event", "\\", "message_viewed", "::", "create", "(", "array", "(", "'objectid'", "=>", "$", "mua", "->", "id", ",", "'userid'", "=>", "$", "userid", ",", "// Using the user who read the message as they are the ones performing the action.", "'context'", "=>", "$", "context", ",", "'relateduserid'", "=>", "$", "message", "->", "useridfrom", ",", "'other'", "=>", "array", "(", "'messageid'", "=>", "$", "message", "->", "id", ")", ")", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "}" ]
Mark a single message as read. @param int $userid The user id who marked the message as read @param \stdClass $message The message @param int|null $timeread The time the message was marked as read, if null will default to time()
[ "Mark", "a", "single", "message", "as", "read", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L2237-L2269
213,359
moodle/moodle
message/classes/api.php
api.can_delete_message
public static function can_delete_message($userid, $messageid) { global $DB, $USER; $systemcontext = \context_system::instance(); $conversationid = $DB->get_field('messages', 'conversationid', ['id' => $messageid], MUST_EXIST); if (has_capability('moodle/site:deleteanymessage', $systemcontext)) { return true; } if (!self::is_user_in_conversation($userid, $conversationid)) { return false; } if (has_capability('moodle/site:deleteownmessage', $systemcontext) && $USER->id == $userid) { return true; } return false; }
php
public static function can_delete_message($userid, $messageid) { global $DB, $USER; $systemcontext = \context_system::instance(); $conversationid = $DB->get_field('messages', 'conversationid', ['id' => $messageid], MUST_EXIST); if (has_capability('moodle/site:deleteanymessage', $systemcontext)) { return true; } if (!self::is_user_in_conversation($userid, $conversationid)) { return false; } if (has_capability('moodle/site:deleteownmessage', $systemcontext) && $USER->id == $userid) { return true; } return false; }
[ "public", "static", "function", "can_delete_message", "(", "$", "userid", ",", "$", "messageid", ")", "{", "global", "$", "DB", ",", "$", "USER", ";", "$", "systemcontext", "=", "\\", "context_system", "::", "instance", "(", ")", ";", "$", "conversationid", "=", "$", "DB", "->", "get_field", "(", "'messages'", ",", "'conversationid'", ",", "[", "'id'", "=>", "$", "messageid", "]", ",", "MUST_EXIST", ")", ";", "if", "(", "has_capability", "(", "'moodle/site:deleteanymessage'", ",", "$", "systemcontext", ")", ")", "{", "return", "true", ";", "}", "if", "(", "!", "self", "::", "is_user_in_conversation", "(", "$", "userid", ",", "$", "conversationid", ")", ")", "{", "return", "false", ";", "}", "if", "(", "has_capability", "(", "'moodle/site:deleteownmessage'", ",", "$", "systemcontext", ")", "&&", "$", "USER", "->", "id", "==", "$", "userid", ")", "{", "return", "true", ";", "}", "return", "false", ";", "}" ]
Checks if a user can delete a message. @param int $userid the user id of who we want to delete the message for (this may be done by the admin but will still seem as if it was by the user) @param int $messageid The message id @return bool Returns true if a user can delete the message, false otherwise.
[ "Checks", "if", "a", "user", "can", "delete", "a", "message", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L2308-L2329
213,360
moodle/moodle
message/classes/api.php
api.get_conversation_between_users
public static function get_conversation_between_users(array $userids) { global $DB; $conversations = self::get_individual_conversations_between_users([$userids]); $conversation = $conversations[0]; if ($conversation) { return $conversation->id; } return false; }
php
public static function get_conversation_between_users(array $userids) { global $DB; $conversations = self::get_individual_conversations_between_users([$userids]); $conversation = $conversations[0]; if ($conversation) { return $conversation->id; } return false; }
[ "public", "static", "function", "get_conversation_between_users", "(", "array", "$", "userids", ")", "{", "global", "$", "DB", ";", "$", "conversations", "=", "self", "::", "get_individual_conversations_between_users", "(", "[", "$", "userids", "]", ")", ";", "$", "conversation", "=", "$", "conversations", "[", "0", "]", ";", "if", "(", "$", "conversation", ")", "{", "return", "$", "conversation", "->", "id", ";", "}", "return", "false", ";", "}" ]
Returns the conversation between two users. @param array $userids @return int|bool The id of the conversation, false if not found
[ "Returns", "the", "conversation", "between", "two", "users", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L2374-L2385
213,361
moodle/moodle
message/classes/api.php
api.get_individual_conversations_between_users
public static function get_individual_conversations_between_users(array $useridsets) : array { global $DB; if (empty($useridsets)) { return []; } $hashes = array_map(function($userids) { return helper::get_conversation_hash($userids); }, $useridsets); list($inorequalsql, $params) = $DB->get_in_or_equal($hashes); array_unshift($params, self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL); $where = "type = ? AND convhash ${inorequalsql}"; $conversations = array_fill(0, count($hashes), null); $records = $DB->get_records_select('message_conversations', $where, $params); foreach (array_values($records) as $record) { $index = array_search($record->convhash, $hashes); if ($index !== false) { $conversations[$index] = $record; } } return $conversations; }
php
public static function get_individual_conversations_between_users(array $useridsets) : array { global $DB; if (empty($useridsets)) { return []; } $hashes = array_map(function($userids) { return helper::get_conversation_hash($userids); }, $useridsets); list($inorequalsql, $params) = $DB->get_in_or_equal($hashes); array_unshift($params, self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL); $where = "type = ? AND convhash ${inorequalsql}"; $conversations = array_fill(0, count($hashes), null); $records = $DB->get_records_select('message_conversations', $where, $params); foreach (array_values($records) as $record) { $index = array_search($record->convhash, $hashes); if ($index !== false) { $conversations[$index] = $record; } } return $conversations; }
[ "public", "static", "function", "get_individual_conversations_between_users", "(", "array", "$", "useridsets", ")", ":", "array", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "useridsets", ")", ")", "{", "return", "[", "]", ";", "}", "$", "hashes", "=", "array_map", "(", "function", "(", "$", "userids", ")", "{", "return", "helper", "::", "get_conversation_hash", "(", "$", "userids", ")", ";", "}", ",", "$", "useridsets", ")", ";", "list", "(", "$", "inorequalsql", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "hashes", ")", ";", "array_unshift", "(", "$", "params", ",", "self", "::", "MESSAGE_CONVERSATION_TYPE_INDIVIDUAL", ")", ";", "$", "where", "=", "\"type = ? AND convhash ${inorequalsql}\"", ";", "$", "conversations", "=", "array_fill", "(", "0", ",", "count", "(", "$", "hashes", ")", ",", "null", ")", ";", "$", "records", "=", "$", "DB", "->", "get_records_select", "(", "'message_conversations'", ",", "$", "where", ",", "$", "params", ")", ";", "foreach", "(", "array_values", "(", "$", "records", ")", "as", "$", "record", ")", "{", "$", "index", "=", "array_search", "(", "$", "record", "->", "convhash", ",", "$", "hashes", ")", ";", "if", "(", "$", "index", "!==", "false", ")", "{", "$", "conversations", "[", "$", "index", "]", "=", "$", "record", ";", "}", "}", "return", "$", "conversations", ";", "}" ]
Returns the conversations between sets of users. The returned array of results will be in the same order as the requested arguments, null will be returned if there is no conversation for that user pair. For example: If we have 6 users with ids 1, 2, 3, 4, 5, 6 where only 2 conversations exist. One between 1 and 2 and another between 5 and 6. Then if we call: $conversations = get_individual_conversations_between_users([[1,2], [3,4], [5,6]]); The conversations array will look like: [<conv_record>, null, <conv_record>]; Where null is returned for the pairing of [3, 4] since no record exists. @param array $useridsets An array of arrays where the inner array is the set of user ids @return stdClass[] Array of conversation records
[ "Returns", "the", "conversations", "between", "sets", "of", "users", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L2409-L2434
213,362
moodle/moodle
message/classes/api.php
api.get_self_conversation
public static function get_self_conversation(int $userid) { global $DB; $conditions = [ 'type' => self::MESSAGE_CONVERSATION_TYPE_SELF, 'convhash' => helper::get_conversation_hash([$userid]) ]; return $DB->get_record('message_conversations', $conditions); }
php
public static function get_self_conversation(int $userid) { global $DB; $conditions = [ 'type' => self::MESSAGE_CONVERSATION_TYPE_SELF, 'convhash' => helper::get_conversation_hash([$userid]) ]; return $DB->get_record('message_conversations', $conditions); }
[ "public", "static", "function", "get_self_conversation", "(", "int", "$", "userid", ")", "{", "global", "$", "DB", ";", "$", "conditions", "=", "[", "'type'", "=>", "self", "::", "MESSAGE_CONVERSATION_TYPE_SELF", ",", "'convhash'", "=>", "helper", "::", "get_conversation_hash", "(", "[", "$", "userid", "]", ")", "]", ";", "return", "$", "DB", "->", "get_record", "(", "'message_conversations'", ",", "$", "conditions", ")", ";", "}" ]
Returns the self conversation for a user. @param int $userid The user id to get the self-conversations @return \stdClass|false The self-conversation object or false if it doesn't exist @since Moodle 3.7
[ "Returns", "the", "self", "conversation", "for", "a", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L2443-L2451
213,363
moodle/moodle
message/classes/api.php
api.create_conversation_between_users
public static function create_conversation_between_users(array $userids) { debugging('\core_message\api::create_conversation_between_users is deprecated, please use ' . '\core_message\api::create_conversation instead.', DEBUG_DEVELOPER); // This method was always used for individual conversations. $conversation = self::create_conversation(self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL, $userids); return $conversation->id; }
php
public static function create_conversation_between_users(array $userids) { debugging('\core_message\api::create_conversation_between_users is deprecated, please use ' . '\core_message\api::create_conversation instead.', DEBUG_DEVELOPER); // This method was always used for individual conversations. $conversation = self::create_conversation(self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL, $userids); return $conversation->id; }
[ "public", "static", "function", "create_conversation_between_users", "(", "array", "$", "userids", ")", "{", "debugging", "(", "'\\core_message\\api::create_conversation_between_users is deprecated, please use '", ".", "'\\core_message\\api::create_conversation instead.'", ",", "DEBUG_DEVELOPER", ")", ";", "// This method was always used for individual conversations.", "$", "conversation", "=", "self", "::", "create_conversation", "(", "self", "::", "MESSAGE_CONVERSATION_TYPE_INDIVIDUAL", ",", "$", "userids", ")", ";", "return", "$", "conversation", "->", "id", ";", "}" ]
Creates a conversation between two users. @deprecated since 3.6 @param array $userids @return int The id of the conversation
[ "Creates", "a", "conversation", "between", "two", "users", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L2460-L2468
213,364
moodle/moodle
message/classes/api.php
api.create_conversation
public static function create_conversation(int $type, array $userids, string $name = null, int $enabled = self::MESSAGE_CONVERSATION_ENABLED, string $component = null, string $itemtype = null, int $itemid = null, int $contextid = null) { global $DB; $validtypes = [ self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL, self::MESSAGE_CONVERSATION_TYPE_GROUP, self::MESSAGE_CONVERSATION_TYPE_SELF ]; if (!in_array($type, $validtypes)) { throw new \moodle_exception('An invalid conversation type was specified.'); } // Sanity check. if ($type == self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL) { if (count($userids) > 2) { throw new \moodle_exception('An individual conversation can not have more than two users.'); } if ($userids[0] == $userids[1]) { throw new \moodle_exception('Trying to create an individual conversation instead of a self conversation.'); } } else if ($type == self::MESSAGE_CONVERSATION_TYPE_SELF) { if (count($userids) != 1) { throw new \moodle_exception('A self conversation can not have more than one user.'); } } $conversation = new \stdClass(); $conversation->type = $type; $conversation->name = $name; $conversation->convhash = null; if ($type == self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL || $type == self::MESSAGE_CONVERSATION_TYPE_SELF) { $conversation->convhash = helper::get_conversation_hash($userids); } $conversation->component = $component; $conversation->itemtype = $itemtype; $conversation->itemid = $itemid; $conversation->contextid = $contextid; $conversation->enabled = $enabled; $conversation->timecreated = time(); $conversation->timemodified = $conversation->timecreated; $conversation->id = $DB->insert_record('message_conversations', $conversation); // Add users to this conversation. $arrmembers = []; foreach ($userids as $userid) { $member = new \stdClass(); $member->conversationid = $conversation->id; $member->userid = $userid; $member->timecreated = time(); $member->id = $DB->insert_record('message_conversation_members', $member); $arrmembers[] = $member; } $conversation->members = $arrmembers; return $conversation; }
php
public static function create_conversation(int $type, array $userids, string $name = null, int $enabled = self::MESSAGE_CONVERSATION_ENABLED, string $component = null, string $itemtype = null, int $itemid = null, int $contextid = null) { global $DB; $validtypes = [ self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL, self::MESSAGE_CONVERSATION_TYPE_GROUP, self::MESSAGE_CONVERSATION_TYPE_SELF ]; if (!in_array($type, $validtypes)) { throw new \moodle_exception('An invalid conversation type was specified.'); } // Sanity check. if ($type == self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL) { if (count($userids) > 2) { throw new \moodle_exception('An individual conversation can not have more than two users.'); } if ($userids[0] == $userids[1]) { throw new \moodle_exception('Trying to create an individual conversation instead of a self conversation.'); } } else if ($type == self::MESSAGE_CONVERSATION_TYPE_SELF) { if (count($userids) != 1) { throw new \moodle_exception('A self conversation can not have more than one user.'); } } $conversation = new \stdClass(); $conversation->type = $type; $conversation->name = $name; $conversation->convhash = null; if ($type == self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL || $type == self::MESSAGE_CONVERSATION_TYPE_SELF) { $conversation->convhash = helper::get_conversation_hash($userids); } $conversation->component = $component; $conversation->itemtype = $itemtype; $conversation->itemid = $itemid; $conversation->contextid = $contextid; $conversation->enabled = $enabled; $conversation->timecreated = time(); $conversation->timemodified = $conversation->timecreated; $conversation->id = $DB->insert_record('message_conversations', $conversation); // Add users to this conversation. $arrmembers = []; foreach ($userids as $userid) { $member = new \stdClass(); $member->conversationid = $conversation->id; $member->userid = $userid; $member->timecreated = time(); $member->id = $DB->insert_record('message_conversation_members', $member); $arrmembers[] = $member; } $conversation->members = $arrmembers; return $conversation; }
[ "public", "static", "function", "create_conversation", "(", "int", "$", "type", ",", "array", "$", "userids", ",", "string", "$", "name", "=", "null", ",", "int", "$", "enabled", "=", "self", "::", "MESSAGE_CONVERSATION_ENABLED", ",", "string", "$", "component", "=", "null", ",", "string", "$", "itemtype", "=", "null", ",", "int", "$", "itemid", "=", "null", ",", "int", "$", "contextid", "=", "null", ")", "{", "global", "$", "DB", ";", "$", "validtypes", "=", "[", "self", "::", "MESSAGE_CONVERSATION_TYPE_INDIVIDUAL", ",", "self", "::", "MESSAGE_CONVERSATION_TYPE_GROUP", ",", "self", "::", "MESSAGE_CONVERSATION_TYPE_SELF", "]", ";", "if", "(", "!", "in_array", "(", "$", "type", ",", "$", "validtypes", ")", ")", "{", "throw", "new", "\\", "moodle_exception", "(", "'An invalid conversation type was specified.'", ")", ";", "}", "// Sanity check.", "if", "(", "$", "type", "==", "self", "::", "MESSAGE_CONVERSATION_TYPE_INDIVIDUAL", ")", "{", "if", "(", "count", "(", "$", "userids", ")", ">", "2", ")", "{", "throw", "new", "\\", "moodle_exception", "(", "'An individual conversation can not have more than two users.'", ")", ";", "}", "if", "(", "$", "userids", "[", "0", "]", "==", "$", "userids", "[", "1", "]", ")", "{", "throw", "new", "\\", "moodle_exception", "(", "'Trying to create an individual conversation instead of a self conversation.'", ")", ";", "}", "}", "else", "if", "(", "$", "type", "==", "self", "::", "MESSAGE_CONVERSATION_TYPE_SELF", ")", "{", "if", "(", "count", "(", "$", "userids", ")", "!=", "1", ")", "{", "throw", "new", "\\", "moodle_exception", "(", "'A self conversation can not have more than one user.'", ")", ";", "}", "}", "$", "conversation", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "conversation", "->", "type", "=", "$", "type", ";", "$", "conversation", "->", "name", "=", "$", "name", ";", "$", "conversation", "->", "convhash", "=", "null", ";", "if", "(", "$", "type", "==", "self", "::", "MESSAGE_CONVERSATION_TYPE_INDIVIDUAL", "||", "$", "type", "==", "self", "::", "MESSAGE_CONVERSATION_TYPE_SELF", ")", "{", "$", "conversation", "->", "convhash", "=", "helper", "::", "get_conversation_hash", "(", "$", "userids", ")", ";", "}", "$", "conversation", "->", "component", "=", "$", "component", ";", "$", "conversation", "->", "itemtype", "=", "$", "itemtype", ";", "$", "conversation", "->", "itemid", "=", "$", "itemid", ";", "$", "conversation", "->", "contextid", "=", "$", "contextid", ";", "$", "conversation", "->", "enabled", "=", "$", "enabled", ";", "$", "conversation", "->", "timecreated", "=", "time", "(", ")", ";", "$", "conversation", "->", "timemodified", "=", "$", "conversation", "->", "timecreated", ";", "$", "conversation", "->", "id", "=", "$", "DB", "->", "insert_record", "(", "'message_conversations'", ",", "$", "conversation", ")", ";", "// Add users to this conversation.", "$", "arrmembers", "=", "[", "]", ";", "foreach", "(", "$", "userids", "as", "$", "userid", ")", "{", "$", "member", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "member", "->", "conversationid", "=", "$", "conversation", "->", "id", ";", "$", "member", "->", "userid", "=", "$", "userid", ";", "$", "member", "->", "timecreated", "=", "time", "(", ")", ";", "$", "member", "->", "id", "=", "$", "DB", "->", "insert_record", "(", "'message_conversation_members'", ",", "$", "member", ")", ";", "$", "arrmembers", "[", "]", "=", "$", "member", ";", "}", "$", "conversation", "->", "members", "=", "$", "arrmembers", ";", "return", "$", "conversation", ";", "}" ]
Creates a conversation with selected users and messages. @param int $type The type of conversation @param int[] $userids The array of users to add to the conversation @param string|null $name The name of the conversation @param int $enabled Determines if the conversation is created enabled or disabled @param string|null $component Defines the Moodle component which the conversation belongs to, if any @param string|null $itemtype Defines the type of the component @param int|null $itemid The id of the component @param int|null $contextid The id of the context @return \stdClass
[ "Creates", "a", "conversation", "with", "selected", "users", "and", "messages", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L2483-L2544
213,365
moodle/moodle
message/classes/api.php
api.can_create_group_conversation
public static function can_create_group_conversation(int $userid, \context $context) : bool { global $CFG; // If we can't message at all, then we can't create a conversation. if (empty($CFG->messaging)) { return false; } // We need to check they have the capability to create the conversation. return has_capability('moodle/course:creategroupconversations', $context, $userid); }
php
public static function can_create_group_conversation(int $userid, \context $context) : bool { global $CFG; // If we can't message at all, then we can't create a conversation. if (empty($CFG->messaging)) { return false; } // We need to check they have the capability to create the conversation. return has_capability('moodle/course:creategroupconversations', $context, $userid); }
[ "public", "static", "function", "can_create_group_conversation", "(", "int", "$", "userid", ",", "\\", "context", "$", "context", ")", ":", "bool", "{", "global", "$", "CFG", ";", "// If we can't message at all, then we can't create a conversation.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "return", "false", ";", "}", "// We need to check they have the capability to create the conversation.", "return", "has_capability", "(", "'moodle/course:creategroupconversations'", ",", "$", "context", ",", "$", "userid", ")", ";", "}" ]
Checks if a user can create a group conversation. @param int $userid The id of the user attempting to create the conversation @param \context $context The context they are creating the conversation from, most likely course context @return bool
[ "Checks", "if", "a", "user", "can", "create", "a", "group", "conversation", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L2553-L2563
213,366
moodle/moodle
message/classes/api.php
api.can_create_contact
public static function can_create_contact(int $userid, int $requesteduserid) : bool { global $CFG; // If we can't message at all, then we can't create a contact. if (empty($CFG->messaging)) { return false; } // If we can message anyone on the site then we can create a contact. if ($CFG->messagingallusers) { return true; } // We need to check if they are in the same course. return enrol_sharing_course($userid, $requesteduserid); }
php
public static function can_create_contact(int $userid, int $requesteduserid) : bool { global $CFG; // If we can't message at all, then we can't create a contact. if (empty($CFG->messaging)) { return false; } // If we can message anyone on the site then we can create a contact. if ($CFG->messagingallusers) { return true; } // We need to check if they are in the same course. return enrol_sharing_course($userid, $requesteduserid); }
[ "public", "static", "function", "can_create_contact", "(", "int", "$", "userid", ",", "int", "$", "requesteduserid", ")", ":", "bool", "{", "global", "$", "CFG", ";", "// If we can't message at all, then we can't create a contact.", "if", "(", "empty", "(", "$", "CFG", "->", "messaging", ")", ")", "{", "return", "false", ";", "}", "// If we can message anyone on the site then we can create a contact.", "if", "(", "$", "CFG", "->", "messagingallusers", ")", "{", "return", "true", ";", "}", "// We need to check if they are in the same course.", "return", "enrol_sharing_course", "(", "$", "userid", ",", "$", "requesteduserid", ")", ";", "}" ]
Checks if a user can create 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 @return bool
[ "Checks", "if", "a", "user", "can", "create", "a", "contact", "request", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L2572-L2587
213,367
moodle/moodle
message/classes/api.php
api.create_contact_request
public static function create_contact_request(int $userid, int $requesteduserid) : \stdClass { global $DB, $PAGE; $request = new \stdClass(); $request->userid = $userid; $request->requesteduserid = $requesteduserid; $request->timecreated = time(); $request->id = $DB->insert_record('message_contact_requests', $request); // Send a notification. $userfrom = \core_user::get_user($userid); $userfromfullname = fullname($userfrom); $userto = \core_user::get_user($requesteduserid); $url = new \moodle_url('/message/pendingcontactrequests.php'); $subject = get_string('messagecontactrequestsnotificationsubject', 'core_message', $userfromfullname); $fullmessage = get_string('messagecontactrequestsnotification', 'core_message', $userfromfullname); $message = new \core\message\message(); $message->courseid = SITEID; $message->component = 'moodle'; $message->name = 'messagecontactrequests'; $message->notification = 1; $message->userfrom = $userfrom; $message->userto = $userto; $message->subject = $subject; $message->fullmessage = text_to_html($fullmessage); $message->fullmessageformat = FORMAT_HTML; $message->fullmessagehtml = $fullmessage; $message->smallmessage = ''; $message->contexturl = $url->out(false); $userpicture = new \user_picture($userfrom); $userpicture->includetoken = $userto->id; // Generate an out-of-session token for the user receiving the message. $message->customdata = [ 'notificationiconurl' => $userpicture->get_url($PAGE)->out(false), 'actionbuttons' => [ 'accept' => get_string_manager()->get_string('accept', 'moodle', null, $userto->lang), 'reject' => get_string_manager()->get_string('reject', 'moodle', null, $userto->lang), ], ]; message_send($message); return $request; }
php
public static function create_contact_request(int $userid, int $requesteduserid) : \stdClass { global $DB, $PAGE; $request = new \stdClass(); $request->userid = $userid; $request->requesteduserid = $requesteduserid; $request->timecreated = time(); $request->id = $DB->insert_record('message_contact_requests', $request); // Send a notification. $userfrom = \core_user::get_user($userid); $userfromfullname = fullname($userfrom); $userto = \core_user::get_user($requesteduserid); $url = new \moodle_url('/message/pendingcontactrequests.php'); $subject = get_string('messagecontactrequestsnotificationsubject', 'core_message', $userfromfullname); $fullmessage = get_string('messagecontactrequestsnotification', 'core_message', $userfromfullname); $message = new \core\message\message(); $message->courseid = SITEID; $message->component = 'moodle'; $message->name = 'messagecontactrequests'; $message->notification = 1; $message->userfrom = $userfrom; $message->userto = $userto; $message->subject = $subject; $message->fullmessage = text_to_html($fullmessage); $message->fullmessageformat = FORMAT_HTML; $message->fullmessagehtml = $fullmessage; $message->smallmessage = ''; $message->contexturl = $url->out(false); $userpicture = new \user_picture($userfrom); $userpicture->includetoken = $userto->id; // Generate an out-of-session token for the user receiving the message. $message->customdata = [ 'notificationiconurl' => $userpicture->get_url($PAGE)->out(false), 'actionbuttons' => [ 'accept' => get_string_manager()->get_string('accept', 'moodle', null, $userto->lang), 'reject' => get_string_manager()->get_string('reject', 'moodle', null, $userto->lang), ], ]; message_send($message); return $request; }
[ "public", "static", "function", "create_contact_request", "(", "int", "$", "userid", ",", "int", "$", "requesteduserid", ")", ":", "\\", "stdClass", "{", "global", "$", "DB", ",", "$", "PAGE", ";", "$", "request", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "request", "->", "userid", "=", "$", "userid", ";", "$", "request", "->", "requesteduserid", "=", "$", "requesteduserid", ";", "$", "request", "->", "timecreated", "=", "time", "(", ")", ";", "$", "request", "->", "id", "=", "$", "DB", "->", "insert_record", "(", "'message_contact_requests'", ",", "$", "request", ")", ";", "// Send a notification.", "$", "userfrom", "=", "\\", "core_user", "::", "get_user", "(", "$", "userid", ")", ";", "$", "userfromfullname", "=", "fullname", "(", "$", "userfrom", ")", ";", "$", "userto", "=", "\\", "core_user", "::", "get_user", "(", "$", "requesteduserid", ")", ";", "$", "url", "=", "new", "\\", "moodle_url", "(", "'/message/pendingcontactrequests.php'", ")", ";", "$", "subject", "=", "get_string", "(", "'messagecontactrequestsnotificationsubject'", ",", "'core_message'", ",", "$", "userfromfullname", ")", ";", "$", "fullmessage", "=", "get_string", "(", "'messagecontactrequestsnotification'", ",", "'core_message'", ",", "$", "userfromfullname", ")", ";", "$", "message", "=", "new", "\\", "core", "\\", "message", "\\", "message", "(", ")", ";", "$", "message", "->", "courseid", "=", "SITEID", ";", "$", "message", "->", "component", "=", "'moodle'", ";", "$", "message", "->", "name", "=", "'messagecontactrequests'", ";", "$", "message", "->", "notification", "=", "1", ";", "$", "message", "->", "userfrom", "=", "$", "userfrom", ";", "$", "message", "->", "userto", "=", "$", "userto", ";", "$", "message", "->", "subject", "=", "$", "subject", ";", "$", "message", "->", "fullmessage", "=", "text_to_html", "(", "$", "fullmessage", ")", ";", "$", "message", "->", "fullmessageformat", "=", "FORMAT_HTML", ";", "$", "message", "->", "fullmessagehtml", "=", "$", "fullmessage", ";", "$", "message", "->", "smallmessage", "=", "''", ";", "$", "message", "->", "contexturl", "=", "$", "url", "->", "out", "(", "false", ")", ";", "$", "userpicture", "=", "new", "\\", "user_picture", "(", "$", "userfrom", ")", ";", "$", "userpicture", "->", "includetoken", "=", "$", "userto", "->", "id", ";", "// Generate an out-of-session token for the user receiving the message.", "$", "message", "->", "customdata", "=", "[", "'notificationiconurl'", "=>", "$", "userpicture", "->", "get_url", "(", "$", "PAGE", ")", "->", "out", "(", "false", ")", ",", "'actionbuttons'", "=>", "[", "'accept'", "=>", "get_string_manager", "(", ")", "->", "get_string", "(", "'accept'", ",", "'moodle'", ",", "null", ",", "$", "userto", "->", "lang", ")", ",", "'reject'", "=>", "get_string_manager", "(", ")", "->", "get_string", "(", "'reject'", ",", "'moodle'", ",", "null", ",", "$", "userto", "->", "lang", ")", ",", "]", ",", "]", ";", "message_send", "(", "$", "message", ")", ";", "return", "$", "request", ";", "}" ]
Handles creating 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 @return \stdClass the request
[ "Handles", "creating", "a", "contact", "request", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L2596-L2641
213,368
moodle/moodle
message/classes/api.php
api.confirm_contact_request
public static function confirm_contact_request(int $userid, int $requesteduserid) { global $DB; if ($request = $DB->get_record('message_contact_requests', ['userid' => $userid, 'requesteduserid' => $requesteduserid])) { self::add_contact($userid, $requesteduserid); $DB->delete_records('message_contact_requests', ['id' => $request->id]); } }
php
public static function confirm_contact_request(int $userid, int $requesteduserid) { global $DB; if ($request = $DB->get_record('message_contact_requests', ['userid' => $userid, 'requesteduserid' => $requesteduserid])) { self::add_contact($userid, $requesteduserid); $DB->delete_records('message_contact_requests', ['id' => $request->id]); } }
[ "public", "static", "function", "confirm_contact_request", "(", "int", "$", "userid", ",", "int", "$", "requesteduserid", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "request", "=", "$", "DB", "->", "get_record", "(", "'message_contact_requests'", ",", "[", "'userid'", "=>", "$", "userid", ",", "'requesteduserid'", "=>", "$", "requesteduserid", "]", ")", ")", "{", "self", "::", "add_contact", "(", "$", "userid", ",", "$", "requesteduserid", ")", ";", "$", "DB", "->", "delete_records", "(", "'message_contact_requests'", ",", "[", "'id'", "=>", "$", "request", "->", "id", "]", ")", ";", "}", "}" ]
Handles confirming a contact request. @param int $userid The id of the user who created the contact request @param int $requesteduserid The id of the user confirming the request
[ "Handles", "confirming", "a", "contact", "request", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L2650-L2659
213,369
moodle/moodle
message/classes/api.php
api.decline_contact_request
public static function decline_contact_request(int $userid, int $requesteduserid) { global $DB; if ($request = $DB->get_record('message_contact_requests', ['userid' => $userid, 'requesteduserid' => $requesteduserid])) { $DB->delete_records('message_contact_requests', ['id' => $request->id]); } }
php
public static function decline_contact_request(int $userid, int $requesteduserid) { global $DB; if ($request = $DB->get_record('message_contact_requests', ['userid' => $userid, 'requesteduserid' => $requesteduserid])) { $DB->delete_records('message_contact_requests', ['id' => $request->id]); } }
[ "public", "static", "function", "decline_contact_request", "(", "int", "$", "userid", ",", "int", "$", "requesteduserid", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "request", "=", "$", "DB", "->", "get_record", "(", "'message_contact_requests'", ",", "[", "'userid'", "=>", "$", "userid", ",", "'requesteduserid'", "=>", "$", "requesteduserid", "]", ")", ")", "{", "$", "DB", "->", "delete_records", "(", "'message_contact_requests'", ",", "[", "'id'", "=>", "$", "request", "->", "id", "]", ")", ";", "}", "}" ]
Handles declining a contact request. @param int $userid The id of the user who created the contact request @param int $requesteduserid The id of the user declining the request
[ "Handles", "declining", "a", "contact", "request", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L2667-L2674
213,370
moodle/moodle
message/classes/api.php
api.add_contact
public static function add_contact(int $userid, int $contactid) { global $DB; $messagecontact = new \stdClass(); $messagecontact->userid = $userid; $messagecontact->contactid = $contactid; $messagecontact->timecreated = time(); $messagecontact->id = $DB->insert_record('message_contacts', $messagecontact); $eventparams = [ 'objectid' => $messagecontact->id, 'userid' => $userid, 'relateduserid' => $contactid, 'context' => \context_user::instance($userid) ]; $event = \core\event\message_contact_added::create($eventparams); $event->add_record_snapshot('message_contacts', $messagecontact); $event->trigger(); }
php
public static function add_contact(int $userid, int $contactid) { global $DB; $messagecontact = new \stdClass(); $messagecontact->userid = $userid; $messagecontact->contactid = $contactid; $messagecontact->timecreated = time(); $messagecontact->id = $DB->insert_record('message_contacts', $messagecontact); $eventparams = [ 'objectid' => $messagecontact->id, 'userid' => $userid, 'relateduserid' => $contactid, 'context' => \context_user::instance($userid) ]; $event = \core\event\message_contact_added::create($eventparams); $event->add_record_snapshot('message_contacts', $messagecontact); $event->trigger(); }
[ "public", "static", "function", "add_contact", "(", "int", "$", "userid", ",", "int", "$", "contactid", ")", "{", "global", "$", "DB", ";", "$", "messagecontact", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "messagecontact", "->", "userid", "=", "$", "userid", ";", "$", "messagecontact", "->", "contactid", "=", "$", "contactid", ";", "$", "messagecontact", "->", "timecreated", "=", "time", "(", ")", ";", "$", "messagecontact", "->", "id", "=", "$", "DB", "->", "insert_record", "(", "'message_contacts'", ",", "$", "messagecontact", ")", ";", "$", "eventparams", "=", "[", "'objectid'", "=>", "$", "messagecontact", "->", "id", ",", "'userid'", "=>", "$", "userid", ",", "'relateduserid'", "=>", "$", "contactid", ",", "'context'", "=>", "\\", "context_user", "::", "instance", "(", "$", "userid", ")", "]", ";", "$", "event", "=", "\\", "core", "\\", "event", "\\", "message_contact_added", "::", "create", "(", "$", "eventparams", ")", ";", "$", "event", "->", "add_record_snapshot", "(", "'message_contacts'", ",", "$", "messagecontact", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "}" ]
Handles adding a contact. @param int $userid The id of the user who requested to be a contact @param int $contactid The id of the contact
[ "Handles", "adding", "a", "contact", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L2731-L2749
213,371
moodle/moodle
message/classes/api.php
api.remove_contact
public static function remove_contact(int $userid, int $contactid) { global $DB; if ($contact = self::get_contact($userid, $contactid)) { $DB->delete_records('message_contacts', ['id' => $contact->id]); $event = \core\event\message_contact_removed::create(array( 'objectid' => $contact->id, 'userid' => $userid, 'relateduserid' => $contactid, 'context' => \context_user::instance($userid) )); $event->add_record_snapshot('message_contacts', $contact); $event->trigger(); } }
php
public static function remove_contact(int $userid, int $contactid) { global $DB; if ($contact = self::get_contact($userid, $contactid)) { $DB->delete_records('message_contacts', ['id' => $contact->id]); $event = \core\event\message_contact_removed::create(array( 'objectid' => $contact->id, 'userid' => $userid, 'relateduserid' => $contactid, 'context' => \context_user::instance($userid) )); $event->add_record_snapshot('message_contacts', $contact); $event->trigger(); } }
[ "public", "static", "function", "remove_contact", "(", "int", "$", "userid", ",", "int", "$", "contactid", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "contact", "=", "self", "::", "get_contact", "(", "$", "userid", ",", "$", "contactid", ")", ")", "{", "$", "DB", "->", "delete_records", "(", "'message_contacts'", ",", "[", "'id'", "=>", "$", "contact", "->", "id", "]", ")", ";", "$", "event", "=", "\\", "core", "\\", "event", "\\", "message_contact_removed", "::", "create", "(", "array", "(", "'objectid'", "=>", "$", "contact", "->", "id", ",", "'userid'", "=>", "$", "userid", ",", "'relateduserid'", "=>", "$", "contactid", ",", "'context'", "=>", "\\", "context_user", "::", "instance", "(", "$", "userid", ")", ")", ")", ";", "$", "event", "->", "add_record_snapshot", "(", "'message_contacts'", ",", "$", "contact", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "}", "}" ]
Handles removing a contact. @param int $userid The id of the user who is removing a user as a contact @param int $contactid The id of the user to be removed as a contact
[ "Handles", "removing", "a", "contact", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L2757-L2772
213,372
moodle/moodle
message/classes/api.php
api.block_user
public static function block_user(int $userid, int $usertoblockid) { global $DB; $blocked = new \stdClass(); $blocked->userid = $userid; $blocked->blockeduserid = $usertoblockid; $blocked->timecreated = time(); $blocked->id = $DB->insert_record('message_users_blocked', $blocked); // Trigger event for blocking a contact. $event = \core\event\message_user_blocked::create(array( 'objectid' => $blocked->id, 'userid' => $userid, 'relateduserid' => $usertoblockid, 'context' => \context_user::instance($userid) )); $event->add_record_snapshot('message_users_blocked', $blocked); $event->trigger(); }
php
public static function block_user(int $userid, int $usertoblockid) { global $DB; $blocked = new \stdClass(); $blocked->userid = $userid; $blocked->blockeduserid = $usertoblockid; $blocked->timecreated = time(); $blocked->id = $DB->insert_record('message_users_blocked', $blocked); // Trigger event for blocking a contact. $event = \core\event\message_user_blocked::create(array( 'objectid' => $blocked->id, 'userid' => $userid, 'relateduserid' => $usertoblockid, 'context' => \context_user::instance($userid) )); $event->add_record_snapshot('message_users_blocked', $blocked); $event->trigger(); }
[ "public", "static", "function", "block_user", "(", "int", "$", "userid", ",", "int", "$", "usertoblockid", ")", "{", "global", "$", "DB", ";", "$", "blocked", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "blocked", "->", "userid", "=", "$", "userid", ";", "$", "blocked", "->", "blockeduserid", "=", "$", "usertoblockid", ";", "$", "blocked", "->", "timecreated", "=", "time", "(", ")", ";", "$", "blocked", "->", "id", "=", "$", "DB", "->", "insert_record", "(", "'message_users_blocked'", ",", "$", "blocked", ")", ";", "// Trigger event for blocking a contact.", "$", "event", "=", "\\", "core", "\\", "event", "\\", "message_user_blocked", "::", "create", "(", "array", "(", "'objectid'", "=>", "$", "blocked", "->", "id", ",", "'userid'", "=>", "$", "userid", ",", "'relateduserid'", "=>", "$", "usertoblockid", ",", "'context'", "=>", "\\", "context_user", "::", "instance", "(", "$", "userid", ")", ")", ")", ";", "$", "event", "->", "add_record_snapshot", "(", "'message_users_blocked'", ",", "$", "blocked", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "}" ]
Handles blocking a user. @param int $userid The id of the user who is blocking @param int $usertoblockid The id of the user being blocked
[ "Handles", "blocking", "a", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L2780-L2798
213,373
moodle/moodle
message/classes/api.php
api.unblock_user
public static function unblock_user(int $userid, int $usertounblockid) { global $DB; if ($blockeduser = $DB->get_record('message_users_blocked', ['userid' => $userid, 'blockeduserid' => $usertounblockid])) { $DB->delete_records('message_users_blocked', ['id' => $blockeduser->id]); // Trigger event for unblocking a contact. $event = \core\event\message_user_unblocked::create(array( 'objectid' => $blockeduser->id, 'userid' => $userid, 'relateduserid' => $usertounblockid, 'context' => \context_user::instance($userid) )); $event->add_record_snapshot('message_users_blocked', $blockeduser); $event->trigger(); } }
php
public static function unblock_user(int $userid, int $usertounblockid) { global $DB; if ($blockeduser = $DB->get_record('message_users_blocked', ['userid' => $userid, 'blockeduserid' => $usertounblockid])) { $DB->delete_records('message_users_blocked', ['id' => $blockeduser->id]); // Trigger event for unblocking a contact. $event = \core\event\message_user_unblocked::create(array( 'objectid' => $blockeduser->id, 'userid' => $userid, 'relateduserid' => $usertounblockid, 'context' => \context_user::instance($userid) )); $event->add_record_snapshot('message_users_blocked', $blockeduser); $event->trigger(); } }
[ "public", "static", "function", "unblock_user", "(", "int", "$", "userid", ",", "int", "$", "usertounblockid", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "blockeduser", "=", "$", "DB", "->", "get_record", "(", "'message_users_blocked'", ",", "[", "'userid'", "=>", "$", "userid", ",", "'blockeduserid'", "=>", "$", "usertounblockid", "]", ")", ")", "{", "$", "DB", "->", "delete_records", "(", "'message_users_blocked'", ",", "[", "'id'", "=>", "$", "blockeduser", "->", "id", "]", ")", ";", "// Trigger event for unblocking a contact.", "$", "event", "=", "\\", "core", "\\", "event", "\\", "message_user_unblocked", "::", "create", "(", "array", "(", "'objectid'", "=>", "$", "blockeduser", "->", "id", ",", "'userid'", "=>", "$", "userid", ",", "'relateduserid'", "=>", "$", "usertounblockid", ",", "'context'", "=>", "\\", "context_user", "::", "instance", "(", "$", "userid", ")", ")", ")", ";", "$", "event", "->", "add_record_snapshot", "(", "'message_users_blocked'", ",", "$", "blockeduser", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "}", "}" ]
Handles unblocking a user. @param int $userid The id of the user who is unblocking @param int $usertounblockid The id of the user being unblocked
[ "Handles", "unblocking", "a", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L2806-L2823
213,374
moodle/moodle
message/classes/api.php
api.is_contact
public static function is_contact(int $userid, int $contactid) : bool { global $DB; $sql = "SELECT id FROM {message_contacts} mc WHERE (mc.userid = ? AND mc.contactid = ?) OR (mc.userid = ? AND mc.contactid = ?)"; return $DB->record_exists_sql($sql, [$userid, $contactid, $contactid, $userid]); }
php
public static function is_contact(int $userid, int $contactid) : bool { global $DB; $sql = "SELECT id FROM {message_contacts} mc WHERE (mc.userid = ? AND mc.contactid = ?) OR (mc.userid = ? AND mc.contactid = ?)"; return $DB->record_exists_sql($sql, [$userid, $contactid, $contactid, $userid]); }
[ "public", "static", "function", "is_contact", "(", "int", "$", "userid", ",", "int", "$", "contactid", ")", ":", "bool", "{", "global", "$", "DB", ";", "$", "sql", "=", "\"SELECT id\n FROM {message_contacts} mc\n WHERE (mc.userid = ? AND mc.contactid = ?)\n OR (mc.userid = ? AND mc.contactid = ?)\"", ";", "return", "$", "DB", "->", "record_exists_sql", "(", "$", "sql", ",", "[", "$", "userid", ",", "$", "contactid", ",", "$", "contactid", ",", "$", "userid", "]", ")", ";", "}" ]
Checks if users are already contacts. @param int $userid The id of one of the users @param int $contactid The id of the other user @return bool Returns true if they are a contact, false otherwise
[ "Checks", "if", "users", "are", "already", "contacts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L2832-L2840
213,375
moodle/moodle
message/classes/api.php
api.get_contact
public static function get_contact(int $userid, int $contactid) { global $DB; $sql = "SELECT mc.* FROM {message_contacts} mc WHERE (mc.userid = ? AND mc.contactid = ?) OR (mc.userid = ? AND mc.contactid = ?)"; return $DB->get_record_sql($sql, [$userid, $contactid, $contactid, $userid]); }
php
public static function get_contact(int $userid, int $contactid) { global $DB; $sql = "SELECT mc.* FROM {message_contacts} mc WHERE (mc.userid = ? AND mc.contactid = ?) OR (mc.userid = ? AND mc.contactid = ?)"; return $DB->get_record_sql($sql, [$userid, $contactid, $contactid, $userid]); }
[ "public", "static", "function", "get_contact", "(", "int", "$", "userid", ",", "int", "$", "contactid", ")", "{", "global", "$", "DB", ";", "$", "sql", "=", "\"SELECT mc.*\n FROM {message_contacts} mc\n WHERE (mc.userid = ? AND mc.contactid = ?)\n OR (mc.userid = ? AND mc.contactid = ?)\"", ";", "return", "$", "DB", "->", "get_record_sql", "(", "$", "sql", ",", "[", "$", "userid", ",", "$", "contactid", ",", "$", "contactid", ",", "$", "userid", "]", ")", ";", "}" ]
Returns the row in the database table message_contacts that represents the contact between two people. @param int $userid The id of one of the users @param int $contactid The id of the other user @return mixed A fieldset object containing the record, false otherwise
[ "Returns", "the", "row", "in", "the", "database", "table", "message_contacts", "that", "represents", "the", "contact", "between", "two", "people", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L2849-L2857
213,376
moodle/moodle
message/classes/api.php
api.is_blocked
public static function is_blocked(int $userid, int $blockeduserid) : bool { global $DB; return $DB->record_exists('message_users_blocked', ['userid' => $userid, 'blockeduserid' => $blockeduserid]); }
php
public static function is_blocked(int $userid, int $blockeduserid) : bool { global $DB; return $DB->record_exists('message_users_blocked', ['userid' => $userid, 'blockeduserid' => $blockeduserid]); }
[ "public", "static", "function", "is_blocked", "(", "int", "$", "userid", ",", "int", "$", "blockeduserid", ")", ":", "bool", "{", "global", "$", "DB", ";", "return", "$", "DB", "->", "record_exists", "(", "'message_users_blocked'", ",", "[", "'userid'", "=>", "$", "userid", ",", "'blockeduserid'", "=>", "$", "blockeduserid", "]", ")", ";", "}" ]
Checks if a user is already blocked. @param int $userid @param int $blockeduserid @return bool Returns true if they are a blocked, false otherwise
[ "Checks", "if", "a", "user", "is", "already", "blocked", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L2866-L2870
213,377
moodle/moodle
message/classes/api.php
api.get_contact_requests_between_users
public static function get_contact_requests_between_users(int $userid, int $requesteduserid) : array { global $DB; $sql = "SELECT * FROM {message_contact_requests} mcr WHERE (mcr.userid = ? AND mcr.requesteduserid = ?) OR (mcr.userid = ? AND mcr.requesteduserid = ?)"; return $DB->get_records_sql($sql, [$userid, $requesteduserid, $requesteduserid, $userid]); }
php
public static function get_contact_requests_between_users(int $userid, int $requesteduserid) : array { global $DB; $sql = "SELECT * FROM {message_contact_requests} mcr WHERE (mcr.userid = ? AND mcr.requesteduserid = ?) OR (mcr.userid = ? AND mcr.requesteduserid = ?)"; return $DB->get_records_sql($sql, [$userid, $requesteduserid, $requesteduserid, $userid]); }
[ "public", "static", "function", "get_contact_requests_between_users", "(", "int", "$", "userid", ",", "int", "$", "requesteduserid", ")", ":", "array", "{", "global", "$", "DB", ";", "$", "sql", "=", "\"SELECT *\n FROM {message_contact_requests} mcr\n WHERE (mcr.userid = ? AND mcr.requesteduserid = ?)\n OR (mcr.userid = ? AND mcr.requesteduserid = ?)\"", ";", "return", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "[", "$", "userid", ",", "$", "requesteduserid", ",", "$", "requesteduserid", ",", "$", "userid", "]", ")", ";", "}" ]
Get contact requests between users. @param int $userid The id of the user who is creating the contact request @param int $requesteduserid The id of the user being requested @return \stdClass[]
[ "Get", "contact", "requests", "between", "users", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L2879-L2887
213,378
moodle/moodle
message/classes/api.php
api.does_contact_request_exist
public static function does_contact_request_exist(int $userid, int $requesteduserid) : bool { global $DB; $sql = "SELECT id FROM {message_contact_requests} mcr WHERE (mcr.userid = ? AND mcr.requesteduserid = ?) OR (mcr.userid = ? AND mcr.requesteduserid = ?)"; return $DB->record_exists_sql($sql, [$userid, $requesteduserid, $requesteduserid, $userid]); }
php
public static function does_contact_request_exist(int $userid, int $requesteduserid) : bool { global $DB; $sql = "SELECT id FROM {message_contact_requests} mcr WHERE (mcr.userid = ? AND mcr.requesteduserid = ?) OR (mcr.userid = ? AND mcr.requesteduserid = ?)"; return $DB->record_exists_sql($sql, [$userid, $requesteduserid, $requesteduserid, $userid]); }
[ "public", "static", "function", "does_contact_request_exist", "(", "int", "$", "userid", ",", "int", "$", "requesteduserid", ")", ":", "bool", "{", "global", "$", "DB", ";", "$", "sql", "=", "\"SELECT id\n FROM {message_contact_requests} mcr\n WHERE (mcr.userid = ? AND mcr.requesteduserid = ?)\n OR (mcr.userid = ? AND mcr.requesteduserid = ?)\"", ";", "return", "$", "DB", "->", "record_exists_sql", "(", "$", "sql", ",", "[", "$", "userid", ",", "$", "requesteduserid", ",", "$", "requesteduserid", ",", "$", "userid", "]", ")", ";", "}" ]
Checks if a contact request already exists between users. @param int $userid The id of the user who is creating the contact request @param int $requesteduserid The id of the user being requested @return bool Returns true if a contact request exists, false otherwise
[ "Checks", "if", "a", "contact", "request", "already", "exists", "between", "users", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L2896-L2904
213,379
moodle/moodle
message/classes/api.php
api.is_user_in_conversation
public static function is_user_in_conversation(int $userid, int $conversationid) : bool { global $DB; return $DB->record_exists('message_conversation_members', ['conversationid' => $conversationid, 'userid' => $userid]); }
php
public static function is_user_in_conversation(int $userid, int $conversationid) : bool { global $DB; return $DB->record_exists('message_conversation_members', ['conversationid' => $conversationid, 'userid' => $userid]); }
[ "public", "static", "function", "is_user_in_conversation", "(", "int", "$", "userid", ",", "int", "$", "conversationid", ")", ":", "bool", "{", "global", "$", "DB", ";", "return", "$", "DB", "->", "record_exists", "(", "'message_conversation_members'", ",", "[", "'conversationid'", "=>", "$", "conversationid", ",", "'userid'", "=>", "$", "userid", "]", ")", ";", "}" ]
Checks if a user is already in a conversation. @param int $userid The id of the user we want to check if they are in a group @param int $conversationid The id of the conversation @return bool Returns true if a contact request exists, false otherwise
[ "Checks", "if", "a", "user", "is", "already", "in", "a", "conversation", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L2913-L2918
213,380
moodle/moodle
message/classes/api.php
api.can_contact_user
protected static function can_contact_user(int $recipientid, int $senderid) : bool { if (has_capability('moodle/site:messageanyuser', \context_system::instance(), $senderid) || $recipientid == $senderid) { // The sender has the ability to contact any user across the entire site or themselves. return true; } // The initial value of $cancontact is null to indicate that a value has not been determined. $cancontact = null; if (self::is_blocked($recipientid, $senderid)) { // The recipient has specifically blocked this sender. $cancontact = false; } $sharedcourses = null; if (null === $cancontact) { // There are three user preference options: // - Site: Allow anyone not explicitly blocked to contact me; // - Course members: Allow anyone I am in a course with to contact me; and // - Contacts: Only allow my contacts to contact me. // // The Site option is only possible when the messagingallusers site setting is also enabled. $privacypreference = self::get_user_privacy_messaging_preference($recipientid); if (self::MESSAGE_PRIVACY_SITE === $privacypreference) { // The user preference is to allow any user to contact them. // No need to check anything else. $cancontact = true; } else { // This user only allows their own contacts, and possibly course peers, to contact them. // If the users are contacts then we can avoid the more expensive shared courses check. $cancontact = self::is_contact($senderid, $recipientid); if (!$cancontact && self::MESSAGE_PRIVACY_COURSEMEMBER === $privacypreference) { // The users are not contacts and the user allows course member messaging. // Check whether these two users share any course together. $sharedcourses = enrol_get_shared_courses($recipientid, $senderid, true); $cancontact = (!empty($sharedcourses)); } } } if (false === $cancontact) { // At the moment the users cannot contact one another. // Check whether the messageanyuser capability applies in any of the shared courses. // This is intended to allow teachers to message students regardless of message settings. // Note: You cannot use empty($sharedcourses) here because this may be an empty array. if (null === $sharedcourses) { $sharedcourses = enrol_get_shared_courses($recipientid, $senderid, true); } foreach ($sharedcourses as $course) { // Note: enrol_get_shared_courses will preload any shared context. if (has_capability('moodle/site:messageanyuser', \context_course::instance($course->id), $senderid)) { $cancontact = true; break; } } } return $cancontact; }
php
protected static function can_contact_user(int $recipientid, int $senderid) : bool { if (has_capability('moodle/site:messageanyuser', \context_system::instance(), $senderid) || $recipientid == $senderid) { // The sender has the ability to contact any user across the entire site or themselves. return true; } // The initial value of $cancontact is null to indicate that a value has not been determined. $cancontact = null; if (self::is_blocked($recipientid, $senderid)) { // The recipient has specifically blocked this sender. $cancontact = false; } $sharedcourses = null; if (null === $cancontact) { // There are three user preference options: // - Site: Allow anyone not explicitly blocked to contact me; // - Course members: Allow anyone I am in a course with to contact me; and // - Contacts: Only allow my contacts to contact me. // // The Site option is only possible when the messagingallusers site setting is also enabled. $privacypreference = self::get_user_privacy_messaging_preference($recipientid); if (self::MESSAGE_PRIVACY_SITE === $privacypreference) { // The user preference is to allow any user to contact them. // No need to check anything else. $cancontact = true; } else { // This user only allows their own contacts, and possibly course peers, to contact them. // If the users are contacts then we can avoid the more expensive shared courses check. $cancontact = self::is_contact($senderid, $recipientid); if (!$cancontact && self::MESSAGE_PRIVACY_COURSEMEMBER === $privacypreference) { // The users are not contacts and the user allows course member messaging. // Check whether these two users share any course together. $sharedcourses = enrol_get_shared_courses($recipientid, $senderid, true); $cancontact = (!empty($sharedcourses)); } } } if (false === $cancontact) { // At the moment the users cannot contact one another. // Check whether the messageanyuser capability applies in any of the shared courses. // This is intended to allow teachers to message students regardless of message settings. // Note: You cannot use empty($sharedcourses) here because this may be an empty array. if (null === $sharedcourses) { $sharedcourses = enrol_get_shared_courses($recipientid, $senderid, true); } foreach ($sharedcourses as $course) { // Note: enrol_get_shared_courses will preload any shared context. if (has_capability('moodle/site:messageanyuser', \context_course::instance($course->id), $senderid)) { $cancontact = true; break; } } } return $cancontact; }
[ "protected", "static", "function", "can_contact_user", "(", "int", "$", "recipientid", ",", "int", "$", "senderid", ")", ":", "bool", "{", "if", "(", "has_capability", "(", "'moodle/site:messageanyuser'", ",", "\\", "context_system", "::", "instance", "(", ")", ",", "$", "senderid", ")", "||", "$", "recipientid", "==", "$", "senderid", ")", "{", "// The sender has the ability to contact any user across the entire site or themselves.", "return", "true", ";", "}", "// The initial value of $cancontact is null to indicate that a value has not been determined.", "$", "cancontact", "=", "null", ";", "if", "(", "self", "::", "is_blocked", "(", "$", "recipientid", ",", "$", "senderid", ")", ")", "{", "// The recipient has specifically blocked this sender.", "$", "cancontact", "=", "false", ";", "}", "$", "sharedcourses", "=", "null", ";", "if", "(", "null", "===", "$", "cancontact", ")", "{", "// There are three user preference options:", "// - Site: Allow anyone not explicitly blocked to contact me;", "// - Course members: Allow anyone I am in a course with to contact me; and", "// - Contacts: Only allow my contacts to contact me.", "//", "// The Site option is only possible when the messagingallusers site setting is also enabled.", "$", "privacypreference", "=", "self", "::", "get_user_privacy_messaging_preference", "(", "$", "recipientid", ")", ";", "if", "(", "self", "::", "MESSAGE_PRIVACY_SITE", "===", "$", "privacypreference", ")", "{", "// The user preference is to allow any user to contact them.", "// No need to check anything else.", "$", "cancontact", "=", "true", ";", "}", "else", "{", "// This user only allows their own contacts, and possibly course peers, to contact them.", "// If the users are contacts then we can avoid the more expensive shared courses check.", "$", "cancontact", "=", "self", "::", "is_contact", "(", "$", "senderid", ",", "$", "recipientid", ")", ";", "if", "(", "!", "$", "cancontact", "&&", "self", "::", "MESSAGE_PRIVACY_COURSEMEMBER", "===", "$", "privacypreference", ")", "{", "// The users are not contacts and the user allows course member messaging.", "// Check whether these two users share any course together.", "$", "sharedcourses", "=", "enrol_get_shared_courses", "(", "$", "recipientid", ",", "$", "senderid", ",", "true", ")", ";", "$", "cancontact", "=", "(", "!", "empty", "(", "$", "sharedcourses", ")", ")", ";", "}", "}", "}", "if", "(", "false", "===", "$", "cancontact", ")", "{", "// At the moment the users cannot contact one another.", "// Check whether the messageanyuser capability applies in any of the shared courses.", "// This is intended to allow teachers to message students regardless of message settings.", "// Note: You cannot use empty($sharedcourses) here because this may be an empty array.", "if", "(", "null", "===", "$", "sharedcourses", ")", "{", "$", "sharedcourses", "=", "enrol_get_shared_courses", "(", "$", "recipientid", ",", "$", "senderid", ",", "true", ")", ";", "}", "foreach", "(", "$", "sharedcourses", "as", "$", "course", ")", "{", "// Note: enrol_get_shared_courses will preload any shared context.", "if", "(", "has_capability", "(", "'moodle/site:messageanyuser'", ",", "\\", "context_course", "::", "instance", "(", "$", "course", "->", "id", ")", ",", "$", "senderid", ")", ")", "{", "$", "cancontact", "=", "true", ";", "break", ";", "}", "}", "}", "return", "$", "cancontact", ";", "}" ]
Checks if the sender can message the recipient. @param int $recipientid @param int $senderid @return bool true if recipient hasn't blocked sender and sender can contact to recipient, false otherwise.
[ "Checks", "if", "the", "sender", "can", "message", "the", "recipient", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L2927-L2990
213,381
moodle/moodle
message/classes/api.php
api.add_members_to_conversation
public static function add_members_to_conversation(array $userids, int $convid) { global $DB; $conversation = $DB->get_record('message_conversations', ['id' => $convid], '*', MUST_EXIST); // We can only add members to a group conversation. if ($conversation->type != self::MESSAGE_CONVERSATION_TYPE_GROUP) { throw new \moodle_exception('You can not add members to a non-group conversation.'); } // Be sure we are not trying to add a non existing user to the conversation. Work only with existing users. list($useridcondition, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED); $existingusers = $DB->get_fieldset_select('user', 'id', "id $useridcondition", $params); // Be sure we are not adding a user is already member of the conversation. Take all the members. $memberuserids = array_values($DB->get_records_menu( 'message_conversation_members', ['conversationid' => $convid], 'id', 'id, userid') ); // Work with existing new members. $members = array(); $newuserids = array_diff($existingusers, $memberuserids); foreach ($newuserids as $userid) { $member = new \stdClass(); $member->conversationid = $convid; $member->userid = $userid; $member->timecreated = time(); $members[] = $member; } $DB->insert_records('message_conversation_members', $members); }
php
public static function add_members_to_conversation(array $userids, int $convid) { global $DB; $conversation = $DB->get_record('message_conversations', ['id' => $convid], '*', MUST_EXIST); // We can only add members to a group conversation. if ($conversation->type != self::MESSAGE_CONVERSATION_TYPE_GROUP) { throw new \moodle_exception('You can not add members to a non-group conversation.'); } // Be sure we are not trying to add a non existing user to the conversation. Work only with existing users. list($useridcondition, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED); $existingusers = $DB->get_fieldset_select('user', 'id', "id $useridcondition", $params); // Be sure we are not adding a user is already member of the conversation. Take all the members. $memberuserids = array_values($DB->get_records_menu( 'message_conversation_members', ['conversationid' => $convid], 'id', 'id, userid') ); // Work with existing new members. $members = array(); $newuserids = array_diff($existingusers, $memberuserids); foreach ($newuserids as $userid) { $member = new \stdClass(); $member->conversationid = $convid; $member->userid = $userid; $member->timecreated = time(); $members[] = $member; } $DB->insert_records('message_conversation_members', $members); }
[ "public", "static", "function", "add_members_to_conversation", "(", "array", "$", "userids", ",", "int", "$", "convid", ")", "{", "global", "$", "DB", ";", "$", "conversation", "=", "$", "DB", "->", "get_record", "(", "'message_conversations'", ",", "[", "'id'", "=>", "$", "convid", "]", ",", "'*'", ",", "MUST_EXIST", ")", ";", "// We can only add members to a group conversation.", "if", "(", "$", "conversation", "->", "type", "!=", "self", "::", "MESSAGE_CONVERSATION_TYPE_GROUP", ")", "{", "throw", "new", "\\", "moodle_exception", "(", "'You can not add members to a non-group conversation.'", ")", ";", "}", "// Be sure we are not trying to add a non existing user to the conversation. Work only with existing users.", "list", "(", "$", "useridcondition", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "userids", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "existingusers", "=", "$", "DB", "->", "get_fieldset_select", "(", "'user'", ",", "'id'", ",", "\"id $useridcondition\"", ",", "$", "params", ")", ";", "// Be sure we are not adding a user is already member of the conversation. Take all the members.", "$", "memberuserids", "=", "array_values", "(", "$", "DB", "->", "get_records_menu", "(", "'message_conversation_members'", ",", "[", "'conversationid'", "=>", "$", "convid", "]", ",", "'id'", ",", "'id, userid'", ")", ")", ";", "// Work with existing new members.", "$", "members", "=", "array", "(", ")", ";", "$", "newuserids", "=", "array_diff", "(", "$", "existingusers", ",", "$", "memberuserids", ")", ";", "foreach", "(", "$", "newuserids", "as", "$", "userid", ")", "{", "$", "member", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "member", "->", "conversationid", "=", "$", "convid", ";", "$", "member", "->", "userid", "=", "$", "userid", ";", "$", "member", "->", "timecreated", "=", "time", "(", ")", ";", "$", "members", "[", "]", "=", "$", "member", ";", "}", "$", "DB", "->", "insert_records", "(", "'message_conversation_members'", ",", "$", "members", ")", ";", "}" ]
Add some new members to an existing conversation. @param array $userids User ids array to add as members. @param int $convid The conversation id. Must exists. @throws \dml_missing_record_exception If convid conversation doesn't exist @throws \dml_exception If there is a database error @throws \moodle_exception If trying to add a member(s) to a non-group conversation
[ "Add", "some", "new", "members", "to", "an", "existing", "conversation", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L3001-L3032
213,382
moodle/moodle
message/classes/api.php
api.remove_members_from_conversation
public static function remove_members_from_conversation(array $userids, int $convid) { global $DB; $conversation = $DB->get_record('message_conversations', ['id' => $convid], '*', MUST_EXIST); if ($conversation->type != self::MESSAGE_CONVERSATION_TYPE_GROUP) { throw new \moodle_exception('You can not remove members from a non-group conversation.'); } list($useridcondition, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED); $params['convid'] = $convid; $DB->delete_records_select('message_conversation_members', "conversationid = :convid AND userid $useridcondition", $params); }
php
public static function remove_members_from_conversation(array $userids, int $convid) { global $DB; $conversation = $DB->get_record('message_conversations', ['id' => $convid], '*', MUST_EXIST); if ($conversation->type != self::MESSAGE_CONVERSATION_TYPE_GROUP) { throw new \moodle_exception('You can not remove members from a non-group conversation.'); } list($useridcondition, $params) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED); $params['convid'] = $convid; $DB->delete_records_select('message_conversation_members', "conversationid = :convid AND userid $useridcondition", $params); }
[ "public", "static", "function", "remove_members_from_conversation", "(", "array", "$", "userids", ",", "int", "$", "convid", ")", "{", "global", "$", "DB", ";", "$", "conversation", "=", "$", "DB", "->", "get_record", "(", "'message_conversations'", ",", "[", "'id'", "=>", "$", "convid", "]", ",", "'*'", ",", "MUST_EXIST", ")", ";", "if", "(", "$", "conversation", "->", "type", "!=", "self", "::", "MESSAGE_CONVERSATION_TYPE_GROUP", ")", "{", "throw", "new", "\\", "moodle_exception", "(", "'You can not remove members from a non-group conversation.'", ")", ";", "}", "list", "(", "$", "useridcondition", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "userids", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "params", "[", "'convid'", "]", "=", "$", "convid", ";", "$", "DB", "->", "delete_records_select", "(", "'message_conversation_members'", ",", "\"conversationid = :convid AND userid $useridcondition\"", ",", "$", "params", ")", ";", "}" ]
Remove some members from an existing conversation. @param array $userids The user ids to remove from conversation members. @param int $convid The conversation id. Must exists. @throws \dml_exception @throws \moodle_exception If trying to remove a member(s) from a non-group conversation
[ "Remove", "some", "members", "from", "an", "existing", "conversation", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L3042-L3056
213,383
moodle/moodle
message/classes/api.php
api.is_conversation_area_enabled
public static function is_conversation_area_enabled(string $component, string $itemtype, int $itemid, int $contextid) : bool { global $DB; return $DB->record_exists('message_conversations', [ 'itemid' => $itemid, 'contextid' => $contextid, 'component' => $component, 'itemtype' => $itemtype, 'enabled' => self::MESSAGE_CONVERSATION_ENABLED ] ); }
php
public static function is_conversation_area_enabled(string $component, string $itemtype, int $itemid, int $contextid) : bool { global $DB; return $DB->record_exists('message_conversations', [ 'itemid' => $itemid, 'contextid' => $contextid, 'component' => $component, 'itemtype' => $itemtype, 'enabled' => self::MESSAGE_CONVERSATION_ENABLED ] ); }
[ "public", "static", "function", "is_conversation_area_enabled", "(", "string", "$", "component", ",", "string", "$", "itemtype", ",", "int", "$", "itemid", ",", "int", "$", "contextid", ")", ":", "bool", "{", "global", "$", "DB", ";", "return", "$", "DB", "->", "record_exists", "(", "'message_conversations'", ",", "[", "'itemid'", "=>", "$", "itemid", ",", "'contextid'", "=>", "$", "contextid", ",", "'component'", "=>", "$", "component", ",", "'itemtype'", "=>", "$", "itemtype", ",", "'enabled'", "=>", "self", "::", "MESSAGE_CONVERSATION_ENABLED", "]", ")", ";", "}" ]
Checks whether or not a conversation area is enabled. @param string $component Defines the Moodle component which the area was added to. @param string $itemtype Defines the type of the component. @param int $itemid The id of the component. @param int $contextid The id of the context. @return bool Returns if a conversation area exists and is enabled, false otherwise
[ "Checks", "whether", "or", "not", "a", "conversation", "area", "is", "enabled", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L3080-L3092
213,384
moodle/moodle
message/classes/api.php
api.get_conversation_by_area
public static function get_conversation_by_area(string $component, string $itemtype, int $itemid, int $contextid) { global $DB; return $DB->get_record('message_conversations', [ 'itemid' => $itemid, 'contextid' => $contextid, 'component' => $component, 'itemtype' => $itemtype ] ); }
php
public static function get_conversation_by_area(string $component, string $itemtype, int $itemid, int $contextid) { global $DB; return $DB->get_record('message_conversations', [ 'itemid' => $itemid, 'contextid' => $contextid, 'component' => $component, 'itemtype' => $itemtype ] ); }
[ "public", "static", "function", "get_conversation_by_area", "(", "string", "$", "component", ",", "string", "$", "itemtype", ",", "int", "$", "itemid", ",", "int", "$", "contextid", ")", "{", "global", "$", "DB", ";", "return", "$", "DB", "->", "get_record", "(", "'message_conversations'", ",", "[", "'itemid'", "=>", "$", "itemid", ",", "'contextid'", "=>", "$", "contextid", ",", "'component'", "=>", "$", "component", ",", "'itemtype'", "=>", "$", "itemtype", "]", ")", ";", "}" ]
Get conversation by area. @param string $component Defines the Moodle component which the area was added to. @param string $itemtype Defines the type of the component. @param int $itemid The id of the component. @param int $contextid The id of the context. @return \stdClass
[ "Get", "conversation", "by", "area", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L3103-L3114
213,385
moodle/moodle
message/classes/api.php
api.enable_conversation
public static function enable_conversation(int $conversationid) { global $DB; $conversation = new \stdClass(); $conversation->id = $conversationid; $conversation->enabled = self::MESSAGE_CONVERSATION_ENABLED; $conversation->timemodified = time(); $DB->update_record('message_conversations', $conversation); }
php
public static function enable_conversation(int $conversationid) { global $DB; $conversation = new \stdClass(); $conversation->id = $conversationid; $conversation->enabled = self::MESSAGE_CONVERSATION_ENABLED; $conversation->timemodified = time(); $DB->update_record('message_conversations', $conversation); }
[ "public", "static", "function", "enable_conversation", "(", "int", "$", "conversationid", ")", "{", "global", "$", "DB", ";", "$", "conversation", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "conversation", "->", "id", "=", "$", "conversationid", ";", "$", "conversation", "->", "enabled", "=", "self", "::", "MESSAGE_CONVERSATION_ENABLED", ";", "$", "conversation", "->", "timemodified", "=", "time", "(", ")", ";", "$", "DB", "->", "update_record", "(", "'message_conversations'", ",", "$", "conversation", ")", ";", "}" ]
Enable a conversation. @param int $conversationid The id of the conversation. @return void
[ "Enable", "a", "conversation", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L3122-L3130
213,386
moodle/moodle
message/classes/api.php
api.disable_conversation
public static function disable_conversation(int $conversationid) { global $DB; $conversation = new \stdClass(); $conversation->id = $conversationid; $conversation->enabled = self::MESSAGE_CONVERSATION_DISABLED; $conversation->timemodified = time(); $DB->update_record('message_conversations', $conversation); }
php
public static function disable_conversation(int $conversationid) { global $DB; $conversation = new \stdClass(); $conversation->id = $conversationid; $conversation->enabled = self::MESSAGE_CONVERSATION_DISABLED; $conversation->timemodified = time(); $DB->update_record('message_conversations', $conversation); }
[ "public", "static", "function", "disable_conversation", "(", "int", "$", "conversationid", ")", "{", "global", "$", "DB", ";", "$", "conversation", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "conversation", "->", "id", "=", "$", "conversationid", ";", "$", "conversation", "->", "enabled", "=", "self", "::", "MESSAGE_CONVERSATION_DISABLED", ";", "$", "conversation", "->", "timemodified", "=", "time", "(", ")", ";", "$", "DB", "->", "update_record", "(", "'message_conversations'", ",", "$", "conversation", ")", ";", "}" ]
Disable a conversation. @param int $conversationid The id of the conversation. @return void
[ "Disable", "a", "conversation", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L3138-L3146
213,387
moodle/moodle
message/classes/api.php
api.update_conversation_name
public static function update_conversation_name(int $conversationid, string $name) { global $DB; if ($conversation = $DB->get_record('message_conversations', array('id' => $conversationid))) { if ($name <> $conversation->name) { $conversation->name = $name; $conversation->timemodified = time(); $DB->update_record('message_conversations', $conversation); } } }
php
public static function update_conversation_name(int $conversationid, string $name) { global $DB; if ($conversation = $DB->get_record('message_conversations', array('id' => $conversationid))) { if ($name <> $conversation->name) { $conversation->name = $name; $conversation->timemodified = time(); $DB->update_record('message_conversations', $conversation); } } }
[ "public", "static", "function", "update_conversation_name", "(", "int", "$", "conversationid", ",", "string", "$", "name", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "conversation", "=", "$", "DB", "->", "get_record", "(", "'message_conversations'", ",", "array", "(", "'id'", "=>", "$", "conversationid", ")", ")", ")", "{", "if", "(", "$", "name", "<>", "$", "conversation", "->", "name", ")", "{", "$", "conversation", "->", "name", "=", "$", "name", ";", "$", "conversation", "->", "timemodified", "=", "time", "(", ")", ";", "$", "DB", "->", "update_record", "(", "'message_conversations'", ",", "$", "conversation", ")", ";", "}", "}", "}" ]
Update the name of a conversation. @param int $conversationid The id of a conversation. @param string $name The main name of the area @return void
[ "Update", "the", "name", "of", "a", "conversation", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L3155-L3165
213,388
moodle/moodle
message/classes/api.php
api.get_unread_conversation_counts
public static function get_unread_conversation_counts(int $userid) : array { global $DB; // Get all conversations the user is in, and check unread. $unreadcountssql = 'SELECT conv.id, conv.type, indcounts.unreadcount FROM {message_conversations} conv INNER JOIN ( SELECT m.conversationid, count(m.id) as unreadcount FROM {messages} m INNER JOIN {message_conversations} mc ON mc.id = m.conversationid INNER JOIN {message_conversation_members} mcm ON m.conversationid = mcm.conversationid LEFT JOIN {message_user_actions} mua ON (mua.messageid = m.id AND mua.userid = ? AND (mua.action = ? OR mua.action = ?)) WHERE mcm.userid = ? AND m.useridfrom != ? AND mua.id is NULL GROUP BY m.conversationid ) indcounts ON indcounts.conversationid = conv.id WHERE conv.enabled = 1'; $unreadcounts = $DB->get_records_sql($unreadcountssql, [$userid, self::MESSAGE_ACTION_READ, self::MESSAGE_ACTION_DELETED, $userid, $userid]); // Get favourites, so we can track these separately. $service = \core_favourites\service_factory::get_service_for_user_context(\context_user::instance($userid)); $favouriteconversations = $service->find_favourites_by_type('core_message', 'message_conversations'); $favouriteconvids = array_flip(array_column($favouriteconversations, 'itemid')); // Assemble the return array. $counts = ['favourites' => 0, 'types' => [ self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL => 0, self::MESSAGE_CONVERSATION_TYPE_GROUP => 0, self::MESSAGE_CONVERSATION_TYPE_SELF => 0 ]]; foreach ($unreadcounts as $convid => $info) { if (isset($favouriteconvids[$convid])) { $counts['favourites']++; continue; } $counts['types'][$info->type]++; } return $counts; }
php
public static function get_unread_conversation_counts(int $userid) : array { global $DB; // Get all conversations the user is in, and check unread. $unreadcountssql = 'SELECT conv.id, conv.type, indcounts.unreadcount FROM {message_conversations} conv INNER JOIN ( SELECT m.conversationid, count(m.id) as unreadcount FROM {messages} m INNER JOIN {message_conversations} mc ON mc.id = m.conversationid INNER JOIN {message_conversation_members} mcm ON m.conversationid = mcm.conversationid LEFT JOIN {message_user_actions} mua ON (mua.messageid = m.id AND mua.userid = ? AND (mua.action = ? OR mua.action = ?)) WHERE mcm.userid = ? AND m.useridfrom != ? AND mua.id is NULL GROUP BY m.conversationid ) indcounts ON indcounts.conversationid = conv.id WHERE conv.enabled = 1'; $unreadcounts = $DB->get_records_sql($unreadcountssql, [$userid, self::MESSAGE_ACTION_READ, self::MESSAGE_ACTION_DELETED, $userid, $userid]); // Get favourites, so we can track these separately. $service = \core_favourites\service_factory::get_service_for_user_context(\context_user::instance($userid)); $favouriteconversations = $service->find_favourites_by_type('core_message', 'message_conversations'); $favouriteconvids = array_flip(array_column($favouriteconversations, 'itemid')); // Assemble the return array. $counts = ['favourites' => 0, 'types' => [ self::MESSAGE_CONVERSATION_TYPE_INDIVIDUAL => 0, self::MESSAGE_CONVERSATION_TYPE_GROUP => 0, self::MESSAGE_CONVERSATION_TYPE_SELF => 0 ]]; foreach ($unreadcounts as $convid => $info) { if (isset($favouriteconvids[$convid])) { $counts['favourites']++; continue; } $counts['types'][$info->type]++; } return $counts; }
[ "public", "static", "function", "get_unread_conversation_counts", "(", "int", "$", "userid", ")", ":", "array", "{", "global", "$", "DB", ";", "// Get all conversations the user is in, and check unread.", "$", "unreadcountssql", "=", "'SELECT conv.id, conv.type, indcounts.unreadcount\n FROM {message_conversations} conv\n INNER JOIN (\n SELECT m.conversationid, count(m.id) as unreadcount\n FROM {messages} m\n INNER JOIN {message_conversations} mc\n ON mc.id = m.conversationid\n INNER JOIN {message_conversation_members} mcm\n ON m.conversationid = mcm.conversationid\n LEFT JOIN {message_user_actions} mua\n ON (mua.messageid = m.id AND mua.userid = ? AND\n (mua.action = ? OR mua.action = ?))\n WHERE mcm.userid = ?\n AND m.useridfrom != ?\n AND mua.id is NULL\n GROUP BY m.conversationid\n ) indcounts\n ON indcounts.conversationid = conv.id\n WHERE conv.enabled = 1'", ";", "$", "unreadcounts", "=", "$", "DB", "->", "get_records_sql", "(", "$", "unreadcountssql", ",", "[", "$", "userid", ",", "self", "::", "MESSAGE_ACTION_READ", ",", "self", "::", "MESSAGE_ACTION_DELETED", ",", "$", "userid", ",", "$", "userid", "]", ")", ";", "// Get favourites, so we can track these separately.", "$", "service", "=", "\\", "core_favourites", "\\", "service_factory", "::", "get_service_for_user_context", "(", "\\", "context_user", "::", "instance", "(", "$", "userid", ")", ")", ";", "$", "favouriteconversations", "=", "$", "service", "->", "find_favourites_by_type", "(", "'core_message'", ",", "'message_conversations'", ")", ";", "$", "favouriteconvids", "=", "array_flip", "(", "array_column", "(", "$", "favouriteconversations", ",", "'itemid'", ")", ")", ";", "// Assemble the return array.", "$", "counts", "=", "[", "'favourites'", "=>", "0", ",", "'types'", "=>", "[", "self", "::", "MESSAGE_CONVERSATION_TYPE_INDIVIDUAL", "=>", "0", ",", "self", "::", "MESSAGE_CONVERSATION_TYPE_GROUP", "=>", "0", ",", "self", "::", "MESSAGE_CONVERSATION_TYPE_SELF", "=>", "0", "]", "]", ";", "foreach", "(", "$", "unreadcounts", "as", "$", "convid", "=>", "$", "info", ")", "{", "if", "(", "isset", "(", "$", "favouriteconvids", "[", "$", "convid", "]", ")", ")", "{", "$", "counts", "[", "'favourites'", "]", "++", ";", "continue", ";", "}", "$", "counts", "[", "'types'", "]", "[", "$", "info", "->", "type", "]", "++", ";", "}", "return", "$", "counts", ";", "}" ]
Get the unread counts for all conversations for the user, sorted by type, and including favourites. @param int $userid the id of the user whose conversations we'll check. @return array the unread counts for each conversation, indexed by type.
[ "Get", "the", "unread", "counts", "for", "all", "conversations", "for", "the", "user", "sorted", "by", "type", "and", "including", "favourites", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L3200-L3247
213,389
moodle/moodle
message/classes/api.php
api.mute_conversation
public static function mute_conversation(int $userid, int $conversationid) : void { global $DB; $mutedconversation = new \stdClass(); $mutedconversation->userid = $userid; $mutedconversation->conversationid = $conversationid; $mutedconversation->action = self::CONVERSATION_ACTION_MUTED; $mutedconversation->timecreated = time(); $DB->insert_record('message_conversation_actions', $mutedconversation); }
php
public static function mute_conversation(int $userid, int $conversationid) : void { global $DB; $mutedconversation = new \stdClass(); $mutedconversation->userid = $userid; $mutedconversation->conversationid = $conversationid; $mutedconversation->action = self::CONVERSATION_ACTION_MUTED; $mutedconversation->timecreated = time(); $DB->insert_record('message_conversation_actions', $mutedconversation); }
[ "public", "static", "function", "mute_conversation", "(", "int", "$", "userid", ",", "int", "$", "conversationid", ")", ":", "void", "{", "global", "$", "DB", ";", "$", "mutedconversation", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "mutedconversation", "->", "userid", "=", "$", "userid", ";", "$", "mutedconversation", "->", "conversationid", "=", "$", "conversationid", ";", "$", "mutedconversation", "->", "action", "=", "self", "::", "CONVERSATION_ACTION_MUTED", ";", "$", "mutedconversation", "->", "timecreated", "=", "time", "(", ")", ";", "$", "DB", "->", "insert_record", "(", "'message_conversation_actions'", ",", "$", "mutedconversation", ")", ";", "}" ]
Handles muting a conversation. @param int $userid The id of the user @param int $conversationid The id of the conversation
[ "Handles", "muting", "a", "conversation", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L3255-L3265
213,390
moodle/moodle
message/classes/api.php
api.unmute_conversation
public static function unmute_conversation(int $userid, int $conversationid) : void { global $DB; $DB->delete_records('message_conversation_actions', [ 'userid' => $userid, 'conversationid' => $conversationid, 'action' => self::CONVERSATION_ACTION_MUTED ] ); }
php
public static function unmute_conversation(int $userid, int $conversationid) : void { global $DB; $DB->delete_records('message_conversation_actions', [ 'userid' => $userid, 'conversationid' => $conversationid, 'action' => self::CONVERSATION_ACTION_MUTED ] ); }
[ "public", "static", "function", "unmute_conversation", "(", "int", "$", "userid", ",", "int", "$", "conversationid", ")", ":", "void", "{", "global", "$", "DB", ";", "$", "DB", "->", "delete_records", "(", "'message_conversation_actions'", ",", "[", "'userid'", "=>", "$", "userid", ",", "'conversationid'", "=>", "$", "conversationid", ",", "'action'", "=>", "self", "::", "CONVERSATION_ACTION_MUTED", "]", ")", ";", "}" ]
Handles unmuting a conversation. @param int $userid The id of the user @param int $conversationid The id of the conversation
[ "Handles", "unmuting", "a", "conversation", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L3273-L3283
213,391
moodle/moodle
message/classes/api.php
api.is_conversation_muted
public static function is_conversation_muted(int $userid, int $conversationid) : bool { global $DB; return $DB->record_exists('message_conversation_actions', [ 'userid' => $userid, 'conversationid' => $conversationid, 'action' => self::CONVERSATION_ACTION_MUTED ] ); }
php
public static function is_conversation_muted(int $userid, int $conversationid) : bool { global $DB; return $DB->record_exists('message_conversation_actions', [ 'userid' => $userid, 'conversationid' => $conversationid, 'action' => self::CONVERSATION_ACTION_MUTED ] ); }
[ "public", "static", "function", "is_conversation_muted", "(", "int", "$", "userid", ",", "int", "$", "conversationid", ")", ":", "bool", "{", "global", "$", "DB", ";", "return", "$", "DB", "->", "record_exists", "(", "'message_conversation_actions'", ",", "[", "'userid'", "=>", "$", "userid", ",", "'conversationid'", "=>", "$", "conversationid", ",", "'action'", "=>", "self", "::", "CONVERSATION_ACTION_MUTED", "]", ")", ";", "}" ]
Checks whether a conversation is muted or not. @param int $userid The id of the user @param int $conversationid The id of the conversation @return bool Whether or not the conversation is muted or not
[ "Checks", "whether", "a", "conversation", "is", "muted", "or", "not", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L3292-L3302
213,392
moodle/moodle
message/classes/api.php
api.delete_all_conversation_data
public static function delete_all_conversation_data(int $conversationid) { global $DB; $DB->delete_records('message_conversations', ['id' => $conversationid]); $DB->delete_records('message_conversation_members', ['conversationid' => $conversationid]); $DB->delete_records('message_conversation_actions', ['conversationid' => $conversationid]); // Now, go through and delete any messages and related message actions for the conversation. if ($messages = $DB->get_records('messages', ['conversationid' => $conversationid])) { $messageids = array_keys($messages); list($insql, $inparams) = $DB->get_in_or_equal($messageids); $DB->delete_records_select('message_user_actions', "messageid $insql", $inparams); // Delete the messages now. $DB->delete_records('messages', ['conversationid' => $conversationid]); } }
php
public static function delete_all_conversation_data(int $conversationid) { global $DB; $DB->delete_records('message_conversations', ['id' => $conversationid]); $DB->delete_records('message_conversation_members', ['conversationid' => $conversationid]); $DB->delete_records('message_conversation_actions', ['conversationid' => $conversationid]); // Now, go through and delete any messages and related message actions for the conversation. if ($messages = $DB->get_records('messages', ['conversationid' => $conversationid])) { $messageids = array_keys($messages); list($insql, $inparams) = $DB->get_in_or_equal($messageids); $DB->delete_records_select('message_user_actions', "messageid $insql", $inparams); // Delete the messages now. $DB->delete_records('messages', ['conversationid' => $conversationid]); } }
[ "public", "static", "function", "delete_all_conversation_data", "(", "int", "$", "conversationid", ")", "{", "global", "$", "DB", ";", "$", "DB", "->", "delete_records", "(", "'message_conversations'", ",", "[", "'id'", "=>", "$", "conversationid", "]", ")", ";", "$", "DB", "->", "delete_records", "(", "'message_conversation_members'", ",", "[", "'conversationid'", "=>", "$", "conversationid", "]", ")", ";", "$", "DB", "->", "delete_records", "(", "'message_conversation_actions'", ",", "[", "'conversationid'", "=>", "$", "conversationid", "]", ")", ";", "// Now, go through and delete any messages and related message actions for the conversation.", "if", "(", "$", "messages", "=", "$", "DB", "->", "get_records", "(", "'messages'", ",", "[", "'conversationid'", "=>", "$", "conversationid", "]", ")", ")", "{", "$", "messageids", "=", "array_keys", "(", "$", "messages", ")", ";", "list", "(", "$", "insql", ",", "$", "inparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "messageids", ")", ";", "$", "DB", "->", "delete_records_select", "(", "'message_user_actions'", ",", "\"messageid $insql\"", ",", "$", "inparams", ")", ";", "// Delete the messages now.", "$", "DB", "->", "delete_records", "(", "'messages'", ",", "[", "'conversationid'", "=>", "$", "conversationid", "]", ")", ";", "}", "}" ]
Completely removes all related data in the DB for a given conversation. @param int $conversationid The id of the conversation
[ "Completely", "removes", "all", "related", "data", "in", "the", "DB", "for", "a", "given", "conversation", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/api.php#L3309-L3326
213,393
moodle/moodle
admin/tool/monitor/classes/output/managesubs/subs.php
subs.col_unsubscribe
public function col_unsubscribe(\tool_monitor\subscription $sub) { global $OUTPUT, $CFG; $deleteurl = new \moodle_url($CFG->wwwroot. '/admin/tool/monitor/index.php', array('subscriptionid' => $sub->id, 'action' => 'unsubscribe', 'courseid' => $this->courseid, 'sesskey' => sesskey())); $icon = $OUTPUT->render(new \pix_icon('t/delete', get_string('deletesubscription', 'tool_monitor'))); return \html_writer::link($deleteurl, $icon, array('class' => 'action-icon')); }
php
public function col_unsubscribe(\tool_monitor\subscription $sub) { global $OUTPUT, $CFG; $deleteurl = new \moodle_url($CFG->wwwroot. '/admin/tool/monitor/index.php', array('subscriptionid' => $sub->id, 'action' => 'unsubscribe', 'courseid' => $this->courseid, 'sesskey' => sesskey())); $icon = $OUTPUT->render(new \pix_icon('t/delete', get_string('deletesubscription', 'tool_monitor'))); return \html_writer::link($deleteurl, $icon, array('class' => 'action-icon')); }
[ "public", "function", "col_unsubscribe", "(", "\\", "tool_monitor", "\\", "subscription", "$", "sub", ")", "{", "global", "$", "OUTPUT", ",", "$", "CFG", ";", "$", "deleteurl", "=", "new", "\\", "moodle_url", "(", "$", "CFG", "->", "wwwroot", ".", "'/admin/tool/monitor/index.php'", ",", "array", "(", "'subscriptionid'", "=>", "$", "sub", "->", "id", ",", "'action'", "=>", "'unsubscribe'", ",", "'courseid'", "=>", "$", "this", "->", "courseid", ",", "'sesskey'", "=>", "sesskey", "(", ")", ")", ")", ";", "$", "icon", "=", "$", "OUTPUT", "->", "render", "(", "new", "\\", "pix_icon", "(", "'t/delete'", ",", "get_string", "(", "'deletesubscription'", ",", "'tool_monitor'", ")", ")", ")", ";", "return", "\\", "html_writer", "::", "link", "(", "$", "deleteurl", ",", "$", "icon", ",", "array", "(", "'class'", "=>", "'action-icon'", ")", ")", ";", "}" ]
Generate content for unsubscribe column. @param \tool_monitor\subscription $sub subscription object @return string html used to display the unsubscribe field.
[ "Generate", "content", "for", "unsubscribe", "column", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/monitor/classes/output/managesubs/subs.php#L170-L178
213,394
moodle/moodle
lib/lessphp/Exception/Parser.php
Less_Exception_Parser.genMessage
public function genMessage(){ if( $this->currentFile && $this->currentFile['filename'] ){ $this->message .= ' in '.basename($this->currentFile['filename']); } if( $this->index !== null ){ $this->getInput(); if( $this->input ){ $line = self::getLineNumber(); $this->message .= ' on line '.$line.', column '.self::getColumn(); $lines = explode("\n",$this->input); $count = count($lines); $start_line = max(0, $line-3); $last_line = min($count, $start_line+6); $num_len = strlen($last_line); for( $i = $start_line; $i < $last_line; $i++ ){ $this->message .= "\n".str_pad($i+1,$num_len,'0',STR_PAD_LEFT).'| '.$lines[$i]; } } } }
php
public function genMessage(){ if( $this->currentFile && $this->currentFile['filename'] ){ $this->message .= ' in '.basename($this->currentFile['filename']); } if( $this->index !== null ){ $this->getInput(); if( $this->input ){ $line = self::getLineNumber(); $this->message .= ' on line '.$line.', column '.self::getColumn(); $lines = explode("\n",$this->input); $count = count($lines); $start_line = max(0, $line-3); $last_line = min($count, $start_line+6); $num_len = strlen($last_line); for( $i = $start_line; $i < $last_line; $i++ ){ $this->message .= "\n".str_pad($i+1,$num_len,'0',STR_PAD_LEFT).'| '.$lines[$i]; } } } }
[ "public", "function", "genMessage", "(", ")", "{", "if", "(", "$", "this", "->", "currentFile", "&&", "$", "this", "->", "currentFile", "[", "'filename'", "]", ")", "{", "$", "this", "->", "message", ".=", "' in '", ".", "basename", "(", "$", "this", "->", "currentFile", "[", "'filename'", "]", ")", ";", "}", "if", "(", "$", "this", "->", "index", "!==", "null", ")", "{", "$", "this", "->", "getInput", "(", ")", ";", "if", "(", "$", "this", "->", "input", ")", "{", "$", "line", "=", "self", "::", "getLineNumber", "(", ")", ";", "$", "this", "->", "message", ".=", "' on line '", ".", "$", "line", ".", "', column '", ".", "self", "::", "getColumn", "(", ")", ";", "$", "lines", "=", "explode", "(", "\"\\n\"", ",", "$", "this", "->", "input", ")", ";", "$", "count", "=", "count", "(", "$", "lines", ")", ";", "$", "start_line", "=", "max", "(", "0", ",", "$", "line", "-", "3", ")", ";", "$", "last_line", "=", "min", "(", "$", "count", ",", "$", "start_line", "+", "6", ")", ";", "$", "num_len", "=", "strlen", "(", "$", "last_line", ")", ";", "for", "(", "$", "i", "=", "$", "start_line", ";", "$", "i", "<", "$", "last_line", ";", "$", "i", "++", ")", "{", "$", "this", "->", "message", ".=", "\"\\n\"", ".", "str_pad", "(", "$", "i", "+", "1", ",", "$", "num_len", ",", "'0'", ",", "STR_PAD_LEFT", ")", ".", "'| '", ".", "$", "lines", "[", "$", "i", "]", ";", "}", "}", "}", "}" ]
Converts the exception to string @return string
[ "Converts", "the", "exception", "to", "string" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Exception/Parser.php#L69-L93
213,395
moodle/moodle
lib/lessphp/Exception/Parser.php
Less_Exception_Parser.getLineNumber
public function getLineNumber(){ if( $this->index ){ // https://bugs.php.net/bug.php?id=49790 if (ini_get("mbstring.func_overload")) { return substr_count(substr($this->input, 0, $this->index), "\n") + 1; } else { return substr_count($this->input, "\n", 0, $this->index) + 1; } } return 1; }
php
public function getLineNumber(){ if( $this->index ){ // https://bugs.php.net/bug.php?id=49790 if (ini_get("mbstring.func_overload")) { return substr_count(substr($this->input, 0, $this->index), "\n") + 1; } else { return substr_count($this->input, "\n", 0, $this->index) + 1; } } return 1; }
[ "public", "function", "getLineNumber", "(", ")", "{", "if", "(", "$", "this", "->", "index", ")", "{", "// https://bugs.php.net/bug.php?id=49790\r", "if", "(", "ini_get", "(", "\"mbstring.func_overload\"", ")", ")", "{", "return", "substr_count", "(", "substr", "(", "$", "this", "->", "input", ",", "0", ",", "$", "this", "->", "index", ")", ",", "\"\\n\"", ")", "+", "1", ";", "}", "else", "{", "return", "substr_count", "(", "$", "this", "->", "input", ",", "\"\\n\"", ",", "0", ",", "$", "this", "->", "index", ")", "+", "1", ";", "}", "}", "return", "1", ";", "}" ]
Returns the line number the error was encountered @return integer
[ "Returns", "the", "line", "number", "the", "error", "was", "encountered" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Exception/Parser.php#L100-L110
213,396
moodle/moodle
lib/lessphp/Exception/Parser.php
Less_Exception_Parser.getColumn
public function getColumn(){ $part = substr($this->input, 0, $this->index); $pos = strrpos($part,"\n"); return $this->index - $pos; }
php
public function getColumn(){ $part = substr($this->input, 0, $this->index); $pos = strrpos($part,"\n"); return $this->index - $pos; }
[ "public", "function", "getColumn", "(", ")", "{", "$", "part", "=", "substr", "(", "$", "this", "->", "input", ",", "0", ",", "$", "this", "->", "index", ")", ";", "$", "pos", "=", "strrpos", "(", "$", "part", ",", "\"\\n\"", ")", ";", "return", "$", "this", "->", "index", "-", "$", "pos", ";", "}" ]
Returns the column the error was encountered @return integer
[ "Returns", "the", "column", "the", "error", "was", "encountered" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/lessphp/Exception/Parser.php#L118-L123
213,397
moodle/moodle
calendar/classes/local/event/proxies/cm_info_proxy.php
cm_info_proxy.get
public function get($member) { if ($this->base && property_exists($this->base, $member)) { return $this->base->{$member}; } return $this->get_proxied_instance()->{$member}; }
php
public function get($member) { if ($this->base && property_exists($this->base, $member)) { return $this->base->{$member}; } return $this->get_proxied_instance()->{$member}; }
[ "public", "function", "get", "(", "$", "member", ")", "{", "if", "(", "$", "this", "->", "base", "&&", "property_exists", "(", "$", "this", "->", "base", ",", "$", "member", ")", ")", "{", "return", "$", "this", "->", "base", "->", "{", "$", "member", "}", ";", "}", "return", "$", "this", "->", "get_proxied_instance", "(", ")", "->", "{", "$", "member", "}", ";", "}" ]
Retrieve a member of the proxied class. @param string $member The name of the member to retrieve @return mixed The member.
[ "Retrieve", "a", "member", "of", "the", "proxied", "class", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/local/event/proxies/cm_info_proxy.php#L64-L70
213,398
moodle/moodle
calendar/classes/local/event/container.php
container.init
private static function init() { if (empty(self::$eventfactory)) { self::$actionfactory = new action_factory(); self::$eventmapper = new event_mapper( // The event mapper we return from here needs to know how to // make events, so it needs an event factory. However we can't // give it the same one as we store and return in the container // as that one uses all our plumbing to control event visibility. // // So we make a new even factory that doesn't do anyting other than // return the instance. new event_factory( // Never apply actions, simply return. function(event_interface $event) { return $event; }, // Never hide an event. function() { return true; }, // Never bail out early when instantiating an event. function() { return false; }, self::$coursecache, self::$modulecache ) ); self::$eventfactory = new event_factory( [self::class, 'apply_component_provide_event_action'], [self::class, 'apply_component_is_event_visible'], function ($dbrow) { $requestinguserid = self::get_requesting_user(); if (!empty($dbrow->categoryid)) { // This is a category event. Check that the category is visible to this user. $category = \core_course_category::get($dbrow->categoryid, IGNORE_MISSING, true, $requestinguserid); if (empty($category) || !$category->is_uservisible($requestinguserid)) { return true; } } // At present we only have a bail-out check for events in course modules. if (empty($dbrow->modulename)) { return false; } $instances = get_fast_modinfo($dbrow->courseid, $requestinguserid)->instances; // If modinfo doesn't know about the module, we should ignore it. if (!isset($instances[$dbrow->modulename]) || !isset($instances[$dbrow->modulename][$dbrow->instance])) { return true; } $cm = $instances[$dbrow->modulename][$dbrow->instance]; // If the module is not visible to the current user, we should ignore it. // We have to check enrolment here as well because the uservisible check // looks for the "view" capability however some activities (such as Lesson) // have that capability set on the "Authenticated User" role rather than // on "Student" role, which means uservisible returns true even when the user // is no longer enrolled in the course. // So, with the following we are checking - // 1) Only process modules if $cm->uservisible is true. // 2) Only process modules for courses a user has the capability to view OR they are enrolled in. // 3) Only process modules for courses that are visible OR if the course is not visible, the user // has the capability to view hidden courses. if (!$cm->uservisible) { return true; } $coursecontext = \context_course::instance($dbrow->courseid); if (!$cm->get_course()->visible && !has_capability('moodle/course:viewhiddencourses', $coursecontext, $requestinguserid)) { return true; } if (!has_capability('moodle/course:view', $coursecontext, $requestinguserid) && !is_enrolled($coursecontext, $requestinguserid)) { return true; } // Ok, now check if we are looking at a completion event. if ($dbrow->eventtype === \core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED) { // Need to have completion enabled before displaying these events. $course = new \stdClass(); $course->id = $dbrow->courseid; $completion = new \completion_info($course); return (bool) !$completion->is_enabled($cm); } return false; }, self::$coursecache, self::$modulecache ); } if (empty(self::$eventvault)) { self::$eventretrievalstrategy = new raw_event_retrieval_strategy(); self::$eventvault = new event_vault(self::$eventfactory, self::$eventretrievalstrategy); } }
php
private static function init() { if (empty(self::$eventfactory)) { self::$actionfactory = new action_factory(); self::$eventmapper = new event_mapper( // The event mapper we return from here needs to know how to // make events, so it needs an event factory. However we can't // give it the same one as we store and return in the container // as that one uses all our plumbing to control event visibility. // // So we make a new even factory that doesn't do anyting other than // return the instance. new event_factory( // Never apply actions, simply return. function(event_interface $event) { return $event; }, // Never hide an event. function() { return true; }, // Never bail out early when instantiating an event. function() { return false; }, self::$coursecache, self::$modulecache ) ); self::$eventfactory = new event_factory( [self::class, 'apply_component_provide_event_action'], [self::class, 'apply_component_is_event_visible'], function ($dbrow) { $requestinguserid = self::get_requesting_user(); if (!empty($dbrow->categoryid)) { // This is a category event. Check that the category is visible to this user. $category = \core_course_category::get($dbrow->categoryid, IGNORE_MISSING, true, $requestinguserid); if (empty($category) || !$category->is_uservisible($requestinguserid)) { return true; } } // At present we only have a bail-out check for events in course modules. if (empty($dbrow->modulename)) { return false; } $instances = get_fast_modinfo($dbrow->courseid, $requestinguserid)->instances; // If modinfo doesn't know about the module, we should ignore it. if (!isset($instances[$dbrow->modulename]) || !isset($instances[$dbrow->modulename][$dbrow->instance])) { return true; } $cm = $instances[$dbrow->modulename][$dbrow->instance]; // If the module is not visible to the current user, we should ignore it. // We have to check enrolment here as well because the uservisible check // looks for the "view" capability however some activities (such as Lesson) // have that capability set on the "Authenticated User" role rather than // on "Student" role, which means uservisible returns true even when the user // is no longer enrolled in the course. // So, with the following we are checking - // 1) Only process modules if $cm->uservisible is true. // 2) Only process modules for courses a user has the capability to view OR they are enrolled in. // 3) Only process modules for courses that are visible OR if the course is not visible, the user // has the capability to view hidden courses. if (!$cm->uservisible) { return true; } $coursecontext = \context_course::instance($dbrow->courseid); if (!$cm->get_course()->visible && !has_capability('moodle/course:viewhiddencourses', $coursecontext, $requestinguserid)) { return true; } if (!has_capability('moodle/course:view', $coursecontext, $requestinguserid) && !is_enrolled($coursecontext, $requestinguserid)) { return true; } // Ok, now check if we are looking at a completion event. if ($dbrow->eventtype === \core_completion\api::COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED) { // Need to have completion enabled before displaying these events. $course = new \stdClass(); $course->id = $dbrow->courseid; $completion = new \completion_info($course); return (bool) !$completion->is_enabled($cm); } return false; }, self::$coursecache, self::$modulecache ); } if (empty(self::$eventvault)) { self::$eventretrievalstrategy = new raw_event_retrieval_strategy(); self::$eventvault = new event_vault(self::$eventfactory, self::$eventretrievalstrategy); } }
[ "private", "static", "function", "init", "(", ")", "{", "if", "(", "empty", "(", "self", "::", "$", "eventfactory", ")", ")", "{", "self", "::", "$", "actionfactory", "=", "new", "action_factory", "(", ")", ";", "self", "::", "$", "eventmapper", "=", "new", "event_mapper", "(", "// The event mapper we return from here needs to know how to", "// make events, so it needs an event factory. However we can't", "// give it the same one as we store and return in the container", "// as that one uses all our plumbing to control event visibility.", "//", "// So we make a new even factory that doesn't do anyting other than", "// return the instance.", "new", "event_factory", "(", "// Never apply actions, simply return.", "function", "(", "event_interface", "$", "event", ")", "{", "return", "$", "event", ";", "}", ",", "// Never hide an event.", "function", "(", ")", "{", "return", "true", ";", "}", ",", "// Never bail out early when instantiating an event.", "function", "(", ")", "{", "return", "false", ";", "}", ",", "self", "::", "$", "coursecache", ",", "self", "::", "$", "modulecache", ")", ")", ";", "self", "::", "$", "eventfactory", "=", "new", "event_factory", "(", "[", "self", "::", "class", ",", "'apply_component_provide_event_action'", "]", ",", "[", "self", "::", "class", ",", "'apply_component_is_event_visible'", "]", ",", "function", "(", "$", "dbrow", ")", "{", "$", "requestinguserid", "=", "self", "::", "get_requesting_user", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "dbrow", "->", "categoryid", ")", ")", "{", "// This is a category event. Check that the category is visible to this user.", "$", "category", "=", "\\", "core_course_category", "::", "get", "(", "$", "dbrow", "->", "categoryid", ",", "IGNORE_MISSING", ",", "true", ",", "$", "requestinguserid", ")", ";", "if", "(", "empty", "(", "$", "category", ")", "||", "!", "$", "category", "->", "is_uservisible", "(", "$", "requestinguserid", ")", ")", "{", "return", "true", ";", "}", "}", "// At present we only have a bail-out check for events in course modules.", "if", "(", "empty", "(", "$", "dbrow", "->", "modulename", ")", ")", "{", "return", "false", ";", "}", "$", "instances", "=", "get_fast_modinfo", "(", "$", "dbrow", "->", "courseid", ",", "$", "requestinguserid", ")", "->", "instances", ";", "// If modinfo doesn't know about the module, we should ignore it.", "if", "(", "!", "isset", "(", "$", "instances", "[", "$", "dbrow", "->", "modulename", "]", ")", "||", "!", "isset", "(", "$", "instances", "[", "$", "dbrow", "->", "modulename", "]", "[", "$", "dbrow", "->", "instance", "]", ")", ")", "{", "return", "true", ";", "}", "$", "cm", "=", "$", "instances", "[", "$", "dbrow", "->", "modulename", "]", "[", "$", "dbrow", "->", "instance", "]", ";", "// If the module is not visible to the current user, we should ignore it.", "// We have to check enrolment here as well because the uservisible check", "// looks for the \"view\" capability however some activities (such as Lesson)", "// have that capability set on the \"Authenticated User\" role rather than", "// on \"Student\" role, which means uservisible returns true even when the user", "// is no longer enrolled in the course.", "// So, with the following we are checking -", "// 1) Only process modules if $cm->uservisible is true.", "// 2) Only process modules for courses a user has the capability to view OR they are enrolled in.", "// 3) Only process modules for courses that are visible OR if the course is not visible, the user", "// has the capability to view hidden courses.", "if", "(", "!", "$", "cm", "->", "uservisible", ")", "{", "return", "true", ";", "}", "$", "coursecontext", "=", "\\", "context_course", "::", "instance", "(", "$", "dbrow", "->", "courseid", ")", ";", "if", "(", "!", "$", "cm", "->", "get_course", "(", ")", "->", "visible", "&&", "!", "has_capability", "(", "'moodle/course:viewhiddencourses'", ",", "$", "coursecontext", ",", "$", "requestinguserid", ")", ")", "{", "return", "true", ";", "}", "if", "(", "!", "has_capability", "(", "'moodle/course:view'", ",", "$", "coursecontext", ",", "$", "requestinguserid", ")", "&&", "!", "is_enrolled", "(", "$", "coursecontext", ",", "$", "requestinguserid", ")", ")", "{", "return", "true", ";", "}", "// Ok, now check if we are looking at a completion event.", "if", "(", "$", "dbrow", "->", "eventtype", "===", "\\", "core_completion", "\\", "api", "::", "COMPLETION_EVENT_TYPE_DATE_COMPLETION_EXPECTED", ")", "{", "// Need to have completion enabled before displaying these events.", "$", "course", "=", "new", "\\", "stdClass", "(", ")", ";", "$", "course", "->", "id", "=", "$", "dbrow", "->", "courseid", ";", "$", "completion", "=", "new", "\\", "completion_info", "(", "$", "course", ")", ";", "return", "(", "bool", ")", "!", "$", "completion", "->", "is_enabled", "(", "$", "cm", ")", ";", "}", "return", "false", ";", "}", ",", "self", "::", "$", "coursecache", ",", "self", "::", "$", "modulecache", ")", ";", "}", "if", "(", "empty", "(", "self", "::", "$", "eventvault", ")", ")", "{", "self", "::", "$", "eventretrievalstrategy", "=", "new", "raw_event_retrieval_strategy", "(", ")", ";", "self", "::", "$", "eventvault", "=", "new", "event_vault", "(", "self", "::", "$", "eventfactory", ",", "self", "::", "$", "eventretrievalstrategy", ")", ";", "}", "}" ]
Initialises the dependency graph if it hasn't yet been.
[ "Initialises", "the", "dependency", "graph", "if", "it", "hasn", "t", "yet", "been", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/local/event/container.php#L92-L197
213,399
moodle/moodle
calendar/classes/local/event/container.php
container.reset_caches
public static function reset_caches() { self::$requestinguserid = null; self::$eventfactory = null; self::$eventmapper = null; self::$eventvault = null; self::$actionfactory = null; self::$eventretrievalstrategy = null; self::$coursecache = []; self::$modulecache = []; }
php
public static function reset_caches() { self::$requestinguserid = null; self::$eventfactory = null; self::$eventmapper = null; self::$eventvault = null; self::$actionfactory = null; self::$eventretrievalstrategy = null; self::$coursecache = []; self::$modulecache = []; }
[ "public", "static", "function", "reset_caches", "(", ")", "{", "self", "::", "$", "requestinguserid", "=", "null", ";", "self", "::", "$", "eventfactory", "=", "null", ";", "self", "::", "$", "eventmapper", "=", "null", ";", "self", "::", "$", "eventvault", "=", "null", ";", "self", "::", "$", "actionfactory", "=", "null", ";", "self", "::", "$", "eventretrievalstrategy", "=", "null", ";", "self", "::", "$", "coursecache", "=", "[", "]", ";", "self", "::", "$", "modulecache", "=", "[", "]", ";", "}" ]
Reset all static caches, called between tests.
[ "Reset", "all", "static", "caches", "called", "between", "tests", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/local/event/container.php#L202-L211