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
217,600
moodle/moodle
lib/behat/behat_field_manager.php
behat_field_manager.get_field_instance
public static function get_field_instance($type, NodeElement $fieldnode, Session $session) { global $CFG; // If the field is not part of a moodleform, we should still try to find out // which field type are we dealing with. if ($type == 'field' && $guessedtype = self::guess_field_type($fieldnode, $session)) { $type = $guessedtype; } $classname = 'behat_form_' . $type; // Fallsback on the type guesser if nothing specific exists. $classpath = $CFG->libdir . '/behat/form_field/' . $classname . '.php'; if (!file_exists($classpath)) { $classname = 'behat_form_field'; $classpath = $CFG->libdir . '/behat/form_field/' . $classname . '.php'; } // Returns the instance. require_once($classpath); return new $classname($session, $fieldnode); }
php
public static function get_field_instance($type, NodeElement $fieldnode, Session $session) { global $CFG; // If the field is not part of a moodleform, we should still try to find out // which field type are we dealing with. if ($type == 'field' && $guessedtype = self::guess_field_type($fieldnode, $session)) { $type = $guessedtype; } $classname = 'behat_form_' . $type; // Fallsback on the type guesser if nothing specific exists. $classpath = $CFG->libdir . '/behat/form_field/' . $classname . '.php'; if (!file_exists($classpath)) { $classname = 'behat_form_field'; $classpath = $CFG->libdir . '/behat/form_field/' . $classname . '.php'; } // Returns the instance. require_once($classpath); return new $classname($session, $fieldnode); }
[ "public", "static", "function", "get_field_instance", "(", "$", "type", ",", "NodeElement", "$", "fieldnode", ",", "Session", "$", "session", ")", "{", "global", "$", "CFG", ";", "// If the field is not part of a moodleform, we should still try to find out", "// which field type are we dealing with.", "if", "(", "$", "type", "==", "'field'", "&&", "$", "guessedtype", "=", "self", "::", "guess_field_type", "(", "$", "fieldnode", ",", "$", "session", ")", ")", "{", "$", "type", "=", "$", "guessedtype", ";", "}", "$", "classname", "=", "'behat_form_'", ".", "$", "type", ";", "// Fallsback on the type guesser if nothing specific exists.", "$", "classpath", "=", "$", "CFG", "->", "libdir", ".", "'/behat/form_field/'", ".", "$", "classname", ".", "'.php'", ";", "if", "(", "!", "file_exists", "(", "$", "classpath", ")", ")", "{", "$", "classname", "=", "'behat_form_field'", ";", "$", "classpath", "=", "$", "CFG", "->", "libdir", ".", "'/behat/form_field/'", ".", "$", "classname", ".", "'.php'", ";", "}", "// Returns the instance.", "require_once", "(", "$", "classpath", ")", ";", "return", "new", "$", "classname", "(", "$", "session", ",", "$", "fieldnode", ")", ";", "}" ]
Returns the appropiate behat_form_field according to the provided type. It defaults to behat_form_field. @param string $type The field type (checkbox, date_selector, text...) @param NodeElement $fieldnode @param Session $session The behat session @return behat_form_field
[ "Returns", "the", "appropiate", "behat_form_field", "according", "to", "the", "provided", "type", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/behat_field_manager.php#L104-L127
217,601
moodle/moodle
lib/behat/behat_field_manager.php
behat_field_manager.guess_field_type
public static function guess_field_type(NodeElement $fieldnode, Session $session) { // Textareas are considered text based elements. $tagname = strtolower($fieldnode->getTagName()); if ($tagname == 'textarea') { // If there is an iframe with $id + _ifr there a TinyMCE editor loaded. $xpath = '//div[@id="' . $fieldnode->getAttribute('id') . 'editable"]'; if ($session->getPage()->find('xpath', $xpath)) { return 'editor'; } return 'textarea'; } else if ($tagname == 'input') { $type = $fieldnode->getAttribute('type'); switch ($type) { case 'text': case 'password': case 'email': case 'file': return 'text'; case 'checkbox': return 'checkbox'; break; case 'radio': return 'radio'; break; default: // Here we return false because all text-based // fields should be included in the first switch case. return false; } } else if ($tagname == 'select') { // Select tag. return 'select'; } // We can not provide a closer field type. return false; }
php
public static function guess_field_type(NodeElement $fieldnode, Session $session) { // Textareas are considered text based elements. $tagname = strtolower($fieldnode->getTagName()); if ($tagname == 'textarea') { // If there is an iframe with $id + _ifr there a TinyMCE editor loaded. $xpath = '//div[@id="' . $fieldnode->getAttribute('id') . 'editable"]'; if ($session->getPage()->find('xpath', $xpath)) { return 'editor'; } return 'textarea'; } else if ($tagname == 'input') { $type = $fieldnode->getAttribute('type'); switch ($type) { case 'text': case 'password': case 'email': case 'file': return 'text'; case 'checkbox': return 'checkbox'; break; case 'radio': return 'radio'; break; default: // Here we return false because all text-based // fields should be included in the first switch case. return false; } } else if ($tagname == 'select') { // Select tag. return 'select'; } // We can not provide a closer field type. return false; }
[ "public", "static", "function", "guess_field_type", "(", "NodeElement", "$", "fieldnode", ",", "Session", "$", "session", ")", "{", "// Textareas are considered text based elements.", "$", "tagname", "=", "strtolower", "(", "$", "fieldnode", "->", "getTagName", "(", ")", ")", ";", "if", "(", "$", "tagname", "==", "'textarea'", ")", "{", "// If there is an iframe with $id + _ifr there a TinyMCE editor loaded.", "$", "xpath", "=", "'//div[@id=\"'", ".", "$", "fieldnode", "->", "getAttribute", "(", "'id'", ")", ".", "'editable\"]'", ";", "if", "(", "$", "session", "->", "getPage", "(", ")", "->", "find", "(", "'xpath'", ",", "$", "xpath", ")", ")", "{", "return", "'editor'", ";", "}", "return", "'textarea'", ";", "}", "else", "if", "(", "$", "tagname", "==", "'input'", ")", "{", "$", "type", "=", "$", "fieldnode", "->", "getAttribute", "(", "'type'", ")", ";", "switch", "(", "$", "type", ")", "{", "case", "'text'", ":", "case", "'password'", ":", "case", "'email'", ":", "case", "'file'", ":", "return", "'text'", ";", "case", "'checkbox'", ":", "return", "'checkbox'", ";", "break", ";", "case", "'radio'", ":", "return", "'radio'", ";", "break", ";", "default", ":", "// Here we return false because all text-based", "// fields should be included in the first switch case.", "return", "false", ";", "}", "}", "else", "if", "(", "$", "tagname", "==", "'select'", ")", "{", "// Select tag.", "return", "'select'", ";", "}", "// We can not provide a closer field type.", "return", "false", ";", "}" ]
Guesses a basic field type and returns it. This method is intended to detect HTML form fields when no moodleform-specific elements have been detected. @param NodeElement $fieldnode @param Session $session @return string|bool The field type or false.
[ "Guesses", "a", "basic", "field", "type", "and", "returns", "it", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/behat_field_manager.php#L139-L179
217,602
moodle/moodle
notes/edit_form.php
note_edit_form.definition
public function definition() { $mform =& $this->_form; $mform->addElement('header', 'general', get_string('note', 'notes')); $mform->addElement('textarea', 'content', get_string('content', 'notes'), array('rows' => 15, 'cols' => 40)); $mform->setType('content', PARAM_RAW); $mform->addRule('content', get_string('nocontent', 'notes'), 'required', null, 'client'); $mform->setForceLtr('content', false); $mform->addElement('select', 'publishstate', get_string('publishstate', 'notes'), note_get_state_names()); $mform->setDefault('publishstate', NOTES_STATE_PUBLIC); $mform->setType('publishstate', PARAM_ALPHA); $mform->addHelpButton('publishstate', 'publishstate', 'notes'); $this->add_action_buttons(); $mform->addElement('hidden', 'courseid'); $mform->setType('courseid', PARAM_INT); $mform->addElement('hidden', 'userid'); $mform->setType('userid', PARAM_INT); $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); }
php
public function definition() { $mform =& $this->_form; $mform->addElement('header', 'general', get_string('note', 'notes')); $mform->addElement('textarea', 'content', get_string('content', 'notes'), array('rows' => 15, 'cols' => 40)); $mform->setType('content', PARAM_RAW); $mform->addRule('content', get_string('nocontent', 'notes'), 'required', null, 'client'); $mform->setForceLtr('content', false); $mform->addElement('select', 'publishstate', get_string('publishstate', 'notes'), note_get_state_names()); $mform->setDefault('publishstate', NOTES_STATE_PUBLIC); $mform->setType('publishstate', PARAM_ALPHA); $mform->addHelpButton('publishstate', 'publishstate', 'notes'); $this->add_action_buttons(); $mform->addElement('hidden', 'courseid'); $mform->setType('courseid', PARAM_INT); $mform->addElement('hidden', 'userid'); $mform->setType('userid', PARAM_INT); $mform->addElement('hidden', 'id'); $mform->setType('id', PARAM_INT); }
[ "public", "function", "definition", "(", ")", "{", "$", "mform", "=", "&", "$", "this", "->", "_form", ";", "$", "mform", "->", "addElement", "(", "'header'", ",", "'general'", ",", "get_string", "(", "'note'", ",", "'notes'", ")", ")", ";", "$", "mform", "->", "addElement", "(", "'textarea'", ",", "'content'", ",", "get_string", "(", "'content'", ",", "'notes'", ")", ",", "array", "(", "'rows'", "=>", "15", ",", "'cols'", "=>", "40", ")", ")", ";", "$", "mform", "->", "setType", "(", "'content'", ",", "PARAM_RAW", ")", ";", "$", "mform", "->", "addRule", "(", "'content'", ",", "get_string", "(", "'nocontent'", ",", "'notes'", ")", ",", "'required'", ",", "null", ",", "'client'", ")", ";", "$", "mform", "->", "setForceLtr", "(", "'content'", ",", "false", ")", ";", "$", "mform", "->", "addElement", "(", "'select'", ",", "'publishstate'", ",", "get_string", "(", "'publishstate'", ",", "'notes'", ")", ",", "note_get_state_names", "(", ")", ")", ";", "$", "mform", "->", "setDefault", "(", "'publishstate'", ",", "NOTES_STATE_PUBLIC", ")", ";", "$", "mform", "->", "setType", "(", "'publishstate'", ",", "PARAM_ALPHA", ")", ";", "$", "mform", "->", "addHelpButton", "(", "'publishstate'", ",", "'publishstate'", ",", "'notes'", ")", ";", "$", "this", "->", "add_action_buttons", "(", ")", ";", "$", "mform", "->", "addElement", "(", "'hidden'", ",", "'courseid'", ")", ";", "$", "mform", "->", "setType", "(", "'courseid'", ",", "PARAM_INT", ")", ";", "$", "mform", "->", "addElement", "(", "'hidden'", ",", "'userid'", ")", ";", "$", "mform", "->", "setType", "(", "'userid'", ",", "PARAM_INT", ")", ";", "$", "mform", "->", "addElement", "(", "'hidden'", ",", "'id'", ")", ";", "$", "mform", "->", "setType", "(", "'id'", ",", "PARAM_INT", ")", ";", "}" ]
Define the form for editing notes
[ "Define", "the", "form", "for", "editing", "notes" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/notes/edit_form.php#L28-L52
217,603
moodle/moodle
tag/classes/tag.php
core_tag_tag.make_display_name
public static function make_display_name($tag, $ashtml = true) { global $CFG; if (empty($CFG->keeptagnamecase)) { // This is the normalized tag name. $tagname = core_text::strtotitle($tag->name); } else { // Original casing of the tag name. $tagname = $tag->rawname; } // Clean up a bit just in case the rules change again. $tagname = clean_param($tagname, PARAM_TAG); return $ashtml ? htmlspecialchars($tagname) : $tagname; }
php
public static function make_display_name($tag, $ashtml = true) { global $CFG; if (empty($CFG->keeptagnamecase)) { // This is the normalized tag name. $tagname = core_text::strtotitle($tag->name); } else { // Original casing of the tag name. $tagname = $tag->rawname; } // Clean up a bit just in case the rules change again. $tagname = clean_param($tagname, PARAM_TAG); return $ashtml ? htmlspecialchars($tagname) : $tagname; }
[ "public", "static", "function", "make_display_name", "(", "$", "tag", ",", "$", "ashtml", "=", "true", ")", "{", "global", "$", "CFG", ";", "if", "(", "empty", "(", "$", "CFG", "->", "keeptagnamecase", ")", ")", "{", "// This is the normalized tag name.", "$", "tagname", "=", "core_text", "::", "strtotitle", "(", "$", "tag", "->", "name", ")", ";", "}", "else", "{", "// Original casing of the tag name.", "$", "tagname", "=", "$", "tag", "->", "rawname", ";", "}", "// Clean up a bit just in case the rules change again.", "$", "tagname", "=", "clean_param", "(", "$", "tagname", ",", "PARAM_TAG", ")", ";", "return", "$", "ashtml", "?", "htmlspecialchars", "(", "$", "tagname", ")", ":", "$", "tagname", ";", "}" ]
Prepares tag name ready to be displayed @param stdClass|core_tag_tag $tag record from db table tag, must contain properties name and rawname @param bool $ashtml (default true) if true will return htmlspecialchars encoded string @return string
[ "Prepares", "tag", "name", "ready", "to", "be", "displayed" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L135-L150
217,604
moodle/moodle
tag/classes/tag.php
core_tag_tag.get
public static function get($id, $returnfields = 'id, name, rawname, tagcollid', $strictness = IGNORE_MISSING) { global $DB; $record = $DB->get_record('tag', array('id' => $id), $returnfields, $strictness); if ($record) { return new static($record); } return false; }
php
public static function get($id, $returnfields = 'id, name, rawname, tagcollid', $strictness = IGNORE_MISSING) { global $DB; $record = $DB->get_record('tag', array('id' => $id), $returnfields, $strictness); if ($record) { return new static($record); } return false; }
[ "public", "static", "function", "get", "(", "$", "id", ",", "$", "returnfields", "=", "'id, name, rawname, tagcollid'", ",", "$", "strictness", "=", "IGNORE_MISSING", ")", "{", "global", "$", "DB", ";", "$", "record", "=", "$", "DB", "->", "get_record", "(", "'tag'", ",", "array", "(", "'id'", "=>", "$", "id", ")", ",", "$", "returnfields", ",", "$", "strictness", ")", ";", "if", "(", "$", "record", ")", "{", "return", "new", "static", "(", "$", "record", ")", ";", "}", "return", "false", ";", "}" ]
Simple function to just return a single tag object by its id @param int $id @param string $returnfields which fields do we want returned from table {tag}. Default value is 'id,name,rawname,tagcollid', specify '*' to include all fields. @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended); MUST_EXIST means throw exception if no record or multiple records found @return core_tag_tag|false tag object
[ "Simple", "function", "to", "just", "return", "a", "single", "tag", "object", "by", "its", "id" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L202-L209
217,605
moodle/moodle
tag/classes/tag.php
core_tag_tag.get_bulk
public static function get_bulk($ids, $returnfields = 'id, name, rawname, tagcollid') { global $DB; $result = array(); if (empty($ids)) { return $result; } list($sql, $params) = $DB->get_in_or_equal($ids); $records = $DB->get_records_select('tag', 'id '.$sql, $params, '', $returnfields); foreach ($records as $record) { $result[$record->id] = new static($record); } return $result; }
php
public static function get_bulk($ids, $returnfields = 'id, name, rawname, tagcollid') { global $DB; $result = array(); if (empty($ids)) { return $result; } list($sql, $params) = $DB->get_in_or_equal($ids); $records = $DB->get_records_select('tag', 'id '.$sql, $params, '', $returnfields); foreach ($records as $record) { $result[$record->id] = new static($record); } return $result; }
[ "public", "static", "function", "get_bulk", "(", "$", "ids", ",", "$", "returnfields", "=", "'id, name, rawname, tagcollid'", ")", "{", "global", "$", "DB", ";", "$", "result", "=", "array", "(", ")", ";", "if", "(", "empty", "(", "$", "ids", ")", ")", "{", "return", "$", "result", ";", "}", "list", "(", "$", "sql", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "ids", ")", ";", "$", "records", "=", "$", "DB", "->", "get_records_select", "(", "'tag'", ",", "'id '", ".", "$", "sql", ",", "$", "params", ",", "''", ",", "$", "returnfields", ")", ";", "foreach", "(", "$", "records", "as", "$", "record", ")", "{", "$", "result", "[", "$", "record", "->", "id", "]", "=", "new", "static", "(", "$", "record", ")", ";", "}", "return", "$", "result", ";", "}" ]
Simple function to just return an array of tag objects by their ids @param int[] $ids @param string $returnfields which fields do we want returned from table {tag}. Default value is 'id,name,rawname,tagcollid', specify '*' to include all fields. @return core_tag_tag[] array of retrieved tags
[ "Simple", "function", "to", "just", "return", "an", "array", "of", "tag", "objects", "by", "their", "ids" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L220-L232
217,606
moodle/moodle
tag/classes/tag.php
core_tag_tag.get_by_name
public static function get_by_name($tagcollid, $name, $returnfields='id, name, rawname, tagcollid', $strictness = IGNORE_MISSING) { global $DB; if ($tagcollid == 0) { $tags = static::guess_by_name($name, $returnfields); if ($tags) { $tag = reset($tags); return $tag; } else if ($strictness == MUST_EXIST) { throw new dml_missing_record_exception('tag', 'name=?', array($name)); } return false; } $name = core_text::strtolower($name); // To cope with input that might just be wrong case. $params = array('name' => $name, 'tagcollid' => $tagcollid); $record = $DB->get_record('tag', $params, $returnfields, $strictness); if ($record) { return new static($record); } return false; }
php
public static function get_by_name($tagcollid, $name, $returnfields='id, name, rawname, tagcollid', $strictness = IGNORE_MISSING) { global $DB; if ($tagcollid == 0) { $tags = static::guess_by_name($name, $returnfields); if ($tags) { $tag = reset($tags); return $tag; } else if ($strictness == MUST_EXIST) { throw new dml_missing_record_exception('tag', 'name=?', array($name)); } return false; } $name = core_text::strtolower($name); // To cope with input that might just be wrong case. $params = array('name' => $name, 'tagcollid' => $tagcollid); $record = $DB->get_record('tag', $params, $returnfields, $strictness); if ($record) { return new static($record); } return false; }
[ "public", "static", "function", "get_by_name", "(", "$", "tagcollid", ",", "$", "name", ",", "$", "returnfields", "=", "'id, name, rawname, tagcollid'", ",", "$", "strictness", "=", "IGNORE_MISSING", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "tagcollid", "==", "0", ")", "{", "$", "tags", "=", "static", "::", "guess_by_name", "(", "$", "name", ",", "$", "returnfields", ")", ";", "if", "(", "$", "tags", ")", "{", "$", "tag", "=", "reset", "(", "$", "tags", ")", ";", "return", "$", "tag", ";", "}", "else", "if", "(", "$", "strictness", "==", "MUST_EXIST", ")", "{", "throw", "new", "dml_missing_record_exception", "(", "'tag'", ",", "'name=?'", ",", "array", "(", "$", "name", ")", ")", ";", "}", "return", "false", ";", "}", "$", "name", "=", "core_text", "::", "strtolower", "(", "$", "name", ")", ";", "// To cope with input that might just be wrong case.", "$", "params", "=", "array", "(", "'name'", "=>", "$", "name", ",", "'tagcollid'", "=>", "$", "tagcollid", ")", ";", "$", "record", "=", "$", "DB", "->", "get_record", "(", "'tag'", ",", "$", "params", ",", "$", "returnfields", ",", "$", "strictness", ")", ";", "if", "(", "$", "record", ")", "{", "return", "new", "static", "(", "$", "record", ")", ";", "}", "return", "false", ";", "}" ]
Simple function to just return a single tag object by tagcollid and name @param int $tagcollid tag collection to use, if 0 is given we will try to guess the tag collection and return the first match @param string $name tag name @param string $returnfields which fields do we want returned. This is a comma separated string containing any combination of 'id', 'name', 'rawname', 'tagcollid' or '*' to include all fields. @param int $strictness IGNORE_MISSING means compatible mode, false returned if record not found, debug message if more found; IGNORE_MULTIPLE means return first, ignore multiple records found(not recommended); MUST_EXIST means throw exception if no record or multiple records found @return core_tag_tag|false tag object
[ "Simple", "function", "to", "just", "return", "a", "single", "tag", "object", "by", "tagcollid", "and", "name" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L247-L267
217,607
moodle/moodle
tag/classes/tag.php
core_tag_tag.guess_by_name
public static function guess_by_name($name, $returnfields='id, name, rawname, tagcollid') { global $DB; if (empty($name)) { return array(); } $tagcolls = core_tag_collection::get_collections(); list($sql, $params) = $DB->get_in_or_equal(array_keys($tagcolls), SQL_PARAMS_NAMED); $params['name'] = core_text::strtolower($name); $tags = $DB->get_records_select('tag', 'name = :name AND tagcollid ' . $sql, $params, '', $returnfields); if (count($tags) > 1) { // Sort in the same order as tag collections. $tagcolls = core_tag_collection::get_collections(); uasort($tags, function($a, $b) use ($tagcolls) { return $tagcolls[$a->tagcollid]->sortorder < $tagcolls[$b->tagcollid]->sortorder ? -1 : 1; }); } $rv = array(); foreach ($tags as $id => $tag) { $rv[$id] = new static($tag); } return $rv; }
php
public static function guess_by_name($name, $returnfields='id, name, rawname, tagcollid') { global $DB; if (empty($name)) { return array(); } $tagcolls = core_tag_collection::get_collections(); list($sql, $params) = $DB->get_in_or_equal(array_keys($tagcolls), SQL_PARAMS_NAMED); $params['name'] = core_text::strtolower($name); $tags = $DB->get_records_select('tag', 'name = :name AND tagcollid ' . $sql, $params, '', $returnfields); if (count($tags) > 1) { // Sort in the same order as tag collections. $tagcolls = core_tag_collection::get_collections(); uasort($tags, function($a, $b) use ($tagcolls) { return $tagcolls[$a->tagcollid]->sortorder < $tagcolls[$b->tagcollid]->sortorder ? -1 : 1; }); } $rv = array(); foreach ($tags as $id => $tag) { $rv[$id] = new static($tag); } return $rv; }
[ "public", "static", "function", "guess_by_name", "(", "$", "name", ",", "$", "returnfields", "=", "'id, name, rawname, tagcollid'", ")", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "name", ")", ")", "{", "return", "array", "(", ")", ";", "}", "$", "tagcolls", "=", "core_tag_collection", "::", "get_collections", "(", ")", ";", "list", "(", "$", "sql", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "array_keys", "(", "$", "tagcolls", ")", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "params", "[", "'name'", "]", "=", "core_text", "::", "strtolower", "(", "$", "name", ")", ";", "$", "tags", "=", "$", "DB", "->", "get_records_select", "(", "'tag'", ",", "'name = :name AND tagcollid '", ".", "$", "sql", ",", "$", "params", ",", "''", ",", "$", "returnfields", ")", ";", "if", "(", "count", "(", "$", "tags", ")", ">", "1", ")", "{", "// Sort in the same order as tag collections.", "$", "tagcolls", "=", "core_tag_collection", "::", "get_collections", "(", ")", ";", "uasort", "(", "$", "tags", ",", "function", "(", "$", "a", ",", "$", "b", ")", "use", "(", "$", "tagcolls", ")", "{", "return", "$", "tagcolls", "[", "$", "a", "->", "tagcollid", "]", "->", "sortorder", "<", "$", "tagcolls", "[", "$", "b", "->", "tagcollid", "]", "->", "sortorder", "?", "-", "1", ":", "1", ";", "}", ")", ";", "}", "$", "rv", "=", "array", "(", ")", ";", "foreach", "(", "$", "tags", "as", "$", "id", "=>", "$", "tag", ")", "{", "$", "rv", "[", "$", "id", "]", "=", "new", "static", "(", "$", "tag", ")", ";", "}", "return", "$", "rv", ";", "}" ]
Looking in all tag collections for the tag with the given name @param string $name tag name @param string $returnfields @return array array of core_tag_tag instances
[ "Looking", "in", "all", "tag", "collections", "for", "the", "tag", "with", "the", "given", "name" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L276-L297
217,608
moodle/moodle
tag/classes/tag.php
core_tag_tag.get_by_name_bulk
public static function get_by_name_bulk($tagcollid, $tags, $returnfields = 'id, name, rawname, tagcollid') { global $DB; if (empty($tags)) { return array(); } $cleantags = self::normalize(self::normalize($tags, false)); // Format: rawname => normalised name. list($namesql, $params) = $DB->get_in_or_equal(array_values($cleantags)); array_unshift($params, $tagcollid); $recordset = $DB->get_recordset_sql("SELECT $returnfields FROM {tag} WHERE tagcollid = ? AND name $namesql", $params); $result = array_fill_keys($cleantags, null); foreach ($recordset as $record) { $result[$record->name] = new static($record); } $recordset->close(); return $result; }
php
public static function get_by_name_bulk($tagcollid, $tags, $returnfields = 'id, name, rawname, tagcollid') { global $DB; if (empty($tags)) { return array(); } $cleantags = self::normalize(self::normalize($tags, false)); // Format: rawname => normalised name. list($namesql, $params) = $DB->get_in_or_equal(array_values($cleantags)); array_unshift($params, $tagcollid); $recordset = $DB->get_recordset_sql("SELECT $returnfields FROM {tag} WHERE tagcollid = ? AND name $namesql", $params); $result = array_fill_keys($cleantags, null); foreach ($recordset as $record) { $result[$record->name] = new static($record); } $recordset->close(); return $result; }
[ "public", "static", "function", "get_by_name_bulk", "(", "$", "tagcollid", ",", "$", "tags", ",", "$", "returnfields", "=", "'id, name, rawname, tagcollid'", ")", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "tags", ")", ")", "{", "return", "array", "(", ")", ";", "}", "$", "cleantags", "=", "self", "::", "normalize", "(", "self", "::", "normalize", "(", "$", "tags", ",", "false", ")", ")", ";", "// Format: rawname => normalised name.", "list", "(", "$", "namesql", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "array_values", "(", "$", "cleantags", ")", ")", ";", "array_unshift", "(", "$", "params", ",", "$", "tagcollid", ")", ";", "$", "recordset", "=", "$", "DB", "->", "get_recordset_sql", "(", "\"SELECT $returnfields FROM {tag} WHERE tagcollid = ? AND name $namesql\"", ",", "$", "params", ")", ";", "$", "result", "=", "array_fill_keys", "(", "$", "cleantags", ",", "null", ")", ";", "foreach", "(", "$", "recordset", "as", "$", "record", ")", "{", "$", "result", "[", "$", "record", "->", "name", "]", "=", "new", "static", "(", "$", "record", ")", ";", "}", "$", "recordset", "->", "close", "(", ")", ";", "return", "$", "result", ";", "}" ]
Returns the list of tag objects by tag collection id and the list of tag names @param int $tagcollid @param array $tags array of tags to look for @param string $returnfields list of DB fields to return, must contain 'id', 'name' and 'rawname' @return array tag-indexed array of objects. No value for a key means the tag wasn't found.
[ "Returns", "the", "list", "of", "tag", "objects", "by", "tag", "collection", "id", "and", "the", "list", "of", "tag", "names" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L307-L327
217,609
moodle/moodle
tag/classes/tag.php
core_tag_tag.normalize
public static function normalize($rawtags, $tolowercase = true) { $result = array(); foreach ($rawtags as $rawtag) { $rawtag = trim($rawtag); if (strval($rawtag) !== '') { $clean = clean_param($rawtag, PARAM_TAG); if ($tolowercase) { $result[$rawtag] = core_text::strtolower($clean); } else { $result[$rawtag] = $clean; } } } return $result; }
php
public static function normalize($rawtags, $tolowercase = true) { $result = array(); foreach ($rawtags as $rawtag) { $rawtag = trim($rawtag); if (strval($rawtag) !== '') { $clean = clean_param($rawtag, PARAM_TAG); if ($tolowercase) { $result[$rawtag] = core_text::strtolower($clean); } else { $result[$rawtag] = $clean; } } } return $result; }
[ "public", "static", "function", "normalize", "(", "$", "rawtags", ",", "$", "tolowercase", "=", "true", ")", "{", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "rawtags", "as", "$", "rawtag", ")", "{", "$", "rawtag", "=", "trim", "(", "$", "rawtag", ")", ";", "if", "(", "strval", "(", "$", "rawtag", ")", "!==", "''", ")", "{", "$", "clean", "=", "clean_param", "(", "$", "rawtag", ",", "PARAM_TAG", ")", ";", "if", "(", "$", "tolowercase", ")", "{", "$", "result", "[", "$", "rawtag", "]", "=", "core_text", "::", "strtolower", "(", "$", "clean", ")", ";", "}", "else", "{", "$", "result", "[", "$", "rawtag", "]", "=", "$", "clean", ";", "}", "}", "}", "return", "$", "result", ";", "}" ]
Function that normalizes a list of tag names. @param array $rawtags array of tags @param bool $tolowercase convert to lower case? @return array lowercased normalized tags, indexed by the normalized tag, in the same order as the original array. (Eg: 'Banana' => 'banana').
[ "Function", "that", "normalizes", "a", "list", "of", "tag", "names", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L338-L352
217,610
moodle/moodle
tag/classes/tag.php
core_tag_tag.make_url
public static function make_url($tagcollid, $name, $exclusivemode = 0, $fromctx = 0, $ctx = 0, $rec = 1) { $coll = core_tag_collection::get_by_id($tagcollid); if (!empty($coll->customurl)) { $url = '/' . ltrim(trim($coll->customurl), '/'); } else { $url = '/tag/index.php'; } $params = array('tc' => $tagcollid, 'tag' => $name); if ($exclusivemode) { $params['excl'] = 1; } if ($fromctx) { $params['from'] = $fromctx; } if ($ctx) { $params['ctx'] = $ctx; } if (!$rec) { $params['rec'] = 0; } return new moodle_url($url, $params); }
php
public static function make_url($tagcollid, $name, $exclusivemode = 0, $fromctx = 0, $ctx = 0, $rec = 1) { $coll = core_tag_collection::get_by_id($tagcollid); if (!empty($coll->customurl)) { $url = '/' . ltrim(trim($coll->customurl), '/'); } else { $url = '/tag/index.php'; } $params = array('tc' => $tagcollid, 'tag' => $name); if ($exclusivemode) { $params['excl'] = 1; } if ($fromctx) { $params['from'] = $fromctx; } if ($ctx) { $params['ctx'] = $ctx; } if (!$rec) { $params['rec'] = 0; } return new moodle_url($url, $params); }
[ "public", "static", "function", "make_url", "(", "$", "tagcollid", ",", "$", "name", ",", "$", "exclusivemode", "=", "0", ",", "$", "fromctx", "=", "0", ",", "$", "ctx", "=", "0", ",", "$", "rec", "=", "1", ")", "{", "$", "coll", "=", "core_tag_collection", "::", "get_by_id", "(", "$", "tagcollid", ")", ";", "if", "(", "!", "empty", "(", "$", "coll", "->", "customurl", ")", ")", "{", "$", "url", "=", "'/'", ".", "ltrim", "(", "trim", "(", "$", "coll", "->", "customurl", ")", ",", "'/'", ")", ";", "}", "else", "{", "$", "url", "=", "'/tag/index.php'", ";", "}", "$", "params", "=", "array", "(", "'tc'", "=>", "$", "tagcollid", ",", "'tag'", "=>", "$", "name", ")", ";", "if", "(", "$", "exclusivemode", ")", "{", "$", "params", "[", "'excl'", "]", "=", "1", ";", "}", "if", "(", "$", "fromctx", ")", "{", "$", "params", "[", "'from'", "]", "=", "$", "fromctx", ";", "}", "if", "(", "$", "ctx", ")", "{", "$", "params", "[", "'ctx'", "]", "=", "$", "ctx", ";", "}", "if", "(", "!", "$", "rec", ")", "{", "$", "params", "[", "'rec'", "]", "=", "0", ";", "}", "return", "new", "moodle_url", "(", "$", "url", ",", "$", "params", ")", ";", "}" ]
Creates a URL to view a tag @param int $tagcollid @param string $name @param int $exclusivemode @param int $fromctx context id where this tag cloud is displayed @param int $ctx context id for tag view link @param int $rec recursive argument for tag view link @return \moodle_url
[ "Creates", "a", "URL", "to", "view", "a", "tag" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L388-L409
217,611
moodle/moodle
tag/classes/tag.php
core_tag_tag.get_view_url
public function get_view_url($exclusivemode = 0, $fromctx = 0, $ctx = 0, $rec = 1) { return static::make_url($this->record->tagcollid, $this->record->rawname, $exclusivemode, $fromctx, $ctx, $rec); }
php
public function get_view_url($exclusivemode = 0, $fromctx = 0, $ctx = 0, $rec = 1) { return static::make_url($this->record->tagcollid, $this->record->rawname, $exclusivemode, $fromctx, $ctx, $rec); }
[ "public", "function", "get_view_url", "(", "$", "exclusivemode", "=", "0", ",", "$", "fromctx", "=", "0", ",", "$", "ctx", "=", "0", ",", "$", "rec", "=", "1", ")", "{", "return", "static", "::", "make_url", "(", "$", "this", "->", "record", "->", "tagcollid", ",", "$", "this", "->", "record", "->", "rawname", ",", "$", "exclusivemode", ",", "$", "fromctx", ",", "$", "ctx", ",", "$", "rec", ")", ";", "}" ]
Returns URL to view the tag @param int $exclusivemode @param int $fromctx context id where this tag cloud is displayed @param int $ctx context id for tag view link @param int $rec recursive argument for tag view link @return \moodle_url
[ "Returns", "URL", "to", "view", "the", "tag" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L420-L423
217,612
moodle/moodle
tag/classes/tag.php
core_tag_tag.ensure_fields_exist
protected function ensure_fields_exist($list, $caller) { global $DB; $missing = array_diff($list, array_keys((array)$this->record)); if ($missing) { debugging('core_tag_tag::' . $caller . '() must be called on fully retrieved tag object. Missing fields: '. join(', ', $missing), DEBUG_DEVELOPER); $this->record = $DB->get_record('tag', array('id' => $this->record->id), '*', MUST_EXIST); } }
php
protected function ensure_fields_exist($list, $caller) { global $DB; $missing = array_diff($list, array_keys((array)$this->record)); if ($missing) { debugging('core_tag_tag::' . $caller . '() must be called on fully retrieved tag object. Missing fields: '. join(', ', $missing), DEBUG_DEVELOPER); $this->record = $DB->get_record('tag', array('id' => $this->record->id), '*', MUST_EXIST); } }
[ "protected", "function", "ensure_fields_exist", "(", "$", "list", ",", "$", "caller", ")", "{", "global", "$", "DB", ";", "$", "missing", "=", "array_diff", "(", "$", "list", ",", "array_keys", "(", "(", "array", ")", "$", "this", "->", "record", ")", ")", ";", "if", "(", "$", "missing", ")", "{", "debugging", "(", "'core_tag_tag::'", ".", "$", "caller", ".", "'() must be called on fully retrieved tag object. Missing fields: '", ".", "join", "(", "', '", ",", "$", "missing", ")", ",", "DEBUG_DEVELOPER", ")", ";", "$", "this", "->", "record", "=", "$", "DB", "->", "get_record", "(", "'tag'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "record", "->", "id", ")", ",", "'*'", ",", "MUST_EXIST", ")", ";", "}", "}" ]
Validates that the required fields were retrieved and retrieves them if missing @param array $list array of the fields that need to be validated @param string $caller name of the function that requested it, for the debugging message
[ "Validates", "that", "the", "required", "fields", "were", "retrieved", "and", "retrieves", "them", "if", "missing" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L431-L439
217,613
moodle/moodle
tag/classes/tag.php
core_tag_tag.delete_instance_as_record
protected function delete_instance_as_record($taginstance, $fullobject = false) { global $DB; $this->ensure_fields_exist(array('name', 'rawname', 'isstandard'), 'delete_instance_as_record'); $DB->delete_records('tag_instance', array('id' => $taginstance->id)); // We can not fire an event with 'null' as the contextid. if (is_null($taginstance->contextid)) { $taginstance->contextid = context_system::instance()->id; } // Trigger tag removed event. $taginstance->tagid = $this->id; \core\event\tag_removed::create_from_tag_instance($taginstance, $this->name, $this->rawname, $fullobject)->trigger(); // If there are no other instances of the tag then consider deleting the tag as well. if (!$this->isstandard) { if (!$DB->record_exists('tag_instance', array('tagid' => $this->id))) { self::delete_tags($this->id); } } return true; }
php
protected function delete_instance_as_record($taginstance, $fullobject = false) { global $DB; $this->ensure_fields_exist(array('name', 'rawname', 'isstandard'), 'delete_instance_as_record'); $DB->delete_records('tag_instance', array('id' => $taginstance->id)); // We can not fire an event with 'null' as the contextid. if (is_null($taginstance->contextid)) { $taginstance->contextid = context_system::instance()->id; } // Trigger tag removed event. $taginstance->tagid = $this->id; \core\event\tag_removed::create_from_tag_instance($taginstance, $this->name, $this->rawname, $fullobject)->trigger(); // If there are no other instances of the tag then consider deleting the tag as well. if (!$this->isstandard) { if (!$DB->record_exists('tag_instance', array('tagid' => $this->id))) { self::delete_tags($this->id); } } return true; }
[ "protected", "function", "delete_instance_as_record", "(", "$", "taginstance", ",", "$", "fullobject", "=", "false", ")", "{", "global", "$", "DB", ";", "$", "this", "->", "ensure_fields_exist", "(", "array", "(", "'name'", ",", "'rawname'", ",", "'isstandard'", ")", ",", "'delete_instance_as_record'", ")", ";", "$", "DB", "->", "delete_records", "(", "'tag_instance'", ",", "array", "(", "'id'", "=>", "$", "taginstance", "->", "id", ")", ")", ";", "// We can not fire an event with 'null' as the contextid.", "if", "(", "is_null", "(", "$", "taginstance", "->", "contextid", ")", ")", "{", "$", "taginstance", "->", "contextid", "=", "context_system", "::", "instance", "(", ")", "->", "id", ";", "}", "// Trigger tag removed event.", "$", "taginstance", "->", "tagid", "=", "$", "this", "->", "id", ";", "\\", "core", "\\", "event", "\\", "tag_removed", "::", "create_from_tag_instance", "(", "$", "taginstance", ",", "$", "this", "->", "name", ",", "$", "this", "->", "rawname", ",", "$", "fullobject", ")", "->", "trigger", "(", ")", ";", "// If there are no other instances of the tag then consider deleting the tag as well.", "if", "(", "!", "$", "this", "->", "isstandard", ")", "{", "if", "(", "!", "$", "DB", "->", "record_exists", "(", "'tag_instance'", ",", "array", "(", "'tagid'", "=>", "$", "this", "->", "id", ")", ")", ")", "{", "self", "::", "delete_tags", "(", "$", "this", "->", "id", ")", ";", "}", "}", "return", "true", ";", "}" ]
Deletes the tag instance given the record from tag_instance DB table @param stdClass $taginstance @param bool $fullobject whether $taginstance contains all fields from DB table tag_instance (in this case it is safe to add a record snapshot to the event) @return bool
[ "Deletes", "the", "tag", "instance", "given", "the", "record", "from", "tag_instance", "DB", "table" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L449-L473
217,614
moodle/moodle
tag/classes/tag.php
core_tag_tag.delete_instance
protected function delete_instance($component, $itemtype, $itemid, $tiuserid = 0) { global $DB; $params = array('tagid' => $this->id, 'itemtype' => $itemtype, 'itemid' => $itemid); if ($tiuserid) { $params['tiuserid'] = $tiuserid; } if ($component) { $params['component'] = $component; } $taginstance = $DB->get_record('tag_instance', $params); if (!$taginstance) { return; } $this->delete_instance_as_record($taginstance, true); }
php
protected function delete_instance($component, $itemtype, $itemid, $tiuserid = 0) { global $DB; $params = array('tagid' => $this->id, 'itemtype' => $itemtype, 'itemid' => $itemid); if ($tiuserid) { $params['tiuserid'] = $tiuserid; } if ($component) { $params['component'] = $component; } $taginstance = $DB->get_record('tag_instance', $params); if (!$taginstance) { return; } $this->delete_instance_as_record($taginstance, true); }
[ "protected", "function", "delete_instance", "(", "$", "component", ",", "$", "itemtype", ",", "$", "itemid", ",", "$", "tiuserid", "=", "0", ")", "{", "global", "$", "DB", ";", "$", "params", "=", "array", "(", "'tagid'", "=>", "$", "this", "->", "id", ",", "'itemtype'", "=>", "$", "itemtype", ",", "'itemid'", "=>", "$", "itemid", ")", ";", "if", "(", "$", "tiuserid", ")", "{", "$", "params", "[", "'tiuserid'", "]", "=", "$", "tiuserid", ";", "}", "if", "(", "$", "component", ")", "{", "$", "params", "[", "'component'", "]", "=", "$", "component", ";", "}", "$", "taginstance", "=", "$", "DB", "->", "get_record", "(", "'tag_instance'", ",", "$", "params", ")", ";", "if", "(", "!", "$", "taginstance", ")", "{", "return", ";", "}", "$", "this", "->", "delete_instance_as_record", "(", "$", "taginstance", ",", "true", ")", ";", "}" ]
Delete one instance of a tag. If the last instance was deleted, it will also delete the tag, unless it is standard. @param string $component component responsible for tagging. For BC it can be empty but in this case the query will be slow because DB index will not be used. @param string $itemtype the type of the record for which to remove the instance @param int $itemid the id of the record for which to remove the instance @param int $tiuserid tag instance user id, only needed for tag areas with user tagging (such as core/course)
[ "Delete", "one", "instance", "of", "a", "tag", ".", "If", "the", "last", "instance", "was", "deleted", "it", "will", "also", "delete", "the", "tag", "unless", "it", "is", "standard", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L484-L500
217,615
moodle/moodle
tag/classes/tag.php
core_tag_tag.delete_instances_as_record
public static function delete_instances_as_record(array $taginstances) { global $DB; if (empty($taginstances)) { return; } $taginstanceids = array_map(function($taginstance) { return $taginstance->id; }, $taginstances); // Now remove all the tag instances. $DB->delete_records_list('tag_instance', 'id', $taginstanceids); // Save the system context in case the 'contextid' column in the 'tag_instance' table is null. $syscontextid = context_system::instance()->id; // Loop through the tag instances and fire an 'tag_removed' event. foreach ($taginstances as $taginstance) { // We can not fire an event with 'null' as the contextid. if (is_null($taginstance->contextid)) { $taginstance->contextid = $syscontextid; } // Trigger tag removed event. \core\event\tag_removed::create_from_tag_instance($taginstance, $taginstance->name, $taginstance->rawname, true)->trigger(); } }
php
public static function delete_instances_as_record(array $taginstances) { global $DB; if (empty($taginstances)) { return; } $taginstanceids = array_map(function($taginstance) { return $taginstance->id; }, $taginstances); // Now remove all the tag instances. $DB->delete_records_list('tag_instance', 'id', $taginstanceids); // Save the system context in case the 'contextid' column in the 'tag_instance' table is null. $syscontextid = context_system::instance()->id; // Loop through the tag instances and fire an 'tag_removed' event. foreach ($taginstances as $taginstance) { // We can not fire an event with 'null' as the contextid. if (is_null($taginstance->contextid)) { $taginstance->contextid = $syscontextid; } // Trigger tag removed event. \core\event\tag_removed::create_from_tag_instance($taginstance, $taginstance->name, $taginstance->rawname, true)->trigger(); } }
[ "public", "static", "function", "delete_instances_as_record", "(", "array", "$", "taginstances", ")", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "taginstances", ")", ")", "{", "return", ";", "}", "$", "taginstanceids", "=", "array_map", "(", "function", "(", "$", "taginstance", ")", "{", "return", "$", "taginstance", "->", "id", ";", "}", ",", "$", "taginstances", ")", ";", "// Now remove all the tag instances.", "$", "DB", "->", "delete_records_list", "(", "'tag_instance'", ",", "'id'", ",", "$", "taginstanceids", ")", ";", "// Save the system context in case the 'contextid' column in the 'tag_instance' table is null.", "$", "syscontextid", "=", "context_system", "::", "instance", "(", ")", "->", "id", ";", "// Loop through the tag instances and fire an 'tag_removed' event.", "foreach", "(", "$", "taginstances", "as", "$", "taginstance", ")", "{", "// We can not fire an event with 'null' as the contextid.", "if", "(", "is_null", "(", "$", "taginstance", "->", "contextid", ")", ")", "{", "$", "taginstance", "->", "contextid", "=", "$", "syscontextid", ";", "}", "// Trigger tag removed event.", "\\", "core", "\\", "event", "\\", "tag_removed", "::", "create_from_tag_instance", "(", "$", "taginstance", ",", "$", "taginstance", "->", "name", ",", "$", "taginstance", "->", "rawname", ",", "true", ")", "->", "trigger", "(", ")", ";", "}", "}" ]
Bulk delete all tag instances. @param stdClass[] $taginstances A list of tag_instance records to delete. Each record must also contain the name and rawname columns from the related tag record.
[ "Bulk", "delete", "all", "tag", "instances", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L509-L534
217,616
moodle/moodle
tag/classes/tag.php
core_tag_tag.delete_instances_by_id
public static function delete_instances_by_id(array $taginstanceids) { global $DB; if (empty($taginstanceids)) { return; } list($idsql, $params) = $DB->get_in_or_equal($taginstanceids); $sql = "SELECT ti.*, t.name, t.rawname, t.isstandard FROM {tag_instance} ti JOIN {tag} t ON ti.tagid = t.id WHERE ti.id {$idsql}"; if ($taginstances = $DB->get_records_sql($sql, $params)) { static::delete_instances_as_record($taginstances); } }
php
public static function delete_instances_by_id(array $taginstanceids) { global $DB; if (empty($taginstanceids)) { return; } list($idsql, $params) = $DB->get_in_or_equal($taginstanceids); $sql = "SELECT ti.*, t.name, t.rawname, t.isstandard FROM {tag_instance} ti JOIN {tag} t ON ti.tagid = t.id WHERE ti.id {$idsql}"; if ($taginstances = $DB->get_records_sql($sql, $params)) { static::delete_instances_as_record($taginstances); } }
[ "public", "static", "function", "delete_instances_by_id", "(", "array", "$", "taginstanceids", ")", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "taginstanceids", ")", ")", "{", "return", ";", "}", "list", "(", "$", "idsql", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "taginstanceids", ")", ";", "$", "sql", "=", "\"SELECT ti.*, t.name, t.rawname, t.isstandard\n FROM {tag_instance} ti\n JOIN {tag} t\n ON ti.tagid = t.id\n WHERE ti.id {$idsql}\"", ";", "if", "(", "$", "taginstances", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "$", "params", ")", ")", "{", "static", "::", "delete_instances_as_record", "(", "$", "taginstances", ")", ";", "}", "}" ]
Bulk delete all tag instances by tag id. @param int[] $taginstanceids List of tag instance ids to be deleted.
[ "Bulk", "delete", "all", "tag", "instances", "by", "tag", "id", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L541-L558
217,617
moodle/moodle
tag/classes/tag.php
core_tag_tag.delete_instances
public static function delete_instances($component, $itemtype = null, $contextid = null) { global $DB; $sql = "SELECT ti.*, t.name, t.rawname, t.isstandard FROM {tag_instance} ti JOIN {tag} t ON ti.tagid = t.id WHERE ti.component = :component"; $params = array('component' => $component); if (!is_null($contextid)) { $sql .= " AND ti.contextid = :contextid"; $params['contextid'] = $contextid; } if (!is_null($itemtype)) { $sql .= " AND ti.itemtype = :itemtype"; $params['itemtype'] = $itemtype; } if ($taginstances = $DB->get_records_sql($sql, $params)) { static::delete_instances_as_record($taginstances); } }
php
public static function delete_instances($component, $itemtype = null, $contextid = null) { global $DB; $sql = "SELECT ti.*, t.name, t.rawname, t.isstandard FROM {tag_instance} ti JOIN {tag} t ON ti.tagid = t.id WHERE ti.component = :component"; $params = array('component' => $component); if (!is_null($contextid)) { $sql .= " AND ti.contextid = :contextid"; $params['contextid'] = $contextid; } if (!is_null($itemtype)) { $sql .= " AND ti.itemtype = :itemtype"; $params['itemtype'] = $itemtype; } if ($taginstances = $DB->get_records_sql($sql, $params)) { static::delete_instances_as_record($taginstances); } }
[ "public", "static", "function", "delete_instances", "(", "$", "component", ",", "$", "itemtype", "=", "null", ",", "$", "contextid", "=", "null", ")", "{", "global", "$", "DB", ";", "$", "sql", "=", "\"SELECT ti.*, t.name, t.rawname, t.isstandard\n FROM {tag_instance} ti\n JOIN {tag} t\n ON ti.tagid = t.id\n WHERE ti.component = :component\"", ";", "$", "params", "=", "array", "(", "'component'", "=>", "$", "component", ")", ";", "if", "(", "!", "is_null", "(", "$", "contextid", ")", ")", "{", "$", "sql", ".=", "\" AND ti.contextid = :contextid\"", ";", "$", "params", "[", "'contextid'", "]", "=", "$", "contextid", ";", "}", "if", "(", "!", "is_null", "(", "$", "itemtype", ")", ")", "{", "$", "sql", ".=", "\" AND ti.itemtype = :itemtype\"", ";", "$", "params", "[", "'itemtype'", "]", "=", "$", "itemtype", ";", "}", "if", "(", "$", "taginstances", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "$", "params", ")", ")", "{", "static", "::", "delete_instances_as_record", "(", "$", "taginstances", ")", ";", "}", "}" ]
Bulk delete all tag instances for a component or tag area @param string $component @param string $itemtype (optional) @param int $contextid (optional)
[ "Bulk", "delete", "all", "tag", "instances", "for", "a", "component", "or", "tag", "area" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L567-L588
217,618
moodle/moodle
tag/classes/tag.php
core_tag_tag.add_instance
protected function add_instance($component, $itemtype, $itemid, context $context, $ordering, $tiuserid = 0) { global $DB; $this->ensure_fields_exist(array('name', 'rawname'), 'add_instance'); $taginstance = new stdClass; $taginstance->tagid = $this->id; $taginstance->component = $component ? $component : ''; $taginstance->itemid = $itemid; $taginstance->itemtype = $itemtype; $taginstance->contextid = $context->id; $taginstance->ordering = $ordering; $taginstance->timecreated = time(); $taginstance->timemodified = $taginstance->timecreated; $taginstance->tiuserid = $tiuserid; $taginstance->id = $DB->insert_record('tag_instance', $taginstance); // Trigger tag added event. \core\event\tag_added::create_from_tag_instance($taginstance, $this->name, $this->rawname, true)->trigger(); return $taginstance->id; }
php
protected function add_instance($component, $itemtype, $itemid, context $context, $ordering, $tiuserid = 0) { global $DB; $this->ensure_fields_exist(array('name', 'rawname'), 'add_instance'); $taginstance = new stdClass; $taginstance->tagid = $this->id; $taginstance->component = $component ? $component : ''; $taginstance->itemid = $itemid; $taginstance->itemtype = $itemtype; $taginstance->contextid = $context->id; $taginstance->ordering = $ordering; $taginstance->timecreated = time(); $taginstance->timemodified = $taginstance->timecreated; $taginstance->tiuserid = $tiuserid; $taginstance->id = $DB->insert_record('tag_instance', $taginstance); // Trigger tag added event. \core\event\tag_added::create_from_tag_instance($taginstance, $this->name, $this->rawname, true)->trigger(); return $taginstance->id; }
[ "protected", "function", "add_instance", "(", "$", "component", ",", "$", "itemtype", ",", "$", "itemid", ",", "context", "$", "context", ",", "$", "ordering", ",", "$", "tiuserid", "=", "0", ")", "{", "global", "$", "DB", ";", "$", "this", "->", "ensure_fields_exist", "(", "array", "(", "'name'", ",", "'rawname'", ")", ",", "'add_instance'", ")", ";", "$", "taginstance", "=", "new", "stdClass", ";", "$", "taginstance", "->", "tagid", "=", "$", "this", "->", "id", ";", "$", "taginstance", "->", "component", "=", "$", "component", "?", "$", "component", ":", "''", ";", "$", "taginstance", "->", "itemid", "=", "$", "itemid", ";", "$", "taginstance", "->", "itemtype", "=", "$", "itemtype", ";", "$", "taginstance", "->", "contextid", "=", "$", "context", "->", "id", ";", "$", "taginstance", "->", "ordering", "=", "$", "ordering", ";", "$", "taginstance", "->", "timecreated", "=", "time", "(", ")", ";", "$", "taginstance", "->", "timemodified", "=", "$", "taginstance", "->", "timecreated", ";", "$", "taginstance", "->", "tiuserid", "=", "$", "tiuserid", ";", "$", "taginstance", "->", "id", "=", "$", "DB", "->", "insert_record", "(", "'tag_instance'", ",", "$", "taginstance", ")", ";", "// Trigger tag added event.", "\\", "core", "\\", "event", "\\", "tag_added", "::", "create_from_tag_instance", "(", "$", "taginstance", ",", "$", "this", "->", "name", ",", "$", "this", "->", "rawname", ",", "true", ")", "->", "trigger", "(", ")", ";", "return", "$", "taginstance", "->", "id", ";", "}" ]
Adds a tag instance @param string $component @param string $itemtype @param string $itemid @param context $context @param int $ordering @param int $tiuserid tag instance user id, only needed for tag areas with user tagging (such as core/course) @return int id of tag_instance
[ "Adds", "a", "tag", "instance" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L601-L622
217,619
moodle/moodle
tag/classes/tag.php
core_tag_tag.update_instance_ordering
protected function update_instance_ordering($instanceid, $ordering) { global $DB; $data = new stdClass(); $data->id = $instanceid; $data->ordering = $ordering; $data->timemodified = time(); $DB->update_record('tag_instance', $data); }
php
protected function update_instance_ordering($instanceid, $ordering) { global $DB; $data = new stdClass(); $data->id = $instanceid; $data->ordering = $ordering; $data->timemodified = time(); $DB->update_record('tag_instance', $data); }
[ "protected", "function", "update_instance_ordering", "(", "$", "instanceid", ",", "$", "ordering", ")", "{", "global", "$", "DB", ";", "$", "data", "=", "new", "stdClass", "(", ")", ";", "$", "data", "->", "id", "=", "$", "instanceid", ";", "$", "data", "->", "ordering", "=", "$", "ordering", ";", "$", "data", "->", "timemodified", "=", "time", "(", ")", ";", "$", "DB", "->", "update_record", "(", "'tag_instance'", ",", "$", "data", ")", ";", "}" ]
Updates the ordering on tag instance @param int $instanceid @param int $ordering
[ "Updates", "the", "ordering", "on", "tag", "instance" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L630-L638
217,620
moodle/moodle
tag/classes/tag.php
core_tag_tag.get_items_tags
public static function get_items_tags($component, $itemtype, $itemids, $standardonly = self::BOTH_STANDARD_AND_NOT, $tiuserid = 0) { global $DB; if (static::is_enabled($component, $itemtype) === false) { // Tagging area is properly defined but not enabled - return empty array. return array(); } if (empty($itemids)) { return array(); } $standardonly = (int)$standardonly; // In case somebody passed bool. list($idsql, $params) = $DB->get_in_or_equal($itemids, SQL_PARAMS_NAMED); // Note: if the fields in this query are changed, you need to do the same changes in core_tag_tag::get_correlated_tags(). $sql = "SELECT ti.id AS taginstanceid, tg.id, tg.isstandard, tg.name, tg.rawname, tg.flag, tg.tagcollid, ti.ordering, ti.contextid AS taginstancecontextid, ti.itemid FROM {tag_instance} ti JOIN {tag} tg ON tg.id = ti.tagid WHERE ti.itemtype = :itemtype AND ti.itemid $idsql ". ($component ? "AND ti.component = :component " : ""). ($tiuserid ? "AND ti.tiuserid = :tiuserid " : ""). (($standardonly == self::STANDARD_ONLY) ? "AND tg.isstandard = 1 " : ""). (($standardonly == self::NOT_STANDARD_ONLY) ? "AND tg.isstandard = 0 " : ""). "ORDER BY ti.ordering ASC, ti.id"; $params['itemtype'] = $itemtype; $params['component'] = $component; $params['tiuserid'] = $tiuserid; $records = $DB->get_records_sql($sql, $params); $result = array(); foreach ($itemids as $itemid) { $result[$itemid] = []; } foreach ($records as $id => $record) { $result[$record->itemid][$id] = new static($record); } return $result; }
php
public static function get_items_tags($component, $itemtype, $itemids, $standardonly = self::BOTH_STANDARD_AND_NOT, $tiuserid = 0) { global $DB; if (static::is_enabled($component, $itemtype) === false) { // Tagging area is properly defined but not enabled - return empty array. return array(); } if (empty($itemids)) { return array(); } $standardonly = (int)$standardonly; // In case somebody passed bool. list($idsql, $params) = $DB->get_in_or_equal($itemids, SQL_PARAMS_NAMED); // Note: if the fields in this query are changed, you need to do the same changes in core_tag_tag::get_correlated_tags(). $sql = "SELECT ti.id AS taginstanceid, tg.id, tg.isstandard, tg.name, tg.rawname, tg.flag, tg.tagcollid, ti.ordering, ti.contextid AS taginstancecontextid, ti.itemid FROM {tag_instance} ti JOIN {tag} tg ON tg.id = ti.tagid WHERE ti.itemtype = :itemtype AND ti.itemid $idsql ". ($component ? "AND ti.component = :component " : ""). ($tiuserid ? "AND ti.tiuserid = :tiuserid " : ""). (($standardonly == self::STANDARD_ONLY) ? "AND tg.isstandard = 1 " : ""). (($standardonly == self::NOT_STANDARD_ONLY) ? "AND tg.isstandard = 0 " : ""). "ORDER BY ti.ordering ASC, ti.id"; $params['itemtype'] = $itemtype; $params['component'] = $component; $params['tiuserid'] = $tiuserid; $records = $DB->get_records_sql($sql, $params); $result = array(); foreach ($itemids as $itemid) { $result[$itemid] = []; } foreach ($records as $id => $record) { $result[$record->itemid][$id] = new static($record); } return $result; }
[ "public", "static", "function", "get_items_tags", "(", "$", "component", ",", "$", "itemtype", ",", "$", "itemids", ",", "$", "standardonly", "=", "self", "::", "BOTH_STANDARD_AND_NOT", ",", "$", "tiuserid", "=", "0", ")", "{", "global", "$", "DB", ";", "if", "(", "static", "::", "is_enabled", "(", "$", "component", ",", "$", "itemtype", ")", "===", "false", ")", "{", "// Tagging area is properly defined but not enabled - return empty array.", "return", "array", "(", ")", ";", "}", "if", "(", "empty", "(", "$", "itemids", ")", ")", "{", "return", "array", "(", ")", ";", "}", "$", "standardonly", "=", "(", "int", ")", "$", "standardonly", ";", "// In case somebody passed bool.", "list", "(", "$", "idsql", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "itemids", ",", "SQL_PARAMS_NAMED", ")", ";", "// Note: if the fields in this query are changed, you need to do the same changes in core_tag_tag::get_correlated_tags().", "$", "sql", "=", "\"SELECT ti.id AS taginstanceid, tg.id, tg.isstandard, tg.name, tg.rawname, tg.flag,\n tg.tagcollid, ti.ordering, ti.contextid AS taginstancecontextid, ti.itemid\n FROM {tag_instance} ti\n JOIN {tag} tg ON tg.id = ti.tagid\n WHERE ti.itemtype = :itemtype AND ti.itemid $idsql \"", ".", "(", "$", "component", "?", "\"AND ti.component = :component \"", ":", "\"\"", ")", ".", "(", "$", "tiuserid", "?", "\"AND ti.tiuserid = :tiuserid \"", ":", "\"\"", ")", ".", "(", "(", "$", "standardonly", "==", "self", "::", "STANDARD_ONLY", ")", "?", "\"AND tg.isstandard = 1 \"", ":", "\"\"", ")", ".", "(", "(", "$", "standardonly", "==", "self", "::", "NOT_STANDARD_ONLY", ")", "?", "\"AND tg.isstandard = 0 \"", ":", "\"\"", ")", ".", "\"ORDER BY ti.ordering ASC, ti.id\"", ";", "$", "params", "[", "'itemtype'", "]", "=", "$", "itemtype", ";", "$", "params", "[", "'component'", "]", "=", "$", "component", ";", "$", "params", "[", "'tiuserid'", "]", "=", "$", "tiuserid", ";", "$", "records", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "itemids", "as", "$", "itemid", ")", "{", "$", "result", "[", "$", "itemid", "]", "=", "[", "]", ";", "}", "foreach", "(", "$", "records", "as", "$", "id", "=>", "$", "record", ")", "{", "$", "result", "[", "$", "record", "->", "itemid", "]", "[", "$", "id", "]", "=", "new", "static", "(", "$", "record", ")", ";", "}", "return", "$", "result", ";", "}" ]
Get the array of core_tag_tag objects associated with a list of items. Use {@link core_tag_tag::get_item_tags_array()} if you wish to get the same data as simple array. @param string $component component responsible for tagging. For BC it can be empty but in this case the query will be slow because DB index will not be used. @param string $itemtype type of the tagged item @param int[] $itemids @param int $standardonly wether to return only standard tags or any @param int $tiuserid tag instance user id, only needed for tag areas with user tagging @return core_tag_tag[] each object contains additional fields taginstanceid, taginstancecontextid and ordering
[ "Get", "the", "array", "of", "core_tag_tag", "objects", "associated", "with", "a", "list", "of", "items", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L653-L694
217,621
moodle/moodle
tag/classes/tag.php
core_tag_tag.get_item_tags_array
public static function get_item_tags_array($component, $itemtype, $itemid, $standardonly = self::BOTH_STANDARD_AND_NOT, $tiuserid = 0, $ashtml = true) { $tags = array(); foreach (static::get_item_tags($component, $itemtype, $itemid, $standardonly, $tiuserid) as $tag) { $tags[$tag->id] = $tag->get_display_name($ashtml); } return $tags; }
php
public static function get_item_tags_array($component, $itemtype, $itemid, $standardonly = self::BOTH_STANDARD_AND_NOT, $tiuserid = 0, $ashtml = true) { $tags = array(); foreach (static::get_item_tags($component, $itemtype, $itemid, $standardonly, $tiuserid) as $tag) { $tags[$tag->id] = $tag->get_display_name($ashtml); } return $tags; }
[ "public", "static", "function", "get_item_tags_array", "(", "$", "component", ",", "$", "itemtype", ",", "$", "itemid", ",", "$", "standardonly", "=", "self", "::", "BOTH_STANDARD_AND_NOT", ",", "$", "tiuserid", "=", "0", ",", "$", "ashtml", "=", "true", ")", "{", "$", "tags", "=", "array", "(", ")", ";", "foreach", "(", "static", "::", "get_item_tags", "(", "$", "component", ",", "$", "itemtype", ",", "$", "itemid", ",", "$", "standardonly", ",", "$", "tiuserid", ")", "as", "$", "tag", ")", "{", "$", "tags", "[", "$", "tag", "->", "id", "]", "=", "$", "tag", "->", "get_display_name", "(", "$", "ashtml", ")", ";", "}", "return", "$", "tags", ";", "}" ]
Returns the list of display names of the tags that are associated with an item This method is usually used to prefill the form data for the 'tags' form element @param string $component component responsible for tagging. For BC it can be empty but in this case the query will be slow because DB index will not be used. @param string $itemtype type of the tagged item @param int $itemid @param int $standardonly wether to return only standard tags or any @param int $tiuserid tag instance user id, only needed for tag areas with user tagging @param bool $ashtml (default true) if true will return htmlspecialchars encoded tag names @return string[] array of tags display names
[ "Returns", "the", "list", "of", "display", "names", "of", "the", "tags", "that", "are", "associated", "with", "an", "item" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L729-L736
217,622
moodle/moodle
tag/classes/tag.php
core_tag_tag.remove_all_item_tags
public static function remove_all_item_tags($component, $itemtype, $itemid, $tiuserid = 0) { $context = context_system::instance(); // Context will not be used. static::set_item_tags($component, $itemtype, $itemid, $context, null, $tiuserid); }
php
public static function remove_all_item_tags($component, $itemtype, $itemid, $tiuserid = 0) { $context = context_system::instance(); // Context will not be used. static::set_item_tags($component, $itemtype, $itemid, $context, null, $tiuserid); }
[ "public", "static", "function", "remove_all_item_tags", "(", "$", "component", ",", "$", "itemtype", ",", "$", "itemid", ",", "$", "tiuserid", "=", "0", ")", "{", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "// Context will not be used.", "static", "::", "set_item_tags", "(", "$", "component", ",", "$", "itemtype", ",", "$", "itemid", ",", "$", "context", ",", "null", ",", "$", "tiuserid", ")", ";", "}" ]
Removes all tags from an item. All tags will be removed even if tagging is disabled in this area. This is usually called when the item itself has been deleted. @param string $component component responsible for tagging @param string $itemtype type of the tagged item @param int $itemid @param int $tiuserid tag instance user id, only needed for tag areas with user tagging (such as core/course)
[ "Removes", "all", "tags", "from", "an", "item", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L857-L860
217,623
moodle/moodle
tag/classes/tag.php
core_tag_tag.add_item_tag
public static function add_item_tag($component, $itemtype, $itemid, context $context, $tagname, $tiuserid = 0) { global $DB; if (static::is_enabled($component, $itemtype) === false) { // Tagging area is properly defined but not enabled - do nothing. return null; } $rawname = clean_param($tagname, PARAM_TAG); $normalisedname = core_text::strtolower($rawname); $tagcollid = core_tag_area::get_collection($component, $itemtype); $usersql = $tiuserid ? " AND ti.tiuserid = :tiuserid " : ""; $sql = 'SELECT t.*, ti.id AS taginstanceid FROM {tag} t LEFT JOIN {tag_instance} ti ON ti.tagid = t.id AND ti.itemtype = :itemtype '. $usersql . 'AND ti.itemid = :itemid AND ti.component = :component WHERE t.name = :name AND t.tagcollid = :tagcollid'; $params = array('name' => $normalisedname, 'tagcollid' => $tagcollid, 'itemtype' => $itemtype, 'itemid' => $itemid, 'component' => $component, 'tiuserid' => $tiuserid); $record = $DB->get_record_sql($sql, $params); if ($record) { if ($record->taginstanceid) { // Tag was already added to the item, nothing to do here. return $record->taginstanceid; } $tag = new static($record); } else { // The tag does not exist yet, create it. $tags = static::add($tagcollid, array($tagname)); $tag = reset($tags); } $ordering = $DB->get_field_sql('SELECT MAX(ordering) FROM {tag_instance} ti WHERE ti.itemtype = :itemtype AND ti.itemid = :itemid AND ti.component = :component' . $usersql, $params); return $tag->add_instance($component, $itemtype, $itemid, $context, $ordering + 1, $tiuserid); }
php
public static function add_item_tag($component, $itemtype, $itemid, context $context, $tagname, $tiuserid = 0) { global $DB; if (static::is_enabled($component, $itemtype) === false) { // Tagging area is properly defined but not enabled - do nothing. return null; } $rawname = clean_param($tagname, PARAM_TAG); $normalisedname = core_text::strtolower($rawname); $tagcollid = core_tag_area::get_collection($component, $itemtype); $usersql = $tiuserid ? " AND ti.tiuserid = :tiuserid " : ""; $sql = 'SELECT t.*, ti.id AS taginstanceid FROM {tag} t LEFT JOIN {tag_instance} ti ON ti.tagid = t.id AND ti.itemtype = :itemtype '. $usersql . 'AND ti.itemid = :itemid AND ti.component = :component WHERE t.name = :name AND t.tagcollid = :tagcollid'; $params = array('name' => $normalisedname, 'tagcollid' => $tagcollid, 'itemtype' => $itemtype, 'itemid' => $itemid, 'component' => $component, 'tiuserid' => $tiuserid); $record = $DB->get_record_sql($sql, $params); if ($record) { if ($record->taginstanceid) { // Tag was already added to the item, nothing to do here. return $record->taginstanceid; } $tag = new static($record); } else { // The tag does not exist yet, create it. $tags = static::add($tagcollid, array($tagname)); $tag = reset($tags); } $ordering = $DB->get_field_sql('SELECT MAX(ordering) FROM {tag_instance} ti WHERE ti.itemtype = :itemtype AND ti.itemid = :itemid AND ti.component = :component' . $usersql, $params); return $tag->add_instance($component, $itemtype, $itemid, $context, $ordering + 1, $tiuserid); }
[ "public", "static", "function", "add_item_tag", "(", "$", "component", ",", "$", "itemtype", ",", "$", "itemid", ",", "context", "$", "context", ",", "$", "tagname", ",", "$", "tiuserid", "=", "0", ")", "{", "global", "$", "DB", ";", "if", "(", "static", "::", "is_enabled", "(", "$", "component", ",", "$", "itemtype", ")", "===", "false", ")", "{", "// Tagging area is properly defined but not enabled - do nothing.", "return", "null", ";", "}", "$", "rawname", "=", "clean_param", "(", "$", "tagname", ",", "PARAM_TAG", ")", ";", "$", "normalisedname", "=", "core_text", "::", "strtolower", "(", "$", "rawname", ")", ";", "$", "tagcollid", "=", "core_tag_area", "::", "get_collection", "(", "$", "component", ",", "$", "itemtype", ")", ";", "$", "usersql", "=", "$", "tiuserid", "?", "\" AND ti.tiuserid = :tiuserid \"", ":", "\"\"", ";", "$", "sql", "=", "'SELECT t.*, ti.id AS taginstanceid\n FROM {tag} t\n LEFT JOIN {tag_instance} ti ON ti.tagid = t.id AND ti.itemtype = :itemtype '", ".", "$", "usersql", ".", "'AND ti.itemid = :itemid AND ti.component = :component\n WHERE t.name = :name AND t.tagcollid = :tagcollid'", ";", "$", "params", "=", "array", "(", "'name'", "=>", "$", "normalisedname", ",", "'tagcollid'", "=>", "$", "tagcollid", ",", "'itemtype'", "=>", "$", "itemtype", ",", "'itemid'", "=>", "$", "itemid", ",", "'component'", "=>", "$", "component", ",", "'tiuserid'", "=>", "$", "tiuserid", ")", ";", "$", "record", "=", "$", "DB", "->", "get_record_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "if", "(", "$", "record", ")", "{", "if", "(", "$", "record", "->", "taginstanceid", ")", "{", "// Tag was already added to the item, nothing to do here.", "return", "$", "record", "->", "taginstanceid", ";", "}", "$", "tag", "=", "new", "static", "(", "$", "record", ")", ";", "}", "else", "{", "// The tag does not exist yet, create it.", "$", "tags", "=", "static", "::", "add", "(", "$", "tagcollid", ",", "array", "(", "$", "tagname", ")", ")", ";", "$", "tag", "=", "reset", "(", "$", "tags", ")", ";", "}", "$", "ordering", "=", "$", "DB", "->", "get_field_sql", "(", "'SELECT MAX(ordering) FROM {tag_instance} ti\n WHERE ti.itemtype = :itemtype AND ti.itemid = :itemid AND\n ti.component = :component'", ".", "$", "usersql", ",", "$", "params", ")", ";", "return", "$", "tag", "->", "add_instance", "(", "$", "component", ",", "$", "itemtype", ",", "$", "itemid", ",", "$", "context", ",", "$", "ordering", "+", "1", ",", "$", "tiuserid", ")", ";", "}" ]
Adds a tag to an item, without overwriting the current tags. If the tag has already been added to the record, no changes are made. @param string $component the component that was tagged @param string $itemtype the type of record to tag ('post' for blogs, 'user' for users, etc.) @param int $itemid the id of the record to tag @param context $context the context of where this tag was assigned @param string $tagname the tag to add @param int $tiuserid tag instance user id, only needed for tag areas with user tagging (such as core/course) @return int id of tag_instance that was either created or already existed or null if tagging is not enabled
[ "Adds", "a", "tag", "to", "an", "item", "without", "overwriting", "the", "current", "tags", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L875-L914
217,624
moodle/moodle
tag/classes/tag.php
core_tag_tag.remove_item_tag
public static function remove_item_tag($component, $itemtype, $itemid, $tagname, $tiuserid = 0) { global $DB; if (static::is_enabled($component, $itemtype) === false) { // Tagging area is properly defined but not enabled - do nothing. return array(); } $rawname = clean_param($tagname, PARAM_TAG); $normalisedname = core_text::strtolower($rawname); $usersql = $tiuserid ? " AND tiuserid = :tiuserid " : ""; $componentsql = $component ? " AND ti.component = :component " : ""; $sql = 'SELECT t.*, ti.id AS taginstanceid, ti.contextid AS taginstancecontextid, ti.ordering FROM {tag} t JOIN {tag_instance} ti ON ti.tagid = t.id ' . $usersql . ' WHERE t.name = :name AND ti.itemtype = :itemtype AND ti.itemid = :itemid ' . $componentsql; $params = array('name' => $normalisedname, 'itemtype' => $itemtype, 'itemid' => $itemid, 'component' => $component, 'tiuserid' => $tiuserid); if ($record = $DB->get_record_sql($sql, $params)) { $taginstance = (object)array('id' => $record->taginstanceid, 'itemtype' => $itemtype, 'itemid' => $itemid, 'contextid' => $record->taginstancecontextid, 'tiuserid' => $tiuserid); $tag = new static($record); $tag->delete_instance_as_record($taginstance, false); $componentsql = $component ? " AND component = :component " : ""; $sql = "UPDATE {tag_instance} SET ordering = ordering - 1 WHERE itemtype = :itemtype AND itemid = :itemid $componentsql $usersql AND ordering > :ordering"; $params['ordering'] = $record->ordering; $DB->execute($sql, $params); } }
php
public static function remove_item_tag($component, $itemtype, $itemid, $tagname, $tiuserid = 0) { global $DB; if (static::is_enabled($component, $itemtype) === false) { // Tagging area is properly defined but not enabled - do nothing. return array(); } $rawname = clean_param($tagname, PARAM_TAG); $normalisedname = core_text::strtolower($rawname); $usersql = $tiuserid ? " AND tiuserid = :tiuserid " : ""; $componentsql = $component ? " AND ti.component = :component " : ""; $sql = 'SELECT t.*, ti.id AS taginstanceid, ti.contextid AS taginstancecontextid, ti.ordering FROM {tag} t JOIN {tag_instance} ti ON ti.tagid = t.id ' . $usersql . ' WHERE t.name = :name AND ti.itemtype = :itemtype AND ti.itemid = :itemid ' . $componentsql; $params = array('name' => $normalisedname, 'itemtype' => $itemtype, 'itemid' => $itemid, 'component' => $component, 'tiuserid' => $tiuserid); if ($record = $DB->get_record_sql($sql, $params)) { $taginstance = (object)array('id' => $record->taginstanceid, 'itemtype' => $itemtype, 'itemid' => $itemid, 'contextid' => $record->taginstancecontextid, 'tiuserid' => $tiuserid); $tag = new static($record); $tag->delete_instance_as_record($taginstance, false); $componentsql = $component ? " AND component = :component " : ""; $sql = "UPDATE {tag_instance} SET ordering = ordering - 1 WHERE itemtype = :itemtype AND itemid = :itemid $componentsql $usersql AND ordering > :ordering"; $params['ordering'] = $record->ordering; $DB->execute($sql, $params); } }
[ "public", "static", "function", "remove_item_tag", "(", "$", "component", ",", "$", "itemtype", ",", "$", "itemid", ",", "$", "tagname", ",", "$", "tiuserid", "=", "0", ")", "{", "global", "$", "DB", ";", "if", "(", "static", "::", "is_enabled", "(", "$", "component", ",", "$", "itemtype", ")", "===", "false", ")", "{", "// Tagging area is properly defined but not enabled - do nothing.", "return", "array", "(", ")", ";", "}", "$", "rawname", "=", "clean_param", "(", "$", "tagname", ",", "PARAM_TAG", ")", ";", "$", "normalisedname", "=", "core_text", "::", "strtolower", "(", "$", "rawname", ")", ";", "$", "usersql", "=", "$", "tiuserid", "?", "\" AND tiuserid = :tiuserid \"", ":", "\"\"", ";", "$", "componentsql", "=", "$", "component", "?", "\" AND ti.component = :component \"", ":", "\"\"", ";", "$", "sql", "=", "'SELECT t.*, ti.id AS taginstanceid, ti.contextid AS taginstancecontextid, ti.ordering\n FROM {tag} t JOIN {tag_instance} ti ON ti.tagid = t.id '", ".", "$", "usersql", ".", "'\n WHERE t.name = :name AND ti.itemtype = :itemtype\n AND ti.itemid = :itemid '", ".", "$", "componentsql", ";", "$", "params", "=", "array", "(", "'name'", "=>", "$", "normalisedname", ",", "'itemtype'", "=>", "$", "itemtype", ",", "'itemid'", "=>", "$", "itemid", ",", "'component'", "=>", "$", "component", ",", "'tiuserid'", "=>", "$", "tiuserid", ")", ";", "if", "(", "$", "record", "=", "$", "DB", "->", "get_record_sql", "(", "$", "sql", ",", "$", "params", ")", ")", "{", "$", "taginstance", "=", "(", "object", ")", "array", "(", "'id'", "=>", "$", "record", "->", "taginstanceid", ",", "'itemtype'", "=>", "$", "itemtype", ",", "'itemid'", "=>", "$", "itemid", ",", "'contextid'", "=>", "$", "record", "->", "taginstancecontextid", ",", "'tiuserid'", "=>", "$", "tiuserid", ")", ";", "$", "tag", "=", "new", "static", "(", "$", "record", ")", ";", "$", "tag", "->", "delete_instance_as_record", "(", "$", "taginstance", ",", "false", ")", ";", "$", "componentsql", "=", "$", "component", "?", "\" AND component = :component \"", ":", "\"\"", ";", "$", "sql", "=", "\"UPDATE {tag_instance} SET ordering = ordering - 1\n WHERE itemtype = :itemtype\n AND itemid = :itemid $componentsql $usersql\n AND ordering > :ordering\"", ";", "$", "params", "[", "'ordering'", "]", "=", "$", "record", "->", "ordering", ";", "$", "DB", "->", "execute", "(", "$", "sql", ",", "$", "params", ")", ";", "}", "}" ]
Removes the tag from an item without changing the other tags @param string $component the component that was tagged @param string $itemtype the type of record to tag ('post' for blogs, 'user' for users, etc.) @param int $itemid the id of the record to tag @param string $tagname the tag to remove @param int $tiuserid tag instance user id, only needed for tag areas with user tagging (such as core/course)
[ "Removes", "the", "tag", "from", "an", "item", "without", "changing", "the", "other", "tags" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L925-L959
217,625
moodle/moodle
tag/classes/tag.php
core_tag_tag.move_context
public static function move_context($component, $itemtype, $oldcontext, $newcontext) { global $DB; if ($oldcontext instanceof context) { $oldcontext = $oldcontext->id; } if ($newcontext instanceof context) { $newcontext = $newcontext->id; } $DB->set_field('tag_instance', 'contextid', $newcontext, array('component' => $component, 'itemtype' => $itemtype, 'contextid' => $oldcontext)); }
php
public static function move_context($component, $itemtype, $oldcontext, $newcontext) { global $DB; if ($oldcontext instanceof context) { $oldcontext = $oldcontext->id; } if ($newcontext instanceof context) { $newcontext = $newcontext->id; } $DB->set_field('tag_instance', 'contextid', $newcontext, array('component' => $component, 'itemtype' => $itemtype, 'contextid' => $oldcontext)); }
[ "public", "static", "function", "move_context", "(", "$", "component", ",", "$", "itemtype", ",", "$", "oldcontext", ",", "$", "newcontext", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "oldcontext", "instanceof", "context", ")", "{", "$", "oldcontext", "=", "$", "oldcontext", "->", "id", ";", "}", "if", "(", "$", "newcontext", "instanceof", "context", ")", "{", "$", "newcontext", "=", "$", "newcontext", "->", "id", ";", "}", "$", "DB", "->", "set_field", "(", "'tag_instance'", ",", "'contextid'", ",", "$", "newcontext", ",", "array", "(", "'component'", "=>", "$", "component", ",", "'itemtype'", "=>", "$", "itemtype", ",", "'contextid'", "=>", "$", "oldcontext", ")", ")", ";", "}" ]
Allows to move all tag instances from one context to another @param string $component the component that was tagged @param string $itemtype the type of record to tag ('post' for blogs, 'user' for users, etc.) @param context $oldcontext @param context $newcontext
[ "Allows", "to", "move", "all", "tag", "instances", "from", "one", "context", "to", "another" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L969-L979
217,626
moodle/moodle
tag/classes/tag.php
core_tag_tag.change_items_context
public static function change_items_context($component, $itemtype, $itemids, $newcontext) { global $DB; if (empty($itemids)) { return; } if (!is_array($itemids)) { $itemids = array($itemids); } list($sql, $params) = $DB->get_in_or_equal($itemids, SQL_PARAMS_NAMED); $params['component'] = $component; $params['itemtype'] = $itemtype; if ($newcontext instanceof context) { $newcontext = $newcontext->id; } $DB->set_field_select('tag_instance', 'contextid', $newcontext, 'component = :component AND itemtype = :itemtype AND itemid ' . $sql, $params); }
php
public static function change_items_context($component, $itemtype, $itemids, $newcontext) { global $DB; if (empty($itemids)) { return; } if (!is_array($itemids)) { $itemids = array($itemids); } list($sql, $params) = $DB->get_in_or_equal($itemids, SQL_PARAMS_NAMED); $params['component'] = $component; $params['itemtype'] = $itemtype; if ($newcontext instanceof context) { $newcontext = $newcontext->id; } $DB->set_field_select('tag_instance', 'contextid', $newcontext, 'component = :component AND itemtype = :itemtype AND itemid ' . $sql, $params); }
[ "public", "static", "function", "change_items_context", "(", "$", "component", ",", "$", "itemtype", ",", "$", "itemids", ",", "$", "newcontext", ")", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "itemids", ")", ")", "{", "return", ";", "}", "if", "(", "!", "is_array", "(", "$", "itemids", ")", ")", "{", "$", "itemids", "=", "array", "(", "$", "itemids", ")", ";", "}", "list", "(", "$", "sql", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "itemids", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "params", "[", "'component'", "]", "=", "$", "component", ";", "$", "params", "[", "'itemtype'", "]", "=", "$", "itemtype", ";", "if", "(", "$", "newcontext", "instanceof", "context", ")", "{", "$", "newcontext", "=", "$", "newcontext", "->", "id", ";", "}", "$", "DB", "->", "set_field_select", "(", "'tag_instance'", ",", "'contextid'", ",", "$", "newcontext", ",", "'component = :component AND itemtype = :itemtype AND itemid '", ".", "$", "sql", ",", "$", "params", ")", ";", "}" ]
Moves all tags of the specified items to the new context @param string $component the component that was tagged @param string $itemtype the type of record to tag ('post' for blogs, 'user' for users, etc.) @param array $itemids @param context|int $newcontext target context to move tags to
[ "Moves", "all", "tags", "of", "the", "specified", "items", "to", "the", "new", "context" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L989-L1006
217,627
moodle/moodle
tag/classes/tag.php
core_tag_tag.change_instances_context
public static function change_instances_context(array $taginstanceids, context $newcontext) { global $DB; if (empty($taginstanceids)) { return; } list($sql, $params) = $DB->get_in_or_equal($taginstanceids); $DB->set_field_select('tag_instance', 'contextid', $newcontext->id, "id {$sql}", $params); }
php
public static function change_instances_context(array $taginstanceids, context $newcontext) { global $DB; if (empty($taginstanceids)) { return; } list($sql, $params) = $DB->get_in_or_equal($taginstanceids); $DB->set_field_select('tag_instance', 'contextid', $newcontext->id, "id {$sql}", $params); }
[ "public", "static", "function", "change_instances_context", "(", "array", "$", "taginstanceids", ",", "context", "$", "newcontext", ")", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "taginstanceids", ")", ")", "{", "return", ";", "}", "list", "(", "$", "sql", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "taginstanceids", ")", ";", "$", "DB", "->", "set_field_select", "(", "'tag_instance'", ",", "'contextid'", ",", "$", "newcontext", "->", "id", ",", "\"id {$sql}\"", ",", "$", "params", ")", ";", "}" ]
Moves all of the specified tag instances into a new context. @param array $taginstanceids The list of tag instance ids that should be moved @param context $newcontext The context to move the tag instances into
[ "Moves", "all", "of", "the", "specified", "tag", "instances", "into", "a", "new", "context", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L1014-L1023
217,628
moodle/moodle
tag/classes/tag.php
core_tag_tag.flag
public function flag() { global $DB; $this->ensure_fields_exist(array('name', 'userid', 'rawname', 'flag'), 'flag'); // Update all the tags to flagged. $this->timemodified = time(); $this->flag++; $DB->update_record('tag', array('timemodified' => $this->timemodified, 'flag' => $this->flag, 'id' => $this->id)); $event = \core\event\tag_flagged::create(array( 'objectid' => $this->id, 'relateduserid' => $this->userid, 'context' => context_system::instance(), 'other' => array( 'name' => $this->name, 'rawname' => $this->rawname ) )); $event->trigger(); }
php
public function flag() { global $DB; $this->ensure_fields_exist(array('name', 'userid', 'rawname', 'flag'), 'flag'); // Update all the tags to flagged. $this->timemodified = time(); $this->flag++; $DB->update_record('tag', array('timemodified' => $this->timemodified, 'flag' => $this->flag, 'id' => $this->id)); $event = \core\event\tag_flagged::create(array( 'objectid' => $this->id, 'relateduserid' => $this->userid, 'context' => context_system::instance(), 'other' => array( 'name' => $this->name, 'rawname' => $this->rawname ) )); $event->trigger(); }
[ "public", "function", "flag", "(", ")", "{", "global", "$", "DB", ";", "$", "this", "->", "ensure_fields_exist", "(", "array", "(", "'name'", ",", "'userid'", ",", "'rawname'", ",", "'flag'", ")", ",", "'flag'", ")", ";", "// Update all the tags to flagged.", "$", "this", "->", "timemodified", "=", "time", "(", ")", ";", "$", "this", "->", "flag", "++", ";", "$", "DB", "->", "update_record", "(", "'tag'", ",", "array", "(", "'timemodified'", "=>", "$", "this", "->", "timemodified", ",", "'flag'", "=>", "$", "this", "->", "flag", ",", "'id'", "=>", "$", "this", "->", "id", ")", ")", ";", "$", "event", "=", "\\", "core", "\\", "event", "\\", "tag_flagged", "::", "create", "(", "array", "(", "'objectid'", "=>", "$", "this", "->", "id", ",", "'relateduserid'", "=>", "$", "this", "->", "userid", ",", "'context'", "=>", "context_system", "::", "instance", "(", ")", ",", "'other'", "=>", "array", "(", "'name'", "=>", "$", "this", "->", "name", ",", "'rawname'", "=>", "$", "this", "->", "rawname", ")", ")", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "}" ]
Flag a tag as inappropriate
[ "Flag", "a", "tag", "as", "inappropriate" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L1105-L1127
217,629
moodle/moodle
tag/classes/tag.php
core_tag_tag.set_related_tags
public function set_related_tags($tagnames) { $context = context_system::instance(); $tagobjects = $tagnames ? static::create_if_missing($this->tagcollid, $tagnames) : array(); unset($tagobjects[$this->name]); // Never link to itself. $currenttags = static::get_item_tags('core', 'tag', $this->id); // For data coherence reasons, it's better to remove deleted tags // before adding new data: ordering could be duplicated. foreach ($currenttags as $currenttag) { if (!array_key_exists($currenttag->name, $tagobjects)) { $taginstance = (object)array('id' => $currenttag->taginstanceid, 'itemtype' => 'tag', 'itemid' => $this->id, 'contextid' => $context->id); $currenttag->delete_instance_as_record($taginstance, false); $this->delete_instance('core', 'tag', $currenttag->id); } } foreach ($tagobjects as $name => $tag) { foreach ($currenttags as $currenttag) { if ($currenttag->name === $name) { continue 2; } } $this->add_instance('core', 'tag', $tag->id, $context, 0); $tag->add_instance('core', 'tag', $this->id, $context, 0); $currenttags[] = $tag; } }
php
public function set_related_tags($tagnames) { $context = context_system::instance(); $tagobjects = $tagnames ? static::create_if_missing($this->tagcollid, $tagnames) : array(); unset($tagobjects[$this->name]); // Never link to itself. $currenttags = static::get_item_tags('core', 'tag', $this->id); // For data coherence reasons, it's better to remove deleted tags // before adding new data: ordering could be duplicated. foreach ($currenttags as $currenttag) { if (!array_key_exists($currenttag->name, $tagobjects)) { $taginstance = (object)array('id' => $currenttag->taginstanceid, 'itemtype' => 'tag', 'itemid' => $this->id, 'contextid' => $context->id); $currenttag->delete_instance_as_record($taginstance, false); $this->delete_instance('core', 'tag', $currenttag->id); } } foreach ($tagobjects as $name => $tag) { foreach ($currenttags as $currenttag) { if ($currenttag->name === $name) { continue 2; } } $this->add_instance('core', 'tag', $tag->id, $context, 0); $tag->add_instance('core', 'tag', $this->id, $context, 0); $currenttags[] = $tag; } }
[ "public", "function", "set_related_tags", "(", "$", "tagnames", ")", "{", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "$", "tagobjects", "=", "$", "tagnames", "?", "static", "::", "create_if_missing", "(", "$", "this", "->", "tagcollid", ",", "$", "tagnames", ")", ":", "array", "(", ")", ";", "unset", "(", "$", "tagobjects", "[", "$", "this", "->", "name", "]", ")", ";", "// Never link to itself.", "$", "currenttags", "=", "static", "::", "get_item_tags", "(", "'core'", ",", "'tag'", ",", "$", "this", "->", "id", ")", ";", "// For data coherence reasons, it's better to remove deleted tags", "// before adding new data: ordering could be duplicated.", "foreach", "(", "$", "currenttags", "as", "$", "currenttag", ")", "{", "if", "(", "!", "array_key_exists", "(", "$", "currenttag", "->", "name", ",", "$", "tagobjects", ")", ")", "{", "$", "taginstance", "=", "(", "object", ")", "array", "(", "'id'", "=>", "$", "currenttag", "->", "taginstanceid", ",", "'itemtype'", "=>", "'tag'", ",", "'itemid'", "=>", "$", "this", "->", "id", ",", "'contextid'", "=>", "$", "context", "->", "id", ")", ";", "$", "currenttag", "->", "delete_instance_as_record", "(", "$", "taginstance", ",", "false", ")", ";", "$", "this", "->", "delete_instance", "(", "'core'", ",", "'tag'", ",", "$", "currenttag", "->", "id", ")", ";", "}", "}", "foreach", "(", "$", "tagobjects", "as", "$", "name", "=>", "$", "tag", ")", "{", "foreach", "(", "$", "currenttags", "as", "$", "currenttag", ")", "{", "if", "(", "$", "currenttag", "->", "name", "===", "$", "name", ")", "{", "continue", "2", ";", "}", "}", "$", "this", "->", "add_instance", "(", "'core'", ",", "'tag'", ",", "$", "tag", "->", "id", ",", "$", "context", ",", "0", ")", ";", "$", "tag", "->", "add_instance", "(", "'core'", ",", "'tag'", ",", "$", "this", "->", "id", ",", "$", "context", ",", "0", ")", ";", "$", "currenttags", "[", "]", "=", "$", "tag", ";", "}", "}" ]
Sets the list of tags related to this one. Tag relations are recorded by two instances linking two tags to each other. For tag relations ordering is not used and may be random. @param array $tagnames
[ "Sets", "the", "list", "of", "tags", "related", "to", "this", "one", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L1167-L1196
217,630
moodle/moodle
tag/classes/tag.php
core_tag_tag.add_related_tags
public function add_related_tags($tagnames) { $context = context_system::instance(); $tagobjects = static::create_if_missing($this->tagcollid, $tagnames); $currenttags = static::get_item_tags('core', 'tag', $this->id); foreach ($tagobjects as $name => $tag) { foreach ($currenttags as $currenttag) { if ($currenttag->name === $name) { continue 2; } } $this->add_instance('core', 'tag', $tag->id, $context, 0); $tag->add_instance('core', 'tag', $this->id, $context, 0); $currenttags[] = $tag; } }
php
public function add_related_tags($tagnames) { $context = context_system::instance(); $tagobjects = static::create_if_missing($this->tagcollid, $tagnames); $currenttags = static::get_item_tags('core', 'tag', $this->id); foreach ($tagobjects as $name => $tag) { foreach ($currenttags as $currenttag) { if ($currenttag->name === $name) { continue 2; } } $this->add_instance('core', 'tag', $tag->id, $context, 0); $tag->add_instance('core', 'tag', $this->id, $context, 0); $currenttags[] = $tag; } }
[ "public", "function", "add_related_tags", "(", "$", "tagnames", ")", "{", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "$", "tagobjects", "=", "static", "::", "create_if_missing", "(", "$", "this", "->", "tagcollid", ",", "$", "tagnames", ")", ";", "$", "currenttags", "=", "static", "::", "get_item_tags", "(", "'core'", ",", "'tag'", ",", "$", "this", "->", "id", ")", ";", "foreach", "(", "$", "tagobjects", "as", "$", "name", "=>", "$", "tag", ")", "{", "foreach", "(", "$", "currenttags", "as", "$", "currenttag", ")", "{", "if", "(", "$", "currenttag", "->", "name", "===", "$", "name", ")", "{", "continue", "2", ";", "}", "}", "$", "this", "->", "add_instance", "(", "'core'", ",", "'tag'", ",", "$", "tag", "->", "id", ",", "$", "context", ",", "0", ")", ";", "$", "tag", "->", "add_instance", "(", "'core'", ",", "'tag'", ",", "$", "this", "->", "id", ",", "$", "context", ",", "0", ")", ";", "$", "currenttags", "[", "]", "=", "$", "tag", ";", "}", "}" ]
Adds to the list of related tags without removing existing Tag relations are recorded by two instances linking two tags to each other. For tag relations ordering is not used and may be random. @param array $tagnames
[ "Adds", "to", "the", "list", "of", "related", "tags", "without", "removing", "existing" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L1206-L1222
217,631
moodle/moodle
tag/classes/tag.php
core_tag_tag.get_correlated_tags
public function get_correlated_tags($keepduplicates = false) { global $DB; $correlated = $DB->get_field('tag_correlation', 'correlatedtags', array('tagid' => $this->id)); if (!$correlated) { return array(); } $correlated = preg_split('/\s*,\s*/', trim($correlated), -1, PREG_SPLIT_NO_EMPTY); list($query, $params) = $DB->get_in_or_equal($correlated); // This is (and has to) return the same fields as the query in core_tag_tag::get_item_tags(). $sql = "SELECT ti.id AS taginstanceid, tg.id, tg.isstandard, tg.name, tg.rawname, tg.flag, tg.tagcollid, ti.ordering, ti.contextid AS taginstancecontextid, ti.itemid FROM {tag} tg INNER JOIN {tag_instance} ti ON tg.id = ti.tagid WHERE tg.id $query AND tg.id <> ? AND tg.tagcollid = ? ORDER BY ti.ordering ASC, ti.id"; $params[] = $this->id; $params[] = $this->tagcollid; $records = $DB->get_records_sql($sql, $params); $seen = array(); $result = array(); foreach ($records as $id => $record) { if (!$keepduplicates && !empty($seen[$record->id])) { continue; } $result[$id] = new static($record); $seen[$record->id] = true; } return $result; }
php
public function get_correlated_tags($keepduplicates = false) { global $DB; $correlated = $DB->get_field('tag_correlation', 'correlatedtags', array('tagid' => $this->id)); if (!$correlated) { return array(); } $correlated = preg_split('/\s*,\s*/', trim($correlated), -1, PREG_SPLIT_NO_EMPTY); list($query, $params) = $DB->get_in_or_equal($correlated); // This is (and has to) return the same fields as the query in core_tag_tag::get_item_tags(). $sql = "SELECT ti.id AS taginstanceid, tg.id, tg.isstandard, tg.name, tg.rawname, tg.flag, tg.tagcollid, ti.ordering, ti.contextid AS taginstancecontextid, ti.itemid FROM {tag} tg INNER JOIN {tag_instance} ti ON tg.id = ti.tagid WHERE tg.id $query AND tg.id <> ? AND tg.tagcollid = ? ORDER BY ti.ordering ASC, ti.id"; $params[] = $this->id; $params[] = $this->tagcollid; $records = $DB->get_records_sql($sql, $params); $seen = array(); $result = array(); foreach ($records as $id => $record) { if (!$keepduplicates && !empty($seen[$record->id])) { continue; } $result[$id] = new static($record); $seen[$record->id] = true; } return $result; }
[ "public", "function", "get_correlated_tags", "(", "$", "keepduplicates", "=", "false", ")", "{", "global", "$", "DB", ";", "$", "correlated", "=", "$", "DB", "->", "get_field", "(", "'tag_correlation'", ",", "'correlatedtags'", ",", "array", "(", "'tagid'", "=>", "$", "this", "->", "id", ")", ")", ";", "if", "(", "!", "$", "correlated", ")", "{", "return", "array", "(", ")", ";", "}", "$", "correlated", "=", "preg_split", "(", "'/\\s*,\\s*/'", ",", "trim", "(", "$", "correlated", ")", ",", "-", "1", ",", "PREG_SPLIT_NO_EMPTY", ")", ";", "list", "(", "$", "query", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "correlated", ")", ";", "// This is (and has to) return the same fields as the query in core_tag_tag::get_item_tags().", "$", "sql", "=", "\"SELECT ti.id AS taginstanceid, tg.id, tg.isstandard, tg.name, tg.rawname, tg.flag,\n tg.tagcollid, ti.ordering, ti.contextid AS taginstancecontextid, ti.itemid\n FROM {tag} tg\n INNER JOIN {tag_instance} ti ON tg.id = ti.tagid\n WHERE tg.id $query AND tg.id <> ? AND tg.tagcollid = ?\n ORDER BY ti.ordering ASC, ti.id\"", ";", "$", "params", "[", "]", "=", "$", "this", "->", "id", ";", "$", "params", "[", "]", "=", "$", "this", "->", "tagcollid", ";", "$", "records", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "$", "seen", "=", "array", "(", ")", ";", "$", "result", "=", "array", "(", ")", ";", "foreach", "(", "$", "records", "as", "$", "id", "=>", "$", "record", ")", "{", "if", "(", "!", "$", "keepduplicates", "&&", "!", "empty", "(", "$", "seen", "[", "$", "record", "->", "id", "]", ")", ")", "{", "continue", ";", "}", "$", "result", "[", "$", "id", "]", "=", "new", "static", "(", "$", "record", ")", ";", "$", "seen", "[", "$", "record", "->", "id", "]", "=", "true", ";", "}", "return", "$", "result", ";", "}" ]
Returns the correlated tags of a tag, retrieved from the tag_correlation table. Correlated tags are calculated in cron based on existing tag instances. @param bool $keepduplicates if true, will return one record for each existing tag instance which may result in duplicates of the actual tags @return core_tag_tag[] an array of tag objects
[ "Returns", "the", "correlated", "tags", "of", "a", "tag", "retrieved", "from", "the", "tag_correlation", "table", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L1233-L1264
217,632
moodle/moodle
tag/classes/tag.php
core_tag_tag.get_related_tags
public function get_related_tags() { $manual = $this->get_manual_related_tags(); $automatic = $this->get_correlated_tags(); $relatedtags = array_merge($manual, $automatic); // Remove duplicated tags (multiple instances of the same tag). $seen = array(); foreach ($relatedtags as $instance => $tag) { if (isset($seen[$tag->id])) { unset($relatedtags[$instance]); } else { $seen[$tag->id] = 1; } } return $relatedtags; }
php
public function get_related_tags() { $manual = $this->get_manual_related_tags(); $automatic = $this->get_correlated_tags(); $relatedtags = array_merge($manual, $automatic); // Remove duplicated tags (multiple instances of the same tag). $seen = array(); foreach ($relatedtags as $instance => $tag) { if (isset($seen[$tag->id])) { unset($relatedtags[$instance]); } else { $seen[$tag->id] = 1; } } return $relatedtags; }
[ "public", "function", "get_related_tags", "(", ")", "{", "$", "manual", "=", "$", "this", "->", "get_manual_related_tags", "(", ")", ";", "$", "automatic", "=", "$", "this", "->", "get_correlated_tags", "(", ")", ";", "$", "relatedtags", "=", "array_merge", "(", "$", "manual", ",", "$", "automatic", ")", ";", "// Remove duplicated tags (multiple instances of the same tag).", "$", "seen", "=", "array", "(", ")", ";", "foreach", "(", "$", "relatedtags", "as", "$", "instance", "=>", "$", "tag", ")", "{", "if", "(", "isset", "(", "$", "seen", "[", "$", "tag", "->", "id", "]", ")", ")", "{", "unset", "(", "$", "relatedtags", "[", "$", "instance", "]", ")", ";", "}", "else", "{", "$", "seen", "[", "$", "tag", "->", "id", "]", "=", "1", ";", "}", "}", "return", "$", "relatedtags", ";", "}" ]
Returns tags related to a tag Related tags of a tag come from two sources: - manually added related tags, which are tag_instance entries for that tag - correlated tags, which are calculated @return core_tag_tag[] an array of tag objects
[ "Returns", "tags", "related", "to", "a", "tag" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L1284-L1300
217,633
moodle/moodle
tag/classes/tag.php
core_tag_tag.count_tagged_items
public function count_tagged_items($component, $itemtype, $subquery = '', $params = array()) { global $DB; if (empty($itemtype) || !$DB->get_manager()->table_exists($itemtype)) { return 0; } $params = $params ? $params : array(); $query = "SELECT COUNT(it.id) FROM {".$itemtype."} it INNER JOIN {tag_instance} tt ON it.id = tt.itemid WHERE tt.itemtype = :itemtype AND tt.tagid = :tagid"; $params['itemtype'] = $itemtype; $params['tagid'] = $this->id; if ($component) { $query .= ' AND tt.component = :component'; $params['component'] = $component; } if ($subquery) { $query .= ' AND ' . $subquery; } return $DB->get_field_sql($query, $params); }
php
public function count_tagged_items($component, $itemtype, $subquery = '', $params = array()) { global $DB; if (empty($itemtype) || !$DB->get_manager()->table_exists($itemtype)) { return 0; } $params = $params ? $params : array(); $query = "SELECT COUNT(it.id) FROM {".$itemtype."} it INNER JOIN {tag_instance} tt ON it.id = tt.itemid WHERE tt.itemtype = :itemtype AND tt.tagid = :tagid"; $params['itemtype'] = $itemtype; $params['tagid'] = $this->id; if ($component) { $query .= ' AND tt.component = :component'; $params['component'] = $component; } if ($subquery) { $query .= ' AND ' . $subquery; } return $DB->get_field_sql($query, $params); }
[ "public", "function", "count_tagged_items", "(", "$", "component", ",", "$", "itemtype", ",", "$", "subquery", "=", "''", ",", "$", "params", "=", "array", "(", ")", ")", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "itemtype", ")", "||", "!", "$", "DB", "->", "get_manager", "(", ")", "->", "table_exists", "(", "$", "itemtype", ")", ")", "{", "return", "0", ";", "}", "$", "params", "=", "$", "params", "?", "$", "params", ":", "array", "(", ")", ";", "$", "query", "=", "\"SELECT COUNT(it.id)\n FROM {\"", ".", "$", "itemtype", ".", "\"} it INNER JOIN {tag_instance} tt ON it.id = tt.itemid\n WHERE tt.itemtype = :itemtype AND tt.tagid = :tagid\"", ";", "$", "params", "[", "'itemtype'", "]", "=", "$", "itemtype", ";", "$", "params", "[", "'tagid'", "]", "=", "$", "this", "->", "id", ";", "if", "(", "$", "component", ")", "{", "$", "query", ".=", "' AND tt.component = :component'", ";", "$", "params", "[", "'component'", "]", "=", "$", "component", ";", "}", "if", "(", "$", "subquery", ")", "{", "$", "query", ".=", "' AND '", ".", "$", "subquery", ";", "}", "return", "$", "DB", "->", "get_field_sql", "(", "$", "query", ",", "$", "params", ")", ";", "}" ]
Count how many items are tagged with a specific tag. @param string $component component responsible for tagging. For BC it can be empty but in this case the query will be slow because DB index will not be used. @param string $itemtype type to restrict search to @param string $subquery additional query to be appended to WHERE clause, refer to the itemtable as 'it' @param array $params additional parameters for the DB query @return int number of mathing tags.
[ "Count", "how", "many", "items", "are", "tagged", "with", "a", "specific", "tag", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L1349-L1371
217,634
moodle/moodle
tag/classes/tag.php
core_tag_tag.is_item_tagged_with
public static function is_item_tagged_with($component, $itemtype, $itemid, $tagname) { global $DB; $tagcollid = core_tag_area::get_collection($component, $itemtype); $query = 'SELECT 1 FROM {tag} t JOIN {tag_instance} ti ON ti.tagid = t.id WHERE t.name = ? AND t.tagcollid = ? AND ti.itemtype = ? AND ti.itemid = ?'; $cleanname = core_text::strtolower(clean_param($tagname, PARAM_TAG)); $params = array($cleanname, $tagcollid, $itemtype, $itemid); if ($component) { $query .= ' AND ti.component = ?'; $params[] = $component; } return $DB->record_exists_sql($query, $params) ? 1 : 0; }
php
public static function is_item_tagged_with($component, $itemtype, $itemid, $tagname) { global $DB; $tagcollid = core_tag_area::get_collection($component, $itemtype); $query = 'SELECT 1 FROM {tag} t JOIN {tag_instance} ti ON ti.tagid = t.id WHERE t.name = ? AND t.tagcollid = ? AND ti.itemtype = ? AND ti.itemid = ?'; $cleanname = core_text::strtolower(clean_param($tagname, PARAM_TAG)); $params = array($cleanname, $tagcollid, $itemtype, $itemid); if ($component) { $query .= ' AND ti.component = ?'; $params[] = $component; } return $DB->record_exists_sql($query, $params) ? 1 : 0; }
[ "public", "static", "function", "is_item_tagged_with", "(", "$", "component", ",", "$", "itemtype", ",", "$", "itemid", ",", "$", "tagname", ")", "{", "global", "$", "DB", ";", "$", "tagcollid", "=", "core_tag_area", "::", "get_collection", "(", "$", "component", ",", "$", "itemtype", ")", ";", "$", "query", "=", "'SELECT 1 FROM {tag} t\n JOIN {tag_instance} ti ON ti.tagid = t.id\n WHERE t.name = ? AND t.tagcollid = ? AND ti.itemtype = ? AND ti.itemid = ?'", ";", "$", "cleanname", "=", "core_text", "::", "strtolower", "(", "clean_param", "(", "$", "tagname", ",", "PARAM_TAG", ")", ")", ";", "$", "params", "=", "array", "(", "$", "cleanname", ",", "$", "tagcollid", ",", "$", "itemtype", ",", "$", "itemid", ")", ";", "if", "(", "$", "component", ")", "{", "$", "query", ".=", "' AND ti.component = ?'", ";", "$", "params", "[", "]", "=", "$", "component", ";", "}", "return", "$", "DB", "->", "record_exists_sql", "(", "$", "query", ",", "$", "params", ")", "?", "1", ":", "0", ";", "}" ]
Determine if an item is tagged with a specific tag Note that this is a static method and not a method of core_tag object because the tag might not exist yet, for example user searches for "php" and we offer him to add "php" to his interests. @param string $component component responsible for tagging. For BC it can be empty but in this case the query will be slow because DB index will not be used. @param string $itemtype the record type to look for @param int $itemid the record id to look for @param string $tagname a tag name @return int 1 if it is tagged, 0 otherwise
[ "Determine", "if", "an", "item", "is", "tagged", "with", "a", "specific", "tag" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L1386-L1399
217,635
moodle/moodle
tag/classes/tag.php
core_tag_tag.get_formatted_description
public function get_formatted_description($options = array()) { $options = empty($options) ? array() : (array)$options; $options += array('para' => false, 'overflowdiv' => true); $description = file_rewrite_pluginfile_urls($this->description, 'pluginfile.php', context_system::instance()->id, 'tag', 'description', $this->id); return format_text($description, $this->descriptionformat, $options); }
php
public function get_formatted_description($options = array()) { $options = empty($options) ? array() : (array)$options; $options += array('para' => false, 'overflowdiv' => true); $description = file_rewrite_pluginfile_urls($this->description, 'pluginfile.php', context_system::instance()->id, 'tag', 'description', $this->id); return format_text($description, $this->descriptionformat, $options); }
[ "public", "function", "get_formatted_description", "(", "$", "options", "=", "array", "(", ")", ")", "{", "$", "options", "=", "empty", "(", "$", "options", ")", "?", "array", "(", ")", ":", "(", "array", ")", "$", "options", ";", "$", "options", "+=", "array", "(", "'para'", "=>", "false", ",", "'overflowdiv'", "=>", "true", ")", ";", "$", "description", "=", "file_rewrite_pluginfile_urls", "(", "$", "this", "->", "description", ",", "'pluginfile.php'", ",", "context_system", "::", "instance", "(", ")", "->", "id", ",", "'tag'", ",", "'description'", ",", "$", "this", "->", "id", ")", ";", "return", "format_text", "(", "$", "description", ",", "$", "this", "->", "descriptionformat", ",", "$", "options", ")", ";", "}" ]
Returns formatted description of the tag @param array $options @return string
[ "Returns", "formatted", "description", "of", "the", "tag" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L1443-L1449
217,636
moodle/moodle
tag/classes/tag.php
core_tag_tag.delete_tags
public static function delete_tags($tagids) { global $DB; if (!is_array($tagids)) { $tagids = array($tagids); } if (empty($tagids)) { return; } // Use the tagids to create a select statement to be used later. list($tagsql, $tagparams) = $DB->get_in_or_equal($tagids); // Store the tags and tag instances we are going to delete. $tags = $DB->get_records_select('tag', 'id ' . $tagsql, $tagparams); $taginstances = $DB->get_records_select('tag_instance', 'tagid ' . $tagsql, $tagparams); // Delete all the tag instances. $select = 'WHERE tagid ' . $tagsql; $sql = "DELETE FROM {tag_instance} $select"; $DB->execute($sql, $tagparams); // Delete all the tag correlations. $sql = "DELETE FROM {tag_correlation} $select"; $DB->execute($sql, $tagparams); // Delete all the tags. $select = 'WHERE id ' . $tagsql; $sql = "DELETE FROM {tag} $select"; $DB->execute($sql, $tagparams); // Fire an event that these items were untagged. if ($taginstances) { // Save the system context in case the 'contextid' column in the 'tag_instance' table is null. $syscontextid = context_system::instance()->id; // Loop through the tag instances and fire a 'tag_removed'' event. foreach ($taginstances as $taginstance) { // We can not fire an event with 'null' as the contextid. if (is_null($taginstance->contextid)) { $taginstance->contextid = $syscontextid; } // Trigger tag removed event. \core\event\tag_removed::create_from_tag_instance($taginstance, $tags[$taginstance->tagid]->name, $tags[$taginstance->tagid]->rawname, true)->trigger(); } } // Fire an event that these tags were deleted. if ($tags) { $context = context_system::instance(); foreach ($tags as $tag) { // Delete all files associated with this tag. $fs = get_file_storage(); $files = $fs->get_area_files($context->id, 'tag', 'description', $tag->id); foreach ($files as $file) { $file->delete(); } // Trigger an event for deleting this tag. $event = \core\event\tag_deleted::create(array( 'objectid' => $tag->id, 'relateduserid' => $tag->userid, 'context' => $context, 'other' => array( 'name' => $tag->name, 'rawname' => $tag->rawname ) )); $event->add_record_snapshot('tag', $tag); $event->trigger(); } } return true; }
php
public static function delete_tags($tagids) { global $DB; if (!is_array($tagids)) { $tagids = array($tagids); } if (empty($tagids)) { return; } // Use the tagids to create a select statement to be used later. list($tagsql, $tagparams) = $DB->get_in_or_equal($tagids); // Store the tags and tag instances we are going to delete. $tags = $DB->get_records_select('tag', 'id ' . $tagsql, $tagparams); $taginstances = $DB->get_records_select('tag_instance', 'tagid ' . $tagsql, $tagparams); // Delete all the tag instances. $select = 'WHERE tagid ' . $tagsql; $sql = "DELETE FROM {tag_instance} $select"; $DB->execute($sql, $tagparams); // Delete all the tag correlations. $sql = "DELETE FROM {tag_correlation} $select"; $DB->execute($sql, $tagparams); // Delete all the tags. $select = 'WHERE id ' . $tagsql; $sql = "DELETE FROM {tag} $select"; $DB->execute($sql, $tagparams); // Fire an event that these items were untagged. if ($taginstances) { // Save the system context in case the 'contextid' column in the 'tag_instance' table is null. $syscontextid = context_system::instance()->id; // Loop through the tag instances and fire a 'tag_removed'' event. foreach ($taginstances as $taginstance) { // We can not fire an event with 'null' as the contextid. if (is_null($taginstance->contextid)) { $taginstance->contextid = $syscontextid; } // Trigger tag removed event. \core\event\tag_removed::create_from_tag_instance($taginstance, $tags[$taginstance->tagid]->name, $tags[$taginstance->tagid]->rawname, true)->trigger(); } } // Fire an event that these tags were deleted. if ($tags) { $context = context_system::instance(); foreach ($tags as $tag) { // Delete all files associated with this tag. $fs = get_file_storage(); $files = $fs->get_area_files($context->id, 'tag', 'description', $tag->id); foreach ($files as $file) { $file->delete(); } // Trigger an event for deleting this tag. $event = \core\event\tag_deleted::create(array( 'objectid' => $tag->id, 'relateduserid' => $tag->userid, 'context' => $context, 'other' => array( 'name' => $tag->name, 'rawname' => $tag->rawname ) )); $event->add_record_snapshot('tag', $tag); $event->trigger(); } } return true; }
[ "public", "static", "function", "delete_tags", "(", "$", "tagids", ")", "{", "global", "$", "DB", ";", "if", "(", "!", "is_array", "(", "$", "tagids", ")", ")", "{", "$", "tagids", "=", "array", "(", "$", "tagids", ")", ";", "}", "if", "(", "empty", "(", "$", "tagids", ")", ")", "{", "return", ";", "}", "// Use the tagids to create a select statement to be used later.", "list", "(", "$", "tagsql", ",", "$", "tagparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "tagids", ")", ";", "// Store the tags and tag instances we are going to delete.", "$", "tags", "=", "$", "DB", "->", "get_records_select", "(", "'tag'", ",", "'id '", ".", "$", "tagsql", ",", "$", "tagparams", ")", ";", "$", "taginstances", "=", "$", "DB", "->", "get_records_select", "(", "'tag_instance'", ",", "'tagid '", ".", "$", "tagsql", ",", "$", "tagparams", ")", ";", "// Delete all the tag instances.", "$", "select", "=", "'WHERE tagid '", ".", "$", "tagsql", ";", "$", "sql", "=", "\"DELETE FROM {tag_instance} $select\"", ";", "$", "DB", "->", "execute", "(", "$", "sql", ",", "$", "tagparams", ")", ";", "// Delete all the tag correlations.", "$", "sql", "=", "\"DELETE FROM {tag_correlation} $select\"", ";", "$", "DB", "->", "execute", "(", "$", "sql", ",", "$", "tagparams", ")", ";", "// Delete all the tags.", "$", "select", "=", "'WHERE id '", ".", "$", "tagsql", ";", "$", "sql", "=", "\"DELETE FROM {tag} $select\"", ";", "$", "DB", "->", "execute", "(", "$", "sql", ",", "$", "tagparams", ")", ";", "// Fire an event that these items were untagged.", "if", "(", "$", "taginstances", ")", "{", "// Save the system context in case the 'contextid' column in the 'tag_instance' table is null.", "$", "syscontextid", "=", "context_system", "::", "instance", "(", ")", "->", "id", ";", "// Loop through the tag instances and fire a 'tag_removed'' event.", "foreach", "(", "$", "taginstances", "as", "$", "taginstance", ")", "{", "// We can not fire an event with 'null' as the contextid.", "if", "(", "is_null", "(", "$", "taginstance", "->", "contextid", ")", ")", "{", "$", "taginstance", "->", "contextid", "=", "$", "syscontextid", ";", "}", "// Trigger tag removed event.", "\\", "core", "\\", "event", "\\", "tag_removed", "::", "create_from_tag_instance", "(", "$", "taginstance", ",", "$", "tags", "[", "$", "taginstance", "->", "tagid", "]", "->", "name", ",", "$", "tags", "[", "$", "taginstance", "->", "tagid", "]", "->", "rawname", ",", "true", ")", "->", "trigger", "(", ")", ";", "}", "}", "// Fire an event that these tags were deleted.", "if", "(", "$", "tags", ")", "{", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "foreach", "(", "$", "tags", "as", "$", "tag", ")", "{", "// Delete all files associated with this tag.", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "files", "=", "$", "fs", "->", "get_area_files", "(", "$", "context", "->", "id", ",", "'tag'", ",", "'description'", ",", "$", "tag", "->", "id", ")", ";", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "$", "file", "->", "delete", "(", ")", ";", "}", "// Trigger an event for deleting this tag.", "$", "event", "=", "\\", "core", "\\", "event", "\\", "tag_deleted", "::", "create", "(", "array", "(", "'objectid'", "=>", "$", "tag", "->", "id", ",", "'relateduserid'", "=>", "$", "tag", "->", "userid", ",", "'context'", "=>", "$", "context", ",", "'other'", "=>", "array", "(", "'name'", "=>", "$", "tag", "->", "name", ",", "'rawname'", "=>", "$", "tag", "->", "rawname", ")", ")", ")", ";", "$", "event", "->", "add_record_snapshot", "(", "'tag'", ",", "$", "tag", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "}", "}", "return", "true", ";", "}" ]
Delete one or more tag, and all their instances if there are any left. @param int|array $tagids one tagid (int), or one array of tagids to delete @return bool true on success, false otherwise
[ "Delete", "one", "or", "more", "tag", "and", "all", "their", "instances", "if", "there", "are", "any", "left", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L1507-L1583
217,637
moodle/moodle
tag/classes/tag.php
core_tag_tag.combine_correlated_tags
protected function combine_correlated_tags($tags) { global $DB; $ids = array_map(function($t) { return $t->id; }, $tags); // Retrieve the correlated tags of this tag and correlated tags of all tags to be merged in one query // but store them separately. Calculate the list of correlated tags that need to be added to the current. list($sql, $params) = $DB->get_in_or_equal($ids); $params[] = $this->id; $records = $DB->get_records_select('tag_correlation', 'tagid '.$sql.' OR tagid = ?', $params, '', 'tagid, id, correlatedtags'); $correlated = array(); $mycorrelated = array(); foreach ($records as $record) { $taglist = preg_split('/\s*,\s*/', trim($record->correlatedtags), -1, PREG_SPLIT_NO_EMPTY); if ($record->tagid == $this->id) { $mycorrelated = $taglist; } else { $correlated = array_merge($correlated, $taglist); } } array_unique($correlated); // Strip out from $correlated the ids of the tags that are already in $mycorrelated // or are one of the tags that are going to be combined. $correlated = array_diff($correlated, [$this->id], $ids, $mycorrelated); if (empty($correlated)) { // Nothing to do, ignore situation when current tag is correlated to one of the merged tags - they will // be deleted later and get_tag_correlation() will not return them. Next cron will clean everything up. return; } // Update correlated tags of this tag. $newcorrelatedlist = join(',', array_merge($mycorrelated, $correlated)); if (isset($records[$this->id])) { $DB->update_record('tag_correlation', array('id' => $records[$this->id]->id, 'correlatedtags' => $newcorrelatedlist)); } else { $DB->insert_record('tag_correlation', array('tagid' => $this->id, 'correlatedtags' => $newcorrelatedlist)); } // Add this tag to the list of correlated tags of each tag in $correlated. list($sql, $params) = $DB->get_in_or_equal($correlated); $records = $DB->get_records_select('tag_correlation', 'tagid '.$sql, $params, '', 'tagid, id, correlatedtags'); foreach ($correlated as $tagid) { if (isset($records[$tagid])) { $newcorrelatedlist = $records[$tagid]->correlatedtags . ',' . $this->id; $DB->update_record('tag_correlation', array('id' => $records[$tagid]->id, 'correlatedtags' => $newcorrelatedlist)); } else { $DB->insert_record('tag_correlation', array('tagid' => $tagid, 'correlatedtags' => '' . $this->id)); } } }
php
protected function combine_correlated_tags($tags) { global $DB; $ids = array_map(function($t) { return $t->id; }, $tags); // Retrieve the correlated tags of this tag and correlated tags of all tags to be merged in one query // but store them separately. Calculate the list of correlated tags that need to be added to the current. list($sql, $params) = $DB->get_in_or_equal($ids); $params[] = $this->id; $records = $DB->get_records_select('tag_correlation', 'tagid '.$sql.' OR tagid = ?', $params, '', 'tagid, id, correlatedtags'); $correlated = array(); $mycorrelated = array(); foreach ($records as $record) { $taglist = preg_split('/\s*,\s*/', trim($record->correlatedtags), -1, PREG_SPLIT_NO_EMPTY); if ($record->tagid == $this->id) { $mycorrelated = $taglist; } else { $correlated = array_merge($correlated, $taglist); } } array_unique($correlated); // Strip out from $correlated the ids of the tags that are already in $mycorrelated // or are one of the tags that are going to be combined. $correlated = array_diff($correlated, [$this->id], $ids, $mycorrelated); if (empty($correlated)) { // Nothing to do, ignore situation when current tag is correlated to one of the merged tags - they will // be deleted later and get_tag_correlation() will not return them. Next cron will clean everything up. return; } // Update correlated tags of this tag. $newcorrelatedlist = join(',', array_merge($mycorrelated, $correlated)); if (isset($records[$this->id])) { $DB->update_record('tag_correlation', array('id' => $records[$this->id]->id, 'correlatedtags' => $newcorrelatedlist)); } else { $DB->insert_record('tag_correlation', array('tagid' => $this->id, 'correlatedtags' => $newcorrelatedlist)); } // Add this tag to the list of correlated tags of each tag in $correlated. list($sql, $params) = $DB->get_in_or_equal($correlated); $records = $DB->get_records_select('tag_correlation', 'tagid '.$sql, $params, '', 'tagid, id, correlatedtags'); foreach ($correlated as $tagid) { if (isset($records[$tagid])) { $newcorrelatedlist = $records[$tagid]->correlatedtags . ',' . $this->id; $DB->update_record('tag_correlation', array('id' => $records[$tagid]->id, 'correlatedtags' => $newcorrelatedlist)); } else { $DB->insert_record('tag_correlation', array('tagid' => $tagid, 'correlatedtags' => '' . $this->id)); } } }
[ "protected", "function", "combine_correlated_tags", "(", "$", "tags", ")", "{", "global", "$", "DB", ";", "$", "ids", "=", "array_map", "(", "function", "(", "$", "t", ")", "{", "return", "$", "t", "->", "id", ";", "}", ",", "$", "tags", ")", ";", "// Retrieve the correlated tags of this tag and correlated tags of all tags to be merged in one query", "// but store them separately. Calculate the list of correlated tags that need to be added to the current.", "list", "(", "$", "sql", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "ids", ")", ";", "$", "params", "[", "]", "=", "$", "this", "->", "id", ";", "$", "records", "=", "$", "DB", "->", "get_records_select", "(", "'tag_correlation'", ",", "'tagid '", ".", "$", "sql", ".", "' OR tagid = ?'", ",", "$", "params", ",", "''", ",", "'tagid, id, correlatedtags'", ")", ";", "$", "correlated", "=", "array", "(", ")", ";", "$", "mycorrelated", "=", "array", "(", ")", ";", "foreach", "(", "$", "records", "as", "$", "record", ")", "{", "$", "taglist", "=", "preg_split", "(", "'/\\s*,\\s*/'", ",", "trim", "(", "$", "record", "->", "correlatedtags", ")", ",", "-", "1", ",", "PREG_SPLIT_NO_EMPTY", ")", ";", "if", "(", "$", "record", "->", "tagid", "==", "$", "this", "->", "id", ")", "{", "$", "mycorrelated", "=", "$", "taglist", ";", "}", "else", "{", "$", "correlated", "=", "array_merge", "(", "$", "correlated", ",", "$", "taglist", ")", ";", "}", "}", "array_unique", "(", "$", "correlated", ")", ";", "// Strip out from $correlated the ids of the tags that are already in $mycorrelated", "// or are one of the tags that are going to be combined.", "$", "correlated", "=", "array_diff", "(", "$", "correlated", ",", "[", "$", "this", "->", "id", "]", ",", "$", "ids", ",", "$", "mycorrelated", ")", ";", "if", "(", "empty", "(", "$", "correlated", ")", ")", "{", "// Nothing to do, ignore situation when current tag is correlated to one of the merged tags - they will", "// be deleted later and get_tag_correlation() will not return them. Next cron will clean everything up.", "return", ";", "}", "// Update correlated tags of this tag.", "$", "newcorrelatedlist", "=", "join", "(", "','", ",", "array_merge", "(", "$", "mycorrelated", ",", "$", "correlated", ")", ")", ";", "if", "(", "isset", "(", "$", "records", "[", "$", "this", "->", "id", "]", ")", ")", "{", "$", "DB", "->", "update_record", "(", "'tag_correlation'", ",", "array", "(", "'id'", "=>", "$", "records", "[", "$", "this", "->", "id", "]", "->", "id", ",", "'correlatedtags'", "=>", "$", "newcorrelatedlist", ")", ")", ";", "}", "else", "{", "$", "DB", "->", "insert_record", "(", "'tag_correlation'", ",", "array", "(", "'tagid'", "=>", "$", "this", "->", "id", ",", "'correlatedtags'", "=>", "$", "newcorrelatedlist", ")", ")", ";", "}", "// Add this tag to the list of correlated tags of each tag in $correlated.", "list", "(", "$", "sql", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "correlated", ")", ";", "$", "records", "=", "$", "DB", "->", "get_records_select", "(", "'tag_correlation'", ",", "'tagid '", ".", "$", "sql", ",", "$", "params", ",", "''", ",", "'tagid, id, correlatedtags'", ")", ";", "foreach", "(", "$", "correlated", "as", "$", "tagid", ")", "{", "if", "(", "isset", "(", "$", "records", "[", "$", "tagid", "]", ")", ")", "{", "$", "newcorrelatedlist", "=", "$", "records", "[", "$", "tagid", "]", "->", "correlatedtags", ".", "','", ".", "$", "this", "->", "id", ";", "$", "DB", "->", "update_record", "(", "'tag_correlation'", ",", "array", "(", "'id'", "=>", "$", "records", "[", "$", "tagid", "]", "->", "id", ",", "'correlatedtags'", "=>", "$", "newcorrelatedlist", ")", ")", ";", "}", "else", "{", "$", "DB", "->", "insert_record", "(", "'tag_correlation'", ",", "array", "(", "'tagid'", "=>", "$", "tagid", ",", "'correlatedtags'", "=>", "''", ".", "$", "this", "->", "id", ")", ")", ";", "}", "}", "}" ]
Combine together correlated tags of several tags This is a help method for method combine_tags() @param core_tag_tag[] $tags
[ "Combine", "together", "correlated", "tags", "of", "several", "tags" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/tag/classes/tag.php#L1592-L1644
217,638
moodle/moodle
grade/grading/form/guide/renderer.php
gradingform_guide_renderer.display_regrade_confirmation
public function display_regrade_confirmation($elementname, $changelevel, $value) { $html = html_writer::start_tag('div', array('class' => 'gradingform_guide-regrade', 'role' => 'alert')); if ($changelevel<=2) { $html .= get_string('regrademessage1', 'gradingform_guide'); $selectoptions = array( 0 => get_string('regradeoption0', 'gradingform_guide'), 1 => get_string('regradeoption1', 'gradingform_guide') ); $html .= html_writer::select($selectoptions, $elementname.'[regrade]', $value, false); } else { $html .= get_string('regrademessage5', 'gradingform_guide'); $html .= html_writer::empty_tag('input', array('name' => $elementname.'[regrade]', 'value' => 1, 'type' => 'hidden')); } $html .= html_writer::end_tag('div'); return $html; }
php
public function display_regrade_confirmation($elementname, $changelevel, $value) { $html = html_writer::start_tag('div', array('class' => 'gradingform_guide-regrade', 'role' => 'alert')); if ($changelevel<=2) { $html .= get_string('regrademessage1', 'gradingform_guide'); $selectoptions = array( 0 => get_string('regradeoption0', 'gradingform_guide'), 1 => get_string('regradeoption1', 'gradingform_guide') ); $html .= html_writer::select($selectoptions, $elementname.'[regrade]', $value, false); } else { $html .= get_string('regrademessage5', 'gradingform_guide'); $html .= html_writer::empty_tag('input', array('name' => $elementname.'[regrade]', 'value' => 1, 'type' => 'hidden')); } $html .= html_writer::end_tag('div'); return $html; }
[ "public", "function", "display_regrade_confirmation", "(", "$", "elementname", ",", "$", "changelevel", ",", "$", "value", ")", "{", "$", "html", "=", "html_writer", "::", "start_tag", "(", "'div'", ",", "array", "(", "'class'", "=>", "'gradingform_guide-regrade'", ",", "'role'", "=>", "'alert'", ")", ")", ";", "if", "(", "$", "changelevel", "<=", "2", ")", "{", "$", "html", ".=", "get_string", "(", "'regrademessage1'", ",", "'gradingform_guide'", ")", ";", "$", "selectoptions", "=", "array", "(", "0", "=>", "get_string", "(", "'regradeoption0'", ",", "'gradingform_guide'", ")", ",", "1", "=>", "get_string", "(", "'regradeoption1'", ",", "'gradingform_guide'", ")", ")", ";", "$", "html", ".=", "html_writer", "::", "select", "(", "$", "selectoptions", ",", "$", "elementname", ".", "'[regrade]'", ",", "$", "value", ",", "false", ")", ";", "}", "else", "{", "$", "html", ".=", "get_string", "(", "'regrademessage5'", ",", "'gradingform_guide'", ")", ";", "$", "html", ".=", "html_writer", "::", "empty_tag", "(", "'input'", ",", "array", "(", "'name'", "=>", "$", "elementname", ".", "'[regrade]'", ",", "'value'", "=>", "1", ",", "'type'", "=>", "'hidden'", ")", ")", ";", "}", "$", "html", ".=", "html_writer", "::", "end_tag", "(", "'div'", ")", ";", "return", "$", "html", ";", "}" ]
Displays a confirmation message after a regrade has occured @param string $elementname @param int $changelevel @param int $value The regrade option that was used @return string
[ "Displays", "a", "confirmation", "message", "after", "a", "regrade", "has", "occured" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/guide/renderer.php#L753-L768
217,639
moodle/moodle
grade/grading/form/guide/renderer.php
gradingform_guide_renderer.display_guide_mapping_explained
public function display_guide_mapping_explained($scores) { $html = ''; if (!$scores) { return $html; } if (isset($scores['modulegrade']) && $scores['maxscore'] != $scores['modulegrade']) { $html .= $this->box(html_writer::tag('div', get_string('guidemappingexplained', 'gradingform_guide', (object)$scores)) , 'generalbox gradingform_guide-error'); } return $html; }
php
public function display_guide_mapping_explained($scores) { $html = ''; if (!$scores) { return $html; } if (isset($scores['modulegrade']) && $scores['maxscore'] != $scores['modulegrade']) { $html .= $this->box(html_writer::tag('div', get_string('guidemappingexplained', 'gradingform_guide', (object)$scores)) , 'generalbox gradingform_guide-error'); } return $html; }
[ "public", "function", "display_guide_mapping_explained", "(", "$", "scores", ")", "{", "$", "html", "=", "''", ";", "if", "(", "!", "$", "scores", ")", "{", "return", "$", "html", ";", "}", "if", "(", "isset", "(", "$", "scores", "[", "'modulegrade'", "]", ")", "&&", "$", "scores", "[", "'maxscore'", "]", "!=", "$", "scores", "[", "'modulegrade'", "]", ")", "{", "$", "html", ".=", "$", "this", "->", "box", "(", "html_writer", "::", "tag", "(", "'div'", ",", "get_string", "(", "'guidemappingexplained'", ",", "'gradingform_guide'", ",", "(", "object", ")", "$", "scores", ")", ")", ",", "'generalbox gradingform_guide-error'", ")", ";", "}", "return", "$", "html", ";", "}" ]
Generates and returns HTML code to display information box about how guide score is converted to the grade @param array $scores @return string
[ "Generates", "and", "returns", "HTML", "code", "to", "display", "information", "box", "about", "how", "guide", "score", "is", "converted", "to", "the", "grade" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/guide/renderer.php#L775-L786
217,640
moodle/moodle
blocks/rss_client/classes/output/renderer.php
renderer.render_item
public function render_item(\templatable $item) { $data = $item->export_for_template($this); return $this->render_from_template('block_rss_client/item', $data); }
php
public function render_item(\templatable $item) { $data = $item->export_for_template($this); return $this->render_from_template('block_rss_client/item', $data); }
[ "public", "function", "render_item", "(", "\\", "templatable", "$", "item", ")", "{", "$", "data", "=", "$", "item", "->", "export_for_template", "(", "$", "this", ")", ";", "return", "$", "this", "->", "render_from_template", "(", "'block_rss_client/item'", ",", "$", "data", ")", ";", "}" ]
Render an RSS Item @param templatable $item @return string|boolean
[ "Render", "an", "RSS", "Item" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/rss_client/classes/output/renderer.php#L46-L50
217,641
moodle/moodle
blocks/rss_client/classes/output/renderer.php
renderer.render_feed
public function render_feed(\templatable $feed) { $data = $feed->export_for_template($this); return $this->render_from_template('block_rss_client/feed', $data); }
php
public function render_feed(\templatable $feed) { $data = $feed->export_for_template($this); return $this->render_from_template('block_rss_client/feed', $data); }
[ "public", "function", "render_feed", "(", "\\", "templatable", "$", "feed", ")", "{", "$", "data", "=", "$", "feed", "->", "export_for_template", "(", "$", "this", ")", ";", "return", "$", "this", "->", "render_from_template", "(", "'block_rss_client/feed'", ",", "$", "data", ")", ";", "}" ]
Render an RSS Feed @param templatable $feed @return string|boolean
[ "Render", "an", "RSS", "Feed" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/rss_client/classes/output/renderer.php#L58-L62
217,642
moodle/moodle
blocks/rss_client/classes/output/renderer.php
renderer.render_block
public function render_block(\templatable $block) { $data = $block->export_for_template($this); return $this->render_from_template('block_rss_client/block', $data); }
php
public function render_block(\templatable $block) { $data = $block->export_for_template($this); return $this->render_from_template('block_rss_client/block', $data); }
[ "public", "function", "render_block", "(", "\\", "templatable", "$", "block", ")", "{", "$", "data", "=", "$", "block", "->", "export_for_template", "(", "$", "this", ")", ";", "return", "$", "this", "->", "render_from_template", "(", "'block_rss_client/block'", ",", "$", "data", ")", ";", "}" ]
Render an RSS feeds block @param \templatable $block @return string|boolean
[ "Render", "an", "RSS", "feeds", "block" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/rss_client/classes/output/renderer.php#L70-L74
217,643
moodle/moodle
blocks/rss_client/classes/output/renderer.php
renderer.render_footer
public function render_footer(\templatable $footer) { $data = $footer->export_for_template($this); return $this->render_from_template('block_rss_client/footer', $data); }
php
public function render_footer(\templatable $footer) { $data = $footer->export_for_template($this); return $this->render_from_template('block_rss_client/footer', $data); }
[ "public", "function", "render_footer", "(", "\\", "templatable", "$", "footer", ")", "{", "$", "data", "=", "$", "footer", "->", "export_for_template", "(", "$", "this", ")", ";", "return", "$", "this", "->", "render_from_template", "(", "'block_rss_client/footer'", ",", "$", "data", ")", ";", "}" ]
Render the block footer @param templatable $footer @return string|boolean
[ "Render", "the", "block", "footer" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/rss_client/classes/output/renderer.php#L82-L86
217,644
moodle/moodle
blocks/rss_client/classes/output/renderer.php
renderer.format_description
public function format_description($description) { $description = format_text($description, FORMAT_HTML, array('para' => false)); $description = break_up_long_words($description, 30); return $description; }
php
public function format_description($description) { $description = format_text($description, FORMAT_HTML, array('para' => false)); $description = break_up_long_words($description, 30); return $description; }
[ "public", "function", "format_description", "(", "$", "description", ")", "{", "$", "description", "=", "format_text", "(", "$", "description", ",", "FORMAT_HTML", ",", "array", "(", "'para'", "=>", "false", ")", ")", ";", "$", "description", "=", "break_up_long_words", "(", "$", "description", ",", "30", ")", ";", "return", "$", "description", ";", "}" ]
Format an RSS item description @param string $description @return string
[ "Format", "an", "RSS", "item", "description" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/blocks/rss_client/classes/output/renderer.php#L115-L120
217,645
moodle/moodle
mod/quiz/addrandomform.php
quiz_add_random_form.get_number_of_questions_to_add_choices
private function get_number_of_questions_to_add_choices() { $maxrand = 100; $randomcount = array(); for ($i = 1; $i <= min(10, $maxrand); $i++) { $randomcount[$i] = $i; } for ($i = 20; $i <= min(100, $maxrand); $i += 10) { $randomcount[$i] = $i; } return $randomcount; }
php
private function get_number_of_questions_to_add_choices() { $maxrand = 100; $randomcount = array(); for ($i = 1; $i <= min(10, $maxrand); $i++) { $randomcount[$i] = $i; } for ($i = 20; $i <= min(100, $maxrand); $i += 10) { $randomcount[$i] = $i; } return $randomcount; }
[ "private", "function", "get_number_of_questions_to_add_choices", "(", ")", "{", "$", "maxrand", "=", "100", ";", "$", "randomcount", "=", "array", "(", ")", ";", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<=", "min", "(", "10", ",", "$", "maxrand", ")", ";", "$", "i", "++", ")", "{", "$", "randomcount", "[", "$", "i", "]", "=", "$", "i", ";", "}", "for", "(", "$", "i", "=", "20", ";", "$", "i", "<=", "min", "(", "100", ",", "$", "maxrand", ")", ";", "$", "i", "+=", "10", ")", "{", "$", "randomcount", "[", "$", "i", "]", "=", "$", "i", ";", "}", "return", "$", "randomcount", ";", "}" ]
Return an arbitrary array for the dropdown menu @return array of integers array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100)
[ "Return", "an", "arbitrary", "array", "for", "the", "dropdown", "menu" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/quiz/addrandomform.php#L131-L141
217,646
moodle/moodle
grade/grading/form/guide/backup/moodle2/backup_gradingform_guide_plugin.class.php
backup_gradingform_guide_plugin.define_definition_plugin_structure
protected function define_definition_plugin_structure() { // Append data only if the grand-parent element has 'method' set to 'guide'. $plugin = $this->get_plugin_element(null, '../../method', 'guide'); // Create a visible container for our data. $pluginwrapper = new backup_nested_element($this->get_recommended_name()); // Connect our visible container to the parent. $plugin->add_child($pluginwrapper); // Define our elements. $criteria = new backup_nested_element('guidecriteria'); $criterion = new backup_nested_element('guidecriterion', array('id'), array( 'sortorder', 'shortname', 'description', 'descriptionformat', 'descriptionmarkers', 'descriptionmarkersformat', 'maxscore')); $comments = new backup_nested_element('guidecomments'); $comment = new backup_nested_element('guidecomment', array('id'), array( 'sortorder', 'description', 'descriptionformat')); // Build elements hierarchy. $pluginwrapper->add_child($criteria); $criteria->add_child($criterion); $pluginwrapper->add_child($comments); $comments->add_child($comment); // Set sources to populate the data. $criterion->set_source_table('gradingform_guide_criteria', array('definitionid' => backup::VAR_PARENTID)); $comment->set_source_table('gradingform_guide_comments', array('definitionid' => backup::VAR_PARENTID)); // No need to annotate ids or files yet (one day when criterion definition supports // embedded files, they must be annotated here). return $plugin; }
php
protected function define_definition_plugin_structure() { // Append data only if the grand-parent element has 'method' set to 'guide'. $plugin = $this->get_plugin_element(null, '../../method', 'guide'); // Create a visible container for our data. $pluginwrapper = new backup_nested_element($this->get_recommended_name()); // Connect our visible container to the parent. $plugin->add_child($pluginwrapper); // Define our elements. $criteria = new backup_nested_element('guidecriteria'); $criterion = new backup_nested_element('guidecriterion', array('id'), array( 'sortorder', 'shortname', 'description', 'descriptionformat', 'descriptionmarkers', 'descriptionmarkersformat', 'maxscore')); $comments = new backup_nested_element('guidecomments'); $comment = new backup_nested_element('guidecomment', array('id'), array( 'sortorder', 'description', 'descriptionformat')); // Build elements hierarchy. $pluginwrapper->add_child($criteria); $criteria->add_child($criterion); $pluginwrapper->add_child($comments); $comments->add_child($comment); // Set sources to populate the data. $criterion->set_source_table('gradingform_guide_criteria', array('definitionid' => backup::VAR_PARENTID)); $comment->set_source_table('gradingform_guide_comments', array('definitionid' => backup::VAR_PARENTID)); // No need to annotate ids or files yet (one day when criterion definition supports // embedded files, they must be annotated here). return $plugin; }
[ "protected", "function", "define_definition_plugin_structure", "(", ")", "{", "// Append data only if the grand-parent element has 'method' set to 'guide'.", "$", "plugin", "=", "$", "this", "->", "get_plugin_element", "(", "null", ",", "'../../method'", ",", "'guide'", ")", ";", "// Create a visible container for our data.", "$", "pluginwrapper", "=", "new", "backup_nested_element", "(", "$", "this", "->", "get_recommended_name", "(", ")", ")", ";", "// Connect our visible container to the parent.", "$", "plugin", "->", "add_child", "(", "$", "pluginwrapper", ")", ";", "// Define our elements.", "$", "criteria", "=", "new", "backup_nested_element", "(", "'guidecriteria'", ")", ";", "$", "criterion", "=", "new", "backup_nested_element", "(", "'guidecriterion'", ",", "array", "(", "'id'", ")", ",", "array", "(", "'sortorder'", ",", "'shortname'", ",", "'description'", ",", "'descriptionformat'", ",", "'descriptionmarkers'", ",", "'descriptionmarkersformat'", ",", "'maxscore'", ")", ")", ";", "$", "comments", "=", "new", "backup_nested_element", "(", "'guidecomments'", ")", ";", "$", "comment", "=", "new", "backup_nested_element", "(", "'guidecomment'", ",", "array", "(", "'id'", ")", ",", "array", "(", "'sortorder'", ",", "'description'", ",", "'descriptionformat'", ")", ")", ";", "// Build elements hierarchy.", "$", "pluginwrapper", "->", "add_child", "(", "$", "criteria", ")", ";", "$", "criteria", "->", "add_child", "(", "$", "criterion", ")", ";", "$", "pluginwrapper", "->", "add_child", "(", "$", "comments", ")", ";", "$", "comments", "->", "add_child", "(", "$", "comment", ")", ";", "// Set sources to populate the data.", "$", "criterion", "->", "set_source_table", "(", "'gradingform_guide_criteria'", ",", "array", "(", "'definitionid'", "=>", "backup", "::", "VAR_PARENTID", ")", ")", ";", "$", "comment", "->", "set_source_table", "(", "'gradingform_guide_comments'", ",", "array", "(", "'definitionid'", "=>", "backup", "::", "VAR_PARENTID", ")", ")", ";", "// No need to annotate ids or files yet (one day when criterion definition supports", "// embedded files, they must be annotated here).", "return", "$", "plugin", ";", "}" ]
Declares marking guide structures to append to the grading form definition @return backup_plugin_element
[ "Declares", "marking", "guide", "structures", "to", "append", "to", "the", "grading", "form", "definition" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/guide/backup/moodle2/backup_gradingform_guide_plugin.class.php#L40-L83
217,647
moodle/moodle
grade/grading/form/guide/backup/moodle2/backup_gradingform_guide_plugin.class.php
backup_gradingform_guide_plugin.define_instance_plugin_structure
protected function define_instance_plugin_structure() { // Append data only if the ancestor 'definition' element has 'method' set to 'guide'. $plugin = $this->get_plugin_element(null, '../../../../method', 'guide'); // Create a visible container for our data. $pluginwrapper = new backup_nested_element($this->get_recommended_name()); // Connect our visible container to the parent. $plugin->add_child($pluginwrapper); // Define our elements. $fillings = new backup_nested_element('fillings'); $filling = new backup_nested_element('filling', array('id'), array( 'criterionid', 'remark', 'remarkformat', 'score')); // Build elements hierarchy. $pluginwrapper->add_child($fillings); $fillings->add_child($filling); // Set sources to populate the data. $filling->set_source_table('gradingform_guide_fillings', array('instanceid' => backup::VAR_PARENTID)); // No need to annotate ids or files yet (one day when remark field supports // embedded fileds, they must be annotated here). return $plugin; }
php
protected function define_instance_plugin_structure() { // Append data only if the ancestor 'definition' element has 'method' set to 'guide'. $plugin = $this->get_plugin_element(null, '../../../../method', 'guide'); // Create a visible container for our data. $pluginwrapper = new backup_nested_element($this->get_recommended_name()); // Connect our visible container to the parent. $plugin->add_child($pluginwrapper); // Define our elements. $fillings = new backup_nested_element('fillings'); $filling = new backup_nested_element('filling', array('id'), array( 'criterionid', 'remark', 'remarkformat', 'score')); // Build elements hierarchy. $pluginwrapper->add_child($fillings); $fillings->add_child($filling); // Set sources to populate the data. $filling->set_source_table('gradingform_guide_fillings', array('instanceid' => backup::VAR_PARENTID)); // No need to annotate ids or files yet (one day when remark field supports // embedded fileds, they must be annotated here). return $plugin; }
[ "protected", "function", "define_instance_plugin_structure", "(", ")", "{", "// Append data only if the ancestor 'definition' element has 'method' set to 'guide'.", "$", "plugin", "=", "$", "this", "->", "get_plugin_element", "(", "null", ",", "'../../../../method'", ",", "'guide'", ")", ";", "// Create a visible container for our data.", "$", "pluginwrapper", "=", "new", "backup_nested_element", "(", "$", "this", "->", "get_recommended_name", "(", ")", ")", ";", "// Connect our visible container to the parent.", "$", "plugin", "->", "add_child", "(", "$", "pluginwrapper", ")", ";", "// Define our elements.", "$", "fillings", "=", "new", "backup_nested_element", "(", "'fillings'", ")", ";", "$", "filling", "=", "new", "backup_nested_element", "(", "'filling'", ",", "array", "(", "'id'", ")", ",", "array", "(", "'criterionid'", ",", "'remark'", ",", "'remarkformat'", ",", "'score'", ")", ")", ";", "// Build elements hierarchy.", "$", "pluginwrapper", "->", "add_child", "(", "$", "fillings", ")", ";", "$", "fillings", "->", "add_child", "(", "$", "filling", ")", ";", "// Set sources to populate the data.", "$", "filling", "->", "set_source_table", "(", "'gradingform_guide_fillings'", ",", "array", "(", "'instanceid'", "=>", "backup", "::", "VAR_PARENTID", ")", ")", ";", "// No need to annotate ids or files yet (one day when remark field supports", "// embedded fileds, they must be annotated here).", "return", "$", "plugin", ";", "}" ]
Declares marking guide structures to append to the grading form instances @return backup_plugin_element
[ "Declares", "marking", "guide", "structures", "to", "append", "to", "the", "grading", "form", "instances" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/form/guide/backup/moodle2/backup_gradingform_guide_plugin.class.php#L89-L121
217,648
moodle/moodle
admin/tool/usertours/classes/local/target/unattached.php
unattached.add_disabled_constraints_to_form
public static function add_disabled_constraints_to_form(\MoodleQuickForm $mform) { $myvalue = \tool_usertours\target::get_target_constant_for_class(get_class()); foreach (array_keys(self::$forcedsettings) as $settingname) { $mform->hideIf($settingname, 'targettype', 'eq', $myvalue); } }
php
public static function add_disabled_constraints_to_form(\MoodleQuickForm $mform) { $myvalue = \tool_usertours\target::get_target_constant_for_class(get_class()); foreach (array_keys(self::$forcedsettings) as $settingname) { $mform->hideIf($settingname, 'targettype', 'eq', $myvalue); } }
[ "public", "static", "function", "add_disabled_constraints_to_form", "(", "\\", "MoodleQuickForm", "$", "mform", ")", "{", "$", "myvalue", "=", "\\", "tool_usertours", "\\", "target", "::", "get_target_constant_for_class", "(", "get_class", "(", ")", ")", ";", "foreach", "(", "array_keys", "(", "self", "::", "$", "forcedsettings", ")", "as", "$", "settingname", ")", "{", "$", "mform", "->", "hideIf", "(", "$", "settingname", ",", "'targettype'", ",", "'eq'", ",", "$", "myvalue", ")", ";", "}", "}" ]
Add the disabledIf values. @param MoodleQuickForm $mform The form to add configuration to.
[ "Add", "the", "disabledIf", "values", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/usertours/classes/local/target/unattached.php#L83-L89
217,649
moodle/moodle
message/classes/search/base_message.php
base_message.get_doc_url
public function get_doc_url(\core_search\document $doc) { $users = $this->get_current_other_users($doc); $position = 'm'.$doc->get('itemid'); return new \moodle_url('/message/index.php', array('history' => MESSAGE_HISTORY_ALL, 'user1' => $users['currentuserid'], 'user2' => $users['otheruserid']), $position); }
php
public function get_doc_url(\core_search\document $doc) { $users = $this->get_current_other_users($doc); $position = 'm'.$doc->get('itemid'); return new \moodle_url('/message/index.php', array('history' => MESSAGE_HISTORY_ALL, 'user1' => $users['currentuserid'], 'user2' => $users['otheruserid']), $position); }
[ "public", "function", "get_doc_url", "(", "\\", "core_search", "\\", "document", "$", "doc", ")", "{", "$", "users", "=", "$", "this", "->", "get_current_other_users", "(", "$", "doc", ")", ";", "$", "position", "=", "'m'", ".", "$", "doc", "->", "get", "(", "'itemid'", ")", ";", "return", "new", "\\", "moodle_url", "(", "'/message/index.php'", ",", "array", "(", "'history'", "=>", "MESSAGE_HISTORY_ALL", ",", "'user1'", "=>", "$", "users", "[", "'currentuserid'", "]", ",", "'user2'", "=>", "$", "users", "[", "'otheruserid'", "]", ")", ",", "$", "position", ")", ";", "}" ]
Link to the message. @param \core_search\document $doc @return \moodle_url
[ "Link", "to", "the", "message", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/search/base_message.php#L96-L101
217,650
moodle/moodle
message/classes/search/base_message.php
base_message.get_context_url
public function get_context_url(\core_search\document $doc) { $users = $this->get_current_other_users($doc); return new \moodle_url('/message/index.php', array('user1' => $users['currentuserid'], 'user2' => $users['otheruserid'])); }
php
public function get_context_url(\core_search\document $doc) { $users = $this->get_current_other_users($doc); return new \moodle_url('/message/index.php', array('user1' => $users['currentuserid'], 'user2' => $users['otheruserid'])); }
[ "public", "function", "get_context_url", "(", "\\", "core_search", "\\", "document", "$", "doc", ")", "{", "$", "users", "=", "$", "this", "->", "get_current_other_users", "(", "$", "doc", ")", ";", "return", "new", "\\", "moodle_url", "(", "'/message/index.php'", ",", "array", "(", "'user1'", "=>", "$", "users", "[", "'currentuserid'", "]", ",", "'user2'", "=>", "$", "users", "[", "'otheruserid'", "]", ")", ")", ";", "}" ]
Link to the conversation. @param \core_search\document $doc @return \moodle_url
[ "Link", "to", "the", "conversation", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/search/base_message.php#L109-L112
217,651
moodle/moodle
message/classes/search/base_message.php
base_message.get_document_recordset_helper
protected function get_document_recordset_helper($modifiedfrom, \context $context = null, $userfield) { global $DB; if ($userfield == 'useridto') { $userfield = 'mcm.userid'; } else { $userfield = 'm.useridfrom'; } // Set up basic query. $where = $userfield . ' != :noreplyuser AND ' . $userfield . ' != :supportuser AND m.timecreated >= :modifiedfrom'; $params = [ 'noreplyuser' => \core_user::NOREPLY_USER, 'supportuser' => \core_user::SUPPORT_USER, 'modifiedfrom' => $modifiedfrom ]; // Check context to see whether to add other restrictions. if ($context === null) { $context = \context_system::instance(); } switch ($context->contextlevel) { case CONTEXT_COURSECAT: case CONTEXT_COURSE: case CONTEXT_MODULE: case CONTEXT_BLOCK: // There are no messages in any of these contexts so nothing can be found. return null; case CONTEXT_USER: // Add extra restriction to specific user context. $where .= ' AND ' . $userfield . ' = :userid'; $params['userid'] = $context->instanceid; break; case CONTEXT_SYSTEM: break; default: throw new \coding_exception('Unexpected contextlevel: ' . $context->contextlevel); } $sql = "SELECT m.*, mcm.userid as useridto FROM {messages} m INNER JOIN {message_conversations} mc ON m.conversationid = mc.id INNER JOIN {message_conversation_members} mcm ON mcm.conversationid = mc.id WHERE mcm.userid != m.useridfrom AND $where ORDER BY m.timecreated ASC"; return $DB->get_recordset_sql($sql, $params); }
php
protected function get_document_recordset_helper($modifiedfrom, \context $context = null, $userfield) { global $DB; if ($userfield == 'useridto') { $userfield = 'mcm.userid'; } else { $userfield = 'm.useridfrom'; } // Set up basic query. $where = $userfield . ' != :noreplyuser AND ' . $userfield . ' != :supportuser AND m.timecreated >= :modifiedfrom'; $params = [ 'noreplyuser' => \core_user::NOREPLY_USER, 'supportuser' => \core_user::SUPPORT_USER, 'modifiedfrom' => $modifiedfrom ]; // Check context to see whether to add other restrictions. if ($context === null) { $context = \context_system::instance(); } switch ($context->contextlevel) { case CONTEXT_COURSECAT: case CONTEXT_COURSE: case CONTEXT_MODULE: case CONTEXT_BLOCK: // There are no messages in any of these contexts so nothing can be found. return null; case CONTEXT_USER: // Add extra restriction to specific user context. $where .= ' AND ' . $userfield . ' = :userid'; $params['userid'] = $context->instanceid; break; case CONTEXT_SYSTEM: break; default: throw new \coding_exception('Unexpected contextlevel: ' . $context->contextlevel); } $sql = "SELECT m.*, mcm.userid as useridto FROM {messages} m INNER JOIN {message_conversations} mc ON m.conversationid = mc.id INNER JOIN {message_conversation_members} mcm ON mcm.conversationid = mc.id WHERE mcm.userid != m.useridfrom AND $where ORDER BY m.timecreated ASC"; return $DB->get_recordset_sql($sql, $params); }
[ "protected", "function", "get_document_recordset_helper", "(", "$", "modifiedfrom", ",", "\\", "context", "$", "context", "=", "null", ",", "$", "userfield", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "userfield", "==", "'useridto'", ")", "{", "$", "userfield", "=", "'mcm.userid'", ";", "}", "else", "{", "$", "userfield", "=", "'m.useridfrom'", ";", "}", "// Set up basic query.", "$", "where", "=", "$", "userfield", ".", "' != :noreplyuser AND '", ".", "$", "userfield", ".", "' != :supportuser AND m.timecreated >= :modifiedfrom'", ";", "$", "params", "=", "[", "'noreplyuser'", "=>", "\\", "core_user", "::", "NOREPLY_USER", ",", "'supportuser'", "=>", "\\", "core_user", "::", "SUPPORT_USER", ",", "'modifiedfrom'", "=>", "$", "modifiedfrom", "]", ";", "// Check context to see whether to add other restrictions.", "if", "(", "$", "context", "===", "null", ")", "{", "$", "context", "=", "\\", "context_system", "::", "instance", "(", ")", ";", "}", "switch", "(", "$", "context", "->", "contextlevel", ")", "{", "case", "CONTEXT_COURSECAT", ":", "case", "CONTEXT_COURSE", ":", "case", "CONTEXT_MODULE", ":", "case", "CONTEXT_BLOCK", ":", "// There are no messages in any of these contexts so nothing can be found.", "return", "null", ";", "case", "CONTEXT_USER", ":", "// Add extra restriction to specific user context.", "$", "where", ".=", "' AND '", ".", "$", "userfield", ".", "' = :userid'", ";", "$", "params", "[", "'userid'", "]", "=", "$", "context", "->", "instanceid", ";", "break", ";", "case", "CONTEXT_SYSTEM", ":", "break", ";", "default", ":", "throw", "new", "\\", "coding_exception", "(", "'Unexpected contextlevel: '", ".", "$", "context", "->", "contextlevel", ")", ";", "}", "$", "sql", "=", "\"SELECT m.*, mcm.userid as useridto\n FROM {messages} m\n INNER JOIN {message_conversations} mc\n ON m.conversationid = mc.id\n INNER JOIN {message_conversation_members} mcm\n ON mcm.conversationid = mc.id\n WHERE mcm.userid != m.useridfrom\n AND $where\n ORDER BY m.timecreated ASC\"", ";", "return", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "}" ]
Helper function to implement get_document_recordset for subclasses. @param int $modifiedfrom Modified from date @param \context|null $context Context or null @param string $userfield Name of user field (from or to) being considered @return \moodle_recordset|null Recordset or null if no results possible @throws \coding_exception If context invalid
[ "Helper", "function", "to", "implement", "get_document_recordset", "for", "subclasses", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/message/classes/search/base_message.php#L144-L198
217,652
moodle/moodle
mod/assign/submission/file/locallib.php
assign_submission_file.get_settings
public function get_settings(MoodleQuickForm $mform) { global $CFG, $COURSE; if ($this->assignment->has_instance()) { $defaultmaxfilesubmissions = $this->get_config('maxfilesubmissions'); $defaultmaxsubmissionsizebytes = $this->get_config('maxsubmissionsizebytes'); $defaultfiletypes = $this->get_config('filetypeslist'); } else { $defaultmaxfilesubmissions = get_config('assignsubmission_file', 'maxfiles'); $defaultmaxsubmissionsizebytes = get_config('assignsubmission_file', 'maxbytes'); $defaultfiletypes = get_config('assignsubmission_file', 'filetypes'); } $defaultfiletypes = (string)$defaultfiletypes; $settings = array(); $options = array(); for ($i = 1; $i <= get_config('assignsubmission_file', 'maxfiles'); $i++) { $options[$i] = $i; } $name = get_string('maxfilessubmission', 'assignsubmission_file'); $mform->addElement('select', 'assignsubmission_file_maxfiles', $name, $options); $mform->addHelpButton('assignsubmission_file_maxfiles', 'maxfilessubmission', 'assignsubmission_file'); $mform->setDefault('assignsubmission_file_maxfiles', $defaultmaxfilesubmissions); $mform->hideIf('assignsubmission_file_maxfiles', 'assignsubmission_file_enabled', 'notchecked'); $choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes, get_config('assignsubmission_file', 'maxbytes')); $settings[] = array('type' => 'select', 'name' => 'maxsubmissionsizebytes', 'description' => get_string('maximumsubmissionsize', 'assignsubmission_file'), 'options'=> $choices, 'default'=> $defaultmaxsubmissionsizebytes); $name = get_string('maximumsubmissionsize', 'assignsubmission_file'); $mform->addElement('select', 'assignsubmission_file_maxsizebytes', $name, $choices); $mform->addHelpButton('assignsubmission_file_maxsizebytes', 'maximumsubmissionsize', 'assignsubmission_file'); $mform->setDefault('assignsubmission_file_maxsizebytes', $defaultmaxsubmissionsizebytes); $mform->hideIf('assignsubmission_file_maxsizebytes', 'assignsubmission_file_enabled', 'notchecked'); $name = get_string('acceptedfiletypes', 'assignsubmission_file'); $mform->addElement('filetypes', 'assignsubmission_file_filetypes', $name); $mform->addHelpButton('assignsubmission_file_filetypes', 'acceptedfiletypes', 'assignsubmission_file'); $mform->setDefault('assignsubmission_file_filetypes', $defaultfiletypes); $mform->hideIf('assignsubmission_file_filetypes', 'assignsubmission_file_enabled', 'notchecked'); }
php
public function get_settings(MoodleQuickForm $mform) { global $CFG, $COURSE; if ($this->assignment->has_instance()) { $defaultmaxfilesubmissions = $this->get_config('maxfilesubmissions'); $defaultmaxsubmissionsizebytes = $this->get_config('maxsubmissionsizebytes'); $defaultfiletypes = $this->get_config('filetypeslist'); } else { $defaultmaxfilesubmissions = get_config('assignsubmission_file', 'maxfiles'); $defaultmaxsubmissionsizebytes = get_config('assignsubmission_file', 'maxbytes'); $defaultfiletypes = get_config('assignsubmission_file', 'filetypes'); } $defaultfiletypes = (string)$defaultfiletypes; $settings = array(); $options = array(); for ($i = 1; $i <= get_config('assignsubmission_file', 'maxfiles'); $i++) { $options[$i] = $i; } $name = get_string('maxfilessubmission', 'assignsubmission_file'); $mform->addElement('select', 'assignsubmission_file_maxfiles', $name, $options); $mform->addHelpButton('assignsubmission_file_maxfiles', 'maxfilessubmission', 'assignsubmission_file'); $mform->setDefault('assignsubmission_file_maxfiles', $defaultmaxfilesubmissions); $mform->hideIf('assignsubmission_file_maxfiles', 'assignsubmission_file_enabled', 'notchecked'); $choices = get_max_upload_sizes($CFG->maxbytes, $COURSE->maxbytes, get_config('assignsubmission_file', 'maxbytes')); $settings[] = array('type' => 'select', 'name' => 'maxsubmissionsizebytes', 'description' => get_string('maximumsubmissionsize', 'assignsubmission_file'), 'options'=> $choices, 'default'=> $defaultmaxsubmissionsizebytes); $name = get_string('maximumsubmissionsize', 'assignsubmission_file'); $mform->addElement('select', 'assignsubmission_file_maxsizebytes', $name, $choices); $mform->addHelpButton('assignsubmission_file_maxsizebytes', 'maximumsubmissionsize', 'assignsubmission_file'); $mform->setDefault('assignsubmission_file_maxsizebytes', $defaultmaxsubmissionsizebytes); $mform->hideIf('assignsubmission_file_maxsizebytes', 'assignsubmission_file_enabled', 'notchecked'); $name = get_string('acceptedfiletypes', 'assignsubmission_file'); $mform->addElement('filetypes', 'assignsubmission_file_filetypes', $name); $mform->addHelpButton('assignsubmission_file_filetypes', 'acceptedfiletypes', 'assignsubmission_file'); $mform->setDefault('assignsubmission_file_filetypes', $defaultfiletypes); $mform->hideIf('assignsubmission_file_filetypes', 'assignsubmission_file_enabled', 'notchecked'); }
[ "public", "function", "get_settings", "(", "MoodleQuickForm", "$", "mform", ")", "{", "global", "$", "CFG", ",", "$", "COURSE", ";", "if", "(", "$", "this", "->", "assignment", "->", "has_instance", "(", ")", ")", "{", "$", "defaultmaxfilesubmissions", "=", "$", "this", "->", "get_config", "(", "'maxfilesubmissions'", ")", ";", "$", "defaultmaxsubmissionsizebytes", "=", "$", "this", "->", "get_config", "(", "'maxsubmissionsizebytes'", ")", ";", "$", "defaultfiletypes", "=", "$", "this", "->", "get_config", "(", "'filetypeslist'", ")", ";", "}", "else", "{", "$", "defaultmaxfilesubmissions", "=", "get_config", "(", "'assignsubmission_file'", ",", "'maxfiles'", ")", ";", "$", "defaultmaxsubmissionsizebytes", "=", "get_config", "(", "'assignsubmission_file'", ",", "'maxbytes'", ")", ";", "$", "defaultfiletypes", "=", "get_config", "(", "'assignsubmission_file'", ",", "'filetypes'", ")", ";", "}", "$", "defaultfiletypes", "=", "(", "string", ")", "$", "defaultfiletypes", ";", "$", "settings", "=", "array", "(", ")", ";", "$", "options", "=", "array", "(", ")", ";", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<=", "get_config", "(", "'assignsubmission_file'", ",", "'maxfiles'", ")", ";", "$", "i", "++", ")", "{", "$", "options", "[", "$", "i", "]", "=", "$", "i", ";", "}", "$", "name", "=", "get_string", "(", "'maxfilessubmission'", ",", "'assignsubmission_file'", ")", ";", "$", "mform", "->", "addElement", "(", "'select'", ",", "'assignsubmission_file_maxfiles'", ",", "$", "name", ",", "$", "options", ")", ";", "$", "mform", "->", "addHelpButton", "(", "'assignsubmission_file_maxfiles'", ",", "'maxfilessubmission'", ",", "'assignsubmission_file'", ")", ";", "$", "mform", "->", "setDefault", "(", "'assignsubmission_file_maxfiles'", ",", "$", "defaultmaxfilesubmissions", ")", ";", "$", "mform", "->", "hideIf", "(", "'assignsubmission_file_maxfiles'", ",", "'assignsubmission_file_enabled'", ",", "'notchecked'", ")", ";", "$", "choices", "=", "get_max_upload_sizes", "(", "$", "CFG", "->", "maxbytes", ",", "$", "COURSE", "->", "maxbytes", ",", "get_config", "(", "'assignsubmission_file'", ",", "'maxbytes'", ")", ")", ";", "$", "settings", "[", "]", "=", "array", "(", "'type'", "=>", "'select'", ",", "'name'", "=>", "'maxsubmissionsizebytes'", ",", "'description'", "=>", "get_string", "(", "'maximumsubmissionsize'", ",", "'assignsubmission_file'", ")", ",", "'options'", "=>", "$", "choices", ",", "'default'", "=>", "$", "defaultmaxsubmissionsizebytes", ")", ";", "$", "name", "=", "get_string", "(", "'maximumsubmissionsize'", ",", "'assignsubmission_file'", ")", ";", "$", "mform", "->", "addElement", "(", "'select'", ",", "'assignsubmission_file_maxsizebytes'", ",", "$", "name", ",", "$", "choices", ")", ";", "$", "mform", "->", "addHelpButton", "(", "'assignsubmission_file_maxsizebytes'", ",", "'maximumsubmissionsize'", ",", "'assignsubmission_file'", ")", ";", "$", "mform", "->", "setDefault", "(", "'assignsubmission_file_maxsizebytes'", ",", "$", "defaultmaxsubmissionsizebytes", ")", ";", "$", "mform", "->", "hideIf", "(", "'assignsubmission_file_maxsizebytes'", ",", "'assignsubmission_file_enabled'", ",", "'notchecked'", ")", ";", "$", "name", "=", "get_string", "(", "'acceptedfiletypes'", ",", "'assignsubmission_file'", ")", ";", "$", "mform", "->", "addElement", "(", "'filetypes'", ",", "'assignsubmission_file_filetypes'", ",", "$", "name", ")", ";", "$", "mform", "->", "addHelpButton", "(", "'assignsubmission_file_filetypes'", ",", "'acceptedfiletypes'", ",", "'assignsubmission_file'", ")", ";", "$", "mform", "->", "setDefault", "(", "'assignsubmission_file_filetypes'", ",", "$", "defaultfiletypes", ")", ";", "$", "mform", "->", "hideIf", "(", "'assignsubmission_file_filetypes'", ",", "'assignsubmission_file_enabled'", ",", "'notchecked'", ")", ";", "}" ]
Get the default setting for file submission plugin @param MoodleQuickForm $mform The form to add elements to @return void
[ "Get", "the", "default", "setting", "for", "file", "submission", "plugin" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/submission/file/locallib.php#L67-L120
217,653
moodle/moodle
mod/assign/submission/file/locallib.php
assign_submission_file.save_settings
public function save_settings(stdClass $data) { $this->set_config('maxfilesubmissions', $data->assignsubmission_file_maxfiles); $this->set_config('maxsubmissionsizebytes', $data->assignsubmission_file_maxsizebytes); if (!empty($data->assignsubmission_file_filetypes)) { $this->set_config('filetypeslist', $data->assignsubmission_file_filetypes); } else { $this->set_config('filetypeslist', ''); } return true; }
php
public function save_settings(stdClass $data) { $this->set_config('maxfilesubmissions', $data->assignsubmission_file_maxfiles); $this->set_config('maxsubmissionsizebytes', $data->assignsubmission_file_maxsizebytes); if (!empty($data->assignsubmission_file_filetypes)) { $this->set_config('filetypeslist', $data->assignsubmission_file_filetypes); } else { $this->set_config('filetypeslist', ''); } return true; }
[ "public", "function", "save_settings", "(", "stdClass", "$", "data", ")", "{", "$", "this", "->", "set_config", "(", "'maxfilesubmissions'", ",", "$", "data", "->", "assignsubmission_file_maxfiles", ")", ";", "$", "this", "->", "set_config", "(", "'maxsubmissionsizebytes'", ",", "$", "data", "->", "assignsubmission_file_maxsizebytes", ")", ";", "if", "(", "!", "empty", "(", "$", "data", "->", "assignsubmission_file_filetypes", ")", ")", "{", "$", "this", "->", "set_config", "(", "'filetypeslist'", ",", "$", "data", "->", "assignsubmission_file_filetypes", ")", ";", "}", "else", "{", "$", "this", "->", "set_config", "(", "'filetypeslist'", ",", "''", ")", ";", "}", "return", "true", ";", "}" ]
Save the settings for file submission plugin @param stdClass $data @return bool
[ "Save", "the", "settings", "for", "file", "submission", "plugin" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/submission/file/locallib.php#L128-L139
217,654
moodle/moodle
mod/assign/submission/file/locallib.php
assign_submission_file.get_file_options
private function get_file_options() { $fileoptions = array('subdirs' => 1, 'maxbytes' => $this->get_config('maxsubmissionsizebytes'), 'maxfiles' => $this->get_config('maxfilesubmissions'), 'accepted_types' => $this->get_configured_typesets(), 'return_types' => (FILE_INTERNAL | FILE_CONTROLLED_LINK)); if ($fileoptions['maxbytes'] == 0) { // Use module default. $fileoptions['maxbytes'] = get_config('assignsubmission_file', 'maxbytes'); } return $fileoptions; }
php
private function get_file_options() { $fileoptions = array('subdirs' => 1, 'maxbytes' => $this->get_config('maxsubmissionsizebytes'), 'maxfiles' => $this->get_config('maxfilesubmissions'), 'accepted_types' => $this->get_configured_typesets(), 'return_types' => (FILE_INTERNAL | FILE_CONTROLLED_LINK)); if ($fileoptions['maxbytes'] == 0) { // Use module default. $fileoptions['maxbytes'] = get_config('assignsubmission_file', 'maxbytes'); } return $fileoptions; }
[ "private", "function", "get_file_options", "(", ")", "{", "$", "fileoptions", "=", "array", "(", "'subdirs'", "=>", "1", ",", "'maxbytes'", "=>", "$", "this", "->", "get_config", "(", "'maxsubmissionsizebytes'", ")", ",", "'maxfiles'", "=>", "$", "this", "->", "get_config", "(", "'maxfilesubmissions'", ")", ",", "'accepted_types'", "=>", "$", "this", "->", "get_configured_typesets", "(", ")", ",", "'return_types'", "=>", "(", "FILE_INTERNAL", "|", "FILE_CONTROLLED_LINK", ")", ")", ";", "if", "(", "$", "fileoptions", "[", "'maxbytes'", "]", "==", "0", ")", "{", "// Use module default.", "$", "fileoptions", "[", "'maxbytes'", "]", "=", "get_config", "(", "'assignsubmission_file'", ",", "'maxbytes'", ")", ";", "}", "return", "$", "fileoptions", ";", "}" ]
File format options @return array
[ "File", "format", "options" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/submission/file/locallib.php#L146-L157
217,655
moodle/moodle
mod/assign/submission/file/locallib.php
assign_submission_file.get_form_elements
public function get_form_elements($submission, MoodleQuickForm $mform, stdClass $data) { global $OUTPUT; if ($this->get_config('maxfilesubmissions') <= 0) { return false; } $fileoptions = $this->get_file_options(); $submissionid = $submission ? $submission->id : 0; $data = file_prepare_standard_filemanager($data, 'files', $fileoptions, $this->assignment->get_context(), 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, $submissionid); $mform->addElement('filemanager', 'files_filemanager', $this->get_name(), null, $fileoptions); return true; }
php
public function get_form_elements($submission, MoodleQuickForm $mform, stdClass $data) { global $OUTPUT; if ($this->get_config('maxfilesubmissions') <= 0) { return false; } $fileoptions = $this->get_file_options(); $submissionid = $submission ? $submission->id : 0; $data = file_prepare_standard_filemanager($data, 'files', $fileoptions, $this->assignment->get_context(), 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, $submissionid); $mform->addElement('filemanager', 'files_filemanager', $this->get_name(), null, $fileoptions); return true; }
[ "public", "function", "get_form_elements", "(", "$", "submission", ",", "MoodleQuickForm", "$", "mform", ",", "stdClass", "$", "data", ")", "{", "global", "$", "OUTPUT", ";", "if", "(", "$", "this", "->", "get_config", "(", "'maxfilesubmissions'", ")", "<=", "0", ")", "{", "return", "false", ";", "}", "$", "fileoptions", "=", "$", "this", "->", "get_file_options", "(", ")", ";", "$", "submissionid", "=", "$", "submission", "?", "$", "submission", "->", "id", ":", "0", ";", "$", "data", "=", "file_prepare_standard_filemanager", "(", "$", "data", ",", "'files'", ",", "$", "fileoptions", ",", "$", "this", "->", "assignment", "->", "get_context", "(", ")", ",", "'assignsubmission_file'", ",", "ASSIGNSUBMISSION_FILE_FILEAREA", ",", "$", "submissionid", ")", ";", "$", "mform", "->", "addElement", "(", "'filemanager'", ",", "'files_filemanager'", ",", "$", "this", "->", "get_name", "(", ")", ",", "null", ",", "$", "fileoptions", ")", ";", "return", "true", ";", "}" ]
Add elements to submission form @param mixed $submission stdClass|null @param MoodleQuickForm $mform @param stdClass $data @return bool
[ "Add", "elements", "to", "submission", "form" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/submission/file/locallib.php#L167-L187
217,656
moodle/moodle
mod/assign/submission/file/locallib.php
assign_submission_file.count_files
private function count_files($submissionid, $area) { $fs = get_file_storage(); $files = $fs->get_area_files($this->assignment->get_context()->id, 'assignsubmission_file', $area, $submissionid, 'id', false); return count($files); }
php
private function count_files($submissionid, $area) { $fs = get_file_storage(); $files = $fs->get_area_files($this->assignment->get_context()->id, 'assignsubmission_file', $area, $submissionid, 'id', false); return count($files); }
[ "private", "function", "count_files", "(", "$", "submissionid", ",", "$", "area", ")", "{", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "files", "=", "$", "fs", "->", "get_area_files", "(", "$", "this", "->", "assignment", "->", "get_context", "(", ")", "->", "id", ",", "'assignsubmission_file'", ",", "$", "area", ",", "$", "submissionid", ",", "'id'", ",", "false", ")", ";", "return", "count", "(", "$", "files", ")", ";", "}" ]
Count the number of files @param int $submissionid @param string $area @return int
[ "Count", "the", "number", "of", "files" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/submission/file/locallib.php#L196-L206
217,657
moodle/moodle
mod/assign/submission/file/locallib.php
assign_submission_file.remove
public function remove(stdClass $submission) { $fs = get_file_storage(); $fs->delete_area_files($this->assignment->get_context()->id, 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, $submission->id); return true; }
php
public function remove(stdClass $submission) { $fs = get_file_storage(); $fs->delete_area_files($this->assignment->get_context()->id, 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, $submission->id); return true; }
[ "public", "function", "remove", "(", "stdClass", "$", "submission", ")", "{", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "fs", "->", "delete_area_files", "(", "$", "this", "->", "assignment", "->", "get_context", "(", ")", "->", "id", ",", "'assignsubmission_file'", ",", "ASSIGNSUBMISSION_FILE_FILEAREA", ",", "$", "submission", "->", "id", ")", ";", "return", "true", ";", "}" ]
Remove files from this submission. @param stdClass $submission The submission @return boolean
[ "Remove", "files", "from", "this", "submission", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/submission/file/locallib.php#L316-L324
217,658
moodle/moodle
mod/assign/submission/file/locallib.php
assign_submission_file.get_files
public function get_files(stdClass $submission, stdClass $user) { $result = array(); $fs = get_file_storage(); $files = $fs->get_area_files($this->assignment->get_context()->id, 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, $submission->id, 'timemodified', false); foreach ($files as $file) { // Do we return the full folder path or just the file name? if (isset($submission->exportfullpath) && $submission->exportfullpath == false) { $result[$file->get_filename()] = $file; } else { $result[$file->get_filepath().$file->get_filename()] = $file; } } return $result; }
php
public function get_files(stdClass $submission, stdClass $user) { $result = array(); $fs = get_file_storage(); $files = $fs->get_area_files($this->assignment->get_context()->id, 'assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, $submission->id, 'timemodified', false); foreach ($files as $file) { // Do we return the full folder path or just the file name? if (isset($submission->exportfullpath) && $submission->exportfullpath == false) { $result[$file->get_filename()] = $file; } else { $result[$file->get_filepath().$file->get_filename()] = $file; } } return $result; }
[ "public", "function", "get_files", "(", "stdClass", "$", "submission", ",", "stdClass", "$", "user", ")", "{", "$", "result", "=", "array", "(", ")", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "files", "=", "$", "fs", "->", "get_area_files", "(", "$", "this", "->", "assignment", "->", "get_context", "(", ")", "->", "id", ",", "'assignsubmission_file'", ",", "ASSIGNSUBMISSION_FILE_FILEAREA", ",", "$", "submission", "->", "id", ",", "'timemodified'", ",", "false", ")", ";", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "// Do we return the full folder path or just the file name?", "if", "(", "isset", "(", "$", "submission", "->", "exportfullpath", ")", "&&", "$", "submission", "->", "exportfullpath", "==", "false", ")", "{", "$", "result", "[", "$", "file", "->", "get_filename", "(", ")", "]", "=", "$", "file", ";", "}", "else", "{", "$", "result", "[", "$", "file", "->", "get_filepath", "(", ")", ".", "$", "file", "->", "get_filename", "(", ")", "]", "=", "$", "file", ";", "}", "}", "return", "$", "result", ";", "}" ]
Produce a list of files suitable for export that represent this feedback or submission @param stdClass $submission The submission @param stdClass $user The user record - unused @return array - return an array of files indexed by filename
[ "Produce", "a", "list", "of", "files", "suitable", "for", "export", "that", "represent", "this", "feedback", "or", "submission" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/submission/file/locallib.php#L333-L353
217,659
moodle/moodle
mod/assign/submission/file/locallib.php
assign_submission_file.view_summary
public function view_summary(stdClass $submission, & $showviewlink) { $count = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA); // Show we show a link to view all files for this plugin? $showviewlink = $count > ASSIGNSUBMISSION_FILE_MAXSUMMARYFILES; if ($count <= ASSIGNSUBMISSION_FILE_MAXSUMMARYFILES) { return $this->assignment->render_area_files('assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, $submission->id); } else { return get_string('countfiles', 'assignsubmission_file', $count); } }
php
public function view_summary(stdClass $submission, & $showviewlink) { $count = $this->count_files($submission->id, ASSIGNSUBMISSION_FILE_FILEAREA); // Show we show a link to view all files for this plugin? $showviewlink = $count > ASSIGNSUBMISSION_FILE_MAXSUMMARYFILES; if ($count <= ASSIGNSUBMISSION_FILE_MAXSUMMARYFILES) { return $this->assignment->render_area_files('assignsubmission_file', ASSIGNSUBMISSION_FILE_FILEAREA, $submission->id); } else { return get_string('countfiles', 'assignsubmission_file', $count); } }
[ "public", "function", "view_summary", "(", "stdClass", "$", "submission", ",", "&", "$", "showviewlink", ")", "{", "$", "count", "=", "$", "this", "->", "count_files", "(", "$", "submission", "->", "id", ",", "ASSIGNSUBMISSION_FILE_FILEAREA", ")", ";", "// Show we show a link to view all files for this plugin?", "$", "showviewlink", "=", "$", "count", ">", "ASSIGNSUBMISSION_FILE_MAXSUMMARYFILES", ";", "if", "(", "$", "count", "<=", "ASSIGNSUBMISSION_FILE_MAXSUMMARYFILES", ")", "{", "return", "$", "this", "->", "assignment", "->", "render_area_files", "(", "'assignsubmission_file'", ",", "ASSIGNSUBMISSION_FILE_FILEAREA", ",", "$", "submission", "->", "id", ")", ";", "}", "else", "{", "return", "get_string", "(", "'countfiles'", ",", "'assignsubmission_file'", ",", "$", "count", ")", ";", "}", "}" ]
Display the list of files in the submission status table @param stdClass $submission @param bool $showviewlink Set this to true if the list of files is long @return string
[ "Display", "the", "list", "of", "files", "in", "the", "submission", "status", "table" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/submission/file/locallib.php#L362-L374
217,660
moodle/moodle
mod/assign/submission/file/locallib.php
assign_submission_file.get_config_for_external
public function get_config_for_external() { global $CFG; $configs = $this->get_config(); // Get a size in bytes. if ($configs->maxsubmissionsizebytes == 0) { $configs->maxsubmissionsizebytes = get_max_upload_file_size($CFG->maxbytes, $this->assignment->get_course()->maxbytes, get_config('assignsubmission_file', 'maxbytes')); } return (array) $configs; }
php
public function get_config_for_external() { global $CFG; $configs = $this->get_config(); // Get a size in bytes. if ($configs->maxsubmissionsizebytes == 0) { $configs->maxsubmissionsizebytes = get_max_upload_file_size($CFG->maxbytes, $this->assignment->get_course()->maxbytes, get_config('assignsubmission_file', 'maxbytes')); } return (array) $configs; }
[ "public", "function", "get_config_for_external", "(", ")", "{", "global", "$", "CFG", ";", "$", "configs", "=", "$", "this", "->", "get_config", "(", ")", ";", "// Get a size in bytes.", "if", "(", "$", "configs", "->", "maxsubmissionsizebytes", "==", "0", ")", "{", "$", "configs", "->", "maxsubmissionsizebytes", "=", "get_max_upload_file_size", "(", "$", "CFG", "->", "maxbytes", ",", "$", "this", "->", "assignment", "->", "get_course", "(", ")", "->", "maxbytes", ",", "get_config", "(", "'assignsubmission_file'", ",", "'maxbytes'", ")", ")", ";", "}", "return", "(", "array", ")", "$", "configs", ";", "}" ]
Return the plugin configs for external functions. @return array the list of settings @since Moodle 3.2
[ "Return", "the", "plugin", "configs", "for", "external", "functions", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/submission/file/locallib.php#L608-L619
217,661
moodle/moodle
mod/assign/submission/file/locallib.php
assign_submission_file.get_configured_typesets
private function get_configured_typesets() { $typeslist = (string)$this->get_config('filetypeslist'); $util = new \core_form\filetypes_util(); $sets = $util->normalize_file_types($typeslist); return $sets; }
php
private function get_configured_typesets() { $typeslist = (string)$this->get_config('filetypeslist'); $util = new \core_form\filetypes_util(); $sets = $util->normalize_file_types($typeslist); return $sets; }
[ "private", "function", "get_configured_typesets", "(", ")", "{", "$", "typeslist", "=", "(", "string", ")", "$", "this", "->", "get_config", "(", "'filetypeslist'", ")", ";", "$", "util", "=", "new", "\\", "core_form", "\\", "filetypes_util", "(", ")", ";", "$", "sets", "=", "$", "util", "->", "normalize_file_types", "(", "$", "typeslist", ")", ";", "return", "$", "sets", ";", "}" ]
Get the type sets configured for this assignment. @return array('groupname', 'mime/type', ...)
[ "Get", "the", "type", "sets", "configured", "for", "this", "assignment", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/submission/file/locallib.php#L626-L633
217,662
moodle/moodle
mod/assign/classes/privacy/provider.php
provider.get_metadata
public static function get_metadata(collection $collection) : collection { $assigngrades = [ 'userid' => 'privacy:metadata:userid', 'timecreated' => 'privacy:metadata:timecreated', 'timemodified' => 'timemodified', 'grader' => 'privacy:metadata:grader', 'grade' => 'privacy:metadata:grade', 'attemptnumber' => 'attemptnumber' ]; $assignoverrides = [ 'groupid' => 'privacy:metadata:groupid', 'userid' => 'privacy:metadata:userid', 'allowsubmissionsfromdate' => 'allowsubmissionsfromdate', 'duedate' => 'duedate', 'cutoffdate' => 'cutoffdate' ]; $assignsubmission = [ 'userid' => 'privacy:metadata:userid', 'timecreated' => 'privacy:metadata:timecreated', 'timemodified' => 'timemodified', 'status' => 'gradingstatus', 'groupid' => 'privacy:metadata:groupid', 'attemptnumber' => 'attemptnumber', 'latest' => 'privacy:metadata:latest' ]; $assignuserflags = [ 'userid' => 'privacy:metadata:userid', 'assignment' => 'privacy:metadata:assignmentid', 'locked' => 'locksubmissions', 'mailed' => 'privacy:metadata:mailed', 'extensionduedate' => 'extensionduedate', 'workflowstate' => 'markingworkflowstate', 'allocatedmarker' => 'allocatedmarker' ]; $assignusermapping = [ 'assignment' => 'privacy:metadata:assignmentid', 'userid' => 'privacy:metadata:userid' ]; $collection->add_database_table('assign_grades', $assigngrades, 'privacy:metadata:assigngrades'); $collection->add_database_table('assign_overrides', $assignoverrides, 'privacy:metadata:assignoverrides'); $collection->add_database_table('assign_submission', $assignsubmission, 'privacy:metadata:assignsubmissiondetail'); $collection->add_database_table('assign_user_flags', $assignuserflags, 'privacy:metadata:assignuserflags'); $collection->add_database_table('assign_user_mapping', $assignusermapping, 'privacy:metadata:assignusermapping'); $collection->add_user_preference('assign_perpage', 'privacy:metadata:assignperpage'); $collection->add_user_preference('assign_filter', 'privacy:metadata:assignfilter'); $collection->add_user_preference('assign_markerfilter', 'privacy:metadata:assignmarkerfilter'); $collection->add_user_preference('assign_workflowfilter', 'privacy:metadata:assignworkflowfilter'); $collection->add_user_preference('assign_quickgrading', 'privacy:metadata:assignquickgrading'); $collection->add_user_preference('assign_downloadasfolders', 'privacy:metadata:assigndownloadasfolders'); // Link to subplugins. $collection->add_plugintype_link('assignsubmission', [],'privacy:metadata:assignsubmissionpluginsummary'); $collection->add_plugintype_link('assignfeedback', [], 'privacy:metadata:assignfeedbackpluginsummary'); $collection->add_subsystem_link('core_message', [], 'privacy:metadata:assignmessageexplanation'); return $collection; }
php
public static function get_metadata(collection $collection) : collection { $assigngrades = [ 'userid' => 'privacy:metadata:userid', 'timecreated' => 'privacy:metadata:timecreated', 'timemodified' => 'timemodified', 'grader' => 'privacy:metadata:grader', 'grade' => 'privacy:metadata:grade', 'attemptnumber' => 'attemptnumber' ]; $assignoverrides = [ 'groupid' => 'privacy:metadata:groupid', 'userid' => 'privacy:metadata:userid', 'allowsubmissionsfromdate' => 'allowsubmissionsfromdate', 'duedate' => 'duedate', 'cutoffdate' => 'cutoffdate' ]; $assignsubmission = [ 'userid' => 'privacy:metadata:userid', 'timecreated' => 'privacy:metadata:timecreated', 'timemodified' => 'timemodified', 'status' => 'gradingstatus', 'groupid' => 'privacy:metadata:groupid', 'attemptnumber' => 'attemptnumber', 'latest' => 'privacy:metadata:latest' ]; $assignuserflags = [ 'userid' => 'privacy:metadata:userid', 'assignment' => 'privacy:metadata:assignmentid', 'locked' => 'locksubmissions', 'mailed' => 'privacy:metadata:mailed', 'extensionduedate' => 'extensionduedate', 'workflowstate' => 'markingworkflowstate', 'allocatedmarker' => 'allocatedmarker' ]; $assignusermapping = [ 'assignment' => 'privacy:metadata:assignmentid', 'userid' => 'privacy:metadata:userid' ]; $collection->add_database_table('assign_grades', $assigngrades, 'privacy:metadata:assigngrades'); $collection->add_database_table('assign_overrides', $assignoverrides, 'privacy:metadata:assignoverrides'); $collection->add_database_table('assign_submission', $assignsubmission, 'privacy:metadata:assignsubmissiondetail'); $collection->add_database_table('assign_user_flags', $assignuserflags, 'privacy:metadata:assignuserflags'); $collection->add_database_table('assign_user_mapping', $assignusermapping, 'privacy:metadata:assignusermapping'); $collection->add_user_preference('assign_perpage', 'privacy:metadata:assignperpage'); $collection->add_user_preference('assign_filter', 'privacy:metadata:assignfilter'); $collection->add_user_preference('assign_markerfilter', 'privacy:metadata:assignmarkerfilter'); $collection->add_user_preference('assign_workflowfilter', 'privacy:metadata:assignworkflowfilter'); $collection->add_user_preference('assign_quickgrading', 'privacy:metadata:assignquickgrading'); $collection->add_user_preference('assign_downloadasfolders', 'privacy:metadata:assigndownloadasfolders'); // Link to subplugins. $collection->add_plugintype_link('assignsubmission', [],'privacy:metadata:assignsubmissionpluginsummary'); $collection->add_plugintype_link('assignfeedback', [], 'privacy:metadata:assignfeedbackpluginsummary'); $collection->add_subsystem_link('core_message', [], 'privacy:metadata:assignmessageexplanation'); return $collection; }
[ "public", "static", "function", "get_metadata", "(", "collection", "$", "collection", ")", ":", "collection", "{", "$", "assigngrades", "=", "[", "'userid'", "=>", "'privacy:metadata:userid'", ",", "'timecreated'", "=>", "'privacy:metadata:timecreated'", ",", "'timemodified'", "=>", "'timemodified'", ",", "'grader'", "=>", "'privacy:metadata:grader'", ",", "'grade'", "=>", "'privacy:metadata:grade'", ",", "'attemptnumber'", "=>", "'attemptnumber'", "]", ";", "$", "assignoverrides", "=", "[", "'groupid'", "=>", "'privacy:metadata:groupid'", ",", "'userid'", "=>", "'privacy:metadata:userid'", ",", "'allowsubmissionsfromdate'", "=>", "'allowsubmissionsfromdate'", ",", "'duedate'", "=>", "'duedate'", ",", "'cutoffdate'", "=>", "'cutoffdate'", "]", ";", "$", "assignsubmission", "=", "[", "'userid'", "=>", "'privacy:metadata:userid'", ",", "'timecreated'", "=>", "'privacy:metadata:timecreated'", ",", "'timemodified'", "=>", "'timemodified'", ",", "'status'", "=>", "'gradingstatus'", ",", "'groupid'", "=>", "'privacy:metadata:groupid'", ",", "'attemptnumber'", "=>", "'attemptnumber'", ",", "'latest'", "=>", "'privacy:metadata:latest'", "]", ";", "$", "assignuserflags", "=", "[", "'userid'", "=>", "'privacy:metadata:userid'", ",", "'assignment'", "=>", "'privacy:metadata:assignmentid'", ",", "'locked'", "=>", "'locksubmissions'", ",", "'mailed'", "=>", "'privacy:metadata:mailed'", ",", "'extensionduedate'", "=>", "'extensionduedate'", ",", "'workflowstate'", "=>", "'markingworkflowstate'", ",", "'allocatedmarker'", "=>", "'allocatedmarker'", "]", ";", "$", "assignusermapping", "=", "[", "'assignment'", "=>", "'privacy:metadata:assignmentid'", ",", "'userid'", "=>", "'privacy:metadata:userid'", "]", ";", "$", "collection", "->", "add_database_table", "(", "'assign_grades'", ",", "$", "assigngrades", ",", "'privacy:metadata:assigngrades'", ")", ";", "$", "collection", "->", "add_database_table", "(", "'assign_overrides'", ",", "$", "assignoverrides", ",", "'privacy:metadata:assignoverrides'", ")", ";", "$", "collection", "->", "add_database_table", "(", "'assign_submission'", ",", "$", "assignsubmission", ",", "'privacy:metadata:assignsubmissiondetail'", ")", ";", "$", "collection", "->", "add_database_table", "(", "'assign_user_flags'", ",", "$", "assignuserflags", ",", "'privacy:metadata:assignuserflags'", ")", ";", "$", "collection", "->", "add_database_table", "(", "'assign_user_mapping'", ",", "$", "assignusermapping", ",", "'privacy:metadata:assignusermapping'", ")", ";", "$", "collection", "->", "add_user_preference", "(", "'assign_perpage'", ",", "'privacy:metadata:assignperpage'", ")", ";", "$", "collection", "->", "add_user_preference", "(", "'assign_filter'", ",", "'privacy:metadata:assignfilter'", ")", ";", "$", "collection", "->", "add_user_preference", "(", "'assign_markerfilter'", ",", "'privacy:metadata:assignmarkerfilter'", ")", ";", "$", "collection", "->", "add_user_preference", "(", "'assign_workflowfilter'", ",", "'privacy:metadata:assignworkflowfilter'", ")", ";", "$", "collection", "->", "add_user_preference", "(", "'assign_quickgrading'", ",", "'privacy:metadata:assignquickgrading'", ")", ";", "$", "collection", "->", "add_user_preference", "(", "'assign_downloadasfolders'", ",", "'privacy:metadata:assigndownloadasfolders'", ")", ";", "// Link to subplugins.", "$", "collection", "->", "add_plugintype_link", "(", "'assignsubmission'", ",", "[", "]", ",", "'privacy:metadata:assignsubmissionpluginsummary'", ")", ";", "$", "collection", "->", "add_plugintype_link", "(", "'assignfeedback'", ",", "[", "]", ",", "'privacy:metadata:assignfeedbackpluginsummary'", ")", ";", "$", "collection", "->", "add_subsystem_link", "(", "'core_message'", ",", "[", "]", ",", "'privacy:metadata:assignmessageexplanation'", ")", ";", "return", "$", "collection", ";", "}" ]
Provides meta data that is stored about a user with mod_assign @param collection $collection A collection of meta data items to be added to. @return collection Returns the collection of metadata.
[ "Provides", "meta", "data", "that", "is", "stored", "about", "a", "user", "with", "mod_assign" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/classes/privacy/provider.php#L72-L128
217,663
moodle/moodle
mod/assign/classes/privacy/provider.php
provider.get_contexts_for_userid
public static function get_contexts_for_userid(int $userid) : contextlist { $params = ['modulename' => 'assign', 'contextlevel' => CONTEXT_MODULE, 'userid' => $userid, 'graderid' => $userid, 'aouserid' => $userid, 'asnuserid' => $userid, 'aufuserid' => $userid, 'aumuserid' => $userid]; $sql = "SELECT ctx.id FROM {course_modules} cm JOIN {modules} m ON cm.module = m.id AND m.name = :modulename JOIN {assign} a ON cm.instance = a.id JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel JOIN {assign_grades} ag ON a.id = ag.assignment AND (ag.userid = :userid OR ag.grader = :graderid)"; $contextlist = new contextlist(); $contextlist->add_from_sql($sql, $params); $sql = "SELECT ctx.id FROM {course_modules} cm JOIN {modules} m ON cm.module = m.id AND m.name = :modulename JOIN {assign} a ON cm.instance = a.id JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel JOIN {assign_overrides} ao ON a.id = ao.assignid WHERE ao.userid = :aouserid"; $contextlist->add_from_sql($sql, $params); $sql = "SELECT ctx.id FROM {course_modules} cm JOIN {modules} m ON cm.module = m.id AND m.name = :modulename JOIN {assign} a ON cm.instance = a.id JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel JOIN {assign_submission} asn ON a.id = asn.assignment WHERE asn.userid = :asnuserid"; $contextlist->add_from_sql($sql, $params); $sql = "SELECT ctx.id FROM {course_modules} cm JOIN {modules} m ON cm.module = m.id AND m.name = :modulename JOIN {assign} a ON cm.instance = a.id JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel JOIN {assign_user_flags} auf ON a.id = auf.assignment WHERE auf.userid = :aufuserid"; $contextlist->add_from_sql($sql, $params); $sql = "SELECT ctx.id FROM {course_modules} cm JOIN {modules} m ON cm.module = m.id AND m.name = :modulename JOIN {assign} a ON cm.instance = a.id JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel JOIN {assign_user_mapping} aum ON a.id = aum.assignment WHERE aum.userid = :aumuserid"; $contextlist->add_from_sql($sql, $params); manager::plugintype_class_callback('assignfeedback', self::ASSIGNFEEDBACK_INTERFACE, 'get_context_for_userid_within_feedback', [$userid, $contextlist]); manager::plugintype_class_callback('assignsubmission', self::ASSIGNSUBMISSION_INTERFACE, 'get_context_for_userid_within_submission', [$userid, $contextlist]); return $contextlist; }
php
public static function get_contexts_for_userid(int $userid) : contextlist { $params = ['modulename' => 'assign', 'contextlevel' => CONTEXT_MODULE, 'userid' => $userid, 'graderid' => $userid, 'aouserid' => $userid, 'asnuserid' => $userid, 'aufuserid' => $userid, 'aumuserid' => $userid]; $sql = "SELECT ctx.id FROM {course_modules} cm JOIN {modules} m ON cm.module = m.id AND m.name = :modulename JOIN {assign} a ON cm.instance = a.id JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel JOIN {assign_grades} ag ON a.id = ag.assignment AND (ag.userid = :userid OR ag.grader = :graderid)"; $contextlist = new contextlist(); $contextlist->add_from_sql($sql, $params); $sql = "SELECT ctx.id FROM {course_modules} cm JOIN {modules} m ON cm.module = m.id AND m.name = :modulename JOIN {assign} a ON cm.instance = a.id JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel JOIN {assign_overrides} ao ON a.id = ao.assignid WHERE ao.userid = :aouserid"; $contextlist->add_from_sql($sql, $params); $sql = "SELECT ctx.id FROM {course_modules} cm JOIN {modules} m ON cm.module = m.id AND m.name = :modulename JOIN {assign} a ON cm.instance = a.id JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel JOIN {assign_submission} asn ON a.id = asn.assignment WHERE asn.userid = :asnuserid"; $contextlist->add_from_sql($sql, $params); $sql = "SELECT ctx.id FROM {course_modules} cm JOIN {modules} m ON cm.module = m.id AND m.name = :modulename JOIN {assign} a ON cm.instance = a.id JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel JOIN {assign_user_flags} auf ON a.id = auf.assignment WHERE auf.userid = :aufuserid"; $contextlist->add_from_sql($sql, $params); $sql = "SELECT ctx.id FROM {course_modules} cm JOIN {modules} m ON cm.module = m.id AND m.name = :modulename JOIN {assign} a ON cm.instance = a.id JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel JOIN {assign_user_mapping} aum ON a.id = aum.assignment WHERE aum.userid = :aumuserid"; $contextlist->add_from_sql($sql, $params); manager::plugintype_class_callback('assignfeedback', self::ASSIGNFEEDBACK_INTERFACE, 'get_context_for_userid_within_feedback', [$userid, $contextlist]); manager::plugintype_class_callback('assignsubmission', self::ASSIGNSUBMISSION_INTERFACE, 'get_context_for_userid_within_submission', [$userid, $contextlist]); return $contextlist; }
[ "public", "static", "function", "get_contexts_for_userid", "(", "int", "$", "userid", ")", ":", "contextlist", "{", "$", "params", "=", "[", "'modulename'", "=>", "'assign'", ",", "'contextlevel'", "=>", "CONTEXT_MODULE", ",", "'userid'", "=>", "$", "userid", ",", "'graderid'", "=>", "$", "userid", ",", "'aouserid'", "=>", "$", "userid", ",", "'asnuserid'", "=>", "$", "userid", ",", "'aufuserid'", "=>", "$", "userid", ",", "'aumuserid'", "=>", "$", "userid", "]", ";", "$", "sql", "=", "\"SELECT ctx.id\n FROM {course_modules} cm\n JOIN {modules} m ON cm.module = m.id AND m.name = :modulename\n JOIN {assign} a ON cm.instance = a.id\n JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel\n JOIN {assign_grades} ag ON a.id = ag.assignment AND (ag.userid = :userid OR ag.grader = :graderid)\"", ";", "$", "contextlist", "=", "new", "contextlist", "(", ")", ";", "$", "contextlist", "->", "add_from_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "$", "sql", "=", "\"SELECT ctx.id\n FROM {course_modules} cm\n JOIN {modules} m ON cm.module = m.id AND m.name = :modulename\n JOIN {assign} a ON cm.instance = a.id\n JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel\n JOIN {assign_overrides} ao ON a.id = ao.assignid\n WHERE ao.userid = :aouserid\"", ";", "$", "contextlist", "->", "add_from_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "$", "sql", "=", "\"SELECT ctx.id\n FROM {course_modules} cm\n JOIN {modules} m ON cm.module = m.id AND m.name = :modulename\n JOIN {assign} a ON cm.instance = a.id\n JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel\n JOIN {assign_submission} asn ON a.id = asn.assignment\n WHERE asn.userid = :asnuserid\"", ";", "$", "contextlist", "->", "add_from_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "$", "sql", "=", "\"SELECT ctx.id\n FROM {course_modules} cm\n JOIN {modules} m ON cm.module = m.id AND m.name = :modulename\n JOIN {assign} a ON cm.instance = a.id\n JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel\n JOIN {assign_user_flags} auf ON a.id = auf.assignment\n WHERE auf.userid = :aufuserid\"", ";", "$", "contextlist", "->", "add_from_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "$", "sql", "=", "\"SELECT ctx.id\n FROM {course_modules} cm\n JOIN {modules} m ON cm.module = m.id AND m.name = :modulename\n JOIN {assign} a ON cm.instance = a.id\n JOIN {context} ctx ON cm.id = ctx.instanceid AND ctx.contextlevel = :contextlevel\n JOIN {assign_user_mapping} aum ON a.id = aum.assignment\n WHERE aum.userid = :aumuserid\"", ";", "$", "contextlist", "->", "add_from_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "manager", "::", "plugintype_class_callback", "(", "'assignfeedback'", ",", "self", "::", "ASSIGNFEEDBACK_INTERFACE", ",", "'get_context_for_userid_within_feedback'", ",", "[", "$", "userid", ",", "$", "contextlist", "]", ")", ";", "manager", "::", "plugintype_class_callback", "(", "'assignsubmission'", ",", "self", "::", "ASSIGNSUBMISSION_INTERFACE", ",", "'get_context_for_userid_within_submission'", ",", "[", "$", "userid", ",", "$", "contextlist", "]", ")", ";", "return", "$", "contextlist", ";", "}" ]
Returns all of the contexts that has information relating to the userid. @param int $userid The user ID. @return contextlist an object with the contexts related to a userid.
[ "Returns", "all", "of", "the", "contexts", "that", "has", "information", "relating", "to", "the", "userid", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/classes/privacy/provider.php#L136-L202
217,664
moodle/moodle
mod/assign/classes/privacy/provider.php
provider.export_user_data
public static function export_user_data(approved_contextlist $contextlist) { foreach ($contextlist->get_contexts() as $context) { // Check that the context is a module context. if ($context->contextlevel != CONTEXT_MODULE) { continue; } $user = $contextlist->get_user(); $assigndata = helper::get_context_data($context, $user); helper::export_context_files($context, $user); writer::with_context($context)->export_data([], $assigndata); $assign = new \assign($context, null, null); // I need to find out if I'm a student or a teacher. if ($userids = self::get_graded_users($user->id, $assign)) { // Return teacher info. $currentpath = [get_string('privacy:studentpath', 'mod_assign')]; foreach ($userids as $studentuserid) { $studentpath = array_merge($currentpath, [$studentuserid->id]); static::export_submission($assign, $studentuserid, $context, $studentpath, true); } } static::export_overrides($context, $assign, $user); static::export_submission($assign, $user, $context, []); // Meta data. self::store_assign_user_flags($context, $assign, $user->id); if ($assign->is_blind_marking()) { $uniqueid = $assign->get_uniqueid_for_user_static($assign->get_instance()->id, $contextlist->get_user()->id); if ($uniqueid) { writer::with_context($context) ->export_metadata([get_string('blindmarking', 'mod_assign')], 'blindmarkingid', $uniqueid, get_string('privacy:blindmarkingidentifier', 'mod_assign')); } } } }
php
public static function export_user_data(approved_contextlist $contextlist) { foreach ($contextlist->get_contexts() as $context) { // Check that the context is a module context. if ($context->contextlevel != CONTEXT_MODULE) { continue; } $user = $contextlist->get_user(); $assigndata = helper::get_context_data($context, $user); helper::export_context_files($context, $user); writer::with_context($context)->export_data([], $assigndata); $assign = new \assign($context, null, null); // I need to find out if I'm a student or a teacher. if ($userids = self::get_graded_users($user->id, $assign)) { // Return teacher info. $currentpath = [get_string('privacy:studentpath', 'mod_assign')]; foreach ($userids as $studentuserid) { $studentpath = array_merge($currentpath, [$studentuserid->id]); static::export_submission($assign, $studentuserid, $context, $studentpath, true); } } static::export_overrides($context, $assign, $user); static::export_submission($assign, $user, $context, []); // Meta data. self::store_assign_user_flags($context, $assign, $user->id); if ($assign->is_blind_marking()) { $uniqueid = $assign->get_uniqueid_for_user_static($assign->get_instance()->id, $contextlist->get_user()->id); if ($uniqueid) { writer::with_context($context) ->export_metadata([get_string('blindmarking', 'mod_assign')], 'blindmarkingid', $uniqueid, get_string('privacy:blindmarkingidentifier', 'mod_assign')); } } } }
[ "public", "static", "function", "export_user_data", "(", "approved_contextlist", "$", "contextlist", ")", "{", "foreach", "(", "$", "contextlist", "->", "get_contexts", "(", ")", "as", "$", "context", ")", "{", "// Check that the context is a module context.", "if", "(", "$", "context", "->", "contextlevel", "!=", "CONTEXT_MODULE", ")", "{", "continue", ";", "}", "$", "user", "=", "$", "contextlist", "->", "get_user", "(", ")", ";", "$", "assigndata", "=", "helper", "::", "get_context_data", "(", "$", "context", ",", "$", "user", ")", ";", "helper", "::", "export_context_files", "(", "$", "context", ",", "$", "user", ")", ";", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_data", "(", "[", "]", ",", "$", "assigndata", ")", ";", "$", "assign", "=", "new", "\\", "assign", "(", "$", "context", ",", "null", ",", "null", ")", ";", "// I need to find out if I'm a student or a teacher.", "if", "(", "$", "userids", "=", "self", "::", "get_graded_users", "(", "$", "user", "->", "id", ",", "$", "assign", ")", ")", "{", "// Return teacher info.", "$", "currentpath", "=", "[", "get_string", "(", "'privacy:studentpath'", ",", "'mod_assign'", ")", "]", ";", "foreach", "(", "$", "userids", "as", "$", "studentuserid", ")", "{", "$", "studentpath", "=", "array_merge", "(", "$", "currentpath", ",", "[", "$", "studentuserid", "->", "id", "]", ")", ";", "static", "::", "export_submission", "(", "$", "assign", ",", "$", "studentuserid", ",", "$", "context", ",", "$", "studentpath", ",", "true", ")", ";", "}", "}", "static", "::", "export_overrides", "(", "$", "context", ",", "$", "assign", ",", "$", "user", ")", ";", "static", "::", "export_submission", "(", "$", "assign", ",", "$", "user", ",", "$", "context", ",", "[", "]", ")", ";", "// Meta data.", "self", "::", "store_assign_user_flags", "(", "$", "context", ",", "$", "assign", ",", "$", "user", "->", "id", ")", ";", "if", "(", "$", "assign", "->", "is_blind_marking", "(", ")", ")", "{", "$", "uniqueid", "=", "$", "assign", "->", "get_uniqueid_for_user_static", "(", "$", "assign", "->", "get_instance", "(", ")", "->", "id", ",", "$", "contextlist", "->", "get_user", "(", ")", "->", "id", ")", ";", "if", "(", "$", "uniqueid", ")", "{", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_metadata", "(", "[", "get_string", "(", "'blindmarking'", ",", "'mod_assign'", ")", "]", ",", "'blindmarkingid'", ",", "$", "uniqueid", ",", "get_string", "(", "'privacy:blindmarkingidentifier'", ",", "'mod_assign'", ")", ")", ";", "}", "}", "}", "}" ]
Write out the user data filtered by contexts. @param approved_contextlist $contextlist contexts that we are writing data out from.
[ "Write", "out", "the", "user", "data", "filtered", "by", "contexts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/classes/privacy/provider.php#L279-L315
217,665
moodle/moodle
mod/assign/classes/privacy/provider.php
provider.delete_data_for_all_users_in_context
public static function delete_data_for_all_users_in_context(\context $context) { global $DB; if ($context->contextlevel == CONTEXT_MODULE) { $cm = get_coursemodule_from_id('assign', $context->instanceid); if ($cm) { // Get the assignment related to this context. $assign = new \assign($context, null, null); // What to do first... Get sub plugins to delete their stuff. $requestdata = new assign_plugin_request_data($context, $assign); manager::plugintype_class_callback('assignsubmission', self::ASSIGNSUBMISSION_INTERFACE, 'delete_submission_for_context', [$requestdata]); $requestdata = new assign_plugin_request_data($context, $assign); manager::plugintype_class_callback('assignfeedback', self::ASSIGNFEEDBACK_INTERFACE, 'delete_feedback_for_context', [$requestdata]); $DB->delete_records('assign_grades', ['assignment' => $assign->get_instance()->id]); // Delete advanced grading information. $gradingmanager = get_grading_manager($context, 'mod_assign', 'submissions'); $controller = $gradingmanager->get_active_controller(); if (isset($controller)) { \core_grading\privacy\provider::delete_instance_data($context); } // Time to roll my own method for deleting overrides. static::delete_overrides_for_users($assign); $DB->delete_records('assign_submission', ['assignment' => $assign->get_instance()->id]); $DB->delete_records('assign_user_flags', ['assignment' => $assign->get_instance()->id]); $DB->delete_records('assign_user_mapping', ['assignment' => $assign->get_instance()->id]); } } }
php
public static function delete_data_for_all_users_in_context(\context $context) { global $DB; if ($context->contextlevel == CONTEXT_MODULE) { $cm = get_coursemodule_from_id('assign', $context->instanceid); if ($cm) { // Get the assignment related to this context. $assign = new \assign($context, null, null); // What to do first... Get sub plugins to delete their stuff. $requestdata = new assign_plugin_request_data($context, $assign); manager::plugintype_class_callback('assignsubmission', self::ASSIGNSUBMISSION_INTERFACE, 'delete_submission_for_context', [$requestdata]); $requestdata = new assign_plugin_request_data($context, $assign); manager::plugintype_class_callback('assignfeedback', self::ASSIGNFEEDBACK_INTERFACE, 'delete_feedback_for_context', [$requestdata]); $DB->delete_records('assign_grades', ['assignment' => $assign->get_instance()->id]); // Delete advanced grading information. $gradingmanager = get_grading_manager($context, 'mod_assign', 'submissions'); $controller = $gradingmanager->get_active_controller(); if (isset($controller)) { \core_grading\privacy\provider::delete_instance_data($context); } // Time to roll my own method for deleting overrides. static::delete_overrides_for_users($assign); $DB->delete_records('assign_submission', ['assignment' => $assign->get_instance()->id]); $DB->delete_records('assign_user_flags', ['assignment' => $assign->get_instance()->id]); $DB->delete_records('assign_user_mapping', ['assignment' => $assign->get_instance()->id]); } } }
[ "public", "static", "function", "delete_data_for_all_users_in_context", "(", "\\", "context", "$", "context", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "context", "->", "contextlevel", "==", "CONTEXT_MODULE", ")", "{", "$", "cm", "=", "get_coursemodule_from_id", "(", "'assign'", ",", "$", "context", "->", "instanceid", ")", ";", "if", "(", "$", "cm", ")", "{", "// Get the assignment related to this context.", "$", "assign", "=", "new", "\\", "assign", "(", "$", "context", ",", "null", ",", "null", ")", ";", "// What to do first... Get sub plugins to delete their stuff.", "$", "requestdata", "=", "new", "assign_plugin_request_data", "(", "$", "context", ",", "$", "assign", ")", ";", "manager", "::", "plugintype_class_callback", "(", "'assignsubmission'", ",", "self", "::", "ASSIGNSUBMISSION_INTERFACE", ",", "'delete_submission_for_context'", ",", "[", "$", "requestdata", "]", ")", ";", "$", "requestdata", "=", "new", "assign_plugin_request_data", "(", "$", "context", ",", "$", "assign", ")", ";", "manager", "::", "plugintype_class_callback", "(", "'assignfeedback'", ",", "self", "::", "ASSIGNFEEDBACK_INTERFACE", ",", "'delete_feedback_for_context'", ",", "[", "$", "requestdata", "]", ")", ";", "$", "DB", "->", "delete_records", "(", "'assign_grades'", ",", "[", "'assignment'", "=>", "$", "assign", "->", "get_instance", "(", ")", "->", "id", "]", ")", ";", "// Delete advanced grading information.", "$", "gradingmanager", "=", "get_grading_manager", "(", "$", "context", ",", "'mod_assign'", ",", "'submissions'", ")", ";", "$", "controller", "=", "$", "gradingmanager", "->", "get_active_controller", "(", ")", ";", "if", "(", "isset", "(", "$", "controller", ")", ")", "{", "\\", "core_grading", "\\", "privacy", "\\", "provider", "::", "delete_instance_data", "(", "$", "context", ")", ";", "}", "// Time to roll my own method for deleting overrides.", "static", "::", "delete_overrides_for_users", "(", "$", "assign", ")", ";", "$", "DB", "->", "delete_records", "(", "'assign_submission'", ",", "[", "'assignment'", "=>", "$", "assign", "->", "get_instance", "(", ")", "->", "id", "]", ")", ";", "$", "DB", "->", "delete_records", "(", "'assign_user_flags'", ",", "[", "'assignment'", "=>", "$", "assign", "->", "get_instance", "(", ")", "->", "id", "]", ")", ";", "$", "DB", "->", "delete_records", "(", "'assign_user_mapping'", ",", "[", "'assignment'", "=>", "$", "assign", "->", "get_instance", "(", ")", "->", "id", "]", ")", ";", "}", "}", "}" ]
Delete all use data which matches the specified context. @param \context $context The module context.
[ "Delete", "all", "use", "data", "which", "matches", "the", "specified", "context", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/classes/privacy/provider.php#L322-L353
217,666
moodle/moodle
mod/assign/classes/privacy/provider.php
provider.delete_overrides_for_users
protected static function delete_overrides_for_users(\assign $assign, array $userids = []) { global $DB; $assignid = $assign->get_instance()->id; $usersql = ''; $params = ['assignid' => $assignid]; if (!empty($userids)) { list($usersql, $userparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED); $params = array_merge($params, $userparams); $overrides = $DB->get_records_select('assign_overrides', "assignid = :assignid AND userid $usersql", $params); } else { $overrides = $DB->get_records('assign_overrides', $params); } if (!empty($overrides)) { $params = ['modulename' => 'assign', 'instance' => $assignid]; if (!empty($userids)) { $params = array_merge($params, $userparams); $DB->delete_records_select('event', "modulename = :modulename AND instance = :instance AND userid $usersql", $params); // Setting up for the next query. $params = $userparams; $usersql = "AND userid $usersql"; } else { $DB->delete_records('event', $params); // Setting up for the next query. $params = []; } list($overridesql, $overrideparams) = $DB->get_in_or_equal(array_keys($overrides), SQL_PARAMS_NAMED); $params = array_merge($params, $overrideparams); $DB->delete_records_select('assign_overrides', "id $overridesql $usersql", $params); } }
php
protected static function delete_overrides_for_users(\assign $assign, array $userids = []) { global $DB; $assignid = $assign->get_instance()->id; $usersql = ''; $params = ['assignid' => $assignid]; if (!empty($userids)) { list($usersql, $userparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED); $params = array_merge($params, $userparams); $overrides = $DB->get_records_select('assign_overrides', "assignid = :assignid AND userid $usersql", $params); } else { $overrides = $DB->get_records('assign_overrides', $params); } if (!empty($overrides)) { $params = ['modulename' => 'assign', 'instance' => $assignid]; if (!empty($userids)) { $params = array_merge($params, $userparams); $DB->delete_records_select('event', "modulename = :modulename AND instance = :instance AND userid $usersql", $params); // Setting up for the next query. $params = $userparams; $usersql = "AND userid $usersql"; } else { $DB->delete_records('event', $params); // Setting up for the next query. $params = []; } list($overridesql, $overrideparams) = $DB->get_in_or_equal(array_keys($overrides), SQL_PARAMS_NAMED); $params = array_merge($params, $overrideparams); $DB->delete_records_select('assign_overrides', "id $overridesql $usersql", $params); } }
[ "protected", "static", "function", "delete_overrides_for_users", "(", "\\", "assign", "$", "assign", ",", "array", "$", "userids", "=", "[", "]", ")", "{", "global", "$", "DB", ";", "$", "assignid", "=", "$", "assign", "->", "get_instance", "(", ")", "->", "id", ";", "$", "usersql", "=", "''", ";", "$", "params", "=", "[", "'assignid'", "=>", "$", "assignid", "]", ";", "if", "(", "!", "empty", "(", "$", "userids", ")", ")", "{", "list", "(", "$", "usersql", ",", "$", "userparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "userids", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "params", "=", "array_merge", "(", "$", "params", ",", "$", "userparams", ")", ";", "$", "overrides", "=", "$", "DB", "->", "get_records_select", "(", "'assign_overrides'", ",", "\"assignid = :assignid AND userid $usersql\"", ",", "$", "params", ")", ";", "}", "else", "{", "$", "overrides", "=", "$", "DB", "->", "get_records", "(", "'assign_overrides'", ",", "$", "params", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "overrides", ")", ")", "{", "$", "params", "=", "[", "'modulename'", "=>", "'assign'", ",", "'instance'", "=>", "$", "assignid", "]", ";", "if", "(", "!", "empty", "(", "$", "userids", ")", ")", "{", "$", "params", "=", "array_merge", "(", "$", "params", ",", "$", "userparams", ")", ";", "$", "DB", "->", "delete_records_select", "(", "'event'", ",", "\"modulename = :modulename AND instance = :instance AND userid $usersql\"", ",", "$", "params", ")", ";", "// Setting up for the next query.", "$", "params", "=", "$", "userparams", ";", "$", "usersql", "=", "\"AND userid $usersql\"", ";", "}", "else", "{", "$", "DB", "->", "delete_records", "(", "'event'", ",", "$", "params", ")", ";", "// Setting up for the next query.", "$", "params", "=", "[", "]", ";", "}", "list", "(", "$", "overridesql", ",", "$", "overrideparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "array_keys", "(", "$", "overrides", ")", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "params", "=", "array_merge", "(", "$", "params", ",", "$", "overrideparams", ")", ";", "$", "DB", "->", "delete_records_select", "(", "'assign_overrides'", ",", "\"id $overridesql $usersql\"", ",", "$", "params", ")", ";", "}", "}" ]
Deletes assignment overrides in bulk @param \assign $assign The assignment object @param array $userids An array of user IDs
[ "Deletes", "assignment", "overrides", "in", "bulk" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/classes/privacy/provider.php#L452-L483
217,667
moodle/moodle
mod/assign/classes/privacy/provider.php
provider.get_graded_users
protected static function get_graded_users(int $userid, \assign $assign) { $params = ['grader' => $userid, 'assignid' => $assign->get_instance()->id]; $sql = "SELECT DISTINCT userid AS id FROM {assign_grades} WHERE grader = :grader AND assignment = :assignid"; $useridlist = new useridlist($userid, $assign->get_instance()->id); $useridlist->add_from_sql($sql, $params); // Call sub-plugins to see if they have information not already collected. manager::plugintype_class_callback('assignsubmission', self::ASSIGNSUBMISSION_INTERFACE, 'get_student_user_ids', [$useridlist]); manager::plugintype_class_callback('assignfeedback', self::ASSIGNFEEDBACK_INTERFACE, 'get_student_user_ids', [$useridlist]); $userids = $useridlist->get_userids(); return ($userids) ? $userids : false; }
php
protected static function get_graded_users(int $userid, \assign $assign) { $params = ['grader' => $userid, 'assignid' => $assign->get_instance()->id]; $sql = "SELECT DISTINCT userid AS id FROM {assign_grades} WHERE grader = :grader AND assignment = :assignid"; $useridlist = new useridlist($userid, $assign->get_instance()->id); $useridlist->add_from_sql($sql, $params); // Call sub-plugins to see if they have information not already collected. manager::plugintype_class_callback('assignsubmission', self::ASSIGNSUBMISSION_INTERFACE, 'get_student_user_ids', [$useridlist]); manager::plugintype_class_callback('assignfeedback', self::ASSIGNFEEDBACK_INTERFACE, 'get_student_user_ids', [$useridlist]); $userids = $useridlist->get_userids(); return ($userids) ? $userids : false; }
[ "protected", "static", "function", "get_graded_users", "(", "int", "$", "userid", ",", "\\", "assign", "$", "assign", ")", "{", "$", "params", "=", "[", "'grader'", "=>", "$", "userid", ",", "'assignid'", "=>", "$", "assign", "->", "get_instance", "(", ")", "->", "id", "]", ";", "$", "sql", "=", "\"SELECT DISTINCT userid AS id\n FROM {assign_grades}\n WHERE grader = :grader AND assignment = :assignid\"", ";", "$", "useridlist", "=", "new", "useridlist", "(", "$", "userid", ",", "$", "assign", "->", "get_instance", "(", ")", "->", "id", ")", ";", "$", "useridlist", "->", "add_from_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "// Call sub-plugins to see if they have information not already collected.", "manager", "::", "plugintype_class_callback", "(", "'assignsubmission'", ",", "self", "::", "ASSIGNSUBMISSION_INTERFACE", ",", "'get_student_user_ids'", ",", "[", "$", "useridlist", "]", ")", ";", "manager", "::", "plugintype_class_callback", "(", "'assignfeedback'", ",", "self", "::", "ASSIGNFEEDBACK_INTERFACE", ",", "'get_student_user_ids'", ",", "[", "$", "useridlist", "]", ")", ";", "$", "userids", "=", "$", "useridlist", "->", "get_userids", "(", ")", ";", "return", "(", "$", "userids", ")", "?", "$", "userids", ":", "false", ";", "}" ]
Find out if this user has graded any users. @param int $userid The user ID (potential teacher). @param assign $assign The assignment object. @return array If successful an array of objects with userids that this user graded, otherwise false.
[ "Find", "out", "if", "this", "user", "has", "graded", "any", "users", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/classes/privacy/provider.php#L492-L509
217,668
moodle/moodle
mod/assign/classes/privacy/provider.php
provider.store_assign_user_flags
protected static function store_assign_user_flags(\context $context, \assign $assign, int $userid) { $datatypes = ['locked' => get_string('locksubmissions', 'mod_assign'), 'mailed' => get_string('privacy:metadata:mailed', 'mod_assign'), 'extensionduedate' => get_string('extensionduedate', 'mod_assign'), 'workflowstate' => get_string('markingworkflowstate', 'mod_assign'), 'allocatedmarker' => get_string('allocatedmarker_help', 'mod_assign')]; $userflags = (array)$assign->get_user_flags($userid, false); foreach ($datatypes as $key => $description) { if (isset($userflags[$key]) && !empty($userflags[$key])) { $value = $userflags[$key]; if ($key == 'locked' || $key == 'mailed') { $value = transform::yesno($value); } else if ($key == 'extensionduedate') { $value = transform::datetime($value); } writer::with_context($context)->export_metadata([], $key, $value, $description); } } }
php
protected static function store_assign_user_flags(\context $context, \assign $assign, int $userid) { $datatypes = ['locked' => get_string('locksubmissions', 'mod_assign'), 'mailed' => get_string('privacy:metadata:mailed', 'mod_assign'), 'extensionduedate' => get_string('extensionduedate', 'mod_assign'), 'workflowstate' => get_string('markingworkflowstate', 'mod_assign'), 'allocatedmarker' => get_string('allocatedmarker_help', 'mod_assign')]; $userflags = (array)$assign->get_user_flags($userid, false); foreach ($datatypes as $key => $description) { if (isset($userflags[$key]) && !empty($userflags[$key])) { $value = $userflags[$key]; if ($key == 'locked' || $key == 'mailed') { $value = transform::yesno($value); } else if ($key == 'extensionduedate') { $value = transform::datetime($value); } writer::with_context($context)->export_metadata([], $key, $value, $description); } } }
[ "protected", "static", "function", "store_assign_user_flags", "(", "\\", "context", "$", "context", ",", "\\", "assign", "$", "assign", ",", "int", "$", "userid", ")", "{", "$", "datatypes", "=", "[", "'locked'", "=>", "get_string", "(", "'locksubmissions'", ",", "'mod_assign'", ")", ",", "'mailed'", "=>", "get_string", "(", "'privacy:metadata:mailed'", ",", "'mod_assign'", ")", ",", "'extensionduedate'", "=>", "get_string", "(", "'extensionduedate'", ",", "'mod_assign'", ")", ",", "'workflowstate'", "=>", "get_string", "(", "'markingworkflowstate'", ",", "'mod_assign'", ")", ",", "'allocatedmarker'", "=>", "get_string", "(", "'allocatedmarker_help'", ",", "'mod_assign'", ")", "]", ";", "$", "userflags", "=", "(", "array", ")", "$", "assign", "->", "get_user_flags", "(", "$", "userid", ",", "false", ")", ";", "foreach", "(", "$", "datatypes", "as", "$", "key", "=>", "$", "description", ")", "{", "if", "(", "isset", "(", "$", "userflags", "[", "$", "key", "]", ")", "&&", "!", "empty", "(", "$", "userflags", "[", "$", "key", "]", ")", ")", "{", "$", "value", "=", "$", "userflags", "[", "$", "key", "]", ";", "if", "(", "$", "key", "==", "'locked'", "||", "$", "key", "==", "'mailed'", ")", "{", "$", "value", "=", "transform", "::", "yesno", "(", "$", "value", ")", ";", "}", "else", "if", "(", "$", "key", "==", "'extensionduedate'", ")", "{", "$", "value", "=", "transform", "::", "datetime", "(", "$", "value", ")", ";", "}", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_metadata", "(", "[", "]", ",", "$", "key", ",", "$", "value", ",", "$", "description", ")", ";", "}", "}", "}" ]
Writes out various user meta data about the assignment. @param \context $context The context of this assignment. @param \assign $assign The assignment object. @param int $userid The user ID
[ "Writes", "out", "various", "user", "meta", "data", "about", "the", "assignment", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/classes/privacy/provider.php#L518-L537
217,669
moodle/moodle
mod/assign/classes/privacy/provider.php
provider.export_grade_data
protected static function export_grade_data(\stdClass $grade, \context $context, array $currentpath) { $gradedata = (object)[ 'timecreated' => transform::datetime($grade->timecreated), 'timemodified' => transform::datetime($grade->timemodified), 'grader' => transform::user($grade->grader), 'grade' => $grade->grade, 'attemptnumber' => ($grade->attemptnumber + 1) ]; writer::with_context($context) ->export_data(array_merge($currentpath, [get_string('privacy:gradepath', 'mod_assign')]), $gradedata); }
php
protected static function export_grade_data(\stdClass $grade, \context $context, array $currentpath) { $gradedata = (object)[ 'timecreated' => transform::datetime($grade->timecreated), 'timemodified' => transform::datetime($grade->timemodified), 'grader' => transform::user($grade->grader), 'grade' => $grade->grade, 'attemptnumber' => ($grade->attemptnumber + 1) ]; writer::with_context($context) ->export_data(array_merge($currentpath, [get_string('privacy:gradepath', 'mod_assign')]), $gradedata); }
[ "protected", "static", "function", "export_grade_data", "(", "\\", "stdClass", "$", "grade", ",", "\\", "context", "$", "context", ",", "array", "$", "currentpath", ")", "{", "$", "gradedata", "=", "(", "object", ")", "[", "'timecreated'", "=>", "transform", "::", "datetime", "(", "$", "grade", "->", "timecreated", ")", ",", "'timemodified'", "=>", "transform", "::", "datetime", "(", "$", "grade", "->", "timemodified", ")", ",", "'grader'", "=>", "transform", "::", "user", "(", "$", "grade", "->", "grader", ")", ",", "'grade'", "=>", "$", "grade", "->", "grade", ",", "'attemptnumber'", "=>", "(", "$", "grade", "->", "attemptnumber", "+", "1", ")", "]", ";", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_data", "(", "array_merge", "(", "$", "currentpath", ",", "[", "get_string", "(", "'privacy:gradepath'", ",", "'mod_assign'", ")", "]", ")", ",", "$", "gradedata", ")", ";", "}" ]
Formats and then exports the user's grade data. @param \stdClass $grade The assign grade object @param \context $context The context object @param array $currentpath Current directory path that we are exporting to.
[ "Formats", "and", "then", "exports", "the", "user", "s", "grade", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/classes/privacy/provider.php#L546-L556
217,670
moodle/moodle
mod/assign/classes/privacy/provider.php
provider.export_submission_data
protected static function export_submission_data(\stdClass $submission, \context $context, array $currentpath) { $submissiondata = (object)[ 'timecreated' => transform::datetime($submission->timecreated), 'timemodified' => transform::datetime($submission->timemodified), 'status' => get_string('submissionstatus_' . $submission->status, 'mod_assign'), 'groupid' => $submission->groupid, 'attemptnumber' => ($submission->attemptnumber + 1), 'latest' => transform::yesno($submission->latest) ]; writer::with_context($context) ->export_data(array_merge($currentpath, [get_string('privacy:submissionpath', 'mod_assign')]), $submissiondata); }
php
protected static function export_submission_data(\stdClass $submission, \context $context, array $currentpath) { $submissiondata = (object)[ 'timecreated' => transform::datetime($submission->timecreated), 'timemodified' => transform::datetime($submission->timemodified), 'status' => get_string('submissionstatus_' . $submission->status, 'mod_assign'), 'groupid' => $submission->groupid, 'attemptnumber' => ($submission->attemptnumber + 1), 'latest' => transform::yesno($submission->latest) ]; writer::with_context($context) ->export_data(array_merge($currentpath, [get_string('privacy:submissionpath', 'mod_assign')]), $submissiondata); }
[ "protected", "static", "function", "export_submission_data", "(", "\\", "stdClass", "$", "submission", ",", "\\", "context", "$", "context", ",", "array", "$", "currentpath", ")", "{", "$", "submissiondata", "=", "(", "object", ")", "[", "'timecreated'", "=>", "transform", "::", "datetime", "(", "$", "submission", "->", "timecreated", ")", ",", "'timemodified'", "=>", "transform", "::", "datetime", "(", "$", "submission", "->", "timemodified", ")", ",", "'status'", "=>", "get_string", "(", "'submissionstatus_'", ".", "$", "submission", "->", "status", ",", "'mod_assign'", ")", ",", "'groupid'", "=>", "$", "submission", "->", "groupid", ",", "'attemptnumber'", "=>", "(", "$", "submission", "->", "attemptnumber", "+", "1", ")", ",", "'latest'", "=>", "transform", "::", "yesno", "(", "$", "submission", "->", "latest", ")", "]", ";", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_data", "(", "array_merge", "(", "$", "currentpath", ",", "[", "get_string", "(", "'privacy:submissionpath'", ",", "'mod_assign'", ")", "]", ")", ",", "$", "submissiondata", ")", ";", "}" ]
Formats and then exports the user's submission data. @param \stdClass $submission The assign submission object @param \context $context The context object @param array $currentpath Current directory path that we are exporting to.
[ "Formats", "and", "then", "exports", "the", "user", "s", "submission", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/classes/privacy/provider.php#L565-L576
217,671
moodle/moodle
mod/assign/classes/privacy/provider.php
provider.export_user_preferences
public static function export_user_preferences(int $userid) { $context = \context_system::instance(); $assignpreferences = [ 'assign_perpage' => ['string' => get_string('privacy:metadata:assignperpage', 'mod_assign'), 'bool' => false], 'assign_filter' => ['string' => get_string('privacy:metadata:assignfilter', 'mod_assign'), 'bool' => false], 'assign_markerfilter' => ['string' => get_string('privacy:metadata:assignmarkerfilter', 'mod_assign'), 'bool' => true], 'assign_workflowfilter' => ['string' => get_string('privacy:metadata:assignworkflowfilter', 'mod_assign'), 'bool' => true], 'assign_quickgrading' => ['string' => get_string('privacy:metadata:assignquickgrading', 'mod_assign'), 'bool' => true], 'assign_downloadasfolders' => ['string' => get_string('privacy:metadata:assigndownloadasfolders', 'mod_assign'), 'bool' => true] ]; foreach ($assignpreferences as $key => $preference) { $value = get_user_preferences($key, null, $userid); if ($preference['bool']) { $value = transform::yesno($value); } if (isset($value)) { writer::with_context($context)->export_user_preference('mod_assign', $key, $value, $preference['string']); } } }
php
public static function export_user_preferences(int $userid) { $context = \context_system::instance(); $assignpreferences = [ 'assign_perpage' => ['string' => get_string('privacy:metadata:assignperpage', 'mod_assign'), 'bool' => false], 'assign_filter' => ['string' => get_string('privacy:metadata:assignfilter', 'mod_assign'), 'bool' => false], 'assign_markerfilter' => ['string' => get_string('privacy:metadata:assignmarkerfilter', 'mod_assign'), 'bool' => true], 'assign_workflowfilter' => ['string' => get_string('privacy:metadata:assignworkflowfilter', 'mod_assign'), 'bool' => true], 'assign_quickgrading' => ['string' => get_string('privacy:metadata:assignquickgrading', 'mod_assign'), 'bool' => true], 'assign_downloadasfolders' => ['string' => get_string('privacy:metadata:assigndownloadasfolders', 'mod_assign'), 'bool' => true] ]; foreach ($assignpreferences as $key => $preference) { $value = get_user_preferences($key, null, $userid); if ($preference['bool']) { $value = transform::yesno($value); } if (isset($value)) { writer::with_context($context)->export_user_preference('mod_assign', $key, $value, $preference['string']); } } }
[ "public", "static", "function", "export_user_preferences", "(", "int", "$", "userid", ")", "{", "$", "context", "=", "\\", "context_system", "::", "instance", "(", ")", ";", "$", "assignpreferences", "=", "[", "'assign_perpage'", "=>", "[", "'string'", "=>", "get_string", "(", "'privacy:metadata:assignperpage'", ",", "'mod_assign'", ")", ",", "'bool'", "=>", "false", "]", ",", "'assign_filter'", "=>", "[", "'string'", "=>", "get_string", "(", "'privacy:metadata:assignfilter'", ",", "'mod_assign'", ")", ",", "'bool'", "=>", "false", "]", ",", "'assign_markerfilter'", "=>", "[", "'string'", "=>", "get_string", "(", "'privacy:metadata:assignmarkerfilter'", ",", "'mod_assign'", ")", ",", "'bool'", "=>", "true", "]", ",", "'assign_workflowfilter'", "=>", "[", "'string'", "=>", "get_string", "(", "'privacy:metadata:assignworkflowfilter'", ",", "'mod_assign'", ")", ",", "'bool'", "=>", "true", "]", ",", "'assign_quickgrading'", "=>", "[", "'string'", "=>", "get_string", "(", "'privacy:metadata:assignquickgrading'", ",", "'mod_assign'", ")", ",", "'bool'", "=>", "true", "]", ",", "'assign_downloadasfolders'", "=>", "[", "'string'", "=>", "get_string", "(", "'privacy:metadata:assigndownloadasfolders'", ",", "'mod_assign'", ")", ",", "'bool'", "=>", "true", "]", "]", ";", "foreach", "(", "$", "assignpreferences", "as", "$", "key", "=>", "$", "preference", ")", "{", "$", "value", "=", "get_user_preferences", "(", "$", "key", ",", "null", ",", "$", "userid", ")", ";", "if", "(", "$", "preference", "[", "'bool'", "]", ")", "{", "$", "value", "=", "transform", "::", "yesno", "(", "$", "value", ")", ";", "}", "if", "(", "isset", "(", "$", "value", ")", ")", "{", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_user_preference", "(", "'mod_assign'", ",", "$", "key", ",", "$", "value", ",", "$", "preference", "[", "'string'", "]", ")", ";", "}", "}", "}" ]
Stores the user preferences related to mod_assign. @param int $userid The user ID that we want the preferences for.
[ "Stores", "the", "user", "preferences", "related", "to", "mod_assign", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/classes/privacy/provider.php#L583-L604
217,672
moodle/moodle
mod/assign/classes/privacy/provider.php
provider.export_overrides
public static function export_overrides(\context $context, \assign $assign, \stdClass $user) { $overrides = $assign->override_exists($user->id); // Overrides returns an array with data in it, but an override with actual data will have the assign ID set. if (isset($overrides->assignid)) { $data = new \stdClass(); if (!empty($overrides->duedate)) { $data->duedate = transform::datetime($overrides->duedate); } if (!empty($overrides->cutoffdate)) { $data->cutoffdate = transform::datetime($overrides->cutoffdate); } if (!empty($overrides->allowsubmissionsfromdate)) { $data->allowsubmissionsfromdate = transform::datetime($overrides->allowsubmissionsfromdate); } if (!empty($data)) { writer::with_context($context)->export_data([get_string('overrides', 'mod_assign')], $data); } } }
php
public static function export_overrides(\context $context, \assign $assign, \stdClass $user) { $overrides = $assign->override_exists($user->id); // Overrides returns an array with data in it, but an override with actual data will have the assign ID set. if (isset($overrides->assignid)) { $data = new \stdClass(); if (!empty($overrides->duedate)) { $data->duedate = transform::datetime($overrides->duedate); } if (!empty($overrides->cutoffdate)) { $data->cutoffdate = transform::datetime($overrides->cutoffdate); } if (!empty($overrides->allowsubmissionsfromdate)) { $data->allowsubmissionsfromdate = transform::datetime($overrides->allowsubmissionsfromdate); } if (!empty($data)) { writer::with_context($context)->export_data([get_string('overrides', 'mod_assign')], $data); } } }
[ "public", "static", "function", "export_overrides", "(", "\\", "context", "$", "context", ",", "\\", "assign", "$", "assign", ",", "\\", "stdClass", "$", "user", ")", "{", "$", "overrides", "=", "$", "assign", "->", "override_exists", "(", "$", "user", "->", "id", ")", ";", "// Overrides returns an array with data in it, but an override with actual data will have the assign ID set.", "if", "(", "isset", "(", "$", "overrides", "->", "assignid", ")", ")", "{", "$", "data", "=", "new", "\\", "stdClass", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "overrides", "->", "duedate", ")", ")", "{", "$", "data", "->", "duedate", "=", "transform", "::", "datetime", "(", "$", "overrides", "->", "duedate", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "overrides", "->", "cutoffdate", ")", ")", "{", "$", "data", "->", "cutoffdate", "=", "transform", "::", "datetime", "(", "$", "overrides", "->", "cutoffdate", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "overrides", "->", "allowsubmissionsfromdate", ")", ")", "{", "$", "data", "->", "allowsubmissionsfromdate", "=", "transform", "::", "datetime", "(", "$", "overrides", "->", "allowsubmissionsfromdate", ")", ";", "}", "if", "(", "!", "empty", "(", "$", "data", ")", ")", "{", "writer", "::", "with_context", "(", "$", "context", ")", "->", "export_data", "(", "[", "get_string", "(", "'overrides'", ",", "'mod_assign'", ")", "]", ",", "$", "data", ")", ";", "}", "}", "}" ]
Export overrides for this assignment. @param \context $context Context @param \assign $assign The assign object. @param \stdClass $user The user object.
[ "Export", "overrides", "for", "this", "assignment", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/classes/privacy/provider.php#L613-L632
217,673
moodle/moodle
mod/assign/classes/privacy/provider.php
provider.export_submission
protected static function export_submission(\assign $assign, \stdClass $user, \context_module $context, array $path, bool $exportforteacher = false) { $submissions = $assign->get_all_submissions($user->id); $teacher = ($exportforteacher) ? $user : null; $gradingmanager = get_grading_manager($context, 'mod_assign', 'submissions'); $controller = $gradingmanager->get_active_controller(); foreach ($submissions as $submission) { // Attempt numbers start at zero, which is fine for programming, but doesn't make as much sense // for users. $submissionpath = array_merge($path, [get_string('privacy:attemptpath', 'mod_assign', ($submission->attemptnumber + 1))]); $params = new assign_plugin_request_data($context, $assign, $submission, $submissionpath ,$teacher); manager::plugintype_class_callback('assignsubmission', self::ASSIGNSUBMISSION_INTERFACE, 'export_submission_user_data', [$params]); if (!isset($teacher)) { self::export_submission_data($submission, $context, $submissionpath); } $grade = $assign->get_user_grade($user->id, false, $submission->attemptnumber); if ($grade) { $params = new assign_plugin_request_data($context, $assign, $grade, $submissionpath, $teacher); manager::plugintype_class_callback('assignfeedback', self::ASSIGNFEEDBACK_INTERFACE, 'export_feedback_user_data', [$params]); self::export_grade_data($grade, $context, $submissionpath); // Check for advanced grading and retrieve that information. if (isset($controller)) { \core_grading\privacy\provider::export_item_data($context, $grade->id, $submissionpath); } } } }
php
protected static function export_submission(\assign $assign, \stdClass $user, \context_module $context, array $path, bool $exportforteacher = false) { $submissions = $assign->get_all_submissions($user->id); $teacher = ($exportforteacher) ? $user : null; $gradingmanager = get_grading_manager($context, 'mod_assign', 'submissions'); $controller = $gradingmanager->get_active_controller(); foreach ($submissions as $submission) { // Attempt numbers start at zero, which is fine for programming, but doesn't make as much sense // for users. $submissionpath = array_merge($path, [get_string('privacy:attemptpath', 'mod_assign', ($submission->attemptnumber + 1))]); $params = new assign_plugin_request_data($context, $assign, $submission, $submissionpath ,$teacher); manager::plugintype_class_callback('assignsubmission', self::ASSIGNSUBMISSION_INTERFACE, 'export_submission_user_data', [$params]); if (!isset($teacher)) { self::export_submission_data($submission, $context, $submissionpath); } $grade = $assign->get_user_grade($user->id, false, $submission->attemptnumber); if ($grade) { $params = new assign_plugin_request_data($context, $assign, $grade, $submissionpath, $teacher); manager::plugintype_class_callback('assignfeedback', self::ASSIGNFEEDBACK_INTERFACE, 'export_feedback_user_data', [$params]); self::export_grade_data($grade, $context, $submissionpath); // Check for advanced grading and retrieve that information. if (isset($controller)) { \core_grading\privacy\provider::export_item_data($context, $grade->id, $submissionpath); } } } }
[ "protected", "static", "function", "export_submission", "(", "\\", "assign", "$", "assign", ",", "\\", "stdClass", "$", "user", ",", "\\", "context_module", "$", "context", ",", "array", "$", "path", ",", "bool", "$", "exportforteacher", "=", "false", ")", "{", "$", "submissions", "=", "$", "assign", "->", "get_all_submissions", "(", "$", "user", "->", "id", ")", ";", "$", "teacher", "=", "(", "$", "exportforteacher", ")", "?", "$", "user", ":", "null", ";", "$", "gradingmanager", "=", "get_grading_manager", "(", "$", "context", ",", "'mod_assign'", ",", "'submissions'", ")", ";", "$", "controller", "=", "$", "gradingmanager", "->", "get_active_controller", "(", ")", ";", "foreach", "(", "$", "submissions", "as", "$", "submission", ")", "{", "// Attempt numbers start at zero, which is fine for programming, but doesn't make as much sense", "// for users.", "$", "submissionpath", "=", "array_merge", "(", "$", "path", ",", "[", "get_string", "(", "'privacy:attemptpath'", ",", "'mod_assign'", ",", "(", "$", "submission", "->", "attemptnumber", "+", "1", ")", ")", "]", ")", ";", "$", "params", "=", "new", "assign_plugin_request_data", "(", "$", "context", ",", "$", "assign", ",", "$", "submission", ",", "$", "submissionpath", ",", "$", "teacher", ")", ";", "manager", "::", "plugintype_class_callback", "(", "'assignsubmission'", ",", "self", "::", "ASSIGNSUBMISSION_INTERFACE", ",", "'export_submission_user_data'", ",", "[", "$", "params", "]", ")", ";", "if", "(", "!", "isset", "(", "$", "teacher", ")", ")", "{", "self", "::", "export_submission_data", "(", "$", "submission", ",", "$", "context", ",", "$", "submissionpath", ")", ";", "}", "$", "grade", "=", "$", "assign", "->", "get_user_grade", "(", "$", "user", "->", "id", ",", "false", ",", "$", "submission", "->", "attemptnumber", ")", ";", "if", "(", "$", "grade", ")", "{", "$", "params", "=", "new", "assign_plugin_request_data", "(", "$", "context", ",", "$", "assign", ",", "$", "grade", ",", "$", "submissionpath", ",", "$", "teacher", ")", ";", "manager", "::", "plugintype_class_callback", "(", "'assignfeedback'", ",", "self", "::", "ASSIGNFEEDBACK_INTERFACE", ",", "'export_feedback_user_data'", ",", "[", "$", "params", "]", ")", ";", "self", "::", "export_grade_data", "(", "$", "grade", ",", "$", "context", ",", "$", "submissionpath", ")", ";", "// Check for advanced grading and retrieve that information.", "if", "(", "isset", "(", "$", "controller", ")", ")", "{", "\\", "core_grading", "\\", "privacy", "\\", "provider", "::", "export_item_data", "(", "$", "context", ",", "$", "grade", "->", "id", ",", "$", "submissionpath", ")", ";", "}", "}", "}", "}" ]
Exports assignment submission data for a user. @param \assign $assign The assignment object @param \stdClass $user The user object @param \context_module $context The context @param array $path The path for exporting data @param bool|boolean $exportforteacher A flag for if this is exporting data as a teacher.
[ "Exports", "assignment", "submission", "data", "for", "a", "user", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/classes/privacy/provider.php#L643-L674
217,674
moodle/moodle
mod/forum/classes/local/builders/exported_discussion_summaries.php
exported_discussion_summaries.get_favourites
private function get_favourites(stdClass $user) : array { $ids = []; if (isloggedin()) { $usercontext = \context_user::instance($user->id); $ufservice = \core_favourites\service_factory::get_service_for_user_context($usercontext); $favourites = $ufservice->find_favourites_by_type('mod_forum', 'discussions'); foreach ($favourites as $favourite) { $ids[] = $favourite->itemid; } } return $ids; }
php
private function get_favourites(stdClass $user) : array { $ids = []; if (isloggedin()) { $usercontext = \context_user::instance($user->id); $ufservice = \core_favourites\service_factory::get_service_for_user_context($usercontext); $favourites = $ufservice->find_favourites_by_type('mod_forum', 'discussions'); foreach ($favourites as $favourite) { $ids[] = $favourite->itemid; } } return $ids; }
[ "private", "function", "get_favourites", "(", "stdClass", "$", "user", ")", ":", "array", "{", "$", "ids", "=", "[", "]", ";", "if", "(", "isloggedin", "(", ")", ")", "{", "$", "usercontext", "=", "\\", "context_user", "::", "instance", "(", "$", "user", "->", "id", ")", ";", "$", "ufservice", "=", "\\", "core_favourites", "\\", "service_factory", "::", "get_service_for_user_context", "(", "$", "usercontext", ")", ";", "$", "favourites", "=", "$", "ufservice", "->", "find_favourites_by_type", "(", "'mod_forum'", ",", "'discussions'", ")", ";", "foreach", "(", "$", "favourites", "as", "$", "favourite", ")", "{", "$", "ids", "[", "]", "=", "$", "favourite", "->", "itemid", ";", "}", "}", "return", "$", "ids", ";", "}" ]
Get a list of all favourited discussions. @param stdClass $user The user we are getting favourites for @return int[] A list of favourited itemids
[ "Get", "a", "list", "of", "all", "favourited", "discussions", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/builders/exported_discussion_summaries.php#L189-L202
217,675
moodle/moodle
mod/forum/classes/local/builders/exported_discussion_summaries.php
exported_discussion_summaries.get_author_groups_from_posts
private function get_author_groups_from_posts(array $posts, $forum) : array { $course = $forum->get_course_record(); $coursemodule = $forum->get_course_module_record(); $authorids = array_reduce($posts, function($carry, $post) { $carry[$post->get_author_id()] = true; return $carry; }, []); $authorgroups = groups_get_all_groups($course->id, array_keys($authorids), $coursemodule->groupingid, 'g.*, gm.id, gm.groupid, gm.userid'); $authorgroups = array_reduce($authorgroups, function($carry, $group) { // Clean up data returned from groups_get_all_groups. $userid = $group->userid; $groupid = $group->groupid; unset($group->userid); unset($group->groupid); $group->id = $groupid; if (!isset($carry[$userid])) { $carry[$userid] = [$group]; } else { $carry[$userid][] = $group; } return $carry; }, []); foreach (array_diff(array_keys($authorids), array_keys($authorgroups)) as $authorid) { $authorgroups[$authorid] = []; } return $authorgroups; }
php
private function get_author_groups_from_posts(array $posts, $forum) : array { $course = $forum->get_course_record(); $coursemodule = $forum->get_course_module_record(); $authorids = array_reduce($posts, function($carry, $post) { $carry[$post->get_author_id()] = true; return $carry; }, []); $authorgroups = groups_get_all_groups($course->id, array_keys($authorids), $coursemodule->groupingid, 'g.*, gm.id, gm.groupid, gm.userid'); $authorgroups = array_reduce($authorgroups, function($carry, $group) { // Clean up data returned from groups_get_all_groups. $userid = $group->userid; $groupid = $group->groupid; unset($group->userid); unset($group->groupid); $group->id = $groupid; if (!isset($carry[$userid])) { $carry[$userid] = [$group]; } else { $carry[$userid][] = $group; } return $carry; }, []); foreach (array_diff(array_keys($authorids), array_keys($authorgroups)) as $authorid) { $authorgroups[$authorid] = []; } return $authorgroups; }
[ "private", "function", "get_author_groups_from_posts", "(", "array", "$", "posts", ",", "$", "forum", ")", ":", "array", "{", "$", "course", "=", "$", "forum", "->", "get_course_record", "(", ")", ";", "$", "coursemodule", "=", "$", "forum", "->", "get_course_module_record", "(", ")", ";", "$", "authorids", "=", "array_reduce", "(", "$", "posts", ",", "function", "(", "$", "carry", ",", "$", "post", ")", "{", "$", "carry", "[", "$", "post", "->", "get_author_id", "(", ")", "]", "=", "true", ";", "return", "$", "carry", ";", "}", ",", "[", "]", ")", ";", "$", "authorgroups", "=", "groups_get_all_groups", "(", "$", "course", "->", "id", ",", "array_keys", "(", "$", "authorids", ")", ",", "$", "coursemodule", "->", "groupingid", ",", "'g.*, gm.id, gm.groupid, gm.userid'", ")", ";", "$", "authorgroups", "=", "array_reduce", "(", "$", "authorgroups", ",", "function", "(", "$", "carry", ",", "$", "group", ")", "{", "// Clean up data returned from groups_get_all_groups.", "$", "userid", "=", "$", "group", "->", "userid", ";", "$", "groupid", "=", "$", "group", "->", "groupid", ";", "unset", "(", "$", "group", "->", "userid", ")", ";", "unset", "(", "$", "group", "->", "groupid", ")", ";", "$", "group", "->", "id", "=", "$", "groupid", ";", "if", "(", "!", "isset", "(", "$", "carry", "[", "$", "userid", "]", ")", ")", "{", "$", "carry", "[", "$", "userid", "]", "=", "[", "$", "group", "]", ";", "}", "else", "{", "$", "carry", "[", "$", "userid", "]", "[", "]", "=", "$", "group", ";", "}", "return", "$", "carry", ";", "}", ",", "[", "]", ")", ";", "foreach", "(", "array_diff", "(", "array_keys", "(", "$", "authorids", ")", ",", "array_keys", "(", "$", "authorgroups", ")", ")", "as", "$", "authorid", ")", "{", "$", "authorgroups", "[", "$", "authorid", "]", "=", "[", "]", ";", "}", "return", "$", "authorgroups", ";", "}" ]
Get the author's groups for a list of posts. @param post_entity[] $posts The list of posts @param forum_entity $forum The forum entity @return array Author groups indexed by author id
[ "Get", "the", "author", "s", "groups", "for", "a", "list", "of", "posts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/forum/classes/local/builders/exported_discussion_summaries.php#L223-L256
217,676
moodle/moodle
lib/spout/src/Spout/Reader/XLSX/Helper/SharedStringsHelper.php
SharedStringsHelper.hasSharedStrings
public function hasSharedStrings() { $hasSharedStrings = false; $zip = new \ZipArchive(); if ($zip->open($this->filePath) === true) { $hasSharedStrings = ($zip->locateName(self::SHARED_STRINGS_XML_FILE_PATH) !== false); $zip->close(); } return $hasSharedStrings; }
php
public function hasSharedStrings() { $hasSharedStrings = false; $zip = new \ZipArchive(); if ($zip->open($this->filePath) === true) { $hasSharedStrings = ($zip->locateName(self::SHARED_STRINGS_XML_FILE_PATH) !== false); $zip->close(); } return $hasSharedStrings; }
[ "public", "function", "hasSharedStrings", "(", ")", "{", "$", "hasSharedStrings", "=", "false", ";", "$", "zip", "=", "new", "\\", "ZipArchive", "(", ")", ";", "if", "(", "$", "zip", "->", "open", "(", "$", "this", "->", "filePath", ")", "===", "true", ")", "{", "$", "hasSharedStrings", "=", "(", "$", "zip", "->", "locateName", "(", "self", "::", "SHARED_STRINGS_XML_FILE_PATH", ")", "!==", "false", ")", ";", "$", "zip", "->", "close", "(", ")", ";", "}", "return", "$", "hasSharedStrings", ";", "}" ]
Returns whether the XLSX file contains a shared strings XML file @return bool
[ "Returns", "whether", "the", "XLSX", "file", "contains", "a", "shared", "strings", "XML", "file" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Reader/XLSX/Helper/SharedStringsHelper.php#L61-L72
217,677
moodle/moodle
lib/spout/src/Spout/Reader/XLSX/Helper/SharedStringsHelper.php
SharedStringsHelper.processSharedStringsItem
protected function processSharedStringsItem($xmlReader, $sharedStringIndex) { $sharedStringValue = ''; // NOTE: expand() will automatically decode all XML entities of the child nodes $siNode = $xmlReader->expand(); $textNodes = $siNode->getElementsByTagName(self::XML_NODE_T); foreach ($textNodes as $textNode) { if ($this->shouldExtractTextNodeValue($textNode)) { $textNodeValue = $textNode->nodeValue; $shouldPreserveWhitespace = $this->shouldPreserveWhitespace($textNode); $sharedStringValue .= ($shouldPreserveWhitespace) ? $textNodeValue : trim($textNodeValue); } } $this->cachingStrategy->addStringForIndex($sharedStringValue, $sharedStringIndex); }
php
protected function processSharedStringsItem($xmlReader, $sharedStringIndex) { $sharedStringValue = ''; // NOTE: expand() will automatically decode all XML entities of the child nodes $siNode = $xmlReader->expand(); $textNodes = $siNode->getElementsByTagName(self::XML_NODE_T); foreach ($textNodes as $textNode) { if ($this->shouldExtractTextNodeValue($textNode)) { $textNodeValue = $textNode->nodeValue; $shouldPreserveWhitespace = $this->shouldPreserveWhitespace($textNode); $sharedStringValue .= ($shouldPreserveWhitespace) ? $textNodeValue : trim($textNodeValue); } } $this->cachingStrategy->addStringForIndex($sharedStringValue, $sharedStringIndex); }
[ "protected", "function", "processSharedStringsItem", "(", "$", "xmlReader", ",", "$", "sharedStringIndex", ")", "{", "$", "sharedStringValue", "=", "''", ";", "// NOTE: expand() will automatically decode all XML entities of the child nodes", "$", "siNode", "=", "$", "xmlReader", "->", "expand", "(", ")", ";", "$", "textNodes", "=", "$", "siNode", "->", "getElementsByTagName", "(", "self", "::", "XML_NODE_T", ")", ";", "foreach", "(", "$", "textNodes", "as", "$", "textNode", ")", "{", "if", "(", "$", "this", "->", "shouldExtractTextNodeValue", "(", "$", "textNode", ")", ")", "{", "$", "textNodeValue", "=", "$", "textNode", "->", "nodeValue", ";", "$", "shouldPreserveWhitespace", "=", "$", "this", "->", "shouldPreserveWhitespace", "(", "$", "textNode", ")", ";", "$", "sharedStringValue", ".=", "(", "$", "shouldPreserveWhitespace", ")", "?", "$", "textNodeValue", ":", "trim", "(", "$", "textNodeValue", ")", ";", "}", "}", "$", "this", "->", "cachingStrategy", "->", "addStringForIndex", "(", "$", "sharedStringValue", ",", "$", "sharedStringIndex", ")", ";", "}" ]
Processes the shared strings item XML node which the given XML reader is positioned on. @param \Box\Spout\Reader\Wrapper\XMLReader $xmlReader XML Reader positioned on a "<si>" node @param int $sharedStringIndex Index of the processed shared strings item @return void
[ "Processes", "the", "shared", "strings", "item", "XML", "node", "which", "the", "given", "XML", "reader", "is", "positioned", "on", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Reader/XLSX/Helper/SharedStringsHelper.php#L165-L183
217,678
moodle/moodle
course/edit_form.php
course_edit_form.definition_after_data
function definition_after_data() { global $DB; $mform = $this->_form; // add available groupings $courseid = $mform->getElementValue('id'); if ($courseid and $mform->elementExists('defaultgroupingid')) { $options = array(); if ($groupings = $DB->get_records('groupings', array('courseid'=>$courseid))) { foreach ($groupings as $grouping) { $options[$grouping->id] = format_string($grouping->name); } } core_collator::asort($options); $gr_el =& $mform->getElement('defaultgroupingid'); $gr_el->load($options); } // add course format options $formatvalue = $mform->getElementValue('format'); if (is_array($formatvalue) && !empty($formatvalue)) { $params = array('format' => $formatvalue[0]); // Load the course as well if it is available, course formats may need it to work out // they preferred course end date. if ($courseid) { $params['id'] = $courseid; } $courseformat = course_get_format((object)$params); $elements = $courseformat->create_edit_form_elements($mform); for ($i = 0; $i < count($elements); $i++) { $mform->insertElementBefore($mform->removeElement($elements[$i]->getName(), false), 'addcourseformatoptionshere'); } // Remove newsitems element if format does not support news. if (!$courseformat->supports_news()) { $mform->removeElement('newsitems'); } } // Tweak the form with values provided by custom fields in use. $handler = core_course\customfield\course_handler::create(); $handler->instance_form_definition_after_data($mform, empty($courseid) ? 0 : $courseid); }
php
function definition_after_data() { global $DB; $mform = $this->_form; // add available groupings $courseid = $mform->getElementValue('id'); if ($courseid and $mform->elementExists('defaultgroupingid')) { $options = array(); if ($groupings = $DB->get_records('groupings', array('courseid'=>$courseid))) { foreach ($groupings as $grouping) { $options[$grouping->id] = format_string($grouping->name); } } core_collator::asort($options); $gr_el =& $mform->getElement('defaultgroupingid'); $gr_el->load($options); } // add course format options $formatvalue = $mform->getElementValue('format'); if (is_array($formatvalue) && !empty($formatvalue)) { $params = array('format' => $formatvalue[0]); // Load the course as well if it is available, course formats may need it to work out // they preferred course end date. if ($courseid) { $params['id'] = $courseid; } $courseformat = course_get_format((object)$params); $elements = $courseformat->create_edit_form_elements($mform); for ($i = 0; $i < count($elements); $i++) { $mform->insertElementBefore($mform->removeElement($elements[$i]->getName(), false), 'addcourseformatoptionshere'); } // Remove newsitems element if format does not support news. if (!$courseformat->supports_news()) { $mform->removeElement('newsitems'); } } // Tweak the form with values provided by custom fields in use. $handler = core_course\customfield\course_handler::create(); $handler->instance_form_definition_after_data($mform, empty($courseid) ? 0 : $courseid); }
[ "function", "definition_after_data", "(", ")", "{", "global", "$", "DB", ";", "$", "mform", "=", "$", "this", "->", "_form", ";", "// add available groupings", "$", "courseid", "=", "$", "mform", "->", "getElementValue", "(", "'id'", ")", ";", "if", "(", "$", "courseid", "and", "$", "mform", "->", "elementExists", "(", "'defaultgroupingid'", ")", ")", "{", "$", "options", "=", "array", "(", ")", ";", "if", "(", "$", "groupings", "=", "$", "DB", "->", "get_records", "(", "'groupings'", ",", "array", "(", "'courseid'", "=>", "$", "courseid", ")", ")", ")", "{", "foreach", "(", "$", "groupings", "as", "$", "grouping", ")", "{", "$", "options", "[", "$", "grouping", "->", "id", "]", "=", "format_string", "(", "$", "grouping", "->", "name", ")", ";", "}", "}", "core_collator", "::", "asort", "(", "$", "options", ")", ";", "$", "gr_el", "=", "&", "$", "mform", "->", "getElement", "(", "'defaultgroupingid'", ")", ";", "$", "gr_el", "->", "load", "(", "$", "options", ")", ";", "}", "// add course format options", "$", "formatvalue", "=", "$", "mform", "->", "getElementValue", "(", "'format'", ")", ";", "if", "(", "is_array", "(", "$", "formatvalue", ")", "&&", "!", "empty", "(", "$", "formatvalue", ")", ")", "{", "$", "params", "=", "array", "(", "'format'", "=>", "$", "formatvalue", "[", "0", "]", ")", ";", "// Load the course as well if it is available, course formats may need it to work out", "// they preferred course end date.", "if", "(", "$", "courseid", ")", "{", "$", "params", "[", "'id'", "]", "=", "$", "courseid", ";", "}", "$", "courseformat", "=", "course_get_format", "(", "(", "object", ")", "$", "params", ")", ";", "$", "elements", "=", "$", "courseformat", "->", "create_edit_form_elements", "(", "$", "mform", ")", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "elements", ")", ";", "$", "i", "++", ")", "{", "$", "mform", "->", "insertElementBefore", "(", "$", "mform", "->", "removeElement", "(", "$", "elements", "[", "$", "i", "]", "->", "getName", "(", ")", ",", "false", ")", ",", "'addcourseformatoptionshere'", ")", ";", "}", "// Remove newsitems element if format does not support news.", "if", "(", "!", "$", "courseformat", "->", "supports_news", "(", ")", ")", "{", "$", "mform", "->", "removeElement", "(", "'newsitems'", ")", ";", "}", "}", "// Tweak the form with values provided by custom fields in use.", "$", "handler", "=", "core_course", "\\", "customfield", "\\", "course_handler", "::", "create", "(", ")", ";", "$", "handler", "->", "instance_form_definition_after_data", "(", "$", "mform", ",", "empty", "(", "$", "courseid", ")", "?", "0", ":", "$", "courseid", ")", ";", "}" ]
Fill in the current page data for this course.
[ "Fill", "in", "the", "current", "page", "data", "for", "this", "course", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/edit_form.php#L351-L397
217,679
moodle/moodle
lib/spout/src/Spout/Writer/AbstractWriter.php
AbstractWriter.openToFile
public function openToFile($outputFilePath) { $this->outputFilePath = $outputFilePath; $this->filePointer = $this->globalFunctionsHelper->fopen($this->outputFilePath, 'wb+'); $this->throwIfFilePointerIsNotAvailable(); $this->openWriter(); $this->isWriterOpened = true; return $this; }
php
public function openToFile($outputFilePath) { $this->outputFilePath = $outputFilePath; $this->filePointer = $this->globalFunctionsHelper->fopen($this->outputFilePath, 'wb+'); $this->throwIfFilePointerIsNotAvailable(); $this->openWriter(); $this->isWriterOpened = true; return $this; }
[ "public", "function", "openToFile", "(", "$", "outputFilePath", ")", "{", "$", "this", "->", "outputFilePath", "=", "$", "outputFilePath", ";", "$", "this", "->", "filePointer", "=", "$", "this", "->", "globalFunctionsHelper", "->", "fopen", "(", "$", "this", "->", "outputFilePath", ",", "'wb+'", ")", ";", "$", "this", "->", "throwIfFilePointerIsNotAvailable", "(", ")", ";", "$", "this", "->", "openWriter", "(", ")", ";", "$", "this", "->", "isWriterOpened", "=", "true", ";", "return", "$", "this", ";", "}" ]
Inits the writer and opens it to accept data. By using this method, the data will be written to a file. @api @param string $outputFilePath Path of the output file that will contain the data @return AbstractWriter @throws \Box\Spout\Common\Exception\IOException If the writer cannot be opened or if the given path is not writable
[ "Inits", "the", "writer", "and", "opens", "it", "to", "accept", "data", ".", "By", "using", "this", "method", "the", "data", "will", "be", "written", "to", "a", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/AbstractWriter.php#L110-L121
217,680
moodle/moodle
lib/spout/src/Spout/Writer/AbstractWriter.php
AbstractWriter.openToBrowser
public function openToBrowser($outputFileName) { $this->outputFilePath = $this->globalFunctionsHelper->basename($outputFileName); $this->filePointer = $this->globalFunctionsHelper->fopen('php://output', 'w'); $this->throwIfFilePointerIsNotAvailable(); // Clear any previous output (otherwise the generated file will be corrupted) // @see https://github.com/box/spout/issues/241 $this->globalFunctionsHelper->ob_end_clean(); // Set headers $this->globalFunctionsHelper->header('Content-Type: ' . static::$headerContentType); $this->globalFunctionsHelper->header('Content-Disposition: attachment; filename="' . $this->outputFilePath . '"'); /* * When forcing the download of a file over SSL,IE8 and lower browsers fail * if the Cache-Control and Pragma headers are not set. * * @see http://support.microsoft.com/KB/323308 * @see https://github.com/liuggio/ExcelBundle/issues/45 */ $this->globalFunctionsHelper->header('Cache-Control: max-age=0'); $this->globalFunctionsHelper->header('Pragma: public'); $this->openWriter(); $this->isWriterOpened = true; return $this; }
php
public function openToBrowser($outputFileName) { $this->outputFilePath = $this->globalFunctionsHelper->basename($outputFileName); $this->filePointer = $this->globalFunctionsHelper->fopen('php://output', 'w'); $this->throwIfFilePointerIsNotAvailable(); // Clear any previous output (otherwise the generated file will be corrupted) // @see https://github.com/box/spout/issues/241 $this->globalFunctionsHelper->ob_end_clean(); // Set headers $this->globalFunctionsHelper->header('Content-Type: ' . static::$headerContentType); $this->globalFunctionsHelper->header('Content-Disposition: attachment; filename="' . $this->outputFilePath . '"'); /* * When forcing the download of a file over SSL,IE8 and lower browsers fail * if the Cache-Control and Pragma headers are not set. * * @see http://support.microsoft.com/KB/323308 * @see https://github.com/liuggio/ExcelBundle/issues/45 */ $this->globalFunctionsHelper->header('Cache-Control: max-age=0'); $this->globalFunctionsHelper->header('Pragma: public'); $this->openWriter(); $this->isWriterOpened = true; return $this; }
[ "public", "function", "openToBrowser", "(", "$", "outputFileName", ")", "{", "$", "this", "->", "outputFilePath", "=", "$", "this", "->", "globalFunctionsHelper", "->", "basename", "(", "$", "outputFileName", ")", ";", "$", "this", "->", "filePointer", "=", "$", "this", "->", "globalFunctionsHelper", "->", "fopen", "(", "'php://output'", ",", "'w'", ")", ";", "$", "this", "->", "throwIfFilePointerIsNotAvailable", "(", ")", ";", "// Clear any previous output (otherwise the generated file will be corrupted)", "// @see https://github.com/box/spout/issues/241", "$", "this", "->", "globalFunctionsHelper", "->", "ob_end_clean", "(", ")", ";", "// Set headers", "$", "this", "->", "globalFunctionsHelper", "->", "header", "(", "'Content-Type: '", ".", "static", "::", "$", "headerContentType", ")", ";", "$", "this", "->", "globalFunctionsHelper", "->", "header", "(", "'Content-Disposition: attachment; filename=\"'", ".", "$", "this", "->", "outputFilePath", ".", "'\"'", ")", ";", "/*\n * When forcing the download of a file over SSL,IE8 and lower browsers fail\n * if the Cache-Control and Pragma headers are not set.\n *\n * @see http://support.microsoft.com/KB/323308\n * @see https://github.com/liuggio/ExcelBundle/issues/45\n */", "$", "this", "->", "globalFunctionsHelper", "->", "header", "(", "'Cache-Control: max-age=0'", ")", ";", "$", "this", "->", "globalFunctionsHelper", "->", "header", "(", "'Pragma: public'", ")", ";", "$", "this", "->", "openWriter", "(", ")", ";", "$", "this", "->", "isWriterOpened", "=", "true", ";", "return", "$", "this", ";", "}" ]
Inits the writer and opens it to accept data. By using this method, the data will be outputted directly to the browser. @codeCoverageIgnore @api @param string $outputFileName Name of the output file that will contain the data. If a path is passed in, only the file name will be kept @return AbstractWriter @throws \Box\Spout\Common\Exception\IOException If the writer cannot be opened
[ "Inits", "the", "writer", "and", "opens", "it", "to", "accept", "data", ".", "By", "using", "this", "method", "the", "data", "will", "be", "outputted", "directly", "to", "the", "browser", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/AbstractWriter.php#L134-L163
217,681
moodle/moodle
lib/spout/src/Spout/Writer/AbstractWriter.php
AbstractWriter.close
public function close() { if (!$this->isWriterOpened) { return; } $this->closeWriter(); if (is_resource($this->filePointer)) { $this->globalFunctionsHelper->fclose($this->filePointer); } $this->isWriterOpened = false; }
php
public function close() { if (!$this->isWriterOpened) { return; } $this->closeWriter(); if (is_resource($this->filePointer)) { $this->globalFunctionsHelper->fclose($this->filePointer); } $this->isWriterOpened = false; }
[ "public", "function", "close", "(", ")", "{", "if", "(", "!", "$", "this", "->", "isWriterOpened", ")", "{", "return", ";", "}", "$", "this", "->", "closeWriter", "(", ")", ";", "if", "(", "is_resource", "(", "$", "this", "->", "filePointer", ")", ")", "{", "$", "this", "->", "globalFunctionsHelper", "->", "fclose", "(", "$", "this", "->", "filePointer", ")", ";", "}", "$", "this", "->", "isWriterOpened", "=", "false", ";", "}" ]
Closes the writer. This will close the streamer as well, preventing new data to be written to the file. @api @return void
[ "Closes", "the", "writer", ".", "This", "will", "close", "the", "streamer", "as", "well", "preventing", "new", "data", "to", "be", "written", "to", "the", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/AbstractWriter.php#L351-L364
217,682
moodle/moodle
mod/chat/classes/task/cron_task.php
cron_task.execute
public function execute() { global $CFG, $DB; require_once($CFG->dirroot . '/mod/chat/lib.php'); chat_update_chat_times(); chat_delete_old_users(); $timenow = time(); $subselect = "SELECT c.keepdays FROM {chat} c WHERE c.id = {chat_messages}.chatid"; $DB->delete_records_select('chat_messages', "($subselect) > 0 AND timestamp < (? - ($subselect) * ?)", [$timenow, DAYSECS]); $DB->delete_records_select('chat_messages_current', "timestamp < ?", [$timenow - 8 * HOURSECS]); }
php
public function execute() { global $CFG, $DB; require_once($CFG->dirroot . '/mod/chat/lib.php'); chat_update_chat_times(); chat_delete_old_users(); $timenow = time(); $subselect = "SELECT c.keepdays FROM {chat} c WHERE c.id = {chat_messages}.chatid"; $DB->delete_records_select('chat_messages', "($subselect) > 0 AND timestamp < (? - ($subselect) * ?)", [$timenow, DAYSECS]); $DB->delete_records_select('chat_messages_current', "timestamp < ?", [$timenow - 8 * HOURSECS]); }
[ "public", "function", "execute", "(", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/mod/chat/lib.php'", ")", ";", "chat_update_chat_times", "(", ")", ";", "chat_delete_old_users", "(", ")", ";", "$", "timenow", "=", "time", "(", ")", ";", "$", "subselect", "=", "\"SELECT c.keepdays\n FROM {chat} c\n WHERE c.id = {chat_messages}.chatid\"", ";", "$", "DB", "->", "delete_records_select", "(", "'chat_messages'", ",", "\"($subselect) > 0 AND timestamp < (? - ($subselect) * ?)\"", ",", "[", "$", "timenow", ",", "DAYSECS", "]", ")", ";", "$", "DB", "->", "delete_records_select", "(", "'chat_messages_current'", ",", "\"timestamp < ?\"", ",", "[", "$", "timenow", "-", "8", "*", "HOURSECS", "]", ")", ";", "}" ]
Run chat cron.
[ "Run", "chat", "cron", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/chat/classes/task/cron_task.php#L49-L64
217,683
moodle/moodle
lib/classes/output/mustache_pix_helper.php
mustache_pix_helper.pix
public function pix($text, Mustache_LambdaHelper $helper) { // Split the text into an array of variables. $key = strtok($text, ","); $key = trim($helper->render($key)); $component = strtok(","); $component = trim($helper->render($component)); if (!$component) { $component = ''; } $component = $helper->render($component); $text = strtok(""); // Allow mustache tags in the last argument. $text = trim($helper->render($text)); return trim($this->renderer->pix_icon($key, $text, $component)); }
php
public function pix($text, Mustache_LambdaHelper $helper) { // Split the text into an array of variables. $key = strtok($text, ","); $key = trim($helper->render($key)); $component = strtok(","); $component = trim($helper->render($component)); if (!$component) { $component = ''; } $component = $helper->render($component); $text = strtok(""); // Allow mustache tags in the last argument. $text = trim($helper->render($text)); return trim($this->renderer->pix_icon($key, $text, $component)); }
[ "public", "function", "pix", "(", "$", "text", ",", "Mustache_LambdaHelper", "$", "helper", ")", "{", "// Split the text into an array of variables.", "$", "key", "=", "strtok", "(", "$", "text", ",", "\",\"", ")", ";", "$", "key", "=", "trim", "(", "$", "helper", "->", "render", "(", "$", "key", ")", ")", ";", "$", "component", "=", "strtok", "(", "\",\"", ")", ";", "$", "component", "=", "trim", "(", "$", "helper", "->", "render", "(", "$", "component", ")", ")", ";", "if", "(", "!", "$", "component", ")", "{", "$", "component", "=", "''", ";", "}", "$", "component", "=", "$", "helper", "->", "render", "(", "$", "component", ")", ";", "$", "text", "=", "strtok", "(", "\"\"", ")", ";", "// Allow mustache tags in the last argument.", "$", "text", "=", "trim", "(", "$", "helper", "->", "render", "(", "$", "text", ")", ")", ";", "return", "trim", "(", "$", "this", "->", "renderer", "->", "pix_icon", "(", "$", "key", ",", "$", "text", ",", "$", "component", ")", ")", ";", "}" ]
Read a pix icon name from a template and get it from pix_icon. {{#pix}}t/edit,component,Anything else is alt text{{/pix}} The args are comma separated and only the first is required. @param string $text The text to parse for arguments. @param Mustache_LambdaHelper $helper Used to render nested mustache variables. @return string
[ "Read", "a", "pix", "icon", "name", "from", "a", "template", "and", "get", "it", "from", "pix_icon", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/output/mustache_pix_helper.php#L62-L77
217,684
moodle/moodle
availability/condition/profile/classes/condition.php
condition.is_field_condition_met
protected static function is_field_condition_met($operator, $uservalue, $value) { if ($uservalue === false) { // If the user value is false this is an instant fail. // All user values come from the database as either data or the default. // They will always be a string. return false; } $fieldconditionmet = true; // Just to be doubly sure it is a string. $uservalue = (string)$uservalue; switch($operator) { case self::OP_CONTAINS: $pos = strpos($uservalue, $value); if ($pos === false) { $fieldconditionmet = false; } break; case self::OP_DOES_NOT_CONTAIN: if (!empty($value)) { $pos = strpos($uservalue, $value); if ($pos !== false) { $fieldconditionmet = false; } } break; case self::OP_IS_EQUAL_TO: if ($value !== $uservalue) { $fieldconditionmet = false; } break; case self::OP_STARTS_WITH: $length = strlen($value); if ((substr($uservalue, 0, $length) !== $value)) { $fieldconditionmet = false; } break; case self::OP_ENDS_WITH: $length = strlen($value); $start = $length * -1; if (substr($uservalue, $start) !== $value) { $fieldconditionmet = false; } break; case self::OP_IS_EMPTY: if (!empty($uservalue)) { $fieldconditionmet = false; } break; case self::OP_IS_NOT_EMPTY: if (empty($uservalue)) { $fieldconditionmet = false; } break; } return $fieldconditionmet; }
php
protected static function is_field_condition_met($operator, $uservalue, $value) { if ($uservalue === false) { // If the user value is false this is an instant fail. // All user values come from the database as either data or the default. // They will always be a string. return false; } $fieldconditionmet = true; // Just to be doubly sure it is a string. $uservalue = (string)$uservalue; switch($operator) { case self::OP_CONTAINS: $pos = strpos($uservalue, $value); if ($pos === false) { $fieldconditionmet = false; } break; case self::OP_DOES_NOT_CONTAIN: if (!empty($value)) { $pos = strpos($uservalue, $value); if ($pos !== false) { $fieldconditionmet = false; } } break; case self::OP_IS_EQUAL_TO: if ($value !== $uservalue) { $fieldconditionmet = false; } break; case self::OP_STARTS_WITH: $length = strlen($value); if ((substr($uservalue, 0, $length) !== $value)) { $fieldconditionmet = false; } break; case self::OP_ENDS_WITH: $length = strlen($value); $start = $length * -1; if (substr($uservalue, $start) !== $value) { $fieldconditionmet = false; } break; case self::OP_IS_EMPTY: if (!empty($uservalue)) { $fieldconditionmet = false; } break; case self::OP_IS_NOT_EMPTY: if (empty($uservalue)) { $fieldconditionmet = false; } break; } return $fieldconditionmet; }
[ "protected", "static", "function", "is_field_condition_met", "(", "$", "operator", ",", "$", "uservalue", ",", "$", "value", ")", "{", "if", "(", "$", "uservalue", "===", "false", ")", "{", "// If the user value is false this is an instant fail.", "// All user values come from the database as either data or the default.", "// They will always be a string.", "return", "false", ";", "}", "$", "fieldconditionmet", "=", "true", ";", "// Just to be doubly sure it is a string.", "$", "uservalue", "=", "(", "string", ")", "$", "uservalue", ";", "switch", "(", "$", "operator", ")", "{", "case", "self", "::", "OP_CONTAINS", ":", "$", "pos", "=", "strpos", "(", "$", "uservalue", ",", "$", "value", ")", ";", "if", "(", "$", "pos", "===", "false", ")", "{", "$", "fieldconditionmet", "=", "false", ";", "}", "break", ";", "case", "self", "::", "OP_DOES_NOT_CONTAIN", ":", "if", "(", "!", "empty", "(", "$", "value", ")", ")", "{", "$", "pos", "=", "strpos", "(", "$", "uservalue", ",", "$", "value", ")", ";", "if", "(", "$", "pos", "!==", "false", ")", "{", "$", "fieldconditionmet", "=", "false", ";", "}", "}", "break", ";", "case", "self", "::", "OP_IS_EQUAL_TO", ":", "if", "(", "$", "value", "!==", "$", "uservalue", ")", "{", "$", "fieldconditionmet", "=", "false", ";", "}", "break", ";", "case", "self", "::", "OP_STARTS_WITH", ":", "$", "length", "=", "strlen", "(", "$", "value", ")", ";", "if", "(", "(", "substr", "(", "$", "uservalue", ",", "0", ",", "$", "length", ")", "!==", "$", "value", ")", ")", "{", "$", "fieldconditionmet", "=", "false", ";", "}", "break", ";", "case", "self", "::", "OP_ENDS_WITH", ":", "$", "length", "=", "strlen", "(", "$", "value", ")", ";", "$", "start", "=", "$", "length", "*", "-", "1", ";", "if", "(", "substr", "(", "$", "uservalue", ",", "$", "start", ")", "!==", "$", "value", ")", "{", "$", "fieldconditionmet", "=", "false", ";", "}", "break", ";", "case", "self", "::", "OP_IS_EMPTY", ":", "if", "(", "!", "empty", "(", "$", "uservalue", ")", ")", "{", "$", "fieldconditionmet", "=", "false", ";", "}", "break", ";", "case", "self", "::", "OP_IS_NOT_EMPTY", ":", "if", "(", "empty", "(", "$", "uservalue", ")", ")", "{", "$", "fieldconditionmet", "=", "false", ";", "}", "break", ";", "}", "return", "$", "fieldconditionmet", ";", "}" ]
Returns true if a field meets the required conditions, false otherwise. @param string $operator the requirement/condition @param string $uservalue the user's value @param string $value the value required @return boolean True if conditions are met
[ "Returns", "true", "if", "a", "field", "meets", "the", "required", "conditions", "false", "otherwise", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/availability/condition/profile/classes/condition.php#L267-L322
217,685
moodle/moodle
availability/condition/profile/classes/condition.php
condition.get_custom_profile_fields
public static function get_custom_profile_fields() { global $DB, $CFG; if (self::$customprofilefields === null) { // Get fields and store them indexed by shortname. require_once($CFG->dirroot . '/user/profile/lib.php'); $fields = profile_get_custom_fields(true); self::$customprofilefields = array(); foreach ($fields as $field) { self::$customprofilefields[$field->shortname] = $field; } } return self::$customprofilefields; }
php
public static function get_custom_profile_fields() { global $DB, $CFG; if (self::$customprofilefields === null) { // Get fields and store them indexed by shortname. require_once($CFG->dirroot . '/user/profile/lib.php'); $fields = profile_get_custom_fields(true); self::$customprofilefields = array(); foreach ($fields as $field) { self::$customprofilefields[$field->shortname] = $field; } } return self::$customprofilefields; }
[ "public", "static", "function", "get_custom_profile_fields", "(", ")", "{", "global", "$", "DB", ",", "$", "CFG", ";", "if", "(", "self", "::", "$", "customprofilefields", "===", "null", ")", "{", "// Get fields and store them indexed by shortname.", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/user/profile/lib.php'", ")", ";", "$", "fields", "=", "profile_get_custom_fields", "(", "true", ")", ";", "self", "::", "$", "customprofilefields", "=", "array", "(", ")", ";", "foreach", "(", "$", "fields", "as", "$", "field", ")", "{", "self", "::", "$", "customprofilefields", "[", "$", "field", "->", "shortname", "]", "=", "$", "field", ";", "}", "}", "return", "self", "::", "$", "customprofilefields", ";", "}" ]
Gets data about custom profile fields. Cached statically in current request. This only includes fields which can be tested by the system (those whose data is cached in $USER object) - basically doesn't include textarea type fields. @return array Array of records indexed by shortname
[ "Gets", "data", "about", "custom", "profile", "fields", ".", "Cached", "statically", "in", "current", "request", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/availability/condition/profile/classes/condition.php#L334-L347
217,686
moodle/moodle
availability/condition/profile/classes/condition.php
condition.get_cached_user_profile_field
protected function get_cached_user_profile_field($userid) { global $USER, $DB, $CFG; $iscurrentuser = $USER->id == $userid; if (isguestuser($userid) || ($iscurrentuser && !isloggedin())) { // Must be logged in and can't be the guest. return false; } // Custom profile fields will be numeric, there are no numeric standard profile fields so this is not a problem. $iscustomprofilefield = $this->customfield ? true : false; if ($iscustomprofilefield) { // As its a custom profile field we need to map the id back to the actual field. // We'll also preload all of the other custom profile fields just in case and ensure we have the // default value available as well. if (!array_key_exists($this->customfield, self::get_custom_profile_fields())) { // No such field exists. // This shouldn't normally happen but occur if things go wrong when deleting a custom profile field // or when restoring a backup of a course with user profile field conditions. return false; } $field = $this->customfield; } else { $field = $this->standardfield; } // If its the current user than most likely we will be able to get this information from $USER. // If its a regular profile field then it should already be available, if not then we have a mega problem. // If its a custom profile field then it should be available but may not be. If it is then we use the value // available, otherwise we load all custom profile fields into a temp object and refer to that. // Noting its not going be great for performance if we have to use the temp object as it involves loading the // custom profile field API and classes. if ($iscurrentuser) { if (!$iscustomprofilefield) { if (property_exists($USER, $field)) { return $USER->{$field}; } else { // Unknown user field. This should not happen. throw new \coding_exception('Requested user profile field does not exist'); } } // Checking if the custom profile fields are already available. if (!isset($USER->profile)) { // Drat! they're not. We need to use a temp object and load them. // We don't use $USER as the profile fields are loaded into the object. $user = new \stdClass; $user->id = $USER->id; // This should ALWAYS be set, but just in case we check. require_once($CFG->dirroot . '/user/profile/lib.php'); profile_load_custom_fields($user); if (array_key_exists($field, $user->profile)) { return $user->profile[$field]; } } else if (array_key_exists($field, $USER->profile)) { // Hurrah they're available, this is easy. return $USER->profile[$field]; } // The profile field doesn't exist. return false; } else { // Loading for another user. if ($iscustomprofilefield) { // Fetch the data for the field. Noting we keep this query simple so that Database caching takes care of performance // for us (this will likely be hit again). // We are able to do this because we've already pre-loaded the custom fields. $data = $DB->get_field('user_info_data', 'data', array('userid' => $userid, 'fieldid' => self::$customprofilefields[$field]->id), IGNORE_MISSING); // If we have data return that, otherwise return the default. if ($data !== false) { return $data; } else { return self::$customprofilefields[$field]->defaultdata; } } else { // Its a standard field, retrieve it from the user. return $DB->get_field('user', $field, array('id' => $userid), MUST_EXIST); } } return false; }
php
protected function get_cached_user_profile_field($userid) { global $USER, $DB, $CFG; $iscurrentuser = $USER->id == $userid; if (isguestuser($userid) || ($iscurrentuser && !isloggedin())) { // Must be logged in and can't be the guest. return false; } // Custom profile fields will be numeric, there are no numeric standard profile fields so this is not a problem. $iscustomprofilefield = $this->customfield ? true : false; if ($iscustomprofilefield) { // As its a custom profile field we need to map the id back to the actual field. // We'll also preload all of the other custom profile fields just in case and ensure we have the // default value available as well. if (!array_key_exists($this->customfield, self::get_custom_profile_fields())) { // No such field exists. // This shouldn't normally happen but occur if things go wrong when deleting a custom profile field // or when restoring a backup of a course with user profile field conditions. return false; } $field = $this->customfield; } else { $field = $this->standardfield; } // If its the current user than most likely we will be able to get this information from $USER. // If its a regular profile field then it should already be available, if not then we have a mega problem. // If its a custom profile field then it should be available but may not be. If it is then we use the value // available, otherwise we load all custom profile fields into a temp object and refer to that. // Noting its not going be great for performance if we have to use the temp object as it involves loading the // custom profile field API and classes. if ($iscurrentuser) { if (!$iscustomprofilefield) { if (property_exists($USER, $field)) { return $USER->{$field}; } else { // Unknown user field. This should not happen. throw new \coding_exception('Requested user profile field does not exist'); } } // Checking if the custom profile fields are already available. if (!isset($USER->profile)) { // Drat! they're not. We need to use a temp object and load them. // We don't use $USER as the profile fields are loaded into the object. $user = new \stdClass; $user->id = $USER->id; // This should ALWAYS be set, but just in case we check. require_once($CFG->dirroot . '/user/profile/lib.php'); profile_load_custom_fields($user); if (array_key_exists($field, $user->profile)) { return $user->profile[$field]; } } else if (array_key_exists($field, $USER->profile)) { // Hurrah they're available, this is easy. return $USER->profile[$field]; } // The profile field doesn't exist. return false; } else { // Loading for another user. if ($iscustomprofilefield) { // Fetch the data for the field. Noting we keep this query simple so that Database caching takes care of performance // for us (this will likely be hit again). // We are able to do this because we've already pre-loaded the custom fields. $data = $DB->get_field('user_info_data', 'data', array('userid' => $userid, 'fieldid' => self::$customprofilefields[$field]->id), IGNORE_MISSING); // If we have data return that, otherwise return the default. if ($data !== false) { return $data; } else { return self::$customprofilefields[$field]->defaultdata; } } else { // Its a standard field, retrieve it from the user. return $DB->get_field('user', $field, array('id' => $userid), MUST_EXIST); } } return false; }
[ "protected", "function", "get_cached_user_profile_field", "(", "$", "userid", ")", "{", "global", "$", "USER", ",", "$", "DB", ",", "$", "CFG", ";", "$", "iscurrentuser", "=", "$", "USER", "->", "id", "==", "$", "userid", ";", "if", "(", "isguestuser", "(", "$", "userid", ")", "||", "(", "$", "iscurrentuser", "&&", "!", "isloggedin", "(", ")", ")", ")", "{", "// Must be logged in and can't be the guest.", "return", "false", ";", "}", "// Custom profile fields will be numeric, there are no numeric standard profile fields so this is not a problem.", "$", "iscustomprofilefield", "=", "$", "this", "->", "customfield", "?", "true", ":", "false", ";", "if", "(", "$", "iscustomprofilefield", ")", "{", "// As its a custom profile field we need to map the id back to the actual field.", "// We'll also preload all of the other custom profile fields just in case and ensure we have the", "// default value available as well.", "if", "(", "!", "array_key_exists", "(", "$", "this", "->", "customfield", ",", "self", "::", "get_custom_profile_fields", "(", ")", ")", ")", "{", "// No such field exists.", "// This shouldn't normally happen but occur if things go wrong when deleting a custom profile field", "// or when restoring a backup of a course with user profile field conditions.", "return", "false", ";", "}", "$", "field", "=", "$", "this", "->", "customfield", ";", "}", "else", "{", "$", "field", "=", "$", "this", "->", "standardfield", ";", "}", "// If its the current user than most likely we will be able to get this information from $USER.", "// If its a regular profile field then it should already be available, if not then we have a mega problem.", "// If its a custom profile field then it should be available but may not be. If it is then we use the value", "// available, otherwise we load all custom profile fields into a temp object and refer to that.", "// Noting its not going be great for performance if we have to use the temp object as it involves loading the", "// custom profile field API and classes.", "if", "(", "$", "iscurrentuser", ")", "{", "if", "(", "!", "$", "iscustomprofilefield", ")", "{", "if", "(", "property_exists", "(", "$", "USER", ",", "$", "field", ")", ")", "{", "return", "$", "USER", "->", "{", "$", "field", "}", ";", "}", "else", "{", "// Unknown user field. This should not happen.", "throw", "new", "\\", "coding_exception", "(", "'Requested user profile field does not exist'", ")", ";", "}", "}", "// Checking if the custom profile fields are already available.", "if", "(", "!", "isset", "(", "$", "USER", "->", "profile", ")", ")", "{", "// Drat! they're not. We need to use a temp object and load them.", "// We don't use $USER as the profile fields are loaded into the object.", "$", "user", "=", "new", "\\", "stdClass", ";", "$", "user", "->", "id", "=", "$", "USER", "->", "id", ";", "// This should ALWAYS be set, but just in case we check.", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/user/profile/lib.php'", ")", ";", "profile_load_custom_fields", "(", "$", "user", ")", ";", "if", "(", "array_key_exists", "(", "$", "field", ",", "$", "user", "->", "profile", ")", ")", "{", "return", "$", "user", "->", "profile", "[", "$", "field", "]", ";", "}", "}", "else", "if", "(", "array_key_exists", "(", "$", "field", ",", "$", "USER", "->", "profile", ")", ")", "{", "// Hurrah they're available, this is easy.", "return", "$", "USER", "->", "profile", "[", "$", "field", "]", ";", "}", "// The profile field doesn't exist.", "return", "false", ";", "}", "else", "{", "// Loading for another user.", "if", "(", "$", "iscustomprofilefield", ")", "{", "// Fetch the data for the field. Noting we keep this query simple so that Database caching takes care of performance", "// for us (this will likely be hit again).", "// We are able to do this because we've already pre-loaded the custom fields.", "$", "data", "=", "$", "DB", "->", "get_field", "(", "'user_info_data'", ",", "'data'", ",", "array", "(", "'userid'", "=>", "$", "userid", ",", "'fieldid'", "=>", "self", "::", "$", "customprofilefields", "[", "$", "field", "]", "->", "id", ")", ",", "IGNORE_MISSING", ")", ";", "// If we have data return that, otherwise return the default.", "if", "(", "$", "data", "!==", "false", ")", "{", "return", "$", "data", ";", "}", "else", "{", "return", "self", "::", "$", "customprofilefields", "[", "$", "field", "]", "->", "defaultdata", ";", "}", "}", "else", "{", "// Its a standard field, retrieve it from the user.", "return", "$", "DB", "->", "get_field", "(", "'user'", ",", "$", "field", ",", "array", "(", "'id'", "=>", "$", "userid", ")", ",", "MUST_EXIST", ")", ";", "}", "}", "return", "false", ";", "}" ]
Return the value for a user's profile field @param int $userid User ID @return string|bool Value, or false if user does not have a value for this field
[ "Return", "the", "value", "for", "a", "user", "s", "profile", "field" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/availability/condition/profile/classes/condition.php#L362-L440
217,687
moodle/moodle
availability/condition/profile/classes/condition.php
condition.get_condition_sql
private function get_condition_sql($field, $field2 = null, $istext = false) { global $DB; if (is_null($field2)) { $field2 = $field; } $params = array(); switch($this->operator) { case self::OP_CONTAINS: $sql = $DB->sql_like($field, self::unique_sql_parameter( $params, '%' . $this->value . '%')); break; case self::OP_DOES_NOT_CONTAIN: if (empty($this->value)) { // The 'does not contain nothing' expression matches everyone. return null; } $sql = $DB->sql_like($field, self::unique_sql_parameter( $params, '%' . $this->value . '%'), true, true, true); break; case self::OP_IS_EQUAL_TO: if ($istext) { $sql = $DB->sql_compare_text($field) . ' = ' . $DB->sql_compare_text( self::unique_sql_parameter($params, $this->value)); } else { $sql = $field . ' = ' . self::unique_sql_parameter( $params, $this->value); } break; case self::OP_STARTS_WITH: $sql = $DB->sql_like($field, self::unique_sql_parameter( $params, $this->value . '%')); break; case self::OP_ENDS_WITH: $sql = $DB->sql_like($field, self::unique_sql_parameter( $params, '%' . $this->value)); break; case self::OP_IS_EMPTY: // Mimic PHP empty() behaviour for strings, '0' or ''. $emptystring = self::unique_sql_parameter($params, ''); if ($istext) { $sql = '(' . $DB->sql_compare_text($field) . " IN ('0', $emptystring) OR $field2 IS NULL)"; } else { $sql = '(' . $field . " IN ('0', $emptystring) OR $field2 IS NULL)"; } break; case self::OP_IS_NOT_EMPTY: $emptystring = self::unique_sql_parameter($params, ''); if ($istext) { $sql = '(' . $DB->sql_compare_text($field) . " NOT IN ('0', $emptystring) AND $field2 IS NOT NULL)"; } else { $sql = '(' . $field . " NOT IN ('0', $emptystring) AND $field2 IS NOT NULL)"; } break; } return array($sql, $params); }
php
private function get_condition_sql($field, $field2 = null, $istext = false) { global $DB; if (is_null($field2)) { $field2 = $field; } $params = array(); switch($this->operator) { case self::OP_CONTAINS: $sql = $DB->sql_like($field, self::unique_sql_parameter( $params, '%' . $this->value . '%')); break; case self::OP_DOES_NOT_CONTAIN: if (empty($this->value)) { // The 'does not contain nothing' expression matches everyone. return null; } $sql = $DB->sql_like($field, self::unique_sql_parameter( $params, '%' . $this->value . '%'), true, true, true); break; case self::OP_IS_EQUAL_TO: if ($istext) { $sql = $DB->sql_compare_text($field) . ' = ' . $DB->sql_compare_text( self::unique_sql_parameter($params, $this->value)); } else { $sql = $field . ' = ' . self::unique_sql_parameter( $params, $this->value); } break; case self::OP_STARTS_WITH: $sql = $DB->sql_like($field, self::unique_sql_parameter( $params, $this->value . '%')); break; case self::OP_ENDS_WITH: $sql = $DB->sql_like($field, self::unique_sql_parameter( $params, '%' . $this->value)); break; case self::OP_IS_EMPTY: // Mimic PHP empty() behaviour for strings, '0' or ''. $emptystring = self::unique_sql_parameter($params, ''); if ($istext) { $sql = '(' . $DB->sql_compare_text($field) . " IN ('0', $emptystring) OR $field2 IS NULL)"; } else { $sql = '(' . $field . " IN ('0', $emptystring) OR $field2 IS NULL)"; } break; case self::OP_IS_NOT_EMPTY: $emptystring = self::unique_sql_parameter($params, ''); if ($istext) { $sql = '(' . $DB->sql_compare_text($field) . " NOT IN ('0', $emptystring) AND $field2 IS NOT NULL)"; } else { $sql = '(' . $field . " NOT IN ('0', $emptystring) AND $field2 IS NOT NULL)"; } break; } return array($sql, $params); }
[ "private", "function", "get_condition_sql", "(", "$", "field", ",", "$", "field2", "=", "null", ",", "$", "istext", "=", "false", ")", "{", "global", "$", "DB", ";", "if", "(", "is_null", "(", "$", "field2", ")", ")", "{", "$", "field2", "=", "$", "field", ";", "}", "$", "params", "=", "array", "(", ")", ";", "switch", "(", "$", "this", "->", "operator", ")", "{", "case", "self", "::", "OP_CONTAINS", ":", "$", "sql", "=", "$", "DB", "->", "sql_like", "(", "$", "field", ",", "self", "::", "unique_sql_parameter", "(", "$", "params", ",", "'%'", ".", "$", "this", "->", "value", ".", "'%'", ")", ")", ";", "break", ";", "case", "self", "::", "OP_DOES_NOT_CONTAIN", ":", "if", "(", "empty", "(", "$", "this", "->", "value", ")", ")", "{", "// The 'does not contain nothing' expression matches everyone.", "return", "null", ";", "}", "$", "sql", "=", "$", "DB", "->", "sql_like", "(", "$", "field", ",", "self", "::", "unique_sql_parameter", "(", "$", "params", ",", "'%'", ".", "$", "this", "->", "value", ".", "'%'", ")", ",", "true", ",", "true", ",", "true", ")", ";", "break", ";", "case", "self", "::", "OP_IS_EQUAL_TO", ":", "if", "(", "$", "istext", ")", "{", "$", "sql", "=", "$", "DB", "->", "sql_compare_text", "(", "$", "field", ")", ".", "' = '", ".", "$", "DB", "->", "sql_compare_text", "(", "self", "::", "unique_sql_parameter", "(", "$", "params", ",", "$", "this", "->", "value", ")", ")", ";", "}", "else", "{", "$", "sql", "=", "$", "field", ".", "' = '", ".", "self", "::", "unique_sql_parameter", "(", "$", "params", ",", "$", "this", "->", "value", ")", ";", "}", "break", ";", "case", "self", "::", "OP_STARTS_WITH", ":", "$", "sql", "=", "$", "DB", "->", "sql_like", "(", "$", "field", ",", "self", "::", "unique_sql_parameter", "(", "$", "params", ",", "$", "this", "->", "value", ".", "'%'", ")", ")", ";", "break", ";", "case", "self", "::", "OP_ENDS_WITH", ":", "$", "sql", "=", "$", "DB", "->", "sql_like", "(", "$", "field", ",", "self", "::", "unique_sql_parameter", "(", "$", "params", ",", "'%'", ".", "$", "this", "->", "value", ")", ")", ";", "break", ";", "case", "self", "::", "OP_IS_EMPTY", ":", "// Mimic PHP empty() behaviour for strings, '0' or ''.", "$", "emptystring", "=", "self", "::", "unique_sql_parameter", "(", "$", "params", ",", "''", ")", ";", "if", "(", "$", "istext", ")", "{", "$", "sql", "=", "'('", ".", "$", "DB", "->", "sql_compare_text", "(", "$", "field", ")", ".", "\" IN ('0', $emptystring) OR $field2 IS NULL)\"", ";", "}", "else", "{", "$", "sql", "=", "'('", ".", "$", "field", ".", "\" IN ('0', $emptystring) OR $field2 IS NULL)\"", ";", "}", "break", ";", "case", "self", "::", "OP_IS_NOT_EMPTY", ":", "$", "emptystring", "=", "self", "::", "unique_sql_parameter", "(", "$", "params", ",", "''", ")", ";", "if", "(", "$", "istext", ")", "{", "$", "sql", "=", "'('", ".", "$", "DB", "->", "sql_compare_text", "(", "$", "field", ")", ".", "\" NOT IN ('0', $emptystring) AND $field2 IS NOT NULL)\"", ";", "}", "else", "{", "$", "sql", "=", "'('", ".", "$", "field", ".", "\" NOT IN ('0', $emptystring) AND $field2 IS NOT NULL)\"", ";", "}", "break", ";", "}", "return", "array", "(", "$", "sql", ",", "$", "params", ")", ";", "}" ]
Gets SQL to match a field against this condition. The second copy of the field is in case you're using variables for the field so that it needs to be two different ones. @param string $field Field name @param string $field2 Second copy of field name (default same). @param boolean $istext Any of the fields correspond to a TEXT column in database (true) or not (false). @return array Array of SQL and parameters
[ "Gets", "SQL", "to", "match", "a", "field", "against", "this", "condition", ".", "The", "second", "copy", "of", "the", "field", "is", "in", "case", "you", "re", "using", "variables", "for", "the", "field", "so", "that", "it", "needs", "to", "be", "two", "different", "ones", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/availability/condition/profile/classes/condition.php#L513-L569
217,688
moodle/moodle
repository/wikimedia/wikimedia.php
wikimedia.get_thumb_url
public function get_thumb_url($image_url, $orig_width, $orig_height, $thumb_width = 75, $force = false) { global $OUTPUT; if (!$force && $orig_width <= $thumb_width && $orig_height <= $thumb_width) { return $image_url; } else { $thumb_url = ''; $commons_main_dir = 'https://upload.wikimedia.org/wikipedia/commons/'; if ($image_url) { $short_path = str_replace($commons_main_dir, '', $image_url); $extension = strtolower(pathinfo($short_path, PATHINFO_EXTENSION)); if (strcmp($extension, 'gif') == 0) { //no thumb for gifs return $OUTPUT->image_url(file_extension_icon('.gif', $thumb_width))->out(false); } $dir_parts = explode('/', $short_path); $file_name = end($dir_parts); if ($orig_height > $orig_width) { $thumb_width = round($thumb_width * $orig_width/$orig_height); } $thumb_url = $commons_main_dir . 'thumb/' . implode('/', $dir_parts) . '/'. $thumb_width .'px-' . $file_name; if (strcmp($extension, 'svg') == 0) { //png thumb for svg-s $thumb_url .= '.png'; } } return $thumb_url; } }
php
public function get_thumb_url($image_url, $orig_width, $orig_height, $thumb_width = 75, $force = false) { global $OUTPUT; if (!$force && $orig_width <= $thumb_width && $orig_height <= $thumb_width) { return $image_url; } else { $thumb_url = ''; $commons_main_dir = 'https://upload.wikimedia.org/wikipedia/commons/'; if ($image_url) { $short_path = str_replace($commons_main_dir, '', $image_url); $extension = strtolower(pathinfo($short_path, PATHINFO_EXTENSION)); if (strcmp($extension, 'gif') == 0) { //no thumb for gifs return $OUTPUT->image_url(file_extension_icon('.gif', $thumb_width))->out(false); } $dir_parts = explode('/', $short_path); $file_name = end($dir_parts); if ($orig_height > $orig_width) { $thumb_width = round($thumb_width * $orig_width/$orig_height); } $thumb_url = $commons_main_dir . 'thumb/' . implode('/', $dir_parts) . '/'. $thumb_width .'px-' . $file_name; if (strcmp($extension, 'svg') == 0) { //png thumb for svg-s $thumb_url .= '.png'; } } return $thumb_url; } }
[ "public", "function", "get_thumb_url", "(", "$", "image_url", ",", "$", "orig_width", ",", "$", "orig_height", ",", "$", "thumb_width", "=", "75", ",", "$", "force", "=", "false", ")", "{", "global", "$", "OUTPUT", ";", "if", "(", "!", "$", "force", "&&", "$", "orig_width", "<=", "$", "thumb_width", "&&", "$", "orig_height", "<=", "$", "thumb_width", ")", "{", "return", "$", "image_url", ";", "}", "else", "{", "$", "thumb_url", "=", "''", ";", "$", "commons_main_dir", "=", "'https://upload.wikimedia.org/wikipedia/commons/'", ";", "if", "(", "$", "image_url", ")", "{", "$", "short_path", "=", "str_replace", "(", "$", "commons_main_dir", ",", "''", ",", "$", "image_url", ")", ";", "$", "extension", "=", "strtolower", "(", "pathinfo", "(", "$", "short_path", ",", "PATHINFO_EXTENSION", ")", ")", ";", "if", "(", "strcmp", "(", "$", "extension", ",", "'gif'", ")", "==", "0", ")", "{", "//no thumb for gifs", "return", "$", "OUTPUT", "->", "image_url", "(", "file_extension_icon", "(", "'.gif'", ",", "$", "thumb_width", ")", ")", "->", "out", "(", "false", ")", ";", "}", "$", "dir_parts", "=", "explode", "(", "'/'", ",", "$", "short_path", ")", ";", "$", "file_name", "=", "end", "(", "$", "dir_parts", ")", ";", "if", "(", "$", "orig_height", ">", "$", "orig_width", ")", "{", "$", "thumb_width", "=", "round", "(", "$", "thumb_width", "*", "$", "orig_width", "/", "$", "orig_height", ")", ";", "}", "$", "thumb_url", "=", "$", "commons_main_dir", ".", "'thumb/'", ".", "implode", "(", "'/'", ",", "$", "dir_parts", ")", ".", "'/'", ".", "$", "thumb_width", ".", "'px-'", ".", "$", "file_name", ";", "if", "(", "strcmp", "(", "$", "extension", ",", "'svg'", ")", "==", "0", ")", "{", "//png thumb for svg-s", "$", "thumb_url", ".=", "'.png'", ";", "}", "}", "return", "$", "thumb_url", ";", "}", "}" ]
Generate thumbnail URL from image URL. @param string $image_url @param int $orig_width @param int $orig_height @param int $thumb_width @param bool $force When true, forces the generation of a thumb URL. @global object OUTPUT @return string
[ "Generate", "thumbnail", "URL", "from", "image", "URL", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/wikimedia/wikimedia.php#L113-L139
217,689
moodle/moodle
lib/behat/form_field/behat_form_field.php
behat_form_field.guess_type
private function guess_type() { global $CFG; // We default to the text-based field if nothing was detected. if (!$type = behat_field_manager::guess_field_type($this->field, $this->session)) { $type = 'text'; } $classname = 'behat_form_' . $type; $classpath = $CFG->dirroot . '/lib/behat/form_field/' . $classname . '.php'; require_once($classpath); return new $classname($this->session, $this->field); }
php
private function guess_type() { global $CFG; // We default to the text-based field if nothing was detected. if (!$type = behat_field_manager::guess_field_type($this->field, $this->session)) { $type = 'text'; } $classname = 'behat_form_' . $type; $classpath = $CFG->dirroot . '/lib/behat/form_field/' . $classname . '.php'; require_once($classpath); return new $classname($this->session, $this->field); }
[ "private", "function", "guess_type", "(", ")", "{", "global", "$", "CFG", ";", "// We default to the text-based field if nothing was detected.", "if", "(", "!", "$", "type", "=", "behat_field_manager", "::", "guess_field_type", "(", "$", "this", "->", "field", ",", "$", "this", "->", "session", ")", ")", "{", "$", "type", "=", "'text'", ";", "}", "$", "classname", "=", "'behat_form_'", ".", "$", "type", ";", "$", "classpath", "=", "$", "CFG", "->", "dirroot", ".", "'/lib/behat/form_field/'", ".", "$", "classname", ".", "'.php'", ";", "require_once", "(", "$", "classpath", ")", ";", "return", "new", "$", "classname", "(", "$", "this", "->", "session", ",", "$", "this", "->", "field", ")", ";", "}" ]
Guesses the element type we are dealing with in case is not a text-based element. This class is the generic field type, behat_field_manager::get_form_field() should be able to find the appropiate class for the field type, but in cases like moodle form group elements we can not find the type of the field through the DOM so we also need to take care of the different field types from here. If we need to deal with more complex moodle form elements we will need to refactor this simple HTML elements guess method. @return behat_form_field
[ "Guesses", "the", "element", "type", "we", "are", "dealing", "with", "in", "case", "is", "not", "a", "text", "-", "based", "element", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/form_field/behat_form_field.php#L162-L174
217,690
moodle/moodle
lib/behat/form_field/behat_form_field.php
behat_form_field.get_internal_field_id
protected function get_internal_field_id() { if (!$this->running_javascript()) { throw new coding_exception('You can only get an internal ID using the selenium driver.'); } return $this->session->getDriver()->getWebDriverSession()->element('xpath', $this->field->getXPath())->getID(); }
php
protected function get_internal_field_id() { if (!$this->running_javascript()) { throw new coding_exception('You can only get an internal ID using the selenium driver.'); } return $this->session->getDriver()->getWebDriverSession()->element('xpath', $this->field->getXPath())->getID(); }
[ "protected", "function", "get_internal_field_id", "(", ")", "{", "if", "(", "!", "$", "this", "->", "running_javascript", "(", ")", ")", "{", "throw", "new", "coding_exception", "(", "'You can only get an internal ID using the selenium driver.'", ")", ";", "}", "return", "$", "this", "->", "session", "->", "getDriver", "(", ")", "->", "getWebDriverSession", "(", ")", "->", "element", "(", "'xpath'", ",", "$", "this", "->", "field", "->", "getXPath", "(", ")", ")", "->", "getID", "(", ")", ";", "}" ]
Gets the field internal id used by selenium wire protocol. Only available when running_javascript(). @throws coding_exception @return int
[ "Gets", "the", "field", "internal", "id", "used", "by", "selenium", "wire", "protocol", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/form_field/behat_form_field.php#L207-L214
217,691
moodle/moodle
lib/behat/form_field/behat_form_field.php
behat_form_field.get_field_locator
protected function get_field_locator($locatortype = false) { if (!empty($this->fieldlocator)) { return $this->fieldlocator; } $fieldid = $this->field->getAttribute('id'); // Defaults to label. if ($locatortype == 'label' || $locatortype == false) { $labelnode = $this->session->getPage()->find('xpath', '//label[@for="' . $fieldid . '"]'); // Exception only if $locatortype was specified. if (!$labelnode && $locatortype == 'label') { throw new coding_exception('Field with "' . $fieldid . '" id does not have a label.'); } $this->fieldlocator = $labelnode->getText(); } // Let's look for the name as a second option (more popular than // id's when pointing to fields). if (($locatortype == 'name' || $locatortype == false) && empty($this->fieldlocator)) { $name = $this->field->getAttribute('name'); // Exception only if $locatortype was specified. if (!$name && $locatortype == 'name') { throw new coding_exception('Field with "' . $fieldid . '" id does not have a name attribute.'); } $this->fieldlocator = $name; } // Otherwise returns the id if no specific locator type was provided. if (empty($this->fieldlocator)) { $this->fieldlocator = $fieldid; } return $this->fieldlocator; }
php
protected function get_field_locator($locatortype = false) { if (!empty($this->fieldlocator)) { return $this->fieldlocator; } $fieldid = $this->field->getAttribute('id'); // Defaults to label. if ($locatortype == 'label' || $locatortype == false) { $labelnode = $this->session->getPage()->find('xpath', '//label[@for="' . $fieldid . '"]'); // Exception only if $locatortype was specified. if (!$labelnode && $locatortype == 'label') { throw new coding_exception('Field with "' . $fieldid . '" id does not have a label.'); } $this->fieldlocator = $labelnode->getText(); } // Let's look for the name as a second option (more popular than // id's when pointing to fields). if (($locatortype == 'name' || $locatortype == false) && empty($this->fieldlocator)) { $name = $this->field->getAttribute('name'); // Exception only if $locatortype was specified. if (!$name && $locatortype == 'name') { throw new coding_exception('Field with "' . $fieldid . '" id does not have a name attribute.'); } $this->fieldlocator = $name; } // Otherwise returns the id if no specific locator type was provided. if (empty($this->fieldlocator)) { $this->fieldlocator = $fieldid; } return $this->fieldlocator; }
[ "protected", "function", "get_field_locator", "(", "$", "locatortype", "=", "false", ")", "{", "if", "(", "!", "empty", "(", "$", "this", "->", "fieldlocator", ")", ")", "{", "return", "$", "this", "->", "fieldlocator", ";", "}", "$", "fieldid", "=", "$", "this", "->", "field", "->", "getAttribute", "(", "'id'", ")", ";", "// Defaults to label.", "if", "(", "$", "locatortype", "==", "'label'", "||", "$", "locatortype", "==", "false", ")", "{", "$", "labelnode", "=", "$", "this", "->", "session", "->", "getPage", "(", ")", "->", "find", "(", "'xpath'", ",", "'//label[@for=\"'", ".", "$", "fieldid", ".", "'\"]'", ")", ";", "// Exception only if $locatortype was specified.", "if", "(", "!", "$", "labelnode", "&&", "$", "locatortype", "==", "'label'", ")", "{", "throw", "new", "coding_exception", "(", "'Field with \"'", ".", "$", "fieldid", ".", "'\" id does not have a label.'", ")", ";", "}", "$", "this", "->", "fieldlocator", "=", "$", "labelnode", "->", "getText", "(", ")", ";", "}", "// Let's look for the name as a second option (more popular than", "// id's when pointing to fields).", "if", "(", "(", "$", "locatortype", "==", "'name'", "||", "$", "locatortype", "==", "false", ")", "&&", "empty", "(", "$", "this", "->", "fieldlocator", ")", ")", "{", "$", "name", "=", "$", "this", "->", "field", "->", "getAttribute", "(", "'name'", ")", ";", "// Exception only if $locatortype was specified.", "if", "(", "!", "$", "name", "&&", "$", "locatortype", "==", "'name'", ")", "{", "throw", "new", "coding_exception", "(", "'Field with \"'", ".", "$", "fieldid", ".", "'\" id does not have a name attribute.'", ")", ";", "}", "$", "this", "->", "fieldlocator", "=", "$", "name", ";", "}", "// Otherwise returns the id if no specific locator type was provided.", "if", "(", "empty", "(", "$", "this", "->", "fieldlocator", ")", ")", "{", "$", "this", "->", "fieldlocator", "=", "$", "fieldid", ";", "}", "return", "$", "this", "->", "fieldlocator", ";", "}" ]
Gets the field locator. Defaults to the field label but you can specify other locators if you are interested. Public visibility as in most cases will be hard to use this method in a generic way, as fields can be selected using multiple ways (label, id, name...). @throws coding_exception @param string $locatortype @return string
[ "Gets", "the", "field", "locator", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/form_field/behat_form_field.php#L243-L285
217,692
moodle/moodle
lib/phpexcel/PHPExcel/Chart/GridLines.php
PHPExcel_Chart_GridLines.setLineColorProperties
public function setLineColorProperties($value, $alpha = 0, $type = self::EXCEL_COLOR_TYPE_STANDARD) { $this->activateObject() ->lineProperties['color'] = $this->setColorProperties( $value, $alpha, $type ); }
php
public function setLineColorProperties($value, $alpha = 0, $type = self::EXCEL_COLOR_TYPE_STANDARD) { $this->activateObject() ->lineProperties['color'] = $this->setColorProperties( $value, $alpha, $type ); }
[ "public", "function", "setLineColorProperties", "(", "$", "value", ",", "$", "alpha", "=", "0", ",", "$", "type", "=", "self", "::", "EXCEL_COLOR_TYPE_STANDARD", ")", "{", "$", "this", "->", "activateObject", "(", ")", "->", "lineProperties", "[", "'color'", "]", "=", "$", "this", "->", "setColorProperties", "(", "$", "value", ",", "$", "alpha", ",", "$", "type", ")", ";", "}" ]
Set Line Color Properties @param string $value @param int $alpha @param string $type
[ "Set", "Line", "Color", "Properties" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Chart/GridLines.php#L115-L123
217,693
moodle/moodle
lib/phpexcel/PHPExcel/Chart/GridLines.php
PHPExcel_Chart_GridLines.setGlowProperties
public function setGlowProperties($size, $color_value = null, $color_alpha = null, $color_type = null) { $this ->activateObject() ->setGlowSize($size) ->setGlowColor($color_value, $color_alpha, $color_type); }
php
public function setGlowProperties($size, $color_value = null, $color_alpha = null, $color_type = null) { $this ->activateObject() ->setGlowSize($size) ->setGlowColor($color_value, $color_alpha, $color_type); }
[ "public", "function", "setGlowProperties", "(", "$", "size", ",", "$", "color_value", "=", "null", ",", "$", "color_alpha", "=", "null", ",", "$", "color_type", "=", "null", ")", "{", "$", "this", "->", "activateObject", "(", ")", "->", "setGlowSize", "(", "$", "size", ")", "->", "setGlowColor", "(", "$", "color_value", ",", "$", "color_alpha", ",", "$", "color_type", ")", ";", "}" ]
Set Glow Properties @param float $size @param string $color_value @param int $color_alpha @param string $color_type
[ "Set", "Glow", "Properties" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Chart/GridLines.php#L207-L213
217,694
moodle/moodle
lib/phpexcel/PHPExcel/Chart/GridLines.php
PHPExcel_Chart_GridLines.setSoftEdgesSize
public function setSoftEdgesSize($size) { if (!is_null($size)) { $this->activateObject(); $softEdges['size'] = (string) $this->getExcelPointsWidth($size); } }
php
public function setSoftEdgesSize($size) { if (!is_null($size)) { $this->activateObject(); $softEdges['size'] = (string) $this->getExcelPointsWidth($size); } }
[ "public", "function", "setSoftEdgesSize", "(", "$", "size", ")", "{", "if", "(", "!", "is_null", "(", "$", "size", ")", ")", "{", "$", "this", "->", "activateObject", "(", ")", ";", "$", "softEdges", "[", "'size'", "]", "=", "(", "string", ")", "$", "this", "->", "getExcelPointsWidth", "(", "$", "size", ")", ";", "}", "}" ]
Set Soft Edges Size @param float $size
[ "Set", "Soft", "Edges", "Size" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Chart/GridLines.php#L455-L461
217,695
moodle/moodle
course/classes/output/bulk_activity_completion_renderer.php
core_course_bulk_activity_completion_renderer.navigation
public function navigation($courseorid, $page) { $tabs = core_completion\manager::get_available_completion_tabs($courseorid); if (count($tabs) > 1) { return $this->tabtree($tabs, $page); } else { return ''; } }
php
public function navigation($courseorid, $page) { $tabs = core_completion\manager::get_available_completion_tabs($courseorid); if (count($tabs) > 1) { return $this->tabtree($tabs, $page); } else { return ''; } }
[ "public", "function", "navigation", "(", "$", "courseorid", ",", "$", "page", ")", "{", "$", "tabs", "=", "core_completion", "\\", "manager", "::", "get_available_completion_tabs", "(", "$", "courseorid", ")", ";", "if", "(", "count", "(", "$", "tabs", ")", ">", "1", ")", "{", "return", "$", "this", "->", "tabtree", "(", "$", "tabs", ",", "$", "page", ")", ";", "}", "else", "{", "return", "''", ";", "}", "}" ]
Render the navigation tabs for the completion page. @param int|stdClass $courseorid the course object or id. @param String $page the tab to focus. @return string html
[ "Render", "the", "navigation", "tabs", "for", "the", "completion", "page", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/output/bulk_activity_completion_renderer.php#L45-L52
217,696
moodle/moodle
course/classes/output/bulk_activity_completion_renderer.php
core_course_bulk_activity_completion_renderer.edit_bulk_completion
public function edit_bulk_completion($form, $activities) { ob_start(); $form->display(); $formhtml = ob_get_contents(); ob_end_clean(); $data = (object)[ 'form' => $formhtml, 'activities' => array_values($activities), 'activitiescount' => count($activities), ]; return parent::render_from_template('core_course/editbulkactivitycompletion', $data); }
php
public function edit_bulk_completion($form, $activities) { ob_start(); $form->display(); $formhtml = ob_get_contents(); ob_end_clean(); $data = (object)[ 'form' => $formhtml, 'activities' => array_values($activities), 'activitiescount' => count($activities), ]; return parent::render_from_template('core_course/editbulkactivitycompletion', $data); }
[ "public", "function", "edit_bulk_completion", "(", "$", "form", ",", "$", "activities", ")", "{", "ob_start", "(", ")", ";", "$", "form", "->", "display", "(", ")", ";", "$", "formhtml", "=", "ob_get_contents", "(", ")", ";", "ob_end_clean", "(", ")", ";", "$", "data", "=", "(", "object", ")", "[", "'form'", "=>", "$", "formhtml", ",", "'activities'", "=>", "array_values", "(", "$", "activities", ")", ",", "'activitiescount'", "=>", "count", "(", "$", "activities", ")", ",", "]", ";", "return", "parent", "::", "render_from_template", "(", "'core_course/editbulkactivitycompletion'", ",", "$", "data", ")", ";", "}" ]
Renders the form for bulk editing activities completion @param moodleform $form @param array $activities @return string
[ "Renders", "the", "form", "for", "bulk", "editing", "activities", "completion" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/output/bulk_activity_completion_renderer.php#L81-L93
217,697
moodle/moodle
course/classes/output/bulk_activity_completion_renderer.php
core_course_bulk_activity_completion_renderer.edit_default_completion
public function edit_default_completion($form, $modules) { ob_start(); $form->display(); $formhtml = ob_get_contents(); ob_end_clean(); $data = (object)[ 'form' => $formhtml, 'modules' => array_values($modules), 'modulescount' => count($modules), ]; return parent::render_from_template('core_course/editdefaultcompletion', $data); }
php
public function edit_default_completion($form, $modules) { ob_start(); $form->display(); $formhtml = ob_get_contents(); ob_end_clean(); $data = (object)[ 'form' => $formhtml, 'modules' => array_values($modules), 'modulescount' => count($modules), ]; return parent::render_from_template('core_course/editdefaultcompletion', $data); }
[ "public", "function", "edit_default_completion", "(", "$", "form", ",", "$", "modules", ")", "{", "ob_start", "(", ")", ";", "$", "form", "->", "display", "(", ")", ";", "$", "formhtml", "=", "ob_get_contents", "(", ")", ";", "ob_end_clean", "(", ")", ";", "$", "data", "=", "(", "object", ")", "[", "'form'", "=>", "$", "formhtml", ",", "'modules'", "=>", "array_values", "(", "$", "modules", ")", ",", "'modulescount'", "=>", "count", "(", "$", "modules", ")", ",", "]", ";", "return", "parent", "::", "render_from_template", "(", "'core_course/editdefaultcompletion'", ",", "$", "data", ")", ";", "}" ]
Renders the form for editing default completion @param moodleform $form @param array $modules @return string
[ "Renders", "the", "form", "for", "editing", "default", "completion" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/course/classes/output/bulk_activity_completion_renderer.php#L102-L114
217,698
moodle/moodle
cache/stores/mongodb/MongoDB/ChangeStream.php
ChangeStream.isResumableError
private function isResumableError(RuntimeException $exception) { if ($exception instanceof ConnectionException) { return true; } if ( ! $exception instanceof ServerException) { return false; } if (in_array($exception->getCode(), [self::$errorCodeCappedPositionLost, self::$errorCodeCursorKilled, self::$errorCodeInterrupted])) { return false; } return true; }
php
private function isResumableError(RuntimeException $exception) { if ($exception instanceof ConnectionException) { return true; } if ( ! $exception instanceof ServerException) { return false; } if (in_array($exception->getCode(), [self::$errorCodeCappedPositionLost, self::$errorCodeCursorKilled, self::$errorCodeInterrupted])) { return false; } return true; }
[ "private", "function", "isResumableError", "(", "RuntimeException", "$", "exception", ")", "{", "if", "(", "$", "exception", "instanceof", "ConnectionException", ")", "{", "return", "true", ";", "}", "if", "(", "!", "$", "exception", "instanceof", "ServerException", ")", "{", "return", "false", ";", "}", "if", "(", "in_array", "(", "$", "exception", "->", "getCode", "(", ")", ",", "[", "self", "::", "$", "errorCodeCappedPositionLost", ",", "self", "::", "$", "errorCodeCursorKilled", ",", "self", "::", "$", "errorCodeInterrupted", "]", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Determines if an exception is a resumable error. @see https://github.com/mongodb/specifications/blob/master/source/change-streams/change-streams.rst#resumable-error @param RuntimeException $exception @return boolean
[ "Determines", "if", "an", "exception", "is", "a", "resumable", "error", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/ChangeStream.php#L200-L215
217,699
moodle/moodle
cache/stores/mongodb/MongoDB/ChangeStream.php
ChangeStream.resume
private function resume() { $newChangeStream = call_user_func($this->resumeCallable, $this->resumeToken); $this->csIt = $newChangeStream->csIt; $this->csIt->rewind(); }
php
private function resume() { $newChangeStream = call_user_func($this->resumeCallable, $this->resumeToken); $this->csIt = $newChangeStream->csIt; $this->csIt->rewind(); }
[ "private", "function", "resume", "(", ")", "{", "$", "newChangeStream", "=", "call_user_func", "(", "$", "this", "->", "resumeCallable", ",", "$", "this", "->", "resumeToken", ")", ";", "$", "this", "->", "csIt", "=", "$", "newChangeStream", "->", "csIt", ";", "$", "this", "->", "csIt", "->", "rewind", "(", ")", ";", "}" ]
Creates a new changeStream after a resumable server error. @return void
[ "Creates", "a", "new", "changeStream", "after", "a", "resumable", "server", "error", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/stores/mongodb/MongoDB/ChangeStream.php#L222-L227