id
int32
0
241k
repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
216,900
moodle/moodle
user/externallib.php
core_user_external.get_private_files_info
public static function get_private_files_info($userid = 0) { global $CFG, $USER; require_once($CFG->libdir . '/filelib.php'); $params = self::validate_parameters(self::get_private_files_info_parameters(), array('userid' => $userid)); $warnings = array(); $context = context_system::instance(); self::validate_context($context); if (empty($params['userid']) || $params['userid'] == $USER->id) { $usercontext = context_user::instance($USER->id); require_capability('moodle/user:manageownfiles', $usercontext); } else { $user = core_user::get_user($params['userid'], '*', MUST_EXIST); core_user::require_active_user($user); // Only admins can retrieve other users information. require_capability('moodle/site:config', $context); $usercontext = context_user::instance($user->id); } $fileareainfo = file_get_file_area_info($usercontext->id, 'user', 'private'); $result = array(); $result['filecount'] = $fileareainfo['filecount']; $result['foldercount'] = $fileareainfo['foldercount']; $result['filesize'] = $fileareainfo['filesize']; $result['filesizewithoutreferences'] = $fileareainfo['filesize_without_references']; $result['warnings'] = $warnings; return $result; }
php
public static function get_private_files_info($userid = 0) { global $CFG, $USER; require_once($CFG->libdir . '/filelib.php'); $params = self::validate_parameters(self::get_private_files_info_parameters(), array('userid' => $userid)); $warnings = array(); $context = context_system::instance(); self::validate_context($context); if (empty($params['userid']) || $params['userid'] == $USER->id) { $usercontext = context_user::instance($USER->id); require_capability('moodle/user:manageownfiles', $usercontext); } else { $user = core_user::get_user($params['userid'], '*', MUST_EXIST); core_user::require_active_user($user); // Only admins can retrieve other users information. require_capability('moodle/site:config', $context); $usercontext = context_user::instance($user->id); } $fileareainfo = file_get_file_area_info($usercontext->id, 'user', 'private'); $result = array(); $result['filecount'] = $fileareainfo['filecount']; $result['foldercount'] = $fileareainfo['foldercount']; $result['filesize'] = $fileareainfo['filesize']; $result['filesizewithoutreferences'] = $fileareainfo['filesize_without_references']; $result['warnings'] = $warnings; return $result; }
[ "public", "static", "function", "get_private_files_info", "(", "$", "userid", "=", "0", ")", "{", "global", "$", "CFG", ",", "$", "USER", ";", "require_once", "(", "$", "CFG", "->", "libdir", ".", "'/filelib.php'", ")", ";", "$", "params", "=", "self", "::", "validate_parameters", "(", "self", "::", "get_private_files_info_parameters", "(", ")", ",", "array", "(", "'userid'", "=>", "$", "userid", ")", ")", ";", "$", "warnings", "=", "array", "(", ")", ";", "$", "context", "=", "context_system", "::", "instance", "(", ")", ";", "self", "::", "validate_context", "(", "$", "context", ")", ";", "if", "(", "empty", "(", "$", "params", "[", "'userid'", "]", ")", "||", "$", "params", "[", "'userid'", "]", "==", "$", "USER", "->", "id", ")", "{", "$", "usercontext", "=", "context_user", "::", "instance", "(", "$", "USER", "->", "id", ")", ";", "require_capability", "(", "'moodle/user:manageownfiles'", ",", "$", "usercontext", ")", ";", "}", "else", "{", "$", "user", "=", "core_user", "::", "get_user", "(", "$", "params", "[", "'userid'", "]", ",", "'*'", ",", "MUST_EXIST", ")", ";", "core_user", "::", "require_active_user", "(", "$", "user", ")", ";", "// Only admins can retrieve other users information.", "require_capability", "(", "'moodle/site:config'", ",", "$", "context", ")", ";", "$", "usercontext", "=", "context_user", "::", "instance", "(", "$", "user", "->", "id", ")", ";", "}", "$", "fileareainfo", "=", "file_get_file_area_info", "(", "$", "usercontext", "->", "id", ",", "'user'", ",", "'private'", ")", ";", "$", "result", "=", "array", "(", ")", ";", "$", "result", "[", "'filecount'", "]", "=", "$", "fileareainfo", "[", "'filecount'", "]", ";", "$", "result", "[", "'foldercount'", "]", "=", "$", "fileareainfo", "[", "'foldercount'", "]", ";", "$", "result", "[", "'filesize'", "]", "=", "$", "fileareainfo", "[", "'filesize'", "]", ";", "$", "result", "[", "'filesizewithoutreferences'", "]", "=", "$", "fileareainfo", "[", "'filesize_without_references'", "]", ";", "$", "result", "[", "'warnings'", "]", "=", "$", "warnings", ";", "return", "$", "result", ";", "}" ]
Returns general information about files in the user private files area. @param int $userid Id of the user, default to current user. @return array of warnings and file area information @since Moodle 3.4 @throws moodle_exception
[ "Returns", "general", "information", "about", "files", "in", "the", "user", "private", "files", "area", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/externallib.php#L1956-L1986
216,901
moodle/moodle
favourites/classes/service_factory.php
service_factory.get_service_for_user_context
public static function get_service_for_user_context(\context_user $context) : local\service\user_favourite_service { return new local\service\user_favourite_service($context, new local\repository\favourite_repository()); }
php
public static function get_service_for_user_context(\context_user $context) : local\service\user_favourite_service { return new local\service\user_favourite_service($context, new local\repository\favourite_repository()); }
[ "public", "static", "function", "get_service_for_user_context", "(", "\\", "context_user", "$", "context", ")", ":", "local", "\\", "service", "\\", "user_favourite_service", "{", "return", "new", "local", "\\", "service", "\\", "user_favourite_service", "(", "$", "context", ",", "new", "local", "\\", "repository", "\\", "favourite_repository", "(", ")", ")", ";", "}" ]
Returns a basic service object providing operations for user favourites. @param \context_user $context the context of the user to which the service should be scoped. @return \core_favourites\local\service\user_favourite_service the service object.
[ "Returns", "a", "basic", "service", "object", "providing", "operations", "for", "user", "favourites", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/favourites/classes/service_factory.php#L45-L47
216,902
moodle/moodle
backup/moodle2/restore_qtype_extrafields_plugin.class.php
restore_qtype_extrafields_plugin.process_extraanswerdata
public function process_extraanswerdata($data) { global $DB; $extra = $this->qtypeobj->extra_answer_fields(); $tablename = array_shift($extra); $oldquestionid = $this->get_old_parentid('question'); $questioncreated = $this->get_mappingid('question_created', $oldquestionid) ? true : false; if ($questioncreated) { $data['answerid'] = $this->get_mappingid('question_answer', $data['id']); $DB->insert_record($tablename, $data); } else { $DB->update_record($tablename, $data); } }
php
public function process_extraanswerdata($data) { global $DB; $extra = $this->qtypeobj->extra_answer_fields(); $tablename = array_shift($extra); $oldquestionid = $this->get_old_parentid('question'); $questioncreated = $this->get_mappingid('question_created', $oldquestionid) ? true : false; if ($questioncreated) { $data['answerid'] = $this->get_mappingid('question_answer', $data['id']); $DB->insert_record($tablename, $data); } else { $DB->update_record($tablename, $data); } }
[ "public", "function", "process_extraanswerdata", "(", "$", "data", ")", "{", "global", "$", "DB", ";", "$", "extra", "=", "$", "this", "->", "qtypeobj", "->", "extra_answer_fields", "(", ")", ";", "$", "tablename", "=", "array_shift", "(", "$", "extra", ")", ";", "$", "oldquestionid", "=", "$", "this", "->", "get_old_parentid", "(", "'question'", ")", ";", "$", "questioncreated", "=", "$", "this", "->", "get_mappingid", "(", "'question_created'", ",", "$", "oldquestionid", ")", "?", "true", ":", "false", ";", "if", "(", "$", "questioncreated", ")", "{", "$", "data", "[", "'answerid'", "]", "=", "$", "this", "->", "get_mappingid", "(", "'question_answer'", ",", "$", "data", "[", "'id'", "]", ")", ";", "$", "DB", "->", "insert_record", "(", "$", "tablename", ",", "$", "data", ")", ";", "}", "else", "{", "$", "DB", "->", "update_record", "(", "$", "tablename", ",", "$", "data", ")", ";", "}", "}" ]
Processes the extra answer data @param array $data extra answer data
[ "Processes", "the", "extra", "answer", "data" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/moodle2/restore_qtype_extrafields_plugin.class.php#L83-L98
216,903
moodle/moodle
question/type/edit_question_form.php
question_edit_form.can_preview
protected function can_preview() { return empty($this->question->beingcopied) && !empty($this->question->id) && $this->question->formoptions->canedit; }
php
protected function can_preview() { return empty($this->question->beingcopied) && !empty($this->question->id) && $this->question->formoptions->canedit; }
[ "protected", "function", "can_preview", "(", ")", "{", "return", "empty", "(", "$", "this", "->", "question", "->", "beingcopied", ")", "&&", "!", "empty", "(", "$", "this", "->", "question", "->", "id", ")", "&&", "$", "this", "->", "question", "->", "formoptions", "->", "canedit", ";", "}" ]
Is the question being edited in a state where it can be previewed? @return bool whether to show the preview link.
[ "Is", "the", "question", "being", "edited", "in", "a", "state", "where", "it", "can", "be", "previewed?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/edit_question_form.php#L276-L279
216,904
moodle/moodle
question/type/edit_question_form.php
question_edit_form.get_per_answer_fields
protected function get_per_answer_fields($mform, $label, $gradeoptions, &$repeatedoptions, &$answersoption) { $repeated = array(); $answeroptions = array(); $answeroptions[] = $mform->createElement('text', 'answer', $label, array('size' => 40)); $answeroptions[] = $mform->createElement('select', 'fraction', get_string('grade'), $gradeoptions); $repeated[] = $mform->createElement('group', 'answeroptions', $label, $answeroptions, null, false); $repeated[] = $mform->createElement('editor', 'feedback', get_string('feedback', 'question'), array('rows' => 5), $this->editoroptions); $repeatedoptions['answer']['type'] = PARAM_RAW; $repeatedoptions['fraction']['default'] = 0; $answersoption = 'answers'; return $repeated; }
php
protected function get_per_answer_fields($mform, $label, $gradeoptions, &$repeatedoptions, &$answersoption) { $repeated = array(); $answeroptions = array(); $answeroptions[] = $mform->createElement('text', 'answer', $label, array('size' => 40)); $answeroptions[] = $mform->createElement('select', 'fraction', get_string('grade'), $gradeoptions); $repeated[] = $mform->createElement('group', 'answeroptions', $label, $answeroptions, null, false); $repeated[] = $mform->createElement('editor', 'feedback', get_string('feedback', 'question'), array('rows' => 5), $this->editoroptions); $repeatedoptions['answer']['type'] = PARAM_RAW; $repeatedoptions['fraction']['default'] = 0; $answersoption = 'answers'; return $repeated; }
[ "protected", "function", "get_per_answer_fields", "(", "$", "mform", ",", "$", "label", ",", "$", "gradeoptions", ",", "&", "$", "repeatedoptions", ",", "&", "$", "answersoption", ")", "{", "$", "repeated", "=", "array", "(", ")", ";", "$", "answeroptions", "=", "array", "(", ")", ";", "$", "answeroptions", "[", "]", "=", "$", "mform", "->", "createElement", "(", "'text'", ",", "'answer'", ",", "$", "label", ",", "array", "(", "'size'", "=>", "40", ")", ")", ";", "$", "answeroptions", "[", "]", "=", "$", "mform", "->", "createElement", "(", "'select'", ",", "'fraction'", ",", "get_string", "(", "'grade'", ")", ",", "$", "gradeoptions", ")", ";", "$", "repeated", "[", "]", "=", "$", "mform", "->", "createElement", "(", "'group'", ",", "'answeroptions'", ",", "$", "label", ",", "$", "answeroptions", ",", "null", ",", "false", ")", ";", "$", "repeated", "[", "]", "=", "$", "mform", "->", "createElement", "(", "'editor'", ",", "'feedback'", ",", "get_string", "(", "'feedback'", ",", "'question'", ")", ",", "array", "(", "'rows'", "=>", "5", ")", ",", "$", "this", "->", "editoroptions", ")", ";", "$", "repeatedoptions", "[", "'answer'", "]", "[", "'type'", "]", "=", "PARAM_RAW", ";", "$", "repeatedoptions", "[", "'fraction'", "]", "[", "'default'", "]", "=", "0", ";", "$", "answersoption", "=", "'answers'", ";", "return", "$", "repeated", ";", "}" ]
Get the list of form elements to repeat, one for each answer. @param object $mform the form being built. @param $label the label to use for each option. @param $gradeoptions the possible grades for each answer. @param $repeatedoptions reference to array of repeated options to fill @param $answersoption reference to return the name of $question->options field holding an array of answers @return array of form fields.
[ "Get", "the", "list", "of", "form", "elements", "to", "repeat", "one", "for", "each", "answer", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/edit_question_form.php#L291-L307
216,905
moodle/moodle
question/type/edit_question_form.php
question_edit_form.add_tag_fields
protected function add_tag_fields($mform) { global $CFG, $DB; $hastagcapability = question_has_capability_on($this->question, 'tag'); // Is the question category in a course context? $qcontext = $this->categorycontext; $qcoursecontext = $qcontext->get_course_context(false); $iscourseoractivityquestion = !empty($qcoursecontext); // Is the current context we're editing in a course context? $editingcontext = $this->contexts->lowest(); $editingcoursecontext = $editingcontext->get_course_context(false); $iseditingcontextcourseoractivity = !empty($editingcoursecontext); $mform->addElement('header', 'tagsheader', get_string('tags')); $tags = \core_tag_tag::get_tags_by_area_in_contexts('core_question', 'question', $this->contexts->all()); $tagstrings = []; foreach ($tags as $tag) { $tagstrings[$tag->name] = $tag->name; } $showstandard = core_tag_area::get_showstandard('core_question', 'question'); if ($showstandard != core_tag_tag::HIDE_STANDARD) { $namefield = empty($CFG->keeptagnamecase) ? 'name' : 'rawname'; $standardtags = $DB->get_records('tag', array('isstandard' => 1, 'tagcollid' => core_tag_area::get_collection('core', 'question')), $namefield, 'id,' . $namefield); foreach ($standardtags as $standardtag) { $tagstrings[$standardtag->$namefield] = $standardtag->$namefield; } } $options = [ 'tags' => true, 'multiple' => true, 'noselectionstring' => get_string('anytags', 'quiz'), ]; $mform->addElement('autocomplete', 'tags', get_string('tags'), $tagstrings, $options); if (!$hastagcapability) { $mform->hardFreeze('tags'); } if ($iseditingcontextcourseoractivity && !$iscourseoractivityquestion) { // If the question is being edited in a course or activity context // and the question isn't a course or activity level question then // allow course tags to be added to the course. $coursetagheader = get_string('questionformtagheader', 'core_question', $editingcoursecontext->get_context_name(true)); $mform->addElement('header', 'coursetagsheader', $coursetagheader); $mform->addElement('autocomplete', 'coursetags', get_string('tags'), $tagstrings, $options); if (!$hastagcapability) { $mform->hardFreeze('coursetags'); } } }
php
protected function add_tag_fields($mform) { global $CFG, $DB; $hastagcapability = question_has_capability_on($this->question, 'tag'); // Is the question category in a course context? $qcontext = $this->categorycontext; $qcoursecontext = $qcontext->get_course_context(false); $iscourseoractivityquestion = !empty($qcoursecontext); // Is the current context we're editing in a course context? $editingcontext = $this->contexts->lowest(); $editingcoursecontext = $editingcontext->get_course_context(false); $iseditingcontextcourseoractivity = !empty($editingcoursecontext); $mform->addElement('header', 'tagsheader', get_string('tags')); $tags = \core_tag_tag::get_tags_by_area_in_contexts('core_question', 'question', $this->contexts->all()); $tagstrings = []; foreach ($tags as $tag) { $tagstrings[$tag->name] = $tag->name; } $showstandard = core_tag_area::get_showstandard('core_question', 'question'); if ($showstandard != core_tag_tag::HIDE_STANDARD) { $namefield = empty($CFG->keeptagnamecase) ? 'name' : 'rawname'; $standardtags = $DB->get_records('tag', array('isstandard' => 1, 'tagcollid' => core_tag_area::get_collection('core', 'question')), $namefield, 'id,' . $namefield); foreach ($standardtags as $standardtag) { $tagstrings[$standardtag->$namefield] = $standardtag->$namefield; } } $options = [ 'tags' => true, 'multiple' => true, 'noselectionstring' => get_string('anytags', 'quiz'), ]; $mform->addElement('autocomplete', 'tags', get_string('tags'), $tagstrings, $options); if (!$hastagcapability) { $mform->hardFreeze('tags'); } if ($iseditingcontextcourseoractivity && !$iscourseoractivityquestion) { // If the question is being edited in a course or activity context // and the question isn't a course or activity level question then // allow course tags to be added to the course. $coursetagheader = get_string('questionformtagheader', 'core_question', $editingcoursecontext->get_context_name(true)); $mform->addElement('header', 'coursetagsheader', $coursetagheader); $mform->addElement('autocomplete', 'coursetags', get_string('tags'), $tagstrings, $options); if (!$hastagcapability) { $mform->hardFreeze('coursetags'); } } }
[ "protected", "function", "add_tag_fields", "(", "$", "mform", ")", "{", "global", "$", "CFG", ",", "$", "DB", ";", "$", "hastagcapability", "=", "question_has_capability_on", "(", "$", "this", "->", "question", ",", "'tag'", ")", ";", "// Is the question category in a course context?", "$", "qcontext", "=", "$", "this", "->", "categorycontext", ";", "$", "qcoursecontext", "=", "$", "qcontext", "->", "get_course_context", "(", "false", ")", ";", "$", "iscourseoractivityquestion", "=", "!", "empty", "(", "$", "qcoursecontext", ")", ";", "// Is the current context we're editing in a course context?", "$", "editingcontext", "=", "$", "this", "->", "contexts", "->", "lowest", "(", ")", ";", "$", "editingcoursecontext", "=", "$", "editingcontext", "->", "get_course_context", "(", "false", ")", ";", "$", "iseditingcontextcourseoractivity", "=", "!", "empty", "(", "$", "editingcoursecontext", ")", ";", "$", "mform", "->", "addElement", "(", "'header'", ",", "'tagsheader'", ",", "get_string", "(", "'tags'", ")", ")", ";", "$", "tags", "=", "\\", "core_tag_tag", "::", "get_tags_by_area_in_contexts", "(", "'core_question'", ",", "'question'", ",", "$", "this", "->", "contexts", "->", "all", "(", ")", ")", ";", "$", "tagstrings", "=", "[", "]", ";", "foreach", "(", "$", "tags", "as", "$", "tag", ")", "{", "$", "tagstrings", "[", "$", "tag", "->", "name", "]", "=", "$", "tag", "->", "name", ";", "}", "$", "showstandard", "=", "core_tag_area", "::", "get_showstandard", "(", "'core_question'", ",", "'question'", ")", ";", "if", "(", "$", "showstandard", "!=", "core_tag_tag", "::", "HIDE_STANDARD", ")", "{", "$", "namefield", "=", "empty", "(", "$", "CFG", "->", "keeptagnamecase", ")", "?", "'name'", ":", "'rawname'", ";", "$", "standardtags", "=", "$", "DB", "->", "get_records", "(", "'tag'", ",", "array", "(", "'isstandard'", "=>", "1", ",", "'tagcollid'", "=>", "core_tag_area", "::", "get_collection", "(", "'core'", ",", "'question'", ")", ")", ",", "$", "namefield", ",", "'id,'", ".", "$", "namefield", ")", ";", "foreach", "(", "$", "standardtags", "as", "$", "standardtag", ")", "{", "$", "tagstrings", "[", "$", "standardtag", "->", "$", "namefield", "]", "=", "$", "standardtag", "->", "$", "namefield", ";", "}", "}", "$", "options", "=", "[", "'tags'", "=>", "true", ",", "'multiple'", "=>", "true", ",", "'noselectionstring'", "=>", "get_string", "(", "'anytags'", ",", "'quiz'", ")", ",", "]", ";", "$", "mform", "->", "addElement", "(", "'autocomplete'", ",", "'tags'", ",", "get_string", "(", "'tags'", ")", ",", "$", "tagstrings", ",", "$", "options", ")", ";", "if", "(", "!", "$", "hastagcapability", ")", "{", "$", "mform", "->", "hardFreeze", "(", "'tags'", ")", ";", "}", "if", "(", "$", "iseditingcontextcourseoractivity", "&&", "!", "$", "iscourseoractivityquestion", ")", "{", "// If the question is being edited in a course or activity context", "// and the question isn't a course or activity level question then", "// allow course tags to be added to the course.", "$", "coursetagheader", "=", "get_string", "(", "'questionformtagheader'", ",", "'core_question'", ",", "$", "editingcoursecontext", "->", "get_context_name", "(", "true", ")", ")", ";", "$", "mform", "->", "addElement", "(", "'header'", ",", "'coursetagsheader'", ",", "$", "coursetagheader", ")", ";", "$", "mform", "->", "addElement", "(", "'autocomplete'", ",", "'coursetags'", ",", "get_string", "(", "'tags'", ")", ",", "$", "tagstrings", ",", "$", "options", ")", ";", "if", "(", "!", "$", "hastagcapability", ")", "{", "$", "mform", "->", "hardFreeze", "(", "'coursetags'", ")", ";", "}", "}", "}" ]
Add the tag and course tag fields to the mform. If the form is being built in a course context then add the field for course tags. If the question category doesn't belong to a course context or we aren't editing in a course context then add the tags element to allow tags to be added to the question category context. @param object $mform The form being built
[ "Add", "the", "tag", "and", "course", "tag", "fields", "to", "the", "mform", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/edit_question_form.php#L321-L376
216,906
moodle/moodle
question/type/edit_question_form.php
question_edit_form.add_per_answer_fields
protected function add_per_answer_fields(&$mform, $label, $gradeoptions, $minoptions = QUESTION_NUMANS_START, $addoptions = QUESTION_NUMANS_ADD) { $mform->addElement('header', 'answerhdr', get_string('answers', 'question'), ''); $mform->setExpanded('answerhdr', 1); $answersoption = ''; $repeatedoptions = array(); $repeated = $this->get_per_answer_fields($mform, $label, $gradeoptions, $repeatedoptions, $answersoption); if (isset($this->question->options)) { $repeatsatstart = count($this->question->options->$answersoption); } else { $repeatsatstart = $minoptions; } $this->repeat_elements($repeated, $repeatsatstart, $repeatedoptions, 'noanswers', 'addanswers', $addoptions, $this->get_more_choices_string(), true); }
php
protected function add_per_answer_fields(&$mform, $label, $gradeoptions, $minoptions = QUESTION_NUMANS_START, $addoptions = QUESTION_NUMANS_ADD) { $mform->addElement('header', 'answerhdr', get_string('answers', 'question'), ''); $mform->setExpanded('answerhdr', 1); $answersoption = ''; $repeatedoptions = array(); $repeated = $this->get_per_answer_fields($mform, $label, $gradeoptions, $repeatedoptions, $answersoption); if (isset($this->question->options)) { $repeatsatstart = count($this->question->options->$answersoption); } else { $repeatsatstart = $minoptions; } $this->repeat_elements($repeated, $repeatsatstart, $repeatedoptions, 'noanswers', 'addanswers', $addoptions, $this->get_more_choices_string(), true); }
[ "protected", "function", "add_per_answer_fields", "(", "&", "$", "mform", ",", "$", "label", ",", "$", "gradeoptions", ",", "$", "minoptions", "=", "QUESTION_NUMANS_START", ",", "$", "addoptions", "=", "QUESTION_NUMANS_ADD", ")", "{", "$", "mform", "->", "addElement", "(", "'header'", ",", "'answerhdr'", ",", "get_string", "(", "'answers'", ",", "'question'", ")", ",", "''", ")", ";", "$", "mform", "->", "setExpanded", "(", "'answerhdr'", ",", "1", ")", ";", "$", "answersoption", "=", "''", ";", "$", "repeatedoptions", "=", "array", "(", ")", ";", "$", "repeated", "=", "$", "this", "->", "get_per_answer_fields", "(", "$", "mform", ",", "$", "label", ",", "$", "gradeoptions", ",", "$", "repeatedoptions", ",", "$", "answersoption", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "question", "->", "options", ")", ")", "{", "$", "repeatsatstart", "=", "count", "(", "$", "this", "->", "question", "->", "options", "->", "$", "answersoption", ")", ";", "}", "else", "{", "$", "repeatsatstart", "=", "$", "minoptions", ";", "}", "$", "this", "->", "repeat_elements", "(", "$", "repeated", ",", "$", "repeatsatstart", ",", "$", "repeatedoptions", ",", "'noanswers'", ",", "'addanswers'", ",", "$", "addoptions", ",", "$", "this", "->", "get_more_choices_string", "(", ")", ",", "true", ")", ";", "}" ]
Add a set of form fields, obtained from get_per_answer_fields, to the form, one for each existing answer, with some blanks for some new ones. @param object $mform the form being built. @param $label the label to use for each option. @param $gradeoptions the possible grades for each answer. @param $minoptions the minimum number of answer blanks to display. Default QUESTION_NUMANS_START. @param $addoptions the number of answer blanks to add. Default QUESTION_NUMANS_ADD.
[ "Add", "a", "set", "of", "form", "fields", "obtained", "from", "get_per_answer_fields", "to", "the", "form", "one", "for", "each", "existing", "answer", "with", "some", "blanks", "for", "some", "new", "ones", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/edit_question_form.php#L388-L407
216,907
moodle/moodle
question/type/edit_question_form.php
question_edit_form.get_hint_fields
protected function get_hint_fields($withclearwrong = false, $withshownumpartscorrect = false) { $mform = $this->_form; $repeatedoptions = array(); $repeated = array(); $repeated[] = $mform->createElement('editor', 'hint', get_string('hintn', 'question'), array('rows' => 5), $this->editoroptions); $repeatedoptions['hint']['type'] = PARAM_RAW; $optionelements = array(); if ($withclearwrong) { $optionelements[] = $mform->createElement('advcheckbox', 'hintclearwrong', get_string('options', 'question'), get_string('clearwrongparts', 'question')); } if ($withshownumpartscorrect) { $optionelements[] = $mform->createElement('advcheckbox', 'hintshownumcorrect', '', get_string('shownumpartscorrect', 'question')); } if (count($optionelements)) { $repeated[] = $mform->createElement('group', 'hintoptions', get_string('hintnoptions', 'question'), $optionelements, null, false); } return array($repeated, $repeatedoptions); }
php
protected function get_hint_fields($withclearwrong = false, $withshownumpartscorrect = false) { $mform = $this->_form; $repeatedoptions = array(); $repeated = array(); $repeated[] = $mform->createElement('editor', 'hint', get_string('hintn', 'question'), array('rows' => 5), $this->editoroptions); $repeatedoptions['hint']['type'] = PARAM_RAW; $optionelements = array(); if ($withclearwrong) { $optionelements[] = $mform->createElement('advcheckbox', 'hintclearwrong', get_string('options', 'question'), get_string('clearwrongparts', 'question')); } if ($withshownumpartscorrect) { $optionelements[] = $mform->createElement('advcheckbox', 'hintshownumcorrect', '', get_string('shownumpartscorrect', 'question')); } if (count($optionelements)) { $repeated[] = $mform->createElement('group', 'hintoptions', get_string('hintnoptions', 'question'), $optionelements, null, false); } return array($repeated, $repeatedoptions); }
[ "protected", "function", "get_hint_fields", "(", "$", "withclearwrong", "=", "false", ",", "$", "withshownumpartscorrect", "=", "false", ")", "{", "$", "mform", "=", "$", "this", "->", "_form", ";", "$", "repeatedoptions", "=", "array", "(", ")", ";", "$", "repeated", "=", "array", "(", ")", ";", "$", "repeated", "[", "]", "=", "$", "mform", "->", "createElement", "(", "'editor'", ",", "'hint'", ",", "get_string", "(", "'hintn'", ",", "'question'", ")", ",", "array", "(", "'rows'", "=>", "5", ")", ",", "$", "this", "->", "editoroptions", ")", ";", "$", "repeatedoptions", "[", "'hint'", "]", "[", "'type'", "]", "=", "PARAM_RAW", ";", "$", "optionelements", "=", "array", "(", ")", ";", "if", "(", "$", "withclearwrong", ")", "{", "$", "optionelements", "[", "]", "=", "$", "mform", "->", "createElement", "(", "'advcheckbox'", ",", "'hintclearwrong'", ",", "get_string", "(", "'options'", ",", "'question'", ")", ",", "get_string", "(", "'clearwrongparts'", ",", "'question'", ")", ")", ";", "}", "if", "(", "$", "withshownumpartscorrect", ")", "{", "$", "optionelements", "[", "]", "=", "$", "mform", "->", "createElement", "(", "'advcheckbox'", ",", "'hintshownumcorrect'", ",", "''", ",", "get_string", "(", "'shownumpartscorrect'", ",", "'question'", ")", ")", ";", "}", "if", "(", "count", "(", "$", "optionelements", ")", ")", "{", "$", "repeated", "[", "]", "=", "$", "mform", "->", "createElement", "(", "'group'", ",", "'hintoptions'", ",", "get_string", "(", "'hintnoptions'", ",", "'question'", ")", ",", "$", "optionelements", ",", "null", ",", "false", ")", ";", "}", "return", "array", "(", "$", "repeated", ",", "$", "repeatedoptions", ")", ";", "}" ]
Create the form elements required by one hint. @param string $withclearwrong whether this quesiton type uses the 'Clear wrong' option on hints. @param string $withshownumpartscorrect whether this quesiton type uses the 'Show num parts correct' option on hints. @return array form field elements for one hint.
[ "Create", "the", "form", "elements", "required", "by", "one", "hint", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/edit_question_form.php#L446-L471
216,908
moodle/moodle
question/type/edit_question_form.php
question_edit_form.data_preprocessing_extra_answer_fields
protected function data_preprocessing_extra_answer_fields($question, $extraanswerfields) { // Setting $question->$field[$key] won't work in PHP, so we need set an array of answer values to $question->$field. // As we may have several extra fields with data for several answers in each, we use an array of arrays. // Index in $extrafieldsdata is an extra answer field name, value - array of it's data for each answer. $extrafieldsdata = array(); // First, prepare an array if empty arrays for each extra answer fields data. foreach ($extraanswerfields as $field) { $extrafieldsdata[$field] = array(); } // Fill arrays with data from $question->options->answers. $key = 0; foreach ($question->options->answers as $answer) { foreach ($extraanswerfields as $field) { // See hack comment in {@link data_preprocessing_answers()}. unset($this->_form->_defaultValues["{$field}[{$key}]"]); $extrafieldsdata[$field][$key] = $this->data_preprocessing_extra_answer_field($answer, $field); } $key++; } // Set this data in the $question object. foreach ($extraanswerfields as $field) { $question->$field = $extrafieldsdata[$field]; } return $question; }
php
protected function data_preprocessing_extra_answer_fields($question, $extraanswerfields) { // Setting $question->$field[$key] won't work in PHP, so we need set an array of answer values to $question->$field. // As we may have several extra fields with data for several answers in each, we use an array of arrays. // Index in $extrafieldsdata is an extra answer field name, value - array of it's data for each answer. $extrafieldsdata = array(); // First, prepare an array if empty arrays for each extra answer fields data. foreach ($extraanswerfields as $field) { $extrafieldsdata[$field] = array(); } // Fill arrays with data from $question->options->answers. $key = 0; foreach ($question->options->answers as $answer) { foreach ($extraanswerfields as $field) { // See hack comment in {@link data_preprocessing_answers()}. unset($this->_form->_defaultValues["{$field}[{$key}]"]); $extrafieldsdata[$field][$key] = $this->data_preprocessing_extra_answer_field($answer, $field); } $key++; } // Set this data in the $question object. foreach ($extraanswerfields as $field) { $question->$field = $extrafieldsdata[$field]; } return $question; }
[ "protected", "function", "data_preprocessing_extra_answer_fields", "(", "$", "question", ",", "$", "extraanswerfields", ")", "{", "// Setting $question->$field[$key] won't work in PHP, so we need set an array of answer values to $question->$field.", "// As we may have several extra fields with data for several answers in each, we use an array of arrays.", "// Index in $extrafieldsdata is an extra answer field name, value - array of it's data for each answer.", "$", "extrafieldsdata", "=", "array", "(", ")", ";", "// First, prepare an array if empty arrays for each extra answer fields data.", "foreach", "(", "$", "extraanswerfields", "as", "$", "field", ")", "{", "$", "extrafieldsdata", "[", "$", "field", "]", "=", "array", "(", ")", ";", "}", "// Fill arrays with data from $question->options->answers.", "$", "key", "=", "0", ";", "foreach", "(", "$", "question", "->", "options", "->", "answers", "as", "$", "answer", ")", "{", "foreach", "(", "$", "extraanswerfields", "as", "$", "field", ")", "{", "// See hack comment in {@link data_preprocessing_answers()}.", "unset", "(", "$", "this", "->", "_form", "->", "_defaultValues", "[", "\"{$field}[{$key}]\"", "]", ")", ";", "$", "extrafieldsdata", "[", "$", "field", "]", "[", "$", "key", "]", "=", "$", "this", "->", "data_preprocessing_extra_answer_field", "(", "$", "answer", ",", "$", "field", ")", ";", "}", "$", "key", "++", ";", "}", "// Set this data in the $question object.", "foreach", "(", "$", "extraanswerfields", "as", "$", "field", ")", "{", "$", "question", "->", "$", "field", "=", "$", "extrafieldsdata", "[", "$", "field", "]", ";", "}", "return", "$", "question", ";", "}" ]
Perform the necessary preprocessing for the extra answer fields. Questions that do something not trivial when editing extra answer fields will want to override this. @param object $question the data being passed to the form. @param array $extraanswerfields extra answer fields (without table name). @return object $question the modified data.
[ "Perform", "the", "necessary", "preprocessing", "for", "the", "extra", "answer", "fields", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/type/edit_question_form.php#L675-L701
216,909
moodle/moodle
backup/util/ui/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 instanceof \context_course) { $sectionsql = "itemid IN (SELECT id FROM {course_sections} WHERE course = ?) AND type = ?"; $DB->delete_records_select('backup_controllers', $sectionsql, [$context->instanceid, \backup::TYPE_1SECTION]); $DB->delete_records('backup_controllers', ['itemid' => $context->instanceid, 'type' => \backup::TYPE_1COURSE]); } if ($context instanceof \context_module) { $DB->delete_records('backup_controllers', ['itemid' => $context->instanceid, 'type' => \backup::TYPE_1ACTIVITY]); } return; }
php
public static function delete_data_for_all_users_in_context(\context $context) { global $DB; if ($context instanceof \context_course) { $sectionsql = "itemid IN (SELECT id FROM {course_sections} WHERE course = ?) AND type = ?"; $DB->delete_records_select('backup_controllers', $sectionsql, [$context->instanceid, \backup::TYPE_1SECTION]); $DB->delete_records('backup_controllers', ['itemid' => $context->instanceid, 'type' => \backup::TYPE_1COURSE]); } if ($context instanceof \context_module) { $DB->delete_records('backup_controllers', ['itemid' => $context->instanceid, 'type' => \backup::TYPE_1ACTIVITY]); } return; }
[ "public", "static", "function", "delete_data_for_all_users_in_context", "(", "\\", "context", "$", "context", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "context", "instanceof", "\\", "context_course", ")", "{", "$", "sectionsql", "=", "\"itemid IN (SELECT id FROM {course_sections} WHERE course = ?) AND type = ?\"", ";", "$", "DB", "->", "delete_records_select", "(", "'backup_controllers'", ",", "$", "sectionsql", ",", "[", "$", "context", "->", "instanceid", ",", "\\", "backup", "::", "TYPE_1SECTION", "]", ")", ";", "$", "DB", "->", "delete_records", "(", "'backup_controllers'", ",", "[", "'itemid'", "=>", "$", "context", "->", "instanceid", ",", "'type'", "=>", "\\", "backup", "::", "TYPE_1COURSE", "]", ")", ";", "}", "if", "(", "$", "context", "instanceof", "\\", "context_module", ")", "{", "$", "DB", "->", "delete_records", "(", "'backup_controllers'", ",", "[", "'itemid'", "=>", "$", "context", "->", "instanceid", ",", "'type'", "=>", "\\", "backup", "::", "TYPE_1ACTIVITY", "]", ")", ";", "}", "return", ";", "}" ]
Delete all user data which matches the specified context. Only dealing with the specific context - not it's child contexts. @param \context $context A user context.
[ "Delete", "all", "user", "data", "which", "matches", "the", "specified", "context", ".", "Only", "dealing", "with", "the", "specific", "context", "-", "not", "it", "s", "child", "contexts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/classes/privacy/provider.php#L230-L242
216,910
moodle/moodle
backup/util/ui/classes/privacy/provider.php
provider.delete_data_for_users
public static function delete_data_for_users(approved_userlist $userlist) { global $DB; if (empty($userlist->get_userids())) { return; } $context = $userlist->get_context(); if ($context instanceof \context_course) { list($usersql, $userparams) = $DB->get_in_or_equal($userlist->get_userids(), SQL_PARAMS_NAMED); $select = "itemid = :itemid AND userid {$usersql} AND type = :type"; $params = $userparams; $params['itemid'] = $context->instanceid; $params['type'] = \backup::TYPE_1COURSE; $DB->delete_records_select('backup_controllers', $select, $params); $params = $userparams; $params['course'] = $context->instanceid; $params['type'] = \backup::TYPE_1SECTION; $sectionsql = "itemid IN (SELECT id FROM {course_sections} WHERE course = :course)"; $select = $sectionsql . " AND userid {$usersql} AND type = :type"; $DB->delete_records_select('backup_controllers', $select, $params); } if ($context instanceof \context_module) { list($usersql, $userparams) = $DB->get_in_or_equal($userlist->get_userids(), SQL_PARAMS_NAMED); $select = "itemid = :itemid AND userid {$usersql} AND type = :type"; $params = $userparams; $params['itemid'] = $context->instanceid; $params['type'] = \backup::TYPE_1ACTIVITY; // Delete activity backup data. $select = "itemid = :itemid AND type = :type AND userid {$usersql}"; $params = ['itemid' => $context->instanceid, 'type' => 'activity'] + $userparams; $DB->delete_records_select('backup_controllers', $select, $params); } }
php
public static function delete_data_for_users(approved_userlist $userlist) { global $DB; if (empty($userlist->get_userids())) { return; } $context = $userlist->get_context(); if ($context instanceof \context_course) { list($usersql, $userparams) = $DB->get_in_or_equal($userlist->get_userids(), SQL_PARAMS_NAMED); $select = "itemid = :itemid AND userid {$usersql} AND type = :type"; $params = $userparams; $params['itemid'] = $context->instanceid; $params['type'] = \backup::TYPE_1COURSE; $DB->delete_records_select('backup_controllers', $select, $params); $params = $userparams; $params['course'] = $context->instanceid; $params['type'] = \backup::TYPE_1SECTION; $sectionsql = "itemid IN (SELECT id FROM {course_sections} WHERE course = :course)"; $select = $sectionsql . " AND userid {$usersql} AND type = :type"; $DB->delete_records_select('backup_controllers', $select, $params); } if ($context instanceof \context_module) { list($usersql, $userparams) = $DB->get_in_or_equal($userlist->get_userids(), SQL_PARAMS_NAMED); $select = "itemid = :itemid AND userid {$usersql} AND type = :type"; $params = $userparams; $params['itemid'] = $context->instanceid; $params['type'] = \backup::TYPE_1ACTIVITY; // Delete activity backup data. $select = "itemid = :itemid AND type = :type AND userid {$usersql}"; $params = ['itemid' => $context->instanceid, 'type' => 'activity'] + $userparams; $DB->delete_records_select('backup_controllers', $select, $params); } }
[ "public", "static", "function", "delete_data_for_users", "(", "approved_userlist", "$", "userlist", ")", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "userlist", "->", "get_userids", "(", ")", ")", ")", "{", "return", ";", "}", "$", "context", "=", "$", "userlist", "->", "get_context", "(", ")", ";", "if", "(", "$", "context", "instanceof", "\\", "context_course", ")", "{", "list", "(", "$", "usersql", ",", "$", "userparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "userlist", "->", "get_userids", "(", ")", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "select", "=", "\"itemid = :itemid AND userid {$usersql} AND type = :type\"", ";", "$", "params", "=", "$", "userparams", ";", "$", "params", "[", "'itemid'", "]", "=", "$", "context", "->", "instanceid", ";", "$", "params", "[", "'type'", "]", "=", "\\", "backup", "::", "TYPE_1COURSE", ";", "$", "DB", "->", "delete_records_select", "(", "'backup_controllers'", ",", "$", "select", ",", "$", "params", ")", ";", "$", "params", "=", "$", "userparams", ";", "$", "params", "[", "'course'", "]", "=", "$", "context", "->", "instanceid", ";", "$", "params", "[", "'type'", "]", "=", "\\", "backup", "::", "TYPE_1SECTION", ";", "$", "sectionsql", "=", "\"itemid IN (SELECT id FROM {course_sections} WHERE course = :course)\"", ";", "$", "select", "=", "$", "sectionsql", ".", "\" AND userid {$usersql} AND type = :type\"", ";", "$", "DB", "->", "delete_records_select", "(", "'backup_controllers'", ",", "$", "select", ",", "$", "params", ")", ";", "}", "if", "(", "$", "context", "instanceof", "\\", "context_module", ")", "{", "list", "(", "$", "usersql", ",", "$", "userparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "userlist", "->", "get_userids", "(", ")", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "select", "=", "\"itemid = :itemid AND userid {$usersql} AND type = :type\"", ";", "$", "params", "=", "$", "userparams", ";", "$", "params", "[", "'itemid'", "]", "=", "$", "context", "->", "instanceid", ";", "$", "params", "[", "'type'", "]", "=", "\\", "backup", "::", "TYPE_1ACTIVITY", ";", "// Delete activity backup data.", "$", "select", "=", "\"itemid = :itemid AND type = :type AND userid {$usersql}\"", ";", "$", "params", "=", "[", "'itemid'", "=>", "$", "context", "->", "instanceid", ",", "'type'", "=>", "'activity'", "]", "+", "$", "userparams", ";", "$", "DB", "->", "delete_records_select", "(", "'backup_controllers'", ",", "$", "select", ",", "$", "params", ")", ";", "}", "}" ]
Delete multiple users within a single context. Only dealing with the specific context - not it's child contexts. @param approved_userlist $userlist The approved context and user information to delete information for.
[ "Delete", "multiple", "users", "within", "a", "single", "context", ".", "Only", "dealing", "with", "the", "specific", "context", "-", "not", "it", "s", "child", "contexts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/classes/privacy/provider.php#L250-L286
216,911
moodle/moodle
backup/util/ui/classes/privacy/provider.php
provider.delete_data_for_user
public static function delete_data_for_user(approved_contextlist $contextlist) { global $DB; if (empty($contextlist->count())) { return; } $userid = $contextlist->get_user()->id; foreach ($contextlist->get_contexts() as $context) { if ($context instanceof \context_course) { $select = "itemid = :itemid AND userid = :userid AND type = :type"; $params = [ 'userid' => $userid, 'itemid' => $context->instanceid, 'type' => \backup::TYPE_1COURSE ]; $DB->delete_records_select('backup_controllers', $select, $params); $params = [ 'userid' => $userid, 'course' => $context->instanceid, 'type' => \backup::TYPE_1SECTION ]; $sectionsql = "itemid IN (SELECT id FROM {course_sections} WHERE course = :course)"; $select = $sectionsql . " AND userid = :userid AND type = :type"; $DB->delete_records_select('backup_controllers', $select, $params); } if ($context instanceof \context_module) { list($usersql, $userparams) = $DB->get_in_or_equal($userlist->get_userids(), SQL_PARAMS_NAMED); $select = "itemid = :itemid AND userid = :userid AND type = :type"; $params = [ 'itemid' => $context->instanceid, 'userid' => $userid, 'type' => \backup::TYPE_1ACTIVITY ]; $DB->delete_records_select('backup_controllers', $select, $params); } } }
php
public static function delete_data_for_user(approved_contextlist $contextlist) { global $DB; if (empty($contextlist->count())) { return; } $userid = $contextlist->get_user()->id; foreach ($contextlist->get_contexts() as $context) { if ($context instanceof \context_course) { $select = "itemid = :itemid AND userid = :userid AND type = :type"; $params = [ 'userid' => $userid, 'itemid' => $context->instanceid, 'type' => \backup::TYPE_1COURSE ]; $DB->delete_records_select('backup_controllers', $select, $params); $params = [ 'userid' => $userid, 'course' => $context->instanceid, 'type' => \backup::TYPE_1SECTION ]; $sectionsql = "itemid IN (SELECT id FROM {course_sections} WHERE course = :course)"; $select = $sectionsql . " AND userid = :userid AND type = :type"; $DB->delete_records_select('backup_controllers', $select, $params); } if ($context instanceof \context_module) { list($usersql, $userparams) = $DB->get_in_or_equal($userlist->get_userids(), SQL_PARAMS_NAMED); $select = "itemid = :itemid AND userid = :userid AND type = :type"; $params = [ 'itemid' => $context->instanceid, 'userid' => $userid, 'type' => \backup::TYPE_1ACTIVITY ]; $DB->delete_records_select('backup_controllers', $select, $params); } } }
[ "public", "static", "function", "delete_data_for_user", "(", "approved_contextlist", "$", "contextlist", ")", "{", "global", "$", "DB", ";", "if", "(", "empty", "(", "$", "contextlist", "->", "count", "(", ")", ")", ")", "{", "return", ";", "}", "$", "userid", "=", "$", "contextlist", "->", "get_user", "(", ")", "->", "id", ";", "foreach", "(", "$", "contextlist", "->", "get_contexts", "(", ")", "as", "$", "context", ")", "{", "if", "(", "$", "context", "instanceof", "\\", "context_course", ")", "{", "$", "select", "=", "\"itemid = :itemid AND userid = :userid AND type = :type\"", ";", "$", "params", "=", "[", "'userid'", "=>", "$", "userid", ",", "'itemid'", "=>", "$", "context", "->", "instanceid", ",", "'type'", "=>", "\\", "backup", "::", "TYPE_1COURSE", "]", ";", "$", "DB", "->", "delete_records_select", "(", "'backup_controllers'", ",", "$", "select", ",", "$", "params", ")", ";", "$", "params", "=", "[", "'userid'", "=>", "$", "userid", ",", "'course'", "=>", "$", "context", "->", "instanceid", ",", "'type'", "=>", "\\", "backup", "::", "TYPE_1SECTION", "]", ";", "$", "sectionsql", "=", "\"itemid IN (SELECT id FROM {course_sections} WHERE course = :course)\"", ";", "$", "select", "=", "$", "sectionsql", ".", "\" AND userid = :userid AND type = :type\"", ";", "$", "DB", "->", "delete_records_select", "(", "'backup_controllers'", ",", "$", "select", ",", "$", "params", ")", ";", "}", "if", "(", "$", "context", "instanceof", "\\", "context_module", ")", "{", "list", "(", "$", "usersql", ",", "$", "userparams", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "userlist", "->", "get_userids", "(", ")", ",", "SQL_PARAMS_NAMED", ")", ";", "$", "select", "=", "\"itemid = :itemid AND userid = :userid AND type = :type\"", ";", "$", "params", "=", "[", "'itemid'", "=>", "$", "context", "->", "instanceid", ",", "'userid'", "=>", "$", "userid", ",", "'type'", "=>", "\\", "backup", "::", "TYPE_1ACTIVITY", "]", ";", "$", "DB", "->", "delete_records_select", "(", "'backup_controllers'", ",", "$", "select", ",", "$", "params", ")", ";", "}", "}", "}" ]
Delete all user data for the specified user, in the specified contexts. Only dealing with the specific context - not it's child contexts. @param approved_contextlist $contextlist The approved contexts and user information to delete information for.
[ "Delete", "all", "user", "data", "for", "the", "specified", "user", "in", "the", "specified", "contexts", ".", "Only", "dealing", "with", "the", "specific", "context", "-", "not", "it", "s", "child", "contexts", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/classes/privacy/provider.php#L294-L335
216,912
moodle/moodle
calendar/classes/type_base.php
type_base.convert_to_timestamp
public function convert_to_timestamp($year, $month, $day, $hour = 0, $minute = 0) { $gregorianinfo = $this->convert_to_gregorian($year, $month, $day, $hour, $minute); return make_timestamp( $gregorianinfo['year'], $gregorianinfo['month'], $gregorianinfo['day'], $gregorianinfo['hour'], $gregorianinfo['minute'], 0); }
php
public function convert_to_timestamp($year, $month, $day, $hour = 0, $minute = 0) { $gregorianinfo = $this->convert_to_gregorian($year, $month, $day, $hour, $minute); return make_timestamp( $gregorianinfo['year'], $gregorianinfo['month'], $gregorianinfo['day'], $gregorianinfo['hour'], $gregorianinfo['minute'], 0); }
[ "public", "function", "convert_to_timestamp", "(", "$", "year", ",", "$", "month", ",", "$", "day", ",", "$", "hour", "=", "0", ",", "$", "minute", "=", "0", ")", "{", "$", "gregorianinfo", "=", "$", "this", "->", "convert_to_gregorian", "(", "$", "year", ",", "$", "month", ",", "$", "day", ",", "$", "hour", ",", "$", "minute", ")", ";", "return", "make_timestamp", "(", "$", "gregorianinfo", "[", "'year'", "]", ",", "$", "gregorianinfo", "[", "'month'", "]", ",", "$", "gregorianinfo", "[", "'day'", "]", ",", "$", "gregorianinfo", "[", "'hour'", "]", ",", "$", "gregorianinfo", "[", "'minute'", "]", ",", "0", ")", ";", "}" ]
Provided with a day, month, year, hour and minute in the specific calendar type convert it into the equivalent Unix Time Stamp. @param int $year @param int $month @param int $day @param int $hour @param int $minute @return int timestamp
[ "Provided", "with", "a", "day", "month", "year", "hour", "and", "minute", "in", "the", "specific", "calendar", "type", "convert", "it", "into", "the", "equivalent", "Unix", "Time", "Stamp", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/type_base.php#L232-L241
216,913
moodle/moodle
calendar/classes/type_base.php
type_base.get_prev_day
public function get_prev_day($daytimestamp) { $date = new \DateTime(); $date->setTimestamp($daytimestamp); $date->modify('-1 day'); return $date->getTimestamp(); }
php
public function get_prev_day($daytimestamp) { $date = new \DateTime(); $date->setTimestamp($daytimestamp); $date->modify('-1 day'); return $date->getTimestamp(); }
[ "public", "function", "get_prev_day", "(", "$", "daytimestamp", ")", "{", "$", "date", "=", "new", "\\", "DateTime", "(", ")", ";", "$", "date", "->", "setTimestamp", "(", "$", "daytimestamp", ")", ";", "$", "date", "->", "modify", "(", "'-1 day'", ")", ";", "return", "$", "date", "->", "getTimestamp", "(", ")", ";", "}" ]
Get the previous day. @param int $daytimestamp The day timestamp. @return int previous day timestamp
[ "Get", "the", "previous", "day", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/type_base.php#L249-L255
216,914
moodle/moodle
calendar/classes/type_base.php
type_base.get_next_day
public function get_next_day($daytimestamp) { $date = new \DateTime(); $date->setTimestamp($daytimestamp); $date->modify('+1 day'); return $date->getTimestamp(); }
php
public function get_next_day($daytimestamp) { $date = new \DateTime(); $date->setTimestamp($daytimestamp); $date->modify('+1 day'); return $date->getTimestamp(); }
[ "public", "function", "get_next_day", "(", "$", "daytimestamp", ")", "{", "$", "date", "=", "new", "\\", "DateTime", "(", ")", ";", "$", "date", "->", "setTimestamp", "(", "$", "daytimestamp", ")", ";", "$", "date", "->", "modify", "(", "'+1 day'", ")", ";", "return", "$", "date", "->", "getTimestamp", "(", ")", ";", "}" ]
Get the next day. @param int $daytimestamp The day timestamp. @return int the following day
[ "Get", "the", "next", "day", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/calendar/classes/type_base.php#L263-L269
216,915
moodle/moodle
lib/behat/form_field/behat_form_radio.php
behat_form_radio.set_value
public function set_value($value) { if ($this->running_javascript()) { // Check on radio button. $this->field->click(); // Trigger the onchange event as triggered when 'selecting' the radio. if (!empty($value) && !$this->field->isSelected()) { $this->trigger_on_change(); } } else { // Goutte does not accept a check nor a click in an input[type=radio]. $this->field->setValue($this->field->getAttribute('value')); } }
php
public function set_value($value) { if ($this->running_javascript()) { // Check on radio button. $this->field->click(); // Trigger the onchange event as triggered when 'selecting' the radio. if (!empty($value) && !$this->field->isSelected()) { $this->trigger_on_change(); } } else { // Goutte does not accept a check nor a click in an input[type=radio]. $this->field->setValue($this->field->getAttribute('value')); } }
[ "public", "function", "set_value", "(", "$", "value", ")", "{", "if", "(", "$", "this", "->", "running_javascript", "(", ")", ")", "{", "// Check on radio button.", "$", "this", "->", "field", "->", "click", "(", ")", ";", "// Trigger the onchange event as triggered when 'selecting' the radio.", "if", "(", "!", "empty", "(", "$", "value", ")", "&&", "!", "$", "this", "->", "field", "->", "isSelected", "(", ")", ")", "{", "$", "this", "->", "trigger_on_change", "(", ")", ";", "}", "}", "else", "{", "// Goutte does not accept a check nor a click in an input[type=radio].", "$", "this", "->", "field", "->", "setValue", "(", "$", "this", "->", "field", "->", "getAttribute", "(", "'value'", ")", ")", ";", "}", "}" ]
Sets the value of a radio Partially overwriting behat_form_checkbox implementation as when JS is disabled we can not check() and we should use setValue() @param string $value @return void
[ "Sets", "the", "value", "of", "a", "radio" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/behat/form_field/behat_form_radio.php#L75-L89
216,916
moodle/moodle
lib/htmlpurifier/HTMLPurifier/UnitConverter.php
HTMLPurifier_UnitConverter.div
private function div($s1, $s2, $scale) { if ($this->bcmath) { return bcdiv($s1, $s2, $scale); } else { return $this->scale((float)$s1 / (float)$s2, $scale); } }
php
private function div($s1, $s2, $scale) { if ($this->bcmath) { return bcdiv($s1, $s2, $scale); } else { return $this->scale((float)$s1 / (float)$s2, $scale); } }
[ "private", "function", "div", "(", "$", "s1", ",", "$", "s2", ",", "$", "scale", ")", "{", "if", "(", "$", "this", "->", "bcmath", ")", "{", "return", "bcdiv", "(", "$", "s1", ",", "$", "s2", ",", "$", "scale", ")", ";", "}", "else", "{", "return", "$", "this", "->", "scale", "(", "(", "float", ")", "$", "s1", "/", "(", "float", ")", "$", "s2", ",", "$", "scale", ")", ";", "}", "}" ]
Divides two numbers, using arbitrary precision when available. @param string $s1 @param string $s2 @param int $scale @return string
[ "Divides", "two", "numbers", "using", "arbitrary", "precision", "when", "available", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/UnitConverter.php#L246-L253
216,917
moodle/moodle
lib/adodb/datadict/datadict-mssqlnative.inc.php
ADODB2_mssqlnative.DropColumnSQL
function DropColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') { $tabname = $this->TableName ($tabname); if (!is_array($flds)) $flds = explode(',',$flds); $f = array(); $s = 'ALTER TABLE ' . $tabname; foreach($flds as $v) { if ( $constraintname = $this->DefaultConstraintname($tabname,$v) ) { $sql[] = 'ALTER TABLE ' . $tabname . ' DROP CONSTRAINT ' . $constraintname; } $f[] = ' DROP COLUMN ' . $this->NameQuote($v); } $s .= implode(', ',$f); $sql[] = $s; return $sql; }
php
function DropColumnSQL($tabname, $flds, $tableflds='',$tableoptions='') { $tabname = $this->TableName ($tabname); if (!is_array($flds)) $flds = explode(',',$flds); $f = array(); $s = 'ALTER TABLE ' . $tabname; foreach($flds as $v) { if ( $constraintname = $this->DefaultConstraintname($tabname,$v) ) { $sql[] = 'ALTER TABLE ' . $tabname . ' DROP CONSTRAINT ' . $constraintname; } $f[] = ' DROP COLUMN ' . $this->NameQuote($v); } $s .= implode(', ',$f); $sql[] = $s; return $sql; }
[ "function", "DropColumnSQL", "(", "$", "tabname", ",", "$", "flds", ",", "$", "tableflds", "=", "''", ",", "$", "tableoptions", "=", "''", ")", "{", "$", "tabname", "=", "$", "this", "->", "TableName", "(", "$", "tabname", ")", ";", "if", "(", "!", "is_array", "(", "$", "flds", ")", ")", "$", "flds", "=", "explode", "(", "','", ",", "$", "flds", ")", ";", "$", "f", "=", "array", "(", ")", ";", "$", "s", "=", "'ALTER TABLE '", ".", "$", "tabname", ";", "foreach", "(", "$", "flds", "as", "$", "v", ")", "{", "if", "(", "$", "constraintname", "=", "$", "this", "->", "DefaultConstraintname", "(", "$", "tabname", ",", "$", "v", ")", ")", "{", "$", "sql", "[", "]", "=", "'ALTER TABLE '", ".", "$", "tabname", ".", "' DROP CONSTRAINT '", ".", "$", "constraintname", ";", "}", "$", "f", "[", "]", "=", "' DROP COLUMN '", ".", "$", "this", "->", "NameQuote", "(", "$", "v", ")", ";", "}", "$", "s", ".=", "implode", "(", "', '", ",", "$", "f", ")", ";", "$", "sql", "[", "]", "=", "$", "s", ";", "return", "$", "sql", ";", "}" ]
Drop a column, syntax is ALTER TABLE table DROP COLUMN column,column @param string $tabname Table Name @param string[] $flds One, or an array of Fields To Drop @param string $tableflds Throwaway value to make the function match the parent @param string $tableoptions Throway value to make the function match the parent @return string The SQL necessary to drop the column
[ "Drop", "a", "column", "syntax", "is", "ALTER", "TABLE", "table", "DROP", "COLUMN", "column", "column" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/adodb/datadict/datadict-mssqlnative.inc.php#L223-L239
216,918
moodle/moodle
lib/htmlpurifier/HTMLPurifier/URISchemeRegistry.php
HTMLPurifier_URISchemeRegistry.instance
public static function instance($prototype = null) { static $instance = null; if ($prototype !== null) { $instance = $prototype; } elseif ($instance === null || $prototype == true) { $instance = new HTMLPurifier_URISchemeRegistry(); } return $instance; }
php
public static function instance($prototype = null) { static $instance = null; if ($prototype !== null) { $instance = $prototype; } elseif ($instance === null || $prototype == true) { $instance = new HTMLPurifier_URISchemeRegistry(); } return $instance; }
[ "public", "static", "function", "instance", "(", "$", "prototype", "=", "null", ")", "{", "static", "$", "instance", "=", "null", ";", "if", "(", "$", "prototype", "!==", "null", ")", "{", "$", "instance", "=", "$", "prototype", ";", "}", "elseif", "(", "$", "instance", "===", "null", "||", "$", "prototype", "==", "true", ")", "{", "$", "instance", "=", "new", "HTMLPurifier_URISchemeRegistry", "(", ")", ";", "}", "return", "$", "instance", ";", "}" ]
Retrieve sole instance of the registry. @param HTMLPurifier_URISchemeRegistry $prototype Optional prototype to overload sole instance with, or bool true to reset to default registry. @return HTMLPurifier_URISchemeRegistry @note Pass a registry object $prototype with a compatible interface and the function will copy it and return it all further times.
[ "Retrieve", "sole", "instance", "of", "the", "registry", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/URISchemeRegistry.php#L17-L26
216,919
moodle/moodle
lib/htmlpurifier/HTMLPurifier/URISchemeRegistry.php
HTMLPurifier_URISchemeRegistry.getScheme
public function getScheme($scheme, $config, $context) { if (!$config) { $config = HTMLPurifier_Config::createDefault(); } // important, otherwise attacker could include arbitrary file $allowed_schemes = $config->get('URI.AllowedSchemes'); if (!$config->get('URI.OverrideAllowedSchemes') && !isset($allowed_schemes[$scheme]) ) { return; } if (isset($this->schemes[$scheme])) { return $this->schemes[$scheme]; } if (!isset($allowed_schemes[$scheme])) { return; } $class = 'HTMLPurifier_URIScheme_' . $scheme; if (!class_exists($class)) { return; } $this->schemes[$scheme] = new $class(); return $this->schemes[$scheme]; }
php
public function getScheme($scheme, $config, $context) { if (!$config) { $config = HTMLPurifier_Config::createDefault(); } // important, otherwise attacker could include arbitrary file $allowed_schemes = $config->get('URI.AllowedSchemes'); if (!$config->get('URI.OverrideAllowedSchemes') && !isset($allowed_schemes[$scheme]) ) { return; } if (isset($this->schemes[$scheme])) { return $this->schemes[$scheme]; } if (!isset($allowed_schemes[$scheme])) { return; } $class = 'HTMLPurifier_URIScheme_' . $scheme; if (!class_exists($class)) { return; } $this->schemes[$scheme] = new $class(); return $this->schemes[$scheme]; }
[ "public", "function", "getScheme", "(", "$", "scheme", ",", "$", "config", ",", "$", "context", ")", "{", "if", "(", "!", "$", "config", ")", "{", "$", "config", "=", "HTMLPurifier_Config", "::", "createDefault", "(", ")", ";", "}", "// important, otherwise attacker could include arbitrary file", "$", "allowed_schemes", "=", "$", "config", "->", "get", "(", "'URI.AllowedSchemes'", ")", ";", "if", "(", "!", "$", "config", "->", "get", "(", "'URI.OverrideAllowedSchemes'", ")", "&&", "!", "isset", "(", "$", "allowed_schemes", "[", "$", "scheme", "]", ")", ")", "{", "return", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "schemes", "[", "$", "scheme", "]", ")", ")", "{", "return", "$", "this", "->", "schemes", "[", "$", "scheme", "]", ";", "}", "if", "(", "!", "isset", "(", "$", "allowed_schemes", "[", "$", "scheme", "]", ")", ")", "{", "return", ";", "}", "$", "class", "=", "'HTMLPurifier_URIScheme_'", ".", "$", "scheme", ";", "if", "(", "!", "class_exists", "(", "$", "class", ")", ")", "{", "return", ";", "}", "$", "this", "->", "schemes", "[", "$", "scheme", "]", "=", "new", "$", "class", "(", ")", ";", "return", "$", "this", "->", "schemes", "[", "$", "scheme", "]", ";", "}" ]
Retrieves a scheme validator object @param string $scheme String scheme name like http or mailto @param HTMLPurifier_Config $config @param HTMLPurifier_Context $context @return HTMLPurifier_URIScheme
[ "Retrieves", "a", "scheme", "validator", "object" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/URISchemeRegistry.php#L41-L68
216,920
moodle/moodle
lib/classes/task/tag_cron_task.php
tag_cron_task.compute_correlations
public function compute_correlations($mincorrelation = 2) { global $DB; // This mighty one line query fetches a row from the database for every // individual tag correlation. We then need to process the rows collecting // the correlations for each tag id. // The fields used by this query are as follows: // tagid : This is the tag id, there should be at least $mincorrelation // rows for each tag id. // correlation : This is the tag id that correlates to the above tagid field. // correlationid : This is the id of the row in the tag_correlation table that // relates to the tagid field and will be NULL if there are no // existing correlations. $sql = 'SELECT pairs.tagid, pairs.correlation, pairs.ocurrences, co.id AS correlationid FROM ( SELECT ta.tagid, tb.tagid AS correlation, COUNT(*) AS ocurrences FROM {tag_instance} ta JOIN {tag} tga ON ta.tagid = tga.id JOIN {tag_instance} tb ON (ta.itemtype = tb.itemtype AND ta.component = tb.component AND ta.itemid = tb.itemid AND ta.tagid <> tb.tagid) JOIN {tag} tgb ON tb.tagid = tgb.id AND tgb.tagcollid = tga.tagcollid GROUP BY ta.tagid, tb.tagid HAVING COUNT(*) > :mincorrelation ) pairs LEFT JOIN {tag_correlation} co ON co.tagid = pairs.tagid ORDER BY pairs.tagid ASC, pairs.ocurrences DESC, pairs.correlation ASC'; $rs = $DB->get_recordset_sql($sql, array('mincorrelation' => $mincorrelation)); // Set up an empty tag correlation object. $tagcorrelation = new stdClass; $tagcorrelation->id = null; $tagcorrelation->tagid = null; $tagcorrelation->correlatedtags = array(); // We store each correlation id in this array so we can remove any correlations // that no longer exist. $correlations = array(); // Iterate each row of the result set and build them into tag correlations. // We add all of a tag's correlations to $tagcorrelation->correlatedtags[] // then save the $tagcorrelation object. foreach ($rs as $row) { if ($row->tagid != $tagcorrelation->tagid) { // The tag id has changed so we have all of the correlations for this tag. $tagcorrelationid = $this->process_computed_correlation($tagcorrelation); if ($tagcorrelationid) { $correlations[] = $tagcorrelationid; } // Now we reset the tag correlation object so we can reuse it and set it // up for the current record. $tagcorrelation = new stdClass; $tagcorrelation->id = $row->correlationid; $tagcorrelation->tagid = $row->tagid; $tagcorrelation->correlatedtags = array(); } // Save the correlation on the tag correlation object. $tagcorrelation->correlatedtags[] = $row->correlation; } // Update the current correlation after the last record. $tagcorrelationid = $this->process_computed_correlation($tagcorrelation); if ($tagcorrelationid) { $correlations[] = $tagcorrelationid; } // Close the recordset. $rs->close(); // Remove any correlations that weren't just identified. if (empty($correlations)) { // There are no tag correlations. $DB->delete_records('tag_correlation'); } else { list($sql, $params) = $DB->get_in_or_equal($correlations, SQL_PARAMS_NAMED, 'param0000', false); $DB->delete_records_select('tag_correlation', 'id '.$sql, $params); } }
php
public function compute_correlations($mincorrelation = 2) { global $DB; // This mighty one line query fetches a row from the database for every // individual tag correlation. We then need to process the rows collecting // the correlations for each tag id. // The fields used by this query are as follows: // tagid : This is the tag id, there should be at least $mincorrelation // rows for each tag id. // correlation : This is the tag id that correlates to the above tagid field. // correlationid : This is the id of the row in the tag_correlation table that // relates to the tagid field and will be NULL if there are no // existing correlations. $sql = 'SELECT pairs.tagid, pairs.correlation, pairs.ocurrences, co.id AS correlationid FROM ( SELECT ta.tagid, tb.tagid AS correlation, COUNT(*) AS ocurrences FROM {tag_instance} ta JOIN {tag} tga ON ta.tagid = tga.id JOIN {tag_instance} tb ON (ta.itemtype = tb.itemtype AND ta.component = tb.component AND ta.itemid = tb.itemid AND ta.tagid <> tb.tagid) JOIN {tag} tgb ON tb.tagid = tgb.id AND tgb.tagcollid = tga.tagcollid GROUP BY ta.tagid, tb.tagid HAVING COUNT(*) > :mincorrelation ) pairs LEFT JOIN {tag_correlation} co ON co.tagid = pairs.tagid ORDER BY pairs.tagid ASC, pairs.ocurrences DESC, pairs.correlation ASC'; $rs = $DB->get_recordset_sql($sql, array('mincorrelation' => $mincorrelation)); // Set up an empty tag correlation object. $tagcorrelation = new stdClass; $tagcorrelation->id = null; $tagcorrelation->tagid = null; $tagcorrelation->correlatedtags = array(); // We store each correlation id in this array so we can remove any correlations // that no longer exist. $correlations = array(); // Iterate each row of the result set and build them into tag correlations. // We add all of a tag's correlations to $tagcorrelation->correlatedtags[] // then save the $tagcorrelation object. foreach ($rs as $row) { if ($row->tagid != $tagcorrelation->tagid) { // The tag id has changed so we have all of the correlations for this tag. $tagcorrelationid = $this->process_computed_correlation($tagcorrelation); if ($tagcorrelationid) { $correlations[] = $tagcorrelationid; } // Now we reset the tag correlation object so we can reuse it and set it // up for the current record. $tagcorrelation = new stdClass; $tagcorrelation->id = $row->correlationid; $tagcorrelation->tagid = $row->tagid; $tagcorrelation->correlatedtags = array(); } // Save the correlation on the tag correlation object. $tagcorrelation->correlatedtags[] = $row->correlation; } // Update the current correlation after the last record. $tagcorrelationid = $this->process_computed_correlation($tagcorrelation); if ($tagcorrelationid) { $correlations[] = $tagcorrelationid; } // Close the recordset. $rs->close(); // Remove any correlations that weren't just identified. if (empty($correlations)) { // There are no tag correlations. $DB->delete_records('tag_correlation'); } else { list($sql, $params) = $DB->get_in_or_equal($correlations, SQL_PARAMS_NAMED, 'param0000', false); $DB->delete_records_select('tag_correlation', 'id '.$sql, $params); } }
[ "public", "function", "compute_correlations", "(", "$", "mincorrelation", "=", "2", ")", "{", "global", "$", "DB", ";", "// This mighty one line query fetches a row from the database for every", "// individual tag correlation. We then need to process the rows collecting", "// the correlations for each tag id.", "// The fields used by this query are as follows:", "// tagid : This is the tag id, there should be at least $mincorrelation", "// rows for each tag id.", "// correlation : This is the tag id that correlates to the above tagid field.", "// correlationid : This is the id of the row in the tag_correlation table that", "// relates to the tagid field and will be NULL if there are no", "// existing correlations.", "$", "sql", "=", "'SELECT pairs.tagid, pairs.correlation, pairs.ocurrences, co.id AS correlationid\n FROM (\n SELECT ta.tagid, tb.tagid AS correlation, COUNT(*) AS ocurrences\n FROM {tag_instance} ta\n JOIN {tag} tga ON ta.tagid = tga.id\n JOIN {tag_instance} tb ON (ta.itemtype = tb.itemtype AND ta.component = tb.component\n AND ta.itemid = tb.itemid AND ta.tagid <> tb.tagid)\n JOIN {tag} tgb ON tb.tagid = tgb.id AND tgb.tagcollid = tga.tagcollid\n GROUP BY ta.tagid, tb.tagid\n HAVING COUNT(*) > :mincorrelation\n ) pairs\n LEFT JOIN {tag_correlation} co ON co.tagid = pairs.tagid\n ORDER BY pairs.tagid ASC, pairs.ocurrences DESC, pairs.correlation ASC'", ";", "$", "rs", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ",", "array", "(", "'mincorrelation'", "=>", "$", "mincorrelation", ")", ")", ";", "// Set up an empty tag correlation object.", "$", "tagcorrelation", "=", "new", "stdClass", ";", "$", "tagcorrelation", "->", "id", "=", "null", ";", "$", "tagcorrelation", "->", "tagid", "=", "null", ";", "$", "tagcorrelation", "->", "correlatedtags", "=", "array", "(", ")", ";", "// We store each correlation id in this array so we can remove any correlations", "// that no longer exist.", "$", "correlations", "=", "array", "(", ")", ";", "// Iterate each row of the result set and build them into tag correlations.", "// We add all of a tag's correlations to $tagcorrelation->correlatedtags[]", "// then save the $tagcorrelation object.", "foreach", "(", "$", "rs", "as", "$", "row", ")", "{", "if", "(", "$", "row", "->", "tagid", "!=", "$", "tagcorrelation", "->", "tagid", ")", "{", "// The tag id has changed so we have all of the correlations for this tag.", "$", "tagcorrelationid", "=", "$", "this", "->", "process_computed_correlation", "(", "$", "tagcorrelation", ")", ";", "if", "(", "$", "tagcorrelationid", ")", "{", "$", "correlations", "[", "]", "=", "$", "tagcorrelationid", ";", "}", "// Now we reset the tag correlation object so we can reuse it and set it", "// up for the current record.", "$", "tagcorrelation", "=", "new", "stdClass", ";", "$", "tagcorrelation", "->", "id", "=", "$", "row", "->", "correlationid", ";", "$", "tagcorrelation", "->", "tagid", "=", "$", "row", "->", "tagid", ";", "$", "tagcorrelation", "->", "correlatedtags", "=", "array", "(", ")", ";", "}", "// Save the correlation on the tag correlation object.", "$", "tagcorrelation", "->", "correlatedtags", "[", "]", "=", "$", "row", "->", "correlation", ";", "}", "// Update the current correlation after the last record.", "$", "tagcorrelationid", "=", "$", "this", "->", "process_computed_correlation", "(", "$", "tagcorrelation", ")", ";", "if", "(", "$", "tagcorrelationid", ")", "{", "$", "correlations", "[", "]", "=", "$", "tagcorrelationid", ";", "}", "// Close the recordset.", "$", "rs", "->", "close", "(", ")", ";", "// Remove any correlations that weren't just identified.", "if", "(", "empty", "(", "$", "correlations", ")", ")", "{", "// There are no tag correlations.", "$", "DB", "->", "delete_records", "(", "'tag_correlation'", ")", ";", "}", "else", "{", "list", "(", "$", "sql", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "correlations", ",", "SQL_PARAMS_NAMED", ",", "'param0000'", ",", "false", ")", ";", "$", "DB", "->", "delete_records_select", "(", "'tag_correlation'", ",", "'id '", ".", "$", "sql", ",", "$", "params", ")", ";", "}", "}" ]
Calculates and stores the correlated tags of all tags. The correlations are stored in the 'tag_correlation' table. Two tags are correlated if they appear together a lot. Ex.: Users tagged with "computers" will probably also be tagged with "algorithms". The rationale for the 'tag_correlation' table is performance. It works as a cache for a potentially heavy load query done at the 'tag_instance' table. So, the 'tag_correlation' table stores redundant information derived from the 'tag_instance' table. @param int $mincorrelation Only tags with more than $mincorrelation correlations will be identified.
[ "Calculates", "and", "stores", "the", "correlated", "tags", "of", "all", "tags", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/task/tag_cron_task.php#L69-L145
216,921
moodle/moodle
lib/classes/task/tag_cron_task.php
tag_cron_task.cleanup
public function cleanup() { global $DB; // Get ids to delete from instances where the tag has been deleted. This should never happen apparently. $sql = "SELECT ti.id FROM {tag_instance} ti LEFT JOIN {tag} t ON t.id = ti.tagid WHERE t.id IS null"; $tagids = $DB->get_records_sql($sql); $tagarray = array(); foreach ($tagids as $tagid) { $tagarray[] = $tagid->id; } // Next get ids from instances that have an owner that has been deleted. $sql = "SELECT ti.id FROM {tag_instance} ti, {user} u WHERE ti.itemid = u.id AND ti.itemtype = 'user' AND ti.component = 'core' AND u.deleted = 1"; $tagids = $DB->get_records_sql($sql); foreach ($tagids as $tagid) { $tagarray[] = $tagid->id; } // Get the other itemtypes. $sql = "SELECT DISTINCT component, itemtype FROM {tag_instance} WHERE itemtype <> 'user' or component <> 'core'"; $tagareas = $DB->get_recordset_sql($sql); foreach ($tagareas as $tagarea) { $sql = 'SELECT ti.id FROM {tag_instance} ti LEFT JOIN {' . $tagarea->itemtype . '} it ON it.id = ti.itemid WHERE it.id IS null AND ti.itemtype = ? AND ti.component = ?'; $tagids = $DB->get_records_sql($sql, array($tagarea->itemtype, $tagarea->component)); foreach ($tagids as $tagid) { $tagarray[] = $tagid->id; } } $tagareas->close(); // Get instances for each of the ids to be deleted. if (count($tagarray) > 0) { list($sqlin, $params) = $DB->get_in_or_equal($tagarray); $sql = "SELECT ti.*, COALESCE(t.name, 'deleted') AS name, COALESCE(t.rawname, 'deleted') AS rawname FROM {tag_instance} ti LEFT JOIN {tag} t ON t.id = ti.tagid WHERE ti.id $sqlin"; $instances = $DB->get_records_sql($sql, $params); $this->bulk_delete_instances($instances); } core_tag_collection::cleanup_unused_tags(); }
php
public function cleanup() { global $DB; // Get ids to delete from instances where the tag has been deleted. This should never happen apparently. $sql = "SELECT ti.id FROM {tag_instance} ti LEFT JOIN {tag} t ON t.id = ti.tagid WHERE t.id IS null"; $tagids = $DB->get_records_sql($sql); $tagarray = array(); foreach ($tagids as $tagid) { $tagarray[] = $tagid->id; } // Next get ids from instances that have an owner that has been deleted. $sql = "SELECT ti.id FROM {tag_instance} ti, {user} u WHERE ti.itemid = u.id AND ti.itemtype = 'user' AND ti.component = 'core' AND u.deleted = 1"; $tagids = $DB->get_records_sql($sql); foreach ($tagids as $tagid) { $tagarray[] = $tagid->id; } // Get the other itemtypes. $sql = "SELECT DISTINCT component, itemtype FROM {tag_instance} WHERE itemtype <> 'user' or component <> 'core'"; $tagareas = $DB->get_recordset_sql($sql); foreach ($tagareas as $tagarea) { $sql = 'SELECT ti.id FROM {tag_instance} ti LEFT JOIN {' . $tagarea->itemtype . '} it ON it.id = ti.itemid WHERE it.id IS null AND ti.itemtype = ? AND ti.component = ?'; $tagids = $DB->get_records_sql($sql, array($tagarea->itemtype, $tagarea->component)); foreach ($tagids as $tagid) { $tagarray[] = $tagid->id; } } $tagareas->close(); // Get instances for each of the ids to be deleted. if (count($tagarray) > 0) { list($sqlin, $params) = $DB->get_in_or_equal($tagarray); $sql = "SELECT ti.*, COALESCE(t.name, 'deleted') AS name, COALESCE(t.rawname, 'deleted') AS rawname FROM {tag_instance} ti LEFT JOIN {tag} t ON t.id = ti.tagid WHERE ti.id $sqlin"; $instances = $DB->get_records_sql($sql, $params); $this->bulk_delete_instances($instances); } core_tag_collection::cleanup_unused_tags(); }
[ "public", "function", "cleanup", "(", ")", "{", "global", "$", "DB", ";", "// Get ids to delete from instances where the tag has been deleted. This should never happen apparently.", "$", "sql", "=", "\"SELECT ti.id\n FROM {tag_instance} ti\n LEFT JOIN {tag} t ON t.id = ti.tagid\n WHERE t.id IS null\"", ";", "$", "tagids", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ")", ";", "$", "tagarray", "=", "array", "(", ")", ";", "foreach", "(", "$", "tagids", "as", "$", "tagid", ")", "{", "$", "tagarray", "[", "]", "=", "$", "tagid", "->", "id", ";", "}", "// Next get ids from instances that have an owner that has been deleted.", "$", "sql", "=", "\"SELECT ti.id\n FROM {tag_instance} ti, {user} u\n WHERE ti.itemid = u.id\n AND ti.itemtype = 'user'\n AND ti.component = 'core'\n AND u.deleted = 1\"", ";", "$", "tagids", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ")", ";", "foreach", "(", "$", "tagids", "as", "$", "tagid", ")", "{", "$", "tagarray", "[", "]", "=", "$", "tagid", "->", "id", ";", "}", "// Get the other itemtypes.", "$", "sql", "=", "\"SELECT DISTINCT component, itemtype\n FROM {tag_instance}\n WHERE itemtype <> 'user' or component <> 'core'\"", ";", "$", "tagareas", "=", "$", "DB", "->", "get_recordset_sql", "(", "$", "sql", ")", ";", "foreach", "(", "$", "tagareas", "as", "$", "tagarea", ")", "{", "$", "sql", "=", "'SELECT ti.id\n FROM {tag_instance} ti\n LEFT JOIN {'", ".", "$", "tagarea", "->", "itemtype", ".", "'} it ON it.id = ti.itemid\n WHERE it.id IS null\n AND ti.itemtype = ? AND ti.component = ?'", ";", "$", "tagids", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "array", "(", "$", "tagarea", "->", "itemtype", ",", "$", "tagarea", "->", "component", ")", ")", ";", "foreach", "(", "$", "tagids", "as", "$", "tagid", ")", "{", "$", "tagarray", "[", "]", "=", "$", "tagid", "->", "id", ";", "}", "}", "$", "tagareas", "->", "close", "(", ")", ";", "// Get instances for each of the ids to be deleted.", "if", "(", "count", "(", "$", "tagarray", ")", ">", "0", ")", "{", "list", "(", "$", "sqlin", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "tagarray", ")", ";", "$", "sql", "=", "\"SELECT ti.*, COALESCE(t.name, 'deleted') AS name, COALESCE(t.rawname, 'deleted') AS rawname\n FROM {tag_instance} ti\n LEFT JOIN {tag} t ON t.id = ti.tagid\n WHERE ti.id $sqlin\"", ";", "$", "instances", "=", "$", "DB", "->", "get_records_sql", "(", "$", "sql", ",", "$", "params", ")", ";", "$", "this", "->", "bulk_delete_instances", "(", "$", "instances", ")", ";", "}", "core_tag_collection", "::", "cleanup_unused_tags", "(", ")", ";", "}" ]
Clean up the tag tables, making sure all tagged object still exists. This method is called from cron. This should normally not be necessary, but in case related tags are not deleted when the tagged record is removed, this should be done once in a while, perhaps on an occasional cron run. On a site with lots of tags, this could become an expensive function to call.
[ "Clean", "up", "the", "tag", "tables", "making", "sure", "all", "tagged", "object", "still", "exists", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/task/tag_cron_task.php#L157-L213
216,922
moodle/moodle
lib/classes/task/tag_cron_task.php
tag_cron_task.process_computed_correlation
public function process_computed_correlation(stdClass $tagcorrelation) { global $DB; // You must provide a tagid and correlatedtags must be set and be an array. if (empty($tagcorrelation->tagid) || !isset($tagcorrelation->correlatedtags) || !is_array($tagcorrelation->correlatedtags)) { return false; } $tagcorrelation->correlatedtags = join(',', $tagcorrelation->correlatedtags); if (!empty($tagcorrelation->id)) { // The tag correlation already exists so update it. $DB->update_record('tag_correlation', $tagcorrelation); } else { // This is a new correlation to insert. $tagcorrelation->id = $DB->insert_record('tag_correlation', $tagcorrelation); } return $tagcorrelation->id; }
php
public function process_computed_correlation(stdClass $tagcorrelation) { global $DB; // You must provide a tagid and correlatedtags must be set and be an array. if (empty($tagcorrelation->tagid) || !isset($tagcorrelation->correlatedtags) || !is_array($tagcorrelation->correlatedtags)) { return false; } $tagcorrelation->correlatedtags = join(',', $tagcorrelation->correlatedtags); if (!empty($tagcorrelation->id)) { // The tag correlation already exists so update it. $DB->update_record('tag_correlation', $tagcorrelation); } else { // This is a new correlation to insert. $tagcorrelation->id = $DB->insert_record('tag_correlation', $tagcorrelation); } return $tagcorrelation->id; }
[ "public", "function", "process_computed_correlation", "(", "stdClass", "$", "tagcorrelation", ")", "{", "global", "$", "DB", ";", "// You must provide a tagid and correlatedtags must be set and be an array.", "if", "(", "empty", "(", "$", "tagcorrelation", "->", "tagid", ")", "||", "!", "isset", "(", "$", "tagcorrelation", "->", "correlatedtags", ")", "||", "!", "is_array", "(", "$", "tagcorrelation", "->", "correlatedtags", ")", ")", "{", "return", "false", ";", "}", "$", "tagcorrelation", "->", "correlatedtags", "=", "join", "(", "','", ",", "$", "tagcorrelation", "->", "correlatedtags", ")", ";", "if", "(", "!", "empty", "(", "$", "tagcorrelation", "->", "id", ")", ")", "{", "// The tag correlation already exists so update it.", "$", "DB", "->", "update_record", "(", "'tag_correlation'", ",", "$", "tagcorrelation", ")", ";", "}", "else", "{", "// This is a new correlation to insert.", "$", "tagcorrelation", "->", "id", "=", "$", "DB", "->", "insert_record", "(", "'tag_correlation'", ",", "$", "tagcorrelation", ")", ";", "}", "return", "$", "tagcorrelation", "->", "id", ";", "}" ]
This function processes a tag correlation and makes changes in the database as required. The tag correlation object needs have both a tagid property and a correlatedtags property that is an array. @param stdClass $tagcorrelation @return int/bool The id of the tag correlation that was just processed or false.
[ "This", "function", "processes", "a", "tag", "correlation", "and", "makes", "changes", "in", "the", "database", "as", "required", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/task/tag_cron_task.php#L223-L241
216,923
moodle/moodle
lib/classes/task/tag_cron_task.php
tag_cron_task.bulk_delete_instances
public function bulk_delete_instances($instances) { global $DB; $instanceids = array(); foreach ($instances as $instance) { $instanceids[] = $instance->id; } // This is a multi db compatible method of creating the correct sql when using the 'IN' value. // $insql is the sql statement, $params are the id numbers. list($insql, $params) = $DB->get_in_or_equal($instanceids); $sql = 'id ' . $insql; $DB->delete_records_select('tag_instance', $sql, $params); // Now go through and record each tag individually with the event system. foreach ($instances as $instance) { // Trigger tag removed event (i.e. The tag instance has been removed). \core\event\tag_removed::create_from_tag_instance($instance, $instance->name, $instance->rawname, true)->trigger(); } }
php
public function bulk_delete_instances($instances) { global $DB; $instanceids = array(); foreach ($instances as $instance) { $instanceids[] = $instance->id; } // This is a multi db compatible method of creating the correct sql when using the 'IN' value. // $insql is the sql statement, $params are the id numbers. list($insql, $params) = $DB->get_in_or_equal($instanceids); $sql = 'id ' . $insql; $DB->delete_records_select('tag_instance', $sql, $params); // Now go through and record each tag individually with the event system. foreach ($instances as $instance) { // Trigger tag removed event (i.e. The tag instance has been removed). \core\event\tag_removed::create_from_tag_instance($instance, $instance->name, $instance->rawname, true)->trigger(); } }
[ "public", "function", "bulk_delete_instances", "(", "$", "instances", ")", "{", "global", "$", "DB", ";", "$", "instanceids", "=", "array", "(", ")", ";", "foreach", "(", "$", "instances", "as", "$", "instance", ")", "{", "$", "instanceids", "[", "]", "=", "$", "instance", "->", "id", ";", "}", "// This is a multi db compatible method of creating the correct sql when using the 'IN' value.", "// $insql is the sql statement, $params are the id numbers.", "list", "(", "$", "insql", ",", "$", "params", ")", "=", "$", "DB", "->", "get_in_or_equal", "(", "$", "instanceids", ")", ";", "$", "sql", "=", "'id '", ".", "$", "insql", ";", "$", "DB", "->", "delete_records_select", "(", "'tag_instance'", ",", "$", "sql", ",", "$", "params", ")", ";", "// Now go through and record each tag individually with the event system.", "foreach", "(", "$", "instances", "as", "$", "instance", ")", "{", "// Trigger tag removed event (i.e. The tag instance has been removed).", "\\", "core", "\\", "event", "\\", "tag_removed", "::", "create_from_tag_instance", "(", "$", "instance", ",", "$", "instance", "->", "name", ",", "$", "instance", "->", "rawname", ",", "true", ")", "->", "trigger", "(", ")", ";", "}", "}" ]
This function will delete numerous tag instances efficiently. This removes tag instances only. It doesn't check to see if it is the last use of a tag. @param array $instances An array of tag instance objects with the addition of the tagname and tagrawname (used for recording a delete event).
[ "This", "function", "will", "delete", "numerous", "tag", "instances", "efficiently", ".", "This", "removes", "tag", "instances", "only", ".", "It", "doesn", "t", "check", "to", "see", "if", "it", "is", "the", "last", "use", "of", "a", "tag", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/classes/task/tag_cron_task.php#L250-L270
216,924
moodle/moodle
question/behaviour/adaptive/behaviour.php
qbehaviour_adaptive.adaptive_mark_details_from_step
protected function adaptive_mark_details_from_step(question_attempt_step $gradedstep, question_state $state, $maxmark, $penalty) { $details = new qbehaviour_adaptive_mark_details($state); $details->maxmark = $maxmark; $details->actualmark = $gradedstep->get_fraction() * $details->maxmark; $details->rawmark = $gradedstep->get_behaviour_var('_rawfraction') * $details->maxmark; $details->currentpenalty = $penalty * $details->maxmark; $details->totalpenalty = $details->currentpenalty * $this->qa->get_last_behaviour_var('_try', 0); $details->improvable = $this->is_state_improvable($gradedstep->get_state()); return $details; }
php
protected function adaptive_mark_details_from_step(question_attempt_step $gradedstep, question_state $state, $maxmark, $penalty) { $details = new qbehaviour_adaptive_mark_details($state); $details->maxmark = $maxmark; $details->actualmark = $gradedstep->get_fraction() * $details->maxmark; $details->rawmark = $gradedstep->get_behaviour_var('_rawfraction') * $details->maxmark; $details->currentpenalty = $penalty * $details->maxmark; $details->totalpenalty = $details->currentpenalty * $this->qa->get_last_behaviour_var('_try', 0); $details->improvable = $this->is_state_improvable($gradedstep->get_state()); return $details; }
[ "protected", "function", "adaptive_mark_details_from_step", "(", "question_attempt_step", "$", "gradedstep", ",", "question_state", "$", "state", ",", "$", "maxmark", ",", "$", "penalty", ")", "{", "$", "details", "=", "new", "qbehaviour_adaptive_mark_details", "(", "$", "state", ")", ";", "$", "details", "->", "maxmark", "=", "$", "maxmark", ";", "$", "details", "->", "actualmark", "=", "$", "gradedstep", "->", "get_fraction", "(", ")", "*", "$", "details", "->", "maxmark", ";", "$", "details", "->", "rawmark", "=", "$", "gradedstep", "->", "get_behaviour_var", "(", "'_rawfraction'", ")", "*", "$", "details", "->", "maxmark", ";", "$", "details", "->", "currentpenalty", "=", "$", "penalty", "*", "$", "details", "->", "maxmark", ";", "$", "details", "->", "totalpenalty", "=", "$", "details", "->", "currentpenalty", "*", "$", "this", "->", "qa", "->", "get_last_behaviour_var", "(", "'_try'", ",", "0", ")", ";", "$", "details", "->", "improvable", "=", "$", "this", "->", "is_state_improvable", "(", "$", "gradedstep", "->", "get_state", "(", ")", ")", ";", "return", "$", "details", ";", "}" ]
Actually populate the qbehaviour_adaptive_mark_details object. @param question_attempt_step $gradedstep the step that holds the relevant mark details. @param question_state $state the state corresponding to $gradedstep. @param unknown_type $maxmark the maximum mark for this question_attempt. @param unknown_type $penalty the penalty for this question, as a fraction.
[ "Actually", "populate", "the", "qbehaviour_adaptive_mark_details", "object", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/question/behaviour/adaptive/behaviour.php#L263-L277
216,925
moodle/moodle
lib/filebrowser/file_info.php
file_info.get_params_rawencoded
public function get_params_rawencoded() { $params = $this->get_params(); $encoded = array(); $encoded[] = 'contextid=' . $params['contextid']; $encoded[] = 'component=' . $params['component']; $encoded[] = 'filearea=' . $params['filearea']; $encoded[] = 'itemid=' . (is_null($params['itemid']) ? -1 : $params['itemid']); $encoded[] = 'filepath=' . (is_null($params['filepath']) ? '' : rawurlencode($params['filepath'])); $encoded[] = 'filename=' . ((is_null($params['filename']) or $params['filename'] === '.') ? '' : rawurlencode($params['filename'])); return $encoded; }
php
public function get_params_rawencoded() { $params = $this->get_params(); $encoded = array(); $encoded[] = 'contextid=' . $params['contextid']; $encoded[] = 'component=' . $params['component']; $encoded[] = 'filearea=' . $params['filearea']; $encoded[] = 'itemid=' . (is_null($params['itemid']) ? -1 : $params['itemid']); $encoded[] = 'filepath=' . (is_null($params['filepath']) ? '' : rawurlencode($params['filepath'])); $encoded[] = 'filename=' . ((is_null($params['filename']) or $params['filename'] === '.') ? '' : rawurlencode($params['filename'])); return $encoded; }
[ "public", "function", "get_params_rawencoded", "(", ")", "{", "$", "params", "=", "$", "this", "->", "get_params", "(", ")", ";", "$", "encoded", "=", "array", "(", ")", ";", "$", "encoded", "[", "]", "=", "'contextid='", ".", "$", "params", "[", "'contextid'", "]", ";", "$", "encoded", "[", "]", "=", "'component='", ".", "$", "params", "[", "'component'", "]", ";", "$", "encoded", "[", "]", "=", "'filearea='", ".", "$", "params", "[", "'filearea'", "]", ";", "$", "encoded", "[", "]", "=", "'itemid='", ".", "(", "is_null", "(", "$", "params", "[", "'itemid'", "]", ")", "?", "-", "1", ":", "$", "params", "[", "'itemid'", "]", ")", ";", "$", "encoded", "[", "]", "=", "'filepath='", ".", "(", "is_null", "(", "$", "params", "[", "'filepath'", "]", ")", "?", "''", ":", "rawurlencode", "(", "$", "params", "[", "'filepath'", "]", ")", ")", ";", "$", "encoded", "[", "]", "=", "'filename='", ".", "(", "(", "is_null", "(", "$", "params", "[", "'filename'", "]", ")", "or", "$", "params", "[", "'filename'", "]", "===", "'.'", ")", "?", "''", ":", "rawurlencode", "(", "$", "params", "[", "'filename'", "]", ")", ")", ";", "return", "$", "encoded", ";", "}" ]
Returns array of url encoded params. @return array with numeric keys
[ "Returns", "array", "of", "url", "encoded", "params", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filebrowser/file_info.php#L213-L224
216,926
moodle/moodle
lib/htmlpurifier/HTMLPurifier/Bootstrap.php
HTMLPurifier_Bootstrap.getPath
public static function getPath($class) { if (strncmp('HTMLPurifier', $class, 12) !== 0) { return false; } // Custom implementations if (strncmp('HTMLPurifier_Language_', $class, 22) === 0) { $code = str_replace('_', '-', substr($class, 22)); $file = 'HTMLPurifier/Language/classes/' . $code . '.php'; } else { $file = str_replace('_', '/', $class) . '.php'; } if (!file_exists(HTMLPURIFIER_PREFIX . '/' . $file)) { return false; } return $file; }
php
public static function getPath($class) { if (strncmp('HTMLPurifier', $class, 12) !== 0) { return false; } // Custom implementations if (strncmp('HTMLPurifier_Language_', $class, 22) === 0) { $code = str_replace('_', '-', substr($class, 22)); $file = 'HTMLPurifier/Language/classes/' . $code . '.php'; } else { $file = str_replace('_', '/', $class) . '.php'; } if (!file_exists(HTMLPURIFIER_PREFIX . '/' . $file)) { return false; } return $file; }
[ "public", "static", "function", "getPath", "(", "$", "class", ")", "{", "if", "(", "strncmp", "(", "'HTMLPurifier'", ",", "$", "class", ",", "12", ")", "!==", "0", ")", "{", "return", "false", ";", "}", "// Custom implementations", "if", "(", "strncmp", "(", "'HTMLPurifier_Language_'", ",", "$", "class", ",", "22", ")", "===", "0", ")", "{", "$", "code", "=", "str_replace", "(", "'_'", ",", "'-'", ",", "substr", "(", "$", "class", ",", "22", ")", ")", ";", "$", "file", "=", "'HTMLPurifier/Language/classes/'", ".", "$", "code", ".", "'.php'", ";", "}", "else", "{", "$", "file", "=", "str_replace", "(", "'_'", ",", "'/'", ",", "$", "class", ")", ".", "'.php'", ";", "}", "if", "(", "!", "file_exists", "(", "HTMLPURIFIER_PREFIX", ".", "'/'", ".", "$", "file", ")", ")", "{", "return", "false", ";", "}", "return", "$", "file", ";", "}" ]
Returns the path for a specific class. @param string $class Class path to get @return string
[ "Returns", "the", "path", "for", "a", "specific", "class", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/htmlpurifier/HTMLPurifier/Bootstrap.php#L58-L74
216,927
moodle/moodle
lib/pear/HTML/QuickForm/autocomplete.php
HTML_QuickForm_autocomplete.toHtml
function toHtml() { // prevent problems with grouped elements $arrayName = str_replace(array('[', ']'), array('__', ''), $this->getName()) . '_values'; $this->updateAttributes(array( 'onkeypress' => 'return autocomplete(this, event, ' . $arrayName . ');' )); if ($this->_flagFrozen) { $js = ''; } else { $js = "<script type=\"text/javascript\">\n//<![CDATA[\n"; if (!defined('HTML_QUICKFORM_AUTOCOMPLETE_EXISTS')) { $this->_js .= <<<EOS /* begin javascript for autocomplete */ function setSelectionRange(input, selectionStart, selectionEnd) { if (input.setSelectionRange) { input.setSelectionRange(selectionStart, selectionEnd); } else if (input.createTextRange) { var range = input.createTextRange(); range.collapse(true); range.moveEnd("character", selectionEnd); range.moveStart("character", selectionStart); range.select(); } input.focus(); } function setCaretToPosition(input, position) { setSelectionRange(input, position, position); } function replaceSelection (input, replaceString) { var len = replaceString.length; if (input.setSelectionRange) { var selectionStart = input.selectionStart; var selectionEnd = input.selectionEnd; input.value = input.value.substring(0, selectionStart) + replaceString + input.value.substring(selectionEnd); input.selectionStart = selectionStart + len; input.selectionEnd = selectionStart + len; } else if (document.selection) { var range = document.selection.createRange(); var saved_range = range.duplicate(); if (range.parentElement() == input) { range.text = replaceString; range.moveEnd("character", saved_range.selectionStart + len); range.moveStart("character", saved_range.selectionStart + len); range.select(); } } input.focus(); } function autocompleteMatch (text, values) { for (var i = 0; i < values.length; i++) { if (values[i].toUpperCase().indexOf(text.toUpperCase()) == 0) { return values[i]; } } return null; } function autocomplete(textbox, event, values) { if (textbox.setSelectionRange || textbox.createTextRange) { switch (event.keyCode) { case 38: // up arrow case 40: // down arrow case 37: // left arrow case 39: // right arrow case 33: // page up case 34: // page down case 36: // home case 35: // end case 13: // enter case 9: // tab case 27: // esc case 16: // shift case 17: // ctrl case 18: // alt case 20: // caps lock case 8: // backspace case 46: // delete return true; break; default: var c = String.fromCharCode( (event.charCode == undefined) ? event.keyCode : event.charCode ); replaceSelection(textbox, c); sMatch = autocompleteMatch(textbox.value, values); var len = textbox.value.length; if (sMatch != null) { textbox.value = sMatch; setSelectionRange(textbox, len, textbox.value.length); } return false; } } else { return true; } } /* end javascript for autocomplete */ EOS; define('HTML_QUICKFORM_AUTOCOMPLETE_EXISTS', true); } $jsEscape = array( "\r" => '\r', "\n" => '\n', "\t" => '\t', "'" => "\\'", '"' => '\"', '\\' => '\\\\' ); $js .= $this->_js; $js .= 'var ' . $arrayName . " = new Array();\n"; for ($i = 0; $i < count($this->_options); $i++) { $js .= $arrayName . '[' . $i . "] = '" . strtr($this->_options[$i], $jsEscape) . "';\n"; } $js .= "//]]>\n</script>"; } return $js . parent::toHtml(); }
php
function toHtml() { // prevent problems with grouped elements $arrayName = str_replace(array('[', ']'), array('__', ''), $this->getName()) . '_values'; $this->updateAttributes(array( 'onkeypress' => 'return autocomplete(this, event, ' . $arrayName . ');' )); if ($this->_flagFrozen) { $js = ''; } else { $js = "<script type=\"text/javascript\">\n//<![CDATA[\n"; if (!defined('HTML_QUICKFORM_AUTOCOMPLETE_EXISTS')) { $this->_js .= <<<EOS /* begin javascript for autocomplete */ function setSelectionRange(input, selectionStart, selectionEnd) { if (input.setSelectionRange) { input.setSelectionRange(selectionStart, selectionEnd); } else if (input.createTextRange) { var range = input.createTextRange(); range.collapse(true); range.moveEnd("character", selectionEnd); range.moveStart("character", selectionStart); range.select(); } input.focus(); } function setCaretToPosition(input, position) { setSelectionRange(input, position, position); } function replaceSelection (input, replaceString) { var len = replaceString.length; if (input.setSelectionRange) { var selectionStart = input.selectionStart; var selectionEnd = input.selectionEnd; input.value = input.value.substring(0, selectionStart) + replaceString + input.value.substring(selectionEnd); input.selectionStart = selectionStart + len; input.selectionEnd = selectionStart + len; } else if (document.selection) { var range = document.selection.createRange(); var saved_range = range.duplicate(); if (range.parentElement() == input) { range.text = replaceString; range.moveEnd("character", saved_range.selectionStart + len); range.moveStart("character", saved_range.selectionStart + len); range.select(); } } input.focus(); } function autocompleteMatch (text, values) { for (var i = 0; i < values.length; i++) { if (values[i].toUpperCase().indexOf(text.toUpperCase()) == 0) { return values[i]; } } return null; } function autocomplete(textbox, event, values) { if (textbox.setSelectionRange || textbox.createTextRange) { switch (event.keyCode) { case 38: // up arrow case 40: // down arrow case 37: // left arrow case 39: // right arrow case 33: // page up case 34: // page down case 36: // home case 35: // end case 13: // enter case 9: // tab case 27: // esc case 16: // shift case 17: // ctrl case 18: // alt case 20: // caps lock case 8: // backspace case 46: // delete return true; break; default: var c = String.fromCharCode( (event.charCode == undefined) ? event.keyCode : event.charCode ); replaceSelection(textbox, c); sMatch = autocompleteMatch(textbox.value, values); var len = textbox.value.length; if (sMatch != null) { textbox.value = sMatch; setSelectionRange(textbox, len, textbox.value.length); } return false; } } else { return true; } } /* end javascript for autocomplete */ EOS; define('HTML_QUICKFORM_AUTOCOMPLETE_EXISTS', true); } $jsEscape = array( "\r" => '\r', "\n" => '\n', "\t" => '\t', "'" => "\\'", '"' => '\"', '\\' => '\\\\' ); $js .= $this->_js; $js .= 'var ' . $arrayName . " = new Array();\n"; for ($i = 0; $i < count($this->_options); $i++) { $js .= $arrayName . '[' . $i . "] = '" . strtr($this->_options[$i], $jsEscape) . "';\n"; } $js .= "//]]>\n</script>"; } return $js . parent::toHtml(); }
[ "function", "toHtml", "(", ")", "{", "// prevent problems with grouped elements", "$", "arrayName", "=", "str_replace", "(", "array", "(", "'['", ",", "']'", ")", ",", "array", "(", "'__'", ",", "''", ")", ",", "$", "this", "->", "getName", "(", ")", ")", ".", "'_values'", ";", "$", "this", "->", "updateAttributes", "(", "array", "(", "'onkeypress'", "=>", "'return autocomplete(this, event, '", ".", "$", "arrayName", ".", "');'", ")", ")", ";", "if", "(", "$", "this", "->", "_flagFrozen", ")", "{", "$", "js", "=", "''", ";", "}", "else", "{", "$", "js", "=", "\"<script type=\\\"text/javascript\\\">\\n//<![CDATA[\\n\"", ";", "if", "(", "!", "defined", "(", "'HTML_QUICKFORM_AUTOCOMPLETE_EXISTS'", ")", ")", "{", "$", "this", "->", "_js", ".=", " <<<EOS\n\n/* begin javascript for autocomplete */\nfunction setSelectionRange(input, selectionStart, selectionEnd) {\n if (input.setSelectionRange) {\n input.setSelectionRange(selectionStart, selectionEnd);\n }\n else if (input.createTextRange) {\n var range = input.createTextRange();\n range.collapse(true);\n range.moveEnd(\"character\", selectionEnd);\n range.moveStart(\"character\", selectionStart);\n range.select();\n }\n input.focus();\n}\n\nfunction setCaretToPosition(input, position) {\n setSelectionRange(input, position, position);\n}\n\nfunction replaceSelection (input, replaceString) {\n\tvar len = replaceString.length;\n if (input.setSelectionRange) {\n var selectionStart = input.selectionStart;\n var selectionEnd = input.selectionEnd;\n\n input.value = input.value.substring(0, selectionStart) + replaceString + input.value.substring(selectionEnd);\n\t\tinput.selectionStart = selectionStart + len;\n\t\tinput.selectionEnd = selectionStart + len;\n }\n else if (document.selection) {\n var range = document.selection.createRange();\n\t\tvar saved_range = range.duplicate();\n\n if (range.parentElement() == input) {\n range.text = replaceString;\n\t\t\trange.moveEnd(\"character\", saved_range.selectionStart + len);\n\t\t\trange.moveStart(\"character\", saved_range.selectionStart + len);\n\t\t\trange.select();\n }\n }\n input.focus();\n}\n\n\nfunction autocompleteMatch (text, values) {\n for (var i = 0; i < values.length; i++) {\n if (values[i].toUpperCase().indexOf(text.toUpperCase()) == 0) {\n return values[i];\n }\n }\n\n return null;\n}\n\nfunction autocomplete(textbox, event, values) {\n if (textbox.setSelectionRange || textbox.createTextRange) {\n switch (event.keyCode) {\n case 38: // up arrow\n case 40: // down arrow\n case 37: // left arrow\n case 39: // right arrow\n case 33: // page up\n case 34: // page down\n case 36: // home\n case 35: // end\n case 13: // enter\n case 9: // tab\n case 27: // esc\n case 16: // shift\n case 17: // ctrl\n case 18: // alt\n case 20: // caps lock\n case 8: // backspace\n case 46: // delete\n return true;\n break;\n\n default:\n var c = String.fromCharCode(\n (event.charCode == undefined) ? event.keyCode : event.charCode\n );\n replaceSelection(textbox, c);\n sMatch = autocompleteMatch(textbox.value, values);\n var len = textbox.value.length;\n\t\t\t\t\n if (sMatch != null) {\n textbox.value = sMatch;\n setSelectionRange(textbox, len, textbox.value.length);\n }\n return false;\n }\n }\n else {\n return true;\n }\n}\n/* end javascript for autocomplete */\n\nEOS", ";", "define", "(", "'HTML_QUICKFORM_AUTOCOMPLETE_EXISTS'", ",", "true", ")", ";", "}", "$", "jsEscape", "=", "array", "(", "\"\\r\"", "=>", "'\\r'", ",", "\"\\n\"", "=>", "'\\n'", ",", "\"\\t\"", "=>", "'\\t'", ",", "\"'\"", "=>", "\"\\\\'\"", ",", "'\"'", "=>", "'\\\"'", ",", "'\\\\'", "=>", "'\\\\\\\\'", ")", ";", "$", "js", ".=", "$", "this", "->", "_js", ";", "$", "js", ".=", "'var '", ".", "$", "arrayName", ".", "\" = new Array();\\n\"", ";", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "count", "(", "$", "this", "->", "_options", ")", ";", "$", "i", "++", ")", "{", "$", "js", ".=", "$", "arrayName", ".", "'['", ".", "$", "i", ".", "\"] = '\"", ".", "strtr", "(", "$", "this", "->", "_options", "[", "$", "i", "]", ",", "$", "jsEscape", ")", ".", "\"';\\n\"", ";", "}", "$", "js", ".=", "\"//]]>\\n</script>\"", ";", "}", "return", "$", "js", ".", "parent", "::", "toHtml", "(", ")", ";", "}" ]
Returns Html for the autocomplete input text element @access public @return string
[ "Returns", "Html", "for", "the", "autocomplete", "input", "text", "element" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/pear/HTML/QuickForm/autocomplete.php#L121-L254
216,928
moodle/moodle
grade/grading/classes/privacy/gradingform_legacy_polyfill.php
gradingform_legacy_polyfill.get_gradingform_export_data
public static function get_gradingform_export_data(\context $context, $definition, int $userid) { debugging('This method is deprecated. Please use the gradingform_provider_v2 interface', DEBUG_DEVELOPER); return static::_get_gradingform_export_data($context, $definition, $userid); }
php
public static function get_gradingform_export_data(\context $context, $definition, int $userid) { debugging('This method is deprecated. Please use the gradingform_provider_v2 interface', DEBUG_DEVELOPER); return static::_get_gradingform_export_data($context, $definition, $userid); }
[ "public", "static", "function", "get_gradingform_export_data", "(", "\\", "context", "$", "context", ",", "$", "definition", ",", "int", "$", "userid", ")", "{", "debugging", "(", "'This method is deprecated. Please use the gradingform_provider_v2 interface'", ",", "DEBUG_DEVELOPER", ")", ";", "return", "static", "::", "_get_gradingform_export_data", "(", "$", "context", ",", "$", "definition", ",", "$", "userid", ")", ";", "}" ]
This method is used to export any user data this sub-plugin has using the object to get the context and userid. @deprecated Since Moodle 3.6 MDL-62535 Please use the methods in the gradingform_provider_v2 interface. @todo MDL-63167 remove this method. @param context $context Context owner of the data. @param stdClass $definition Grading definition entry to export. @param int $userid The user whose information is to be exported. @return stdClass The data to export.
[ "This", "method", "is", "used", "to", "export", "any", "user", "data", "this", "sub", "-", "plugin", "has", "using", "the", "object", "to", "get", "the", "context", "and", "userid", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/grade/grading/classes/privacy/gradingform_legacy_polyfill.php#L69-L72
216,929
moodle/moodle
mod/assign/submission/file/backup/moodle2/restore_assignsubmission_file_subplugin.class.php
restore_assignsubmission_file_subplugin.process_assignsubmission_file_submission
public function process_assignsubmission_file_submission($data) { global $DB; $data = (object)$data; $data->assignment = $this->get_new_parentid('assign'); $oldsubmissionid = $data->submission; // The mapping is set in the restore for the core assign activity // when a submission node is processed. $data->submission = $this->get_mappingid('submission', $data->submission); $DB->insert_record('assignsubmission_file', $data); $this->add_related_files('assignsubmission_file', 'submission_files', 'submission', null, $oldsubmissionid); }
php
public function process_assignsubmission_file_submission($data) { global $DB; $data = (object)$data; $data->assignment = $this->get_new_parentid('assign'); $oldsubmissionid = $data->submission; // The mapping is set in the restore for the core assign activity // when a submission node is processed. $data->submission = $this->get_mappingid('submission', $data->submission); $DB->insert_record('assignsubmission_file', $data); $this->add_related_files('assignsubmission_file', 'submission_files', 'submission', null, $oldsubmissionid); }
[ "public", "function", "process_assignsubmission_file_submission", "(", "$", "data", ")", "{", "global", "$", "DB", ";", "$", "data", "=", "(", "object", ")", "$", "data", ";", "$", "data", "->", "assignment", "=", "$", "this", "->", "get_new_parentid", "(", "'assign'", ")", ";", "$", "oldsubmissionid", "=", "$", "data", "->", "submission", ";", "// The mapping is set in the restore for the core assign activity", "// when a submission node is processed.", "$", "data", "->", "submission", "=", "$", "this", "->", "get_mappingid", "(", "'submission'", ",", "$", "data", "->", "submission", ")", ";", "$", "DB", "->", "insert_record", "(", "'assignsubmission_file'", ",", "$", "data", ")", ";", "$", "this", "->", "add_related_files", "(", "'assignsubmission_file'", ",", "'submission_files'", ",", "'submission'", ",", "null", ",", "$", "oldsubmissionid", ")", ";", "}" ]
Processes one submission_file element @param mixed $data @return void
[ "Processes", "one", "submission_file", "element" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/assign/submission/file/backup/moodle2/restore_assignsubmission_file_subplugin.class.php#L58-L75
216,930
moodle/moodle
admin/tool/task/classes/run_from_cli.php
run_from_cli.find_php_cli_path
protected static function find_php_cli_path() { global $CFG; if (!empty($CFG->pathtophp) && is_executable(trim($CFG->pathtophp))) { return $CFG->pathtophp; } return false; }
php
protected static function find_php_cli_path() { global $CFG; if (!empty($CFG->pathtophp) && is_executable(trim($CFG->pathtophp))) { return $CFG->pathtophp; } return false; }
[ "protected", "static", "function", "find_php_cli_path", "(", ")", "{", "global", "$", "CFG", ";", "if", "(", "!", "empty", "(", "$", "CFG", "->", "pathtophp", ")", "&&", "is_executable", "(", "trim", "(", "$", "CFG", "->", "pathtophp", ")", ")", ")", "{", "return", "$", "CFG", "->", "pathtophp", ";", "}", "return", "false", ";", "}" ]
Find the path of PHP CLI binary. @return string|false The PHP CLI executable PATH
[ "Find", "the", "path", "of", "PHP", "CLI", "binary", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/task/classes/run_from_cli.php#L42-L50
216,931
moodle/moodle
admin/tool/task/classes/run_from_cli.php
run_from_cli.execute
public static function execute(\core\task\task_base $task):bool { global $CFG; if (!self::is_runnable()) { $redirecturl = new \moodle_url('/admin/settings.php', ['section' => 'systempaths']); throw new \moodle_exception('cannotfindthepathtothecli', 'tool_task', $redirecturl->out()); } else { // Shell-escaped path to the PHP binary. $phpbinary = escapeshellarg(self::find_php_cli_path()); // Shell-escaped path CLI script. $pathcomponents = [$CFG->dirroot, $CFG->admin, 'tool', 'task', 'cli', 'schedule_task.php']; $scriptpath = escapeshellarg(implode(DIRECTORY_SEPARATOR, $pathcomponents)); // Shell-escaped task name. $classname = get_class($task); $taskarg = escapeshellarg("--execute={$classname}"); // Build the CLI command. $command = "{$phpbinary} {$scriptpath} {$taskarg}"; // Execute it. passthru($command); } return true; }
php
public static function execute(\core\task\task_base $task):bool { global $CFG; if (!self::is_runnable()) { $redirecturl = new \moodle_url('/admin/settings.php', ['section' => 'systempaths']); throw new \moodle_exception('cannotfindthepathtothecli', 'tool_task', $redirecturl->out()); } else { // Shell-escaped path to the PHP binary. $phpbinary = escapeshellarg(self::find_php_cli_path()); // Shell-escaped path CLI script. $pathcomponents = [$CFG->dirroot, $CFG->admin, 'tool', 'task', 'cli', 'schedule_task.php']; $scriptpath = escapeshellarg(implode(DIRECTORY_SEPARATOR, $pathcomponents)); // Shell-escaped task name. $classname = get_class($task); $taskarg = escapeshellarg("--execute={$classname}"); // Build the CLI command. $command = "{$phpbinary} {$scriptpath} {$taskarg}"; // Execute it. passthru($command); } return true; }
[ "public", "static", "function", "execute", "(", "\\", "core", "\\", "task", "\\", "task_base", "$", "task", ")", ":", "bool", "{", "global", "$", "CFG", ";", "if", "(", "!", "self", "::", "is_runnable", "(", ")", ")", "{", "$", "redirecturl", "=", "new", "\\", "moodle_url", "(", "'/admin/settings.php'", ",", "[", "'section'", "=>", "'systempaths'", "]", ")", ";", "throw", "new", "\\", "moodle_exception", "(", "'cannotfindthepathtothecli'", ",", "'tool_task'", ",", "$", "redirecturl", "->", "out", "(", ")", ")", ";", "}", "else", "{", "// Shell-escaped path to the PHP binary.", "$", "phpbinary", "=", "escapeshellarg", "(", "self", "::", "find_php_cli_path", "(", ")", ")", ";", "// Shell-escaped path CLI script.", "$", "pathcomponents", "=", "[", "$", "CFG", "->", "dirroot", ",", "$", "CFG", "->", "admin", ",", "'tool'", ",", "'task'", ",", "'cli'", ",", "'schedule_task.php'", "]", ";", "$", "scriptpath", "=", "escapeshellarg", "(", "implode", "(", "DIRECTORY_SEPARATOR", ",", "$", "pathcomponents", ")", ")", ";", "// Shell-escaped task name.", "$", "classname", "=", "get_class", "(", "$", "task", ")", ";", "$", "taskarg", "=", "escapeshellarg", "(", "\"--execute={$classname}\"", ")", ";", "// Build the CLI command.", "$", "command", "=", "\"{$phpbinary} {$scriptpath} {$taskarg}\"", ";", "// Execute it.", "passthru", "(", "$", "command", ")", ";", "}", "return", "true", ";", "}" ]
Executes a cron from web invocation using PHP CLI. @param \core\task\task_base $task Task that be executed via CLI. @return bool @throws \moodle_exception
[ "Executes", "a", "cron", "from", "web", "invocation", "using", "PHP", "CLI", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/task/classes/run_from_cli.php#L68-L94
216,932
moodle/moodle
lib/phpexcel/PHPExcel/Shared/ZipArchive.php
PHPExcel_Shared_ZipArchive.addFromString
public function addFromString($localname, $contents) { $filenameParts = pathinfo($localname); $handle = fopen($this->tempDir.'/'.$filenameParts["basename"], "wb"); fwrite($handle, $contents); fclose($handle); $res = $this->zip->add($this->tempDir.'/'.$filenameParts["basename"], PCLZIP_OPT_REMOVE_PATH, $this->tempDir, PCLZIP_OPT_ADD_PATH, $filenameParts["dirname"]); if ($res == 0) { throw new PHPExcel_Writer_Exception("Error zipping files : " . $this->zip->errorInfo(true)); } unlink($this->tempDir.'/'.$filenameParts["basename"]); }
php
public function addFromString($localname, $contents) { $filenameParts = pathinfo($localname); $handle = fopen($this->tempDir.'/'.$filenameParts["basename"], "wb"); fwrite($handle, $contents); fclose($handle); $res = $this->zip->add($this->tempDir.'/'.$filenameParts["basename"], PCLZIP_OPT_REMOVE_PATH, $this->tempDir, PCLZIP_OPT_ADD_PATH, $filenameParts["dirname"]); if ($res == 0) { throw new PHPExcel_Writer_Exception("Error zipping files : " . $this->zip->errorInfo(true)); } unlink($this->tempDir.'/'.$filenameParts["basename"]); }
[ "public", "function", "addFromString", "(", "$", "localname", ",", "$", "contents", ")", "{", "$", "filenameParts", "=", "pathinfo", "(", "$", "localname", ")", ";", "$", "handle", "=", "fopen", "(", "$", "this", "->", "tempDir", ".", "'/'", ".", "$", "filenameParts", "[", "\"basename\"", "]", ",", "\"wb\"", ")", ";", "fwrite", "(", "$", "handle", ",", "$", "contents", ")", ";", "fclose", "(", "$", "handle", ")", ";", "$", "res", "=", "$", "this", "->", "zip", "->", "add", "(", "$", "this", "->", "tempDir", ".", "'/'", ".", "$", "filenameParts", "[", "\"basename\"", "]", ",", "PCLZIP_OPT_REMOVE_PATH", ",", "$", "this", "->", "tempDir", ",", "PCLZIP_OPT_ADD_PATH", ",", "$", "filenameParts", "[", "\"dirname\"", "]", ")", ";", "if", "(", "$", "res", "==", "0", ")", "{", "throw", "new", "PHPExcel_Writer_Exception", "(", "\"Error zipping files : \"", ".", "$", "this", "->", "zip", "->", "errorInfo", "(", "true", ")", ")", ";", "}", "unlink", "(", "$", "this", "->", "tempDir", ".", "'/'", ".", "$", "filenameParts", "[", "\"basename\"", "]", ")", ";", "}" ]
Add a new file to the zip archive from a string of raw data. @param string $localname Directory/Name of the file to add to the zip archive @param string $contents String of data to add to the zip archive
[ "Add", "a", "new", "file", "to", "the", "zip", "archive", "from", "a", "string", "of", "raw", "data", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Shared/ZipArchive.php#L86-L100
216,933
moodle/moodle
lib/filestorage/zip_archive.php
zip_archive.close
public function close() { if (!isset($this->za)) { return false; } if ($this->emptyziphack) { @$this->za->close(); $this->za = null; $this->mode = null; $this->namelookup = null; $this->modified = false; @unlink($this->emptyziphack); $this->emptyziphack = false; return true; } else if ($this->za->numFiles == 0) { // PHP can not create empty archives, so let's fake it. @$this->za->close(); $this->za = null; $this->mode = null; $this->namelookup = null; $this->modified = false; // If the existing archive is already empty, we didn't change it. Don't bother completing a save. // This is important when we are inspecting archives that we might not have write permission to. if (@filesize($this->archivepathname) == 22 && @file_get_contents($this->archivepathname) === base64_decode(self::$emptyzipcontent)) { return true; } @unlink($this->archivepathname); $data = base64_decode(self::$emptyzipcontent); if (!file_put_contents($this->archivepathname, $data)) { return false; } return true; } $res = $this->za->close(); $this->za = null; $this->mode = null; $this->namelookup = null; if ($this->modified) { $this->fix_utf8_flags(); $this->modified = false; } return $res; }
php
public function close() { if (!isset($this->za)) { return false; } if ($this->emptyziphack) { @$this->za->close(); $this->za = null; $this->mode = null; $this->namelookup = null; $this->modified = false; @unlink($this->emptyziphack); $this->emptyziphack = false; return true; } else if ($this->za->numFiles == 0) { // PHP can not create empty archives, so let's fake it. @$this->za->close(); $this->za = null; $this->mode = null; $this->namelookup = null; $this->modified = false; // If the existing archive is already empty, we didn't change it. Don't bother completing a save. // This is important when we are inspecting archives that we might not have write permission to. if (@filesize($this->archivepathname) == 22 && @file_get_contents($this->archivepathname) === base64_decode(self::$emptyzipcontent)) { return true; } @unlink($this->archivepathname); $data = base64_decode(self::$emptyzipcontent); if (!file_put_contents($this->archivepathname, $data)) { return false; } return true; } $res = $this->za->close(); $this->za = null; $this->mode = null; $this->namelookup = null; if ($this->modified) { $this->fix_utf8_flags(); $this->modified = false; } return $res; }
[ "public", "function", "close", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "za", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "this", "->", "emptyziphack", ")", "{", "@", "$", "this", "->", "za", "->", "close", "(", ")", ";", "$", "this", "->", "za", "=", "null", ";", "$", "this", "->", "mode", "=", "null", ";", "$", "this", "->", "namelookup", "=", "null", ";", "$", "this", "->", "modified", "=", "false", ";", "@", "unlink", "(", "$", "this", "->", "emptyziphack", ")", ";", "$", "this", "->", "emptyziphack", "=", "false", ";", "return", "true", ";", "}", "else", "if", "(", "$", "this", "->", "za", "->", "numFiles", "==", "0", ")", "{", "// PHP can not create empty archives, so let's fake it.", "@", "$", "this", "->", "za", "->", "close", "(", ")", ";", "$", "this", "->", "za", "=", "null", ";", "$", "this", "->", "mode", "=", "null", ";", "$", "this", "->", "namelookup", "=", "null", ";", "$", "this", "->", "modified", "=", "false", ";", "// If the existing archive is already empty, we didn't change it. Don't bother completing a save.", "// This is important when we are inspecting archives that we might not have write permission to.", "if", "(", "@", "filesize", "(", "$", "this", "->", "archivepathname", ")", "==", "22", "&&", "@", "file_get_contents", "(", "$", "this", "->", "archivepathname", ")", "===", "base64_decode", "(", "self", "::", "$", "emptyzipcontent", ")", ")", "{", "return", "true", ";", "}", "@", "unlink", "(", "$", "this", "->", "archivepathname", ")", ";", "$", "data", "=", "base64_decode", "(", "self", "::", "$", "emptyzipcontent", ")", ";", "if", "(", "!", "file_put_contents", "(", "$", "this", "->", "archivepathname", ",", "$", "data", ")", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}", "$", "res", "=", "$", "this", "->", "za", "->", "close", "(", ")", ";", "$", "this", "->", "za", "=", "null", ";", "$", "this", "->", "mode", "=", "null", ";", "$", "this", "->", "namelookup", "=", "null", ";", "if", "(", "$", "this", "->", "modified", ")", "{", "$", "this", "->", "fix_utf8_flags", "(", ")", ";", "$", "this", "->", "modified", "=", "false", ";", "}", "return", "$", "res", ";", "}" ]
Close archive, write changes to disk. @return bool success
[ "Close", "archive", "write", "changes", "to", "disk", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/zip_archive.php#L188-L235
216,934
moodle/moodle
lib/filestorage/zip_archive.php
zip_archive.get_stream
public function get_stream($index) { if (!isset($this->za)) { return false; } $name = $this->za->getNameIndex($index); if ($name === false) { return false; } return $this->za->getStream($name); }
php
public function get_stream($index) { if (!isset($this->za)) { return false; } $name = $this->za->getNameIndex($index); if ($name === false) { return false; } return $this->za->getStream($name); }
[ "public", "function", "get_stream", "(", "$", "index", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "za", ")", ")", "{", "return", "false", ";", "}", "$", "name", "=", "$", "this", "->", "za", "->", "getNameIndex", "(", "$", "index", ")", ";", "if", "(", "$", "name", "===", "false", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "za", "->", "getStream", "(", "$", "name", ")", ";", "}" ]
Returns file stream for reading of content. @param int $index index of file @return resource|bool file handle or false if error
[ "Returns", "file", "stream", "for", "reading", "of", "content", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/zip_archive.php#L243-L254
216,935
moodle/moodle
lib/filestorage/zip_archive.php
zip_archive.get_info
public function get_info($index) { if (!isset($this->za)) { return false; } // Need to use the ZipArchive's numfiles, as $this->count() relies on this function to count actual files (skipping OSX junk). if ($index < 0 or $index >=$this->za->numFiles) { return false; } // PHP 5.6 introduced encoding guessing logic, we need to fall back // to raw ZIP_FL_ENC_RAW (== 64) to get consistent results as in PHP 5.5. $result = $this->za->statIndex($index, 64); if ($result === false) { return false; } $info = new stdClass(); $info->index = $index; $info->original_pathname = $result['name']; $info->pathname = $this->unmangle_pathname($result['name']); $info->mtime = (int)$result['mtime']; if ($info->pathname[strlen($info->pathname)-1] === '/') { $info->is_directory = true; $info->size = 0; } else { $info->is_directory = false; $info->size = (int)$result['size']; } if ($this->is_system_file($info)) { // Don't return system files. return false; } return $info; }
php
public function get_info($index) { if (!isset($this->za)) { return false; } // Need to use the ZipArchive's numfiles, as $this->count() relies on this function to count actual files (skipping OSX junk). if ($index < 0 or $index >=$this->za->numFiles) { return false; } // PHP 5.6 introduced encoding guessing logic, we need to fall back // to raw ZIP_FL_ENC_RAW (== 64) to get consistent results as in PHP 5.5. $result = $this->za->statIndex($index, 64); if ($result === false) { return false; } $info = new stdClass(); $info->index = $index; $info->original_pathname = $result['name']; $info->pathname = $this->unmangle_pathname($result['name']); $info->mtime = (int)$result['mtime']; if ($info->pathname[strlen($info->pathname)-1] === '/') { $info->is_directory = true; $info->size = 0; } else { $info->is_directory = false; $info->size = (int)$result['size']; } if ($this->is_system_file($info)) { // Don't return system files. return false; } return $info; }
[ "public", "function", "get_info", "(", "$", "index", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "za", ")", ")", "{", "return", "false", ";", "}", "// Need to use the ZipArchive's numfiles, as $this->count() relies on this function to count actual files (skipping OSX junk).", "if", "(", "$", "index", "<", "0", "or", "$", "index", ">=", "$", "this", "->", "za", "->", "numFiles", ")", "{", "return", "false", ";", "}", "// PHP 5.6 introduced encoding guessing logic, we need to fall back", "// to raw ZIP_FL_ENC_RAW (== 64) to get consistent results as in PHP 5.5.", "$", "result", "=", "$", "this", "->", "za", "->", "statIndex", "(", "$", "index", ",", "64", ")", ";", "if", "(", "$", "result", "===", "false", ")", "{", "return", "false", ";", "}", "$", "info", "=", "new", "stdClass", "(", ")", ";", "$", "info", "->", "index", "=", "$", "index", ";", "$", "info", "->", "original_pathname", "=", "$", "result", "[", "'name'", "]", ";", "$", "info", "->", "pathname", "=", "$", "this", "->", "unmangle_pathname", "(", "$", "result", "[", "'name'", "]", ")", ";", "$", "info", "->", "mtime", "=", "(", "int", ")", "$", "result", "[", "'mtime'", "]", ";", "if", "(", "$", "info", "->", "pathname", "[", "strlen", "(", "$", "info", "->", "pathname", ")", "-", "1", "]", "===", "'/'", ")", "{", "$", "info", "->", "is_directory", "=", "true", ";", "$", "info", "->", "size", "=", "0", ";", "}", "else", "{", "$", "info", "->", "is_directory", "=", "false", ";", "$", "info", "->", "size", "=", "(", "int", ")", "$", "result", "[", "'size'", "]", ";", "}", "if", "(", "$", "this", "->", "is_system_file", "(", "$", "info", ")", ")", "{", "// Don't return system files.", "return", "false", ";", "}", "return", "$", "info", ";", "}" ]
Returns file information. @param int $index index of file @return stdClass|bool info object or false if error
[ "Returns", "file", "information", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/zip_archive.php#L262-L300
216,936
moodle/moodle
lib/filestorage/zip_archive.php
zip_archive.add_file_from_pathname
public function add_file_from_pathname($localname, $pathname) { if ($this->emptyziphack) { $this->close(); $this->open($this->archivepathname, file_archive::OVERWRITE, $this->encoding); } if (!isset($this->za)) { return false; } if ($this->archivepathname === realpath($pathname)) { // Do not add self into archive. return false; } if (!is_readable($pathname) or is_dir($pathname)) { return false; } if (is_null($localname)) { $localname = clean_param($pathname, PARAM_PATH); } $localname = trim($localname, '/'); // No leading slashes in archives! $localname = $this->mangle_pathname($localname); if ($localname === '') { // Sorry - conversion failed badly. return false; } if (!$this->za->addFile($pathname, $localname)) { return false; } $this->modified = true; return true; }
php
public function add_file_from_pathname($localname, $pathname) { if ($this->emptyziphack) { $this->close(); $this->open($this->archivepathname, file_archive::OVERWRITE, $this->encoding); } if (!isset($this->za)) { return false; } if ($this->archivepathname === realpath($pathname)) { // Do not add self into archive. return false; } if (!is_readable($pathname) or is_dir($pathname)) { return false; } if (is_null($localname)) { $localname = clean_param($pathname, PARAM_PATH); } $localname = trim($localname, '/'); // No leading slashes in archives! $localname = $this->mangle_pathname($localname); if ($localname === '') { // Sorry - conversion failed badly. return false; } if (!$this->za->addFile($pathname, $localname)) { return false; } $this->modified = true; return true; }
[ "public", "function", "add_file_from_pathname", "(", "$", "localname", ",", "$", "pathname", ")", "{", "if", "(", "$", "this", "->", "emptyziphack", ")", "{", "$", "this", "->", "close", "(", ")", ";", "$", "this", "->", "open", "(", "$", "this", "->", "archivepathname", ",", "file_archive", "::", "OVERWRITE", ",", "$", "this", "->", "encoding", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "za", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "this", "->", "archivepathname", "===", "realpath", "(", "$", "pathname", ")", ")", "{", "// Do not add self into archive.", "return", "false", ";", "}", "if", "(", "!", "is_readable", "(", "$", "pathname", ")", "or", "is_dir", "(", "$", "pathname", ")", ")", "{", "return", "false", ";", "}", "if", "(", "is_null", "(", "$", "localname", ")", ")", "{", "$", "localname", "=", "clean_param", "(", "$", "pathname", ",", "PARAM_PATH", ")", ";", "}", "$", "localname", "=", "trim", "(", "$", "localname", ",", "'/'", ")", ";", "// No leading slashes in archives!", "$", "localname", "=", "$", "this", "->", "mangle_pathname", "(", "$", "localname", ")", ";", "if", "(", "$", "localname", "===", "''", ")", "{", "// Sorry - conversion failed badly.", "return", "false", ";", "}", "if", "(", "!", "$", "this", "->", "za", "->", "addFile", "(", "$", "pathname", ",", "$", "localname", ")", ")", "{", "return", "false", ";", "}", "$", "this", "->", "modified", "=", "true", ";", "return", "true", ";", "}" ]
Add file into archive. @param string $localname name of file in archive @param string $pathname location of file @return bool success
[ "Add", "file", "into", "archive", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/zip_archive.php#L373-L408
216,937
moodle/moodle
lib/filestorage/zip_archive.php
zip_archive.add_file_from_string
public function add_file_from_string($localname, $contents) { if ($this->emptyziphack) { $this->close(); $this->open($this->archivepathname, file_archive::OVERWRITE, $this->encoding); } if (!isset($this->za)) { return false; } $localname = trim($localname, '/'); // No leading slashes in archives! $localname = $this->mangle_pathname($localname); if ($localname === '') { // Sorry - conversion failed badly. return false; } if ($this->usedmem > 2097151) { // This prevents running out of memory when adding many large files using strings. $this->close(); $res = $this->open($this->archivepathname, file_archive::OPEN, $this->encoding); if ($res !== true) { print_error('cannotopenzip'); } } $this->usedmem += strlen($contents); if (!$this->za->addFromString($localname, $contents)) { return false; } $this->modified = true; return true; }
php
public function add_file_from_string($localname, $contents) { if ($this->emptyziphack) { $this->close(); $this->open($this->archivepathname, file_archive::OVERWRITE, $this->encoding); } if (!isset($this->za)) { return false; } $localname = trim($localname, '/'); // No leading slashes in archives! $localname = $this->mangle_pathname($localname); if ($localname === '') { // Sorry - conversion failed badly. return false; } if ($this->usedmem > 2097151) { // This prevents running out of memory when adding many large files using strings. $this->close(); $res = $this->open($this->archivepathname, file_archive::OPEN, $this->encoding); if ($res !== true) { print_error('cannotopenzip'); } } $this->usedmem += strlen($contents); if (!$this->za->addFromString($localname, $contents)) { return false; } $this->modified = true; return true; }
[ "public", "function", "add_file_from_string", "(", "$", "localname", ",", "$", "contents", ")", "{", "if", "(", "$", "this", "->", "emptyziphack", ")", "{", "$", "this", "->", "close", "(", ")", ";", "$", "this", "->", "open", "(", "$", "this", "->", "archivepathname", ",", "file_archive", "::", "OVERWRITE", ",", "$", "this", "->", "encoding", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "za", ")", ")", "{", "return", "false", ";", "}", "$", "localname", "=", "trim", "(", "$", "localname", ",", "'/'", ")", ";", "// No leading slashes in archives!", "$", "localname", "=", "$", "this", "->", "mangle_pathname", "(", "$", "localname", ")", ";", "if", "(", "$", "localname", "===", "''", ")", "{", "// Sorry - conversion failed badly.", "return", "false", ";", "}", "if", "(", "$", "this", "->", "usedmem", ">", "2097151", ")", "{", "// This prevents running out of memory when adding many large files using strings.", "$", "this", "->", "close", "(", ")", ";", "$", "res", "=", "$", "this", "->", "open", "(", "$", "this", "->", "archivepathname", ",", "file_archive", "::", "OPEN", ",", "$", "this", "->", "encoding", ")", ";", "if", "(", "$", "res", "!==", "true", ")", "{", "print_error", "(", "'cannotopenzip'", ")", ";", "}", "}", "$", "this", "->", "usedmem", "+=", "strlen", "(", "$", "contents", ")", ";", "if", "(", "!", "$", "this", "->", "za", "->", "addFromString", "(", "$", "localname", ",", "$", "contents", ")", ")", "{", "return", "false", ";", "}", "$", "this", "->", "modified", "=", "true", ";", "return", "true", ";", "}" ]
Add content of string into archive. @param string $localname name of file in archive @param string $contents contents @return bool success
[ "Add", "content", "of", "string", "into", "archive", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/zip_archive.php#L417-L450
216,938
moodle/moodle
lib/filestorage/zip_archive.php
zip_archive.add_directory
public function add_directory($localname) { if ($this->emptyziphack) { $this->close(); $this->open($this->archivepathname, file_archive::OVERWRITE, $this->encoding); } if (!isset($this->za)) { return false; } $localname = trim($localname, '/'). '/'; $localname = $this->mangle_pathname($localname); if ($localname === '/') { // Sorry - conversion failed badly. return false; } if ($localname !== '') { if (!$this->za->addEmptyDir($localname)) { return false; } $this->modified = true; } return true; }
php
public function add_directory($localname) { if ($this->emptyziphack) { $this->close(); $this->open($this->archivepathname, file_archive::OVERWRITE, $this->encoding); } if (!isset($this->za)) { return false; } $localname = trim($localname, '/'). '/'; $localname = $this->mangle_pathname($localname); if ($localname === '/') { // Sorry - conversion failed badly. return false; } if ($localname !== '') { if (!$this->za->addEmptyDir($localname)) { return false; } $this->modified = true; } return true; }
[ "public", "function", "add_directory", "(", "$", "localname", ")", "{", "if", "(", "$", "this", "->", "emptyziphack", ")", "{", "$", "this", "->", "close", "(", ")", ";", "$", "this", "->", "open", "(", "$", "this", "->", "archivepathname", ",", "file_archive", "::", "OVERWRITE", ",", "$", "this", "->", "encoding", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "za", ")", ")", "{", "return", "false", ";", "}", "$", "localname", "=", "trim", "(", "$", "localname", ",", "'/'", ")", ".", "'/'", ";", "$", "localname", "=", "$", "this", "->", "mangle_pathname", "(", "$", "localname", ")", ";", "if", "(", "$", "localname", "===", "'/'", ")", "{", "// Sorry - conversion failed badly.", "return", "false", ";", "}", "if", "(", "$", "localname", "!==", "''", ")", "{", "if", "(", "!", "$", "this", "->", "za", "->", "addEmptyDir", "(", "$", "localname", ")", ")", "{", "return", "false", ";", "}", "$", "this", "->", "modified", "=", "true", ";", "}", "return", "true", ";", "}" ]
Add empty directory into archive. @param string $localname name of file in archive @return bool success
[ "Add", "empty", "directory", "into", "archive", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/zip_archive.php#L458-L482
216,939
moodle/moodle
lib/filestorage/zip_archive.php
zip_archive.valid
public function valid() { if (!isset($this->za)) { return false; } // Skip over unwanted system files (get_info will return false). while (!$this->get_info($this->pos) && $this->pos < $this->za->numFiles) { $this->next(); } // No files left - we're at the end. if ($this->pos >= $this->za->numFiles) { return false; } return true; }
php
public function valid() { if (!isset($this->za)) { return false; } // Skip over unwanted system files (get_info will return false). while (!$this->get_info($this->pos) && $this->pos < $this->za->numFiles) { $this->next(); } // No files left - we're at the end. if ($this->pos >= $this->za->numFiles) { return false; } return true; }
[ "public", "function", "valid", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "za", ")", ")", "{", "return", "false", ";", "}", "// Skip over unwanted system files (get_info will return false).", "while", "(", "!", "$", "this", "->", "get_info", "(", "$", "this", "->", "pos", ")", "&&", "$", "this", "->", "pos", "<", "$", "this", "->", "za", "->", "numFiles", ")", "{", "$", "this", "->", "next", "(", ")", ";", "}", "// No files left - we're at the end.", "if", "(", "$", "this", "->", "pos", ">=", "$", "this", "->", "za", "->", "numFiles", ")", "{", "return", "false", ";", "}", "return", "true", ";", "}" ]
Did we reach the end? @return bool
[ "Did", "we", "reach", "the", "end?" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/zip_archive.php#L525-L541
216,940
moodle/moodle
lib/filestorage/zip_archive.php
zip_archive.zip_get_central_end
public static function zip_get_central_end($fp, $filesize) { // Find end of central directory record. fseek($fp, $filesize - 22); $info = unpack('Vsig', fread($fp, 4)); if ($info['sig'] === 0x06054b50) { // There is no comment. fseek($fp, $filesize - 22); $data = fread($fp, 22); } else { // There is some comment with 0xFF max size - that is 65557. fseek($fp, $filesize - 65557); $data = fread($fp, 65557); } $pos = strpos($data, pack('V', 0x06054b50)); if ($pos === false) { // Borked ZIP structure! return false; } $centralend = unpack('Vsig/vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_length', substr($data, $pos, 22)); if ($centralend['comment_length']) { $centralend['comment'] = substr($data, 22, $centralend['comment_length']); } else { $centralend['comment'] = ''; } return $centralend; }
php
public static function zip_get_central_end($fp, $filesize) { // Find end of central directory record. fseek($fp, $filesize - 22); $info = unpack('Vsig', fread($fp, 4)); if ($info['sig'] === 0x06054b50) { // There is no comment. fseek($fp, $filesize - 22); $data = fread($fp, 22); } else { // There is some comment with 0xFF max size - that is 65557. fseek($fp, $filesize - 65557); $data = fread($fp, 65557); } $pos = strpos($data, pack('V', 0x06054b50)); if ($pos === false) { // Borked ZIP structure! return false; } $centralend = unpack('Vsig/vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_length', substr($data, $pos, 22)); if ($centralend['comment_length']) { $centralend['comment'] = substr($data, 22, $centralend['comment_length']); } else { $centralend['comment'] = ''; } return $centralend; }
[ "public", "static", "function", "zip_get_central_end", "(", "$", "fp", ",", "$", "filesize", ")", "{", "// Find end of central directory record.", "fseek", "(", "$", "fp", ",", "$", "filesize", "-", "22", ")", ";", "$", "info", "=", "unpack", "(", "'Vsig'", ",", "fread", "(", "$", "fp", ",", "4", ")", ")", ";", "if", "(", "$", "info", "[", "'sig'", "]", "===", "0x06054b50", ")", "{", "// There is no comment.", "fseek", "(", "$", "fp", ",", "$", "filesize", "-", "22", ")", ";", "$", "data", "=", "fread", "(", "$", "fp", ",", "22", ")", ";", "}", "else", "{", "// There is some comment with 0xFF max size - that is 65557.", "fseek", "(", "$", "fp", ",", "$", "filesize", "-", "65557", ")", ";", "$", "data", "=", "fread", "(", "$", "fp", ",", "65557", ")", ";", "}", "$", "pos", "=", "strpos", "(", "$", "data", ",", "pack", "(", "'V'", ",", "0x06054b50", ")", ")", ";", "if", "(", "$", "pos", "===", "false", ")", "{", "// Borked ZIP structure!", "return", "false", ";", "}", "$", "centralend", "=", "unpack", "(", "'Vsig/vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_length'", ",", "substr", "(", "$", "data", ",", "$", "pos", ",", "22", ")", ")", ";", "if", "(", "$", "centralend", "[", "'comment_length'", "]", ")", "{", "$", "centralend", "[", "'comment'", "]", "=", "substr", "(", "$", "data", ",", "22", ",", "$", "centralend", "[", "'comment_length'", "]", ")", ";", "}", "else", "{", "$", "centralend", "[", "'comment'", "]", "=", "''", ";", "}", "return", "$", "centralend", ";", "}" ]
Read end of central signature of ZIP file. @internal @static @param resource $fp @param int $filesize @return array|bool
[ "Read", "end", "of", "central", "signature", "of", "ZIP", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/zip_archive.php#L800-L827
216,941
moodle/moodle
lib/filestorage/zip_archive.php
zip_archive.zip_parse_file_header
public static function zip_parse_file_header($data, $centralend, &$pos) { $file = unpack('Vsig/vversion/vversion_req/vgeneral/vmethod/Vmodified/Vcrc/Vsize_compressed/Vsize/vname_length/vextra_length/vcomment_length/vdisk/vattr/Vattrext/Vlocal_offset', substr($data, $pos, 46)); $file['central_offset'] = $centralend['offset'] + $pos; $pos = $pos + 46; if ($file['sig'] !== 0x02014b50) { // Borked ZIP structure! return false; } $file['name'] = substr($data, $pos, $file['name_length']); $pos = $pos + $file['name_length']; $file['extra'] = array(); $file['extra_data'] = ''; if ($file['extra_length']) { $extradata = substr($data, $pos, $file['extra_length']); $file['extra_data'] = $extradata; while (strlen($extradata) > 4) { $extra = unpack('vid/vsize', substr($extradata, 0, 4)); $extra['data'] = substr($extradata, 4, $extra['size']); $extradata = substr($extradata, 4+$extra['size']); $file['extra'][] = $extra; } $pos = $pos + $file['extra_length']; } if ($file['comment_length']) { $pos = $pos + $file['comment_length']; $file['comment'] = substr($data, $pos, $file['comment_length']); } else { $file['comment'] = ''; } return $file; }
php
public static function zip_parse_file_header($data, $centralend, &$pos) { $file = unpack('Vsig/vversion/vversion_req/vgeneral/vmethod/Vmodified/Vcrc/Vsize_compressed/Vsize/vname_length/vextra_length/vcomment_length/vdisk/vattr/Vattrext/Vlocal_offset', substr($data, $pos, 46)); $file['central_offset'] = $centralend['offset'] + $pos; $pos = $pos + 46; if ($file['sig'] !== 0x02014b50) { // Borked ZIP structure! return false; } $file['name'] = substr($data, $pos, $file['name_length']); $pos = $pos + $file['name_length']; $file['extra'] = array(); $file['extra_data'] = ''; if ($file['extra_length']) { $extradata = substr($data, $pos, $file['extra_length']); $file['extra_data'] = $extradata; while (strlen($extradata) > 4) { $extra = unpack('vid/vsize', substr($extradata, 0, 4)); $extra['data'] = substr($extradata, 4, $extra['size']); $extradata = substr($extradata, 4+$extra['size']); $file['extra'][] = $extra; } $pos = $pos + $file['extra_length']; } if ($file['comment_length']) { $pos = $pos + $file['comment_length']; $file['comment'] = substr($data, $pos, $file['comment_length']); } else { $file['comment'] = ''; } return $file; }
[ "public", "static", "function", "zip_parse_file_header", "(", "$", "data", ",", "$", "centralend", ",", "&", "$", "pos", ")", "{", "$", "file", "=", "unpack", "(", "'Vsig/vversion/vversion_req/vgeneral/vmethod/Vmodified/Vcrc/Vsize_compressed/Vsize/vname_length/vextra_length/vcomment_length/vdisk/vattr/Vattrext/Vlocal_offset'", ",", "substr", "(", "$", "data", ",", "$", "pos", ",", "46", ")", ")", ";", "$", "file", "[", "'central_offset'", "]", "=", "$", "centralend", "[", "'offset'", "]", "+", "$", "pos", ";", "$", "pos", "=", "$", "pos", "+", "46", ";", "if", "(", "$", "file", "[", "'sig'", "]", "!==", "0x02014b50", ")", "{", "// Borked ZIP structure!", "return", "false", ";", "}", "$", "file", "[", "'name'", "]", "=", "substr", "(", "$", "data", ",", "$", "pos", ",", "$", "file", "[", "'name_length'", "]", ")", ";", "$", "pos", "=", "$", "pos", "+", "$", "file", "[", "'name_length'", "]", ";", "$", "file", "[", "'extra'", "]", "=", "array", "(", ")", ";", "$", "file", "[", "'extra_data'", "]", "=", "''", ";", "if", "(", "$", "file", "[", "'extra_length'", "]", ")", "{", "$", "extradata", "=", "substr", "(", "$", "data", ",", "$", "pos", ",", "$", "file", "[", "'extra_length'", "]", ")", ";", "$", "file", "[", "'extra_data'", "]", "=", "$", "extradata", ";", "while", "(", "strlen", "(", "$", "extradata", ")", ">", "4", ")", "{", "$", "extra", "=", "unpack", "(", "'vid/vsize'", ",", "substr", "(", "$", "extradata", ",", "0", ",", "4", ")", ")", ";", "$", "extra", "[", "'data'", "]", "=", "substr", "(", "$", "extradata", ",", "4", ",", "$", "extra", "[", "'size'", "]", ")", ";", "$", "extradata", "=", "substr", "(", "$", "extradata", ",", "4", "+", "$", "extra", "[", "'size'", "]", ")", ";", "$", "file", "[", "'extra'", "]", "[", "]", "=", "$", "extra", ";", "}", "$", "pos", "=", "$", "pos", "+", "$", "file", "[", "'extra_length'", "]", ";", "}", "if", "(", "$", "file", "[", "'comment_length'", "]", ")", "{", "$", "pos", "=", "$", "pos", "+", "$", "file", "[", "'comment_length'", "]", ";", "$", "file", "[", "'comment'", "]", "=", "substr", "(", "$", "data", ",", "$", "pos", ",", "$", "file", "[", "'comment_length'", "]", ")", ";", "}", "else", "{", "$", "file", "[", "'comment'", "]", "=", "''", ";", "}", "return", "$", "file", ";", "}" ]
Parse file header. @internal @param string $data @param array $centralend @param int $pos (modified) @return array|bool file info
[ "Parse", "file", "header", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/filestorage/zip_archive.php#L837-L867
216,942
moodle/moodle
lib/google/src/Google/Auth/AppIdentity.php
Google_Auth_AppIdentity.authenticateForScope
public function authenticateForScope($scopes) { if ($this->token && $this->tokenScopes == $scopes) { return $this->token; } $cacheKey = self::CACHE_PREFIX; if (is_string($scopes)) { $cacheKey .= $scopes; } else if (is_array($scopes)) { $cacheKey .= implode(":", $scopes); } $this->token = $this->client->getCache()->get($cacheKey); if (!$this->token) { $this->retrieveToken($scopes, $cacheKey); } else if ($this->token['expiration_time'] < time()) { $this->client->getCache()->delete($cacheKey); $this->retrieveToken($scopes, $cacheKey); } $this->tokenScopes = $scopes; return $this->token; }
php
public function authenticateForScope($scopes) { if ($this->token && $this->tokenScopes == $scopes) { return $this->token; } $cacheKey = self::CACHE_PREFIX; if (is_string($scopes)) { $cacheKey .= $scopes; } else if (is_array($scopes)) { $cacheKey .= implode(":", $scopes); } $this->token = $this->client->getCache()->get($cacheKey); if (!$this->token) { $this->retrieveToken($scopes, $cacheKey); } else if ($this->token['expiration_time'] < time()) { $this->client->getCache()->delete($cacheKey); $this->retrieveToken($scopes, $cacheKey); } $this->tokenScopes = $scopes; return $this->token; }
[ "public", "function", "authenticateForScope", "(", "$", "scopes", ")", "{", "if", "(", "$", "this", "->", "token", "&&", "$", "this", "->", "tokenScopes", "==", "$", "scopes", ")", "{", "return", "$", "this", "->", "token", ";", "}", "$", "cacheKey", "=", "self", "::", "CACHE_PREFIX", ";", "if", "(", "is_string", "(", "$", "scopes", ")", ")", "{", "$", "cacheKey", ".=", "$", "scopes", ";", "}", "else", "if", "(", "is_array", "(", "$", "scopes", ")", ")", "{", "$", "cacheKey", ".=", "implode", "(", "\":\"", ",", "$", "scopes", ")", ";", "}", "$", "this", "->", "token", "=", "$", "this", "->", "client", "->", "getCache", "(", ")", "->", "get", "(", "$", "cacheKey", ")", ";", "if", "(", "!", "$", "this", "->", "token", ")", "{", "$", "this", "->", "retrieveToken", "(", "$", "scopes", ",", "$", "cacheKey", ")", ";", "}", "else", "if", "(", "$", "this", "->", "token", "[", "'expiration_time'", "]", "<", "time", "(", ")", ")", "{", "$", "this", "->", "client", "->", "getCache", "(", ")", "->", "delete", "(", "$", "cacheKey", ")", ";", "$", "this", "->", "retrieveToken", "(", "$", "scopes", ",", "$", "cacheKey", ")", ";", "}", "$", "this", "->", "tokenScopes", "=", "$", "scopes", ";", "return", "$", "this", "->", "token", ";", "}" ]
Retrieve an access token for the scopes supplied.
[ "Retrieve", "an", "access", "token", "for", "the", "scopes", "supplied", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/google/src/Google/Auth/AppIdentity.php#L47-L70
216,943
moodle/moodle
lib/google/src/Google/Auth/AppIdentity.php
Google_Auth_AppIdentity.retrieveToken
private function retrieveToken($scopes, $cacheKey) { $this->token = AppIdentityService::getAccessToken($scopes); if ($this->token) { $this->client->getCache()->set( $cacheKey, $this->token ); } }
php
private function retrieveToken($scopes, $cacheKey) { $this->token = AppIdentityService::getAccessToken($scopes); if ($this->token) { $this->client->getCache()->set( $cacheKey, $this->token ); } }
[ "private", "function", "retrieveToken", "(", "$", "scopes", ",", "$", "cacheKey", ")", "{", "$", "this", "->", "token", "=", "AppIdentityService", "::", "getAccessToken", "(", "$", "scopes", ")", ";", "if", "(", "$", "this", "->", "token", ")", "{", "$", "this", "->", "client", "->", "getCache", "(", ")", "->", "set", "(", "$", "cacheKey", ",", "$", "this", "->", "token", ")", ";", "}", "}" ]
Retrieve a new access token and store it in cache @param mixed $scopes @param string $cacheKey
[ "Retrieve", "a", "new", "access", "token", "and", "store", "it", "in", "cache" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/google/src/Google/Auth/AppIdentity.php#L77-L86
216,944
moodle/moodle
lib/form/url.php
MoodleQuickForm_url.get_filepicker_unique_id
protected function get_filepicker_unique_id() : string { if (empty($this->filepickeruniqueid)) { $this->filepickeruniqueid = uniqid(); } return $this->filepickeruniqueid; }
php
protected function get_filepicker_unique_id() : string { if (empty($this->filepickeruniqueid)) { $this->filepickeruniqueid = uniqid(); } return $this->filepickeruniqueid; }
[ "protected", "function", "get_filepicker_unique_id", "(", ")", ":", "string", "{", "if", "(", "empty", "(", "$", "this", "->", "filepickeruniqueid", ")", ")", "{", "$", "this", "->", "filepickeruniqueid", "=", "uniqid", "(", ")", ";", "}", "return", "$", "this", "->", "filepickeruniqueid", ";", "}" ]
Returns the unique id of the file picker associated with this url element, setting it in the process if not set. @return string the unique id of the file picker.
[ "Returns", "the", "unique", "id", "of", "the", "file", "picker", "associated", "with", "this", "url", "element", "setting", "it", "in", "the", "process", "if", "not", "set", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/form/url.php#L217-L222
216,945
moodle/moodle
lib/horde/framework/Horde/Imap/Client/Ids.php
Horde_Imap_Client_Ids.add
public function add($ids) { if (!is_null($ids)) { if (is_string($ids) && in_array($ids, array(self::ALL, self::SEARCH_RES, self::LARGEST))) { $this->_ids = $ids; } elseif ($add = $this->_resolveIds($ids)) { if (is_array($this->_ids) && !empty($this->_ids)) { foreach ($add as $val) { $this->_ids[] = $val; } } else { $this->_ids = $add; } if (!$this->duplicates) { $this->_ids = (count($this->_ids) > 25000) ? array_unique($this->_ids) : array_keys(array_flip($this->_ids)); } } $this->_sorted = is_array($this->_ids) && (count($this->_ids) === 1); } }
php
public function add($ids) { if (!is_null($ids)) { if (is_string($ids) && in_array($ids, array(self::ALL, self::SEARCH_RES, self::LARGEST))) { $this->_ids = $ids; } elseif ($add = $this->_resolveIds($ids)) { if (is_array($this->_ids) && !empty($this->_ids)) { foreach ($add as $val) { $this->_ids[] = $val; } } else { $this->_ids = $add; } if (!$this->duplicates) { $this->_ids = (count($this->_ids) > 25000) ? array_unique($this->_ids) : array_keys(array_flip($this->_ids)); } } $this->_sorted = is_array($this->_ids) && (count($this->_ids) === 1); } }
[ "public", "function", "add", "(", "$", "ids", ")", "{", "if", "(", "!", "is_null", "(", "$", "ids", ")", ")", "{", "if", "(", "is_string", "(", "$", "ids", ")", "&&", "in_array", "(", "$", "ids", ",", "array", "(", "self", "::", "ALL", ",", "self", "::", "SEARCH_RES", ",", "self", "::", "LARGEST", ")", ")", ")", "{", "$", "this", "->", "_ids", "=", "$", "ids", ";", "}", "elseif", "(", "$", "add", "=", "$", "this", "->", "_resolveIds", "(", "$", "ids", ")", ")", "{", "if", "(", "is_array", "(", "$", "this", "->", "_ids", ")", "&&", "!", "empty", "(", "$", "this", "->", "_ids", ")", ")", "{", "foreach", "(", "$", "add", "as", "$", "val", ")", "{", "$", "this", "->", "_ids", "[", "]", "=", "$", "val", ";", "}", "}", "else", "{", "$", "this", "->", "_ids", "=", "$", "add", ";", "}", "if", "(", "!", "$", "this", "->", "duplicates", ")", "{", "$", "this", "->", "_ids", "=", "(", "count", "(", "$", "this", "->", "_ids", ")", ">", "25000", ")", "?", "array_unique", "(", "$", "this", "->", "_ids", ")", ":", "array_keys", "(", "array_flip", "(", "$", "this", "->", "_ids", ")", ")", ";", "}", "}", "$", "this", "->", "_sorted", "=", "is_array", "(", "$", "this", "->", "_ids", ")", "&&", "(", "count", "(", "$", "this", "->", "_ids", ")", "===", "1", ")", ";", "}", "}" ]
Add IDs to the current object. @param mixed $ids Either self::ALL, self::SEARCH_RES, self::LARGEST, Horde_Imap_Client_Ids object, array, or sequence string.
[ "Add", "IDs", "to", "the", "current", "object", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Ids.php#L162-L185
216,946
moodle/moodle
lib/horde/framework/Horde/Imap/Client/Ids.php
Horde_Imap_Client_Ids.remove
public function remove($ids) { if (!$this->isEmpty() && ($remove = $this->_resolveIds($ids))) { $this->_ids = array_diff($this->_ids, array_unique($remove)); } }
php
public function remove($ids) { if (!$this->isEmpty() && ($remove = $this->_resolveIds($ids))) { $this->_ids = array_diff($this->_ids, array_unique($remove)); } }
[ "public", "function", "remove", "(", "$", "ids", ")", "{", "if", "(", "!", "$", "this", "->", "isEmpty", "(", ")", "&&", "(", "$", "remove", "=", "$", "this", "->", "_resolveIds", "(", "$", "ids", ")", ")", ")", "{", "$", "this", "->", "_ids", "=", "array_diff", "(", "$", "this", "->", "_ids", ",", "array_unique", "(", "$", "remove", ")", ")", ";", "}", "}" ]
Removed IDs from the current object. @since 2.17.0 @param mixed $ids Either Horde_Imap_Client_Ids object, array, or sequence string.
[ "Removed", "IDs", "from", "the", "current", "object", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Ids.php#L195-L201
216,947
moodle/moodle
lib/horde/framework/Horde/Imap/Client/Ids.php
Horde_Imap_Client_Ids.sort
public function sort() { if (!$this->_sorted && is_array($this->_ids)) { $this->_sort($this->_ids); $this->_sorted = true; } }
php
public function sort() { if (!$this->_sorted && is_array($this->_ids)) { $this->_sort($this->_ids); $this->_sorted = true; } }
[ "public", "function", "sort", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_sorted", "&&", "is_array", "(", "$", "this", "->", "_ids", ")", ")", "{", "$", "this", "->", "_sort", "(", "$", "this", "->", "_ids", ")", ";", "$", "this", "->", "_sorted", "=", "true", ";", "}", "}" ]
Sorts the IDs.
[ "Sorts", "the", "IDs", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Ids.php#L226-L232
216,948
moodle/moodle
lib/horde/framework/Horde/Imap/Client/Ids.php
Horde_Imap_Client_Ids.split
public function split($length) { $id = new Horde_Stream_Temp(); $id->add($this->tostring_sort, true); $out = array(); do { $out[] = $id->substring(0, $length) . $id->getToChar(','); } while (!$id->eof()); return $out; }
php
public function split($length) { $id = new Horde_Stream_Temp(); $id->add($this->tostring_sort, true); $out = array(); do { $out[] = $id->substring(0, $length) . $id->getToChar(','); } while (!$id->eof()); return $out; }
[ "public", "function", "split", "(", "$", "length", ")", "{", "$", "id", "=", "new", "Horde_Stream_Temp", "(", ")", ";", "$", "id", "->", "add", "(", "$", "this", "->", "tostring_sort", ",", "true", ")", ";", "$", "out", "=", "array", "(", ")", ";", "do", "{", "$", "out", "[", "]", "=", "$", "id", "->", "substring", "(", "0", ",", "$", "length", ")", ".", "$", "id", "->", "getToChar", "(", "','", ")", ";", "}", "while", "(", "!", "$", "id", "->", "eof", "(", ")", ")", ";", "return", "$", "out", ";", "}" ]
Split the sequence string at an approximate length. @since 2.7.0 @param integer $length Length to split. @return array A list containing individual sequence strings.
[ "Split", "the", "sequence", "string", "at", "an", "approximate", "length", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Ids.php#L253-L265
216,949
moodle/moodle
lib/horde/framework/Horde/Imap/Client/Ids.php
Horde_Imap_Client_Ids._toSequenceString
protected function _toSequenceString($sort = true) { if (empty($this->_ids)) { return ''; } $in = $this->_ids; if ($sort && !$this->_sorted) { $this->_sort($in); } $first = $last = array_shift($in); $i = count($in) - 1; $out = array(); foreach ($in as $key => $val) { if (($last + 1) == $val) { $last = $val; } if (($i == $key) || ($last != $val)) { if ($last == $first) { $out[] = $first; if ($i == $key) { $out[] = $val; } } else { $out[] = $first . ':' . $last; if (($i == $key) && ($last != $val)) { $out[] = $val; } } $first = $last = $val; } } return empty($out) ? $first : implode(',', $out); }
php
protected function _toSequenceString($sort = true) { if (empty($this->_ids)) { return ''; } $in = $this->_ids; if ($sort && !$this->_sorted) { $this->_sort($in); } $first = $last = array_shift($in); $i = count($in) - 1; $out = array(); foreach ($in as $key => $val) { if (($last + 1) == $val) { $last = $val; } if (($i == $key) || ($last != $val)) { if ($last == $first) { $out[] = $first; if ($i == $key) { $out[] = $val; } } else { $out[] = $first . ':' . $last; if (($i == $key) && ($last != $val)) { $out[] = $val; } } $first = $last = $val; } } return empty($out) ? $first : implode(',', $out); }
[ "protected", "function", "_toSequenceString", "(", "$", "sort", "=", "true", ")", "{", "if", "(", "empty", "(", "$", "this", "->", "_ids", ")", ")", "{", "return", "''", ";", "}", "$", "in", "=", "$", "this", "->", "_ids", ";", "if", "(", "$", "sort", "&&", "!", "$", "this", "->", "_sorted", ")", "{", "$", "this", "->", "_sort", "(", "$", "in", ")", ";", "}", "$", "first", "=", "$", "last", "=", "array_shift", "(", "$", "in", ")", ";", "$", "i", "=", "count", "(", "$", "in", ")", "-", "1", ";", "$", "out", "=", "array", "(", ")", ";", "foreach", "(", "$", "in", "as", "$", "key", "=>", "$", "val", ")", "{", "if", "(", "(", "$", "last", "+", "1", ")", "==", "$", "val", ")", "{", "$", "last", "=", "$", "val", ";", "}", "if", "(", "(", "$", "i", "==", "$", "key", ")", "||", "(", "$", "last", "!=", "$", "val", ")", ")", "{", "if", "(", "$", "last", "==", "$", "first", ")", "{", "$", "out", "[", "]", "=", "$", "first", ";", "if", "(", "$", "i", "==", "$", "key", ")", "{", "$", "out", "[", "]", "=", "$", "val", ";", "}", "}", "else", "{", "$", "out", "[", "]", "=", "$", "first", ".", "':'", ".", "$", "last", ";", "if", "(", "(", "$", "i", "==", "$", "key", ")", "&&", "(", "$", "last", "!=", "$", "val", ")", ")", "{", "$", "out", "[", "]", "=", "$", "val", ";", "}", "}", "$", "first", "=", "$", "last", "=", "$", "val", ";", "}", "}", "return", "empty", "(", "$", "out", ")", "?", "$", "first", ":", "implode", "(", "','", ",", "$", "out", ")", ";", "}" ]
Create an IMAP message sequence string from a list of indices. Index Format: range_start:range_end,uid,uid2,... @param boolean $sort Numerically sort the IDs before creating the range? @return string The IMAP message sequence string.
[ "Create", "an", "IMAP", "message", "sequence", "string", "from", "a", "list", "of", "indices", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Ids.php#L300-L340
216,950
moodle/moodle
lib/horde/framework/Horde/Imap/Client/Ids.php
Horde_Imap_Client_Ids._fromSequenceString
protected function _fromSequenceString($str) { $ids = array(); $str = trim($str); if (!strlen($str)) { return $ids; } $idarray = explode(',', $str); foreach ($idarray as $val) { $range = explode(':', $val); if (isset($range[1])) { for ($i = min($range), $j = max($range); $i <= $j; ++$i) { $ids[] = $i; } } else { $ids[] = $val; } } return $ids; }
php
protected function _fromSequenceString($str) { $ids = array(); $str = trim($str); if (!strlen($str)) { return $ids; } $idarray = explode(',', $str); foreach ($idarray as $val) { $range = explode(':', $val); if (isset($range[1])) { for ($i = min($range), $j = max($range); $i <= $j; ++$i) { $ids[] = $i; } } else { $ids[] = $val; } } return $ids; }
[ "protected", "function", "_fromSequenceString", "(", "$", "str", ")", "{", "$", "ids", "=", "array", "(", ")", ";", "$", "str", "=", "trim", "(", "$", "str", ")", ";", "if", "(", "!", "strlen", "(", "$", "str", ")", ")", "{", "return", "$", "ids", ";", "}", "$", "idarray", "=", "explode", "(", "','", ",", "$", "str", ")", ";", "foreach", "(", "$", "idarray", "as", "$", "val", ")", "{", "$", "range", "=", "explode", "(", "':'", ",", "$", "val", ")", ";", "if", "(", "isset", "(", "$", "range", "[", "1", "]", ")", ")", "{", "for", "(", "$", "i", "=", "min", "(", "$", "range", ")", ",", "$", "j", "=", "max", "(", "$", "range", ")", ";", "$", "i", "<=", "$", "j", ";", "++", "$", "i", ")", "{", "$", "ids", "[", "]", "=", "$", "i", ";", "}", "}", "else", "{", "$", "ids", "[", "]", "=", "$", "val", ";", "}", "}", "return", "$", "ids", ";", "}" ]
Parse an IMAP message sequence string into a list of indices. @see _toSequenceString() @param string $str The IMAP message sequence string. @return array An array of indices.
[ "Parse", "an", "IMAP", "message", "sequence", "string", "into", "a", "list", "of", "indices", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/horde/framework/Horde/Imap/Client/Ids.php#L351-L374
216,951
moodle/moodle
enrol/editinstance_form.php
enrol_instance_edit_form.validation
public function validation($data, $files) { $errors = parent::validation($data, $files); list($instance, $plugin, $context, $type) = $this->_customdata; $pluginerrors = $plugin->edit_instance_validation($data, $files, $instance, $context); $errors = array_merge($errors, $pluginerrors); return $errors; }
php
public function validation($data, $files) { $errors = parent::validation($data, $files); list($instance, $plugin, $context, $type) = $this->_customdata; $pluginerrors = $plugin->edit_instance_validation($data, $files, $instance, $context); $errors = array_merge($errors, $pluginerrors); return $errors; }
[ "public", "function", "validation", "(", "$", "data", ",", "$", "files", ")", "{", "$", "errors", "=", "parent", "::", "validation", "(", "$", "data", ",", "$", "files", ")", ";", "list", "(", "$", "instance", ",", "$", "plugin", ",", "$", "context", ",", "$", "type", ")", "=", "$", "this", "->", "_customdata", ";", "$", "pluginerrors", "=", "$", "plugin", "->", "edit_instance_validation", "(", "$", "data", ",", "$", "files", ",", "$", "instance", ",", "$", "context", ")", ";", "$", "errors", "=", "array_merge", "(", "$", "errors", ",", "$", "pluginerrors", ")", ";", "return", "$", "errors", ";", "}" ]
Validate this form. Calls plugin validation method. @param array $data @param array $files @return array
[ "Validate", "this", "form", ".", "Calls", "plugin", "validation", "method", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/editinstance_form.php#L79-L89
216,952
moodle/moodle
user/editadvanced_form.php
user_editadvanced_form.definition_after_data
public function definition_after_data() { global $USER, $CFG, $DB, $OUTPUT; $mform = $this->_form; // Trim required name fields. foreach (useredit_get_required_name_fields() as $field) { $mform->applyFilter($field, 'trim'); } if ($userid = $mform->getElementValue('id')) { $user = $DB->get_record('user', array('id' => $userid)); } else { $user = false; } // User can not change own auth method. if ($userid == $USER->id) { $mform->hardFreeze('auth'); $mform->hardFreeze('preference_auth_forcepasswordchange'); } // Admin must choose some password and supply correct email. if (!empty($USER->newadminuser)) { $mform->addRule('newpassword', get_string('required'), 'required', null, 'client'); if ($mform->elementExists('suspended')) { $mform->removeElement('suspended'); } } // Require password for new users. if ($userid > 0) { if ($mform->elementExists('createpassword')) { $mform->removeElement('createpassword'); } } if ($user and is_mnet_remote_user($user)) { // Only local accounts can be suspended. if ($mform->elementExists('suspended')) { $mform->removeElement('suspended'); } } if ($user and ($user->id == $USER->id or is_siteadmin($user))) { // Prevent self and admin mess ups. if ($mform->elementExists('suspended')) { $mform->hardFreeze('suspended'); } } // Print picture. if (empty($USER->newadminuser)) { if ($user) { $context = context_user::instance($user->id, MUST_EXIST); $fs = get_file_storage(); $hasuploadedpicture = ($fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.png') || $fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.jpg')); if (!empty($user->picture) && $hasuploadedpicture) { $imagevalue = $OUTPUT->user_picture($user, array('courseid' => SITEID, 'size' => 64)); } else { $imagevalue = get_string('none'); } } else { $imagevalue = get_string('none'); } $imageelement = $mform->getElement('currentpicture'); $imageelement->setValue($imagevalue); if ($user && $mform->elementExists('deletepicture') && !$hasuploadedpicture) { $mform->removeElement('deletepicture'); } } // Next the customisable profile fields. profile_definition_after_data($mform, $userid); }
php
public function definition_after_data() { global $USER, $CFG, $DB, $OUTPUT; $mform = $this->_form; // Trim required name fields. foreach (useredit_get_required_name_fields() as $field) { $mform->applyFilter($field, 'trim'); } if ($userid = $mform->getElementValue('id')) { $user = $DB->get_record('user', array('id' => $userid)); } else { $user = false; } // User can not change own auth method. if ($userid == $USER->id) { $mform->hardFreeze('auth'); $mform->hardFreeze('preference_auth_forcepasswordchange'); } // Admin must choose some password and supply correct email. if (!empty($USER->newadminuser)) { $mform->addRule('newpassword', get_string('required'), 'required', null, 'client'); if ($mform->elementExists('suspended')) { $mform->removeElement('suspended'); } } // Require password for new users. if ($userid > 0) { if ($mform->elementExists('createpassword')) { $mform->removeElement('createpassword'); } } if ($user and is_mnet_remote_user($user)) { // Only local accounts can be suspended. if ($mform->elementExists('suspended')) { $mform->removeElement('suspended'); } } if ($user and ($user->id == $USER->id or is_siteadmin($user))) { // Prevent self and admin mess ups. if ($mform->elementExists('suspended')) { $mform->hardFreeze('suspended'); } } // Print picture. if (empty($USER->newadminuser)) { if ($user) { $context = context_user::instance($user->id, MUST_EXIST); $fs = get_file_storage(); $hasuploadedpicture = ($fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.png') || $fs->file_exists($context->id, 'user', 'icon', 0, '/', 'f2.jpg')); if (!empty($user->picture) && $hasuploadedpicture) { $imagevalue = $OUTPUT->user_picture($user, array('courseid' => SITEID, 'size' => 64)); } else { $imagevalue = get_string('none'); } } else { $imagevalue = get_string('none'); } $imageelement = $mform->getElement('currentpicture'); $imageelement->setValue($imagevalue); if ($user && $mform->elementExists('deletepicture') && !$hasuploadedpicture) { $mform->removeElement('deletepicture'); } } // Next the customisable profile fields. profile_definition_after_data($mform, $userid); }
[ "public", "function", "definition_after_data", "(", ")", "{", "global", "$", "USER", ",", "$", "CFG", ",", "$", "DB", ",", "$", "OUTPUT", ";", "$", "mform", "=", "$", "this", "->", "_form", ";", "// Trim required name fields.", "foreach", "(", "useredit_get_required_name_fields", "(", ")", "as", "$", "field", ")", "{", "$", "mform", "->", "applyFilter", "(", "$", "field", ",", "'trim'", ")", ";", "}", "if", "(", "$", "userid", "=", "$", "mform", "->", "getElementValue", "(", "'id'", ")", ")", "{", "$", "user", "=", "$", "DB", "->", "get_record", "(", "'user'", ",", "array", "(", "'id'", "=>", "$", "userid", ")", ")", ";", "}", "else", "{", "$", "user", "=", "false", ";", "}", "// User can not change own auth method.", "if", "(", "$", "userid", "==", "$", "USER", "->", "id", ")", "{", "$", "mform", "->", "hardFreeze", "(", "'auth'", ")", ";", "$", "mform", "->", "hardFreeze", "(", "'preference_auth_forcepasswordchange'", ")", ";", "}", "// Admin must choose some password and supply correct email.", "if", "(", "!", "empty", "(", "$", "USER", "->", "newadminuser", ")", ")", "{", "$", "mform", "->", "addRule", "(", "'newpassword'", ",", "get_string", "(", "'required'", ")", ",", "'required'", ",", "null", ",", "'client'", ")", ";", "if", "(", "$", "mform", "->", "elementExists", "(", "'suspended'", ")", ")", "{", "$", "mform", "->", "removeElement", "(", "'suspended'", ")", ";", "}", "}", "// Require password for new users.", "if", "(", "$", "userid", ">", "0", ")", "{", "if", "(", "$", "mform", "->", "elementExists", "(", "'createpassword'", ")", ")", "{", "$", "mform", "->", "removeElement", "(", "'createpassword'", ")", ";", "}", "}", "if", "(", "$", "user", "and", "is_mnet_remote_user", "(", "$", "user", ")", ")", "{", "// Only local accounts can be suspended.", "if", "(", "$", "mform", "->", "elementExists", "(", "'suspended'", ")", ")", "{", "$", "mform", "->", "removeElement", "(", "'suspended'", ")", ";", "}", "}", "if", "(", "$", "user", "and", "(", "$", "user", "->", "id", "==", "$", "USER", "->", "id", "or", "is_siteadmin", "(", "$", "user", ")", ")", ")", "{", "// Prevent self and admin mess ups.", "if", "(", "$", "mform", "->", "elementExists", "(", "'suspended'", ")", ")", "{", "$", "mform", "->", "hardFreeze", "(", "'suspended'", ")", ";", "}", "}", "// Print picture.", "if", "(", "empty", "(", "$", "USER", "->", "newadminuser", ")", ")", "{", "if", "(", "$", "user", ")", "{", "$", "context", "=", "context_user", "::", "instance", "(", "$", "user", "->", "id", ",", "MUST_EXIST", ")", ";", "$", "fs", "=", "get_file_storage", "(", ")", ";", "$", "hasuploadedpicture", "=", "(", "$", "fs", "->", "file_exists", "(", "$", "context", "->", "id", ",", "'user'", ",", "'icon'", ",", "0", ",", "'/'", ",", "'f2.png'", ")", "||", "$", "fs", "->", "file_exists", "(", "$", "context", "->", "id", ",", "'user'", ",", "'icon'", ",", "0", ",", "'/'", ",", "'f2.jpg'", ")", ")", ";", "if", "(", "!", "empty", "(", "$", "user", "->", "picture", ")", "&&", "$", "hasuploadedpicture", ")", "{", "$", "imagevalue", "=", "$", "OUTPUT", "->", "user_picture", "(", "$", "user", ",", "array", "(", "'courseid'", "=>", "SITEID", ",", "'size'", "=>", "64", ")", ")", ";", "}", "else", "{", "$", "imagevalue", "=", "get_string", "(", "'none'", ")", ";", "}", "}", "else", "{", "$", "imagevalue", "=", "get_string", "(", "'none'", ")", ";", "}", "$", "imageelement", "=", "$", "mform", "->", "getElement", "(", "'currentpicture'", ")", ";", "$", "imageelement", "->", "setValue", "(", "$", "imagevalue", ")", ";", "if", "(", "$", "user", "&&", "$", "mform", "->", "elementExists", "(", "'deletepicture'", ")", "&&", "!", "$", "hasuploadedpicture", ")", "{", "$", "mform", "->", "removeElement", "(", "'deletepicture'", ")", ";", "}", "}", "// Next the customisable profile fields.", "profile_definition_after_data", "(", "$", "mform", ",", "$", "userid", ")", ";", "}" ]
Extend the form definition after data has been parsed.
[ "Extend", "the", "form", "definition", "after", "data", "has", "been", "parsed", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/user/editadvanced_form.php#L169-L243
216,953
moodle/moodle
lib/phpexcel/PHPExcel/Worksheet/PageSetup.php
PHPExcel_Worksheet_PageSetup.setPrintAreaByColumnAndRow
public function setPrintAreaByColumnAndRow($column1, $row1, $column2, $row2, $index = 0, $method = self::SETPRINTRANGE_OVERWRITE) { return $this->setPrintArea( PHPExcel_Cell::stringFromColumnIndex($column1) . $row1 . ':' . PHPExcel_Cell::stringFromColumnIndex($column2) . $row2, $index, $method ); }
php
public function setPrintAreaByColumnAndRow($column1, $row1, $column2, $row2, $index = 0, $method = self::SETPRINTRANGE_OVERWRITE) { return $this->setPrintArea( PHPExcel_Cell::stringFromColumnIndex($column1) . $row1 . ':' . PHPExcel_Cell::stringFromColumnIndex($column2) . $row2, $index, $method ); }
[ "public", "function", "setPrintAreaByColumnAndRow", "(", "$", "column1", ",", "$", "row1", ",", "$", "column2", ",", "$", "row2", ",", "$", "index", "=", "0", ",", "$", "method", "=", "self", "::", "SETPRINTRANGE_OVERWRITE", ")", "{", "return", "$", "this", "->", "setPrintArea", "(", "PHPExcel_Cell", "::", "stringFromColumnIndex", "(", "$", "column1", ")", ".", "$", "row1", ".", "':'", ".", "PHPExcel_Cell", "::", "stringFromColumnIndex", "(", "$", "column2", ")", ".", "$", "row2", ",", "$", "index", ",", "$", "method", ")", ";", "}" ]
Set print area @param int $column1 Column 1 @param int $row1 Row 1 @param int $column2 Column 2 @param int $row2 Row 2 @param int $index Identifier for a specific print area range allowing several ranges to be set When the method is "O"verwrite, then a positive integer index will overwrite that indexed entry in the print areas list; a negative index value will identify which entry to overwrite working bacward through the print area to the list, with the last entry as -1. Specifying an index value of 0, will overwrite <b>all</b> existing print ranges. When the method is "I"nsert, then a positive index will insert after that indexed entry in the print areas list, while a negative index will insert before the indexed entry. Specifying an index value of 0, will always append the new print range at the end of the list. Print areas are numbered from 1 @param string $method Determines the method used when setting multiple print areas Default behaviour, or the "O" method, overwrites existing print area The "I" method, inserts the new print area before any specified index, or at the end of the list @return PHPExcel_Worksheet_PageSetup @throws PHPExcel_Exception
[ "Set", "print", "area" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/phpexcel/PHPExcel/Worksheet/PageSetup.php#L759-L766
216,954
moodle/moodle
mod/data/lib.php
data_field_base.define_default_field
function define_default_field() { global $OUTPUT; if (empty($this->data->id)) { echo $OUTPUT->notification('Programmer error: dataid not defined in field class'); } $this->field = new stdClass(); $this->field->id = 0; $this->field->dataid = $this->data->id; $this->field->type = $this->type; $this->field->param1 = ''; $this->field->param2 = ''; $this->field->param3 = ''; $this->field->name = ''; $this->field->description = ''; $this->field->required = false; return true; }
php
function define_default_field() { global $OUTPUT; if (empty($this->data->id)) { echo $OUTPUT->notification('Programmer error: dataid not defined in field class'); } $this->field = new stdClass(); $this->field->id = 0; $this->field->dataid = $this->data->id; $this->field->type = $this->type; $this->field->param1 = ''; $this->field->param2 = ''; $this->field->param3 = ''; $this->field->name = ''; $this->field->description = ''; $this->field->required = false; return true; }
[ "function", "define_default_field", "(", ")", "{", "global", "$", "OUTPUT", ";", "if", "(", "empty", "(", "$", "this", "->", "data", "->", "id", ")", ")", "{", "echo", "$", "OUTPUT", "->", "notification", "(", "'Programmer error: dataid not defined in field class'", ")", ";", "}", "$", "this", "->", "field", "=", "new", "stdClass", "(", ")", ";", "$", "this", "->", "field", "->", "id", "=", "0", ";", "$", "this", "->", "field", "->", "dataid", "=", "$", "this", "->", "data", "->", "id", ";", "$", "this", "->", "field", "->", "type", "=", "$", "this", "->", "type", ";", "$", "this", "->", "field", "->", "param1", "=", "''", ";", "$", "this", "->", "field", "->", "param2", "=", "''", ";", "$", "this", "->", "field", "->", "param3", "=", "''", ";", "$", "this", "->", "field", "->", "name", "=", "''", ";", "$", "this", "->", "field", "->", "description", "=", "''", ";", "$", "this", "->", "field", "->", "required", "=", "false", ";", "return", "true", ";", "}" ]
This field just sets up a default field object @return bool
[ "This", "field", "just", "sets", "up", "a", "default", "field", "object" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/lib.php#L144-L161
216,955
moodle/moodle
mod/data/lib.php
data_field_base.define_field
function define_field($data) { $this->field->type = $this->type; $this->field->dataid = $this->data->id; $this->field->name = trim($data->name); $this->field->description = trim($data->description); $this->field->required = !empty($data->required) ? 1 : 0; if (isset($data->param1)) { $this->field->param1 = trim($data->param1); } if (isset($data->param2)) { $this->field->param2 = trim($data->param2); } if (isset($data->param3)) { $this->field->param3 = trim($data->param3); } if (isset($data->param4)) { $this->field->param4 = trim($data->param4); } if (isset($data->param5)) { $this->field->param5 = trim($data->param5); } return true; }
php
function define_field($data) { $this->field->type = $this->type; $this->field->dataid = $this->data->id; $this->field->name = trim($data->name); $this->field->description = trim($data->description); $this->field->required = !empty($data->required) ? 1 : 0; if (isset($data->param1)) { $this->field->param1 = trim($data->param1); } if (isset($data->param2)) { $this->field->param2 = trim($data->param2); } if (isset($data->param3)) { $this->field->param3 = trim($data->param3); } if (isset($data->param4)) { $this->field->param4 = trim($data->param4); } if (isset($data->param5)) { $this->field->param5 = trim($data->param5); } return true; }
[ "function", "define_field", "(", "$", "data", ")", "{", "$", "this", "->", "field", "->", "type", "=", "$", "this", "->", "type", ";", "$", "this", "->", "field", "->", "dataid", "=", "$", "this", "->", "data", "->", "id", ";", "$", "this", "->", "field", "->", "name", "=", "trim", "(", "$", "data", "->", "name", ")", ";", "$", "this", "->", "field", "->", "description", "=", "trim", "(", "$", "data", "->", "description", ")", ";", "$", "this", "->", "field", "->", "required", "=", "!", "empty", "(", "$", "data", "->", "required", ")", "?", "1", ":", "0", ";", "if", "(", "isset", "(", "$", "data", "->", "param1", ")", ")", "{", "$", "this", "->", "field", "->", "param1", "=", "trim", "(", "$", "data", "->", "param1", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "->", "param2", ")", ")", "{", "$", "this", "->", "field", "->", "param2", "=", "trim", "(", "$", "data", "->", "param2", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "->", "param3", ")", ")", "{", "$", "this", "->", "field", "->", "param3", "=", "trim", "(", "$", "data", "->", "param3", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "->", "param4", ")", ")", "{", "$", "this", "->", "field", "->", "param4", "=", "trim", "(", "$", "data", "->", "param4", ")", ";", "}", "if", "(", "isset", "(", "$", "data", "->", "param5", ")", ")", "{", "$", "this", "->", "field", "->", "param5", "=", "trim", "(", "$", "data", "->", "param5", ")", ";", "}", "return", "true", ";", "}" ]
Set up the field object according to data in an object. Now is the time to clean it! @return bool
[ "Set", "up", "the", "field", "object", "according", "to", "data", "in", "an", "object", ".", "Now", "is", "the", "time", "to", "clean", "it!" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/lib.php#L168-L193
216,956
moodle/moodle
mod/data/lib.php
data_field_base.update_field
function update_field() { global $DB; $DB->update_record('data_fields', $this->field); // Trigger an event for updating this field. $event = \mod_data\event\field_updated::create(array( 'objectid' => $this->field->id, 'context' => $this->context, 'other' => array( 'fieldname' => $this->field->name, 'dataid' => $this->data->id ) )); $event->trigger(); return true; }
php
function update_field() { global $DB; $DB->update_record('data_fields', $this->field); // Trigger an event for updating this field. $event = \mod_data\event\field_updated::create(array( 'objectid' => $this->field->id, 'context' => $this->context, 'other' => array( 'fieldname' => $this->field->name, 'dataid' => $this->data->id ) )); $event->trigger(); return true; }
[ "function", "update_field", "(", ")", "{", "global", "$", "DB", ";", "$", "DB", "->", "update_record", "(", "'data_fields'", ",", "$", "this", "->", "field", ")", ";", "// Trigger an event for updating this field.", "$", "event", "=", "\\", "mod_data", "\\", "event", "\\", "field_updated", "::", "create", "(", "array", "(", "'objectid'", "=>", "$", "this", "->", "field", "->", "id", ",", "'context'", "=>", "$", "this", "->", "context", ",", "'other'", "=>", "array", "(", "'fieldname'", "=>", "$", "this", "->", "field", "->", "name", ",", "'dataid'", "=>", "$", "this", "->", "data", "->", "id", ")", ")", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "return", "true", ";", "}" ]
Update a field in the database @global object @return bool
[ "Update", "a", "field", "in", "the", "database" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/lib.php#L233-L250
216,957
moodle/moodle
mod/data/lib.php
data_field_base.delete_field
function delete_field() { global $DB; if (!empty($this->field->id)) { // Get the field before we delete it. $field = $DB->get_record('data_fields', array('id' => $this->field->id)); $this->delete_content(); $DB->delete_records('data_fields', array('id'=>$this->field->id)); // Trigger an event for deleting this field. $event = \mod_data\event\field_deleted::create(array( 'objectid' => $this->field->id, 'context' => $this->context, 'other' => array( 'fieldname' => $this->field->name, 'dataid' => $this->data->id ) )); $event->add_record_snapshot('data_fields', $field); $event->trigger(); } return true; }
php
function delete_field() { global $DB; if (!empty($this->field->id)) { // Get the field before we delete it. $field = $DB->get_record('data_fields', array('id' => $this->field->id)); $this->delete_content(); $DB->delete_records('data_fields', array('id'=>$this->field->id)); // Trigger an event for deleting this field. $event = \mod_data\event\field_deleted::create(array( 'objectid' => $this->field->id, 'context' => $this->context, 'other' => array( 'fieldname' => $this->field->name, 'dataid' => $this->data->id ) )); $event->add_record_snapshot('data_fields', $field); $event->trigger(); } return true; }
[ "function", "delete_field", "(", ")", "{", "global", "$", "DB", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "field", "->", "id", ")", ")", "{", "// Get the field before we delete it.", "$", "field", "=", "$", "DB", "->", "get_record", "(", "'data_fields'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "field", "->", "id", ")", ")", ";", "$", "this", "->", "delete_content", "(", ")", ";", "$", "DB", "->", "delete_records", "(", "'data_fields'", ",", "array", "(", "'id'", "=>", "$", "this", "->", "field", "->", "id", ")", ")", ";", "// Trigger an event for deleting this field.", "$", "event", "=", "\\", "mod_data", "\\", "event", "\\", "field_deleted", "::", "create", "(", "array", "(", "'objectid'", "=>", "$", "this", "->", "field", "->", "id", ",", "'context'", "=>", "$", "this", "->", "context", ",", "'other'", "=>", "array", "(", "'fieldname'", "=>", "$", "this", "->", "field", "->", "name", ",", "'dataid'", "=>", "$", "this", "->", "data", "->", "id", ")", ")", ")", ";", "$", "event", "->", "add_record_snapshot", "(", "'data_fields'", ",", "$", "field", ")", ";", "$", "event", "->", "trigger", "(", ")", ";", "}", "return", "true", ";", "}" ]
Delete a field completely @global object @return bool
[ "Delete", "a", "field", "completely" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/lib.php#L258-L282
216,958
moodle/moodle
mod/data/lib.php
data_field_base.display_add_field
function display_add_field($recordid=0, $formdata=null) { global $DB, $OUTPUT; if ($formdata) { $fieldname = 'field_' . $this->field->id; $content = $formdata->$fieldname; } else if ($recordid) { $content = $DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid)); } else { $content = ''; } // beware get_field returns false for new, empty records MDL-18567 if ($content===false) { $content=''; } $str = '<div title="' . s($this->field->description) . '">'; $str .= '<label for="field_'.$this->field->id.'"><span class="accesshide">'.$this->field->name.'</span>'; if ($this->field->required) { $image = $OUTPUT->pix_icon('req', get_string('requiredelement', 'form')); $str .= html_writer::div($image, 'inline-req'); } $str .= '</label><input class="basefieldinput form-control d-inline mod-data-input" ' . 'type="text" name="field_' . $this->field->id . '" ' . 'id="field_' . $this->field->id . '" value="' . s($content) . '" />'; $str .= '</div>'; return $str; }
php
function display_add_field($recordid=0, $formdata=null) { global $DB, $OUTPUT; if ($formdata) { $fieldname = 'field_' . $this->field->id; $content = $formdata->$fieldname; } else if ($recordid) { $content = $DB->get_field('data_content', 'content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid)); } else { $content = ''; } // beware get_field returns false for new, empty records MDL-18567 if ($content===false) { $content=''; } $str = '<div title="' . s($this->field->description) . '">'; $str .= '<label for="field_'.$this->field->id.'"><span class="accesshide">'.$this->field->name.'</span>'; if ($this->field->required) { $image = $OUTPUT->pix_icon('req', get_string('requiredelement', 'form')); $str .= html_writer::div($image, 'inline-req'); } $str .= '</label><input class="basefieldinput form-control d-inline mod-data-input" ' . 'type="text" name="field_' . $this->field->id . '" ' . 'id="field_' . $this->field->id . '" value="' . s($content) . '" />'; $str .= '</div>'; return $str; }
[ "function", "display_add_field", "(", "$", "recordid", "=", "0", ",", "$", "formdata", "=", "null", ")", "{", "global", "$", "DB", ",", "$", "OUTPUT", ";", "if", "(", "$", "formdata", ")", "{", "$", "fieldname", "=", "'field_'", ".", "$", "this", "->", "field", "->", "id", ";", "$", "content", "=", "$", "formdata", "->", "$", "fieldname", ";", "}", "else", "if", "(", "$", "recordid", ")", "{", "$", "content", "=", "$", "DB", "->", "get_field", "(", "'data_content'", ",", "'content'", ",", "array", "(", "'fieldid'", "=>", "$", "this", "->", "field", "->", "id", ",", "'recordid'", "=>", "$", "recordid", ")", ")", ";", "}", "else", "{", "$", "content", "=", "''", ";", "}", "// beware get_field returns false for new, empty records MDL-18567", "if", "(", "$", "content", "===", "false", ")", "{", "$", "content", "=", "''", ";", "}", "$", "str", "=", "'<div title=\"'", ".", "s", "(", "$", "this", "->", "field", "->", "description", ")", ".", "'\">'", ";", "$", "str", ".=", "'<label for=\"field_'", ".", "$", "this", "->", "field", "->", "id", ".", "'\"><span class=\"accesshide\">'", ".", "$", "this", "->", "field", "->", "name", ".", "'</span>'", ";", "if", "(", "$", "this", "->", "field", "->", "required", ")", "{", "$", "image", "=", "$", "OUTPUT", "->", "pix_icon", "(", "'req'", ",", "get_string", "(", "'requiredelement'", ",", "'form'", ")", ")", ";", "$", "str", ".=", "html_writer", "::", "div", "(", "$", "image", ",", "'inline-req'", ")", ";", "}", "$", "str", ".=", "'</label><input class=\"basefieldinput form-control d-inline mod-data-input\" '", ".", "'type=\"text\" name=\"field_'", ".", "$", "this", "->", "field", "->", "id", ".", "'\" '", ".", "'id=\"field_'", ".", "$", "this", "->", "field", "->", "id", ".", "'\" value=\"'", ".", "s", "(", "$", "content", ")", ".", "'\" />'", ";", "$", "str", ".=", "'</div>'", ";", "return", "$", "str", ";", "}" ]
Print the relevant form element in the ADD template for this field @global object @param int $recordid @return string
[ "Print", "the", "relevant", "form", "element", "in", "the", "ADD", "template", "for", "this", "field" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/lib.php#L291-L320
216,959
moodle/moodle
mod/data/lib.php
data_field_base.display_edit_field
function display_edit_field() { global $CFG, $DB, $OUTPUT; if (empty($this->field)) { // No field has been defined yet, try and make one $this->define_default_field(); } echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide'); echo '<form id="editfield" action="'.$CFG->wwwroot.'/mod/data/field.php" method="post">'."\n"; echo '<input type="hidden" name="d" value="'.$this->data->id.'" />'."\n"; if (empty($this->field->id)) { echo '<input type="hidden" name="mode" value="add" />'."\n"; $savebutton = get_string('add'); } else { echo '<input type="hidden" name="fid" value="'.$this->field->id.'" />'."\n"; echo '<input type="hidden" name="mode" value="update" />'."\n"; $savebutton = get_string('savechanges'); } echo '<input type="hidden" name="type" value="'.$this->type.'" />'."\n"; echo '<input name="sesskey" value="'.sesskey().'" type="hidden" />'."\n"; echo $OUTPUT->heading($this->name(), 3); require_once($CFG->dirroot.'/mod/data/field/'.$this->type.'/mod.html'); echo '<div class="mdl-align">'; echo '<input type="submit" class="btn btn-primary" value="'.$savebutton.'" />'."\n"; echo '<input type="submit" class="btn btn-secondary" name="cancel" value="'.get_string('cancel').'" />'."\n"; echo '</div>'; echo '</form>'; echo $OUTPUT->box_end(); }
php
function display_edit_field() { global $CFG, $DB, $OUTPUT; if (empty($this->field)) { // No field has been defined yet, try and make one $this->define_default_field(); } echo $OUTPUT->box_start('generalbox boxaligncenter boxwidthwide'); echo '<form id="editfield" action="'.$CFG->wwwroot.'/mod/data/field.php" method="post">'."\n"; echo '<input type="hidden" name="d" value="'.$this->data->id.'" />'."\n"; if (empty($this->field->id)) { echo '<input type="hidden" name="mode" value="add" />'."\n"; $savebutton = get_string('add'); } else { echo '<input type="hidden" name="fid" value="'.$this->field->id.'" />'."\n"; echo '<input type="hidden" name="mode" value="update" />'."\n"; $savebutton = get_string('savechanges'); } echo '<input type="hidden" name="type" value="'.$this->type.'" />'."\n"; echo '<input name="sesskey" value="'.sesskey().'" type="hidden" />'."\n"; echo $OUTPUT->heading($this->name(), 3); require_once($CFG->dirroot.'/mod/data/field/'.$this->type.'/mod.html'); echo '<div class="mdl-align">'; echo '<input type="submit" class="btn btn-primary" value="'.$savebutton.'" />'."\n"; echo '<input type="submit" class="btn btn-secondary" name="cancel" value="'.get_string('cancel').'" />'."\n"; echo '</div>'; echo '</form>'; echo $OUTPUT->box_end(); }
[ "function", "display_edit_field", "(", ")", "{", "global", "$", "CFG", ",", "$", "DB", ",", "$", "OUTPUT", ";", "if", "(", "empty", "(", "$", "this", "->", "field", ")", ")", "{", "// No field has been defined yet, try and make one", "$", "this", "->", "define_default_field", "(", ")", ";", "}", "echo", "$", "OUTPUT", "->", "box_start", "(", "'generalbox boxaligncenter boxwidthwide'", ")", ";", "echo", "'<form id=\"editfield\" action=\"'", ".", "$", "CFG", "->", "wwwroot", ".", "'/mod/data/field.php\" method=\"post\">'", ".", "\"\\n\"", ";", "echo", "'<input type=\"hidden\" name=\"d\" value=\"'", ".", "$", "this", "->", "data", "->", "id", ".", "'\" />'", ".", "\"\\n\"", ";", "if", "(", "empty", "(", "$", "this", "->", "field", "->", "id", ")", ")", "{", "echo", "'<input type=\"hidden\" name=\"mode\" value=\"add\" />'", ".", "\"\\n\"", ";", "$", "savebutton", "=", "get_string", "(", "'add'", ")", ";", "}", "else", "{", "echo", "'<input type=\"hidden\" name=\"fid\" value=\"'", ".", "$", "this", "->", "field", "->", "id", ".", "'\" />'", ".", "\"\\n\"", ";", "echo", "'<input type=\"hidden\" name=\"mode\" value=\"update\" />'", ".", "\"\\n\"", ";", "$", "savebutton", "=", "get_string", "(", "'savechanges'", ")", ";", "}", "echo", "'<input type=\"hidden\" name=\"type\" value=\"'", ".", "$", "this", "->", "type", ".", "'\" />'", ".", "\"\\n\"", ";", "echo", "'<input name=\"sesskey\" value=\"'", ".", "sesskey", "(", ")", ".", "'\" type=\"hidden\" />'", ".", "\"\\n\"", ";", "echo", "$", "OUTPUT", "->", "heading", "(", "$", "this", "->", "name", "(", ")", ",", "3", ")", ";", "require_once", "(", "$", "CFG", "->", "dirroot", ".", "'/mod/data/field/'", ".", "$", "this", "->", "type", ".", "'/mod.html'", ")", ";", "echo", "'<div class=\"mdl-align\">'", ";", "echo", "'<input type=\"submit\" class=\"btn btn-primary\" value=\"'", ".", "$", "savebutton", ".", "'\" />'", ".", "\"\\n\"", ";", "echo", "'<input type=\"submit\" class=\"btn btn-secondary\" name=\"cancel\" value=\"'", ".", "get_string", "(", "'cancel'", ")", ".", "'\" />'", ".", "\"\\n\"", ";", "echo", "'</div>'", ";", "echo", "'</form>'", ";", "echo", "$", "OUTPUT", "->", "box_end", "(", ")", ";", "}" ]
Print the relevant form element to define the attributes for this field viewable by teachers only. @global object @global object @return void Output is echo'd
[ "Print", "the", "relevant", "form", "element", "to", "define", "the", "attributes", "for", "this", "field", "viewable", "by", "teachers", "only", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/lib.php#L330-L363
216,960
moodle/moodle
mod/data/lib.php
data_field_base.update_content
function update_content($recordid, $value, $name=''){ global $DB; $content = new stdClass(); $content->fieldid = $this->field->id; $content->recordid = $recordid; $content->content = clean_param($value, PARAM_NOTAGS); if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { $content->id = $oldcontent->id; return $DB->update_record('data_content', $content); } else { return $DB->insert_record('data_content', $content); } }
php
function update_content($recordid, $value, $name=''){ global $DB; $content = new stdClass(); $content->fieldid = $this->field->id; $content->recordid = $recordid; $content->content = clean_param($value, PARAM_NOTAGS); if ($oldcontent = $DB->get_record('data_content', array('fieldid'=>$this->field->id, 'recordid'=>$recordid))) { $content->id = $oldcontent->id; return $DB->update_record('data_content', $content); } else { return $DB->insert_record('data_content', $content); } }
[ "function", "update_content", "(", "$", "recordid", ",", "$", "value", ",", "$", "name", "=", "''", ")", "{", "global", "$", "DB", ";", "$", "content", "=", "new", "stdClass", "(", ")", ";", "$", "content", "->", "fieldid", "=", "$", "this", "->", "field", "->", "id", ";", "$", "content", "->", "recordid", "=", "$", "recordid", ";", "$", "content", "->", "content", "=", "clean_param", "(", "$", "value", ",", "PARAM_NOTAGS", ")", ";", "if", "(", "$", "oldcontent", "=", "$", "DB", "->", "get_record", "(", "'data_content'", ",", "array", "(", "'fieldid'", "=>", "$", "this", "->", "field", "->", "id", ",", "'recordid'", "=>", "$", "recordid", ")", ")", ")", "{", "$", "content", "->", "id", "=", "$", "oldcontent", "->", "id", ";", "return", "$", "DB", "->", "update_record", "(", "'data_content'", ",", "$", "content", ")", ";", "}", "else", "{", "return", "$", "DB", "->", "insert_record", "(", "'data_content'", ",", "$", "content", ")", ";", "}", "}" ]
Update the content of one data field in the data_content table @global object @param int $recordid @param mixed $value @param string $name @return bool
[ "Update", "the", "content", "of", "one", "data", "field", "in", "the", "data_content", "table" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/lib.php#L402-L416
216,961
moodle/moodle
mod/data/lib.php
data_field_base.delete_content
function delete_content($recordid=0) { global $DB; if ($recordid) { $conditions = array('fieldid'=>$this->field->id, 'recordid'=>$recordid); } else { $conditions = array('fieldid'=>$this->field->id); } $rs = $DB->get_recordset('data_content', $conditions); if ($rs->valid()) { $fs = get_file_storage(); foreach ($rs as $content) { $fs->delete_area_files($this->context->id, 'mod_data', 'content', $content->id); } } $rs->close(); return $DB->delete_records('data_content', $conditions); }
php
function delete_content($recordid=0) { global $DB; if ($recordid) { $conditions = array('fieldid'=>$this->field->id, 'recordid'=>$recordid); } else { $conditions = array('fieldid'=>$this->field->id); } $rs = $DB->get_recordset('data_content', $conditions); if ($rs->valid()) { $fs = get_file_storage(); foreach ($rs as $content) { $fs->delete_area_files($this->context->id, 'mod_data', 'content', $content->id); } } $rs->close(); return $DB->delete_records('data_content', $conditions); }
[ "function", "delete_content", "(", "$", "recordid", "=", "0", ")", "{", "global", "$", "DB", ";", "if", "(", "$", "recordid", ")", "{", "$", "conditions", "=", "array", "(", "'fieldid'", "=>", "$", "this", "->", "field", "->", "id", ",", "'recordid'", "=>", "$", "recordid", ")", ";", "}", "else", "{", "$", "conditions", "=", "array", "(", "'fieldid'", "=>", "$", "this", "->", "field", "->", "id", ")", ";", "}", "$", "rs", "=", "$", "DB", "->", "get_recordset", "(", "'data_content'", ",", "$", "conditions", ")", ";", "if", "(", "$", "rs", "->", "valid", "(", ")", ")", "{", "$", "fs", "=", "get_file_storage", "(", ")", ";", "foreach", "(", "$", "rs", "as", "$", "content", ")", "{", "$", "fs", "->", "delete_area_files", "(", "$", "this", "->", "context", "->", "id", ",", "'mod_data'", ",", "'content'", ",", "$", "content", "->", "id", ")", ";", "}", "}", "$", "rs", "->", "close", "(", ")", ";", "return", "$", "DB", "->", "delete_records", "(", "'data_content'", ",", "$", "conditions", ")", ";", "}" ]
Delete all content associated with the field @global object @param int $recordid @return bool
[ "Delete", "all", "content", "associated", "with", "the", "field" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/lib.php#L425-L444
216,962
moodle/moodle
mod/data/lib.php
data_field_base.image
function image() { global $OUTPUT; $params = array('d'=>$this->data->id, 'fid'=>$this->field->id, 'mode'=>'display', 'sesskey'=>sesskey()); $link = new moodle_url('/mod/data/field.php', $params); $str = '<a href="'.$link->out().'">'; $str .= $OUTPUT->pix_icon('field/' . $this->type, $this->type, 'data'); $str .= '</a>'; return $str; }
php
function image() { global $OUTPUT; $params = array('d'=>$this->data->id, 'fid'=>$this->field->id, 'mode'=>'display', 'sesskey'=>sesskey()); $link = new moodle_url('/mod/data/field.php', $params); $str = '<a href="'.$link->out().'">'; $str .= $OUTPUT->pix_icon('field/' . $this->type, $this->type, 'data'); $str .= '</a>'; return $str; }
[ "function", "image", "(", ")", "{", "global", "$", "OUTPUT", ";", "$", "params", "=", "array", "(", "'d'", "=>", "$", "this", "->", "data", "->", "id", ",", "'fid'", "=>", "$", "this", "->", "field", "->", "id", ",", "'mode'", "=>", "'display'", ",", "'sesskey'", "=>", "sesskey", "(", ")", ")", ";", "$", "link", "=", "new", "moodle_url", "(", "'/mod/data/field.php'", ",", "$", "params", ")", ";", "$", "str", "=", "'<a href=\"'", ".", "$", "link", "->", "out", "(", ")", ".", "'\">'", ";", "$", "str", ".=", "$", "OUTPUT", "->", "pix_icon", "(", "'field/'", ".", "$", "this", "->", "type", ",", "$", "this", "->", "type", ",", "'data'", ")", ";", "$", "str", ".=", "'</a>'", ";", "return", "$", "str", ";", "}" ]
Prints the respective type icon @global object @return string
[ "Prints", "the", "respective", "type", "icon" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/lib.php#L505-L514
216,963
moodle/moodle
mod/data/lib.php
data_preset_importer.data_preset_get_file_contents
public function data_preset_get_file_contents(&$filestorage, &$fileobj, $dir, $filename) { if(empty($filestorage) || empty($fileobj)) { if (substr($dir, -1)!='/') { $dir .= '/'; } if (file_exists($dir.$filename)) { return file_get_contents($dir.$filename); } else { return null; } } else { if ($filestorage->file_exists(DATA_PRESET_CONTEXT, DATA_PRESET_COMPONENT, DATA_PRESET_FILEAREA, 0, $fileobj->get_filepath(), $filename)) { $file = $filestorage->get_file(DATA_PRESET_CONTEXT, DATA_PRESET_COMPONENT, DATA_PRESET_FILEAREA, 0, $fileobj->get_filepath(), $filename); return $file->get_content(); } else { return null; } } }
php
public function data_preset_get_file_contents(&$filestorage, &$fileobj, $dir, $filename) { if(empty($filestorage) || empty($fileobj)) { if (substr($dir, -1)!='/') { $dir .= '/'; } if (file_exists($dir.$filename)) { return file_get_contents($dir.$filename); } else { return null; } } else { if ($filestorage->file_exists(DATA_PRESET_CONTEXT, DATA_PRESET_COMPONENT, DATA_PRESET_FILEAREA, 0, $fileobj->get_filepath(), $filename)) { $file = $filestorage->get_file(DATA_PRESET_CONTEXT, DATA_PRESET_COMPONENT, DATA_PRESET_FILEAREA, 0, $fileobj->get_filepath(), $filename); return $file->get_content(); } else { return null; } } }
[ "public", "function", "data_preset_get_file_contents", "(", "&", "$", "filestorage", ",", "&", "$", "fileobj", ",", "$", "dir", ",", "$", "filename", ")", "{", "if", "(", "empty", "(", "$", "filestorage", ")", "||", "empty", "(", "$", "fileobj", ")", ")", "{", "if", "(", "substr", "(", "$", "dir", ",", "-", "1", ")", "!=", "'/'", ")", "{", "$", "dir", ".=", "'/'", ";", "}", "if", "(", "file_exists", "(", "$", "dir", ".", "$", "filename", ")", ")", "{", "return", "file_get_contents", "(", "$", "dir", ".", "$", "filename", ")", ";", "}", "else", "{", "return", "null", ";", "}", "}", "else", "{", "if", "(", "$", "filestorage", "->", "file_exists", "(", "DATA_PRESET_CONTEXT", ",", "DATA_PRESET_COMPONENT", ",", "DATA_PRESET_FILEAREA", ",", "0", ",", "$", "fileobj", "->", "get_filepath", "(", ")", ",", "$", "filename", ")", ")", "{", "$", "file", "=", "$", "filestorage", "->", "get_file", "(", "DATA_PRESET_CONTEXT", ",", "DATA_PRESET_COMPONENT", ",", "DATA_PRESET_FILEAREA", ",", "0", ",", "$", "fileobj", "->", "get_filepath", "(", ")", ",", "$", "filename", ")", ";", "return", "$", "file", "->", "get_content", "(", ")", ";", "}", "else", "{", "return", "null", ";", "}", "}", "}" ]
Retreive the contents of a file. That file may either be in a conventional directory of the Moodle file storage @param file_storage $filestorage. should be null if using a conventional directory @param stored_file $fileobj the directory to look in. null if using a conventional directory @param string $dir the directory to look in. null if using the Moodle file storage @param string $filename the name of the file we want @return string the contents of the file or null if the file doesn't exist.
[ "Retreive", "the", "contents", "of", "a", "file", ".", "That", "file", "may", "either", "be", "in", "a", "conventional", "directory", "of", "the", "Moodle", "file", "storage" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/mod/data/lib.php#L2489-L2508
216,964
moodle/moodle
competency/classes/course_competency_settings.php
course_competency_settings.get_by_courseid
public static function get_by_courseid($courseid) { global $DB; $params = array( 'courseid' => $courseid ); $settings = new static(null, (object) $params); if ($record = $DB->get_record(self::TABLE, $params)) { $settings->from_record($record); } return $settings; }
php
public static function get_by_courseid($courseid) { global $DB; $params = array( 'courseid' => $courseid ); $settings = new static(null, (object) $params); if ($record = $DB->get_record(self::TABLE, $params)) { $settings->from_record($record); } return $settings; }
[ "public", "static", "function", "get_by_courseid", "(", "$", "courseid", ")", "{", "global", "$", "DB", ";", "$", "params", "=", "array", "(", "'courseid'", "=>", "$", "courseid", ")", ";", "$", "settings", "=", "new", "static", "(", "null", ",", "(", "object", ")", "$", "params", ")", ";", "if", "(", "$", "record", "=", "$", "DB", "->", "get_record", "(", "self", "::", "TABLE", ",", "$", "params", ")", ")", "{", "$", "settings", "->", "from_record", "(", "$", "record", ")", ";", "}", "return", "$", "settings", ";", "}" ]
Get a the course settings for a single course. @param int $courseid The course id @return course_competency_settings
[ "Get", "a", "the", "course", "settings", "for", "a", "single", "course", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/course_competency_settings.php#L67-L80
216,965
moodle/moodle
competency/classes/course_competency_settings.php
course_competency_settings.can_read
public static function can_read($courseid) { $context = context_course::instance($courseid); $capabilities = array('moodle/competency:coursecompetencyview', 'moodle/competency:coursecompetencymanage'); return has_any_capability($capabilities, $context); }
php
public static function can_read($courseid) { $context = context_course::instance($courseid); $capabilities = array('moodle/competency:coursecompetencyview', 'moodle/competency:coursecompetencymanage'); return has_any_capability($capabilities, $context); }
[ "public", "static", "function", "can_read", "(", "$", "courseid", ")", "{", "$", "context", "=", "context_course", "::", "instance", "(", "$", "courseid", ")", ";", "$", "capabilities", "=", "array", "(", "'moodle/competency:coursecompetencyview'", ",", "'moodle/competency:coursecompetencymanage'", ")", ";", "return", "has_any_capability", "(", "$", "capabilities", ",", "$", "context", ")", ";", "}" ]
Can the current user view competency settings for this course. @param int $courseid The course ID. @return bool
[ "Can", "the", "current", "user", "view", "competency", "settings", "for", "this", "course", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/course_competency_settings.php#L88-L94
216,966
moodle/moodle
competency/classes/course_competency_settings.php
course_competency_settings.can_manage_course
public static function can_manage_course($courseid) { $context = context_course::instance($courseid); $capabilities = array('moodle/competency:coursecompetencyconfigure'); return has_any_capability($capabilities, $context); }
php
public static function can_manage_course($courseid) { $context = context_course::instance($courseid); $capabilities = array('moodle/competency:coursecompetencyconfigure'); return has_any_capability($capabilities, $context); }
[ "public", "static", "function", "can_manage_course", "(", "$", "courseid", ")", "{", "$", "context", "=", "context_course", "::", "instance", "(", "$", "courseid", ")", ";", "$", "capabilities", "=", "array", "(", "'moodle/competency:coursecompetencyconfigure'", ")", ";", "return", "has_any_capability", "(", "$", "capabilities", ",", "$", "context", ")", ";", "}" ]
Can the current user change competency settings for this course. @param int $courseid The course ID. @return bool
[ "Can", "the", "current", "user", "change", "competency", "settings", "for", "this", "course", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/competency/classes/course_competency_settings.php#L102-L108
216,967
moodle/moodle
admin/tool/policy/classes/output/page_agreedocs.php
page_agreedocs.redirect_to_policies
protected function redirect_to_policies($userid, $returnurl = null) { // Make a list of all policies that the user has not answered yet. $allpolicies = $this->policies; if ($this->isexistinguser) { $acceptances = api::get_user_acceptances($userid); foreach ($allpolicies as $ix => $policy) { $isaccepted = api::is_user_version_accepted($userid, $policy->id, $acceptances); if ($isaccepted) { // The user has accepted this policy, do not show it again. unset($allpolicies[$ix]); } else if ($isaccepted === false && $policy->optional == policy_version::AGREEMENT_OPTIONAL) { // The user declined this policy but the agreement was optional, do not show it. unset($allpolicies[$ix]); } else { // The user has not answered the policy yet, or the agreement is compulsory. Show it. continue; } } } else { $presignupcache = \cache::make('core', 'presignup'); $acceptances = $presignupcache->get('tool_policy_policyversionidsagreed'); if ($acceptances) { foreach ($allpolicies as $ix => $policy) { if (in_array($policy->id, $acceptances)) { unset($allpolicies[$ix]); } } } } if (!empty($allpolicies)) { // Check if some of the to-be-accepted policies should be agreed on their own page. foreach ($allpolicies as $policy) { if ($policy->agreementstyle == policy_version::AGREEMENTSTYLE_OWNPAGE) { if (empty($returnurl)) { $returnurl = (new moodle_url('/admin/tool/policy/index.php'))->out_as_local_url(false); } $urlparams = ['versionid' => $policy->id, 'returnurl' => $returnurl]; redirect(new moodle_url('/admin/tool/policy/view.php', $urlparams)); } } $currentpolicyversionids = []; foreach ($allpolicies as $policy) { $currentpolicyversionids[] = $policy->id; } $cache = \cache::make('core', 'presignup'); $cachekey = 'tool_policy_viewedpolicies'; $viewedpolicies = $cache->get($cachekey); if (!empty($viewedpolicies)) { // Get the list of the policies docs which the user haven't viewed during this session. $pendingpolicies = array_diff($currentpolicyversionids, $viewedpolicies); } else { $pendingpolicies = $currentpolicyversionids; } if (count($pendingpolicies) > 0) { // Still is needed to show some policies docs. Save in the session and redirect. $policyversionid = array_shift($pendingpolicies); $viewedpolicies[] = $policyversionid; $cache->set($cachekey, $viewedpolicies); if (empty($returnurl)) { $returnurl = new moodle_url('/admin/tool/policy/index.php'); } $urlparams = ['versionid' => $policyversionid, 'returnurl' => $returnurl, 'numpolicy' => count($currentpolicyversionids) - count($pendingpolicies), 'totalpolicies' => count($currentpolicyversionids), ]; redirect(new moodle_url('/admin/tool/policy/view.php', $urlparams)); } } else { // Update the policyagreed for the user to avoid infinite loop because there are no policies to-be-accepted. api::update_policyagreed($userid); $this->redirect_to_previous_url(); } }
php
protected function redirect_to_policies($userid, $returnurl = null) { // Make a list of all policies that the user has not answered yet. $allpolicies = $this->policies; if ($this->isexistinguser) { $acceptances = api::get_user_acceptances($userid); foreach ($allpolicies as $ix => $policy) { $isaccepted = api::is_user_version_accepted($userid, $policy->id, $acceptances); if ($isaccepted) { // The user has accepted this policy, do not show it again. unset($allpolicies[$ix]); } else if ($isaccepted === false && $policy->optional == policy_version::AGREEMENT_OPTIONAL) { // The user declined this policy but the agreement was optional, do not show it. unset($allpolicies[$ix]); } else { // The user has not answered the policy yet, or the agreement is compulsory. Show it. continue; } } } else { $presignupcache = \cache::make('core', 'presignup'); $acceptances = $presignupcache->get('tool_policy_policyversionidsagreed'); if ($acceptances) { foreach ($allpolicies as $ix => $policy) { if (in_array($policy->id, $acceptances)) { unset($allpolicies[$ix]); } } } } if (!empty($allpolicies)) { // Check if some of the to-be-accepted policies should be agreed on their own page. foreach ($allpolicies as $policy) { if ($policy->agreementstyle == policy_version::AGREEMENTSTYLE_OWNPAGE) { if (empty($returnurl)) { $returnurl = (new moodle_url('/admin/tool/policy/index.php'))->out_as_local_url(false); } $urlparams = ['versionid' => $policy->id, 'returnurl' => $returnurl]; redirect(new moodle_url('/admin/tool/policy/view.php', $urlparams)); } } $currentpolicyversionids = []; foreach ($allpolicies as $policy) { $currentpolicyversionids[] = $policy->id; } $cache = \cache::make('core', 'presignup'); $cachekey = 'tool_policy_viewedpolicies'; $viewedpolicies = $cache->get($cachekey); if (!empty($viewedpolicies)) { // Get the list of the policies docs which the user haven't viewed during this session. $pendingpolicies = array_diff($currentpolicyversionids, $viewedpolicies); } else { $pendingpolicies = $currentpolicyversionids; } if (count($pendingpolicies) > 0) { // Still is needed to show some policies docs. Save in the session and redirect. $policyversionid = array_shift($pendingpolicies); $viewedpolicies[] = $policyversionid; $cache->set($cachekey, $viewedpolicies); if (empty($returnurl)) { $returnurl = new moodle_url('/admin/tool/policy/index.php'); } $urlparams = ['versionid' => $policyversionid, 'returnurl' => $returnurl, 'numpolicy' => count($currentpolicyversionids) - count($pendingpolicies), 'totalpolicies' => count($currentpolicyversionids), ]; redirect(new moodle_url('/admin/tool/policy/view.php', $urlparams)); } } else { // Update the policyagreed for the user to avoid infinite loop because there are no policies to-be-accepted. api::update_policyagreed($userid); $this->redirect_to_previous_url(); } }
[ "protected", "function", "redirect_to_policies", "(", "$", "userid", ",", "$", "returnurl", "=", "null", ")", "{", "// Make a list of all policies that the user has not answered yet.", "$", "allpolicies", "=", "$", "this", "->", "policies", ";", "if", "(", "$", "this", "->", "isexistinguser", ")", "{", "$", "acceptances", "=", "api", "::", "get_user_acceptances", "(", "$", "userid", ")", ";", "foreach", "(", "$", "allpolicies", "as", "$", "ix", "=>", "$", "policy", ")", "{", "$", "isaccepted", "=", "api", "::", "is_user_version_accepted", "(", "$", "userid", ",", "$", "policy", "->", "id", ",", "$", "acceptances", ")", ";", "if", "(", "$", "isaccepted", ")", "{", "// The user has accepted this policy, do not show it again.", "unset", "(", "$", "allpolicies", "[", "$", "ix", "]", ")", ";", "}", "else", "if", "(", "$", "isaccepted", "===", "false", "&&", "$", "policy", "->", "optional", "==", "policy_version", "::", "AGREEMENT_OPTIONAL", ")", "{", "// The user declined this policy but the agreement was optional, do not show it.", "unset", "(", "$", "allpolicies", "[", "$", "ix", "]", ")", ";", "}", "else", "{", "// The user has not answered the policy yet, or the agreement is compulsory. Show it.", "continue", ";", "}", "}", "}", "else", "{", "$", "presignupcache", "=", "\\", "cache", "::", "make", "(", "'core'", ",", "'presignup'", ")", ";", "$", "acceptances", "=", "$", "presignupcache", "->", "get", "(", "'tool_policy_policyversionidsagreed'", ")", ";", "if", "(", "$", "acceptances", ")", "{", "foreach", "(", "$", "allpolicies", "as", "$", "ix", "=>", "$", "policy", ")", "{", "if", "(", "in_array", "(", "$", "policy", "->", "id", ",", "$", "acceptances", ")", ")", "{", "unset", "(", "$", "allpolicies", "[", "$", "ix", "]", ")", ";", "}", "}", "}", "}", "if", "(", "!", "empty", "(", "$", "allpolicies", ")", ")", "{", "// Check if some of the to-be-accepted policies should be agreed on their own page.", "foreach", "(", "$", "allpolicies", "as", "$", "policy", ")", "{", "if", "(", "$", "policy", "->", "agreementstyle", "==", "policy_version", "::", "AGREEMENTSTYLE_OWNPAGE", ")", "{", "if", "(", "empty", "(", "$", "returnurl", ")", ")", "{", "$", "returnurl", "=", "(", "new", "moodle_url", "(", "'/admin/tool/policy/index.php'", ")", ")", "->", "out_as_local_url", "(", "false", ")", ";", "}", "$", "urlparams", "=", "[", "'versionid'", "=>", "$", "policy", "->", "id", ",", "'returnurl'", "=>", "$", "returnurl", "]", ";", "redirect", "(", "new", "moodle_url", "(", "'/admin/tool/policy/view.php'", ",", "$", "urlparams", ")", ")", ";", "}", "}", "$", "currentpolicyversionids", "=", "[", "]", ";", "foreach", "(", "$", "allpolicies", "as", "$", "policy", ")", "{", "$", "currentpolicyversionids", "[", "]", "=", "$", "policy", "->", "id", ";", "}", "$", "cache", "=", "\\", "cache", "::", "make", "(", "'core'", ",", "'presignup'", ")", ";", "$", "cachekey", "=", "'tool_policy_viewedpolicies'", ";", "$", "viewedpolicies", "=", "$", "cache", "->", "get", "(", "$", "cachekey", ")", ";", "if", "(", "!", "empty", "(", "$", "viewedpolicies", ")", ")", "{", "// Get the list of the policies docs which the user haven't viewed during this session.", "$", "pendingpolicies", "=", "array_diff", "(", "$", "currentpolicyversionids", ",", "$", "viewedpolicies", ")", ";", "}", "else", "{", "$", "pendingpolicies", "=", "$", "currentpolicyversionids", ";", "}", "if", "(", "count", "(", "$", "pendingpolicies", ")", ">", "0", ")", "{", "// Still is needed to show some policies docs. Save in the session and redirect.", "$", "policyversionid", "=", "array_shift", "(", "$", "pendingpolicies", ")", ";", "$", "viewedpolicies", "[", "]", "=", "$", "policyversionid", ";", "$", "cache", "->", "set", "(", "$", "cachekey", ",", "$", "viewedpolicies", ")", ";", "if", "(", "empty", "(", "$", "returnurl", ")", ")", "{", "$", "returnurl", "=", "new", "moodle_url", "(", "'/admin/tool/policy/index.php'", ")", ";", "}", "$", "urlparams", "=", "[", "'versionid'", "=>", "$", "policyversionid", ",", "'returnurl'", "=>", "$", "returnurl", ",", "'numpolicy'", "=>", "count", "(", "$", "currentpolicyversionids", ")", "-", "count", "(", "$", "pendingpolicies", ")", ",", "'totalpolicies'", "=>", "count", "(", "$", "currentpolicyversionids", ")", ",", "]", ";", "redirect", "(", "new", "moodle_url", "(", "'/admin/tool/policy/view.php'", ",", "$", "urlparams", ")", ")", ";", "}", "}", "else", "{", "// Update the policyagreed for the user to avoid infinite loop because there are no policies to-be-accepted.", "api", "::", "update_policyagreed", "(", "$", "userid", ")", ";", "$", "this", "->", "redirect_to_previous_url", "(", ")", ";", "}", "}" ]
Before display the consent page, the user has to view all the still-non-accepted policy docs. This function checks if the non-accepted policy docs have been shown and redirect to them. @param int $userid User identifier who wants to access to the consent page. @param moodle_url $returnurl URL to return after shown the policy docs.
[ "Before", "display", "the", "consent", "page", "the", "user", "has", "to", "view", "all", "the", "still", "-", "non", "-", "accepted", "policy", "docs", ".", "This", "function", "checks", "if", "the", "non", "-", "accepted", "policy", "docs", "have", "been", "shown", "and", "redirect", "to", "them", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/output/page_agreedocs.php#L228-L308
216,968
moodle/moodle
admin/tool/policy/classes/output/page_agreedocs.php
page_agreedocs.prepare_user_acceptances
protected function prepare_user_acceptances($userid) { global $USER; // Get all the policy version acceptances for this user. $lang = current_language(); foreach ($this->policies as $policy) { // Get a link to display the full policy document. $policy->url = new moodle_url('/admin/tool/policy/view.php', array('policyid' => $policy->policyid, 'returnurl' => qualified_me())); $policyattributes = array('data-action' => 'view', 'data-versionid' => $policy->id, 'data-behalfid' => $this->behalfid); $policymodal = html_writer::link($policy->url, $policy->name, $policyattributes); // Check if this policy version has been agreed or not. if ($this->isexistinguser) { // Existing user. $versionagreed = false; $versiondeclined = false; $acceptances = api::get_user_acceptances($userid); $policy->versionacceptance = api::get_user_version_acceptance($userid, $policy->id, $acceptances); if (!empty($policy->versionacceptance)) { // The policy version has ever been replied to before. Check if status = 1 to know if still is accepted. if ($policy->versionacceptance->status) { $versionagreed = true; } else { $versiondeclined = true; } if ($versionagreed) { if ($policy->versionacceptance->lang != $lang) { // Add a message because this version has been accepted in a different language than the current one. $policy->versionlangsagreed = get_string('policyversionacceptedinotherlang', 'tool_policy'); } $usermodified = $policy->versionacceptance->usermodified; if ($usermodified && $usermodified != $userid && $USER->id == $userid) { // Add a message because this version has been accepted on behalf of current user. $policy->versionbehalfsagreed = get_string('policyversionacceptedinbehalf', 'tool_policy'); } } } } else { // New user. $versionagreed = in_array($policy->id, $this->agreedocs); $versiondeclined = false; } $policy->versionagreed = $versionagreed; $policy->versiondeclined = $versiondeclined; $policy->policylink = html_writer::link($policy->url, $policy->name); $policy->policymodal = $policymodal; } }
php
protected function prepare_user_acceptances($userid) { global $USER; // Get all the policy version acceptances for this user. $lang = current_language(); foreach ($this->policies as $policy) { // Get a link to display the full policy document. $policy->url = new moodle_url('/admin/tool/policy/view.php', array('policyid' => $policy->policyid, 'returnurl' => qualified_me())); $policyattributes = array('data-action' => 'view', 'data-versionid' => $policy->id, 'data-behalfid' => $this->behalfid); $policymodal = html_writer::link($policy->url, $policy->name, $policyattributes); // Check if this policy version has been agreed or not. if ($this->isexistinguser) { // Existing user. $versionagreed = false; $versiondeclined = false; $acceptances = api::get_user_acceptances($userid); $policy->versionacceptance = api::get_user_version_acceptance($userid, $policy->id, $acceptances); if (!empty($policy->versionacceptance)) { // The policy version has ever been replied to before. Check if status = 1 to know if still is accepted. if ($policy->versionacceptance->status) { $versionagreed = true; } else { $versiondeclined = true; } if ($versionagreed) { if ($policy->versionacceptance->lang != $lang) { // Add a message because this version has been accepted in a different language than the current one. $policy->versionlangsagreed = get_string('policyversionacceptedinotherlang', 'tool_policy'); } $usermodified = $policy->versionacceptance->usermodified; if ($usermodified && $usermodified != $userid && $USER->id == $userid) { // Add a message because this version has been accepted on behalf of current user. $policy->versionbehalfsagreed = get_string('policyversionacceptedinbehalf', 'tool_policy'); } } } } else { // New user. $versionagreed = in_array($policy->id, $this->agreedocs); $versiondeclined = false; } $policy->versionagreed = $versionagreed; $policy->versiondeclined = $versiondeclined; $policy->policylink = html_writer::link($policy->url, $policy->name); $policy->policymodal = $policymodal; } }
[ "protected", "function", "prepare_user_acceptances", "(", "$", "userid", ")", "{", "global", "$", "USER", ";", "// Get all the policy version acceptances for this user.", "$", "lang", "=", "current_language", "(", ")", ";", "foreach", "(", "$", "this", "->", "policies", "as", "$", "policy", ")", "{", "// Get a link to display the full policy document.", "$", "policy", "->", "url", "=", "new", "moodle_url", "(", "'/admin/tool/policy/view.php'", ",", "array", "(", "'policyid'", "=>", "$", "policy", "->", "policyid", ",", "'returnurl'", "=>", "qualified_me", "(", ")", ")", ")", ";", "$", "policyattributes", "=", "array", "(", "'data-action'", "=>", "'view'", ",", "'data-versionid'", "=>", "$", "policy", "->", "id", ",", "'data-behalfid'", "=>", "$", "this", "->", "behalfid", ")", ";", "$", "policymodal", "=", "html_writer", "::", "link", "(", "$", "policy", "->", "url", ",", "$", "policy", "->", "name", ",", "$", "policyattributes", ")", ";", "// Check if this policy version has been agreed or not.", "if", "(", "$", "this", "->", "isexistinguser", ")", "{", "// Existing user.", "$", "versionagreed", "=", "false", ";", "$", "versiondeclined", "=", "false", ";", "$", "acceptances", "=", "api", "::", "get_user_acceptances", "(", "$", "userid", ")", ";", "$", "policy", "->", "versionacceptance", "=", "api", "::", "get_user_version_acceptance", "(", "$", "userid", ",", "$", "policy", "->", "id", ",", "$", "acceptances", ")", ";", "if", "(", "!", "empty", "(", "$", "policy", "->", "versionacceptance", ")", ")", "{", "// The policy version has ever been replied to before. Check if status = 1 to know if still is accepted.", "if", "(", "$", "policy", "->", "versionacceptance", "->", "status", ")", "{", "$", "versionagreed", "=", "true", ";", "}", "else", "{", "$", "versiondeclined", "=", "true", ";", "}", "if", "(", "$", "versionagreed", ")", "{", "if", "(", "$", "policy", "->", "versionacceptance", "->", "lang", "!=", "$", "lang", ")", "{", "// Add a message because this version has been accepted in a different language than the current one.", "$", "policy", "->", "versionlangsagreed", "=", "get_string", "(", "'policyversionacceptedinotherlang'", ",", "'tool_policy'", ")", ";", "}", "$", "usermodified", "=", "$", "policy", "->", "versionacceptance", "->", "usermodified", ";", "if", "(", "$", "usermodified", "&&", "$", "usermodified", "!=", "$", "userid", "&&", "$", "USER", "->", "id", "==", "$", "userid", ")", "{", "// Add a message because this version has been accepted on behalf of current user.", "$", "policy", "->", "versionbehalfsagreed", "=", "get_string", "(", "'policyversionacceptedinbehalf'", ",", "'tool_policy'", ")", ";", "}", "}", "}", "}", "else", "{", "// New user.", "$", "versionagreed", "=", "in_array", "(", "$", "policy", "->", "id", ",", "$", "this", "->", "agreedocs", ")", ";", "$", "versiondeclined", "=", "false", ";", "}", "$", "policy", "->", "versionagreed", "=", "$", "versionagreed", ";", "$", "policy", "->", "versiondeclined", "=", "$", "versiondeclined", ";", "$", "policy", "->", "policylink", "=", "html_writer", "::", "link", "(", "$", "policy", "->", "url", ",", "$", "policy", "->", "name", ")", ";", "$", "policy", "->", "policymodal", "=", "$", "policymodal", ";", "}", "}" ]
Prepare user acceptances. @param int $userid
[ "Prepare", "user", "acceptances", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/admin/tool/policy/classes/output/page_agreedocs.php#L395-L445
216,969
moodle/moodle
cache/disabledlib.php
cache_config_disabled.generate_configuration_array
protected function generate_configuration_array() { $configuration = array(); $configuration['stores'] = $this->configstores; $configuration['modemappings'] = $this->configmodemappings; $configuration['definitions'] = $this->configdefinitions; $configuration['definitionmappings'] = $this->configdefinitionmappings; $configuration['locks'] = $this->configlocks; return $configuration; }
php
protected function generate_configuration_array() { $configuration = array(); $configuration['stores'] = $this->configstores; $configuration['modemappings'] = $this->configmodemappings; $configuration['definitions'] = $this->configdefinitions; $configuration['definitionmappings'] = $this->configdefinitionmappings; $configuration['locks'] = $this->configlocks; return $configuration; }
[ "protected", "function", "generate_configuration_array", "(", ")", "{", "$", "configuration", "=", "array", "(", ")", ";", "$", "configuration", "[", "'stores'", "]", "=", "$", "this", "->", "configstores", ";", "$", "configuration", "[", "'modemappings'", "]", "=", "$", "this", "->", "configmodemappings", ";", "$", "configuration", "[", "'definitions'", "]", "=", "$", "this", "->", "configdefinitions", ";", "$", "configuration", "[", "'definitionmappings'", "]", "=", "$", "this", "->", "configdefinitionmappings", ";", "$", "configuration", "[", "'locks'", "]", "=", "$", "this", "->", "configlocks", ";", "return", "$", "configuration", ";", "}" ]
Generates a configuration array suitable to be written to the config file. @return array
[ "Generates", "a", "configuration", "array", "suitable", "to", "be", "written", "to", "the", "config", "file", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/cache/disabledlib.php#L327-L335
216,970
moodle/moodle
repository/equella/lib.php
repository_equella.get_listing
public function get_listing($path = null, $page = null) { global $COURSE; $callbackurl = new moodle_url('/repository/equella/callback.php', array('repo_id'=>$this->id)); $mimetypesstr = ''; $restrict = ''; if (!empty($this->mimetypes)) { $mimetypesstr = '&mimeTypes=' . implode(',', $this->mimetypes); // We're restricting to a mime type, so we always restrict to selecting resources only. $restrict = '&attachmentonly=true'; } else if ($this->get_option('equella_select_restriction') != 'none') { // The option value matches the EQUELLA paramter name. $restrict = '&' . $this->get_option('equella_select_restriction') . '=true'; } $url = $this->get_option('equella_url') . '?method=lms' . '&returnurl='.urlencode($callbackurl) . '&returnprefix=tle' . '&template=standard' . '&token='.urlencode($this->getssotoken('write')) . '&courseId='.urlencode($COURSE->idnumber) . '&courseCode='.urlencode($COURSE->shortname) . '&action=searchThin' . '&forcePost=true' . '&cancelDisabled=true' . '&attachmentUuidUrls=true' . '&options='.urlencode($this->get_option('equella_options') . $mimetypesstr) . $restrict; $manageurl = $this->get_option('equella_url'); $manageurl = str_ireplace('signon.do', 'logon.do', $manageurl); $manageurl = $this->appendtoken($manageurl); $list = array(); $list['object'] = array(); $list['object']['type'] = 'text/html'; $list['object']['src'] = $url; $list['nologin'] = true; $list['nosearch'] = true; $list['norefresh'] = true; $list['manage'] = $manageurl; return $list; }
php
public function get_listing($path = null, $page = null) { global $COURSE; $callbackurl = new moodle_url('/repository/equella/callback.php', array('repo_id'=>$this->id)); $mimetypesstr = ''; $restrict = ''; if (!empty($this->mimetypes)) { $mimetypesstr = '&mimeTypes=' . implode(',', $this->mimetypes); // We're restricting to a mime type, so we always restrict to selecting resources only. $restrict = '&attachmentonly=true'; } else if ($this->get_option('equella_select_restriction') != 'none') { // The option value matches the EQUELLA paramter name. $restrict = '&' . $this->get_option('equella_select_restriction') . '=true'; } $url = $this->get_option('equella_url') . '?method=lms' . '&returnurl='.urlencode($callbackurl) . '&returnprefix=tle' . '&template=standard' . '&token='.urlencode($this->getssotoken('write')) . '&courseId='.urlencode($COURSE->idnumber) . '&courseCode='.urlencode($COURSE->shortname) . '&action=searchThin' . '&forcePost=true' . '&cancelDisabled=true' . '&attachmentUuidUrls=true' . '&options='.urlencode($this->get_option('equella_options') . $mimetypesstr) . $restrict; $manageurl = $this->get_option('equella_url'); $manageurl = str_ireplace('signon.do', 'logon.do', $manageurl); $manageurl = $this->appendtoken($manageurl); $list = array(); $list['object'] = array(); $list['object']['type'] = 'text/html'; $list['object']['src'] = $url; $list['nologin'] = true; $list['nosearch'] = true; $list['norefresh'] = true; $list['manage'] = $manageurl; return $list; }
[ "public", "function", "get_listing", "(", "$", "path", "=", "null", ",", "$", "page", "=", "null", ")", "{", "global", "$", "COURSE", ";", "$", "callbackurl", "=", "new", "moodle_url", "(", "'/repository/equella/callback.php'", ",", "array", "(", "'repo_id'", "=>", "$", "this", "->", "id", ")", ")", ";", "$", "mimetypesstr", "=", "''", ";", "$", "restrict", "=", "''", ";", "if", "(", "!", "empty", "(", "$", "this", "->", "mimetypes", ")", ")", "{", "$", "mimetypesstr", "=", "'&mimeTypes='", ".", "implode", "(", "','", ",", "$", "this", "->", "mimetypes", ")", ";", "// We're restricting to a mime type, so we always restrict to selecting resources only.", "$", "restrict", "=", "'&attachmentonly=true'", ";", "}", "else", "if", "(", "$", "this", "->", "get_option", "(", "'equella_select_restriction'", ")", "!=", "'none'", ")", "{", "// The option value matches the EQUELLA paramter name.", "$", "restrict", "=", "'&'", ".", "$", "this", "->", "get_option", "(", "'equella_select_restriction'", ")", ".", "'=true'", ";", "}", "$", "url", "=", "$", "this", "->", "get_option", "(", "'equella_url'", ")", ".", "'?method=lms'", ".", "'&returnurl='", ".", "urlencode", "(", "$", "callbackurl", ")", ".", "'&returnprefix=tle'", ".", "'&template=standard'", ".", "'&token='", ".", "urlencode", "(", "$", "this", "->", "getssotoken", "(", "'write'", ")", ")", ".", "'&courseId='", ".", "urlencode", "(", "$", "COURSE", "->", "idnumber", ")", ".", "'&courseCode='", ".", "urlencode", "(", "$", "COURSE", "->", "shortname", ")", ".", "'&action=searchThin'", ".", "'&forcePost=true'", ".", "'&cancelDisabled=true'", ".", "'&attachmentUuidUrls=true'", ".", "'&options='", ".", "urlencode", "(", "$", "this", "->", "get_option", "(", "'equella_options'", ")", ".", "$", "mimetypesstr", ")", ".", "$", "restrict", ";", "$", "manageurl", "=", "$", "this", "->", "get_option", "(", "'equella_url'", ")", ";", "$", "manageurl", "=", "str_ireplace", "(", "'signon.do'", ",", "'logon.do'", ",", "$", "manageurl", ")", ";", "$", "manageurl", "=", "$", "this", "->", "appendtoken", "(", "$", "manageurl", ")", ";", "$", "list", "=", "array", "(", ")", ";", "$", "list", "[", "'object'", "]", "=", "array", "(", ")", ";", "$", "list", "[", "'object'", "]", "[", "'type'", "]", "=", "'text/html'", ";", "$", "list", "[", "'object'", "]", "[", "'src'", "]", "=", "$", "url", ";", "$", "list", "[", "'nologin'", "]", "=", "true", ";", "$", "list", "[", "'nosearch'", "]", "=", "true", ";", "$", "list", "[", "'norefresh'", "]", "=", "true", ";", "$", "list", "[", "'manage'", "]", "=", "$", "manageurl", ";", "return", "$", "list", ";", "}" ]
Display embedded equella interface @param string $path @param mixed $page @return array
[ "Display", "embedded", "equella", "interface" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/equella/lib.php#L67-L110
216,971
moodle/moodle
repository/equella/lib.php
repository_equella.connection_result
private function connection_result($errno = null) { static $countfailures = array(); $sess = sesskey(); if (!array_key_exists($sess, $countfailures)) { $countfailures[$sess] = 0; } if ($errno !== null) { if ($errno == 0) { // reset count of failed connections $countfailures[$sess] = 0; } else if ($errno == 7 /*CURLE_COULDNT_CONNECT*/ || $errno == 9 /*CURLE_REMOTE_ACCESS_DENIED*/) { // problems with server $countfailures[$sess]++; } } return ($countfailures[$sess] < 3); }
php
private function connection_result($errno = null) { static $countfailures = array(); $sess = sesskey(); if (!array_key_exists($sess, $countfailures)) { $countfailures[$sess] = 0; } if ($errno !== null) { if ($errno == 0) { // reset count of failed connections $countfailures[$sess] = 0; } else if ($errno == 7 /*CURLE_COULDNT_CONNECT*/ || $errno == 9 /*CURLE_REMOTE_ACCESS_DENIED*/) { // problems with server $countfailures[$sess]++; } } return ($countfailures[$sess] < 3); }
[ "private", "function", "connection_result", "(", "$", "errno", "=", "null", ")", "{", "static", "$", "countfailures", "=", "array", "(", ")", ";", "$", "sess", "=", "sesskey", "(", ")", ";", "if", "(", "!", "array_key_exists", "(", "$", "sess", ",", "$", "countfailures", ")", ")", "{", "$", "countfailures", "[", "$", "sess", "]", "=", "0", ";", "}", "if", "(", "$", "errno", "!==", "null", ")", "{", "if", "(", "$", "errno", "==", "0", ")", "{", "// reset count of failed connections", "$", "countfailures", "[", "$", "sess", "]", "=", "0", ";", "}", "else", "if", "(", "$", "errno", "==", "7", "/*CURLE_COULDNT_CONNECT*/", "||", "$", "errno", "==", "9", "/*CURLE_REMOTE_ACCESS_DENIED*/", ")", "{", "// problems with server", "$", "countfailures", "[", "$", "sess", "]", "++", ";", "}", "}", "return", "(", "$", "countfailures", "[", "$", "sess", "]", "<", "3", ")", ";", "}" ]
Counts the number of failed connections. If we received the connection timeout more than 3 times in a row, we don't attemt to connect to the server any more during this request. This function is used by {@link repository_equella::sync_reference()} that synchronises the file size of referenced files. @param int $errno omit if we just want to know the return value, the last curl_errno otherwise @return bool true if we had less than 3 failed connections, false if no more connections attempts recommended
[ "Counts", "the", "number", "of", "failed", "connections", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/equella/lib.php#L148-L164
216,972
moodle/moodle
repository/equella/lib.php
repository_equella.get_instance_option_names
public static function get_instance_option_names() { $rv = array('equella_url', 'equella_select_restriction', 'equella_options', 'equella_shareid', 'equella_sharedsecret' ); foreach (self::get_all_editing_roles() as $role) { array_push($rv, "equella_{$role->shortname}_shareid"); array_push($rv, "equella_{$role->shortname}_sharedsecret"); } return $rv; }
php
public static function get_instance_option_names() { $rv = array('equella_url', 'equella_select_restriction', 'equella_options', 'equella_shareid', 'equella_sharedsecret' ); foreach (self::get_all_editing_roles() as $role) { array_push($rv, "equella_{$role->shortname}_shareid"); array_push($rv, "equella_{$role->shortname}_sharedsecret"); } return $rv; }
[ "public", "static", "function", "get_instance_option_names", "(", ")", "{", "$", "rv", "=", "array", "(", "'equella_url'", ",", "'equella_select_restriction'", ",", "'equella_options'", ",", "'equella_shareid'", ",", "'equella_sharedsecret'", ")", ";", "foreach", "(", "self", "::", "get_all_editing_roles", "(", ")", "as", "$", "role", ")", "{", "array_push", "(", "$", "rv", ",", "\"equella_{$role->shortname}_shareid\"", ")", ";", "array_push", "(", "$", "rv", ",", "\"equella_{$role->shortname}_sharedsecret\"", ")", ";", "}", "return", "$", "rv", ";", "}" ]
Names of the instance settings @return array
[ "Names", "of", "the", "instance", "settings" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/equella/lib.php#L308-L319
216,973
moodle/moodle
repository/equella/lib.php
repository_equella.getssotoken_raw
private static function getssotoken_raw($username, $shareid, $sharedsecret) { $time = time() . '000'; return urlencode($username) . ':' . $shareid . ':' . $time . ':' . base64_encode(pack('H*', md5($username . $shareid . $time . $sharedsecret))); }
php
private static function getssotoken_raw($username, $shareid, $sharedsecret) { $time = time() . '000'; return urlencode($username) . ':' . $shareid . ':' . $time . ':' . base64_encode(pack('H*', md5($username . $shareid . $time . $sharedsecret))); }
[ "private", "static", "function", "getssotoken_raw", "(", "$", "username", ",", "$", "shareid", ",", "$", "sharedsecret", ")", "{", "$", "time", "=", "time", "(", ")", ".", "'000'", ";", "return", "urlencode", "(", "$", "username", ")", ".", "':'", ".", "$", "shareid", ".", "':'", ".", "$", "time", ".", "':'", ".", "base64_encode", "(", "pack", "(", "'H*'", ",", "md5", "(", "$", "username", ".", "$", "shareid", ".", "$", "time", ".", "$", "sharedsecret", ")", ")", ")", ";", "}" ]
Generate equella token @param string $username @param string $shareid @param string $sharedsecret @return string
[ "Generate", "equella", "token" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/equella/lib.php#L329-L338
216,974
moodle/moodle
repository/equella/lib.php
repository_equella.getssotoken
private function getssotoken($readwrite = 'read') { global $USER; if (empty($USER->username)) { return false; } if ($readwrite == 'write') { foreach (self::get_all_editing_roles() as $role) { if (user_has_role_assignment($USER->id, $role->id, $this->context->id)) { // See if the user has a role that is linked to an equella role. $shareid = $this->get_option("equella_{$role->shortname}_shareid"); if (!empty($shareid)) { return $this->getssotoken_raw($USER->username, $shareid, $this->get_option("equella_{$role->shortname}_sharedsecret")); } } } } // If we are only reading, use the unadorned shareid and secret. $shareid = $this->get_option('equella_shareid'); if (!empty($shareid)) { return $this->getssotoken_raw($USER->username, $shareid, $this->get_option('equella_sharedsecret')); } }
php
private function getssotoken($readwrite = 'read') { global $USER; if (empty($USER->username)) { return false; } if ($readwrite == 'write') { foreach (self::get_all_editing_roles() as $role) { if (user_has_role_assignment($USER->id, $role->id, $this->context->id)) { // See if the user has a role that is linked to an equella role. $shareid = $this->get_option("equella_{$role->shortname}_shareid"); if (!empty($shareid)) { return $this->getssotoken_raw($USER->username, $shareid, $this->get_option("equella_{$role->shortname}_sharedsecret")); } } } } // If we are only reading, use the unadorned shareid and secret. $shareid = $this->get_option('equella_shareid'); if (!empty($shareid)) { return $this->getssotoken_raw($USER->username, $shareid, $this->get_option('equella_sharedsecret')); } }
[ "private", "function", "getssotoken", "(", "$", "readwrite", "=", "'read'", ")", "{", "global", "$", "USER", ";", "if", "(", "empty", "(", "$", "USER", "->", "username", ")", ")", "{", "return", "false", ";", "}", "if", "(", "$", "readwrite", "==", "'write'", ")", "{", "foreach", "(", "self", "::", "get_all_editing_roles", "(", ")", "as", "$", "role", ")", "{", "if", "(", "user_has_role_assignment", "(", "$", "USER", "->", "id", ",", "$", "role", "->", "id", ",", "$", "this", "->", "context", "->", "id", ")", ")", "{", "// See if the user has a role that is linked to an equella role.", "$", "shareid", "=", "$", "this", "->", "get_option", "(", "\"equella_{$role->shortname}_shareid\"", ")", ";", "if", "(", "!", "empty", "(", "$", "shareid", ")", ")", "{", "return", "$", "this", "->", "getssotoken_raw", "(", "$", "USER", "->", "username", ",", "$", "shareid", ",", "$", "this", "->", "get_option", "(", "\"equella_{$role->shortname}_sharedsecret\"", ")", ")", ";", "}", "}", "}", "}", "// If we are only reading, use the unadorned shareid and secret.", "$", "shareid", "=", "$", "this", "->", "get_option", "(", "'equella_shareid'", ")", ";", "if", "(", "!", "empty", "(", "$", "shareid", ")", ")", "{", "return", "$", "this", "->", "getssotoken_raw", "(", "$", "USER", "->", "username", ",", "$", "shareid", ",", "$", "this", "->", "get_option", "(", "'equella_sharedsecret'", ")", ")", ";", "}", "}" ]
Generate equella sso token @param string $readwrite @return string
[ "Generate", "equella", "sso", "token" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/repository/equella/lib.php#L361-L386
216,975
moodle/moodle
lib/flickrclient.php
flickr_client.set_request_token_secret
public function set_request_token_secret(array $identifiers, $secret) { if (empty($identifiers) || empty($identifiers['caller'])) { throw new coding_exception('Invalid call identification'); } $cache = cache::make_from_params(cache_store::MODE_SESSION, 'core', 'flickrclient', $identifiers); $cache->set('request_token_secret', $secret); }
php
public function set_request_token_secret(array $identifiers, $secret) { if (empty($identifiers) || empty($identifiers['caller'])) { throw new coding_exception('Invalid call identification'); } $cache = cache::make_from_params(cache_store::MODE_SESSION, 'core', 'flickrclient', $identifiers); $cache->set('request_token_secret', $secret); }
[ "public", "function", "set_request_token_secret", "(", "array", "$", "identifiers", ",", "$", "secret", ")", "{", "if", "(", "empty", "(", "$", "identifiers", ")", "||", "empty", "(", "$", "identifiers", "[", "'caller'", "]", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Invalid call identification'", ")", ";", "}", "$", "cache", "=", "cache", "::", "make_from_params", "(", "cache_store", "::", "MODE_SESSION", ",", "'core'", ",", "'flickrclient'", ",", "$", "identifiers", ")", ";", "$", "cache", "->", "set", "(", "'request_token_secret'", ",", "$", "secret", ")", ";", "}" ]
Temporarily store the request token secret in the session. The request token secret is returned by the oauth request_token method. It needs to be stored in the session before the user is redirected to the Flickr to authorize the client. After redirecting back, this secret is used for exchanging the request token with the access token. The identifiers help to avoid collisions between multiple calls to this method from different plugins in the same session. They are used as the session cache identifiers. Provide an associative array identifying the particular method call. At least, the array must contain the 'caller' with the caller's component name. Use additional items if needed. @param array $identifiers Identification of the call @param string $secret
[ "Temporarily", "store", "the", "request", "token", "secret", "in", "the", "session", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/flickrclient.php#L89-L97
216,976
moodle/moodle
lib/flickrclient.php
flickr_client.get_request_token_secret
public function get_request_token_secret(array $identifiers) { if (empty($identifiers) || empty($identifiers['caller'])) { throw new coding_exception('Invalid call identification'); } $cache = cache::make_from_params(cache_store::MODE_SESSION, 'core', 'flickrclient', $identifiers); return $cache->get('request_token_secret'); }
php
public function get_request_token_secret(array $identifiers) { if (empty($identifiers) || empty($identifiers['caller'])) { throw new coding_exception('Invalid call identification'); } $cache = cache::make_from_params(cache_store::MODE_SESSION, 'core', 'flickrclient', $identifiers); return $cache->get('request_token_secret'); }
[ "public", "function", "get_request_token_secret", "(", "array", "$", "identifiers", ")", "{", "if", "(", "empty", "(", "$", "identifiers", ")", "||", "empty", "(", "$", "identifiers", "[", "'caller'", "]", ")", ")", "{", "throw", "new", "coding_exception", "(", "'Invalid call identification'", ")", ";", "}", "$", "cache", "=", "cache", "::", "make_from_params", "(", "cache_store", "::", "MODE_SESSION", ",", "'core'", ",", "'flickrclient'", ",", "$", "identifiers", ")", ";", "return", "$", "cache", "->", "get", "(", "'request_token_secret'", ")", ";", "}" ]
Returns previously stored request token secret. See {@link self::set_request_token_secret()} for more details on the $identifiers argument. @param array $identifiers Identification of the call @return string|bool False on error, string secret otherwise.
[ "Returns", "previously", "stored", "request", "token", "secret", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/flickrclient.php#L108-L117
216,977
moodle/moodle
lib/flickrclient.php
flickr_client.call
public function call($function, array $params = [], $method = 'GET') { if (strpos($function, 'flickr.') !== 0) { $function = 'flickr.'.$function; } $params['method'] = $function; $params['format'] = 'json'; $params['nojsoncallback'] = 1; $rawresponse = $this->request($method, self::REST_ROOT, $params); $response = json_decode($rawresponse); if (!is_object($response) || !isset($response->stat)) { throw new moodle_exception('flickr_api_call_failed', 'core_error', '', $rawresponse); } if ($response->stat === 'ok') { return $response; } else if ($response->stat === 'fail' && $response->code == 98) { // Authentication failure, give the caller a chance to re-authenticate. return false; } else { throw new moodle_exception('flickr_api_call_failed', 'core_error', '', $response); } return $response; }
php
public function call($function, array $params = [], $method = 'GET') { if (strpos($function, 'flickr.') !== 0) { $function = 'flickr.'.$function; } $params['method'] = $function; $params['format'] = 'json'; $params['nojsoncallback'] = 1; $rawresponse = $this->request($method, self::REST_ROOT, $params); $response = json_decode($rawresponse); if (!is_object($response) || !isset($response->stat)) { throw new moodle_exception('flickr_api_call_failed', 'core_error', '', $rawresponse); } if ($response->stat === 'ok') { return $response; } else if ($response->stat === 'fail' && $response->code == 98) { // Authentication failure, give the caller a chance to re-authenticate. return false; } else { throw new moodle_exception('flickr_api_call_failed', 'core_error', '', $response); } return $response; }
[ "public", "function", "call", "(", "$", "function", ",", "array", "$", "params", "=", "[", "]", ",", "$", "method", "=", "'GET'", ")", "{", "if", "(", "strpos", "(", "$", "function", ",", "'flickr.'", ")", "!==", "0", ")", "{", "$", "function", "=", "'flickr.'", ".", "$", "function", ";", "}", "$", "params", "[", "'method'", "]", "=", "$", "function", ";", "$", "params", "[", "'format'", "]", "=", "'json'", ";", "$", "params", "[", "'nojsoncallback'", "]", "=", "1", ";", "$", "rawresponse", "=", "$", "this", "->", "request", "(", "$", "method", ",", "self", "::", "REST_ROOT", ",", "$", "params", ")", ";", "$", "response", "=", "json_decode", "(", "$", "rawresponse", ")", ";", "if", "(", "!", "is_object", "(", "$", "response", ")", "||", "!", "isset", "(", "$", "response", "->", "stat", ")", ")", "{", "throw", "new", "moodle_exception", "(", "'flickr_api_call_failed'", ",", "'core_error'", ",", "''", ",", "$", "rawresponse", ")", ";", "}", "if", "(", "$", "response", "->", "stat", "===", "'ok'", ")", "{", "return", "$", "response", ";", "}", "else", "if", "(", "$", "response", "->", "stat", "===", "'fail'", "&&", "$", "response", "->", "code", "==", "98", ")", "{", "// Authentication failure, give the caller a chance to re-authenticate.", "return", "false", ";", "}", "else", "{", "throw", "new", "moodle_exception", "(", "'flickr_api_call_failed'", ",", "'core_error'", ",", "''", ",", "$", "response", ")", ";", "}", "return", "$", "response", ";", "}" ]
Call a Flickr API method. @param string $function API function name like 'flickr.photos.getSizes' or just 'photos.getSizes' @param array $params Additional API call arguments. @param string $method HTTP method to use (GET or POST). @return object|bool Response as returned by the Flickr or false on invalid authentication
[ "Call", "a", "Flickr", "API", "method", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/flickrclient.php#L127-L156
216,978
moodle/moodle
lib/flickrclient.php
flickr_client.get_photo_url
public function get_photo_url($photoid) { $cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'core', 'flickrclient'); $url = $cache->get('photourl_'.$photoid); if ($url === false) { $response = $this->call('photos.getSizes', ['photo_id' => $photoid]); // Sizes are returned from smallest to greatest. if (!empty($response->sizes->size) && is_array($response->sizes->size)) { while ($bestsize = array_pop($response->sizes->size)) { if (isset($bestsize->source)) { $url = $bestsize->source; break; } } } } if ($url === false) { throw new repository_exception('cannotdownload', 'repository'); } else { $cache->set('photourl_'.$photoid, $url); } return $url; }
php
public function get_photo_url($photoid) { $cache = cache::make_from_params(cache_store::MODE_APPLICATION, 'core', 'flickrclient'); $url = $cache->get('photourl_'.$photoid); if ($url === false) { $response = $this->call('photos.getSizes', ['photo_id' => $photoid]); // Sizes are returned from smallest to greatest. if (!empty($response->sizes->size) && is_array($response->sizes->size)) { while ($bestsize = array_pop($response->sizes->size)) { if (isset($bestsize->source)) { $url = $bestsize->source; break; } } } } if ($url === false) { throw new repository_exception('cannotdownload', 'repository'); } else { $cache->set('photourl_'.$photoid, $url); } return $url; }
[ "public", "function", "get_photo_url", "(", "$", "photoid", ")", "{", "$", "cache", "=", "cache", "::", "make_from_params", "(", "cache_store", "::", "MODE_APPLICATION", ",", "'core'", ",", "'flickrclient'", ")", ";", "$", "url", "=", "$", "cache", "->", "get", "(", "'photourl_'", ".", "$", "photoid", ")", ";", "if", "(", "$", "url", "===", "false", ")", "{", "$", "response", "=", "$", "this", "->", "call", "(", "'photos.getSizes'", ",", "[", "'photo_id'", "=>", "$", "photoid", "]", ")", ";", "// Sizes are returned from smallest to greatest.", "if", "(", "!", "empty", "(", "$", "response", "->", "sizes", "->", "size", ")", "&&", "is_array", "(", "$", "response", "->", "sizes", "->", "size", ")", ")", "{", "while", "(", "$", "bestsize", "=", "array_pop", "(", "$", "response", "->", "sizes", "->", "size", ")", ")", "{", "if", "(", "isset", "(", "$", "bestsize", "->", "source", ")", ")", "{", "$", "url", "=", "$", "bestsize", "->", "source", ";", "break", ";", "}", "}", "}", "}", "if", "(", "$", "url", "===", "false", ")", "{", "throw", "new", "repository_exception", "(", "'cannotdownload'", ",", "'repository'", ")", ";", "}", "else", "{", "$", "cache", "->", "set", "(", "'photourl_'", ".", "$", "photoid", ",", "$", "url", ")", ";", "}", "return", "$", "url", ";", "}" ]
Return the URL to fetch the given photo from. Flickr photos are distributed via farm servers staticflickr.com in various sizes (resolutions). The method tries to find the source URL of the photo in the highest possible resolution. Results are cached so that we do not need to query the Flickr API over and over again. @param string $photoid Flickr photo identifier @return string URL
[ "Return", "the", "URL", "to", "fetch", "the", "given", "photo", "from", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/flickrclient.php#L169-L196
216,979
moodle/moodle
lib/flickrclient.php
flickr_client.upload
public function upload(stored_file $photo, array $meta = []) { $args = [ 'title' => isset($meta['title']) ? $meta['title'] : null, 'description' => isset($meta['description']) ? $meta['description'] : null, 'tags' => isset($meta['tags']) ? $meta['tags'] : null, 'is_public' => isset($meta['is_public']) ? $meta['is_public'] : 0, 'is_friend' => isset($meta['is_friend']) ? $meta['is_friend'] : 0, 'is_family' => isset($meta['is_family']) ? $meta['is_family'] : 0, 'safety_level' => isset($meta['safety_level']) ? $meta['safety_level'] : 1, 'content_type' => isset($meta['content_type']) ? $meta['content_type'] : 1, 'hidden' => isset($meta['hidden']) ? $meta['hidden'] : 2, ]; $this->sign_secret = $this->consumer_secret.'&'.$this->access_token_secret; $params = $this->prepare_oauth_parameters(self::UPLOAD_ROOT, ['oauth_token' => $this->access_token] + $args, 'POST'); $params['photo'] = $photo; $response = $this->http->post(self::UPLOAD_ROOT, $params); if ($response) { $xml = simplexml_load_string($response); if ((string)$xml['stat'] === 'ok') { return (int)$xml->photoid; } else if ((string)$xml['stat'] === 'fail' && (int)$xml->err['code'] == 98) { // Authentication failure. return false; } else { throw new moodle_exception('flickr_upload_failed', 'core_error', '', ['code' => (int)$xml->err['code'], 'message' => (string)$xml->err['msg']]); } } else { throw new moodle_exception('flickr_upload_error', 'core_error', '', null, $response); } }
php
public function upload(stored_file $photo, array $meta = []) { $args = [ 'title' => isset($meta['title']) ? $meta['title'] : null, 'description' => isset($meta['description']) ? $meta['description'] : null, 'tags' => isset($meta['tags']) ? $meta['tags'] : null, 'is_public' => isset($meta['is_public']) ? $meta['is_public'] : 0, 'is_friend' => isset($meta['is_friend']) ? $meta['is_friend'] : 0, 'is_family' => isset($meta['is_family']) ? $meta['is_family'] : 0, 'safety_level' => isset($meta['safety_level']) ? $meta['safety_level'] : 1, 'content_type' => isset($meta['content_type']) ? $meta['content_type'] : 1, 'hidden' => isset($meta['hidden']) ? $meta['hidden'] : 2, ]; $this->sign_secret = $this->consumer_secret.'&'.$this->access_token_secret; $params = $this->prepare_oauth_parameters(self::UPLOAD_ROOT, ['oauth_token' => $this->access_token] + $args, 'POST'); $params['photo'] = $photo; $response = $this->http->post(self::UPLOAD_ROOT, $params); if ($response) { $xml = simplexml_load_string($response); if ((string)$xml['stat'] === 'ok') { return (int)$xml->photoid; } else if ((string)$xml['stat'] === 'fail' && (int)$xml->err['code'] == 98) { // Authentication failure. return false; } else { throw new moodle_exception('flickr_upload_failed', 'core_error', '', ['code' => (int)$xml->err['code'], 'message' => (string)$xml->err['msg']]); } } else { throw new moodle_exception('flickr_upload_error', 'core_error', '', null, $response); } }
[ "public", "function", "upload", "(", "stored_file", "$", "photo", ",", "array", "$", "meta", "=", "[", "]", ")", "{", "$", "args", "=", "[", "'title'", "=>", "isset", "(", "$", "meta", "[", "'title'", "]", ")", "?", "$", "meta", "[", "'title'", "]", ":", "null", ",", "'description'", "=>", "isset", "(", "$", "meta", "[", "'description'", "]", ")", "?", "$", "meta", "[", "'description'", "]", ":", "null", ",", "'tags'", "=>", "isset", "(", "$", "meta", "[", "'tags'", "]", ")", "?", "$", "meta", "[", "'tags'", "]", ":", "null", ",", "'is_public'", "=>", "isset", "(", "$", "meta", "[", "'is_public'", "]", ")", "?", "$", "meta", "[", "'is_public'", "]", ":", "0", ",", "'is_friend'", "=>", "isset", "(", "$", "meta", "[", "'is_friend'", "]", ")", "?", "$", "meta", "[", "'is_friend'", "]", ":", "0", ",", "'is_family'", "=>", "isset", "(", "$", "meta", "[", "'is_family'", "]", ")", "?", "$", "meta", "[", "'is_family'", "]", ":", "0", ",", "'safety_level'", "=>", "isset", "(", "$", "meta", "[", "'safety_level'", "]", ")", "?", "$", "meta", "[", "'safety_level'", "]", ":", "1", ",", "'content_type'", "=>", "isset", "(", "$", "meta", "[", "'content_type'", "]", ")", "?", "$", "meta", "[", "'content_type'", "]", ":", "1", ",", "'hidden'", "=>", "isset", "(", "$", "meta", "[", "'hidden'", "]", ")", "?", "$", "meta", "[", "'hidden'", "]", ":", "2", ",", "]", ";", "$", "this", "->", "sign_secret", "=", "$", "this", "->", "consumer_secret", ".", "'&'", ".", "$", "this", "->", "access_token_secret", ";", "$", "params", "=", "$", "this", "->", "prepare_oauth_parameters", "(", "self", "::", "UPLOAD_ROOT", ",", "[", "'oauth_token'", "=>", "$", "this", "->", "access_token", "]", "+", "$", "args", ",", "'POST'", ")", ";", "$", "params", "[", "'photo'", "]", "=", "$", "photo", ";", "$", "response", "=", "$", "this", "->", "http", "->", "post", "(", "self", "::", "UPLOAD_ROOT", ",", "$", "params", ")", ";", "if", "(", "$", "response", ")", "{", "$", "xml", "=", "simplexml_load_string", "(", "$", "response", ")", ";", "if", "(", "(", "string", ")", "$", "xml", "[", "'stat'", "]", "===", "'ok'", ")", "{", "return", "(", "int", ")", "$", "xml", "->", "photoid", ";", "}", "else", "if", "(", "(", "string", ")", "$", "xml", "[", "'stat'", "]", "===", "'fail'", "&&", "(", "int", ")", "$", "xml", "->", "err", "[", "'code'", "]", "==", "98", ")", "{", "// Authentication failure.", "return", "false", ";", "}", "else", "{", "throw", "new", "moodle_exception", "(", "'flickr_upload_failed'", ",", "'core_error'", ",", "''", ",", "[", "'code'", "=>", "(", "int", ")", "$", "xml", "->", "err", "[", "'code'", "]", ",", "'message'", "=>", "(", "string", ")", "$", "xml", "->", "err", "[", "'msg'", "]", "]", ")", ";", "}", "}", "else", "{", "throw", "new", "moodle_exception", "(", "'flickr_upload_error'", ",", "'core_error'", ",", "''", ",", "null", ",", "$", "response", ")", ";", "}", "}" ]
Upload a photo from Moodle file pool to Flickr. Optional meta information are title, description, tags, is_public, is_friend, is_family, safety_level, content_type and hidden. See {@link https://www.flickr.com/services/api/upload.api.html}. Upload can't be asynchronous because then the query would not return the photo ID which we need to add the photo to a photoset (album) eventually. @param stored_file $photo stored in Moodle file pool @param array $meta optional meta information @return int|bool photo id, false on authentication failure
[ "Upload", "a", "photo", "from", "Moodle", "file", "pool", "to", "Flickr", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/flickrclient.php#L213-L252
216,980
moodle/moodle
enrol/bulkchange_forms.php
enrol_bulk_enrolment_change_form.get_users_table
protected function get_users_table(array $users, array $statusoptions) { $table = new html_table(); $table->head = array( get_string('name'), get_string('participationstatus', 'enrol'), get_string('enroltimestart', 'enrol'), get_string('enroltimeend', 'enrol'), ); $table->data = array(); foreach ($users as $user) { foreach ($user->enrolments as $enrolment) { $input = html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'bulkuser[]', 'value' => $user->id)); $table->data[] = array( fullname($user).$input, $statusoptions[$enrolment->status], (!empty($enrolment->timestart))?userdate($enrolment->timestart):'', (!empty($enrolment->timeend))?userdate($enrolment->timeend):'', ); } } return html_writer::table($table); }
php
protected function get_users_table(array $users, array $statusoptions) { $table = new html_table(); $table->head = array( get_string('name'), get_string('participationstatus', 'enrol'), get_string('enroltimestart', 'enrol'), get_string('enroltimeend', 'enrol'), ); $table->data = array(); foreach ($users as $user) { foreach ($user->enrolments as $enrolment) { $input = html_writer::empty_tag('input', array('type' => 'hidden', 'name' => 'bulkuser[]', 'value' => $user->id)); $table->data[] = array( fullname($user).$input, $statusoptions[$enrolment->status], (!empty($enrolment->timestart))?userdate($enrolment->timestart):'', (!empty($enrolment->timeend))?userdate($enrolment->timeend):'', ); } } return html_writer::table($table); }
[ "protected", "function", "get_users_table", "(", "array", "$", "users", ",", "array", "$", "statusoptions", ")", "{", "$", "table", "=", "new", "html_table", "(", ")", ";", "$", "table", "->", "head", "=", "array", "(", "get_string", "(", "'name'", ")", ",", "get_string", "(", "'participationstatus'", ",", "'enrol'", ")", ",", "get_string", "(", "'enroltimestart'", ",", "'enrol'", ")", ",", "get_string", "(", "'enroltimeend'", ",", "'enrol'", ")", ",", ")", ";", "$", "table", "->", "data", "=", "array", "(", ")", ";", "foreach", "(", "$", "users", "as", "$", "user", ")", "{", "foreach", "(", "$", "user", "->", "enrolments", "as", "$", "enrolment", ")", "{", "$", "input", "=", "html_writer", "::", "empty_tag", "(", "'input'", ",", "array", "(", "'type'", "=>", "'hidden'", ",", "'name'", "=>", "'bulkuser[]'", ",", "'value'", "=>", "$", "user", "->", "id", ")", ")", ";", "$", "table", "->", "data", "[", "]", "=", "array", "(", "fullname", "(", "$", "user", ")", ".", "$", "input", ",", "$", "statusoptions", "[", "$", "enrolment", "->", "status", "]", ",", "(", "!", "empty", "(", "$", "enrolment", "->", "timestart", ")", ")", "?", "userdate", "(", "$", "enrolment", "->", "timestart", ")", ":", "''", ",", "(", "!", "empty", "(", "$", "enrolment", "->", "timeend", ")", ")", "?", "userdate", "(", "$", "enrolment", "->", "timeend", ")", ":", "''", ",", ")", ";", "}", "}", "return", "html_writer", "::", "table", "(", "$", "table", ")", ";", "}" ]
Generates an HTML table to display the users being affected by the bulk change. @param array $users @param array $statusoptions @return string
[ "Generates", "an", "HTML", "table", "to", "display", "the", "users", "being", "affected", "by", "the", "bulk", "change", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/enrol/bulkchange_forms.php#L70-L91
216,981
moodle/moodle
lib/spout/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php
FileSystemHelper.createRootFolder
protected function createRootFolder() { $this->rootFolder = $this->createFolder($this->baseFolderRealPath, uniqid('xlsx', true)); return $this; }
php
protected function createRootFolder() { $this->rootFolder = $this->createFolder($this->baseFolderRealPath, uniqid('xlsx', true)); return $this; }
[ "protected", "function", "createRootFolder", "(", ")", "{", "$", "this", "->", "rootFolder", "=", "$", "this", "->", "createFolder", "(", "$", "this", "->", "baseFolderRealPath", ",", "uniqid", "(", "'xlsx'", ",", "true", ")", ")", ";", "return", "$", "this", ";", "}" ]
Creates the folder that will be used as root @return FileSystemHelper @throws \Box\Spout\Common\Exception\IOException If unable to create the folder
[ "Creates", "the", "folder", "that", "will", "be", "used", "as", "root" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php#L95-L99
216,982
moodle/moodle
lib/spout/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php
FileSystemHelper.createRelsFolderAndFile
protected function createRelsFolderAndFile() { $this->relsFolder = $this->createFolder($this->rootFolder, self::RELS_FOLDER_NAME); $this->createRelsFile(); return $this; }
php
protected function createRelsFolderAndFile() { $this->relsFolder = $this->createFolder($this->rootFolder, self::RELS_FOLDER_NAME); $this->createRelsFile(); return $this; }
[ "protected", "function", "createRelsFolderAndFile", "(", ")", "{", "$", "this", "->", "relsFolder", "=", "$", "this", "->", "createFolder", "(", "$", "this", "->", "rootFolder", ",", "self", "::", "RELS_FOLDER_NAME", ")", ";", "$", "this", "->", "createRelsFile", "(", ")", ";", "return", "$", "this", ";", "}" ]
Creates the "_rels" folder under the root folder as well as the ".rels" file in it @return FileSystemHelper @throws \Box\Spout\Common\Exception\IOException If unable to create the folder or the ".rels" file
[ "Creates", "the", "_rels", "folder", "under", "the", "root", "folder", "as", "well", "as", "the", ".", "rels", "file", "in", "it" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php#L107-L114
216,983
moodle/moodle
lib/spout/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php
FileSystemHelper.createDocPropsFolderAndFiles
protected function createDocPropsFolderAndFiles() { $this->docPropsFolder = $this->createFolder($this->rootFolder, self::DOC_PROPS_FOLDER_NAME); $this->createAppXmlFile(); $this->createCoreXmlFile(); return $this; }
php
protected function createDocPropsFolderAndFiles() { $this->docPropsFolder = $this->createFolder($this->rootFolder, self::DOC_PROPS_FOLDER_NAME); $this->createAppXmlFile(); $this->createCoreXmlFile(); return $this; }
[ "protected", "function", "createDocPropsFolderAndFiles", "(", ")", "{", "$", "this", "->", "docPropsFolder", "=", "$", "this", "->", "createFolder", "(", "$", "this", "->", "rootFolder", ",", "self", "::", "DOC_PROPS_FOLDER_NAME", ")", ";", "$", "this", "->", "createAppXmlFile", "(", ")", ";", "$", "this", "->", "createCoreXmlFile", "(", ")", ";", "return", "$", "this", ";", "}" ]
Creates the "docProps" folder under the root folder as well as the "app.xml" and "core.xml" files in it @return FileSystemHelper @throws \Box\Spout\Common\Exception\IOException If unable to create the folder or one of the files
[ "Creates", "the", "docProps", "folder", "under", "the", "root", "folder", "as", "well", "as", "the", "app", ".", "xml", "and", "core", ".", "xml", "files", "in", "it" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php#L144-L152
216,984
moodle/moodle
lib/spout/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php
FileSystemHelper.createAppXmlFile
protected function createAppXmlFile() { $appName = self::APP_NAME; $appXmlFileContents = <<<EOD <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"> <Application>$appName</Application> <TotalTime>0</TotalTime> </Properties> EOD; $this->createFileWithContents($this->docPropsFolder, self::APP_XML_FILE_NAME, $appXmlFileContents); return $this; }
php
protected function createAppXmlFile() { $appName = self::APP_NAME; $appXmlFileContents = <<<EOD <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties"> <Application>$appName</Application> <TotalTime>0</TotalTime> </Properties> EOD; $this->createFileWithContents($this->docPropsFolder, self::APP_XML_FILE_NAME, $appXmlFileContents); return $this; }
[ "protected", "function", "createAppXmlFile", "(", ")", "{", "$", "appName", "=", "self", "::", "APP_NAME", ";", "$", "appXmlFileContents", "=", " <<<EOD\n<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<Properties xmlns=\"http://schemas.openxmlformats.org/officeDocument/2006/extended-properties\">\n <Application>$appName</Application>\n <TotalTime>0</TotalTime>\n</Properties>\nEOD", ";", "$", "this", "->", "createFileWithContents", "(", "$", "this", "->", "docPropsFolder", ",", "self", "::", "APP_XML_FILE_NAME", ",", "$", "appXmlFileContents", ")", ";", "return", "$", "this", ";", "}" ]
Creates the "app.xml" file under the "docProps" folder @return FileSystemHelper @throws \Box\Spout\Common\Exception\IOException If unable to create the file
[ "Creates", "the", "app", ".", "xml", "file", "under", "the", "docProps", "folder" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php#L160-L174
216,985
moodle/moodle
lib/spout/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php
FileSystemHelper.createCoreXmlFile
protected function createCoreXmlFile() { $createdDate = (new \DateTime())->format(\DateTime::W3C); $coreXmlFileContents = <<<EOD <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <dcterms:created xsi:type="dcterms:W3CDTF">$createdDate</dcterms:created> <dcterms:modified xsi:type="dcterms:W3CDTF">$createdDate</dcterms:modified> <cp:revision>0</cp:revision> </cp:coreProperties> EOD; $this->createFileWithContents($this->docPropsFolder, self::CORE_XML_FILE_NAME, $coreXmlFileContents); return $this; }
php
protected function createCoreXmlFile() { $createdDate = (new \DateTime())->format(\DateTime::W3C); $coreXmlFileContents = <<<EOD <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <cp:coreProperties xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcmitype="http://purl.org/dc/dcmitype/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <dcterms:created xsi:type="dcterms:W3CDTF">$createdDate</dcterms:created> <dcterms:modified xsi:type="dcterms:W3CDTF">$createdDate</dcterms:modified> <cp:revision>0</cp:revision> </cp:coreProperties> EOD; $this->createFileWithContents($this->docPropsFolder, self::CORE_XML_FILE_NAME, $coreXmlFileContents); return $this; }
[ "protected", "function", "createCoreXmlFile", "(", ")", "{", "$", "createdDate", "=", "(", "new", "\\", "DateTime", "(", ")", ")", "->", "format", "(", "\\", "DateTime", "::", "W3C", ")", ";", "$", "coreXmlFileContents", "=", " <<<EOD\n<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<cp:coreProperties xmlns:cp=\"http://schemas.openxmlformats.org/package/2006/metadata/core-properties\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:dcmitype=\"http://purl.org/dc/dcmitype/\" xmlns:dcterms=\"http://purl.org/dc/terms/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n <dcterms:created xsi:type=\"dcterms:W3CDTF\">$createdDate</dcterms:created>\n <dcterms:modified xsi:type=\"dcterms:W3CDTF\">$createdDate</dcterms:modified>\n <cp:revision>0</cp:revision>\n</cp:coreProperties>\nEOD", ";", "$", "this", "->", "createFileWithContents", "(", "$", "this", "->", "docPropsFolder", ",", "self", "::", "CORE_XML_FILE_NAME", ",", "$", "coreXmlFileContents", ")", ";", "return", "$", "this", ";", "}" ]
Creates the "core.xml" file under the "docProps" folder @return FileSystemHelper @throws \Box\Spout\Common\Exception\IOException If unable to create the file
[ "Creates", "the", "core", ".", "xml", "file", "under", "the", "docProps", "folder" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php#L182-L197
216,986
moodle/moodle
lib/spout/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php
FileSystemHelper.createXlFolderAndSubFolders
protected function createXlFolderAndSubFolders() { $this->xlFolder = $this->createFolder($this->rootFolder, self::XL_FOLDER_NAME); $this->createXlRelsFolder(); $this->createXlWorksheetsFolder(); return $this; }
php
protected function createXlFolderAndSubFolders() { $this->xlFolder = $this->createFolder($this->rootFolder, self::XL_FOLDER_NAME); $this->createXlRelsFolder(); $this->createXlWorksheetsFolder(); return $this; }
[ "protected", "function", "createXlFolderAndSubFolders", "(", ")", "{", "$", "this", "->", "xlFolder", "=", "$", "this", "->", "createFolder", "(", "$", "this", "->", "rootFolder", ",", "self", "::", "XL_FOLDER_NAME", ")", ";", "$", "this", "->", "createXlRelsFolder", "(", ")", ";", "$", "this", "->", "createXlWorksheetsFolder", "(", ")", ";", "return", "$", "this", ";", "}" ]
Creates the "xl" folder under the root folder as well as its subfolders @return FileSystemHelper @throws \Box\Spout\Common\Exception\IOException If unable to create at least one of the folders
[ "Creates", "the", "xl", "folder", "under", "the", "root", "folder", "as", "well", "as", "its", "subfolders" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php#L205-L212
216,987
moodle/moodle
lib/spout/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php
FileSystemHelper.createXlRelsFolder
protected function createXlRelsFolder() { $this->xlRelsFolder = $this->createFolder($this->xlFolder, self::RELS_FOLDER_NAME); return $this; }
php
protected function createXlRelsFolder() { $this->xlRelsFolder = $this->createFolder($this->xlFolder, self::RELS_FOLDER_NAME); return $this; }
[ "protected", "function", "createXlRelsFolder", "(", ")", "{", "$", "this", "->", "xlRelsFolder", "=", "$", "this", "->", "createFolder", "(", "$", "this", "->", "xlFolder", ",", "self", "::", "RELS_FOLDER_NAME", ")", ";", "return", "$", "this", ";", "}" ]
Creates the "_rels" folder under the "xl" folder @return FileSystemHelper @throws \Box\Spout\Common\Exception\IOException If unable to create the folder
[ "Creates", "the", "_rels", "folder", "under", "the", "xl", "folder" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php#L220-L224
216,988
moodle/moodle
lib/spout/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php
FileSystemHelper.createXlWorksheetsFolder
protected function createXlWorksheetsFolder() { $this->xlWorksheetsFolder = $this->createFolder($this->xlFolder, self::WORKSHEETS_FOLDER_NAME); return $this; }
php
protected function createXlWorksheetsFolder() { $this->xlWorksheetsFolder = $this->createFolder($this->xlFolder, self::WORKSHEETS_FOLDER_NAME); return $this; }
[ "protected", "function", "createXlWorksheetsFolder", "(", ")", "{", "$", "this", "->", "xlWorksheetsFolder", "=", "$", "this", "->", "createFolder", "(", "$", "this", "->", "xlFolder", ",", "self", "::", "WORKSHEETS_FOLDER_NAME", ")", ";", "return", "$", "this", ";", "}" ]
Creates the "worksheets" folder under the "xl" folder @return FileSystemHelper @throws \Box\Spout\Common\Exception\IOException If unable to create the folder
[ "Creates", "the", "worksheets", "folder", "under", "the", "xl", "folder" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php#L232-L236
216,989
moodle/moodle
lib/spout/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php
FileSystemHelper.createWorkbookFile
public function createWorkbookFile($worksheets) { $workbookXmlFileContents = <<<EOD <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"> <sheets> EOD; /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */ $escaper = \Box\Spout\Common\Escaper\XLSX::getInstance(); /** @var Worksheet $worksheet */ foreach ($worksheets as $worksheet) { $worksheetName = $worksheet->getExternalSheet()->getName(); $worksheetId = $worksheet->getId(); $workbookXmlFileContents .= '<sheet name="' . $escaper->escape($worksheetName) . '" sheetId="' . $worksheetId . '" r:id="rIdSheet' . $worksheetId . '"/>'; } $workbookXmlFileContents .= <<<EOD </sheets> </workbook> EOD; $this->createFileWithContents($this->xlFolder, self::WORKBOOK_XML_FILE_NAME, $workbookXmlFileContents); return $this; }
php
public function createWorkbookFile($worksheets) { $workbookXmlFileContents = <<<EOD <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"> <sheets> EOD; /** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */ $escaper = \Box\Spout\Common\Escaper\XLSX::getInstance(); /** @var Worksheet $worksheet */ foreach ($worksheets as $worksheet) { $worksheetName = $worksheet->getExternalSheet()->getName(); $worksheetId = $worksheet->getId(); $workbookXmlFileContents .= '<sheet name="' . $escaper->escape($worksheetName) . '" sheetId="' . $worksheetId . '" r:id="rIdSheet' . $worksheetId . '"/>'; } $workbookXmlFileContents .= <<<EOD </sheets> </workbook> EOD; $this->createFileWithContents($this->xlFolder, self::WORKBOOK_XML_FILE_NAME, $workbookXmlFileContents); return $this; }
[ "public", "function", "createWorkbookFile", "(", "$", "worksheets", ")", "{", "$", "workbookXmlFileContents", "=", " <<<EOD\n<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n<workbook xmlns=\"http://schemas.openxmlformats.org/spreadsheetml/2006/main\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\">\n <sheets>\nEOD", ";", "/** @noinspection PhpUnnecessaryFullyQualifiedNameInspection */", "$", "escaper", "=", "\\", "Box", "\\", "Spout", "\\", "Common", "\\", "Escaper", "\\", "XLSX", "::", "getInstance", "(", ")", ";", "/** @var Worksheet $worksheet */", "foreach", "(", "$", "worksheets", "as", "$", "worksheet", ")", "{", "$", "worksheetName", "=", "$", "worksheet", "->", "getExternalSheet", "(", ")", "->", "getName", "(", ")", ";", "$", "worksheetId", "=", "$", "worksheet", "->", "getId", "(", ")", ";", "$", "workbookXmlFileContents", ".=", "'<sheet name=\"'", ".", "$", "escaper", "->", "escape", "(", "$", "worksheetName", ")", ".", "'\" sheetId=\"'", ".", "$", "worksheetId", ".", "'\" r:id=\"rIdSheet'", ".", "$", "worksheetId", ".", "'\"/>'", ";", "}", "$", "workbookXmlFileContents", ".=", " <<<EOD\n </sheets>\n</workbook>\nEOD", ";", "$", "this", "->", "createFileWithContents", "(", "$", "this", "->", "xlFolder", ",", "self", "::", "WORKBOOK_XML_FILE_NAME", ",", "$", "workbookXmlFileContents", ")", ";", "return", "$", "this", ";", "}" ]
Creates the "workbook.xml" file under the "xl" folder @param Worksheet[] $worksheets @return FileSystemHelper
[ "Creates", "the", "workbook", ".", "xml", "file", "under", "the", "xl", "folder" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php#L278-L304
216,990
moodle/moodle
lib/spout/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php
FileSystemHelper.createStylesFile
public function createStylesFile($styleHelper) { $stylesXmlFileContents = $styleHelper->getStylesXMLFileContent(); $this->createFileWithContents($this->xlFolder, self::STYLES_XML_FILE_NAME, $stylesXmlFileContents); return $this; }
php
public function createStylesFile($styleHelper) { $stylesXmlFileContents = $styleHelper->getStylesXMLFileContent(); $this->createFileWithContents($this->xlFolder, self::STYLES_XML_FILE_NAME, $stylesXmlFileContents); return $this; }
[ "public", "function", "createStylesFile", "(", "$", "styleHelper", ")", "{", "$", "stylesXmlFileContents", "=", "$", "styleHelper", "->", "getStylesXMLFileContent", "(", ")", ";", "$", "this", "->", "createFileWithContents", "(", "$", "this", "->", "xlFolder", ",", "self", "::", "STYLES_XML_FILE_NAME", ",", "$", "stylesXmlFileContents", ")", ";", "return", "$", "this", ";", "}" ]
Creates the "styles.xml" file under the "xl" folder @param StyleHelper $styleHelper @return FileSystemHelper
[ "Creates", "the", "styles", ".", "xml", "file", "under", "the", "xl", "folder" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/spout/src/Spout/Writer/XLSX/Helper/FileSystemHelper.php#L340-L346
216,991
moodle/moodle
backup/util/ui/backup_ui_setting.class.php
backup_setting_ui.make
final public static function make(backup_setting $setting, $type, $label, array $attributes = null, array $options = null) { // Base the decision we make on the type that was sent. switch ($type) { case backup_setting::UI_HTML_CHECKBOX : return new backup_setting_ui_checkbox($setting, $label, null, (array)$attributes, (array)$options); case backup_setting::UI_HTML_DROPDOWN : return new backup_setting_ui_select($setting, $label, null, (array)$attributes, (array)$options); case backup_setting::UI_HTML_RADIOBUTTON : return new backup_setting_ui_radio($setting, $label, null, null, (array)$attributes, (array)$options); case backup_setting::UI_HTML_TEXTFIELD : return new backup_setting_ui_text($setting, $label, $attributes, $options); default: throw new backup_setting_ui_exception('setting_invalid_ui_type'); } }
php
final public static function make(backup_setting $setting, $type, $label, array $attributes = null, array $options = null) { // Base the decision we make on the type that was sent. switch ($type) { case backup_setting::UI_HTML_CHECKBOX : return new backup_setting_ui_checkbox($setting, $label, null, (array)$attributes, (array)$options); case backup_setting::UI_HTML_DROPDOWN : return new backup_setting_ui_select($setting, $label, null, (array)$attributes, (array)$options); case backup_setting::UI_HTML_RADIOBUTTON : return new backup_setting_ui_radio($setting, $label, null, null, (array)$attributes, (array)$options); case backup_setting::UI_HTML_TEXTFIELD : return new backup_setting_ui_text($setting, $label, $attributes, $options); default: throw new backup_setting_ui_exception('setting_invalid_ui_type'); } }
[ "final", "public", "static", "function", "make", "(", "backup_setting", "$", "setting", ",", "$", "type", ",", "$", "label", ",", "array", "$", "attributes", "=", "null", ",", "array", "$", "options", "=", "null", ")", "{", "// Base the decision we make on the type that was sent.", "switch", "(", "$", "type", ")", "{", "case", "backup_setting", "::", "UI_HTML_CHECKBOX", ":", "return", "new", "backup_setting_ui_checkbox", "(", "$", "setting", ",", "$", "label", ",", "null", ",", "(", "array", ")", "$", "attributes", ",", "(", "array", ")", "$", "options", ")", ";", "case", "backup_setting", "::", "UI_HTML_DROPDOWN", ":", "return", "new", "backup_setting_ui_select", "(", "$", "setting", ",", "$", "label", ",", "null", ",", "(", "array", ")", "$", "attributes", ",", "(", "array", ")", "$", "options", ")", ";", "case", "backup_setting", "::", "UI_HTML_RADIOBUTTON", ":", "return", "new", "backup_setting_ui_radio", "(", "$", "setting", ",", "$", "label", ",", "null", ",", "null", ",", "(", "array", ")", "$", "attributes", ",", "(", "array", ")", "$", "options", ")", ";", "case", "backup_setting", "::", "UI_HTML_TEXTFIELD", ":", "return", "new", "backup_setting_ui_text", "(", "$", "setting", ",", "$", "label", ",", "$", "attributes", ",", "$", "options", ")", ";", "default", ":", "throw", "new", "backup_setting_ui_exception", "(", "'setting_invalid_ui_type'", ")", ";", "}", "}" ]
Creates a new backup setting ui based on the setting it is given @throws backup_setting_ui_exception if the setting type is not supported, @param backup_setting $setting @param int $type The backup_setting UI type. One of backup_setting::UI_*; @param string $label The label to display with the setting ui @param array $attributes Array of HTML attributes to apply to the element @param array $options Array of options to apply to the setting ui object @return backup_setting_ui_text|backup_setting_ui_checkbox|backup_setting_ui_select|backup_setting_ui_radio
[ "Creates", "a", "new", "backup", "setting", "ui", "based", "on", "the", "setting", "it", "is", "given" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/backup_ui_setting.class.php#L245-L259
216,992
moodle/moodle
backup/util/ui/backup_ui_setting.class.php
backup_setting_ui.get_label
public function get_label(base_task $task = null) { // If a task has been provided and the label is not already set meaningfully // we will attempt to improve it. if (!is_null($task) && $this->label == $this->setting->get_name() && strpos($this->setting->get_name(), '_include') !== false) { if ($this->setting->get_level() == backup_setting::SECTION_LEVEL) { $this->label = get_string('includesection', 'backup', $task->get_name()); } else if ($this->setting->get_level() == backup_setting::ACTIVITY_LEVEL) { $this->label = $task->get_name(); } } return $this->label; }
php
public function get_label(base_task $task = null) { // If a task has been provided and the label is not already set meaningfully // we will attempt to improve it. if (!is_null($task) && $this->label == $this->setting->get_name() && strpos($this->setting->get_name(), '_include') !== false) { if ($this->setting->get_level() == backup_setting::SECTION_LEVEL) { $this->label = get_string('includesection', 'backup', $task->get_name()); } else if ($this->setting->get_level() == backup_setting::ACTIVITY_LEVEL) { $this->label = $task->get_name(); } } return $this->label; }
[ "public", "function", "get_label", "(", "base_task", "$", "task", "=", "null", ")", "{", "// If a task has been provided and the label is not already set meaningfully", "// we will attempt to improve it.", "if", "(", "!", "is_null", "(", "$", "task", ")", "&&", "$", "this", "->", "label", "==", "$", "this", "->", "setting", "->", "get_name", "(", ")", "&&", "strpos", "(", "$", "this", "->", "setting", "->", "get_name", "(", ")", ",", "'_include'", ")", "!==", "false", ")", "{", "if", "(", "$", "this", "->", "setting", "->", "get_level", "(", ")", "==", "backup_setting", "::", "SECTION_LEVEL", ")", "{", "$", "this", "->", "label", "=", "get_string", "(", "'includesection'", ",", "'backup'", ",", "$", "task", "->", "get_name", "(", ")", ")", ";", "}", "else", "if", "(", "$", "this", "->", "setting", "->", "get_level", "(", ")", "==", "backup_setting", "::", "ACTIVITY_LEVEL", ")", "{", "$", "this", "->", "label", "=", "$", "task", "->", "get_name", "(", ")", ";", "}", "}", "return", "$", "this", "->", "label", ";", "}" ]
Gets the label for this item @param base_task $task Optional, if provided and the setting is an include $task is used to set the setting label @return string
[ "Gets", "the", "label", "for", "this", "item" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/backup_ui_setting.class.php#L288-L299
216,993
moodle/moodle
backup/util/ui/backup_ui_setting.class.php
backup_setting_ui.is_changeable
public function is_changeable($level = null) { if ($this->setting->get_status() === backup_setting::NOT_LOCKED) { // Its not locked so its chanegable. return true; } else if ($this->setting->get_status() !== backup_setting::LOCKED_BY_HIERARCHY) { // Its not changeable because its locked by permission or config. return false; } else if ($this->setting->has_dependencies_on_settings()) { foreach ($this->setting->get_settings_depended_on() as $dependency) { if ($level && $dependency->get_setting()->get_level() >= $level) { continue; } if ($dependency->is_locked() && $dependency->get_setting()->get_level() !== $this->setting->get_level()) { // Its not changeable because one or more dependancies arn't changeable. return false; } } // Its changeable because all dependencies are changeable. return true; } // We should never get here but if we do return false to be safe. // The setting would need to be locked by hierarchy and not have any deps. return false; }
php
public function is_changeable($level = null) { if ($this->setting->get_status() === backup_setting::NOT_LOCKED) { // Its not locked so its chanegable. return true; } else if ($this->setting->get_status() !== backup_setting::LOCKED_BY_HIERARCHY) { // Its not changeable because its locked by permission or config. return false; } else if ($this->setting->has_dependencies_on_settings()) { foreach ($this->setting->get_settings_depended_on() as $dependency) { if ($level && $dependency->get_setting()->get_level() >= $level) { continue; } if ($dependency->is_locked() && $dependency->get_setting()->get_level() !== $this->setting->get_level()) { // Its not changeable because one or more dependancies arn't changeable. return false; } } // Its changeable because all dependencies are changeable. return true; } // We should never get here but if we do return false to be safe. // The setting would need to be locked by hierarchy and not have any deps. return false; }
[ "public", "function", "is_changeable", "(", "$", "level", "=", "null", ")", "{", "if", "(", "$", "this", "->", "setting", "->", "get_status", "(", ")", "===", "backup_setting", "::", "NOT_LOCKED", ")", "{", "// Its not locked so its chanegable.", "return", "true", ";", "}", "else", "if", "(", "$", "this", "->", "setting", "->", "get_status", "(", ")", "!==", "backup_setting", "::", "LOCKED_BY_HIERARCHY", ")", "{", "// Its not changeable because its locked by permission or config.", "return", "false", ";", "}", "else", "if", "(", "$", "this", "->", "setting", "->", "has_dependencies_on_settings", "(", ")", ")", "{", "foreach", "(", "$", "this", "->", "setting", "->", "get_settings_depended_on", "(", ")", "as", "$", "dependency", ")", "{", "if", "(", "$", "level", "&&", "$", "dependency", "->", "get_setting", "(", ")", "->", "get_level", "(", ")", ">=", "$", "level", ")", "{", "continue", ";", "}", "if", "(", "$", "dependency", "->", "is_locked", "(", ")", "&&", "$", "dependency", "->", "get_setting", "(", ")", "->", "get_level", "(", ")", "!==", "$", "this", "->", "setting", "->", "get_level", "(", ")", ")", "{", "// Its not changeable because one or more dependancies arn't changeable.", "return", "false", ";", "}", "}", "// Its changeable because all dependencies are changeable.", "return", "true", ";", "}", "// We should never get here but if we do return false to be safe.", "// The setting would need to be locked by hierarchy and not have any deps.", "return", "false", ";", "}" ]
Returns true if the setting is changeable. A setting is changeable if it meets either of the two following conditions. 1. The setting is not locked 2. The setting is locked but only by settings that are of the same level (same page) Condition 2 is really why we have this function @param int $level Optional, if provided only depedency_settings below or equal to this level are considered, when checking if the ui_setting is changeable. Although dependencies might cause a lock on this setting, they could be changeable in the same view. @return bool
[ "Returns", "true", "if", "the", "setting", "is", "changeable", "." ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/backup_ui_setting.class.php#L315-L338
216,994
moodle/moodle
backup/util/ui/backup_ui_setting.class.php
backup_setting_ui_checkbox.get_static_value
public function get_static_value() { global $OUTPUT; // Checkboxes are always yes or no. if ($this->get_value()) { return $OUTPUT->pix_icon('i/valid', get_string('yes')); } else { return $OUTPUT->pix_icon('i/invalid', get_string('no')); } }
php
public function get_static_value() { global $OUTPUT; // Checkboxes are always yes or no. if ($this->get_value()) { return $OUTPUT->pix_icon('i/valid', get_string('yes')); } else { return $OUTPUT->pix_icon('i/invalid', get_string('no')); } }
[ "public", "function", "get_static_value", "(", ")", "{", "global", "$", "OUTPUT", ";", "// Checkboxes are always yes or no.", "if", "(", "$", "this", "->", "get_value", "(", ")", ")", "{", "return", "$", "OUTPUT", "->", "pix_icon", "(", "'i/valid'", ",", "get_string", "(", "'yes'", ")", ")", ";", "}", "else", "{", "return", "$", "OUTPUT", "->", "pix_icon", "(", "'i/invalid'", ",", "get_string", "(", "'no'", ")", ")", ";", "}", "}" ]
Gets the static value for the element @global core_renderer $OUTPUT @return string
[ "Gets", "the", "static", "value", "for", "the", "element" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/backup_ui_setting.class.php#L454-L462
216,995
moodle/moodle
backup/util/ui/backup_ui_setting.class.php
backup_setting_ui_checkbox.is_changeable
public function is_changeable($level = null) { if ($this->changeable === false) { return false; } else { return parent::is_changeable($level); } }
php
public function is_changeable($level = null) { if ($this->changeable === false) { return false; } else { return parent::is_changeable($level); } }
[ "public", "function", "is_changeable", "(", "$", "level", "=", "null", ")", "{", "if", "(", "$", "this", "->", "changeable", "===", "false", ")", "{", "return", "false", ";", "}", "else", "{", "return", "parent", "::", "is_changeable", "(", "$", "level", ")", ";", "}", "}" ]
Returns true if the setting is changeable @param int $level Optional, if provided only depedency_settings below or equal to this level are considered, when checking if the ui_setting is changeable. Although dependencies might cause a lock on this setting, they could be changeable in the same view. @return bool
[ "Returns", "true", "if", "the", "setting", "is", "changeable" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/backup_ui_setting.class.php#L471-L477
216,996
moodle/moodle
backup/util/ui/backup_ui_setting.class.php
backup_setting_ui_select.is_changeable
public function is_changeable($level = null) { if (count($this->values) == 1) { return false; } else { return parent::is_changeable($level); } }
php
public function is_changeable($level = null) { if (count($this->values) == 1) { return false; } else { return parent::is_changeable($level); } }
[ "public", "function", "is_changeable", "(", "$", "level", "=", "null", ")", "{", "if", "(", "count", "(", "$", "this", "->", "values", ")", "==", "1", ")", "{", "return", "false", ";", "}", "else", "{", "return", "parent", "::", "is_changeable", "(", "$", "level", ")", ";", "}", "}" ]
Returns true if the setting is changeable, false otherwise @param int $level Optional, if provided only depedency_settings below or equal to this level are considered, when checking if the ui_setting is changeable. Although dependencies might cause a lock on this setting, they could be changeable in the same view. @return bool
[ "Returns", "true", "if", "the", "setting", "is", "changeable", "false", "otherwise" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/backup/util/ui/backup_ui_setting.class.php#L655-L661
216,997
moodle/moodle
lib/jabber/XMPP/XMLStream.php
XMPPHP_XMLStream.addIdHandler
public function addIdHandler($id, $pointer, $obj = null) { $this->idhandlers[$id] = array($pointer, $obj); }
php
public function addIdHandler($id, $pointer, $obj = null) { $this->idhandlers[$id] = array($pointer, $obj); }
[ "public", "function", "addIdHandler", "(", "$", "id", ",", "$", "pointer", ",", "$", "obj", "=", "null", ")", "{", "$", "this", "->", "idhandlers", "[", "$", "id", "]", "=", "array", "(", "$", "pointer", ",", "$", "obj", ")", ";", "}" ]
Add ID Handler @param integer $id @param string $pointer @param string $obj
[ "Add", "ID", "Handler" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/jabber/XMPP/XMLStream.php#L234-L236
216,998
moodle/moodle
lib/jabber/XMPP/XMLStream.php
XMPPHP_XMLStream.disconnect
public function disconnect() { $this->log->log("Disconnecting...", XMPPHP_Log::LEVEL_VERBOSE); if(false == (bool) $this->socket) { return; } $this->reconnect = false; $this->send($this->stream_end); $this->sent_disconnect = true; $this->processUntil('end_stream', 5); $this->disconnected = true; }
php
public function disconnect() { $this->log->log("Disconnecting...", XMPPHP_Log::LEVEL_VERBOSE); if(false == (bool) $this->socket) { return; } $this->reconnect = false; $this->send($this->stream_end); $this->sent_disconnect = true; $this->processUntil('end_stream', 5); $this->disconnected = true; }
[ "public", "function", "disconnect", "(", ")", "{", "$", "this", "->", "log", "->", "log", "(", "\"Disconnecting...\"", ",", "XMPPHP_Log", "::", "LEVEL_VERBOSE", ")", ";", "if", "(", "false", "==", "(", "bool", ")", "$", "this", "->", "socket", ")", "{", "return", ";", "}", "$", "this", "->", "reconnect", "=", "false", ";", "$", "this", "->", "send", "(", "$", "this", "->", "stream_end", ")", ";", "$", "this", "->", "sent_disconnect", "=", "true", ";", "$", "this", "->", "processUntil", "(", "'end_stream'", ",", "5", ")", ";", "$", "this", "->", "disconnected", "=", "true", ";", "}" ]
Disconnect from XMPP Host
[ "Disconnect", "from", "XMPP", "Host" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/jabber/XMPP/XMLStream.php#L350-L360
216,999
moodle/moodle
lib/jabber/XMPP/XMLStream.php
XMPPHP_XMLStream.__process
private function __process($maximum=5) { $remaining = $maximum; do { $starttime = (microtime(true) * 1000000); $read = array($this->socket); $write = array(); $except = array(); if (is_null($maximum)) { $secs = NULL; $usecs = NULL; } else if ($maximum == 0) { $secs = 0; $usecs = 0; } else { $usecs = $remaining % 1000000; $secs = floor(($remaining - $usecs) / 1000000); } $updated = @stream_select($read, $write, $except, $secs, $usecs); if ($updated === false) { $this->log->log("Error on stream_select()", XMPPHP_Log::LEVEL_VERBOSE); if ($this->reconnect) { $this->doReconnect(); } else { fclose($this->socket); $this->socket = NULL; return false; } } else if ($updated > 0) { # XXX: Is this big enough? $buff = @fread($this->socket, 4096); if(!$buff) { if($this->reconnect) { $this->doReconnect(); } else { fclose($this->socket); $this->socket = NULL; return false; } } $this->log->log("RECV: $buff", XMPPHP_Log::LEVEL_VERBOSE); xml_parse($this->parser, $buff, false); } else { # $updated == 0 means no changes during timeout. } $endtime = (microtime(true)*1000000); $time_past = $endtime - $starttime; $remaining = $remaining - $time_past; } while (is_null($maximum) || $remaining > 0); return true; }
php
private function __process($maximum=5) { $remaining = $maximum; do { $starttime = (microtime(true) * 1000000); $read = array($this->socket); $write = array(); $except = array(); if (is_null($maximum)) { $secs = NULL; $usecs = NULL; } else if ($maximum == 0) { $secs = 0; $usecs = 0; } else { $usecs = $remaining % 1000000; $secs = floor(($remaining - $usecs) / 1000000); } $updated = @stream_select($read, $write, $except, $secs, $usecs); if ($updated === false) { $this->log->log("Error on stream_select()", XMPPHP_Log::LEVEL_VERBOSE); if ($this->reconnect) { $this->doReconnect(); } else { fclose($this->socket); $this->socket = NULL; return false; } } else if ($updated > 0) { # XXX: Is this big enough? $buff = @fread($this->socket, 4096); if(!$buff) { if($this->reconnect) { $this->doReconnect(); } else { fclose($this->socket); $this->socket = NULL; return false; } } $this->log->log("RECV: $buff", XMPPHP_Log::LEVEL_VERBOSE); xml_parse($this->parser, $buff, false); } else { # $updated == 0 means no changes during timeout. } $endtime = (microtime(true)*1000000); $time_past = $endtime - $starttime; $remaining = $remaining - $time_past; } while (is_null($maximum) || $remaining > 0); return true; }
[ "private", "function", "__process", "(", "$", "maximum", "=", "5", ")", "{", "$", "remaining", "=", "$", "maximum", ";", "do", "{", "$", "starttime", "=", "(", "microtime", "(", "true", ")", "*", "1000000", ")", ";", "$", "read", "=", "array", "(", "$", "this", "->", "socket", ")", ";", "$", "write", "=", "array", "(", ")", ";", "$", "except", "=", "array", "(", ")", ";", "if", "(", "is_null", "(", "$", "maximum", ")", ")", "{", "$", "secs", "=", "NULL", ";", "$", "usecs", "=", "NULL", ";", "}", "else", "if", "(", "$", "maximum", "==", "0", ")", "{", "$", "secs", "=", "0", ";", "$", "usecs", "=", "0", ";", "}", "else", "{", "$", "usecs", "=", "$", "remaining", "%", "1000000", ";", "$", "secs", "=", "floor", "(", "(", "$", "remaining", "-", "$", "usecs", ")", "/", "1000000", ")", ";", "}", "$", "updated", "=", "@", "stream_select", "(", "$", "read", ",", "$", "write", ",", "$", "except", ",", "$", "secs", ",", "$", "usecs", ")", ";", "if", "(", "$", "updated", "===", "false", ")", "{", "$", "this", "->", "log", "->", "log", "(", "\"Error on stream_select()\"", ",", "XMPPHP_Log", "::", "LEVEL_VERBOSE", ")", ";", "if", "(", "$", "this", "->", "reconnect", ")", "{", "$", "this", "->", "doReconnect", "(", ")", ";", "}", "else", "{", "fclose", "(", "$", "this", "->", "socket", ")", ";", "$", "this", "->", "socket", "=", "NULL", ";", "return", "false", ";", "}", "}", "else", "if", "(", "$", "updated", ">", "0", ")", "{", "# XXX: Is this big enough?", "$", "buff", "=", "@", "fread", "(", "$", "this", "->", "socket", ",", "4096", ")", ";", "if", "(", "!", "$", "buff", ")", "{", "if", "(", "$", "this", "->", "reconnect", ")", "{", "$", "this", "->", "doReconnect", "(", ")", ";", "}", "else", "{", "fclose", "(", "$", "this", "->", "socket", ")", ";", "$", "this", "->", "socket", "=", "NULL", ";", "return", "false", ";", "}", "}", "$", "this", "->", "log", "->", "log", "(", "\"RECV: $buff\"", ",", "XMPPHP_Log", "::", "LEVEL_VERBOSE", ")", ";", "xml_parse", "(", "$", "this", "->", "parser", ",", "$", "buff", ",", "false", ")", ";", "}", "else", "{", "# $updated == 0 means no changes during timeout.", "}", "$", "endtime", "=", "(", "microtime", "(", "true", ")", "*", "1000000", ")", ";", "$", "time_past", "=", "$", "endtime", "-", "$", "starttime", ";", "$", "remaining", "=", "$", "remaining", "-", "$", "time_past", ";", "}", "while", "(", "is_null", "(", "$", "maximum", ")", "||", "$", "remaining", ">", "0", ")", ";", "return", "true", ";", "}" ]
Core reading tool 0 -> only read if data is immediately ready NULL -> wait forever and ever integer -> process for this amount of time
[ "Core", "reading", "tool", "0", "-", ">", "only", "read", "if", "data", "is", "immediately", "ready", "NULL", "-", ">", "wait", "forever", "and", "ever", "integer", "-", ">", "process", "for", "this", "amount", "of", "time" ]
a411b499b98afc9901c24a9466c7e322946a04aa
https://github.com/moodle/moodle/blob/a411b499b98afc9901c24a9466c7e322946a04aa/lib/jabber/XMPP/XMLStream.php#L378-L429