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,900 | moodle/moodle | lib/licenselib.php | license_manager.add | static public function add($license) {
global $DB;
if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
// record exists
if ($record->version < $license->version) {
// update license record
$license->enabled = $record->enabled;
$license->id = $record->id;
$DB->update_record('license', $license);
}
} else {
$DB->insert_record('license', $license);
}
return true;
} | php | static public function add($license) {
global $DB;
if ($record = $DB->get_record('license', array('shortname'=>$license->shortname))) {
// record exists
if ($record->version < $license->version) {
// update license record
$license->enabled = $record->enabled;
$license->id = $record->id;
$DB->update_record('license', $license);
}
} else {
$DB->insert_record('license', $license);
}
return true;
} | [
"static",
"public",
"function",
"add",
"(",
"$",
"license",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"$",
"record",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'license'",
",",
"array",
"(",
"'shortname'",
"=>",
"$",
"license",
"->",
"shortname",
")",
")",
")",
"{",
"// record exists",
"if",
"(",
"$",
"record",
"->",
"version",
"<",
"$",
"license",
"->",
"version",
")",
"{",
"// update license record",
"$",
"license",
"->",
"enabled",
"=",
"$",
"record",
"->",
"enabled",
";",
"$",
"license",
"->",
"id",
"=",
"$",
"record",
"->",
"id",
";",
"$",
"DB",
"->",
"update_record",
"(",
"'license'",
",",
"$",
"license",
")",
";",
"}",
"}",
"else",
"{",
"$",
"DB",
"->",
"insert_record",
"(",
"'license'",
",",
"$",
"license",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Adding a new license type
@param object $license {
shortname => string a shortname of license, will be refered by files table[required]
fullname => string the fullname of the license [required]
source => string the homepage of the license type[required]
enabled => int is it enabled?
version => int a version number used by moodle [required]
} | [
"Adding",
"a",
"new",
"license",
"type"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/licenselib.php#L42-L56 |
213,901 | moodle/moodle | lib/licenselib.php | license_manager.get_licenses | static public function get_licenses($param = null) {
global $DB;
if (empty($param) || !is_array($param)) {
$param = array();
}
// get licenses by conditions
if ($records = $DB->get_records('license', $param)) {
return $records;
} else {
return array();
}
} | php | static public function get_licenses($param = null) {
global $DB;
if (empty($param) || !is_array($param)) {
$param = array();
}
// get licenses by conditions
if ($records = $DB->get_records('license', $param)) {
return $records;
} else {
return array();
}
} | [
"static",
"public",
"function",
"get_licenses",
"(",
"$",
"param",
"=",
"null",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"empty",
"(",
"$",
"param",
")",
"||",
"!",
"is_array",
"(",
"$",
"param",
")",
")",
"{",
"$",
"param",
"=",
"array",
"(",
")",
";",
"}",
"// get licenses by conditions",
"if",
"(",
"$",
"records",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'license'",
",",
"$",
"param",
")",
")",
"{",
"return",
"$",
"records",
";",
"}",
"else",
"{",
"return",
"array",
"(",
")",
";",
"}",
"}"
] | Get license records
@param mixed $param
@return array | [
"Get",
"license",
"records"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/licenselib.php#L63-L74 |
213,902 | moodle/moodle | lib/licenselib.php | license_manager.enable | static public function enable($license) {
global $DB;
if ($license = self::get_license_by_shortname($license)) {
$license->enabled = 1;
$DB->update_record('license', $license);
}
self::set_active_licenses();
return true;
} | php | static public function enable($license) {
global $DB;
if ($license = self::get_license_by_shortname($license)) {
$license->enabled = 1;
$DB->update_record('license', $license);
}
self::set_active_licenses();
return true;
} | [
"static",
"public",
"function",
"enable",
"(",
"$",
"license",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"$",
"license",
"=",
"self",
"::",
"get_license_by_shortname",
"(",
"$",
"license",
")",
")",
"{",
"$",
"license",
"->",
"enabled",
"=",
"1",
";",
"$",
"DB",
"->",
"update_record",
"(",
"'license'",
",",
"$",
"license",
")",
";",
"}",
"self",
"::",
"set_active_licenses",
"(",
")",
";",
"return",
"true",
";",
"}"
] | Enable a license
@param string $license the shortname of license
@return boolean | [
"Enable",
"a",
"license"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/licenselib.php#L95-L103 |
213,903 | moodle/moodle | lib/licenselib.php | license_manager.disable | static public function disable($license) {
global $DB, $CFG;
// Site default license cannot be disabled!
if ($license == $CFG->sitedefaultlicense) {
print_error('error');
}
if ($license = self::get_license_by_shortname($license)) {
$license->enabled = 0;
$DB->update_record('license', $license);
}
self::set_active_licenses();
return true;
} | php | static public function disable($license) {
global $DB, $CFG;
// Site default license cannot be disabled!
if ($license == $CFG->sitedefaultlicense) {
print_error('error');
}
if ($license = self::get_license_by_shortname($license)) {
$license->enabled = 0;
$DB->update_record('license', $license);
}
self::set_active_licenses();
return true;
} | [
"static",
"public",
"function",
"disable",
"(",
"$",
"license",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"CFG",
";",
"// Site default license cannot be disabled!",
"if",
"(",
"$",
"license",
"==",
"$",
"CFG",
"->",
"sitedefaultlicense",
")",
"{",
"print_error",
"(",
"'error'",
")",
";",
"}",
"if",
"(",
"$",
"license",
"=",
"self",
"::",
"get_license_by_shortname",
"(",
"$",
"license",
")",
")",
"{",
"$",
"license",
"->",
"enabled",
"=",
"0",
";",
"$",
"DB",
"->",
"update_record",
"(",
"'license'",
",",
"$",
"license",
")",
";",
"}",
"self",
"::",
"set_active_licenses",
"(",
")",
";",
"return",
"true",
";",
"}"
] | Disable a license
@param string $license the shortname of license
@return boolean | [
"Disable",
"a",
"license"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/licenselib.php#L110-L122 |
213,904 | moodle/moodle | lib/horde/framework/Horde/Imap/Client/Tokenize.php | Horde_Imap_Client_Tokenize.addLiteralStream | public function addLiteralStream($data)
{
$pos = $this->_stream->pos();
if (!isset($this->_literals[$pos])) {
$this->_literals[$pos] = new Horde_Stream_Temp();
}
$this->_literals[$pos]->add($data);
} | php | public function addLiteralStream($data)
{
$pos = $this->_stream->pos();
if (!isset($this->_literals[$pos])) {
$this->_literals[$pos] = new Horde_Stream_Temp();
}
$this->_literals[$pos]->add($data);
} | [
"public",
"function",
"addLiteralStream",
"(",
"$",
"data",
")",
"{",
"$",
"pos",
"=",
"$",
"this",
"->",
"_stream",
"->",
"pos",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_literals",
"[",
"$",
"pos",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_literals",
"[",
"$",
"pos",
"]",
"=",
"new",
"Horde_Stream_Temp",
"(",
")",
";",
"}",
"$",
"this",
"->",
"_literals",
"[",
"$",
"pos",
"]",
"->",
"add",
"(",
"$",
"data",
")",
";",
"}"
] | Add data to literal stream at the current position.
@param mixed $data Data to add (string, resource, or Horde_Stream
object). | [
"Add",
"data",
"to",
"literal",
"stream",
"at",
"the",
"current",
"position",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Tokenize.php#L147-L154 |
213,905 | moodle/moodle | lib/horde/framework/Horde/Imap/Client/Tokenize.php | Horde_Imap_Client_Tokenize.flushIterator | public function flushIterator($return = true, $sublevel = true)
{
$out = array();
if ($return) {
$this->_nextModify = array(
'level' => $sublevel ? $this->_level : 0,
'out' => array()
);
$this->next();
$out = $this->_nextModify['out'];
$this->_nextModify = array();
} elseif ($sublevel && $this->_level) {
$this->_nextModify = array(
'level' => $this->_level
);
$this->next();
$this->_nextModify = array();
} else {
$this->_stream->end();
$this->_stream->getChar();
$this->_current = $this->_key = $this->_level = false;
}
return $out;
} | php | public function flushIterator($return = true, $sublevel = true)
{
$out = array();
if ($return) {
$this->_nextModify = array(
'level' => $sublevel ? $this->_level : 0,
'out' => array()
);
$this->next();
$out = $this->_nextModify['out'];
$this->_nextModify = array();
} elseif ($sublevel && $this->_level) {
$this->_nextModify = array(
'level' => $this->_level
);
$this->next();
$this->_nextModify = array();
} else {
$this->_stream->end();
$this->_stream->getChar();
$this->_current = $this->_key = $this->_level = false;
}
return $out;
} | [
"public",
"function",
"flushIterator",
"(",
"$",
"return",
"=",
"true",
",",
"$",
"sublevel",
"=",
"true",
")",
"{",
"$",
"out",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"return",
")",
"{",
"$",
"this",
"->",
"_nextModify",
"=",
"array",
"(",
"'level'",
"=>",
"$",
"sublevel",
"?",
"$",
"this",
"->",
"_level",
":",
"0",
",",
"'out'",
"=>",
"array",
"(",
")",
")",
";",
"$",
"this",
"->",
"next",
"(",
")",
";",
"$",
"out",
"=",
"$",
"this",
"->",
"_nextModify",
"[",
"'out'",
"]",
";",
"$",
"this",
"->",
"_nextModify",
"=",
"array",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"sublevel",
"&&",
"$",
"this",
"->",
"_level",
")",
"{",
"$",
"this",
"->",
"_nextModify",
"=",
"array",
"(",
"'level'",
"=>",
"$",
"this",
"->",
"_level",
")",
";",
"$",
"this",
"->",
"next",
"(",
")",
";",
"$",
"this",
"->",
"_nextModify",
"=",
"array",
"(",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"_stream",
"->",
"end",
"(",
")",
";",
"$",
"this",
"->",
"_stream",
"->",
"getChar",
"(",
")",
";",
"$",
"this",
"->",
"_current",
"=",
"$",
"this",
"->",
"_key",
"=",
"$",
"this",
"->",
"_level",
"=",
"false",
";",
"}",
"return",
"$",
"out",
";",
"}"
] | Flush the remaining entries left in the iterator.
@param boolean $return If true, return entries. Only returns entries
on the current level.
@param boolean $sublevel Only flush items in current sublevel?
@return array The entries if $return is true. | [
"Flush",
"the",
"remaining",
"entries",
"left",
"in",
"the",
"iterator",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Tokenize.php#L165-L190 |
213,906 | moodle/moodle | lib/horde/framework/Horde/Imap/Client/Tokenize.php | Horde_Imap_Client_Tokenize.getLiteralLength | public function getLiteralLength()
{
if ($this->_stream->substring(-1, 1) === '}') {
$literal_data = $this->_stream->getString(
$this->_stream->search('{', true) - 1
);
$literal_len = substr($literal_data, 2, -1);
if (is_numeric($literal_len)) {
return array(
'binary' => ($literal_data[0] === '~'),
'length' => intval($literal_len)
);
}
}
return null;
} | php | public function getLiteralLength()
{
if ($this->_stream->substring(-1, 1) === '}') {
$literal_data = $this->_stream->getString(
$this->_stream->search('{', true) - 1
);
$literal_len = substr($literal_data, 2, -1);
if (is_numeric($literal_len)) {
return array(
'binary' => ($literal_data[0] === '~'),
'length' => intval($literal_len)
);
}
}
return null;
} | [
"public",
"function",
"getLiteralLength",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_stream",
"->",
"substring",
"(",
"-",
"1",
",",
"1",
")",
"===",
"'}'",
")",
"{",
"$",
"literal_data",
"=",
"$",
"this",
"->",
"_stream",
"->",
"getString",
"(",
"$",
"this",
"->",
"_stream",
"->",
"search",
"(",
"'{'",
",",
"true",
")",
"-",
"1",
")",
";",
"$",
"literal_len",
"=",
"substr",
"(",
"$",
"literal_data",
",",
"2",
",",
"-",
"1",
")",
";",
"if",
"(",
"is_numeric",
"(",
"$",
"literal_len",
")",
")",
"{",
"return",
"array",
"(",
"'binary'",
"=>",
"(",
"$",
"literal_data",
"[",
"0",
"]",
"===",
"'~'",
")",
",",
"'length'",
"=>",
"intval",
"(",
"$",
"literal_len",
")",
")",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Return literal length data located at the end of the stream.
@return mixed Null if no literal data found, or an array with these
keys:
- binary: (boolean) True if this is a literal8.
- length: (integer) Length of the literal. | [
"Return",
"literal",
"length",
"data",
"located",
"at",
"the",
"end",
"of",
"the",
"stream",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Tokenize.php#L200-L217 |
213,907 | moodle/moodle | lib/horde/framework/Horde/Imap/Client/Tokenize.php | Horde_Imap_Client_Tokenize.nextStream | public function nextStream()
{
$changed = $this->_literalStream;
$this->_literalStream = true;
$out = $this->next();
if ($changed) {
$this->_literalStream = false;
}
return $out;
} | php | public function nextStream()
{
$changed = $this->_literalStream;
$this->_literalStream = true;
$out = $this->next();
if ($changed) {
$this->_literalStream = false;
}
return $out;
} | [
"public",
"function",
"nextStream",
"(",
")",
"{",
"$",
"changed",
"=",
"$",
"this",
"->",
"_literalStream",
";",
"$",
"this",
"->",
"_literalStream",
"=",
"true",
";",
"$",
"out",
"=",
"$",
"this",
"->",
"next",
"(",
")",
";",
"if",
"(",
"$",
"changed",
")",
"{",
"$",
"this",
"->",
"_literalStream",
"=",
"false",
";",
"}",
"return",
"$",
"out",
";",
"}"
] | Force return of literal data as stream, if next token.
@see next() | [
"Force",
"return",
"of",
"literal",
"data",
"as",
"stream",
"if",
"next",
"token",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Tokenize.php#L382-L394 |
213,908 | moodle/moodle | lib/htmlpurifier/HTMLPurifier/Printer/ConfigForm.php | HTMLPurifier_Printer_ConfigForm.setTextareaDimensions | public function setTextareaDimensions($cols = null, $rows = null)
{
if ($cols) {
$this->fields['default']->cols = $cols;
}
if ($rows) {
$this->fields['default']->rows = $rows;
}
} | php | public function setTextareaDimensions($cols = null, $rows = null)
{
if ($cols) {
$this->fields['default']->cols = $cols;
}
if ($rows) {
$this->fields['default']->rows = $rows;
}
} | [
"public",
"function",
"setTextareaDimensions",
"(",
"$",
"cols",
"=",
"null",
",",
"$",
"rows",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"cols",
")",
"{",
"$",
"this",
"->",
"fields",
"[",
"'default'",
"]",
"->",
"cols",
"=",
"$",
"cols",
";",
"}",
"if",
"(",
"$",
"rows",
")",
"{",
"$",
"this",
"->",
"fields",
"[",
"'default'",
"]",
"->",
"rows",
"=",
"$",
"rows",
";",
"}",
"}"
] | Sets default column and row size for textareas in sub-printers
@param $cols Integer columns of textarea, null to use default
@param $rows Integer rows of textarea, null to use default | [
"Sets",
"default",
"column",
"and",
"row",
"size",
"for",
"textareas",
"in",
"sub",
"-",
"printers"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Printer/ConfigForm.php#L59-L67 |
213,909 | moodle/moodle | lib/htmlpurifier/HTMLPurifier/Printer/ConfigForm.php | HTMLPurifier_Printer_ConfigForm.render | public function render($config, $allowed = true, $render_controls = true)
{
if (is_array($config) && isset($config[0])) {
$gen_config = $config[0];
$config = $config[1];
} else {
$gen_config = $config;
}
$this->config = $config;
$this->genConfig = $gen_config;
$this->prepareGenerator($gen_config);
$allowed = HTMLPurifier_Config::getAllowedDirectivesForForm($allowed, $config->def);
$all = array();
foreach ($allowed as $key) {
list($ns, $directive) = $key;
$all[$ns][$directive] = $config->get($ns . '.' . $directive);
}
$ret = '';
$ret .= $this->start('table', array('class' => 'hp-config'));
$ret .= $this->start('thead');
$ret .= $this->start('tr');
$ret .= $this->element('th', 'Directive', array('class' => 'hp-directive'));
$ret .= $this->element('th', 'Value', array('class' => 'hp-value'));
$ret .= $this->end('tr');
$ret .= $this->end('thead');
foreach ($all as $ns => $directives) {
$ret .= $this->renderNamespace($ns, $directives);
}
if ($render_controls) {
$ret .= $this->start('tbody');
$ret .= $this->start('tr');
$ret .= $this->start('td', array('colspan' => 2, 'class' => 'controls'));
$ret .= $this->elementEmpty('input', array('type' => 'submit', 'value' => 'Submit'));
$ret .= '[<a href="?">Reset</a>]';
$ret .= $this->end('td');
$ret .= $this->end('tr');
$ret .= $this->end('tbody');
}
$ret .= $this->end('table');
return $ret;
} | php | public function render($config, $allowed = true, $render_controls = true)
{
if (is_array($config) && isset($config[0])) {
$gen_config = $config[0];
$config = $config[1];
} else {
$gen_config = $config;
}
$this->config = $config;
$this->genConfig = $gen_config;
$this->prepareGenerator($gen_config);
$allowed = HTMLPurifier_Config::getAllowedDirectivesForForm($allowed, $config->def);
$all = array();
foreach ($allowed as $key) {
list($ns, $directive) = $key;
$all[$ns][$directive] = $config->get($ns . '.' . $directive);
}
$ret = '';
$ret .= $this->start('table', array('class' => 'hp-config'));
$ret .= $this->start('thead');
$ret .= $this->start('tr');
$ret .= $this->element('th', 'Directive', array('class' => 'hp-directive'));
$ret .= $this->element('th', 'Value', array('class' => 'hp-value'));
$ret .= $this->end('tr');
$ret .= $this->end('thead');
foreach ($all as $ns => $directives) {
$ret .= $this->renderNamespace($ns, $directives);
}
if ($render_controls) {
$ret .= $this->start('tbody');
$ret .= $this->start('tr');
$ret .= $this->start('td', array('colspan' => 2, 'class' => 'controls'));
$ret .= $this->elementEmpty('input', array('type' => 'submit', 'value' => 'Submit'));
$ret .= '[<a href="?">Reset</a>]';
$ret .= $this->end('td');
$ret .= $this->end('tr');
$ret .= $this->end('tbody');
}
$ret .= $this->end('table');
return $ret;
} | [
"public",
"function",
"render",
"(",
"$",
"config",
",",
"$",
"allowed",
"=",
"true",
",",
"$",
"render_controls",
"=",
"true",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"config",
")",
"&&",
"isset",
"(",
"$",
"config",
"[",
"0",
"]",
")",
")",
"{",
"$",
"gen_config",
"=",
"$",
"config",
"[",
"0",
"]",
";",
"$",
"config",
"=",
"$",
"config",
"[",
"1",
"]",
";",
"}",
"else",
"{",
"$",
"gen_config",
"=",
"$",
"config",
";",
"}",
"$",
"this",
"->",
"config",
"=",
"$",
"config",
";",
"$",
"this",
"->",
"genConfig",
"=",
"$",
"gen_config",
";",
"$",
"this",
"->",
"prepareGenerator",
"(",
"$",
"gen_config",
")",
";",
"$",
"allowed",
"=",
"HTMLPurifier_Config",
"::",
"getAllowedDirectivesForForm",
"(",
"$",
"allowed",
",",
"$",
"config",
"->",
"def",
")",
";",
"$",
"all",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"allowed",
"as",
"$",
"key",
")",
"{",
"list",
"(",
"$",
"ns",
",",
"$",
"directive",
")",
"=",
"$",
"key",
";",
"$",
"all",
"[",
"$",
"ns",
"]",
"[",
"$",
"directive",
"]",
"=",
"$",
"config",
"->",
"get",
"(",
"$",
"ns",
".",
"'.'",
".",
"$",
"directive",
")",
";",
"}",
"$",
"ret",
"=",
"''",
";",
"$",
"ret",
".=",
"$",
"this",
"->",
"start",
"(",
"'table'",
",",
"array",
"(",
"'class'",
"=>",
"'hp-config'",
")",
")",
";",
"$",
"ret",
".=",
"$",
"this",
"->",
"start",
"(",
"'thead'",
")",
";",
"$",
"ret",
".=",
"$",
"this",
"->",
"start",
"(",
"'tr'",
")",
";",
"$",
"ret",
".=",
"$",
"this",
"->",
"element",
"(",
"'th'",
",",
"'Directive'",
",",
"array",
"(",
"'class'",
"=>",
"'hp-directive'",
")",
")",
";",
"$",
"ret",
".=",
"$",
"this",
"->",
"element",
"(",
"'th'",
",",
"'Value'",
",",
"array",
"(",
"'class'",
"=>",
"'hp-value'",
")",
")",
";",
"$",
"ret",
".=",
"$",
"this",
"->",
"end",
"(",
"'tr'",
")",
";",
"$",
"ret",
".=",
"$",
"this",
"->",
"end",
"(",
"'thead'",
")",
";",
"foreach",
"(",
"$",
"all",
"as",
"$",
"ns",
"=>",
"$",
"directives",
")",
"{",
"$",
"ret",
".=",
"$",
"this",
"->",
"renderNamespace",
"(",
"$",
"ns",
",",
"$",
"directives",
")",
";",
"}",
"if",
"(",
"$",
"render_controls",
")",
"{",
"$",
"ret",
".=",
"$",
"this",
"->",
"start",
"(",
"'tbody'",
")",
";",
"$",
"ret",
".=",
"$",
"this",
"->",
"start",
"(",
"'tr'",
")",
";",
"$",
"ret",
".=",
"$",
"this",
"->",
"start",
"(",
"'td'",
",",
"array",
"(",
"'colspan'",
"=>",
"2",
",",
"'class'",
"=>",
"'controls'",
")",
")",
";",
"$",
"ret",
".=",
"$",
"this",
"->",
"elementEmpty",
"(",
"'input'",
",",
"array",
"(",
"'type'",
"=>",
"'submit'",
",",
"'value'",
"=>",
"'Submit'",
")",
")",
";",
"$",
"ret",
".=",
"'[<a href=\"?\">Reset</a>]'",
";",
"$",
"ret",
".=",
"$",
"this",
"->",
"end",
"(",
"'td'",
")",
";",
"$",
"ret",
".=",
"$",
"this",
"->",
"end",
"(",
"'tr'",
")",
";",
"$",
"ret",
".=",
"$",
"this",
"->",
"end",
"(",
"'tbody'",
")",
";",
"}",
"$",
"ret",
".=",
"$",
"this",
"->",
"end",
"(",
"'table'",
")",
";",
"return",
"$",
"ret",
";",
"}"
] | Returns HTML output for a configuration form
@param HTMLPurifier_Config|array $config Configuration object of current form state, or an array
where [0] has an HTML namespace and [1] is being rendered.
@param array|bool $allowed Optional namespace(s) and directives to restrict form to.
@param bool $render_controls
@return string | [
"Returns",
"HTML",
"output",
"for",
"a",
"configuration",
"form"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Printer/ConfigForm.php#L93-L136 |
213,910 | moodle/moodle | user/profile/field/menu/define.class.php | profile_define_menu.define_validate_specific | public function define_validate_specific($data, $files) {
$err = array();
$data->param1 = str_replace("\r", '', $data->param1);
// Check that we have at least 2 options.
if (($options = explode("\n", $data->param1)) === false) {
$err['param1'] = get_string('profilemenunooptions', 'admin');
} else if (count($options) < 2) {
$err['param1'] = get_string('profilemenutoofewoptions', 'admin');
} else if (!empty($data->defaultdata) and !in_array($data->defaultdata, $options)) {
// Check the default data exists in the options.
$err['defaultdata'] = get_string('profilemenudefaultnotinoptions', 'admin');
}
return $err;
} | php | public function define_validate_specific($data, $files) {
$err = array();
$data->param1 = str_replace("\r", '', $data->param1);
// Check that we have at least 2 options.
if (($options = explode("\n", $data->param1)) === false) {
$err['param1'] = get_string('profilemenunooptions', 'admin');
} else if (count($options) < 2) {
$err['param1'] = get_string('profilemenutoofewoptions', 'admin');
} else if (!empty($data->defaultdata) and !in_array($data->defaultdata, $options)) {
// Check the default data exists in the options.
$err['defaultdata'] = get_string('profilemenudefaultnotinoptions', 'admin');
}
return $err;
} | [
"public",
"function",
"define_validate_specific",
"(",
"$",
"data",
",",
"$",
"files",
")",
"{",
"$",
"err",
"=",
"array",
"(",
")",
";",
"$",
"data",
"->",
"param1",
"=",
"str_replace",
"(",
"\"\\r\"",
",",
"''",
",",
"$",
"data",
"->",
"param1",
")",
";",
"// Check that we have at least 2 options.",
"if",
"(",
"(",
"$",
"options",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"data",
"->",
"param1",
")",
")",
"===",
"false",
")",
"{",
"$",
"err",
"[",
"'param1'",
"]",
"=",
"get_string",
"(",
"'profilemenunooptions'",
",",
"'admin'",
")",
";",
"}",
"else",
"if",
"(",
"count",
"(",
"$",
"options",
")",
"<",
"2",
")",
"{",
"$",
"err",
"[",
"'param1'",
"]",
"=",
"get_string",
"(",
"'profilemenutoofewoptions'",
",",
"'admin'",
")",
";",
"}",
"else",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
"->",
"defaultdata",
")",
"and",
"!",
"in_array",
"(",
"$",
"data",
"->",
"defaultdata",
",",
"$",
"options",
")",
")",
"{",
"// Check the default data exists in the options.",
"$",
"err",
"[",
"'defaultdata'",
"]",
"=",
"get_string",
"(",
"'profilemenudefaultnotinoptions'",
",",
"'admin'",
")",
";",
"}",
"return",
"$",
"err",
";",
"}"
] | Validates data for the profile field.
@param array $data
@param array $files
@return array | [
"Validates",
"data",
"for",
"the",
"profile",
"field",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/profile/field/menu/define.class.php#L54-L69 |
213,911 | moodle/moodle | mod/assign/renderer.php | mod_assign_renderer.add_table_row_tuple | private function add_table_row_tuple(html_table $table, $first, $second) {
$row = new html_table_row();
$cell1 = new html_table_cell($first);
$cell2 = new html_table_cell($second);
$row->cells = array($cell1, $cell2);
$table->data[] = $row;
} | php | private function add_table_row_tuple(html_table $table, $first, $second) {
$row = new html_table_row();
$cell1 = new html_table_cell($first);
$cell2 = new html_table_cell($second);
$row->cells = array($cell1, $cell2);
$table->data[] = $row;
} | [
"private",
"function",
"add_table_row_tuple",
"(",
"html_table",
"$",
"table",
",",
"$",
"first",
",",
"$",
"second",
")",
"{",
"$",
"row",
"=",
"new",
"html_table_row",
"(",
")",
";",
"$",
"cell1",
"=",
"new",
"html_table_cell",
"(",
"$",
"first",
")",
";",
"$",
"cell2",
"=",
"new",
"html_table_cell",
"(",
"$",
"second",
")",
";",
"$",
"row",
"->",
"cells",
"=",
"array",
"(",
"$",
"cell1",
",",
"$",
"cell2",
")",
";",
"$",
"table",
"->",
"data",
"[",
"]",
"=",
"$",
"row",
";",
"}"
] | Utility function to add a row of data to a table with 2 columns. Modified
the table param and does not return a value
@param html_table $table The table to append the row of data to
@param string $first The first column text
@param string $second The second column text
@return void | [
"Utility",
"function",
"to",
"add",
"a",
"row",
"of",
"data",
"to",
"a",
"table",
"with",
"2",
"columns",
".",
"Modified",
"the",
"table",
"param",
"and",
"does",
"not",
"return",
"a",
"value"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/renderer.php#L81-L87 |
213,912 | moodle/moodle | mod/assign/renderer.php | mod_assign_renderer.render_assign_gradingmessage | public function render_assign_gradingmessage(assign_gradingmessage $result) {
$urlparams = array('id' => $result->coursemoduleid, 'action'=>'grading');
if (!empty($result->page)) {
$urlparams['page'] = $result->page;
}
$url = new moodle_url('/mod/assign/view.php', $urlparams);
$classes = $result->gradingerror ? 'notifyproblem' : 'notifysuccess';
$o = '';
$o .= $this->output->heading($result->heading, 4);
$o .= $this->output->notification($result->message, $classes);
$o .= $this->output->continue_button($url);
return $o;
} | php | public function render_assign_gradingmessage(assign_gradingmessage $result) {
$urlparams = array('id' => $result->coursemoduleid, 'action'=>'grading');
if (!empty($result->page)) {
$urlparams['page'] = $result->page;
}
$url = new moodle_url('/mod/assign/view.php', $urlparams);
$classes = $result->gradingerror ? 'notifyproblem' : 'notifysuccess';
$o = '';
$o .= $this->output->heading($result->heading, 4);
$o .= $this->output->notification($result->message, $classes);
$o .= $this->output->continue_button($url);
return $o;
} | [
"public",
"function",
"render_assign_gradingmessage",
"(",
"assign_gradingmessage",
"$",
"result",
")",
"{",
"$",
"urlparams",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"result",
"->",
"coursemoduleid",
",",
"'action'",
"=>",
"'grading'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"result",
"->",
"page",
")",
")",
"{",
"$",
"urlparams",
"[",
"'page'",
"]",
"=",
"$",
"result",
"->",
"page",
";",
"}",
"$",
"url",
"=",
"new",
"moodle_url",
"(",
"'/mod/assign/view.php'",
",",
"$",
"urlparams",
")",
";",
"$",
"classes",
"=",
"$",
"result",
"->",
"gradingerror",
"?",
"'notifyproblem'",
":",
"'notifysuccess'",
";",
"$",
"o",
"=",
"''",
";",
"$",
"o",
".=",
"$",
"this",
"->",
"output",
"->",
"heading",
"(",
"$",
"result",
"->",
"heading",
",",
"4",
")",
";",
"$",
"o",
".=",
"$",
"this",
"->",
"output",
"->",
"notification",
"(",
"$",
"result",
"->",
"message",
",",
"$",
"classes",
")",
";",
"$",
"o",
".=",
"$",
"this",
"->",
"output",
"->",
"continue_button",
"(",
"$",
"url",
")",
";",
"return",
"$",
"o",
";",
"}"
] | Render a grading message notification
@param assign_gradingmessage $result The result to render
@return string | [
"Render",
"a",
"grading",
"message",
"notification"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/renderer.php#L94-L107 |
213,913 | moodle/moodle | mod/assign/renderer.php | mod_assign_renderer.render_assign_form | public function render_assign_form(assign_form $form) {
$o = '';
if ($form->jsinitfunction) {
$this->page->requires->js_init_call($form->jsinitfunction, array());
}
$o .= $this->output->box_start('boxaligncenter ' . $form->classname);
$o .= $this->moodleform($form->form);
$o .= $this->output->box_end();
return $o;
} | php | public function render_assign_form(assign_form $form) {
$o = '';
if ($form->jsinitfunction) {
$this->page->requires->js_init_call($form->jsinitfunction, array());
}
$o .= $this->output->box_start('boxaligncenter ' . $form->classname);
$o .= $this->moodleform($form->form);
$o .= $this->output->box_end();
return $o;
} | [
"public",
"function",
"render_assign_form",
"(",
"assign_form",
"$",
"form",
")",
"{",
"$",
"o",
"=",
"''",
";",
"if",
"(",
"$",
"form",
"->",
"jsinitfunction",
")",
"{",
"$",
"this",
"->",
"page",
"->",
"requires",
"->",
"js_init_call",
"(",
"$",
"form",
"->",
"jsinitfunction",
",",
"array",
"(",
")",
")",
";",
"}",
"$",
"o",
".=",
"$",
"this",
"->",
"output",
"->",
"box_start",
"(",
"'boxaligncenter '",
".",
"$",
"form",
"->",
"classname",
")",
";",
"$",
"o",
".=",
"$",
"this",
"->",
"moodleform",
"(",
"$",
"form",
"->",
"form",
")",
";",
"$",
"o",
".=",
"$",
"this",
"->",
"output",
"->",
"box_end",
"(",
")",
";",
"return",
"$",
"o",
";",
"}"
] | Render the generic form
@param assign_form $form The form to render
@return string | [
"Render",
"the",
"generic",
"form"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/renderer.php#L114-L123 |
213,914 | moodle/moodle | mod/assign/renderer.php | mod_assign_renderer.render_assign_user_summary | public function render_assign_user_summary(assign_user_summary $summary) {
$o = '';
$supendedclass = '';
$suspendedicon = '';
if (!$summary->user) {
return;
}
if ($summary->suspendeduser) {
$supendedclass = ' usersuspended';
$suspendedstring = get_string('userenrolmentsuspended', 'grades');
$suspendedicon = ' ' . $this->pix_icon('i/enrolmentsuspended', $suspendedstring);
}
$o .= $this->output->container_start('usersummary');
$o .= $this->output->box_start('boxaligncenter usersummarysection'.$supendedclass);
if ($summary->blindmarking) {
$o .= get_string('hiddenuser', 'assign') . $summary->uniqueidforuser.$suspendedicon;
} else {
$o .= $this->output->user_picture($summary->user);
$o .= $this->output->spacer(array('width'=>30));
$urlparams = array('id' => $summary->user->id, 'course'=>$summary->courseid);
$url = new moodle_url('/user/view.php', $urlparams);
$fullname = fullname($summary->user, $summary->viewfullnames);
$extrainfo = array();
foreach ($summary->extrauserfields as $extrafield) {
$extrainfo[] = $summary->user->$extrafield;
}
if (count($extrainfo)) {
$fullname .= ' (' . implode(', ', $extrainfo) . ')';
}
$fullname .= $suspendedicon;
$o .= $this->output->action_link($url, $fullname);
}
$o .= $this->output->box_end();
$o .= $this->output->container_end();
return $o;
} | php | public function render_assign_user_summary(assign_user_summary $summary) {
$o = '';
$supendedclass = '';
$suspendedicon = '';
if (!$summary->user) {
return;
}
if ($summary->suspendeduser) {
$supendedclass = ' usersuspended';
$suspendedstring = get_string('userenrolmentsuspended', 'grades');
$suspendedicon = ' ' . $this->pix_icon('i/enrolmentsuspended', $suspendedstring);
}
$o .= $this->output->container_start('usersummary');
$o .= $this->output->box_start('boxaligncenter usersummarysection'.$supendedclass);
if ($summary->blindmarking) {
$o .= get_string('hiddenuser', 'assign') . $summary->uniqueidforuser.$suspendedicon;
} else {
$o .= $this->output->user_picture($summary->user);
$o .= $this->output->spacer(array('width'=>30));
$urlparams = array('id' => $summary->user->id, 'course'=>$summary->courseid);
$url = new moodle_url('/user/view.php', $urlparams);
$fullname = fullname($summary->user, $summary->viewfullnames);
$extrainfo = array();
foreach ($summary->extrauserfields as $extrafield) {
$extrainfo[] = $summary->user->$extrafield;
}
if (count($extrainfo)) {
$fullname .= ' (' . implode(', ', $extrainfo) . ')';
}
$fullname .= $suspendedicon;
$o .= $this->output->action_link($url, $fullname);
}
$o .= $this->output->box_end();
$o .= $this->output->container_end();
return $o;
} | [
"public",
"function",
"render_assign_user_summary",
"(",
"assign_user_summary",
"$",
"summary",
")",
"{",
"$",
"o",
"=",
"''",
";",
"$",
"supendedclass",
"=",
"''",
";",
"$",
"suspendedicon",
"=",
"''",
";",
"if",
"(",
"!",
"$",
"summary",
"->",
"user",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"summary",
"->",
"suspendeduser",
")",
"{",
"$",
"supendedclass",
"=",
"' usersuspended'",
";",
"$",
"suspendedstring",
"=",
"get_string",
"(",
"'userenrolmentsuspended'",
",",
"'grades'",
")",
";",
"$",
"suspendedicon",
"=",
"' '",
".",
"$",
"this",
"->",
"pix_icon",
"(",
"'i/enrolmentsuspended'",
",",
"$",
"suspendedstring",
")",
";",
"}",
"$",
"o",
".=",
"$",
"this",
"->",
"output",
"->",
"container_start",
"(",
"'usersummary'",
")",
";",
"$",
"o",
".=",
"$",
"this",
"->",
"output",
"->",
"box_start",
"(",
"'boxaligncenter usersummarysection'",
".",
"$",
"supendedclass",
")",
";",
"if",
"(",
"$",
"summary",
"->",
"blindmarking",
")",
"{",
"$",
"o",
".=",
"get_string",
"(",
"'hiddenuser'",
",",
"'assign'",
")",
".",
"$",
"summary",
"->",
"uniqueidforuser",
".",
"$",
"suspendedicon",
";",
"}",
"else",
"{",
"$",
"o",
".=",
"$",
"this",
"->",
"output",
"->",
"user_picture",
"(",
"$",
"summary",
"->",
"user",
")",
";",
"$",
"o",
".=",
"$",
"this",
"->",
"output",
"->",
"spacer",
"(",
"array",
"(",
"'width'",
"=>",
"30",
")",
")",
";",
"$",
"urlparams",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"summary",
"->",
"user",
"->",
"id",
",",
"'course'",
"=>",
"$",
"summary",
"->",
"courseid",
")",
";",
"$",
"url",
"=",
"new",
"moodle_url",
"(",
"'/user/view.php'",
",",
"$",
"urlparams",
")",
";",
"$",
"fullname",
"=",
"fullname",
"(",
"$",
"summary",
"->",
"user",
",",
"$",
"summary",
"->",
"viewfullnames",
")",
";",
"$",
"extrainfo",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"summary",
"->",
"extrauserfields",
"as",
"$",
"extrafield",
")",
"{",
"$",
"extrainfo",
"[",
"]",
"=",
"$",
"summary",
"->",
"user",
"->",
"$",
"extrafield",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"extrainfo",
")",
")",
"{",
"$",
"fullname",
".=",
"' ('",
".",
"implode",
"(",
"', '",
",",
"$",
"extrainfo",
")",
".",
"')'",
";",
"}",
"$",
"fullname",
".=",
"$",
"suspendedicon",
";",
"$",
"o",
".=",
"$",
"this",
"->",
"output",
"->",
"action_link",
"(",
"$",
"url",
",",
"$",
"fullname",
")",
";",
"}",
"$",
"o",
".=",
"$",
"this",
"->",
"output",
"->",
"box_end",
"(",
")",
";",
"$",
"o",
".=",
"$",
"this",
"->",
"output",
"->",
"container_end",
"(",
")",
";",
"return",
"$",
"o",
";",
"}"
] | Render the user summary
@param assign_user_summary $summary The user summary to render
@return string | [
"Render",
"the",
"user",
"summary"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/renderer.php#L131-L169 |
213,915 | moodle/moodle | mod/assign/renderer.php | mod_assign_renderer.render_assign_submit_for_grading_page | public function render_assign_submit_for_grading_page($page) {
$o = '';
$o .= $this->output->container_start('submitforgrading');
$o .= $this->output->heading(get_string('confirmsubmissionheading', 'assign'), 3);
$cancelurl = new moodle_url('/mod/assign/view.php', array('id' => $page->coursemoduleid));
if (count($page->notifications)) {
// At least one of the submission plugins is not ready for submission.
$o .= $this->output->heading(get_string('submissionnotready', 'assign'), 4);
foreach ($page->notifications as $notification) {
$o .= $this->output->notification($notification);
}
$o .= $this->output->continue_button($cancelurl);
} else {
// All submission plugins ready - show the confirmation form.
$o .= $this->moodleform($page->confirmform);
}
$o .= $this->output->container_end();
return $o;
} | php | public function render_assign_submit_for_grading_page($page) {
$o = '';
$o .= $this->output->container_start('submitforgrading');
$o .= $this->output->heading(get_string('confirmsubmissionheading', 'assign'), 3);
$cancelurl = new moodle_url('/mod/assign/view.php', array('id' => $page->coursemoduleid));
if (count($page->notifications)) {
// At least one of the submission plugins is not ready for submission.
$o .= $this->output->heading(get_string('submissionnotready', 'assign'), 4);
foreach ($page->notifications as $notification) {
$o .= $this->output->notification($notification);
}
$o .= $this->output->continue_button($cancelurl);
} else {
// All submission plugins ready - show the confirmation form.
$o .= $this->moodleform($page->confirmform);
}
$o .= $this->output->container_end();
return $o;
} | [
"public",
"function",
"render_assign_submit_for_grading_page",
"(",
"$",
"page",
")",
"{",
"$",
"o",
"=",
"''",
";",
"$",
"o",
".=",
"$",
"this",
"->",
"output",
"->",
"container_start",
"(",
"'submitforgrading'",
")",
";",
"$",
"o",
".=",
"$",
"this",
"->",
"output",
"->",
"heading",
"(",
"get_string",
"(",
"'confirmsubmissionheading'",
",",
"'assign'",
")",
",",
"3",
")",
";",
"$",
"cancelurl",
"=",
"new",
"moodle_url",
"(",
"'/mod/assign/view.php'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"page",
"->",
"coursemoduleid",
")",
")",
";",
"if",
"(",
"count",
"(",
"$",
"page",
"->",
"notifications",
")",
")",
"{",
"// At least one of the submission plugins is not ready for submission.",
"$",
"o",
".=",
"$",
"this",
"->",
"output",
"->",
"heading",
"(",
"get_string",
"(",
"'submissionnotready'",
",",
"'assign'",
")",
",",
"4",
")",
";",
"foreach",
"(",
"$",
"page",
"->",
"notifications",
"as",
"$",
"notification",
")",
"{",
"$",
"o",
".=",
"$",
"this",
"->",
"output",
"->",
"notification",
"(",
"$",
"notification",
")",
";",
"}",
"$",
"o",
".=",
"$",
"this",
"->",
"output",
"->",
"continue_button",
"(",
"$",
"cancelurl",
")",
";",
"}",
"else",
"{",
"// All submission plugins ready - show the confirmation form.",
"$",
"o",
".=",
"$",
"this",
"->",
"moodleform",
"(",
"$",
"page",
"->",
"confirmform",
")",
";",
"}",
"$",
"o",
".=",
"$",
"this",
"->",
"output",
"->",
"container_end",
"(",
")",
";",
"return",
"$",
"o",
";",
"}"
] | Render the submit for grading page
@param assign_submit_for_grading_page $page
@return string | [
"Render",
"the",
"submit",
"for",
"grading",
"page"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/renderer.php#L177-L201 |
213,916 | moodle/moodle | mod/assign/renderer.php | mod_assign_renderer.render_assign_header | public function render_assign_header(assign_header $header) {
$o = '';
if ($header->subpage) {
$this->page->navbar->add($header->subpage);
$args = ['contextname' => $header->context->get_context_name(false, true), 'subpage' => $header->subpage];
$title = get_string('subpagetitle', 'assign', $args);
} else {
$title = $header->context->get_context_name(false, true);
}
$courseshortname = $header->context->get_course_context()->get_context_name(false, true);
$title = $courseshortname . ': ' . $title;
$heading = format_string($header->assign->name, false, array('context' => $header->context));
$this->page->set_title($title);
$this->page->set_heading($this->page->course->fullname);
$o .= $this->output->header();
$o .= $this->output->heading($heading);
if ($header->preface) {
$o .= $header->preface;
}
if ($header->showintro) {
$o .= $this->output->box_start('generalbox boxaligncenter', 'intro');
$o .= format_module_intro('assign', $header->assign, $header->coursemoduleid);
$o .= $header->postfix;
$o .= $this->output->box_end();
}
return $o;
} | php | public function render_assign_header(assign_header $header) {
$o = '';
if ($header->subpage) {
$this->page->navbar->add($header->subpage);
$args = ['contextname' => $header->context->get_context_name(false, true), 'subpage' => $header->subpage];
$title = get_string('subpagetitle', 'assign', $args);
} else {
$title = $header->context->get_context_name(false, true);
}
$courseshortname = $header->context->get_course_context()->get_context_name(false, true);
$title = $courseshortname . ': ' . $title;
$heading = format_string($header->assign->name, false, array('context' => $header->context));
$this->page->set_title($title);
$this->page->set_heading($this->page->course->fullname);
$o .= $this->output->header();
$o .= $this->output->heading($heading);
if ($header->preface) {
$o .= $header->preface;
}
if ($header->showintro) {
$o .= $this->output->box_start('generalbox boxaligncenter', 'intro');
$o .= format_module_intro('assign', $header->assign, $header->coursemoduleid);
$o .= $header->postfix;
$o .= $this->output->box_end();
}
return $o;
} | [
"public",
"function",
"render_assign_header",
"(",
"assign_header",
"$",
"header",
")",
"{",
"$",
"o",
"=",
"''",
";",
"if",
"(",
"$",
"header",
"->",
"subpage",
")",
"{",
"$",
"this",
"->",
"page",
"->",
"navbar",
"->",
"add",
"(",
"$",
"header",
"->",
"subpage",
")",
";",
"$",
"args",
"=",
"[",
"'contextname'",
"=>",
"$",
"header",
"->",
"context",
"->",
"get_context_name",
"(",
"false",
",",
"true",
")",
",",
"'subpage'",
"=>",
"$",
"header",
"->",
"subpage",
"]",
";",
"$",
"title",
"=",
"get_string",
"(",
"'subpagetitle'",
",",
"'assign'",
",",
"$",
"args",
")",
";",
"}",
"else",
"{",
"$",
"title",
"=",
"$",
"header",
"->",
"context",
"->",
"get_context_name",
"(",
"false",
",",
"true",
")",
";",
"}",
"$",
"courseshortname",
"=",
"$",
"header",
"->",
"context",
"->",
"get_course_context",
"(",
")",
"->",
"get_context_name",
"(",
"false",
",",
"true",
")",
";",
"$",
"title",
"=",
"$",
"courseshortname",
".",
"': '",
".",
"$",
"title",
";",
"$",
"heading",
"=",
"format_string",
"(",
"$",
"header",
"->",
"assign",
"->",
"name",
",",
"false",
",",
"array",
"(",
"'context'",
"=>",
"$",
"header",
"->",
"context",
")",
")",
";",
"$",
"this",
"->",
"page",
"->",
"set_title",
"(",
"$",
"title",
")",
";",
"$",
"this",
"->",
"page",
"->",
"set_heading",
"(",
"$",
"this",
"->",
"page",
"->",
"course",
"->",
"fullname",
")",
";",
"$",
"o",
".=",
"$",
"this",
"->",
"output",
"->",
"header",
"(",
")",
";",
"$",
"o",
".=",
"$",
"this",
"->",
"output",
"->",
"heading",
"(",
"$",
"heading",
")",
";",
"if",
"(",
"$",
"header",
"->",
"preface",
")",
"{",
"$",
"o",
".=",
"$",
"header",
"->",
"preface",
";",
"}",
"if",
"(",
"$",
"header",
"->",
"showintro",
")",
"{",
"$",
"o",
".=",
"$",
"this",
"->",
"output",
"->",
"box_start",
"(",
"'generalbox boxaligncenter'",
",",
"'intro'",
")",
";",
"$",
"o",
".=",
"format_module_intro",
"(",
"'assign'",
",",
"$",
"header",
"->",
"assign",
",",
"$",
"header",
"->",
"coursemoduleid",
")",
";",
"$",
"o",
".=",
"$",
"header",
"->",
"postfix",
";",
"$",
"o",
".=",
"$",
"this",
"->",
"output",
"->",
"box_end",
"(",
")",
";",
"}",
"return",
"$",
"o",
";",
"}"
] | Render the header.
@param assign_header $header
@return string | [
"Render",
"the",
"header",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/renderer.php#L218-L249 |
213,917 | moodle/moodle | mod/assign/renderer.php | mod_assign_renderer.render_assign_attempt_history_chooser | public function render_assign_attempt_history_chooser(assign_attempt_history_chooser $history) {
$o = '';
$context = $history->export_for_template($this);
$o .= $this->render_from_template('mod_assign/attempt_history_chooser', $context);
return $o;
} | php | public function render_assign_attempt_history_chooser(assign_attempt_history_chooser $history) {
$o = '';
$context = $history->export_for_template($this);
$o .= $this->render_from_template('mod_assign/attempt_history_chooser', $context);
return $o;
} | [
"public",
"function",
"render_assign_attempt_history_chooser",
"(",
"assign_attempt_history_chooser",
"$",
"history",
")",
"{",
"$",
"o",
"=",
"''",
";",
"$",
"context",
"=",
"$",
"history",
"->",
"export_for_template",
"(",
"$",
"this",
")",
";",
"$",
"o",
".=",
"$",
"this",
"->",
"render_from_template",
"(",
"'mod_assign/attempt_history_chooser'",
",",
"$",
"context",
")",
";",
"return",
"$",
"o",
";",
"}"
] | Output the attempt history chooser for this assignment
@param assign_attempt_history_chooser $history
@return string | [
"Output",
"the",
"attempt",
"history",
"chooser",
"for",
"this",
"assignment"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/renderer.php#L996-L1003 |
213,918 | moodle/moodle | mod/assign/renderer.php | mod_assign_renderer.render_assign_grading_table | public function render_assign_grading_table(assign_grading_table $table) {
$o = '';
$o .= $this->output->box_start('boxaligncenter gradingtable');
$this->page->requires->js_init_call('M.mod_assign.init_grading_table', array());
$this->page->requires->string_for_js('nousersselected', 'assign');
$this->page->requires->string_for_js('batchoperationconfirmgrantextension', 'assign');
$this->page->requires->string_for_js('batchoperationconfirmlock', 'assign');
$this->page->requires->string_for_js('batchoperationconfirmremovesubmission', 'assign');
$this->page->requires->string_for_js('batchoperationconfirmreverttodraft', 'assign');
$this->page->requires->string_for_js('batchoperationconfirmunlock', 'assign');
$this->page->requires->string_for_js('batchoperationconfirmaddattempt', 'assign');
$this->page->requires->string_for_js('batchoperationconfirmdownloadselected', 'assign');
$this->page->requires->string_for_js('batchoperationconfirmsetmarkingworkflowstate', 'assign');
$this->page->requires->string_for_js('batchoperationconfirmsetmarkingallocation', 'assign');
$this->page->requires->string_for_js('editaction', 'assign');
foreach ($table->plugingradingbatchoperations as $plugin => $operations) {
foreach ($operations as $operation => $description) {
$this->page->requires->string_for_js('batchoperationconfirm' . $operation,
'assignfeedback_' . $plugin);
}
}
$o .= $this->flexible_table($table, $table->get_rows_per_page(), true);
$o .= $this->output->box_end();
return $o;
} | php | public function render_assign_grading_table(assign_grading_table $table) {
$o = '';
$o .= $this->output->box_start('boxaligncenter gradingtable');
$this->page->requires->js_init_call('M.mod_assign.init_grading_table', array());
$this->page->requires->string_for_js('nousersselected', 'assign');
$this->page->requires->string_for_js('batchoperationconfirmgrantextension', 'assign');
$this->page->requires->string_for_js('batchoperationconfirmlock', 'assign');
$this->page->requires->string_for_js('batchoperationconfirmremovesubmission', 'assign');
$this->page->requires->string_for_js('batchoperationconfirmreverttodraft', 'assign');
$this->page->requires->string_for_js('batchoperationconfirmunlock', 'assign');
$this->page->requires->string_for_js('batchoperationconfirmaddattempt', 'assign');
$this->page->requires->string_for_js('batchoperationconfirmdownloadselected', 'assign');
$this->page->requires->string_for_js('batchoperationconfirmsetmarkingworkflowstate', 'assign');
$this->page->requires->string_for_js('batchoperationconfirmsetmarkingallocation', 'assign');
$this->page->requires->string_for_js('editaction', 'assign');
foreach ($table->plugingradingbatchoperations as $plugin => $operations) {
foreach ($operations as $operation => $description) {
$this->page->requires->string_for_js('batchoperationconfirm' . $operation,
'assignfeedback_' . $plugin);
}
}
$o .= $this->flexible_table($table, $table->get_rows_per_page(), true);
$o .= $this->output->box_end();
return $o;
} | [
"public",
"function",
"render_assign_grading_table",
"(",
"assign_grading_table",
"$",
"table",
")",
"{",
"$",
"o",
"=",
"''",
";",
"$",
"o",
".=",
"$",
"this",
"->",
"output",
"->",
"box_start",
"(",
"'boxaligncenter gradingtable'",
")",
";",
"$",
"this",
"->",
"page",
"->",
"requires",
"->",
"js_init_call",
"(",
"'M.mod_assign.init_grading_table'",
",",
"array",
"(",
")",
")",
";",
"$",
"this",
"->",
"page",
"->",
"requires",
"->",
"string_for_js",
"(",
"'nousersselected'",
",",
"'assign'",
")",
";",
"$",
"this",
"->",
"page",
"->",
"requires",
"->",
"string_for_js",
"(",
"'batchoperationconfirmgrantextension'",
",",
"'assign'",
")",
";",
"$",
"this",
"->",
"page",
"->",
"requires",
"->",
"string_for_js",
"(",
"'batchoperationconfirmlock'",
",",
"'assign'",
")",
";",
"$",
"this",
"->",
"page",
"->",
"requires",
"->",
"string_for_js",
"(",
"'batchoperationconfirmremovesubmission'",
",",
"'assign'",
")",
";",
"$",
"this",
"->",
"page",
"->",
"requires",
"->",
"string_for_js",
"(",
"'batchoperationconfirmreverttodraft'",
",",
"'assign'",
")",
";",
"$",
"this",
"->",
"page",
"->",
"requires",
"->",
"string_for_js",
"(",
"'batchoperationconfirmunlock'",
",",
"'assign'",
")",
";",
"$",
"this",
"->",
"page",
"->",
"requires",
"->",
"string_for_js",
"(",
"'batchoperationconfirmaddattempt'",
",",
"'assign'",
")",
";",
"$",
"this",
"->",
"page",
"->",
"requires",
"->",
"string_for_js",
"(",
"'batchoperationconfirmdownloadselected'",
",",
"'assign'",
")",
";",
"$",
"this",
"->",
"page",
"->",
"requires",
"->",
"string_for_js",
"(",
"'batchoperationconfirmsetmarkingworkflowstate'",
",",
"'assign'",
")",
";",
"$",
"this",
"->",
"page",
"->",
"requires",
"->",
"string_for_js",
"(",
"'batchoperationconfirmsetmarkingallocation'",
",",
"'assign'",
")",
";",
"$",
"this",
"->",
"page",
"->",
"requires",
"->",
"string_for_js",
"(",
"'editaction'",
",",
"'assign'",
")",
";",
"foreach",
"(",
"$",
"table",
"->",
"plugingradingbatchoperations",
"as",
"$",
"plugin",
"=>",
"$",
"operations",
")",
"{",
"foreach",
"(",
"$",
"operations",
"as",
"$",
"operation",
"=>",
"$",
"description",
")",
"{",
"$",
"this",
"->",
"page",
"->",
"requires",
"->",
"string_for_js",
"(",
"'batchoperationconfirm'",
".",
"$",
"operation",
",",
"'assignfeedback_'",
".",
"$",
"plugin",
")",
";",
"}",
"}",
"$",
"o",
".=",
"$",
"this",
"->",
"flexible_table",
"(",
"$",
"table",
",",
"$",
"table",
"->",
"get_rows_per_page",
"(",
")",
",",
"true",
")",
";",
"$",
"o",
".=",
"$",
"this",
"->",
"output",
"->",
"box_end",
"(",
")",
";",
"return",
"$",
"o",
";",
"}"
] | Render the grading table.
@param assign_grading_table $table
@return string | [
"Render",
"the",
"grading",
"table",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/renderer.php#L1237-L1263 |
213,919 | moodle/moodle | mod/assign/renderer.php | mod_assign_renderer.render_assign_course_index_summary | public function render_assign_course_index_summary(assign_course_index_summary $indexsummary) {
$o = '';
$strplural = get_string('modulenameplural', 'assign');
$strsectionname = $indexsummary->courseformatname;
$strduedate = get_string('duedate', 'assign');
$strsubmission = get_string('submission', 'assign');
$strgrade = get_string('grade');
$table = new html_table();
if ($indexsummary->usesections) {
$table->head = array ($strsectionname, $strplural, $strduedate, $strsubmission, $strgrade);
$table->align = array ('left', 'left', 'center', 'right', 'right');
} else {
$table->head = array ($strplural, $strduedate, $strsubmission, $strgrade);
$table->align = array ('left', 'left', 'center', 'right');
}
$table->data = array();
$currentsection = '';
foreach ($indexsummary->assignments as $info) {
$params = array('id' => $info['cmid']);
$link = html_writer::link(new moodle_url('/mod/assign/view.php', $params),
$info['cmname']);
$due = $info['timedue'] ? userdate($info['timedue']) : '-';
$printsection = '';
if ($indexsummary->usesections) {
if ($info['sectionname'] !== $currentsection) {
if ($info['sectionname']) {
$printsection = $info['sectionname'];
}
if ($currentsection !== '') {
$table->data[] = 'hr';
}
$currentsection = $info['sectionname'];
}
}
if ($indexsummary->usesections) {
$row = array($printsection, $link, $due, $info['submissioninfo'], $info['gradeinfo']);
} else {
$row = array($link, $due, $info['submissioninfo'], $info['gradeinfo']);
}
$table->data[] = $row;
}
$o .= html_writer::table($table);
return $o;
} | php | public function render_assign_course_index_summary(assign_course_index_summary $indexsummary) {
$o = '';
$strplural = get_string('modulenameplural', 'assign');
$strsectionname = $indexsummary->courseformatname;
$strduedate = get_string('duedate', 'assign');
$strsubmission = get_string('submission', 'assign');
$strgrade = get_string('grade');
$table = new html_table();
if ($indexsummary->usesections) {
$table->head = array ($strsectionname, $strplural, $strduedate, $strsubmission, $strgrade);
$table->align = array ('left', 'left', 'center', 'right', 'right');
} else {
$table->head = array ($strplural, $strduedate, $strsubmission, $strgrade);
$table->align = array ('left', 'left', 'center', 'right');
}
$table->data = array();
$currentsection = '';
foreach ($indexsummary->assignments as $info) {
$params = array('id' => $info['cmid']);
$link = html_writer::link(new moodle_url('/mod/assign/view.php', $params),
$info['cmname']);
$due = $info['timedue'] ? userdate($info['timedue']) : '-';
$printsection = '';
if ($indexsummary->usesections) {
if ($info['sectionname'] !== $currentsection) {
if ($info['sectionname']) {
$printsection = $info['sectionname'];
}
if ($currentsection !== '') {
$table->data[] = 'hr';
}
$currentsection = $info['sectionname'];
}
}
if ($indexsummary->usesections) {
$row = array($printsection, $link, $due, $info['submissioninfo'], $info['gradeinfo']);
} else {
$row = array($link, $due, $info['submissioninfo'], $info['gradeinfo']);
}
$table->data[] = $row;
}
$o .= html_writer::table($table);
return $o;
} | [
"public",
"function",
"render_assign_course_index_summary",
"(",
"assign_course_index_summary",
"$",
"indexsummary",
")",
"{",
"$",
"o",
"=",
"''",
";",
"$",
"strplural",
"=",
"get_string",
"(",
"'modulenameplural'",
",",
"'assign'",
")",
";",
"$",
"strsectionname",
"=",
"$",
"indexsummary",
"->",
"courseformatname",
";",
"$",
"strduedate",
"=",
"get_string",
"(",
"'duedate'",
",",
"'assign'",
")",
";",
"$",
"strsubmission",
"=",
"get_string",
"(",
"'submission'",
",",
"'assign'",
")",
";",
"$",
"strgrade",
"=",
"get_string",
"(",
"'grade'",
")",
";",
"$",
"table",
"=",
"new",
"html_table",
"(",
")",
";",
"if",
"(",
"$",
"indexsummary",
"->",
"usesections",
")",
"{",
"$",
"table",
"->",
"head",
"=",
"array",
"(",
"$",
"strsectionname",
",",
"$",
"strplural",
",",
"$",
"strduedate",
",",
"$",
"strsubmission",
",",
"$",
"strgrade",
")",
";",
"$",
"table",
"->",
"align",
"=",
"array",
"(",
"'left'",
",",
"'left'",
",",
"'center'",
",",
"'right'",
",",
"'right'",
")",
";",
"}",
"else",
"{",
"$",
"table",
"->",
"head",
"=",
"array",
"(",
"$",
"strplural",
",",
"$",
"strduedate",
",",
"$",
"strsubmission",
",",
"$",
"strgrade",
")",
";",
"$",
"table",
"->",
"align",
"=",
"array",
"(",
"'left'",
",",
"'left'",
",",
"'center'",
",",
"'right'",
")",
";",
"}",
"$",
"table",
"->",
"data",
"=",
"array",
"(",
")",
";",
"$",
"currentsection",
"=",
"''",
";",
"foreach",
"(",
"$",
"indexsummary",
"->",
"assignments",
"as",
"$",
"info",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'id'",
"=>",
"$",
"info",
"[",
"'cmid'",
"]",
")",
";",
"$",
"link",
"=",
"html_writer",
"::",
"link",
"(",
"new",
"moodle_url",
"(",
"'/mod/assign/view.php'",
",",
"$",
"params",
")",
",",
"$",
"info",
"[",
"'cmname'",
"]",
")",
";",
"$",
"due",
"=",
"$",
"info",
"[",
"'timedue'",
"]",
"?",
"userdate",
"(",
"$",
"info",
"[",
"'timedue'",
"]",
")",
":",
"'-'",
";",
"$",
"printsection",
"=",
"''",
";",
"if",
"(",
"$",
"indexsummary",
"->",
"usesections",
")",
"{",
"if",
"(",
"$",
"info",
"[",
"'sectionname'",
"]",
"!==",
"$",
"currentsection",
")",
"{",
"if",
"(",
"$",
"info",
"[",
"'sectionname'",
"]",
")",
"{",
"$",
"printsection",
"=",
"$",
"info",
"[",
"'sectionname'",
"]",
";",
"}",
"if",
"(",
"$",
"currentsection",
"!==",
"''",
")",
"{",
"$",
"table",
"->",
"data",
"[",
"]",
"=",
"'hr'",
";",
"}",
"$",
"currentsection",
"=",
"$",
"info",
"[",
"'sectionname'",
"]",
";",
"}",
"}",
"if",
"(",
"$",
"indexsummary",
"->",
"usesections",
")",
"{",
"$",
"row",
"=",
"array",
"(",
"$",
"printsection",
",",
"$",
"link",
",",
"$",
"due",
",",
"$",
"info",
"[",
"'submissioninfo'",
"]",
",",
"$",
"info",
"[",
"'gradeinfo'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"row",
"=",
"array",
"(",
"$",
"link",
",",
"$",
"due",
",",
"$",
"info",
"[",
"'submissioninfo'",
"]",
",",
"$",
"info",
"[",
"'gradeinfo'",
"]",
")",
";",
"}",
"$",
"table",
"->",
"data",
"[",
"]",
"=",
"$",
"row",
";",
"}",
"$",
"o",
".=",
"html_writer",
"::",
"table",
"(",
"$",
"table",
")",
";",
"return",
"$",
"o",
";",
"}"
] | Render a course index summary
@param assign_course_index_summary $indexsummary
@return string | [
"Render",
"a",
"course",
"index",
"summary"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/renderer.php#L1340-L1390 |
213,920 | moodle/moodle | mod/assign/renderer.php | mod_assign_renderer.flexible_table | protected function flexible_table(flexible_table $table, $rowsperpage, $displaylinks) {
$o = '';
ob_start();
$table->out($rowsperpage, $displaylinks);
$o = ob_get_contents();
ob_end_clean();
return $o;
} | php | protected function flexible_table(flexible_table $table, $rowsperpage, $displaylinks) {
$o = '';
ob_start();
$table->out($rowsperpage, $displaylinks);
$o = ob_get_contents();
ob_end_clean();
return $o;
} | [
"protected",
"function",
"flexible_table",
"(",
"flexible_table",
"$",
"table",
",",
"$",
"rowsperpage",
",",
"$",
"displaylinks",
")",
"{",
"$",
"o",
"=",
"''",
";",
"ob_start",
"(",
")",
";",
"$",
"table",
"->",
"out",
"(",
"$",
"rowsperpage",
",",
"$",
"displaylinks",
")",
";",
"$",
"o",
"=",
"ob_get_contents",
"(",
")",
";",
"ob_end_clean",
"(",
")",
";",
"return",
"$",
"o",
";",
"}"
] | Helper method dealing with the fact we can not just fetch the output of flexible_table
@param flexible_table $table The table to render
@param int $rowsperpage How many assignments to render in a page
@param bool $displaylinks - Whether to render links in the table
(e.g. downloads would not enable this)
@return string HTML | [
"Helper",
"method",
"dealing",
"with",
"the",
"fact",
"we",
"can",
"not",
"just",
"fetch",
"the",
"output",
"of",
"flexible_table"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/renderer.php#L1463-L1472 |
213,921 | moodle/moodle | mod/assign/renderer.php | mod_assign_renderer.render_grading_app | public function render_grading_app(grading_app $app) {
$context = $app->export_for_template($this);
return $this->render_from_template('mod_assign/grading_app', $context);
} | php | public function render_grading_app(grading_app $app) {
$context = $app->export_for_template($this);
return $this->render_from_template('mod_assign/grading_app', $context);
} | [
"public",
"function",
"render_grading_app",
"(",
"grading_app",
"$",
"app",
")",
"{",
"$",
"context",
"=",
"$",
"app",
"->",
"export_for_template",
"(",
"$",
"this",
")",
";",
"return",
"$",
"this",
"->",
"render_from_template",
"(",
"'mod_assign/grading_app'",
",",
"$",
"context",
")",
";",
"}"
] | Defer to template..
@param grading_app $app - All the data to render the grading app. | [
"Defer",
"to",
"template",
".."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/renderer.php#L1496-L1499 |
213,922 | moodle/moodle | lib/xmlize.php | core_xml_parser.startelement | private function startelement($parser, $name, $attrs) {
$current = &$this->current;
$level = &$this->level;
if (!empty($name)) {
if ($level == 0) {
$current[$level][$name] = array();
$current[$level][$name]["@"] = $attrs; // Attribute.
$current[$level][$name]["#"] = array(); // Other tags.
$current[$level + 1] = & $current[$level][$name]["#"];
$level++;
} else {
if (empty($current[$level][$name])) {
$current[$level][$name] = array();
}
$siz = count($current[$level][$name]);
if (!empty($attrs)) {
$current[$level][$name][$siz]["@"] = $attrs; // Attribute.
}
$current[$level][$name][$siz]["#"] = array(); // Other tags.
$current[$level + 1] = & $current[$level][$name][$siz]["#"];
$level++;
}
}
} | php | private function startelement($parser, $name, $attrs) {
$current = &$this->current;
$level = &$this->level;
if (!empty($name)) {
if ($level == 0) {
$current[$level][$name] = array();
$current[$level][$name]["@"] = $attrs; // Attribute.
$current[$level][$name]["#"] = array(); // Other tags.
$current[$level + 1] = & $current[$level][$name]["#"];
$level++;
} else {
if (empty($current[$level][$name])) {
$current[$level][$name] = array();
}
$siz = count($current[$level][$name]);
if (!empty($attrs)) {
$current[$level][$name][$siz]["@"] = $attrs; // Attribute.
}
$current[$level][$name][$siz]["#"] = array(); // Other tags.
$current[$level + 1] = & $current[$level][$name][$siz]["#"];
$level++;
}
}
} | [
"private",
"function",
"startelement",
"(",
"$",
"parser",
",",
"$",
"name",
",",
"$",
"attrs",
")",
"{",
"$",
"current",
"=",
"&",
"$",
"this",
"->",
"current",
";",
"$",
"level",
"=",
"&",
"$",
"this",
"->",
"level",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"if",
"(",
"$",
"level",
"==",
"0",
")",
"{",
"$",
"current",
"[",
"$",
"level",
"]",
"[",
"$",
"name",
"]",
"=",
"array",
"(",
")",
";",
"$",
"current",
"[",
"$",
"level",
"]",
"[",
"$",
"name",
"]",
"[",
"\"@\"",
"]",
"=",
"$",
"attrs",
";",
"// Attribute.",
"$",
"current",
"[",
"$",
"level",
"]",
"[",
"$",
"name",
"]",
"[",
"\"#\"",
"]",
"=",
"array",
"(",
")",
";",
"// Other tags.",
"$",
"current",
"[",
"$",
"level",
"+",
"1",
"]",
"=",
"&",
"$",
"current",
"[",
"$",
"level",
"]",
"[",
"$",
"name",
"]",
"[",
"\"#\"",
"]",
";",
"$",
"level",
"++",
";",
"}",
"else",
"{",
"if",
"(",
"empty",
"(",
"$",
"current",
"[",
"$",
"level",
"]",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"current",
"[",
"$",
"level",
"]",
"[",
"$",
"name",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"siz",
"=",
"count",
"(",
"$",
"current",
"[",
"$",
"level",
"]",
"[",
"$",
"name",
"]",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"attrs",
")",
")",
"{",
"$",
"current",
"[",
"$",
"level",
"]",
"[",
"$",
"name",
"]",
"[",
"$",
"siz",
"]",
"[",
"\"@\"",
"]",
"=",
"$",
"attrs",
";",
"// Attribute.",
"}",
"$",
"current",
"[",
"$",
"level",
"]",
"[",
"$",
"name",
"]",
"[",
"$",
"siz",
"]",
"[",
"\"#\"",
"]",
"=",
"array",
"(",
")",
";",
"// Other tags.",
"$",
"current",
"[",
"$",
"level",
"+",
"1",
"]",
"=",
"&",
"$",
"current",
"[",
"$",
"level",
"]",
"[",
"$",
"name",
"]",
"[",
"$",
"siz",
"]",
"[",
"\"#\"",
"]",
";",
"$",
"level",
"++",
";",
"}",
"}",
"}"
] | Is called when tags are opened.
Note: Used by xml element handler as callback.
@author Kilian Singer
@param resource $parser The XML parser resource.
@param string $name The XML source to parse.
@param array $attrs Stores attributes of XML tag. | [
"Is",
"called",
"when",
"tags",
"are",
"opened",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/xmlize.php#L101-L124 |
213,923 | moodle/moodle | lib/xmlize.php | core_xml_parser.endelement | private function endelement($parser, $name) {
$current = &$this->current;
$level = &$this->level;
if (!empty($name)) {
if (empty($current[$level])) {
$current[$level] = '';
} else if (array_key_exists(0, $current[$level])) {
if (count($current[$level]) == 1) {
$current[$level] = $current[$level][0]; // We remove array index if we only have a single entry.
}
}
$level--;
}
} | php | private function endelement($parser, $name) {
$current = &$this->current;
$level = &$this->level;
if (!empty($name)) {
if (empty($current[$level])) {
$current[$level] = '';
} else if (array_key_exists(0, $current[$level])) {
if (count($current[$level]) == 1) {
$current[$level] = $current[$level][0]; // We remove array index if we only have a single entry.
}
}
$level--;
}
} | [
"private",
"function",
"endelement",
"(",
"$",
"parser",
",",
"$",
"name",
")",
"{",
"$",
"current",
"=",
"&",
"$",
"this",
"->",
"current",
";",
"$",
"level",
"=",
"&",
"$",
"this",
"->",
"level",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"name",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"current",
"[",
"$",
"level",
"]",
")",
")",
"{",
"$",
"current",
"[",
"$",
"level",
"]",
"=",
"''",
";",
"}",
"else",
"if",
"(",
"array_key_exists",
"(",
"0",
",",
"$",
"current",
"[",
"$",
"level",
"]",
")",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"current",
"[",
"$",
"level",
"]",
")",
"==",
"1",
")",
"{",
"$",
"current",
"[",
"$",
"level",
"]",
"=",
"$",
"current",
"[",
"$",
"level",
"]",
"[",
"0",
"]",
";",
"// We remove array index if we only have a single entry.",
"}",
"}",
"$",
"level",
"--",
";",
"}",
"}"
] | Is called when tags are closed.
Note: Used by xml element handler as callback.
@author Kilian Singer
@param resource $parser The XML parser resource.
@param string $name The XML source to parse. | [
"Is",
"called",
"when",
"tags",
"are",
"closed",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/xmlize.php#L135-L149 |
213,924 | moodle/moodle | lib/xmlize.php | core_xml_parser.characterdata | private function characterdata($parser, $data) {
$current = &$this->current;
$level = &$this->level;
if (($data == "0") || (!empty($data) && trim($data) != "")) {
$siz = count($current[$level]);
if ($siz == 0) {
$current[$level][0] = $data;
} else {
$key = max(array_keys($current[$level]));
if (is_int($key)) {
end($current[$level]);
if (is_int(key($current[$level]))) { // If last index is nummeric we have CDATA and concat.
$current[$level][$key] = $current[$level][$key] . $data;
} else {
$current[$level][$key + 1] = $data; // Otherwise we make a new key.
}
} else {
$current[$level][0] = $data;
}
}
}
} | php | private function characterdata($parser, $data) {
$current = &$this->current;
$level = &$this->level;
if (($data == "0") || (!empty($data) && trim($data) != "")) {
$siz = count($current[$level]);
if ($siz == 0) {
$current[$level][0] = $data;
} else {
$key = max(array_keys($current[$level]));
if (is_int($key)) {
end($current[$level]);
if (is_int(key($current[$level]))) { // If last index is nummeric we have CDATA and concat.
$current[$level][$key] = $current[$level][$key] . $data;
} else {
$current[$level][$key + 1] = $data; // Otherwise we make a new key.
}
} else {
$current[$level][0] = $data;
}
}
}
} | [
"private",
"function",
"characterdata",
"(",
"$",
"parser",
",",
"$",
"data",
")",
"{",
"$",
"current",
"=",
"&",
"$",
"this",
"->",
"current",
";",
"$",
"level",
"=",
"&",
"$",
"this",
"->",
"level",
";",
"if",
"(",
"(",
"$",
"data",
"==",
"\"0\"",
")",
"||",
"(",
"!",
"empty",
"(",
"$",
"data",
")",
"&&",
"trim",
"(",
"$",
"data",
")",
"!=",
"\"\"",
")",
")",
"{",
"$",
"siz",
"=",
"count",
"(",
"$",
"current",
"[",
"$",
"level",
"]",
")",
";",
"if",
"(",
"$",
"siz",
"==",
"0",
")",
"{",
"$",
"current",
"[",
"$",
"level",
"]",
"[",
"0",
"]",
"=",
"$",
"data",
";",
"}",
"else",
"{",
"$",
"key",
"=",
"max",
"(",
"array_keys",
"(",
"$",
"current",
"[",
"$",
"level",
"]",
")",
")",
";",
"if",
"(",
"is_int",
"(",
"$",
"key",
")",
")",
"{",
"end",
"(",
"$",
"current",
"[",
"$",
"level",
"]",
")",
";",
"if",
"(",
"is_int",
"(",
"key",
"(",
"$",
"current",
"[",
"$",
"level",
"]",
")",
")",
")",
"{",
"// If last index is nummeric we have CDATA and concat.",
"$",
"current",
"[",
"$",
"level",
"]",
"[",
"$",
"key",
"]",
"=",
"$",
"current",
"[",
"$",
"level",
"]",
"[",
"$",
"key",
"]",
".",
"$",
"data",
";",
"}",
"else",
"{",
"$",
"current",
"[",
"$",
"level",
"]",
"[",
"$",
"key",
"+",
"1",
"]",
"=",
"$",
"data",
";",
"// Otherwise we make a new key.",
"}",
"}",
"else",
"{",
"$",
"current",
"[",
"$",
"level",
"]",
"[",
"0",
"]",
"=",
"$",
"data",
";",
"}",
"}",
"}",
"}"
] | Is called for text between the start and the end of tags.
Note: Used by xml element handler as callback.
@author Kilian Singer
@param resource $parser The XML parser resource.
@param string $data The XML source to parse. | [
"Is",
"called",
"for",
"text",
"between",
"the",
"start",
"and",
"the",
"end",
"of",
"tags",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/xmlize.php#L159-L180 |
213,925 | moodle/moodle | lib/xmlize.php | core_xml_parser.parse | public function parse($data, $whitespace = 1, $encoding = 'UTF-8', $reporterrors = false) {
$data = trim($data);
$this->xml = array();
$this->current = array();
$this->level = 0;
$this->current[0] = & $this->xml;
$parser = xml_parser_create($encoding);
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, $whitespace);
xml_set_element_handler($parser, [$this, "startelement"], [$this, "endelement"]);
xml_set_character_data_handler($parser, [$this, "characterdata"]);
// Start parsing an xml document.
for ($i = 0; $i < strlen($data); $i += 4096) {
if (!xml_parse($parser, substr($data, $i, 4096))) {
break;
}
}
if ($reporterrors) {
$errorcode = xml_get_error_code($parser);
if ($errorcode) {
$exception = new xml_format_exception(xml_error_string($errorcode),
xml_get_current_line_number($parser),
xml_get_current_column_number($parser));
xml_parser_free($parser);
throw $exception;
}
}
xml_parser_free($parser); // Deletes the parser.
if (empty($this->xml)) { // XML file is invalid or empty, return false.
return false;
}
return $this->xml;
} | php | public function parse($data, $whitespace = 1, $encoding = 'UTF-8', $reporterrors = false) {
$data = trim($data);
$this->xml = array();
$this->current = array();
$this->level = 0;
$this->current[0] = & $this->xml;
$parser = xml_parser_create($encoding);
xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, $whitespace);
xml_set_element_handler($parser, [$this, "startelement"], [$this, "endelement"]);
xml_set_character_data_handler($parser, [$this, "characterdata"]);
// Start parsing an xml document.
for ($i = 0; $i < strlen($data); $i += 4096) {
if (!xml_parse($parser, substr($data, $i, 4096))) {
break;
}
}
if ($reporterrors) {
$errorcode = xml_get_error_code($parser);
if ($errorcode) {
$exception = new xml_format_exception(xml_error_string($errorcode),
xml_get_current_line_number($parser),
xml_get_current_column_number($parser));
xml_parser_free($parser);
throw $exception;
}
}
xml_parser_free($parser); // Deletes the parser.
if (empty($this->xml)) { // XML file is invalid or empty, return false.
return false;
}
return $this->xml;
} | [
"public",
"function",
"parse",
"(",
"$",
"data",
",",
"$",
"whitespace",
"=",
"1",
",",
"$",
"encoding",
"=",
"'UTF-8'",
",",
"$",
"reporterrors",
"=",
"false",
")",
"{",
"$",
"data",
"=",
"trim",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"xml",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"current",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"level",
"=",
"0",
";",
"$",
"this",
"->",
"current",
"[",
"0",
"]",
"=",
"&",
"$",
"this",
"->",
"xml",
";",
"$",
"parser",
"=",
"xml_parser_create",
"(",
"$",
"encoding",
")",
";",
"xml_parser_set_option",
"(",
"$",
"parser",
",",
"XML_OPTION_CASE_FOLDING",
",",
"0",
")",
";",
"xml_parser_set_option",
"(",
"$",
"parser",
",",
"XML_OPTION_SKIP_WHITE",
",",
"$",
"whitespace",
")",
";",
"xml_set_element_handler",
"(",
"$",
"parser",
",",
"[",
"$",
"this",
",",
"\"startelement\"",
"]",
",",
"[",
"$",
"this",
",",
"\"endelement\"",
"]",
")",
";",
"xml_set_character_data_handler",
"(",
"$",
"parser",
",",
"[",
"$",
"this",
",",
"\"characterdata\"",
"]",
")",
";",
"// Start parsing an xml document.",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"strlen",
"(",
"$",
"data",
")",
";",
"$",
"i",
"+=",
"4096",
")",
"{",
"if",
"(",
"!",
"xml_parse",
"(",
"$",
"parser",
",",
"substr",
"(",
"$",
"data",
",",
"$",
"i",
",",
"4096",
")",
")",
")",
"{",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"reporterrors",
")",
"{",
"$",
"errorcode",
"=",
"xml_get_error_code",
"(",
"$",
"parser",
")",
";",
"if",
"(",
"$",
"errorcode",
")",
"{",
"$",
"exception",
"=",
"new",
"xml_format_exception",
"(",
"xml_error_string",
"(",
"$",
"errorcode",
")",
",",
"xml_get_current_line_number",
"(",
"$",
"parser",
")",
",",
"xml_get_current_column_number",
"(",
"$",
"parser",
")",
")",
";",
"xml_parser_free",
"(",
"$",
"parser",
")",
";",
"throw",
"$",
"exception",
";",
"}",
"}",
"xml_parser_free",
"(",
"$",
"parser",
")",
";",
"// Deletes the parser.",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"xml",
")",
")",
"{",
"// XML file is invalid or empty, return false.",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"xml",
";",
"}"
] | Parses XML string.
Note: Interface is kept equal to previous version.
@author Kilian Singer
@param string $data the XML source to parse.
@param int $whitespace If set to 1 allows the parser to skip "space" characters in xml document. Default is 1
@param string $encoding Specify an OUTPUT encoding. If not specified, it defaults to UTF-8.
@param bool $reporterrors if set to true, then a {@link xml_format_exception}
exception will be thrown if the XML is not well-formed. Otherwise errors are ignored.
@return array representation of the parsed XML. | [
"Parses",
"XML",
"string",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/xmlize.php#L195-L227 |
213,926 | moodle/moodle | mod/resource/backup/moodle1/lib.php | moodle1_mod_resource_handler.on_resource_end | public function on_resource_end(array $data) {
if ($successor = $this->get_successor($data['type'], $data['reference'])) {
$successor->on_legacy_resource_end($data);
}
} | php | public function on_resource_end(array $data) {
if ($successor = $this->get_successor($data['type'], $data['reference'])) {
$successor->on_legacy_resource_end($data);
}
} | [
"public",
"function",
"on_resource_end",
"(",
"array",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"successor",
"=",
"$",
"this",
"->",
"get_successor",
"(",
"$",
"data",
"[",
"'type'",
"]",
",",
"$",
"data",
"[",
"'reference'",
"]",
")",
")",
"{",
"$",
"successor",
"->",
"on_legacy_resource_end",
"(",
"$",
"data",
")",
";",
"}",
"}"
] | Give succesors a chance to finish their job | [
"Give",
"succesors",
"a",
"chance",
"to",
"finish",
"their",
"job"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/resource/backup/moodle1/lib.php#L235-L239 |
213,927 | moodle/moodle | mod/resource/backup/moodle1/lib.php | moodle1_mod_resource_handler.get_successor | protected function get_successor($type, $reference) {
switch ($type) {
case 'text':
case 'html':
$name = 'page';
break;
case 'directory':
$name = 'folder';
break;
case 'ims':
$name = 'imscp';
break;
case 'file':
// if starts with $@FILEPHP@$ then it is URL link to a local course file
// to be migrated to the new resource module
if (strpos($reference, '$@FILEPHP@$') === 0) {
$name = null;
break;
}
// if http:// https:// ftp:// OR starts with slash need to be converted to URL
if (strpos($reference, '://') or strpos($reference, '/') === 0) {
$name = 'url';
} else {
$name = null;
}
break;
default:
throw new moodle1_convert_exception('unknown_resource_successor', $type);
}
if (is_null($name)) {
return null;
}
if (!isset($this->successors[$name])) {
$this->log('preparing resource successor handler', backup::LOG_DEBUG, $name);
$class = 'moodle1_mod_'.$name.'_handler';
$this->successors[$name] = new $class($this->converter, 'mod', $name);
// add the successor into the modlist stash
$modnames = $this->converter->get_stash('modnameslist');
$modnames[] = $name;
$modnames = array_unique($modnames); // should not be needed but just in case
$this->converter->set_stash('modnameslist', $modnames);
// add the successor's modinfo stash
$modinfo = $this->converter->get_stash('modinfo_resource');
$modinfo['name'] = $name;
$modinfo['instances'] = array();
$this->converter->set_stash('modinfo_'.$name, $modinfo);
}
return $this->successors[$name];
} | php | protected function get_successor($type, $reference) {
switch ($type) {
case 'text':
case 'html':
$name = 'page';
break;
case 'directory':
$name = 'folder';
break;
case 'ims':
$name = 'imscp';
break;
case 'file':
// if starts with $@FILEPHP@$ then it is URL link to a local course file
// to be migrated to the new resource module
if (strpos($reference, '$@FILEPHP@$') === 0) {
$name = null;
break;
}
// if http:// https:// ftp:// OR starts with slash need to be converted to URL
if (strpos($reference, '://') or strpos($reference, '/') === 0) {
$name = 'url';
} else {
$name = null;
}
break;
default:
throw new moodle1_convert_exception('unknown_resource_successor', $type);
}
if (is_null($name)) {
return null;
}
if (!isset($this->successors[$name])) {
$this->log('preparing resource successor handler', backup::LOG_DEBUG, $name);
$class = 'moodle1_mod_'.$name.'_handler';
$this->successors[$name] = new $class($this->converter, 'mod', $name);
// add the successor into the modlist stash
$modnames = $this->converter->get_stash('modnameslist');
$modnames[] = $name;
$modnames = array_unique($modnames); // should not be needed but just in case
$this->converter->set_stash('modnameslist', $modnames);
// add the successor's modinfo stash
$modinfo = $this->converter->get_stash('modinfo_resource');
$modinfo['name'] = $name;
$modinfo['instances'] = array();
$this->converter->set_stash('modinfo_'.$name, $modinfo);
}
return $this->successors[$name];
} | [
"protected",
"function",
"get_successor",
"(",
"$",
"type",
",",
"$",
"reference",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'text'",
":",
"case",
"'html'",
":",
"$",
"name",
"=",
"'page'",
";",
"break",
";",
"case",
"'directory'",
":",
"$",
"name",
"=",
"'folder'",
";",
"break",
";",
"case",
"'ims'",
":",
"$",
"name",
"=",
"'imscp'",
";",
"break",
";",
"case",
"'file'",
":",
"// if starts with $@FILEPHP@$ then it is URL link to a local course file",
"// to be migrated to the new resource module",
"if",
"(",
"strpos",
"(",
"$",
"reference",
",",
"'$@FILEPHP@$'",
")",
"===",
"0",
")",
"{",
"$",
"name",
"=",
"null",
";",
"break",
";",
"}",
"// if http:// https:// ftp:// OR starts with slash need to be converted to URL",
"if",
"(",
"strpos",
"(",
"$",
"reference",
",",
"'://'",
")",
"or",
"strpos",
"(",
"$",
"reference",
",",
"'/'",
")",
"===",
"0",
")",
"{",
"$",
"name",
"=",
"'url'",
";",
"}",
"else",
"{",
"$",
"name",
"=",
"null",
";",
"}",
"break",
";",
"default",
":",
"throw",
"new",
"moodle1_convert_exception",
"(",
"'unknown_resource_successor'",
",",
"$",
"type",
")",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"name",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"successors",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"log",
"(",
"'preparing resource successor handler'",
",",
"backup",
"::",
"LOG_DEBUG",
",",
"$",
"name",
")",
";",
"$",
"class",
"=",
"'moodle1_mod_'",
".",
"$",
"name",
".",
"'_handler'",
";",
"$",
"this",
"->",
"successors",
"[",
"$",
"name",
"]",
"=",
"new",
"$",
"class",
"(",
"$",
"this",
"->",
"converter",
",",
"'mod'",
",",
"$",
"name",
")",
";",
"// add the successor into the modlist stash",
"$",
"modnames",
"=",
"$",
"this",
"->",
"converter",
"->",
"get_stash",
"(",
"'modnameslist'",
")",
";",
"$",
"modnames",
"[",
"]",
"=",
"$",
"name",
";",
"$",
"modnames",
"=",
"array_unique",
"(",
"$",
"modnames",
")",
";",
"// should not be needed but just in case",
"$",
"this",
"->",
"converter",
"->",
"set_stash",
"(",
"'modnameslist'",
",",
"$",
"modnames",
")",
";",
"// add the successor's modinfo stash",
"$",
"modinfo",
"=",
"$",
"this",
"->",
"converter",
"->",
"get_stash",
"(",
"'modinfo_resource'",
")",
";",
"$",
"modinfo",
"[",
"'name'",
"]",
"=",
"$",
"name",
";",
"$",
"modinfo",
"[",
"'instances'",
"]",
"=",
"array",
"(",
")",
";",
"$",
"this",
"->",
"converter",
"->",
"set_stash",
"(",
"'modinfo_'",
".",
"$",
"name",
",",
"$",
"modinfo",
")",
";",
"}",
"return",
"$",
"this",
"->",
"successors",
"[",
"$",
"name",
"]",
";",
"}"
] | Returns the handler of the new 2.0 mod type according the given type of the legacy 1.9 resource
@param string $type the value of the 'type' field in 1.9 resource
@param string $reference a file path. Necessary to differentiate files from web URLs
@throws moodle1_convert_exception for the unknown types
@return null|moodle1_mod_handler the instance of the handler, or null if the type does not have a successor | [
"Returns",
"the",
"handler",
"of",
"the",
"new",
"2",
".",
"0",
"mod",
"type",
"according",
"the",
"given",
"type",
"of",
"the",
"legacy",
"1",
".",
"9",
"resource"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/resource/backup/moodle1/lib.php#L251-L305 |
213,928 | moodle/moodle | user/renderer.php | core_user_renderer.user_list | public function user_list($userlist, $exclusivemode) {
$tagfeed = new core_tag\output\tagfeed();
foreach ($userlist as $user) {
$userpicture = $this->output->user_picture($user, array('size' => $exclusivemode ? 100 : 35));
$fullname = fullname($user);
if (user_can_view_profile($user)) {
$profilelink = new moodle_url('/user/view.php', array('id' => $user->id));
$fullname = html_writer::link($profilelink, $fullname);
}
$tagfeed->add($userpicture, $fullname);
}
$items = $tagfeed->export_for_template($this->output);
if ($exclusivemode) {
$output = '<div><ul class="inline-list">';
foreach ($items['items'] as $item) {
$output .= '<li><div class="user-box">'. $item['img'] . $item['heading'] ."</div></li>\n";
}
$output .= "</ul></div>\n";
return $output;
}
return $this->output->render_from_template('core_tag/tagfeed', $items);
} | php | public function user_list($userlist, $exclusivemode) {
$tagfeed = new core_tag\output\tagfeed();
foreach ($userlist as $user) {
$userpicture = $this->output->user_picture($user, array('size' => $exclusivemode ? 100 : 35));
$fullname = fullname($user);
if (user_can_view_profile($user)) {
$profilelink = new moodle_url('/user/view.php', array('id' => $user->id));
$fullname = html_writer::link($profilelink, $fullname);
}
$tagfeed->add($userpicture, $fullname);
}
$items = $tagfeed->export_for_template($this->output);
if ($exclusivemode) {
$output = '<div><ul class="inline-list">';
foreach ($items['items'] as $item) {
$output .= '<li><div class="user-box">'. $item['img'] . $item['heading'] ."</div></li>\n";
}
$output .= "</ul></div>\n";
return $output;
}
return $this->output->render_from_template('core_tag/tagfeed', $items);
} | [
"public",
"function",
"user_list",
"(",
"$",
"userlist",
",",
"$",
"exclusivemode",
")",
"{",
"$",
"tagfeed",
"=",
"new",
"core_tag",
"\\",
"output",
"\\",
"tagfeed",
"(",
")",
";",
"foreach",
"(",
"$",
"userlist",
"as",
"$",
"user",
")",
"{",
"$",
"userpicture",
"=",
"$",
"this",
"->",
"output",
"->",
"user_picture",
"(",
"$",
"user",
",",
"array",
"(",
"'size'",
"=>",
"$",
"exclusivemode",
"?",
"100",
":",
"35",
")",
")",
";",
"$",
"fullname",
"=",
"fullname",
"(",
"$",
"user",
")",
";",
"if",
"(",
"user_can_view_profile",
"(",
"$",
"user",
")",
")",
"{",
"$",
"profilelink",
"=",
"new",
"moodle_url",
"(",
"'/user/view.php'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"user",
"->",
"id",
")",
")",
";",
"$",
"fullname",
"=",
"html_writer",
"::",
"link",
"(",
"$",
"profilelink",
",",
"$",
"fullname",
")",
";",
"}",
"$",
"tagfeed",
"->",
"add",
"(",
"$",
"userpicture",
",",
"$",
"fullname",
")",
";",
"}",
"$",
"items",
"=",
"$",
"tagfeed",
"->",
"export_for_template",
"(",
"$",
"this",
"->",
"output",
")",
";",
"if",
"(",
"$",
"exclusivemode",
")",
"{",
"$",
"output",
"=",
"'<div><ul class=\"inline-list\">'",
";",
"foreach",
"(",
"$",
"items",
"[",
"'items'",
"]",
"as",
"$",
"item",
")",
"{",
"$",
"output",
".=",
"'<li><div class=\"user-box\">'",
".",
"$",
"item",
"[",
"'img'",
"]",
".",
"$",
"item",
"[",
"'heading'",
"]",
".",
"\"</div></li>\\n\"",
";",
"}",
"$",
"output",
".=",
"\"</ul></div>\\n\"",
";",
"return",
"$",
"output",
";",
"}",
"return",
"$",
"this",
"->",
"output",
"->",
"render_from_template",
"(",
"'core_tag/tagfeed'",
",",
"$",
"items",
")",
";",
"}"
] | Displays the list of tagged users
@param array $userlist
@param bool $exclusivemode if set to true it means that no other entities tagged with this tag
are displayed on the page and the per-page limit may be bigger
@return string | [
"Displays",
"the",
"list",
"of",
"tagged",
"users"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/renderer.php#L86-L110 |
213,929 | moodle/moodle | user/renderer.php | core_user_renderer.format_filter_option | protected function format_filter_option($filtertype, $criteria, $value, $label) {
$optionlabel = get_string('filteroption', 'moodle', (object)['criteria' => $criteria, 'value' => $label]);
$optionvalue = "$filtertype:$value";
return [$optionvalue => $optionlabel];
} | php | protected function format_filter_option($filtertype, $criteria, $value, $label) {
$optionlabel = get_string('filteroption', 'moodle', (object)['criteria' => $criteria, 'value' => $label]);
$optionvalue = "$filtertype:$value";
return [$optionvalue => $optionlabel];
} | [
"protected",
"function",
"format_filter_option",
"(",
"$",
"filtertype",
",",
"$",
"criteria",
",",
"$",
"value",
",",
"$",
"label",
")",
"{",
"$",
"optionlabel",
"=",
"get_string",
"(",
"'filteroption'",
",",
"'moodle'",
",",
"(",
"object",
")",
"[",
"'criteria'",
"=>",
"$",
"criteria",
",",
"'value'",
"=>",
"$",
"label",
"]",
")",
";",
"$",
"optionvalue",
"=",
"\"$filtertype:$value\"",
";",
"return",
"[",
"$",
"optionvalue",
"=>",
"$",
"optionlabel",
"]",
";",
"}"
] | Returns a formatted filter option.
@param int $filtertype The filter type (e.g. status, role, group, enrolment, last access).
@param string $criteria The string label of the filter type.
@param int $value The value for the filter option.
@param string $label The string representation of the filter option's value.
@return array The formatted option with the ['filtertype:value' => 'criteria: label'] format. | [
"Returns",
"a",
"formatted",
"filter",
"option",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/renderer.php#L272-L276 |
213,930 | moodle/moodle | user/renderer.php | core_user_renderer.handle_missing_applied_filters | private function handle_missing_applied_filters($filtersapplied, $filteroptions) {
global $DB;
foreach ($filtersapplied as $filter) {
if (!array_key_exists($filter, $filteroptions)) {
$filtervalue = explode(':', $filter);
if (count($filtervalue) !== 2) {
continue;
}
$key = $filtervalue[0];
$value = $filtervalue[1];
switch($key) {
case USER_FILTER_LAST_ACCESS:
$now = usergetmidnight(time());
$criteria = get_string('usersnoaccesssince');
// Days.
for ($i = 1; $i < 7; $i++) {
$timestamp = strtotime('-' . $i . ' days', $now);
if ($timestamp < $value) {
break;
}
$val = get_string('numdays', 'moodle', $i);
$filteroptions += $this->format_filter_option(USER_FILTER_LAST_ACCESS, $criteria, $timestamp, $val);
}
// Weeks.
for ($i = 1; $i < 10; $i++) {
$timestamp = strtotime('-'.$i.' weeks', $now);
if ($timestamp < $value) {
break;
}
$val = get_string('numweeks', 'moodle', $i);
$filteroptions += $this->format_filter_option(USER_FILTER_LAST_ACCESS, $criteria, $timestamp, $val);
}
// Months.
for ($i = 2; $i < 12; $i++) {
$timestamp = strtotime('-'.$i.' months', $now);
if ($timestamp < $value) {
break;
}
$val = get_string('nummonths', 'moodle', $i);
$filteroptions += $this->format_filter_option(USER_FILTER_LAST_ACCESS, $criteria, $timestamp, $val);
}
// Try a year.
$timestamp = strtotime('-1 year', $now);
if ($timestamp >= $value) {
$val = get_string('numyear', 'moodle', 1);
$filteroptions += $this->format_filter_option(USER_FILTER_LAST_ACCESS, $criteria, $timestamp, $val);
}
break;
case USER_FILTER_ROLE:
$criteria = get_string('role');
if ($role = $DB->get_record('role', array('id' => $value))) {
$role = role_get_name($role);
$filteroptions += $this->format_filter_option(USER_FILTER_ROLE, $criteria, $value, $role);
}
break;
}
}
}
return $filteroptions;
} | php | private function handle_missing_applied_filters($filtersapplied, $filteroptions) {
global $DB;
foreach ($filtersapplied as $filter) {
if (!array_key_exists($filter, $filteroptions)) {
$filtervalue = explode(':', $filter);
if (count($filtervalue) !== 2) {
continue;
}
$key = $filtervalue[0];
$value = $filtervalue[1];
switch($key) {
case USER_FILTER_LAST_ACCESS:
$now = usergetmidnight(time());
$criteria = get_string('usersnoaccesssince');
// Days.
for ($i = 1; $i < 7; $i++) {
$timestamp = strtotime('-' . $i . ' days', $now);
if ($timestamp < $value) {
break;
}
$val = get_string('numdays', 'moodle', $i);
$filteroptions += $this->format_filter_option(USER_FILTER_LAST_ACCESS, $criteria, $timestamp, $val);
}
// Weeks.
for ($i = 1; $i < 10; $i++) {
$timestamp = strtotime('-'.$i.' weeks', $now);
if ($timestamp < $value) {
break;
}
$val = get_string('numweeks', 'moodle', $i);
$filteroptions += $this->format_filter_option(USER_FILTER_LAST_ACCESS, $criteria, $timestamp, $val);
}
// Months.
for ($i = 2; $i < 12; $i++) {
$timestamp = strtotime('-'.$i.' months', $now);
if ($timestamp < $value) {
break;
}
$val = get_string('nummonths', 'moodle', $i);
$filteroptions += $this->format_filter_option(USER_FILTER_LAST_ACCESS, $criteria, $timestamp, $val);
}
// Try a year.
$timestamp = strtotime('-1 year', $now);
if ($timestamp >= $value) {
$val = get_string('numyear', 'moodle', 1);
$filteroptions += $this->format_filter_option(USER_FILTER_LAST_ACCESS, $criteria, $timestamp, $val);
}
break;
case USER_FILTER_ROLE:
$criteria = get_string('role');
if ($role = $DB->get_record('role', array('id' => $value))) {
$role = role_get_name($role);
$filteroptions += $this->format_filter_option(USER_FILTER_ROLE, $criteria, $value, $role);
}
break;
}
}
}
return $filteroptions;
} | [
"private",
"function",
"handle_missing_applied_filters",
"(",
"$",
"filtersapplied",
",",
"$",
"filteroptions",
")",
"{",
"global",
"$",
"DB",
";",
"foreach",
"(",
"$",
"filtersapplied",
"as",
"$",
"filter",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"filter",
",",
"$",
"filteroptions",
")",
")",
"{",
"$",
"filtervalue",
"=",
"explode",
"(",
"':'",
",",
"$",
"filter",
")",
";",
"if",
"(",
"count",
"(",
"$",
"filtervalue",
")",
"!==",
"2",
")",
"{",
"continue",
";",
"}",
"$",
"key",
"=",
"$",
"filtervalue",
"[",
"0",
"]",
";",
"$",
"value",
"=",
"$",
"filtervalue",
"[",
"1",
"]",
";",
"switch",
"(",
"$",
"key",
")",
"{",
"case",
"USER_FILTER_LAST_ACCESS",
":",
"$",
"now",
"=",
"usergetmidnight",
"(",
"time",
"(",
")",
")",
";",
"$",
"criteria",
"=",
"get_string",
"(",
"'usersnoaccesssince'",
")",
";",
"// Days.",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<",
"7",
";",
"$",
"i",
"++",
")",
"{",
"$",
"timestamp",
"=",
"strtotime",
"(",
"'-'",
".",
"$",
"i",
".",
"' days'",
",",
"$",
"now",
")",
";",
"if",
"(",
"$",
"timestamp",
"<",
"$",
"value",
")",
"{",
"break",
";",
"}",
"$",
"val",
"=",
"get_string",
"(",
"'numdays'",
",",
"'moodle'",
",",
"$",
"i",
")",
";",
"$",
"filteroptions",
"+=",
"$",
"this",
"->",
"format_filter_option",
"(",
"USER_FILTER_LAST_ACCESS",
",",
"$",
"criteria",
",",
"$",
"timestamp",
",",
"$",
"val",
")",
";",
"}",
"// Weeks.",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<",
"10",
";",
"$",
"i",
"++",
")",
"{",
"$",
"timestamp",
"=",
"strtotime",
"(",
"'-'",
".",
"$",
"i",
".",
"' weeks'",
",",
"$",
"now",
")",
";",
"if",
"(",
"$",
"timestamp",
"<",
"$",
"value",
")",
"{",
"break",
";",
"}",
"$",
"val",
"=",
"get_string",
"(",
"'numweeks'",
",",
"'moodle'",
",",
"$",
"i",
")",
";",
"$",
"filteroptions",
"+=",
"$",
"this",
"->",
"format_filter_option",
"(",
"USER_FILTER_LAST_ACCESS",
",",
"$",
"criteria",
",",
"$",
"timestamp",
",",
"$",
"val",
")",
";",
"}",
"// Months.",
"for",
"(",
"$",
"i",
"=",
"2",
";",
"$",
"i",
"<",
"12",
";",
"$",
"i",
"++",
")",
"{",
"$",
"timestamp",
"=",
"strtotime",
"(",
"'-'",
".",
"$",
"i",
".",
"' months'",
",",
"$",
"now",
")",
";",
"if",
"(",
"$",
"timestamp",
"<",
"$",
"value",
")",
"{",
"break",
";",
"}",
"$",
"val",
"=",
"get_string",
"(",
"'nummonths'",
",",
"'moodle'",
",",
"$",
"i",
")",
";",
"$",
"filteroptions",
"+=",
"$",
"this",
"->",
"format_filter_option",
"(",
"USER_FILTER_LAST_ACCESS",
",",
"$",
"criteria",
",",
"$",
"timestamp",
",",
"$",
"val",
")",
";",
"}",
"// Try a year.",
"$",
"timestamp",
"=",
"strtotime",
"(",
"'-1 year'",
",",
"$",
"now",
")",
";",
"if",
"(",
"$",
"timestamp",
">=",
"$",
"value",
")",
"{",
"$",
"val",
"=",
"get_string",
"(",
"'numyear'",
",",
"'moodle'",
",",
"1",
")",
";",
"$",
"filteroptions",
"+=",
"$",
"this",
"->",
"format_filter_option",
"(",
"USER_FILTER_LAST_ACCESS",
",",
"$",
"criteria",
",",
"$",
"timestamp",
",",
"$",
"val",
")",
";",
"}",
"break",
";",
"case",
"USER_FILTER_ROLE",
":",
"$",
"criteria",
"=",
"get_string",
"(",
"'role'",
")",
";",
"if",
"(",
"$",
"role",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'role'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"value",
")",
")",
")",
"{",
"$",
"role",
"=",
"role_get_name",
"(",
"$",
"role",
")",
";",
"$",
"filteroptions",
"+=",
"$",
"this",
"->",
"format_filter_option",
"(",
"USER_FILTER_ROLE",
",",
"$",
"criteria",
",",
"$",
"value",
",",
"$",
"role",
")",
";",
"}",
"break",
";",
"}",
"}",
"}",
"return",
"$",
"filteroptions",
";",
"}"
] | Handles cases when after reloading the applied filters are missing in the filter options.
@param array $filtersapplied The applied filters.
@param array $filteroptions The filter options.
@return array The formatted options with the ['filtertype:value' => 'criteria: label'] format. | [
"Handles",
"cases",
"when",
"after",
"reloading",
"the",
"applied",
"filters",
"are",
"missing",
"in",
"the",
"filter",
"options",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/renderer.php#L285-L346 |
213,931 | moodle/moodle | course/format/lib.php | format_base.get_format_or_default | protected static final function get_format_or_default($format) {
global $CFG;
require_once($CFG->dirroot . '/course/lib.php');
if (array_key_exists($format, self::$classesforformat)) {
return self::$classesforformat[$format];
}
$plugins = get_sorted_course_formats();
foreach ($plugins as $plugin) {
self::$classesforformat[$plugin] = $plugin;
}
if (array_key_exists($format, self::$classesforformat)) {
return self::$classesforformat[$format];
}
if (PHPUNIT_TEST && class_exists('format_' . $format)) {
// Allow unittests to use non-existing course formats.
return $format;
}
// Else return default format
$defaultformat = get_config('moodlecourse', 'format');
if (!in_array($defaultformat, $plugins)) {
// when default format is not set correctly, use the first available format
$defaultformat = reset($plugins);
}
debugging('Format plugin format_'.$format.' is not found. Using default format_'.$defaultformat, DEBUG_DEVELOPER);
self::$classesforformat[$format] = $defaultformat;
return $defaultformat;
} | php | protected static final function get_format_or_default($format) {
global $CFG;
require_once($CFG->dirroot . '/course/lib.php');
if (array_key_exists($format, self::$classesforformat)) {
return self::$classesforformat[$format];
}
$plugins = get_sorted_course_formats();
foreach ($plugins as $plugin) {
self::$classesforformat[$plugin] = $plugin;
}
if (array_key_exists($format, self::$classesforformat)) {
return self::$classesforformat[$format];
}
if (PHPUNIT_TEST && class_exists('format_' . $format)) {
// Allow unittests to use non-existing course formats.
return $format;
}
// Else return default format
$defaultformat = get_config('moodlecourse', 'format');
if (!in_array($defaultformat, $plugins)) {
// when default format is not set correctly, use the first available format
$defaultformat = reset($plugins);
}
debugging('Format plugin format_'.$format.' is not found. Using default format_'.$defaultformat, DEBUG_DEVELOPER);
self::$classesforformat[$format] = $defaultformat;
return $defaultformat;
} | [
"protected",
"static",
"final",
"function",
"get_format_or_default",
"(",
"$",
"format",
")",
"{",
"global",
"$",
"CFG",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/course/lib.php'",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"format",
",",
"self",
"::",
"$",
"classesforformat",
")",
")",
"{",
"return",
"self",
"::",
"$",
"classesforformat",
"[",
"$",
"format",
"]",
";",
"}",
"$",
"plugins",
"=",
"get_sorted_course_formats",
"(",
")",
";",
"foreach",
"(",
"$",
"plugins",
"as",
"$",
"plugin",
")",
"{",
"self",
"::",
"$",
"classesforformat",
"[",
"$",
"plugin",
"]",
"=",
"$",
"plugin",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"format",
",",
"self",
"::",
"$",
"classesforformat",
")",
")",
"{",
"return",
"self",
"::",
"$",
"classesforformat",
"[",
"$",
"format",
"]",
";",
"}",
"if",
"(",
"PHPUNIT_TEST",
"&&",
"class_exists",
"(",
"'format_'",
".",
"$",
"format",
")",
")",
"{",
"// Allow unittests to use non-existing course formats.",
"return",
"$",
"format",
";",
"}",
"// Else return default format",
"$",
"defaultformat",
"=",
"get_config",
"(",
"'moodlecourse'",
",",
"'format'",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"defaultformat",
",",
"$",
"plugins",
")",
")",
"{",
"// when default format is not set correctly, use the first available format",
"$",
"defaultformat",
"=",
"reset",
"(",
"$",
"plugins",
")",
";",
"}",
"debugging",
"(",
"'Format plugin format_'",
".",
"$",
"format",
".",
"' is not found. Using default format_'",
".",
"$",
"defaultformat",
",",
"DEBUG_DEVELOPER",
")",
";",
"self",
"::",
"$",
"classesforformat",
"[",
"$",
"format",
"]",
"=",
"$",
"defaultformat",
";",
"return",
"$",
"defaultformat",
";",
"}"
] | Validates that course format exists and enabled and returns either itself or default format
@param string $format
@return string | [
"Validates",
"that",
"course",
"format",
"exists",
"and",
"enabled",
"and",
"returns",
"either",
"itself",
"or",
"default",
"format"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/lib.php#L98-L130 |
213,932 | moodle/moodle | course/format/lib.php | format_base.get_class_name | protected static final function get_class_name($format) {
global $CFG;
static $classnames = array('site' => 'format_site');
if (!isset($classnames[$format])) {
$plugins = core_component::get_plugin_list('format');
$usedformat = self::get_format_or_default($format);
if (isset($plugins[$usedformat]) && file_exists($plugins[$usedformat].'/lib.php')) {
require_once($plugins[$usedformat].'/lib.php');
}
$classnames[$format] = 'format_'. $usedformat;
if (!class_exists($classnames[$format])) {
require_once($CFG->dirroot.'/course/format/formatlegacy.php');
$classnames[$format] = 'format_legacy';
}
}
return $classnames[$format];
} | php | protected static final function get_class_name($format) {
global $CFG;
static $classnames = array('site' => 'format_site');
if (!isset($classnames[$format])) {
$plugins = core_component::get_plugin_list('format');
$usedformat = self::get_format_or_default($format);
if (isset($plugins[$usedformat]) && file_exists($plugins[$usedformat].'/lib.php')) {
require_once($plugins[$usedformat].'/lib.php');
}
$classnames[$format] = 'format_'. $usedformat;
if (!class_exists($classnames[$format])) {
require_once($CFG->dirroot.'/course/format/formatlegacy.php');
$classnames[$format] = 'format_legacy';
}
}
return $classnames[$format];
} | [
"protected",
"static",
"final",
"function",
"get_class_name",
"(",
"$",
"format",
")",
"{",
"global",
"$",
"CFG",
";",
"static",
"$",
"classnames",
"=",
"array",
"(",
"'site'",
"=>",
"'format_site'",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"classnames",
"[",
"$",
"format",
"]",
")",
")",
"{",
"$",
"plugins",
"=",
"core_component",
"::",
"get_plugin_list",
"(",
"'format'",
")",
";",
"$",
"usedformat",
"=",
"self",
"::",
"get_format_or_default",
"(",
"$",
"format",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"plugins",
"[",
"$",
"usedformat",
"]",
")",
"&&",
"file_exists",
"(",
"$",
"plugins",
"[",
"$",
"usedformat",
"]",
".",
"'/lib.php'",
")",
")",
"{",
"require_once",
"(",
"$",
"plugins",
"[",
"$",
"usedformat",
"]",
".",
"'/lib.php'",
")",
";",
"}",
"$",
"classnames",
"[",
"$",
"format",
"]",
"=",
"'format_'",
".",
"$",
"usedformat",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"classnames",
"[",
"$",
"format",
"]",
")",
")",
"{",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/course/format/formatlegacy.php'",
")",
";",
"$",
"classnames",
"[",
"$",
"format",
"]",
"=",
"'format_legacy'",
";",
"}",
"}",
"return",
"$",
"classnames",
"[",
"$",
"format",
"]",
";",
"}"
] | Get class name for the format
If course format xxx does not declare class format_xxx, format_legacy will be returned.
This function also includes lib.php file from corresponding format plugin
@param string $format
@return string | [
"Get",
"class",
"name",
"for",
"the",
"format"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/lib.php#L141-L157 |
213,933 | moodle/moodle | course/format/lib.php | format_base.instance | public static final function instance($courseorid) {
global $DB;
if (!is_object($courseorid)) {
$courseid = (int)$courseorid;
if ($courseid && isset(self::$instances[$courseid]) && count(self::$instances[$courseid]) == 1) {
$formats = array_keys(self::$instances[$courseid]);
$format = reset($formats);
} else {
$format = $DB->get_field('course', 'format', array('id' => $courseid), MUST_EXIST);
}
} else {
$format = $courseorid->format;
if (isset($courseorid->id)) {
$courseid = clean_param($courseorid->id, PARAM_INT);
} else {
$courseid = 0;
}
}
// validate that format exists and enabled, use default otherwise
$format = self::get_format_or_default($format);
if (!isset(self::$instances[$courseid][$format])) {
$classname = self::get_class_name($format);
self::$instances[$courseid][$format] = new $classname($format, $courseid);
}
return self::$instances[$courseid][$format];
} | php | public static final function instance($courseorid) {
global $DB;
if (!is_object($courseorid)) {
$courseid = (int)$courseorid;
if ($courseid && isset(self::$instances[$courseid]) && count(self::$instances[$courseid]) == 1) {
$formats = array_keys(self::$instances[$courseid]);
$format = reset($formats);
} else {
$format = $DB->get_field('course', 'format', array('id' => $courseid), MUST_EXIST);
}
} else {
$format = $courseorid->format;
if (isset($courseorid->id)) {
$courseid = clean_param($courseorid->id, PARAM_INT);
} else {
$courseid = 0;
}
}
// validate that format exists and enabled, use default otherwise
$format = self::get_format_or_default($format);
if (!isset(self::$instances[$courseid][$format])) {
$classname = self::get_class_name($format);
self::$instances[$courseid][$format] = new $classname($format, $courseid);
}
return self::$instances[$courseid][$format];
} | [
"public",
"static",
"final",
"function",
"instance",
"(",
"$",
"courseorid",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"!",
"is_object",
"(",
"$",
"courseorid",
")",
")",
"{",
"$",
"courseid",
"=",
"(",
"int",
")",
"$",
"courseorid",
";",
"if",
"(",
"$",
"courseid",
"&&",
"isset",
"(",
"self",
"::",
"$",
"instances",
"[",
"$",
"courseid",
"]",
")",
"&&",
"count",
"(",
"self",
"::",
"$",
"instances",
"[",
"$",
"courseid",
"]",
")",
"==",
"1",
")",
"{",
"$",
"formats",
"=",
"array_keys",
"(",
"self",
"::",
"$",
"instances",
"[",
"$",
"courseid",
"]",
")",
";",
"$",
"format",
"=",
"reset",
"(",
"$",
"formats",
")",
";",
"}",
"else",
"{",
"$",
"format",
"=",
"$",
"DB",
"->",
"get_field",
"(",
"'course'",
",",
"'format'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"courseid",
")",
",",
"MUST_EXIST",
")",
";",
"}",
"}",
"else",
"{",
"$",
"format",
"=",
"$",
"courseorid",
"->",
"format",
";",
"if",
"(",
"isset",
"(",
"$",
"courseorid",
"->",
"id",
")",
")",
"{",
"$",
"courseid",
"=",
"clean_param",
"(",
"$",
"courseorid",
"->",
"id",
",",
"PARAM_INT",
")",
";",
"}",
"else",
"{",
"$",
"courseid",
"=",
"0",
";",
"}",
"}",
"// validate that format exists and enabled, use default otherwise",
"$",
"format",
"=",
"self",
"::",
"get_format_or_default",
"(",
"$",
"format",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"instances",
"[",
"$",
"courseid",
"]",
"[",
"$",
"format",
"]",
")",
")",
"{",
"$",
"classname",
"=",
"self",
"::",
"get_class_name",
"(",
"$",
"format",
")",
";",
"self",
"::",
"$",
"instances",
"[",
"$",
"courseid",
"]",
"[",
"$",
"format",
"]",
"=",
"new",
"$",
"classname",
"(",
"$",
"format",
",",
"$",
"courseid",
")",
";",
"}",
"return",
"self",
"::",
"$",
"instances",
"[",
"$",
"courseid",
"]",
"[",
"$",
"format",
"]",
";",
"}"
] | Returns an instance of the class
@todo MDL-35727 use MUC for caching of instances, limit the number of cached instances
@param int|stdClass $courseorid either course id or
an object that has the property 'format' and may contain property 'id'
@return format_base | [
"Returns",
"an",
"instance",
"of",
"the",
"class"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/lib.php#L168-L193 |
213,934 | moodle/moodle | course/format/lib.php | format_base.get_course | public function get_course() {
global $DB;
if (!$this->courseid) {
return null;
}
if ($this->course === false) {
$this->course = get_course($this->courseid);
$options = $this->get_format_options();
$dbcoursecolumns = null;
foreach ($options as $optionname => $optionvalue) {
if (isset($this->course->$optionname)) {
// Course format options must not have the same names as existing columns in db table "course".
if (!isset($dbcoursecolumns)) {
$dbcoursecolumns = $DB->get_columns('course');
}
if (isset($dbcoursecolumns[$optionname])) {
debugging('The option name '.$optionname.' in course format '.$this->format.
' is invalid because the field with the same name exists in {course} table',
DEBUG_DEVELOPER);
continue;
}
}
$this->course->$optionname = $optionvalue;
}
}
return $this->course;
} | php | public function get_course() {
global $DB;
if (!$this->courseid) {
return null;
}
if ($this->course === false) {
$this->course = get_course($this->courseid);
$options = $this->get_format_options();
$dbcoursecolumns = null;
foreach ($options as $optionname => $optionvalue) {
if (isset($this->course->$optionname)) {
// Course format options must not have the same names as existing columns in db table "course".
if (!isset($dbcoursecolumns)) {
$dbcoursecolumns = $DB->get_columns('course');
}
if (isset($dbcoursecolumns[$optionname])) {
debugging('The option name '.$optionname.' in course format '.$this->format.
' is invalid because the field with the same name exists in {course} table',
DEBUG_DEVELOPER);
continue;
}
}
$this->course->$optionname = $optionvalue;
}
}
return $this->course;
} | [
"public",
"function",
"get_course",
"(",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"courseid",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"course",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"course",
"=",
"get_course",
"(",
"$",
"this",
"->",
"courseid",
")",
";",
"$",
"options",
"=",
"$",
"this",
"->",
"get_format_options",
"(",
")",
";",
"$",
"dbcoursecolumns",
"=",
"null",
";",
"foreach",
"(",
"$",
"options",
"as",
"$",
"optionname",
"=>",
"$",
"optionvalue",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"course",
"->",
"$",
"optionname",
")",
")",
"{",
"// Course format options must not have the same names as existing columns in db table \"course\".",
"if",
"(",
"!",
"isset",
"(",
"$",
"dbcoursecolumns",
")",
")",
"{",
"$",
"dbcoursecolumns",
"=",
"$",
"DB",
"->",
"get_columns",
"(",
"'course'",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"dbcoursecolumns",
"[",
"$",
"optionname",
"]",
")",
")",
"{",
"debugging",
"(",
"'The option name '",
".",
"$",
"optionname",
".",
"' in course format '",
".",
"$",
"this",
"->",
"format",
".",
"' is invalid because the field with the same name exists in {course} table'",
",",
"DEBUG_DEVELOPER",
")",
";",
"continue",
";",
"}",
"}",
"$",
"this",
"->",
"course",
"->",
"$",
"optionname",
"=",
"$",
"optionvalue",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"course",
";",
"}"
] | Returns a record from course database table plus additional fields
that course format defines
@return stdClass | [
"Returns",
"a",
"record",
"from",
"course",
"database",
"table",
"plus",
"additional",
"fields",
"that",
"course",
"format",
"defines"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/lib.php#L240-L266 |
213,935 | moodle/moodle | course/format/lib.php | format_base.get_last_section_number | public function get_last_section_number() {
$course = $this->get_course();
if (isset($course->numsections)) {
return $course->numsections;
}
$modinfo = get_fast_modinfo($course);
$sections = $modinfo->get_section_info_all();
return (int)max(array_keys($sections));
} | php | public function get_last_section_number() {
$course = $this->get_course();
if (isset($course->numsections)) {
return $course->numsections;
}
$modinfo = get_fast_modinfo($course);
$sections = $modinfo->get_section_info_all();
return (int)max(array_keys($sections));
} | [
"public",
"function",
"get_last_section_number",
"(",
")",
"{",
"$",
"course",
"=",
"$",
"this",
"->",
"get_course",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"course",
"->",
"numsections",
")",
")",
"{",
"return",
"$",
"course",
"->",
"numsections",
";",
"}",
"$",
"modinfo",
"=",
"get_fast_modinfo",
"(",
"$",
"course",
")",
";",
"$",
"sections",
"=",
"$",
"modinfo",
"->",
"get_section_info_all",
"(",
")",
";",
"return",
"(",
"int",
")",
"max",
"(",
"array_keys",
"(",
"$",
"sections",
")",
")",
";",
"}"
] | Method used in the rendered and during backup instead of legacy 'numsections'
Default renderer will treat sections with sectionnumber greater that the value returned by this
method as "orphaned" and not display them on the course page unless in editing mode.
Backup will store this value as 'numsections'.
This method ensures that 3rd party course format plugins that still use 'numsections' continue to
work but at the same time we no longer expect formats to have 'numsections' property.
@return int | [
"Method",
"used",
"in",
"the",
"rendered",
"and",
"during",
"backup",
"instead",
"of",
"legacy",
"numsections"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/lib.php#L280-L288 |
213,936 | moodle/moodle | course/format/lib.php | format_base.get_section | public final function get_section($section, $strictness = IGNORE_MISSING) {
if (is_object($section)) {
$sectionnum = $section->section;
} else {
$sectionnum = $section;
}
$sections = $this->get_sections();
if (array_key_exists($sectionnum, $sections)) {
return $sections[$sectionnum];
}
if ($strictness == MUST_EXIST) {
throw new moodle_exception('sectionnotexist');
}
return null;
} | php | public final function get_section($section, $strictness = IGNORE_MISSING) {
if (is_object($section)) {
$sectionnum = $section->section;
} else {
$sectionnum = $section;
}
$sections = $this->get_sections();
if (array_key_exists($sectionnum, $sections)) {
return $sections[$sectionnum];
}
if ($strictness == MUST_EXIST) {
throw new moodle_exception('sectionnotexist');
}
return null;
} | [
"public",
"final",
"function",
"get_section",
"(",
"$",
"section",
",",
"$",
"strictness",
"=",
"IGNORE_MISSING",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"section",
")",
")",
"{",
"$",
"sectionnum",
"=",
"$",
"section",
"->",
"section",
";",
"}",
"else",
"{",
"$",
"sectionnum",
"=",
"$",
"section",
";",
"}",
"$",
"sections",
"=",
"$",
"this",
"->",
"get_sections",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"sectionnum",
",",
"$",
"sections",
")",
")",
"{",
"return",
"$",
"sections",
"[",
"$",
"sectionnum",
"]",
";",
"}",
"if",
"(",
"$",
"strictness",
"==",
"MUST_EXIST",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'sectionnotexist'",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Returns information about section used in course
@param int|stdClass $section either section number (field course_section.section) or row from course_section table
@param int $strictness
@return section_info | [
"Returns",
"information",
"about",
"section",
"used",
"in",
"course"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/lib.php#L362-L376 |
213,937 | moodle/moodle | course/format/lib.php | format_base.get_format_options | public function get_format_options($section = null) {
global $DB;
if ($section === null) {
$options = $this->course_format_options();
} else {
$options = $this->section_format_options();
}
if (empty($options)) {
// there are no option for course/sections anyway, no need to go further
return array();
}
if ($section === null) {
// course format options will be returned
$sectionid = 0;
} else if ($this->courseid && isset($section->id)) {
// course section format options will be returned
$sectionid = $section->id;
} else if ($this->courseid && is_int($section) &&
($sectionobj = $DB->get_record('course_sections',
array('section' => $section, 'course' => $this->courseid), 'id'))) {
// course section format options will be returned
$sectionid = $sectionobj->id;
} else {
// non-existing (yet) section was passed as an argument
// default format options for course section will be returned
$sectionid = -1;
}
if (!array_key_exists($sectionid, $this->formatoptions)) {
$this->formatoptions[$sectionid] = array();
// first fill with default values
foreach ($options as $optionname => $optionparams) {
$this->formatoptions[$sectionid][$optionname] = null;
if (array_key_exists('default', $optionparams)) {
$this->formatoptions[$sectionid][$optionname] = $optionparams['default'];
}
}
if ($this->courseid && $sectionid !== -1) {
// overwrite the default options values with those stored in course_format_options table
// nothing can be stored if we are interested in generic course ($this->courseid == 0)
// or generic section ($sectionid === 0)
$records = $DB->get_records('course_format_options',
array('courseid' => $this->courseid,
'format' => $this->format,
'sectionid' => $sectionid
), '', 'id,name,value');
foreach ($records as $record) {
if (array_key_exists($record->name, $this->formatoptions[$sectionid])) {
$value = $record->value;
if ($value !== null && isset($options[$record->name]['type'])) {
// this will convert string value to number if needed
$value = clean_param($value, $options[$record->name]['type']);
}
$this->formatoptions[$sectionid][$record->name] = $value;
}
}
}
}
return $this->formatoptions[$sectionid];
} | php | public function get_format_options($section = null) {
global $DB;
if ($section === null) {
$options = $this->course_format_options();
} else {
$options = $this->section_format_options();
}
if (empty($options)) {
// there are no option for course/sections anyway, no need to go further
return array();
}
if ($section === null) {
// course format options will be returned
$sectionid = 0;
} else if ($this->courseid && isset($section->id)) {
// course section format options will be returned
$sectionid = $section->id;
} else if ($this->courseid && is_int($section) &&
($sectionobj = $DB->get_record('course_sections',
array('section' => $section, 'course' => $this->courseid), 'id'))) {
// course section format options will be returned
$sectionid = $sectionobj->id;
} else {
// non-existing (yet) section was passed as an argument
// default format options for course section will be returned
$sectionid = -1;
}
if (!array_key_exists($sectionid, $this->formatoptions)) {
$this->formatoptions[$sectionid] = array();
// first fill with default values
foreach ($options as $optionname => $optionparams) {
$this->formatoptions[$sectionid][$optionname] = null;
if (array_key_exists('default', $optionparams)) {
$this->formatoptions[$sectionid][$optionname] = $optionparams['default'];
}
}
if ($this->courseid && $sectionid !== -1) {
// overwrite the default options values with those stored in course_format_options table
// nothing can be stored if we are interested in generic course ($this->courseid == 0)
// or generic section ($sectionid === 0)
$records = $DB->get_records('course_format_options',
array('courseid' => $this->courseid,
'format' => $this->format,
'sectionid' => $sectionid
), '', 'id,name,value');
foreach ($records as $record) {
if (array_key_exists($record->name, $this->formatoptions[$sectionid])) {
$value = $record->value;
if ($value !== null && isset($options[$record->name]['type'])) {
// this will convert string value to number if needed
$value = clean_param($value, $options[$record->name]['type']);
}
$this->formatoptions[$sectionid][$record->name] = $value;
}
}
}
}
return $this->formatoptions[$sectionid];
} | [
"public",
"function",
"get_format_options",
"(",
"$",
"section",
"=",
"null",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"$",
"section",
"===",
"null",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"course_format_options",
"(",
")",
";",
"}",
"else",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"section_format_options",
"(",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"options",
")",
")",
"{",
"// there are no option for course/sections anyway, no need to go further",
"return",
"array",
"(",
")",
";",
"}",
"if",
"(",
"$",
"section",
"===",
"null",
")",
"{",
"// course format options will be returned",
"$",
"sectionid",
"=",
"0",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"courseid",
"&&",
"isset",
"(",
"$",
"section",
"->",
"id",
")",
")",
"{",
"// course section format options will be returned",
"$",
"sectionid",
"=",
"$",
"section",
"->",
"id",
";",
"}",
"else",
"if",
"(",
"$",
"this",
"->",
"courseid",
"&&",
"is_int",
"(",
"$",
"section",
")",
"&&",
"(",
"$",
"sectionobj",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'course_sections'",
",",
"array",
"(",
"'section'",
"=>",
"$",
"section",
",",
"'course'",
"=>",
"$",
"this",
"->",
"courseid",
")",
",",
"'id'",
")",
")",
")",
"{",
"// course section format options will be returned",
"$",
"sectionid",
"=",
"$",
"sectionobj",
"->",
"id",
";",
"}",
"else",
"{",
"// non-existing (yet) section was passed as an argument",
"// default format options for course section will be returned",
"$",
"sectionid",
"=",
"-",
"1",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"sectionid",
",",
"$",
"this",
"->",
"formatoptions",
")",
")",
"{",
"$",
"this",
"->",
"formatoptions",
"[",
"$",
"sectionid",
"]",
"=",
"array",
"(",
")",
";",
"// first fill with default values",
"foreach",
"(",
"$",
"options",
"as",
"$",
"optionname",
"=>",
"$",
"optionparams",
")",
"{",
"$",
"this",
"->",
"formatoptions",
"[",
"$",
"sectionid",
"]",
"[",
"$",
"optionname",
"]",
"=",
"null",
";",
"if",
"(",
"array_key_exists",
"(",
"'default'",
",",
"$",
"optionparams",
")",
")",
"{",
"$",
"this",
"->",
"formatoptions",
"[",
"$",
"sectionid",
"]",
"[",
"$",
"optionname",
"]",
"=",
"$",
"optionparams",
"[",
"'default'",
"]",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"courseid",
"&&",
"$",
"sectionid",
"!==",
"-",
"1",
")",
"{",
"// overwrite the default options values with those stored in course_format_options table",
"// nothing can be stored if we are interested in generic course ($this->courseid == 0)",
"// or generic section ($sectionid === 0)",
"$",
"records",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'course_format_options'",
",",
"array",
"(",
"'courseid'",
"=>",
"$",
"this",
"->",
"courseid",
",",
"'format'",
"=>",
"$",
"this",
"->",
"format",
",",
"'sectionid'",
"=>",
"$",
"sectionid",
")",
",",
"''",
",",
"'id,name,value'",
")",
";",
"foreach",
"(",
"$",
"records",
"as",
"$",
"record",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"record",
"->",
"name",
",",
"$",
"this",
"->",
"formatoptions",
"[",
"$",
"sectionid",
"]",
")",
")",
"{",
"$",
"value",
"=",
"$",
"record",
"->",
"value",
";",
"if",
"(",
"$",
"value",
"!==",
"null",
"&&",
"isset",
"(",
"$",
"options",
"[",
"$",
"record",
"->",
"name",
"]",
"[",
"'type'",
"]",
")",
")",
"{",
"// this will convert string value to number if needed",
"$",
"value",
"=",
"clean_param",
"(",
"$",
"value",
",",
"$",
"options",
"[",
"$",
"record",
"->",
"name",
"]",
"[",
"'type'",
"]",
")",
";",
"}",
"$",
"this",
"->",
"formatoptions",
"[",
"$",
"sectionid",
"]",
"[",
"$",
"record",
"->",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"formatoptions",
"[",
"$",
"sectionid",
"]",
";",
"}"
] | Returns the format options stored for this course or course section
When overriding please note that this function is called from rebuild_course_cache()
and section_info object, therefore using of get_fast_modinfo() and/or any function that
accesses it may lead to recursion.
@param null|int|stdClass|section_info $section if null the course format options will be returned
otherwise options for specified section will be returned. This can be either
section object or relative section number (field course_sections.section)
@return array | [
"Returns",
"the",
"format",
"options",
"stored",
"for",
"this",
"course",
"or",
"course",
"section"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/lib.php#L620-L678 |
213,938 | moodle/moodle | course/format/lib.php | format_base.validate_format_options | protected function validate_format_options(array $rawdata, int $sectionid = null) : array {
if (!$sectionid) {
$allformatoptions = $this->course_format_options(true);
} else {
$allformatoptions = $this->section_format_options(true);
}
$data = array_intersect_key($rawdata, $allformatoptions);
foreach ($data as $key => $value) {
$option = $allformatoptions[$key] + ['type' => PARAM_RAW, 'element_type' => null, 'element_attributes' => [[]]];
$data[$key] = clean_param($value, $option['type']);
if ($option['element_type'] === 'select' && !array_key_exists($data[$key], $option['element_attributes'][0])) {
// Value invalid for select element, skip.
unset($data[$key]);
}
}
return $data;
} | php | protected function validate_format_options(array $rawdata, int $sectionid = null) : array {
if (!$sectionid) {
$allformatoptions = $this->course_format_options(true);
} else {
$allformatoptions = $this->section_format_options(true);
}
$data = array_intersect_key($rawdata, $allformatoptions);
foreach ($data as $key => $value) {
$option = $allformatoptions[$key] + ['type' => PARAM_RAW, 'element_type' => null, 'element_attributes' => [[]]];
$data[$key] = clean_param($value, $option['type']);
if ($option['element_type'] === 'select' && !array_key_exists($data[$key], $option['element_attributes'][0])) {
// Value invalid for select element, skip.
unset($data[$key]);
}
}
return $data;
} | [
"protected",
"function",
"validate_format_options",
"(",
"array",
"$",
"rawdata",
",",
"int",
"$",
"sectionid",
"=",
"null",
")",
":",
"array",
"{",
"if",
"(",
"!",
"$",
"sectionid",
")",
"{",
"$",
"allformatoptions",
"=",
"$",
"this",
"->",
"course_format_options",
"(",
"true",
")",
";",
"}",
"else",
"{",
"$",
"allformatoptions",
"=",
"$",
"this",
"->",
"section_format_options",
"(",
"true",
")",
";",
"}",
"$",
"data",
"=",
"array_intersect_key",
"(",
"$",
"rawdata",
",",
"$",
"allformatoptions",
")",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"option",
"=",
"$",
"allformatoptions",
"[",
"$",
"key",
"]",
"+",
"[",
"'type'",
"=>",
"PARAM_RAW",
",",
"'element_type'",
"=>",
"null",
",",
"'element_attributes'",
"=>",
"[",
"[",
"]",
"]",
"]",
";",
"$",
"data",
"[",
"$",
"key",
"]",
"=",
"clean_param",
"(",
"$",
"value",
",",
"$",
"option",
"[",
"'type'",
"]",
")",
";",
"if",
"(",
"$",
"option",
"[",
"'element_type'",
"]",
"===",
"'select'",
"&&",
"!",
"array_key_exists",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
",",
"$",
"option",
"[",
"'element_attributes'",
"]",
"[",
"0",
"]",
")",
")",
"{",
"// Value invalid for select element, skip.",
"unset",
"(",
"$",
"data",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"return",
"$",
"data",
";",
"}"
] | Prepares values of course or section format options before storing them in DB
If an option has invalid value it is not returned
@param array $rawdata associative array of the proposed course/section format options
@param int|null $sectionid null if it is course format option
@return array array of options that have valid values | [
"Prepares",
"values",
"of",
"course",
"or",
"section",
"format",
"options",
"before",
"storing",
"them",
"in",
"DB"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/lib.php#L759-L775 |
213,939 | moodle/moodle | course/format/lib.php | format_base.update_format_options | protected function update_format_options($data, $sectionid = null) {
global $DB;
$data = $this->validate_format_options((array)$data, $sectionid);
if (!$sectionid) {
$allformatoptions = $this->course_format_options();
$sectionid = 0;
} else {
$allformatoptions = $this->section_format_options();
}
if (empty($allformatoptions)) {
// nothing to update anyway
return false;
}
$defaultoptions = array();
$cached = array();
foreach ($allformatoptions as $key => $option) {
$defaultoptions[$key] = null;
if (array_key_exists('default', $option)) {
$defaultoptions[$key] = $option['default'];
}
$cached[$key] = ($sectionid === 0 || !empty($option['cache']));
}
$records = $DB->get_records('course_format_options',
array('courseid' => $this->courseid,
'format' => $this->format,
'sectionid' => $sectionid
), '', 'name,id,value');
$changed = $needrebuild = false;
foreach ($defaultoptions as $key => $value) {
if (isset($records[$key])) {
if (array_key_exists($key, $data) && $records[$key]->value !== $data[$key]) {
$DB->set_field('course_format_options', 'value',
$data[$key], array('id' => $records[$key]->id));
$changed = true;
$needrebuild = $needrebuild || $cached[$key];
}
} else {
if (array_key_exists($key, $data) && $data[$key] !== $value) {
$newvalue = $data[$key];
$changed = true;
$needrebuild = $needrebuild || $cached[$key];
} else {
$newvalue = $value;
// we still insert entry in DB but there are no changes from user point of
// view and no need to call rebuild_course_cache()
}
$DB->insert_record('course_format_options', array(
'courseid' => $this->courseid,
'format' => $this->format,
'sectionid' => $sectionid,
'name' => $key,
'value' => $newvalue
));
}
}
if ($needrebuild) {
rebuild_course_cache($this->courseid, true);
}
if ($changed) {
// reset internal caches
if (!$sectionid) {
$this->course = false;
}
unset($this->formatoptions[$sectionid]);
}
return $changed;
} | php | protected function update_format_options($data, $sectionid = null) {
global $DB;
$data = $this->validate_format_options((array)$data, $sectionid);
if (!$sectionid) {
$allformatoptions = $this->course_format_options();
$sectionid = 0;
} else {
$allformatoptions = $this->section_format_options();
}
if (empty($allformatoptions)) {
// nothing to update anyway
return false;
}
$defaultoptions = array();
$cached = array();
foreach ($allformatoptions as $key => $option) {
$defaultoptions[$key] = null;
if (array_key_exists('default', $option)) {
$defaultoptions[$key] = $option['default'];
}
$cached[$key] = ($sectionid === 0 || !empty($option['cache']));
}
$records = $DB->get_records('course_format_options',
array('courseid' => $this->courseid,
'format' => $this->format,
'sectionid' => $sectionid
), '', 'name,id,value');
$changed = $needrebuild = false;
foreach ($defaultoptions as $key => $value) {
if (isset($records[$key])) {
if (array_key_exists($key, $data) && $records[$key]->value !== $data[$key]) {
$DB->set_field('course_format_options', 'value',
$data[$key], array('id' => $records[$key]->id));
$changed = true;
$needrebuild = $needrebuild || $cached[$key];
}
} else {
if (array_key_exists($key, $data) && $data[$key] !== $value) {
$newvalue = $data[$key];
$changed = true;
$needrebuild = $needrebuild || $cached[$key];
} else {
$newvalue = $value;
// we still insert entry in DB but there are no changes from user point of
// view and no need to call rebuild_course_cache()
}
$DB->insert_record('course_format_options', array(
'courseid' => $this->courseid,
'format' => $this->format,
'sectionid' => $sectionid,
'name' => $key,
'value' => $newvalue
));
}
}
if ($needrebuild) {
rebuild_course_cache($this->courseid, true);
}
if ($changed) {
// reset internal caches
if (!$sectionid) {
$this->course = false;
}
unset($this->formatoptions[$sectionid]);
}
return $changed;
} | [
"protected",
"function",
"update_format_options",
"(",
"$",
"data",
",",
"$",
"sectionid",
"=",
"null",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"validate_format_options",
"(",
"(",
"array",
")",
"$",
"data",
",",
"$",
"sectionid",
")",
";",
"if",
"(",
"!",
"$",
"sectionid",
")",
"{",
"$",
"allformatoptions",
"=",
"$",
"this",
"->",
"course_format_options",
"(",
")",
";",
"$",
"sectionid",
"=",
"0",
";",
"}",
"else",
"{",
"$",
"allformatoptions",
"=",
"$",
"this",
"->",
"section_format_options",
"(",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"allformatoptions",
")",
")",
"{",
"// nothing to update anyway",
"return",
"false",
";",
"}",
"$",
"defaultoptions",
"=",
"array",
"(",
")",
";",
"$",
"cached",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"allformatoptions",
"as",
"$",
"key",
"=>",
"$",
"option",
")",
"{",
"$",
"defaultoptions",
"[",
"$",
"key",
"]",
"=",
"null",
";",
"if",
"(",
"array_key_exists",
"(",
"'default'",
",",
"$",
"option",
")",
")",
"{",
"$",
"defaultoptions",
"[",
"$",
"key",
"]",
"=",
"$",
"option",
"[",
"'default'",
"]",
";",
"}",
"$",
"cached",
"[",
"$",
"key",
"]",
"=",
"(",
"$",
"sectionid",
"===",
"0",
"||",
"!",
"empty",
"(",
"$",
"option",
"[",
"'cache'",
"]",
")",
")",
";",
"}",
"$",
"records",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'course_format_options'",
",",
"array",
"(",
"'courseid'",
"=>",
"$",
"this",
"->",
"courseid",
",",
"'format'",
"=>",
"$",
"this",
"->",
"format",
",",
"'sectionid'",
"=>",
"$",
"sectionid",
")",
",",
"''",
",",
"'name,id,value'",
")",
";",
"$",
"changed",
"=",
"$",
"needrebuild",
"=",
"false",
";",
"foreach",
"(",
"$",
"defaultoptions",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"records",
"[",
"$",
"key",
"]",
")",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"data",
")",
"&&",
"$",
"records",
"[",
"$",
"key",
"]",
"->",
"value",
"!==",
"$",
"data",
"[",
"$",
"key",
"]",
")",
"{",
"$",
"DB",
"->",
"set_field",
"(",
"'course_format_options'",
",",
"'value'",
",",
"$",
"data",
"[",
"$",
"key",
"]",
",",
"array",
"(",
"'id'",
"=>",
"$",
"records",
"[",
"$",
"key",
"]",
"->",
"id",
")",
")",
";",
"$",
"changed",
"=",
"true",
";",
"$",
"needrebuild",
"=",
"$",
"needrebuild",
"||",
"$",
"cached",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"data",
")",
"&&",
"$",
"data",
"[",
"$",
"key",
"]",
"!==",
"$",
"value",
")",
"{",
"$",
"newvalue",
"=",
"$",
"data",
"[",
"$",
"key",
"]",
";",
"$",
"changed",
"=",
"true",
";",
"$",
"needrebuild",
"=",
"$",
"needrebuild",
"||",
"$",
"cached",
"[",
"$",
"key",
"]",
";",
"}",
"else",
"{",
"$",
"newvalue",
"=",
"$",
"value",
";",
"// we still insert entry in DB but there are no changes from user point of",
"// view and no need to call rebuild_course_cache()",
"}",
"$",
"DB",
"->",
"insert_record",
"(",
"'course_format_options'",
",",
"array",
"(",
"'courseid'",
"=>",
"$",
"this",
"->",
"courseid",
",",
"'format'",
"=>",
"$",
"this",
"->",
"format",
",",
"'sectionid'",
"=>",
"$",
"sectionid",
",",
"'name'",
"=>",
"$",
"key",
",",
"'value'",
"=>",
"$",
"newvalue",
")",
")",
";",
"}",
"}",
"if",
"(",
"$",
"needrebuild",
")",
"{",
"rebuild_course_cache",
"(",
"$",
"this",
"->",
"courseid",
",",
"true",
")",
";",
"}",
"if",
"(",
"$",
"changed",
")",
"{",
"// reset internal caches",
"if",
"(",
"!",
"$",
"sectionid",
")",
"{",
"$",
"this",
"->",
"course",
"=",
"false",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"formatoptions",
"[",
"$",
"sectionid",
"]",
")",
";",
"}",
"return",
"$",
"changed",
";",
"}"
] | Updates format options for a course or section
If $data does not contain property with the option name, the option will not be updated
@param stdClass|array $data return value from {@link moodleform::get_data()} or array with data
@param null|int null if these are options for course or section id (course_sections.id)
if these are options for section
@return bool whether there were any changes to the options values | [
"Updates",
"format",
"options",
"for",
"a",
"course",
"or",
"section"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/lib.php#L797-L863 |
213,940 | moodle/moodle | course/format/lib.php | format_base.editsection_form | public function editsection_form($action, $customdata = array()) {
global $CFG;
require_once($CFG->dirroot. '/course/editsection_form.php');
$context = context_course::instance($this->courseid);
if (!array_key_exists('course', $customdata)) {
$customdata['course'] = $this->get_course();
}
return new editsection_form($action, $customdata);
} | php | public function editsection_form($action, $customdata = array()) {
global $CFG;
require_once($CFG->dirroot. '/course/editsection_form.php');
$context = context_course::instance($this->courseid);
if (!array_key_exists('course', $customdata)) {
$customdata['course'] = $this->get_course();
}
return new editsection_form($action, $customdata);
} | [
"public",
"function",
"editsection_form",
"(",
"$",
"action",
",",
"$",
"customdata",
"=",
"array",
"(",
")",
")",
"{",
"global",
"$",
"CFG",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/course/editsection_form.php'",
")",
";",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"this",
"->",
"courseid",
")",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"'course'",
",",
"$",
"customdata",
")",
")",
"{",
"$",
"customdata",
"[",
"'course'",
"]",
"=",
"$",
"this",
"->",
"get_course",
"(",
")",
";",
"}",
"return",
"new",
"editsection_form",
"(",
"$",
"action",
",",
"$",
"customdata",
")",
";",
"}"
] | Return an instance of moodleform to edit a specified section
Default implementation returns instance of editsection_form that automatically adds
additional fields defined in {@link format_base::section_format_options()}
Format plugins may extend editsection_form if they want to have custom edit section form.
@param mixed $action the action attribute for the form. If empty defaults to auto detect the
current url. If a moodle_url object then outputs params as hidden variables.
@param array $customdata the array with custom data to be passed to the form
/course/editsection.php passes section_info object in 'cs' field
for filling availability fields
@return moodleform | [
"Return",
"an",
"instance",
"of",
"moodleform",
"to",
"edit",
"a",
"specified",
"section"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/lib.php#L908-L916 |
213,941 | moodle/moodle | course/format/lib.php | format_base.is_section_current | public function is_section_current($section) {
if (is_object($section)) {
$sectionnum = $section->section;
} else {
$sectionnum = $section;
}
return ($sectionnum && ($course = $this->get_course()) && $course->marker == $sectionnum);
} | php | public function is_section_current($section) {
if (is_object($section)) {
$sectionnum = $section->section;
} else {
$sectionnum = $section;
}
return ($sectionnum && ($course = $this->get_course()) && $course->marker == $sectionnum);
} | [
"public",
"function",
"is_section_current",
"(",
"$",
"section",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"section",
")",
")",
"{",
"$",
"sectionnum",
"=",
"$",
"section",
"->",
"section",
";",
"}",
"else",
"{",
"$",
"sectionnum",
"=",
"$",
"section",
";",
"}",
"return",
"(",
"$",
"sectionnum",
"&&",
"(",
"$",
"course",
"=",
"$",
"this",
"->",
"get_course",
"(",
")",
")",
"&&",
"$",
"course",
"->",
"marker",
"==",
"$",
"sectionnum",
")",
";",
"}"
] | Returns true if the specified section is current
By default we analyze $course->marker
@param int|stdClass|section_info $section
@return bool | [
"Returns",
"true",
"if",
"the",
"specified",
"section",
"is",
"current"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/lib.php#L1011-L1018 |
213,942 | moodle/moodle | course/format/lib.php | format_base.delete_section | public function delete_section($section, $forcedeleteifnotempty = false) {
global $DB;
if (!$this->uses_sections()) {
// Not possible to delete section if sections are not used.
return false;
}
if (!is_object($section)) {
$section = $DB->get_record('course_sections', array('course' => $this->get_courseid(), 'section' => $section),
'id,section,sequence,summary');
}
if (!$section || !$section->section) {
// Not possible to delete 0-section.
return false;
}
if (!$forcedeleteifnotempty && (!empty($section->sequence) || !empty($section->summary))) {
return false;
}
$course = $this->get_course();
// Remove the marker if it points to this section.
if ($section->section == $course->marker) {
course_set_marker($course->id, 0);
}
$lastsection = $DB->get_field_sql('SELECT max(section) from {course_sections}
WHERE course = ?', array($course->id));
// Find out if we need to descrease the 'numsections' property later.
$courseformathasnumsections = array_key_exists('numsections',
$this->get_format_options());
$decreasenumsections = $courseformathasnumsections && ($section->section <= $course->numsections);
// Move the section to the end.
move_section_to($course, $section->section, $lastsection, true);
// Delete all modules from the section.
foreach (preg_split('/,/', $section->sequence, -1, PREG_SPLIT_NO_EMPTY) as $cmid) {
course_delete_module($cmid);
}
// Delete section and it's format options.
$DB->delete_records('course_format_options', array('sectionid' => $section->id));
$DB->delete_records('course_sections', array('id' => $section->id));
rebuild_course_cache($course->id, true);
// Delete section summary files.
$context = \context_course::instance($course->id);
$fs = get_file_storage();
$fs->delete_area_files($context->id, 'course', 'section', $section->id);
// Descrease 'numsections' if needed.
if ($decreasenumsections) {
$this->update_course_format_options(array('numsections' => $course->numsections - 1));
}
return true;
} | php | public function delete_section($section, $forcedeleteifnotempty = false) {
global $DB;
if (!$this->uses_sections()) {
// Not possible to delete section if sections are not used.
return false;
}
if (!is_object($section)) {
$section = $DB->get_record('course_sections', array('course' => $this->get_courseid(), 'section' => $section),
'id,section,sequence,summary');
}
if (!$section || !$section->section) {
// Not possible to delete 0-section.
return false;
}
if (!$forcedeleteifnotempty && (!empty($section->sequence) || !empty($section->summary))) {
return false;
}
$course = $this->get_course();
// Remove the marker if it points to this section.
if ($section->section == $course->marker) {
course_set_marker($course->id, 0);
}
$lastsection = $DB->get_field_sql('SELECT max(section) from {course_sections}
WHERE course = ?', array($course->id));
// Find out if we need to descrease the 'numsections' property later.
$courseformathasnumsections = array_key_exists('numsections',
$this->get_format_options());
$decreasenumsections = $courseformathasnumsections && ($section->section <= $course->numsections);
// Move the section to the end.
move_section_to($course, $section->section, $lastsection, true);
// Delete all modules from the section.
foreach (preg_split('/,/', $section->sequence, -1, PREG_SPLIT_NO_EMPTY) as $cmid) {
course_delete_module($cmid);
}
// Delete section and it's format options.
$DB->delete_records('course_format_options', array('sectionid' => $section->id));
$DB->delete_records('course_sections', array('id' => $section->id));
rebuild_course_cache($course->id, true);
// Delete section summary files.
$context = \context_course::instance($course->id);
$fs = get_file_storage();
$fs->delete_area_files($context->id, 'course', 'section', $section->id);
// Descrease 'numsections' if needed.
if ($decreasenumsections) {
$this->update_course_format_options(array('numsections' => $course->numsections - 1));
}
return true;
} | [
"public",
"function",
"delete_section",
"(",
"$",
"section",
",",
"$",
"forcedeleteifnotempty",
"=",
"false",
")",
"{",
"global",
"$",
"DB",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"uses_sections",
"(",
")",
")",
"{",
"// Not possible to delete section if sections are not used.",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"is_object",
"(",
"$",
"section",
")",
")",
"{",
"$",
"section",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'course_sections'",
",",
"array",
"(",
"'course'",
"=>",
"$",
"this",
"->",
"get_courseid",
"(",
")",
",",
"'section'",
"=>",
"$",
"section",
")",
",",
"'id,section,sequence,summary'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"section",
"||",
"!",
"$",
"section",
"->",
"section",
")",
"{",
"// Not possible to delete 0-section.",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"forcedeleteifnotempty",
"&&",
"(",
"!",
"empty",
"(",
"$",
"section",
"->",
"sequence",
")",
"||",
"!",
"empty",
"(",
"$",
"section",
"->",
"summary",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"course",
"=",
"$",
"this",
"->",
"get_course",
"(",
")",
";",
"// Remove the marker if it points to this section.",
"if",
"(",
"$",
"section",
"->",
"section",
"==",
"$",
"course",
"->",
"marker",
")",
"{",
"course_set_marker",
"(",
"$",
"course",
"->",
"id",
",",
"0",
")",
";",
"}",
"$",
"lastsection",
"=",
"$",
"DB",
"->",
"get_field_sql",
"(",
"'SELECT max(section) from {course_sections}\n WHERE course = ?'",
",",
"array",
"(",
"$",
"course",
"->",
"id",
")",
")",
";",
"// Find out if we need to descrease the 'numsections' property later.",
"$",
"courseformathasnumsections",
"=",
"array_key_exists",
"(",
"'numsections'",
",",
"$",
"this",
"->",
"get_format_options",
"(",
")",
")",
";",
"$",
"decreasenumsections",
"=",
"$",
"courseformathasnumsections",
"&&",
"(",
"$",
"section",
"->",
"section",
"<=",
"$",
"course",
"->",
"numsections",
")",
";",
"// Move the section to the end.",
"move_section_to",
"(",
"$",
"course",
",",
"$",
"section",
"->",
"section",
",",
"$",
"lastsection",
",",
"true",
")",
";",
"// Delete all modules from the section.",
"foreach",
"(",
"preg_split",
"(",
"'/,/'",
",",
"$",
"section",
"->",
"sequence",
",",
"-",
"1",
",",
"PREG_SPLIT_NO_EMPTY",
")",
"as",
"$",
"cmid",
")",
"{",
"course_delete_module",
"(",
"$",
"cmid",
")",
";",
"}",
"// Delete section and it's format options.",
"$",
"DB",
"->",
"delete_records",
"(",
"'course_format_options'",
",",
"array",
"(",
"'sectionid'",
"=>",
"$",
"section",
"->",
"id",
")",
")",
";",
"$",
"DB",
"->",
"delete_records",
"(",
"'course_sections'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"section",
"->",
"id",
")",
")",
";",
"rebuild_course_cache",
"(",
"$",
"course",
"->",
"id",
",",
"true",
")",
";",
"// Delete section summary files.",
"$",
"context",
"=",
"\\",
"context_course",
"::",
"instance",
"(",
"$",
"course",
"->",
"id",
")",
";",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"$",
"fs",
"->",
"delete_area_files",
"(",
"$",
"context",
"->",
"id",
",",
"'course'",
",",
"'section'",
",",
"$",
"section",
"->",
"id",
")",
";",
"// Descrease 'numsections' if needed.",
"if",
"(",
"$",
"decreasenumsections",
")",
"{",
"$",
"this",
"->",
"update_course_format_options",
"(",
"array",
"(",
"'numsections'",
"=>",
"$",
"course",
"->",
"numsections",
"-",
"1",
")",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Deletes a section
Do not call this function directly, instead call {@link course_delete_section()}
@param int|stdClass|section_info $section
@param bool $forcedeleteifnotempty if set to false section will not be deleted if it has modules in it.
@return bool whether section was deleted | [
"Deletes",
"a",
"section"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/lib.php#L1067-L1125 |
213,943 | moodle/moodle | course/format/lib.php | format_base.inplace_editable_update_section_name | public function inplace_editable_update_section_name($section, $itemtype, $newvalue) {
if ($itemtype === 'sectionname' || $itemtype === 'sectionnamenl') {
$context = context_course::instance($section->course);
external_api::validate_context($context);
require_capability('moodle/course:update', $context);
$newtitle = clean_param($newvalue, PARAM_TEXT);
if (strval($section->name) !== strval($newtitle)) {
course_update_section($section->course, $section, array('name' => $newtitle));
}
return $this->inplace_editable_render_section_name($section, ($itemtype === 'sectionname'), true);
}
} | php | public function inplace_editable_update_section_name($section, $itemtype, $newvalue) {
if ($itemtype === 'sectionname' || $itemtype === 'sectionnamenl') {
$context = context_course::instance($section->course);
external_api::validate_context($context);
require_capability('moodle/course:update', $context);
$newtitle = clean_param($newvalue, PARAM_TEXT);
if (strval($section->name) !== strval($newtitle)) {
course_update_section($section->course, $section, array('name' => $newtitle));
}
return $this->inplace_editable_render_section_name($section, ($itemtype === 'sectionname'), true);
}
} | [
"public",
"function",
"inplace_editable_update_section_name",
"(",
"$",
"section",
",",
"$",
"itemtype",
",",
"$",
"newvalue",
")",
"{",
"if",
"(",
"$",
"itemtype",
"===",
"'sectionname'",
"||",
"$",
"itemtype",
"===",
"'sectionnamenl'",
")",
"{",
"$",
"context",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"section",
"->",
"course",
")",
";",
"external_api",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"require_capability",
"(",
"'moodle/course:update'",
",",
"$",
"context",
")",
";",
"$",
"newtitle",
"=",
"clean_param",
"(",
"$",
"newvalue",
",",
"PARAM_TEXT",
")",
";",
"if",
"(",
"strval",
"(",
"$",
"section",
"->",
"name",
")",
"!==",
"strval",
"(",
"$",
"newtitle",
")",
")",
"{",
"course_update_section",
"(",
"$",
"section",
"->",
"course",
",",
"$",
"section",
",",
"array",
"(",
"'name'",
"=>",
"$",
"newtitle",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"inplace_editable_render_section_name",
"(",
"$",
"section",
",",
"(",
"$",
"itemtype",
"===",
"'sectionname'",
")",
",",
"true",
")",
";",
"}",
"}"
] | Updates the value in the database and modifies this object respectively.
ALWAYS check user permissions before performing an update! Throw exceptions if permissions are not sufficient
or value is not legit.
@param stdClass $section
@param string $itemtype
@param mixed $newvalue
@return \core\output\inplace_editable | [
"Updates",
"the",
"value",
"in",
"the",
"database",
"and",
"modifies",
"this",
"object",
"respectively",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/lib.php#L1183-L1195 |
213,944 | moodle/moodle | course/format/lib.php | format_base.get_default_course_enddate | public function get_default_course_enddate($mform, $fieldnames = array()) {
if (empty($fieldnames)) {
$fieldnames = array('startdate' => 'startdate');
}
$startdate = $this->get_form_start_date($mform, $fieldnames);
$courseduration = intval(get_config('moodlecourse', 'courseduration'));
if (!$courseduration) {
// Default, it should be already set during upgrade though.
$courseduration = YEARSECS;
}
return $startdate + $courseduration;
} | php | public function get_default_course_enddate($mform, $fieldnames = array()) {
if (empty($fieldnames)) {
$fieldnames = array('startdate' => 'startdate');
}
$startdate = $this->get_form_start_date($mform, $fieldnames);
$courseduration = intval(get_config('moodlecourse', 'courseduration'));
if (!$courseduration) {
// Default, it should be already set during upgrade though.
$courseduration = YEARSECS;
}
return $startdate + $courseduration;
} | [
"public",
"function",
"get_default_course_enddate",
"(",
"$",
"mform",
",",
"$",
"fieldnames",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"fieldnames",
")",
")",
"{",
"$",
"fieldnames",
"=",
"array",
"(",
"'startdate'",
"=>",
"'startdate'",
")",
";",
"}",
"$",
"startdate",
"=",
"$",
"this",
"->",
"get_form_start_date",
"(",
"$",
"mform",
",",
"$",
"fieldnames",
")",
";",
"$",
"courseduration",
"=",
"intval",
"(",
"get_config",
"(",
"'moodlecourse'",
",",
"'courseduration'",
")",
")",
";",
"if",
"(",
"!",
"$",
"courseduration",
")",
"{",
"// Default, it should be already set during upgrade though.",
"$",
"courseduration",
"=",
"YEARSECS",
";",
"}",
"return",
"$",
"startdate",
"+",
"$",
"courseduration",
";",
"}"
] | Returns the default end date value based on the start date.
This is the default implementation for course formats, it is based on
moodlecourse/courseduration setting. Course formats like format_weeks for
example can overwrite this method and return a value based on their internal options.
@param moodleform $mform
@param array $fieldnames The form - field names mapping.
@return int | [
"Returns",
"the",
"default",
"end",
"date",
"value",
"based",
"on",
"the",
"start",
"date",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/lib.php#L1209-L1223 |
213,945 | moodle/moodle | course/format/lib.php | format_base.supports_news | public function supports_news() {
// For backwards compatibility, check if default blocks include the news_items block.
$defaultblocks = $this->get_default_blocks();
foreach ($defaultblocks as $blocks) {
if (in_array('news_items', $blocks)) {
return true;
}
}
// Return false by default.
return false;
} | php | public function supports_news() {
// For backwards compatibility, check if default blocks include the news_items block.
$defaultblocks = $this->get_default_blocks();
foreach ($defaultblocks as $blocks) {
if (in_array('news_items', $blocks)) {
return true;
}
}
// Return false by default.
return false;
} | [
"public",
"function",
"supports_news",
"(",
")",
"{",
"// For backwards compatibility, check if default blocks include the news_items block.",
"$",
"defaultblocks",
"=",
"$",
"this",
"->",
"get_default_blocks",
"(",
")",
";",
"foreach",
"(",
"$",
"defaultblocks",
"as",
"$",
"blocks",
")",
"{",
"if",
"(",
"in_array",
"(",
"'news_items'",
",",
"$",
"blocks",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"// Return false by default.",
"return",
"false",
";",
"}"
] | Indicates whether the course format supports the creation of the Announcements forum.
For course format plugin developers, please override this to return true if you want the Announcements forum
to be created upon course creation.
@return bool | [
"Indicates",
"whether",
"the",
"course",
"format",
"supports",
"the",
"creation",
"of",
"the",
"Announcements",
"forum",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/lib.php#L1233-L1243 |
213,946 | moodle/moodle | course/format/lib.php | format_base.get_form_start_date | protected function get_form_start_date($mform, $fieldnames) {
$startdate = $mform->getElementValue($fieldnames['startdate']);
return $mform->getElement($fieldnames['startdate'])->exportValue($startdate);
} | php | protected function get_form_start_date($mform, $fieldnames) {
$startdate = $mform->getElementValue($fieldnames['startdate']);
return $mform->getElement($fieldnames['startdate'])->exportValue($startdate);
} | [
"protected",
"function",
"get_form_start_date",
"(",
"$",
"mform",
",",
"$",
"fieldnames",
")",
"{",
"$",
"startdate",
"=",
"$",
"mform",
"->",
"getElementValue",
"(",
"$",
"fieldnames",
"[",
"'startdate'",
"]",
")",
";",
"return",
"$",
"mform",
"->",
"getElement",
"(",
"$",
"fieldnames",
"[",
"'startdate'",
"]",
")",
"->",
"exportValue",
"(",
"$",
"startdate",
")",
";",
"}"
] | Get the start date value from the course settings page form.
@param moodleform $mform
@param array $fieldnames The form - field names mapping.
@return int | [
"Get",
"the",
"start",
"date",
"value",
"from",
"the",
"course",
"settings",
"page",
"form",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/lib.php#L1252-L1255 |
213,947 | moodle/moodle | course/format/lib.php | format_site.course_format_options | public function course_format_options($foreditform = false) {
static $courseformatoptions = false;
if ($courseformatoptions === false) {
$courseformatoptions = array(
'numsections' => array(
'default' => 1,
'type' => PARAM_INT,
),
);
}
return $courseformatoptions;
} | php | public function course_format_options($foreditform = false) {
static $courseformatoptions = false;
if ($courseformatoptions === false) {
$courseformatoptions = array(
'numsections' => array(
'default' => 1,
'type' => PARAM_INT,
),
);
}
return $courseformatoptions;
} | [
"public",
"function",
"course_format_options",
"(",
"$",
"foreditform",
"=",
"false",
")",
"{",
"static",
"$",
"courseformatoptions",
"=",
"false",
";",
"if",
"(",
"$",
"courseformatoptions",
"===",
"false",
")",
"{",
"$",
"courseformatoptions",
"=",
"array",
"(",
"'numsections'",
"=>",
"array",
"(",
"'default'",
"=>",
"1",
",",
"'type'",
"=>",
"PARAM_INT",
",",
")",
",",
")",
";",
"}",
"return",
"$",
"courseformatoptions",
";",
"}"
] | Definitions of the additional options that site uses
@param bool $foreditform
@return array of options | [
"Definitions",
"of",
"the",
"additional",
"options",
"that",
"site",
"uses"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/format/lib.php#L1378-L1389 |
213,948 | moodle/moodle | question/type/random/questiontype.php | qtype_random.init_qtype_lists | protected function init_qtype_lists() {
if (!is_null($this->excludedqtypes)) {
return; // Already done.
}
$excludedqtypes = array();
$manualqtypes = array();
foreach (question_bank::get_all_qtypes() as $qtype) {
$quotedname = "'" . $qtype->name() . "'";
if (!$qtype->is_usable_by_random()) {
$excludedqtypes[] = $quotedname;
} else if ($qtype->is_manual_graded()) {
$manualqtypes[] = $quotedname;
}
}
$this->excludedqtypes = implode(',', $excludedqtypes);
$this->manualqtypes = implode(',', $manualqtypes);
} | php | protected function init_qtype_lists() {
if (!is_null($this->excludedqtypes)) {
return; // Already done.
}
$excludedqtypes = array();
$manualqtypes = array();
foreach (question_bank::get_all_qtypes() as $qtype) {
$quotedname = "'" . $qtype->name() . "'";
if (!$qtype->is_usable_by_random()) {
$excludedqtypes[] = $quotedname;
} else if ($qtype->is_manual_graded()) {
$manualqtypes[] = $quotedname;
}
}
$this->excludedqtypes = implode(',', $excludedqtypes);
$this->manualqtypes = implode(',', $manualqtypes);
} | [
"protected",
"function",
"init_qtype_lists",
"(",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"excludedqtypes",
")",
")",
"{",
"return",
";",
"// Already done.",
"}",
"$",
"excludedqtypes",
"=",
"array",
"(",
")",
";",
"$",
"manualqtypes",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"question_bank",
"::",
"get_all_qtypes",
"(",
")",
"as",
"$",
"qtype",
")",
"{",
"$",
"quotedname",
"=",
"\"'\"",
".",
"$",
"qtype",
"->",
"name",
"(",
")",
".",
"\"'\"",
";",
"if",
"(",
"!",
"$",
"qtype",
"->",
"is_usable_by_random",
"(",
")",
")",
"{",
"$",
"excludedqtypes",
"[",
"]",
"=",
"$",
"quotedname",
";",
"}",
"else",
"if",
"(",
"$",
"qtype",
"->",
"is_manual_graded",
"(",
")",
")",
"{",
"$",
"manualqtypes",
"[",
"]",
"=",
"$",
"quotedname",
";",
"}",
"}",
"$",
"this",
"->",
"excludedqtypes",
"=",
"implode",
"(",
"','",
",",
"$",
"excludedqtypes",
")",
";",
"$",
"this",
"->",
"manualqtypes",
"=",
"implode",
"(",
"','",
",",
"$",
"manualqtypes",
")",
";",
"}"
] | This method needs to be called before the ->excludedqtypes and
->manualqtypes fields can be used. | [
"This",
"method",
"needs",
"to",
"be",
"called",
"before",
"the",
"-",
">",
"excludedqtypes",
"and",
"-",
">",
"manualqtypes",
"fields",
"can",
"be",
"used",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/random/questiontype.php#L100-L116 |
213,949 | moodle/moodle | question/type/random/questiontype.php | qtype_random.get_available_questions_from_category | public function get_available_questions_from_category($categoryid, $subcategories) {
if (isset($this->availablequestionsbycategory[$categoryid][$subcategories])) {
return $this->availablequestionsbycategory[$categoryid][$subcategories];
}
$this->init_qtype_lists();
if ($subcategories) {
$categoryids = question_categorylist($categoryid);
} else {
$categoryids = array($categoryid);
}
$questionids = question_bank::get_finder()->get_questions_from_categories(
$categoryids, 'qtype NOT IN (' . $this->excludedqtypes . ')');
$this->availablequestionsbycategory[$categoryid][$subcategories] = $questionids;
return $questionids;
} | php | public function get_available_questions_from_category($categoryid, $subcategories) {
if (isset($this->availablequestionsbycategory[$categoryid][$subcategories])) {
return $this->availablequestionsbycategory[$categoryid][$subcategories];
}
$this->init_qtype_lists();
if ($subcategories) {
$categoryids = question_categorylist($categoryid);
} else {
$categoryids = array($categoryid);
}
$questionids = question_bank::get_finder()->get_questions_from_categories(
$categoryids, 'qtype NOT IN (' . $this->excludedqtypes . ')');
$this->availablequestionsbycategory[$categoryid][$subcategories] = $questionids;
return $questionids;
} | [
"public",
"function",
"get_available_questions_from_category",
"(",
"$",
"categoryid",
",",
"$",
"subcategories",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"availablequestionsbycategory",
"[",
"$",
"categoryid",
"]",
"[",
"$",
"subcategories",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"availablequestionsbycategory",
"[",
"$",
"categoryid",
"]",
"[",
"$",
"subcategories",
"]",
";",
"}",
"$",
"this",
"->",
"init_qtype_lists",
"(",
")",
";",
"if",
"(",
"$",
"subcategories",
")",
"{",
"$",
"categoryids",
"=",
"question_categorylist",
"(",
"$",
"categoryid",
")",
";",
"}",
"else",
"{",
"$",
"categoryids",
"=",
"array",
"(",
"$",
"categoryid",
")",
";",
"}",
"$",
"questionids",
"=",
"question_bank",
"::",
"get_finder",
"(",
")",
"->",
"get_questions_from_categories",
"(",
"$",
"categoryids",
",",
"'qtype NOT IN ('",
".",
"$",
"this",
"->",
"excludedqtypes",
".",
"')'",
")",
";",
"$",
"this",
"->",
"availablequestionsbycategory",
"[",
"$",
"categoryid",
"]",
"[",
"$",
"subcategories",
"]",
"=",
"$",
"questionids",
";",
"return",
"$",
"questionids",
";",
"}"
] | Get all the usable questions from a particular question category.
@param int $categoryid the id of a question category.
@param bool whether to include questions from subcategories.
@param string $questionsinuse comma-separated list of question ids to
exclude from consideration.
@return array of question records. | [
"Get",
"all",
"the",
"usable",
"questions",
"from",
"a",
"particular",
"question",
"category",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/random/questiontype.php#L251-L267 |
213,950 | moodle/moodle | question/type/random/questiontype.php | qtype_random.choose_other_question | public function choose_other_question($questiondata, $excludedquestions, $allowshuffle = true, $forcequestionid = null) {
$available = $this->get_available_questions_from_category($questiondata->category,
!empty($questiondata->questiontext));
shuffle($available);
if ($forcequestionid !== null) {
$forcedquestionkey = array_search($forcequestionid, $available);
if ($forcedquestionkey !== false) {
unset($available[$forcedquestionkey]);
array_unshift($available, $forcequestionid);
} else {
throw new coding_exception('thisquestionidisnotavailable', $forcequestionid);
}
}
foreach ($available as $questionid) {
if (in_array($questionid, $excludedquestions)) {
continue;
}
$question = question_bank::load_question($questionid, $allowshuffle);
$this->set_selected_question_name($question, $questiondata->name);
return $question;
}
return null;
} | php | public function choose_other_question($questiondata, $excludedquestions, $allowshuffle = true, $forcequestionid = null) {
$available = $this->get_available_questions_from_category($questiondata->category,
!empty($questiondata->questiontext));
shuffle($available);
if ($forcequestionid !== null) {
$forcedquestionkey = array_search($forcequestionid, $available);
if ($forcedquestionkey !== false) {
unset($available[$forcedquestionkey]);
array_unshift($available, $forcequestionid);
} else {
throw new coding_exception('thisquestionidisnotavailable', $forcequestionid);
}
}
foreach ($available as $questionid) {
if (in_array($questionid, $excludedquestions)) {
continue;
}
$question = question_bank::load_question($questionid, $allowshuffle);
$this->set_selected_question_name($question, $questiondata->name);
return $question;
}
return null;
} | [
"public",
"function",
"choose_other_question",
"(",
"$",
"questiondata",
",",
"$",
"excludedquestions",
",",
"$",
"allowshuffle",
"=",
"true",
",",
"$",
"forcequestionid",
"=",
"null",
")",
"{",
"$",
"available",
"=",
"$",
"this",
"->",
"get_available_questions_from_category",
"(",
"$",
"questiondata",
"->",
"category",
",",
"!",
"empty",
"(",
"$",
"questiondata",
"->",
"questiontext",
")",
")",
";",
"shuffle",
"(",
"$",
"available",
")",
";",
"if",
"(",
"$",
"forcequestionid",
"!==",
"null",
")",
"{",
"$",
"forcedquestionkey",
"=",
"array_search",
"(",
"$",
"forcequestionid",
",",
"$",
"available",
")",
";",
"if",
"(",
"$",
"forcedquestionkey",
"!==",
"false",
")",
"{",
"unset",
"(",
"$",
"available",
"[",
"$",
"forcedquestionkey",
"]",
")",
";",
"array_unshift",
"(",
"$",
"available",
",",
"$",
"forcequestionid",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"coding_exception",
"(",
"'thisquestionidisnotavailable'",
",",
"$",
"forcequestionid",
")",
";",
"}",
"}",
"foreach",
"(",
"$",
"available",
"as",
"$",
"questionid",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"questionid",
",",
"$",
"excludedquestions",
")",
")",
"{",
"continue",
";",
"}",
"$",
"question",
"=",
"question_bank",
"::",
"load_question",
"(",
"$",
"questionid",
",",
"$",
"allowshuffle",
")",
";",
"$",
"this",
"->",
"set_selected_question_name",
"(",
"$",
"question",
",",
"$",
"questiondata",
"->",
"name",
")",
";",
"return",
"$",
"question",
";",
"}",
"return",
"null",
";",
"}"
] | Load the definition of another question picked randomly by this question.
@param object $questiondata the data defining a random question.
@param array $excludedquestions of question ids. We will no pick any question whose id is in this list.
@param bool $allowshuffle if false, then any shuffle option on the selected quetsion is disabled.
@param null|integer $forcequestionid if not null then force the picking of question with id $forcequestionid.
@throws coding_exception
@return question_definition|null the definition of the question that was
selected, or null if no suitable question could be found. | [
"Load",
"the",
"definition",
"of",
"another",
"question",
"picked",
"randomly",
"by",
"this",
"question",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/random/questiontype.php#L283-L308 |
213,951 | moodle/moodle | lib/pear/HTML/QuickForm/file.php | HTML_QuickForm_file.moveUploadedFile | function moveUploadedFile($dest, $fileName = '')
{
if ($dest != '' && substr($dest, -1) != '/') {
$dest .= '/';
}
$fileName = ($fileName != '') ? $fileName : basename($this->_value['name']);
if (move_uploaded_file($this->_value['tmp_name'], $dest . $fileName)) {
return true;
} else {
return false;
}
} | php | function moveUploadedFile($dest, $fileName = '')
{
if ($dest != '' && substr($dest, -1) != '/') {
$dest .= '/';
}
$fileName = ($fileName != '') ? $fileName : basename($this->_value['name']);
if (move_uploaded_file($this->_value['tmp_name'], $dest . $fileName)) {
return true;
} else {
return false;
}
} | [
"function",
"moveUploadedFile",
"(",
"$",
"dest",
",",
"$",
"fileName",
"=",
"''",
")",
"{",
"if",
"(",
"$",
"dest",
"!=",
"''",
"&&",
"substr",
"(",
"$",
"dest",
",",
"-",
"1",
")",
"!=",
"'/'",
")",
"{",
"$",
"dest",
".=",
"'/'",
";",
"}",
"$",
"fileName",
"=",
"(",
"$",
"fileName",
"!=",
"''",
")",
"?",
"$",
"fileName",
":",
"basename",
"(",
"$",
"this",
"->",
"_value",
"[",
"'name'",
"]",
")",
";",
"if",
"(",
"move_uploaded_file",
"(",
"$",
"this",
"->",
"_value",
"[",
"'tmp_name'",
"]",
",",
"$",
"dest",
".",
"$",
"fileName",
")",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Moves an uploaded file into the destination
@param string Destination directory path
@param string New file name
@access public
@return bool Whether the file was moved successfully | [
"Moves",
"an",
"uploaded",
"file",
"into",
"the",
"destination"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/file.php#L205-L216 |
213,952 | moodle/moodle | lib/pear/HTML/QuickForm/file.php | HTML_QuickForm_file._ruleIsUploadedFile | function _ruleIsUploadedFile($elementValue)
{
if ((isset($elementValue['error']) && $elementValue['error'] == 0) ||
(!empty($elementValue['tmp_name']) && $elementValue['tmp_name'] != 'none')) {
return is_uploaded_file($elementValue['tmp_name']);
} else {
return false;
}
} | php | function _ruleIsUploadedFile($elementValue)
{
if ((isset($elementValue['error']) && $elementValue['error'] == 0) ||
(!empty($elementValue['tmp_name']) && $elementValue['tmp_name'] != 'none')) {
return is_uploaded_file($elementValue['tmp_name']);
} else {
return false;
}
} | [
"function",
"_ruleIsUploadedFile",
"(",
"$",
"elementValue",
")",
"{",
"if",
"(",
"(",
"isset",
"(",
"$",
"elementValue",
"[",
"'error'",
"]",
")",
"&&",
"$",
"elementValue",
"[",
"'error'",
"]",
"==",
"0",
")",
"||",
"(",
"!",
"empty",
"(",
"$",
"elementValue",
"[",
"'tmp_name'",
"]",
")",
"&&",
"$",
"elementValue",
"[",
"'tmp_name'",
"]",
"!=",
"'none'",
")",
")",
"{",
"return",
"is_uploaded_file",
"(",
"$",
"elementValue",
"[",
"'tmp_name'",
"]",
")",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | Checks if the given element contains an uploaded file
@param array Uploaded file info (from $_FILES)
@access private
@return bool true if file has been uploaded, false otherwise | [
"Checks",
"if",
"the",
"given",
"element",
"contains",
"an",
"uploaded",
"file"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/file.php#L242-L250 |
213,953 | moodle/moodle | lib/pear/HTML/QuickForm/file.php | HTML_QuickForm_file._ruleCheckMaxFileSize | function _ruleCheckMaxFileSize($elementValue, $maxSize)
{
if (!empty($elementValue['error']) &&
(UPLOAD_ERR_FORM_SIZE == $elementValue['error'] || UPLOAD_ERR_INI_SIZE == $elementValue['error'])) {
return false;
}
if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) {
return true;
}
return ($maxSize >= @filesize($elementValue['tmp_name']));
} | php | function _ruleCheckMaxFileSize($elementValue, $maxSize)
{
if (!empty($elementValue['error']) &&
(UPLOAD_ERR_FORM_SIZE == $elementValue['error'] || UPLOAD_ERR_INI_SIZE == $elementValue['error'])) {
return false;
}
if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) {
return true;
}
return ($maxSize >= @filesize($elementValue['tmp_name']));
} | [
"function",
"_ruleCheckMaxFileSize",
"(",
"$",
"elementValue",
",",
"$",
"maxSize",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"elementValue",
"[",
"'error'",
"]",
")",
"&&",
"(",
"UPLOAD_ERR_FORM_SIZE",
"==",
"$",
"elementValue",
"[",
"'error'",
"]",
"||",
"UPLOAD_ERR_INI_SIZE",
"==",
"$",
"elementValue",
"[",
"'error'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"HTML_QuickForm_file",
"::",
"_ruleIsUploadedFile",
"(",
"$",
"elementValue",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"(",
"$",
"maxSize",
">=",
"@",
"filesize",
"(",
"$",
"elementValue",
"[",
"'tmp_name'",
"]",
")",
")",
";",
"}"
] | Checks that the file does not exceed the max file size
@param array Uploaded file info (from $_FILES)
@param int Max file size
@access private
@return bool true if filesize is lower than maxsize, false otherwise | [
"Checks",
"that",
"the",
"file",
"does",
"not",
"exceed",
"the",
"max",
"file",
"size"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/file.php#L263-L273 |
213,954 | moodle/moodle | lib/pear/HTML/QuickForm/file.php | HTML_QuickForm_file._ruleCheckMimeType | function _ruleCheckMimeType($elementValue, $mimeType)
{
if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) {
return true;
}
if (is_array($mimeType)) {
return in_array($elementValue['type'], $mimeType);
}
return $elementValue['type'] == $mimeType;
} | php | function _ruleCheckMimeType($elementValue, $mimeType)
{
if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) {
return true;
}
if (is_array($mimeType)) {
return in_array($elementValue['type'], $mimeType);
}
return $elementValue['type'] == $mimeType;
} | [
"function",
"_ruleCheckMimeType",
"(",
"$",
"elementValue",
",",
"$",
"mimeType",
")",
"{",
"if",
"(",
"!",
"HTML_QuickForm_file",
"::",
"_ruleIsUploadedFile",
"(",
"$",
"elementValue",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"mimeType",
")",
")",
"{",
"return",
"in_array",
"(",
"$",
"elementValue",
"[",
"'type'",
"]",
",",
"$",
"mimeType",
")",
";",
"}",
"return",
"$",
"elementValue",
"[",
"'type'",
"]",
"==",
"$",
"mimeType",
";",
"}"
] | Checks if the given element contains an uploaded file of the right mime type
@param array Uploaded file info (from $_FILES)
@param mixed Mime Type (can be an array of allowed types)
@access private
@return bool true if mimetype is correct, false otherwise | [
"Checks",
"if",
"the",
"given",
"element",
"contains",
"an",
"uploaded",
"file",
"of",
"the",
"right",
"mime",
"type"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/file.php#L286-L295 |
213,955 | moodle/moodle | lib/pear/HTML/QuickForm/file.php | HTML_QuickForm_file._ruleCheckFileName | function _ruleCheckFileName($elementValue, $regex)
{
if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) {
return true;
}
return preg_match($regex, $elementValue['name']);
} | php | function _ruleCheckFileName($elementValue, $regex)
{
if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) {
return true;
}
return preg_match($regex, $elementValue['name']);
} | [
"function",
"_ruleCheckFileName",
"(",
"$",
"elementValue",
",",
"$",
"regex",
")",
"{",
"if",
"(",
"!",
"HTML_QuickForm_file",
"::",
"_ruleIsUploadedFile",
"(",
"$",
"elementValue",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"preg_match",
"(",
"$",
"regex",
",",
"$",
"elementValue",
"[",
"'name'",
"]",
")",
";",
"}"
] | Checks if the given element contains an uploaded file of the filename regex
@param array Uploaded file info (from $_FILES)
@param string Regular expression
@access private
@return bool true if name matches regex, false otherwise | [
"Checks",
"if",
"the",
"given",
"element",
"contains",
"an",
"uploaded",
"file",
"of",
"the",
"filename",
"regex"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/file.php#L308-L314 |
213,956 | moodle/moodle | enrol/mnet/lib.php | enrol_mnet_plugin.can_add_instance | public function can_add_instance($courseid) {
global $CFG, $DB;
require_once($CFG->dirroot.'/mnet/service/enrol/locallib.php');
$service = mnetservice_enrol::get_instance();
if (!$service->is_available()) {
return false;
}
$coursecontext = context_course::instance($courseid);
if (!has_capability('moodle/course:enrolconfig', $coursecontext)) {
return false;
}
$subscribers = $service->get_remote_subscribers();
if (empty($subscribers)) {
return false;
}
return true;
} | php | public function can_add_instance($courseid) {
global $CFG, $DB;
require_once($CFG->dirroot.'/mnet/service/enrol/locallib.php');
$service = mnetservice_enrol::get_instance();
if (!$service->is_available()) {
return false;
}
$coursecontext = context_course::instance($courseid);
if (!has_capability('moodle/course:enrolconfig', $coursecontext)) {
return false;
}
$subscribers = $service->get_remote_subscribers();
if (empty($subscribers)) {
return false;
}
return true;
} | [
"public",
"function",
"can_add_instance",
"(",
"$",
"courseid",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"DB",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/mnet/service/enrol/locallib.php'",
")",
";",
"$",
"service",
"=",
"mnetservice_enrol",
"::",
"get_instance",
"(",
")",
";",
"if",
"(",
"!",
"$",
"service",
"->",
"is_available",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"coursecontext",
"=",
"context_course",
"::",
"instance",
"(",
"$",
"courseid",
")",
";",
"if",
"(",
"!",
"has_capability",
"(",
"'moodle/course:enrolconfig'",
",",
"$",
"coursecontext",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"subscribers",
"=",
"$",
"service",
"->",
"get_remote_subscribers",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"subscribers",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Returns true if a new instance can be added to this course.
The link is returned only if there are some MNet peers that we publish enrolment service to.
@param int $courseid id of the course to add the instance to
@return boolean | [
"Returns",
"true",
"if",
"a",
"new",
"instance",
"can",
"be",
"added",
"to",
"this",
"course",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/mnet/lib.php#L72-L90 |
213,957 | moodle/moodle | enrol/mnet/lib.php | enrol_mnet_plugin.get_valid_hosts_options | protected function get_valid_hosts_options() {
global $CFG;
require_once($CFG->dirroot.'/mnet/service/enrol/locallib.php');
$service = mnetservice_enrol::get_instance();
$subscribers = $service->get_remote_subscribers();
$hosts = array(0 => get_string('remotesubscribersall', 'enrol_mnet'));
foreach ($subscribers as $hostid => $subscriber) {
$hosts[$hostid] = $subscriber->appname.': '.$subscriber->hostname.' ('.$subscriber->hosturl.')';
}
return $hosts;
} | php | protected function get_valid_hosts_options() {
global $CFG;
require_once($CFG->dirroot.'/mnet/service/enrol/locallib.php');
$service = mnetservice_enrol::get_instance();
$subscribers = $service->get_remote_subscribers();
$hosts = array(0 => get_string('remotesubscribersall', 'enrol_mnet'));
foreach ($subscribers as $hostid => $subscriber) {
$hosts[$hostid] = $subscriber->appname.': '.$subscriber->hostname.' ('.$subscriber->hosturl.')';
}
return $hosts;
} | [
"protected",
"function",
"get_valid_hosts_options",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"require_once",
"(",
"$",
"CFG",
"->",
"dirroot",
".",
"'/mnet/service/enrol/locallib.php'",
")",
";",
"$",
"service",
"=",
"mnetservice_enrol",
"::",
"get_instance",
"(",
")",
";",
"$",
"subscribers",
"=",
"$",
"service",
"->",
"get_remote_subscribers",
"(",
")",
";",
"$",
"hosts",
"=",
"array",
"(",
"0",
"=>",
"get_string",
"(",
"'remotesubscribersall'",
",",
"'enrol_mnet'",
")",
")",
";",
"foreach",
"(",
"$",
"subscribers",
"as",
"$",
"hostid",
"=>",
"$",
"subscriber",
")",
"{",
"$",
"hosts",
"[",
"$",
"hostid",
"]",
"=",
"$",
"subscriber",
"->",
"appname",
".",
"': '",
".",
"$",
"subscriber",
"->",
"hostname",
".",
"' ('",
".",
"$",
"subscriber",
"->",
"hosturl",
".",
"')'",
";",
"}",
"return",
"$",
"hosts",
";",
"}"
] | Return an array of valid options for the hosts property.
@return array | [
"Return",
"an",
"array",
"of",
"valid",
"options",
"for",
"the",
"hosts",
"property",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/mnet/lib.php#L119-L131 |
213,958 | moodle/moodle | blocks/html/block_html.php | block_html.instance_copy | public function instance_copy($fromid) {
$fromcontext = context_block::instance($fromid);
$fs = get_file_storage();
// This extra check if file area is empty adds one query if it is not empty but saves several if it is.
if (!$fs->is_area_empty($fromcontext->id, 'block_html', 'content', 0, false)) {
$draftitemid = 0;
file_prepare_draft_area($draftitemid, $fromcontext->id, 'block_html', 'content', 0, array('subdirs' => true));
file_save_draft_area_files($draftitemid, $this->context->id, 'block_html', 'content', 0, array('subdirs' => true));
}
return true;
} | php | public function instance_copy($fromid) {
$fromcontext = context_block::instance($fromid);
$fs = get_file_storage();
// This extra check if file area is empty adds one query if it is not empty but saves several if it is.
if (!$fs->is_area_empty($fromcontext->id, 'block_html', 'content', 0, false)) {
$draftitemid = 0;
file_prepare_draft_area($draftitemid, $fromcontext->id, 'block_html', 'content', 0, array('subdirs' => true));
file_save_draft_area_files($draftitemid, $this->context->id, 'block_html', 'content', 0, array('subdirs' => true));
}
return true;
} | [
"public",
"function",
"instance_copy",
"(",
"$",
"fromid",
")",
"{",
"$",
"fromcontext",
"=",
"context_block",
"::",
"instance",
"(",
"$",
"fromid",
")",
";",
"$",
"fs",
"=",
"get_file_storage",
"(",
")",
";",
"// This extra check if file area is empty adds one query if it is not empty but saves several if it is.",
"if",
"(",
"!",
"$",
"fs",
"->",
"is_area_empty",
"(",
"$",
"fromcontext",
"->",
"id",
",",
"'block_html'",
",",
"'content'",
",",
"0",
",",
"false",
")",
")",
"{",
"$",
"draftitemid",
"=",
"0",
";",
"file_prepare_draft_area",
"(",
"$",
"draftitemid",
",",
"$",
"fromcontext",
"->",
"id",
",",
"'block_html'",
",",
"'content'",
",",
"0",
",",
"array",
"(",
"'subdirs'",
"=>",
"true",
")",
")",
";",
"file_save_draft_area_files",
"(",
"$",
"draftitemid",
",",
"$",
"this",
"->",
"context",
"->",
"id",
",",
"'block_html'",
",",
"'content'",
",",
"0",
",",
"array",
"(",
"'subdirs'",
"=>",
"true",
")",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Copy any block-specific data when copying to a new block instance.
@param int $fromid the id number of the block instance to copy from
@return boolean | [
"Copy",
"any",
"block",
"-",
"specific",
"data",
"when",
"copying",
"to",
"a",
"new",
"block",
"instance",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/html/block_html.php#L151-L161 |
213,959 | moodle/moodle | mod/forum/classes/local/vaults/post_read_receipt_collection.php | post_read_receipt_collection.from_db_records | protected function from_db_records(array $results) {
$entityfactory = $this->get_entity_factory();
$records = array_map(function($result) {
return $result['record'];
}, $results);
return $entityfactory->get_post_read_receipt_collection_from_stdclasses($records);
} | php | protected function from_db_records(array $results) {
$entityfactory = $this->get_entity_factory();
$records = array_map(function($result) {
return $result['record'];
}, $results);
return $entityfactory->get_post_read_receipt_collection_from_stdclasses($records);
} | [
"protected",
"function",
"from_db_records",
"(",
"array",
"$",
"results",
")",
"{",
"$",
"entityfactory",
"=",
"$",
"this",
"->",
"get_entity_factory",
"(",
")",
";",
"$",
"records",
"=",
"array_map",
"(",
"function",
"(",
"$",
"result",
")",
"{",
"return",
"$",
"result",
"[",
"'record'",
"]",
";",
"}",
",",
"$",
"results",
")",
";",
"return",
"$",
"entityfactory",
"->",
"get_post_read_receipt_collection_from_stdclasses",
"(",
"$",
"records",
")",
";",
"}"
] | Convert the DB records into post_read_receipt_collection entities.
@param array $results The DB records
@return post_read_receipt_collection | [
"Convert",
"the",
"DB",
"records",
"into",
"post_read_receipt_collection",
"entities",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/vaults/post_read_receipt_collection.php#L77-L84 |
213,960 | moodle/moodle | privacy/classes/local/request/userlist_base.php | userlist_base.add_userids | protected function add_userids(array $userids) : userlist_base {
$this->set_userids(array_merge($this->get_userids(), $userids));
return $this;
} | php | protected function add_userids(array $userids) : userlist_base {
$this->set_userids(array_merge($this->get_userids(), $userids));
return $this;
} | [
"protected",
"function",
"add_userids",
"(",
"array",
"$",
"userids",
")",
":",
"userlist_base",
"{",
"$",
"this",
"->",
"set_userids",
"(",
"array_merge",
"(",
"$",
"this",
"->",
"get_userids",
"(",
")",
",",
"$",
"userids",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add a set of additional userids.
@param array $userids The list of users.
@return $this | [
"Add",
"a",
"set",
"of",
"additional",
"userids",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/userlist_base.php#L92-L96 |
213,961 | moodle/moodle | privacy/classes/local/request/userlist_base.php | userlist_base.get_users | public function get_users() : array {
$users = [];
foreach ($this->userids as $userid) {
if ($user = \core_user::get_user($userid)) {
$users[] = $user;
}
}
return $users;
} | php | public function get_users() : array {
$users = [];
foreach ($this->userids as $userid) {
if ($user = \core_user::get_user($userid)) {
$users[] = $user;
}
}
return $users;
} | [
"public",
"function",
"get_users",
"(",
")",
":",
"array",
"{",
"$",
"users",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"userids",
"as",
"$",
"userid",
")",
"{",
"if",
"(",
"$",
"user",
"=",
"\\",
"core_user",
"::",
"get_user",
"(",
"$",
"userid",
")",
")",
"{",
"$",
"users",
"[",
"]",
"=",
"$",
"user",
";",
"}",
"}",
"return",
"$",
"users",
";",
"}"
] | Get the complete list of user objects that relate to this request.
@return \stdClass[] | [
"Get",
"the",
"complete",
"list",
"of",
"user",
"objects",
"that",
"relate",
"to",
"this",
"request",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/userlist_base.php#L112-L121 |
213,962 | moodle/moodle | privacy/classes/local/request/userlist_base.php | userlist_base.current | public function current() {
$user = \core_user::get_user($this->userids[$this->iteratorposition]);
if (false === $user) {
// This user was not found.
unset($this->userids[$this->iteratorposition]);
// Check to see if there are any more users left.
if ($this->count()) {
// Move the pointer to the next record and try again.
$this->next();
$user = $this->current();
} else {
// There are no more context ids left.
return;
}
}
return $user;
} | php | public function current() {
$user = \core_user::get_user($this->userids[$this->iteratorposition]);
if (false === $user) {
// This user was not found.
unset($this->userids[$this->iteratorposition]);
// Check to see if there are any more users left.
if ($this->count()) {
// Move the pointer to the next record and try again.
$this->next();
$user = $this->current();
} else {
// There are no more context ids left.
return;
}
}
return $user;
} | [
"public",
"function",
"current",
"(",
")",
"{",
"$",
"user",
"=",
"\\",
"core_user",
"::",
"get_user",
"(",
"$",
"this",
"->",
"userids",
"[",
"$",
"this",
"->",
"iteratorposition",
"]",
")",
";",
"if",
"(",
"false",
"===",
"$",
"user",
")",
"{",
"// This user was not found.",
"unset",
"(",
"$",
"this",
"->",
"userids",
"[",
"$",
"this",
"->",
"iteratorposition",
"]",
")",
";",
"// Check to see if there are any more users left.",
"if",
"(",
"$",
"this",
"->",
"count",
"(",
")",
")",
"{",
"// Move the pointer to the next record and try again.",
"$",
"this",
"->",
"next",
"(",
")",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"current",
"(",
")",
";",
"}",
"else",
"{",
"// There are no more context ids left.",
"return",
";",
"}",
"}",
"return",
"$",
"user",
";",
"}"
] | Return the current user.
@return \user | [
"Return",
"the",
"current",
"user",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/privacy/classes/local/request/userlist_base.php#L149-L168 |
213,963 | moodle/moodle | search/engine/solr/classes/document.php | document.format_text | protected function format_text($text) {
// Since we allow output for highlighting, we need to encode html entities.
// This ensures plaintext html chars don't become valid html.
$out = s($text);
$startcount = 0;
$endcount = 0;
// Remove end/start pairs that span a few common seperation characters. Allows us to highlight phrases instead of words.
$regex = '|'.engine::HIGHLIGHT_END.'([ .,-]{0,3})'.engine::HIGHLIGHT_START.'|';
$out = preg_replace($regex, '$1', $out);
// Now replace our start and end highlight markers.
$out = str_replace(engine::HIGHLIGHT_START, '<span class="highlight">', $out, $startcount);
$out = str_replace(engine::HIGHLIGHT_END, '</span>', $out, $endcount);
// This makes sure any highlight tags are balanced, incase truncation or the highlight text contained our markers.
while ($startcount > $endcount) {
$out .= '</span>';
$endcount++;
}
while ($startcount < $endcount) {
$out = '<span class="highlight">' . $out;
$endcount++;
}
return parent::format_text($out);
} | php | protected function format_text($text) {
// Since we allow output for highlighting, we need to encode html entities.
// This ensures plaintext html chars don't become valid html.
$out = s($text);
$startcount = 0;
$endcount = 0;
// Remove end/start pairs that span a few common seperation characters. Allows us to highlight phrases instead of words.
$regex = '|'.engine::HIGHLIGHT_END.'([ .,-]{0,3})'.engine::HIGHLIGHT_START.'|';
$out = preg_replace($regex, '$1', $out);
// Now replace our start and end highlight markers.
$out = str_replace(engine::HIGHLIGHT_START, '<span class="highlight">', $out, $startcount);
$out = str_replace(engine::HIGHLIGHT_END, '</span>', $out, $endcount);
// This makes sure any highlight tags are balanced, incase truncation or the highlight text contained our markers.
while ($startcount > $endcount) {
$out .= '</span>';
$endcount++;
}
while ($startcount < $endcount) {
$out = '<span class="highlight">' . $out;
$endcount++;
}
return parent::format_text($out);
} | [
"protected",
"function",
"format_text",
"(",
"$",
"text",
")",
"{",
"// Since we allow output for highlighting, we need to encode html entities.",
"// This ensures plaintext html chars don't become valid html.",
"$",
"out",
"=",
"s",
"(",
"$",
"text",
")",
";",
"$",
"startcount",
"=",
"0",
";",
"$",
"endcount",
"=",
"0",
";",
"// Remove end/start pairs that span a few common seperation characters. Allows us to highlight phrases instead of words.",
"$",
"regex",
"=",
"'|'",
".",
"engine",
"::",
"HIGHLIGHT_END",
".",
"'([ .,-]{0,3})'",
".",
"engine",
"::",
"HIGHLIGHT_START",
".",
"'|'",
";",
"$",
"out",
"=",
"preg_replace",
"(",
"$",
"regex",
",",
"'$1'",
",",
"$",
"out",
")",
";",
"// Now replace our start and end highlight markers.",
"$",
"out",
"=",
"str_replace",
"(",
"engine",
"::",
"HIGHLIGHT_START",
",",
"'<span class=\"highlight\">'",
",",
"$",
"out",
",",
"$",
"startcount",
")",
";",
"$",
"out",
"=",
"str_replace",
"(",
"engine",
"::",
"HIGHLIGHT_END",
",",
"'</span>'",
",",
"$",
"out",
",",
"$",
"endcount",
")",
";",
"// This makes sure any highlight tags are balanced, incase truncation or the highlight text contained our markers.",
"while",
"(",
"$",
"startcount",
">",
"$",
"endcount",
")",
"{",
"$",
"out",
".=",
"'</span>'",
";",
"$",
"endcount",
"++",
";",
"}",
"while",
"(",
"$",
"startcount",
"<",
"$",
"endcount",
")",
"{",
"$",
"out",
"=",
"'<span class=\"highlight\">'",
".",
"$",
"out",
";",
"$",
"endcount",
"++",
";",
"}",
"return",
"parent",
"::",
"format_text",
"(",
"$",
"out",
")",
";",
"}"
] | Formats a text string coming from the search engine.
@param string $text Text to format
@return string HTML text to be renderer | [
"Formats",
"a",
"text",
"string",
"coming",
"from",
"the",
"search",
"engine",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/engine/solr/classes/document.php#L135-L162 |
213,964 | moodle/moodle | search/engine/solr/classes/document.php | document.apply_defaults | protected function apply_defaults() {
parent::apply_defaults();
// We want to set the solr_filegroupingid to id if it isn't set.
if (!isset($this->data['solr_filegroupingid'])) {
$this->data['solr_filegroupingid'] = $this->data['id'];
}
} | php | protected function apply_defaults() {
parent::apply_defaults();
// We want to set the solr_filegroupingid to id if it isn't set.
if (!isset($this->data['solr_filegroupingid'])) {
$this->data['solr_filegroupingid'] = $this->data['id'];
}
} | [
"protected",
"function",
"apply_defaults",
"(",
")",
"{",
"parent",
"::",
"apply_defaults",
"(",
")",
";",
"// We want to set the solr_filegroupingid to id if it isn't set.",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"'solr_filegroupingid'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"data",
"[",
"'solr_filegroupingid'",
"]",
"=",
"$",
"this",
"->",
"data",
"[",
"'id'",
"]",
";",
"}",
"}"
] | Apply any defaults to unset fields before export. Called after document building, but before export.
Sub-classes of this should make sure to call parent::apply_defaults(). | [
"Apply",
"any",
"defaults",
"to",
"unset",
"fields",
"before",
"export",
".",
"Called",
"after",
"document",
"building",
"but",
"before",
"export",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/engine/solr/classes/document.php#L169-L176 |
213,965 | moodle/moodle | search/engine/solr/classes/document.php | document.export_file_for_engine | public function export_file_for_engine($file) {
$data = $this->export_for_engine();
// Content is index in the main document.
unset($data['content']);
unset($data['description1']);
unset($data['description2']);
// Going to append the fileid to give it a unique id.
$data['id'] = $data['id'].'-solrfile'.$file->get_id();
$data['type'] = \core_search\manager::TYPE_FILE;
$data['solr_fileid'] = $file->get_id();
$data['solr_filecontenthash'] = $file->get_contenthash();
$data['solr_fileindexstatus'] = self::INDEXED_FILE_TRUE;
$data['title'] = $file->get_filename();
$data['modified'] = self::format_time_for_engine($file->get_timemodified());
return $data;
} | php | public function export_file_for_engine($file) {
$data = $this->export_for_engine();
// Content is index in the main document.
unset($data['content']);
unset($data['description1']);
unset($data['description2']);
// Going to append the fileid to give it a unique id.
$data['id'] = $data['id'].'-solrfile'.$file->get_id();
$data['type'] = \core_search\manager::TYPE_FILE;
$data['solr_fileid'] = $file->get_id();
$data['solr_filecontenthash'] = $file->get_contenthash();
$data['solr_fileindexstatus'] = self::INDEXED_FILE_TRUE;
$data['title'] = $file->get_filename();
$data['modified'] = self::format_time_for_engine($file->get_timemodified());
return $data;
} | [
"public",
"function",
"export_file_for_engine",
"(",
"$",
"file",
")",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"export_for_engine",
"(",
")",
";",
"// Content is index in the main document.",
"unset",
"(",
"$",
"data",
"[",
"'content'",
"]",
")",
";",
"unset",
"(",
"$",
"data",
"[",
"'description1'",
"]",
")",
";",
"unset",
"(",
"$",
"data",
"[",
"'description2'",
"]",
")",
";",
"// Going to append the fileid to give it a unique id.",
"$",
"data",
"[",
"'id'",
"]",
"=",
"$",
"data",
"[",
"'id'",
"]",
".",
"'-solrfile'",
".",
"$",
"file",
"->",
"get_id",
"(",
")",
";",
"$",
"data",
"[",
"'type'",
"]",
"=",
"\\",
"core_search",
"\\",
"manager",
"::",
"TYPE_FILE",
";",
"$",
"data",
"[",
"'solr_fileid'",
"]",
"=",
"$",
"file",
"->",
"get_id",
"(",
")",
";",
"$",
"data",
"[",
"'solr_filecontenthash'",
"]",
"=",
"$",
"file",
"->",
"get_contenthash",
"(",
")",
";",
"$",
"data",
"[",
"'solr_fileindexstatus'",
"]",
"=",
"self",
"::",
"INDEXED_FILE_TRUE",
";",
"$",
"data",
"[",
"'title'",
"]",
"=",
"$",
"file",
"->",
"get_filename",
"(",
")",
";",
"$",
"data",
"[",
"'modified'",
"]",
"=",
"self",
"::",
"format_time_for_engine",
"(",
"$",
"file",
"->",
"get_timemodified",
"(",
")",
")",
";",
"return",
"$",
"data",
";",
"}"
] | Export the data for the given file in relation to this document.
@param \stored_file $file The stored file we are talking about.
@return array | [
"Export",
"the",
"data",
"for",
"the",
"given",
"file",
"in",
"relation",
"to",
"this",
"document",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/search/engine/solr/classes/document.php#L184-L202 |
213,966 | moodle/moodle | lib/horde/framework/Horde/Translation.php | Horde_Translation.t | public static function t($message)
{
if (!isset(static::$_handlers[static::$_domain])) {
static::loadHandler('Horde_Translation_Handler_Gettext');
}
return static::$_handlers[static::$_domain]->t($message);
} | php | public static function t($message)
{
if (!isset(static::$_handlers[static::$_domain])) {
static::loadHandler('Horde_Translation_Handler_Gettext');
}
return static::$_handlers[static::$_domain]->t($message);
} | [
"public",
"static",
"function",
"t",
"(",
"$",
"message",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"static",
"::",
"$",
"_handlers",
"[",
"static",
"::",
"$",
"_domain",
"]",
")",
")",
"{",
"static",
"::",
"loadHandler",
"(",
"'Horde_Translation_Handler_Gettext'",
")",
";",
"}",
"return",
"static",
"::",
"$",
"_handlers",
"[",
"static",
"::",
"$",
"_domain",
"]",
"->",
"t",
"(",
"$",
"message",
")",
";",
"}"
] | Returns the translation of a message.
@var string $message The string to translate.
@return string The string translation, or the original string if no
translation exists. | [
"Returns",
"the",
"translation",
"of",
"a",
"message",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Translation.php#L90-L96 |
213,967 | moodle/moodle | lib/horde/framework/Horde/Imap/Client/Base/Alerts.php | Horde_Imap_Client_Base_Alerts.add | public function add($alert, $type = null)
{
$this->_alert = new stdClass;
$this->_alert->alert = $alert;
if (!is_null($type)) {
$this->_alert->type = $type;
}
$this->notify();
} | php | public function add($alert, $type = null)
{
$this->_alert = new stdClass;
$this->_alert->alert = $alert;
if (!is_null($type)) {
$this->_alert->type = $type;
}
$this->notify();
} | [
"public",
"function",
"add",
"(",
"$",
"alert",
",",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"_alert",
"=",
"new",
"stdClass",
";",
"$",
"this",
"->",
"_alert",
"->",
"alert",
"=",
"$",
"alert",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"type",
")",
")",
"{",
"$",
"this",
"->",
"_alert",
"->",
"type",
"=",
"$",
"type",
";",
"}",
"$",
"this",
"->",
"notify",
"(",
")",
";",
"}"
] | Add an alert.
@param string $alert The alert string.
@param string $type The alert type. | [
"Add",
"an",
"alert",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Base/Alerts.php#L47-L56 |
213,968 | moodle/moodle | mod/forum/mod_form.php | mod_forum_mod_form.add_completion_rules | public function add_completion_rules() {
$mform =& $this->_form;
$group=array();
$group[] =& $mform->createElement('checkbox', 'completionpostsenabled', '', get_string('completionposts','forum'));
$group[] =& $mform->createElement('text', 'completionposts', '', array('size'=>3));
$mform->setType('completionposts',PARAM_INT);
$mform->addGroup($group, 'completionpostsgroup', get_string('completionpostsgroup','forum'), array(' '), false);
$mform->disabledIf('completionposts','completionpostsenabled','notchecked');
$group=array();
$group[] =& $mform->createElement('checkbox', 'completiondiscussionsenabled', '', get_string('completiondiscussions','forum'));
$group[] =& $mform->createElement('text', 'completiondiscussions', '', array('size'=>3));
$mform->setType('completiondiscussions',PARAM_INT);
$mform->addGroup($group, 'completiondiscussionsgroup', get_string('completiondiscussionsgroup','forum'), array(' '), false);
$mform->disabledIf('completiondiscussions','completiondiscussionsenabled','notchecked');
$group=array();
$group[] =& $mform->createElement('checkbox', 'completionrepliesenabled', '', get_string('completionreplies','forum'));
$group[] =& $mform->createElement('text', 'completionreplies', '', array('size'=>3));
$mform->setType('completionreplies',PARAM_INT);
$mform->addGroup($group, 'completionrepliesgroup', get_string('completionrepliesgroup','forum'), array(' '), false);
$mform->disabledIf('completionreplies','completionrepliesenabled','notchecked');
return array('completiondiscussionsgroup','completionrepliesgroup','completionpostsgroup');
} | php | public function add_completion_rules() {
$mform =& $this->_form;
$group=array();
$group[] =& $mform->createElement('checkbox', 'completionpostsenabled', '', get_string('completionposts','forum'));
$group[] =& $mform->createElement('text', 'completionposts', '', array('size'=>3));
$mform->setType('completionposts',PARAM_INT);
$mform->addGroup($group, 'completionpostsgroup', get_string('completionpostsgroup','forum'), array(' '), false);
$mform->disabledIf('completionposts','completionpostsenabled','notchecked');
$group=array();
$group[] =& $mform->createElement('checkbox', 'completiondiscussionsenabled', '', get_string('completiondiscussions','forum'));
$group[] =& $mform->createElement('text', 'completiondiscussions', '', array('size'=>3));
$mform->setType('completiondiscussions',PARAM_INT);
$mform->addGroup($group, 'completiondiscussionsgroup', get_string('completiondiscussionsgroup','forum'), array(' '), false);
$mform->disabledIf('completiondiscussions','completiondiscussionsenabled','notchecked');
$group=array();
$group[] =& $mform->createElement('checkbox', 'completionrepliesenabled', '', get_string('completionreplies','forum'));
$group[] =& $mform->createElement('text', 'completionreplies', '', array('size'=>3));
$mform->setType('completionreplies',PARAM_INT);
$mform->addGroup($group, 'completionrepliesgroup', get_string('completionrepliesgroup','forum'), array(' '), false);
$mform->disabledIf('completionreplies','completionrepliesenabled','notchecked');
return array('completiondiscussionsgroup','completionrepliesgroup','completionpostsgroup');
} | [
"public",
"function",
"add_completion_rules",
"(",
")",
"{",
"$",
"mform",
"=",
"&",
"$",
"this",
"->",
"_form",
";",
"$",
"group",
"=",
"array",
"(",
")",
";",
"$",
"group",
"[",
"]",
"=",
"&",
"$",
"mform",
"->",
"createElement",
"(",
"'checkbox'",
",",
"'completionpostsenabled'",
",",
"''",
",",
"get_string",
"(",
"'completionposts'",
",",
"'forum'",
")",
")",
";",
"$",
"group",
"[",
"]",
"=",
"&",
"$",
"mform",
"->",
"createElement",
"(",
"'text'",
",",
"'completionposts'",
",",
"''",
",",
"array",
"(",
"'size'",
"=>",
"3",
")",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'completionposts'",
",",
"PARAM_INT",
")",
";",
"$",
"mform",
"->",
"addGroup",
"(",
"$",
"group",
",",
"'completionpostsgroup'",
",",
"get_string",
"(",
"'completionpostsgroup'",
",",
"'forum'",
")",
",",
"array",
"(",
"' '",
")",
",",
"false",
")",
";",
"$",
"mform",
"->",
"disabledIf",
"(",
"'completionposts'",
",",
"'completionpostsenabled'",
",",
"'notchecked'",
")",
";",
"$",
"group",
"=",
"array",
"(",
")",
";",
"$",
"group",
"[",
"]",
"=",
"&",
"$",
"mform",
"->",
"createElement",
"(",
"'checkbox'",
",",
"'completiondiscussionsenabled'",
",",
"''",
",",
"get_string",
"(",
"'completiondiscussions'",
",",
"'forum'",
")",
")",
";",
"$",
"group",
"[",
"]",
"=",
"&",
"$",
"mform",
"->",
"createElement",
"(",
"'text'",
",",
"'completiondiscussions'",
",",
"''",
",",
"array",
"(",
"'size'",
"=>",
"3",
")",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'completiondiscussions'",
",",
"PARAM_INT",
")",
";",
"$",
"mform",
"->",
"addGroup",
"(",
"$",
"group",
",",
"'completiondiscussionsgroup'",
",",
"get_string",
"(",
"'completiondiscussionsgroup'",
",",
"'forum'",
")",
",",
"array",
"(",
"' '",
")",
",",
"false",
")",
";",
"$",
"mform",
"->",
"disabledIf",
"(",
"'completiondiscussions'",
",",
"'completiondiscussionsenabled'",
",",
"'notchecked'",
")",
";",
"$",
"group",
"=",
"array",
"(",
")",
";",
"$",
"group",
"[",
"]",
"=",
"&",
"$",
"mform",
"->",
"createElement",
"(",
"'checkbox'",
",",
"'completionrepliesenabled'",
",",
"''",
",",
"get_string",
"(",
"'completionreplies'",
",",
"'forum'",
")",
")",
";",
"$",
"group",
"[",
"]",
"=",
"&",
"$",
"mform",
"->",
"createElement",
"(",
"'text'",
",",
"'completionreplies'",
",",
"''",
",",
"array",
"(",
"'size'",
"=>",
"3",
")",
")",
";",
"$",
"mform",
"->",
"setType",
"(",
"'completionreplies'",
",",
"PARAM_INT",
")",
";",
"$",
"mform",
"->",
"addGroup",
"(",
"$",
"group",
",",
"'completionrepliesgroup'",
",",
"get_string",
"(",
"'completionrepliesgroup'",
",",
"'forum'",
")",
",",
"array",
"(",
"' '",
")",
",",
"false",
")",
";",
"$",
"mform",
"->",
"disabledIf",
"(",
"'completionreplies'",
",",
"'completionrepliesenabled'",
",",
"'notchecked'",
")",
";",
"return",
"array",
"(",
"'completiondiscussionsgroup'",
",",
"'completionrepliesgroup'",
",",
"'completionpostsgroup'",
")",
";",
"}"
] | Add custom completion rules.
@return array Array of string IDs of added items, empty array if none | [
"Add",
"custom",
"completion",
"rules",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/mod_form.php#L286-L311 |
213,969 | moodle/moodle | message/classes/privacy/provider.php | provider.export_user_preferences | public static function export_user_preferences(int $userid) {
$preferences = get_user_preferences(null, null, $userid);
foreach ($preferences as $name => $value) {
if (
(substr($name, 0, 16) == 'message_provider') ||
($name == 'message_blocknoncontacts') ||
($name == 'message_entertosend')
) {
writer::export_user_preference(
'core_message',
$name,
$value,
get_string('privacy:request:preference:set', 'core_message', (object) [
'name' => $name,
'value' => $value,
])
);
}
}
} | php | public static function export_user_preferences(int $userid) {
$preferences = get_user_preferences(null, null, $userid);
foreach ($preferences as $name => $value) {
if (
(substr($name, 0, 16) == 'message_provider') ||
($name == 'message_blocknoncontacts') ||
($name == 'message_entertosend')
) {
writer::export_user_preference(
'core_message',
$name,
$value,
get_string('privacy:request:preference:set', 'core_message', (object) [
'name' => $name,
'value' => $value,
])
);
}
}
} | [
"public",
"static",
"function",
"export_user_preferences",
"(",
"int",
"$",
"userid",
")",
"{",
"$",
"preferences",
"=",
"get_user_preferences",
"(",
"null",
",",
"null",
",",
"$",
"userid",
")",
";",
"foreach",
"(",
"$",
"preferences",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"(",
"substr",
"(",
"$",
"name",
",",
"0",
",",
"16",
")",
"==",
"'message_provider'",
")",
"||",
"(",
"$",
"name",
"==",
"'message_blocknoncontacts'",
")",
"||",
"(",
"$",
"name",
"==",
"'message_entertosend'",
")",
")",
"{",
"writer",
"::",
"export_user_preference",
"(",
"'core_message'",
",",
"$",
"name",
",",
"$",
"value",
",",
"get_string",
"(",
"'privacy:request:preference:set'",
",",
"'core_message'",
",",
"(",
"object",
")",
"[",
"'name'",
"=>",
"$",
"name",
",",
"'value'",
"=>",
"$",
"value",
",",
"]",
")",
")",
";",
"}",
"}",
"}"
] | Store all user preferences for core message.
@param int $userid The userid of the user whose data is to be exported. | [
"Store",
"all",
"user",
"preferences",
"for",
"core",
"message",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/privacy/provider.php#L183-L202 |
213,970 | moodle/moodle | message/classes/privacy/provider.php | provider.export_conversations | public static function export_conversations(int $userid, string $component, string $itemtype, \context $context,
array $subcontext = [], int $itemid = 0) {
global $DB;
// Search for conversations for this user in this area.
$sql = "SELECT DISTINCT mc.*
FROM {message_conversations} mc
JOIN {message_conversation_members} mcm
ON (mcm.conversationid = mc.id AND mcm.userid = :userid)";
$params = [
'userid' => $userid
];
// Get the conversations for the defined component and itemtype.
if (!empty($component) && !empty($itemtype)) {
$sql .= " WHERE mc.component = :component AND mc.itemtype = :itemtype";
$params['component'] = $component;
$params['itemtype'] = $itemtype;
if (!empty($itemid)) {
$sql .= " AND mc.itemid = :itemid";
$params['itemid'] = $itemid;
}
} else {
// Get all the conversations without any component and itemtype, so with null contextid.
$sql .= " WHERE mc.contextid IS NULL";
}
if ($conversations = $DB->get_records_sql($sql, $params)) {
// Export conversation messages.
foreach ($conversations as $conversation) {
self::export_user_data_conversation_messages($userid, $conversation, $context, $subcontext);
}
}
} | php | public static function export_conversations(int $userid, string $component, string $itemtype, \context $context,
array $subcontext = [], int $itemid = 0) {
global $DB;
// Search for conversations for this user in this area.
$sql = "SELECT DISTINCT mc.*
FROM {message_conversations} mc
JOIN {message_conversation_members} mcm
ON (mcm.conversationid = mc.id AND mcm.userid = :userid)";
$params = [
'userid' => $userid
];
// Get the conversations for the defined component and itemtype.
if (!empty($component) && !empty($itemtype)) {
$sql .= " WHERE mc.component = :component AND mc.itemtype = :itemtype";
$params['component'] = $component;
$params['itemtype'] = $itemtype;
if (!empty($itemid)) {
$sql .= " AND mc.itemid = :itemid";
$params['itemid'] = $itemid;
}
} else {
// Get all the conversations without any component and itemtype, so with null contextid.
$sql .= " WHERE mc.contextid IS NULL";
}
if ($conversations = $DB->get_records_sql($sql, $params)) {
// Export conversation messages.
foreach ($conversations as $conversation) {
self::export_user_data_conversation_messages($userid, $conversation, $context, $subcontext);
}
}
} | [
"public",
"static",
"function",
"export_conversations",
"(",
"int",
"$",
"userid",
",",
"string",
"$",
"component",
",",
"string",
"$",
"itemtype",
",",
"\\",
"context",
"$",
"context",
",",
"array",
"$",
"subcontext",
"=",
"[",
"]",
",",
"int",
"$",
"itemid",
"=",
"0",
")",
"{",
"global",
"$",
"DB",
";",
"// Search for conversations for this user in this area.",
"$",
"sql",
"=",
"\"SELECT DISTINCT mc.*\n FROM {message_conversations} mc\n JOIN {message_conversation_members} mcm\n ON (mcm.conversationid = mc.id AND mcm.userid = :userid)\"",
";",
"$",
"params",
"=",
"[",
"'userid'",
"=>",
"$",
"userid",
"]",
";",
"// Get the conversations for the defined component and itemtype.",
"if",
"(",
"!",
"empty",
"(",
"$",
"component",
")",
"&&",
"!",
"empty",
"(",
"$",
"itemtype",
")",
")",
"{",
"$",
"sql",
".=",
"\" WHERE mc.component = :component AND mc.itemtype = :itemtype\"",
";",
"$",
"params",
"[",
"'component'",
"]",
"=",
"$",
"component",
";",
"$",
"params",
"[",
"'itemtype'",
"]",
"=",
"$",
"itemtype",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"itemid",
")",
")",
"{",
"$",
"sql",
".=",
"\" AND mc.itemid = :itemid\"",
";",
"$",
"params",
"[",
"'itemid'",
"]",
"=",
"$",
"itemid",
";",
"}",
"}",
"else",
"{",
"// Get all the conversations without any component and itemtype, so with null contextid.",
"$",
"sql",
".=",
"\" WHERE mc.contextid IS NULL\"",
";",
"}",
"if",
"(",
"$",
"conversations",
"=",
"$",
"DB",
"->",
"get_records_sql",
"(",
"$",
"sql",
",",
"$",
"params",
")",
")",
"{",
"// Export conversation messages.",
"foreach",
"(",
"$",
"conversations",
"as",
"$",
"conversation",
")",
"{",
"self",
"::",
"export_user_data_conversation_messages",
"(",
"$",
"userid",
",",
"$",
"conversation",
",",
"$",
"context",
",",
"$",
"subcontext",
")",
";",
"}",
"}",
"}"
] | Store all conversations which match the specified component, itemtype, and itemid.
Conversations without context (for now, the private ones) are stored in '<$context> | Messages | <Other user id>'.
Conversations with context are stored in '<$context> | Messages | <Conversation item type> | <Conversation name>'.
@param int $userid The user whose information is to be exported.
@param string $component The component to fetch data from.
@param string $itemtype The itemtype that the data was exported in within the component.
@param \context $context The context to export for.
@param array $subcontext The sub-context in which to export this data.
@param int $itemid Optional itemid associated with component. | [
"Store",
"all",
"conversations",
"which",
"match",
"the",
"specified",
"component",
"itemtype",
"and",
"itemid",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/privacy/provider.php#L503-L536 |
213,971 | moodle/moodle | message/classes/privacy/provider.php | provider.delete_user_data | protected static function delete_user_data(int $userid) {
global $DB;
// Delete individual conversations information for this user.
self::delete_user_data_conversations($userid, [], '', '');
// Delete contacts, requests, users blocked and notifications.
$DB->delete_records_select('message_contacts', 'userid = ? OR contactid = ?', [$userid, $userid]);
$DB->delete_records_select('message_contact_requests', 'userid = ? OR requesteduserid = ?', [$userid, $userid]);
$DB->delete_records_select('message_users_blocked', 'userid = ? OR blockeduserid = ?', [$userid, $userid]);
$DB->delete_records_select('notifications', 'useridfrom = ? OR useridto = ?', [$userid, $userid]);
} | php | protected static function delete_user_data(int $userid) {
global $DB;
// Delete individual conversations information for this user.
self::delete_user_data_conversations($userid, [], '', '');
// Delete contacts, requests, users blocked and notifications.
$DB->delete_records_select('message_contacts', 'userid = ? OR contactid = ?', [$userid, $userid]);
$DB->delete_records_select('message_contact_requests', 'userid = ? OR requesteduserid = ?', [$userid, $userid]);
$DB->delete_records_select('message_users_blocked', 'userid = ? OR blockeduserid = ?', [$userid, $userid]);
$DB->delete_records_select('notifications', 'useridfrom = ? OR useridto = ?', [$userid, $userid]);
} | [
"protected",
"static",
"function",
"delete_user_data",
"(",
"int",
"$",
"userid",
")",
"{",
"global",
"$",
"DB",
";",
"// Delete individual conversations information for this user.",
"self",
"::",
"delete_user_data_conversations",
"(",
"$",
"userid",
",",
"[",
"]",
",",
"''",
",",
"''",
")",
";",
"// Delete contacts, requests, users blocked and notifications.",
"$",
"DB",
"->",
"delete_records_select",
"(",
"'message_contacts'",
",",
"'userid = ? OR contactid = ?'",
",",
"[",
"$",
"userid",
",",
"$",
"userid",
"]",
")",
";",
"$",
"DB",
"->",
"delete_records_select",
"(",
"'message_contact_requests'",
",",
"'userid = ? OR requesteduserid = ?'",
",",
"[",
"$",
"userid",
",",
"$",
"userid",
"]",
")",
";",
"$",
"DB",
"->",
"delete_records_select",
"(",
"'message_users_blocked'",
",",
"'userid = ? OR blockeduserid = ?'",
",",
"[",
"$",
"userid",
",",
"$",
"userid",
"]",
")",
";",
"$",
"DB",
"->",
"delete_records_select",
"(",
"'notifications'",
",",
"'useridfrom = ? OR useridto = ?'",
",",
"[",
"$",
"userid",
",",
"$",
"userid",
"]",
")",
";",
"}"
] | Delete all user data for the specified user.
@param int $userid The user id | [
"Delete",
"all",
"user",
"data",
"for",
"the",
"specified",
"user",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/privacy/provider.php#L814-L825 |
213,972 | moodle/moodle | message/classes/privacy/provider.php | provider.export_user_data_contacts | protected static function export_user_data_contacts(int $userid) {
global $DB;
$context = \context_user::instance($userid);
// Get the user's contacts.
if ($contacts = $DB->get_records_select('message_contacts', 'userid = ? OR contactid = ?', [$userid, $userid], 'id ASC')) {
$contactdata = [];
foreach ($contacts as $contact) {
$contactdata[] = (object) [
'contact' => transform::user($contact->contactid)
];
}
writer::with_context($context)->export_data([get_string('contacts', 'core_message')], (object) $contactdata);
}
} | php | protected static function export_user_data_contacts(int $userid) {
global $DB;
$context = \context_user::instance($userid);
// Get the user's contacts.
if ($contacts = $DB->get_records_select('message_contacts', 'userid = ? OR contactid = ?', [$userid, $userid], 'id ASC')) {
$contactdata = [];
foreach ($contacts as $contact) {
$contactdata[] = (object) [
'contact' => transform::user($contact->contactid)
];
}
writer::with_context($context)->export_data([get_string('contacts', 'core_message')], (object) $contactdata);
}
} | [
"protected",
"static",
"function",
"export_user_data_contacts",
"(",
"int",
"$",
"userid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"context",
"=",
"\\",
"context_user",
"::",
"instance",
"(",
"$",
"userid",
")",
";",
"// Get the user's contacts.",
"if",
"(",
"$",
"contacts",
"=",
"$",
"DB",
"->",
"get_records_select",
"(",
"'message_contacts'",
",",
"'userid = ? OR contactid = ?'",
",",
"[",
"$",
"userid",
",",
"$",
"userid",
"]",
",",
"'id ASC'",
")",
")",
"{",
"$",
"contactdata",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"contacts",
"as",
"$",
"contact",
")",
"{",
"$",
"contactdata",
"[",
"]",
"=",
"(",
"object",
")",
"[",
"'contact'",
"=>",
"transform",
"::",
"user",
"(",
"$",
"contact",
"->",
"contactid",
")",
"]",
";",
"}",
"writer",
"::",
"with_context",
"(",
"$",
"context",
")",
"->",
"export_data",
"(",
"[",
"get_string",
"(",
"'contacts'",
",",
"'core_message'",
")",
"]",
",",
"(",
"object",
")",
"$",
"contactdata",
")",
";",
"}",
"}"
] | Export the messaging contact data.
@param int $userid | [
"Export",
"the",
"messaging",
"contact",
"data",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/privacy/provider.php#L832-L847 |
213,973 | moodle/moodle | message/classes/privacy/provider.php | provider.export_user_data_contact_requests | protected static function export_user_data_contact_requests(int $userid) {
global $DB;
$context = \context_user::instance($userid);
if ($contactrequests = $DB->get_records_select('message_contact_requests', 'userid = ? OR requesteduserid = ?',
[$userid, $userid], 'id ASC')) {
$contactrequestsdata = [];
foreach ($contactrequests as $contactrequest) {
if ($userid == $contactrequest->requesteduserid) {
$maderequest = false;
$contactid = $contactrequest->userid;
} else {
$maderequest = true;
$contactid = $contactrequest->requesteduserid;
}
$contactrequestsdata[] = (object) [
'contactrequest' => transform::user($contactid),
'maderequest' => transform::yesno($maderequest)
];
}
writer::with_context($context)->export_data([get_string('contactrequests', 'core_message')],
(object) $contactrequestsdata);
}
} | php | protected static function export_user_data_contact_requests(int $userid) {
global $DB;
$context = \context_user::instance($userid);
if ($contactrequests = $DB->get_records_select('message_contact_requests', 'userid = ? OR requesteduserid = ?',
[$userid, $userid], 'id ASC')) {
$contactrequestsdata = [];
foreach ($contactrequests as $contactrequest) {
if ($userid == $contactrequest->requesteduserid) {
$maderequest = false;
$contactid = $contactrequest->userid;
} else {
$maderequest = true;
$contactid = $contactrequest->requesteduserid;
}
$contactrequestsdata[] = (object) [
'contactrequest' => transform::user($contactid),
'maderequest' => transform::yesno($maderequest)
];
}
writer::with_context($context)->export_data([get_string('contactrequests', 'core_message')],
(object) $contactrequestsdata);
}
} | [
"protected",
"static",
"function",
"export_user_data_contact_requests",
"(",
"int",
"$",
"userid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"context",
"=",
"\\",
"context_user",
"::",
"instance",
"(",
"$",
"userid",
")",
";",
"if",
"(",
"$",
"contactrequests",
"=",
"$",
"DB",
"->",
"get_records_select",
"(",
"'message_contact_requests'",
",",
"'userid = ? OR requesteduserid = ?'",
",",
"[",
"$",
"userid",
",",
"$",
"userid",
"]",
",",
"'id ASC'",
")",
")",
"{",
"$",
"contactrequestsdata",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"contactrequests",
"as",
"$",
"contactrequest",
")",
"{",
"if",
"(",
"$",
"userid",
"==",
"$",
"contactrequest",
"->",
"requesteduserid",
")",
"{",
"$",
"maderequest",
"=",
"false",
";",
"$",
"contactid",
"=",
"$",
"contactrequest",
"->",
"userid",
";",
"}",
"else",
"{",
"$",
"maderequest",
"=",
"true",
";",
"$",
"contactid",
"=",
"$",
"contactrequest",
"->",
"requesteduserid",
";",
"}",
"$",
"contactrequestsdata",
"[",
"]",
"=",
"(",
"object",
")",
"[",
"'contactrequest'",
"=>",
"transform",
"::",
"user",
"(",
"$",
"contactid",
")",
",",
"'maderequest'",
"=>",
"transform",
"::",
"yesno",
"(",
"$",
"maderequest",
")",
"]",
";",
"}",
"writer",
"::",
"with_context",
"(",
"$",
"context",
")",
"->",
"export_data",
"(",
"[",
"get_string",
"(",
"'contactrequests'",
",",
"'core_message'",
")",
"]",
",",
"(",
"object",
")",
"$",
"contactrequestsdata",
")",
";",
"}",
"}"
] | Export the messaging contact requests data.
@param int $userid | [
"Export",
"the",
"messaging",
"contact",
"requests",
"data",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/privacy/provider.php#L854-L879 |
213,974 | moodle/moodle | message/classes/privacy/provider.php | provider.export_user_data_blocked_users | protected static function export_user_data_blocked_users(int $userid) {
global $DB;
$context = \context_user::instance($userid);
if ($blockedusers = $DB->get_records('message_users_blocked', ['userid' => $userid], 'id ASC')) {
$blockedusersdata = [];
foreach ($blockedusers as $blockeduser) {
$blockedusersdata[] = (object) [
'blockeduser' => transform::user($blockeduser->blockeduserid)
];
}
writer::with_context($context)->export_data([get_string('blockedusers', 'core_message')], (object) $blockedusersdata);
}
} | php | protected static function export_user_data_blocked_users(int $userid) {
global $DB;
$context = \context_user::instance($userid);
if ($blockedusers = $DB->get_records('message_users_blocked', ['userid' => $userid], 'id ASC')) {
$blockedusersdata = [];
foreach ($blockedusers as $blockeduser) {
$blockedusersdata[] = (object) [
'blockeduser' => transform::user($blockeduser->blockeduserid)
];
}
writer::with_context($context)->export_data([get_string('blockedusers', 'core_message')], (object) $blockedusersdata);
}
} | [
"protected",
"static",
"function",
"export_user_data_blocked_users",
"(",
"int",
"$",
"userid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"context",
"=",
"\\",
"context_user",
"::",
"instance",
"(",
"$",
"userid",
")",
";",
"if",
"(",
"$",
"blockedusers",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'message_users_blocked'",
",",
"[",
"'userid'",
"=>",
"$",
"userid",
"]",
",",
"'id ASC'",
")",
")",
"{",
"$",
"blockedusersdata",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"blockedusers",
"as",
"$",
"blockeduser",
")",
"{",
"$",
"blockedusersdata",
"[",
"]",
"=",
"(",
"object",
")",
"[",
"'blockeduser'",
"=>",
"transform",
"::",
"user",
"(",
"$",
"blockeduser",
"->",
"blockeduserid",
")",
"]",
";",
"}",
"writer",
"::",
"with_context",
"(",
"$",
"context",
")",
"->",
"export_data",
"(",
"[",
"get_string",
"(",
"'blockedusers'",
",",
"'core_message'",
")",
"]",
",",
"(",
"object",
")",
"$",
"blockedusersdata",
")",
";",
"}",
"}"
] | Export the messaging blocked users data.
@param int $userid | [
"Export",
"the",
"messaging",
"blocked",
"users",
"data",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/privacy/provider.php#L886-L900 |
213,975 | moodle/moodle | message/classes/privacy/provider.php | provider.export_user_data_notifications | protected static function export_user_data_notifications(int $userid) {
global $DB;
$context = \context_user::instance($userid);
$notificationdata = [];
$select = "useridfrom = ? OR useridto = ?";
$notifications = $DB->get_recordset_select('notifications', $select, [$userid, $userid], 'timecreated ASC');
foreach ($notifications as $notification) {
$timeread = !is_null($notification->timeread) ? transform::datetime($notification->timeread) : '-';
$data = (object) [
'subject' => $notification->subject,
'fullmessage' => $notification->fullmessage,
'smallmessage' => $notification->smallmessage,
'component' => $notification->component,
'eventtype' => $notification->eventtype,
'contexturl' => $notification->contexturl,
'contexturlname' => $notification->contexturlname,
'timeread' => $timeread,
'timecreated' => transform::datetime($notification->timecreated),
'customdata' => $notification->customdata,
];
$notificationdata[] = $data;
}
$notifications->close();
writer::with_context($context)->export_data([get_string('notifications', 'core_message')], (object) $notificationdata);
} | php | protected static function export_user_data_notifications(int $userid) {
global $DB;
$context = \context_user::instance($userid);
$notificationdata = [];
$select = "useridfrom = ? OR useridto = ?";
$notifications = $DB->get_recordset_select('notifications', $select, [$userid, $userid], 'timecreated ASC');
foreach ($notifications as $notification) {
$timeread = !is_null($notification->timeread) ? transform::datetime($notification->timeread) : '-';
$data = (object) [
'subject' => $notification->subject,
'fullmessage' => $notification->fullmessage,
'smallmessage' => $notification->smallmessage,
'component' => $notification->component,
'eventtype' => $notification->eventtype,
'contexturl' => $notification->contexturl,
'contexturlname' => $notification->contexturlname,
'timeread' => $timeread,
'timecreated' => transform::datetime($notification->timecreated),
'customdata' => $notification->customdata,
];
$notificationdata[] = $data;
}
$notifications->close();
writer::with_context($context)->export_data([get_string('notifications', 'core_message')], (object) $notificationdata);
} | [
"protected",
"static",
"function",
"export_user_data_notifications",
"(",
"int",
"$",
"userid",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"context",
"=",
"\\",
"context_user",
"::",
"instance",
"(",
"$",
"userid",
")",
";",
"$",
"notificationdata",
"=",
"[",
"]",
";",
"$",
"select",
"=",
"\"useridfrom = ? OR useridto = ?\"",
";",
"$",
"notifications",
"=",
"$",
"DB",
"->",
"get_recordset_select",
"(",
"'notifications'",
",",
"$",
"select",
",",
"[",
"$",
"userid",
",",
"$",
"userid",
"]",
",",
"'timecreated ASC'",
")",
";",
"foreach",
"(",
"$",
"notifications",
"as",
"$",
"notification",
")",
"{",
"$",
"timeread",
"=",
"!",
"is_null",
"(",
"$",
"notification",
"->",
"timeread",
")",
"?",
"transform",
"::",
"datetime",
"(",
"$",
"notification",
"->",
"timeread",
")",
":",
"'-'",
";",
"$",
"data",
"=",
"(",
"object",
")",
"[",
"'subject'",
"=>",
"$",
"notification",
"->",
"subject",
",",
"'fullmessage'",
"=>",
"$",
"notification",
"->",
"fullmessage",
",",
"'smallmessage'",
"=>",
"$",
"notification",
"->",
"smallmessage",
",",
"'component'",
"=>",
"$",
"notification",
"->",
"component",
",",
"'eventtype'",
"=>",
"$",
"notification",
"->",
"eventtype",
",",
"'contexturl'",
"=>",
"$",
"notification",
"->",
"contexturl",
",",
"'contexturlname'",
"=>",
"$",
"notification",
"->",
"contexturlname",
",",
"'timeread'",
"=>",
"$",
"timeread",
",",
"'timecreated'",
"=>",
"transform",
"::",
"datetime",
"(",
"$",
"notification",
"->",
"timecreated",
")",
",",
"'customdata'",
"=>",
"$",
"notification",
"->",
"customdata",
",",
"]",
";",
"$",
"notificationdata",
"[",
"]",
"=",
"$",
"data",
";",
"}",
"$",
"notifications",
"->",
"close",
"(",
")",
";",
"writer",
"::",
"with_context",
"(",
"$",
"context",
")",
"->",
"export_data",
"(",
"[",
"get_string",
"(",
"'notifications'",
",",
"'core_message'",
")",
"]",
",",
"(",
"object",
")",
"$",
"notificationdata",
")",
";",
"}"
] | Export the notification data.
@param int $userid | [
"Export",
"the",
"notification",
"data",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/privacy/provider.php#L1028-L1057 |
213,976 | moodle/moodle | lib/classes/scss.php | core_scss.to_css | public function to_css() {
$content = implode(';', $this->scssprepend);
if (!empty($this->scssfile)) {
$content .= file_get_contents($this->scssfile);
}
$content .= implode(';', $this->scsscontent);
return $this->compile($content);
} | php | public function to_css() {
$content = implode(';', $this->scssprepend);
if (!empty($this->scssfile)) {
$content .= file_get_contents($this->scssfile);
}
$content .= implode(';', $this->scsscontent);
return $this->compile($content);
} | [
"public",
"function",
"to_css",
"(",
")",
"{",
"$",
"content",
"=",
"implode",
"(",
"';'",
",",
"$",
"this",
"->",
"scssprepend",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"scssfile",
")",
")",
"{",
"$",
"content",
".=",
"file_get_contents",
"(",
"$",
"this",
"->",
"scssfile",
")",
";",
"}",
"$",
"content",
".=",
"implode",
"(",
"';'",
",",
"$",
"this",
"->",
"scsscontent",
")",
";",
"return",
"$",
"this",
"->",
"compile",
"(",
"$",
"content",
")",
";",
"}"
] | Compiles to CSS.
@return string | [
"Compiles",
"to",
"CSS",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/scss.php#L92-L99 |
213,977 | moodle/moodle | lib/classes/scss.php | core_scss.compile | public function compile($code, $path = null) {
global $CFG;
$pathtosassc = trim($CFG->pathtosassc ?? '');
if (!empty($pathtosassc) && is_executable($pathtosassc) && !is_dir($pathtosassc)) {
$process = proc_open(
$pathtosassc . ' -I' . implode(':', $this->importPaths) . ' -s',
[
['pipe', 'r'], // Set the process stdin pipe to read mode.
['pipe', 'w'], // Set the process stdout pipe to write mode.
['pipe', 'w'] // Set the process stderr pipe to write mode.
],
$pipes // Pipes become available in $pipes (pass by reference).
);
if (is_resource($process)) {
fwrite($pipes[0], $code); // Write the raw scss to the sassc process stdin.
fclose($pipes[0]);
$stdout = stream_get_contents($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[1]);
fclose($pipes[2]);
// The proc_close function returns the process exit status. Anything other than 0 is bad.
if (proc_close($process) !== 0) {
throw new coding_exception($stderr);
}
// Compiled CSS code will be available from stdout.
return $stdout;
}
}
return parent::compile($code, $path);
} | php | public function compile($code, $path = null) {
global $CFG;
$pathtosassc = trim($CFG->pathtosassc ?? '');
if (!empty($pathtosassc) && is_executable($pathtosassc) && !is_dir($pathtosassc)) {
$process = proc_open(
$pathtosassc . ' -I' . implode(':', $this->importPaths) . ' -s',
[
['pipe', 'r'], // Set the process stdin pipe to read mode.
['pipe', 'w'], // Set the process stdout pipe to write mode.
['pipe', 'w'] // Set the process stderr pipe to write mode.
],
$pipes // Pipes become available in $pipes (pass by reference).
);
if (is_resource($process)) {
fwrite($pipes[0], $code); // Write the raw scss to the sassc process stdin.
fclose($pipes[0]);
$stdout = stream_get_contents($pipes[1]);
$stderr = stream_get_contents($pipes[2]);
fclose($pipes[1]);
fclose($pipes[2]);
// The proc_close function returns the process exit status. Anything other than 0 is bad.
if (proc_close($process) !== 0) {
throw new coding_exception($stderr);
}
// Compiled CSS code will be available from stdout.
return $stdout;
}
}
return parent::compile($code, $path);
} | [
"public",
"function",
"compile",
"(",
"$",
"code",
",",
"$",
"path",
"=",
"null",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"pathtosassc",
"=",
"trim",
"(",
"$",
"CFG",
"->",
"pathtosassc",
"??",
"''",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"pathtosassc",
")",
"&&",
"is_executable",
"(",
"$",
"pathtosassc",
")",
"&&",
"!",
"is_dir",
"(",
"$",
"pathtosassc",
")",
")",
"{",
"$",
"process",
"=",
"proc_open",
"(",
"$",
"pathtosassc",
".",
"' -I'",
".",
"implode",
"(",
"':'",
",",
"$",
"this",
"->",
"importPaths",
")",
".",
"' -s'",
",",
"[",
"[",
"'pipe'",
",",
"'r'",
"]",
",",
"// Set the process stdin pipe to read mode.",
"[",
"'pipe'",
",",
"'w'",
"]",
",",
"// Set the process stdout pipe to write mode.",
"[",
"'pipe'",
",",
"'w'",
"]",
"// Set the process stderr pipe to write mode.",
"]",
",",
"$",
"pipes",
"// Pipes become available in $pipes (pass by reference).",
")",
";",
"if",
"(",
"is_resource",
"(",
"$",
"process",
")",
")",
"{",
"fwrite",
"(",
"$",
"pipes",
"[",
"0",
"]",
",",
"$",
"code",
")",
";",
"// Write the raw scss to the sassc process stdin.",
"fclose",
"(",
"$",
"pipes",
"[",
"0",
"]",
")",
";",
"$",
"stdout",
"=",
"stream_get_contents",
"(",
"$",
"pipes",
"[",
"1",
"]",
")",
";",
"$",
"stderr",
"=",
"stream_get_contents",
"(",
"$",
"pipes",
"[",
"2",
"]",
")",
";",
"fclose",
"(",
"$",
"pipes",
"[",
"1",
"]",
")",
";",
"fclose",
"(",
"$",
"pipes",
"[",
"2",
"]",
")",
";",
"// The proc_close function returns the process exit status. Anything other than 0 is bad.",
"if",
"(",
"proc_close",
"(",
"$",
"process",
")",
"!==",
"0",
")",
"{",
"throw",
"new",
"coding_exception",
"(",
"$",
"stderr",
")",
";",
"}",
"// Compiled CSS code will be available from stdout.",
"return",
"$",
"stdout",
";",
"}",
"}",
"return",
"parent",
"::",
"compile",
"(",
"$",
"code",
",",
"$",
"path",
")",
";",
"}"
] | Compile scss.
Overrides ScssPHP's implementation, using the SassC compiler if it is available.
@param string $code SCSS to compile.
@param string $path Path to SCSS to compile.
@return string The compiled CSS. | [
"Compile",
"scss",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/scss.php#L111-L147 |
213,978 | moodle/moodle | lib/classes/scss.php | core_scss.is_valid_file | protected function is_valid_file($path) {
global $CFG;
$realpath = realpath($path);
// Additional theme directory.
$addthemedirectory = core_component::get_plugin_types()['theme'];
$addrealroot = realpath($addthemedirectory);
// Original theme directory.
$themedirectory = $CFG->dirroot . "/theme";
$realroot = realpath($themedirectory);
// File should end in .scss and must be in sites theme directory, else ignore it.
$pathvalid = $realpath !== false;
$pathvalid = $pathvalid && (substr($path, -5) === '.scss');
$pathvalid = $pathvalid && (strpos($realpath, $realroot) === 0 || strpos($realpath, $addrealroot) === 0);
return $pathvalid;
} | php | protected function is_valid_file($path) {
global $CFG;
$realpath = realpath($path);
// Additional theme directory.
$addthemedirectory = core_component::get_plugin_types()['theme'];
$addrealroot = realpath($addthemedirectory);
// Original theme directory.
$themedirectory = $CFG->dirroot . "/theme";
$realroot = realpath($themedirectory);
// File should end in .scss and must be in sites theme directory, else ignore it.
$pathvalid = $realpath !== false;
$pathvalid = $pathvalid && (substr($path, -5) === '.scss');
$pathvalid = $pathvalid && (strpos($realpath, $realroot) === 0 || strpos($realpath, $addrealroot) === 0);
return $pathvalid;
} | [
"protected",
"function",
"is_valid_file",
"(",
"$",
"path",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"realpath",
"=",
"realpath",
"(",
"$",
"path",
")",
";",
"// Additional theme directory.",
"$",
"addthemedirectory",
"=",
"core_component",
"::",
"get_plugin_types",
"(",
")",
"[",
"'theme'",
"]",
";",
"$",
"addrealroot",
"=",
"realpath",
"(",
"$",
"addthemedirectory",
")",
";",
"// Original theme directory.",
"$",
"themedirectory",
"=",
"$",
"CFG",
"->",
"dirroot",
".",
"\"/theme\"",
";",
"$",
"realroot",
"=",
"realpath",
"(",
"$",
"themedirectory",
")",
";",
"// File should end in .scss and must be in sites theme directory, else ignore it.",
"$",
"pathvalid",
"=",
"$",
"realpath",
"!==",
"false",
";",
"$",
"pathvalid",
"=",
"$",
"pathvalid",
"&&",
"(",
"substr",
"(",
"$",
"path",
",",
"-",
"5",
")",
"===",
"'.scss'",
")",
";",
"$",
"pathvalid",
"=",
"$",
"pathvalid",
"&&",
"(",
"strpos",
"(",
"$",
"realpath",
",",
"$",
"realroot",
")",
"===",
"0",
"||",
"strpos",
"(",
"$",
"realpath",
",",
"$",
"addrealroot",
")",
"===",
"0",
")",
";",
"return",
"$",
"pathvalid",
";",
"}"
] | Is the given file valid for import ?
@param $path
@return bool | [
"Is",
"the",
"given",
"file",
"valid",
"for",
"import",
"?"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/scss.php#L184-L202 |
213,979 | moodle/moodle | mod/glossary/classes/external.php | mod_glossary_external.get_browse_modes_from_display_format | protected static function get_browse_modes_from_display_format($format) {
global $DB;
$formats = array();
$dp = $DB->get_record('glossary_formats', array('name' => $format), '*', IGNORE_MISSING);
if ($dp) {
$formats = glossary_get_visible_tabs($dp);
}
// Always add 'letter'.
$modes = array('letter');
if (in_array('category', $formats)) {
$modes[] = 'cat';
}
if (in_array('date', $formats)) {
$modes[] = 'date';
}
if (in_array('author', $formats)) {
$modes[] = 'author';
}
return $modes;
} | php | protected static function get_browse_modes_from_display_format($format) {
global $DB;
$formats = array();
$dp = $DB->get_record('glossary_formats', array('name' => $format), '*', IGNORE_MISSING);
if ($dp) {
$formats = glossary_get_visible_tabs($dp);
}
// Always add 'letter'.
$modes = array('letter');
if (in_array('category', $formats)) {
$modes[] = 'cat';
}
if (in_array('date', $formats)) {
$modes[] = 'date';
}
if (in_array('author', $formats)) {
$modes[] = 'author';
}
return $modes;
} | [
"protected",
"static",
"function",
"get_browse_modes_from_display_format",
"(",
"$",
"format",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"formats",
"=",
"array",
"(",
")",
";",
"$",
"dp",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'glossary_formats'",
",",
"array",
"(",
"'name'",
"=>",
"$",
"format",
")",
",",
"'*'",
",",
"IGNORE_MISSING",
")",
";",
"if",
"(",
"$",
"dp",
")",
"{",
"$",
"formats",
"=",
"glossary_get_visible_tabs",
"(",
"$",
"dp",
")",
";",
"}",
"// Always add 'letter'.",
"$",
"modes",
"=",
"array",
"(",
"'letter'",
")",
";",
"if",
"(",
"in_array",
"(",
"'category'",
",",
"$",
"formats",
")",
")",
"{",
"$",
"modes",
"[",
"]",
"=",
"'cat'",
";",
"}",
"if",
"(",
"in_array",
"(",
"'date'",
",",
"$",
"formats",
")",
")",
"{",
"$",
"modes",
"[",
"]",
"=",
"'date'",
";",
"}",
"if",
"(",
"in_array",
"(",
"'author'",
",",
"$",
"formats",
")",
")",
"{",
"$",
"modes",
"[",
"]",
"=",
"'author'",
";",
"}",
"return",
"$",
"modes",
";",
"}"
] | Get the browse modes from the display format.
This returns some of the terms that can be used when reporting a glossary being viewed.
@param string $format The display format of the glossary.
@return array Containing some of all of the following: letter, cat, date, author. | [
"Get",
"the",
"browse",
"modes",
"from",
"the",
"display",
"format",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/external.php#L51-L74 |
213,980 | moodle/moodle | mod/glossary/classes/external.php | mod_glossary_external.get_entry_return_structure | protected static function get_entry_return_structure($includecat = false) {
$params = array(
'id' => new external_value(PARAM_INT, 'The entry ID'),
'glossaryid' => new external_value(PARAM_INT, 'The glossary ID'),
'userid' => new external_value(PARAM_INT, 'Author ID'),
'userfullname' => new external_value(PARAM_NOTAGS, 'Author full name'),
'userpictureurl' => new external_value(PARAM_URL, 'Author picture'),
'concept' => new external_value(PARAM_RAW, 'The concept'),
'definition' => new external_value(PARAM_RAW, 'The definition'),
'definitionformat' => new external_format_value('definition'),
'definitiontrust' => new external_value(PARAM_BOOL, 'The definition trust flag'),
'definitioninlinefiles' => new external_files('entry definition inline files', VALUE_OPTIONAL),
'attachment' => new external_value(PARAM_BOOL, 'Whether or not the entry has attachments'),
'attachments' => new external_files('attachments', VALUE_OPTIONAL),
'timecreated' => new external_value(PARAM_INT, 'Time created'),
'timemodified' => new external_value(PARAM_INT, 'Time modified'),
'teacherentry' => new external_value(PARAM_BOOL, 'The entry was created by a teacher, or equivalent.'),
'sourceglossaryid' => new external_value(PARAM_INT, 'The source glossary ID'),
'usedynalink' => new external_value(PARAM_BOOL, 'Whether the concept should be automatically linked'),
'casesensitive' => new external_value(PARAM_BOOL, 'When true, the matching is case sensitive'),
'fullmatch' => new external_value(PARAM_BOOL, 'When true, the matching is done on full words only'),
'approved' => new external_value(PARAM_BOOL, 'Whether the entry was approved'),
'tags' => new external_multiple_structure(
\core_tag\external\tag_item_exporter::get_read_structure(), 'Tags', VALUE_OPTIONAL
),
);
if ($includecat) {
$params['categoryid'] = new external_value(PARAM_INT, 'The category ID. This may be' .
' \''. GLOSSARY_SHOW_NOT_CATEGORISED . '\' when the entry is not categorised', VALUE_DEFAULT,
GLOSSARY_SHOW_NOT_CATEGORISED);
$params['categoryname'] = new external_value(PARAM_RAW, 'The category name. May be empty when the entry is' .
' not categorised, or the request was limited to one category.', VALUE_DEFAULT, '');
}
return new external_single_structure($params);
} | php | protected static function get_entry_return_structure($includecat = false) {
$params = array(
'id' => new external_value(PARAM_INT, 'The entry ID'),
'glossaryid' => new external_value(PARAM_INT, 'The glossary ID'),
'userid' => new external_value(PARAM_INT, 'Author ID'),
'userfullname' => new external_value(PARAM_NOTAGS, 'Author full name'),
'userpictureurl' => new external_value(PARAM_URL, 'Author picture'),
'concept' => new external_value(PARAM_RAW, 'The concept'),
'definition' => new external_value(PARAM_RAW, 'The definition'),
'definitionformat' => new external_format_value('definition'),
'definitiontrust' => new external_value(PARAM_BOOL, 'The definition trust flag'),
'definitioninlinefiles' => new external_files('entry definition inline files', VALUE_OPTIONAL),
'attachment' => new external_value(PARAM_BOOL, 'Whether or not the entry has attachments'),
'attachments' => new external_files('attachments', VALUE_OPTIONAL),
'timecreated' => new external_value(PARAM_INT, 'Time created'),
'timemodified' => new external_value(PARAM_INT, 'Time modified'),
'teacherentry' => new external_value(PARAM_BOOL, 'The entry was created by a teacher, or equivalent.'),
'sourceglossaryid' => new external_value(PARAM_INT, 'The source glossary ID'),
'usedynalink' => new external_value(PARAM_BOOL, 'Whether the concept should be automatically linked'),
'casesensitive' => new external_value(PARAM_BOOL, 'When true, the matching is case sensitive'),
'fullmatch' => new external_value(PARAM_BOOL, 'When true, the matching is done on full words only'),
'approved' => new external_value(PARAM_BOOL, 'Whether the entry was approved'),
'tags' => new external_multiple_structure(
\core_tag\external\tag_item_exporter::get_read_structure(), 'Tags', VALUE_OPTIONAL
),
);
if ($includecat) {
$params['categoryid'] = new external_value(PARAM_INT, 'The category ID. This may be' .
' \''. GLOSSARY_SHOW_NOT_CATEGORISED . '\' when the entry is not categorised', VALUE_DEFAULT,
GLOSSARY_SHOW_NOT_CATEGORISED);
$params['categoryname'] = new external_value(PARAM_RAW, 'The category name. May be empty when the entry is' .
' not categorised, or the request was limited to one category.', VALUE_DEFAULT, '');
}
return new external_single_structure($params);
} | [
"protected",
"static",
"function",
"get_entry_return_structure",
"(",
"$",
"includecat",
"=",
"false",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'id'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'The entry ID'",
")",
",",
"'glossaryid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'The glossary ID'",
")",
",",
"'userid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Author ID'",
")",
",",
"'userfullname'",
"=>",
"new",
"external_value",
"(",
"PARAM_NOTAGS",
",",
"'Author full name'",
")",
",",
"'userpictureurl'",
"=>",
"new",
"external_value",
"(",
"PARAM_URL",
",",
"'Author picture'",
")",
",",
"'concept'",
"=>",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'The concept'",
")",
",",
"'definition'",
"=>",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'The definition'",
")",
",",
"'definitionformat'",
"=>",
"new",
"external_format_value",
"(",
"'definition'",
")",
",",
"'definitiontrust'",
"=>",
"new",
"external_value",
"(",
"PARAM_BOOL",
",",
"'The definition trust flag'",
")",
",",
"'definitioninlinefiles'",
"=>",
"new",
"external_files",
"(",
"'entry definition inline files'",
",",
"VALUE_OPTIONAL",
")",
",",
"'attachment'",
"=>",
"new",
"external_value",
"(",
"PARAM_BOOL",
",",
"'Whether or not the entry has attachments'",
")",
",",
"'attachments'",
"=>",
"new",
"external_files",
"(",
"'attachments'",
",",
"VALUE_OPTIONAL",
")",
",",
"'timecreated'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Time created'",
")",
",",
"'timemodified'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'Time modified'",
")",
",",
"'teacherentry'",
"=>",
"new",
"external_value",
"(",
"PARAM_BOOL",
",",
"'The entry was created by a teacher, or equivalent.'",
")",
",",
"'sourceglossaryid'",
"=>",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'The source glossary ID'",
")",
",",
"'usedynalink'",
"=>",
"new",
"external_value",
"(",
"PARAM_BOOL",
",",
"'Whether the concept should be automatically linked'",
")",
",",
"'casesensitive'",
"=>",
"new",
"external_value",
"(",
"PARAM_BOOL",
",",
"'When true, the matching is case sensitive'",
")",
",",
"'fullmatch'",
"=>",
"new",
"external_value",
"(",
"PARAM_BOOL",
",",
"'When true, the matching is done on full words only'",
")",
",",
"'approved'",
"=>",
"new",
"external_value",
"(",
"PARAM_BOOL",
",",
"'Whether the entry was approved'",
")",
",",
"'tags'",
"=>",
"new",
"external_multiple_structure",
"(",
"\\",
"core_tag",
"\\",
"external",
"\\",
"tag_item_exporter",
"::",
"get_read_structure",
"(",
")",
",",
"'Tags'",
",",
"VALUE_OPTIONAL",
")",
",",
")",
";",
"if",
"(",
"$",
"includecat",
")",
"{",
"$",
"params",
"[",
"'categoryid'",
"]",
"=",
"new",
"external_value",
"(",
"PARAM_INT",
",",
"'The category ID. This may be'",
".",
"' \\''",
".",
"GLOSSARY_SHOW_NOT_CATEGORISED",
".",
"'\\' when the entry is not categorised'",
",",
"VALUE_DEFAULT",
",",
"GLOSSARY_SHOW_NOT_CATEGORISED",
")",
";",
"$",
"params",
"[",
"'categoryname'",
"]",
"=",
"new",
"external_value",
"(",
"PARAM_RAW",
",",
"'The category name. May be empty when the entry is'",
".",
"' not categorised, or the request was limited to one category.'",
",",
"VALUE_DEFAULT",
",",
"''",
")",
";",
"}",
"return",
"new",
"external_single_structure",
"(",
"$",
"params",
")",
";",
"}"
] | Get the return value of an entry.
@param bool $includecat Whether the definition should include category info.
@return external_definition | [
"Get",
"the",
"return",
"value",
"of",
"an",
"entry",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/external.php#L82-L118 |
213,981 | moodle/moodle | mod/glossary/classes/external.php | mod_glossary_external.fill_entry_details | protected static function fill_entry_details($entry, $context) {
global $PAGE;
$canviewfullnames = has_capability('moodle/site:viewfullnames', $context);
// Format concept and definition.
$entry->concept = external_format_string($entry->concept, $context->id);
list($entry->definition, $entry->definitionformat) = external_format_text($entry->definition, $entry->definitionformat,
$context->id, 'mod_glossary', 'entry', $entry->id);
// Author details.
$user = mod_glossary_entry_query_builder::get_user_from_record($entry);
$userpicture = new user_picture($user);
$userpicture->size = 1;
$entry->userfullname = fullname($user, $canviewfullnames);
$entry->userpictureurl = $userpicture->get_url($PAGE)->out(false);
// Fetch attachments.
$entry->attachment = !empty($entry->attachment) ? 1 : 0;
$entry->attachments = array();
if ($entry->attachment) {
$entry->attachments = external_util::get_area_files($context->id, 'mod_glossary', 'attachment', $entry->id);
}
$definitioninlinefiles = external_util::get_area_files($context->id, 'mod_glossary', 'entry', $entry->id);
if (!empty($definitioninlinefiles)) {
$entry->definitioninlinefiles = $definitioninlinefiles;
}
$entry->tags = \core_tag\external\util::get_item_tags('mod_glossary', 'glossary_entries', $entry->id);
} | php | protected static function fill_entry_details($entry, $context) {
global $PAGE;
$canviewfullnames = has_capability('moodle/site:viewfullnames', $context);
// Format concept and definition.
$entry->concept = external_format_string($entry->concept, $context->id);
list($entry->definition, $entry->definitionformat) = external_format_text($entry->definition, $entry->definitionformat,
$context->id, 'mod_glossary', 'entry', $entry->id);
// Author details.
$user = mod_glossary_entry_query_builder::get_user_from_record($entry);
$userpicture = new user_picture($user);
$userpicture->size = 1;
$entry->userfullname = fullname($user, $canviewfullnames);
$entry->userpictureurl = $userpicture->get_url($PAGE)->out(false);
// Fetch attachments.
$entry->attachment = !empty($entry->attachment) ? 1 : 0;
$entry->attachments = array();
if ($entry->attachment) {
$entry->attachments = external_util::get_area_files($context->id, 'mod_glossary', 'attachment', $entry->id);
}
$definitioninlinefiles = external_util::get_area_files($context->id, 'mod_glossary', 'entry', $entry->id);
if (!empty($definitioninlinefiles)) {
$entry->definitioninlinefiles = $definitioninlinefiles;
}
$entry->tags = \core_tag\external\util::get_item_tags('mod_glossary', 'glossary_entries', $entry->id);
} | [
"protected",
"static",
"function",
"fill_entry_details",
"(",
"$",
"entry",
",",
"$",
"context",
")",
"{",
"global",
"$",
"PAGE",
";",
"$",
"canviewfullnames",
"=",
"has_capability",
"(",
"'moodle/site:viewfullnames'",
",",
"$",
"context",
")",
";",
"// Format concept and definition.",
"$",
"entry",
"->",
"concept",
"=",
"external_format_string",
"(",
"$",
"entry",
"->",
"concept",
",",
"$",
"context",
"->",
"id",
")",
";",
"list",
"(",
"$",
"entry",
"->",
"definition",
",",
"$",
"entry",
"->",
"definitionformat",
")",
"=",
"external_format_text",
"(",
"$",
"entry",
"->",
"definition",
",",
"$",
"entry",
"->",
"definitionformat",
",",
"$",
"context",
"->",
"id",
",",
"'mod_glossary'",
",",
"'entry'",
",",
"$",
"entry",
"->",
"id",
")",
";",
"// Author details.",
"$",
"user",
"=",
"mod_glossary_entry_query_builder",
"::",
"get_user_from_record",
"(",
"$",
"entry",
")",
";",
"$",
"userpicture",
"=",
"new",
"user_picture",
"(",
"$",
"user",
")",
";",
"$",
"userpicture",
"->",
"size",
"=",
"1",
";",
"$",
"entry",
"->",
"userfullname",
"=",
"fullname",
"(",
"$",
"user",
",",
"$",
"canviewfullnames",
")",
";",
"$",
"entry",
"->",
"userpictureurl",
"=",
"$",
"userpicture",
"->",
"get_url",
"(",
"$",
"PAGE",
")",
"->",
"out",
"(",
"false",
")",
";",
"// Fetch attachments.",
"$",
"entry",
"->",
"attachment",
"=",
"!",
"empty",
"(",
"$",
"entry",
"->",
"attachment",
")",
"?",
"1",
":",
"0",
";",
"$",
"entry",
"->",
"attachments",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"entry",
"->",
"attachment",
")",
"{",
"$",
"entry",
"->",
"attachments",
"=",
"external_util",
"::",
"get_area_files",
"(",
"$",
"context",
"->",
"id",
",",
"'mod_glossary'",
",",
"'attachment'",
",",
"$",
"entry",
"->",
"id",
")",
";",
"}",
"$",
"definitioninlinefiles",
"=",
"external_util",
"::",
"get_area_files",
"(",
"$",
"context",
"->",
"id",
",",
"'mod_glossary'",
",",
"'entry'",
",",
"$",
"entry",
"->",
"id",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"definitioninlinefiles",
")",
")",
"{",
"$",
"entry",
"->",
"definitioninlinefiles",
"=",
"$",
"definitioninlinefiles",
";",
"}",
"$",
"entry",
"->",
"tags",
"=",
"\\",
"core_tag",
"\\",
"external",
"\\",
"util",
"::",
"get_item_tags",
"(",
"'mod_glossary'",
",",
"'glossary_entries'",
",",
"$",
"entry",
"->",
"id",
")",
";",
"}"
] | Fill in an entry object.
This adds additional required fields for the external function to return.
@param stdClass $entry The entry.
@param context $context The context the entry belongs to.
@return void | [
"Fill",
"in",
"an",
"entry",
"object",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/external.php#L129-L157 |
213,982 | moodle/moodle | mod/glossary/classes/external.php | mod_glossary_external.validate_glossary | protected static function validate_glossary($id) {
global $DB;
$glossary = $DB->get_record('glossary', array('id' => $id), '*', MUST_EXIST);
list($course, $cm) = get_course_and_cm_from_instance($glossary, 'glossary');
$context = context_module::instance($cm->id);
self::validate_context($context);
return array($glossary, $context, $course, $cm);
} | php | protected static function validate_glossary($id) {
global $DB;
$glossary = $DB->get_record('glossary', array('id' => $id), '*', MUST_EXIST);
list($course, $cm) = get_course_and_cm_from_instance($glossary, 'glossary');
$context = context_module::instance($cm->id);
self::validate_context($context);
return array($glossary, $context, $course, $cm);
} | [
"protected",
"static",
"function",
"validate_glossary",
"(",
"$",
"id",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"glossary",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'glossary'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"id",
")",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"list",
"(",
"$",
"course",
",",
"$",
"cm",
")",
"=",
"get_course_and_cm_from_instance",
"(",
"$",
"glossary",
",",
"'glossary'",
")",
";",
"$",
"context",
"=",
"context_module",
"::",
"instance",
"(",
"$",
"cm",
"->",
"id",
")",
";",
"self",
"::",
"validate_context",
"(",
"$",
"context",
")",
";",
"return",
"array",
"(",
"$",
"glossary",
",",
"$",
"context",
",",
"$",
"course",
",",
"$",
"cm",
")",
";",
"}"
] | Validate a glossary via ID.
@param int $id The glossary ID.
@return array Contains glossary, context, course and cm. | [
"Validate",
"a",
"glossary",
"via",
"ID",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/external.php#L165-L172 |
213,983 | moodle/moodle | mod/glossary/classes/external.php | mod_glossary_external.get_glossaries_by_courses | public static function get_glossaries_by_courses($courseids = array()) {
$params = self::validate_parameters(self::get_glossaries_by_courses_parameters(), array('courseids' => $courseids));
$warnings = array();
$courses = array();
$courseids = $params['courseids'];
if (empty($courseids)) {
$courses = enrol_get_my_courses();
$courseids = array_keys($courses);
}
// Array to store the glossaries to return.
$glossaries = array();
$modes = array();
// Ensure there are courseids to loop through.
if (!empty($courseids)) {
list($courses, $warnings) = external_util::validate_courses($courseids, $courses);
// Get the glossaries in these courses, this function checks users visibility permissions.
$glossaries = get_all_instances_in_courses('glossary', $courses);
foreach ($glossaries as $glossary) {
$context = context_module::instance($glossary->coursemodule);
$glossary->name = external_format_string($glossary->name, $context->id);
list($glossary->intro, $glossary->introformat) = external_format_text($glossary->intro, $glossary->introformat,
$context->id, 'mod_glossary', 'intro', null);
$glossary->introfiles = external_util::get_area_files($context->id, 'mod_glossary', 'intro', false, false);
// Make sure we have a number of entries per page.
if (!$glossary->entbypage) {
$glossary->entbypage = $CFG->glossary_entbypage;
}
// Add the list of browsing modes.
if (!isset($modes[$glossary->displayformat])) {
$modes[$glossary->displayformat] = self::get_browse_modes_from_display_format($glossary->displayformat);
}
$glossary->browsemodes = $modes[$glossary->displayformat];
$glossary->canaddentry = has_capability('mod/glossary:write', $context) ? 1 : 0;
}
}
$result = array();
$result['glossaries'] = $glossaries;
$result['warnings'] = $warnings;
return $result;
} | php | public static function get_glossaries_by_courses($courseids = array()) {
$params = self::validate_parameters(self::get_glossaries_by_courses_parameters(), array('courseids' => $courseids));
$warnings = array();
$courses = array();
$courseids = $params['courseids'];
if (empty($courseids)) {
$courses = enrol_get_my_courses();
$courseids = array_keys($courses);
}
// Array to store the glossaries to return.
$glossaries = array();
$modes = array();
// Ensure there are courseids to loop through.
if (!empty($courseids)) {
list($courses, $warnings) = external_util::validate_courses($courseids, $courses);
// Get the glossaries in these courses, this function checks users visibility permissions.
$glossaries = get_all_instances_in_courses('glossary', $courses);
foreach ($glossaries as $glossary) {
$context = context_module::instance($glossary->coursemodule);
$glossary->name = external_format_string($glossary->name, $context->id);
list($glossary->intro, $glossary->introformat) = external_format_text($glossary->intro, $glossary->introformat,
$context->id, 'mod_glossary', 'intro', null);
$glossary->introfiles = external_util::get_area_files($context->id, 'mod_glossary', 'intro', false, false);
// Make sure we have a number of entries per page.
if (!$glossary->entbypage) {
$glossary->entbypage = $CFG->glossary_entbypage;
}
// Add the list of browsing modes.
if (!isset($modes[$glossary->displayformat])) {
$modes[$glossary->displayformat] = self::get_browse_modes_from_display_format($glossary->displayformat);
}
$glossary->browsemodes = $modes[$glossary->displayformat];
$glossary->canaddentry = has_capability('mod/glossary:write', $context) ? 1 : 0;
}
}
$result = array();
$result['glossaries'] = $glossaries;
$result['warnings'] = $warnings;
return $result;
} | [
"public",
"static",
"function",
"get_glossaries_by_courses",
"(",
"$",
"courseids",
"=",
"array",
"(",
")",
")",
"{",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_glossaries_by_courses_parameters",
"(",
")",
",",
"array",
"(",
"'courseids'",
"=>",
"$",
"courseids",
")",
")",
";",
"$",
"warnings",
"=",
"array",
"(",
")",
";",
"$",
"courses",
"=",
"array",
"(",
")",
";",
"$",
"courseids",
"=",
"$",
"params",
"[",
"'courseids'",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"courseids",
")",
")",
"{",
"$",
"courses",
"=",
"enrol_get_my_courses",
"(",
")",
";",
"$",
"courseids",
"=",
"array_keys",
"(",
"$",
"courses",
")",
";",
"}",
"// Array to store the glossaries to return.",
"$",
"glossaries",
"=",
"array",
"(",
")",
";",
"$",
"modes",
"=",
"array",
"(",
")",
";",
"// Ensure there are courseids to loop through.",
"if",
"(",
"!",
"empty",
"(",
"$",
"courseids",
")",
")",
"{",
"list",
"(",
"$",
"courses",
",",
"$",
"warnings",
")",
"=",
"external_util",
"::",
"validate_courses",
"(",
"$",
"courseids",
",",
"$",
"courses",
")",
";",
"// Get the glossaries in these courses, this function checks users visibility permissions.",
"$",
"glossaries",
"=",
"get_all_instances_in_courses",
"(",
"'glossary'",
",",
"$",
"courses",
")",
";",
"foreach",
"(",
"$",
"glossaries",
"as",
"$",
"glossary",
")",
"{",
"$",
"context",
"=",
"context_module",
"::",
"instance",
"(",
"$",
"glossary",
"->",
"coursemodule",
")",
";",
"$",
"glossary",
"->",
"name",
"=",
"external_format_string",
"(",
"$",
"glossary",
"->",
"name",
",",
"$",
"context",
"->",
"id",
")",
";",
"list",
"(",
"$",
"glossary",
"->",
"intro",
",",
"$",
"glossary",
"->",
"introformat",
")",
"=",
"external_format_text",
"(",
"$",
"glossary",
"->",
"intro",
",",
"$",
"glossary",
"->",
"introformat",
",",
"$",
"context",
"->",
"id",
",",
"'mod_glossary'",
",",
"'intro'",
",",
"null",
")",
";",
"$",
"glossary",
"->",
"introfiles",
"=",
"external_util",
"::",
"get_area_files",
"(",
"$",
"context",
"->",
"id",
",",
"'mod_glossary'",
",",
"'intro'",
",",
"false",
",",
"false",
")",
";",
"// Make sure we have a number of entries per page.",
"if",
"(",
"!",
"$",
"glossary",
"->",
"entbypage",
")",
"{",
"$",
"glossary",
"->",
"entbypage",
"=",
"$",
"CFG",
"->",
"glossary_entbypage",
";",
"}",
"// Add the list of browsing modes.",
"if",
"(",
"!",
"isset",
"(",
"$",
"modes",
"[",
"$",
"glossary",
"->",
"displayformat",
"]",
")",
")",
"{",
"$",
"modes",
"[",
"$",
"glossary",
"->",
"displayformat",
"]",
"=",
"self",
"::",
"get_browse_modes_from_display_format",
"(",
"$",
"glossary",
"->",
"displayformat",
")",
";",
"}",
"$",
"glossary",
"->",
"browsemodes",
"=",
"$",
"modes",
"[",
"$",
"glossary",
"->",
"displayformat",
"]",
";",
"$",
"glossary",
"->",
"canaddentry",
"=",
"has_capability",
"(",
"'mod/glossary:write'",
",",
"$",
"context",
")",
"?",
"1",
":",
"0",
";",
"}",
"}",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"result",
"[",
"'glossaries'",
"]",
"=",
"$",
"glossaries",
";",
"$",
"result",
"[",
"'warnings'",
"]",
"=",
"$",
"warnings",
";",
"return",
"$",
"result",
";",
"}"
] | Returns a list of glossaries in a provided list of courses.
If no list is provided all glossaries that the user can view will be returned.
@param array $courseids the course IDs.
@return array of glossaries
@since Moodle 3.1 | [
"Returns",
"a",
"list",
"of",
"glossaries",
"in",
"a",
"provided",
"list",
"of",
"courses",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/external.php#L200-L247 |
213,984 | moodle/moodle | mod/glossary/classes/external.php | mod_glossary_external.view_glossary | public static function view_glossary($id, $mode) {
$params = self::validate_parameters(self::view_glossary_parameters(), array(
'id' => $id,
'mode' => $mode
));
$id = $params['id'];
$mode = $params['mode'];
$warnings = array();
// Get and validate the glossary.
list($glossary, $context, $course, $cm) = self::validate_glossary($id);
// Trigger module viewed event.
glossary_view($glossary, $course, $cm, $context, $mode);
return array(
'status' => true,
'warnings' => $warnings
);
} | php | public static function view_glossary($id, $mode) {
$params = self::validate_parameters(self::view_glossary_parameters(), array(
'id' => $id,
'mode' => $mode
));
$id = $params['id'];
$mode = $params['mode'];
$warnings = array();
// Get and validate the glossary.
list($glossary, $context, $course, $cm) = self::validate_glossary($id);
// Trigger module viewed event.
glossary_view($glossary, $course, $cm, $context, $mode);
return array(
'status' => true,
'warnings' => $warnings
);
} | [
"public",
"static",
"function",
"view_glossary",
"(",
"$",
"id",
",",
"$",
"mode",
")",
"{",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"view_glossary_parameters",
"(",
")",
",",
"array",
"(",
"'id'",
"=>",
"$",
"id",
",",
"'mode'",
"=>",
"$",
"mode",
")",
")",
";",
"$",
"id",
"=",
"$",
"params",
"[",
"'id'",
"]",
";",
"$",
"mode",
"=",
"$",
"params",
"[",
"'mode'",
"]",
";",
"$",
"warnings",
"=",
"array",
"(",
")",
";",
"// Get and validate the glossary.",
"list",
"(",
"$",
"glossary",
",",
"$",
"context",
",",
"$",
"course",
",",
"$",
"cm",
")",
"=",
"self",
"::",
"validate_glossary",
"(",
"$",
"id",
")",
";",
"// Trigger module viewed event.",
"glossary_view",
"(",
"$",
"glossary",
",",
"$",
"course",
",",
"$",
"cm",
",",
"$",
"context",
",",
"$",
"mode",
")",
";",
"return",
"array",
"(",
"'status'",
"=>",
"true",
",",
"'warnings'",
"=>",
"$",
"warnings",
")",
";",
"}"
] | Notify that the course module was viewed.
@param int $id The glossary instance ID.
@param string $mode The view mode.
@return array of warnings and status result
@since Moodle 3.1
@throws moodle_exception | [
"Notify",
"that",
"the",
"course",
"module",
"was",
"viewed",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/external.php#L336-L355 |
213,985 | moodle/moodle | mod/glossary/classes/external.php | mod_glossary_external.view_entry | public static function view_entry($id) {
global $DB, $USER;
$params = self::validate_parameters(self::view_entry_parameters(), array('id' => $id));
$id = $params['id'];
$warnings = array();
// Get and validate the glossary.
$entry = $DB->get_record('glossary_entries', array('id' => $id), '*', MUST_EXIST);
list($glossary, $context, $course, $cm) = self::validate_glossary($entry->glossaryid);
if (!glossary_can_view_entry($entry, $cm)) {
throw new invalid_parameter_exception('invalidentry');
}
// Trigger view.
glossary_entry_view($entry, $context);
return array(
'status' => true,
'warnings' => $warnings
);
} | php | public static function view_entry($id) {
global $DB, $USER;
$params = self::validate_parameters(self::view_entry_parameters(), array('id' => $id));
$id = $params['id'];
$warnings = array();
// Get and validate the glossary.
$entry = $DB->get_record('glossary_entries', array('id' => $id), '*', MUST_EXIST);
list($glossary, $context, $course, $cm) = self::validate_glossary($entry->glossaryid);
if (!glossary_can_view_entry($entry, $cm)) {
throw new invalid_parameter_exception('invalidentry');
}
// Trigger view.
glossary_entry_view($entry, $context);
return array(
'status' => true,
'warnings' => $warnings
);
} | [
"public",
"static",
"function",
"view_entry",
"(",
"$",
"id",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"USER",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"view_entry_parameters",
"(",
")",
",",
"array",
"(",
"'id'",
"=>",
"$",
"id",
")",
")",
";",
"$",
"id",
"=",
"$",
"params",
"[",
"'id'",
"]",
";",
"$",
"warnings",
"=",
"array",
"(",
")",
";",
"// Get and validate the glossary.",
"$",
"entry",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'glossary_entries'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"id",
")",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"list",
"(",
"$",
"glossary",
",",
"$",
"context",
",",
"$",
"course",
",",
"$",
"cm",
")",
"=",
"self",
"::",
"validate_glossary",
"(",
"$",
"entry",
"->",
"glossaryid",
")",
";",
"if",
"(",
"!",
"glossary_can_view_entry",
"(",
"$",
"entry",
",",
"$",
"cm",
")",
")",
"{",
"throw",
"new",
"invalid_parameter_exception",
"(",
"'invalidentry'",
")",
";",
"}",
"// Trigger view.",
"glossary_entry_view",
"(",
"$",
"entry",
",",
"$",
"context",
")",
";",
"return",
"array",
"(",
"'status'",
"=>",
"true",
",",
"'warnings'",
"=>",
"$",
"warnings",
")",
";",
"}"
] | Notify that the entry was viewed.
@param int $id The entry ID.
@return array of warnings and status result
@since Moodle 3.1
@throws moodle_exception
@throws invalid_parameter_exception | [
"Notify",
"that",
"the",
"entry",
"was",
"viewed",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/external.php#L391-L413 |
213,986 | moodle/moodle | mod/glossary/classes/external.php | mod_glossary_external.get_entries_by_letter | public static function get_entries_by_letter($id, $letter, $from, $limit, $options) {
$params = self::validate_parameters(self::get_entries_by_letter_parameters(), array(
'id' => $id,
'letter' => $letter,
'from' => $from,
'limit' => $limit,
'options' => $options,
));
$id = $params['id'];
$letter = $params['letter'];
$from = $params['from'];
$limit = $params['limit'];
$options = $params['options'];
$warnings = array();
// Get and validate the glossary.
list($glossary, $context) = self::validate_glossary($id);
// Validate the mode.
$modes = self::get_browse_modes_from_display_format($glossary->displayformat);
if (!in_array('letter', $modes)) {
throw new invalid_parameter_exception('invalidbrowsemode');
}
$entries = array();
list($records, $count) = glossary_get_entries_by_letter($glossary, $context, $letter, $from, $limit, $options);
foreach ($records as $key => $record) {
self::fill_entry_details($record, $context);
$entries[] = $record;
}
return array(
'count' => $count,
'entries' => $entries,
'ratinginfo' => \core_rating\external\util::get_rating_info($glossary, $context, 'mod_glossary', 'entry', $entries),
'warnings' => $warnings
);
} | php | public static function get_entries_by_letter($id, $letter, $from, $limit, $options) {
$params = self::validate_parameters(self::get_entries_by_letter_parameters(), array(
'id' => $id,
'letter' => $letter,
'from' => $from,
'limit' => $limit,
'options' => $options,
));
$id = $params['id'];
$letter = $params['letter'];
$from = $params['from'];
$limit = $params['limit'];
$options = $params['options'];
$warnings = array();
// Get and validate the glossary.
list($glossary, $context) = self::validate_glossary($id);
// Validate the mode.
$modes = self::get_browse_modes_from_display_format($glossary->displayformat);
if (!in_array('letter', $modes)) {
throw new invalid_parameter_exception('invalidbrowsemode');
}
$entries = array();
list($records, $count) = glossary_get_entries_by_letter($glossary, $context, $letter, $from, $limit, $options);
foreach ($records as $key => $record) {
self::fill_entry_details($record, $context);
$entries[] = $record;
}
return array(
'count' => $count,
'entries' => $entries,
'ratinginfo' => \core_rating\external\util::get_rating_info($glossary, $context, 'mod_glossary', 'entry', $entries),
'warnings' => $warnings
);
} | [
"public",
"static",
"function",
"get_entries_by_letter",
"(",
"$",
"id",
",",
"$",
"letter",
",",
"$",
"from",
",",
"$",
"limit",
",",
"$",
"options",
")",
"{",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_entries_by_letter_parameters",
"(",
")",
",",
"array",
"(",
"'id'",
"=>",
"$",
"id",
",",
"'letter'",
"=>",
"$",
"letter",
",",
"'from'",
"=>",
"$",
"from",
",",
"'limit'",
"=>",
"$",
"limit",
",",
"'options'",
"=>",
"$",
"options",
",",
")",
")",
";",
"$",
"id",
"=",
"$",
"params",
"[",
"'id'",
"]",
";",
"$",
"letter",
"=",
"$",
"params",
"[",
"'letter'",
"]",
";",
"$",
"from",
"=",
"$",
"params",
"[",
"'from'",
"]",
";",
"$",
"limit",
"=",
"$",
"params",
"[",
"'limit'",
"]",
";",
"$",
"options",
"=",
"$",
"params",
"[",
"'options'",
"]",
";",
"$",
"warnings",
"=",
"array",
"(",
")",
";",
"// Get and validate the glossary.",
"list",
"(",
"$",
"glossary",
",",
"$",
"context",
")",
"=",
"self",
"::",
"validate_glossary",
"(",
"$",
"id",
")",
";",
"// Validate the mode.",
"$",
"modes",
"=",
"self",
"::",
"get_browse_modes_from_display_format",
"(",
"$",
"glossary",
"->",
"displayformat",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"'letter'",
",",
"$",
"modes",
")",
")",
"{",
"throw",
"new",
"invalid_parameter_exception",
"(",
"'invalidbrowsemode'",
")",
";",
"}",
"$",
"entries",
"=",
"array",
"(",
")",
";",
"list",
"(",
"$",
"records",
",",
"$",
"count",
")",
"=",
"glossary_get_entries_by_letter",
"(",
"$",
"glossary",
",",
"$",
"context",
",",
"$",
"letter",
",",
"$",
"from",
",",
"$",
"limit",
",",
"$",
"options",
")",
";",
"foreach",
"(",
"$",
"records",
"as",
"$",
"key",
"=>",
"$",
"record",
")",
"{",
"self",
"::",
"fill_entry_details",
"(",
"$",
"record",
",",
"$",
"context",
")",
";",
"$",
"entries",
"[",
"]",
"=",
"$",
"record",
";",
"}",
"return",
"array",
"(",
"'count'",
"=>",
"$",
"count",
",",
"'entries'",
"=>",
"$",
"entries",
",",
"'ratinginfo'",
"=>",
"\\",
"core_rating",
"\\",
"external",
"\\",
"util",
"::",
"get_rating_info",
"(",
"$",
"glossary",
",",
"$",
"context",
",",
"'mod_glossary'",
",",
"'entry'",
",",
"$",
"entries",
")",
",",
"'warnings'",
"=>",
"$",
"warnings",
")",
";",
"}"
] | Browse a glossary entries by letter.
@param int $id The glossary ID.
@param string $letter A letter, or a special keyword.
@param int $from Start returning records from here.
@param int $limit Number of records to return.
@param array $options Array of options.
@return array Containing count, entries and warnings.
@since Moodle 3.1
@throws moodle_exception
@throws invalid_parameter_exception | [
"Browse",
"a",
"glossary",
"entries",
"by",
"letter",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/external.php#L460-L497 |
213,987 | moodle/moodle | mod/glossary/classes/external.php | mod_glossary_external.get_categories | public static function get_categories($id, $from, $limit) {
$params = self::validate_parameters(self::get_categories_parameters(), array(
'id' => $id,
'from' => $from,
'limit' => $limit
));
$id = $params['id'];
$from = $params['from'];
$limit = $params['limit'];
$warnings = array();
// Get and validate the glossary.
list($glossary, $context) = self::validate_glossary($id);
// Fetch the categories.
$categories = array();
list($records, $count) = glossary_get_categories($glossary, $from, $limit);
foreach ($records as $category) {
$category->name = external_format_string($category->name, $context->id);
$categories[] = $category;
}
return array(
'count' => $count,
'categories' => $categories,
'warnings' => array(),
);
} | php | public static function get_categories($id, $from, $limit) {
$params = self::validate_parameters(self::get_categories_parameters(), array(
'id' => $id,
'from' => $from,
'limit' => $limit
));
$id = $params['id'];
$from = $params['from'];
$limit = $params['limit'];
$warnings = array();
// Get and validate the glossary.
list($glossary, $context) = self::validate_glossary($id);
// Fetch the categories.
$categories = array();
list($records, $count) = glossary_get_categories($glossary, $from, $limit);
foreach ($records as $category) {
$category->name = external_format_string($category->name, $context->id);
$categories[] = $category;
}
return array(
'count' => $count,
'categories' => $categories,
'warnings' => array(),
);
} | [
"public",
"static",
"function",
"get_categories",
"(",
"$",
"id",
",",
"$",
"from",
",",
"$",
"limit",
")",
"{",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_categories_parameters",
"(",
")",
",",
"array",
"(",
"'id'",
"=>",
"$",
"id",
",",
"'from'",
"=>",
"$",
"from",
",",
"'limit'",
"=>",
"$",
"limit",
")",
")",
";",
"$",
"id",
"=",
"$",
"params",
"[",
"'id'",
"]",
";",
"$",
"from",
"=",
"$",
"params",
"[",
"'from'",
"]",
";",
"$",
"limit",
"=",
"$",
"params",
"[",
"'limit'",
"]",
";",
"$",
"warnings",
"=",
"array",
"(",
")",
";",
"// Get and validate the glossary.",
"list",
"(",
"$",
"glossary",
",",
"$",
"context",
")",
"=",
"self",
"::",
"validate_glossary",
"(",
"$",
"id",
")",
";",
"// Fetch the categories.",
"$",
"categories",
"=",
"array",
"(",
")",
";",
"list",
"(",
"$",
"records",
",",
"$",
"count",
")",
"=",
"glossary_get_categories",
"(",
"$",
"glossary",
",",
"$",
"from",
",",
"$",
"limit",
")",
";",
"foreach",
"(",
"$",
"records",
"as",
"$",
"category",
")",
"{",
"$",
"category",
"->",
"name",
"=",
"external_format_string",
"(",
"$",
"category",
"->",
"name",
",",
"$",
"context",
"->",
"id",
")",
";",
"$",
"categories",
"[",
"]",
"=",
"$",
"category",
";",
"}",
"return",
"array",
"(",
"'count'",
"=>",
"$",
"count",
",",
"'categories'",
"=>",
"$",
"categories",
",",
"'warnings'",
"=>",
"array",
"(",
")",
",",
")",
";",
"}"
] | Get the categories of a glossary.
@param int $id The glossary ID.
@param int $from Start returning records from here.
@param int $limit Number of records to return.
@return array Containing count, categories and warnings.
@since Moodle 3.1
@throws moodle_exception | [
"Get",
"the",
"categories",
"of",
"a",
"glossary",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/external.php#L639-L666 |
213,988 | moodle/moodle | mod/glossary/classes/external.php | mod_glossary_external.get_entries_by_category | public static function get_entries_by_category($id, $categoryid, $from, $limit, $options) {
global $DB;
$params = self::validate_parameters(self::get_entries_by_category_parameters(), array(
'id' => $id,
'categoryid' => $categoryid,
'from' => $from,
'limit' => $limit,
'options' => $options,
));
$id = $params['id'];
$categoryid = $params['categoryid'];
$from = $params['from'];
$limit = $params['limit'];
$options = $params['options'];
$warnings = array();
// Get and validate the glossary.
list($glossary, $context) = self::validate_glossary($id);
// Validate the mode.
$modes = self::get_browse_modes_from_display_format($glossary->displayformat);
if (!in_array('cat', $modes)) {
throw new invalid_parameter_exception('invalidbrowsemode');
}
// Validate the category.
if (in_array($categoryid, array(GLOSSARY_SHOW_ALL_CATEGORIES, GLOSSARY_SHOW_NOT_CATEGORISED))) {
// All good.
} else if (!$DB->record_exists('glossary_categories', array('id' => $categoryid, 'glossaryid' => $id))) {
throw new invalid_parameter_exception('invalidcategory');
}
// Fetching the entries.
$entries = array();
list($records, $count) = glossary_get_entries_by_category($glossary, $context, $categoryid, $from, $limit, $options);
foreach ($records as $key => $record) {
self::fill_entry_details($record, $context);
if ($record->categoryid === null) {
$record->categoryid = GLOSSARY_SHOW_NOT_CATEGORISED;
}
if (isset($record->categoryname)) {
$record->categoryname = external_format_string($record->categoryname, $context->id);
}
$entries[] = $record;
}
return array(
'count' => $count,
'entries' => $entries,
'ratinginfo' => \core_rating\external\util::get_rating_info($glossary, $context, 'mod_glossary', 'entry', $entries),
'warnings' => $warnings
);
} | php | public static function get_entries_by_category($id, $categoryid, $from, $limit, $options) {
global $DB;
$params = self::validate_parameters(self::get_entries_by_category_parameters(), array(
'id' => $id,
'categoryid' => $categoryid,
'from' => $from,
'limit' => $limit,
'options' => $options,
));
$id = $params['id'];
$categoryid = $params['categoryid'];
$from = $params['from'];
$limit = $params['limit'];
$options = $params['options'];
$warnings = array();
// Get and validate the glossary.
list($glossary, $context) = self::validate_glossary($id);
// Validate the mode.
$modes = self::get_browse_modes_from_display_format($glossary->displayformat);
if (!in_array('cat', $modes)) {
throw new invalid_parameter_exception('invalidbrowsemode');
}
// Validate the category.
if (in_array($categoryid, array(GLOSSARY_SHOW_ALL_CATEGORIES, GLOSSARY_SHOW_NOT_CATEGORISED))) {
// All good.
} else if (!$DB->record_exists('glossary_categories', array('id' => $categoryid, 'glossaryid' => $id))) {
throw new invalid_parameter_exception('invalidcategory');
}
// Fetching the entries.
$entries = array();
list($records, $count) = glossary_get_entries_by_category($glossary, $context, $categoryid, $from, $limit, $options);
foreach ($records as $key => $record) {
self::fill_entry_details($record, $context);
if ($record->categoryid === null) {
$record->categoryid = GLOSSARY_SHOW_NOT_CATEGORISED;
}
if (isset($record->categoryname)) {
$record->categoryname = external_format_string($record->categoryname, $context->id);
}
$entries[] = $record;
}
return array(
'count' => $count,
'entries' => $entries,
'ratinginfo' => \core_rating\external\util::get_rating_info($glossary, $context, 'mod_glossary', 'entry', $entries),
'warnings' => $warnings
);
} | [
"public",
"static",
"function",
"get_entries_by_category",
"(",
"$",
"id",
",",
"$",
"categoryid",
",",
"$",
"from",
",",
"$",
"limit",
",",
"$",
"options",
")",
"{",
"global",
"$",
"DB",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_entries_by_category_parameters",
"(",
")",
",",
"array",
"(",
"'id'",
"=>",
"$",
"id",
",",
"'categoryid'",
"=>",
"$",
"categoryid",
",",
"'from'",
"=>",
"$",
"from",
",",
"'limit'",
"=>",
"$",
"limit",
",",
"'options'",
"=>",
"$",
"options",
",",
")",
")",
";",
"$",
"id",
"=",
"$",
"params",
"[",
"'id'",
"]",
";",
"$",
"categoryid",
"=",
"$",
"params",
"[",
"'categoryid'",
"]",
";",
"$",
"from",
"=",
"$",
"params",
"[",
"'from'",
"]",
";",
"$",
"limit",
"=",
"$",
"params",
"[",
"'limit'",
"]",
";",
"$",
"options",
"=",
"$",
"params",
"[",
"'options'",
"]",
";",
"$",
"warnings",
"=",
"array",
"(",
")",
";",
"// Get and validate the glossary.",
"list",
"(",
"$",
"glossary",
",",
"$",
"context",
")",
"=",
"self",
"::",
"validate_glossary",
"(",
"$",
"id",
")",
";",
"// Validate the mode.",
"$",
"modes",
"=",
"self",
"::",
"get_browse_modes_from_display_format",
"(",
"$",
"glossary",
"->",
"displayformat",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"'cat'",
",",
"$",
"modes",
")",
")",
"{",
"throw",
"new",
"invalid_parameter_exception",
"(",
"'invalidbrowsemode'",
")",
";",
"}",
"// Validate the category.",
"if",
"(",
"in_array",
"(",
"$",
"categoryid",
",",
"array",
"(",
"GLOSSARY_SHOW_ALL_CATEGORIES",
",",
"GLOSSARY_SHOW_NOT_CATEGORISED",
")",
")",
")",
"{",
"// All good.",
"}",
"else",
"if",
"(",
"!",
"$",
"DB",
"->",
"record_exists",
"(",
"'glossary_categories'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"categoryid",
",",
"'glossaryid'",
"=>",
"$",
"id",
")",
")",
")",
"{",
"throw",
"new",
"invalid_parameter_exception",
"(",
"'invalidcategory'",
")",
";",
"}",
"// Fetching the entries.",
"$",
"entries",
"=",
"array",
"(",
")",
";",
"list",
"(",
"$",
"records",
",",
"$",
"count",
")",
"=",
"glossary_get_entries_by_category",
"(",
"$",
"glossary",
",",
"$",
"context",
",",
"$",
"categoryid",
",",
"$",
"from",
",",
"$",
"limit",
",",
"$",
"options",
")",
";",
"foreach",
"(",
"$",
"records",
"as",
"$",
"key",
"=>",
"$",
"record",
")",
"{",
"self",
"::",
"fill_entry_details",
"(",
"$",
"record",
",",
"$",
"context",
")",
";",
"if",
"(",
"$",
"record",
"->",
"categoryid",
"===",
"null",
")",
"{",
"$",
"record",
"->",
"categoryid",
"=",
"GLOSSARY_SHOW_NOT_CATEGORISED",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"record",
"->",
"categoryname",
")",
")",
"{",
"$",
"record",
"->",
"categoryname",
"=",
"external_format_string",
"(",
"$",
"record",
"->",
"categoryname",
",",
"$",
"context",
"->",
"id",
")",
";",
"}",
"$",
"entries",
"[",
"]",
"=",
"$",
"record",
";",
"}",
"return",
"array",
"(",
"'count'",
"=>",
"$",
"count",
",",
"'entries'",
"=>",
"$",
"entries",
",",
"'ratinginfo'",
"=>",
"\\",
"core_rating",
"\\",
"external",
"\\",
"util",
"::",
"get_rating_info",
"(",
"$",
"glossary",
",",
"$",
"context",
",",
"'mod_glossary'",
",",
"'entry'",
",",
"$",
"entries",
")",
",",
"'warnings'",
"=>",
"$",
"warnings",
")",
";",
"}"
] | Browse a glossary entries by category.
@param int $id The glossary ID.
@param int $categoryid The category ID.
@param int $from Start returning records from here.
@param int $limit Number of records to return.
@param array $options Array of options.
@return array Containing count, entries and warnings.
@since Moodle 3.1
@throws moodle_exception
@throws invalid_parameter_exception | [
"Browse",
"a",
"glossary",
"entries",
"by",
"category",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/external.php#L722-L775 |
213,989 | moodle/moodle | mod/glossary/classes/external.php | mod_glossary_external.get_authors | public static function get_authors($id, $from, $limit, $options) {
global $PAGE;
$params = self::validate_parameters(self::get_authors_parameters(), array(
'id' => $id,
'from' => $from,
'limit' => $limit,
'options' => $options,
));
$id = $params['id'];
$from = $params['from'];
$limit = $params['limit'];
$options = $params['options'];
$warnings = array();
// Get and validate the glossary.
list($glossary, $context) = self::validate_glossary($id);
// Fetching the entries.
list($users, $count) = glossary_get_authors($glossary, $context, $limit, $from, $options);
$canviewfullnames = has_capability('moodle/site:viewfullnames', $context);
foreach ($users as $user) {
$userpicture = new user_picture($user);
$userpicture->size = 1;
$author = new stdClass();
$author->id = $user->id;
$author->fullname = fullname($user, $canviewfullnames);
$author->pictureurl = $userpicture->get_url($PAGE)->out(false);
$authors[] = $author;
}
$users->close();
return array(
'count' => $count,
'authors' => $authors,
'warnings' => array(),
);
} | php | public static function get_authors($id, $from, $limit, $options) {
global $PAGE;
$params = self::validate_parameters(self::get_authors_parameters(), array(
'id' => $id,
'from' => $from,
'limit' => $limit,
'options' => $options,
));
$id = $params['id'];
$from = $params['from'];
$limit = $params['limit'];
$options = $params['options'];
$warnings = array();
// Get and validate the glossary.
list($glossary, $context) = self::validate_glossary($id);
// Fetching the entries.
list($users, $count) = glossary_get_authors($glossary, $context, $limit, $from, $options);
$canviewfullnames = has_capability('moodle/site:viewfullnames', $context);
foreach ($users as $user) {
$userpicture = new user_picture($user);
$userpicture->size = 1;
$author = new stdClass();
$author->id = $user->id;
$author->fullname = fullname($user, $canviewfullnames);
$author->pictureurl = $userpicture->get_url($PAGE)->out(false);
$authors[] = $author;
}
$users->close();
return array(
'count' => $count,
'authors' => $authors,
'warnings' => array(),
);
} | [
"public",
"static",
"function",
"get_authors",
"(",
"$",
"id",
",",
"$",
"from",
",",
"$",
"limit",
",",
"$",
"options",
")",
"{",
"global",
"$",
"PAGE",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_authors_parameters",
"(",
")",
",",
"array",
"(",
"'id'",
"=>",
"$",
"id",
",",
"'from'",
"=>",
"$",
"from",
",",
"'limit'",
"=>",
"$",
"limit",
",",
"'options'",
"=>",
"$",
"options",
",",
")",
")",
";",
"$",
"id",
"=",
"$",
"params",
"[",
"'id'",
"]",
";",
"$",
"from",
"=",
"$",
"params",
"[",
"'from'",
"]",
";",
"$",
"limit",
"=",
"$",
"params",
"[",
"'limit'",
"]",
";",
"$",
"options",
"=",
"$",
"params",
"[",
"'options'",
"]",
";",
"$",
"warnings",
"=",
"array",
"(",
")",
";",
"// Get and validate the glossary.",
"list",
"(",
"$",
"glossary",
",",
"$",
"context",
")",
"=",
"self",
"::",
"validate_glossary",
"(",
"$",
"id",
")",
";",
"// Fetching the entries.",
"list",
"(",
"$",
"users",
",",
"$",
"count",
")",
"=",
"glossary_get_authors",
"(",
"$",
"glossary",
",",
"$",
"context",
",",
"$",
"limit",
",",
"$",
"from",
",",
"$",
"options",
")",
";",
"$",
"canviewfullnames",
"=",
"has_capability",
"(",
"'moodle/site:viewfullnames'",
",",
"$",
"context",
")",
";",
"foreach",
"(",
"$",
"users",
"as",
"$",
"user",
")",
"{",
"$",
"userpicture",
"=",
"new",
"user_picture",
"(",
"$",
"user",
")",
";",
"$",
"userpicture",
"->",
"size",
"=",
"1",
";",
"$",
"author",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"author",
"->",
"id",
"=",
"$",
"user",
"->",
"id",
";",
"$",
"author",
"->",
"fullname",
"=",
"fullname",
"(",
"$",
"user",
",",
"$",
"canviewfullnames",
")",
";",
"$",
"author",
"->",
"pictureurl",
"=",
"$",
"userpicture",
"->",
"get_url",
"(",
"$",
"PAGE",
")",
"->",
"out",
"(",
"false",
")",
";",
"$",
"authors",
"[",
"]",
"=",
"$",
"author",
";",
"}",
"$",
"users",
"->",
"close",
"(",
")",
";",
"return",
"array",
"(",
"'count'",
"=>",
"$",
"count",
",",
"'authors'",
"=>",
"$",
"authors",
",",
"'warnings'",
"=>",
"array",
"(",
")",
",",
")",
";",
"}"
] | Get the authors of a glossary.
@param int $id The glossary ID.
@param int $from Start returning records from here.
@param int $limit Number of records to return.
@param array $options Array of options.
@return array Containing count, authors and warnings.
@since Moodle 3.1
@throws moodle_exception | [
"Get",
"the",
"authors",
"of",
"a",
"glossary",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/external.php#L823-L862 |
213,990 | moodle/moodle | mod/glossary/classes/external.php | mod_glossary_external.get_entries_by_search | public static function get_entries_by_search($id, $query, $fullsearch, $order, $sort, $from, $limit, $options) {
$params = self::validate_parameters(self::get_entries_by_search_parameters(), array(
'id' => $id,
'query' => $query,
'fullsearch' => $fullsearch,
'order' => core_text::strtoupper($order),
'sort' => core_text::strtoupper($sort),
'from' => $from,
'limit' => $limit,
'options' => $options,
));
$id = $params['id'];
$query = $params['query'];
$fullsearch = $params['fullsearch'];
$order = $params['order'];
$sort = $params['sort'];
$from = $params['from'];
$limit = $params['limit'];
$options = $params['options'];
$warnings = array();
if (!in_array($order, array('CONCEPT', 'CREATION', 'UPDATE'))) {
throw new invalid_parameter_exception('invalidorder');
} else if (!in_array($sort, array('ASC', 'DESC'))) {
throw new invalid_parameter_exception('invalidsort');
}
// Get and validate the glossary.
list($glossary, $context) = self::validate_glossary($id);
// Fetching the entries.
$entries = array();
list($records, $count) = glossary_get_entries_by_search($glossary, $context, $query, $fullsearch, $order, $sort, $from,
$limit, $options);
foreach ($records as $key => $record) {
self::fill_entry_details($record, $context);
$entries[] = $record;
}
return array(
'count' => $count,
'entries' => $entries,
'ratinginfo' => \core_rating\external\util::get_rating_info($glossary, $context, 'mod_glossary', 'entry', $entries),
'warnings' => $warnings
);
} | php | public static function get_entries_by_search($id, $query, $fullsearch, $order, $sort, $from, $limit, $options) {
$params = self::validate_parameters(self::get_entries_by_search_parameters(), array(
'id' => $id,
'query' => $query,
'fullsearch' => $fullsearch,
'order' => core_text::strtoupper($order),
'sort' => core_text::strtoupper($sort),
'from' => $from,
'limit' => $limit,
'options' => $options,
));
$id = $params['id'];
$query = $params['query'];
$fullsearch = $params['fullsearch'];
$order = $params['order'];
$sort = $params['sort'];
$from = $params['from'];
$limit = $params['limit'];
$options = $params['options'];
$warnings = array();
if (!in_array($order, array('CONCEPT', 'CREATION', 'UPDATE'))) {
throw new invalid_parameter_exception('invalidorder');
} else if (!in_array($sort, array('ASC', 'DESC'))) {
throw new invalid_parameter_exception('invalidsort');
}
// Get and validate the glossary.
list($glossary, $context) = self::validate_glossary($id);
// Fetching the entries.
$entries = array();
list($records, $count) = glossary_get_entries_by_search($glossary, $context, $query, $fullsearch, $order, $sort, $from,
$limit, $options);
foreach ($records as $key => $record) {
self::fill_entry_details($record, $context);
$entries[] = $record;
}
return array(
'count' => $count,
'entries' => $entries,
'ratinginfo' => \core_rating\external\util::get_rating_info($glossary, $context, 'mod_glossary', 'entry', $entries),
'warnings' => $warnings
);
} | [
"public",
"static",
"function",
"get_entries_by_search",
"(",
"$",
"id",
",",
"$",
"query",
",",
"$",
"fullsearch",
",",
"$",
"order",
",",
"$",
"sort",
",",
"$",
"from",
",",
"$",
"limit",
",",
"$",
"options",
")",
"{",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_entries_by_search_parameters",
"(",
")",
",",
"array",
"(",
"'id'",
"=>",
"$",
"id",
",",
"'query'",
"=>",
"$",
"query",
",",
"'fullsearch'",
"=>",
"$",
"fullsearch",
",",
"'order'",
"=>",
"core_text",
"::",
"strtoupper",
"(",
"$",
"order",
")",
",",
"'sort'",
"=>",
"core_text",
"::",
"strtoupper",
"(",
"$",
"sort",
")",
",",
"'from'",
"=>",
"$",
"from",
",",
"'limit'",
"=>",
"$",
"limit",
",",
"'options'",
"=>",
"$",
"options",
",",
")",
")",
";",
"$",
"id",
"=",
"$",
"params",
"[",
"'id'",
"]",
";",
"$",
"query",
"=",
"$",
"params",
"[",
"'query'",
"]",
";",
"$",
"fullsearch",
"=",
"$",
"params",
"[",
"'fullsearch'",
"]",
";",
"$",
"order",
"=",
"$",
"params",
"[",
"'order'",
"]",
";",
"$",
"sort",
"=",
"$",
"params",
"[",
"'sort'",
"]",
";",
"$",
"from",
"=",
"$",
"params",
"[",
"'from'",
"]",
";",
"$",
"limit",
"=",
"$",
"params",
"[",
"'limit'",
"]",
";",
"$",
"options",
"=",
"$",
"params",
"[",
"'options'",
"]",
";",
"$",
"warnings",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"order",
",",
"array",
"(",
"'CONCEPT'",
",",
"'CREATION'",
",",
"'UPDATE'",
")",
")",
")",
"{",
"throw",
"new",
"invalid_parameter_exception",
"(",
"'invalidorder'",
")",
";",
"}",
"else",
"if",
"(",
"!",
"in_array",
"(",
"$",
"sort",
",",
"array",
"(",
"'ASC'",
",",
"'DESC'",
")",
")",
")",
"{",
"throw",
"new",
"invalid_parameter_exception",
"(",
"'invalidsort'",
")",
";",
"}",
"// Get and validate the glossary.",
"list",
"(",
"$",
"glossary",
",",
"$",
"context",
")",
"=",
"self",
"::",
"validate_glossary",
"(",
"$",
"id",
")",
";",
"// Fetching the entries.",
"$",
"entries",
"=",
"array",
"(",
")",
";",
"list",
"(",
"$",
"records",
",",
"$",
"count",
")",
"=",
"glossary_get_entries_by_search",
"(",
"$",
"glossary",
",",
"$",
"context",
",",
"$",
"query",
",",
"$",
"fullsearch",
",",
"$",
"order",
",",
"$",
"sort",
",",
"$",
"from",
",",
"$",
"limit",
",",
"$",
"options",
")",
";",
"foreach",
"(",
"$",
"records",
"as",
"$",
"key",
"=>",
"$",
"record",
")",
"{",
"self",
"::",
"fill_entry_details",
"(",
"$",
"record",
",",
"$",
"context",
")",
";",
"$",
"entries",
"[",
"]",
"=",
"$",
"record",
";",
"}",
"return",
"array",
"(",
"'count'",
"=>",
"$",
"count",
",",
"'entries'",
"=>",
"$",
"entries",
",",
"'ratinginfo'",
"=>",
"\\",
"core_rating",
"\\",
"external",
"\\",
"util",
"::",
"get_rating_info",
"(",
"$",
"glossary",
",",
"$",
"context",
",",
"'mod_glossary'",
",",
"'entry'",
",",
"$",
"entries",
")",
",",
"'warnings'",
"=>",
"$",
"warnings",
")",
";",
"}"
] | Browse a glossary entries using the search.
@param int $id The glossary ID.
@param string $query The search query.
@param bool $fullsearch Whether or not full search is required.
@param string $order The way to order the results.
@param string $sort The direction of the order.
@param int $from Start returning records from here.
@param int $limit Number of records to return.
@param array $options Array of options.
@return array Containing count, entries and warnings.
@since Moodle 3.1
@throws moodle_exception
@throws invalid_parameter_exception | [
"Browse",
"a",
"glossary",
"entries",
"using",
"the",
"search",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/external.php#L1134-L1179 |
213,991 | moodle/moodle | mod/glossary/classes/external.php | mod_glossary_external.get_entry_by_id | public static function get_entry_by_id($id) {
global $DB, $USER;
$params = self::validate_parameters(self::get_entry_by_id_parameters(), array('id' => $id));
$id = $params['id'];
$warnings = array();
// Get and validate the glossary.
$entry = $DB->get_record('glossary_entries', array('id' => $id), '*', MUST_EXIST);
list($glossary, $context) = self::validate_glossary($entry->glossaryid);
if (empty($entry->approved) && $entry->userid != $USER->id && !has_capability('mod/glossary:approve', $context)) {
throw new invalid_parameter_exception('invalidentry');
}
$entry = glossary_get_entry_by_id($id);
self::fill_entry_details($entry, $context);
return array(
'entry' => $entry,
'ratinginfo' => \core_rating\external\util::get_rating_info($glossary, $context, 'mod_glossary', 'entry',
array($entry)),
'warnings' => $warnings
);
} | php | public static function get_entry_by_id($id) {
global $DB, $USER;
$params = self::validate_parameters(self::get_entry_by_id_parameters(), array('id' => $id));
$id = $params['id'];
$warnings = array();
// Get and validate the glossary.
$entry = $DB->get_record('glossary_entries', array('id' => $id), '*', MUST_EXIST);
list($glossary, $context) = self::validate_glossary($entry->glossaryid);
if (empty($entry->approved) && $entry->userid != $USER->id && !has_capability('mod/glossary:approve', $context)) {
throw new invalid_parameter_exception('invalidentry');
}
$entry = glossary_get_entry_by_id($id);
self::fill_entry_details($entry, $context);
return array(
'entry' => $entry,
'ratinginfo' => \core_rating\external\util::get_rating_info($glossary, $context, 'mod_glossary', 'entry',
array($entry)),
'warnings' => $warnings
);
} | [
"public",
"static",
"function",
"get_entry_by_id",
"(",
"$",
"id",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"USER",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"get_entry_by_id_parameters",
"(",
")",
",",
"array",
"(",
"'id'",
"=>",
"$",
"id",
")",
")",
";",
"$",
"id",
"=",
"$",
"params",
"[",
"'id'",
"]",
";",
"$",
"warnings",
"=",
"array",
"(",
")",
";",
"// Get and validate the glossary.",
"$",
"entry",
"=",
"$",
"DB",
"->",
"get_record",
"(",
"'glossary_entries'",
",",
"array",
"(",
"'id'",
"=>",
"$",
"id",
")",
",",
"'*'",
",",
"MUST_EXIST",
")",
";",
"list",
"(",
"$",
"glossary",
",",
"$",
"context",
")",
"=",
"self",
"::",
"validate_glossary",
"(",
"$",
"entry",
"->",
"glossaryid",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"entry",
"->",
"approved",
")",
"&&",
"$",
"entry",
"->",
"userid",
"!=",
"$",
"USER",
"->",
"id",
"&&",
"!",
"has_capability",
"(",
"'mod/glossary:approve'",
",",
"$",
"context",
")",
")",
"{",
"throw",
"new",
"invalid_parameter_exception",
"(",
"'invalidentry'",
")",
";",
"}",
"$",
"entry",
"=",
"glossary_get_entry_by_id",
"(",
"$",
"id",
")",
";",
"self",
"::",
"fill_entry_details",
"(",
"$",
"entry",
",",
"$",
"context",
")",
";",
"return",
"array",
"(",
"'entry'",
"=>",
"$",
"entry",
",",
"'ratinginfo'",
"=>",
"\\",
"core_rating",
"\\",
"external",
"\\",
"util",
"::",
"get_rating_info",
"(",
"$",
"glossary",
",",
"$",
"context",
",",
"'mod_glossary'",
",",
"'entry'",
",",
"array",
"(",
"$",
"entry",
")",
")",
",",
"'warnings'",
"=>",
"$",
"warnings",
")",
";",
"}"
] | Get an entry.
@param int $id The entry ID.
@return array Containing entry and warnings.
@since Moodle 3.1
@throws moodle_exception
@throws invalid_parameter_exception | [
"Get",
"an",
"entry",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/external.php#L1389-L1413 |
213,992 | moodle/moodle | mod/glossary/classes/external.php | mod_glossary_external.add_entry | public static function add_entry($glossaryid, $concept, $definition, $definitionformat, $options = array()) {
global $CFG;
$params = self::validate_parameters(self::add_entry_parameters(), array(
'glossaryid' => $glossaryid,
'concept' => $concept,
'definition' => $definition,
'definitionformat' => $definitionformat,
'options' => $options,
));
$warnings = array();
// Get and validate the glossary.
list($glossary, $context, $course, $cm) = self::validate_glossary($params['glossaryid']);
require_capability('mod/glossary:write', $context);
if (!$glossary->allowduplicatedentries) {
if (glossary_concept_exists($glossary, $params['concept'])) {
throw new moodle_exception('errconceptalreadyexists', 'glossary');
}
}
// Prepare the entry object.
$entry = new stdClass;
$entry->id = null;
$entry->aliases = '';
$entry->usedynalink = $CFG->glossary_linkentries;
$entry->casesensitive = $CFG->glossary_casesensitive;
$entry->fullmatch = $CFG->glossary_fullmatch;
$entry->concept = $params['concept'];
$entry->definition_editor = array(
'text' => $params['definition'],
'format' => $params['definitionformat'],
);
// Options.
foreach ($params['options'] as $option) {
$name = trim($option['name']);
switch ($name) {
case 'inlineattachmentsid':
$entry->definition_editor['itemid'] = clean_param($option['value'], PARAM_INT);
break;
case 'attachmentsid':
$entry->attachment_filemanager = clean_param($option['value'], PARAM_INT);
break;
case 'categories':
$entry->categories = clean_param($option['value'], PARAM_SEQUENCE);
$entry->categories = explode(',', $entry->categories);
break;
case 'aliases':
$entry->aliases = clean_param($option['value'], PARAM_NOTAGS);
// Convert to the expected format.
$entry->aliases = str_replace(",", "\n", $entry->aliases);
break;
case 'usedynalink':
case 'casesensitive':
case 'fullmatch':
// Only allow if linking is enabled.
if ($glossary->usedynalink) {
$entry->{$name} = clean_param($option['value'], PARAM_BOOL);
}
break;
default:
throw new moodle_exception('errorinvalidparam', 'webservice', '', $name);
}
}
$entry = glossary_edit_entry($entry, $course, $cm, $glossary, $context);
return array(
'entryid' => $entry->id,
'warnings' => $warnings
);
} | php | public static function add_entry($glossaryid, $concept, $definition, $definitionformat, $options = array()) {
global $CFG;
$params = self::validate_parameters(self::add_entry_parameters(), array(
'glossaryid' => $glossaryid,
'concept' => $concept,
'definition' => $definition,
'definitionformat' => $definitionformat,
'options' => $options,
));
$warnings = array();
// Get and validate the glossary.
list($glossary, $context, $course, $cm) = self::validate_glossary($params['glossaryid']);
require_capability('mod/glossary:write', $context);
if (!$glossary->allowduplicatedentries) {
if (glossary_concept_exists($glossary, $params['concept'])) {
throw new moodle_exception('errconceptalreadyexists', 'glossary');
}
}
// Prepare the entry object.
$entry = new stdClass;
$entry->id = null;
$entry->aliases = '';
$entry->usedynalink = $CFG->glossary_linkentries;
$entry->casesensitive = $CFG->glossary_casesensitive;
$entry->fullmatch = $CFG->glossary_fullmatch;
$entry->concept = $params['concept'];
$entry->definition_editor = array(
'text' => $params['definition'],
'format' => $params['definitionformat'],
);
// Options.
foreach ($params['options'] as $option) {
$name = trim($option['name']);
switch ($name) {
case 'inlineattachmentsid':
$entry->definition_editor['itemid'] = clean_param($option['value'], PARAM_INT);
break;
case 'attachmentsid':
$entry->attachment_filemanager = clean_param($option['value'], PARAM_INT);
break;
case 'categories':
$entry->categories = clean_param($option['value'], PARAM_SEQUENCE);
$entry->categories = explode(',', $entry->categories);
break;
case 'aliases':
$entry->aliases = clean_param($option['value'], PARAM_NOTAGS);
// Convert to the expected format.
$entry->aliases = str_replace(",", "\n", $entry->aliases);
break;
case 'usedynalink':
case 'casesensitive':
case 'fullmatch':
// Only allow if linking is enabled.
if ($glossary->usedynalink) {
$entry->{$name} = clean_param($option['value'], PARAM_BOOL);
}
break;
default:
throw new moodle_exception('errorinvalidparam', 'webservice', '', $name);
}
}
$entry = glossary_edit_entry($entry, $course, $cm, $glossary, $context);
return array(
'entryid' => $entry->id,
'warnings' => $warnings
);
} | [
"public",
"static",
"function",
"add_entry",
"(",
"$",
"glossaryid",
",",
"$",
"concept",
",",
"$",
"definition",
",",
"$",
"definitionformat",
",",
"$",
"options",
"=",
"array",
"(",
")",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"params",
"=",
"self",
"::",
"validate_parameters",
"(",
"self",
"::",
"add_entry_parameters",
"(",
")",
",",
"array",
"(",
"'glossaryid'",
"=>",
"$",
"glossaryid",
",",
"'concept'",
"=>",
"$",
"concept",
",",
"'definition'",
"=>",
"$",
"definition",
",",
"'definitionformat'",
"=>",
"$",
"definitionformat",
",",
"'options'",
"=>",
"$",
"options",
",",
")",
")",
";",
"$",
"warnings",
"=",
"array",
"(",
")",
";",
"// Get and validate the glossary.",
"list",
"(",
"$",
"glossary",
",",
"$",
"context",
",",
"$",
"course",
",",
"$",
"cm",
")",
"=",
"self",
"::",
"validate_glossary",
"(",
"$",
"params",
"[",
"'glossaryid'",
"]",
")",
";",
"require_capability",
"(",
"'mod/glossary:write'",
",",
"$",
"context",
")",
";",
"if",
"(",
"!",
"$",
"glossary",
"->",
"allowduplicatedentries",
")",
"{",
"if",
"(",
"glossary_concept_exists",
"(",
"$",
"glossary",
",",
"$",
"params",
"[",
"'concept'",
"]",
")",
")",
"{",
"throw",
"new",
"moodle_exception",
"(",
"'errconceptalreadyexists'",
",",
"'glossary'",
")",
";",
"}",
"}",
"// Prepare the entry object.",
"$",
"entry",
"=",
"new",
"stdClass",
";",
"$",
"entry",
"->",
"id",
"=",
"null",
";",
"$",
"entry",
"->",
"aliases",
"=",
"''",
";",
"$",
"entry",
"->",
"usedynalink",
"=",
"$",
"CFG",
"->",
"glossary_linkentries",
";",
"$",
"entry",
"->",
"casesensitive",
"=",
"$",
"CFG",
"->",
"glossary_casesensitive",
";",
"$",
"entry",
"->",
"fullmatch",
"=",
"$",
"CFG",
"->",
"glossary_fullmatch",
";",
"$",
"entry",
"->",
"concept",
"=",
"$",
"params",
"[",
"'concept'",
"]",
";",
"$",
"entry",
"->",
"definition_editor",
"=",
"array",
"(",
"'text'",
"=>",
"$",
"params",
"[",
"'definition'",
"]",
",",
"'format'",
"=>",
"$",
"params",
"[",
"'definitionformat'",
"]",
",",
")",
";",
"// Options.",
"foreach",
"(",
"$",
"params",
"[",
"'options'",
"]",
"as",
"$",
"option",
")",
"{",
"$",
"name",
"=",
"trim",
"(",
"$",
"option",
"[",
"'name'",
"]",
")",
";",
"switch",
"(",
"$",
"name",
")",
"{",
"case",
"'inlineattachmentsid'",
":",
"$",
"entry",
"->",
"definition_editor",
"[",
"'itemid'",
"]",
"=",
"clean_param",
"(",
"$",
"option",
"[",
"'value'",
"]",
",",
"PARAM_INT",
")",
";",
"break",
";",
"case",
"'attachmentsid'",
":",
"$",
"entry",
"->",
"attachment_filemanager",
"=",
"clean_param",
"(",
"$",
"option",
"[",
"'value'",
"]",
",",
"PARAM_INT",
")",
";",
"break",
";",
"case",
"'categories'",
":",
"$",
"entry",
"->",
"categories",
"=",
"clean_param",
"(",
"$",
"option",
"[",
"'value'",
"]",
",",
"PARAM_SEQUENCE",
")",
";",
"$",
"entry",
"->",
"categories",
"=",
"explode",
"(",
"','",
",",
"$",
"entry",
"->",
"categories",
")",
";",
"break",
";",
"case",
"'aliases'",
":",
"$",
"entry",
"->",
"aliases",
"=",
"clean_param",
"(",
"$",
"option",
"[",
"'value'",
"]",
",",
"PARAM_NOTAGS",
")",
";",
"// Convert to the expected format.",
"$",
"entry",
"->",
"aliases",
"=",
"str_replace",
"(",
"\",\"",
",",
"\"\\n\"",
",",
"$",
"entry",
"->",
"aliases",
")",
";",
"break",
";",
"case",
"'usedynalink'",
":",
"case",
"'casesensitive'",
":",
"case",
"'fullmatch'",
":",
"// Only allow if linking is enabled.",
"if",
"(",
"$",
"glossary",
"->",
"usedynalink",
")",
"{",
"$",
"entry",
"->",
"{",
"$",
"name",
"}",
"=",
"clean_param",
"(",
"$",
"option",
"[",
"'value'",
"]",
",",
"PARAM_BOOL",
")",
";",
"}",
"break",
";",
"default",
":",
"throw",
"new",
"moodle_exception",
"(",
"'errorinvalidparam'",
",",
"'webservice'",
",",
"''",
",",
"$",
"name",
")",
";",
"}",
"}",
"$",
"entry",
"=",
"glossary_edit_entry",
"(",
"$",
"entry",
",",
"$",
"course",
",",
"$",
"cm",
",",
"$",
"glossary",
",",
"$",
"context",
")",
";",
"return",
"array",
"(",
"'entryid'",
"=>",
"$",
"entry",
"->",
"id",
",",
"'warnings'",
"=>",
"$",
"warnings",
")",
";",
"}"
] | Add a new entry to a given glossary.
@param int $glossaryid the glosary id
@param string $concept the glossary concept
@param string $definition the concept definition
@param int $definitionformat the concept definition format
@param array $options additional settings
@return array Containing entry and warnings.
@since Moodle 3.2
@throws moodle_exception
@throws invalid_parameter_exception | [
"Add",
"a",
"new",
"entry",
"to",
"a",
"given",
"glossary",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/glossary/classes/external.php#L1474-L1546 |
213,993 | moodle/moodle | enrol/meta/locallib.php | enrol_meta_handler.sync_course_instances | protected static function sync_course_instances($courseid, $userid) {
global $DB;
static $preventrecursion = false;
// does anything want to sync with this parent?
if (!$enrols = $DB->get_records('enrol', array('customint1'=>$courseid, 'enrol'=>'meta'), 'id ASC')) {
return;
}
if ($preventrecursion) {
return;
}
$preventrecursion = true;
try {
foreach ($enrols as $enrol) {
self::sync_with_parent_course($enrol, $userid);
}
} catch (Exception $e) {
$preventrecursion = false;
throw $e;
}
$preventrecursion = false;
} | php | protected static function sync_course_instances($courseid, $userid) {
global $DB;
static $preventrecursion = false;
// does anything want to sync with this parent?
if (!$enrols = $DB->get_records('enrol', array('customint1'=>$courseid, 'enrol'=>'meta'), 'id ASC')) {
return;
}
if ($preventrecursion) {
return;
}
$preventrecursion = true;
try {
foreach ($enrols as $enrol) {
self::sync_with_parent_course($enrol, $userid);
}
} catch (Exception $e) {
$preventrecursion = false;
throw $e;
}
$preventrecursion = false;
} | [
"protected",
"static",
"function",
"sync_course_instances",
"(",
"$",
"courseid",
",",
"$",
"userid",
")",
"{",
"global",
"$",
"DB",
";",
"static",
"$",
"preventrecursion",
"=",
"false",
";",
"// does anything want to sync with this parent?",
"if",
"(",
"!",
"$",
"enrols",
"=",
"$",
"DB",
"->",
"get_records",
"(",
"'enrol'",
",",
"array",
"(",
"'customint1'",
"=>",
"$",
"courseid",
",",
"'enrol'",
"=>",
"'meta'",
")",
",",
"'id ASC'",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"$",
"preventrecursion",
")",
"{",
"return",
";",
"}",
"$",
"preventrecursion",
"=",
"true",
";",
"try",
"{",
"foreach",
"(",
"$",
"enrols",
"as",
"$",
"enrol",
")",
"{",
"self",
"::",
"sync_with_parent_course",
"(",
"$",
"enrol",
",",
"$",
"userid",
")",
";",
"}",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"$",
"preventrecursion",
"=",
"false",
";",
"throw",
"$",
"e",
";",
"}",
"$",
"preventrecursion",
"=",
"false",
";",
"}"
] | Synchronise meta enrolments of this user in this course
@static
@param int $courseid
@param int $userid
@return void | [
"Synchronise",
"meta",
"enrolments",
"of",
"this",
"user",
"in",
"this",
"course"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/meta/locallib.php#L43-L69 |
213,994 | moodle/moodle | enrol/meta/locallib.php | enrol_meta_handler.user_not_supposed_to_be_here | protected static function user_not_supposed_to_be_here($instance, $ue, context_course $context, $plugin) {
if (!$ue) {
// Not enrolled yet - simple!
return;
}
$userid = $ue->userid;
$unenrolaction = $plugin->get_config('unenrolaction', ENROL_EXT_REMOVED_SUSPENDNOROLES);
if ($unenrolaction == ENROL_EXT_REMOVED_UNENROL) {
// Purges grades, group membership, preferences, etc. - admins were warned!
$plugin->unenrol_user($instance, $userid);
} else if ($unenrolaction == ENROL_EXT_REMOVED_SUSPEND) {
if ($ue->status != ENROL_USER_SUSPENDED) {
$plugin->update_user_enrol($instance, $userid, ENROL_USER_SUSPENDED);
}
} else if ($unenrolaction == ENROL_EXT_REMOVED_SUSPENDNOROLES) {
if ($ue->status != ENROL_USER_SUSPENDED) {
$plugin->update_user_enrol($instance, $userid, ENROL_USER_SUSPENDED);
}
role_unassign_all(array('userid'=>$userid, 'contextid'=>$context->id, 'component'=>'enrol_meta', 'itemid'=>$instance->id));
} else {
debugging('Unknown unenrol action '.$unenrolaction);
}
} | php | protected static function user_not_supposed_to_be_here($instance, $ue, context_course $context, $plugin) {
if (!$ue) {
// Not enrolled yet - simple!
return;
}
$userid = $ue->userid;
$unenrolaction = $plugin->get_config('unenrolaction', ENROL_EXT_REMOVED_SUSPENDNOROLES);
if ($unenrolaction == ENROL_EXT_REMOVED_UNENROL) {
// Purges grades, group membership, preferences, etc. - admins were warned!
$plugin->unenrol_user($instance, $userid);
} else if ($unenrolaction == ENROL_EXT_REMOVED_SUSPEND) {
if ($ue->status != ENROL_USER_SUSPENDED) {
$plugin->update_user_enrol($instance, $userid, ENROL_USER_SUSPENDED);
}
} else if ($unenrolaction == ENROL_EXT_REMOVED_SUSPENDNOROLES) {
if ($ue->status != ENROL_USER_SUSPENDED) {
$plugin->update_user_enrol($instance, $userid, ENROL_USER_SUSPENDED);
}
role_unassign_all(array('userid'=>$userid, 'contextid'=>$context->id, 'component'=>'enrol_meta', 'itemid'=>$instance->id));
} else {
debugging('Unknown unenrol action '.$unenrolaction);
}
} | [
"protected",
"static",
"function",
"user_not_supposed_to_be_here",
"(",
"$",
"instance",
",",
"$",
"ue",
",",
"context_course",
"$",
"context",
",",
"$",
"plugin",
")",
"{",
"if",
"(",
"!",
"$",
"ue",
")",
"{",
"// Not enrolled yet - simple!",
"return",
";",
"}",
"$",
"userid",
"=",
"$",
"ue",
"->",
"userid",
";",
"$",
"unenrolaction",
"=",
"$",
"plugin",
"->",
"get_config",
"(",
"'unenrolaction'",
",",
"ENROL_EXT_REMOVED_SUSPENDNOROLES",
")",
";",
"if",
"(",
"$",
"unenrolaction",
"==",
"ENROL_EXT_REMOVED_UNENROL",
")",
"{",
"// Purges grades, group membership, preferences, etc. - admins were warned!",
"$",
"plugin",
"->",
"unenrol_user",
"(",
"$",
"instance",
",",
"$",
"userid",
")",
";",
"}",
"else",
"if",
"(",
"$",
"unenrolaction",
"==",
"ENROL_EXT_REMOVED_SUSPEND",
")",
"{",
"if",
"(",
"$",
"ue",
"->",
"status",
"!=",
"ENROL_USER_SUSPENDED",
")",
"{",
"$",
"plugin",
"->",
"update_user_enrol",
"(",
"$",
"instance",
",",
"$",
"userid",
",",
"ENROL_USER_SUSPENDED",
")",
";",
"}",
"}",
"else",
"if",
"(",
"$",
"unenrolaction",
"==",
"ENROL_EXT_REMOVED_SUSPENDNOROLES",
")",
"{",
"if",
"(",
"$",
"ue",
"->",
"status",
"!=",
"ENROL_USER_SUSPENDED",
")",
"{",
"$",
"plugin",
"->",
"update_user_enrol",
"(",
"$",
"instance",
",",
"$",
"userid",
",",
"ENROL_USER_SUSPENDED",
")",
";",
"}",
"role_unassign_all",
"(",
"array",
"(",
"'userid'",
"=>",
"$",
"userid",
",",
"'contextid'",
"=>",
"$",
"context",
"->",
"id",
",",
"'component'",
"=>",
"'enrol_meta'",
",",
"'itemid'",
"=>",
"$",
"instance",
"->",
"id",
")",
")",
";",
"}",
"else",
"{",
"debugging",
"(",
"'Unknown unenrol action '",
".",
"$",
"unenrolaction",
")",
";",
"}",
"}"
] | Deal with users that are not supposed to be enrolled via this instance
@static
@param stdClass $instance
@param stdClass $ue
@param context_course $context
@param enrol_meta $plugin
@return void | [
"Deal",
"with",
"users",
"that",
"are",
"not",
"supposed",
"to",
"be",
"enrolled",
"via",
"this",
"instance"
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/meta/locallib.php#L224-L251 |
213,995 | moodle/moodle | grade/import/csv/classes/load_data.php | gradeimport_csv_load_data.load_csv_content | public function load_csv_content($text, $encoding, $separator, $previewrows) {
$this->raise_limits();
$this->iid = csv_import_reader::get_new_iid('grade');
$csvimport = new csv_import_reader($this->iid, 'grade');
$csvimport->load_csv_content($text, $encoding, $separator);
$this->error = $csvimport->get_error();
// If there are no import errors then proceed.
if (empty($this->error)) {
// Get header (field names).
$this->headers = $csvimport->get_columns();
$this->trim_headers();
$csvimport->init();
$this->previewdata = array();
for ($numlines = 0; $numlines <= $previewrows; $numlines++) {
$lines = $csvimport->next();
if ($lines) {
$this->previewdata[] = $lines;
}
}
}
} | php | public function load_csv_content($text, $encoding, $separator, $previewrows) {
$this->raise_limits();
$this->iid = csv_import_reader::get_new_iid('grade');
$csvimport = new csv_import_reader($this->iid, 'grade');
$csvimport->load_csv_content($text, $encoding, $separator);
$this->error = $csvimport->get_error();
// If there are no import errors then proceed.
if (empty($this->error)) {
// Get header (field names).
$this->headers = $csvimport->get_columns();
$this->trim_headers();
$csvimport->init();
$this->previewdata = array();
for ($numlines = 0; $numlines <= $previewrows; $numlines++) {
$lines = $csvimport->next();
if ($lines) {
$this->previewdata[] = $lines;
}
}
}
} | [
"public",
"function",
"load_csv_content",
"(",
"$",
"text",
",",
"$",
"encoding",
",",
"$",
"separator",
",",
"$",
"previewrows",
")",
"{",
"$",
"this",
"->",
"raise_limits",
"(",
")",
";",
"$",
"this",
"->",
"iid",
"=",
"csv_import_reader",
"::",
"get_new_iid",
"(",
"'grade'",
")",
";",
"$",
"csvimport",
"=",
"new",
"csv_import_reader",
"(",
"$",
"this",
"->",
"iid",
",",
"'grade'",
")",
";",
"$",
"csvimport",
"->",
"load_csv_content",
"(",
"$",
"text",
",",
"$",
"encoding",
",",
"$",
"separator",
")",
";",
"$",
"this",
"->",
"error",
"=",
"$",
"csvimport",
"->",
"get_error",
"(",
")",
";",
"// If there are no import errors then proceed.",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"error",
")",
")",
"{",
"// Get header (field names).",
"$",
"this",
"->",
"headers",
"=",
"$",
"csvimport",
"->",
"get_columns",
"(",
")",
";",
"$",
"this",
"->",
"trim_headers",
"(",
")",
";",
"$",
"csvimport",
"->",
"init",
"(",
")",
";",
"$",
"this",
"->",
"previewdata",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"numlines",
"=",
"0",
";",
"$",
"numlines",
"<=",
"$",
"previewrows",
";",
"$",
"numlines",
"++",
")",
"{",
"$",
"lines",
"=",
"$",
"csvimport",
"->",
"next",
"(",
")",
";",
"if",
"(",
"$",
"lines",
")",
"{",
"$",
"this",
"->",
"previewdata",
"[",
"]",
"=",
"$",
"lines",
";",
"}",
"}",
"}",
"}"
] | Load CSV content for previewing.
@param string $text The grade data being imported.
@param string $encoding The type of encoding the file uses.
@param string $separator The separator being used to define each field.
@param int $previewrows How many rows are being previewed. | [
"Load",
"CSV",
"content",
"for",
"previewing",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/import/csv/classes/load_data.php#L71-L97 |
213,996 | moodle/moodle | grade/import/csv/classes/load_data.php | gradeimport_csv_load_data.fetch_grade_items | public static function fetch_grade_items($courseid) {
$gradeitems = null;
if ($allgradeitems = grade_item::fetch_all(array('courseid' => $courseid))) {
foreach ($allgradeitems as $gradeitem) {
// Skip course type and category type.
if ($gradeitem->itemtype == 'course' || $gradeitem->itemtype == 'category') {
continue;
}
$displaystring = null;
if (!empty($gradeitem->itemmodule)) {
$displaystring = get_string('modulename', $gradeitem->itemmodule).get_string('labelsep', 'langconfig')
.$gradeitem->get_name();
} else {
$displaystring = $gradeitem->get_name();
}
$gradeitems[$gradeitem->id] = $displaystring;
}
}
return $gradeitems;
} | php | public static function fetch_grade_items($courseid) {
$gradeitems = null;
if ($allgradeitems = grade_item::fetch_all(array('courseid' => $courseid))) {
foreach ($allgradeitems as $gradeitem) {
// Skip course type and category type.
if ($gradeitem->itemtype == 'course' || $gradeitem->itemtype == 'category') {
continue;
}
$displaystring = null;
if (!empty($gradeitem->itemmodule)) {
$displaystring = get_string('modulename', $gradeitem->itemmodule).get_string('labelsep', 'langconfig')
.$gradeitem->get_name();
} else {
$displaystring = $gradeitem->get_name();
}
$gradeitems[$gradeitem->id] = $displaystring;
}
}
return $gradeitems;
} | [
"public",
"static",
"function",
"fetch_grade_items",
"(",
"$",
"courseid",
")",
"{",
"$",
"gradeitems",
"=",
"null",
";",
"if",
"(",
"$",
"allgradeitems",
"=",
"grade_item",
"::",
"fetch_all",
"(",
"array",
"(",
"'courseid'",
"=>",
"$",
"courseid",
")",
")",
")",
"{",
"foreach",
"(",
"$",
"allgradeitems",
"as",
"$",
"gradeitem",
")",
"{",
"// Skip course type and category type.",
"if",
"(",
"$",
"gradeitem",
"->",
"itemtype",
"==",
"'course'",
"||",
"$",
"gradeitem",
"->",
"itemtype",
"==",
"'category'",
")",
"{",
"continue",
";",
"}",
"$",
"displaystring",
"=",
"null",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"gradeitem",
"->",
"itemmodule",
")",
")",
"{",
"$",
"displaystring",
"=",
"get_string",
"(",
"'modulename'",
",",
"$",
"gradeitem",
"->",
"itemmodule",
")",
".",
"get_string",
"(",
"'labelsep'",
",",
"'langconfig'",
")",
".",
"$",
"gradeitem",
"->",
"get_name",
"(",
")",
";",
"}",
"else",
"{",
"$",
"displaystring",
"=",
"$",
"gradeitem",
"->",
"get_name",
"(",
")",
";",
"}",
"$",
"gradeitems",
"[",
"$",
"gradeitem",
"->",
"id",
"]",
"=",
"$",
"displaystring",
";",
"}",
"}",
"return",
"$",
"gradeitems",
";",
"}"
] | Gets all of the grade items in this course.
@param int $courseid Course id;
@return array An array of grade items for the course. | [
"Gets",
"all",
"of",
"the",
"grade",
"items",
"in",
"this",
"course",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/import/csv/classes/load_data.php#L105-L125 |
213,997 | moodle/moodle | grade/import/csv/classes/load_data.php | gradeimport_csv_load_data.trim_headers | protected function trim_headers() {
foreach ($this->headers as $i => $h) {
$h = trim($h); // Remove whitespace.
$h = clean_param($h, PARAM_RAW); // Clean the header.
$this->headers[$i] = $h;
}
} | php | protected function trim_headers() {
foreach ($this->headers as $i => $h) {
$h = trim($h); // Remove whitespace.
$h = clean_param($h, PARAM_RAW); // Clean the header.
$this->headers[$i] = $h;
}
} | [
"protected",
"function",
"trim_headers",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"headers",
"as",
"$",
"i",
"=>",
"$",
"h",
")",
"{",
"$",
"h",
"=",
"trim",
"(",
"$",
"h",
")",
";",
"// Remove whitespace.",
"$",
"h",
"=",
"clean_param",
"(",
"$",
"h",
",",
"PARAM_RAW",
")",
";",
"// Clean the header.",
"$",
"this",
"->",
"headers",
"[",
"$",
"i",
"]",
"=",
"$",
"h",
";",
"}",
"}"
] | Cleans the column headers from the CSV file. | [
"Cleans",
"the",
"column",
"headers",
"from",
"the",
"CSV",
"file",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/import/csv/classes/load_data.php#L130-L136 |
213,998 | moodle/moodle | grade/import/csv/classes/load_data.php | gradeimport_csv_load_data.insert_grade_record | protected function insert_grade_record($record, $studentid) {
global $DB, $USER, $CFG;
$record->importcode = $this->importcode;
$record->userid = $studentid;
$record->importer = $USER->id;
// By default the maximum grade is 100.
$gradepointmaximum = 100;
// If the grade limit has been increased then use the gradepointmax setting.
if ($CFG->unlimitedgrades) {
$gradepointmaximum = $CFG->gradepointmax;
}
// If the record final grade is set then check that the grade value isn't too high.
// Final grade will not be set if we are inserting feedback.
if (!isset($record->finalgrade) || $record->finalgrade <= $gradepointmaximum) {
return $DB->insert_record('grade_import_values', $record);
} else {
$this->cleanup_import(get_string('gradevaluetoobig', 'grades', $gradepointmaximum));
return null;
}
} | php | protected function insert_grade_record($record, $studentid) {
global $DB, $USER, $CFG;
$record->importcode = $this->importcode;
$record->userid = $studentid;
$record->importer = $USER->id;
// By default the maximum grade is 100.
$gradepointmaximum = 100;
// If the grade limit has been increased then use the gradepointmax setting.
if ($CFG->unlimitedgrades) {
$gradepointmaximum = $CFG->gradepointmax;
}
// If the record final grade is set then check that the grade value isn't too high.
// Final grade will not be set if we are inserting feedback.
if (!isset($record->finalgrade) || $record->finalgrade <= $gradepointmaximum) {
return $DB->insert_record('grade_import_values', $record);
} else {
$this->cleanup_import(get_string('gradevaluetoobig', 'grades', $gradepointmaximum));
return null;
}
} | [
"protected",
"function",
"insert_grade_record",
"(",
"$",
"record",
",",
"$",
"studentid",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"USER",
",",
"$",
"CFG",
";",
"$",
"record",
"->",
"importcode",
"=",
"$",
"this",
"->",
"importcode",
";",
"$",
"record",
"->",
"userid",
"=",
"$",
"studentid",
";",
"$",
"record",
"->",
"importer",
"=",
"$",
"USER",
"->",
"id",
";",
"// By default the maximum grade is 100.",
"$",
"gradepointmaximum",
"=",
"100",
";",
"// If the grade limit has been increased then use the gradepointmax setting.",
"if",
"(",
"$",
"CFG",
"->",
"unlimitedgrades",
")",
"{",
"$",
"gradepointmaximum",
"=",
"$",
"CFG",
"->",
"gradepointmax",
";",
"}",
"// If the record final grade is set then check that the grade value isn't too high.",
"// Final grade will not be set if we are inserting feedback.",
"if",
"(",
"!",
"isset",
"(",
"$",
"record",
"->",
"finalgrade",
")",
"||",
"$",
"record",
"->",
"finalgrade",
"<=",
"$",
"gradepointmaximum",
")",
"{",
"return",
"$",
"DB",
"->",
"insert_record",
"(",
"'grade_import_values'",
",",
"$",
"record",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"cleanup_import",
"(",
"get_string",
"(",
"'gradevaluetoobig'",
",",
"'grades'",
",",
"$",
"gradepointmaximum",
")",
")",
";",
"return",
"null",
";",
"}",
"}"
] | Inserts a record into the grade_import_values table. This also adds common record information.
@param object $record The grade record being inserted into the database.
@param int $studentid The student ID.
@return bool|int true or insert id on success. Null if the grade value is too high. | [
"Inserts",
"a",
"record",
"into",
"the",
"grade_import_values",
"table",
".",
"This",
"also",
"adds",
"common",
"record",
"information",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/import/csv/classes/load_data.php#L156-L175 |
213,999 | moodle/moodle | grade/import/csv/classes/load_data.php | gradeimport_csv_load_data.import_new_grade_item | protected function import_new_grade_item($header, $key, $value) {
global $DB, $USER;
// First check if header is already in temp database.
if (empty($this->newgradeitems[$key])) {
$newgradeitem = new stdClass();
$newgradeitem->itemname = $header[$key];
$newgradeitem->importcode = $this->importcode;
$newgradeitem->importer = $USER->id;
// Insert into new grade item buffer.
$this->newgradeitems[$key] = $DB->insert_record('grade_import_newitem', $newgradeitem);
}
$newgrade = new stdClass();
$newgrade->newgradeitem = $this->newgradeitems[$key];
$trimmed = trim($value);
if ($trimmed === '' or $trimmed == '-') {
// Blank or dash grade means null, ie "no grade".
$newgrade->finalgrade = null;
} else {
// We have an actual grade.
$newgrade->finalgrade = $value;
}
$this->newgrades[] = $newgrade;
return $newgrade;
} | php | protected function import_new_grade_item($header, $key, $value) {
global $DB, $USER;
// First check if header is already in temp database.
if (empty($this->newgradeitems[$key])) {
$newgradeitem = new stdClass();
$newgradeitem->itemname = $header[$key];
$newgradeitem->importcode = $this->importcode;
$newgradeitem->importer = $USER->id;
// Insert into new grade item buffer.
$this->newgradeitems[$key] = $DB->insert_record('grade_import_newitem', $newgradeitem);
}
$newgrade = new stdClass();
$newgrade->newgradeitem = $this->newgradeitems[$key];
$trimmed = trim($value);
if ($trimmed === '' or $trimmed == '-') {
// Blank or dash grade means null, ie "no grade".
$newgrade->finalgrade = null;
} else {
// We have an actual grade.
$newgrade->finalgrade = $value;
}
$this->newgrades[] = $newgrade;
return $newgrade;
} | [
"protected",
"function",
"import_new_grade_item",
"(",
"$",
"header",
",",
"$",
"key",
",",
"$",
"value",
")",
"{",
"global",
"$",
"DB",
",",
"$",
"USER",
";",
"// First check if header is already in temp database.",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"newgradeitems",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"newgradeitem",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"newgradeitem",
"->",
"itemname",
"=",
"$",
"header",
"[",
"$",
"key",
"]",
";",
"$",
"newgradeitem",
"->",
"importcode",
"=",
"$",
"this",
"->",
"importcode",
";",
"$",
"newgradeitem",
"->",
"importer",
"=",
"$",
"USER",
"->",
"id",
";",
"// Insert into new grade item buffer.",
"$",
"this",
"->",
"newgradeitems",
"[",
"$",
"key",
"]",
"=",
"$",
"DB",
"->",
"insert_record",
"(",
"'grade_import_newitem'",
",",
"$",
"newgradeitem",
")",
";",
"}",
"$",
"newgrade",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"newgrade",
"->",
"newgradeitem",
"=",
"$",
"this",
"->",
"newgradeitems",
"[",
"$",
"key",
"]",
";",
"$",
"trimmed",
"=",
"trim",
"(",
"$",
"value",
")",
";",
"if",
"(",
"$",
"trimmed",
"===",
"''",
"or",
"$",
"trimmed",
"==",
"'-'",
")",
"{",
"// Blank or dash grade means null, ie \"no grade\".",
"$",
"newgrade",
"->",
"finalgrade",
"=",
"null",
";",
"}",
"else",
"{",
"// We have an actual grade.",
"$",
"newgrade",
"->",
"finalgrade",
"=",
"$",
"value",
";",
"}",
"$",
"this",
"->",
"newgrades",
"[",
"]",
"=",
"$",
"newgrade",
";",
"return",
"$",
"newgrade",
";",
"}"
] | Insert the new grade into the grade item buffer table.
@param array $header The column headers from the CSV file.
@param int $key Current row identifier.
@param string $value The value for this row (final grade).
@return stdClass new grade that is ready for commiting to the gradebook. | [
"Insert",
"the",
"new",
"grade",
"into",
"the",
"grade",
"item",
"buffer",
"table",
"."
] | a411b499b98afc9901c24a9466c7e322946a04aa | https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/import/csv/classes/load_data.php#L185-L212 |
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.